@data-fair/frame 0.8.2 → 0.8.4
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.
- package/dist/d-frame-content.min.js +1 -1
- package/dist/v-iframe-compat/d-frame-content.min.js +1 -1
- package/lib/DFrameContent.d.ts +2 -2
- package/lib/DFrameContent.js +3 -1
- package/lib/v-iframe-compat/d-frame-content.js +17 -10
- package/lib/vue-router/d-frame-content.js +19 -5
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var DFrameContent=function(){"use strict";var
|
|
1
|
+
var DFrameContent=function(){"use strict";var g=Object.defineProperty;var l=(a,n,r)=>n in a?g(a,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[n]=r;var o=(a,n,r)=>l(a,typeof n!="symbol"?n+"":n,r);function a(h){return h[0]==="df-parent"&&h[1]==="init"}function n(h){return h[0]==="df-parent"&&h[1]==="updateSrc"}const r=["animationstart","webkitAnimationStart","animationiteration","webkitAnimationIteration","animationend","webkitAnimationEnd","input","mouseup","mousedown","orientationchange","afterprint","beforeprint","readystatechange","touchstart","touchend","touchcancel","transitionstart","webkitTransitionStart","MSTransitionStart","oTransitionStart","otransitionstart","transitioniteration","webkitTransitionIteration","MSTransitionIteration","oTransitionIteration","otransitioniteration","transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend","resize"];class u{constructor(t){o(this,"initialized",!1);o(this,"options");o(this,"pendingCheckHeight",!1);o(this,"debug",!1);o(this,"id");o(this,"throttledCheckHeight");o(this,"lastHeight",0);this.options=t??{};const e=()=>{this.checkHeight(),this.pendingCheckHeight=!1};this.throttledCheckHeight=()=>{this.pendingCheckHeight||(this.pendingCheckHeight=!0,requestAnimationFrame(e))},!(typeof window>"u")&&(window.addEventListener("message",i=>this.onMessage(i)),this.postMessageToParent(["df-child","init"]))}log(t,...e){t==="debug"&&!this.debug||(t==="debug"&&console.timeLog(`d-frame:${this.id}:content`,...e),t==="info"&&console.info(`d-frame:${this.id}:content`,...e),t==="error"&&console.error(`d-frame:${this.id}:content`,...e))}onMessage(t){if(t.source===window.parent&&Array.isArray(t.data)){const e=t.data;a(e)&&(this.id=e[2].id,this.debug=!!e[2].debug,this.debug&&console.time(`d-frame:${this.id}:content`),e[2].resize!=="no"&&this.initResize(),(e[2].syncParams||e[2].syncPath||e[2].stateChangeEvents)&&this.initStateChangeWatcher(),this.initialized=!0),n(e)&&(this.options.updateSrc?this.options.updateSrc(e[2].startsWith("/")?window.location.origin+e[2]:e[2],this):window.location.href=e[2])}}postMessageToParent(t){window.parent.postMessage(t)}sendNotif(t){this.postMessageToParent(["df-child","notif",t])}sendMessage(t){this.postMessageToParent(["df-child","custom",t])}ready(){this.postMessageToParent(["df-child","ready"])}initResize(){this.log("debug","initResize"),this.checkHeight(),this.createMutationObserver(),this.createWindowEventListeners()}initStateChangeWatcher(){this.log("debug","initStateChangeWatcher");const t=window.history.replaceState,e=(...s)=>{const d=t.apply(window.history,s);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),d};window.history.pushState=e;const i=(...s)=>{const d=t.apply(window.history,s);return this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),d};window.history.replaceState=i}createMutationObserver(){const t=document.querySelector("body");if(!t)throw new Error("DFrameContentManager was initialized before the HTML body");new window.MutationObserver(this.throttledCheckHeight).observe(t,{attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0})}createWindowEventListeners(){for(const t of r)window.addEventListener(t,this.throttledCheckHeight,{passive:!0})}checkHeight(){const t=document.querySelectorAll("[data-iframe-height]");let e=0,i=0;for(const s of t){const d=s.getAttribute("data-iframe-height"),c=s.getBoundingClientRect().bottom+parseFloat(getComputedStyle(s).getPropertyValue("margin-bottom")),f=d?c+parseFloat(d):c;c>e&&(e=c),f>i&&(i=f)}i=Math.ceil(i),e>0&&i!==this.lastHeight&&(this.postMessageToParent(["df-child","height",i]),this.lastHeight=i)}}return new u}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var VIframeCompatDFrameContent=function(){"use strict";var
|
|
1
|
+
var VIframeCompatDFrameContent=function(){"use strict";var b=Object.defineProperty;var m=(d,s,l)=>s in d?b(d,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[s]=l;var h=(d,s,l)=>m(d,typeof s!="symbol"?s+"":s,l);function d(n){return n[0]==="df-parent"&&n[1]==="init"}function s(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}const l=["animationstart","webkitAnimationStart","animationiteration","webkitAnimationIteration","animationend","webkitAnimationEnd","input","mouseup","mousedown","orientationchange","afterprint","beforeprint","readystatechange","touchstart","touchend","touchcancel","transitionstart","webkitTransitionStart","MSTransitionStart","oTransitionStart","otransitionstart","transitioniteration","webkitTransitionIteration","MSTransitionIteration","oTransitionIteration","otransitioniteration","transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend","resize"];class p{constructor(e){h(this,"initialized",!1);h(this,"options");h(this,"pendingCheckHeight",!1);h(this,"debug",!1);h(this,"id");h(this,"throttledCheckHeight");h(this,"lastHeight",0);this.options=e??{};const t=()=>{this.checkHeight(),this.pendingCheckHeight=!1};this.throttledCheckHeight=()=>{this.pendingCheckHeight||(this.pendingCheckHeight=!0,requestAnimationFrame(t))},!(typeof window>"u")&&(window.addEventListener("message",i=>this.onMessage(i)),this.postMessageToParent(["df-child","init"]))}log(e,...t){e==="debug"&&!this.debug||(e==="debug"&&console.timeLog(`d-frame:${this.id}:content`,...t),e==="info"&&console.info(`d-frame:${this.id}:content`,...t),e==="error"&&console.error(`d-frame:${this.id}:content`,...t))}onMessage(e){if(e.source===window.parent&&Array.isArray(e.data)){const t=e.data;d(t)&&(this.id=t[2].id,this.debug=!!t[2].debug,this.debug&&console.time(`d-frame:${this.id}:content`),t[2].resize!=="no"&&this.initResize(),(t[2].syncParams||t[2].syncPath||t[2].stateChangeEvents)&&this.initStateChangeWatcher(),this.initialized=!0),s(t)&&(this.options.updateSrc?this.options.updateSrc(t[2].startsWith("/")?window.location.origin+t[2]:t[2],this):window.location.href=t[2])}}postMessageToParent(e){window.parent.postMessage(e)}sendNotif(e){this.postMessageToParent(["df-child","notif",e])}sendMessage(e){this.postMessageToParent(["df-child","custom",e])}ready(){this.postMessageToParent(["df-child","ready"])}initResize(){this.log("debug","initResize"),this.checkHeight(),this.createMutationObserver(),this.createWindowEventListeners()}initStateChangeWatcher(){this.log("debug","initStateChangeWatcher");const e=window.history.replaceState,t=(...o)=>{const r=e.apply(window.history,o);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),r};window.history.pushState=t;const i=(...o)=>{const r=e.apply(window.history,o);return this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),r};window.history.replaceState=i}createMutationObserver(){const e=document.querySelector("body");if(!e)throw new Error("DFrameContentManager was initialized before the HTML body");new window.MutationObserver(this.throttledCheckHeight).observe(e,{attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0})}createWindowEventListeners(){for(const e of l)window.addEventListener(e,this.throttledCheckHeight,{passive:!0})}checkHeight(){const e=document.querySelectorAll("[data-iframe-height]");let t=0,i=0;for(const o of e){const r=o.getAttribute("data-iframe-height"),c=o.getBoundingClientRect().bottom+parseFloat(getComputedStyle(o).getPropertyValue("margin-bottom")),a=r?c+parseFloat(r):c;c>t&&(t=c),a>i&&(i=a)}i=Math.ceil(i),t>0&&i!==this.lastHeight&&(this.postMessageToParent(["df-child","height",i]),this.lastHeight=i)}}const w=(n,e)=>{const t=Object.keys(n);e.forEach((i,o)=>{n[o]=i,t.splice(t.indexOf(o),1)}),t.forEach(i=>{delete n[i]})},g=new p({updateSrc(n,e){var r,c;const t=window.vIframeOptions,i=t==null?void 0:t.reactiveParams;if(i&&typeof i=="object"){const a=new URL(n);if(a.origin===window.location.origin&&a.pathname===window.location.pathname){e.log("debug","applying reactive params",a.searchParams),w(i,a.searchParams);return}}const o=t==null?void 0:t.router;if(o){const a=((r=o.options)==null?void 0:r.base)??((c=o.options.history)==null?void 0:c.base);if(a==null)e.log("error","failed to access base path in router (no router.options.base nor router.options.history.base)",o);else{const u=window.location.origin+a;if(!n.startsWith(u))e.log("info","src does not start with base path",n,u);else{let f=n.replace(u,"");f.startsWith("/")||(f="/"+f),e.log("debug","applying router.replace",f),o.replace(f);return}}}e.log("info","falling back to updating window.location.href",n),window.location.href=n}});return window.dFrameContent=g,g}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
package/lib/DFrameContent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Notif } from './messages.js';
|
|
2
2
|
export type DFrameContentOptions = {
|
|
3
|
-
updateSrc?: (src: string) => void;
|
|
3
|
+
updateSrc?: (src: string, instance: DFrameContent) => void;
|
|
4
4
|
};
|
|
5
5
|
export default class DFrameContent {
|
|
6
6
|
initialized: boolean;
|
|
@@ -11,7 +11,7 @@ export default class DFrameContent {
|
|
|
11
11
|
private throttledCheckHeight;
|
|
12
12
|
private lastHeight;
|
|
13
13
|
constructor(options?: DFrameContentOptions);
|
|
14
|
-
|
|
14
|
+
log(level: 'debug' | 'info' | 'error', ...args: any[]): void;
|
|
15
15
|
private onMessage;
|
|
16
16
|
private postMessageToParent;
|
|
17
17
|
sendNotif(notif: Notif): void;
|
package/lib/DFrameContent.js
CHANGED
|
@@ -63,6 +63,8 @@ export default class DFrameContent {
|
|
|
63
63
|
console.timeLog(`d-frame:${this.id}:content`, ...args);
|
|
64
64
|
if (level === 'info')
|
|
65
65
|
console.info(`d-frame:${this.id}:content`, ...args);
|
|
66
|
+
if (level === 'error')
|
|
67
|
+
console.error(`d-frame:${this.id}:content`, ...args);
|
|
66
68
|
}
|
|
67
69
|
onMessage(e) {
|
|
68
70
|
if (e.source === window.parent && Array.isArray(e.data)) {
|
|
@@ -80,7 +82,7 @@ export default class DFrameContent {
|
|
|
80
82
|
}
|
|
81
83
|
if (isUpdateSrcMessage(message)) {
|
|
82
84
|
if (this.options.updateSrc) {
|
|
83
|
-
this.options.updateSrc(message[2].startsWith('/') ? window.location.origin + message[2] : message[2]);
|
|
85
|
+
this.options.updateSrc(message[2].startsWith('/') ? window.location.origin + message[2] : message[2], this);
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
88
|
window.location.href = message[2];
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import DFrameContent from '../DFrameContent.js';
|
|
2
2
|
import { applySearchParams } from '../vue-reactive/util.js';
|
|
3
3
|
const dFrameContent = new DFrameContent({
|
|
4
|
-
updateSrc
|
|
4
|
+
updateSrc(src, instance) {
|
|
5
5
|
const vIframeOptions = window.vIframeOptions;
|
|
6
6
|
const reactiveParams = vIframeOptions?.reactiveParams;
|
|
7
7
|
if (reactiveParams && typeof reactiveParams === 'object') {
|
|
8
8
|
const srcUrl = new URL(src);
|
|
9
9
|
if (srcUrl.origin === window.location.origin && srcUrl.pathname === window.location.pathname) {
|
|
10
|
+
instance.log('debug', 'applying reactive params', srcUrl.searchParams);
|
|
10
11
|
applySearchParams(reactiveParams, srcUrl.searchParams);
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
const router = vIframeOptions?.router;
|
|
16
|
+
if (router) {
|
|
15
17
|
// @ts-ignore vue-router v2
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
base
|
|
19
|
-
if (!base) {
|
|
20
|
-
console.error('failed to access base path in router (no router.options.base nor router.options.history.base)');
|
|
21
|
-
window.location.href = src;
|
|
18
|
+
const base = router.options?.base ?? router.options.history?.base;
|
|
19
|
+
if (base === null || base === undefined) {
|
|
20
|
+
instance.log('error', 'failed to access base path in router (no router.options.base nor router.options.history.base)', router);
|
|
22
21
|
}
|
|
23
22
|
else {
|
|
24
23
|
const urlPrefix = window.location.origin + base;
|
|
25
|
-
if (src.startsWith(urlPrefix)) {
|
|
26
|
-
|
|
24
|
+
if (!src.startsWith(urlPrefix)) {
|
|
25
|
+
instance.log('info', 'src does not start with base path', src, urlPrefix);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
let newRoute = src.replace(urlPrefix, '');
|
|
29
|
+
if (!newRoute.startsWith('/'))
|
|
30
|
+
newRoute = '/' + newRoute;
|
|
31
|
+
instance.log('debug', 'applying router.replace', newRoute);
|
|
32
|
+
router.replace(newRoute);
|
|
27
33
|
return;
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
}
|
|
37
|
+
instance.log('info', 'falling back to updating window.location.href', src);
|
|
31
38
|
window.location.href = src;
|
|
32
39
|
}
|
|
33
40
|
});
|
|
@@ -2,14 +2,28 @@ import DFrameContent from '../DFrameContent.js';
|
|
|
2
2
|
export function vueRouterDFrameContent(router, options) {
|
|
3
3
|
return new DFrameContent({
|
|
4
4
|
...options,
|
|
5
|
-
updateSrc: (src) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
updateSrc: (src, instance) => {
|
|
6
|
+
// @ts-ignore vue-router v2
|
|
7
|
+
const base = router.options?.base ?? router.options.history?.base;
|
|
8
|
+
if (base === null || base === undefined) {
|
|
9
|
+
instance.log('error', 'failed to access base path in router (no router.options.base nor router.options.history.base)', router);
|
|
9
10
|
}
|
|
10
11
|
else {
|
|
11
|
-
window.location.
|
|
12
|
+
const urlPrefix = window.location.origin + base;
|
|
13
|
+
if (!src.startsWith(urlPrefix)) {
|
|
14
|
+
instance.log('info', 'src does not start with base path', src, urlPrefix);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
let newRoute = src.replace(urlPrefix, '');
|
|
18
|
+
if (!newRoute.startsWith('/'))
|
|
19
|
+
newRoute = '/' + newRoute;
|
|
20
|
+
instance.log('debug', 'applying router.replace', newRoute);
|
|
21
|
+
router.replace(newRoute);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
12
24
|
}
|
|
25
|
+
instance.log('info', 'falling back to updating window.location.href', src);
|
|
26
|
+
window.location.href = src;
|
|
13
27
|
}
|
|
14
28
|
});
|
|
15
29
|
}
|