@makeswift/runtime 0.26.4-canary.0 → 0.26.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/{client.js → react.js} +4 -4
- package/dist/cjs/api/react.js.map +1 -0
- package/dist/cjs/api-handler/handlers/element-tree.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/api-handler/handlers/merge-translated-data.js.map +1 -1
- package/dist/cjs/api-handler/handlers/translatable-data.js.map +1 -1
- package/dist/cjs/builder/host-to-builder-actions.js +3 -3
- package/dist/cjs/builder/host-to-builder-actions.js.map +1 -1
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/builder/index.js.map +1 -1
- package/dist/cjs/client/index.js +8 -8
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/components/builtin/Box/Box.js +1 -1
- package/dist/cjs/components/builtin/Box/Box.js.map +1 -1
- package/dist/cjs/components/builtin/Form/Form.js +1 -1
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/components/hooks/useTableFormFieldRefs.js +1 -1
- package/dist/cjs/components/hooks/useTableFormFieldRefs.js.map +1 -1
- package/dist/cjs/next/api-handler/config/app-router.js +10 -1
- package/dist/cjs/next/api-handler/config/app-router.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +2 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
- package/dist/cjs/next/components/tests/makeswift-component/fixtures.js +2 -1
- package/dist/cjs/next/components/tests/makeswift-component/fixtures.js.map +1 -1
- package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js +3 -2
- package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
- package/dist/cjs/next/testing/element-data.js +3 -3
- package/dist/cjs/next/testing/element-data.js.map +1 -1
- package/dist/cjs/next/testing/index.js +0 -2
- package/dist/cjs/next/testing/index.js.map +1 -1
- package/dist/cjs/next/testing/page-rendering.js +3 -3
- package/dist/cjs/next/testing/page-rendering.js.map +1 -1
- package/dist/cjs/prop-controllers/descriptors.js.map +1 -1
- package/dist/cjs/prop-controllers/instances.js.map +1 -1
- package/dist/cjs/runtimes/react/components/Document.js +2 -2
- package/dist/cjs/runtimes/react/components/Document.js.map +1 -1
- package/dist/cjs/runtimes/react/components/DocumentRoot.js.map +1 -1
- package/dist/cjs/runtimes/react/components/Element.js +2 -2
- package/dist/cjs/runtimes/react/components/Element.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementReference.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementRegistration.js +2 -2
- package/dist/cjs/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/cjs/runtimes/react/components/MakeswiftComponent.js +2 -2
- package/dist/cjs/runtimes/react/components/MakeswiftComponent.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +3 -3
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/components/page/Page.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +3 -2
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js +2 -2
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls.js +2 -2
- package/dist/cjs/runtimes/react/controls.js.map +1 -1
- package/dist/cjs/runtimes/react/element-imperative-handle.js +1 -1
- package/dist/cjs/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-breakpoints.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-breakpoints.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-builder-edit-mode.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-builder-edit-mode.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-component.js +3 -3
- package/dist/cjs/runtimes/react/hooks/use-component.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-dispatch.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-document.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-document.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-element-id.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-element-id.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-is-in-builder.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-is-in-builder.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/{use-is-read-only.js → use-is-preview.js} +9 -9
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-register-document.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-selector.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-universal-dispatch.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +2 -2
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/runtimes/react/index.js +3 -3
- package/dist/cjs/runtimes/react/index.js.map +1 -1
- package/dist/cjs/runtimes/react/poll-box-model.js +1 -1
- package/dist/cjs/runtimes/react/poll-box-model.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime-core.js +3 -3
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +2 -4
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/utils/can-accept-ref.js.map +1 -1
- package/dist/cjs/state/actions/{internal/read-only-actions.js → internal.js} +62 -30
- package/dist/cjs/state/actions/internal.js.map +1 -0
- package/dist/cjs/state/builder-api/actions.js +8 -11
- package/dist/cjs/state/builder-api/actions.js.map +1 -1
- package/dist/cjs/state/host-api.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +2 -2
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/cjs/state/modules/api-resources.js +4 -7
- package/dist/cjs/state/modules/api-resources.js.map +1 -1
- package/dist/cjs/state/modules/{read-write/box-models.js → box-models.js} +4 -6
- package/dist/cjs/state/modules/box-models.js.map +1 -0
- package/dist/cjs/state/modules/breakpoints.js +1 -2
- package/dist/cjs/state/modules/breakpoints.js.map +1 -1
- package/dist/cjs/state/modules/builder-edit-mode.js +1 -2
- package/dist/cjs/state/modules/builder-edit-mode.js.map +1 -1
- package/dist/cjs/state/modules/components-meta.js +2 -3
- package/dist/cjs/state/modules/components-meta.js.map +1 -1
- package/dist/cjs/state/modules/{read-write/element-imperative-handles.js → element-imperative-handles.js} +3 -4
- package/dist/cjs/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/cjs/state/modules/element-trees.js +3 -5
- package/dist/cjs/state/modules/element-trees.js.map +1 -1
- package/dist/cjs/state/modules/is-in-builder.js +1 -2
- package/dist/cjs/state/modules/is-in-builder.js.map +1 -1
- package/dist/cjs/state/modules/{is-read-only.js → is-preview.js} +9 -12
- package/dist/cjs/state/modules/is-preview.js.map +1 -0
- package/dist/cjs/state/modules/localized-resources-map.js +2 -4
- package/dist/cjs/state/modules/localized-resources-map.js.map +1 -1
- package/dist/cjs/state/modules/{read-write/pointer.js → pointer.js} +2 -3
- package/dist/cjs/state/modules/pointer.js.map +1 -0
- package/dist/cjs/state/modules/prop-controllers.js +2 -3
- package/dist/cjs/state/modules/prop-controllers.js.map +1 -1
- package/dist/cjs/state/modules/react-components.js +2 -3
- package/dist/cjs/state/modules/react-components.js.map +1 -1
- package/dist/cjs/state/modules/read-only-documents.js +2 -3
- package/dist/cjs/state/modules/read-only-documents.js.map +1 -1
- package/dist/cjs/state/modules/{read-write/read-write-documents.js → read-write-documents.js} +3 -3
- package/dist/cjs/state/modules/read-write-documents.js.map +1 -0
- package/dist/cjs/state/react-builder-preview.js +508 -18
- package/dist/cjs/state/react-builder-preview.js.map +1 -1
- package/dist/cjs/state/react-page.js +250 -6
- package/dist/cjs/state/react-page.js.map +1 -1
- package/dist/cjs/state/shared-api.js.map +1 -1
- package/dist/cjs/state/translations/get.js +2 -2
- package/dist/cjs/state/translations/get.js.map +1 -1
- package/dist/cjs/state/translations/merge.js +2 -2
- package/dist/cjs/state/translations/merge.js.map +1 -1
- package/dist/esm/api/{client.js → react.js} +1 -1
- package/dist/esm/api/react.js.map +1 -0
- package/dist/esm/api-handler/handlers/element-tree.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/api-handler/handlers/merge-translated-data.js.map +1 -1
- package/dist/esm/api-handler/handlers/translatable-data.js.map +1 -1
- package/dist/esm/builder/host-to-builder-actions.js +4 -4
- package/dist/esm/builder/host-to-builder-actions.js.map +1 -1
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/index.js.map +1 -1
- package/dist/esm/client/index.js +5 -5
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/components/builtin/Box/Box.js +1 -1
- package/dist/esm/components/builtin/Box/Box.js.map +1 -1
- package/dist/esm/components/builtin/Form/Form.js +1 -1
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/components/hooks/useTableFormFieldRefs.js +1 -1
- package/dist/esm/components/hooks/useTableFormFieldRefs.js.map +1 -1
- package/dist/esm/next/api-handler/config/app-router.js +10 -1
- package/dist/esm/next/api-handler/config/app-router.js.map +1 -1
- package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +2 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
- package/dist/esm/next/components/tests/makeswift-component/fixtures.js +2 -1
- package/dist/esm/next/components/tests/makeswift-component/fixtures.js.map +1 -1
- package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js +3 -2
- package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
- package/dist/esm/next/testing/element-data.js +1 -1
- package/dist/esm/next/testing/element-data.js.map +1 -1
- package/dist/esm/next/testing/index.js +0 -1
- package/dist/esm/next/testing/index.js.map +1 -1
- package/dist/esm/next/testing/page-rendering.js +3 -3
- package/dist/esm/next/testing/page-rendering.js.map +1 -1
- package/dist/esm/prop-controllers/descriptors.js.map +1 -1
- package/dist/esm/prop-controllers/instances.js.map +1 -1
- package/dist/esm/runtimes/react/components/Document.js +1 -1
- package/dist/esm/runtimes/react/components/Document.js.map +1 -1
- package/dist/esm/runtimes/react/components/DocumentRoot.js.map +1 -1
- package/dist/esm/runtimes/react/components/Element.js +1 -3
- package/dist/esm/runtimes/react/components/Element.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementReference.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementRegistration.js +1 -1
- package/dist/esm/runtimes/react/components/ElementRegistration.js.map +1 -1
- package/dist/esm/runtimes/react/components/MakeswiftComponent.js +1 -1
- package/dist/esm/runtimes/react/components/MakeswiftComponent.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +2 -2
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/components/page/Page.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +3 -2
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +2 -2
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/runtimes/react/controls.js +2 -2
- package/dist/esm/runtimes/react/controls.js.map +1 -1
- package/dist/esm/runtimes/react/element-imperative-handle.js +1 -1
- package/dist/esm/runtimes/react/element-imperative-handle.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-breakpoints.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-breakpoints.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-builder-edit-mode.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-builder-edit-mode.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-component.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-component.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-dispatch.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-document.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-document.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-element-id.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-element-id.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-is-in-builder.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-is-in-builder.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-is-preview.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-register-document.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-selector.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-universal-dispatch.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +1 -1
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/runtimes/react/index.js +2 -2
- package/dist/esm/runtimes/react/index.js.map +1 -1
- package/dist/esm/runtimes/react/poll-box-model.js +1 -1
- package/dist/esm/runtimes/react/poll-box-model.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime-core.js +1 -4
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +5 -3
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/utils/can-accept-ref.js.map +1 -1
- package/dist/esm/state/actions/{internal/read-only-actions.js → internal.js} +52 -24
- package/dist/esm/state/actions/internal.js.map +1 -0
- package/dist/esm/state/builder-api/actions.js +7 -8
- package/dist/esm/state/builder-api/actions.js.map +1 -1
- package/dist/esm/state/host-api.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +1 -1
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/state/modules/api-resources.js +5 -8
- package/dist/esm/state/modules/api-resources.js.map +1 -1
- package/dist/esm/state/modules/{read-write/box-models.js → box-models.js} +4 -6
- package/dist/esm/state/modules/box-models.js.map +1 -0
- package/dist/esm/state/modules/breakpoints.js +2 -3
- package/dist/esm/state/modules/breakpoints.js.map +1 -1
- package/dist/esm/state/modules/builder-edit-mode.js +2 -3
- package/dist/esm/state/modules/builder-edit-mode.js.map +1 -1
- package/dist/esm/state/modules/components-meta.js +3 -4
- package/dist/esm/state/modules/components-meta.js.map +1 -1
- package/dist/esm/state/modules/{read-write/element-imperative-handles.js → element-imperative-handles.js} +3 -4
- package/dist/esm/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/esm/state/modules/element-trees.js +4 -6
- package/dist/esm/state/modules/element-trees.js.map +1 -1
- package/dist/esm/state/modules/is-in-builder.js +2 -3
- package/dist/esm/state/modules/is-in-builder.js.map +1 -1
- package/dist/esm/state/modules/is-preview.js +21 -0
- package/dist/esm/state/modules/is-preview.js.map +1 -0
- package/dist/esm/state/modules/localized-resources-map.js +3 -5
- package/dist/esm/state/modules/localized-resources-map.js.map +1 -1
- package/dist/esm/state/modules/{read-write/pointer.js → pointer.js} +2 -3
- package/dist/esm/state/modules/pointer.js.map +1 -0
- package/dist/esm/state/modules/prop-controllers.js +3 -4
- package/dist/esm/state/modules/prop-controllers.js.map +1 -1
- package/dist/esm/state/modules/react-components.js +3 -4
- package/dist/esm/state/modules/react-components.js.map +1 -1
- package/dist/esm/state/modules/read-only-documents.js +6 -4
- package/dist/esm/state/modules/read-only-documents.js.map +1 -1
- package/dist/esm/state/modules/{read-write/read-write-documents.js → read-write-documents.js} +3 -3
- package/dist/esm/state/modules/read-write-documents.js.map +1 -0
- package/dist/esm/state/react-builder-preview.js +500 -15
- package/dist/esm/state/react-builder-preview.js.map +1 -1
- package/dist/esm/state/react-page.js +240 -7
- package/dist/esm/state/react-page.js.map +1 -1
- package/dist/esm/state/shared-api.js.map +1 -1
- package/dist/esm/state/translations/get.js +1 -1
- package/dist/esm/state/translations/get.js.map +1 -1
- package/dist/esm/state/translations/merge.js +1 -1
- package/dist/esm/state/translations/merge.js.map +1 -1
- package/dist/types/api/{client.d.ts → react.d.ts} +1 -1
- package/dist/types/api/react.d.ts.map +1 -0
- package/dist/types/api-handler/handlers/element-tree.d.ts +1 -1
- package/dist/types/api-handler/handlers/element-tree.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/merge-translated-data.d.ts +1 -1
- package/dist/types/api-handler/handlers/merge-translated-data.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/translatable-data.d.ts +1 -1
- package/dist/types/api-handler/handlers/translatable-data.d.ts.map +1 -1
- package/dist/types/api-handler/handlers/webhook/types.d.ts +4 -4
- package/dist/types/builder/host-to-builder-actions.d.ts +2 -2
- package/dist/types/builder/host-to-builder-actions.d.ts.map +1 -1
- package/dist/types/builder/index.d.ts +2 -2
- package/dist/types/builder/index.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/components/builtin/Box/Box.d.ts +1 -1
- package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
- package/dist/types/components/builtin/Form/Form.d.ts +1 -1
- package/dist/types/components/builtin/Form/Form.d.ts.map +1 -1
- package/dist/types/locale.d.ts +1 -1
- package/dist/types/next/api-handler/config/app-router.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +1 -1
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +3 -3
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +1 -1
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -1
- package/dist/types/next/components/tests/makeswift-component/fixtures.d.ts +1 -1
- package/dist/types/next/components/tests/makeswift-component/fixtures.d.ts.map +1 -1
- package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts +1 -1
- package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts.map +1 -1
- package/dist/types/next/testing/element-data.d.ts +1 -1
- package/dist/types/next/testing/element-data.d.ts.map +1 -1
- package/dist/types/next/testing/index.d.ts +0 -1
- package/dist/types/next/testing/index.d.ts.map +1 -1
- package/dist/types/next/testing/page-rendering.d.ts.map +1 -1
- package/dist/types/prop-controllers/descriptors.d.ts +1 -1
- package/dist/types/prop-controllers/descriptors.d.ts.map +1 -1
- package/dist/types/prop-controllers/instances.d.ts +1 -1
- package/dist/types/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/Document.d.ts +1 -1
- package/dist/types/runtimes/react/components/Document.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/DocumentRoot.d.ts +1 -1
- package/dist/types/runtimes/react/components/DocumentRoot.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/Element.d.ts +1 -1
- package/dist/types/runtimes/react/components/Element.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/ElementData.d.ts +1 -1
- package/dist/types/runtimes/react/components/ElementData.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/ElementReference.d.ts +1 -1
- package/dist/types/runtimes/react/components/ElementReference.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/page/Page.d.ts +1 -1
- package/dist/types/runtimes/react/components/page/Page.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls.d.ts +2 -2
- package/dist/types/runtimes/react/controls.d.ts.map +1 -1
- package/dist/types/runtimes/react/element-imperative-handle.d.ts +1 -1
- package/dist/types/runtimes/react/element-imperative-handle.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-cache-data.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-cache-data.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-component.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-component.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-dispatch.d.ts +3 -3
- package/dist/types/runtimes/react/hooks/use-dispatch.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-document.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-document.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts +2 -0
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-register-document.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-register-document.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-selector.d.ts +3 -3
- package/dist/types/runtimes/react/hooks/use-selector.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts +4 -4
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-universal-dispatch.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-universal-dispatch.d.ts.map +1 -1
- package/dist/types/runtimes/react/host-api-client.d.ts +1 -1
- package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
- package/dist/types/runtimes/react/index.d.ts +1 -1
- package/dist/types/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/poll-box-model.d.ts +1 -1
- package/dist/types/runtimes/react/poll-box-model.d.ts.map +1 -1
- package/dist/types/runtimes/react/react-runtime-core.d.ts +1 -1
- package/dist/types/runtimes/react/react-runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts +1 -2
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/utils/can-accept-ref.d.ts +1 -1
- package/dist/types/runtimes/react/utils/can-accept-ref.d.ts.map +1 -1
- package/dist/types/state/__tests__/react-page.test.d.ts +2 -0
- package/dist/types/state/__tests__/react-page.test.d.ts.map +1 -0
- package/dist/types/state/actions/index.d.ts +5 -6
- package/dist/types/state/actions/index.d.ts.map +1 -1
- package/dist/types/state/actions/{internal/read-only-actions.d.ts → internal.d.ts} +67 -33
- package/dist/types/state/actions/internal.d.ts.map +1 -0
- package/dist/types/state/builder-api/actions.d.ts +14 -14
- package/dist/types/state/builder-api/actions.d.ts.map +1 -1
- package/dist/types/state/host-api.d.ts +1 -1
- package/dist/types/state/host-api.d.ts.map +1 -1
- package/dist/types/state/modules/api-resources.d.ts.map +1 -1
- package/dist/types/state/modules/{read-write/box-models.d.ts → box-models.d.ts} +1 -1
- package/dist/types/state/modules/box-models.d.ts.map +1 -0
- package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/state/modules/builder-edit-mode.d.ts.map +1 -1
- package/dist/types/state/modules/components-meta.d.ts.map +1 -1
- package/dist/types/state/modules/element-imperative-handles.d.ts +7 -0
- package/dist/types/state/modules/element-imperative-handles.d.ts.map +1 -0
- package/dist/types/state/modules/element-trees.d.ts.map +1 -1
- package/dist/types/state/modules/is-in-builder.d.ts.map +1 -1
- package/dist/types/state/modules/{is-read-only.d.ts → is-preview.d.ts} +3 -3
- package/dist/types/state/modules/is-preview.d.ts.map +1 -0
- package/dist/types/state/modules/localized-resources-map.d.ts.map +1 -1
- package/dist/types/state/modules/{read-write/pointer.d.ts → pointer.d.ts} +3 -2
- package/dist/types/state/modules/pointer.d.ts.map +1 -0
- package/dist/types/state/modules/prop-controllers.d.ts.map +1 -1
- package/dist/types/state/modules/react-components.d.ts.map +1 -1
- package/dist/types/state/modules/read-only-documents.d.ts.map +1 -1
- package/dist/types/state/modules/{read-write/read-write-documents.d.ts → read-write-documents.d.ts} +4 -4
- package/dist/types/state/modules/read-write-documents.d.ts.map +1 -0
- package/dist/types/state/react-builder-preview.d.ts +93 -26
- package/dist/types/state/react-builder-preview.d.ts.map +1 -1
- package/dist/types/state/react-page.d.ts +136 -20
- package/dist/types/state/react-page.d.ts.map +1 -1
- package/dist/types/state/shared-api.d.ts.map +1 -1
- package/dist/types/state/translations/get.d.ts +1 -1
- package/dist/types/state/translations/get.d.ts.map +1 -1
- package/dist/types/state/translations/merge.d.ts +1 -1
- package/dist/types/state/translations/merge.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/api/client.js.map +0 -1
- package/dist/cjs/next/testing/react-runtime.js +0 -29
- package/dist/cjs/next/testing/react-runtime.js.map +0 -1
- package/dist/cjs/runtimes/react/hooks/use-is-read-only.js.map +0 -1
- package/dist/cjs/runtimes/react/testing/react-runtime.js +0 -32
- package/dist/cjs/runtimes/react/testing/react-runtime.js.map +0 -1
- package/dist/cjs/state/actions/internal/index.js +0 -34
- package/dist/cjs/state/actions/internal/index.js.map +0 -1
- package/dist/cjs/state/actions/internal/read-only-actions.js.map +0 -1
- package/dist/cjs/state/actions/internal/read-write-actions.js +0 -70
- package/dist/cjs/state/actions/internal/read-write-actions.js.map +0 -1
- package/dist/cjs/state/middleware/prop-controller-handles.js +0 -114
- package/dist/cjs/state/middleware/prop-controller-handles.js.map +0 -1
- package/dist/cjs/state/middleware/read-only-element-tree.js +0 -52
- package/dist/cjs/state/middleware/read-only-element-tree.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/builder-api/element-size.js +0 -40
- package/dist/cjs/state/middleware/read-write/builder-api/element-size.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/builder-api/index.js +0 -76
- package/dist/cjs/state/middleware/read-write/builder-api/index.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +0 -278
- package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/makeswift-api-client-sync.js +0 -37
- package/dist/cjs/state/middleware/read-write/makeswift-api-client-sync.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/measure-box-models.js +0 -71
- package/dist/cjs/state/middleware/read-write/measure-box-models.js.map +0 -1
- package/dist/cjs/state/middleware/read-write/update-element-tree.js +0 -59
- package/dist/cjs/state/middleware/read-write/update-element-tree.js.map +0 -1
- package/dist/cjs/state/modules/is-read-only.js.map +0 -1
- package/dist/cjs/state/modules/read-write/box-models.js.map +0 -1
- package/dist/cjs/state/modules/read-write/element-imperative-handles.js.map +0 -1
- package/dist/cjs/state/modules/read-write/pointer.js.map +0 -1
- package/dist/cjs/state/modules/read-write/read-write-documents.js.map +0 -1
- package/dist/cjs/state/ops/copy-element-tree.js +0 -67
- package/dist/cjs/state/ops/copy-element-tree.js.map +0 -1
- package/dist/cjs/state/ops/merge-element.js +0 -73
- package/dist/cjs/state/ops/merge-element.js.map +0 -1
- package/dist/cjs/state/read-only-state.js +0 -209
- package/dist/cjs/state/read-only-state.js.map +0 -1
- package/dist/cjs/state/read-write-state.js +0 -121
- package/dist/cjs/state/read-write-state.js.map +0 -1
- package/dist/esm/api/client.js.map +0 -1
- package/dist/esm/next/testing/react-runtime.js +0 -5
- package/dist/esm/next/testing/react-runtime.js.map +0 -1
- package/dist/esm/runtimes/react/hooks/use-is-read-only.js +0 -9
- package/dist/esm/runtimes/react/hooks/use-is-read-only.js.map +0 -1
- package/dist/esm/runtimes/react/testing/react-runtime.js +0 -8
- package/dist/esm/runtimes/react/testing/react-runtime.js.map +0 -1
- package/dist/esm/state/actions/internal/index.js +0 -10
- package/dist/esm/state/actions/internal/index.js.map +0 -1
- package/dist/esm/state/actions/internal/read-only-actions.js.map +0 -1
- package/dist/esm/state/actions/internal/read-write-actions.js +0 -41
- package/dist/esm/state/actions/internal/read-write-actions.js.map +0 -1
- package/dist/esm/state/middleware/prop-controller-handles.js +0 -80
- package/dist/esm/state/middleware/prop-controller-handles.js.map +0 -1
- package/dist/esm/state/middleware/read-only-element-tree.js +0 -28
- package/dist/esm/state/middleware/read-only-element-tree.js.map +0 -1
- package/dist/esm/state/middleware/read-write/builder-api/element-size.js +0 -16
- package/dist/esm/state/middleware/read-write/builder-api/element-size.js.map +0 -1
- package/dist/esm/state/middleware/read-write/builder-api/index.js +0 -52
- package/dist/esm/state/middleware/read-write/builder-api/index.js.map +0 -1
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +0 -251
- package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +0 -1
- package/dist/esm/state/middleware/read-write/makeswift-api-client-sync.js +0 -13
- package/dist/esm/state/middleware/read-write/makeswift-api-client-sync.js.map +0 -1
- package/dist/esm/state/middleware/read-write/measure-box-models.js +0 -37
- package/dist/esm/state/middleware/read-write/measure-box-models.js.map +0 -1
- package/dist/esm/state/middleware/read-write/update-element-tree.js +0 -35
- package/dist/esm/state/middleware/read-write/update-element-tree.js.map +0 -1
- package/dist/esm/state/modules/is-read-only.js +0 -24
- package/dist/esm/state/modules/is-read-only.js.map +0 -1
- package/dist/esm/state/modules/read-write/box-models.js.map +0 -1
- package/dist/esm/state/modules/read-write/element-imperative-handles.js.map +0 -1
- package/dist/esm/state/modules/read-write/pointer.js.map +0 -1
- package/dist/esm/state/modules/read-write/read-write-documents.js.map +0 -1
- package/dist/esm/state/ops/copy-element-tree.js +0 -37
- package/dist/esm/state/ops/copy-element-tree.js.map +0 -1
- package/dist/esm/state/ops/merge-element.js +0 -39
- package/dist/esm/state/ops/merge-element.js.map +0 -1
- package/dist/esm/state/read-only-state.js +0 -157
- package/dist/esm/state/read-only-state.js.map +0 -1
- package/dist/esm/state/read-write-state.js +0 -76
- package/dist/esm/state/read-write-state.js.map +0 -1
- package/dist/types/api/client.d.ts.map +0 -1
- package/dist/types/next/testing/react-runtime.d.ts +0 -2
- package/dist/types/next/testing/react-runtime.d.ts.map +0 -1
- package/dist/types/runtimes/react/hooks/use-is-read-only.d.ts +0 -2
- package/dist/types/runtimes/react/hooks/use-is-read-only.d.ts.map +0 -1
- package/dist/types/runtimes/react/testing/react-runtime.d.ts +0 -3
- package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +0 -1
- package/dist/types/state/__tests__/merge-element.test.d.ts +0 -2
- package/dist/types/state/__tests__/merge-element.test.d.ts.map +0 -1
- package/dist/types/state/actions/internal/index.d.ts +0 -25
- package/dist/types/state/actions/internal/index.d.ts.map +0 -1
- package/dist/types/state/actions/internal/read-only-actions.d.ts.map +0 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts +0 -48
- package/dist/types/state/actions/internal/read-write-actions.d.ts.map +0 -1
- package/dist/types/state/middleware/prop-controller-handles.d.ts +0 -4
- package/dist/types/state/middleware/prop-controller-handles.d.ts.map +0 -1
- package/dist/types/state/middleware/read-only-element-tree.d.ts +0 -4
- package/dist/types/state/middleware/read-only-element-tree.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/builder-api/element-size.d.ts +0 -12
- package/dist/types/state/middleware/read-write/builder-api/element-size.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/builder-api/index.d.ts +0 -5
- package/dist/types/state/middleware/read-write/builder-api/index.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts +0 -6
- package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/makeswift-api-client-sync.d.ts +0 -5
- package/dist/types/state/middleware/read-write/makeswift-api-client-sync.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/measure-box-models.d.ts +0 -4
- package/dist/types/state/middleware/read-write/measure-box-models.d.ts.map +0 -1
- package/dist/types/state/middleware/read-write/update-element-tree.d.ts +0 -4
- package/dist/types/state/middleware/read-write/update-element-tree.d.ts.map +0 -1
- package/dist/types/state/modules/is-read-only.d.ts.map +0 -1
- package/dist/types/state/modules/read-write/box-models.d.ts.map +0 -1
- package/dist/types/state/modules/read-write/element-imperative-handles.d.ts +0 -6
- package/dist/types/state/modules/read-write/element-imperative-handles.d.ts.map +0 -1
- package/dist/types/state/modules/read-write/pointer.d.ts.map +0 -1
- package/dist/types/state/modules/read-write/read-write-documents.d.ts.map +0 -1
- package/dist/types/state/ops/copy-element-tree.d.ts +0 -37
- package/dist/types/state/ops/copy-element-tree.d.ts.map +0 -1
- package/dist/types/state/ops/merge-element.d.ts +0 -4
- package/dist/types/state/ops/merge-element.d.ts.map +0 -1
- package/dist/types/state/read-only-state.d.ts +0 -122
- package/dist/types/state/read-only-state.d.ts.map +0 -1
- package/dist/types/state/read-write-state.d.ts +0 -56
- package/dist/types/state/read-write-state.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/actions/internal.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../api/types'\nimport { type Descriptor as PropControllerDescriptor } from '../../prop-controllers/descriptors'\n\nimport { type Measurable } from '../modules/box-models'\nimport { type ComponentMeta } from '../modules/components-meta'\nimport { type PropControllersHandle } from '../modules/prop-controller-handles'\nimport { type ComponentType } from '../modules/react-components'\nimport { type DescriptorsByComponentType } from '../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../shared-api'\nimport { type SerializedState as APIClientCache } from '../makeswift-api-client'\n\nexport const InternalActionTypes = {\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n CHANGE_ELEMENT_TREE: 'CHANGE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_MEASURABLE: 'REGISTER_MEASURABLE',\n UNREGISTER_MEASURABLE: 'UNREGISTER_MEASURABLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n\n UPDATE_API_CLIENT_CACHE: 'UPDATE_API_CLIENT_CACHE',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof InternalActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof InternalActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof InternalActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\ntype ChangeElementTreeAction = {\n type: typeof InternalActionTypes.CHANGE_ELEMENT_TREE\n payload: {\n oldDocument: DocumentPayload\n newDocument: DocumentPayload\n descriptors: DescriptorsByComponentType\n operation: Operation\n }\n}\n\nexport type RegisterComponentAction = {\n type: typeof InternalActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof InternalActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof InternalActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof InternalActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterMeasurableAction = {\n type: typeof InternalActionTypes.REGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string; measurable: Measurable }\n}\n\ntype UnregisterMeasurableAction = {\n type: typeof InternalActionTypes.UNREGISTER_MEASURABLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof InternalActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof InternalActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof InternalActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof InternalActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof InternalActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof InternalActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof InternalActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype UpdateAPIClientCache = {\n type: typeof InternalActionTypes.UPDATE_API_CLIENT_CACHE\n payload: APIClientCache\n}\n\nexport type InternalAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | ChangeElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterMeasurableAction\n | UnregisterMeasurableAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | UpdateAPIClientCache\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: InternalActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: InternalActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: InternalActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function changeElementTree(\n payload: ChangeElementTreeAction['payload'],\n): ChangeElementTreeAction {\n return {\n type: InternalActionTypes.CHANGE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: InternalActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: InternalActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, InternalAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: InternalActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: InternalActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, InternalAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerMeasurable(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): RegisterMeasurableAction {\n return {\n type: InternalActionTypes.REGISTER_MEASURABLE,\n payload: { documentKey, elementKey, measurable },\n }\n}\n\nexport function unregisterMeasurable(\n documentKey: string,\n elementKey: string,\n): UnregisterMeasurableAction {\n return { type: InternalActionTypes.UNREGISTER_MEASURABLE, payload: { documentKey, elementKey } }\n}\n\nexport function registerMeasurableEffect(\n documentKey: string,\n elementKey: string,\n measurable: Measurable,\n): ThunkAction<() => void, unknown, unknown, InternalAction> {\n return dispatch => {\n dispatch(registerMeasurable(documentKey, elementKey, measurable))\n\n return () => {\n dispatch(unregisterMeasurable(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: InternalActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: InternalActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: InternalActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: InternalActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: InternalActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: InternalActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, InternalAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: InternalActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function updateAPIClientCache(payload: APIClientCache): UpdateAPIClientCache {\n return { type: InternalActionTypes.UPDATE_API_CLIENT_CACHE, payload }\n}\n"],"mappings":"AAmBO,MAAM,sBAAsB;AAAA,EACjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EAEtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EAEvB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,mBAAmB;AAAA,EAEnB,yBAAyB;AAC3B;AAkIO,SAAS,qBACd,cACA,YACA,UACA,QAC4B;AAC5B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,cAAc,YAAY,UAAU,OAAO;AAAA,EACxD;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO,EAAE,MAAM,oBAAoB,qBAAqB,QAAQ;AAClE;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,SAAS,kBACd,MACA,MACA,2BACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,0BAA0B;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AoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,OAAO;AAAA,EAC7C;AACF;AAEO,SAAS,gCACd,aACA,YACuC;AACvC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEA,SAAS,uBACP,MACA,WAC8B;AAC9B,SAAO,EAAE,MAAM,oBAAoB,0BAA0B,SAAS,EAAE,MAAM,UAAU,EAAE;AAC5F;AAEA,SAAS,yBAAyB,MAA8C;AAC9E,SAAO,EAAE,MAAM,oBAAoB,4BAA4B,SAAS,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,qBAAqB,SAA+C;AAClF,SAAO,EAAE,MAAM,oBAAoB,yBAAyB,QAAQ;AACtE;","names":[]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { SharedActionTypes } from "../shared-api";
|
|
2
|
-
export * from "../shared-api";
|
|
3
2
|
const BuilderActionTypes = {
|
|
4
3
|
...SharedActionTypes,
|
|
5
4
|
MAKESWIFT_CONNECTION_CHECK: "MAKESWIFT_CONNECTION_CHECK",
|
|
5
|
+
CHANGE_ELEMENT_BOX_MODELS: "CHANGE_ELEMENT_BOX_MODELS",
|
|
6
6
|
MOUNT_COMPONENT: "MOUNT_COMPONENT",
|
|
7
7
|
UNMOUNT_COMPONENT: "UNMOUNT_COMPONENT",
|
|
8
8
|
CHANGE_DOCUMENT_ELEMENT_SIZE: "CHANGE_DOCUMENT_ELEMENT_SIZE",
|
|
9
|
-
CHANGE_ELEMENT_BOX_MODELS: "CHANGE_ELEMENT_BOX_MODELS",
|
|
10
9
|
MESSAGE_BUILDER_PROP_CONTROLLER: "MESSAGE_BUILDER_PROP_CONTROLLER",
|
|
11
10
|
HANDLE_WHEEL: "HANDLE_WHEEL",
|
|
12
11
|
HANDLE_POINTER_MOVE: "HANDLE_POINTER_MOVE",
|
|
@@ -20,6 +19,12 @@ const BuilderActionTypes = {
|
|
|
20
19
|
function makeswiftConnectionCheck(payload) {
|
|
21
20
|
return { type: BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK, payload };
|
|
22
21
|
}
|
|
22
|
+
function changeElementBoxModels(changedElementBoxModels) {
|
|
23
|
+
return {
|
|
24
|
+
type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,
|
|
25
|
+
payload: { changedElementBoxModels }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
23
28
|
function mountComponent(documentKey, elementKey) {
|
|
24
29
|
return { type: BuilderActionTypes.MOUNT_COMPONENT, payload: { documentKey, elementKey } };
|
|
25
30
|
}
|
|
@@ -37,12 +42,6 @@ function mountComponentEffect(documentKey, elementKey) {
|
|
|
37
42
|
function changeDocumentElementSize(size) {
|
|
38
43
|
return { type: BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE, payload: { size } };
|
|
39
44
|
}
|
|
40
|
-
function changeElementBoxModels(changedElementBoxModels) {
|
|
41
|
-
return {
|
|
42
|
-
type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,
|
|
43
|
-
payload: { changedElementBoxModels }
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
45
|
function messageBuilderPropController(documentKey, elementKey, propName, message) {
|
|
47
46
|
return {
|
|
48
47
|
type: BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/builder-api/actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SerializedControl } from '../../builder'\nimport { type PropControllerMessage } from '../../prop-controllers/instances'\n\nimport { type Document } from '../modules/read-only-documents'\nimport { type ComponentMeta } from '../modules/components-meta'\nimport { type BoxModel } from '../modules/read-write/box-models'\n\nimport { type ElementSize } from '../middleware/read-write/builder-api/element-size'\nimport { type DocumentPayload, type SharedAction, SharedActionTypes } from '../shared-api'\n\nexport * from '../shared-api'\n\n// actions dispatched by the host to the builder (\"Builder API\")\n// note that some of these actions, in addition to being dispatched to the builder,\n// might also be internally intercepted by the host as a part of maintaining the\n// runtime's \"read-write\" state\nexport const BuilderActionTypes = {\n ...SharedActionTypes,\n\n MAKESWIFT_CONNECTION_CHECK: 'MAKESWIFT_CONNECTION_CHECK',\n\n MOUNT_COMPONENT: 'MOUNT_COMPONENT',\n UNMOUNT_COMPONENT: 'UNMOUNT_COMPONENT',\n\n CHANGE_DOCUMENT_ELEMENT_SIZE: 'CHANGE_DOCUMENT_ELEMENT_SIZE',\n CHANGE_ELEMENT_BOX_MODELS: 'CHANGE_ELEMENT_BOX_MODELS',\n\n MESSAGE_BUILDER_PROP_CONTROLLER: 'MESSAGE_BUILDER_PROP_CONTROLLER',\n\n HANDLE_WHEEL: 'HANDLE_WHEEL',\n HANDLE_POINTER_MOVE: 'HANDLE_POINTER_MOVE',\n\n ELEMENT_FROM_POINT_CHANGE: 'ELEMENT_FROM_POINT_CHANGE',\n\n REGISTER_BUILDER_DOCUMENT: 'REGISTER_BUILDER_DOCUMENT',\n UNREGISTER_BUILDER_DOCUMENT: 'UNREGISTER_BUILDER_DOCUMENT',\n\n REGISTER_BUILDER_COMPONENT: 'REGISTER_BUILDER_COMPONENT',\n UNREGISTER_BUILDER_COMPONENT: 'UNREGISTER_BUILDER_COMPONENT',\n\n HANDLE_HOST_NAVIGATE: 'HANDLE_HOST_NAVIGATE',\n} as const\n\ntype ActionWithTransferables<A> = A & {\n transferables?: Transferable[]\n}\n\ntype MakeswiftConnectionCheckAction = {\n type: typeof BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK\n payload: { currentUrl: string }\n}\n\ntype MountComponentAction = {\n type: typeof BuilderActionTypes.MOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UnmountComponentAction = {\n type: typeof BuilderActionTypes.UNMOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype ChangeDocumentElementSizeAction = {\n type: typeof BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE\n payload: { size: ElementSize }\n}\n\ntype ChangeElementBoxModelsAction = {\n type: typeof BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS\n payload: { changedElementBoxModels: Map<string, Map<string, BoxModel | null>> }\n}\n\ntype MessageBuilderPropControllerAction<T = PropControllerMessage> = {\n type: typeof BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER\n payload: { documentKey: string; elementKey: string; propName: string; message: T }\n}\n\ntype HandleWheelAction = {\n type: typeof BuilderActionTypes.HANDLE_WHEEL\n payload: { deltaX: number; deltaY: number }\n}\n\ntype HandlePointerMoveAction = {\n type: typeof BuilderActionTypes.HANDLE_POINTER_MOVE\n payload: { clientX: number; clientY: number }\n}\n\ntype ElementFromPointChangeAction = {\n type: typeof BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE\n payload: { keys: { documentKey: string; elementKey: string } | null }\n}\n\ntype RegisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string; document: DocumentPayload }\n}\n\ntype UnregisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string }\n}\n\ntype RegisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n serializedControls: Record<string, SerializedControl>\n }\n}\n\ntype UnregisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT\n payload: { type: string }\n}\n\ntype HandleHostNavigateAction = {\n type: typeof BuilderActionTypes.HANDLE_HOST_NAVIGATE\n payload: { url: string | null }\n}\n\nexport type BuilderAction =\n | SharedAction\n | MakeswiftConnectionCheckAction\n | MountComponentAction\n | UnmountComponentAction\n | ChangeDocumentElementSizeAction\n | ChangeElementBoxModelsAction\n | MessageBuilderPropControllerAction\n | HandleWheelAction\n | HandlePointerMoveAction\n | ElementFromPointChangeAction\n | RegisterBuilderDocumentAction\n | UnregisterBuilderDocumentAction\n | RegisterBuilderComponentAction\n | UnregisterBuilderComponentAction\n | HandleHostNavigateAction\n\nexport function makeswiftConnectionCheck(\n payload: MakeswiftConnectionCheckAction['payload'],\n): MakeswiftConnectionCheckAction {\n return { type: BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK, payload }\n}\n\nexport function mountComponent(documentKey: string, elementKey: string): MountComponentAction {\n return { type: BuilderActionTypes.MOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function unmountComponent(documentKey: string, elementKey: string): UnmountComponentAction {\n return { type: BuilderActionTypes.UNMOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function mountComponentEffect(\n documentKey: string,\n elementKey: string,\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n dispatch(mountComponent(documentKey, elementKey))\n\n return () => {\n dispatch(unmountComponent(documentKey, elementKey))\n }\n }\n}\n\nexport function changeDocumentElementSize(size: ElementSize): ChangeDocumentElementSizeAction {\n return { type: BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE, payload: { size } }\n}\n\nexport function changeElementBoxModels(\n changedElementBoxModels: Map<string, Map<string, BoxModel | null>>,\n): ChangeElementBoxModelsAction {\n return {\n type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,\n payload: { changedElementBoxModels },\n }\n}\n\nexport function messageBuilderPropController<T>(\n documentKey: string,\n elementKey: string,\n propName: string,\n message: T,\n): MessageBuilderPropControllerAction<T> {\n return {\n type: BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER,\n payload: { documentKey, elementKey, propName, message },\n }\n}\n\nexport function handleWheel(payload: { deltaX: number; deltaY: number }): HandleWheelAction {\n return { type: BuilderActionTypes.HANDLE_WHEEL, payload }\n}\n\nexport function handlePointerMove(payload: {\n clientX: number\n clientY: number\n}): HandlePointerMoveAction {\n return { type: BuilderActionTypes.HANDLE_POINTER_MOVE, payload }\n}\n\nexport function elementFromPointChange(\n keys: {\n documentKey: string\n elementKey: string\n } | null,\n): ElementFromPointChangeAction {\n return { type: BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE, payload: { keys } }\n}\n\nexport function registerBuilderDocument(document: Document): RegisterBuilderDocumentAction {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_DOCUMENT,\n payload: { documentKey: document.key, document },\n }\n}\n\nexport function unregisterBuilderDocument(documentKey: string): UnregisterBuilderDocumentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT, payload: { documentKey } }\n}\n\nexport function registerBuilderDocumentsEffect(\n documents: Document[],\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n documents.forEach(document => dispatch(registerBuilderDocument(document)))\n\n return () => {\n documents.forEach(document => dispatch(unregisterBuilderDocument(document.key)))\n }\n }\n}\n\nexport function registerBuilderComponent(\n payload: RegisterBuilderComponentAction['payload'],\n transferables?: Transferable[],\n): ActionWithTransferables<RegisterBuilderComponentAction> {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_COMPONENT,\n payload,\n transferables,\n }\n}\n\nexport function unregisterBuilderComponent(\n payload: UnregisterBuilderComponentAction['payload'],\n): UnregisterBuilderComponentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT, payload }\n}\n\nexport function hasTransferables<A extends BuilderAction>(\n action: A,\n): action is ActionWithTransferables<A> {\n return 'transferables' in action && Array.isArray(action.transferables)\n}\n"],"mappings":"AAUA,SAAkD,yBAAyB;AAE3E,cAAc;AAMP,MAAM,qBAAqB;AAAA,EAChC,GAAG;AAAA,EAEH,4BAA4B;AAAA,EAE5B,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EAEnB,8BAA8B;AAAA,EAC9B,2BAA2B;AAAA,EAE3B,iCAAiC;AAAA,EAEjC,cAAc;AAAA,EACd,qBAAqB;AAAA,EAErB,2BAA2B;AAAA,EAE3B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,4BAA4B;AAAA,EAC5B,8BAA8B;AAAA,EAE9B,sBAAsB;AACxB;AAiGO,SAAS,yBACd,SACgC;AAChC,SAAO,EAAE,MAAM,mBAAmB,4BAA4B,QAAQ;AACxE;AAEO,SAAS,eAAe,aAAqB,YAA0C;AAC5F,SAAO,EAAE,MAAM,mBAAmB,iBAAiB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC1F;AAEO,SAAS,iBAAiB,aAAqB,YAA4C;AAChG,SAAO,EAAE,MAAM,mBAAmB,mBAAmB,SAAS,EAAE,aAAa,WAAW,EAAE;AAC5F;AAEO,SAAS,qBACd,aACA,YAC0D;AAC1D,SAAO,cAAY;AACjB,aAAS,eAAe,aAAa,UAAU,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,iBAAiB,aAAa,UAAU,CAAC;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,0BAA0B,MAAoD;AAC5F,SAAO,EAAE,MAAM,mBAAmB,8BAA8B,SAAS,EAAE,KAAK,EAAE;AACpF;AAEO,SAAS,uBACd,yBAC8B;AAC9B,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB,SAAS,EAAE,wBAAwB;AAAA,EACrC;AACF;AAEO,SAAS,6BACd,aACA,YACA,UACA,SACuC;AACvC,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB,SAAS,EAAE,aAAa,YAAY,UAAU,QAAQ;AAAA,EACxD;AACF;AAEO,SAAS,YAAY,SAAgE;AAC1F,SAAO,EAAE,MAAM,mBAAmB,cAAc,QAAQ;AAC1D;AAEO,SAAS,kBAAkB,SAGN;AAC1B,SAAO,EAAE,MAAM,mBAAmB,qBAAqB,QAAQ;AACjE;AAEO,SAAS,uBACd,MAI8B;AAC9B,SAAO,EAAE,MAAM,mBAAmB,2BAA2B,SAAS,EAAE,KAAK,EAAE;AACjF;AAEO,SAAS,wBAAwB,UAAmD;AACzF,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB,SAAS,EAAE,aAAa,SAAS,KAAK,SAAS;AAAA,EACjD;AACF;AAEO,SAAS,0BAA0B,aAAsD;AAC9F,SAAO,EAAE,MAAM,mBAAmB,6BAA6B,SAAS,EAAE,YAAY,EAAE;AAC1F;AAEO,SAAS,+BACd,WAC0D;AAC1D,SAAO,cAAY;AACjB,cAAU,QAAQ,cAAY,SAAS,wBAAwB,QAAQ,CAAC,CAAC;AAEzE,WAAO,MAAM;AACX,gBAAU,QAAQ,cAAY,SAAS,0BAA0B,SAAS,GAAG,CAAC,CAAC;AAAA,IACjF;AAAA,EACF;AACF;AAEO,SAAS,yBACd,SACA,eACyD;AACzD,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,2BACd,SACkC;AAClC,SAAO,EAAE,MAAM,mBAAmB,8BAA8B,QAAQ;AAC1E;AAEO,SAAS,iBACd,QACsC;AACtC,SAAO,mBAAmB,UAAU,MAAM,QAAQ,OAAO,aAAa;AACxE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/builder-api/actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SerializedControl } from '../../builder'\nimport { type PropControllerMessage } from '../../prop-controllers/instances'\n\nimport { type Document } from '../modules/read-only-documents'\nimport { type BoxModel } from '../modules/box-models'\nimport { type ComponentMeta } from '../modules/components-meta'\n\nimport { type Size } from '../react-builder-preview'\nimport { type DocumentPayload, type SharedAction, SharedActionTypes } from '../shared-api'\n\nexport const BuilderActionTypes = {\n ...SharedActionTypes,\n\n MAKESWIFT_CONNECTION_CHECK: 'MAKESWIFT_CONNECTION_CHECK',\n\n CHANGE_ELEMENT_BOX_MODELS: 'CHANGE_ELEMENT_BOX_MODELS',\n\n MOUNT_COMPONENT: 'MOUNT_COMPONENT',\n UNMOUNT_COMPONENT: 'UNMOUNT_COMPONENT',\n\n CHANGE_DOCUMENT_ELEMENT_SIZE: 'CHANGE_DOCUMENT_ELEMENT_SIZE',\n MESSAGE_BUILDER_PROP_CONTROLLER: 'MESSAGE_BUILDER_PROP_CONTROLLER',\n\n HANDLE_WHEEL: 'HANDLE_WHEEL',\n HANDLE_POINTER_MOVE: 'HANDLE_POINTER_MOVE',\n\n ELEMENT_FROM_POINT_CHANGE: 'ELEMENT_FROM_POINT_CHANGE',\n\n REGISTER_BUILDER_DOCUMENT: 'REGISTER_BUILDER_DOCUMENT',\n UNREGISTER_BUILDER_DOCUMENT: 'UNREGISTER_BUILDER_DOCUMENT',\n\n REGISTER_BUILDER_COMPONENT: 'REGISTER_BUILDER_COMPONENT',\n UNREGISTER_BUILDER_COMPONENT: 'UNREGISTER_BUILDER_COMPONENT',\n\n HANDLE_HOST_NAVIGATE: 'HANDLE_HOST_NAVIGATE',\n} as const\n\ntype ActionWithTransferables<A> = A & {\n transferables?: Transferable[]\n}\n\ntype MakeswiftConnectionCheckAction = {\n type: typeof BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK\n payload: { currentUrl: string }\n}\n\ntype ChangeElementBoxModelsAction = {\n type: typeof BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS\n payload: { changedElementBoxModels: Map<string, Map<string, BoxModel | null>> }\n}\n\ntype MountComponentAction = {\n type: typeof BuilderActionTypes.MOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype UnmountComponentAction = {\n type: typeof BuilderActionTypes.UNMOUNT_COMPONENT\n payload: { documentKey: string; elementKey: string }\n}\n\ntype ChangeDocumentElementSizeAction = {\n type: typeof BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE\n payload: { size: Size }\n}\n\ntype MessageBuilderPropControllerAction<T = PropControllerMessage> = {\n type: typeof BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER\n payload: { documentKey: string; elementKey: string; propName: string; message: T }\n}\n\ntype HandleWheelAction = {\n type: typeof BuilderActionTypes.HANDLE_WHEEL\n payload: { deltaX: number; deltaY: number }\n}\n\ntype HandlePointerMoveAction = {\n type: typeof BuilderActionTypes.HANDLE_POINTER_MOVE\n payload: { clientX: number; clientY: number }\n}\n\ntype ElementFromPointChangeAction = {\n type: typeof BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE\n payload: { keys: { documentKey: string; elementKey: string } | null }\n}\n\ntype RegisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string; document: DocumentPayload }\n}\n\ntype UnregisterBuilderDocumentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT\n payload: { documentKey: string }\n}\n\ntype RegisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.REGISTER_BUILDER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n serializedControls: Record<string, SerializedControl>\n }\n}\n\ntype UnregisterBuilderComponentAction = {\n type: typeof BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT\n payload: { type: string }\n}\n\ntype HandleHostNavigateAction = {\n type: typeof BuilderActionTypes.HANDLE_HOST_NAVIGATE\n payload: { url: string | null }\n}\n\nexport type BuilderAction =\n | SharedAction\n | MakeswiftConnectionCheckAction\n | ChangeElementBoxModelsAction\n | MountComponentAction\n | UnmountComponentAction\n | ChangeDocumentElementSizeAction\n | MessageBuilderPropControllerAction\n | HandleWheelAction\n | HandlePointerMoveAction\n | ElementFromPointChangeAction\n | RegisterBuilderDocumentAction\n | UnregisterBuilderDocumentAction\n | RegisterBuilderComponentAction\n | UnregisterBuilderComponentAction\n | HandleHostNavigateAction\n\nexport function makeswiftConnectionCheck(\n payload: MakeswiftConnectionCheckAction['payload'],\n): MakeswiftConnectionCheckAction {\n return { type: BuilderActionTypes.MAKESWIFT_CONNECTION_CHECK, payload }\n}\n\nexport function changeElementBoxModels(\n changedElementBoxModels: Map<string, Map<string, BoxModel | null>>,\n): ChangeElementBoxModelsAction {\n return {\n type: BuilderActionTypes.CHANGE_ELEMENT_BOX_MODELS,\n payload: { changedElementBoxModels },\n }\n}\n\nexport function mountComponent(documentKey: string, elementKey: string): MountComponentAction {\n return { type: BuilderActionTypes.MOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function unmountComponent(documentKey: string, elementKey: string): UnmountComponentAction {\n return { type: BuilderActionTypes.UNMOUNT_COMPONENT, payload: { documentKey, elementKey } }\n}\n\nexport function mountComponentEffect(\n documentKey: string,\n elementKey: string,\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n dispatch(mountComponent(documentKey, elementKey))\n\n return () => {\n dispatch(unmountComponent(documentKey, elementKey))\n }\n }\n}\n\nexport function changeDocumentElementSize(size: Size): ChangeDocumentElementSizeAction {\n return { type: BuilderActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE, payload: { size } }\n}\n\nexport function messageBuilderPropController<T>(\n documentKey: string,\n elementKey: string,\n propName: string,\n message: T,\n): MessageBuilderPropControllerAction<T> {\n return {\n type: BuilderActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER,\n payload: { documentKey, elementKey, propName, message },\n }\n}\n\nexport function handleWheel(payload: { deltaX: number; deltaY: number }): HandleWheelAction {\n return { type: BuilderActionTypes.HANDLE_WHEEL, payload }\n}\n\nexport function handlePointerMove(payload: {\n clientX: number\n clientY: number\n}): HandlePointerMoveAction {\n return { type: BuilderActionTypes.HANDLE_POINTER_MOVE, payload }\n}\n\nexport function elementFromPointChange(\n keys: {\n documentKey: string\n elementKey: string\n } | null,\n): ElementFromPointChangeAction {\n return { type: BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE, payload: { keys } }\n}\n\nexport function registerBuilderDocument(document: Document): RegisterBuilderDocumentAction {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_DOCUMENT,\n payload: { documentKey: document.key, document },\n }\n}\n\nexport function unregisterBuilderDocument(documentKey: string): UnregisterBuilderDocumentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_DOCUMENT, payload: { documentKey } }\n}\n\nexport function registerBuilderDocumentsEffect(\n documents: Document[],\n): ThunkAction<() => void, unknown, unknown, BuilderAction> {\n return dispatch => {\n documents.forEach(document => dispatch(registerBuilderDocument(document)))\n\n return () => {\n documents.forEach(document => dispatch(unregisterBuilderDocument(document.key)))\n }\n }\n}\n\nexport function registerBuilderComponent(\n payload: RegisterBuilderComponentAction['payload'],\n transferables?: Transferable[],\n): ActionWithTransferables<RegisterBuilderComponentAction> {\n return {\n type: BuilderActionTypes.REGISTER_BUILDER_COMPONENT,\n payload,\n transferables,\n }\n}\n\nexport function unregisterBuilderComponent(\n payload: UnregisterBuilderComponentAction['payload'],\n): UnregisterBuilderComponentAction {\n return { type: BuilderActionTypes.UNREGISTER_BUILDER_COMPONENT, payload }\n}\n\nexport function hasTransferables<A extends BuilderAction>(\n action: A,\n): action is ActionWithTransferables<A> {\n return 'transferables' in action && Array.isArray(action.transferables)\n}\n"],"mappings":"AAUA,SAAkD,yBAAyB;AAEpE,MAAM,qBAAqB;AAAA,EAChC,GAAG;AAAA,EAEH,4BAA4B;AAAA,EAE5B,2BAA2B;AAAA,EAE3B,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EAEnB,8BAA8B;AAAA,EA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mB,2BAA2B,SAAS,EAAE,KAAK,EAAE;AACjF;AAEO,SAAS,wBAAwB,UAAmD;AACzF,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB,SAAS,EAAE,aAAa,SAAS,KAAK,SAAS;AAAA,EACjD;AACF;AAEO,SAAS,0BAA0B,aAAsD;AAC9F,SAAO,EAAE,MAAM,mBAAmB,6BAA6B,SAAS,EAAE,YAAY,EAAE;AAC1F;AAEO,SAAS,+BACd,WAC0D;AAC1D,SAAO,cAAY;AACjB,cAAU,QAAQ,cAAY,SAAS,wBAAwB,QAAQ,CAAC,CAAC;AAEzE,WAAO,MAAM;AACX,gBAAU,QAAQ,cAAY,SAAS,0BAA0B,SAAS,GAAG,CAAC,CAAC;AAAA,IACjF;AAAA,EACF;AACF;AAEO,SAAS,yBACd,SACA,eACyD;AACzD,SAAO;AAAA,IACL,MAAM,mBAAmB;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,2BACd,SACkC;AAClC,SAAO,EAAE,MAAM,mBAAmB,8BAA8B,QAAQ;AAC1E;AAEO,SAAS,iBACd,QACsC;AACtC,SAAO,mBAAmB,UAAU,MAAM,QAAQ,OAAO,aAAa;AACxE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/host-api.ts"],"sourcesContent":["import { isAction } from '@reduxjs/toolkit'\n\nimport { type Operation } from 'ot-json0'\n\nimport { type PropControllerMessage } from '../prop-controllers/instances'\nimport { type APIResource, APIResourceLocale } from '../api/types'\n\nimport { BuilderEditMode } from './modules/builder-edit-mode'\nimport { type Point } from './modules/
|
|
1
|
+
{"version":3,"sources":["../../../src/state/host-api.ts"],"sourcesContent":["import { isAction } from '@reduxjs/toolkit'\n\nimport { type Operation } from 'ot-json0'\n\nimport { type PropControllerMessage } from '../prop-controllers/instances'\nimport { type APIResource, APIResourceLocale } from '../api/types'\n\nimport { BuilderEditMode } from './modules/builder-edit-mode'\nimport { type Point } from './modules/pointer'\n\nimport { type SharedAction, SharedActionTypes } from './shared-api'\n\nexport const HostActionTypes = {\n ...SharedActionTypes,\n\n INIT: 'INIT',\n CLEAN_UP: 'CLEAN_UP',\n\n CHANGE_DOCUMENT: 'CHANGE_DOCUMENT',\n\n CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP: 'CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP',\n SCROLL_DOCUMENT_ELEMENT: 'SCROLL_DOCUMENT_ELEMENT',\n\n MESSAGE_HOST_PROP_CONTROLLER: 'MESSAGE_HOST_PROP_CONTROLLER',\n\n CHANGE_API_RESOURCE: 'CHANGE_API_RESOURCE',\n EVICT_API_RESOURCE: 'EVICT_API_RESOURCE',\n\n SET_BUILDER_EDIT_MODE: 'SET_BUILDER_EDIT_MODE',\n SET_LOCALIZED_RESOURCE_ID: 'SET_LOCALIZED_RESOURCE_ID',\n\n BUILDER_POINTER_MOVE: 'BUILDER_POINTER_MOVE',\n} as const\n\ntype InitAction = { type: typeof HostActionTypes.INIT }\n\ntype CleanUpAction = { type: typeof HostActionTypes.CLEAN_UP }\n\ntype ChangeDocumentAction = {\n type: typeof HostActionTypes.CHANGE_DOCUMENT\n payload: { documentKey: string; operation: Operation }\n}\n\ntype ChangeDocumentElementScrollTopAction = {\n type: typeof HostActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP\n payload: { scrollTop: number }\n}\n\ntype ScrollDocumentElementAction = {\n type: typeof HostActionTypes.SCROLL_DOCUMENT_ELEMENT\n payload: { scrollTopDelta: number }\n}\n\ntype MessageHostPropControllerAction<T = PropControllerMessage> = {\n type: typeof HostActionTypes.MESSAGE_HOST_PROP_CONTROLLER\n payload: { documentKey: string; elementKey: string; propName: string; message: T }\n}\n\ntype ChangeAPIResourceAction = {\n type: typeof HostActionTypes.CHANGE_API_RESOURCE\n payload: { resource: APIResource; locale?: string | null }\n}\n\ntype EvictAPIResourceAction = {\n type: typeof HostActionTypes.EVICT_API_RESOURCE\n payload: { id: string; locale?: string | null }\n}\n\ntype SetBuilderEditModeAction = {\n type: typeof HostActionTypes.SET_BUILDER_EDIT_MODE\n payload: { editMode: BuilderEditMode }\n}\n\ntype SetLocalizedResourceIdAction = {\n type: typeof HostActionTypes.SET_LOCALIZED_RESOURCE_ID\n // TODO: make `locale` required once we've upgraded the builder to always provide it\n payload: { locale?: string; resourceId: string; localizedResourceId: string | null }\n}\n\ntype BuilderPointerMoveAction = {\n type: typeof HostActionTypes.BUILDER_POINTER_MOVE\n payload: { pointer: Point | null }\n}\n\nexport type HostAction =\n | SharedAction\n | InitAction\n | CleanUpAction\n | ChangeDocumentAction\n | ChangeDocumentElementScrollTopAction\n | ScrollDocumentElementAction\n | MessageHostPropControllerAction\n | ChangeAPIResourceAction\n | EvictAPIResourceAction\n | SetBuilderEditModeAction\n | SetLocalizedResourceIdAction\n | BuilderPointerMoveAction\n\nexport function init(): InitAction {\n return { type: HostActionTypes.INIT }\n}\n\nexport function cleanUp(): CleanUpAction {\n return { type: HostActionTypes.CLEAN_UP }\n}\n\nexport function changeDocument(documentKey: string, operation: Operation): ChangeDocumentAction {\n return { type: HostActionTypes.CHANGE_DOCUMENT, payload: { documentKey, operation } }\n}\n\nexport function changeDocumentElementScrollTop(\n scrollTop: number,\n): ChangeDocumentElementScrollTopAction {\n return { type: HostActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP, payload: { scrollTop } }\n}\n\nexport function scrollDocumentElement(scrollTopDelta: number): ScrollDocumentElementAction {\n return { type: HostActionTypes.SCROLL_DOCUMENT_ELEMENT, payload: { scrollTopDelta } }\n}\n\nexport function messageHostPropController<T>(\n documentKey: string,\n elementKey: string,\n propName: string,\n message: T,\n): MessageHostPropControllerAction<T> {\n return {\n type: HostActionTypes.MESSAGE_HOST_PROP_CONTROLLER,\n payload: { documentKey, elementKey, propName, message },\n }\n}\n\nexport function changeApiResource<R extends APIResource>(\n resource: R,\n locale?: APIResourceLocale<R>,\n): ChangeAPIResourceAction {\n return { type: HostActionTypes.CHANGE_API_RESOURCE, payload: { resource, locale } }\n}\n\nexport function evictApiResource(id: string, locale?: string | null): EvictAPIResourceAction {\n return { type: HostActionTypes.EVICT_API_RESOURCE, payload: { id, locale } }\n}\n\nexport function setBuilderEditMode(editMode: BuilderEditMode): SetBuilderEditModeAction {\n return {\n type: HostActionTypes.SET_BUILDER_EDIT_MODE,\n payload: { editMode },\n }\n}\n\nexport function setLocalizedResourceId({\n resourceId,\n localizedResourceId,\n locale,\n}: {\n resourceId: string\n localizedResourceId: string | null\n locale?: string\n}): SetLocalizedResourceIdAction {\n return {\n type: HostActionTypes.SET_LOCALIZED_RESOURCE_ID,\n payload: { resourceId, localizedResourceId, locale },\n }\n}\n\nexport function builderPointerMove(pointer: Point | null): BuilderPointerMoveAction {\n return { type: HostActionTypes.BUILDER_POINTER_MOVE, payload: { pointer } }\n}\n\nexport function isHostAction(action: unknown): action is HostAction {\n return isAction(action) && Object.hasOwn(HostActionTypes, action.type)\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AAUzB,SAA4B,yBAAyB;AAE9C,MAAM,kBAAkB;AAAA,EAC7B,GAAG;AAAA,EAEH,MAAM;AAAA,EACN,UAAU;AAAA,EAEV,iBAAiB;AAAA,EAEjB,oCAAoC;AAAA,EACpC,yBAAyB;AAAA,EAEzB,8BAA8B;AAAA,EAE9B,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EAEpB,uBAAuB;AAAA,EACvB,2BAA2B;AAAA,EAE3B,sBAAsB;AACxB;AAkEO,SAAS,OAAmB;AACjC,SAAO,EAAE,MAAM,gBAAgB,KAAK;AACtC;AAEO,SAAS,UAAyB;AACvC,SAAO,EAAE,MAAM,gBAAgB,SAAS;AAC1C;AAEO,SAAS,eAAe,aAAqB,WAA4C;AAC9F,SAAO,EAAE,MAAM,gBAAgB,iBAAiB,SAAS,EAAE,aAAa,UAAU,EAAE;AACtF;AAEO,SAAS,+BACd,WACsC;AACtC,SAAO,EAAE,MAAM,gBAAgB,oCAAoC,SAAS,EAAE,UAAU,EAAE;AAC5F;AAEO,SAAS,sBAAsB,gBAAqD;AACzF,SAAO,EAAE,MAAM,gBAAgB,yBAAyB,SAAS,EAAE,eAAe,EAAE;AACtF;AAEO,SAAS,0BACd,aACA,YACA,UACA,SACoC;AACpC,SAAO;AAAA,IACL,MAAM,gBAAgB;AAAA,IACtB,SAAS,EAAE,aAAa,YAAY,UAAU,QAAQ;AAAA,EACxD;AACF;AAEO,SAAS,kBACd,UACA,QACyB;AACzB,SAAO,EAAE,MAAM,gBAAgB,qBAAqB,SAAS,EAAE,UAAU,OAAO,EAAE;AACpF;AAEO,SAAS,iBAAiB,IAAY,QAAgD;AAC3F,SAAO,EAAE,MAAM,gBAAgB,oBAAoB,SAAS,EAAE,IAAI,OAAO,EAAE;AAC7E;AAEO,SAAS,mBAAmB,UAAqD;AACtF,SAAO;AAAA,IACL,MAAM,gBAAgB;AAAA,IACtB,SAAS,EAAE,SAAS;AAAA,EACtB;AACF;AAEO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACF,GAIiC;AAC/B,SAAO;AAAA,IACL,MAAM,gBAAgB;AAAA,IACtB,SAAS,EAAE,YAAY,qBAAqB,OAAO;AAAA,EACrD;AACF;AAEO,SAAS,mBAAmB,SAAiD;AAClF,SAAO,EAAE,MAAM,gBAAgB,sBAAsB,SAAS,EAAE,QAAQ,EAAE;AAC5E;AAEO,SAAS,aAAa,QAAuC;AAClE,SAAO,SAAS,MAAM,KAAK,OAAO,OAAO,iBAAiB,OAAO,IAAI;AACvE;","names":[]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import * as APIResources from "./modules/api-resources";
|
|
6
6
|
import * as LocalizedResourcesMap from "./modules/localized-resources-map";
|
|
7
7
|
import { ActionTypes } from "./actions";
|
|
8
|
-
import { apiResourceFulfilled } from "./actions/internal
|
|
8
|
+
import { apiResourceFulfilled } from "./actions/internal";
|
|
9
9
|
import { setLocalizedResourceId } from "./host-api";
|
|
10
10
|
import { actionMiddleware, middlewareOptions, devToolsConfig } from "./toolkit";
|
|
11
11
|
import {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchJson = async <T>(url: string): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AACvC,SAAsB,mBAAmB;AACzC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE;AAAA,EACE;AAAA,OAUK;AAEP,MAAM,UAAU,gBAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC9F;AACF;AAEO,SAAS,eACd,OACA,cACA,YACA,QACgD;A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AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,aAAa,CAAC;AAAA,IAEvF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes } from './actions'\nimport { apiResourceFulfilled } from './actions/internal'\nimport { setLocalizedResourceId } from './host-api'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../api'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchJson = async <T>(url: string): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AACvC,SAAsB,mBAAmB;AACzC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE;AAAA,EACE;AAAA,OAUK;AAEP,MAAM,UAAU,gBAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3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AAA,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,aAAS,qBAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;AAIA,SAAS,wBACP,eACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS,EAAE,GAAG,OAAO,SAAS,QAAQ,UAAU,cAAc;AAAA,UAChE,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,aAAa,CAAC;AAAA,IAEvF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -3,10 +3,7 @@ import {
|
|
|
3
3
|
LocalizableAPIResourceType
|
|
4
4
|
} from "../../api";
|
|
5
5
|
import deepEqual from "../../utils/deepEqual";
|
|
6
|
-
import { isKnownAction } from "../actions";
|
|
7
|
-
import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
|
|
8
|
-
import { ReadWriteActionTypes } from "../actions/internal/read-write-actions";
|
|
9
|
-
import { HostActionTypes } from "../host-api";
|
|
6
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
10
7
|
function isValidAPIResourceType(resourceType) {
|
|
11
8
|
return resourceType in APIResourceType;
|
|
12
9
|
}
|
|
@@ -85,7 +82,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
85
82
|
if (!isKnownAction(action))
|
|
86
83
|
return state;
|
|
87
84
|
switch (action.type) {
|
|
88
|
-
case
|
|
85
|
+
case ActionTypes.UPDATE_API_CLIENT_CACHE: {
|
|
89
86
|
const { apiResources } = action.payload;
|
|
90
87
|
return Object.entries(apiResources).reduce((state2, [resourceType, cachedResources]) => {
|
|
91
88
|
const resType = resourceType;
|
|
@@ -98,7 +95,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
98
95
|
return updated == null || updated === existing ? state2 : new Map(state2).set(resType, updated);
|
|
99
96
|
}, state);
|
|
100
97
|
}
|
|
101
|
-
case
|
|
98
|
+
case ActionTypes.API_RESOURCE_FULFILLED: {
|
|
102
99
|
const { resourceType, resourceId, resource, locale } = action.payload;
|
|
103
100
|
return new Map(state).set(
|
|
104
101
|
resourceType,
|
|
@@ -108,7 +105,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
108
105
|
)
|
|
109
106
|
);
|
|
110
107
|
}
|
|
111
|
-
case
|
|
108
|
+
case ActionTypes.CHANGE_API_RESOURCE: {
|
|
112
109
|
const { resource, locale } = action.payload;
|
|
113
110
|
const existingApiResource = getAPIResource(state, resource.__typename, resource.id, locale);
|
|
114
111
|
if (deepEqual(existingApiResource, resource))
|
|
@@ -121,7 +118,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
121
118
|
)
|
|
122
119
|
);
|
|
123
120
|
}
|
|
124
|
-
case
|
|
121
|
+
case ActionTypes.EVICT_API_RESOURCE: {
|
|
125
122
|
const { id, locale } = action.payload;
|
|
126
123
|
const [resourceType, resourceId] = id.split(":");
|
|
127
124
|
if (!isValidAPIResourceType(resourceType))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/api-resources.ts"],"sourcesContent":["import {\n APIResourceType,\n APIResourceLocale,\n LocalizableAPIResourceType,\n type APIResource,\n} from '../../api'\n\nimport deepEqual from '../../utils/deepEqual'\nimport { Branded } from '../../utils/branded'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\nimport { ReadWriteActionTypes } from '../actions/internal/read-write-actions'\nimport { HostActionTypes } from '../host-api'\n\ntype CompositeResourceId = Branded<string, 'CompositeResourceId'>\n\nfunction isValidAPIResourceType(resourceType: string): resourceType is APIResourceType {\n return resourceType in APIResourceType\n}\n\nfunction isLocalizableAPIResourceType(\n resourceType: APIResourceType,\n): resourceType is LocalizableAPIResourceType {\n return resourceType in LocalizableAPIResourceType\n}\n\nfunction compositeId(\n resourceId: string,\n resourceType: APIResourceType,\n locale?: string | null,\n): CompositeResourceId {\n return (\n locale != null && isLocalizableAPIResourceType(resourceType)\n ? `${resourceId}@${locale}`\n : resourceId\n ) as CompositeResourceId\n}\n\nfunction parseCompositeId(compositeId: CompositeResourceId): [string, string | null] {\n const [resourceId, locale] = compositeId.split('@')\n return [resourceId, locale ?? null]\n}\n\nexport type State = Map<APIResourceType, Map<CompositeResourceId, APIResource | null>>\n\nexport type SerializedState = {\n [key in APIResourceType]?: {\n id: string\n value: Extract<APIResource, { __typename: key }> | null\n locale?: APIResourceLocale<key>\n }[]\n}\n\nexport function getInitialState(\n serializedState: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n },\n): State {\n return new Map(\n Object.entries(serializedState).map(([resourceType, resources]) => [\n resourceType,\n new Map(\n resources.map(({ id, value, locale }) => [\n compositeId(id, resourceType as APIResourceType, locale),\n value,\n ]),\n ),\n ]),\n ) as State\n}\n\nexport function getSerializedState(state: State): SerializedState {\n const resourceMap: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n }\n\n Array.from(state.entries()).forEach(([resourceType, resources]) => {\n const particularResourceMap: { id: string; value: any; locale?: any }[] = []\n\n Array.from(resources.entries()).forEach(([compositeId, value]) => {\n if (value != null) {\n const [id, locale] = parseCompositeId(compositeId)\n console.assert(\n locale == null || isLocalizableAPIResourceType(resourceType),\n `Unexpected locale for non-localizable resource type ${resourceType}`,\n { id, locale },\n )\n\n particularResourceMap.push(locale != null ? { id, value, locale } : { id, value })\n }\n })\n\n resourceMap[resourceType] = particularResourceMap\n })\n\n return resourceMap\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n return state.get(resourceType)?.has(compositeId(resourceId, resourceType, locale)) ?? false\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n const resource = state.get(resourceType)?.get(compositeId(resourceId, resourceType, locale))\n\n return resource?.__typename === resourceType\n ? (resource as Extract<typeof resource, { __typename: T }>)\n : 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 ReadWriteActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { apiResources } = action.payload\n\n return Object.entries(apiResources).reduce((state, [resourceType, cachedResources]) => {\n const resType = resourceType as APIResourceType\n const cached:\n | { id: string; value: APIResource | null; locale?: string | null }[]\n | undefined = cachedResources\n\n const existing = state.get(resType) ?? new Map<CompositeResourceId, APIResource | null>()\n const updated = cached?.reduce((r, { id, value, locale }) => {\n const cid = compositeId(id, resType, locale)\n return r.get(cid) != null ? r : new Map(r).set(cid, value)\n }, existing)\n\n return updated == null || updated === existing\n ? state\n : new Map(state).set(resType, updated)\n }, state)\n }\n\n case ReadOnlyActionTypes.API_RESOURCE_FULFILLED: {\n const { resourceType, resourceId, resource, locale } = action.payload\n return new Map(state).set(\n resourceType,\n new Map(state.get(resourceType)!).set(\n compositeId(resourceId, resourceType, locale),\n resource,\n ),\n )\n }\n\n case HostActionTypes.CHANGE_API_RESOURCE: {\n const { resource, locale } = action.payload\n const existingApiResource = getAPIResource(state, resource.__typename, resource.id, locale)\n\n if (deepEqual(existingApiResource, resource)) return state\n\n return new Map(state).set(\n resource.__typename,\n new Map(state.get(resource.__typename)!).set(\n compositeId(resource.id, resource.__typename, locale),\n resource,\n ),\n )\n }\n\n case HostActionTypes.EVICT_API_RESOURCE: {\n const { id, locale } = action.payload\n const [resourceType, resourceId] = id.split(':')\n\n if (!isValidAPIResourceType(resourceType)) return state\n\n const resources = new Map(state.get(resourceType as APIResourceType)!)\n\n const deleted = resources.delete(compositeId(resourceId, resourceType, locale))\n\n return deleted ? new Map(state).set(resourceType as APIResourceType, resources) : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AAEP,OAAO,eAAe;AAGtB,SAA0C,qBAAqB;AAC/D,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAIhC,SAAS,uBAAuB,cAAuD;AACrF,SAAO,gBAAgB;AACzB;AAEA,SAAS,6BACP,cAC4C;AAC5C,SAAO,gBAAgB;AACzB;AAEA,SAAS,YACP,YACA,cACA,QACqB;AACrB,SACE,UAAU,QAAQ,6BAA6B,YAAY,IACvD,GAAG,UAAU,IAAI,MAAM,KACvB;AAER;AAEA,SAAS,iBAAiBA,cAA2D;AACnF,QAAM,CAAC,YAAY,MAAM,IAAIA,aAAY,MAAM,GAAG;AAClD,SAAO,CAAC,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oBAAoB,wBAAwB;AAC/C,YAAM,EAAE,cAAc,YAAY,UAAU,OAAO,IAAI,OAAO;AAC9D,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB;AAAA,QACA,IAAI,IAAI,MAAM,IAAI,YAAY,CAAE,EAAE;AAAA,UAChC,YAAY,YAAY,cAAc,MAAM;AAAA,UAC5C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,gBAAgB,qBAAqB;AACxC,YAAM,EAAE,UAAU,OAAO,IAAI,OAAO;AACpC,YAAM,sBAAsB,eAAe,OAAO,SAAS,YAAY,SAAS,IAAI,MAAM;AAE1F,UAAI,UAAU,qBAAqB,QAAQ;AAAG,eAAO;AAErD,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB,SAAS;AAAA,QACT,IAAI,IAAI,MAAM,IAAI,SAAS,UAAU,CAAE,EAAE;AAAA,UACvC,YAAY,SAAS,IAAI,SAAS,YAAY,MAAM;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,gBAAgB,oBAAoB;AACvC,YAAM,EAAE,IAAI,OAAO,IAAI,OAAO;AAC9B,YAAM,CAAC,cAAc,UAAU,IAAI,GAAG,MAAM,GAAG;AAE/C,UAAI,CAAC,uBAAuB,YAAY;AAAG,eAAO;AAElD,YAAM,YAAY,IAAI,IAAI,MAAM,IAAI,YAA+B,CAAE;AAErE,YAAM,UAAU,UAAU,OAAO,YAAY,YAAY,cAAc,MAAM,CAAC;AAE9E,aAAO,UAAU,IAAI,IAAI,KAAK,EAAE,IAAI,cAAiC,SAAS,IAAI;AAAA,IACpF;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["compositeId","state"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/api-resources.ts"],"sourcesContent":["import {\n APIResourceType,\n APIResourceLocale,\n LocalizableAPIResourceType,\n type APIResource,\n} from '../../api'\n\nimport deepEqual from '../../utils/deepEqual'\nimport { Branded } from '../../utils/branded'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\ntype CompositeResourceId = Branded<string, 'CompositeResourceId'>\n\nfunction isValidAPIResourceType(resourceType: string): resourceType is APIResourceType {\n return resourceType in APIResourceType\n}\n\nfunction isLocalizableAPIResourceType(\n resourceType: APIResourceType,\n): resourceType is LocalizableAPIResourceType {\n return resourceType in LocalizableAPIResourceType\n}\n\nfunction compositeId(\n resourceId: string,\n resourceType: APIResourceType,\n locale?: string | null,\n): CompositeResourceId {\n return (\n locale != null && isLocalizableAPIResourceType(resourceType)\n ? `${resourceId}@${locale}`\n : resourceId\n ) as CompositeResourceId\n}\n\nfunction parseCompositeId(compositeId: CompositeResourceId): [string, string | null] {\n const [resourceId, locale] = compositeId.split('@')\n return [resourceId, locale ?? null]\n}\n\nexport type State = Map<APIResourceType, Map<CompositeResourceId, APIResource | null>>\n\nexport type SerializedState = {\n [key in APIResourceType]?: {\n id: string\n value: Extract<APIResource, { __typename: key }> | null\n locale?: APIResourceLocale<key>\n }[]\n}\n\nexport function getInitialState(\n serializedState: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n },\n): State {\n return new Map(\n Object.entries(serializedState).map(([resourceType, resources]) => [\n resourceType,\n new Map(\n resources.map(({ id, value, locale }) => [\n compositeId(id, resourceType as APIResourceType, locale),\n value,\n ]),\n ),\n ]),\n ) as State\n}\n\nexport function getSerializedState(state: State): SerializedState {\n const resourceMap: SerializedState = {\n Swatch: [],\n File: [],\n Typography: [],\n PagePathnameSlice: [],\n GlobalElement: [],\n Table: [],\n Snippet: [],\n Page: [],\n Site: [],\n LocalizedGlobalElement: [],\n }\n\n Array.from(state.entries()).forEach(([resourceType, resources]) => {\n const particularResourceMap: { id: string; value: any; locale?: any }[] = []\n\n Array.from(resources.entries()).forEach(([compositeId, value]) => {\n if (value != null) {\n const [id, locale] = parseCompositeId(compositeId)\n console.assert(\n locale == null || isLocalizableAPIResourceType(resourceType),\n `Unexpected locale for non-localizable resource type ${resourceType}`,\n { id, locale },\n )\n\n particularResourceMap.push(locale != null ? { id, value, locale } : { id, value })\n }\n })\n\n resourceMap[resourceType] = particularResourceMap\n })\n\n return resourceMap\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n return state.get(resourceType)?.has(compositeId(resourceId, resourceType, locale)) ?? false\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n const resource = state.get(resourceType)?.get(compositeId(resourceId, resourceType, locale))\n\n return resource?.__typename === resourceType\n ? (resource as Extract<typeof resource, { __typename: T }>)\n : 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 ActionTypes.UPDATE_API_CLIENT_CACHE: {\n const { apiResources } = action.payload\n\n return Object.entries(apiResources).reduce((state, [resourceType, cachedResources]) => {\n const resType = resourceType as APIResourceType\n const cached:\n | { id: string; value: APIResource | null; locale?: string | null }[]\n | undefined = cachedResources\n\n const existing = state.get(resType) ?? new Map<CompositeResourceId, APIResource | null>()\n const updated = cached?.reduce((r, { id, value, locale }) => {\n const cid = compositeId(id, resType, locale)\n return r.get(cid) != null ? r : new Map(r).set(cid, value)\n }, existing)\n\n return updated == null || updated === existing\n ? state\n : new Map(state).set(resType, updated)\n }, state)\n }\n\n case ActionTypes.API_RESOURCE_FULFILLED: {\n const { resourceType, resourceId, resource, locale } = action.payload\n return new Map(state).set(\n resourceType,\n new Map(state.get(resourceType)!).set(\n compositeId(resourceId, resourceType, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.CHANGE_API_RESOURCE: {\n const { resource, locale } = action.payload\n const existingApiResource = getAPIResource(state, resource.__typename, resource.id, locale)\n\n if (deepEqual(existingApiResource, resource)) return state\n\n return new Map(state).set(\n resource.__typename,\n new Map(state.get(resource.__typename)!).set(\n compositeId(resource.id, resource.__typename, locale),\n resource,\n ),\n )\n }\n\n case ActionTypes.EVICT_API_RESOURCE: {\n const { id, locale } = action.payload\n const [resourceType, resourceId] = id.split(':')\n\n if (!isValidAPIResourceType(resourceType)) return state\n\n const resources = new Map(state.get(resourceType as APIResourceType)!)\n\n const deleted = resources.delete(compositeId(resourceId, resourceType, locale))\n\n return deleted ? new Map(state).set(resourceType as APIResourceType, resources) : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AAEP,OAAO,eAAe;AAGtB,SAA0C,aAAa,qBAAqB;AAI5E,SAAS,uBAAuB,cAAuD;AACrF,SAAO,gBAAgB;AACzB;AAEA,SAAS,6BACP,cAC4C;AAC5C,SAAO,gBAAgB;AACzB;AAEA,SAAS,YACP,YACA,cACA,QACqB;AACrB,SACE,UAAU,QAAQ,6BAA6B,YAAY,IACvD,GAAG,UAAU,IAAI,MAAM,KACvB;AAER;AAEA,SAAS,iBAAiBA,cAA2D;AACnF,QAAM,CAAC,YAAY,MAAM,IAAIA,aAAY,MAAM,GAAG;AAClD,SAAO,CAAC,YAAY,UAAU,IAAI;AACpC;AAYO,SAAS,gBACd,kBAAmC;AAAA,EACjC,QAAQ,CAAC;AAAA,EACT,MAAM,CAAC;AAAA,EACP,YAAY,CAAC;AAAA,EACb,mBAAmB,CAAC;AAAA,EACpB,eAAe,CAAC;AAAA,EAChB,OAAO,CAAC;AAAA,EACR,SAAS,CAAC;AAAA,EACV,MAAM,CAAC;AAAA,EACP,MAAM,CAAC;AAAA,EACP,wBAAwB,CAAC;AAC3B,GACO;AACP,SAAO,IAAI;AAAA,IACT,OAAO,QAAQ,eAAe,EAAE,IAAI,CAAC,CAAC,cAAc,SAAS,MAAM;AAAA,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AAI,UAAU,qBAAqB,QAAQ;AAAG,eAAO;AAErD,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB,SAAS;AAAA,QACT,IAAI,IAAI,MAAM,IAAI,SAAS,UAAU,CAAE,EAAE;AAAA,UACvC,YAAY,SAAS,IAAI,SAAS,YAAY,MAAM;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,KAAK,YAAY,oBAAoB;AACnC,YAAM,EAAE,IAAI,OAAO,IAAI,OAAO;AAC9B,YAAM,CAAC,cAAc,UAAU,IAAI,GAAG,MAAM,GAAG;AAE/C,UAAI,CAAC,uBAAuB,YAAY;AAAG,eAAO;AAElD,YAAM,YAAY,IAAI,IAAI,MAAM,IAAI,YAA+B,CAAE;AAErE,YAAM,UAAU,UAAU,OAAO,YAAY,YAAY,cAAc,MAAM,CAAC;AAE9E,aAAO,UAAU,IAAI,IAAI,KAAK,EAAE,IAAI,cAAiC,SAAS,IAAI;AAAA,IACpF;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":["compositeId","state"]}
|
|
@@ -3,9 +3,7 @@ import {
|
|
|
3
3
|
getBox as getBoxWithoutScroll,
|
|
4
4
|
withScroll
|
|
5
5
|
} from "css-box-model";
|
|
6
|
-
import { isKnownAction } from "
|
|
7
|
-
import { ReadWriteActionTypes } from "../../actions/internal/read-write-actions";
|
|
8
|
-
import { BuilderActionTypes } from "../../builder-api/actions";
|
|
6
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
9
7
|
function parse(rawString) {
|
|
10
8
|
const value = Number(rawString.replace(/px$/, ""));
|
|
11
9
|
return Number.isFinite(value) ? value : 0;
|
|
@@ -45,7 +43,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
45
43
|
if (!isKnownAction(action))
|
|
46
44
|
return state;
|
|
47
45
|
switch (action.type) {
|
|
48
|
-
case
|
|
46
|
+
case ActionTypes.REGISTER_MEASURABLE: {
|
|
49
47
|
const { documentKey, elementKey, measurable } = action.payload;
|
|
50
48
|
return {
|
|
51
49
|
...state,
|
|
@@ -55,13 +53,13 @@ function reducer(state = getInitialState(), action) {
|
|
|
55
53
|
)
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
|
-
case
|
|
56
|
+
case ActionTypes.UNREGISTER_MEASURABLE: {
|
|
59
57
|
const { documentKey, elementKey } = action.payload;
|
|
60
58
|
const nextMeasurables = new Map(state.measurables.get(documentKey) ?? []);
|
|
61
59
|
const deleted = nextMeasurables.delete(elementKey);
|
|
62
60
|
return deleted ? { ...state, measurables: new Map(state.measurables).set(documentKey, nextMeasurables) } : state;
|
|
63
61
|
}
|
|
64
|
-
case
|
|
62
|
+
case ActionTypes.CHANGE_ELEMENT_BOX_MODELS: {
|
|
65
63
|
const { changedElementBoxModels } = action.payload;
|
|
66
64
|
if (changedElementBoxModels.size === 0)
|
|
67
65
|
return state;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/box-models.ts"],"sourcesContent":["import { type BoxModel } from '@makeswift/controls'\nimport {\n createBox as createBoxWithoutScroll,\n CreateBoxArgs,\n getBox as getBoxWithoutScroll,\n withScroll,\n} from 'css-box-model'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport type { BoxModel }\n\nexport function parse(rawString: string): number {\n const value = Number(rawString.replace(/px$/, ''))\n\n return Number.isFinite(value) ? value : 0\n}\n\nexport function createBox(boxArgs: CreateBoxArgs): BoxModel {\n return withScroll(createBoxWithoutScroll(boxArgs))\n}\n\nexport function getBox(element: Element): BoxModel {\n return withScroll(getBoxWithoutScroll(element))\n}\n\nexport interface BoxModelHandle {\n getBoxModel(): BoxModel | null\n}\n\nexport type Measurable = Element | BoxModelHandle\n\nexport function isMeasurable(value: unknown): value is Measurable {\n if (value instanceof Element) return true\n\n if (\n typeof value === 'object' &&\n value !== null &&\n 'getBoxModel' in value &&\n typeof (value as { getBoxModel: unknown }).getBoxModel === 'function'\n ) {\n return true\n }\n\n return false\n}\n\nexport function measure(measurable: Measurable): BoxModel | null {\n if (measurable instanceof Element) return getBox(measurable)\n\n return measurable.getBoxModel()\n}\n\nexport type State = {\n measurables: Map<string, Map<string, Measurable>>\n boxModels: Map<string, Map<string, BoxModel>>\n}\n\nexport function getInitialState(): State {\n return { measurables: new Map(), boxModels: new Map() }\n}\n\nexport function getMeasurables(state: State): Map<string, Map<string, Measurable>> {\n return state.measurables\n}\n\nexport function getBoxModels(state: State): Map<string, Map<string, BoxModel>> {\n return state.boxModels\n}\n\nexport function getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModel | null {\n return getBoxModels(state).get(documentKey)?.get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction) {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ActionTypes.REGISTER_MEASURABLE: {\n const { documentKey, elementKey, measurable } = action.payload\n\n return {\n ...state,\n measurables: new Map(state.measurables).set(\n documentKey,\n new Map(state.measurables.get(documentKey) ?? []).set(elementKey, measurable),\n ),\n }\n }\n\n case ActionTypes.UNREGISTER_MEASURABLE: {\n const { documentKey, elementKey } = action.payload\n const nextMeasurables = new Map(state.measurables.get(documentKey) ?? [])\n\n const deleted = nextMeasurables.delete(elementKey)\n\n return deleted\n ? { ...state, measurables: new Map(state.measurables).set(documentKey, nextMeasurables) }\n : state\n }\n\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS: {\n const { changedElementBoxModels } = action.payload\n\n if (changedElementBoxModels.size === 0) return state\n\n const nextBoxModels = new Map(state.boxModels)\n\n changedElementBoxModels.forEach((changedBoxModels, documentKey) => {\n const nextDocumentBoxModels = new Map(nextBoxModels.get(documentKey) ?? [])\n\n changedBoxModels.forEach((changedBoxModel, elementKey) => {\n if (changedBoxModel == null) nextDocumentBoxModels.delete(elementKey)\n else nextDocumentBoxModels.set(elementKey, changedBoxModel)\n })\n\n if (nextDocumentBoxModels.size > 0) nextBoxModels.set(documentKey, nextDocumentBoxModels)\n else nextBoxModels.delete(documentKey)\n })\n\n return { ...state, boxModels: nextBoxModels }\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AACA;AAAA,EACE,aAAa;AAAA,EAEb,UAAU;AAAA,EACV;AAAA,OACK;AAEP,SAA0C,aAAa,qBAAqB;AAIrE,SAAS,MAAM,WAA2B;AAC/C,QAAM,QAAQ,OAAO,UAAU,QAAQ,OAAO,EAAE,CAAC;AAEjD,SAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;AAEO,SAAS,UAAU,SAAkC;AAC1D,SAAO,WAAW,uBAAuB,OAAO,CAAC;AACnD;AAEO,SAAS,OAAO,SAA4B;AACjD,SAAO,WAAW,oBAAoB,OAAO,CAAC;AAChD;AAQO,SAAS,aAAa,OAAqC;AAChE,MAAI,iBAAiB;AAAS,WAAO;AAErC,MACE,OAAO,UAAU,YACjB,UAAU,QACV,iBAAiB,SACjB,OAAQ,MAAmC,gBAAgB,YAC3D;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,QAAQ,YAAyC;AAC/D,MAAI,sBAAsB;AAAS,WAAO,OAAO,UAAU;AAE3D,SAAO,WAAW,YAAY;AAChC;AAOO,SAAS,kBAAyB;AACvC,SAAO,EAAE,aAAa,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE;AACxD;AAEO,SAAS,eAAe,OAAoD;AACjF,SAAO,MAAM;AACf;AAEO,SAAS,aAAa,OAAkD;AAC7E,SAAO,MAAM;AACf;AAEO,SAAS,YACd,OACA,aACA,YACiB;AACjB,SAAO,aAAa,KAAK,EAAE,IAAI,WAAW,GAAG,IAAI,UAAU,KAAK;AAClE;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAgC;AACxF,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,YAAY,qBAAqB;AACpC,YAAM,EAAE,aAAa,YAAY,W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import { BuilderActionTypes } from "../builder-api/actions";
|
|
1
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
3
2
|
import {
|
|
4
3
|
getBreakpoint
|
|
5
4
|
} from "@makeswift/controls";
|
|
@@ -35,7 +34,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
35
34
|
if (!isKnownAction(action))
|
|
36
35
|
return state;
|
|
37
36
|
switch (action.type) {
|
|
38
|
-
case
|
|
37
|
+
case ActionTypes.SET_BREAKPOINTS: {
|
|
39
38
|
const breakpoints = action.payload.breakpoints;
|
|
40
39
|
if (breakpoints.length === 0)
|
|
41
40
|
throw new Error("Breakpoints cannot be empty.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { type Breakpoint, type Breakpoints } from '@makeswift/controls'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { type Breakpoint, type Breakpoints } from '@makeswift/controls'\n\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport {\n getBreakpoint,\n type Breakpoint,\n type BreakpointId,\n type Breakpoints,\n} from '@makeswift/controls'\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = (typeof DefaultBreakpointID)[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\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 ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width.\n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n"],"mappings":"AAEA,SAA0C,aAAa,qBAAqB;AAE5E;AAAA,EACE;AAAA,OAIK;AAIA,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,gBAAgB,cAAc,qBAA4B;AACxE,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,YAAY,iBAAiB;AAChC,YAAM,cAAc,OAAO,QAAQ;AAEnC,UAAI,YAAY,WAAW;AAAG,cAAM,IAAI,MAAM,8BAA8B;AAE5E,aAAO;AAAA,IACT;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;AAIO,SAAS,sBAAsB,OAAsC;AAC1E,2BAAyB,KAAK;AAE9B,QAAM,SAAS,OAAO,QAAQ,KAAK,EAChC,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,GAAG,OAAO,GAAG,EAAE,EACvC,KAAK,CAAC,GAAG,M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OAAO;AAC7C,YAAM,IAAI;AAAA,QACR,wBAAwB,EAAE;AAAA,WACvB,EAAE,uBAAuB,QAAQ,+BAA+B,KAAK,EAAE,oBAAoB,KAAK,KAAK;AAAA,MAC1G;AAAA,IACF;AAEA,QAAI,QAAQ,UAAU,KAAK,OAAO;AAChC,YAAM,IAAI;AAAA,QACR,4CAA4C,EAAE,UAAU,KAAK,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { isKnownAction } from "../actions";
|
|
2
|
-
import { HostActionTypes } from "../host-api";
|
|
1
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
3
2
|
const BuilderEditMode = {
|
|
4
3
|
BUILD: "build",
|
|
5
4
|
CONTENT: "content",
|
|
@@ -12,7 +11,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
12
11
|
if (!isKnownAction(action))
|
|
13
12
|
return state;
|
|
14
13
|
switch (action.type) {
|
|
15
|
-
case
|
|
14
|
+
case ActionTypes.SET_BUILDER_EDIT_MODE:
|
|
16
15
|
return action.payload.editMode;
|
|
17
16
|
default:
|
|
18
17
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/builder-edit-mode.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/builder-edit-mode.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport const BuilderEditMode = {\n BUILD: 'build',\n CONTENT: 'content',\n INTERACT: 'interact',\n} as const\n\nexport type BuilderEditMode = (typeof BuilderEditMode)[keyof typeof BuilderEditMode]\n\nexport type State = BuilderEditMode | null\n\nexport function getInitialState(): State {\n return 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 ActionTypes.SET_BUILDER_EDIT_MODE:\n return action.payload.editMode\n\n default:\n return state\n }\n}\n"],"mappings":"AAAA,SAA0C,aAAa,qBAAqB;AAErE,MAAM,kBAAkB;AAAA,EAC7B,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AACZ;AAMO,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,YAAY;AACf,aAAO,OAAO,QAAQ;AAAA,IAExB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { isKnownAction } from "../actions";
|
|
2
|
-
import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
|
|
1
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
3
2
|
const ComponentIcon = {
|
|
4
3
|
Billing: "billing",
|
|
5
4
|
Bolt: "bolt",
|
|
@@ -39,9 +38,9 @@ function reducer(state = getInitialState(), action) {
|
|
|
39
38
|
if (!isKnownAction(action))
|
|
40
39
|
return state;
|
|
41
40
|
switch (action.type) {
|
|
42
|
-
case
|
|
41
|
+
case ActionTypes.REGISTER_COMPONENT:
|
|
43
42
|
return new Map(state).set(action.payload.type, action.payload.meta);
|
|
44
|
-
case
|
|
43
|
+
case ActionTypes.UNREGISTER_COMPONENT: {
|
|
45
44
|
const nextState = new Map(state);
|
|
46
45
|
const deleted = nextState.delete(action.payload.type);
|
|
47
46
|
return deleted ? nextState : state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\nexport const ComponentIcon = {\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Navigation: 'navigation',\n SocialLinks: 'social-links',\n Star: 'star',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? 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 ActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AAAA,SAA0C,aAAa,qBAAqB;AAErE,MAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACT;AAcO,SAAS,gBAAgB;AAAA,EAC9B,iBAAiB,oBAAI,IAAI;AAC3B,IAAqD,CAAC,GAAU;AAC9D,SAAO;AACT;AAEO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO;AACT;AAEO,SAAS,iBAAiB,OAAc,MAAoC;AACjF,SAAO,kBAAkB,KAAK,EAAE,IAAI,IAAI,KAAK;AAC/C;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,YAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,IAAI;AAAA,IAEpE,KAAK,YAAY,sBAAsB;AACrC,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { isKnownAction } from "
|
|
2
|
-
import { ReadOnlyActionTypes } from "../../actions/internal/read-only-actions";
|
|
1
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
3
2
|
function getElementImperativeHandles(state) {
|
|
4
3
|
return state;
|
|
5
4
|
}
|
|
@@ -10,7 +9,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
10
9
|
if (!isKnownAction(action))
|
|
11
10
|
return state;
|
|
12
11
|
switch (action.type) {
|
|
13
|
-
case
|
|
12
|
+
case ActionTypes.REGISTER_COMPONENT_HANDLE:
|
|
14
13
|
return new Map(state).set(
|
|
15
14
|
action.payload.documentKey,
|
|
16
15
|
new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(
|
|
@@ -18,7 +17,7 @@ function reducer(state = getInitialState(), action) {
|
|
|
18
17
|
action.payload.componentHandle
|
|
19
18
|
)
|
|
20
19
|
);
|
|
21
|
-
case
|
|
20
|
+
case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {
|
|
22
21
|
const byElementKey = new Map(state.get(action.payload.documentKey) ?? []);
|
|
23
22
|
const deleted = byElementKey.delete(action.payload.elementKey);
|
|
24
23
|
if (!deleted)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/element-imperative-handles.ts"],"sourcesContent":["import { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\nimport { type Action, type UnknownAction, ActionTypes, isKnownAction } from '../actions'\n\ntype State = Map<string, Map<string, ElementImperativeHandle>>\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return state\n}\n\nfunction getInitialState(): State {\n return new Map()\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 ActionTypes.REGISTER_COMPONENT_HANDLE:\n return new Map(state).set(\n action.payload.documentKey,\n new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const byElementKey = new Map(state.get(action.payload.documentKey) ?? [])\n\n const deleted = byElementKey.delete(action.payload.elementKey)\n\n if (!deleted) return state\n\n return new Map(state).set(action.payload.documentKey, byElementKey)\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AACA,SAA0C,aAAa,qBAAqB;AAIrE,SAAS,4BACd,OACmD;AACnD,SAAO;AACT;AAEA,SAAS,kBAAyB;AAChC,SAAO,oBAAI,IAAI;AACjB;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,YAAY;AACf,aAAO,IAAI,IAAI,KAAK,EAAE;AAAA,QACpB,OAAO,QAAQ;AAAA,QACf,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE;AAAA,UAC5D,OAAO,QAAQ;AAAA,UACf,OAAO,QAAQ;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,YAAY,6BAA6B;AAC5C,YAAM,eAAe,IAAI,IAAI,MAAM,IAAI,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC;AAExE,YAAM,UAAU,aAAa,OAAO,OAAO,QAAQ,UAAU;AAE7D,UAAI,CAAC;AAAS,eAAO;AAErB,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,aAAa,YAAY;AAAA,IACpE;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { getIn } from "immutable";
|
|
2
2
|
import { isElementReference } from "@makeswift/controls";
|
|
3
3
|
import * as Introspection from "../../prop-controllers/introspection";
|
|
4
|
-
import { isKnownAction } from "../actions";
|
|
5
|
-
import { ReadOnlyActionTypes } from "../actions/internal/read-only-actions";
|
|
6
|
-
import { ReadWriteActionTypes } from "../actions/internal/read-write-actions";
|
|
4
|
+
import { ActionTypes, isKnownAction } from "../actions";
|
|
7
5
|
import { getRootElement } from "./read-only-documents";
|
|
8
6
|
function getInitialState(documents, descriptors) {
|
|
9
7
|
const state = /* @__PURE__ */ new Map();
|
|
@@ -33,19 +31,19 @@ function reducer(state = getInitialState(), action) {
|
|
|
33
31
|
if (!isKnownAction(action))
|
|
34
32
|
return state;
|
|
35
33
|
switch (action.type) {
|
|
36
|
-
case
|
|
34
|
+
case ActionTypes.CREATE_ELEMENT_TREE: {
|
|
37
35
|
const { document, descriptors } = action.payload;
|
|
38
36
|
return new Map(state).set(
|
|
39
37
|
document.key,
|
|
40
38
|
buildElementTree(getRootElement(document), descriptors)
|
|
41
39
|
);
|
|
42
40
|
}
|
|
43
|
-
case
|
|
41
|
+
case ActionTypes.DELETE_ELEMENT_TREE: {
|
|
44
42
|
const nextState = new Map(state);
|
|
45
43
|
const deleted = nextState.delete(action.payload.documentKey);
|
|
46
44
|
return deleted ? nextState : state;
|
|
47
45
|
}
|
|
48
|
-
case
|
|
46
|
+
case ActionTypes.CHANGE_ELEMENT_TREE: {
|
|
49
47
|
const { oldDocument, newDocument, descriptors, operation } = action.payload;
|
|
50
48
|
const documentKey = oldDocument.key;
|
|
51
49
|
console.assert(
|