@superblocksteam/library 2.0.55 → 2.0.56-next.1
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/{build-manifest-BNJahcH4.js → build-manifest-DZwcz6uX.js} +1 -1
- package/dist/{build-manifest-BNJahcH4.js.map → build-manifest-DZwcz6uX.js.map} +1 -1
- 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 +5007 -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-DxFT8zmk.js +3068 -0
- package/dist/widget-wrapper-naming-DxFT8zmk.js.map +1 -0
- package/package.json +27 -14
- 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
|
@@ -0,0 +1,3068 @@
|
|
|
1
|
+
import { t as getTracer } from "./utils-AzBGeVXo.js";
|
|
2
|
+
import { getQueryParams, pathStringToArray, toMobXPatch } from "@superblocksteam/library-shared";
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
import React, { createContext, isValidElement, useCallback, useContext, useSyncExternalStore } from "react";
|
|
5
|
+
import { action, entries, isComputedProp, isObservableArray, isObservableMap, isObservableObject, makeAutoObservable, makeObservable, observable, observe, reaction, toJS, values } from "mobx";
|
|
6
|
+
import { matchRoutes } from "react-router";
|
|
7
|
+
import { pick, throttle } from "lodash";
|
|
8
|
+
import { ApiResponseType, OrchestratorViewMode, SUPERBLOCKS_AUTHORIZATION_HEADER, SUPERBLOCKS_REQUEST_ID_HEADER, ViewMode, decodeBytestrings } from "@superblocksteam/shared";
|
|
9
|
+
import { NotificationPosition } from "@superblocksteam/library-shared/types";
|
|
10
|
+
import isString from "lodash/isString";
|
|
11
|
+
import { toast } from "sonner";
|
|
12
|
+
import styled from "styled-components";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { ROOT_CONTEXT, context, propagation, trace } from "@opentelemetry/api";
|
|
15
|
+
import diff from "microdiff";
|
|
16
|
+
import { InputType, PropsCategory } from "@superblocksteam/library-shared/props";
|
|
17
|
+
|
|
18
|
+
//#region src/lib/internal-details/is-edit-mode.ts
|
|
19
|
+
const getIsEditMode = () => {
|
|
20
|
+
return window._SB_VIEW_MODE === "dev";
|
|
21
|
+
};
|
|
22
|
+
let editMode;
|
|
23
|
+
const isEditMode = () => {
|
|
24
|
+
if (editMode === void 0) editMode = getIsEditMode();
|
|
25
|
+
return editMode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/lib/utils/clean-object.ts
|
|
30
|
+
const isReactElement = (obj) => {
|
|
31
|
+
return obj && (obj.$$typeof === Symbol.for("react.element") || isValidElement(obj) || typeof Node !== "undefined" && obj instanceof Node);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Cleans an object by removing proxy wrappers and filtering out functions.
|
|
35
|
+
* This is useful for preparing objects for JSON serialization.
|
|
36
|
+
*/
|
|
37
|
+
function cleanObject(obj) {
|
|
38
|
+
obj = toJS(obj);
|
|
39
|
+
if (!obj || typeof obj !== "object") return typeof obj === "function" ? void 0 : obj;
|
|
40
|
+
if (Array.isArray(obj)) return obj.map(cleanObject).filter((item) => item !== void 0);
|
|
41
|
+
if (isReactElement(obj)) return;
|
|
42
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
43
|
+
if (obj === value || key === "bind") return acc;
|
|
44
|
+
const cleaned = cleanObject(value);
|
|
45
|
+
if (cleaned !== void 0) acc[key] = cleaned;
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/lib/internal-details/lib/iframe.ts
|
|
52
|
+
function isEmbeddedBySuperblocksFirstParty() {
|
|
53
|
+
return typeof window !== "undefined" && window !== window.parent;
|
|
54
|
+
}
|
|
55
|
+
const PARENT_REF = typeof window !== "undefined" && window !== window.parent ? window.parent : null;
|
|
56
|
+
const SELF_REF = typeof window !== "undefined" ? window : null;
|
|
57
|
+
function parentMessageHandler(e) {
|
|
58
|
+
if (e.source !== PARENT_REF && e.source !== SELF_REF) return;
|
|
59
|
+
const event = new SbIframeEventInternal(e.data.type, e.data);
|
|
60
|
+
iframeMessageHandler.dispatchEvent(event);
|
|
61
|
+
}
|
|
62
|
+
if (isEmbeddedBySuperblocksFirstParty() && PARENT_REF) typeof window !== "undefined" && window.addEventListener("message", parentMessageHandler);
|
|
63
|
+
/** @deprecated Use editorBridge instead */
|
|
64
|
+
function sendMessageImmediately(message, options) {
|
|
65
|
+
if (!PARENT_REF) {
|
|
66
|
+
console.warn("PARENT_REF is not set, message not delivered. Message: ", message);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
message = cleanObject(message);
|
|
70
|
+
if (isEmbeddedBySuperblocksFirstParty()) {
|
|
71
|
+
if (!PARENT_REF) throw new Error("Parent is not set");
|
|
72
|
+
try {
|
|
73
|
+
PARENT_REF.postMessage({
|
|
74
|
+
...message,
|
|
75
|
+
startTime: options?.overrideStartTime ?? +/* @__PURE__ */ new Date()
|
|
76
|
+
}, "*");
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error("Error sending message to parent", message, e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var SbIframeEventInternal = class extends Event {
|
|
83
|
+
data;
|
|
84
|
+
constructor(type, data) {
|
|
85
|
+
super(type);
|
|
86
|
+
this.data = data;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var SbMessageHandler = class extends EventTarget {};
|
|
90
|
+
const iframeMessageHandler = new SbMessageHandler();
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/edit-mode/base-editor-bridge.ts
|
|
94
|
+
var DeployedParentBridge = class {
|
|
95
|
+
navigateTo(url, newWindow) {
|
|
96
|
+
sendMessageImmediately({
|
|
97
|
+
type: "navigate-to",
|
|
98
|
+
payload: {
|
|
99
|
+
url,
|
|
100
|
+
newWindow
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
connected() {}
|
|
105
|
+
sendReady() {}
|
|
106
|
+
sendLoadError(_error) {}
|
|
107
|
+
sendNotification(_type, _message, _description) {}
|
|
108
|
+
selectWidgets(_sourceIds) {}
|
|
109
|
+
editOpRequest(_type, _payload) {}
|
|
110
|
+
undo() {}
|
|
111
|
+
redo() {}
|
|
112
|
+
sendStreamedApiEvent(_event, _apiName) {}
|
|
113
|
+
sendStreamedApiMessage(_message, _apiName) {}
|
|
114
|
+
setApiStarted(_apiName) {}
|
|
115
|
+
setApiResponse(_apiName, _response) {}
|
|
116
|
+
updatePropertiesPanels(_updates) {}
|
|
117
|
+
addPropertiesPanel(_id, _definition) {}
|
|
118
|
+
addApiRunRecord(_apiId, _run) {}
|
|
119
|
+
updateApiRunRecord(_apiId, _callId, _updates) {}
|
|
120
|
+
initializeEditorSyncedStore(_payload) {}
|
|
121
|
+
updateEditorSyncedStore(_payload) {}
|
|
122
|
+
resolvePromise(_callbackId, _payload) {}
|
|
123
|
+
rejectPromise(_callbackId, _payload) {}
|
|
124
|
+
canvasClicked() {}
|
|
125
|
+
registerContextMenuClick(_sourceId, _clientX, _clientY) {}
|
|
126
|
+
updateRoute(routeInfo) {
|
|
127
|
+
sendMessageImmediately({
|
|
128
|
+
type: "route-change",
|
|
129
|
+
payload: routeInfo
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
socketError(_message) {}
|
|
133
|
+
aiGenerate(_prompt) {}
|
|
134
|
+
addComponentToAiContext(_sourceId, _selectorId) {}
|
|
135
|
+
toggleComponentInAiContext(_sourceId, _selectorId, _label) {}
|
|
136
|
+
setAiContextMode(_mode) {}
|
|
137
|
+
sendAiLoaderState(_shouldShowLoader) {}
|
|
138
|
+
sendRuntimeError(_data) {}
|
|
139
|
+
sendClearRuntimeError(_id) {}
|
|
140
|
+
setInteractionMode(_mode) {}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/edit-mode/get-edit-store.ts
|
|
145
|
+
/**
|
|
146
|
+
* Get the global EditStore instance
|
|
147
|
+
* @returns The EditStore instance
|
|
148
|
+
*/
|
|
149
|
+
function getEditStore() {
|
|
150
|
+
if (!window.__SUPERBLOCKS_EDITOR_HOOK__ || !window.__SUPERBLOCKS_EDITOR_HOOK__.isInitialized) throw new Error("EditStore not initialized");
|
|
151
|
+
return window.__SUPERBLOCKS_EDITOR_HOOK__;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/edit-mode/message-queue.ts
|
|
156
|
+
const MESSAGE_BATCH_TIME = 50;
|
|
157
|
+
const DEFAULT_KEY = "default";
|
|
158
|
+
var MessageQueue = class {
|
|
159
|
+
keyedActionQueue = {};
|
|
160
|
+
constructor() {}
|
|
161
|
+
flattenKeyedQueue() {
|
|
162
|
+
return Object.values(this.keyedActionQueue).flat();
|
|
163
|
+
}
|
|
164
|
+
triggerSendFromQueue = throttle(() => {
|
|
165
|
+
sendMessageImmediately({
|
|
166
|
+
type: "iframe-action-batch",
|
|
167
|
+
payload: this.flattenKeyedQueue()
|
|
168
|
+
}, { overrideStartTime: Date.now() - MESSAGE_BATCH_TIME });
|
|
169
|
+
this.keyedActionQueue = {};
|
|
170
|
+
}, MESSAGE_BATCH_TIME);
|
|
171
|
+
queueMessage(message, mergeOptions) {
|
|
172
|
+
if (mergeOptions) {
|
|
173
|
+
const { key, mergeFn } = mergeOptions;
|
|
174
|
+
this.keyedActionQueue[key] ??= [];
|
|
175
|
+
this.keyedActionQueue[key] = mergeFn(this.keyedActionQueue[key], message);
|
|
176
|
+
} else {
|
|
177
|
+
this.keyedActionQueue[DEFAULT_KEY] ??= [];
|
|
178
|
+
this.keyedActionQueue[DEFAULT_KEY].push(message);
|
|
179
|
+
}
|
|
180
|
+
this.triggerSendFromQueue();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var message_queue_default = new MessageQueue();
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/edit-mode/superblocks-editor-bridge.ts
|
|
187
|
+
var SuperblocksEditorBridge = class SuperblocksEditorBridge {
|
|
188
|
+
static instance;
|
|
189
|
+
messagesToSend = [];
|
|
190
|
+
connectedToParent = false;
|
|
191
|
+
static getInstance() {
|
|
192
|
+
const editMode$1 = isEditMode();
|
|
193
|
+
if (!SuperblocksEditorBridge.instance) SuperblocksEditorBridge.instance = editMode$1 ? new SuperblocksEditorBridge() : new DeployedParentBridge();
|
|
194
|
+
return SuperblocksEditorBridge.instance;
|
|
195
|
+
}
|
|
196
|
+
connected() {
|
|
197
|
+
this.connectedToParent = true;
|
|
198
|
+
this.messagesToSend.forEach((message) => this.queueMessage(message.payload, message.mergeOptions));
|
|
199
|
+
this.messagesToSend = [];
|
|
200
|
+
}
|
|
201
|
+
sendReady() {
|
|
202
|
+
this.sendImmediate({
|
|
203
|
+
type: "sb-ready",
|
|
204
|
+
payload: void 0
|
|
205
|
+
}, true);
|
|
206
|
+
}
|
|
207
|
+
sendLoadError(error) {
|
|
208
|
+
this.sendImmediate({
|
|
209
|
+
type: "sb-load-error",
|
|
210
|
+
payload: { error }
|
|
211
|
+
}, true);
|
|
212
|
+
}
|
|
213
|
+
sendNotification(type, message, description) {
|
|
214
|
+
this.queueMessage({
|
|
215
|
+
type: "codeMode/sendNotification",
|
|
216
|
+
payload: {
|
|
217
|
+
type,
|
|
218
|
+
message,
|
|
219
|
+
description
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
selectWidgets(sourceIds) {
|
|
224
|
+
this.queueMessage({
|
|
225
|
+
type: "client:selectWidgets",
|
|
226
|
+
payload: { sourceIds }
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
editOpRequest(type, payload) {
|
|
230
|
+
this.sendImmediate({
|
|
231
|
+
type: "sb-edit-operation-request",
|
|
232
|
+
payload: {
|
|
233
|
+
type,
|
|
234
|
+
payload
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
undo() {
|
|
239
|
+
this.sendImmediate({
|
|
240
|
+
type: "undo",
|
|
241
|
+
payload: void 0
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
redo() {
|
|
245
|
+
this.sendImmediate({
|
|
246
|
+
type: "redo",
|
|
247
|
+
payload: void 0
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
sendStreamedApiEvent(event, apiName) {
|
|
251
|
+
this.sendImmediate({
|
|
252
|
+
type: "api/stream-event",
|
|
253
|
+
payload: {
|
|
254
|
+
event,
|
|
255
|
+
apiName
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
sendStreamedApiMessage(message, apiName) {
|
|
260
|
+
this.sendImmediate({
|
|
261
|
+
type: "api/stream-message",
|
|
262
|
+
payload: {
|
|
263
|
+
message,
|
|
264
|
+
apiName
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
setApiStarted(apiName) {
|
|
269
|
+
this.sendImmediate({
|
|
270
|
+
type: "api/started-execution",
|
|
271
|
+
payload: { apiName }
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
setApiResponse(apiName, response) {
|
|
275
|
+
this.sendImmediate({
|
|
276
|
+
type: "api/set-api-response",
|
|
277
|
+
payload: {
|
|
278
|
+
apiName,
|
|
279
|
+
response
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
navigateTo(path, newWindow) {
|
|
284
|
+
this.sendImmediate({
|
|
285
|
+
type: "navigate-to",
|
|
286
|
+
payload: {
|
|
287
|
+
url: path,
|
|
288
|
+
newWindow
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
updatePropertiesPanels(updates) {
|
|
293
|
+
this.queueMessage({
|
|
294
|
+
type: "codeMode/updatePropertiesPanels",
|
|
295
|
+
payload: updates
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
addPropertiesPanel(id, definition) {
|
|
299
|
+
this.queueMessage({
|
|
300
|
+
type: "codeMode/addPropertiesPanel",
|
|
301
|
+
payload: {
|
|
302
|
+
id,
|
|
303
|
+
definition
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
addApiRunRecord(apiId, run) {
|
|
308
|
+
this.queueMessage({
|
|
309
|
+
type: "codeMode/addApiRunRecord",
|
|
310
|
+
payload: {
|
|
311
|
+
apiId,
|
|
312
|
+
run
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
updateApiRunRecord(apiId, callId, updates) {
|
|
317
|
+
this.queueMessage({
|
|
318
|
+
type: "codeMode/updateApiRunRecord",
|
|
319
|
+
payload: {
|
|
320
|
+
apiId,
|
|
321
|
+
callId,
|
|
322
|
+
updates
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
initializeEditorSyncedStore(payload) {
|
|
327
|
+
this.queueMessage({
|
|
328
|
+
type: "codeMode/editor-synced-store/init",
|
|
329
|
+
payload
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
mergeSyncedStoreUpdate(existingActions, newAction) {
|
|
333
|
+
if (!existingActions || existingActions.length === 0) return [newAction];
|
|
334
|
+
const firstAction = existingActions[0];
|
|
335
|
+
const newActionPatches = newAction.payload.patch;
|
|
336
|
+
firstAction.payload.patch = Array.isArray(firstAction.payload.patch) ? firstAction.payload.patch : [firstAction.payload.patch];
|
|
337
|
+
firstAction.payload.patch.push(...Array.isArray(newActionPatches) ? newActionPatches : [newActionPatches]);
|
|
338
|
+
return existingActions;
|
|
339
|
+
}
|
|
340
|
+
updateEditorSyncedStore(payload) {
|
|
341
|
+
this.queueMessage({
|
|
342
|
+
type: "codeMode/editor-synced-store/update",
|
|
343
|
+
payload
|
|
344
|
+
}, {
|
|
345
|
+
key: `synced-store-update-${payload.storeId}`,
|
|
346
|
+
mergeFn: this.mergeSyncedStoreUpdate
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
resolvePromise(callbackId, payload) {
|
|
350
|
+
this.sendImmediate({
|
|
351
|
+
type: "resolve-promise",
|
|
352
|
+
callbackId,
|
|
353
|
+
payload
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
rejectPromise(callbackId, payload) {
|
|
357
|
+
this.sendImmediate({
|
|
358
|
+
type: "reject-promise",
|
|
359
|
+
callbackId,
|
|
360
|
+
payload
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
canvasClicked() {
|
|
364
|
+
this.sendImmediate({
|
|
365
|
+
type: "register-click",
|
|
366
|
+
payload: {
|
|
367
|
+
type: "INSIDE_IFRAME_CLICKED",
|
|
368
|
+
context: {
|
|
369
|
+
sourceId: "",
|
|
370
|
+
clientX: 0,
|
|
371
|
+
clientY: 0
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
registerContextMenuClick(sourceId, clientX, clientY) {
|
|
377
|
+
this.sendImmediate({
|
|
378
|
+
type: "register-click",
|
|
379
|
+
payload: {
|
|
380
|
+
type: "OPEN_CONTEXT_MENU",
|
|
381
|
+
context: {
|
|
382
|
+
sourceId,
|
|
383
|
+
clientX,
|
|
384
|
+
clientY
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
updateRoute(routeInfo) {
|
|
390
|
+
this.sendImmediate({
|
|
391
|
+
type: "route-change",
|
|
392
|
+
payload: routeInfo
|
|
393
|
+
}, true);
|
|
394
|
+
}
|
|
395
|
+
addComponentToAiContext(sourceId, selectorId) {
|
|
396
|
+
const editStore = getEditStore();
|
|
397
|
+
if (editStore?.ai.isAlternateSourceIdTarget(sourceId, selectorId)) {
|
|
398
|
+
editStore.ai.addTargetedSelector(selectorId);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
this.sendImmediate({
|
|
402
|
+
type: "ai-updates",
|
|
403
|
+
payload: {
|
|
404
|
+
type: "add-component-to-context",
|
|
405
|
+
component: sourceId
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
toggleComponentInAiContext(sourceId, selectorId, label) {
|
|
410
|
+
const editStore = getEditStore();
|
|
411
|
+
if (editStore?.ai.isAlternateSourceIdTarget(sourceId, selectorId)) {
|
|
412
|
+
editStore.ai.toggleTargetedSelector(selectorId);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
this.sendImmediate({
|
|
416
|
+
type: "ai-updates",
|
|
417
|
+
payload: {
|
|
418
|
+
type: "toggle-component-in-context",
|
|
419
|
+
component: sourceId,
|
|
420
|
+
label
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
setAiContextMode(mode) {
|
|
425
|
+
this.sendImmediate({
|
|
426
|
+
type: "ai-updates",
|
|
427
|
+
payload: {
|
|
428
|
+
type: "set-ai-context-mode",
|
|
429
|
+
mode
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
aiGenerate(prompt, forceSend = false) {
|
|
434
|
+
const sanitizedPrompt = clampPromptLength(prompt);
|
|
435
|
+
this.sendImmediate({
|
|
436
|
+
type: "ai-updates",
|
|
437
|
+
payload: {
|
|
438
|
+
type: "ai-generate",
|
|
439
|
+
prompt: sanitizedPrompt
|
|
440
|
+
}
|
|
441
|
+
}, forceSend);
|
|
442
|
+
}
|
|
443
|
+
sendAiLoaderState(shouldShowLoader) {
|
|
444
|
+
this.sendImmediate({
|
|
445
|
+
type: "ai-updates",
|
|
446
|
+
payload: {
|
|
447
|
+
type: "loader-state",
|
|
448
|
+
shouldShowLoader
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
socketError(message) {
|
|
453
|
+
this.sendImmediate({
|
|
454
|
+
type: "socket/error",
|
|
455
|
+
payload: { message }
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
sendRuntimeError(data) {
|
|
459
|
+
this.sendImmediate({
|
|
460
|
+
type: "runtime-error",
|
|
461
|
+
payload: data
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
sendClearRuntimeError(id) {
|
|
465
|
+
this.sendImmediate({
|
|
466
|
+
type: "clear-runtime-error",
|
|
467
|
+
payload: { id }
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
setInteractionMode(mode) {
|
|
471
|
+
this.sendImmediate({
|
|
472
|
+
type: "set-interaction-mode",
|
|
473
|
+
payload: { interactionMode: mode }
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
queueMessage(message, mergeOptions) {
|
|
477
|
+
if (!this.connectedToParent) this.messagesToSend.push({
|
|
478
|
+
payload: message,
|
|
479
|
+
mergeOptions
|
|
480
|
+
});
|
|
481
|
+
else message_queue_default.queueMessage(message, mergeOptions);
|
|
482
|
+
}
|
|
483
|
+
sendImmediate(message, forceSend = false) {
|
|
484
|
+
if (!this.connectedToParent && !forceSend) this.messagesToSend.push({ payload: message });
|
|
485
|
+
else sendMessageImmediately(message);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const MAX_AI_PROMPT_LENGTH = 16e3;
|
|
489
|
+
const TRUNCATION_SUFFIX = "... (truncated)";
|
|
490
|
+
function clampPromptLength(prompt) {
|
|
491
|
+
if (prompt.length <= MAX_AI_PROMPT_LENGTH) return prompt;
|
|
492
|
+
const available = Math.max(MAX_AI_PROMPT_LENGTH - 15, 0);
|
|
493
|
+
return `${prompt.slice(0, available)}${TRUNCATION_SUFFIX}`;
|
|
494
|
+
}
|
|
495
|
+
const editorBridge = SuperblocksEditorBridge.getInstance();
|
|
496
|
+
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/lib/internal-details/location-store.ts
|
|
499
|
+
var LocationStore = class {
|
|
500
|
+
route;
|
|
501
|
+
rootStore;
|
|
502
|
+
constructor(rootStore) {
|
|
503
|
+
this.rootStore = rootStore;
|
|
504
|
+
}
|
|
505
|
+
@action updateLocation(location, routes, params) {
|
|
506
|
+
this.route = this.locationToRouteInfo(location, routes, params);
|
|
507
|
+
this.sendLocationToEditor();
|
|
508
|
+
}
|
|
509
|
+
sendLocationToEditor() {
|
|
510
|
+
if (!this.route) return;
|
|
511
|
+
editorBridge.updateRoute(this.route);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Recursively searches through route tree (including nested children) to find a matching route
|
|
515
|
+
*/
|
|
516
|
+
findMatchingRoute(routes, pathname) {
|
|
517
|
+
return matchRoutes(routes, pathname)?.at(-1);
|
|
518
|
+
}
|
|
519
|
+
locationToRouteInfo(location, routes, params) {
|
|
520
|
+
const match = this.findMatchingRoute(routes, location.pathname);
|
|
521
|
+
if (!match?.pathname) return;
|
|
522
|
+
return {
|
|
523
|
+
hash: location.hash,
|
|
524
|
+
pathname: location.pathname,
|
|
525
|
+
queryParams: getQueryParams(location.search),
|
|
526
|
+
route: match.pathname,
|
|
527
|
+
routeParams: params
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/lib/user-facing/assets/icons/system-danger.svg
|
|
534
|
+
var _path$5;
|
|
535
|
+
function _extends$5() {
|
|
536
|
+
return _extends$5 = Object.assign ? Object.assign.bind() : function(n) {
|
|
537
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
538
|
+
var t = arguments[e];
|
|
539
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
540
|
+
}
|
|
541
|
+
return n;
|
|
542
|
+
}, _extends$5.apply(null, arguments);
|
|
543
|
+
}
|
|
544
|
+
var SvgSystemDanger = function SvgSystemDanger$1(props) {
|
|
545
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends$5({
|
|
546
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
547
|
+
width: 16,
|
|
548
|
+
height: 16,
|
|
549
|
+
fill: "none"
|
|
550
|
+
}, props), _path$5 || (_path$5 = /* @__PURE__ */ React$1.createElement("path", {
|
|
551
|
+
fill: "currentColor",
|
|
552
|
+
fillRule: "evenodd",
|
|
553
|
+
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",
|
|
554
|
+
clipRule: "evenodd"
|
|
555
|
+
})));
|
|
556
|
+
};
|
|
557
|
+
var system_danger_default = SvgSystemDanger;
|
|
558
|
+
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/lib/user-facing/assets/icons/system-error.svg
|
|
561
|
+
var _path$4;
|
|
562
|
+
function _extends$4() {
|
|
563
|
+
return _extends$4 = Object.assign ? Object.assign.bind() : function(n) {
|
|
564
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
565
|
+
var t = arguments[e];
|
|
566
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
567
|
+
}
|
|
568
|
+
return n;
|
|
569
|
+
}, _extends$4.apply(null, arguments);
|
|
570
|
+
}
|
|
571
|
+
var SvgSystemError = function SvgSystemError$1(props) {
|
|
572
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends$4({
|
|
573
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
574
|
+
width: 16,
|
|
575
|
+
height: 16,
|
|
576
|
+
fill: "none"
|
|
577
|
+
}, props), _path$4 || (_path$4 = /* @__PURE__ */ React$1.createElement("path", {
|
|
578
|
+
fill: "currentColor",
|
|
579
|
+
fillRule: "evenodd",
|
|
580
|
+
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",
|
|
581
|
+
clipRule: "evenodd"
|
|
582
|
+
})));
|
|
583
|
+
};
|
|
584
|
+
var system_error_default = SvgSystemError;
|
|
585
|
+
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/lib/user-facing/assets/icons/system-info.svg
|
|
588
|
+
var _path$3;
|
|
589
|
+
function _extends$3() {
|
|
590
|
+
return _extends$3 = Object.assign ? Object.assign.bind() : function(n) {
|
|
591
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
592
|
+
var t = arguments[e];
|
|
593
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
594
|
+
}
|
|
595
|
+
return n;
|
|
596
|
+
}, _extends$3.apply(null, arguments);
|
|
597
|
+
}
|
|
598
|
+
var SvgSystemInfo = function SvgSystemInfo$1(props) {
|
|
599
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends$3({
|
|
600
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
601
|
+
width: 16,
|
|
602
|
+
height: 16,
|
|
603
|
+
fill: "none"
|
|
604
|
+
}, props), _path$3 || (_path$3 = /* @__PURE__ */ React$1.createElement("path", {
|
|
605
|
+
fill: "currentColor",
|
|
606
|
+
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"
|
|
607
|
+
})));
|
|
608
|
+
};
|
|
609
|
+
var system_info_default = SvgSystemInfo;
|
|
610
|
+
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region src/lib/user-facing/assets/icons/system-success.svg
|
|
613
|
+
var _path$2;
|
|
614
|
+
function _extends$2() {
|
|
615
|
+
return _extends$2 = Object.assign ? Object.assign.bind() : function(n) {
|
|
616
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
617
|
+
var t = arguments[e];
|
|
618
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
619
|
+
}
|
|
620
|
+
return n;
|
|
621
|
+
}, _extends$2.apply(null, arguments);
|
|
622
|
+
}
|
|
623
|
+
var SvgSystemSuccess = function SvgSystemSuccess$1(props) {
|
|
624
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends$2({
|
|
625
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
626
|
+
width: 16,
|
|
627
|
+
height: 16,
|
|
628
|
+
fill: "none"
|
|
629
|
+
}, props), _path$2 || (_path$2 = /* @__PURE__ */ React$1.createElement("path", {
|
|
630
|
+
fill: "currentColor",
|
|
631
|
+
fillRule: "evenodd",
|
|
632
|
+
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",
|
|
633
|
+
clipRule: "evenodd"
|
|
634
|
+
})));
|
|
635
|
+
};
|
|
636
|
+
var system_success_default = SvgSystemSuccess;
|
|
637
|
+
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/lib/user-facing/styling/colors.ts
|
|
640
|
+
const colors = {
|
|
641
|
+
WHITE: "#FFFFFF",
|
|
642
|
+
BLACK: "#000000",
|
|
643
|
+
PLATFORM_BLACK: "#0E141B",
|
|
644
|
+
OFF_WHITE: "#F2F2F2",
|
|
645
|
+
DISABLED: "rgba(0, 0, 0, 0.25)",
|
|
646
|
+
GREY_25: "#F9FAFB",
|
|
647
|
+
GREY_50: "#F3F4F6",
|
|
648
|
+
GREY_100: "#E8EAED",
|
|
649
|
+
GREY_200: "#C6CAD2",
|
|
650
|
+
GREY_300: "#A4AAB7",
|
|
651
|
+
GREY_400: "#818A9C",
|
|
652
|
+
GREY_500: "#6C7689",
|
|
653
|
+
GREY_600: "#5A6272",
|
|
654
|
+
GREY_700: "#454D5F",
|
|
655
|
+
GREY_800: "#2F3437",
|
|
656
|
+
GREY_900: "#121517",
|
|
657
|
+
GRAY_GRID: "#CCD3DB",
|
|
658
|
+
RED_500_8: "rgba(255, 72, 72, 0.08)",
|
|
659
|
+
RED_25: "#FF48481F",
|
|
660
|
+
RED_500: "#FF4848",
|
|
661
|
+
RED_600: "#DB4949",
|
|
662
|
+
RED_700: "#C54141",
|
|
663
|
+
ORANGE_25: "#FFEEC5",
|
|
664
|
+
ORANGE_600: "#FA8A0F",
|
|
665
|
+
SUBTLE_BLUE: "#29bbff14",
|
|
666
|
+
SUBTLE_BLUE_SOLID: "#eefaff",
|
|
667
|
+
ACCENT_BLUE_NEW_DARKER: "#0087E0",
|
|
668
|
+
BLUE_MINMAX_LABELS: "#0062A3",
|
|
669
|
+
DRAG_PREVIEW_BLUE: "rgba(0, 135, 224, 0.16)",
|
|
670
|
+
ACCENT_BLUE_500: "#27BBFF",
|
|
671
|
+
ACCENT_BLUE_500_04: "#27BBFF0A",
|
|
672
|
+
ACCENT_BLUE_500_25: "#27BBFF14",
|
|
673
|
+
ACCENT_BLUE_500_50: "#27BBFF1F",
|
|
674
|
+
ACCENT_BLUE_500_18: "#27BBFF2E",
|
|
675
|
+
ACCENT_BLUE_500_24: "#27BBFF3D",
|
|
676
|
+
ACCENT_BLUE_500_48: "#27BBFF7A",
|
|
677
|
+
ACCENT_BLUE_600: "#00A8F5",
|
|
678
|
+
ACCENT_BLUE_700: "#009AE0",
|
|
679
|
+
ACCENT_ORANGE: "#FF9F35",
|
|
680
|
+
ACCENT_ORANGE_04: "#FF9F350A",
|
|
681
|
+
ACCENT_ORANGE_24: "#FF9F353D",
|
|
682
|
+
LIGHT_ORANGE: "#FF9F351E",
|
|
683
|
+
ACCENT_ORANGE_600: "#FA8A0F",
|
|
684
|
+
SUBTLE_PURPLE: "#643ADF14",
|
|
685
|
+
ACCENT_PURPLE: "#643ADF",
|
|
686
|
+
LIGHT_PURPLE: "#643ADF1E",
|
|
687
|
+
ACCENT_PURPLE_500: "#7C4FF8",
|
|
688
|
+
ACCENT_PURPLE_600: "#5227CE",
|
|
689
|
+
SUBTLE_GREEN: "#14CDB714",
|
|
690
|
+
LIGHT_GREEN: "#9BDCAD",
|
|
691
|
+
ACCENT_GREEN: "#14CDB7",
|
|
692
|
+
ACCENT_GREEN_600: "#08BAA5",
|
|
693
|
+
LIGHT_PINK: `rgba(255, 98, 164, 0.12)`,
|
|
694
|
+
ACCENT_PINK: "#FF62A4",
|
|
695
|
+
HOVER_BLUE: "#E3F8FF",
|
|
696
|
+
HOVER_GREEN: "#14CDB724",
|
|
697
|
+
CLICK_GREEN: "#14CDB734",
|
|
698
|
+
INFO: "#27BBFF",
|
|
699
|
+
WARNING: "#FF9F35",
|
|
700
|
+
DANGER: "#F45252",
|
|
701
|
+
DANGER_BRIGHT: "rgba(255, 72, 72, 1.0)",
|
|
702
|
+
DANGER_SUBTLE: "#F452521F",
|
|
703
|
+
SUCCESS: "#0CC26D",
|
|
704
|
+
NONE: "transparent"
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/lib/user-facing/themes/classnames.ts
|
|
709
|
+
const MODIFIER_CLASSNAMES = {
|
|
710
|
+
DISABLED_MODIFIER: "sb-disabled",
|
|
711
|
+
ERROR_MODIFIER: "sb-error",
|
|
712
|
+
ACTIVE_MODIFIER: "sb-active"
|
|
713
|
+
};
|
|
714
|
+
const CLASS_NAMES = {
|
|
715
|
+
...MODIFIER_CLASSNAMES,
|
|
716
|
+
HEADING1: "sb-heading-1",
|
|
717
|
+
HEADING2: "sb-heading-2",
|
|
718
|
+
HEADING3: "sb-heading-3",
|
|
719
|
+
HEADING4: "sb-heading-4",
|
|
720
|
+
HEADING5: "sb-heading-5",
|
|
721
|
+
HEADING6: "sb-heading-6",
|
|
722
|
+
BODY1: "sb-body-1",
|
|
723
|
+
BODY2: "sb-body-2",
|
|
724
|
+
BODY3: "sb-body-3",
|
|
725
|
+
LINK: "sb-link",
|
|
726
|
+
INPUT_LABEL: "sb-input-label",
|
|
727
|
+
LABEL: "sb-label",
|
|
728
|
+
CODE_TEXT: "sb-code",
|
|
729
|
+
INPUT_TEXT: "sb-input-text",
|
|
730
|
+
INPUT_PLACEHOLDER: "sb-input-placeholder",
|
|
731
|
+
BUTTON_LABEL: "sb-button-label",
|
|
732
|
+
SYSTEM_TEXT: "sb-system-text",
|
|
733
|
+
BUILTIN_BODY: "sb-builtin-body",
|
|
734
|
+
ELLIPSIS_TEXT: "sb-ellipsis-text",
|
|
735
|
+
BUTTON: "sb-button",
|
|
736
|
+
PRIMARY_BUTTON: "sb-button-primary",
|
|
737
|
+
SECONDARY_BUTTON: "sb-button-secondary",
|
|
738
|
+
SECONDARY_NEUTRAL_BUTTON: "sb-button-secondary-neutral",
|
|
739
|
+
TERTIARY_BUTTON: "sb-button-tertiary",
|
|
740
|
+
SYSTEM_BUTTON: "sb-button-system",
|
|
741
|
+
INPUT: "sb-input",
|
|
742
|
+
SWITCH: "sb-switch",
|
|
743
|
+
CHECKBOX: "sb-checkbox",
|
|
744
|
+
RADIO: "sb-radio",
|
|
745
|
+
SECTION: "sb-section",
|
|
746
|
+
ROUNDED_CONTAINER: "sb-rounded-container",
|
|
747
|
+
CANVAS: "sb-canvas",
|
|
748
|
+
DEFAULT_CONTAINER: "sb-default-container",
|
|
749
|
+
DEFAULT_CONTAINER_STYLE_CARD: "sb-default-container-style-card",
|
|
750
|
+
DEFAULT_CONTAINER_STYLE_NONE: "sb-default-container-style-none",
|
|
751
|
+
DEFAULT_CONTAINER_BORDER: "sb-default-container-border",
|
|
752
|
+
CONTAINER_BORDER_OUTLINE: "sb-container-border-overlay",
|
|
753
|
+
POPOVER_WRAPPER: "sb-popover-wrapper",
|
|
754
|
+
TAB: "sb-tab",
|
|
755
|
+
MODAL: "sb-modal",
|
|
756
|
+
SLIDEOUT: "sb-slideout",
|
|
757
|
+
BORDER_BOTTOM: "sb-util-border-bottom",
|
|
758
|
+
BORDER_TOP: "sb-util-border-top",
|
|
759
|
+
NOTIFICATION: "sb-notification",
|
|
760
|
+
STYLED_SCROLLBAR: "sb-scrollable",
|
|
761
|
+
TOOLTIP: "sb-tooltip",
|
|
762
|
+
DROPDOWN: "sb-dropdown",
|
|
763
|
+
DROPDOWN_MENU: "sb-dropdown-menu",
|
|
764
|
+
MENU_ITEM: "sb-menu-item",
|
|
765
|
+
TAG_INPUT: "sb-tag-input",
|
|
766
|
+
DATEPICKER: "sb-datepicker",
|
|
767
|
+
DROPDOWN_CLEAR_ICON: "sb-dropdown-clear-icon",
|
|
768
|
+
CARET_ICON: "sb-caret-icon",
|
|
769
|
+
PRIMARY_COLOR_ICON: "sb-primary-color-icon",
|
|
770
|
+
CLOSE_ICON: "sb-close-icon",
|
|
771
|
+
ICON: "sb-icon",
|
|
772
|
+
PAGINATOR: "sb-rc-paginator",
|
|
773
|
+
CODE_EDITOR: "sb-code-editor",
|
|
774
|
+
ERROR_INLINE_MESSAGE: "sb-error-inline-message"
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/lib/user-facing/utils/notification.tsx
|
|
779
|
+
const activeNotifications = /* @__PURE__ */ new Map();
|
|
780
|
+
const StatusIconWrapper = styled.div`
|
|
781
|
+
color: ${(props) => props.color};
|
|
782
|
+
font-size: 16px;
|
|
783
|
+
margin-top: -2px;
|
|
784
|
+
margin-left: -10px;
|
|
785
|
+
svg {
|
|
786
|
+
width: 18px;
|
|
787
|
+
height: 18px;
|
|
788
|
+
}
|
|
789
|
+
`;
|
|
790
|
+
const MessageWrapper = styled.div`
|
|
791
|
+
font-size: 12px;
|
|
792
|
+
font-weight: 500;
|
|
793
|
+
line-height: 1.3;
|
|
794
|
+
margin-left: -26px;
|
|
795
|
+
margin-right: 0;
|
|
796
|
+
white-space: pre-wrap;
|
|
797
|
+
`;
|
|
798
|
+
const DescriptionWrapper = styled.div`
|
|
799
|
+
font-size: 12px;
|
|
800
|
+
margin-left: -26px;
|
|
801
|
+
margin-right: -10px;
|
|
802
|
+
`;
|
|
803
|
+
const styleMessage = (message, dataTest) => {
|
|
804
|
+
return /* @__PURE__ */ jsx(MessageWrapper, {
|
|
805
|
+
"data-test": dataTest ? dataTest : "notification",
|
|
806
|
+
children: message
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
const styleDescription = (description) => {
|
|
810
|
+
if (!description) return;
|
|
811
|
+
return /* @__PURE__ */ jsx(DescriptionWrapper, { children: description });
|
|
812
|
+
};
|
|
813
|
+
const messageWithCount = (key, message, dataTest) => {
|
|
814
|
+
let updatedMessage = message;
|
|
815
|
+
if (key) {
|
|
816
|
+
const count = (activeNotifications.get(key)?.count ?? 0) + 1;
|
|
817
|
+
activeNotifications.set(key, {
|
|
818
|
+
count,
|
|
819
|
+
message
|
|
820
|
+
});
|
|
821
|
+
if (count > 1 && isString(message)) updatedMessage = `${message} (${count} times)`;
|
|
822
|
+
}
|
|
823
|
+
return styleMessage(updatedMessage, dataTest);
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* When a Key is used,
|
|
827
|
+
* duplicate notifications are not shown but the timeout is added to the first notification.
|
|
828
|
+
* @returns A string key based on inputs
|
|
829
|
+
*/
|
|
830
|
+
const getKey = (type, message, description, duration) => {
|
|
831
|
+
return isString(message) ? `${type}--${String(message)}--${description}--${duration}` : void 0;
|
|
832
|
+
};
|
|
833
|
+
const removeNotificationsWithKey = (key) => {
|
|
834
|
+
document.querySelectorAll(`[data-testid="notification_${key}"]`).forEach((el) => {
|
|
835
|
+
el.remove();
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
const attrSafeKey = (str) => {
|
|
839
|
+
return str.replace(/\W+/g, "_");
|
|
840
|
+
};
|
|
841
|
+
const getIcon = (type) => {
|
|
842
|
+
let icon;
|
|
843
|
+
let color;
|
|
844
|
+
switch (type) {
|
|
845
|
+
case "success":
|
|
846
|
+
icon = /* @__PURE__ */ jsx(system_success_default, {});
|
|
847
|
+
color = colors.SUCCESS;
|
|
848
|
+
break;
|
|
849
|
+
case "error":
|
|
850
|
+
icon = /* @__PURE__ */ jsx(system_error_default, {});
|
|
851
|
+
color = colors.DANGER;
|
|
852
|
+
break;
|
|
853
|
+
case "info":
|
|
854
|
+
icon = /* @__PURE__ */ jsx(system_info_default, {});
|
|
855
|
+
color = colors.INFO;
|
|
856
|
+
break;
|
|
857
|
+
case "warning":
|
|
858
|
+
icon = /* @__PURE__ */ jsx(system_danger_default, {});
|
|
859
|
+
color = colors.WARNING;
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
return /* @__PURE__ */ jsx(StatusIconWrapper, {
|
|
863
|
+
color,
|
|
864
|
+
children: icon
|
|
865
|
+
});
|
|
866
|
+
};
|
|
867
|
+
function onAlertClose(key) {
|
|
868
|
+
if (key) activeNotifications.delete(key);
|
|
869
|
+
}
|
|
870
|
+
const positionToPlacement = {
|
|
871
|
+
[NotificationPosition.bottom]: "bottom-center",
|
|
872
|
+
[NotificationPosition.top]: "top-center",
|
|
873
|
+
[NotificationPosition.topLeft]: "top-left",
|
|
874
|
+
[NotificationPosition.topRight]: "top-right",
|
|
875
|
+
[NotificationPosition.bottomLeft]: "bottom-left",
|
|
876
|
+
[NotificationPosition.bottomRight]: "bottom-right"
|
|
877
|
+
};
|
|
878
|
+
function sendNotification({ message, description, duration, key = getKey("success", message, description, duration), placement = NotificationPosition.bottomRight, style, dataTest, type }) {
|
|
879
|
+
const icon = getIcon(type);
|
|
880
|
+
const handleClose = () => {
|
|
881
|
+
onAlertClose(key);
|
|
882
|
+
if (key) removeNotificationsWithKey(attrSafeKey(`notification-${key}`));
|
|
883
|
+
};
|
|
884
|
+
if (key) {
|
|
885
|
+
toast.dismiss(key);
|
|
886
|
+
removeNotificationsWithKey(attrSafeKey(`notification-${key}`));
|
|
887
|
+
}
|
|
888
|
+
const position = positionToPlacement[placement];
|
|
889
|
+
toast.success(messageWithCount(key, message, dataTest), {
|
|
890
|
+
id: key,
|
|
891
|
+
description: styleDescription(description),
|
|
892
|
+
icon,
|
|
893
|
+
duration: duration ? duration * 1e3 : void 0,
|
|
894
|
+
position,
|
|
895
|
+
className: CLASS_NAMES.NOTIFICATION,
|
|
896
|
+
style,
|
|
897
|
+
onDismiss: handleClose,
|
|
898
|
+
onAutoClose: handleClose
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/lib/internal-details/superblocks-context.tsx
|
|
904
|
+
var SuperblocksAppContext = class {
|
|
905
|
+
context;
|
|
906
|
+
constructor() {
|
|
907
|
+
makeAutoObservable(this);
|
|
908
|
+
}
|
|
909
|
+
get user() {
|
|
910
|
+
return this.context?.user;
|
|
911
|
+
}
|
|
912
|
+
get groups() {
|
|
913
|
+
return this.context?.groups;
|
|
914
|
+
}
|
|
915
|
+
get selectedProfile() {
|
|
916
|
+
return this.context?.profiles?.selected;
|
|
917
|
+
}
|
|
918
|
+
get profiles() {
|
|
919
|
+
return this.context?.profiles;
|
|
920
|
+
}
|
|
921
|
+
setProfile(profileName) {
|
|
922
|
+
const profile = this.context?.profiles?.available.find((profile$1) => profile$1.displayName === profileName);
|
|
923
|
+
if (profile && this.context?.profiles) this.context.profiles.selected = profile;
|
|
924
|
+
else if (!profile || !this.context?.profiles) throw new Error(`Profile ${profileName} not found`);
|
|
925
|
+
}
|
|
926
|
+
updateContext(context$2) {
|
|
927
|
+
this.context = {
|
|
928
|
+
...this.context,
|
|
929
|
+
...context$2
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const context$1 = new SuperblocksAppContext();
|
|
934
|
+
const SuperblocksContext = createContext(context$1);
|
|
935
|
+
function SuperblocksContextProvider({ children, value: contextOverride }) {
|
|
936
|
+
if (contextOverride) return /* @__PURE__ */ jsx(SuperblocksContext.Provider, {
|
|
937
|
+
value: contextOverride,
|
|
938
|
+
children
|
|
939
|
+
});
|
|
940
|
+
return /* @__PURE__ */ jsx(SuperblocksContext.Provider, {
|
|
941
|
+
value: context$1,
|
|
942
|
+
children
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
function useSuperblocksContext() {
|
|
946
|
+
return useContext(SuperblocksContext);
|
|
947
|
+
}
|
|
948
|
+
function useSuperblocksUser() {
|
|
949
|
+
const context$2 = useSuperblocksContext();
|
|
950
|
+
return useSyncExternalStore((onStoreChange) => {
|
|
951
|
+
return reaction(() => context$2.user, onStoreChange);
|
|
952
|
+
}, () => {
|
|
953
|
+
return context$2.user;
|
|
954
|
+
}, () => {
|
|
955
|
+
return context$2.user;
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
function useSuperblocksGroups() {
|
|
959
|
+
const context$2 = useSuperblocksContext();
|
|
960
|
+
return useSyncExternalStore((onStoreChange) => {
|
|
961
|
+
return reaction(() => context$2.groups, onStoreChange);
|
|
962
|
+
}, () => {
|
|
963
|
+
return context$2.groups;
|
|
964
|
+
}, () => {
|
|
965
|
+
return context$2.groups;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
function useSuperblocksProfiles() {
|
|
969
|
+
const context$2 = useSuperblocksContext();
|
|
970
|
+
return {
|
|
971
|
+
profiles: useSyncExternalStore((onStoreChange) => {
|
|
972
|
+
return reaction(() => context$2.profiles, onStoreChange);
|
|
973
|
+
}, () => {
|
|
974
|
+
return context$2.profiles;
|
|
975
|
+
}, () => {
|
|
976
|
+
return context$2.profiles;
|
|
977
|
+
}),
|
|
978
|
+
setProfile: useCallback((profileName) => {
|
|
979
|
+
context$2.setProfile(profileName);
|
|
980
|
+
}, [context$2])
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/lib/internal-details/lib/resolve-id-singleton.ts
|
|
986
|
+
const EMBED_STRING = `embedded-`;
|
|
987
|
+
let promiseCount = 0;
|
|
988
|
+
const resolverMap = /* @__PURE__ */ new Map();
|
|
989
|
+
const rejectorMap = /* @__PURE__ */ new Map();
|
|
990
|
+
const multiUseCallbacks = /* @__PURE__ */ new Map();
|
|
991
|
+
function addNewPromise(resolver, isMultiUse = false, rejecter) {
|
|
992
|
+
const promiseId = `${isEmbeddedBySuperblocksFirstParty() ? EMBED_STRING : ""}p${++promiseCount}`;
|
|
993
|
+
resolverMap.set(promiseId, resolver);
|
|
994
|
+
if (isMultiUse) multiUseCallbacks.set(promiseId, resolver);
|
|
995
|
+
if (rejecter) rejectorMap.set(promiseId, rejecter);
|
|
996
|
+
return promiseId;
|
|
997
|
+
}
|
|
998
|
+
function resolveById(id, payload) {
|
|
999
|
+
const isEmbedId = id.startsWith(EMBED_STRING);
|
|
1000
|
+
if (isEmbeddedBySuperblocksFirstParty() && !isEmbedId || !isEmbeddedBySuperblocksFirstParty() && isEmbedId) editorBridge.resolvePromise(id, payload);
|
|
1001
|
+
else try {
|
|
1002
|
+
const resolver = resolverMap.get(id);
|
|
1003
|
+
if (!resolver) throw new Error(`Promise not found for id ${id}`);
|
|
1004
|
+
resolver(payload);
|
|
1005
|
+
if (!multiUseCallbacks.has(id)) {
|
|
1006
|
+
resolverMap.delete(id);
|
|
1007
|
+
rejectorMap.delete(id);
|
|
1008
|
+
}
|
|
1009
|
+
} catch (e) {
|
|
1010
|
+
console.log("Error resolving promise", e);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
function rejectById(id, payload) {
|
|
1014
|
+
const isEmbedId = id.startsWith(EMBED_STRING);
|
|
1015
|
+
if (isEmbeddedBySuperblocksFirstParty() && !isEmbedId || !isEmbeddedBySuperblocksFirstParty() && isEmbedId) editorBridge.rejectPromise(id, payload);
|
|
1016
|
+
else try {
|
|
1017
|
+
const rejecter = rejectorMap.get(id);
|
|
1018
|
+
if (!rejecter) throw new Error(`Promise not found for id ${id}`);
|
|
1019
|
+
rejecter(payload);
|
|
1020
|
+
if (!multiUseCallbacks.has(id)) {
|
|
1021
|
+
resolverMap.delete(id);
|
|
1022
|
+
rejectorMap.delete(id);
|
|
1023
|
+
}
|
|
1024
|
+
} catch (e) {
|
|
1025
|
+
console.log("Error rejecting promise", e);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/lib/tracing/context-utils.ts
|
|
1031
|
+
function getContextFromTraceHeaders(traceHeaders) {
|
|
1032
|
+
let parentContext = context.active();
|
|
1033
|
+
try {
|
|
1034
|
+
parentContext = propagation.extract(context.active(), traceHeaders);
|
|
1035
|
+
} catch (error) {
|
|
1036
|
+
console.warn("Failed to extract parent context from headers", traceHeaders, error);
|
|
1037
|
+
}
|
|
1038
|
+
return parentContext;
|
|
1039
|
+
}
|
|
1040
|
+
function createIframeSpan(name, attributes, parentContext) {
|
|
1041
|
+
return getTracer("superblocks-iframe").startSpan(name, { attributes }, parentContext);
|
|
1042
|
+
}
|
|
1043
|
+
function getTraceContextHeadersFromSpan(span) {
|
|
1044
|
+
const traceContextHeaders = {};
|
|
1045
|
+
const contextWithSpan = trace.setSpan(ROOT_CONTEXT, span);
|
|
1046
|
+
propagation.inject(contextWithSpan, traceContextHeaders);
|
|
1047
|
+
return traceContextHeaders;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region src/lib/utils/generate-id.ts
|
|
1052
|
+
const generateId = () => {
|
|
1053
|
+
return Math.random().toString(36).substring(2, 15);
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/lib/internal-details/lib/features/api-utils.ts
|
|
1058
|
+
async function executeV2Api(params) {
|
|
1059
|
+
const { body, apiName, controlFlowOnlyFiles, notifyOnSystemError, eventType, onMessage, processStreamEvents, responseType, abortController, baseUrl, viewMode, accessToken, token, traceHeaders } = params;
|
|
1060
|
+
let parentContext = context.active();
|
|
1061
|
+
if (traceHeaders) parentContext = getContextFromTraceHeaders(traceHeaders);
|
|
1062
|
+
let applicationId = "unknown";
|
|
1063
|
+
if ("fetchByPath" in body) applicationId = body.fetchByPath.applicationId;
|
|
1064
|
+
const span = createIframeSpan("iframe_execute_v2_api", {
|
|
1065
|
+
"api-name": apiName || "unknown",
|
|
1066
|
+
"application-id": applicationId,
|
|
1067
|
+
event_type: eventType,
|
|
1068
|
+
response_type: responseType,
|
|
1069
|
+
view_mode: viewMode
|
|
1070
|
+
}, parentContext);
|
|
1071
|
+
try {
|
|
1072
|
+
let cleanedBody;
|
|
1073
|
+
try {
|
|
1074
|
+
cleanedBody = cleanObject(body);
|
|
1075
|
+
} catch {
|
|
1076
|
+
cleanedBody = structuredClone(body);
|
|
1077
|
+
}
|
|
1078
|
+
if (controlFlowOnlyFiles && controlFlowOnlyFiles.length > 0) cleanedBody = {
|
|
1079
|
+
...cleanedBody,
|
|
1080
|
+
files: controlFlowOnlyFiles
|
|
1081
|
+
};
|
|
1082
|
+
const traceContextHeaders = getTraceContextHeadersFromSpan(span);
|
|
1083
|
+
const init = {
|
|
1084
|
+
method: HttpMethod.Post,
|
|
1085
|
+
body: JSON.stringify(cleanedBody),
|
|
1086
|
+
signal: abortController?.signal,
|
|
1087
|
+
headers: {
|
|
1088
|
+
[SUPERBLOCKS_AUTHORIZATION_HEADER]: `Bearer ${accessToken}`,
|
|
1089
|
+
Authorization: `Bearer ${token}`,
|
|
1090
|
+
[SUPERBLOCKS_REQUEST_ID_HEADER]: generateId(),
|
|
1091
|
+
...traceContextHeaders
|
|
1092
|
+
},
|
|
1093
|
+
credentials: "include"
|
|
1094
|
+
};
|
|
1095
|
+
return responseType === ApiResponseType.STREAM ? await fetchServerStream({
|
|
1096
|
+
augmentedInit: init,
|
|
1097
|
+
fullUrl: baseUrl,
|
|
1098
|
+
timeoutId: setTimeout(() => {}, 1e3),
|
|
1099
|
+
onMessage,
|
|
1100
|
+
processStreamEvents
|
|
1101
|
+
}) : await fetchServer({
|
|
1102
|
+
augmentedInit: init,
|
|
1103
|
+
fullUrl: baseUrl,
|
|
1104
|
+
timeoutId: setTimeout(() => {}, 1e3)
|
|
1105
|
+
});
|
|
1106
|
+
} catch (err) {
|
|
1107
|
+
const message = `Failed to execute ${apiName || "API"}. ${err}`;
|
|
1108
|
+
const suppressError = viewMode !== ViewMode.EDITOR && err?.code === 20;
|
|
1109
|
+
if (notifyOnSystemError && !suppressError) console.log(message);
|
|
1110
|
+
return { systemError: message };
|
|
1111
|
+
} finally {
|
|
1112
|
+
span.end();
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const HttpMethod = {
|
|
1116
|
+
Get: "GET",
|
|
1117
|
+
Post: "POST",
|
|
1118
|
+
Put: "PUT",
|
|
1119
|
+
Patch: "PATCH",
|
|
1120
|
+
Delete: "DELETE"
|
|
1121
|
+
};
|
|
1122
|
+
const stream = async ({ url, headers, body, onMessage, onComplete, onError, defaultError, method, baseUrl = "/api/", signal, init: overrideInit }) => {
|
|
1123
|
+
const init = overrideInit ?? {
|
|
1124
|
+
body: JSON.stringify(body),
|
|
1125
|
+
headers,
|
|
1126
|
+
method
|
|
1127
|
+
};
|
|
1128
|
+
try {
|
|
1129
|
+
const response = await fetch(`${baseUrl}${url}`, init);
|
|
1130
|
+
if (!response.ok) try {
|
|
1131
|
+
const parsed = await response.json();
|
|
1132
|
+
throw new HttpError(response.status, !response.status || response.status >= 500, parsed?.error?.message ?? parsed?.responseMeta?.error?.message ?? defaultError);
|
|
1133
|
+
} catch (e) {
|
|
1134
|
+
if (e instanceof HttpError) throw e;
|
|
1135
|
+
throw new HttpError(response.status, !response.status || response.status >= 500, response.statusText);
|
|
1136
|
+
}
|
|
1137
|
+
if (!response.body) return;
|
|
1138
|
+
const reader = response.body.getReader();
|
|
1139
|
+
const decoder = new TextDecoder();
|
|
1140
|
+
let done = false;
|
|
1141
|
+
let lastChunk = "";
|
|
1142
|
+
while (!done) {
|
|
1143
|
+
if (signal && signal.aborted) return;
|
|
1144
|
+
const { value, done: readerDone } = await reader.read();
|
|
1145
|
+
const chunk = lastChunk + decoder.decode(value);
|
|
1146
|
+
const messages = chunk.split("\n");
|
|
1147
|
+
let jsonValues = [];
|
|
1148
|
+
try {
|
|
1149
|
+
jsonValues = messages.filter(Boolean).map((message) => JSON.parse(message.trim()));
|
|
1150
|
+
lastChunk = "";
|
|
1151
|
+
} catch (e) {
|
|
1152
|
+
lastChunk = chunk;
|
|
1153
|
+
if (readerDone) throw e;
|
|
1154
|
+
}
|
|
1155
|
+
for (const jsonValue of jsonValues.filter(Boolean)) {
|
|
1156
|
+
if (jsonValue?.error) {
|
|
1157
|
+
onError(jsonValue.error.message ?? defaultError);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
onMessage(jsonValue);
|
|
1161
|
+
}
|
|
1162
|
+
done = readerDone && lastChunk === "";
|
|
1163
|
+
}
|
|
1164
|
+
} catch (e) {
|
|
1165
|
+
if (e.name === "AbortError") console.log("Fetch was cancelled");
|
|
1166
|
+
else onError(e.message ?? defaultError, e.code);
|
|
1167
|
+
} finally {
|
|
1168
|
+
onComplete();
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
const handleError = (rawError, { fullUrl, augmentedInit }) => {
|
|
1172
|
+
const error = rawError instanceof TypeError ? new HttpError(0, true, rawError.message) : rawError;
|
|
1173
|
+
console.error(`Request to '${fullUrl} has failed
|
|
1174
|
+
Response Status: ${error.code}
|
|
1175
|
+
Response Status Text: ${error.message}`);
|
|
1176
|
+
let critical = error.critical;
|
|
1177
|
+
if (fullUrl.match(/apis\/.*/) && (critical || error.code === 0)) critical = false;
|
|
1178
|
+
if (fullUrl.match(/\/(commits|deployment).*/) && error.code === 500) critical = false;
|
|
1179
|
+
if (augmentedInit.method === HttpMethod.Get && fullUrl.match(/apis\/.*/)) critical = true;
|
|
1180
|
+
else if (fullUrl.match(/apis\/.*/)) {}
|
|
1181
|
+
if (error.code && error.code < 500 && error.code >= 400) {
|
|
1182
|
+
if (error.code === 404) critical = true;
|
|
1183
|
+
}
|
|
1184
|
+
if (error.code >= 500) critical = false;
|
|
1185
|
+
};
|
|
1186
|
+
const fetchServerStream = async ({ augmentedInit, fullUrl, timeoutId, onMessage, processStreamEvents }) => {
|
|
1187
|
+
const handleMessage = (message) => {
|
|
1188
|
+
if (message?.result?.event?.data) onMessage && onMessage(message.result.event.data);
|
|
1189
|
+
else if (message?.result?.event?.start || message?.result?.event?.end) processStreamEvents && processStreamEvents(message);
|
|
1190
|
+
};
|
|
1191
|
+
const onComplete = () => {
|
|
1192
|
+
clearTimeout(timeoutId);
|
|
1193
|
+
};
|
|
1194
|
+
const onError = (error, statusCode) => {
|
|
1195
|
+
if (statusCode != null) handleError(new HttpError(statusCode, !statusCode || statusCode >= 500, error), {
|
|
1196
|
+
fullUrl,
|
|
1197
|
+
augmentedInit,
|
|
1198
|
+
timeoutId
|
|
1199
|
+
});
|
|
1200
|
+
else handleError(new TypeError(error), {
|
|
1201
|
+
fullUrl,
|
|
1202
|
+
augmentedInit,
|
|
1203
|
+
timeoutId
|
|
1204
|
+
});
|
|
1205
|
+
};
|
|
1206
|
+
return stream({
|
|
1207
|
+
url: fullUrl,
|
|
1208
|
+
init: augmentedInit,
|
|
1209
|
+
onMessage: handleMessage,
|
|
1210
|
+
onComplete,
|
|
1211
|
+
onError,
|
|
1212
|
+
baseUrl: "",
|
|
1213
|
+
signal: augmentedInit?.signal ?? void 0
|
|
1214
|
+
});
|
|
1215
|
+
};
|
|
1216
|
+
const getErrorMessageFromObject = (message) => {
|
|
1217
|
+
const messageJSONString = JSON.stringify(message);
|
|
1218
|
+
const match = /"message"\s*:\s*"([^"]*)"/.exec(messageJSONString);
|
|
1219
|
+
return match ? match[1] : messageJSONString;
|
|
1220
|
+
};
|
|
1221
|
+
const fetchServer = ({ augmentedInit, fullUrl, timeoutId }) => {
|
|
1222
|
+
return fetch(fullUrl, augmentedInit).then(async (response) => {
|
|
1223
|
+
try {
|
|
1224
|
+
if (response.status === 204) return null;
|
|
1225
|
+
const json = await response.json();
|
|
1226
|
+
if (response.ok && json) {
|
|
1227
|
+
if (json.data == null) return json;
|
|
1228
|
+
return json.data;
|
|
1229
|
+
} else {
|
|
1230
|
+
let message = json.responseMeta?.error?.message ?? json?.message;
|
|
1231
|
+
if (typeof message === "object") message = getErrorMessageFromObject(message);
|
|
1232
|
+
throw new HttpError(response.status, !response.status || response.status >= 500, message);
|
|
1233
|
+
}
|
|
1234
|
+
} catch (e) {
|
|
1235
|
+
if (e instanceof HttpError) throw e;
|
|
1236
|
+
throw new HttpError(response.status, !response.status || response.status >= 500, response.statusText);
|
|
1237
|
+
}
|
|
1238
|
+
}).catch((rawError) => {
|
|
1239
|
+
handleError(rawError, {
|
|
1240
|
+
fullUrl,
|
|
1241
|
+
augmentedInit,
|
|
1242
|
+
timeoutId
|
|
1243
|
+
});
|
|
1244
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
1245
|
+
};
|
|
1246
|
+
var HttpError = class extends Error {
|
|
1247
|
+
code;
|
|
1248
|
+
critical;
|
|
1249
|
+
constructor(code, critical = false, m) {
|
|
1250
|
+
super(m);
|
|
1251
|
+
this.code = code;
|
|
1252
|
+
this.critical = critical;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
const parseStreamResult = (streamResult, options) => {
|
|
1256
|
+
if (!streamResult || !Array.isArray(streamResult) || !streamResult.length) return;
|
|
1257
|
+
const execution = streamResult[0].result.execution;
|
|
1258
|
+
const [errors, events] = streamResult.reduce((accum, event) => {
|
|
1259
|
+
if (event.result.event.end && event.result.event.end.error) accum[0].push(event.result.event.end.error);
|
|
1260
|
+
accum[1].push(event.result.event);
|
|
1261
|
+
return accum;
|
|
1262
|
+
}, [[], []]);
|
|
1263
|
+
const result = {
|
|
1264
|
+
execution,
|
|
1265
|
+
events,
|
|
1266
|
+
errors,
|
|
1267
|
+
status: "STATUS_COMPLETED"
|
|
1268
|
+
};
|
|
1269
|
+
if (options?.includeFinalOutput) {
|
|
1270
|
+
let returnBlockOutput;
|
|
1271
|
+
for (let i = 0; i < streamResult.length; i++) {
|
|
1272
|
+
const streamEvent = streamResult[i];
|
|
1273
|
+
if (streamEvent.result.event.type === "BLOCK_TYPE_RETURN" && streamEvent.result.event.end) {
|
|
1274
|
+
returnBlockOutput = streamEvent.result.event.end?.output;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
if (returnBlockOutput) result.output = returnBlockOutput;
|
|
1279
|
+
else result.output = streamResult[streamResult.length - 1].result.event.end?.output;
|
|
1280
|
+
}
|
|
1281
|
+
return result;
|
|
1282
|
+
};
|
|
1283
|
+
const isApiV2ExecutionResponse = (response) => {
|
|
1284
|
+
return !!response && "output" in response && response?.output?.result != null;
|
|
1285
|
+
};
|
|
1286
|
+
const decodeBytestringsInV2ExecutionResponse = (response) => {
|
|
1287
|
+
if (!isApiV2ExecutionResponse(response)) return;
|
|
1288
|
+
if (response.output) response.output.result = decodeBytestrings(response.output.result, false);
|
|
1289
|
+
if (Array.isArray(response.events)) response.events.forEach((event) => {
|
|
1290
|
+
const typedEvent = event;
|
|
1291
|
+
if (typedEvent?.end?.output?.result != null) typedEvent.end.output.result = decodeBytestrings(typedEvent.end.output.result, false);
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/lib/internal-details/lib/features/file-utils.ts
|
|
1297
|
+
function getFileUploadId(file) {
|
|
1298
|
+
return `${file.name.replace(/[^a-zA-Z0-9.-]/g, "_")}-${file.size}-${file.lastModified}`;
|
|
1299
|
+
}
|
|
1300
|
+
function getFileInputData(f) {
|
|
1301
|
+
const superblocksId = getFileUploadId(f);
|
|
1302
|
+
const nameParts = f.name.split(".");
|
|
1303
|
+
const extension = nameParts.length > 1 ? nameParts.pop() || "" : "";
|
|
1304
|
+
return {
|
|
1305
|
+
$superblocksId: superblocksId,
|
|
1306
|
+
name: f.name,
|
|
1307
|
+
extension,
|
|
1308
|
+
type: f.type,
|
|
1309
|
+
size: f.size,
|
|
1310
|
+
encoding: "text"
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
async function formatFileForRequest(file, fileId) {
|
|
1314
|
+
return {
|
|
1315
|
+
originalName: fileId,
|
|
1316
|
+
buffer: await new Promise((resolve, reject) => {
|
|
1317
|
+
const reader = new FileReader();
|
|
1318
|
+
reader.onload = () => resolve(reader.result.split(",")[1]);
|
|
1319
|
+
reader.onerror = () => reject(new Error(reader.error?.message || "Unknown error reading file"));
|
|
1320
|
+
reader.readAsDataURL(file);
|
|
1321
|
+
}),
|
|
1322
|
+
encoding: "base64",
|
|
1323
|
+
mimetype: "text/plain"
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
async function getInputsWithFileMetadata(inputs) {
|
|
1327
|
+
const filesForRequest = {};
|
|
1328
|
+
const processValue = async (value) => {
|
|
1329
|
+
if (value === void 0) return null;
|
|
1330
|
+
if (value instanceof File) {
|
|
1331
|
+
const inputData = getFileInputData(value);
|
|
1332
|
+
if (!filesForRequest[inputData.$superblocksId]) filesForRequest[inputData.$superblocksId] = await formatFileForRequest(value, inputData.$superblocksId);
|
|
1333
|
+
return inputData;
|
|
1334
|
+
} else if (Array.isArray(value)) return await Promise.all(value.map((item) => processValue(item)));
|
|
1335
|
+
else if (typeof value === "object" && value != null && value.constructor === Object) return await processObject(value);
|
|
1336
|
+
return value;
|
|
1337
|
+
};
|
|
1338
|
+
const processObject = async (obj) => {
|
|
1339
|
+
const result = {};
|
|
1340
|
+
for (const [key, value] of Object.entries(obj)) result[key] = await processValue(value);
|
|
1341
|
+
return result;
|
|
1342
|
+
};
|
|
1343
|
+
return {
|
|
1344
|
+
inputs: await processObject(inputs),
|
|
1345
|
+
files: Object.values(filesForRequest)
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region src/lib/internal-details/lib/features/api-store.ts
|
|
1351
|
+
var ApiManager = class {
|
|
1352
|
+
agentUrls = [];
|
|
1353
|
+
token;
|
|
1354
|
+
accessToken;
|
|
1355
|
+
runningApiControllers = {};
|
|
1356
|
+
waitForInitApiPromise = void 0;
|
|
1357
|
+
callContexts = {};
|
|
1358
|
+
constructor(rootStore) {
|
|
1359
|
+
this.rootStore = rootStore;
|
|
1360
|
+
}
|
|
1361
|
+
setTokens(token, accessToken) {
|
|
1362
|
+
this.token = token;
|
|
1363
|
+
this.accessToken = accessToken;
|
|
1364
|
+
}
|
|
1365
|
+
isInitialized() {
|
|
1366
|
+
return !!this.token && !!this.accessToken;
|
|
1367
|
+
}
|
|
1368
|
+
async awaitInitApiIfNeeded() {
|
|
1369
|
+
if (this.waitForInitApiPromise) await this.waitForInitApiPromise;
|
|
1370
|
+
}
|
|
1371
|
+
loadApiManifest({ apis = {} }) {
|
|
1372
|
+
const apisToSet = Object.values(apis).map(({ api, scopeId }) => {
|
|
1373
|
+
api.apiPb.metadata.id = api.apiPb.metadata.name;
|
|
1374
|
+
return {
|
|
1375
|
+
...api,
|
|
1376
|
+
scopeId
|
|
1377
|
+
};
|
|
1378
|
+
});
|
|
1379
|
+
this.waitForInitApiPromise = new Promise((resolve) => {
|
|
1380
|
+
const callbackId = addNewPromise(resolve);
|
|
1381
|
+
window.parent.postMessage({
|
|
1382
|
+
type: "set-apis-deployed-mode",
|
|
1383
|
+
payload: {
|
|
1384
|
+
apis: apisToSet,
|
|
1385
|
+
callbackId
|
|
1386
|
+
}
|
|
1387
|
+
}, "*");
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
@action async rerunApiByCallId(callId) {
|
|
1391
|
+
const context$2 = this.callContexts[callId];
|
|
1392
|
+
if (!context$2) {
|
|
1393
|
+
console.error(`No call context found for callId: ${callId}`);
|
|
1394
|
+
throw new Error(`No call context found for callId: ${callId}`);
|
|
1395
|
+
}
|
|
1396
|
+
if (context$2.callback) {
|
|
1397
|
+
await context$2.callback();
|
|
1398
|
+
return {
|
|
1399
|
+
data: void 0,
|
|
1400
|
+
error: void 0
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
const result = await this.executeApiInternal({
|
|
1404
|
+
apiId: context$2.apiId,
|
|
1405
|
+
apiName: context$2.apiName,
|
|
1406
|
+
path: context$2.path,
|
|
1407
|
+
inputs: context$2.inputs,
|
|
1408
|
+
options: context$2.options,
|
|
1409
|
+
callId,
|
|
1410
|
+
callback: void 0
|
|
1411
|
+
});
|
|
1412
|
+
return {
|
|
1413
|
+
data: result.data,
|
|
1414
|
+
error: result.error
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
@action async runApiByPath({ path, inputs, callId, callback, isTestRun }) {
|
|
1418
|
+
await this.awaitInitApiIfNeeded();
|
|
1419
|
+
const apiName = path.match(/^\/apis\/([^/]+)\/api\.yaml$/)?.[1];
|
|
1420
|
+
if (!apiName) throw new Error(`Invalid path: ${path}`);
|
|
1421
|
+
editorBridge.setApiStarted(apiName);
|
|
1422
|
+
const result = await this.executeApiInternal({
|
|
1423
|
+
apiId: apiName,
|
|
1424
|
+
apiName,
|
|
1425
|
+
path,
|
|
1426
|
+
inputs,
|
|
1427
|
+
options: inputs ?? {},
|
|
1428
|
+
callId,
|
|
1429
|
+
isTestRun,
|
|
1430
|
+
callback
|
|
1431
|
+
});
|
|
1432
|
+
editorBridge.setApiResponse(apiName, result.parsedResult);
|
|
1433
|
+
return {
|
|
1434
|
+
data: result.data,
|
|
1435
|
+
error: result.error
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
async executeApiInternal({ apiId, apiName, path, inputs, options, callId: providedCallId, callback, isTestRun }) {
|
|
1439
|
+
const executionStartTime = Date.now();
|
|
1440
|
+
const callId = providedCallId ?? `${apiId}-${executionStartTime}-${Math.random().toString(36).substr(2, 9)}`;
|
|
1441
|
+
const isRerun = !!this.callContexts[callId];
|
|
1442
|
+
if (isRerun) editorBridge.updateApiRunRecord(apiId, callId, { loading: true });
|
|
1443
|
+
if (!this.rootStore.applicationId) {
|
|
1444
|
+
sendNotification({
|
|
1445
|
+
message: "No application ID was found, ensure the app was bootstrap correctly.",
|
|
1446
|
+
type: "error"
|
|
1447
|
+
});
|
|
1448
|
+
return {
|
|
1449
|
+
parsedResult: {
|
|
1450
|
+
status: "STATUS_COMPLETED",
|
|
1451
|
+
execution: "",
|
|
1452
|
+
errors: [{ message: "No application ID was found, ensure the app was bootstrap correctly." }]
|
|
1453
|
+
},
|
|
1454
|
+
data: null,
|
|
1455
|
+
error: "No application ID was found"
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
if (!this.agentUrls.length) {
|
|
1459
|
+
sendNotification({
|
|
1460
|
+
message: "No active agent found",
|
|
1461
|
+
type: "error"
|
|
1462
|
+
});
|
|
1463
|
+
return {
|
|
1464
|
+
parsedResult: {
|
|
1465
|
+
status: "STATUS_COMPLETED",
|
|
1466
|
+
execution: "",
|
|
1467
|
+
errors: [{ message: "No active agent found" }]
|
|
1468
|
+
},
|
|
1469
|
+
data: null,
|
|
1470
|
+
error: "No active agent found"
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
const agentBaseUrl = this.agentUrls[Math.floor(Math.random() * this.agentUrls.length)];
|
|
1474
|
+
const orchestratorUrl = new URL("v2/execute", agentBaseUrl).href;
|
|
1475
|
+
const profileKey = context$1.profiles?.selected?.key ?? "staging";
|
|
1476
|
+
const profileId = context$1.profiles?.selected?.id ?? "";
|
|
1477
|
+
const events = [];
|
|
1478
|
+
await this.rootStore.editStore?.operationManager.ensureFilesSynced();
|
|
1479
|
+
const abortController = new AbortController();
|
|
1480
|
+
this.runningApiControllers[apiName] = abortController;
|
|
1481
|
+
const editMode$1 = isEditMode();
|
|
1482
|
+
const isStream = editMode$1 ? true : false;
|
|
1483
|
+
const authResult = await new Promise((resolve) => {
|
|
1484
|
+
const callbackId = addNewPromise(resolve);
|
|
1485
|
+
window.parent.postMessage({
|
|
1486
|
+
type: "authenticate-api-request",
|
|
1487
|
+
payload: {
|
|
1488
|
+
apiId,
|
|
1489
|
+
callbackId
|
|
1490
|
+
}
|
|
1491
|
+
}, "*");
|
|
1492
|
+
});
|
|
1493
|
+
if (authResult?.errors && authResult.errors.length > 0) console.error("API Authentication returned with errors", authResult.errors);
|
|
1494
|
+
const { traceHeaders,...restArgs } = options;
|
|
1495
|
+
const { inputs: finalInputs, files } = await getInputsWithFileMetadata({
|
|
1496
|
+
...restArgs,
|
|
1497
|
+
...inputs
|
|
1498
|
+
});
|
|
1499
|
+
const syncResponse = await executeV2Api({
|
|
1500
|
+
body: {
|
|
1501
|
+
inputs: finalInputs,
|
|
1502
|
+
fetchByPath: {
|
|
1503
|
+
path,
|
|
1504
|
+
applicationId: this.rootStore.applicationId ?? "",
|
|
1505
|
+
branchName: "main",
|
|
1506
|
+
profile: {
|
|
1507
|
+
name: profileKey,
|
|
1508
|
+
id: profileId
|
|
1509
|
+
},
|
|
1510
|
+
viewMode: OrchestratorViewMode.UNSPECIFIED
|
|
1511
|
+
},
|
|
1512
|
+
options: {
|
|
1513
|
+
includeEventOutputs: editMode$1,
|
|
1514
|
+
includeEvents: isStream || editMode$1,
|
|
1515
|
+
includeResolved: editMode$1
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
apiName,
|
|
1519
|
+
controlFlowOnlyFiles: files,
|
|
1520
|
+
environment: profileKey,
|
|
1521
|
+
eventType: "api",
|
|
1522
|
+
notifyOnSystemError: true,
|
|
1523
|
+
responseType: isStream ? ApiResponseType.STREAM : ApiResponseType.SYNC,
|
|
1524
|
+
baseUrl: isStream ? orchestratorUrl + "/stream" : orchestratorUrl,
|
|
1525
|
+
agents: [],
|
|
1526
|
+
viewMode: editMode$1 ? ViewMode.EDITOR : ViewMode.DEPLOYED,
|
|
1527
|
+
accessToken: this.accessToken ?? "",
|
|
1528
|
+
token: this.token ?? "",
|
|
1529
|
+
traceHeaders,
|
|
1530
|
+
abortController,
|
|
1531
|
+
onMessage: (message) => {
|
|
1532
|
+
editorBridge.sendStreamedApiMessage(message, apiName);
|
|
1533
|
+
},
|
|
1534
|
+
processStreamEvents: (event) => {
|
|
1535
|
+
events.push(event);
|
|
1536
|
+
editorBridge.sendStreamedApiEvent(event, apiName);
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
const parsedResult = (isStream ? parseStreamResult(events, { includeFinalOutput: true }) : syncResponse) ?? void 0;
|
|
1540
|
+
if (parsedResult) decodeBytestringsInV2ExecutionResponse(parsedResult);
|
|
1541
|
+
delete this.runningApiControllers[apiName];
|
|
1542
|
+
const error = this.findError(parsedResult ?? void 0);
|
|
1543
|
+
const data = isApiV2ExecutionResponse(parsedResult) ? parsedResult?.output?.result : null;
|
|
1544
|
+
const timeTaken = Date.now() - executionStartTime;
|
|
1545
|
+
this.callContexts[callId] = {
|
|
1546
|
+
apiId,
|
|
1547
|
+
apiName,
|
|
1548
|
+
path,
|
|
1549
|
+
inputs,
|
|
1550
|
+
options,
|
|
1551
|
+
callback
|
|
1552
|
+
};
|
|
1553
|
+
if (isRerun) editorBridge.updateApiRunRecord(apiId, callId, {
|
|
1554
|
+
timestamp: executionStartTime,
|
|
1555
|
+
statusCode: this.extractStatusCode(parsedResult),
|
|
1556
|
+
timeTaken,
|
|
1557
|
+
inputs,
|
|
1558
|
+
response: data,
|
|
1559
|
+
error,
|
|
1560
|
+
loading: false,
|
|
1561
|
+
isTestRun
|
|
1562
|
+
});
|
|
1563
|
+
else editorBridge.addApiRunRecord(apiId, {
|
|
1564
|
+
id: `${apiId}-${executionStartTime}`,
|
|
1565
|
+
callId,
|
|
1566
|
+
timestamp: executionStartTime,
|
|
1567
|
+
statusCode: this.extractStatusCode(parsedResult),
|
|
1568
|
+
timeTaken,
|
|
1569
|
+
inputs,
|
|
1570
|
+
response: data,
|
|
1571
|
+
error,
|
|
1572
|
+
loading: false,
|
|
1573
|
+
isTestRun
|
|
1574
|
+
});
|
|
1575
|
+
return {
|
|
1576
|
+
parsedResult,
|
|
1577
|
+
data,
|
|
1578
|
+
error
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
findError(apiResponse) {
|
|
1582
|
+
if (apiResponse && "systemError" in apiResponse) return;
|
|
1583
|
+
const firstUnhandledError = apiResponse?.errors?.find((error) => !error?.handled);
|
|
1584
|
+
if (!firstUnhandledError) return;
|
|
1585
|
+
return `Error in API: ${firstUnhandledError?.message}`;
|
|
1586
|
+
}
|
|
1587
|
+
extractStatusCode(response) {
|
|
1588
|
+
if (!response) return 500;
|
|
1589
|
+
if ("systemError" in response) return 500;
|
|
1590
|
+
if ("errors" in response && response.errors && response.errors.length > 0) return 500;
|
|
1591
|
+
if ("status" in response && response.status === "STATUS_COMPLETED") return 200;
|
|
1592
|
+
return 500;
|
|
1593
|
+
}
|
|
1594
|
+
@action async cancelApi(apiName, _scopeId) {
|
|
1595
|
+
const abortController = this.runningApiControllers[apiName];
|
|
1596
|
+
if (!abortController) {
|
|
1597
|
+
console.warn(`No running API execution found for ${apiName}`);
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
abortController.abort();
|
|
1601
|
+
delete this.runningApiControllers[apiName];
|
|
1602
|
+
editorBridge.setApiResponse(apiName, {
|
|
1603
|
+
status: "STATUS_CANCELLED",
|
|
1604
|
+
execution: null,
|
|
1605
|
+
events: [],
|
|
1606
|
+
errors: [{ message: "API execution was cancelled" }],
|
|
1607
|
+
output: null
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
var api_store_default = ApiManager;
|
|
1612
|
+
|
|
1613
|
+
//#endregion
|
|
1614
|
+
//#region src/lib/internal-details/lib/evaluator/sanitize-object.ts
|
|
1615
|
+
const objectFallbackCache = /* @__PURE__ */ new WeakMap();
|
|
1616
|
+
function sanitizeObject(obj) {
|
|
1617
|
+
if (!objectFallbackCache.has(obj)) objectFallbackCache.set(obj, {});
|
|
1618
|
+
const fallbackCache = objectFallbackCache.get(obj);
|
|
1619
|
+
return new Proxy(obj, { get(target, prop) {
|
|
1620
|
+
try {
|
|
1621
|
+
const value = target[prop];
|
|
1622
|
+
if (typeof prop === "string") fallbackCache[prop] = value;
|
|
1623
|
+
return value;
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
if (error instanceof Promise) return typeof prop === "string" ? fallbackCache[prop] : void 0;
|
|
1626
|
+
throw error;
|
|
1627
|
+
}
|
|
1628
|
+
} });
|
|
1629
|
+
}
|
|
1630
|
+
function sanitizedToJS(value) {
|
|
1631
|
+
if (value === null || value === void 0 || typeof value !== "object") return toJS(value);
|
|
1632
|
+
return toJS(sanitizeObject(value));
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
//#endregion
|
|
1636
|
+
//#region src/edit-mode/mobx-sync/create-patch.ts
|
|
1637
|
+
const microPatches = (oldValue, newValue, baseStr) => {
|
|
1638
|
+
const cleanedOldValue = removeBindAndReactElements(oldValue);
|
|
1639
|
+
const cleanedNewValue = removeBindAndReactElements(newValue);
|
|
1640
|
+
if (cleanedOldValue === void 0) return [{
|
|
1641
|
+
op: "add",
|
|
1642
|
+
path: pathStringToArray(baseStr),
|
|
1643
|
+
value: cleanedNewValue
|
|
1644
|
+
}];
|
|
1645
|
+
if (isPrimitive(cleanedOldValue) || isPrimitive(cleanedNewValue)) {
|
|
1646
|
+
if (cleanedOldValue !== cleanedNewValue) return [{
|
|
1647
|
+
op: "update",
|
|
1648
|
+
path: pathStringToArray(baseStr),
|
|
1649
|
+
value: cleanedNewValue
|
|
1650
|
+
}];
|
|
1651
|
+
return [];
|
|
1652
|
+
}
|
|
1653
|
+
const diffs = diff(cleanedOldValue, cleanedNewValue);
|
|
1654
|
+
const basePath = pathStringToArray(baseStr);
|
|
1655
|
+
return diffs.map((diff$1) => toMobXPatchFromMicroDiff(diff$1, basePath));
|
|
1656
|
+
};
|
|
1657
|
+
function isPrimitive(value) {
|
|
1658
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "undefined";
|
|
1659
|
+
}
|
|
1660
|
+
function toMobXPatchFromMicroDiff(diff$1, basePath) {
|
|
1661
|
+
const type = diff$1.type;
|
|
1662
|
+
const fullPath = [...basePath, ...diff$1.path];
|
|
1663
|
+
switch (type) {
|
|
1664
|
+
case "CREATE": return {
|
|
1665
|
+
op: "add",
|
|
1666
|
+
path: fullPath,
|
|
1667
|
+
value: diff$1.value
|
|
1668
|
+
};
|
|
1669
|
+
case "CHANGE": return {
|
|
1670
|
+
op: "update",
|
|
1671
|
+
path: fullPath,
|
|
1672
|
+
value: diff$1.value
|
|
1673
|
+
};
|
|
1674
|
+
case "REMOVE": return {
|
|
1675
|
+
op: "remove",
|
|
1676
|
+
path: fullPath
|
|
1677
|
+
};
|
|
1678
|
+
default: throw new Error(`Unhandled diff type: ${type}`);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
const removeBindAndReactElements = (value) => {
|
|
1682
|
+
if (!value || typeof value !== "object") return value;
|
|
1683
|
+
if (isReactElement(value)) return;
|
|
1684
|
+
if (Array.isArray(value)) return value.map(removeBindAndReactElements);
|
|
1685
|
+
return Object.fromEntries(Object.entries(value).map(([key, value$1]) => {
|
|
1686
|
+
if (key === "bind") return [key, void 0];
|
|
1687
|
+
return [key, removeBindAndReactElements(value$1)];
|
|
1688
|
+
}));
|
|
1689
|
+
};
|
|
1690
|
+
|
|
1691
|
+
//#endregion
|
|
1692
|
+
//#region src/edit-mode/mobx-sync/deep-observe.ts
|
|
1693
|
+
function buildPath(entry) {
|
|
1694
|
+
if (!entry) return "ROOT";
|
|
1695
|
+
const res = [];
|
|
1696
|
+
while (entry.parent) {
|
|
1697
|
+
res.push(entry.path);
|
|
1698
|
+
entry = entry.parent;
|
|
1699
|
+
}
|
|
1700
|
+
return res.reverse().join("/");
|
|
1701
|
+
}
|
|
1702
|
+
function isRecursivelyObservable(thing) {
|
|
1703
|
+
return isObservableObject(thing) || isObservableArray(thing) || isObservableMap(thing);
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Given an object, deeply observes the given object.
|
|
1707
|
+
* It is like `observe` from mobx, but applied recursively, including all future children.
|
|
1708
|
+
*
|
|
1709
|
+
* Note that the given object cannot ever contain cycles and should be a tree.
|
|
1710
|
+
*
|
|
1711
|
+
* As benefit: path and root will be provided in the callback, so the signature of the listener is
|
|
1712
|
+
* (change, path, root) => void
|
|
1713
|
+
*
|
|
1714
|
+
* The returned disposer can be invoked to clean up the listener
|
|
1715
|
+
*
|
|
1716
|
+
* deepObserve cannot be used on computed values.
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* const disposer = deepObserve(target, (change, path) => {
|
|
1720
|
+
* console.dir(change)
|
|
1721
|
+
* })
|
|
1722
|
+
*/
|
|
1723
|
+
function deepObserve(target, listener) {
|
|
1724
|
+
const entrySet = /* @__PURE__ */ new WeakMap();
|
|
1725
|
+
function genericListener(change) {
|
|
1726
|
+
const entry = entrySet.get(change.object);
|
|
1727
|
+
processChange(change, entry);
|
|
1728
|
+
listener(change, buildPath(entry), target);
|
|
1729
|
+
}
|
|
1730
|
+
function processChange(change, parent) {
|
|
1731
|
+
switch (change.type) {
|
|
1732
|
+
case "add":
|
|
1733
|
+
observeRecursively(change.newValue, parent, change.name);
|
|
1734
|
+
break;
|
|
1735
|
+
case "update":
|
|
1736
|
+
unobserveRecursively(change.oldValue);
|
|
1737
|
+
observeRecursively(change.newValue, parent, change.name || "" + change.index);
|
|
1738
|
+
break;
|
|
1739
|
+
case "remove":
|
|
1740
|
+
case "delete":
|
|
1741
|
+
unobserveRecursively(change.oldValue);
|
|
1742
|
+
break;
|
|
1743
|
+
case "splice":
|
|
1744
|
+
change.removed.map(unobserveRecursively);
|
|
1745
|
+
change.added.forEach((value, idx) => observeRecursively(value, parent, "" + (change.index + idx)));
|
|
1746
|
+
for (let i = change.index + change.addedCount; i < change.object.length; i++) if (isRecursivelyObservable(change.object[i])) {
|
|
1747
|
+
const entry = entrySet.get(change.object[i]);
|
|
1748
|
+
if (entry) entry.path = "" + i;
|
|
1749
|
+
}
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function observeRecursively(thing, parent, path) {
|
|
1754
|
+
if (isRecursivelyObservable(thing)) {
|
|
1755
|
+
const entry = entrySet.get(thing);
|
|
1756
|
+
if (entry) {
|
|
1757
|
+
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}'`);
|
|
1758
|
+
} else {
|
|
1759
|
+
const entry$1 = {
|
|
1760
|
+
parent,
|
|
1761
|
+
path,
|
|
1762
|
+
dispose: observe(thing, genericListener)
|
|
1763
|
+
};
|
|
1764
|
+
entrySet.set(thing, entry$1);
|
|
1765
|
+
entries(thing).forEach(([key, value]) => observeRecursively(value, entry$1, "" + key));
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function unobserveRecursively(thing) {
|
|
1770
|
+
if (isRecursivelyObservable(thing)) {
|
|
1771
|
+
const entry = entrySet.get(thing);
|
|
1772
|
+
if (!entry) return;
|
|
1773
|
+
entrySet.delete(thing);
|
|
1774
|
+
entry.dispose();
|
|
1775
|
+
values(thing).forEach(unobserveRecursively);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
observeRecursively(target, void 0, "");
|
|
1779
|
+
return () => {
|
|
1780
|
+
unobserveRecursively(target);
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region src/edit-mode/mobx-sync/mobx-editor-sync.ts
|
|
1786
|
+
/**
|
|
1787
|
+
* Syncs a mobx store to the editor automatically through postmessage
|
|
1788
|
+
*/
|
|
1789
|
+
function startEditorSync(options) {
|
|
1790
|
+
if (!isEditMode()) return () => {};
|
|
1791
|
+
const { store, storeId, keys, projection, debounce } = options;
|
|
1792
|
+
const reactionOptions = {
|
|
1793
|
+
delay: debounce,
|
|
1794
|
+
name: `editor-sync(${storeId})`
|
|
1795
|
+
};
|
|
1796
|
+
let initialState;
|
|
1797
|
+
if (keys) initialState = sanitizedToJS(pick(store, Object.keys(keys)));
|
|
1798
|
+
else if (projection) initialState = sanitizedToJS(projection(store));
|
|
1799
|
+
else initialState = sanitizedToJS(store);
|
|
1800
|
+
editorBridge.initializeEditorSyncedStore({
|
|
1801
|
+
storeId,
|
|
1802
|
+
initialState
|
|
1803
|
+
});
|
|
1804
|
+
if (projection) {
|
|
1805
|
+
const initialProjection = projection(store);
|
|
1806
|
+
const projectionKeys = Object.keys(initialProjection);
|
|
1807
|
+
const createDisposer = (key) => {
|
|
1808
|
+
let lastValue;
|
|
1809
|
+
return reaction(() => {
|
|
1810
|
+
return sanitizedToJS(projection(store)[key]);
|
|
1811
|
+
}, (value) => {
|
|
1812
|
+
const diffs = microPatches(lastValue, value, key);
|
|
1813
|
+
lastValue = value;
|
|
1814
|
+
if (!(diffs.length === 0)) editorBridge.updateEditorSyncedStore({
|
|
1815
|
+
storeId,
|
|
1816
|
+
patch: diffs
|
|
1817
|
+
});
|
|
1818
|
+
}, reactionOptions);
|
|
1819
|
+
};
|
|
1820
|
+
const projectionDisposers = projectionKeys.reduce((acc, key) => {
|
|
1821
|
+
acc[key] = createDisposer(key);
|
|
1822
|
+
return acc;
|
|
1823
|
+
}, {});
|
|
1824
|
+
const projectionKeysDisposer = reaction(() => Object.keys(projection(store)), (newKeys) => {
|
|
1825
|
+
const lastKeys = Object.keys(projectionDisposers);
|
|
1826
|
+
const deletedKeys = lastKeys.filter((key) => !newKeys.includes(key));
|
|
1827
|
+
newKeys.filter((key) => !lastKeys.includes(key)).forEach((key) => {
|
|
1828
|
+
projectionDisposers[key] = createDisposer(key);
|
|
1829
|
+
editorBridge.updateEditorSyncedStore({
|
|
1830
|
+
storeId,
|
|
1831
|
+
patch: {
|
|
1832
|
+
op: "update",
|
|
1833
|
+
path: [key],
|
|
1834
|
+
value: sanitizedToJS(projection(store)[key])
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
});
|
|
1838
|
+
deletedKeys.forEach((key) => {
|
|
1839
|
+
projectionDisposers[key]();
|
|
1840
|
+
delete projectionDisposers[key];
|
|
1841
|
+
editorBridge.updateEditorSyncedStore({
|
|
1842
|
+
storeId,
|
|
1843
|
+
patch: {
|
|
1844
|
+
op: "remove",
|
|
1845
|
+
path: [key]
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
});
|
|
1849
|
+
}, reactionOptions);
|
|
1850
|
+
return () => {
|
|
1851
|
+
projectionKeysDisposer();
|
|
1852
|
+
Object.values(projectionDisposers).forEach((disposer) => disposer());
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
const keyArr = Object.keys(keys ?? store);
|
|
1856
|
+
const computedKeys = keyArr.filter((key) => isComputedProp(store, key));
|
|
1857
|
+
const observableKeys = keyArr.filter((key) => !computedKeys.includes(key));
|
|
1858
|
+
const disposers = [];
|
|
1859
|
+
const computedDisposers = computedKeys.map((key) => reaction(() => store[key], (value) => {
|
|
1860
|
+
editorBridge.updateEditorSyncedStore({
|
|
1861
|
+
storeId,
|
|
1862
|
+
patch: {
|
|
1863
|
+
op: "update",
|
|
1864
|
+
path: [key],
|
|
1865
|
+
value
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
}, reactionOptions));
|
|
1869
|
+
disposers.push(...computedDisposers);
|
|
1870
|
+
if (observableKeys.length > 0 || !(keys !== void 0)) {
|
|
1871
|
+
const deepDisposer = deepObserve(store, (change, pathStr) => {
|
|
1872
|
+
const patch = toMobXPatch(change, pathStr);
|
|
1873
|
+
if (keys && !keys[patch.path[0]]) return;
|
|
1874
|
+
try {
|
|
1875
|
+
editorBridge.updateEditorSyncedStore({
|
|
1876
|
+
storeId,
|
|
1877
|
+
patch
|
|
1878
|
+
});
|
|
1879
|
+
} catch (error) {
|
|
1880
|
+
console.error(`[startEditorSync][${storeId}] Failed to send patch:`, error);
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
disposers.push(deepDisposer);
|
|
1884
|
+
}
|
|
1885
|
+
return () => {
|
|
1886
|
+
disposers.forEach((disposer) => disposer());
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
//#endregion
|
|
1891
|
+
//#region src/lib/user-facing/properties-panel/properties-panel-definition.ts
|
|
1892
|
+
function createPropertiesPanelDefinition(sections, componentProps) {
|
|
1893
|
+
const sectionDefs = [];
|
|
1894
|
+
const getSectionChildren = (propDefinitions, parentPath) => {
|
|
1895
|
+
const properties = [];
|
|
1896
|
+
/**
|
|
1897
|
+
* There are three ways we can display a Composite prop:
|
|
1898
|
+
* 1. Prop control + popover panel (e.g: TextStyle)
|
|
1899
|
+
* 2. Prop control (e.g: Border)
|
|
1900
|
+
* 3. Inline, without a prop control (e.g: Search prop on Table, which contains backgroundColor, borderRadius, etc.)
|
|
1901
|
+
*
|
|
1902
|
+
* isCompositeWithInlineNestedProps is used to determine if a prop is of type (3).
|
|
1903
|
+
*/
|
|
1904
|
+
const isCompositeWithInlineNestedProps = (prop, fullPath) => {
|
|
1905
|
+
if (!(prop instanceof CompositeProp) || !prop.hasPropertiesPanelDisplay()) return false;
|
|
1906
|
+
const displayMode = prop.propertiesPanelChildrenDisplayMode();
|
|
1907
|
+
if (!displayMode) return false;
|
|
1908
|
+
return (typeof displayMode === "function" ? displayMode(componentProps, fullPath) : displayMode)?.type === "inline";
|
|
1909
|
+
};
|
|
1910
|
+
for (const [name, prop] of Object.entries(propDefinitions)) {
|
|
1911
|
+
if (!prop) continue;
|
|
1912
|
+
const fullPath = parentPath ? `${parentPath}.${name}` : name;
|
|
1913
|
+
if (isCompositeWithInlineNestedProps(prop, fullPath)) {
|
|
1914
|
+
const inlinePropertiesDefs = getSectionChildren(prop.nestedProps, fullPath);
|
|
1915
|
+
properties.push(...inlinePropertiesDefs);
|
|
1916
|
+
} else if (prop.hasPropertiesPanelDisplay()) {
|
|
1917
|
+
const def = prop.setName(fullPath).toDefinition(componentProps);
|
|
1918
|
+
if (def) properties.push(def);
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
return properties;
|
|
1922
|
+
};
|
|
1923
|
+
for (const section of Object.values(sections)) {
|
|
1924
|
+
const children = getSectionChildren(section.props, "");
|
|
1925
|
+
if (children.length === 0) continue;
|
|
1926
|
+
sectionDefs.push({
|
|
1927
|
+
name: section.name,
|
|
1928
|
+
category: section.category,
|
|
1929
|
+
children,
|
|
1930
|
+
showHeader: section.propertiesPanelConfig.showHeader,
|
|
1931
|
+
isDefaultOpen: section.propertiesPanelConfig.isDefaultOpen,
|
|
1932
|
+
headerType: section.propertiesPanelConfig.headerType,
|
|
1933
|
+
subHeader: section.propertiesPanelConfig.subHeader
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
return { sections: sectionDefs };
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region src/lib/user-facing/properties-panel/props-builder.ts
|
|
1941
|
+
function mergeRelations(existingRelations, relations) {
|
|
1942
|
+
if (!existingRelations || existingRelations.length === 0) return relations;
|
|
1943
|
+
if (!relations || relations.length === 0) return existingRelations;
|
|
1944
|
+
return existingRelations && existingRelations.length > 0 ? existingRelations.flatMap((existing) => relations.map((relation) => [...existing, ...relation])) : relations;
|
|
1945
|
+
}
|
|
1946
|
+
function getChildren(input, path, props) {
|
|
1947
|
+
function getChildrenFromSection(section) {
|
|
1948
|
+
return Object.keys(section.props).reduce((acc, key) => {
|
|
1949
|
+
const prop = section.props[key];
|
|
1950
|
+
if (!prop) return acc;
|
|
1951
|
+
const definition = prop.setName(path + "." + key).toDefinition(props);
|
|
1952
|
+
if (definition) acc[key] = definition;
|
|
1953
|
+
return acc;
|
|
1954
|
+
}, {});
|
|
1955
|
+
}
|
|
1956
|
+
let children;
|
|
1957
|
+
if (input instanceof Section) children = getChildrenFromSection(input);
|
|
1958
|
+
else if (Object.values(input).every((c) => c instanceof Section)) children = Object.values(input).reduce((acc, section) => {
|
|
1959
|
+
return {
|
|
1960
|
+
...acc,
|
|
1961
|
+
...getChildrenFromSection(section)
|
|
1962
|
+
};
|
|
1963
|
+
}, {});
|
|
1964
|
+
else children = Object.fromEntries(Object.entries(input).map(([key, prop]) => {
|
|
1965
|
+
return [key, prop.setName(path + "." + key).toDefinition(props)];
|
|
1966
|
+
}));
|
|
1967
|
+
return children;
|
|
1968
|
+
}
|
|
1969
|
+
var Section = class Section {
|
|
1970
|
+
props = {};
|
|
1971
|
+
propertiesPanelConfig = {
|
|
1972
|
+
showHeader: true,
|
|
1973
|
+
isDefaultOpen: true
|
|
1974
|
+
};
|
|
1975
|
+
constructor(category) {
|
|
1976
|
+
this.category = category;
|
|
1977
|
+
}
|
|
1978
|
+
static category(category) {
|
|
1979
|
+
return new Section(category);
|
|
1980
|
+
}
|
|
1981
|
+
children(props) {
|
|
1982
|
+
if (props instanceof CompositeProp || props instanceof RecordProp) this.props = {
|
|
1983
|
+
...this.props,
|
|
1984
|
+
...props.getProps()
|
|
1985
|
+
};
|
|
1986
|
+
else if (props instanceof UnionProp) this.props = {
|
|
1987
|
+
...this.props,
|
|
1988
|
+
...props.getProps()
|
|
1989
|
+
};
|
|
1990
|
+
else this.props = {
|
|
1991
|
+
...this.props,
|
|
1992
|
+
...props
|
|
1993
|
+
};
|
|
1994
|
+
return this;
|
|
1995
|
+
}
|
|
1996
|
+
add = this.children;
|
|
1997
|
+
propertiesPanel(config) {
|
|
1998
|
+
this.propertiesPanelConfig = {
|
|
1999
|
+
...this.propertiesPanelConfig,
|
|
2000
|
+
...config
|
|
2001
|
+
};
|
|
2002
|
+
return this;
|
|
2003
|
+
}
|
|
2004
|
+
get name() {
|
|
2005
|
+
switch (this.category) {
|
|
2006
|
+
case PropsCategory.Content: return "Content";
|
|
2007
|
+
case PropsCategory.Routing: return "Routing";
|
|
2008
|
+
case PropsCategory.Interaction: return "Interaction";
|
|
2009
|
+
case PropsCategory.Layout: return "Layout";
|
|
2010
|
+
case PropsCategory.Appearance: return "Appearance";
|
|
2011
|
+
case PropsCategory.Permissions: return "Permissions";
|
|
2012
|
+
case PropsCategory.EventHandlers: return "Actions";
|
|
2013
|
+
case PropsCategory.Styles: return "Styles";
|
|
2014
|
+
case PropsCategory.Uncategorized: return "Uncategorized";
|
|
2015
|
+
default: return "Uncategorized";
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
var Prop = class Prop {
|
|
2020
|
+
prop;
|
|
2021
|
+
/**
|
|
2022
|
+
* Relations are an array of arrays
|
|
2023
|
+
* each sub-array is AND requirements, and each element is an OR requirement
|
|
2024
|
+
*/
|
|
2025
|
+
relations = [];
|
|
2026
|
+
constructor(typeString) {
|
|
2027
|
+
this.prop = {
|
|
2028
|
+
path: "",
|
|
2029
|
+
dataType: typeString
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
static unset() {
|
|
2033
|
+
return new Prop("any");
|
|
2034
|
+
}
|
|
2035
|
+
static string() {
|
|
2036
|
+
return new Prop("string");
|
|
2037
|
+
}
|
|
2038
|
+
static number() {
|
|
2039
|
+
return new Prop("number");
|
|
2040
|
+
}
|
|
2041
|
+
static boolean() {
|
|
2042
|
+
return new Prop("boolean");
|
|
2043
|
+
}
|
|
2044
|
+
static array() {
|
|
2045
|
+
return new Prop("array");
|
|
2046
|
+
}
|
|
2047
|
+
static any() {
|
|
2048
|
+
return new Prop("any");
|
|
2049
|
+
}
|
|
2050
|
+
static jsx() {
|
|
2051
|
+
return new Prop("jsx");
|
|
2052
|
+
}
|
|
2053
|
+
static literal(value) {
|
|
2054
|
+
switch (typeof value) {
|
|
2055
|
+
case "string": return Prop.string().default(value);
|
|
2056
|
+
case "number": return Prop.number().default(value);
|
|
2057
|
+
case "boolean": return Prop.boolean().default(value);
|
|
2058
|
+
default: {
|
|
2059
|
+
const exhaustiveCheck = value;
|
|
2060
|
+
throw new Error(`Invalid literal value: ${exhaustiveCheck}`);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
static eventHandler() {
|
|
2065
|
+
return new Prop("eventHandler");
|
|
2066
|
+
}
|
|
2067
|
+
static function(implementation) {
|
|
2068
|
+
return new FunctionProp(implementation);
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Creates a composite property, which is a property that contains nested properties. For example,
|
|
2072
|
+
* the following composite property:
|
|
2073
|
+
*
|
|
2074
|
+
* ```ts
|
|
2075
|
+
* const prop = Prop.composite({
|
|
2076
|
+
* name: Prop.string(),
|
|
2077
|
+
* age: Prop.number(),
|
|
2078
|
+
* });
|
|
2079
|
+
* ```
|
|
2080
|
+
*
|
|
2081
|
+
* is equivalent to the following type:
|
|
2082
|
+
*
|
|
2083
|
+
* ```ts
|
|
2084
|
+
* type Prop = {
|
|
2085
|
+
* name: string;
|
|
2086
|
+
* age: number;
|
|
2087
|
+
* };
|
|
2088
|
+
* ```
|
|
2089
|
+
*/
|
|
2090
|
+
static composite(props) {
|
|
2091
|
+
return new CompositeProp(props);
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Creates a record property, which is a record that maps string keys to the nestedproperties. For example,
|
|
2095
|
+
* the following record property:
|
|
2096
|
+
*
|
|
2097
|
+
* ```ts
|
|
2098
|
+
* const prop = Prop.record({
|
|
2099
|
+
* name: Prop.string(),
|
|
2100
|
+
* age: Prop.number(),
|
|
2101
|
+
* });
|
|
2102
|
+
* ```
|
|
2103
|
+
*
|
|
2104
|
+
* is equivalent to the following type:
|
|
2105
|
+
*
|
|
2106
|
+
* ```ts
|
|
2107
|
+
* type Prop = Record<string, {
|
|
2108
|
+
* name: string;
|
|
2109
|
+
* age: number;
|
|
2110
|
+
* }>;
|
|
2111
|
+
* ```
|
|
2112
|
+
*/
|
|
2113
|
+
static record(props) {
|
|
2114
|
+
return new RecordProp(props);
|
|
2115
|
+
}
|
|
2116
|
+
static union(props) {
|
|
2117
|
+
return new UnionProp(props.shared, props.variants);
|
|
2118
|
+
}
|
|
2119
|
+
default(de) {
|
|
2120
|
+
this.prop.default = de;
|
|
2121
|
+
if (this.prop.propertiesPanelDisplay && this.prop.propertiesPanelDisplay.defaultValue === void 0) this.prop.propertiesPanelDisplay.defaultValue = de;
|
|
2122
|
+
return this;
|
|
2123
|
+
}
|
|
2124
|
+
contextual(computedArgs) {
|
|
2125
|
+
this.prop.contextual = true;
|
|
2126
|
+
this.prop.computedArgs = computedArgs;
|
|
2127
|
+
return this;
|
|
2128
|
+
}
|
|
2129
|
+
setName(name) {
|
|
2130
|
+
this.prop.path = name;
|
|
2131
|
+
return this;
|
|
2132
|
+
}
|
|
2133
|
+
propertiesPanel(schema) {
|
|
2134
|
+
let baseControlType;
|
|
2135
|
+
let isJSConvertible = true;
|
|
2136
|
+
let isTriggerProperty = false;
|
|
2137
|
+
let inputType;
|
|
2138
|
+
switch (this.prop.dataType) {
|
|
2139
|
+
case "string":
|
|
2140
|
+
baseControlType = "INPUT_TEXT";
|
|
2141
|
+
break;
|
|
2142
|
+
case "number":
|
|
2143
|
+
baseControlType = "INPUT_TEXT";
|
|
2144
|
+
inputType = InputType.NUMBER;
|
|
2145
|
+
break;
|
|
2146
|
+
case "array":
|
|
2147
|
+
baseControlType = "INPUT_TEXT";
|
|
2148
|
+
break;
|
|
2149
|
+
case "boolean":
|
|
2150
|
+
baseControlType = "SWITCH";
|
|
2151
|
+
break;
|
|
2152
|
+
case "eventHandler":
|
|
2153
|
+
baseControlType = "EVENT_HANDLER";
|
|
2154
|
+
isJSConvertible = false;
|
|
2155
|
+
isTriggerProperty = true;
|
|
2156
|
+
break;
|
|
2157
|
+
case "jsx":
|
|
2158
|
+
baseControlType = "JSX";
|
|
2159
|
+
break;
|
|
2160
|
+
case "any":
|
|
2161
|
+
default:
|
|
2162
|
+
baseControlType = "INPUT_JS_EXPR";
|
|
2163
|
+
break;
|
|
2164
|
+
}
|
|
2165
|
+
const propertiesPanelDisplay = {
|
|
2166
|
+
controlType: baseControlType,
|
|
2167
|
+
isJSConvertible,
|
|
2168
|
+
isTriggerProperty,
|
|
2169
|
+
defaultValue: schema.defaultValue ?? this.prop.default,
|
|
2170
|
+
defaultOnAdd: this.prop.propertiesPanelDisplay?.defaultOnAdd,
|
|
2171
|
+
inputType,
|
|
2172
|
+
...schema
|
|
2173
|
+
};
|
|
2174
|
+
this.prop.propertiesPanelDisplay = propertiesPanelDisplay;
|
|
2175
|
+
return this;
|
|
2176
|
+
}
|
|
2177
|
+
setDisplayProperty(property, value) {
|
|
2178
|
+
if (!this.prop.propertiesPanelDisplay) return this;
|
|
2179
|
+
this.prop.propertiesPanelDisplay[property] = value;
|
|
2180
|
+
return this;
|
|
2181
|
+
}
|
|
2182
|
+
docs(docs) {
|
|
2183
|
+
this.prop.docs = docs;
|
|
2184
|
+
return this;
|
|
2185
|
+
}
|
|
2186
|
+
build() {
|
|
2187
|
+
return this.prop;
|
|
2188
|
+
}
|
|
2189
|
+
toDefinition(props) {
|
|
2190
|
+
const evaluatedProperties = Object.entries(this.prop.propertiesPanelDisplay ?? {}).reduce((acc, [key, value]) => {
|
|
2191
|
+
if (typeof value === "function") try {
|
|
2192
|
+
acc[key] = value.bind(props)(this.prop.path);
|
|
2193
|
+
} catch (e) {
|
|
2194
|
+
console.error(`Error evaluating property ${key}:`, e);
|
|
2195
|
+
}
|
|
2196
|
+
return acc;
|
|
2197
|
+
}, {});
|
|
2198
|
+
if (evaluatedProperties.isVisible === false) return;
|
|
2199
|
+
const propertiesPanelDisplay = {
|
|
2200
|
+
...this.prop.propertiesPanelDisplay,
|
|
2201
|
+
...evaluatedProperties
|
|
2202
|
+
};
|
|
2203
|
+
if ("treatDefaultAsNull" in propertiesPanelDisplay) {
|
|
2204
|
+
if (propertiesPanelDisplay.treatDefaultAsNull) {
|
|
2205
|
+
if (propertiesPanelDisplay.defaultOnAdd === void 0) propertiesPanelDisplay.defaultOnAdd = propertiesPanelDisplay.defaultValue;
|
|
2206
|
+
propertiesPanelDisplay.defaultValue = void 0;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
let panelConfig;
|
|
2210
|
+
const childrenDisplay = propertiesPanelDisplay?.childrenDisplayMode;
|
|
2211
|
+
if (childrenDisplay?.type === "popover") {
|
|
2212
|
+
if (!(this instanceof CompositeProp || this instanceof RecordProp)) {
|
|
2213
|
+
console.error(this);
|
|
2214
|
+
throw new Error("Only composite properties can be used in popover properties at the moment");
|
|
2215
|
+
}
|
|
2216
|
+
const content = this.getProps();
|
|
2217
|
+
const { type,...rest } = childrenDisplay;
|
|
2218
|
+
let contentDef;
|
|
2219
|
+
if (content instanceof Section) contentDef = { content };
|
|
2220
|
+
else if (Object.values(content).every((c) => c instanceof Section)) contentDef = content;
|
|
2221
|
+
else contentDef = { content: Section.category(PropsCategory.Content).propertiesPanel({ showHeader: false }).children(content) };
|
|
2222
|
+
panelConfig = {
|
|
2223
|
+
...createPropertiesPanelDefinition(contentDef, props),
|
|
2224
|
+
...rest
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
if (this.prop.computedArgs) propertiesPanelDisplay.computedArgs = typeof this.prop.computedArgs === "function" ? this.prop.computedArgs(props) : this.prop.computedArgs;
|
|
2228
|
+
const propertiesPanelDisplayWithPanelConfig = {
|
|
2229
|
+
...propertiesPanelDisplay,
|
|
2230
|
+
...panelConfig && { panelConfig }
|
|
2231
|
+
};
|
|
2232
|
+
return {
|
|
2233
|
+
path: this.prop.path,
|
|
2234
|
+
dataType: this.prop.dataType,
|
|
2235
|
+
relations: this.relations,
|
|
2236
|
+
propertiesPanelDisplay: propertiesPanelDisplayWithPanelConfig
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
getRelations() {
|
|
2240
|
+
return this.relations;
|
|
2241
|
+
}
|
|
2242
|
+
dependsOn(relations) {
|
|
2243
|
+
this.relations = relations;
|
|
2244
|
+
return this;
|
|
2245
|
+
}
|
|
2246
|
+
hasPropertiesPanelDisplay() {
|
|
2247
|
+
return this.prop.propertiesPanelDisplay !== void 0;
|
|
2248
|
+
}
|
|
2249
|
+
get type() {
|
|
2250
|
+
return this.prop.dataType;
|
|
2251
|
+
}
|
|
2252
|
+
get path() {
|
|
2253
|
+
return this.prop.path;
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
/**
|
|
2257
|
+
* See {@link Prop.composite}
|
|
2258
|
+
*/
|
|
2259
|
+
var CompositeProp = class extends Prop {
|
|
2260
|
+
typeString = "composite";
|
|
2261
|
+
nestedProps;
|
|
2262
|
+
constructor(props) {
|
|
2263
|
+
super("composite");
|
|
2264
|
+
this.nestedProps = props;
|
|
2265
|
+
}
|
|
2266
|
+
getProps() {
|
|
2267
|
+
return this.nestedProps;
|
|
2268
|
+
}
|
|
2269
|
+
toDefinition(props) {
|
|
2270
|
+
const definition = super.toDefinition(props);
|
|
2271
|
+
if (!definition) return;
|
|
2272
|
+
return {
|
|
2273
|
+
...definition,
|
|
2274
|
+
children: getChildren(this.nestedProps, this.prop.path, props)
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
propertiesPanelChildrenDisplayMode() {
|
|
2278
|
+
return this.prop.propertiesPanelDisplay?.childrenDisplayMode;
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
/**
|
|
2282
|
+
* See {@link Prop.record}
|
|
2283
|
+
*/
|
|
2284
|
+
var RecordProp = class extends Prop {
|
|
2285
|
+
typeString = "recordOf";
|
|
2286
|
+
nestedProps;
|
|
2287
|
+
constructor(props) {
|
|
2288
|
+
super("recordOf");
|
|
2289
|
+
this.nestedProps = props;
|
|
2290
|
+
}
|
|
2291
|
+
getProps() {
|
|
2292
|
+
return this.nestedProps;
|
|
2293
|
+
}
|
|
2294
|
+
toDefinition(props) {
|
|
2295
|
+
const definition = super.toDefinition(props);
|
|
2296
|
+
if (!definition) return;
|
|
2297
|
+
return {
|
|
2298
|
+
...definition,
|
|
2299
|
+
children: getChildren(this.nestedProps, this.prop.path, props)
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
};
|
|
2303
|
+
var FunctionProp = class extends Prop {
|
|
2304
|
+
typeString = "function";
|
|
2305
|
+
_actionPanel;
|
|
2306
|
+
constructor(implementation) {
|
|
2307
|
+
super("function");
|
|
2308
|
+
this.default(implementation);
|
|
2309
|
+
}
|
|
2310
|
+
actionPanel(panel) {
|
|
2311
|
+
this._actionPanel = panel || {};
|
|
2312
|
+
return this;
|
|
2313
|
+
}
|
|
2314
|
+
getActionPanel() {
|
|
2315
|
+
return this._actionPanel;
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
var UnionProp = class extends Prop {
|
|
2319
|
+
typeString = "union";
|
|
2320
|
+
shared;
|
|
2321
|
+
variants;
|
|
2322
|
+
constructor(shared, variants) {
|
|
2323
|
+
super("any");
|
|
2324
|
+
this.shared = shared;
|
|
2325
|
+
this.variants = variants;
|
|
2326
|
+
}
|
|
2327
|
+
getProps() {
|
|
2328
|
+
const sharedKeys = Object.keys(this.shared);
|
|
2329
|
+
const variants = this.variants;
|
|
2330
|
+
const preMergeRelationsMap = variants.reduce((acc, v) => {
|
|
2331
|
+
Object.entries(v).forEach(([key, prop]) => {
|
|
2332
|
+
const existingRelations = acc[key] ?? [];
|
|
2333
|
+
const newRelations = prop.getRelations() ?? [];
|
|
2334
|
+
acc[key] = [...existingRelations, ...newRelations];
|
|
2335
|
+
});
|
|
2336
|
+
return acc;
|
|
2337
|
+
}, {});
|
|
2338
|
+
const mergedVariants = variants.reduce((acc, v) => {
|
|
2339
|
+
const relations = Object.entries(v).filter(([key]) => sharedKeys.includes(key)).map(([key, prop]) => {
|
|
2340
|
+
return {
|
|
2341
|
+
key,
|
|
2342
|
+
value: prop.build().default
|
|
2343
|
+
};
|
|
2344
|
+
});
|
|
2345
|
+
const filteredVariant = Object.fromEntries(Object.entries(v).filter(([key]) => !sharedKeys.includes(key)).map(([key, prop]) => {
|
|
2346
|
+
const existingRelations = prop?.getRelations() ?? [];
|
|
2347
|
+
const preMergeRelations = preMergeRelationsMap[key];
|
|
2348
|
+
const existingNonPreMergeRelations = existingRelations.filter((r) => !preMergeRelations.some((p) => p === r));
|
|
2349
|
+
const newProp = prop.dependsOn([...existingNonPreMergeRelations, ...mergeRelations(preMergeRelations, [relations])]);
|
|
2350
|
+
if (acc[key]) {
|
|
2351
|
+
const existingPropRelations = acc[key].getRelations() ?? [];
|
|
2352
|
+
const newPropRelations = newProp.getRelations() ?? [];
|
|
2353
|
+
const seenHashes = /* @__PURE__ */ new Set();
|
|
2354
|
+
const uniqueRelations = [...existingPropRelations, ...newPropRelations].filter((relationGroup) => {
|
|
2355
|
+
const hash = relationGroup.map((r) => `${r.key}:${String(r.value)}`).sort().join("|");
|
|
2356
|
+
if (seenHashes.has(hash)) return false;
|
|
2357
|
+
seenHashes.add(hash);
|
|
2358
|
+
return true;
|
|
2359
|
+
});
|
|
2360
|
+
return [key, acc[key].dependsOn(uniqueRelations)];
|
|
2361
|
+
}
|
|
2362
|
+
return [key, newProp];
|
|
2363
|
+
}));
|
|
2364
|
+
return {
|
|
2365
|
+
...acc,
|
|
2366
|
+
...filteredVariant
|
|
2367
|
+
};
|
|
2368
|
+
}, {});
|
|
2369
|
+
return {
|
|
2370
|
+
...this.shared,
|
|
2371
|
+
...mergedVariants
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
|
|
2376
|
+
//#endregion
|
|
2377
|
+
//#region src/lib/user-facing/properties-panel/create-managed-props-list.ts
|
|
2378
|
+
const RECORD_PATH_IDENTIFIER = "*";
|
|
2379
|
+
function buildCompositeDefault(prop, name, parentDefault) {
|
|
2380
|
+
const defaultThroughParent = parentDefault?.[name];
|
|
2381
|
+
const selfDefault = prop.build().default;
|
|
2382
|
+
let propDefault = defaultThroughParent ?? selfDefault;
|
|
2383
|
+
if (!propDefault && typeof parentDefault === "function") propDefault = function getNestedDefault(s) {
|
|
2384
|
+
return parentDefault.call(this, s)?.[name];
|
|
2385
|
+
};
|
|
2386
|
+
return propDefault;
|
|
2387
|
+
}
|
|
2388
|
+
function buildPropLeafDefault(prop, name, parentDefault) {
|
|
2389
|
+
const defaultThroughParent = parentDefault?.[name];
|
|
2390
|
+
let propDefault = prop.build().default ?? defaultThroughParent;
|
|
2391
|
+
if (!propDefault && typeof parentDefault === "function") propDefault = function getNestedDefault(s) {
|
|
2392
|
+
return parentDefault.call(this, s)?.[name];
|
|
2393
|
+
};
|
|
2394
|
+
return propDefault;
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Core traversal function that walks through all properties in sections
|
|
2398
|
+
* and calls the provided callback for each leaf property.
|
|
2399
|
+
*/
|
|
2400
|
+
function traverseProps(sections, onProp, parentPath = "") {
|
|
2401
|
+
const processProps = ({ props, parentPath: parentPath$1, parentDefault }) => {
|
|
2402
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
2403
|
+
if (!prop) continue;
|
|
2404
|
+
const fullPath = parentPath$1 ? `${parentPath$1}.${name}` : name;
|
|
2405
|
+
if (prop instanceof CompositeProp) {
|
|
2406
|
+
const compositeDefault = buildCompositeDefault(prop, name, parentDefault);
|
|
2407
|
+
processProps({
|
|
2408
|
+
props: prop.nestedProps,
|
|
2409
|
+
parentPath: fullPath,
|
|
2410
|
+
parentDefault: compositeDefault
|
|
2411
|
+
});
|
|
2412
|
+
} else if (prop instanceof RecordProp) {
|
|
2413
|
+
const recordPath = `${fullPath}.${RECORD_PATH_IDENTIFIER}`;
|
|
2414
|
+
processProps({
|
|
2415
|
+
props: prop.nestedProps,
|
|
2416
|
+
parentPath: recordPath,
|
|
2417
|
+
parentDefault: prop.build().default
|
|
2418
|
+
});
|
|
2419
|
+
} else if (prop instanceof Section) processProps({
|
|
2420
|
+
props: prop.props,
|
|
2421
|
+
parentPath: parentPath$1
|
|
2422
|
+
});
|
|
2423
|
+
else if (prop instanceof UnionProp) {
|
|
2424
|
+
const sharedKeys = Object.keys(prop.shared);
|
|
2425
|
+
processProps({
|
|
2426
|
+
props: prop.shared,
|
|
2427
|
+
parentPath: fullPath
|
|
2428
|
+
});
|
|
2429
|
+
for (const variant of prop.variants) processProps({
|
|
2430
|
+
props: Object.fromEntries(Object.entries(variant).filter(([key]) => !sharedKeys.includes(key))),
|
|
2431
|
+
parentPath: fullPath
|
|
2432
|
+
});
|
|
2433
|
+
} else if (prop instanceof Prop) onProp(prop, fullPath, name, parentDefault);
|
|
2434
|
+
else console.warn("Invalid prop type", {
|
|
2435
|
+
name,
|
|
2436
|
+
prop
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
for (const section of Object.values(sections)) processProps({
|
|
2441
|
+
props: section.props,
|
|
2442
|
+
parentPath,
|
|
2443
|
+
parentDefault: void 0
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
function createManagedPropsList(sections, parentPath = "") {
|
|
2447
|
+
const managedPropsList = [];
|
|
2448
|
+
traverseProps(sections, (prop, fullPath, name, parentDefault) => {
|
|
2449
|
+
let configuredProp = prop.setName(fullPath);
|
|
2450
|
+
const propDefault = buildPropLeafDefault(prop, name, parentDefault);
|
|
2451
|
+
if (propDefault !== void 0) configuredProp = configuredProp.default(propDefault);
|
|
2452
|
+
const builtProp = configuredProp.build();
|
|
2453
|
+
if (builtProp.dataType === "internal") return;
|
|
2454
|
+
managedPropsList.push({ ...builtProp });
|
|
2455
|
+
}, parentPath);
|
|
2456
|
+
return managedPropsList;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
//#endregion
|
|
2460
|
+
//#region src/lib/internal-details/lib/features/type-defs-utils.ts
|
|
2461
|
+
const analyzePropertyType = (propData, prop) => {
|
|
2462
|
+
let dataType;
|
|
2463
|
+
if (propData.dataType === "composite" && prop && typeof prop.getProps === "function") {
|
|
2464
|
+
const nestedProps = prop.getProps();
|
|
2465
|
+
const objectFields = {};
|
|
2466
|
+
for (const [key, nestedProp] of Object.entries(nestedProps)) if (nestedProp && typeof nestedProp.build === "function") {
|
|
2467
|
+
const nestedPropData = nestedProp.build();
|
|
2468
|
+
if (nestedPropData && nestedPropData.isExternallyReadable) objectFields[key] = analyzePropertyType(nestedPropData, nestedProp);
|
|
2469
|
+
}
|
|
2470
|
+
if (Object.keys(objectFields).length > 0) dataType = objectFields;
|
|
2471
|
+
} else if (propData.dataType === "dimension") dataType = {
|
|
2472
|
+
mode: "string",
|
|
2473
|
+
value: "number"
|
|
2474
|
+
};
|
|
2475
|
+
else if (propData.dataType === "string" || propData.dataType === "number" || propData.dataType === "boolean" || propData.dataType === "array" || propData.dataType === "function") dataType = propData.dataType;
|
|
2476
|
+
else dataType = "unknown";
|
|
2477
|
+
return dataType;
|
|
2478
|
+
};
|
|
2479
|
+
|
|
2480
|
+
//#endregion
|
|
2481
|
+
//#region src/lib/internal-details/lib/features/component-registry.ts
|
|
2482
|
+
/**
|
|
2483
|
+
* TODO: The component registry could be split into two a thin layer always on, and move some stuff to the EditStore.
|
|
2484
|
+
* Some of the actions (rename, delete) and some of the data (isDroppable) are editor-only.
|
|
2485
|
+
*/
|
|
2486
|
+
var ComponentRegistry = class {
|
|
2487
|
+
_componentRegistry = /* @__PURE__ */ new Map();
|
|
2488
|
+
_componentToType = /* @__PURE__ */ new WeakMap();
|
|
2489
|
+
_defaultContainerType;
|
|
2490
|
+
_defaultButtonType;
|
|
2491
|
+
_defaultTextType;
|
|
2492
|
+
constructor(rootStore) {
|
|
2493
|
+
this.rootStore = rootStore;
|
|
2494
|
+
makeAutoObservable(this);
|
|
2495
|
+
startEditorSync({
|
|
2496
|
+
store: this,
|
|
2497
|
+
storeId: "component-registry",
|
|
2498
|
+
keys: {
|
|
2499
|
+
customComponentList: true,
|
|
2500
|
+
libraryComponentCatalogs: true,
|
|
2501
|
+
libraryComponentEditorConfigs: true,
|
|
2502
|
+
entityDefinitions: true
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
getOrCreateMetadata(type) {
|
|
2507
|
+
let metadata = this._componentRegistry.get(type);
|
|
2508
|
+
if (!metadata) {
|
|
2509
|
+
metadata = {
|
|
2510
|
+
type,
|
|
2511
|
+
propertiesDefinition: {},
|
|
2512
|
+
managedProps: [],
|
|
2513
|
+
internalProps: [],
|
|
2514
|
+
editorTemplates: [],
|
|
2515
|
+
editorConfig: void 0
|
|
2516
|
+
};
|
|
2517
|
+
this._componentRegistry.set(type, metadata);
|
|
2518
|
+
}
|
|
2519
|
+
return metadata;
|
|
2520
|
+
}
|
|
2521
|
+
addComponent(type, rawComponent, propertiesDefinition) {
|
|
2522
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2523
|
+
metadata.propertiesDefinition = propertiesDefinition;
|
|
2524
|
+
if (typeof rawComponent !== "string") this._componentToType.set(rawComponent, type);
|
|
2525
|
+
}
|
|
2526
|
+
deleteComponent(type) {
|
|
2527
|
+
this._componentRegistry.delete(type);
|
|
2528
|
+
}
|
|
2529
|
+
renameComponent(oldName, newName) {
|
|
2530
|
+
const metadata = this._componentRegistry.get(oldName);
|
|
2531
|
+
if (metadata) {
|
|
2532
|
+
metadata.type = newName;
|
|
2533
|
+
this._componentRegistry.set(newName, metadata);
|
|
2534
|
+
this._componentRegistry.delete(oldName);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
addManagedProps(type, props) {
|
|
2538
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2539
|
+
metadata.managedProps = props;
|
|
2540
|
+
}
|
|
2541
|
+
deleteManagedProps(type) {
|
|
2542
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2543
|
+
metadata.managedProps = [];
|
|
2544
|
+
}
|
|
2545
|
+
addEditorTemplate(type, template) {
|
|
2546
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2547
|
+
const existingTemplates = metadata.editorTemplates;
|
|
2548
|
+
if (existingTemplates.some((t) => t.catalog?.displayName === template.catalog?.displayName && t.catalog?.category === template.catalog?.category)) return;
|
|
2549
|
+
metadata.editorTemplates = [...existingTemplates, template];
|
|
2550
|
+
}
|
|
2551
|
+
getEditorTemplates(type) {
|
|
2552
|
+
return this._componentRegistry.get(type)?.editorTemplates;
|
|
2553
|
+
}
|
|
2554
|
+
getEditorConfigFromComponentType(type) {
|
|
2555
|
+
const componentStrType = this.getTypeForComponent(type);
|
|
2556
|
+
return componentStrType ? this.getEditorConfig(componentStrType) : void 0;
|
|
2557
|
+
}
|
|
2558
|
+
addEditorConfig(type, config) {
|
|
2559
|
+
if (config.useAs) {
|
|
2560
|
+
if (config.useAs.defaultContainer) this._defaultContainerType = type;
|
|
2561
|
+
if (config.useAs.defaultButton) this._defaultButtonType = type;
|
|
2562
|
+
if (config.useAs.defaultText) this._defaultTextType = type;
|
|
2563
|
+
}
|
|
2564
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2565
|
+
metadata.editorConfig = config;
|
|
2566
|
+
}
|
|
2567
|
+
addInternalProps(type, props) {
|
|
2568
|
+
const metadata = this.getOrCreateMetadata(type);
|
|
2569
|
+
metadata.internalProps = props;
|
|
2570
|
+
}
|
|
2571
|
+
getInternalProps(type) {
|
|
2572
|
+
return this._componentRegistry.get(type)?.internalProps ?? [];
|
|
2573
|
+
}
|
|
2574
|
+
getEditorConfig(type) {
|
|
2575
|
+
return this._componentRegistry.get(type)?.editorConfig;
|
|
2576
|
+
}
|
|
2577
|
+
get entityDefinitions() {
|
|
2578
|
+
const entityDefinitions = {};
|
|
2579
|
+
for (const [componentType, metadata] of this._componentRegistry.entries()) {
|
|
2580
|
+
const propertiesDefinition = metadata.propertiesDefinition;
|
|
2581
|
+
if (!propertiesDefinition) continue;
|
|
2582
|
+
const entityDefinition = {
|
|
2583
|
+
description: metadata.editorConfig?.description,
|
|
2584
|
+
props: {}
|
|
2585
|
+
};
|
|
2586
|
+
for (const section of Object.values(propertiesDefinition)) for (const [propKey, propValue] of Object.entries(section.props)) {
|
|
2587
|
+
if (!propValue) continue;
|
|
2588
|
+
const prop = propValue;
|
|
2589
|
+
const propData = prop.build();
|
|
2590
|
+
if (propData && propData.isExternallyReadable) {
|
|
2591
|
+
const dataType = analyzePropertyType(propData, prop);
|
|
2592
|
+
const entityDefEntry = {
|
|
2593
|
+
label: propData.docs?.label,
|
|
2594
|
+
description: propData.docs?.description,
|
|
2595
|
+
isSettable: propData.isExternallySettable,
|
|
2596
|
+
dataType
|
|
2597
|
+
};
|
|
2598
|
+
entityDefinition.props[propKey] = entityDefEntry;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
entityDefinitions[componentType] = entityDefinition;
|
|
2602
|
+
}
|
|
2603
|
+
return entityDefinitions;
|
|
2604
|
+
}
|
|
2605
|
+
get libraryComponentCatalogs() {
|
|
2606
|
+
const catalogs = [];
|
|
2607
|
+
for (const [componentType, metadata] of this._componentRegistry.entries()) for (const template of metadata.editorTemplates) {
|
|
2608
|
+
const catalog = template.catalog;
|
|
2609
|
+
if (catalog) catalogs.push({
|
|
2610
|
+
...catalog,
|
|
2611
|
+
componentType
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
return catalogs;
|
|
2615
|
+
}
|
|
2616
|
+
get libraryComponentEditorConfigs() {
|
|
2617
|
+
const configs = {};
|
|
2618
|
+
for (const [componentType, metadata] of this._componentRegistry.entries()) if (metadata.editorConfig) configs[componentType] = metadata.editorConfig;
|
|
2619
|
+
return configs;
|
|
2620
|
+
}
|
|
2621
|
+
get customComponentList() {
|
|
2622
|
+
return Array.from(this._componentRegistry.keys());
|
|
2623
|
+
}
|
|
2624
|
+
get containerTypes() {
|
|
2625
|
+
return new Set([this.defaultTagNames.container]);
|
|
2626
|
+
}
|
|
2627
|
+
get defaultTagNames() {
|
|
2628
|
+
if (!this._defaultContainerType) console.warn("No default container registered - defaulting to 'Container'.");
|
|
2629
|
+
if (!this._defaultButtonType) console.warn("No default button registered - defaulting to 'Button'.");
|
|
2630
|
+
if (!this._defaultTextType) console.warn("No default text registered - defaulting to 'Text'.");
|
|
2631
|
+
return {
|
|
2632
|
+
container: this._defaultContainerType ?? "Container",
|
|
2633
|
+
button: this._defaultButtonType ?? "Button",
|
|
2634
|
+
text: this._defaultTextType ?? "Text"
|
|
2635
|
+
};
|
|
2636
|
+
}
|
|
2637
|
+
get managedPropsRegistry() {
|
|
2638
|
+
const registry = /* @__PURE__ */ new Map();
|
|
2639
|
+
for (const [type, metadata] of this._componentRegistry.entries()) registry.set(type, metadata.managedProps);
|
|
2640
|
+
return registry;
|
|
2641
|
+
}
|
|
2642
|
+
getManagedProps(type) {
|
|
2643
|
+
return this._componentRegistry.get(type)?.managedProps ?? [];
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* Get the component type string for a raw component reference.
|
|
2647
|
+
* Used for registry-based component identity checking.
|
|
2648
|
+
*/
|
|
2649
|
+
getTypeForComponent(component) {
|
|
2650
|
+
return this._componentToType.get(component);
|
|
2651
|
+
}
|
|
2652
|
+
/**
|
|
2653
|
+
* Check if a component or element type is registered in the component registry.
|
|
2654
|
+
* Accepts both component references and string element names (e.g., "div").
|
|
2655
|
+
* Used for component identity checking instead of symbol-based approach.
|
|
2656
|
+
*/
|
|
2657
|
+
hasComponent(component) {
|
|
2658
|
+
if (typeof component === "string") return this._componentRegistry.has(component);
|
|
2659
|
+
return this._componentToType.has(component);
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* Get the property path with the record identifier if it exists. For example,
|
|
2663
|
+
* `columns.columnName.label` becomes `columns.*.label`, for record properties.
|
|
2664
|
+
*/
|
|
2665
|
+
getPropertyWithRecordIdentifier(type, path) {
|
|
2666
|
+
const managedProps = this.getManagedProps(type);
|
|
2667
|
+
const splitPath = path.split(".");
|
|
2668
|
+
if (splitPath.length === 1) return path;
|
|
2669
|
+
const [parentKey, _maybeTheRecordKey, ...rest] = splitPath;
|
|
2670
|
+
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 [
|
|
2671
|
+
parentKey,
|
|
2672
|
+
RECORD_PATH_IDENTIFIER,
|
|
2673
|
+
rest.join(".")
|
|
2674
|
+
].join(".");
|
|
2675
|
+
return path;
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2679
|
+
//#endregion
|
|
2680
|
+
//#region src/lib/internal-details/lib/root-store.ts
|
|
2681
|
+
var RootStore = class {
|
|
2682
|
+
apis;
|
|
2683
|
+
componentRegistry;
|
|
2684
|
+
editStore;
|
|
2685
|
+
locationStore;
|
|
2686
|
+
currentPageScopeId;
|
|
2687
|
+
applicationId;
|
|
2688
|
+
userId;
|
|
2689
|
+
windowOriginUrl;
|
|
2690
|
+
editorRegisteredCallbacks = [];
|
|
2691
|
+
constructor() {
|
|
2692
|
+
this.apis = new api_store_default(this);
|
|
2693
|
+
this.componentRegistry = new ComponentRegistry(this);
|
|
2694
|
+
this.locationStore = new LocationStore(this);
|
|
2695
|
+
makeObservable(this, {
|
|
2696
|
+
editStore: observable.shallow,
|
|
2697
|
+
setEditStore: action,
|
|
2698
|
+
applicationId: observable,
|
|
2699
|
+
userId: observable
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
setEditStore(editStore) {
|
|
2703
|
+
if (this.editStore) return;
|
|
2704
|
+
this.editStore = editStore;
|
|
2705
|
+
this.editorRegisteredCallbacks.forEach((fn) => fn());
|
|
2706
|
+
this.editorRegisteredCallbacks = [];
|
|
2707
|
+
}
|
|
2708
|
+
onEditorRegistered(fn) {
|
|
2709
|
+
this.editorRegisteredCallbacks.push(fn);
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
var root_store_default = new RootStore();
|
|
2713
|
+
|
|
2714
|
+
//#endregion
|
|
2715
|
+
//#region src/lib/user-facing/assets/images/clark.svg
|
|
2716
|
+
var _path$1, _path2, _path3, _path4, _path5, _path6, _path7, _defs;
|
|
2717
|
+
function _extends$1() {
|
|
2718
|
+
return _extends$1 = Object.assign ? Object.assign.bind() : function(n) {
|
|
2719
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
2720
|
+
var t = arguments[e];
|
|
2721
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2722
|
+
}
|
|
2723
|
+
return n;
|
|
2724
|
+
}, _extends$1.apply(null, arguments);
|
|
2725
|
+
}
|
|
2726
|
+
var SvgClark = function SvgClark$1(props) {
|
|
2727
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends$1({
|
|
2728
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2729
|
+
width: 28,
|
|
2730
|
+
height: 20,
|
|
2731
|
+
fill: "none"
|
|
2732
|
+
}, props), _path$1 || (_path$1 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2733
|
+
fill: "url(#clark_svg__a)",
|
|
2734
|
+
d: "M20.41 1.239a5.16 5.16 0 0 0-4.703 5.413l2.648-.232a2.227 2.227 0 1 1 2.886 2.49l.18 2.062.035.02c.575-.05 1.213-.454 1.57-.748 1.617-1.337 1.71-3.2 1.705-3.672 0-.063.047-.117.11-.123l.27-.024a.18.18 0 0 0 .167-.206c-.068-.444-.304-1.577-1.018-2.419-.064-.074-.019-.194.079-.203l.402-.035c.142-.012.218-.166.13-.28-.492-.64-1.994-2.26-4.46-2.043"
|
|
2735
|
+
})), _path2 || (_path2 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2736
|
+
fill: "#2A333D",
|
|
2737
|
+
d: "M18.333 6.987a2.226 2.226 0 0 0 2.411 2.024l.555-.048c-.612-2.74-1.987-3.551-1.987-3.551.153-.386 1.044-.836 1.044-.836a2.226 2.226 0 0 0-2.023 2.411",
|
|
2738
|
+
opacity: .12
|
|
2739
|
+
})), _path3 || (_path3 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2740
|
+
fill: "url(#clark_svg__b)",
|
|
2741
|
+
d: "m6.65 12.564.045.492-.228-2.607A2.338 2.338 0 1 1 8.58 6.587l2.588-.226a5.16 5.16 0 0 0-5.371-3.584c-2.467.216-3.665 2.072-4.039 2.787-.066.127.035.266.177.253l.403-.035c.097-.008.162.102.113.186-.558.953-.593 2.11-.583 2.56a.18.18 0 0 0 .2.173l.27-.023a.12.12 0 0 1 .13.101c.078.467.492 2.285 2.317 3.32.402.228 1.291.515 1.866.465"
|
|
2742
|
+
})), _path4 || (_path4 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2743
|
+
fill: "#2A333D",
|
|
2744
|
+
d: "M9.161 7.938a2.337 2.337 0 0 1-2.124 2.53l-.582.052c.133-2.944 1.406-4.032 1.406-4.032-.227-.371-1.231-.675-1.231-.675A2.337 2.337 0 0 1 9.16 7.938",
|
|
2745
|
+
opacity: .12
|
|
2746
|
+
})), _path5 || (_path5 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2747
|
+
fill: "currentColor",
|
|
2748
|
+
fillRule: "evenodd",
|
|
2749
|
+
d: "M21.72 10.543c-.461-3.366-2.697-6.01-6.685-6.252-.109-.006-.163-.01-.202-.031a.2.2 0 0 1-.078-.084c-.02-.04-.02-.092-.02-.197v-.572a.192.192 0 0 0-.308-.153l-.938.708a.192.192 0 0 1-.309-.154v-.361a.192.192 0 0 0-.318-.145l-.807.717a9 9 0 0 1-.5.431 2 2 0 0 1-.305.2c-.119.069-.414.205-1.004.477-2.794 1.29-4.104 3.885-3.852 6.757.43 4.911 3.404 6.652 8.266 6.226 4.215-.368 7.758-2.469 7.06-7.567M11.64 10.2c.142.62-.16 1.221-.678 1.34-.518.12-1.053-.286-1.197-.907a1.3 1.3 0 0 1-.018-.521.384.384 0 1 0 .376-.667.8.8 0 0 1 .32-.153c.517-.12 1.053.287 1.196.908m7.042-.148c.51-.146.782-.761.606-1.374-.176-.612-.732-.99-1.242-.844a.83.83 0 0 0-.375.23.384.384 0 1 1-.284.713q-.01.211.052.431c.176.613.732.99 1.243.844m-5.448 3.596-.253-2.896a2.08 2.08 0 0 1 4.092-.685l.704 2.82a2.31 2.31 0 1 1-4.543.761",
|
|
2750
|
+
clipRule: "evenodd"
|
|
2751
|
+
})), _path6 || (_path6 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2752
|
+
fill: "url(#clark_svg__c)",
|
|
2753
|
+
d: "M13.88 14.096a2.3 2.3 0 0 0 1.847.492 2.3 2.3 0 0 0 1.585-1.066 1.79 1.79 0 0 1-3.431.574",
|
|
2754
|
+
opacity: .5
|
|
2755
|
+
})), _path7 || (_path7 = /* @__PURE__ */ React$1.createElement("path", {
|
|
2756
|
+
fill: "url(#clark_svg__d)",
|
|
2757
|
+
d: "M13.191 13.144a2.312 2.312 0 0 0 4.465-.748l.123.491a2.31 2.31 0 1 1-4.544.761z",
|
|
2758
|
+
opacity: .5
|
|
2759
|
+
})), _defs || (_defs = /* @__PURE__ */ React$1.createElement("defs", null, /* @__PURE__ */ React$1.createElement("linearGradient", {
|
|
2760
|
+
id: "clark_svg__a",
|
|
2761
|
+
x1: 21.636,
|
|
2762
|
+
x2: 17.027,
|
|
2763
|
+
y1: 4.149,
|
|
2764
|
+
y2: 8.785,
|
|
2765
|
+
gradientUnits: "userSpaceOnUse"
|
|
2766
|
+
}, /* @__PURE__ */ React$1.createElement("stop", { stopColor: "currentColor" }), /* @__PURE__ */ React$1.createElement("stop", {
|
|
2767
|
+
offset: 1,
|
|
2768
|
+
stopColor: "currentColor",
|
|
2769
|
+
stopOpacity: .84
|
|
2770
|
+
})), /* @__PURE__ */ React$1.createElement("linearGradient", {
|
|
2771
|
+
id: "clark_svg__b",
|
|
2772
|
+
x1: 4.534,
|
|
2773
|
+
x2: 10.643,
|
|
2774
|
+
y1: 6.603,
|
|
2775
|
+
y2: 9.712,
|
|
2776
|
+
gradientUnits: "userSpaceOnUse"
|
|
2777
|
+
}, /* @__PURE__ */ React$1.createElement("stop", { stopColor: "currentColor" }), /* @__PURE__ */ React$1.createElement("stop", {
|
|
2778
|
+
offset: 1,
|
|
2779
|
+
stopColor: "currentColor",
|
|
2780
|
+
stopOpacity: .84
|
|
2781
|
+
})), /* @__PURE__ */ React$1.createElement("linearGradient", {
|
|
2782
|
+
id: "clark_svg__c",
|
|
2783
|
+
x1: 15.788,
|
|
2784
|
+
x2: 16.004,
|
|
2785
|
+
y1: 13.866,
|
|
2786
|
+
y2: 15.093,
|
|
2787
|
+
gradientUnits: "userSpaceOnUse"
|
|
2788
|
+
}, /* @__PURE__ */ React$1.createElement("stop", {
|
|
2789
|
+
stopColor: "currentColor",
|
|
2790
|
+
stopOpacity: .6
|
|
2791
|
+
}), /* @__PURE__ */ React$1.createElement("stop", {
|
|
2792
|
+
offset: 1,
|
|
2793
|
+
stopColor: "currentColor"
|
|
2794
|
+
})), /* @__PURE__ */ React$1.createElement("linearGradient", {
|
|
2795
|
+
id: "clark_svg__d",
|
|
2796
|
+
x1: 15.704,
|
|
2797
|
+
x2: 16.07,
|
|
2798
|
+
y1: 13.597,
|
|
2799
|
+
y2: 15.67,
|
|
2800
|
+
gradientUnits: "userSpaceOnUse"
|
|
2801
|
+
}, /* @__PURE__ */ React$1.createElement("stop", {
|
|
2802
|
+
stopColor: "currentColor",
|
|
2803
|
+
stopOpacity: .6
|
|
2804
|
+
}), /* @__PURE__ */ React$1.createElement("stop", {
|
|
2805
|
+
offset: 1,
|
|
2806
|
+
stopColor: "currentColor"
|
|
2807
|
+
})))));
|
|
2808
|
+
};
|
|
2809
|
+
var clark_default = SvgClark;
|
|
2810
|
+
|
|
2811
|
+
//#endregion
|
|
2812
|
+
//#region src/lib/internal-details/internal-components/common.ts
|
|
2813
|
+
const ErrorIconContainer = styled.div`
|
|
2814
|
+
width: 60px;
|
|
2815
|
+
height: 60px;
|
|
2816
|
+
min-width: 60px;
|
|
2817
|
+
min-height: 60px;
|
|
2818
|
+
background: linear-gradient(135deg, #aab 0%, #000033 50%, #000066 100%);
|
|
2819
|
+
border-radius: 16px;
|
|
2820
|
+
display: flex;
|
|
2821
|
+
align-items: center;
|
|
2822
|
+
justify-content: center;
|
|
2823
|
+
margin: 0 auto 16px;
|
|
2824
|
+
flex-shrink: 0;
|
|
2825
|
+
animation: scaleIn 0.3s ease-out forwards;
|
|
2826
|
+
opacity: 0;
|
|
2827
|
+
box-shadow:
|
|
2828
|
+
0 0 1px black,
|
|
2829
|
+
0 4px 12px rgba(0, 85, 187, 0.15),
|
|
2830
|
+
0 2px 4px rgba(0, 85, 187, 0.05);
|
|
2831
|
+
|
|
2832
|
+
@keyframes scaleIn {
|
|
2833
|
+
from {
|
|
2834
|
+
transform: scale(0.8);
|
|
2835
|
+
opacity: 0;
|
|
2836
|
+
}
|
|
2837
|
+
to {
|
|
2838
|
+
transform: scale(1);
|
|
2839
|
+
opacity: 1;
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
`;
|
|
2843
|
+
const StyledClarkIcon = styled(clark_default)`
|
|
2844
|
+
width: 54px;
|
|
2845
|
+
height: 54px;
|
|
2846
|
+
color: white;
|
|
2847
|
+
margin-top: 3px;
|
|
2848
|
+
margin-left: 1px;
|
|
2849
|
+
animation: scaleIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
|
|
2850
|
+
opacity: 0;
|
|
2851
|
+
|
|
2852
|
+
@keyframes scaleIn {
|
|
2853
|
+
0% {
|
|
2854
|
+
transform: scale(0.6);
|
|
2855
|
+
opacity: 0;
|
|
2856
|
+
}
|
|
2857
|
+
50% {
|
|
2858
|
+
transform: scale(1.1);
|
|
2859
|
+
}
|
|
2860
|
+
100% {
|
|
2861
|
+
transform: scale(1);
|
|
2862
|
+
opacity: 1;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
`;
|
|
2866
|
+
const ErrorTitle = styled.h2`
|
|
2867
|
+
font-family: Inter;
|
|
2868
|
+
color: rgba(0, 0, 0, 0.85);
|
|
2869
|
+
font-weight: 600;
|
|
2870
|
+
font-size: 24px;
|
|
2871
|
+
line-height: 1.35;
|
|
2872
|
+
text-align: center;
|
|
2873
|
+
margin-bottom: 6px;
|
|
2874
|
+
flex-shrink: 0;
|
|
2875
|
+
`;
|
|
2876
|
+
const ErrorMessage = styled.p`
|
|
2877
|
+
font-family: Inter;
|
|
2878
|
+
font-size: 14px;
|
|
2879
|
+
color: #6c7689;
|
|
2880
|
+
line-height: 1.5715;
|
|
2881
|
+
text-align: center;
|
|
2882
|
+
flex-shrink: 0;
|
|
2883
|
+
margin-top: 0;
|
|
2884
|
+
margin-bottom: 16px;
|
|
2885
|
+
`;
|
|
2886
|
+
const ErrorDetails = styled.details`
|
|
2887
|
+
margin-top: 24px;
|
|
2888
|
+
text-align: left;
|
|
2889
|
+
background-color: #f9fafb;
|
|
2890
|
+
border-radius: 6px;
|
|
2891
|
+
padding: 16px;
|
|
2892
|
+
box-shadow:
|
|
2893
|
+
0px 0px 1px 0px #22272f52,
|
|
2894
|
+
0px 1px 3px 0px #22272f1f;
|
|
2895
|
+
flex-shrink: 0;
|
|
2896
|
+
font-family: Inter;
|
|
2897
|
+
|
|
2898
|
+
&[open] summary {
|
|
2899
|
+
margin-bottom: 12px;
|
|
2900
|
+
}
|
|
2901
|
+
`;
|
|
2902
|
+
const ErrorSummary = styled.summary`
|
|
2903
|
+
cursor: pointer;
|
|
2904
|
+
font-weight: 500;
|
|
2905
|
+
color: #374151;
|
|
2906
|
+
font-size: 14px;
|
|
2907
|
+
user-select: none;
|
|
2908
|
+
`;
|
|
2909
|
+
const ErrorStack = styled.pre`
|
|
2910
|
+
font-size: 12px;
|
|
2911
|
+
color: #dc2626;
|
|
2912
|
+
overflow: auto;
|
|
2913
|
+
white-space: pre-wrap;
|
|
2914
|
+
margin: 16px;
|
|
2915
|
+
font-family: monospace;
|
|
2916
|
+
`;
|
|
2917
|
+
const ErrorContainer = styled.div`
|
|
2918
|
+
position: absolute;
|
|
2919
|
+
inset: 0;
|
|
2920
|
+
display: flex;
|
|
2921
|
+
align-items: center;
|
|
2922
|
+
justify-content: center;
|
|
2923
|
+
z-index: 10;
|
|
2924
|
+
background: rgba(255, 255, 255, 0.5);
|
|
2925
|
+
pointer-events: auto;
|
|
2926
|
+
`;
|
|
2927
|
+
const ErrorContent = styled.div`
|
|
2928
|
+
max-width: 700px;
|
|
2929
|
+
padding: 40px;
|
|
2930
|
+
overflow-y: auto;
|
|
2931
|
+
flex: 1;
|
|
2932
|
+
display: flex;
|
|
2933
|
+
flex-direction: column;
|
|
2934
|
+
gap: 20px;
|
|
2935
|
+
|
|
2936
|
+
opacity: 0;
|
|
2937
|
+
animation: fadeIn 0.3s ease-out forwards;
|
|
2938
|
+
|
|
2939
|
+
@keyframes fadeIn {
|
|
2940
|
+
from {
|
|
2941
|
+
opacity: 0;
|
|
2942
|
+
}
|
|
2943
|
+
to {
|
|
2944
|
+
opacity: 1;
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
`;
|
|
2948
|
+
const SecondaryButton = styled.button`
|
|
2949
|
+
color: ${colors.GREY_700};
|
|
2950
|
+
border: 1px solid ${colors.GREY_100};
|
|
2951
|
+
width: fit-content;
|
|
2952
|
+
border-radius: 4px;
|
|
2953
|
+
padding: 6px 12px;
|
|
2954
|
+
cursor: pointer;
|
|
2955
|
+
height: fit-content;
|
|
2956
|
+
font-size: 12px;
|
|
2957
|
+
|
|
2958
|
+
&:hover {
|
|
2959
|
+
opacity: 0.8;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
&:active {
|
|
2963
|
+
opacity: 0.6;
|
|
2964
|
+
}
|
|
2965
|
+
`;
|
|
2966
|
+
const ActionsContainer = styled.div`
|
|
2967
|
+
display: flex;
|
|
2968
|
+
gap: 12px;
|
|
2969
|
+
align-items: center;
|
|
2970
|
+
justify-content: center;
|
|
2971
|
+
`;
|
|
2972
|
+
|
|
2973
|
+
//#endregion
|
|
2974
|
+
//#region src/edit-mode/assets/ai-stars.svg
|
|
2975
|
+
var _path;
|
|
2976
|
+
function _extends() {
|
|
2977
|
+
return _extends = Object.assign ? Object.assign.bind() : function(n) {
|
|
2978
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
2979
|
+
var t = arguments[e];
|
|
2980
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2981
|
+
}
|
|
2982
|
+
return n;
|
|
2983
|
+
}, _extends.apply(null, arguments);
|
|
2984
|
+
}
|
|
2985
|
+
var SvgAiStars = function SvgAiStars$1(props) {
|
|
2986
|
+
return /* @__PURE__ */ React$1.createElement("svg", _extends({
|
|
2987
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2988
|
+
width: 13,
|
|
2989
|
+
height: 14,
|
|
2990
|
+
fill: "none"
|
|
2991
|
+
}, props), _path || (_path = /* @__PURE__ */ React$1.createElement("path", {
|
|
2992
|
+
fill: "currentColor",
|
|
2993
|
+
fillRule: "evenodd",
|
|
2994
|
+
d: "M10.5.9a.6.6 0 0 1 .586.472l.133.605a.4.4 0 0 0 .305.305l.605.132a.6.6 0 0 1 0 1.172l-.605.133a.4.4 0 0 0-.305.305l-.133.605a.6.6 0 0 1-1.172 0l-.132-.605a.4.4 0 0 0-.305-.305l-.605-.133a.6.6 0 0 1 0-1.172l.605-.132a.4.4 0 0 0 .305-.305l.132-.605A.6.6 0 0 1 10.5.9M5.077 3.833a.6.6 0 0 0-1.153 0l-.215.74A2.4 2.4 0 0 1 2.074 6.21l-.741.215a.6.6 0 0 0 0 1.153l.74.215A2.4 2.4 0 0 1 3.71 9.427l.215.74a.6.6 0 0 0 1.153 0l.215-.74a2.4 2.4 0 0 1 1.635-1.635l.74-.215a.6.6 0 0 0 0-1.153l-.74-.215a2.4 2.4 0 0 1-1.635-1.635zm6.01 5.539a.6.6 0 0 0-1.173 0l-.132.605a.4.4 0 0 1-.305.305l-.605.133a.6.6 0 0 0 0 1.172l.605.132a.4.4 0 0 1 .305.305l.132.605a.6.6 0 0 0 1.172 0l.133-.605a.4.4 0 0 1 .305-.305l.605-.132a.6.6 0 0 0 0-1.172l-.605-.133a.4.4 0 0 1-.305-.305z",
|
|
2995
|
+
clipRule: "evenodd"
|
|
2996
|
+
})));
|
|
2997
|
+
};
|
|
2998
|
+
var ai_stars_default = SvgAiStars;
|
|
2999
|
+
|
|
3000
|
+
//#endregion
|
|
3001
|
+
//#region src/lib/internal-details/internal-components/fix-with-clark-button.tsx
|
|
3002
|
+
const MAX_STACK_FRAMES = 10;
|
|
3003
|
+
const MAX_PROMPT_LENGTH = 8e3;
|
|
3004
|
+
function buildRuntimeErrorPrompt(error) {
|
|
3005
|
+
const defaultPrompt = "Fix this error: Unknown error";
|
|
3006
|
+
if (!error) return defaultPrompt;
|
|
3007
|
+
const [messageLine, ...rawFrames] = error.stack?.split("\n") ?? [];
|
|
3008
|
+
const message = (messageLine || error.message || error.toString()).trim();
|
|
3009
|
+
const filteredFrames = rawFrames.filter((line) => line && !line.includes("node_modules"));
|
|
3010
|
+
const selectedFrames = filteredFrames.slice(0, MAX_STACK_FRAMES);
|
|
3011
|
+
const omittedCount = filteredFrames.length - selectedFrames.length;
|
|
3012
|
+
const frameSection = [...selectedFrames, ...omittedCount > 0 ? [`... (${omittedCount} additional frame${omittedCount > 1 ? "s" : ""} omitted)`] : []].map((line) => line.trimEnd()).join("\n");
|
|
3013
|
+
const prompt = `Fix this error: ${frameSection ? `${message}\n${frameSection}` : message}`;
|
|
3014
|
+
if (prompt.length <= MAX_PROMPT_LENGTH) return prompt;
|
|
3015
|
+
const suffix = "... (truncated)";
|
|
3016
|
+
const availableChars = Math.max(MAX_PROMPT_LENGTH - 15, 0);
|
|
3017
|
+
return `${prompt.slice(0, availableChars)}${suffix}`;
|
|
3018
|
+
}
|
|
3019
|
+
const FixWithClarkButtonContainer = styled.button`
|
|
3020
|
+
padding: 6px 12px;
|
|
3021
|
+
background-color: ${colors.ACCENT_BLUE_500};
|
|
3022
|
+
border-radius: 4px;
|
|
3023
|
+
border: none;
|
|
3024
|
+
color: white;
|
|
3025
|
+
height: fit-content;
|
|
3026
|
+
display: flex;
|
|
3027
|
+
gap: 4px;
|
|
3028
|
+
cursor: pointer;
|
|
3029
|
+
transition: opacity 0.2s;
|
|
3030
|
+
font-size: 12px;
|
|
3031
|
+
align-items: center;
|
|
3032
|
+
|
|
3033
|
+
&:hover:not(:disabled) {
|
|
3034
|
+
opacity: 0.8;
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
&:disabled {
|
|
3038
|
+
opacity: 0.5;
|
|
3039
|
+
cursor: not-allowed;
|
|
3040
|
+
}
|
|
3041
|
+
`;
|
|
3042
|
+
function FixWithClarkButton({ identifier, error, onClick }) {
|
|
3043
|
+
const isAiEditing = root_store_default.editStore?.ai.getIsEditing() ?? false;
|
|
3044
|
+
const handleFixWithAi = () => {
|
|
3045
|
+
onClick?.();
|
|
3046
|
+
if (identifier) editorBridge.addComponentToAiContext(identifier.sourceId, identifier.selectorId);
|
|
3047
|
+
const prompt = buildRuntimeErrorPrompt(error);
|
|
3048
|
+
editorBridge.aiGenerate(prompt, true);
|
|
3049
|
+
};
|
|
3050
|
+
return /* @__PURE__ */ jsxs(FixWithClarkButtonContainer, {
|
|
3051
|
+
onClick: handleFixWithAi,
|
|
3052
|
+
disabled: isAiEditing,
|
|
3053
|
+
children: [/* @__PURE__ */ jsx(ai_stars_default, {}), " Fix with Clark"]
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
//#endregion
|
|
3058
|
+
//#region src/lib/utils/widget-wrapper-naming.ts
|
|
3059
|
+
const getWidgetAnchorName = (selectorId) => {
|
|
3060
|
+
return `--widget-${selectorId}`;
|
|
3061
|
+
};
|
|
3062
|
+
const getWidgetRectAnchorName = (selectorId) => {
|
|
3063
|
+
return `--widget-rect-${selectorId}`;
|
|
3064
|
+
};
|
|
3065
|
+
|
|
3066
|
+
//#endregion
|
|
3067
|
+
export { useSuperblocksUser as A, generateId as C, useSuperblocksContext as D, SuperblocksContextProvider as E, iframeMessageHandler as F, isEmbeddedBySuperblocksFirstParty as I, isEditMode as L, colors as M, editorBridge as N, useSuperblocksGroups as O, getEditStore as P, startEditorSync as S, resolveById as T, createManagedPropsList as _, ActionsContainer as a, Section as b, ErrorDetails as c, ErrorStack as d, ErrorSummary as f, root_store_default as g, StyledClarkIcon as h, ai_stars_default as i, sendNotification as j, useSuperblocksProfiles as k, ErrorIconContainer as l, SecondaryButton as m, getWidgetRectAnchorName as n, ErrorContainer as o, ErrorTitle as p, FixWithClarkButton as r, ErrorContent as s, getWidgetAnchorName as t, ErrorMessage as u, Prop as v, rejectById as w, createPropertiesPanelDefinition as x, PropsCategory as y };
|
|
3068
|
+
//# sourceMappingURL=widget-wrapper-naming-DxFT8zmk.js.map
|