@wordpress/block-editor 8.5.1 → 8.5.2

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 (54) hide show
  1. package/build/components/block-alignment-control/ui.js +1 -1
  2. package/build/components/block-alignment-control/ui.js.map +1 -1
  3. package/build/components/block-lock/menu-item.js +1 -1
  4. package/build/components/block-lock/menu-item.js.map +1 -1
  5. package/build/components/block-lock/modal.js +1 -1
  6. package/build/components/block-lock/modal.js.map +1 -1
  7. package/build/components/block-lock/use-block-lock.js +3 -6
  8. package/build/components/block-lock/use-block-lock.js.map +1 -1
  9. package/build/components/copy-handler/index.js +44 -9
  10. package/build/components/copy-handler/index.js.map +1 -1
  11. package/build/components/link-control/index.js +6 -7
  12. package/build/components/link-control/index.js.map +1 -1
  13. package/build/components/list-view/block.js +13 -2
  14. package/build/components/list-view/block.js.map +1 -1
  15. package/build/store/actions.js +22 -29
  16. package/build/store/actions.js.map +1 -1
  17. package/build/store/selectors.js +96 -1
  18. package/build/store/selectors.js.map +1 -1
  19. package/build/store/utils.js +27 -0
  20. package/build/store/utils.js.map +1 -0
  21. package/build-module/components/block-alignment-control/ui.js +2 -2
  22. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  23. package/build-module/components/block-lock/menu-item.js +1 -1
  24. package/build-module/components/block-lock/menu-item.js.map +1 -1
  25. package/build-module/components/block-lock/modal.js +1 -1
  26. package/build-module/components/block-lock/modal.js.map +1 -1
  27. package/build-module/components/block-lock/use-block-lock.js +3 -6
  28. package/build-module/components/block-lock/use-block-lock.js.map +1 -1
  29. package/build-module/components/copy-handler/index.js +44 -9
  30. package/build-module/components/copy-handler/index.js.map +1 -1
  31. package/build-module/components/link-control/index.js +6 -7
  32. package/build-module/components/link-control/index.js.map +1 -1
  33. package/build-module/components/list-view/block.js +13 -2
  34. package/build-module/components/list-view/block.js.map +1 -1
  35. package/build-module/store/actions.js +5 -14
  36. package/build-module/store/actions.js.map +1 -1
  37. package/build-module/store/selectors.js +88 -0
  38. package/build-module/store/selectors.js.map +1 -1
  39. package/build-module/store/utils.js +20 -0
  40. package/build-module/store/utils.js.map +1 -0
  41. package/build-style/style-rtl.css +1 -2
  42. package/build-style/style.css +1 -2
  43. package/package.json +28 -28
  44. package/src/components/block-alignment-control/ui.js +2 -2
  45. package/src/components/block-lock/menu-item.js +1 -1
  46. package/src/components/block-lock/modal.js +1 -1
  47. package/src/components/block-lock/style.scss +1 -2
  48. package/src/components/block-lock/use-block-lock.js +4 -8
  49. package/src/components/copy-handler/index.js +52 -10
  50. package/src/components/link-control/index.js +5 -5
  51. package/src/components/list-view/block.js +16 -7
  52. package/src/store/actions.js +5 -13
  53. package/src/store/selectors.js +126 -0
  54. package/src/store/utils.js +19 -0
@@ -7,9 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.__experimentalGetGlobalBlocksByName = exports.__experimentalGetDirectInsertBlock = exports.__experimentalGetBlockListSettingsForBlocks = exports.__experimentalGetAllowedPatterns = exports.__experimentalGetAllowedBlocks = exports.__experimentalGetActiveBlockIdByBlockNames = void 0;
9
9
  exports.__experimentalGetLastBlockAttributeChanges = __experimentalGetLastBlockAttributeChanges;
