@makeswift/runtime 0.24.0-canary.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/react.js +28 -7
- package/dist/cjs/api/react.js.map +1 -1
- package/dist/cjs/api/site-version.js +36 -0
- package/dist/cjs/api/site-version.js.map +1 -0
- package/dist/cjs/components/builtin/Box/register.js +3 -3
- package/dist/cjs/components/builtin/Box/register.js.map +1 -1
- package/dist/cjs/components/builtin/Button/register.js +2 -2
- package/dist/cjs/components/builtin/Button/register.js.map +1 -1
- package/dist/cjs/components/builtin/Carousel/Carousel.js +6 -5
- package/dist/cjs/components/builtin/Carousel/Carousel.js.map +1 -1
- package/dist/cjs/components/builtin/Carousel/register.js +2 -2
- package/dist/cjs/components/builtin/Carousel/register.js.map +1 -1
- package/dist/cjs/components/builtin/Countdown/register.js +2 -2
- package/dist/cjs/components/builtin/Countdown/register.js.map +1 -1
- package/dist/cjs/components/builtin/Form/register.js +4 -4
- package/dist/cjs/components/builtin/Form/register.js.map +1 -1
- package/dist/cjs/components/builtin/Image/Image.js +3 -3
- package/dist/cjs/components/builtin/Image/Image.js.map +1 -1
- package/dist/cjs/components/builtin/Navigation/register.js +4 -4
- package/dist/cjs/components/builtin/Navigation/register.js.map +1 -1
- package/dist/cjs/components/builtin/SocialLinks/register.js +3 -3
- package/dist/cjs/components/builtin/SocialLinks/register.js.map +1 -1
- package/dist/cjs/components/builtin/Text/register.js +3 -3
- package/dist/cjs/components/builtin/Text/register.js.map +1 -1
- package/dist/cjs/components/hooks/useMediaQuery.js +5 -5
- package/dist/cjs/components/hooks/useMediaQuery.js.map +1 -1
- package/dist/cjs/components/page/Page.js +7 -4
- package/dist/cjs/components/page/Page.js.map +1 -1
- package/dist/cjs/components/page/PageHead.js +17 -8
- package/dist/cjs/components/page/PageHead.js.map +1 -1
- package/dist/cjs/components/page/page-seo-settings.js +43 -0
- package/dist/cjs/components/page/page-seo-settings.js.map +1 -0
- package/dist/cjs/components/shared/Link/index.js +3 -1
- package/dist/cjs/components/shared/Link/index.js.map +1 -1
- package/dist/cjs/components/utils/responsive-style.js +2 -3
- package/dist/cjs/components/utils/responsive-style.js.map +1 -1
- package/dist/cjs/core/index.js +18 -2
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/jest-setup.js +3 -0
- package/dist/cjs/jest-setup.js.map +1 -1
- package/dist/cjs/locale.js +79 -0
- package/dist/cjs/locale.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/clear-draft.js +64 -0
- package/dist/cjs/next/api-handler/handlers/clear-draft.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/manifest.js +3 -2
- package/dist/cjs/next/api-handler/handlers/manifest.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/redirect-draft.js +77 -0
- package/dist/cjs/next/api-handler/handlers/redirect-draft.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/redirect-preview.js +67 -0
- package/dist/cjs/next/api-handler/handlers/redirect-preview.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/utils/draft.js +53 -0
- package/dist/cjs/next/api-handler/handlers/utils/draft.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/webhook/index.js +3 -3
- package/dist/cjs/next/api-handler/handlers/webhook/index.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/webhook/site-published.js +8 -5
- package/dist/cjs/next/api-handler/handlers/webhook/site-published.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/webhook/types.js.map +1 -1
- package/dist/cjs/next/api-handler/index.js +24 -9
- package/dist/cjs/next/api-handler/index.js.map +1 -1
- package/dist/cjs/next/cache.js +29 -0
- package/dist/cjs/next/cache.js.map +1 -0
- package/dist/cjs/next/client.js +135 -60
- package/dist/cjs/next/client.js.map +1 -1
- package/dist/cjs/next/components/page.js +3 -2
- package/dist/cjs/next/components/page.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/color-control/fixtures.js +51 -0
- package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -0
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +91 -35
- 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 +91 -0
- package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
- package/dist/cjs/next/components/tests/controls/style-control/fixtures.js +60 -0
- package/dist/cjs/next/components/tests/controls/style-control/fixtures.js.map +1 -0
- package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js +20 -11
- package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
- package/dist/cjs/next/document.js +1 -3
- package/dist/cjs/next/document.js.map +1 -1
- package/dist/cjs/next/draft-mode/index.js +3 -3
- package/dist/cjs/next/draft-mode/index.js.map +1 -1
- package/dist/cjs/next/hooks/use-is-pages-router.js.map +1 -1
- package/dist/cjs/next/index.js +0 -3
- package/dist/cjs/next/index.js.map +1 -1
- package/dist/cjs/next/middleware/index.js +29 -0
- package/dist/cjs/next/middleware/index.js.map +1 -0
- package/dist/cjs/next/middleware/request-utils.js +49 -0
- package/dist/cjs/next/middleware/request-utils.js.map +1 -0
- package/dist/cjs/next/preview-mode.js +4 -110
- package/dist/cjs/next/preview-mode.js.map +1 -1
- package/dist/cjs/next/root-style-registry.js +24 -20
- package/dist/cjs/next/root-style-registry.js.map +1 -1
- package/dist/cjs/next/server.js +0 -3
- package/dist/cjs/next/server.js.map +1 -1
- package/dist/cjs/next/tests/test-utils.js +61 -0
- package/dist/cjs/next/tests/test-utils.js.map +1 -0
- package/dist/cjs/runtimes/react/components/Document.js +1 -1
- package/dist/cjs/runtimes/react/components/Document.js.map +1 -1
- package/dist/cjs/runtimes/react/components/ElementData.js +1 -0
- package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +14 -3
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js +72 -0
- package/dist/cjs/runtimes/react/components/draft-switcher/draft-switcher.js.map +1 -0
- package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js +79 -0
- package/dist/cjs/runtimes/react/components/draft-switcher/draft-toolbar.js.map +1 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +67 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-handshake.js +45 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-handshake.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.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-document-context.js +8 -13
- package/dist/cjs/runtimes/react/hooks/use-document-context.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-register-document.js +8 -1
- package/dist/cjs/runtimes/react/hooks/use-register-document.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolvable-record.js +68 -0
- package/dist/cjs/runtimes/react/hooks/use-resolvable-record.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +6 -5
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolved-value.js +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resolved-value.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +2 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +1 -2
- package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +5 -1
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +4 -4
- package/dist/cjs/runtimes/react/testing/breakpoints.js.map +1 -0
- package/dist/cjs/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +33 -7
- package/dist/cjs/runtimes/react/testing/element-data.js.map +1 -0
- package/dist/cjs/runtimes/react/testing/index.js +27 -0
- package/dist/cjs/runtimes/react/testing/index.js.map +1 -0
- package/dist/cjs/runtimes/react/testing/react-provider.js +38 -0
- package/dist/cjs/runtimes/react/testing/react-provider.js.map +1 -0
- package/dist/cjs/runtimes/react/use-style.js +2 -2
- package/dist/cjs/runtimes/react/use-style.js.map +1 -1
- package/dist/cjs/slate/BlockPlugin/setBlockKeyForDevice.js +1 -2
- package/dist/cjs/slate/BlockPlugin/setBlockKeyForDevice.js.map +1 -1
- package/dist/cjs/slate/TypographyPlugin/setActiveTypographyStyle.js +2 -2
- package/dist/cjs/slate/TypographyPlugin/setActiveTypographyStyle.js.map +1 -1
- package/dist/cjs/slate/selectors.js +2 -3
- package/dist/cjs/slate/selectors.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +23 -12
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/cjs/state/modules/breakpoints.js +1 -44
- package/dist/cjs/state/modules/breakpoints.js.map +1 -1
- package/dist/cjs/state/modules/element-trees.js +10 -7
- package/dist/cjs/state/modules/element-trees.js.map +1 -1
- package/dist/esm/api/react.js +28 -7
- package/dist/esm/api/react.js.map +1 -1
- package/dist/esm/api/site-version.js +10 -0
- package/dist/esm/api/site-version.js.map +1 -0
- package/dist/esm/components/builtin/Box/register.js +1 -1
- package/dist/esm/components/builtin/Box/register.js.map +1 -1
- package/dist/esm/components/builtin/Button/register.js +1 -1
- package/dist/esm/components/builtin/Button/register.js.map +1 -1
- package/dist/esm/components/builtin/Carousel/Carousel.js +5 -4
- package/dist/esm/components/builtin/Carousel/Carousel.js.map +1 -1
- package/dist/esm/components/builtin/Carousel/register.js +1 -1
- package/dist/esm/components/builtin/Carousel/register.js.map +1 -1
- package/dist/esm/components/builtin/Countdown/register.js +1 -1
- package/dist/esm/components/builtin/Countdown/register.js.map +1 -1
- package/dist/esm/components/builtin/Form/register.js +1 -1
- package/dist/esm/components/builtin/Form/register.js.map +1 -1
- package/dist/esm/components/builtin/Image/Image.js +1 -1
- package/dist/esm/components/builtin/Image/Image.js.map +1 -1
- package/dist/esm/components/builtin/Navigation/register.js +1 -1
- package/dist/esm/components/builtin/Navigation/register.js.map +1 -1
- package/dist/esm/components/builtin/SocialLinks/register.js +1 -1
- package/dist/esm/components/builtin/SocialLinks/register.js.map +1 -1
- package/dist/esm/components/builtin/Text/register.js +1 -1
- package/dist/esm/components/builtin/Text/register.js.map +1 -1
- package/dist/esm/components/hooks/useMediaQuery.js +1 -1
- package/dist/esm/components/hooks/useMediaQuery.js.map +1 -1
- package/dist/esm/components/page/Page.js +5 -2
- package/dist/esm/components/page/Page.js.map +1 -1
- package/dist/esm/components/page/PageHead.js +17 -8
- package/dist/esm/components/page/PageHead.js.map +1 -1
- package/dist/esm/components/page/page-seo-settings.js +19 -0
- package/dist/esm/components/page/page-seo-settings.js.map +1 -0
- package/dist/esm/components/shared/Link/index.js +3 -1
- package/dist/esm/components/shared/Link/index.js.map +1 -1
- package/dist/esm/components/utils/responsive-style.js +3 -2
- package/dist/esm/components/utils/responsive-style.js.map +1 -1
- package/dist/esm/core/index.js +18 -2
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/jest-setup.js +4 -1
- package/dist/esm/jest-setup.js.map +1 -1
- package/dist/esm/locale.js +79 -0
- package/dist/esm/locale.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/clear-draft.js +50 -0
- package/dist/esm/next/api-handler/handlers/clear-draft.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/manifest.js +3 -2
- package/dist/esm/next/api-handler/handlers/manifest.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/redirect-draft.js +63 -0
- package/dist/esm/next/api-handler/handlers/redirect-draft.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/redirect-preview.js +53 -0
- package/dist/esm/next/api-handler/handlers/redirect-preview.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/utils/draft.js +24 -0
- package/dist/esm/next/api-handler/handlers/utils/draft.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/webhook/index.js +3 -3
- package/dist/esm/next/api-handler/handlers/webhook/index.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/webhook/site-published.js +7 -3
- package/dist/esm/next/api-handler/handlers/webhook/site-published.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/webhook/types.js.map +1 -1
- package/dist/esm/next/api-handler/index.js +28 -9
- package/dist/esm/next/api-handler/index.js.map +1 -1
- package/dist/esm/next/cache.js +5 -0
- package/dist/esm/next/cache.js.map +1 -0
- package/dist/esm/next/client.js +128 -54
- package/dist/esm/next/client.js.map +1 -1
- package/dist/esm/next/components/page.js +3 -2
- package/dist/esm/next/components/page.js.map +1 -1
- package/dist/esm/next/components/tests/controls/color-control/fixtures.js +24 -0
- package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -0
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +82 -39
- 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 +56 -0
- package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
- package/dist/esm/next/components/tests/controls/style-control/fixtures.js +35 -0
- package/dist/esm/next/components/tests/controls/style-control/fixtures.js.map +1 -0
- package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js +7 -11
- package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
- package/dist/esm/next/document.js +1 -3
- package/dist/esm/next/document.js.map +1 -1
- package/dist/esm/next/draft-mode/index.js +1 -1
- package/dist/esm/next/draft-mode/index.js.map +1 -1
- package/dist/esm/next/hooks/use-is-pages-router.js.map +1 -1
- package/dist/esm/next/index.js +0 -2
- package/dist/esm/next/index.js.map +1 -1
- package/dist/esm/next/middleware/index.js +5 -0
- package/dist/esm/next/middleware/index.js.map +1 -0
- package/dist/esm/next/middleware/request-utils.js +28 -0
- package/dist/esm/next/middleware/request-utils.js.map +1 -0
- package/dist/esm/next/preview-mode.js +2 -105
- package/dist/esm/next/preview-mode.js.map +1 -1
- package/dist/esm/next/root-style-registry.js +24 -20
- package/dist/esm/next/root-style-registry.js.map +1 -1
- package/dist/esm/next/server.js +0 -2
- package/dist/esm/next/server.js.map +1 -1
- package/dist/esm/next/tests/test-utils.js +37 -0
- package/dist/esm/next/tests/test-utils.js.map +1 -0
- package/dist/esm/runtimes/react/components/Document.js +2 -2
- package/dist/esm/runtimes/react/components/Document.js.map +1 -1
- package/dist/esm/runtimes/react/components/ElementData.js +1 -0
- package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +15 -4
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js +48 -0
- package/dist/esm/runtimes/react/components/draft-switcher/draft-switcher.js.map +1 -0
- package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js +55 -0
- package/dist/esm/runtimes/react/components/draft-switcher/draft-toolbar.js.map +1 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +43 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-handshake.js +21 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-handshake.js.map +1 -0
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +2 -2
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-document-context.js +6 -11
- package/dist/esm/runtimes/react/hooks/use-document-context.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-register-document.js +9 -2
- package/dist/esm/runtimes/react/hooks/use-register-document.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolvable-record.js +44 -0
- package/dist/esm/runtimes/react/hooks/use-resolvable-record.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js +6 -5
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolved-value.js +1 -1
- package/dist/esm/runtimes/react/hooks/use-resolved-value.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +3 -2
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +5 -1
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +1 -1
- package/dist/esm/runtimes/react/testing/breakpoints.js.map +1 -0
- package/dist/esm/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +29 -4
- package/dist/esm/runtimes/react/testing/element-data.js.map +1 -0
- package/dist/esm/runtimes/react/testing/index.js +4 -0
- package/dist/esm/runtimes/react/testing/index.js.map +1 -0
- package/dist/esm/runtimes/react/testing/react-provider.js +14 -0
- package/dist/esm/runtimes/react/testing/react-provider.js.map +1 -0
- package/dist/esm/runtimes/react/use-style.js +2 -2
- package/dist/esm/runtimes/react/use-style.js.map +1 -1
- package/dist/esm/slate/BlockPlugin/setBlockKeyForDevice.js +4 -2
- package/dist/esm/slate/BlockPlugin/setBlockKeyForDevice.js.map +1 -1
- package/dist/esm/slate/TypographyPlugin/setActiveTypographyStyle.js +3 -1
- package/dist/esm/slate/TypographyPlugin/setActiveTypographyStyle.js.map +1 -1
- package/dist/esm/slate/selectors.js +4 -2
- package/dist/esm/slate/selectors.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +22 -11
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/state/modules/breakpoints.js +1 -42
- package/dist/esm/state/modules/breakpoints.js.map +1 -1
- package/dist/esm/state/modules/element-trees.js +10 -7
- package/dist/esm/state/modules/element-trees.js.map +1 -1
- package/dist/types/api/react.d.ts +4 -1
- package/dist/types/api/react.d.ts.map +1 -1
- package/dist/types/api/site-version.d.ts +6 -0
- package/dist/types/api/site-version.d.ts.map +1 -0
- package/dist/types/components/builtin/Box/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Button/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Carousel/Carousel.d.ts.map +1 -1
- package/dist/types/components/builtin/Image/Image.d.ts.map +1 -1
- package/dist/types/components/hooks/useMediaQuery.d.ts +1 -1
- package/dist/types/components/hooks/useMediaQuery.d.ts.map +1 -1
- package/dist/types/components/page/Page.d.ts +3 -1
- package/dist/types/components/page/Page.d.ts.map +1 -1
- package/dist/types/components/page/PageHead.d.ts +3 -1
- package/dist/types/components/page/PageHead.d.ts.map +1 -1
- package/dist/types/components/page/page-seo-settings.d.ts +11 -0
- package/dist/types/components/page/page-seo-settings.d.ts.map +1 -0
- package/dist/types/components/shared/Link/index.d.ts.map +1 -1
- package/dist/types/components/utils/responsive-style.d.ts +1 -1
- package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
- package/dist/types/controls/link.d.ts +1 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/locale.d.ts +3 -3
- package/dist/types/locale.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/clear-draft.d.ts +20 -0
- package/dist/types/next/api-handler/handlers/clear-draft.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/manifest.d.ts +1 -0
- package/dist/types/next/api-handler/handlers/manifest.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/redirect-draft.d.ts +18 -0
- package/dist/types/next/api-handler/handlers/redirect-draft.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/redirect-preview.d.ts +18 -0
- package/dist/types/next/api-handler/handlers/redirect-preview.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/utils/draft.d.ts +16 -0
- package/dist/types/next/api-handler/handlers/utils/draft.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/webhook/index.d.ts +9 -11
- package/dist/types/next/api-handler/handlers/webhook/index.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/webhook/site-published.d.ts +6 -3
- package/dist/types/next/api-handler/handlers/webhook/site-published.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/webhook/types.d.ts +13 -12
- package/dist/types/next/api-handler/handlers/webhook/types.d.ts.map +1 -1
- package/dist/types/next/api-handler/index.d.ts +10 -5
- package/dist/types/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/next/cache.d.ts +2 -0
- package/dist/types/next/cache.d.ts.map +1 -0
- package/dist/types/next/client.d.ts +14 -12
- package/dist/types/next/client.d.ts.map +1 -1
- package/dist/types/next/components/page.d.ts +21 -1
- package/dist/types/next/components/page.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/color-control/client.test.d.ts +3 -0
- package/dist/types/next/components/tests/controls/color-control/client.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +11 -0
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/color-control/server.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/color-control/server.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +2 -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/client.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control/client.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +42 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/style-control/client.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/style-control/client.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts +6 -0
- package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/style-control/server.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/style-control/server.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/makeswift-page-metadata-rendering.test.d.ts +3 -0
- package/dist/types/next/components/tests/makeswift-page-metadata-rendering.test.d.ts.map +1 -0
- package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts.map +1 -1
- package/dist/types/next/document.d.ts +1 -5
- package/dist/types/next/document.d.ts.map +1 -1
- package/dist/types/next/draft-mode/index.d.ts +2 -2
- package/dist/types/next/hooks/use-is-pages-router.d.ts.map +1 -1
- package/dist/types/next/index.d.ts +0 -1
- package/dist/types/next/index.d.ts.map +1 -1
- package/dist/types/next/middleware/index.d.ts +2 -0
- package/dist/types/next/middleware/index.d.ts.map +1 -0
- package/dist/types/next/middleware/request-utils.d.ts +3 -0
- package/dist/types/next/middleware/request-utils.d.ts.map +1 -0
- package/dist/types/next/middleware/request-utils.test.d.ts +2 -0
- package/dist/types/next/middleware/request-utils.test.d.ts.map +1 -0
- package/dist/types/next/preview-mode.d.ts +3 -10
- package/dist/types/next/preview-mode.d.ts.map +1 -1
- package/dist/types/next/root-style-registry.d.ts +2 -1
- package/dist/types/next/root-style-registry.d.ts.map +1 -1
- package/dist/types/next/server.d.ts +0 -1
- package/dist/types/next/server.d.ts.map +1 -1
- package/dist/types/next/tests/client.error-handling.test.d.ts +2 -0
- package/dist/types/next/tests/client.error-handling.test.d.ts.map +1 -0
- package/dist/types/next/tests/client.get-page-snapshot.test.d.ts +2 -0
- package/dist/types/next/tests/client.get-page-snapshot.test.d.ts.map +1 -0
- package/dist/types/next/tests/client.get-resources.test.d.ts +2 -0
- package/dist/types/next/tests/client.get-resources.test.d.ts.map +1 -0
- package/dist/types/next/tests/server.makeswift-api-handler.test.d.ts +2 -0
- package/dist/types/next/tests/server.makeswift-api-handler.test.d.ts.map +1 -0
- package/dist/types/next/tests/test-utils.d.ts +8 -0
- package/dist/types/next/tests/test-utils.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/Document.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/ElementData.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +2 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts +4 -0
- package/dist/types/runtimes/react/components/draft-switcher/draft-switcher.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts +6 -0
- package/dist/types/runtimes/react/components/draft-switcher/draft-toolbar.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts +4 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-handshake.d.ts +4 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-handshake.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-cache-data.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-document-context.d.ts +2 -7
- package/dist/types/runtimes/react/hooks/use-document-context.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-register-document.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resolvable-record.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-resolvable-record.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -1
- package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
- package/dist/types/{utils/tests/breakpoint-test-util.d.ts → runtimes/react/testing/breakpoints.d.ts} +1 -1
- package/dist/types/runtimes/react/testing/breakpoints.d.ts.map +1 -0
- package/dist/types/{utils/tests/element-data-test-test.d.ts → runtimes/react/testing/element-data.d.ts} +7 -3
- package/dist/types/runtimes/react/testing/element-data.d.ts.map +1 -0
- package/dist/types/runtimes/react/testing/index.d.ts +4 -0
- package/dist/types/runtimes/react/testing/index.d.ts.map +1 -0
- package/dist/types/runtimes/react/testing/react-provider.d.ts +8 -0
- package/dist/types/runtimes/react/testing/react-provider.d.ts.map +1 -0
- package/dist/types/slate/BlockPlugin/setBlockKeyForDevice.d.ts +1 -1
- package/dist/types/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
- package/dist/types/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +1 -1
- package/dist/types/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
- package/dist/types/slate/selectors.d.ts +1 -2
- package/dist/types/slate/selectors.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -1
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts +7 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees-demo-component.d.ts.map +1 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts +239 -0
- package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts.map +1 -1
- package/dist/types/state/modules/breakpoints.d.ts +2 -7
- package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/state/modules/element-trees.d.ts +1 -1
- package/dist/types/state/modules/element-trees.d.ts.map +1 -1
- package/package.json +17 -5
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +0 -80
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +0 -1
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +0 -100
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +0 -1
- package/dist/cjs/next/draft-mode/draft-mode-script.js +0 -137
- package/dist/cjs/next/draft-mode/draft-mode-script.js.map +0 -1
- package/dist/cjs/runtimes/react/resolvable-record.js +0 -67
- package/dist/cjs/runtimes/react/resolvable-record.js.map +0 -1
- package/dist/cjs/utils/tests/breakpoint-test-util.js.map +0 -1
- package/dist/cjs/utils/tests/element-data-test-test.js.map +0 -1
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +0 -60
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +0 -1
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +0 -80
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +0 -1
- package/dist/esm/next/draft-mode/draft-mode-script.js +0 -103
- package/dist/esm/next/draft-mode/draft-mode-script.js.map +0 -1
- package/dist/esm/runtimes/react/resolvable-record.js +0 -43
- package/dist/esm/runtimes/react/resolvable-record.js.map +0 -1
- package/dist/esm/utils/tests/breakpoint-test-util.js.map +0 -1
- package/dist/esm/utils/tests/element-data-test-test.js.map +0 -1
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts +0 -20
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts.map +0 -1
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts +0 -2
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts.map +0 -1
- package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts +0 -20
- package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts.map +0 -1
- package/dist/types/next/components/tests/controls/color-control.test.d.ts +0 -3
- package/dist/types/next/components/tests/controls/color-control.test.d.ts.map +0 -1
- package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +0 -2
- package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +0 -1
- package/dist/types/next/components/tests/controls/style-control.test.d.ts +0 -2
- package/dist/types/next/components/tests/controls/style-control.test.d.ts.map +0 -1
- package/dist/types/next/draft-mode/draft-mode-script.d.ts +0 -6
- package/dist/types/next/draft-mode/draft-mode-script.d.ts.map +0 -1
- package/dist/types/runtimes/react/resolvable-record.d.ts +0 -3
- package/dist/types/runtimes/react/resolvable-record.d.ts.map +0 -1
- package/dist/types/utils/tests/breakpoint-test-util.d.ts.map +0 -1
- package/dist/types/utils/tests/element-data-test-test.d.ts.map +0 -1
package/dist/cjs/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js}
RENAMED
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var breakpoints_exports = {};
|
|
20
|
+
__export(breakpoints_exports, {
|
|
21
21
|
DESKTOP_MEDIA_QUERY: () => DESKTOP_MEDIA_QUERY,
|
|
22
22
|
MOBILE_MEDIA_QUERY: () => MOBILE_MEDIA_QUERY,
|
|
23
23
|
TABLET_MEDIA_QUERY: () => TABLET_MEDIA_QUERY
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(breakpoints_exports);
|
|
26
26
|
const DESKTOP_MEDIA_QUERY = "only screen and (min-width: 769px)";
|
|
27
27
|
const TABLET_MEDIA_QUERY = "only screen and (min-width: 769px)";
|
|
28
28
|
const MOBILE_MEDIA_QUERY = "only screen and (min-width: 769px)";
|
|
@@ -32,4 +32,4 @@ const MOBILE_MEDIA_QUERY = "only screen and (min-width: 769px)";
|
|
|
32
32
|
MOBILE_MEDIA_QUERY,
|
|
33
33
|
TABLET_MEDIA_QUERY
|
|
34
34
|
});
|
|
35
|
-
//# sourceMappingURL=
|
|
35
|
+
//# sourceMappingURL=breakpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/breakpoints.ts"],"sourcesContent":["export const DESKTOP_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const TABLET_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const MOBILE_MEDIA_QUERY = 'only screen and (min-width: 769px)'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;","names":[]}
|
package/dist/cjs/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js}
RENAMED
|
@@ -16,14 +16,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var element_data_exports = {};
|
|
20
|
+
__export(element_data_exports, {
|
|
21
|
+
createMakeswiftComponentSnapshot: () => createMakeswiftComponentSnapshot,
|
|
21
22
|
createMakeswiftPageSnapshot: () => createMakeswiftPageSnapshot,
|
|
22
23
|
createRootComponent: () => createRootComponent
|
|
23
24
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(element_data_exports);
|
|
25
26
|
var import_crypto = require("crypto");
|
|
26
|
-
var
|
|
27
|
+
var import_react = require("../../../api/react");
|
|
28
|
+
var import_components = require("../../../components");
|
|
27
29
|
function createRootComponent(elements, rootId) {
|
|
28
30
|
return {
|
|
29
31
|
key: rootId ?? (0, import_crypto.randomUUID)(),
|
|
@@ -61,15 +63,39 @@ function createMakeswiftPageSnapshot(elementData, {
|
|
|
61
63
|
locale
|
|
62
64
|
},
|
|
63
65
|
cacheData: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
...import_react.CacheData.empty(),
|
|
67
|
+
...cacheData
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function createMakeswiftComponentSnapshot(elementData, {
|
|
72
|
+
cacheData = {},
|
|
73
|
+
locale = null
|
|
74
|
+
} = {}) {
|
|
75
|
+
return {
|
|
76
|
+
key: (0, import_crypto.randomUUID)(),
|
|
77
|
+
document: {
|
|
78
|
+
id: "test-component-id",
|
|
79
|
+
name: "Test Component Document",
|
|
80
|
+
siteId: "test-site-id",
|
|
81
|
+
data: elementData,
|
|
82
|
+
inheritsFromParent: false,
|
|
83
|
+
locale
|
|
84
|
+
},
|
|
85
|
+
meta: {
|
|
86
|
+
allowLocaleFallback: false,
|
|
87
|
+
requestedLocale: locale
|
|
88
|
+
},
|
|
89
|
+
cacheData: {
|
|
90
|
+
...import_react.CacheData.empty(),
|
|
66
91
|
...cacheData
|
|
67
92
|
}
|
|
68
93
|
};
|
|
69
94
|
}
|
|
70
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
96
|
0 && (module.exports = {
|
|
97
|
+
createMakeswiftComponentSnapshot,
|
|
72
98
|
createMakeswiftPageSnapshot,
|
|
73
99
|
createRootComponent
|
|
74
100
|
});
|
|
75
|
-
//# sourceMappingURL=element-data
|
|
101
|
+
//# sourceMappingURL=element-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/element-data.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\nimport { type MakeswiftPageSnapshot, type MakeswiftComponentSnapshot } from '../../../next/client'\nimport { type ElementData } from '../../../state/react-page'\nimport { CacheData } from '../../../api/react'\nimport { MakeswiftComponentType } from '../../../components'\n\nexport function createRootComponent(elements: ElementData[], rootId?: string) {\n return {\n key: rootId ?? randomUUID(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nexport function createMakeswiftPageSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementData,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: randomUUID(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAG3B,mBAA0B;AAC1B,wBAAuC;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,cAAU,0BAAW;AAAA,IAC1B,MAAM,yCAAuB;AAAA,IAC7B,OAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS;AAAA,UACP;AAAA,YACE,UAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO;AAAA,cACP,OAAO,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC;AAAA,YACjC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,4BACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAAyF,CAAC,GACnE;AACvB,SAAO;AAAA,IACL,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM,EAAE,IAAI,eAAe;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,MACX,OAAO,CAAC;AAAA,MACR,MAAM,CAAC;AAAA,MACP,KAAK,CAAC;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,GAAG,uBAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,iCACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAA8F,CAAC,GACnE;AAC5B,SAAO;AAAA,IACL,SAAK,0BAAW;AAAA,IAChB,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,uBAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var testing_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(testing_exports);
|
|
18
|
+
__reExport(testing_exports, require("./breakpoints"), module.exports);
|
|
19
|
+
__reExport(testing_exports, require("./element-data"), module.exports);
|
|
20
|
+
__reExport(testing_exports, require("./react-provider"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./breakpoints"),
|
|
24
|
+
...require("./element-data"),
|
|
25
|
+
...require("./react-provider")
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/index.ts"],"sourcesContent":["export * from './breakpoints'\nexport * from './element-data'\nexport * from './react-provider'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,0BAAd;AACA,4BAAc,2BADd;AAEA,4BAAc,6BAFd;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var react_provider_exports = {};
|
|
20
|
+
__export(react_provider_exports, {
|
|
21
|
+
ReactProvider: () => ReactProvider
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(react_provider_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_next = require("../../../next");
|
|
26
|
+
var import_RuntimeProvider = require("../components/RuntimeProvider");
|
|
27
|
+
function ReactProvider({
|
|
28
|
+
children,
|
|
29
|
+
runtime,
|
|
30
|
+
previewMode = false
|
|
31
|
+
}) {
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RuntimeProvider.ReactRuntimeProvider, { previewMode, runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_next.RootStyleRegistry, { children }) });
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
ReactProvider
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=react-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-provider.tsx"],"sourcesContent":["import { RootStyleRegistry } from '../../../next'\nimport { ReactRuntimeProvider } from '../components/RuntimeProvider'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function ReactProvider({\n children,\n runtime,\n previewMode = false,\n}: {\n children: React.ReactNode\n runtime: ReactRuntime\n previewMode?: boolean\n}) {\n return (\n <ReactRuntimeProvider previewMode={previewMode} runtime={runtime}>\n <RootStyleRegistry>{children}</RootStyleRegistry>\n </ReactRuntimeProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeM;AAfN,kBAAkC;AAClC,6BAAqC;AAG9B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAIG;AACD,SACE,4CAAC,+CAAqB,aAA0B,SAC9C,sDAAC,iCAAmB,UAAS,GAC/B;AAEJ;","names":[]}
|
|
@@ -37,7 +37,7 @@ var import_react = __toESM(require("react"));
|
|
|
37
37
|
var import_serialize = require("@emotion/serialize");
|
|
38
38
|
var import_utils = require("@emotion/utils");
|
|
39
39
|
var import_root_style_registry = require("../../next/root-style-registry");
|
|
40
|
-
|
|
40
|
+
var import_is_server = require("../../utils/is-server");
|
|
41
41
|
const useInsertionEffectSpecifier = "useInsertionEffect";
|
|
42
42
|
const useInsertionEffect = import_react.default[useInsertionEffectSpecifier] ?? import_react.default.useLayoutEffect;
|
|
43
43
|
function useStyle(style) {
|
|
@@ -57,7 +57,7 @@ function useStyles(cache, styles) {
|
|
|
57
57
|
}
|
|
58
58
|
function useUniversalInsertionEffect(effect) {
|
|
59
59
|
useInsertionEffect(effect);
|
|
60
|
-
if (isServer)
|
|
60
|
+
if ((0, import_is_server.isServer)())
|
|
61
61
|
effect();
|
|
62
62
|
}
|
|
63
63
|
function serializedStyleClassName(cache, serialized) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { EmotionCache } from '@emotion/cache'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles, type SerializedStyles } from '@emotion/utils'\n\nimport { useCache } from '../../next/root-style-registry'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { EmotionCache } from '@emotion/cache'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles, type SerializedStyles } from '@emotion/utils'\n\nimport { useCache } from '../../next/root-style-registry'\nimport { isServer } from '../../utils/is-server'\n\nconst useInsertionEffectSpecifier = 'useInsertionEffect'\nconst useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect\n\nexport function useStyle(style: CSSObject): string {\n const cache = useCache()\n const serialized = serializeStyles([style], cache.registered)\n\n registerStyles(cache, serialized, false)\n\n useUniversalInsertionEffect(() => {\n insertStyles(cache, serialized, false)\n })\n\n return serializedStyleClassName(cache, serialized)\n}\n\nexport function useStyles(cache: EmotionCache, styles: SerializedStyles[]) {\n styles.forEach(s => registerStyles(cache, s, false))\n\n useUniversalInsertionEffect(() => {\n styles.forEach(s => insertStyles(cache, s, false))\n })\n}\n\nfunction useUniversalInsertionEffect(effect: () => void) {\n useInsertionEffect(effect)\n if (isServer()) effect()\n}\n\nexport function serializedStyleClassName(\n cache: EmotionCache,\n serialized: SerializedStyles,\n): string {\n // see https://github.com/emotion-js/emotion/blob/main/packages/utils/src/index.ts#L26\n return `${cache.key}-${serialized.name}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGlB,uBAAgC;AAChC,mBAAoE;AAEpE,iCAAyB;AACzB,uBAAyB;AAEzB,MAAM,8BAA8B;AACpC,MAAM,qBAAqB,aAAAA,QAAM,2BAA2B,KAAK,aAAAA,QAAM;AAEhE,SAAS,SAAS,OAA0B;AACjD,QAAM,YAAQ,qCAAS;AACvB,QAAM,iBAAa,kCAAgB,CAAC,KAAK,GAAG,MAAM,UAAU;AAE5D,mCAAe,OAAO,YAAY,KAAK;AAEvC,8BAA4B,MAAM;AAChC,mCAAa,OAAO,YAAY,KAAK;AAAA,EACvC,CAAC;AAED,SAAO,yBAAyB,OAAO,UAAU;AACnD;AAEO,SAAS,UAAU,OAAqB,QAA4B;AACzE,SAAO,QAAQ,WAAK,6BAAe,OAAO,GAAG,KAAK,CAAC;AAEnD,8BAA4B,MAAM;AAChC,WAAO,QAAQ,WAAK,2BAAa,OAAO,GAAG,KAAK,CAAC;AAAA,EACnD,CAAC;AACH;AAEA,SAAS,4BAA4B,QAAoB;AACvD,qBAAmB,MAAM;AACzB,UAAI,2BAAS;AAAG,WAAO;AACzB;AAEO,SAAS,yBACd,OACA,YACQ;AAER,SAAO,GAAG,MAAM,GAAG,IAAI,WAAW,IAAI;AACxC;","names":["React"]}
|
|
@@ -24,7 +24,6 @@ module.exports = __toCommonJS(setBlockKeyForDevice_exports);
|
|
|
24
24
|
var import_slate = require("slate");
|
|
25
25
|
var import_controls = require("@makeswift/controls");
|
|
26
26
|
var import_selectors = require("../selectors");
|
|
27
|
-
var import_breakpoints = require("../../state/modules/breakpoints");
|
|
28
27
|
function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
|
|
29
28
|
const at = options?.at ?? editor.selection;
|
|
30
29
|
if (!at)
|
|
@@ -33,7 +32,7 @@ function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options
|
|
|
33
32
|
for (const [node, path] of rootElements) {
|
|
34
33
|
if (import_controls.Slate.isBlock(node)) {
|
|
35
34
|
const deviceValues = node[key] ?? [];
|
|
36
|
-
const currentDeviceValue = (0,
|
|
35
|
+
const currentDeviceValue = (0, import_controls.findBreakpointOverride)(breakpoints, deviceValues, deviceId, (v) => v);
|
|
37
36
|
const nextDeviceValue = {
|
|
38
37
|
...currentDeviceValue,
|
|
39
38
|
deviceId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/BlockPlugin/setBlockKeyForDevice.ts"],"sourcesContent":["import { Editor, Transforms, Location } from 'slate'\nimport { Slate
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/BlockPlugin/setBlockKeyForDevice.ts"],"sourcesContent":["import { Editor, Transforms, Location } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { getBlocksInSelection } from '../selectors'\nimport { EditableBlockKey, EditableBlockValue } from './types'\n\ntype SetBlockKeyForDeviceOptions = {\n at?: Location\n}\n\nexport function setBlockKeyForDevice(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n key: EditableBlockKey,\n value: EditableBlockValue[number]['value'],\n options?: SetBlockKeyForDeviceOptions,\n) {\n const at = options?.at ?? editor.selection\n if (!at) return\n\n const rootElements = getBlocksInSelection(editor)\n\n for (const [node, path] of rootElements) {\n if (Slate.isBlock(node)) {\n const deviceValues = node[key] ?? []\n const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, v => v)\n const nextDeviceValue = {\n ...currentDeviceValue,\n deviceId,\n value,\n }\n Transforms.setNodes(\n editor,\n {\n [key]: [...deviceValues.filter(v => v.deviceId !== deviceId), nextDeviceValue],\n },\n { at: path },\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAC7C,sBAKO;AAEP,uBAAqC;AAO9B,SAAS,qBACd,QACA,aACA,UACA,KACA,OACA,SACA;AACA,QAAM,KAAK,SAAS,MAAM,OAAO;AACjC,MAAI,CAAC;AAAI;AAET,QAAM,mBAAe,uCAAqB,MAAM;AAEhD,aAAW,CAAC,MAAM,IAAI,KAAK,cAAc;AACvC,QAAI,sBAAM,QAAQ,IAAI,GAAG;AACvB,YAAM,eAAe,KAAK,GAAG,KAAK,CAAC;AACnC,YAAM,yBAAqB,wCAAuB,aAAa,cAAc,UAAU,OAAK,CAAC;AAC7F,YAAM,kBAAkB;AAAA,QACtB,GAAG;AAAA,QACH;AAAA,QACA;AAAA,MACF;AACA,8BAAW;AAAA,QACT;AAAA,QACA;AAAA,UACE,CAAC,GAAG,GAAG,CAAC,GAAG,aAAa,OAAO,OAAK,EAAE,aAAa,QAAQ,GAAG,eAAe;AAAA,QAC/E;AAAA,QACA,EAAE,IAAI,KAAK;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -22,7 +22,7 @@ __export(setActiveTypographyStyle_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(setActiveTypographyStyle_exports);
|
|
24
24
|
var import_slate = require("slate");
|
|
25
|
-
var
|
|
25
|
+
var import_controls = require("@makeswift/controls");
|
|
26
26
|
function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value, options) {
|
|
27
27
|
import_slate.Editor.withoutNormalizing(editor, () => {
|
|
28
28
|
const at = options?.at ?? editor.selection;
|
|
@@ -52,7 +52,7 @@ function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value, op
|
|
|
52
52
|
for (const [node, path] of textNodes) {
|
|
53
53
|
if (import_slate.Text.isText(node)) {
|
|
54
54
|
const deviceOverrides = node?.typography?.style ?? [];
|
|
55
|
-
const deviceStyle = (0,
|
|
55
|
+
const deviceStyle = (0, import_controls.findBreakpointOverride)(
|
|
56
56
|
breakpoints,
|
|
57
57
|
deviceOverrides,
|
|
58
58
|
deviceId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/setActiveTypographyStyle.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/setActiveTypographyStyle.ts"],"sourcesContent":["import { Editor, Transforms, Text, Range } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n RichTextTypography,\n} from '@makeswift/controls'\n\ntype SetActiveTypographyStyleOptions = {\n at?: Range\n}\n\nexport function setActiveTypographyStyle(\n editor: Editor,\n breakpoints: Breakpoints,\n deviceId: string,\n prop: string,\n value?: unknown,\n options?: SetActiveTypographyStyleOptions,\n) {\n Editor.withoutNormalizing(editor, () => {\n const at = options?.at ?? editor.selection\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n\n if (atRef.current) {\n Transforms.setNodes(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: node => Text.isText(node),\n split: Range.isExpanded(atRef.current),\n },\n )\n }\n\n if (atRef.current) {\n const textNodes = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n )\n\n for (const [node, path] of textNodes) {\n if (Text.isText(node)) {\n const deviceOverrides = node?.typography?.style ?? []\n const deviceStyle = findBreakpointOverride(\n breakpoints,\n deviceOverrides,\n deviceId as BreakpointId,\n v => v,\n ) || {\n value: {},\n }\n const nextDeviceStyle = {\n deviceId,\n value: { ...deviceStyle.value, [prop]: value },\n }\n\n const nextTypography: RichTextTypography = {\n ...node.typography,\n style: [...deviceOverrides.filter(v => v.deviceId !== deviceId), nextDeviceStyle],\n }\n\n Transforms.setNodes(\n editor,\n {\n typography: nextTypography,\n },\n { at: path },\n )\n }\n }\n }\n\n atRef.unref()\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgD;AAChD,sBAKO;AAMA,SAAS,yBACd,QACA,aACA,UACA,MACA,OACA,SACA;AACA,sBAAO,mBAAmB,QAAQ,MAAM;AACtC,UAAM,KAAK,SAAS,MAAM,OAAO;AACjC,QAAI,CAAC;AAAI;AACT,UAAM,QAAQ,oBAAO,SAAS,QAAQ,EAAE;AAExC,QAAI,MAAM,SAAS;AACjB,8BAAW;AAAA,QACT;AAAA,QACA;AAAA,UACE,OAAO;AAAA,QACT;AAAA,QACA;AAAA,UACE,IAAI,MAAM;AAAA,UACV,OAAO,UAAQ,kBAAK,OAAO,IAAI;AAAA,UAC/B,OAAO,mBAAM,WAAW,MAAM,OAAO;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,MAAM,SAAS;AACjB,YAAM,YAAY,MAAM;AAAA,QACtB,oBAAO,MAAM,QAAQ;AAAA,UACnB,IAAI,MAAM;AAAA,UACV,OAAO,UAAQ,kBAAK,OAAO,IAAI,KAAK,KAAK,UAAU;AAAA,QACrD,CAAC;AAAA,MACH;AAEA,iBAAW,CAAC,MAAM,IAAI,KAAK,WAAW;AACpC,YAAI,kBAAK,OAAO,IAAI,GAAG;AACrB,gBAAM,kBAAkB,MAAM,YAAY,SAAS,CAAC;AACpD,gBAAM,kBAAc;AAAA,YAClB;AAAA,YACA;AAAA,YACA;AAAA,YACA,OAAK;AAAA,UACP,KAAK;AAAA,YACH,OAAO,CAAC;AAAA,UACV;AACA,gBAAM,kBAAkB;AAAA,YACtB;AAAA,YACA,OAAO,EAAE,GAAG,YAAY,OAAO,CAAC,IAAI,GAAG,MAAM;AAAA,UAC/C;AAEA,gBAAM,iBAAqC;AAAA,YACzC,GAAG,KAAK;AAAA,YACR,OAAO,CAAC,GAAG,gBAAgB,OAAO,OAAK,EAAE,aAAa,QAAQ,GAAG,eAAe;AAAA,UAClF;AAEA,kCAAW;AAAA,YACT;AAAA,YACA;AAAA,cACE,YAAY;AAAA,YACd;AAAA,YACA,EAAE,IAAI,KAAK;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM;AAAA,EACd,CAAC;AACH;","names":[]}
|
|
@@ -43,7 +43,6 @@ var import_controls = require("@makeswift/controls");
|
|
|
43
43
|
var import_unhangRange = __toESM(require("./utils/unhangRange"));
|
|
44
44
|
var import_shallowEqual = __toESM(require("../utils/shallowEqual"));
|
|
45
45
|
var import_isNonNullable = require("../utils/isNonNullable");
|
|
46
|
-
var import_breakpoints = require("../state/modules/breakpoints");
|
|
47
46
|
var import_deepEqual = __toESM(require("../utils/deepEqual"));
|
|
48
47
|
var import_keys = __toESM(require("../utils/keys"));
|
|
49
48
|
function getSelection(editor) {
|
|
@@ -88,7 +87,7 @@ function getActiveBlockDeviceOverrideValue(editor, key, breakpoints, deviceId) {
|
|
|
88
87
|
const active = [];
|
|
89
88
|
const blocks = getBlocksInSelection(editor);
|
|
90
89
|
blocks.forEach(([block]) => {
|
|
91
|
-
const deviceOverride = (0,
|
|
90
|
+
const deviceOverride = (0, import_controls.findBreakpointOverride)(breakpoints, block[key], deviceId) || null;
|
|
92
91
|
active.push(deviceOverride?.value ?? null);
|
|
93
92
|
});
|
|
94
93
|
return active.length === 0 ? null : active.reduce((a, b) => (0, import_shallowEqual.default)(a, b) ? b : null);
|
|
@@ -117,7 +116,7 @@ const fuseTypographyMarks = (values, breakpoints) => {
|
|
|
117
116
|
id: values.map((v) => v && v.id).reduce((a, b) => a === b ? a : void 0) ?? void 0,
|
|
118
117
|
style: devices.map(
|
|
119
118
|
(deviceId) => values.map(
|
|
120
|
-
(v) => v && (0,
|
|
119
|
+
(v) => v && (0, import_controls.findBreakpointOverride)(breakpoints, v.style, deviceId) || {
|
|
121
120
|
deviceId,
|
|
122
121
|
value: {}
|
|
123
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport { Slate
|
|
1
|
+
{"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+C;AAC/C,sBAKO;AAIP,yBAAwB;AACxB,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AI,IAAI,MAAU,KAAK;AAAA,IAC9E,OAAO,QAAQ;AAAA,MAAI,cACjB,OACG;AAAA,QACC,OACG,SAAK,wCAAuB,aAAa,EAAE,OAAO,QAAQ,KAAM;AAAA,UAC/D;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AAAA,MACJ,EACC,OAAO,CAAC,KAAK,EAAE,MAAM,MAAM;AAC1B,cAAM,IAAI,aAAa,IAAI,OAAO,KAAK;AACvC,eAAO;AAAA,UACL;AAAA,UACA,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,wBACd,QACA,aACkB;AAClB,QAAM,SAA6B,CAAC;AAEpC,QAAM,YAAY,oBAAO,MAAM,QAAQ;AAAA,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,kBAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,kBAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":["unhangRange","shallowEqual","deepEqual","keys"]}
|
|
@@ -42,7 +42,8 @@ var APIResources = __toESM(require("./modules/api-resources"));
|
|
|
42
42
|
var LocalizedResourcesMap = __toESM(require("./modules/localized-resources-map"));
|
|
43
43
|
var import_actions = require("./actions");
|
|
44
44
|
var import_api = require("../api");
|
|
45
|
-
var
|
|
45
|
+
var import_cache = require("../next/cache");
|
|
46
|
+
var import_site_version = require("../api/site-version");
|
|
46
47
|
const reducer = (0, import_redux.combineReducers)({
|
|
47
48
|
apiResources: APIResources.reducer,
|
|
48
49
|
localizedResourcesMap: LocalizedResourcesMap.reducer
|
|
@@ -80,10 +81,13 @@ function getAPIResource(state, resourceType, resourceId, locale) {
|
|
|
80
81
|
return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
async function fetchJson(url) {
|
|
84
|
+
async function fetchJson(url, siteVersion) {
|
|
84
85
|
const response = await fetch(url, {
|
|
85
|
-
headers: {
|
|
86
|
-
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Type": "application/json",
|
|
88
|
+
[import_site_version.API_HANDLER_SITE_VERSION_HEADER]: siteVersion
|
|
89
|
+
},
|
|
90
|
+
next: { tags: [import_cache.MAKESWIFT_CACHE_TAG] }
|
|
87
91
|
});
|
|
88
92
|
if (response.status === 404)
|
|
89
93
|
return null;
|
|
@@ -96,7 +100,7 @@ async function fetchJson(url) {
|
|
|
96
100
|
}
|
|
97
101
|
return response.json();
|
|
98
102
|
}
|
|
99
|
-
function fetchAPIResource(resourceType, resourceId, locale) {
|
|
103
|
+
function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
100
104
|
return async (dispatch, getState) => {
|
|
101
105
|
const state = getState();
|
|
102
106
|
if (getHasAPIResource(state, resourceType, resourceId, locale)) {
|
|
@@ -105,16 +109,22 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
105
109
|
let resource;
|
|
106
110
|
switch (resourceType) {
|
|
107
111
|
case import_api.APIResourceType.Swatch:
|
|
108
|
-
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}
|
|
112
|
+
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`, siteVersion);
|
|
109
113
|
break;
|
|
110
114
|
case import_api.APIResourceType.File:
|
|
111
|
-
resource = await fetchJson(`/api/makeswift/files/${resourceId}
|
|
115
|
+
resource = await fetchJson(`/api/makeswift/files/${resourceId}`, siteVersion);
|
|
112
116
|
break;
|
|
113
117
|
case import_api.APIResourceType.Typography:
|
|
114
|
-
resource = await fetchJson(
|
|
118
|
+
resource = await fetchJson(
|
|
119
|
+
`/api/makeswift/typographies/${resourceId}`,
|
|
120
|
+
siteVersion
|
|
121
|
+
);
|
|
115
122
|
break;
|
|
116
123
|
case import_api.APIResourceType.GlobalElement:
|
|
117
|
-
resource = await fetchJson(
|
|
124
|
+
resource = await fetchJson(
|
|
125
|
+
`/api/makeswift/global-elements/${resourceId}`,
|
|
126
|
+
siteVersion
|
|
127
|
+
);
|
|
118
128
|
break;
|
|
119
129
|
case import_api.APIResourceType.LocalizedGlobalElement: {
|
|
120
130
|
if (locale == null)
|
|
@@ -123,7 +133,8 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
123
133
|
return null;
|
|
124
134
|
}
|
|
125
135
|
resource = await fetchJson(
|
|
126
|
-
`/api/makeswift/localized-global-elements/${resourceId}/${locale}
|
|
136
|
+
`/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
|
|
137
|
+
siteVersion
|
|
127
138
|
);
|
|
128
139
|
dispatch(
|
|
129
140
|
(0, import_actions.setLocalizedResourceId)({
|
|
@@ -138,11 +149,11 @@ function fetchAPIResource(resourceType, resourceId, locale) {
|
|
|
138
149
|
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
139
150
|
if (locale != null)
|
|
140
151
|
url.searchParams.set("locale", locale);
|
|
141
|
-
resource = await fetchJson(url.pathname + url.search);
|
|
152
|
+
resource = await fetchJson(url.pathname + url.search, siteVersion);
|
|
142
153
|
break;
|
|
143
154
|
}
|
|
144
155
|
case import_api.APIResourceType.Table:
|
|
145
|
-
resource = await fetchJson(`/api/makeswift/tables/${resourceId}
|
|
156
|
+
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`, siteVersion);
|
|
146
157
|
break;
|
|
147
158
|
default:
|
|
148
159
|
resource = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n applyMiddleware,\n createStore,\n combineReducers,\n type Dispatch as ReduxDispatch,\n type Store as ReduxStore,\n type Middleware,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\n\nimport { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'\n\nimport { serializeState } from '../utils/serializeState'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\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'\nimport { MAKESWIFT_CACHE_TAG } from '../next/api-handler/handlers/webhook/site-published'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\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\nasync function fetchJson<T>(url: string): Promise<T | null> {\n const response = await fetch(url, {\n headers: { 'Content-Type': 'application/json' },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\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\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\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\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\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): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: 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}): Store {\n const composeEnhancers = composeWithDevToolsDevelopmentOnly({\n name: `API client store (${new Date().toISOString()})`,\n serialize: true,\n stateSanitizer: (state: any) => serializeState(state),\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n })\n\n return createStore(\n reducer,\n {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n composeEnhancers(applyMiddleware(thunk, defaultLocaleMiddleware(defaultLocale))),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAOO;AACP,yBAA4D;AAE5D,uBAAmD;AAEnD,4BAA+B;AAE/B,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;AACvF,iBAWO;AACP,4BAAoC;AAEpC,MAAM,cAAU,8BAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AASD,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,2BAAgB;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;AAChD,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO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AA,IAC1D,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,IACnD,WAAW;AAAA,IACX,gBAAgB,CAAC,cAAe,sCAAe,KAAK;AAAA,IACpD,iBAAiB;AAAA,MACf,2BAAY;AAAA,MACZ,2BAAY;AAAA,MACZ,2BAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,aAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,qBAAiB,8BAAgB,mBAAAA,SAAO,wBAAwB,aAAa,CAAC,CAAC;AAAA,EACjF;AACF;","names":["thunk"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n applyMiddleware,\n createStore,\n combineReducers,\n type Dispatch as ReduxDispatch,\n type Store as ReduxStore,\n type Middleware,\n} from 'redux'\nimport thunk, { type ThunkAction, type ThunkDispatch } from 'redux-thunk'\n\nimport { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'\n\nimport { serializeState } from '../utils/serializeState'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\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'\nimport { MAKESWIFT_CACHE_TAG } from '../next/cache'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../api/site-version'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\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\nasync function fetchJson<T>(url: string, siteVersion: MakeswiftSiteVersion): Promise<T | null> {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\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\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n siteVersion: MakeswiftSiteVersion,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\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}`, siteVersion)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n siteVersion,\n )\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 siteVersion,\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, siteVersion)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`, siteVersion)\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\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\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): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: 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}): Store {\n const composeEnhancers = composeWithDevToolsDevelopmentOnly({\n name: `API client store (${new Date().toISOString()})`,\n serialize: true,\n stateSanitizer: (state: any) => serializeState(state),\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n })\n\n return createStore(\n reducer,\n {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n composeEnhancers(applyMiddleware(thunk, defaultLocaleMiddleware(defaultLocale))),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAOO;AACP,yBAA4D;AAE5D,uBAAmD;AAEnD,4BAA+B;AAE/B,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;A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,MACE,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,qBAAiB,8BAAgB,mBAAAA,SAAO,wBAAwB,aAAa,CAAC,CAAC;AAAA,EACjF;AACF;","names":["thunk"]}
|
|
@@ -20,18 +20,12 @@ var breakpoints_exports = {};
|
|
|
20
20
|
__export(breakpoints_exports, {
|
|
21
21
|
DEFAULT_BREAKPOINTS: () => DEFAULT_BREAKPOINTS,
|
|
22
22
|
DefaultBreakpointID: () => DefaultBreakpointID,
|
|
23
|
-
|
|
24
|
-
findNextFallback: () => findNextFallback,
|
|
25
|
-
getBaseBreakpoint: () => import_controls2.getBaseBreakpoint,
|
|
26
|
-
getBreakpoint: () => getBreakpoint,
|
|
27
|
-
getBreakpointMediaQuery: () => getBreakpointMediaQuery,
|
|
23
|
+
getBreakpoint: () => import_controls2.getBreakpoint,
|
|
28
24
|
getInitialState: () => getInitialState,
|
|
29
|
-
getViewportStyle: () => getViewportStyle,
|
|
30
25
|
parseBreakpointsInput: () => parseBreakpointsInput,
|
|
31
26
|
reducer: () => reducer
|
|
32
27
|
});
|
|
33
28
|
module.exports = __toCommonJS(breakpoints_exports);
|
|
34
|
-
var import_controls = require("@makeswift/controls");
|
|
35
29
|
var import_actions = require("../actions");
|
|
36
30
|
var import_controls2 = require("@makeswift/controls");
|
|
37
31
|
const DefaultBreakpointID = {
|
|
@@ -127,49 +121,12 @@ function validateBreakpointsInput(input) {
|
|
|
127
121
|
}
|
|
128
122
|
});
|
|
129
123
|
}
|
|
130
|
-
const getBreakpoint = (state, breakpointId) => {
|
|
131
|
-
const breakpoint = state.find(({ id }) => id === breakpointId);
|
|
132
|
-
if (breakpoint == null)
|
|
133
|
-
throw new Error(`Unrecognized breakpoint ID: "${breakpointId}".`);
|
|
134
|
-
return breakpoint;
|
|
135
|
-
};
|
|
136
|
-
const getBreakpointMediaQuery = (breakpoint) => {
|
|
137
|
-
const parts = ["@media only screen"];
|
|
138
|
-
if (breakpoint.minWidth != null) {
|
|
139
|
-
parts.push(`(min-width: ${breakpoint.minWidth}px)`);
|
|
140
|
-
}
|
|
141
|
-
if (breakpoint.maxWidth != null) {
|
|
142
|
-
parts.push(`(max-width: ${breakpoint.maxWidth}px)`);
|
|
143
|
-
}
|
|
144
|
-
return parts.join(" and ");
|
|
145
|
-
};
|
|
146
|
-
const getViewportStyle = (state, deviceId) => {
|
|
147
|
-
const device = getBreakpoint(state, deviceId);
|
|
148
|
-
return device && {
|
|
149
|
-
width: device.viewportWidth != null ? device.viewportWidth : "100%",
|
|
150
|
-
minWidth: device.minWidth
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallbackStrategy) {
|
|
154
|
-
const deviceOverride = (0, import_controls.findBreakpointOverride)(
|
|
155
|
-
breakpoints,
|
|
156
|
-
value.filter((v) => v.deviceId !== activeDeviceId),
|
|
157
|
-
deviceId,
|
|
158
|
-
fallbackStrategy
|
|
159
|
-
);
|
|
160
|
-
return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null;
|
|
161
|
-
}
|
|
162
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
163
125
|
0 && (module.exports = {
|
|
164
126
|
DEFAULT_BREAKPOINTS,
|
|
165
127
|
DefaultBreakpointID,
|
|
166
|
-
findBreakpointOverride,
|
|
167
|
-
findNextFallback,
|
|
168
|
-
getBaseBreakpoint,
|
|
169
128
|
getBreakpoint,
|
|
170
|
-
getBreakpointMediaQuery,
|
|
171
129
|
getInitialState,
|
|
172
|
-
getViewportStyle,
|
|
173
130
|
parseBreakpointsInput,
|
|
174
131
|
reducer
|
|
175
132
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { type Breakpoint, type Breakpoints } from '@makeswift/controls'\n\nimport { Action, ActionTypes } 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): State {\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAoC;AAEpC,IAAAA,mBAKO;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,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