@wordpress/block-editor 8.0.11 → 8.0.12-next.33ec3857e2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/components/block-caption/index.native.js +14 -3
- package/build/components/block-caption/index.native.js.map +1 -1
- package/build/components/block-inspector/index.js +12 -23
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list-appender/index.js +3 -11
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-preview/auto.js +10 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +51 -0
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-settings/container.native.js +2 -1
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-styles/index.js +110 -134
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/menu-items.js +63 -0
- package/build/components/block-styles/menu-items.js.map +1 -0
- package/build/components/block-styles/preview-panel.js +45 -0
- package/build/components/block-styles/preview-panel.js.map +1 -0
- package/build/components/block-styles/use-styles-for-block.js +119 -0
- package/build/components/block-styles/use-styles-for-block.js.map +1 -0
- package/build/components/block-styles/utils.js +39 -0
- package/build/components/block-styles/utils.js.map +1 -1
- package/build/components/block-switcher/block-styles-menu.js +3 -23
- package/build/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +11 -1
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/button-block-appender/index.js +2 -1
- package/build/components/button-block-appender/index.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +51 -10
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/default-block-appender/index.js +16 -19
- package/build/components/default-block-appender/index.js.map +1 -1
- package/build/components/default-style-picker/index.js +18 -3
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/iframe/index.js +3 -4
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +17 -10
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/default-block-appender.js +2 -4
- package/build/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build/components/inserter/index.native.js +1 -1
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +7 -4
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inspector-controls/block-support-slot-container.js +2 -1
- package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +3 -5
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls/slot.js +1 -3
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +6 -6
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +23 -3
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/media-placeholder/index.js +2 -0
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +2 -0
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/rich-text/file-paste-handler.js +1 -1
- package/build/components/rich-text/file-paste-handler.js.map +1 -1
- package/build/components/rich-text/prevent-event-discovery.js +33 -0
- package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +3 -1
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/selection-scroll-into-view/index.js +2 -1
- package/build/components/selection-scroll-into-view/index.js.map +1 -1
- package/build/components/use-display-block-controls/index.native.js +45 -0
- package/build/components/use-display-block-controls/index.native.js.map +1 -0
- package/build/components/use-on-block-drop/index.js +7 -3
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +3 -1
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/hooks/border-color.js +63 -5
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border-radius.js +47 -0
- package/build/hooks/border-radius.js.map +1 -1
- package/build/hooks/border-style.js +41 -0
- package/build/hooks/border-style.js.map +1 -1
- package/build/hooks/border-width.js +70 -31
- package/build/hooks/border-width.js.map +1 -1
- package/build/hooks/border.js +81 -11
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/letter-spacing.js +1 -1
- package/build/hooks/letter-spacing.js.map +1 -1
- package/build/hooks/typography.js +1 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/store/actions.js +1 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/selectors.js +25 -7
- package/build/store/selectors.js.map +1 -1
- package/build/utils/get-paste-event-data.js +1 -1
- package/build/utils/get-paste-event-data.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +1 -1
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-caption/index.native.js +13 -3
- package/build-module/components/block-caption/index.native.js.map +1 -1
- package/build-module/components/block-inspector/index.js +12 -23
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +3 -10
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +10 -2
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +46 -0
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +2 -1
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-styles/index.js +112 -133
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/menu-items.js +50 -0
- package/build-module/components/block-styles/menu-items.js.map +1 -0
- package/build-module/components/block-styles/preview-panel.js +35 -0
- package/build-module/components/block-styles/preview-panel.js.map +1 -0
- package/build-module/components/block-styles/use-styles-for-block.js +107 -0
- package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
- package/build-module/components/block-styles/utils.js +34 -0
- package/build-module/components/block-styles/utils.js.map +1 -1
- package/build-module/components/block-switcher/block-styles-menu.js +3 -21
- package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +11 -1
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/button-block-appender/index.js +2 -1
- package/build-module/components/button-block-appender/index.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +54 -13
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/default-block-appender/index.js +15 -18
- package/build-module/components/default-block-appender/index.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +17 -3
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/iframe/index.js +3 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +2 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/default-block-appender.js +2 -4
- package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build-module/components/inserter/index.native.js +2 -2
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +7 -4
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +3 -5
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +1 -3
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +6 -6
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +22 -3
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +2 -0
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +2 -0
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/rich-text/file-paste-handler.js +1 -1
- package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
- package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
- package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +2 -1
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/selection-scroll-into-view/index.js +2 -1
- package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
- package/build-module/components/use-display-block-controls/index.native.js +34 -0
- package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
- package/build-module/components/use-on-block-drop/index.js +7 -3
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +3 -4
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/hooks/border-color.js +61 -7
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border-radius.js +42 -0
- package/build-module/hooks/border-radius.js.map +1 -1
- package/build-module/hooks/border-style.js +36 -0
- package/build-module/hooks/border-style.js.map +1 -1
- package/build-module/hooks/border-width.js +66 -32
- package/build-module/hooks/border-width.js.map +1 -1
- package/build-module/hooks/border.js +80 -12
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/letter-spacing.js +1 -1
- package/build-module/hooks/letter-spacing.js.map +1 -1
- package/build-module/hooks/typography.js +1 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/store/actions.js +1 -2
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/selectors.js +24 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/get-paste-event-data.js +1 -1
- package/build-module/utils/get-paste-event-data.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +1 -1
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +226 -180
- package/build-style/style.css +226 -180
- package/package.json +27 -27
- package/src/components/block-caption/index.native.js +22 -4
- package/src/components/block-inspector/index.js +14 -17
- package/src/components/block-list-appender/index.js +5 -21
- package/src/components/block-preview/auto.js +7 -2
- package/src/components/block-preview/index.js +60 -0
- package/src/components/block-preview/style.scss +23 -0
- package/src/components/block-preview/test/index.js +114 -0
- package/src/components/block-settings/container.native.js +1 -0
- package/src/components/block-styles/index.js +125 -145
- package/src/components/block-styles/menu-items.js +49 -0
- package/src/components/block-styles/preview-panel.js +36 -0
- package/src/components/block-styles/style.scss +59 -51
- package/src/components/block-styles/test/{index.js → utils.js} +60 -1
- package/src/components/block-styles/use-styles-for-block.js +99 -0
- package/src/components/block-styles/utils.js +39 -0
- package/src/components/block-switcher/block-styles-menu.js +3 -38
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +10 -1
- package/src/components/border-style-control/style.scss +0 -1
- package/src/components/button-block-appender/index.js +1 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +75 -19
- package/src/components/colors-gradients/style.scss +42 -5
- package/src/components/default-block-appender/index.js +17 -24
- package/src/components/default-block-appender/style.scss +4 -0
- package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
- package/src/components/default-block-appender/test/index.js +4 -14
- package/src/components/default-style-picker/index.js +18 -6
- package/src/components/iframe/index.js +6 -3
- package/src/components/index.js +5 -2
- package/src/components/inner-blocks/README.md +2 -0
- package/src/components/inner-blocks/default-block-appender.js +2 -7
- package/src/components/inserter/index.native.js +2 -2
- package/src/components/inserter/tabs.native.js +5 -4
- package/src/components/inspector-controls/block-support-slot-container.js +3 -1
- package/src/components/inspector-controls/fill.native.js +4 -3
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls/slot.js +2 -7
- package/src/components/letter-spacing-control/index.js +6 -6
- package/src/components/link-control/README.md +1 -1
- package/src/components/link-control/test/index.js +2 -0
- package/src/components/list-view/block-select-button.js +20 -1
- package/src/components/media-placeholder/index.js +2 -0
- package/src/components/media-replace-flow/index.js +2 -0
- package/src/components/rich-text/file-paste-handler.js +3 -1
- package/src/components/rich-text/prevent-event-discovery.js +23 -0
- package/src/components/rich-text/use-input-rules.js +2 -1
- package/src/components/selection-scroll-into-view/index.js +1 -0
- package/src/components/url-input/README.md +5 -0
- package/src/components/use-display-block-controls/index.native.js +38 -0
- package/src/components/use-on-block-drop/index.js +7 -3
- package/src/components/writing-flow/test/use-multi-selection.js +36 -0
- package/src/components/writing-flow/use-multi-selection.js +12 -9
- package/src/hooks/border-color.js +55 -3
- package/src/hooks/border-radius.js +32 -0
- package/src/hooks/border-style.js +26 -0
- package/src/hooks/border-width.js +56 -32
- package/src/hooks/border.js +115 -20
- package/src/hooks/border.scss +3 -17
- package/src/hooks/dimensions.scss +5 -0
- package/src/hooks/letter-spacing.js +1 -1
- package/src/hooks/typography.js +1 -1
- package/src/store/actions.js +1 -2
- package/src/store/defaults.js +2 -0
- package/src/store/selectors.js +37 -7
- package/src/style.scss +4 -3
- package/src/utils/get-paste-event-data.js +1 -1
- package/src/utils/parse-css-unit-to-px.js +1 -1
- package/src/utils/test/parse-css-unit-to-px.js +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/use-canvas-click-redirect/index.js +0 -66
- package/build/components/use-canvas-click-redirect/index.js.map +0 -1
- package/build-module/components/use-canvas-click-redirect/index.js +0 -54
- package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
- package/src/components/use-canvas-click-redirect/index.js +0 -57
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocksToPosition","insertBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","select","getSettings","mediaUpload","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,aAFD,EAGCC,kBAHD,EAICC,YAJD,QAKO,mBALP;AAMA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AACvC,MAAIC,MAAM,GAAG;AACZC,IAAAA,eAAe,EAAE,IADL;AAEZC,IAAAA,YAAY,EAAE,IAFF;AAGZC,IAAAA,QAAQ,EAAE,IAHE;AAIZC,IAAAA,IAAI,EAAE,IAJM;AAKZC,IAAAA,MAAM,EAAE;AALI,GAAb;;AAQA,MAAK,CAAEN,KAAK,CAACO,YAAb,EAA4B;AAC3B,WAAON,MAAP;AACA;;AAED,MAAI;AACHA,IAAAA,MAAM,GAAGO,MAAM,CAACC,MAAP,CACRR,MADQ,EAERS,IAAI,CAACC,KAAL,CAAYX,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAZ,CAFQ,CAAT;AAIA,GALD,CAKE,OAAQC,GAAR,EAAc;AACf,WAAOZ,MAAP;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IAAKe,IAAL,EAAY;AAClBD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFM,MAEA;AACNH,MAAAA,OAAO,CAAEpD,KAAF,CAAP;AACA;AACD,GAXD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocksToPosition A function that moves blocks.\n * @param {Function} insertBlocks A function that inserts blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocksToPosition,\n\tinsertBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertBlocks(\n\t\t\t\tblocksToInsert,\n\t\t\t\ttargetBlockIndex,\n\t\t\t\ttargetRootClientId,\n\t\t\t\ttrue,\n\t\t\t\tnull\n\t\t\t);\n\t\t}\n\n\t\t// If the user is moving a block\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex(\n\t\t\t\tsourceClientIds[ 0 ],\n\t\t\t\tsourceRootClientId\n\t\t\t);\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocksToPosition(\n\t\t\t\tsourceClientIds,\n\t\t\t\tsourceRootClientId,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tinsertIndex\n\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n *\n * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.\n */\nexport default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t} = useDispatch( blockEditorStore );\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocksToPosition,\n\t\tinsertBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\tif ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else if ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocksToPosition","insertBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","select","getSettings","mediaUpload","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,aAFD,EAGCC,kBAHD,EAICC,YAJD,QAKO,mBALP;AAMA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AACvC,MAAIC,MAAM,GAAG;AACZC,IAAAA,eAAe,EAAE,IADL;AAEZC,IAAAA,YAAY,EAAE,IAFF;AAGZC,IAAAA,QAAQ,EAAE,IAHE;AAIZC,IAAAA,IAAI,EAAE,IAJM;AAKZC,IAAAA,MAAM,EAAE;AALI,GAAb;;AAQA,MAAK,CAAEN,KAAK,CAACO,YAAb,EAA4B;AAC3B,WAAON,MAAP;AACA;;AAED,MAAI;AACHA,IAAAA,MAAM,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AR,CAAtC;AACA,UAAMgD,IAAI,GAAGvD,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAb;AAEA;AACF;AACA;AACA;;AACE,QAAK2C,IAAL,EAAY;AACXD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFD,MAEO,IAAKf,KAAK,CAACN,MAAX,EAAoB;AAC1BmB,MAAAA,YAAY,CAAEb,KAAF,CAAZ;AACA,KAFM,MAEA;AACNY,MAAAA,OAAO,CAAEpD,KAAF,CAAP;AACA;AACD,GAfD;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocksToPosition A function that moves blocks.\n * @param {Function} insertBlocks A function that inserts blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocksToPosition,\n\tinsertBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertBlocks(\n\t\t\t\tblocksToInsert,\n\t\t\t\ttargetBlockIndex,\n\t\t\t\ttargetRootClientId,\n\t\t\t\ttrue,\n\t\t\t\tnull\n\t\t\t);\n\t\t}\n\n\t\t// If the user is moving a block\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex(\n\t\t\t\tsourceClientIds[ 0 ],\n\t\t\t\tsourceRootClientId\n\t\t\t);\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocksToPosition(\n\t\t\t\tsourceClientIds,\n\t\t\t\tsourceRootClientId,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tinsertIndex\n\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n *\n * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.\n */\nexport default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t} = useDispatch( blockEditorStore );\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocksToPosition,\n\t\tinsertBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
|
|
@@ -14,9 +14,9 @@ import { useSelect } from '@wordpress/data';
|
|
|
14
14
|
|
|
15
15
|
import { store as blockEditorStore } from '../../store';
|
|
16
16
|
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export function toggleRichText(container, toggle) {
|
|
18
|
+
Array.from(container.querySelectorAll( // Exclude the Post Title from multi-select disable.
|
|
19
|
+
'.rich-text:not( .editor-post-title__input )')).forEach(node => {
|
|
20
20
|
if (toggle) {
|
|
21
21
|
node.setAttribute('contenteditable', true);
|
|
22
22
|
} else {
|
|
@@ -32,7 +32,6 @@ function toggleRichText(container, toggle) {
|
|
|
32
32
|
* @param {string} type 'start' or 'end'.
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
function getDeepestNode(node, type) {
|
|
37
36
|
const child = type === 'start' ? 'firstChild' : 'lastChild';
|
|
38
37
|
const sibling = type === 'start' ? 'nextSibling' : 'previousSibling';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","toggleRichText","container","toggle","Array","from","querySelectorAll","forEach","node","setAttribute","removeAttribute","getDeepestNode","type","child","sibling","nodeType","TEXT_NODE","test","data","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","multiSelectedBlockClientIds","selectedBlockClientId","useMultiSelection","selectedRef","startRef","endRef","ownerDocument","defaultView","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","focus","range","createRange","startNode","endNode","setStartBefore","setEndAfter","addRange"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","toggleRichText","container","toggle","Array","from","querySelectorAll","forEach","node","setAttribute","removeAttribute","getDeepestNode","type","child","sibling","nodeType","TEXT_NODE","test","data","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","multiSelectedBlockClientIds","selectedBlockClientId","useMultiSelection","selectedRef","startRef","endRef","ownerDocument","defaultView","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","focus","range","createRange","startNode","endNode","setStartBefore","setEndAfter","addRange"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,I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C,MAAAA;AAAF,QAAanB,2BAAnB;;AAEA,QAAKmB,MAAM,GAAG,CAAd,EAAkB;AACjB;AACA,KAlCU,CAoCX;AACA;;;AACA,QAAK,CAAEf,QAAQ,CAACS,OAAX,IAAsB,CAAER,MAAM,CAACQ,OAApC,EAA8C;AAC7C;AACA,KAxCU,CA0CX;AACA;;;AACA9B,IAAAA,IAAI,CAACqC,KAAL;AAEA,UAAMZ,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA,UAAMY,KAAK,GAAGf,aAAa,CAACgB,WAAd,EAAd,CA/CW,CAiDX;AACA;AACA;;AACA,UAAMC,SAAS,GAAGrC,cAAc,CAAEkB,QAAQ,CAACS,OAAX,EAAoB,OAApB,CAAhC;AACA,UAAMW,OAAO,GAAGtC,cAAc,CAAEmB,MAAM,CAACQ,OAAT,EAAkB,KAAlB,CAA9B,CArDW,CAuDX;AACA;AACA;;AACArC,IAAAA,cAAc,CAAEO,IAAF,EAAQ,KAAR,CAAd;AAEAsC,IAAAA,KAAK,CAACI,cAAN,CAAsBF,SAAtB;AACAF,IAAAA,KAAK,CAACK,WAAN,CAAmBF,OAAnB;AAEAhB,IAAAA,SAAS,CAACU,eAAV;AACAV,IAAAA,SAAS,CAACmB,QAAV,CAAoBN,KAApB;AACA,GAlEiB,EAmElB,CACCvB,iBADD,EAECF,gBAFD,EAGCI,2BAHD,EAICC,qBAJD,CAnEkB,CAAnB;AA0EA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nexport function toggleRichText( container, toggle ) {\n\tArray.from(\n\t\tcontainer.querySelectorAll(\n\t\t\t// Exclude the Post Title from multi-select disable.\n\t\t\t'.rich-text:not( .editor-post-title__input )'\n\t\t)\n\t).forEach( ( node ) => {\n\t\tif ( toggle ) {\n\t\t\tnode.setAttribute( 'contenteditable', true );\n\t\t} else {\n\t\t\tnode.removeAttribute( 'contenteditable' );\n\t\t}\n\t} );\n}\n\n/**\n * Returns for the deepest node at the start or end of a container node. Ignores\n * any text nodes that only contain HTML formatting whitespace.\n *\n * @param {Element} node Container to search.\n * @param {string} type 'start' or 'end'.\n */\nfunction getDeepestNode( node, type ) {\n\tconst child = type === 'start' ? 'firstChild' : 'lastChild';\n\tconst sibling = type === 'start' ? 'nextSibling' : 'previousSibling';\n\n\twhile ( node[ child ] ) {\n\t\tnode = node[ child ];\n\n\t\twhile (\n\t\t\tnode.nodeType === node.TEXT_NODE &&\n\t\t\t/^[ \\t\\n]*$/.test( node.data ) &&\n\t\t\tnode[ sibling ]\n\t\t) {\n\t\t\tnode = node[ sibling ];\n\t\t}\n\t}\n\n\treturn node;\n}\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t} = useSelect( selector, [] );\n\tconst selectedRef = useBlockRef( selectedBlockClientId );\n\t// These must be in the right DOM order.\n\tconst startRef = useBlockRef( first( multiSelectedBlockClientIds ) );\n\tconst endRef = useBlockRef( last( multiSelectedBlockClientIds ) );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\tif ( ! selectedBlockClientId || isMultiSelecting ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( selection.rangeCount && ! selection.isCollapsed ) {\n\t\t\t\t\tconst blockNode = selectedRef.current;\n\t\t\t\t\tconst {\n\t\t\t\t\t\tstartContainer,\n\t\t\t\t\t\tendContainer,\n\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t!! blockNode &&\n\t\t\t\t\t\t( ! blockNode.contains( startContainer ) ||\n\t\t\t\t\t\t\t! blockNode.contains( endContainer ) )\n\t\t\t\t\t) {\n\t\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The block refs might not be immediately available\n\t\t\t// when dragging blocks into another block.\n\t\t\tif ( ! startRef.current || ! endRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For some browsers, like Safari, it is important that focus happens\n\t\t\t// BEFORE selection.\n\t\t\tnode.focus();\n\n\t\t\tconst selection = defaultView.getSelection();\n\t\t\tconst range = ownerDocument.createRange();\n\n\t\t\t// These must be in the right DOM order.\n\t\t\t// The most stable way to select the whole block contents is to start\n\t\t\t// and end at the deepest points.\n\t\t\tconst startNode = getDeepestNode( startRef.current, 'start' );\n\t\t\tconst endNode = getDeepestNode( endRef.current, 'end' );\n\n\t\t\t// While rich text will be disabled with a delay when there is a multi\n\t\t\t// selection, we must do it immediately because it's not possible to set\n\t\t\t// selection across editable hosts.\n\t\t\ttoggleRichText( node, false );\n\n\t\t\trange.setStartBefore( startNode );\n\t\t\trange.setEndAfter( endNode );\n\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( range );\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -12,7 +12,7 @@ import classnames from 'classnames';
|
|
|
12
12
|
import { addFilter } from '@wordpress/hooks';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
14
14
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
15
|
-
import { useState } from '@wordpress/element';
|
|
15
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
16
16
|
/**
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
@@ -21,7 +21,7 @@ import ColorGradientControl from '../components/colors-gradients/control';
|
|
|
21
21
|
import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
|
|
22
22
|
import { getColorClassName, getColorObjectByColorValue, getColorObjectByAttributeValues } from '../components/colors';
|
|
23
23
|
import useSetting from '../components/use-setting';
|
|
24
|
-
import { hasBorderSupport, shouldSkipSerialization } from './border';
|
|
24
|
+
import { hasBorderSupport, removeBorderAttribute, shouldSkipSerialization } from './border';
|
|
25
25
|
import { cleanEmptyObject } from './utils'; // Defining empty array here instead of inline avoids unnecessary re-renders of
|
|
26
26
|
// color control.
|
|
27
27
|
|
|
@@ -50,11 +50,23 @@ export function BorderColorEdit(props) {
|
|
|
50
50
|
} = props;
|
|
51
51
|
const colorGradientSettings = useMultipleOriginColorsAndGradients();
|
|
52
52
|
const availableColors = colorGradientSettings.colors.reduce((colors, origin) => colors.concat(origin.colors), []);
|
|
53
|
+
const {
|
|
54
|
+
color: customBorderColor
|
|
55
|
+
} = (style === null || style === void 0 ? void 0 : style.border) || {};
|
|
53
56
|
const [colorValue, setColorValue] = useState(() => {
|
|
54
|
-
var _getColorObjectByAttr
|
|
57
|
+
var _getColorObjectByAttr;
|
|
55
58
|
|
|
56
|
-
return (_getColorObjectByAttr = getColorObjectByAttributeValues(availableColors, borderColor,
|
|
57
|
-
});
|
|
59
|
+
return (_getColorObjectByAttr = getColorObjectByAttributeValues(availableColors, borderColor, customBorderColor)) === null || _getColorObjectByAttr === void 0 ? void 0 : _getColorObjectByAttr.color;
|
|
60
|
+
}); // Detect changes in the color attributes and update the colorValue to keep the
|
|
61
|
+
// UI in sync. This is necessary for situations when border controls interact with
|
|
62
|
+
// eachother: eg, setting the border width to zero causes the color and style
|
|
63
|
+
// selections to be cleared.
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
var _getColorObjectByAttr2;
|
|
67
|
+
|
|
68
|
+
setColorValue((_getColorObjectByAttr2 = getColorObjectByAttributeValues(availableColors, borderColor, customBorderColor)) === null || _getColorObjectByAttr2 === void 0 ? void 0 : _getColorObjectByAttr2.color);
|
|
69
|
+
}, [borderColor, customBorderColor, availableColors]);
|
|
58
70
|
|
|
59
71
|
const onChangeColor = value => {
|
|
60
72
|
setColorValue(value);
|
|
@@ -81,6 +93,48 @@ export function BorderColorEdit(props) {
|
|
|
81
93
|
__experimentalIsRenderedInSidebar: true
|
|
82
94
|
}, colorGradientSettings));
|
|
83
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks if there is a current value in the border color block support
|
|
98
|
+
* attributes.
|
|
99
|
+
*
|
|
100
|
+
* @param {Object} props Block props.
|
|
101
|
+
* @return {boolean} Whether or not the block has a border color value set.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
export function hasBorderColorValue(props) {
|
|
105
|
+
var _style$border;
|
|
106
|
+
|
|
107
|
+
const {
|
|
108
|
+
attributes: {
|
|
109
|
+
borderColor,
|
|
110
|
+
style
|
|
111
|
+
}
|
|
112
|
+
} = props;
|
|
113
|
+
return !!borderColor || !!(style !== null && style !== void 0 && (_style$border = style.border) !== null && _style$border !== void 0 && _style$border.color);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Resets the border color block support attributes. This can be used when
|
|
117
|
+
* disabling the border color support controls for a block via a progressive
|
|
118
|
+
* discovery panel.
|
|
119
|
+
*
|
|
120
|
+
* @param {Object} props Block props.
|
|
121
|
+
* @param {Object} props.attributes Block's attributes.
|
|
122
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
export function resetBorderColor(_ref) {
|
|
126
|
+
let {
|
|
127
|
+
attributes = {},
|
|
128
|
+
setAttributes
|
|
129
|
+
} = _ref;
|
|
130
|
+
const {
|
|
131
|
+
style
|
|
132
|
+
} = attributes;
|
|
133
|
+
setAttributes({
|
|
134
|
+
borderColor: undefined,
|
|
135
|
+
style: removeBorderAttribute(style, 'color')
|
|
136
|
+
});
|
|
137
|
+
}
|
|
84
138
|
/**
|
|
85
139
|
* Filters registered block settings, extending attributes to include
|
|
86
140
|
* `borderColor` if needed.
|
|
@@ -181,7 +235,7 @@ function addEditProps(settings) {
|
|
|
181
235
|
|
|
182
236
|
|
|
183
237
|
export const withBorderColorPaletteStyles = createHigherOrderComponent(BlockListBlock => props => {
|
|
184
|
-
var
|
|
238
|
+
var _getColorObjectByAttr3, _props$wrapperProps;
|
|
185
239
|
|
|
186
240
|
const {
|
|
187
241
|
name,
|
|
@@ -197,7 +251,7 @@ export const withBorderColorPaletteStyles = createHigherOrderComponent(BlockList
|
|
|
197
251
|
}
|
|
198
252
|
|
|
199
253
|
const extraStyles = {
|
|
200
|
-
borderColor: borderColor ? (
|
|
254
|
+
borderColor: borderColor ? (_getColorObjectByAttr3 = getColorObjectByAttributeValues(colors, borderColor)) === null || _getColorObjectByAttr3 === void 0 ? void 0 : _getColorObjectByAttr3.color : undefined
|
|
201
255
|
};
|
|
202
256
|
let wrapperProps = props.wrapperProps;
|
|
203
257
|
wrapperProps = { ...props.wrapperProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-color.js"],"names":["classnames","addFilter","__","createHigherOrderComponent","useState","ColorGradientControl","useMultipleOriginColorsAndGradients","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","useSetting","hasBorderSupport","shouldSkipSerialization","cleanEmptyObject","EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","colorValue","setColorValue","border","color","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","addAttributes","settings","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,wCAAjC;AACA,OAAOC,mCAAP,MAAgD,yEAAhD;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,QAIO,sBAJP;AAKA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SAASC,gBAAT,EAA2BC,uBAA3B,QAA0D,UAA1D;AACA,SAASC,gBAAT,QAAiC,SAAjC,C,CAEA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,KAA1B,EAAkC;AACxC,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,KADP;AAELC,IAAAA;AAFK,MAGFJ,KAHJ;AAIA,QAAMK,qBAAqB,GAAGf,mCAAmC,EAAjE;AACA,QAAMgB,eAAe,GAAGD,qBAAq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V,CADV,2DACrB,uBAAwDY,KADnC,GAErBM;AAHgB,GAApB;AAMA,MAAIiB,YAAY,GAAGrC,KAAK,CAACqC,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAGrC,KAAK,CAACqC,YADK;AAEdlC,IAAAA,KAAK,EAAE,EACN,GAAGiC,WADG;AAEN,iCAAGpC,KAAK,CAACqC,YAAT,wDAAG,oBAAoBlC,KAAvB;AAFM;AAFO,GAAf;AAQA,SAAO,cAAC,cAAD,eAAqBH,KAArB;AAA6B,IAAA,YAAY,EAAGqC;AAA5C,KAAP;AACA,CA7BoE,CAA/D;AAgCPpD,SAAS,CACR,0BADQ,EAER,2BAFQ,EAGRqC,aAHQ,CAAT;AAMArC,SAAS,CACR,kCADQ,EAER,0BAFQ,EAGRwC,YAHQ,CAAT;AAMAxC,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGR6C,YAHQ,CAAT;AAMA7C,SAAS,CACR,uBADQ,EAER,8CAFQ,EAGRgD,4BAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from '../components/colors-gradients/control';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport { hasBorderSupport, shouldSkipSerialization } from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tstyle?.border?.color\n\t\t\t)?.color\n\t);\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\treturn (\n\t\t<ColorGradientControl\n\t\t\tlabel={ __( 'Color' ) }\n\t\t\tcolorValue={ colorValue }\n\t\t\tonColorChange={ onChangeColor }\n\t\t\tclearable={ false }\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\n\t\t};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-color.js"],"names":["classnames","addFilter","__","createHigherOrderComponent","useEffect","useState","ColorGradientControl","useMultipleOriginColorsAndGradients","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","useSetting","hasBorderSupport","removeBorderAttribute","shouldSkipSerialization","cleanEmptyObject","EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","color","customBorderColor","border","colorValue","setColorValue","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","hasBorderColorValue","resetBorderColor","addAttributes","settings","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,oBAApC;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,wCAAjC;AACA,OAAOC,mCAAP,MAAgD,yEAAhD;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,QAIO,sBAJP;AAKA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SACCC,gBADD,EAECC,qBAFD,EAGCC,uBAHD,QAIO,UAJP;AAKA,SAASC,gBAAT,QAAiC,SAAjC,C,CAEA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,KAA1B,EAAkC;AACxC,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,KADP;AAELC,IAAAA;AAFK,MAGFJ,KAHJ;AAIA,QAAMK,qBAAqB,GAAGhB,mCAAmC,EAAjE;AACA,QAAMiB,eAAe,GAAGD,qBAAqB,CAACE,MAAtB,CAA6BC,MAA7B,CACvB,CAAED,MAAF,EAAUE,MAAV,KAAsBF,MAAM,CAACG,MAAP,CAAeD,MAAM,CAACF,MAAtB,CADC,EAEvB,EAFuB,CAAxB;AAIA,QAAM;AAAEI,IAAAA,KAAK,EA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Q,EAGR0C,aAHQ,CAAT;AAMA1C,SAAS,CACR,kCADQ,EAER,0BAFQ,EAGR6C,YAHQ,CAAT;AAMA7C,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGRkD,YAHQ,CAAT;AAMAlD,SAAS,CACR,uBADQ,EAER,8CAFQ,EAGRqD,4BAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from '../components/colors-gradients/control';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport {\n\thasBorderSupport,\n\tremoveBorderAttribute,\n\tshouldSkipSerialization,\n} from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst { color: customBorderColor } = style?.border || {};\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t);\n\n\t// Detect changes in the color attributes and update the colorValue to keep the\n\t// UI in sync. This is necessary for situations when border controls interact with\n\t// eachother: eg, setting the border width to zero causes the color and style\n\t// selections to be cleared.\n\tuseEffect( () => {\n\t\tsetColorValue(\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t\t);\n\t}, [ borderColor, customBorderColor, availableColors ] );\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\treturn (\n\t\t<ColorGradientControl\n\t\t\tlabel={ __( 'Color' ) }\n\t\t\tcolorValue={ colorValue }\n\t\t\tonColorChange={ onChangeColor }\n\t\t\tclearable={ false }\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value in the border color block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border color value set.\n */\nexport function hasBorderColorValue( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t} = props;\n\n\treturn !! borderColor || !! style?.border?.color;\n}\n\n/**\n * Resets the border color block support attributes. This can be used when\n * disabling the border color support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderColor( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tborderColor: undefined,\n\t\tstyle: removeBorderAttribute( style, 'color' ),\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\n\t\t};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
|
|
@@ -5,6 +5,7 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import BorderRadiusControl from '../components/border-radius-control';
|
|
7
7
|
import { cleanEmptyObject } from './utils';
|
|
8
|
+
import { removeBorderAttribute } from './border';
|
|
8
9
|
/**
|
|
9
10
|
* Inspector control panel containing the border radius related configuration.
|
|
10
11
|
*
|
|
@@ -44,4 +45,45 @@ export function BorderRadiusEdit(props) {
|
|
|
44
45
|
onChange: onChange
|
|
45
46
|
});
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks if there is a current value in the border radius block support
|
|
50
|
+
* attributes.
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} props Block props.
|
|
53
|
+
* @return {boolean} Whether or not the block has a border radius value set.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export function hasBorderRadiusValue(props) {
|
|
57
|
+
var _props$attributes$sty, _props$attributes$sty2;
|
|
58
|
+
|
|
59
|
+
const borderRadius = (_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : (_props$attributes$sty2 = _props$attributes$sty.border) === null || _props$attributes$sty2 === void 0 ? void 0 : _props$attributes$sty2.radius;
|
|
60
|
+
|
|
61
|
+
if (typeof borderRadius === 'object') {
|
|
62
|
+
return Object.entries(borderRadius).some(Boolean);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return !!borderRadius;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resets the border radius block support attributes. This can be used when
|
|
69
|
+
* disabling the border radius support controls for a block via a progressive
|
|
70
|
+
* discovery panel.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} props Block props.
|
|
73
|
+
* @param {Object} props.attributes Block's attributes.
|
|
74
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export function resetBorderRadius(_ref) {
|
|
78
|
+
let {
|
|
79
|
+
attributes = {},
|
|
80
|
+
setAttributes
|
|
81
|
+
} = _ref;
|
|
82
|
+
const {
|
|
83
|
+
style
|
|
84
|
+
} = attributes;
|
|
85
|
+
setAttributes({
|
|
86
|
+
style: removeBorderAttribute(style, 'radius')
|
|
87
|
+
});
|
|
88
|
+
}
|
|
47
89
|
//# sourceMappingURL=border-radius.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-radius.js"],"names":["BorderRadiusControl","cleanEmptyObject","BorderRadiusEdit","props","attributes","style","setAttributes","onChange","newRadius","newStyle","border","radius","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,qCAAhC;AACA,SAASC,gBAAT,QAAiC,SAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,gBAAT,CAA2BC,KAA3B,EAAmC;AAAA;;AACzC,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA;AAAF,KADP;AAELC,IAAAA;AAFK,MAGFH,KAHJ;;AAKA,QAAMI,QAAQ,GAAKC,SAAF,IAAiB;AACjC,QAAIC,QAAQ,GAAG,EACd,GAAGJ,KADW;AAEdK,MAAAA,MAAM,EAAE,EACP,IAAGL,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAEK,MAAV,CADO;AAEPC,QAAAA,MAAM,EAAEH;AAFD;AAFM,KAAf;;AAQA,QAAKA,SAAS,KAAKI,SAAd,IAA2BJ,SAAS,KAAK,EAA9C,EAAmD;AAClDC,MAAAA,QAAQ,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-radius.js"],"names":["BorderRadiusControl","cleanEmptyObject","removeBorderAttribute","BorderRadiusEdit","props","attributes","style","setAttributes","onChange","newRadius","newStyle","border","radius","undefined","hasBorderRadiusValue","border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AhB,EAA+BG,IAA/B,CAAqCC,OAArC,CAAP;AACA;;AAED,SAAO,CAAC,CAAEJ,YAAV;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,iBAAT,OAAiE;AAAA,MAArC;AAAEf,IAAAA,UAAU,GAAG,EAAf;AAAmBE,IAAAA;AAAnB,GAAqC;AACvE,QAAM;AAAED,IAAAA;AAAF,MAAYD,UAAlB;AACAE,EAAAA,aAAa,CAAE;AAAED,IAAAA,KAAK,EAAEJ,qBAAqB,CAAEI,KAAF,EAAS,QAAT;AAA9B,GAAF,CAAb;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport BorderRadiusControl from '../components/border-radius-control';\nimport { cleanEmptyObject } from './utils';\nimport { removeBorderAttribute } from './border';\n\n/**\n * Inspector control panel containing the border radius related configuration.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border radius edit element.\n */\nexport function BorderRadiusEdit( props ) {\n\tconst {\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst onChange = ( newRadius ) => {\n\t\tlet newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tradius: newRadius,\n\t\t\t},\n\t\t};\n\n\t\tif ( newRadius === undefined || newRadius === '' ) {\n\t\t\tnewStyle = cleanEmptyObject( newStyle );\n\t\t}\n\n\t\tsetAttributes( { style: newStyle } );\n\t};\n\n\treturn (\n\t\t<BorderRadiusControl\n\t\t\tvalues={ style?.border?.radius }\n\t\t\tonChange={ onChange }\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value in the border radius block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border radius value set.\n */\nexport function hasBorderRadiusValue( props ) {\n\tconst borderRadius = props.attributes.style?.border?.radius;\n\n\tif ( typeof borderRadius === 'object' ) {\n\t\treturn Object.entries( borderRadius ).some( Boolean );\n\t}\n\n\treturn !! borderRadius;\n}\n\n/**\n * Resets the border radius block support attributes. This can be used when\n * disabling the border radius support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderRadius( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\tsetAttributes( { style: removeBorderAttribute( style, 'radius' ) } );\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import BorderStyleControl from '../components/border-style-control';
|
|
7
7
|
import { cleanEmptyObject } from './utils';
|
|
8
|
+
import { removeBorderAttribute } from './border';
|
|
8
9
|
/**
|
|
9
10
|
* Inspector control for configuring border style property.
|
|
10
11
|
*
|
|
@@ -39,4 +40,39 @@ export const BorderStyleEdit = props => {
|
|
|
39
40
|
onChange: onChange
|
|
40
41
|
});
|
|
41
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Checks if there is a current value in the border style block support
|
|
45
|
+
* attributes.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} props Block props.
|
|
48
|
+
* @return {boolean} Whether or not the block has a border style value set.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export function hasBorderStyleValue(props) {
|
|
52
|
+
var _props$attributes$sty, _props$attributes$sty2;
|
|
53
|
+
|
|
54
|
+
return !!((_props$attributes$sty = props.attributes.style) !== null && _props$attributes$sty !== void 0 && (_props$attributes$sty2 = _props$attributes$sty.border) !== null && _props$attributes$sty2 !== void 0 && _props$attributes$sty2.style);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resets the border style block support attribute. This can be used when
|
|
58
|
+
* disabling the border style support control for a block via a progressive
|
|
59
|
+
* discovery panel.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} props Block props.
|
|
62
|
+
* @param {Object} props.attributes Block's attributes.
|
|
63
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
export function resetBorderStyle(_ref) {
|
|
67
|
+
let {
|
|
68
|
+
attributes = {},
|
|
69
|
+
setAttributes
|
|
70
|
+
} = _ref;
|
|
71
|
+
const {
|
|
72
|
+
style
|
|
73
|
+
} = attributes;
|
|
74
|
+
setAttributes({
|
|
75
|
+
style: removeBorderAttribute(style, 'style')
|
|
76
|
+
});
|
|
77
|
+
}
|
|
42
78
|
//# sourceMappingURL=border-style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-style.js"],"names":["BorderStyleControl","cleanEmptyObject","BorderStyleEdit","props","attributes","style","setAttributes","onChange","newBorderStyle","newStyleAttributes","border"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,kBAAP,MAA+B,oCAA/B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAAKC,KAAF,IAAa;AAAA;;AAC3C,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA;AAAF,KADP;AAELC,IAAAA;AAFK,MAGFH,KAHJ;;AAKA,QAAMI,QAAQ,GAAKC,cAAF,IAAsB;AACtC,UAAMC,kBAAkB,GAAG,EAC1B,GAAGJ,KADuB;AAE1BK,MAAAA,MAAM,EAAE,EACP,IAAGL,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAEK,MAAV,CADO;AAEPL,QAAAA,KAAK,EAAEG;AAFA;AAFkB,KAA3B;AAQAF,IAAAA,aAAa,CAAE;AAAED,MAAAA,KAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-style.js"],"names":["BorderStyleControl","cleanEmptyObject","removeBorderAttribute","BorderStyleEdit","props","attributes","style","setAttributes","onChange","newBorderStyle","newStyleAttributes","border","hasBorderStyleValue","resetBorderStyle"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,kBAAP,MAA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B,CAAEI,KAAF,EAAS,OAAT;AAA9B,GAAF,CAAb;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport BorderStyleControl from '../components/border-style-control';\nimport { cleanEmptyObject } from './utils';\nimport { removeBorderAttribute } from './border';\n\n/**\n * Inspector control for configuring border style property.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border style edit element.\n */\nexport const BorderStyleEdit = ( props ) => {\n\tconst {\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst onChange = ( newBorderStyle ) => {\n\t\tconst newStyleAttributes = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tstyle: newBorderStyle,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( { style: cleanEmptyObject( newStyleAttributes ) } );\n\t};\n\n\treturn (\n\t\t<BorderStyleControl\n\t\t\tvalue={ style?.border?.style }\n\t\t\tonChange={ onChange }\n\t\t/>\n\t);\n};\n\n/**\n * Checks if there is a current value in the border style block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border style value set.\n */\nexport function hasBorderStyleValue( props ) {\n\treturn !! props.attributes.style?.border?.style;\n}\n\n/**\n * Resets the border style block support attribute. This can be used when\n * disabling the border style support control for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderStyle( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\tsetAttributes( { style: removeBorderAttribute( style, 'style' ) } );\n}\n"]}
|
|
@@ -4,13 +4,14 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { __experimentalUnitControl as UnitControl, __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';
|
|
7
|
-
import {
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { cleanEmptyObject } from './utils';
|
|
14
|
+
import { removeBorderAttribute } from './border';
|
|
14
15
|
import useSetting from '../components/use-setting';
|
|
15
16
|
const MIN_BORDER_WIDTH = 0;
|
|
16
17
|
/**
|
|
@@ -33,24 +34,12 @@ export const BorderWidthEdit = props => {
|
|
|
33
34
|
width,
|
|
34
35
|
color: customBorderColor,
|
|
35
36
|
style: borderStyle
|
|
36
|
-
} = (style === null || style === void 0 ? void 0 : style.border) || {};
|
|
37
|
-
|
|
38
|
-
const [colorSelection, setColorSelection] = useState(); // Temporarily track previous border color & style selections to be able to
|
|
39
|
-
// restore them when border width changes from zero value.
|
|
37
|
+
} = (style === null || style === void 0 ? void 0 : style.border) || {}; // Used to temporarily track previous border color & style selections to be
|
|
38
|
+
// able to restore them when border width changes from zero value.
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}, [borderStyle]);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (borderColor || customBorderColor) {
|
|
48
|
-
setColorSelection({
|
|
49
|
-
name: !!borderColor ? borderColor : undefined,
|
|
50
|
-
color: !!customBorderColor ? customBorderColor : undefined
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}, [borderColor, customBorderColor]);
|
|
40
|
+
const [styleSelection, setStyleSelection] = useState();
|
|
41
|
+
const [colorSelection, setColorSelection] = useState();
|
|
42
|
+
const [customColorSelection, setCustomColorSelection] = useState();
|
|
54
43
|
|
|
55
44
|
const onChange = newWidth => {
|
|
56
45
|
let newStyle = { ...style,
|
|
@@ -60,28 +49,38 @@ export const BorderWidthEdit = props => {
|
|
|
60
49
|
}; // Used to clear named border color attribute.
|
|
61
50
|
|
|
62
51
|
let borderPaletteColor = borderColor;
|
|
63
|
-
const hasZeroWidth = parseFloat(newWidth) === 0;
|
|
52
|
+
const hasZeroWidth = parseFloat(newWidth) === 0;
|
|
53
|
+
const hadPreviousZeroWidth = parseFloat(width) === 0; // Setting the border width explicitly to zero will also set the
|
|
64
54
|
// border style to `none` and clear border color attributes.
|
|
65
55
|
|
|
66
|
-
if (hasZeroWidth) {
|
|
56
|
+
if (hasZeroWidth && !hadPreviousZeroWidth) {
|
|
57
|
+
// Before clearing color and style selections, keep track of
|
|
58
|
+
// the current selections so they can be restored when the width
|
|
59
|
+
// changes to a non-zero value.
|
|
60
|
+
setColorSelection(borderColor);
|
|
61
|
+
setCustomColorSelection(customBorderColor);
|
|
62
|
+
setStyleSelection(borderStyle); // Clear style and color attributes.
|
|
63
|
+
|
|
67
64
|
borderPaletteColor = undefined;
|
|
68
65
|
newStyle.border.color = undefined;
|
|
69
66
|
newStyle.border.style = 'none';
|
|
70
|
-
}
|
|
71
|
-
// border style was 'none'. This is to support changes to the UI which
|
|
72
|
-
// change the border style UI to a segmented control without a "none"
|
|
73
|
-
// option.
|
|
74
|
-
|
|
67
|
+
}
|
|
75
68
|
|
|
76
|
-
if (!hasZeroWidth &&
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
if (!hasZeroWidth && hadPreviousZeroWidth) {
|
|
70
|
+
// Restore previous border style selection if width is now not zero and
|
|
71
|
+
// border style was 'none'. This is to support changes to the UI which
|
|
72
|
+
// change the border style UI to a segmented control without a "none"
|
|
73
|
+
// option.
|
|
74
|
+
if (borderStyle === 'none') {
|
|
75
|
+
newStyle.border.style = styleSelection;
|
|
76
|
+
} // Restore previous border color selection if width is no longer zero
|
|
77
|
+
// and current border color is undefined.
|
|
80
78
|
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
if (borderColor === undefined) {
|
|
81
|
+
borderPaletteColor = colorSelection;
|
|
82
|
+
newStyle.border.color = customColorSelection;
|
|
83
|
+
}
|
|
85
84
|
} // If width was reset, clean out undefined styles.
|
|
86
85
|
|
|
87
86
|
|
|
@@ -106,4 +105,39 @@ export const BorderWidthEdit = props => {
|
|
|
106
105
|
units: units
|
|
107
106
|
});
|
|
108
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Checks if there is a current value in the border width block support
|
|
110
|
+
* attributes.
|
|
111
|
+
*
|
|
112
|
+
* @param {Object} props Block props.
|
|
113
|
+
* @return {boolean} Whether or not the block has a border width value set.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
export function hasBorderWidthValue(props) {
|
|
117
|
+
var _props$attributes$sty, _props$attributes$sty2;
|
|
118
|
+
|
|
119
|
+
return !!((_props$attributes$sty = props.attributes.style) !== null && _props$attributes$sty !== void 0 && (_props$attributes$sty2 = _props$attributes$sty.border) !== null && _props$attributes$sty2 !== void 0 && _props$attributes$sty2.width);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Resets the border width block support attribute. This can be used when
|
|
123
|
+
* disabling the border width support control for a block via a progressive
|
|
124
|
+
* discovery panel.
|
|
125
|
+
*
|
|
126
|
+
* @param {Object} props Block props.
|
|
127
|
+
* @param {Object} props.attributes Block's attributes.
|
|
128
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
export function resetBorderWidth(_ref) {
|
|
132
|
+
let {
|
|
133
|
+
attributes = {},
|
|
134
|
+
setAttributes
|
|
135
|
+
} = _ref;
|
|
136
|
+
const {
|
|
137
|
+
style
|
|
138
|
+
} = attributes;
|
|
139
|
+
setAttributes({
|
|
140
|
+
style: removeBorderAttribute(style, 'width')
|
|
141
|
+
});
|
|
142
|
+
}
|
|
109
143
|
//# sourceMappingURL=border-width.js.map
|