payload-canvas 0.4.0 → 0.5.1
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/README.md +626 -154
- package/dist/admin/AiKeyField.d.ts +8 -0
- package/dist/admin/AiKeyField.js +54 -0
- package/dist/admin/BuilderTab.js +4 -1
- package/dist/admin/DocumentEditView.d.ts +9 -0
- package/dist/admin/DocumentEditView.js +45 -0
- package/dist/admin/LayoutField.d.ts +2 -2
- package/dist/admin/LayoutField.js +10 -7
- package/dist/admin/TemplateConditionsField.d.ts +9 -0
- package/dist/admin/TemplateConditionsField.js +22 -0
- package/dist/admin/aiKeyField.scss +58 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +6 -0
- package/dist/admin/diff/changes.js +5 -0
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/Inspector.js +75 -28
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +21 -16
- package/dist/admin/editor/Overlay.js +8 -3
- package/dist/admin/editor/actions.d.ts +10 -2
- package/dist/admin/editor/actions.js +18 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
- package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
- package/dist/admin/editor/classes/ClassManager.js +56 -0
- package/dist/admin/editor/classes/controller.d.ts +112 -0
- package/dist/admin/editor/classes/controller.js +326 -0
- package/dist/admin/editor/classes/manager.scss +262 -0
- package/dist/admin/editor/classes/managerModel.d.ts +5 -0
- package/dist/admin/editor/classes/managerModel.js +27 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
- package/dist/admin/editor/comments/CommentLayer.js +143 -0
- package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
- package/dist/admin/editor/comments/CommentsPanel.js +73 -0
- package/dist/admin/editor/comments/Thread.d.ts +26 -0
- package/dist/admin/editor/comments/Thread.js +84 -0
- package/dist/admin/editor/comments/comments.scss +539 -0
- package/dist/admin/editor/comments/controller.d.ts +48 -0
- package/dist/admin/editor/comments/controller.js +142 -0
- package/dist/admin/editor/contentMode.d.ts +17 -0
- package/dist/admin/editor/contentMode.js +37 -0
- package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
- package/dist/admin/editor/dnd/DropOutlines.js +73 -0
- package/dist/admin/editor/dnd/dnd.scss +43 -0
- package/dist/admin/editor/dnd/mode.d.ts +4 -0
- package/dist/admin/editor/dnd/mode.js +39 -0
- package/dist/admin/editor/editor.scss +13 -58
- package/dist/admin/editor/empty/EmptyStart.js +18 -66
- package/dist/admin/editor/fields/AddButton.d.ts +15 -0
- package/dist/admin/editor/fields/AddButton.js +14 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -2
- package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
- package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
- package/dist/admin/editor/fields/ConditionRows.js +137 -0
- package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
- package/dist/admin/editor/fields/ListWhereField.js +20 -0
- package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
- package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
- package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
- package/dist/admin/editor/fields/RelatedField.js +44 -0
- package/dist/admin/editor/fields/SortField.d.ts +13 -0
- package/dist/admin/editor/fields/SortField.js +37 -0
- package/dist/admin/editor/fields/WhereField.d.ts +12 -4
- package/dist/admin/editor/fields/WhereField.js +33 -53
- package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
- package/dist/admin/editor/fields/collectionFields.js +15 -0
- package/dist/admin/editor/fields/conditions.d.ts +99 -0
- package/dist/admin/editor/fields/conditions.js +339 -0
- package/dist/admin/editor/fields/fields.scss +232 -9
- package/dist/admin/editor/fields/listOptions.d.ts +44 -0
- package/dist/admin/editor/fields/listOptions.js +111 -0
- package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
- package/dist/admin/editor/fields/queryFilterRows.js +29 -0
- package/dist/admin/editor/fields/whereRows.d.ts +11 -12
- package/dist/admin/editor/fields/whereRows.js +83 -34
- package/dist/admin/editor/icons.d.ts +16 -1
- package/dist/admin/editor/icons.js +30 -1
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +4 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -1
- package/dist/admin/editor/insert/picker.js +17 -10
- package/dist/admin/editor/insert/spots.d.ts +12 -1
- package/dist/admin/editor/insert/spots.js +49 -10
- package/dist/admin/editor/layout/LeftPanel.js +11 -6
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/menu/blockMenu.js +27 -17
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +63 -12
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +67 -6
- package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
- package/dist/admin/editor/sections/ComponentFields.js +116 -0
- package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
- package/dist/admin/editor/sections/PropertyControls.js +65 -0
- package/dist/admin/editor/sections/components.d.ts +29 -0
- package/dist/admin/editor/sections/components.js +112 -0
- package/dist/admin/editor/sections/components.scss +238 -0
- package/dist/admin/editor/sections/variants.d.ts +32 -0
- package/dist/admin/editor/sections/variants.js +59 -0
- package/dist/admin/editor/sections/variants.scss +90 -0
- package/dist/admin/editor/shortcuts.d.ts +4 -1
- package/dist/admin/editor/shortcuts.js +19 -3
- package/dist/admin/editor/store.d.ts +18 -0
- package/dist/admin/editor/store.js +46 -0
- package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
- package/dist/admin/editor/styles/ClassBar.js +90 -0
- package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
- package/dist/admin/editor/styles/ClassCss.js +28 -0
- package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
- package/dist/admin/editor/styles/ClassDialog.js +151 -0
- package/dist/admin/editor/styles/ColorPicker.js +5 -2
- package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
- package/dist/admin/editor/styles/RawClasses.js +184 -32
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
- package/dist/admin/editor/styles/StylesPanel.js +53 -14
- package/dist/admin/editor/styles/VariantBar.js +2 -2
- package/dist/admin/editor/styles/classEdit.d.ts +4 -0
- package/dist/admin/editor/styles/classEdit.js +20 -0
- package/dist/admin/editor/styles/classes.scss +381 -0
- package/dist/admin/editor/styles/context.d.ts +19 -6
- package/dist/admin/editor/styles/context.js +24 -6
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +30 -12
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/styles.scss +26 -104
- package/dist/admin/editor/styles/suggestions.d.ts +22 -0
- package/dist/admin/editor/styles/suggestions.js +77 -0
- package/dist/admin/editor/styles/tokens.js +14 -0
- package/dist/admin/editor/templates/Bindable.js +86 -57
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/Visibility.d.ts +9 -0
- package/dist/admin/editor/templates/Visibility.js +54 -0
- package/dist/admin/editor/templates/binding.d.ts +2 -2
- package/dist/admin/editor/templates/binding.js +2 -2
- package/dist/admin/editor/templates/templates.scss +27 -0
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
- package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
- package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +5 -4
- package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/topbar.scss +3 -1
- package/dist/admin/formChoice.d.ts +3 -0
- package/dist/admin/formChoice.js +10 -0
- package/dist/admin/layoutField.scss +69 -0
- package/dist/admin/screen/BuilderScreen.d.ts +6 -1
- package/dist/admin/screen/BuilderScreen.js +4 -3
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.js +17 -4
- package/dist/ai/adapters/cloudflare-gateway.js +7 -1
- package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
- package/dist/ai/adapters/openai-compatible.js +1 -0
- package/dist/ai/adapters/openrouter.js +2 -0
- package/dist/ai/config.d.ts +24 -4
- package/dist/ai/config.js +27 -8
- package/dist/ai/endpoint.d.ts +5 -2
- package/dist/ai/endpoint.js +31 -26
- package/dist/ai/images/cloudflare-workers-ai.js +6 -2
- package/dist/ai/images/openai.js +8 -3
- package/dist/ai/images/openrouter.js +6 -2
- package/dist/ai/images/service.d.ts +10 -4
- package/dist/ai/images/service.js +23 -7
- package/dist/ai/openai-format.d.ts +7 -0
- package/dist/ai/openai-format.js +17 -5
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +25 -5
- package/dist/ai/settings/index.d.ts +62 -0
- package/dist/ai/settings/index.js +264 -0
- package/dist/ai/settings/secret.d.ts +11 -0
- package/dist/ai/settings/secret.js +46 -0
- package/dist/ai/settings/shared.d.ts +22 -0
- package/dist/ai/settings/shared.js +3 -0
- package/dist/ai/tools.d.ts +3 -0
- package/dist/ai/tools.js +79 -15
- package/dist/ai/types.d.ts +43 -0
- package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
- package/dist/blocks/builtins/adjacentLinks.js +76 -0
- package/dist/blocks/builtins/carousel.d.ts +2 -29
- package/dist/blocks/builtins/carousel.js +44 -51
- package/dist/blocks/builtins/disclosure.d.ts +2 -1
- package/dist/blocks/builtins/disclosure.js +22 -32
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +1 -1
- package/dist/blocks/builtins/faq.js +2 -2
- package/dist/blocks/builtins/filterLink.d.ts +1 -19
- package/dist/blocks/builtins/filterLink.js +9 -50
- package/dist/blocks/builtins/icon.d.ts +2 -0
- package/dist/blocks/builtins/icon.js +8 -8
- package/dist/blocks/builtins/index.d.ts +18 -13
- package/dist/blocks/builtins/index.js +43 -22
- package/dist/blocks/builtins/marquee.d.ts +5 -0
- package/dist/blocks/builtins/marquee.js +68 -0
- package/dist/blocks/builtins/popup.d.ts +5 -0
- package/dist/blocks/builtins/popup.js +83 -0
- package/dist/blocks/builtins/sectionRef.d.ts +16 -2
- package/dist/blocks/builtins/sectionRef.js +34 -12
- package/dist/blocks/builtins/shared.d.ts +18 -23
- package/dist/blocks/builtins/shared.js +34 -42
- package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
- package/dist/blocks/builtins/tableOfContents.js +12 -18
- package/dist/blocks/builtins/tabs.d.ts +6 -0
- package/dist/blocks/builtins/tabs.js +87 -0
- package/dist/blocks/client/adjacentLinks.d.ts +4 -0
- package/dist/blocks/client/adjacentLinks.js +4 -0
- package/dist/blocks/client/carousel.d.ts +45 -0
- package/dist/blocks/client/carousel.js +53 -0
- package/dist/blocks/client/embed.d.ts +21 -0
- package/dist/blocks/client/embed.js +23 -0
- package/dist/blocks/client/field.d.ts +7 -0
- package/dist/blocks/client/field.js +8 -0
- package/dist/blocks/client/filterLink.d.ts +19 -0
- package/dist/blocks/client/filterLink.js +30 -0
- package/dist/blocks/client/helpers.d.ts +21 -0
- package/dist/blocks/client/helpers.js +24 -0
- package/dist/blocks/client/marquee.d.ts +14 -0
- package/dist/blocks/client/marquee.js +25 -0
- package/dist/blocks/client/menu.d.ts +46 -0
- package/dist/blocks/client/menu.js +49 -0
- package/dist/blocks/client/popup.d.ts +15 -0
- package/dist/blocks/client/popup.js +16 -0
- package/dist/blocks/client/tabs.d.ts +10 -0
- package/dist/blocks/client/tabs.js +11 -0
- package/dist/blocks/defaults.d.ts +15 -52
- package/dist/blocks/defaults.js +203 -437
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +2 -1
- package/dist/classes/actions.d.ts +97 -0
- package/dist/classes/actions.js +296 -0
- package/dist/classes/collection.d.ts +5 -0
- package/dist/classes/collection.js +189 -0
- package/dist/classes/config.d.ts +34 -0
- package/dist/classes/config.js +8 -0
- package/dist/classes/endpoints.d.ts +2 -0
- package/dist/classes/endpoints.js +120 -0
- package/dist/classes/index.d.ts +36 -0
- package/dist/classes/index.js +42 -0
- package/dist/classes/mcp.d.ts +6 -0
- package/dist/classes/mcp.js +161 -0
- package/dist/classes/shared.d.ts +131 -0
- package/dist/classes/shared.js +300 -0
- package/dist/classes/sheet.d.ts +34 -0
- package/dist/classes/sheet.js +126 -0
- package/dist/classes/usage.d.ts +57 -0
- package/dist/classes/usage.js +208 -0
- package/dist/comments/collection.d.ts +38 -0
- package/dist/comments/collection.js +226 -0
- package/dist/comments/config.d.ts +15 -0
- package/dist/comments/config.js +2 -0
- package/dist/comments/index.d.ts +20 -0
- package/dist/comments/index.js +22 -0
- package/dist/comments/shared.d.ts +54 -0
- package/dist/comments/shared.js +104 -0
- package/dist/core/bindings.d.ts +77 -32
- package/dist/core/bindings.js +319 -134
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +21 -8
- package/dist/core/blocks.js +37 -16
- package/dist/core/classes.d.ts +16 -8
- package/dist/core/classes.js +31 -27
- package/dist/core/components.d.ts +72 -0
- package/dist/core/components.js +294 -0
- package/dist/core/contentMode.d.ts +27 -0
- package/dist/core/contentMode.js +0 -0
- package/dist/core/dropTarget.d.ts +11 -0
- package/dist/core/dropTarget.js +24 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +5 -2
- package/dist/core/headings.js +14 -6
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +8 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +85 -24
- package/dist/core/payloadBlocks.js +5 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +20 -6
- package/dist/core/sectionOrigin.d.ts +6 -0
- package/dist/core/sectionOrigin.js +21 -0
- package/dist/core/sections.d.ts +72 -0
- package/dist/core/sections.js +331 -0
- package/dist/core/templateChoice.d.ts +24 -0
- package/dist/core/templateChoice.js +43 -0
- package/dist/core/tree.js +18 -6
- package/dist/core/types.d.ts +148 -18
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +28 -11
- package/dist/core/visibility.d.ts +63 -0
- package/dist/core/visibility.js +214 -0
- package/dist/core/whereValues.d.ts +22 -0
- package/dist/core/whereValues.js +43 -0
- package/dist/css/classes.d.ts +16 -0
- package/dist/css/classes.js +172 -0
- package/dist/css/index.d.ts +32 -1
- package/dist/css/index.js +64 -5
- package/dist/css/tokens.d.ts +10 -0
- package/dist/css/tokens.js +23 -10
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +5 -0
- package/dist/live/session.js +8 -0
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +10 -1
- package/dist/mcp/index.js +146 -54
- package/dist/mcp/shared.d.ts +93 -3
- package/dist/mcp/shared.js +211 -15
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +19 -8
- package/dist/plugin/index.js +89 -20
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +9 -7
- package/dist/plugin/listCollections.js +30 -21
- package/dist/plugin/sections.d.ts +14 -7
- package/dist/plugin/sections.js +69 -23
- package/dist/plugin/sectionsUsedIn.d.ts +6 -0
- package/dist/plugin/sectionsUsedIn.js +24 -0
- package/dist/plugin/templateEndpoint.d.ts +9 -0
- package/dist/plugin/templateEndpoint.js +49 -0
- package/dist/plugin/templates.js +23 -8
- package/dist/protocol/index.d.ts +16 -1
- package/dist/react/canvas/BuilderCanvas.js +144 -21
- package/dist/react/canvas/classes.d.ts +17 -0
- package/dist/react/canvas/classes.js +102 -0
- package/dist/react/canvas/controls.d.ts +31 -0
- package/dist/react/canvas/controls.js +75 -0
- package/dist/react/canvas/fetchDocs.d.ts +2 -2
- package/dist/react/canvas/fetchDocs.js +16 -8
- package/dist/react/canvas/measure.d.ts +9 -0
- package/dist/react/canvas/measure.js +106 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +4 -3
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +2 -11
- package/dist/react/components/Button.js +8 -43
- package/dist/react/components/CollectionList.d.ts +4 -1
- package/dist/react/components/CollectionList.js +10 -3
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +7 -4
- package/dist/react/components/Field.js +3 -14
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +1 -1
- package/dist/react/components/List.js +2 -2
- package/dist/react/components/Menu.d.ts +10 -1
- package/dist/react/components/Menu.js +39 -12
- package/dist/react/components/RichText.d.ts +3 -4
- package/dist/react/components/RichText.js +5 -5
- package/dist/react/components/builtins/Accordion.d.ts +4 -3
- package/dist/react/components/builtins/Accordion.js +6 -5
- package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
- package/dist/react/components/builtins/AdjacentLinks.js +20 -0
- package/dist/react/components/builtins/Carousel.d.ts +21 -10
- package/dist/react/components/builtins/Carousel.js +175 -100
- package/dist/react/components/builtins/Disclosure.d.ts +4 -3
- package/dist/react/components/builtins/Disclosure.js +6 -5
- package/dist/react/components/builtins/Embed.d.ts +11 -0
- package/dist/react/components/builtins/Embed.js +23 -0
- package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
- package/dist/react/components/builtins/EmbedHtml.js +51 -0
- package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
- package/dist/react/components/builtins/EmbedPreview.js +105 -0
- package/dist/react/components/builtins/FilterLink.d.ts +1 -1
- package/dist/react/components/builtins/FilterLink.js +4 -4
- package/dist/react/components/builtins/Marquee.d.ts +8 -0
- package/dist/react/components/builtins/Marquee.js +15 -0
- package/dist/react/components/builtins/Popup.d.ts +26 -0
- package/dist/react/components/builtins/Popup.js +146 -0
- package/dist/react/components/builtins/SectionRef.d.ts +4 -3
- package/dist/react/components/builtins/SectionRef.js +9 -5
- package/dist/react/components/builtins/Tab.d.ts +7 -0
- package/dist/react/components/builtins/Tab.js +21 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
- package/dist/react/components/builtins/TableOfContents.js +22 -7
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/index.d.ts +37 -20
- package/dist/react/components/builtins/index.js +54 -20
- package/dist/react/components/builtins/tabsContext.d.ts +12 -0
- package/dist/react/components/builtins/tabsContext.js +6 -0
- package/dist/react/components/index.js +11 -8
- package/dist/react/components/lazy.d.ts +32 -0
- package/dist/react/components/lazy.js +20 -0
- package/dist/react/components/lazyBlock.d.ts +17 -0
- package/dist/react/components/lazyBlock.js +23 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -2
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +96 -45
- package/dist/react/render/canvasMode.d.ts +13 -0
- package/dist/react/render/canvasMode.js +13 -0
- package/dist/react/render/canvasServer.js +4 -3
- package/dist/react/render/canvasServerTypes.d.ts +5 -0
- package/dist/react/render/lists.d.ts +36 -4
- package/dist/react/render/lists.js +132 -15
- package/dist/react/render/marks.d.ts +15 -0
- package/dist/react/render/marks.js +23 -0
- package/dist/react/render/payload.d.ts +8 -1
- package/dist/react/render/payload.js +12 -3
- package/dist/react/render/preview.d.ts +11 -0
- package/dist/react/render/preview.js +13 -0
- package/dist/react/render/relations.d.ts +10 -0
- package/dist/react/render/relations.js +39 -0
- package/dist/react/render/resolve.d.ts +8 -4
- package/dist/react/render/resolve.js +11 -5
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +11 -5
- package/dist/react/render/sections.js +52 -24
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +62 -5
- package/dist/react/server.d.ts +2 -37
- package/dist/react/server.js +8 -133
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +113 -0
- package/dist/theme/client.d.ts +1 -0
- package/dist/theme/client.js +2 -0
- package/dist/theme/css.d.ts +6 -1
- package/dist/theme/css.js +12 -4
- package/dist/theme/global.js +83 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/server.d.ts +15 -0
- package/dist/theme/server.js +43 -0
- package/dist/theme/usage.d.ts +23 -0
- package/dist/theme/usage.js +68 -0
- package/dist/theme/variables.d.ts +72 -0
- package/dist/theme/variables.js +231 -0
- package/package.json +4 -2
- package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
- package/dist/admin/editor/styles/SiteClasses.js +0 -31
- package/dist/blocks/builtins/headingId.d.ts +0 -15
- package/dist/blocks/builtins/headingId.js +0 -36
- package/dist/blocks/builtins/lightbox.d.ts +0 -43
- package/dist/blocks/builtins/lightbox.js +0 -93
- package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
- package/dist/blocks/builtins/mediaBackdrop.js +0 -79
- package/dist/react/components/Quote.d.ts +0 -3
- package/dist/react/components/Quote.js +0 -12
- package/dist/react/components/Spacer.d.ts +0 -3
- package/dist/react/components/Spacer.js +0 -6
- package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
- package/dist/react/components/builtins/BackdropVideo.js +0 -16
- package/dist/react/components/builtins/Lightbox.d.ts +0 -45
- package/dist/react/components/builtins/Lightbox.js +0 -252
- package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
- package/dist/react/components/builtins/MediaBackdrop.js +0 -61
|
@@ -1,134 +1,209 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import fadePlugin from 'embla-carousel-fade';
|
|
4
|
+
import useEmblaCarousel from 'embla-carousel-react';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
6
|
+
import { CAROUSEL_CLASS_MAP as C, CAROUSEL_LABELS } from '../../../blocks/client/carousel.js';
|
|
7
|
+
import { joinClasses, labelOf } from '../../../blocks/client/helpers.js';
|
|
8
|
+
import { COLLECTION_LIST_BLOCK, REPEAT_BLOCK } from '../../../core/blockNames.js';
|
|
9
|
+
import { useCanvasMode } from '../../render/canvasMode.js';
|
|
10
|
+
import { CANVAS_CONTROL_ATTRIBUTE, useCanvasReveal } from '../../render/reveal.js';
|
|
6
11
|
import { Chevron } from './glyphs.js';
|
|
7
|
-
/** The slides: the
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
12
|
+
/** The slides of an unwrapped list: the items inside the list's wrapper. */
|
|
13
|
+
const LIST_SLIDES = ':scope > * > *';
|
|
14
|
+
/** Marks a control: in the editor's canvas a click on it acts as on the site and selects nothing. */
|
|
15
|
+
const CONTROL = { [CANVAS_CONTROL_ATTRIBUTE]: '' };
|
|
16
|
+
/**
|
|
17
|
+
* True when the slides slot holds one collection list or repeat that renders a wrapper: the track
|
|
18
|
+
* unwraps it, so its items are the slides. A repeat with `as: 'none'` has no wrapper.
|
|
19
|
+
*/
|
|
20
|
+
export function unwrapsList(slides) {
|
|
21
|
+
const shown = slides.filter((block) => !block.hidden);
|
|
22
|
+
if (shown.length !== 1)
|
|
23
|
+
return false;
|
|
24
|
+
const only = shown[0];
|
|
25
|
+
return only.type === COLLECTION_LIST_BLOCK || (only.type === REPEAT_BLOCK && only.props?.as !== 'none');
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
|
|
28
|
+
const reducedMotion = () => window.matchMedia(REDUCED_MOTION).matches;
|
|
29
|
+
const subscribeReducedMotion = (onChange) => {
|
|
30
|
+
const query = window.matchMedia(REDUCED_MOTION);
|
|
31
|
+
query.addEventListener('change', onChange);
|
|
32
|
+
return () => query.removeEventListener('change', onChange);
|
|
33
|
+
};
|
|
34
|
+
const noReducedMotion = () => false;
|
|
35
|
+
/** The stop (Embla scroll snap) that shows slide `slide`: several slides can share one stop. */
|
|
36
|
+
export function stopOf(stops, slide) {
|
|
37
|
+
const stop = stops.findIndex((slides) => slides.includes(slide));
|
|
38
|
+
return stop >= 0 ? stop : slide;
|
|
30
39
|
}
|
|
40
|
+
const viewOf = (api) => ({
|
|
41
|
+
stops: api.scrollSnapList().length,
|
|
42
|
+
slides: api.slideNodes().length,
|
|
43
|
+
index: api.selectedScrollSnap(),
|
|
44
|
+
canPrevious: api.canScrollPrev(),
|
|
45
|
+
canNext: api.canScrollNext(),
|
|
46
|
+
});
|
|
31
47
|
/**
|
|
32
|
-
* Slides from the "slides" slot
|
|
33
|
-
* loop and autoplay. A region with `aria-roledescription="carousel"`; each
|
|
34
|
-
* labelled "i of n".
|
|
35
|
-
*
|
|
36
|
-
*
|
|
48
|
+
* Slides from the "slides" slot on Embla Carousel: they slide (swipe, drag, arrows, dots, arrow
|
|
49
|
+
* keys) or fade, with loop and autoplay. A region with `aria-roledescription="carousel"`; each
|
|
50
|
+
* slide is a group labelled "i of n". Autoplay shows a pause button, pauses on hover and focus,
|
|
51
|
+
* stops when the visitor swipes, and never runs with reduced motion.
|
|
52
|
+
*
|
|
53
|
+
* In the editor's canvas the arrows and dots work (they are canvas controls), slides do not drag
|
|
54
|
+
* (the editor drags blocks), fade shows as sliding so each slide can be selected, autoplay is
|
|
55
|
+
* off, and selecting a block in a slide brings that slide into view (`useCanvasReveal`).
|
|
37
56
|
*/
|
|
38
|
-
export function Carousel({ block, props, className, attributes,
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const [index, setIndex] = useState(0);
|
|
42
|
-
const [paused, setPaused] = useState(false);
|
|
43
|
-
const [stopped, setStopped] = useState(false);
|
|
44
|
-
const canvas = mode === 'canvas';
|
|
57
|
+
export function Carousel({ block, props, className, attributes, partAttributes, slots, mode, labels }) {
|
|
58
|
+
const canvasMode = useCanvasMode();
|
|
59
|
+
const canvas = mode === 'canvas' || canvasMode !== 'site';
|
|
45
60
|
const fade = props.mode === 'fade' && !canvas;
|
|
46
61
|
const loop = props.loop === true;
|
|
62
|
+
const align = props.align === 'center' ? 'center' : 'start';
|
|
47
63
|
const autoplay = typeof props.autoplay === 'number' && props.autoplay > 0 && !canvas ? props.autoplay : 0;
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
const blocks = block.slots?.slides ?? [];
|
|
65
|
+
const list = unwrapsList(blocks);
|
|
66
|
+
const options = useMemo(() => ({ loop, align, watchDrag: !canvas, duration: 28, ...(list ? { slides: LIST_SLIDES } : {}) }), [loop, align, canvas, list]);
|
|
67
|
+
const plugins = useMemo(() => (fade ? [fadePlugin()] : []), [fade]);
|
|
68
|
+
const [viewportRef, api] = useEmblaCarousel(options, plugins);
|
|
69
|
+
const root = useRef(null);
|
|
70
|
+
// Before the script runs (server HTML), count the slides from the data, so the controls render
|
|
71
|
+
// at once. A list's items are known only in the browser.
|
|
72
|
+
const initial = list ? 0 : canvas ? blocks.length : blocks.filter((child) => !child.hidden).length;
|
|
73
|
+
const [view, setView] = useState({ stops: initial, slides: initial, index: 0, canPrevious: loop, canNext: initial > 1 });
|
|
74
|
+
// The visitor's choice with the pause button (or a swipe, which stops). Without one, autoplay runs
|
|
75
|
+
// unless the visitor asks for less motion. `paused`: hover or focus.
|
|
76
|
+
const [choice, setChoice] = useState(null);
|
|
77
|
+
const [paused, setPaused] = useState(false);
|
|
78
|
+
const reduced = useSyncExternalStore(subscribeReducedMotion, reducedMotion, noReducedMotion);
|
|
79
|
+
const L = labels ? { ...CAROUSEL_LABELS, ...labels } : CAROUSEL_LABELS;
|
|
60
80
|
const label = (name, values) => labelOf(props, L, name, values);
|
|
61
81
|
const slideRole = label('slideRole');
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
// The template, filled in per slide below.
|
|
83
|
+
const slideLabel = label('slideLabel');
|
|
84
|
+
// The controls follow the carousel.
|
|
64
85
|
useEffect(() => {
|
|
65
|
-
|
|
66
|
-
if (!el || canvas)
|
|
86
|
+
if (!api)
|
|
67
87
|
return;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
}, [canvas, count, fade, index, slideLabel, slideRole]);
|
|
78
|
-
// Scroll mode: the current slide follows the scroll position.
|
|
88
|
+
const sync = () => setView(viewOf(api));
|
|
89
|
+
sync();
|
|
90
|
+
api.on('select', sync).on('reInit', sync);
|
|
91
|
+
return () => {
|
|
92
|
+
api.off('select', sync).off('reInit', sync);
|
|
93
|
+
};
|
|
94
|
+
}, [api]);
|
|
95
|
+
// Each slide is a group labelled "i of n".
|
|
79
96
|
useEffect(() => {
|
|
80
|
-
|
|
81
|
-
if (!el || fade)
|
|
97
|
+
if (!api)
|
|
82
98
|
return;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
const labelSlides = () => {
|
|
100
|
+
const slides = api.slideNodes();
|
|
101
|
+
slides.forEach((slide, i) => {
|
|
102
|
+
slide.setAttribute('role', 'group');
|
|
103
|
+
slide.setAttribute('aria-roledescription', slideRole);
|
|
104
|
+
slide.setAttribute('aria-label', labelOf({}, { slideLabel }, 'slideLabel', { n: i + 1, count: slides.length }));
|
|
89
105
|
});
|
|
90
106
|
};
|
|
91
|
-
|
|
107
|
+
labelSlides();
|
|
108
|
+
api.on('reInit', labelSlides);
|
|
92
109
|
return () => {
|
|
93
|
-
|
|
94
|
-
el.removeEventListener('scroll', onScroll);
|
|
110
|
+
api.off('reInit', labelSlides);
|
|
95
111
|
};
|
|
96
|
-
}, [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!
|
|
112
|
+
}, [api, slideLabel, slideRole]);
|
|
113
|
+
// A list's items can change inside its wrapper, where Embla does not look.
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!api || !list)
|
|
100
116
|
return;
|
|
101
|
-
const
|
|
102
|
-
|
|
117
|
+
const container = api.containerNode();
|
|
118
|
+
const observer = new MutationObserver(() => {
|
|
119
|
+
const now = container.querySelectorAll(LIST_SLIDES);
|
|
120
|
+
const before = api.slideNodes();
|
|
121
|
+
if (now.length !== before.length || Array.from(now).some((slide, i) => slide !== before[i]))
|
|
122
|
+
api.reInit();
|
|
123
|
+
});
|
|
124
|
+
observer.observe(container, { childList: true, subtree: true });
|
|
125
|
+
return () => observer.disconnect();
|
|
126
|
+
}, [api, list]);
|
|
127
|
+
// Canvas: the slides move by transform, which the editor does not see. A `scroll` event from
|
|
128
|
+
// the viewport tells it to measure the blocks again.
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!api || !canvas)
|
|
131
|
+
return;
|
|
132
|
+
const moved = () => api.rootNode().dispatchEvent(new Event('scroll'));
|
|
133
|
+
api.on('scroll', moved).on('settle', moved);
|
|
134
|
+
return () => {
|
|
135
|
+
api.off('scroll', moved).off('settle', moved);
|
|
136
|
+
};
|
|
137
|
+
}, [api, canvas]);
|
|
138
|
+
// Canvas: selecting a block in a slide (or the slide) brings the slide into view at once.
|
|
139
|
+
useCanvasReveal(root, (target) => {
|
|
140
|
+
if (!api)
|
|
103
141
|
return;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
142
|
+
const slide = api.slideNodes().findIndex((node) => node.contains(target));
|
|
143
|
+
if (slide < 0)
|
|
144
|
+
return;
|
|
145
|
+
api.scrollTo(stopOf(api.internalEngine().slideRegistry, slide), true);
|
|
146
|
+
});
|
|
147
|
+
// Autoplay: a swipe stops it.
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (!api || !autoplay)
|
|
107
150
|
return;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
151
|
+
const stop = () => setChoice('stop');
|
|
152
|
+
api.on('pointerDown', stop);
|
|
153
|
+
return () => {
|
|
154
|
+
api.off('pointerDown', stop);
|
|
155
|
+
};
|
|
156
|
+
}, [api, autoplay]);
|
|
157
|
+
const playing = autoplay > 0 && view.stops > 1 && (choice === 'play' || (choice === null && !reduced));
|
|
111
158
|
useEffect(() => {
|
|
112
|
-
if (!playing ||
|
|
159
|
+
if (!api || !playing || paused)
|
|
113
160
|
return;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
161
|
+
// The next slide after `autoplay` ms, counted again after every move. It wraps to the first.
|
|
162
|
+
let timer = 0;
|
|
163
|
+
const schedule = () => {
|
|
164
|
+
window.clearTimeout(timer);
|
|
165
|
+
timer = window.setTimeout(() => (api.canScrollNext() ? api.scrollNext() : api.scrollTo(0)), autoplay);
|
|
166
|
+
};
|
|
167
|
+
schedule();
|
|
168
|
+
api.on('select', schedule);
|
|
169
|
+
return () => {
|
|
170
|
+
window.clearTimeout(timer);
|
|
171
|
+
api.off('select', schedule);
|
|
172
|
+
};
|
|
173
|
+
}, [api, autoplay, paused, playing]);
|
|
174
|
+
const go = useCallback((to) => {
|
|
175
|
+
if (!api)
|
|
119
176
|
return;
|
|
177
|
+
const jump = reducedMotion();
|
|
178
|
+
if (to === 'previous')
|
|
179
|
+
api.scrollPrev(jump);
|
|
180
|
+
else if (to === 'next')
|
|
181
|
+
api.scrollNext(jump);
|
|
182
|
+
else
|
|
183
|
+
api.scrollTo(to, jump);
|
|
184
|
+
}, [api]);
|
|
185
|
+
// Arrow keys on the focused viewport or on a control move one stop.
|
|
186
|
+
const onKeyDown = (event) => {
|
|
120
187
|
if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft')
|
|
121
188
|
return;
|
|
189
|
+
if (!(event.target instanceof Element) || !event.target.closest('[data-carousel-viewport], [data-carousel-control]'))
|
|
190
|
+
return;
|
|
191
|
+
if (event.target.closest('[data-carousel-track]'))
|
|
192
|
+
return;
|
|
122
193
|
event.preventDefault();
|
|
123
|
-
|
|
194
|
+
go(event.key === 'ArrowRight' ? 'next' : 'previous');
|
|
124
195
|
};
|
|
125
|
-
const showArrows = props.arrows !== false &&
|
|
126
|
-
const showDots = props.dots === true &&
|
|
127
|
-
const
|
|
128
|
-
|
|
196
|
+
const showArrows = props.arrows !== false && view.stops > 1;
|
|
197
|
+
const showDots = props.dots === true && view.stops > 1;
|
|
198
|
+
const trackId = `carousel-${block.id}`;
|
|
199
|
+
const trackClass = joinClasses(C.track, list ? C.trackList : undefined, fade ? (list ? C.fadeList : C.fade) : undefined, partAttributes.slides?.className);
|
|
200
|
+
// The parts' own classes (`block.partClassName`) join the component's classes.
|
|
201
|
+
const arrowClass = joinClasses(C.button, partAttributes.arrow?.className);
|
|
202
|
+
const dotClass = joinClasses(C.button, C.dot, partAttributes.dot?.className);
|
|
203
|
+
// An empty arrow slot shows a chevron; a filled one shows its blocks.
|
|
129
204
|
const arrowContent = (slot) => (block.slots?.[slot]?.length ?? 0) > 0 ? slots[slot] : _jsx(Chevron, { className: C.icon, direction: slot === 'previous' ? 'left' : 'right' });
|
|
130
|
-
return (_jsxs("section", { ...attributes, "aria-roledescription": label('carouselRole'), "aria-label":
|
|
205
|
+
return (_jsxs("section", { ...attributes, ref: root, "aria-roledescription": label('carouselRole'), "aria-label": label('label'), className: className, onFocus: () => setPaused(true), onBlur: (event) => {
|
|
131
206
|
if (!event.currentTarget.contains(event.relatedTarget))
|
|
132
207
|
setPaused(false);
|
|
133
|
-
}, onPointerEnter: () => setPaused(true), onPointerLeave: () => setPaused(false), children: [_jsx("div", { ...
|
|
208
|
+
}, onPointerEnter: () => setPaused(true), onPointerLeave: () => setPaused(false), onKeyDown: onKeyDown, children: [_jsx("div", { ref: viewportRef, "data-carousel-viewport": "", className: C.viewport, tabIndex: canvas ? undefined : 0, children: _jsx("div", { ...partAttributes.slides, id: trackId, "data-carousel-track": "", className: trackClass, "aria-live": playing && !paused ? 'off' : 'polite', children: slots.slides }) }), showArrows || showDots || autoplay > 0 ? (_jsxs("div", { "data-carousel-controls": "", className: joinClasses(C.controls, partAttributes.controls?.className), children: [showDots ? (_jsx("div", { "data-carousel-dots": "", className: C.dots, children: Array.from({ length: view.stops }, (_, i) => (_jsx("button", { ...CONTROL, type: "button", "data-carousel-control": "", "data-carousel-dot": "", className: dotClass, "aria-controls": trackId, "aria-label": label('dotLabel', { n: i + 1, count: view.stops }), "aria-current": i === view.index ? 'true' : undefined, onClick: () => go(i) }, i))) })) : null, _jsxs("div", { "data-carousel-arrows": "", className: C.arrows, children: [autoplay > 0 ? (_jsx("button", { ...CONTROL, type: "button", "data-carousel-control": "", "data-carousel-pause": "", className: joinClasses(C.button, partAttributes.pause?.className), onClick: () => setChoice(playing ? 'stop' : 'play'), children: playing ? label('pauseLabel') : label('playLabel') })) : null, showArrows ? (_jsxs(_Fragment, { children: [_jsx("button", { ...partAttributes.previous, ...CONTROL, type: "button", "data-carousel-control": "", "data-carousel-arrow": "previous", className: arrowClass, "aria-controls": trackId, "aria-label": label('previousLabel'), disabled: !view.canPrevious, onClick: () => go('previous'), children: arrowContent('previous') }), _jsx("button", { ...partAttributes.next, ...CONTROL, type: "button", "data-carousel-control": "", "data-carousel-arrow": "next", className: arrowClass, "aria-controls": trackId, "aria-label": label('nextLabel'), disabled: !view.canNext, onClick: () => go('next'), children: arrowContent('next') })] })) : null] })] })) : null] }));
|
|
134
209
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
2
|
/**
|
|
3
3
|
* A native <details>: it opens with the mouse and the keyboard without script, and the closed
|
|
4
|
-
* content stays in the HTML. The height animation is CSS only.
|
|
5
|
-
*
|
|
4
|
+
* content stays in the HTML. The height animation is CSS only. The editor's canvas shows it as the
|
|
5
|
+
* site does: a click on the summary opens and closes it, and selecting a block inside it (or the
|
|
6
|
+
* disclosure itself) opens it.
|
|
6
7
|
*/
|
|
7
|
-
export declare function Disclosure({ props, className, attributes,
|
|
8
|
+
export declare function Disclosure({ props, className, attributes, partAttributes, slots }: BlockComponentProps): import("react").JSX.Element;
|
|
@@ -3,11 +3,12 @@ import { DISCLOSURE_CLASS_MAP as C } from '../../../blocks/builtins/disclosure.j
|
|
|
3
3
|
import { joinClasses } from '../../../blocks/builtins/shared.js';
|
|
4
4
|
/**
|
|
5
5
|
* A native <details>: it opens with the mouse and the keyboard without script, and the closed
|
|
6
|
-
* content stays in the HTML. The height animation is CSS only.
|
|
7
|
-
*
|
|
6
|
+
* content stays in the HTML. The height animation is CSS only. The editor's canvas shows it as the
|
|
7
|
+
* site does: a click on the summary opens and closes it, and selecting a block inside it (or the
|
|
8
|
+
* disclosure itself) opens it.
|
|
8
9
|
*/
|
|
9
|
-
export function Disclosure({ props, className, attributes,
|
|
10
|
-
const open =
|
|
10
|
+
export function Disclosure({ props, className, attributes, partAttributes, slots }) {
|
|
11
|
+
const open = props.open === true;
|
|
11
12
|
const classes = props.animate === false ? className : className ? `${className} ${C.animate}` : C.animate;
|
|
12
|
-
return (_jsxs("details", { ...attributes, className: classes, open: open || undefined, children: [_jsx("summary", { ...
|
|
13
|
+
return (_jsxs("details", { ...attributes, className: classes, open: open || undefined, children: [_jsx("summary", { ...partAttributes.summary, className: joinClasses(C.summary, partAttributes.summary?.className), children: slots.summary }), _jsx("div", { ...partAttributes.content, children: slots.content })] }));
|
|
13
14
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EMBED_LABELS } from '../../../blocks/client/embed.js';
|
|
2
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
3
|
+
export type EmbedLabels = Partial<typeof EMBED_LABELS>;
|
|
4
|
+
/**
|
|
5
|
+
* Custom HTML. `inline`: the HTML is in the page, and its scripts run (`EmbedHtml`). `isolated`:
|
|
6
|
+
* a sandboxed frame shows it, with no JavaScript of ours. Empty code renders nothing on the site.
|
|
7
|
+
* The canvas never runs the code (`EmbedPreview`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function Embed({ props, className, attributes, mode, labels }: BlockComponentProps & {
|
|
10
|
+
labels?: EmbedLabels;
|
|
11
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EMBED_CLASS_MAP as C, EMBED_LABELS, EMBED_SANDBOX, embedMode } from '../../../blocks/client/embed.js';
|
|
3
|
+
import { joinClasses, labelOf } from '../../../blocks/client/helpers.js';
|
|
4
|
+
// The inline HTML and the canvas preview load their JavaScript only on pages that render them.
|
|
5
|
+
import { EmbedHtml, EmbedPreview } from '../lazy.js';
|
|
6
|
+
import { asText } from '../placeholder.js';
|
|
7
|
+
/**
|
|
8
|
+
* Custom HTML. `inline`: the HTML is in the page, and its scripts run (`EmbedHtml`). `isolated`:
|
|
9
|
+
* a sandboxed frame shows it, with no JavaScript of ours. Empty code renders nothing on the site.
|
|
10
|
+
* The canvas never runs the code (`EmbedPreview`).
|
|
11
|
+
*/
|
|
12
|
+
export function Embed({ props, className, attributes, mode, labels }) {
|
|
13
|
+
const code = asText(props.code);
|
|
14
|
+
const kind = embedMode(props.mode);
|
|
15
|
+
const title = labelOf(props, labels ? { ...EMBED_LABELS, ...labels } : EMBED_LABELS, 'title');
|
|
16
|
+
if (mode === 'canvas')
|
|
17
|
+
return _jsx(EmbedPreview, { code: code, mode: kind, title: title, className: className, attributes: attributes });
|
|
18
|
+
if (!code.trim())
|
|
19
|
+
return null;
|
|
20
|
+
if (kind === 'inline')
|
|
21
|
+
return _jsx(EmbedHtml, { html: code, className: className, attributes: attributes });
|
|
22
|
+
return _jsx("iframe", { ...attributes, className: joinClasses(C.frame, className), title: title, srcDoc: code, sandbox: EMBED_SANDBOX, loading: "lazy" });
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `<script>` tags under `root` that have not run yet. Scripts that arrive through
|
|
3
|
+
* `innerHTML` never run, so each one is replaced by a new script element with the same attributes
|
|
4
|
+
* and text. External scripts keep their order (`async = false`) unless they have `async`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runScripts(root: Element): void;
|
|
7
|
+
/**
|
|
8
|
+
* Inline custom HTML on the site. The browser runs the scripts of the server's HTML itself. After
|
|
9
|
+
* a client render (a page change in the app), React sets `innerHTML`, so the scripts run here.
|
|
10
|
+
*/
|
|
11
|
+
export declare function EmbedHtml({ html, className, attributes }: {
|
|
12
|
+
html: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
attributes: Record<string, string>;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
4
|
+
/** Scripts that already ran: those the browser ran from the server's HTML, and our copies. */
|
|
5
|
+
const ran = new WeakSet();
|
|
6
|
+
const subscribe = () => () => { };
|
|
7
|
+
/**
|
|
8
|
+
* Runs the `<script>` tags under `root` that have not run yet. Scripts that arrive through
|
|
9
|
+
* `innerHTML` never run, so each one is replaced by a new script element with the same attributes
|
|
10
|
+
* and text. External scripts keep their order (`async = false`) unless they have `async`.
|
|
11
|
+
*/
|
|
12
|
+
export function runScripts(root) {
|
|
13
|
+
for (const old of root.querySelectorAll('script')) {
|
|
14
|
+
if (ran.has(old))
|
|
15
|
+
continue;
|
|
16
|
+
const script = old.ownerDocument.createElement('script');
|
|
17
|
+
for (const { name, value } of Array.from(old.attributes))
|
|
18
|
+
script.setAttribute(name, value);
|
|
19
|
+
if (!old.hasAttribute('async'))
|
|
20
|
+
script.async = false;
|
|
21
|
+
script.text = old.text;
|
|
22
|
+
ran.add(script);
|
|
23
|
+
old.replaceWith(script);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Inline custom HTML on the site. The browser runs the scripts of the server's HTML itself. After
|
|
28
|
+
* a client render (a page change in the app), React sets `innerHTML`, so the scripts run here.
|
|
29
|
+
*/
|
|
30
|
+
export function EmbedHtml({ html, className, attributes }) {
|
|
31
|
+
const ref = useRef(null);
|
|
32
|
+
// False while React hydrates the server's HTML: its scripts ran when the page loaded.
|
|
33
|
+
const client = useSyncExternalStore(subscribe, () => true, () => false);
|
|
34
|
+
const fromServer = useRef(!client);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const root = ref.current;
|
|
37
|
+
if (!root)
|
|
38
|
+
return;
|
|
39
|
+
if (fromServer.current) {
|
|
40
|
+
fromServer.current = false;
|
|
41
|
+
for (const script of root.querySelectorAll('script'))
|
|
42
|
+
ran.add(script);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
runScripts(root);
|
|
46
|
+
// `html`: React set new HTML, so its scripts must run.
|
|
47
|
+
// oxlint-disable-next-line react/exhaustive-effect-dependencies
|
|
48
|
+
}, [html]);
|
|
49
|
+
// The scripts may change their HTML before React hydrates it: that is expected, not a mismatch.
|
|
50
|
+
return _jsx("div", { ...attributes, ref: ref, className: className, dangerouslySetInnerHTML: { __html: html }, suppressHydrationWarning: true });
|
|
51
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type EmbedMode } from '../../../blocks/client/embed.js';
|
|
2
|
+
/**
|
|
3
|
+
* The canvas frame: no `allow-scripts`, so no code runs (scripts, `onerror` handlers, forms).
|
|
4
|
+
* `allow-same-origin` only lets the canvas read the content's height.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PREVIEW_SANDBOX = "allow-same-origin";
|
|
7
|
+
/**
|
|
8
|
+
* The document of an inline preview: the code with the page's stylesheets and the classes of
|
|
9
|
+
* `<html>` and `<body>` (theme, fonts), so it looks as it does in the page.
|
|
10
|
+
*/
|
|
11
|
+
export declare function previewDocument(code: string, page: PageLook): string;
|
|
12
|
+
/**
|
|
13
|
+
* The height of what the body shows: from its top to the lowest bottom edge (with margin) of its
|
|
14
|
+
* children that have a box. Scripts and styles have none, so code with only scripts measures 0.
|
|
15
|
+
*/
|
|
16
|
+
export declare function contentHeight(body: HTMLElement): number;
|
|
17
|
+
type PageLook = {
|
|
18
|
+
styles: string;
|
|
19
|
+
htmlClass: string;
|
|
20
|
+
bodyClass: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Custom code on the canvas, never run: a sandboxed frame without scripts. Inline code grows to
|
|
24
|
+
* its content's height. Empty code, or code with nothing to see (only scripts), shows a
|
|
25
|
+
* "Custom code" box, so the block can still be selected.
|
|
26
|
+
*/
|
|
27
|
+
export declare function EmbedPreview({ code, mode, title, className, attributes, }: {
|
|
28
|
+
code: string;
|
|
29
|
+
mode: EmbedMode;
|
|
30
|
+
title: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
attributes: Record<string, string>;
|
|
33
|
+
}): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { EMBED_CLASS_MAP as C } from '../../../blocks/client/embed.js';
|
|
5
|
+
import { joinClasses } from '../../../blocks/client/helpers.js';
|
|
6
|
+
import { PlaceholderBox } from '../placeholder.js';
|
|
7
|
+
/**
|
|
8
|
+
* The canvas frame: no `allow-scripts`, so no code runs (scripts, `onerror` handlers, forms).
|
|
9
|
+
* `allow-same-origin` only lets the canvas read the content's height.
|
|
10
|
+
*/
|
|
11
|
+
export const PREVIEW_SANDBOX = 'allow-same-origin';
|
|
12
|
+
const LABEL = 'Custom code';
|
|
13
|
+
/** Clicks go to the canvas, so the block selects as any other. */
|
|
14
|
+
const NO_POINTER = { pointerEvents: 'none' };
|
|
15
|
+
/** Below this height (code with only scripts) the canvas shows the placeholder instead. */
|
|
16
|
+
const MIN_HEIGHT = 4;
|
|
17
|
+
const escapeAttribute = (value) => value.replace(/&/g, '&').replace(/"/g, '"');
|
|
18
|
+
/**
|
|
19
|
+
* The document of an inline preview: the code with the page's stylesheets and the classes of
|
|
20
|
+
* `<html>` and `<body>` (theme, fonts), so it looks as it does in the page.
|
|
21
|
+
*/
|
|
22
|
+
export function previewDocument(code, page) {
|
|
23
|
+
return (`<!doctype html><html class="${escapeAttribute(page.htmlClass)}"><head>${page.styles}</head>` +
|
|
24
|
+
`<body class="${escapeAttribute(page.bodyClass)}" style="margin:0;display:flow-root;background:transparent">${code}</body></html>`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The height of what the body shows: from its top to the lowest bottom edge (with margin) of its
|
|
28
|
+
* children that have a box. Scripts and styles have none, so code with only scripts measures 0.
|
|
29
|
+
*/
|
|
30
|
+
export function contentHeight(body) {
|
|
31
|
+
const top = body.getBoundingClientRect().top;
|
|
32
|
+
let bottom = top;
|
|
33
|
+
for (const child of Array.from(body.children)) {
|
|
34
|
+
const rect = child.getBoundingClientRect();
|
|
35
|
+
if (rect.width === 0 && rect.height === 0)
|
|
36
|
+
continue;
|
|
37
|
+
bottom = Math.max(bottom, rect.bottom + (Number.parseFloat(getComputedStyle(child).marginBottom) || 0));
|
|
38
|
+
}
|
|
39
|
+
return Math.ceil(bottom - top);
|
|
40
|
+
}
|
|
41
|
+
function pageLook() {
|
|
42
|
+
const styles = Array.from(document.querySelectorAll('link[rel="stylesheet"], style'), (el) => el.outerHTML).join('');
|
|
43
|
+
return { styles, htmlClass: document.documentElement.className, bodyClass: document.body.className };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Custom code on the canvas, never run: a sandboxed frame without scripts. Inline code grows to
|
|
47
|
+
* its content's height. Empty code, or code with nothing to see (only scripts), shows a
|
|
48
|
+
* "Custom code" box, so the block can still be selected.
|
|
49
|
+
*/
|
|
50
|
+
export function EmbedPreview({ code, mode, title, className, attributes, }) {
|
|
51
|
+
const frame = useRef(null);
|
|
52
|
+
const [height, setHeight] = useState(0);
|
|
53
|
+
// The page's stylesheets and classes, read once: they exist only in the browser.
|
|
54
|
+
const [look, setLook] = useState(null);
|
|
55
|
+
const empty = !code.trim();
|
|
56
|
+
const inline = mode === 'inline';
|
|
57
|
+
// Isolated code shows as it is; inline code with the page's look (empty until it is read).
|
|
58
|
+
const srcDoc = inline ? (look ? previewDocument(code, look) : null) : code;
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
// oxlint-disable-next-line react/set-state-in-effect
|
|
61
|
+
setLook(pageLook());
|
|
62
|
+
}, []);
|
|
63
|
+
// Inline: the frame grows with its content (images that load, fonts). The frame's `load` waits
|
|
64
|
+
// for every image and stylesheet, and the old document stays a moment after a change, so for
|
|
65
|
+
// about two seconds each frame checks for a new body to watch.
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const el = frame.current;
|
|
68
|
+
if (!el || !inline || srcDoc === null)
|
|
69
|
+
return;
|
|
70
|
+
let observer = null;
|
|
71
|
+
let watched = null;
|
|
72
|
+
let tries = 0;
|
|
73
|
+
let poll = 0;
|
|
74
|
+
const watch = () => {
|
|
75
|
+
const body = el.contentDocument?.body;
|
|
76
|
+
if (!body || body === watched)
|
|
77
|
+
return;
|
|
78
|
+
watched = body;
|
|
79
|
+
observer?.disconnect();
|
|
80
|
+
const update = () => setHeight(contentHeight(body));
|
|
81
|
+
update();
|
|
82
|
+
observer = new ResizeObserver(update);
|
|
83
|
+
observer.observe(body);
|
|
84
|
+
};
|
|
85
|
+
const check = () => {
|
|
86
|
+
watch();
|
|
87
|
+
if (++tries < 120)
|
|
88
|
+
poll = requestAnimationFrame(check);
|
|
89
|
+
};
|
|
90
|
+
el.addEventListener('load', watch);
|
|
91
|
+
check();
|
|
92
|
+
return () => {
|
|
93
|
+
cancelAnimationFrame(poll);
|
|
94
|
+
el.removeEventListener('load', watch);
|
|
95
|
+
observer?.disconnect();
|
|
96
|
+
};
|
|
97
|
+
}, [inline, srcDoc]);
|
|
98
|
+
if (empty)
|
|
99
|
+
return _jsx(PlaceholderBox, { attributes: attributes, className: className, label: LABEL });
|
|
100
|
+
if (!inline) {
|
|
101
|
+
return (_jsx("iframe", { ...attributes, className: joinClasses(C.frame, className), title: title, srcDoc: srcDoc ?? '', sandbox: PREVIEW_SANDBOX, style: NO_POINTER }));
|
|
102
|
+
}
|
|
103
|
+
const blank = height < MIN_HEIGHT;
|
|
104
|
+
return (_jsxs("div", { ...attributes, className: className, children: [_jsx("iframe", { ref: frame, className: C.frame, title: title, srcDoc: srcDoc ?? '', sandbox: PREVIEW_SANDBOX, style: { ...NO_POINTER, height } }), blank ? _jsx(PlaceholderBox, { attributes: {}, label: LABEL, style: { minHeight: 48 } }) : null] }));
|
|
105
|
+
}
|
|
@@ -5,4 +5,4 @@ import type { BlockComponentProps } from '../../render/types.js';
|
|
|
5
5
|
* After hydration it keeps the page's other query values and marks the current filter with
|
|
6
6
|
* `aria-current="true"`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function FilterLink({ props, className, attributes,
|
|
8
|
+
export declare function FilterLink({ props, className, attributes, partAttributes, slots }: BlockComponentProps): import("react").JSX.Element;
|