@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
@@ -88,7 +88,8 @@ export default function useSelectionObserver() {
88
88
  selectionChange
89
89
  } = useDispatch(blockEditorStore);
90
90
  const {
91
- getBlockParents
91
+ getBlockParents,
92
+ getBlockSelectionStart
92
93
  } = useSelect(blockEditorStore);
93
94
  return useRefEffect(node => {
94
95
  const {
@@ -98,29 +99,63 @@ export default function useSelectionObserver() {
98
99
  defaultView
99
100
  } = ownerDocument;
100
101
 
101
- function onSelectionChange() {
102
+ function onSelectionChange(event) {
102
103
  const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
103
104
  // contentEditable wrapper.
104
105
 
105
- if (!selection.rangeCount || selection.isCollapsed) {
106
+ if (!selection.rangeCount) {
107
+ setContentEditableWrapper(node, false);
108
+ return;
109
+ } // If selection is collapsed and we haven't used `shift+click`,
110
+ // end multi selection and disable the contentEditable wrapper.
111
+ // We have to check about `shift+click` case because elements
112
+ // that don't support text selection might be involved, and we might
113
+ // update the clientIds to multi-select blocks.
114
+ // For now we check if the event is a `mouse` event.
115
+
116
+
117
+ const isClickShift = event.shiftKey && event.type === 'mouseup';
118
+
119
+ if (selection.isCollapsed && !isClickShift) {
106
120
  setContentEditableWrapper(node, false);
107
121
  return;
108
122
  }
109
123
 
110
- const clientId = getBlockClientId(extractSelectionStartNode(selection));
111
- const endClientId = getBlockClientId(extractSelectionEndNode(selection)); // If the selection did not involve a block, return early.
124
+ let startClientId = getBlockClientId(extractSelectionStartNode(selection));
125
+ let endClientId = getBlockClientId(extractSelectionEndNode(selection)); // If the selection has changed and we had pressed `shift+click`,
126
+ // we need to check if in an element that doesn't support
127
+ // text selection has been clicked.
128
+
129
+ if (isClickShift) {
130
+ const selectedClientId = getBlockSelectionStart();
131
+ const clickedClientId = getBlockClientId(event.target); // `endClientId` is not defined if we end the selection by clicking a non-selectable block.
132
+ // We need to check if there was already a selection with a non-selectable focusNode.
133
+
134
+ const focusNodeIsNonSelectable = clickedClientId !== endClientId;
135
+
136
+ if (startClientId === endClientId && selection.isCollapsed || !endClientId || focusNodeIsNonSelectable) {
137
+ endClientId = clickedClientId;
138
+ } // Handle the case when we have a non-selectable block
139
+ // selected and click another one.
140
+
141
+
142
+ if (startClientId !== selectedClientId) {
143
+ startClientId = selectedClientId;
144
+ }
145
+ } // If the selection did not involve a block, return.
146
+
112
147
 
113
- if (clientId === undefined && endClientId === undefined) {
148
+ if (startClientId === undefined && endClientId === undefined) {
114
149
  setContentEditableWrapper(node, false);
115
150
  return;
116
151
  }
117
152
 
118
- const isSingularSelection = clientId === endClientId;
153
+ const isSingularSelection = startClientId === endClientId;
119
154
 
120
155
  if (isSingularSelection) {
121
- selectBlock(clientId);
156
+ selectBlock(startClientId);
122
157
  } else {
123
- const startPath = [...getBlockParents(clientId), clientId];
158
+ const startPath = [...getBlockParents(startClientId), startClientId];
124
159
  const endPath = [...getBlockParents(endClientId), endClientId];
125
160
  const depth = findDepth(startPath, endPath);
126
161
  multiSelect(startPath[depth], endPath[depth]);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","ownerDocument","defaultView","onSelectionChange","getSelection","rangeCount","isCollapsed","clientId","endClientId","undefined","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,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,yBAA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GAAG,CACjB,GAAGX,eAAe,CAAEO,QAAF,CADD,EAEjBA,QAFiB,CAAlB;AAIA,cAAMK,OAAO,GAAG,CACf,GAAGZ,eAAe,CAAEQ,WAAF,CADH,EAEfA,WAFe,CAAhB;AAIA,cAAMlB,KAAK,GAAGH,SAAS,CAAEwB,SAAF,EAAaC,OAAb,CAAvB;AAEAf,QAAAA,WAAW,CAAEc,SAAS,CAAErB,KAAF,CAAX,EAAsBsB,OAAO,CAAEtB,KAAF,CAA7B,CAAX;AACA;AACD;;AAED,aAASuB,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;;AACArB,IAAAA,IAAI,CAACsB,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfvB,MAAAA,IAAI,CAACwB,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GA7EiB,EA8ElB,CAAEpB,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CC,eAA7C,CA9EkB,CAAnB;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":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","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":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,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;AAC7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AS,GAAG,CACjB,GAAGpB,eAAe,CAAEY,aAAF,CADD,EAEjBA,aAFiB,CAAlB;AAIA,cAAMS,OAAO,GAAG,CACf,GAAGrB,eAAe,CAAEa,WAAF,CADH,EAEfA,WAFe,CAAhB;AAIA,cAAMvB,KAAK,GAAGH,SAAS,CAAEiC,SAAF,EAAaC,OAAb,CAAvB;AAEAxB,QAAAA,WAAW,CAAEuB,SAAS,CAAE9B,KAAF,CAAX,EAAsB+B,OAAO,CAAE/B,KAAF,CAA7B,CAAX;AACA;AACD;;AAED,aAASgC,YAAT,GAAwB;AACvBpB,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;;AACA9B,IAAAA,IAAI,CAAC+B,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfhC,MAAAA,IAAI,CAACiC,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GAjHiB,EAkHlB,CAAE7B,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CC,eAA7C,CAlHkB,CAAnB;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"]}
@@ -1534,28 +1534,6 @@ export function canMoveBlocks(state, clientIds) {
1534
1534
  let rootClientId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1535
1535
  return clientIds.every(clientId => canMoveBlock(state, clientId, rootClientId));
1536
1536
  }
1537
- /**
1538
- * Determines if the given block is allowed to be edited.
1539
- *
1540
- * @param {Object} state Editor state.
1541
- * @param {string} clientId The block client Id.
1542
- *
1543
- * @return {boolean} Whether the given block is allowed to be edited.
1544
- */
1545
-
1546
- export function canEditBlock(state, clientId) {
1547
- const attributes = getBlockAttributes(state, clientId);
1548
-
1549
- if (attributes === null) {
1550
- return true;
1551
- }
1552
-
1553
- const {
1554
- lock
1555
- } = attributes; // When the edit is true, we cannot edit the block.
1556
-
1557
- return !(lock !== null && lock !== void 0 && lock.edit);
1558
- }
1559
1537
  /**
1560
1538
  * Determines if the given block type can be locked/unlocked by a user.
1561
1539
  *