@wordpress/block-editor 8.0.4 → 8.0.8
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/build/components/block-preview/auto.js +1 -0
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +7 -1
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/colors/with-colors.js +9 -4
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +6 -2
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +11 -70
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/colors-gradients/use-common-single-multiple-selects.js +21 -0
- package/build/components/colors-gradients/use-common-single-multiple-selects.js.map +1 -0
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +98 -0
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -0
- package/build/components/gradients/use-gradient.js +7 -6
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/use-setting/index.js +1 -1
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/border-color.js +12 -12
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/color-panel.js +2 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +45 -23
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/typography.js +3 -0
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-color-props.js +19 -6
- package/build/hooks/use-color-props.js.map +1 -1
- package/build/store/selectors.js +37 -43
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -0
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +7 -1
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/colors/with-colors.js +9 -4
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +6 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +10 -72
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js +11 -0
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js.map +1 -0
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +85 -0
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -0
- package/build-module/components/gradients/use-gradient.js +7 -6
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/use-setting/index.js +1 -1
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/border-color.js +11 -12
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/color-panel.js +2 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +46 -24
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/typography.js +1 -2
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-color-props.js +16 -4
- package/build-module/hooks/use-color-props.js.map +1 -1
- package/build-module/store/selectors.js +37 -43
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +8 -1
- package/build-style/style.css +8 -1
- package/package.json +3 -3
- package/src/components/block-preview/auto.js +3 -0
- package/src/components/block-preview/style.scss +5 -0
- package/src/components/block-tools/block-selection-button.js +5 -1
- package/src/components/colors/with-colors.js +16 -5
- package/src/components/colors-gradients/control.js +6 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +8 -92
- package/src/components/colors-gradients/use-common-single-multiple-selects.js +11 -0
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +107 -0
- package/src/components/gradients/use-gradient.js +18 -7
- package/src/components/link-control/style.scss +6 -2
- package/src/components/use-setting/index.js +1 -1
- package/src/hooks/border-color.js +15 -9
- package/src/hooks/color-panel.js +1 -0
- package/src/hooks/color.js +71 -31
- package/src/hooks/test/color.js +109 -0
- package/src/hooks/typography.js +1 -1
- package/src/hooks/use-color-props.js +30 -4
- package/src/store/selectors.js +14 -26
|
@@ -68,6 +68,7 @@ function AutoBlockPreview(_ref) {
|
|
|
68
68
|
documentElement
|
|
69
69
|
}
|
|
70
70
|
} = bodyElement;
|
|
71
|
+
documentElement.classList.add('block-editor-block-preview__content-iframe');
|
|
71
72
|
documentElement.style.position = 'absolute';
|
|
72
73
|
documentElement.style.width = '100%';
|
|
73
74
|
bodyElement.style.padding = __experimentalPadding + 'px';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-preview/auto.js"],"names":["MemoizedBlockList","AutoBlockPreview","viewportWidth","__experimentalPadding","containerResizeListener","width","containerWidth","contentResizeListener","height","contentHeight","styles","select","store","getSettings","BlockList","scale","transform","bodyElement","ownerDocument","documentElement","style","position","padding","pointerEvents"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAKA;AACA;AACA;AAMA;AACA,IAAIA,iBAAJ;;AAEA,SAASC,gBAAT,OAAsE;AAAA,MAA3C;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA;AAAjB,GAA2C;AACrE,QAAM,CACLC,uBADK,EAEL;AAAEC,IAAAA,KAAK,EAAEC;AAAT,GAFK,IAGF,iCAHJ;AAIA,QAAM,CACLC,qBADK,EAEL;AAAEC,IAAAA,MAAM,EAAEC;AAAV,GAFK,IAGF,iCAHJ;AAIA,QAAMC,MAAM,GAAG,qBAAaC,MAAF,IAAc;AACvC,WAAOA,MAAM,CAAEC,YAAF,CAAN,CAAgBC,WAAhB,GAA8BH,MAArC;AACA,GAFc,EAEZ,EAFY,CAAf,CATqE,CAarE;;AACAV,EAAAA,iBAAiB,GAAGA,iBAAiB,IAAI,mBAAMc,kBAAN,CAAzC;AAEA,QAAMC,KAAK,GAAGT,cAAc,GAAGJ,aAA/B;AAEA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGE,uBADH,EAEC,4BAAC,oBAAD;AACC,IAAA,SAAS,EAAC,qCADX;AAEC,IAAA,KAAK,EAAG;AACPY,MAAAA,SAAS,EAAG,SAASD,KAAO,GADrB;AAEPP,MAAAA,MAAM,EAAEC,aAAa,GAAGM;AAFjB;AAFT,KAOC,4BAAC,eAAD;AACC,IAAA,IAAI,EAAG,4BAAC,qBAAD;AAAc,MAAA,MAAM,EAAGL;AAAvB,MADR;AAEC,IAAA,UAAU,EAAG,2BAAgBO,WAAF,IAAmB;AAC7C,YAAM;AACLC,QAAAA,aAAa,EAAE;AAAEC,UAAAA;AAAF;AADV,UAEFF,WAFJ;AAGAE,MAAAA,eAAe,CAACC,KAAhB,CAAsBC,QAAtB,GAAiC,UAAjC;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-preview/auto.js"],"names":["MemoizedBlockList","AutoBlockPreview","viewportWidth","__experimentalPadding","containerResizeListener","width","containerWidth","contentResizeListener","height","contentHeight","styles","select","store","getSettings","BlockList","scale","transform","bodyElement","ownerDocument","documentElement","classList","add","style","position","padding","pointerEvents"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAKA;AACA;AACA;AAMA;AACA,IAAIA,iBAAJ;;AAEA,SAASC,gBAAT,OAAsE;AAAA,MAA3C;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA;AAAjB,GAA2C;AACrE,QAAM,CACLC,uBADK,EAEL;AAAEC,IAAAA,KAAK,EAAEC;AAAT,GAFK,IAGF,iCAHJ;AAIA,QAAM,CACLC,qBADK,EAEL;AAAEC,IAAAA,MAAM,EAAEC;AAAV,GAFK,IAGF,iCAHJ;AAIA,QAAMC,MAAM,GAAG,qBAAaC,MAAF,IAAc;AACvC,WAAOA,MAAM,CAAEC,YAAF,CAAN,CAAgBC,WAAhB,GAA8BH,MAArC;AACA,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/**\n * WordPress dependencies\n */\nimport { Disabled } from '@wordpress/components';\nimport { useResizeObserver, pure, useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../block-list';\nimport Iframe from '../iframe';\nimport EditorStyles from '../editor-styles';\nimport { store } from '../../store';\n\n// This is used to avoid rendering the block list if the sizes change.\nlet MemoizedBlockList;\n\nfunction AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {\n\tconst [\n\t\tcontainerResizeListener,\n\t\t{ width: containerWidth },\n\t] = useResizeObserver();\n\tconst [\n\t\tcontentResizeListener,\n\t\t{ height: contentHeight },\n\t] = useResizeObserver();\n\tconst styles = useSelect( ( select ) => {\n\t\treturn select( store ).getSettings().styles;\n\t}, [] );\n\n\t// Initialize on render instead of module top level, to avoid circular dependency issues.\n\tMemoizedBlockList = MemoizedBlockList || pure( BlockList );\n\n\tconst scale = containerWidth / viewportWidth;\n\n\treturn (\n\t\t<div className=\"block-editor-block-preview__container\">\n\t\t\t{ containerResizeListener }\n\t\t\t<Disabled\n\t\t\t\tclassName=\"block-editor-block-preview__content\"\n\t\t\t\tstyle={ {\n\t\t\t\t\ttransform: `scale(${ scale })`,\n\t\t\t\t\theight: contentHeight * scale,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Iframe\n\t\t\t\t\thead={ <EditorStyles styles={ styles } /> }\n\t\t\t\t\tcontentRef={ useRefEffect( ( bodyElement ) => {\n\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\townerDocument: { documentElement },\n\t\t\t\t\t\t} = bodyElement;\n\t\t\t\t\t\tdocumentElement.classList.add(\n\t\t\t\t\t\t\t'block-editor-block-preview__content-iframe'\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdocumentElement.style.position = 'absolute';\n\t\t\t\t\t\tdocumentElement.style.width = '100%';\n\t\t\t\t\t\tbodyElement.style.padding =\n\t\t\t\t\t\t\t__experimentalPadding + 'px';\n\t\t\t\t\t}, [] ) }\n\t\t\t\t\taria-hidden\n\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\twidth: viewportWidth,\n\t\t\t\t\t\theight: contentHeight,\n\t\t\t\t\t\tpointerEvents: 'none',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t<MemoizedBlockList renderAppender={ false } />\n\t\t\t\t</Iframe>\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n}\n\nexport default AutoBlockPreview;\n"]}
|
|
@@ -118,7 +118,8 @@ function BlockSelectionButton(_ref) {
|
|
|
118
118
|
getSelectedBlockClientId,
|
|
119
119
|
getMultiSelectedBlocksEndClientId,
|
|
120
120
|
getPreviousBlockClientId,
|
|
121
|
-
getNextBlockClientId
|
|
121
|
+
getNextBlockClientId,
|
|
122
|
+
isNavigationMode
|
|
122
123
|
} = (0, _data.useSelect)(_store.store);
|
|
123
124
|
const {
|
|
124
125
|
selectBlock,
|
|
@@ -175,6 +176,11 @@ function BlockSelectionButton(_ref) {
|
|
|
175
176
|
|
|
176
177
|
const startingBlockClientId = hasBlockMovingClientId();
|
|
177
178
|
|
|
179
|
+
if (isEscape && isNavigationMode()) {
|
|
180
|
+
clearSelectedBlock();
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
}
|
|
183
|
+
|
|
178
184
|
if (isEscape && startingBlockClientId && !event.defaultPrevented) {
|
|
179
185
|
setBlockMovingClientId(null);
|
|
180
186
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-selection-button.js"],"names":["BlockSelectionButton","clientId","rootClientId","blockElement","blockInformation","selected","select","getBlock","getBlockIndex","hasBlockMovingClientId","getBlockListSettings","blockEditorStore","index","name","attributes","blockMovingMode","orientation","setNavigationMode","removeBlock","ref","blockType","label","current","focus","getBlockRootClientId","getClientIdsOfDescendants","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","selectBlock","clearSelectedBlock","setBlockMovingClientId","moveBlockToPosition","onKeyDown","event","keyCode","isUp","UP","isDown","DOWN","isLeft","LEFT","isRight","RIGHT","isTab","TAB","isEscape","ESCAPE","isEnter","ENTER","isSpace","SPACE","isShift","shiftKey","BACKSPACE","DELETE","preventDefault","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","navigateUp","navigateDown","navigateOut","navigateIn","focusedBlockUid","startingBlockClientId","defaultPrevented","sourceRoot","destRoot","sourceBlockIndex","destinationBlockIndex","nextTabbable","tabbable","findNext","ownerDocument","defaultView","frameElement","findPrevious","classNames","dragHandleLabel","icon","draggableProps","dragHandle"],"mappings":";;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AAYA;;AAIA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAvCA;AACA;AACA;;AAGA;AACA;AACA;;AAyBA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,oBAAT,OAA0E;AAAA,MAA3C;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAA2C;AACzE,QAAMC,gBAAgB,GAAG,yCAA4BH,QAA5B,CAAzB;AACA,QAAMI,QAAQ,GAAG,qBACdC,MAAF,IAAc;AAAA;;AACb,UAAM;AACLC,MAAAA,QADK;AAELC,MAAAA,aAFK;AAGLC,MAAAA,sBAHK;AAILC,MAAAA;AAJK,QAKFJ,MAAM,CAAEK,YAAF,CALV;AAMA,UAAMC,KAAK,GAAGJ,aAAa,CAAEP,QAAF,EAAYC,YAAZ,CAA3B;AACA,UAAM;AAAEW,MAAAA,IAAF;AAAQC,MAAAA;AAAR,QAAuBP,QAAQ,CAAEN,QAAF,CAArC;AACA,UAAMc,eAAe,GAAGN,sBAAsB,EAA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AIC,IAAA,KAAK,EAAGH,eAJT,CAKC;AACA;AAND;AAOC,IAAA,QAAQ,EAAC;AAPV,KAQME,cARN,EAFF,CADD,CAPD,EAuBC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,GAAG,EAAGhE,GADP;AAEC,IAAA,OAAO,EAAG,MAAMF,iBAAiB,CAAE,KAAF,CAFlC;AAGC,IAAA,SAAS,EAAGiB,SAHb;AAIC,IAAA,KAAK,EAAGb,KAJT;AAKC,IAAA,SAAS,EAAC;AALX,KAOC,4BAAC,mBAAD;AAAY,IAAA,QAAQ,EAAGpB;AAAvB,IAPD,CADD,CAvBD,CADD,CADD;AAuCA;;eAEcD,oB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { dragHandle } from '@wordpress/icons';\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tBACKSPACE,\n\tDELETE,\n\tUP,\n\tDOWN,\n\tLEFT,\n\tRIGHT,\n\tTAB,\n\tESCAPE,\n\tENTER,\n\tSPACE,\n} from '@wordpress/keycodes';\nimport {\n\tgetBlockType,\n\t__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,\n} from '@wordpress/blocks';\nimport { speak } from '@wordpress/a11y';\nimport { focus } from '@wordpress/dom';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockTitle from '../block-title';\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport BlockDraggable from '../block-draggable';\nimport useBlockDisplayInformation from '../use-block-display-information';\n\n/**\n * Block selection button component, displaying the label of the block. If the block\n * descends from a root block, a button is displayed enabling the user to select\n * the root block.\n *\n * @param {string} props Component props.\n * @param {string} props.clientId Client ID of block.\n *\n * @return {WPComponent} The component to be rendered.\n */\nfunction BlockSelectionButton( { clientId, rootClientId, blockElement } ) {\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst selected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockIndex,\n\t\t\t\thasBlockMovingClientId,\n\t\t\t\tgetBlockListSettings,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst index = getBlockIndex( clientId, rootClientId );\n\t\t\tconst { name, attributes } = getBlock( clientId );\n\t\t\tconst blockMovingMode = hasBlockMovingClientId();\n\t\t\treturn {\n\t\t\t\tindex,\n\t\t\t\tname,\n\t\t\t\tattributes,\n\t\t\t\tblockMovingMode,\n\t\t\t\torientation: getBlockListSettings( rootClientId )?.orientation,\n\t\t\t};\n\t\t},\n\t\t[ clientId, rootClientId ]\n\t);\n\tconst { index, name, attributes, blockMovingMode, orientation } = selected;\n\tconst { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );\n\tconst ref = useRef();\n\n\tconst blockType = getBlockType( name );\n\tconst label = getAccessibleBlockLabel(\n\t\tblockType,\n\t\tattributes,\n\t\tindex + 1,\n\t\torientation\n\t);\n\n\t// Focus the breadcrumb in navigation mode.\n\tuseEffect( () => {\n\t\tref.current.focus();\n\n\t\tspeak( label );\n\t}, [ label ] );\n\n\tconst {\n\t\thasBlockMovingClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockRootClientId,\n\t\tgetClientIdsOfDescendants,\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tselectBlock,\n\t\tclearSelectedBlock,\n\t\tsetBlockMovingClientId,\n\t\tmoveBlockToPosition,\n\t} = useDispatch( blockEditorStore );\n\n\tfunction onKeyDown( event ) {\n\t\tconst { keyCode } = event;\n\t\tconst isUp = keyCode === UP;\n\t\tconst isDown = keyCode === DOWN;\n\t\tconst isLeft = keyCode === LEFT;\n\t\tconst isRight = keyCode === RIGHT;\n\t\tconst isTab = keyCode === TAB;\n\t\tconst isEscape = keyCode === ESCAPE;\n\t\tconst isEnter = keyCode === ENTER;\n\t\tconst isSpace = keyCode === SPACE;\n\t\tconst isShift = event.shiftKey;\n\n\t\tif ( keyCode === BACKSPACE || keyCode === DELETE ) {\n\t\t\tremoveBlock( clientId );\n\t\t\tevent.preventDefault();\n\t\t\treturn;\n\t\t}\n\n\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\n\t\tconst navigateUp = ( isTab && isShift ) || isUp;\n\t\tconst navigateDown = ( isTab && ! isShift ) || isDown;\n\t\t// Move out of current nesting level (no effect if at root level).\n\t\tconst navigateOut = isLeft;\n\t\t// Move into next nesting level (no effect if the current block has no innerBlocks).\n\t\tconst navigateIn = isRight;\n\n\t\tlet focusedBlockUid;\n\t\tif ( navigateUp ) {\n\t\t\tfocusedBlockUid = selectionBeforeEndClientId;\n\t\t} else if ( navigateDown ) {\n\t\t\tfocusedBlockUid = selectionAfterEndClientId;\n\t\t} else if ( navigateOut ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetBlockRootClientId( selectedBlockClientId ) ??\n\t\t\t\tselectedBlockClientId;\n\t\t} else if ( navigateIn ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetClientIdsOfDescendants( [ selectedBlockClientId ] )[ 0 ] ??\n\t\t\t\tselectedBlockClientId;\n\t\t}\n\t\tconst startingBlockClientId = hasBlockMovingClientId();\n\n\t\tif ( isEscape && startingBlockClientId && ! event.defaultPrevented ) {\n\t\t\tsetBlockMovingClientId( null );\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( ( isEnter || isSpace ) && startingBlockClientId ) {\n\t\t\tconst sourceRoot = getBlockRootClientId( startingBlockClientId );\n\t\t\tconst destRoot = getBlockRootClientId( selectedBlockClientId );\n\t\t\tconst sourceBlockIndex = getBlockIndex(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot\n\t\t\t);\n\t\t\tlet destinationBlockIndex = getBlockIndex(\n\t\t\t\tselectedBlockClientId,\n\t\t\t\tdestRoot\n\t\t\t);\n\t\t\tif (\n\t\t\t\tsourceBlockIndex < destinationBlockIndex &&\n\t\t\t\tsourceRoot === destRoot\n\t\t\t) {\n\t\t\t\tdestinationBlockIndex -= 1;\n\t\t\t}\n\t\t\tmoveBlockToPosition(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot,\n\t\t\t\tdestRoot,\n\t\t\t\tdestinationBlockIndex\n\t\t\t);\n\t\t\tselectBlock( startingBlockClientId );\n\t\t\tsetBlockMovingClientId( null );\n\t\t}\n\t\tif ( navigateDown || navigateUp || navigateOut || navigateIn ) {\n\t\t\tif ( focusedBlockUid ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectBlock( focusedBlockUid );\n\t\t\t} else if ( isTab && selectedBlockClientId ) {\n\t\t\t\tlet nextTabbable;\n\n\t\t\t\tif ( navigateDown ) {\n\t\t\t\t\tnextTabbable = focus.tabbable.findNext( blockElement );\n\n\t\t\t\t\tif ( ! nextTabbable ) {\n\t\t\t\t\t\tnextTabbable =\n\t\t\t\t\t\t\tblockElement.ownerDocument.defaultView.frameElement;\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextTabbable = focus.tabbable.findPrevious( blockElement );\n\t\t\t\t}\n\n\t\t\t\tif ( nextTabbable ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tnextTabbable.focus();\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst classNames = classnames(\n\t\t'block-editor-block-list__block-selection-button',\n\t\t{\n\t\t\t'is-block-moving-mode': !! blockMovingMode,\n\t\t}\n\t);\n\n\tconst dragHandleLabel = __( 'Drag' );\n\n\treturn (\n\t\t<div className={ classNames }>\n\t\t\t<Flex\n\t\t\t\tjustify=\"center\"\n\t\t\t\tclassName=\"block-editor-block-list__block-selection-button__content\"\n\t\t\t>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } showColors />\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockDraggable clientIds={ [ clientId ] }>\n\t\t\t\t\t\t{ ( draggableProps ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ dragHandle }\n\t\t\t\t\t\t\t\tclassName=\"block-selection-button_drag-handle\"\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\tlabel={ dragHandleLabel }\n\t\t\t\t\t\t\t\t// Should not be able to tab to drag handle as this\n\t\t\t\t\t\t\t\t// button can only be used with a pointer device.\n\t\t\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\t\t\t{ ...draggableProps }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</BlockDraggable>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tonClick={ () => setNavigationMode( false ) }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tclassName=\"block-selection-button_select-button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockTitle clientId={ clientId } />\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\t\t</div>\n\t);\n}\n\nexport default BlockSelectionButton;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-selection-button.js"],"names":["BlockSelectionButton","clientId","rootClientId","blockElement","blockInformation","selected","select","getBlock","getBlockIndex","hasBlockMovingClientId","getBlockListSettings","blockEditorStore","index","name","attributes","blockMovingMode","orientation","setNavigationMode","removeBlock","ref","blockType","label","current","focus","getBlockRootClientId","getClientIdsOfDescendants","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","isNavigationMode","selectBlock","clearSelectedBlock","setBlockMovingClientId","moveBlockToPosition","onKeyDown","event","keyCode","isUp","UP","isDown","DOWN","isLeft","LEFT","isRight","RIGHT","isTab","TAB","isEscape","ESCAPE","isEnter","ENTER","isSpace","SPACE","isShift","shiftKey","BACKSPACE","DELETE","preventDefault","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","navigateUp","navigateDown","navigateOut","navigateIn","focusedBlockUid","startingBlockClientId","defaultPrevented","sourceRoot","destRoot","sourceBlockIndex","destinationBlockIndex","nextTabbable","tabbable","findNext","ownerDocument","defaultView","frameElement","findPrevious","classNames","dragHandleLabel","icon","draggableProps","dragHandle"],"mappings":";;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AAYA;;AAIA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAvCA;AACA;AACA;;AAGA;AACA;AACA;;AAyBA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,oBAAT,OAA0E;AAAA,MAA3C;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAA2C;AACzE,QAAMC,gBAAgB,GAAG,yCAA4BH,QAA5B,CAAzB;AACA,QAAMI,QAAQ,GAAG,qBACdC,MAAF,IAAc;AAAA;;AACb,UAAM;AACLC,MAAAA,QADK;AAELC,MAAAA,aAFK;AAGLC,MAAAA,sBAHK;AAILC,MAAAA;AAJK,QAKFJ,MAAM,CAAEK,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QACC,4BAAC,kBAAD;AAAW,IAAA,IAAI,EAAG7E,gBAAH,aAAGA,gBAAH,uBAAGA,gBAAgB,CAAE+E,IAApC;AAA2C,IAAA,UAAU;AAArD,IADD,CAJD,EAOC,4BAAC,oBAAD,QACC,4BAAC,uBAAD;AAAgB,IAAA,SAAS,EAAG,CAAElF,QAAF;AAA5B,KACKmF,cAAF,IACD,4BAAC,kBAAD;AACC,IAAA,IAAI,EAAGC,iBADR;AAEC,IAAA,SAAS,EAAC,oCAFX;AAGC,mBAAY,MAHb;AAIC,IAAA,KAAK,EAAGH,eAJT,CAKC;AACA;AAND;AAOC,IAAA,QAAQ,EAAC;AAPV,KAQME,cARN,EAFF,CADD,CAPD,EAuBC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,GAAG,EAAGjE,GADP;AAEC,IAAA,OAAO,EAAG,MAAMF,iBAAiB,CAAE,KAAF,CAFlC;AAGC,IAAA,SAAS,EAAGkB,SAHb;AAIC,IAAA,KAAK,EAAGd,KAJT;AAKC,IAAA,SAAS,EAAC;AALX,KAOC,4BAAC,mBAAD;AAAY,IAAA,QAAQ,EAAGpB;AAAvB,IAPD,CADD,CAvBD,CADD,CADD;AAuCA;;eAEcD,oB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { dragHandle } from '@wordpress/icons';\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tBACKSPACE,\n\tDELETE,\n\tUP,\n\tDOWN,\n\tLEFT,\n\tRIGHT,\n\tTAB,\n\tESCAPE,\n\tENTER,\n\tSPACE,\n} from '@wordpress/keycodes';\nimport {\n\tgetBlockType,\n\t__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,\n} from '@wordpress/blocks';\nimport { speak } from '@wordpress/a11y';\nimport { focus } from '@wordpress/dom';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockTitle from '../block-title';\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport BlockDraggable from '../block-draggable';\nimport useBlockDisplayInformation from '../use-block-display-information';\n\n/**\n * Block selection button component, displaying the label of the block. If the block\n * descends from a root block, a button is displayed enabling the user to select\n * the root block.\n *\n * @param {string} props Component props.\n * @param {string} props.clientId Client ID of block.\n *\n * @return {WPComponent} The component to be rendered.\n */\nfunction BlockSelectionButton( { clientId, rootClientId, blockElement } ) {\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst selected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockIndex,\n\t\t\t\thasBlockMovingClientId,\n\t\t\t\tgetBlockListSettings,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst index = getBlockIndex( clientId, rootClientId );\n\t\t\tconst { name, attributes } = getBlock( clientId );\n\t\t\tconst blockMovingMode = hasBlockMovingClientId();\n\t\t\treturn {\n\t\t\t\tindex,\n\t\t\t\tname,\n\t\t\t\tattributes,\n\t\t\t\tblockMovingMode,\n\t\t\t\torientation: getBlockListSettings( rootClientId )?.orientation,\n\t\t\t};\n\t\t},\n\t\t[ clientId, rootClientId ]\n\t);\n\tconst { index, name, attributes, blockMovingMode, orientation } = selected;\n\tconst { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );\n\tconst ref = useRef();\n\n\tconst blockType = getBlockType( name );\n\tconst label = getAccessibleBlockLabel(\n\t\tblockType,\n\t\tattributes,\n\t\tindex + 1,\n\t\torientation\n\t);\n\n\t// Focus the breadcrumb in navigation mode.\n\tuseEffect( () => {\n\t\tref.current.focus();\n\n\t\tspeak( label );\n\t}, [ label ] );\n\n\tconst {\n\t\thasBlockMovingClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockRootClientId,\n\t\tgetClientIdsOfDescendants,\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tisNavigationMode,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tselectBlock,\n\t\tclearSelectedBlock,\n\t\tsetBlockMovingClientId,\n\t\tmoveBlockToPosition,\n\t} = useDispatch( blockEditorStore );\n\n\tfunction onKeyDown( event ) {\n\t\tconst { keyCode } = event;\n\t\tconst isUp = keyCode === UP;\n\t\tconst isDown = keyCode === DOWN;\n\t\tconst isLeft = keyCode === LEFT;\n\t\tconst isRight = keyCode === RIGHT;\n\t\tconst isTab = keyCode === TAB;\n\t\tconst isEscape = keyCode === ESCAPE;\n\t\tconst isEnter = keyCode === ENTER;\n\t\tconst isSpace = keyCode === SPACE;\n\t\tconst isShift = event.shiftKey;\n\n\t\tif ( keyCode === BACKSPACE || keyCode === DELETE ) {\n\t\t\tremoveBlock( clientId );\n\t\t\tevent.preventDefault();\n\t\t\treturn;\n\t\t}\n\n\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\n\t\tconst navigateUp = ( isTab && isShift ) || isUp;\n\t\tconst navigateDown = ( isTab && ! isShift ) || isDown;\n\t\t// Move out of current nesting level (no effect if at root level).\n\t\tconst navigateOut = isLeft;\n\t\t// Move into next nesting level (no effect if the current block has no innerBlocks).\n\t\tconst navigateIn = isRight;\n\n\t\tlet focusedBlockUid;\n\t\tif ( navigateUp ) {\n\t\t\tfocusedBlockUid = selectionBeforeEndClientId;\n\t\t} else if ( navigateDown ) {\n\t\t\tfocusedBlockUid = selectionAfterEndClientId;\n\t\t} else if ( navigateOut ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetBlockRootClientId( selectedBlockClientId ) ??\n\t\t\t\tselectedBlockClientId;\n\t\t} else if ( navigateIn ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetClientIdsOfDescendants( [ selectedBlockClientId ] )[ 0 ] ??\n\t\t\t\tselectedBlockClientId;\n\t\t}\n\t\tconst startingBlockClientId = hasBlockMovingClientId();\n\t\tif ( isEscape && isNavigationMode() ) {\n\t\t\tclearSelectedBlock();\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( isEscape && startingBlockClientId && ! event.defaultPrevented ) {\n\t\t\tsetBlockMovingClientId( null );\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( ( isEnter || isSpace ) && startingBlockClientId ) {\n\t\t\tconst sourceRoot = getBlockRootClientId( startingBlockClientId );\n\t\t\tconst destRoot = getBlockRootClientId( selectedBlockClientId );\n\t\t\tconst sourceBlockIndex = getBlockIndex(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot\n\t\t\t);\n\t\t\tlet destinationBlockIndex = getBlockIndex(\n\t\t\t\tselectedBlockClientId,\n\t\t\t\tdestRoot\n\t\t\t);\n\t\t\tif (\n\t\t\t\tsourceBlockIndex < destinationBlockIndex &&\n\t\t\t\tsourceRoot === destRoot\n\t\t\t) {\n\t\t\t\tdestinationBlockIndex -= 1;\n\t\t\t}\n\t\t\tmoveBlockToPosition(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot,\n\t\t\t\tdestRoot,\n\t\t\t\tdestinationBlockIndex\n\t\t\t);\n\t\t\tselectBlock( startingBlockClientId );\n\t\t\tsetBlockMovingClientId( null );\n\t\t}\n\t\tif ( navigateDown || navigateUp || navigateOut || navigateIn ) {\n\t\t\tif ( focusedBlockUid ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectBlock( focusedBlockUid );\n\t\t\t} else if ( isTab && selectedBlockClientId ) {\n\t\t\t\tlet nextTabbable;\n\n\t\t\t\tif ( navigateDown ) {\n\t\t\t\t\tnextTabbable = focus.tabbable.findNext( blockElement );\n\n\t\t\t\t\tif ( ! nextTabbable ) {\n\t\t\t\t\t\tnextTabbable =\n\t\t\t\t\t\t\tblockElement.ownerDocument.defaultView.frameElement;\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextTabbable = focus.tabbable.findPrevious( blockElement );\n\t\t\t\t}\n\n\t\t\t\tif ( nextTabbable ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tnextTabbable.focus();\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst classNames = classnames(\n\t\t'block-editor-block-list__block-selection-button',\n\t\t{\n\t\t\t'is-block-moving-mode': !! blockMovingMode,\n\t\t}\n\t);\n\n\tconst dragHandleLabel = __( 'Drag' );\n\n\treturn (\n\t\t<div className={ classNames }>\n\t\t\t<Flex\n\t\t\t\tjustify=\"center\"\n\t\t\t\tclassName=\"block-editor-block-list__block-selection-button__content\"\n\t\t\t>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } showColors />\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockDraggable clientIds={ [ clientId ] }>\n\t\t\t\t\t\t{ ( draggableProps ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ dragHandle }\n\t\t\t\t\t\t\t\tclassName=\"block-selection-button_drag-handle\"\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\tlabel={ dragHandleLabel }\n\t\t\t\t\t\t\t\t// Should not be able to tab to drag handle as this\n\t\t\t\t\t\t\t\t// button can only be used with a pointer device.\n\t\t\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\t\t\t{ ...draggableProps }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</BlockDraggable>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tonClick={ () => setNavigationMode( false ) }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tclassName=\"block-selection-button_select-button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockTitle clientId={ clientId } />\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\t\t</div>\n\t);\n}\n\nexport default BlockSelectionButton;\n"]}
|
|
@@ -31,7 +31,7 @@ var _useSetting = _interopRequireDefault(require("../use-setting"));
|
|
|
31
31
|
/**
|
|
32
32
|
* Internal dependencies
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
/**
|
|
36
36
|
* Higher order component factory for injecting the `colorsArray` argument as
|
|
37
37
|
* the colors prop in the `withCustomColors` HOC.
|
|
@@ -40,7 +40,6 @@ const DEFAULT_COLORS = [];
|
|
|
40
40
|
*
|
|
41
41
|
* @return {Function} The higher order component.
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
43
|
const withCustomColorPalette = colorsArray => (0, _compose.createHigherOrderComponent)(WrappedComponent => props => (0, _element.createElement)(WrappedComponent, (0, _extends2.default)({}, props, {
|
|
45
44
|
colors: colorsArray
|
|
46
45
|
})), 'withCustomColorPalette');
|
|
@@ -53,9 +52,15 @@ const withCustomColorPalette = colorsArray => (0, _compose.createHigherOrderComp
|
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
const withEditorColorPalette = () => (0, _compose.createHigherOrderComponent)(WrappedComponent => props => {
|
|
56
|
-
|
|
55
|
+
// Some color settings have a special handling for deprecated flags in `useSetting`,
|
|
56
|
+
// so we can't unwrap them by doing const { ... } = useSetting('color')
|
|
57
|
+
// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
|
|
58
|
+
const userPalette = (0, _useSetting.default)('color.palette.custom');
|
|
59
|
+
const themePalette = (0, _useSetting.default)('color.palette.theme');
|
|
60
|
+
const defaultPalette = (0, _useSetting.default)('color.palette.default');
|
|
61
|
+
const allColors = (0, _element.useMemo)(() => [...(userPalette || []), ...(themePalette || []), ...(defaultPalette || [])], [userPalette, themePalette, defaultPalette]);
|
|
57
62
|
return (0, _element.createElement)(WrappedComponent, (0, _extends2.default)({}, props, {
|
|
58
|
-
colors:
|
|
63
|
+
colors: allColors
|
|
59
64
|
}));
|
|
60
65
|
}, 'withEditorColorPalette');
|
|
61
66
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/with-colors.js"],"names":["DEFAULT_COLORS","withCustomColorPalette","colorsArray","WrappedComponent","props","withEditorColorPalette","colors","createColorHOC","colorTypes","withColorPalette","colorMap","colorObject","colorType","Component","constructor","setters","createSetters","colorUtils","getMostReadableColor","bind","state","colorValue","settersAccumulator","colorContext","colorAttributeName","upperFirstColorAttributeName","customColorAttributeName","createSetColor","setAttributes","slug","undefined","getDerivedStateFromProps","previousState","attributes","newState","previousColorObject","previousColor","color","class","render","createCustomColorsHOC","withColors"],"mappings":";;;;;;;;;;AAQA;;;;AALA;;AAMA;;AAKA;;AAMA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AASA,MAAMA,cAAc,GAAG,EAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,WAAF,IAC9B,yCACGC,gBAAF,IAA0BC,KAAF,IACvB,4BAAC,gBAAD,6BAAuBA,KAAvB;AAA+B,EAAA,MAAM,EAAGF;AAAxC,GAFF,EAIC,wBAJD,CADD;AAQA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,sBAAsB,GAAG,MAC9B,yCACGF,gBAAF,IAA0BC,KAAF,IAAa;AACpC,QAAME,MAAM,GAAG,yBAAY,eAAZ,KAAiCN,cAAhD;AACA,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,8BACNf,YADM,EAENZ,WAAW,CAACkB,IAFN;AAFyB,aAAjC;AAOA;;AACD,iBAAOK,QAAP;AACA,SAtCK,EAuCN,EAvCM,CAAP;AAyCA;;AAEDK,MAAAA,MAAM,GAAG;AACR,eACC,4BAAC,gBAAD,6BAEK,KAAKnC,KAFV;AAGEE,UAAAA,MAAM,EAAEwB;AAHV,WAIK,KAAKV,KAJV,EAKK,KAAKL,OALV;AAMEE,UAAAA,UAAU,EAAE,KAAKA;AANnB,WADD;AAWA;;AAzH6B,KAA/B;AA2HA,GA9Hc,CAAT,CAAP;AAgIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASuB,qBAAT,CAAgCtC,WAAhC,EAA8C;AACpD,SAAO,YAAqB;AAC3B,UAAMO,gBAAgB,GAAGR,sBAAsB,CAAEC,WAAF,CAA/C;;AAD2B,sCAAhBM,UAAgB;AAAhBA,MAAAA,UAAgB;AAAA;;AAE3B,WAAO,yCACND,cAAc,CAAEC,UAAF,EAAcC,gBAAd,CADR,EAEN,kBAFM,CAAP;AAIA,GAND;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASgC,UAAT,GAAqC;AACnD,QAAMhC,gBAAgB,GAAGJ,sBAAsB,EAA/C;;AADmD,qCAAbG,UAAa;AAAbA,IAAAA,UAAa;AAAA;;AAEnD,SAAO,yCACND,cAAc,CAAEC,UAAF,EAAcC,gBAAd,CADR,EAEN,YAFM,CAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { isString, kebabCase, reduce, upperFirst } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport useSetting from '../use-setting';\n\nconst DEFAULT_COLORS = [];\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => (\n\t\t\t<WrappedComponent { ...props } colors={ colorsArray } />\n\t\t),\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\tconst colors = useSetting( 'color.palette' ) || DEFAULT_COLORS;\n\t\t\treturn <WrappedComponent { ...props } colors={ colors } />;\n\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {WPComponent} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = reduce(\n\t\tcolorTypes,\n\t\t( colorObject, colorType ) => {\n\t\t\treturn {\n\t\t\t\t...colorObject,\n\t\t\t\t...( isString( colorType )\n\t\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t\t: colorType ),\n\t\t\t};\n\t\t},\n\t\t{}\n\t);\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn class extends Component {\n\t\t\t\tconstructor( props ) {\n\t\t\t\t\tsuper( props );\n\n\t\t\t\t\tthis.setters = this.createSetters();\n\t\t\t\t\tthis.colorUtils = {\n\t\t\t\t\t\tgetMostReadableColor: this.getMostReadableColor.bind(\n\t\t\t\t\t\t\tthis\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.state = {};\n\t\t\t\t}\n\n\t\t\t\tgetMostReadableColor( colorValue ) {\n\t\t\t\t\tconst { colors } = this.props;\n\t\t\t\t\treturn getMostReadableColor( colors, colorValue );\n\t\t\t\t}\n\n\t\t\t\tcreateSetters() {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsettersAccumulator,\n\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst upperFirstColorAttributeName = upperFirst(\n\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst customColorAttributeName = `custom${ upperFirstColorAttributeName }`;\n\t\t\t\t\t\t\tsettersAccumulator[\n\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`\n\t\t\t\t\t\t\t] = this.createSetColor(\n\t\t\t\t\t\t\t\tcolorAttributeName,\n\t\t\t\t\t\t\t\tcustomColorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn settersAccumulator;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcreateSetColor( colorAttributeName, customColorAttributeName ) {\n\t\t\t\t\treturn ( colorValue ) => {\n\t\t\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\t\t\tthis.props.colors,\n\t\t\t\t\t\t\tcolorValue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.props.setAttributes( {\n\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? colorObject.slug\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t[ customColorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: colorValue,\n\t\t\t\t\t\t} );\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstatic getDerivedStateFromProps(\n\t\t\t\t\t{ attributes, colors },\n\t\t\t\t\tpreviousState\n\t\t\t\t) {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t( newState, colorContext, colorAttributeName ) => {\n\t\t\t\t\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\tattributes[\n\t\t\t\t\t\t\t\t\t`custom${ upperFirst(\n\t\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t\t) }`\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst previousColorObject =\n\t\t\t\t\t\t\t\tpreviousState[ colorAttributeName ];\n\t\t\t\t\t\t\tconst previousColor = previousColorObject?.color;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The \"and previousColorObject\" condition checks that a previous color object was already computed.\n\t\t\t\t\t\t\t * At the start previousColorObject and colorValue are both equal to undefined\n\t\t\t\t\t\t\t * bus as previousColorObject does not exist we should compute the object.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpreviousColor === colorObject.color &&\n\t\t\t\t\t\t\t\tpreviousColorObject\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnewState[\n\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t] = previousColorObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] = {\n\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn newState;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\trender() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t...this.props,\n\t\t\t\t\t\t\t\tcolors: undefined,\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\t...this.setters,\n\t\t\t\t\t\t\t\tcolorUtils: this.colorUtils,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/with-colors.js"],"names":["withCustomColorPalette","colorsArray","WrappedComponent","props","withEditorColorPalette","userPalette","themePalette","defaultPalette","allColors","createColorHOC","colorTypes","withColorPalette","colorMap","colorObject","colorType","Component","constructor","setters","createSetters","colorUtils","getMostReadableColor","bind","state","colorValue","colors","settersAccumulator","colorContext","colorAttributeName","upperFirstColorAttributeName","customColorAttributeName","createSetColor","setAttributes","slug","undefined","getDerivedStateFromProps","previousState","attributes","newState","previousColorObject","previousColor","color","class","render","createCustomColorsHOC","withColors"],"mappings":";;;;;;;;;;AAQA;;;;AALA;;AAMA;;AAKA;;AAMA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAKC,WAAF,IAC9B,yCACGC,gBAAF,IAA0BC,KAAF,IACvB,4BAAC,gBAAD,6BAAuBA,KAAvB;AAA+B,EAAA,MAAM,EAAGF;AAAx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M,CAAP;AAIA,GAND;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASiC,UAAT,GAAqC;AACnD,QAAMjC,gBAAgB,GAAGP,sBAAsB,EAA/C;;AADmD,qCAAbM,UAAa;AAAbA,IAAAA,UAAa;AAAA;;AAEnD,SAAO,yCACND,cAAc,CAAEC,UAAF,EAAcC,gBAAd,CADR,EAEN,YAFM,CAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { isString, kebabCase, reduce, upperFirst } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, Component } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport useSetting from '../use-setting';\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => (\n\t\t\t<WrappedComponent { ...props } colors={ colorsArray } />\n\t\t),\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\t// Some color settings have a special handling for deprecated flags in `useSetting`,\n\t\t\t// so we can't unwrap them by doing const { ... } = useSetting('color')\n\t\t\t// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.\n\t\t\tconst userPalette = useSetting( 'color.palette.custom' );\n\t\t\tconst themePalette = useSetting( 'color.palette.theme' );\n\t\t\tconst defaultPalette = useSetting( 'color.palette.default' );\n\t\t\tconst allColors = useMemo(\n\t\t\t\t() => [\n\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t],\n\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t);\n\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {WPComponent} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = reduce(\n\t\tcolorTypes,\n\t\t( colorObject, colorType ) => {\n\t\t\treturn {\n\t\t\t\t...colorObject,\n\t\t\t\t...( isString( colorType )\n\t\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t\t: colorType ),\n\t\t\t};\n\t\t},\n\t\t{}\n\t);\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn class extends Component {\n\t\t\t\tconstructor( props ) {\n\t\t\t\t\tsuper( props );\n\n\t\t\t\t\tthis.setters = this.createSetters();\n\t\t\t\t\tthis.colorUtils = {\n\t\t\t\t\t\tgetMostReadableColor: this.getMostReadableColor.bind(\n\t\t\t\t\t\t\tthis\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.state = {};\n\t\t\t\t}\n\n\t\t\t\tgetMostReadableColor( colorValue ) {\n\t\t\t\t\tconst { colors } = this.props;\n\t\t\t\t\treturn getMostReadableColor( colors, colorValue );\n\t\t\t\t}\n\n\t\t\t\tcreateSetters() {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsettersAccumulator,\n\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst upperFirstColorAttributeName = upperFirst(\n\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst customColorAttributeName = `custom${ upperFirstColorAttributeName }`;\n\t\t\t\t\t\t\tsettersAccumulator[\n\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`\n\t\t\t\t\t\t\t] = this.createSetColor(\n\t\t\t\t\t\t\t\tcolorAttributeName,\n\t\t\t\t\t\t\t\tcustomColorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn settersAccumulator;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcreateSetColor( colorAttributeName, customColorAttributeName ) {\n\t\t\t\t\treturn ( colorValue ) => {\n\t\t\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\t\t\tthis.props.colors,\n\t\t\t\t\t\t\tcolorValue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.props.setAttributes( {\n\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? colorObject.slug\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t[ customColorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: colorValue,\n\t\t\t\t\t\t} );\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstatic getDerivedStateFromProps(\n\t\t\t\t\t{ attributes, colors },\n\t\t\t\t\tpreviousState\n\t\t\t\t) {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t( newState, colorContext, colorAttributeName ) => {\n\t\t\t\t\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\tattributes[\n\t\t\t\t\t\t\t\t\t`custom${ upperFirst(\n\t\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t\t) }`\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst previousColorObject =\n\t\t\t\t\t\t\t\tpreviousState[ colorAttributeName ];\n\t\t\t\t\t\t\tconst previousColor = previousColorObject?.color;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The \"and previousColorObject\" condition checks that a previous color object was already computed.\n\t\t\t\t\t\t\t * At the start previousColorObject and colorValue are both equal to undefined\n\t\t\t\t\t\t\t * bus as previousColorObject does not exist we should compute the object.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpreviousColor === colorObject.color &&\n\t\t\t\t\t\t\t\tpreviousColorObject\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnewState[\n\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t] = previousColorObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] = {\n\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn newState;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\trender() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t...this.props,\n\t\t\t\t\t\t\t\tcolors: undefined,\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\t...this.setters,\n\t\t\t\t\t\t\t\tcolorUtils: this.colorUtils,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"]}
|
|
@@ -41,6 +41,7 @@ function ColorGradientControlInner(_ref) {
|
|
|
41
41
|
disableCustomColors,
|
|
42
42
|
disableCustomGradients,
|
|
43
43
|
__experimentalHasMultipleOrigins,
|
|
44
|
+
__experimentalIsRenderedInSidebar,
|
|
44
45
|
className,
|
|
45
46
|
label,
|
|
46
47
|
onColorChange,
|
|
@@ -48,7 +49,8 @@ function ColorGradientControlInner(_ref) {
|
|
|
48
49
|
colorValue,
|
|
49
50
|
gradientValue,
|
|
50
51
|
clearable,
|
|
51
|
-
showTitle = true
|
|
52
|
+
showTitle = true,
|
|
53
|
+
enableAlpha
|
|
52
54
|
} = _ref;
|
|
53
55
|
const canChooseAColor = onColorChange && (!(0, _lodash.isEmpty)(colors) || !disableCustomColors);
|
|
54
56
|
const canChooseAGradient = onGradientChange && (!(0, _lodash.isEmpty)(gradients) || !disableCustomGradients);
|
|
@@ -85,7 +87,9 @@ function ColorGradientControlInner(_ref) {
|
|
|
85
87
|
colors,
|
|
86
88
|
disableCustomColors,
|
|
87
89
|
__experimentalHasMultipleOrigins: __experimentalHasMultipleOrigins,
|
|
88
|
-
|
|
90
|
+
__experimentalIsRenderedInSidebar: __experimentalIsRenderedInSidebar,
|
|
91
|
+
clearable: clearable,
|
|
92
|
+
enableAlpha: enableAlpha
|
|
89
93
|
}), (currentTab === 'gradient' || !canChooseAColor) && (0, _element.createElement)(_components.GradientPicker, {
|
|
90
94
|
value: gradientValue,
|
|
91
95
|
onChange: canChooseAColor ? newGradient => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/control.js"],"names":["colorsAndGradientKeys","ColorGradientControlInner","colors","gradients","disableCustomColors","disableCustomGradients","__experimentalHasMultipleOrigins","className","label","onColorChange","onGradientChange","colorValue","gradientValue","clearable","showTitle","canChooseAColor","canChooseAGradient","currentTab","setCurrentTab","newColor","newGradient","ColorGradientControlSelect","props","colorGradientSettings","ColorGradientControl","key","hasOwnProperty"],"mappings":";;;;;;;;;AASA;;;;AANA;;AACA;;AAMA;;AAQA;;AAKA;;AAvBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AAGA,MAAMA,qBAAqB,GAAG,CAC7B,QAD6B,EAE7B,qBAF6B,EAG7B,WAH6B,EAI7B,wBAJ6B,CAA9B;;AAOA,SAASC,yBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/control.js"],"names":["colorsAndGradientKeys","ColorGradientControlInner","colors","gradients","disableCustomColors","disableCustomGradients","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","className","label","onColorChange","onGradientChange","colorValue","gradientValue","clearable","showTitle","enableAlpha","canChooseAColor","canChooseAGradient","currentTab","setCurrentTab","newColor","newGradient","ColorGradientControlSelect","props","colorGradientSettings","ColorGradientControl","key","hasOwnProperty"],"mappings":";;;;;;;;;AASA;;;;AANA;;AACA;;AAMA;;AAQA;;AAKA;;AAvBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AAGA,MAAMA,qBAAqB,GAAG,CAC7B,QAD6B,EAE7B,qBAF6B,EAG7B,WAH6B,EAI7B,wBAJ6B,CAA9B;;AAOA,SAASC,yBAAT,OAgBI;AAAA,MAhBgC;AACnCC,IAAAA,MADmC;AAEnCC,IAAAA,SAFmC;AAGnCC,IAAAA,mBAHmC;AAInCC,IAAAA,sBAJmC;AAKnCC,IAAAA,gCALmC;AAMnCC,IAAAA,iCANmC;AAOnCC,IAAAA,SAPmC;AAQnCC,IAAAA,KARmC;AASnCC,IAAAA,aATmC;AAUnCC,IAAAA,gBAVmC;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qBAAP,EAAgC2B,GAAF,IAAWH,KAAK,CAACI,cAAN,CAAsBD,GAAtB,CAAzC,CADD,EAEE;AACD,WAAO,4BAAC,yBAAD,EAAgCH,KAAhC,CAAP;AACA;;AACD,SAAO,4BAAC,0BAAD,EAAiCA,KAAjC,CAAP;AACA;;eAEcE,oB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { every, isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport {\n\tBaseControl,\n\t__experimentalVStack as VStack,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\tColorPalette,\n\tGradientPicker,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\n\nconst colorsAndGradientKeys = [\n\t'colors',\n\t'disableCustomColors',\n\t'gradients',\n\t'disableCustomGradients',\n];\n\nfunction ColorGradientControlInner( {\n\tcolors,\n\tgradients,\n\tdisableCustomColors,\n\tdisableCustomGradients,\n\t__experimentalHasMultipleOrigins,\n\t__experimentalIsRenderedInSidebar,\n\tclassName,\n\tlabel,\n\tonColorChange,\n\tonGradientChange,\n\tcolorValue,\n\tgradientValue,\n\tclearable,\n\tshowTitle = true,\n\tenableAlpha,\n} ) {\n\tconst canChooseAColor =\n\t\tonColorChange && ( ! isEmpty( colors ) || ! disableCustomColors );\n\tconst canChooseAGradient =\n\t\tonGradientChange &&\n\t\t( ! isEmpty( gradients ) || ! disableCustomGradients );\n\tconst [ currentTab, setCurrentTab ] = useState(\n\t\tgradientValue ? 'gradient' : !! canChooseAColor && 'color'\n\t);\n\n\tif ( ! canChooseAColor && ! canChooseAGradient ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<BaseControl\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-color-gradient-control',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t<fieldset>\n\t\t\t\t<VStack spacing={ 1 }>\n\t\t\t\t\t{ showTitle && (\n\t\t\t\t\t\t<legend>\n\t\t\t\t\t\t\t<div className=\"block-editor-color-gradient-control__color-indicator\">\n\t\t\t\t\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</legend>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canChooseAColor && canChooseAGradient && (\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\tvalue={ currentTab }\n\t\t\t\t\t\t\tonChange={ setCurrentTab }\n\t\t\t\t\t\t\tlabel={ __( 'Select color type' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"color\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Solid' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"gradient\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Gradient' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ( currentTab === 'color' || ! canChooseAGradient ) && (\n\t\t\t\t\t\t<ColorPalette\n\t\t\t\t\t\t\tvalue={ colorValue }\n\t\t\t\t\t\t\tonChange={\n\t\t\t\t\t\t\t\tcanChooseAGradient\n\t\t\t\t\t\t\t\t\t? ( newColor ) => {\n\t\t\t\t\t\t\t\t\t\t\tonColorChange( newColor );\n\t\t\t\t\t\t\t\t\t\t\tonGradientChange();\n\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t: onColorChange\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{ ...{ colors, disableCustomColors } }\n\t\t\t\t\t\t\t__experimentalHasMultipleOrigins={\n\t\t\t\t\t\t\t\t__experimentalHasMultipleOrigins\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t__experimentalIsRenderedInSidebar={\n\t\t\t\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tclearable={ clearable }\n\t\t\t\t\t\t\tenableAlpha={ enableAlpha }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ( currentTab === 'gradient' || ! canChooseAColor ) && (\n\t\t\t\t\t\t<GradientPicker\n\t\t\t\t\t\t\tvalue={ gradientValue }\n\t\t\t\t\t\t\tonChange={\n\t\t\t\t\t\t\t\tcanChooseAColor\n\t\t\t\t\t\t\t\t\t? ( newGradient ) => {\n\t\t\t\t\t\t\t\t\t\t\tonGradientChange( newGradient );\n\t\t\t\t\t\t\t\t\t\t\tonColorChange();\n\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t: onGradientChange\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{ ...{ gradients, disableCustomGradients } }\n\t\t\t\t\t\t\t__experimentalHasMultipleOrigins={\n\t\t\t\t\t\t\t\t__experimentalHasMultipleOrigins\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tclearable={ clearable }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</VStack>\n\t\t\t</fieldset>\n\t\t</BaseControl>\n\t);\n}\n\nfunction ColorGradientControlSelect( props ) {\n\tconst colorGradientSettings = {};\n\tcolorGradientSettings.colors = useSetting( 'color.palette' );\n\tcolorGradientSettings.gradients = useSetting( 'color.gradients' );\n\tcolorGradientSettings.disableCustomColors = ! useSetting( 'color.custom' );\n\tcolorGradientSettings.disableCustomGradients = ! useSetting(\n\t\t'color.customGradient'\n\t);\n\n\treturn (\n\t\t<ColorGradientControlInner\n\t\t\t{ ...{ ...colorGradientSettings, ...props } }\n\t\t/>\n\t);\n}\n\nfunction ColorGradientControl( props ) {\n\tif (\n\t\tevery( colorsAndGradientKeys, ( key ) => props.hasOwnProperty( key ) )\n\t) {\n\t\treturn <ColorGradientControlInner { ...props } />;\n\t}\n\treturn <ColorGradientControlSelect { ...props } />;\n}\n\nexport default ColorGradientControl;\n"]}
|
|
@@ -27,6 +27,10 @@ var _gradients = require("../gradients");
|
|
|
27
27
|
|
|
28
28
|
var _useSetting = _interopRequireDefault(require("../use-setting"));
|
|
29
29
|
|
|
30
|
+
var _useCommonSingleMultipleSelects = _interopRequireDefault(require("./use-common-single-multiple-selects"));
|
|
31
|
+
|
|
32
|
+
var _useMultipleOriginColorsAndGradients = _interopRequireDefault(require("./use-multiple-origin-colors-and-gradients"));
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* External dependencies
|
|
32
36
|
*/
|
|
@@ -93,6 +97,8 @@ const PanelColorGradientSettingsInner = _ref3 => {
|
|
|
93
97
|
title,
|
|
94
98
|
showTitle = true,
|
|
95
99
|
__experimentalHasMultipleOrigins,
|
|
100
|
+
__experimentalIsRenderedInSidebar,
|
|
101
|
+
enableAlpha,
|
|
96
102
|
...props
|
|
97
103
|
} = _ref3;
|
|
98
104
|
|
|
@@ -117,88 +123,23 @@ const PanelColorGradientSettingsInner = _ref3 => {
|
|
|
117
123
|
gradients,
|
|
118
124
|
disableCustomColors,
|
|
119
125
|
disableCustomGradients,
|
|
120
|
-
__experimentalHasMultipleOrigins
|
|
126
|
+
__experimentalHasMultipleOrigins,
|
|
127
|
+
__experimentalIsRenderedInSidebar,
|
|
128
|
+
enableAlpha
|
|
121
129
|
}, setting))), children);
|
|
122
130
|
};
|
|
123
131
|
|
|
124
132
|
exports.PanelColorGradientSettingsInner = PanelColorGradientSettingsInner;
|
|
125
133
|
|
|
126
|
-
function useCommonSingleMultipleSelects() {
|
|
127
|
-
return {
|
|
128
|
-
disableCustomColors: !(0, _useSetting.default)('color.custom'),
|
|
129
|
-
disableCustomGradients: !(0, _useSetting.default)('color.customGradient')
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
134
|
const PanelColorGradientSettingsSingleSelect = props => {
|
|
134
|
-
const colorGradientSettings =
|
|
135
|
+
const colorGradientSettings = (0, _useCommonSingleMultipleSelects.default)();
|
|
135
136
|
colorGradientSettings.colors = (0, _useSetting.default)('color.palette');
|
|
136
137
|
colorGradientSettings.gradients = (0, _useSetting.default)('color.gradients');
|
|
137
138
|
return (0, _element.createElement)(PanelColorGradientSettingsInner, (0, _extends2.default)({}, colorGradientSettings, props));
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
const PanelColorGradientSettingsMultipleSelect = props => {
|
|
141
|
-
const colorGradientSettings =
|
|
142
|
-
const customColors = (0, _useSetting.default)('color.palette.user');
|
|
143
|
-
const themeColors = (0, _useSetting.default)('color.palette.theme');
|
|
144
|
-
const defaultColors = (0, _useSetting.default)('color.palette.default');
|
|
145
|
-
const shouldDisplayDefaultColors = (0, _useSetting.default)('color.defaultPalette');
|
|
146
|
-
colorGradientSettings.colors = (0, _element.useMemo)(() => {
|
|
147
|
-
const result = [];
|
|
148
|
-
|
|
149
|
-
if (themeColors && themeColors.length) {
|
|
150
|
-
result.push({
|
|
151
|
-
name: (0, _i18n._x)('Theme', 'Indicates this palette comes from the theme.'),
|
|
152
|
-
colors: themeColors
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (shouldDisplayDefaultColors && defaultColors && defaultColors.length) {
|
|
157
|
-
result.push({
|
|
158
|
-
name: (0, _i18n._x)('Default', 'Indicates this palette comes from WordPress.'),
|
|
159
|
-
colors: defaultColors
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (customColors && customColors.length) {
|
|
164
|
-
result.push({
|
|
165
|
-
name: (0, _i18n._x)('Custom', 'Indicates this palette comes from the theme.'),
|
|
166
|
-
colors: customColors
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
}, [defaultColors, themeColors, customColors]);
|
|
172
|
-
const customGradients = (0, _useSetting.default)('color.gradients.user');
|
|
173
|
-
const themeGradients = (0, _useSetting.default)('color.gradients.theme');
|
|
174
|
-
const defaultGradients = (0, _useSetting.default)('color.gradients.default');
|
|
175
|
-
const shouldDisplayDefaultGradients = (0, _useSetting.default)('color.defaultGradients');
|
|
176
|
-
colorGradientSettings.gradients = (0, _element.useMemo)(() => {
|
|
177
|
-
const result = [];
|
|
178
|
-
|
|
179
|
-
if (themeGradients && themeGradients.length) {
|
|
180
|
-
result.push({
|
|
181
|
-
name: (0, _i18n._x)('Theme', 'Indicates this palette comes from the theme.'),
|
|
182
|
-
gradients: themeGradients
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (shouldDisplayDefaultGradients && defaultGradients && defaultGradients.length) {
|
|
187
|
-
result.push({
|
|
188
|
-
name: (0, _i18n._x)('Default', 'Indicates this palette comes from WordPress.'),
|
|
189
|
-
gradients: defaultGradients
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (customGradients && customGradients.length) {
|
|
194
|
-
result.push({
|
|
195
|
-
name: (0, _i18n._x)('Custom', 'Indicates this palette is created by the user.'),
|
|
196
|
-
gradients: customGradients
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return result;
|
|
201
|
-
}, [customGradients, themeGradients, defaultGradients]);
|
|
142
|
+
const colorGradientSettings = (0, _useMultipleOriginColorsAndGradients.default)();
|
|
202
143
|
return (0, _element.createElement)(PanelColorGradientSettingsInner, (0, _extends2.default)({}, colorGradientSettings, props));
|
|
203
144
|
};
|
|
204
145
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js"],"names":["colorIndicatorAriaLabel","gradientIndicatorAriaLabel","colorsAndGradientKeys","Indicators","colors","gradients","settings","map","index","colorValue","gradientValue","label","availableColors","availableGradients","ariaLabel","colorObject","toLowerCase","name","gradientObject","PanelColorGradientSettingsInner","className","disableCustomColors","disableCustomGradients","children","title","showTitle","__experimentalHasMultipleOrigins","props","setting","undefined","titleElement","useCommonSingleMultipleSelects","PanelColorGradientSettingsSingleSelect","colorGradientSettings","PanelColorGradientSettingsMultipleSelect","customColors","themeColors","defaultColors","shouldDisplayDefaultColors","result","length","push","customGradients","themeGradients","defaultGradients","shouldDisplayDefaultGradients","PanelColorGradientSettings","key","hasOwnProperty"],"mappings":";;;;;;;;;AAWA;;;;AARA;;AACA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AAnBA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AAMA;AACA,MAAMA,uBAAuB,GAAG,cAAI,gBAAJ,CAAhC,C,CAEA;;AACA,MAAMC,0BAA0B,GAAG,cAAI,mBAAJ,CAAnC;AAEA,MAAMC,qBAAqB,GAAG,CAC7B,QAD6B,EAE7B,qBAF6B,EAG7B,WAH6B,EAI7B,wBAJ6B,CAA9B;;AAOA,MAAMC,UAAU,GAAG,QAAuC;AAAA,MAArC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,SAAV;AAAqBC,IAAAA;AAArB,GAAqC;AACzD,SAAOA,QAAQ,CAACC,GAAT,CACN,QAQCC,KARD,KASK;AAAA,QARJ;AACCC,MAAAA,UADD;AAECC,MAAAA,aAFD;AAGCC,MAAAA,KAHD;AAICP,MAAAA,MAAM,EAAEQ,eAJT;AAKCP,MAAAA,SAAS,EAAEQ;AALZ,KAQI;;AACJ,QAAK,CAAEJ,UAAF,IAAgB,CAAEC,aAAvB,EAAuC;AACtC,aAAO,IAAP;AACA;;AACD,QAAII,SAAJ;;AACA,QAAKL,UAAL,EAAkB;AACjB,YAAMM,WAAW,GAAG,wCACnBH,eAAe,IAAIR,MADA,EAEnBK,UAFmB,CAApB;AAIAK,MAAAA,SAAS,GAAG,mBACX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AAP,CAAa;AACZxB,QAAAA,IAAI,EAAE,cACL,OADK,EAEL,8CAFK,CADM;AAKZZ,QAAAA,SAAS,EAAEsC;AALC,OAAb;AAOA;;AACD,QACCE,6BAA6B,IAC7BD,gBADA,IAEAA,gBAAgB,CAACJ,MAHlB,EAIE;AACDD,MAAAA,MAAM,CAACE,IAAP,CAAa;AACZxB,QAAAA,IAAI,EAAE,cACL,SADK,EAEL,8CAFK,CADM;AAKZZ,QAAAA,SAAS,EAAEuC;AALC,OAAb;AAOA;;AACD,QAAKF,eAAe,IAAIA,eAAe,CAACF,MAAxC,EAAiD;AAChDD,MAAAA,MAAM,CAACE,IAAP,CAAa;AACZxB,QAAAA,IAAI,EAAE,cACL,QADK,EAEL,gDAFK,CADM;AAKZZ,QAAAA,SAAS,EAAEqC;AALC,OAAb;AAOA;;AACD,WAAOH,MAAP;AACA,GAlCiC,EAkC/B,CAAEG,eAAF,EAAmBC,cAAnB,EAAmCC,gBAAnC,CAlC+B,CAAlC;AAmCA,SACC,4BAAC,+BAAD,6BACWX,qBADX,EACqCN,KADrC,EADD;AAKA,CAzFD;;AA2FA,MAAMmB,0BAA0B,GAAKnB,KAAF,IAAa;AAC/C,MACC,mBAAOzB,qBAAP,EAAgC6C,GAAF,IAAWpB,KAAK,CAACqB,cAAN,CAAsBD,GAAtB,CAAzC,CADD,EAEE;AACD,WAAO,4BAAC,+BAAD,EAAsCpB,KAAtC,CAAP;AACA;;AACD,MAAKA,KAAK,CAACD,gCAAX,EAA8C;AAC7C,WAAO,4BAAC,wCAAD,EAA+CC,KAA/C,CAAP;AACA;;AACD,SAAO,4BAAC,sCAAD,EAA6CA,KAA7C,CAAP;AACA,CAVD;;eAYemB,0B","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { every, isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { PanelBody, ColorIndicator } from '@wordpress/components';\nimport { sprintf, __, _x } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from './control';\nimport { getColorObjectByColorValue } from '../colors';\nimport { __experimentalGetGradientObjectByGradientValue } from '../gradients';\nimport useSetting from '../use-setting';\n\n// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)\nconst colorIndicatorAriaLabel = __( '(%s: color %s)' );\n\n// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)\nconst gradientIndicatorAriaLabel = __( '(%s: gradient %s)' );\n\nconst colorsAndGradientKeys = [\n\t'colors',\n\t'disableCustomColors',\n\t'gradients',\n\t'disableCustomGradients',\n];\n\nconst Indicators = ( { colors, gradients, settings } ) => {\n\treturn settings.map(\n\t\t(\n\t\t\t{\n\t\t\t\tcolorValue,\n\t\t\t\tgradientValue,\n\t\t\t\tlabel,\n\t\t\t\tcolors: availableColors,\n\t\t\t\tgradients: availableGradients,\n\t\t\t},\n\t\t\tindex\n\t\t) => {\n\t\t\tif ( ! colorValue && ! gradientValue ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet ariaLabel;\n\t\t\tif ( colorValue ) {\n\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\tavailableColors || colors,\n\t\t\t\t\tcolorValue\n\t\t\t\t);\n\t\t\t\tariaLabel = sprintf(\n\t\t\t\t\tcolorIndicatorAriaLabel,\n\t\t\t\t\tlabel.toLowerCase(),\n\t\t\t\t\t( colorObject && colorObject.name ) || colorValue\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst gradientObject = __experimentalGetGradientObjectByGradientValue(\n\t\t\t\t\tavailableGradients || gradients,\n\t\t\t\t\tcolorValue\n\t\t\t\t);\n\t\t\t\tariaLabel = sprintf(\n\t\t\t\t\tgradientIndicatorAriaLabel,\n\t\t\t\t\tlabel.toLowerCase(),\n\t\t\t\t\t( gradientObject && gradientObject.name ) || gradientValue\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\t<ColorIndicator\n\t\t\t\t\tkey={ index }\n\t\t\t\t\tcolorValue={ colorValue || gradientValue }\n\t\t\t\t\taria-label={ ariaLabel }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t);\n};\n\nexport const PanelColorGradientSettingsInner = ( {\n\tclassName,\n\tcolors,\n\tgradients,\n\tdisableCustomColors,\n\tdisableCustomGradients,\n\tchildren,\n\tsettings,\n\ttitle,\n\tshowTitle = true,\n\t__experimentalHasMultipleOrigins,\n\t...props\n} ) => {\n\tif (\n\t\tisEmpty( colors ) &&\n\t\tisEmpty( gradients ) &&\n\t\tdisableCustomColors &&\n\t\tdisableCustomGradients &&\n\t\tevery(\n\t\t\tsettings,\n\t\t\t( setting ) =>\n\t\t\t\tisEmpty( setting.colors ) &&\n\t\t\t\tisEmpty( setting.gradients ) &&\n\t\t\t\t( setting.disableCustomColors === undefined ||\n\t\t\t\t\tsetting.disableCustomColors ) &&\n\t\t\t\t( setting.disableCustomGradients === undefined ||\n\t\t\t\t\tsetting.disableCustomGradients )\n\t\t)\n\t) {\n\t\treturn null;\n\t}\n\n\tconst titleElement = (\n\t\t<span className=\"block-editor-panel-color-gradient-settings__panel-title\">\n\t\t\t{ title }\n\t\t\t<Indicators\n\t\t\t\tcolors={ colors }\n\t\t\t\tgradients={ gradients }\n\t\t\t\tsettings={ settings }\n\t\t\t/>\n\t\t</span>\n\t);\n\n\treturn (\n\t\t<PanelBody\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-panel-color-gradient-settings',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t\ttitle={ showTitle ? titleElement : undefined }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ settings.map( ( setting, index ) => (\n\t\t\t\t<ColorGradientControl\n\t\t\t\t\tshowTitle={ showTitle }\n\t\t\t\t\tkey={ index }\n\t\t\t\t\t{ ...{\n\t\t\t\t\t\tcolors,\n\t\t\t\t\t\tgradients,\n\t\t\t\t\t\tdisableCustomColors,\n\t\t\t\t\t\tdisableCustomGradients,\n\t\t\t\t\t\t__experimentalHasMultipleOrigins,\n\t\t\t\t\t\t...setting,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ children }\n\t\t</PanelBody>\n\t);\n};\n\nfunction useCommonSingleMultipleSelects() {\n\treturn {\n\t\tdisableCustomColors: ! useSetting( 'color.custom' ),\n\t\tdisableCustomGradients: ! useSetting( 'color.customGradient' ),\n\t};\n}\n\nconst PanelColorGradientSettingsSingleSelect = ( props ) => {\n\tconst colorGradientSettings = useCommonSingleMultipleSelects();\n\tcolorGradientSettings.colors = useSetting( 'color.palette' );\n\tcolorGradientSettings.gradients = useSetting( 'color.gradients' );\n\treturn (\n\t\t<PanelColorGradientSettingsInner\n\t\t\t{ ...{ ...colorGradientSettings, ...props } }\n\t\t/>\n\t);\n};\n\nconst PanelColorGradientSettingsMultipleSelect = ( props ) => {\n\tconst colorGradientSettings = useCommonSingleMultipleSelects();\n\tconst customColors = useSetting( 'color.palette.user' );\n\tconst themeColors = useSetting( 'color.palette.theme' );\n\tconst defaultColors = useSetting( 'color.palette.default' );\n\tconst shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );\n\n\tcolorGradientSettings.colors = useMemo( () => {\n\t\tconst result = [];\n\t\tif ( themeColors && themeColors.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Theme',\n\t\t\t\t\t'Indicates this palette comes from the theme.'\n\t\t\t\t),\n\t\t\t\tcolors: themeColors,\n\t\t\t} );\n\t\t}\n\t\tif (\n\t\t\tshouldDisplayDefaultColors &&\n\t\t\tdefaultColors &&\n\t\t\tdefaultColors.length\n\t\t) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Default',\n\t\t\t\t\t'Indicates this palette comes from WordPress.'\n\t\t\t\t),\n\t\t\t\tcolors: defaultColors,\n\t\t\t} );\n\t\t}\n\t\tif ( customColors && customColors.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Custom',\n\t\t\t\t\t'Indicates this palette comes from the theme.'\n\t\t\t\t),\n\t\t\t\tcolors: customColors,\n\t\t\t} );\n\t\t}\n\t\treturn result;\n\t}, [ defaultColors, themeColors, customColors ] );\n\n\tconst customGradients = useSetting( 'color.gradients.user' );\n\tconst themeGradients = useSetting( 'color.gradients.theme' );\n\tconst defaultGradients = useSetting( 'color.gradients.default' );\n\tconst shouldDisplayDefaultGradients = useSetting(\n\t\t'color.defaultGradients'\n\t);\n\tcolorGradientSettings.gradients = useMemo( () => {\n\t\tconst result = [];\n\t\tif ( themeGradients && themeGradients.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Theme',\n\t\t\t\t\t'Indicates this palette comes from the theme.'\n\t\t\t\t),\n\t\t\t\tgradients: themeGradients,\n\t\t\t} );\n\t\t}\n\t\tif (\n\t\t\tshouldDisplayDefaultGradients &&\n\t\t\tdefaultGradients &&\n\t\t\tdefaultGradients.length\n\t\t) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Default',\n\t\t\t\t\t'Indicates this palette comes from WordPress.'\n\t\t\t\t),\n\t\t\t\tgradients: defaultGradients,\n\t\t\t} );\n\t\t}\n\t\tif ( customGradients && customGradients.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Custom',\n\t\t\t\t\t'Indicates this palette is created by the user.'\n\t\t\t\t),\n\t\t\t\tgradients: customGradients,\n\t\t\t} );\n\t\t}\n\t\treturn result;\n\t}, [ customGradients, themeGradients, defaultGradients ] );\n\treturn (\n\t\t<PanelColorGradientSettingsInner\n\t\t\t{ ...{ ...colorGradientSettings, ...props } }\n\t\t/>\n\t);\n};\n\nconst PanelColorGradientSettings = ( props ) => {\n\tif (\n\t\tevery( colorsAndGradientKeys, ( key ) => props.hasOwnProperty( key ) )\n\t) {\n\t\treturn <PanelColorGradientSettingsInner { ...props } />;\n\t}\n\tif ( props.__experimentalHasMultipleOrigins ) {\n\t\treturn <PanelColorGradientSettingsMultipleSelect { ...props } />;\n\t}\n\treturn <PanelColorGradientSettingsSingleSelect { ...props } />;\n};\n\nexport default PanelColorGradientSettings;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js"],"names":["colorIndicatorAriaLabel","gradientIndicatorAriaLabel","colorsAndGradientKeys","Indicators","colors","gradients","settings","map","index","colorValue","gradientValue","label","availableColors","availableGradients","ariaLabel","colorObject","toLowerCase","name","gradientObject","PanelColorGradientSettingsInner","className","disableCustomColors","disableCustomGradients","children","title","showTitle","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","enableAlpha","props","setting","undefined","titleElement","PanelColorGradientSettingsSingleSelect","colorGradientSettings","PanelColorGradientSettingsMultipleSelect","PanelColorGradientSettings","key","hasOwnProperty"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AApBA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AAQA;AACA,MAAMA,uBAAuB,GAAG,cAAI,gBAAJ,CAAhC,C,CAEA;;AACA,MAAMC,0BAA0B,GAAG,cAAI,mBAAJ,CAAnC;AAEA,MAAMC,qBAAqB,GAAG,CAC7B,QAD6B,EAE7B,qBAF6B,EAG7B,WAH6B,EAI7B,wBAJ6B,CAA9B;;AAOA,MAAMC,UAAU,GAAG,QAAuC;AAAA,MAArC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,SAAV;AAAqBC,IAAAA;AAArB,GAAqC;AACzD,SAAOA,QAAQ,CAACC,GAAT,CACN,QAQCC,KARD,KASK;AAAA,QARJ;AACCC,MAAAA,UADD;AAECC,MAAAA,aAFD;AAGCC,MAAAA,KAHD;AAICP,MAAAA,MAAM,EAAEQ,eAJT;AAKCP,MAAAA,SAAS,EAAEQ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,KAAF,IAAa;AAC7D,QAAMK,qBAAqB,GAAG,mDAA9B;AACA,SACC,4BAAC,+BAAD,6BACWA,qBADX,EACqCL,KADrC,EADD;AAKA,CAPD;;AASA,MAAMO,0BAA0B,GAAKP,KAAF,IAAa;AAC/C,MACC,mBAAO3B,qBAAP,EAAgCmC,GAAF,IAAWR,KAAK,CAACS,cAAN,CAAsBD,GAAtB,CAAzC,CADD,EAEE;AACD,WAAO,4BAAC,+BAAD,EAAsCR,KAAtC,CAAP;AACA;;AACD,MAAKA,KAAK,CAACH,gCAAX,EAA8C;AAC7C,WAAO,4BAAC,wCAAD,EAA+CG,KAA/C,CAAP;AACA;;AACD,SAAO,4BAAC,sCAAD,EAA6CA,KAA7C,CAAP;AACA,CAVD;;eAYeO,0B","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { every, isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { PanelBody, ColorIndicator } from '@wordpress/components';\nimport { sprintf, __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from './control';\nimport { getColorObjectByColorValue } from '../colors';\nimport { __experimentalGetGradientObjectByGradientValue } from '../gradients';\nimport useSetting from '../use-setting';\nimport useCommonSingleMultipleSelects from './use-common-single-multiple-selects';\nimport useMultipleOriginColorsAndGradients from './use-multiple-origin-colors-and-gradients';\n\n// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)\nconst colorIndicatorAriaLabel = __( '(%s: color %s)' );\n\n// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)\nconst gradientIndicatorAriaLabel = __( '(%s: gradient %s)' );\n\nconst colorsAndGradientKeys = [\n\t'colors',\n\t'disableCustomColors',\n\t'gradients',\n\t'disableCustomGradients',\n];\n\nconst Indicators = ( { colors, gradients, settings } ) => {\n\treturn settings.map(\n\t\t(\n\t\t\t{\n\t\t\t\tcolorValue,\n\t\t\t\tgradientValue,\n\t\t\t\tlabel,\n\t\t\t\tcolors: availableColors,\n\t\t\t\tgradients: availableGradients,\n\t\t\t},\n\t\t\tindex\n\t\t) => {\n\t\t\tif ( ! colorValue && ! gradientValue ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet ariaLabel;\n\t\t\tif ( colorValue ) {\n\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\tavailableColors || colors,\n\t\t\t\t\tcolorValue\n\t\t\t\t);\n\t\t\t\tariaLabel = sprintf(\n\t\t\t\t\tcolorIndicatorAriaLabel,\n\t\t\t\t\tlabel.toLowerCase(),\n\t\t\t\t\t( colorObject && colorObject.name ) || colorValue\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst gradientObject = __experimentalGetGradientObjectByGradientValue(\n\t\t\t\t\tavailableGradients || gradients,\n\t\t\t\t\tcolorValue\n\t\t\t\t);\n\t\t\t\tariaLabel = sprintf(\n\t\t\t\t\tgradientIndicatorAriaLabel,\n\t\t\t\t\tlabel.toLowerCase(),\n\t\t\t\t\t( gradientObject && gradientObject.name ) || gradientValue\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\t<ColorIndicator\n\t\t\t\t\tkey={ index }\n\t\t\t\t\tcolorValue={ colorValue || gradientValue }\n\t\t\t\t\taria-label={ ariaLabel }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t);\n};\n\nexport const PanelColorGradientSettingsInner = ( {\n\tclassName,\n\tcolors,\n\tgradients,\n\tdisableCustomColors,\n\tdisableCustomGradients,\n\tchildren,\n\tsettings,\n\ttitle,\n\tshowTitle = true,\n\t__experimentalHasMultipleOrigins,\n\t__experimentalIsRenderedInSidebar,\n\tenableAlpha,\n\t...props\n} ) => {\n\tif (\n\t\tisEmpty( colors ) &&\n\t\tisEmpty( gradients ) &&\n\t\tdisableCustomColors &&\n\t\tdisableCustomGradients &&\n\t\tevery(\n\t\t\tsettings,\n\t\t\t( setting ) =>\n\t\t\t\tisEmpty( setting.colors ) &&\n\t\t\t\tisEmpty( setting.gradients ) &&\n\t\t\t\t( setting.disableCustomColors === undefined ||\n\t\t\t\t\tsetting.disableCustomColors ) &&\n\t\t\t\t( setting.disableCustomGradients === undefined ||\n\t\t\t\t\tsetting.disableCustomGradients )\n\t\t)\n\t) {\n\t\treturn null;\n\t}\n\n\tconst titleElement = (\n\t\t<span className=\"block-editor-panel-color-gradient-settings__panel-title\">\n\t\t\t{ title }\n\t\t\t<Indicators\n\t\t\t\tcolors={ colors }\n\t\t\t\tgradients={ gradients }\n\t\t\t\tsettings={ settings }\n\t\t\t/>\n\t\t</span>\n\t);\n\n\treturn (\n\t\t<PanelBody\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-panel-color-gradient-settings',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t\ttitle={ showTitle ? titleElement : undefined }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ settings.map( ( setting, index ) => (\n\t\t\t\t<ColorGradientControl\n\t\t\t\t\tshowTitle={ showTitle }\n\t\t\t\t\tkey={ index }\n\t\t\t\t\t{ ...{\n\t\t\t\t\t\tcolors,\n\t\t\t\t\t\tgradients,\n\t\t\t\t\t\tdisableCustomColors,\n\t\t\t\t\t\tdisableCustomGradients,\n\t\t\t\t\t\t__experimentalHasMultipleOrigins,\n\t\t\t\t\t\t__experimentalIsRenderedInSidebar,\n\t\t\t\t\t\tenableAlpha,\n\t\t\t\t\t\t...setting,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ children }\n\t\t</PanelBody>\n\t);\n};\n\nconst PanelColorGradientSettingsSingleSelect = ( props ) => {\n\tconst colorGradientSettings = useCommonSingleMultipleSelects();\n\tcolorGradientSettings.colors = useSetting( 'color.palette' );\n\tcolorGradientSettings.gradients = useSetting( 'color.gradients' );\n\treturn (\n\t\t<PanelColorGradientSettingsInner\n\t\t\t{ ...{ ...colorGradientSettings, ...props } }\n\t\t/>\n\t);\n};\n\nconst PanelColorGradientSettingsMultipleSelect = ( props ) => {\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\treturn (\n\t\t<PanelColorGradientSettingsInner\n\t\t\t{ ...{ ...colorGradientSettings, ...props } }\n\t\t/>\n\t);\n};\n\nconst PanelColorGradientSettings = ( props ) => {\n\tif (\n\t\tevery( colorsAndGradientKeys, ( key ) => props.hasOwnProperty( key ) )\n\t) {\n\t\treturn <PanelColorGradientSettingsInner { ...props } />;\n\t}\n\tif ( props.__experimentalHasMultipleOrigins ) {\n\t\treturn <PanelColorGradientSettingsMultipleSelect { ...props } />;\n\t}\n\treturn <PanelColorGradientSettingsSingleSelect { ...props } />;\n};\n\nexport default PanelColorGradientSettings;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useCommonSingleMultipleSelects;
|
|
9
|
+
|
|
10
|
+
var _useSetting = _interopRequireDefault(require("../use-setting"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
function useCommonSingleMultipleSelects() {
|
|
16
|
+
return {
|
|
17
|
+
disableCustomColors: !(0, _useSetting.default)('color.custom'),
|
|
18
|
+
disableCustomGradients: !(0, _useSetting.default)('color.customGradient')
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=use-common-single-multiple-selects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js"],"names":["useCommonSingleMultipleSelects","disableCustomColors","disableCustomGradients"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,8BAAT,GAA0C;AACxD,SAAO;AACNC,IAAAA,mBAAmB,EAAE,CAAE,yBAAY,cAAZ,CADjB;AAENC,IAAAA,sBAAsB,EAAE,CAAE,yBAAY,sBAAZ;AAFpB,GAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\n\nexport default function useCommonSingleMultipleSelects() {\n\treturn {\n\t\tdisableCustomColors: ! useSetting( 'color.custom' ),\n\t\tdisableCustomGradients: ! useSetting( 'color.customGradient' ),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useMultipleOriginColorsAndGradients;
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
var _i18n = require("@wordpress/i18n");
|
|
13
|
+
|
|
14
|
+
var _useSetting = _interopRequireDefault(require("../use-setting"));
|
|
15
|
+
|
|
16
|
+
var _useCommonSingleMultipleSelects = _interopRequireDefault(require("./use-common-single-multiple-selects"));
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* WordPress dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves color and gradient related settings.
|
|
28
|
+
*
|
|
29
|
+
* The arrays for colors and gradients are made up of color palettes from each
|
|
30
|
+
* origin i.e. "Core", "Theme", and "User".
|
|
31
|
+
*
|
|
32
|
+
* @return {Object} Color and gradient related settings.
|
|
33
|
+
*/
|
|
34
|
+
function useMultipleOriginColorsAndGradients() {
|
|
35
|
+
const colorGradientSettings = (0, _useCommonSingleMultipleSelects.default)();
|
|
36
|
+
const customColors = (0, _useSetting.default)('color.palette.custom');
|
|
37
|
+
const themeColors = (0, _useSetting.default)('color.palette.theme');
|
|
38
|
+
const defaultColors = (0, _useSetting.default)('color.palette.default');
|
|
39
|
+
const shouldDisplayDefaultColors = (0, _useSetting.default)('color.defaultPalette');
|
|
40
|
+
colorGradientSettings.colors = (0, _element.useMemo)(() => {
|
|
41
|
+
const result = [];
|
|
42
|
+
|
|
43
|
+
if (themeColors && themeColors.length) {
|
|
44
|
+
result.push({
|
|
45
|
+
name: (0, _i18n._x)('Theme', 'Indicates this palette comes from the theme.'),
|
|
46
|
+
colors: themeColors
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (shouldDisplayDefaultColors && defaultColors && defaultColors.length) {
|
|
51
|
+
result.push({
|
|
52
|
+
name: (0, _i18n._x)('Default', 'Indicates this palette comes from WordPress.'),
|
|
53
|
+
colors: defaultColors
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (customColors && customColors.length) {
|
|
58
|
+
result.push({
|
|
59
|
+
name: (0, _i18n._x)('Custom', 'Indicates this palette comes from the theme.'),
|
|
60
|
+
colors: customColors
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
}, [defaultColors, themeColors, customColors]);
|
|
66
|
+
const customGradients = (0, _useSetting.default)('color.gradients.custom');
|
|
67
|
+
const themeGradients = (0, _useSetting.default)('color.gradients.theme');
|
|
68
|
+
const defaultGradients = (0, _useSetting.default)('color.gradients.default');
|
|
69
|
+
const shouldDisplayDefaultGradients = (0, _useSetting.default)('color.defaultGradients');
|
|
70
|
+
colorGradientSettings.gradients = (0, _element.useMemo)(() => {
|
|
71
|
+
const result = [];
|
|
72
|
+
|
|
73
|
+
if (themeGradients && themeGradients.length) {
|
|
74
|
+
result.push({
|
|
75
|
+
name: (0, _i18n._x)('Theme', 'Indicates this palette comes from the theme.'),
|
|
76
|
+
gradients: themeGradients
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (shouldDisplayDefaultGradients && defaultGradients && defaultGradients.length) {
|
|
81
|
+
result.push({
|
|
82
|
+
name: (0, _i18n._x)('Default', 'Indicates this palette comes from WordPress.'),
|
|
83
|
+
gradients: defaultGradients
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (customGradients && customGradients.length) {
|
|
88
|
+
result.push({
|
|
89
|
+
name: (0, _i18n._x)('Custom', 'Indicates this palette is created by the user.'),
|
|
90
|
+
gradients: customGradients
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}, [customGradients, themeGradients, defaultGradients]);
|
|
96
|
+
return colorGradientSettings;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=use-multiple-origin-colors-and-gradients.js.map
|