@wordpress/block-editor 8.5.0 → 8.5.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.
Files changed (123) 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-content-overlay/index.js +13 -4
  4. package/build/components/block-content-overlay/index.js.map +1 -1
  5. package/build/components/block-lock/index.js +8 -0
  6. package/build/components/block-lock/index.js.map +1 -1
  7. package/build/components/block-lock/menu-item.js +5 -20
  8. package/build/components/block-lock/menu-item.js.map +1 -1
  9. package/build/components/block-lock/modal.js +33 -12
  10. package/build/components/block-lock/modal.js.map +1 -1
  11. package/build/components/block-lock/toolbar.js +7 -20
  12. package/build/components/block-lock/toolbar.js.map +1 -1
  13. package/build/components/block-lock/use-block-lock.js +50 -0
  14. package/build/components/block-lock/use-block-lock.js.map +1 -0
  15. package/build/components/block-pattern-setup/index.js +37 -22
  16. package/build/components/block-pattern-setup/index.js.map +1 -1
  17. package/build/components/block-pattern-setup/setup-toolbar.js +1 -1
  18. package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  19. package/build/components/block-preview/auto.js +6 -3
  20. package/build/components/block-preview/auto.js.map +1 -1
  21. package/build/components/block-preview/index.js +4 -2
  22. package/build/components/block-preview/index.js.map +1 -1
  23. package/build/components/block-switcher/index.js +7 -2
  24. package/build/components/block-switcher/index.js.map +1 -1
  25. package/build/components/copy-handler/index.js +44 -9
  26. package/build/components/copy-handler/index.js.map +1 -1
  27. package/build/components/link-control/index.js +6 -7
  28. package/build/components/link-control/index.js.map +1 -1
  29. package/build/components/list-view/block-select-button.js +4 -10
  30. package/build/components/list-view/block-select-button.js.map +1 -1
  31. package/build/components/list-view/block.js +13 -2
  32. package/build/components/list-view/block.js.map +1 -1
  33. package/build/components/writing-flow/use-selection-observer.js +7 -1
  34. package/build/components/writing-flow/use-selection-observer.js.map +1 -1
  35. package/build/hooks/duotone.js +66 -16
  36. package/build/hooks/duotone.js.map +1 -1
  37. package/build/hooks/index.js +7 -1
  38. package/build/hooks/index.js.map +1 -1
  39. package/build/index.js +7 -0
  40. package/build/index.js.map +1 -1
  41. package/build/store/actions.js +22 -29
  42. package/build/store/actions.js.map +1 -1
  43. package/build/store/selectors.js +122 -3
  44. package/build/store/selectors.js.map +1 -1
  45. package/build/store/utils.js +27 -0
  46. package/build/store/utils.js.map +1 -0
  47. package/build-module/components/block-alignment-control/ui.js +2 -2
  48. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  49. package/build-module/components/block-content-overlay/index.js +13 -4
  50. package/build-module/components/block-content-overlay/index.js.map +1 -1
  51. package/build-module/components/block-lock/index.js +1 -0
  52. package/build-module/components/block-lock/index.js.map +1 -1
  53. package/build-module/components/block-lock/menu-item.js +4 -18
  54. package/build-module/components/block-lock/menu-item.js.map +1 -1
  55. package/build-module/components/block-lock/modal.js +31 -12
  56. package/build-module/components/block-lock/modal.js.map +1 -1
  57. package/build-module/components/block-lock/toolbar.js +6 -18
  58. package/build-module/components/block-lock/toolbar.js.map +1 -1
  59. package/build-module/components/block-lock/use-block-lock.js +41 -0
  60. package/build-module/components/block-lock/use-block-lock.js.map +1 -0
  61. package/build-module/components/block-pattern-setup/index.js +39 -24
  62. package/build-module/components/block-pattern-setup/index.js.map +1 -1
  63. package/build-module/components/block-pattern-setup/setup-toolbar.js +1 -1
  64. package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  65. package/build-module/components/block-preview/auto.js +6 -3
  66. package/build-module/components/block-preview/auto.js.map +1 -1
  67. package/build-module/components/block-preview/index.js +4 -2
  68. package/build-module/components/block-preview/index.js.map +1 -1
  69. package/build-module/components/block-switcher/index.js +7 -2
  70. package/build-module/components/block-switcher/index.js.map +1 -1
  71. package/build-module/components/copy-handler/index.js +44 -9
  72. package/build-module/components/copy-handler/index.js.map +1 -1
  73. package/build-module/components/link-control/index.js +6 -7
  74. package/build-module/components/link-control/index.js.map +1 -1
  75. package/build-module/components/list-view/block-select-button.js +4 -9
  76. package/build-module/components/list-view/block-select-button.js.map +1 -1
  77. package/build-module/components/list-view/block.js +13 -2
  78. package/build-module/components/list-view/block.js.map +1 -1
  79. package/build-module/components/writing-flow/use-selection-observer.js +7 -1
  80. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
  81. package/build-module/hooks/duotone.js +63 -16
  82. package/build-module/hooks/duotone.js.map +1 -1
  83. package/build-module/hooks/index.js +1 -0
  84. package/build-module/hooks/index.js.map +1 -1
  85. package/build-module/index.js +1 -1
  86. package/build-module/index.js.map +1 -1
  87. package/build-module/store/actions.js +5 -14
  88. package/build-module/store/actions.js.map +1 -1
  89. package/build-module/store/selectors.js +112 -2
  90. package/build-module/store/selectors.js.map +1 -1
  91. package/build-module/store/utils.js +20 -0
  92. package/build-module/store/utils.js.map +1 -0
  93. package/build-style/style-rtl.css +35 -28
  94. package/build-style/style.css +35 -28
  95. package/package.json +28 -28
  96. package/src/components/block-alignment-control/ui.js +2 -2
  97. package/src/components/block-content-overlay/index.js +19 -2
  98. package/src/components/block-content-overlay/style.scss +0 -1
  99. package/src/components/block-lock/index.js +1 -0
  100. package/src/components/block-lock/menu-item.js +3 -23
  101. package/src/components/block-lock/modal.js +37 -13
  102. package/src/components/block-lock/style.scss +1 -2
  103. package/src/components/block-lock/toolbar.js +4 -21
  104. package/src/components/block-lock/use-block-lock.js +45 -0
  105. package/src/components/block-pattern-setup/index.js +84 -59
  106. package/src/components/block-pattern-setup/setup-toolbar.js +3 -1
  107. package/src/components/block-pattern-setup/style.scss +32 -26
  108. package/src/components/block-preview/auto.js +10 -1
  109. package/src/components/block-preview/index.js +2 -0
  110. package/src/components/block-switcher/index.js +13 -1
  111. package/src/components/block-switcher/style.scss +7 -3
  112. package/src/components/block-switcher/test/__snapshots__/index.js.snap +15 -13
  113. package/src/components/copy-handler/index.js +52 -10
  114. package/src/components/link-control/index.js +5 -5
  115. package/src/components/list-view/block-select-button.js +2 -10
  116. package/src/components/list-view/block.js +16 -7
  117. package/src/components/writing-flow/use-selection-observer.js +7 -0
  118. package/src/hooks/duotone.js +98 -62
  119. package/src/hooks/index.js +1 -0
  120. package/src/index.js +1 -0
  121. package/src/store/actions.js +5 -13
  122. package/src/store/selectors.js +148 -2
  123. package/src/store/utils.js +19 -0
