@01.software/sdk 0.5.3 → 0.5.5
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/auth.cjs +22 -46
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.js +22 -47
- package/dist/auth.js.map +1 -1
- package/dist/index.cjs +922 -1069
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +922 -1072
- package/dist/index.js.map +1 -1
- package/dist/realtime.cjs +75 -101
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.js +75 -102
- package/dist/realtime.js.map +1 -1
- package/dist/ui/code-block.cjs +13 -35
- package/dist/ui/code-block.cjs.map +1 -1
- package/dist/ui/code-block.js +13 -35
- package/dist/ui/code-block.js.map +1 -1
- package/dist/ui/flow/server.cjs +26 -68
- package/dist/ui/flow/server.cjs.map +1 -1
- package/dist/ui/flow/server.js +26 -71
- package/dist/ui/flow/server.js.map +1 -1
- package/dist/ui/flow.cjs +244 -238
- package/dist/ui/flow.cjs.map +1 -1
- package/dist/ui/flow.js +244 -240
- package/dist/ui/flow.js.map +1 -1
- package/dist/ui/form.cjs +40 -84
- package/dist/ui/form.cjs.map +1 -1
- package/dist/ui/form.js +40 -86
- package/dist/ui/form.js.map +1 -1
- package/dist/ui/image.cjs +27 -40
- package/dist/ui/image.cjs.map +1 -1
- package/dist/ui/image.js +27 -42
- package/dist/ui/image.js.map +1 -1
- package/dist/ui/rich-text.cjs +33 -67
- package/dist/ui/rich-text.cjs.map +1 -1
- package/dist/ui/rich-text.js +33 -69
- package/dist/ui/rich-text.js.map +1 -1
- package/dist/ui/video.cjs +32 -50
- package/dist/ui/video.cjs.map +1 -1
- package/dist/ui/video.js +32 -52
- package/dist/ui/video.js.map +1 -1
- package/dist/webhook.cjs +48 -73
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.js +48 -74
- package/dist/webhook.js.map +1 -1
- package/package.json +3 -3
package/dist/ui/flow.js
CHANGED
|
@@ -1,55 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
|
-
var __async = (__this, __arguments, generator) => {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
var fulfilled = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.next(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var rejected = (value) => {
|
|
43
|
-
try {
|
|
44
|
-
step(generator.throw(value));
|
|
45
|
-
} catch (e) {
|
|
46
|
-
reject(e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
2
|
|
|
54
3
|
// src/ui/Flow/types.ts
|
|
55
4
|
function isDynamicNode(node) {
|
|
@@ -116,133 +65,128 @@ function collectionKeys(collection) {
|
|
|
116
65
|
|
|
117
66
|
// src/ui/Flow/query-options.ts
|
|
118
67
|
function flowQueryOptions(client, slug, id) {
|
|
119
|
-
|
|
120
|
-
const identifier = (_a = id != null ? id : slug) != null ? _a : "";
|
|
68
|
+
const identifier = id ?? slug ?? "";
|
|
121
69
|
return {
|
|
122
70
|
queryKey: collectionKeys("flows").detail(identifier),
|
|
123
|
-
queryFn: () =>
|
|
71
|
+
queryFn: async () => {
|
|
124
72
|
if (id) return client.from("flows").findById(id);
|
|
125
|
-
const result =
|
|
73
|
+
const result = await client.from("flows").find({
|
|
126
74
|
where: { slug: { equals: slug } },
|
|
127
75
|
limit: 1
|
|
128
76
|
});
|
|
129
77
|
const doc = result.docs[0];
|
|
130
78
|
if (!doc) throw new Error(`Flow not found: ${slug}`);
|
|
131
79
|
return doc;
|
|
132
|
-
}
|
|
80
|
+
}
|
|
133
81
|
};
|
|
134
82
|
}
|
|
135
83
|
function nodeTypesQueryOptions(client) {
|
|
136
84
|
return {
|
|
137
85
|
queryKey: collectionKeys("flow-node-types").lists(),
|
|
138
|
-
queryFn: () =>
|
|
139
|
-
const result =
|
|
86
|
+
queryFn: async () => {
|
|
87
|
+
const result = await client.from("flow-node-types").find({ limit: 0 });
|
|
140
88
|
return result.docs;
|
|
141
|
-
}
|
|
89
|
+
}
|
|
142
90
|
};
|
|
143
91
|
}
|
|
144
92
|
function edgeTypesQueryOptions(client) {
|
|
145
93
|
return {
|
|
146
94
|
queryKey: collectionKeys("flow-edge-types").lists(),
|
|
147
|
-
queryFn: () =>
|
|
148
|
-
const result =
|
|
95
|
+
queryFn: async () => {
|
|
96
|
+
const result = await client.from("flow-edge-types").find({ limit: 0 });
|
|
149
97
|
return result.docs;
|
|
150
|
-
}
|
|
98
|
+
}
|
|
151
99
|
};
|
|
152
100
|
}
|
|
153
101
|
|
|
154
102
|
// src/ui/Flow/useFlow.ts
|
|
155
103
|
function toNodeTypeDef(doc) {
|
|
156
|
-
var _a, _b, _c, _d, _e, _f;
|
|
157
104
|
return {
|
|
158
|
-
slug: String(
|
|
159
|
-
name: String(
|
|
160
|
-
color: String(
|
|
161
|
-
defaultSize:
|
|
105
|
+
slug: String(doc.slug ?? ""),
|
|
106
|
+
name: String(doc.title ?? ""),
|
|
107
|
+
color: String(doc.color ?? "#e5e7eb"),
|
|
108
|
+
defaultSize: doc.defaultSize ?? {
|
|
162
109
|
width: 200,
|
|
163
110
|
height: 200
|
|
164
111
|
},
|
|
165
112
|
fields: Array.isArray(doc.fields) ? doc.fields : [],
|
|
166
113
|
transparentBackground: Boolean(doc.transparentBackground),
|
|
167
|
-
template:
|
|
168
|
-
customCSS:
|
|
114
|
+
template: doc.template ?? null,
|
|
115
|
+
customCSS: doc.customCSS ?? null
|
|
169
116
|
};
|
|
170
117
|
}
|
|
171
118
|
function toEdgeTypeDef(doc) {
|
|
172
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
173
119
|
return {
|
|
174
|
-
slug: String(
|
|
175
|
-
name: String(
|
|
176
|
-
color: String(
|
|
177
|
-
strokeWidth:
|
|
178
|
-
animated:
|
|
179
|
-
lineStyle: String(
|
|
180
|
-
markerStart: String(
|
|
181
|
-
markerEnd: String(
|
|
120
|
+
slug: String(doc.slug ?? ""),
|
|
121
|
+
name: String(doc.title ?? ""),
|
|
122
|
+
color: String(doc.color ?? ""),
|
|
123
|
+
strokeWidth: doc.strokeWidth ?? 2,
|
|
124
|
+
animated: doc.animated ?? false,
|
|
125
|
+
lineStyle: String(doc.lineStyle ?? "default"),
|
|
126
|
+
markerStart: String(doc.markerStart ?? "none"),
|
|
127
|
+
markerEnd: String(doc.markerEnd ?? "arrow"),
|
|
182
128
|
fields: Array.isArray(doc.fields) ? doc.fields : []
|
|
183
129
|
};
|
|
184
130
|
}
|
|
185
131
|
function useFlow(options) {
|
|
186
|
-
var _a, _b;
|
|
187
132
|
const { client, slug, id, enabled = true } = options;
|
|
188
133
|
const hasIdentifier = !!(slug || id);
|
|
189
134
|
const flowQuery = useQuery(
|
|
190
|
-
|
|
135
|
+
{
|
|
136
|
+
...flowQueryOptions(client, slug, id),
|
|
191
137
|
enabled: enabled && hasIdentifier
|
|
192
|
-
}
|
|
138
|
+
},
|
|
193
139
|
client.queryClient
|
|
194
140
|
);
|
|
195
141
|
const nodeTypesQuery = useQuery(
|
|
196
|
-
|
|
142
|
+
{
|
|
143
|
+
...nodeTypesQueryOptions(client),
|
|
197
144
|
enabled
|
|
198
|
-
}
|
|
145
|
+
},
|
|
199
146
|
client.queryClient
|
|
200
147
|
);
|
|
201
148
|
const edgeTypesQuery = useQuery(
|
|
202
|
-
|
|
149
|
+
{
|
|
150
|
+
...edgeTypesQueryOptions(client),
|
|
203
151
|
enabled
|
|
204
|
-
}
|
|
152
|
+
},
|
|
205
153
|
client.queryClient
|
|
206
154
|
);
|
|
207
155
|
const nodeTypeDefs = useMemo(() => {
|
|
208
|
-
|
|
209
|
-
const apiDefs = ((_a2 = nodeTypesQuery.data) != null ? _a2 : []).map(toNodeTypeDef);
|
|
156
|
+
const apiDefs = (nodeTypesQuery.data ?? []).map(toNodeTypeDef);
|
|
210
157
|
const builtInSlugs = new Set(BUILT_IN_NODE_TYPES.map((t) => t.slug));
|
|
211
158
|
const customDefs = apiDefs.filter((d) => !builtInSlugs.has(d.slug));
|
|
212
159
|
return [...BUILT_IN_NODE_TYPES, ...customDefs];
|
|
213
160
|
}, [nodeTypesQuery.data]);
|
|
214
161
|
const edgeTypeDefs = useMemo(() => {
|
|
215
|
-
|
|
216
|
-
const apiDefs = ((_a2 = edgeTypesQuery.data) != null ? _a2 : []).map(toEdgeTypeDef);
|
|
162
|
+
const apiDefs = (edgeTypesQuery.data ?? []).map(toEdgeTypeDef);
|
|
217
163
|
const builtInSlugs = new Set(BUILT_IN_EDGE_TYPES.map((t) => t.slug));
|
|
218
164
|
const customDefs = apiDefs.filter((d) => !builtInSlugs.has(d.slug));
|
|
219
165
|
return [...BUILT_IN_EDGE_TYPES, ...customDefs];
|
|
220
166
|
}, [edgeTypesQuery.data]);
|
|
221
167
|
const flow = flowQuery.data;
|
|
222
|
-
const canvas = flow
|
|
168
|
+
const canvas = flow?.canvas;
|
|
223
169
|
return {
|
|
224
170
|
data: canvas,
|
|
225
171
|
nodeTypeDefs,
|
|
226
172
|
edgeTypeDefs,
|
|
227
173
|
flow,
|
|
228
174
|
isLoading: flowQuery.isLoading || nodeTypesQuery.isLoading || edgeTypesQuery.isLoading,
|
|
229
|
-
error:
|
|
175
|
+
error: flowQuery.error ?? nodeTypesQuery.error ?? edgeTypesQuery.error
|
|
230
176
|
};
|
|
231
177
|
}
|
|
232
178
|
|
|
233
179
|
// src/ui/Flow/prefetchFlow.ts
|
|
234
|
-
function prefetchFlow(options) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
]);
|
|
245
|
-
});
|
|
180
|
+
async function prefetchFlow(options) {
|
|
181
|
+
const { client, slug, id } = options;
|
|
182
|
+
if (!slug && !id) {
|
|
183
|
+
throw new Error("prefetchFlow requires either slug or id");
|
|
184
|
+
}
|
|
185
|
+
await Promise.all([
|
|
186
|
+
client.queryClient.prefetchQuery(flowQueryOptions(client, slug, id)),
|
|
187
|
+
client.queryClient.prefetchQuery(nodeTypesQueryOptions(client)),
|
|
188
|
+
client.queryClient.prefetchQuery(edgeTypesQueryOptions(client))
|
|
189
|
+
]);
|
|
246
190
|
}
|
|
247
191
|
|
|
248
192
|
// src/ui/Flow/useFlowData.ts
|
|
@@ -250,21 +194,15 @@ import { useMemo as useMemo2 } from "react";
|
|
|
250
194
|
function useFlowData(options) {
|
|
251
195
|
const { data, nodeTypeDefs: inputNodeDefs, edgeTypeDefs: inputEdgeDefs } = options;
|
|
252
196
|
const nodeTypeDefsMap = useMemo2(() => {
|
|
253
|
-
const allDefs = inputNodeDefs
|
|
197
|
+
const allDefs = inputNodeDefs ?? BUILT_IN_NODE_TYPES;
|
|
254
198
|
return new Map(allDefs.map((d) => [d.slug, d]));
|
|
255
199
|
}, [inputNodeDefs]);
|
|
256
200
|
const edgeTypeDefsMap = useMemo2(() => {
|
|
257
|
-
const allDefs = inputEdgeDefs
|
|
201
|
+
const allDefs = inputEdgeDefs ?? BUILT_IN_EDGE_TYPES;
|
|
258
202
|
return new Map(allDefs.map((d) => [d.slug, d]));
|
|
259
203
|
}, [inputEdgeDefs]);
|
|
260
|
-
const nodes = useMemo2(() =>
|
|
261
|
-
|
|
262
|
-
return (_a = data == null ? void 0 : data.nodes) != null ? _a : [];
|
|
263
|
-
}, [data == null ? void 0 : data.nodes]);
|
|
264
|
-
const edges = useMemo2(() => {
|
|
265
|
-
var _a;
|
|
266
|
-
return (_a = data == null ? void 0 : data.edges) != null ? _a : [];
|
|
267
|
-
}, [data == null ? void 0 : data.edges]);
|
|
204
|
+
const nodes = useMemo2(() => data?.nodes ?? [], [data?.nodes]);
|
|
205
|
+
const edges = useMemo2(() => data?.edges ?? [], [data?.edges]);
|
|
268
206
|
return {
|
|
269
207
|
nodes,
|
|
270
208
|
edges,
|
|
@@ -275,10 +213,9 @@ function useFlowData(options) {
|
|
|
275
213
|
|
|
276
214
|
// src/ui/Flow/utils.ts
|
|
277
215
|
function getNodeSize(node) {
|
|
278
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
279
216
|
return {
|
|
280
|
-
width:
|
|
281
|
-
height:
|
|
217
|
+
width: node.style?.width ?? node.measured?.width ?? node.width ?? 200,
|
|
218
|
+
height: node.style?.height ?? node.measured?.height ?? node.height ?? 200
|
|
282
219
|
};
|
|
283
220
|
}
|
|
284
221
|
function getAbsolutePosition(node, nodeMap) {
|
|
@@ -350,13 +287,12 @@ function getFrames(nodes) {
|
|
|
350
287
|
if (frames.length === 0) return [];
|
|
351
288
|
const nodeMap = new Map(nodes.map((n) => [n.id, n]));
|
|
352
289
|
return frames.map((f) => {
|
|
353
|
-
var _a;
|
|
354
290
|
const data = f.data;
|
|
355
291
|
const abs = getAbsolutePosition(f, nodeMap);
|
|
356
292
|
const { width: w, height: h } = getNodeSize(f);
|
|
357
293
|
return {
|
|
358
294
|
id: f.id,
|
|
359
|
-
label:
|
|
295
|
+
label: data.label ?? "",
|
|
360
296
|
bounds: { x: abs.x, y: abs.y, width: w, height: h }
|
|
361
297
|
};
|
|
362
298
|
}).sort((a, b) => a.bounds.y - b.bounds.y || a.bounds.x - b.bounds.x);
|
|
@@ -365,13 +301,13 @@ function getFrameData(data, frameId) {
|
|
|
365
301
|
const frame = data.nodes.find((n) => n.id === frameId);
|
|
366
302
|
if (!frame || frame.type !== "frame") return void 0;
|
|
367
303
|
const descendantIds = collectDescendants(data.nodes, frameId);
|
|
368
|
-
const childNodes = data.nodes.filter((n) => descendantIds.has(n.id)).map((n) =>
|
|
304
|
+
const childNodes = data.nodes.filter((n) => descendantIds.has(n.id)).map((n) => ({ ...n, draggable: false }));
|
|
369
305
|
const childEdges = data.edges.filter(
|
|
370
306
|
(e) => descendantIds.has(e.source) && descendantIds.has(e.target)
|
|
371
307
|
);
|
|
372
308
|
const frameBounds = getNodeBounds(data.nodes, [frameId]);
|
|
373
309
|
const { width: w, height: h } = getNodeSize(frame);
|
|
374
|
-
const clampBounds = frameBounds
|
|
310
|
+
const clampBounds = frameBounds ?? {
|
|
375
311
|
x: frame.position.x,
|
|
376
312
|
y: frame.position.y,
|
|
377
313
|
width: w,
|
|
@@ -379,7 +315,7 @@ function getFrameData(data, frameId) {
|
|
|
379
315
|
};
|
|
380
316
|
const contentNodeIds = childNodes.filter((n) => n.id !== frameId).map((n) => n.id);
|
|
381
317
|
const contentBounds = contentNodeIds.length > 0 ? getNodeBounds(data.nodes, contentNodeIds) : void 0;
|
|
382
|
-
const fitBounds = contentBounds
|
|
318
|
+
const fitBounds = contentBounds ?? clampBounds;
|
|
383
319
|
return {
|
|
384
320
|
data: {
|
|
385
321
|
nodes: childNodes,
|
|
@@ -420,6 +356,7 @@ function ensureQuickJSLoaded() {
|
|
|
420
356
|
_notify();
|
|
421
357
|
}).catch(() => {
|
|
422
358
|
_state = { status: "failed", module: null };
|
|
359
|
+
_notify();
|
|
423
360
|
});
|
|
424
361
|
}
|
|
425
362
|
function useQuickJS() {
|
|
@@ -429,6 +366,13 @@ function useQuickJS() {
|
|
|
429
366
|
// src/ui/Flow/template-compiler.ts
|
|
430
367
|
var MAX_CACHE_SIZE = 100;
|
|
431
368
|
var MAX_MATERIALIZE_DEPTH = 20;
|
|
369
|
+
var IFRAME_BLOCKED_PROPS = /* @__PURE__ */ new Set([
|
|
370
|
+
"srcdoc",
|
|
371
|
+
"allow",
|
|
372
|
+
"allowpaymentrequest",
|
|
373
|
+
"name",
|
|
374
|
+
"sandbox"
|
|
375
|
+
]);
|
|
432
376
|
var ALLOWED_ELEMENTS = /* @__PURE__ */ new Set([
|
|
433
377
|
"div",
|
|
434
378
|
"span",
|
|
@@ -462,7 +406,8 @@ var ALLOWED_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
462
406
|
"path",
|
|
463
407
|
"g",
|
|
464
408
|
"circle",
|
|
465
|
-
"rect"
|
|
409
|
+
"rect",
|
|
410
|
+
"iframe"
|
|
466
411
|
]);
|
|
467
412
|
var BLOCKED_PATTERNS = [
|
|
468
413
|
/\bdocument\s*\./,
|
|
@@ -542,7 +487,7 @@ function isSafeUrl(value) {
|
|
|
542
487
|
try {
|
|
543
488
|
const url = new URL(value);
|
|
544
489
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
545
|
-
} catch
|
|
490
|
+
} catch {
|
|
546
491
|
return false;
|
|
547
492
|
}
|
|
548
493
|
}
|
|
@@ -564,13 +509,16 @@ function sanitizeStyle(style) {
|
|
|
564
509
|
for (const [k, v] of Object.entries(style)) {
|
|
565
510
|
if (BLOCKED_STYLE_PROPS.has(k)) continue;
|
|
566
511
|
if (typeof v === "string" && /url\s*\(/i.test(v)) continue;
|
|
567
|
-
if (k === "position" && typeof v === "string" && /fixed|
|
|
512
|
+
if (k === "position" && typeof v === "string" && /fixed|sticky/i.test(v)) continue;
|
|
513
|
+
if (k === "zIndex") {
|
|
514
|
+
const n = typeof v === "number" ? v : parseInt(String(v), 10);
|
|
515
|
+
if (isNaN(n) || n > 9998) continue;
|
|
516
|
+
}
|
|
568
517
|
safe[k] = v;
|
|
569
518
|
}
|
|
570
519
|
return safe;
|
|
571
520
|
}
|
|
572
521
|
function materialize(node, depth = 0) {
|
|
573
|
-
var _a;
|
|
574
522
|
if (depth > MAX_MATERIALIZE_DEPTH) return null;
|
|
575
523
|
if (node == null) return null;
|
|
576
524
|
if (typeof node === "string" || typeof node === "number") return node;
|
|
@@ -592,7 +540,7 @@ function materialize(node, depth = 0) {
|
|
|
592
540
|
);
|
|
593
541
|
}
|
|
594
542
|
if (d.$$t === "el") {
|
|
595
|
-
const type = String(
|
|
543
|
+
const type = String(d.type ?? "");
|
|
596
544
|
const props = d.props && typeof d.props === "object" ? d.props : {};
|
|
597
545
|
const ch = Array.isArray(d.ch) ? d.ch : [];
|
|
598
546
|
if (!ALLOWED_ELEMENTS.has(type.toLowerCase())) return null;
|
|
@@ -600,6 +548,7 @@ function materialize(node, depth = 0) {
|
|
|
600
548
|
for (const [k, v] of Object.entries(props)) {
|
|
601
549
|
if (k.startsWith("on")) continue;
|
|
602
550
|
if (k === "dangerouslySetInnerHTML" || k === "ref") continue;
|
|
551
|
+
if (type === "iframe" && IFRAME_BLOCKED_PROPS.has(k)) continue;
|
|
603
552
|
if ((k === "src" || k === "href") && !isSafeUrl(v)) continue;
|
|
604
553
|
if (k === "style") {
|
|
605
554
|
safeProps[k] = sanitizeStyle(v);
|
|
@@ -607,6 +556,9 @@ function materialize(node, depth = 0) {
|
|
|
607
556
|
}
|
|
608
557
|
safeProps[k] = v;
|
|
609
558
|
}
|
|
559
|
+
if (type === "iframe") {
|
|
560
|
+
safeProps["sandbox"] = "allow-scripts allow-same-origin";
|
|
561
|
+
}
|
|
610
562
|
const children = ch.map((c) => materialize(c, depth + 1));
|
|
611
563
|
return React.createElement(type, safeProps, ...children);
|
|
612
564
|
}
|
|
@@ -640,7 +592,7 @@ function makeRenderer(jsCode) {
|
|
|
640
592
|
const raw = vm.dump(callResult.handle);
|
|
641
593
|
callResult.handle.dispose();
|
|
642
594
|
return materialize(JSON.parse(String(raw)));
|
|
643
|
-
} catch
|
|
595
|
+
} catch {
|
|
644
596
|
return null;
|
|
645
597
|
} finally {
|
|
646
598
|
vm.dispose();
|
|
@@ -649,8 +601,7 @@ function makeRenderer(jsCode) {
|
|
|
649
601
|
}
|
|
650
602
|
function makeReactFC(renderer, qjs) {
|
|
651
603
|
return function QuickJSTemplateComponent(props) {
|
|
652
|
-
|
|
653
|
-
return (_a = renderer(qjs, props)) != null ? _a : null;
|
|
604
|
+
return renderer(qjs, props) ?? null;
|
|
654
605
|
};
|
|
655
606
|
}
|
|
656
607
|
function compileTemplate(code, slug) {
|
|
@@ -660,10 +611,10 @@ function compileTemplate(code, slug) {
|
|
|
660
611
|
if (!qjs) return null;
|
|
661
612
|
const cacheKey = `${slug}:${code.length}:${hashCode(code)}`;
|
|
662
613
|
if (rendererCache.has(cacheKey)) {
|
|
663
|
-
const
|
|
614
|
+
const entry = rendererCache.get(cacheKey);
|
|
664
615
|
rendererCache.delete(cacheKey);
|
|
665
|
-
rendererCache.set(cacheKey,
|
|
666
|
-
return
|
|
616
|
+
rendererCache.set(cacheKey, entry);
|
|
617
|
+
return entry.fc;
|
|
667
618
|
}
|
|
668
619
|
let jsCode;
|
|
669
620
|
try {
|
|
@@ -674,16 +625,17 @@ function compileTemplate(code, slug) {
|
|
|
674
625
|
jsxFragmentPragma: "React.Fragment"
|
|
675
626
|
});
|
|
676
627
|
jsCode = result.code;
|
|
677
|
-
} catch
|
|
628
|
+
} catch {
|
|
678
629
|
return null;
|
|
679
630
|
}
|
|
680
631
|
const renderer = makeRenderer(jsCode);
|
|
632
|
+
const fc = makeReactFC(renderer, qjs);
|
|
681
633
|
if (rendererCache.size >= MAX_CACHE_SIZE) {
|
|
682
634
|
const oldest = rendererCache.keys().next().value;
|
|
683
635
|
if (oldest) rendererCache.delete(oldest);
|
|
684
636
|
}
|
|
685
|
-
rendererCache.set(cacheKey, renderer);
|
|
686
|
-
return
|
|
637
|
+
rendererCache.set(cacheKey, { renderer, fc });
|
|
638
|
+
return fc;
|
|
687
639
|
}
|
|
688
640
|
function clearTemplateCache() {
|
|
689
641
|
rendererCache.clear();
|
|
@@ -697,15 +649,15 @@ function sanitizeUrl(url) {
|
|
|
697
649
|
const parsed = new URL(url);
|
|
698
650
|
if (parsed.protocol === "http:" || parsed.protocol === "https:") return url;
|
|
699
651
|
return void 0;
|
|
700
|
-
} catch
|
|
652
|
+
} catch {
|
|
701
653
|
return void 0;
|
|
702
654
|
}
|
|
703
655
|
}
|
|
704
656
|
function renderFieldValue(key, val, fieldDef) {
|
|
705
657
|
if (val == null || val === "") return null;
|
|
706
|
-
const fieldType = fieldDef
|
|
658
|
+
const fieldType = fieldDef?.fieldType;
|
|
707
659
|
if (fieldType === "image" || typeof val === "object" && val !== null && "url" in val) {
|
|
708
|
-
const imgUrl = typeof val === "string" ? val : val
|
|
660
|
+
const imgUrl = typeof val === "string" ? val : val?.url;
|
|
709
661
|
const safeUrl = sanitizeUrl(imgUrl);
|
|
710
662
|
if (!safeUrl) return null;
|
|
711
663
|
return /* @__PURE__ */ React2.createElement(
|
|
@@ -818,12 +770,11 @@ function EnhancedDynamicNode({
|
|
|
818
770
|
);
|
|
819
771
|
}
|
|
820
772
|
function DefaultFrameNode({ data }) {
|
|
821
|
-
var _a, _b, _c, _d;
|
|
822
773
|
const d = data;
|
|
823
|
-
const baseColor =
|
|
824
|
-
const padding =
|
|
825
|
-
const borderStyle =
|
|
826
|
-
const opacity =
|
|
774
|
+
const baseColor = d.color ?? "rgb(128,128,128)";
|
|
775
|
+
const padding = d.padding ?? 20;
|
|
776
|
+
const borderStyle = d.borderStyle ?? "dashed";
|
|
777
|
+
const opacity = d.opacity ?? 0.15;
|
|
827
778
|
const bgColor = (() => {
|
|
828
779
|
const m = baseColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
829
780
|
if (m) return `rgba(${m[1]},${m[2]},${m[3]},${opacity})`;
|
|
@@ -857,21 +808,21 @@ function DefaultFrameNode({ data }) {
|
|
|
857
808
|
|
|
858
809
|
// src/ui/Flow/field-helpers.ts
|
|
859
810
|
function getImageField(fields, name) {
|
|
860
|
-
const val = fields
|
|
811
|
+
const val = fields?.[name];
|
|
861
812
|
if (val && typeof val === "object" && val !== null && "url" in val)
|
|
862
813
|
return val;
|
|
863
814
|
return void 0;
|
|
864
815
|
}
|
|
865
816
|
function getTextField(fields, name) {
|
|
866
|
-
const val = fields
|
|
817
|
+
const val = fields?.[name];
|
|
867
818
|
return typeof val === "string" ? val : void 0;
|
|
868
819
|
}
|
|
869
820
|
function getNumberField(fields, name) {
|
|
870
|
-
const val = fields
|
|
821
|
+
const val = fields?.[name];
|
|
871
822
|
return typeof val === "number" ? val : void 0;
|
|
872
823
|
}
|
|
873
824
|
function getBooleanField(fields, name) {
|
|
874
|
-
const val = fields
|
|
825
|
+
const val = fields?.[name];
|
|
875
826
|
return typeof val === "boolean" ? val : void 0;
|
|
876
827
|
}
|
|
877
828
|
|
|
@@ -880,21 +831,77 @@ import postcss from "postcss";
|
|
|
880
831
|
var ALLOWED_AT_RULES = /* @__PURE__ */ new Set(["keyframes", "media", "supports", "container", "layer"]);
|
|
881
832
|
var BLOCKED_VALUE_PATTERNS = [/url\s*\(/i, /expression\s*\(/i, /paint\s*\(/i, /-moz-binding/i];
|
|
882
833
|
var DANGEROUS_SELECTOR = /(?:^|[\s,])(?::root|html|body)\b/;
|
|
834
|
+
var BLOCKED_PROPERTY_VALUES = {
|
|
835
|
+
// absolute is allowed — contained by nearest positioned ancestor (node wrapper)
|
|
836
|
+
position: /fixed|sticky/i
|
|
837
|
+
};
|
|
838
|
+
var Z_INDEX_MAX = 9998;
|
|
883
839
|
function sanitizeCSS(css, scopeClass) {
|
|
884
840
|
let root;
|
|
885
841
|
try {
|
|
886
842
|
root = postcss.parse(css);
|
|
887
|
-
} catch
|
|
843
|
+
} catch {
|
|
888
844
|
return "";
|
|
889
845
|
}
|
|
846
|
+
const safeScopeClass = scopeClass ? scopeClass.replace(/[{}()[\];,'"\\<>\s]/g, "") : "";
|
|
847
|
+
const keyframeNameMap = /* @__PURE__ */ new Map();
|
|
848
|
+
if (safeScopeClass) {
|
|
849
|
+
root.walkAtRules(/^keyframes$/i, (node) => {
|
|
850
|
+
const rawName = node.params.trim().replace(/^['"]|['"]$/g, "");
|
|
851
|
+
const originalName = rawName;
|
|
852
|
+
const scopedName = `${safeScopeClass}__${rawName.replace(/\s+/g, "_")}`;
|
|
853
|
+
keyframeNameMap.set(originalName, scopedName);
|
|
854
|
+
node.params = scopedName;
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
if (safeScopeClass && keyframeNameMap.size > 0) {
|
|
858
|
+
const ANIM_KEYWORDS = /* @__PURE__ */ new Set(["none", "initial", "inherit", "unset", "revert"]);
|
|
859
|
+
const replaceAnimName = (token) => {
|
|
860
|
+
const t = token.trim().replace(/^['"]|['"]$/g, "");
|
|
861
|
+
return ANIM_KEYWORDS.has(t) ? token : keyframeNameMap.get(t) ?? token;
|
|
862
|
+
};
|
|
863
|
+
root.walkDecls(/^animation-name$/i, (node) => {
|
|
864
|
+
node.value = node.value.split(",").map(replaceAnimName).join(", ");
|
|
865
|
+
});
|
|
866
|
+
root.walkDecls(/^animation$/i, (node) => {
|
|
867
|
+
node.value = node.value.split(",").map(
|
|
868
|
+
(anim) => anim.split(/(\s+)/).map((token) => /\s/.test(token) ? token : replaceAnimName(token)).join("")
|
|
869
|
+
).join(",");
|
|
870
|
+
});
|
|
871
|
+
}
|
|
890
872
|
root.walkAtRules((node) => {
|
|
891
873
|
if (!ALLOWED_AT_RULES.has(node.name.toLowerCase())) {
|
|
892
874
|
node.remove();
|
|
893
875
|
}
|
|
894
876
|
});
|
|
895
877
|
root.walkDecls((node) => {
|
|
896
|
-
|
|
878
|
+
const normalizedValue = node.value.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
879
|
+
if (BLOCKED_VALUE_PATTERNS.some((p) => p.test(normalizedValue))) {
|
|
897
880
|
node.remove();
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const propLower = node.prop.toLowerCase();
|
|
884
|
+
const blockedValuePattern = BLOCKED_PROPERTY_VALUES[propLower];
|
|
885
|
+
if (blockedValuePattern) {
|
|
886
|
+
const deescaped = normalizedValue.replace(
|
|
887
|
+
/\\([0-9a-fA-F]{1,6})\s?/g,
|
|
888
|
+
(_, hex) => String.fromCodePoint(parseInt(hex, 16))
|
|
889
|
+
);
|
|
890
|
+
if (blockedValuePattern.test(deescaped)) {
|
|
891
|
+
node.remove();
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (propLower === "z-index") {
|
|
896
|
+
const zv = node.value.trim();
|
|
897
|
+
if (zv === "auto" || zv === "initial" || zv === "inherit" || zv === "unset" || zv === "revert") {
|
|
898
|
+
} else {
|
|
899
|
+
const val = parseInt(zv, 10);
|
|
900
|
+
if (isNaN(val) || String(val) !== zv || val > Z_INDEX_MAX) {
|
|
901
|
+
node.remove();
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
898
905
|
}
|
|
899
906
|
});
|
|
900
907
|
root.walkRules((rule) => {
|
|
@@ -904,13 +911,12 @@ function sanitizeCSS(css, scopeClass) {
|
|
|
904
911
|
return;
|
|
905
912
|
}
|
|
906
913
|
if (scopeClass) {
|
|
907
|
-
const safeScopeClass = scopeClass.replace(/[{}()[\];,'"\\<>]/g, "");
|
|
908
914
|
if (!safeScopeClass) {
|
|
909
915
|
rule.remove();
|
|
910
916
|
return;
|
|
911
917
|
}
|
|
912
918
|
const parent = rule.parent;
|
|
913
|
-
if (
|
|
919
|
+
if (parent?.type === "atrule" && parent.name.toLowerCase() === "keyframes") {
|
|
914
920
|
return;
|
|
915
921
|
}
|
|
916
922
|
rule.selectors = rule.selectors.map((sel) => `.${safeScopeClass} ${sel}`);
|
|
@@ -943,7 +949,7 @@ function getImageSrcSet(image) {
|
|
|
943
949
|
if (sizes) {
|
|
944
950
|
for (const size of IMAGE_SIZES) {
|
|
945
951
|
const entry = sizes[String(size)];
|
|
946
|
-
if (
|
|
952
|
+
if (entry?.url && entry.width) {
|
|
947
953
|
parts.push(`${entry.url} ${entry.width}w`);
|
|
948
954
|
}
|
|
949
955
|
}
|
|
@@ -954,11 +960,10 @@ function getImageSrcSet(image) {
|
|
|
954
960
|
return parts.join(", ");
|
|
955
961
|
}
|
|
956
962
|
function getImagePlaceholderStyle(image, options) {
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
const paletteColor = (_b = options == null ? void 0 : options.paletteColor) != null ? _b : "muted";
|
|
963
|
+
const type = options?.type ?? "blur";
|
|
964
|
+
const paletteColor = options?.paletteColor ?? "muted";
|
|
960
965
|
if (type === "none") return {};
|
|
961
|
-
const color =
|
|
966
|
+
const color = image.palette?.[paletteColor];
|
|
962
967
|
if (type === "blur") {
|
|
963
968
|
const lqip = image.lqip;
|
|
964
969
|
if (lqip) {
|
|
@@ -997,15 +1002,14 @@ function Image({
|
|
|
997
1002
|
fill = false,
|
|
998
1003
|
imageRendering
|
|
999
1004
|
}) {
|
|
1000
|
-
var _a, _b;
|
|
1001
1005
|
const [loaded, setLoaded] = useState(false);
|
|
1002
1006
|
const firedRef = useRef(false);
|
|
1003
1007
|
const isPixelRendering = imageRendering === "pixelated" || imageRendering === "crisp-edges";
|
|
1004
|
-
const placeholder = placeholderProp
|
|
1005
|
-
const loading = priority ? "eager" : loadingProp
|
|
1008
|
+
const placeholder = placeholderProp ?? (isPixelRendering ? "none" : "blur");
|
|
1009
|
+
const loading = priority ? "eager" : loadingProp ?? "lazy";
|
|
1006
1010
|
const aspectRatio = !fill && image.width && image.height ? `${image.width} / ${image.height}` : void 0;
|
|
1007
1011
|
const srcSet = getImageSrcSet(image);
|
|
1008
|
-
const src =
|
|
1012
|
+
const src = image.url ?? void 0;
|
|
1009
1013
|
const hasLqip = placeholder === "blur" && !!image.lqip;
|
|
1010
1014
|
const placeholderStyle = getImagePlaceholderStyle(image, {
|
|
1011
1015
|
type: placeholder
|
|
@@ -1015,7 +1019,7 @@ function Image({
|
|
|
1015
1019
|
if (firedRef.current) return;
|
|
1016
1020
|
firedRef.current = true;
|
|
1017
1021
|
setLoaded(true);
|
|
1018
|
-
onLoad
|
|
1022
|
+
onLoad?.();
|
|
1019
1023
|
}, [onLoad]);
|
|
1020
1024
|
const imgRef = useCallback(
|
|
1021
1025
|
(node) => {
|
|
@@ -1025,10 +1029,13 @@ function Image({
|
|
|
1025
1029
|
},
|
|
1026
1030
|
[fireLoad]
|
|
1027
1031
|
);
|
|
1028
|
-
const containerStyle =
|
|
1032
|
+
const containerStyle = {
|
|
1029
1033
|
position: "relative",
|
|
1030
|
-
overflow: "hidden"
|
|
1031
|
-
|
|
1034
|
+
overflow: "hidden",
|
|
1035
|
+
...fill ? { width: "100%", height: "100%" } : {},
|
|
1036
|
+
...aspectRatio ? { aspectRatio } : {},
|
|
1037
|
+
...style
|
|
1038
|
+
};
|
|
1032
1039
|
const overlayBase = {
|
|
1033
1040
|
position: "absolute",
|
|
1034
1041
|
top: 0,
|
|
@@ -1039,41 +1046,44 @@ function Image({
|
|
|
1039
1046
|
transition: "opacity 0.3s ease",
|
|
1040
1047
|
pointerEvents: "none"
|
|
1041
1048
|
};
|
|
1042
|
-
const mainImgStyle =
|
|
1049
|
+
const mainImgStyle = {
|
|
1043
1050
|
display: "block",
|
|
1044
1051
|
width: "100%",
|
|
1045
1052
|
height: "100%",
|
|
1046
|
-
objectFit
|
|
1047
|
-
|
|
1053
|
+
objectFit,
|
|
1054
|
+
...imageRendering ? { imageRendering } : {},
|
|
1048
1055
|
opacity: loaded ? 1 : 0,
|
|
1049
|
-
transition: "opacity 0.3s ease"
|
|
1050
|
-
|
|
1056
|
+
transition: "opacity 0.3s ease",
|
|
1057
|
+
...imgStyle
|
|
1058
|
+
};
|
|
1051
1059
|
return /* @__PURE__ */ React3.createElement("div", { className, style: containerStyle }, hasLqip && /* @__PURE__ */ React3.createElement(
|
|
1052
1060
|
"img",
|
|
1053
1061
|
{
|
|
1054
1062
|
"aria-hidden": true,
|
|
1055
1063
|
alt: "",
|
|
1056
1064
|
src: image.lqip,
|
|
1057
|
-
style:
|
|
1065
|
+
style: {
|
|
1066
|
+
...overlayBase,
|
|
1058
1067
|
display: "block",
|
|
1059
1068
|
objectFit,
|
|
1060
1069
|
filter: "blur(20px)",
|
|
1061
1070
|
transform: "scale(1.1)"
|
|
1062
|
-
}
|
|
1071
|
+
}
|
|
1063
1072
|
}
|
|
1064
1073
|
), placeholderColor && /* @__PURE__ */ React3.createElement(
|
|
1065
1074
|
"div",
|
|
1066
1075
|
{
|
|
1067
1076
|
"aria-hidden": true,
|
|
1068
|
-
style:
|
|
1077
|
+
style: {
|
|
1078
|
+
...overlayBase,
|
|
1069
1079
|
backgroundColor: placeholderColor
|
|
1070
|
-
}
|
|
1080
|
+
}
|
|
1071
1081
|
}
|
|
1072
1082
|
), /* @__PURE__ */ React3.createElement(
|
|
1073
1083
|
"img",
|
|
1074
1084
|
{
|
|
1075
1085
|
ref: imgRef,
|
|
1076
|
-
alt:
|
|
1086
|
+
alt: image.alt ?? "",
|
|
1077
1087
|
src,
|
|
1078
1088
|
srcSet: srcSet || void 0,
|
|
1079
1089
|
sizes,
|
|
@@ -1092,10 +1102,9 @@ function Image({
|
|
|
1092
1102
|
function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrapper, renderNode) {
|
|
1093
1103
|
const types = {};
|
|
1094
1104
|
types.dynamic = ((props) => {
|
|
1095
|
-
var _a;
|
|
1096
1105
|
const d = props.data;
|
|
1097
|
-
const typeDef = nodeTypeDefsMap
|
|
1098
|
-
const CustomRenderer = nodeRenderers
|
|
1106
|
+
const typeDef = nodeTypeDefsMap?.get(d.nodeTypeSlug);
|
|
1107
|
+
const CustomRenderer = nodeRenderers?.[d.nodeTypeSlug];
|
|
1099
1108
|
const defaultRender = typeDef ? /* @__PURE__ */ React4.createElement(
|
|
1100
1109
|
EnhancedDynamicNode,
|
|
1101
1110
|
{
|
|
@@ -1104,7 +1113,7 @@ function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrap
|
|
|
1104
1113
|
width: props.width,
|
|
1105
1114
|
height: props.height
|
|
1106
1115
|
}
|
|
1107
|
-
) : /* @__PURE__ */ React4.createElement(DefaultDynamicNode,
|
|
1116
|
+
) : /* @__PURE__ */ React4.createElement(DefaultDynamicNode, { ...props });
|
|
1108
1117
|
const slotProps = {
|
|
1109
1118
|
id: props.id,
|
|
1110
1119
|
nodeTypeSlug: d.nodeTypeSlug,
|
|
@@ -1118,9 +1127,9 @@ function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrap
|
|
|
1118
1127
|
};
|
|
1119
1128
|
let content;
|
|
1120
1129
|
if (CustomRenderer) {
|
|
1121
|
-
content = /* @__PURE__ */ React4.createElement(CustomRenderer,
|
|
1130
|
+
content = /* @__PURE__ */ React4.createElement(CustomRenderer, { ...slotProps });
|
|
1122
1131
|
} else if (d.nodeTypeSlug === "image") {
|
|
1123
|
-
const imageVal =
|
|
1132
|
+
const imageVal = d.fields?.image;
|
|
1124
1133
|
if (imageVal && typeof imageVal === "object" && "url" in imageVal) {
|
|
1125
1134
|
content = /* @__PURE__ */ React4.createElement(
|
|
1126
1135
|
Image,
|
|
@@ -1183,8 +1192,7 @@ function createEdgeTypes(edgeRenderers, edgeTypeDefsMap) {
|
|
|
1183
1192
|
const types = {};
|
|
1184
1193
|
for (const [slug, Renderer] of Object.entries(edgeRenderers)) {
|
|
1185
1194
|
types[slug] = ((props) => {
|
|
1186
|
-
|
|
1187
|
-
const def = edgeTypeDefsMap == null ? void 0 : edgeTypeDefsMap.get(slug);
|
|
1195
|
+
const def = edgeTypeDefsMap?.get(slug);
|
|
1188
1196
|
return /* @__PURE__ */ React4.createElement(
|
|
1189
1197
|
Renderer,
|
|
1190
1198
|
{
|
|
@@ -1193,7 +1201,7 @@ function createEdgeTypes(edgeRenderers, edgeTypeDefsMap) {
|
|
|
1193
1201
|
source: props.source,
|
|
1194
1202
|
target: props.target,
|
|
1195
1203
|
label: props.label,
|
|
1196
|
-
fields:
|
|
1204
|
+
fields: props.data?.fields,
|
|
1197
1205
|
edgeTypeDef: def,
|
|
1198
1206
|
style: props.style
|
|
1199
1207
|
}
|
|
@@ -1217,33 +1225,38 @@ var EDGE_TYPE_MAP = {
|
|
|
1217
1225
|
default: "default"
|
|
1218
1226
|
};
|
|
1219
1227
|
function applyEdgeStyles(edges, edgeTypeDefsMap) {
|
|
1220
|
-
if (!
|
|
1228
|
+
if (!edgeTypeDefsMap?.size) return edges;
|
|
1221
1229
|
return edges.map((edge) => {
|
|
1222
|
-
var _a;
|
|
1223
1230
|
const slug = edge.edgeTypeSlug;
|
|
1224
1231
|
if (!slug) return edge;
|
|
1225
1232
|
const def = edgeTypeDefsMap.get(slug);
|
|
1226
1233
|
if (!def) return edge;
|
|
1227
|
-
const styled =
|
|
1234
|
+
const styled = { ...edge };
|
|
1228
1235
|
if (!styled.type && def.lineStyle) {
|
|
1229
|
-
styled.type =
|
|
1236
|
+
styled.type = EDGE_TYPE_MAP[def.lineStyle] ?? "default";
|
|
1230
1237
|
}
|
|
1231
|
-
styled.style =
|
|
1238
|
+
styled.style = {
|
|
1239
|
+
...def.color ? { stroke: def.color } : void 0,
|
|
1240
|
+
...def.strokeWidth ? { strokeWidth: def.strokeWidth } : void 0,
|
|
1241
|
+
...edge.style
|
|
1242
|
+
};
|
|
1232
1243
|
if (styled.animated == null && def.animated) styled.animated = true;
|
|
1233
1244
|
if (!styled.markerStart) {
|
|
1234
1245
|
const startType = toMarkerType(def.markerStart);
|
|
1235
1246
|
if (startType) {
|
|
1236
|
-
styled.markerStart =
|
|
1237
|
-
type: startType
|
|
1238
|
-
|
|
1247
|
+
styled.markerStart = {
|
|
1248
|
+
type: startType,
|
|
1249
|
+
...def.color ? { color: def.color } : void 0
|
|
1250
|
+
};
|
|
1239
1251
|
}
|
|
1240
1252
|
}
|
|
1241
1253
|
if (!styled.markerEnd) {
|
|
1242
1254
|
const endType = toMarkerType(def.markerEnd);
|
|
1243
1255
|
if (endType) {
|
|
1244
|
-
styled.markerEnd =
|
|
1245
|
-
type: endType
|
|
1246
|
-
|
|
1256
|
+
styled.markerEnd = {
|
|
1257
|
+
type: endType,
|
|
1258
|
+
...def.color ? { color: def.color } : void 0
|
|
1259
|
+
};
|
|
1247
1260
|
}
|
|
1248
1261
|
}
|
|
1249
1262
|
return styled;
|
|
@@ -1318,7 +1331,7 @@ function FocusHandler({
|
|
|
1318
1331
|
if (bw === 0 || bh === 0) return;
|
|
1319
1332
|
const zoomFn = mode === "cover" ? Math.max : Math.min;
|
|
1320
1333
|
const zoom = zoomFn(containerSize.w / bw, containerSize.h / bh);
|
|
1321
|
-
const centerTarget = clampBounds
|
|
1334
|
+
const centerTarget = clampBounds ?? b;
|
|
1322
1335
|
const cx = centerTarget.x + centerTarget.width / 2;
|
|
1323
1336
|
const cy = centerTarget.y + centerTarget.height / 2;
|
|
1324
1337
|
const x = containerSize.w / 2 - cx * zoom;
|
|
@@ -1328,9 +1341,9 @@ function FocusHandler({
|
|
|
1328
1341
|
containerSize.w / clampBounds.width,
|
|
1329
1342
|
containerSize.h / clampBounds.height
|
|
1330
1343
|
);
|
|
1331
|
-
store.getState().setMinZoom(Math.max(Math.min(coverZoom, zoom), minZoomProp
|
|
1344
|
+
store.getState().setMinZoom(Math.max(Math.min(coverZoom, zoom), minZoomProp ?? 0));
|
|
1332
1345
|
} else {
|
|
1333
|
-
store.getState().setMinZoom(minZoomProp
|
|
1346
|
+
store.getState().setMinZoom(minZoomProp ?? 0.5);
|
|
1334
1347
|
}
|
|
1335
1348
|
let vp = { x, y, zoom };
|
|
1336
1349
|
if (isInitial || isBoundsChange) {
|
|
@@ -1338,12 +1351,12 @@ function FocusHandler({
|
|
|
1338
1351
|
if (extent) {
|
|
1339
1352
|
const visW = containerSize.w / zoom;
|
|
1340
1353
|
const visH = containerSize.h / zoom;
|
|
1341
|
-
onInitialFit
|
|
1354
|
+
onInitialFit?.([
|
|
1342
1355
|
[Math.min(extent[0][0], cx - visW / 2), Math.min(extent[0][1], cy - visH / 2)],
|
|
1343
1356
|
[Math.max(extent[1][0], cx + visW / 2), Math.max(extent[1][1], cy + visH / 2)]
|
|
1344
1357
|
]);
|
|
1345
1358
|
} else {
|
|
1346
|
-
onInitialFit
|
|
1359
|
+
onInitialFit?.();
|
|
1347
1360
|
}
|
|
1348
1361
|
} else {
|
|
1349
1362
|
if (extent) {
|
|
@@ -1419,14 +1432,13 @@ function FlowRenderer({
|
|
|
1419
1432
|
minZoom: minZoomProp,
|
|
1420
1433
|
maxZoom: maxZoomProp
|
|
1421
1434
|
}) {
|
|
1422
|
-
var _a, _b;
|
|
1423
1435
|
const resolvedFrameRenderer = hideFrames ? NullFrameRenderer : frameRenderer;
|
|
1424
1436
|
const nodeTypeDefsMap = React6.useMemo(() => {
|
|
1425
|
-
if (!
|
|
1437
|
+
if (!nodeTypeDefs?.length) return void 0;
|
|
1426
1438
|
return new Map(nodeTypeDefs.map((d) => [d.slug, d]));
|
|
1427
1439
|
}, [nodeTypeDefs]);
|
|
1428
1440
|
const edgeTypeDefsMap = React6.useMemo(() => {
|
|
1429
|
-
if (!
|
|
1441
|
+
if (!edgeTypeDefs?.length) return void 0;
|
|
1430
1442
|
return new Map(edgeTypeDefs.map((d) => [d.slug, d]));
|
|
1431
1443
|
}, [edgeTypeDefs]);
|
|
1432
1444
|
const nodeTypes = React6.useMemo(
|
|
@@ -1444,28 +1456,27 @@ function FlowRenderer({
|
|
|
1444
1456
|
[edgeRenderers, edgeTypeDefsMap]
|
|
1445
1457
|
);
|
|
1446
1458
|
const mergedCSS = React6.useMemo(() => {
|
|
1447
|
-
if (!
|
|
1459
|
+
if (!nodeTypeDefs?.length) return "";
|
|
1448
1460
|
return nodeTypeDefs.filter((d) => d.customCSS).map((d) => sanitizeCSS(d.customCSS, `flow-node--${d.slug}`)).join("\n");
|
|
1449
1461
|
}, [nodeTypeDefs]);
|
|
1450
1462
|
const styledEdges = React6.useMemo(() => {
|
|
1451
|
-
|
|
1452
|
-
let edges = applyEdgeStyles((_a2 = data == null ? void 0 : data.edges) != null ? _a2 : [], edgeTypeDefsMap);
|
|
1463
|
+
let edges = applyEdgeStyles(data?.edges ?? [], edgeTypeDefsMap);
|
|
1453
1464
|
if (edgeRenderers) {
|
|
1454
1465
|
edges = edges.map((edge) => {
|
|
1455
1466
|
const slug = edge.edgeTypeSlug;
|
|
1456
1467
|
if (slug && edgeRenderers[slug]) {
|
|
1457
|
-
return
|
|
1468
|
+
return { ...edge, type: slug };
|
|
1458
1469
|
}
|
|
1459
1470
|
return edge;
|
|
1460
1471
|
});
|
|
1461
1472
|
}
|
|
1462
1473
|
return edges;
|
|
1463
|
-
}, [data
|
|
1474
|
+
}, [data?.edges, edgeTypeDefsMap, edgeRenderers]);
|
|
1464
1475
|
const translateExtent = React6.useMemo(() => {
|
|
1465
1476
|
if (translateExtentProp) return translateExtentProp;
|
|
1466
|
-
const es = clampBounds
|
|
1477
|
+
const es = clampBounds ?? bounds;
|
|
1467
1478
|
if (!es) return void 0;
|
|
1468
|
-
const ep = clampBounds ? 0 : focusPadding
|
|
1479
|
+
const ep = clampBounds ? 0 : focusPadding ?? 0.1;
|
|
1469
1480
|
return [
|
|
1470
1481
|
[es.x - ep * es.width, es.y - ep * es.height],
|
|
1471
1482
|
[es.x + es.width * (1 + ep), es.y + es.height * (1 + ep)]
|
|
@@ -1489,23 +1500,24 @@ function FlowRenderer({
|
|
|
1489
1500
|
},
|
|
1490
1501
|
[]
|
|
1491
1502
|
);
|
|
1492
|
-
const activeExtent = !bounds || extentReadyRef.current ?
|
|
1503
|
+
const activeExtent = !bounds || extentReadyRef.current ? expandedExtentRef.current ?? translateExtent : void 0;
|
|
1493
1504
|
if (!data) return null;
|
|
1494
|
-
const resolvedDefaultViewport = defaultViewportProp
|
|
1505
|
+
const resolvedDefaultViewport = defaultViewportProp ?? (!fitView && data.viewport ? data.viewport : void 0);
|
|
1495
1506
|
return /* @__PURE__ */ React6.createElement(ReactFlowProvider, null, /* @__PURE__ */ React6.createElement(
|
|
1496
1507
|
"div",
|
|
1497
1508
|
{
|
|
1498
1509
|
className,
|
|
1499
|
-
style:
|
|
1510
|
+
style: {
|
|
1500
1511
|
width: "100%",
|
|
1501
1512
|
height: "100%",
|
|
1502
|
-
background: "transparent"
|
|
1503
|
-
|
|
1513
|
+
background: "transparent",
|
|
1514
|
+
...style
|
|
1515
|
+
}
|
|
1504
1516
|
},
|
|
1505
1517
|
/* @__PURE__ */ React6.createElement(
|
|
1506
1518
|
ReactFlow,
|
|
1507
1519
|
{
|
|
1508
|
-
nodes:
|
|
1520
|
+
nodes: data.nodes ?? [],
|
|
1509
1521
|
edges: styledEdges,
|
|
1510
1522
|
nodeTypes,
|
|
1511
1523
|
edgeTypes: customEdgeTypes,
|
|
@@ -1545,10 +1557,10 @@ function FlowRenderer({
|
|
|
1545
1557
|
FocusHandler,
|
|
1546
1558
|
{
|
|
1547
1559
|
bounds,
|
|
1548
|
-
padding: focusPadding
|
|
1549
|
-
animation: focusAnimation
|
|
1560
|
+
padding: focusPadding ?? 0.1,
|
|
1561
|
+
animation: focusAnimation ?? true,
|
|
1550
1562
|
mode: focusMode,
|
|
1551
|
-
responsive: responsiveFit
|
|
1563
|
+
responsive: responsiveFit ?? true,
|
|
1552
1564
|
extent: translateExtent,
|
|
1553
1565
|
clampBounds,
|
|
1554
1566
|
minZoomProp,
|
|
@@ -1562,24 +1574,16 @@ function FlowRenderer({
|
|
|
1562
1574
|
|
|
1563
1575
|
// src/ui/Flow/FlowFrame.tsx
|
|
1564
1576
|
import React7, { useMemo as useMemo3, useEffect, useRef as useRef2 } from "react";
|
|
1565
|
-
function FlowFrame(
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
"client",
|
|
1576
|
-
"slug",
|
|
1577
|
-
"id",
|
|
1578
|
-
"frameId",
|
|
1579
|
-
"loading",
|
|
1580
|
-
"error",
|
|
1581
|
-
"onDataReady"
|
|
1582
|
-
]);
|
|
1577
|
+
function FlowFrame({
|
|
1578
|
+
client,
|
|
1579
|
+
slug,
|
|
1580
|
+
id,
|
|
1581
|
+
frameId,
|
|
1582
|
+
loading = null,
|
|
1583
|
+
error: renderError,
|
|
1584
|
+
onDataReady,
|
|
1585
|
+
...rendererProps
|
|
1586
|
+
}) {
|
|
1583
1587
|
const { data, nodeTypeDefs, edgeTypeDefs, flow, isLoading, error } = useFlow({
|
|
1584
1588
|
client,
|
|
1585
1589
|
slug,
|
|
@@ -1592,9 +1596,8 @@ function FlowFrame(_a) {
|
|
|
1592
1596
|
const onDataReadyRef = useRef2(onDataReady);
|
|
1593
1597
|
onDataReadyRef.current = onDataReady;
|
|
1594
1598
|
useEffect(() => {
|
|
1595
|
-
var _a2;
|
|
1596
1599
|
if (frameData && flow) {
|
|
1597
|
-
|
|
1600
|
+
onDataReadyRef.current?.(frameData, flow);
|
|
1598
1601
|
}
|
|
1599
1602
|
}, [frameData, flow]);
|
|
1600
1603
|
if (process.env.NODE_ENV !== "production" && !slug && !id) {
|
|
@@ -1613,14 +1616,15 @@ function FlowFrame(_a) {
|
|
|
1613
1616
|
}
|
|
1614
1617
|
return /* @__PURE__ */ React7.createElement(
|
|
1615
1618
|
FlowRenderer,
|
|
1616
|
-
|
|
1619
|
+
{
|
|
1620
|
+
...rendererProps,
|
|
1617
1621
|
data: frameData.data,
|
|
1618
1622
|
nodeTypeDefs,
|
|
1619
1623
|
edgeTypeDefs,
|
|
1620
1624
|
bounds: frameData.fitBounds,
|
|
1621
1625
|
clampBounds: frameData.clampBounds,
|
|
1622
1626
|
hideFrames: true
|
|
1623
|
-
}
|
|
1627
|
+
}
|
|
1624
1628
|
);
|
|
1625
1629
|
}
|
|
1626
1630
|
export {
|