@metapages/metapage 1.8.9 → 1.8.10
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metapageRenderer.d.ts","sourceRoot":"","sources":["../../src/metapage/metapageRenderer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"metapageRenderer.d.ts","sourceRoot":"","sources":["../../src/metapage/metapageRenderer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AA6FD,wBAAsB,cAAc,CAAC,KAAK,EAAE;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACtD,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA8PlC"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import { MetapageEvents as
|
|
2
|
-
import { Metapage as
|
|
3
|
-
import { pageLoaded as
|
|
4
|
-
import { getMetapageDefinitionFromUrl as
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
return !1;
|
|
8
|
-
try {
|
|
9
|
-
return new URL(a).pathname.split(";")[0].split(";")[1] === "type=metapage-divider";
|
|
10
|
-
} catch {
|
|
11
|
-
return !1;
|
|
12
|
-
}
|
|
1
|
+
import { MetapageEvents as T } from "./events.js";
|
|
2
|
+
import { Metapage as F } from "./Metapage.js";
|
|
3
|
+
import { pageLoaded as J } from "./MetapageTools.js";
|
|
4
|
+
import { getMetapageDefinitionFromUrl as R } from "./util.js";
|
|
5
|
+
function $(r) {
|
|
6
|
+
return r.startsWith("data:") ? r.includes("type=metapage-divider") : !1;
|
|
13
7
|
}
|
|
14
|
-
function
|
|
15
|
-
const i = JSON.parse(JSON.stringify(
|
|
8
|
+
function W(r) {
|
|
9
|
+
const i = JSON.parse(JSON.stringify(r));
|
|
16
10
|
i.meta || (i.meta = {}), i.meta.layouts || (i.meta.layouts = {}), i.meta.layouts["react-grid-layout"] || (i.meta.layouts["react-grid-layout"] = {
|
|
17
11
|
docs: "https://www.npmjs.com/package/react-grid-layout",
|
|
18
12
|
props: {
|
|
@@ -23,141 +17,155 @@ function U(a) {
|
|
|
23
17
|
},
|
|
24
18
|
layout: []
|
|
25
19
|
});
|
|
26
|
-
const
|
|
20
|
+
const t = i.meta.layouts["react-grid-layout"];
|
|
27
21
|
if (i.metaframes) {
|
|
28
|
-
Object.keys(i.metaframes).forEach((
|
|
29
|
-
if (!
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
i:
|
|
22
|
+
Object.keys(i.metaframes).forEach((a) => {
|
|
23
|
+
if (!t.layout.some((l) => l.i === a)) {
|
|
24
|
+
const l = t.layout.length > 0 ? Math.max(...t.layout.map((o) => (o.y || 0) + (o.h || 2))) : 0;
|
|
25
|
+
t.layout.push({
|
|
26
|
+
i: a,
|
|
33
27
|
x: 0,
|
|
34
|
-
y:
|
|
35
|
-
w:
|
|
36
|
-
h:
|
|
28
|
+
y: l,
|
|
29
|
+
w: t.props.cols,
|
|
30
|
+
h: $(i.metaframes[a].url) ? 1 : 3
|
|
37
31
|
});
|
|
38
32
|
}
|
|
39
33
|
});
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const f = new Set(Object.keys(i.metaframes));
|
|
35
|
+
t.layout = t.layout.filter((a) => f.has(a.i)), t.layout.forEach((a) => {
|
|
36
|
+
a.x = a.x || 0, a.y = a.y || 0, a.w = a.w || 1, a.h = a.h || 1;
|
|
43
37
|
});
|
|
44
38
|
}
|
|
45
39
|
return i;
|
|
46
40
|
}
|
|
47
|
-
async function
|
|
48
|
-
var C, O,
|
|
49
|
-
let { url: i, definition:
|
|
50
|
-
if (!i && !
|
|
41
|
+
async function Z(r) {
|
|
42
|
+
var b, C, O, j, S;
|
|
43
|
+
let { url: i, definition: t, onOutputs: f, rootDiv: a, options: l = {} } = r;
|
|
44
|
+
if (!i && !t)
|
|
51
45
|
throw new Error("Either url or definition must be provided");
|
|
52
|
-
if (i &&
|
|
46
|
+
if (i && t)
|
|
53
47
|
throw new Error("Either url or definition must be provided, not both");
|
|
54
|
-
if (i && (
|
|
48
|
+
if (i && (t = await R(i)), !t)
|
|
55
49
|
throw new Error("Failed to fetch metapage definition");
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
s.debug = c.debug || !1;
|
|
50
|
+
t = W(t), t = await P(t), await J();
|
|
51
|
+
const o = new F();
|
|
52
|
+
o.debug = l.debug || !1;
|
|
60
53
|
try {
|
|
61
|
-
await
|
|
54
|
+
await o.setDefinition(JSON.parse(JSON.stringify(t)));
|
|
62
55
|
} catch (e) {
|
|
63
|
-
throw
|
|
56
|
+
throw o.dispose(), new Error(`Failed to set metapage definition: ${e}`);
|
|
64
57
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
58
|
+
const y = [];
|
|
59
|
+
f && y.push(o.addListenerReturnDisposer(T.Outputs, f));
|
|
60
|
+
const m = (C = (b = t == null ? void 0 : t.meta) == null ? void 0 : b.layouts) == null ? void 0 : C["react-grid-layout"], p = m == null ? void 0 : m.layout;
|
|
61
|
+
if (!m || !p)
|
|
69
62
|
throw new Error("No valid layout found in metapage definition");
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
const g = /* @__PURE__ */ new Set(), E = p.map((e, d) => {
|
|
64
|
+
const s = o.getMetaframes()[e.i];
|
|
65
|
+
return s && $(s.url) ? { index: d, y: e.y, id: e.i } : null;
|
|
66
|
+
}).filter((e) => e !== null);
|
|
67
|
+
if (E.length > 0) {
|
|
68
|
+
const e = E.reduce((s, n) => n.y < s.y ? n : s), d = ((O = p.find((s) => s.i === e.id)) == null ? void 0 : O.y) ?? 0;
|
|
69
|
+
p.forEach((s) => {
|
|
70
|
+
s.y >= d && g.add(s.i);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const M = o.getMetaframeIds().filter((e) => !g.has(e));
|
|
74
|
+
let u = p.filter((e) => M.includes(e.i));
|
|
75
|
+
if (u.length === 0)
|
|
76
|
+
return console.warn("No visible metaframes found"), {
|
|
77
|
+
setInputs: (e) => {
|
|
78
|
+
o.isDisposed() || o.setInputs(e);
|
|
79
|
+
},
|
|
80
|
+
dispose: () => {
|
|
81
|
+
y.forEach((e) => e()), o.dispose(), a.innerHTML = "";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
u.sort((e, d) => e.y !== d.y ? e.y - d.y : e.x - d.x);
|
|
85
|
+
const H = Math.max(...u.map((e) => e.x + e.w));
|
|
86
|
+
Math.max(...u.map((e) => e.y + e.h));
|
|
87
|
+
const L = {
|
|
83
88
|
display: "grid",
|
|
84
|
-
gridTemplateColumns: `repeat(${
|
|
85
|
-
|
|
86
|
-
gap: `${((
|
|
89
|
+
gridTemplateColumns: `repeat(${Math.max(1, H)}, 1fr)`,
|
|
90
|
+
gridAutoRows: "minmax(100px, auto)",
|
|
91
|
+
gap: `${((j = m.props.margin) == null ? void 0 : j[0]) || 10}px`,
|
|
87
92
|
width: "100%",
|
|
88
93
|
height: "100%",
|
|
89
|
-
padding: ((
|
|
94
|
+
padding: ((S = m.props.containerPadding) == null ? void 0 : S[0]) || 0,
|
|
90
95
|
minHeight: 0,
|
|
91
96
|
alignContent: "stretch"
|
|
92
|
-
},
|
|
97
|
+
}, k = {
|
|
93
98
|
width: "100%",
|
|
94
99
|
height: "100%",
|
|
95
100
|
overflow: "hidden",
|
|
96
101
|
display: "flex",
|
|
97
102
|
flexDirection: "column"
|
|
98
103
|
};
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
Object.assign(
|
|
102
|
-
const
|
|
103
|
-
Object.assign(
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
104
|
+
a.innerHTML = "";
|
|
105
|
+
const h = document.createElement("div");
|
|
106
|
+
Object.assign(h.style, k);
|
|
107
|
+
const w = document.createElement("div");
|
|
108
|
+
Object.assign(w.style, L), M.forEach((e, d) => {
|
|
109
|
+
const s = p.find((N) => N.i === e);
|
|
110
|
+
if (!s)
|
|
106
111
|
return;
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
112
|
+
const n = o.getMetaframes()[e];
|
|
113
|
+
if (!n)
|
|
109
114
|
return;
|
|
110
|
-
const
|
|
111
|
-
gridColumn: `${
|
|
112
|
-
gridRow: `${
|
|
115
|
+
const I = {
|
|
116
|
+
gridColumn: `${s.x + 1} / span ${s.w}`,
|
|
117
|
+
gridRow: `${s.y + 1} / span ${s.h}`,
|
|
113
118
|
overflow: "hidden",
|
|
114
119
|
width: "100%",
|
|
115
120
|
minHeight: "100%",
|
|
116
121
|
height: "100%",
|
|
117
|
-
border:
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
border: l.hideFrameBorders ? "none" : "1px solid #e0e0e0",
|
|
123
|
+
position: "relative"
|
|
124
|
+
}, c = document.createElement("iframe");
|
|
125
|
+
c.src = n.url, c.style.border = "none", c.style.position = "absolute", c.style.top = "0", c.style.left = "0", c.style.width = "100%", c.style.height = "100%";
|
|
126
|
+
const x = document.createElement("div");
|
|
127
|
+
Object.assign(x.style, I), x.appendChild(c), w.appendChild(x);
|
|
120
128
|
});
|
|
121
|
-
const
|
|
122
|
-
return
|
|
123
|
-
const
|
|
124
|
-
if (!
|
|
129
|
+
const v = document.createElement("div");
|
|
130
|
+
return v.style.display = "none", Object.keys(o.getMetaframes()).filter((e) => g.has(e)).forEach((e) => {
|
|
131
|
+
const d = o.getMetaframes()[e];
|
|
132
|
+
if (!d)
|
|
125
133
|
return;
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
}),
|
|
134
|
+
const s = document.createElement("div");
|
|
135
|
+
s.setAttribute("data-metaframe-id", e);
|
|
136
|
+
const n = document.createElement("iframe");
|
|
137
|
+
n.src = d.url, n.style.border = "none", n.style.height = "100%", n.style.width = "100%", n.style.overflow = "clip", s.appendChild(n), v.appendChild(s);
|
|
138
|
+
}), h.appendChild(w), h.appendChild(v), a.appendChild(h), {
|
|
131
139
|
setInputs: (e) => {
|
|
132
|
-
|
|
140
|
+
o.isDisposed() || o.setInputs(e);
|
|
133
141
|
},
|
|
134
142
|
dispose: () => {
|
|
135
|
-
|
|
143
|
+
y.forEach((e) => e()), o.dispose(), a.innerHTML = "";
|
|
136
144
|
}
|
|
137
145
|
};
|
|
138
146
|
}
|
|
139
|
-
const
|
|
140
|
-
var
|
|
141
|
-
if (!
|
|
147
|
+
const A = (r) => {
|
|
148
|
+
var t;
|
|
149
|
+
if (!r)
|
|
142
150
|
return;
|
|
143
|
-
typeof
|
|
144
|
-
let i = (
|
|
145
|
-
return i || (
|
|
146
|
-
},
|
|
147
|
-
if (!(
|
|
148
|
-
return
|
|
149
|
-
for (const [i,
|
|
150
|
-
if (!(
|
|
151
|
+
typeof r == "string" && (r.startsWith("/") && (r = "https://metapage.io" + r), r = new URL(r));
|
|
152
|
+
let i = (t = /\/m?f\/([0-9a-zA-Z-]{3,})\/?(metaframe\.json)?.*$/g.exec(r.pathname)) == null ? void 0 : t[1];
|
|
153
|
+
return i || (r.searchParams.get("mfk") ?? void 0);
|
|
154
|
+
}, P = async (r) => {
|
|
155
|
+
if (!(r != null && r.metaframes))
|
|
156
|
+
return r;
|
|
157
|
+
for (const [i, t] of Object.entries(r.metaframes)) {
|
|
158
|
+
if (!(t.url.startsWith("https://metapage.io/mf/") || t.url.startsWith("https://metapage.io/f/")))
|
|
151
159
|
continue;
|
|
152
|
-
const
|
|
153
|
-
if (!
|
|
160
|
+
const f = A(t.url);
|
|
161
|
+
if (!f)
|
|
154
162
|
continue;
|
|
155
|
-
const
|
|
156
|
-
|
|
163
|
+
const a = await fetch(`https://metapage.io/f/${f}/definition.json`).then((l) => l.json());
|
|
164
|
+
a != null && a.url && (t.url = a == null ? void 0 : a.url);
|
|
157
165
|
}
|
|
158
|
-
return
|
|
166
|
+
return r;
|
|
159
167
|
};
|
|
160
168
|
export {
|
|
161
|
-
|
|
169
|
+
Z as renderMetapage
|
|
162
170
|
};
|
|
163
171
|
//# sourceMappingURL=metapageRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metapageRenderer.js","sources":["../../src/metapage/metapageRenderer.ts"],"sourcesContent":[null],"names":["isMetaframeDivider","url","validateLayout","definition","validated","layout","metaframeId","
|
|
1
|
+
{"version":3,"file":"metapageRenderer.js","sources":["../../src/metapage/metapageRenderer.ts"],"sourcesContent":[null],"names":["isMetaframeDivider","url","validateLayout","definition","validated","layout","metaframeId","currentMaxY","l","allMetaframeIds","renderMetapage","props","onOutputs","rootDiv","options","getMetapageDefinitionFromUrl","processMetapage","pageLoaded","metapage","Metapage","err","disposers","MetapageEvents","desktopLayoutBlob","_b","_a","metaframesToHide","dividers","item","index","metaframe","lowestYDivider","lowest","current","dividerY","_c","visibleMetaframeIds","visibleLayoutItems","inputs","disposer","a","b","maxCol","gridStyle","_d","_e","containerStyle","container","gridContainer","layoutItem","itemStyle","iframe","wrapper","hiddenContainer","getMetaframeKey","mfk","metapageDefinition","metaframeDefinition","r"],"mappings":";;;;AAgCA,SAASA,EAAmBC,GAAW;AACrC,SAAKA,EAAI,WAAW,OAAO,IAGpBA,EAAI,SAAS,uBAAuB,IAFlC;AAGX;AAGA,SAASC,EACPC,GAAgC;AAGhC,QAAMC,IAAY,KAAK,MAAM,KAAK,UAAUD,CAAU,CAAC;AAEnD,EAACC,EAAU,SACbA,EAAU,OAAO,KAGdA,EAAU,KAAK,YACRA,EAAA,KAAK,UAAU,KAGtBA,EAAU,KAAK,QAAQ,mBAAmB,MACnCA,EAAA,KAAK,QAAQ,mBAAmB,IAAI;AAAA,IAC5C,MAAM;AAAA,IACN,OAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,CAAC,IAAI,EAAE;AAAA,MACf,WAAW;AAAA,MACX,kBAAkB,CAAC,GAAG,CAAC;AAAA,IACxB;AAAA,IACD,QAAQ,CAAE;AAAA,EAAA;AAId,QAAMC,IAAS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A,EAACA,KAAA,QAAAA,EAAoB;AAChB,WAAAA;AAEE,aAAA,CAAClD,GAAawB,CAAS,KAAK,OAAO,QAC5C0B,EAAmB,UAAU,GAC5B;AAGC,QAAA,EACE1B,EAAU,IAAI,WAAW,yBAAyB,KAClDA,EAAU,IAAI,WAAW,wBAAwB;AAGnD;AAEI,UAAAyB,IAAMD,EAAgBxB,EAAU,GAAG;AACzC,QAAI,CAACyB;AACH;AAEF,UAAME,IAAsB,MAAM,MAChC,yBAAyBF,CAAG,kBAAkB,EAC9C,KAAK,CAACG,MAAMA,EAAE,KAAM,CAAA;AACtB,IAAID,KAAA,QAAAA,EAAqB,QACvB3B,EAAU,MAAM2B,KAAA,gBAAAA,EAAqB;AAAA,EAEzC;AACO,SAAAD;AACT;"}
|
package/package.json
CHANGED
|
@@ -34,13 +34,7 @@ function isMetaframeDivider(url: string): boolean {
|
|
|
34
34
|
if (!url.startsWith("data:")) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
const parsed = new URL(url);
|
|
39
|
-
const mimetype = parsed.pathname.split(";")[0];
|
|
40
|
-
return mimetype.split(";")[1] === "type=metapage-divider";
|
|
41
|
-
} catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
37
|
+
return url.includes("type=metapage-divider");
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
// Utility function to validate layout (simplified version)
|
|
@@ -118,14 +112,12 @@ function validateLayout(
|
|
|
118
112
|
* and returns a function to set inputs and a dispose function
|
|
119
113
|
*/
|
|
120
114
|
export async function renderMetapage(props: {
|
|
121
|
-
url?: string
|
|
115
|
+
url?: string;
|
|
122
116
|
definition?: MetapageDefinitionV2;
|
|
123
117
|
onOutputs?: (outputs: MetapageInstanceInputs) => void;
|
|
124
118
|
rootDiv: HTMLElement;
|
|
125
119
|
options?: RenderingOptions;
|
|
126
120
|
}): Promise<MetapageRendererResult> {
|
|
127
|
-
|
|
128
|
-
|
|
129
121
|
// Validate and clean the definition
|
|
130
122
|
let { url, definition, onOutputs, rootDiv, options = {} } = props;
|
|
131
123
|
if (!url && !definition) {
|
|
@@ -138,13 +130,13 @@ export async function renderMetapage(props: {
|
|
|
138
130
|
if (url) {
|
|
139
131
|
definition = await getMetapageDefinitionFromUrl(url);
|
|
140
132
|
}
|
|
141
|
-
|
|
133
|
+
|
|
142
134
|
if (!definition) {
|
|
143
135
|
throw new Error("Failed to fetch metapage definition");
|
|
144
136
|
}
|
|
145
137
|
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
definition = validateLayout(definition);
|
|
139
|
+
definition = await processMetapage(definition);
|
|
148
140
|
|
|
149
141
|
// Wait for page to be loaded
|
|
150
142
|
await pageLoaded();
|
|
@@ -154,7 +146,7 @@ export async function renderMetapage(props: {
|
|
|
154
146
|
metapage.debug = options.debug || false;
|
|
155
147
|
|
|
156
148
|
try {
|
|
157
|
-
await metapage.setDefinition(
|
|
149
|
+
await metapage.setDefinition(JSON.parse(JSON.stringify(definition)));
|
|
158
150
|
} catch (err) {
|
|
159
151
|
metapage.dispose();
|
|
160
152
|
throw new Error(`Failed to set metapage definition: ${err}`);
|
|
@@ -170,8 +162,7 @@ export async function renderMetapage(props: {
|
|
|
170
162
|
}
|
|
171
163
|
|
|
172
164
|
// Get the layout information
|
|
173
|
-
const desktopLayoutBlob =
|
|
174
|
-
processedDefinition?.meta?.layouts?.["react-grid-layout"];
|
|
165
|
+
const desktopLayoutBlob = definition?.meta?.layouts?.["react-grid-layout"];
|
|
175
166
|
const layout = desktopLayoutBlob?.layout as LayoutItem[];
|
|
176
167
|
|
|
177
168
|
if (!desktopLayoutBlob || !layout) {
|
|
@@ -179,23 +170,22 @@ export async function renderMetapage(props: {
|
|
|
179
170
|
}
|
|
180
171
|
|
|
181
172
|
// Find dividers and determine which metaframes to hide
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// If no dividers found, return empty list
|
|
197
|
-
if (dividers.length === 0) return { metaframesToHide: new Set<string>() };
|
|
173
|
+
const metaframesToHide = new Set<string>();
|
|
174
|
+
|
|
175
|
+
// Find all dividers and their y positions
|
|
176
|
+
const dividers = layout
|
|
177
|
+
.map((item: LayoutItem, index: number) => {
|
|
178
|
+
const metaframe = metapage.getMetaframes()[item.i];
|
|
179
|
+
return metaframe && isMetaframeDivider(metaframe.url)
|
|
180
|
+
? { index, y: item.y, id: item.i }
|
|
181
|
+
: null;
|
|
182
|
+
})
|
|
183
|
+
.filter(
|
|
184
|
+
(item): item is { index: number; y: number; id: string } => item !== null
|
|
185
|
+
);
|
|
198
186
|
|
|
187
|
+
// If dividers found, determine which metaframes to hide
|
|
188
|
+
if (dividers.length > 0) {
|
|
199
189
|
// Find the divider with the lowest y value
|
|
200
190
|
const lowestYDivider = dividers.reduce(
|
|
201
191
|
(
|
|
@@ -204,8 +194,6 @@ export async function renderMetapage(props: {
|
|
|
204
194
|
) => (current.y < lowest.y ? current : lowest)
|
|
205
195
|
);
|
|
206
196
|
|
|
207
|
-
// Create a set of metaframe IDs to hide (divider and those below it)
|
|
208
|
-
const metaframesToHide = new Set<string>();
|
|
209
197
|
const dividerY =
|
|
210
198
|
layout.find((item: LayoutItem) => item.i === lowestYDivider.id)?.y ?? 0;
|
|
211
199
|
|
|
@@ -215,31 +203,61 @@ export async function renderMetapage(props: {
|
|
|
215
203
|
metaframesToHide.add(item.i);
|
|
216
204
|
}
|
|
217
205
|
});
|
|
218
|
-
|
|
219
|
-
return { metaframesToHide };
|
|
220
|
-
})();
|
|
206
|
+
}
|
|
221
207
|
|
|
222
208
|
// Get visible metaframes
|
|
223
|
-
const visibleMetaframeIds =
|
|
224
|
-
|
|
225
|
-
|
|
209
|
+
const visibleMetaframeIds = metapage
|
|
210
|
+
.getMetaframeIds()
|
|
211
|
+
.filter((metaframeId) => !metaframesToHide.has(metaframeId));
|
|
226
212
|
|
|
227
213
|
// Calculate grid dimensions based on visible metaframes only
|
|
228
|
-
|
|
214
|
+
let visibleLayoutItems = layout.filter((item: LayoutItem) =>
|
|
229
215
|
visibleMetaframeIds.includes(item.i)
|
|
230
216
|
);
|
|
217
|
+
|
|
218
|
+
// Handle case where no metaframes are visible
|
|
219
|
+
if (visibleLayoutItems.length === 0) {
|
|
220
|
+
console.warn("No visible metaframes found");
|
|
221
|
+
// Return early with empty result
|
|
222
|
+
return {
|
|
223
|
+
setInputs: (inputs: MetapageInstanceInputs) => {
|
|
224
|
+
if (!metapage.isDisposed()) {
|
|
225
|
+
metapage.setInputs(inputs);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
dispose: () => {
|
|
229
|
+
disposers.forEach((disposer) => disposer());
|
|
230
|
+
metapage.dispose();
|
|
231
|
+
rootDiv.innerHTML = "";
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Sort visible layout items by y position to ensure proper grid layout
|
|
237
|
+
visibleLayoutItems.sort((a, b) => {
|
|
238
|
+
if (a.y !== b.y) {
|
|
239
|
+
return a.y - b.y;
|
|
240
|
+
}
|
|
241
|
+
return a.x - b.x;
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Calculate grid dimensions based on visible items only
|
|
231
245
|
const maxCol = Math.max(
|
|
232
246
|
...visibleLayoutItems.map((item: LayoutItem) => item.x + item.w)
|
|
233
247
|
);
|
|
248
|
+
|
|
249
|
+
// For rows, we need to account for the fact that we're hiding items below the divider
|
|
250
|
+
// So we should use the actual visible items' positions
|
|
234
251
|
const maxRow = Math.max(
|
|
235
252
|
...visibleLayoutItems.map((item: LayoutItem) => item.y + item.h)
|
|
236
253
|
);
|
|
254
|
+
|
|
237
255
|
|
|
238
256
|
// Create grid container style
|
|
239
257
|
const gridStyle = {
|
|
240
258
|
display: "grid",
|
|
241
|
-
gridTemplateColumns: `repeat(${maxCol}, 1fr)`,
|
|
242
|
-
|
|
259
|
+
gridTemplateColumns: `repeat(${Math.max(1, maxCol)}, 1fr)`,
|
|
260
|
+
gridAutoRows: "minmax(100px, auto)",
|
|
243
261
|
gap: `${desktopLayoutBlob.props.margin?.[0] || 10}px`,
|
|
244
262
|
width: "100%",
|
|
245
263
|
height: "100%",
|
|
@@ -286,15 +304,25 @@ export async function renderMetapage(props: {
|
|
|
286
304
|
minHeight: "100%",
|
|
287
305
|
height: "100%",
|
|
288
306
|
border: options.hideFrameBorders ? "none" : "1px solid #e0e0e0",
|
|
307
|
+
position: "relative" as const,
|
|
289
308
|
};
|
|
290
309
|
|
|
291
310
|
// Create iframe for the metaframe
|
|
292
311
|
const iframe = document.createElement("iframe");
|
|
293
312
|
iframe.src = metaframe.url;
|
|
294
313
|
iframe.style.border = "none";
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
314
|
+
iframe.style.position = "absolute";
|
|
315
|
+
iframe.style.top = "0";
|
|
316
|
+
iframe.style.left = "0";
|
|
317
|
+
iframe.style.width = "100%";
|
|
318
|
+
iframe.style.height = "100%";
|
|
319
|
+
|
|
320
|
+
// Create wrapper div for proper grid positioning
|
|
321
|
+
const wrapper = document.createElement("div");
|
|
322
|
+
Object.assign(wrapper.style, itemStyle);
|
|
323
|
+
wrapper.appendChild(iframe);
|
|
324
|
+
|
|
325
|
+
gridContainer.appendChild(wrapper);
|
|
298
326
|
});
|
|
299
327
|
|
|
300
328
|
// Create hidden container for hidden metaframes
|