@makeswift/runtime 0.27.3 → 0.27.4
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/client/index.js +3 -3
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +3 -3
- package/package.json +3 -3
- package/dist/cjs/api/api-resources-client.js +0 -160
- package/dist/cjs/api/api-resources-client.js.map +0 -1
- package/dist/cjs/api/react.js +0 -256
- package/dist/cjs/api/react.js.map +0 -1
- package/dist/cjs/api-handler/handlers/webhook/diff-projection.js +0 -62
- package/dist/cjs/api-handler/handlers/webhook/diff-projection.js.map +0 -1
- package/dist/cjs/box-model.js +0 -33
- package/dist/cjs/box-model.js.map +0 -1
- package/dist/cjs/builder/serialization.js +0 -78
- package/dist/cjs/builder/serialization.js.map +0 -1
- package/dist/cjs/components/builtin/index.js +0 -84
- package/dist/cjs/components/builtin/index.js.map +0 -1
- package/dist/cjs/components/index.js +0 -25
- package/dist/cjs/components/index.js.map +0 -1
- package/dist/cjs/controls/rich-text-v2/translation.js +0 -187
- package/dist/cjs/controls/rich-text-v2/translation.js.map +0 -1
- package/dist/cjs/controls/serialization/base/index.js +0 -78
- package/dist/cjs/controls/serialization/base/index.js.map +0 -1
- package/dist/cjs/controls/serialization/base/visitor.js +0 -59
- package/dist/cjs/controls/serialization/base/visitor.js.map +0 -1
- package/dist/cjs/controls/serialization/index.js +0 -55
- package/dist/cjs/controls/serialization/index.js.map +0 -1
- package/dist/cjs/controls/serialization/message-port/function-serialization.js +0 -79
- package/dist/cjs/controls/serialization/message-port/function-serialization.js.map +0 -1
- package/dist/cjs/controls/serialization/message-port/index.js +0 -25
- package/dist/cjs/controls/serialization/message-port/index.js.map +0 -1
- package/dist/cjs/controls/serialization/message-port/visitor.js +0 -48
- package/dist/cjs/controls/serialization/message-port/visitor.js.map +0 -1
- package/dist/cjs/core/index.js +0 -57
- package/dist/cjs/core/index.js.map +0 -1
- package/dist/cjs/next/fetch.js +0 -30
- package/dist/cjs/next/fetch.js.map +0 -1
- package/dist/cjs/prop-controllers/index.js +0 -48
- package/dist/cjs/prop-controllers/index.js.map +0 -1
- package/dist/cjs/prop-controllers/serialization.js +0 -355
- package/dist/cjs/prop-controllers/serialization.js.map +0 -1
- package/dist/cjs/react.js +0 -40
- package/dist/cjs/react.js.map +0 -1
- package/dist/cjs/runtimes/react/components/LiveProvider.js +0 -50
- package/dist/cjs/runtimes/react/components/LiveProvider.js.map +0 -1
- package/dist/cjs/runtimes/react/components/MakeswiftFonts.js +0 -33
- package/dist/cjs/runtimes/react/components/MakeswiftFonts.js.map +0 -1
- package/dist/cjs/runtimes/react/components/PreviewProvider.js +0 -57
- package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +0 -1
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +0 -67
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +0 -1
- package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js +0 -39
- package/dist/cjs/runtimes/react/hooks/use-current-breakpoint.js.map +0 -1
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js +0 -33
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js.map +0 -1
- package/dist/cjs/runtimes/react/lib/resolved-style-to-css.js +0 -59
- package/dist/cjs/runtimes/react/lib/resolved-style-to-css.js.map +0 -1
- package/dist/cjs/runtimes/react/resource-resolver.js +0 -52
- package/dist/cjs/runtimes/react/resource-resolver.js.map +0 -1
- package/dist/cjs/state/actions/internal.js +0 -205
- package/dist/cjs/state/actions/internal.js.map +0 -1
- package/dist/cjs/state/actions.js +0 -423
- package/dist/cjs/state/actions.js.map +0 -1
- package/dist/cjs/state/api-client/client-store.js +0 -81
- package/dist/cjs/state/api-client/client-store.js.map +0 -1
- package/dist/cjs/state/api-client/fetch-api-resource.js +0 -125
- package/dist/cjs/state/api-client/fetch-api-resource.js.map +0 -1
- package/dist/cjs/state/api-client/state.js +0 -89
- package/dist/cjs/state/api-client/state.js.map +0 -1
- package/dist/cjs/state/api-client/store.js +0 -36
- package/dist/cjs/state/api-client/store.js.map +0 -1
- package/dist/cjs/state/builder-api/api.js +0 -17
- package/dist/cjs/state/builder-api/api.js.map +0 -1
- package/dist/cjs/state/builder-api/navigation-listener.js +0 -110
- package/dist/cjs/state/builder-api/navigation-listener.js.map +0 -1
- package/dist/cjs/state/mixins/breakpoint-watch.js +0 -72
- package/dist/cjs/state/mixins/breakpoint-watch.js.map +0 -1
- package/dist/cjs/state/mixins/setup-teardown.js +0 -35
- package/dist/cjs/state/mixins/setup-teardown.js.map +0 -1
- package/dist/cjs/state/modules/box-models.js +0 -127
- package/dist/cjs/state/modules/box-models.js.map +0 -1
- package/dist/cjs/state/modules/element-imperative-handles.js +0 -60
- package/dist/cjs/state/modules/element-imperative-handles.js.map +0 -1
- package/dist/cjs/state/modules/is-preview.js +0 -47
- package/dist/cjs/state/modules/is-preview.js.map +0 -1
- package/dist/cjs/state/modules/pointer.js +0 -47
- package/dist/cjs/state/modules/pointer.js.map +0 -1
- package/dist/cjs/state/modules/read-write-documents.js +0 -98
- package/dist/cjs/state/modules/read-write-documents.js.map +0 -1
- package/dist/cjs/state/react-builder-preview.js +0 -610
- package/dist/cjs/state/react-builder-preview.js.map +0 -1
- package/dist/cjs/state/react-page.js +0 -355
- package/dist/cjs/state/react-page.js.map +0 -1
- package/dist/cjs/utils/ref-counted-map.js +0 -120
- package/dist/cjs/utils/ref-counted-map.js.map +0 -1
- package/dist/esm/api/api-resources-client.js +0 -127
- package/dist/esm/api/api-resources-client.js.map +0 -1
- package/dist/esm/api/react.js +0 -223
- package/dist/esm/api/react.js.map +0 -1
- package/dist/esm/api-handler/handlers/webhook/diff-projection.js +0 -38
- package/dist/esm/api-handler/handlers/webhook/diff-projection.js.map +0 -1
- package/dist/esm/box-model.js +0 -7
- package/dist/esm/box-model.js.map +0 -1
- package/dist/esm/builder/serialization.js +0 -59
- package/dist/esm/builder/serialization.js.map +0 -1
- package/dist/esm/components/builtin/index.js +0 -34
- package/dist/esm/components/builtin/index.js.map +0 -1
- package/dist/esm/components/index.js +0 -3
- package/dist/esm/components/index.js.map +0 -1
- package/dist/esm/controls/rich-text-v2/translation.js +0 -152
- package/dist/esm/controls/rich-text-v2/translation.js.map +0 -1
- package/dist/esm/controls/serialization/base/index.js +0 -78
- package/dist/esm/controls/serialization/base/index.js.map +0 -1
- package/dist/esm/controls/serialization/base/visitor.js +0 -39
- package/dist/esm/controls/serialization/base/visitor.js.map +0 -1
- package/dist/esm/controls/serialization/index.js +0 -30
- package/dist/esm/controls/serialization/index.js.map +0 -1
- package/dist/esm/controls/serialization/message-port/function-serialization.js +0 -52
- package/dist/esm/controls/serialization/message-port/function-serialization.js.map +0 -1
- package/dist/esm/controls/serialization/message-port/index.js +0 -3
- package/dist/esm/controls/serialization/message-port/index.js.map +0 -1
- package/dist/esm/controls/serialization/message-port/visitor.js +0 -24
- package/dist/esm/controls/serialization/message-port/visitor.js.map +0 -1
- package/dist/esm/core/index.js +0 -35
- package/dist/esm/core/index.js.map +0 -1
- package/dist/esm/next/fetch.js +0 -6
- package/dist/esm/next/fetch.js.map +0 -1
- package/dist/esm/prop-controllers/index.js +0 -11
- package/dist/esm/prop-controllers/index.js.map +0 -1
- package/dist/esm/prop-controllers/serialization.js +0 -338
- package/dist/esm/prop-controllers/serialization.js.map +0 -1
- package/dist/esm/react.js +0 -11
- package/dist/esm/react.js.map +0 -1
- package/dist/esm/runtimes/react/components/LiveProvider.js +0 -20
- package/dist/esm/runtimes/react/components/LiveProvider.js.map +0 -1
- package/dist/esm/runtimes/react/components/MakeswiftFonts.js +0 -9
- package/dist/esm/runtimes/react/components/MakeswiftFonts.js.map +0 -1
- package/dist/esm/runtimes/react/components/PreviewProvider.js +0 -27
- package/dist/esm/runtimes/react/components/PreviewProvider.js.map +0 -1
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +0 -43
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +0 -1
- package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js +0 -15
- package/dist/esm/runtimes/react/hooks/use-current-breakpoint.js.map +0 -1
- package/dist/esm/runtimes/react/hooks/use-is-preview.js +0 -9
- package/dist/esm/runtimes/react/hooks/use-is-preview.js.map +0 -1
- package/dist/esm/runtimes/react/lib/resolved-style-to-css.js +0 -38
- package/dist/esm/runtimes/react/lib/resolved-style-to-css.js.map +0 -1
- package/dist/esm/runtimes/react/resource-resolver.js +0 -28
- package/dist/esm/runtimes/react/resource-resolver.js.map +0 -1
- package/dist/esm/state/actions/internal.js +0 -162
- package/dist/esm/state/actions/internal.js.map +0 -1
- package/dist/esm/state/actions.js +0 -349
- package/dist/esm/state/actions.js.map +0 -1
- package/dist/esm/state/api-client/client-store.js +0 -49
- package/dist/esm/state/api-client/client-store.js.map +0 -1
- package/dist/esm/state/api-client/fetch-api-resource.js +0 -93
- package/dist/esm/state/api-client/fetch-api-resource.js.map +0 -1
- package/dist/esm/state/api-client/state.js +0 -52
- package/dist/esm/state/api-client/state.js.map +0 -1
- package/dist/esm/state/api-client/store.js +0 -12
- package/dist/esm/state/api-client/store.js.map +0 -1
- package/dist/esm/state/builder-api/api.js +0 -1
- package/dist/esm/state/builder-api/api.js.map +0 -1
- package/dist/esm/state/builder-api/navigation-listener.js +0 -86
- package/dist/esm/state/builder-api/navigation-listener.js.map +0 -1
- package/dist/esm/state/mixins/breakpoint-watch.js +0 -48
- package/dist/esm/state/mixins/breakpoint-watch.js.map +0 -1
- package/dist/esm/state/mixins/setup-teardown.js +0 -11
- package/dist/esm/state/mixins/setup-teardown.js.map +0 -1
- package/dist/esm/state/modules/box-models.js +0 -98
- package/dist/esm/state/modules/box-models.js.map +0 -1
- package/dist/esm/state/modules/element-imperative-handles.js +0 -35
- package/dist/esm/state/modules/element-imperative-handles.js.map +0 -1
- package/dist/esm/state/modules/is-preview.js +0 -21
- package/dist/esm/state/modules/is-preview.js.map +0 -1
- package/dist/esm/state/modules/pointer.js +0 -22
- package/dist/esm/state/modules/pointer.js.map +0 -1
- package/dist/esm/state/modules/read-write-documents.js +0 -60
- package/dist/esm/state/modules/read-write-documents.js.map +0 -1
- package/dist/esm/state/react-builder-preview.js +0 -590
- package/dist/esm/state/react-builder-preview.js.map +0 -1
- package/dist/esm/state/react-page.js +0 -319
- package/dist/esm/state/react-page.js.map +0 -1
- package/dist/esm/utils/ref-counted-map.js +0 -96
- package/dist/esm/utils/ref-counted-map.js.map +0 -1
- package/dist/types/api/api-resources-client.d.ts +0 -57
- package/dist/types/api/api-resources-client.d.ts.map +0 -1
- package/dist/types/api/react.d.ts +0 -82
- package/dist/types/api/react.d.ts.map +0 -1
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +0 -201
- package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts.map +0 -1
- package/dist/types/box-model.d.ts +0 -3
- package/dist/types/box-model.d.ts.map +0 -1
- package/dist/types/builder/serialization.d.ts +0 -23
- package/dist/types/builder/serialization.d.ts.map +0 -1
- package/dist/types/builder/serialization.test.d.ts +0 -2
- package/dist/types/builder/serialization.test.d.ts.map +0 -1
- package/dist/types/client/tests/client.get-component-snapshots.test.d.ts +0 -2
- package/dist/types/client/tests/client.get-component-snapshots.test.d.ts.map +0 -1
- package/dist/types/client/tests/client.introspect-many.test.d.ts +0 -2
- package/dist/types/client/tests/client.introspect-many.test.d.ts.map +0 -1
- package/dist/types/components/builtin/index.d.ts +0 -17
- package/dist/types/components/builtin/index.d.ts.map +0 -1
- package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts +0 -3
- package/dist/types/components/hooks/__tests__/useMediaQuery.test.d.ts.map +0 -1
- package/dist/types/components/index.d.ts +0 -3
- package/dist/types/components/index.d.ts.map +0 -1
- package/dist/types/controls/rich-text-v2/translation.d.ts +0 -6
- package/dist/types/controls/rich-text-v2/translation.d.ts.map +0 -1
- package/dist/types/controls/serialization/base/index.d.ts +0 -10
- package/dist/types/controls/serialization/base/index.d.ts.map +0 -1
- package/dist/types/controls/serialization/base/visitor.d.ts +0 -7
- package/dist/types/controls/serialization/base/visitor.d.ts.map +0 -1
- package/dist/types/controls/serialization/index.d.ts +0 -10
- package/dist/types/controls/serialization/index.d.ts.map +0 -1
- package/dist/types/controls/serialization/message-port/function-serialization.d.ts +0 -16
- package/dist/types/controls/serialization/message-port/function-serialization.d.ts.map +0 -1
- package/dist/types/controls/serialization/message-port/function-serialization.test.d.ts +0 -2
- package/dist/types/controls/serialization/message-port/function-serialization.test.d.ts.map +0 -1
- package/dist/types/controls/serialization/message-port/index.d.ts +0 -3
- package/dist/types/controls/serialization/message-port/index.d.ts.map +0 -1
- package/dist/types/controls/serialization/message-port/visitor.d.ts +0 -7
- package/dist/types/controls/serialization/message-port/visitor.d.ts.map +0 -1
- package/dist/types/core/index.d.ts +0 -2
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/next/api-handler/config/pages-router.test.d.ts +0 -2
- package/dist/types/next/api-handler/config/pages-router.test.d.ts.map +0 -1
- package/dist/types/next/components/tests/controls/code-control.test.d.ts +0 -2
- package/dist/types/next/components/tests/controls/code-control.test.d.ts.map +0 -1
- package/dist/types/next/components/tests/makeswift-component-rendering.test.d.ts +0 -3
- package/dist/types/next/components/tests/makeswift-component-rendering.test.d.ts.map +0 -1
- package/dist/types/next/fetch.d.ts +0 -3
- package/dist/types/next/fetch.d.ts.map +0 -1
- package/dist/types/prop-controllers/index.d.ts +0 -8
- package/dist/types/prop-controllers/index.d.ts.map +0 -1
- package/dist/types/prop-controllers/serialization.d.ts +0 -228
- package/dist/types/prop-controllers/serialization.d.ts.map +0 -1
- package/dist/types/react.d.ts +0 -4
- package/dist/types/react.d.ts.map +0 -1
- package/dist/types/runtimes/react/components/LiveProvider.d.ts +0 -3
- package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +0 -1
- package/dist/types/runtimes/react/components/MakeswiftFonts.d.ts +0 -7
- package/dist/types/runtimes/react/components/MakeswiftFonts.d.ts.map +0 -1
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts +0 -3
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +0 -1
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts +0 -4
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +0 -1
- package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts +0 -3
- package/dist/types/runtimes/react/hooks/use-current-breakpoint.d.ts.map +0 -1
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts +0 -2
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts.map +0 -1
- package/dist/types/runtimes/react/lib/resolved-style-to-css.d.ts +0 -4
- package/dist/types/runtimes/react/lib/resolved-style-to-css.d.ts.map +0 -1
- package/dist/types/runtimes/react/resource-resolver.d.ts +0 -10
- package/dist/types/runtimes/react/resource-resolver.d.ts.map +0 -1
- package/dist/types/state/__tests__/react-page.test.d.ts +0 -2
- package/dist/types/state/__tests__/react-page.test.d.ts.map +0 -1
- package/dist/types/state/actions/internal.d.ts +0 -181
- package/dist/types/state/actions/internal.d.ts.map +0 -1
- package/dist/types/state/actions.d.ts +0 -461
- package/dist/types/state/actions.d.ts.map +0 -1
- package/dist/types/state/api-client/client-store.d.ts +0 -6
- package/dist/types/state/api-client/client-store.d.ts.map +0 -1
- package/dist/types/state/api-client/fetch-api-resource.d.ts +0 -11
- package/dist/types/state/api-client/fetch-api-resource.d.ts.map +0 -1
- package/dist/types/state/api-client/state.d.ts +0 -30
- package/dist/types/state/api-client/state.d.ts.map +0 -1
- package/dist/types/state/api-client/store.d.ts +0 -18
- package/dist/types/state/api-client/store.d.ts.map +0 -1
- package/dist/types/state/builder-api/api.d.ts +0 -9
- package/dist/types/state/builder-api/api.d.ts.map +0 -1
- package/dist/types/state/builder-api/navigation-listener.d.ts +0 -3
- package/dist/types/state/builder-api/navigation-listener.d.ts.map +0 -1
- package/dist/types/state/mixins/breakpoint-watch.d.ts +0 -11
- package/dist/types/state/mixins/breakpoint-watch.d.ts.map +0 -1
- package/dist/types/state/mixins/setup-teardown.d.ts +0 -7
- package/dist/types/state/mixins/setup-teardown.d.ts.map +0 -1
- package/dist/types/state/modules/box-models.d.ts +0 -23
- package/dist/types/state/modules/box-models.d.ts.map +0 -1
- package/dist/types/state/modules/element-imperative-handles.d.ts +0 -7
- package/dist/types/state/modules/element-imperative-handles.d.ts.map +0 -1
- package/dist/types/state/modules/is-preview.d.ts +0 -6
- package/dist/types/state/modules/is-preview.d.ts.map +0 -1
- package/dist/types/state/modules/pointer.d.ts +0 -12
- package/dist/types/state/modules/pointer.d.ts.map +0 -1
- package/dist/types/state/modules/read-write-documents.d.ts +0 -14
- package/dist/types/state/modules/read-write-documents.d.ts.map +0 -1
- package/dist/types/state/react-builder-preview.d.ts +0 -110
- package/dist/types/state/react-builder-preview.d.ts.map +0 -1
- package/dist/types/state/react-page.d.ts +0 -149
- package/dist/types/state/react-page.d.ts.map +0 -1
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +0 -2
- package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +0 -1
- package/dist/types/utils/ref-counted-map.d.ts +0 -32
- package/dist/types/utils/ref-counted-map.d.ts.map +0 -1
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var serialization_exports = {};
|
|
21
|
-
__export(serialization_exports, {
|
|
22
|
-
deserializeControl: () => deserializeControl,
|
|
23
|
-
deserializeControls: () => deserializeControls,
|
|
24
|
-
serializeControl: () => serializeControl,
|
|
25
|
-
serializeControls: () => serializeControls
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(serialization_exports);
|
|
28
|
-
var import_controls = require("@makeswift/controls");
|
|
29
|
-
var import_serialization = require("../prop-controllers/serialization");
|
|
30
|
-
var import_descriptors = require("../prop-controllers/descriptors");
|
|
31
|
-
var import_base = require("../controls/serialization/base");
|
|
32
|
-
var import_message_port = require("../controls/serialization/message-port");
|
|
33
|
-
var import_serialization2 = require("../controls/serialization");
|
|
34
|
-
__reExport(serialization_exports, require("../prop-controllers/serialization"), module.exports);
|
|
35
|
-
function serializeControl(control) {
|
|
36
|
-
if ((0, import_descriptors.isLegacyDescriptor)(control)) {
|
|
37
|
-
return (0, import_serialization.serializeLegacyControl)(control);
|
|
38
|
-
}
|
|
39
|
-
const messagePortVisitor = new import_message_port.ClientMessagePortSerializationVisitor();
|
|
40
|
-
const serializedControl = control.accept(messagePortVisitor);
|
|
41
|
-
return [serializedControl, messagePortVisitor.getTransferables()];
|
|
42
|
-
}
|
|
43
|
-
function isSerializedLegacyControl(control) {
|
|
44
|
-
return "options" in control;
|
|
45
|
-
}
|
|
46
|
-
function deserializeControl(serializedControl, options) {
|
|
47
|
-
if (isSerializedLegacyControl(serializedControl)) {
|
|
48
|
-
const record = options?.plugins ? (0, import_controls.deserializeObject)(serializedControl, options?.plugins) : serializedControl;
|
|
49
|
-
return (0, import_serialization.deserializeLegacyControl)(record);
|
|
50
|
-
}
|
|
51
|
-
const plugins = [import_message_port.functionDeserializationPlugin, ...options?.plugins ?? []];
|
|
52
|
-
return (0, import_base.deserializeControl)(serializedControl, { plugins });
|
|
53
|
-
}
|
|
54
|
-
function serializeControls(controls) {
|
|
55
|
-
return Object.entries(controls).reduce(
|
|
56
|
-
([accControls, accTransferables], [key, control]) => {
|
|
57
|
-
const [serializedControl, transferables] = serializeControl(control);
|
|
58
|
-
return [{ ...accControls, [key]: serializedControl }, [...accTransferables, ...transferables]];
|
|
59
|
-
},
|
|
60
|
-
[{}, []]
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
function deserializeControls(serializedControls, { onError, plugins } = {}) {
|
|
64
|
-
return (0, import_serialization2.deserializeControlRecords)(
|
|
65
|
-
serializedControls,
|
|
66
|
-
(serializedControl, options) => deserializeControl(serializedControl, options),
|
|
67
|
-
{ onError, plugins }
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
-
0 && (module.exports = {
|
|
72
|
-
deserializeControl,
|
|
73
|
-
deserializeControls,
|
|
74
|
-
serializeControl,
|
|
75
|
-
serializeControls,
|
|
76
|
-
...require("../prop-controllers/serialization")
|
|
77
|
-
});
|
|
78
|
-
//# sourceMappingURL=serialization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/builder/serialization.ts"],"sourcesContent":["import {\n type Data,\n ControlDefinition as UnifiedControlDefinition,\n type SerializedRecord,\n DeserializationPlugin,\n deserializeObject,\n} from '@makeswift/controls'\n\nimport {\n type SerializedLegacyControl,\n type DeserializedLegacyControl,\n serializeLegacyControl,\n deserializeLegacyControl,\n} from '../prop-controllers/serialization'\n\nimport { type Descriptor, isLegacyDescriptor } from '../prop-controllers/descriptors'\n\nimport { deserializeControl as deserializeUnifiedControl } from '../controls/serialization/base'\nimport {\n type DeserializedFunction,\n type SerializedFunction,\n ClientMessagePortSerializationVisitor,\n functionDeserializationPlugin,\n} from '../controls/serialization/message-port'\n\nimport {\n type DeserializeControlRecordsOptions,\n deserializeControlRecords,\n} from '../controls/serialization'\n\nexport * from '../prop-controllers/serialization'\n\nexport type SerializedControl<T extends Data = Data> = SerializedLegacyControl<T> | SerializedRecord\n\nexport type DeserializedControl<T extends Data = Data> =\n | DeserializedLegacyControl<T>\n | UnifiedControlDefinition\n\nexport function serializeControl<T extends Data>(\n control: Descriptor<T>,\n): [SerializedControl<T>, Transferable[]] {\n if (isLegacyDescriptor(control)) {\n return serializeLegacyControl(control)\n }\n\n const messagePortVisitor = new ClientMessagePortSerializationVisitor()\n const serializedControl = control.accept(messagePortVisitor)\n return [serializedControl, messagePortVisitor.getTransferables()]\n}\n\nfunction isSerializedLegacyControl<T extends Data>(\n control: SerializedControl<T>,\n): control is SerializedLegacyControl<T> {\n return 'options' in control\n}\n\nexport type DeserializeControlOptions = {\n plugins?: DeserializationPlugin<any>[]\n}\n\nexport function deserializeControl<T extends Data>(\n serializedControl: SerializedControl<T>,\n options?: DeserializeControlOptions,\n): DeserializedControl<T> {\n if (isSerializedLegacyControl(serializedControl)) {\n // Parity with controls deserialization logic below: \"preprocess\" serialized\n // legacy controls if the caller provided custom deserialization plugins\n const record = options?.plugins\n ? deserializeObject(serializedControl, options?.plugins)\n : serializedControl\n return deserializeLegacyControl(record as SerializedLegacyControl<T>)\n }\n\n const plugins = [functionDeserializationPlugin, ...(options?.plugins ?? [])]\n return deserializeUnifiedControl(serializedControl, { plugins })\n}\n\nexport function serializeControls(\n controls: Record<string, Descriptor>,\n): [Record<string, SerializedControl>, Transferable[]] {\n return Object.entries(controls).reduce(\n ([accControls, accTransferables], [key, control]) => {\n const [serializedControl, transferables] = serializeControl(control)\n\n return [{ ...accControls, [key]: serializedControl }, [...accTransferables, ...transferables]]\n },\n [{}, []] as [Record<string, SerializedControl>, Transferable[]],\n )\n}\n\nexport function deserializeControls(\n serializedControls: Record<string, unknown>,\n { onError, plugins }: DeserializeControlRecordsOptions = {},\n): Record<string, DeserializedControl> {\n return deserializeControlRecords<DeserializedControl>(\n serializedControls,\n (serializedControl, options) => deserializeControl(serializedControl, options),\n { onError, plugins },\n )\n}\n\ntype AnyFunction = (...args: any[]) => any\n\nexport type Serialize<T> = T extends AnyFunction\n ? SerializedFunction<T>\n : T extends Record<string, unknown>\n ? { [K in keyof T]: Serialize<T[K]> }\n : T\n\nexport type Deserialize<T> =\n T extends SerializedFunction<infer U>\n ? DeserializedFunction<U>\n : T extends Record<string, unknown>\n ? { [K in keyof T]: Deserialize<T[K]> }\n : T\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAMO;AAEP,2BAKO;AAEP,yBAAoD;AAEpD,kBAAgE;AAChE,0BAKO;AAEP,IAAAA,wBAGO;AAEP,kCAAc,8CA9Bd;AAsCO,SAAS,iBACd,SACwC;AACxC,UAAI,uCAAmB,OAAO,GAAG;AAC/B,eAAO,6CAAuB,OAAO;AAAA,EACvC;AAEA,QAAM,qBAAqB,IAAI,0DAAsC;AACrE,QAAM,oBAAoB,QAAQ,OAAO,kBAAkB;AAC3D,SAAO,CAAC,mBAAmB,mBAAmB,iBAAiB,CAAC;AAClE;AAEA,SAAS,0BACP,SACuC;AACvC,SAAO,aAAa;AACtB;AAMO,SAAS,mBACd,mBACA,SACwB;AACxB,MAAI,0BAA0B,iBAAiB,GAAG;AAGhD,UAAM,SAAS,SAAS,cACpB,mCAAkB,mBAAmB,SAAS,OAAO,IACrD;AACJ,eAAO,+CAAyB,MAAoC;AAAA,EACtE;AAEA,QAAM,UAAU,CAAC,mDAA+B,GAAI,SAAS,WAAW,CAAC,CAAE;AAC3E,aAAO,YAAAC,oBAA0B,mBAAmB,EAAE,QAAQ,CAAC;AACjE;AAEO,SAAS,kBACd,UACqD;AACrD,SAAO,OAAO,QAAQ,QAAQ,EAAE;AAAA,IAC9B,CAAC,CAAC,aAAa,gBAAgB,GAAG,CAAC,KAAK,OAAO,MAAM;AACnD,YAAM,CAAC,mBAAmB,aAAa,IAAI,iBAAiB,OAAO;AAEnE,aAAO,CAAC,EAAE,GAAG,aAAa,CAAC,GAAG,GAAG,kBAAkB,GAAG,CAAC,GAAG,kBAAkB,GAAG,aAAa,CAAC;AAAA,IAC/F;AAAA,IACA,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,EACT;AACF;AAEO,SAAS,oBACd,oBACA,EAAE,SAAS,QAAQ,IAAsC,CAAC,GACrB;AACrC,aAAO;AAAA,IACL;AAAA,IACA,CAAC,mBAAmB,YAAY,mBAAmB,mBAAmB,OAAO;AAAA,IAC7E,EAAE,SAAS,QAAQ;AAAA,EACrB;AACF;","names":["import_serialization","deserializeUnifiedControl"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var builtin_exports = {};
|
|
31
|
-
__export(builtin_exports, {
|
|
32
|
-
Box: () => import_Box.default,
|
|
33
|
-
Button: () => import_Button.default,
|
|
34
|
-
Carousel: () => import_Carousel.default,
|
|
35
|
-
Countdown: () => import_Countdown.default,
|
|
36
|
-
Divider: () => import_Divider.default,
|
|
37
|
-
Embed: () => import_Embed.default,
|
|
38
|
-
Form: () => import_Form.default,
|
|
39
|
-
Image: () => import_Image.default,
|
|
40
|
-
MakeswiftComponentType: () => import_constants.MakeswiftComponentType,
|
|
41
|
-
Navigation: () => import_Navigation.default,
|
|
42
|
-
Root: () => import_Root.default,
|
|
43
|
-
Slot: () => import_Slot.default,
|
|
44
|
-
SocialLinks: () => import_SocialLinks.default,
|
|
45
|
-
Text: () => import_Text.default,
|
|
46
|
-
Video: () => import_Video.default
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(builtin_exports);
|
|
49
|
-
__reExport(builtin_exports, require("./Box"), module.exports);
|
|
50
|
-
var import_Box = __toESM(require("./Box"));
|
|
51
|
-
var import_Button = __toESM(require("./Button"));
|
|
52
|
-
var import_Carousel = __toESM(require("./Carousel"));
|
|
53
|
-
var import_Countdown = __toESM(require("./Countdown"));
|
|
54
|
-
var import_Divider = __toESM(require("./Divider"));
|
|
55
|
-
var import_Embed = __toESM(require("./Embed"));
|
|
56
|
-
var import_Form = __toESM(require("./Form"));
|
|
57
|
-
var import_Image = __toESM(require("./Image"));
|
|
58
|
-
var import_Navigation = __toESM(require("./Navigation"));
|
|
59
|
-
var import_Root = __toESM(require("./Root"));
|
|
60
|
-
var import_Slot = __toESM(require("./Slot"));
|
|
61
|
-
var import_SocialLinks = __toESM(require("./SocialLinks"));
|
|
62
|
-
var import_Text = __toESM(require("./Text"));
|
|
63
|
-
var import_Video = __toESM(require("./Video"));
|
|
64
|
-
var import_constants = require("./constants");
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 && (module.exports = {
|
|
67
|
-
Box,
|
|
68
|
-
Button,
|
|
69
|
-
Carousel,
|
|
70
|
-
Countdown,
|
|
71
|
-
Divider,
|
|
72
|
-
Embed,
|
|
73
|
-
Form,
|
|
74
|
-
Image,
|
|
75
|
-
MakeswiftComponentType,
|
|
76
|
-
Navigation,
|
|
77
|
-
Root,
|
|
78
|
-
Slot,
|
|
79
|
-
SocialLinks,
|
|
80
|
-
Text,
|
|
81
|
-
Video,
|
|
82
|
-
...require("./Box")
|
|
83
|
-
});
|
|
84
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/builtin/index.ts"],"sourcesContent":["export * from './Box'\nexport { default as Box } from './Box'\nexport { default as Button } from './Button'\nexport { default as Carousel } from './Carousel'\nexport { default as Countdown } from './Countdown'\nexport { default as Divider } from './Divider'\nexport { default as Embed } from './Embed'\nexport { default as Form } from './Form'\nexport { default as Image } from './Image'\nexport { default as Navigation } from './Navigation'\nexport { default as Root } from './Root'\nexport { default as Slot } from './Slot'\nexport { default as SocialLinks } from './SocialLinks'\nexport { default as Text } from './Text'\nexport { default as Video } from './Video'\n\nexport { MakeswiftComponentType } from './constants'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAc,kBAAd;AACA,iBAA+B;AAC/B,oBAAkC;AAClC,sBAAoC;AACpC,uBAAqC;AACrC,qBAAmC;AACnC,mBAAiC;AACjC,kBAAgC;AAChC,mBAAiC;AACjC,wBAAsC;AACtC,kBAAgC;AAChC,kBAAgC;AAChC,yBAAuC;AACvC,kBAAgC;AAChC,mBAAiC;AAEjC,uBAAuC;","names":[]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var components_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(components_exports);
|
|
18
|
-
__reExport(components_exports, require("./builtin"), module.exports);
|
|
19
|
-
__reExport(components_exports, require("./hooks"), module.exports);
|
|
20
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
-
0 && (module.exports = {
|
|
22
|
-
...require("./builtin"),
|
|
23
|
-
...require("./hooks")
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from './builtin'\nexport * from './hooks'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,sBAAd;AACA,+BAAc,oBADd;","names":[]}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var translation_exports = {};
|
|
30
|
-
__export(translation_exports, {
|
|
31
|
-
getTranslatableData: () => getTranslatableData,
|
|
32
|
-
mergeTranslatedNodes: () => mergeTranslatedNodes
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(translation_exports);
|
|
35
|
-
var import_escape_html = __toESM(require("escape-html"));
|
|
36
|
-
var import_slate = require("slate");
|
|
37
|
-
var import_slate_hyperscript = require("slate-hyperscript");
|
|
38
|
-
var import_parse5 = require("parse5");
|
|
39
|
-
var import_controls = require("@makeswift/controls");
|
|
40
|
-
var import_types = require("../../slate/types");
|
|
41
|
-
function createEditorWithPlugins(plugins) {
|
|
42
|
-
return plugins.reduceRight(
|
|
43
|
-
(editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,
|
|
44
|
-
(0, import_slate.createEditor)()
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
function pathToString(path) {
|
|
48
|
-
return path.join(":");
|
|
49
|
-
}
|
|
50
|
-
function stringToPath(s) {
|
|
51
|
-
return s.split(":").map((a) => parseInt(a));
|
|
52
|
-
}
|
|
53
|
-
function getDescendantTranslatableData(descendant, path) {
|
|
54
|
-
if (import_slate.Text.isText(descendant)) {
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
|
-
if (import_controls.Slate.isList(descendant) || import_controls.Slate.isListItem(descendant)) {
|
|
58
|
-
return descendant.children.reduce(
|
|
59
|
-
(acc, d, j) => ({ ...acc, ...getDescendantTranslatableData(d, [...path, j]) }),
|
|
60
|
-
{}
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
const text = getInlineOrTextTranslatableData(descendant);
|
|
64
|
-
if (text == null)
|
|
65
|
-
return {};
|
|
66
|
-
return { [pathToString(path)]: text };
|
|
67
|
-
}
|
|
68
|
-
function getInlineOrTextTranslatableData(descendant, path = []) {
|
|
69
|
-
if (import_slate.Text.isText(descendant)) {
|
|
70
|
-
let string = (0, import_escape_html.default)(descendant.text);
|
|
71
|
-
if (string === "")
|
|
72
|
-
return null;
|
|
73
|
-
if (descendant.typography === void 0)
|
|
74
|
-
return string;
|
|
75
|
-
return `<span key="${pathToString(path)}">${string}</span>`;
|
|
76
|
-
}
|
|
77
|
-
const children = descendant.children.map((child, i) => getInlineOrTextTranslatableData(child, [...path, i])).join("");
|
|
78
|
-
if (children === "")
|
|
79
|
-
return null;
|
|
80
|
-
switch (descendant.type) {
|
|
81
|
-
case import_types.InlineType.Link:
|
|
82
|
-
return `<a key="${pathToString(path)}">${children}</a>`;
|
|
83
|
-
case import_types.InlineType.SuperScript:
|
|
84
|
-
return `<sup key="${pathToString(path)}">${children}</sup>`;
|
|
85
|
-
case import_types.InlineType.SubScript:
|
|
86
|
-
return `<sub key="${pathToString(path)}">${children}</sub>`;
|
|
87
|
-
case import_types.InlineType.Code:
|
|
88
|
-
return `<code key="${pathToString(path)}">${children}</code>`;
|
|
89
|
-
default:
|
|
90
|
-
return children;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function getTranslatableData(nodes, plugins) {
|
|
94
|
-
const editor = createEditorWithPlugins(plugins);
|
|
95
|
-
editor.children = nodes;
|
|
96
|
-
editor.typographyNormalizationDirection = "up";
|
|
97
|
-
import_slate.Editor.normalize(editor, { force: true });
|
|
98
|
-
return editor.children.reduce(
|
|
99
|
-
(acc, descendant, i) => ({
|
|
100
|
-
...acc,
|
|
101
|
-
...getDescendantTranslatableData(descendant, [i])
|
|
102
|
-
}),
|
|
103
|
-
{}
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
function deserializeTranslationHtmlString(el, translationKey) {
|
|
107
|
-
if (el.nodeName === "#document-fragment") {
|
|
108
|
-
const children = Array.from(el.childNodes).map((element) => deserializeTranslationHtmlString(element)).flat();
|
|
109
|
-
if (children.length === 0) {
|
|
110
|
-
children.push((0, import_slate_hyperscript.jsx)("text", {}, ""));
|
|
111
|
-
}
|
|
112
|
-
return children;
|
|
113
|
-
}
|
|
114
|
-
if (el.nodeName === "#text" && "value" in el) {
|
|
115
|
-
return [(0, import_slate_hyperscript.jsx)("text", { translationKey: translationKey ?? void 0 }, el.value)];
|
|
116
|
-
}
|
|
117
|
-
if ("namespaceURI" in el) {
|
|
118
|
-
const translationKey2 = el.attrs.find((a) => a.name === "key")?.value ?? void 0;
|
|
119
|
-
const children = Array.from(el.childNodes).map((element) => deserializeTranslationHtmlString(element, translationKey2)).flat();
|
|
120
|
-
if (children.length === 0) {
|
|
121
|
-
children.push((0, import_slate_hyperscript.jsx)("text", {}, ""));
|
|
122
|
-
}
|
|
123
|
-
switch (el.nodeName) {
|
|
124
|
-
case "code":
|
|
125
|
-
return [(0, import_slate_hyperscript.jsx)("element", { type: import_types.InlineType.Code, translationKey: translationKey2 }, children)];
|
|
126
|
-
case "sub":
|
|
127
|
-
return [(0, import_slate_hyperscript.jsx)("element", { type: import_types.InlineType.SubScript, translationKey: translationKey2 }, children)];
|
|
128
|
-
case "sup":
|
|
129
|
-
return [(0, import_slate_hyperscript.jsx)("element", { type: import_types.InlineType.SuperScript, translationKey: translationKey2 }, children)];
|
|
130
|
-
case "a":
|
|
131
|
-
return [(0, import_slate_hyperscript.jsx)("element", { type: import_types.InlineType.Link, translationKey: translationKey2 }, children)];
|
|
132
|
-
default:
|
|
133
|
-
return children;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
function mergeTranslatedNodes(nodes, translatedData, plugins) {
|
|
139
|
-
const sourceEditor = createEditorWithPlugins(plugins);
|
|
140
|
-
const targetEditor = createEditorWithPlugins(plugins);
|
|
141
|
-
sourceEditor.children = nodes;
|
|
142
|
-
sourceEditor.typographyNormalizationDirection = "up";
|
|
143
|
-
import_slate.Editor.normalize(sourceEditor, { force: true });
|
|
144
|
-
Object.entries(translatedData).reverse().forEach(([blockStringPath, htmlString]) => {
|
|
145
|
-
const blockPath = stringToPath(blockStringPath);
|
|
146
|
-
if (blockPath.length === 0)
|
|
147
|
-
return;
|
|
148
|
-
const html = (0, import_parse5.parseFragment)(htmlString);
|
|
149
|
-
const inlineDescendants = deserializeTranslationHtmlString(html);
|
|
150
|
-
targetEditor.children = [{ type: import_types.BlockType.Default, children: inlineDescendants }];
|
|
151
|
-
targetEditor.typographyNormalizationDirection = "neutral";
|
|
152
|
-
import_slate.Editor.normalize(targetEditor, { force: true });
|
|
153
|
-
for (const [descendant, absolutePathToTargetNode] of import_slate.Node.descendants(targetEditor)) {
|
|
154
|
-
if (!import_slate.Text.isText(descendant) && !import_controls.Slate.isInline(descendant) || descendant.translationKey == null || descendant.translationKey === "") {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const relativePathToSourceNode = stringToPath(descendant.translationKey);
|
|
158
|
-
const absolutePathToSourceNode = [...blockPath, ...relativePathToSourceNode];
|
|
159
|
-
const [sourceNode] = import_slate.Editor.node(sourceEditor, absolutePathToSourceNode);
|
|
160
|
-
if (import_slate.Text.isText(sourceNode) && import_slate.Text.isText(descendant)) {
|
|
161
|
-
const { translationKey, text, ...rest } = sourceNode;
|
|
162
|
-
import_slate.Transforms.setNodes(targetEditor, rest, { at: absolutePathToTargetNode });
|
|
163
|
-
import_slate.Transforms.unsetNodes(targetEditor, "translationKey", { at: absolutePathToTargetNode });
|
|
164
|
-
} else if (import_controls.Slate.isInline(sourceNode) && import_controls.Slate.isInline(descendant)) {
|
|
165
|
-
const { translationKey, children, ...rest } = sourceNode;
|
|
166
|
-
import_slate.Transforms.setNodes(targetEditor, rest, { at: absolutePathToTargetNode });
|
|
167
|
-
import_slate.Transforms.unsetNodes(targetEditor, "translationKey", { at: absolutePathToTargetNode });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const translatedChildren = targetEditor.children.at(0)?.children;
|
|
171
|
-
import_slate.Editor.withoutNormalizing(sourceEditor, () => {
|
|
172
|
-
Array.from(import_slate.Node.children(sourceEditor, blockPath)).reverse().forEach(([_, path]) => {
|
|
173
|
-
import_slate.Transforms.removeNodes(sourceEditor, { at: path });
|
|
174
|
-
});
|
|
175
|
-
import_slate.Transforms.insertNodes(sourceEditor, translatedChildren, { at: [...blockPath, 0] });
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
sourceEditor.typographyNormalizationDirection = "down";
|
|
179
|
-
import_slate.Editor.normalize(sourceEditor, { force: true });
|
|
180
|
-
return sourceEditor.children;
|
|
181
|
-
}
|
|
182
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
-
0 && (module.exports = {
|
|
184
|
-
getTranslatableData,
|
|
185
|
-
mergeTranslatedNodes
|
|
186
|
-
});
|
|
187
|
-
//# sourceMappingURL=translation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/controls/rich-text-v2/translation.ts"],"sourcesContent":["import escapeHtml from 'escape-html'\nimport { Descendant, Editor, Element, Node, Text, Transforms, createEditor } from 'slate'\nimport { jsx } from 'slate-hyperscript'\nimport { parseFragment } from 'parse5'\nimport { ChildNode, DocumentFragment } from 'parse5/dist/tree-adapters/default'\n\nimport { type TranslationDto, Slate } from '@makeswift/controls'\n\nimport { RichTextV2Plugin } from './plugin'\nimport { type MakeswiftEditor, BlockType, InlineType } from '../../slate/types'\n\nfunction createEditorWithPlugins(plugins: RichTextV2Plugin[]): MakeswiftEditor {\n return plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n createEditor(),\n )\n}\n\nfunction pathToString(path: number[]): string {\n return path.join(':')\n}\n\nfunction stringToPath(s: string): number[] {\n return s.split(':').map(a => parseInt(a))\n}\n\nfunction getDescendantTranslatableData(descendant: Descendant, path: number[]): TranslationDto {\n if (Text.isText(descendant)) {\n return {}\n }\n\n if (Slate.isList(descendant) || Slate.isListItem(descendant)) {\n return descendant.children.reduce(\n (acc, d, j) => ({ ...acc, ...getDescendantTranslatableData(d, [...path, j]) }),\n {},\n )\n }\n\n const text = getInlineOrTextTranslatableData(descendant)\n if (text == null) return {}\n\n return { [pathToString(path)]: text }\n}\n\nfunction getInlineOrTextTranslatableData(\n descendant: Descendant,\n path: number[] = [],\n): string | null {\n if (Text.isText(descendant)) {\n let string = escapeHtml(descendant.text)\n\n if (string === '') return null\n\n if (descendant.typography === undefined) return string\n\n return `<span key=\"${pathToString(path)}\">${string}</span>`\n }\n\n const children = descendant.children\n .map((child: Descendant, i: number) => getInlineOrTextTranslatableData(child, [...path, i]))\n .join('')\n\n if (children === '') return null\n\n switch (descendant.type) {\n case InlineType.Link:\n return `<a key=\"${pathToString(path)}\">${children}</a>`\n\n case InlineType.SuperScript:\n return `<sup key=\"${pathToString(path)}\">${children}</sup>`\n\n case InlineType.SubScript:\n return `<sub key=\"${pathToString(path)}\">${children}</sub>`\n\n case InlineType.Code:\n return `<code key=\"${pathToString(path)}\">${children}</code>`\n\n default:\n return children\n }\n}\n\nexport type RichTextTranslationDto = Record<string, string>\n\nexport function getTranslatableData(\n nodes: Slate.Descendant[],\n plugins: RichTextV2Plugin[],\n): RichTextTranslationDto {\n const editor = createEditorWithPlugins(plugins)\n\n editor.children = nodes\n editor.typographyNormalizationDirection = 'up'\n Editor.normalize(editor, { force: true })\n\n return editor.children.reduce(\n (acc, descendant: Descendant, i) => ({\n ...acc,\n ...getDescendantTranslatableData(descendant, [i]),\n }),\n {},\n )\n}\n\nfunction deserializeTranslationHtmlString(\n el: ChildNode | DocumentFragment,\n translationKey?: string,\n): Descendant[] {\n if (el.nodeName === '#document-fragment') {\n const children = Array.from(el.childNodes)\n .map(element => deserializeTranslationHtmlString(element))\n .flat()\n\n if (children.length === 0) {\n children.push(jsx('text', {}, ''))\n }\n\n return children\n }\n\n if (el.nodeName === '#text' && 'value' in el) {\n return [jsx('text', { translationKey: translationKey ?? undefined }, el.value)]\n }\n\n if ('namespaceURI' in el) {\n const translationKey = el.attrs.find(a => a.name === 'key')?.value ?? undefined\n const children = Array.from(el.childNodes)\n .map(element => deserializeTranslationHtmlString(element, translationKey))\n .flat()\n\n if (children.length === 0) {\n children.push(jsx('text', {}, ''))\n }\n\n switch (el.nodeName) {\n case 'code':\n return [jsx('element', { type: InlineType.Code, translationKey }, children)]\n\n case 'sub':\n return [jsx('element', { type: InlineType.SubScript, translationKey }, children)]\n\n case 'sup':\n return [jsx('element', { type: InlineType.SuperScript, translationKey }, children)]\n\n case 'a':\n return [jsx('element', { type: InlineType.Link, translationKey }, children)]\n\n default:\n return children\n }\n }\n\n return []\n}\n\nexport function mergeTranslatedNodes(\n nodes: Slate.Descendant[],\n translatedData: RichTextTranslationDto,\n plugins: RichTextV2Plugin[],\n): Slate.Descendant[] {\n const sourceEditor = createEditorWithPlugins(plugins)\n const targetEditor = createEditorWithPlugins(plugins)\n\n sourceEditor.children = nodes\n sourceEditor.typographyNormalizationDirection = 'up'\n Editor.normalize(sourceEditor, { force: true })\n\n Object.entries(translatedData)\n .reverse()\n .forEach(([blockStringPath, htmlString]) => {\n const blockPath = stringToPath(blockStringPath)\n if (blockPath.length === 0) return\n\n const html = parseFragment(htmlString)\n const inlineDescendants = deserializeTranslationHtmlString(html)\n\n targetEditor.children = [{ type: BlockType.Default, children: inlineDescendants }]\n\n targetEditor.typographyNormalizationDirection = 'neutral'\n Editor.normalize(targetEditor, { force: true })\n\n for (const [descendant, absolutePathToTargetNode] of Node.descendants(targetEditor)) {\n if (\n (!Text.isText(descendant) && !Slate.isInline(descendant)) ||\n descendant.translationKey == null ||\n descendant.translationKey === ''\n ) {\n continue\n }\n\n const relativePathToSourceNode = stringToPath(descendant.translationKey)\n\n const absolutePathToSourceNode = [...blockPath, ...relativePathToSourceNode]\n\n const [sourceNode] = Editor.node(sourceEditor, absolutePathToSourceNode)\n\n if (Text.isText(sourceNode) && Text.isText(descendant)) {\n const { translationKey, text, ...rest } = sourceNode\n Transforms.setNodes(targetEditor, rest, { at: absolutePathToTargetNode })\n Transforms.unsetNodes(targetEditor, 'translationKey', { at: absolutePathToTargetNode })\n } else if (Slate.isInline(sourceNode) && Slate.isInline(descendant)) {\n const { translationKey, children, ...rest } = sourceNode\n Transforms.setNodes(targetEditor, rest, { at: absolutePathToTargetNode })\n Transforms.unsetNodes(targetEditor, 'translationKey', { at: absolutePathToTargetNode })\n }\n }\n const translatedChildren = (targetEditor.children.at(0) as Element)?.children\n\n Editor.withoutNormalizing(sourceEditor, () => {\n Array.from(Node.children(sourceEditor, blockPath))\n .reverse()\n .forEach(([_, path]) => {\n Transforms.removeNodes(sourceEditor, { at: path })\n })\n\n Transforms.insertNodes(sourceEditor, translatedChildren, { at: [...blockPath, 0] })\n })\n })\n\n sourceEditor.typographyNormalizationDirection = 'down'\n Editor.normalize(sourceEditor, { force: true })\n\n return sourceEditor.children\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,mBAAkF;AAClF,+BAAoB;AACpB,oBAA8B;AAG9B,sBAA2C;AAG3C,mBAA4D;AAE5D,SAAS,wBAAwB,SAA8C;AAC7E,SAAO,QAAQ;AAAA,IACb,CAAC,QAAQ,WAAW,QAAQ,aAAa,MAAM,KAAK;AAAA,QACpD,2BAAa;AAAA,EACf;AACF;AAEA,SAAS,aAAa,MAAwB;AAC5C,SAAO,KAAK,KAAK,GAAG;AACtB;AAEA,SAAS,aAAa,GAAqB;AACzC,SAAO,EAAE,MAAM,GAAG,EAAE,IAAI,OAAK,SAAS,CAAC,CAAC;AAC1C;AAEA,SAAS,8BAA8B,YAAwB,MAAgC;AAC7F,MAAI,kBAAK,OAAO,UAAU,GAAG;AAC3B,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,sBAAM,OAAO,UAAU,KAAK,sBAAM,WAAW,UAAU,GAAG;AAC5D,WAAO,WAAW,SAAS;AAAA,MACzB,CAAC,KAAK,GAAG,OAAO,E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I,yBAAyB,CAAC;AAAA,MACxF,WAAW,sBAAM,SAAS,UAAU,KAAK,sBAAM,SAAS,UAAU,GAAG;AACnE,cAAM,EAAE,gBAAgB,UAAU,GAAG,KAAK,IAAI;AAC9C,gCAAW,SAAS,cAAc,MAAM,EAAE,IAAI,yBAAyB,CAAC;AACxE,gCAAW,WAAW,cAAc,kBAAkB,EAAE,IAAI,yBAAyB,CAAC;AAAA,MACxF;AAAA,IACF;AACA,UAAM,qBAAsB,aAAa,SAAS,GAAG,CAAC,GAAe;AAErE,wBAAO,mBAAmB,cAAc,MAAM;AAC5C,YAAM,KAAK,kBAAK,SAAS,cAAc,SAAS,CAAC,EAC9C,QAAQ,EACR,QAAQ,CAAC,CAAC,GAAG,IAAI,MAAM;AACtB,gCAAW,YAAY,cAAc,EAAE,IAAI,KAAK,CAAC;AAAA,MACnD,CAAC;AAEH,8BAAW,YAAY,cAAc,oBAAoB,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC;AAAA,IACpF,CAAC;AAAA,EACH,CAAC;AAEH,eAAa,mCAAmC;AAChD,sBAAO,UAAU,cAAc,EAAE,OAAO,KAAK,CAAC;AAE9C,SAAO,aAAa;AACtB;","names":["escapeHtml","translationKey"]}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var base_exports = {};
|
|
20
|
-
__export(base_exports, {
|
|
21
|
-
deserializeControl: () => deserializeControl,
|
|
22
|
-
deserializeUnifiedControlDef: () => deserializeUnifiedControlDef,
|
|
23
|
-
serializeControls: () => serializeControls
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(base_exports);
|
|
26
|
-
var import_controls = require("@makeswift/controls");
|
|
27
|
-
var import__ = require("../../index");
|
|
28
|
-
function serializeControls(controls, visitor) {
|
|
29
|
-
return Object.entries(controls).reduce(
|
|
30
|
-
(acc, [key, control]) => {
|
|
31
|
-
return { ...acc, [key]: control.accept(visitor) };
|
|
32
|
-
},
|
|
33
|
-
{}
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
function deserializeControl(serializedControl, options) {
|
|
37
|
-
const plugins = options?.plugins ?? [];
|
|
38
|
-
return deserializeUnifiedControlDef((0, import_controls.deserializeRecord)(serializedControl, plugins));
|
|
39
|
-
}
|
|
40
|
-
function deserializeUnifiedControlDef(record) {
|
|
41
|
-
const deserializeMethod = {
|
|
42
|
-
[import__.CheckboxDefinition.type]: import__.CheckboxDefinition.deserialize,
|
|
43
|
-
[import__.CodeDefinition.type]: import__.CodeDefinition.deserialize,
|
|
44
|
-
[import__.ColorDefinition.type]: import__.ColorDefinition.deserialize,
|
|
45
|
-
[import__.ComboboxDefinition.type]: import__.ComboboxDefinition.deserialize,
|
|
46
|
-
[import__.FontDefinition.type]: import__.FontDefinition.deserialize,
|
|
47
|
-
[import__.GroupDefinition.type]: (record2) => import__.GroupDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
48
|
-
[import__.IconRadioGroupDefinition.type]: import__.IconRadioGroupDefinition.deserialize,
|
|
49
|
-
[import__.ImageDefinition.type]: import__.ImageDefinition.deserialize,
|
|
50
|
-
[import__.LinkDefinition.type]: import__.LinkDefinition.deserialize,
|
|
51
|
-
[import__.ListDefinition.type]: (record2) => import__.ListDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
52
|
-
[import__.NumberDefinition.type]: import__.NumberDefinition.deserialize,
|
|
53
|
-
[import__.RichTextV1Definition.type]: import__.RichTextV1Definition.deserialize,
|
|
54
|
-
[import__.RichTextV2Definition.type]: (record2) => import__.RichTextV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
55
|
-
[import__.SelectDefinition.type]: import__.SelectDefinition.deserialize,
|
|
56
|
-
[import__.ShapeDefinition.type]: (record2) => import__.ShapeDefinition.deserialize(record2, deserializeUnifiedControlDef),
|
|
57
|
-
[import__.SliderDefinition.type]: import__.SliderDefinition.deserialize,
|
|
58
|
-
[import_controls.ShapeV2Definition.type]: (record2) => import_controls.ShapeV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
59
|
-
[import__.SlotDefinition.type]: import__.SlotDefinition.deserialize,
|
|
60
|
-
[import__.StyleDefinition.type]: import__.StyleDefinition.deserialize,
|
|
61
|
-
[import__.StyleV2Definition.type]: (record2) => import__.StyleV2Definition.deserialize(record2, deserializeUnifiedControlDef),
|
|
62
|
-
[import__.TextAreaDefinition.type]: import__.TextAreaDefinition.deserialize,
|
|
63
|
-
[import__.TextInputDefinition.type]: import__.TextInputDefinition.deserialize,
|
|
64
|
-
[import__.unstable_TypographyDefinition.type]: import__.unstable_TypographyDefinition.deserialize
|
|
65
|
-
};
|
|
66
|
-
const deserialize = deserializeMethod[record.type] ?? null;
|
|
67
|
-
if (deserialize == null) {
|
|
68
|
-
throw new Error(`Unknown control type: ${record.type}`);
|
|
69
|
-
}
|
|
70
|
-
return deserialize(record);
|
|
71
|
-
}
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
deserializeControl,
|
|
75
|
-
deserializeUnifiedControlDef,
|
|
76
|
-
serializeControls
|
|
77
|
-
});
|
|
78
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/controls/serialization/base/index.ts"],"sourcesContent":["import {\n ControlDefinition,\n type SerializedRecord,\n type DeserializedRecord,\n ShapeV2Definition,\n DeserializationPlugin,\n deserializeRecord,\n} from '@makeswift/controls'\n\nimport {\n CheckboxDefinition,\n CodeDefinition,\n ColorDefinition,\n ComboboxDefinition,\n FontDefinition,\n GroupDefinition,\n IconRadioGroupDefinition,\n ImageDefinition,\n LinkDefinition,\n ListDefinition,\n NumberDefinition,\n RichTextV1Definition,\n RichTextV2Definition,\n SelectDefinition,\n ShapeDefinition,\n SliderDefinition,\n SlotDefinition,\n StyleDefinition,\n StyleV2Definition,\n TextAreaDefinition,\n TextInputDefinition,\n unstable_TypographyDefinition,\n} from '../../index'\n\nimport { BaseControlSerializationVisitor } from './visitor'\n\nexport { type SerializedRecord, type DeserializedRecord } from '@makeswift/controls'\n\nexport function serializeControls(\n controls: Record<string, ControlDefinition>,\n visitor: BaseControlSerializationVisitor,\n): Record<string, SerializedRecord> {\n return Object.entries(controls).reduce<Record<string, SerializedRecord>>(\n (acc, [key, control]) => {\n return { ...acc, [key]: control.accept(visitor) }\n },\n {},\n )\n}\n\nexport type DeserializeControlOptions = {\n plugins: DeserializationPlugin<any>[]\n}\n\nexport function deserializeControl(\n serializedControl: SerializedRecord,\n options: DeserializeControlOptions,\n): ControlDefinition {\n const plugins = options?.plugins ?? []\n\n return deserializeUnifiedControlDef(deserializeRecord(serializedControl, plugins))\n}\n\nexport function deserializeUnifiedControlDef(record: DeserializedRecord): ControlDefinition {\n type DeserializeMethod = (data: DeserializedRecord) => ControlDefinition\n const deserializeMethod: Record<string, DeserializeMethod> = {\n [CheckboxDefinition.type]: CheckboxDefinition.deserialize,\n [CodeDefinition.type]: CodeDefinition.deserialize,\n [ColorDefinition.type]: ColorDefinition.deserialize,\n [ComboboxDefinition.type]: ComboboxDefinition.deserialize,\n [FontDefinition.type]: FontDefinition.deserialize,\n [GroupDefinition.type]: record =>\n GroupDefinition.deserialize(record, deserializeUnifiedControlDef),\n [IconRadioGroupDefinition.type]: IconRadioGroupDefinition.deserialize,\n [ImageDefinition.type]: ImageDefinition.deserialize,\n [LinkDefinition.type]: LinkDefinition.deserialize,\n [ListDefinition.type]: record =>\n ListDefinition.deserialize(record, deserializeUnifiedControlDef),\n [NumberDefinition.type]: NumberDefinition.deserialize,\n [RichTextV1Definition.type]: RichTextV1Definition.deserialize,\n [RichTextV2Definition.type]: record =>\n RichTextV2Definition.deserialize(record, deserializeUnifiedControlDef),\n [SelectDefinition.type]: SelectDefinition.deserialize,\n [ShapeDefinition.type]: record =>\n ShapeDefinition.deserialize(record, deserializeUnifiedControlDef),\n [SliderDefinition.type]: SliderDefinition.deserialize,\n [ShapeV2Definition.type]: record =>\n ShapeV2Definition.deserialize(record, deserializeUnifiedControlDef),\n [SlotDefinition.type]: SlotDefinition.deserialize,\n [StyleDefinition.type]: StyleDefinition.deserialize,\n [StyleV2Definition.type]: record =>\n StyleV2Definition.deserialize(record, deserializeUnifiedControlDef),\n [TextAreaDefinition.type]: TextAreaDefinition.deserialize,\n [TextInputDefinition.type]: TextInputDefinition.deserialize,\n [unstable_TypographyDefinition.type]: unstable_TypographyDefinition.deserialize,\n } as const\n\n const deserialize = deserializeMethod[record.type] ?? null\n if (deserialize == null) {\n throw new Error(`Unknown control type: ${record.type}`)\n }\n\n return deserialize(record)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AAEP,eAuBO;AAMA,SAAS,kBACd,UACA,SACkC;AAClC,SAAO,OAAO,QAAQ,QAAQ,EAAE;AAAA,IAC9B,CAAC,KAAK,CAAC,KAAK,OAAO,MAAM;AACvB,aAAO,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YAAYA,SAAQ,4BAA4B;AAAA,IACpE,CAAC,wBAAe,IAAI,GAAG,wBAAe;AAAA,IACtC,CAAC,yBAAgB,IAAI,GAAG,yBAAgB;AAAA,IACxC,CAAC,2BAAkB,IAAI,GAAG,CAAAA,YACxB,2BAAkB,YAAYA,SAAQ,4BAA4B;AAAA,IACpE,CAAC,4BAAmB,IAAI,GAAG,4BAAmB;AAAA,IAC9C,CAAC,6BAAoB,IAAI,GAAG,6BAAoB;AAAA,IAChD,CAAC,uCAA8B,IAAI,GAAG,uCAA8B;AAAA,EACtE;AAEA,QAAM,cAAc,kBAAkB,OAAO,IAAI,KAAK;AACtD,MAAI,eAAe,MAAM;AACvB,UAAM,IAAI,MAAM,yBAAyB,OAAO,IAAI,EAAE;AAAA,EACxD;AAEA,SAAO,YAAY,MAAM;AAC3B;","names":["record"]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var visitor_exports = {};
|
|
20
|
-
__export(visitor_exports, {
|
|
21
|
-
BaseControlSerializationVisitor: () => BaseControlSerializationVisitor
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(visitor_exports);
|
|
24
|
-
var import_controls = require("@makeswift/controls");
|
|
25
|
-
var import_rich_text_v2 = require("../../rich-text-v2");
|
|
26
|
-
class BaseControlSerializationVisitor extends import_controls.ControlSerializationVisitor {
|
|
27
|
-
constructor(plugins) {
|
|
28
|
-
const serializeDefinitionPlugin = {
|
|
29
|
-
match: (val) => val instanceof import_controls.ControlDefinition,
|
|
30
|
-
serialize: (val) => val.accept(this)
|
|
31
|
-
};
|
|
32
|
-
super([serializeDefinitionPlugin, ...plugins]);
|
|
33
|
-
}
|
|
34
|
-
visitRichTextV2(def) {
|
|
35
|
-
const { plugins, ...config } = def.config;
|
|
36
|
-
const pluginDefs = plugins.map(
|
|
37
|
-
({ control }) => control ? {
|
|
38
|
-
control: {
|
|
39
|
-
definition: control.definition,
|
|
40
|
-
// FIXME: remove getValue/onChange stubs once we released a version of the builder
|
|
41
|
-
// built against the runtime where these can be optional
|
|
42
|
-
getValue: () => void 0,
|
|
43
|
-
onChange: () => {
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} : {}
|
|
47
|
-
);
|
|
48
|
-
const serialized = (0, import_controls.serializeObject)(
|
|
49
|
-
{ config: { ...config, plugins: pluginDefs } },
|
|
50
|
-
this.serializationPlugins
|
|
51
|
-
);
|
|
52
|
-
return { ...serialized, type: import_rich_text_v2.RichTextV2Definition.type };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
BaseControlSerializationVisitor
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=visitor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/controls/serialization/base/visitor.ts"],"sourcesContent":["import {\n ControlDefinition,\n SerializedRecord,\n serializeObject,\n SerializationPlugin,\n ControlSerializationVisitor,\n} from '@makeswift/controls'\n\nimport { RichTextV2Definition } from '../../rich-text-v2'\n\nexport class BaseControlSerializationVisitor extends ControlSerializationVisitor {\n constructor(plugins: SerializationPlugin<any>[]) {\n const serializeDefinitionPlugin: SerializationPlugin<ControlDefinition> = {\n match: (val: unknown) => val instanceof ControlDefinition,\n serialize: (val: ControlDefinition) => val.accept(this),\n }\n\n super([serializeDefinitionPlugin, ...plugins])\n }\n\n visitRichTextV2(def: RichTextV2Definition): SerializedRecord {\n const { plugins, ...config } = def.config\n\n // serialize only the plugin control definition, if any\n const pluginDefs = plugins.map(({ control }) =>\n control\n ? {\n control: {\n definition: control.definition,\n // FIXME: remove getValue/onChange stubs once we released a version of the builder\n // built against the runtime where these can be optional\n getValue: () => undefined,\n onChange: () => {},\n },\n }\n : {},\n )\n\n const serialized = serializeObject(\n { config: { ...config, plugins: pluginDefs } },\n this.serializationPlugins,\n ) as SerializedRecord\n\n return { ...serialized, type: RichTextV2Definition.type }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAMO;AAEP,0BAAqC;AAE9B,MAAM,wCAAwC,4CAA4B;AAAA,EAC/E,YAAY,SAAqC;AAC/C,UAAM,4BAAoE;AAAA,MACxE,OAAO,CAAC,QAAiB,eAAe;AAAA,MACxC,WAAW,CAAC,QAA2B,IAAI,OAAO,IAAI;AAAA,IACxD;AAEA,UAAM,CAAC,2BAA2B,GAAG,OAAO,CAAC;AAAA,EAC/C;AAAA,EAEA,gBAAgB,KAA6C;AAC3D,UAAM,EAAE,SAAS,GAAG,OAAO,IAAI,IAAI;AAGnC,UAAM,aAAa,QAAQ;AAAA,MAAI,CAAC,EAAE,QAAQ,MACxC,UACI;AAAA,QACE,SAAS;AAAA,UACP,YAAY,QAAQ;AAAA;AAAA;AAAA,UAGpB,UAAU,MAAM;AAAA,UAChB,UAAU,MAAM;AAAA,UAAC;AAAA,QACnB;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAEA,UAAM,iBAAa;AAAA,MACjB,EAAE,QAAQ,EAAE,GAAG,QAAQ,SAAS,WAAW,EAAE;AAAA,MAC7C,KAAK;AAAA,IACP;AAEA,WAAO,EAAE,GAAG,YAAY,MAAM,yCAAqB,KAAK;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var serialization_exports = {};
|
|
20
|
-
__export(serialization_exports, {
|
|
21
|
-
deserializeControlRecords: () => deserializeControlRecords,
|
|
22
|
-
isSerializedRecord: () => isSerializedRecord
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(serialization_exports);
|
|
25
|
-
function isSerializedRecord(r) {
|
|
26
|
-
return r != null && typeof r === "object" && "type" in r && typeof r.type === "string";
|
|
27
|
-
}
|
|
28
|
-
function deserializeControlRecords(serializedControls, deserialize, { onError, plugins } = {}) {
|
|
29
|
-
return Object.entries(serializedControls).reduce(
|
|
30
|
-
(deserializedControls, [key, serializedControl]) => {
|
|
31
|
-
try {
|
|
32
|
-
if (!isSerializedRecord(serializedControl)) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Expected serialized control data, got ${JSON.stringify(serializedControl)}`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
const deserializedControl = deserialize(serializedControl, { plugins });
|
|
38
|
-
return { ...deserializedControls, [key]: deserializedControl };
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const error = err instanceof Error ? new Error(`Could not deserialize control for "${key}": ${err.message}`, {
|
|
41
|
-
cause: err
|
|
42
|
-
}) : new Error(`Could not deserialize control for "${key}", unknown error: ${err}`);
|
|
43
|
-
onError?.(error, { key, serializedControl });
|
|
44
|
-
return deserializedControls;
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
{}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
-
0 && (module.exports = {
|
|
52
|
-
deserializeControlRecords,
|
|
53
|
-
isSerializedRecord
|
|
54
|
-
});
|
|
55
|
-
//# sourceMappingURL=index.js.map
|