@@ -12,6 +12,12 @@ import { Platform } from '@wordpress/element';
12
12
  import { applyFilters } from '@wordpress/hooks';
13
13
  import { symbol } from '@wordpress/icons';
14
14
  import { __ } from '@wordpress/i18n';
15
+ import { create, remove, toHTMLString } from '@wordpress/rich-text';
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+
20
+ import { mapRichTextSettings } from './utils';
15
21
  /**
16
22
  * A block selection object.
17
23
  *
@@ -853,6 +859,19 @@ export function __unstableIsFullySelected(state) {
853
859
  const selectionFocus = getSelectionEnd(state);
854
860
  return !selectionAnchor.attributeKey && !selectionFocus.attributeKey && typeof selectionAnchor.offset === 'undefined' && typeof selectionFocus.offset === 'undefined';
855
861
  }
862
+ /**
863
+ * Returns true if the selection is collapsed.
864
+ *
865
+ * @param {Object} state Editor state.
866
+ *
867
+ * @return {boolean} Whether the selection is collapsed.
868
+ */
869
+
870
+ export function __unstableIsSelectionCollapsed(state) {
871
+ const selectionAnchor = getSelectionStart(state);
872
+ const selectionFocus = getSelectionEnd(state);
873
+ return !!selectionAnchor && !!selectionFocus && selectionAnchor.clientId === selectionFocus.clientId && selectionAnchor.attributeKey === selectionFocus.attributeKey && selectionAnchor.offset === selectionFocus.offset;
874
+ }
856
875
  /**
857
876
  * Check whether the selection is mergeable.
858
877
  *
@@ -904,6 +923,75 @@ export function __unstableIsSelectionMergeable(state, isForward) {
904
923
  const blocksToMerge = switchToBlockType(blockToMerge, targetBlock.name);
905
924
  return blocksToMerge && blocksToMerge.length;
906
925
  }
926
+ /**
927
+ * Get partial selected blocks with their content updated
928
+ * based on the selection.
929
+ *
930
+ * @param {Object} state Editor state.
931
+ *
932
+ * @return {Object[]} Updated partial selected blocks.
933
+ */
934
+
935
+ export const __unstableGetSelectedBlocksWithPartialSelection = state => {
936
+ const selectionAnchor = getSelectionStart(state);
937
+ const selectionFocus = getSelectionEnd(state);
938
+
939
+ if (selectionAnchor.clientId === selectionFocus.clientId) {
940
+ return EMPTY_ARRAY;
941
+ } // Can't split if the selection is not set.
942
+
943
+
944
+ if (!selectionAnchor.attributeKey || !selectionFocus.attributeKey || typeof selectionAnchor.offset === 'undefined' || typeof selectionFocus.offset === 'undefined') {
945
+ return EMPTY_ARRAY;
946
+ }
947
+
948
+ const anchorRootClientId = getBlockRootClientId(state, selectionAnchor.clientId);
949
+ const focusRootClientId = getBlockRootClientId(state, selectionFocus.clientId); // It's not splittable if the selection doesn't start and end in the same
950
+ // block list. Maybe in the future it should be allowed.
951
+
952
+ if (anchorRootClientId !== focusRootClientId) {
953
+ return EMPTY_ARRAY;
954
+ }
955
+
956
+ const blockOrder = getBlockOrder(state, anchorRootClientId);
957
+ const anchorIndex = blockOrder.indexOf(selectionAnchor.clientId);
958
+ const focusIndex = blockOrder.indexOf(selectionFocus.clientId); // Reassign selection start and end based on order.
959
+
960
+ const [selectionStart, selectionEnd] = anchorIndex > focusIndex ? [selectionFocus, selectionAnchor] : [selectionAnchor, selectionFocus];
961
+ const blockA = getBlock(state, selectionStart.clientId);
962
+ const blockAType = getBlockType(blockA.name);
963
+ const blockB = getBlock(state, selectionEnd.clientId);
964
+ const blockBType = getBlockType(blockB.name);
965
+ const htmlA = blockA.attributes[selectionStart.attributeKey];
966
+ const htmlB = blockB.attributes[selectionEnd.attributeKey];
967
+ const attributeDefinitionA = blockAType.attributes[selectionStart.attributeKey];
968
+ const attributeDefinitionB = blockBType.attributes[selectionEnd.attributeKey];
969
+ let valueA = create({
970
+ html: htmlA,
971
+ ...mapRichTextSettings(attributeDefinitionA)
972
+ });
973
+ let valueB = create({
974
+ html: htmlB,
975
+ ...mapRichTextSettings(attributeDefinitionB)
976
+ });
977
+ valueA = remove(valueA, 0, selectionStart.offset);
978
+ valueB = remove(valueB, selectionEnd.offset, valueB.text.length);
979
+ return [{ ...blockA,
980
+ attributes: { ...blockA.attributes,
981
+ [selectionStart.attributeKey]: toHTMLString({
982
+ value: valueA,
983
+ ...mapRichTextSettings(attributeDefinitionA)
984
+ })
985
+ }
986
+ }, { ...blockB,
987
+ attributes: { ...blockB.attributes,
988
+ [selectionEnd.attributeKey]: toHTMLString({
989
+ value: valueB,
990
+ ...mapRichTextSettings(attributeDefinitionB)
991
+ })
992
+ }
993
+ }];
994
+ };
907
995
  /**
908
996
  * Returns an array containing all block client IDs in the editor in the order
909
997
  * they appear. Optionally accepts a root client ID of the block list for which
@@ -1379,7 +1467,7 @@ export function canRemoveBlock(state, clientId) {
1379
1467
  const {
1380
1468
  lock
1381
1469
  } = attributes;
1382
- const parentIsLocked = !!getTemplateLock(state, rootClientId); // If we don't have a lock on the blockType level, we differ to the parent templateLock.
1470
+ const parentIsLocked = !!getTemplateLock(state, rootClientId); // If we don't have a lock on the blockType level, we defer to the parent templateLock.
1383
1471
 
1384
1472
  if (lock === undefined || (lock === null || lock === void 0 ? void 0 : lock.remove) === undefined) {
1385
1473
  return !parentIsLocked;
@@ -1423,7 +1511,7 @@ export function canMoveBlock(state, clientId) {
1423
1511
  const {
1424
1512
  lock
1425
1513
  } = attributes;
1426
- const parentIsLocked = getTemplateLock(state, rootClientId) === 'all'; // If we don't have a lock on the blockType level, we differ to the parent templateLock.
1514
+ const parentIsLocked = getTemplateLock(state, rootClientId) === 'all'; // If we don't have a lock on the blockType level, we defer to the parent templateLock.
1427
1515
 
1428
1516
  if (lock === undefined || (lock === null || lock === void 0 ? void 0 : lock.move) === undefined) {
1429
1517
  return !parentIsLocked;
@@ -1446,6 +1534,28 @@ export function canMoveBlocks(state, clientIds) {
1446
1534
  let rootClientId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1447
1535
  return clientIds.every(clientId => canMoveBlock(state, clientId, rootClientId));
1448
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
+ }
1449
1559
  /**
1450
1560
  * Determines if the given block type can be locked/unlocked by a user.
1451
1561
  *