@wordpress/block-editor 14.1.0 → 14.2.1-next.1f6eadc42.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 +2 -0
- package/README.md +1 -10
- package/build/components/block-alignment-matrix-control/index.js +2 -2
- package/build/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build/components/block-breadcrumb/index.js +2 -2
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-canvas/index.js +8 -1
- package/build/components/block-canvas/index.js.map +1 -1
- package/build/components/block-compare/block-view.js +1 -0
- package/build/components/block-compare/block-view.js.map +1 -1
- package/build/components/block-draggable/index.js +4 -4
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/use-scroll-when-dragging.js +25 -25
- package/build/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build/components/block-edit/multiple-usage-warning.js +2 -0
- package/build/components/block-edit/multiple-usage-warning.js.map +1 -1
- package/build/components/block-inspector/index.js +27 -11
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-invalid-warning.js +3 -2
- package/build/components/block-list/block-invalid-warning.js.map +1 -1
- package/build/components/block-list/block.js +5 -1
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/index.js +14 -3
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +5 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +1 -0
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js +53 -0
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -0
- package/build/components/block-list/zoom-out-separator.js +98 -0
- package/build/components/block-list/zoom-out-separator.js.map +1 -0
- package/build/components/block-lock/toolbar.js +3 -3
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/button.js +1 -0
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +1 -0
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +4 -1
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +2 -10
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +22 -7
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-patterns-list/index.js +12 -20
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-patterns-paging/index.js +12 -3
- package/build/components/block-patterns-paging/index.js.map +1 -1
- package/build/components/block-popover/index.js +2 -15
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-quick-navigation/index.js +4 -1
- package/build/components/block-quick-navigation/index.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +4 -0
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-switcher/index.js +30 -19
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-switcher/pattern-transformations-menu.js +2 -10
- package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build/components/block-toolbar/index.js +19 -12
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/shuffle.js +6 -2
- package/build/components/block-toolbar/shuffle.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +8 -2
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/block-toolbar-popover.js +10 -6
- package/build/components/block-tools/block-toolbar-popover.js.map +1 -1
- package/build/components/block-tools/index.js +1 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +2 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js +7 -21
- package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build/components/block-tools/zoom-out-popover.js +3 -4
- package/build/components/block-tools/zoom-out-popover.js.map +1 -1
- package/build/components/block-tools/zoom-out-toolbar.js +26 -7
- package/build/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build/components/block-variation-picker/index.js +4 -1
- package/build/components/block-variation-picker/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +4 -1
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/button-block-appender/index.js +20 -23
- package/build/components/button-block-appender/index.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +4 -1
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/content-lock/index.js +13 -0
- package/build/components/content-lock/index.js.map +1 -0
- package/build/components/content-lock/modify-content-lock-menu-item.js +64 -0
- package/build/components/content-lock/modify-content-lock-menu-item.js.map +1 -0
- package/build/components/editor-styles/index.js +4 -3
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/global-styles/background-panel.js +8 -12
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +8 -5
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.native.js +1 -1
- package/build/components/global-styles/color-panel.native.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +34 -37
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +4 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/shadow-panel-components.js +14 -17
- package/build/components/global-styles/shadow-panel-components.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +17 -6
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/global-styles/utils.js +4 -6
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/grid/grid-item-movers.js +2 -2
- package/build/components/grid/grid-item-movers.js.map +1 -1
- package/build/components/grid/grid-item-resizer.js +2 -2
- package/build/components/grid/grid-item-resizer.js.map +1 -1
- package/build/components/iframe/get-compatibility-styles.js +1 -1
- package/build/components/iframe/get-compatibility-styles.js.map +1 -1
- package/build/components/iframe/index.js +5 -5
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +2 -4
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -3
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +4 -1
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js +4 -1
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +23 -13
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build/components/inserter/index.js +4 -11
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/library.js +2 -4
- package/build/components/inserter/library.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +3 -3
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +1 -8
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +9 -7
- package/build/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build/components/inserter/media-tab/media-tab.js +4 -1
- package/build/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build/components/inserter/menu.js +7 -24
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +4 -5
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter-list-item/index.js +4 -4
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/inserter-listbox/index.js +3 -13
- package/build/components/inserter-listbox/index.js.map +1 -1
- package/build/components/inserter-listbox/item.js +6 -11
- package/build/components/inserter-listbox/item.js.map +1 -1
- package/build/components/inserter-listbox/row.js +1 -9
- package/build/components/inserter-listbox/row.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/index.js +4 -1
- package/build/components/inspector-controls-tabs/index.js.map +1 -1
- package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/inspector-popover-header/index.js +8 -2
- package/build/components/inspector-popover-header/index.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +7 -4
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/link-control/index.js +19 -10
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +4 -1
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/list-view/block-select-button.js +4 -1
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/index.js +3 -7
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/media-placeholder/index.js +32 -11
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +8 -1
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +19 -19
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/event-listeners/paste-handler.js +12 -1
- package/build/components/rich-text/event-listeners/paste-handler.js.map +1 -1
- package/build/components/rich-text/index.js +38 -30
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-mark-persistent.js +5 -5
- package/build/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js +4 -1
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +8 -9
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/linked-button.js +35 -0
- package/build/components/spacing-sizes-control/linked-button.js.map +1 -0
- package/build/components/spacing-sizes-control/utils.js +4 -15
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/components/tool-selector/index.js +4 -1
- package/build/components/tool-selector/index.js.map +1 -1
- package/build/components/url-input/button.js +12 -3
- package/build/components/url-input/button.js.map +1 -1
- package/build/components/url-input/index.js +4 -1
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +31 -7
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/writing-flow/index.js +2 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +4 -1
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-event-redirect.js +66 -0
- package/build/components/writing-flow/use-event-redirect.js.map +1 -0
- package/build/components/writing-flow/use-input.js +31 -1
- package/build/components/writing-flow/use-input.js.map +1 -1
- package/build/components/writing-flow/use-select-all.js +14 -1
- package/build/components/writing-flow/use-select-all.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +20 -6
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +4 -4
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-flow/utils.js +27 -0
- package/build/components/writing-flow/utils.js.map +1 -1
- package/build/hooks/block-bindings.js +33 -29
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/content-lock-ui.js +8 -26
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/duotone.js +0 -4
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/layout.js +4 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/spacing-visualizer.js +3 -3
- package/build/hooks/spacing-visualizer.js.map +1 -1
- package/build/hooks/style.js +1 -5
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +19 -20
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/use-zoom-out.js +7 -7
- package/build/hooks/use-zoom-out.js.map +1 -1
- package/build/layouts/constrained.js +41 -42
- package/build/layouts/constrained.js.map +1 -1
- package/build/layouts/flex.js +4 -1
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/grid.js +19 -16
- package/build/layouts/grid.js.map +1 -1
- package/build/layouts/utils.js +1 -7
- package/build/layouts/utils.js.map +1 -1
- package/build/private-apis.js +2 -3
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +2 -7
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +1 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-keys.js +2 -1
- package/build/store/private-keys.js.map +1 -1
- package/build/store/private-selectors.js +16 -18
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +1 -10
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +19 -43
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +48 -0
- package/build/store/utils.js.map +1 -1
- package/build/utils/block-bindings.js +16 -11
- package/build/utils/block-bindings.js.map +1 -1
- package/build/utils/dom.js +101 -0
- package/build/utils/dom.js.map +1 -1
- package/build/utils/get-font-styles-and-weights.js +4 -4
- package/build/utils/get-font-styles-and-weights.js.map +1 -1
- package/build/utils/transform-styles/index.js +120 -16
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-alignment-matrix-control/index.js +1 -1
- package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js +2 -2
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-canvas/index.js +9 -1
- package/build-module/components/block-canvas/index.js.map +1 -1
- package/build-module/components/block-compare/block-view.js +1 -0
- package/build-module/components/block-compare/block-view.js.map +1 -1
- package/build-module/components/block-draggable/index.js +4 -4
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/use-scroll-when-dragging.js +25 -25
- package/build-module/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build-module/components/block-edit/multiple-usage-warning.js +2 -0
- package/build-module/components/block-edit/multiple-usage-warning.js.map +1 -1
- package/build-module/components/block-inspector/index.js +27 -11
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.js +3 -2
- package/build-module/components/block-list/block-invalid-warning.js.map +1 -1
- package/build-module/components/block-list/block.js +5 -1
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/index.js +14 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +5 -1
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +1 -0
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js +47 -0
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -0
- package/build-module/components/block-list/zoom-out-separator.js +90 -0
- package/build-module/components/block-list/zoom-out-separator.js.map +1 -0
- package/build-module/components/block-lock/toolbar.js +3 -3
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/button.js +1 -0
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +1 -0
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +4 -1
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +2 -10
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +23 -8
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +12 -20
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-patterns-paging/index.js +12 -3
- package/build-module/components/block-patterns-paging/index.js.map +1 -1
- package/build-module/components/block-popover/index.js +2 -15
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-quick-navigation/index.js +4 -1
- package/build-module/components/block-quick-navigation/index.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +4 -0
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +30 -19
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-switcher/pattern-transformations-menu.js +2 -10
- package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +19 -12
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/shuffle.js +6 -2
- package/build-module/components/block-toolbar/shuffle.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +8 -2
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/block-toolbar-popover.js +10 -6
- package/build-module/components/block-tools/block-toolbar-popover.js.map +1 -1
- package/build-module/components/block-tools/index.js +1 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +2 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js +7 -22
- package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-popover.js +3 -4
- package/build-module/components/block-tools/zoom-out-popover.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-toolbar.js +27 -8
- package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build-module/components/block-variation-picker/index.js +4 -1
- package/build-module/components/block-variation-picker/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +4 -1
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/button-block-appender/index.js +22 -26
- package/build-module/components/button-block-appender/index.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +4 -1
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/content-lock/index.js +2 -0
- package/build-module/components/content-lock/index.js.map +1 -0
- package/build-module/components/content-lock/modify-content-lock-menu-item.js +57 -0
- package/build-module/components/content-lock/modify-content-lock-menu-item.js.map +1 -0
- package/build-module/components/editor-styles/index.js +4 -3
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +8 -12
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +7 -4
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.native.js +2 -2
- package/build-module/components/global-styles/color-panel.native.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +36 -39
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +4 -1
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/shadow-panel-components.js +14 -17
- package/build-module/components/global-styles/shadow-panel-components.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +17 -6
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/global-styles/utils.js +4 -6
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/grid/grid-item-movers.js +3 -3
- package/build-module/components/grid/grid-item-movers.js.map +1 -1
- package/build-module/components/grid/grid-item-resizer.js +2 -2
- package/build-module/components/grid/grid-item-resizer.js.map +1 -1
- package/build-module/components/iframe/get-compatibility-styles.js +1 -1
- package/build-module/components/iframe/get-compatibility-styles.js.map +1 -1
- package/build-module/components/iframe/index.js +5 -5
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +2 -4
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -3
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +4 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js +4 -1
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +23 -13
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build-module/components/inserter/index.js +4 -11
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/library.js +2 -4
- package/build-module/components/inserter/library.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +3 -3
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +1 -8
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +10 -8
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-tab.js +4 -1
- package/build-module/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +7 -24
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +5 -6
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +4 -4
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/inserter-listbox/index.js +3 -11
- package/build-module/components/inserter-listbox/index.js.map +1 -1
- package/build-module/components/inserter-listbox/item.js +7 -12
- package/build-module/components/inserter-listbox/item.js.map +1 -1
- package/build-module/components/inserter-listbox/row.js +2 -10
- package/build-module/components/inserter-listbox/row.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/index.js +4 -1
- package/build-module/components/inspector-controls-tabs/index.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/inspector-popover-header/index.js +8 -2
- package/build-module/components/inspector-popover-header/index.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +7 -4
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/link-control/index.js +19 -10
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +4 -1
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +4 -1
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/index.js +3 -7
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +32 -11
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +8 -1
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +19 -19
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/event-listeners/paste-handler.js +12 -1
- package/build-module/components/rich-text/event-listeners/paste-handler.js.map +1 -1
- package/build-module/components/rich-text/index.js +39 -31
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-mark-persistent.js +5 -5
- package/build-module/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js +4 -1
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +9 -10
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/linked-button.js +28 -0
- package/build-module/components/spacing-sizes-control/linked-button.js.map +1 -0
- package/build-module/components/spacing-sizes-control/utils.js +4 -15
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/tool-selector/index.js +4 -1
- package/build-module/components/tool-selector/index.js.map +1 -1
- package/build-module/components/url-input/button.js +12 -3
- package/build-module/components/url-input/button.js.map +1 -1
- package/build-module/components/url-input/index.js +4 -1
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +31 -7
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/writing-flow/index.js +2 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +4 -1
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-event-redirect.js +60 -0
- package/build-module/components/writing-flow/use-event-redirect.js.map +1 -0
- package/build-module/components/writing-flow/use-input.js +31 -1
- package/build-module/components/writing-flow/use-input.js.map +1 -1
- package/build-module/components/writing-flow/use-select-all.js +14 -1
- package/build-module/components/writing-flow/use-select-all.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +16 -2
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +4 -4
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-flow/utils.js +26 -0
- package/build-module/components/writing-flow/utils.js.map +1 -1
- package/build-module/hooks/block-bindings.js +35 -31
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +10 -30
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/duotone.js +0 -4
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/layout.js +4 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/spacing-visualizer.js +3 -3
- package/build-module/hooks/spacing-visualizer.js.map +1 -1
- package/build-module/hooks/style.js +1 -5
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +19 -20
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/use-zoom-out.js +7 -7
- package/build-module/hooks/use-zoom-out.js.map +1 -1
- package/build-module/layouts/constrained.js +44 -45
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/layouts/flex.js +4 -1
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/grid.js +21 -18
- package/build-module/layouts/grid.js.map +1 -1
- package/build-module/layouts/utils.js +1 -7
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/private-apis.js +3 -4
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +2 -7
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +1 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-keys.js +1 -0
- package/build-module/store/private-keys.js.map +1 -1
- package/build-module/store/private-selectors.js +15 -18
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +1 -9
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +22 -46
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +46 -0
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/block-bindings.js +17 -12
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-module/utils/dom.js +99 -0
- package/build-module/utils/dom.js.map +1 -1
- package/build-module/utils/get-font-styles-and-weights.js +4 -4
- package/build-module/utils/get-font-styles-and-weights.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +120 -16
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +19 -11
- package/build-style/content.css +19 -11
- package/build-style/style-rtl.css +27 -117
- package/build-style/style.css +27 -117
- package/build-types/utils/dom.d.ts +25 -0
- package/build-types/utils/dom.d.ts.map +1 -1
- package/package.json +34 -32
- package/src/components/block-alignment-matrix-control/index.js +1 -1
- package/src/components/block-breadcrumb/index.js +2 -2
- package/src/components/block-breadcrumb/style.scss +1 -30
- package/src/components/block-canvas/index.js +9 -1
- package/src/components/block-compare/block-view.js +6 -1
- package/src/components/block-compare/test/__snapshots__/block-view.js.snap +1 -1
- package/src/components/block-draggable/content.scss +1 -1
- package/src/components/block-draggable/index.js +4 -4
- package/src/components/block-draggable/style.scss +1 -1
- package/src/components/block-draggable/use-scroll-when-dragging.js +25 -25
- package/src/components/block-edit/multiple-usage-warning.js +2 -0
- package/src/components/block-inspector/index.js +22 -7
- package/src/components/block-inspector/style.scss +2 -4
- package/src/components/block-list/block-invalid-warning.js +3 -2
- package/src/components/block-list/block.js +6 -2
- package/src/components/block-list/content.scss +23 -3
- package/src/components/block-list/index.js +59 -38
- package/src/components/block-list/use-block-props/index.js +3 -0
- package/src/components/block-list/use-block-props/use-focus-first-element.js +1 -0
- package/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js +56 -0
- package/src/components/block-list/zoom-out-separator.js +110 -0
- package/src/components/block-lock/style.scss +1 -1
- package/src/components/block-lock/toolbar.js +3 -3
- package/src/components/block-mover/button.js +1 -0
- package/src/components/block-mover/index.js +1 -0
- package/src/components/block-mover/style.scss +1 -1
- package/src/components/block-navigation/dropdown.js +2 -0
- package/src/components/block-pattern-setup/index.js +3 -15
- package/src/components/block-pattern-setup/setup-toolbar.js +17 -4
- package/src/components/block-pattern-setup/style.scss +2 -2
- package/src/components/block-patterns-list/index.js +15 -18
- package/src/components/block-patterns-list/style.scss +2 -2
- package/src/components/block-patterns-paging/index.js +6 -0
- package/src/components/block-popover/index.js +7 -28
- package/src/components/block-popover/style.scss +1 -1
- package/src/components/block-quick-navigation/index.js +2 -0
- package/src/components/block-settings-menu-controls/index.js +7 -1
- package/src/components/block-switcher/index.js +45 -23
- package/src/components/block-switcher/pattern-transformations-menu.js +3 -12
- package/src/components/block-switcher/style.scss +5 -30
- package/src/components/block-toolbar/index.js +27 -11
- package/src/components/block-toolbar/shuffle.js +9 -7
- package/src/components/block-toolbar/style.scss +4 -1
- package/src/components/block-tools/block-selection-button.js +4 -0
- package/src/components/block-tools/block-toolbar-popover.js +10 -6
- package/src/components/block-tools/index.js +1 -1
- package/src/components/block-tools/style.scss +3 -4
- package/src/components/block-tools/use-block-toolbar-popover-props.js +2 -1
- package/src/components/block-tools/zoom-out-mode-inserters.js +2 -17
- package/src/components/block-tools/zoom-out-popover.js +3 -7
- package/src/components/block-tools/zoom-out-toolbar.js +31 -6
- package/src/components/block-variation-picker/README.md +2 -2
- package/src/components/block-variation-picker/index.js +6 -1
- package/src/components/block-variation-transforms/index.js +2 -0
- package/src/components/block-variation-transforms/style.scss +1 -1
- package/src/components/button-block-appender/content.scss +0 -1
- package/src/components/button-block-appender/index.js +30 -28
- package/src/components/color-palette/test/control.js +15 -2
- package/src/components/colors-gradients/dropdown.js +5 -1
- package/src/components/colors-gradients/style.scss +4 -4
- package/src/components/content-lock/index.js +1 -0
- package/src/components/content-lock/modify-content-lock-menu-item.js +58 -0
- package/src/components/default-block-appender/content.scss +0 -1
- package/src/components/editor-styles/index.js +4 -3
- package/src/components/global-styles/background-panel.js +6 -14
- package/src/components/global-styles/color-panel.js +8 -4
- package/src/components/global-styles/color-panel.native.js +2 -2
- package/src/components/global-styles/dimensions-panel.js +40 -40
- package/src/components/global-styles/filters-panel.js +5 -1
- package/src/components/global-styles/shadow-panel-components.js +11 -15
- package/src/components/global-styles/style.scss +3 -4
- package/src/components/global-styles/test/typography-utils.js +96 -5
- package/src/components/global-styles/test/utils.js +10 -0
- package/src/components/global-styles/typography-utils.js +22 -6
- package/src/components/global-styles/utils.js +4 -6
- package/src/components/grid/grid-item-movers.js +3 -3
- package/src/components/grid/grid-item-resizer.js +2 -2
- package/src/components/grid/style.scss +1 -1
- package/src/components/iframe/get-compatibility-styles.js +6 -1
- package/src/components/iframe/index.js +5 -5
- package/src/components/inner-blocks/index.js +2 -2
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -3
- package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +2 -0
- package/src/components/inserter/block-patterns-tab/index.js +2 -0
- package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +32 -15
- package/src/components/inserter/index.js +4 -10
- package/src/components/inserter/library.js +0 -2
- package/src/components/inserter/media-tab/hooks.js +3 -3
- package/src/components/inserter/media-tab/media-list.js +1 -7
- package/src/components/inserter/media-tab/media-preview.js +15 -8
- package/src/components/inserter/media-tab/media-tab.js +2 -0
- package/src/components/inserter/menu.js +15 -29
- package/src/components/inserter/quick-inserter.js +3 -4
- package/src/components/inserter/style.scss +10 -17
- package/src/components/inserter-list-item/index.js +4 -4
- package/src/components/inserter-list-item/style.scss +1 -3
- package/src/components/inserter-listbox/index.js +2 -11
- package/src/components/inserter-listbox/item.js +12 -14
- package/src/components/inserter-listbox/row.js +2 -9
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/index.js +2 -0
- package/src/components/inspector-controls-tabs/settings-tab.js +1 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +5 -2
- package/src/components/inspector-popover-header/index.js +4 -0
- package/src/components/letter-spacing-control/README.md +8 -1
- package/src/components/letter-spacing-control/index.js +7 -4
- package/src/components/link-control/index.js +17 -8
- package/src/components/link-control/settings-drawer.js +2 -0
- package/src/components/link-control/style.scss +1 -3
- package/src/components/list-view/block-select-button.js +2 -0
- package/src/components/list-view/index.js +3 -8
- package/src/components/list-view/style.scss +14 -16
- package/src/components/media-placeholder/README.md +2 -2
- package/src/components/media-placeholder/index.js +21 -4
- package/src/components/media-replace-flow/index.js +12 -1
- package/src/components/provider/use-block-sync.js +20 -20
- package/src/components/responsive-block-control/README.md +3 -27
- package/src/components/rich-text/content.scss +1 -1
- package/src/components/rich-text/event-listeners/paste-handler.js +6 -1
- package/src/components/rich-text/index.js +54 -41
- package/src/components/rich-text/style.scss +1 -1
- package/src/components/rich-text/use-mark-persistent.js +5 -5
- package/src/components/skip-to-selected-block/index.js +2 -0
- package/src/components/spacing-sizes-control/index.js +10 -13
- package/src/components/spacing-sizes-control/linked-button.js +32 -0
- package/src/components/spacing-sizes-control/style.scss +1 -0
- package/src/components/spacing-sizes-control/test/utils.js +14 -15
- package/src/components/spacing-sizes-control/utils.js +5 -18
- package/src/components/tool-selector/index.js +2 -0
- package/src/components/url-input/button.js +6 -0
- package/src/components/url-input/index.js +2 -0
- package/src/components/url-popover/stories/index.story.js +7 -1
- package/src/components/use-block-drop-zone/index.js +37 -5
- package/src/components/warning/content.scss +3 -10
- package/src/components/writing-flow/index.js +2 -0
- package/src/components/writing-flow/use-arrow-nav.js +9 -2
- package/src/components/writing-flow/use-event-redirect.js +72 -0
- package/src/components/writing-flow/use-input.js +36 -1
- package/src/components/writing-flow/use-select-all.js +18 -1
- package/src/components/writing-flow/use-selection-observer.js +23 -3
- package/src/components/writing-flow/use-tab-nav.js +4 -4
- package/src/components/writing-flow/utils.js +30 -0
- package/src/hooks/block-bindings.js +42 -43
- package/src/hooks/block-bindings.scss +1 -9
- package/src/hooks/content-lock-ui.js +11 -36
- package/src/hooks/duotone.js +0 -4
- package/src/hooks/layout.js +2 -1
- package/src/hooks/layout.scss +5 -27
- package/src/hooks/spacing-visualizer.js +3 -3
- package/src/hooks/style.js +1 -4
- package/src/hooks/use-bindings-attributes.js +23 -24
- package/src/hooks/use-zoom-out.js +7 -7
- package/src/layouts/constrained.js +53 -48
- package/src/layouts/flex.js +2 -0
- package/src/layouts/grid.js +29 -22
- package/src/layouts/test/grid.js +2 -2
- package/src/layouts/test/utils.js +6 -8
- package/src/layouts/utils.js +1 -9
- package/src/private-apis.js +2 -2
- package/src/store/actions.js +4 -6
- package/src/store/private-actions.js +1 -0
- package/src/store/private-keys.js +1 -0
- package/src/store/private-selectors.js +18 -14
- package/src/store/reducer.js +0 -7
- package/src/store/selectors.js +32 -51
- package/src/store/utils.js +50 -0
- package/src/utils/block-bindings.js +15 -16
- package/src/utils/dom.js +117 -0
- package/src/utils/get-font-styles-and-weights.js +12 -4
- package/src/utils/test/get-font-styles-and-weights.js +148 -0
- package/src/utils/test/transform-styles.js +259 -50
- package/src/utils/transform-styles/index.js +132 -21
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/spacing-sizes-control/sides-dropdown/index.js +0 -86
- package/build/components/spacing-sizes-control/sides-dropdown/index.js.map +0 -1
- package/build-module/components/spacing-sizes-control/sides-dropdown/index.js +0 -81
- package/build-module/components/spacing-sizes-control/sides-dropdown/index.js.map +0 -1
- package/src/components/spacing-sizes-control/sides-dropdown/index.js +0 -91
- package/src/utils/test/__snapshots__/transform-styles.js.snap +0 -109
package/build/store/utils.js
CHANGED
|
@@ -4,16 +4,64 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAllPatternsDependants = exports.checkAllowListRecursive = exports.checkAllowList = void 0;
|
|
7
|
+
exports.getGrammar = getGrammar;
|
|
7
8
|
exports.getInsertBlockTypeDependants = getInsertBlockTypeDependants;
|
|
9
|
+
exports.getParsedPattern = getParsedPattern;
|
|
8
10
|
exports.withRootClientIdOptionKey = void 0;
|
|
11
|
+
var _blocks = require("@wordpress/blocks");
|
|
12
|
+
var _blockSerializationDefaultParser = require("@wordpress/block-serialization-default-parser");
|
|
9
13
|
var _privateKeys = require("./private-keys");
|
|
10
14
|
var _lockUnlock = require("../lock-unlock");
|
|
11
15
|
var _constants = require("./constants");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* Internal dependencies
|
|
14
22
|
*/
|
|
15
23
|
|
|
16
24
|
const withRootClientIdOptionKey = exports.withRootClientIdOptionKey = Symbol('withRootClientId');
|
|
25
|
+
const parsedPatternCache = new WeakMap();
|
|
26
|
+
const grammarMapCache = new WeakMap();
|
|
27
|
+
function parsePattern(pattern) {
|
|
28
|
+
const blocks = (0, _blocks.parse)(pattern.content, {
|
|
29
|
+
__unstableSkipMigrationLogs: true
|
|
30
|
+
});
|
|
31
|
+
if (blocks.length === 1) {
|
|
32
|
+
blocks[0].attributes = {
|
|
33
|
+
...blocks[0].attributes,
|
|
34
|
+
metadata: {
|
|
35
|
+
...(blocks[0].attributes.metadata || {}),
|
|
36
|
+
categories: pattern.categories,
|
|
37
|
+
patternName: pattern.name,
|
|
38
|
+
name: blocks[0].attributes.metadata?.name || pattern.title
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...pattern,
|
|
44
|
+
blocks
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function getParsedPattern(pattern) {
|
|
48
|
+
let parsedPattern = parsedPatternCache.get(pattern);
|
|
49
|
+
if (!parsedPattern) {
|
|
50
|
+
parsedPattern = parsePattern(pattern);
|
|
51
|
+
parsedPatternCache.set(pattern, parsedPattern);
|
|
52
|
+
}
|
|
53
|
+
return parsedPattern;
|
|
54
|
+
}
|
|
55
|
+
function getGrammar(pattern) {
|
|
56
|
+
let grammarMap = grammarMapCache.get(pattern);
|
|
57
|
+
if (!grammarMap) {
|
|
58
|
+
grammarMap = (0, _blockSerializationDefaultParser.parse)(pattern.content);
|
|
59
|
+
// Block names are null only at the top level for whitespace.
|
|
60
|
+
grammarMap = grammarMap.filter(block => block.blockName !== null);
|
|
61
|
+
grammarMapCache.set(pattern, grammarMap);
|
|
62
|
+
}
|
|
63
|
+
return grammarMap;
|
|
64
|
+
}
|
|
17
65
|
const checkAllowList = (list, item, defaultResult = null) => {
|
|
18
66
|
if (typeof list === 'boolean') {
|
|
19
67
|
return list;
|
package/build/store/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_blocks","require","_blockSerializationDefaultParser","_privateKeys","_lockUnlock","_constants","withRootClientIdOptionKey","exports","Symbol","parsedPatternCache","WeakMap","grammarMapCache","parsePattern","pattern","blocks","parse","content","__unstableSkipMigrationLogs","length","attributes","metadata","categories","patternName","name","title","getParsedPattern","parsedPattern","get","set","getGrammar","grammarMap","grammarParse","filter","block","blockName","checkAllowList","list","item","defaultResult","Array","isArray","includes","checkAllowListRecursive","allowedBlockTypes","blocksQueue","shift","isAllowed","innerBlocks","forEach","innerBlock","push","getAllPatternsDependants","select","state","settings","__experimentalBlockPatterns","__experimentalUserPatternCategories","__experimentalReusableBlocks","selectBlockPatternsKey","blockPatterns","unlock","STORE_NAME","getReusableBlocks","getInsertBlockTypeDependants","rootClientId","blockListSettings","byClientId","templateLock","blockEditingModes"],"sources":["@wordpress/block-editor/src/store/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { parse } from '@wordpress/blocks';\nimport { parse as grammarParse } from '@wordpress/block-serialization-default-parser';\n\n/**\n * Internal dependencies\n */\nimport { selectBlockPatternsKey } from './private-keys';\nimport { unlock } from '../lock-unlock';\nimport { STORE_NAME } from './constants';\n\nexport const withRootClientIdOptionKey = Symbol( 'withRootClientId' );\n\nconst parsedPatternCache = new WeakMap();\nconst grammarMapCache = new WeakMap();\n\nfunction parsePattern( pattern ) {\n\tconst blocks = parse( pattern.content, {\n\t\t__unstableSkipMigrationLogs: true,\n\t} );\n\tif ( blocks.length === 1 ) {\n\t\tblocks[ 0 ].attributes = {\n\t\t\t...blocks[ 0 ].attributes,\n\t\t\tmetadata: {\n\t\t\t\t...( blocks[ 0 ].attributes.metadata || {} ),\n\t\t\t\tcategories: pattern.categories,\n\t\t\t\tpatternName: pattern.name,\n\t\t\t\tname: blocks[ 0 ].attributes.metadata?.name || pattern.title,\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\t...pattern,\n\t\tblocks,\n\t};\n}\n\nexport function getParsedPattern( pattern ) {\n\tlet parsedPattern = parsedPatternCache.get( pattern );\n\tif ( ! parsedPattern ) {\n\t\tparsedPattern = parsePattern( pattern );\n\t\tparsedPatternCache.set( pattern, parsedPattern );\n\t}\n\treturn parsedPattern;\n}\n\nexport function getGrammar( pattern ) {\n\tlet grammarMap = grammarMapCache.get( pattern );\n\tif ( ! grammarMap ) {\n\t\tgrammarMap = grammarParse( pattern.content );\n\t\t// Block names are null only at the top level for whitespace.\n\t\tgrammarMap = grammarMap.filter( ( block ) => block.blockName !== null );\n\t\tgrammarMapCache.set( pattern, grammarMap );\n\t}\n\treturn grammarMap;\n}\n\nexport const checkAllowList = ( list, item, defaultResult = null ) => {\n\tif ( typeof list === 'boolean' ) {\n\t\treturn list;\n\t}\n\tif ( Array.isArray( list ) ) {\n\t\t// TODO: when there is a canonical way to detect that we are editing a post\n\t\t// the following check should be changed to something like:\n\t\t// if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )\n\t\tif ( list.includes( 'core/post-content' ) && item === null ) {\n\t\t\treturn true;\n\t\t}\n\t\treturn list.includes( item );\n\t}\n\treturn defaultResult;\n};\n\nexport const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => {\n\tif ( typeof allowedBlockTypes === 'boolean' ) {\n\t\treturn allowedBlockTypes;\n\t}\n\n\tconst blocksQueue = [ ...blocks ];\n\twhile ( blocksQueue.length > 0 ) {\n\t\tconst block = blocksQueue.shift();\n\n\t\tconst isAllowed = checkAllowList(\n\t\t\tallowedBlockTypes,\n\t\t\tblock.name || block.blockName,\n\t\t\ttrue\n\t\t);\n\t\tif ( ! isAllowed ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tblock.innerBlocks?.forEach( ( innerBlock ) => {\n\t\t\tblocksQueue.push( innerBlock );\n\t\t} );\n\t}\n\n\treturn true;\n};\n\nexport const getAllPatternsDependants = ( select ) => ( state ) => {\n\treturn [\n\t\tstate.settings.__experimentalBlockPatterns,\n\t\tstate.settings.__experimentalUserPatternCategories,\n\t\tstate.settings.__experimentalReusableBlocks,\n\t\tstate.settings[ selectBlockPatternsKey ]?.( select ),\n\t\tstate.blockPatterns,\n\t\tunlock( select( STORE_NAME ) ).getReusableBlocks(),\n\t];\n};\n\nexport function getInsertBlockTypeDependants( state, rootClientId ) {\n\treturn [\n\t\tstate.blockListSettings[ rootClientId ],\n\t\tstate.blocks.byClientId.get( rootClientId ),\n\t\tstate.settings.allowedBlockTypes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockEditingModes,\n\t];\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gCAAA,GAAAD,OAAA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C/BQ,iBAAiB,EACjBV,KAAK,CAACV,IAAI,IAAIU,KAAK,CAACC,SAAS,EAC7B,IACD,CAAC;IACD,IAAK,CAAEY,SAAS,EAAG;MAClB,OAAO,KAAK;IACb;IAEAb,KAAK,CAACc,WAAW,EAAEC,OAAO,CAAIC,UAAU,IAAM;MAC7CL,WAAW,CAACM,IAAI,CAAED,UAAW,CAAC;IAC/B,CAAE,CAAC;EACJ;EAEA,OAAO,IAAI;AACZ,CAAC;AAAC1C,OAAA,CAAAmC,uBAAA,GAAAA,uBAAA;AAEK,MAAMS,wBAAwB,GAAKC,MAAM,IAAQC,KAAK,IAAM;EAClE,OAAO,CACNA,KAAK,CAACC,QAAQ,CAACC,2BAA2B,EAC1CF,KAAK,CAACC,QAAQ,CAACE,mCAAmC,EAClDH,KAAK,CAACC,QAAQ,CAACG,4BAA4B,EAC3CJ,KAAK,CAACC,QAAQ,CAAEI,mCAAsB,CAAE,GAAIN,MAAO,CAAC,EACpDC,KAAK,CAACM,aAAa,EACnB,IAAAC,kBAAM,EAAER,MAAM,CAAES,qBAAW,CAAE,CAAC,CAACC,iBAAiB,CAAC,CAAC,CAClD;AACF,CAAC;AAACvD,OAAA,CAAA4C,wBAAA,GAAAA,wBAAA;AAEK,SAASY,4BAA4BA,CAAEV,KAAK,EAAEW,YAAY,EAAG;EACnE,OAAO,CACNX,KAAK,CAACY,iBAAiB,CAAED,YAAY,CAAE,EACvCX,KAAK,CAACvC,MAAM,CAACoD,UAAU,CAACvC,GAAG,CAAEqC,YAAa,CAAC,EAC3CX,KAAK,CAACC,QAAQ,CAACX,iBAAiB,EAChCU,KAAK,CAACC,QAAQ,CAACa,YAAY,EAC3Bd,KAAK,CAACe,iBAAiB,CACvB;AACF","ignoreList":[]}
|
|
@@ -15,6 +15,9 @@ var _blockEdit = require("../components/block-edit");
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
function isObjectEmpty(object) {
|
|
19
|
+
return !object || Object.keys(object).length === 0;
|
|
20
|
+
}
|
|
18
21
|
function useBlockBindingsUtils() {
|
|
19
22
|
const {
|
|
20
23
|
clientId
|
|
@@ -24,7 +27,7 @@ function useBlockBindingsUtils() {
|
|
|
24
27
|
} = (0, _data.useDispatch)(_store.store);
|
|
25
28
|
const {
|
|
26
29
|
getBlockAttributes
|
|
27
|
-
} = (0, _data.
|
|
30
|
+
} = (0, _data.useRegistry)().select(_store.store);
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* Updates the value of the bindings connected to block attributes.
|
|
@@ -57,10 +60,13 @@ function useBlockBindingsUtils() {
|
|
|
57
60
|
*/
|
|
58
61
|
const updateBlockBindings = bindings => {
|
|
59
62
|
const {
|
|
60
|
-
metadata
|
|
63
|
+
metadata: {
|
|
64
|
+
bindings: currentBindings,
|
|
65
|
+
...metadata
|
|
66
|
+
} = {}
|
|
61
67
|
} = getBlockAttributes(clientId);
|
|
62
68
|
const newBindings = {
|
|
63
|
-
...
|
|
69
|
+
...currentBindings
|
|
64
70
|
};
|
|
65
71
|
Object.entries(bindings).forEach(([attribute, binding]) => {
|
|
66
72
|
if (!binding && newBindings[attribute]) {
|
|
@@ -73,11 +79,11 @@ function useBlockBindingsUtils() {
|
|
|
73
79
|
...metadata,
|
|
74
80
|
bindings: newBindings
|
|
75
81
|
};
|
|
76
|
-
if (
|
|
82
|
+
if (isObjectEmpty(newMetadata.bindings)) {
|
|
77
83
|
delete newMetadata.bindings;
|
|
78
84
|
}
|
|
79
85
|
updateBlockAttributes(clientId, {
|
|
80
|
-
metadata:
|
|
86
|
+
metadata: isObjectEmpty(newMetadata) ? undefined : newMetadata
|
|
81
87
|
});
|
|
82
88
|
};
|
|
83
89
|
|
|
@@ -94,14 +100,13 @@ function useBlockBindingsUtils() {
|
|
|
94
100
|
*/
|
|
95
101
|
const removeAllBlockBindings = () => {
|
|
96
102
|
const {
|
|
97
|
-
metadata
|
|
103
|
+
metadata: {
|
|
104
|
+
bindings,
|
|
105
|
+
...metadata
|
|
106
|
+
} = {}
|
|
98
107
|
} = getBlockAttributes(clientId);
|
|
99
|
-
const newMetadata = {
|
|
100
|
-
...metadata
|
|
101
|
-
};
|
|
102
|
-
delete newMetadata.bindings;
|
|
103
108
|
updateBlockAttributes(clientId, {
|
|
104
|
-
metadata:
|
|
109
|
+
metadata: isObjectEmpty(metadata) ? undefined : metadata
|
|
105
110
|
});
|
|
106
111
|
};
|
|
107
112
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_store","_blockEdit","useBlockBindingsUtils","clientId","useBlockEditContext","updateBlockAttributes","useDispatch","blockEditorStore","getBlockAttributes","
|
|
1
|
+
{"version":3,"names":["_data","require","_store","_blockEdit","isObjectEmpty","object","Object","keys","length","useBlockBindingsUtils","clientId","useBlockEditContext","updateBlockAttributes","useDispatch","blockEditorStore","getBlockAttributes","useRegistry","select","updateBlockBindings","bindings","metadata","currentBindings","newBindings","entries","forEach","attribute","binding","newMetadata","undefined","removeAllBlockBindings"],"sources":["@wordpress/block-editor/src/utils/block-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useRegistry } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useBlockEditContext } from '../components/block-edit';\n\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\nexport function useBlockBindingsUtils() {\n\tconst { clientId } = useBlockEditContext();\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst { getBlockAttributes } = useRegistry().select( blockEditorStore );\n\n\t/**\n\t * Updates the value of the bindings connected to block attributes.\n\t * It removes the binding when the new value is `undefined`.\n\t *\n\t * @param {Object} bindings Bindings including the attributes to update and the new object.\n\t * @param {string} bindings.source The source name to connect to.\n\t * @param {Object} [bindings.args] Object containing the arguments needed by the source.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { updateBlockBindings } = useBlockBindingsUtils();\n\t * updateBlockBindings( {\n\t * url: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'url_custom_field',\n\t * },\n\t * \t },\n\t * alt: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'text_custom_field',\n\t * },\n\t * \t }\n\t * } );\n\t * ```\n\t */\n\tconst updateBlockBindings = ( bindings ) => {\n\t\tconst { metadata: { bindings: currentBindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tconst newBindings = { ...currentBindings };\n\n\t\tObject.entries( bindings ).forEach( ( [ attribute, binding ] ) => {\n\t\t\tif ( ! binding && newBindings[ attribute ] ) {\n\t\t\t\tdelete newBindings[ attribute ];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnewBindings[ attribute ] = binding;\n\t\t} );\n\n\t\tconst newMetadata = {\n\t\t\t...metadata,\n\t\t\tbindings: newBindings,\n\t\t};\n\n\t\tif ( isObjectEmpty( newMetadata.bindings ) ) {\n\t\t\tdelete newMetadata.bindings;\n\t\t}\n\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,\n\t\t} );\n\t};\n\n\t/**\n\t * Removes the bindings property of the `metadata` attribute.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { removeAllBlockBindings } = useBlockBindingsUtils();\n\t * removeAllBlockBindings();\n\t * ```\n\t */\n\tconst removeAllBlockBindings = () => {\n\t\tconst { metadata: { bindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( metadata ) ? undefined : metadata,\n\t\t} );\n\t};\n\n\treturn { updateBlockBindings, removeAllBlockBindings };\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OA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AAKlB,aAAa,CAAEuB,WAAW,CAACR,QAAS,CAAC,EAAG;MAC5C,OAAOQ,WAAW,CAACR,QAAQ;IAC5B;IAEAP,qBAAqB,CAAEF,QAAQ,EAAE;MAChCU,QAAQ,EAAEhB,aAAa,CAAEuB,WAAY,CAAC,GAAGC,SAAS,GAAGD;IACtD,CAAE,CAAC;EACJ,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAME,sBAAsB,GAAGA,CAAA,KAAM;IACpC,MAAM;MAAET,QAAQ,EAAE;QAAED,QAAQ;QAAE,GAAGC;MAAS,CAAC,GAAG,CAAC;IAAE,CAAC,GACjDL,kBAAkB,CAAEL,QAAS,CAAC;IAC/BE,qBAAqB,CAAEF,QAAQ,EAAE;MAChCU,QAAQ,EAAEhB,aAAa,CAAEgB,QAAS,CAAC,GAAGQ,SAAS,GAAGR;IACnD,CAAE,CAAC;EACJ,CAAC;EAED,OAAO;IAAEF,mBAAmB;IAAEW;EAAuB,CAAC;AACvD","ignoreList":[]}
|
package/build/utils/dom.js
CHANGED
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBlockClientId = getBlockClientId;
|
|
7
|
+
exports.getVisibleElementBounds = getVisibleElementBounds;
|
|
7
8
|
exports.isInSameBlock = isInSameBlock;
|
|
8
9
|
exports.isInsideRootBlock = isInsideRootBlock;
|
|
10
|
+
exports.rectUnion = rectUnion;
|
|
9
11
|
const BLOCK_SELECTOR = '.block-editor-block-list__block';
|
|
10
12
|
const APPENDER_SELECTOR = '.block-list-appender';
|
|
11
13
|
const BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender';
|
|
@@ -59,4 +61,103 @@ function getBlockClientId(node) {
|
|
|
59
61
|
}
|
|
60
62
|
return blockNode.id.slice('block-'.length);
|
|
61
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Calculates the union of two rectangles.
|
|
67
|
+
*
|
|
68
|
+
* @param {DOMRect} rect1 First rectangle.
|
|
69
|
+
* @param {DOMRect} rect2 Second rectangle.
|
|
70
|
+
* @return {DOMRect} Union of the two rectangles.
|
|
71
|
+
*/
|
|
72
|
+
function rectUnion(rect1, rect2) {
|
|
73
|
+
const left = Math.min(rect1.left, rect2.left);
|
|
74
|
+
const right = Math.max(rect1.right, rect2.right);
|
|
75
|
+
const bottom = Math.max(rect1.bottom, rect2.bottom);
|
|
76
|
+
const top = Math.min(rect1.top, rect2.top);
|
|
77
|
+
return new window.DOMRectReadOnly(left, top, right - left, bottom - top);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns whether an element is visible.
|
|
82
|
+
*
|
|
83
|
+
* @param {Element} element Element.
|
|
84
|
+
* @return {boolean} Whether the element is visible.
|
|
85
|
+
*/
|
|
86
|
+
function isElementVisible(element) {
|
|
87
|
+
const viewport = element.ownerDocument.defaultView;
|
|
88
|
+
if (!viewport) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Check for <VisuallyHidden> component.
|
|
93
|
+
if (element.classList.contains('components-visually-hidden')) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const bounds = element.getBoundingClientRect();
|
|
97
|
+
if (bounds.width === 0 || bounds.height === 0) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Older browsers, e.g. Safari < 17.4 may not support the `checkVisibility` method.
|
|
102
|
+
if (element.checkVisibility) {
|
|
103
|
+
return element.checkVisibility?.({
|
|
104
|
+
opacityProperty: true,
|
|
105
|
+
contentVisibilityAuto: true,
|
|
106
|
+
visibilityProperty: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const style = viewport.getComputedStyle(element);
|
|
110
|
+
if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the rect of the element including all visible nested elements.
|
|
118
|
+
*
|
|
119
|
+
* Visible nested elements, including elements that overflow the parent, are
|
|
120
|
+
* taken into account.
|
|
121
|
+
*
|
|
122
|
+
* This function is useful for calculating the visible area of a block that
|
|
123
|
+
* contains nested elements that overflow the block, e.g. the Navigation block,
|
|
124
|
+
* which can contain overflowing Submenu blocks.
|
|
125
|
+
*
|
|
126
|
+
* The returned rect represents the full extent of the element and its visible
|
|
127
|
+
* children, which may extend beyond the viewport.
|
|
128
|
+
*
|
|
129
|
+
* @param {Element} element Element.
|
|
130
|
+
* @return {DOMRect} Bounding client rect of the element and its visible children.
|
|
131
|
+
*/
|
|
132
|
+
function getVisibleElementBounds(element) {
|
|
133
|
+
const viewport = element.ownerDocument.defaultView;
|
|
134
|
+
if (!viewport) {
|
|
135
|
+
return new window.DOMRectReadOnly();
|
|
136
|
+
}
|
|
137
|
+
let bounds = element.getBoundingClientRect();
|
|
138
|
+
const stack = [element];
|
|
139
|
+
let currentElement;
|
|
140
|
+
while (currentElement = stack.pop()) {
|
|
141
|
+
for (const child of currentElement.children) {
|
|
142
|
+
if (isElementVisible(child)) {
|
|
143
|
+
const childBounds = child.getBoundingClientRect();
|
|
144
|
+
bounds = rectUnion(bounds, childBounds);
|
|
145
|
+
stack.push(child);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Take into account the outer horizontal limits of the container in which
|
|
152
|
+
* an element is supposed to be "visible". For example, if an element is
|
|
153
|
+
* positioned -10px to the left of the window x value (0), this function
|
|
154
|
+
* discounts the negative overhang because it's not visible and therefore
|
|
155
|
+
* not to be counted in the visibility calculations. Top and bottom values
|
|
156
|
+
* are not accounted for to accommodate vertical scroll.
|
|
157
|
+
*/
|
|
158
|
+
const left = Math.max(bounds.left, 0);
|
|
159
|
+
const right = Math.min(bounds.right, viewport.innerWidth);
|
|
160
|
+
bounds = new window.DOMRectReadOnly(left, bounds.top, right - left, bounds.height);
|
|
161
|
+
return bounds;
|
|
162
|
+
}
|
|
62
163
|
//# sourceMappingURL=dom.js.map
|
package/build/utils/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BLOCK_SELECTOR","APPENDER_SELECTOR","BLOCK_APPENDER_CLASS","isInSameBlock","a","b","closest","isInsideRootBlock","blockElement","element","parentBlock","join","getBlockClientId","node","nodeType","ELEMENT_NODE","parentNode","elementNode","blockNode","id","slice","length"],"sources":["@wordpress/block-editor/src/utils/dom.js"],"sourcesContent":["const BLOCK_SELECTOR = '.block-editor-block-list__block';\nconst APPENDER_SELECTOR = '.block-list-appender';\nconst BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender';\n\n/**\n * Returns true if two elements are contained within the same block.\n *\n * @param {Element} a First element.\n * @param {Element} b Second element.\n *\n * @return {boolean} Whether elements are in the same block.\n */\nexport function isInSameBlock( a, b ) {\n\treturn a.closest( BLOCK_SELECTOR ) === b.closest( BLOCK_SELECTOR );\n}\n\n/**\n * Returns true if an element is considered part of the block and not its inner\n * blocks or appender.\n *\n * @param {Element} blockElement Block container element.\n * @param {Element} element Element.\n *\n * @return {boolean} Whether an element is considered part of the block and not\n * its inner blocks or appender.\n */\nexport function isInsideRootBlock( blockElement, element ) {\n\tconst parentBlock = element.closest(\n\t\t[ BLOCK_SELECTOR, APPENDER_SELECTOR, BLOCK_APPENDER_CLASS ].join( ',' )\n\t);\n\treturn parentBlock === blockElement;\n}\n\n/**\n * Finds the block client ID given any DOM node inside the block.\n *\n * @param {Node?} node DOM node.\n *\n * @return {string|undefined} Client ID or undefined if the node is not part of\n * a block.\n */\nexport function getBlockClientId( node ) {\n\twhile ( node && node.nodeType !== node.ELEMENT_NODE ) {\n\t\tnode = node.parentNode;\n\t}\n\n\tif ( ! node ) {\n\t\treturn;\n\t}\n\n\tconst elementNode = /** @type {Element} */ ( node );\n\tconst blockNode = elementNode.closest( BLOCK_SELECTOR );\n\n\tif ( ! blockNode ) {\n\t\treturn;\n\t}\n\n\treturn blockNode.id.slice( 'block-'.length );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["BLOCK_SELECTOR","APPENDER_SELECTOR","BLOCK_APPENDER_CLASS","isInSameBlock","a","b","closest","isInsideRootBlock","blockElement","element","parentBlock","join","getBlockClientId","node","nodeType","ELEMENT_NODE","parentNode","elementNode","blockNode","id","slice","length","rectUnion","rect1","rect2","left","Math","min","right","max","bottom","top","window","DOMRectReadOnly","isElementVisible","viewport","ownerDocument","defaultView","classList","contains","bounds","getBoundingClientRect","width","height","checkVisibility","opacityProperty","contentVisibilityAuto","visibilityProperty","style","getComputedStyle","display","visibility","opacity","getVisibleElementBounds","stack","currentElement","pop","child","children","childBounds","push","innerWidth"],"sources":["@wordpress/block-editor/src/utils/dom.js"],"sourcesContent":["const BLOCK_SELECTOR = '.block-editor-block-list__block';\nconst APPENDER_SELECTOR = '.block-list-appender';\nconst BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender';\n\n/**\n * Returns true if two elements are contained within the same block.\n *\n * @param {Element} a First element.\n * @param {Element} b Second element.\n *\n * @return {boolean} Whether elements are in the same block.\n */\nexport function isInSameBlock( a, b ) {\n\treturn a.closest( BLOCK_SELECTOR ) === b.closest( BLOCK_SELECTOR );\n}\n\n/**\n * Returns true if an element is considered part of the block and not its inner\n * blocks or appender.\n *\n * @param {Element} blockElement Block container element.\n * @param {Element} element Element.\n *\n * @return {boolean} Whether an element is considered part of the block and not\n * its inner blocks or appender.\n */\nexport function isInsideRootBlock( blockElement, element ) {\n\tconst parentBlock = element.closest(\n\t\t[ BLOCK_SELECTOR, APPENDER_SELECTOR, BLOCK_APPENDER_CLASS ].join( ',' )\n\t);\n\treturn parentBlock === blockElement;\n}\n\n/**\n * Finds the block client ID given any DOM node inside the block.\n *\n * @param {Node?} node DOM node.\n *\n * @return {string|undefined} Client ID or undefined if the node is not part of\n * a block.\n */\nexport function getBlockClientId( node ) {\n\twhile ( node && node.nodeType !== node.ELEMENT_NODE ) {\n\t\tnode = node.parentNode;\n\t}\n\n\tif ( ! node ) {\n\t\treturn;\n\t}\n\n\tconst elementNode = /** @type {Element} */ ( node );\n\tconst blockNode = elementNode.closest( BLOCK_SELECTOR );\n\n\tif ( ! blockNode ) {\n\t\treturn;\n\t}\n\n\treturn blockNode.id.slice( 'block-'.length );\n}\n\n/**\n * Calculates the union of two rectangles.\n *\n * @param {DOMRect} rect1 First rectangle.\n * @param {DOMRect} rect2 Second rectangle.\n * @return {DOMRect} Union of the two rectangles.\n */\nexport function rectUnion( rect1, rect2 ) {\n\tconst left = Math.min( rect1.left, rect2.left );\n\tconst right = Math.max( rect1.right, rect2.right );\n\tconst bottom = Math.max( rect1.bottom, rect2.bottom );\n\tconst top = Math.min( rect1.top, rect2.top );\n\n\treturn new window.DOMRectReadOnly( left, top, right - left, bottom - top );\n}\n\n/**\n * Returns whether an element is visible.\n *\n * @param {Element} element Element.\n * @return {boolean} Whether the element is visible.\n */\nfunction isElementVisible( element ) {\n\tconst viewport = element.ownerDocument.defaultView;\n\tif ( ! viewport ) {\n\t\treturn false;\n\t}\n\n\t// Check for <VisuallyHidden> component.\n\tif ( element.classList.contains( 'components-visually-hidden' ) ) {\n\t\treturn false;\n\t}\n\n\tconst bounds = element.getBoundingClientRect();\n\tif ( bounds.width === 0 || bounds.height === 0 ) {\n\t\treturn false;\n\t}\n\n\t// Older browsers, e.g. Safari < 17.4 may not support the `checkVisibility` method.\n\tif ( element.checkVisibility ) {\n\t\treturn element.checkVisibility?.( {\n\t\t\topacityProperty: true,\n\t\t\tcontentVisibilityAuto: true,\n\t\t\tvisibilityProperty: true,\n\t\t} );\n\t}\n\n\tconst style = viewport.getComputedStyle( element );\n\n\tif (\n\t\tstyle.display === 'none' ||\n\t\tstyle.visibility === 'hidden' ||\n\t\tstyle.opacity === '0'\n\t) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Returns the rect of the element including all visible nested elements.\n *\n * Visible nested elements, including elements that overflow the parent, are\n * taken into account.\n *\n * This function is useful for calculating the visible area of a block that\n * contains nested elements that overflow the block, e.g. the Navigation block,\n * which can contain overflowing Submenu blocks.\n *\n * The returned rect represents the full extent of the element and its visible\n * children, which may extend beyond the viewport.\n *\n * @param {Element} element Element.\n * @return {DOMRect} Bounding client rect of the element and its visible children.\n */\nexport function getVisibleElementBounds( element ) {\n\tconst viewport = element.ownerDocument.defaultView;\n\tif ( ! viewport ) {\n\t\treturn new window.DOMRectReadOnly();\n\t}\n\n\tlet bounds = element.getBoundingClientRect();\n\n\tconst stack = [ element ];\n\tlet currentElement;\n\n\twhile ( ( currentElement = stack.pop() ) ) {\n\t\tfor ( const child of currentElement.children ) {\n\t\t\tif ( isElementVisible( child ) ) {\n\t\t\t\tconst childBounds = child.getBoundingClientRect();\n\t\t\t\tbounds = rectUnion( bounds, childBounds );\n\t\t\t\tstack.push( child );\n\t\t\t}\n\t\t}\n\t}\n\n\t/*\n\t * Take into account the outer horizontal limits of the container in which\n\t * an element is supposed to be \"visible\". For example, if an element is\n\t * positioned -10px to the left of the window x value (0), this function\n\t * discounts the negative overhang because it's not visible and therefore\n\t * not to be counted in the visibility calculations. Top and bottom values\n\t * are not accounted for to accommodate vertical scroll.\n\t */\n\tconst left = Math.max( bounds.left, 0 );\n\tconst right = Math.min( bounds.right, viewport.innerWidth );\n\tbounds = new window.DOMRectReadOnly(\n\t\tleft,\n\t\tbounds.top,\n\t\tright - left,\n\t\tbounds.height\n\t);\n\n\treturn bounds;\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAMA,cAAc,GAAG,iCAAiC;AACxD,MAAMC,iBAAiB,GAAG,sBAAsB;AAChD,MAAMC,oBAAoB,GAAG,qCAAqC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAAEC,CAAC,EAAEC,CAAC,EAA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,uBAAuBA,CAAE5C,OAAO,EAAG;EAClD,MAAM0B,QAAQ,GAAG1B,OAAO,CAAC2B,aAAa,CAACC,WAAW;EAClD,IAAK,CAAEF,QAAQ,EAAG;IACjB,OAAO,IAAIH,MAAM,CAACC,eAAe,CAAC,CAAC;EACpC;EAEA,IAAIO,MAAM,GAAG/B,OAAO,CAACgC,qBAAqB,CAAC,CAAC;EAE5C,MAAMa,KAAK,GAAG,CAAE7C,OAAO,CAAE;EACzB,IAAI8C,cAAc;EAElB,OAAUA,cAAc,GAAGD,KAAK,CAACE,GAAG,CAAC,CAAC,EAAK;IAC1C,KAAM,MAAMC,KAAK,IAAIF,cAAc,CAACG,QAAQ,EAAG;MAC9C,IAAKxB,gBAAgB,CAAEuB,KAAM,CAAC,EAAG;QAChC,MAAME,WAAW,GAAGF,KAAK,CAAChB,qBAAqB,CAAC,CAAC;QACjDD,MAAM,GAAGlB,SAAS,CAAEkB,MAAM,EAAEmB,WAAY,CAAC;QACzCL,KAAK,CAACM,IAAI,CAAEH,KAAM,CAAC;MACpB;IACD;EACD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAMhC,IAAI,GAAGC,IAAI,CAACG,GAAG,CAAEW,MAAM,CAACf,IAAI,EAAE,CAAE,CAAC;EACvC,MAAMG,KAAK,GAAGF,IAAI,CAACC,GAAG,CAAEa,MAAM,CAACZ,KAAK,EAAEO,QAAQ,CAAC0B,UAAW,CAAC;EAC3DrB,MAAM,GAAG,IAAIR,MAAM,CAACC,eAAe,CAClCR,IAAI,EACJe,MAAM,CAACT,GAAG,EACVH,KAAK,GAAGH,IAAI,EACZe,MAAM,CAACG,MACR,CAAC;EAED,OAAOH,MAAM;AACd","ignoreList":[]}
|
|
@@ -69,7 +69,7 @@ function getFontStylesAndWeights(fontFamilyFaces) {
|
|
|
69
69
|
let isVariableFont = false;
|
|
70
70
|
fontFamilyFaces?.forEach(face => {
|
|
71
71
|
// Check for variable font by looking for a space in the font weight value. e.g. "100 900"
|
|
72
|
-
if (/\s/.test(face.fontWeight.trim())) {
|
|
72
|
+
if ('string' === typeof face.fontWeight && /\s/.test(face.fontWeight.trim())) {
|
|
73
73
|
isVariableFont = true;
|
|
74
74
|
|
|
75
75
|
// Find font weight start and end values.
|
|
@@ -91,16 +91,16 @@ function getFontStylesAndWeights(fontFamilyFaces) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Format font style and weight values.
|
|
94
|
-
const fontWeight = (0, _formatFontWeight.formatFontWeight)(face.fontWeight);
|
|
94
|
+
const fontWeight = (0, _formatFontWeight.formatFontWeight)('number' === typeof face.fontWeight ? face.fontWeight.toString() : face.fontWeight);
|
|
95
95
|
const fontStyle = (0, _formatFontStyle.formatFontStyle)(face.fontStyle);
|
|
96
96
|
|
|
97
97
|
// Create font style and font weight lists without duplicates.
|
|
98
|
-
if (fontStyle) {
|
|
98
|
+
if (fontStyle && Object.keys(fontStyle).length) {
|
|
99
99
|
if (!fontStyles.some(style => style.value === fontStyle.value)) {
|
|
100
100
|
fontStyles.push(fontStyle);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
if (fontWeight) {
|
|
103
|
+
if (fontWeight && Object.keys(fontWeight).length) {
|
|
104
104
|
if (!fontWeights.some(weight => weight.value === fontWeight.value)) {
|
|
105
105
|
if (!isVariableFont) {
|
|
106
106
|
fontWeights.push(fontWeight);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_formatFontStyle","_formatFontWeight","FONT_STYLES","name","_x","value","FONT_WEIGHTS","getFontStylesAndWeights","fontFamilyFaces","fontStyles","fontWeights","combinedStyleAndWeightOptions","isSystemFont","length","isVariableFont","forEach","face","test","fontWeight","trim","startValue","endValue","split","parseInt","slice","i","fontWeightValue","toString","some","weight","push","formatFontWeight","fontStyle","formatFontStyle","style","styleName","styleValue","weightName","weightValue","optionName","sprintf","__","key"],"sources":["@wordpress/block-editor/src/utils/get-font-styles-and-weights.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _x, __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { formatFontStyle } from './format-font-style';\nimport { formatFontWeight } from './format-font-weight';\n\nconst FONT_STYLES = [\n\t{\n\t\tname: _x( 'Regular', 'font style' ),\n\t\tvalue: 'normal',\n\t},\n\t{\n\t\tname: _x( 'Italic', 'font style' ),\n\t\tvalue: 'italic',\n\t},\n];\n\nconst FONT_WEIGHTS = [\n\t{\n\t\tname: _x( 'Thin', 'font weight' ),\n\t\tvalue: '100',\n\t},\n\t{\n\t\tname: _x( 'Extra Light', 'font weight' ),\n\t\tvalue: '200',\n\t},\n\t{\n\t\tname: _x( 'Light', 'font weight' ),\n\t\tvalue: '300',\n\t},\n\t{\n\t\tname: _x( 'Regular', 'font weight' ),\n\t\tvalue: '400',\n\t},\n\t{\n\t\tname: _x( 'Medium', 'font weight' ),\n\t\tvalue: '500',\n\t},\n\t{\n\t\tname: _x( 'Semi Bold', 'font weight' ),\n\t\tvalue: '600',\n\t},\n\t{\n\t\tname: _x( 'Bold', 'font weight' ),\n\t\tvalue: '700',\n\t},\n\t{\n\t\tname: _x( 'Extra Bold', 'font weight' ),\n\t\tvalue: '800',\n\t},\n\t{\n\t\tname: _x( 'Black', 'font weight' ),\n\t\tvalue: '900',\n\t},\n\t{\n\t\tname: _x( 'Extra Black', 'font weight' ),\n\t\tvalue: '1000',\n\t},\n];\n\n/**\n * Builds a list of font style and weight options based on font family faces.\n * Defaults to the standard font styles and weights if no font family faces are provided.\n *\n * @param {Array} fontFamilyFaces font family faces array\n * @return {Object} new object with combined and separated font style and weight properties\n */\nexport function getFontStylesAndWeights( fontFamilyFaces ) {\n\tlet fontStyles = [];\n\tlet fontWeights = [];\n\tconst combinedStyleAndWeightOptions = [];\n\tconst isSystemFont = ! fontFamilyFaces || fontFamilyFaces?.length === 0;\n\tlet isVariableFont = false;\n\n\tfontFamilyFaces?.forEach( ( face ) => {\n\t\t// Check for variable font by looking for a space in the font weight value. e.g. \"100 900\"\n\t\tif ( /\\s/.test( face.fontWeight.trim() ) ) {\n\t\t\tisVariableFont = true;\n\n\t\t\t// Find font weight start and end values.\n\t\t\tlet [ startValue, endValue ] = face.fontWeight.split( ' ' );\n\t\t\tstartValue = parseInt( startValue.slice( 0, 1 ) );\n\t\t\tif ( endValue === '1000' ) {\n\t\t\t\tendValue = 10;\n\t\t\t} else {\n\t\t\t\tendValue = parseInt( endValue.slice( 0, 1 ) );\n\t\t\t}\n\n\t\t\t// Create font weight options for available variable weights.\n\t\t\tfor ( let i = startValue; i <= endValue; i++ ) {\n\t\t\t\tconst fontWeightValue = `${ i.toString() }00`;\n\t\t\t\tif (\n\t\t\t\t\t! fontWeights.some(\n\t\t\t\t\t\t( weight ) => weight.value === fontWeightValue\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tfontWeights.push( formatFontWeight( fontWeightValue ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Format font style and weight values.\n\t\tconst fontWeight = formatFontWeight( face.fontWeight );\n\t\tconst fontStyle = formatFontStyle( face.fontStyle );\n\n\t\t// Create font style and font weight lists without duplicates.\n\t\tif ( fontStyle ) {\n\t\t\tif (\n\t\t\t\t! fontStyles.some(\n\t\t\t\t\t( style ) => style.value === fontStyle.value\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfontStyles.push( fontStyle );\n\t\t\t}\n\t\t}\n\t\tif ( fontWeight ) {\n\t\t\tif (\n\t\t\t\t! fontWeights.some(\n\t\t\t\t\t( weight ) => weight.value === fontWeight.value\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif ( ! isVariableFont ) {\n\t\t\t\t\tfontWeights.push( fontWeight );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} );\n\n\t// If there is no font weight of 600 or above, then include faux bold as an option.\n\tif ( ! fontWeights.some( ( weight ) => weight.value >= '600' ) ) {\n\t\tfontWeights.push( {\n\t\t\tname: _x( 'Bold', 'font weight' ),\n\t\t\tvalue: '700',\n\t\t} );\n\t}\n\n\t// If there is no italic font style, then include faux italic as an option.\n\tif ( ! fontStyles.some( ( style ) => style.value === 'italic' ) ) {\n\t\tfontStyles.push( {\n\t\t\tname: _x( 'Italic', 'font style' ),\n\t\t\tvalue: 'italic',\n\t\t} );\n\t}\n\n\t// Use default font styles and weights for system fonts.\n\tif ( isSystemFont ) {\n\t\tfontStyles = FONT_STYLES;\n\t\tfontWeights = FONT_WEIGHTS;\n\t}\n\n\t// Use default styles and weights if there are no available styles or weights from the provided font faces.\n\tfontStyles = fontStyles.length === 0 ? FONT_STYLES : fontStyles;\n\tfontWeights = fontWeights.length === 0 ? FONT_WEIGHTS : fontWeights;\n\n\t// Generate combined font style and weight options for available fonts.\n\tfontStyles.forEach( ( { name: styleName, value: styleValue } ) => {\n\t\tfontWeights.forEach( ( { name: weightName, value: weightValue } ) => {\n\t\t\tconst optionName =\n\t\t\t\tstyleValue === 'normal'\n\t\t\t\t\t? weightName\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Font weight name. 2: Font style name. */\n\t\t\t\t\t\t\t__( '%1$s %2$s' ),\n\t\t\t\t\t\t\tweightName,\n\t\t\t\t\t\t\tstyleName\n\t\t\t\t\t );\n\n\t\t\tcombinedStyleAndWeightOptions.push( {\n\t\t\t\tkey: `${ styleValue }-${ weightValue }`,\n\t\t\t\tname: optionName,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontStyle: styleValue,\n\t\t\t\t\tfontWeight: weightValue,\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\t} );\n\n\treturn {\n\t\tfontStyles,\n\t\tfontWeights,\n\t\tcombinedStyleAndWeightOptions,\n\t\tisSystemFont,\n\t\tisVariableFont,\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AATA;AACA;AACA;;A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UAAU;EAC/DC,WAAW,GAAGA,WAAW,CAACG,MAAM,KAAK,CAAC,GAAGP,YAAY,GAAGI,WAAW;;EAEnE;EACAD,UAAU,CAACM,OAAO,CAAE,CAAE;IAAEZ,IAAI,EAAEgC,SAAS;IAAE9B,KAAK,EAAE+B;EAAW,CAAC,KAAM;IACjE1B,WAAW,CAACK,OAAO,CAAE,CAAE;MAAEZ,IAAI,EAAEkC,UAAU;MAAEhC,KAAK,EAAEiC;IAAY,CAAC,KAAM;MACpE,MAAMC,UAAU,GACfH,UAAU,KAAK,QAAQ,GACpBC,UAAU,GACV,IAAAG,aAAO,GACP;MACA,IAAAC,QAAE,EAAE,WAAY,CAAC,EACjBJ,UAAU,EACVF,SACA,CAAC;MAELxB,6BAA6B,CAACmB,IAAI,CAAE;QACnCY,GAAG,EAAG,GAAGN,UAAY,IAAIE,WAAa,EAAC;QACvCnC,IAAI,EAAEoC,UAAU;QAChBL,KAAK,EAAE;UACNF,SAAS,EAAEI,UAAU;UACrBlB,UAAU,EAAEoB;QACb;MACD,CAAE,CAAC;IACJ,CAAE,CAAC;EACJ,CAAE,CAAC;EAEH,OAAO;IACN7B,UAAU;IACVC,WAAW;IACXC,6BAA6B;IAC7BC,YAAY;IACZE;EACD,CAAC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_formatFontStyle","_formatFontWeight","FONT_STYLES","name","_x","value","FONT_WEIGHTS","getFontStylesAndWeights","fontFamilyFaces","fontStyles","fontWeights","combinedStyleAndWeightOptions","isSystemFont","length","isVariableFont","forEach","face","fontWeight","test","trim","startValue","endValue","split","parseInt","slice","i","fontWeightValue","toString","some","weight","push","formatFontWeight","fontStyle","formatFontStyle","Object","keys","style","styleName","styleValue","weightName","weightValue","optionName","sprintf","__","key"],"sources":["@wordpress/block-editor/src/utils/get-font-styles-and-weights.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _x, __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { formatFontStyle } from './format-font-style';\nimport { formatFontWeight } from './format-font-weight';\n\nconst FONT_STYLES = [\n\t{\n\t\tname: _x( 'Regular', 'font style' ),\n\t\tvalue: 'normal',\n\t},\n\t{\n\t\tname: _x( 'Italic', 'font style' ),\n\t\tvalue: 'italic',\n\t},\n];\n\nconst FONT_WEIGHTS = [\n\t{\n\t\tname: _x( 'Thin', 'font weight' ),\n\t\tvalue: '100',\n\t},\n\t{\n\t\tname: _x( 'Extra Light', 'font weight' ),\n\t\tvalue: '200',\n\t},\n\t{\n\t\tname: _x( 'Light', 'font weight' ),\n\t\tvalue: '300',\n\t},\n\t{\n\t\tname: _x( 'Regular', 'font weight' ),\n\t\tvalue: '400',\n\t},\n\t{\n\t\tname: _x( 'Medium', 'font weight' ),\n\t\tvalue: '500',\n\t},\n\t{\n\t\tname: _x( 'Semi Bold', 'font weight' ),\n\t\tvalue: '600',\n\t},\n\t{\n\t\tname: _x( 'Bold', 'font weight' ),\n\t\tvalue: '700',\n\t},\n\t{\n\t\tname: _x( 'Extra Bold', 'font weight' ),\n\t\tvalue: '800',\n\t},\n\t{\n\t\tname: _x( 'Black', 'font weight' ),\n\t\tvalue: '900',\n\t},\n\t{\n\t\tname: _x( 'Extra Black', 'font weight' ),\n\t\tvalue: '1000',\n\t},\n];\n\n/**\n * Builds a list of font style and weight options based on font family faces.\n * Defaults to the standard font styles and weights if no font family faces are provided.\n *\n * @param {Array} fontFamilyFaces font family faces array\n * @return {Object} new object with combined and separated font style and weight properties\n */\nexport function getFontStylesAndWeights( fontFamilyFaces ) {\n\tlet fontStyles = [];\n\tlet fontWeights = [];\n\tconst combinedStyleAndWeightOptions = [];\n\tconst isSystemFont = ! fontFamilyFaces || fontFamilyFaces?.length === 0;\n\tlet isVariableFont = false;\n\n\tfontFamilyFaces?.forEach( ( face ) => {\n\t\t// Check for variable font by looking for a space in the font weight value. e.g. \"100 900\"\n\t\tif (\n\t\t\t'string' === typeof face.fontWeight &&\n\t\t\t/\\s/.test( face.fontWeight.trim() )\n\t\t) {\n\t\t\tisVariableFont = true;\n\n\t\t\t// Find font weight start and end values.\n\t\t\tlet [ startValue, endValue ] = face.fontWeight.split( ' ' );\n\t\t\tstartValue = parseInt( startValue.slice( 0, 1 ) );\n\t\t\tif ( endValue === '1000' ) {\n\t\t\t\tendValue = 10;\n\t\t\t} else {\n\t\t\t\tendValue = parseInt( endValue.slice( 0, 1 ) );\n\t\t\t}\n\n\t\t\t// Create font weight options for available variable weights.\n\t\t\tfor ( let i = startValue; i <= endValue; i++ ) {\n\t\t\t\tconst fontWeightValue = `${ i.toString() }00`;\n\t\t\t\tif (\n\t\t\t\t\t! fontWeights.some(\n\t\t\t\t\t\t( weight ) => weight.value === fontWeightValue\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tfontWeights.push( formatFontWeight( fontWeightValue ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Format font style and weight values.\n\t\tconst fontWeight = formatFontWeight(\n\t\t\t'number' === typeof face.fontWeight\n\t\t\t\t? face.fontWeight.toString()\n\t\t\t\t: face.fontWeight\n\t\t);\n\t\tconst fontStyle = formatFontStyle( face.fontStyle );\n\n\t\t// Create font style and font weight lists without duplicates.\n\t\tif ( fontStyle && Object.keys( fontStyle ).length ) {\n\t\t\tif (\n\t\t\t\t! fontStyles.some(\n\t\t\t\t\t( style ) => style.value === fontStyle.value\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfontStyles.push( fontStyle );\n\t\t\t}\n\t\t}\n\n\t\tif ( fontWeight && Object.keys( fontWeight ).length ) {\n\t\t\tif (\n\t\t\t\t! fontWeights.some(\n\t\t\t\t\t( weight ) => weight.value === fontWeight.value\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif ( ! isVariableFont ) {\n\t\t\t\t\tfontWeights.push( fontWeight );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} );\n\n\t// If there is no font weight of 600 or above, then include faux bold as an option.\n\tif ( ! fontWeights.some( ( weight ) => weight.value >= '600' ) ) {\n\t\tfontWeights.push( {\n\t\t\tname: _x( 'Bold', 'font weight' ),\n\t\t\tvalue: '700',\n\t\t} );\n\t}\n\n\t// If there is no italic font style, then include faux italic as an option.\n\tif ( ! fontStyles.some( ( style ) => style.value === 'italic' ) ) {\n\t\tfontStyles.push( {\n\t\t\tname: _x( 'Italic', 'font style' ),\n\t\t\tvalue: 'italic',\n\t\t} );\n\t}\n\n\t// Use default font styles and weights for system fonts.\n\tif ( isSystemFont ) {\n\t\tfontStyles = FONT_STYLES;\n\t\tfontWeights = FONT_WEIGHTS;\n\t}\n\n\t// Use default styles and weights if there are no available styles or weights from the provided font faces.\n\tfontStyles = fontStyles.length === 0 ? FONT_STYLES : fontStyles;\n\tfontWeights = fontWeights.length === 0 ? FONT_WEIGHTS : fontWeights;\n\n\t// Generate combined font style and weight options for available fonts.\n\tfontStyles.forEach( ( { name: styleName, value: styleValue } ) => {\n\t\tfontWeights.forEach( ( { name: weightName, value: weightValue } ) => {\n\t\t\tconst optionName =\n\t\t\t\tstyleValue === 'normal'\n\t\t\t\t\t? weightName\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Font weight name. 2: Font style name. */\n\t\t\t\t\t\t\t__( '%1$s %2$s' ),\n\t\t\t\t\t\t\tweightName,\n\t\t\t\t\t\t\tstyleName\n\t\t\t\t\t );\n\n\t\t\tcombinedStyleAndWeightOptions.push( {\n\t\t\t\tkey: `${ styleValue }-${ weightValue }`,\n\t\t\t\tname: optionName,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontStyle: styleValue,\n\t\t\t\t\tfontWeight: weightValue,\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\t} );\n\n\treturn {\n\t\tfontStyles,\n\t\tfontWeights,\n\t\tcombinedStyleAndWeightOptions,\n\t\tisSystemFont,\n\t\tisVariableFont,\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IA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0;
|
|
8
|
+
var parsel = _interopRequireWildcard(require("parsel-js"));
|
|
8
9
|
var _postcss = _interopRequireWildcard(require("postcss"));
|
|
9
|
-
var
|
|
10
|
+
var _postcssPrefixSelector = _interopRequireDefault(require("postcss-prefix-selector"));
|
|
10
11
|
var _postcssUrlrebase = _interopRequireDefault(require("postcss-urlrebase"));
|
|
11
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -15,25 +16,120 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
const cacheByWrapperSelector = new Map();
|
|
19
|
+
const ROOT_SELECTOR_TOKENS = [{
|
|
20
|
+
type: 'type',
|
|
21
|
+
content: 'body'
|
|
22
|
+
}, {
|
|
23
|
+
type: 'type',
|
|
24
|
+
content: 'html'
|
|
25
|
+
}, {
|
|
26
|
+
type: 'pseudo-class',
|
|
27
|
+
content: ':root'
|
|
28
|
+
}, {
|
|
29
|
+
type: 'pseudo-class',
|
|
30
|
+
content: ':where(body)'
|
|
31
|
+
}, {
|
|
32
|
+
type: 'pseudo-class',
|
|
33
|
+
content: ':where(:root)'
|
|
34
|
+
}, {
|
|
35
|
+
type: 'pseudo-class',
|
|
36
|
+
content: ':where(html)'
|
|
37
|
+
}];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Prefixes root selectors in a way that ensures consistent specificity.
|
|
41
|
+
* This requires special handling, since prefixing a classname before
|
|
42
|
+
* html, body, or :root will generally result in an invalid selector.
|
|
43
|
+
*
|
|
44
|
+
* Some libraries will simply replace the root selector with the prefix
|
|
45
|
+
* instead, but this results in inconsistent specificity.
|
|
46
|
+
*
|
|
47
|
+
* This function instead inserts the prefix after the root tags but before
|
|
48
|
+
* any other part of the selector. This results in consistent specificity:
|
|
49
|
+
* - If a `:where()` selector is used for the prefix, all selectors output
|
|
50
|
+
* by `transformStyles` will have no specificity increase.
|
|
51
|
+
* - If a classname, id, or something else is used as the prefix, all selectors
|
|
52
|
+
* will have the same specificity bump when transformed.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} prefix The prefix.
|
|
55
|
+
* @param {string} selector The selector.
|
|
56
|
+
*
|
|
57
|
+
* @return {string} The prefixed root selector.
|
|
58
|
+
*/
|
|
59
|
+
function prefixRootSelector(prefix, selector) {
|
|
60
|
+
// Use a tokenizer, since regular expressions are unreliable.
|
|
61
|
+
const tokenized = parsel.tokenize(selector);
|
|
62
|
+
|
|
63
|
+
// Find the last token that contains a root selector by walking back
|
|
64
|
+
// through the tokens.
|
|
65
|
+
const lastRootIndex = tokenized.findLastIndex(({
|
|
66
|
+
content,
|
|
67
|
+
type
|
|
68
|
+
}) => {
|
|
69
|
+
return ROOT_SELECTOR_TOKENS.some(rootSelector => content === rootSelector.content && type === rootSelector.type);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Walk forwards to find the combinator after the last root.
|
|
73
|
+
// This is where the root ends and the rest of the selector begins,
|
|
74
|
+
// and the index to insert before.
|
|
75
|
+
// Doing it this way takes into account that a root selector like
|
|
76
|
+
// 'body' may have additional id/class/pseudo-class/attribute-selector
|
|
77
|
+
// parts chained to it, which is difficult to quantify using a regex.
|
|
78
|
+
let insertionPoint = -1;
|
|
79
|
+
for (let i = lastRootIndex + 1; i < tokenized.length; i++) {
|
|
80
|
+
if (tokenized[i].type === 'combinator') {
|
|
81
|
+
insertionPoint = i;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Tokenize and insert the prefix with a ' ' combinator before it.
|
|
87
|
+
const tokenizedPrefix = parsel.tokenize(prefix);
|
|
88
|
+
tokenized.splice(
|
|
89
|
+
// Insert at the insertion point, or the end.
|
|
90
|
+
insertionPoint === -1 ? tokenized.length : insertionPoint, 0, {
|
|
91
|
+
type: 'combinator',
|
|
92
|
+
content: ' '
|
|
93
|
+
}, ...tokenizedPrefix);
|
|
94
|
+
return parsel.stringify(tokenized);
|
|
95
|
+
}
|
|
18
96
|
function transformStyle({
|
|
19
97
|
css,
|
|
20
98
|
ignoredSelectors = [],
|
|
21
99
|
baseURL
|
|
22
|
-
}, wrapperSelector = '') {
|
|
23
|
-
// When there is no wrapper selector
|
|
100
|
+
}, wrapperSelector = '', transformOptions) {
|
|
101
|
+
// When there is no wrapper selector and no base URL, there is no need
|
|
24
102
|
// to transform the CSS. This is most cases because in the default
|
|
25
103
|
// iframed editor, no wrapping is needed, and not many styles
|
|
26
104
|
// provide a base URL.
|
|
27
105
|
if (!wrapperSelector && !baseURL) {
|
|
28
106
|
return css;
|
|
29
107
|
}
|
|
30
|
-
const postcssFriendlyCSS = css.replace(/:root :where\(body\)/g, 'body').replace(/:where\(body\)/g, 'body');
|
|
31
108
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
109
|
+
var _transformOptions$ign;
|
|
110
|
+
const excludedSelectors = [...ignoredSelectors, ...((_transformOptions$ign = transformOptions?.ignoredSelectors) !== null && _transformOptions$ign !== void 0 ? _transformOptions$ign : []), wrapperSelector];
|
|
111
|
+
return (0, _postcss.default)([wrapperSelector && (0, _postcssPrefixSelector.default)({
|
|
112
|
+
prefix: wrapperSelector,
|
|
113
|
+
transform(prefix, selector, prefixedSelector) {
|
|
114
|
+
// For backwards compatibility, don't use the `exclude` option
|
|
115
|
+
// of postcss-prefix-selector, instead handle it here to match
|
|
116
|
+
// the behavior of the old library (postcss-prefix-wrap) that
|
|
117
|
+
// `transformStyle` previously used.
|
|
118
|
+
if (excludedSelectors.some(excludedSelector => excludedSelector instanceof RegExp ? selector.match(excludedSelector) : selector.includes(excludedSelector))) {
|
|
119
|
+
return selector;
|
|
120
|
+
}
|
|
121
|
+
const hasRootSelector = ROOT_SELECTOR_TOKENS.some(rootSelector => selector.startsWith(rootSelector.content));
|
|
122
|
+
|
|
123
|
+
// Reorganize root selectors such that the root part comes before the prefix,
|
|
124
|
+
// but the prefix still comes before the remaining part of the selector.
|
|
125
|
+
if (hasRootSelector) {
|
|
126
|
+
return prefixRootSelector(prefix, selector);
|
|
127
|
+
}
|
|
128
|
+
return prefixedSelector;
|
|
129
|
+
}
|
|
34
130
|
}), baseURL && (0, _postcssUrlrebase.default)({
|
|
35
131
|
rootUrl: baseURL
|
|
36
|
-
})].filter(Boolean)).process(
|
|
132
|
+
})].filter(Boolean)).process(css, {}).css; // use sync PostCSS API
|
|
37
133
|
} catch (error) {
|
|
38
134
|
if (error instanceof _postcss.CssSyntaxError) {
|
|
39
135
|
// eslint-disable-next-line no-console
|
|
@@ -47,18 +143,26 @@ function transformStyle({
|
|
|
47
143
|
}
|
|
48
144
|
|
|
49
145
|
/**
|
|
50
|
-
* Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.
|
|
51
|
-
*
|
|
52
146
|
* @typedef {Object} EditorStyle
|
|
53
|
-
* @property {string}
|
|
54
|
-
* @property {?string}
|
|
55
|
-
* @property {?string[]}
|
|
147
|
+
* @property {string} css the CSS block(s), as a single string.
|
|
148
|
+
* @property {?string} baseURL the base URL to be used as the reference when rewritting urls.
|
|
149
|
+
* @property {?string[]} ignoredSelectors the selectors not to wrap.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @typedef {Object} TransformOptions
|
|
154
|
+
* @property {?string[]} ignoredSelectors the selectors not to wrap.
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.
|
|
56
159
|
*
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
160
|
+
* @param {EditorStyle[]} styles CSS rules.
|
|
161
|
+
* @param {string} wrapperSelector Wrapper selector.
|
|
162
|
+
* @param {TransformOptions} transformOptions Additional options for style transformation.
|
|
59
163
|
* @return {Array} converted rules.
|
|
60
164
|
*/
|
|
61
|
-
const transformStyles = (styles, wrapperSelector = '') => {
|
|
165
|
+
const transformStyles = (styles, wrapperSelector = '', transformOptions) => {
|
|
62
166
|
let cache = cacheByWrapperSelector.get(wrapperSelector);
|
|
63
167
|
if (!cache) {
|
|
64
168
|
cache = new WeakMap();
|
|
@@ -67,7 +171,7 @@ const transformStyles = (styles, wrapperSelector = '') => {
|
|
|
67
171
|
return styles.map(style => {
|
|
68
172
|
let css = cache.get(style);
|
|
69
173
|
if (!css) {
|
|
70
|
-
css = transformStyle(style, wrapperSelector);
|
|
174
|
+
css = transformStyle(style, wrapperSelector, transformOptions);
|
|
71
175
|
cache.set(style, css);
|
|
72
176
|
}
|
|
73
177
|
return css;
|