@superblocksteam/library 2.0.54 → 2.0.56-next.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/{devtools-consolidated-BJ2tPWBk.js → devtools-consolidated-Dm9AFGZs.js} +2 -2
- package/dist/{devtools-consolidated-BJ2tPWBk.js.map → devtools-consolidated-Dm9AFGZs.js.map} +1 -1
- package/dist/{early-console-buffer-Bd5jqqBJ.js → early-console-buffer-SSPd-jq2.js} +1 -1
- package/dist/{early-console-buffer-Bd5jqqBJ.js.map → early-console-buffer-SSPd-jq2.js.map} +1 -1
- package/dist/jsx-dev-runtime/index.d.ts +14 -0
- package/dist/jsx-dev-runtime/index.d.ts.map +1 -0
- package/dist/jsx-dev-runtime/index.js +329 -0
- package/dist/jsx-dev-runtime/index.js.map +1 -0
- package/dist/jsx-runtime/index.d.ts +7 -0
- package/dist/jsx-runtime/index.d.ts.map +1 -0
- package/dist/jsx-runtime/index.js +10 -0
- package/dist/jsx-runtime/index.js.map +1 -0
- package/dist/{index.css → lib/index.css} +17 -11
- package/dist/lib/index.css.map +1 -0
- package/dist/lib/index.d.ts +786 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +4991 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/{logs-BA3qqo2m.js → logs-CgCPS9qr.js} +2 -2
- package/dist/{logs-BA3qqo2m.js.map → logs-CgCPS9qr.js.map} +1 -1
- package/dist/{utils-xmrGF_mk.js → utils-AzBGeVXo.js} +1 -1
- package/dist/{utils-xmrGF_mk.js.map → utils-AzBGeVXo.js.map} +1 -1
- package/dist/utils-DR35eYvX.js +3 -0
- package/dist/widget-wrapper-naming-ChBggw6W.js +3049 -0
- package/dist/widget-wrapper-naming-ChBggw6W.js.map +1 -0
- package/package.json +27 -14
- package/dist/build-manifest-BNJahcH4.js +0 -6
- package/dist/build-manifest-BNJahcH4.js.map +0 -1
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts +0 -1339
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -11471
- package/dist/index.js.map +0 -1
- package/dist/root-store-Cc3dO2jP.js +0 -4721
- package/dist/root-store-Cc3dO2jP.js.map +0 -1
- package/dist/root-store-xviorlO5.js +0 -4
- package/dist/utils-BVE4VhSk.js +0 -3
|
@@ -1,4721 +0,0 @@
|
|
|
1
|
-
import { t as getTracer } from "./utils-xmrGF_mk.js";
|
|
2
|
-
import { NotificationPosition, SbEntityType, TriggerStepType, isValidStepDef } from "@superblocksteam/library-shared/types";
|
|
3
|
-
import _, { cloneDeep, get, isEmpty, isNumber, isObject, isString, isUndefined, pick, set, throttle, toNumber, toString } from "lodash";
|
|
4
|
-
import * as React$1 from "react";
|
|
5
|
-
import React, { Suspense } from "react";
|
|
6
|
-
import styled from "styled-components";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import { Dim, SOURCE_ID_ATTRIBUTE, getBindingIdentifier, getComputedArgsString, getQueryParams, isBindingString, isComputedProperty, isDimension, nameGenerator, pathStringToArray, splitJSPath, stringifySplitPaths, toMobXPatch } from "@superblocksteam/library-shared";
|
|
9
|
-
import { action, computed, createAtom, entries, isComputedProp, isObservableArray, isObservableMap, isObservableObject, makeAutoObservable, makeObservable, observable, observe, reaction, toJS, values } from "mobx";
|
|
10
|
-
import { matchPath } from "react-router";
|
|
11
|
-
import { InputType, PropsPanelCategory } from "@superblocksteam/library-shared/props";
|
|
12
|
-
import JSON5 from "json5";
|
|
13
|
-
import moment from "moment";
|
|
14
|
-
import clone from "rfdc";
|
|
15
|
-
import { ApiResponseType, OrchestratorViewMode, SUPERBLOCKS_AUTHORIZATION_HEADER, SUPERBLOCKS_REQUEST_ID_HEADER, ViewMode, decodeBytestrings, getDynamicBindings } from "@superblocksteam/shared";
|
|
16
|
-
import isString$1 from "lodash/isString";
|
|
17
|
-
import { toast } from "sonner";
|
|
18
|
-
import { ROOT_CONTEXT, context, propagation, trace } from "@opentelemetry/api";
|
|
19
|
-
import diff from "microdiff";
|
|
20
|
-
|
|
21
|
-
//#region src/edit-mode/get-edit-store.ts
|
|
22
|
-
/**
|
|
23
|
-
* Get the global EditStore instance
|
|
24
|
-
* @returns The EditStore instance
|
|
25
|
-
*/
|
|
26
|
-
function getEditStore() {
|
|
27
|
-
if (!window.__SUPERBLOCKS_EDITOR_HOOK__ || !window.__SUPERBLOCKS_EDITOR_HOOK__.isInitialized) throw new Error("EditStore not initialized");
|
|
28
|
-
return window.__SUPERBLOCKS_EDITOR_HOOK__;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/lib/internal-details/is-edit-mode.ts
|
|
33
|
-
const getIsEditMode = () => {
|
|
34
|
-
return window._SB_VIEW_MODE === "dev";
|
|
35
|
-
};
|
|
36
|
-
let editMode;
|
|
37
|
-
const isEditMode = () => {
|
|
38
|
-
if (editMode === void 0) editMode = getIsEditMode();
|
|
39
|
-
return editMode;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/lib/utils/clean-object.ts
|
|
44
|
-
const isReactElement = (obj) => {
|
|
45
|
-
return obj && (obj.$$typeof === Symbol.for("react.element") || typeof Node !== "undefined" && obj instanceof Node);
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Cleans an object by removing proxy wrappers and filtering out functions.
|
|
49
|
-
* This is useful for preparing objects for JSON serialization.
|
|
50
|
-
*/
|
|
51
|
-
function cleanObject(obj) {
|
|
52
|
-
obj = toJS(obj);
|
|
53
|
-
if (!obj || typeof obj !== "object") return typeof obj === "function" ? void 0 : obj;
|
|
54
|
-
if (Array.isArray(obj)) return obj.map(cleanObject).filter((item) => item !== void 0);
|
|
55
|
-
if (isReactElement(obj)) return;
|
|
56
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
57
|
-
if (obj === value || key === "bind") return acc;
|
|
58
|
-
const cleaned = cleanObject(value);
|
|
59
|
-
if (cleaned !== void 0) acc[key] = cleaned;
|
|
60
|
-
return acc;
|
|
61
|
-
}, {});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/lib/internal-details/lib/iframe.ts
|
|
66
|
-
function isEmbeddedBySuperblocksFirstParty() {
|
|
67
|
-
return typeof window !== "undefined" && window !== window.parent;
|
|
68
|
-
}
|
|
69
|
-
const PARENT_REF = typeof window !== "undefined" && window !== window.parent ? window.parent : null;
|
|
70
|
-
const SELF_REF = typeof window !== "undefined" ? window : null;
|
|
71
|
-
function parentMessageHandler(e) {
|
|
72
|
-
if (e.source !== PARENT_REF && e.source !== SELF_REF) return;
|
|
73
|
-
const event = new SbIframeEventInternal(e.data.type, e.data);
|
|
74
|
-
iframeMessageHandler.dispatchEvent(event);
|
|
75
|
-
}
|
|
76
|
-
if (isEmbeddedBySuperblocksFirstParty() && PARENT_REF) typeof window !== "undefined" && window.addEventListener("message", parentMessageHandler);
|
|
77
|
-
/** @deprecated Use editorBridge instead */
|
|
78
|
-
function sendMessageImmediately(message, options) {
|
|
79
|
-
if (!PARENT_REF) {
|
|
80
|
-
console.warn("PARENT_REF is not set, message not delivered. Message: ", message);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
message = cleanObject(message);
|
|
84
|
-
if (isEmbeddedBySuperblocksFirstParty()) {
|
|
85
|
-
if (!PARENT_REF) throw new Error("Parent is not set");
|
|
86
|
-
try {
|
|
87
|
-
PARENT_REF.postMessage({
|
|
88
|
-
...message,
|
|
89
|
-
startTime: options?.overrideStartTime ?? +/* @__PURE__ */ new Date()
|
|
90
|
-
}, "*");
|
|
91
|
-
} catch (e) {
|
|
92
|
-
console.error("Error sending message to parent", message, e);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
var SbIframeEventInternal = class extends Event {
|
|
97
|
-
data;
|
|
98
|
-
constructor(type, data) {
|
|
99
|
-
super(type);
|
|
100
|
-
this.data = data;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var SbMessageHandler = class extends EventTarget {};
|
|
104
|
-
const iframeMessageHandler = new SbMessageHandler();
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/edit-mode/base-editor-bridge.ts
|
|
108
|
-
var DeployedParentBridge = class {
|
|
109
|
-
navigateTo(url, newWindow) {
|
|
110
|
-
sendMessageImmediately({
|
|
111
|
-
type: "navigate-to",
|
|
112
|
-
payload: {
|
|
113
|
-
url,
|
|
114
|
-
newWindow
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
connected() {}
|
|
119
|
-
sendReady() {}
|
|
120
|
-
sendNotification(_type, _message, _description) {}
|
|
121
|
-
selectWidgets(_sourceIds) {}
|
|
122
|
-
editOpRequest(_type, _payload) {}
|
|
123
|
-
undo() {}
|
|
124
|
-
redo() {}
|
|
125
|
-
sendStreamedApiEvent(_event, _apiName) {}
|
|
126
|
-
sendStreamedApiMessage(_message, _apiName) {}
|
|
127
|
-
setApiStarted(_apiName) {}
|
|
128
|
-
setApiResponse(_apiName, _response) {}
|
|
129
|
-
updatePropertiesPanels(_updates) {}
|
|
130
|
-
addPropertiesPanel(_id, _definition) {}
|
|
131
|
-
initializeEditorSyncedStore(_payload) {}
|
|
132
|
-
updateEditorSyncedStore(_payload) {}
|
|
133
|
-
resolvePromise(_callbackId, _payload) {}
|
|
134
|
-
rejectPromise(_callbackId, _payload) {}
|
|
135
|
-
canvasClicked() {}
|
|
136
|
-
registerContextMenuClick(_sourceId, _clientX, _clientY) {}
|
|
137
|
-
updateRoute(routeInfo) {
|
|
138
|
-
sendMessageImmediately({
|
|
139
|
-
type: "route-change",
|
|
140
|
-
payload: routeInfo
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
socketError(_message) {}
|
|
144
|
-
aiGenerate(_prompt) {}
|
|
145
|
-
addComponentToAiContext(_sourceId) {}
|
|
146
|
-
toggleComponentInAiContext(_sourceId, _instanceId, _label) {}
|
|
147
|
-
setAiContextMode(_mode) {}
|
|
148
|
-
sendAiLoaderState(_shouldShowLoader) {}
|
|
149
|
-
sendRuntimeError(_data) {}
|
|
150
|
-
sendClearRuntimeError(_id) {}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region src/edit-mode/message-queue.ts
|
|
155
|
-
const MESSAGE_BATCH_TIME = 50;
|
|
156
|
-
const DEFAULT_KEY = "default";
|
|
157
|
-
var MessageQueue = class {
|
|
158
|
-
keyedActionQueue = {};
|
|
159
|
-
constructor() {}
|
|
160
|
-
flattenKeyedQueue() {
|
|
161
|
-
return Object.values(this.keyedActionQueue).flat();
|
|
162
|
-
}
|
|
163
|
-
triggerSendFromQueue = throttle(() => {
|
|
164
|
-
sendMessageImmediately({
|
|
165
|
-
type: "iframe-action-batch",
|
|
166
|
-
payload: this.flattenKeyedQueue()
|
|
167
|
-
}, { overrideStartTime: Date.now() - MESSAGE_BATCH_TIME });
|
|
168
|
-
this.keyedActionQueue = {};
|
|
169
|
-
}, MESSAGE_BATCH_TIME);
|
|
170
|
-
queueMessage(message, mergeOptions) {
|
|
171
|
-
if (mergeOptions) {
|
|
172
|
-
const { key, mergeFn } = mergeOptions;
|
|
173
|
-
this.keyedActionQueue[key] ??= [];
|
|
174
|
-
this.keyedActionQueue[key] = mergeFn(this.keyedActionQueue[key], message);
|
|
175
|
-
} else {
|
|
176
|
-
this.keyedActionQueue[DEFAULT_KEY] ??= [];
|
|
177
|
-
this.keyedActionQueue[DEFAULT_KEY].push(message);
|
|
178
|
-
}
|
|
179
|
-
this.triggerSendFromQueue();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
var message_queue_default = new MessageQueue();
|
|
183
|
-
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/edit-mode/superblocks-editor-bridge.ts
|
|
186
|
-
var SuperblocksEditorBridge = class SuperblocksEditorBridge {
|
|
187
|
-
static instance;
|
|
188
|
-
messagesToSend = [];
|
|
189
|
-
connectedToParent = false;
|
|
190
|
-
static getInstance() {
|
|
191
|
-
const editMode$1 = isEditMode();
|
|
192
|
-
if (!SuperblocksEditorBridge.instance) SuperblocksEditorBridge.instance = editMode$1 ? new SuperblocksEditorBridge() : new DeployedParentBridge();
|
|
193
|
-
return SuperblocksEditorBridge.instance;
|
|
194
|
-
}
|
|
195
|
-
connected() {
|
|
196
|
-
this.connectedToParent = true;
|
|
197
|
-
this.messagesToSend.forEach((message) => this.queueMessage(message.payload, message.mergeOptions));
|
|
198
|
-
this.messagesToSend = [];
|
|
199
|
-
}
|
|
200
|
-
sendReady() {
|
|
201
|
-
this.sendImmediate({
|
|
202
|
-
type: "sb-ready",
|
|
203
|
-
payload: void 0
|
|
204
|
-
}, true);
|
|
205
|
-
}
|
|
206
|
-
sendNotification(type, message, description) {
|
|
207
|
-
this.queueMessage({
|
|
208
|
-
type: "codeMode/sendNotification",
|
|
209
|
-
payload: {
|
|
210
|
-
type,
|
|
211
|
-
message,
|
|
212
|
-
description
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
selectWidgets(sourceIds) {
|
|
217
|
-
this.queueMessage({
|
|
218
|
-
type: "client:selectWidgets",
|
|
219
|
-
payload: { sourceIds }
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
editOpRequest(type, payload) {
|
|
223
|
-
this.sendImmediate({
|
|
224
|
-
type: "sb-edit-operation-request",
|
|
225
|
-
payload: {
|
|
226
|
-
type,
|
|
227
|
-
payload
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
undo() {
|
|
232
|
-
this.sendImmediate({
|
|
233
|
-
type: "undo",
|
|
234
|
-
payload: void 0
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
redo() {
|
|
238
|
-
this.sendImmediate({
|
|
239
|
-
type: "redo",
|
|
240
|
-
payload: void 0
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
sendStreamedApiEvent(event, apiName) {
|
|
244
|
-
this.sendImmediate({
|
|
245
|
-
type: "api/stream-event",
|
|
246
|
-
payload: {
|
|
247
|
-
event,
|
|
248
|
-
apiName
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
sendStreamedApiMessage(message, apiName) {
|
|
253
|
-
this.sendImmediate({
|
|
254
|
-
type: "api/stream-message",
|
|
255
|
-
payload: {
|
|
256
|
-
message,
|
|
257
|
-
apiName
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
setApiStarted(apiName) {
|
|
262
|
-
this.sendImmediate({
|
|
263
|
-
type: "api/started-execution",
|
|
264
|
-
payload: { apiName }
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
setApiResponse(apiName, response) {
|
|
268
|
-
this.sendImmediate({
|
|
269
|
-
type: "api/set-api-response",
|
|
270
|
-
payload: {
|
|
271
|
-
apiName,
|
|
272
|
-
response
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
navigateTo(path, newWindow) {
|
|
277
|
-
this.sendImmediate({
|
|
278
|
-
type: "navigate-to",
|
|
279
|
-
payload: {
|
|
280
|
-
url: path,
|
|
281
|
-
newWindow
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
updatePropertiesPanels(updates) {
|
|
286
|
-
this.queueMessage({
|
|
287
|
-
type: "codeMode/updatePropertiesPanels",
|
|
288
|
-
payload: updates
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
addPropertiesPanel(id, definition) {
|
|
292
|
-
this.queueMessage({
|
|
293
|
-
type: "codeMode/addPropertiesPanel",
|
|
294
|
-
payload: {
|
|
295
|
-
id,
|
|
296
|
-
definition
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
initializeEditorSyncedStore(payload) {
|
|
301
|
-
this.queueMessage({
|
|
302
|
-
type: "codeMode/editor-synced-store/init",
|
|
303
|
-
payload
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
mergeSyncedStoreUpdate(existingActions, newAction) {
|
|
307
|
-
if (!existingActions || existingActions.length === 0) return [newAction];
|
|
308
|
-
const firstAction = existingActions[0];
|
|
309
|
-
const newActionPatches = newAction.payload.patch;
|
|
310
|
-
firstAction.payload.patch = Array.isArray(firstAction.payload.patch) ? firstAction.payload.patch : [firstAction.payload.patch];
|
|
311
|
-
firstAction.payload.patch.push(...Array.isArray(newActionPatches) ? newActionPatches : [newActionPatches]);
|
|
312
|
-
return existingActions;
|
|
313
|
-
}
|
|
314
|
-
updateEditorSyncedStore(payload) {
|
|
315
|
-
this.queueMessage({
|
|
316
|
-
type: "codeMode/editor-synced-store/update",
|
|
317
|
-
payload
|
|
318
|
-
}, {
|
|
319
|
-
key: `synced-store-update-${payload.storeId}`,
|
|
320
|
-
mergeFn: this.mergeSyncedStoreUpdate
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
resolvePromise(callbackId, payload) {
|
|
324
|
-
this.sendImmediate({
|
|
325
|
-
type: "resolve-promise",
|
|
326
|
-
callbackId,
|
|
327
|
-
payload
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
rejectPromise(callbackId, payload) {
|
|
331
|
-
this.sendImmediate({
|
|
332
|
-
type: "reject-promise",
|
|
333
|
-
callbackId,
|
|
334
|
-
payload
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
canvasClicked() {
|
|
338
|
-
this.sendImmediate({
|
|
339
|
-
type: "register-click",
|
|
340
|
-
payload: {
|
|
341
|
-
type: "INSIDE_IFRAME_CLICKED",
|
|
342
|
-
context: {
|
|
343
|
-
sourceId: "",
|
|
344
|
-
clientX: 0,
|
|
345
|
-
clientY: 0
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
registerContextMenuClick(sourceId, clientX, clientY) {
|
|
351
|
-
this.sendImmediate({
|
|
352
|
-
type: "register-click",
|
|
353
|
-
payload: {
|
|
354
|
-
type: "OPEN_CONTEXT_MENU",
|
|
355
|
-
context: {
|
|
356
|
-
sourceId,
|
|
357
|
-
clientX,
|
|
358
|
-
clientY
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
updateRoute(routeInfo) {
|
|
364
|
-
this.sendImmediate({
|
|
365
|
-
type: "route-change",
|
|
366
|
-
payload: routeInfo
|
|
367
|
-
}, true);
|
|
368
|
-
}
|
|
369
|
-
addComponentToAiContext(sourceId, instanceId) {
|
|
370
|
-
const editStore = getEditStore();
|
|
371
|
-
if (editStore?.ai.isAlternateSourceIdTarget(sourceId, instanceId)) {
|
|
372
|
-
editStore.ai.addTargetedInstance(instanceId);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
this.sendImmediate({
|
|
376
|
-
type: "ai-updates",
|
|
377
|
-
payload: {
|
|
378
|
-
type: "add-component-to-context",
|
|
379
|
-
component: sourceId
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
toggleComponentInAiContext(sourceId, instanceId, label) {
|
|
384
|
-
const editStore = getEditStore();
|
|
385
|
-
if (editStore?.ai.isAlternateSourceIdTarget(sourceId, instanceId)) {
|
|
386
|
-
editStore.ai.toggleTargetedInstance(instanceId);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
this.sendImmediate({
|
|
390
|
-
type: "ai-updates",
|
|
391
|
-
payload: {
|
|
392
|
-
type: "toggle-component-in-context",
|
|
393
|
-
component: sourceId,
|
|
394
|
-
label
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
setAiContextMode(mode) {
|
|
399
|
-
this.sendImmediate({
|
|
400
|
-
type: "ai-updates",
|
|
401
|
-
payload: {
|
|
402
|
-
type: "set-ai-context-mode",
|
|
403
|
-
mode
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
aiGenerate(prompt, forceSend = false) {
|
|
408
|
-
const sanitizedPrompt = clampPromptLength(prompt);
|
|
409
|
-
this.sendImmediate({
|
|
410
|
-
type: "ai-updates",
|
|
411
|
-
payload: {
|
|
412
|
-
type: "ai-generate",
|
|
413
|
-
prompt: sanitizedPrompt
|
|
414
|
-
}
|
|
415
|
-
}, forceSend);
|
|
416
|
-
}
|
|
417
|
-
sendAiLoaderState(shouldShowLoader) {
|
|
418
|
-
this.sendImmediate({
|
|
419
|
-
type: "ai-updates",
|
|
420
|
-
payload: {
|
|
421
|
-
type: "loader-state",
|
|
422
|
-
shouldShowLoader
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
socketError(message) {
|
|
427
|
-
this.sendImmediate({
|
|
428
|
-
type: "socket/error",
|
|
429
|
-
payload: { message }
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
sendRuntimeError(data) {
|
|
433
|
-
this.sendImmediate({
|
|
434
|
-
type: "runtime-error",
|
|
435
|
-
payload: data
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
sendClearRuntimeError(id) {
|
|
439
|
-
this.sendImmediate({
|
|
440
|
-
type: "clear-runtime-error",
|
|
441
|
-
payload: { id }
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
queueMessage(message, mergeOptions) {
|
|
445
|
-
if (!this.connectedToParent) this.messagesToSend.push({
|
|
446
|
-
payload: message,
|
|
447
|
-
mergeOptions
|
|
448
|
-
});
|
|
449
|
-
else message_queue_default.queueMessage(message, mergeOptions);
|
|
450
|
-
}
|
|
451
|
-
sendImmediate(message, forceSend = false) {
|
|
452
|
-
if (!this.connectedToParent && !forceSend) this.messagesToSend.push({ payload: message });
|
|
453
|
-
else sendMessageImmediately(message);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
const MAX_AI_PROMPT_LENGTH = 16e3;
|
|
457
|
-
const TRUNCATION_SUFFIX = "... (truncated)";
|
|
458
|
-
function clampPromptLength(prompt) {
|
|
459
|
-
if (prompt.length <= MAX_AI_PROMPT_LENGTH) return prompt;
|
|
460
|
-
const available = Math.max(MAX_AI_PROMPT_LENGTH - 15, 0);
|
|
461
|
-
return `${prompt.slice(0, available)}${TRUNCATION_SUFFIX}`;
|
|
462
|
-
}
|
|
463
|
-
const editorBridge = SuperblocksEditorBridge.getInstance();
|
|
464
|
-
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/lib/triggers/implementations/apis/cancel-apis.ts
|
|
467
|
-
const CancelApisTrigger = {
|
|
468
|
-
type: TriggerStepType.CANCEL_APIS,
|
|
469
|
-
async execute(_context, step) {
|
|
470
|
-
const apis = step.apis;
|
|
471
|
-
await Promise.all(apis.map((api) => api.cancel()));
|
|
472
|
-
},
|
|
473
|
-
create(apis, onCancel) {
|
|
474
|
-
return {
|
|
475
|
-
type: TriggerStepType.CANCEL_APIS,
|
|
476
|
-
apis,
|
|
477
|
-
onCancel
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
//#endregion
|
|
483
|
-
//#region src/lib/triggers/implementations/apis/run-apis.ts
|
|
484
|
-
const RunApisTrigger = {
|
|
485
|
-
type: TriggerStepType.RUN_APIS,
|
|
486
|
-
async execute(context$1, step, onFinish) {
|
|
487
|
-
const traceHeaders = context$1.additionalContext?.traceHeaders;
|
|
488
|
-
const executions = step.apis.map((api) => api.run({ traceHeaders }));
|
|
489
|
-
return Promise.allSettled(executions).then((responses) => {
|
|
490
|
-
if (!responses.find((response) => response.status === "rejected" || response.value?.errors && response.value?.errors?.length > 0) && step.onSuccess) runEventHandlers({
|
|
491
|
-
flow: step.onSuccess,
|
|
492
|
-
name: context$1.name,
|
|
493
|
-
scopeId: context$1.scopeId,
|
|
494
|
-
additionalContext: context$1.additionalContext
|
|
495
|
-
});
|
|
496
|
-
else if (step.onError) runEventHandlers({
|
|
497
|
-
flow: step.onError,
|
|
498
|
-
name: context$1.name,
|
|
499
|
-
scopeId: context$1.scopeId,
|
|
500
|
-
additionalContext: context$1.additionalContext
|
|
501
|
-
});
|
|
502
|
-
onFinish?.(responses);
|
|
503
|
-
});
|
|
504
|
-
},
|
|
505
|
-
create(apis, opts) {
|
|
506
|
-
return {
|
|
507
|
-
type: TriggerStepType.RUN_APIS,
|
|
508
|
-
apis,
|
|
509
|
-
onSuccess: opts?.onSuccess,
|
|
510
|
-
onError: opts?.onError
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
//#endregion
|
|
516
|
-
//#region src/lib/triggers/implementations/call-function.ts
|
|
517
|
-
const CallFunctionTrigger = {
|
|
518
|
-
type: TriggerStepType.CALL_FUNCTION,
|
|
519
|
-
create(fn) {
|
|
520
|
-
if (typeof fn !== "function") throw new Error("callFunction expects a function");
|
|
521
|
-
return {
|
|
522
|
-
type: TriggerStepType.CALL_FUNCTION,
|
|
523
|
-
exec: fn
|
|
524
|
-
};
|
|
525
|
-
},
|
|
526
|
-
async execute(_ctx, step) {
|
|
527
|
-
await Promise.resolve(step.exec());
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region src/lib/triggers/implementations/components/control-modal.ts
|
|
533
|
-
const ControlModalTrigger = {
|
|
534
|
-
type: TriggerStepType.CONTROL_MODAL,
|
|
535
|
-
async execute(context$1, step) {
|
|
536
|
-
if (step.name === void 0) return;
|
|
537
|
-
context$1.rootStore.entityManager.runCode({
|
|
538
|
-
scopeId: context$1.scopeId,
|
|
539
|
-
name: context$1.name,
|
|
540
|
-
func: (state, step$1) => {
|
|
541
|
-
if (!state || !step$1.name) return;
|
|
542
|
-
if (step$1.action === "open") state[step$1.name].isOpen = true;
|
|
543
|
-
else state[step$1.name].isOpen = false;
|
|
544
|
-
},
|
|
545
|
-
args: [step]
|
|
546
|
-
});
|
|
547
|
-
},
|
|
548
|
-
create(modal, opts) {
|
|
549
|
-
const meta = getBindingIdentifier(modal);
|
|
550
|
-
return {
|
|
551
|
-
type: TriggerStepType.CONTROL_MODAL,
|
|
552
|
-
name: meta?.entityName,
|
|
553
|
-
action: opts.action
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
//#endregion
|
|
559
|
-
//#region src/lib/triggers/implementations/components/control-slideout.ts
|
|
560
|
-
const ControlSlideoutTrigger = {
|
|
561
|
-
type: TriggerStepType.CONTROL_SLIDEOUT,
|
|
562
|
-
async execute(context$1, step) {
|
|
563
|
-
context$1.rootStore.entityManager.runCode({
|
|
564
|
-
scopeId: context$1.scopeId,
|
|
565
|
-
name: context$1.name,
|
|
566
|
-
func: (state, step$1) => {
|
|
567
|
-
if (!state || !step$1.name) return;
|
|
568
|
-
state[step$1.name].isOpen = step$1.action === "open";
|
|
569
|
-
},
|
|
570
|
-
args: [step]
|
|
571
|
-
});
|
|
572
|
-
},
|
|
573
|
-
create(slideout, opts) {
|
|
574
|
-
const meta = getBindingIdentifier(slideout);
|
|
575
|
-
return {
|
|
576
|
-
type: TriggerStepType.CONTROL_SLIDEOUT,
|
|
577
|
-
name: meta?.entityName,
|
|
578
|
-
action: opts.action
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
//#endregion
|
|
584
|
-
//#region src/lib/internal-details/lib/evaluator/names.ts
|
|
585
|
-
const getName = (name) => {
|
|
586
|
-
return {
|
|
587
|
-
isAnonymous: !name,
|
|
588
|
-
value: name ?? Math.random().toString(36).substring(7),
|
|
589
|
-
__isName: true
|
|
590
|
-
};
|
|
591
|
-
};
|
|
592
|
-
const isName = (name) => {
|
|
593
|
-
return typeof name === "object" && name != null && "__isName" in name;
|
|
594
|
-
};
|
|
595
|
-
const isNameEqual = (a, b) => {
|
|
596
|
-
return a.value === b.value && a.isAnonymous === b.isAnonymous;
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
//#endregion
|
|
600
|
-
//#region src/lib/triggers/implementations/components/reset-component.ts
|
|
601
|
-
const ResetComponentTrigger = {
|
|
602
|
-
type: TriggerStepType.RESET_COMPONENT,
|
|
603
|
-
async execute(context$1, step) {
|
|
604
|
-
if (!step.widget?.name) return;
|
|
605
|
-
context$1.rootStore.entityManager.resetEntity({
|
|
606
|
-
name: getName(step.widget?.name),
|
|
607
|
-
scopeId: context$1.scopeId,
|
|
608
|
-
key: step.propertyName,
|
|
609
|
-
onlyMetaProps: true
|
|
610
|
-
});
|
|
611
|
-
},
|
|
612
|
-
create(component, opts) {
|
|
613
|
-
const meta = getBindingIdentifier(component);
|
|
614
|
-
return {
|
|
615
|
-
type: TriggerStepType.RESET_COMPONENT,
|
|
616
|
-
widget: meta ? { name: meta.entityName } : void 0,
|
|
617
|
-
propertyName: opts?.property
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
|
|
622
|
-
//#endregion
|
|
623
|
-
//#region src/lib/triggers/implementations/components/set-component-property.ts
|
|
624
|
-
const SetComponentPropertyTrigger = {
|
|
625
|
-
type: TriggerStepType.SET_COMPONENT_PROPERTY,
|
|
626
|
-
async execute(context$1, step) {
|
|
627
|
-
const { propertyValue } = step;
|
|
628
|
-
const value = context$1.rootStore.entityManager.computeValue({
|
|
629
|
-
scopeId: context$1.scopeId,
|
|
630
|
-
name: context$1.name,
|
|
631
|
-
value: propertyValue,
|
|
632
|
-
args: [context$1.additionalContext]
|
|
633
|
-
});
|
|
634
|
-
context$1.rootStore.entityManager.runCode({
|
|
635
|
-
scopeId: context$1.scopeId,
|
|
636
|
-
name: context$1.name,
|
|
637
|
-
func: (state, value$1, step$1) => {
|
|
638
|
-
if (!state) return;
|
|
639
|
-
state[step$1.widget?.name][step$1.propertyName] = value$1;
|
|
640
|
-
},
|
|
641
|
-
args: [value, step]
|
|
642
|
-
});
|
|
643
|
-
},
|
|
644
|
-
create(component, opts) {
|
|
645
|
-
const meta = getBindingIdentifier(component);
|
|
646
|
-
return {
|
|
647
|
-
type: TriggerStepType.SET_COMPONENT_PROPERTY,
|
|
648
|
-
widget: meta ? { name: meta.entityName } : void 0,
|
|
649
|
-
propertyName: opts.property,
|
|
650
|
-
propertyValue: opts.value
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
//#endregion
|
|
656
|
-
//#region src/lib/triggers/implementations/navigate/navigate-to-app.ts
|
|
657
|
-
const NavigateToAppTrigger = {
|
|
658
|
-
type: TriggerStepType.NAVIGATE_TO_APP,
|
|
659
|
-
async execute(_context, step) {
|
|
660
|
-
console.log("Navigate to app", step);
|
|
661
|
-
},
|
|
662
|
-
create(appId) {
|
|
663
|
-
return {
|
|
664
|
-
type: TriggerStepType.NAVIGATE_TO_APP,
|
|
665
|
-
targetApp: {
|
|
666
|
-
name: appId,
|
|
667
|
-
id: appId,
|
|
668
|
-
url: ""
|
|
669
|
-
},
|
|
670
|
-
queryParams: {},
|
|
671
|
-
newWindowApp: false
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
//#endregion
|
|
677
|
-
//#region src/lib/triggers/implementations/navigate/navigate-to-route.ts
|
|
678
|
-
const NavigateToRouteTrigger = {
|
|
679
|
-
type: TriggerStepType.NAVIGATE_TO_ROUTE,
|
|
680
|
-
async execute(context$1, step) {
|
|
681
|
-
const queryParams = step.queryParams ? context$1.rootStore.entityManager.computeValue({
|
|
682
|
-
scopeId: context$1.scopeId,
|
|
683
|
-
name: context$1.name,
|
|
684
|
-
value: step.queryParams,
|
|
685
|
-
args: [context$1.additionalContext]
|
|
686
|
-
}) : {};
|
|
687
|
-
const routeParams = step.routeParams ? context$1.rootStore.entityManager.computeValue({
|
|
688
|
-
scopeId: context$1.scopeId,
|
|
689
|
-
name: context$1.name,
|
|
690
|
-
value: step.routeParams,
|
|
691
|
-
args: [context$1.additionalContext]
|
|
692
|
-
}) : {};
|
|
693
|
-
console.log("Navigate to route", {
|
|
694
|
-
routeId: step.routeId,
|
|
695
|
-
routeParams,
|
|
696
|
-
queryParams,
|
|
697
|
-
keepQueryParams: step.keepQueryParams,
|
|
698
|
-
newWindow: step.newWindow
|
|
699
|
-
});
|
|
700
|
-
},
|
|
701
|
-
create(route) {
|
|
702
|
-
return {
|
|
703
|
-
type: TriggerStepType.NAVIGATE_TO_ROUTE,
|
|
704
|
-
routeId: route,
|
|
705
|
-
routePathDescriptor: route,
|
|
706
|
-
newWindow: false
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
//#endregion
|
|
712
|
-
//#region src/lib/internal-details/utils/is-local-link.ts
|
|
713
|
-
function isLocalLink(href) {
|
|
714
|
-
return new URL(href, window.location.origin).origin === window.location.origin;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
//#endregion
|
|
718
|
-
//#region src/lib/internal-details/utils/navigation.ts
|
|
719
|
-
var NavigationEvent = class extends Event {
|
|
720
|
-
destination;
|
|
721
|
-
formData;
|
|
722
|
-
downloadRequest;
|
|
723
|
-
newWindow;
|
|
724
|
-
navigationType;
|
|
725
|
-
userInitiated;
|
|
726
|
-
constructor({ isSameDocument, targetUrl, formData, isBlob = false, newWindow = false, userInitiated = false }) {
|
|
727
|
-
super("navigate", { cancelable: true });
|
|
728
|
-
this.destination = {
|
|
729
|
-
sameDocument: isSameDocument,
|
|
730
|
-
url: targetUrl
|
|
731
|
-
};
|
|
732
|
-
if (formData) this.formData = formData;
|
|
733
|
-
this.downloadRequest = isBlob;
|
|
734
|
-
this.newWindow = newWindow;
|
|
735
|
-
this.navigationType = "push";
|
|
736
|
-
this.userInitiated = userInitiated;
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
var NavigationPolyfill = class extends EventTarget {
|
|
740
|
-
constructor() {
|
|
741
|
-
super();
|
|
742
|
-
interceptWindowClicks(this);
|
|
743
|
-
patchGlobalScope(this);
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
const navigation = window.navigation ?? new NavigationPolyfill();
|
|
747
|
-
function patchGlobalScope(navigation$1) {
|
|
748
|
-
try {
|
|
749
|
-
Object.defineProperty(window, "navigation", { value: navigation$1 });
|
|
750
|
-
} catch {}
|
|
751
|
-
}
|
|
752
|
-
function interceptWindowClicks(navigation$1) {
|
|
753
|
-
function clickCallback(ev, aEl) {
|
|
754
|
-
if (!(ev.button === 0 && !ev.defaultPrevented && !ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey)) return;
|
|
755
|
-
const targetUrl = new URL(aEl.href, window.location.origin);
|
|
756
|
-
const navigationEvent = new NavigationEvent({
|
|
757
|
-
isSameDocument: targetUrl.origin === window.location.origin && targetUrl.pathname === window.location.pathname,
|
|
758
|
-
targetUrl: aEl.href,
|
|
759
|
-
isBlob: targetUrl.protocol === "blob:",
|
|
760
|
-
newWindow: aEl.target === "_blank",
|
|
761
|
-
userInitiated: true
|
|
762
|
-
});
|
|
763
|
-
if (!navigation$1.dispatchEvent(navigationEvent)) ev.preventDefault();
|
|
764
|
-
}
|
|
765
|
-
function submitCallback(ev, form) {
|
|
766
|
-
if (ev.defaultPrevented) return;
|
|
767
|
-
if ((ev.submitter && "formMethod" in ev.submitter && ev.submitter.formMethod ? ev.submitter.formMethod : form.method) === "dialog") return;
|
|
768
|
-
const navigationEvent = new NavigationEvent({
|
|
769
|
-
isSameDocument: false,
|
|
770
|
-
targetUrl: ev.submitter && "formAction" in ev.submitter && ev.submitter.formAction ? ev.submitter.formAction : form.action,
|
|
771
|
-
formData: new FormData(form)
|
|
772
|
-
});
|
|
773
|
-
navigation$1.dispatchEvent(navigationEvent);
|
|
774
|
-
if (navigationEvent.defaultPrevented) ev.preventDefault();
|
|
775
|
-
}
|
|
776
|
-
window.addEventListener("click", (ev) => {
|
|
777
|
-
const aEl = ev.target.closest?.("a[href]");
|
|
778
|
-
if (aEl instanceof HTMLAnchorElement) clickCallback(ev, aEl);
|
|
779
|
-
}, true);
|
|
780
|
-
window.addEventListener("submit", (ev) => {
|
|
781
|
-
const form = ev.target.closest?.("form");
|
|
782
|
-
if (form instanceof HTMLFormElement) submitCallback(ev, form);
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
//#endregion
|
|
787
|
-
//#region src/lib/triggers/implementations/navigate/utils.ts
|
|
788
|
-
const isValidUrlScheme = (url) => {
|
|
789
|
-
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
|
|
790
|
-
};
|
|
791
|
-
const isValidUrl = (url) => {
|
|
792
|
-
try {
|
|
793
|
-
new URL(url);
|
|
794
|
-
return true;
|
|
795
|
-
} catch {
|
|
796
|
-
return false;
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
//#endregion
|
|
801
|
-
//#region src/lib/triggers/implementations/navigate/navigate-to.ts
|
|
802
|
-
const NavigateToTrigger = {
|
|
803
|
-
type: TriggerStepType.NAVIGATE_TO,
|
|
804
|
-
async execute(context$1, step) {
|
|
805
|
-
let url = context$1.rootStore.entityManager.computeValue({
|
|
806
|
-
scopeId: context$1.scopeId,
|
|
807
|
-
name: context$1.name,
|
|
808
|
-
value: step.url,
|
|
809
|
-
args: [context$1.additionalContext]
|
|
810
|
-
});
|
|
811
|
-
const urlWithScheme = isValidUrlScheme(url) ? url : "https://" + url;
|
|
812
|
-
if (isValidUrl(urlWithScheme) && !url.startsWith("/")) url = urlWithScheme;
|
|
813
|
-
if (isLocalLink(url)) {
|
|
814
|
-
navigation.dispatchEvent(new NavigationEvent({
|
|
815
|
-
isSameDocument: true,
|
|
816
|
-
targetUrl: url,
|
|
817
|
-
userInitiated: true
|
|
818
|
-
}));
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
if (step.newWindow) navigation.dispatchEvent(new NavigationEvent({
|
|
822
|
-
isSameDocument: false,
|
|
823
|
-
targetUrl: url,
|
|
824
|
-
newWindow: true,
|
|
825
|
-
userInitiated: true
|
|
826
|
-
}));
|
|
827
|
-
else if (window.top) window.top.location.href = url;
|
|
828
|
-
else window.location.href = url;
|
|
829
|
-
},
|
|
830
|
-
create(url, opts) {
|
|
831
|
-
return {
|
|
832
|
-
type: TriggerStepType.NAVIGATE_TO,
|
|
833
|
-
url,
|
|
834
|
-
newWindow: opts?.newWindow ?? false,
|
|
835
|
-
replaceHistory: opts?.replaceHistory,
|
|
836
|
-
arguments: opts?.arguments
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
|
|
841
|
-
//#endregion
|
|
842
|
-
//#region src/lib/triggers/implementations/navigate/set-query-params.ts
|
|
843
|
-
const SetQueryParamsTrigger = {
|
|
844
|
-
type: TriggerStepType.SET_QUERY_PARAMS,
|
|
845
|
-
async execute(_context, step) {
|
|
846
|
-
console.log("SetQueryParamsTrigger", step);
|
|
847
|
-
},
|
|
848
|
-
create(queryParams, opts) {
|
|
849
|
-
return {
|
|
850
|
-
type: TriggerStepType.SET_QUERY_PARAMS,
|
|
851
|
-
queryParams,
|
|
852
|
-
keepQueryParams: opts?.keep ?? false
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
//#endregion
|
|
858
|
-
//#region src/lib/triggers/implementations/run-js.ts
|
|
859
|
-
const RunJsTrigger = {
|
|
860
|
-
type: TriggerStepType.RUN_JS,
|
|
861
|
-
create(handler) {
|
|
862
|
-
return {
|
|
863
|
-
type: TriggerStepType.RUN_JS,
|
|
864
|
-
handler,
|
|
865
|
-
code: handler ? handler.toString() : ""
|
|
866
|
-
};
|
|
867
|
-
},
|
|
868
|
-
async execute(context$1, step) {
|
|
869
|
-
if (step.handler) context$1.rootStore.entityManager.runCode({
|
|
870
|
-
scopeId: context$1.scopeId,
|
|
871
|
-
name: context$1.name,
|
|
872
|
-
func: step.handler,
|
|
873
|
-
args: [context$1.additionalContext],
|
|
874
|
-
excludeState: true
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
|
|
879
|
-
//#endregion
|
|
880
|
-
//#region src/lib/triggers/implementations/set-profile.ts
|
|
881
|
-
const SetProfileTrigger = {
|
|
882
|
-
type: TriggerStepType.SET_PROFILE,
|
|
883
|
-
async execute(_context, step) {
|
|
884
|
-
console.log("SetProfileTrigger", step);
|
|
885
|
-
},
|
|
886
|
-
create(profileId, opts) {
|
|
887
|
-
return {
|
|
888
|
-
type: TriggerStepType.SET_PROFILE,
|
|
889
|
-
profileId,
|
|
890
|
-
action: opts.action ?? "set"
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
//#endregion
|
|
896
|
-
//#region src/lib/triggers/implementations/state/reset-state-var.ts
|
|
897
|
-
const ResetStateVarTrigger = {
|
|
898
|
-
type: TriggerStepType.RESET_STATE_VAR,
|
|
899
|
-
async execute(context$1, step) {
|
|
900
|
-
if (step.variable === void 0) return;
|
|
901
|
-
context$1.rootStore.entityManager.runCode({
|
|
902
|
-
scopeId: context$1.scopeId,
|
|
903
|
-
name: context$1.name,
|
|
904
|
-
func: () => step.variable?.set(step.variable.defaultValue),
|
|
905
|
-
args: []
|
|
906
|
-
});
|
|
907
|
-
},
|
|
908
|
-
create(variable) {
|
|
909
|
-
return {
|
|
910
|
-
type: TriggerStepType.RESET_STATE_VAR,
|
|
911
|
-
variable
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
//#endregion
|
|
917
|
-
//#region src/lib/triggers/implementations/state/set-state-var.ts
|
|
918
|
-
const SetStateVarTrigger = {
|
|
919
|
-
type: TriggerStepType.SET_STATE_VAR,
|
|
920
|
-
async execute(context$1, step) {
|
|
921
|
-
if (step.variable === void 0) return;
|
|
922
|
-
const value = context$1.rootStore.entityManager.computeValue({
|
|
923
|
-
scopeId: context$1.scopeId,
|
|
924
|
-
name: context$1.name,
|
|
925
|
-
value: step.value,
|
|
926
|
-
args: [context$1.additionalContext]
|
|
927
|
-
});
|
|
928
|
-
context$1.rootStore.entityManager.runCode({
|
|
929
|
-
scopeId: context$1.scopeId,
|
|
930
|
-
name: context$1.name,
|
|
931
|
-
func: (state, value$1) => {
|
|
932
|
-
if (!state) return;
|
|
933
|
-
step.variable?.set(value$1);
|
|
934
|
-
},
|
|
935
|
-
args: [value]
|
|
936
|
-
});
|
|
937
|
-
},
|
|
938
|
-
create(variable, opts) {
|
|
939
|
-
return {
|
|
940
|
-
type: TriggerStepType.SET_STATE_VAR,
|
|
941
|
-
variable,
|
|
942
|
-
value: opts.value
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
|
|
947
|
-
//#endregion
|
|
948
|
-
//#region src/lib/triggers/implementations/timers/control-timer.ts
|
|
949
|
-
const ControlTimerTrigger = {
|
|
950
|
-
type: TriggerStepType.CONTROL_TIMER,
|
|
951
|
-
async execute(_context, step) {
|
|
952
|
-
if (step.timer) step.timer[step.action]();
|
|
953
|
-
},
|
|
954
|
-
create(timer, opts) {
|
|
955
|
-
return {
|
|
956
|
-
type: TriggerStepType.CONTROL_TIMER,
|
|
957
|
-
timer,
|
|
958
|
-
action: opts.action
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
//#endregion
|
|
964
|
-
//#region src/lib/triggers/implementations/trigger-event.ts
|
|
965
|
-
const TriggerEventTrigger = {
|
|
966
|
-
type: TriggerStepType.TRIGGER_EVENT,
|
|
967
|
-
async execute(_context, step) {
|
|
968
|
-
console.log("TriggerEventTrigger", step);
|
|
969
|
-
},
|
|
970
|
-
create(eventName, opts) {
|
|
971
|
-
return {
|
|
972
|
-
type: TriggerStepType.TRIGGER_EVENT,
|
|
973
|
-
event: { name: eventName },
|
|
974
|
-
eventPayload: opts?.data
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
|
|
979
|
-
//#endregion
|
|
980
|
-
//#region src/lib/triggers/registry.ts
|
|
981
|
-
const EventRegistry = {
|
|
982
|
-
[TriggerStepType.RUN_JS]: RunJsTrigger,
|
|
983
|
-
[TriggerStepType.NAVIGATE_TO]: NavigateToTrigger,
|
|
984
|
-
[TriggerStepType.NAVIGATE_TO_APP]: NavigateToAppTrigger,
|
|
985
|
-
[TriggerStepType.NAVIGATE_TO_ROUTE]: NavigateToRouteTrigger,
|
|
986
|
-
[TriggerStepType.SET_QUERY_PARAMS]: SetQueryParamsTrigger,
|
|
987
|
-
[TriggerStepType.CONTROL_SLIDEOUT]: ControlSlideoutTrigger,
|
|
988
|
-
[TriggerStepType.CONTROL_MODAL]: ControlModalTrigger,
|
|
989
|
-
[TriggerStepType.RESET_COMPONENT]: ResetComponentTrigger,
|
|
990
|
-
[TriggerStepType.CALL_FUNCTION]: CallFunctionTrigger,
|
|
991
|
-
[TriggerStepType.RUN_APIS]: RunApisTrigger,
|
|
992
|
-
[TriggerStepType.CANCEL_APIS]: CancelApisTrigger,
|
|
993
|
-
[TriggerStepType.SET_STATE_VAR]: SetStateVarTrigger,
|
|
994
|
-
[TriggerStepType.SET_COMPONENT_PROPERTY]: SetComponentPropertyTrigger,
|
|
995
|
-
[TriggerStepType.RESET_STATE_VAR]: ResetStateVarTrigger,
|
|
996
|
-
[TriggerStepType.CONTROL_TIMER]: ControlTimerTrigger,
|
|
997
|
-
[TriggerStepType.SET_PROFILE]: SetProfileTrigger,
|
|
998
|
-
[TriggerStepType.TRIGGER_EVENT]: TriggerEventTrigger
|
|
999
|
-
};
|
|
1000
|
-
var registry_default = EventRegistry;
|
|
1001
|
-
|
|
1002
|
-
//#endregion
|
|
1003
|
-
//#region src/lib/triggers/run-event-handlers.ts
|
|
1004
|
-
const getRootStore = () => import("./root-store-xviorlO5.js").then((module) => module.default);
|
|
1005
|
-
const runEventHandlers = async ({ flow, name, scopeId, additionalContext }) => {
|
|
1006
|
-
const context$1 = {
|
|
1007
|
-
scopeId,
|
|
1008
|
-
name,
|
|
1009
|
-
rootStore: await getRootStore(),
|
|
1010
|
-
additionalContext
|
|
1011
|
-
};
|
|
1012
|
-
const steps = flow?.build() ?? [];
|
|
1013
|
-
for (const step of steps) {
|
|
1014
|
-
if (!isValidStepDef(step)) continue;
|
|
1015
|
-
const trigger = registry_default[step.type];
|
|
1016
|
-
if (trigger) await trigger.execute(context$1, step);
|
|
1017
|
-
else console.error(`Trigger ${step.type} not found`);
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
var run_event_handlers_default = runEventHandlers;
|
|
1021
|
-
|
|
1022
|
-
//#endregion
|
|
1023
|
-
//#region src/lib/user-facing/properties-panel/properties-panel-definition.ts
|
|
1024
|
-
function createPropertiesPanelDefinition(sections, entity, scopedState) {
|
|
1025
|
-
const sectionDefs = [];
|
|
1026
|
-
const getSectionChildren = (props, parentPath) => {
|
|
1027
|
-
const properties = [];
|
|
1028
|
-
/**
|
|
1029
|
-
* There are three ways we can display a Composite prop:
|
|
1030
|
-
* 1. Prop control + popover panel (e.g: TextStyle)
|
|
1031
|
-
* 2. Prop control (e.g: Border)
|
|
1032
|
-
* 3. Inline, without a prop control (e.g: Search prop on Table, which contains backgroundColor, borderRadius, etc.)
|
|
1033
|
-
*
|
|
1034
|
-
* isCompositeWithInlineNestedProps is used to determine if a prop is of type (3).
|
|
1035
|
-
*/
|
|
1036
|
-
const isCompositeWithInlineNestedProps = (prop, fullPath) => {
|
|
1037
|
-
if (!(prop instanceof CompositeProp) || !prop.hasPropertiesPanelDisplay()) return false;
|
|
1038
|
-
const displayMode = prop.propertiesPanelChildrenDisplayMode();
|
|
1039
|
-
if (!displayMode) return false;
|
|
1040
|
-
return (typeof displayMode === "function" ? displayMode(entity, fullPath) : displayMode)?.type === "inline";
|
|
1041
|
-
};
|
|
1042
|
-
for (const [name, prop] of Object.entries(props)) {
|
|
1043
|
-
const fullPath = parentPath ? `${parentPath}.${name}` : name;
|
|
1044
|
-
if (isCompositeWithInlineNestedProps(prop, fullPath)) {
|
|
1045
|
-
const inlinePropertiesDefs = getSectionChildren(prop.nestedProps, fullPath);
|
|
1046
|
-
properties.push(...inlinePropertiesDefs);
|
|
1047
|
-
} else if (prop.hasPropertiesPanelDisplay()) {
|
|
1048
|
-
const def = prop.setName(fullPath).toDefinition(entity, scopedState);
|
|
1049
|
-
if (def) properties.push(def);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
return properties;
|
|
1053
|
-
};
|
|
1054
|
-
for (const [, section] of Object.entries(sections)) {
|
|
1055
|
-
const children = getSectionChildren(section.props, "");
|
|
1056
|
-
if (children.length === 0) continue;
|
|
1057
|
-
sectionDefs.push({
|
|
1058
|
-
name: section.name,
|
|
1059
|
-
category: section.category,
|
|
1060
|
-
children,
|
|
1061
|
-
showHeader: section.propertiesPanelConfig.showHeader,
|
|
1062
|
-
isDefaultOpen: section.propertiesPanelConfig.isDefaultOpen,
|
|
1063
|
-
headerType: section.propertiesPanelConfig.headerType,
|
|
1064
|
-
subHeader: section.propertiesPanelConfig.subHeader
|
|
1065
|
-
});
|
|
1066
|
-
}
|
|
1067
|
-
return { sections: sectionDefs };
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
//#endregion
|
|
1071
|
-
//#region src/lib/user-facing/properties-panel/validators.ts
|
|
1072
|
-
const Valid = (result) => {
|
|
1073
|
-
return {
|
|
1074
|
-
valid: true,
|
|
1075
|
-
result
|
|
1076
|
-
};
|
|
1077
|
-
};
|
|
1078
|
-
const DEFAULT_INVALID_MESSAGE = "Value does not match Required Data Format";
|
|
1079
|
-
const Invalid = (message = DEFAULT_INVALID_MESSAGE, invalidValue) => {
|
|
1080
|
-
return {
|
|
1081
|
-
valid: false,
|
|
1082
|
-
message,
|
|
1083
|
-
invalidValue
|
|
1084
|
-
};
|
|
1085
|
-
};
|
|
1086
|
-
const VALIDATORS = {
|
|
1087
|
-
TEXT: (value) => {
|
|
1088
|
-
let parsed = value;
|
|
1089
|
-
if (isUndefined(value) || value === null) return Valid("");
|
|
1090
|
-
if (isObject(value) || Array.isArray(value)) return Valid(JSON5.stringify(value, null, 2));
|
|
1091
|
-
let isValid = isString(value);
|
|
1092
|
-
if (!isValid) try {
|
|
1093
|
-
parsed = toString(value);
|
|
1094
|
-
isValid = true;
|
|
1095
|
-
} catch (e) {
|
|
1096
|
-
console.error(`Error when parsing ${value} to string`);
|
|
1097
|
-
console.error(e);
|
|
1098
|
-
return Invalid("Invalid string", value);
|
|
1099
|
-
}
|
|
1100
|
-
return Valid(parsed);
|
|
1101
|
-
},
|
|
1102
|
-
TEXT_EMPTY_NULL: (value, props) => {
|
|
1103
|
-
if (value === "") return Valid(null);
|
|
1104
|
-
return VALIDATORS.TEXT(value, props);
|
|
1105
|
-
},
|
|
1106
|
-
TEXT_ALLOW_UNDEFINED: (value, props) => {
|
|
1107
|
-
if (isUndefined(value)) return Valid(value);
|
|
1108
|
-
return VALIDATORS.TEXT(value, props);
|
|
1109
|
-
},
|
|
1110
|
-
REGEX: (value, props) => {
|
|
1111
|
-
const result = VALIDATORS.TEXT(value, props);
|
|
1112
|
-
if (result.valid && result.result !== void 0) {
|
|
1113
|
-
try {
|
|
1114
|
-
new RegExp(result.result);
|
|
1115
|
-
} catch (_e) {
|
|
1116
|
-
return Invalid("Invalid regex", value);
|
|
1117
|
-
}
|
|
1118
|
-
return Valid(result.result);
|
|
1119
|
-
}
|
|
1120
|
-
return Invalid("Invalid regex", value);
|
|
1121
|
-
},
|
|
1122
|
-
NUMBER: (value) => {
|
|
1123
|
-
let parsed = value;
|
|
1124
|
-
if (isUndefined(value)) return Invalid("Invalid number", value);
|
|
1125
|
-
let isValid = isNumber(value);
|
|
1126
|
-
if (!isValid) try {
|
|
1127
|
-
parsed = toNumber(value);
|
|
1128
|
-
isValid = true;
|
|
1129
|
-
} catch (e) {
|
|
1130
|
-
console.error(`Error when parsing ${value} to number`);
|
|
1131
|
-
console.error(e);
|
|
1132
|
-
return Invalid("Invalid number", value);
|
|
1133
|
-
}
|
|
1134
|
-
return Valid(parsed);
|
|
1135
|
-
},
|
|
1136
|
-
NUMBER_ALLOW_UNDEFINED: (value, props) => {
|
|
1137
|
-
if (isUndefined(value)) return Valid(value);
|
|
1138
|
-
return VALIDATORS.NUMBER(value, props);
|
|
1139
|
-
},
|
|
1140
|
-
BOOLEAN: (value) => {
|
|
1141
|
-
if (isUndefined(value)) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1142
|
-
return Valid(Boolean(value));
|
|
1143
|
-
},
|
|
1144
|
-
BOOLEAN_ALLOW_UNDEFINED: (value, props) => {
|
|
1145
|
-
if (isUndefined(value)) return Valid(value);
|
|
1146
|
-
return VALIDATORS.BOOLEAN(value, props);
|
|
1147
|
-
},
|
|
1148
|
-
OBJECT: (value) => {
|
|
1149
|
-
let parsed = value;
|
|
1150
|
-
if (isUndefined(value)) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1151
|
-
let isValid = isObject(value);
|
|
1152
|
-
if (!isValid) try {
|
|
1153
|
-
parsed = JSON.parse(value);
|
|
1154
|
-
isValid = true;
|
|
1155
|
-
} catch (e) {
|
|
1156
|
-
console.error(`Error when parsing ${value} to object`);
|
|
1157
|
-
console.error(e);
|
|
1158
|
-
return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1159
|
-
}
|
|
1160
|
-
return Valid(parsed);
|
|
1161
|
-
},
|
|
1162
|
-
OBJECT_OR_UNDEFINED: (value, props) => {
|
|
1163
|
-
if (isUndefined(value)) return Valid(value);
|
|
1164
|
-
return VALIDATORS.OBJECT(value, props);
|
|
1165
|
-
},
|
|
1166
|
-
ARRAY: (value) => {
|
|
1167
|
-
let parsed = value;
|
|
1168
|
-
try {
|
|
1169
|
-
if (isUndefined(value)) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1170
|
-
if (isString(value)) parsed = JSON5.parse(parsed);
|
|
1171
|
-
if (!Array.isArray(parsed)) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1172
|
-
return Valid(parsed);
|
|
1173
|
-
} catch (e) {
|
|
1174
|
-
console.error(e);
|
|
1175
|
-
return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1176
|
-
}
|
|
1177
|
-
},
|
|
1178
|
-
ARRAY_ALLOW_UNDEFINED: (value, props) => {
|
|
1179
|
-
if (isUndefined(value)) return Valid(value);
|
|
1180
|
-
return VALIDATORS.ARRAY(value, props);
|
|
1181
|
-
},
|
|
1182
|
-
NUMBER_ARRAY: (value, props) => {
|
|
1183
|
-
const res = VALIDATORS.ARRAY(value, props);
|
|
1184
|
-
if (!res.valid) return Invalid("Invalid number array", value);
|
|
1185
|
-
else if (!res.result.every((datum) => typeof datum === "number")) return Invalid("Not all elements in the array are numbers", value);
|
|
1186
|
-
return Valid(res.result);
|
|
1187
|
-
},
|
|
1188
|
-
FRACTION_DIGITS: (value, props) => {
|
|
1189
|
-
if (isEmpty(value)) return Valid(void 0);
|
|
1190
|
-
const result = VALIDATORS.NUMBER(value, props);
|
|
1191
|
-
if (!result.valid) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1192
|
-
if (result.result < 0 || result.result > 20) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1193
|
-
return Valid(result.result);
|
|
1194
|
-
},
|
|
1195
|
-
ICONS: () => {
|
|
1196
|
-
return Invalid("Icons validation not implemented", void 0);
|
|
1197
|
-
},
|
|
1198
|
-
DATE: (value, props) => {
|
|
1199
|
-
const dateFormat = props.dateFormat ? props.dateFormat : "YYYY-MM-DD";
|
|
1200
|
-
if (value === void 0) return Invalid("Value does not match Required Data Format" + (props.dateFormat ? props.dateFormat : ""), value);
|
|
1201
|
-
if (!moment(value, dateFormat).isValid()) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1202
|
-
return Valid(value);
|
|
1203
|
-
},
|
|
1204
|
-
URL_OR_BASE64: (value) => {
|
|
1205
|
-
if (!value) return Invalid(DEFAULT_INVALID_MESSAGE, value);
|
|
1206
|
-
if (/^data:application\/pdf;base64,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i.test(value)) return Valid(value);
|
|
1207
|
-
try {
|
|
1208
|
-
const newUrl = new URL(value);
|
|
1209
|
-
if (newUrl.protocol !== "https:") return Invalid("Only HTTPS protocol supported", value);
|
|
1210
|
-
return Valid(newUrl.href);
|
|
1211
|
-
} catch {
|
|
1212
|
-
return Invalid("Provided URL / Base64 is invalid.", value);
|
|
1213
|
-
}
|
|
1214
|
-
},
|
|
1215
|
-
URL_FOR_HYPERLINK: (value) => {
|
|
1216
|
-
const dummyBaseUrl = "https://superblocks.com";
|
|
1217
|
-
try {
|
|
1218
|
-
if (!(new URL(dummyBaseUrl).origin === new URL(value, dummyBaseUrl).origin)) {
|
|
1219
|
-
const absoluteUrl = new URL(value);
|
|
1220
|
-
if (absoluteUrl.protocol === "javascript:") return Invalid(`Invalid protocol ${absoluteUrl.protocol}`, value);
|
|
1221
|
-
} else if (value && value.startsWith("..")) return Invalid("Relative URLs cannot start with '..'", value);
|
|
1222
|
-
return Valid(value);
|
|
1223
|
-
} catch {
|
|
1224
|
-
return Invalid("Provided URL is invalid.", value);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
|
|
1229
|
-
//#endregion
|
|
1230
|
-
//#region src/lib/user-facing/properties-panel/props-builder.ts
|
|
1231
|
-
function mergeRelations(existingRelations, relations) {
|
|
1232
|
-
if (!existingRelations || existingRelations.length === 0) return relations;
|
|
1233
|
-
if (!relations || relations.length === 0) return existingRelations;
|
|
1234
|
-
return existingRelations && existingRelations.length > 0 ? existingRelations.flatMap((existing) => relations.map((relation) => [...existing, ...relation])) : relations;
|
|
1235
|
-
}
|
|
1236
|
-
function getChildren(input, path, entity, scopedState) {
|
|
1237
|
-
function getChildrenFromSection(section) {
|
|
1238
|
-
return Object.keys(section.props).reduce((acc, key) => {
|
|
1239
|
-
const definition = section.props[key].setName(path + "." + key).toDefinition(entity, scopedState);
|
|
1240
|
-
if (definition) acc[key] = definition;
|
|
1241
|
-
return acc;
|
|
1242
|
-
}, {});
|
|
1243
|
-
}
|
|
1244
|
-
let children;
|
|
1245
|
-
if (input instanceof Section) children = getChildrenFromSection(input);
|
|
1246
|
-
else if (Object.values(input).every((c) => c instanceof Section)) children = Object.values(input).reduce((acc, section) => {
|
|
1247
|
-
return {
|
|
1248
|
-
...acc,
|
|
1249
|
-
...getChildrenFromSection(section)
|
|
1250
|
-
};
|
|
1251
|
-
}, {});
|
|
1252
|
-
else children = Object.fromEntries(Object.entries(input).map(([key, prop]) => {
|
|
1253
|
-
return [key, prop.setName(path + "." + key).toDefinition(entity, scopedState)];
|
|
1254
|
-
}));
|
|
1255
|
-
return children;
|
|
1256
|
-
}
|
|
1257
|
-
var Section = class Section {
|
|
1258
|
-
props = {};
|
|
1259
|
-
propertiesPanelConfig = {
|
|
1260
|
-
showHeader: true,
|
|
1261
|
-
isDefaultOpen: true
|
|
1262
|
-
};
|
|
1263
|
-
constructor(category) {
|
|
1264
|
-
this.category = category;
|
|
1265
|
-
}
|
|
1266
|
-
static category(category) {
|
|
1267
|
-
return new Section(category);
|
|
1268
|
-
}
|
|
1269
|
-
children(props) {
|
|
1270
|
-
if (props instanceof CompositeProp || props instanceof RecordProp) this.props = {
|
|
1271
|
-
...this.props,
|
|
1272
|
-
...props.getProps()
|
|
1273
|
-
};
|
|
1274
|
-
else if (props instanceof UnionProp) this.props = {
|
|
1275
|
-
...this.props,
|
|
1276
|
-
...props.getProps()
|
|
1277
|
-
};
|
|
1278
|
-
else this.props = {
|
|
1279
|
-
...this.props,
|
|
1280
|
-
...props
|
|
1281
|
-
};
|
|
1282
|
-
return this;
|
|
1283
|
-
}
|
|
1284
|
-
add = this.children;
|
|
1285
|
-
propertiesPanel(config) {
|
|
1286
|
-
this.propertiesPanelConfig = {
|
|
1287
|
-
...this.propertiesPanelConfig,
|
|
1288
|
-
...config
|
|
1289
|
-
};
|
|
1290
|
-
return this;
|
|
1291
|
-
}
|
|
1292
|
-
get name() {
|
|
1293
|
-
switch (this.category) {
|
|
1294
|
-
case PropsPanelCategory.Content: return "Content";
|
|
1295
|
-
case PropsPanelCategory.Routing: return "Routing";
|
|
1296
|
-
case PropsPanelCategory.Interaction: return "Interaction";
|
|
1297
|
-
case PropsPanelCategory.Layout: return "Layout";
|
|
1298
|
-
case PropsPanelCategory.Appearance: return "Appearance";
|
|
1299
|
-
case PropsPanelCategory.Permissions: return "Permissions";
|
|
1300
|
-
case PropsPanelCategory.EventHandlers: return "Event handlers";
|
|
1301
|
-
case PropsPanelCategory.CustomStyles: return "Custom styles";
|
|
1302
|
-
case PropsPanelCategory.Uncategorized: return "Uncategorized";
|
|
1303
|
-
default: return "Uncategorized";
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
var Prop = class Prop {
|
|
1308
|
-
prop;
|
|
1309
|
-
/**
|
|
1310
|
-
* Relations are an array of arrays
|
|
1311
|
-
* each sub-array is AND requirements, and each element is an OR requirement
|
|
1312
|
-
*/
|
|
1313
|
-
relations = [];
|
|
1314
|
-
constructor(typeString, defaultValidator) {
|
|
1315
|
-
this.prop = {
|
|
1316
|
-
path: "",
|
|
1317
|
-
dataType: typeString,
|
|
1318
|
-
isExternallyReadable: true,
|
|
1319
|
-
isExternallySettable: false,
|
|
1320
|
-
validate: defaultValidator
|
|
1321
|
-
};
|
|
1322
|
-
}
|
|
1323
|
-
static unset() {
|
|
1324
|
-
return new Prop("any");
|
|
1325
|
-
}
|
|
1326
|
-
static string() {
|
|
1327
|
-
return new Prop("string", VALIDATORS.TEXT_ALLOW_UNDEFINED);
|
|
1328
|
-
}
|
|
1329
|
-
static number() {
|
|
1330
|
-
return new Prop("number", VALIDATORS.NUMBER_ALLOW_UNDEFINED);
|
|
1331
|
-
}
|
|
1332
|
-
static boolean() {
|
|
1333
|
-
return new Prop("boolean", VALIDATORS.BOOLEAN_ALLOW_UNDEFINED);
|
|
1334
|
-
}
|
|
1335
|
-
static array() {
|
|
1336
|
-
return new Prop("array", VALIDATORS.ARRAY_ALLOW_UNDEFINED);
|
|
1337
|
-
}
|
|
1338
|
-
static any() {
|
|
1339
|
-
return new Prop("any");
|
|
1340
|
-
}
|
|
1341
|
-
static jsx() {
|
|
1342
|
-
return new Prop("jsx");
|
|
1343
|
-
}
|
|
1344
|
-
static dimension() {
|
|
1345
|
-
return new Prop("dimension");
|
|
1346
|
-
}
|
|
1347
|
-
static literal(value) {
|
|
1348
|
-
switch (typeof value) {
|
|
1349
|
-
case "string": return Prop.string().default(value);
|
|
1350
|
-
case "number": return Prop.number().default(value);
|
|
1351
|
-
case "boolean": return Prop.boolean().default(value);
|
|
1352
|
-
default: {
|
|
1353
|
-
const exhaustiveCheck = value;
|
|
1354
|
-
throw new Error(`Invalid literal value: ${exhaustiveCheck}`);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
static event() {
|
|
1359
|
-
return new Prop("event");
|
|
1360
|
-
}
|
|
1361
|
-
static children() {
|
|
1362
|
-
return new ChildrenProp();
|
|
1363
|
-
}
|
|
1364
|
-
static function(implementation) {
|
|
1365
|
-
return new FunctionProp(implementation);
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
* Creates an internal property that is not exposed in the entity's public interface,
|
|
1369
|
-
* not tracked for reactivity/syncing, and not serialized. This is useful for
|
|
1370
|
-
* storing implementation details like SuspensibleAPI instances that other
|
|
1371
|
-
* properties can reference via `this._propertyName`.
|
|
1372
|
-
*/
|
|
1373
|
-
static internal(factory) {
|
|
1374
|
-
return new Prop("internal").default(factory);
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Creates a composite property, which is a property that contains nested properties. For example,
|
|
1378
|
-
* the following composite property:
|
|
1379
|
-
*
|
|
1380
|
-
* ```ts
|
|
1381
|
-
* const prop = Prop.composite({
|
|
1382
|
-
* name: Prop.string(),
|
|
1383
|
-
* age: Prop.number(),
|
|
1384
|
-
* });
|
|
1385
|
-
* ```
|
|
1386
|
-
*
|
|
1387
|
-
* is equivalent to the following type:
|
|
1388
|
-
*
|
|
1389
|
-
* ```ts
|
|
1390
|
-
* type Prop = {
|
|
1391
|
-
* name: string;
|
|
1392
|
-
* age: number;
|
|
1393
|
-
* };
|
|
1394
|
-
* ```
|
|
1395
|
-
*/
|
|
1396
|
-
static composite(props) {
|
|
1397
|
-
return new CompositeProp(props);
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Creates a record property, which is a record that maps string keys to the nestedproperties. For example,
|
|
1401
|
-
* the following record property:
|
|
1402
|
-
*
|
|
1403
|
-
* ```ts
|
|
1404
|
-
* const prop = Prop.record({
|
|
1405
|
-
* name: Prop.string(),
|
|
1406
|
-
* age: Prop.number(),
|
|
1407
|
-
* });
|
|
1408
|
-
* ```
|
|
1409
|
-
*
|
|
1410
|
-
* is equivalent to the following type:
|
|
1411
|
-
*
|
|
1412
|
-
* ```ts
|
|
1413
|
-
* type Prop = Record<string, {
|
|
1414
|
-
* name: string;
|
|
1415
|
-
* age: number;
|
|
1416
|
-
* }>;
|
|
1417
|
-
* ```
|
|
1418
|
-
*/
|
|
1419
|
-
static record(props) {
|
|
1420
|
-
return new RecordProp(props);
|
|
1421
|
-
}
|
|
1422
|
-
static union(props) {
|
|
1423
|
-
return new UnionProp(props.shared, props.variants);
|
|
1424
|
-
}
|
|
1425
|
-
readable() {
|
|
1426
|
-
this.prop.isExternallyReadable = true;
|
|
1427
|
-
return this;
|
|
1428
|
-
}
|
|
1429
|
-
writable() {
|
|
1430
|
-
this.prop.isExternallySettable = true;
|
|
1431
|
-
return this;
|
|
1432
|
-
}
|
|
1433
|
-
readAndWrite() {
|
|
1434
|
-
this.prop.isExternallyReadable = true;
|
|
1435
|
-
this.prop.isExternallySettable = true;
|
|
1436
|
-
return this;
|
|
1437
|
-
}
|
|
1438
|
-
default(de) {
|
|
1439
|
-
this.prop.default = de;
|
|
1440
|
-
if (this.prop.propertiesPanelDisplay && this.prop.propertiesPanelDisplay.defaultValue === void 0) this.prop.propertiesPanelDisplay.defaultValue = de;
|
|
1441
|
-
return this;
|
|
1442
|
-
}
|
|
1443
|
-
computed(computeFn) {
|
|
1444
|
-
return this.default(computeFn);
|
|
1445
|
-
}
|
|
1446
|
-
allowNestedBindings() {
|
|
1447
|
-
this.prop.nestedBindings = true;
|
|
1448
|
-
throw new Error("Nested bindings are not supported yet");
|
|
1449
|
-
}
|
|
1450
|
-
contextual(computedArgs) {
|
|
1451
|
-
this.prop.contextual = true;
|
|
1452
|
-
this.prop.computedArgs = computedArgs;
|
|
1453
|
-
return this;
|
|
1454
|
-
}
|
|
1455
|
-
validate(validateFn) {
|
|
1456
|
-
this.prop.validate = validateFn;
|
|
1457
|
-
return this;
|
|
1458
|
-
}
|
|
1459
|
-
setName(name) {
|
|
1460
|
-
this.prop.path = name;
|
|
1461
|
-
return this;
|
|
1462
|
-
}
|
|
1463
|
-
onEdit(callback) {
|
|
1464
|
-
this.prop.onEditProperty = callback;
|
|
1465
|
-
return this;
|
|
1466
|
-
}
|
|
1467
|
-
onEvaluate(callback) {
|
|
1468
|
-
this.prop.onEvaluateProperty = callback;
|
|
1469
|
-
return this;
|
|
1470
|
-
}
|
|
1471
|
-
propertiesPanel(schema) {
|
|
1472
|
-
let baseControlType;
|
|
1473
|
-
let isJSConvertible = true;
|
|
1474
|
-
let isTriggerProperty = false;
|
|
1475
|
-
let inputType;
|
|
1476
|
-
switch (this.prop.dataType) {
|
|
1477
|
-
case "string":
|
|
1478
|
-
baseControlType = "INPUT_TEXT";
|
|
1479
|
-
break;
|
|
1480
|
-
case "number":
|
|
1481
|
-
baseControlType = "INPUT_TEXT";
|
|
1482
|
-
inputType = InputType.NUMBER;
|
|
1483
|
-
break;
|
|
1484
|
-
case "array":
|
|
1485
|
-
baseControlType = "INPUT_TEXT";
|
|
1486
|
-
break;
|
|
1487
|
-
case "boolean":
|
|
1488
|
-
baseControlType = "SWITCH";
|
|
1489
|
-
break;
|
|
1490
|
-
case "event":
|
|
1491
|
-
baseControlType = "EVENT_TRIGGER";
|
|
1492
|
-
isJSConvertible = false;
|
|
1493
|
-
isTriggerProperty = true;
|
|
1494
|
-
break;
|
|
1495
|
-
case "jsx":
|
|
1496
|
-
case "children":
|
|
1497
|
-
baseControlType = "JSX";
|
|
1498
|
-
break;
|
|
1499
|
-
case "any":
|
|
1500
|
-
default:
|
|
1501
|
-
baseControlType = "INPUT_JS_EXPR";
|
|
1502
|
-
break;
|
|
1503
|
-
}
|
|
1504
|
-
const propertiesPanelDisplay = {
|
|
1505
|
-
controlType: baseControlType,
|
|
1506
|
-
isJSConvertible,
|
|
1507
|
-
isTriggerProperty,
|
|
1508
|
-
defaultValue: schema.defaultValue ?? this.prop.default,
|
|
1509
|
-
defaultOnAdd: this.prop.propertiesPanelDisplay?.defaultOnAdd,
|
|
1510
|
-
inputType,
|
|
1511
|
-
...schema
|
|
1512
|
-
};
|
|
1513
|
-
this.prop.propertiesPanelDisplay = propertiesPanelDisplay;
|
|
1514
|
-
return this;
|
|
1515
|
-
}
|
|
1516
|
-
setDisplayProperty(property, value) {
|
|
1517
|
-
if (!this.prop.propertiesPanelDisplay) return this;
|
|
1518
|
-
this.prop.propertiesPanelDisplay[property] = value;
|
|
1519
|
-
return this;
|
|
1520
|
-
}
|
|
1521
|
-
docs(docs) {
|
|
1522
|
-
this.prop.docs = docs;
|
|
1523
|
-
return this;
|
|
1524
|
-
}
|
|
1525
|
-
/**
|
|
1526
|
-
* Sets a custom type hint for documentation generation.
|
|
1527
|
-
* This will override the auto-generated type in generated docs.
|
|
1528
|
-
*
|
|
1529
|
-
* @param typeHint The TypeScript type string to display in documentation
|
|
1530
|
-
* @example .typeHint("CSSProperties")
|
|
1531
|
-
* @example .typeHint("Record<string, { color: string; backgroundColor?: string }>")
|
|
1532
|
-
*/
|
|
1533
|
-
typeHint(typeHint) {
|
|
1534
|
-
this.prop.typeHint = typeHint;
|
|
1535
|
-
return this;
|
|
1536
|
-
}
|
|
1537
|
-
build() {
|
|
1538
|
-
return this.prop;
|
|
1539
|
-
}
|
|
1540
|
-
toDefinition(entity, scopedState) {
|
|
1541
|
-
const evaluatedProperties = Object.entries(this.prop.propertiesPanelDisplay ?? {}).reduce((acc, [key, value]) => {
|
|
1542
|
-
if (typeof value === "function") try {
|
|
1543
|
-
acc[key] = value.bind(entity)(scopedState, this.prop.path);
|
|
1544
|
-
} catch (e) {
|
|
1545
|
-
console.error(`Error evaluating property ${key}, for type ${entity?.type}:`, e);
|
|
1546
|
-
}
|
|
1547
|
-
return acc;
|
|
1548
|
-
}, {});
|
|
1549
|
-
if (evaluatedProperties.isVisible === false) return;
|
|
1550
|
-
const propertiesPanelDisplay = {
|
|
1551
|
-
...this.prop.propertiesPanelDisplay,
|
|
1552
|
-
...evaluatedProperties
|
|
1553
|
-
};
|
|
1554
|
-
if ("treatDefaultAsNull" in propertiesPanelDisplay) {
|
|
1555
|
-
if (propertiesPanelDisplay.treatDefaultAsNull) {
|
|
1556
|
-
if (propertiesPanelDisplay.defaultOnAdd === void 0) propertiesPanelDisplay.defaultOnAdd = propertiesPanelDisplay.defaultValue;
|
|
1557
|
-
propertiesPanelDisplay.defaultValue = void 0;
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
let panelConfig;
|
|
1561
|
-
const childrenDisplay = propertiesPanelDisplay?.childrenDisplayMode;
|
|
1562
|
-
if (childrenDisplay?.type === "popover") {
|
|
1563
|
-
if (!(this instanceof CompositeProp || this instanceof RecordProp)) {
|
|
1564
|
-
console.error(this);
|
|
1565
|
-
throw new Error("Only composite properties can be used in popover properties at the moment");
|
|
1566
|
-
}
|
|
1567
|
-
const content = this.getProps();
|
|
1568
|
-
const { type,...rest } = childrenDisplay;
|
|
1569
|
-
let contentDef;
|
|
1570
|
-
if (content instanceof Section) contentDef = { content };
|
|
1571
|
-
else if (Object.values(content).every((c) => c instanceof Section)) contentDef = content;
|
|
1572
|
-
else contentDef = { content: Section.category(PropsPanelCategory.Content).propertiesPanel({ showHeader: false }).children(content) };
|
|
1573
|
-
panelConfig = {
|
|
1574
|
-
...createPropertiesPanelDefinition(contentDef, entity, scopedState),
|
|
1575
|
-
...rest
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
if (this.prop.computedArgs) propertiesPanelDisplay.computedArgs = typeof this.prop.computedArgs === "function" ? this.prop.computedArgs(entity) : this.prop.computedArgs;
|
|
1579
|
-
const propertiesPanelDisplayWithPanelConfig = {
|
|
1580
|
-
...propertiesPanelDisplay,
|
|
1581
|
-
...panelConfig && { panelConfig }
|
|
1582
|
-
};
|
|
1583
|
-
return {
|
|
1584
|
-
path: this.prop.path,
|
|
1585
|
-
dataType: this.prop.dataType,
|
|
1586
|
-
relations: this.relations,
|
|
1587
|
-
propertiesPanelDisplay: propertiesPanelDisplayWithPanelConfig
|
|
1588
|
-
};
|
|
1589
|
-
}
|
|
1590
|
-
getRelations() {
|
|
1591
|
-
return this.relations;
|
|
1592
|
-
}
|
|
1593
|
-
dependsOn(relations) {
|
|
1594
|
-
this.relations = relations;
|
|
1595
|
-
return this;
|
|
1596
|
-
}
|
|
1597
|
-
hasPropertiesPanelDisplay() {
|
|
1598
|
-
return this.prop.propertiesPanelDisplay !== void 0;
|
|
1599
|
-
}
|
|
1600
|
-
get type() {
|
|
1601
|
-
return this.prop.dataType;
|
|
1602
|
-
}
|
|
1603
|
-
get path() {
|
|
1604
|
-
return this.prop.path;
|
|
1605
|
-
}
|
|
1606
|
-
get onEditProperty() {
|
|
1607
|
-
return this.prop.onEditProperty;
|
|
1608
|
-
}
|
|
1609
|
-
get onEvaluateProperty() {
|
|
1610
|
-
return this.prop.onEvaluateProperty;
|
|
1611
|
-
}
|
|
1612
|
-
};
|
|
1613
|
-
/**
|
|
1614
|
-
* See {@link Prop.composite}
|
|
1615
|
-
*/
|
|
1616
|
-
var CompositeProp = class extends Prop {
|
|
1617
|
-
typeString = "composite";
|
|
1618
|
-
nestedProps;
|
|
1619
|
-
constructor(props) {
|
|
1620
|
-
super("composite");
|
|
1621
|
-
this.nestedProps = props;
|
|
1622
|
-
}
|
|
1623
|
-
getProps() {
|
|
1624
|
-
return this.nestedProps;
|
|
1625
|
-
}
|
|
1626
|
-
toDefinition(entity, scopedState) {
|
|
1627
|
-
const definition = super.toDefinition(entity, scopedState);
|
|
1628
|
-
if (!definition) return;
|
|
1629
|
-
return {
|
|
1630
|
-
...definition,
|
|
1631
|
-
children: getChildren(this.nestedProps, this.prop.path, entity, scopedState)
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
propertiesPanelChildrenDisplayMode() {
|
|
1635
|
-
return this.prop.propertiesPanelDisplay?.childrenDisplayMode;
|
|
1636
|
-
}
|
|
1637
|
-
typeHint(typeHint) {
|
|
1638
|
-
this.prop.typeHint = typeHint;
|
|
1639
|
-
return this;
|
|
1640
|
-
}
|
|
1641
|
-
};
|
|
1642
|
-
/**
|
|
1643
|
-
* See {@link Prop.record}
|
|
1644
|
-
*/
|
|
1645
|
-
var RecordProp = class extends Prop {
|
|
1646
|
-
typeString = "recordOf";
|
|
1647
|
-
nestedProps;
|
|
1648
|
-
constructor(props) {
|
|
1649
|
-
super("recordOf");
|
|
1650
|
-
this.nestedProps = props;
|
|
1651
|
-
}
|
|
1652
|
-
getProps() {
|
|
1653
|
-
return this.nestedProps;
|
|
1654
|
-
}
|
|
1655
|
-
toDefinition(entity, scopedState) {
|
|
1656
|
-
const definition = super.toDefinition(entity, scopedState);
|
|
1657
|
-
if (!definition) return;
|
|
1658
|
-
return {
|
|
1659
|
-
...definition,
|
|
1660
|
-
children: getChildren(this.nestedProps, this.prop.path, entity, scopedState)
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
|
-
typeHint(typeHint) {
|
|
1664
|
-
this.prop.typeHint = typeHint;
|
|
1665
|
-
return this;
|
|
1666
|
-
}
|
|
1667
|
-
};
|
|
1668
|
-
var ChildrenProp = class extends Prop {
|
|
1669
|
-
typeString = "children";
|
|
1670
|
-
constructor() {
|
|
1671
|
-
super("children");
|
|
1672
|
-
}
|
|
1673
|
-
};
|
|
1674
|
-
var FunctionProp = class extends Prop {
|
|
1675
|
-
typeString = "function";
|
|
1676
|
-
_actionPanel;
|
|
1677
|
-
constructor(implementation) {
|
|
1678
|
-
super("function");
|
|
1679
|
-
this.default(implementation);
|
|
1680
|
-
}
|
|
1681
|
-
actionPanel(panel) {
|
|
1682
|
-
this._actionPanel = panel || {};
|
|
1683
|
-
return this;
|
|
1684
|
-
}
|
|
1685
|
-
getActionPanel() {
|
|
1686
|
-
return this._actionPanel;
|
|
1687
|
-
}
|
|
1688
|
-
hasActionPanel() {
|
|
1689
|
-
return !!this._actionPanel;
|
|
1690
|
-
}
|
|
1691
|
-
};
|
|
1692
|
-
var UnionProp = class extends Prop {
|
|
1693
|
-
typeString = "union";
|
|
1694
|
-
shared;
|
|
1695
|
-
variants;
|
|
1696
|
-
constructor(shared, variants) {
|
|
1697
|
-
super("any");
|
|
1698
|
-
this.shared = shared;
|
|
1699
|
-
this.variants = variants;
|
|
1700
|
-
}
|
|
1701
|
-
getProps() {
|
|
1702
|
-
const sharedKeys = Object.keys(this.shared);
|
|
1703
|
-
const variants = this.variants;
|
|
1704
|
-
const preMergeRelationsMap = variants.reduce((acc, v) => {
|
|
1705
|
-
Object.entries(v).forEach(([key, prop]) => {
|
|
1706
|
-
const existingRelations = acc[key] ?? [];
|
|
1707
|
-
const newRelations = prop.getRelations() ?? [];
|
|
1708
|
-
acc[key] = [...existingRelations, ...newRelations];
|
|
1709
|
-
});
|
|
1710
|
-
return acc;
|
|
1711
|
-
}, {});
|
|
1712
|
-
const mergedVariants = variants.reduce((acc, v) => {
|
|
1713
|
-
const relations = Object.entries(v).filter(([key]) => sharedKeys.includes(key)).map(([key, prop]) => {
|
|
1714
|
-
return {
|
|
1715
|
-
key,
|
|
1716
|
-
value: prop.build().default
|
|
1717
|
-
};
|
|
1718
|
-
});
|
|
1719
|
-
const filteredVariant = Object.fromEntries(Object.entries(v).filter(([key]) => !sharedKeys.includes(key)).map(([key, prop]) => {
|
|
1720
|
-
const existingRelations = prop?.getRelations() ?? [];
|
|
1721
|
-
const preMergeRelations = preMergeRelationsMap[key];
|
|
1722
|
-
const existingNonPreMergeRelations = existingRelations.filter((r) => !preMergeRelations.some((p) => p === r));
|
|
1723
|
-
const newProp = prop.dependsOn([...existingNonPreMergeRelations, ...mergeRelations(preMergeRelations, [relations])]);
|
|
1724
|
-
if (acc[key]) {
|
|
1725
|
-
const existingPropRelations = acc[key].getRelations() ?? [];
|
|
1726
|
-
const newPropRelations = newProp.getRelations() ?? [];
|
|
1727
|
-
const seenHashes = /* @__PURE__ */ new Set();
|
|
1728
|
-
const uniqueRelations = [...existingPropRelations, ...newPropRelations].filter((relationGroup) => {
|
|
1729
|
-
const hash = relationGroup.map((r) => `${r.key}:${String(r.value)}`).sort().join("|");
|
|
1730
|
-
if (seenHashes.has(hash)) return false;
|
|
1731
|
-
seenHashes.add(hash);
|
|
1732
|
-
return true;
|
|
1733
|
-
});
|
|
1734
|
-
return [key, acc[key].dependsOn(uniqueRelations)];
|
|
1735
|
-
}
|
|
1736
|
-
return [key, newProp];
|
|
1737
|
-
}));
|
|
1738
|
-
return {
|
|
1739
|
-
...acc,
|
|
1740
|
-
...filteredVariant
|
|
1741
|
-
};
|
|
1742
|
-
}, {});
|
|
1743
|
-
return {
|
|
1744
|
-
...this.shared,
|
|
1745
|
-
...mergedVariants
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
|
|
1750
|
-
//#endregion
|
|
1751
|
-
//#region src/lib/user-facing/properties-panel/create-managed-props-list.ts
|
|
1752
|
-
const RECORD_PATH_IDENTIFIER = "*";
|
|
1753
|
-
function buildCompositeDefault(prop, name, parentDefault) {
|
|
1754
|
-
const defaultThroughParent = parentDefault?.[name];
|
|
1755
|
-
const selfDefault = prop.build().default;
|
|
1756
|
-
let propDefault = defaultThroughParent ?? selfDefault;
|
|
1757
|
-
if (!propDefault && typeof parentDefault === "function") propDefault = function getNestedDefault(s) {
|
|
1758
|
-
return parentDefault.call(this, s)?.[name];
|
|
1759
|
-
};
|
|
1760
|
-
return propDefault;
|
|
1761
|
-
}
|
|
1762
|
-
function buildPropLeafDefault(prop, name, parentDefault) {
|
|
1763
|
-
const defaultThroughParent = parentDefault?.[name];
|
|
1764
|
-
let propDefault = prop.build().default ?? defaultThroughParent;
|
|
1765
|
-
if (!propDefault && typeof parentDefault === "function") propDefault = function getNestedDefault(s) {
|
|
1766
|
-
return parentDefault.call(this, s)?.[name];
|
|
1767
|
-
};
|
|
1768
|
-
return propDefault;
|
|
1769
|
-
}
|
|
1770
|
-
/**
|
|
1771
|
-
* Core traversal function that walks through all properties in sections
|
|
1772
|
-
* and calls the provided callback for each leaf property.
|
|
1773
|
-
*/
|
|
1774
|
-
function traverseProps(sections, onProp, parentPath = "") {
|
|
1775
|
-
const processProps = ({ sectionName, props, parentPath: parentPath$1, parentDefault }) => {
|
|
1776
|
-
for (const [name, prop] of Object.entries(props)) {
|
|
1777
|
-
const fullPath = parentPath$1 ? `${parentPath$1}.${name}` : name;
|
|
1778
|
-
if (prop instanceof CompositeProp) {
|
|
1779
|
-
const compositeDefault = buildCompositeDefault(prop, name, parentDefault);
|
|
1780
|
-
processProps({
|
|
1781
|
-
sectionName,
|
|
1782
|
-
props: prop.nestedProps,
|
|
1783
|
-
parentPath: fullPath,
|
|
1784
|
-
parentDefault: compositeDefault
|
|
1785
|
-
});
|
|
1786
|
-
} else if (prop instanceof RecordProp) {
|
|
1787
|
-
const recordPath = `${fullPath}.${RECORD_PATH_IDENTIFIER}`;
|
|
1788
|
-
processProps({
|
|
1789
|
-
sectionName,
|
|
1790
|
-
props: prop.nestedProps,
|
|
1791
|
-
parentPath: recordPath,
|
|
1792
|
-
parentDefault: prop.build().default
|
|
1793
|
-
});
|
|
1794
|
-
} else if (prop instanceof Section) processProps({
|
|
1795
|
-
sectionName,
|
|
1796
|
-
props: prop.props,
|
|
1797
|
-
parentPath: parentPath$1
|
|
1798
|
-
});
|
|
1799
|
-
else if (prop instanceof UnionProp) {
|
|
1800
|
-
const sharedKeys = Object.keys(prop.shared);
|
|
1801
|
-
processProps({
|
|
1802
|
-
sectionName,
|
|
1803
|
-
props: prop.shared,
|
|
1804
|
-
parentPath: fullPath
|
|
1805
|
-
});
|
|
1806
|
-
for (const variant of prop.variants) processProps({
|
|
1807
|
-
sectionName,
|
|
1808
|
-
props: Object.fromEntries(Object.entries(variant).filter(([key]) => !sharedKeys.includes(key))),
|
|
1809
|
-
parentPath: fullPath
|
|
1810
|
-
});
|
|
1811
|
-
} else if (prop instanceof Prop) onProp(prop, fullPath, name, parentDefault, sectionName);
|
|
1812
|
-
else console.warn("Invalid prop type", {
|
|
1813
|
-
name,
|
|
1814
|
-
prop
|
|
1815
|
-
});
|
|
1816
|
-
}
|
|
1817
|
-
};
|
|
1818
|
-
for (const [sectionName, section] of Object.entries(sections)) processProps({
|
|
1819
|
-
sectionName,
|
|
1820
|
-
props: section.props,
|
|
1821
|
-
parentPath,
|
|
1822
|
-
parentDefault: void 0
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
function createInternalPropsList(sections, parentPath = "") {
|
|
1826
|
-
const internalPropsList = [];
|
|
1827
|
-
traverseProps(sections, (prop, fullPath) => {
|
|
1828
|
-
const builtProp = prop.setName(fullPath).build();
|
|
1829
|
-
if (builtProp.dataType === "internal" && builtProp.default) internalPropsList.push({
|
|
1830
|
-
path: fullPath,
|
|
1831
|
-
factory: builtProp.default
|
|
1832
|
-
});
|
|
1833
|
-
}, parentPath);
|
|
1834
|
-
return internalPropsList;
|
|
1835
|
-
}
|
|
1836
|
-
function createManagedPropsList(sections, parentPath = "") {
|
|
1837
|
-
const managedPropsList = [];
|
|
1838
|
-
traverseProps(sections, (prop, fullPath, name, parentDefault, sectionName) => {
|
|
1839
|
-
let configuredProp = prop.setName(fullPath);
|
|
1840
|
-
const propDefault = buildPropLeafDefault(prop, name, parentDefault);
|
|
1841
|
-
if (propDefault !== void 0) configuredProp = configuredProp.default(propDefault);
|
|
1842
|
-
const builtProp = configuredProp.build();
|
|
1843
|
-
if (builtProp.dataType === "internal") return;
|
|
1844
|
-
managedPropsList.push({
|
|
1845
|
-
...builtProp,
|
|
1846
|
-
...sectionName === "meta" ? { isMetaProp: true } : {},
|
|
1847
|
-
...builtProp.dataType === "function" ? {
|
|
1848
|
-
isFunctionProp: true,
|
|
1849
|
-
hasActionPanel: !!prop.getActionPanel()
|
|
1850
|
-
} : {}
|
|
1851
|
-
});
|
|
1852
|
-
}, parentPath);
|
|
1853
|
-
return managedPropsList;
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
//#endregion
|
|
1857
|
-
//#region src/lib/utils/fast-clone.ts
|
|
1858
|
-
const fastClone = clone({});
|
|
1859
|
-
|
|
1860
|
-
//#endregion
|
|
1861
|
-
//#region src/lib/internal-details/lib/devtools/index.tsx
|
|
1862
|
-
let internalStores = {};
|
|
1863
|
-
const SUPPORTED_MODES = ["local-dev"];
|
|
1864
|
-
function registerStores(stores) {
|
|
1865
|
-
internalStores = {
|
|
1866
|
-
...internalStores,
|
|
1867
|
-
...stores
|
|
1868
|
-
};
|
|
1869
|
-
if (SUPPORTED_MODES.includes("production")) {
|
|
1870
|
-
if (Object.keys(internalStores).length === Object.keys(stores).length) import("./devtools-consolidated-BJ2tPWBk.js").then(({ initializeCustomDevTools, setRegisteredStores }) => {
|
|
1871
|
-
setRegisteredStores(internalStores);
|
|
1872
|
-
initializeCustomDevTools();
|
|
1873
|
-
}).catch((error) => {
|
|
1874
|
-
console.warn("[DevTools] Failed to initialize custom devtools:", error);
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
const DevToolsInternal = React.lazy(() => {
|
|
1879
|
-
return import("./devtools-consolidated-BJ2tPWBk.js").then((module) => ({ default: module.CustomDevTools }));
|
|
1880
|
-
});
|
|
1881
|
-
const DevTools = () => {
|
|
1882
|
-
if (!SUPPORTED_MODES.includes("production")) return null;
|
|
1883
|
-
return /* @__PURE__ */ jsx(Suspense, {
|
|
1884
|
-
fallback: null,
|
|
1885
|
-
children: /* @__PURE__ */ jsx(DevToolsInternal, {})
|
|
1886
|
-
});
|
|
1887
|
-
};
|
|
1888
|
-
|
|
1889
|
-
//#endregion
|
|
1890
|
-
//#region src/lib/internal-details/lib/evaluator/create-global-object.ts
|
|
1891
|
-
const ARGS_VAR_NAME = "$SB_args";
|
|
1892
|
-
const USER_JS_CODE_VAR_NAME = "$SB_userJSCode";
|
|
1893
|
-
const SNAPSHOT_VAR_NAME = "$SB_snapshot";
|
|
1894
|
-
const globalNamesToIgnore = new Set([
|
|
1895
|
-
ARGS_VAR_NAME,
|
|
1896
|
-
USER_JS_CODE_VAR_NAME,
|
|
1897
|
-
SNAPSHOT_VAR_NAME
|
|
1898
|
-
]);
|
|
1899
|
-
function globalProxyHasTrap(_target, name) {
|
|
1900
|
-
return !globalNamesToIgnore.has(name);
|
|
1901
|
-
}
|
|
1902
|
-
function rejectModify() {
|
|
1903
|
-
throw new TypeError("Cannot modify read-only object");
|
|
1904
|
-
}
|
|
1905
|
-
function rejectGlobalAssignment() {
|
|
1906
|
-
throw new ReferenceError("Global assignments are not allowed");
|
|
1907
|
-
}
|
|
1908
|
-
const extraLibraries = {
|
|
1909
|
-
_,
|
|
1910
|
-
moment,
|
|
1911
|
-
Dim
|
|
1912
|
-
};
|
|
1913
|
-
const globalsRelyingOnWorkerGlobalScope = new Set([
|
|
1914
|
-
"atob",
|
|
1915
|
-
"btoa",
|
|
1916
|
-
"createImageBitmap",
|
|
1917
|
-
"queueMicrotask",
|
|
1918
|
-
"reportError",
|
|
1919
|
-
"structuredClone"
|
|
1920
|
-
]);
|
|
1921
|
-
function createGlobalObject({ snapshot }) {
|
|
1922
|
-
return new Proxy({}, {
|
|
1923
|
-
set: rejectGlobalAssignment,
|
|
1924
|
-
defineProperty: rejectModify,
|
|
1925
|
-
setPrototypeOf: rejectModify,
|
|
1926
|
-
has: globalProxyHasTrap,
|
|
1927
|
-
get(_target, name) {
|
|
1928
|
-
if (name === Symbol.unscopables) return;
|
|
1929
|
-
const lib = extraLibraries[name];
|
|
1930
|
-
if (lib) return lib;
|
|
1931
|
-
if (name in globalThis) {
|
|
1932
|
-
if (globalsRelyingOnWorkerGlobalScope.has(name)) return globalThis[name].bind(globalThis);
|
|
1933
|
-
return globalThis[name];
|
|
1934
|
-
}
|
|
1935
|
-
return snapshot[name];
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
//#endregion
|
|
1941
|
-
//#region src/lib/internal-details/lib/evaluator/pretty-print-function.ts
|
|
1942
|
-
const prettyPrintFunction = (func, args, fnName) => {
|
|
1943
|
-
let funcStr;
|
|
1944
|
-
try {
|
|
1945
|
-
funcStr = func.toString().replace(/\s+/g, " ").trim();
|
|
1946
|
-
} catch {
|
|
1947
|
-
funcStr = "[Function]";
|
|
1948
|
-
}
|
|
1949
|
-
let argsStr;
|
|
1950
|
-
try {
|
|
1951
|
-
argsStr = args.map((arg) => {
|
|
1952
|
-
try {
|
|
1953
|
-
return typeof arg === "string" ? `"${arg.replace(/\n/g, "\\n").replace(/"/g, "\\\"")}"` : String(arg).replace(/\s+/g, " ").trim();
|
|
1954
|
-
} catch {
|
|
1955
|
-
return String(arg);
|
|
1956
|
-
}
|
|
1957
|
-
}).join(", ");
|
|
1958
|
-
} catch {
|
|
1959
|
-
argsStr = "[Arguments]";
|
|
1960
|
-
}
|
|
1961
|
-
return `${fnName}: ${funcStr}(${argsStr})`;
|
|
1962
|
-
};
|
|
1963
|
-
|
|
1964
|
-
//#endregion
|
|
1965
|
-
//#region src/lib/internal-details/lib/evaluator/compute-engines.ts
|
|
1966
|
-
var EvalComputeEngine = class {
|
|
1967
|
-
statementFunction = new Function(SNAPSHOT_VAR_NAME, ARGS_VAR_NAME, USER_JS_CODE_VAR_NAME, `with (${SNAPSHOT_VAR_NAME}) {
|
|
1968
|
-
return (() => {
|
|
1969
|
-
"use strict";
|
|
1970
|
-
return eval("(" + ${USER_JS_CODE_VAR_NAME} + ")").call(this, ${SNAPSHOT_VAR_NAME}, ...${ARGS_VAR_NAME});
|
|
1971
|
-
})()
|
|
1972
|
-
}`);
|
|
1973
|
-
statementFunctionNoSnapshot = new Function(ARGS_VAR_NAME, USER_JS_CODE_VAR_NAME, `return (() => {
|
|
1974
|
-
"use strict";
|
|
1975
|
-
return eval("(" + ${USER_JS_CODE_VAR_NAME} + ")").call(this, ...${ARGS_VAR_NAME});
|
|
1976
|
-
})()`);
|
|
1977
|
-
compute({ snapshot, entityName, func, args, path, excludeState }) {
|
|
1978
|
-
try {
|
|
1979
|
-
if (excludeState) return this.statementFunctionNoSnapshot.call(snapshot[entityName.value], args || [], func.toString());
|
|
1980
|
-
const globalScope = createGlobalObject({ snapshot });
|
|
1981
|
-
return this.statementFunction.call(snapshot[entityName.value], globalScope, args || [], func.toString());
|
|
1982
|
-
} catch (error) {
|
|
1983
|
-
if (error instanceof Promise) throw error;
|
|
1984
|
-
console.log(`Error in eval(${entityName.value}.${path})`, {
|
|
1985
|
-
error,
|
|
1986
|
-
func: prettyPrintFunction(func, args || [], entityName.value + "." + path)
|
|
1987
|
-
});
|
|
1988
|
-
return;
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
};
|
|
1992
|
-
var DirectComputeEngine = class {
|
|
1993
|
-
compute({ snapshot, entityName, func, args, path, excludeState }) {
|
|
1994
|
-
if (!func) return void 0;
|
|
1995
|
-
try {
|
|
1996
|
-
const entity = snapshot[entityName.value];
|
|
1997
|
-
if (!entity) return void 0;
|
|
1998
|
-
const funcArgs = args || [];
|
|
1999
|
-
if (excludeState) return func.call(entity, ...funcArgs);
|
|
2000
|
-
return func.call(entity, snapshot, ...funcArgs);
|
|
2001
|
-
} catch (error) {
|
|
2002
|
-
if (error instanceof Promise) throw error;
|
|
2003
|
-
console.log(`Error in direct(${entityName.value}.${path})`, {
|
|
2004
|
-
error,
|
|
2005
|
-
func: prettyPrintFunction(func, args || [], entityName.value + "." + path)
|
|
2006
|
-
});
|
|
2007
|
-
return;
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
};
|
|
2011
|
-
|
|
2012
|
-
//#endregion
|
|
2013
|
-
//#region src/lib/internal-details/lib/evaluator/sanitize-object.ts
|
|
2014
|
-
const objectFallbackCache = /* @__PURE__ */ new WeakMap();
|
|
2015
|
-
function sanitizeObject(obj) {
|
|
2016
|
-
if (!objectFallbackCache.has(obj)) objectFallbackCache.set(obj, {});
|
|
2017
|
-
const fallbackCache = objectFallbackCache.get(obj);
|
|
2018
|
-
return new Proxy(obj, { get(target, prop) {
|
|
2019
|
-
try {
|
|
2020
|
-
const value = target[prop];
|
|
2021
|
-
if (typeof prop === "string") fallbackCache[prop] = value;
|
|
2022
|
-
return value;
|
|
2023
|
-
} catch (error) {
|
|
2024
|
-
if (error instanceof Promise) return typeof prop === "string" ? fallbackCache[prop] : void 0;
|
|
2025
|
-
throw error;
|
|
2026
|
-
}
|
|
2027
|
-
} });
|
|
2028
|
-
}
|
|
2029
|
-
function sanitizeEntity(entity) {
|
|
2030
|
-
return sanitizeObject(entity);
|
|
2031
|
-
}
|
|
2032
|
-
function sanitizeScopedState(state) {
|
|
2033
|
-
return new Proxy(state, { get(target, prop) {
|
|
2034
|
-
const value = target[prop];
|
|
2035
|
-
if (value && typeof value === "object" && "type" in value) return sanitizeObject(value);
|
|
2036
|
-
return value;
|
|
2037
|
-
} });
|
|
2038
|
-
}
|
|
2039
|
-
function sanitizedToJS(value) {
|
|
2040
|
-
if (value === null || value === void 0 || typeof value !== "object") return toJS(value);
|
|
2041
|
-
return toJS(sanitizeObject(value));
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
//#endregion
|
|
2045
|
-
//#region src/lib/internal-details/lib/evaluator/create-scope-proxy.ts
|
|
2046
|
-
function createScopeProxy(scopes, useSuspense = false) {
|
|
2047
|
-
return new Proxy({}, {
|
|
2048
|
-
get: function(_target, prop, _receiver) {
|
|
2049
|
-
for (const scope of scopes) {
|
|
2050
|
-
if (typeof prop === "symbol") return;
|
|
2051
|
-
if (prop in scope.entities) return !useSuspense ? sanitizeEntity(scope.entities[prop]) : scope.entities[prop];
|
|
2052
|
-
if (scope !== scopes[0] && scope.name === prop) return !useSuspense ? sanitizeScopedState(scope.entities) : scope.entities;
|
|
2053
|
-
}
|
|
2054
|
-
},
|
|
2055
|
-
ownKeys: function(_target) {
|
|
2056
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2057
|
-
for (const scope of scopes) {
|
|
2058
|
-
for (const key of Reflect.ownKeys(scope.entities)) keys.add(key);
|
|
2059
|
-
if (scope.name) keys.add(scope.name);
|
|
2060
|
-
}
|
|
2061
|
-
return Array.from(keys);
|
|
2062
|
-
},
|
|
2063
|
-
has: function(_target, prop) {
|
|
2064
|
-
for (const scope of scopes) {
|
|
2065
|
-
if (typeof prop === "symbol") return false;
|
|
2066
|
-
if (scope !== scopes[0] && scope.name === prop || prop in scope.entities) return true;
|
|
2067
|
-
}
|
|
2068
|
-
return false;
|
|
2069
|
-
},
|
|
2070
|
-
set: function(_target, _prop, _value, _receiver) {
|
|
2071
|
-
throw new Error("Cannot set state directly");
|
|
2072
|
-
}
|
|
2073
|
-
});
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
//#endregion
|
|
2077
|
-
//#region src/lib/user-facing/event-flow.ts
|
|
2078
|
-
var EventFlow = class EventFlow {
|
|
2079
|
-
steps = [];
|
|
2080
|
-
constructor() {}
|
|
2081
|
-
addStep(step) {
|
|
2082
|
-
this.steps.push({
|
|
2083
|
-
...step,
|
|
2084
|
-
id: nameGenerator()
|
|
2085
|
-
});
|
|
2086
|
-
return this;
|
|
2087
|
-
}
|
|
2088
|
-
static start() {
|
|
2089
|
-
return new EventFlow();
|
|
2090
|
-
}
|
|
2091
|
-
static runJS(handler) {
|
|
2092
|
-
return EventFlow.start().runJS(handler);
|
|
2093
|
-
}
|
|
2094
|
-
runJS(handler) {
|
|
2095
|
-
return this.addStep(registry_default.runJs.create(handler));
|
|
2096
|
-
}
|
|
2097
|
-
static navigateTo(url, opts) {
|
|
2098
|
-
return EventFlow.start().navigateTo(url, opts);
|
|
2099
|
-
}
|
|
2100
|
-
navigateTo(url, opts) {
|
|
2101
|
-
return this.addStep(registry_default.navigateTo.create(url, opts));
|
|
2102
|
-
}
|
|
2103
|
-
static navigateToApp(appId) {
|
|
2104
|
-
return EventFlow.start().navigateToApp(appId);
|
|
2105
|
-
}
|
|
2106
|
-
navigateToApp(appId) {
|
|
2107
|
-
return this.addStep(registry_default.navigateToApp.create(appId));
|
|
2108
|
-
}
|
|
2109
|
-
static navigateToRoute(route) {
|
|
2110
|
-
return EventFlow.start().navigateToRoute(route);
|
|
2111
|
-
}
|
|
2112
|
-
navigateToRoute(route) {
|
|
2113
|
-
return this.addStep(registry_default.navigateToRoute.create(route));
|
|
2114
|
-
}
|
|
2115
|
-
static setQueryParams(params, opts) {
|
|
2116
|
-
return EventFlow.start().setQueryParams(params, opts);
|
|
2117
|
-
}
|
|
2118
|
-
setQueryParams(params, opts) {
|
|
2119
|
-
return this.addStep(registry_default.setQueryParams.create(params, opts));
|
|
2120
|
-
}
|
|
2121
|
-
static controlSlideout(slideout, opts) {
|
|
2122
|
-
return EventFlow.start().controlSlideout(slideout, opts);
|
|
2123
|
-
}
|
|
2124
|
-
controlSlideout(slideout, opts) {
|
|
2125
|
-
return this.addStep(registry_default.controlSlideout.create(slideout, opts));
|
|
2126
|
-
}
|
|
2127
|
-
static controlModal(modal, opts) {
|
|
2128
|
-
return EventFlow.start().controlModal(modal, opts);
|
|
2129
|
-
}
|
|
2130
|
-
controlModal(modal, opts) {
|
|
2131
|
-
return this.addStep(registry_default.controlModal.create(modal, opts));
|
|
2132
|
-
}
|
|
2133
|
-
static controlTimer(stateTimer, opts) {
|
|
2134
|
-
return EventFlow.start().controlTimer(stateTimer, opts);
|
|
2135
|
-
}
|
|
2136
|
-
controlTimer(stateTimer, opts) {
|
|
2137
|
-
return this.addStep(registry_default.controlTimer.create(stateTimer, opts));
|
|
2138
|
-
}
|
|
2139
|
-
static runApis(apis, opts) {
|
|
2140
|
-
return EventFlow.start().runApis(apis, opts);
|
|
2141
|
-
}
|
|
2142
|
-
runApis(apis, opts) {
|
|
2143
|
-
return this.addStep(registry_default.executeApi.create(apis, opts));
|
|
2144
|
-
}
|
|
2145
|
-
static cancelApis(apis, onCancel) {
|
|
2146
|
-
return EventFlow.start().cancelApis(apis, onCancel);
|
|
2147
|
-
}
|
|
2148
|
-
cancelApis(apis, onCancel) {
|
|
2149
|
-
return this.addStep(registry_default.cancelApi.create(apis, onCancel));
|
|
2150
|
-
}
|
|
2151
|
-
static resetComponent(component, opts) {
|
|
2152
|
-
return EventFlow.start().resetComponent(component, opts);
|
|
2153
|
-
}
|
|
2154
|
-
resetComponent(component, opts) {
|
|
2155
|
-
return this.addStep(registry_default.resetComponent.create(component, opts));
|
|
2156
|
-
}
|
|
2157
|
-
static resetStateVar(state) {
|
|
2158
|
-
return EventFlow.start().resetStateVar(state);
|
|
2159
|
-
}
|
|
2160
|
-
resetStateVar(state) {
|
|
2161
|
-
return this.addStep(registry_default.resetStateVar.create(state));
|
|
2162
|
-
}
|
|
2163
|
-
static setStateVar(stateVarName, opts) {
|
|
2164
|
-
return EventFlow.start().setStateVar(stateVarName, opts);
|
|
2165
|
-
}
|
|
2166
|
-
setStateVar(stateVar, opts) {
|
|
2167
|
-
return this.addStep(registry_default.setStateVar.create(stateVar, opts));
|
|
2168
|
-
}
|
|
2169
|
-
callFunction(component) {
|
|
2170
|
-
return this.addStep(registry_default.callFunction.create(component));
|
|
2171
|
-
}
|
|
2172
|
-
static callFunction(component) {
|
|
2173
|
-
return EventFlow.start().callFunction(component);
|
|
2174
|
-
}
|
|
2175
|
-
static setComponentProperty(component, opts) {
|
|
2176
|
-
return EventFlow.start().setComponentProperty(component, opts);
|
|
2177
|
-
}
|
|
2178
|
-
setComponentProperty(component, opts) {
|
|
2179
|
-
return this.addStep(registry_default.setComponentProperty.create(component, opts));
|
|
2180
|
-
}
|
|
2181
|
-
static showAlert(message, opts) {
|
|
2182
|
-
return EventFlow.start().showAlert(message, opts);
|
|
2183
|
-
}
|
|
2184
|
-
showAlert(_message, _opts) {
|
|
2185
|
-
return this;
|
|
2186
|
-
}
|
|
2187
|
-
static setProfile(profileId, opts) {
|
|
2188
|
-
return EventFlow.start().setProfile(profileId, opts);
|
|
2189
|
-
}
|
|
2190
|
-
setProfile(profileId, opts) {
|
|
2191
|
-
return this.addStep(registry_default.setProfile.create(profileId, opts));
|
|
2192
|
-
}
|
|
2193
|
-
static triggerEvent(eventName, opts) {
|
|
2194
|
-
return EventFlow.start().triggerEvent(eventName, opts);
|
|
2195
|
-
}
|
|
2196
|
-
triggerEvent(eventName, opts) {
|
|
2197
|
-
return this.addStep(registry_default.triggerEvent.create(eventName, opts));
|
|
2198
|
-
}
|
|
2199
|
-
static sequence(eventFlows) {
|
|
2200
|
-
return EventFlow.start().sequence(eventFlows);
|
|
2201
|
-
}
|
|
2202
|
-
sequence(eventFlows) {
|
|
2203
|
-
this.steps = [...this.steps, ...eventFlows.flatMap((eventFlow) => eventFlow.build())];
|
|
2204
|
-
return this;
|
|
2205
|
-
}
|
|
2206
|
-
build() {
|
|
2207
|
-
return this.steps;
|
|
2208
|
-
}
|
|
2209
|
-
};
|
|
2210
|
-
|
|
2211
|
-
//#endregion
|
|
2212
|
-
//#region src/lib/internal-details/lib/evaluator/binding-strings/transform-bindings.ts
|
|
2213
|
-
const transformBindings = (value) => {
|
|
2214
|
-
const body = stringToJS(value.value);
|
|
2215
|
-
return new Function(`return ${body}`);
|
|
2216
|
-
};
|
|
2217
|
-
const toEvalFunc = ([prop, binding]) => {
|
|
2218
|
-
return [prop, transformBindings(binding)];
|
|
2219
|
-
};
|
|
2220
|
-
const stringToJS = (string) => {
|
|
2221
|
-
if (string === void 0 || string === "") return "''";
|
|
2222
|
-
const { stringSegments, jsSnippets } = getDynamicBindings(string);
|
|
2223
|
-
const shouldWrapInParentheses = jsSnippets.length > 1;
|
|
2224
|
-
return stringSegments.map((segment, index) => {
|
|
2225
|
-
if (jsSnippets[index] && jsSnippets[index].length > 0) return shouldWrapInParentheses ? `(${jsSnippets[index]})` : jsSnippets[index];
|
|
2226
|
-
else {
|
|
2227
|
-
const escaped = segment.replaceAll("\\", "\\\\").replaceAll(`\n`, `\\n`);
|
|
2228
|
-
if (segment.includes("'")) return `"${escaped.replaceAll(`"`, "\\\\\"")}"`;
|
|
2229
|
-
else return `'${escaped}'`;
|
|
2230
|
-
}
|
|
2231
|
-
}).join(" + ");
|
|
2232
|
-
};
|
|
2233
|
-
|
|
2234
|
-
//#endregion
|
|
2235
|
-
//#region src/lib/internal-details/lib/evaluator/lazy-function.ts
|
|
2236
|
-
const lazyFunctionSymbol = Symbol("lazy-function");
|
|
2237
|
-
const isLazyFunction = (value) => {
|
|
2238
|
-
return typeof value === "function" && value[lazyFunctionSymbol];
|
|
2239
|
-
};
|
|
2240
|
-
const LazyFunction = (source, args = []) => {
|
|
2241
|
-
const argsObj = getComputedArgsString(args);
|
|
2242
|
-
const func = new Function(argsObj, source);
|
|
2243
|
-
func[lazyFunctionSymbol] = true;
|
|
2244
|
-
return func;
|
|
2245
|
-
};
|
|
2246
|
-
|
|
2247
|
-
//#endregion
|
|
2248
|
-
//#region src/lib/internal-details/lib/evaluator/to-executables-or-values.ts
|
|
2249
|
-
const isFunctionProp = (value) => {
|
|
2250
|
-
return typeof value === "function" && !isLazyFunction(value);
|
|
2251
|
-
};
|
|
2252
|
-
const isDerivedProp = (value) => {
|
|
2253
|
-
return isBindingString(value);
|
|
2254
|
-
};
|
|
2255
|
-
const isEventFlow = (value) => {
|
|
2256
|
-
return value instanceof EventFlow;
|
|
2257
|
-
};
|
|
2258
|
-
const isComputedProp$1 = (value) => {
|
|
2259
|
-
return isComputedProperty(value);
|
|
2260
|
-
};
|
|
2261
|
-
const isNestedInputProp = (value) => {
|
|
2262
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && !isFunctionProp(value) && !isDerivedProp(value) && !isEventFlow(value) && !isDimension(value) && !isComputedProp$1(value) && !isLazyFunction(value);
|
|
2263
|
-
};
|
|
2264
|
-
const toExecutablesOrValues = (props, propsSchema) => {
|
|
2265
|
-
const parentSchema = (propsSchema?.length ?? 0) > 0 ? getParentsSchema(propsSchema) : void 0;
|
|
2266
|
-
const toExecutablesOrValuesInternal = (props$1, basePath = "", inRecordProp = false) => {
|
|
2267
|
-
if (!isNestedInputProp(props$1)) return [[basePath, toExecutableOrValue(basePath, props$1)]];
|
|
2268
|
-
const items = [];
|
|
2269
|
-
Object.entries(props$1).forEach(([prop, value]) => {
|
|
2270
|
-
const path = basePath === "" ? prop : `${basePath}.${prop}`;
|
|
2271
|
-
const itemSchema = propsSchema?.find((schema) => {
|
|
2272
|
-
if (schema.path === path) return true;
|
|
2273
|
-
if (inRecordProp) {
|
|
2274
|
-
const recordKey = getRecordKey(path);
|
|
2275
|
-
if (recordKey) return schema.path === recordKey;
|
|
2276
|
-
}
|
|
2277
|
-
return false;
|
|
2278
|
-
});
|
|
2279
|
-
const isFunction = itemSchema?.dataType === "function" || itemSchema?.dataType === "event";
|
|
2280
|
-
if (isNestedInputProp(value) && shouldTraverseNestedProp(path, propsSchema, parentSchema)) items.push(...toExecutablesOrValuesInternal(value, path, true));
|
|
2281
|
-
else items.push([path, toExecutableOrValue(path, value, isFunction)]);
|
|
2282
|
-
});
|
|
2283
|
-
return items;
|
|
2284
|
-
};
|
|
2285
|
-
return toExecutablesOrValuesInternal(props);
|
|
2286
|
-
};
|
|
2287
|
-
const toExecutableOrValue = (path, value, isAnExternalFunction = false) => {
|
|
2288
|
-
if (isAnExternalFunction) if (isEventFlow(value)) return {
|
|
2289
|
-
value,
|
|
2290
|
-
type: "event"
|
|
2291
|
-
};
|
|
2292
|
-
else return {
|
|
2293
|
-
value,
|
|
2294
|
-
type: "external-function"
|
|
2295
|
-
};
|
|
2296
|
-
else if (isFunctionProp(value)) return {
|
|
2297
|
-
value,
|
|
2298
|
-
type: "function"
|
|
2299
|
-
};
|
|
2300
|
-
else if (isDerivedProp(value)) return {
|
|
2301
|
-
value: toEvalFunc([path, value])[1],
|
|
2302
|
-
type: "mustache-bindings"
|
|
2303
|
-
};
|
|
2304
|
-
else if (isComputedProp$1(value)) return {
|
|
2305
|
-
value: value.value,
|
|
2306
|
-
type: "normal"
|
|
2307
|
-
};
|
|
2308
|
-
else if (isLazyFunction(value)) return {
|
|
2309
|
-
value,
|
|
2310
|
-
type: "lazy-function"
|
|
2311
|
-
};
|
|
2312
|
-
return {
|
|
2313
|
-
value,
|
|
2314
|
-
type: "normal"
|
|
2315
|
-
};
|
|
2316
|
-
};
|
|
2317
|
-
const shouldTraverseNestedProp = (path, propsSchema, managedPropsList) => {
|
|
2318
|
-
if (managedPropsList === void 0) return true;
|
|
2319
|
-
const pathSegments = path.split(".");
|
|
2320
|
-
const shouldTraverse = managedPropsList.map((prop) => {
|
|
2321
|
-
return prop.path.split(".").slice(0, pathSegments.length);
|
|
2322
|
-
}).some((prop) => {
|
|
2323
|
-
if (prop.length !== pathSegments.length) return false;
|
|
2324
|
-
return prop.every((segment, index) => {
|
|
2325
|
-
if (segment === RECORD_PATH_IDENTIFIER) return true;
|
|
2326
|
-
return segment === pathSegments[index];
|
|
2327
|
-
});
|
|
2328
|
-
});
|
|
2329
|
-
if (!shouldTraverse && propsSchema) {
|
|
2330
|
-
if (propsSchema.some((prop) => prop.path.startsWith(`${path}.${RECORD_PATH_IDENTIFIER}`))) return true;
|
|
2331
|
-
}
|
|
2332
|
-
return shouldTraverse;
|
|
2333
|
-
};
|
|
2334
|
-
const getParentsSchema = (propsSchema) => propsSchema?.map((prop) => prop.path.split(".").slice(0, -1).join(".")).map((parentPath) => ({ path: parentPath })).filter((prop) => prop.path !== "");
|
|
2335
|
-
const getRecordKey = (path) => {
|
|
2336
|
-
const [parentKey, _maybeTheRecordKey, ...rest] = path.split(".");
|
|
2337
|
-
if (rest.length == 0) return;
|
|
2338
|
-
return [
|
|
2339
|
-
parentKey,
|
|
2340
|
-
RECORD_PATH_IDENTIFIER,
|
|
2341
|
-
rest.join(".")
|
|
2342
|
-
].join(".");
|
|
2343
|
-
};
|
|
2344
|
-
|
|
2345
|
-
//#endregion
|
|
2346
|
-
//#region src/lib/internal-details/lib/evaluator/entity-manager.ts
|
|
2347
|
-
const GLOBAL_SCOPE_ID = "Global";
|
|
2348
|
-
const PROTECTED_KEYS = new Set([
|
|
2349
|
-
"type",
|
|
2350
|
-
"isAnonymous",
|
|
2351
|
-
"scopeId",
|
|
2352
|
-
"name"
|
|
2353
|
-
]);
|
|
2354
|
-
const isNestedPath = (path) => path.includes(".");
|
|
2355
|
-
const buildEntityScope = (id, name) => ({
|
|
2356
|
-
id,
|
|
2357
|
-
name,
|
|
2358
|
-
entities: {},
|
|
2359
|
-
entityMeta: {},
|
|
2360
|
-
childScopes: /* @__PURE__ */ new Set(),
|
|
2361
|
-
idToName: {},
|
|
2362
|
-
getEntity(name$1, options) {
|
|
2363
|
-
const entity = this.entities[name$1.value];
|
|
2364
|
-
if (!(options?.useSuspense ?? false) && entity) return sanitizeEntity(entity);
|
|
2365
|
-
return entity;
|
|
2366
|
-
},
|
|
2367
|
-
getEntityMeta(name$1, options) {
|
|
2368
|
-
const entityMeta = this.entityMeta[name$1.value];
|
|
2369
|
-
if (!(options?.useSuspense ?? false) && entityMeta) return sanitizeEntity(entityMeta);
|
|
2370
|
-
return entityMeta;
|
|
2371
|
-
},
|
|
2372
|
-
getEntityName(id$1) {
|
|
2373
|
-
return this.idToName[id$1];
|
|
2374
|
-
},
|
|
2375
|
-
setEntityName(id$1, name$1, currentName) {
|
|
2376
|
-
this.idToName[id$1] = name$1;
|
|
2377
|
-
if (currentName) {
|
|
2378
|
-
const entity = this.entities[currentName.value];
|
|
2379
|
-
delete this.entities[currentName.value];
|
|
2380
|
-
this.entities[name$1.value] = entity;
|
|
2381
|
-
const entityMeta = this.entityMeta[currentName.value];
|
|
2382
|
-
delete this.entityMeta[currentName.value];
|
|
2383
|
-
this.entityMeta[name$1.value] = entityMeta;
|
|
2384
|
-
entity.name = name$1.value;
|
|
2385
|
-
entity.isAnonymous = name$1.isAnonymous;
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
});
|
|
2389
|
-
var EntityManager = class {
|
|
2390
|
-
state;
|
|
2391
|
-
allScopes = {};
|
|
2392
|
-
atoms = {};
|
|
2393
|
-
validationCache = {};
|
|
2394
|
-
dirComputeEngine;
|
|
2395
|
-
evalComputeEngine;
|
|
2396
|
-
constructor(componentRegistry, options) {
|
|
2397
|
-
this.componentRegistry = componentRegistry;
|
|
2398
|
-
this.state = observable(buildEntityScope(GLOBAL_SCOPE_ID));
|
|
2399
|
-
this.allScopes = observable({ [GLOBAL_SCOPE_ID]: this.state }, void 0);
|
|
2400
|
-
this.validationCache = observable({});
|
|
2401
|
-
this.dirComputeEngine = new DirectComputeEngine();
|
|
2402
|
-
this.evalComputeEngine = new EvalComputeEngine();
|
|
2403
|
-
makeObservable(this, {
|
|
2404
|
-
createScope: action,
|
|
2405
|
-
deleteScope: action,
|
|
2406
|
-
setValidationState: action,
|
|
2407
|
-
getFullState: computed,
|
|
2408
|
-
getValidationState: computed,
|
|
2409
|
-
createEntity: action,
|
|
2410
|
-
updateEntity: action,
|
|
2411
|
-
deleteEntity: action,
|
|
2412
|
-
resetEntity: action,
|
|
2413
|
-
renameEntity: action,
|
|
2414
|
-
runCode: action,
|
|
2415
|
-
computeValue: action
|
|
2416
|
-
});
|
|
2417
|
-
if (options?.devtools) registerStores({ Entities: this.state });
|
|
2418
|
-
}
|
|
2419
|
-
getEntity(scopeId, name, options) {
|
|
2420
|
-
return this.getState(scopeId, options)[name.value];
|
|
2421
|
-
}
|
|
2422
|
-
getEntityById(scopeId, id, options) {
|
|
2423
|
-
const scope = this.getScope(scopeId);
|
|
2424
|
-
const name = scope.getEntityName(id);
|
|
2425
|
-
return name ? scope.getEntity(name, options) : void 0;
|
|
2426
|
-
}
|
|
2427
|
-
getState(scopeId, options) {
|
|
2428
|
-
const scope = this.getScope(scopeId);
|
|
2429
|
-
const useSuspense = options?.useSuspense ?? false;
|
|
2430
|
-
if (options?.includeParentScopes ?? false) return createScopeProxy(this.getAccessibleScopes(scopeId), useSuspense);
|
|
2431
|
-
return createScopeProxy([scope], useSuspense);
|
|
2432
|
-
}
|
|
2433
|
-
getScopeName(scopeId) {
|
|
2434
|
-
return this.getScope(scopeId).name ?? "";
|
|
2435
|
-
}
|
|
2436
|
-
setValidationState(entityId, property, state) {
|
|
2437
|
-
this.validationCache[`${entityId}-${property}`] = state;
|
|
2438
|
-
}
|
|
2439
|
-
get getValidationState() {
|
|
2440
|
-
return this.validationCache;
|
|
2441
|
-
}
|
|
2442
|
-
get getFullState() {
|
|
2443
|
-
const entities = {};
|
|
2444
|
-
const processScope = (scope) => {
|
|
2445
|
-
for (const name of Object.keys(scope.entities)) {
|
|
2446
|
-
const entity = this.getEntity(scope.id, getName(name));
|
|
2447
|
-
const id = entity[SOURCE_ID_ATTRIBUTE];
|
|
2448
|
-
const isNameBasedEntity = entity.type === SbEntityType.VARIABLE || entity.type === SbEntityType.API || entity.type === SbEntityType.TIMER || entity.type === "global" || entity.type === "theme";
|
|
2449
|
-
if (!id && !isNameBasedEntity) console.warn(`Entity has no source id. Type: ${entity?.type}`);
|
|
2450
|
-
if (isNameBasedEntity) entities[name] = entity;
|
|
2451
|
-
else entities[id] = entity;
|
|
2452
|
-
}
|
|
2453
|
-
for (const childScopeId of scope.childScopes) processScope(this.getScope(childScopeId));
|
|
2454
|
-
};
|
|
2455
|
-
processScope(this.state);
|
|
2456
|
-
return entities;
|
|
2457
|
-
}
|
|
2458
|
-
getAccessibleScopes(scopeId) {
|
|
2459
|
-
const path = [];
|
|
2460
|
-
let currentScope = this.state;
|
|
2461
|
-
const isDescendant = (scope, scopeId$1) => {
|
|
2462
|
-
if (scope.id === scopeId$1) return true;
|
|
2463
|
-
return Array.from(scope.childScopes).some((childScopeId) => {
|
|
2464
|
-
return isDescendant(this.getScope(childScopeId), scopeId$1);
|
|
2465
|
-
});
|
|
2466
|
-
};
|
|
2467
|
-
while (currentScope) {
|
|
2468
|
-
path.unshift(currentScope);
|
|
2469
|
-
if (currentScope.id === scopeId) break;
|
|
2470
|
-
currentScope = Array.from(currentScope.childScopes).map((childScopeId) => this.getScope(childScopeId)).find((childScope) => childScope.id === scopeId || isDescendant(childScope, scopeId));
|
|
2471
|
-
}
|
|
2472
|
-
if (!currentScope) throw new Error(`Scope with id ${scopeId} not found`);
|
|
2473
|
-
return path;
|
|
2474
|
-
}
|
|
2475
|
-
getScope(scopeId) {
|
|
2476
|
-
const scope = this.allScopes[scopeId];
|
|
2477
|
-
if (!scope) throw new Error(`Scope with id ${scopeId} not found`);
|
|
2478
|
-
return scope;
|
|
2479
|
-
}
|
|
2480
|
-
getPossibleScope(scopeId) {
|
|
2481
|
-
try {
|
|
2482
|
-
return this.getScope(scopeId);
|
|
2483
|
-
} catch (_e) {
|
|
2484
|
-
return;
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
createScope(params) {
|
|
2488
|
-
const { name, parentScopeId } = params;
|
|
2489
|
-
const scopeId = params.scopeId ?? nameGenerator();
|
|
2490
|
-
if (this.getPossibleScope(scopeId)) return scopeId;
|
|
2491
|
-
const parentScope = parentScopeId ? this.getScope(parentScopeId) : this.state;
|
|
2492
|
-
const newScope = buildEntityScope(scopeId, name);
|
|
2493
|
-
parentScope.childScopes.add(scopeId);
|
|
2494
|
-
this.allScopes[scopeId] = newScope;
|
|
2495
|
-
return scopeId;
|
|
2496
|
-
}
|
|
2497
|
-
deleteScope(params) {
|
|
2498
|
-
const { scopeId } = params;
|
|
2499
|
-
const scopes = this.getAccessibleScopes(scopeId);
|
|
2500
|
-
if (scopes.length > 1) {
|
|
2501
|
-
delete this.allScopes[scopeId];
|
|
2502
|
-
scopes[1].childScopes.delete(scopeId);
|
|
2503
|
-
delete this.atoms[scopeId];
|
|
2504
|
-
} else throw new Error(`Cannot delete root scope`);
|
|
2505
|
-
}
|
|
2506
|
-
createEntity(params) {
|
|
2507
|
-
const { scopeId, name, props, type, instanceId } = params;
|
|
2508
|
-
this.createEntityStructure(scopeId, name, props, type, instanceId);
|
|
2509
|
-
return name;
|
|
2510
|
-
}
|
|
2511
|
-
createEntityStructure(scopeId, name, props, type, instanceId) {
|
|
2512
|
-
const scope = this.getScope(scopeId);
|
|
2513
|
-
scope.entities[name.value] = {
|
|
2514
|
-
type,
|
|
2515
|
-
isAnonymous: name.isAnonymous,
|
|
2516
|
-
scopeId,
|
|
2517
|
-
name: name.value
|
|
2518
|
-
};
|
|
2519
|
-
scope.entityMeta[name.value] = { type };
|
|
2520
|
-
if (instanceId) scope.idToName[instanceId] = name;
|
|
2521
|
-
else if (!instanceId && type === SbEntityType.API) scope.idToName[name.value] = name;
|
|
2522
|
-
const managedPropsForType = this.componentRegistry.getManagedProps(type);
|
|
2523
|
-
if (managedPropsForType.length === 0) console.log(`ALERT: No managed properties found for type ${type},
|
|
2524
|
-
this means the entire item will have leaf properties (more expensive)`);
|
|
2525
|
-
const internalProps = this.componentRegistry.getInternalProps(type);
|
|
2526
|
-
for (const internalProp of internalProps) this.addInternalProperty(scopeId, name, internalProp);
|
|
2527
|
-
const functionalProps = toExecutablesOrValues(props, managedPropsForType);
|
|
2528
|
-
const addedProperties = /* @__PURE__ */ new Set();
|
|
2529
|
-
for (const [prop, value] of functionalProps) {
|
|
2530
|
-
this.addProperty(scopeId, name, prop, value);
|
|
2531
|
-
addedProperties.add(prop);
|
|
2532
|
-
}
|
|
2533
|
-
this.addMissingProps(managedPropsForType, addedProperties, scopeId, name);
|
|
2534
|
-
}
|
|
2535
|
-
addInternalProperty(scopeId, name, internalProp) {
|
|
2536
|
-
const entity = this.getScope(scopeId).getEntity(name);
|
|
2537
|
-
const { path, factory } = internalProp;
|
|
2538
|
-
const instance = factory.call(entity);
|
|
2539
|
-
Object.defineProperty(entity, path, {
|
|
2540
|
-
value: instance,
|
|
2541
|
-
writable: false,
|
|
2542
|
-
enumerable: false,
|
|
2543
|
-
configurable: false
|
|
2544
|
-
});
|
|
2545
|
-
}
|
|
2546
|
-
addProperty(scopeId, name, prop, eov) {
|
|
2547
|
-
if (prop.split(".").includes(RECORD_PATH_IDENTIFIER)) return;
|
|
2548
|
-
const entity = this.getScope(scopeId).getEntity(name);
|
|
2549
|
-
const entityMeta = this.getScope(scopeId).getEntityMeta(name);
|
|
2550
|
-
const pathSegments = prop.split(".");
|
|
2551
|
-
const isNested = pathSegments.length > 1;
|
|
2552
|
-
const finalSegment = pathSegments.pop() || "";
|
|
2553
|
-
const parentSegments = isNested ? pathSegments : [];
|
|
2554
|
-
let propParent = entity;
|
|
2555
|
-
if (isNested) {
|
|
2556
|
-
let metaParent = entityMeta;
|
|
2557
|
-
for (const segment of parentSegments) {
|
|
2558
|
-
if (!(segment in propParent)) {
|
|
2559
|
-
propParent[segment] = {};
|
|
2560
|
-
metaParent[segment] = {};
|
|
2561
|
-
}
|
|
2562
|
-
propParent = propParent[segment];
|
|
2563
|
-
metaParent = metaParent[segment];
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
const getMetaParent = () => isNested ? get(entityMeta, parentSegments) : entityMeta;
|
|
2567
|
-
const snapshot = this.getState.bind(this);
|
|
2568
|
-
const isComputed = typeof eov.value === "function" && eov.type !== "function";
|
|
2569
|
-
const computeEngine = eov.type === "mustache-bindings" || eov.type === "lazy-function" ? this.evalComputeEngine : this.dirComputeEngine;
|
|
2570
|
-
const entityType = entity.type;
|
|
2571
|
-
if (eov.type === "external-function") {
|
|
2572
|
-
const finalFunction = async (...args) => this.dirComputeEngine.compute({
|
|
2573
|
-
snapshot: snapshot(scopeId, { useSuspense: true }),
|
|
2574
|
-
func: eov.value,
|
|
2575
|
-
path: prop,
|
|
2576
|
-
args,
|
|
2577
|
-
excludeState: true,
|
|
2578
|
-
get entityName() {
|
|
2579
|
-
return getName(entity.name);
|
|
2580
|
-
}
|
|
2581
|
-
});
|
|
2582
|
-
entity[prop] = finalFunction;
|
|
2583
|
-
return;
|
|
2584
|
-
} else if (eov.type === "event") {
|
|
2585
|
-
const finalFunction = async (...args) => {
|
|
2586
|
-
await run_event_handlers_default({
|
|
2587
|
-
flow: eov.value,
|
|
2588
|
-
scopeId,
|
|
2589
|
-
additionalContext: args[0],
|
|
2590
|
-
get name() {
|
|
2591
|
-
return getName(entity.name);
|
|
2592
|
-
}
|
|
2593
|
-
});
|
|
2594
|
-
};
|
|
2595
|
-
if (isNested) propParent[finalSegment] = finalFunction;
|
|
2596
|
-
else entity[prop] = finalFunction;
|
|
2597
|
-
return;
|
|
2598
|
-
}
|
|
2599
|
-
let finalProp = prop;
|
|
2600
|
-
if (isNested) finalProp = this.componentRegistry.getPropertyWithRecordIdentifier(entityType, prop);
|
|
2601
|
-
const managedProp = this.componentRegistry.getManagedProps(entityType).find((p) => p.path === finalProp);
|
|
2602
|
-
const getValue = computed(() => {
|
|
2603
|
-
if (managedProp?.isExternallyReadable === false) return;
|
|
2604
|
-
let ret = null;
|
|
2605
|
-
try {
|
|
2606
|
-
const metaParent = getMetaParent();
|
|
2607
|
-
if (metaParent && finalSegment in metaParent) ret = metaParent[finalSegment];
|
|
2608
|
-
else if (isComputed) if (managedProp?.contextual) ret = function(context$1) {
|
|
2609
|
-
return computeEngine.compute({
|
|
2610
|
-
snapshot: snapshot(scopeId, { useSuspense: true }),
|
|
2611
|
-
entityName: name,
|
|
2612
|
-
func: eov.value,
|
|
2613
|
-
path: prop,
|
|
2614
|
-
args: [context$1],
|
|
2615
|
-
excludeState: true
|
|
2616
|
-
});
|
|
2617
|
-
};
|
|
2618
|
-
else ret = computeEngine.compute({
|
|
2619
|
-
snapshot: snapshot(scopeId, { useSuspense: true }),
|
|
2620
|
-
entityName: name,
|
|
2621
|
-
func: eov.value,
|
|
2622
|
-
path: prop
|
|
2623
|
-
});
|
|
2624
|
-
else ret = eov.value;
|
|
2625
|
-
if (managedProp?.validate && typeof ret !== "function") {
|
|
2626
|
-
const entity$1 = snapshot(scopeId, { useSuspense: true })[name.value];
|
|
2627
|
-
const validationResult = managedProp.validate(ret, entity$1);
|
|
2628
|
-
if (entity$1?.[SOURCE_ID_ATTRIBUTE]) this.setValidationState(entity$1[SOURCE_ID_ATTRIBUTE], prop, {
|
|
2629
|
-
isValid: validationResult.valid,
|
|
2630
|
-
message: validationResult.valid ? "" : validationResult.message,
|
|
2631
|
-
invalidValue: validationResult.valid ? void 0 : validationResult.invalidValue
|
|
2632
|
-
});
|
|
2633
|
-
if (!validationResult.valid) return;
|
|
2634
|
-
ret = validationResult.result;
|
|
2635
|
-
}
|
|
2636
|
-
} catch (e) {
|
|
2637
|
-
if (e instanceof Promise) throw e;
|
|
2638
|
-
console.log("Could not compute property value");
|
|
2639
|
-
return;
|
|
2640
|
-
}
|
|
2641
|
-
return ret;
|
|
2642
|
-
});
|
|
2643
|
-
const setValue = (value) => {
|
|
2644
|
-
if (managedProp?.isExternallySettable === false) {
|
|
2645
|
-
console.warn(`The property "${finalSegment}" on entity "${name.value}" is not settable, it will be ignored.`);
|
|
2646
|
-
return;
|
|
2647
|
-
}
|
|
2648
|
-
const metaParent = getMetaParent();
|
|
2649
|
-
metaParent[finalSegment] = value;
|
|
2650
|
-
};
|
|
2651
|
-
const { atom, isNew } = this.getOrCreateAtom(scopeId, name, prop);
|
|
2652
|
-
Object.defineProperty(propParent, finalSegment, {
|
|
2653
|
-
get: () => {
|
|
2654
|
-
atom.reportObserved();
|
|
2655
|
-
return getValue.get();
|
|
2656
|
-
},
|
|
2657
|
-
set: action((value) => {
|
|
2658
|
-
setValue(value);
|
|
2659
|
-
atom.reportChanged();
|
|
2660
|
-
}),
|
|
2661
|
-
enumerable: true,
|
|
2662
|
-
configurable: true
|
|
2663
|
-
});
|
|
2664
|
-
if (!isNew) atom.reportChanged();
|
|
2665
|
-
}
|
|
2666
|
-
deleteEntity(params) {
|
|
2667
|
-
const scope = this.getScope(params.scopeId);
|
|
2668
|
-
delete scope.entities[params.name.value];
|
|
2669
|
-
delete scope.entityMeta[params.name.value];
|
|
2670
|
-
delete this.atoms?.[params.scopeId]?.[params.name.value];
|
|
2671
|
-
}
|
|
2672
|
-
deleteProperty(params) {
|
|
2673
|
-
const { scopeId, name, prop } = params;
|
|
2674
|
-
if (prop.split(".").includes(RECORD_PATH_IDENTIFIER)) return;
|
|
2675
|
-
const scope = this.getScope(scopeId);
|
|
2676
|
-
const entity = scope.getEntity(name);
|
|
2677
|
-
const entityMeta = scope.getEntityMeta(name);
|
|
2678
|
-
if (!entity || !entityMeta) {
|
|
2679
|
-
console.warn(`Entity ${name.value} not found in scope ${scopeId}`);
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
const pathSegments = prop.split(".");
|
|
2683
|
-
const isNested = pathSegments.length > 1;
|
|
2684
|
-
const finalSegment = pathSegments.pop() || "";
|
|
2685
|
-
const parentSegments = isNested ? pathSegments : [];
|
|
2686
|
-
let propParent = entity;
|
|
2687
|
-
let metaParent = entityMeta;
|
|
2688
|
-
if (isNested) for (const segment of parentSegments) {
|
|
2689
|
-
if (!(segment in propParent) || !(segment in metaParent)) return;
|
|
2690
|
-
propParent = propParent[segment];
|
|
2691
|
-
metaParent = metaParent[segment];
|
|
2692
|
-
}
|
|
2693
|
-
if (finalSegment in propParent) delete propParent[finalSegment];
|
|
2694
|
-
if (finalSegment in metaParent) delete metaParent[finalSegment];
|
|
2695
|
-
if (this.atoms[scopeId]?.[name.value]?.[prop]) delete this.atoms[scopeId][name.value][prop];
|
|
2696
|
-
}
|
|
2697
|
-
deleteObsoleteNestedProperties(scopeId, name, nextProps, entity) {
|
|
2698
|
-
for (const [propKey, propValue] of Object.entries(nextProps)) if (propValue && typeof propValue === "object" && !Array.isArray(propValue) && !isReactElement(propValue)) {
|
|
2699
|
-
const entityPropValue = entity[propKey];
|
|
2700
|
-
if (!entityPropValue || typeof entityPropValue !== "object" || Array.isArray(entityPropValue) || isReactElement(entityPropValue)) continue;
|
|
2701
|
-
const currentKeys = new Set(Object.keys(propValue));
|
|
2702
|
-
const keysToDelete = Object.keys(entityPropValue).filter((key) => !currentKeys.has(key));
|
|
2703
|
-
for (const keyToDelete of keysToDelete) {
|
|
2704
|
-
const obsoleteObj = entityPropValue[keyToDelete];
|
|
2705
|
-
if (obsoleteObj && typeof obsoleteObj === "object" && !isReactElement(obsoleteObj)) {
|
|
2706
|
-
const nestedProps = this.getNestedPropertyPaths(`${propKey}.${keyToDelete}`, obsoleteObj);
|
|
2707
|
-
for (const nestedProp of nestedProps) this.deleteProperty({
|
|
2708
|
-
scopeId,
|
|
2709
|
-
name,
|
|
2710
|
-
prop: nestedProp
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
this.deleteProperty({
|
|
2714
|
-
scopeId,
|
|
2715
|
-
name,
|
|
2716
|
-
prop: `${propKey}.${keyToDelete}`
|
|
2717
|
-
});
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2721
|
-
getNestedPropertyPaths(basePath, obj) {
|
|
2722
|
-
try {
|
|
2723
|
-
const paths = [];
|
|
2724
|
-
if (obj && typeof obj === "object" && !Array.isArray(obj) && !isReactElement(obj)) for (const [key, value] of Object.entries(obj)) {
|
|
2725
|
-
const currentPath = `${basePath}.${key}`;
|
|
2726
|
-
paths.push(currentPath);
|
|
2727
|
-
if (value && typeof value === "object" && !Array.isArray(value)) paths.push(...this.getNestedPropertyPaths(currentPath, value));
|
|
2728
|
-
}
|
|
2729
|
-
return paths;
|
|
2730
|
-
} catch (_e) {
|
|
2731
|
-
return [];
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
deleteEntityById(params) {
|
|
2735
|
-
const name = this.getScope(params.scopeId).getEntityName(params.entityId);
|
|
2736
|
-
if (name) this.deleteEntity({
|
|
2737
|
-
name,
|
|
2738
|
-
scopeId: params.scopeId
|
|
2739
|
-
});
|
|
2740
|
-
}
|
|
2741
|
-
resetEntity(params) {
|
|
2742
|
-
const { name, key, onlyMetaProps } = params;
|
|
2743
|
-
const entityMeta = this.getScope(params.scopeId).getEntityMeta(name);
|
|
2744
|
-
if (key) {
|
|
2745
|
-
if (key in entityMeta) delete entityMeta[key];
|
|
2746
|
-
} else {
|
|
2747
|
-
let metaPropsNames = [];
|
|
2748
|
-
if (onlyMetaProps) metaPropsNames = this.componentRegistry.getManagedProps(entityMeta.type).filter((p) => p.isMetaProp).map((p) => p.path);
|
|
2749
|
-
for (const prop of Object.keys(entityMeta)) if (!onlyMetaProps || onlyMetaProps && metaPropsNames.includes(prop)) delete entityMeta[prop];
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
updateEntity(params) {
|
|
2753
|
-
const { scopeId, name, props, instanceId } = params;
|
|
2754
|
-
const scope = this.getScope(scopeId);
|
|
2755
|
-
const entity = scope.getEntity(name);
|
|
2756
|
-
if (!entity) {
|
|
2757
|
-
console.warn(`Entity with name ${name.value} not found on scope ${scopeId}. This shouldn't happen, so there is a bug somewhere that you need to track down`);
|
|
2758
|
-
return;
|
|
2759
|
-
}
|
|
2760
|
-
const type = entity.type;
|
|
2761
|
-
if (instanceId) scope.idToName[instanceId] = name;
|
|
2762
|
-
this.deleteObsoleteNestedProperties(scopeId, name, props, entity);
|
|
2763
|
-
const managedPropsForType = this.componentRegistry.getManagedProps(type);
|
|
2764
|
-
const internalProps = this.componentRegistry.getInternalProps(type);
|
|
2765
|
-
const functionalProps = toExecutablesOrValues(props, managedPropsForType);
|
|
2766
|
-
const addedProperties = /* @__PURE__ */ new Set();
|
|
2767
|
-
for (const [prop, value] of functionalProps) if (value.value != void 0) {
|
|
2768
|
-
this.addProperty(scopeId, name, prop, value);
|
|
2769
|
-
addedProperties.add(prop);
|
|
2770
|
-
}
|
|
2771
|
-
Object.keys(entity).filter((key) => {
|
|
2772
|
-
const propInfo = managedPropsForType.find((p) => p.path === key);
|
|
2773
|
-
const isInternalProp = internalProps.some((p) => p.path === key);
|
|
2774
|
-
return !(key in props) && !PROTECTED_KEYS.has(key) && propInfo?.dataType !== "function" && !isInternalProp;
|
|
2775
|
-
}).forEach((key) => delete entity[key]);
|
|
2776
|
-
this.addMissingProps(managedPropsForType, addedProperties, scopeId, name);
|
|
2777
|
-
}
|
|
2778
|
-
addMissingProps(managedProps, addedProperties, scopeId, name) {
|
|
2779
|
-
const entity = this.getScope(scopeId).getEntity(name);
|
|
2780
|
-
for (const prop of managedProps) {
|
|
2781
|
-
const isComputed = typeof prop.default === "function" && prop.dataType !== "function";
|
|
2782
|
-
if (get(entity, prop.path) == null && !addedProperties.has(prop.path) && (!isNestedPath(prop.path) || prop.default !== void 0)) if (isComputed) this.addProperty(scopeId, name, prop.path, {
|
|
2783
|
-
value: prop.default,
|
|
2784
|
-
type: "normal"
|
|
2785
|
-
});
|
|
2786
|
-
else this.addProperty(scopeId, name, prop.path, toExecutableOrValue(prop.path, prop.default !== void 0 ? fastClone(prop.default) : void 0, prop.dataType === "function" || prop.dataType === "event"));
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
renameEntity(params) {
|
|
2790
|
-
const { scopeId, instanceId, newName, isDuplicate } = params;
|
|
2791
|
-
const scope = this.getScope(scopeId);
|
|
2792
|
-
const existingName = scope.getEntityName(instanceId);
|
|
2793
|
-
if (!existingName && !isDuplicate) {
|
|
2794
|
-
console.warn(`Entity with id ${instanceId} not found`);
|
|
2795
|
-
return;
|
|
2796
|
-
}
|
|
2797
|
-
scope.setEntityName(instanceId, newName, existingName);
|
|
2798
|
-
}
|
|
2799
|
-
runCode(params) {
|
|
2800
|
-
const { scopeId, name, func, args, excludeState } = params;
|
|
2801
|
-
const state = this.getState(scopeId);
|
|
2802
|
-
this.dirComputeEngine.compute({
|
|
2803
|
-
snapshot: state,
|
|
2804
|
-
entityName: name,
|
|
2805
|
-
func,
|
|
2806
|
-
args,
|
|
2807
|
-
excludeState
|
|
2808
|
-
});
|
|
2809
|
-
}
|
|
2810
|
-
computeValue(params) {
|
|
2811
|
-
const { scopeId, name, value, validator, args } = params;
|
|
2812
|
-
const { value: transformedValue, type } = toExecutableOrValue(name.value, value);
|
|
2813
|
-
const isComputed = typeof transformedValue === "function" && type !== "function";
|
|
2814
|
-
const computeEngine = type === "mustache-bindings" || type === "lazy-function" ? this.evalComputeEngine : this.dirComputeEngine;
|
|
2815
|
-
const result = isComputed ? computeEngine.compute({
|
|
2816
|
-
snapshot: this.getState(scopeId),
|
|
2817
|
-
entityName: name,
|
|
2818
|
-
func: transformedValue,
|
|
2819
|
-
args,
|
|
2820
|
-
excludeState: true
|
|
2821
|
-
}) : transformedValue;
|
|
2822
|
-
if (validator) {
|
|
2823
|
-
const vResult = validator(result, this.getEntity(scopeId, name));
|
|
2824
|
-
if (!vResult.valid) throw Error(`Validation error for ${name.value}: ${vResult.message}`);
|
|
2825
|
-
return vResult.result;
|
|
2826
|
-
}
|
|
2827
|
-
return result;
|
|
2828
|
-
}
|
|
2829
|
-
getOrCreateAtom(scopeId, name, prop) {
|
|
2830
|
-
const isNew = !this.atoms[scopeId]?.[name.value]?.[prop];
|
|
2831
|
-
const scopeAtoms = this.atoms[scopeId] ??= {};
|
|
2832
|
-
const entityAtoms = scopeAtoms[name.value] ??= {};
|
|
2833
|
-
return {
|
|
2834
|
-
atom: entityAtoms[prop] ??= createAtom(`${scopeId}-${name.value}:${prop}`),
|
|
2835
|
-
isNew
|
|
2836
|
-
};
|
|
2837
|
-
}
|
|
2838
|
-
};
|
|
2839
|
-
|
|
2840
|
-
//#endregion
|
|
2841
|
-
//#region src/lib/internal-details/location-store.ts
|
|
2842
|
-
var LocationStore = class {
|
|
2843
|
-
route;
|
|
2844
|
-
rootStore;
|
|
2845
|
-
constructor(rootStore) {
|
|
2846
|
-
this.rootStore = rootStore;
|
|
2847
|
-
}
|
|
2848
|
-
@action updateLocation(location, routes, params) {
|
|
2849
|
-
this.route = this.locationToRouteInfo(location, routes, params);
|
|
2850
|
-
this.sendLocationToEditor();
|
|
2851
|
-
this.updateGlobalScopeUrl();
|
|
2852
|
-
}
|
|
2853
|
-
sendLocationToEditor() {
|
|
2854
|
-
if (!this.route) return;
|
|
2855
|
-
editorBridge.updateRoute(this.route);
|
|
2856
|
-
}
|
|
2857
|
-
async updateGlobalScopeUrl() {
|
|
2858
|
-
if (!this.route) return;
|
|
2859
|
-
const globalName = getName("Global");
|
|
2860
|
-
const currentGlobalEntity = this.rootStore.entityManager.getEntity(GLOBAL_SCOPE_ID, globalName);
|
|
2861
|
-
this.rootStore.entityManager.updateEntity({
|
|
2862
|
-
scopeId: GLOBAL_SCOPE_ID,
|
|
2863
|
-
name: globalName,
|
|
2864
|
-
props: {
|
|
2865
|
-
...currentGlobalEntity,
|
|
2866
|
-
URL: {
|
|
2867
|
-
...currentGlobalEntity.URL,
|
|
2868
|
-
...this.route
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
});
|
|
2872
|
-
}
|
|
2873
|
-
locationToRouteInfo(location, routes, params) {
|
|
2874
|
-
const route = routes.find((route$1) => !!route$1.path && matchPath(route$1.path, location.pathname));
|
|
2875
|
-
if (!route?.path) return;
|
|
2876
|
-
return {
|
|
2877
|
-
hash: location.hash,
|
|
2878
|
-
pathname: location.pathname,
|
|
2879
|
-
queryParams: getQueryParams(location.search),
|
|
2880
|
-
route: route.path,
|
|
2881
|
-
routeParams: params
|
|
2882
|
-
};
|
|
2883
|
-
}
|
|
2884
|
-
};
|
|
2885
|
-
|
|
2886
|
-
//#endregion
|
|
2887
|
-
//#region src/lib/user-facing/assets/icons/system-danger.svg
|
|
2888
|
-
var _path$3;
|
|
2889
|
-
function _extends$3() {
|
|
2890
|
-
return _extends$3 = Object.assign ? Object.assign.bind() : function(n) {
|
|
2891
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
2892
|
-
var t = arguments[e];
|
|
2893
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2894
|
-
}
|
|
2895
|
-
return n;
|
|
2896
|
-
}, _extends$3.apply(null, arguments);
|
|
2897
|
-
}
|
|
2898
|
-
var SvgSystemDanger = function SvgSystemDanger$1(props) {
|
|
2899
|
-
return /* @__PURE__ */ React$1.createElement("svg", _extends$3({
|
|
2900
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2901
|
-
width: 16,
|
|
2902
|
-
height: 16,
|
|
2903
|
-
fill: "none"
|
|
2904
|
-
}, props), _path$3 || (_path$3 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2905
|
-
fill: "currentColor",
|
|
2906
|
-
fillRule: "evenodd",
|
|
2907
|
-
d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m.75-10a.75.75 0 0 0-1.5 0v3a.75.75 0 1 0 1.5 0zM8 9.75a1 1 0 1 0 0 2 1 1 0 0 0 0-2",
|
|
2908
|
-
clipRule: "evenodd"
|
|
2909
|
-
})));
|
|
2910
|
-
};
|
|
2911
|
-
var system_danger_default = SvgSystemDanger;
|
|
2912
|
-
|
|
2913
|
-
//#endregion
|
|
2914
|
-
//#region src/lib/user-facing/assets/icons/system-error.svg
|
|
2915
|
-
var _path$2;
|
|
2916
|
-
function _extends$2() {
|
|
2917
|
-
return _extends$2 = Object.assign ? Object.assign.bind() : function(n) {
|
|
2918
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
2919
|
-
var t = arguments[e];
|
|
2920
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2921
|
-
}
|
|
2922
|
-
return n;
|
|
2923
|
-
}, _extends$2.apply(null, arguments);
|
|
2924
|
-
}
|
|
2925
|
-
var SvgSystemError = function SvgSystemError$1(props) {
|
|
2926
|
-
return /* @__PURE__ */ React$1.createElement("svg", _extends$2({
|
|
2927
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2928
|
-
width: 16,
|
|
2929
|
-
height: 16,
|
|
2930
|
-
fill: "none"
|
|
2931
|
-
}, props), _path$2 || (_path$2 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2932
|
-
fill: "currentColor",
|
|
2933
|
-
fillRule: "evenodd",
|
|
2934
|
-
d: "M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0M5.942 5.058a.625.625 0 1 0-.884.884L7.116 8l-2.058 2.058a.625.625 0 1 0 .884.884L8 8.884l2.058 2.058a.625.625 0 1 0 .884-.884L8.884 8l2.058-2.058a.625.625 0 1 0-.884-.884L8 7.116z",
|
|
2935
|
-
clipRule: "evenodd"
|
|
2936
|
-
})));
|
|
2937
|
-
};
|
|
2938
|
-
var system_error_default = SvgSystemError;
|
|
2939
|
-
|
|
2940
|
-
//#endregion
|
|
2941
|
-
//#region src/lib/user-facing/assets/icons/system-info.svg
|
|
2942
|
-
var _path$1;
|
|
2943
|
-
function _extends$1() {
|
|
2944
|
-
return _extends$1 = Object.assign ? Object.assign.bind() : function(n) {
|
|
2945
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
2946
|
-
var t = arguments[e];
|
|
2947
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2948
|
-
}
|
|
2949
|
-
return n;
|
|
2950
|
-
}, _extends$1.apply(null, arguments);
|
|
2951
|
-
}
|
|
2952
|
-
var SvgSystemInfo = function SvgSystemInfo$1(props) {
|
|
2953
|
-
return /* @__PURE__ */ React$1.createElement("svg", _extends$1({
|
|
2954
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2955
|
-
width: 16,
|
|
2956
|
-
height: 16,
|
|
2957
|
-
fill: "none"
|
|
2958
|
-
}, props), _path$1 || (_path$1 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2959
|
-
fill: "currentColor",
|
|
2960
|
-
d: "M8 1a7 7 0 1 0 7 7 7.014 7.014 0 0 0-7-7m-.135 3.23a.808.808 0 1 1 0 1.616.808.808 0 0 1 0-1.615m.673 7.54H8a.54.54 0 0 1-.538-.54V8a.538.538 0 1 1 0-1.077H8a.54.54 0 0 1 .538.539v3.23a.538.538 0 1 1 0 1.077"
|
|
2961
|
-
})));
|
|
2962
|
-
};
|
|
2963
|
-
var system_info_default = SvgSystemInfo;
|
|
2964
|
-
|
|
2965
|
-
//#endregion
|
|
2966
|
-
//#region src/lib/user-facing/assets/icons/system-success.svg
|
|
2967
|
-
var _path;
|
|
2968
|
-
function _extends() {
|
|
2969
|
-
return _extends = Object.assign ? Object.assign.bind() : function(n) {
|
|
2970
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
2971
|
-
var t = arguments[e];
|
|
2972
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2973
|
-
}
|
|
2974
|
-
return n;
|
|
2975
|
-
}, _extends.apply(null, arguments);
|
|
2976
|
-
}
|
|
2977
|
-
var SvgSystemSuccess = function SvgSystemSuccess$1(props) {
|
|
2978
|
-
return /* @__PURE__ */ React$1.createElement("svg", _extends({
|
|
2979
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2980
|
-
width: 16,
|
|
2981
|
-
height: 16,
|
|
2982
|
-
fill: "none"
|
|
2983
|
-
}, props), _path || (_path = /* @__PURE__ */ React$1.createElement("path", {
|
|
2984
|
-
fill: "currentColor",
|
|
2985
|
-
fillRule: "evenodd",
|
|
2986
|
-
d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.442-8.058a.625.625 0 1 0-.884-.884L7.5 9.116 5.942 7.558a.625.625 0 1 0-.884.884l2 2c.244.244.64.244.884 0z",
|
|
2987
|
-
clipRule: "evenodd"
|
|
2988
|
-
})));
|
|
2989
|
-
};
|
|
2990
|
-
var system_success_default = SvgSystemSuccess;
|
|
2991
|
-
|
|
2992
|
-
//#endregion
|
|
2993
|
-
//#region src/lib/user-facing/styling/colors.ts
|
|
2994
|
-
const colors = {
|
|
2995
|
-
WHITE: "#FFFFFF",
|
|
2996
|
-
BLACK: "#000000",
|
|
2997
|
-
PLATFORM_BLACK: "#0E141B",
|
|
2998
|
-
OFF_WHITE: "#F2F2F2",
|
|
2999
|
-
DISABLED: "rgba(0, 0, 0, 0.25)",
|
|
3000
|
-
GREY_25: "#F9FAFB",
|
|
3001
|
-
GREY_50: "#F3F4F6",
|
|
3002
|
-
GREY_100: "#E8EAED",
|
|
3003
|
-
GREY_200: "#C6CAD2",
|
|
3004
|
-
GREY_300: "#A4AAB7",
|
|
3005
|
-
GREY_400: "#818A9C",
|
|
3006
|
-
GREY_500: "#6C7689",
|
|
3007
|
-
GREY_600: "#5A6272",
|
|
3008
|
-
GREY_700: "#454D5F",
|
|
3009
|
-
GREY_800: "#2F3437",
|
|
3010
|
-
GREY_900: "#121517",
|
|
3011
|
-
GRAY_GRID: "#CCD3DB",
|
|
3012
|
-
RED_500_8: "rgba(255, 72, 72, 0.08)",
|
|
3013
|
-
RED_25: "#FF48481F",
|
|
3014
|
-
RED_500: "#FF4848",
|
|
3015
|
-
RED_600: "#DB4949",
|
|
3016
|
-
RED_700: "#C54141",
|
|
3017
|
-
ORANGE_25: "#FFEEC5",
|
|
3018
|
-
ORANGE_600: "#FA8A0F",
|
|
3019
|
-
SUBTLE_BLUE: "#29bbff14",
|
|
3020
|
-
SUBTLE_BLUE_SOLID: "#eefaff",
|
|
3021
|
-
ACCENT_BLUE_NEW_DARKER: "#0087E0",
|
|
3022
|
-
BLUE_MINMAX_LABELS: "#0062A3",
|
|
3023
|
-
DRAG_PREVIEW_BLUE: "rgba(0, 135, 224, 0.16)",
|
|
3024
|
-
ACCENT_BLUE_500: "#27BBFF",
|
|
3025
|
-
ACCENT_BLUE_500_04: "#27BBFF0A",
|
|
3026
|
-
ACCENT_BLUE_500_25: "#27BBFF14",
|
|
3027
|
-
ACCENT_BLUE_500_50: "#27BBFF1F",
|
|
3028
|
-
ACCENT_BLUE_500_18: "#27BBFF2E",
|
|
3029
|
-
ACCENT_BLUE_500_24: "#27BBFF3D",
|
|
3030
|
-
ACCENT_BLUE_500_48: "#27BBFF7A",
|
|
3031
|
-
ACCENT_BLUE_600: "#00A8F5",
|
|
3032
|
-
ACCENT_BLUE_700: "#009AE0",
|
|
3033
|
-
ACCENT_ORANGE: "#FF9F35",
|
|
3034
|
-
ACCENT_ORANGE_04: "#FF9F350A",
|
|
3035
|
-
ACCENT_ORANGE_24: "#FF9F353D",
|
|
3036
|
-
LIGHT_ORANGE: "#FF9F351E",
|
|
3037
|
-
ACCENT_ORANGE_600: "#FA8A0F",
|
|
3038
|
-
SUBTLE_PURPLE: "#643ADF14",
|
|
3039
|
-
ACCENT_PURPLE: "#643ADF",
|
|
3040
|
-
LIGHT_PURPLE: "#643ADF1E",
|
|
3041
|
-
ACCENT_PURPLE_500: "#7C4FF8",
|
|
3042
|
-
ACCENT_PURPLE_600: "#5227CE",
|
|
3043
|
-
SUBTLE_GREEN: "#14CDB714",
|
|
3044
|
-
LIGHT_GREEN: "#9BDCAD",
|
|
3045
|
-
ACCENT_GREEN: "#14CDB7",
|
|
3046
|
-
ACCENT_GREEN_600: "#08BAA5",
|
|
3047
|
-
LIGHT_PINK: `rgba(255, 98, 164, 0.12)`,
|
|
3048
|
-
ACCENT_PINK: "#FF62A4",
|
|
3049
|
-
HOVER_BLUE: "#E3F8FF",
|
|
3050
|
-
HOVER_GREEN: "#14CDB724",
|
|
3051
|
-
CLICK_GREEN: "#14CDB734",
|
|
3052
|
-
INFO: "#27BBFF",
|
|
3053
|
-
WARNING: "#FF9F35",
|
|
3054
|
-
DANGER: "#F45252",
|
|
3055
|
-
DANGER_BRIGHT: "rgba(255, 72, 72, 1.0)",
|
|
3056
|
-
DANGER_SUBTLE: "#F452521F",
|
|
3057
|
-
SUCCESS: "#0CC26D",
|
|
3058
|
-
NONE: "transparent"
|
|
3059
|
-
};
|
|
3060
|
-
|
|
3061
|
-
//#endregion
|
|
3062
|
-
//#region src/lib/user-facing/themes/classnames.ts
|
|
3063
|
-
const MODIFIER_CLASSNAMES = {
|
|
3064
|
-
DISABLED_MODIFIER: "sb-disabled",
|
|
3065
|
-
ERROR_MODIFIER: "sb-error",
|
|
3066
|
-
ACTIVE_MODIFIER: "sb-active"
|
|
3067
|
-
};
|
|
3068
|
-
const CLASS_NAMES = {
|
|
3069
|
-
...MODIFIER_CLASSNAMES,
|
|
3070
|
-
HEADING1: "sb-heading-1",
|
|
3071
|
-
HEADING2: "sb-heading-2",
|
|
3072
|
-
HEADING3: "sb-heading-3",
|
|
3073
|
-
HEADING4: "sb-heading-4",
|
|
3074
|
-
HEADING5: "sb-heading-5",
|
|
3075
|
-
HEADING6: "sb-heading-6",
|
|
3076
|
-
BODY1: "sb-body-1",
|
|
3077
|
-
BODY2: "sb-body-2",
|
|
3078
|
-
BODY3: "sb-body-3",
|
|
3079
|
-
LINK: "sb-link",
|
|
3080
|
-
INPUT_LABEL: "sb-input-label",
|
|
3081
|
-
LABEL: "sb-label",
|
|
3082
|
-
CODE_TEXT: "sb-code",
|
|
3083
|
-
INPUT_TEXT: "sb-input-text",
|
|
3084
|
-
INPUT_PLACEHOLDER: "sb-input-placeholder",
|
|
3085
|
-
BUTTON_LABEL: "sb-button-label",
|
|
3086
|
-
SYSTEM_TEXT: "sb-system-text",
|
|
3087
|
-
BUILTIN_BODY: "sb-builtin-body",
|
|
3088
|
-
ELLIPSIS_TEXT: "sb-ellipsis-text",
|
|
3089
|
-
BUTTON: "sb-button",
|
|
3090
|
-
PRIMARY_BUTTON: "sb-button-primary",
|
|
3091
|
-
SECONDARY_BUTTON: "sb-button-secondary",
|
|
3092
|
-
SECONDARY_NEUTRAL_BUTTON: "sb-button-secondary-neutral",
|
|
3093
|
-
TERTIARY_BUTTON: "sb-button-tertiary",
|
|
3094
|
-
SYSTEM_BUTTON: "sb-button-system",
|
|
3095
|
-
INPUT: "sb-input",
|
|
3096
|
-
SWITCH: "sb-switch",
|
|
3097
|
-
CHECKBOX: "sb-checkbox",
|
|
3098
|
-
RADIO: "sb-radio",
|
|
3099
|
-
SECTION: "sb-section",
|
|
3100
|
-
ROUNDED_CONTAINER: "sb-rounded-container",
|
|
3101
|
-
CANVAS: "sb-canvas",
|
|
3102
|
-
DEFAULT_CONTAINER: "sb-default-container",
|
|
3103
|
-
DEFAULT_CONTAINER_STYLE_CARD: "sb-default-container-style-card",
|
|
3104
|
-
DEFAULT_CONTAINER_STYLE_NONE: "sb-default-container-style-none",
|
|
3105
|
-
DEFAULT_CONTAINER_BORDER: "sb-default-container-border",
|
|
3106
|
-
CONTAINER_BORDER_OUTLINE: "sb-container-border-overlay",
|
|
3107
|
-
POPOVER_WRAPPER: "sb-popover-wrapper",
|
|
3108
|
-
TAB: "sb-tab",
|
|
3109
|
-
MODAL: "sb-modal",
|
|
3110
|
-
SLIDEOUT: "sb-slideout",
|
|
3111
|
-
BORDER_BOTTOM: "sb-util-border-bottom",
|
|
3112
|
-
BORDER_TOP: "sb-util-border-top",
|
|
3113
|
-
NOTIFICATION: "sb-notification",
|
|
3114
|
-
STYLED_SCROLLBAR: "sb-scrollable",
|
|
3115
|
-
TOOLTIP: "sb-tooltip",
|
|
3116
|
-
DROPDOWN: "sb-dropdown",
|
|
3117
|
-
DROPDOWN_MENU: "sb-dropdown-menu",
|
|
3118
|
-
MENU_ITEM: "sb-menu-item",
|
|
3119
|
-
TAG_INPUT: "sb-tag-input",
|
|
3120
|
-
DATEPICKER: "sb-datepicker",
|
|
3121
|
-
DROPDOWN_CLEAR_ICON: "sb-dropdown-clear-icon",
|
|
3122
|
-
CARET_ICON: "sb-caret-icon",
|
|
3123
|
-
PRIMARY_COLOR_ICON: "sb-primary-color-icon",
|
|
3124
|
-
CLOSE_ICON: "sb-close-icon",
|
|
3125
|
-
ICON: "sb-icon",
|
|
3126
|
-
PAGINATOR: "sb-rc-paginator",
|
|
3127
|
-
CODE_EDITOR: "sb-code-editor",
|
|
3128
|
-
ERROR_INLINE_MESSAGE: "sb-error-inline-message"
|
|
3129
|
-
};
|
|
3130
|
-
|
|
3131
|
-
//#endregion
|
|
3132
|
-
//#region src/lib/user-facing/utils/notification.tsx
|
|
3133
|
-
const activeNotifications = /* @__PURE__ */ new Map();
|
|
3134
|
-
const StatusIconWrapper = styled.div`
|
|
3135
|
-
color: ${(props) => props.color};
|
|
3136
|
-
font-size: 16px;
|
|
3137
|
-
margin-top: -2px;
|
|
3138
|
-
margin-left: -10px;
|
|
3139
|
-
svg {
|
|
3140
|
-
width: 18px;
|
|
3141
|
-
height: 18px;
|
|
3142
|
-
}
|
|
3143
|
-
`;
|
|
3144
|
-
const MessageWrapper = styled.div`
|
|
3145
|
-
font-size: 12px;
|
|
3146
|
-
font-weight: 500;
|
|
3147
|
-
line-height: 1.3;
|
|
3148
|
-
margin-left: -26px;
|
|
3149
|
-
margin-right: 0;
|
|
3150
|
-
white-space: pre-wrap;
|
|
3151
|
-
`;
|
|
3152
|
-
const DescriptionWrapper = styled.div`
|
|
3153
|
-
font-size: 12px;
|
|
3154
|
-
margin-left: -26px;
|
|
3155
|
-
margin-right: -10px;
|
|
3156
|
-
`;
|
|
3157
|
-
const styleMessage = (message, dataTest) => {
|
|
3158
|
-
return /* @__PURE__ */ jsx(MessageWrapper, {
|
|
3159
|
-
"data-test": dataTest ? dataTest : "notification",
|
|
3160
|
-
children: message
|
|
3161
|
-
});
|
|
3162
|
-
};
|
|
3163
|
-
const styleDescription = (description) => {
|
|
3164
|
-
if (!description) return;
|
|
3165
|
-
return /* @__PURE__ */ jsx(DescriptionWrapper, { children: description });
|
|
3166
|
-
};
|
|
3167
|
-
const messageWithCount = (key, message, dataTest) => {
|
|
3168
|
-
let updatedMessage = message;
|
|
3169
|
-
if (key) {
|
|
3170
|
-
const count = (activeNotifications.get(key)?.count ?? 0) + 1;
|
|
3171
|
-
activeNotifications.set(key, {
|
|
3172
|
-
count,
|
|
3173
|
-
message
|
|
3174
|
-
});
|
|
3175
|
-
if (count > 1 && isString$1(message)) updatedMessage = `${message} (${count} times)`;
|
|
3176
|
-
}
|
|
3177
|
-
return styleMessage(updatedMessage, dataTest);
|
|
3178
|
-
};
|
|
3179
|
-
/**
|
|
3180
|
-
* When a Key is used,
|
|
3181
|
-
* duplicate notifications are not shown but the timeout is added to the first notification.
|
|
3182
|
-
* @returns A string key based on inputs
|
|
3183
|
-
*/
|
|
3184
|
-
const getKey = (type, message, description, duration) => {
|
|
3185
|
-
return isString$1(message) ? `${type}--${String(message)}--${description}--${duration}` : void 0;
|
|
3186
|
-
};
|
|
3187
|
-
const removeNotificationsWithKey = (key) => {
|
|
3188
|
-
document.querySelectorAll(`[data-testid="notification_${key}"]`).forEach((el) => {
|
|
3189
|
-
el.remove();
|
|
3190
|
-
});
|
|
3191
|
-
};
|
|
3192
|
-
const attrSafeKey = (str) => {
|
|
3193
|
-
return str.replace(/\W+/g, "_");
|
|
3194
|
-
};
|
|
3195
|
-
const getIcon = (type) => {
|
|
3196
|
-
let icon;
|
|
3197
|
-
let color;
|
|
3198
|
-
switch (type) {
|
|
3199
|
-
case "success":
|
|
3200
|
-
icon = /* @__PURE__ */ jsx(system_success_default, {});
|
|
3201
|
-
color = colors.SUCCESS;
|
|
3202
|
-
break;
|
|
3203
|
-
case "error":
|
|
3204
|
-
icon = /* @__PURE__ */ jsx(system_error_default, {});
|
|
3205
|
-
color = colors.DANGER;
|
|
3206
|
-
break;
|
|
3207
|
-
case "info":
|
|
3208
|
-
icon = /* @__PURE__ */ jsx(system_info_default, {});
|
|
3209
|
-
color = colors.INFO;
|
|
3210
|
-
break;
|
|
3211
|
-
case "warning":
|
|
3212
|
-
icon = /* @__PURE__ */ jsx(system_danger_default, {});
|
|
3213
|
-
color = colors.WARNING;
|
|
3214
|
-
break;
|
|
3215
|
-
}
|
|
3216
|
-
return /* @__PURE__ */ jsx(StatusIconWrapper, {
|
|
3217
|
-
color,
|
|
3218
|
-
children: icon
|
|
3219
|
-
});
|
|
3220
|
-
};
|
|
3221
|
-
function onAlertClose(key) {
|
|
3222
|
-
if (key) activeNotifications.delete(key);
|
|
3223
|
-
}
|
|
3224
|
-
const positionToPlacement = {
|
|
3225
|
-
[NotificationPosition.bottom]: "bottom-center",
|
|
3226
|
-
[NotificationPosition.top]: "top-center",
|
|
3227
|
-
[NotificationPosition.topLeft]: "top-left",
|
|
3228
|
-
[NotificationPosition.topRight]: "top-right",
|
|
3229
|
-
[NotificationPosition.bottomLeft]: "bottom-left",
|
|
3230
|
-
[NotificationPosition.bottomRight]: "bottom-right"
|
|
3231
|
-
};
|
|
3232
|
-
function sendNotification({ message, description, duration, key = getKey("success", message, description, duration), placement = NotificationPosition.bottomRight, style, dataTest, type }) {
|
|
3233
|
-
const icon = getIcon(type);
|
|
3234
|
-
const handleClose = () => {
|
|
3235
|
-
onAlertClose(key);
|
|
3236
|
-
if (key) removeNotificationsWithKey(attrSafeKey(`notification-${key}`));
|
|
3237
|
-
};
|
|
3238
|
-
if (key) {
|
|
3239
|
-
toast.dismiss(key);
|
|
3240
|
-
removeNotificationsWithKey(attrSafeKey(`notification-${key}`));
|
|
3241
|
-
}
|
|
3242
|
-
const position = positionToPlacement[placement];
|
|
3243
|
-
toast.success(messageWithCount(key, message, dataTest), {
|
|
3244
|
-
id: key,
|
|
3245
|
-
description: styleDescription(description),
|
|
3246
|
-
icon,
|
|
3247
|
-
duration: duration ? duration * 1e3 : void 0,
|
|
3248
|
-
position,
|
|
3249
|
-
className: CLASS_NAMES.NOTIFICATION,
|
|
3250
|
-
style,
|
|
3251
|
-
onDismiss: handleClose,
|
|
3252
|
-
onAutoClose: handleClose
|
|
3253
|
-
});
|
|
3254
|
-
}
|
|
3255
|
-
|
|
3256
|
-
//#endregion
|
|
3257
|
-
//#region src/lib/internal-details/lib/evaluator/file-utils.ts
|
|
3258
|
-
var FileManagerClass = class FileManagerClass {
|
|
3259
|
-
static instance;
|
|
3260
|
-
storage = {};
|
|
3261
|
-
constructor() {}
|
|
3262
|
-
static getInstance() {
|
|
3263
|
-
if (!FileManagerClass.instance) FileManagerClass.instance = new FileManagerClass();
|
|
3264
|
-
return FileManagerClass.instance;
|
|
3265
|
-
}
|
|
3266
|
-
store(componentName, file) {
|
|
3267
|
-
const fileId = getFileUploadId(file);
|
|
3268
|
-
if (!this.storage[componentName]) this.storage[componentName] = {};
|
|
3269
|
-
this.storage[componentName][fileId] = file;
|
|
3270
|
-
}
|
|
3271
|
-
get(componentName, fileId) {
|
|
3272
|
-
return this.storage[componentName]?.[fileId];
|
|
3273
|
-
}
|
|
3274
|
-
remove(componentName, file) {
|
|
3275
|
-
const fileId = getFileUploadId(file);
|
|
3276
|
-
if (this.storage[componentName]) delete this.storage[componentName][fileId];
|
|
3277
|
-
}
|
|
3278
|
-
clearComponent(componentName) {
|
|
3279
|
-
delete this.storage[componentName];
|
|
3280
|
-
}
|
|
3281
|
-
clear() {
|
|
3282
|
-
this.storage = {};
|
|
3283
|
-
}
|
|
3284
|
-
};
|
|
3285
|
-
const FileManager = FileManagerClass.getInstance();
|
|
3286
|
-
function getFileUploadId(file) {
|
|
3287
|
-
return `${file.name.replace(/[^a-zA-Z0-9.-]/g, "_")}-${file.size}-${file.lastModified}`;
|
|
3288
|
-
}
|
|
3289
|
-
/**
|
|
3290
|
-
* Check if the given object is a light readable file.
|
|
3291
|
-
* Meaning it has a $superblocksId property.
|
|
3292
|
-
*
|
|
3293
|
-
* Compare to `isReadableFile` which checks if the object is a full superblocks readable file object.
|
|
3294
|
-
*/
|
|
3295
|
-
const isLightReadableFile = (f) => {
|
|
3296
|
-
if (!f || typeof f !== "object" || Array.isArray(f)) return false;
|
|
3297
|
-
if (Object.entries(f).length === 0) return false;
|
|
3298
|
-
return "$superblocksId" in f;
|
|
3299
|
-
};
|
|
3300
|
-
function getFilePaths(root, path = []) {
|
|
3301
|
-
const paths = [];
|
|
3302
|
-
if (!root || !(typeof root === "object")) return paths;
|
|
3303
|
-
if (Array.isArray(root) || isObservableArray(root)) {
|
|
3304
|
-
root.forEach((v, i) => {
|
|
3305
|
-
paths.push(...getFilePaths(v, [...path, i.toString()]));
|
|
3306
|
-
});
|
|
3307
|
-
return paths;
|
|
3308
|
-
}
|
|
3309
|
-
if (isLightReadableFile(root)) return [path];
|
|
3310
|
-
Object.entries(root).forEach(([key, value]) => {
|
|
3311
|
-
if (isLightReadableFile(value)) paths.push([...path, key]);
|
|
3312
|
-
else if (value && (Array.isArray(value) || isObservableArray(value))) value.forEach((v, i) => {
|
|
3313
|
-
paths.push(...getFilePaths(v, [
|
|
3314
|
-
...path,
|
|
3315
|
-
key,
|
|
3316
|
-
i.toString()
|
|
3317
|
-
]));
|
|
3318
|
-
});
|
|
3319
|
-
else if (value && typeof value === "object") paths.push(...getFilePaths(value, [...path, key]));
|
|
3320
|
-
});
|
|
3321
|
-
return paths;
|
|
3322
|
-
}
|
|
3323
|
-
/**
|
|
3324
|
-
* Extract Files and path to files from entities.
|
|
3325
|
-
* Used to retrieve files that are in an entity's state which is bound in a Backend API.
|
|
3326
|
-
* @param entities - The entities to extract files from
|
|
3327
|
-
* @returns
|
|
3328
|
-
*/
|
|
3329
|
-
function extractFilesFromEntities(entities) {
|
|
3330
|
-
const files = {};
|
|
3331
|
-
const pathToFiles = [];
|
|
3332
|
-
Object.entries(entities).forEach(([entityName, entityValue]) => {
|
|
3333
|
-
getFilePaths(entityValue).forEach((path) => {
|
|
3334
|
-
const fileObj = get(entityValue, path);
|
|
3335
|
-
if (isLightReadableFile(fileObj)) {
|
|
3336
|
-
const fileId = fileObj.$superblocksId;
|
|
3337
|
-
const file = FileManager.get(entityName, fileId);
|
|
3338
|
-
if (file) {
|
|
3339
|
-
files[fileId] = file;
|
|
3340
|
-
pathToFiles.push([entityName, ...path]);
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
});
|
|
3344
|
-
});
|
|
3345
|
-
return {
|
|
3346
|
-
files,
|
|
3347
|
-
paths: pathToFiles
|
|
3348
|
-
};
|
|
3349
|
-
}
|
|
3350
|
-
async function formatFilesForRequest(files) {
|
|
3351
|
-
const entries$1 = Object.entries(files);
|
|
3352
|
-
return await Promise.all(entries$1.map(async ([fileId, file]) => {
|
|
3353
|
-
try {
|
|
3354
|
-
return {
|
|
3355
|
-
originalName: fileId,
|
|
3356
|
-
buffer: await new Promise((resolve, reject) => {
|
|
3357
|
-
const reader = new FileReader();
|
|
3358
|
-
reader.onload = () => resolve(reader.result.split(",")[1]);
|
|
3359
|
-
reader.onerror = () => reject(new Error(reader.error?.message || "Unknown error reading file"));
|
|
3360
|
-
reader.readAsDataURL(file);
|
|
3361
|
-
}),
|
|
3362
|
-
encoding: "base64",
|
|
3363
|
-
mimetype: "text/plain"
|
|
3364
|
-
};
|
|
3365
|
-
} catch (error) {
|
|
3366
|
-
console.warn(`Failed to encode file ${file.name} (ID: ${fileId}):`, error);
|
|
3367
|
-
throw error;
|
|
3368
|
-
}
|
|
3369
|
-
}));
|
|
3370
|
-
}
|
|
3371
|
-
function getFileWithUploadId(f) {
|
|
3372
|
-
const uploadId = getFileUploadId(f);
|
|
3373
|
-
Object.defineProperty(f, "$superblocksId", {
|
|
3374
|
-
value: uploadId,
|
|
3375
|
-
writable: false,
|
|
3376
|
-
enumerable: true,
|
|
3377
|
-
configurable: false
|
|
3378
|
-
});
|
|
3379
|
-
return f;
|
|
3380
|
-
}
|
|
3381
|
-
function getFileMetadata(f) {
|
|
3382
|
-
const superblocksId = getFileUploadId(f);
|
|
3383
|
-
const nameParts = f.name.split(".");
|
|
3384
|
-
const extension = nameParts.length > 1 ? nameParts.pop() || "" : "";
|
|
3385
|
-
return {
|
|
3386
|
-
$superblocksId: superblocksId,
|
|
3387
|
-
name: f.name,
|
|
3388
|
-
extension,
|
|
3389
|
-
type: f.type,
|
|
3390
|
-
size: f.size,
|
|
3391
|
-
encoding: "text"
|
|
3392
|
-
};
|
|
3393
|
-
}
|
|
3394
|
-
|
|
3395
|
-
//#endregion
|
|
3396
|
-
//#region src/lib/internal-details/lib/evaluator/binding-extraction.ts
|
|
3397
|
-
function getApiDeps(entitiesState, scopeId, apiDepCandidates) {
|
|
3398
|
-
const apiDepEntries = apiDepCandidates.map((candidateName) => {
|
|
3399
|
-
const [entityName, ...rest] = splitJSPath(candidateName) ?? [];
|
|
3400
|
-
return [entityName, rest.length === 0 ? "" : stringifySplitPaths(rest)];
|
|
3401
|
-
});
|
|
3402
|
-
const candidates = {};
|
|
3403
|
-
apiDepEntries.forEach(([name, rest]) => {
|
|
3404
|
-
if (name in candidates) {
|
|
3405
|
-
const parts = splitJSPath(rest) ?? [];
|
|
3406
|
-
const existingParts = splitJSPath(candidates[name]) ?? [];
|
|
3407
|
-
let i = 0;
|
|
3408
|
-
for (i = 0; i < Math.min(parts.length, existingParts.length); i++) if (parts[i] === existingParts[i]) continue;
|
|
3409
|
-
candidates[name] = stringifySplitPaths(parts.slice(0, i - 1));
|
|
3410
|
-
} else candidates[name] = rest;
|
|
3411
|
-
});
|
|
3412
|
-
const entities = Object.fromEntries(Object.entries(candidates).map(([candidateName, path]) => [candidateName, buildEntityByPath(path, entitiesState.getEntity(scopeId, getName(candidateName), { includeParentScopes: true }))]).filter(([_$1, entity]) => !!entity));
|
|
3413
|
-
const { files, paths } = extractFilesFromEntities(entities);
|
|
3414
|
-
/**
|
|
3415
|
-
* Update entities data payload that rely on files,
|
|
3416
|
-
* to honor the FilePrivateMetadata type
|
|
3417
|
-
* which is checked on runtime in the backend.
|
|
3418
|
-
*/
|
|
3419
|
-
const clonedEntities = /* @__PURE__ */ new Set();
|
|
3420
|
-
paths.forEach((path) => {
|
|
3421
|
-
const fileProps = get(entities, path);
|
|
3422
|
-
if (isLightReadableFile(fileProps)) {
|
|
3423
|
-
const file = FileManager.get(path[0], fileProps.$superblocksId);
|
|
3424
|
-
if (file) {
|
|
3425
|
-
const entityName = path[0];
|
|
3426
|
-
if (!clonedEntities.has(entityName)) {
|
|
3427
|
-
entities[entityName] = cloneDeep(entities[entityName]);
|
|
3428
|
-
clonedEntities.add(entityName);
|
|
3429
|
-
}
|
|
3430
|
-
set(entities, path, getFileMetadata(file));
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
});
|
|
3434
|
-
return {
|
|
3435
|
-
entities,
|
|
3436
|
-
files
|
|
3437
|
-
};
|
|
3438
|
-
}
|
|
3439
|
-
function buildEntityByPath(path, entity) {
|
|
3440
|
-
if (!isObject(entity) || path === "") return entity;
|
|
3441
|
-
const [pathPart, ...rest] = splitJSPath(path) ?? [];
|
|
3442
|
-
const entityToSend = {};
|
|
3443
|
-
if (isObject(entity) && pathPart in entity) entityToSend[pathPart] = buildEntityByPath(stringifySplitPaths(rest), entity[pathPart]);
|
|
3444
|
-
else entityToSend[pathPart] = entity;
|
|
3445
|
-
return entityToSend;
|
|
3446
|
-
}
|
|
3447
|
-
|
|
3448
|
-
//#endregion
|
|
3449
|
-
//#region src/lib/internal-details/lib/resolve-id-singleton.ts
|
|
3450
|
-
const EMBED_STRING = `embedded-`;
|
|
3451
|
-
let promiseCount = 0;
|
|
3452
|
-
const resolverMap = /* @__PURE__ */ new Map();
|
|
3453
|
-
const rejectorMap = /* @__PURE__ */ new Map();
|
|
3454
|
-
const multiUseCallbacks = /* @__PURE__ */ new Map();
|
|
3455
|
-
function addNewPromise(resolver, isMultiUse = false, rejecter) {
|
|
3456
|
-
const promiseId = `${isEmbeddedBySuperblocksFirstParty() ? EMBED_STRING : ""}p${++promiseCount}`;
|
|
3457
|
-
resolverMap.set(promiseId, resolver);
|
|
3458
|
-
if (isMultiUse) multiUseCallbacks.set(promiseId, resolver);
|
|
3459
|
-
if (rejecter) rejectorMap.set(promiseId, rejecter);
|
|
3460
|
-
return promiseId;
|
|
3461
|
-
}
|
|
3462
|
-
function resolveById(id, payload) {
|
|
3463
|
-
const isEmbedId = id.startsWith(EMBED_STRING);
|
|
3464
|
-
if (isEmbeddedBySuperblocksFirstParty() && !isEmbedId || !isEmbeddedBySuperblocksFirstParty() && isEmbedId) editorBridge.resolvePromise(id, payload);
|
|
3465
|
-
else try {
|
|
3466
|
-
const resolver = resolverMap.get(id);
|
|
3467
|
-
if (!resolver) throw new Error(`Promise not found for id ${id}`);
|
|
3468
|
-
resolver(payload);
|
|
3469
|
-
if (!multiUseCallbacks.has(id)) {
|
|
3470
|
-
resolverMap.delete(id);
|
|
3471
|
-
rejectorMap.delete(id);
|
|
3472
|
-
}
|
|
3473
|
-
} catch (e) {
|
|
3474
|
-
console.log("Error resolving promise", e);
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
function rejectById(id, payload) {
|
|
3478
|
-
const isEmbedId = id.startsWith(EMBED_STRING);
|
|
3479
|
-
if (isEmbeddedBySuperblocksFirstParty() && !isEmbedId || !isEmbeddedBySuperblocksFirstParty() && isEmbedId) editorBridge.rejectPromise(id, payload);
|
|
3480
|
-
else try {
|
|
3481
|
-
const rejecter = rejectorMap.get(id);
|
|
3482
|
-
if (!rejecter) throw new Error(`Promise not found for id ${id}`);
|
|
3483
|
-
rejecter(payload);
|
|
3484
|
-
if (!multiUseCallbacks.has(id)) {
|
|
3485
|
-
resolverMap.delete(id);
|
|
3486
|
-
rejectorMap.delete(id);
|
|
3487
|
-
}
|
|
3488
|
-
} catch (e) {
|
|
3489
|
-
console.log("Error rejecting promise", e);
|
|
3490
|
-
}
|
|
3491
|
-
}
|
|
3492
|
-
|
|
3493
|
-
//#endregion
|
|
3494
|
-
//#region src/lib/tracing/context-utils.ts
|
|
3495
|
-
function getContextFromTraceHeaders(traceHeaders) {
|
|
3496
|
-
let parentContext = context.active();
|
|
3497
|
-
try {
|
|
3498
|
-
parentContext = propagation.extract(context.active(), traceHeaders);
|
|
3499
|
-
} catch (error) {
|
|
3500
|
-
console.warn("Failed to extract parent context from headers", traceHeaders, error);
|
|
3501
|
-
}
|
|
3502
|
-
return parentContext;
|
|
3503
|
-
}
|
|
3504
|
-
function createIframeSpan(name, attributes, parentContext) {
|
|
3505
|
-
return getTracer("superblocks-iframe").startSpan(name, { attributes }, parentContext);
|
|
3506
|
-
}
|
|
3507
|
-
function getTraceContextHeadersFromSpan(span) {
|
|
3508
|
-
const traceContextHeaders = {};
|
|
3509
|
-
const contextWithSpan = trace.setSpan(ROOT_CONTEXT, span);
|
|
3510
|
-
propagation.inject(contextWithSpan, traceContextHeaders);
|
|
3511
|
-
return traceContextHeaders;
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
//#endregion
|
|
3515
|
-
//#region src/lib/utils/generate-id.ts
|
|
3516
|
-
const generateId = () => {
|
|
3517
|
-
return Math.random().toString(36).substring(2, 15);
|
|
3518
|
-
};
|
|
3519
|
-
|
|
3520
|
-
//#endregion
|
|
3521
|
-
//#region src/lib/internal-details/lib/features/api-utils.ts
|
|
3522
|
-
async function executeV2Api(params) {
|
|
3523
|
-
const { body, controlFlowOnlyFiles, api, notifyOnSystemError, eventType, onMessage, processStreamEvents, responseType, abortController, baseUrl, viewMode, accessToken, token, traceHeaders } = params;
|
|
3524
|
-
let parentContext = context.active();
|
|
3525
|
-
if (traceHeaders) parentContext = getContextFromTraceHeaders(traceHeaders);
|
|
3526
|
-
let applicationId = "unknown";
|
|
3527
|
-
if ("fetchByPath" in body) applicationId = body.fetchByPath.applicationId;
|
|
3528
|
-
const span = createIframeSpan("iframe_execute_v2_api", {
|
|
3529
|
-
"api-name": api?.apiPb?.metadata?.name || "unknown",
|
|
3530
|
-
"application-id": applicationId,
|
|
3531
|
-
event_type: eventType,
|
|
3532
|
-
response_type: responseType,
|
|
3533
|
-
view_mode: viewMode
|
|
3534
|
-
}, parentContext);
|
|
3535
|
-
try {
|
|
3536
|
-
let cleanedBody;
|
|
3537
|
-
try {
|
|
3538
|
-
cleanedBody = cleanObject(body);
|
|
3539
|
-
} catch {
|
|
3540
|
-
cleanedBody = structuredClone(body);
|
|
3541
|
-
}
|
|
3542
|
-
if (controlFlowOnlyFiles && controlFlowOnlyFiles.length > 0) cleanedBody = {
|
|
3543
|
-
...cleanedBody,
|
|
3544
|
-
files: controlFlowOnlyFiles
|
|
3545
|
-
};
|
|
3546
|
-
const traceContextHeaders = getTraceContextHeadersFromSpan(span);
|
|
3547
|
-
const init = {
|
|
3548
|
-
method: HttpMethod.Post,
|
|
3549
|
-
body: JSON.stringify(cleanedBody),
|
|
3550
|
-
signal: abortController?.signal,
|
|
3551
|
-
headers: {
|
|
3552
|
-
[SUPERBLOCKS_AUTHORIZATION_HEADER]: `Bearer ${accessToken}`,
|
|
3553
|
-
Authorization: `Bearer ${token}`,
|
|
3554
|
-
[SUPERBLOCKS_REQUEST_ID_HEADER]: generateId(),
|
|
3555
|
-
...traceContextHeaders
|
|
3556
|
-
},
|
|
3557
|
-
credentials: "include"
|
|
3558
|
-
};
|
|
3559
|
-
return responseType === ApiResponseType.STREAM ? await fetchServerStream({
|
|
3560
|
-
augmentedInit: init,
|
|
3561
|
-
fullUrl: baseUrl,
|
|
3562
|
-
timeoutId: setTimeout(() => {}, 1e3),
|
|
3563
|
-
onMessage,
|
|
3564
|
-
processStreamEvents
|
|
3565
|
-
}) : await fetchServer({
|
|
3566
|
-
augmentedInit: init,
|
|
3567
|
-
fullUrl: baseUrl,
|
|
3568
|
-
timeoutId: setTimeout(() => {}, 1e3)
|
|
3569
|
-
});
|
|
3570
|
-
} catch (err) {
|
|
3571
|
-
const message = `Failed to execute ${api?.apiPb?.metadata?.name || "API"}. ${err}`;
|
|
3572
|
-
const suppressError = viewMode !== ViewMode.EDITOR && err?.code === 20;
|
|
3573
|
-
if (notifyOnSystemError && !suppressError) console.log(message);
|
|
3574
|
-
return { systemError: message };
|
|
3575
|
-
} finally {
|
|
3576
|
-
span.end();
|
|
3577
|
-
}
|
|
3578
|
-
}
|
|
3579
|
-
const HttpMethod = {
|
|
3580
|
-
Get: "GET",
|
|
3581
|
-
Post: "POST",
|
|
3582
|
-
Put: "PUT",
|
|
3583
|
-
Patch: "PATCH",
|
|
3584
|
-
Delete: "DELETE"
|
|
3585
|
-
};
|
|
3586
|
-
const stream = async ({ url, headers, body, onMessage, onComplete, onError, defaultError, method, baseUrl = "/api/", signal, init: overrideInit }) => {
|
|
3587
|
-
const init = overrideInit ?? {
|
|
3588
|
-
body: JSON.stringify(body),
|
|
3589
|
-
headers,
|
|
3590
|
-
method
|
|
3591
|
-
};
|
|
3592
|
-
try {
|
|
3593
|
-
const response = await fetch(`${baseUrl}${url}`, init);
|
|
3594
|
-
if (!response.ok) try {
|
|
3595
|
-
const parsed = await response.json();
|
|
3596
|
-
throw new HttpError(response.status, !response.status || response.status >= 500, parsed?.error?.message ?? parsed?.responseMeta?.error?.message ?? defaultError);
|
|
3597
|
-
} catch (e) {
|
|
3598
|
-
if (e instanceof HttpError) throw e;
|
|
3599
|
-
throw new HttpError(response.status, !response.status || response.status >= 500, response.statusText);
|
|
3600
|
-
}
|
|
3601
|
-
if (!response.body) return;
|
|
3602
|
-
const reader = response.body.getReader();
|
|
3603
|
-
const decoder = new TextDecoder();
|
|
3604
|
-
let done = false;
|
|
3605
|
-
let lastChunk = "";
|
|
3606
|
-
while (!done) {
|
|
3607
|
-
if (signal && signal.aborted) return;
|
|
3608
|
-
const { value, done: readerDone } = await reader.read();
|
|
3609
|
-
const chunk = lastChunk + decoder.decode(value);
|
|
3610
|
-
const messages = chunk.split("\n");
|
|
3611
|
-
let jsonValues = [];
|
|
3612
|
-
try {
|
|
3613
|
-
jsonValues = messages.filter(Boolean).map((message) => JSON.parse(message.trim()));
|
|
3614
|
-
lastChunk = "";
|
|
3615
|
-
} catch (e) {
|
|
3616
|
-
lastChunk = chunk;
|
|
3617
|
-
if (readerDone) throw e;
|
|
3618
|
-
}
|
|
3619
|
-
for (const jsonValue of jsonValues.filter(Boolean)) {
|
|
3620
|
-
if (jsonValue?.error) {
|
|
3621
|
-
onError(jsonValue.error.message ?? defaultError);
|
|
3622
|
-
return;
|
|
3623
|
-
}
|
|
3624
|
-
onMessage(jsonValue);
|
|
3625
|
-
}
|
|
3626
|
-
done = readerDone && lastChunk === "";
|
|
3627
|
-
}
|
|
3628
|
-
} catch (e) {
|
|
3629
|
-
if (e.name === "AbortError") console.log("Fetch was cancelled");
|
|
3630
|
-
else onError(e.message ?? defaultError, e.code);
|
|
3631
|
-
} finally {
|
|
3632
|
-
onComplete();
|
|
3633
|
-
}
|
|
3634
|
-
};
|
|
3635
|
-
const handleError = (rawError, { fullUrl, augmentedInit }) => {
|
|
3636
|
-
const error = rawError instanceof TypeError ? new HttpError(0, true, rawError.message) : rawError;
|
|
3637
|
-
console.error(`Request to '${fullUrl} has failed
|
|
3638
|
-
Response Status: ${error.code}
|
|
3639
|
-
Response Status Text: ${error.message}`);
|
|
3640
|
-
let critical = error.critical;
|
|
3641
|
-
if (fullUrl.match(/apis\/.*/) && (critical || error.code === 0)) critical = false;
|
|
3642
|
-
if (fullUrl.match(/\/(commits|deployment).*/) && error.code === 500) critical = false;
|
|
3643
|
-
if (augmentedInit.method === HttpMethod.Get && fullUrl.match(/apis\/.*/)) critical = true;
|
|
3644
|
-
else if (fullUrl.match(/apis\/.*/)) {}
|
|
3645
|
-
if (error.code && error.code < 500 && error.code >= 400) {
|
|
3646
|
-
if (error.code === 404) critical = true;
|
|
3647
|
-
}
|
|
3648
|
-
if (error.code >= 500) critical = false;
|
|
3649
|
-
};
|
|
3650
|
-
const fetchServerStream = async ({ augmentedInit, fullUrl, timeoutId, onMessage, processStreamEvents }) => {
|
|
3651
|
-
const handleMessage = (message) => {
|
|
3652
|
-
if (message?.result?.event?.data) onMessage && onMessage(message.result.event.data);
|
|
3653
|
-
else if (message?.result?.event?.start || message?.result?.event?.end) processStreamEvents && processStreamEvents(message);
|
|
3654
|
-
};
|
|
3655
|
-
const onComplete = () => {
|
|
3656
|
-
clearTimeout(timeoutId);
|
|
3657
|
-
};
|
|
3658
|
-
const onError = (error, statusCode) => {
|
|
3659
|
-
if (statusCode != null) handleError(new HttpError(statusCode, !statusCode || statusCode >= 500, error), {
|
|
3660
|
-
fullUrl,
|
|
3661
|
-
augmentedInit,
|
|
3662
|
-
timeoutId
|
|
3663
|
-
});
|
|
3664
|
-
else handleError(new TypeError(error), {
|
|
3665
|
-
fullUrl,
|
|
3666
|
-
augmentedInit,
|
|
3667
|
-
timeoutId
|
|
3668
|
-
});
|
|
3669
|
-
};
|
|
3670
|
-
return stream({
|
|
3671
|
-
url: fullUrl,
|
|
3672
|
-
init: augmentedInit,
|
|
3673
|
-
onMessage: handleMessage,
|
|
3674
|
-
onComplete,
|
|
3675
|
-
onError,
|
|
3676
|
-
baseUrl: "",
|
|
3677
|
-
signal: augmentedInit?.signal ?? void 0
|
|
3678
|
-
});
|
|
3679
|
-
};
|
|
3680
|
-
const getErrorMessageFromObject = (message) => {
|
|
3681
|
-
const messageJSONString = JSON.stringify(message);
|
|
3682
|
-
const match = /"message"\s*:\s*"([^"]*)"/.exec(messageJSONString);
|
|
3683
|
-
return match ? match[1] : messageJSONString;
|
|
3684
|
-
};
|
|
3685
|
-
const fetchServer = ({ augmentedInit, fullUrl, timeoutId }) => {
|
|
3686
|
-
return fetch(fullUrl, augmentedInit).then(async (response) => {
|
|
3687
|
-
try {
|
|
3688
|
-
if (response.status === 204) return null;
|
|
3689
|
-
const json = await response.json();
|
|
3690
|
-
if (response.ok && json) {
|
|
3691
|
-
if (json.data == null) return json;
|
|
3692
|
-
return json.data;
|
|
3693
|
-
} else {
|
|
3694
|
-
let message = json.responseMeta?.error?.message ?? json?.message;
|
|
3695
|
-
if (typeof message === "object") message = getErrorMessageFromObject(message);
|
|
3696
|
-
throw new HttpError(response.status, !response.status || response.status >= 500, message);
|
|
3697
|
-
}
|
|
3698
|
-
} catch (e) {
|
|
3699
|
-
if (e instanceof HttpError) throw e;
|
|
3700
|
-
throw new HttpError(response.status, !response.status || response.status >= 500, response.statusText);
|
|
3701
|
-
}
|
|
3702
|
-
}).catch((rawError) => {
|
|
3703
|
-
handleError(rawError, {
|
|
3704
|
-
fullUrl,
|
|
3705
|
-
augmentedInit,
|
|
3706
|
-
timeoutId
|
|
3707
|
-
});
|
|
3708
|
-
}).finally(() => clearTimeout(timeoutId));
|
|
3709
|
-
};
|
|
3710
|
-
var HttpError = class extends Error {
|
|
3711
|
-
code;
|
|
3712
|
-
critical;
|
|
3713
|
-
constructor(code, critical = false, m) {
|
|
3714
|
-
super(m);
|
|
3715
|
-
this.code = code;
|
|
3716
|
-
this.critical = critical;
|
|
3717
|
-
}
|
|
3718
|
-
};
|
|
3719
|
-
const parseStreamResult = (streamResult, options) => {
|
|
3720
|
-
if (!streamResult || !Array.isArray(streamResult) || !streamResult.length) return;
|
|
3721
|
-
const execution = streamResult[0].result.execution;
|
|
3722
|
-
const [errors, events] = streamResult.reduce((accum, event) => {
|
|
3723
|
-
if (event.result.event.end && event.result.event.end.error) accum[0].push(event.result.event.end.error);
|
|
3724
|
-
accum[1].push(event.result.event);
|
|
3725
|
-
return accum;
|
|
3726
|
-
}, [[], []]);
|
|
3727
|
-
const result = {
|
|
3728
|
-
execution,
|
|
3729
|
-
events,
|
|
3730
|
-
errors,
|
|
3731
|
-
status: "STATUS_COMPLETED"
|
|
3732
|
-
};
|
|
3733
|
-
if (options?.includeFinalOutput) {
|
|
3734
|
-
let returnBlockOutput;
|
|
3735
|
-
for (let i = 0; i < streamResult.length; i++) {
|
|
3736
|
-
const streamEvent = streamResult[i];
|
|
3737
|
-
if (streamEvent.result.event.type === "BLOCK_TYPE_RETURN" && streamEvent.result.event.end) {
|
|
3738
|
-
returnBlockOutput = streamEvent.result.event.end?.output;
|
|
3739
|
-
break;
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
if (returnBlockOutput) result.output = returnBlockOutput;
|
|
3743
|
-
else result.output = streamResult[streamResult.length - 1].result.event.end?.output;
|
|
3744
|
-
}
|
|
3745
|
-
return result;
|
|
3746
|
-
};
|
|
3747
|
-
const isApiV2ExecutionResponse = (response) => {
|
|
3748
|
-
return !!response && "output" in response && response?.output?.result != null;
|
|
3749
|
-
};
|
|
3750
|
-
const decodeBytestringsInV2ExecutionResponse = (response) => {
|
|
3751
|
-
if (!isApiV2ExecutionResponse(response)) return;
|
|
3752
|
-
if (response.output) response.output.result = decodeBytestrings(response.output.result, false);
|
|
3753
|
-
if (Array.isArray(response.events)) response.events.forEach((event) => {
|
|
3754
|
-
const typedEvent = event;
|
|
3755
|
-
if (typedEvent?.end?.output?.result != null) typedEvent.end.output.result = decodeBytestrings(typedEvent.end.output.result, false);
|
|
3756
|
-
});
|
|
3757
|
-
};
|
|
3758
|
-
|
|
3759
|
-
//#endregion
|
|
3760
|
-
//#region src/lib/internal-details/lib/features/api-store.ts
|
|
3761
|
-
var ApiManager = class {
|
|
3762
|
-
agentUrls = [];
|
|
3763
|
-
token;
|
|
3764
|
-
accessToken;
|
|
3765
|
-
apisByName = {};
|
|
3766
|
-
apiNameToDepCandidates = {};
|
|
3767
|
-
apiNameToApiReferences = {};
|
|
3768
|
-
runningApiControllers = {};
|
|
3769
|
-
waitForInitApiPromise = void 0;
|
|
3770
|
-
constructor(rootStore) {
|
|
3771
|
-
this.rootStore = rootStore;
|
|
3772
|
-
}
|
|
3773
|
-
setTokens(token, accessToken) {
|
|
3774
|
-
this.token = token;
|
|
3775
|
-
this.accessToken = accessToken;
|
|
3776
|
-
}
|
|
3777
|
-
isInitialized() {
|
|
3778
|
-
return !!this.token && !!this.accessToken;
|
|
3779
|
-
}
|
|
3780
|
-
async awaitInitApiIfNeeded() {
|
|
3781
|
-
if (this.waitForInitApiPromise) await this.waitForInitApiPromise;
|
|
3782
|
-
}
|
|
3783
|
-
loadApiManifest({ apis = {}, apiDependencies = [] }) {
|
|
3784
|
-
this.setAllApis(apis);
|
|
3785
|
-
apiDependencies.forEach((dep) => {
|
|
3786
|
-
this.setApiDepCandidates(dep.scopeId, dep.apiName, dep.params);
|
|
3787
|
-
this.setApiReferences(dep.scopeId, dep.apiName, dep.dependencies);
|
|
3788
|
-
});
|
|
3789
|
-
const apisToSet = Object.values(apis).map(({ api, scopeId }) => ({
|
|
3790
|
-
...api,
|
|
3791
|
-
scopeId
|
|
3792
|
-
}));
|
|
3793
|
-
this.waitForInitApiPromise = new Promise((resolve) => {
|
|
3794
|
-
const callbackId = addNewPromise(resolve);
|
|
3795
|
-
window.parent.postMessage({
|
|
3796
|
-
type: "set-apis-deployed-mode",
|
|
3797
|
-
payload: {
|
|
3798
|
-
apis: apisToSet,
|
|
3799
|
-
callbackId
|
|
3800
|
-
}
|
|
3801
|
-
}, "*");
|
|
3802
|
-
});
|
|
3803
|
-
}
|
|
3804
|
-
setAllApis(apis) {
|
|
3805
|
-
this.apisByName = {};
|
|
3806
|
-
Object.values(apis).forEach(({ api, scopeId }) => {
|
|
3807
|
-
if (!this.apisByName[scopeId]) this.apisByName[scopeId] = {};
|
|
3808
|
-
this.apisByName[scopeId][api.apiPb.metadata.name] = api;
|
|
3809
|
-
});
|
|
3810
|
-
}
|
|
3811
|
-
setApisLoaded() {
|
|
3812
|
-
this.rootStore.setApisLoaded();
|
|
3813
|
-
}
|
|
3814
|
-
setApiDepCandidates(scopeId, apiName, deps) {
|
|
3815
|
-
if (!this.apiNameToDepCandidates[scopeId]) this.apiNameToDepCandidates[scopeId] = {};
|
|
3816
|
-
this.apiNameToDepCandidates[scopeId][apiName] = deps;
|
|
3817
|
-
if (!this.rootStore.isApisLoaded) this.rootStore.setApisLoaded();
|
|
3818
|
-
}
|
|
3819
|
-
setApiReferences(scopeId, apiName, deps) {
|
|
3820
|
-
if (!this.apiNameToApiReferences[scopeId]) this.apiNameToApiReferences[scopeId] = {};
|
|
3821
|
-
this.apiNameToApiReferences[scopeId][apiName] = deps;
|
|
3822
|
-
}
|
|
3823
|
-
updateApi(api, scopeId) {
|
|
3824
|
-
if (!this.apisByName[scopeId]) this.apisByName[scopeId] = {};
|
|
3825
|
-
this.apisByName[scopeId][api.apiPb.metadata.name] = api;
|
|
3826
|
-
if (!this.rootStore.entityManager.getPossibleScope(scopeId)) {
|
|
3827
|
-
console.warn(`Scope ${scopeId} not found. Could not update API.`, api.apiPb.metadata.name);
|
|
3828
|
-
return;
|
|
3829
|
-
}
|
|
3830
|
-
const name = {
|
|
3831
|
-
value: api.apiPb.metadata.name,
|
|
3832
|
-
isAnonymous: false
|
|
3833
|
-
};
|
|
3834
|
-
if (!this.rootStore.entityManager.getEntity(scopeId, name)) this.rootStore.entityManager.createEntity({
|
|
3835
|
-
name,
|
|
3836
|
-
scopeId,
|
|
3837
|
-
type: SbEntityType.API,
|
|
3838
|
-
props: { response: null }
|
|
3839
|
-
});
|
|
3840
|
-
}
|
|
3841
|
-
deleteApi(apiName, scopeId) {
|
|
3842
|
-
if (!scopeId) return;
|
|
3843
|
-
if (this.apisByName[scopeId]) delete this.apisByName[scopeId][apiName];
|
|
3844
|
-
if (!this.rootStore.entityManager.getPossibleScope(scopeId)) {
|
|
3845
|
-
console.warn(`Scope ${scopeId} not found. Could not delete API.`, apiName);
|
|
3846
|
-
return;
|
|
3847
|
-
}
|
|
3848
|
-
const name = {
|
|
3849
|
-
value: apiName,
|
|
3850
|
-
isAnonymous: false
|
|
3851
|
-
};
|
|
3852
|
-
this.rootStore.entityManager.deleteEntity({
|
|
3853
|
-
name,
|
|
3854
|
-
scopeId
|
|
3855
|
-
});
|
|
3856
|
-
}
|
|
3857
|
-
renameApi({ api, oldName, scopeId }) {
|
|
3858
|
-
const name = {
|
|
3859
|
-
value: oldName,
|
|
3860
|
-
isAnonymous: false
|
|
3861
|
-
};
|
|
3862
|
-
if (!this.rootStore.entityManager.getEntity(scopeId, name)) {
|
|
3863
|
-
console.warn(`API with name ${oldName} not found`);
|
|
3864
|
-
return;
|
|
3865
|
-
}
|
|
3866
|
-
const newName = {
|
|
3867
|
-
value: api.apiPb.metadata.name,
|
|
3868
|
-
isAnonymous: false
|
|
3869
|
-
};
|
|
3870
|
-
this.rootStore.entityManager.renameEntity({
|
|
3871
|
-
newName,
|
|
3872
|
-
scopeId,
|
|
3873
|
-
isDuplicate: false,
|
|
3874
|
-
instanceId: oldName
|
|
3875
|
-
});
|
|
3876
|
-
}
|
|
3877
|
-
@action async runApi(apiName, scopeId, options = {}) {
|
|
3878
|
-
await this.awaitInitApiIfNeeded();
|
|
3879
|
-
const api = this.apisByName[scopeId][apiName];
|
|
3880
|
-
editorBridge.setApiStarted(apiName);
|
|
3881
|
-
if (!api) {
|
|
3882
|
-
console.error(`Api ${apiName} not found`);
|
|
3883
|
-
throw new Error(`Api ${apiName} not found`);
|
|
3884
|
-
}
|
|
3885
|
-
if (!this.rootStore.applicationId) {
|
|
3886
|
-
editorBridge.setApiResponse(apiName, {
|
|
3887
|
-
status: "STATUS_COMPLETED",
|
|
3888
|
-
execution: null,
|
|
3889
|
-
errors: [{ message: "No application ID was found, ensure the app was bootstrap correctly." }]
|
|
3890
|
-
});
|
|
3891
|
-
sendNotification({
|
|
3892
|
-
message: "No application ID was found, ensure the app was bootstrap correctly.",
|
|
3893
|
-
type: "error"
|
|
3894
|
-
});
|
|
3895
|
-
return {
|
|
3896
|
-
data: null,
|
|
3897
|
-
error: "No application ID was found"
|
|
3898
|
-
};
|
|
3899
|
-
}
|
|
3900
|
-
const apiDepCandidates = this.apiNameToDepCandidates[scopeId]?.[apiName] ?? [];
|
|
3901
|
-
const { entities: inputs, files } = getApiDeps(this.rootStore.entityManager, scopeId, apiDepCandidates);
|
|
3902
|
-
const controlFlowOnlyFiles = await formatFilesForRequest(files);
|
|
3903
|
-
if (!this.agentUrls.length) {
|
|
3904
|
-
editorBridge.setApiResponse(apiName, {
|
|
3905
|
-
status: "STATUS_COMPLETED",
|
|
3906
|
-
execution: null,
|
|
3907
|
-
errors: [{ message: "No active agent found" }]
|
|
3908
|
-
});
|
|
3909
|
-
sendNotification({
|
|
3910
|
-
message: "No active agent found",
|
|
3911
|
-
type: "error"
|
|
3912
|
-
});
|
|
3913
|
-
return {
|
|
3914
|
-
data: null,
|
|
3915
|
-
error: "No active agent found"
|
|
3916
|
-
};
|
|
3917
|
-
}
|
|
3918
|
-
const agentBaseUrl = this.agentUrls[Math.floor(Math.random() * this.agentUrls.length)];
|
|
3919
|
-
const orchestratorUrl = new URL("v2/execute", agentBaseUrl).href;
|
|
3920
|
-
const profileKey = (this.rootStore.entityManager.getPossibleScope(GLOBAL_SCOPE_ID)?.entities?.Global)?.profiles?.selected?.key ?? "staging";
|
|
3921
|
-
const events = [];
|
|
3922
|
-
await this.rootStore.editStore?.operationManager.ensureFilesSynced();
|
|
3923
|
-
const abortController = new AbortController();
|
|
3924
|
-
this.runningApiControllers[apiName] = abortController;
|
|
3925
|
-
const editMode$1 = isEditMode();
|
|
3926
|
-
const isStream = editMode$1 ? true : false;
|
|
3927
|
-
const authResult = await new Promise((resolve) => {
|
|
3928
|
-
const callbackId = addNewPromise(resolve);
|
|
3929
|
-
window.parent.postMessage({
|
|
3930
|
-
type: "authenticate-api-request",
|
|
3931
|
-
payload: {
|
|
3932
|
-
apiId: api.apiPb.metadata.id,
|
|
3933
|
-
callbackId
|
|
3934
|
-
}
|
|
3935
|
-
}, "*");
|
|
3936
|
-
});
|
|
3937
|
-
if (authResult?.errors && authResult.errors.length > 0) console.error("API Authentication returned with errors", authResult.errors);
|
|
3938
|
-
const { traceHeaders,...restArgs } = options;
|
|
3939
|
-
const syncResponse = await executeV2Api({
|
|
3940
|
-
body: {
|
|
3941
|
-
inputs: {
|
|
3942
|
-
...restArgs,
|
|
3943
|
-
...inputs
|
|
3944
|
-
},
|
|
3945
|
-
fetchByPath: {
|
|
3946
|
-
path: `/pages/${api.pageName}/apis/${apiName}/api.yaml`,
|
|
3947
|
-
applicationId: this.rootStore.applicationId ?? "",
|
|
3948
|
-
branchName: "main",
|
|
3949
|
-
profile: { name: profileKey },
|
|
3950
|
-
viewMode: OrchestratorViewMode.UNSPECIFIED
|
|
3951
|
-
},
|
|
3952
|
-
options: {
|
|
3953
|
-
includeEventOutputs: editMode$1,
|
|
3954
|
-
includeEvents: isStream || editMode$1,
|
|
3955
|
-
includeResolved: editMode$1
|
|
3956
|
-
}
|
|
3957
|
-
},
|
|
3958
|
-
controlFlowOnlyFiles,
|
|
3959
|
-
api,
|
|
3960
|
-
environment: profileKey,
|
|
3961
|
-
eventType: "api",
|
|
3962
|
-
notifyOnSystemError: true,
|
|
3963
|
-
responseType: isStream ? ApiResponseType.STREAM : ApiResponseType.SYNC,
|
|
3964
|
-
baseUrl: isStream ? orchestratorUrl + "/stream" : orchestratorUrl,
|
|
3965
|
-
agents: [],
|
|
3966
|
-
viewMode: editMode$1 ? ViewMode.EDITOR : ViewMode.DEPLOYED,
|
|
3967
|
-
accessToken: this.accessToken ?? "",
|
|
3968
|
-
token: this.token ?? "",
|
|
3969
|
-
traceHeaders,
|
|
3970
|
-
abortController,
|
|
3971
|
-
onMessage: (message) => {
|
|
3972
|
-
editorBridge.sendStreamedApiMessage(message, apiName);
|
|
3973
|
-
},
|
|
3974
|
-
processStreamEvents: (event) => {
|
|
3975
|
-
events.push(event);
|
|
3976
|
-
editorBridge.sendStreamedApiEvent(event, apiName);
|
|
3977
|
-
}
|
|
3978
|
-
});
|
|
3979
|
-
const parsedResult = isStream ? parseStreamResult(events, { includeFinalOutput: true }) : syncResponse;
|
|
3980
|
-
if (parsedResult) decodeBytestringsInV2ExecutionResponse(parsedResult);
|
|
3981
|
-
delete this.runningApiControllers[apiName];
|
|
3982
|
-
editorBridge.setApiResponse(apiName, parsedResult);
|
|
3983
|
-
const error = this.findError(parsedResult ?? void 0);
|
|
3984
|
-
return {
|
|
3985
|
-
data: isApiV2ExecutionResponse(parsedResult) ? parsedResult?.output?.result : null,
|
|
3986
|
-
error
|
|
3987
|
-
};
|
|
3988
|
-
}
|
|
3989
|
-
findError(apiResponse) {
|
|
3990
|
-
if (apiResponse && "systemError" in apiResponse) return;
|
|
3991
|
-
const firstUnhandledError = apiResponse?.errors?.find((error) => !error?.handled);
|
|
3992
|
-
if (!firstUnhandledError) return;
|
|
3993
|
-
return `Error in API: ${firstUnhandledError?.message}`;
|
|
3994
|
-
}
|
|
3995
|
-
@action async cancelApi(apiName, _scopeId) {
|
|
3996
|
-
const abortController = this.runningApiControllers[apiName];
|
|
3997
|
-
if (!abortController) {
|
|
3998
|
-
console.warn(`No running API execution found for ${apiName}`);
|
|
3999
|
-
return;
|
|
4000
|
-
}
|
|
4001
|
-
abortController.abort();
|
|
4002
|
-
delete this.runningApiControllers[apiName];
|
|
4003
|
-
editorBridge.setApiResponse(apiName, {
|
|
4004
|
-
status: "STATUS_CANCELLED",
|
|
4005
|
-
execution: null,
|
|
4006
|
-
events: [],
|
|
4007
|
-
errors: [{ message: "API execution was cancelled" }],
|
|
4008
|
-
output: null
|
|
4009
|
-
});
|
|
4010
|
-
}
|
|
4011
|
-
};
|
|
4012
|
-
var api_store_default = ApiManager;
|
|
4013
|
-
|
|
4014
|
-
//#endregion
|
|
4015
|
-
//#region src/edit-mode/mobx-sync/create-patch.ts
|
|
4016
|
-
const microPatches = (oldValue, newValue, baseStr) => {
|
|
4017
|
-
const cleanedOldValue = removeBindAndReactElements(oldValue);
|
|
4018
|
-
const cleanedNewValue = removeBindAndReactElements(newValue);
|
|
4019
|
-
if (cleanedOldValue === void 0) return [{
|
|
4020
|
-
op: "add",
|
|
4021
|
-
path: pathStringToArray(baseStr),
|
|
4022
|
-
value: cleanedNewValue
|
|
4023
|
-
}];
|
|
4024
|
-
if (isPrimitive(cleanedOldValue) || isPrimitive(cleanedNewValue)) {
|
|
4025
|
-
if (cleanedOldValue !== cleanedNewValue) return [{
|
|
4026
|
-
op: "update",
|
|
4027
|
-
path: pathStringToArray(baseStr),
|
|
4028
|
-
value: cleanedNewValue
|
|
4029
|
-
}];
|
|
4030
|
-
return [];
|
|
4031
|
-
}
|
|
4032
|
-
const diffs = diff(cleanedOldValue, cleanedNewValue);
|
|
4033
|
-
const basePath = pathStringToArray(baseStr);
|
|
4034
|
-
return diffs.map((diff$1) => toMobXPatchFromMicroDiff(diff$1, basePath));
|
|
4035
|
-
};
|
|
4036
|
-
function isPrimitive(value) {
|
|
4037
|
-
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "undefined";
|
|
4038
|
-
}
|
|
4039
|
-
function toMobXPatchFromMicroDiff(diff$1, basePath) {
|
|
4040
|
-
const type = diff$1.type;
|
|
4041
|
-
const fullPath = [...basePath, ...diff$1.path];
|
|
4042
|
-
switch (type) {
|
|
4043
|
-
case "CREATE": return {
|
|
4044
|
-
op: "add",
|
|
4045
|
-
path: fullPath,
|
|
4046
|
-
value: diff$1.value
|
|
4047
|
-
};
|
|
4048
|
-
case "CHANGE": return {
|
|
4049
|
-
op: "update",
|
|
4050
|
-
path: fullPath,
|
|
4051
|
-
value: diff$1.value
|
|
4052
|
-
};
|
|
4053
|
-
case "REMOVE": return {
|
|
4054
|
-
op: "remove",
|
|
4055
|
-
path: fullPath
|
|
4056
|
-
};
|
|
4057
|
-
default: throw new Error(`Unhandled diff type: ${type}`);
|
|
4058
|
-
}
|
|
4059
|
-
}
|
|
4060
|
-
const removeBindAndReactElements = (value) => {
|
|
4061
|
-
if (!value || typeof value !== "object") return value;
|
|
4062
|
-
if (isReactElement(value)) return;
|
|
4063
|
-
if (Array.isArray(value)) return value.map(removeBindAndReactElements);
|
|
4064
|
-
return Object.fromEntries(Object.entries(value).map(([key, value$1]) => {
|
|
4065
|
-
if (key === "bind") return [key, void 0];
|
|
4066
|
-
return [key, removeBindAndReactElements(value$1)];
|
|
4067
|
-
}));
|
|
4068
|
-
};
|
|
4069
|
-
|
|
4070
|
-
//#endregion
|
|
4071
|
-
//#region src/edit-mode/mobx-sync/deep-observe.ts
|
|
4072
|
-
function buildPath(entry) {
|
|
4073
|
-
if (!entry) return "ROOT";
|
|
4074
|
-
const res = [];
|
|
4075
|
-
while (entry.parent) {
|
|
4076
|
-
res.push(entry.path);
|
|
4077
|
-
entry = entry.parent;
|
|
4078
|
-
}
|
|
4079
|
-
return res.reverse().join("/");
|
|
4080
|
-
}
|
|
4081
|
-
function isRecursivelyObservable(thing) {
|
|
4082
|
-
return isObservableObject(thing) || isObservableArray(thing) || isObservableMap(thing);
|
|
4083
|
-
}
|
|
4084
|
-
/**
|
|
4085
|
-
* Given an object, deeply observes the given object.
|
|
4086
|
-
* It is like `observe` from mobx, but applied recursively, including all future children.
|
|
4087
|
-
*
|
|
4088
|
-
* Note that the given object cannot ever contain cycles and should be a tree.
|
|
4089
|
-
*
|
|
4090
|
-
* As benefit: path and root will be provided in the callback, so the signature of the listener is
|
|
4091
|
-
* (change, path, root) => void
|
|
4092
|
-
*
|
|
4093
|
-
* The returned disposer can be invoked to clean up the listener
|
|
4094
|
-
*
|
|
4095
|
-
* deepObserve cannot be used on computed values.
|
|
4096
|
-
*
|
|
4097
|
-
* @example
|
|
4098
|
-
* const disposer = deepObserve(target, (change, path) => {
|
|
4099
|
-
* console.dir(change)
|
|
4100
|
-
* })
|
|
4101
|
-
*/
|
|
4102
|
-
function deepObserve(target, listener) {
|
|
4103
|
-
const entrySet = /* @__PURE__ */ new WeakMap();
|
|
4104
|
-
function genericListener(change) {
|
|
4105
|
-
const entry = entrySet.get(change.object);
|
|
4106
|
-
processChange(change, entry);
|
|
4107
|
-
listener(change, buildPath(entry), target);
|
|
4108
|
-
}
|
|
4109
|
-
function processChange(change, parent) {
|
|
4110
|
-
switch (change.type) {
|
|
4111
|
-
case "add":
|
|
4112
|
-
observeRecursively(change.newValue, parent, change.name);
|
|
4113
|
-
break;
|
|
4114
|
-
case "update":
|
|
4115
|
-
unobserveRecursively(change.oldValue);
|
|
4116
|
-
observeRecursively(change.newValue, parent, change.name || "" + change.index);
|
|
4117
|
-
break;
|
|
4118
|
-
case "remove":
|
|
4119
|
-
case "delete":
|
|
4120
|
-
unobserveRecursively(change.oldValue);
|
|
4121
|
-
break;
|
|
4122
|
-
case "splice":
|
|
4123
|
-
change.removed.map(unobserveRecursively);
|
|
4124
|
-
change.added.forEach((value, idx) => observeRecursively(value, parent, "" + (change.index + idx)));
|
|
4125
|
-
for (let i = change.index + change.addedCount; i < change.object.length; i++) if (isRecursivelyObservable(change.object[i])) {
|
|
4126
|
-
const entry = entrySet.get(change.object[i]);
|
|
4127
|
-
if (entry) entry.path = "" + i;
|
|
4128
|
-
}
|
|
4129
|
-
break;
|
|
4130
|
-
}
|
|
4131
|
-
}
|
|
4132
|
-
function observeRecursively(thing, parent, path) {
|
|
4133
|
-
if (isRecursivelyObservable(thing)) {
|
|
4134
|
-
const entry = entrySet.get(thing);
|
|
4135
|
-
if (entry) {
|
|
4136
|
-
if (entry.parent !== parent || entry.path !== path) throw new Error(`The same observable object cannot appear twice in the same tree, trying to assign it to '${buildPath(parent)}/${path}', but it already exists at '${buildPath(entry.parent)}/${entry.path}'`);
|
|
4137
|
-
} else {
|
|
4138
|
-
const entry$1 = {
|
|
4139
|
-
parent,
|
|
4140
|
-
path,
|
|
4141
|
-
dispose: observe(thing, genericListener)
|
|
4142
|
-
};
|
|
4143
|
-
entrySet.set(thing, entry$1);
|
|
4144
|
-
entries(thing).forEach(([key, value]) => observeRecursively(value, entry$1, "" + key));
|
|
4145
|
-
}
|
|
4146
|
-
}
|
|
4147
|
-
}
|
|
4148
|
-
function unobserveRecursively(thing) {
|
|
4149
|
-
if (isRecursivelyObservable(thing)) {
|
|
4150
|
-
const entry = entrySet.get(thing);
|
|
4151
|
-
if (!entry) return;
|
|
4152
|
-
entrySet.delete(thing);
|
|
4153
|
-
entry.dispose();
|
|
4154
|
-
values(thing).forEach(unobserveRecursively);
|
|
4155
|
-
}
|
|
4156
|
-
}
|
|
4157
|
-
observeRecursively(target, void 0, "");
|
|
4158
|
-
return () => {
|
|
4159
|
-
unobserveRecursively(target);
|
|
4160
|
-
};
|
|
4161
|
-
}
|
|
4162
|
-
|
|
4163
|
-
//#endregion
|
|
4164
|
-
//#region src/edit-mode/mobx-sync/mobx-editor-sync.ts
|
|
4165
|
-
/**
|
|
4166
|
-
* Syncs a mobx store to the editor automatically through postmessage
|
|
4167
|
-
*/
|
|
4168
|
-
function startEditorSync(options) {
|
|
4169
|
-
if (!isEditMode()) return () => {};
|
|
4170
|
-
const { store, storeId, keys, projection, debounce } = options;
|
|
4171
|
-
const reactionOptions = {
|
|
4172
|
-
delay: debounce,
|
|
4173
|
-
name: `editor-sync(${storeId})`
|
|
4174
|
-
};
|
|
4175
|
-
let initialState;
|
|
4176
|
-
if (keys) initialState = sanitizedToJS(pick(store, Object.keys(keys)));
|
|
4177
|
-
else if (projection) initialState = sanitizedToJS(projection(store));
|
|
4178
|
-
else initialState = sanitizedToJS(store);
|
|
4179
|
-
editorBridge.initializeEditorSyncedStore({
|
|
4180
|
-
storeId,
|
|
4181
|
-
initialState
|
|
4182
|
-
});
|
|
4183
|
-
if (projection) {
|
|
4184
|
-
const initialProjection = projection(store);
|
|
4185
|
-
const projectionKeys = Object.keys(initialProjection);
|
|
4186
|
-
const createDisposer = (key) => {
|
|
4187
|
-
let lastValue;
|
|
4188
|
-
return reaction(() => {
|
|
4189
|
-
return sanitizedToJS(projection(store)[key]);
|
|
4190
|
-
}, (value) => {
|
|
4191
|
-
const diffs = microPatches(lastValue, value, key);
|
|
4192
|
-
lastValue = value;
|
|
4193
|
-
if (!(diffs.length === 0)) editorBridge.updateEditorSyncedStore({
|
|
4194
|
-
storeId,
|
|
4195
|
-
patch: diffs
|
|
4196
|
-
});
|
|
4197
|
-
}, reactionOptions);
|
|
4198
|
-
};
|
|
4199
|
-
const projectionDisposers = projectionKeys.reduce((acc, key) => {
|
|
4200
|
-
acc[key] = createDisposer(key);
|
|
4201
|
-
return acc;
|
|
4202
|
-
}, {});
|
|
4203
|
-
const projectionKeysDisposer = reaction(() => Object.keys(projection(store)), (newKeys) => {
|
|
4204
|
-
const lastKeys = Object.keys(projectionDisposers);
|
|
4205
|
-
const deletedKeys = lastKeys.filter((key) => !newKeys.includes(key));
|
|
4206
|
-
newKeys.filter((key) => !lastKeys.includes(key)).forEach((key) => {
|
|
4207
|
-
projectionDisposers[key] = createDisposer(key);
|
|
4208
|
-
editorBridge.updateEditorSyncedStore({
|
|
4209
|
-
storeId,
|
|
4210
|
-
patch: {
|
|
4211
|
-
op: "update",
|
|
4212
|
-
path: [key],
|
|
4213
|
-
value: sanitizedToJS(projection(store)[key])
|
|
4214
|
-
}
|
|
4215
|
-
});
|
|
4216
|
-
});
|
|
4217
|
-
deletedKeys.forEach((key) => {
|
|
4218
|
-
projectionDisposers[key]();
|
|
4219
|
-
delete projectionDisposers[key];
|
|
4220
|
-
editorBridge.updateEditorSyncedStore({
|
|
4221
|
-
storeId,
|
|
4222
|
-
patch: {
|
|
4223
|
-
op: "remove",
|
|
4224
|
-
path: [key]
|
|
4225
|
-
}
|
|
4226
|
-
});
|
|
4227
|
-
});
|
|
4228
|
-
}, reactionOptions);
|
|
4229
|
-
return () => {
|
|
4230
|
-
projectionKeysDisposer();
|
|
4231
|
-
Object.values(projectionDisposers).forEach((disposer) => disposer());
|
|
4232
|
-
};
|
|
4233
|
-
}
|
|
4234
|
-
const keyArr = Object.keys(keys ?? store);
|
|
4235
|
-
const computedKeys = keyArr.filter((key) => isComputedProp(store, key));
|
|
4236
|
-
const observableKeys = keyArr.filter((key) => !computedKeys.includes(key));
|
|
4237
|
-
const disposers = [];
|
|
4238
|
-
const computedDisposers = computedKeys.map((key) => reaction(() => store[key], (value) => {
|
|
4239
|
-
editorBridge.updateEditorSyncedStore({
|
|
4240
|
-
storeId,
|
|
4241
|
-
patch: {
|
|
4242
|
-
op: "update",
|
|
4243
|
-
path: [key],
|
|
4244
|
-
value
|
|
4245
|
-
}
|
|
4246
|
-
});
|
|
4247
|
-
}, reactionOptions));
|
|
4248
|
-
disposers.push(...computedDisposers);
|
|
4249
|
-
if (observableKeys.length > 0 || !(keys !== void 0)) {
|
|
4250
|
-
const deepDisposer = deepObserve(store, (change, pathStr) => {
|
|
4251
|
-
const patch = toMobXPatch(change, pathStr);
|
|
4252
|
-
if (keys && !keys[patch.path[0]]) return;
|
|
4253
|
-
try {
|
|
4254
|
-
editorBridge.updateEditorSyncedStore({
|
|
4255
|
-
storeId,
|
|
4256
|
-
patch
|
|
4257
|
-
});
|
|
4258
|
-
} catch (error) {
|
|
4259
|
-
console.error(`[startEditorSync][${storeId}] Failed to send patch:`, error);
|
|
4260
|
-
}
|
|
4261
|
-
});
|
|
4262
|
-
disposers.push(deepDisposer);
|
|
4263
|
-
}
|
|
4264
|
-
return () => {
|
|
4265
|
-
disposers.forEach((disposer) => disposer());
|
|
4266
|
-
};
|
|
4267
|
-
}
|
|
4268
|
-
|
|
4269
|
-
//#endregion
|
|
4270
|
-
//#region src/lib/internal-details/lib/features/type-defs-utils.ts
|
|
4271
|
-
const analyzePropertyType = (propData, prop) => {
|
|
4272
|
-
let dataType;
|
|
4273
|
-
if (propData.dataType === "composite" && prop && typeof prop.getProps === "function") {
|
|
4274
|
-
const nestedProps = prop.getProps();
|
|
4275
|
-
const objectFields = {};
|
|
4276
|
-
for (const [key, nestedProp] of Object.entries(nestedProps)) if (nestedProp && typeof nestedProp.build === "function") {
|
|
4277
|
-
const nestedPropData = nestedProp.build();
|
|
4278
|
-
if (nestedPropData && nestedPropData.isExternallyReadable) objectFields[key] = analyzePropertyType(nestedPropData, nestedProp);
|
|
4279
|
-
}
|
|
4280
|
-
if (Object.keys(objectFields).length > 0) dataType = objectFields;
|
|
4281
|
-
} else if (propData.dataType === "dimension") dataType = {
|
|
4282
|
-
mode: "string",
|
|
4283
|
-
value: "number"
|
|
4284
|
-
};
|
|
4285
|
-
else if (propData.dataType === "event") dataType = "function";
|
|
4286
|
-
else if (propData.dataType === "string" || propData.dataType === "number" || propData.dataType === "boolean" || propData.dataType === "array" || propData.dataType === "function") dataType = propData.dataType;
|
|
4287
|
-
else dataType = "unknown";
|
|
4288
|
-
return dataType;
|
|
4289
|
-
};
|
|
4290
|
-
|
|
4291
|
-
//#endregion
|
|
4292
|
-
//#region src/lib/internal-details/lib/features/component-registry.ts
|
|
4293
|
-
/**
|
|
4294
|
-
* TODO: The component registry could be split into two a thin layer always on, and move some stuff to the EditStore.
|
|
4295
|
-
* Some of the actions (rename, delete) and some of the data (isDroppable) are editor-only.
|
|
4296
|
-
*/
|
|
4297
|
-
var ComponentRegistry = class {
|
|
4298
|
-
_typeRegistry = /* @__PURE__ */ new Map();
|
|
4299
|
-
_customComponentRegistry = /* @__PURE__ */ new Map();
|
|
4300
|
-
_managedPropsRegistry = /* @__PURE__ */ new Map();
|
|
4301
|
-
_internalPropsRegistry = /* @__PURE__ */ new Map();
|
|
4302
|
-
_editorTemplatesRegistry = /* @__PURE__ */ new Map();
|
|
4303
|
-
_editorConfigsRegistry = /* @__PURE__ */ new Map();
|
|
4304
|
-
_defaultContainerType;
|
|
4305
|
-
_defaultButtonType;
|
|
4306
|
-
_defaultTextType;
|
|
4307
|
-
constructor(rootStore) {
|
|
4308
|
-
this.rootStore = rootStore;
|
|
4309
|
-
makeAutoObservable(this);
|
|
4310
|
-
startEditorSync({
|
|
4311
|
-
store: this,
|
|
4312
|
-
storeId: "component-registry",
|
|
4313
|
-
keys: {
|
|
4314
|
-
customComponentList: true,
|
|
4315
|
-
libraryComponentCatalogs: true,
|
|
4316
|
-
libraryComponentEditorConfigs: true,
|
|
4317
|
-
entityDefinitions: true,
|
|
4318
|
-
componentsWithCallFunctions: true
|
|
4319
|
-
}
|
|
4320
|
-
});
|
|
4321
|
-
}
|
|
4322
|
-
addType(type, component) {
|
|
4323
|
-
this._typeRegistry.set(type, component);
|
|
4324
|
-
}
|
|
4325
|
-
addCustomComponent(type, component) {
|
|
4326
|
-
this._customComponentRegistry.set(type, component);
|
|
4327
|
-
}
|
|
4328
|
-
deleteCustomComponent(type) {
|
|
4329
|
-
this._customComponentRegistry.delete(type);
|
|
4330
|
-
this._managedPropsRegistry.delete(type);
|
|
4331
|
-
this._editorTemplatesRegistry.delete(type);
|
|
4332
|
-
}
|
|
4333
|
-
renameCustomComponent(oldName, newName) {
|
|
4334
|
-
const component = this._customComponentRegistry.get(oldName);
|
|
4335
|
-
const managedProps = this._managedPropsRegistry.get(oldName);
|
|
4336
|
-
if (component) {
|
|
4337
|
-
this._customComponentRegistry.set(newName, component);
|
|
4338
|
-
this._customComponentRegistry.delete(oldName);
|
|
4339
|
-
if (managedProps) {
|
|
4340
|
-
this._managedPropsRegistry.set(newName, managedProps);
|
|
4341
|
-
this._managedPropsRegistry.delete(oldName);
|
|
4342
|
-
}
|
|
4343
|
-
}
|
|
4344
|
-
}
|
|
4345
|
-
addManagedProps(type, props) {
|
|
4346
|
-
this._managedPropsRegistry.set(type, props);
|
|
4347
|
-
}
|
|
4348
|
-
deleteManagedProps(type) {
|
|
4349
|
-
this._managedPropsRegistry.delete(type);
|
|
4350
|
-
}
|
|
4351
|
-
addEditorTemplate(type, template) {
|
|
4352
|
-
const existingTemplates = this._editorTemplatesRegistry.get(type) ?? [];
|
|
4353
|
-
if (existingTemplates.some((t) => t.catalog?.displayName === template.catalog?.displayName && t.catalog?.category === template.catalog?.category)) return;
|
|
4354
|
-
this._editorTemplatesRegistry.set(type, [...existingTemplates, template]);
|
|
4355
|
-
}
|
|
4356
|
-
getEditorTemplates(type) {
|
|
4357
|
-
return this._editorTemplatesRegistry.get(type);
|
|
4358
|
-
}
|
|
4359
|
-
addEditorConfig(type, config) {
|
|
4360
|
-
if (config.useAs) {
|
|
4361
|
-
if (config.useAs.defaultContainer) this._defaultContainerType = type;
|
|
4362
|
-
if (config.useAs.defaultButton) this._defaultButtonType = type;
|
|
4363
|
-
if (config.useAs.defaultText) this._defaultTextType = type;
|
|
4364
|
-
}
|
|
4365
|
-
this._editorConfigsRegistry.set(type, config);
|
|
4366
|
-
}
|
|
4367
|
-
addInternalProps(type, props) {
|
|
4368
|
-
this._internalPropsRegistry.set(type, props);
|
|
4369
|
-
}
|
|
4370
|
-
getInternalProps(type) {
|
|
4371
|
-
return this._internalPropsRegistry.get(type) ?? [];
|
|
4372
|
-
}
|
|
4373
|
-
getEditorConfig(type) {
|
|
4374
|
-
return this._editorConfigsRegistry.get(type);
|
|
4375
|
-
}
|
|
4376
|
-
get entityDefinitions() {
|
|
4377
|
-
const entityDefinitions = {};
|
|
4378
|
-
for (const [componentType, componentData] of [...this._typeRegistry.entries(), ...this._customComponentRegistry.entries()]) {
|
|
4379
|
-
const propertiesDefinition = componentData.propertiesDefinition;
|
|
4380
|
-
if (!propertiesDefinition) continue;
|
|
4381
|
-
const entityDefinition = {
|
|
4382
|
-
description: this.getEditorConfig(componentType)?.description,
|
|
4383
|
-
props: {}
|
|
4384
|
-
};
|
|
4385
|
-
for (const section of Object.values(propertiesDefinition)) for (const [propKey, prop] of Object.entries(section.props)) {
|
|
4386
|
-
const propData = prop.build();
|
|
4387
|
-
if (propData && propData.isExternallyReadable) {
|
|
4388
|
-
const dataType = analyzePropertyType(propData, prop);
|
|
4389
|
-
const entityDefEntry = {
|
|
4390
|
-
label: propData.docs?.label,
|
|
4391
|
-
description: propData.docs?.description,
|
|
4392
|
-
isSettable: propData.isExternallySettable,
|
|
4393
|
-
priority: propData.docs?.priority,
|
|
4394
|
-
dataType
|
|
4395
|
-
};
|
|
4396
|
-
entityDefinition.props[propKey] = entityDefEntry;
|
|
4397
|
-
}
|
|
4398
|
-
}
|
|
4399
|
-
entityDefinitions[componentType] = entityDefinition;
|
|
4400
|
-
}
|
|
4401
|
-
return entityDefinitions;
|
|
4402
|
-
}
|
|
4403
|
-
get libraryComponentCatalogs() {
|
|
4404
|
-
return Array.from(this._editorTemplatesRegistry.entries()).flatMap(([componentType, templates]) => {
|
|
4405
|
-
return templates.reduce((acc, template) => {
|
|
4406
|
-
const catalog = template.catalog;
|
|
4407
|
-
if (catalog) return [...acc, {
|
|
4408
|
-
...catalog,
|
|
4409
|
-
componentType
|
|
4410
|
-
}];
|
|
4411
|
-
return acc;
|
|
4412
|
-
}, []);
|
|
4413
|
-
});
|
|
4414
|
-
}
|
|
4415
|
-
get libraryComponentEditorConfigs() {
|
|
4416
|
-
return Object.fromEntries(this._editorConfigsRegistry.entries());
|
|
4417
|
-
}
|
|
4418
|
-
get customComponentList() {
|
|
4419
|
-
return Array.from(this._customComponentRegistry.keys());
|
|
4420
|
-
}
|
|
4421
|
-
get containerTypes() {
|
|
4422
|
-
return new Set([this.defaultTagNames.container]);
|
|
4423
|
-
}
|
|
4424
|
-
get defaultTagNames() {
|
|
4425
|
-
if (!this._defaultContainerType) console.warn("No default container registered - defaulting to 'Container'.");
|
|
4426
|
-
if (!this._defaultButtonType) console.warn("No default button registered - defaulting to 'Button'.");
|
|
4427
|
-
if (!this._defaultTextType) console.warn("No default text registered - defaulting to 'Text'.");
|
|
4428
|
-
return {
|
|
4429
|
-
container: this._defaultContainerType ?? "Container",
|
|
4430
|
-
button: this._defaultButtonType ?? "Button",
|
|
4431
|
-
text: this._defaultTextType ?? "Text"
|
|
4432
|
-
};
|
|
4433
|
-
}
|
|
4434
|
-
get managedPropsRegistry() {
|
|
4435
|
-
return this._managedPropsRegistry;
|
|
4436
|
-
}
|
|
4437
|
-
getManagedProps(type) {
|
|
4438
|
-
return this._managedPropsRegistry.get(type) ?? [];
|
|
4439
|
-
}
|
|
4440
|
-
getComponent(type) {
|
|
4441
|
-
return this._typeRegistry.get(type) ?? this._customComponentRegistry.get(type);
|
|
4442
|
-
}
|
|
4443
|
-
/**
|
|
4444
|
-
* Get the property path with the record identifier if it exists. For example,
|
|
4445
|
-
* `columns.columnName.label` becomes `columns.*.label`, for record properties.
|
|
4446
|
-
*/
|
|
4447
|
-
getPropertyWithRecordIdentifier(type, path) {
|
|
4448
|
-
const managedProps = this.getManagedProps(type);
|
|
4449
|
-
const splitPath = path.split(".");
|
|
4450
|
-
if (splitPath.length === 1) return path;
|
|
4451
|
-
const [parentKey, _maybeTheRecordKey, ...rest] = splitPath;
|
|
4452
|
-
for (const prop of managedProps) if (prop.path.startsWith(parentKey) && prop.path.includes(RECORD_PATH_IDENTIFIER) && rest.length > 0 && prop.path.endsWith(rest.join("."))) return [
|
|
4453
|
-
parentKey,
|
|
4454
|
-
RECORD_PATH_IDENTIFIER,
|
|
4455
|
-
rest.join(".")
|
|
4456
|
-
].join(".");
|
|
4457
|
-
return path;
|
|
4458
|
-
}
|
|
4459
|
-
get componentsWithCallFunctions() {
|
|
4460
|
-
return Object.fromEntries(Array.from(this.managedPropsRegistry.entries()).filter(([_$1, props]) => {
|
|
4461
|
-
return props.some((prop) => prop.isFunctionProp);
|
|
4462
|
-
}).map(([type, props]) => {
|
|
4463
|
-
return [type, props.filter((prop) => prop.isFunctionProp && prop.hasActionPanel).map((prop) => ({
|
|
4464
|
-
functionName: prop.path,
|
|
4465
|
-
label: prop.docs?.label,
|
|
4466
|
-
priority: prop.docs?.priority
|
|
4467
|
-
}))];
|
|
4468
|
-
}).filter(([_$1, props]) => props.length > 0));
|
|
4469
|
-
}
|
|
4470
|
-
};
|
|
4471
|
-
|
|
4472
|
-
//#endregion
|
|
4473
|
-
//#region src/lib/internal-details/lib/features/name-manager.ts
|
|
4474
|
-
const DEFAULT_ANONYMOUS_SOURCE_ID = "SB--anon-src";
|
|
4475
|
-
var NameManager = class {
|
|
4476
|
-
_mountedIdentifiers = {};
|
|
4477
|
-
_allPossibleIdentifiers = {};
|
|
4478
|
-
_scopeToNameToIdentifiers = {};
|
|
4479
|
-
_allNamesToIdentifiers = {};
|
|
4480
|
-
_prefixAllocation = {};
|
|
4481
|
-
_instanceIdToPrefixInfo = {};
|
|
4482
|
-
constructor(entityManager) {
|
|
4483
|
-
this.entityManager = entityManager;
|
|
4484
|
-
makeObservable(this, {
|
|
4485
|
-
_mountedIdentifiers: observable,
|
|
4486
|
-
_allPossibleIdentifiers: observable,
|
|
4487
|
-
_scopeToNameToIdentifiers: observable,
|
|
4488
|
-
_allNamesToIdentifiers: observable,
|
|
4489
|
-
registerIdentifier: action,
|
|
4490
|
-
unregisterIdentifier: action,
|
|
4491
|
-
registerAndGetIdentifiers: action,
|
|
4492
|
-
changeWidgetName: action
|
|
4493
|
-
});
|
|
4494
|
-
}
|
|
4495
|
-
get scopeToNameToIds() {
|
|
4496
|
-
return this._scopeToNameToIdentifiers;
|
|
4497
|
-
}
|
|
4498
|
-
getWidgetName(instanceId) {
|
|
4499
|
-
return this._mountedIdentifiers[instanceId]?.name;
|
|
4500
|
-
}
|
|
4501
|
-
hasEntityWithName(name) {
|
|
4502
|
-
return Object.keys(this._allNamesToIdentifiers[name] ?? {}).length > 0;
|
|
4503
|
-
}
|
|
4504
|
-
hasDuplicateNames(scopeId, name) {
|
|
4505
|
-
return this.getSharedNameCount(scopeId, name) > 1;
|
|
4506
|
-
}
|
|
4507
|
-
nextNameAndIdForCombination(params) {
|
|
4508
|
-
const instancePrefix = params.rootId ? `${params.sourceId}-${params.scopeId}-${params.rootId}` : `${params.sourceId}-${params.scopeId}`;
|
|
4509
|
-
this._prefixAllocation[instancePrefix] ??= {
|
|
4510
|
-
usedIndices: /* @__PURE__ */ new Set(),
|
|
4511
|
-
guaranteedIndex: 0,
|
|
4512
|
-
optimisticIndex: null
|
|
4513
|
-
};
|
|
4514
|
-
const allocation = this._prefixAllocation[instancePrefix];
|
|
4515
|
-
let order = allocation.guaranteedIndex;
|
|
4516
|
-
if (allocation.optimisticIndex != null && !allocation.usedIndices.has(allocation.optimisticIndex)) {
|
|
4517
|
-
order = allocation.optimisticIndex;
|
|
4518
|
-
if (allocation.optimisticIndex + 1 >= allocation.guaranteedIndex) allocation.optimisticIndex = null;
|
|
4519
|
-
else allocation.optimisticIndex += 1;
|
|
4520
|
-
} else {
|
|
4521
|
-
order = allocation.guaranteedIndex;
|
|
4522
|
-
allocation.guaranteedIndex += 1;
|
|
4523
|
-
}
|
|
4524
|
-
allocation.usedIndices.add(order);
|
|
4525
|
-
const instanceId = `I-${`${instancePrefix}-${order}`}`;
|
|
4526
|
-
this._instanceIdToPrefixInfo[instanceId] = {
|
|
4527
|
-
prefix: instancePrefix,
|
|
4528
|
-
index: order
|
|
4529
|
-
};
|
|
4530
|
-
return {
|
|
4531
|
-
name: {
|
|
4532
|
-
value: params.name == null ? `anon-${instanceId}` : params.name,
|
|
4533
|
-
isAnonymous: params.name == null,
|
|
4534
|
-
__isName: true
|
|
4535
|
-
},
|
|
4536
|
-
instanceId
|
|
4537
|
-
};
|
|
4538
|
-
}
|
|
4539
|
-
trackIdentifier(identifier) {
|
|
4540
|
-
const { scopeId, instanceId, name } = identifier;
|
|
4541
|
-
set(this._scopeToNameToIdentifiers, [
|
|
4542
|
-
scopeId,
|
|
4543
|
-
name.value,
|
|
4544
|
-
instanceId
|
|
4545
|
-
], identifier);
|
|
4546
|
-
set(this._allNamesToIdentifiers, [name.value, instanceId], identifier);
|
|
4547
|
-
this._mountedIdentifiers[instanceId] = identifier;
|
|
4548
|
-
}
|
|
4549
|
-
untrackIdentifier(instanceId) {
|
|
4550
|
-
const identifier = this._mountedIdentifiers[instanceId];
|
|
4551
|
-
if (!identifier) return;
|
|
4552
|
-
const { scopeId, name } = identifier;
|
|
4553
|
-
if (get(this._scopeToNameToIdentifiers, [
|
|
4554
|
-
scopeId,
|
|
4555
|
-
name.value,
|
|
4556
|
-
instanceId
|
|
4557
|
-
])) delete this._scopeToNameToIdentifiers[scopeId][name.value][instanceId];
|
|
4558
|
-
if (get(this._allNamesToIdentifiers, [name.value, instanceId])) delete this._allNamesToIdentifiers[name.value][instanceId];
|
|
4559
|
-
delete this._mountedIdentifiers[instanceId];
|
|
4560
|
-
const prefixInfo = this._instanceIdToPrefixInfo[instanceId];
|
|
4561
|
-
if (prefixInfo) {
|
|
4562
|
-
const allocation = this._prefixAllocation[prefixInfo.prefix];
|
|
4563
|
-
if (allocation) {
|
|
4564
|
-
allocation.usedIndices.delete(prefixInfo.index);
|
|
4565
|
-
if (allocation.usedIndices.size === 0) delete this._prefixAllocation[prefixInfo.prefix];
|
|
4566
|
-
else if (allocation.optimisticIndex == null || allocation.optimisticIndex > prefixInfo.index) allocation.optimisticIndex = prefixInfo.index;
|
|
4567
|
-
}
|
|
4568
|
-
delete this._instanceIdToPrefixInfo[instanceId];
|
|
4569
|
-
}
|
|
4570
|
-
}
|
|
4571
|
-
registerIdentifier(identifier) {
|
|
4572
|
-
this.trackIdentifier(identifier);
|
|
4573
|
-
}
|
|
4574
|
-
unregisterIdentifier(instanceId) {
|
|
4575
|
-
this.untrackIdentifier(instanceId);
|
|
4576
|
-
}
|
|
4577
|
-
getExistingIdentifier(instanceId) {
|
|
4578
|
-
const identifier = this._allPossibleIdentifiers[instanceId];
|
|
4579
|
-
if (!identifier) {
|
|
4580
|
-
console.log(`No identifier found for instanceId ${instanceId}`);
|
|
4581
|
-
return;
|
|
4582
|
-
}
|
|
4583
|
-
return identifier;
|
|
4584
|
-
}
|
|
4585
|
-
registerAndGetIdentifiers(params) {
|
|
4586
|
-
const { sourceId = DEFAULT_ANONYMOUS_SOURCE_ID, scopeId, rootId, existingInstanceId, type } = params;
|
|
4587
|
-
if (existingInstanceId) {
|
|
4588
|
-
const identifier$1 = this.getExistingIdentifier(existingInstanceId);
|
|
4589
|
-
if (identifier$1) return identifier$1;
|
|
4590
|
-
}
|
|
4591
|
-
const { name, instanceId } = this.nextNameAndIdForCombination({
|
|
4592
|
-
sourceId,
|
|
4593
|
-
scopeId,
|
|
4594
|
-
rootId,
|
|
4595
|
-
name: params.name
|
|
4596
|
-
});
|
|
4597
|
-
if (this._mountedIdentifiers[instanceId]) return this._mountedIdentifiers[instanceId];
|
|
4598
|
-
const identifier = {
|
|
4599
|
-
sourceId,
|
|
4600
|
-
name,
|
|
4601
|
-
instanceId,
|
|
4602
|
-
scopeId,
|
|
4603
|
-
type
|
|
4604
|
-
};
|
|
4605
|
-
this._allPossibleIdentifiers[instanceId] = identifier;
|
|
4606
|
-
return identifier;
|
|
4607
|
-
}
|
|
4608
|
-
getSharedNameCount(scopeId, name) {
|
|
4609
|
-
return Object.keys(this._scopeToNameToIdentifiers[scopeId]?.[name] ?? {}).length;
|
|
4610
|
-
}
|
|
4611
|
-
changeWidgetName(instanceId, _newName) {
|
|
4612
|
-
const existingIdentifier = this._mountedIdentifiers[instanceId];
|
|
4613
|
-
if (!existingIdentifier) return null;
|
|
4614
|
-
const existingNameCount = this.getSharedNameCount(existingIdentifier.scopeId, existingIdentifier.name.value);
|
|
4615
|
-
const newName = _newName == null ? `anon-${instanceId}` : _newName;
|
|
4616
|
-
const name = {
|
|
4617
|
-
value: newName,
|
|
4618
|
-
isAnonymous: newName == null,
|
|
4619
|
-
__isName: true
|
|
4620
|
-
};
|
|
4621
|
-
const newIdentifier = {
|
|
4622
|
-
...existingIdentifier,
|
|
4623
|
-
name
|
|
4624
|
-
};
|
|
4625
|
-
this.untrackIdentifier(existingIdentifier.instanceId);
|
|
4626
|
-
this.trackIdentifier(newIdentifier);
|
|
4627
|
-
this.entityManager.renameEntity({
|
|
4628
|
-
scopeId: existingIdentifier.scopeId,
|
|
4629
|
-
instanceId: existingIdentifier.instanceId,
|
|
4630
|
-
newName: name,
|
|
4631
|
-
isDuplicate: existingNameCount > 1
|
|
4632
|
-
});
|
|
4633
|
-
return newIdentifier;
|
|
4634
|
-
}
|
|
4635
|
-
};
|
|
4636
|
-
|
|
4637
|
-
//#endregion
|
|
4638
|
-
//#region src/lib/internal-details/lib/root-store.ts
|
|
4639
|
-
var RootStore = class {
|
|
4640
|
-
apis;
|
|
4641
|
-
nameManager;
|
|
4642
|
-
entityManager;
|
|
4643
|
-
componentRegistry;
|
|
4644
|
-
editStore;
|
|
4645
|
-
locationStore;
|
|
4646
|
-
currentPageScopeId;
|
|
4647
|
-
applicationId;
|
|
4648
|
-
userId;
|
|
4649
|
-
windowOriginUrl;
|
|
4650
|
-
editorRegisteredCallbacks = [];
|
|
4651
|
-
apisLoaded = false;
|
|
4652
|
-
appLoadedCallbacks = [];
|
|
4653
|
-
pageLoadedCallbacks = /* @__PURE__ */ new Map();
|
|
4654
|
-
constructor() {
|
|
4655
|
-
this.apis = new api_store_default(this);
|
|
4656
|
-
this.componentRegistry = new ComponentRegistry(this);
|
|
4657
|
-
this.entityManager = new EntityManager(this.componentRegistry, { devtools: true });
|
|
4658
|
-
this.nameManager = new NameManager(this.entityManager);
|
|
4659
|
-
this.locationStore = new LocationStore(this);
|
|
4660
|
-
this.entityManager.createEntity({
|
|
4661
|
-
name: getName("Global"),
|
|
4662
|
-
type: "global",
|
|
4663
|
-
props: {},
|
|
4664
|
-
scopeId: GLOBAL_SCOPE_ID
|
|
4665
|
-
});
|
|
4666
|
-
makeObservable(this, {
|
|
4667
|
-
editStore: observable.shallow,
|
|
4668
|
-
setEditStore: action,
|
|
4669
|
-
applicationId: observable,
|
|
4670
|
-
userId: observable
|
|
4671
|
-
});
|
|
4672
|
-
}
|
|
4673
|
-
setEditStore(editStore) {
|
|
4674
|
-
if (this.editStore) return;
|
|
4675
|
-
this.editStore = editStore;
|
|
4676
|
-
this.editorRegisteredCallbacks.forEach((fn) => fn());
|
|
4677
|
-
this.editorRegisteredCallbacks = [];
|
|
4678
|
-
}
|
|
4679
|
-
onEditorRegistered(fn) {
|
|
4680
|
-
this.editorRegisteredCallbacks.push(fn);
|
|
4681
|
-
}
|
|
4682
|
-
/**
|
|
4683
|
-
* There is a timing problem here between when the APIs are registered and when the scope entities are registered.
|
|
4684
|
-
* Regardless of which one is done first, we need to wait for both before firing page load actions
|
|
4685
|
-
*/
|
|
4686
|
-
setApisLoaded() {
|
|
4687
|
-
this.apisLoaded = true;
|
|
4688
|
-
this.fireAppLoadedCallbacks();
|
|
4689
|
-
if (this.currentPageScopeId) this.firePageLoadedCallbacks(this.currentPageScopeId);
|
|
4690
|
-
}
|
|
4691
|
-
fireAppLoadedCallbacks() {
|
|
4692
|
-
if (!this.apisLoaded) return;
|
|
4693
|
-
for (const fn of this.appLoadedCallbacks) fn();
|
|
4694
|
-
}
|
|
4695
|
-
onAppLoaded(fn) {
|
|
4696
|
-
this.appLoadedCallbacks.push(fn);
|
|
4697
|
-
return () => {
|
|
4698
|
-
this.appLoadedCallbacks.filter((cb) => cb !== fn);
|
|
4699
|
-
};
|
|
4700
|
-
}
|
|
4701
|
-
firePageLoadedCallbacks(scopeId) {
|
|
4702
|
-
if (!this.apisLoaded) return;
|
|
4703
|
-
this.pageLoadedCallbacks.get(scopeId)?.forEach((fn) => fn());
|
|
4704
|
-
}
|
|
4705
|
-
onPageLoaded(scopeId, fn) {
|
|
4706
|
-
const callbacks = this.pageLoadedCallbacks.get(scopeId) || [];
|
|
4707
|
-
callbacks.push(fn);
|
|
4708
|
-
this.pageLoadedCallbacks.set(scopeId, callbacks);
|
|
4709
|
-
return () => {
|
|
4710
|
-
this.pageLoadedCallbacks.set(scopeId, callbacks.filter((cb) => cb !== fn));
|
|
4711
|
-
};
|
|
4712
|
-
}
|
|
4713
|
-
get isApisLoaded() {
|
|
4714
|
-
return this.apisLoaded;
|
|
4715
|
-
}
|
|
4716
|
-
};
|
|
4717
|
-
var root_store_default = new RootStore();
|
|
4718
|
-
|
|
4719
|
-
//#endregion
|
|
4720
|
-
export { getName as A, Section as C, NavigationEvent as D, run_event_handlers_default as E, isEmbeddedBySuperblocksFirstParty as F, isEditMode as I, getEditStore as L, isNameEqual as M, editorBridge as N, navigation as O, iframeMessageHandler as P, RecordProp as S, createPropertiesPanelDefinition as T, DevTools as _, addNewPromise as a, Prop as b, FileManager as c, CLASS_NAMES as d, colors as f, EventFlow as g, LazyFunction as h, generateId as i, isName as j, isLocalLink as k, getFileWithUploadId as l, GLOBAL_SCOPE_ID as m, DEFAULT_ANONYMOUS_SOURCE_ID as n, rejectById as o, system_error_default as p, startEditorSync as r, resolveById as s, root_store_default as t, sendNotification as u, createInternalPropsList as v, VALIDATORS as w, PropsPanelCategory as x, createManagedPropsList as y };
|
|
4721
|
-
//# sourceMappingURL=root-store-Cc3dO2jP.js.map
|