@wordpress/block-editor 8.5.3 → 8.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/build/components/block-content-overlay/index.js +4 -13
  2. package/build/components/block-content-overlay/index.js.map +1 -1
  3. package/build/components/block-lock/modal.js +4 -34
  4. package/build/components/block-lock/modal.js.map +1 -1
  5. package/build/components/block-lock/toolbar.js +1 -2
  6. package/build/components/block-lock/toolbar.js.map +1 -1
  7. package/build/components/block-lock/use-block-lock.js +1 -4
  8. package/build/components/block-lock/use-block-lock.js.map +1 -1
  9. package/build/components/inserter/index.js +21 -7
  10. package/build/components/inserter/index.js.map +1 -1
  11. package/build/components/inserter/quick-inserter.js +4 -5
  12. package/build/components/inserter/quick-inserter.js.map +1 -1
  13. package/build/components/writing-flow/use-click-selection.js +1 -3
  14. package/build/components/writing-flow/use-click-selection.js.map +1 -1
  15. package/build/components/writing-flow/use-selection-observer.js +44 -9
  16. package/build/components/writing-flow/use-selection-observer.js.map +1 -1
  17. package/build/store/selectors.js +0 -24
  18. package/build/store/selectors.js.map +1 -1
  19. package/build-module/components/block-content-overlay/index.js +4 -13
  20. package/build-module/components/block-content-overlay/index.js.map +1 -1
  21. package/build-module/components/block-lock/modal.js +5 -34
  22. package/build-module/components/block-lock/modal.js.map +1 -1
  23. package/build-module/components/block-lock/toolbar.js +1 -2
  24. package/build-module/components/block-lock/toolbar.js.map +1 -1
  25. package/build-module/components/block-lock/use-block-lock.js +1 -4
  26. package/build-module/components/block-lock/use-block-lock.js.map +1 -1
  27. package/build-module/components/inserter/index.js +21 -7
  28. package/build-module/components/inserter/index.js.map +1 -1
  29. package/build-module/components/inserter/quick-inserter.js +4 -5
  30. package/build-module/components/inserter/quick-inserter.js.map +1 -1
  31. package/build-module/components/writing-flow/use-click-selection.js +1 -3
  32. package/build-module/components/writing-flow/use-click-selection.js.map +1 -1
  33. package/build-module/components/writing-flow/use-selection-observer.js +44 -9
  34. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
  35. package/build-module/store/selectors.js +0 -22
  36. package/build-module/store/selectors.js.map +1 -1
  37. package/package.json +4 -4
  38. package/src/components/block-content-overlay/index.js +2 -19
  39. package/src/components/block-lock/modal.js +3 -42
  40. package/src/components/block-lock/toolbar.js +2 -2
  41. package/src/components/block-lock/use-block-lock.js +1 -4
  42. package/src/components/inserter/index.js +20 -0
  43. package/src/components/inserter/quick-inserter.js +3 -11
  44. package/src/components/writing-flow/use-click-selection.js +1 -4
  45. package/src/components/writing-flow/use-selection-observer.js +51 -13
  46. package/src/store/selectors.js +0 -20
@@ -99,7 +99,8 @@ function useSelectionObserver() {
99
99
  selectionChange
100
100
  } = (0, _data.useDispatch)(_store.store);
101
101
  const {
102
- getBlockParents
102
+ getBlockParents,
103
+ getBlockSelectionStart
103
104
  } = (0, _data.useSelect)(_store.store);
