@wordpress/block-editor 8.1.0 → 8.1.2
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 +6 -0
- package/README.md +7 -5
- package/build/components/block-inspector/index.js +7 -0
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-preview/auto.js +3 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/colors-gradients/tools-panel-color-dropdown.js +89 -0
- package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
- package/build/components/contrast-checker/index.js +75 -64
- package/build/components/contrast-checker/index.js.map +1 -1
- package/build/components/index.js +9 -9
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +9 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/search-items.js +3 -1
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +3 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/line-height-control/index.native.js +3 -2
- package/build/components/line-height-control/index.native.js.map +1 -1
- package/build/components/link-control/link-preview.js +5 -2
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/list-view/block-contents.js +3 -1
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block-select-button.js +4 -2
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +2 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/media-placeholder/index.js +1 -11
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.native.js +13 -0
- package/build/components/media-replace-flow/index.native.js.map +1 -0
- package/build/components/rich-text/index.js +2 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +2 -1
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/use-paste-handler.js +14 -5
- package/build/components/rich-text/use-paste-handler.js.map +1 -1
- package/build/components/rich-text/utils.js +2 -1
- package/build/components/rich-text/utils.js.map +1 -1
- package/build/hooks/border-color.js +1 -1
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/color-panel.js +23 -17
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +176 -10
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/font-size.js +14 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/typography.native.js +2 -4
- package/build/hooks/typography.native.js.map +1 -1
- package/build/hooks/utils.js +55 -0
- package/build/hooks/utils.js.map +1 -1
- package/build-module/components/block-inspector/index.js +7 -0
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +3 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +75 -0
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
- package/build-module/components/contrast-checker/index.js +75 -65
- package/build-module/components/contrast-checker/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -0
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -1
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/line-height-control/index.native.js +3 -2
- package/build-module/components/line-height-control/index.native.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +5 -2
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +3 -1
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +4 -2
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +2 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +1 -10
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.native.js +4 -0
- package/build-module/components/media-replace-flow/index.native.js.map +1 -0
- package/build-module/components/rich-text/index.js +2 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +2 -1
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-paste-handler.js +14 -5
- package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
- package/build-module/components/rich-text/utils.js +2 -1
- package/build-module/components/rich-text/utils.js.map +1 -1
- package/build-module/hooks/border-color.js +1 -1
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/color-panel.js +22 -15
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +174 -11
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/font-size.js +12 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/typography.native.js +2 -4
- package/build-module/hooks/typography.native.js.map +1 -1
- package/build-module/hooks/utils.js +52 -1
- package/build-module/hooks/utils.js.map +1 -1
- package/build-style/style-rtl.css +71 -9
- package/build-style/style.css +71 -9
- package/package.json +26 -30
- package/src/components/block-inspector/index.js +9 -0
- package/src/components/block-preview/auto.js +3 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +0 -1
- package/src/components/colors-gradients/tools-panel-color-dropdown.js +85 -0
- package/src/components/contrast-checker/index.js +102 -87
- package/src/components/contrast-checker/test/index.js +176 -7
- package/src/components/index.js +1 -1
- package/src/components/index.native.js +1 -0
- package/src/components/inserter/search-items.js +3 -1
- package/src/components/inspector-controls/block-support-tools-panel.js +2 -0
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/line-height-control/index.native.js +2 -1
- package/src/components/link-control/link-preview.js +2 -1
- package/src/components/link-control/style.scss +3 -9
- package/src/components/list-view/block-contents.js +2 -0
- package/src/components/list-view/block-select-button.js +2 -0
- package/src/components/list-view/block.js +1 -0
- package/src/components/media-placeholder/index.js +1 -10
- package/src/components/media-replace-flow/index.native.js +3 -0
- package/src/components/rich-text/index.js +1 -0
- package/src/components/rich-text/index.native.js +1 -0
- package/src/components/rich-text/use-paste-handler.js +16 -3
- package/src/components/rich-text/utils.js +1 -0
- package/src/hooks/border-color.js +1 -1
- package/src/hooks/color-panel.js +24 -21
- package/src/hooks/color.js +177 -8
- package/src/hooks/color.scss +85 -0
- package/src/hooks/font-size.js +29 -1
- package/src/hooks/typography.native.js +1 -3
- package/src/hooks/utils.js +69 -1
- package/src/style.scss +1 -0
- package/build/components/preserve-scroll-in-reorder/index.js +0 -22
- package/build/components/preserve-scroll-in-reorder/index.js.map +0 -1
- package/build-module/components/preserve-scroll-in-reorder/index.js +0 -12
- package/build-module/components/preserve-scroll-in-reorder/index.js.map +0 -1
- package/src/components/preserve-scroll-in-reorder/index.js +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-paste-handler.js"],"names":["adjustLines","value","isMultiline","LINE_SEPARATOR","RegExp","usePasteHandler","props","propsRef","current","element","_onPaste","event","isSelected","disableFormats","onChange","formatTypes","tagName","onReplace","onSplit","onSplitMiddle","__unstableEmbedURLOnPaste","multilineTag","preserveWhiteSpace","pastePlainText","preventDefault","clipboardData","plainText","html","getData","error1","error2","removeWindowsFragments","removeCharsetMetaTag","window","console","log","transformed","reduce","accumlator","__unstablePasteRule","files","isInternal","pastedMultilineTag","undefined","pastedValue","multilineWrapperTags","activeFormats","text","length","content","HTML","mode","pastedBlocks","trim","valueToInsert","addEventListener","removeEventListener","startReg","endReg","replace","metaTag","startsWith","slice"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AAKA;;AACA;;AACA;;AArBA;AACA;AACA;;AAcA;AACA;AACA;;AAKA;;AAEA;AACA;AACA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X/C,YAAAA,KADW;AAEXmD,YAAAA,YAAY,EAAEH,OAFH;AAGXhC,YAAAA,SAHW;AAIXC,YAAAA,OAJW;AAKXC,YAAAA,aALW;AAMXE,YAAAA;AANW,WAAZ;AAQA;AACD;AACD;;AAEDZ,IAAAA,OAAO,CAAC8C,gBAAR,CAA0B,OAA1B,EAAmC7C,QAAnC;AACA,WAAO,MAAM;AACZD,MAAAA,OAAO,CAAC+C,mBAAR,CAA6B,OAA7B,EAAsC9C,QAAtC;AACA,KAFD;AAGA,GAzMM,EAyMJ,EAzMI,CAAP;AA0MA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASqB,sBAAT,CAAiCJ,IAAjC,EAAwC;AACvC,QAAM8B,QAAQ,GAAG,yBAAjB;AACA,QAAMC,MAAM,GAAG,uBAAf;AAEA,SAAO/B,IAAI,CAACgC,OAAL,CAAcF,QAAd,EAAwB,EAAxB,EAA6BE,OAA7B,CAAsCD,MAAtC,EAA8C,EAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAAS1B,oBAAT,CAA+BL,IAA/B,EAAsC;AACrC,QAAMiC,OAAO,GAAI,wBAAjB;;AAEA,MAAKjC,IAAI,CAACkC,UAAL,CAAiBD,OAAjB,CAAL,EAAkC;AACjC,WAAOjC,IAAI,CAACmC,KAAL,CAAYF,OAAO,CAACZ,MAApB,CAAP;AACA;;AAED,SAAOrB,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport { pasteHandler } from '@wordpress/blocks';\nimport {\n\tisEmpty,\n\tinsert,\n\tcreate,\n\treplace,\n\t__UNSTABLE_LINE_SEPARATOR as LINE_SEPARATOR,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { filePasteHandler } from './file-paste-handler';\nimport { addActiveFormats, isShortcode } from './utils';\nimport { splitValue } from './split-value';\n\n/** @typedef {import('@wordpress/rich-text').RichTextValue} RichTextValue */\n\n/**\n * Replaces line separators with line breaks if not multiline.\n * Replaces line breaks with line separators if multiline.\n *\n * @param {RichTextValue} value Value to adjust.\n * @param {boolean} isMultiline Whether to adjust to multiline or not.\n *\n * @return {RichTextValue} Adjusted value.\n */\nfunction adjustLines( value, isMultiline ) {\n\tif ( isMultiline ) {\n\t\treturn replace( value, /\\n+/g, LINE_SEPARATOR );\n\t}\n\n\treturn replace( value, new RegExp( LINE_SEPARATOR, 'g' ), '\\n' );\n}\n\nexport function usePasteHandler( props ) {\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction _onPaste( event ) {\n\t\t\tconst {\n\t\t\t\tisSelected,\n\t\t\t\tdisableFormats,\n\t\t\t\tonChange,\n\t\t\t\tvalue,\n\t\t\t\tformatTypes,\n\t\t\t\ttagName,\n\t\t\t\tonReplace,\n\t\t\t\tonSplit,\n\t\t\t\tonSplitMiddle,\n\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\tmultilineTag,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t\tpastePlainText,\n\t\t\t} = propsRef.current;\n\n\t\t\tif ( ! isSelected ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { clipboardData } = event;\n\n\t\t\tlet plainText = '';\n\t\t\tlet html = '';\n\n\t\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t\t// arguments first, then fallback to `Text` if they fail.\n\t\t\ttry {\n\t\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t\t} catch ( error1 ) {\n\t\t\t\ttry {\n\t\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t\t} catch ( error2 ) {\n\t\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t\t// behaviour.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove Windows-specific metadata appended within copied HTML text.\n\t\t\thtml = removeWindowsFragments( html );\n\n\t\t\t// Strip meta tag.\n\t\t\thtml = removeCharsetMetaTag( html );\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\t\tif ( disableFormats ) {\n\t\t\t\tonChange( insert( value, plainText ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstablePasteRule } ) => {\n\t\t\t\t\t// Only allow one transform.\n\t\t\t\t\tif ( __unstablePasteRule && accumlator === value ) {\n\t\t\t\t\t\taccumlator = __unstablePasteRule( value, {\n\t\t\t\t\t\t\thtml,\n\t\t\t\t\t\t\tplainText,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tvalue\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\tonChange( transformed );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst files = [ ...getFilesFromDataTransfer( clipboardData ) ];\n\t\t\tconst isInternal = clipboardData.getData( 'rich-text' ) === 'true';\n\n\t\t\t// If the data comes from a rich text instance, we can directly use it\n\t\t\t// without filtering the data. The filters are only meant for externally\n\t\t\t// pasted content and remove inline styles.\n\t\t\tif ( isInternal ) {\n\t\t\t\tconst pastedMultilineTag =\n\t\t\t\t\tclipboardData.getData( 'rich-text-multi-line-tag' ) ||\n\t\t\t\t\tundefined;\n\t\t\t\tlet pastedValue = create( {\n\t\t\t\t\thtml,\n\t\t\t\t\tmultilineTag: pastedMultilineTag,\n\t\t\t\t\tmultilineWrapperTags:\n\t\t\t\t\t\tpastedMultilineTag === 'li'\n\t\t\t\t\t\t\t? [ 'ul', 'ol' ]\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\t\t\t\tpastedValue = adjustLines( pastedValue, !! multilineTag );\n\t\t\t\taddActiveFormats( pastedValue, value.activeFormats );\n\t\t\t\tonChange( insert( value, pastedValue ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( pastePlainText ) {\n\t\t\t\tonChange( insert( value, create( { text: plainText } ) ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only process file if no HTML is present.\n\t\t\t// Note: a pasted file may have the URL as plain text.\n\t\t\tif ( files && files.length && ! html ) {\n\t\t\t\tconst content = pasteHandler( {\n\t\t\t\t\tHTML: filePasteHandler( files ),\n\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\ttagName,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\n\t\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\twindow.console.log( 'Received items:\\n\\n', files );\n\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = onReplace && onSplit ? 'AUTO' : 'INLINE';\n\n\t\t\t// Force the blocks mode when the user is pasting\n\t\t\t// on a new line & the content resembles a shortcode.\n\t\t\t// Otherwise it's going to be detected as inline\n\t\t\t// and the shortcode won't be replaced.\n\t\t\tif (\n\t\t\t\tmode === 'AUTO' &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisShortcode( plainText )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t__unstableEmbedURLOnPaste &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisURL( plainText.trim() )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tconst content = pasteHandler( {\n\t\t\t\tHTML: html,\n\t\t\t\tplainText,\n\t\t\t\tmode,\n\t\t\t\ttagName,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t} );\n\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tlet valueToInsert = create( { html: content } );\n\n\t\t\t\t// If the content should be multiline, we should process text\n\t\t\t\t// separated by a line break as separate lines.\n\t\t\t\tvalueToInsert = adjustLines( valueToInsert, !! multilineTag );\n\n\t\t\t\taddActiveFormats( valueToInsert, value.activeFormats );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else if ( content.length > 0 ) {\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content, content.length - 1, -1 );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'paste', _onPaste );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'paste', _onPaste );\n\t\t};\n\t}, [] );\n}\n\n/**\n * Normalizes a given string of HTML to remove the Windows specific \"Fragment\" comments\n * and any preceeding and trailing whitespace.\n *\n * @param {string} html the html to be normalized\n * @return {string} the normalized html\n */\nfunction removeWindowsFragments( html ) {\n\tconst startReg = /.*<!--StartFragment-->/s;\n\tconst endReg = /<!--EndFragment-->.*/s;\n\n\treturn html.replace( startReg, '' ).replace( endReg, '' );\n}\n\n/**\n * Removes the charset meta tag inserted by Chromium.\n * See:\n * - https://github.com/WordPress/gutenberg/issues/33585\n * - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4\n *\n * @param {string} html the html to be stripped of the meta tag.\n * @return {string} the cleaned html\n */\nfunction removeCharsetMetaTag( html ) {\n\tconst metaTag = `<meta charset='utf-8'>`;\n\n\tif ( html.startsWith( metaTag ) ) {\n\t\treturn html.slice( metaTag.length );\n\t}\n\n\treturn html;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-paste-handler.js"],"names":["adjustLines","value","isMultiline","LINE_SEPARATOR","RegExp","usePasteHandler","props","propsRef","current","element","_onPaste","event","isSelected","disableFormats","onChange","formatTypes","tagName","onReplace","onSplit","onSplitMiddle","__unstableEmbedURLOnPaste","multilineTag","preserveWhiteSpace","pastePlainText","preventDefault","clipboardData","plainText","html","getData","error1","error2","removeWindowsFragments","removeCharsetMetaTag","window","console","log","transformed","reduce","accumlator","__unstablePasteRule","files","isInternal","pastedMultilineTag","undefined","pastedValue","multilineWrapperTags","activeFormats","text","length","includes","content","HTML","mode","pastedBlocks","trim","valueToInsert","addEventListener","removeEventListener","startReg","endReg","replace","metaTag","startsWith","slice"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AAKA;;AACA;;AACA;;AArBA;AACA;AACA;;AAcA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,KAAtB,EAA6BC,WAA7B,EAA2C;AAC1C,MAAKA,WAAL,EAAmB;AAClB,WAAO,uBAASD,KAAT,EAAgB,MAAhB,EAAwBE,mCAAxB,CAAP;AACA;;AAED,SAAO,uBAASF,KAAT,EAAgB,IAAIG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ACD;;AAEDZ,IAAAA,OAAO,CAAC+C,gBAAR,CAA0B,OAA1B,EAAmC9C,QAAnC;AACA,WAAO,MAAM;AACZD,MAAAA,OAAO,CAACgD,mBAAR,CAA6B,OAA7B,EAAsC/C,QAAtC;AACA,KAFD;AAGA,GAtNM,EAsNJ,EAtNI,CAAP;AAuNA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASqB,sBAAT,CAAiCJ,IAAjC,EAAwC;AACvC,QAAM+B,QAAQ,GAAG,yBAAjB;AACA,QAAMC,MAAM,GAAG,uBAAf;AAEA,SAAOhC,IAAI,CAACiC,OAAL,CAAcF,QAAd,EAAwB,EAAxB,EAA6BE,OAA7B,CAAsCD,MAAtC,EAA8C,EAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAAS3B,oBAAT,CAA+BL,IAA/B,EAAsC;AACrC,QAAMkC,OAAO,GAAI,wBAAjB;;AAEA,MAAKlC,IAAI,CAACmC,UAAL,CAAiBD,OAAjB,CAAL,EAAkC;AACjC,WAAOlC,IAAI,CAACoC,KAAL,CAAYF,OAAO,CAACb,MAApB,CAAP;AACA;;AAED,SAAOrB,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport { pasteHandler } from '@wordpress/blocks';\nimport {\n\tisEmpty,\n\tinsert,\n\tcreate,\n\treplace,\n\t__UNSTABLE_LINE_SEPARATOR as LINE_SEPARATOR,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { filePasteHandler } from './file-paste-handler';\nimport { addActiveFormats, isShortcode } from './utils';\nimport { splitValue } from './split-value';\n\n/** @typedef {import('@wordpress/rich-text').RichTextValue} RichTextValue */\n\n/**\n * Replaces line separators with line breaks if not multiline.\n * Replaces line breaks with line separators if multiline.\n *\n * @param {RichTextValue} value Value to adjust.\n * @param {boolean} isMultiline Whether to adjust to multiline or not.\n *\n * @return {RichTextValue} Adjusted value.\n */\nfunction adjustLines( value, isMultiline ) {\n\tif ( isMultiline ) {\n\t\treturn replace( value, /\\n+/g, LINE_SEPARATOR );\n\t}\n\n\treturn replace( value, new RegExp( LINE_SEPARATOR, 'g' ), '\\n' );\n}\n\nexport function usePasteHandler( props ) {\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction _onPaste( event ) {\n\t\t\tconst {\n\t\t\t\tisSelected,\n\t\t\t\tdisableFormats,\n\t\t\t\tonChange,\n\t\t\t\tvalue,\n\t\t\t\tformatTypes,\n\t\t\t\ttagName,\n\t\t\t\tonReplace,\n\t\t\t\tonSplit,\n\t\t\t\tonSplitMiddle,\n\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\tmultilineTag,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t\tpastePlainText,\n\t\t\t} = propsRef.current;\n\n\t\t\tif ( ! isSelected ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { clipboardData } = event;\n\n\t\t\tlet plainText = '';\n\t\t\tlet html = '';\n\n\t\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t\t// arguments first, then fallback to `Text` if they fail.\n\t\t\ttry {\n\t\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t\t} catch ( error1 ) {\n\t\t\t\ttry {\n\t\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t\t} catch ( error2 ) {\n\t\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t\t// behaviour.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove Windows-specific metadata appended within copied HTML text.\n\t\t\thtml = removeWindowsFragments( html );\n\n\t\t\t// Strip meta tag.\n\t\t\thtml = removeCharsetMetaTag( html );\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\t\tif ( disableFormats ) {\n\t\t\t\tonChange( insert( value, plainText ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstablePasteRule } ) => {\n\t\t\t\t\t// Only allow one transform.\n\t\t\t\t\tif ( __unstablePasteRule && accumlator === value ) {\n\t\t\t\t\t\taccumlator = __unstablePasteRule( value, {\n\t\t\t\t\t\t\thtml,\n\t\t\t\t\t\t\tplainText,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tvalue\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\tonChange( transformed );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst files = [ ...getFilesFromDataTransfer( clipboardData ) ];\n\t\t\tconst isInternal = clipboardData.getData( 'rich-text' ) === 'true';\n\n\t\t\t// If the data comes from a rich text instance, we can directly use it\n\t\t\t// without filtering the data. The filters are only meant for externally\n\t\t\t// pasted content and remove inline styles.\n\t\t\tif ( isInternal ) {\n\t\t\t\tconst pastedMultilineTag =\n\t\t\t\t\tclipboardData.getData( 'rich-text-multi-line-tag' ) ||\n\t\t\t\t\tundefined;\n\t\t\t\tlet pastedValue = create( {\n\t\t\t\t\thtml,\n\t\t\t\t\tmultilineTag: pastedMultilineTag,\n\t\t\t\t\tmultilineWrapperTags:\n\t\t\t\t\t\tpastedMultilineTag === 'li'\n\t\t\t\t\t\t\t? [ 'ul', 'ol' ]\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\t\t\t\tpastedValue = adjustLines( pastedValue, !! multilineTag );\n\t\t\t\taddActiveFormats( pastedValue, value.activeFormats );\n\t\t\t\tonChange( insert( value, pastedValue ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( pastePlainText ) {\n\t\t\t\tonChange( insert( value, create( { text: plainText } ) ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Process any attached files, unless we detect Microsoft Office as\n\t\t\t// the source.\n\t\t\t//\n\t\t\t// When content is copied from Microsoft Office, an image of the\n\t\t\t// content is rendered and attached to the clipboard along with the\n\t\t\t// plain-text and HTML content. This artifact is a distraction from\n\t\t\t// the relevant clipboard data, so we ignore it.\n\t\t\t//\n\t\t\t// Props https://github.com/pubpub/pubpub/commit/2f933277a15a263a1ab4bbd36b96d3a106544aec\n\t\t\tif (\n\t\t\t\tfiles &&\n\t\t\t\tfiles.length &&\n\t\t\t\t! html?.includes(\n\t\t\t\t\t'xmlns:o=\"urn:schemas-microsoft-com:office:office'\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tconst content = pasteHandler( {\n\t\t\t\t\tHTML: filePasteHandler( files ),\n\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\ttagName,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\n\t\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\twindow.console.log( 'Received items:\\n\\n', files );\n\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = onReplace && onSplit ? 'AUTO' : 'INLINE';\n\n\t\t\t// Force the blocks mode when the user is pasting\n\t\t\t// on a new line & the content resembles a shortcode.\n\t\t\t// Otherwise it's going to be detected as inline\n\t\t\t// and the shortcode won't be replaced.\n\t\t\tif (\n\t\t\t\tmode === 'AUTO' &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisShortcode( plainText )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t__unstableEmbedURLOnPaste &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisURL( plainText.trim() )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tconst content = pasteHandler( {\n\t\t\t\tHTML: html,\n\t\t\t\tplainText,\n\t\t\t\tmode,\n\t\t\t\ttagName,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t} );\n\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tlet valueToInsert = create( { html: content } );\n\n\t\t\t\t// If the content should be multiline, we should process text\n\t\t\t\t// separated by a line break as separate lines.\n\t\t\t\tvalueToInsert = adjustLines( valueToInsert, !! multilineTag );\n\n\t\t\t\taddActiveFormats( valueToInsert, value.activeFormats );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else if ( content.length > 0 ) {\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content, content.length - 1, -1 );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'paste', _onPaste );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'paste', _onPaste );\n\t\t};\n\t}, [] );\n}\n\n/**\n * Normalizes a given string of HTML to remove the Windows specific \"Fragment\" comments\n * and any preceeding and trailing whitespace.\n *\n * @param {string} html the html to be normalized\n * @return {string} the normalized html\n */\nfunction removeWindowsFragments( html ) {\n\tconst startReg = /.*<!--StartFragment-->/s;\n\tconst endReg = /<!--EndFragment-->.*/s;\n\n\treturn html.replace( startReg, '' ).replace( endReg, '' );\n}\n\n/**\n * Removes the charset meta tag inserted by Chromium.\n * See:\n * - https://github.com/WordPress/gutenberg/issues/33585\n * - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4\n *\n * @param {string} html the html to be stripped of the meta tag.\n * @return {string} the cleaned html\n */\nfunction removeCharsetMetaTag( html ) {\n\tconst metaTag = `<meta charset='utf-8'>`;\n\n\tif ( html.startsWith( metaTag ) ) {\n\t\treturn html.slice( metaTag.length );\n\t}\n\n\treturn html;\n}\n"]}
|
|
@@ -69,7 +69,8 @@ function getAllowedFormats(_ref) {
|
|
|
69
69
|
|
|
70
70
|
(0, _deprecated.default)('wp.blockEditor.RichText formattingControls prop', {
|
|
71
71
|
since: '5.4',
|
|
72
|
-
alternative: 'allowedFormats'
|
|
72
|
+
alternative: 'allowedFormats',
|
|
73
|
+
version: '6.2'
|
|
73
74
|
});
|
|
74
75
|
return formattingControls.map(name => `core/${name}`);
|
|
75
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/utils.js"],"names":["addActiveFormats","value","activeFormats","length","index","formats","getMultilineTag","multiline","getAllowedFormats","allowedFormats","formattingControls","disableFormats","EMPTY_ARRAY","since","alternative","map","name","isShortcode","text","test","createLinkInParagraph","url","onReplace","link","content"],"mappings":";;;;;;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AANA;AACA;AACA;AAMO,SAASA,gBAAT,CAA2BC,KAA3B,EAAkCC,aAAlC,EAAkD;AACxD,MAAKA,aAAL,aAAKA,aAAL,eAAKA,aAAa,CAAEC,MAApB,EAA6B;AAC5B,QAAIC,KAAK,GAAGH,KAAK,CAACI,OAAN,CAAcF,MAA1B;;AAEA,WAAQC,KAAK,EAAb,EAAkB;AACjBH,MAAAA,KAAK,CAACI,OAAN,CAAeD,KAAf,IAAyB,CACxB,GAAGF,aADqB,EAExB,IAAKD,KAAK,CAACI,OAAN,CAAeD,KAAf,KAA0B,EAA/B,CAFwB,CAAzB;AAIA;AACD;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,eAAT,CAA0BC,SAA1B,EAAsC;AAC5C,MAAKA,SAAS,KAAK,IAAd,IAAsBA,SAAS,KAAK,GAApC,IAA2CA,SAAS,KAAK,IAA9D,EAAqE;AACpE;AACA;;AAED,SAAOA,SAAS,KAAK,IAAd,GAAqB,GAArB,GAA2BA,SAAlC;AACA;;AAEM,SAASC,iBAAT,OAIH;AAAA,MAJ+B;AAClCC,IAAAA,cADkC;AAElCC,IAAAA,kBAFkC;AAGlCC,IAAAA;AAHkC,GAI/B;;AACH,MAAKA,cAAL,EAAsB;AACrB,WAAOH,iBAAiB,CAACI,WAAzB;AACA;;AAED,MAAK,CAAEH,cAAF,IAAoB,CAAEC,kBAA3B,EAAgD;AAC/C;AACA;;AAED,MAAKD,cAAL,EAAsB;AACrB,WAAOA,cAAP;AACA;;AAED,2BAAY,iDAAZ,EAA+D;AAC9DI,IAAAA,KAAK,EAAE,KADuD;AAE9DC,IAAAA,WAAW,EAAE;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/utils.js"],"names":["addActiveFormats","value","activeFormats","length","index","formats","getMultilineTag","multiline","getAllowedFormats","allowedFormats","formattingControls","disableFormats","EMPTY_ARRAY","since","alternative","version","map","name","isShortcode","text","test","createLinkInParagraph","url","onReplace","link","content"],"mappings":";;;;;;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AANA;AACA;AACA;AAMO,SAASA,gBAAT,CAA2BC,K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,CAAqBD,IAArB,CAAhC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASE,qBAAT,CAAgCC,GAAhC,EAAqCC,SAArC,EAAiD;AACvD,QAAMC,IAAI,GAAG;AAAG,IAAA,IAAI,EAAGF;AAAV,KAAkBA,GAAlB,CAAb;AACAC,EAAAA,SAAS,CACR,yBAAa,gBAAb,EAA+B;AAAEE,IAAAA,OAAO,EAAE,6BAAgBD,IAAhB;AAAX,GAA/B,CADQ,CAAT;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { regexp } from '@wordpress/shortcode';\nimport deprecated from '@wordpress/deprecated';\nimport { renderToString } from '@wordpress/element';\nimport { createBlock } from '@wordpress/blocks';\n\nexport function addActiveFormats( value, activeFormats ) {\n\tif ( activeFormats?.length ) {\n\t\tlet index = value.formats.length;\n\n\t\twhile ( index-- ) {\n\t\t\tvalue.formats[ index ] = [\n\t\t\t\t...activeFormats,\n\t\t\t\t...( value.formats[ index ] || [] ),\n\t\t\t];\n\t\t}\n\t}\n}\n\n/**\n * Get the multiline tag based on the multiline prop.\n *\n * @param {?(string|boolean)} multiline The multiline prop.\n *\n * @return {?string} The multiline tag.\n */\nexport function getMultilineTag( multiline ) {\n\tif ( multiline !== true && multiline !== 'p' && multiline !== 'li' ) {\n\t\treturn;\n\t}\n\n\treturn multiline === true ? 'p' : multiline;\n}\n\nexport function getAllowedFormats( {\n\tallowedFormats,\n\tformattingControls,\n\tdisableFormats,\n} ) {\n\tif ( disableFormats ) {\n\t\treturn getAllowedFormats.EMPTY_ARRAY;\n\t}\n\n\tif ( ! allowedFormats && ! formattingControls ) {\n\t\treturn;\n\t}\n\n\tif ( allowedFormats ) {\n\t\treturn allowedFormats;\n\t}\n\n\tdeprecated( 'wp.blockEditor.RichText formattingControls prop', {\n\t\tsince: '5.4',\n\t\talternative: 'allowedFormats',\n\t\tversion: '6.2',\n\t} );\n\n\treturn formattingControls.map( ( name ) => `core/${ name }` );\n}\n\ngetAllowedFormats.EMPTY_ARRAY = [];\n\nexport const isShortcode = ( text ) => regexp( '.*' ).test( text );\n\n/**\n * Creates a link from pasted URL.\n * Creates a paragraph block containing a link to the URL, and calls `onReplace`.\n *\n * @param {string} url The URL that could not be embedded.\n * @param {Function} onReplace Function to call with the created fallback block.\n */\nexport function createLinkInParagraph( url, onReplace ) {\n\tconst link = <a href={ url }>{ url }</a>;\n\tonReplace(\n\t\tcreateBlock( 'core/paragraph', { content: renderToString( link ) } )\n\t);\n}\n"]}
|
|
@@ -81,7 +81,7 @@ function BorderColorEdit(props) {
|
|
|
81
81
|
return (_getColorObjectByAttr = (0, _colors.getColorObjectByAttributeValues)(availableColors, borderColor, customBorderColor)) === null || _getColorObjectByAttr === void 0 ? void 0 : _getColorObjectByAttr.color;
|
|
82
82
|
}); // Detect changes in the color attributes and update the colorValue to keep the
|
|
83
83
|
// UI in sync. This is necessary for situations when border controls interact with
|
|
84
|
-
//
|
|
84
|
+
// each other: eg, setting the border width to zero causes the color and style
|
|
85
85
|
// selections to be cleared.
|
|
86
86
|
|
|
87
87
|
(0, _element.useEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-color.js"],"names":["EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","color","customBorderColor","border","colorValue","setColorValue","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","settings","label","onColorChange","clearable","hasBorderColorValue","resetBorderColor","addAttributes","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AA7BA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAgBA;AACA;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,MAAjC,EAAyCL,WAAzC,CADqB,2DACrB,uBAAwDS,KADnC,GAErBU;AAHgB,GAApB;AAMA,MAAIsB,YAAY,GAAG3C,KAAK,CAAC2C,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAG3C,KAAK,CAAC2C,YADK;AAEdxC,IAAAA,KAAK,EAAE,EACN,GAAGuC,WADG;AAEN,iCAAG1C,KAAK,CAAC2C,YAAT,wDAAG,oBAAoBxC,KAAvB;AAFM;AAFO,GAAf;AAQA,SAAO,4BAAC,cAAD,6BAAqBH,KAArB;AAA6B,IAAA,YAAY,EAAG2C;AAA5C,KAAP;AACA,CA7B0C,CAArC;;AAgCP,sBACC,0BADD,EAEC,2BAFD,EAGCd,aAHD;AAMA,sBACC,kCADD,EAEC,0BAFD,EAGCE,YAHD;AAMA,sBACC,0BADD,EAEC,0BAFD,EAGCK,YAHD;AAMA,sBACC,uBADD,EAEC,8CAFD,EAGCG,4BAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport {\n\thasBorderSupport,\n\tremoveBorderAttribute,\n\tshouldSkipSerialization,\n} from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst { color: customBorderColor } = style?.border || {};\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t);\n\n\t// Detect changes in the color attributes and update the colorValue to keep the\n\t// UI in sync. This is necessary for situations when border controls interact with\n\t// eachother: eg, setting the border width to zero causes the color and style\n\t// selections to be cleared.\n\tuseEffect( () => {\n\t\tsetColorValue(\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t\t);\n\t}, [ borderColor, customBorderColor, availableColors ] );\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\tconst settings = [\n\t\t{\n\t\t\tlabel: __( 'Color' ),\n\t\t\tonColorChange: onChangeColor,\n\t\t\tcolorValue,\n\t\t\tclearable: false,\n\t\t},\n\t];\n\treturn (\n\t\t<ColorGradientSettingsDropdown\n\t\t\tsettings={ settings }\n\t\t\tdisableCustomColors\n\t\t\tdisableCustomGradients\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\tenableAlpha\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value in the border color block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border color value set.\n */\nexport function hasBorderColorValue( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t} = props;\n\n\treturn !! borderColor || !! style?.border?.color;\n}\n\n/**\n * Resets the border color block support attributes. This can be used when\n * disabling the border color support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderColor( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tborderColor: undefined,\n\t\tstyle: removeBorderAttribute( style, 'color' ),\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 )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\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 * 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 )\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 } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\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...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\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-color.js"],"names":["EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","color","customBorderColor","border","colorValue","setColorValue","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","settings","label","onColorChange","clearable","hasBorderColorValue","resetBorderColor","addAttributes","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AA7BA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAgBA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,eAAT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AC2C,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAG3C,KAAK,CAAC2C,YADK;AAEdxC,IAAAA,KAAK,EAAE,EACN,GAAGuC,WADG;AAEN,iCAAG1C,KAAK,CAAC2C,YAAT,wDAAG,oBAAoBxC,KAAvB;AAFM;AAFO,GAAf;AAQA,SAAO,4BAAC,cAAD,6BAAqBH,KAArB;AAA6B,IAAA,YAAY,EAAG2C;AAA5C,KAAP;AACA,CA7B0C,CAArC;;AAgCP,sBACC,0BADD,EAEC,2BAFD,EAGCd,aAHD;AAMA,sBACC,kCADD,EAEC,0BAFD,EAGCE,YAHD;AAMA,sBACC,0BADD,EAEC,0BAFD,EAGCK,YAHD;AAMA,sBACC,uBADD,EAEC,8CAFD,EAGCG,4BAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport {\n\thasBorderSupport,\n\tremoveBorderAttribute,\n\tshouldSkipSerialization,\n} from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst { color: customBorderColor } = style?.border || {};\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t);\n\n\t// Detect changes in the color attributes and update the colorValue to keep the\n\t// UI in sync. This is necessary for situations when border controls interact with\n\t// each other: eg, setting the border width to zero causes the color and style\n\t// selections to be cleared.\n\tuseEffect( () => {\n\t\tsetColorValue(\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t\t);\n\t}, [ borderColor, customBorderColor, availableColors ] );\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\tconst settings = [\n\t\t{\n\t\t\tlabel: __( 'Color' ),\n\t\t\tonColorChange: onChangeColor,\n\t\t\tcolorValue,\n\t\t\tclearable: false,\n\t\t},\n\t];\n\treturn (\n\t\t<ColorGradientSettingsDropdown\n\t\t\tsettings={ settings }\n\t\t\tdisableCustomColors\n\t\t\tdisableCustomGradients\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\tenableAlpha\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value in the border color block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border color value set.\n */\nexport function hasBorderColorValue( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t} = props;\n\n\treturn !! borderColor || !! style?.border?.color;\n}\n\n/**\n * Resets the border color block support attributes. This can be used when\n * disabling the border color support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderColor( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tborderColor: undefined,\n\t\tstyle: removeBorderAttribute( style, 'color' ),\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 )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\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 * 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 )\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 } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\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...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\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"]}
|
|
@@ -9,12 +9,10 @@ exports.default = ColorPanel;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _i18n = require("@wordpress/i18n");
|
|
13
|
-
|
|
14
|
-
var _panelColorGradientSettings = _interopRequireDefault(require("../components/colors-gradients/panel-color-gradient-settings"));
|
|
15
|
-
|
|
16
12
|
var _contrastChecker = _interopRequireDefault(require("../components/contrast-checker"));
|
|
17
13
|
|
|
14
|
+
var _toolsPanelColorDropdown = _interopRequireDefault(require("../components/colors-gradients/tools-panel-color-dropdown"));
|
|
15
|
+
|
|
18
16
|
var _inspectorControls = _interopRequireDefault(require("../components/inspector-controls"));
|
|
19
17
|
|
|
20
18
|
var _useBlockRefs = require("../components/block-list/use-block-props/use-block-refs");
|
|
@@ -35,13 +33,15 @@ function ColorPanel(_ref) {
|
|
|
35
33
|
enableAlpha = false,
|
|
36
34
|
settings,
|
|
37
35
|
clientId,
|
|
38
|
-
enableContrastChecking = true
|
|
39
|
-
showTitle = true
|
|
36
|
+
enableContrastChecking = true
|
|
40
37
|
} = _ref;
|
|
41
38
|
const [detectedBackgroundColor, setDetectedBackgroundColor] = (0, _element.useState)();
|
|
42
39
|
const [detectedColor, setDetectedColor] = (0, _element.useState)();
|
|
40
|
+
const [detectedLinkColor, setDetectedLinkColor] = (0, _element.useState)();
|
|
43
41
|
const ref = (0, _useBlockRefs.__unstableUseBlockRef)(clientId);
|
|
44
42
|
(0, _element.useEffect)(() => {
|
|
43
|
+
var _ref$current;
|
|
44
|
+
|
|
45
45
|
if (!enableContrastChecking) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
@@ -51,6 +51,12 @@ function ColorPanel(_ref) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
setDetectedColor(getComputedStyle(ref.current).color);
|
|
54
|
+
const firstLinkElement = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector('a');
|
|
55
|
+
|
|
56
|
+
if (firstLinkElement && !!firstLinkElement.innerText) {
|
|
57
|
+
setDetectedLinkColor(getComputedStyle(firstLinkElement).color);
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
let backgroundColorNode = ref.current;
|
|
55
61
|
let backgroundColor = getComputedStyle(backgroundColorNode).backgroundColor;
|
|
56
62
|
|
|
@@ -61,18 +67,18 @@ function ColorPanel(_ref) {
|
|
|
61
67
|
|
|
62
68
|
setDetectedBackgroundColor(backgroundColor);
|
|
63
69
|
});
|
|
64
|
-
return (0, _element.createElement)(_inspectorControls.default,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}, enableContrastChecking && (0, _element.createElement)(_contrastChecker.default, {
|
|
70
|
+
return (0, _element.createElement)(_inspectorControls.default, {
|
|
71
|
+
__experimentalGroup: "color"
|
|
72
|
+
}, settings.map((setting, index) => (0, _element.createElement)(_toolsPanelColorDropdown.default, {
|
|
73
|
+
key: index,
|
|
74
|
+
settings: setting,
|
|
75
|
+
panelId: clientId,
|
|
76
|
+
enableAlpha: enableAlpha
|
|
77
|
+
})), enableContrastChecking && (0, _element.createElement)(_contrastChecker.default, {
|
|
73
78
|
backgroundColor: detectedBackgroundColor,
|
|
74
79
|
textColor: detectedColor,
|
|
75
|
-
enableAlphaChecker: enableAlpha
|
|
76
|
-
|
|
80
|
+
enableAlphaChecker: enableAlpha,
|
|
81
|
+
linkColor: detectedLinkColor
|
|
82
|
+
}));
|
|
77
83
|
}
|
|
78
84
|
//# sourceMappingURL=color-panel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/color-panel.js"],"names":["getComputedStyle","node","ownerDocument","defaultView","ColorPanel","enableAlpha","settings","clientId","enableContrastChecking","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/color-panel.js"],"names":["getComputedStyle","node","ownerDocument","defaultView","ColorPanel","enableAlpha","settings","clientId","enableContrastChecking","detectedBackgroundColor","setDetectedBackgroundColor","detectedColor","setDetectedColor","detectedLinkColor","setDetectedLinkColor","ref","current","color","firstLinkElement","querySelector","innerText","backgroundColorNode","backgroundColor","parentNode","nodeType","ELEMENT_NODE","map","setting","index"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;AAMA,SAASA,gBAAT,CAA2BC,IAA3B,EAAkC;AACjC,SAAOA,IAAI,CAACC,aAAL,CAAmBC,WAAnB,CAA+BH,gBAA/B,CAAiDC,IAAjD,CAAP;AACA;;AAEc,SAASG,UAAT,OAKX;AAAA,MALgC;AACnCC,IAAAA,WAAW,GAAG,KADqB;AAEnCC,IAAAA,QAFmC;AAGnCC,IAAAA,QAHmC;AAInCC,IAAAA,sBAAsB,GAAG;AAJU,GAKhC;AACH,QAAM,CAAEC,uBAAF,EAA2BC,0BAA3B,IAA0D,wBAAhE;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,wBAA5C;AACA,QAAM,CAAEC,iBAAF,EAAqBC,oBAArB,IAA8C,wBAApD;AACA,QAAMC,GAAG,GAAG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BAAsB,IACvB,4BAAC,wBAAD;AACC,IAAA,eAAe,EAAGC,uBADnB;AAEC,IAAA,SAAS,EAAGE,aAFb;AAGC,IAAA,kBAAkB,EAAGN,WAHtB;AAIC,IAAA,SAAS,EAAGQ;AAJb,IAVF,CADD;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ContrastChecker from '../components/contrast-checker';\nimport ToolsPanelColorDropdown from '../components/colors-gradients/tools-panel-color-dropdown';\nimport InspectorControls from '../components/inspector-controls';\nimport { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs';\n\nfunction getComputedStyle( node ) {\n\treturn node.ownerDocument.defaultView.getComputedStyle( node );\n}\n\nexport default function ColorPanel( {\n\tenableAlpha = false,\n\tsettings,\n\tclientId,\n\tenableContrastChecking = true,\n} ) {\n\tconst [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();\n\tconst [ detectedColor, setDetectedColor ] = useState();\n\tconst [ detectedLinkColor, setDetectedLinkColor ] = useState();\n\tconst ref = useBlockRef( clientId );\n\n\tuseEffect( () => {\n\t\tif ( ! enableContrastChecking ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\t\tsetDetectedColor( getComputedStyle( ref.current ).color );\n\n\t\tconst firstLinkElement = ref.current?.querySelector( 'a' );\n\t\tif ( firstLinkElement && !! firstLinkElement.innerText ) {\n\t\t\tsetDetectedLinkColor( getComputedStyle( firstLinkElement ).color );\n\t\t}\n\n\t\tlet backgroundColorNode = ref.current;\n\t\tlet backgroundColor = getComputedStyle( backgroundColorNode )\n\t\t\t.backgroundColor;\n\t\twhile (\n\t\t\tbackgroundColor === 'rgba(0, 0, 0, 0)' &&\n\t\t\tbackgroundColorNode.parentNode &&\n\t\t\tbackgroundColorNode.parentNode.nodeType ===\n\t\t\t\tbackgroundColorNode.parentNode.ELEMENT_NODE\n\t\t) {\n\t\t\tbackgroundColorNode = backgroundColorNode.parentNode;\n\t\t\tbackgroundColor = getComputedStyle( backgroundColorNode )\n\t\t\t\t.backgroundColor;\n\t\t}\n\n\t\tsetDetectedBackgroundColor( backgroundColor );\n\t} );\n\n\treturn (\n\t\t<InspectorControls __experimentalGroup=\"color\">\n\t\t\t{ settings.map( ( setting, index ) => (\n\t\t\t\t<ToolsPanelColorDropdown\n\t\t\t\t\tkey={ index }\n\t\t\t\t\tsettings={ setting }\n\t\t\t\t\tpanelId={ clientId }\n\t\t\t\t\tenableAlpha={ enableAlpha }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ enableContrastChecking && (\n\t\t\t\t<ContrastChecker\n\t\t\t\t\tbackgroundColor={ detectedBackgroundColor }\n\t\t\t\t\ttextColor={ detectedColor }\n\t\t\t\t\tenableAlphaChecker={ enableAlpha }\n\t\t\t\t\tlinkColor={ detectedLinkColor }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</InspectorControls>\n\t);\n}\n"]}
|
package/build/hooks/color.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.COLOR_SUPPORT_KEY = void 0;
|
|
|
9
9
|
exports.ColorEdit = ColorEdit;
|
|
10
10
|
exports.addEditProps = addEditProps;
|
|
11
11
|
exports.addSaveProps = addSaveProps;
|
|
12
|
+
exports.addTransforms = addTransforms;
|
|
12
13
|
exports.withColorPaletteStyles = void 0;
|
|
13
14
|
|
|
14
15
|
var _element = require("@wordpress/element");
|
|
@@ -84,6 +85,143 @@ const hasTextColorSupport = blockType => {
|
|
|
84
85
|
const colorSupport = (0, _blocks.getBlockSupport)(blockType, COLOR_SUPPORT_KEY);
|
|
85
86
|
return colorSupport && colorSupport.text !== false;
|
|
86
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Checks whether a color has been set either with a named preset color in
|
|
90
|
+
* a top level block attribute or as a custom value within the style attribute
|
|
91
|
+
* object.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} name Name of the color to check.
|
|
94
|
+
* @return {boolean} Whether or not a color has a value.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const hasColor = name => props => {
|
|
99
|
+
var _props$attributes$sty9, _props$attributes$sty10;
|
|
100
|
+
|
|
101
|
+
if (name === 'background') {
|
|
102
|
+
var _props$attributes$sty, _props$attributes$sty2, _props$attributes$sty3, _props$attributes$sty4;
|
|
103
|
+
|
|
104
|
+
return !!props.attributes.backgroundColor || !!((_props$attributes$sty = props.attributes.style) !== null && _props$attributes$sty !== void 0 && (_props$attributes$sty2 = _props$attributes$sty.color) !== null && _props$attributes$sty2 !== void 0 && _props$attributes$sty2.background) || !!props.attributes.gradient || !!((_props$attributes$sty3 = props.attributes.style) !== null && _props$attributes$sty3 !== void 0 && (_props$attributes$sty4 = _props$attributes$sty3.color) !== null && _props$attributes$sty4 !== void 0 && _props$attributes$sty4.gradient);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (name === 'link') {
|
|
108
|
+
var _props$attributes$sty5, _props$attributes$sty6, _props$attributes$sty7, _props$attributes$sty8;
|
|
109
|
+
|
|
110
|
+
return !!((_props$attributes$sty5 = props.attributes.style) !== null && _props$attributes$sty5 !== void 0 && (_props$attributes$sty6 = _props$attributes$sty5.elements) !== null && _props$attributes$sty6 !== void 0 && (_props$attributes$sty7 = _props$attributes$sty6.link) !== null && _props$attributes$sty7 !== void 0 && (_props$attributes$sty8 = _props$attributes$sty7.color) !== null && _props$attributes$sty8 !== void 0 && _props$attributes$sty8.text);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return !!props.attributes[`${name}Color`] || !!((_props$attributes$sty9 = props.attributes.style) !== null && _props$attributes$sty9 !== void 0 && (_props$attributes$sty10 = _props$attributes$sty9.color) !== null && _props$attributes$sty10 !== void 0 && _props$attributes$sty10[name]);
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Clears a single color property from a style object.
|
|
117
|
+
*
|
|
118
|
+
* @param {Array} path Path to color property to clear within styles object.
|
|
119
|
+
* @param {Object} style Block attributes style object.
|
|
120
|
+
* @return {Object} Styles with the color property omitted.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
const clearColorFromStyles = (path, style) => (0, _utils.cleanEmptyObject)((0, _utils.immutableSet)(style, path, undefined));
|
|
125
|
+
/**
|
|
126
|
+
* Resets the block attributes for text color.
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} props Current block props.
|
|
129
|
+
* @param {Object} props.attributes Block attributes.
|
|
130
|
+
* @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
const resetTextColor = _ref => {
|
|
135
|
+
let {
|
|
136
|
+
attributes,
|
|
137
|
+
setAttributes
|
|
138
|
+
} = _ref;
|
|
139
|
+
setAttributes({
|
|
140
|
+
textColor: undefined,
|
|
141
|
+
style: clearColorFromStyles(['color', 'text'], attributes.style)
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Clears text color related properties from supplied attributes.
|
|
146
|
+
*
|
|
147
|
+
* @param {Object} attributes Block attributes.
|
|
148
|
+
* @return {Object} Update block attributes with text color properties omitted.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const resetAllTextFilter = attributes => ({
|
|
153
|
+
textColor: undefined,
|
|
154
|
+
style: clearColorFromStyles(['color', 'text'], attributes.style)
|
|
155
|
+
});
|
|
156
|
+
/**
|
|
157
|
+
* Resets the block attributes for link color.
|
|
158
|
+
*
|
|
159
|
+
* @param {Object} props Current block props.
|
|
160
|
+
* @param {Object} props.attributes Block attributes.
|
|
161
|
+
* @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
const resetLinkColor = _ref2 => {
|
|
166
|
+
let {
|
|
167
|
+
attributes,
|
|
168
|
+
setAttributes
|
|
169
|
+
} = _ref2;
|
|
170
|
+
const path = ['elements', 'link', 'color', 'text'];
|
|
171
|
+
setAttributes({
|
|
172
|
+
style: clearColorFromStyles(path, attributes.style)
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Clears link color related properties from supplied attributes.
|
|
177
|
+
*
|
|
178
|
+
* @param {Object} attributes Block attributes.
|
|
179
|
+
* @return {Object} Update block attributes with link color properties omitted.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
const resetAllLinkFilter = attributes => ({
|
|
184
|
+
style: clearColorFromStyles(['elements', 'link', 'color', 'text'], attributes.style)
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Clears all background color related properties including gradients from
|
|
188
|
+
* supplied block attributes.
|
|
189
|
+
*
|
|
190
|
+
* @param {Object} attributes Block attributes.
|
|
191
|
+
* @return {Object} Block attributes with background and gradient omitted.
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
const clearBackgroundAndGradient = attributes => {
|
|
196
|
+
var _attributes$style;
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
backgroundColor: undefined,
|
|
200
|
+
gradient: undefined,
|
|
201
|
+
style: { ...attributes.style,
|
|
202
|
+
color: { ...((_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.color),
|
|
203
|
+
background: undefined,
|
|
204
|
+
gradient: undefined
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Resets the block attributes for both background color and gradient.
|
|
211
|
+
*
|
|
212
|
+
* @param {Object} props Current block props.
|
|
213
|
+
* @param {Object} props.attributes Block attributes.
|
|
214
|
+
* @param {Function} props.setAttributes Block's setAttributes prop used to apply reset.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
const resetBackgroundAndGradient = _ref3 => {
|
|
219
|
+
let {
|
|
220
|
+
attributes,
|
|
221
|
+
setAttributes
|
|
222
|
+
} = _ref3;
|
|
223
|
+
setAttributes(clearBackgroundAndGradient(attributes));
|
|
224
|
+
};
|
|
87
225
|
/**
|
|
88
226
|
* Filters registered block settings, extending attributes to include
|
|
89
227
|
* `backgroundColor` and `textColor` attribute.
|
|
@@ -144,7 +282,7 @@ function addSaveProps(props, blockType, attributes) {
|
|
|
144
282
|
return props;
|
|
145
283
|
}
|
|
146
284
|
|
|
147
|
-
const hasGradient = hasGradientSupport(blockType); // I'd have
|
|
285
|
+
const hasGradient = hasGradientSupport(blockType); // I'd have preferred to avoid the "style" attribute usage here
|
|
148
286
|
|
|
149
287
|
const {
|
|
150
288
|
backgroundColor,
|
|
@@ -166,7 +304,7 @@ function addSaveProps(props, blockType, attributes) {
|
|
|
166
304
|
return props;
|
|
167
305
|
}
|
|
168
306
|
/**
|
|
169
|
-
* Filters registered block settings to
|
|
307
|
+
* Filters registered block settings to extend the block edit wrapper
|
|
170
308
|
* to apply the desired styles and classnames properly.
|
|
171
309
|
*
|
|
172
310
|
* @param {Object} settings Original block settings.
|
|
@@ -204,10 +342,6 @@ const getLinkColorFromAttributeValue = (colors, value) => {
|
|
|
204
342
|
|
|
205
343
|
return value;
|
|
206
344
|
};
|
|
207
|
-
|
|
208
|
-
function immutableSet(object, path, value) {
|
|
209
|
-
return (0, _lodash.setWith)(object ? (0, _lodash.clone)(object) : {}, path, value, _lodash.clone);
|
|
210
|
-
}
|
|
211
345
|
/**
|
|
212
346
|
* Inspector control panel containing the color related configuration
|
|
213
347
|
*
|
|
@@ -340,13 +474,14 @@ function ColorEdit(props) {
|
|
|
340
474
|
const onChangeLinkColor = value => {
|
|
341
475
|
const colorObject = (0, _colors.getColorObjectByColorValue)(allSolids, value);
|
|
342
476
|
const newLinkColorValue = colorObject !== null && colorObject !== void 0 && colorObject.slug ? `var:preset|color|${colorObject.slug}` : value;
|
|
343
|
-
const newStyle = (0, _utils.cleanEmptyObject)(immutableSet(style, ['elements', 'link', 'color', 'text'], newLinkColorValue));
|
|
477
|
+
const newStyle = (0, _utils.cleanEmptyObject)((0, _utils.immutableSet)(style, ['elements', 'link', 'color', 'text'], newLinkColorValue));
|
|
344
478
|
props.setAttributes({
|
|
345
479
|
style: newStyle
|
|
346
480
|
});
|
|
347
481
|
};
|
|
348
482
|
|
|
349
483
|
const enableContrastChecking = _element.Platform.OS === 'web' && !gradient && !(style !== null && style !== void 0 && (_style$color6 = style.color) !== null && _style$color6 !== void 0 && _style$color6.gradient);
|
|
484
|
+
const defaultColorControls = (0, _blocks.getBlockSupport)(props.name, [COLOR_SUPPORT_KEY, '__experimentalDefaultControls']);
|
|
350
485
|
return (0, _element.createElement)(_colorPanel.default, {
|
|
351
486
|
enableContrastChecking: enableContrastChecking,
|
|
352
487
|
clientId: props.clientId,
|
|
@@ -354,18 +489,30 @@ function ColorEdit(props) {
|
|
|
354
489
|
settings: [...(hasTextColor ? [{
|
|
355
490
|
label: (0, _i18n.__)('Text'),
|
|
356
491
|
onColorChange: onChangeColor('text'),
|
|
357
|
-
colorValue: (0, _colors.getColorObjectByAttributeValues)(allSolids, textColor, style === null || style === void 0 ? void 0 : (_style$color7 = style.color) === null || _style$color7 === void 0 ? void 0 : _style$color7.text).color
|
|
492
|
+
colorValue: (0, _colors.getColorObjectByAttributeValues)(allSolids, textColor, style === null || style === void 0 ? void 0 : (_style$color7 = style.color) === null || _style$color7 === void 0 ? void 0 : _style$color7.text).color,
|
|
493
|
+
isShownByDefault: defaultColorControls === null || defaultColorControls === void 0 ? void 0 : defaultColorControls.text,
|
|
494
|
+
hasValue: () => hasColor('text')(props),
|
|
495
|
+
onDeselect: () => resetTextColor(props),
|
|
496
|
+
resetAllFilter: resetAllTextFilter
|
|
358
497
|
}] : []), ...(hasBackgroundColor || hasGradientColor ? [{
|
|
359
498
|
label: (0, _i18n.__)('Background'),
|
|
360
499
|
onColorChange: hasBackgroundColor ? onChangeColor('background') : undefined,
|
|
361
500
|
colorValue: (0, _colors.getColorObjectByAttributeValues)(allSolids, backgroundColor, style === null || style === void 0 ? void 0 : (_style$color8 = style.color) === null || _style$color8 === void 0 ? void 0 : _style$color8.background).color,
|
|
362
501
|
gradientValue,
|
|
363
|
-
onGradientChange: hasGradientColor ? onChangeGradient : undefined
|
|
502
|
+
onGradientChange: hasGradientColor ? onChangeGradient : undefined,
|
|
503
|
+
isShownByDefault: defaultColorControls === null || defaultColorControls === void 0 ? void 0 : defaultColorControls.background,
|
|
504
|
+
hasValue: () => hasColor('background')(props),
|
|
505
|
+
onDeselect: () => resetBackgroundAndGradient(props),
|
|
506
|
+
resetAllFilter: clearBackgroundAndGradient
|
|
364
507
|
}] : []), ...(hasLinkColor ? [{
|
|
365
508
|
label: (0, _i18n.__)('Link'),
|
|
366
509
|
onColorChange: onChangeLinkColor,
|
|
367
510
|
colorValue: getLinkColorFromAttributeValue(allSolids, style === null || style === void 0 ? void 0 : (_style$elements2 = style.elements) === null || _style$elements2 === void 0 ? void 0 : (_style$elements2$link = _style$elements2.link) === null || _style$elements2$link === void 0 ? void 0 : (_style$elements2$link2 = _style$elements2$link.color) === null || _style$elements2$link2 === void 0 ? void 0 : _style$elements2$link2.text),
|
|
368
|
-
clearable: !!(style !== null && style !== void 0 && (_style$elements3 = style.elements) !== null && _style$elements3 !== void 0 && (_style$elements3$link = _style$elements3.link) !== null && _style$elements3$link !== void 0 && (_style$elements3$link2 = _style$elements3$link.color) !== null && _style$elements3$link2 !== void 0 && _style$elements3$link2.text)
|
|
511
|
+
clearable: !!(style !== null && style !== void 0 && (_style$elements3 = style.elements) !== null && _style$elements3 !== void 0 && (_style$elements3$link = _style$elements3.link) !== null && _style$elements3$link !== void 0 && (_style$elements3$link2 = _style$elements3$link.color) !== null && _style$elements3$link2 !== void 0 && _style$elements3$link2.text),
|
|
512
|
+
isShownByDefault: defaultColorControls === null || defaultColorControls === void 0 ? void 0 : defaultColorControls.link,
|
|
513
|
+
hasValue: () => hasColor('link')(props),
|
|
514
|
+
onDeselect: () => resetLinkColor(props),
|
|
515
|
+
resetAllFilter: resetAllLinkFilter
|
|
369
516
|
}] : [])]
|
|
370
517
|
});
|
|
371
518
|
}
|
|
@@ -424,8 +571,27 @@ const withColorPaletteStyles = (0, _compose.createHigherOrderComponent)(BlockLis
|
|
|
424
571
|
}));
|
|
425
572
|
});
|
|
426
573
|
exports.withColorPaletteStyles = withColorPaletteStyles;
|
|
574
|
+
const MIGRATION_PATHS = {
|
|
575
|
+
linkColor: [['style', 'elements', 'link', 'color', 'text']],
|
|
576
|
+
textColor: [['textColor'], ['style', 'color', 'text']],
|
|
577
|
+
backgroundColor: [['backgroundColor'], ['style', 'color', 'background']],
|
|
578
|
+
gradient: [['gradient'], ['style', 'color', 'gradient']]
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
function addTransforms(result, source, index, results) {
|
|
582
|
+
const destinationBlockType = result.name;
|
|
583
|
+
const activeSupports = {
|
|
584
|
+
linkColor: hasLinkColorSupport(destinationBlockType),
|
|
585
|
+
textColor: hasTextColorSupport(destinationBlockType),
|
|
586
|
+
backgroundColor: hasBackgroundColorSupport(destinationBlockType),
|
|
587
|
+
gradient: hasGradientSupport(destinationBlockType)
|
|
588
|
+
};
|
|
589
|
+
return (0, _utils.transformStyles)(activeSupports, MIGRATION_PATHS, result, source, index, results);
|
|
590
|
+
}
|
|
591
|
+
|
|
427
592
|
(0, _hooks.addFilter)('blocks.registerBlockType', 'core/color/addAttribute', addAttributes);
|
|
428
593
|
(0, _hooks.addFilter)('blocks.getSaveContent.extraProps', 'core/color/addSaveProps', addSaveProps);
|
|
429
594
|
(0, _hooks.addFilter)('blocks.registerBlockType', 'core/color/addEditProps', addEditProps);
|
|
430
595
|
(0, _hooks.addFilter)('editor.BlockListBlock', 'core/color/with-color-palette-styles', withColorPaletteStyles);
|
|
596
|
+
(0, _hooks.addFilter)('blocks.switchToBlockType.transformedBlock', 'core/color/addTransforms', addTransforms);
|
|
431
597
|
//# sourceMappingURL=color.js.map
|