@data-fair/frame 0.2.0 → 0.3.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.min.js +2 -2
- package/{src → lib}/DFrameElement.js +32 -24
- package/lib/utils/sync-params.d.ts +7 -0
- package/lib/utils/sync-params.js +80 -0
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +17 -0
- package/lib/v-iframe-compat/d-frame-content.d.ts +8 -0
- package/lib/v-iframe-compat/d-frame-content.js +31 -0
- package/lib/v-iframe-compat/ui-notif.d.ts +16 -0
- package/lib/v-iframe-compat/ui-notif.js +34 -0
- package/lib/vue-router/d-frame-content.d.ts +5 -0
- package/lib/vue-router/d-frame-content.js +16 -0
- package/lib/vue-router/state-change-adapter.d.ts +10 -0
- package/lib/vue-router/state-change-adapter.js +16 -0
- package/package.json +4 -4
- /package/{src → lib}/DFrameContent.d.ts +0 -0
- /package/{src → lib}/DFrameContent.js +0 -0
- /package/{src → lib}/DFrameElement.d.ts +0 -0
- /package/{src → lib}/d-frame-content.d.ts +0 -0
- /package/{src → lib}/d-frame-content.js +0 -0
- /package/{src → lib}/d-frame.d.ts +0 -0
- /package/{src → lib}/d-frame.js +0 -0
- /package/{src → lib}/messages.d.ts +0 -0
- /package/{src → lib}/messages.js +0 -0
package/dist/d-frame.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H=Object.defineProperty;var M=(d,c,p)=>c in d?H(d,c,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[c]=p;var o=(d,c,p)=>M(d,typeof c!="symbol"?c+"":c,p);(function(){"use strict";function d(e){return e[0]==="df-child"&&e[1]==="init"}function c(e){return e[0]==="df-child"&&e[1]==="height"}function p(e){return e[0]==="df-child"&&e[1]==="stateChange"}function y(e){return e[0]==="df-child"&&e[1]==="custom"}function b(e){return e[0]==="df-child"&&e[1]==="notif"}function w(e){return e.endsWith("/")?e:e===""?"/":e.slice(0,e.lastIndexOf("/")+1)}function A(e,a){if(a.origin!==e.origin)return a.href;if(a.pathname===e.pathname)return"";const t=w(e.pathname);return a.pathname.startsWith(t)?a.pathname.replace(t,"./"):a.pathname}const E=e=>e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&");function S(e){const a=[];for(const t of e.split(",")){const[s="*",i]=t.split(":"),r="^"+E(s).replace(/\\\*/g,"(.*)")+"$";a.push({regexp:new RegExp(r),append:i})}return a}function P(e,a,t,s){if(!t&&!s)return e.href;const i=new URL(a);if(t&&i.searchParams.forEach((r,u)=>{for(const n of t){if(n.append&&!u.startsWith(n.append)||u===s)continue;const h=n.append?u.replace(n.append,""):u;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 z(e,a,t,s,i){const r=new URL(t),u=new URL(a);if(s&&(r.searchParams.forEach((n,h)=>{for(const l of s){if(l.append&&!h.startsWith(l.append))continue;const f=l.append?h.replace(l.append,""):h;if(f.match(l.regexp)){u.searchParams.get(f)===null&&r.searchParams.delete(h);break}}}),u.searchParams.forEach((n,h)=>{for(const l of s){if(!h.match(l.regexp)||(e==null?void 0:e.searchParams.get(h))===n)continue;const f=l.append?l.append+h:h;r.searchParams.set(f,n);break}})),i!==null&&e){const n=A(e,u);n?r.searchParams.set(i,n):r.searchParams.delete(i)}return r}function R(e){return e.vIframe===!0&&e.uiNotification!==void 0}function g(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 C{stateChange(a,t){a==="replace"&&window.history.replaceState(null,"",t),a==="push"&&window.history.pushState(null,"",t)}}const m=document.createElement("template");m.innerHTML=`<style>
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
}
|
|
@@ -8,5 +8,5 @@ var C=Object.defineProperty;var H=(u,c,p)=>c in u?C(u,c,{enumerable:!0,configura
|
|
|
8
8
|
border: none;
|
|
9
9
|
max-height: 100%;
|
|
10
10
|
}
|
|
11
|
-
</style><slot name="loader"></slot><iframe class="d-frame-iframe" frameborder="0">`;class
|
|
11
|
+
</style><slot name="loader"></slot><iframe class="d-frame-iframe" frameborder="0">`;class v 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=m.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!==r[0].contentRect.width&&(this.width=r[0].contentRect.width,this.updateAspectRatioHeight())}).observe(this),this.adapter=new C,window.addEventListener("message",r=>this.onMessage(r))}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(){return this.getAttribute("aspect-ratio")??"auto"}set aspectRatio(t){this.setAttribute("aspect-ratio",t)}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 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(d(i)&&(this.postMessageToChild(["df-parent","init",{debug:this.debug,resize:this.resize,syncParams:this.syncParams!==null,syncPath:this.syncPath!==null}]),this.init()),c(i)&&(this.resizedHeight=i[2],this.updateStyle()),p(i)&&(this.parsedSyncParams||this.syncPath)){const r=z(this.srcUrl,i[3],window.location.href,this.parsedSyncParams,this.syncPath);r.href!==window.location.href&&this.adapter.stateChange(i[2],r)}y(i)&&this.dispatchEvent(new CustomEvent("message",{detail:i[2]})),b(i)&&this.dispatchEvent(new CustomEvent("notif",{detail:i[2]}))}else R(i)&&(console.log("v-iframe notification",i.uiNotification,g(i.uiNotification)),this.dispatchEvent(new CustomEvent("notif",{detail:g(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=P(this.srcUrl,window.location.href,this.parsedSyncParams,this.syncPath);this.initialSrc?this.postMessageToChild(["df-parent","updateSrc",t]):this.iframeElement.setAttribute("src",t)}updateStyle(){let t="";(this.resize==="yes"||this.resize==="auto"&&this.resizedHeight)&&(this.iframeElement.setAttribute("scrolling","no"),this.resizedHeight?(this.slotElement.style.display="none",t+=`height:${this.resizedHeight}px;`):this.height?(this.slotElement.style.display="none",t+=`height:${this.height};`):this.aspectRatio!=="auto"?(this.slotElement.style.display="none",t+=`height:${this.aspectRatioHeight}px;`):(this.slotElement.style.display="block",t+="height:0;")),(this.resize==="no"||this.resize==="auto"&&!this.resizedHeight)&&(this.iframeElement.setAttribute("scrolling","auto"),this.height?t+=`height:${this.height};`:t+=`height:${this.aspectRatioHeight}px;`),this.iframeElement.setAttribute("style",t)}updateAspectRatioHeight(){this.width&&(this.resizedHeight||this.height||(this.aspectRatioHeight=this.width/this.actualAspectRatio,this.updateStyle()))}log(t,...s){t==="debug"&&!this.debug||(t==="debug"&&console.debug("d-frame",...s),t==="info"&&console.info("d-frame",...s))}connectedCallback(){if(!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=S(this.syncParams||"*")),this.updateStyle(),this.updateSrc()}static get observedAttributes(){return["src","aspect-ratio","height","sync-params","sync-path"]}attributeChangedCallback(t,s,i){this.log("debug","attribute change",t,s,i),t==="aspect-ratio"&&this.updateAspectRatioHeight(),t==="src"&&this.updateSrc(),t==="height"&&this.updateStyle(),t==="sync-params"&&this.updateSrc(),t==="sync-path"&&this.updateSrc()}}customElements.define("d-frame",v)})();
|
|
12
12
|
//# sourceMappingURL=d-frame.min.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// this is a good doc about writing web components https://web.dev/articles/custom-elements-best-practices
|
|
2
2
|
import { isCustomMessage, isHeightMessage, isInitChildMessage, isNotifMessage, isStateChangeMessage } from './messages.js';
|
|
3
3
|
import { parseSyncParams, getChildSrc, getParentUrl } from './utils/sync-params.js';
|
|
4
|
+
import { isVIframeUiNotif, convertVIframeUiNotif } from './v-iframe-compat/ui-notif.js';
|
|
4
5
|
class WindowStateChangeAdapter {
|
|
5
6
|
stateChange(action, newUrl) {
|
|
6
7
|
if (action === 'replace')
|
|
@@ -120,34 +121,41 @@ export default class DFrameElement extends HTMLElement {
|
|
|
120
121
|
window.addEventListener('message', (e) => this.onMessage(e));
|
|
121
122
|
}
|
|
122
123
|
onMessage(e) {
|
|
123
|
-
if (e.source === this.iframeElement?.contentWindow
|
|
124
|
+
if (e.source === this.iframeElement?.contentWindow) {
|
|
124
125
|
const message = e.data;
|
|
125
126
|
this.log('debug', 'received message from child', message);
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
if (Array.isArray(e.data)) {
|
|
128
|
+
if (isInitChildMessage(message)) {
|
|
129
|
+
// simple handshake for initialization
|
|
130
|
+
this.postMessageToChild(['df-parent', 'init', {
|
|
131
|
+
debug: this.debug,
|
|
132
|
+
resize: this.resize,
|
|
133
|
+
syncParams: this.syncParams !== null,
|
|
134
|
+
syncPath: this.syncPath !== null
|
|
135
|
+
}]);
|
|
136
|
+
this.init();
|
|
137
|
+
}
|
|
138
|
+
if (isHeightMessage(message)) {
|
|
139
|
+
this.resizedHeight = message[2];
|
|
140
|
+
this.updateStyle();
|
|
141
|
+
}
|
|
142
|
+
if (isStateChangeMessage(message) && (this.parsedSyncParams || this.syncPath)) {
|
|
143
|
+
const newParentHUrl = getParentUrl(this.srcUrl, message[3], window.location.href, this.parsedSyncParams, this.syncPath);
|
|
144
|
+
if (newParentHUrl.href !== window.location.href) {
|
|
145
|
+
this.adapter.stateChange(message[2], newParentHUrl);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (isCustomMessage(message)) {
|
|
149
|
+
this.dispatchEvent(new CustomEvent('message', { detail: message[2] }));
|
|
150
|
+
}
|
|
151
|
+
if (isNotifMessage(message)) {
|
|
152
|
+
this.dispatchEvent(new CustomEvent('notif', { detail: message[2] }));
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.dispatchEvent(new CustomEvent('notif', { detail: message[2] }));
|
|
155
|
+
else if (isVIframeUiNotif(message)) {
|
|
156
|
+
console.log('v-iframe notification', message.uiNotification, convertVIframeUiNotif(message.uiNotification));
|
|
157
|
+
// maintain compatibility with v-iframe notifications sent through postMessage
|
|
158
|
+
this.dispatchEvent(new CustomEvent('notif', { detail: convertVIframeUiNotif(message.uiNotification) }));
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
161
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ParsedSyncParams = {
|
|
2
|
+
regexp: RegExp;
|
|
3
|
+
append?: string;
|
|
4
|
+
}[];
|
|
5
|
+
export declare function parseSyncParams(syncParamsStr: string): ParsedSyncParams;
|
|
6
|
+
export declare function getChildSrc(srcUrl: URL, parentHref: string, syncParams: ParsedSyncParams | undefined, syncPath: null | string): string;
|
|
7
|
+
export declare function getParentUrl(srcUrl: URL | undefined, childHref: string, currentParentHref: string, syncParams: ParsedSyncParams | undefined, syncPath: null | string): URL;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getUrlRelativePath } from './url.js';
|
|
2
|
+
const escapeRegExp = (str) => str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
3
|
+
export function parseSyncParams(syncParamsStr) {
|
|
4
|
+
const syncParams = [];
|
|
5
|
+
for (const syncParam of syncParamsStr.split(',')) {
|
|
6
|
+
const [pattern = '*', append] = syncParam.split(':');
|
|
7
|
+
const regexpStr = '^' + escapeRegExp(pattern).replace(/\\\*/g, '(.*)') + '$';
|
|
8
|
+
syncParams.push({
|
|
9
|
+
regexp: new RegExp(regexpStr),
|
|
10
|
+
append
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return syncParams;
|
|
14
|
+
}
|
|
15
|
+
export function getChildSrc(srcUrl, parentHref, syncParams, syncPath) {
|
|
16
|
+
if (!syncParams && !syncPath)
|
|
17
|
+
return srcUrl.href;
|
|
18
|
+
const parentUrl = new URL(parentHref);
|
|
19
|
+
if (syncParams) {
|
|
20
|
+
parentUrl.searchParams.forEach((value, key) => {
|
|
21
|
+
for (const syncParam of syncParams) {
|
|
22
|
+
if (syncParam.append && !key.startsWith(syncParam.append))
|
|
23
|
+
continue;
|
|
24
|
+
if (key === syncPath)
|
|
25
|
+
continue;
|
|
26
|
+
const childKey = syncParam.append ? key.replace(syncParam.append, '') : key;
|
|
27
|
+
if (!childKey.match(syncParam.regexp))
|
|
28
|
+
continue;
|
|
29
|
+
srcUrl.searchParams.set(childKey, value);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (syncPath !== null) {
|
|
35
|
+
const path = parentUrl.searchParams.get(syncPath);
|
|
36
|
+
if (path) {
|
|
37
|
+
srcUrl.pathname = new URL(path, srcUrl).pathname;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return srcUrl.href;
|
|
41
|
+
}
|
|
42
|
+
export function getParentUrl(srcUrl, childHref, currentParentHref, syncParams, syncPath) {
|
|
43
|
+
const parentUrl = new URL(currentParentHref);
|
|
44
|
+
const childUrl = new URL(childHref);
|
|
45
|
+
if (syncParams) {
|
|
46
|
+
// remove existing keys that were deleted from the child
|
|
47
|
+
parentUrl.searchParams.forEach((value, key) => {
|
|
48
|
+
for (const syncParam of syncParams) {
|
|
49
|
+
if (syncParam.append && !key.startsWith(syncParam.append))
|
|
50
|
+
continue;
|
|
51
|
+
const childKey = syncParam.append ? key.replace(syncParam.append, '') : key;
|
|
52
|
+
if (!childKey.match(syncParam.regexp))
|
|
53
|
+
continue;
|
|
54
|
+
if (childUrl.searchParams.get(childKey) === null)
|
|
55
|
+
parentUrl.searchParams.delete(key);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// apply params from child to parent
|
|
60
|
+
childUrl.searchParams.forEach((value, key) => {
|
|
61
|
+
for (const syncParam of syncParams) {
|
|
62
|
+
if (!key.match(syncParam.regexp))
|
|
63
|
+
continue;
|
|
64
|
+
if (srcUrl?.searchParams.get(key) === value)
|
|
65
|
+
continue;
|
|
66
|
+
const parentKey = syncParam.append ? (syncParam.append + key) : key;
|
|
67
|
+
parentUrl.searchParams.set(parentKey, value);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (syncPath !== null && srcUrl) {
|
|
73
|
+
const path = getUrlRelativePath(srcUrl, childUrl);
|
|
74
|
+
if (path)
|
|
75
|
+
parentUrl.searchParams.set(syncPath, path);
|
|
76
|
+
else
|
|
77
|
+
parentUrl.searchParams.delete(syncPath);
|
|
78
|
+
}
|
|
79
|
+
return parentUrl;
|
|
80
|
+
}
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function getPathDirectory(path) {
|
|
2
|
+
if (path.endsWith('/'))
|
|
3
|
+
return path;
|
|
4
|
+
if (path === '')
|
|
5
|
+
return '/';
|
|
6
|
+
return path.slice(0, path.lastIndexOf('/') + 1);
|
|
7
|
+
}
|
|
8
|
+
export function getUrlRelativePath(srcUrl, currentUrl) {
|
|
9
|
+
if (currentUrl.origin !== srcUrl.origin)
|
|
10
|
+
return currentUrl.href;
|
|
11
|
+
if (currentUrl.pathname === srcUrl.pathname)
|
|
12
|
+
return '';
|
|
13
|
+
const srcDirectory = getPathDirectory(srcUrl.pathname);
|
|
14
|
+
if (!currentUrl.pathname.startsWith(srcDirectory))
|
|
15
|
+
return currentUrl.pathname;
|
|
16
|
+
return currentUrl.pathname.replace(srcDirectory, './');
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DFrameContent from '../DFrameContent.js';
|
|
2
|
+
import type { Router } from 'vue-router';
|
|
3
|
+
export type VIframeOptions = {
|
|
4
|
+
router?: Router;
|
|
5
|
+
reactiveParams?: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
declare const dFrameContent: DFrameContent;
|
|
8
|
+
export default dFrameContent;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import DFrameContent from '../DFrameContent.js';
|
|
2
|
+
const dFrameContent = new DFrameContent({
|
|
3
|
+
updateSrc: (src) => {
|
|
4
|
+
const vIframeOptions = window.vIframeOptions;
|
|
5
|
+
const reactiveParams = vIframeOptions?.reactiveParams;
|
|
6
|
+
if (reactiveParams) {
|
|
7
|
+
const srcUrl = new URL(src);
|
|
8
|
+
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
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (vIframeOptions?.router) {
|
|
21
|
+
const urlPrefix = window.location.origin + vIframeOptions.router.options.history.base;
|
|
22
|
+
if (src.startsWith(urlPrefix)) {
|
|
23
|
+
vIframeOptions.router.replace(src.replace(urlPrefix, ''));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
window.location.href = src;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
window.dFrameContent = dFrameContent;
|
|
31
|
+
export default dFrameContent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Notif } from '../messages.ts';
|
|
2
|
+
type NotifType = 'default' | 'info' | 'success' | 'warning' | 'error';
|
|
3
|
+
export type PartialUiNotif = string | {
|
|
4
|
+
type?: NotifType;
|
|
5
|
+
msg: string;
|
|
6
|
+
error?: any;
|
|
7
|
+
errorMsg?: string;
|
|
8
|
+
clientError?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type VIframeUiNotif = {
|
|
11
|
+
vIframe: true;
|
|
12
|
+
uiNotification: PartialUiNotif;
|
|
13
|
+
};
|
|
14
|
+
export declare function isVIframeUiNotif(message: any): message is VIframeUiNotif;
|
|
15
|
+
export declare function convertVIframeUiNotif(notif: PartialUiNotif): Notif;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function isVIframeUiNotif(message) {
|
|
2
|
+
return message.vIframe === true && message.uiNotification !== undefined;
|
|
3
|
+
}
|
|
4
|
+
export function convertVIframeUiNotif(notif) {
|
|
5
|
+
if (typeof notif === 'string')
|
|
6
|
+
return { type: 'default', title: notif };
|
|
7
|
+
if (notif.error && !notif.errorMsg) {
|
|
8
|
+
const errorMsg = (notif.error.response && (notif.error.response.data || notif.error.response.status)) || notif.error.message || notif.error;
|
|
9
|
+
if (notif.msg) {
|
|
10
|
+
return {
|
|
11
|
+
type: 'error',
|
|
12
|
+
title: notif.msg,
|
|
13
|
+
detail: errorMsg
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return {
|
|
18
|
+
type: 'error',
|
|
19
|
+
title: errorMsg
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (notif.type === 'error') {
|
|
24
|
+
return {
|
|
25
|
+
type: notif.clientError ? 'warning' : 'error',
|
|
26
|
+
title: notif.msg,
|
|
27
|
+
detail: notif.errorMsg
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
type: notif.type ?? 'default',
|
|
32
|
+
title: notif.msg
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import DFrameContent, { type DFrameContentOptions } from '../DFrameContent.js';
|
|
2
|
+
import type { Router } from 'vue-router';
|
|
3
|
+
type VueRouterDFrameContentOptions = Omit<DFrameContentOptions, 'updateSrc'>;
|
|
4
|
+
export declare function vueRouterDFrameContent(router: Router, options?: VueRouterDFrameContentOptions): DFrameContent;
|
|
5
|
+
export default vueRouterDFrameContent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import DFrameContent from '../DFrameContent.js';
|
|
2
|
+
export function vueRouterDFrameContent(router, options) {
|
|
3
|
+
return new DFrameContent({
|
|
4
|
+
...options,
|
|
5
|
+
updateSrc: (src) => {
|
|
6
|
+
const urlPrefix = window.location.origin + router.options.history.base;
|
|
7
|
+
if (src.startsWith(urlPrefix)) {
|
|
8
|
+
router.replace(src.replace(urlPrefix, ''));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
window.location.href = src;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export default vueRouterDFrameContent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type StateChangeAdapter } from '../DFrameElement.js';
|
|
2
|
+
import type { Router } from 'vue-router';
|
|
3
|
+
declare class VueRouterDFrameStateChangeAdapter implements StateChangeAdapter {
|
|
4
|
+
router: Router;
|
|
5
|
+
constructor(router: Router);
|
|
6
|
+
stateChange(action: 'push' | 'replace', newUrl: URL): void;
|
|
7
|
+
onStateChange(callback: () => void): void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (router: Router) => VueRouterDFrameStateChangeAdapter;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class VueRouterDFrameStateChangeAdapter {
|
|
2
|
+
router;
|
|
3
|
+
constructor(router) {
|
|
4
|
+
this.router = router;
|
|
5
|
+
}
|
|
6
|
+
stateChange(action, newUrl) {
|
|
7
|
+
if (action === 'push')
|
|
8
|
+
this.router.push({ query: Object.fromEntries(newUrl.searchParams) });
|
|
9
|
+
if (action === 'replace')
|
|
10
|
+
this.router.replace({ query: Object.fromEntries(newUrl.searchParams) });
|
|
11
|
+
}
|
|
12
|
+
onStateChange(callback) {
|
|
13
|
+
this.router.afterEach(callback);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default (router) => new VueRouterDFrameStateChangeAdapter(router);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-fair/frame",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "An iframe wrapper for powerful web app integrations.",
|
|
5
5
|
"main": "dist/frame.min.js",
|
|
6
6
|
"directories": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dev-zellij": "zellij --layout .zellij.kdl",
|
|
24
24
|
"prepare": "husky",
|
|
25
25
|
"test": "node --test tests/*.js",
|
|
26
|
-
"build": "rm -f
|
|
26
|
+
"build": "rm -f lib/*.d.ts && rm -f lib/*.js && tsc -p tsconfig.json && rm -rf dist && vite -c vite.config.d-frame.js build && vite -c vite.config.d-frame-content.js build",
|
|
27
27
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
28
28
|
"publish:main": "cd doc && npm run build:main && cd .. && gh-pages-multi deploy -v -s doc/.output/public -t main",
|
|
29
29
|
"publish:latest": "cd doc && npm run build:latest && cd .. && gh-pages-multi deploy -v -s doc/.output/public -t latest"
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"type": "module",
|
|
39
39
|
"files": [
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"lib/**/*.js",
|
|
41
|
+
"lib/**/*.d.ts",
|
|
42
42
|
"dist/*.js"
|
|
43
43
|
]
|
|
44
44
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → lib}/d-frame.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/{src → lib}/messages.js
RENAMED
|
File without changes
|