@wordpress/edit-site 4.3.2 → 4.4.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-editor/resizable-editor.js +2 -1
  3. package/build/components/block-editor/resizable-editor.js.map +1 -1
  4. package/build/components/editor/global-styles-renderer.js +2 -1
  5. package/build/components/editor/global-styles-renderer.js.map +1 -1
  6. package/build/components/global-styles/border-panel.js +100 -79
  7. package/build/components/global-styles/border-panel.js.map +1 -1
  8. package/build/components/global-styles/use-global-styles-output.js +91 -15
  9. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  10. package/build/components/global-styles/utils.js +12 -2
  11. package/build/components/global-styles/utils.js.map +1 -1
  12. package/build/components/sidebar/navigation-menu-sidebar/index.js +4 -2
  13. package/build/components/sidebar/navigation-menu-sidebar/index.js.map +1 -1
  14. package/build-module/components/block-editor/resizable-editor.js +2 -1
  15. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  16. package/build-module/components/editor/global-styles-renderer.js +2 -1
  17. package/build-module/components/editor/global-styles-renderer.js.map +1 -1
  18. package/build-module/components/global-styles/border-panel.js +103 -80
  19. package/build-module/components/global-styles/border-panel.js.map +1 -1
  20. package/build-module/components/global-styles/use-global-styles-output.js +87 -13
  21. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  22. package/build-module/components/global-styles/utils.js +12 -2
  23. package/build-module/components/global-styles/utils.js.map +1 -1
  24. package/build-module/components/sidebar/navigation-menu-sidebar/index.js +4 -2
  25. package/build-module/components/sidebar/navigation-menu-sidebar/index.js.map +1 -1
  26. package/build-style/style-rtl.css +39 -0
  27. package/build-style/style.css +39 -0
  28. package/package.json +29 -29
  29. package/src/components/block-editor/resizable-editor.js +6 -2
  30. package/src/components/editor/global-styles-renderer.js +2 -1
  31. package/src/components/global-styles/border-panel.js +112 -109
  32. package/src/components/global-styles/test/use-global-styles-output.js +4 -1
  33. package/src/components/global-styles/use-global-styles-output.js +112 -17
  34. package/src/components/global-styles/utils.js +6 -0
  35. package/src/components/sidebar/navigation-menu-sidebar/index.js +4 -1
  36. package/src/components/sidebar/style.scss +50 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.4.0 (2022-04-21)
6
+
5
7
  ## 4.3.0 (2022-04-08)
6
8
 
7
9
  ## 4.2.0 (2022-03-23)
@@ -51,6 +51,7 @@ function ResizableEditor(_ref) {
51
51
  let {
52
52
  enableResizing,
53
53
  settings,
54
+ children,
54
55
  ...props
55
56
  } = _ref;
56
57
  const deviceType = (0, _data.useSelect)(select => select(_store.store).__experimentalGetPreviewDeviceType(), []);
@@ -158,7 +159,7 @@ function ResizableEditor(_ref) {
158
159
  ref: ref,
159
160
  name: "editor-canvas",
160
161
  className: "edit-site-visual-editor__editor-canvas"
161
- }, props)));
162
+ }, props), settings.svgFilters, children));
162
163
  }
163
164
 
