payload-canvas 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +625 -153
- 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 -2
- package/dist/blocks/index.js +1 -2
- 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,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { Collapsible, DraggableSortable, FieldLabel, useDraggableSortable } from '@payloadcms/ui';
|
|
4
4
|
import { memo, use, useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { createId } from '../../../core/ids.js';
|
|
6
6
|
import { Icon } from '../icons.js';
|
|
7
7
|
import { RenderBlockFields } from '../renderField.js';
|
|
8
8
|
import { Popover, usePopover } from '../styles/popover.js';
|
|
9
|
+
import { AddButton } from './AddButton.js';
|
|
9
10
|
import { arrayStateKey, cloneRow, fallbackRowLabel, moveItem, toggleId, withRowIds } from './arrayRows.js';
|
|
10
11
|
import { ArrayRowContext, asStructuralChange, generatedRowId, getCollapsedRows, setCollapsedRows, useCollapsedRows } from './arrayState.js';
|
|
11
12
|
import { rowLabel } from './values.js';
|
|
@@ -57,7 +58,7 @@ export function ArrayField({ fields, label, singular, description, maxRows, path
|
|
|
57
58
|
};
|
|
58
59
|
}, []);
|
|
59
60
|
const ids = rows.map((row) => row.id);
|
|
60
|
-
return (_jsxs("div", { className: "builder-field-array", children: [_jsxs("div", { className: "builder-field-array__head", children: [_jsx(FieldLabel, { label: label, path: path }), rows.length > 0 && (_jsxs("div", { className: "builder-field-array__head-actions", children: [_jsx("button", { type: "button", onClick: () => setCollapsedRows(stateKey, new Set(ids)), children: "Collapse all" }), _jsx("button", { type: "button", onClick: () => setCollapsedRows(stateKey, new Set()), children: "Show all" })] }))] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), rows.length > 0 && (_jsx(DraggableSortable, { className: "builder-field-array__rows", ids: ids, onDragEnd: ({ moveFromIndex, moveToIndex }) => actions.move(moveFromIndex, moveToIndex), children: rows.map((row, index) => (_jsx(ArrayFieldRow, { actions: actions, collapsed: collapsed.has(row.id), fields: fields, full: full, index: index, itemLabel: itemLabel, path: path, row: row, rowCount: rows.length, stateKey: stateKey }, row.id))) })), _jsx(
|
|
61
|
+
return (_jsxs("div", { className: "builder-field-array", children: [_jsxs("div", { className: "builder-field-array__head", children: [_jsx(FieldLabel, { label: label, path: path }), rows.length > 0 && (_jsxs("div", { className: "builder-field-array__head-actions", children: [_jsx("button", { type: "button", onClick: () => setCollapsedRows(stateKey, new Set(ids)), children: "Collapse all" }), _jsx("button", { type: "button", onClick: () => setCollapsedRows(stateKey, new Set()), children: "Show all" })] }))] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), rows.length > 0 && (_jsx(DraggableSortable, { className: "builder-field-array__rows", ids: ids, onDragEnd: ({ moveFromIndex, moveToIndex }) => actions.move(moveFromIndex, moveToIndex), children: rows.map((row, index) => (_jsx(ArrayFieldRow, { actions: actions, collapsed: collapsed.has(row.id), fields: fields, full: full, index: index, itemLabel: itemLabel, path: path, row: row, rowCount: rows.length, stateKey: stateKey }, row.id))) })), _jsx(AddButton, { disabled: full, onClick: () => actions.addBelow(rows.length - 1), children: singular ? `Add ${singular.toLowerCase()}` : 'Add item' })] }));
|
|
61
62
|
}
|
|
62
63
|
/** One row. Memoized: typing in one row does not re-render the others. */
|
|
63
64
|
const ArrayFieldRow = memo(function ArrayFieldRow({ actions, collapsed, fields, full, index, itemLabel, path, row, rowCount, stateKey, }) {
|
|
@@ -19,6 +19,7 @@ export declare function CheckedTextField({ check, onChange, value, ...props }: B
|
|
|
19
19
|
readonly check: (value: string) => string | null;
|
|
20
20
|
readonly value: string;
|
|
21
21
|
readonly onChange: (value: string) => void;
|
|
22
|
+
readonly placeholder?: string;
|
|
22
23
|
}): import("react").JSX.Element;
|
|
23
24
|
/**
|
|
24
25
|
* A number input that keeps the text as typed. A valid number is stored at once; text that is not
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ConditionFieldOption, type ConditionRow, type ConditionSources } from './conditions.js';
|
|
2
|
+
export type { ConditionFieldOption, ConditionRow, ConditionSources } from './conditions.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
/** "Or" groups of "and" rows. */
|
|
5
|
+
readonly groups: ConditionRow[][];
|
|
6
|
+
/** Called with every group and row (rows without a field too: the caller leaves those out of the stored value). */
|
|
7
|
+
readonly onChange: (groups: ConditionRow[][]) => void;
|
|
8
|
+
/** The fields to pick from. Empty: the field is a text input. */
|
|
9
|
+
readonly fields: ConditionFieldOption[];
|
|
10
|
+
/** The value sources besides a fixed value. */
|
|
11
|
+
readonly sources?: ConditionSources;
|
|
12
|
+
/** The operator of a new row, before a field is picked. */
|
|
13
|
+
readonly defaultOperator: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The condition groups. With one group, "Add condition" and "Add “or” group" sit side by side
|
|
17
|
+
* under the rows; with several, each boxed group has its own "Add condition".
|
|
18
|
+
*/
|
|
19
|
+
export declare function ConditionRows({ groups, onChange, fields, sources, defaultOperator }: Props): import("react").JSX.Element;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Condition rows: field, operator, value and a remove button, in "or" groups of "and" rows. Shared
|
|
4
|
+
// by the where builder (WhereField: a Payload `where` query) and the visibility conditions (a
|
|
5
|
+
// block's `visibility`). The value input follows the field's Payload type (a select's options, a
|
|
6
|
+
// date, a number, a document picker, checked / not checked), and a row's value can come from
|
|
7
|
+
// another source (a relative date, a page field, a URL parameter, another field) when the caller
|
|
8
|
+
// offers it. The caller turns the groups into its own stored value. The rules live in conditions.ts.
|
|
9
|
+
import { RelationshipInput, SelectInput } from '@payloadcms/ui';
|
|
10
|
+
import { Fragment, useId, useState } from 'react';
|
|
11
|
+
import { pageToken, pageTokenPath, parseDateToken, queryToken, queryTokenParam } from '../../../core/whereValues.js';
|
|
12
|
+
import { Select } from '../ui/Select.js';
|
|
13
|
+
import { AddButton, RemoveRowButton } from './AddButton.js';
|
|
14
|
+
import { changeRelativeDate, compatibleFields, operatorOptions, RELATIVE_DATE_OPTIONS, relativeDateKey, rowSource, rowSources, SOURCE_LABELS, valueInputOf, withField, withOperator, withSource, } from './conditions.js';
|
|
15
|
+
import { fromRelationshipInput, toRelationshipInput } from './values.js';
|
|
16
|
+
import { parseWhereValue, whereValueText } from './whereRows.js';
|
|
17
|
+
const CHECKED = [
|
|
18
|
+
{ value: 'true', label: 'checked' },
|
|
19
|
+
{ value: 'false', label: 'not checked' },
|
|
20
|
+
];
|
|
21
|
+
/** The select value of a field option: the path, with a prefix for "number of items". */
|
|
22
|
+
const optionKey = (path, count) => (count ? `#${path}` : path);
|
|
23
|
+
const fieldOf = (fields, row) => fields.find((f) => f.path === row.field && Boolean(f.count) === Boolean(row.count));
|
|
24
|
+
/** The field select: the fields, then "Number of items" for counts, and the row's own path when it is not listed. */
|
|
25
|
+
function fieldEntries(fields, row) {
|
|
26
|
+
const entries = fields.filter((f) => !f.count).map((f) => ({ value: optionKey(f.path), label: f.label }));
|
|
27
|
+
const counts = fields.filter((f) => f.count).map((f) => ({ value: optionKey(f.path, true), label: `${f.label} (count)` }));
|
|
28
|
+
if (counts.length > 0)
|
|
29
|
+
entries.push({ group: 'Number of items', options: counts });
|
|
30
|
+
if (row.field && !fieldOf(fields, row))
|
|
31
|
+
entries.unshift({ value: optionKey(row.field, row.count), label: row.count ? `${row.field} (count)` : row.field });
|
|
32
|
+
return entries;
|
|
33
|
+
}
|
|
34
|
+
const newRow = (operator) => ({ field: '', operator, value: '', text: '' });
|
|
35
|
+
/**
|
|
36
|
+
* The condition groups. With one group, "Add condition" and "Add “or” group" sit side by side
|
|
37
|
+
* under the rows; with several, each boxed group has its own "Add condition".
|
|
38
|
+
*/
|
|
39
|
+
export function ConditionRows({ groups, onChange, fields, sources, defaultOperator }) {
|
|
40
|
+
const multi = groups.length > 1;
|
|
41
|
+
const changeGroup = (g, rows) =>
|
|
42
|
+
// A group without rows is gone.
|
|
43
|
+
onChange(rows.length === 0 ? groups.filter((_, i) => i !== g) : groups.map((group, i) => (i === g ? rows : group)));
|
|
44
|
+
const addOrGroup = (_jsx(AddButton, { onClick: () => onChange([...groups, [newRow(defaultOperator)]]), children: "Add \u201Cor\u201D group" }));
|
|
45
|
+
if (groups.length === 0) {
|
|
46
|
+
return _jsx(AddButton, { onClick: () => onChange([[newRow(defaultOperator)]]), children: "Add condition" });
|
|
47
|
+
}
|
|
48
|
+
return (_jsxs("div", { className: "builder-conditions", children: [groups.map((group, g) => {
|
|
49
|
+
const groupName = multi ? `Group ${g + 1}` : '';
|
|
50
|
+
return (_jsxs(Fragment, { children: [g > 0 && (_jsx("p", { className: "builder-conditions__or", "aria-hidden": "true", children: "or" })), _jsxs("fieldset", { className: `builder-conditions__group${multi ? ' builder-conditions__group--boxed' : ''}`, "aria-label": multi ? `${groupName}: all of these match` : undefined, children: [multi && _jsx("legend", { className: "builder-conditions__legend", children: g === 0 ? 'All of these' : 'Or all of these' }), group.map((row, r) => {
|
|
51
|
+
const name = multi ? `${groupName}, condition ${r + 1}` : `Condition ${r + 1}`;
|
|
52
|
+
return (_jsxs(Fragment, { children: [r > 0 && (_jsx("p", { className: "builder-conditions__and", "aria-hidden": "true", children: "and" })), _jsx(ConditionRowEditor, { row: row, name: name, fields: fields, sources: sources, onChange: (next) => changeGroup(g, group.map((old, i) => (i === r ? next : old))), onRemove: () => changeGroup(g, group.filter((_, i) => i !== r)) })] }, r));
|
|
53
|
+
}), multi && (_jsx(AddButton, { "aria-label": `Add a condition to ${groupName.toLowerCase()}`, onClick: () => changeGroup(g, [...group, newRow(defaultOperator)]), children: "Add condition" }))] })] }, g));
|
|
54
|
+
}), _jsxs("div", { className: "builder-add-row", children: [!multi && _jsx(AddButton, { onClick: () => changeGroup(0, [...groups[0], newRow(defaultOperator)]), children: "Add condition" }), addOrGroup] })] }));
|
|
55
|
+
}
|
|
56
|
+
/** One row: field, operator, remove; then where the value comes from and the value. */
|
|
57
|
+
function ConditionRowEditor({ row, name, fields, sources, onChange, onRemove }) {
|
|
58
|
+
const field = fieldOf(fields, row);
|
|
59
|
+
const offered = rowSources(field, row.operator, sources);
|
|
60
|
+
const source = rowSource(row, sources);
|
|
61
|
+
const input = valueInputOf(field, row.operator);
|
|
62
|
+
const sourceOptions = (offered.includes(source) ? offered : [source, ...offered]).map((value) => ({ value, label: SOURCE_LABELS[value] }));
|
|
63
|
+
return (_jsxs("fieldset", { className: "builder-where__row", "aria-label": name, children: [fields.length > 0 ? (_jsx(Select, { "aria-label": `${name}: field`, placeholder: "Field", value: row.field ? optionKey(row.field, row.count) : null, options: fieldEntries(fields, row), onValueChange: (key) => {
|
|
64
|
+
const picked = fields.find((f) => optionKey(f.path, f.count) === key);
|
|
65
|
+
onChange(withField(row, picked, picked?.path ?? key ?? ''));
|
|
66
|
+
} })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: field`, placeholder: "Field", value: row.field, onChange: (e) => onChange({ ...row, field: e.target.value }) })), _jsx(Select, { "aria-label": `${name}: operator`, value: row.operator, options: operatorOptions(field, row.operator), onValueChange: (next) => onChange(withOperator(row, next ?? row.operator, field, sources)) }), _jsx(RemoveRowButton, { label: `Remove ${name.toLowerCase()}`, onClick: onRemove }), input.kind !== 'none' && (_jsxs("div", { className: "builder-where__value", children: [sourceOptions.length > 1 && (_jsx(Select, { "aria-label": `${name}: value from`, className: "builder-where__source", value: source, options: sourceOptions, onValueChange: (next) => onChange(withSource(row, (next ?? 'fixed'), field, sources)) })), _jsx(SourceValue, { row: row, name: name, field: field, source: source, sources: sources, onChange: onChange })] }))] }));
|
|
67
|
+
}
|
|
68
|
+
/** The value input of the row's source. */
|
|
69
|
+
function SourceValue({ row, name, field, source, sources, onChange }) {
|
|
70
|
+
const setValue = (value) => onChange({ ...row, value, text: '' });
|
|
71
|
+
const fieldSelect = (candidates, value, placeholder, set) => (_jsx(Select, { "aria-label": `${name}: ${placeholder.toLowerCase()}`, placeholder: placeholder, value: value || null, options: candidates.map((f) => ({ value: f.path, label: f.label })), onValueChange: (path) => set(path ?? '') }));
|
|
72
|
+
switch (source) {
|
|
73
|
+
case 'date': {
|
|
74
|
+
const date = parseDateToken(row.value) ?? { amount: 0, unit: 'd', direction: -1 };
|
|
75
|
+
const key = relativeDateKey(date);
|
|
76
|
+
return (_jsxs("div", { className: "builder-where__inline", children: [key !== 'now' && (_jsx(AmountInput, { label: `${name}: number of ${date.unit === 'h' ? 'hours' : 'days'}`, value: date.amount, onCommit: (amount) => setValue(changeRelativeDate(date, { amount })) })), _jsx(Select, { "aria-label": `${name}: relative date`, value: key, options: RELATIVE_DATE_OPTIONS, onValueChange: (next) => setValue(changeRelativeDate(date, { key: next ?? 'now' })) })] }));
|
|
77
|
+
}
|
|
78
|
+
case 'page':
|
|
79
|
+
return fieldSelect(compatibleFields(field, sources?.page ?? []), pageTokenPath(row.value), 'Page field', (path) => setValue(pageToken(path)));
|
|
80
|
+
case 'field':
|
|
81
|
+
return fieldSelect(compatibleFields(field, sources?.field ?? [], true), row.valueField ?? null, 'Other field', (path) => onChange({ ...row, value: undefined, text: '', valueField: path }));
|
|
82
|
+
case 'query':
|
|
83
|
+
return (_jsxs("div", { className: "builder-where__inline", children: [_jsx("span", { className: "builder-where__prefix", "aria-hidden": "true", children: "?" }), _jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: URL parameter`, title: "The editor preview ignores this condition.", placeholder: "category", value: queryTokenParam(row.value) ?? '', onChange: (e) => setValue(queryToken(e.target.value.trim())) })] }));
|
|
84
|
+
default:
|
|
85
|
+
return _jsx(FixedValue, { row: row, name: name, field: field, onChange: onChange });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** A number of days or hours: keeps what is typed, and stores only whole numbers from 1. */
|
|
89
|
+
function AmountInput({ label, value, onCommit }) {
|
|
90
|
+
const [text, setText] = useState(String(value));
|
|
91
|
+
const [shown, setShown] = useState(value);
|
|
92
|
+
if (value !== shown) {
|
|
93
|
+
setShown(value);
|
|
94
|
+
setText(String(value));
|
|
95
|
+
}
|
|
96
|
+
return (_jsx("input", { type: "number", min: 1, step: 1, className: "builder-where__input builder-where__input--amount", "aria-label": label, value: text, onChange: (e) => {
|
|
97
|
+
setText(e.target.value);
|
|
98
|
+
const amount = Math.floor(Number(e.target.value));
|
|
99
|
+
if (amount >= 1)
|
|
100
|
+
onCommit(amount);
|
|
101
|
+
}, onBlur: () => setText(String(value)) }));
|
|
102
|
+
}
|
|
103
|
+
/** The date part of a stored date ("2026-01-31" of "2026-01-31T00:00:00.000Z") for a date input. */
|
|
104
|
+
const dateInputValue = (value) => (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value) ? value.slice(0, 10) : '');
|
|
105
|
+
/** A fixed value, typed by the field: a select's options, checked, a number, a date, documents, or text. */
|
|
106
|
+
function FixedValue({ row, name, field, onChange }) {
|
|
107
|
+
const id = useId();
|
|
108
|
+
const input = valueInputOf(field, row.operator);
|
|
109
|
+
const type = field?.count ? 'number' : field?.type;
|
|
110
|
+
const typed = (text) => onChange({ ...row, text, value: parseWhereValue(text, row.operator, type) });
|
|
111
|
+
switch (input.kind) {
|
|
112
|
+
case 'checkbox':
|
|
113
|
+
return (_jsx(Select, { "aria-label": `${name}: value`, value: row.value === false ? 'false' : 'true', options: CHECKED, onValueChange: (next) => onChange({ ...row, value: next !== 'false', text: '' }) }));
|
|
114
|
+
case 'number':
|
|
115
|
+
return (_jsxs("div", { className: "builder-where__inline", children: [_jsx("input", { type: "number", className: "builder-where__input", "aria-label": `${name}: value`, placeholder: "0", value: row.text || whereValueText(row.value), onChange: (e) => typed(e.target.value) }), field?.count && _jsx("span", { className: "builder-where__suffix", children: "items" })] }));
|
|
116
|
+
case 'date':
|
|
117
|
+
return (_jsx("input", { type: "date", className: "builder-where__input", "aria-label": `${name}: date`, value: dateInputValue(row.value), onChange: (e) => onChange({ ...row, value: e.target.value, text: '' }) }));
|
|
118
|
+
case 'options': {
|
|
119
|
+
const options = (field?.options ?? []).map((o) => ({ label: o.label, value: o.value }));
|
|
120
|
+
if (!input.multiple) {
|
|
121
|
+
return (_jsx(Select, { "aria-label": `${name}: value`, placeholder: "Choose", value: typeof row.value === 'string' && row.value ? row.value : null, options: options, onValueChange: (next) => onChange({ ...row, value: next ?? '', text: '' }) }));
|
|
122
|
+
}
|
|
123
|
+
return (_jsx(SelectInput, { className: "builder-where__payload", hasMany: true, isClearable: true, name: `${id}-value`, path: `${id}-value`, options: options, placeholder: "Choose", value: Array.isArray(row.value) ? row.value.map(String) : [], onChange: (next) => {
|
|
124
|
+
const list = Array.isArray(next) ? next.map((o) => String(o.value)) : [];
|
|
125
|
+
onChange({ ...row, value: list, text: '' });
|
|
126
|
+
} }));
|
|
127
|
+
}
|
|
128
|
+
case 'documents': {
|
|
129
|
+
const relationTo = [String(field?.relationTo)];
|
|
130
|
+
const shared = { className: 'builder-where__payload', path: `${id}-value`, relationTo, allowCreate: false, allowEdit: false, placeholder: 'Choose' };
|
|
131
|
+
const set = (next) => onChange({ ...row, value: fromRelationshipInput(next, false) ?? '', text: '' });
|
|
132
|
+
return input.multiple ? (_jsx(RelationshipInput, { ...shared, hasMany: true, onChange: set, value: toRelationshipInput(Array.isArray(row.value) ? row.value : [], relationTo, false, true) })) : (_jsx(RelationshipInput, { ...shared, hasMany: false, onChange: set, value: toRelationshipInput(row.value === '' ? null : row.value, relationTo, false, false) }));
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
return (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: value`, placeholder: input.multiple ? 'a, b, c' : 'Value', value: row.text, onChange: (e) => typed(e.target.value) }));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
import { WhereField } from './WhereField.js';
|
|
3
|
+
/**
|
|
4
|
+
* A collection list's `where` in the inspector. A row's value can be a relative date, a URL
|
|
5
|
+
* parameter, and in a template a field of the page's document (`$page.<path>`, read when the
|
|
6
|
+
* list loads, on the site and the canvas alike).
|
|
7
|
+
*/
|
|
8
|
+
export declare function ListWhereField(props: Omit<ComponentProps<typeof WhereField>, 'sources'>): import("react").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useRuntime } from '../runtime.js';
|
|
5
|
+
import { pageConditionFields } from '../templates/visibilityRows.js';
|
|
6
|
+
import { useValue } from '../valueStore.js';
|
|
7
|
+
import { WhereField } from './WhereField.js';
|
|
8
|
+
/**
|
|
9
|
+
* A collection list's `where` in the inspector. A row's value can be a relative date, a URL
|
|
10
|
+
* parameter, and in a template a field of the page's document (`$page.<path>`, read when the
|
|
11
|
+
* list loads, on the site and the canvas alike).
|
|
12
|
+
*/
|
|
13
|
+
export function ListWhereField(props) {
|
|
14
|
+
const runtime = useRuntime();
|
|
15
|
+
const template = useValue(runtime.template);
|
|
16
|
+
const target = template.isTemplate ? template.target : null;
|
|
17
|
+
const page = target ? runtime.config.templates?.sources?.[target] : undefined;
|
|
18
|
+
const sources = useMemo(() => ({ date: true, query: true, ...(page && target ? { page: pageConditionFields(page, target) } : {}) }), [page, target]);
|
|
19
|
+
return _jsx(WhereField, { ...props, sources: sources });
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
readonly label: string;
|
|
3
|
+
readonly description?: string;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly required: boolean;
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
readonly onChange: (value: unknown) => void;
|
|
8
|
+
/** The slug of the listed collection, when known: its fields fill the field select. */
|
|
9
|
+
readonly collection?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A collection list's URL filters as rows: a URL parameter and the field it filters
|
|
13
|
+
* (`?category=news` lists documents whose field is "news"). Stores `{ [param]: field }`. A value
|
|
14
|
+
* that maps URL values to where queries (the full form) opens as JSON. "Edit as JSON" switches
|
|
15
|
+
* to the JSON editor.
|
|
16
|
+
*/
|
|
17
|
+
export declare function QueryFiltersField({ label, description, path, required, value, onChange, collection }: Props): import("react").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldLabel } from '@payloadcms/ui';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { Select } from '../ui/Select.js';
|
|
6
|
+
import { AddButton, RemoveRowButton } from './AddButton.js';
|
|
7
|
+
import { useCollectionFields } from './collectionFields.js';
|
|
8
|
+
import { JsonField } from './JsonField.js';
|
|
9
|
+
import { queryFilterRows, rowsQueryFilters } from './queryFilterRows.js';
|
|
10
|
+
/**
|
|
11
|
+
* A collection list's URL filters as rows: a URL parameter and the field it filters
|
|
12
|
+
* (`?category=news` lists documents whose field is "news"). Stores `{ [param]: field }`. A value
|
|
13
|
+
* that maps URL values to where queries (the full form) opens as JSON. "Edit as JSON" switches
|
|
14
|
+
* to the JSON editor.
|
|
15
|
+
*/
|
|
16
|
+
export function QueryFiltersField({ label, description, path, required, value, onChange, collection }) {
|
|
17
|
+
const fields = useCollectionFields(collection);
|
|
18
|
+
const [json, setJson] = useState(false);
|
|
19
|
+
const [draft, setDraft] = useState(() => ({ rows: queryFilterRows(value) ?? [], source: value }));
|
|
20
|
+
// The value changed from outside (undo, AI edit): show it. Our own edits come back as `source`.
|
|
21
|
+
if (value !== draft.source)
|
|
22
|
+
setDraft({ rows: queryFilterRows(value) ?? [], source: value });
|
|
23
|
+
const fits = queryFilterRows(value) !== null;
|
|
24
|
+
if (json || !fits) {
|
|
25
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsx(JsonField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value }), fits ? (_jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(false), children: "Edit as rows" })) : (_jsx("p", { className: "builder-field-group__description", children: "Too complex for rows, so they open as JSON." }))] }));
|
|
26
|
+
}
|
|
27
|
+
const update = (rows) => {
|
|
28
|
+
const next = rowsQueryFilters(rows);
|
|
29
|
+
setDraft({ rows, source: next });
|
|
30
|
+
onChange(next);
|
|
31
|
+
};
|
|
32
|
+
const change = (index, patch) => update(draft.rows.map((row, i) => (i === index ? { ...row, ...patch } : row)));
|
|
33
|
+
const fieldOptions = (current) => {
|
|
34
|
+
const options = fields.map((f) => ({ value: f.name, label: f.name }));
|
|
35
|
+
return current && !options.some((o) => o.value === current) ? [{ value: current, label: current }, ...options] : options;
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsxs("div", { className: "builder-where__head", children: [_jsx(FieldLabel, { label: label, path: path, required: required }), _jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(true), children: "Edit as JSON" })] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), draft.rows.map((row, index) => {
|
|
38
|
+
const name = `URL filter ${index + 1}`;
|
|
39
|
+
return (_jsxs("fieldset", { className: "builder-where__row builder-where__row--pair", "aria-label": name, children: [_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: URL parameter`, placeholder: "URL parameter", value: row.param, onChange: (e) => change(index, { param: e.target.value }) }), fields.length > 0 ? (_jsx(Select, { "aria-label": `${name}: field`, placeholder: "Field", value: row.field || null, options: fieldOptions(row.field), onValueChange: (field) => change(index, { field: field ?? '' }) })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: field`, placeholder: "Field", value: row.field, onChange: (e) => change(index, { field: e.target.value }) })), _jsx(RemoveRowButton, { label: `Remove ${name.toLowerCase()}`, onClick: () => update(draft.rows.filter((_, i) => i !== index)) })] }, index));
|
|
40
|
+
}), _jsx(AddButton, { onClick: () => update([...draft.rows, { param: '', field: '' }]), children: "Add URL filter" })] }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RelatedMode } from './listOptions.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
/** The stored field name (`filterField`) and how it relates (`filterBy`). */
|
|
5
|
+
readonly field: unknown;
|
|
6
|
+
readonly mode: unknown;
|
|
7
|
+
/** Sets both props at once. `undefined` removes a prop. */
|
|
8
|
+
readonly onChange: (field: string | undefined, mode: RelatedMode | undefined) => void;
|
|
9
|
+
/** The slug of the listed collection. */
|
|
10
|
+
readonly collection?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A collection list's "Related to this page" (`admin.custom.builderRelated`): one select of the
|
|
14
|
+
* fields that relate the listed documents to the template's document, in words ("Categories links
|
|
15
|
+
* to this page"). It stores the same `filterField` + `filterBy` props as before. Outside a template
|
|
16
|
+
* there is no page document, so it shows only when a filter is already set.
|
|
17
|
+
*/
|
|
18
|
+
export declare function RelatedField({ label, field, mode, onChange, collection }: Props): import("react").JSX.Element | null;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldLabel } from '@payloadcms/ui';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { useRuntime } from '../runtime.js';
|
|
6
|
+
import { Select } from '../ui/Select.js';
|
|
7
|
+
import { useValue } from '../valueStore.js';
|
|
8
|
+
import { useCollectionFields } from './collectionFields.js';
|
|
9
|
+
import { parseRelatedKey, relatedChoice, relatedKey, relatedLabel, relatedOptions } from './listOptions.js';
|
|
10
|
+
/** "current" is the default mode, so it is not stored. */
|
|
11
|
+
const storedMode = (mode) => (mode === 'current' ? undefined : mode);
|
|
12
|
+
const MODE_OPTIONS = [
|
|
13
|
+
{ value: 'current', label: 'Its field links to this page' },
|
|
14
|
+
{ value: 'linked', label: 'This page links to it' },
|
|
15
|
+
{ value: 'shared', label: 'Same value as this page' },
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* A collection list's "Related to this page" (`admin.custom.builderRelated`): one select of the
|
|
19
|
+
* fields that relate the listed documents to the template's document, in words ("Categories links
|
|
20
|
+
* to this page"). It stores the same `filterField` + `filterBy` props as before. Outside a template
|
|
21
|
+
* there is no page document, so it shows only when a filter is already set.
|
|
22
|
+
*/
|
|
23
|
+
export function RelatedField({ label, field, mode, onChange, collection }) {
|
|
24
|
+
const runtime = useRuntime();
|
|
25
|
+
const template = useValue(runtime.template);
|
|
26
|
+
const target = template.isTemplate ? (template.target ?? undefined) : undefined;
|
|
27
|
+
const listedFields = useCollectionFields(collection);
|
|
28
|
+
const pageFields = useCollectionFields(target);
|
|
29
|
+
const options = useMemo(() => (collection && target ? relatedOptions({ slug: collection, fields: listedFields }, { slug: target, fields: pageFields }) : []), [collection, target, listedFields, pageFields]);
|
|
30
|
+
const current = relatedChoice(field, mode);
|
|
31
|
+
if (!target && !current)
|
|
32
|
+
return null;
|
|
33
|
+
const set = (next) => next ? onChange(next.field, storedMode(next.mode)) : onChange(undefined, undefined);
|
|
34
|
+
// The fields are unknown (no collection yet, or not in the config): the mode and the field name as text.
|
|
35
|
+
if (target && (listedFields.length === 0 || pageFields.length === 0)) {
|
|
36
|
+
const how = MODE_OPTIONS.some((o) => o.value === mode) ? mode : 'current';
|
|
37
|
+
return (_jsxs("div", { className: "field-type builder-related", children: [_jsx(FieldLabel, { as: "span", label: label }), _jsxs("div", { className: "builder-sort__row", children: [_jsx(Select, { "aria-label": `${label}: how`, value: how, options: MODE_OPTIONS, onValueChange: (next) => onChange(current?.field, storedMode((next ?? 'current'))) }), _jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${label}: field name`, placeholder: "Field name", value: current?.field ?? '', onChange: (e) => onChange(e.target.value.trim() || undefined, storedMode(how)) })] })] }));
|
|
38
|
+
}
|
|
39
|
+
const entries = options.map((o) => ({ value: relatedKey(o), label: o.label }));
|
|
40
|
+
if (current && !options.some((o) => relatedKey(o) === relatedKey(current))) {
|
|
41
|
+
entries.unshift({ value: relatedKey(current), label: relatedLabel(current.mode, current.field) });
|
|
42
|
+
}
|
|
43
|
+
return (_jsxs("div", { className: "field-type builder-related", children: [_jsx(FieldLabel, { as: "span", label: label }), _jsx(Select, { "aria-label": label, emptyLabel: "Not filtered", value: current ? relatedKey(current) : null, options: entries, onValueChange: (key) => set(parseRelatedKey(key)) }), !target && _jsx("p", { className: "builder-field-note", children: "Works only in a template." })] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
readonly label: string;
|
|
3
|
+
readonly value: unknown;
|
|
4
|
+
readonly onChange: (value: unknown) => void;
|
|
5
|
+
/** The slug of the listed collection, when known: its fields fill the field select. */
|
|
6
|
+
readonly collection?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A list's sort (`admin.custom.builderSort`): a field of the collection and a direction, or a
|
|
10
|
+
* random order. Stores the same text as before: "-publishedAt", "title" or "$random".
|
|
11
|
+
*/
|
|
12
|
+
export declare function SortField({ label, value, onChange, collection }: Props): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldLabel } from '@payloadcms/ui';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { Select } from '../ui/Select.js';
|
|
6
|
+
import { useCollectionFields } from './collectionFields.js';
|
|
7
|
+
import { directionLabels, parseSort, RANDOM_SORT, sortFieldOptions, sortValue } from './listOptions.js';
|
|
8
|
+
/**
|
|
9
|
+
* A list's sort (`admin.custom.builderSort`): a field of the collection and a direction, or a
|
|
10
|
+
* random order. Stores the same text as before: "-publishedAt", "title" or "$random".
|
|
11
|
+
*/
|
|
12
|
+
export function SortField({ label, value, onChange, collection }) {
|
|
13
|
+
const fields = useCollectionFields(collection);
|
|
14
|
+
const options = useMemo(() => sortFieldOptions(fields), [fields]);
|
|
15
|
+
const choice = parseSort(value);
|
|
16
|
+
const picked = choice && choice !== 'random' ? choice : null;
|
|
17
|
+
const known = picked ? options.find((o) => o.value === picked.field) : undefined;
|
|
18
|
+
const [ascending, descending] = directionLabels(known?.type);
|
|
19
|
+
const entries = options.map((o) => ({ value: o.value, label: o.label }));
|
|
20
|
+
// A stored field the collection does not list (typed by hand or by AI) stays choosable.
|
|
21
|
+
if (picked && !known)
|
|
22
|
+
entries.unshift({ value: picked.field, label: picked.field });
|
|
23
|
+
entries.push('separator', { value: RANDOM_SORT, label: 'Random order' });
|
|
24
|
+
const pick = (next) => {
|
|
25
|
+
if (!next)
|
|
26
|
+
return onChange(null);
|
|
27
|
+
if (next === RANDOM_SORT)
|
|
28
|
+
return onChange(RANDOM_SORT);
|
|
29
|
+
// Dates start with the newest, everything else from A or the lowest.
|
|
30
|
+
const type = options.find((o) => o.value === next)?.type;
|
|
31
|
+
onChange(sortValue({ field: next, descending: picked ? picked.descending : type === 'date' }));
|
|
32
|
+
};
|
|
33
|
+
return (_jsxs("div", { className: "field-type builder-sort", children: [_jsx(FieldLabel, { as: "span", label: label }), _jsxs("div", { className: "builder-sort__row", children: [_jsx(Select, { "aria-label": `${label}: field`, placeholder: "Default order", value: choice === 'random' ? RANDOM_SORT : (picked?.field ?? null), options: entries, onValueChange: pick }), picked && (_jsx(Select, { "aria-label": `${label}: direction`, value: picked.descending ? 'desc' : 'asc', options: [
|
|
34
|
+
{ value: 'asc', label: ascending },
|
|
35
|
+
{ value: 'desc', label: descending },
|
|
36
|
+
], onValueChange: (next) => onChange(sortValue({ field: picked.field, descending: next === 'desc' })) }))] })] }));
|
|
37
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type DataField } from '../../../core/fields.js';
|
|
2
|
+
import { type ConditionFieldOption, type ConditionSources } from './ConditionRows.js';
|
|
1
3
|
type Props = {
|
|
2
4
|
readonly label: string;
|
|
3
5
|
readonly description?: string;
|
|
@@ -7,11 +9,17 @@ type Props = {
|
|
|
7
9
|
readonly onChange: (value: unknown) => void;
|
|
8
10
|
/** The slug of the collection the query runs on, when known: its fields fill the field select. */
|
|
9
11
|
readonly collection?: string;
|
|
12
|
+
/** Value sources besides a fixed value: relative dates, page fields, URL parameters. */
|
|
13
|
+
readonly sources?: ConditionSources;
|
|
10
14
|
};
|
|
15
|
+
/** A collection field as a condition field: its label, type, options and related collection. */
|
|
16
|
+
export declare function whereFieldOption(field: DataField): ConditionFieldOption;
|
|
11
17
|
/**
|
|
12
|
-
* A Payload `where` query as rows:
|
|
13
|
-
* object as the JSON editor. A where the rows cannot
|
|
14
|
-
*
|
|
18
|
+
* A Payload `where` query as condition rows: rows in a group are AND-ed, groups are OR-ed
|
|
19
|
+
* (`{ or: [...] }`). Stores the same where object as the JSON editor. A where the rows cannot
|
|
20
|
+
* show (nested groups, unknown operators) opens as JSON, so nothing is lost. "Edit as JSON"
|
|
21
|
+
* switches to the JSON editor. Used by the collection list's `where` (`admin.custom.builderWhere`,
|
|
22
|
+
* through ListWhereField) and by the templates' conditions field.
|
|
15
23
|
*/
|
|
16
|
-
export declare function WhereField({ label, description, path, required, value, onChange, collection }: Props): import("react").JSX.Element;
|
|
24
|
+
export declare function WhereField({ label, description, path, required, value, onChange, collection, sources }: Props): import("react").JSX.Element;
|
|
17
25
|
export {};
|
|
@@ -1,67 +1,47 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { FieldLabel } from '@payloadcms/ui';
|
|
4
4
|
import { useMemo, useState } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { optionList, textOf } from '../../../core/fields.js';
|
|
6
|
+
import { useCollectionFields } from './collectionFields.js';
|
|
7
|
+
import { ConditionRows } from './ConditionRows.js';
|
|
7
8
|
import { JsonField } from './JsonField.js';
|
|
8
|
-
import {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
const OPERATOR_OPTIONS = WHERE_OPERATORS.map((value) => ({ value, label: OPERATOR_LABELS[value] }));
|
|
23
|
-
const YES_NO = [
|
|
24
|
-
{ value: 'true', label: 'yes' },
|
|
25
|
-
{ value: 'false', label: 'no' },
|
|
26
|
-
];
|
|
27
|
-
const editRows = (value) => (whereRows(value) ?? []).map((row) => ({ ...row, text: whereValueText(row.value) }));
|
|
9
|
+
import { groupsWhere, whereGroups, whereValueText } from './whereRows.js';
|
|
10
|
+
const editGroups = (value) => (whereGroups(value) ?? []).map((group) => group.map((row) => ({ ...row, text: whereValueText(row.value) })));
|
|
11
|
+
/** A collection field as a condition field: its label, type, options and related collection. */
|
|
12
|
+
export function whereFieldOption(field) {
|
|
13
|
+
const out = { path: field.name, label: textOf(field.label) ?? field.name, type: field.type };
|
|
14
|
+
if (field.hasMany)
|
|
15
|
+
out.hasMany = true;
|
|
16
|
+
if (field.relationTo !== undefined)
|
|
17
|
+
out.relationTo = field.relationTo;
|
|
18
|
+
if (field.type === 'select' || field.type === 'radio')
|
|
19
|
+
out.options = optionList(field);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
28
22
|
/**
|
|
29
|
-
* A Payload `where` query as rows:
|
|
30
|
-
* object as the JSON editor. A where the rows cannot
|
|
31
|
-
*
|
|
23
|
+
* A Payload `where` query as condition rows: rows in a group are AND-ed, groups are OR-ed
|
|
24
|
+
* (`{ or: [...] }`). Stores the same where object as the JSON editor. A where the rows cannot
|
|
25
|
+
* show (nested groups, unknown operators) opens as JSON, so nothing is lost. "Edit as JSON"
|
|
26
|
+
* switches to the JSON editor. Used by the collection list's `where` (`admin.custom.builderWhere`,
|
|
27
|
+
* through ListWhereField) and by the templates' conditions field.
|
|
32
28
|
*/
|
|
33
|
-
export function WhereField({ label, description, path, required, value, onChange, collection }) {
|
|
34
|
-
const
|
|
35
|
-
const fields = useMemo(() =>
|
|
36
|
-
const found = config.collections.find((c) => c.slug === collection);
|
|
37
|
-
return found ? dataFields(found.fields).filter((f) => f.type !== 'group' && f.type !== 'array' && f.type !== 'blocks') : [];
|
|
38
|
-
}, [config.collections, collection]);
|
|
29
|
+
export function WhereField({ label, description, path, required, value, onChange, collection, sources }) {
|
|
30
|
+
const collectionFields = useCollectionFields(collection);
|
|
31
|
+
const fields = useMemo(() => collectionFields.map(whereFieldOption), [collectionFields]);
|
|
39
32
|
const [json, setJson] = useState(false);
|
|
40
|
-
const [draft, setDraft] = useState(() => ({
|
|
33
|
+
const [draft, setDraft] = useState(() => ({ groups: editGroups(value), source: value }));
|
|
41
34
|
// The value changed from outside (undo, AI edit): show it. Our own edits come back as `source`.
|
|
42
35
|
if (value !== draft.source)
|
|
43
|
-
setDraft({
|
|
44
|
-
const fits =
|
|
36
|
+
setDraft({ groups: editGroups(value), source: value });
|
|
37
|
+
const fits = whereGroups(value) !== null;
|
|
45
38
|
if (json || !fits) {
|
|
46
|
-
return (_jsxs("div", { className: "builder-where", children: [_jsx(JsonField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value }), fits ? (_jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(false), children: "Edit as conditions" })) : (_jsx("p", { className: "builder-field-group__description", children: "
|
|
39
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsx(JsonField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value }), fits ? (_jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(false), children: "Edit as conditions" })) : (_jsx("p", { className: "builder-field-group__description", children: "Too complex for condition rows, so it opens as JSON." }))] }));
|
|
47
40
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setDraft({ rows, source: where });
|
|
41
|
+
const update = (groups) => {
|
|
42
|
+
const where = groupsWhere(groups);
|
|
43
|
+
setDraft({ groups, source: where });
|
|
52
44
|
onChange(where);
|
|
53
45
|
};
|
|
54
|
-
|
|
55
|
-
const fieldOptions = (current) => {
|
|
56
|
-
const options = fields.map((f) => ({ value: f.name, label: f.name }));
|
|
57
|
-
return current && !options.some((o) => o.value === current) ? [{ value: current, label: current }, ...options] : options;
|
|
58
|
-
};
|
|
59
|
-
return (_jsxs("div", { className: "builder-where", children: [_jsxs("div", { className: "builder-where__head", children: [_jsx(FieldLabel, { label: label, path: path, required: required }), _jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(true), children: "Edit as JSON" })] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), draft.rows.map((row, index) => {
|
|
60
|
-
const name = `Condition ${index + 1}`;
|
|
61
|
-
return (_jsxs("fieldset", { className: "builder-where__row", "aria-label": name, children: [fields.length > 0 ? (_jsx(Select, { "aria-label": `${name}: field`, placeholder: "Field", value: row.field || null, options: fieldOptions(row.field), onValueChange: (field) => change(index, { field: field ?? '', value: parseWhereValue(row.text, row.operator, typeOf(field ?? '')) }) })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: field`, placeholder: "Field", value: row.field, onChange: (e) => change(index, { field: e.target.value }) })), _jsx(Select, { "aria-label": `${name}: operator`, value: row.operator, options: OPERATOR_OPTIONS, onValueChange: (next) => {
|
|
62
|
-
const operator = (next ?? 'equals');
|
|
63
|
-
const converted = convertWhereValue(row, operator, typeOf(row.field));
|
|
64
|
-
change(index, { operator, value: converted, text: whereValueText(converted) });
|
|
65
|
-
} }), row.operator === 'exists' ? (_jsx(Select, { "aria-label": `${name}: value`, value: row.value === false ? 'false' : 'true', options: YES_NO, onValueChange: (next) => change(index, { value: next !== 'false', text: next ?? 'true' }) })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: value`, placeholder: row.operator === 'in' || row.operator === 'not_in' ? 'a, b, c' : 'Value', value: row.text, onChange: (e) => change(index, { text: e.target.value, value: parseWhereValue(e.target.value, row.operator, typeOf(row.field)) }) })), _jsx("button", { type: "button", className: "builder-where__remove", "aria-label": `Remove ${name.toLowerCase()}`, onClick: () => update(draft.rows.filter((_, i) => i !== index)), children: "\u00D7" })] }, index));
|
|
66
|
-
}), _jsx(Button, { buttonStyle: "secondary", icon: "plus", iconPosition: "left", iconStyle: "with-border", margin: false, onClick: () => update([...draft.rows, { field: '', operator: 'equals', value: '', text: '' }]), size: "small", children: "Add condition" })] }));
|
|
46
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsxs("div", { className: "builder-where__head", children: [_jsx(FieldLabel, { label: label, path: path, required: required }), _jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(true), children: "Edit as JSON" })] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), _jsx(ConditionRows, { groups: draft.groups, onChange: update, fields: fields, sources: sources, defaultOperator: "equals" })] }));
|
|
67
47
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DataField } from '../../../core/fields.js';
|
|
2
|
+
/**
|
|
3
|
+
* The fields of a collection that a query can filter on directly: its data fields without groups,
|
|
4
|
+
* arrays and blocks fields. Empty when the collection is unknown.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useCollectionFields(collection: string | undefined): DataField[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useConfig } from '@payloadcms/ui';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { dataFields } from '../../../core/fields.js';
|
|
5
|
+
/**
|
|
6
|
+
* The fields of a collection that a query can filter on directly: its data fields without groups,
|
|
7
|
+
* arrays and blocks fields. Empty when the collection is unknown.
|
|
8
|
+
*/
|
|
9
|
+
export function useCollectionFields(collection) {
|
|
10
|
+
const { config } = useConfig();
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
const found = config.collections.find((c) => c.slug === collection);
|
|
13
|
+
return found ? dataFields(found.fields).filter((f) => f.type !== 'group' && f.type !== 'array' && f.type !== 'blocks') : [];
|
|
14
|
+
}, [config.collections, collection]);
|
|
15
|
+
}
|