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
15
15
16
16
Modifying the viewport:
17
17
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
24
24
25
25
Modifying the views:
26
26
Original file line number Diff line number Diff line change 5
5
6
6
import { panelsUtil } from './panels-util' ;
7
7
import './pl-copy-to-clipboard/pl-copy-to-clipboard' ;
8
+ import { iframeMsgDataExtraction } from '../utils' ;
8
9
9
10
export const modalStyleguide = {
10
11
// set up some defaults
@@ -195,24 +196,11 @@ export const modalStyleguide = {
195
196
/**
196
197
* toggle the comment pop-up based on a user clicking on the pattern
197
198
* 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.
199
201
*/
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 ) ;
216
204
217
205
// see if it got a path to replace
218
206
if ( data . event !== undefined && data . event === 'patternLab.patternQuery' ) {
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
import { scrollTo } from 'scroll-js' ;
7
- import { urlHandler , Dispatcher } from '../utils' ;
7
+ import { urlHandler , Dispatcher , iframeMsgDataExtraction } from '../utils' ;
8
8
import { panelsViewer } from './panels-viewer' ;
9
9
import { store } from '../store.js' ;
10
10
// These are the actions needed by this element.
@@ -283,25 +283,11 @@ export const modalViewer = {
283
283
/**
284
284
* toggle the comment pop-up based on a user clicking on the pattern
285
285
* 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.
287
288
*/
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 ) ;
305
291
306
292
if ( data . event !== undefined && data . event === 'patternLab.pageLoad' ) {
307
293
// @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');
7
7
import { getParents } from './get-parents' ;
8
8
import { store } from '../../store.js' ; // redux store
9
9
import { BaseComponent } from '../base-component.js' ;
10
+ import { iframeMsgDataExtraction } from '../../utils' ;
10
11
import Mousetrap from 'mousetrap' ;
11
12
import 'url-search-params-polyfill' ;
12
13
@@ -89,24 +90,13 @@ class Nav extends BaseComponent {
89
90
}
90
91
}
91
92
92
- receiveIframeMessage ( event ) {
93
+ /**
94
+ *
95
+ * @param {MessageEvent } e A message received by a target object.
96
+ */
97
+ receiveIframeMessage ( e ) {
93
98
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 ) ;
110
100
111
101
if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
112
102
try {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Mousetrap from 'mousetrap';
10
10
import VisuallyHidden from '@reach/visually-hidden' ;
11
11
import Autosuggest from 'react-autosuggest' ;
12
12
13
- import { urlHandler } from '../../utils' ;
13
+ import { urlHandler , iframeMsgDataExtraction } from '../../utils' ;
14
14
import { BaseComponent } from '../base-component' ;
15
15
16
16
@define
@@ -118,22 +118,12 @@ class Search extends BaseComponent {
118
118
document . activeElement . blur ( ) ;
119
119
}
120
120
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 ) ;
137
127
138
128
if ( data . event !== undefined && data . event === 'patternLab.keyPress' ) {
139
129
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
3
3
import { ifDefined } from 'lit-html/directives/if-defined' ;
4
4
import { html } from 'lit-html' ;
5
5
import { BaseLitComponent } from '../../components/base-component' ;
6
+ import { iframeMsgDataExtraction } from '../../utils' ;
6
7
import { customElement } from 'lit-element' ;
7
8
import Mousetrap from 'mousetrap' ;
8
9
import styles from './pl-header.scss?external' ;
@@ -142,24 +143,14 @@ class Header extends BaseLitComponent {
142
143
` ;
143
144
}
144
145
145
- receiveIframeMessage ( event ) {
146
+ /**
147
+ *
148
+ * @param {MessageEvent } e A message received by a target object.
149
+ */
150
+ receiveIframeMessage ( e ) {
146
151
const self = this ;
147
152
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 ) ;
163
154
164
155
if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
165
156
try {
Original file line number Diff line number Diff line change 2
2
import { define , props } from 'skatejs' ;
3
3
import Mousetrap from 'mousetrap' ;
4
4
import { h } from 'preact' ;
5
- import { urlHandler , patternName } from '../../utils' ;
5
+ import { urlHandler , patternName , iframeMsgDataExtraction } from '../../utils' ;
6
6
import { store } from '../../store' ; // redux store
7
7
import styles from './pl-tools-menu.scss?external' ;
8
8
@@ -99,23 +99,14 @@ class ToolsMenu extends BaseLitComponent {
99
99
this . toggle ( ) ;
100
100
}
101
101
102
- receiveIframeMessage ( event ) {
102
+ /**
103
+ *
104
+ * @param {MessageEvent } e A message received by a target object.
105
+ */
106
+ receiveIframeMessage ( e ) {
103
107
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
- }
111
108
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 ) ;
119
110
120
111
if ( data . event !== undefined && data . event === 'patternLab.pageClick' ) {
121
112
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