164
165
  var _default = ResizableEditor;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/resizable-editor.js"],"names":["DEFAULT_STYLES","width","height","HANDLE_STYLES_OVERRIDE","position","undefined","userSelect","cursor","top","right","bottom","left","ResizableEditor","enableResizing","settings","props","deviceType","select","editSiteStore","__experimentalGetPreviewDeviceType","deviceStyles","setWidth","setHeight","iframeRef","mouseMoveTypingResetRef","ref","autoResizeIframeHeight","iframe","current","animationFrame","resizeHeight","contentWindow","requestAnimationFrame","contentDocument","documentElement","scrollHeight","resizeObserver","registerObserver","disconnect","ResizeObserver","observe","addEventListener","cancelAnimationFrame","removeEventListener","resizeWidthBy","deltaPixels","offsetWidth","event","direction","element","style","styles","__unstableResolvedAssets"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,cAAc,GAAG;AACtBC,EA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BN,EAxCD,CADD;AA0EA;;eAEcH,e","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { ResizableBox } from '@wordpress/components';\nimport {\n\t__experimentalUseResizeCanvas as useResizeCanvas,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n\t__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport ResizeHandle from './resize-handle';\n\nconst DEFAULT_STYLES = {\n\twidth: '100%',\n\theight: '100%',\n};\n\n// Removes the inline styles in the drag handles.\nconst HANDLE_STYLES_OVERRIDE = {\n\tposition: undefined,\n\tuserSelect: undefined,\n\tcursor: undefined,\n\twidth: undefined,\n\theight: undefined,\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nfunction ResizableEditor( { enableResizing, settings, ...props } ) {\n\tconst deviceType = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editSiteStore ).__experimentalGetPreviewDeviceType(),\n\t\t[]\n\t);\n\tconst deviceStyles = useResizeCanvas( deviceType );\n\tconst [ width, setWidth ] = useState( DEFAULT_STYLES.width );\n\tconst [ height, setHeight ] = useState( DEFAULT_STYLES.height );\n\tconst iframeRef = useRef();\n\tconst mouseMoveTypingResetRef = useMouseMoveTypingReset();\n\tconst ref = useMergeRefs( [ iframeRef, mouseMoveTypingResetRef ] );\n\n\tuseEffect(\n\t\tfunction autoResizeIframeHeight() {\n\t\t\tconst iframe = iframeRef.current;\n\n\t\t\tif ( ! iframe || ! enableResizing ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet animationFrame = null;\n\n\t\t\tfunction resizeHeight() {\n\t\t\t\tif ( ! animationFrame ) {\n\t\t\t\t\t// Throttle the updates on animation frame.\n\t\t\t\t\tanimationFrame = iframe.contentWindow.requestAnimationFrame(\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\tsetHeight(\n\t\t\t\t\t\t\t\tiframe.contentDocument.documentElement\n\t\t\t\t\t\t\t\t\t.scrollHeight\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tanimationFrame = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet resizeObserver;\n\n\t\t\tfunction registerObserver() {\n\t\t\t\tresizeObserver?.disconnect();\n\n\t\t\t\tresizeObserver = new iframe.contentWindow.ResizeObserver(\n\t\t\t\t\tresizeHeight\n\t\t\t\t);\n\t\t\t\t// Observing the <html> rather than the <body> because the latter\n\t\t\t\t// gets destroyed and remounted after initialization in <Iframe>.\n\t\t\t\tresizeObserver.observe(\n\t\t\t\t\tiframe.contentDocument.documentElement\n\t\t\t\t);\n\n\t\t\t\tresizeHeight();\n\t\t\t}\n\n\t\t\t// This is only required in Firefox for some unknown reasons.\n\t\t\tiframe.addEventListener( 'load', registerObserver );\n\t\t\t// This is required in Chrome and Safari.\n\t\t\tregisterObserver();\n\n\t\t\treturn () => {\n\t\t\t\tiframe.contentWindow?.cancelAnimationFrame( animationFrame );\n\t\t\t\tresizeObserver?.disconnect();\n\t\t\t\tiframe.removeEventListener( 'load', registerObserver );\n\t\t\t};\n\t\t},\n\t\t[ enableResizing ]\n\t);\n\n\tconst resizeWidthBy = useCallback( ( deltaPixels ) => {\n\t\tif ( iframeRef.current ) {\n\t\t\tsetWidth( iframeRef.current.offsetWidth + deltaPixels );\n\t\t}\n\t}, [] );\n\n\treturn (\n\t\t<ResizableBox\n\t\t\tsize={ {\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t\tonResizeStop={ ( event, direction, element ) => {\n\t\t\t\tsetWidth( element.style.width );\n\t\t\t} }\n\t\t\tminWidth={ 300 }\n\t\t\tmaxWidth=\"100%\"\n\t\t\tmaxHeight=\"100%\"\n\t\t\tenable={ {\n\t\t\t\tright: enableResizing,\n\t\t\t\tleft: enableResizing,\n\t\t\t} }\n\t\t\tshowHandle={ enableResizing }\n\t\t\t// The editor is centered horizontally, resizing it only\n\t\t\t// moves half the distance. Hence double the ratio to correctly\n\t\t\t// align the cursor to the resizer handle.\n\t\t\tresizeRatio={ 2 }\n\t\t\thandleComponent={ {\n\t\t\t\tleft: (\n\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\tdirection=\"left\"\n\t\t\t\t\t\tresizeWidthBy={ resizeWidthBy }\n\t\t\t\t\t/>\n\t\t\t\t),\n\t\t\t\tright: (\n\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\tdirection=\"right\"\n\t\t\t\t\t\tresizeWidthBy={ resizeWidthBy }\n\t\t\t\t\t/>\n\t\t\t\t),\n\t\t\t} }\n\t\t\thandleClasses={ undefined }\n\t\t\thandleStyles={ {\n\t\t\t\tleft: HANDLE_STYLES_OVERRIDE,\n\t\t\t\tright: HANDLE_STYLES_OVERRIDE,\n\t\t\t} }\n\t\t>\n\t\t\t<Iframe\n\t\t\t\tstyle={ enableResizing ? undefined : deviceStyles }\n\t\t\t\thead={\n\t\t\t\t\t<>\n\t\t\t\t\t\t<EditorStyles styles={ settings.styles } />\n\t\t\t\t\t\t<style>{\n\t\t\t\t\t\t\t// Forming a \"block formatting context\" to prevent margin collapsing.\n\t\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context\n\t\t\t\t\t\t\t`.is-root-container { display: flow-root; }`\n\t\t\t\t\t\t}</style>\n\t\t\t\t\t\t{ enableResizing && (\n\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// Force the <html> and <body>'s heights to fit the content.\n\t\t\t\t\t\t\t\t\t`html, body { height: -moz-fit-content !important; height: fit-content !important; min-height: 0 !important; }`\n\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\t\t// Some themes will have `min-height: 100vh` for the root container,\n\t\t\t\t\t\t\t\t\t// which isn't a requirement in auto resize mode.\n\t\t\t\t\t\t\t\t\t`.is-root-container { min-height: 0 !important; }`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tassets={ settings.__unstableResolvedAssets }\n\t\t\t\tref={ ref }\n\t\t\t\tname=\"editor-canvas\"\n\t\t\t\tclassName=\"edit-site-visual-editor__editor-canvas\"\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t</ResizableBox>\n\t);\n}\n\nexport default ResizableEditor;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/resizable-editor.js"],"names":["DEFAULT_STYLES","width","height","HANDLE_STYLES_OVERRIDE","position","undefined","userSelect","cursor","top","right","bottom","left","ResizableEditor","enableResizing","settings","children","props","deviceType","select","editSiteStore","__experimentalGetPreviewDeviceType","deviceStyles","setWidth","setHeight","iframeRef","mouseMoveTypingResetRef","ref","autoResizeIframeHeight","iframe","current","animationFrame","resizeHeight","contentWindow","requestAnimationFrame","contentDocument","documentElement","scrollHeight","resizeObserver","registerObserver","disconnect","ResizeObserver","observe","addEventListener","cancelAnimationFrame","removeEventListener","resizeWidthBy","deltaPixels","offsetWidth","event","direction","element","style","styles","__unstableResolvedAssets","svgFilters"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,cAAc,GAAG;AACtBC,EAAAA,KAAK,EAAE,MADe;AAEtBC,EAAAA,MAAM,EAAE;AAFc,CAAvB,C,CAKA;;AACA,MAAMC,sBAAsB,GAAG;AAC9BC,EAAAA,QAAQ,EAAEC,SADoB;AAE9BC,EAAAA,UAAU,EAAED,SAFkB;AAG9BE,EAAAA,MAAM,EAAEF,SAHsB;AAI9BJ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,MATV;AAUC,IAAA,SAAS,EAAC,MAVX;AAWC,IAAA,MAAM,EAAG;AACRQ,MAAAA,KAAK,EAAEI,cADC;AAERF,MAAAA,IAAI,EAAEE;AAFE,KAXV;AAeC,IAAA,UAAU,EAAGA,cAfd,CAgBC;AACA;AACA;AAlBD;AAmBC,IAAA,WAAW,EAAG,CAnBf;AAoBC,IAAA,eAAe,EAAG;AACjBF,MAAAA,IAAI,EACH,4BAAC,qBAAD;AACC,QAAA,SAAS,EAAC,MADX;AAEC,QAAA,aAAa,EAAGkC;AAFjB,QAFgB;AAOjBpC,MAAAA,KAAK,EACJ,4BAAC,qBAAD;AACC,QAAA,SAAS,EAAC,OADX;AAEC,QAAA,aAAa,EAAGoC;AAFjB;AARgB,KApBnB;AAkCC,IAAA,aAAa,EAAGxC,SAlCjB;AAmCC,IAAA,YAAY,EAAG;AACdM,MAAAA,IAAI,EAAER,sBADQ;AAEdM,MAAAA,KAAK,EAAEN;AAFO;AAnChB,KAwCC,4BAAC,6BAAD;AACC,IAAA,KAAK,EAAGU,cAAc,GAAGR,SAAH,GAAegB,YADtC;AAEC,IAAA,IAAI,EACH,qDACC,4BAAC,mCAAD;AAAc,MAAA,MAAM,EAAGP,QAAQ,CAACsC;AAAhC,MADD,EAEC,2CACC;AACA;AACC,gDAHF,CAFD,EAOGvC,cAAc,IACf,2CAEE;AACC,mHAHH,EAME;AACA;AACC,sDARH,CARF,CAHF;AAyBC,IAAA,MAAM,EAAGC,QAAQ,CAACuC,wBAzBnB;AA0BC,IAAA,GAAG,EAAG3B,GA1BP;AA2BC,IAAA,IAAI,EAAC,eA3BN;AA4BC,IAAA,SAAS,EAAC;AA5BX,KA6BMV,KA7BN,GAgCGF,QAAQ,CAACwC,UAhCZ,EAiCGvC,QAjCH,CAxCD,CADD;AA8EA;;eAEcH,e","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { ResizableBox } from '@wordpress/components';\nimport {\n\t__experimentalUseResizeCanvas as useResizeCanvas,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n\t__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport ResizeHandle from './resize-handle';\n\nconst DEFAULT_STYLES = {\n\twidth: '100%',\n\theight: '100%',\n};\n\n// Removes the inline styles in the drag handles.\nconst HANDLE_STYLES_OVERRIDE = {\n\tposition: undefined,\n\tuserSelect: undefined,\n\tcursor: undefined,\n\twidth: undefined,\n\theight: undefined,\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nfunction ResizableEditor( { enableResizing, settings, children, ...props } ) {\n\tconst deviceType = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editSiteStore ).__experimentalGetPreviewDeviceType(),\n\t\t[]\n\t);\n\tconst deviceStyles = useResizeCanvas( deviceType );\n\tconst [ width, setWidth ] = useState( DEFAULT_STYLES.width );\n\tconst [ height, setHeight ] = useState( DEFAULT_STYLES.height );\n\tconst iframeRef = useRef();\n\tconst mouseMoveTypingResetRef = useMouseMoveTypingReset();\n\tconst ref = useMergeRefs( [ iframeRef, mouseMoveTypingResetRef ] );\n\n\tuseEffect(\n\t\tfunction autoResizeIframeHeight() {\n\t\t\tconst iframe = iframeRef.current;\n\n\t\t\tif ( ! iframe || ! enableResizing ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet animationFrame = null;\n\n\t\t\tfunction resizeHeight() {\n\t\t\t\tif ( ! animationFrame ) {\n\t\t\t\t\t// Throttle the updates on animation frame.\n\t\t\t\t\tanimationFrame = iframe.contentWindow.requestAnimationFrame(\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\tsetHeight(\n\t\t\t\t\t\t\t\tiframe.contentDocument.documentElement\n\t\t\t\t\t\t\t\t\t.scrollHeight\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tanimationFrame = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet resizeObserver;\n\n\t\t\tfunction registerObserver() {\n\t\t\t\tresizeObserver?.disconnect();\n\n\t\t\t\tresizeObserver = new iframe.contentWindow.ResizeObserver(\n\t\t\t\t\tresizeHeight\n\t\t\t\t);\n\t\t\t\t// Observing the <html> rather than the <body> because the latter\n\t\t\t\t// gets destroyed and remounted after initialization in <Iframe>.\n\t\t\t\tresizeObserver.observe(\n\t\t\t\t\tiframe.contentDocument.documentElement\n\t\t\t\t);\n\n\t\t\t\tresizeHeight();\n\t\t\t}\n\n\t\t\t// This is only required in Firefox for some unknown reasons.\n\t\t\tiframe.addEventListener( 'load', registerObserver );\n\t\t\t// This is required in Chrome and Safari.\n\t\t\tregisterObserver();\n\n\t\t\treturn () => {\n\t\t\t\tiframe.contentWindow?.cancelAnimationFrame( animationFrame );\n\t\t\t\tresizeObserver?.disconnect();\n\t\t\t\tiframe.removeEventListener( 'load', registerObserver );\n\t\t\t};\n\t\t},\n\t\t[ enableResizing ]\n\t);\n\n\tconst resizeWidthBy = useCallback( ( deltaPixels ) => {\n\t\tif ( iframeRef.current ) {\n\t\t\tsetWidth( iframeRef.current.offsetWidth + deltaPixels );\n\t\t}\n\t}, [] );\n\n\treturn (\n\t\t<ResizableBox\n\t\t\tsize={ {\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t\tonResizeStop={ ( event, direction, element ) => {\n\t\t\t\tsetWidth( element.style.width );\n\t\t\t} }\n\t\t\tminWidth={ 300 }\n\t\t\tmaxWidth=\"100%\"\n\t\t\tmaxHeight=\"100%\"\n\t\t\tenable={ {\n\t\t\t\tright: enableResizing,\n\t\t\t\tleft: enableResizing,\n\t\t\t} }\n\t\t\tshowHandle={ enableResizing }\n\t\t\t// The editor is centered horizontally, resizing it only\n\t\t\t// moves half the distance. Hence double the ratio to correctly\n\t\t\t// align the cursor to the resizer handle.\n\t\t\tresizeRatio={ 2 }\n\t\t\thandleComponent={ {\n\t\t\t\tleft: (\n\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\tdirection=\"left\"\n\t\t\t\t\t\tresizeWidthBy={ resizeWidthBy }\n\t\t\t\t\t/>\n\t\t\t\t),\n\t\t\t\tright: (\n\t\t\t\t\t<ResizeHandle\n\t\t\t\t\t\tdirection=\"right\"\n\t\t\t\t\t\tresizeWidthBy={ resizeWidthBy }\n\t\t\t\t\t/>\n\t\t\t\t),\n\t\t\t} }\n\t\t\thandleClasses={ undefined }\n\t\t\thandleStyles={ {\n\t\t\t\tleft: HANDLE_STYLES_OVERRIDE,\n\t\t\t\tright: HANDLE_STYLES_OVERRIDE,\n\t\t\t} }\n\t\t>\n\t\t\t<Iframe\n\t\t\t\tstyle={ enableResizing ? undefined : deviceStyles }\n\t\t\t\thead={\n\t\t\t\t\t<>\n\t\t\t\t\t\t<EditorStyles styles={ settings.styles } />\n\t\t\t\t\t\t<style>{\n\t\t\t\t\t\t\t// Forming a \"block formatting context\" to prevent margin collapsing.\n\t\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context\n\t\t\t\t\t\t\t`.is-root-container { display: flow-root; }`\n\t\t\t\t\t\t}</style>\n\t\t\t\t\t\t{ enableResizing && (\n\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// Force the <html> and <body>'s heights to fit the content.\n\t\t\t\t\t\t\t\t\t`html, body { height: -moz-fit-content !important; height: fit-content !important; min-height: 0 !important; }`\n\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\t\t// Some themes will have `min-height: 100vh` for the root container,\n\t\t\t\t\t\t\t\t\t// which isn't a requirement in auto resize mode.\n\t\t\t\t\t\t\t\t\t`.is-root-container { min-height: 0 !important; }`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tassets={ settings.__unstableResolvedAssets }\n\t\t\t\tref={ ref }\n\t\t\t\tname=\"editor-canvas\"\n\t\t\t\tclassName=\"edit-site-visual-editor__editor-canvas\"\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ /* Filters need to be rendered before children to avoid Safari rendering issues. */ }\n\t\t\t\t{ settings.svgFilters }\n\t\t\t\t{ children }\n\t\t\t</Iframe>\n\t\t</ResizableBox>\n\t);\n}\n\nexport default ResizableEditor;\n"]}
@@ -31,7 +31,7 @@ var _useGlobalStylesOutput = require("../global-styles/use-global-styles-output"
31
31
  * Internal dependencies
32
32
  */
33
33
  function useGlobalStylesRenderer() {
34
- const [styles, settings] = (0, _useGlobalStylesOutput.useGlobalStylesOutput)();
34
+ const [styles, settings, svgFilters] = (0, _useGlobalStylesOutput.useGlobalStylesOutput)();
35
35
  const {
36
36
  getSettings
37
37
  } = (0, _data.useSelect)(_store.store);
@@ -47,6 +47,7 @@ function useGlobalStylesRenderer() {
47
47
  const nonGlobalStyles = (0, _lodash.filter)(currentStoreSettings.styles, style => !style.isGlobalStyles);
48
48
  updateSettings({ ...currentStoreSettings,
49
49
  styles: [...nonGlobalStyles, ...styles],
50
+ svgFilters,
50
51
  __experimentalFeatures: settings
51
52
  });
52
53
  }, [styles, settings]);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/editor/global-styles-renderer.js"],"names":["useGlobalStylesRenderer","styles","settings","getSettings","editSiteStore","updateSettings","currentStoreSettings","nonGlobalStyles","style","isGlobalStyles","__experimentalFeatures","GlobalStylesRenderer"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAKA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AAGA,SAASA,uBAAT,GAAmC;AAClC,QAAM,CAAEC,MAAF,EAAUC,QAAV,IAAuB,mDAA7B;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAkB,qBAAWC,YAAX,CAAxB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAqB,uBAAaD,YAAb,CAA3B;AAEA,0BAAW,MAAM;AAChB,QAAK,CAAEH,MAAF,IAAY,CAAEC,QAAnB,EAA8B;AAC7B;AACA;;AAED,UAAMI,oBAAoB,GAAGH,WAAW,EAAxC;AACA,UAAMI,eAAe,GAAG,oBACvBD,oBAAoB,CAACL,MADE,EAErBO,KAAF,IAAa,CAAEA,KAAK,CAACC,cAFE,CAAxB;AAIAJ,IAAAA,cAAc,CAAE,EACf,GAAGC,oBADY;AAEfL,MAAAA,MAAM,EAAE,CAAE,GAAGM,eAAL,EAAsB,GAAGN,MAAzB,CAFO;AAGfS,MAAAA,sBAAsB,EAAER;AAHT,KAAF,CAAd;AAKA,GAfD,EAeG,CAAED,MAAF,EAAUC,QAAV,CAfH;AAgBA;;AAEM,SAASS,oBAAT,GAAgC;AACtCX,EAAAA,uBAAuB;AAEvB,SAAO,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\n\n/**\n * Internal dependencies\n */\nimport { useGlobalStylesOutput } from '../global-styles/use-global-styles-output';\n\nfunction useGlobalStylesRenderer() {\n\tconst [ styles, settings ] = useGlobalStylesOutput();\n\tconst { getSettings } = useSelect( editSiteStore );\n\tconst { updateSettings } = useDispatch( editSiteStore );\n\n\tuseEffect( () => {\n\t\tif ( ! styles || ! settings ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentStoreSettings = getSettings();\n\t\tconst nonGlobalStyles = filter(\n\t\t\tcurrentStoreSettings.styles,\n\t\t\t( style ) => ! style.isGlobalStyles\n\t\t);\n\t\tupdateSettings( {\n\t\t\t...currentStoreSettings,\n\t\t\tstyles: [ ...nonGlobalStyles, ...styles ],\n\t\t\t__experimentalFeatures: settings,\n\t\t} );\n\t}, [ styles, settings ] );\n}\n\nexport function GlobalStylesRenderer() {\n\tuseGlobalStylesRenderer();\n\n\treturn null;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/editor/global-styles-renderer.js"],"names":["useGlobalStylesRenderer","styles","settings","svgFilters","getSettings","editSiteStore","updateSettings","currentStoreSettings","nonGlobalStyles","style","isGlobalStyles","__experimentalFeatures","GlobalStylesRenderer"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAKA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AAGA,SAASA,uBAAT,GAAmC;AAClC,QAAM,CAAEC,MAAF,EAAUC,QAAV,EAAoBC,UAApB,IAAmC,mDAAzC;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAkB,qBAAWC,YAAX,CAAxB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAqB,uBAAaD,YAAb,CAA3B;AAEA,0BAAW,MAAM;AAChB,QAAK,CAAEJ,MAAF,IAAY,CAAEC,QAAnB,EAA8B;AAC7B;AACA;;AAED,UAAMK,oBAAoB,GAAGH,WAAW,EAAxC;AACA,UAAMI,eAAe,GAAG,oBACvBD,oBAAoB,CAACN,MADE,EAErBQ,KAAF,IAAa,CAAEA,KAAK,CAACC,cAFE,CAAxB;AAIAJ,IAAAA,cAAc,CAAE,EACf,GAAGC,oBADY;AAEfN,MAAAA,MAAM,EAAE,CAAE,GAAGO,eAAL,EAAsB,GAAGP,MAAzB,CAFO;AAGfE,MAAAA,UAHe;AAIfQ,MAAAA,sBAAsB,EAAET;AAJT,KAAF,CAAd;AAMA,GAhBD,EAgBG,CAAED,MAAF,EAAUC,QAAV,CAhBH;AAiBA;;AAEM,SAASU,oBAAT,GAAgC;AACtCZ,EAAAA,uBAAuB;AAEvB,SAAO,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\n\n/**\n * Internal dependencies\n */\nimport { useGlobalStylesOutput } from '../global-styles/use-global-styles-output';\n\nfunction useGlobalStylesRenderer() {\n\tconst [ styles, settings, svgFilters ] = useGlobalStylesOutput();\n\tconst { getSettings } = useSelect( editSiteStore );\n\tconst { updateSettings } = useDispatch( editSiteStore );\n\n\tuseEffect( () => {\n\t\tif ( ! styles || ! settings ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentStoreSettings = getSettings();\n\t\tconst nonGlobalStyles = filter(\n\t\t\tcurrentStoreSettings.styles,\n\t\t\t( style ) => ! style.isGlobalStyles\n\t\t);\n\t\tupdateSettings( {\n\t\t\t...currentStoreSettings,\n\t\t\tstyles: [ ...nonGlobalStyles, ...styles ],\n\t\t\tsvgFilters,\n\t\t\t__experimentalFeatures: settings,\n\t\t} );\n\t}, [ styles, settings ] );\n}\n\nexport function GlobalStylesRenderer() {\n\tuseGlobalStylesRenderer();\n\n\treturn null;\n}\n"]}
@@ -23,8 +23,6 @@ var _hooks = require("./hooks");
23
23
  /**
24
24
  * Internal dependencies
25
25
  */
26
- const MIN_BORDER_WIDTH = 0;
27
-
28
26
  function useHasBorderPanel(name) {
29
27
  const controls = [useHasBorderColorControl(name), useHasBorderRadiusControl(name), useHasBorderStyleControl(name), useHasBorderWidthControl(name)];
30
28
  return controls.some(Boolean);
@@ -50,6 +48,37 @@ function useHasBorderWidthControl(name) {
50
48
  return (0, _hooks.useSetting)('border.width', name)[0] && supports.includes('borderWidth');
51
49
  }
52
50
 
51
+ function applyFallbackStyle(border) {
52
+ if (!border) {
53
+ return border;
54
+ }
55
+
56
+ if (!border.style && (border.color || border.width)) {
57
+ return { ...border,
58
+ style: 'solid'
59
+ };
60
+ }
61
+
62
+ return border;
63
+ }
64
+
65
+ function applyAllFallbackStyles(border) {
66
+ if (!border) {
67
+ return border;
68
+ }
69
+
70
+ if ((0, _components.__experimentalHasSplitBorders)(border)) {
71
+ return {
72
+ top: applyFallbackStyle(border.top),
73
+ right: applyFallbackStyle(border.right),
74
+ bottom: applyFallbackStyle(border.bottom),
75
+ left: applyFallbackStyle(border.left)
76
+ };
77
+ }
78
+
79
+ return applyFallbackStyle(border);
80
+ }
81
+
53
82
  function BorderPanel(_ref) {
54
83
  let {
55
84
  name
@@ -57,46 +86,11 @@ function BorderPanel(_ref) {
57
86
  // To better reflect if the user has customized a value we need to
58
87
  // ensure the style value being checked is from the `user` origin.
59
88
  const [userBorderStyles] = (0, _hooks.useStyle)('border', name, 'user');
60
-
61
- const createHasValueCallback = feature => () => !!(userBorderStyles !== null && userBorderStyles !== void 0 && userBorderStyles[feature]);
62
-
63
- const createResetCallback = setStyle => () => setStyle(undefined);
64
-
65
- const handleOnChange = setStyle => value => {
66
- setStyle(value || undefined);
67
- };
68
-
69
- const units = (0, _components.__experimentalUseCustomUnits)({
70
- availableUnits: (0, _hooks.useSetting)('spacing.units')[0] || ['px', 'em', 'rem']
71
- }); // Border width.
72
-
73
- const showBorderWidth = useHasBorderWidthControl(name);
74
- const [borderWidthValue, setBorderWidth] = (0, _hooks.useStyle)('border.width', name); // Border style.
75
-
76
- const showBorderStyle = useHasBorderStyleControl(name);
77
- const [borderStyle, setBorderStyle] = (0, _hooks.useStyle)('border.style', name); // When we set a border color or width ensure we have a style so the user
78
- // can see a visible border.
79
-
80
- const handleOnChangeWithStyle = setStyle => value => {
81
- if (!!value && !borderStyle) {
82
- setBorderStyle('solid');
83
- }
84
-
85
- setStyle(value || undefined);
86
- }; // Border color.
87
-
88
-
89
+ const [border, setBorder] = (0, _hooks.useStyle)('border', name);
90
+ const colors = (0, _hooks.useColorsPerOrigin)(name);
89
91
  const showBorderColor = useHasBorderColorControl(name);
90
- const [borderColor, setBorderColor] = (0, _hooks.useStyle)('border.color', name);
91
- const disableCustomColors = !(0, _hooks.useSetting)('color.custom')[0];
92
- const disableCustomGradients = !(0, _hooks.useSetting)('color.customGradient')[0];
93
- const borderColorSettings = [{
94
- label: (0, _i18n.__)('Color'),
95
- colors: (0, _hooks.useColorsPerOrigin)(name),
96
- colorValue: borderColor,
97
- onColorChange: handleOnChangeWithStyle(setBorderColor),
98
- clearable: false
99
- }]; // Border radius.
92
+ const showBorderStyle = useHasBorderStyleControl(name);
93
+ const showBorderWidth = useHasBorderWidthControl(name); // Border radius.
100
94
 
101
95
  const showBorderRadius = useHasBorderRadiusControl(name);
102
96
  const [borderRadiusValues, setBorderRadius] = (0, _hooks.useStyle)('border.radius', name);
@@ -111,57 +105,84 @@ function BorderPanel(_ref) {
111
105
  return !!borderValues;
112
106
  };
113
107
 
114
- const resetAll = () => {
115
- setBorderColor(undefined);
116
- setBorderRadius(undefined);
117
- setBorderStyle(undefined);
118
- setBorderWidth(undefined);
108
+ const resetBorder = () => {
109
+ if (hasBorderRadius()) {
110
+ return setBorder({
111
+ radius: userBorderStyles.radius
112
+ });
113
+ }
114
+
115
+ setBorder(undefined);
119
116
  };
120
117
 
118
+ const resetAll = (0, _element.useCallback)(() => setBorder(undefined), [setBorder]);
119
+ const onBorderChange = (0, _element.useCallback)(newBorder => {
120
+ // Ensure we have a visible border style when a border width or
121
+ // color is being selected.
122
+ const newBorderWithStyle = applyAllFallbackStyles(newBorder); // As we can't conditionally generate styles based on if other
123
+ // style properties have been set we need to force split border
124
+ // definitions for user set border styles. Border radius is derived
125
+ // from the same property i.e. `border.radius` if it is a string
126
+ // that is used. The longhand border radii styles are only generated
127
+ // if that property is an object.
128
+ //
129
+ // For borders (color, style, and width) those are all properties on
130
+ // the `border` style property. This means if the theme.json defined
131
+ // split borders and the user condenses them into a flat border or
132
+ // vice-versa we'd get both sets of styles which would conflict.
133
+
134
+ const updatedBorder = !(0, _components.__experimentalHasSplitBorders)(newBorderWithStyle) ? {
135
+ top: newBorderWithStyle,
136
+ right: newBorderWithStyle,
137
+ bottom: newBorderWithStyle,
138
+ left: newBorderWithStyle
139
+ } : {
140
+ color: null,
141
+ style: null,
142
+ width: null,
143
+ ...newBorderWithStyle
144
+ }; // As radius is maintained separately to color, style, and width
145
+ // maintain its value. Undefined values here will be cleaned when
146
+ // global styles are saved.
147
+
148
+ setBorder({
149
+ radius: border === null || border === void 0 ? void 0 : border.radius,
150
+ ...updatedBorder
151
+ });
152
+ }, [setBorder]);
121
153
  return (0, _element.createElement)(_components.__experimentalToolsPanel, {
122
154
  label: (0, _i18n.__)('Border'),
123
155
  resetAll: resetAll
124
- }, showBorderWidth && (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
125
- className: "single-column",
126
- hasValue: createHasValueCallback('width'),
127
- label: (0, _i18n.__)('Width'),
128
- onDeselect: createResetCallback(setBorderWidth),
129
- isShownByDefault: true
130
- }, (0, _element.createElement)(_components.__experimentalUnitControl, {
131
- value: borderWidthValue,
132
- label: (0, _i18n.__)('Width'),
133
- min: MIN_BORDER_WIDTH,
134
- onChange: handleOnChangeWithStyle(setBorderWidth),
135
- units: units
136
- })), showBorderStyle && (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
137
- className: "single-column",
138
- hasValue: createHasValueCallback('style'),
139
- label: (0, _i18n.__)('Style'),
140
- onDeselect: createResetCallback(setBorderStyle),
141
- isShownByDefault: true
142
- }, (0, _element.createElement)(_blockEditor.__experimentalBorderStyleControl, {
143
- value: borderStyle,
144
- onChange: handleOnChange(setBorderStyle)
145
- })), showBorderColor && (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
146
- hasValue: createHasValueCallback('color'),
147
- label: (0, _i18n.__)('Color'),
148
- onDeselect: createResetCallback(setBorderColor),
156
+ }, (showBorderWidth || showBorderColor) && (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
157
+ hasValue: () => (0, _components.__experimentalIsDefinedBorder)(userBorderStyles),
158
+ label: (0, _i18n.__)('Border'),
159
+ onDeselect: () => resetBorder(),
149
160
  isShownByDefault: true
150
- }, (0, _element.createElement)(_blockEditor.__experimentalColorGradientSettingsDropdown, {
151
- __experimentalHasMultipleOrigins: true,
152
- __experimentalIsRenderedInSidebar: true,
153
- disableCustomColors: disableCustomColors,
154
- disableCustomGradients: disableCustomGradients,
161
+ }, (0, _element.createElement)(_components.__experimentalBorderBoxControl, {
162
+ colors: colors,
155
163
  enableAlpha: true,
156
- settings: borderColorSettings
164
+ onChange: onBorderChange,
165
+ showStyle: showBorderStyle,
166
+ value: border,
167
+ popoverClassNames: {
168
+ linked: 'edit-site-global-styles-sidebar__border-box-control__popover',
169
+ top: 'edit-site-global-styles-sidebar__border-box-control__popover-top',
170
+ right: 'edit-site-global-styles-sidebar__border-box-control__popover-right',
171
+ bottom: 'edit-site-global-styles-sidebar__border-box-control__popover-bottom',
172
+ left: 'edit-site-global-styles-sidebar__border-box-control__popover-left'
173
+ },
174
+ __experimentalHasMultipleOrigins: true,
175
+ __experimentalIsRenderedInSidebar: true
157
176
  })), showBorderRadius && (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
158
177
  hasValue: hasBorderRadius,
159
178
  label: (0, _i18n.__)('Radius'),
160
- onDeselect: createResetCallback(setBorderRadius),
179
+ onDeselect: () => setBorderRadius(undefined),
161
180
  isShownByDefault: true
162
181
  }, (0, _element.createElement)(_blockEditor.__experimentalBorderRadiusControl, {
163
182
  values: borderRadiusValues,
164
- onChange: handleOnChange(setBorderRadius)
183
+ onChange: value => {
184
+ setBorderRadius(value || undefined);
185
+ }
165
186
  })));
166
187
  }
167
188
  //# sourceMappingURL=border-panel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/border-panel.js"],"names":["MIN_BORDER_WIDTH","useHasBorderPanel","name","controls","useHasBorderColorControl","useHasBorderRadiusControl","useHasBorderStyleControl","useHasBorderWidthControl","some","Boolean","supports","includes","BorderPanel","userBorderStyles","createHasValueCallback","feature","createResetCallback","setStyle","undefined","handleOnChange","value","units","availableUnits","showBorderWidth","borderWidthValue","setBorderWidth","showBorderStyle","borderStyle","setBorderStyle","handleOnChangeWithStyle","showBorderColor","borderColor","setBorderColor","disableCustomColors","disableCustomGradients","borderColorSettings","label","colors","colorValue","onColorChange","clearable","showBorderRadius","borderRadiusValues","setBorderRadius","hasBorderRadius","borderValues","radius","Object","entries","resetAll"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AAMA;;AAKA;;AAnBA;AACA;AACA;;AAcA;AACA;AACA;AAQA,MAAMA,gBAAgB,GAAG,CAAzB;;AAEO,SAASC,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMC,QAAQ,GAAG,CAChBC,wBAAwB,CAAEF,IAAF,CADR,EAEhBG,yBAAyB,CAAEH,IAAF,CAFT,EAGhBI,wBAAwB,CAAEJ,IAAF,CAHR,EAIhBK,wBAAwB,CAAEL,IAAF,CAJR,CAAjB;AAOA,SAAOC,QAAQ,CAACK,IAAT,CAAeC,OAAf,CAAP;AACA;;AAED,SAASL,wBAAT,CAAmCF,IAAnC,EAA0C;AACzC,QAAMQ,QAAQ,GAAG,2CAAgCR,IAAhC,CAAjB;AACA,SACC,uBAAY,cAAZ,EAA4BA,IAA5B,EAAoC,CAApC,KACAQ,QAAQ,CAACC,QAAT,CAAmB,aAAnB,CAFD;AAIA;;AAED,SAASN,yBAAT,CAAoCH,IAApC,EAA2C;AAC1C,QAAMQ,QAAQ,GAAG,2CAAgCR,IAAhC,CAAjB;AACA,SACC,uBAAY,eAAZ,EAA6BA,IAA7B,EAAqC,CAArC,KACAQ,QAAQ,CAACC,QAAT,CAAmB,cAAnB,CAFD;AAIA;;AAED,SAASL,wBAAT,CAAmCJ,IAAnC,EAA0C;AACzC,QAAMQ,QAAQ,GAAG,2CAAgCR,IAAhC,CAAjB;AACA,SACC,uBAAY,cAAZ,EAA4BA,IAA5B,EAAoC,CAApC,KACAQ,QAAQ,CAACC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EC,IAAA,KAAK,EAAG,cAAI,OAAJ,CAFT;AAGC,IAAA,UAAU,EAAGE,mBAAmB,CAAEgB,cAAF,CAHjC;AAIC,IAAA,gBAAgB,EAAG;AAJpB,KAMC,4BAAC,wDAAD;AACC,IAAA,gCAAgC,MADjC;AAEC,IAAA,iCAAiC,MAFlC;AAGC,IAAA,mBAAmB,EAAGC,mBAHvB;AAIC,IAAA,sBAAsB,EAAGC,sBAJ1B;AAKC,IAAA,WAAW,MALZ;AAMC,IAAA,QAAQ,EAAGC;AANZ,IAND,CAjCF,EAiDGM,gBAAgB,IACjB,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAGG,eADZ;AAEC,IAAA,KAAK,EAAG,cAAI,QAAJ,CAFT;AAGC,IAAA,UAAU,EAAG5B,mBAAmB,CAAE2B,eAAF,CAHjC;AAIC,IAAA,gBAAgB,EAAG;AAJpB,KAMC,4BAAC,8CAAD;AACC,IAAA,MAAM,EAAGD,kBADV;AAEC,IAAA,QAAQ,EAAGvB,cAAc,CAAEwB,eAAF;AAF1B,IAND,CAlDF,CADD;AAiEA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalBorderRadiusControl as BorderRadiusControl,\n\t__experimentalBorderStyleControl as BorderStyleControl,\n\t__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,\n} from '@wordpress/block-editor';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalUseCustomUnits as useCustomUnits,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetSupportedGlobalStylesPanels,\n\tuseColorsPerOrigin,\n\tuseSetting,\n\tuseStyle,\n} from './hooks';\n\nconst MIN_BORDER_WIDTH = 0;\n\nexport function useHasBorderPanel( name ) {\n\tconst controls = [\n\t\tuseHasBorderColorControl( name ),\n\t\tuseHasBorderRadiusControl( name ),\n\t\tuseHasBorderStyleControl( name ),\n\t\tuseHasBorderWidthControl( name ),\n\t];\n\n\treturn controls.some( Boolean );\n}\n\nfunction useHasBorderColorControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.color', name )[ 0 ] &&\n\t\tsupports.includes( 'borderColor' )\n\t);\n}\n\nfunction useHasBorderRadiusControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.radius', name )[ 0 ] &&\n\t\tsupports.includes( 'borderRadius' )\n\t);\n}\n\nfunction useHasBorderStyleControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.style', name )[ 0 ] &&\n\t\tsupports.includes( 'borderStyle' )\n\t);\n}\n\nfunction useHasBorderWidthControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.width', name )[ 0 ] &&\n\t\tsupports.includes( 'borderWidth' )\n\t);\n}\n\nexport default function BorderPanel( { name } ) {\n\t// To better reflect if the user has customized a value we need to\n\t// ensure the style value being checked is from the `user` origin.\n\tconst [ userBorderStyles ] = useStyle( 'border', name, 'user' );\n\tconst createHasValueCallback = ( feature ) => () =>\n\t\t!! userBorderStyles?.[ feature ];\n\n\tconst createResetCallback = ( setStyle ) => () => setStyle( undefined );\n\n\tconst handleOnChange = ( setStyle ) => ( value ) => {\n\t\tsetStyle( value || undefined );\n\t};\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' )[ 0 ] || [\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t],\n\t} );\n\n\t// Border width.\n\tconst showBorderWidth = useHasBorderWidthControl( name );\n\tconst [ borderWidthValue, setBorderWidth ] = useStyle(\n\t\t'border.width',\n\t\tname\n\t);\n\n\t// Border style.\n\tconst showBorderStyle = useHasBorderStyleControl( name );\n\tconst [ borderStyle, setBorderStyle ] = useStyle( 'border.style', name );\n\n\t// When we set a border color or width ensure we have a style so the user\n\t// can see a visible border.\n\tconst handleOnChangeWithStyle = ( setStyle ) => ( value ) => {\n\t\tif ( !! value && ! borderStyle ) {\n\t\t\tsetBorderStyle( 'solid' );\n\t\t}\n\n\t\tsetStyle( value || undefined );\n\t};\n\n\t// Border color.\n\tconst showBorderColor = useHasBorderColorControl( name );\n\tconst [ borderColor, setBorderColor ] = useStyle( 'border.color', name );\n\tconst disableCustomColors = ! useSetting( 'color.custom' )[ 0 ];\n\tconst disableCustomGradients = ! useSetting( 'color.customGradient' )[ 0 ];\n\n\tconst borderColorSettings = [\n\t\t{\n\t\t\tlabel: __( 'Color' ),\n\t\t\tcolors: useColorsPerOrigin( name ),\n\t\t\tcolorValue: borderColor,\n\t\t\tonColorChange: handleOnChangeWithStyle( setBorderColor ),\n\t\t\tclearable: false,\n\t\t},\n\t];\n\n\t// Border radius.\n\tconst showBorderRadius = useHasBorderRadiusControl( name );\n\tconst [ borderRadiusValues, setBorderRadius ] = useStyle(\n\t\t'border.radius',\n\t\tname\n\t);\n\tconst hasBorderRadius = () => {\n\t\tconst borderValues = userBorderStyles?.radius;\n\t\tif ( typeof borderValues === 'object' ) {\n\t\t\treturn Object.entries( borderValues ).some( Boolean );\n\t\t}\n\t\treturn !! borderValues;\n\t};\n\n\tconst resetAll = () => {\n\t\tsetBorderColor( undefined );\n\t\tsetBorderRadius( undefined );\n\t\tsetBorderStyle( undefined );\n\t\tsetBorderWidth( undefined );\n\t};\n\n\treturn (\n\t\t<ToolsPanel label={ __( 'Border' ) } resetAll={ resetAll }>\n\t\t\t{ showBorderWidth && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tclassName=\"single-column\"\n\t\t\t\t\thasValue={ createHasValueCallback( 'width' ) }\n\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\tonDeselect={ createResetCallback( setBorderWidth ) }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<UnitControl\n\t\t\t\t\t\tvalue={ borderWidthValue }\n\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\tmin={ MIN_BORDER_WIDTH }\n\t\t\t\t\t\tonChange={ handleOnChangeWithStyle( setBorderWidth ) }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ showBorderStyle && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tclassName=\"single-column\"\n\t\t\t\t\thasValue={ createHasValueCallback( 'style' ) }\n\t\t\t\t\tlabel={ __( 'Style' ) }\n\t\t\t\t\tonDeselect={ createResetCallback( setBorderStyle ) }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<BorderStyleControl\n\t\t\t\t\t\tvalue={ borderStyle }\n\t\t\t\t\t\tonChange={ handleOnChange( setBorderStyle ) }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ showBorderColor && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ createHasValueCallback( 'color' ) }\n\t\t\t\t\tlabel={ __( 'Color' ) }\n\t\t\t\t\tonDeselect={ createResetCallback( setBorderColor ) }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<ColorGradientSettingsDropdown\n\t\t\t\t\t\t__experimentalHasMultipleOrigins\n\t\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t\t\tdisableCustomColors={ disableCustomColors }\n\t\t\t\t\t\tdisableCustomGradients={ disableCustomGradients }\n\t\t\t\t\t\tenableAlpha\n\t\t\t\t\t\tsettings={ borderColorSettings }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ showBorderRadius && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ hasBorderRadius }\n\t\t\t\t\tlabel={ __( 'Radius' ) }\n\t\t\t\t\tonDeselect={ createResetCallback( setBorderRadius ) }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<BorderRadiusControl\n\t\t\t\t\t\tvalues={ borderRadiusValues }\n\t\t\t\t\t\tonChange={ handleOnChange( setBorderRadius ) }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t</ToolsPanel>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/border-panel.js"],"names":["useHasBorderPanel","name","controls","useHasBorderColorControl","useHasBorderRadiusControl","useHasBorderStyleControl","useHasBorderWidthControl","some","Boolean","supports","includes","applyFallbackStyle","border","style","color","width","applyAllFallbackStyles","top","right","bottom","left","BorderPanel","userBorderStyles","setBorder","colors","showBorderColor","showBorderStyle","showBorderWidth","showBorderRadius","borderRadiusValues","setBorderRadius","hasBorderRadius","borderValues","radius","Object","entries","resetBorder","undefined","resetAll","onBorderChange","newBorder","newBorderWithStyle","updatedBorder","linked","value"],"mappings":";;;;;;;;AAWA;;AARA;;AACA;;AAQA;;AAKA;;AAjBA;AACA;AACA;;AAYA;AACA;AACA;AAQO,SAASA,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMC,QAAQ,GAAG,CAChBC,wBAAwB,CAAEF,IAAF,CADR,EAEhBG,yBAAyB,CAAEH,IAAF,CAFT,EAGhBI,wBAAwB,CAAEJ,IAAF,CAHR,EAIhBK,wBAAwB,CAAEL,IAAF,CAJR,CAAjB;AAOA,SAAOC,QAAQ,CAACK,IAAT,CAAeC,OAAf,CAAP;AACA;;AAED,SAASL,wBAAT,CAAmCF,IAAnC,EAA0C;AACzC,QAAMQ,QAAQ,GAAG,2CAAgCR,IAAhC,CAAjB;AACA,SACC,uBAAY,cAAZ,EAA4BA,IAA5B,EAAoC,CAApC,KACAQ,QAAQ,CAACC,QAAT,CAAmB,aAAnB,CAFD;AAIA;;AAED,SAASN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AA,MAAM,EAAGZ,MADV;AAEC,IAAA,WAAW,EAAG,IAFf;AAGC,IAAA,QAAQ,EAAGe,cAHZ;AAIC,IAAA,SAAS,EAAGb,eAJb;AAKC,IAAA,KAAK,EAAGd,MALT;AAMC,IAAA,iBAAiB,EAAG;AACnB+B,MAAAA,MAAM,EACL,8DAFkB;AAGnB1B,MAAAA,GAAG,EACF,kEAJkB;AAKnBC,MAAAA,KAAK,EACJ,oEANkB;AAOnBC,MAAAA,MAAM,EACL,qEARkB;AASnBC,MAAAA,IAAI,EACH;AAVkB,KANrB;AAkBC,IAAA,gCAAgC,EAAG,IAlBpC;AAmBC,IAAA,iCAAiC,EAAG;AAnBrC,IAND,CAFF,EA+BGQ,gBAAgB,IACjB,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAGG,eADZ;AAEC,IAAA,KAAK,EAAG,cAAI,QAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMD,eAAe,CAAEO,SAAF,CAHnC;AAIC,IAAA,gBAAgB,EAAG;AAJpB,KAMC,4BAAC,8CAAD;AACC,IAAA,MAAM,EAAGR,kBADV;AAEC,IAAA,QAAQ,EAAKe,KAAF,IAAa;AACvBd,MAAAA,eAAe,CAAEc,KAAK,IAAIP,SAAX,CAAf;AACA;AAJF,IAND,CAhCF,CADD;AAiDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalBorderRadiusControl as BorderRadiusControl } from '@wordpress/block-editor';\nimport {\n\t__experimentalBorderBoxControl as BorderBoxControl,\n\t__experimentalHasSplitBorders as hasSplitBorders,\n\t__experimentalIsDefinedBorder as isDefinedBorder,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetSupportedGlobalStylesPanels,\n\tuseColorsPerOrigin,\n\tuseSetting,\n\tuseStyle,\n} from './hooks';\n\nexport function useHasBorderPanel( name ) {\n\tconst controls = [\n\t\tuseHasBorderColorControl( name ),\n\t\tuseHasBorderRadiusControl( name ),\n\t\tuseHasBorderStyleControl( name ),\n\t\tuseHasBorderWidthControl( name ),\n\t];\n\n\treturn controls.some( Boolean );\n}\n\nfunction useHasBorderColorControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.color', name )[ 0 ] &&\n\t\tsupports.includes( 'borderColor' )\n\t);\n}\n\nfunction useHasBorderRadiusControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.radius', name )[ 0 ] &&\n\t\tsupports.includes( 'borderRadius' )\n\t);\n}\n\nfunction useHasBorderStyleControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.style', name )[ 0 ] &&\n\t\tsupports.includes( 'borderStyle' )\n\t);\n}\n\nfunction useHasBorderWidthControl( name ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\treturn (\n\t\tuseSetting( 'border.width', name )[ 0 ] &&\n\t\tsupports.includes( 'borderWidth' )\n\t);\n}\n\nfunction applyFallbackStyle( border ) {\n\tif ( ! border ) {\n\t\treturn border;\n\t}\n\n\tif ( ! border.style && ( border.color || border.width ) ) {\n\t\treturn { ...border, style: 'solid' };\n\t}\n\n\treturn border;\n}\n\nfunction applyAllFallbackStyles( border ) {\n\tif ( ! border ) {\n\t\treturn border;\n\t}\n\n\tif ( hasSplitBorders( border ) ) {\n\t\treturn {\n\t\t\ttop: applyFallbackStyle( border.top ),\n\t\t\tright: applyFallbackStyle( border.right ),\n\t\t\tbottom: applyFallbackStyle( border.bottom ),\n\t\t\tleft: applyFallbackStyle( border.left ),\n\t\t};\n\t}\n\n\treturn applyFallbackStyle( border );\n}\n\nexport default function BorderPanel( { name } ) {\n\t// To better reflect if the user has customized a value we need to\n\t// ensure the style value being checked is from the `user` origin.\n\tconst [ userBorderStyles ] = useStyle( 'border', name, 'user' );\n\tconst [ border, setBorder ] = useStyle( 'border', name );\n\tconst colors = useColorsPerOrigin( name );\n\n\tconst showBorderColor = useHasBorderColorControl( name );\n\tconst showBorderStyle = useHasBorderStyleControl( name );\n\tconst showBorderWidth = useHasBorderWidthControl( name );\n\n\t// Border radius.\n\tconst showBorderRadius = useHasBorderRadiusControl( name );\n\tconst [ borderRadiusValues, setBorderRadius ] = useStyle(\n\t\t'border.radius',\n\t\tname\n\t);\n\tconst hasBorderRadius = () => {\n\t\tconst borderValues = userBorderStyles?.radius;\n\t\tif ( typeof borderValues === 'object' ) {\n\t\t\treturn Object.entries( borderValues ).some( Boolean );\n\t\t}\n\t\treturn !! borderValues;\n\t};\n\n\tconst resetBorder = () => {\n\t\tif ( hasBorderRadius() ) {\n\t\t\treturn setBorder( { radius: userBorderStyles.radius } );\n\t\t}\n\n\t\tsetBorder( undefined );\n\t};\n\n\tconst resetAll = useCallback( () => setBorder( undefined ), [ setBorder ] );\n\tconst onBorderChange = useCallback(\n\t\t( newBorder ) => {\n\t\t\t// Ensure we have a visible border style when a border width or\n\t\t\t// color is being selected.\n\t\t\tconst newBorderWithStyle = applyAllFallbackStyles( newBorder );\n\n\t\t\t// As we can't conditionally generate styles based on if other\n\t\t\t// style properties have been set we need to force split border\n\t\t\t// definitions for user set border styles. Border radius is derived\n\t\t\t// from the same property i.e. `border.radius` if it is a string\n\t\t\t// that is used. The longhand border radii styles are only generated\n\t\t\t// if that property is an object.\n\t\t\t//\n\t\t\t// For borders (color, style, and width) those are all properties on\n\t\t\t// the `border` style property. This means if the theme.json defined\n\t\t\t// split borders and the user condenses them into a flat border or\n\t\t\t// vice-versa we'd get both sets of styles which would conflict.\n\t\t\tconst updatedBorder = ! hasSplitBorders( newBorderWithStyle )\n\t\t\t\t? {\n\t\t\t\t\t\ttop: newBorderWithStyle,\n\t\t\t\t\t\tright: newBorderWithStyle,\n\t\t\t\t\t\tbottom: newBorderWithStyle,\n\t\t\t\t\t\tleft: newBorderWithStyle,\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tcolor: null,\n\t\t\t\t\t\tstyle: null,\n\t\t\t\t\t\twidth: null,\n\t\t\t\t\t\t...newBorderWithStyle,\n\t\t\t\t };\n\n\t\t\t// As radius is maintained separately to color, style, and width\n\t\t\t// maintain its value. Undefined values here will be cleaned when\n\t\t\t// global styles are saved.\n\t\t\tsetBorder( { radius: border?.radius, ...updatedBorder } );\n\t\t},\n\t\t[ setBorder ]\n\t);\n\n\treturn (\n\t\t<ToolsPanel label={ __( 'Border' ) } resetAll={ resetAll }>\n\t\t\t{ ( showBorderWidth || showBorderColor ) && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ () => isDefinedBorder( userBorderStyles ) }\n\t\t\t\t\tlabel={ __( 'Border' ) }\n\t\t\t\t\tonDeselect={ () => resetBorder() }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<BorderBoxControl\n\t\t\t\t\t\tcolors={ colors }\n\t\t\t\t\t\tenableAlpha={ true }\n\t\t\t\t\t\tonChange={ onBorderChange }\n\t\t\t\t\t\tshowStyle={ showBorderStyle }\n\t\t\t\t\t\tvalue={ border }\n\t\t\t\t\t\tpopoverClassNames={ {\n\t\t\t\t\t\t\tlinked:\n\t\t\t\t\t\t\t\t'edit-site-global-styles-sidebar__border-box-control__popover',\n\t\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\t\t'edit-site-global-styles-sidebar__border-box-control__popover-top',\n\t\t\t\t\t\t\tright:\n\t\t\t\t\t\t\t\t'edit-site-global-styles-sidebar__border-box-control__popover-right',\n\t\t\t\t\t\t\tbottom:\n\t\t\t\t\t\t\t\t'edit-site-global-styles-sidebar__border-box-control__popover-bottom',\n\t\t\t\t\t\t\tleft:\n\t\t\t\t\t\t\t\t'edit-site-global-styles-sidebar__border-box-control__popover-left',\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t__experimentalHasMultipleOrigins={ true }\n\t\t\t\t\t\t__experimentalIsRenderedInSidebar={ true }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ showBorderRadius && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ hasBorderRadius }\n\t\t\t\t\tlabel={ __( 'Radius' ) }\n\t\t\t\t\tonDeselect={ () => setBorderRadius( undefined ) }\n\t\t\t\t\tisShownByDefault={ true }\n\t\t\t\t>\n\t\t\t\t\t<BorderRadiusControl\n\t\t\t\t\t\tvalues={ borderRadiusValues }\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tsetBorderRadius( value || undefined );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t</ToolsPanel>\n\t);\n}\n"]}
@@ -4,20 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.toStyles = exports.toCustomProperties = exports.getNodesWithStyles = exports.getNodesWithSettings = void 0;
7
+ exports.toSvgFilters = toSvgFilters;
7
8
  exports.useGlobalStylesOutput = useGlobalStylesOutput;
8
9
 
10
+ var _element = require("@wordpress/element");
11
+
9
12
  var _lodash = require("lodash");
10
13
 
11
14
  var _blocks = require("@wordpress/blocks");
12
15
 
13
- var _element = require("@wordpress/element");
14
-
15
16
  var _styleEngine = require("@wordpress/style-engine");
16
17
 
18
+ var _blockEditor = require("@wordpress/block-editor");
19
+
17
20
  var _utils = require("./utils");
18
21
 
19
22
  var _context = require("./context");
20
23
 
24
+ var _hooks = require("./hooks");
25
+
21
26
  /**
22
27
  * External dependencies
23
28
  */
@@ -26,10 +31,6 @@ var _context = require("./context");
26
31
  * WordPress dependencies
27
32
  */
28
33
 
29
- /**
30
- * Internal dependencies
31
- */
32
-
33
34
  /**
34
35
  * Internal dependencies
35
36
  */
@@ -60,13 +61,18 @@ function getPresetsDeclarations() {
60
61
  let {
61
62
  path,
62
63
  valueKey,
64
+ valueFunc,
63
65
  cssVarInfix
64
66
  } = _ref;
65
67
  const presetByOrigin = (0, _lodash.get)(blockPresets, path, []);
66
68
  ['default', 'theme', 'custom'].forEach(origin => {
67
69
  if (presetByOrigin[origin]) {
68
70
  presetByOrigin[origin].forEach(value => {
69
- declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${value[valueKey]}`);
71
+ if (valueKey) {
72
+ declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${value[valueKey]}`);
73
+ } else if (valueFunc && typeof valueFunc === 'function') {
74
+ declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${valueFunc(value)}`);
75
+ }
70
76
  });
71
77
  }
72
78
  });
@@ -120,6 +126,18 @@ function getPresetsClasses(blockSelector) {
120
126
  }, '');
121
127
  }
122
128
 
129
+ function getPresetsSvgFilters() {
130
+ let blockPresets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
131
+ return _utils.PRESET_METADATA.filter( // Duotone are the only type of filters for now.
132
+ metadata => metadata.path.at(-1) === 'duotone').flatMap(metadata => {
133
+ const presetByOrigin = (0, _lodash.get)(blockPresets, metadata.path, {});
134
+ return ['default', 'theme'].filter(origin => presetByOrigin[origin]).flatMap(origin => presetByOrigin[origin].map(preset => (0, _element.createElement)(_blockEditor.__unstablePresetDuotoneFilter, {
135
+ preset: preset,
136
+ key: preset.slug
137
+ })));
138
+ });
139
+ }
140
+
123
141
  function flattenTree() {
124
142
  let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
125
143
  let prefix = arguments.length > 1 ? arguments[1] : undefined;
@@ -208,7 +226,7 @@ const getNodesWithStyles = (tree, blockSelectors) => {
208
226
  return nodes;
209
227
  }
210
228
 
211
- const pickStyleKeys = treeToPickFrom => (0, _lodash.pickBy)(treeToPickFrom, (value, key) => ['border', 'color', 'spacing', 'typography'].includes(key)); // Top-level.
229
+ const pickStyleKeys = treeToPickFrom => (0, _lodash.pickBy)(treeToPickFrom, (value, key) => ['border', 'color', 'spacing', 'typography', 'filter'].includes(key)); // Top-level.
212
230
 
213
231
 
214
232
  const styles = pickStyleKeys(tree.styles);
@@ -237,7 +255,8 @@ const getNodesWithStyles = (tree, blockSelectors) => {
237
255
  if (!!blockStyles && !!(blockSelectors !== null && blockSelectors !== void 0 && (_blockSelectors$block = blockSelectors[blockName]) !== null && _blockSelectors$block !== void 0 && _blockSelectors$block.selector)) {
238
256
  nodes.push({
239
257
  styles: blockStyles,
240
- selector: blockSelectors[blockName].selector
258
+ selector: blockSelectors[blockName].selector,
259
+ duotoneSelector: blockSelectors[blockName].duotoneSelector
241
260
  });
242
261
  }
243
262
 
@@ -336,15 +355,44 @@ const toCustomProperties = (tree, blockSelectors) => {
336
355
 
337
356
  exports.toCustomProperties = toCustomProperties;
338
357
 
339
- const toStyles = (tree, blockSelectors) => {
358
+ const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
340
359
  const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
341
360
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
342
- let ruleset = '.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }';
361
+ /*
362
+ * Reset default browser margin on the root body element.
363
+ * This is set on the root selector **before** generating the ruleset
364
+ * from the `theme.json`. This is to ensure that if the `theme.json` declares
365
+ * `margin` in its `spacing` declaration for the `body` element then these
366
+ * user-generated values take precedence in the CSS cascade.
367
+ * @link https://github.com/WordPress/gutenberg/issues/36147.
368
+ */
369
+
370
+ let ruleset = 'body {margin: 0;}';
343
371
  nodesWithStyles.forEach(_ref8 => {
344
372
  let {
345
373
  selector,
374
+ duotoneSelector,
346
375
  styles
347
376
  } = _ref8;
377
+ const duotoneStyles = {};
378
+
379
+ if (styles !== null && styles !== void 0 && styles.filter) {
380
+ duotoneStyles.filter = styles.filter;
381
+ delete styles.filter;
382
+ } // Process duotone styles (they use color.__experimentalDuotone selector).
383
+
384
+
385
+ if (duotoneSelector) {
386
+ const duotoneDeclarations = getStylesDeclarations(duotoneStyles);
387
+
388
+ if (duotoneDeclarations.length === 0) {
389
+ return;
390
+ }
391
+
392
+ ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
393
+ } // Process the remaning block styles (they use either normal block class or __experimentalSelector).
394
+
395
+
348
396
  const declarations = getStylesDeclarations(styles);
349
397
 
350
398
  if (declarations.length === 0) {
@@ -353,6 +401,17 @@ const toStyles = (tree, blockSelectors) => {
353
401
 
354
402
  ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
355
403
  });
404
+ /* Add alignment / layout styles */
405
+
406
+ ruleset = ruleset + '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
407
+ ruleset = ruleset + '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
408
+ ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
409
+
410
+ if (hasBlockGapSupport) {
411
+ ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
412
+ ruleset = ruleset + '.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }';
413
+ }
414
+
356
415
  nodesWithSettings.forEach(_ref9 => {
357
416
  let {
358
417
  selector,
@@ -375,16 +434,28 @@ const toStyles = (tree, blockSelectors) => {
375
434
 
376
435
  exports.toStyles = toStyles;
377
436
 
437
+ function toSvgFilters(tree, blockSelectors) {
438
+ const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
439
+ return nodesWithSettings.flatMap(_ref10 => {
440
+ let {
441
+ presets
442
+ } = _ref10;
443
+ return getPresetsSvgFilters(presets);
444
+ });
445
+ }
446
+
378
447
  const getBlockSelectors = blockTypes => {
379
448
  const result = {};
380
449
  blockTypes.forEach(blockType => {
381
- var _blockType$supports$_, _blockType$supports;
450
+ var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$;
382
451
 
383
452
  const name = blockType.name;
384
453
  const selector = (_blockType$supports$_ = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports = blockType.supports) === null || _blockType$supports === void 0 ? void 0 : _blockType$supports.__experimentalSelector) !== null && _blockType$supports$_ !== void 0 ? _blockType$supports$_ : '.wp-block-' + name.replace('core/', '').replace('/', '-');
454
+ const duotoneSelector = (_blockType$supports$c = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports2 = blockType.supports) === null || _blockType$supports2 === void 0 ? void 0 : (_blockType$supports2$ = _blockType$supports2.color) === null || _blockType$supports2$ === void 0 ? void 0 : _blockType$supports2$.__experimentalDuotone) !== null && _blockType$supports$c !== void 0 ? _blockType$supports$c : null;
385
455
  result[name] = {
386
456
  name,
387
- selector
457
+ selector,
458
+ duotoneSelector
388
459
  };
389
460
  });
390
461
  return result;
@@ -393,9 +464,12 @@ const getBlockSelectors = blockTypes => {
393
464
  function useGlobalStylesOutput() {
394
465
  const [stylesheets, setStylesheets] = (0, _element.useState)([]);
395
466
  const [settings, setSettings] = (0, _element.useState)({});
467
+ const [svgFilters, setSvgFilters] = (0, _element.useState)({});
396
468
  const {
397
469
  merged: mergedConfig
398
470
  } = (0, _element.useContext)(_context.GlobalStylesContext);
471
+ const [blockGap] = (0, _hooks.useSetting)('spacing.blockGap');
472
+ const hasBlockGapSupport = blockGap !== null;
399
473
  (0, _element.useEffect)(() => {
400
474
  if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
401
475
  return;
@@ -403,7 +477,8 @@ function useGlobalStylesOutput() {
403
477
 
404
478
  const blockSelectors = getBlockSelectors((0, _blocks.getBlockTypes)());
405
479
  const customProperties = toCustomProperties(mergedConfig, blockSelectors);
406
- const globalStyles = toStyles(mergedConfig, blockSelectors);
480
+ const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport);
481
+ const filters = toSvgFilters(mergedConfig, blockSelectors);
407
482
  setStylesheets([{
408
483
  css: customProperties,
409
484
  isGlobalStyles: true
@@ -412,7 +487,8 @@ function useGlobalStylesOutput() {
412
487
  isGlobalStyles: true
413
488
  }]);
414
489
  setSettings(mergedConfig.settings);
490
+ setSvgFilters(filters);
415
491
  }, [mergedConfig]);
416
- return [stylesheets, settings];
492
+ return [stylesheets, settings, svgFilters, hasBlockGapSupport];
417
493
  }
418
494
  //# sourceMappingURL=use-global-styles-output.js.map