10
- exports.__unstableGetClientIdsTree = exports.__unstableGetClientIdWithClientIdsTree = exports.__unstableGetBlockWithoutInnerBlocks = exports.__experimentalGetReusableBlockTitle = exports.__experimentalGetPatternsByBlockTypes = exports.__experimentalGetPatternTransformItems = exports.__experimentalGetParsedPattern = void 0;
10
+ exports.__unstableGetSelectedBlocksWithPartialSelection = exports.__unstableGetClientIdsTree = exports.__unstableGetClientIdWithClientIdsTree = exports.__unstableGetBlockWithoutInnerBlocks = exports.__experimentalGetReusableBlockTitle = exports.__experimentalGetPatternsByBlockTypes = exports.__experimentalGetPatternTransformItems = exports.__experimentalGetParsedPattern = void 0;
11
11
  exports.__unstableIsFullySelected = __unstableIsFullySelected;
12
12
  exports.__unstableIsLastBlockChangeIgnored = __unstableIsLastBlockChangeIgnored;
13
+ exports.__unstableIsSelectionCollapsed = __unstableIsSelectionCollapsed;
13
14
  exports.__unstableIsSelectionMergeable = __unstableIsSelectionMergeable;
14
15
  exports.areInnerBlocksControlled = areInnerBlocksControlled;
15
16
  exports.canEditBlock = canEditBlock;
@@ -99,6 +100,10 @@ var _icons = require("@wordpress/icons");
99
100
 
100
101
  var _i18n = require("@wordpress/i18n");
101
102
 
103
+ var _richText = require("@wordpress/rich-text");
104
+
105
+ var _utils = require("./utils");
106
+
102
107
  /**
103
108
  * External dependencies
104
109
  */
@@ -107,6 +112,10 @@ var _i18n = require("@wordpress/i18n");
107
112
  * WordPress dependencies
108
113
  */
109
114
 
