@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.
- package/build/components/block-alignment-control/ui.js +1 -1
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-lock/menu-item.js +1 -1
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +1 -1
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/use-block-lock.js +3 -6
- package/build/components/block-lock/use-block-lock.js.map +1 -1
- package/build/components/copy-handler/index.js +44 -9
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/link-control/index.js +6 -7
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block.js +13 -2
- package/build/components/list-view/block.js.map +1 -1
- package/build/store/actions.js +22 -29
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +96 -1
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +27 -0
- package/build/store/utils.js.map +1 -0
- package/build-module/components/block-alignment-control/ui.js +2 -2
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +1 -1
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +1 -1
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/use-block-lock.js +3 -6
- package/build-module/components/block-lock/use-block-lock.js.map +1 -1
- package/build-module/components/copy-handler/index.js +44 -9
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/link-control/index.js +6 -7
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block.js +13 -2
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/store/actions.js +5 -14
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +88 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +20 -0
- package/build-module/store/utils.js.map +1 -0
- package/build-style/style-rtl.css +1 -2
- package/build-style/style.css +1 -2
- package/package.json +28 -28
- package/src/components/block-alignment-control/ui.js +2 -2
- package/src/components/block-lock/menu-item.js +1 -1
- package/src/components/block-lock/modal.js +1 -1
- package/src/components/block-lock/style.scss +1 -2
- package/src/components/block-lock/use-block-lock.js +4 -8
- package/src/components/copy-handler/index.js +52 -10
- package/src/components/link-control/index.js +5 -5
- package/src/components/list-view/block.js +16 -7
- package/src/store/actions.js +5 -13
- package/src/store/selectors.js +126 -0
- 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
|