@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.
- 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-content-overlay/index.js +13 -4
- package/build/components/block-content-overlay/index.js.map +1 -1
- package/build/components/block-lock/index.js +8 -0
- package/build/components/block-lock/index.js.map +1 -1
- package/build/components/block-lock/menu-item.js +5 -20
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +33 -12
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +7 -20
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-lock/use-block-lock.js +50 -0
- package/build/components/block-lock/use-block-lock.js.map +1 -0
- package/build/components/block-pattern-setup/index.js +37 -22
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -3
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +4 -2
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-switcher/index.js +7 -2
- package/build/components/block-switcher/index.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-select-button.js +4 -10
- package/build/components/list-view/block-select-button.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/components/writing-flow/use-selection-observer.js +7 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/duotone.js +66 -16
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +7 -1
- package/build/hooks/index.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +22 -29
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +122 -3
- 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-content-overlay/index.js +13 -4
- package/build-module/components/block-content-overlay/index.js.map +1 -1
- package/build-module/components/block-lock/index.js +1 -0
- package/build-module/components/block-lock/index.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +4 -18
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +31 -12
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +6 -18
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-lock/use-block-lock.js +41 -0
- package/build-module/components/block-lock/use-block-lock.js.map +1 -0
- package/build-module/components/block-pattern-setup/index.js +39 -24
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +4 -2
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +7 -2
- package/build-module/components/block-switcher/index.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-select-button.js +4 -9
- package/build-module/components/list-view/block-select-button.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/components/writing-flow/use-selection-observer.js +7 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/duotone.js +63 -16
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.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 +112 -2
- 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 +35 -28
- package/build-style/style.css +35 -28
- package/package.json +28 -28
- package/src/components/block-alignment-control/ui.js +2 -2
- package/src/components/block-content-overlay/index.js +19 -2
- package/src/components/block-content-overlay/style.scss +0 -1
- package/src/components/block-lock/index.js +1 -0
- package/src/components/block-lock/menu-item.js +3 -23
- package/src/components/block-lock/modal.js +37 -13
- package/src/components/block-lock/style.scss +1 -2
- package/src/components/block-lock/toolbar.js +4 -21
- package/src/components/block-lock/use-block-lock.js +45 -0
- package/src/components/block-pattern-setup/index.js +84 -59
- package/src/components/block-pattern-setup/setup-toolbar.js +3 -1
- package/src/components/block-pattern-setup/style.scss +32 -26
- package/src/components/block-preview/auto.js +10 -1
- package/src/components/block-preview/index.js +2 -0
- package/src/components/block-switcher/index.js +13 -1
- package/src/components/block-switcher/style.scss +7 -3
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +15 -13
- package/src/components/copy-handler/index.js +52 -10
- package/src/components/link-control/index.js +5 -5
- package/src/components/list-view/block-select-button.js +2 -10
- package/src/components/list-view/block.js +16 -7
- package/src/components/writing-flow/use-selection-observer.js +7 -0
- package/src/hooks/duotone.js +98 -62
- package/src/hooks/index.js +1 -0
- package/src/index.js +1 -0
- package/src/store/actions.js +5 -13
- package/src/store/selectors.js +148 -2
- 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
|
|
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
|
|
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
|
*
|