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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextFieldClientComponent } from 'payload';
|
|
2
|
+
import './fields.scss';
|
|
3
|
+
/** A variable's value (or dark value): a color picker, a size input or a Google Font, from the row's type. */
|
|
4
|
+
export declare const ThemeVariableValueField: TextFieldClientComponent;
|
|
5
|
+
/** The row label: preview, name, type and value. */
|
|
6
|
+
export declare function ThemeVariableRowLabel(): import("react").JSX.Element;
|
|
7
|
+
/**
|
|
8
|
+
* Under the list: for each saved variable in use that this form renames, retypes or removes, what
|
|
9
|
+
* breaks, with links to the pages. Nothing while no change touches a used variable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ThemeVariablesWarning(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The theme's Variables list in Payload's admin: the value field that follows the row's type, the
|
|
4
|
+
// row label with a preview, and the warning while a rename or a removal would break blocks or
|
|
5
|
+
// classes that use a variable (as Webflow warns).
|
|
6
|
+
import { FieldError, TextInput, useConfig, useDocumentInfo, useField, useFormFields, useRowLabel } from '@payloadcms/ui';
|
|
7
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { builderViewPath } from '../../plugin/links.js';
|
|
9
|
+
import { VARIABLE_TYPES } from '../variables.js';
|
|
10
|
+
import { ThemeColorField } from './ColorField.js';
|
|
11
|
+
import { FieldShell } from './FieldShell.js';
|
|
12
|
+
import { ThemeFontField } from './FontField.js';
|
|
13
|
+
import './fields.scss';
|
|
14
|
+
/** `variables.2.value` → `variables.2`. */
|
|
15
|
+
const rowPath = (path) => path.slice(0, path.lastIndexOf('.'));
|
|
16
|
+
const asType = (value) => (value === 'size' || value === 'font' ? value : 'color');
|
|
17
|
+
/** A variable's value (or dark value): a color picker, a size input or a Google Font, from the row's type. */
|
|
18
|
+
export const ThemeVariableValueField = function ThemeVariableValueField(props) {
|
|
19
|
+
const type = useFormFields(([fields]) => asType(fields[`${rowPath(props.path)}.type`]?.value));
|
|
20
|
+
if (type === 'color')
|
|
21
|
+
return _jsx(ThemeColorField, { ...props });
|
|
22
|
+
if (type === 'font')
|
|
23
|
+
return _jsx(ThemeFontField, { ...props });
|
|
24
|
+
return _jsx(SizeField, { ...props });
|
|
25
|
+
};
|
|
26
|
+
function SizeField({ path, field, readOnly }) {
|
|
27
|
+
const { value, setValue, disabled, showError } = useField({ path });
|
|
28
|
+
return (_jsxs(FieldShell, { field: { ...field, label: false }, path: path, className: "theme-variable-size", children: [_jsx(TextInput, { path: path, label: field.label, value: value ?? '', placeholder: "24px or 1.5rem", readOnly: Boolean(readOnly || disabled), showError: showError, Error: _jsx(FieldError, { path: path, showError: showError }), onChange: (e) => setValue(e.target.value) }), value ? _jsx("span", { className: "theme-variable-size__bar", style: { width: `min(100%, ${value})` }, "aria-hidden": "true" }) : null] }));
|
|
29
|
+
}
|
|
30
|
+
/** The row's preview: a swatch, the size as a bar, or "Ag" in the font. */
|
|
31
|
+
function Preview({ type, value }) {
|
|
32
|
+
if (!value)
|
|
33
|
+
return _jsx("span", { className: "theme-variable-label__preview", "data-empty": "", "aria-hidden": "true" });
|
|
34
|
+
if (type === 'color')
|
|
35
|
+
return _jsx("span", { className: "theme-variable-label__preview", style: { background: value }, "aria-hidden": "true" });
|
|
36
|
+
if (type === 'font') {
|
|
37
|
+
return (_jsx("span", { className: "theme-variable-label__preview theme-variable-label__preview--font", style: { fontFamily: `"${value}", sans-serif` }, "aria-hidden": "true", children: "Ag" }));
|
|
38
|
+
}
|
|
39
|
+
return (_jsx("span", { className: "theme-variable-label__preview theme-variable-label__preview--size", "aria-hidden": "true", children: _jsx("span", { style: { width: `min(100%, ${value})` } }) }));
|
|
40
|
+
}
|
|
41
|
+
/** The row label: preview, name, type and value. */
|
|
42
|
+
export function ThemeVariableRowLabel() {
|
|
43
|
+
const { data, rowNumber } = useRowLabel();
|
|
44
|
+
const type = asType(data?.type);
|
|
45
|
+
const name = data?.name?.trim();
|
|
46
|
+
const value = data?.value?.trim() ?? '';
|
|
47
|
+
return (_jsxs("span", { className: "theme-variable-label", children: [_jsx(Preview, { type: type, value: value }), _jsx("span", { className: "theme-variable-label__name", children: name || `Variable ${(rowNumber ?? 0) + 1}` }), _jsxs("span", { className: "theme-variable-label__meta", children: [VARIABLE_TYPES.find((t) => t.value === type)?.label, value ? ` · ${value}` : ''] })] }));
|
|
48
|
+
}
|
|
49
|
+
const plural = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
50
|
+
/** Where it is used, as a phrase: "3 blocks on 2 pages and 1 class". */
|
|
51
|
+
function usedText(usage) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
if (usage.blocks > 0)
|
|
54
|
+
parts.push(`${plural(usage.blocks, 'block')} on ${plural(usage.documents.length, 'page')}`);
|
|
55
|
+
if (usage.classes.length > 0)
|
|
56
|
+
parts.push(plural(usage.classes.length, 'class', 'classes'));
|
|
57
|
+
return parts.join(' and ');
|
|
58
|
+
}
|
|
59
|
+
const rowsOf = (list) => Array.isArray(list)
|
|
60
|
+
? list.flatMap((v) => (v?.id && typeof v.name === 'string' ? [{ id: v.id, name: v.name.trim(), type: asType(v.type) }] : []))
|
|
61
|
+
: [];
|
|
62
|
+
/**
|
|
63
|
+
* Under the list: for each saved variable in use that this form renames, retypes or removes, what
|
|
64
|
+
* breaks, with links to the pages. Nothing while no change touches a used variable.
|
|
65
|
+
*/
|
|
66
|
+
export function ThemeVariablesWarning() {
|
|
67
|
+
const { config: { routes: { admin, api }, }, } = useConfig();
|
|
68
|
+
const { savedDocumentData } = useDocumentInfo();
|
|
69
|
+
const saved = useMemo(() => rowsOf(savedDocumentData?.variables), [savedDocumentData]);
|
|
70
|
+
// The current rows as text, so the form's other edits do not render this again.
|
|
71
|
+
const currentKey = useFormFields(([fields]) => {
|
|
72
|
+
const count = Number(fields.variables?.value ?? 0);
|
|
73
|
+
const rows = [];
|
|
74
|
+
for (let i = 0; i < count; i++)
|
|
75
|
+
rows.push([fields[`variables.${i}.id`]?.value, fields[`variables.${i}.name`]?.value, fields[`variables.${i}.type`]?.value].map((v) => String(v ?? '').trim()).join('\u0000'));
|
|
76
|
+
return rows.join('\u0001');
|
|
77
|
+
});
|
|
78
|
+
const [usage, setUsage] = useState(null);
|
|
79
|
+
const savedKey = saved.map((v) => `${v.type}:${v.name}`).join(',');
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!savedKey)
|
|
82
|
+
return;
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
// Same origin, as the admin's own requests: `serverURL` may name another host.
|
|
85
|
+
fetch(`${api}/builder/theme/variables/usage?variables=${encodeURIComponent(savedKey)}`, { credentials: 'include', signal: controller.signal })
|
|
86
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
87
|
+
.then((body) => setUsage(body?.usage ?? null))
|
|
88
|
+
.catch(() => {
|
|
89
|
+
// Offline or aborted: no warning.
|
|
90
|
+
});
|
|
91
|
+
return () => controller.abort();
|
|
92
|
+
}, [api, savedKey]);
|
|
93
|
+
if (!usage)
|
|
94
|
+
return null;
|
|
95
|
+
const current = new Map(currentKey
|
|
96
|
+
.split('\u0001')
|
|
97
|
+
.filter(Boolean)
|
|
98
|
+
.map((row) => {
|
|
99
|
+
const [id = '', name = '', type = ''] = row.split('\u0000');
|
|
100
|
+
return [id, { name, type: asType(type) }];
|
|
101
|
+
}));
|
|
102
|
+
const broken = saved.flatMap((variable) => {
|
|
103
|
+
const used = usage[variable.name];
|
|
104
|
+
if (!used || (used.blocks === 0 && used.classes.length === 0))
|
|
105
|
+
return [];
|
|
106
|
+
const now = current.get(variable.id);
|
|
107
|
+
if (now && now.name === variable.name && now.type === variable.type)
|
|
108
|
+
return [];
|
|
109
|
+
const change = !now ? 'removed' : now.name !== variable.name ? `renamed to “${now.name || '…'}”` : `changed to a ${now.type}`;
|
|
110
|
+
return [{ variable, used, change }];
|
|
111
|
+
});
|
|
112
|
+
if (broken.length === 0)
|
|
113
|
+
return null;
|
|
114
|
+
return (_jsxs("div", { className: "theme-variables-warning", "aria-live": "polite", children: [_jsx("p", { className: "theme-variables-warning__title", children: broken.length === 1 ? 'A variable in use changes' : `${broken.length} variables in use change` }), _jsx("ul", { className: "theme-variables-warning__list", children: broken.map(({ variable, used, change }) => (_jsxs("li", { children: [_jsxs("p", { children: [_jsx("code", { children: variable.name }), " is ", change, ". ", usedText(used), " still use ", _jsx("code", { children: variable.name }), " and lose this ", variable.type, " when you save."] }), used.documents.length > 0 || used.classes.length > 0 ? (_jsxs("p", { className: "theme-variables-warning__where", children: ["Used on", ' ', used.documents.map((doc, index) => (_jsxs("span", { children: [index > 0 ? ', ' : '', _jsx("a", { href: builderViewPath(admin, doc.collection, doc.id), target: "_blank", rel: "noreferrer", children: doc.title })] }, `${doc.collection}:${doc.id}`))), used.classes.length > 0 ? `${used.documents.length > 0 ? ' and in ' : ''}${used.classes.map((name) => `.${name}`).join(', ')}` : ''] })) : null] }, variable.id))) }), _jsx("p", { className: "theme-variables-warning__hint", children: "Change those blocks first, or keep the old name." })] }));
|
|
115
|
+
}
|
|
@@ -247,4 +247,117 @@
|
|
|
247
247
|
@extend %theme-quiet-button;
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
+
|
|
251
|
+
// Variables ------------------------------------------------------------------------------------
|
|
252
|
+
|
|
253
|
+
.theme-variable-size {
|
|
254
|
+
&__bar {
|
|
255
|
+
display: block;
|
|
256
|
+
max-width: 100%;
|
|
257
|
+
height: 4px;
|
|
258
|
+
margin-top: calc(var(--base) * 0.375);
|
|
259
|
+
border-radius: 2px;
|
|
260
|
+
background: var(--theme-elevation-300);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.theme-variable-label {
|
|
265
|
+
display: inline-flex;
|
|
266
|
+
align-items: center;
|
|
267
|
+
gap: calc(var(--base) * 0.5);
|
|
268
|
+
min-width: 0;
|
|
269
|
+
|
|
270
|
+
&__preview {
|
|
271
|
+
display: inline-grid;
|
|
272
|
+
flex-shrink: 0;
|
|
273
|
+
place-items: center;
|
|
274
|
+
width: 18px;
|
|
275
|
+
height: 18px;
|
|
276
|
+
overflow: hidden;
|
|
277
|
+
border: 1px solid var(--theme-elevation-200);
|
|
278
|
+
border-radius: 4px;
|
|
279
|
+
background: var(--theme-elevation-50);
|
|
280
|
+
|
|
281
|
+
&[data-empty] {
|
|
282
|
+
background: repeating-conic-gradient(var(--theme-elevation-100) 0 25%, var(--theme-elevation-0) 0 50%) 0 0 / 8px 8px;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&--font {
|
|
286
|
+
color: var(--theme-text);
|
|
287
|
+
font-size: 11px;
|
|
288
|
+
line-height: 1;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
&--size {
|
|
292
|
+
justify-items: start;
|
|
293
|
+
padding: 0 2px;
|
|
294
|
+
|
|
295
|
+
> span {
|
|
296
|
+
display: block;
|
|
297
|
+
max-width: 100%;
|
|
298
|
+
height: 4px;
|
|
299
|
+
border-radius: 2px;
|
|
300
|
+
background: var(--theme-elevation-500);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
&__name {
|
|
306
|
+
color: var(--theme-text);
|
|
307
|
+
font-family: var(--font-mono, monospace);
|
|
308
|
+
font-weight: 500;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
&__meta {
|
|
312
|
+
overflow: hidden;
|
|
313
|
+
color: var(--theme-elevation-500);
|
|
314
|
+
text-overflow: ellipsis;
|
|
315
|
+
white-space: nowrap;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.theme-variables-warning {
|
|
320
|
+
margin: calc(var(--base) * -0.5) 0 var(--spacing-field, calc(var(--base) * 1.5));
|
|
321
|
+
padding: calc(var(--base) * 0.75) var(--base);
|
|
322
|
+
border: 1px solid var(--theme-warning-250);
|
|
323
|
+
border-radius: var(--style-radius-m, var(--border-radius-m));
|
|
324
|
+
background: var(--theme-warning-50);
|
|
325
|
+
color: var(--theme-warning-800);
|
|
326
|
+
font-size: var(--font-body-size-m, 13px);
|
|
327
|
+
|
|
328
|
+
p {
|
|
329
|
+
margin: 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
code {
|
|
333
|
+
padding: 0 3px;
|
|
334
|
+
border-radius: 3px;
|
|
335
|
+
background: var(--theme-warning-100);
|
|
336
|
+
font-size: 0.95em;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
a {
|
|
340
|
+
color: inherit;
|
|
341
|
+
text-decoration: underline;
|
|
342
|
+
text-underline-offset: 2px;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
&__title {
|
|
346
|
+
font-weight: 600;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
&__list {
|
|
350
|
+
display: flex;
|
|
351
|
+
flex-direction: column;
|
|
352
|
+
gap: calc(var(--base) * 0.5);
|
|
353
|
+
margin: calc(var(--base) * 0.5) 0;
|
|
354
|
+
padding: 0;
|
|
355
|
+
list-style: none;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
&__where,
|
|
359
|
+
&__hint {
|
|
360
|
+
color: var(--theme-warning-650);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
250
363
|
}
|
package/dist/theme/client.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { ThemeColorField } from './admin/ColorField.js';
|
|
|
2
2
|
export { ThemeFontField } from './admin/FontField.js';
|
|
3
3
|
export { ThemeSliderField } from './admin/SliderField.js';
|
|
4
4
|
export { ThemeSaveSignal } from './admin/SaveSignal.js';
|
|
5
|
+
export { ThemeVariableRowLabel, ThemeVariableValueField, ThemeVariablesWarning } from './admin/Variables.js';
|
package/dist/theme/client.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
// 'payload-canvas/theme-client#ThemeFontField' — Google Font family with previews
|
|
5
5
|
// 'payload-canvas/theme-client#ThemeSliderField' — slider plus number input (number or text field)
|
|
6
6
|
// 'payload-canvas/theme-client#ThemeSaveSignal' — tells open canvases that the theme changed
|
|
7
|
+
// 'payload-canvas/theme-client#ThemeVariableValueField', '#ThemeVariableRowLabel', '#ThemeVariablesWarning' — the Variables list
|
|
7
8
|
// The fields work in any Payload config, not only in the theme global.
|
|
8
9
|
export { ThemeColorField } from './admin/ColorField.js';
|
|
9
10
|
export { ThemeFontField } from './admin/FontField.js';
|
|
10
11
|
export { ThemeSliderField } from './admin/SliderField.js';
|
|
11
12
|
export { ThemeSaveSignal } from './admin/SaveSignal.js';
|
|
13
|
+
export { ThemeVariableRowLabel, ThemeVariableValueField, ThemeVariablesWarning } from './admin/Variables.js';
|
package/dist/theme/css.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ThemeColors } from './colors.js';
|
|
2
|
+
import { type ThemeVariable } from './variables.js';
|
|
2
3
|
/** The theme global's data, as Payload stores it. Every value is optional. */
|
|
3
4
|
export type ThemeData = {
|
|
4
5
|
colors?: ThemeColors | null;
|
|
@@ -10,6 +11,8 @@ export type ThemeData = {
|
|
|
10
11
|
borderRadius?: string | number | null;
|
|
11
12
|
/** The color variables derived on save (for API consumers). The CSS helpers derive them again. */
|
|
12
13
|
derivedTokens?: Record<string, string> | null;
|
|
14
|
+
/** Design variables: named colors, sizes and fonts (`bg-brand`, `p-gutter`, `font-display`). See `variables.ts`. */
|
|
15
|
+
variables?: ThemeVariable[] | null;
|
|
13
16
|
};
|
|
14
17
|
/** Google Font family names. */
|
|
15
18
|
export type ThemeFonts = {
|
|
@@ -35,11 +38,13 @@ export declare function themeFontFamilies(theme: ThemeData | null | undefined):
|
|
|
35
38
|
* `--sidebar*` (the shadcn/ui names).
|
|
36
39
|
* - `--radius` (rem), `--spacing` (Tailwind's spacing unit, from the base in px).
|
|
37
40
|
* - `--font-sans`, `--font-heading`, `--font-mono`.
|
|
41
|
+
* - Design variables: `--color-<name>`, `--spacing-<name>`, `--font-<name>`.
|
|
38
42
|
*/
|
|
39
43
|
export declare function themeVariables(theme: ThemeData | null | undefined): Record<string, string>;
|
|
40
44
|
/**
|
|
41
45
|
* The theme as CSS: the fallback font faces (one `@font-face` for each chosen family that has known
|
|
42
|
-
* metrics), then one rule `:root:root { --primary: …; … }
|
|
46
|
+
* metrics), then one rule `:root:root { --primary: …; … }`, then the variables' dark values
|
|
47
|
+
* (`:root:root.dark, :root:root .dark { … }`). Empty string when the theme sets nothing.
|
|
43
48
|
* The doubled selector wins over the `:root` defaults in the app's CSS in any load order.
|
|
44
49
|
*/
|
|
45
50
|
export declare function themeCss(theme: ThemeData | null | undefined): string;
|
package/dist/theme/css.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The stored theme as CSS variables and font links. Pure and client-safe.
|
|
2
2
|
import { deriveColors } from './colors.js';
|
|
3
3
|
import { fallbackFamilyName, fallbackFontFace, hasFallbackMetrics } from './fallbacks.js';
|
|
4
|
+
import { variableDeclarations, variableFontFamilies, variablesDarkCss } from './variables.js';
|
|
4
5
|
/** Font variable name → fallback stack after the chosen family. */
|
|
5
6
|
const FONT_FALLBACKS = {
|
|
6
7
|
sans: 'sans-serif',
|
|
@@ -29,7 +30,8 @@ export function themeFontFamilies(theme) {
|
|
|
29
30
|
if (family)
|
|
30
31
|
families[name] = family;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
// Font variables (`font-display`). Their names never clash with sans, heading and mono.
|
|
34
|
+
return { ...variableFontFamilies(theme?.variables), ...families };
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* The CSS variables the theme sets. Only values the theme has are included, so everything else
|
|
@@ -42,6 +44,7 @@ export function themeFontFamilies(theme) {
|
|
|
42
44
|
* `--sidebar*` (the shadcn/ui names).
|
|
43
45
|
* - `--radius` (rem), `--spacing` (Tailwind's spacing unit, from the base in px).
|
|
44
46
|
* - `--font-sans`, `--font-heading`, `--font-mono`.
|
|
47
|
+
* - Design variables: `--color-<name>`, `--spacing-<name>`, `--font-<name>`.
|
|
45
48
|
*/
|
|
46
49
|
export function themeVariables(theme) {
|
|
47
50
|
const vars = {};
|
|
@@ -56,13 +59,16 @@ export function themeVariables(theme) {
|
|
|
56
59
|
for (const [name, family] of Object.entries(themeFontFamilies(theme))) {
|
|
57
60
|
// A known family gets a fallback face scaled to its size (see `themeCss`), so the swap does not move text.
|
|
58
61
|
const sized = hasFallbackMetrics(family) ? `'${fallbackFamilyName(family)}', ` : '';
|
|
59
|
-
vars[`--font-${name}`] = `'${family}', ${sized}${FONT_FALLBACKS[name]}`;
|
|
62
|
+
vars[`--font-${name}`] = `'${family}', ${sized}${FONT_FALLBACKS[name] ?? 'sans-serif'}`;
|
|
60
63
|
}
|
|
64
|
+
// Color and size variables (`--color-brand`, `--spacing-gutter`).
|
|
65
|
+
Object.assign(vars, variableDeclarations(theme?.variables));
|
|
61
66
|
return vars;
|
|
62
67
|
}
|
|
63
68
|
/**
|
|
64
69
|
* The theme as CSS: the fallback font faces (one `@font-face` for each chosen family that has known
|
|
65
|
-
* metrics), then one rule `:root:root { --primary: …; … }
|
|
70
|
+
* metrics), then one rule `:root:root { --primary: …; … }`, then the variables' dark values
|
|
71
|
+
* (`:root:root.dark, :root:root .dark { … }`). Empty string when the theme sets nothing.
|
|
66
72
|
* The doubled selector wins over the `:root` defaults in the app's CSS in any load order.
|
|
67
73
|
*/
|
|
68
74
|
export function themeCss(theme) {
|
|
@@ -71,7 +77,9 @@ export function themeCss(theme) {
|
|
|
71
77
|
return '';
|
|
72
78
|
const faces = [...new Set(Object.values(themeFontFamilies(theme)))].flatMap((family) => fallbackFontFace(family) ?? []);
|
|
73
79
|
const rule = `:root:root { ${entries.map(([k, v]) => `${k}: ${v};`).join(' ')} }`;
|
|
74
|
-
|
|
80
|
+
// Dark values of the variables, under the `.dark` class.
|
|
81
|
+
const dark = variablesDarkCss(theme?.variables);
|
|
82
|
+
return [...faces, rule, ...(dark ? [dark] : [])].join('\n');
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
77
85
|
* One Google Fonts stylesheet URL for the families, with the regular, italic, medium, semibold
|
package/dist/theme/global.js
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
import { revalidatePath, revalidateTag } from 'next/cache';
|
|
4
4
|
import { deriveColors } from './colors.js';
|
|
5
5
|
import { DEFAULT_THEME_SLUG } from './config.js';
|
|
6
|
+
import { forgetThemeVariables } from './server.js';
|
|
7
|
+
import { VARIABLE_TYPES, variableNameProblem, variableValueProblem } from './variables.js';
|
|
6
8
|
const CLIENT = 'payload-canvas/theme-client';
|
|
7
9
|
const COLOR_FIELD = `${CLIENT}#ThemeColorField`;
|
|
8
10
|
const FONT_FIELD = `${CLIENT}#ThemeFontField`;
|
|
9
11
|
const SLIDER_FIELD = `${CLIENT}#ThemeSliderField`;
|
|
10
12
|
const SAVE_SIGNAL = `${CLIENT}#ThemeSaveSignal`;
|
|
13
|
+
const VARIABLE_VALUE_FIELD = `${CLIENT}#ThemeVariableValueField`;
|
|
14
|
+
const VARIABLE_ROW_LABEL = `${CLIENT}#ThemeVariableRowLabel`;
|
|
15
|
+
const VARIABLES_WARNING = `${CLIENT}#ThemeVariablesWarning`;
|
|
11
16
|
/** Name of the hidden field that holds the derived color variables. */
|
|
12
17
|
export const DERIVED_TOKENS_FIELD = 'derivedTokens';
|
|
13
18
|
const COLORS = [
|
|
@@ -74,11 +79,87 @@ function themeFields() {
|
|
|
74
79
|
custom: { min: 0, max: 2, step: 0.125, unit: 'rem', fallback: 0.625 },
|
|
75
80
|
},
|
|
76
81
|
},
|
|
82
|
+
variablesField(),
|
|
83
|
+
// Warns while a rename or a removal would break blocks or classes that use a variable.
|
|
84
|
+
{ name: 'variablesWarning', type: 'ui', admin: { components: { Field: VARIABLES_WARNING } } },
|
|
77
85
|
{ name: DERIVED_TOKENS_FIELD, type: 'json', admin: { hidden: true } },
|
|
78
86
|
// Renders nothing. After each save it tells open builder canvases to reload the theme.
|
|
79
87
|
{ name: 'themeSaveSignal', type: 'ui', admin: { components: { Field: SAVE_SIGNAL } } },
|
|
80
88
|
];
|
|
81
89
|
}
|
|
90
|
+
const typeOf = (siblingData) => {
|
|
91
|
+
const type = siblingData?.type;
|
|
92
|
+
return type === 'size' || type === 'font' ? type : 'color';
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Design variables: named colors, sizes and fonts (`bg-brand`, `p-gutter`, `font-display`), with
|
|
96
|
+
* an optional dark-mode value. See `variables.ts`.
|
|
97
|
+
*/
|
|
98
|
+
function variablesField() {
|
|
99
|
+
return {
|
|
100
|
+
name: 'variables',
|
|
101
|
+
type: 'array',
|
|
102
|
+
label: 'Variables',
|
|
103
|
+
labels: { singular: 'Variable', plural: 'Variables' },
|
|
104
|
+
admin: {
|
|
105
|
+
description: 'Named colors, sizes and fonts. Blocks and classes use them by name, so one change here updates every page.',
|
|
106
|
+
initCollapsed: true,
|
|
107
|
+
components: { RowLabel: VARIABLE_ROW_LABEL },
|
|
108
|
+
},
|
|
109
|
+
fields: [
|
|
110
|
+
{
|
|
111
|
+
type: 'row',
|
|
112
|
+
fields: [
|
|
113
|
+
{
|
|
114
|
+
name: 'name',
|
|
115
|
+
type: 'text',
|
|
116
|
+
required: true,
|
|
117
|
+
admin: { width: '50%', placeholder: 'brand' },
|
|
118
|
+
validate: (value, { siblingData, data }) => {
|
|
119
|
+
const problem = variableNameProblem(value, typeOf(siblingData));
|
|
120
|
+
if (problem)
|
|
121
|
+
return problem;
|
|
122
|
+
const rows = (data?.variables ?? []).filter((row) => typeof row?.name === 'string' && row.name.trim() === String(value).trim());
|
|
123
|
+
return rows.length > 1 ? 'Another variable has this name.' : true;
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'type',
|
|
128
|
+
type: 'select',
|
|
129
|
+
required: true,
|
|
130
|
+
defaultValue: 'color',
|
|
131
|
+
options: VARIABLE_TYPES.map((t) => ({ value: t.value, label: t.label })),
|
|
132
|
+
admin: { width: '50%' },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'row',
|
|
138
|
+
fields: [
|
|
139
|
+
{
|
|
140
|
+
name: 'value',
|
|
141
|
+
type: 'text',
|
|
142
|
+
required: true,
|
|
143
|
+
admin: { width: '50%', components: { Field: VARIABLE_VALUE_FIELD } },
|
|
144
|
+
validate: (value, { siblingData }) => variableValueProblem(value, typeOf(siblingData)) ?? (value ? true : 'Enter a value.'),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'darkValue',
|
|
148
|
+
type: 'text',
|
|
149
|
+
label: 'Dark mode',
|
|
150
|
+
admin: {
|
|
151
|
+
width: '50%',
|
|
152
|
+
description: 'Used inside the dark class. Empty: the same value.',
|
|
153
|
+
condition: (_data, siblingData) => typeOf(siblingData) !== 'font',
|
|
154
|
+
components: { Field: VARIABLE_VALUE_FIELD },
|
|
155
|
+
},
|
|
156
|
+
validate: (value, { siblingData }) => variableValueProblem(value, typeOf(siblingData)) ?? true,
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
82
163
|
/** Derives the color variables on the same write, so API consumers get them too. */
|
|
83
164
|
const deriveTokens = ({ data, originalDoc }) => ({
|
|
84
165
|
...data,
|
|
@@ -91,6 +172,8 @@ const deriveTokens = ({ data, originalDoc }) => ({
|
|
|
91
172
|
*/
|
|
92
173
|
function revalidateTheme(cacheTag) {
|
|
93
174
|
return ({ doc, req: { payload, context } }) => {
|
|
175
|
+
// The compiles read the variables again (a new name makes `bg-<name>` exist).
|
|
176
|
+
forgetThemeVariables(payload);
|
|
94
177
|
if (context?.disableRevalidate)
|
|
95
178
|
return doc;
|
|
96
179
|
try {
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { deriveColors, formatOklch, hexToOklch, hexToOklchValue, parseHex, rgbToOklch, type Oklch, type ThemeColors, } from './colors.js';
|
|
2
2
|
export { cleanFamily, googleFontsHref, themeCss, themeFontFamilies, themeOutput, themeVariables, type ThemeData, type ThemeFonts, type ThemeOutput, } from './css.js';
|
|
3
3
|
export { DEFAULT_THEME_SLUG, THEME_CHANNEL, THEME_CONFIG_KEY, THEME_PATH, themeConfigOf, type ThemeOptions, type ThemeServerConfig, } from './config.js';
|
|
4
|
+
export { cleanVariables, textUsesVariable, variableNameProblem, variableProperty, variablesThemeCss, variableTokens, variableValueProblem, VARIABLE_TYPES, type ThemeVariable, type ThemeVariableType, type VariableToken, } from './variables.js';
|
package/dist/theme/index.js
CHANGED
|
@@ -3,3 +3,4 @@
|
|
|
3
3
|
export { deriveColors, formatOklch, hexToOklch, hexToOklchValue, parseHex, rgbToOklch, } from './colors.js';
|
|
4
4
|
export { cleanFamily, googleFontsHref, themeCss, themeFontFamilies, themeOutput, themeVariables, } from './css.js';
|
|
5
5
|
export { DEFAULT_THEME_SLUG, THEME_CHANNEL, THEME_CONFIG_KEY, THEME_PATH, themeConfigOf, } from './config.js';
|
|
6
|
+
export { cleanVariables, textUsesVariable, variableNameProblem, variableProperty, variablesThemeCss, variableTokens, variableValueProblem, VARIABLE_TYPES, } from './variables.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { StyleTokens } from '../core/types.js';
|
|
3
|
+
import { type CssOptions } from '../css/index.js';
|
|
4
|
+
import { type ThemeVariable } from './variables.js';
|
|
5
|
+
/** The theme's usable variables. Empty with `theme: false` or when the global cannot be read. */
|
|
6
|
+
export declare function themeVariablesOf(payload: Payload): Promise<ThemeVariable[]>;
|
|
7
|
+
/** Forgets the cached variables (after a theme save). */
|
|
8
|
+
export declare function forgetThemeVariables(payload: Payload): void;
|
|
9
|
+
/**
|
|
10
|
+
* The CSS options with the theme's variables registered (`themeCss`), so the compile knows
|
|
11
|
+
* `bg-brand`, `p-gutter` and `font-display`. The options as they are without variables.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withThemeVariables(payload: Payload, css: CssOptions): Promise<CssOptions>;
|
|
14
|
+
/** The Styles panel's tokens with the theme's variables: their names in the token lists, and `variables`. */
|
|
15
|
+
export declare function themeStyleTokens(payload: Payload, css: CssOptions): Promise<StyleTokens>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The theme's design variables on the server: read once per Payload instance (a theme save clears
|
|
2
|
+
// the cache), and added to the CSS options of every Tailwind compile. Server-only, no Next imports.
|
|
3
|
+
import { getStyleTokens } from '../css/index.js';
|
|
4
|
+
import { themeConfigOf } from './config.js';
|
|
5
|
+
import { cleanVariables, variablesThemeCss, variableTokens } from './variables.js';
|
|
6
|
+
/** On the Payload instance (not a module map), so every copy of this module shares it. */
|
|
7
|
+
const CACHE = Symbol.for('payload-canvas.themeVariables');
|
|
8
|
+
/** Other server processes see a theme save after at most this long. */
|
|
9
|
+
const TTL_MS = 10_000;
|
|
10
|
+
/** The theme's usable variables. Empty with `theme: false` or when the global cannot be read. */
|
|
11
|
+
export function themeVariablesOf(payload) {
|
|
12
|
+
// A stub without a config (some unit tests call hooks with one) has no theme.
|
|
13
|
+
const config = payload?.config ? themeConfigOf(payload) : null;
|
|
14
|
+
if (!config)
|
|
15
|
+
return Promise.resolve([]);
|
|
16
|
+
const holder = payload;
|
|
17
|
+
const cached = holder[CACHE];
|
|
18
|
+
if (cached && Date.now() - cached.at < TTL_MS)
|
|
19
|
+
return cached.value;
|
|
20
|
+
const value = payload
|
|
21
|
+
.findGlobal({ slug: config.slug, depth: 0, overrideAccess: true })
|
|
22
|
+
.then((doc) => cleanVariables(doc?.variables))
|
|
23
|
+
.catch(() => []);
|
|
24
|
+
holder[CACHE] = { at: Date.now(), value };
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/** Forgets the cached variables (after a theme save). */
|
|
28
|
+
export function forgetThemeVariables(payload) {
|
|
29
|
+
delete payload[CACHE];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The CSS options with the theme's variables registered (`themeCss`), so the compile knows
|
|
33
|
+
* `bg-brand`, `p-gutter` and `font-display`. The options as they are without variables.
|
|
34
|
+
*/
|
|
35
|
+
export async function withThemeVariables(payload, css) {
|
|
36
|
+
const themeCss = variablesThemeCss(await themeVariablesOf(payload));
|
|
37
|
+
return themeCss ? { ...css, themeCss } : css;
|
|
38
|
+
}
|
|
39
|
+
/** The Styles panel's tokens with the theme's variables: their names in the token lists, and `variables`. */
|
|
40
|
+
export async function themeStyleTokens(payload, css) {
|
|
41
|
+
const [variables, tokens] = await Promise.all([themeVariablesOf(payload), withThemeVariables(payload, css).then(getStyleTokens)]);
|
|
42
|
+
return variables.length > 0 ? { ...tokens, variables: variableTokens(variables) } : tokens;
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Endpoint, PayloadRequest } from 'payload';
|
|
2
|
+
import type { ClassUsageDocument } from '../classes/shared.js';
|
|
3
|
+
import type { Layout } from '../core/types.js';
|
|
4
|
+
import { type ThemeVariable } from './variables.js';
|
|
5
|
+
/** Where one variable is used. */
|
|
6
|
+
export type VariableUsage = {
|
|
7
|
+
/** Blocks (and inner parts) that use it. */
|
|
8
|
+
blocks: number;
|
|
9
|
+
documents: ClassUsageDocument[];
|
|
10
|
+
/** Editable classes whose styles or custom CSS use it. */
|
|
11
|
+
classes: string[];
|
|
12
|
+
};
|
|
13
|
+
/** Path below the API route: `GET` where each variable is used. `?variables=color:brand,size:gutter` limits it. */
|
|
14
|
+
export declare const VARIABLE_USAGE_PATH = "/builder/theme/variables/usage";
|
|
15
|
+
type Wanted = Pick<ThemeVariable, 'name' | 'type'>;
|
|
16
|
+
/** Blocks of a layout that use the variable (their classes or their parts' classes). */
|
|
17
|
+
export declare function countVariableUses(layout: Layout, variable: Wanted): number;
|
|
18
|
+
/** Where each variable is used, in the documents and classes the request's user may read. Keyed by name. */
|
|
19
|
+
export declare function variableUsage(req: PayloadRequest, variables: readonly Wanted[]): Promise<Record<string, VariableUsage>>;
|
|
20
|
+
/** `color:brand,size:gutter` → the variables. Unknown types are left out. */
|
|
21
|
+
export declare function parseVariablesParam(value: string): Wanted[];
|
|
22
|
+
export declare function variableUsageEndpoint(): Endpoint;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Where the theme's design variables are used: blocks in every builder layout (pages, posts,
|
|
2
|
+
// templates, saved sections; open live sessions first) and the editable classes. The Theme form
|
|
3
|
+
// warns before a rename or delete of a variable in use. Server-only.
|
|
4
|
+
import { loadClasses } from '../classes/actions.js';
|
|
5
|
+
import { classesConfigOf } from '../classes/config.js';
|
|
6
|
+
import { scanLayouts } from '../classes/usage.js';
|
|
7
|
+
import { walkBlocks } from '../core/tree.js';
|
|
8
|
+
import { THEME_PATH } from './config.js';
|
|
9
|
+
import { themeVariablesOf } from './server.js';
|
|
10
|
+
import { textUsesVariable } from './variables.js';
|
|
11
|
+
/** Path below the API route: `GET` where each variable is used. `?variables=color:brand,size:gutter` limits it. */
|
|
12
|
+
export const VARIABLE_USAGE_PATH = `${THEME_PATH}/variables/usage`;
|
|
13
|
+
/** Blocks of a layout that use the variable (their classes or their parts' classes). */
|
|
14
|
+
export function countVariableUses(layout, variable) {
|
|
15
|
+
let count = 0;
|
|
16
|
+
walkBlocks(layout, (block) => {
|
|
17
|
+
const texts = [block.className, ...Object.values(block.partClassName ?? {})];
|
|
18
|
+
if (texts.some((text) => typeof text === 'string' && textUsesVariable(text, variable)))
|
|
19
|
+
count++;
|
|
20
|
+
});
|
|
21
|
+
return count;
|
|
22
|
+
}
|
|
23
|
+
/** Where each variable is used, in the documents and classes the request's user may read. Keyed by name. */
|
|
24
|
+
export async function variableUsage(req, variables) {
|
|
25
|
+
const usage = Object.fromEntries(variables.map((v) => [v.name, { blocks: 0, documents: [], classes: [] }]));
|
|
26
|
+
if (variables.length === 0)
|
|
27
|
+
return usage;
|
|
28
|
+
const [layouts, classes] = await Promise.all([
|
|
29
|
+
scanLayouts(req, true),
|
|
30
|
+
classesConfigOf(req.payload) ? loadClasses(req).catch(() => []) : Promise.resolve([]),
|
|
31
|
+
]);
|
|
32
|
+
for (const variable of variables) {
|
|
33
|
+
const entry = usage[variable.name];
|
|
34
|
+
for (const { collection, id, title, layout } of layouts) {
|
|
35
|
+
const blocks = countVariableUses(layout, variable);
|
|
36
|
+
if (blocks === 0)
|
|
37
|
+
continue;
|
|
38
|
+
entry.blocks += blocks;
|
|
39
|
+
entry.documents.push({ collection, id, title, blocks });
|
|
40
|
+
}
|
|
41
|
+
for (const item of classes) {
|
|
42
|
+
if (textUsesVariable(item.styles, variable) || textUsesVariable(item.css, variable))
|
|
43
|
+
entry.classes.push(item.name);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return usage;
|
|
47
|
+
}
|
|
48
|
+
const TYPES = new Set(['color', 'size', 'font']);
|
|
49
|
+
/** `color:brand,size:gutter` → the variables. Unknown types are left out. */
|
|
50
|
+
export function parseVariablesParam(value) {
|
|
51
|
+
return value
|
|
52
|
+
.split(',')
|
|
53
|
+
.map((part) => part.trim().split(':'))
|
|
54
|
+
.flatMap(([type, name]) => (type && name && TYPES.has(type) ? [{ type: type, name }] : []));
|
|
55
|
+
}
|
|
56
|
+
export function variableUsageEndpoint() {
|
|
57
|
+
return {
|
|
58
|
+
path: VARIABLE_USAGE_PATH,
|
|
59
|
+
method: 'get',
|
|
60
|
+
handler: async (req) => {
|
|
61
|
+
if (!req.user)
|
|
62
|
+
return Response.json({ error: 'Sign in to see where variables are used.' }, { status: 401 });
|
|
63
|
+
const asked = typeof req.searchParams?.get === 'function' ? req.searchParams.get('variables') : null;
|
|
64
|
+
const variables = asked ? parseVariablesParam(asked) : await themeVariablesOf(req.payload);
|
|
65
|
+
return Response.json({ usage: await variableUsage(req, variables) }, { headers: { 'Cache-Control': 'no-store' } });
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|