@epic-web/workshop-utils 6.47.4 → 6.47.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,2 @@
1
- type CustomReactType = {
2
- useEffect: (cb: () => (() => void) | void, deps: Array<any>) => void;
3
- createElement: (type: string, props: any, ...children: Array<any>) => any;
4
- };
5
- export declare function EpicShopIFrameSync<ReactType extends CustomReactType>({ React, navigate, }: {
6
- React: ReactType;
7
- navigate: (...args: Array<any>) => void;
8
- }): any;
9
- export {};
1
+ export declare function EpicShopIFrameSync(_props: unknown): null;
10
2
  //# sourceMappingURL=iframe-sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe-sync.d.ts","sourceRoot":"","sources":["../../src/iframe-sync.tsx"],"names":[],"mappings":"AAwBA,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA;IACpE,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;CACzE,CAAA;AAgCD,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,eAAe,EAAE,EACrE,KAAK,EACL,QAAQ,GACR,EAAE;IACF,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA;CACvC,OAiDA"}
1
+ {"version":3,"file":"iframe-sync.d.ts","sourceRoot":"","sources":["../../src/iframe-sync.tsx"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,QAGjD"}
@@ -1,97 +1,5 @@
1
- /*
2
- This file is kinda weird. EpicShop actually bundles react and react router to
3
- avoid getting version clashes, but this component is used in the "host"
4
- application. Anything we use in this file will be this file's version of that
5
- dependency, which in the case of bundled dependencies would be different from
6
- the host app's version. We want to avoid shipping two versions of React and
7
- react-router to the client. So we need to accept React and navigate as props
8
- rather than just using those things directly.
9
-
10
- To reduce the annoyance, we'll have the host applications have a file like this:
11
-
12
- // Ignore this file please
13
- import { EpicShopIFrameSync } from '@epic-web/workshop-utils/iframe-sync'
14
- import { useNavigate } from '@remix-run/react'
15
- import * as React from 'react'
16
-
17
- export function EpicShop() {
18
- const navigate = useNavigate()
19
- return <EpicShopIFrameSync React={React} navigate={navigate} />
20
- }
21
-
22
- */
23
- let effectSetup = false;
24
- const iframeSyncScript = /* javascript */ `
25
- if (window.parent !== window) {
26
- window.__epicshop__ = window.__epicshop__ || {};
27
- window.parent.postMessage(
28
- { type: 'epicshop:loaded', url: window.location.href },
29
- '*'
30
- );
31
- function handleMessage(event) {
32
- const { type, params } = event.data
33
- if (type === 'epicshop:navigate-call') {
34
- const [distanceOrUrl, options] = params
35
- if (typeof distanceOrUrl === 'number') {
36
- window.history.go(distanceOrUrl)
37
- } else {
38
- if (options?.replace) {
39
- window.location.replace(distanceOrUrl)
40
- } else {
41
- window.location.assign(distanceOrUrl)
42
- }
43
- }
44
- }
45
- }
46
-
47
- window.addEventListener('message', handleMessage)
48
- window.__epicshop__.onHydrated = function() {
49
- window.removeEventListener('message', handleMessage)
50
- };
51
- }
52
- `;
53
- export function EpicShopIFrameSync({ React, navigate, }) {
54
- // communicate with parent
55
- React.useEffect(() => {
56
- if (effectSetup)
57
- return;
58
- effectSetup = true;
59
- if (window.parent === window)
60
- return;
61
- // @ts-expect-error - this is fine 🔥
62
- window.__epicshop__?.onHydrated?.();
63
- const methods = [
64
- 'pushState',
65
- 'replaceState',
66
- 'go',
67
- 'forward',
68
- 'back',
69
- ];
70
- for (const method of methods) {
71
- // @ts-expect-error - this is fine 🔥
72
- window.history[method] = new Proxy(window.history[method], {
73
- apply(target, thisArg, argArray) {
74
- window.parent.postMessage({ type: 'epicshop:history-call', method, args: argArray }, '*');
75
- // @ts-expect-error - this is fine too 🙃
76
- return target.apply(thisArg, argArray);
77
- },
78
- });
79
- }
80
- }, []);
81
- // listen for messages from parent
82
- React.useEffect(() => {
83
- function handleMessage(event) {
84
- const { type, params } = event.data;
85
- if (type === 'epicshop:navigate-call') {
86
- navigate(...params);
87
- }
88
- }
89
- window.addEventListener('message', handleMessage);
90
- return () => window.removeEventListener('message', handleMessage);
91
- }, [navigate]);
92
- return React.createElement('script', {
93
- type: 'module',
94
- dangerouslySetInnerHTML: { __html: iframeSyncScript },
95
- });
1
+ export function EpicShopIFrameSync(_props) {
2
+ // no-op...
3
+ return null;
96
4
  }
97
5
  //# sourceMappingURL=iframe-sync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe-sync.js","sourceRoot":"","sources":["../../src/iframe-sync.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,IAAI,WAAW,GAAG,KAAK,CAAA;AAOvB,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BzC,CAAA;AAED,MAAM,UAAU,kBAAkB,CAAoC,EACrE,KAAK,EACL,QAAQ,GAIR;IACA,0BAA0B;IAC1B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,IAAI,WAAW;YAAE,OAAM;QACvB,WAAW,GAAG,IAAI,CAAA;QAClB,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM;YAAE,OAAM;QAEpC,qCAAqC;QAErC,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE,EAAE,CAAA;QAEnC,MAAM,OAAO,GAAG;YACf,WAAW;YACX,cAAc;YACd,IAAI;YACJ,SAAS;YACT,MAAM;SACG,CAAA;QACV,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,qCAAqC;YACrC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBAC1D,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ;oBAC9B,MAAM,CAAC,MAAM,CAAC,WAAW,CACxB,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EACzD,GAAG,CACH,CAAA;oBACD,yCAAyC;oBACzC,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;gBACvC,CAAC;aACD,CAAC,CAAA;QACH,CAAC;IACF,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,kCAAkC;IAClC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,SAAS,aAAa,CAAC,KAAmB;YACzC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA;YACnC,IAAI,IAAI,KAAK,wBAAwB,EAAE,CAAC;gBACvC,QAAQ,CAAC,GAAG,MAAM,CAAC,CAAA;YACpB,CAAC;QACF,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;QACjD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAClE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE;QACpC,IAAI,EAAE,QAAQ;QACd,uBAAuB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;KACrD,CAAC,CAAA;AACH,CAAC","sourcesContent":["/*\nThis file is kinda weird. EpicShop actually bundles react and react router to\navoid getting version clashes, but this component is used in the \"host\"\napplication. Anything we use in this file will be this file's version of that\ndependency, which in the case of bundled dependencies would be different from\nthe host app's version. We want to avoid shipping two versions of React and\nreact-router to the client. So we need to accept React and navigate as props\nrather than just using those things directly.\n\nTo reduce the annoyance, we'll have the host applications have a file like this:\n\n// Ignore this file please\nimport { EpicShopIFrameSync } from '@epic-web/workshop-utils/iframe-sync'\nimport { useNavigate } from '@remix-run/react'\nimport * as React from 'react'\n\nexport function EpicShop() {\n\tconst navigate = useNavigate()\n\treturn <EpicShopIFrameSync React={React} navigate={navigate} />\n}\n\n */\nlet effectSetup = false\n\ntype CustomReactType = {\n\tuseEffect: (cb: () => (() => void) | void, deps: Array<any>) => void\n\tcreateElement: (type: string, props: any, ...children: Array<any>) => any\n}\n\nconst iframeSyncScript = /* javascript */ `\nif (window.parent !== window) {\n\twindow.__epicshop__ = window.__epicshop__ || {};\n\twindow.parent.postMessage(\n\t\t{ type: 'epicshop:loaded', url: window.location.href },\n\t\t'*'\n\t);\n\tfunction handleMessage(event) {\n\t\tconst { type, params } = event.data\n\t\tif (type === 'epicshop:navigate-call') {\n\t\t\tconst [distanceOrUrl, options] = params\n\t\t\tif (typeof distanceOrUrl === 'number') {\n\t\t\t\twindow.history.go(distanceOrUrl)\n\t\t\t} else {\n\t\t\t\tif (options?.replace) {\n\t\t\t\t\twindow.location.replace(distanceOrUrl)\n\t\t\t\t} else {\n\t\t\t\t\twindow.location.assign(distanceOrUrl)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\twindow.addEventListener('message', handleMessage)\n\twindow.__epicshop__.onHydrated = function() {\n\t\twindow.removeEventListener('message', handleMessage)\n\t};\n}\n`\n\nexport function EpicShopIFrameSync<ReactType extends CustomReactType>({\n\tReact,\n\tnavigate,\n}: {\n\tReact: ReactType\n\tnavigate: (...args: Array<any>) => void\n}) {\n\t// communicate with parent\n\tReact.useEffect(() => {\n\t\tif (effectSetup) return\n\t\teffectSetup = true\n\t\tif (window.parent === window) return\n\n\t\t// @ts-expect-error - this is fine 🔥\n\n\t\twindow.__epicshop__?.onHydrated?.()\n\n\t\tconst methods = [\n\t\t\t'pushState',\n\t\t\t'replaceState',\n\t\t\t'go',\n\t\t\t'forward',\n\t\t\t'back',\n\t\t] as const\n\t\tfor (const method of methods) {\n\t\t\t// @ts-expect-error - this is fine 🔥\n\t\t\twindow.history[method] = new Proxy(window.history[method], {\n\t\t\t\tapply(target, thisArg, argArray) {\n\t\t\t\t\twindow.parent.postMessage(\n\t\t\t\t\t\t{ type: 'epicshop:history-call', method, args: argArray },\n\t\t\t\t\t\t'*',\n\t\t\t\t\t)\n\t\t\t\t\t// @ts-expect-error - this is fine too 🙃\n\t\t\t\t\treturn target.apply(thisArg, argArray)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}, [])\n\n\t// listen for messages from parent\n\tReact.useEffect(() => {\n\t\tfunction handleMessage(event: MessageEvent) {\n\t\t\tconst { type, params } = event.data\n\t\t\tif (type === 'epicshop:navigate-call') {\n\t\t\t\tnavigate(...params)\n\t\t\t}\n\t\t}\n\t\twindow.addEventListener('message', handleMessage)\n\t\treturn () => window.removeEventListener('message', handleMessage)\n\t}, [navigate])\n\n\treturn React.createElement('script', {\n\t\ttype: 'module',\n\t\tdangerouslySetInnerHTML: { __html: iframeSyncScript },\n\t})\n}\n"]}
1
+ {"version":3,"file":"iframe-sync.js","sourceRoot":"","sources":["../../src/iframe-sync.tsx"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,MAAe;IACjD,WAAW;IACX,OAAO,IAAI,CAAA;AACZ,CAAC","sourcesContent":["export function EpicShopIFrameSync(_props: unknown) {\n\t// no-op...\n\treturn null\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epic-web/workshop-utils",
3
- "version": "6.47.4",
3
+ "version": "6.47.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },