@wordpress/block-editor 12.6.0 → 12.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +2 -2
- package/build/autocompleters/block.js +6 -2
- package/build/autocompleters/block.js.map +1 -1
- package/build/components/block-editing-mode/index.js +1 -1
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-list/block.js +4 -2
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/index.js +2 -4
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-parent-selector/index.js +6 -21
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +3 -17
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -34
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/utils.js +56 -51
- package/build/components/block-toolbar/utils.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +4 -2
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-variation-picker/index.native.js +10 -20
- package/build/components/block-variation-picker/index.native.js.map +1 -1
- package/build/components/editor-styles/index.js +2 -2
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +11 -11
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/behaviors-panel.js +66 -0
- package/build/components/global-styles/behaviors-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +118 -4
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +20 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +4 -4
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +6 -2
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-debounced-input.js +5 -7
- package/build/components/inserter/hooks/use-debounced-input.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +3 -2
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.js +3 -2
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter-list-item/index.js +1 -1
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/link-control/index.js +47 -6
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/link-preview.js +3 -3
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +6 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-replace-flow/index.native.js +15 -3
- package/build/components/media-replace-flow/index.native.js.map +1 -1
- package/build/components/rich-text/format-edit.js +57 -28
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/get-rich-text-values.js +11 -18
- package/build/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +2 -2
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/hooks/behaviors.js +5 -12
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/border.js +2 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/style.js +11 -2
- package/build/hooks/style.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +2 -3
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +4 -71
- package/build/store/selectors.js.map +1 -1
- package/build-module/autocompleters/block.js +7 -3
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +1 -1
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-list/block.js +4 -2
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/index.js +2 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -22
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -18
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +6 -36
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/utils.js +54 -49
- package/build-module/components/block-toolbar/utils.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +4 -2
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-variation-picker/index.native.js +13 -23
- package/build-module/components/block-variation-picker/index.native.js.map +1 -1
- package/build-module/components/editor-styles/index.js +2 -2
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +11 -11
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/behaviors-panel.js +57 -0
- package/build-module/components/global-styles/behaviors-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +115 -5
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +4 -4
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +7 -3
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-debounced-input.js +5 -7
- package/build-module/components/inserter/hooks/use-debounced-input.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +3 -2
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.js +3 -2
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +1 -1
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/link-control/index.js +45 -6
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +3 -3
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +6 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-replace-flow/index.native.js +15 -3
- package/build-module/components/media-replace-flow/index.native.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +51 -26
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/get-rich-text-values.js +13 -18
- package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +2 -2
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/hooks/behaviors.js +5 -12
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/border.js +2 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/style.js +11 -2
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +2 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +4 -69
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +18 -5
- package/build-style/style.css +18 -5
- package/package.json +31 -31
- package/src/autocompleters/block.js +21 -6
- package/src/components/block-draggable/test/index.native.js +2 -3
- package/src/components/block-editing-mode/index.js +1 -1
- package/src/components/block-list/block.js +6 -1
- package/src/components/block-list/index.js +3 -6
- package/src/components/block-list/test/block-invalid-warning.native.js +8 -1
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +24 -0
- package/src/components/block-parent-selector/index.js +30 -42
- package/src/components/block-preview/auto.js +8 -1
- package/src/components/block-preview/style.scss +2 -1
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -13
- package/src/components/block-toolbar/index.js +36 -63
- package/src/components/block-toolbar/utils.js +57 -45
- package/src/components/block-tools/block-contextual-toolbar.js +43 -35
- package/src/components/block-tools/style.scss +17 -5
- package/src/components/block-variation-picker/index.native.js +52 -72
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/editor-styles/index.js +2 -2
- package/src/components/font-sizes/fluid-utils.js +17 -17
- package/src/components/font-sizes/test/fluid-utils.js +6 -6
- package/src/components/global-styles/behaviors-panel.js +71 -0
- package/src/components/global-styles/hooks.js +114 -5
- package/src/components/global-styles/index.js +3 -0
- package/src/components/global-styles/test/typography-utils.js +6 -6
- package/src/components/global-styles/typography-utils.js +4 -4
- package/src/components/global-styles/utils.js +2 -1
- package/src/components/inserter/hooks/use-block-types-state.js +15 -6
- package/src/components/inserter/hooks/use-debounced-input.js +8 -7
- package/src/components/inserter/hooks/use-patterns-state.js +2 -1
- package/src/components/inserter/reusable-blocks-tab.js +4 -1
- package/src/components/inserter-list-item/index.js +3 -1
- package/src/components/link-control/README.md +12 -3
- package/src/components/link-control/index.js +43 -6
- package/src/components/link-control/link-preview.js +6 -4
- package/src/components/link-control/style.scss +3 -2
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/list-view/use-list-view-drop-zone.js +5 -1
- package/src/components/media-replace-flow/index.native.js +12 -3
- package/src/components/media-upload/test/index.native.js +1 -0
- package/src/components/rich-text/format-edit.js +62 -38
- package/src/components/rich-text/get-rich-text-values.js +22 -28
- package/src/components/spacing-sizes-control/test/utils.js +9 -1
- package/src/components/spacing-sizes-control/utils.js +2 -2
- package/src/hooks/behaviors.js +10 -16
- package/src/hooks/border.js +2 -1
- package/src/hooks/style.js +7 -3
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +22 -28
- package/src/store/selectors.js +3 -80
- package/src/store/test/selectors.js +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/format-edit.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/format-edit.js"],"names":["DEFAULT_BLOCK_CONTEXT","usesContextKey","Symbol","Edit","onChange","onFocus","value","forwardedRef","settings","name","edit","EditFunction","usesContext","blockContext","BlockContext","context","Object","fromEntries","entries","filter","key","includes","activeFormat","isActive","undefined","activeObject","isObjectActive","type","attributes","FormatEdit","formatTypes","props","map"],"mappings":";;;;;;;;;;AAIA;;AADA;;AAMA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGA,MAAMA,qBAAqB,GAAG,EAA9B;AAEO,MAAMC,cAAc,GAAGC,MAAM,CAAE,aAAF,CAA7B;;;AAEP,SAASC,IAAT,CAAe;AAAEC,EAAAA,QAAF;AAAYC,EAAAA,OAAZ;AAAqBC,EAAAA,KAArB;AAA4BC,EAAAA,YAA5B;AAA0CC,EAAAA;AAA1C,CAAf,EAAsE;AACrE,QAAM;AACLC,IAAAA,IADK;AAELC,IAAAA,IAAI,EAAEC,YAFD;AAGL,KAAEV,cAAF,GAAoBW;AAHf,MAIFJ,QAJJ;AAMA,QAAMK,YAAY,GAAG,yBAAYC,qBAAZ,CAArB,CAPqE,CASrE;;AACA,QAAMC,OAAO,GAAG,sBAAS,MAAM;AAC9B,WAAOH,WAAW,GACfI,MAAM,CAACC,WAAP,CACAD,MAAM,CAACE,OAAP,CAAgBL,YAAhB,EAA+BM,MAA/B,CAAuC,CAAE,CAAEC,GAAF,CAAF,KACtCR,WAAW,CAACS,QAAZ,CAAsBD,GAAtB,CADD,CADA,CADe,GAMfpB,qBANH;AAOA,GARe,EAQb,CAAEY,WAAF,EAAeC,YAAf,CARa,CAAhB;;AAUA,MAAK,CAAEF,YAAP,EAAsB;AACrB,WAAO,IAAP;AACA;;AAED,QAAMW,YAAY,GAAG,+BAAiBhB,KAAjB,EAAwBG,IAAxB,CAArB;AACA,QAAMc,QAAQ,GAAGD,YAAY,KAAKE,SAAlC;AACA,QAAMC,YAAY,GAAG,+BAAiBnB,KAAjB,CAArB;AACA,QAAMoB,cAAc,GACnBD,YAAY,KAAKD,SAAjB,IAA8BC,YAAY,CAACE,IAAb,KAAsBlB,IADrD;AAGA,SACC,4BAAC,YAAD;AACC,IAAA,GAAG,EAAGA,IADP;AAEC,IAAA,QAAQ,EAAGc,QAFZ;AAGC,IAAA,gBAAgB,EAAGA,QAAQ,GAAGD,YAAY,CAACM,UAAb,IAA2B,EAA9B,GAAmC,EAH/D;AAIC,IAAA,cAAc,EAAGF,cAJlB;AAKC,IAAA,sBAAsB,EACrBA,cAAc,GAAGD,YAAY,CAACG,UAAb,IAA2B,EAA9B,GAAmC,EANnD;AAQC,IAAA,KAAK,EAAGtB,KART;AASC,IAAA,QAAQ,EAAGF,QATZ;AAUC,IAAA,OAAO,EAAGC,OAVX;AAWC,IAAA,UAAU,EAAGE,YAXd;AAYC,IAAA,OAAO,EAAGQ;AAZX,IADD;AAgBA;;AAEc,SAASc,UAAT,CAAqB;AAAEC,EAAAA,WAAF;AAAe,KAAGC;AAAlB,CAArB,EAAiD;AAC/D,SAAOD,WAAW,CAACE,GAAZ,CAAmBxB,QAAF,IACvB,4BAAC,IAAD;AAAM,IAAA,QAAQ,EAAGA,QAAjB;AAAA,OAAiCuB,KAAjC;AAAyC,IAAA,GAAG,EAAGvB,QAAQ,CAACC;AAAxD,IADM,CAAP;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getActiveFormat, getActiveObject } from '@wordpress/rich-text';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockContext from '../block-context';\n\nconst DEFAULT_BLOCK_CONTEXT = {};\n\nexport const usesContextKey = Symbol( 'usesContext' );\n\nfunction Edit( { onChange, onFocus, value, forwardedRef, settings } ) {\n\tconst {\n\t\tname,\n\t\tedit: EditFunction,\n\t\t[ usesContextKey ]: usesContext,\n\t} = settings;\n\n\tconst blockContext = useContext( BlockContext );\n\n\t// Assign context values using the block type's declared context needs.\n\tconst context = useMemo( () => {\n\t\treturn usesContext\n\t\t\t? Object.fromEntries(\n\t\t\t\t\tObject.entries( blockContext ).filter( ( [ key ] ) =>\n\t\t\t\t\t\tusesContext.includes( key )\n\t\t\t\t\t)\n\t\t\t )\n\t\t\t: DEFAULT_BLOCK_CONTEXT;\n\t}, [ usesContext, blockContext ] );\n\n\tif ( ! EditFunction ) {\n\t\treturn null;\n\t}\n\n\tconst activeFormat = getActiveFormat( value, name );\n\tconst isActive = activeFormat !== undefined;\n\tconst activeObject = getActiveObject( value );\n\tconst isObjectActive =\n\t\tactiveObject !== undefined && activeObject.type === name;\n\n\treturn (\n\t\t<EditFunction\n\t\t\tkey={ name }\n\t\t\tisActive={ isActive }\n\t\t\tactiveAttributes={ isActive ? activeFormat.attributes || {} : {} }\n\t\t\tisObjectActive={ isObjectActive }\n\t\t\tactiveObjectAttributes={\n\t\t\t\tisObjectActive ? activeObject.attributes || {} : {}\n\t\t\t}\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tonFocus={ onFocus }\n\t\t\tcontentRef={ forwardedRef }\n\t\t\tcontext={ context }\n\t\t/>\n\t);\n}\n\nexport default function FormatEdit( { formatTypes, ...props } ) {\n\treturn formatTypes.map( ( settings ) => (\n\t\t<Edit settings={ settings } { ...props } key={ settings.name } />\n\t) );\n}\n"]}
|
|
@@ -28,13 +28,13 @@ var _content = require("./content");
|
|
|
28
28
|
* except that it does not render the elements to a string, but instead collects
|
|
29
29
|
* the values of all rich text `Content` elements.
|
|
30
30
|
*/
|
|
31
|
-
function addValuesForElement(element,
|
|
31
|
+
function addValuesForElement(element, values, innerBlocks) {
|
|
32
32
|
if (null === element || undefined === element || false === element) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (Array.isArray(element)) {
|
|
37
|
-
return addValuesForElements(element,
|
|
37
|
+
return addValuesForElements(element, values, innerBlocks);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
switch (typeof element) {
|
|
@@ -51,16 +51,15 @@ function addValuesForElement(element, ...args) {
|
|
|
51
51
|
switch (type) {
|
|
52
52
|
case _element.StrictMode:
|
|
53
53
|
case _element.Fragment:
|
|
54
|
-
return addValuesForElements(props.children,
|
|
54
|
+
return addValuesForElements(props.children, values, innerBlocks);
|
|
55
55
|
|
|
56
56
|
case _element.RawHTML:
|
|
57
57
|
return;
|
|
58
58
|
|
|
59
59
|
case _innerBlocks.default.Content:
|
|
60
|
-
return addValuesForBlocks(
|
|
60
|
+
return addValuesForBlocks(values, innerBlocks);
|
|
61
61
|
|
|
62
62
|
case _content.Content:
|
|
63
|
-
const [values] = args;
|
|
64
63
|
values.push(props.value);
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
@@ -68,17 +67,14 @@ function addValuesForElement(element, ...args) {
|
|
|
68
67
|
switch (typeof type) {
|
|
69
68
|
case 'string':
|
|
70
69
|
if (typeof props.children !== 'undefined') {
|
|
71
|
-
return addValuesForElements(props.children,
|
|
70
|
+
return addValuesForElements(props.children, values, innerBlocks);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
return;
|
|
75
74
|
|
|
76
75
|
case 'function':
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return addValuesForElement(type(props), ...args);
|
|
76
|
+
const el = type.prototype && typeof type.prototype.render === 'function' ? new type(props).render() : type(props);
|
|
77
|
+
return addValuesForElement(el, values, innerBlocks);
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
|
|
@@ -90,10 +86,6 @@ function addValuesForElements(children, ...args) {
|
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
|
|
93
|
-
function _getSaveElement(name, attributes, innerBlocks) {
|
|
94
|
-
return (0, _blocks.getSaveElement)(name, attributes, innerBlocks.map(block => _getSaveElement(block.name, block.attributes, block.innerBlocks)));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
89
|
function addValuesForBlocks(values, blocks) {
|
|
98
90
|
for (let i = 0; i < blocks.length; i++) {
|
|
99
91
|
const {
|
|
@@ -101,9 +93,10 @@ function addValuesForBlocks(values, blocks) {
|
|
|
101
93
|
attributes,
|
|
102
94
|
innerBlocks
|
|
103
95
|
} = blocks[i];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
const saveElement = (0, _blocks.getSaveElement)(name, attributes, // Instead of letting save elements use `useInnerBlocksProps.save`,
|
|
97
|
+
// force them to use InnerBlocks.Content instead so we can intercept
|
|
98
|
+
// a single component.
|
|
99
|
+
(0, _element.createElement)(_innerBlocks.default.Content, null));
|
|
107
100
|
addValuesForElement(saveElement, values, innerBlocks);
|
|
108
101
|
}
|
|
109
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["addValuesForElement","element","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["addValuesForElement","element","values","innerBlocks","undefined","Array","isArray","addValuesForElements","type","props","StrictMode","Fragment","children","RawHTML","InnerBlocks","Content","addValuesForBlocks","push","value","el","prototype","render","args","i","length","blocks","name","attributes","saveElement","getRichTextValues","getBlockProps","skipFilters"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AACA;;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,OAA9B,EAAuCC,MAAvC,EAA+CC,WAA/C,EAA6D;AAC5D,MAAK,SAASF,OAAT,IAAoBG,SAAS,KAAKH,OAAlC,IAA6C,UAAUA,OAA5D,EAAsE;AACrE;AACA;;AAED,MAAKI,KAAK,CAACC,OAAN,CAAeL,OAAf,CAAL,EAAgC;AAC/B,WAAOM,oBAAoB,CAAEN,OAAF,EAAWC,MA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GX,QAAQ,CAACY,MAA9B,EAAsCD,CAAC,EAAvC,EAA4C;AAC3CvB,IAAAA,mBAAmB,CAAEY,QAAQ,CAAEW,CAAF,CAAV,EAAiB,GAAGD,IAApB,CAAnB;AACA;AACD;;AAED,SAASN,kBAAT,CAA6Bd,MAA7B,EAAqCuB,MAArC,EAA8C;AAC7C,OAAM,IAAIF,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGE,MAAM,CAACD,MAA5B,EAAoCD,CAAC,EAArC,EAA0C;AACzC,UAAM;AAAEG,MAAAA,IAAF;AAAQC,MAAAA,UAAR;AAAoBxB,MAAAA;AAApB,QAAoCsB,MAAM,CAAEF,CAAF,CAAhD;AACA,UAAMK,WAAW,GAAG,4BACnBF,IADmB,EAEnBC,UAFmB,EAGnB;AACA;AACA;AACA,gCAAC,oBAAD,CAAa,OAAb,OANmB,CAApB;AAQA3B,IAAAA,mBAAmB,CAAE4B,WAAF,EAAe1B,MAAf,EAAuBC,WAAvB,CAAnB;AACA;AACD;;AAEM,SAAS0B,iBAAT,CAA4BJ,MAAM,GAAG,EAArC,EAA0C;AAChDK,kCAAcC,WAAd,GAA4B,IAA5B;AACA,QAAM7B,MAAM,GAAG,EAAf;AACAc,EAAAA,kBAAkB,CAAEd,MAAF,EAAUuB,MAAV,CAAlB;AACAK,kCAAcC,WAAd,GAA4B,KAA5B;AACA,SAAO7B,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML, StrictMode, Fragment } from '@wordpress/element';\nimport {\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from '../inner-blocks';\nimport { Content } from './content';\n\n/*\n * This function is similar to `@wordpress/element`'s `renderToString` function,\n * except that it does not render the elements to a string, but instead collects\n * the values of all rich text `Content` elements.\n */\nfunction addValuesForElement( element, values, innerBlocks ) {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn;\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn addValuesForElements( element, values, innerBlocks );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\tcase 'number':\n\t\t\treturn;\n\t}\n\n\tconst { type, props } = element;\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn addValuesForElements( props.children, values, innerBlocks );\n\t\tcase RawHTML:\n\t\t\treturn;\n\t\tcase InnerBlocks.Content:\n\t\t\treturn addValuesForBlocks( values, innerBlocks );\n\t\tcase Content:\n\t\t\tvalues.push( props.value );\n\t\t\treturn;\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\tif ( typeof props.children !== 'undefined' ) {\n\t\t\t\treturn addValuesForElements(\n\t\t\t\t\tprops.children,\n\t\t\t\t\tvalues,\n\t\t\t\t\tinnerBlocks\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\tcase 'function':\n\t\t\tconst el =\n\t\t\t\ttype.prototype && typeof type.prototype.render === 'function'\n\t\t\t\t\t? new type( props ).render()\n\t\t\t\t\t: type( props );\n\t\t\treturn addValuesForElement( el, values, innerBlocks );\n\t}\n}\n\nfunction addValuesForElements( children, ...args ) {\n\tchildren = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < children.length; i++ ) {\n\t\taddValuesForElement( children[ i ], ...args );\n\t}\n}\n\nfunction addValuesForBlocks( values, blocks ) {\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tconst { name, attributes, innerBlocks } = blocks[ i ];\n\t\tconst saveElement = getSaveElement(\n\t\t\tname,\n\t\t\tattributes,\n\t\t\t// Instead of letting save elements use `useInnerBlocksProps.save`,\n\t\t\t// force them to use InnerBlocks.Content instead so we can intercept\n\t\t\t// a single component.\n\t\t\t<InnerBlocks.Content />\n\t\t);\n\t\taddValuesForElement( saveElement, values, innerBlocks );\n\t}\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = [];\n\taddValuesForBlocks( values, blocks );\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
|
|
@@ -115,8 +115,8 @@ function getCustomValueFromPreset(value, spacingSizes) {
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
function getPresetValueFromCustomValue(value, spacingSizes) {
|
|
118
|
-
// Return value as-is if it is already a preset;
|
|
119
|
-
if (isValueSpacingPreset(value) || value === '0') {
|
|
118
|
+
// Return value as-is if it is undefined or is already a preset, or '0';
|
|
119
|
+
if (!value || isValueSpacingPreset(value) || value === '0') {
|
|
120
120
|
return value;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","sidesAll","axial","sidesAxial","horizontal","sidesHorizontal","vertical","sidesVertical","sidesTop","sidesRight","sidesBottom","sidesLeft","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAaO,MAAMA,SAAS,GAAG,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CAAlB;;AAEA,MAAMC,cAAc,GAAG;AAC7BC,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AsCpD;;;AACA,SAAOnC,KAAK,CAACf,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is already a preset;\n\tif ( isValueSpacingPreset( value ) || value === '0' ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","sidesAll","axial","sidesAxial","horizontal","sidesHorizontal","vertical","sidesVertical","sidesTop","sidesRight","sidesBottom","sidesLeft","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAaO,MAAMA,SAAS,GAAG,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CAAlB;;AAEA,MAAMC,cAAc,GAAG;AAC7BC,EAAAA,GAAG,EAAEC,SADwB;AAE7BC,EAAAA,KAAK,EAAED,SAFsB;AAG7BE,EAAAA,MAAM,EAAEF,SAHqB;AAI7BG,EAAAA,IAAI,EAAEH;AAJuB,CAAvB;;AAOA,MAAMI,KAAK,GAAG;AACpBC,EAAAA,MAAM,EAAEC,eADY;AAEpBC,EAAAA,KAAK,EAAEC,iBAFa;AAGpBC,EAAAA,UAAU,EAAEC,sBAHQ;AAIpBC,EAAAA,QAAQ,EAAEC,oBAJU;AAKpBb,EAAAA,GAAG,EAAEc,eALe;AAMpBZ,EAAAA,KAAK,EAAEa,iBANa;A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CAAnB,CAFoD,CAIpD;AACA;AACA;AACA;;AACA,QAAMC,sBAAsB,GAC3B3E,GAAG,KAAKG,MAAR,IAAkBC,IAAI,KAAKF,KAA3B,KAAsC,CAAC,CAAEF,GAAH,IAAU,CAAC,CAAEI,IAAnD,CADD;AAEA,QAAMwE,2BAA2B,GAChC,CAAEH,UAAU,CAACvB,MAAb,IAAuBoB,uBAAuB,CAAEd,KAAF,CAD/C;;AAGA,MACCG,cAAc,CAAEH,KAAF,CAAd,KACEmB,sBAAsB,IAAIC,2BAD5B,CADD,EAGE;AACD,WAAOvD,KAAK,CAACb,KAAb;AACA,GAlBmD,CAoBpD;AACA;;;AACA,MAAKiE,UAAU,CAACvB,MAAX,KAAsB,CAA3B,EAA+B;AAC9B,QAAImB,IAAJ;AAEAf,IAAAA,MAAM,CAACuB,OAAP,CAAgBxB,MAAhB,EAAyByB,IAAzB,CAA+B,CAAE,CAAEC,GAAF,EAAOxD,KAAP,CAAF,KAAsB;AACpD8C,MAAAA,IAAI,GAAGU,GAAP;AACA,aAAOxD,KAAK,KAAKtB,SAAjB;AACA,KAHD;AAKA,WAAOoE,IAAP;AACA,GA/BmD,CAiCpD;;;AACA,MAAKb,KAAK,EAAEN,MAAP,KAAkB,CAAlB,IAAuB,CAAEuB,UAAU,CAACvB,MAAzC,EAAkD;AACjD,WAAOM,KAAK,CAAE,CAAF,CAAZ;AACA,GApCmD,CAsCpD;;;AACA,SAAOnC,KAAK,CAACf,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is undefined or is already a preset, or '0';\n\tif ( ! value || isValueSpacingPreset( value ) || value === '0' ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
|
package/build/hooks/behaviors.js
CHANGED
|
@@ -38,16 +38,13 @@ function BehaviorsControl({
|
|
|
38
38
|
disabled = false
|
|
39
39
|
}) {
|
|
40
40
|
const {
|
|
41
|
-
settings
|
|
42
|
-
themeBehaviors
|
|
41
|
+
settings
|
|
43
42
|
} = (0, _data.useSelect)(select => {
|
|
44
43
|
const {
|
|
45
|
-
getBehaviors,
|
|
46
44
|
getSettings
|
|
47
45
|
} = select(_store.store);
|
|
48
46
|
return {
|
|
49
|
-
settings: getSettings()?.__experimentalFeatures?.blocks?.[blockName]?.behaviors
|
|
50
|
-
themeBehaviors: getBehaviors()?.blocks?.[blockName]
|
|
47
|
+
settings: getSettings()?.__experimentalFeatures?.blocks?.[blockName]?.behaviors || {}
|
|
51
48
|
};
|
|
52
49
|
}, [blockName]);
|
|
53
50
|
const defaultBehaviors = {
|
|
@@ -71,8 +68,7 @@ function BehaviorsControl({
|
|
|
71
68
|
behaviors,
|
|
72
69
|
behaviorsValue
|
|
73
70
|
} = (0, _element.useMemo)(() => {
|
|
74
|
-
const mergedBehaviors = { ...
|
|
75
|
-
...(blockBehaviors || {})
|
|
71
|
+
const mergedBehaviors = { ...(blockBehaviors || {})
|
|
76
72
|
};
|
|
77
73
|
let value = '';
|
|
78
74
|
|
|
@@ -88,7 +84,7 @@ function BehaviorsControl({
|
|
|
88
84
|
behaviors: mergedBehaviors,
|
|
89
85
|
behaviorsValue: value
|
|
90
86
|
};
|
|
91
|
-
}, [blockBehaviors
|
|
87
|
+
}, [blockBehaviors]); // If every behavior is disabled, do not show the behaviors inspector control.
|
|
92
88
|
|
|
93
89
|
if (behaviorsOptions.length === 0) {
|
|
94
90
|
return null;
|
|
@@ -184,8 +180,5 @@ const withBehaviors = (0, _compose.createHigherOrderComponent)(BlockEdit => {
|
|
|
184
180
|
};
|
|
185
181
|
}, 'withBehaviors');
|
|
186
182
|
exports.withBehaviors = withBehaviors;
|
|
187
|
-
|
|
188
|
-
if (window?.__experimentalInteractivityAPI) {
|
|
189
|
-
(0, _hooks.addFilter)('editor.BlockEdit', 'core/behaviors/with-inspector-control', withBehaviors);
|
|
190
|
-
}
|
|
183
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/behaviors/with-inspector-control', withBehaviors);
|
|
191
184
|
//# sourceMappingURL=behaviors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/behaviors.js"],"names":["BehaviorsControl","blockName","blockBehaviors","onChangeBehavior","onChangeAnimation","disabled","settings","themeBehaviors","select","getBehaviors","getSettings","blockEditorStore","__experimentalFeatures","blocks","behaviors","defaultBehaviors","default","value","label","noBehaviors","behaviorsOptions","Object","entries","filter","behaviorName","behaviorValue","map","charAt","toUpperCase","slice","toLowerCase","options","values","behaviorsValue","mergedBehaviors","undefined","lightbox","enabled","length","helpText","animation","withBehaviors","BlockEdit","props","blockEdit","name","blockHasLink","attributes","linkDestination","nextValue","setAttributes","window","__experimentalInteractivityAPI"],"mappings":";;;;;;;AASA;;AANA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AAfA;AACA;AACA;;AASA;AACA;AACA;AAIA,SAASA,gBAAT,CAA2B;AAC1BC,EAAAA,SAD0B;AAE1BC,EAAAA,cAF0B;AAG1BC,EAAAA,gBAH0B;AAI1BC,EAAAA,iBAJ0B;AAK1BC,EAAAA,QAAQ,GAAG;AALe,CAA3B,EAMI;AACH,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAA+B,qBAClCC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB,QAAgCF,MAAM,CAAEG,YAAF,CAA5C;AAEA,WAAO;AACNL,MAAAA,QAAQ,EACPI,WAAW,IAAIE,sBAAf,EAAuCC,MAAvC,GAAiDZ,SAAjD,GACGa,SAHE;AAINP,MAAAA,cAAc,EAAEE,YAAY,IAAII,MAAhB,GAA0BZ,SAA1B;AAJV,KAAP;AAMA,GAVmC,EAWpC,CAAEA,SAAF,CAXoC,CAArC;AAcA,QAAMc,gBAAgB,GAAG;AACxBC,IAAAA,OAAO,EAAE;AACRC,MAAAA,KAAK,EAAE,SADC;AAERC,MAAAA,KAAK,EAAE,cAAI,SAAJ;AAFC,KADe;AAKxBC,IAAAA,WAAW,EAAE;AACZF,MAAAA,KAAK,EAAE,EADK;AAEZC,MAAAA,KAAK,EAAE,cAAI,cAAJ;AAFK;AALW,GAAzB;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wBACC,kBADD,EAEC,uCAFD,EAGCX,aAHD;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { InspectorControls } from '../components';\n\nfunction BehaviorsControl( {\n\tblockName,\n\tblockBehaviors,\n\tonChangeBehavior,\n\tonChangeAnimation,\n\tdisabled = false,\n} ) {\n\tconst { settings, themeBehaviors } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBehaviors, getSettings } = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tsettings:\n\t\t\t\t\tgetSettings()?.__experimentalFeatures?.blocks?.[ blockName ]\n\t\t\t\t\t\t?.behaviors,\n\t\t\t\tthemeBehaviors: getBehaviors()?.blocks?.[ blockName ],\n\t\t\t};\n\t\t},\n\t\t[ blockName ]\n\t);\n\n\tconst defaultBehaviors = {\n\t\tdefault: {\n\t\t\tvalue: 'default',\n\t\t\tlabel: __( 'Default' ),\n\t\t},\n\t\tnoBehaviors: {\n\t\t\tvalue: '',\n\t\t\tlabel: __( 'No behaviors' ),\n\t\t},\n\t};\n\n\tconst behaviorsOptions = Object.entries( settings )\n\t\t.filter(\n\t\t\t( [ behaviorName, behaviorValue ] ) =>\n\t\t\t\thasBlockSupport( blockName, `behaviors.${ behaviorName }` ) &&\n\t\t\t\tbehaviorValue\n\t\t) // Filter out behaviors that are disabled.\n\t\t.map( ( [ behaviorName ] ) => ( {\n\t\t\tvalue: behaviorName,\n\t\t\t// Capitalize the first letter of the behavior name.\n\t\t\tlabel: `${ behaviorName.charAt( 0 ).toUpperCase() }${ behaviorName\n\t\t\t\t.slice( 1 )\n\t\t\t\t.toLowerCase() }`,\n\t\t} ) );\n\n\tconst options = [\n\t\t...Object.values( defaultBehaviors ),\n\t\t...behaviorsOptions,\n\t];\n\n\tconst { behaviors, behaviorsValue } = useMemo( () => {\n\t\tconst mergedBehaviors = {\n\t\t\t...themeBehaviors,\n\t\t\t...( blockBehaviors || {} ),\n\t\t};\n\n\t\tlet value = '';\n\t\tif ( blockBehaviors === undefined ) {\n\t\t\tvalue = 'default';\n\t\t}\n\t\tif ( blockBehaviors?.lightbox.enabled ) {\n\t\t\tvalue = 'lightbox';\n\t\t}\n\t\treturn {\n\t\t\tbehaviors: mergedBehaviors,\n\t\t\tbehaviorsValue: value,\n\t\t};\n\t}, [ blockBehaviors, themeBehaviors ] );\n\t// If every behavior is disabled, do not show the behaviors inspector control.\n\tif ( behaviorsOptions.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst helpText = disabled\n\t\t? __( 'The lightbox behavior is disabled for linked images.' )\n\t\t: '';\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<div>\n\t\t\t\t<SelectControl\n\t\t\t\t\tlabel={ __( 'Behaviors' ) }\n\t\t\t\t\t// At the moment we are only supporting one behavior (Lightbox)\n\t\t\t\t\tvalue={ behaviorsValue }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ onChangeBehavior }\n\t\t\t\t\thideCancelButton={ true }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t\t{ behaviorsValue === 'lightbox' && (\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Animation' ) }\n\t\t\t\t\t\t// At the moment we are only supporting one behavior (Lightbox)\n\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\tbehaviors?.lightbox.animation\n\t\t\t\t\t\t\t\t? behaviors?.lightbox.animation\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptions={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: 'zoom',\n\t\t\t\t\t\t\t\tlabel: __( 'Zoom' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: 'fade',\n\t\t\t\t\t\t\t\tlabel: __( 'Fade' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t] }\n\t\t\t\t\t\tonChange={ onChangeAnimation }\n\t\t\t\t\t\thideCancelButton={ false }\n\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning behaviors to blocks if behaviors are enabled in the theme.json.\n *\n * Currently, only the `core/image` block is supported.\n *\n * @param {WPComponent} BlockEdit Original component.\n *\n * @return {WPComponent} Wrapped component.\n */\nexport const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn ( props ) => {\n\t\tconst blockEdit = <BlockEdit key=\"edit\" { ...props } />;\n\t\t// Only add behaviors to blocks with support.\n\t\tif ( ! hasBlockSupport( props.name, 'behaviors' ) ) {\n\t\t\treturn blockEdit;\n\t\t}\n\t\tconst blockHasLink =\n\t\t\ttypeof props.attributes?.linkDestination !== 'undefined' &&\n\t\t\tprops.attributes?.linkDestination !== 'none';\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ blockEdit }\n\t\t\t\t<BehaviorsControl\n\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\tblockBehaviors={ props.attributes.behaviors }\n\t\t\t\t\tonChangeBehavior={ ( nextValue ) => {\n\t\t\t\t\t\tif ( nextValue === 'default' ) {\n\t\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\t\tbehaviors: undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If the user selects something, it means that they want to\n\t\t\t\t\t\t\t// change the default value (true) so we save it in the attributes.\n\t\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\t\tbehaviors: {\n\t\t\t\t\t\t\t\t\tlightbox: {\n\t\t\t\t\t\t\t\t\t\tenabled: nextValue === 'lightbox',\n\t\t\t\t\t\t\t\t\t\tanimation:\n\t\t\t\t\t\t\t\t\t\t\tnextValue === 'lightbox'\n\t\t\t\t\t\t\t\t\t\t\t\t? 'zoom'\n\t\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonChangeAnimation={ ( nextValue ) => {\n\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\tbehaviors: {\n\t\t\t\t\t\t\t\tlightbox: {\n\t\t\t\t\t\t\t\t\tenabled:\n\t\t\t\t\t\t\t\t\t\tprops.attributes.behaviors.lightbox\n\t\t\t\t\t\t\t\t\t\t\t.enabled,\n\t\t\t\t\t\t\t\t\tanimation: nextValue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdisabled={ blockHasLink }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n}, 'withBehaviors' );\n\nif ( window?.__experimentalInteractivityAPI ) {\n\taddFilter(\n\t\t'editor.BlockEdit',\n\t\t'core/behaviors/with-inspector-control',\n\t\twithBehaviors\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/behaviors.js"],"names":["BehaviorsControl","blockName","blockBehaviors","onChangeBehavior","onChangeAnimation","disabled","settings","select","getSettings","blockEditorStore","__experimentalFeatures","blocks","behaviors","defaultBehaviors","default","value","label","noBehaviors","behaviorsOptions","Object","entries","filter","behaviorName","behaviorValue","map","charAt","toUpperCase","slice","toLowerCase","options","values","behaviorsValue","mergedBehaviors","undefined","lightbox","enabled","length","helpText","animation","withBehaviors","BlockEdit","props","blockEdit","name","blockHasLink","attributes","linkDestination","nextValue","setAttributes"],"mappings":";;;;;;;AASA;;AANA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AAfA;AACA;AACA;;AASA;AACA;AACA;AAIA,SAASA,gBAAT,CAA2B;AAC1BC,EAAAA,SAD0B;AAE1BC,EAAAA,cAF0B;AAG1BC,EAAAA,gBAH0B;AAI1BC,EAAAA,iBAJ0B;AAK1BC,EAAAA,QAAQ,GAAG;AALe,CAA3B,EAMI;AACH,QAAM;AAAEC,IAAAA;AAAF,MAAe,qBAClBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAkBD,MAAM,CAAEE,YAAF,CAA9B;AACA,WAAO;AACNH,MAAAA,QAAQ,EACPE,WAAW,IAAIE,sBAAf,EAAuCC,MAAvC,GAAiDV,SAAjD,GACGW,SADH,IACgB;AAHX,KAAP;AAKA,GARmB,EASpB,CAAEX,SAAF,CAToB,CAArB;AAYA,QAAMY,gBAAgB,GAAG;AACxBC,IAAAA,OAAO,EAAE;AACRC,MAAAA,KAAK,EAAE,SADC;AAERC,MAAAA,KAAK,EAAE,cAAI,SAAJ;AAFC,KADe;AAKxBC,IAAAA,WAAW,EAAE;AACZF,MAAAA,KAAK,EAAE,EADK;AAEZC,MAAAA,KAAK,EAAE,cAAI,cAAJ;AAFK;AALW,GAAzB;AAUA,QAAME,gBAAgB,GAAGC,MAAM,CAACC,OAAP,CAAgBd,QAAhB,EACvBe,MADuB,CAEvB,CAAE,CAAEC,YAAF,EAAgBC,aAAhB,CAAF,KACC,6BAAiBtB,SAAjB,EAA6B,aAAaqB,YAAc,EAAxD,KACAC,aAJsB,EAKtB;AALsB,GAMvBC,GANuB,CAMlB,CAAE,CAAEF,YAAF,CAAF,MAA0B;AAC/BP,IAAAA,KAAK,EAAEO,YADwB;AAE/B;AACAN,IAAAA,KAA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AAiBjC,SAFnC;AAGC,MAAA,gBAAgB,EAAKmC,SAAF,IAAiB;AACnC,YAAKA,SAAS,KAAK,SAAnB,EAA+B;AAC9BN,UAAAA,KAAK,CAACO,aAAN,CAAqB;AACpBpC,YAAAA,SAAS,EAAEqB;AADS,WAArB;AAGA,SAJD,MAIO;AACN;AACA;AACAQ,UAAAA,KAAK,CAACO,aAAN,CAAqB;AACpBpC,YAAAA,SAAS,EAAE;AACVsB,cAAAA,QAAQ,EAAE;AACTC,gBAAAA,OAAO,EAAEY,SAAS,KAAK,UADd;AAETT,gBAAAA,SAAS,EACRS,SAAS,KAAK,UAAd,GACG,MADH,GAEG;AALK;AADA;AADS,WAArB;AAWA;AACD,OAvBF;AAwBC,MAAA,iBAAiB,EAAKA,SAAF,IAAiB;AACpCN,QAAAA,KAAK,CAACO,aAAN,CAAqB;AACpBpC,UAAAA,SAAS,EAAE;AACVsB,YAAAA,QAAQ,EAAE;AACTC,cAAAA,OAAO,EACNM,KAAK,CAACI,UAAN,CAAiBjC,SAAjB,CAA2BsB,QAA3B,CACEC,OAHM;AAITG,cAAAA,SAAS,EAAES;AAJF;AADA;AADS,SAArB;AAUA,OAnCF;AAoCC,MAAA,QAAQ,EAAGH;AApCZ,MAFD,CADD;AA2CA,GApDD;AAqDA,CAtD4B,EAsD1B,eAtD0B,CAAtB;;AAwDP,sBACC,kBADD,EAEC,uCAFD,EAGCL,aAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { InspectorControls } from '../components';\n\nfunction BehaviorsControl( {\n\tblockName,\n\tblockBehaviors,\n\tonChangeBehavior,\n\tonChangeAnimation,\n\tdisabled = false,\n} ) {\n\tconst { settings } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\tsettings:\n\t\t\t\t\tgetSettings()?.__experimentalFeatures?.blocks?.[ blockName ]\n\t\t\t\t\t\t?.behaviors || {},\n\t\t\t};\n\t\t},\n\t\t[ blockName ]\n\t);\n\n\tconst defaultBehaviors = {\n\t\tdefault: {\n\t\t\tvalue: 'default',\n\t\t\tlabel: __( 'Default' ),\n\t\t},\n\t\tnoBehaviors: {\n\t\t\tvalue: '',\n\t\t\tlabel: __( 'No behaviors' ),\n\t\t},\n\t};\n\tconst behaviorsOptions = Object.entries( settings )\n\t\t.filter(\n\t\t\t( [ behaviorName, behaviorValue ] ) =>\n\t\t\t\thasBlockSupport( blockName, `behaviors.${ behaviorName }` ) &&\n\t\t\t\tbehaviorValue\n\t\t) // Filter out behaviors that are disabled.\n\t\t.map( ( [ behaviorName ] ) => ( {\n\t\t\tvalue: behaviorName,\n\t\t\t// Capitalize the first letter of the behavior name.\n\t\t\tlabel: `${ behaviorName.charAt( 0 ).toUpperCase() }${ behaviorName\n\t\t\t\t.slice( 1 )\n\t\t\t\t.toLowerCase() }`,\n\t\t} ) );\n\tconst options = [\n\t\t...Object.values( defaultBehaviors ),\n\t\t...behaviorsOptions,\n\t];\n\n\tconst { behaviors, behaviorsValue } = useMemo( () => {\n\t\tconst mergedBehaviors = {\n\t\t\t...( blockBehaviors || {} ),\n\t\t};\n\n\t\tlet value = '';\n\t\tif ( blockBehaviors === undefined ) {\n\t\t\tvalue = 'default';\n\t\t}\n\t\tif ( blockBehaviors?.lightbox.enabled ) {\n\t\t\tvalue = 'lightbox';\n\t\t}\n\t\treturn {\n\t\t\tbehaviors: mergedBehaviors,\n\t\t\tbehaviorsValue: value,\n\t\t};\n\t}, [ blockBehaviors ] );\n\n\t// If every behavior is disabled, do not show the behaviors inspector control.\n\tif ( behaviorsOptions.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst helpText = disabled\n\t\t? __( 'The lightbox behavior is disabled for linked images.' )\n\t\t: '';\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<div>\n\t\t\t\t<SelectControl\n\t\t\t\t\tlabel={ __( 'Behaviors' ) }\n\t\t\t\t\t// At the moment we are only supporting one behavior (Lightbox)\n\t\t\t\t\tvalue={ behaviorsValue }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ onChangeBehavior }\n\t\t\t\t\thideCancelButton={ true }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t\t{ behaviorsValue === 'lightbox' && (\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Animation' ) }\n\t\t\t\t\t\t// At the moment we are only supporting one behavior (Lightbox)\n\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\tbehaviors?.lightbox.animation\n\t\t\t\t\t\t\t\t? behaviors?.lightbox.animation\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptions={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: 'zoom',\n\t\t\t\t\t\t\t\tlabel: __( 'Zoom' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: 'fade',\n\t\t\t\t\t\t\t\tlabel: __( 'Fade' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t] }\n\t\t\t\t\t\tonChange={ onChangeAnimation }\n\t\t\t\t\t\thideCancelButton={ false }\n\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning behaviors to blocks if behaviors are enabled in the theme.json.\n *\n * Currently, only the `core/image` block is supported.\n *\n * @param {WPComponent} BlockEdit Original component.\n *\n * @return {WPComponent} Wrapped component.\n */\nexport const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn ( props ) => {\n\t\tconst blockEdit = <BlockEdit key=\"edit\" { ...props } />;\n\t\t// Only add behaviors to blocks with support.\n\t\tif ( ! hasBlockSupport( props.name, 'behaviors' ) ) {\n\t\t\treturn blockEdit;\n\t\t}\n\t\tconst blockHasLink =\n\t\t\ttypeof props.attributes?.linkDestination !== 'undefined' &&\n\t\t\tprops.attributes?.linkDestination !== 'none';\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ blockEdit }\n\t\t\t\t<BehaviorsControl\n\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\tblockBehaviors={ props.attributes.behaviors }\n\t\t\t\t\tonChangeBehavior={ ( nextValue ) => {\n\t\t\t\t\t\tif ( nextValue === 'default' ) {\n\t\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\t\tbehaviors: undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If the user selects something, it means that they want to\n\t\t\t\t\t\t\t// change the default value (true) so we save it in the attributes.\n\t\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\t\tbehaviors: {\n\t\t\t\t\t\t\t\t\tlightbox: {\n\t\t\t\t\t\t\t\t\t\tenabled: nextValue === 'lightbox',\n\t\t\t\t\t\t\t\t\t\tanimation:\n\t\t\t\t\t\t\t\t\t\t\tnextValue === 'lightbox'\n\t\t\t\t\t\t\t\t\t\t\t\t? 'zoom'\n\t\t\t\t\t\t\t\t\t\t\t\t: '',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonChangeAnimation={ ( nextValue ) => {\n\t\t\t\t\t\tprops.setAttributes( {\n\t\t\t\t\t\t\tbehaviors: {\n\t\t\t\t\t\t\t\tlightbox: {\n\t\t\t\t\t\t\t\t\tenabled:\n\t\t\t\t\t\t\t\t\t\tprops.attributes.behaviors.lightbox\n\t\t\t\t\t\t\t\t\t\t\t.enabled,\n\t\t\t\t\t\t\t\t\tanimation: nextValue,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdisabled={ blockHasLink }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n}, 'withBehaviors' );\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/behaviors/with-inspector-control',\n\twithBehaviors\n);\n"]}
|
package/build/hooks/border.js
CHANGED
|
@@ -397,10 +397,11 @@ const withBorderColorPaletteStyles = (0, _compose.createHigherOrderComponent)(Bl
|
|
|
397
397
|
borderBottomColor: borderBottomColor || borderColorValue,
|
|
398
398
|
borderLeftColor: borderLeftColor || borderColorValue
|
|
399
399
|
};
|
|
400
|
+
const cleanedExtraStyles = (0, _utils.cleanEmptyObject)(extraStyles) || {};
|
|
400
401
|
let wrapperProps = props.wrapperProps;
|
|
401
402
|
wrapperProps = { ...props.wrapperProps,
|
|
402
403
|
style: { ...props.wrapperProps?.style,
|
|
403
|
-
...
|
|
404
|
+
...cleanedExtraStyles
|
|
404
405
|
}
|
|
405
406
|
};
|
|
406
407
|
return (0, _element.createElement)(BlockListBlock, { ...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border.js"],"names":["BORDER_SUPPORT_KEY","getColorByProperty","colors","property","value","matchedColor","some","origin","color","getMultiOriginColor","namedColor","customColor","colorObject","undefined","getColorSlugFromVariable","exec","styleToAttributes","style","border","borderColor","borderColorValue","borderColorSlug","startsWith","substring","length","updatedStyle","attributesToStyle","attributes","BordersInspectorControl","children","resetAllFilter","attributesResetAllFilter","existingStyle","BorderPanel","props","clientId","name","setAttributes","settings","isEnabled","onChange","newStyle","defaultControls","hasBorderSupport","blockName","feature","Platform","OS","support","radius","width","removeBorderAttribute","attribute","addAttributes","type","addSaveProps","blockType","borderClasses","getBorderClasses","newClassName","className","borderColorClass","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","borderTopColor","top","borderRightColor","right","borderBottomColor","bottom","borderLeftColor","left","extraStyles","wrapperProps"],"mappings":";;;;;;;;;;;;;;;AAWA;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAcO,MAAMA,kBAAkB,GAAG,sBAA3B;;;AAEP,MAAMC,kBAAkB,GAAG,CAAEC,MAAF,EAAUC,QAAV,EAAoBC,KAApB,KAA+B;AACzD,MAAIC,YAAJ;AAEAH,EAAAA,MAAM,CAACI,IAAP,CAAeC,MAAF,IACZA,MAAM,CAACL,MAAP,CAAcI,IAAd,CAAsBE,KAAF,IAAa;AAChC,QAAKA,KAAK,CAAEL,QAAF,CAAL,KAAsBC,KAA3B,EAAmC;AAClCC,MAAAA,YAAY,GAAGG,KAAf;AACA,aAAO,IAAP;AACA;;AAED,WAAO,KAAP;AACA,GAPD,CADD;AAWA,SAAOH,YAAP;AACA,CAfD;;AAiBO,MAAMI,mBAAmB,GAAG,CAAE;AAAEP,EAAAA,MAAF;AAAUQ,EAAAA,UAAV;AAAsBC,EAAAA;AAAtB,CAAF,KAA2C;AAC7E;AACA,MAAKD,UAAL,EAAkB;AACjB,UAAME,WAAW,GAAGX,kBAAkB,CAAEC,MAAF,EAAU,MAAV,EAAkBQ,UAAlB,CAAtC;;AACA,QAAKE,WAAL,EAAmB;AAClB,aAAOA,WAAP;AACA;AACD,GAP4E,CAS7E;;;AACA,MAAK,CAAED,WAAP,EAAqB;AACpB,WAAO;AAAEH,MAAAA,KAAK,EAAEK;AAAT,KAAP;AACA,GAZ4E,CAc7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AJjB,GAApB;AAOA,MAAIwD,YAAY,GAAG1C,KAAK,CAAC0C,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAG1C,KAAK,CAAC0C,YADK;AAEd3D,IAAAA,KAAK,EAAE,EACN,GAAGiB,KAAK,CAAC0C,YAAN,EAAoB3D,KADjB;AAEN,SAAG0D;AAFG;AAFO,GAAf;AAQA,SAAO,4BAAC,cAAD,OAAqBzC,KAArB;AAA6B,IAAA,YAAY,EAAG0C;AAA5C,IAAP;AACA,CAtD0C,EAuD3C,8BAvD2C,CAArC;;AA0DP,sBACC,0BADD,EAEC,2BAFD,EAGCvB,aAHD;AAMA,sBACC,kCADD,EAEC,0BAFD,EAGCE,YAHD;AAMA,sBACC,0BADD,EAEC,0BAFD,EAGCO,YAHD;AAMA,sBACC,uBADD,EAEC,8CAFD,EAGCG,4BAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { __experimentalHasSplitBorders as hasSplitBorders } from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { Platform, useCallback, useMemo } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { getColorClassName } from '../components/colors';\nimport InspectorControls from '../components/inspector-controls';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tcleanEmptyObject,\n\tshouldSkipSerialization,\n\tuseBlockSettings,\n} from './utils';\nimport {\n\tuseHasBorderPanel,\n\tBorderPanel as StylesBorderPanel,\n} from '../components/global-styles';\n\nexport const BORDER_SUPPORT_KEY = '__experimentalBorder';\n\nconst getColorByProperty = ( colors, property, value ) => {\n\tlet matchedColor;\n\n\tcolors.some( ( origin ) =>\n\t\torigin.colors.some( ( color ) => {\n\t\t\tif ( color[ property ] === value ) {\n\t\t\t\tmatchedColor = color;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} )\n\t);\n\n\treturn matchedColor;\n};\n\nexport const getMultiOriginColor = ( { colors, namedColor, customColor } ) => {\n\t// Search each origin (default, theme, or user) for matching color by name.\n\tif ( namedColor ) {\n\t\tconst colorObject = getColorByProperty( colors, 'slug', namedColor );\n\t\tif ( colorObject ) {\n\t\t\treturn colorObject;\n\t\t}\n\t}\n\n\t// Skip if no custom color or matching named color.\n\tif ( ! customColor ) {\n\t\treturn { color: undefined };\n\t}\n\n\t// Attempt to find color via custom color value or build new object.\n\tconst colorObject = getColorByProperty( colors, 'color', customColor );\n\treturn colorObject ? colorObject : { color: customColor };\n};\n\nfunction getColorSlugFromVariable( value ) {\n\tconst namedColor = /var:preset\\|color\\|(.+)/.exec( value );\n\tif ( namedColor && namedColor[ 1 ] ) {\n\t\treturn namedColor[ 1 ];\n\t}\n\treturn null;\n}\n\nfunction styleToAttributes( style ) {\n\tif ( hasSplitBorders( style?.border ) ) {\n\t\treturn {\n\t\t\tstyle,\n\t\t\tborderColor: undefined,\n\t\t};\n\t}\n\n\tconst borderColorValue = style?.border?.color;\n\tconst borderColorSlug = borderColorValue?.startsWith( 'var:preset|color|' )\n\t\t? borderColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.border = {\n\t\t...updatedStyle.border,\n\t\tcolor: borderColorSlug ? undefined : borderColorValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\tborderColor: borderColorSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\tif ( hasSplitBorders( attributes.style?.border ) ) {\n\t\treturn attributes.style;\n\t}\n\treturn {\n\t\t...attributes.style,\n\t\tborder: {\n\t\t\t...attributes.style?.border,\n\t\t\tcolor: attributes.borderColor\n\t\t\t\t? 'var:preset|color|' + attributes.borderColor\n\t\t\t\t: attributes.style?.border?.color,\n\t\t},\n\t};\n}\n\nfunction BordersInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"border\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function BorderPanel( props ) {\n\tconst { clientId, name, attributes, setAttributes } = props;\n\tconst settings = useBlockSettings( name );\n\tconst isEnabled = useHasBorderPanel( settings );\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( {\n\t\t\tstyle: attributes.style,\n\t\t\tborderColor: attributes.borderColor,\n\t\t} );\n\t}, [ attributes.style, attributes.borderColor ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = getBlockSupport( props.name, [\n\t\tBORDER_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\n\treturn (\n\t\t<StylesBorderPanel\n\t\t\tas={ BordersInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Returns a new style object where the specified border attribute has been\n * removed.\n *\n * @param {Object} style Styles from block attributes.\n * @param {string} attribute The border style attribute to clear.\n *\n * @return {Object} Style object with the specified attribute removed.\n */\nexport function removeBorderAttribute( style, attribute ) {\n\treturn cleanEmptyObject( {\n\t\t...style,\n\t\tborder: {\n\t\t\t...style?.border,\n\t\t\t[ attribute ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst borderClasses = getBorderClasses( attributes );\n\tconst newClassName = classnames( props.className, borderClasses );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Generates a CSS class name consisting of all the applicable border color\n * classes given the current block attributes.\n *\n * @param {Object} attributes Block's attributes.\n *\n * @return {string} CSS class name.\n */\nexport function getBorderClasses( attributes ) {\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\treturn classnames( {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor, style } = attributes;\n\t\tconst { colors } = useMultipleOriginColorsAndGradients();\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst { color: borderColorValue } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: borderColor,\n\t\t} );\n\t\tconst { color: borderTopColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.top?.color ),\n\t\t} );\n\t\tconst { color: borderRightColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.right?.color ),\n\t\t} );\n\n\t\tconst { color: borderBottomColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable(\n\t\t\t\tstyle?.border?.bottom?.color\n\t\t\t),\n\t\t} );\n\t\tconst { color: borderLeftColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.left?.color ),\n\t\t} );\n\n\t\tconst extraStyles = {\n\t\t\tborderTopColor: borderTopColor || borderColorValue,\n\t\t\tborderRightColor: borderRightColor || borderColorValue,\n\t\t\tborderBottomColor: borderBottomColor || borderColorValue,\n\t\t\tborderLeftColor: borderLeftColor || borderColorValue,\n\t\t};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t\t...extraStyles,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t},\n\t'withBorderColorPaletteStyles'\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border.js"],"names":["BORDER_SUPPORT_KEY","getColorByProperty","colors","property","value","matchedColor","some","origin","color","getMultiOriginColor","namedColor","customColor","colorObject","undefined","getColorSlugFromVariable","exec","styleToAttributes","style","border","borderColor","borderColorValue","borderColorSlug","startsWith","substring","length","updatedStyle","attributesToStyle","attributes","BordersInspectorControl","children","resetAllFilter","attributesResetAllFilter","existingStyle","BorderPanel","props","clientId","name","setAttributes","settings","isEnabled","onChange","newStyle","defaultControls","hasBorderSupport","blockName","feature","Platform","OS","support","radius","width","removeBorderAttribute","attribute","addAttributes","type","addSaveProps","blockType","borderClasses","getBorderClasses","newClassName","className","borderColorClass","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","borderTopColor","top","borderRightColor","right","borderBottomColor","bottom","borderLeftColor","left","extraStyles","cleanedExtraStyles","wrapperProps"],"mappings":";;;;;;;;;;;;;;;AAWA;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAcO,MAAMA,kBAAkB,GAAG,sBAA3B;;;AAEP,MAAMC,kBAAkB,GAAG,CAAEC,MAAF,EAAUC,QAAV,EAAoBC,KAApB,KAA+B;AACzD,MAAIC,YAAJ;AAEAH,EAAAA,MAAM,CAACI,IAAP,CAAeC,MAAF,IACZA,MAAM,CAACL,MAAP,CAAcI,IAAd,CAAsBE,KAAF,IAAa;AAChC,QAAKA,KAAK,CAAEL,QAAF,CAAL,KAAsBC,KAA3B,EAAmC;AAClCC,MAAAA,YAAY,GAAGG,KAAf;AACA,aAAO,IAAP;AACA;;AAED,WAAO,KAAP;AACA,GAPD,CADD;AAWA,SAAOH,YAAP;AACA,CAfD;;AAiBO,MAAMI,mBAAmB,GAAG,CAAE;AAAEP,EAAAA,MAAF;AAAUQ,EAAAA,UAAV;AAAsBC,EAAAA;AAAtB,CAAF,KAA2C;AAC7E;AACA,MAAKD,UAAL,EAAkB;AACjB,UAAME,WAAW,GA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;AAKA,QAAMmE,WAAW,GAAG;AACnBR,IAAAA,cAAc,EAAEA,cAAc,IAAI/C,gBADf;AAEnBiD,IAAAA,gBAAgB,EAAEA,gBAAgB,IAAIjD,gBAFnB;AAGnBmD,IAAAA,iBAAiB,EAAEA,iBAAiB,IAAInD,gBAHrB;AAInBqD,IAAAA,eAAe,EAAEA,eAAe,IAAIrD;AAJjB,GAApB;AAMA,QAAMwD,kBAAkB,GAAG,6BAAkBD,WAAlB,KAAmC,EAA9D;AAEA,MAAIE,YAAY,GAAG3C,KAAK,CAAC2C,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAG3C,KAAK,CAAC2C,YADK;AAEd5D,IAAAA,KAAK,EAAE,EACN,GAAGiB,KAAK,CAAC2C,YAAN,EAAoB5D,KADjB;AAEN,SAAG2D;AAFG;AAFO,GAAf;AAQA,SAAO,4BAAC,cAAD,OAAqB1C,KAArB;AAA6B,IAAA,YAAY,EAAG2C;AAA5C,IAAP;AACA,CAvD0C,EAwD3C,8BAxD2C,CAArC;;AA2DP,sBACC,0BADD,EAEC,2BAFD,EAGCxB,aAHD;AAMA,sBACC,kCADD,EAEC,0BAFD,EAGCE,YAHD;AAMA,sBACC,0BADD,EAEC,0BAFD,EAGCO,YAHD;AAMA,sBACC,uBADD,EAEC,8CAFD,EAGCG,4BAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { __experimentalHasSplitBorders as hasSplitBorders } from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { Platform, useCallback, useMemo } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { getColorClassName } from '../components/colors';\nimport InspectorControls from '../components/inspector-controls';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tcleanEmptyObject,\n\tshouldSkipSerialization,\n\tuseBlockSettings,\n} from './utils';\nimport {\n\tuseHasBorderPanel,\n\tBorderPanel as StylesBorderPanel,\n} from '../components/global-styles';\n\nexport const BORDER_SUPPORT_KEY = '__experimentalBorder';\n\nconst getColorByProperty = ( colors, property, value ) => {\n\tlet matchedColor;\n\n\tcolors.some( ( origin ) =>\n\t\torigin.colors.some( ( color ) => {\n\t\t\tif ( color[ property ] === value ) {\n\t\t\t\tmatchedColor = color;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} )\n\t);\n\n\treturn matchedColor;\n};\n\nexport const getMultiOriginColor = ( { colors, namedColor, customColor } ) => {\n\t// Search each origin (default, theme, or user) for matching color by name.\n\tif ( namedColor ) {\n\t\tconst colorObject = getColorByProperty( colors, 'slug', namedColor );\n\t\tif ( colorObject ) {\n\t\t\treturn colorObject;\n\t\t}\n\t}\n\n\t// Skip if no custom color or matching named color.\n\tif ( ! customColor ) {\n\t\treturn { color: undefined };\n\t}\n\n\t// Attempt to find color via custom color value or build new object.\n\tconst colorObject = getColorByProperty( colors, 'color', customColor );\n\treturn colorObject ? colorObject : { color: customColor };\n};\n\nfunction getColorSlugFromVariable( value ) {\n\tconst namedColor = /var:preset\\|color\\|(.+)/.exec( value );\n\tif ( namedColor && namedColor[ 1 ] ) {\n\t\treturn namedColor[ 1 ];\n\t}\n\treturn null;\n}\n\nfunction styleToAttributes( style ) {\n\tif ( hasSplitBorders( style?.border ) ) {\n\t\treturn {\n\t\t\tstyle,\n\t\t\tborderColor: undefined,\n\t\t};\n\t}\n\n\tconst borderColorValue = style?.border?.color;\n\tconst borderColorSlug = borderColorValue?.startsWith( 'var:preset|color|' )\n\t\t? borderColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.border = {\n\t\t...updatedStyle.border,\n\t\tcolor: borderColorSlug ? undefined : borderColorValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\tborderColor: borderColorSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\tif ( hasSplitBorders( attributes.style?.border ) ) {\n\t\treturn attributes.style;\n\t}\n\treturn {\n\t\t...attributes.style,\n\t\tborder: {\n\t\t\t...attributes.style?.border,\n\t\t\tcolor: attributes.borderColor\n\t\t\t\t? 'var:preset|color|' + attributes.borderColor\n\t\t\t\t: attributes.style?.border?.color,\n\t\t},\n\t};\n}\n\nfunction BordersInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"border\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function BorderPanel( props ) {\n\tconst { clientId, name, attributes, setAttributes } = props;\n\tconst settings = useBlockSettings( name );\n\tconst isEnabled = useHasBorderPanel( settings );\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( {\n\t\t\tstyle: attributes.style,\n\t\t\tborderColor: attributes.borderColor,\n\t\t} );\n\t}, [ attributes.style, attributes.borderColor ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = getBlockSupport( props.name, [\n\t\tBORDER_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\n\treturn (\n\t\t<StylesBorderPanel\n\t\t\tas={ BordersInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Returns a new style object where the specified border attribute has been\n * removed.\n *\n * @param {Object} style Styles from block attributes.\n * @param {string} attribute The border style attribute to clear.\n *\n * @return {Object} Style object with the specified attribute removed.\n */\nexport function removeBorderAttribute( style, attribute ) {\n\treturn cleanEmptyObject( {\n\t\t...style,\n\t\tborder: {\n\t\t\t...style?.border,\n\t\t\t[ attribute ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst borderClasses = getBorderClasses( attributes );\n\tconst newClassName = classnames( props.className, borderClasses );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Generates a CSS class name consisting of all the applicable border color\n * classes given the current block attributes.\n *\n * @param {Object} attributes Block's attributes.\n *\n * @return {string} CSS class name.\n */\nexport function getBorderClasses( attributes ) {\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\treturn classnames( {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings, BORDER_SUPPORT_KEY, 'color' )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor, style } = attributes;\n\t\tconst { colors } = useMultipleOriginColorsAndGradients();\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst { color: borderColorValue } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: borderColor,\n\t\t} );\n\t\tconst { color: borderTopColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.top?.color ),\n\t\t} );\n\t\tconst { color: borderRightColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.right?.color ),\n\t\t} );\n\n\t\tconst { color: borderBottomColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable(\n\t\t\t\tstyle?.border?.bottom?.color\n\t\t\t),\n\t\t} );\n\t\tconst { color: borderLeftColor } = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: getColorSlugFromVariable( style?.border?.left?.color ),\n\t\t} );\n\n\t\tconst extraStyles = {\n\t\t\tborderTopColor: borderTopColor || borderColorValue,\n\t\t\tborderRightColor: borderRightColor || borderColorValue,\n\t\t\tborderBottomColor: borderBottomColor || borderColorValue,\n\t\t\tborderLeftColor: borderLeftColor || borderColorValue,\n\t\t};\n\t\tconst cleanedExtraStyles = cleanEmptyObject( extraStyles ) || {};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t\t...cleanedExtraStyles,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t},\n\t'withBorderColorPaletteStyles'\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
|
package/build/hooks/style.js
CHANGED
|
@@ -52,7 +52,7 @@ var _blockEditingMode = require("../components/block-editing-mode");
|
|
|
52
52
|
*/
|
|
53
53
|
const styleSupportKeys = [..._typography.TYPOGRAPHY_SUPPORT_KEYS, _border.BORDER_SUPPORT_KEY, _color.COLOR_SUPPORT_KEY, _dimensions.DIMENSIONS_SUPPORT_KEY, _dimensions.SPACING_SUPPORT_KEY];
|
|
54
54
|
|
|
55
|
-
const hasStyleSupport =
|
|
55
|
+
const hasStyleSupport = nameOrType => styleSupportKeys.some(key => (0, _blocks.hasBlockSupport)(nameOrType, key));
|
|
56
56
|
/**
|
|
57
57
|
* Returns the inline styles to add depending on the style object
|
|
58
58
|
*
|
|
@@ -342,13 +342,22 @@ function addEditProps(settings) {
|
|
|
342
342
|
|
|
343
343
|
|
|
344
344
|
const withBlockControls = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
345
|
+
if (!hasStyleSupport(props.name)) {
|
|
346
|
+
return (0, _element.createElement)(BlockEdit, {
|
|
347
|
+
key: "edit",
|
|
348
|
+
...props
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
345
352
|
const shouldDisplayControls = (0, _useDisplayBlockControls.default)();
|
|
346
353
|
const blockEditingMode = (0, _blockEditingMode.useBlockEditingMode)();
|
|
347
354
|
return (0, _element.createElement)(_element.Fragment, null, shouldDisplayControls && blockEditingMode === 'default' && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_color.ColorEdit, { ...props
|
|
348
355
|
}), (0, _element.createElement)(_typography.TypographyPanel, { ...props
|
|
349
356
|
}), (0, _element.createElement)(_border.BorderPanel, { ...props
|
|
350
357
|
}), (0, _element.createElement)(_dimensions.DimensionsPanel, { ...props
|
|
351
|
-
})), (0, _element.createElement)(BlockEdit, {
|
|
358
|
+
})), (0, _element.createElement)(BlockEdit, {
|
|
359
|
+
key: "edit",
|
|
360
|
+
...props
|
|
352
361
|
}));
|
|
353
362
|
}, 'withToolbarControls');
|
|
354
363
|
/**
|