@wordpress/block-editor 10.1.1-next.4d3b314fd5.0 → 10.3.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 +14 -0
- package/README.md +41 -0
- package/build/components/block-controls/slot.js +2 -2
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.js +4 -2
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -5
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-compact.native.js +1 -0
- package/build/components/block-list/block-list-compact.native.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +79 -12
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -23
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +9 -6
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +5 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +5 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/drop-zone.js +85 -0
- package/build/components/block-popover/drop-zone.js.map +1 -0
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +22 -17
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +6 -9
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-preview/live.js +3 -7
- package/build/components/block-preview/live.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +9 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -16
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +18 -42
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +50 -20
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +15 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +256 -0
- package/build/components/font-sizes/fluid-utils.js.map +1 -0
- package/build/components/font-sizes/index.js +8 -0
- package/build/components/font-sizes/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +151 -78
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +1 -1
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/menu.js +14 -3
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-items.js +2 -17
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +4 -2
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +2 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/preview-options/index.js +2 -3
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.js +17 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +40 -9
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +98 -57
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +12 -12
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/types.js +6 -0
- package/build/components/use-on-block-drop/types.js.map +1 -0
- package/build/hooks/align.js +1 -3
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/align.native.js +1 -7
- package/build/hooks/align.native.js.map +1 -1
- package/build/hooks/font-size.js +60 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/margin.js +6 -5
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +2 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +126 -4
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-typography-props.js +17 -3
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/store/actions.js +59 -45
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +3 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +36 -18
- package/build/store/reducer.js.map +1 -1
- package/build/utils/math.js +14 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/pre-parse-patterns.js +19 -2
- package/build/utils/pre-parse-patterns.js.map +1 -1
- package/build-module/components/block-controls/slot.js +3 -3
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +7 -3
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -6
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-compact.native.js +1 -0
- package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +80 -13
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +8 -24
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +10 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +5 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/drop-zone.js +70 -0
- package/build-module/components/block-popover/drop-zone.js.map +1 -0
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +22 -17
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +6 -9
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-preview/live.js +3 -6
- package/build-module/components/block-preview/live.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +9 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +25 -19
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +19 -44
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +4 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +48 -20
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +15 -3
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +245 -0
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
- package/build-module/components/font-sizes/index.js +1 -0
- package/build-module/components/font-sizes/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +148 -81
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +10 -3
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -17
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +3 -2
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -3
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +17 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +40 -10
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +98 -58
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +12 -12
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/types.js +2 -0
- package/build-module/components/use-on-block-drop/types.js.map +1 -0
- package/build-module/hooks/align.js +1 -2
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/align.native.js +1 -6
- package/build-module/hooks/align.native.js.map +1 -1
- package/build-module/hooks/font-size.js +59 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/margin.js +6 -5
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +2 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +124 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +17 -4
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/store/actions.js +55 -42
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +3 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +36 -19
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/pre-parse-patterns.js +19 -2
- package/build-module/utils/pre-parse-patterns.js.map +1 -1
- package/build-style/style-rtl.css +256 -152
- package/build-style/style.css +256 -152
- package/package.json +28 -29
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-controls/slot.js +3 -3
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -11
- package/src/components/block-list/block-list-compact.native.js +1 -0
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/block.native.js +123 -9
- package/src/components/block-list/style.scss +93 -126
- package/src/components/block-list/use-in-between-inserter.js +8 -19
- package/src/components/block-lock/modal.js +12 -7
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-parent-selector/index.js +5 -5
- package/src/components/block-patterns-list/index.js +9 -5
- package/src/components/block-patterns-list/style.scss +7 -3
- package/src/components/block-popover/README.md +8 -0
- package/src/components/block-popover/drop-zone.js +63 -0
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +39 -22
- package/src/components/block-popover/style.scss +17 -1
- package/src/components/block-preview/auto.js +1 -1
- package/src/components/block-preview/index.js +7 -8
- package/src/components/block-preview/live.js +2 -7
- package/src/components/block-preview/test/index.js +1 -7
- package/src/components/block-selection-clearer/index.js +7 -2
- package/src/components/block-selection-clearer/test/index.js +118 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +32 -18
- package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
- package/src/components/block-styles/index.js +26 -49
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +104 -33
- package/src/components/block-switcher/test/index.js +121 -61
- package/src/components/block-toolbar/index.js +4 -6
- package/src/components/block-toolbar/style.scss +38 -14
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +42 -17
- package/src/components/block-tools/selected-block-popover.js +14 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +32 -52
- package/src/components/color-palette/test/control.js +11 -15
- package/src/components/colors-gradients/control.js +2 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
- package/src/components/colors-gradients/test/control.js +49 -77
- package/src/components/font-sizes/fluid-utils.js +296 -0
- package/src/components/font-sizes/index.js +1 -0
- package/src/components/font-sizes/test/fluid-utils.js +168 -0
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/image-size-control/test/index.js +47 -60
- package/src/components/index.js +0 -1
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/src/components/inserter/block-patterns-tab.js +232 -98
- package/src/components/inserter/block-types-tab.js +3 -3
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/inspector-controls/slot.js +6 -2
- package/src/components/link-control/test/index.js +1 -1
- package/src/components/list-view/use-list-view-drop-zone.js +4 -18
- package/src/components/panel-color-settings/test/index.js +4 -4
- package/src/components/preview-options/index.js +2 -2
- package/src/components/preview-options/style.scss +1 -1
- package/src/components/provider/test/use-block-sync.js +131 -165
- package/src/components/responsive-block-control/test/index.js +77 -122
- package/src/components/rich-text/index.js +22 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +24 -9
- package/src/components/spacing-sizes-control/style.scss +42 -31
- package/src/components/use-block-drop-zone/index.js +136 -79
- package/src/components/use-block-drop-zone/test/index.js +333 -81
- package/src/components/use-on-block-drop/index.js +11 -12
- package/src/components/use-on-block-drop/types.ts +1 -0
- package/src/hooks/align.js +3 -2
- package/src/hooks/align.native.js +5 -8
- package/src/hooks/font-size.js +75 -0
- package/src/hooks/margin.js +5 -4
- package/src/hooks/padding.js +1 -0
- package/src/hooks/style.js +122 -3
- package/src/hooks/test/style.js +206 -1
- package/src/hooks/test/use-typography-props.js +22 -0
- package/src/hooks/use-typography-props.js +18 -3
- package/src/hooks/utils.js +6 -2
- package/src/store/actions.js +20 -12
- package/src/store/defaults.js +3 -0
- package/src/store/reducer.js +35 -28
- package/src/store/test/actions.js +0 -9
- package/src/utils/math.js +17 -0
- package/src/utils/pre-parse-patterns.js +12 -7
- package/build/components/inserter/pattern-panel.js +0 -87
- package/build/components/inserter/pattern-panel.js.map +0 -1
- package/build-module/components/inserter/pattern-panel.js +0 -74
- package/build-module/components/inserter/pattern-panel.js.map +0 -1
- package/src/components/inserter/pattern-panel.js +0 -93
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["hasMarginSupport","blockType","support","SPACING_SUPPORT_KEY","margin","hasMarginValue","props","attributes","style","spacing","undefined","resetMargin","setAttributes","useIsMarginDisabled","name","blockName","isDisabled","isInvalid","MarginEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","MarginVisualizer","clientId","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;;AADA;;AAQA;;AACA;;AAIA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAgBA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAT,CAA2BC,SAA3B,EAAuC;AAC7C,QAAMC,OAAO,GAAG,6BAAiBD,SAAjB,EAA4BE,+BAA5B,CAAhB;AACA,SAAO,CAAC,EAAI,SAASD,OAAT,IAAoBA,OAApB,aAAoBA,OAApB,eAAoBA,OAAO,CAAEE,MAAjC,CAAR;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AAAA;;AACvC,SAAO,0BAAAA,KAAK,CAACC,UAAN,CAAiBC,KAAjB,0GAAwBC,OAAxB,kFAAiCL,MAAjC,MAA4CM,SAAnD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,OAA2D;AAAA,MAArC;AAAEJ,IAAAA,UAAU,GAAG,EAAf;AAAmBK,IAAAA;AAAnB,GAAqC;AACjE,QAAM;AAAEJ,IAAAA;AA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,MAAK,CAAE8C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGb,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC;AAHzB,KAKC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IALD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getCustomValueFromPreset } from '../components/spacing-sizes-control/utils';\n\n/**\n * Determines if there is margin support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasMarginSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.margin );\n}\n\n/**\n * Checks if there is a current value in the margin block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a margin value set.\n */\nexport function hasMarginValue( props ) {\n\treturn props.attributes.style?.spacing?.margin !== undefined;\n}\n\n/**\n * Resets the margin block support attributes. This can be used when disabling\n * the margin support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetMargin( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if margin settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether margin setting is disabled.\n */\nexport function useIsMarginDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.margin' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );\n\n\treturn ! hasMarginSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the margin related configuration\n *\n * @param {Object} props Block props.\n *\n * @return {WPElement} Margin edit element.\n */\nexport function MarginEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'margin' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsMarginDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function MarginVisualizer( { clientId, attributes } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getCustomValueFromPreset( margin?.top, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getCustomValueFromPreset( margin?.right, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getCustomValueFromPreset( margin?.bottom, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getCustomValueFromPreset( margin?.left, spacingSizes )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop !== 0 ? `-${ marginTop }` : 0,\n\t\t\tright: marginRight !== 0 ? `-${ marginRight }` : 0,\n\t\t\tbottom: marginBottom !== 0 ? `-${ marginBottom }` : 0,\n\t\t\tleft: marginLeft !== 0 ? `-${ marginLeft }` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ margin ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["hasMarginSupport","blockType","support","SPACING_SUPPORT_KEY","margin","hasMarginValue","props","attributes","style","spacing","undefined","resetMargin","setAttributes","useIsMarginDisabled","name","blockName","isDisabled","isInvalid","MarginEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","MarginVisualizer","clientId","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;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AE8C,QAAF,EAAYC,WAAZ,IAA4B,uBAAU,KAAV,CAAlC;AACA,QAAMC,QAAQ,GAAG,qBAAQhD,MAAR,CAAjB;AACA,QAAMiD,UAAU,GAAG,sBAAnB;;AAEA,QAAMC,UAAU,GAAG,MAAM;AACxB,QAAKD,UAAU,CAACE,OAAhB,EAA0B;AACzBC,MAAAA,MAAM,CAACC,YAAP,CAAqBJ,UAAU,CAACE,OAAhC;AACA;AACD,GAJD;;AAMA,0BAAW,MAAM;AAChB,QAAK,CAAE,6BAAgBnD,MAAhB,EAAwBgD,QAAQ,CAACG,OAAjC,CAAP,EAAoD;AACnDJ,MAAAA,WAAW,CAAE,IAAF,CAAX;AACAC,MAAAA,QAAQ,CAACG,OAAT,GAAmBnD,MAAnB;AAEAkD,MAAAA,UAAU;AAEVD,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAElD,MAAF,CAbH;;AAeA,MAAK,CAAE8C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGb,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC,MAHzB;AAIC,IAAA,KAAK,EAAG;AAJT,KAMC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IAND,CADD;AAUA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getCustomValueFromPreset } from '../components/spacing-sizes-control/utils';\n\n/**\n * Determines if there is margin support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasMarginSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.margin );\n}\n\n/**\n * Checks if there is a current value in the margin block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a margin value set.\n */\nexport function hasMarginValue( props ) {\n\treturn props.attributes.style?.spacing?.margin !== undefined;\n}\n\n/**\n * Resets the margin block support attributes. This can be used when disabling\n * the margin support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetMargin( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if margin settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether margin setting is disabled.\n */\nexport function useIsMarginDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.margin' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );\n\n\treturn ! hasMarginSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the margin related configuration\n *\n * @param {Object} props Block props.\n *\n * @return {WPElement} Margin edit element.\n */\nexport function MarginEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'margin' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsMarginDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function MarginVisualizer( { clientId, attributes } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getCustomValueFromPreset( margin?.top, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getCustomValueFromPreset( margin?.right, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getCustomValueFromPreset( margin?.bottom, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getCustomValueFromPreset( margin?.left, spacingSizes )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop !== 0 ? `calc(${ marginTop } * -1)` : 0,\n\t\t\tright: marginRight !== 0 ? `calc(${ marginRight } * -1)` : 0,\n\t\t\tbottom: marginBottom !== 0 ? `calc(${ marginBottom } * -1)` : 0,\n\t\t\tleft: marginLeft !== 0 ? `calc(${ marginLeft } * -1)` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ margin ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
package/build/hooks/padding.js
CHANGED
|
@@ -218,7 +218,8 @@ function PaddingVisualizer(_ref2) {
|
|
|
218
218
|
return (0, _element.createElement)(_blockPopover.default, {
|
|
219
219
|
clientId: clientId,
|
|
220
220
|
__unstableCoverTarget: true,
|
|
221
|
-
__unstableRefreshSize: padding
|
|
221
|
+
__unstableRefreshSize: padding,
|
|
222
|
+
shift: false
|
|
222
223
|
}, (0, _element.createElement)("div", {
|
|
223
224
|
className: "block-editor__padding-visualizer",
|
|
224
225
|
style: style
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/padding.js"],"names":["hasPaddingSupport","blockType","support","SPACING_SUPPORT_KEY","padding","hasPaddingValue","props","attributes","style","spacing","undefined","resetPadding","setAttributes","useIsPaddingDisabled","name","blockName","isDisabled","isInvalid","PaddingEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","PaddingVisualizer","clientId","borderTopWidth","top","borderRightWidth","right","borderBottomWidth","bottom","borderLeftWidth","left","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;;AADA;;AAQA;;AACA;;AAIA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAgBA;AACA;AACA;;AAeA;AACA;AACA;AACA;AAC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BG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAE9C,OAAF,CAbH;;AAeA,MAAK,CAAE0C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGT,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC;AAHzB,KAKC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IALD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tuseMemo,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport {\n\tgetSpacingPresetCssVar,\n\tisValueSpacingPreset,\n} from '../components/spacing-sizes-control/utils';\n/**\n * Determines if there is padding support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPaddingSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.padding );\n}\n\n/**\n * Checks if there is a current value in the padding block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a padding value set.\n */\nexport function hasPaddingValue( props ) {\n\treturn props.attributes.style?.spacing?.padding !== undefined;\n}\n\n/**\n * Resets the padding block support attributes. This can be used when disabling\n * the padding support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPadding( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if padding settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPaddingDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.padding' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'padding' );\n\n\treturn ! hasPaddingSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the padding related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Padding edit element.\n */\nexport function PaddingEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'padding' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsPaddingDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function PaddingVisualizer( { clientId, attributes } ) {\n\tconst padding = attributes?.style?.spacing?.padding;\n\tconst style = useMemo( () => {\n\t\treturn {\n\t\t\tborderTopWidth: isValueSpacingPreset( padding?.top )\n\t\t\t\t? getSpacingPresetCssVar( padding?.top )\n\t\t\t\t: padding?.top,\n\t\t\tborderRightWidth: isValueSpacingPreset( padding?.right )\n\t\t\t\t? getSpacingPresetCssVar( padding?.right )\n\t\t\t\t: padding?.right,\n\t\t\tborderBottomWidth: isValueSpacingPreset( padding?.bottom )\n\t\t\t\t? getSpacingPresetCssVar( padding?.bottom )\n\t\t\t\t: padding?.bottom,\n\t\t\tborderLeftWidth: isValueSpacingPreset( padding?.left )\n\t\t\t\t? getSpacingPresetCssVar( padding?.left )\n\t\t\t\t: padding?.left,\n\t\t};\n\t}, [ padding ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( padding );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( padding, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = padding;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ padding ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ padding }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/padding.js"],"names":["hasPaddingSupport","blockType","support","SPACING_SUPPORT_KEY","padding","hasPaddingValue","props","attributes","style","spacing","undefined","resetPadding","setAttributes","useIsPaddingDisabled","name","blockName","isDisabled","isInvalid","PaddingEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","PaddingVisualizer","clientId","borderTopWidth","top","borderRightWidth","right","borderBottomWidth","bottom","borderLeftWidth","left","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;;AADA;;AAQA;;AACA;;AAIA;;AAKA;;AACA;;AAMA;;AACA;;A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/C,OAAnB;AAEA8C,MAAAA,UAAU;AAEVD,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAE9C,OAAF,CAbH;;AAeA,MAAK,CAAE0C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGT,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC,OAHzB;AAIC,IAAA,KAAK,EAAG;AAJT,KAMC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IAND,CADD;AAUA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tuseMemo,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport {\n\tgetSpacingPresetCssVar,\n\tisValueSpacingPreset,\n} from '../components/spacing-sizes-control/utils';\n/**\n * Determines if there is padding support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPaddingSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.padding );\n}\n\n/**\n * Checks if there is a current value in the padding block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a padding value set.\n */\nexport function hasPaddingValue( props ) {\n\treturn props.attributes.style?.spacing?.padding !== undefined;\n}\n\n/**\n * Resets the padding block support attributes. This can be used when disabling\n * the padding support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPadding( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if padding settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPaddingDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.padding' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'padding' );\n\n\treturn ! hasPaddingSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the padding related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Padding edit element.\n */\nexport function PaddingEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'padding' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsPaddingDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function PaddingVisualizer( { clientId, attributes } ) {\n\tconst padding = attributes?.style?.spacing?.padding;\n\tconst style = useMemo( () => {\n\t\treturn {\n\t\t\tborderTopWidth: isValueSpacingPreset( padding?.top )\n\t\t\t\t? getSpacingPresetCssVar( padding?.top )\n\t\t\t\t: padding?.top,\n\t\t\tborderRightWidth: isValueSpacingPreset( padding?.right )\n\t\t\t\t? getSpacingPresetCssVar( padding?.right )\n\t\t\t\t: padding?.right,\n\t\t\tborderBottomWidth: isValueSpacingPreset( padding?.bottom )\n\t\t\t\t? getSpacingPresetCssVar( padding?.bottom )\n\t\t\t\t: padding?.bottom,\n\t\t\tborderLeftWidth: isValueSpacingPreset( padding?.left )\n\t\t\t\t? getSpacingPresetCssVar( padding?.left )\n\t\t\t\t: padding?.left,\n\t\t};\n\t}, [ padding ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( padding );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( padding, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = padding;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ padding ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ padding }\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
package/build/hooks/style.js
CHANGED
|
@@ -8,14 +8,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.addEditProps = addEditProps;
|
|
9
9
|
exports.addSaveProps = addSaveProps;
|
|
10
10
|
exports.getInlineStyles = getInlineStyles;
|
|
11
|
+
exports.omitStyle = omitStyle;
|
|
11
12
|
exports.withBlockControls = void 0;
|
|
12
13
|
|
|
13
14
|
var _element = require("@wordpress/element");
|
|
14
15
|
|
|
15
16
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
16
17
|
|
|
17
|
-
var _lodash = require("lodash");
|
|
18
|
-
|
|
19
18
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
20
19
|
|
|
21
20
|
var _hooks = require("@wordpress/hooks");
|
|
@@ -144,6 +143,128 @@ const skipSerializationPathsSave = { ...skipSerializationPathsEdit,
|
|
|
144
143
|
const renamedFeatures = {
|
|
145
144
|
gradients: 'gradient'
|
|
146
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* A utility function used to remove one or more paths from a style object.
|
|
148
|
+
* Works in a way similar to Lodash's `omit()`. See unit tests and examples below.
|
|
149
|
+
*
|
|
150
|
+
* It supports a single string path:
|
|
151
|
+
*
|
|
152
|
+
* ```
|
|
153
|
+
* omitStyle( { color: 'red' }, 'color' ); // {}
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* or an array of paths:
|
|
157
|
+
*
|
|
158
|
+
* ```
|
|
159
|
+
* omitStyle( { color: 'red', background: '#fff' }, [ 'color', 'background' ] ); // {}
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* It also allows you to specify paths at multiple levels in a string.
|
|
163
|
+
*
|
|
164
|
+
* ```
|
|
165
|
+
* omitStyle( { typography: { textDecoration: 'underline' } }, 'typography.textDecoration' ); // {}
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* You can remove multiple paths at the same time:
|
|
169
|
+
*
|
|
170
|
+
* ```
|
|
171
|
+
* omitStyle(
|
|
172
|
+
* {
|
|
173
|
+
* typography: {
|
|
174
|
+
* textDecoration: 'underline',
|
|
175
|
+
* textTransform: 'uppercase',
|
|
176
|
+
* }
|
|
177
|
+
* },
|
|
178
|
+
* [
|
|
179
|
+
* 'typography.textDecoration',
|
|
180
|
+
* 'typography.textTransform',
|
|
181
|
+
* ]
|
|
182
|
+
* );
|
|
183
|
+
* // {}
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* You can also specify nested paths as arrays:
|
|
187
|
+
*
|
|
188
|
+
* ```
|
|
189
|
+
* omitStyle(
|
|
190
|
+
* {
|
|
191
|
+
* typography: {
|
|
192
|
+
* textDecoration: 'underline',
|
|
193
|
+
* textTransform: 'uppercase',
|
|
194
|
+
* }
|
|
195
|
+
* },
|
|
196
|
+
* [
|
|
197
|
+
* [ 'typography', 'textDecoration' ],
|
|
198
|
+
* [ 'typography', 'textTransform' ],
|
|
199
|
+
* ]
|
|
200
|
+
* );
|
|
201
|
+
* // {}
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* With regards to nesting of styles, infinite depth is supported:
|
|
205
|
+
*
|
|
206
|
+
* ```
|
|
207
|
+
* omitStyle(
|
|
208
|
+
* {
|
|
209
|
+
* border: {
|
|
210
|
+
* radius: {
|
|
211
|
+
* topLeft: '10px',
|
|
212
|
+
* topRight: '0.5rem',
|
|
213
|
+
* }
|
|
214
|
+
* }
|
|
215
|
+
* },
|
|
216
|
+
* [
|
|
217
|
+
* [ 'border', 'radius', 'topRight' ],
|
|
218
|
+
* ]
|
|
219
|
+
* );
|
|
220
|
+
* // { border: { radius: { topLeft: '10px' } } }
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* The third argument, `preserveReference`, defines how to treat the input style object.
|
|
224
|
+
* It is mostly necessary to properly handle mutation when recursively handling the style object.
|
|
225
|
+
* Defaulting to `false`, this will always create a new object, avoiding to mutate `style`.
|
|
226
|
+
* However, when recursing, we change that value to `true` in order to work with a single copy
|
|
227
|
+
* of the original style object.
|
|
228
|
+
*
|
|
229
|
+
* @see https://lodash.com/docs/4.17.15#omit
|
|
230
|
+
*
|
|
231
|
+
* @param {Object} style Styles object.
|
|
232
|
+
* @param {Array|string} paths Paths to remove.
|
|
233
|
+
* @param {boolean} preserveReference True to mutate the `style` object, false otherwise.
|
|
234
|
+
* @return {Object} Styles object with the specified paths removed.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
function omitStyle(style, paths) {
|
|
238
|
+
let preserveReference = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
239
|
+
|
|
240
|
+
if (!style) {
|
|
241
|
+
return style;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let newStyle = style;
|
|
245
|
+
|
|
246
|
+
if (!preserveReference) {
|
|
247
|
+
newStyle = JSON.parse(JSON.stringify(style));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!Array.isArray(paths)) {
|
|
251
|
+
paths = [paths];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
paths.forEach(path => {
|
|
255
|
+
if (!Array.isArray(path)) {
|
|
256
|
+
path = path.split('.');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (path.length > 1) {
|
|
260
|
+
const [firstSubpath, ...restPath] = path;
|
|
261
|
+
omitStyle(newStyle[firstSubpath], [restPath], true);
|
|
262
|
+
} else if (path.length === 1) {
|
|
263
|
+
delete newStyle[path[0]];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return newStyle;
|
|
267
|
+
}
|
|
147
268
|
/**
|
|
148
269
|
* Override props assigned to save component to inject the CSS variables definition.
|
|
149
270
|
*
|
|
@@ -155,6 +276,7 @@ const renamedFeatures = {
|
|
|
155
276
|
* @return {Object} Filtered props applied to save element.
|
|
156
277
|
*/
|
|
157
278
|
|
|
279
|
+
|
|
158
280
|
function addSaveProps(props, blockType, attributes) {
|
|
159
281
|
let skipPaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : skipSerializationPathsSave;
|
|
160
282
|
|
|
@@ -170,13 +292,13 @@ function addSaveProps(props, blockType, attributes) {
|
|
|
170
292
|
const skipSerialization = (0, _blocks.getBlockSupport)(blockType, indicator);
|
|
171
293
|
|
|
172
294
|
if (skipSerialization === true) {
|
|
173
|
-
style = (
|
|
295
|
+
style = omitStyle(style, path);
|
|
174
296
|
}
|
|
175
297
|
|
|
176
298
|
if (Array.isArray(skipSerialization)) {
|
|
177
299
|
skipSerialization.forEach(featureName => {
|
|
178
300
|
const feature = renamedFeatures[featureName] || featureName;
|
|
179
|
-
style = (
|
|
301
|
+
style = omitStyle(style, [[...path, feature]]);
|
|
180
302
|
});
|
|
181
303
|
}
|
|
182
304
|
});
|
package/build/hooks/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/style.js"],"names":["styleSupportKeys","TYPOGRAPHY_SUPPORT_KEYS","BORDER_SUPPORT_KEY","COLOR_SUPPORT_KEY","SPACING_SUPPORT_KEY","hasStyleSupport","blockType","some","key","getInlineStyles","styles","output","forEach","rule","value","addAttribute","settings","attributes","style","Object","assign","type","skipSerializationPathsEdit","TYPOGRAPHY_SUPPORT_KEY","skipSerializationPathsSave","renamedFeatures","gradients","addSaveProps","props","skipPaths","entries","indicator","path","skipSerialization","Array","isArray","featureName","feature","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBlockControls","BlockEdit","shouldDisplayControls","withElementsStyles","BlockListBlock","blockElementsContainerIdentifier","skipLinkColorSerialization","name","rawElementsStyles","elements","elementCssRules","keys","length","filteredElementsStyles","link","color","undefined","elementName","elementStyles","cssRule","selector","ELEMENTS","push","element","BlockList","__unstableElementContext","__html","className"],"mappings":";;;;;;;;;;;;AASA;;;;AANA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAIA;AACA;AACA;;AAWA;AACA;AACA;AAaA,MAAMA,gBAAgB,GAAG,CACxB,GAAGC,mCADqB,EAExBC,0BAFwB,EAGxBC,wBAHwB,EAIxBC,+BAJwB,CAAzB;;AAOA,MAAMC,eAAe,GAAKC,SAAF,IACvBN,gBAAgB,CAACO,IAAjB,CAAyBC,GAAF,IAAW,6BAAiBF,SAAjB,EAA4BE,GAA5B,CAAlC,CADD;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,eAAT,GAAwC;AAAA,MAAdC,MAAc,uEAAL,EAAK;AAC9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KAAK,CAACwC;AARX,KAZD,CADD;AA0BA,CA3EyB,CAA3B;AA8EA,sBACC,0BADD,EAEC,yBAFD,EAGCrD,YAHD;AAMA,sBACC,kCADD,EAEC,yBAFD,EAGCY,YAHD;AAMA,sBACC,0BADD,EAEC,yBAFD,EAGCW,YAHD;AAMA,sBACC,kBADD,EAEC,gCAFD,EAGCG,iBAHD;AAMA,sBACC,uBADD,EAEC,kCAFD,EAGCG,kBAHD","sourcesContent":["/**\n * External dependencies\n */\nimport { omit } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, createPortal } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\thasBlockSupport,\n\t__EXPERIMENTAL_ELEMENTS as ELEMENTS,\n} from '@wordpress/blocks';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { getCSSRules, compileCSS } from '@wordpress/style-engine';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport { BORDER_SUPPORT_KEY, BorderPanel } from './border';\nimport { COLOR_SUPPORT_KEY, ColorEdit } from './color';\nimport {\n\tTypographyPanel,\n\tTYPOGRAPHY_SUPPORT_KEY,\n\tTYPOGRAPHY_SUPPORT_KEYS,\n} from './typography';\nimport { SPACING_SUPPORT_KEY, DimensionsPanel } from './dimensions';\nimport useDisplayBlockControls from '../components/use-display-block-controls';\nimport { shouldSkipSerialization } from './utils';\n\nconst styleSupportKeys = [\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\nconst hasStyleSupport = ( blockType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( blockType, key ) );\n\n/**\n * Returns the inline styles to add depending on the style object\n *\n * @param {Object} styles Styles configuration.\n *\n * @return {Object} Flattened CSS variables declaration.\n */\nexport function getInlineStyles( styles = {} ) {\n\tconst output = {};\n\t// The goal is to move everything to server side generated engine styles\n\t// This is temporary as we absorb more and more styles into the engine.\n\tgetCSSRules( styles ).forEach( ( rule ) => {\n\t\toutput[ rule.key ] = rule.value;\n\t} );\n\n\treturn output;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `style` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttribute( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.style ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tstyle: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsEdit = {\n\t[ `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ 'border' ],\n\t[ `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tCOLOR_SUPPORT_KEY,\n\t],\n\t[ `${ TYPOGRAPHY_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t],\n\t[ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\t'spacing',\n\t],\n};\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * Extends the Edit skip paths to enable skipping additional paths in just\n * the Save component. This allows a block support to be serialized within the\n * editor, while using an alternate approach, such as server-side rendering, when\n * the support is saved.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsSave = {\n\t...skipSerializationPathsEdit,\n\t[ `${ SPACING_SUPPORT_KEY }` ]: [ 'spacing.blockGap' ],\n};\n\n/**\n * A dictionary used to normalize feature names between support flags, style\n * object properties and __experimentSkipSerialization configuration arrays.\n *\n * This allows not having to provide a migration for a support flag and possible\n * backwards compatibility bridges, while still achieving consistency between\n * the support flag and the skip serialization array.\n *\n * @constant\n * @type {Record<string, string>}\n */\nconst renamedFeatures = { gradients: 'gradient' };\n\n/**\n * Override props assigned to save component to inject the CSS variables definition.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @param {?Record<string, string[]>} skipPaths An object of keys and paths to skip serialization.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps(\n\tprops,\n\tblockType,\n\tattributes,\n\tskipPaths = skipSerializationPathsSave\n) {\n\tif ( ! hasStyleSupport( blockType ) ) {\n\t\treturn props;\n\t}\n\n\tlet { style } = attributes;\n\tObject.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {\n\t\tconst skipSerialization = getBlockSupport( blockType, indicator );\n\n\t\tif ( skipSerialization === true ) {\n\t\t\tstyle = omit( style, path );\n\t\t}\n\n\t\tif ( Array.isArray( skipSerialization ) ) {\n\t\t\tskipSerialization.forEach( ( featureName ) => {\n\t\t\t\tconst feature = renamedFeatures[ featureName ] || featureName;\n\t\t\t\tstyle = omit( style, [ [ ...path, feature ] ] );\n\t\t\t} );\n\t\t}\n\t} );\n\n\tprops.style = {\n\t\t...getInlineStyles( style ),\n\t\t...props.style,\n\t};\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to extend the block edit wrapper\n * to apply the desired styles and classnames properly.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object}.Filtered block settings.\n */\nexport function addEditProps( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps(\n\t\t\tprops,\n\t\t\tsettings,\n\t\t\tattributes,\n\t\t\tskipSerializationPathsEdit\n\t\t);\n\t};\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include new inspector controls for\n * all the custom styles configs.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst shouldDisplayControls = useDisplayBlockControls();\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldDisplayControls && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ColorEdit { ...props } />\n\t\t\t\t\t\t<TypographyPanel { ...props } />\n\t\t\t\t\t\t<BorderPanel { ...props } />\n\t\t\t\t\t\t<DimensionsPanel { ...props } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\n/**\n * Override the default block element to include elements styles.\n *\n * @param {Function} BlockListBlock Original component\n * @return {Function} Wrapped component\n */\nconst withElementsStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(\n\t\t\tBlockListBlock\n\t\t) }`;\n\n\t\tconst skipLinkColorSerialization = shouldSkipSerialization(\n\t\t\tprops.name,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t'link'\n\t\t);\n\n\t\tconst styles = useMemo( () => {\n\t\t\tconst rawElementsStyles = props.attributes.style?.elements;\n\t\t\tconst elementCssRules = [];\n\t\t\tif (\n\t\t\t\trawElementsStyles &&\n\t\t\t\tObject.keys( rawElementsStyles ).length > 0\n\t\t\t) {\n\t\t\t\t// Remove values based on whether serialization has been skipped for a specific style.\n\t\t\t\tconst filteredElementsStyles = {\n\t\t\t\t\t...rawElementsStyles,\n\t\t\t\t\tlink: {\n\t\t\t\t\t\t...rawElementsStyles.link,\n\t\t\t\t\t\tcolor: ! skipLinkColorSerialization\n\t\t\t\t\t\t\t? rawElementsStyles.link?.color\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tfor ( const [ elementName, elementStyles ] of Object.entries(\n\t\t\t\t\tfilteredElementsStyles\n\t\t\t\t) ) {\n\t\t\t\t\tconst cssRule = compileCSS( elementStyles, {\n\t\t\t\t\t\t// The .editor-styles-wrapper selector is required on elements styles. As it is\n\t\t\t\t\t\t// added to all other editor styles, not providing it causes reset and global\n\t\t\t\t\t\t// styles to override element styles because of higher specificity.\n\t\t\t\t\t\tselector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS[ elementName ] }`,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( !! cssRule ) {\n\t\t\t\t\t\telementCssRules.push( cssRule );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn elementCssRules.length > 0 ? elementCssRules : undefined;\n\t\t}, [ props.attributes.style?.elements ] );\n\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ styles &&\n\t\t\t\t\telement &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t\t__html: styles,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\n\t\t\t\t<BlockListBlock\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tprops.attributes.style?.elements\n\t\t\t\t\t\t\t? classnames(\n\t\t\t\t\t\t\t\t\tprops.className,\n\t\t\t\t\t\t\t\t\tblockElementsContainerIdentifier\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: props.className\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addAttribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/style/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/style/with-block-controls',\n\twithBlockControls\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/with-elements-styles',\n\twithElementsStyles\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/style.js"],"names":["styleSupportKeys","TYPOGRAPHY_SUPPORT_KEYS","BORDER_SUPPORT_KEY","COLOR_SUPPORT_KEY","SPACING_SUPPORT_KEY","hasStyleSupport","blockType","some","key","getInlineStyles","styles","output","forEach","rule","value","addAttribute","settings","attributes","style","Object","assign","type","skipSerializationPathsEdit","TYPOGRAPHY_SUPPORT_KEY","skipSerializationPathsSave","renamedFeatures","gradients","omitStyle","paths","preserveReference","newStyle","JSON","parse","stringify","Array","isArray","path","split","length","firstSubpath","restPath","addSaveProps","props","skipPaths","entries","indicator","skipSerialization","featureName","feature","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBlockControls","BlockEdit","shouldDisplayControls","withElementsStyles","BlockListBlock","blockElementsContainerIdentifier","skipLinkColorSerialization","name","rawElementsStyles","elements","elementCssRules","keys","filteredElementsStyles","link","color","undefined","elementName","elementStyles","cssRule","selector","ELEMENTS","push","element","BlockList","__unstableElementContext","__html","className"],"mappings":";;;;;;;;;;;;;AAQA;;;;AALA;;AAMA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;AAaA,MAAMA,gBAAgB,GAAG,CACxB,GAAGC,mCADqB,EAExBC,0BAFwB,EAGxBC,wBAHwB,EAIxBC,+BAJwB,CAAzB;;AAOA,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ACA,MAAMoB,0BAA0B,GAAG,EAClC,GAAGF,0BAD+B;AAElC,GAAG,GAAGlB,+BAAqB,EAA3B,GAAgC,CAAE,kBAAF;AAFE,CAAnC;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMqB,eAAe,GAAG;AAAEC,EAAAA,SAAS,EAAE;AAAb,CAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,SAAT,CAAoBT,KAApB,EAA2BU,KAA3B,EAA8D;AAAA,MAA5BC,iBAA4B,uEAAR,KAAQ;;AACpE,MAAK,CAAEX,KAAP,EAAe;AACd,WAAOA,KAAP;AACA;;AAED,MAAIY,QAAQ,GAAGZ,KAAf;;AACA,MAAK,CAAEW,iBAAP,EAA2B;AAC1BC,IAAAA,QAAQ,GAAGC,IAAI,CAACC,KAAL,CAAYD,IAAI,CAACE,SAAL,CAAgBf,KAAhB,CAAZ,CAAX;AACA;;AAED,MAAK,CAAEgB,KAAK,CAACC,OAAN,CAAeP,KAAf,CAAP,EAAgC;AAC/BA,IAAAA,KAAK,GAAG,CAAEA,KAAF,CAAR;AACA;;AAEDA,EAAAA,KAAK,CAAChB,OAAN,CAAiBwB,IAAF,IAAY;AAC1B,QAAK,CAAEF,KAAK,CAACC,OAAN,CAAeC,IAAf,CAAP,EAA+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EAiCZ,2BAAEzB,KAAK,CAACzB,UAAN,CAAiBC,KAAnB,2DAAE,uBAAwB2C,QAA1B,CAjCY,CAAf;AAmCA,QAAMa,OAAO,GAAG,yBAAYC,mBAAUC,wBAAtB,CAAhB;AAEA,SACC,qDACGlE,MAAM,IACPgE,OADC,IAED,2BACC;AACC,IAAA,uBAAuB,EAAG;AACzBG,MAAAA,MAAM,EAAEnE;AADiB;AAD3B,IADD,EAMCgE,OAND,CAHF,EAYC,4BAAC,cAAD,6BACMhC,KADN;AAEC,IAAA,SAAS,EACR,0BAAAA,KAAK,CAACzB,UAAN,CAAiBC,KAAjB,0EAAwB2C,QAAxB,GACG,yBACAnB,KAAK,CAACoC,SADN,EAEArB,gCAFA,CADH,GAKGf,KAAK,CAACoC;AARX,KAZD,CADD;AA0BA,CA3EyB,CAA3B;AA8EA,sBACC,0BADD,EAEC,yBAFD,EAGC/D,YAHD;AAMA,sBACC,kCADD,EAEC,yBAFD,EAGC0B,YAHD;AAMA,sBACC,0BADD,EAEC,yBAFD,EAGCQ,YAHD;AAMA,sBACC,kBADD,EAEC,gCAFD,EAGCG,iBAHD;AAMA,sBACC,uBADD,EAEC,kCAFD,EAGCG,kBAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, createPortal } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\thasBlockSupport,\n\t__EXPERIMENTAL_ELEMENTS as ELEMENTS,\n} from '@wordpress/blocks';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { getCSSRules, compileCSS } from '@wordpress/style-engine';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport { BORDER_SUPPORT_KEY, BorderPanel } from './border';\nimport { COLOR_SUPPORT_KEY, ColorEdit } from './color';\nimport {\n\tTypographyPanel,\n\tTYPOGRAPHY_SUPPORT_KEY,\n\tTYPOGRAPHY_SUPPORT_KEYS,\n} from './typography';\nimport { SPACING_SUPPORT_KEY, DimensionsPanel } from './dimensions';\nimport useDisplayBlockControls from '../components/use-display-block-controls';\nimport { shouldSkipSerialization } from './utils';\n\nconst styleSupportKeys = [\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\nconst hasStyleSupport = ( blockType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( blockType, key ) );\n\n/**\n * Returns the inline styles to add depending on the style object\n *\n * @param {Object} styles Styles configuration.\n *\n * @return {Object} Flattened CSS variables declaration.\n */\nexport function getInlineStyles( styles = {} ) {\n\tconst output = {};\n\t// The goal is to move everything to server side generated engine styles\n\t// This is temporary as we absorb more and more styles into the engine.\n\tgetCSSRules( styles ).forEach( ( rule ) => {\n\t\toutput[ rule.key ] = rule.value;\n\t} );\n\n\treturn output;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `style` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttribute( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.style ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tstyle: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsEdit = {\n\t[ `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ 'border' ],\n\t[ `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tCOLOR_SUPPORT_KEY,\n\t],\n\t[ `${ TYPOGRAPHY_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t],\n\t[ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\t'spacing',\n\t],\n};\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * Extends the Edit skip paths to enable skipping additional paths in just\n * the Save component. This allows a block support to be serialized within the\n * editor, while using an alternate approach, such as server-side rendering, when\n * the support is saved.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsSave = {\n\t...skipSerializationPathsEdit,\n\t[ `${ SPACING_SUPPORT_KEY }` ]: [ 'spacing.blockGap' ],\n};\n\n/**\n * A dictionary used to normalize feature names between support flags, style\n * object properties and __experimentSkipSerialization configuration arrays.\n *\n * This allows not having to provide a migration for a support flag and possible\n * backwards compatibility bridges, while still achieving consistency between\n * the support flag and the skip serialization array.\n *\n * @constant\n * @type {Record<string, string>}\n */\nconst renamedFeatures = { gradients: 'gradient' };\n\n/**\n * A utility function used to remove one or more paths from a style object.\n * Works in a way similar to Lodash's `omit()`. See unit tests and examples below.\n *\n * It supports a single string path:\n *\n * ```\n * omitStyle( { color: 'red' }, 'color' ); // {}\n * ```\n *\n * or an array of paths:\n *\n * ```\n * omitStyle( { color: 'red', background: '#fff' }, [ 'color', 'background' ] ); // {}\n * ```\n *\n * It also allows you to specify paths at multiple levels in a string.\n *\n * ```\n * omitStyle( { typography: { textDecoration: 'underline' } }, 'typography.textDecoration' ); // {}\n * ```\n *\n * You can remove multiple paths at the same time:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\ttypography: {\n * \t\t\t\ttextDecoration: 'underline',\n * \t\t\t\ttextTransform: 'uppercase',\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t'typography.textDecoration',\n * \t\t\t'typography.textTransform',\n *\t\t]\n * );\n * // {}\n * ```\n *\n * You can also specify nested paths as arrays:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\ttypography: {\n * \t\t\t\ttextDecoration: 'underline',\n * \t\t\t\ttextTransform: 'uppercase',\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t[ 'typography', 'textDecoration' ],\n * \t\t\t[ 'typography', 'textTransform' ],\n *\t\t]\n * );\n * // {}\n * ```\n *\n * With regards to nesting of styles, infinite depth is supported:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\tborder: {\n * \t\t\t\tradius: {\n * \t\t\t\t\ttopLeft: '10px',\n * \t\t\t\t\ttopRight: '0.5rem',\n * \t\t\t\t}\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t[ 'border', 'radius', 'topRight' ],\n *\t\t]\n * );\n * // { border: { radius: { topLeft: '10px' } } }\n * ```\n *\n * The third argument, `preserveReference`, defines how to treat the input style object.\n * It is mostly necessary to properly handle mutation when recursively handling the style object.\n * Defaulting to `false`, this will always create a new object, avoiding to mutate `style`.\n * However, when recursing, we change that value to `true` in order to work with a single copy\n * of the original style object.\n *\n * @see https://lodash.com/docs/4.17.15#omit\n *\n * @param {Object} style Styles object.\n * @param {Array|string} paths Paths to remove.\n * @param {boolean} preserveReference True to mutate the `style` object, false otherwise.\n * @return {Object} Styles object with the specified paths removed.\n */\nexport function omitStyle( style, paths, preserveReference = false ) {\n\tif ( ! style ) {\n\t\treturn style;\n\t}\n\n\tlet newStyle = style;\n\tif ( ! preserveReference ) {\n\t\tnewStyle = JSON.parse( JSON.stringify( style ) );\n\t}\n\n\tif ( ! Array.isArray( paths ) ) {\n\t\tpaths = [ paths ];\n\t}\n\n\tpaths.forEach( ( path ) => {\n\t\tif ( ! Array.isArray( path ) ) {\n\t\t\tpath = path.split( '.' );\n\t\t}\n\n\t\tif ( path.length > 1 ) {\n\t\t\tconst [ firstSubpath, ...restPath ] = path;\n\t\t\tomitStyle( newStyle[ firstSubpath ], [ restPath ], true );\n\t\t} else if ( path.length === 1 ) {\n\t\t\tdelete newStyle[ path[ 0 ] ];\n\t\t}\n\t} );\n\n\treturn newStyle;\n}\n\n/**\n * Override props assigned to save component to inject the CSS variables definition.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @param {?Record<string, string[]>} skipPaths An object of keys and paths to skip serialization.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps(\n\tprops,\n\tblockType,\n\tattributes,\n\tskipPaths = skipSerializationPathsSave\n) {\n\tif ( ! hasStyleSupport( blockType ) ) {\n\t\treturn props;\n\t}\n\n\tlet { style } = attributes;\n\tObject.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {\n\t\tconst skipSerialization = getBlockSupport( blockType, indicator );\n\n\t\tif ( skipSerialization === true ) {\n\t\t\tstyle = omitStyle( style, path );\n\t\t}\n\n\t\tif ( Array.isArray( skipSerialization ) ) {\n\t\t\tskipSerialization.forEach( ( featureName ) => {\n\t\t\t\tconst feature = renamedFeatures[ featureName ] || featureName;\n\t\t\t\tstyle = omitStyle( style, [ [ ...path, feature ] ] );\n\t\t\t} );\n\t\t}\n\t} );\n\n\tprops.style = {\n\t\t...getInlineStyles( style ),\n\t\t...props.style,\n\t};\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to extend the block edit wrapper\n * to apply the desired styles and classnames properly.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object}.Filtered block settings.\n */\nexport function addEditProps( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps(\n\t\t\tprops,\n\t\t\tsettings,\n\t\t\tattributes,\n\t\t\tskipSerializationPathsEdit\n\t\t);\n\t};\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include new inspector controls for\n * all the custom styles configs.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst shouldDisplayControls = useDisplayBlockControls();\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldDisplayControls && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ColorEdit { ...props } />\n\t\t\t\t\t\t<TypographyPanel { ...props } />\n\t\t\t\t\t\t<BorderPanel { ...props } />\n\t\t\t\t\t\t<DimensionsPanel { ...props } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\n/**\n * Override the default block element to include elements styles.\n *\n * @param {Function} BlockListBlock Original component\n * @return {Function} Wrapped component\n */\nconst withElementsStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(\n\t\t\tBlockListBlock\n\t\t) }`;\n\n\t\tconst skipLinkColorSerialization = shouldSkipSerialization(\n\t\t\tprops.name,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t'link'\n\t\t);\n\n\t\tconst styles = useMemo( () => {\n\t\t\tconst rawElementsStyles = props.attributes.style?.elements;\n\t\t\tconst elementCssRules = [];\n\t\t\tif (\n\t\t\t\trawElementsStyles &&\n\t\t\t\tObject.keys( rawElementsStyles ).length > 0\n\t\t\t) {\n\t\t\t\t// Remove values based on whether serialization has been skipped for a specific style.\n\t\t\t\tconst filteredElementsStyles = {\n\t\t\t\t\t...rawElementsStyles,\n\t\t\t\t\tlink: {\n\t\t\t\t\t\t...rawElementsStyles.link,\n\t\t\t\t\t\tcolor: ! skipLinkColorSerialization\n\t\t\t\t\t\t\t? rawElementsStyles.link?.color\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tfor ( const [ elementName, elementStyles ] of Object.entries(\n\t\t\t\t\tfilteredElementsStyles\n\t\t\t\t) ) {\n\t\t\t\t\tconst cssRule = compileCSS( elementStyles, {\n\t\t\t\t\t\t// The .editor-styles-wrapper selector is required on elements styles. As it is\n\t\t\t\t\t\t// added to all other editor styles, not providing it causes reset and global\n\t\t\t\t\t\t// styles to override element styles because of higher specificity.\n\t\t\t\t\t\tselector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS[ elementName ] }`,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( !! cssRule ) {\n\t\t\t\t\t\telementCssRules.push( cssRule );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn elementCssRules.length > 0 ? elementCssRules : undefined;\n\t\t}, [ props.attributes.style?.elements ] );\n\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ styles &&\n\t\t\t\t\telement &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t\t__html: styles,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\n\t\t\t\t<BlockListBlock\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tprops.attributes.style?.elements\n\t\t\t\t\t\t\t? classnames(\n\t\t\t\t\t\t\t\t\tprops.className,\n\t\t\t\t\t\t\t\t\tblockElementsContainerIdentifier\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: props.className\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addAttribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/style/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/style/with-block-controls',\n\twithBlockControls\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/with-elements-styles',\n\twithElementsStyles\n);\n"]}
|
|
@@ -15,6 +15,8 @@ var _style = require("./style");
|
|
|
15
15
|
|
|
16
16
|
var _fontSizes = require("../components/font-sizes");
|
|
17
17
|
|
|
18
|
+
var _fluidUtils = require("../components/font-sizes/fluid-utils");
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* External dependencies
|
|
20
22
|
*/
|
|
@@ -30,14 +32,26 @@ var _fontSizes = require("../components/font-sizes");
|
|
|
30
32
|
* Provides the CSS class names and inline styles for a block's typography support
|
|
31
33
|
* attributes.
|
|
32
34
|
*
|
|
33
|
-
* @param {Object}
|
|
35
|
+
* @param {Object} attributes Block attributes.
|
|
36
|
+
* @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.
|
|
34
37
|
*
|
|
35
38
|
* @return {Object} Typography block support derived CSS classes & styles.
|
|
36
39
|
*/
|
|
37
|
-
function getTypographyClassesAndStyles(attributes) {
|
|
40
|
+
function getTypographyClassesAndStyles(attributes, isFluidFontSizeActive) {
|
|
38
41
|
var _attributes$style;
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
let typographyStyles = (attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.typography) || {};
|
|
44
|
+
|
|
45
|
+
if (isFluidFontSizeActive) {
|
|
46
|
+
var _attributes$style2, _attributes$style2$ty;
|
|
47
|
+
|
|
48
|
+
typographyStyles = { ...typographyStyles,
|
|
49
|
+
fontSize: (0, _fluidUtils.getComputedFluidTypographyValue)({
|
|
50
|
+
fontSize: attributes === null || attributes === void 0 ? void 0 : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$ty = _attributes$style2.typography) === null || _attributes$style2$ty === void 0 ? void 0 : _attributes$style2$ty.fontSize
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
const style = (0, _style.getInlineStyles)({
|
|
42
56
|
typography: typographyStyles
|
|
43
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["getTypographyClassesAndStyles","attributes","typographyStyles","style","typography","fontFamilyClassName","fontFamily","className"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["getTypographyClassesAndStyles","attributes","isFluidFontSizeActive","typographyStyles","style","typography","fontSize","fontFamilyClassName","fontFamily","className"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;AAKA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,6BAAT,CACNC,UADM,EAENC,qBAFM,EAGL;AAAA;;AACD,MAAIC,gBAAgB,GAAG,CAAAF,UAAU,SAAV,IAAAA,UAAU,WAAV,iCAAAA,UAAU,CAAEG,KAAZ,wEAAmBC,UAAnB,KAAiC,EAAxD;;AAEA,MAAKH,qBAAL,EAA6B;AAAA;;AAC5BC,IAAAA,gBAAgB,GAAG,EAClB,GAAGA,gBADe;AAElBG,MAAAA,QAAQ,EAAE,iDAAiC;AAC1CA,QAAAA,QAAQ,EAAEL,UAAF,aAAEA,UAAF,6CAAEA,UAAU,CAAEG,KAAd,gFAAE,mBAAmBC,UAArB,0DAAE,sBAA+BC;AADC,OAAjC;AAFQ,KAAnB;AAMA;;AAED,QAAMF,KAAK,GAAG,4BAAiB;AAAEC,IAAAA,UAAU,EAAEF;AAAd,GAAjB,CAAd;AACA,QAAMI,mBAAmB,GAAG,CAAC,EAAEN,UAAF,aAAEA,UAAF,eAAEA,UAAU,CAAEO,UAAd,CAAD,GACxB,OAAO,uBAAWP,UAAU,CAACO,UAAtB,CAAoC,cADnB,GAEzB,EAFH;AAIA,QAAMC,SAAS,GAAG,yBACjBF,mBADiB,EAEjB,iCAAkBN,UAAlB,aAAkBA,UAAlB,uBAAkBA,UAAU,CAAEK,QAA9B,CAFiB,CAAlB;AAKA,SAAO;AACNG,IAAAA,SADM;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * Internal dependencies\n */\nimport { getInlineStyles } from './style';\nimport { getFontSizeClass } from '../components/font-sizes';\nimport { getComputedFluidTypographyValue } from '../components/font-sizes/fluid-utils';\n\n// This utility is intended to assist where the serialization of the typography\n// block support is being skipped for a block but the typography related CSS\n// styles still need to be generated so they can be applied to inner elements.\n\n/**\n * Provides the CSS class names and inline styles for a block's typography support\n * attributes.\n *\n * @param {Object} attributes Block attributes.\n * @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.\n *\n * @return {Object} Typography block support derived CSS classes & styles.\n */\nexport function getTypographyClassesAndStyles(\n\tattributes,\n\tisFluidFontSizeActive\n) {\n\tlet typographyStyles = attributes?.style?.typography || {};\n\n\tif ( isFluidFontSizeActive ) {\n\t\ttypographyStyles = {\n\t\t\t...typographyStyles,\n\t\t\tfontSize: getComputedFluidTypographyValue( {\n\t\t\t\tfontSize: attributes?.style?.typography?.fontSize,\n\t\t\t} ),\n\t\t};\n\t}\n\n\tconst style = getInlineStyles( { typography: typographyStyles } );\n\tconst fontFamilyClassName = !! attributes?.fontFamily\n\t\t? `has-${ kebabCase( attributes.fontFamily ) }-font-family`\n\t\t: '';\n\n\tconst className = classnames(\n\t\tfontFamilyClassName,\n\t\tgetFontSizeClass( attributes?.fontSize )\n\t);\n\n\treturn {\n\t\tclassName,\n\t\tstyle,\n\t};\n}\n"]}
|
package/build/hooks/utils.js
CHANGED
|
@@ -47,7 +47,7 @@ function transformStyles(activeSupports, migrationPaths, result, source, index,
|
|
|
47
47
|
var _source$;
|
|
48
48
|
|
|
49
49
|
// If there are no active supports return early.
|
|
50
|
-
if ((0
|
|
50
|
+
if (Object.values(activeSupports !== null && activeSupports !== void 0 ? activeSupports : {}).every(isActive => !isActive)) {
|
|
51
51
|
return result;
|
|
52
52
|
} // If the condition verifies we are probably in the presence of a wrapping transform
|
|
53
53
|
// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.
|
package/build/hooks/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["identity","x","cleanEmptyObject","object","Array","isArray","cleanedNestedObjects","undefined","immutableSet","path","value","clone","transformStyles","activeSupports","migrationPaths","result","source","index","results","isActive","length","innerBlocks","referenceBlockAttributes","attributes","returnBlock","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["identity","x","cleanEmptyObject","object","Array","isArray","cleanedNestedObjects","undefined","immutableSet","path","value","clone","transformStyles","activeSupports","migrationPaths","result","source","index","results","Object","values","every","isActive","length","innerBlocks","referenceBlockAttributes","attributes","returnBlock","entries","forEach","support","styleValue","shouldSkipSerialization","blockType","featureSet","feature","skipSerialization","__experimentalSkipSerialization","includes"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA,MAAMA,QAAQ,GAAKC,CAAF,IAASA,CAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,gBAAgB,GAAKC,MAAF,IAAc;AAC7C,MACCA,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEAC,KAAK,CAACC,OAAN,CAAeF,MAAf,CAHD,EAIE;AACD,WAAOA,MAAP;AACA;;AACD,QAAMG,oBAAoB,GAAG,oBAC5B,uBAAWH,MAAX,EAAmBD,gBAAnB,CAD4B,EAE5BF,QAF4B,CAA7B;AAIA,SAA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,EAAWR,QAAX,CAA2B;;AACtE,QAAKA,QAAL,EAAgB;AACfR,MAAAA,cAAc,CAAEgB,OAAF,CAAd,CAA0BD,OAA1B,CAAqCpB,IAAF,IAAY;AAC9C,cAAMsB,UAAU,GAAG,iBAAKN,wBAAL,EAA+BhB,IAA/B,CAAnB;;AACA,YAAKsB,UAAL,EAAkB;AACjBJ,UAAAA,WAAW,GAAG,EACb,GAAGA,WADU;AAEbD,YAAAA,UAAU,EAAElB,YAAY,CACvBmB,WAAW,CAACD,UADW,EAEvBjB,IAFuB,EAGvBsB,UAHuB;AAFX,WAAd;AAQA;AACD,OAZD;AAaA;AACD,GAhBD;AAiBA,SAAOJ,WAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,uBAAT,CAAkCC,SAAlC,EAA6CC,UAA7C,EAAyDC,OAAzD,EAAmE;AACzE,QAAML,OAAO,GAAG,6BAAiBG,SAAjB,EAA4BC,UAA5B,CAAhB;AACA,QAAME,iBAAiB,GAAGN,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEO,+BAAnC;;AAEA,MAAKjC,KAAK,CAACC,OAAN,CAAe+B,iBAAf,CAAL,EAA0C;AACzC,WAAOA,iBAAiB,CAACE,QAAlB,CAA4BH,OAA5B,CAAP;AACA;;AAED,SAAOC,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { pickBy, isEmpty, mapValues, get, setWith, clone } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\n\nconst identity = ( x ) => x;\n\n/**\n * Removed falsy values from nested object.\n *\n * @param {*} object\n * @return {*} Object cleaned from falsy values\n */\nexport const cleanEmptyObject = ( object ) => {\n\tif (\n\t\tobject === null ||\n\t\ttypeof object !== 'object' ||\n\t\tArray.isArray( object )\n\t) {\n\t\treturn object;\n\t}\n\tconst cleanedNestedObjects = pickBy(\n\t\tmapValues( object, cleanEmptyObject ),\n\t\tidentity\n\t);\n\treturn isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;\n};\n\nexport function immutableSet( object, path, value ) {\n\treturn setWith( object ? clone( object ) : {}, path, value, clone );\n}\n\nexport function transformStyles(\n\tactiveSupports,\n\tmigrationPaths,\n\tresult,\n\tsource,\n\tindex,\n\tresults\n) {\n\t// If there are no active supports return early.\n\tif (\n\t\tObject.values( activeSupports ?? {} ).every(\n\t\t\t( isActive ) => ! isActive\n\t\t)\n\t) {\n\t\treturn result;\n\t}\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\t// For cases where we have a transform from one block to multiple blocks\n\t// or multiple blocks to one block we apply the styles of the first source block\n\t// to the result(s).\n\tlet referenceBlockAttributes = source[ 0 ]?.attributes;\n\t// If we are in presence of transform between more than one block in the source\n\t// that has more than one block in the result\n\t// we apply the styles on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( results.length > 1 && source.length > 1 ) {\n\t\tif ( source[ index ] ) {\n\t\t\treferenceBlockAttributes = source[ index ]?.attributes;\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t}\n\tlet returnBlock = result;\n\tObject.entries( activeSupports ).forEach( ( [ support, isActive ] ) => {\n\t\tif ( isActive ) {\n\t\t\tmigrationPaths[ support ].forEach( ( path ) => {\n\t\t\t\tconst styleValue = get( referenceBlockAttributes, path );\n\t\t\t\tif ( styleValue ) {\n\t\t\t\t\treturnBlock = {\n\t\t\t\t\t\t...returnBlock,\n\t\t\t\t\t\tattributes: immutableSet(\n\t\t\t\t\t\t\treturnBlock.attributes,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tstyleValue\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t} );\n\treturn returnBlock;\n}\n\n/**\n * Check whether serialization of specific block support feature or set should\n * be skipped.\n *\n * @param {string|Object} blockType Block name or block type object.\n * @param {string} featureSet Name of block support feature set.\n * @param {string} feature Name of the individual feature to check.\n *\n * @return {boolean} Whether serialization should occur.\n */\nexport function shouldSkipSerialization( blockType, featureSet, feature ) {\n\tconst support = getBlockSupport( blockType, featureSet );\n\tconst skipSerialization = support?.__experimentalSkipSerialization;\n\n\tif ( Array.isArray( skipSerialization ) ) {\n\t\treturn skipSerialization.includes( feature );\n\t}\n\n\treturn skipSerialization;\n}\n"]}
|