@data-fair/frame 0.5.1 → 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.
@@ -1,2 +1,2 @@
1
- var VIframeCompatDFrameContent=function(){"use strict";var g=Object.defineProperty;var f=(h,s,d)=>s in h?g(h,s,{enumerable:!0,configurable:!0,writable:!0,value:d}):h[s]=d;var r=(h,s,d)=>f(h,typeof s!="symbol"?s+"":s,d);function h(n){return n[0]==="df-parent"&&n[1]==="init"}function s(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}const d=["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){r(this,"initialized",!1);r(this,"options");r(this,"pendingCheckHeight",!1);r(this,"debug",!1);r(this,"id");r(this,"throttledCheckHeight");r(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;h(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),s(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=(...o)=>{const a=t.apply(window.history,o);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),a};window.history.pushState=e;const i=(...o)=>{const a=t.apply(window.history,o);return this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),a};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 d)window.addEventListener(t,this.throttledCheckHeight,{passive:!0})}checkHeight(){const t=document.querySelectorAll("[data-iframe-height]");let e=0;for(const i of t){const o=i.getAttribute("data-iframe-height"),a=i.getBoundingClientRect().bottom+parseFloat(getComputedStyle(i).getPropertyValue("margin-bottom"))+(o?parseFloat(o):0);a>e&&(e=a)}e=Math.ceil(e),e!==this.lastHeight&&(this.postMessageToParent(["df-child","height",e]),this.lastHeight=e)}}const c=new u({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){const o=Object.keys(e);i.searchParams.forEach((a,l)=>{e[l]=a,o.splice(o.indexOf(l),1)}),o.forEach(a=>{delete e[a]});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}();
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
@@ -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
- const existingKeys = Object.keys(reactiveParams);
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.5.1",
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": {