@data-fair/frame 0.18.0 → 0.18.1
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/v-iframe-compat/d-frame-content.min.js +1 -1
- package/lib/v-iframe-compat/d-frame-content.js +2 -2
- package/lib/vue-router/d-frame-content.js +2 -2
- package/lib/vue-router/state-change-adapter.js +2 -2
- package/lib/vue-router/util.d.ts +2 -0
- package/lib/vue-router/util.js +4 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var VIframeCompatDFrameContent=function(){"use strict";var
|
|
1
|
+
var VIframeCompatDFrameContent=function(){"use strict";var y=Object.defineProperty;var M=(c,h,l)=>h in c?y(c,h,{enumerable:!0,configurable:!0,writable:!0,value:l}):c[h]=l;var a=(c,h,l)=>M(c,typeof h!="symbol"?h+"":h,l);function c(n){return n[0]==="df-global"&&n[1]==="mouse"}function h(n){return n[0]==="df-parent"&&n[1]==="init"}function l(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}function u(n){return n[0]==="df-parent"&&n[1]==="parentUrl"}const w=(()=>{try{return window.top!==window.self}catch{return!0}})(),g=["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){a(this,"initialized",!1);a(this,"options");a(this,"pendingCheckHeight",!1);a(this,"debug",!1);a(this,"id");a(this,"throttledCheckHeight");a(this,"lastHeight",0);a(this,"parentUrlListeners",{});a(this,"parentUrlResults",{});a(this,"currentSyncedMouseEvents",new Set);if(this.options=e??{},typeof window>"u")return;if(window.__d_frame__content)throw new Error("DFrameContent was already initialized");window.__d_frame__content=this;const t=()=>{this.checkHeight(),this.pendingCheckHeight=!1};this.throttledCheckHeight=()=>{this.pendingCheckHeight||(this.pendingCheckHeight=!0,requestAnimationFrame(t))},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;if(h(t)&&(this.id=t[2].id,this.debug=!!t[2].debug,this.debug&&console.time(`d-frame:${this.id}:content`),this.log("debug","init handshake is ok",t,this.options),t[2].src&&t[2].src!==window.location.href&&this.log("error",`src mismatch at init, maybe the frame navigated before the initialization handshake: ${window.location.href} !== ${t[2].src}`),t[2].resize!=="no"&&this.initResize(),(t[2].syncParams||t[2].syncPath||t[2].stateChangeEvents)&&this.initStateChangeWatcher(),t[2].mouseEvents&&this.initMouseEvents(t[2].mouseEvents),this.initialized=!0),l(t)){const i=t[2].startsWith("/")?window.location.origin+t[2]:t[2];if(i===window.location.href)return;this.log("debug",`update src ${window.location.href} -> ${i}`),this.options.updateSrc?this.options.updateSrc(i,this):(this.log("debug","no updateSrc method available, falling back to updating window.location.href",i),window.location.href=i)}if(c(t)&&this.applySyncedMouseEvent(t),u(t))if(!this.parentUrlListeners[t[2]])this.log("error",`received getParentUrlResponse message but no matching callback is registered: ${t[2]}`);else for(const i of this.parentUrlListeners[t[2]])i(t[3])}}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"])}reinitHeight(){this.postMessageToParent(["df-child","reinit-height"])}addParentUrlListener(e,t){const i=new URL(e,window.location.href).href;if(!w){t(i);return}this.parentUrlResults[i]&&t(this.parentUrlResults[i]),this.parentUrlListeners[i]=this.parentUrlListeners[i]??[],this.parentUrlListeners[i].push(t),this.postMessageToParent(["df-child","addParentUrlListener",i])}removeParentUrlListener(e,t){const i=new URL(e,window.location.href).href;this.parentUrlListeners[i]&&(this.parentUrlListeners[i]=this.parentUrlListeners[i].filter(o=>o!==t),this.parentUrlListeners[i].length||(delete this.parentUrlListeners[i],this.postMessageToParent(["df-child","removeParentUrlListener",i])))}initMouseEvents(e){this.log("debug","initMouseEvents");for(const t of e)document.addEventListener(t,i=>{i instanceof MouseEvent&&this.transmitSyncedMouseEvent(["df-global","mouse",t,{altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}])},!0)}transmitSyncedMouseEvent(e){this.currentSyncedMouseEvents.has(e[2])?this.currentSyncedMouseEvents.delete(e[2]):this.postMessageToParent(e)}applySyncedMouseEvent(e){this.currentSyncedMouseEvents.add(e[2]);const t=new MouseEvent(e[2],{bubbles:!0,cancelable:!0,view:window,...e[3]});document.body.dispatchEvent(t)}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=window.location.href,s=e.apply(window.history,o);return window.location.href!==r&&this.postMessageToParent(["df-child","stateChange","push",window.location.href]),s};window.history.pushState=t;const i=(...o)=>{const r=window.location.href,s=e.apply(window.history,o);return window.location.href!==r&&this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),s};window.history.replaceState=i}createMutationObserver(){const e=document.querySelector("body");if(!e)throw new Error("DFrameContentManager was initialized before the HTML body");if(!this.throttledCheckHeight)throw new Error("throttledCheckHeight is not defined");new window.MutationObserver(this.throttledCheckHeight).observe(e,{attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0})}createWindowEventListeners(){if(!this.throttledCheckHeight)throw new Error("throttledCheckHeight is not defined");for(const e of g)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");if(r==="false"||r==="no")continue;const s=o.getBoundingClientRect().bottom+parseFloat(getComputedStyle(o).getPropertyValue("margin-bottom")),d=r?s+parseFloat(r):s;s>t&&(t=s),d>i&&(i=d)}i=Math.ceil(i),t>0&&i!==this.lastHeight&&(this.postMessageToParent(["df-child","height",i]),this.lastHeight=i)}}const b=(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]})};function m(n){var t;const e=n.options;return e.base??((t=e.history)==null?void 0:t.base)}const f=new p({updateSrc(n,e){const t=window.vIframeOptions,i=t==null?void 0:t.reactiveParams;if(i&&typeof i=="object"){const r=new URL(n);if(r.origin===window.location.origin&&r.pathname===window.location.pathname){e.log("debug","applying reactive params",r.searchParams),b(i,r.searchParams);return}}const o=t==null?void 0:t.router;if(o){const r=m(o);if(r==null)e.log("error","failed to access base path in router (no router.options.base nor router.options.history.base)",o);else{const s=window.location.origin+r;if(!n.startsWith(s))e.log("info","src does not start with base path",n,s);else{let d=n.replace(s,"");d.startsWith("/")||(d="/"+d),e.log("debug","applying router.replace",d),o.replace(d);return}}}e.log("info","falling back to updating window.location.href",n),window.location.href=n}});return window.dFrameContent=f,f}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import DFrameContent from '../DFrameContent.js';
|
|
2
2
|
import { applySearchParams } from '../vue-reactive/util.js';
|
|
3
|
+
import { getRouterBase } from '../vue-router/util.js';
|
|
3
4
|
const dFrameContent = new DFrameContent({
|
|
4
5
|
updateSrc(src, instance) {
|
|
5
6
|
const vIframeOptions = window.vIframeOptions;
|
|
@@ -14,8 +15,7 @@ const dFrameContent = new DFrameContent({
|
|
|
14
15
|
}
|
|
15
16
|
const router = vIframeOptions?.router;
|
|
16
17
|
if (router) {
|
|
17
|
-
|
|
18
|
-
const base = router.options?.base ?? router.options.history?.base;
|
|
18
|
+
const base = getRouterBase(router);
|
|
19
19
|
if (base === null || base === undefined) {
|
|
20
20
|
instance.log('error', 'failed to access base path in router (no router.options.base nor router.options.history.base)', router);
|
|
21
21
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { inject } from 'vue';
|
|
2
2
|
import DFrameContent from '../DFrameContent.js';
|
|
3
|
+
import { getRouterBase } from './util.js';
|
|
3
4
|
let dFrameContent = null;
|
|
4
5
|
export function vueRouterDFrameContent(router, options) {
|
|
5
6
|
if (dFrameContent)
|
|
@@ -7,8 +8,7 @@ export function vueRouterDFrameContent(router, options) {
|
|
|
7
8
|
dFrameContent = new DFrameContent({
|
|
8
9
|
...options,
|
|
9
10
|
updateSrc: (src, instance) => {
|
|
10
|
-
|
|
11
|
-
const base = router.options?.base ?? router.options.history?.base;
|
|
11
|
+
const base = getRouterBase(router);
|
|
12
12
|
if (base === null || base === undefined) {
|
|
13
13
|
instance.log('error', 'failed to access base path in router (no router.options.base nor router.options.history.base)', router);
|
|
14
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { getRouterBase } from './util.js';
|
|
1
2
|
class VueRouterDFrameStateChangeAdapter {
|
|
2
3
|
router;
|
|
3
4
|
constructor(router) {
|
|
4
5
|
this.router = router;
|
|
5
6
|
}
|
|
6
7
|
stateChange(action, newUrl, element) {
|
|
7
|
-
|
|
8
|
-
const base = this.router.options?.base ?? this.router.options.history?.base;
|
|
8
|
+
const base = getRouterBase(this.router);
|
|
9
9
|
if (base === null || base === undefined) {
|
|
10
10
|
throw new Error('failed to access base path in router (no router.options.base nor router.options.history.base)');
|
|
11
11
|
}
|