Skip to content

Commit d14eb44

Browse files
authored
Merge branch 'dev' into fix-uikitworkshop-absolutely-positioned-pattern-parts-at-the-vertical-end-of-the-page-would-get-cropped
2 parents 1db177f + ee0f2ec commit d14eb44

File tree

17 files changed

+551
-194
lines changed

17 files changed

+551
-194
lines changed

packages/docs/src/docs/advanced-keyboard-shortcuts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Pattern Lab comes with support for a number of special keyboard shortcuts to mak
1515

1616
Modifying 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

2525
Modifying the views:
2626

Lines changed: 3 additions & 0 deletions
Loading

packages/uikit-workshop/src/scripts/components/modal-styleguide.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { panelsUtil } from './panels-util';
77
import './pl-copy-to-clipboard/pl-copy-to-clipboard';
8+
import { iframeMsgDataExtraction } from '../utils';
89

910
export 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') {

packages/uikit-workshop/src/scripts/components/modal-viewer.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { scrollTo } from 'scroll-js';
7-
import { urlHandler, Dispatcher } from '../utils';
7+
import { urlHandler, Dispatcher, iframeMsgDataExtraction } from '../utils';
88
import { panelsViewer } from './panels-viewer';
99
import { 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

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const classNames = require('classnames');
77
import { getParents } from './get-parents';
88
import { store } from '../../store.js'; // redux store
99
import { BaseComponent } from '../base-component.js';
10+
import { iframeMsgDataExtraction } from '../../utils';
1011
import Mousetrap from 'mousetrap';
1112
import '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 {

packages/uikit-workshop/src/scripts/components/pl-search/pl-search.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Mousetrap from 'mousetrap';
1010
import VisuallyHidden from '@reach/visually-hidden';
1111
import Autosuggest from 'react-autosuggest';
1212

13-
import { urlHandler } from '../../utils';
13+
import { urlHandler, iframeMsgDataExtraction } from '../../utils';
1414
import { 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) {

packages/uikit-workshop/src/scripts/lit-components/pl-header/pl-header.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { store } from '../../store.js'; // connect to redux
33
import { ifDefined } from 'lit-html/directives/if-defined';
44
import { html } from 'lit-html';
55
import { BaseLitComponent } from '../../components/base-component';
6+
import { iframeMsgDataExtraction } from '../../utils';
67
import { customElement } from 'lit-element';
78
import Mousetrap from 'mousetrap';
89
import 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 {

packages/uikit-workshop/src/scripts/lit-components/pl-tools-menu/pl-tools-menu.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { define, props } from 'skatejs';
33
import Mousetrap from 'mousetrap';
44
import { h } from 'preact';
5-
import { urlHandler, patternName } from '../../utils';
5+
import { urlHandler, patternName, iframeMsgDataExtraction } from '../../utils';
66
import { store } from '../../store'; // redux store
77
import 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 numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
});

0 commit comments

Comments
 (0)