@makeswift/runtime 0.28.4-canary.0 → 0.28.4-canary.2
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/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/builder/serialization.js +78 -0
- package/dist/cjs/builder/serialization.js.map +1 -0
- package/dist/cjs/client/index.js +3 -3
- package/dist/cjs/controls/serialization/base/index.js +76 -0
- package/dist/cjs/controls/serialization/base/index.js.map +1 -0
- package/dist/cjs/controls/{visitors/message-port-serializer/client-message-port-serialization-visitor.js → serialization/base/visitor.js} +9 -22
- package/dist/cjs/controls/serialization/base/visitor.js.map +1 -0
- package/dist/cjs/controls/serialization/index.js +55 -0
- package/dist/cjs/controls/serialization/index.js.map +1 -0
- package/dist/cjs/controls/serialization/message-port/function-serialization.js.map +1 -0
- package/dist/cjs/{builder/serialization → controls/serialization/message-port}/index.js +6 -6
- package/dist/cjs/controls/serialization/message-port/index.js.map +1 -0
- package/dist/cjs/controls/{visitors/message-port-serializer/index.js → serialization/message-port/visitor.js} +25 -13
- package/dist/cjs/controls/serialization/message-port/visitor.js.map +1 -0
- package/dist/cjs/{builder/serialization/control-serialization.js → prop-controllers/serialization.js} +41 -144
- package/dist/cjs/prop-controllers/serialization.js.map +1 -0
- package/dist/cjs/state/modules/element-trees.js +45 -19
- package/dist/cjs/state/modules/element-trees.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/builder/serialization.js +59 -0
- package/dist/esm/builder/serialization.js.map +1 -0
- package/dist/esm/client/index.js +3 -3
- package/dist/esm/controls/serialization/base/index.js +74 -0
- package/dist/esm/controls/serialization/base/index.js.map +1 -0
- package/dist/esm/controls/{visitors/message-port-serializer/client-message-port-serialization-visitor.js → serialization/base/visitor.js} +6 -20
- package/dist/esm/controls/serialization/base/visitor.js.map +1 -0
- package/dist/esm/controls/serialization/index.js +30 -0
- package/dist/esm/controls/serialization/index.js.map +1 -0
- package/dist/esm/controls/serialization/message-port/function-serialization.js.map +1 -0
- package/dist/esm/controls/serialization/message-port/index.js +3 -0
- package/dist/esm/controls/serialization/message-port/index.js.map +1 -0
- package/dist/esm/controls/serialization/message-port/visitor.js +24 -0
- package/dist/esm/controls/serialization/message-port/visitor.js.map +1 -0
- package/dist/esm/{builder/serialization/control-serialization.js → prop-controllers/serialization.js} +11 -136
- package/dist/esm/prop-controllers/serialization.js.map +1 -0
- package/dist/esm/state/modules/element-trees.js +46 -20
- package/dist/esm/state/modules/element-trees.js.map +1 -1
- package/dist/types/api-handler/handlers/webhook/types.d.ts +4 -4
- package/dist/types/builder/serialization.d.ts +23 -0
- package/dist/types/builder/serialization.d.ts.map +1 -0
- package/dist/types/builder/serialization.test.d.ts +2 -0
- package/dist/types/builder/serialization.test.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +4 -4
- package/dist/types/controls/serialization/base/index.d.ts +10 -0
- package/dist/types/controls/serialization/base/index.d.ts.map +1 -0
- package/dist/types/controls/serialization/base/visitor.d.ts +7 -0
- package/dist/types/controls/serialization/base/visitor.d.ts.map +1 -0
- package/dist/types/controls/serialization/index.d.ts +10 -0
- package/dist/types/controls/serialization/index.d.ts.map +1 -0
- package/dist/types/controls/{visitors/message-port-serializer → serialization/message-port}/function-serialization.d.ts +1 -1
- package/dist/types/controls/serialization/message-port/function-serialization.d.ts.map +1 -0
- package/dist/types/controls/serialization/message-port/function-serialization.test.d.ts.map +1 -0
- package/dist/types/controls/serialization/message-port/index.d.ts +3 -0
- package/dist/types/controls/serialization/message-port/index.d.ts.map +1 -0
- package/dist/types/controls/serialization/message-port/visitor.d.ts +7 -0
- package/dist/types/controls/serialization/message-port/visitor.d.ts.map +1 -0
- package/dist/types/{builder/serialization/control-serialization.d.ts → prop-controllers/serialization.d.ts} +11 -29
- package/dist/types/prop-controllers/serialization.d.ts.map +1 -0
- package/dist/types/slate/BlockPlugin/index.d.ts +3 -3
- package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts +4 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts.map +1 -1
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts +7 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/builder/serialization/control-serialization.js.map +0 -1
- package/dist/cjs/builder/serialization/controls/types.js +0 -17
- package/dist/cjs/builder/serialization/controls/types.js.map +0 -1
- package/dist/cjs/builder/serialization/function-serialization.js +0 -57
- package/dist/cjs/builder/serialization/function-serialization.js.map +0 -1
- package/dist/cjs/builder/serialization/index.js.map +0 -1
- package/dist/cjs/controls/visitors/message-port-serializer/client-message-port-serialization-visitor.js.map +0 -1
- package/dist/cjs/controls/visitors/message-port-serializer/function-serialization.js.map +0 -1
- package/dist/cjs/controls/visitors/message-port-serializer/index.js.map +0 -1
- package/dist/esm/builder/serialization/control-serialization.js.map +0 -1
- package/dist/esm/builder/serialization/controls/types.js +0 -1
- package/dist/esm/builder/serialization/controls/types.js.map +0 -1
- package/dist/esm/builder/serialization/function-serialization.js +0 -31
- package/dist/esm/builder/serialization/function-serialization.js.map +0 -1
- package/dist/esm/builder/serialization/index.js +0 -3
- package/dist/esm/builder/serialization/index.js.map +0 -1
- package/dist/esm/controls/visitors/message-port-serializer/client-message-port-serialization-visitor.js.map +0 -1
- package/dist/esm/controls/visitors/message-port-serializer/function-serialization.js.map +0 -1
- package/dist/esm/controls/visitors/message-port-serializer/index.js +0 -13
- package/dist/esm/controls/visitors/message-port-serializer/index.js.map +0 -1
- package/dist/types/builder/serialization/control-serialization.d.ts.map +0 -1
- package/dist/types/builder/serialization/control-serialization.test.d.ts +0 -2
- package/dist/types/builder/serialization/control-serialization.test.d.ts.map +0 -1
- package/dist/types/builder/serialization/controls/types.d.ts +0 -10
- package/dist/types/builder/serialization/controls/types.d.ts.map +0 -1
- package/dist/types/builder/serialization/function-serialization.d.ts +0 -12
- package/dist/types/builder/serialization/function-serialization.d.ts.map +0 -1
- package/dist/types/builder/serialization/function-serialization.test.d.ts.map +0 -1
- package/dist/types/builder/serialization/index.d.ts +0 -4
- package/dist/types/builder/serialization/index.d.ts.map +0 -1
- package/dist/types/controls/visitors/message-port-serializer/client-message-port-serialization-visitor.d.ts +0 -9
- package/dist/types/controls/visitors/message-port-serializer/client-message-port-serialization-visitor.d.ts.map +0 -1
- package/dist/types/controls/visitors/message-port-serializer/function-serialization.d.ts.map +0 -1
- package/dist/types/controls/visitors/message-port-serializer/function-serialization.test.d.ts +0 -2
- package/dist/types/controls/visitors/message-port-serializer/function-serialization.test.d.ts.map +0 -1
- package/dist/types/controls/visitors/message-port-serializer/index.d.ts +0 -3
- package/dist/types/controls/visitors/message-port-serializer/index.d.ts.map +0 -1
- /package/dist/cjs/controls/{visitors/message-port-serializer → serialization/message-port}/function-serialization.js +0 -0
- /package/dist/esm/controls/{visitors/message-port-serializer → serialization/message-port}/function-serialization.js +0 -0
- /package/dist/types/{builder/serialization → controls/serialization/message-port}/function-serialization.test.d.ts +0 -0
|
@@ -16,31 +16,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
deserializeControl: () => deserializeControl,
|
|
22
|
-
deserializeControls: () => deserializeControls,
|
|
19
|
+
var serialization_exports = {};
|
|
20
|
+
__export(serialization_exports, {
|
|
23
21
|
deserializeLegacyControl: () => deserializeLegacyControl,
|
|
24
|
-
|
|
25
|
-
isSerializedControl: () => isSerializedControl,
|
|
26
|
-
serializeControl: () => serializeControl,
|
|
27
|
-
serializeControls: () => serializeControls
|
|
22
|
+
serializeLegacyControl: () => serializeLegacyControl
|
|
28
23
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var import_deleted = require("
|
|
33
|
-
var import_function_serialization = require("./function-serialization");
|
|
34
|
-
var import_prop_controllers2 = require("@makeswift/prop-controllers");
|
|
35
|
-
var import_descriptors2 = require("../../prop-controllers/descriptors");
|
|
36
|
-
var import_controls3 = require("@makeswift/controls");
|
|
37
|
-
var import_message_port_serializer = require("../../controls/visitors/message-port-serializer");
|
|
24
|
+
module.exports = __toCommonJS(serialization_exports);
|
|
25
|
+
var import_prop_controllers = require("@makeswift/prop-controllers");
|
|
26
|
+
var import_function_serialization = require("../controls/serialization/message-port/function-serialization");
|
|
27
|
+
var import_deleted = require("./deleted");
|
|
38
28
|
function serializeShapeControl(control) {
|
|
39
29
|
const { type } = control.options;
|
|
40
30
|
const transferables = [];
|
|
41
31
|
const serializedType = {};
|
|
42
32
|
Object.entries(type).forEach(([key, control2]) => {
|
|
43
|
-
const [serializedControl, serializedControlTransferables] =
|
|
33
|
+
const [serializedControl, serializedControlTransferables] = serializeLegacyControl(control2);
|
|
44
34
|
serializedType[key] = serializedControl;
|
|
45
35
|
transferables.push(...serializedControlTransferables);
|
|
46
36
|
});
|
|
@@ -50,7 +40,7 @@ function deserializeShapeControl(control) {
|
|
|
50
40
|
const { type } = control.options;
|
|
51
41
|
const deserializedType = {};
|
|
52
42
|
Object.entries(type).forEach(([key, control2]) => {
|
|
53
|
-
deserializedType[key] =
|
|
43
|
+
deserializedType[key] = deserializeLegacyControl(
|
|
54
44
|
control2
|
|
55
45
|
);
|
|
56
46
|
});
|
|
@@ -59,7 +49,7 @@ function deserializeShapeControl(control) {
|
|
|
59
49
|
function serializeListControl(control) {
|
|
60
50
|
const { type, getItemLabel } = control.options;
|
|
61
51
|
const transferables = [];
|
|
62
|
-
const [serializedType, serializedTypeTransferables] =
|
|
52
|
+
const [serializedType, serializedTypeTransferables] = serializeLegacyControl(type);
|
|
63
53
|
const serializedGetItemLabel = getItemLabel && (0, import_function_serialization.serializeFunction)(getItemLabel);
|
|
64
54
|
transferables.push(...serializedTypeTransferables);
|
|
65
55
|
if (serializedGetItemLabel != null)
|
|
@@ -78,7 +68,7 @@ function serializeListControl(control) {
|
|
|
78
68
|
}
|
|
79
69
|
function deserializeListControl(serializedControl) {
|
|
80
70
|
const { type, getItemLabel } = serializedControl.options;
|
|
81
|
-
const deserializedType =
|
|
71
|
+
const deserializedType = deserializeLegacyControl(type);
|
|
82
72
|
const deserializedGetItemLabel = (0, import_function_serialization.isSerializedFunction)(getItemLabel) ? (0, import_function_serialization.deserializeFunction)(getItemLabel) : getItemLabel;
|
|
83
73
|
return {
|
|
84
74
|
...serializedControl,
|
|
@@ -273,20 +263,9 @@ function deserializeRichTextControl(serializedControl) {
|
|
|
273
263
|
const deserializedOptions = (0, import_function_serialization.deserializeFunction)(options);
|
|
274
264
|
return { ...serializedControl, options: deserializedOptions };
|
|
275
265
|
}
|
|
276
|
-
function serializeControl(control) {
|
|
277
|
-
if ((0, import_descriptors2.isLegacyDescriptor)(control)) {
|
|
278
|
-
return serializeLegacyControl(control);
|
|
279
|
-
}
|
|
280
|
-
const messagePortVisitor = new import_message_port_serializer.ClientMessagePortSerializationVisitor();
|
|
281
|
-
const serializedControl = control.accept(messagePortVisitor);
|
|
282
|
-
return [serializedControl, messagePortVisitor.getTransferables()];
|
|
283
|
-
}
|
|
284
|
-
function isSerializedControl(control) {
|
|
285
|
-
return control != null && typeof control === "object" && "type" in control && typeof control.type === "string";
|
|
286
|
-
}
|
|
287
266
|
function serializeLegacyControl(control) {
|
|
288
267
|
switch (control.type) {
|
|
289
|
-
case
|
|
268
|
+
case import_prop_controllers.Types.Checkbox:
|
|
290
269
|
return serializeCheckboxControl(control);
|
|
291
270
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.List:
|
|
292
271
|
return serializeListControl(control);
|
|
@@ -294,31 +273,31 @@ function serializeLegacyControl(control) {
|
|
|
294
273
|
return serializeShapeControl(control);
|
|
295
274
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.Typeahead:
|
|
296
275
|
return serializeTypeaheadControl(control);
|
|
297
|
-
case
|
|
276
|
+
case import_prop_controllers.Types.GapX:
|
|
298
277
|
return serializeControlDef(control);
|
|
299
|
-
case
|
|
278
|
+
case import_prop_controllers.Types.GapY:
|
|
300
279
|
return serializeGapYControl(control);
|
|
301
|
-
case
|
|
280
|
+
case import_prop_controllers.Types.ResponsiveColor:
|
|
302
281
|
return serializeResponsiveColorControl(control);
|
|
303
|
-
case
|
|
282
|
+
case import_prop_controllers.Types.ResponsiveNumber:
|
|
304
283
|
return serializeControlDef(control);
|
|
305
|
-
case
|
|
284
|
+
case import_prop_controllers.Types.Number:
|
|
306
285
|
return serializeNumberControl(control);
|
|
307
|
-
case
|
|
286
|
+
case import_prop_controllers.Types.ResponsiveIconRadioGroup:
|
|
308
287
|
return serializeControlDef(control);
|
|
309
|
-
case
|
|
288
|
+
case import_prop_controllers.Types.ResponsiveSelect:
|
|
310
289
|
return serializeControlDef(control);
|
|
311
|
-
case
|
|
290
|
+
case import_prop_controllers.Types.ResponsiveLength:
|
|
312
291
|
return serializeResponsiveLengthControl(control);
|
|
313
|
-
case
|
|
292
|
+
case import_prop_controllers.Types.Date:
|
|
314
293
|
return serializeDateControl(control);
|
|
315
|
-
case
|
|
294
|
+
case import_prop_controllers.Types.Link:
|
|
316
295
|
return serializeLinkControl(control);
|
|
317
|
-
case
|
|
296
|
+
case import_prop_controllers.Types.TextInput:
|
|
318
297
|
return serializeTextInputControl(control);
|
|
319
|
-
case
|
|
298
|
+
case import_prop_controllers.Types.TextStyle:
|
|
320
299
|
return serializeTextStyleControl(control);
|
|
321
|
-
case
|
|
300
|
+
case import_prop_controllers.Types.Image:
|
|
322
301
|
return serializeImageControl(control);
|
|
323
302
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.RichText:
|
|
324
303
|
return serializeRichTextControl(control);
|
|
@@ -326,12 +305,9 @@ function serializeLegacyControl(control) {
|
|
|
326
305
|
return [control, []];
|
|
327
306
|
}
|
|
328
307
|
}
|
|
329
|
-
function isSerializedLegacyControl(control) {
|
|
330
|
-
return "options" in control;
|
|
331
|
-
}
|
|
332
308
|
function deserializeLegacyControl(serializedControl) {
|
|
333
309
|
switch (serializedControl.type) {
|
|
334
|
-
case
|
|
310
|
+
case import_prop_controllers.Types.Checkbox:
|
|
335
311
|
return deserializeCheckboxControl(serializedControl);
|
|
336
312
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.List:
|
|
337
313
|
return deserializeListControl(serializedControl);
|
|
@@ -339,31 +315,31 @@ function deserializeLegacyControl(serializedControl) {
|
|
|
339
315
|
return deserializeShapeControl(serializedControl);
|
|
340
316
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.Typeahead:
|
|
341
317
|
return deserializeTypeaheadControl(serializedControl);
|
|
342
|
-
case
|
|
318
|
+
case import_prop_controllers.Types.GapX:
|
|
343
319
|
return deserializeControlDef(serializedControl);
|
|
344
|
-
case
|
|
320
|
+
case import_prop_controllers.Types.GapY:
|
|
345
321
|
return deserializeGapYControl(serializedControl);
|
|
346
|
-
case
|
|
322
|
+
case import_prop_controllers.Types.ResponsiveColor:
|
|
347
323
|
return deserializeResponsiveColorControl(serializedControl);
|
|
348
|
-
case
|
|
324
|
+
case import_prop_controllers.Types.ResponsiveNumber:
|
|
349
325
|
return deserializeControlDef(serializedControl);
|
|
350
|
-
case
|
|
326
|
+
case import_prop_controllers.Types.Number:
|
|
351
327
|
return deserializeNumberControl(serializedControl);
|
|
352
|
-
case
|
|
328
|
+
case import_prop_controllers.Types.ResponsiveIconRadioGroup:
|
|
353
329
|
return deserializeControlDef(serializedControl);
|
|
354
|
-
case
|
|
330
|
+
case import_prop_controllers.Types.ResponsiveSelect:
|
|
355
331
|
return deserializeControlDef(serializedControl);
|
|
356
|
-
case
|
|
332
|
+
case import_prop_controllers.Types.ResponsiveLength:
|
|
357
333
|
return deserializeResponsiveLengthControl(serializedControl);
|
|
358
|
-
case
|
|
334
|
+
case import_prop_controllers.Types.Date:
|
|
359
335
|
return deserializeDateControl(serializedControl);
|
|
360
|
-
case
|
|
336
|
+
case import_prop_controllers.Types.Link:
|
|
361
337
|
return deserializeLinkControl(serializedControl);
|
|
362
|
-
case
|
|
338
|
+
case import_prop_controllers.Types.TextInput:
|
|
363
339
|
return deserializeTextInputControl(serializedControl);
|
|
364
|
-
case
|
|
340
|
+
case import_prop_controllers.Types.TextStyle:
|
|
365
341
|
return deserializeTextStyleControl(serializedControl);
|
|
366
|
-
case
|
|
342
|
+
case import_prop_controllers.Types.Image:
|
|
367
343
|
return deserializeImageControl(serializedControl);
|
|
368
344
|
case import_deleted.DELETED_PROP_CONTROLLER_TYPES.RichText:
|
|
369
345
|
return deserializeRichTextControl(serializedControl);
|
|
@@ -371,88 +347,9 @@ function deserializeLegacyControl(serializedControl) {
|
|
|
371
347
|
return serializedControl;
|
|
372
348
|
}
|
|
373
349
|
}
|
|
374
|
-
function deserializeControl(serializedControl, options) {
|
|
375
|
-
if (isSerializedLegacyControl(serializedControl)) {
|
|
376
|
-
const record = options?.plugins ? (0, import_controls.deserializeObject)(serializedControl, options?.plugins) : serializedControl;
|
|
377
|
-
return deserializeLegacyControl(record);
|
|
378
|
-
}
|
|
379
|
-
const plugins = [import_message_port_serializer.functionDeserializationPlugin, ...options?.plugins ?? []];
|
|
380
|
-
return deserializeUnifiedControlDef(
|
|
381
|
-
(0, import_controls3.deserializeRecord)(serializedControl, plugins)
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
function deserializeUnifiedControlDef(record) {
|
|
385
|
-
const deserializeMethod = {
|
|
386
|
-
[import_controls2.CheckboxDefinition.type]: import_controls2.CheckboxDefinition.deserialize,
|
|
387
|
-
[import_controls2.ColorDefinition.type]: import_controls2.ColorDefinition.deserialize,
|
|
388
|
-
[import_controls2.ComboboxDefinition.type]: import_controls2.ComboboxDefinition.deserialize,
|
|
389
|
-
[import_controls2.FontDefinition.type]: import_controls2.FontDefinition.deserialize,
|
|
390
|
-
[import_controls2.GroupDefinition.type]: (record2) => import_controls2.GroupDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
391
|
-
[import_controls2.IconRadioGroupDefinition.type]: import_controls2.IconRadioGroupDefinition.deserialize,
|
|
392
|
-
[import_controls2.ImageDefinition.type]: import_controls2.ImageDefinition.deserialize,
|
|
393
|
-
[import_controls2.LinkDefinition.type]: import_controls2.LinkDefinition.deserialize,
|
|
394
|
-
[import_controls2.ListDefinition.type]: (record2) => import_controls2.ListDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
395
|
-
[import_controls2.NumberDefinition.type]: import_controls2.NumberDefinition.deserialize,
|
|
396
|
-
[import_controls2.RichTextV1Definition.type]: import_controls2.RichTextV1Definition.deserialize,
|
|
397
|
-
[import_controls2.RichTextV2Definition.type]: (record2) => import_controls2.RichTextV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
398
|
-
[import_controls2.SelectDefinition.type]: import_controls2.SelectDefinition.deserialize,
|
|
399
|
-
[import_controls2.ShapeDefinition.type]: (record2) => import_controls2.ShapeDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
400
|
-
[import_controls.ShapeV2Definition.type]: (record2) => import_controls.ShapeV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
401
|
-
[import_controls2.SlotDefinition.type]: import_controls2.SlotDefinition.deserialize,
|
|
402
|
-
[import_controls2.StyleDefinition.type]: import_controls2.StyleDefinition.deserialize,
|
|
403
|
-
[import_controls2.StyleV2Definition.type]: (record2) => import_controls2.StyleV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
404
|
-
[import_controls2.TextAreaDefinition.type]: import_controls2.TextAreaDefinition.deserialize,
|
|
405
|
-
[import_controls2.TextInputDefinition.type]: import_controls2.TextInputDefinition.deserialize,
|
|
406
|
-
[import_controls2.unstable_TypographyDefinition.type]: import_controls2.unstable_TypographyDefinition.deserialize
|
|
407
|
-
};
|
|
408
|
-
const deserialize = deserializeMethod[record.type] ?? null;
|
|
409
|
-
if (deserialize == null) {
|
|
410
|
-
throw new Error(`Unknown control type: ${record.type}`);
|
|
411
|
-
}
|
|
412
|
-
return deserialize(record);
|
|
413
|
-
}
|
|
414
|
-
function serializeControls(controls) {
|
|
415
|
-
return Object.entries(controls).reduce(
|
|
416
|
-
([accControls, accTransferables], [key, control]) => {
|
|
417
|
-
const [serializedControl, transferables] = serializeControl(control);
|
|
418
|
-
return [{ ...accControls, [key]: serializedControl }, [...accTransferables, ...transferables]];
|
|
419
|
-
},
|
|
420
|
-
[{}, []]
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
function deserializeControls(serializedControls, {
|
|
424
|
-
onError,
|
|
425
|
-
plugins
|
|
426
|
-
} = {}) {
|
|
427
|
-
return Object.entries(serializedControls).reduce(
|
|
428
|
-
(deserializedControls, [key, serializedControl]) => {
|
|
429
|
-
try {
|
|
430
|
-
if (!isSerializedControl(serializedControl)) {
|
|
431
|
-
throw new Error(
|
|
432
|
-
`Expected serialized control data, got ${JSON.stringify(serializedControl)}`
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
const deserializedControl = deserializeControl(serializedControl, { plugins });
|
|
436
|
-
return { ...deserializedControls, [key]: deserializedControl };
|
|
437
|
-
} catch (err) {
|
|
438
|
-
const error = err instanceof Error ? new Error(`Could not deserialize control for "${key}": ${err.message}`, {
|
|
439
|
-
cause: err
|
|
440
|
-
}) : new Error(`Could not deserialize control for "${key}", unknown error: ${err}`);
|
|
441
|
-
onError?.(error, { key, serializedControl });
|
|
442
|
-
return deserializedControls;
|
|
443
|
-
}
|
|
444
|
-
},
|
|
445
|
-
{}
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
350
|
// Annotate the CommonJS export names for ESM import in node:
|
|
449
351
|
0 && (module.exports = {
|
|
450
|
-
deserializeControl,
|
|
451
|
-
deserializeControls,
|
|
452
352
|
deserializeLegacyControl,
|
|
453
|
-
|
|
454
|
-
isSerializedControl,
|
|
455
|
-
serializeControl,
|
|
456
|
-
serializeControls
|
|
353
|
+
serializeLegacyControl
|
|
457
354
|
});
|
|
458
|
-
//# sourceMappingURL=
|
|
355
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prop-controllers/serialization.ts"],"sourcesContent":["import {\n type Data,\n type Device,\n type RichTextValue as RichTextControlValue,\n} from '@makeswift/controls'\n\nimport {\n type Descriptor,\n type PropDef,\n type OptionsType,\n CheckboxDescriptor as CheckboxControl,\n CheckboxPropControllerData,\n DateDescriptor as DateControl,\n DatePropControllerData,\n ImageDescriptor as ImageControl,\n ImageData as ImageControlValue,\n GapData,\n GapX,\n GapYDescriptor,\n GapYPropControllerData,\n LinkData,\n LinkDescriptor as LinkControl,\n LinkPropControllerData,\n NumberDescriptor,\n NumberOptions,\n NumberPropControllerData,\n ResponsiveColorDescriptor,\n ResponsiveColorPropControllerData,\n ResponsiveIconRadioGroup,\n ResponsiveLengthDescriptor,\n ResponsiveLengthOptions,\n ResponsiveLengthPropControllerData,\n ResponsiveNumber,\n ResponsiveSelect,\n Types as PropControllerTypes,\n TextStyleDescriptor as TextStyleControl,\n TextStylePropControllerData,\n TextInputDescriptor as TextInputControl,\n} from '@makeswift/prop-controllers'\n\nimport {\n type DeserializedFunction,\n type SerializedFunction,\n deserializeFunction,\n isSerializedFunction,\n serializeFunction,\n} from '../controls/serialization/message-port/function-serialization'\n\nimport {\n PanelDescriptor as PanelControl,\n PanelDescriptorType as PanelControlType,\n PanelDescriptorValueType as PanelControlValueType,\n} from './descriptors'\n\nimport {\n DELETED_PROP_CONTROLLER_TYPES,\n ListDescriptor as ListControl,\n ListOptions as ListControlConfig,\n ListValue as ListControlValue,\n ShapeDescriptor as ShapeControl,\n ShapeValue as ShapeControlValue,\n TypeaheadDescriptor as TypeaheadControl,\n TypeaheadOptions as TypeaheadControlConfig,\n TypeaheadValue as TypeaheadControlValue,\n RichTextDescriptor as RichTextControl,\n} from './deleted'\n\nimport { type LegacyDescriptor } from './descriptors'\n\ntype SerializedShapeControlConfig<T extends Record<string, SerializedPanelControl>> = {\n type: T\n preset?: { [K in keyof T]?: SerializedPanelControlValueType<T[K]> }\n}\n\ntype SerializedShapeControl<\n _T extends Record<string, Data>,\n U extends Record<string, SerializedPanelControl>,\n> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.Shape\n options: SerializedShapeControlConfig<U>\n}\n\nfunction serializeShapeControl<\n T extends Record<string, Data>,\n U extends Record<string, PanelControl>,\n>(\n control: ShapeControl<T, U>,\n): [\n SerializedShapeControl<\n T,\n { [K in keyof U]: SerializedPanelControl<PanelControlValueType<U[K]>> }\n >,\n Transferable[],\n] {\n const { type } = control.options\n const transferables: Transferable[] = []\n const serializedType = {} as {\n [K in keyof U]: SerializedPanelControl<PanelControlValueType<U[K]>>\n }\n\n Object.entries(type).forEach(([key, control]) => {\n const [serializedControl, serializedControlTransferables] = serializeLegacyControl(control)\n\n serializedType[key as keyof typeof type] = serializedControl as SerializedPanelControl\n transferables.push(...serializedControlTransferables)\n })\n\n // @ts-expect-error: preset types are incompatible\n return [{ ...control, options: { ...control.options, type: serializedType } }, transferables]\n}\n\ntype DeserializedShapeControlConfig<T extends Record<string, DeserializedPanelControl>> = {\n type: T\n preset?: { [K in keyof T]?: DeserializedPanelControlValueType<T[K]> }\n}\n\ntype DeserializedShapeControl<\n _T extends Record<string, Data>,\n U extends Record<string, DeserializedPanelControl>,\n> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.Shape\n options: DeserializedShapeControlConfig<U>\n}\n\nfunction deserializeShapeControl<\n T extends Record<string, Data>,\n U extends Record<string, SerializedPanelControl>,\n>(\n control: SerializedShapeControl<T, U>,\n): DeserializedShapeControl<\n T,\n { [K in keyof U]: DeserializedPanelControl<SerializedPanelControlValueType<U[K]>> }\n> {\n const { type } = control.options\n const deserializedType = {} as {\n [K in keyof U]: DeserializedPanelControl<SerializedPanelControlValueType<U[K]>>\n }\n\n Object.entries(type).forEach(([key, control]) => {\n deserializedType[key as keyof typeof type] = deserializeLegacyControl(\n control,\n ) as DeserializedPanelControl\n })\n\n // @ts-expect-error: preset types are incompatible\n return { ...control, options: { ...control.options, type: deserializedType } }\n}\n\ntype SerializedListControlConfig<T extends Data> = {\n type: SerializedPanelControl<T>\n label?: string\n getItemLabel?: SerializedFunction<Exclude<ListControlConfig<T>['getItemLabel'], undefined>>\n preset?: ListControlValue<T>\n defaultValue?: ListControlValue<T>\n}\n\nexport type SerializedListControl<T extends ListControlValue = ListControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.List\n options: SerializedListControlConfig<T extends ListControlValue<infer U> ? U : never>\n}\n\nfunction serializeListControl<T extends Data>(\n control: ListControl<ListControlValue<T>>,\n): [SerializedListControl<ListControlValue<T>>, Transferable[]] {\n const { type, getItemLabel } = control.options\n const transferables: Transferable[] = []\n\n const [serializedType, serializedTypeTransferables] = serializeLegacyControl(type)\n const serializedGetItemLabel = getItemLabel && serializeFunction(getItemLabel)\n\n transferables.push(...serializedTypeTransferables)\n if (serializedGetItemLabel != null) transferables.push(serializedGetItemLabel)\n\n return [\n {\n ...control,\n options: {\n ...control.options,\n type: serializedType as SerializedPanelControl,\n getItemLabel: serializedGetItemLabel,\n },\n },\n transferables,\n ]\n}\n\ntype DeserializedListControlConfig<T extends Data> = {\n type: DeserializedPanelControl<T>\n label?: string\n getItemLabel?: DeserializedFunction<Exclude<ListControlConfig<T>['getItemLabel'], undefined>>\n preset?: ListControlValue<T>\n defaultValue?: ListControlValue<T>\n}\n\ntype DeserializedListControl<T extends ListControlValue = ListControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.List\n options: DeserializedListControlConfig<T extends ListControlValue<infer U> ? U : never>\n}\n\nfunction deserializeListControl<T extends Data>(\n serializedControl: SerializedListControl<ListControlValue<T>>,\n): DeserializedListControl<ListControlValue<T>> {\n const { type, getItemLabel } = serializedControl.options\n\n const deserializedType = deserializeLegacyControl(type) as DeserializedPanelControl\n const deserializedGetItemLabel = isSerializedFunction(getItemLabel)\n ? deserializeFunction(getItemLabel)\n : getItemLabel\n\n return {\n ...serializedControl,\n options: {\n ...serializedControl.options,\n type: deserializedType,\n getItemLabel: deserializedGetItemLabel,\n },\n }\n}\n\ntype SerializedTypeaheadControlConfig<T extends Data> = {\n getItems: SerializedFunction<TypeaheadControlConfig<T>['getItems']>\n label?: string\n preset?: TypeaheadControlValue<T>\n defaultValue?: TypeaheadControlValue<T>\n}\n\nexport type SerializedTypeaheadControl<T extends TypeaheadControlValue = TypeaheadControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.Typeahead\n options: SerializedTypeaheadControlConfig<T['value']>\n}\n\nfunction serializeTypeaheadControl<T extends Data>(\n control: TypeaheadControl<TypeaheadControlValue<T>>,\n): [SerializedTypeaheadControl<TypeaheadControlValue<T>>, Transferable[]] {\n const { getItems } = control.options\n\n const serializedGetItems = getItems && serializeFunction(getItems)\n\n return [\n { ...control, options: { ...control.options, getItems: serializedGetItems } },\n serializedGetItems == null ? [] : [serializedGetItems],\n ]\n}\n\ntype DeserializedTypeaheadControlConfig<T extends Data> = {\n getItems: DeserializedFunction<TypeaheadControlConfig<T>['getItems']>\n label?: string\n preset?: TypeaheadControlValue<T>\n defaultValue?: TypeaheadControlValue<T>\n}\n\ntype DeserializedTypeaheadControl<T extends TypeaheadControlValue = TypeaheadControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.Typeahead\n options: DeserializedTypeaheadControlConfig<T['value']>\n}\n\nfunction deserializeTypeaheadControl<T extends Data>(\n serializedControl: SerializedTypeaheadControl<TypeaheadControlValue<T>>,\n): DeserializedTypeaheadControl<TypeaheadControlValue<T>> {\n const { getItems } = serializedControl.options\n\n const deserializedGetItems = isSerializedFunction(getItems)\n ? deserializeFunction(getItems)\n : getItems\n\n return {\n ...serializedControl,\n options: { ...serializedControl.options, getItems: deserializedGetItems },\n }\n}\n\ntype SerializedConfig<T> =\n | T\n | SerializedFunction<(props: Record<string, unknown>, deviceMode: Device) => T>\n\nexport type DeserializedConfig<T> =\n | T\n | DeserializedFunction<(props: Record<string, unknown>, deviceMode: Device) => T>\n\ntype SerializedControlDef<P extends PropDef> = Descriptor<P> & {\n options: SerializedConfig<OptionsType<P>>\n}\n\nfunction serializeControlDef<P extends PropDef>(\n control: Descriptor<P>,\n): [SerializedControlDef<P>, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\nexport type DeserializedControlDef<P extends PropDef> = Descriptor<P> & {\n options: DeserializedConfig<OptionsType<P>>\n}\n\nfunction deserializeControlDef<P extends PropDef>(\n serializedControl: SerializedControlDef<P>,\n): DeserializedControlDef<P> {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype GapYControlConfig = {\n preset?: GapYPropControllerData\n label?: string\n defaultValue?: GapData\n min?: number\n max?: number\n step?: number\n hidden?: boolean\n}\n\ntype SerializedGapYControl<_T = GapYPropControllerData> = {\n type: typeof PropControllerTypes.GapY\n options: SerializedConfig<GapYControlConfig>\n}\n\nfunction serializeGapYControl(control: GapYDescriptor): [SerializedGapYControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedGapYControl<_T = GapYPropControllerData> = {\n type: typeof PropControllerTypes.GapY\n options: DeserializedConfig<GapYControlConfig>\n}\n\nfunction deserializeGapYControl(serializedControl: SerializedGapYControl): DeserializedGapYControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype CheckboxControlConfig = {\n preset?: CheckboxPropControllerData\n label: string\n hidden?: boolean\n}\n\ntype SerializedCheckboxControl<_T = CheckboxPropControllerData> = {\n type: typeof PropControllerTypes.Checkbox\n options: SerializedConfig<CheckboxControlConfig>\n}\n\nfunction serializeCheckboxControl(\n control: CheckboxControl,\n): [SerializedCheckboxControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedCheckboxControl<_T = CheckboxPropControllerData> = {\n type: typeof PropControllerTypes.Checkbox\n options: DeserializedConfig<CheckboxControlConfig>\n}\n\nfunction deserializeCheckboxControl(\n serializedControl: SerializedCheckboxControl,\n): DeserializedCheckboxControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype ResponsiveColorControlConfig = { label?: string; placeholder?: string; hidden?: boolean }\n\ntype SerializedResponsiveColorControl<_T = ResponsiveColorPropControllerData> = {\n type: typeof PropControllerTypes.ResponsiveColor\n options: SerializedConfig<ResponsiveColorControlConfig>\n}\n\nfunction serializeResponsiveColorControl(\n control: ResponsiveColorDescriptor,\n): [SerializedResponsiveColorControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedResponsiveColorControl<_T = ResponsiveColorPropControllerData> = {\n type: typeof PropControllerTypes.ResponsiveColor\n options: DeserializedConfig<ResponsiveColorControlConfig>\n}\n\nfunction deserializeResponsiveColorControl(\n serializedControl: SerializedResponsiveColorControl,\n): DeserializedResponsiveColorControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\ntype SerializedNumberControl<_T = NumberPropControllerData> = {\n type: typeof PropControllerTypes.Number\n options: SerializedConfig<NumberOptions>\n}\n\nfunction serializeNumberControl(\n control: NumberDescriptor,\n): [SerializedNumberControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedNumberControl<_T = NumberPropControllerData> = {\n type: typeof PropControllerTypes.Number\n options: DeserializedConfig<NumberOptions>\n}\n\nfunction deserializeNumberControl(\n serializedControl: SerializedNumberControl,\n): DeserializedNumberControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype DateControlConfig = { preset?: DatePropControllerData }\n\ntype SerializedDateControl<_T = DatePropControllerData> = {\n type: typeof PropControllerTypes.Date\n options: SerializedConfig<DateControlConfig>\n}\n\nfunction serializeDateControl(control: DateControl): [SerializedDateControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedDateControl<_T = DatePropControllerData> = {\n type: typeof PropControllerTypes.Date\n options: DeserializedConfig<DateControlConfig>\n}\n\nfunction deserializeDateControl(serializedControl: SerializedDateControl): DeserializedDateControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype LinkControlConfig = {\n preset?: LinkPropControllerData\n label?: string\n defaultValue?: LinkPropControllerData\n options?: { value: LinkData['type']; label: string }[]\n hidden?: boolean\n}\n\ntype SerializedLinkControl<_T = LinkPropControllerData> = {\n type: typeof PropControllerTypes.Link\n options: SerializedConfig<LinkControlConfig>\n}\n\nfunction serializeLinkControl(control: LinkControl): [SerializedLinkControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedLinkControl<_T = LinkPropControllerData> = {\n type: typeof PropControllerTypes.Link\n options: DeserializedConfig<LinkControlConfig>\n}\n\nfunction deserializeLinkControl(serializedControl: SerializedLinkControl): DeserializedLinkControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype TextInputControlConfig = { label?: string; placeholder?: string; hidden?: boolean }\n\ntype TextInputControlValue = string\n\ntype SerializedTextInputControl<_T = TextInputControlValue> = {\n type: typeof PropControllerTypes.TextInput\n options: SerializedConfig<TextInputControlConfig>\n}\n\nfunction serializeTextInputControl(\n control: TextInputControl,\n): [SerializedTextInputControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedTextInputControl<_T = TextInputControlValue> = {\n type: typeof PropControllerTypes.TextInput\n options: DeserializedConfig<TextInputControlConfig>\n}\n\nfunction deserializeTextInputControl(\n serializedControl: SerializedTextInputControl,\n): DeserializedTextInputControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype SerializedResponsiveLengthControl<_T = ResponsiveLengthPropControllerData> = {\n type: typeof PropControllerTypes.ResponsiveLength\n options: SerializedConfig<ResponsiveLengthOptions>\n}\n\nfunction serializeResponsiveLengthControl(\n control: ResponsiveLengthDescriptor,\n): [SerializedResponsiveLengthControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedResponsiveLengthControl<_T = ResponsiveLengthPropControllerData> = {\n type: typeof PropControllerTypes.ResponsiveLength\n options: DeserializedConfig<ResponsiveLengthOptions>\n}\n\nfunction deserializeResponsiveLengthControl(\n serializedControl: SerializedResponsiveLengthControl,\n): DeserializedResponsiveLengthControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype SerializedTextStyleControl<_T = TextStylePropControllerData> = {\n type: typeof PropControllerTypes.TextStyle\n options: SerializedConfig<TextStyleControlConfig>\n}\n\nfunction serializeTextStyleControl(\n control: TextStyleControl,\n): [SerializedTextStyleControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype TextStyleControlConfig = {\n preset?: TextStylePropControllerData\n label?: string\n hidden?: boolean\n}\n\ntype DeserializedTextStyleControl<_T = TextStylePropControllerData> = {\n type: typeof PropControllerTypes.TextStyle\n options: DeserializedConfig<TextStyleControlConfig>\n}\n\nfunction deserializeTextStyleControl(\n serializedControl: SerializedTextStyleControl,\n): DeserializedTextStyleControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype ImageControlConfig = { label?: string; hidden?: boolean }\n\ntype SerializedImageControl<_T = ImageControlValue> = {\n type: typeof PropControllerTypes.Image\n options: SerializedConfig<ImageControlConfig>\n}\n\nfunction serializeImageControl(control: ImageControl): [SerializedImageControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedImageControl<_T = ImageControlValue> = {\n type: typeof PropControllerTypes.Image\n options: DeserializedConfig<ImageControlConfig>\n}\n\nfunction deserializeImageControl(\n serializedControl: SerializedImageControl,\n): DeserializedImageControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\ntype RichTextControlConfig = { preset?: RichTextControlValue }\n\ntype SerializedRichTextControl<_T = RichTextControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.RichText\n options: SerializedConfig<RichTextControlConfig>\n}\n\nfunction serializeRichTextControl(\n control: RichTextControl,\n): [SerializedRichTextControl, Transferable[]] {\n const { options } = control\n\n if (typeof options !== 'function') return [{ ...control, options }, []]\n\n const serializedOptions = serializeFunction(options)\n\n return [{ ...control, options: serializedOptions }, [serializedOptions]]\n}\n\ntype DeserializedRichTextControl<_T = RichTextControlValue> = {\n type: typeof DELETED_PROP_CONTROLLER_TYPES.RichText\n options: DeserializedConfig<RichTextControlConfig>\n}\n\nfunction deserializeRichTextControl(\n serializedControl: SerializedRichTextControl,\n): DeserializedRichTextControl {\n const { options } = serializedControl\n\n if (!isSerializedFunction(options)) return { ...serializedControl, options }\n\n const deserializedOptions = deserializeFunction(options)\n\n return { ...serializedControl, options: deserializedOptions }\n}\n\nexport type SerializedLegacyControl<T extends Data = Data> =\n | Exclude<\n LegacyDescriptor<T>,\n | ListControl<T extends ListControlValue ? T : ListControlValue>\n | ShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any>\n | TypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue>\n | Descriptor<typeof GapX>\n | GapYDescriptor<T>\n | Descriptor<typeof ResponsiveNumber>\n | CheckboxControl<T>\n | ResponsiveColorDescriptor<T>\n | NumberDescriptor<T>\n | Descriptor<typeof ResponsiveIconRadioGroup>\n | Descriptor<typeof ResponsiveSelect>\n | ResponsiveLengthDescriptor<T>\n | DateControl<T>\n | LinkControl<T>\n | TextInputControl<T>\n | TextStyleControl<T>\n | ImageControl<T>\n | RichTextControl<T>\n >\n | SerializedListControl<T extends ListControlValue ? T : ListControlValue>\n | SerializedShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any>\n | SerializedTypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue>\n | SerializedControlDef<typeof GapX>\n | SerializedGapYControl<T>\n | SerializedControlDef<typeof ResponsiveNumber>\n | SerializedCheckboxControl<T>\n | SerializedResponsiveColorControl<T>\n | SerializedNumberControl<T>\n | SerializedControlDef<typeof ResponsiveIconRadioGroup>\n | SerializedControlDef<typeof ResponsiveSelect>\n | SerializedResponsiveLengthControl<T>\n | SerializedDateControl<T>\n | SerializedLinkControl<T>\n | SerializedTextInputControl<T>\n | SerializedTextStyleControl<T>\n | SerializedImageControl<T>\n | SerializedRichTextControl<T>\n\ntype SerializedPanelControl<T extends Data = Data> = Extract<\n SerializedLegacyControl<T>,\n { type: PanelControlType }\n>\n\ntype SerializedPanelControlValueType<T extends SerializedPanelControl> =\n T extends SerializedPanelControl<infer U> ? U : never\n\nexport type DeserializedLegacyControl<T extends Data = Data> =\n | Exclude<\n LegacyDescriptor<T>,\n | ListControl<T extends ListControlValue ? T : ListControlValue>\n | ShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any>\n | TypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue>\n | Descriptor<typeof GapX>\n | GapYDescriptor<T>\n | Descriptor<typeof ResponsiveNumber>\n | CheckboxControl<T>\n | ResponsiveColorDescriptor<T>\n | NumberDescriptor<T>\n | Descriptor<typeof ResponsiveIconRadioGroup>\n | Descriptor<typeof ResponsiveSelect>\n | ResponsiveLengthDescriptor<T>\n | DateControl<T>\n | LinkControl<T>\n | TextInputControl<T>\n | TextStyleControl<T>\n | ImageControl<T>\n | RichTextControl<T>\n >\n | DeserializedListControl<T extends ListControlValue ? T : ListControlValue>\n | DeserializedShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any>\n | DeserializedTypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue>\n | DeserializedControlDef<typeof GapX>\n | DeserializedGapYControl<T>\n | DeserializedControlDef<typeof ResponsiveNumber>\n | DeserializedCheckboxControl<T>\n | DeserializedResponsiveColorControl<T>\n | DeserializedNumberControl<T>\n | DeserializedControlDef<typeof ResponsiveIconRadioGroup>\n | DeserializedControlDef<typeof ResponsiveSelect>\n | DeserializedResponsiveLengthControl<T>\n | DeserializedDateControl<T>\n | DeserializedLinkControl<T>\n | DeserializedTextInputControl<T>\n | DeserializedTextStyleControl<T>\n | DeserializedImageControl<T>\n | DeserializedRichTextControl<T>\n\nexport type DeserializedPanelControl<T extends Data = Data> = Extract<\n DeserializedLegacyControl<T>,\n { type: PanelControlType }\n>\n\ntype DeserializedPanelControlValueType<T extends DeserializedPanelControl> =\n T extends DeserializedPanelControl<infer U> ? U : never\n\nexport function serializeLegacyControl<T extends Data>(\n control: LegacyDescriptor<T>,\n): [SerializedLegacyControl<T>, Transferable[]] {\n switch (control.type) {\n case PropControllerTypes.Checkbox:\n return serializeCheckboxControl(control)\n\n case DELETED_PROP_CONTROLLER_TYPES.List:\n return serializeListControl(control)\n\n case DELETED_PROP_CONTROLLER_TYPES.Shape:\n return serializeShapeControl(control)\n\n case DELETED_PROP_CONTROLLER_TYPES.Typeahead:\n return serializeTypeaheadControl(control)\n\n case PropControllerTypes.GapX:\n return serializeControlDef<typeof GapX>(control)\n\n case PropControllerTypes.GapY:\n return serializeGapYControl(control)\n\n case PropControllerTypes.ResponsiveColor:\n return serializeResponsiveColorControl(control)\n\n case PropControllerTypes.ResponsiveNumber:\n return serializeControlDef<typeof ResponsiveNumber>(control)\n\n case PropControllerTypes.Number:\n return serializeNumberControl(control)\n\n case PropControllerTypes.ResponsiveIconRadioGroup:\n return serializeControlDef<typeof ResponsiveIconRadioGroup>(control)\n\n case PropControllerTypes.ResponsiveSelect:\n return serializeControlDef<typeof ResponsiveSelect>(control)\n\n case PropControllerTypes.ResponsiveLength:\n return serializeResponsiveLengthControl(control)\n\n case PropControllerTypes.Date:\n return serializeDateControl(control)\n\n case PropControllerTypes.Link:\n return serializeLinkControl(control)\n\n case PropControllerTypes.TextInput:\n return serializeTextInputControl(control)\n\n case PropControllerTypes.TextStyle:\n return serializeTextStyleControl(control)\n\n case PropControllerTypes.Image:\n return serializeImageControl(control)\n\n case DELETED_PROP_CONTROLLER_TYPES.RichText:\n return serializeRichTextControl(control)\n\n default:\n return [control, []]\n }\n}\n\nexport function deserializeLegacyControl<T extends Data>(\n serializedControl: SerializedLegacyControl<T>,\n): DeserializedLegacyControl<T> {\n switch (serializedControl.type) {\n case PropControllerTypes.Checkbox:\n return deserializeCheckboxControl(serializedControl)\n\n case DELETED_PROP_CONTROLLER_TYPES.List:\n return deserializeListControl(serializedControl)\n\n case DELETED_PROP_CONTROLLER_TYPES.Shape:\n return deserializeShapeControl(serializedControl)\n\n case DELETED_PROP_CONTROLLER_TYPES.Typeahead:\n return deserializeTypeaheadControl(serializedControl)\n\n case PropControllerTypes.GapX:\n return deserializeControlDef<typeof GapX>(serializedControl)\n\n case PropControllerTypes.GapY:\n return deserializeGapYControl(serializedControl)\n\n case PropControllerTypes.ResponsiveColor:\n return deserializeResponsiveColorControl(serializedControl)\n\n case PropControllerTypes.ResponsiveNumber:\n return deserializeControlDef<typeof ResponsiveNumber>(serializedControl)\n\n case PropControllerTypes.Number:\n return deserializeNumberControl(serializedControl)\n\n case PropControllerTypes.ResponsiveIconRadioGroup:\n return deserializeControlDef<typeof ResponsiveIconRadioGroup>(serializedControl)\n\n case PropControllerTypes.ResponsiveSelect:\n return deserializeControlDef<typeof ResponsiveSelect>(serializedControl)\n\n case PropControllerTypes.ResponsiveLength:\n return deserializeResponsiveLengthControl(serializedControl)\n\n case PropControllerTypes.Date:\n return deserializeDateControl(serializedControl)\n\n case PropControllerTypes.Link:\n return deserializeLinkControl(serializedControl)\n\n case PropControllerTypes.TextInput:\n return deserializeTextInputControl(serializedControl)\n\n case PropControllerTypes.TextStyle:\n return deserializeTextStyleControl(serializedControl)\n\n case PropControllerTypes.Image:\n return deserializeImageControl(serializedControl)\n\n case DELETED_PROP_CONTROLLER_TYPES.RichText:\n return deserializeRichTextControl(serializedControl)\n\n default:\n return serializedControl\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,8BAgCO;AAEP,oCAMO;AAQP,qBAWO;AAiBP,SAAS,sBAIP,SAOA;AACA,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,gBAAgC,CAAC;AACvC,QAAM,iBAAiB,CAAC;AAIxB,SAAO,QAAQ,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAKA,QAAO,MAAM;AAC/C,UAAM,CAAC,mBAAmB,8BAA8B,IAAI,uBAAuBA,QAAO;AAE1F,mBAAe,GAAwB,IAAI;AAC3C,kBAAc,KAAK,GAAG,8BAA8B;AAAA,EACtD,CAAC;AAGD,SAAO,CAAC,EAAE,GAAG,SAAS,SAAS,EAAE,GAAG,QAAQ,SAAS,MAAM,eAAe,EAAE,GAAG,aAAa;AAC9F;AAeA,SAAS,wBAIP,SAIA;AACA,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,mBAAmB,CAAC;AAI1B,SAAO,QAAQ,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAKA,QAAO,MAAM;AAC/C,qBAAiB,GAAwB,IAAI;AAAA,MAC3CA;AAAA,IACF;AAAA,EACF,CAAC;AAGD,SAAO,EAAE,GAAG,SAAS,SAAS,EAAE,GAAG,QAAQ,SAAS,MAAM,iBAAiB,EAAE;AAC/E;AAeA,SAAS,qBACP,SAC8D;AAC9D,QAAM,EAAE,MAAM,aAAa,IAAI,QAAQ;AACvC,QAAM,gBAAgC,CAAC;AAEvC,QAAM,CAAC,gBAAgB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MAAoB;AACvB,aAAO,kCAAkC,iBAAiB;AAAA,IAE5D,KAAK,wBAAAA,MAAoB;AACvB,aAAO,sBAA+C,iBAAiB;AAAA,IAEzE,KAAK,wBAAAA,MAAoB;AACvB,aAAO,yBAAyB,iBAAiB;AAAA,IAEnD,KAAK,wBAAAA,MAAoB;AACvB,aAAO,sBAAuD,iBAAiB;AAAA,IAEjF,KAAK,wBAAAA,MAAoB;AACvB,aAAO,sBAA+C,iBAAiB;AAAA,IAEzE,KAAK,wBAAAA,MAAoB;AACvB,aAAO,mCAAmC,iBAAiB;AAAA,IAE7D,KAAK,wBAAAA,MAAoB;AACvB,aAAO,uBAAuB,iBAAiB;AAAA,IAEjD,KAAK,wBAAAA,MAAoB;AACvB,aAAO,uBAAuB,iBAAiB;AAAA,IAEjD,KAAK,wBAAAA,MAAoB;AACvB,aAAO,4BAA4B,iBAAiB;AAAA,IAEtD,KAAK,wBAAAA,MAAoB;AACvB,aAAO,4BAA4B,iBAAiB;AAAA,IAEtD,KAAK,wBAAAA,MAAoB;AACvB,aAAO,wBAAwB,iBAAiB;AAAA,IAElD,KAAK,6CAA8B;AACjC,aAAO,2BAA2B,iBAAiB;AAAA,IAErD;AACE,aAAO;AAAA,EACX;AACF;","names":["control","PropControllerTypes"]}
|
|
@@ -221,11 +221,11 @@ function deleteElement({ elements, elementIds }, deletedElement, propName, descr
|
|
|
221
221
|
}
|
|
222
222
|
function applyDelete(elementTree, descriptors, rootElements, path) {
|
|
223
223
|
const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
|
|
224
|
-
const [deletedElement, propName] = getElementAndPropName(rootElements.
|
|
224
|
+
const [deletedElement, propName] = getElementAndPropName(rootElements.before, deleteElementPath);
|
|
225
225
|
const elements = new Map(elementTree.elements);
|
|
226
226
|
const elementIds = new Map(elementTree.elementIds);
|
|
227
227
|
deleteElement({ elements, elementIds }, deletedElement, propName, descriptors);
|
|
228
|
-
updateParentElements(elements, parentElementPaths, rootElements.
|
|
228
|
+
updateParentElements(elements, parentElementPaths, rootElements.after);
|
|
229
229
|
return {
|
|
230
230
|
elements,
|
|
231
231
|
elementIds
|
|
@@ -252,11 +252,11 @@ function insertElement({ elements, elementIds }, insertedElement, propName, desc
|
|
|
252
252
|
}
|
|
253
253
|
function applyInsert(elementTree, descriptors, rootElements, path) {
|
|
254
254
|
const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
|
|
255
|
-
const [insertedElement, propName] = getElementAndPropName(rootElements.
|
|
255
|
+
const [insertedElement, propName] = getElementAndPropName(rootElements.after, insertedElementPath);
|
|
256
256
|
const elements = new Map(elementTree.elements);
|
|
257
257
|
const elementIds = new Map(elementTree.elementIds);
|
|
258
258
|
insertElement({ elements, elementIds }, insertedElement, propName, descriptors);
|
|
259
|
-
updateParentElements(elements, parentElementPaths, rootElements.
|
|
259
|
+
updateParentElements(elements, parentElementPaths, rootElements.after);
|
|
260
260
|
return {
|
|
261
261
|
elements,
|
|
262
262
|
elementIds
|
|
@@ -264,31 +264,57 @@ function applyInsert(elementTree, descriptors, rootElements, path) {
|
|
|
264
264
|
}
|
|
265
265
|
function applyUpdate(elementTree, descriptors, rootElements, path) {
|
|
266
266
|
const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
|
|
267
|
-
const [deletedElement, propName] = getElementAndPropName(rootElements.
|
|
268
|
-
const [insertedElement, _] = getElementAndPropName(rootElements.
|
|
267
|
+
const [deletedElement, propName] = getElementAndPropName(rootElements.before, updateElementPath);
|
|
268
|
+
const [insertedElement, _] = getElementAndPropName(rootElements.after, updateElementPath);
|
|
269
269
|
const elements = new Map(elementTree.elements);
|
|
270
270
|
const elementIds = new Map(elementTree.elementIds);
|
|
271
271
|
deleteElement({ elements, elementIds }, deletedElement, propName, descriptors);
|
|
272
272
|
insertElement({ elements, elementIds }, insertedElement, propName, descriptors);
|
|
273
|
-
updateParentElements(elements, parentElementPaths, rootElements.
|
|
273
|
+
updateParentElements(elements, parentElementPaths, rootElements.after);
|
|
274
274
|
return {
|
|
275
275
|
elements,
|
|
276
276
|
elementIds
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
|
+
function applyOpComponent(root, component) {
|
|
280
|
+
let applied = root;
|
|
281
|
+
if ("ld" in component || "od" in component) {
|
|
282
|
+
applied = (0, import_immutable.removeIn)(applied, component.p);
|
|
283
|
+
}
|
|
284
|
+
if ("li" in component) {
|
|
285
|
+
applied = (0, import_immutable.setIn)(applied, component.p, component.li);
|
|
286
|
+
}
|
|
287
|
+
if ("oi" in component) {
|
|
288
|
+
applied = (0, import_immutable.setIn)(applied, component.p, component.oi);
|
|
289
|
+
}
|
|
290
|
+
return applied;
|
|
291
|
+
}
|
|
292
|
+
function selectTreeTransform(op) {
|
|
293
|
+
const hasDelete = "ld" in op || "od" in op;
|
|
294
|
+
const hasInsert = "li" in op || "oi" in op;
|
|
295
|
+
if (hasDelete && hasInsert)
|
|
296
|
+
return applyUpdate;
|
|
297
|
+
if (hasDelete)
|
|
298
|
+
return applyDelete;
|
|
299
|
+
if (hasInsert)
|
|
300
|
+
return applyInsert;
|
|
301
|
+
return (elementTree) => elementTree;
|
|
302
|
+
}
|
|
279
303
|
function applyChanges(elementTree, descriptors, rootElements, operation) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
304
|
+
const result = operation.reduce(
|
|
305
|
+
(acc, op) => {
|
|
306
|
+
const rootBefore = acc.rootBefore;
|
|
307
|
+
const rootAfter = operation.length > 1 ? applyOpComponent(rootBefore, op) : rootElements.new;
|
|
308
|
+
const roots = { before: rootBefore, after: rootAfter };
|
|
309
|
+
const applyChange = selectTreeTransform(op);
|
|
310
|
+
return {
|
|
311
|
+
elementTree: applyChange(acc.elementTree, descriptors, roots, op.p),
|
|
312
|
+
rootBefore: rootAfter
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
{ elementTree, rootBefore: rootElements.old }
|
|
316
|
+
);
|
|
317
|
+
return result.elementTree;
|
|
292
318
|
}
|
|
293
319
|
// Annotate the CommonJS export names for ESM import in node:
|
|
294
320
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport * as Introspection from '../../prop-controllers/introspection'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\nimport { ReadWriteActionTypes } from '../actions/internal/read-write-actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ReadOnlyActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ReadWriteActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction hasChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n if (isElementReference(element)) return false\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return false\n\n const children = Introspection.getElementChildren(propDescriptor, element.props[propName])\n return children.length > 0\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n deletedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(deletedElement, propName, descriptors)) {\n for (const element of traverseElementTree(deletedElement, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n } else {\n elements.delete(deletedElement.key)\n elementIds.delete(deletedElement.key)\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, deleteElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.new, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.old, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.new, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n updateParentElements(elements, parentElementPaths, rootElements.new)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n return operation.reduce((tree, op) => {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n if (hasDelete && hasInsert) {\n return applyUpdate(tree, descriptors, rootElements, op.p)\n }\n\n if (hasDelete) return applyDelete(tree, descriptors, rootElements, op.p)\n if (hasInsert) return applyInsert(tree, descriptors, rootElements, op.p)\n return tree\n }, elementTree)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAsB;AAEtB,sBAAmE;AAEnE,oBAA+B;AAE/B,qBAA+D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c,EAAE,UAAU,WAAW,GAAG,iBAAiB,UAAU,WAAW;AAC9E,uBAAqB,UAAU,oBAAoB,aAAa,GAAG;AAEnE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,YACP,aACA,aACA,cACA,MACa;AACb,QAAM,CAAC,mBAAmB,GAAG,kBAAkB,IAAI,wBAAwB,IAAI;AAC/E,QAAM,CAAC,gBAAgB,QAAQ,IAAI,sBAAsB,aAAa,KAAK,iBAAiB;AAC5F,QAAM,CAAC,iBAAiB,CAAC,IAAI,sBAAsB,aAAa,KAAK,iBAAiB;AAEtF,QAAM,WAAW,IAAI,IAAI,YAAY,QAAQ;AAC7C,QAAM,aAAa,IAAI,IAAI,YAAY,UAAU;AAEjD,gBAAc,EAAE,UAAU,WAAW,GAAG,gBAAgB,UAAU,WAAW;AAC7E,gBAAc,EAAE,UAAU,WAAW,GAAG,iBAAiB,UAAU,WAAW;AAE9E,uBAAqB,UAAU,oBAAoB,aAAa,GAAG;AAEnE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,aACP,aACA,aACA,cACA,WACa;AACb,SAAO,UAAU,OAAO,CAAC,MAAM,OAAO;AACpC,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,UAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,QAAI,aAAa,WAAW;AAC1B,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AAAA,IAC1D;AAEA,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,QAAI;AAAW,aAAO,YAAY,MAAM,aAAa,cAAc,GAAG,CAAC;AACvE,WAAO;AAAA,EACT,GAAG,WAAW;AAChB;","names":["i"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn, removeIn, setIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport * as Introspection from '../../prop-controllers/introspection'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\nimport { ReadWriteActionTypes } from '../actions/internal/read-write-actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ReadOnlyActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ReadWriteActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction hasChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n if (isElementReference(element)) return false\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return false\n\n const children = Introspection.getElementChildren(propDescriptor, element.props[propName])\n return children.length > 0\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n deletedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(deletedElement, propName, descriptors)) {\n for (const element of traverseElementTree(deletedElement, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n } else {\n elements.delete(deletedElement.key)\n elementIds.delete(deletedElement.key)\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.before, deleteElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.after, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.before, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.after, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyOpComponent(root: Element, component: Operation[number]): Element {\n let applied: Element = root\n\n if ('ld' in component || 'od' in component) {\n applied = removeIn(applied, component.p)\n }\n\n if ('li' in component) {\n applied = setIn(applied, component.p, component.li)\n }\n\n if ('oi' in component) {\n applied = setIn(applied, component.p, component.oi)\n }\n\n return applied\n}\n\nfunction selectTreeTransform(op: Operation[number]): typeof applyUpdate {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n\n if (hasDelete && hasInsert) return applyUpdate\n if (hasDelete) return applyDelete\n if (hasInsert) return applyInsert\n\n return elementTree => elementTree\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n // Updates the element tree \"cache\" based on the provided operation, which can\n // be composed of 1-n component ops. We apply each component op sequentially\n // to the 'old' root element to determine the changed elements and update the\n // cache accordingly at each intermediate step.\n const result = operation.reduce(\n (acc, op) => {\n const rootBefore = acc.rootBefore\n\n // If there's only one component op, we can skip the application of the op\n // and assume that the result will be the 'new' root element provided to\n // us by the builder.\n const rootAfter = operation.length > 1 ? applyOpComponent(rootBefore, op) : rootElements.new\n\n const roots = { before: rootBefore, after: rootAfter }\n const applyChange = selectTreeTransform(op)\n\n return {\n elementTree: applyChange(acc.elementTree, descriptors, roots, op.p),\n rootBefore: rootAfter,\n }\n },\n { elementTree, rootBefore: rootElements.old },\n )\n\n return result.elementTree\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAuC;AAEvC,sBAAmE;AAEnE,oBAA+B;AAE/B,qBAA+D;AAE/D,+BAAoC;AACpC,gCAAqC;AAErC,iCAA8C;AAUvC,SAAS,gBACd,WACA,aACO;AACP,QAAM,QAAQ,oBAAI,IAAyB;AAC3C,MAAI,aAAa,QAAQ,eAAe;AAAM,WAAO;AAErD,aAAW,CAAC,aAAa,QAAQ,KAAK,WAAW;AAC/C,UAAM,IAAI,aAAa,qBAAiB,2CAAe,QAAQ,GAAG,WAAW,CAAC;AAAA,EAChF;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,OAAc,aAAyC;AAC7E,SAAO,MAAM,IAAI,WAAW,KAAK;AACnC;AAEO,SAAS,YAAY,OAAc,aAA2C;AACnF,SAAO,eAAe,OAAO,WAAW,GAAG,YAAY,oBAAI,IAAI;AACjE;AAEO,SAAS,cAAc,OAAc,aAA0C;AACpF,SAAO,eAAe,OAAO,WAAW,GAAG,cAAc,oBAAI,IAAI;AACnE;AAEO,SAAS,WAAW,OAAc,aAAqB,YAAoC;AAChG,SAAO,YAAY,OAAO,WAAW,EAAE,IAAI,UAAU,KAAK;AAC5D;AAEO,SAAS,aAAa,OAAc,aAAqB,YAAmC;AACjG,SAAO,cAAc,OAAO,WAAW,EAAE,IAAI,UAAU,KAAK;AAC9D;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UA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AU,wBAAM,SAAS,UAAU,GAAG,UAAU,EAAE;AAAA,EACpD;AAEA,MAAI,QAAQ,WAAW;AACrB,kBAAU,wBAAM,SAAS,UAAU,GAAG,UAAU,EAAE;AAAA,EACpD;AAEA,SAAO;AACT;AAEA,SAAS,oBAAoB,IAA2C;AACtE,QAAM,YAAY,QAAQ,MAAM,QAAQ;AACxC,QAAM,YAAY,QAAQ,MAAM,QAAQ;AAExC,MAAI,aAAa;AAAW,WAAO;AACnC,MAAI;AAAW,WAAO;AACtB,MAAI;AAAW,WAAO;AAEtB,SAAO,iBAAe;AACxB;AAEA,SAAS,aACP,aACA,aACA,cACA,WACa;AAKb,QAAM,SAAS,UAAU;AAAA,IACvB,CAAC,KAAK,OAAO;AACX,YAAM,aAAa,IAAI;AAKvB,YAAM,YAAY,UAAU,SAAS,IAAI,iBAAiB,YAAY,EAAE,IAAI,aAAa;AAEzF,YAAM,QAAQ,EAAE,QAAQ,YAAY,OAAO,UAAU;AACrD,YAAM,cAAc,oBAAoB,EAAE;AAE1C,aAAO;AAAA,QACL,aAAa,YAAY,IAAI,aAAa,aAAa,OAAO,GAAG,CAAC;AAAA,QAClE,YAAY;AAAA,MACd;AAAA,IACF;AAAA,IACA,EAAE,aAAa,YAAY,aAAa,IAAI;AAAA,EAC9C;AAEA,SAAO,OAAO;AAChB;","names":["i"]}
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.28.4-canary.
|
|
11
|
+
version: "0.28.4-canary.2",
|
|
12
12
|
interactionMode: true,
|
|
13
13
|
clientSideNavigation: false,
|
|
14
14
|
elementFromPoint: false,
|