@makeswift/runtime 0.24.0-canary.1 → 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 +4 -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 +91 -0
- package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
- 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 +7 -4
- 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 +3 -3
- 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/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 +4 -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 +56 -0
- package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
- 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 +7 -4
- 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 +3 -3
- 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/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.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/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/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-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/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 +15 -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/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/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/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
|
@@ -0,0 +1,68 @@
|
|
|
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 use_resolvable_record_exports = {};
|
|
20
|
+
__export(use_resolvable_record_exports, {
|
|
21
|
+
useResolvableRecord: () => useResolvableRecord
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_resolvable_record_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
function useResolvableRecord(resolvables) {
|
|
26
|
+
const snapshot = (0, import_react.useRef)({ resolvedValues: {}, dirtyProps: /* @__PURE__ */ new Set() });
|
|
27
|
+
return (0, import_react.useMemo)(() => {
|
|
28
|
+
return {
|
|
29
|
+
name: "resolvable-record",
|
|
30
|
+
subscribe: (onUpdate) => {
|
|
31
|
+
const unsubscribes = Object.values(resolvables).map((s) => s.subscribe(onUpdate));
|
|
32
|
+
return () => {
|
|
33
|
+
unsubscribes.forEach((u) => u());
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
readStable: () => {
|
|
37
|
+
const nextSnapshot = Object.entries(resolvables).reduce(
|
|
38
|
+
({ dirtyProps, resolvedValues }, [propName, subscription]) => {
|
|
39
|
+
const lastPropValue = snapshot.current.resolvedValues[propName];
|
|
40
|
+
const propValue = subscription.readStable();
|
|
41
|
+
const isDirty = propValue !== lastPropValue;
|
|
42
|
+
return {
|
|
43
|
+
dirtyProps: isDirty ? dirtyProps.add(propName) : dirtyProps,
|
|
44
|
+
resolvedValues: { ...resolvedValues, [propName]: propValue }
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
{ resolvedValues: {}, dirtyProps: /* @__PURE__ */ new Set() }
|
|
48
|
+
);
|
|
49
|
+
if (nextSnapshot.dirtyProps.size > 0) {
|
|
50
|
+
snapshot.current = nextSnapshot;
|
|
51
|
+
}
|
|
52
|
+
return snapshot.current.resolvedValues;
|
|
53
|
+
},
|
|
54
|
+
triggerResolve: async () => {
|
|
55
|
+
return await Promise.all(
|
|
56
|
+
Object.entries(resolvables).map(
|
|
57
|
+
([propName, sub]) => sub.triggerResolve(snapshot.current.resolvedValues[propName])
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [resolvables]);
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
useResolvableRecord
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=use-resolvable-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolvable-record.tsx"],"sourcesContent":["import { type Resolvable } from '@makeswift/controls'\nimport { useMemo, useRef } from 'react'\n\ntype Snapshot = {\n resolvedValues: Record<string, unknown>\n dirtyProps: Set<string>\n}\n\nexport function useResolvableRecord(\n resolvables: Record<string, Resolvable<unknown>>,\n): Resolvable<Record<string, unknown>> {\n const snapshot = useRef<Snapshot>({ resolvedValues: {}, dirtyProps: new Set() })\n\n return useMemo<Resolvable<Record<string, unknown>>>(() => {\n return {\n name: 'resolvable-record',\n subscribe: (onUpdate: () => void): (() => void) => {\n const unsubscribes = Object.values(resolvables).map(s => s.subscribe(onUpdate))\n return () => {\n unsubscribes.forEach(u => u())\n }\n },\n\n readStable: () => {\n const nextSnapshot = Object.entries(resolvables).reduce<Snapshot>(\n ({ dirtyProps, resolvedValues }, [propName, subscription]) => {\n const lastPropValue = snapshot.current.resolvedValues[propName]\n const propValue = subscription.readStable()\n const isDirty = propValue !== lastPropValue\n\n return {\n dirtyProps: isDirty ? dirtyProps.add(propName) : dirtyProps,\n resolvedValues: { ...resolvedValues, [propName]: propValue },\n }\n },\n { resolvedValues: {}, dirtyProps: new Set() },\n )\n\n if (nextSnapshot.dirtyProps.size > 0) {\n snapshot.current = nextSnapshot\n }\n\n return snapshot.current.resolvedValues\n },\n\n triggerResolve: async () => {\n // While we _could_ only trigger resolution on the dirty props, this is\n // not an airtight solution. Some controls will resolve to nullish\n // values even when the underlying data changes, so they won't be dirty\n // (ex: an Image control where the data changes from `undefined` to a\n // file that has not yet been fetched). Even if you add a nullish check\n // on the resolved value, some controls can resolve to non-nullish value\n // when the resolution does not occur (ex: swatches can resolve to\n // black). The true solution is to trigger resolve on underlying data\n // change, and moving these dirtiness optimizations for resolution\n // triggering at the control level.\n return await Promise.all(\n Object.entries(resolvables).map(([propName, sub]) =>\n sub.triggerResolve(snapshot.current.resolvedValues[propName]),\n ),\n )\n },\n }\n }, [resolvables])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAgC;AAOzB,SAAS,oBACd,aACqC;AACrC,QAAM,eAAW,qBAAiB,EAAE,gBAAgB,CAAC,GAAG,YAAY,oBAAI,IAAI,EAAE,CAAC;AAE/E,aAAO,sBAA6C,MAAM;AACxD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW,CAAC,aAAuC;AACjD,cAAM,eAAe,OAAO,OAAO,WAAW,EAAE,IAAI,OAAK,EAAE,UAAU,QAAQ,CAAC;AAC9E,eAAO,MAAM;AACX,uBAAa,QAAQ,OAAK,EAAE,CAAC;AAAA,QAC/B;AAAA,MACF;AAAA,MAEA,YAAY,MAAM;AAChB,cAAM,eAAe,OAAO,QAAQ,WAAW,EAAE;AAAA,UAC/C,CAAC,EAAE,YAAY,eAAe,GAAG,CAAC,UAAU,YAAY,MAAM;AAC5D,kBAAM,gBAAgB,SAAS,QAAQ,eAAe,QAAQ;AAC9D,kBAAM,YAAY,aAAa,WAAW;AAC1C,kBAAM,UAAU,cAAc;AAE9B,mBAAO;AAAA,cACL,YAAY,UAAU,WAAW,IAAI,QAAQ,IAAI;AAAA,cACjD,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,QAAQ,GAAG,UAAU;AAAA,YAC7D;AAAA,UACF;AAAA,UACA,EAAE,gBAAgB,CAAC,GAAG,YAAY,oBAAI,IAAI,EAAE;AAAA,QAC9C;AAEA,YAAI,aAAa,WAAW,OAAO,GAAG;AACpC,mBAAS,UAAU;AAAA,QACrB;AAEA,eAAO,SAAS,QAAQ;AAAA,MAC1B;AAAA,MAEA,gBAAgB,YAAY;AAW1B,eAAO,MAAM,QAAQ;AAAA,UACnB,OAAO,QAAQ,WAAW,EAAE;AAAA,YAAI,CAAC,CAAC,UAAU,GAAG,MAC7C,IAAI,eAAe,SAAS,QAAQ,eAAe,QAAQ,CAAC;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAClB;","names":[]}
|
|
@@ -38,7 +38,7 @@ var import_use_resource_resolver = require("./use-resource-resolver");
|
|
|
38
38
|
var import_use_document_context = require("./use-document-context");
|
|
39
39
|
var import_use_selector = require("./use-selector");
|
|
40
40
|
var import_use_stylesheet_factory = require("./use-stylesheet-factory");
|
|
41
|
-
var
|
|
41
|
+
var import_use_resolvable_record = require("./use-resolvable-record");
|
|
42
42
|
var import_prop_error_handling_proxy = require("../utils/prop-error-handling-proxy");
|
|
43
43
|
function useControlInstances(elementKey) {
|
|
44
44
|
const documentKey = (0, import_use_document_context.useDocumentKey)();
|
|
@@ -83,10 +83,10 @@ function useResolvedProps(propDefs, elementData, elementKey) {
|
|
|
83
83
|
}),
|
|
84
84
|
[propDefs, resolveProp]
|
|
85
85
|
);
|
|
86
|
-
const props = (0,
|
|
86
|
+
const props = (0, import_use_resolvable_record.useResolvableRecord)(resolvables);
|
|
87
87
|
(0, import_react.useEffect)(() => {
|
|
88
88
|
props.triggerResolve();
|
|
89
|
-
}, []);
|
|
89
|
+
}, [props]);
|
|
90
90
|
const resolvedProps = (0, import_react.useSyncExternalStore)(props.subscribe, props.readStable, props.readStable);
|
|
91
91
|
stylesheetFactory.useDefinedStyles();
|
|
92
92
|
return resolvedProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { useResolvableRecord } from './use-resolvable-record'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo<Record<string, Resolvable<unknown>>>(\n () =>\n mapValues(propDefs, (def, propName) => {\n const defaultValue = (def.config as any)?.defaultValue\n return propErrorHandlingProxy(resolveProp(def, propName), defaultValue, error => {\n console.warn(\n `Error reading value for prop \"${propName}\", falling back to \\`${defaultValue}\\`.`,\n { control: def, error },\n )\n })\n }),\n [propDefs, resolveProp],\n )\n\n const props = useResolvableRecord(resolvables)\n\n // no need to call `triggerResolve` on the server, all the resources should already be in\n // the host API client's cache (populated from the snapshot's cache)\n useEffect(() => {\n props.triggerResolve()\n }, [props])\n\n // the order is important here, the styles are defined in the process of the props resolution,\n // calling `useDefinedStyles` before the props are resolved would effectively be a noop\n const resolvedProps = useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n\n stylesheetFactory.useDefinedStyles()\n\n return resolvedProps\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8E;AAC9E,sBAMO;AAEP,gBAA2B;AAC3B,mCAAoC;AACpC,kCAA+B;AAC/B,0BAA4B;AAE5B,oCAAqC;AAErC,mCAAoC;AACpC,uCAAuC;AAEvC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,kBAAc,4CAAe;AAEnC,aAAO,iCAAY,WAAS;AAC1B,QAAI,eAAe;AAAM,aAAO;AAEhC,WAAO,UAAU,mBAAmB,OAAO,aAAa,UAAU;AAAA,EACpE,CAAC;AACH;AAQO,SAAS,iBACd,UACA,aACA,YACyB;AACzB,QAAM,wBAAoB,oDAAqB;AAC/C,QAAM,uBAAm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aultValue]);
|
|
34
34
|
(0, import_react.useEffect)(() => {
|
|
35
35
|
resolvable.triggerResolve();
|
|
36
|
-
}, []);
|
|
36
|
+
}, [resolvable]);
|
|
37
37
|
return (0, import_react.useSyncExternalStore)(resolvable.subscribe, resolvable.readStable, resolvable.readStable);
|
|
38
38
|
}
|
|
39
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { useMemo, useEffect, useSyncExternalStore } from 'react'\nimport { Resolvable, ResourceResolver } from '@makeswift/controls'\n\nimport { useResourceResolver } from './use-resource-resolver'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nexport function useResolvedValue<D, T>(\n data: D,\n resolver: (data: D, resourceResolver: ResourceResolver) => Resolvable<T>,\n defaultValue?: T,\n): T | undefined {\n const resourceResolver = useResourceResolver()\n const resolvable = useMemo(() => {\n return propErrorHandlingProxy(resolver(data, resourceResolver), defaultValue, error => {\n console.warn(`Error resolving data, falling back to \\`${defaultValue}\\`.`, { error, data })\n })\n }, [data, resourceResolver, defaultValue])\n\n useEffect(() => {\n resolvable.triggerResolve()\n }, [])\n\n return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyD;AAGzD,mCAAoC;AACpC,uCAAuC;AAEhC,SAAS,iBACd,MACA,UACA,cACe;AACf,QAAM,uBAAmB,kDAAoB;AAC7C,QAAM,iBAAa,sBAAQ,MAAM;AAC/B,eAAO,yDAAuB,SAAS,MAAM,gBAAgB,GAAG,cAAc,WAAS;AACrF,cAAQ,KAAK,2CAA2C,YAAY,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5F,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,kBAAkB,YAAY,CAAC;AAEzC,8BAAU,MAAM;AACd,eAAW,eAAe;AAAA,EAC5B,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-value.ts"],"sourcesContent":["import { useMemo, useEffect, useSyncExternalStore } from 'react'\nimport { Resolvable, ResourceResolver } from '@makeswift/controls'\n\nimport { useResourceResolver } from './use-resource-resolver'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nexport function useResolvedValue<D, T>(\n data: D,\n resolver: (data: D, resourceResolver: ResourceResolver) => Resolvable<T>,\n defaultValue?: T,\n): T | undefined {\n const resourceResolver = useResourceResolver()\n const resolvable = useMemo(() => {\n return propErrorHandlingProxy(resolver(data, resourceResolver), defaultValue, error => {\n console.warn(`Error resolving data, falling back to \\`${defaultValue}\\`.`, { error, data })\n })\n }, [data, resourceResolver, defaultValue])\n\n useEffect(() => {\n resolvable.triggerResolve()\n }, [resolvable])\n\n return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyD;AAGzD,mCAAoC;AACpC,uCAAuC;AAEhC,SAAS,iBACd,MACA,UACA,cACe;AACf,QAAM,uBAAmB,kDAAoB;AAC7C,QAAM,iBAAa,sBAAQ,MAAM;AAC/B,eAAO,yDAAuB,SAAS,MAAM,gBAAgB,GAAG,cAAc,WAAS;AACrF,cAAQ,KAAK,2CAA2C,YAAY,OAAO,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5F,CAAC;AAAA,EACH,GAAG,CAAC,MAAM,kBAAkB,YAAY,CAAC;AAEzC,8BAAU,MAAM;AACd,eAAW,eAAe;AAAA,EAC5B,GAAG,CAAC,UAAU,CAAC;AAEf,aAAO,mCAAqB,WAAW,WAAW,WAAW,YAAY,WAAW,UAAU;AAChG;","names":[]}
|
|
@@ -39,7 +39,8 @@ var import_use_document_context = require("./use-document-context");
|
|
|
39
39
|
function useResourceResolver() {
|
|
40
40
|
const store = (0, import_use_store.useStore)();
|
|
41
41
|
const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
|
|
42
|
-
const
|
|
42
|
+
const documentKey = (0, import_use_document_context.useDocumentKey)();
|
|
43
|
+
const locale = (0, import_use_document_context.useDocumentLocale)();
|
|
43
44
|
return (0, import_react.useMemo)(() => {
|
|
44
45
|
return {
|
|
45
46
|
resolveSwatch: (swatchId) => client.resolveSwatch(swatchId),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useStore } from './use-store'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { useStore } from './use-store'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const client = useMakeswiftHostApiClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(() => {\n return {\n resolveSwatch: swatchId => client.resolveSwatch(swatchId),\n resolveFile: fileId => client.resolveFile(fileId),\n resolveTypography: typographyId => client.resolveTypography(typographyId),\n resolvePagePathnameSlice: pageId => client.resolvePagePathnameSlice({ pageId, locale }),\n resolveElementId: elementKey => {\n const read = () =>\n documentKey == null\n ? null\n : ReactPage.getElementId(store.getState(), documentKey, elementKey)\n\n let lastValue: string | null = null\n return {\n name: `element-id:${documentKey}:${elementKey}`,\n readStable: () => (lastValue = read()),\n subscribe: (onUpdate: () => void) =>\n store.subscribe(() => {\n if (read() !== lastValue) onUpdate()\n }),\n }\n },\n }\n }, [client, store, documentKey, locale])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAGxB,gBAA2B;AAC3B,6BAA0C;AAC1C,uBAAyB;AACzB,kCAAkD;AAE3C,SAAS,sBAAwC;AACtD,QAAM,YAAQ,2BAAS;AACvB,QAAM,aAAS,kDAA0B;AAEzC,QAAM,kBAAc,4CAAe;AACnC,QAAM,aAAS,+CAAkB;AAEjC,aAAO,sBAA0B,MAAM;AACrC,WAAO;AAAA,MACL,eAAe,cAAY,OAAO,cAAc,QAAQ;AAAA,MACxD,aAAa,YAAU,OAAO,YAAY,MAAM;AAAA,MAChD,mBAAmB,kBAAgB,OAAO,kBAAkB,YAAY;AAAA,MACxE,0BAA0B,YAAU,OAAO,yBAAyB,EAAE,QAAQ,OAAO,CAAC;AAAA,MACtF,kBAAkB,gBAAc;AAC9B,cAAM,OAAO,MACX,eAAe,OACX,OACA,UAAU,aAAa,MAAM,SAAS,GAAG,aAAa,UAAU;AAEtE,YAAI,YAA2B;AAC/B,eAAO;AAAA,UACL,MAAM,cAAc,WAAW,IAAI,UAAU;AAAA,UAC7C,YAAY,MAAO,YAAY,KAAK;AAAA,UACpC,WAAW,CAAC,aACV,MAAM,UAAU,MAAM;AACpB,gBAAI,KAAK,MAAM;AAAW,uBAAS;AAAA,UACrC,CAAC;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,aAAa,MAAM,CAAC;AACzC;","names":[]}
|
|
@@ -25,7 +25,6 @@ var import_react = require("react");
|
|
|
25
25
|
var import_serialize = require("@emotion/serialize");
|
|
26
26
|
var import_controls = require("@makeswift/controls");
|
|
27
27
|
var import_root_style_registry = require("../../../next/root-style-registry");
|
|
28
|
-
var import_breakpoints = require("../../../state/modules/breakpoints");
|
|
29
28
|
var import_style = require("../controls/style");
|
|
30
29
|
var import_typography = require("../controls/typography");
|
|
31
30
|
var import_use_breakpoints = require("./use-breakpoints");
|
|
@@ -88,7 +87,7 @@ function styleV2Css(breakpoints, style) {
|
|
|
88
87
|
...breakpoints.reduce(
|
|
89
88
|
(styles, breakpoint) => ({
|
|
90
89
|
...styles,
|
|
91
|
-
[(0,
|
|
90
|
+
[(0, import_controls.getBreakpointMediaQuery)(breakpoint)]: style.getStyle(breakpoint)
|
|
92
91
|
}),
|
|
93
92
|
{}
|
|
94
93
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n} from '@makeswift/controls'\n\nimport { useCache } from '../../../next/root-style-registry'\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useCache } from '../../../next/root-style-registry'\n\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2C;AAC3C,uBAAgD;AAIhD,sBAUO;AAEP,iCAAyB;AAEzB,mBAA2B;AAC3B,wBAA8B;AAE9B,6BAA+B;AAC/B,wBAAyB;AACzB,uBAAoD;AACpD,4BAA6B;AAOtB,SAAS,uBAA0C;AACxD,QAAM,kBAAc,uCAAe;AACnC,QAAM,YAAQ,qCAAS;AACvB,QAAM,mBAAe,4BAAS;AAE9B,QAAM,qBAAiB,qBAAyC,CAAC,CAAC,EAAE;AACpE,QAAM,wBAAoB,qBAA4D,CAAC,CAAC,EAAE;AAE1F,aAAO,sBAAQ,MAAM;AACnB,UAAM,gBAAgB,CAAC,kBAAsC;AAAA,MAC3D,cAA2B;AACzB,eAAO;AAAA,MACT;AAAA,MAEA,YACE,OACA,kBACQ;AACR,cAAM,aAAa,eAAe,aAAa,OAAO,KAAK;AAC3D,cAAM,MAAM,KAAK,YAAY,IAAI,YAAY;AAC7C,uBAAe,GAAG,IAAI;AAEtB,cAAM,gBAAY,2CAAyB,OAAO,UAAU;AAC5D,YAAI,CAAC;AAAkB,iBAAO;AAE9B,0BAAkB,GAAG,IAAI;AACzB,eAAO,GAAG,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AAC5B,eAAO,iCAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,aAAO,yBAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,aAAO,kCAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
|
|
@@ -26,8 +26,12 @@ module.exports = __toCommonJS(host_api_client_exports);
|
|
|
26
26
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_react2 = require("../../api/react");
|
|
29
|
+
var import_site_version = require("../../api/site-version");
|
|
29
30
|
const Context = (0, import_react.createContext)(
|
|
30
|
-
new import_react2.MakeswiftHostApiClient({
|
|
31
|
+
new import_react2.MakeswiftHostApiClient({
|
|
32
|
+
uri: "https://api.makeswift.com/graphql",
|
|
33
|
+
siteVersion: import_site_version.MakeswiftSiteVersion.Live
|
|
34
|
+
})
|
|
31
35
|
);
|
|
32
36
|
function useMakeswiftHostApiClient() {
|
|
33
37
|
return (0, import_react.useContext)(Context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\nimport { MakeswiftSiteVersion } from '../../api/site-version'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n siteVersion: MakeswiftSiteVersion.Live,\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBS;AAtBT,mBAAqD;AACrD,IAAAA,gBAAuC;AACvC,0BAAqC;AAErC,MAAM,cAAU;AAAA,EACd,IAAI,qCAAuB;AAAA,IACzB,KAAK;AAAA,IACL,aAAa,yCAAqB;AAAA,EACpC,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,aAAO,yBAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,4CAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":["import_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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EAAE,EAAE,OAAO,CAAC,GAAG,MAAO,MAAM,IAAI,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,eAA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ACA;AACF,GAGU;AACR,QAAM,uBAAmB,qDAAmC;AAAA,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;AA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,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"]}
|
|
@@ -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
|
});
|