@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
@@ -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