@plaudit/gutenberg-api-extensions 2.79.0 → 2.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/MoveError.js +10 -0
- package/dist/blocks/MoveError.js.map +1 -0
- package/{build → dist}/blocks/PathError.js +7 -3
- package/dist/blocks/PathError.js.map +1 -0
- package/{build → dist}/blocks/SNPFlexibleItemsListComponent.d.ts +1 -1
- package/dist/blocks/SNPFlexibleItemsListComponent.js +18 -0
- package/dist/blocks/SNPFlexibleItemsListComponent.js.map +1 -0
- package/{build → dist}/blocks/SNPGroupComponent.d.ts +2 -2
- package/dist/blocks/SNPGroupComponent.js +20 -0
- package/dist/blocks/SNPGroupComponent.js.map +1 -0
- package/{build → dist}/blocks/SNPListComponent.d.ts +1 -1
- package/dist/blocks/SNPListComponent.js +18 -0
- package/dist/blocks/SNPListComponent.js.map +1 -0
- package/dist/blocks/SNPTreeContext.js +14 -0
- package/dist/blocks/SNPTreeContext.js.map +1 -0
- package/dist/blocks/basic-custom-block-bindings-support.js +157 -0
- package/dist/blocks/basic-custom-block-bindings-support.js.map +1 -0
- package/dist/blocks/common-native-property-constructors.d.ts +13 -0
- package/{build → dist}/blocks/common-native-property-constructors.js +105 -151
- package/dist/blocks/common-native-property-constructors.js.map +1 -0
- package/{build → dist}/blocks/conditions.js +12 -7
- package/dist/blocks/conditions.js.map +1 -0
- package/dist/blocks/csnp-api.d.ts +166 -0
- package/dist/blocks/csnp-api.js +74 -0
- package/dist/blocks/csnp-api.js.map +1 -0
- package/{build → dist}/blocks/data-controller-manager.js +4 -1
- package/dist/blocks/data-controller-manager.js.map +1 -0
- package/{build → dist}/blocks/data-controller.js +74 -70
- package/dist/blocks/data-controller.js.map +1 -0
- package/{build → dist}/blocks/hooks/built-in-suspendable-option-protocols/select.js +14 -11
- package/dist/blocks/hooks/built-in-suspendable-option-protocols/select.js.map +1 -0
- package/{build → dist}/blocks/hooks/built-in-suspendable-option-protocols/settings.js +9 -6
- package/dist/blocks/hooks/built-in-suspendable-option-protocols/settings.js.map +1 -0
- package/{build → dist}/blocks/hooks/useSuspendableOptions.d.ts +1 -1
- package/{build → dist}/blocks/hooks/useSuspendableOptions.js +30 -23
- package/dist/blocks/hooks/useSuspendableOptions.js.map +1 -0
- package/dist/blocks/index.js +35 -0
- package/dist/blocks/index.js.map +1 -0
- package/{build → dist}/blocks/layered-styles-api.d.ts +2 -2
- package/{build → dist}/blocks/layered-styles-api.js +10 -6
- package/dist/blocks/layered-styles-api.js.map +1 -0
- package/{build → dist}/blocks/layered-styles-impl.js +14 -9
- package/dist/blocks/layered-styles-impl.js.map +1 -0
- package/{build → dist}/blocks/layout/LaidOutProperty.d.ts +1 -2
- package/dist/blocks/layout/LaidOutProperty.js +47 -0
- package/dist/blocks/layout/LaidOutProperty.js.map +1 -0
- package/dist/blocks/layout/LaidOutPropertyRow.js +15 -0
- package/dist/blocks/layout/LaidOutPropertyRow.js.map +1 -0
- package/{build → dist}/blocks/layout/NodeContext.d.ts +2 -2
- package/dist/blocks/layout/NodeContext.js +44 -0
- package/dist/blocks/layout/NodeContext.js.map +1 -0
- package/dist/blocks/layout/PanelRoot.js +29 -0
- package/dist/blocks/layout/PanelRoot.js.map +1 -0
- package/{build → dist}/blocks/layout/TabsRoot.js +16 -13
- package/dist/blocks/layout/TabsRoot.js.map +1 -0
- package/dist/blocks/layout/ToolsPanelContext.js +23 -0
- package/dist/blocks/layout/ToolsPanelContext.js.map +1 -0
- package/dist/blocks/shared-exportable-types.js +3 -0
- package/dist/blocks/shared-internal-types.js +3 -0
- package/{build → dist}/blocks/simple-block.d.ts +1 -1
- package/dist/blocks/simple-block.js +45 -0
- package/dist/blocks/simple-block.js.map +1 -0
- package/{build → dist}/blocks/simple-native-property-api.d.ts +1 -1
- package/{build → dist}/blocks/simple-native-property-api.js +16 -10
- package/dist/blocks/simple-native-property-api.js.map +1 -0
- package/{build → dist}/blocks/simple-native-property-impl.js +60 -55
- package/dist/blocks/simple-native-property-impl.js.map +1 -0
- package/{build → dist}/blocks/simple-native-property-internal-shared.js +6 -2
- package/dist/blocks/simple-native-property-internal-shared.js.map +1 -0
- package/{build → dist}/blocks/snp-api.d.ts +1 -0
- package/dist/blocks/snp-api.js +7 -0
- package/dist/blocks/snp-api.js.map +1 -0
- package/{build → dist}/blocks/snp-data-store.js +8 -4
- package/dist/blocks/snp-data-store.js.map +1 -0
- package/{build → dist}/blocks/utilities.d.ts +1 -1
- package/dist/blocks/utilities.js +79 -0
- package/dist/blocks/utilities.js.map +1 -0
- package/{build → dist}/controls/AsynchronousFormTokenField.d.ts +1 -1
- package/dist/controls/AsynchronousFormTokenField.js +36 -0
- package/dist/controls/AsynchronousFormTokenField.js.map +1 -0
- package/{build → dist}/controls/BaseSortableItemsControl.d.ts +3 -3
- package/dist/controls/BaseSortableItemsControl.js +25 -0
- package/dist/controls/BaseSortableItemsControl.js.map +1 -0
- package/{build → dist}/controls/ExtendedFormTokenField.d.ts +3 -3
- package/dist/controls/ExtendedFormTokenField.js +64 -0
- package/dist/controls/ExtendedFormTokenField.js.map +1 -0
- package/dist/controls/ExtendedPostPicker.js +28 -0
- package/dist/controls/ExtendedPostPicker.js.map +1 -0
- package/dist/controls/ExtendedRadioControl.d.ts +12 -0
- package/dist/controls/ExtendedRadioControl.js +33 -0
- package/dist/controls/ExtendedRadioControl.js.map +1 -0
- package/{build → dist}/controls/ExtendedTaxonomyPicker.d.ts +1 -1
- package/dist/controls/ExtendedTaxonomyPicker.js +71 -0
- package/dist/controls/ExtendedTaxonomyPicker.js.map +1 -0
- package/{build → dist}/controls/ExtendedTermPicker.d.ts +1 -1
- package/dist/controls/ExtendedTermPicker.js +33 -0
- package/dist/controls/ExtendedTermPicker.js.map +1 -0
- package/dist/controls/ExtendedTextareaControl.d.ts +12 -0
- package/{build → dist}/controls/ExtendedTextareaControl.js +15 -12
- package/dist/controls/ExtendedTextareaControl.js.map +1 -0
- package/dist/controls/ExtendedUserPicker.js +28 -0
- package/dist/controls/ExtendedUserPicker.js.map +1 -0
- package/{build → dist}/controls/FullSizeToggleControl.d.ts +6 -4
- package/dist/controls/FullSizeToggleControl.js +110 -0
- package/dist/controls/FullSizeToggleControl.js.map +1 -0
- package/{build → dist}/controls/ImageControl.d.ts +1 -1
- package/dist/controls/ImageControl.js +81 -0
- package/dist/controls/ImageControl.js.map +1 -0
- package/{build → dist}/controls/InspectorPanel.d.ts +4 -3
- package/dist/controls/InspectorPanel.js +29 -0
- package/dist/controls/InspectorPanel.js.map +1 -0
- package/{build → dist}/controls/LazySuggestionsComboboxControl.d.ts +5 -1
- package/dist/controls/LazySuggestionsComboboxControl.js +32 -0
- package/dist/controls/LazySuggestionsComboboxControl.js.map +1 -0
- package/{build → dist}/controls/MultiSelectControl.d.ts +1 -1
- package/dist/controls/MultiSelectControl.js +33 -0
- package/dist/controls/MultiSelectControl.js.map +1 -0
- package/{build → dist}/controls/PickOne.d.ts +1 -1
- package/dist/controls/PickOne.js +54 -0
- package/dist/controls/PickOne.js.map +1 -0
- package/{build → dist}/controls/PromisableComponent.d.ts +2 -2
- package/{build → dist}/controls/PromisableComponent.js +14 -11
- package/dist/controls/PromisableComponent.js.map +1 -0
- package/{build → dist}/controls/ProperLinkControl.d.ts +1 -1
- package/dist/controls/ProperLinkControl.js +59 -0
- package/dist/controls/ProperLinkControl.js.map +1 -0
- package/dist/controls/SimpleToggle.js +11 -0
- package/dist/controls/SimpleToggle.js.map +1 -0
- package/dist/controls/SortableFlexibleItemsControl.js +18 -0
- package/dist/controls/SortableFlexibleItemsControl.js.map +1 -0
- package/dist/controls/SortableItemsControl.js +15 -0
- package/dist/controls/SortableItemsControl.js.map +1 -0
- package/{build → dist}/controls/basicNumericallyIdedItemPicker.d.ts +1 -1
- package/dist/controls/basicNumericallyIdedItemPicker.js +37 -0
- package/dist/controls/basicNumericallyIdedItemPicker.js.map +1 -0
- package/{build → dist}/controls/hooks/useImprovedTokenManager.d.ts +7 -5
- package/{build → dist}/controls/hooks/useImprovedTokenManager.js +21 -15
- package/dist/controls/hooks/useImprovedTokenManager.js.map +1 -0
- package/{build → dist}/controls/hooks/useMultiSingleConversionLayer.d.ts +1 -1
- package/dist/controls/hooks/useMultiSingleConversionLayer.js +14 -0
- package/dist/controls/hooks/useMultiSingleConversionLayer.js.map +1 -0
- package/dist/controls/hooks/useNonRenderingCounter.js +9 -0
- package/dist/controls/hooks/useNonRenderingCounter.js.map +1 -0
- package/{build → dist}/controls/hooks/useOutputMemoizingFilter.js +7 -4
- package/dist/controls/hooks/useOutputMemoizingFilter.js.map +1 -0
- package/{build → dist}/controls/hooks/useSortableItemsModel.js +14 -11
- package/dist/controls/hooks/useSortableItemsModel.js.map +1 -0
- package/{build → dist}/controls/hooks/useSuggestions.js +16 -13
- package/dist/controls/hooks/useSuggestions.js.map +1 -0
- package/{build → dist}/controls/hooks/useTokenManager.d.ts +5 -3
- package/{build → dist}/controls/hooks/useTokenManager.js +37 -34
- package/dist/controls/hooks/useTokenManager.js.map +1 -0
- package/dist/controls/index.js +41 -0
- package/dist/controls/index.js.map +1 -0
- package/{build → dist}/controls/shared.js +18 -8
- package/dist/controls/shared.js.map +1 -0
- package/dist/controls/types.js +3 -0
- package/dist/editor/post-featured-image.js +125 -0
- package/dist/editor/post-featured-image.js.map +1 -0
- package/dist/editor/simple-gutenberg-endpoints-api.js +26 -0
- package/dist/editor/simple-gutenberg-endpoints-api.js.map +1 -0
- package/{build → dist}/editor/simple-gutenberg-endpoints-impl.js +24 -17
- package/dist/editor/simple-gutenberg-endpoints-impl.js.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.js +27 -0
- package/dist/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.js.map +1 -0
- package/{build → dist}/lib/gutenberg-api-extensions-state/general-logic.js +12 -8
- package/dist/lib/gutenberg-api-extensions-state/general-logic.js.map +1 -0
- package/{build → dist}/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js +10 -6
- package/dist/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js.map +1 -0
- package/{build → dist}/lib/gutenberg-api-extensions-state/snp-logic.js +33 -26
- package/dist/lib/gutenberg-api-extensions-state/snp-logic.js.map +1 -0
- package/{build → dist}/lib/gutenberg-api-extensions-state.d.ts +2 -2
- package/dist/lib/gutenberg-api-extensions-state.js +52 -0
- package/dist/lib/gutenberg-api-extensions-state.js.map +1 -0
- package/{build → dist}/lib/helpers.d.ts +3 -3
- package/{build → dist}/lib/helpers.js +13 -6
- package/dist/lib/helpers.js.map +1 -0
- package/dist/lib/plaudit-icons/column-1.js +6 -0
- package/dist/lib/plaudit-icons/column-1.js.map +1 -0
- package/dist/lib/plaudit-icons/column-2.js +6 -0
- package/dist/lib/plaudit-icons/column-2.js.map +1 -0
- package/dist/lib/plaudit-icons/column-3.js +6 -0
- package/dist/lib/plaudit-icons/column-3.js.map +1 -0
- package/dist/lib/plaudit-icons/placement-center.js +6 -0
- package/dist/lib/plaudit-icons/placement-center.js.map +1 -0
- package/dist/lib/plaudit-icons/placement-end.js +6 -0
- package/dist/lib/plaudit-icons/placement-end.js.map +1 -0
- package/dist/lib/plaudit-icons/placement-start.js +6 -0
- package/dist/lib/plaudit-icons/placement-start.js.map +1 -0
- package/dist/lib/plaudit-icons/placement-stretch.js +6 -0
- package/dist/lib/plaudit-icons/placement-stretch.js.map +1 -0
- package/dist/lib/plaudit-icons/plaudit-icon.js +6 -0
- package/dist/lib/plaudit-icons/plaudit-icon.js.map +1 -0
- package/dist/lib/plaudit-icons/reusable-block-marker.js +6 -0
- package/{build → dist}/lib/plaudit-icons/reusable-block-marker.js.map +1 -1
- package/dist/lib/plaudit-icons.js +29 -0
- package/dist/lib/plaudit-icons.js.map +1 -0
- package/{build → dist}/lib/suspense/promise-handlers.js +16 -7
- package/dist/lib/suspense/promise-handlers.js.map +1 -0
- package/{build → dist}/lib/suspense.d.ts +2 -2
- package/dist/lib/suspense.js +31 -0
- package/dist/lib/suspense.js.map +1 -0
- package/{build → dist}/lib/useful-types.d.ts +4 -1
- package/dist/lib/useful-types.js +11 -0
- package/dist/lib/useful-types.js.map +1 -0
- package/package.json +22 -30
- package/src/blocks/MoveError.ts +7 -0
- package/src/blocks/PathError.ts +18 -0
- package/src/blocks/SNPFlexibleItemsListComponent.tsx +30 -0
- package/src/blocks/SNPGroupComponent.tsx +38 -0
- package/src/blocks/SNPListComponent.tsx +25 -0
- package/src/blocks/SNPTreeContext.tsx +13 -0
- package/src/blocks/basic-custom-block-bindings-support.tsx +243 -0
- package/src/blocks/common-native-property-constructors.tsx +877 -0
- package/src/blocks/conditions.ts +260 -0
- package/src/blocks/csnp-api.ts +214 -0
- package/src/blocks/data-controller-manager.ts +50 -0
- package/src/blocks/data-controller.ts +736 -0
- package/src/blocks/hooks/built-in-suspendable-option-protocols/select.ts +51 -0
- package/src/blocks/hooks/built-in-suspendable-option-protocols/settings.ts +70 -0
- package/src/blocks/hooks/useSuspendableOptions.ts +123 -0
- package/src/blocks/index.ts +20 -0
- package/src/blocks/layered-styles-api.ts +142 -0
- package/src/blocks/layered-styles-impl.ts +94 -0
- package/src/blocks/layout/LaidOutProperty.tsx +72 -0
- package/src/blocks/layout/LaidOutPropertyRow.tsx +22 -0
- package/src/blocks/layout/NodeContext.tsx +54 -0
- package/src/blocks/layout/PanelRoot.tsx +33 -0
- package/src/blocks/layout/TabsRoot.tsx +56 -0
- package/src/blocks/layout/ToolsPanelContext.tsx +22 -0
- package/src/blocks/shared-exportable-types.ts +6 -0
- package/src/blocks/shared-internal-types.ts +18 -0
- package/src/blocks/simple-block.tsx +74 -0
- package/src/blocks/simple-native-property-api.ts +170 -0
- package/src/blocks/simple-native-property-impl.tsx +329 -0
- package/src/blocks/simple-native-property-internal-shared.ts +46 -0
- package/src/blocks/snp-api.ts +5 -0
- package/src/blocks/snp-data-store.ts +66 -0
- package/src/blocks/utilities.ts +80 -0
- package/src/controls/AsynchronousFormTokenField.tsx +85 -0
- package/src/controls/BaseSortableItemsControl.tsx +84 -0
- package/src/controls/ExtendedFormTokenField.tsx +121 -0
- package/src/controls/ExtendedPostPicker.ts +57 -0
- package/src/controls/ExtendedRadioControl.tsx +107 -0
- package/src/controls/ExtendedTaxonomyPicker.tsx +100 -0
- package/src/controls/ExtendedTermPicker.tsx +62 -0
- package/src/controls/ExtendedTextareaControl.tsx +65 -0
- package/src/controls/ExtendedUserPicker.ts +56 -0
- package/src/controls/FullSizeToggleControl.tsx +94 -0
- package/src/controls/ImageControl.tsx +143 -0
- package/src/controls/InspectorPanel.tsx +37 -0
- package/src/controls/LazySuggestionsComboboxControl.tsx +62 -0
- package/src/controls/MultiSelectControl.tsx +59 -0
- package/src/controls/PickOne.tsx +84 -0
- package/src/controls/PromisableComponent.tsx +56 -0
- package/src/controls/ProperLinkControl.tsx +93 -0
- package/src/controls/SimpleToggle.tsx +9 -0
- package/src/controls/SortableFlexibleItemsControl.tsx +35 -0
- package/src/controls/SortableItemsControl.tsx +18 -0
- package/src/controls/basicNumericallyIdedItemPicker.tsx +76 -0
- package/src/controls/hooks/useImprovedTokenManager.ts +157 -0
- package/src/controls/hooks/useMultiSingleConversionLayer.ts +17 -0
- package/src/controls/hooks/useNonRenderingCounter.ts +6 -0
- package/src/controls/hooks/useOutputMemoizingFilter.ts +16 -0
- package/src/controls/hooks/useSortableItemsModel.ts +196 -0
- package/src/controls/hooks/useSuggestions.ts +91 -0
- package/src/controls/hooks/useTokenManager.ts +177 -0
- package/{build/controls/index.js → src/controls/index.ts} +3 -2
- package/src/controls/shared.ts +50 -0
- package/src/controls/types.ts +18 -0
- package/src/editor/post-featured-image.tsx +161 -0
- package/src/editor/simple-gutenberg-endpoints-api.ts +31 -0
- package/src/editor/simple-gutenberg-endpoints-impl.ts +119 -0
- package/src/index.ts +32 -0
- package/src/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.ts +34 -0
- package/src/lib/gutenberg-api-extensions-state/general-logic.ts +41 -0
- package/src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts +42 -0
- package/src/lib/gutenberg-api-extensions-state/snp-logic.ts +240 -0
- package/src/lib/gutenberg-api-extensions-state.ts +69 -0
- package/src/lib/helpers.ts +114 -0
- package/src/lib/plaudit-icons/column-1.tsx +6 -0
- package/src/lib/plaudit-icons/column-2.tsx +6 -0
- package/src/lib/plaudit-icons/column-3.tsx +6 -0
- package/src/lib/plaudit-icons/placement-center.tsx +3 -0
- package/src/lib/plaudit-icons/placement-end.tsx +3 -0
- package/src/lib/plaudit-icons/placement-start.tsx +3 -0
- package/src/lib/plaudit-icons/placement-stretch.tsx +3 -0
- package/src/lib/plaudit-icons/plaudit-icon.tsx +4 -0
- package/src/lib/plaudit-icons/reusable-block-marker.tsx +3 -0
- package/{build/lib/plaudit-icons.js → src/lib/plaudit-icons.ts} +1 -1
- package/src/lib/suspense/promise-handlers.ts +72 -0
- package/src/lib/suspense.tsx +18 -0
- package/src/lib/useful-types.ts +65 -0
- package/build/blocks/MoveError.js +0 -6
- package/build/blocks/MoveError.js.map +0 -1
- package/build/blocks/PathError.js.map +0 -1
- package/build/blocks/SNPFlexibleItemsListComponent.js +0 -15
- package/build/blocks/SNPFlexibleItemsListComponent.js.map +0 -1
- package/build/blocks/SNPGroupComponent.js +0 -17
- package/build/blocks/SNPGroupComponent.js.map +0 -1
- package/build/blocks/SNPListComponent.js +0 -15
- package/build/blocks/SNPListComponent.js.map +0 -1
- package/build/blocks/SNPTreeContext.js +0 -10
- package/build/blocks/SNPTreeContext.js.map +0 -1
- package/build/blocks/basic-custom-block-bindings-support.js +0 -150
- package/build/blocks/basic-custom-block-bindings-support.js.map +0 -1
- package/build/blocks/common-native-property-constructors.d.ts +0 -208
- package/build/blocks/common-native-property-constructors.js.map +0 -1
- package/build/blocks/conditions.js.map +0 -1
- package/build/blocks/data-controller-manager.js.map +0 -1
- package/build/blocks/data-controller.js.map +0 -1
- package/build/blocks/hooks/built-in-suspendable-option-protocols/select.js.map +0 -1
- package/build/blocks/hooks/built-in-suspendable-option-protocols/settings.js.map +0 -1
- package/build/blocks/hooks/useSuspendableOptions.js.map +0 -1
- package/build/blocks/index.js +0 -15
- package/build/blocks/index.js.map +0 -1
- package/build/blocks/layered-styles-api.js.map +0 -1
- package/build/blocks/layered-styles-impl.js.map +0 -1
- package/build/blocks/layout/LaidOutProperty.js +0 -44
- package/build/blocks/layout/LaidOutProperty.js.map +0 -1
- package/build/blocks/layout/LaidOutPropertyRow.js +0 -12
- package/build/blocks/layout/LaidOutPropertyRow.js.map +0 -1
- package/build/blocks/layout/NodeContext.js +0 -37
- package/build/blocks/layout/NodeContext.js.map +0 -1
- package/build/blocks/layout/PanelRoot.js +0 -26
- package/build/blocks/layout/PanelRoot.js.map +0 -1
- package/build/blocks/layout/TabsRoot.js.map +0 -1
- package/build/blocks/layout/ToolsPanelContext.js +0 -18
- package/build/blocks/layout/ToolsPanelContext.js.map +0 -1
- package/build/blocks/shared-exportable-types.js +0 -2
- package/build/blocks/shared-internal-types.js +0 -2
- package/build/blocks/simple-block.js +0 -41
- package/build/blocks/simple-block.js.map +0 -1
- package/build/blocks/simple-native-property-api.js.map +0 -1
- package/build/blocks/simple-native-property-impl.js.map +0 -1
- package/build/blocks/simple-native-property-internal-shared.js.map +0 -1
- package/build/blocks/snp-api.js +0 -2
- package/build/blocks/snp-api.js.map +0 -1
- package/build/blocks/snp-data-store.js.map +0 -1
- package/build/blocks/utilities.js +0 -67
- package/build/blocks/utilities.js.map +0 -1
- package/build/controls/AsynchronousFormTokenField.js +0 -32
- package/build/controls/AsynchronousFormTokenField.js.map +0 -1
- package/build/controls/BaseSortableItemsControl.js +0 -22
- package/build/controls/BaseSortableItemsControl.js.map +0 -1
- package/build/controls/ExtendedFormTokenField.js +0 -58
- package/build/controls/ExtendedFormTokenField.js.map +0 -1
- package/build/controls/ExtendedPostPicker.js +0 -22
- package/build/controls/ExtendedPostPicker.js.map +0 -1
- package/build/controls/ExtendedRadioControl.d.ts +0 -10
- package/build/controls/ExtendedRadioControl.js +0 -30
- package/build/controls/ExtendedRadioControl.js.map +0 -1
- package/build/controls/ExtendedTaxonomyPicker.js +0 -68
- package/build/controls/ExtendedTaxonomyPicker.js.map +0 -1
- package/build/controls/ExtendedTermPicker.js +0 -27
- package/build/controls/ExtendedTermPicker.js.map +0 -1
- package/build/controls/ExtendedTextareaControl.d.ts +0 -14
- package/build/controls/ExtendedTextareaControl.js.map +0 -1
- package/build/controls/ExtendedUserPicker.js +0 -22
- package/build/controls/ExtendedUserPicker.js.map +0 -1
- package/build/controls/FullSizeToggleControl.js +0 -70
- package/build/controls/FullSizeToggleControl.js.map +0 -1
- package/build/controls/ImageControl.js +0 -76
- package/build/controls/ImageControl.js.map +0 -1
- package/build/controls/InspectorPanel.js +0 -26
- package/build/controls/InspectorPanel.js.map +0 -1
- package/build/controls/LazySuggestionsComboboxControl.js +0 -29
- package/build/controls/LazySuggestionsComboboxControl.js.map +0 -1
- package/build/controls/MultiSelectControl.js +0 -30
- package/build/controls/MultiSelectControl.js.map +0 -1
- package/build/controls/PickOne.js +0 -48
- package/build/controls/PickOne.js.map +0 -1
- package/build/controls/PromisableComponent.js.map +0 -1
- package/build/controls/ProperLinkControl.js +0 -56
- package/build/controls/ProperLinkControl.js.map +0 -1
- package/build/controls/SimpleToggle.js +0 -8
- package/build/controls/SimpleToggle.js.map +0 -1
- package/build/controls/SortableFlexibleItemsControl.js +0 -15
- package/build/controls/SortableFlexibleItemsControl.js.map +0 -1
- package/build/controls/SortableItemsControl.js +0 -12
- package/build/controls/SortableItemsControl.js.map +0 -1
- package/build/controls/basicNumericallyIdedItemPicker.js +0 -34
- package/build/controls/basicNumericallyIdedItemPicker.js.map +0 -1
- package/build/controls/hooks/useImprovedTokenManager.js.map +0 -1
- package/build/controls/hooks/useMultiSingleConversionLayer.js +0 -11
- package/build/controls/hooks/useMultiSingleConversionLayer.js.map +0 -1
- package/build/controls/hooks/useNonRenderingCounter.js +0 -6
- package/build/controls/hooks/useNonRenderingCounter.js.map +0 -1
- package/build/controls/hooks/useOutputMemoizingFilter.js.map +0 -1
- package/build/controls/hooks/useSortableItemsModel.js.map +0 -1
- package/build/controls/hooks/useSuggestions.js.map +0 -1
- package/build/controls/hooks/useTokenManager.js.map +0 -1
- package/build/controls/index.js.map +0 -1
- package/build/controls/shared.js.map +0 -1
- package/build/controls/types.js +0 -2
- package/build/editor/post-featured-image.js +0 -122
- package/build/editor/post-featured-image.js.map +0 -1
- package/build/editor/simple-gutenberg-endpoints-api.js +0 -22
- package/build/editor/simple-gutenberg-endpoints-api.js.map +0 -1
- package/build/editor/simple-gutenberg-endpoints-impl.js.map +0 -1
- package/build/index.js +0 -22
- package/build/index.js.map +0 -1
- package/build/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.js +0 -23
- package/build/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.js.map +0 -1
- package/build/lib/gutenberg-api-extensions-state/general-logic.js.map +0 -1
- package/build/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js.map +0 -1
- package/build/lib/gutenberg-api-extensions-state/snp-logic.js.map +0 -1
- package/build/lib/gutenberg-api-extensions-state.js +0 -48
- package/build/lib/gutenberg-api-extensions-state.js.map +0 -1
- package/build/lib/helpers.js.map +0 -1
- package/build/lib/plaudit-icons/column-1.js +0 -3
- package/build/lib/plaudit-icons/column-1.js.map +0 -1
- package/build/lib/plaudit-icons/column-2.js +0 -3
- package/build/lib/plaudit-icons/column-2.js.map +0 -1
- package/build/lib/plaudit-icons/column-3.js +0 -3
- package/build/lib/plaudit-icons/column-3.js.map +0 -1
- package/build/lib/plaudit-icons/placement-center.js +0 -3
- package/build/lib/plaudit-icons/placement-center.js.map +0 -1
- package/build/lib/plaudit-icons/placement-end.js +0 -3
- package/build/lib/plaudit-icons/placement-end.js.map +0 -1
- package/build/lib/plaudit-icons/placement-start.js +0 -3
- package/build/lib/plaudit-icons/placement-start.js.map +0 -1
- package/build/lib/plaudit-icons/placement-stretch.js +0 -3
- package/build/lib/plaudit-icons/placement-stretch.js.map +0 -1
- package/build/lib/plaudit-icons/plaudit-icon.js +0 -3
- package/build/lib/plaudit-icons/plaudit-icon.js.map +0 -1
- package/build/lib/plaudit-icons/reusable-block-marker.js +0 -3
- package/build/lib/plaudit-icons.js.map +0 -1
- package/build/lib/suspense/promise-handlers.js.map +0 -1
- package/build/lib/suspense.js +0 -14
- package/build/lib/suspense.js.map +0 -1
- package/build/lib/useful-types.js +0 -7
- package/build/lib/useful-types.js.map +0 -1
- /package/{build → dist}/blocks/MoveError.d.ts +0 -0
- /package/{build → dist}/blocks/PathError.d.ts +0 -0
- /package/{build → dist}/blocks/SNPTreeContext.d.ts +0 -0
- /package/{build → dist}/blocks/basic-custom-block-bindings-support.d.ts +0 -0
- /package/{build → dist}/blocks/conditions.d.ts +0 -0
- /package/{build → dist}/blocks/data-controller-manager.d.ts +0 -0
- /package/{build → dist}/blocks/data-controller.d.ts +0 -0
- /package/{build → dist}/blocks/hooks/built-in-suspendable-option-protocols/select.d.ts +0 -0
- /package/{build → dist}/blocks/hooks/built-in-suspendable-option-protocols/settings.d.ts +0 -0
- /package/{build → dist}/blocks/index.d.ts +0 -0
- /package/{build → dist}/blocks/layered-styles-impl.d.ts +0 -0
- /package/{build → dist}/blocks/layout/LaidOutPropertyRow.d.ts +0 -0
- /package/{build → dist}/blocks/layout/PanelRoot.d.ts +0 -0
- /package/{build → dist}/blocks/layout/TabsRoot.d.ts +0 -0
- /package/{build → dist}/blocks/layout/ToolsPanelContext.d.ts +0 -0
- /package/{build → dist}/blocks/shared-exportable-types.d.ts +0 -0
- /package/{build → dist}/blocks/shared-exportable-types.js.map +0 -0
- /package/{build → dist}/blocks/shared-internal-types.d.ts +0 -0
- /package/{build → dist}/blocks/shared-internal-types.js.map +0 -0
- /package/{build → dist}/blocks/simple-native-property-impl.d.ts +0 -0
- /package/{build → dist}/blocks/simple-native-property-internal-shared.d.ts +0 -0
- /package/{build → dist}/blocks/snp-data-store.d.ts +0 -0
- /package/{build → dist}/controls/ExtendedPostPicker.d.ts +0 -0
- /package/{build → dist}/controls/ExtendedUserPicker.d.ts +0 -0
- /package/{build → dist}/controls/SimpleToggle.d.ts +0 -0
- /package/{build → dist}/controls/SortableFlexibleItemsControl.d.ts +0 -0
- /package/{build → dist}/controls/SortableItemsControl.d.ts +0 -0
- /package/{build → dist}/controls/hooks/useNonRenderingCounter.d.ts +0 -0
- /package/{build → dist}/controls/hooks/useOutputMemoizingFilter.d.ts +0 -0
- /package/{build → dist}/controls/hooks/useSortableItemsModel.d.ts +0 -0
- /package/{build → dist}/controls/hooks/useSuggestions.d.ts +0 -0
- /package/{build → dist}/controls/index.d.ts +0 -0
- /package/{build → dist}/controls/shared.d.ts +0 -0
- /package/{build → dist}/controls/types.d.ts +0 -0
- /package/{build → dist}/controls/types.js.map +0 -0
- /package/{build → dist}/editor/post-featured-image.d.ts +0 -0
- /package/{build → dist}/editor/simple-gutenberg-endpoints-api.d.ts +0 -0
- /package/{build → dist}/editor/simple-gutenberg-endpoints-impl.d.ts +0 -0
- /package/{build → dist}/index.d.ts +0 -0
- /package/{build → dist}/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.d.ts +0 -0
- /package/{build → dist}/lib/gutenberg-api-extensions-state/general-logic.d.ts +0 -0
- /package/{build → dist}/lib/gutenberg-api-extensions-state/layered-block-styles-logic.d.ts +0 -0
- /package/{build → dist}/lib/gutenberg-api-extensions-state/snp-logic.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/column-1.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/column-2.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/column-3.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/placement-center.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/placement-end.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/placement-start.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/placement-stretch.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/plaudit-icon.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons/reusable-block-marker.d.ts +0 -0
- /package/{build → dist}/lib/plaudit-icons.d.ts +0 -0
- /package/{build → dist}/lib/suspense/promise-handlers.d.ts +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import {createHigherOrderComponent} from "@wordpress/compose";
|
|
2
|
+
import {dispatch, select} from "@wordpress/data";
|
|
3
|
+
import {useEffect, useMemo} from "@wordpress/element";
|
|
4
|
+
import {addAction, addFilter} from "@wordpress/hooks";
|
|
5
|
+
|
|
6
|
+
import {produce} from "immer";
|
|
7
|
+
|
|
8
|
+
import {useDataController, walkToNodeInValue} from "./data-controller";
|
|
9
|
+
import {DataControllerManager, createDataControllerManager} from "./data-controller-manager";
|
|
10
|
+
import {extractStyleLayerValueFromAttributes, LayeredStylesDataStore} from "./layered-styles-impl";
|
|
11
|
+
import {TabsRoot} from "./layout/TabsRoot";
|
|
12
|
+
import {PanelRoot} from "./layout/PanelRoot";
|
|
13
|
+
import {ActualBEPAttrs, ActualBlockEditProps, ActualBlockListBlockProps, isBlockJsonNativePropsConfig, RegisterBlockAttrs} from "../lib/useful-types";
|
|
14
|
+
import {PathError} from "./PathError";
|
|
15
|
+
import type {DataController, DataStore, HydratedSimpleNativeProperty, InspectorPanelGroup} from "./simple-native-property-api";
|
|
16
|
+
import type {HydratedSimpleNativePanel, PerBlockExtraPropTransforms, PreppedSimpleNativePanelsAndTabs} from "./simple-native-property-internal-shared";
|
|
17
|
+
import {SNPDataStore} from "./snp-data-store";
|
|
18
|
+
import {SNPTreeContext} from "./SNPTreeContext";
|
|
19
|
+
|
|
20
|
+
class AttributeDataStore extends SNPDataStore {
|
|
21
|
+
public getAttribute(name: string): any {
|
|
22
|
+
return this.blockEditProps.attributes[name];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public setAttribute(name: string, value: any) {
|
|
26
|
+
this.blockEditProps.setAttributes(name === 'className' ? {className: value?.toString()} : {[name]: value});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type ActualBlockSaveProps = {[key: Exclude<string, 'className'|'style'>]: unknown|undefined, className?: string|undefined, style?: Record<string, unknown>};
|
|
31
|
+
|
|
32
|
+
export function installSimpleNativePropertiesSupport() {
|
|
33
|
+
if (installSimpleNativePropertiesSupport.called) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
installSimpleNativePropertiesSupport.called = true;
|
|
37
|
+
|
|
38
|
+
const dataControllerManager = createDataControllerManager();
|
|
39
|
+
|
|
40
|
+
const registeredBlocks = new Map<string, boolean>();
|
|
41
|
+
addFilter('blocks.registerBlockType', 'plaudit/gutenberg-api-extensions/simple-native-properties', (atts: RegisterBlockAttrs<Record<string, any>>) => {
|
|
42
|
+
let isPlauditNative: boolean;
|
|
43
|
+
if (registeredBlocks.has(atts.name)) {
|
|
44
|
+
isPlauditNative = registeredBlocks.get(atts.name)!;
|
|
45
|
+
} else {
|
|
46
|
+
dispatch('plaudit/gutenberg-api-extensions').recordBaselineBlockAttrs(atts);
|
|
47
|
+
if ((isPlauditNative = isBlockJsonNativePropsConfig(atts.plaudit)) && atts.plaudit.properties !== undefined
|
|
48
|
+
&& (Array.isArray(atts.plaudit.properties) ? atts.plaudit.properties.length : atts.plaudit.properties)
|
|
49
|
+
) {
|
|
50
|
+
dispatch('plaudit/gutenberg-api-extensions').addProperties(atts.name, atts.plaudit.properties);
|
|
51
|
+
}
|
|
52
|
+
registeredBlocks.set(atts.name, isPlauditNative);
|
|
53
|
+
}
|
|
54
|
+
//TODO: Figure out some way to re-register a block when its attributes are changed
|
|
55
|
+
const blockSimpleNativePanelsAndTabs = select('plaudit/gutenberg-api-extensions').preppedProperties(atts.name);
|
|
56
|
+
if (blockSimpleNativePanelsAndTabs) {
|
|
57
|
+
const extraPropTransforms = select('plaudit/gutenberg-api-extensions').extraPropTransforms(atts.name) ?? {};
|
|
58
|
+
const attsAttributes = {...atts.attributes};
|
|
59
|
+
if (isPlauditNative && Object.values(extraPropTransforms).some(cfg => cfg.styleProperty)) {
|
|
60
|
+
attsAttributes['__plaudit/computed-style-attr'] = {type: "object"};
|
|
61
|
+
}
|
|
62
|
+
const injectableProperties: Record<string, any> = {};
|
|
63
|
+
for (const panel of blockSimpleNativePanelsAndTabs.panels) {
|
|
64
|
+
attachSNPsInPanel(panel[1].properties, injectableProperties);
|
|
65
|
+
}
|
|
66
|
+
for (const tabGroup of Object.values(blockSimpleNativePanelsAndTabs.tabs)) {
|
|
67
|
+
for (const tab of Object.values(tabGroup[1])) {
|
|
68
|
+
for (const item of tab.items) {
|
|
69
|
+
if ('properties' in item) {
|
|
70
|
+
attachSNPsInPanel(item.properties, injectableProperties);
|
|
71
|
+
} else if (Array.isArray(item)) {
|
|
72
|
+
attachSNPsInPanel(item, injectableProperties);
|
|
73
|
+
} else {
|
|
74
|
+
attachSNP(item, injectableProperties);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const [name, config] of Object.entries(injectableProperties)) {
|
|
80
|
+
attsAttributes[name] = config;
|
|
81
|
+
}
|
|
82
|
+
return {...atts, attributes: attsAttributes};
|
|
83
|
+
}
|
|
84
|
+
return atts;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
addFilter('editor.BlockEdit', 'plaudit/gutenberg-api-extensions/simple-native-properties',
|
|
88
|
+
createHigherOrderComponent(BlockEdit => (blockEditProps: ActualBlockEditProps) => {
|
|
89
|
+
const blockSimpleNativePanelsAndTabs = select('plaudit/gutenberg-api-extensions').preppedProperties(blockEditProps.name);
|
|
90
|
+
if (!blockSimpleNativePanelsAndTabs) {
|
|
91
|
+
return <BlockEdit {...blockEditProps} />;
|
|
92
|
+
}
|
|
93
|
+
const selectedEditor = select("core/block-editor");
|
|
94
|
+
if (selectedEditor.getBlockParentsByBlockName(blockEditProps.clientId, "core/block")?.length) {
|
|
95
|
+
// If we have a core/block ancestor, then we can't be edited and attempting to self-edit will cause a crash
|
|
96
|
+
return <BlockEdit {...blockEditProps} />;
|
|
97
|
+
}
|
|
98
|
+
return <DataControllerInitializationIsolator bep={blockEditProps} dcm={dataControllerManager} BlockEdit={BlockEdit} snpPanelsAndTabs={blockSimpleNativePanelsAndTabs} />;
|
|
99
|
+
}, 'plauditGutenbergApiExtensionsSimpleNativeProperties'));
|
|
100
|
+
|
|
101
|
+
addAction('plaudit.gutenbergApiExtensions.simpleNativeProperties.afterWrite', 'plaudit/gutenberg-api-extensions/simple-native-properties',
|
|
102
|
+
(value: unknown, definition: HydratedSimpleNativeProperty, dataStore: DataStore) => {
|
|
103
|
+
if ("styleProperty" in definition && definition.styleProperty) {
|
|
104
|
+
const computedStyleAttr: {[key: string]: { property: string, value: string, className: string }} = dataStore.getValue('__plaudit/computed-style-attr') ?? {};
|
|
105
|
+
const valueStr = value?.toString();
|
|
106
|
+
if (computedStyleAttr[definition.name]?.value !== valueStr) {
|
|
107
|
+
if (valueStr?.length) {
|
|
108
|
+
dataStore.setValue('__plaudit/computed-style-attr', {
|
|
109
|
+
...computedStyleAttr,
|
|
110
|
+
[definition.name]: {property: definition.styleProperty, value: valueStr, className: makeHasPropClassName(definition.name)}
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
const entries = Object.entries(computedStyleAttr)
|
|
114
|
+
.filter(([key]) => key !== definition.name);
|
|
115
|
+
dataStore.setValue('__plaudit/computed-style-attr', entries.length ? Object.fromEntries(entries) : undefined);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
addFilter('editor.BlockListBlock', 'plaudit/gutenberg-api-extensions/simple-native-properties',
|
|
122
|
+
createHigherOrderComponent(BlockListBlock => (props: ActualBlockListBlockProps) => {
|
|
123
|
+
const wrapperProps: {className?: string, style?: Record<string, unknown>} = {...props.wrapperProps};
|
|
124
|
+
const extraPropTransforms = select('plaudit/gutenberg-api-extensions').computedExtraPropTransforms(props.name);
|
|
125
|
+
if (!extraPropTransforms || !extraPropTransforms.appliesInEditor) {
|
|
126
|
+
const dataController = dataControllerManager.getDataController(props.clientId);
|
|
127
|
+
if (!dataController) {
|
|
128
|
+
return <BlockListBlock {...props} />;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const hasValidationError = dataController.hasValidationErrors();
|
|
132
|
+
dataControllerManager.notifyOfValidationErrorStatusChange(props.clientId, hasValidationError);
|
|
133
|
+
dataController.dispatch({type: "checkConditions"}); // We don't want to wrap this in a useEffect because this function is already only called when necessary.
|
|
134
|
+
|
|
135
|
+
if (hasValidationError) {
|
|
136
|
+
//TODO: Should I set isValid?
|
|
137
|
+
wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} has-validation-error` : "has-validation-error";
|
|
138
|
+
return <BlockListBlock {...props} wrapperProps={wrapperProps} />;
|
|
139
|
+
}
|
|
140
|
+
return <BlockListBlock {...props} />;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const dataController = dataControllerManager.getDataController(props.clientId);
|
|
144
|
+
if (!dataController) {
|
|
145
|
+
return <BlockListBlock
|
|
146
|
+
{...props}
|
|
147
|
+
wrapperProps={applyExtraPropTransforms(extraPropTransforms.transforms, props.attributes, wrapperProps)}
|
|
148
|
+
/>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const hasValidationError = dataController.hasValidationErrors();
|
|
152
|
+
dataControllerManager.notifyOfValidationErrorStatusChange(props.clientId, hasValidationError);
|
|
153
|
+
dataController.dispatch({type: "checkConditions"}); // We don't want to wrap this in a useEffect because this function is already only called when necessary.
|
|
154
|
+
|
|
155
|
+
if (hasValidationError) {
|
|
156
|
+
//TODO: Should I set isValid?
|
|
157
|
+
wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} has-validation-error` : "has-validation-error";
|
|
158
|
+
}
|
|
159
|
+
return (
|
|
160
|
+
<BlockListBlock
|
|
161
|
+
{...props}
|
|
162
|
+
wrapperProps={applyExtraPropTransforms(extraPropTransforms.transforms, props.attributes, wrapperProps)}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
}, 'plauditGutenbergApiExtensionsSimpleNativeWrapperMarkup'));
|
|
166
|
+
|
|
167
|
+
addFilter('blocks.getSaveContent.extraProps', 'plaudit/gutenberg-api-extensions/simple-native-properties',
|
|
168
|
+
(props: ActualBlockSaveProps, blockType: RegisterBlockAttrs, attributes: ActualBEPAttrs) => {
|
|
169
|
+
if (isBlockJsonNativePropsConfig(blockType.plaudit)) {
|
|
170
|
+
return props;
|
|
171
|
+
}
|
|
172
|
+
const extraPropTransforms = select('plaudit/gutenberg-api-extensions').computedExtraPropTransforms(blockType.name);
|
|
173
|
+
|
|
174
|
+
return extraPropTransforms && extraPropTransforms.appliesInEditor ? produce(props, draft => {
|
|
175
|
+
applyExtraPropTransforms(extraPropTransforms.transforms, attributes, draft);
|
|
176
|
+
}) : props;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export namespace installSimpleNativePropertiesSupport {
|
|
180
|
+
export let called: boolean = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type DataControllerInitializationIsolatorProps = {bep: ActualBlockEditProps, dcm: DataControllerManager, snpPanelsAndTabs: PreppedSimpleNativePanelsAndTabs, BlockEdit: any};
|
|
184
|
+
function DataControllerInitializationIsolator({bep, dcm, snpPanelsAndTabs, BlockEdit}: DataControllerInitializationIsolatorProps) {
|
|
185
|
+
const dataController = useDataController(bep.clientId);
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
dcm.addDataController(bep.clientId, dataController);
|
|
188
|
+
return () => dcm.removeDataController(bep.clientId);
|
|
189
|
+
}, [dataController, bep.clientId]);
|
|
190
|
+
|
|
191
|
+
return <>
|
|
192
|
+
<BlockEdit {...bep} />
|
|
193
|
+
<SNPPropsWrapper blockEditProps={bep} blockSimpleNativePanelsAndTabs={snpPanelsAndTabs} dataController={dataController} />
|
|
194
|
+
</>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function applyExtraPropTransforms(
|
|
198
|
+
extraPropTransforms: PerBlockExtraPropTransforms['transforms'], attributes: ActualBEPAttrs, draft: {className?: string, style?: Record<string, unknown>}
|
|
199
|
+
) {
|
|
200
|
+
for (const [propPath, propTransform] of extraPropTransforms) {
|
|
201
|
+
let value: any;
|
|
202
|
+
try {
|
|
203
|
+
value = propTransform.forLayeredStyles ? extractStyleLayerValueFromAttributes(attributes, propPath[0]) : walkToNodeInValue(attributes[propPath[0]], propPath);
|
|
204
|
+
} catch (e) {
|
|
205
|
+
if (e instanceof PathError) {
|
|
206
|
+
value = undefined;
|
|
207
|
+
} else {
|
|
208
|
+
console.error("Encountered an error while applying extra props transforms:", e);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (propTransform.styleProperty) {
|
|
214
|
+
const hasPropNameClass = makeHasPropClassName(propTransform.propName);
|
|
215
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
216
|
+
const styleValue = typeof value === 'number' ? value.toString() : value.trim();
|
|
217
|
+
if (styleValue.length) {
|
|
218
|
+
if (draft.style) {
|
|
219
|
+
draft.style[propTransform.styleProperty] = styleValue;
|
|
220
|
+
} else {
|
|
221
|
+
draft.style = {[propTransform.styleProperty]: styleValue};
|
|
222
|
+
}
|
|
223
|
+
if (!draft.className) {
|
|
224
|
+
draft.className = hasPropNameClass;
|
|
225
|
+
} else if (!draft.className.split(/\s+/).includes(hasPropNameClass)) {
|
|
226
|
+
draft.className = draft.className + " " + hasPropNameClass;
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
if (draft.style) {
|
|
230
|
+
delete draft.style[propTransform.styleProperty];
|
|
231
|
+
}
|
|
232
|
+
if (draft.className) {
|
|
233
|
+
draft.className = draft.className.split(/\s+/).filter(cn => cn !== hasPropNameClass).join(" ");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} else if (value === undefined || value === null) {
|
|
237
|
+
if (draft.style) {
|
|
238
|
+
delete draft.style[propTransform.styleProperty];
|
|
239
|
+
}
|
|
240
|
+
if (draft.className) {
|
|
241
|
+
draft.className = draft.className.split(/\s+/).filter(cn => cn !== hasPropNameClass).join(" ");
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
console.error(`Encountered a SNP that had a styleProperty set but evaluated to a ${typeof value}.`, "Prop path:", propPath.join("."));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return draft;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function makeDataStoreForPanelOrTab(blockEditProps: ActualBlockEditProps, group: string|undefined, attributeCache: Record<string, any>) {
|
|
252
|
+
return group === 'layered-styles' ? new LayeredStylesDataStore(blockEditProps, attributeCache) : new AttributeDataStore(blockEditProps, attributeCache);
|
|
253
|
+
}
|
|
254
|
+
type SNPPropsWrapperProps = {blockSimpleNativePanelsAndTabs: PreppedSimpleNativePanelsAndTabs, blockEditProps: ActualBlockEditProps, dataController: DataController};
|
|
255
|
+
function SNPPropsWrapper({blockSimpleNativePanelsAndTabs, blockEditProps, dataController}: SNPPropsWrapperProps) {
|
|
256
|
+
useMemo(() => {
|
|
257
|
+
const attributeCache = Object.create(null);
|
|
258
|
+
for (const panel of blockSimpleNativePanelsAndTabs.panels) {
|
|
259
|
+
const dataStore = makeDataStoreForPanelOrTab(blockEditProps, panel[1].group, attributeCache);
|
|
260
|
+
dataController.addProperties(panel[1].properties, dataStore, true);
|
|
261
|
+
}
|
|
262
|
+
for (const [group, [_, tabs]] of Object.entries(blockSimpleNativePanelsAndTabs.tabs)) {
|
|
263
|
+
const dataStore = makeDataStoreForPanelOrTab(blockEditProps, group, attributeCache);
|
|
264
|
+
for (const tab of Object.values(tabs)) {
|
|
265
|
+
for (const panel of tab.items) {
|
|
266
|
+
dataController.addProperties(panel.properties, dataStore, true);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
dataController.dispatch({type: "checkConditions"});
|
|
271
|
+
dataController.dispatch({type: "validateNodes"});
|
|
272
|
+
dataController.dispatch({type: "commitBatchAddedProperties"});
|
|
273
|
+
}, [blockSimpleNativePanelsAndTabs, dataController]); // We don't depend on blockEditProps here - that is handled by the following useEffect
|
|
274
|
+
|
|
275
|
+
// We have to reattach dataStores in the useMemo segment in order for Panel- and Tab-level conditions to work
|
|
276
|
+
useMemo(() => {
|
|
277
|
+
const attributeCache = Object.create(null);
|
|
278
|
+
for (const dataStore of dataController.getAllDataStores()) {
|
|
279
|
+
dataStore.reattach(blockEditProps, attributeCache);
|
|
280
|
+
}
|
|
281
|
+
}, [dataController.getAllDataStores(), blockEditProps]);
|
|
282
|
+
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
//TODO: This is a temporary patch. The proper solution is to subscribe to the block-editor redux store and use that to determine when properties have changed.
|
|
285
|
+
if (dataController.getWasChangedByManagedControl()) {
|
|
286
|
+
dataController.markManagedControlChangeHandled();
|
|
287
|
+
} else{
|
|
288
|
+
dataController.dispatch({type: "checkConditions"});
|
|
289
|
+
dataController.dispatch({type: "validateNodes"});
|
|
290
|
+
}
|
|
291
|
+
}, [dataController.getAllDataStores(), blockEditProps]);
|
|
292
|
+
|
|
293
|
+
//TODO: Hook into block-focus change listener and run validation on focus change
|
|
294
|
+
return <SNPTreeContext.Provider value={dataController}>
|
|
295
|
+
{...blockSimpleNativePanelsAndTabs.panels.map(panel => <PanelRoot key={panel[0]} panel={panel[1]} />)}
|
|
296
|
+
{...Object.entries(blockSimpleNativePanelsAndTabs.tabs).map(
|
|
297
|
+
([group, tabs]) => <TabsRoot key={tabs[0]} tabs={tabs[1]} tabGroupName={group as InspectorPanelGroup} />)}
|
|
298
|
+
</SNPTreeContext.Provider>;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function attachSNP(property: HydratedSimpleNativeProperty, injectableProperties: Record<string, any>) {
|
|
302
|
+
injectableProperties[property.name] = {type: property.type, default: property.alwaysStore !== false ? undefined : property.default};
|
|
303
|
+
if ('enum' in property) {
|
|
304
|
+
injectableProperties[property.name].enum = property.enum;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function attachSNPsInPanel(properties: HydratedSimpleNativePanel['properties'], injectableProperties: Record<string, any>) {
|
|
309
|
+
for (const property of properties) {
|
|
310
|
+
if (Array.isArray(property)) {
|
|
311
|
+
for (const prop of property) {
|
|
312
|
+
attachSNP(prop, injectableProperties);
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
attachSNP(property, injectableProperties);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function makeHasPropClassName(propName: string) {
|
|
321
|
+
return "has-" + kebabCase(propName);
|
|
322
|
+
}
|
|
323
|
+
const kebabCaseRegexes = [/([a-z])([A-Z])/g, /[\s_]+/g] as const;
|
|
324
|
+
export function kebabCase(value: string) {
|
|
325
|
+
return value
|
|
326
|
+
.replace(kebabCaseRegexes[0], "$1-$2")
|
|
327
|
+
.replace(kebabCaseRegexes[1], '-')
|
|
328
|
+
.toLowerCase();
|
|
329
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type {HydratedSimpleNativeProperty, InspectorPanelGroup, SimpleNativePanel, SimpleNativeTab} from "./simple-native-property-api";
|
|
2
|
+
|
|
3
|
+
export type ExtraPropTransformConfig = {propName: string, forLayeredStyles: boolean, styleProperty?: string};
|
|
4
|
+
export type ExtraPropTransformsConfig = {[key: string]: ExtraPropTransformConfig};
|
|
5
|
+
export type PerBlockExtraPropTransforms = {transforms: [[string, ...string[]], ExtraPropTransformConfig][], appliesInEditor: boolean};
|
|
6
|
+
|
|
7
|
+
export type HydratedSimpleNativeTabItem = Omit<HydratedSimpleNativePanel, 'group'>;
|
|
8
|
+
export type HydratedSimpleNativeTab = Omit<SimpleNativeTab, 'items'>&{items: HydratedSimpleNativeTabItem[]};
|
|
9
|
+
export type HydratedSimpleNativeTabGroup = {[tabTitle: string]: HydratedSimpleNativeTab};
|
|
10
|
+
export type HydratedSimpleNativePanel = Omit<SimpleNativePanel, 'properties'>&{properties: HydratedLaidOutProperties};
|
|
11
|
+
|
|
12
|
+
export type HydratedLaidOutProperties = (HydratedSimpleNativeProperty|HydratedSimpleNativeProperty[])[];
|
|
13
|
+
|
|
14
|
+
export type HydratedInspectorPanelGroupedTabs = {[key in InspectorPanelGroup]?: [string, HydratedSimpleNativeTabGroup]};
|
|
15
|
+
export type PreppedSimpleNativePanelsAndTabs = {panels: [string, HydratedSimpleNativePanel][], tabs: HydratedInspectorPanelGroupedTabs};
|
|
16
|
+
|
|
17
|
+
export function isRootLevelPanelGroup(panelGroup: string|undefined) {
|
|
18
|
+
return panelGroup === undefined || panelGroup === "default" || panelGroup === "advanced" || panelGroup === "settings" || panelGroup === "styles";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function buildDefaultValueFromDefinition(definition: HydratedSimpleNativeProperty|undefined, requireNonNullValueOnObject = true): any {
|
|
22
|
+
if (definition === undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
} else if (definition.default !== undefined) {
|
|
25
|
+
return structuredClone(definition.default);
|
|
26
|
+
}
|
|
27
|
+
const typedChildren = Array.isArray(definition.children) ? definition.children : undefined;
|
|
28
|
+
if (!typedChildren?.length) {
|
|
29
|
+
return structuredClone(definition.default);
|
|
30
|
+
} else if (definition.type === 'array') {
|
|
31
|
+
return [];
|
|
32
|
+
} else if (definition.type !== 'object') {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const res = Object.fromEntries(typedChildren.map(def => [def.name, buildDefaultValueFromDefinition(def)]));
|
|
37
|
+
if (requireNonNullValueOnObject) {
|
|
38
|
+
for (const value of Object.values(res)) {
|
|
39
|
+
if (value !== undefined) {
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type {ActualBEPAttrs, ActualBlockEditProps, ActualBlockListBlockProps, ActualBlockSaveProps, BlockJsonNativePropsConfig, RegisterBlockAttrs, NonEmptyArray} from "../lib/useful-types";
|
|
2
|
+
export {isBlockJsonNativePropsConfig, arrayIsNotEmpty} from "../lib/useful-types";
|
|
3
|
+
export type {CSNPConfig} from "./csnp-api";
|
|
4
|
+
export type * from "./common-native-property-constructors";
|
|
5
|
+
export type * from "./simple-native-property-api";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type {ActualBlockEditProps} from "../lib/useful-types";
|
|
2
|
+
import type {DataStore, HydratedSimpleNativeProperty} from "./simple-native-property-api";
|
|
3
|
+
import {buildDefaultValueFromDefinition} from "./simple-native-property-internal-shared";
|
|
4
|
+
|
|
5
|
+
export abstract class SNPDataStore implements DataStore<ActualBlockEditProps> {
|
|
6
|
+
private readonly managedPropertyNames: {[propertyName in string]: true};
|
|
7
|
+
|
|
8
|
+
public constructor(
|
|
9
|
+
protected explicitBlockEditProps: ActualBlockEditProps,
|
|
10
|
+
private attributeCache: Record<string, any>
|
|
11
|
+
) {
|
|
12
|
+
this.managedPropertyNames = Object.create(null);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get blockEditProps() {
|
|
16
|
+
return this.explicitBlockEditProps;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getValue(attr: string): any {
|
|
20
|
+
if (attr in this.attributeCache) {
|
|
21
|
+
return this.attributeCache[attr];
|
|
22
|
+
}
|
|
23
|
+
const existingValue = this.getAttribute(attr);
|
|
24
|
+
return this.attributeCache[attr] = existingValue;
|
|
25
|
+
}
|
|
26
|
+
setValue(attr: string, value: any) {
|
|
27
|
+
this.attributeCache[attr] = value;
|
|
28
|
+
return this.setAttribute(attr, value);
|
|
29
|
+
}
|
|
30
|
+
handlesProperty(name: string): boolean {
|
|
31
|
+
return name in this.managedPropertyNames;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
reattach(explicitBlockEditProps: ActualBlockEditProps, attributeCache: Record<string, any>) {
|
|
35
|
+
if (this.explicitBlockEditProps !== explicitBlockEditProps) { // If the block's properties haven't changed, there's no reason to clear the attribute cache
|
|
36
|
+
this.explicitBlockEditProps = explicitBlockEditProps;
|
|
37
|
+
this.attributeCache = attributeCache;
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected abstract getAttribute(name: string): any;
|
|
43
|
+
protected abstract setAttribute(name: string, value: any): void;
|
|
44
|
+
|
|
45
|
+
protected getCachedValue(attr: string) {
|
|
46
|
+
return this.attributeCache[attr];
|
|
47
|
+
}
|
|
48
|
+
protected hasCachedValue(attr: string) {
|
|
49
|
+
return attr in this.attributeCache;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addProperty(property: HydratedSimpleNativeProperty, writeThroughOnUndefined = true) {
|
|
53
|
+
if (this.managedPropertyNames[property.name]) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (this.getAttribute(property.name) === undefined) {
|
|
57
|
+
if (writeThroughOnUndefined) {
|
|
58
|
+
this.setValue(property.name, buildDefaultValueFromDefinition(property));
|
|
59
|
+
} else {
|
|
60
|
+
this.attributeCache[property.name] = buildDefaultValueFromDefinition(property);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.managedPropertyNames[property.name] = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {type BlockStyle, type BlockVariation, registerBlockStyle, registerBlockVariation, unregisterBlockStyle, unregisterBlockVariation} from "@wordpress/blocks";
|
|
2
|
+
import {store as realBlockEditorStore} from "@wordpress/block-editor";
|
|
3
|
+
import type * as BlockEditorActions from "@wordpress/block-editor/store/actions";
|
|
4
|
+
import type * as BlockEditorSelectors from "@wordpress/block-editor/store/selectors";
|
|
5
|
+
import type {ReduxStoreConfig, StoreDescriptor} from "@wordpress/data/types";
|
|
6
|
+
import domReady from "@wordpress/dom-ready";
|
|
7
|
+
|
|
8
|
+
import type {PairNormalizedPickableOptions} from "../controls";
|
|
9
|
+
|
|
10
|
+
export function registerBlockStyles(blockName: string|string[], ...blockStyles: BlockStyle[]) {
|
|
11
|
+
domReady(() => {
|
|
12
|
+
forStringOrStrings(blockName, bn => {
|
|
13
|
+
for (const blockStyle of blockStyles) {
|
|
14
|
+
registerBlockStyle(bn, blockStyle);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
if (Array.isArray(blockName)) {
|
|
18
|
+
for (const bn of blockName) {
|
|
19
|
+
for (const blockStyle of blockStyles) {
|
|
20
|
+
registerBlockStyle(bn, blockStyle);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
for (const blockStyle of blockStyles) {
|
|
25
|
+
registerBlockStyle(blockName, blockStyle);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function unregisterBlockStyles(blockName: string|string[], ...blockStyleNames: string[]) {
|
|
31
|
+
domReady(() => {
|
|
32
|
+
forStringOrStrings(blockName, bn => {
|
|
33
|
+
for (const blockStyleName of blockStyleNames) {
|
|
34
|
+
unregisterBlockStyle(bn, blockStyleName);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function registerBlockVariations(blockName: string, ...blockVariations: BlockVariation[]) {
|
|
41
|
+
domReady(() => {
|
|
42
|
+
forStringOrStrings(blockName, bn => registerBlockVariation(bn, blockVariations));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export function unregisterBlockVariations(blockName: string, ...blockVariationNames: string[]) {
|
|
46
|
+
domReady(() => {
|
|
47
|
+
forStringOrStrings(blockName, bn => unregisterBlockVariation(bn, blockVariationNames));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function convertToSelectControlOptions(response: unknown): PairNormalizedPickableOptions<string> {
|
|
52
|
+
if (response === null || response === undefined) {
|
|
53
|
+
return [];
|
|
54
|
+
} else if (typeof response === 'object') {
|
|
55
|
+
return (Array.isArray(response) ? response : Object.entries(response)).toSorted(([a], [b]) => a.localeCompare(b));
|
|
56
|
+
} else {
|
|
57
|
+
console.warn("An invalid response type was passed to convertToSelectControlOptions:", response);
|
|
58
|
+
return [[String(response), String(response)]];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type AddArgument<FirstArg, Fn extends (...args: any[]) => any> =
|
|
63
|
+
Fn extends (...arg: [...infer PrevArg]) => infer Return
|
|
64
|
+
? (...args: [FirstArg, ...PrevArg]) => Return
|
|
65
|
+
: never;
|
|
66
|
+
type SelectorInflater<T extends {[name: string]: (...args: any[]) => any}> = {[name in keyof T]: AddArgument<any, T[name]>};
|
|
67
|
+
export interface BlockEditorStoreDescriptor extends StoreDescriptor<ReduxStoreConfig<any, typeof BlockEditorActions, SelectorInflater<typeof BlockEditorSelectors>>> {
|
|
68
|
+
name: "core/block-editor";
|
|
69
|
+
}
|
|
70
|
+
export const blockEditorStore = realBlockEditorStore as BlockEditorStoreDescriptor;
|
|
71
|
+
|
|
72
|
+
export function forStringOrStrings(stringOrStrings: string|string[], action: (string: string) => void) {
|
|
73
|
+
if (Array.isArray(stringOrStrings)) {
|
|
74
|
+
for (const string of stringOrStrings) {
|
|
75
|
+
action(string);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
action(stringOrStrings);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {Spinner, FormTokenField} from '@wordpress/components';
|
|
2
|
+
import {useCallback} from "@wordpress/element";
|
|
3
|
+
import {__} from "@wordpress/i18n";
|
|
4
|
+
|
|
5
|
+
import type {SNPControlSlots} from "../blocks";
|
|
6
|
+
import {useMultiSingleConversionLayer} from "./hooks/useMultiSingleConversionLayer";
|
|
7
|
+
import {useSuggestions} from "./hooks/useSuggestions";
|
|
8
|
+
import {useTokenManager} from "./hooks/useTokenManager";
|
|
9
|
+
import type {TokenItem} from "../lib/useful-types";
|
|
10
|
+
|
|
11
|
+
// The strange values correspond to the literals that are expected by TokenItem.status, which allows the assignment code to be cleaner
|
|
12
|
+
export const enum ValidationState {
|
|
13
|
+
Valid = 'success',
|
|
14
|
+
Invalid = 'error',
|
|
15
|
+
Validating = 'validating',
|
|
16
|
+
Waiting = 'waiting'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type AsynchronousFormTokenFieldPropsBase = {
|
|
20
|
+
label?: string;
|
|
21
|
+
help?: string;
|
|
22
|
+
|
|
23
|
+
validationQuery(tokens: string[]): Promise<Array<TokenItem>>;
|
|
24
|
+
suggestionQuery(input: string): Promise<Array<string>>;
|
|
25
|
+
makeTokenFromSuggestion(suggestion: string): TokenItem;
|
|
26
|
+
validator?: (value: string) => boolean;
|
|
27
|
+
expandOnFocus?: boolean;
|
|
28
|
+
}&Partial<Pick<SNPControlSlots, 'Messages'>>;
|
|
29
|
+
type AsynchronousFormTokenFieldPropsSingle = AsynchronousFormTokenFieldPropsBase&{
|
|
30
|
+
value?: string;
|
|
31
|
+
onChange: (value: string) => void;
|
|
32
|
+
multiple: false;
|
|
33
|
+
};
|
|
34
|
+
type AsynchronousFormTokenFieldPropsMultiple = AsynchronousFormTokenFieldPropsBase&{
|
|
35
|
+
value?: string[];
|
|
36
|
+
onChange: (value: string[]) => void;
|
|
37
|
+
multiple?: true|undefined;
|
|
38
|
+
};
|
|
39
|
+
export type AsynchronousFormTokenFieldProps = AsynchronousFormTokenFieldPropsSingle|AsynchronousFormTokenFieldPropsMultiple;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated use ExtendedFormTokenField instead
|
|
43
|
+
*/
|
|
44
|
+
export function AsynchronousFormTokenField(props: AsynchronousFormTokenFieldProps) {
|
|
45
|
+
const {help, expandOnFocus = false} = props;
|
|
46
|
+
|
|
47
|
+
const [value, setValue] = useMultiSingleConversionLayer(props.value, props.onChange, props.makeTokenFromSuggestion, props.multiple);
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
currentTokens, dispatchValueUpdate, hasValidationError, isInitializing, isValidating, tokenTitleMappings
|
|
51
|
+
} = useTokenManager(value, setValue, props.validationQuery, props.makeTokenFromSuggestion);
|
|
52
|
+
const {
|
|
53
|
+
hasLoadingError, isLoading, suggestions, input, setInput
|
|
54
|
+
} = useSuggestions(undefined, {expandOnFocus, getSuggestions: props.suggestionQuery});
|
|
55
|
+
|
|
56
|
+
const displayTransform = useCallback((token: string) => tokenTitleMappings[token] ?? token, [tokenTitleMappings]);
|
|
57
|
+
const onFocus = useCallback(() => setInput(input), [input]);
|
|
58
|
+
|
|
59
|
+
if (isInitializing) {
|
|
60
|
+
return <Spinner />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//TODO: If focus is in field but user hasn't started typing, show a message telling them to start typing
|
|
64
|
+
return <>
|
|
65
|
+
<FormTokenField
|
|
66
|
+
value={currentTokens}
|
|
67
|
+
label={props.label}
|
|
68
|
+
placeholder="Start typing to see suggestions"
|
|
69
|
+
suggestions={suggestions}
|
|
70
|
+
onChange={dispatchValueUpdate}
|
|
71
|
+
maxLength={props.multiple === false ? 1 : undefined}
|
|
72
|
+
__experimentalValidateInput={props.validator}
|
|
73
|
+
__experimentalAutoSelectFirstMatch={true}
|
|
74
|
+
__experimentalExpandOnFocus={expandOnFocus}
|
|
75
|
+
displayTransform={displayTransform}
|
|
76
|
+
onInputChange={setInput}
|
|
77
|
+
onFocus={onFocus}
|
|
78
|
+
/>
|
|
79
|
+
{help && <div><span className="components-form-token-field__help">{help}</span></div>}
|
|
80
|
+
{hasLoadingError && <div><Spinner /><span className="components-form-token-field__help">{__("An Error Occurred While Loading Suggestions")}</span></div>}
|
|
81
|
+
{isLoading && <div><Spinner /><span className="components-form-token-field__help">{__("Updating Suggestions")}</span></div>}
|
|
82
|
+
{hasValidationError && <div><Spinner /><span className="components-form-token-field__help">{__("An Error Occurred While Validating")}</span></div>}
|
|
83
|
+
{isValidating && <div><Spinner /><span className="components-form-token-field__help">{__("Validating")}</span></div>}
|
|
84
|
+
</>;
|
|
85
|
+
}
|