104
105
  return (0, _compose.useRefEffect)(node => {
105
106
  const {
@@ -109,29 +110,63 @@ function useSelectionObserver() {
109
110
  defaultView
110
111
  } = ownerDocument;
111
112
 
112
- function onSelectionChange() {
113
+ function onSelectionChange(event) {
113
114
  const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
114
115
  // contentEditable wrapper.
115
116
 
116
- if (!selection.rangeCount || selection.isCollapsed) {
117
+ if (!selection.rangeCount) {
118
+ setContentEditableWrapper(node, false);
119
+ return;
120
+ } // If selection is collapsed and we haven't used `shift+click`,
121
+ // end multi selection and disable the contentEditable wrapper.
122
+ // We have to check about `shift+click` case because elements
123
+ // that don't support text selection might be involved, and we might
124
+ // update the clientIds to multi-select blocks.
125
+ // For now we check if the event is a `mouse` event.
126
+
127
+
128
+ const isClickShift = event.shiftKey && event.type === 'mouseup';
129
+
130
+ if (selection.isCollapsed && !isClickShift) {
117
131
  setContentEditableWrapper(node, false);
118
132
  return;
119
133
  }
120
134
 
121
- const clientId = (0, _dom.getBlockClientId)(extractSelectionStartNode(selection));
122
- const endClientId = (0, _dom.getBlockClientId)(extractSelectionEndNode(selection)); // If the selection did not involve a block, return early.
135
+ let startClientId = (0, _dom.getBlockClientId)(extractSelectionStartNode(selection));
136
+ let endClientId = (0, _dom.getBlockClientId)(extractSelectionEndNode(selection)); // If the selection has changed and we had pressed `shift+click`,
137
+ // we need to check if in an element that doesn't support
138
+ // text selection has been clicked.
139
+
140
+ if (isClickShift) {
141
+ const selectedClientId = getBlockSelectionStart();
142
+ const clickedClientId = (0, _dom.getBlockClientId)(event.target); // `endClientId` is not defined if we end the selection by clicking a non-selectable block.
143
+ // We need to check if there was already a selection with a non-selectable focusNode.
144
+
145
+ const focusNodeIsNonSelectable = clickedClientId !== endClientId;
146
+
147
+ if (startClientId === endClientId && selection.isCollapsed || !endClientId || focusNodeIsNonSelectable) {
148
+ endClientId = clickedClientId;
149
+ } // Handle the case when we have a non-selectable block
150
+ // selected and click another one.
151
+
152
+
153
+ if (startClientId !== selectedClientId) {
154
+ startClientId = selectedClientId;
155
+ }
156
+ } // If the selection did not involve a block, return.
157
+
123
158
 
124
- if (clientId === undefined && endClientId === undefined) {
159
+ if (startClientId === undefined && endClientId === undefined) {
125
160
  setContentEditableWrapper(node, false);
126
161
  return;
127
162
  }
128
163
 
129
- const isSingularSelection = clientId === endClientId;
164
+ const isSingularSelection = startClientId === endClientId;
130
165
 
131
166
  if (isSingularSelection) {
132
- selectBlock(clientId);
167
+ selectBlock(startClientId);
133
168
  } else {
134
- const startPath = [...getBlockParents(clientId), clientId];
169
+ const startPath = [...getBlockParents(startClientId), startClientId];
135
170
  const endPath = [...getBlockParents(endClientId), endClientId];
136
171
  const depth = findDepth(startPath, endPath);
137
172
  multiSelect(startPath[depth], endPath[depth]);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","blockEditorStore","getBlockParents","ownerDocument","defaultView","onSelectionChange","getSelection","rangeCount","isCollapsed","clientId","endClientId","undefined","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAT,CAAoCC,SAApC,EAAgD;AAC/C,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA+BF,SAArC;;AAEA,MAAKC,UAAU,CAACE,QAAX,KAAwBF,UAAU,CAACG,SAAxC,EAAoD;AACnD,WAAOH,UAAP;AACA;;AAED,SAAOA,UAAU,CAACI,UAAX,CAAuBH,YAAvB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,uBAAT,CAAkCN,SAAlC,EAA8C;AAC7C,QAAM;AAAEO,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAnC;;AAEA,MAAKO,SAAS,CAACJ,QAAV,KAAuBI,SAAS,CAACH,SAAtC,EAAkD;AACjD,WAAOG,SAAP;AACA;;AAED,SAAOA,SAAS,CAACF,UAAV,CAAsBG,WAAW,GAAG,CAApC,CAAP;AACA;;AAED,SAASC,SAAT,CAAoBC,CAApB,EAAuBC,CAAvB,EAA2B;AAC1B,MAAIC,KAAK,GAAG,CAAZ;;AAEA,SAAQF,CAAC,CAAEE,KAAF,CAAD,KAAeD,CAAC,CAAEC,KAAF,CAAxB,EAAoC;AACnCA,IAAAA,KAAK;AACL;;AAED,SAAOA,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,yBAAT,CAAoCC,IAApC,EAA0CC,KAA1C,EAAkD;AACjDD,EAAAA,IAAI,CAACE,eAAL,GAAuBD,KAAvB,CADiD,CAE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e,CAAhB;AAIA,cAAMnB,KAAK,GAAGH,SAAS,CAAEyB,SAAF,EAAaC,OAAb,CAAvB;AAEAhB,QAAAA,WAAW,CAAEe,SAAS,CAAEtB,KAAF,CAAX,EAAsBuB,OAAO,CAAEvB,KAAF,CAA7B,CAAX;AACA;AACD;;AAED,aAASwB,YAAT,GAAwB;AACvBZ,MAAAA,aAAa,CAACa,gBAAd,CACC,iBADD,EAECX,iBAFD;AAIAD,MAAAA,WAAW,CAACY,gBAAZ,CAA8B,SAA9B,EAAyCX,iBAAzC;AACA;;AAED,aAASY,eAAT,GAA2B;AAC1Bd,MAAAA,aAAa,CAACe,mBAAd,CACC,iBADD,EAECb,iBAFD;AAIAD,MAAAA,WAAW,CAACc,mBAAZ,CAAiC,SAAjC,EAA4Cb,iBAA5C;AACA;;AAED,aAASc,cAAT,GAA0B;AACzBF,MAAAA,eAAe;AACfF,MAAAA,YAAY;AACZ;;AAEDA,IAAAA,YAAY,GAnED,CAoEX;AACA;AACA;;AACAtB,IAAAA,IAAI,CAACuB,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfxB,MAAAA,IAAI,CAACyB,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GA7EK,EA8EN,CAAErB,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CE,eAA7C,CA9EM,CAAP;AAgFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\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\treturn anchorNode.childNodes[ anchorOffset ];\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\treturn focusNode.childNodes[ focusOffset - 1 ];\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\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\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 } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { getBlockParents } = 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() {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount || selection.isCollapsed ) {\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 clientId = getBlockClientId(\n\t\t\t\t\textractSelectionStartNode( selection )\n\t\t\t\t);\n\t\t\t\tconst endClientId = getBlockClientId(\n\t\t\t\t\textractSelectionEndNode( selection )\n\t\t\t\t);\n\n\t\t\t\t// If the selection did not involve a block, return early.\n\t\t\t\tif ( clientId === undefined && endClientId === undefined ) {\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 = clientId === endClientId;\n\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\tclientId,\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\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction addListeners() {\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction removeListeners() {\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\n\t\t\tfunction resetListeners() {\n\t\t\t\tremoveListeners();\n\t\t\t\taddListeners();\n\t\t\t}\n\n\t\t\taddListeners();\n\t\t\t// We must allow rich text to set selection first. This ensures that\n\t\t\t// our `selectionchange` listener is always reset to be called after\n\t\t\t// the rich text one.\n\t\t\tnode.addEventListener( 'focusin', resetListeners );\n\t\t\treturn () => {\n\t\t\t\tremoveListeners();\n\t\t\t\tnode.removeEventListener( 'focusin', resetListeners );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","blockEditorStore","getBlockParents","getBlockSelectionStart","ownerDocument","defaultView","onSelectionChange","event","getSelection","rangeCount","isClickShift","shiftKey","type","isCollapsed","startClientId","endClientId","selectedClientId","clickedClientId","target","focusNodeIsNonSelectable","undefined","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAT,CAAoCC,SAApC,EAAgD;AAC/C,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA+BF,SAArC;;AAEA,MAAKC,UAAU,CAACE,QAAX,KAAwBF,UAAU,CAACG,SAAxC,EAAoD;AACnD,WAAOH,UAAP;AACA;;AAED,SAAOA,UAAU,CAACI,UAAX,CAAuBH,YAAvB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,uBAAT,CAAkCN,SAAlC,EAA8C;AAC7C,QAAM;AAAEO,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAnC;;AAEA,MAAKO,SAAS,CAACJ,QAAV,KAAuBI,SAAS,CAACH,SAAtC,EAAkD;AACjD,WAAOG,SAAP;AACA;;AAED,SAAOA,SAAS,CAACF,UAAV,CAAsBG,WAAW,GAAG,CAApC,CAAP;AACA;;AAED,SAASC,SAAT,CAAoBC,CAApB,EAAuBC,CAAvB,EAA2B;AAC1B,MAAIC,KAAK,G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B,MAAAA,aAAa,CAACqB,gBAAd,CACC,iBADD,EAECnB,iBAFD;AAIAD,MAAAA,WAAW,CAACoB,gBAAZ,CAA8B,SAA9B,EAAyCnB,iBAAzC;AACA;;AAED,aAASoB,eAAT,GAA2B;AAC1BtB,MAAAA,aAAa,CAACuB,mBAAd,CACC,iBADD,EAECrB,iBAFD;AAIAD,MAAAA,WAAW,CAACsB,mBAAZ,CAAiC,SAAjC,EAA4CrB,iBAA5C;AACA;;AAED,aAASsB,cAAT,GAA0B;AACzBF,MAAAA,eAAe;AACfF,MAAAA,YAAY;AACZ;;AAEDA,IAAAA,YAAY,GAvGD,CAwGX;AACA;AACA;;AACA/B,IAAAA,IAAI,CAACgC,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfjC,MAAAA,IAAI,CAACkC,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GAjHK,EAkHN,CAAE9B,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CE,eAA7C,CAlHM,CAAP;AAoHA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\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\treturn anchorNode.childNodes[ anchorOffset ];\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\treturn focusNode.childNodes[ focusOffset - 1 ];\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\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\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 } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { getBlockParents, getBlockSelectionStart } = useSelect(\n\t\tblockEditorStore\n\t);\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange( event ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\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\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet startClientId = getBlockClientId(\n\t\t\t\t\textractSelectionStartNode( selection )\n\t\t\t\t);\n\t\t\t\tlet endClientId = getBlockClientId(\n\t\t\t\t\textractSelectionEndNode( selection )\n\t\t\t\t);\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\tselectBlock( startClientId );\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\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction addListeners() {\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction removeListeners() {\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\n\t\t\tfunction resetListeners() {\n\t\t\t\tremoveListeners();\n\t\t\t\taddListeners();\n\t\t\t}\n\n\t\t\taddListeners();\n\t\t\t// We must allow rich text to set selection first. This ensures that\n\t\t\t// our `selectionchange` listener is always reset to be called after\n\t\t\t// the rich text one.\n\t\t\tnode.addEventListener( 'focusin', resetListeners );\n\t\t\treturn () => {\n\t\t\t\tremoveListeners();\n\t\t\t\tnode.removeEventListener( 'focusin', resetListeners );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"]}
@@ -13,7 +13,6 @@ exports.__unstableIsLastBlockChangeIgnored = __unstableIsLastBlockChangeIgnored;
13
13
  exports.__unstableIsSelectionCollapsed = __unstableIsSelectionCollapsed;
14
14
  exports.__unstableIsSelectionMergeable = __unstableIsSelectionMergeable;
15
15
  exports.areInnerBlocksControlled = areInnerBlocksControlled;
16
- exports.canEditBlock = canEditBlock;
17
16
  exports.canInsertBlockType = void 0;
18
17
  exports.canInsertBlocks = canInsertBlocks;
19
18
  exports.canLockBlockType = canLockBlockType;
@@ -1715,29 +1714,6 @@ function canMoveBlocks(state, clientIds) {
1715
1714
  let rootClientId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1716
1715
  return clientIds.every(clientId => canMoveBlock(state, clientId, rootClientId));
1717
1716
  }
1718
- /**
1719
- * Determines if the given block is allowed to be edited.
1720
- *
1721
- * @param {Object} state Editor state.
1722
- * @param {string} clientId The block client Id.
1723
- *
1724
- * @return {boolean} Whether the given block is allowed to be edited.
1725
- */
1726
-
1727
-
1728
- function canEditBlock(state, clientId) {
1729
- const attributes = getBlockAttributes(state, clientId);
1730
-
1731
- if (attributes === null) {
1732
- return true;
1733
- }
1734
-
1735
- const {
1736
- lock
1737
- } = attributes; // When the edit is true, we cannot edit the block.
1738
-
1739
- return !(lock !== null && lock !== void 0 && lock.edit);
1740
- }
1741
1717
  /**
1742
1718
  * Determines if the given block type can be locked/unlocked by a user.
1743
1719
  *