115
+ /**
116
+ * Internal dependencies
117
+ */
118
+
110
119
  /**
111
120
  * A block selection object.
112
121
  *
@@ -1000,6 +1009,20 @@ function __unstableIsFullySelected(state) {
1000
1009
  const selectionFocus = getSelectionEnd(state);
1001
1010
  return !selectionAnchor.attributeKey && !selectionFocus.attributeKey && typeof selectionAnchor.offset === 'undefined' && typeof selectionFocus.offset === 'undefined';
1002
1011
  }
1012
+ /**
1013
+ * Returns true if the selection is collapsed.
1014
+ *
1015
+ * @param {Object} state Editor state.
1016
+ *
1017
+ * @return {boolean} Whether the selection is collapsed.
1018
+ */
1019
+
1020
+
1021
+ function __unstableIsSelectionCollapsed(state) {
1022
+ const selectionAnchor = getSelectionStart(state);
1023
+ const selectionFocus = getSelectionEnd(state);
1024
+ return !!selectionAnchor && !!selectionFocus && selectionAnchor.clientId === selectionFocus.clientId && selectionAnchor.attributeKey === selectionFocus.attributeKey && selectionAnchor.offset === selectionFocus.offset;
1025
+ }
1003
1026
  /**
1004
1027
  * Check whether the selection is mergeable.
1005
1028
  *
@@ -1052,6 +1075,76 @@ function __unstableIsSelectionMergeable(state, isForward) {
1052
1075
  const blocksToMerge = (0, _blocks.switchToBlockType)(blockToMerge, targetBlock.name);
1053
1076
  return blocksToMerge && blocksToMerge.length;
1054
1077
  }
1078
+ /**
1079
+ * Get partial selected blocks with their content updated
1080
+ * based on the selection.
1081
+ *
1082
+ * @param {Object} state Editor state.
1083
+ *
1084
+ * @return {Object[]} Updated partial selected blocks.
1085
+ */
1086
+
1087
+
1088
+ const __unstableGetSelectedBlocksWithPartialSelection = state => {
1089
+ const selectionAnchor = getSelectionStart(state);
1090
+ const selectionFocus = getSelectionEnd(state);
1091
+
1092
+ if (selectionAnchor.clientId === selectionFocus.clientId) {
1093
+ return EMPTY_ARRAY;
1094
+ } // Can't split if the selection is not set.
1095
+
1096
+
1097
+ if (!selectionAnchor.attributeKey || !selectionFocus.attributeKey || typeof selectionAnchor.offset === 'undefined' || typeof selectionFocus.offset === 'undefined') {
1098
+ return EMPTY_ARRAY;
1099
+ }
1100
+
1101
+ const anchorRootClientId = getBlockRootClientId(state, selectionAnchor.clientId);
1102
+ const focusRootClientId = getBlockRootClientId(state, selectionFocus.clientId); // It's not splittable if the selection doesn't start and end in the same
1103
+ // block list. Maybe in the future it should be allowed.
1104
+
1105
+ if (anchorRootClientId !== focusRootClientId) {
1106
+ return EMPTY_ARRAY;
1107
+ }
1108
+
1109
+ const blockOrder = getBlockOrder(state, anchorRootClientId);
1110
+ const anchorIndex = blockOrder.indexOf(selectionAnchor.clientId);
1111
+ const focusIndex = blockOrder.indexOf(selectionFocus.clientId); // Reassign selection start and end based on order.
1112
+
1113
+ const [selectionStart, selectionEnd] = anchorIndex > focusIndex ? [selectionFocus, selectionAnchor] : [selectionAnchor, selectionFocus];
1114
+ const blockA = getBlock(state, selectionStart.clientId);
1115
+ const blockAType = (0, _blocks.getBlockType)(blockA.name);
1116
+ const blockB = getBlock(state, selectionEnd.clientId);
1117
+ const blockBType = (0, _blocks.getBlockType)(blockB.name);
1118
+ const htmlA = blockA.attributes[selectionStart.attributeKey];
1119
+ const htmlB = blockB.attributes[selectionEnd.attributeKey];
1120
+ const attributeDefinitionA = blockAType.attributes[selectionStart.attributeKey];
1121
+ const attributeDefinitionB = blockBType.attributes[selectionEnd.attributeKey];
1122
+ let valueA = (0, _richText.create)({
1123
+ html: htmlA,
1124
+ ...(0, _utils.mapRichTextSettings)(attributeDefinitionA)
1125
+ });
1126
+ let valueB = (0, _richText.create)({
1127
+ html: htmlB,
1128
+ ...(0, _utils.mapRichTextSettings)(attributeDefinitionB)
1129
+ });
1130
+ valueA = (0, _richText.remove)(valueA, 0, selectionStart.offset);
1131
+ valueB = (0, _richText.remove)(valueB, selectionEnd.offset, valueB.text.length);
1132
+ return [{ ...blockA,
1133
+ attributes: { ...blockA.attributes,
1134
+ [selectionStart.attributeKey]: (0, _richText.toHTMLString)({
1135
+ value: valueA,
1136
+ ...(0, _utils.mapRichTextSettings)(attributeDefinitionA)
1137
+ })
1138
+ }
1139
+ }, { ...blockB,
1140
+ attributes: { ...blockB.attributes,
1141
+ [selectionEnd.attributeKey]: (0, _richText.toHTMLString)({
1142
+ value: valueB,
1143
+ ...(0, _utils.mapRichTextSettings)(attributeDefinitionB)
1144
+ })
1145
+ }
1146
+ }];
1147
+ };
1055
1148
  /**
1056
1149
  * Returns an array containing all block client IDs in the editor in the order
1057
1150
  * they appear. Optionally accepts a root client ID of the block list for which
@@ -1064,6 +1157,8 @@ function __unstableIsSelectionMergeable(state, isForward) {
1064
1157
  */
1065
1158
 
1066
1159
 
1160
+ exports.__unstableGetSelectedBlocksWithPartialSelection = __unstableGetSelectedBlocksWithPartialSelection;
1161
+
1067
1162
  function getBlockOrder(state, rootClientId) {
1068
1163
  return state.blocks.order[rootClientId || ''] || EMPTY_ARRAY;
1069
1164
  }