@wordpress/block-editor 12.17.0 → 12.18.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/CHANGELOG.md +4 -0
- package/README.md +32 -0
- package/build/components/block-draggable/index.js +11 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-edit/context.js +3 -1
- package/build/components/block-edit/context.js.map +1 -1
- package/build/components/block-edit/index.js +4 -2
- package/build/components/block-edit/index.js.map +1 -1
- package/build/components/block-editing-mode/index.js +6 -3
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-inspector/index.js +5 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +4 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +9 -5
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.js +30 -4
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/private-block-context.js +1 -1
- package/build/components/block-list/private-block-context.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/toolbar.js +8 -2
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +15 -3
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-preview/auto.js +1 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +3 -2
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js +12 -1
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/index.js +119 -90
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +10 -3
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +7 -1
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/border-panel.js +5 -14
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +7 -1
- package/build/components/global-styles/effects-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +3 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +31 -14
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/iframe/get-compatibility-styles.js +99 -0
- package/build/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build/components/iframe/index.js +2 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +16 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +16 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/link-control/link-preview.js +30 -26
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -9
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block-contents.js +3 -1
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block.js +10 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +29 -8
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +100 -32
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +52 -4
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +2 -2
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-block-indexes.js +30 -0
- package/build/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build/components/list-view/use-list-view-drop-zone.js +56 -5
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/list-view/utils.js +92 -0
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/provider/index.js +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/recursion-provider/index.js +21 -0
- package/build/components/recursion-provider/index.js.map +1 -1
- package/build/components/rich-text/index.js +30 -6
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +9 -9
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +30 -7
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +50 -8
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/hooks/block-hooks.js +5 -14
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/content-lock-ui.js +17 -42
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/effects.js +66 -0
- package/build/hooks/effects.js.map +1 -0
- package/build/hooks/index.js +15 -2
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +13 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/style.js +6 -2
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/supports.js +2 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.native.js +2 -2
- package/build/hooks/typography.native.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +115 -0
- package/build/hooks/use-bindings-attributes.js.map +1 -0
- package/build/hooks/use-shadow-props.js +46 -0
- package/build/hooks/use-shadow-props.js.map +1 -0
- package/build/hooks/utils.js +11 -7
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +10 -6
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +37 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +60 -9
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +44 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +27 -0
- package/build/store/resolvers.js.map +1 -0
- package/build/store/selectors.js +94 -56
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +5 -26
- package/build/store/utils.js.map +1 -1
- package/build/utils/index.js +0 -16
- package/build/utils/index.js.map +1 -1
- package/build/utils/math.js +13 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/object.js +17 -0
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +37 -27
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +11 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-edit/context.js +1 -0
- package/build-module/components/block-edit/context.js.map +1 -1
- package/build-module/components/block-edit/index.js +5 -3
- package/build-module/components/block-edit/index.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +7 -4
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +6 -5
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +11 -7
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.js +31 -5
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/private-block-context.js +1 -1
- package/build-module/components/block-list/private-block-context.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +8 -2
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +15 -3
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-preview/auto.js +3 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +3 -2
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js +12 -1
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/index.js +116 -86
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +10 -3
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +7 -1
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +5 -14
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +7 -1
- package/build-module/components/global-styles/effects-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +3 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +32 -15
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/iframe/get-compatibility-styles.js +93 -0
- package/build-module/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build-module/components/iframe/index.js +2 -3
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +32 -28
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -8
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +3 -1
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block.js +10 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +30 -9
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +99 -32
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +54 -6
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +2 -2
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-block-indexes.js +23 -0
- package/build-module/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build-module/components/list-view/use-list-view-drop-zone.js +58 -7
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/list-view/utils.js +91 -0
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/provider/index.js +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/recursion-provider/index.js +17 -0
- package/build-module/components/recursion-provider/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +30 -6
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +9 -9
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +31 -8
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +51 -9
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/hooks/block-hooks.js +5 -14
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +19 -43
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/effects.js +51 -0
- package/build-module/hooks/effects.js.map +1 -0
- package/build-module/hooks/index.js +3 -2
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/style.js +6 -2
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/supports.js +2 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.native.js +2 -2
- package/build-module/hooks/typography.native.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +112 -0
- package/build-module/hooks/use-bindings-attributes.js.map +1 -0
- package/build-module/hooks/use-shadow-props.js +39 -0
- package/build-module/hooks/use-shadow-props.js.map +1 -0
- package/build-module/hooks/utils.js +13 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +10 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +35 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +53 -8
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +43 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +20 -0
- package/build-module/store/resolvers.js.map +1 -0
- package/build-module/store/selectors.js +89 -52
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +3 -23
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/index.js +0 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/object.js +16 -0
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +36 -27
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +33 -16
- package/build-style/content.css +33 -16
- package/build-style/default-editor-styles-rtl.css +1 -1
- package/build-style/default-editor-styles.css +1 -1
- package/build-style/style-rtl.css +169 -114
- package/build-style/style.css +169 -114
- package/package.json +31 -31
- package/src/components/block-canvas/style.scss +8 -1
- package/src/components/block-draggable/index.js +16 -5
- package/src/components/block-edit/context.js +1 -0
- package/src/components/block-edit/index.js +4 -0
- package/src/components/block-editing-mode/index.js +12 -7
- package/src/components/block-inspector/index.js +5 -2
- package/src/components/block-list/block.js +5 -4
- package/src/components/block-list/block.native.js +13 -3
- package/src/components/block-list/content.scss +34 -5
- package/src/components/block-list/index.js +52 -16
- package/src/components/block-list/private-block-context.js +1 -1
- package/src/components/block-list/use-in-between-inserter.js +1 -2
- package/src/components/block-lock/toolbar.js +10 -2
- package/src/components/block-popover/inbetween.js +22 -2
- package/src/components/block-preview/auto.js +3 -3
- package/src/components/block-removal-warning-modal/index.js +3 -2
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -7
- package/src/components/block-switcher/block-transformations-menu.js +18 -1
- package/src/components/block-switcher/index.js +133 -111
- package/src/components/block-switcher/style.scss +6 -4
- package/src/components/block-switcher/test/index.js +113 -230
- package/src/components/block-toolbar/style.scss +22 -18
- package/src/components/block-tools/insertion-point.js +15 -2
- package/src/components/block-tools/style.scss +8 -7
- package/src/components/font-sizes/fluid-utils.js +8 -2
- package/src/components/font-sizes/test/fluid-utils.js +9 -0
- package/src/components/global-styles/border-panel.js +7 -17
- package/src/components/global-styles/effects-panel.js +16 -1
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +45 -13
- package/src/components/iframe/get-compatibility-styles.js +120 -0
- package/src/components/iframe/index.js +2 -3
- package/src/components/index.js +4 -2
- package/src/components/index.native.js +4 -2
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -0
- package/src/components/link-control/link-preview.js +31 -55
- package/src/components/link-control/search-input.js +1 -9
- package/src/components/link-control/style.scss +31 -85
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/list-view/block-contents.js +5 -1
- package/src/components/list-view/block.js +9 -0
- package/src/components/list-view/branch.js +30 -10
- package/src/components/list-view/drop-indicator.js +139 -46
- package/src/components/list-view/index.js +74 -3
- package/src/components/list-view/leaf.js +2 -2
- package/src/components/list-view/style.scss +102 -13
- package/src/components/list-view/test/use-list-view-drop-zone.js +4 -0
- package/src/components/list-view/test/utils.js +218 -1
- package/src/components/list-view/use-list-view-block-indexes.js +29 -0
- package/src/components/list-view/use-list-view-drop-zone.js +78 -6
- package/src/components/list-view/utils.js +116 -0
- package/src/components/provider/index.js +3 -1
- package/src/components/recursion-provider/README.md +2 -2
- package/src/components/recursion-provider/index.js +17 -0
- package/src/components/rich-text/index.js +48 -10
- package/src/components/rich-text/native/index.native.js +10 -10
- package/src/components/use-block-drop-zone/index.js +60 -19
- package/src/components/use-block-drop-zone/test/index.js +32 -61
- package/src/components/use-on-block-drop/index.js +92 -11
- package/src/hooks/block-hooks.js +5 -17
- package/src/hooks/content-lock-ui.js +15 -55
- package/src/hooks/effects.js +57 -0
- package/src/hooks/index.js +2 -2
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/style.js +8 -0
- package/src/hooks/supports.js +2 -0
- package/src/hooks/test/effects.js +39 -0
- package/src/hooks/typography.native.js +2 -2
- package/src/hooks/use-bindings-attributes.js +148 -0
- package/src/hooks/use-shadow-props.js +37 -0
- package/src/hooks/utils.js +26 -10
- package/src/index.js +2 -0
- package/src/store/actions.js +9 -4
- package/src/store/index.js +2 -0
- package/src/store/private-actions.js +32 -0
- package/src/store/private-selectors.js +78 -21
- package/src/store/reducer.js +49 -2
- package/src/store/resolvers.js +17 -0
- package/src/store/selectors.js +169 -161
- package/src/store/test/registry-selectors.js +431 -0
- package/src/store/test/selectors.js +14 -400
- package/src/store/utils.js +10 -33
- package/src/style.scss +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/math.js +12 -0
- package/src/utils/object.js +16 -0
- package/src/utils/transform-styles/index.js +52 -37
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/iframe/use-compatibility-styles.js +0 -100
- package/build/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build/hooks/custom-fields.js +0 -106
- package/build/hooks/custom-fields.js.map +0 -1
- package/build/utils/block-variation-transforms.js +0 -42
- package/build/utils/block-variation-transforms.js.map +0 -1
- package/build-module/components/iframe/use-compatibility-styles.js +0 -94
- package/build-module/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build-module/hooks/custom-fields.js +0 -99
- package/build-module/hooks/custom-fields.js.map +0 -1
- package/build-module/utils/block-variation-transforms.js +0 -35
- package/build-module/utils/block-variation-transforms.js.map +0 -1
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +0 -116
- package/src/components/contrast-checker/style.scss +0 -3
- package/src/components/iframe/use-compatibility-styles.js +0 -122
- package/src/hooks/custom-fields.js +0 -115
- package/src/utils/block-variation-transforms.js +0 -38
- package/src/utils/test/block-variation-transforms.js +0 -94
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["matchesAttributes","blockAttributes","variation","Object","entries","every","key","value","__experimentalGetMatchingVariation","variations","matches","filter","attributes","keys","length"],"sources":["@wordpress/block-editor/src/utils/block-variation-transforms.js"],"sourcesContent":["/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */\n\nfunction matchesAttributes( blockAttributes, variation ) {\n\treturn Object.entries( variation ).every( ( [ key, value ] ) => {\n\t\tif (\n\t\t\ttypeof value === 'object' &&\n\t\t\ttypeof blockAttributes[ key ] === 'object'\n\t\t) {\n\t\t\treturn matchesAttributes( blockAttributes[ key ], value );\n\t\t}\n\t\treturn blockAttributes[ key ] === value;\n\t} );\n}\n\n/**\n * Matches the provided block variations with a block's attributes. If no match\n * or more than one matches are found it returns `undefined`. If a single match is\n * found it returns it.\n *\n * This is a simple implementation for now as it takes into account only the attributes\n * of a block variation and not `InnerBlocks`.\n *\n * @param {Object} blockAttributes - The block attributes to try to find a match.\n * @param {WPBlockVariation[]} variations - A list of block variations to test for a match.\n * @return {WPBlockVariation | undefined} - If a match is found returns it. If not or more than one matches are found returns `undefined`.\n */\nexport const __experimentalGetMatchingVariation = (\n\tblockAttributes,\n\tvariations\n) => {\n\tif ( ! variations || ! blockAttributes ) return;\n\tconst matches = variations.filter( ( { attributes } ) => {\n\t\tif ( ! attributes || ! Object.keys( attributes ).length ) return false;\n\t\treturn matchesAttributes( blockAttributes, attributes );\n\t} );\n\tif ( matches.length !== 1 ) return;\n\treturn matches[ 0 ];\n};\n"],"mappings":"AAAA;;AAEA,SAASA,iBAAiBA,CAAEC,eAAe,EAAEC,SAAS,EAAG;EACxD,OAAOC,MAAM,CAACC,OAAO,CAAEF,SAAU,CAAC,CAACG,KAAK,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IAC/D,IACC,OAAOA,KAAK,KAAK,QAAQ,IACzB,OAAON,eAAe,CAAEK,GAAG,CAAE,KAAK,QAAQ,EACzC;MACD,OAAON,iBAAiB,CAAEC,eAAe,CAAEK,GAAG,CAAE,EAAEC,KAAM,CAAC;IAC1D;IACA,OAAON,eAAe,CAAEK,GAAG,CAAE,KAAKC,KAAK;EACxC,CAAE,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kCAAkC,GAAGA,CACjDP,eAAe,EACfQ,UAAU,KACN;EACJ,IAAK,CAAEA,UAAU,IAAI,CAAER,eAAe,EAAG;EACzC,MAAMS,OAAO,GAAGD,UAAU,CAACE,MAAM,CAAE,CAAE;IAAEC;EAAW,CAAC,KAAM;IACxD,IAAK,CAAEA,UAAU,IAAI,CAAET,MAAM,CAACU,IAAI,CAAED,UAAW,CAAC,CAACE,MAAM,EAAG,OAAO,KAAK;IACtE,OAAOd,iBAAiB,CAAEC,eAAe,EAAEW,UAAW,CAAC;EACxD,CAAE,CAAC;EACH,IAAKF,OAAO,CAACI,MAAM,KAAK,CAAC,EAAG;EAC5B,OAAOJ,OAAO,CAAE,CAAC,CAAE;AACpB,CAAC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`BlockSwitcherDropdownMenu should render disabled block switcher with multi block of different types when no transforms 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<div
|
|
6
|
-
class="components-toolbar"
|
|
7
|
-
>
|
|
8
|
-
<div>
|
|
9
|
-
<button
|
|
10
|
-
aria-label="Block Name"
|
|
11
|
-
class="components-button components-toolbar__control block-editor-block-switcher__no-switcher-icon has-icon"
|
|
12
|
-
data-toolbar-item="true"
|
|
13
|
-
disabled=""
|
|
14
|
-
type="button"
|
|
15
|
-
>
|
|
16
|
-
<span
|
|
17
|
-
class="block-editor-block-icon has-colors"
|
|
18
|
-
>
|
|
19
|
-
<svg
|
|
20
|
-
aria-hidden="true"
|
|
21
|
-
focusable="false"
|
|
22
|
-
height="24"
|
|
23
|
-
viewBox="0 0 24 24"
|
|
24
|
-
width="24"
|
|
25
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
-
>
|
|
27
|
-
<path
|
|
28
|
-
clip-rule="evenodd"
|
|
29
|
-
d="M5 4.5h11a.5.5 0 0 1 .5.5v11a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V5a.5.5 0 0 1 .5-.5ZM3 5a2 2 0 0 1 2-2h11a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5Zm17 3v10.75c0 .69-.56 1.25-1.25 1.25H6v1.5h12.75a2.75 2.75 0 0 0 2.75-2.75V8H20Z"
|
|
30
|
-
fill-rule="evenodd"
|
|
31
|
-
/>
|
|
32
|
-
</svg>
|
|
33
|
-
</span>
|
|
34
|
-
</button>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
exports[`BlockSwitcherDropdownMenu should render enabled block switcher with multi block when transforms exist 1`] = `
|
|
41
|
-
<div>
|
|
42
|
-
<div
|
|
43
|
-
class="components-toolbar"
|
|
44
|
-
>
|
|
45
|
-
<div
|
|
46
|
-
class="components-dropdown components-dropdown-menu block-editor-block-switcher"
|
|
47
|
-
tabindex="-1"
|
|
48
|
-
>
|
|
49
|
-
<button
|
|
50
|
-
aria-describedby="components-button__description-2"
|
|
51
|
-
aria-expanded="false"
|
|
52
|
-
aria-haspopup="true"
|
|
53
|
-
aria-label="Multiple blocks selected"
|
|
54
|
-
class="components-button components-dropdown-menu__toggle has-icon"
|
|
55
|
-
data-toolbar-item="true"
|
|
56
|
-
type="button"
|
|
57
|
-
>
|
|
58
|
-
<span
|
|
59
|
-
class="block-editor-block-icon block-editor-block-switcher__toggle has-colors"
|
|
60
|
-
/>
|
|
61
|
-
</button>
|
|
62
|
-
<div
|
|
63
|
-
class="components-visually-hidden emotion-0 emotion-1"
|
|
64
|
-
data-wp-c16t="true"
|
|
65
|
-
data-wp-component="VisuallyHidden"
|
|
66
|
-
style="border: 0px; clip: rect(1px, 1px, 1px, 1px); clip-path: inset( 50% ); height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px; word-wrap: normal;"
|
|
67
|
-
>
|
|
68
|
-
<span
|
|
69
|
-
id="components-button__description-2"
|
|
70
|
-
>
|
|
71
|
-
Change type of 2 blocks
|
|
72
|
-
</span>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
exports[`BlockSwitcherDropdownMenu should render switcher with blocks 1`] = `
|
|
80
|
-
<div>
|
|
81
|
-
<div
|
|
82
|
-
class="components-toolbar"
|
|
83
|
-
>
|
|
84
|
-
<div
|
|
85
|
-
class="components-dropdown components-dropdown-menu block-editor-block-switcher"
|
|
86
|
-
tabindex="-1"
|
|
87
|
-
>
|
|
88
|
-
<button
|
|
89
|
-
aria-describedby="components-button__description-0"
|
|
90
|
-
aria-expanded="false"
|
|
91
|
-
aria-haspopup="true"
|
|
92
|
-
aria-label="Block Name"
|
|
93
|
-
class="components-button components-dropdown-menu__toggle has-icon"
|
|
94
|
-
data-toolbar-item="true"
|
|
95
|
-
type="button"
|
|
96
|
-
>
|
|
97
|
-
<span
|
|
98
|
-
class="block-editor-block-icon block-editor-block-switcher__toggle has-colors"
|
|
99
|
-
/>
|
|
100
|
-
</button>
|
|
101
|
-
<div
|
|
102
|
-
class="components-visually-hidden emotion-0 emotion-1"
|
|
103
|
-
data-wp-c16t="true"
|
|
104
|
-
data-wp-component="VisuallyHidden"
|
|
105
|
-
style="border: 0px; clip: rect(1px, 1px, 1px, 1px); clip-path: inset( 50% ); height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px; word-wrap: normal;"
|
|
106
|
-
>
|
|
107
|
-
<span
|
|
108
|
-
id="components-button__description-0"
|
|
109
|
-
>
|
|
110
|
-
Change block type or style
|
|
111
|
-
</span>
|
|
112
|
-
</div>
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
</div>
|
|
116
|
-
`;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useMemo } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns a list of stylesheets that target the editor canvas. A stylesheet is
|
|
8
|
-
* considered targetting the editor a canvas if it contains the
|
|
9
|
-
* `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.
|
|
10
|
-
*
|
|
11
|
-
* Ideally, this hook should be removed in the future and styles should be added
|
|
12
|
-
* explicitly as editor styles.
|
|
13
|
-
*/
|
|
14
|
-
export function useCompatibilityStyles() {
|
|
15
|
-
// Only memoize the result once on load, since these stylesheets should not
|
|
16
|
-
// change.
|
|
17
|
-
return useMemo( () => {
|
|
18
|
-
// Search the document for stylesheets targetting the editor canvas.
|
|
19
|
-
return Array.from( document.styleSheets ).reduce(
|
|
20
|
-
( accumulator, styleSheet ) => {
|
|
21
|
-
try {
|
|
22
|
-
// May fail for external styles.
|
|
23
|
-
// eslint-disable-next-line no-unused-expressions
|
|
24
|
-
styleSheet.cssRules;
|
|
25
|
-
} catch ( e ) {
|
|
26
|
-
return accumulator;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const { ownerNode, cssRules } = styleSheet;
|
|
30
|
-
|
|
31
|
-
// Stylesheet is added by another stylesheet. See
|
|
32
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet/ownerNode#notes.
|
|
33
|
-
if ( ownerNode === null ) {
|
|
34
|
-
return accumulator;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if ( ! cssRules ) {
|
|
38
|
-
return accumulator;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Don't try to add the reset styles, which were removed as a dependency
|
|
42
|
-
// from `edit-blocks` for the iframe since we don't need to reset admin
|
|
43
|
-
// styles.
|
|
44
|
-
if ( ownerNode.id === 'wp-reset-editor-styles-css' ) {
|
|
45
|
-
return accumulator;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Don't try to add styles without ID. Styles enqueued via the WP dependency system will always have IDs.
|
|
49
|
-
if ( ! ownerNode.id ) {
|
|
50
|
-
return accumulator;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function matchFromRules( _cssRules ) {
|
|
54
|
-
return Array.from( _cssRules ).find(
|
|
55
|
-
( {
|
|
56
|
-
selectorText,
|
|
57
|
-
conditionText,
|
|
58
|
-
cssRules: __cssRules,
|
|
59
|
-
} ) => {
|
|
60
|
-
// If the rule is conditional then it will not have selector text.
|
|
61
|
-
// Recurse into child CSS ruleset to determine selector eligibility.
|
|
62
|
-
if ( conditionText ) {
|
|
63
|
-
return matchFromRules( __cssRules );
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
selectorText &&
|
|
68
|
-
( selectorText.includes(
|
|
69
|
-
'.editor-styles-wrapper'
|
|
70
|
-
) ||
|
|
71
|
-
selectorText.includes( '.wp-block' ) )
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if ( matchFromRules( cssRules ) ) {
|
|
78
|
-
const isInline = ownerNode.tagName === 'STYLE';
|
|
79
|
-
|
|
80
|
-
if ( isInline ) {
|
|
81
|
-
// If the current target is inline,
|
|
82
|
-
// it could be a dependency of an existing stylesheet.
|
|
83
|
-
// Look for that dependency and add it BEFORE the current target.
|
|
84
|
-
const mainStylesCssId = ownerNode.id.replace(
|
|
85
|
-
'-inline-css',
|
|
86
|
-
'-css'
|
|
87
|
-
);
|
|
88
|
-
const mainStylesElement =
|
|
89
|
-
document.getElementById( mainStylesCssId );
|
|
90
|
-
if ( mainStylesElement ) {
|
|
91
|
-
accumulator.push(
|
|
92
|
-
mainStylesElement.cloneNode( true )
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
accumulator.push( ownerNode.cloneNode( true ) );
|
|
98
|
-
|
|
99
|
-
if ( ! isInline ) {
|
|
100
|
-
// If the current target is not inline,
|
|
101
|
-
// we still look for inline styles that could be relevant for the current target.
|
|
102
|
-
// If they exist, add them AFTER the current target.
|
|
103
|
-
const inlineStylesCssId = ownerNode.id.replace(
|
|
104
|
-
'-css',
|
|
105
|
-
'-inline-css'
|
|
106
|
-
);
|
|
107
|
-
const inlineStylesElement =
|
|
108
|
-
document.getElementById( inlineStylesCssId );
|
|
109
|
-
if ( inlineStylesElement ) {
|
|
110
|
-
accumulator.push(
|
|
111
|
-
inlineStylesElement.cloneNode( true )
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return accumulator;
|
|
118
|
-
},
|
|
119
|
-
[]
|
|
120
|
-
);
|
|
121
|
-
}, [] );
|
|
122
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { addFilter } from '@wordpress/hooks';
|
|
5
|
-
import { PanelBody, TextControl } from '@wordpress/components';
|
|
6
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
-
import { hasBlockSupport } from '@wordpress/blocks';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
import { InspectorControls } from '../components';
|
|
13
|
-
import { useBlockEditingMode } from '../components/block-editing-mode';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Filters registered block settings, extending attributes to include `connections`.
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} settings Original block settings.
|
|
19
|
-
*
|
|
20
|
-
* @return {Object} Filtered block settings.
|
|
21
|
-
*/
|
|
22
|
-
function addAttribute( settings ) {
|
|
23
|
-
if ( hasBlockSupport( settings, '__experimentalConnections', true ) ) {
|
|
24
|
-
// Gracefully handle if settings.attributes.connections is undefined.
|
|
25
|
-
settings.attributes = {
|
|
26
|
-
...settings.attributes,
|
|
27
|
-
connections: {
|
|
28
|
-
type: 'object',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return settings;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function CustomFieldsControlPure( { name, connections, setAttributes } ) {
|
|
37
|
-
const blockEditingMode = useBlockEditingMode();
|
|
38
|
-
if ( blockEditingMode !== 'default' ) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// If the block is a paragraph or image block, we need to know which
|
|
43
|
-
// attribute to use for the connection. Only the `content` attribute
|
|
44
|
-
// of the paragraph block and the `url` attribute of the image block are supported.
|
|
45
|
-
let attributeName;
|
|
46
|
-
if ( name === 'core/paragraph' ) attributeName = 'content';
|
|
47
|
-
if ( name === 'core/image' ) attributeName = 'url';
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<InspectorControls>
|
|
51
|
-
<PanelBody title={ __( 'Connections' ) } initialOpen={ true }>
|
|
52
|
-
<TextControl
|
|
53
|
-
__nextHasNoMarginBottom
|
|
54
|
-
autoComplete="off"
|
|
55
|
-
label={ __( 'Custom field meta_key' ) }
|
|
56
|
-
value={
|
|
57
|
-
connections?.attributes?.[ attributeName ]?.value || ''
|
|
58
|
-
}
|
|
59
|
-
onChange={ ( nextValue ) => {
|
|
60
|
-
if ( nextValue === '' ) {
|
|
61
|
-
setAttributes( {
|
|
62
|
-
connections: undefined,
|
|
63
|
-
[ attributeName ]: undefined,
|
|
64
|
-
placeholder: undefined,
|
|
65
|
-
} );
|
|
66
|
-
} else {
|
|
67
|
-
setAttributes( {
|
|
68
|
-
connections: {
|
|
69
|
-
attributes: {
|
|
70
|
-
// The attributeName will be either `content` or `url`.
|
|
71
|
-
[ attributeName ]: {
|
|
72
|
-
// Source will be variable, could be post_meta, user_meta, term_meta, etc.
|
|
73
|
-
// Could even be a custom source like a social media attribute.
|
|
74
|
-
source: 'meta_fields',
|
|
75
|
-
value: nextValue,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
[ attributeName ]: undefined,
|
|
80
|
-
placeholder: sprintf(
|
|
81
|
-
'This content will be replaced on the frontend by the value of "%s" custom field.',
|
|
82
|
-
nextValue
|
|
83
|
-
),
|
|
84
|
-
} );
|
|
85
|
-
}
|
|
86
|
-
} }
|
|
87
|
-
/>
|
|
88
|
-
</PanelBody>
|
|
89
|
-
</InspectorControls>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default {
|
|
94
|
-
edit: CustomFieldsControlPure,
|
|
95
|
-
attributeKeys: [ 'connections' ],
|
|
96
|
-
hasSupport( name ) {
|
|
97
|
-
return (
|
|
98
|
-
hasBlockSupport( name, '__experimentalConnections', false ) &&
|
|
99
|
-
// Check if the current block is a paragraph or image block.
|
|
100
|
-
// Currently, only these two blocks are supported.
|
|
101
|
-
[ 'core/paragraph', 'core/image' ].includes( name )
|
|
102
|
-
);
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
window.__experimentalConnections ||
|
|
108
|
-
window.__experimentalPatternPartialSyncing
|
|
109
|
-
) {
|
|
110
|
-
addFilter(
|
|
111
|
-
'blocks.registerBlockType',
|
|
112
|
-
'core/editor/connections/attribute',
|
|
113
|
-
addAttribute
|
|
114
|
-
);
|
|
115
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */
|
|
2
|
-
|
|
3
|
-
function matchesAttributes( blockAttributes, variation ) {
|
|
4
|
-
return Object.entries( variation ).every( ( [ key, value ] ) => {
|
|
5
|
-
if (
|
|
6
|
-
typeof value === 'object' &&
|
|
7
|
-
typeof blockAttributes[ key ] === 'object'
|
|
8
|
-
) {
|
|
9
|
-
return matchesAttributes( blockAttributes[ key ], value );
|
|
10
|
-
}
|
|
11
|
-
return blockAttributes[ key ] === value;
|
|
12
|
-
} );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Matches the provided block variations with a block's attributes. If no match
|
|
17
|
-
* or more than one matches are found it returns `undefined`. If a single match is
|
|
18
|
-
* found it returns it.
|
|
19
|
-
*
|
|
20
|
-
* This is a simple implementation for now as it takes into account only the attributes
|
|
21
|
-
* of a block variation and not `InnerBlocks`.
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} blockAttributes - The block attributes to try to find a match.
|
|
24
|
-
* @param {WPBlockVariation[]} variations - A list of block variations to test for a match.
|
|
25
|
-
* @return {WPBlockVariation | undefined} - If a match is found returns it. If not or more than one matches are found returns `undefined`.
|
|
26
|
-
*/
|
|
27
|
-
export const __experimentalGetMatchingVariation = (
|
|
28
|
-
blockAttributes,
|
|
29
|
-
variations
|
|
30
|
-
) => {
|
|
31
|
-
if ( ! variations || ! blockAttributes ) return;
|
|
32
|
-
const matches = variations.filter( ( { attributes } ) => {
|
|
33
|
-
if ( ! attributes || ! Object.keys( attributes ).length ) return false;
|
|
34
|
-
return matchesAttributes( blockAttributes, attributes );
|
|
35
|
-
} );
|
|
36
|
-
if ( matches.length !== 1 ) return;
|
|
37
|
-
return matches[ 0 ];
|
|
38
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __experimentalGetMatchingVariation as getMatchingVariation } from '../block-variation-transforms';
|
|
5
|
-
|
|
6
|
-
describe( 'getMatchingVariation', () => {
|
|
7
|
-
describe( 'should not find a match', () => {
|
|
8
|
-
it( 'when no variations or attributes passed', () => {
|
|
9
|
-
expect(
|
|
10
|
-
getMatchingVariation( null, { content: 'hi' } )
|
|
11
|
-
).toBeUndefined();
|
|
12
|
-
expect( getMatchingVariation( {} ) ).toBeUndefined();
|
|
13
|
-
} );
|
|
14
|
-
it( 'when no variation matched', () => {
|
|
15
|
-
const variations = [
|
|
16
|
-
{ name: 'one', attributes: { level: 1 } },
|
|
17
|
-
{ name: 'two', attributes: { level: 2 } },
|
|
18
|
-
];
|
|
19
|
-
expect(
|
|
20
|
-
getMatchingVariation( { level: 4 }, variations )
|
|
21
|
-
).toBeUndefined();
|
|
22
|
-
} );
|
|
23
|
-
it( 'when more than one match found', () => {
|
|
24
|
-
const variations = [
|
|
25
|
-
{ name: 'one', attributes: { level: 1 } },
|
|
26
|
-
{ name: 'two', attributes: { level: 1, content: 'hi' } },
|
|
27
|
-
];
|
|
28
|
-
expect(
|
|
29
|
-
getMatchingVariation(
|
|
30
|
-
{ level: 1, content: 'hi', other: 'prop' },
|
|
31
|
-
variations
|
|
32
|
-
)
|
|
33
|
-
).toBeUndefined();
|
|
34
|
-
} );
|
|
35
|
-
it( 'when variation is a superset of attributes', () => {
|
|
36
|
-
const variations = [
|
|
37
|
-
{ name: 'one', attributes: { level: 1, content: 'hi' } },
|
|
38
|
-
];
|
|
39
|
-
expect(
|
|
40
|
-
getMatchingVariation( { level: 1, other: 'prop' }, variations )
|
|
41
|
-
).toBeUndefined();
|
|
42
|
-
} );
|
|
43
|
-
it( 'when variation has a nested attribute', () => {
|
|
44
|
-
const variations = [
|
|
45
|
-
{ name: 'one', attributes: { query: { author: 'somebody' } } },
|
|
46
|
-
{ name: 'two', attributes: { query: { author: 'nobody' } } },
|
|
47
|
-
];
|
|
48
|
-
expect(
|
|
49
|
-
getMatchingVariation(
|
|
50
|
-
{ query: { author: 'foobar' }, other: 'prop' },
|
|
51
|
-
variations
|
|
52
|
-
)
|
|
53
|
-
).toBeUndefined();
|
|
54
|
-
} );
|
|
55
|
-
} );
|
|
56
|
-
describe( 'should find a match', () => {
|
|
57
|
-
it( 'when variation has one attribute', () => {
|
|
58
|
-
const variations = [
|
|
59
|
-
{ name: 'one', attributes: { level: 1 } },
|
|
60
|
-
{ name: 'two', attributes: { level: 2 } },
|
|
61
|
-
];
|
|
62
|
-
expect(
|
|
63
|
-
getMatchingVariation(
|
|
64
|
-
{ level: 2, content: 'hi', other: 'prop' },
|
|
65
|
-
variations
|
|
66
|
-
).name
|
|
67
|
-
).toEqual( 'two' );
|
|
68
|
-
} );
|
|
69
|
-
it( 'when variation has many attributes', () => {
|
|
70
|
-
const variations = [
|
|
71
|
-
{ name: 'one', attributes: { level: 1, content: 'hi' } },
|
|
72
|
-
{ name: 'two', attributes: { level: 2 } },
|
|
73
|
-
];
|
|
74
|
-
expect(
|
|
75
|
-
getMatchingVariation(
|
|
76
|
-
{ level: 1, content: 'hi', other: 'prop' },
|
|
77
|
-
variations
|
|
78
|
-
).name
|
|
79
|
-
).toEqual( 'one' );
|
|
80
|
-
} );
|
|
81
|
-
it( 'when variation has a nested attribute', () => {
|
|
82
|
-
const variations = [
|
|
83
|
-
{ name: 'one', attributes: { query: { author: 'somebody' } } },
|
|
84
|
-
{ name: 'two', attributes: { query: { author: 'nobody' } } },
|
|
85
|
-
];
|
|
86
|
-
expect(
|
|
87
|
-
getMatchingVariation(
|
|
88
|
-
{ query: { author: 'somebody' }, other: 'prop' },
|
|
89
|
-
variations
|
|
90
|
-
).name
|
|
91
|
-
).toEqual( 'one' );
|
|
92
|
-
} );
|
|
93
|
-
} );
|
|
94
|
-
} );
|