File tree Expand file tree Collapse file tree 17 files changed +551
-194
lines changed Expand file tree Collapse file tree 17 files changed +551
-194
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,12 @@ Pattern Lab comes with support for a number of special keyboard shortcuts to mak
1515
1616Modifying the viewport:
1717
18- - ** ctrl+shift +0** : set the viewport to 320px
19- - ** ctrl+shift +s** : set the viewport to "small"
20- - ** ctrl+shift +m** : set the viewport to "medium"
21- - ** ctrl+shift +l** : set the viewport to "large"
22- - ** ctrl+shift +h** : toggle Hay mode
23- - ** ctrl+shift +d** : toggle disco mode
18+ - ** ctrl+alt +0** : set the viewport to 320px
19+ - ** ctrl+alt +s** : set the viewport to "small"
20+ - ** ctrl+alt +m** : set the viewport to "medium"
21+ - ** ctrl+alt +l** : set the viewport to "large"
22+ - ** ctrl+alt +h** : toggle Hay mode
23+ - ** ctrl+alt +d** : toggle disco mode
2424
2525Modifying the views:
2626
Original file line number Diff line number Diff line change 55
66import { panelsUtil } from './panels-util' ;
77import './pl-copy-to-clipboard/pl-copy-to-clipboard' ;
8+ import { iframeMsgDataExtraction } from '../utils' ;
89
910export const modalStyleguide = {
1011 // set up some defaults
@@ -195,24 +196,11 @@ export const modalStyleguide = {
195196 /**
196197 * toggle the comment pop-up based on a user clicking on the pattern
197198 * based on the great MDN docs at https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
198- * @param {Object } event info
199+ *
200+ * @param {MessageEvent } e A message received by a target object.
199201 */
200- receiveIframeMessage ( event ) {
201- // does the origin sending the message match the current host? if not dev/null the request
202- if (
203- window . location . protocol !== 'file:' &&
204- event . origin !== window . location . protocol + '//' + window . location . host
205- ) {
206- return ;
207- }
208-
209- let data = { } ;
210- try {
211- data =
212- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
213- } catch ( e ) {
214- // @todo : how do we want to handle exceptions here?
215- }
202+ receiveIframeMessage ( e ) {
203+ const data = iframeMsgDataExtraction ( e ) ;
216204
217205 // see if it got a path to replace
218206 if ( data . event !== undefined && data . event === 'patternLab.patternQuery' ) {
Original file line number Diff line number Diff line change 44 */
55
66import { scrollTo } from 'scroll-js' ;
7- import { urlHandler , Dispatcher } from '../utils' ;
7+ import { urlHandler , Dispatcher , iframeMsgDataExtraction } from '../utils' ;
88import { panelsViewer } from './panels-viewer' ;
99import { store } from '../store.js' ;
1010// These are the actions needed by this element.
@@ -283,25 +283,11 @@ export const modalViewer = {
283283 /**
284284 * toggle the comment pop-up based on a user clicking on the pattern
285285 * based on the great MDN docs at https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
286- * @param {Object } event info
286+ *
287+ * @param {MessageEvent } e A message received by a target object.
287288 */
288- receiveIframeMessage ( event ) {
289- // does the origin sending the message match the current host? if not dev/null the request
290- if (
291- window . location . protocol !== 'file:' &&
292- event . origin !== window . location . protocol + '//' + window . location . host
293- ) {
294- return ;
295- }
296-
297- let data = { } ;
298-
299- try {
300- data =
301- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
302- } catch ( e ) {
303- // @todo : how do we want to handle exceptions here?
304- }
289+ receiveIframeMessage ( e ) {
290+ const data = iframeMsgDataExtraction ( e ) ;
305291
306292 if ( data . event !== undefined && data . event === 'patternLab.pageLoad' ) {
307293 // @todo : refactor to better handle async iframe loading
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const classNames = require('classnames');
77import { getParents } from './get-parents' ;
88import { store } from '../../store.js' ; // redux store
99import { BaseComponent } from '../base-component.js' ;
10+ import { iframeMsgDataExtraction } from '../../utils' ;
1011import Mousetrap from 'mousetrap' ;
1112import 'url-search-params-polyfill' ;
1213
@@ -89,24 +90,13 @@ class Nav extends BaseComponent {
8990 }
9091 }
9192
92- receiveIframeMessage ( event ) {
93+ /**
94+ *
95+ * @param {MessageEvent } e A message received by a target object.
96+ */
97+ receiveIframeMessage ( e ) {
9398 const self = this ;
94-
95- // does the origin sending the message match the current host? if not dev/null the request
96- if (
97- window . location . protocol !== 'file:' &&
98- event . origin !== window . location . protocol + '//' + window . location . host
99- ) {
100- return ;
101- }
102-
103- let data = { } ;
104- try {
105- data =
106- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
107- } catch ( e ) {
108- // @todo : how do we want to handle exceptions here?
109- }
99+ const data = iframeMsgDataExtraction ( e ) ;
110100
111101 if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
112102 try {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Mousetrap from 'mousetrap';
1010import VisuallyHidden from '@reach/visually-hidden' ;
1111import Autosuggest from 'react-autosuggest' ;
1212
13- import { urlHandler } from '../../utils' ;
13+ import { urlHandler , iframeMsgDataExtraction } from '../../utils' ;
1414import { BaseComponent } from '../base-component' ;
1515
1616@define
@@ -118,22 +118,12 @@ class Search extends BaseComponent {
118118 document . activeElement . blur ( ) ;
119119 }
120120
121- receiveIframeMessage ( event ) {
122- // does the origin sending the message match the current host? if not dev/null the request
123- if (
124- window . location . protocol !== 'file:' &&
125- event . origin !== window . location . protocol + '//' + window . location . host
126- ) {
127- return ;
128- }
129-
130- let data = { } ;
131- try {
132- data =
133- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
134- } catch ( e ) {
135- // @todo : how do we want to handle exceptions here?
136- }
121+ /**
122+ *
123+ * @param {MessageEvent } e A message received by a target object.
124+ */
125+ receiveIframeMessage ( e ) {
126+ const data = iframeMsgDataExtraction ( e ) ;
137127
138128 if ( data . event !== undefined && data . event === 'patternLab.keyPress' ) {
139129 if ( data . key === 'f' && data . metaKey === true ) {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { store } from '../../store.js'; // connect to redux
33import { ifDefined } from 'lit-html/directives/if-defined' ;
44import { html } from 'lit-html' ;
55import { BaseLitComponent } from '../../components/base-component' ;
6+ import { iframeMsgDataExtraction } from '../../utils' ;
67import { customElement } from 'lit-element' ;
78import Mousetrap from 'mousetrap' ;
89import styles from './pl-header.scss?external' ;
@@ -142,24 +143,14 @@ class Header extends BaseLitComponent {
142143 ` ;
143144 }
144145
145- receiveIframeMessage ( event ) {
146+ /**
147+ *
148+ * @param {MessageEvent } e A message received by a target object.
149+ */
150+ receiveIframeMessage ( e ) {
146151 const self = this ;
147152
148- // does the origin sending the message match the current host? if not dev/null the request
149- if (
150- window . location . protocol !== 'file:' &&
151- event . origin !== window . location . protocol + '//' + window . location . host
152- ) {
153- return ;
154- }
155-
156- let data = { } ;
157- try {
158- data =
159- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
160- } catch ( e ) {
161- // @todo : how do we want to handle exceptions here?
162- }
153+ const data = iframeMsgDataExtraction ( e ) ;
163154
164155 if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
165156 try {
Original file line number Diff line number Diff line change 22import { define , props } from 'skatejs' ;
33import Mousetrap from 'mousetrap' ;
44import { h } from 'preact' ;
5- import { urlHandler , patternName } from '../../utils' ;
5+ import { urlHandler , patternName , iframeMsgDataExtraction } from '../../utils' ;
66import { store } from '../../store' ; // redux store
77import styles from './pl-tools-menu.scss?external' ;
88
@@ -99,23 +99,14 @@ class ToolsMenu extends BaseLitComponent {
9999 this . toggle ( ) ;
100100 }
101101
102- receiveIframeMessage ( event ) {
102+ /**
103+ *
104+ * @param {MessageEvent } e A message received by a target object.
105+ */
106+ receiveIframeMessage ( e ) {
103107 const self = this ;
104- // does the origin sending the message match the current host? if not dev/null the request
105- if (
106- window . location . protocol !== 'file:' &&
107- event . origin !== window . location . protocol + '//' + window . location . host
108- ) {
109- return ;
110- }
111108
112- let data = { } ;
113- try {
114- data =
115- typeof event . data !== 'string' ? event . data : JSON . parse ( event . data ) ;
116- } catch ( e ) {
117- // @todo : how do we want to handle exceptions here?
118- }
109+ const data = iframeMsgDataExtraction ( e ) ;
119110
120111 if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
121112 try {
Original file line number Diff line number Diff line change 1+ import { targetOrigin } from '../../utils' ;
2+
3+ function sendPatternLabKeyEvent ( e , name ) {
4+ try {
5+ window . parent . postMessage (
6+ JSON . stringify ( {
7+ event : `patternLab.${ name } ` ,
8+ key : e . key ,
9+ code : e . code ,
10+ } ) ,
11+ targetOrigin
12+ ) ;
13+ } catch ( error ) {
14+ // @todo : how do we want to handle exceptions here?
15+ }
16+ }
17+
18+ document . addEventListener ( 'keydown' , e => {
19+ sendPatternLabKeyEvent ( e , 'iframeKeyDownEvent' ) ;
20+ } ) ;
21+
22+ document . addEventListener ( 'keyup' , e => {
23+ sendPatternLabKeyEvent ( e , 'iframeKeyUpEvent' ) ;
24+ } ) ;
You can’t perform that action at this time.
0 commit comments