@data-fair/frame 0.18.3 → 0.18.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.
@@ -1,2 +1,2 @@
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 e;return n.options.base??((e=n.options.history)==null?void 0:e.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}();
1
+ var VIframeCompatDFrameContent=function(){"use strict";var M=Object.defineProperty;var v=(c,d,l)=>d in c?M(c,d,{enumerable:!0,configurable:!0,writable:!0,value:l}):c[d]=l;var h=(c,d,l)=>v(c,typeof d!="symbol"?d+"":d,l);function c(n){return n[0]==="df-global"&&n[1]==="mouse"}function d(n){return n[0]==="df-parent"&&n[1]==="init"}function l(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}function g(n){return n[0]==="df-parent"&&n[1]==="parentUrl"}const p=(()=>{try{return window.top!==window.self}catch{return!0}})(),b=["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 m{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);h(this,"parentUrlListeners",{});h(this,"parentUrlResults",{});h(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(d(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),g(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(!p){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 b)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")),a=r?s+parseFloat(r):s;s>t&&(t=s),a>i&&(i=a)}i=Math.ceil(i),t>0&&i!==this.lastHeight&&(this.postMessageToParent(["df-child","height",i]),this.lastHeight=i)}}const y=(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]})},w=new m({updateSrc(n,e){var r,s;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),y(i,a.searchParams);return}}const o=t==null?void 0:t.router;if(o){const a=((r=o.options)==null?void 0:r.base)??((s=o.options.history)==null?void 0:s.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=w,w}();
2
2
  //# sourceMappingURL=d-frame-content.min.js.map
@@ -1,5 +1,5 @@
1
1
  import DFrameContent from '../DFrameContent.js';
2
- import type { Router } from '../vue-router/util.js';
2
+ import type { Router } from 'vue-router';
3
3
  export type VIframeOptions = {
4
4
  router?: Router;
5
5
  reactiveParams?: Record<string, string> | boolean;
@@ -1,6 +1,5 @@
1
1
  import DFrameContent from '../DFrameContent.js';
2
2
  import { applySearchParams } from '../vue-reactive/util.js';
3
- import { getRouterBase } from '../vue-router/util.js';
4
3
  const dFrameContent = new DFrameContent({
5
4
  updateSrc(src, instance) {
6
5
  const vIframeOptions = window.vIframeOptions;
@@ -15,7 +14,8 @@ const dFrameContent = new DFrameContent({
15
14
  }
16
15
  const router = vIframeOptions?.router;
17
16
  if (router) {
18
- const base = getRouterBase(router);
17
+ // @ts-ignore vue-router v2
18
+ const base = router.options?.base ?? router.options.history?.base;
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,6 +1,6 @@
1
1
  import { type Ref } from 'vue';
2
2
  import type DFrameContent from '../DFrameContent.js';
3
- import type { Router } from '../vue-router/router-type.js';
3
+ import type { Router } from 'vue-router';
4
4
  export declare const useDFrameParentUrls: (dFrameContent: DFrameContent, router?: Router) => {
5
5
  get: (childHref: string) => Ref<string | undefined>;
6
6
  clear: () => void;
@@ -1,6 +1,6 @@
1
1
  import { type App } from 'vue';
2
2
  import DFrameContent, { type DFrameContentOptions } from '../DFrameContent.js';
3
- import type { Router } from './util.js';
3
+ import type { Router } from 'vue-router';
4
4
  type VueRouterDFrameContentOptions = Omit<DFrameContentOptions, 'updateSrc'>;
5
5
  export declare function vueRouterDFrameContent(router: Router, options?: VueRouterDFrameContentOptions): DFrameContent;
6
6
  export declare const vueRouterDFrameContentKey: unique symbol;
@@ -1,6 +1,5 @@
1
1
  import { inject } from 'vue';
2
2
  import DFrameContent from '../DFrameContent.js';
3
- import { getRouterBase } from './util.js';
4
3
  let dFrameContent = null;
5
4
  export function vueRouterDFrameContent(router, options) {
6
5
  if (dFrameContent)
@@ -8,7 +7,8 @@ export function vueRouterDFrameContent(router, options) {
8
7
  dFrameContent = new DFrameContent({
9
8
  ...options,
10
9
  updateSrc: (src, instance) => {
11
- const base = getRouterBase(router);
10
+ // @ts-ignore vue-router v2
11
+ const base = router.options?.base ?? router.options.history?.base;
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,5 +1,5 @@
1
1
  import { type DFrameElement, type StateChangeAdapter } from '../DFrameElement.js';
2
- import type { Router } from './util.js';
2
+ import type { Router } from 'vue-router';
3
3
  declare class VueRouterDFrameStateChangeAdapter implements StateChangeAdapter {
4
4
  router: Router;
5
5
  constructor(router: Router);
@@ -1,11 +1,11 @@
1
- import { getRouterBase } from './util.js';
2
1
  class VueRouterDFrameStateChangeAdapter {
3
2
  router;
4
3
  constructor(router) {
5
4
  this.router = router;
6
5
  }
7
6
  stateChange(action, newUrl, element) {
8
- const base = getRouterBase(this.router);
7
+ // @ts-ignore vue-router v2
8
+ const base = this.router.options?.base ?? this.router.options.history?.base;
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
  }
@@ -1,5 +1,5 @@
1
1
  import { type MaybeRefOrGetter } from 'vue';
2
- import type { Router, RouteLocationRaw } from './router-type.js';
2
+ import type { RouteLocationRaw, Router } from 'vue-router';
3
3
  import type DFrameContent from '../DFrameContent.js';
4
4
  export declare const useParentUrl: (location: MaybeRefOrGetter<RouteLocationRaw | undefined>, router: Router, dFrameContent?: DFrameContent) => import("vue").ComputedRef<string | undefined> | import("vue").Ref<string | null | undefined, string | null | undefined>;
5
5
  export default useParentUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/frame",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "description": "An iframe wrapper for powerful web app integrations.",
5
5
  "main": "dist/frame.min.js",
6
6
  "directories": {