@data-fair/frame 0.5.0 → 0.6.0
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/d-frame.min.js +2 -2
- package/dist/v-iframe-compat/d-frame-content.min.js +1 -1
- package/lib/DFrameContent.d.ts +1 -0
- package/lib/DFrameContent.js +7 -2
- package/lib/DFrameElement.d.ts +4 -0
- package/lib/DFrameElement.js +39 -9
- package/lib/messages.d.ts +1 -0
- package/lib/v-iframe-compat/d-frame-content.js +2 -8
- package/lib/vue-reactive/d-frame-content.d.ts +5 -0
- package/lib/vue-reactive/d-frame-content.js +17 -0
- package/lib/vue-reactive/state-change-adapter.d.ts +10 -0
- package/lib/vue-reactive/state-change-adapter.js +15 -0
- package/lib/vue-reactive/util.d.ts +1 -0
- package/lib/vue-reactive/util.js +10 -0
- package/package.json +2 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var DFrameContent=function(){"use strict";var g=Object.defineProperty;var
|
|
1
|
+
var DFrameContent=function(){"use strict";var g=Object.defineProperty;var l=(a,i,s)=>i in a?g(a,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[i]=s;var n=(a,i,s)=>l(a,typeof i!="symbol"?i+"":i,s);function a(r){return r[0]==="df-parent"&&r[1]==="init"}function i(r){return r[0]==="df-parent"&&r[1]==="updateSrc"}const s=["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 c{constructor(e){n(this,"initialized",!1);n(this,"options");n(this,"pendingCheckHeight",!1);n(this,"debug",!1);n(this,"id");n(this,"throttledCheckHeight");n(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",o=>this.onMessage(o)),this.postMessageToParent(["df-child","init"]))}log(e,...t){e==="debug"&&!this.debug||(e==="debug"&&console.timeLog(`${this.id}:d-frame-content`,...t),e==="info"&&console.info(`${this.id}:d-frame-content`,...t))}onMessage(e){if(e.source===window.parent&&Array.isArray(e.data)){const t=e.data;a(t)&&(this.id=t[2].id,this.debug=!!t[2].debug,this.debug&&console.time(`${this.id}:d-frame-content`),t[2].resize!=="no"&&this.initResize(),(t[2].syncParams||t[2].syncPath||t[2].stateChangeEvents)&&this.initStateChangeWatcher(),this.initialized=!0),i(t)&&(this.options.updateSrc?this.options.updateSrc(t[2].startsWith("/")?window.location.origin+t[2]:t[2]):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])}initResize(){this.log("debug","initResize"),this.checkHeight(),this.createMutationObserver(),this.createWindowEventListeners()}initStateChangeWatcher(){this.log("debug","initStateChangeWatcher");const e=window.history.replaceState,t=(...h)=>{const d=e.apply(window.history,h);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),d};window.history.pushState=t;const o=(...h)=>{const d=e.apply(window.history,h);return this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),d};window.history.replaceState=o}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 s)window.addEventListener(e,this.throttledCheckHeight,{passive:!0})}checkHeight(){const e=document.querySelectorAll("[data-iframe-height]");let t=0;for(const o of e){const h=o.getAttribute("data-iframe-height"),d=o.getBoundingClientRect().bottom+parseFloat(getComputedStyle(o).getPropertyValue("margin-bottom"))+(h?parseFloat(h):0);d>t&&(t=d)}t=Math.ceil(t),t!==this.lastHeight&&(this.postMessageToParent(["df-child","height",t]),this.lastHeight=t)}}return new c}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
package/dist/d-frame.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var H=Object.defineProperty;var M=(
|
|
1
|
+
var H=Object.defineProperty;var M=(u,c,g)=>c in u?H(u,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[c]=g;var o=(u,c,g)=>M(u,typeof c!="symbol"?c+"":c,g);(function(){"use strict";function u(e){return e[0]==="df-child"&&e[1]==="init"}function c(e){return e[0]==="df-child"&&e[1]==="height"}function g(e){return e[0]==="df-child"&&e[1]==="stateChange"}function m(e){return e[0]==="df-child"&&e[1]==="custom"}function b(e){return e[0]==="df-child"&&e[1]==="notif"}function y(e){return e.endsWith("/")?e:e===""?"/":e.slice(0,e.lastIndexOf("/")+1)}function w(e,a){if(a.origin!==e.origin)return a.href;if(a.pathname===e.pathname)return"";const t=y(e.pathname);return a.pathname.startsWith(t)?a.pathname.replace(t,"./"):a.pathname}const A=e=>e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&");function E(e){const a=[];for(const t of e.split(",")){const[s="*",i]=t.split(":"),r="^"+A(s).replace(/\\\*/g,"(.*)")+"$";a.push({regexp:new RegExp(r),append:i})}return a}function z(e,a,t,s){if(!t&&!s)return e.href;const i=new URL(a);if(t&&i.searchParams.forEach((r,l)=>{for(const n of t){if(n.append&&!l.startsWith(n.append)||l===s)continue;const h=n.append?l.replace(n.append,""):l;if(h.match(n.regexp)){e.searchParams.set(h,r);break}}}),s!==null){const r=i.searchParams.get(s);r&&(e.pathname=new URL(r,e).pathname)}return e.href}function R(e,a,t,s,i){const r=new URL(t),l=new URL(a);if(s&&(r.searchParams.forEach((n,h)=>{for(const d of s){if(d.append&&!h.startsWith(d.append))continue;const f=d.append?h.replace(d.append,""):h;if(f.match(d.regexp)){l.searchParams.get(f)===null&&r.searchParams.delete(h);break}}}),l.searchParams.forEach((n,h)=>{for(const d of s){if(!h.match(d.regexp)||(e==null?void 0:e.searchParams.get(h))===n)continue;const f=d.append?d.append+h:h;r.searchParams.set(f,n);break}})),i!==null&&e){const n=w(e,l);n?r.searchParams.set(i,n):r.searchParams.delete(i)}return r}function S(e){return e.vIframe===!0&&e.uiNotification!==void 0}function v(e){if(typeof e=="string")return{type:"default",title:e};if(e.error&&!e.errorMsg){const a=e.error.response&&(e.error.response.data||e.error.response.status)||e.error.message||e.error;return e.msg?{type:"error",title:e.msg,detail:a}:{type:"error",title:a}}return e.type==="error"?{type:e.clientError?"warning":"error",title:e.msg,detail:e.errorMsg}:{type:e.type??"default",title:e.msg}}class P{stateChange(a,t){a==="replace"&&window.history.replaceState(null,"",t),a==="push"&&window.history.pushState(null,"",t)}}const p=document.createElement("template");p.innerHTML=`<style>
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
}
|
|
@@ -8,5 +8,5 @@ var H=Object.defineProperty;var M=(d,c,p)=>c in d?H(d,c,{enumerable:!0,configura
|
|
|
8
8
|
height: 100%;
|
|
9
9
|
border: none;
|
|
10
10
|
}
|
|
11
|
-
</style><slot name="loader"></slot><iframe class="d-frame-iframe" frameborder="0">`;class C extends HTMLElement{constructor(){super();o(this,"adapter");o(this,"connected",!1);o(this,"initialSrc");o(this,"srcUrl");o(this,"parsedSyncParams");o(this,"iframeElement");o(this,"slotElement");o(this,"width");o(this,"aspectRatioHeight");o(this,"resizedHeight");const t=
|
|
11
|
+
</style><slot name="loader"></slot><iframe class="d-frame-iframe" frameborder="0">`;class C extends HTMLElement{constructor(){super();o(this,"adapter");o(this,"connected",!1);o(this,"initialSrc");o(this,"srcUrl");o(this,"parsedSyncParams");o(this,"iframeElement");o(this,"slotElement");o(this,"width");o(this,"aspectRatioHeight");o(this,"resizedHeight");o(this,"randomId");this.randomId=Math.random().toString(36).slice(-6);const t=p.content.cloneNode(!0);this.slotElement=t.childNodes[1],this.resize!=="yes"&&(this.slotElement.style.display="none"),this.iframeElement=t.childNodes[2],this.iframeElement.setAttribute("scrolling",this.resize==="yes"?"no":"auto"),this.iframeElement.setAttribute("loading",this.lazy?"lazy":"eager"),this.attachShadow({mode:"open"}).appendChild(t),new ResizeObserver(r=>{(this.width===void 0||Math.abs(this.width-r[0].contentRect.width)>2)&&(this.width=r[0].contentRect.width,this.updateAspectRatioHeight())}).observe(this),this.adapter=new P,window.addEventListener("message",r=>this.onMessage(r))}get id(){return this.getAttribute("id")??this.randomId}set id(t){this.setAttribute("id",t)}get debug(){return this.hasAttribute("debug")}set debug(t){t?this.setAttribute("debug",""):this.removeAttribute("debug")}get lazy(){return this.hasAttribute("lazy")}set lazy(t){t?this.setAttribute("lazy",""):this.removeAttribute("lazy")}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t)}get aspectRatio(){const t=this.getAttribute("aspect-ratio");return t===""?"auto":t}set aspectRatio(t){t!==null?this.setAttribute("aspect-ratio",t):this.removeAttribute("aspect-ratio")}get height(){return this.getAttribute("height")}set height(t){t?this.setAttribute("height",t):this.removeAttribute("height")}set resize(t){this.setAttribute("resize",t)}get resize(){const t=this.getAttribute("resize");return t===null?"auto":t===""?"yes":t}get syncParams(){return this.getAttribute("sync-params")}set syncParams(t){t!==null?this.setAttribute("sync-params",t):this.removeAttribute("sync-params")}get syncPath(){const t=this.getAttribute("sync-path");return t===null?null:t||"p"}set syncPath(t){t!==null?this.setAttribute("sync-params",t):this.removeAttribute("sync-params")}get stateChangeEvents(){return this.hasAttribute("state-change-events")}set stateChangeEvents(t){t?this.setAttribute("state-change-events",""):this.removeAttribute("state-change-events")}get actualAspectRatio(){return this.aspectRatio!=="auto"?Number(this.aspectRatio):!this.width||this.width<500?1:this.width<800?4/3:this.width<1200?16/9:21/9}onMessage(t){var s;if(t.source===((s=this.iframeElement)==null?void 0:s.contentWindow)){const i=t.data;if(this.log("debug","received message from child",i),Array.isArray(t.data)){if(u(i)&&(this.postMessageToChild(["df-parent","init",{id:this.id,debug:this.debug,resize:this.resize,syncParams:this.syncParams!==null,syncPath:this.syncPath!==null,stateChangeEvents:this.stateChangeEvents}]),this.init()),c(i)&&(this.resizedHeight=i[2],this.updateStyle()),g(i)){if(this.parsedSyncParams||this.syncPath){const r=R(this.srcUrl,i[3],window.location.href,this.parsedSyncParams,this.syncPath);r.href!==window.location.href&&this.adapter.stateChange(i[2],r)}this.stateChangeEvents&&this.dispatchEvent(new CustomEvent("state-change",{detail:[i[2],i[3]]}))}m(i)&&this.dispatchEvent(new CustomEvent("message",{detail:i[2]})),b(i)&&this.dispatchEvent(new CustomEvent("notif",{detail:i[2]}))}else S(i)&&this.dispatchEvent(new CustomEvent("notif",{detail:v(i.uiNotification)}))}}init(){this.initialSrc=this.src}postMessageToChild(t){var s,i;this.log("debug","send message to child",t),(i=(s=this.iframeElement)==null?void 0:s.contentWindow)==null||i.postMessage(t)}updateSrc(){if(!this.connected)return;this.srcUrl=new URL(this.src.startsWith("/")?window.location.origin+this.src:this.src);const t=z(this.srcUrl,window.location.href,this.parsedSyncParams,this.syncPath);this.initialSrc?this.postMessageToChild(["df-parent","updateSrc",t]):(this.log("debug","set src attribute of iframe: "+t),this.iframeElement.setAttribute("src",t))}updateStyle(){if(!this.connected)return;let t="";(this.resize==="yes"||this.resize==="auto"&&this.resizedHeight)&&(this.iframeElement.getAttribute("scrolling")!=="no"&&(this.log("debug","set scrolling attribute of iframe: no"),this.iframeElement.setAttribute("scrolling","no")),this.resizedHeight?(this.log("debug","height of iframe based on resize message: "+this.resizedHeight),this.slotElement.style.display="none",t+=`height:${this.resizedHeight}px;`):this.height?(this.log("debug","height of iframe based on direct attribute: "+this.height),this.slotElement.style.display="none",t+=`height:${this.height};`):this.aspectRatio!=="auto"&&this.aspectRatio!==null?(this.log("debug","height of iframe based on aspect ratio: "+this.aspectRatioHeight),this.slotElement.style.display="none",t+=`height:${this.aspectRatioHeight}px;`):(this.log("debug","use slot element while waiting for resize message"),this.slotElement.style.display="block",t+="height:0;")),(this.resize==="no"||this.resize==="auto"&&!this.resizedHeight)&&(this.iframeElement.getAttribute("scrolling")!=="auto"&&(this.log("debug","set scrolling attribute of iframe: auto"),this.iframeElement.setAttribute("scrolling","auto")),this.height?(this.log("debug","height of iframe based on direct attribute: "+this.height),t+=`height:${this.height};`):this.aspectRatio!==null&&(this.log("debug","height of iframe based on aspect ratio: "+this.aspectRatioHeight),t+=`height:${this.aspectRatioHeight}px;`)),this.log("debug","set style attribute of iframe: "+t),this.iframeElement.setAttribute("style",t)}updateAspectRatioHeight(){this.width&&this.aspectRatio!==null&&(this.resizedHeight||this.height||(this.aspectRatioHeight=Math.ceil(this.width/this.actualAspectRatio),this.updateStyle()))}log(t,...s){t==="debug"&&!this.debug||(t==="debug"&&console.timeLog(`${this.id}:d-frame`,...s),t==="info"&&console.info(`${this.id}:d-frame`,...s))}connectedCallback(){if(this.debug&&console.time(`${this.id}:d-frame`),!this.hasAttribute("src"))throw new Error("src is a required attribute");this.log("debug","connected"),this.connected=!0,this.adapter.onStateChange&&this.adapter.onStateChange(()=>{this.updateSrc()}),this.syncParams!==null&&(this.parsedSyncParams=E(this.syncParams||"*")),this.updateStyle(),this.updateSrc()}disconnectedCallback(){this.log("debug","disconnected"),this.debug&&console.timeEnd(`[${this.id}:d-frame]`)}static get observedAttributes(){return["src","aspect-ratio","height","sync-params","sync-path"]}attributeChangedCallback(t,s,i){t==="aspect-ratio"&&this.updateAspectRatioHeight(),this.connected&&(this.log("debug","attribute change",t,s,i),t==="src"&&this.updateSrc(),t==="height"&&this.updateStyle(),t==="sync-params"&&this.updateSrc(),t==="sync-path"&&this.updateSrc())}}customElements.define("d-frame",C)})();
|
|
12
12
|
//# sourceMappingURL=d-frame.min.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var VIframeCompatDFrameContent=function(){"use strict";var g=Object.defineProperty;var f=(
|
|
1
|
+
var VIframeCompatDFrameContent=function(){"use strict";var g=Object.defineProperty;var f=(r,o,h)=>o in r?g(r,o,{enumerable:!0,configurable:!0,writable:!0,value:h}):r[o]=h;var s=(r,o,h)=>f(r,typeof o!="symbol"?o+"":o,h);function r(n){return n[0]==="df-parent"&&n[1]==="init"}function o(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}const h=["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 l{constructor(t){s(this,"initialized",!1);s(this,"options");s(this,"pendingCheckHeight",!1);s(this,"debug",!1);s(this,"id");s(this,"throttledCheckHeight");s(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(`${this.id}:d-frame-content`,...e),t==="info"&&console.info(`${this.id}:d-frame-content`,...e))}onMessage(t){if(t.source===window.parent&&Array.isArray(t.data)){const e=t.data;r(e)&&(this.id=e[2].id,this.debug=!!e[2].debug,this.debug&&console.time(`${this.id}:d-frame-content`),e[2].resize!=="no"&&this.initResize(),(e[2].syncParams||e[2].syncPath||e[2].stateChangeEvents)&&this.initStateChangeWatcher(),this.initialized=!0),o(e)&&(this.options.updateSrc?this.options.updateSrc(e[2].startsWith("/")?window.location.origin+e[2]:e[2]):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])}initResize(){this.log("debug","initResize"),this.checkHeight(),this.createMutationObserver(),this.createWindowEventListeners()}initStateChangeWatcher(){this.log("debug","initStateChangeWatcher");const t=window.history.replaceState,e=(...a)=>{const d=t.apply(window.history,a);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),d};window.history.pushState=e;const i=(...a)=>{const d=t.apply(window.history,a);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 h)window.addEventListener(t,this.throttledCheckHeight,{passive:!0})}checkHeight(){const t=document.querySelectorAll("[data-iframe-height]");let e=0;for(const i of t){const a=i.getAttribute("data-iframe-height"),d=i.getBoundingClientRect().bottom+parseFloat(getComputedStyle(i).getPropertyValue("margin-bottom"))+(a?parseFloat(a):0);d>e&&(e=d)}e=Math.ceil(e),e!==this.lastHeight&&(this.postMessageToParent(["df-child","height",e]),this.lastHeight=e)}}const u=(n,t)=>{const e=Object.keys(n);t.forEach((i,a)=>{n[a]=i,e.splice(e.indexOf(a),1)}),e.forEach(i=>{delete n[i]})},c=new l({updateSrc:n=>{const t=window.vIframeOptions,e=t==null?void 0:t.reactiveParams;if(e){const i=new URL(n);if(i.origin===window.location.origin&&i.pathname===window.location.pathname){u(e,i.searchParams);return}}if(t!=null&&t.router){const i=window.location.origin+t.router.options.history.base;if(n.startsWith(i)){t.router.replace(n.replace(i,""));return}}window.location.href=n}});return window.dFrameContent=c,c}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
package/lib/DFrameContent.d.ts
CHANGED
package/lib/DFrameContent.js
CHANGED
|
@@ -35,6 +35,7 @@ export default class DFrameContent {
|
|
|
35
35
|
options;
|
|
36
36
|
pendingCheckHeight = false;
|
|
37
37
|
debug = false;
|
|
38
|
+
id;
|
|
38
39
|
throttledCheckHeight;
|
|
39
40
|
lastHeight = 0;
|
|
40
41
|
constructor(options) {
|
|
@@ -59,15 +60,18 @@ export default class DFrameContent {
|
|
|
59
60
|
if (level === 'debug' && !this.debug)
|
|
60
61
|
return;
|
|
61
62
|
if (level === 'debug')
|
|
62
|
-
console.
|
|
63
|
+
console.timeLog(`${this.id}:d-frame-content`, ...args);
|
|
63
64
|
if (level === 'info')
|
|
64
|
-
console.info(
|
|
65
|
+
console.info(`${this.id}:d-frame-content`, ...args);
|
|
65
66
|
}
|
|
66
67
|
onMessage(e) {
|
|
67
68
|
if (e.source === window.parent && Array.isArray(e.data)) {
|
|
68
69
|
const message = e.data;
|
|
69
70
|
if (isInitParentMessage(message)) {
|
|
71
|
+
this.id = message[2].id;
|
|
70
72
|
this.debug = !!message[2].debug;
|
|
73
|
+
if (this.debug)
|
|
74
|
+
console.time(`${this.id}:d-frame-content`);
|
|
71
75
|
if (message[2].resize !== 'no')
|
|
72
76
|
this.initResize();
|
|
73
77
|
if (message[2].syncParams || message[2].syncPath || message[2].stateChangeEvents)
|
|
@@ -148,6 +152,7 @@ export default class DFrameContent {
|
|
|
148
152
|
if (bottom > max)
|
|
149
153
|
max = bottom;
|
|
150
154
|
}
|
|
155
|
+
max = Math.ceil(max);
|
|
151
156
|
if (max !== this.lastHeight) {
|
|
152
157
|
this.postMessageToParent(['df-child', 'height', max]);
|
|
153
158
|
this.lastHeight = max;
|
package/lib/DFrameElement.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface StateChangeAdapter {
|
|
|
4
4
|
onStateChange?(callback: () => void): void;
|
|
5
5
|
}
|
|
6
6
|
export default class DFrameElement extends HTMLElement {
|
|
7
|
+
get id(): string;
|
|
8
|
+
set id(value: string);
|
|
7
9
|
get debug(): boolean;
|
|
8
10
|
set debug(value: boolean);
|
|
9
11
|
get lazy(): boolean;
|
|
@@ -32,6 +34,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
32
34
|
private width;
|
|
33
35
|
private aspectRatioHeight;
|
|
34
36
|
private resizedHeight;
|
|
37
|
+
private randomId;
|
|
35
38
|
get actualAspectRatio(): number;
|
|
36
39
|
constructor();
|
|
37
40
|
onMessage(e: MessageEvent): void;
|
|
@@ -42,6 +45,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
42
45
|
updateAspectRatioHeight(): void;
|
|
43
46
|
log(level: 'debug' | 'info', ...args: any[]): void;
|
|
44
47
|
connectedCallback(): void;
|
|
48
|
+
disconnectedCallback(): void;
|
|
45
49
|
static get observedAttributes(): string[];
|
|
46
50
|
attributeChangedCallback(name: string, oldValue: any, newValue: any): void;
|
|
47
51
|
}
|
package/lib/DFrameElement.js
CHANGED
|
@@ -23,6 +23,10 @@ template.innerHTML = `<style>
|
|
|
23
23
|
}
|
|
24
24
|
</style><slot name="loader"></slot><iframe class="d-frame-iframe" frameborder="0">`;
|
|
25
25
|
export default class DFrameElement extends HTMLElement {
|
|
26
|
+
get id() { return this.getAttribute('id') ?? this.randomId; }
|
|
27
|
+
set id(value) {
|
|
28
|
+
this.setAttribute('id', value);
|
|
29
|
+
}
|
|
26
30
|
get debug() { return this.hasAttribute('debug'); }
|
|
27
31
|
set debug(value) {
|
|
28
32
|
if (value)
|
|
@@ -104,6 +108,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
104
108
|
width;
|
|
105
109
|
aspectRatioHeight;
|
|
106
110
|
resizedHeight;
|
|
111
|
+
randomId;
|
|
107
112
|
get actualAspectRatio() {
|
|
108
113
|
if (this.aspectRatio !== 'auto')
|
|
109
114
|
return Number(this.aspectRatio);
|
|
@@ -117,6 +122,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
117
122
|
}
|
|
118
123
|
constructor() {
|
|
119
124
|
super();
|
|
125
|
+
this.randomId = Math.random().toString(36).slice(-6);
|
|
120
126
|
const root = template.content.cloneNode(true);
|
|
121
127
|
this.slotElement = root.childNodes[1];
|
|
122
128
|
if (this.resize !== 'yes')
|
|
@@ -133,7 +139,6 @@ export default class DFrameElement extends HTMLElement {
|
|
|
133
139
|
this.updateAspectRatioHeight();
|
|
134
140
|
}
|
|
135
141
|
});
|
|
136
|
-
// TODO: should we use unobserve or disconnect on cleanup ?
|
|
137
142
|
resizeObserver.observe(this);
|
|
138
143
|
this.adapter = new WindowStateChangeAdapter();
|
|
139
144
|
window.addEventListener('message', (e) => this.onMessage(e));
|
|
@@ -146,6 +151,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
146
151
|
if (isInitChildMessage(message)) {
|
|
147
152
|
// simple handshake for initialization
|
|
148
153
|
this.postMessageToChild(['df-parent', 'init', {
|
|
154
|
+
id: this.id,
|
|
149
155
|
debug: this.debug,
|
|
150
156
|
resize: this.resize,
|
|
151
157
|
syncParams: this.syncParams !== null,
|
|
@@ -177,7 +183,6 @@ export default class DFrameElement extends HTMLElement {
|
|
|
177
183
|
}
|
|
178
184
|
}
|
|
179
185
|
else if (isVIframeUiNotif(message)) {
|
|
180
|
-
console.log('v-iframe notification', message.uiNotification, convertVIframeUiNotif(message.uiNotification));
|
|
181
186
|
// maintain compatibility with v-iframe notifications sent through postMessage
|
|
182
187
|
this.dispatchEvent(new CustomEvent('notif', { detail: convertVIframeUiNotif(message.uiNotification) }));
|
|
183
188
|
}
|
|
@@ -200,41 +205,57 @@ export default class DFrameElement extends HTMLElement {
|
|
|
200
205
|
this.postMessageToChild(['df-parent', 'updateSrc', fullSrc]);
|
|
201
206
|
}
|
|
202
207
|
else {
|
|
208
|
+
this.log('debug', 'set src attribute of iframe: ' + fullSrc);
|
|
203
209
|
this.iframeElement.setAttribute('src', fullSrc);
|
|
204
210
|
}
|
|
205
211
|
}
|
|
206
212
|
updateStyle() {
|
|
213
|
+
if (!this.connected)
|
|
214
|
+
return;
|
|
207
215
|
let style = '';
|
|
208
216
|
if (this.resize === 'yes' || (this.resize === 'auto' && this.resizedHeight)) {
|
|
209
|
-
this.iframeElement.
|
|
217
|
+
if (this.iframeElement.getAttribute('scrolling') !== 'no') {
|
|
218
|
+
this.log('debug', 'set scrolling attribute of iframe: no');
|
|
219
|
+
this.iframeElement.setAttribute('scrolling', 'no');
|
|
220
|
+
}
|
|
210
221
|
if (this.resizedHeight) {
|
|
222
|
+
this.log('debug', 'height of iframe based on resize message: ' + this.resizedHeight);
|
|
211
223
|
this.slotElement.style.display = 'none';
|
|
212
224
|
style += `height:${this.resizedHeight}px;`;
|
|
213
225
|
}
|
|
214
226
|
else {
|
|
215
227
|
if (this.height) {
|
|
228
|
+
this.log('debug', 'height of iframe based on direct attribute: ' + this.height);
|
|
216
229
|
this.slotElement.style.display = 'none';
|
|
217
230
|
style += `height:${this.height};`;
|
|
218
231
|
}
|
|
219
232
|
else if (this.aspectRatio !== 'auto' && this.aspectRatio !== null) {
|
|
233
|
+
this.log('debug', 'height of iframe based on aspect ratio: ' + this.aspectRatioHeight);
|
|
220
234
|
this.slotElement.style.display = 'none';
|
|
221
235
|
style += `height:${this.aspectRatioHeight}px;`;
|
|
222
236
|
}
|
|
223
237
|
else {
|
|
238
|
+
this.log('debug', 'use slot element while waiting for resize message');
|
|
224
239
|
this.slotElement.style.display = 'block';
|
|
225
240
|
style += 'height:0;';
|
|
226
241
|
}
|
|
227
242
|
}
|
|
228
243
|
}
|
|
229
244
|
if (this.resize === 'no' || (this.resize === 'auto' && !this.resizedHeight)) {
|
|
230
|
-
this.iframeElement.
|
|
245
|
+
if (this.iframeElement.getAttribute('scrolling') !== 'auto') {
|
|
246
|
+
this.log('debug', 'set scrolling attribute of iframe: auto');
|
|
247
|
+
this.iframeElement.setAttribute('scrolling', 'auto');
|
|
248
|
+
}
|
|
231
249
|
if (this.height) {
|
|
250
|
+
this.log('debug', 'height of iframe based on direct attribute: ' + this.height);
|
|
232
251
|
style += `height:${this.height};`;
|
|
233
252
|
}
|
|
234
253
|
else if (this.aspectRatio !== null) {
|
|
254
|
+
this.log('debug', 'height of iframe based on aspect ratio: ' + this.aspectRatioHeight);
|
|
235
255
|
style += `height:${this.aspectRatioHeight}px;`;
|
|
236
256
|
}
|
|
237
257
|
}
|
|
258
|
+
this.log('debug', 'set style attribute of iframe: ' + style);
|
|
238
259
|
this.iframeElement.setAttribute('style', style);
|
|
239
260
|
}
|
|
240
261
|
updateAspectRatioHeight() {
|
|
@@ -253,12 +274,15 @@ export default class DFrameElement extends HTMLElement {
|
|
|
253
274
|
if (level === 'debug' && !this.debug)
|
|
254
275
|
return;
|
|
255
276
|
if (level === 'debug')
|
|
256
|
-
console.
|
|
277
|
+
console.timeLog(`${this.id}:d-frame`, ...args);
|
|
278
|
+
// if (level === 'debug') console.debug(`${this.id}:d-frame`, ...args)
|
|
257
279
|
if (level === 'info')
|
|
258
|
-
console.info(
|
|
280
|
+
console.info(`${this.id}:d-frame`, ...args);
|
|
259
281
|
}
|
|
260
282
|
/* standard custom element callbacks */
|
|
261
283
|
connectedCallback() {
|
|
284
|
+
if (this.debug)
|
|
285
|
+
console.time(`${this.id}:d-frame`);
|
|
262
286
|
if (!this.hasAttribute('src'))
|
|
263
287
|
throw new Error('src is a required attribute');
|
|
264
288
|
this.log('debug', 'connected');
|
|
@@ -270,15 +294,21 @@ export default class DFrameElement extends HTMLElement {
|
|
|
270
294
|
this.parsedSyncParams = parseSyncParams(this.syncParams || '*');
|
|
271
295
|
this.updateStyle();
|
|
272
296
|
this.updateSrc();
|
|
273
|
-
|
|
274
|
-
|
|
297
|
+
}
|
|
298
|
+
disconnectedCallback() {
|
|
299
|
+
this.log('debug', 'disconnected');
|
|
300
|
+
if (this.debug)
|
|
301
|
+
console.timeEnd(`[${this.id}:d-frame]`);
|
|
302
|
+
// TODO: more cleanup (resize observer, etc)
|
|
275
303
|
}
|
|
276
304
|
/* reflected attributes */
|
|
277
305
|
static get observedAttributes() { return ['src', 'aspect-ratio', 'height', 'sync-params', 'sync-path']; }
|
|
278
306
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
279
|
-
this.log('debug', 'attribute change', name, oldValue, newValue);
|
|
280
307
|
if (name === 'aspect-ratio')
|
|
281
308
|
this.updateAspectRatioHeight();
|
|
309
|
+
if (!this.connected)
|
|
310
|
+
return;
|
|
311
|
+
this.log('debug', 'attribute change', name, oldValue, newValue);
|
|
282
312
|
if (name === 'src')
|
|
283
313
|
this.updateSrc();
|
|
284
314
|
if (name === 'height')
|
package/lib/messages.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare function isStateChangeMessage(message: any): message is StateChan
|
|
|
15
15
|
export declare function isCustomMessage(message: any): message is CustomMessage;
|
|
16
16
|
export declare function isNotifMessage(message: any): message is NotifMessage;
|
|
17
17
|
export type InitParentMessage = ['df-parent', 'init', {
|
|
18
|
+
id: string;
|
|
18
19
|
debug?: boolean;
|
|
19
20
|
resize: 'yes' | 'no' | 'auto';
|
|
20
21
|
syncParams: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import DFrameContent from '../DFrameContent.js';
|
|
2
|
+
import { applySearchParams } from '../vue-reactive/util.js';
|
|
2
3
|
const dFrameContent = new DFrameContent({
|
|
3
4
|
updateSrc: (src) => {
|
|
4
5
|
const vIframeOptions = window.vIframeOptions;
|
|
@@ -6,14 +7,7 @@ const dFrameContent = new DFrameContent({
|
|
|
6
7
|
if (reactiveParams) {
|
|
7
8
|
const srcUrl = new URL(src);
|
|
8
9
|
if (srcUrl.origin === window.location.origin && srcUrl.pathname === window.location.pathname) {
|
|
9
|
-
|
|
10
|
-
srcUrl.searchParams.forEach((value, key) => {
|
|
11
|
-
reactiveParams[key] = value;
|
|
12
|
-
existingKeys.splice(existingKeys.indexOf(key), 1);
|
|
13
|
-
});
|
|
14
|
-
existingKeys.forEach(key => {
|
|
15
|
-
delete reactiveParams[key];
|
|
16
|
-
});
|
|
10
|
+
applySearchParams(reactiveParams, srcUrl.searchParams);
|
|
17
11
|
return;
|
|
18
12
|
}
|
|
19
13
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import DFrameContent, { type DFrameContentOptions } from '../DFrameContent.js';
|
|
2
|
+
import type { Reactive } from 'vue';
|
|
3
|
+
type VueReactiveDFrameContentOptions = Omit<DFrameContentOptions, 'updateSrc'>;
|
|
4
|
+
export declare function VueReactiveDFrameContent(reactiveParams: Reactive<Record<string, string>>, options?: VueReactiveDFrameContentOptions): DFrameContent;
|
|
5
|
+
export default VueReactiveDFrameContent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DFrameContent from '../DFrameContent.js';
|
|
2
|
+
import { applySearchParams } from './util.js';
|
|
3
|
+
export function VueReactiveDFrameContent(reactiveParams, options) {
|
|
4
|
+
return new DFrameContent({
|
|
5
|
+
...options,
|
|
6
|
+
updateSrc: (src) => {
|
|
7
|
+
const srcUrl = new URL(src);
|
|
8
|
+
if (srcUrl.origin === window.location.origin && srcUrl.pathname === window.location.pathname) {
|
|
9
|
+
applySearchParams(reactiveParams, srcUrl.searchParams);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
window.location.href = src;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export default VueReactiveDFrameContent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type StateChangeAdapter } from '../DFrameElement.js';
|
|
2
|
+
import type { Reactive } from 'vue';
|
|
3
|
+
declare class VueReactiveDFrameStateChangeAdapter implements StateChangeAdapter {
|
|
4
|
+
reactiveParams: Reactive<Record<string, string>>;
|
|
5
|
+
constructor(reactiveParams: Reactive<Record<string, string>>);
|
|
6
|
+
stateChange(action: 'push' | 'replace', newUrl: URL): void;
|
|
7
|
+
onStateChange(callback: () => void): void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (reactiveParams: Reactive<Record<string, string>>) => VueReactiveDFrameStateChangeAdapter;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { watch } from 'vue';
|
|
2
|
+
import { applySearchParams } from './util.js';
|
|
3
|
+
class VueReactiveDFrameStateChangeAdapter {
|
|
4
|
+
reactiveParams;
|
|
5
|
+
constructor(reactiveParams) {
|
|
6
|
+
this.reactiveParams = reactiveParams;
|
|
7
|
+
}
|
|
8
|
+
stateChange(action, newUrl) {
|
|
9
|
+
applySearchParams(this.reactiveParams, newUrl.searchParams);
|
|
10
|
+
}
|
|
11
|
+
onStateChange(callback) {
|
|
12
|
+
watch(this.reactiveParams, callback);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default (reactiveParams) => new VueReactiveDFrameStateChangeAdapter(reactiveParams);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const applySearchParams: (reactiveParams: Record<string, string>, searchParams: URLSearchParams) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const applySearchParams = (reactiveParams, searchParams) => {
|
|
2
|
+
const existingKeys = Object.keys(reactiveParams);
|
|
3
|
+
searchParams.forEach((value, key) => {
|
|
4
|
+
reactiveParams[key] = value;
|
|
5
|
+
existingKeys.splice(existingKeys.indexOf(key), 1);
|
|
6
|
+
});
|
|
7
|
+
existingKeys.forEach(key => {
|
|
8
|
+
delete reactiveParams[key];
|
|
9
|
+
});
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-fair/frame",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "An iframe wrapper for powerful web app integrations.",
|
|
5
5
|
"main": "dist/frame.min.js",
|
|
6
6
|
"directories": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"neostandard": "^0.11.9",
|
|
16
16
|
"typescript": "^5.7.2",
|
|
17
17
|
"vite": "^6.0.3",
|
|
18
|
+
"vue": "^3.5.13",
|
|
18
19
|
"vue-router": "^4.5.0"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|