Skip to content

Commit 49c098c

Browse files
#1143: Remove set current url as it gets fixed in #1202
1 parent c27907f commit 49c098c

File tree

2 files changed

+147
-4
lines changed

2 files changed

+147
-4
lines changed

packages/uikit-workshop/src/scripts/lit-components/pl-viewport-size-list/pl-viewport-size-list.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,153 @@ class ViewportSizes extends BaseComponent {
9393
}
9494
}
9595

96+
/**
97+
* Get a random number between minViewportWidth and maxViewportWidth
98+
*/
99+
getRangeRandomNumber() {
100+
return getRandom(
101+
minViewportWidth,
102+
// Do not evaluate a number higher than the clientWidth of the Iframe
103+
// to prevent having max size multiple times
104+
maxViewportWidth > this.iframe.clientWidth
105+
? this.iframe.clientWidth
106+
: maxViewportWidth
107+
);
108+
}
109+
110+
/**
111+
* Start the disco mode, which means in a specific interval resize
112+
* the iframe random between minViewportWidth and maxViewportWidth
113+
*/
114+
startDisco() {
115+
this.discoMode = true;
116+
this.discoId = setInterval(this.disco.bind(this), 1000);
117+
}
118+
119+
/**
120+
* Stop the disco mode
121+
*/
122+
killDisco() {
123+
this.discoMode = false;
124+
clearInterval(this.discoId);
125+
this.discoID = null;
126+
}
127+
128+
/**
129+
* Action to resize the Iframe in disco mode
130+
*/
131+
disco() {
132+
this.iframe.sizeiframe(this.getRangeRandomNumber(), true);
133+
}
134+
135+
/**
136+
* Start the Hay! mode, which means the iframe is growing slowly
137+
* from minViewportWidth to maxViewportWidth
138+
*/
139+
startHay() {
140+
this.hayMode = true;
141+
this.hayId = setInterval(this.hay.bind(this), 100);
142+
}
143+
144+
/**
145+
* Stop the Hay! Mode
146+
*/
147+
killHay() {
148+
this.hayMode = false;
149+
clearInterval(this.hayId);
150+
this.hayId = null;
151+
}
152+
153+
/**
154+
* Action to resize the Iframe in Hay! mode
155+
*/
156+
hay() {
157+
this.iframe.sizeiframe(store.getState().app.viewportPx + 1, true);
158+
}
159+
160+
/**
161+
* Litte workaround for Firefox Bug.
162+
*
163+
* On QWERTZ keyboards the e.altKey and e.ctrlKey will
164+
* not be set if you click on a key that has a specific
165+
* secondary or third char at ALT + ...
166+
*
167+
* @param {KeyboardEvent} e the keyevent
168+
*/
169+
handleKeyDownEvent(e) {
170+
if (e.key === 'Control') {
171+
this.controlIsPressed = true;
172+
}
173+
if (e.key === 'Alt') {
174+
this.altIsPressed = true;
175+
}
176+
}
177+
178+
/**
179+
* https://patternlab.io/docs/advanced-keyboard-shortcuts.html
180+
*
181+
* Why use these specific key combinations?
182+
* Works on QUERTZ, QUERTY and AZERTY keyboard and they are no
183+
* reserved browser functionality key combinations.
184+
*
185+
* QUERTY https://en.wikipedia.org/wiki/QWERTY
186+
* QUERTZ https://en.wikipedia.org/wiki/QWERTZ
187+
* AZERTY https://en.wikipedia.org/wiki/AZERTY
188+
*
189+
* Chromium
190+
* https://support.google.com/chrome/answer/157179?hl=en
191+
*
192+
* Firefox
193+
* https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly
194+
*
195+
* @param {KeyboardEvent} e the keyevent
196+
197+
*/
198+
handleKeyCombination(e) {
199+
const ctrlKey = this.controlIsPressed;
200+
const altKey = this.altIsPressed;
201+
202+
if (ctrlKey && altKey && (e.code === 'Digit0' || e.code === 'Numpad0')) {
203+
this.resizeViewport(this.sizes.ZERO);
204+
} else if (ctrlKey && altKey && e.code === 'KeyS') {
205+
this.resizeViewport(this.sizes.SMALL);
206+
} else if (ctrlKey && altKey && e.code === 'KeyM') {
207+
this.resizeViewport(this.sizes.MEDIUM);
208+
} else if (ctrlKey && altKey && e.code === 'KeyL') {
209+
this.resizeViewport(this.sizes.LARGE);
210+
} else if (ctrlKey && altKey && e.code === 'KeyF') {
211+
this.resizeViewport(this.sizes.FULL);
212+
} else if (ctrlKey && altKey && e.code === 'KeyR') {
213+
this.resizeViewport(this.sizes.RANDOM);
214+
} else if (ctrlKey && altKey && e.code === 'KeyD') {
215+
this.resizeViewport(this.sizes.DISCO);
216+
} else if (ctrlKey && altKey && e.code === 'KeyH') {
217+
this.resizeViewport(this.sizes.HAY);
218+
}
219+
220+
if (e.key === 'Control') {
221+
this.controlIsPressed = false;
222+
}
223+
if (e.key === 'Alt') {
224+
this.altIsPressed = false;
225+
}
226+
}
227+
228+
/**
229+
* Interpret and handle the received message input
230+
*
231+
* @param {MessageEvent} e A message received by a target object.
232+
*/
233+
receiveIframeMessage(e) {
234+
const data = iframeMsgDataExtraction(e);
235+
236+
if (data.event && data.event === 'patternLab.iframeKeyDownEvent') {
237+
this.handleKeyDownEvent(data);
238+
} else if (data.event && data.event === 'patternLab.iframeKeyUpEvent') {
239+
this.handleKeyCombination(data);
240+
}
241+
}
242+
96243
rendered() {
97244
this.iframe = document.querySelector('pl-iframe');
98245
this.iframeElem = document.querySelector('pl-iframe iframe');

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,6 @@ class IFrame extends BaseLitComponent {
491491
this.sanitizePatternName(event.data.patternpartial) ||
492492
this.getPatternParam();
493493

494-
store.dispatch(
495-
updateCurrentUrl(urlHandler.getFileName(currentPattern))
496-
);
497-
498494
document.title = 'Pattern Lab - ' + currentPattern;
499495

500496
const addressReplacement =

0 commit comments

Comments
 (0)