@wordpress/block-editor 14.3.1 → 14.3.3
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 +2 -2
- package/build/components/block-heading-level-dropdown/index.js +3 -1
- package/build/components/block-heading-level-dropdown/index.js.map +1 -1
- package/build/components/block-list/block.js +27 -4
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +0 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -4
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build/components/block-list/zoom-out-separator.js +18 -1
- package/build/components/block-list/zoom-out-separator.js.map +1 -1
- package/build/components/block-switcher/utils.js +1 -1
- package/build/components/block-switcher/utils.js.map +1 -1
- package/build/components/block-tools/zoom-out-toolbar.js +5 -2
- package/build/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +12 -6
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/rich-text/event-listeners/paste-handler.js +2 -13
- package/build/components/rich-text/event-listeners/paste-handler.js.map +1 -1
- package/build/components/rich-text/index.js +34 -20
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/tool-selector/index.js +2 -1
- package/build/components/tool-selector/index.js.map +1 -1
- package/build/components/writing-flow/index.js +1 -2
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +1 -4
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-input.js +1 -31
- package/build/components/writing-flow/use-input.js.map +1 -1
- package/build/components/writing-flow/use-select-all.js +1 -14
- package/build/components/writing-flow/use-select-all.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +2 -6
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/components/writing-flow/utils.js +0 -27
- package/build/components/writing-flow/utils.js.map +1 -1
- package/build/hooks/layout.js +12 -8
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +22 -28
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/use-zoom-out.js +20 -23
- package/build/hooks/use-zoom-out.js.map +1 -1
- package/build/store/private-actions.js +25 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +22 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +21 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +12 -5
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/index.js +3 -1
- package/build-module/components/block-heading-level-dropdown/index.js.map +1 -1
- package/build-module/components/block-list/block.js +28 -7
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +0 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -4
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build-module/components/block-list/zoom-out-separator.js +18 -1
- package/build-module/components/block-list/zoom-out-separator.js.map +1 -1
- package/build-module/components/block-switcher/utils.js +1 -1
- package/build-module/components/block-switcher/utils.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-toolbar.js +5 -2
- package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +12 -6
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/rich-text/event-listeners/paste-handler.js +2 -13
- package/build-module/components/rich-text/event-listeners/paste-handler.js.map +1 -1
- package/build-module/components/rich-text/index.js +34 -20
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/tool-selector/index.js +2 -1
- package/build-module/components/tool-selector/index.js.map +1 -1
- package/build-module/components/writing-flow/index.js +1 -2
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +1 -4
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-input.js +1 -31
- package/build-module/components/writing-flow/use-input.js.map +1 -1
- package/build-module/components/writing-flow/use-select-all.js +1 -14
- package/build-module/components/writing-flow/use-select-all.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +2 -6
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/components/writing-flow/utils.js +0 -26
- package/build-module/components/writing-flow/utils.js.map +1 -1
- package/build-module/hooks/layout.js +13 -9
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +22 -28
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/use-zoom-out.js +20 -23
- package/build-module/hooks/use-zoom-out.js.map +1 -1
- package/build-module/store/private-actions.js +23 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +20 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +20 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +12 -5
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +10 -0
- package/build-style/content.css +10 -0
- package/build-style/style-rtl.css +4 -0
- package/build-style/style.css +4 -0
- package/package.json +20 -20
- package/src/components/block-heading-level-dropdown/index.js +7 -1
- package/src/components/block-list/block.js +47 -11
- package/src/components/block-list/content.scss +12 -0
- package/src/components/block-list/use-block-props/use-focus-first-element.js +0 -1
- package/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js +7 -3
- package/src/components/block-list/zoom-out-separator.js +14 -1
- package/src/components/block-switcher/test/use-transformed.patterns.js +3 -3
- package/src/components/block-switcher/test/utils.js +3 -3
- package/src/components/block-switcher/utils.js +1 -1
- package/src/components/block-toolbar/style.scss +7 -0
- package/src/components/block-tools/zoom-out-toolbar.js +5 -2
- package/src/components/block-variation-transforms/index.js +13 -4
- package/src/components/rich-text/event-listeners/paste-handler.js +2 -7
- package/src/components/rich-text/index.js +36 -23
- package/src/components/tool-selector/index.js +4 -1
- package/src/components/writing-flow/index.js +0 -2
- package/src/components/writing-flow/use-arrow-nav.js +2 -9
- package/src/components/writing-flow/use-input.js +1 -36
- package/src/components/writing-flow/use-select-all.js +1 -18
- package/src/components/writing-flow/use-selection-observer.js +3 -14
- package/src/components/writing-flow/utils.js +0 -30
- package/src/hooks/layout.js +17 -12
- package/src/hooks/use-bindings-attributes.js +26 -32
- package/src/hooks/use-zoom-out.js +21 -27
- package/src/store/private-actions.js +23 -0
- package/src/store/private-selectors.js +20 -0
- package/src/store/reducer.js +20 -0
- package/src/store/selectors.js +13 -8
- package/src/store/test/private-selectors.js +2 -2
- package/src/store/test/selectors.js +10 -6
- package/build/components/writing-flow/use-event-redirect.js +0 -66
- package/build/components/writing-flow/use-event-redirect.js.map +0 -1
- package/build-module/components/writing-flow/use-event-redirect.js +0 -60
- package/build-module/components/writing-flow/use-event-redirect.js.map +0 -1
- package/src/components/writing-flow/use-event-redirect.js +0 -72
|
@@ -11,7 +11,6 @@ import { useRefEffect } from '@wordpress/compose';
|
|
|
11
11
|
*/
|
|
12
12
|
import { getBlockClientId, isInSameBlock } from '../../utils/dom';
|
|
13
13
|
import { store as blockEditorStore } from '../../store';
|
|
14
|
-
import { getSelectionRoot } from './utils';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Returns true if the element should consider edge navigation upon a keyboard
|
|
@@ -140,6 +139,7 @@ export default function useArrowNav() {
|
|
|
140
139
|
}
|
|
141
140
|
const {
|
|
142
141
|
keyCode,
|
|
142
|
+
target,
|
|
143
143
|
shiftKey,
|
|
144
144
|
ctrlKey,
|
|
145
145
|
altKey,
|
|
@@ -185,7 +185,6 @@ export default function useArrowNav() {
|
|
|
185
185
|
}
|
|
186
186
|
return;
|
|
187
187
|
}
|
|
188
|
-
const target = ownerDocument.activeElement === node ? getSelectionRoot(ownerDocument) : event.target;
|
|
189
188
|
|
|
190
189
|
// Abort if our current target is not a candidate for navigation
|
|
191
190
|
// (e.g. preserve native input behaviors).
|
|
@@ -222,7 +221,6 @@ export default function useArrowNav() {
|
|
|
222
221
|
// When Alt is pressed, only intercept if the caret is also at
|
|
223
222
|
// the horizontal edge.
|
|
224
223
|
altKey ? isHorizontalEdge(target, isReverseDir) : true) && !keepCaretInsideBlock) {
|
|
225
|
-
node.contentEditable = false;
|
|
226
224
|
const closestTabbable = getClosestTabbable(target, isReverse, node, true);
|
|
227
225
|
if (closestTabbable) {
|
|
228
226
|
placeCaretAtVerticalEdge(closestTabbable,
|
|
@@ -232,7 +230,6 @@ export default function useArrowNav() {
|
|
|
232
230
|
event.preventDefault();
|
|
233
231
|
}
|
|
234
232
|
} else if (isHorizontal && defaultView.getSelection().isCollapsed && isHorizontalEdge(target, isReverseDir) && !keepCaretInsideBlock) {
|
|
235
|
-
node.contentEditable = false;
|
|
236
233
|
const closestTabbable = getClosestTabbable(target, isReverseDir, node);
|
|
237
234
|
placeCaretAtHorizontalEdge(closestTabbable, isReverse);
|
|
238
235
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useDispatch","useSelect","useRefEffect","getBlockClientId","isInSameBlock","store","blockEditorStore","getSelectionRoot","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","elementType","getAttribute","verticalInputTypes","includes","simpleInputTypes","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","closest","children","length","firstElementChild","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getSettings","hasMultiSelection","__unstableIsFullySelected","selectBlock","verticalRect","onMouseDown","isClosestTabbableABlock","closestTabbable","onKeyDown","event","defaultPrevented","shiftKey","ctrlKey","altKey","metaKey","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isNavEdge","ownerDocument","defaultView","preventDefault","activeElement","isReverseDir","keepCaretInsideBlock","undefined","getSelection","isCollapsed","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId, isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\nimport { getSelectionRoot } from './utils';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\tconst { tagName } = element;\n\tconst elementType = element.getAttribute( 'type' );\n\n\t// Native inputs should not navigate vertically, unless they are simple types that don't need up/down arrow keys.\n\tif ( isVertical && ! hasModifier ) {\n\t\tif ( tagName === 'INPUT' ) {\n\t\t\tconst verticalInputTypes = [\n\t\t\t\t'date',\n\t\t\t\t'datetime-local',\n\t\t\t\t'month',\n\t\t\t\t'number',\n\t\t\t\t'range',\n\t\t\t\t'time',\n\t\t\t\t'week',\n\t\t\t];\n\t\t\treturn ! verticalInputTypes.includes( elementType );\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'number',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( elementType );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\tif ( node.closest( '[inert]' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Skip if there's only one child that is content editable (and thus a\n\t\t// better candidate).\n\t\tif (\n\t\t\tnode.children.length === 1 &&\n\t\t\tisInSameBlock( node, node.firstElementChild ) &&\n\t\t\tnode.firstElementChild.getAttribute( 'contenteditable' ) === 'true'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction isClosestTabbableABlock( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { keyCode, shiftKey, ctrlKey, altKey, metaKey } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst hasModifier = shiftKey || ctrlKey || altKey || metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst target =\n\t\t\t\townerDocument.activeElement === node\n\t\t\t\t\t? getSelectionRoot( ownerDocument )\n\t\t\t\t\t: event.target;\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\n\t\t\tif ( shiftKey ) {\n\t\t\t\tif (\n\t\t\t\t\tisClosestTabbableABlock( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t// When Alt is pressed, only intercept if the caret is also at\n\t\t\t\t// the horizontal edge.\n\t\t\t\t( altKey ? isHorizontalEdge( target, isReverseDir ) : true ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\t// When Alt is pressed, place the caret at the furthest\n\t\t\t\t\t\t// horizontal edge and the furthest vertical edge.\n\t\t\t\t\t\taltKey ? ! isReverse : isReverse,\n\t\t\t\t\t\taltKey ? undefined : verticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBAAgB,EAChBC,KAAK,EACLC,gBAAgB,EAChBC,cAAc,EACdC,0BAA0B,EAC1BC,wBAAwB,EACxBC,KAAK,QACC,gBAAgB;AACvB,SAASC,EAAE,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,QAAQ,qBAAqB;AAC3D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;;AAEjD;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAiB;AACjE,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,gBAAgB,QAAQ,SAAS;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAEC,OAAO,EAAEC,OAAO,EAAEC,WAAW,EAAG;EACtE,MAAMC,UAAU,GAAGF,OAAO,KAAKd,EAAE,IAAIc,OAAO,KA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C5B,MAAMc,eAAe,GAAGpC,kBAAkB,CACzCC,MAAM,EACNC,SAAS,EACTY,IAAI,EACJ,IACD,CAAC;QAED,IAAKsB,eAAe,EAAG;UACtB7D,wBAAwB,CACvB6D,eAAe;UACf;UACA;UACAM,MAAM,GAAG,CAAExC,SAAS,GAAGA,SAAS,EAChCwC,MAAM,GAAGe,SAAS,GAAGxB,YACtB,CAAC;UACDK,KAAK,CAACe,cAAc,CAAC,CAAC;QACvB;MACD,CAAC,MAAM,IACNL,YAAY,IACZI,WAAW,CAACM,YAAY,CAAC,CAAC,CAACC,WAAW,IACtCvF,gBAAgB,CAAE6B,MAAM,EAAEsD,YAAa,CAAC,IACxC,CAAEC,oBAAoB,EACrB;QACD1C,IAAI,CAACQ,eAAe,GAAG,KAAK;QAC5B,MAAMc,eAAe,GAAGpC,kBAAkB,CACzCC,MAAM,EACNsD,YAAY,EACZzC,IACD,CAAC;QACDxC,0BAA0B,CAAE8D,eAAe,EAAElC,SAAU,CAAC;QACxDoC,KAAK,CAACe,cAAc,CAAC,CAAC;MACvB;IACD;IAEAvC,IAAI,CAAC8C,gBAAgB,CAAE,WAAW,EAAE1B,WAAY,CAAC;IACjDpB,IAAI,CAAC8C,gBAAgB,CAAE,SAAS,EAAEvB,SAAU,CAAC;IAC7C,OAAO,MAAM;MACZvB,IAAI,CAAC+C,mBAAmB,CAAE,WAAW,EAAE3B,WAAY,CAAC;MACpDpB,IAAI,CAAC+C,mBAAmB,CAAE,SAAS,EAAExB,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useDispatch","useSelect","useRefEffect","getBlockClientId","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","elementType","getAttribute","verticalInputTypes","includes","simpleInputTypes","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","closest","children","length","firstElementChild","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getSettings","hasMultiSelection","__unstableIsFullySelected","selectBlock","verticalRect","onMouseDown","isClosestTabbableABlock","closestTabbable","onKeyDown","event","defaultPrevented","shiftKey","ctrlKey","altKey","metaKey","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isNavEdge","ownerDocument","defaultView","preventDefault","isReverseDir","keepCaretInsideBlock","undefined","getSelection","isCollapsed","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId, isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\tconst { tagName } = element;\n\tconst elementType = element.getAttribute( 'type' );\n\n\t// Native inputs should not navigate vertically, unless they are simple types that don't need up/down arrow keys.\n\tif ( isVertical && ! hasModifier ) {\n\t\tif ( tagName === 'INPUT' ) {\n\t\t\tconst verticalInputTypes = [\n\t\t\t\t'date',\n\t\t\t\t'datetime-local',\n\t\t\t\t'month',\n\t\t\t\t'number',\n\t\t\t\t'range',\n\t\t\t\t'time',\n\t\t\t\t'week',\n\t\t\t];\n\t\t\treturn ! verticalInputTypes.includes( elementType );\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'number',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( elementType );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\tif ( node.closest( '[inert]' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Skip if there's only one child that is content editable (and thus a\n\t\t// better candidate).\n\t\tif (\n\t\t\tnode.children.length === 1 &&\n\t\t\tisInSameBlock( node, node.firstElementChild ) &&\n\t\t\tnode.firstElementChild.getAttribute( 'contenteditable' ) === 'true'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction isClosestTabbableABlock( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { keyCode, target, shiftKey, ctrlKey, altKey, metaKey } =\n\t\t\t\tevent;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst hasModifier = shiftKey || ctrlKey || altKey || metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\n\t\t\tif ( shiftKey ) {\n\t\t\t\tif (\n\t\t\t\t\tisClosestTabbableABlock( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t// When Alt is pressed, only intercept if the caret is also at\n\t\t\t\t// the horizontal edge.\n\t\t\t\t( altKey ? isHorizontalEdge( target, isReverseDir ) : true ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\t// When Alt is pressed, place the caret at the furthest\n\t\t\t\t\t\t// horizontal edge and the furthest vertical edge.\n\t\t\t\t\t\taltKey ? ! isReverse : isReverse,\n\t\t\t\t\t\taltKey ? undefined : verticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBAAgB,EAChBC,KAAK,EACLC,gBAAgB,EAChBC,cAAc,EACdC,0BAA0B,EAC1BC,wBAAwB,EACxBC,KAAK,QACC,gBAAgB;AACvB,SAASC,EAAE,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,QAAQ,qBAAqB;AAC3D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;;AAEjD;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAiB;AACjE,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAEC,OAAO,EAAEC,OAAO,EAAEC,WAAW,EAAG;E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AAKsB,eAAe,EAAG;UACtB5D,wBAAwB,CACvB4D,eAAe;UACf;UACA;UACAM,MAAM,GAAG,CAAExC,SAAS,GAAGA,SAAS,EAChCwC,MAAM,GAAGc,SAAS,GAAGvB,YACtB,CAAC;UACDK,KAAK,CAACe,cAAc,CAAC,CAAC;QACvB;MACD,CAAC,MAAM,IACNL,YAAY,IACZI,WAAW,CAACK,YAAY,CAAC,CAAC,CAACC,WAAW,IACtCrF,gBAAgB,CAAE4B,MAAM,EAAEqD,YAAa,CAAC,IACxC,CAAEC,oBAAoB,EACrB;QACD,MAAMnB,eAAe,GAAGpC,kBAAkB,CACzCC,MAAM,EACNqD,YAAY,EACZxC,IACD,CAAC;QACDvC,0BAA0B,CAAE6D,eAAe,EAAElC,SAAU,CAAC;QACxDoC,KAAK,CAACe,cAAc,CAAC,CAAC;MACvB;IACD;IAEAvC,IAAI,CAAC6C,gBAAgB,CAAE,WAAW,EAAEzB,WAAY,CAAC;IACjDpB,IAAI,CAAC6C,gBAAgB,CAAE,SAAS,EAAEtB,SAAU,CAAC;IAC7C,OAAO,MAAM;MACZvB,IAAI,CAAC8C,mBAAmB,CAAE,WAAW,EAAE1B,WAAY,CAAC;MACpDpB,IAAI,CAAC8C,mBAAmB,CAAE,SAAS,EAAEvB,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
@@ -10,7 +10,6 @@ import { createBlock, getDefaultBlockName, hasBlockSupport, getBlockTransforms,
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import { store as blockEditorStore } from '../../store';
|
|
13
|
-
import { getSelectionRoot } from './utils';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Handles input for selections across blocks.
|
|
@@ -43,22 +42,7 @@ export default function useInput() {
|
|
|
43
42
|
// DOM. This will cause React errors (and the DOM should only be
|
|
44
43
|
// altered in a controlled fashion).
|
|
45
44
|
if (node.contentEditable === 'true') {
|
|
46
|
-
|
|
47
|
-
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
48
|
-
const root = getSelectionRoot(node.ownerDocument);
|
|
49
|
-
|
|
50
|
-
// If selection is contained within a nested editable, allow
|
|
51
|
-
// input. We need to ensure that selection is maintained.
|
|
52
|
-
if (root) {
|
|
53
|
-
node.contentEditable = false;
|
|
54
|
-
root.focus();
|
|
55
|
-
selection.removeAllRanges();
|
|
56
|
-
if (range) {
|
|
57
|
-
selection.addRange(range);
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
event.preventDefault();
|
|
61
|
-
}
|
|
45
|
+
event.preventDefault();
|
|
62
46
|
}
|
|
63
47
|
}
|
|
64
48
|
function onKeyDown(event) {
|
|
@@ -66,20 +50,6 @@ export default function useInput() {
|
|
|
66
50
|
return;
|
|
67
51
|
}
|
|
68
52
|
if (!hasMultiSelection()) {
|
|
69
|
-
const {
|
|
70
|
-
ownerDocument
|
|
71
|
-
} = node;
|
|
72
|
-
if (node === ownerDocument.activeElement) {
|
|
73
|
-
if (event.key === 'End' || event.key === 'Home') {
|
|
74
|
-
const selectionRoot = getSelectionRoot(ownerDocument);
|
|
75
|
-
const selection = ownerDocument.defaultView.getSelection();
|
|
76
|
-
selection.selectAllChildren(selectionRoot);
|
|
77
|
-
const method = event.key === 'End' ? 'collapseToEnd' : 'collapseToStart';
|
|
78
|
-
selection[method]();
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
53
|
if (event.keyCode === ENTER) {
|
|
84
54
|
if (event.shiftKey || __unstableIsFullySelected()) {
|
|
85
55
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useDispatch","useRefEffect","ENTER","BACKSPACE","DELETE","createBlock","getDefaultBlockName","hasBlockSupport","getBlockTransforms","findTransform","store","blockEditorStore","getSelectionRoot","useInput","__unstableIsFullySelected","getSelectedBlockClientIds","getSelectedBlockClientId","__unstableIsSelectionMergeable","hasMultiSelection","getBlockName","canInsertBlockType","getBlockRootClientId","getSelectionStart","getSelectionEnd","getBlockAttributes","replaceBlocks","__unstableSplitSelection","removeBlocks","__unstableDeleteSelection","__unstableExpandSelection","__unstableMarkAutomaticChange","node","onBeforeInput","event","contentEditable","selection","ownerDocument","defaultView","getSelection","range","rangeCount","getRangeAt","root","focus","removeAllRanges","addRange","preventDefault","onKeyDown","defaultPrevented","activeElement","key","selectionRoot","selectAllChildren","method","keyCode","shiftKey","clientId","blockName","selectionStart","selectionEnd","attributeKey","selectedAttributeValue","transforms","filter","type","transformation","item","regExp","test","transform","content","__deprecatedOnSplit","length","metaKey","ctrlKey","onCompositionStart","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-input.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';\nimport {\n\tcreateBlock,\n\tgetDefaultBlockName,\n\thasBlockSupport,\n\tgetBlockTransforms,\n\tfindTransform,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getSelectionRoot } from './utils';\n\n/**\n * Handles input for selections across blocks.\n */\nexport default function useInput() {\n\tconst {\n\t\t__unstableIsFullySelected,\n\t\tgetSelectedBlockClientIds,\n\t\tgetSelectedBlockClientId,\n\t\t__unstableIsSelectionMergeable,\n\t\thasMultiSelection,\n\t\tgetBlockName,\n\t\tcanInsertBlockType,\n\t\tgetBlockRootClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlockAttributes,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\treplaceBlocks,\n\t\t__unstableSplitSelection,\n\t\tremoveBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction onBeforeInput( event ) {\n\t\t\t// If writing flow is editable, NEVER allow the browser to alter the\n\t\t\t// DOM. This will cause React errors (and the DOM should only be\n\t\t\t// altered in a controlled fashion).\n\t\t\tif ( node.contentEditable === 'true' ) {\n\t\t\t\tconst selection = node.ownerDocument.defaultView.getSelection();\n\t\t\t\tconst range = selection.rangeCount\n\t\t\t\t\t? selection.getRangeAt( 0 )\n\t\t\t\t\t: null;\n\t\t\t\tconst root = getSelectionRoot( node.ownerDocument );\n\n\t\t\t\t// If selection is contained within a nested editable, allow\n\t\t\t\t// input. We need to ensure that selection is maintained.\n\t\t\t\tif ( root ) {\n\t\t\t\t\tnode.contentEditable = false;\n\t\t\t\t\troot.focus();\n\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\tif ( range ) {\n\t\t\t\t\t\tselection.addRange( range );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tconst { ownerDocument } = node;\n\t\t\t\tif ( node === ownerDocument.activeElement ) {\n\t\t\t\t\tif ( event.key === 'End' || event.key === 'Home' ) {\n\t\t\t\t\t\tconst selectionRoot = getSelectionRoot( ownerDocument );\n\t\t\t\t\t\tconst selection =\n\t\t\t\t\t\t\townerDocument.defaultView.getSelection();\n\t\t\t\t\t\tselection.selectAllChildren( selectionRoot );\n\t\t\t\t\t\tconst method =\n\t\t\t\t\t\t\tevent.key === 'End'\n\t\t\t\t\t\t\t\t? 'collapseToEnd'\n\t\t\t\t\t\t\t\t: 'collapseToStart';\n\t\t\t\t\t\tselection[ method ]();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( event.keyCode === ENTER ) {\n\t\t\t\t\tif ( event.shiftKey || __unstableIsFullySelected() ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst clientId = getSelectedBlockClientId();\n\t\t\t\t\tconst blockName = getBlockName( clientId );\n\t\t\t\t\tconst selectionStart = getSelectionStart();\n\t\t\t\t\tconst selectionEnd = getSelectionEnd();\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectionStart.attributeKey ===\n\t\t\t\t\t\tselectionEnd.attributeKey\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst selectedAttributeValue =\n\t\t\t\t\t\t\tgetBlockAttributes( clientId )[\n\t\t\t\t\t\t\t\tselectionStart.attributeKey\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\tconst transforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t\t\t\t( { type } ) => type === 'enter'\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\t\t\ttransforms,\n\t\t\t\t\t\t\t( item ) => {\n\t\t\t\t\t\t\t\treturn item.regExp.test(\n\t\t\t\t\t\t\t\t\tselectedAttributeValue\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( transformation ) {\n\t\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\ttransformation.transform( {\n\t\t\t\t\t\t\t\t\tcontent: selectedAttributeValue,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t! hasBlockSupport( blockName, 'splitting', false ) &&\n\t\t\t\t\t\t! event.__deprecatedOnSplit\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Ensure template is not locked.\n\t\t\t\t\tif (\n\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t__unstableSplitSelection();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode === ENTER ) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\tgetSelectedBlockClientIds(),\n\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t__unstableSplitSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tevent.keyCode === BACKSPACE ||\n\t\t\t\tevent.keyCode === DELETE\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\tremoveBlocks( getSelectedBlockClientIds() );\n\t\t\t\t} else if ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\t// If key.length is longer than 1, it's a control key that doesn't\n\t\t\t\t// input anything.\n\t\t\t\tevent.key.length === 1 &&\n\t\t\t\t! ( event.metaKey || event.ctrlKey )\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\t\tnode.ownerDocument.defaultView\n\t\t\t\t\t\t.getSelection()\n\t\t\t\t\t\t.removeAllRanges();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onCompositionStart( event ) {\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tnode.contentEditable = false;\n\n\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t__unstableDeleteSelection();\n\t\t\t} else {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\tnode.ownerDocument.defaultView.getSelection().removeAllRanges();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'beforeinput', onBeforeInput );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'compositionstart', onCompositionStart );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'beforeinput', onBeforeInput );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'compositionstart', onCompositionStart );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,KAAK,EAAEC,SAAS,EAAEC,MAAM,QAAQ,qBAAqB;AAC9D,SACCC,WAAW,EACXC,mBAAmB,EACnBC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QACP,mBAAmB;;AAE1B;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,gBAAgB,QAAQ,SAAS;;AAE1C;AACA;AACA;AACA,eAAe,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DhB,IAAI,CAAC8C,mBAAmB,CAAE,kBAAkB,EAAEF,kBAAmB,CAAC;IACnE,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","useRefEffect","ENTER","BACKSPACE","DELETE","createBlock","getDefaultBlockName","hasBlockSupport","getBlockTransforms","findTransform","store","blockEditorStore","useInput","__unstableIsFullySelected","getSelectedBlockClientIds","getSelectedBlockClientId","__unstableIsSelectionMergeable","hasMultiSelection","getBlockName","canInsertBlockType","getBlockRootClientId","getSelectionStart","getSelectionEnd","getBlockAttributes","replaceBlocks","__unstableSplitSelection","removeBlocks","__unstableDeleteSelection","__unstableExpandSelection","__unstableMarkAutomaticChange","node","onBeforeInput","event","contentEditable","preventDefault","onKeyDown","defaultPrevented","keyCode","shiftKey","clientId","blockName","selectionStart","selectionEnd","attributeKey","selectedAttributeValue","transforms","filter","type","transformation","item","regExp","test","transform","content","__deprecatedOnSplit","key","length","metaKey","ctrlKey","ownerDocument","defaultView","getSelection","removeAllRanges","onCompositionStart","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-input.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';\nimport {\n\tcreateBlock,\n\tgetDefaultBlockName,\n\thasBlockSupport,\n\tgetBlockTransforms,\n\tfindTransform,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Handles input for selections across blocks.\n */\nexport default function useInput() {\n\tconst {\n\t\t__unstableIsFullySelected,\n\t\tgetSelectedBlockClientIds,\n\t\tgetSelectedBlockClientId,\n\t\t__unstableIsSelectionMergeable,\n\t\thasMultiSelection,\n\t\tgetBlockName,\n\t\tcanInsertBlockType,\n\t\tgetBlockRootClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlockAttributes,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\treplaceBlocks,\n\t\t__unstableSplitSelection,\n\t\tremoveBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction onBeforeInput( event ) {\n\t\t\t// If writing flow is editable, NEVER allow the browser to alter the\n\t\t\t// DOM. This will cause React errors (and the DOM should only be\n\t\t\t// altered in a controlled fashion).\n\t\t\tif ( node.contentEditable === 'true' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tif ( event.keyCode === ENTER ) {\n\t\t\t\t\tif ( event.shiftKey || __unstableIsFullySelected() ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst clientId = getSelectedBlockClientId();\n\t\t\t\t\tconst blockName = getBlockName( clientId );\n\t\t\t\t\tconst selectionStart = getSelectionStart();\n\t\t\t\t\tconst selectionEnd = getSelectionEnd();\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectionStart.attributeKey ===\n\t\t\t\t\t\tselectionEnd.attributeKey\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst selectedAttributeValue =\n\t\t\t\t\t\t\tgetBlockAttributes( clientId )[\n\t\t\t\t\t\t\t\tselectionStart.attributeKey\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\tconst transforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t\t\t\t( { type } ) => type === 'enter'\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\t\t\ttransforms,\n\t\t\t\t\t\t\t( item ) => {\n\t\t\t\t\t\t\t\treturn item.regExp.test(\n\t\t\t\t\t\t\t\t\tselectedAttributeValue\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( transformation ) {\n\t\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\ttransformation.transform( {\n\t\t\t\t\t\t\t\t\tcontent: selectedAttributeValue,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t! hasBlockSupport( blockName, 'splitting', false ) &&\n\t\t\t\t\t\t! event.__deprecatedOnSplit\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Ensure template is not locked.\n\t\t\t\t\tif (\n\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t__unstableSplitSelection();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode === ENTER ) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\tgetSelectedBlockClientIds(),\n\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t__unstableSplitSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tevent.keyCode === BACKSPACE ||\n\t\t\t\tevent.keyCode === DELETE\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( __unstableIsFullySelected() ) {\n\t\t\t\t\tremoveBlocks( getSelectedBlockClientIds() );\n\t\t\t\t} else if ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\t// If key.length is longer than 1, it's a control key that doesn't\n\t\t\t\t// input anything.\n\t\t\t\tevent.key.length === 1 &&\n\t\t\t\t! ( event.metaKey || event.ctrlKey )\n\t\t\t) {\n\t\t\t\tnode.contentEditable = false;\n\t\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t\t__unstableDeleteSelection( event.keyCode === DELETE );\n\t\t\t\t} else {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\t\tnode.ownerDocument.defaultView\n\t\t\t\t\t\t.getSelection()\n\t\t\t\t\t\t.removeAllRanges();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onCompositionStart( event ) {\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tnode.contentEditable = false;\n\n\t\t\tif ( __unstableIsSelectionMergeable() ) {\n\t\t\t\t__unstableDeleteSelection();\n\t\t\t} else {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Safari does not stop default behaviour with either\n\t\t\t\t// event.preventDefault() or node.contentEditable = false, so\n\t\t\t\t// remove the selection to stop browser manipulation.\n\t\t\t\tnode.ownerDocument.defaultView.getSelection().removeAllRanges();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'beforeinput', onBeforeInput );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'compositionstart', onCompositionStart );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'beforeinput', onBeforeInput );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'compositionstart', onCompositionStart );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,KAAK,EAAEC,SAAS,EAAEC,MAAM,QAAQ,qBAAqB;AAC9D,SACCC,WAAW,EACXC,mBAAmB,EACnBC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QACP,mBAAmB;;AAE1B;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA,eAAe,SAASC,QAAQA,CAAA,EAAG;EAClC,MAAM;IACLC,yBAAyB;IACzBC,yBAAyB;IACzBC,wBAAwB;IACxBC,8BAA8B;IAC9BC,iBAAiB;IACjBC,YAAY;IACZC,kBAAkB;IAClBC,oBAAoB;IACpBC,iBAAiB;IACjBC,eAAe;IACfC;EACD,CAAC,GAAGxB,SAAS,CAAEY,gBAAiB,CAAC;EACjC,MAAM;IACLa,aAAa;IACbC,wBAAwB;IACxBC,YAAY;IACZC,yBAAyB;IACzBC,yBAAyB;IACzBC;EACD,CAAC,GAAG7B,WAAW,CAAEW,gBAAiB,CAAC;EAEnC,OAAOV,YAAY,CAAI6B,IAAI,IAAM;IAChC,SAASC,aAAaA,CAAEC,KAAK,EAAG;MAC/B;MACA;MACA;MACA,IAAKF,IAAI,CAACG,eAAe,KAAK,MAAM,EAAG;QACtCD,KAAK,CAACE,cAAc,CAAC,CAAC;MACvB;IACD;IAEA,SAASC,SAASA,CAAEH,KAAK,EAAG;MAC3B,IAAKA,KAAK,CAACI,gBAAgB,EAAG;QAC7B;MACD;MAEA,IAAK,CAAEnB,iBAAiB,CAAC,CAAC,EAAG;QAC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A,CAAE/B,KAAK,EAAG;MACpC,IAAK,CAAEf,iBAAiB,CAAC,CAAC,EAAG;QAC5B;MACD;MAEAa,IAAI,CAACG,eAAe,GAAG,KAAK;MAE5B,IAAKjB,8BAA8B,CAAC,CAAC,EAAG;QACvCW,yBAAyB,CAAC,CAAC;MAC5B,CAAC,MAAM;QACNK,KAAK,CAACE,cAAc,CAAC,CAAC;QACtB;QACA;QACA;QACAJ,IAAI,CAAC6B,aAAa,CAACC,WAAW,CAACC,YAAY,CAAC,CAAC,CAACC,eAAe,CAAC,CAAC;MAChE;IACD;IAEAhC,IAAI,CAACkC,gBAAgB,CAAE,aAAa,EAAEjC,aAAc,CAAC;IACrDD,IAAI,CAACkC,gBAAgB,CAAE,SAAS,EAAE7B,SAAU,CAAC;IAC7CL,IAAI,CAACkC,gBAAgB,CAAE,kBAAkB,EAAED,kBAAmB,CAAC;IAC/D,OAAO,MAAM;MACZjC,IAAI,CAACmC,mBAAmB,CAAE,aAAa,EAAElC,aAAc,CAAC;MACxDD,IAAI,CAACmC,mBAAmB,CAAE,SAAS,EAAE9B,SAAU,CAAC;MAChDL,IAAI,CAACmC,mBAAmB,CAAE,kBAAkB,EAAEF,kBAAmB,CAAC;IACnE,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
@@ -10,7 +10,6 @@ import { useRefEffect } from '@wordpress/compose';
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import { store as blockEditorStore } from '../../store';
|
|
13
|
-
import { getSelectionRoot } from './utils';
|
|
14
13
|
export default function useSelectAll() {
|
|
15
14
|
const {
|
|
16
15
|
getBlockOrder,
|
|
@@ -27,19 +26,8 @@ export default function useSelectAll() {
|
|
|
27
26
|
if (!isMatch('core/block-editor/select-all', event)) {
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
|
-
const selectionRoot = getSelectionRoot(node.ownerDocument);
|
|
31
29
|
const selectedClientIds = getSelectedBlockClientIds();
|
|
32
|
-
|
|
33
|
-
// Abort if there is selection, but it is not within a block.
|
|
34
|
-
if (selectionRoot && !selectedClientIds.length) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (selectionRoot && selectedClientIds.length < 2 && !isEntirelySelected(selectionRoot)) {
|
|
38
|
-
if (node === node.ownerDocument.activeElement) {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
node.ownerDocument.defaultView.getSelection().selectAllChildren(selectionRoot);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
30
|
+
if (selectedClientIds.length < 2 && !isEntirelySelected(event.target)) {
|
|
43
31
|
return;
|
|
44
32
|
}
|
|
45
33
|
event.preventDefault();
|
|
@@ -52,7 +40,6 @@ export default function useSelectAll() {
|
|
|
52
40
|
if (selectedClientIds.length === blockClientIds.length) {
|
|
53
41
|
if (rootClientId) {
|
|
54
42
|
node.ownerDocument.defaultView.getSelection().removeAllRanges();
|
|
55
|
-
node.contentEditable = 'false';
|
|
56
43
|
selectBlock(rootClientId);
|
|
57
44
|
}
|
|
58
45
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isEntirelySelected","useSelect","useDispatch","__unstableUseShortcutEventMatch","useShortcutEventMatch","useRefEffect","store","blockEditorStore","
|
|
1
|
+
{"version":3,"names":["isEntirelySelected","useSelect","useDispatch","__unstableUseShortcutEventMatch","useShortcutEventMatch","useRefEffect","store","blockEditorStore","useSelectAll","getBlockOrder","getSelectedBlockClientIds","getBlockRootClientId","multiSelect","selectBlock","isMatch","node","onKeyDown","event","selectedClientIds","length","target","preventDefault","firstSelectedClientId","rootClientId","blockClientIds","ownerDocument","defaultView","getSelection","removeAllRanges","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-select-all.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isEntirelySelected } from '@wordpress/dom';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordpress/keyboard-shortcuts';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport default function useSelectAll() {\n\tconst { getBlockOrder, getSelectedBlockClientIds, getBlockRootClientId } =\n\t\tuseSelect( blockEditorStore );\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\tconst isMatch = useShortcutEventMatch();\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( ! isMatch( 'core/block-editor/select-all', event ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\n\t\t\tif (\n\t\t\t\tselectedClientIds.length < 2 &&\n\t\t\t\t! isEntirelySelected( event.target )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst [ firstSelectedClientId ] = selectedClientIds;\n\t\t\tconst rootClientId = getBlockRootClientId( firstSelectedClientId );\n\t\t\tconst blockClientIds = getBlockOrder( rootClientId );\n\n\t\t\t// If we have selected all sibling nested blocks, try selecting up a\n\t\t\t// level. See: https://github.com/WordPress/gutenberg/pull/31859/\n\t\t\tif ( selectedClientIds.length === blockClientIds.length ) {\n\t\t\t\tif ( rootClientId ) {\n\t\t\t\t\tnode.ownerDocument.defaultView\n\t\t\t\t\t\t.getSelection()\n\t\t\t\t\t\t.removeAllRanges();\n\t\t\t\t\tselectBlock( rootClientId );\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tmultiSelect(\n\t\t\t\tblockClientIds[ 0 ],\n\t\t\t\tblockClientIds[ blockClientIds.length - 1 ]\n\t\t\t);\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,kBAA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ACD;MAEAX,WAAW,CACVY,cAAc,CAAE,CAAC,CAAE,EACnBA,cAAc,CAAEA,cAAc,CAACL,MAAM,GAAG,CAAC,CAC1C,CAAC;IACF;IAEAJ,IAAI,CAACc,gBAAgB,CAAE,SAAS,EAAEb,SAAU,CAAC;IAE7C,OAAO,MAAM;MACZD,IAAI,CAACe,mBAAmB,CAAE,SAAS,EAAEd,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
@@ -109,8 +109,7 @@ export default function useSelectionObserver() {
|
|
|
109
109
|
const {
|
|
110
110
|
getBlockParents,
|
|
111
111
|
getBlockSelectionStart,
|
|
112
|
-
isMultiSelecting
|
|
113
|
-
getSelectedBlockClientId
|
|
112
|
+
isMultiSelecting
|
|
114
113
|
} = useSelect(blockEditorStore);
|
|
115
114
|
return useRefEffect(node => {
|
|
116
115
|
const {
|
|
@@ -173,13 +172,10 @@ export default function useSelectionObserver() {
|
|
|
173
172
|
setContentEditableWrapper(node, false);
|
|
174
173
|
return;
|
|
175
174
|
}
|
|
176
|
-
setContentEditableWrapper(node, !!(startClientId && endClientId));
|
|
177
175
|
const isSingularSelection = startClientId === endClientId;
|
|
178
176
|
if (isSingularSelection) {
|
|
179
177
|
if (!isMultiSelecting()) {
|
|
180
|
-
|
|
181
|
-
selectBlock(startClientId);
|
|
182
|
-
}
|
|
178
|
+
selectBlock(startClientId);
|
|
183
179
|
} else {
|
|
184
180
|
multiSelect(startClientId, startClientId);
|
|
185
181
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useDispatch","useRefEffect","create","isSelectionForward","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","length","_focusNode$previousSi","previousSibling","parentElement","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","String","focus","getRichTextElement","element","ELEMENT_NODE","closest","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","getBlockSelectionStart","isMultiSelecting","getSelectedBlockClientId","ownerDocument","defaultView","onSelectionChange","event","getSelection","rangeCount","startNode","endNode","contains","isClickShift","shiftKey","type","isCollapsed","startClientId","endClientId","selectedClientId","clickedClientId","target","focusNodeIsNonSelectable","undefined","isSingularSelection","startPath","endPath","richTextElementStart","richTextElementEnd","_richTextDataStart$st","_richTextDataEnd$star","range","getRangeAt","richTextDataStart","__unstableIsEditableTree","richTextDataEnd","startOffset","start","end","endOffset","clientId","attributeKey","dataset","wpBlockAttributeKey","offset","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { create } from '@wordpress/rich-text';\nimport { isSelectionForward } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\n/**\n * Extract the selection start node from the selection. When the anchor node is\n * not a text node, the selection offset is the index of a child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionStartNode( selection ) {\n\tconst { anchorNode, anchorOffset } = selection;\n\n\tif ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {\n\t\treturn anchorNode;\n\t}\n\n\tif ( anchorOffset === 0 ) {\n\t\treturn anchorNode;\n\t}\n\n\treturn anchorNode.childNodes[ anchorOffset - 1 ];\n}\n\n/**\n * Extract the selection end node from the selection. When the focus node is not\n * a text node, the selection offset is the index of a child node. The selection\n * reaches up to but excluding that child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionEndNode( selection ) {\n\tconst { focusNode, focusOffset } = selection;\n\n\tif ( focusNode.nodeType === focusNode.TEXT_NODE ) {\n\t\treturn focusNode;\n\t}\n\n\tif ( focusOffset === focusNode.childNodes.length ) {\n\t\treturn focusNode;\n\t}\n\n\t// When the selection is forward (the selection ends with the focus node),\n\t// the selection may extend into the next element with an offset of 0. This\n\t// may trigger multi selection even though the selection does not visually\n\t// end in the next block.\n\tif ( focusOffset === 0 && isSelectionForward( selection ) ) {\n\t\treturn focusNode.previousSibling ?? focusNode.parentElement;\n\t}\n\n\treturn focusNode.childNodes[ focusOffset ];\n}\n\nfunction findDepth( a, b ) {\n\tlet depth = 0;\n\n\twhile ( a[ depth ] === b[ depth ] ) {\n\t\tdepth++;\n\t}\n\n\treturn depth;\n}\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\t// Since we are calling this on every selection change, check if the value\n\t// needs to be updated first because it trigger the browser to recalculate\n\t// style.\n\tif ( node.contentEditable !== String( value ) ) {\n\t\tnode.contentEditable = value;\n\n\t\t// Firefox doesn't automatically move focus.\n\t\tif ( value ) {\n\t\t\tnode.focus();\n\t\t}\n\t}\n}\n\nfunction getRichTextElement( node ) {\n\tconst element =\n\t\tnode.nodeType === node.ELEMENT_NODE ? node : node.parentElement;\n\treturn element?.closest( '[data-wp-block-attribute-key]' );\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useSelectionObserver() {\n\tconst { multiSelect, selectBlock, selectionChange } =\n\t\tuseDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\tisMultiSelecting,\n\t\tgetSelectedBlockClientId,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange( event ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startNode = extractSelectionStartNode( selection );\n\t\t\t\tconst endNode = extractSelectionEndNode( selection );\n\n\t\t\t\tif (\n\t\t\t\t\t! node.contains( startNode ) ||\n\t\t\t\t\t! node.contains( endNode )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// If selection is collapsed and we haven't used `shift+click`,\n\t\t\t\t// end multi selection and disable the contentEditable wrapper.\n\t\t\t\t// We have to check about `shift+click` case because elements\n\t\t\t\t// that don't support text selection might be involved, and we might\n\t\t\t\t// update the clientIds to multi-select blocks.\n\t\t\t\t// For now we check if the event is a `mouse` event.\n\t\t\t\tconst isClickShift = event.shiftKey && event.type === 'mouseup';\n\t\t\t\tif ( selection.isCollapsed && ! isClickShift ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.contentEditable === 'true' &&\n\t\t\t\t\t\t! isMultiSelecting()\n\t\t\t\t\t) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\t\tlet element =\n\t\t\t\t\t\t\tstartNode.nodeType === startNode.ELEMENT_NODE\n\t\t\t\t\t\t\t\t? startNode\n\t\t\t\t\t\t\t\t: startNode.parentElement;\n\t\t\t\t\t\telement = element?.closest( '[contenteditable]' );\n\t\t\t\t\t\telement?.focus();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet startClientId = getBlockClientId( startNode );\n\t\t\t\tlet endClientId = getBlockClientId( endNode );\n\n\t\t\t\t// If the selection has changed and we had pressed `shift+click`,\n\t\t\t\t// we need to check if in an element that doesn't support\n\t\t\t\t// text selection has been clicked.\n\t\t\t\tif ( isClickShift ) {\n\t\t\t\t\tconst selectedClientId = getBlockSelectionStart();\n\t\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\t\t\t\t\t// `endClientId` is not defined if we end the selection by clicking a non-selectable block.\n\t\t\t\t\t// We need to check if there was already a selection with a non-selectable focusNode.\n\t\t\t\t\tconst focusNodeIsNonSelectable =\n\t\t\t\t\t\tclickedClientId !== endClientId;\n\t\t\t\t\tif (\n\t\t\t\t\t\t( startClientId === endClientId &&\n\t\t\t\t\t\t\tselection.isCollapsed ) ||\n\t\t\t\t\t\t! endClientId ||\n\t\t\t\t\t\tfocusNodeIsNonSelectable\n\t\t\t\t\t) {\n\t\t\t\t\t\tendClientId = clickedClientId;\n\t\t\t\t\t}\n\t\t\t\t\t// Handle the case when we have a non-selectable block\n\t\t\t\t\t// selected and click another one.\n\t\t\t\t\tif ( startClientId !== selectedClientId ) {\n\t\t\t\t\t\tstartClientId = selectedClientId;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the selection did not involve a block, return.\n\t\t\t\tif (\n\t\t\t\t\tstartClientId === undefined &&\n\t\t\t\t\tendClientId === undefined\n\t\t\t\t) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetContentEditableWrapper(\n\t\t\t\t\tnode,\n\t\t\t\t\t!! ( startClientId && endClientId )\n\t\t\t\t);\n\n\t\t\t\tconst isSingularSelection = startClientId === endClientId;\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tif ( ! isMultiSelecting() ) {\n\t\t\t\t\t\tif ( getSelectedBlockClientId() !== startClientId ) {\n\t\t\t\t\t\t\tselectBlock( startClientId );\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmultiSelect( startClientId, startClientId );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( startClientId ),\n\t\t\t\t\t\tstartClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth = findDepth( startPath, endPath );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartPath[ depth ] !== startClientId ||\n\t\t\t\t\t\tendPath[ depth ] !== endClientId\n\t\t\t\t\t) {\n\t\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst richTextElementStart =\n\t\t\t\t\t\tgetRichTextElement( startNode );\n\t\t\t\t\tconst richTextElementEnd = getRichTextElement( endNode );\n\n\t\t\t\t\tif ( richTextElementStart && richTextElementEnd ) {\n\t\t\t\t\t\tconst range = selection.getRangeAt( 0 );\n\t\t\t\t\t\tconst richTextDataStart = create( {\n\t\t\t\t\t\t\telement: richTextElementStart,\n\t\t\t\t\t\t\trange,\n\t\t\t\t\t\t\t__unstableIsEditableTree: true,\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tconst richTextDataEnd = create( {\n\t\t\t\t\t\t\telement: richTextElementEnd,\n\t\t\t\t\t\t\trange,\n\t\t\t\t\t\t\t__unstableIsEditableTree: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\tconst startOffset =\n\t\t\t\t\t\t\trichTextDataStart.start ?? richTextDataStart.end;\n\t\t\t\t\t\tconst endOffset =\n\t\t\t\t\t\t\trichTextDataEnd.start ?? richTextDataEnd.end;\n\t\t\t\t\t\tselectionChange( {\n\t\t\t\t\t\t\tstart: {\n\t\t\t\t\t\t\t\tclientId: startClientId,\n\t\t\t\t\t\t\t\tattributeKey:\n\t\t\t\t\t\t\t\t\trichTextElementStart.dataset\n\t\t\t\t\t\t\t\t\t\t.wpBlockAttributeKey,\n\t\t\t\t\t\t\t\toffset: startOffset,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tend: {\n\t\t\t\t\t\t\t\tclientId: endClientId,\n\t\t\t\t\t\t\t\tattributeKey:\n\t\t\t\t\t\t\t\t\trichTextElementEnd.dataset\n\t\t\t\t\t\t\t\t\t\t.wpBlockAttributeKey,\n\t\t\t\t\t\t\t\toffset: endOffset,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmultiSelect( startClientId, endClientId );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\townerDocument.addEventListener(\n\t\t\t\t'selectionchange',\n\t\t\t\tonSelectionChange\n\t\t\t);\n\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionChange );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,kBAAkB,QAAQ,gBAAgB;;AAEnD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,gBAAgB,QAAQ,iBAAiB;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,yBAAyBA,CAAEC,SAAS,EAAG;EAC/C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAGF,SAAS;EAE9C,IAAKC,UAAU,CAACE,QAAQ,KAAKF,UAAU,CAACG,SAAS,EAAG;IACnD,OAAOH,UAAU;EAClB;EAEA,IAAKC,YAAY,KAAK,CAAC,EAAG;IACzB,OAAOD,UAAU;EAClB;EAEA,OAAOA,UAAU,CAACI,UAAU,CAAEH,YAAY,GAAG,CAAC,CAAE;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,uBAAuBA,CAAEN,SAAS,EAAG;EAC7C,MAAM;IAAEO,SAAS;IAAEC;EAAY,CAAC,GAAGR,SAAS;E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GAAG,EAAE;cACJE,QAAQ,EAAEtB,WAAW;cACrBuB,YAAY,EACXb,kBAAkB,CAACc,OAAO,CACxBC,mBAAmB;cACtBC,MAAM,EAAEL;YACT;UACD,CAAE,CAAC;QACJ,CAAC,MAAM;UACN1C,WAAW,CAAEoB,aAAa,EAAEC,WAAY,CAAC;QAC1C;MACD;IACD;IAEAd,aAAa,CAACyC,gBAAgB,CAC7B,iBAAiB,EACjBvC,iBACD,CAAC;IACDD,WAAW,CAACwC,gBAAgB,CAAE,SAAS,EAAEvC,iBAAkB,CAAC;IAC5D,OAAO,MAAM;MACZF,aAAa,CAAC0C,mBAAmB,CAChC,iBAAiB,EACjBxC,iBACD,CAAC;MACDD,WAAW,CAACyC,mBAAmB,CAAE,SAAS,EAAExC,iBAAkB,CAAC;IAChE,CAAC;EACF,CAAC,EACD,CAAET,WAAW,EAAEC,WAAW,EAAEC,eAAe,EAAEC,eAAe,CAC7D,CAAC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","useRefEffect","create","isSelectionForward","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","length","_focusNode$previousSi","previousSibling","parentElement","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","String","focus","getRichTextElement","element","ELEMENT_NODE","closest","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","getBlockSelectionStart","isMultiSelecting","ownerDocument","defaultView","onSelectionChange","event","getSelection","rangeCount","startNode","endNode","contains","isClickShift","shiftKey","type","isCollapsed","startClientId","endClientId","selectedClientId","clickedClientId","target","focusNodeIsNonSelectable","undefined","isSingularSelection","startPath","endPath","richTextElementStart","richTextElementEnd","_richTextDataStart$st","_richTextDataEnd$star","range","getRangeAt","richTextDataStart","__unstableIsEditableTree","richTextDataEnd","startOffset","start","end","endOffset","clientId","attributeKey","dataset","wpBlockAttributeKey","offset","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { create } from '@wordpress/rich-text';\nimport { isSelectionForward } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\n/**\n * Extract the selection start node from the selection. When the anchor node is\n * not a text node, the selection offset is the index of a child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionStartNode( selection ) {\n\tconst { anchorNode, anchorOffset } = selection;\n\n\tif ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {\n\t\treturn anchorNode;\n\t}\n\n\tif ( anchorOffset === 0 ) {\n\t\treturn anchorNode;\n\t}\n\n\treturn anchorNode.childNodes[ anchorOffset - 1 ];\n}\n\n/**\n * Extract the selection end node from the selection. When the focus node is not\n * a text node, the selection offset is the index of a child node. The selection\n * reaches up to but excluding that child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionEndNode( selection ) {\n\tconst { focusNode, focusOffset } = selection;\n\n\tif ( focusNode.nodeType === focusNode.TEXT_NODE ) {\n\t\treturn focusNode;\n\t}\n\n\tif ( focusOffset === focusNode.childNodes.length ) {\n\t\treturn focusNode;\n\t}\n\n\t// When the selection is forward (the selection ends with the focus node),\n\t// the selection may extend into the next element with an offset of 0. This\n\t// may trigger multi selection even though the selection does not visually\n\t// end in the next block.\n\tif ( focusOffset === 0 && isSelectionForward( selection ) ) {\n\t\treturn focusNode.previousSibling ?? focusNode.parentElement;\n\t}\n\n\treturn focusNode.childNodes[ focusOffset ];\n}\n\nfunction findDepth( a, b ) {\n\tlet depth = 0;\n\n\twhile ( a[ depth ] === b[ depth ] ) {\n\t\tdepth++;\n\t}\n\n\treturn depth;\n}\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\t// Since we are calling this on every selection change, check if the value\n\t// needs to be updated first because it trigger the browser to recalculate\n\t// style.\n\tif ( node.contentEditable !== String( value ) ) {\n\t\tnode.contentEditable = value;\n\n\t\t// Firefox doesn't automatically move focus.\n\t\tif ( value ) {\n\t\t\tnode.focus();\n\t\t}\n\t}\n}\n\nfunction getRichTextElement( node ) {\n\tconst element =\n\t\tnode.nodeType === node.ELEMENT_NODE ? node : node.parentElement;\n\treturn element?.closest( '[data-wp-block-attribute-key]' );\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useSelectionObserver() {\n\tconst { multiSelect, selectBlock, selectionChange } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { getBlockParents, getBlockSelectionStart, isMultiSelecting } =\n\t\tuseSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange( event ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startNode = extractSelectionStartNode( selection );\n\t\t\t\tconst endNode = extractSelectionEndNode( selection );\n\n\t\t\t\tif (\n\t\t\t\t\t! node.contains( startNode ) ||\n\t\t\t\t\t! node.contains( endNode )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// If selection is collapsed and we haven't used `shift+click`,\n\t\t\t\t// end multi selection and disable the contentEditable wrapper.\n\t\t\t\t// We have to check about `shift+click` case because elements\n\t\t\t\t// that don't support text selection might be involved, and we might\n\t\t\t\t// update the clientIds to multi-select blocks.\n\t\t\t\t// For now we check if the event is a `mouse` event.\n\t\t\t\tconst isClickShift = event.shiftKey && event.type === 'mouseup';\n\t\t\t\tif ( selection.isCollapsed && ! isClickShift ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.contentEditable === 'true' &&\n\t\t\t\t\t\t! isMultiSelecting()\n\t\t\t\t\t) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\t\tlet element =\n\t\t\t\t\t\t\tstartNode.nodeType === startNode.ELEMENT_NODE\n\t\t\t\t\t\t\t\t? startNode\n\t\t\t\t\t\t\t\t: startNode.parentElement;\n\t\t\t\t\t\telement = element?.closest( '[contenteditable]' );\n\t\t\t\t\t\telement?.focus();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet startClientId = getBlockClientId( startNode );\n\t\t\t\tlet endClientId = getBlockClientId( endNode );\n\n\t\t\t\t// If the selection has changed and we had pressed `shift+click`,\n\t\t\t\t// we need to check if in an element that doesn't support\n\t\t\t\t// text selection has been clicked.\n\t\t\t\tif ( isClickShift ) {\n\t\t\t\t\tconst selectedClientId = getBlockSelectionStart();\n\t\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\t\t\t\t\t// `endClientId` is not defined if we end the selection by clicking a non-selectable block.\n\t\t\t\t\t// We need to check if there was already a selection with a non-selectable focusNode.\n\t\t\t\t\tconst focusNodeIsNonSelectable =\n\t\t\t\t\t\tclickedClientId !== endClientId;\n\t\t\t\t\tif (\n\t\t\t\t\t\t( startClientId === endClientId &&\n\t\t\t\t\t\t\tselection.isCollapsed ) ||\n\t\t\t\t\t\t! endClientId ||\n\t\t\t\t\t\tfocusNodeIsNonSelectable\n\t\t\t\t\t) {\n\t\t\t\t\t\tendClientId = clickedClientId;\n\t\t\t\t\t}\n\t\t\t\t\t// Handle the case when we have a non-selectable block\n\t\t\t\t\t// selected and click another one.\n\t\t\t\t\tif ( startClientId !== selectedClientId ) {\n\t\t\t\t\t\tstartClientId = selectedClientId;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the selection did not involve a block, return.\n\t\t\t\tif (\n\t\t\t\t\tstartClientId === undefined &&\n\t\t\t\t\tendClientId === undefined\n\t\t\t\t) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst isSingularSelection = startClientId === endClientId;\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tif ( ! isMultiSelecting() ) {\n\t\t\t\t\t\tselectBlock( startClientId );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmultiSelect( startClientId, startClientId );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( startClientId ),\n\t\t\t\t\t\tstartClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth = findDepth( startPath, endPath );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartPath[ depth ] !== startClientId ||\n\t\t\t\t\t\tendPath[ depth ] !== endClientId\n\t\t\t\t\t) {\n\t\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst richTextElementStart =\n\t\t\t\t\t\tgetRichTextElement( startNode );\n\t\t\t\t\tconst richTextElementEnd = getRichTextElement( endNode );\n\n\t\t\t\t\tif ( richTextElementStart && richTextElementEnd ) {\n\t\t\t\t\t\tconst range = selection.getRangeAt( 0 );\n\t\t\t\t\t\tconst richTextDataStart = create( {\n\t\t\t\t\t\t\telement: richTextElementStart,\n\t\t\t\t\t\t\trange,\n\t\t\t\t\t\t\t__unstableIsEditableTree: true,\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tconst richTextDataEnd = create( {\n\t\t\t\t\t\t\telement: richTextElementEnd,\n\t\t\t\t\t\t\trange,\n\t\t\t\t\t\t\t__unstableIsEditableTree: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\tconst startOffset =\n\t\t\t\t\t\t\trichTextDataStart.start ?? richTextDataStart.end;\n\t\t\t\t\t\tconst endOffset =\n\t\t\t\t\t\t\trichTextDataEnd.start ?? richTextDataEnd.end;\n\t\t\t\t\t\tselectionChange( {\n\t\t\t\t\t\t\tstart: {\n\t\t\t\t\t\t\t\tclientId: startClientId,\n\t\t\t\t\t\t\t\tattributeKey:\n\t\t\t\t\t\t\t\t\trichTextElementStart.dataset\n\t\t\t\t\t\t\t\t\t\t.wpBlockAttributeKey,\n\t\t\t\t\t\t\t\toffset: startOffset,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tend: {\n\t\t\t\t\t\t\t\tclientId: endClientId,\n\t\t\t\t\t\t\t\tattributeKey:\n\t\t\t\t\t\t\t\t\trichTextElementEnd.dataset\n\t\t\t\t\t\t\t\t\t\t.wpBlockAttributeKey,\n\t\t\t\t\t\t\t\toffset: endOffset,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmultiSelect( startClientId, endClientId );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\townerDocument.addEventListener(\n\t\t\t\t'selectionchange',\n\t\t\t\tonSelectionChange\n\t\t\t);\n\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionChange );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,MAAM,QAAQ,sBAA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e,GAAGvE,MAAM,CAAE;YAC/B8B,OAAO,EAAEkC,kBAAkB;YAC3BG,KAAK;YACLG,wBAAwB,EAAE;UAC3B,CAAE,CAAC;UAEH,MAAME,WAAW,IAAAP,qBAAA,GAChBI,iBAAiB,CAACI,KAAK,cAAAR,qBAAA,cAAAA,qBAAA,GAAII,iBAAiB,CAACK,GAAG;UACjD,MAAMC,SAAS,IAAAT,qBAAA,GACdK,eAAe,CAACE,KAAK,cAAAP,qBAAA,cAAAA,qBAAA,GAAIK,eAAe,CAACG,GAAG;UAC7CtC,eAAe,CAAE;YAChBqC,KAAK,EAAE;cACNG,QAAQ,EAAEvB,aAAa;cACvBwB,YAAY,EACXd,oBAAoB,CAACe,OAAO,CAC1BC,mBAAmB;cACtBC,MAAM,EAAER;YACT,CAAC;YACDE,GAAG,EAAE;cACJE,QAAQ,EAAEtB,WAAW;cACrBuB,YAAY,EACXb,kBAAkB,CAACc,OAAO,CACxBC,mBAAmB;cACtBC,MAAM,EAAEL;YACT;UACD,CAAE,CAAC;QACJ,CAAC,MAAM;UACNzC,WAAW,CAAEmB,aAAa,EAAEC,WAAY,CAAC;QAC1C;MACD;IACD;IAEAd,aAAa,CAACyC,gBAAgB,CAC7B,iBAAiB,EACjBvC,iBACD,CAAC;IACDD,WAAW,CAACwC,gBAAgB,CAAE,SAAS,EAAEvC,iBAAkB,CAAC;IAC5D,OAAO,MAAM;MACZF,aAAa,CAAC0C,mBAAmB,CAChC,iBAAiB,EACjBxC,iBACD,CAAC;MACDD,WAAW,CAACyC,mBAAmB,CAAE,SAAS,EAAExC,iBAAkB,CAAC;IAChE,CAAC;EACF,CAAC,EACD,CAAER,WAAW,EAAEC,WAAW,EAAEC,eAAe,EAAEC,eAAe,CAC7D,CAAC;AACF","ignoreList":[]}
|
|
@@ -91,30 +91,4 @@ function toPlainText(html) {
|
|
|
91
91
|
// Merge any consecutive line breaks
|
|
92
92
|
return plainText.replace(/\n\n+/g, '\n\n');
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Gets the current content editable root element based on the selection.
|
|
97
|
-
* @param {Document} ownerDocument
|
|
98
|
-
* @return {Element|undefined} The content editable root element.
|
|
99
|
-
*/
|
|
100
|
-
export function getSelectionRoot(ownerDocument) {
|
|
101
|
-
const {
|
|
102
|
-
defaultView
|
|
103
|
-
} = ownerDocument;
|
|
104
|
-
const {
|
|
105
|
-
anchorNode,
|
|
106
|
-
focusNode
|
|
107
|
-
} = defaultView.getSelection();
|
|
108
|
-
if (!anchorNode || !focusNode) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const anchorElement = (anchorNode.nodeType === anchorNode.ELEMENT_NODE ? anchorNode : anchorNode.parentElement).closest('[contenteditable]');
|
|
112
|
-
if (!anchorElement) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (!anchorElement.contains(focusNode)) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
return anchorElement;
|
|
119
|
-
}
|
|
120
94
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__unstableStripHTML","stripHTML","serialize","createBlock","pasteHandler","findTransform","getBlockTransforms","store","blocksStore","getPasteEventData","blockEditorStore","requiresWrapperOnCopy","Symbol","setClipboardBlocks","event","blocks","registry","_blocks","firstBlock","firstBlockType","select","getBlockType","name","getBlockRootClientId","getBlockName","getBlockAttributes","wrapperBlockClientId","clientId","wrapperBlockName","serialized","clipboardData","setData","toPlainText","getPasteBlocks","canUserUseUnfilteredHTML","plainText","html","files","length","fromTransforms","reduce","accumulator","file","transformation","transform","type","isMatch","push","flat","HTML","mode","replace","trim"
|
|
1
|
+
{"version":3,"names":["__unstableStripHTML","stripHTML","serialize","createBlock","pasteHandler","findTransform","getBlockTransforms","store","blocksStore","getPasteEventData","blockEditorStore","requiresWrapperOnCopy","Symbol","setClipboardBlocks","event","blocks","registry","_blocks","firstBlock","firstBlockType","select","getBlockType","name","getBlockRootClientId","getBlockName","getBlockAttributes","wrapperBlockClientId","clientId","wrapperBlockName","serialized","clipboardData","setData","toPlainText","getPasteBlocks","canUserUseUnfilteredHTML","plainText","html","files","length","fromTransforms","reduce","accumulator","file","transformation","transform","type","isMatch","push","flat","HTML","mode","replace","trim"],"sources":["@wordpress/block-editor/src/components/writing-flow/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tserialize,\n\tcreateBlock,\n\tpasteHandler,\n\tfindTransform,\n\tgetBlockTransforms,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { getPasteEventData } from '../../utils/pasting';\nimport { store as blockEditorStore } from '../../store';\n\nexport const requiresWrapperOnCopy = Symbol( 'requiresWrapperOnCopy' );\n\n/**\n * Sets the clipboard data for the provided blocks, with both HTML and plain\n * text representations.\n *\n * @param {ClipboardEvent} event Clipboard event.\n * @param {WPBlock[]} blocks Blocks to set as clipboard data.\n * @param {Object} registry The registry to select from.\n */\nexport function setClipboardBlocks( event, blocks, registry ) {\n\tlet _blocks = blocks;\n\n\tconst [ firstBlock ] = blocks;\n\n\tif ( firstBlock ) {\n\t\tconst firstBlockType = registry\n\t\t\t.select( blocksStore )\n\t\t\t.getBlockType( firstBlock.name );\n\n\t\tif ( firstBlockType[ requiresWrapperOnCopy ] ) {\n\t\t\tconst { getBlockRootClientId, getBlockName, getBlockAttributes } =\n\t\t\t\tregistry.select( blockEditorStore );\n\t\t\tconst wrapperBlockClientId = getBlockRootClientId(\n\t\t\t\tfirstBlock.clientId\n\t\t\t);\n\t\t\tconst wrapperBlockName = getBlockName( wrapperBlockClientId );\n\n\t\t\tif ( wrapperBlockName ) {\n\t\t\t\t_blocks = createBlock(\n\t\t\t\t\twrapperBlockName,\n\t\t\t\t\tgetBlockAttributes( wrapperBlockClientId ),\n\t\t\t\t\t_blocks\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst serialized = serialize( _blocks );\n\n\tevent.clipboardData.setData( 'text/plain', toPlainText( serialized ) );\n\tevent.clipboardData.setData( 'text/html', serialized );\n}\n\n/**\n * Returns the blocks to be pasted from the clipboard event.\n *\n * @param {ClipboardEvent} event The clipboard event.\n * @param {boolean} canUserUseUnfilteredHTML Whether the user can or can't post unfiltered HTML.\n * @return {Array|string} A list of blocks or a string, depending on `handlerMode`.\n */\nexport function getPasteBlocks( event, canUserUseUnfilteredHTML ) {\n\tconst { plainText, html, files } = getPasteEventData( event );\n\tlet blocks = [];\n\n\tif ( files.length ) {\n\t\tconst fromTransforms = getBlockTransforms( 'from' );\n\t\tblocks = files\n\t\t\t.reduce( ( accumulator, file ) => {\n\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\tfromTransforms,\n\t\t\t\t\t( transform ) =>\n\t\t\t\t\t\ttransform.type === 'files' &&\n\t\t\t\t\t\ttransform.isMatch( [ file ] )\n\t\t\t\t);\n\t\t\t\tif ( transformation ) {\n\t\t\t\t\taccumulator.push( transformation.transform( [ file ] ) );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, [] )\n\t\t\t.flat();\n\t} else {\n\t\tblocks = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t\tmode: 'BLOCKS',\n\t\t\tcanUserUseUnfilteredHTML,\n\t\t} );\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Given a string of HTML representing serialized blocks, returns the plain\n * text extracted after stripping the HTML of any tags and fixing line breaks.\n *\n * @param {string} html Serialized blocks.\n * @return {string} The plain-text content with any html removed.\n */\nfunction toPlainText( html ) {\n\t// Manually handle BR tags as line breaks prior to `stripHTML` call\n\thtml = html.replace( /<br>/g, '\\n' );\n\n\tconst plainText = stripHTML( html ).trim();\n\n\t// Merge any consecutive line breaks\n\treturn plainText.replace( /\\n\\n+/g, '\\n\\n' );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,mBAAmB,IAA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AO,CAAE,QAAQ,EAAE,MAAO,CAAC;AAC7C","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
|
|
|
10
10
|
import { addFilter } from '@wordpress/hooks';
|
|
11
11
|
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
|
|
12
12
|
import { useSelect } from '@wordpress/data';
|
|
13
|
-
import {
|
|
13
|
+
import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, ToggleControl, PanelBody, privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
14
14
|
import { __ } from '@wordpress/i18n';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -250,18 +250,22 @@ function LayoutTypeSwitcher({
|
|
|
250
250
|
type,
|
|
251
251
|
onChange
|
|
252
252
|
}) {
|
|
253
|
-
return /*#__PURE__*/_jsx(
|
|
253
|
+
return /*#__PURE__*/_jsx(ToggleGroupControl, {
|
|
254
|
+
__next40pxDefaultSize: true,
|
|
255
|
+
isBlock: true,
|
|
256
|
+
label: __('Layout type'),
|
|
257
|
+
__nextHasNoMarginBottom: true,
|
|
258
|
+
hideLabelFromVision: true,
|
|
259
|
+
isAdaptiveWidth: true,
|
|
260
|
+
value: type,
|
|
261
|
+
onChange: onChange,
|
|
254
262
|
children: getLayoutTypes().map(({
|
|
255
263
|
name,
|
|
256
264
|
label
|
|
257
265
|
}) => {
|
|
258
|
-
return /*#__PURE__*/_jsx(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
__next40pxDefaultSize: false,
|
|
262
|
-
isPressed: type === name,
|
|
263
|
-
onClick: () => onChange(name),
|
|
264
|
-
children: label
|
|
266
|
+
return /*#__PURE__*/_jsx(ToggleGroupControlOption, {
|
|
267
|
+
value: name,
|
|
268
|
+
label: label
|
|
265
269
|
}, name);
|
|
266
270
|
})
|
|
267
271
|
});
|