@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
package/build/store/selectors.js
CHANGED
|
@@ -7,11 +7,13 @@ 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;
|
|
16
|
+
exports.canEditBlock = canEditBlock;
|
|
15
17
|
exports.canInsertBlockType = void 0;
|
|
16
18
|
exports.canInsertBlocks = canInsertBlocks;
|
|
17
19
|
exports.canLockBlockType = canLockBlockType;
|
|
@@ -98,6 +100,10 @@ var _icons = require("@wordpress/icons");
|
|
|
98
100
|
|
|
99
101
|
var _i18n = require("@wordpress/i18n");
|
|
100
102
|
|
|
103
|
+
var _richText = require("@wordpress/rich-text");
|
|
104
|
+
|
|
105
|
+
var _utils = require("./utils");
|
|
106
|
+
|
|
101
107
|
/**
|
|
102
108
|
* External dependencies
|
|
103
109
|
*/
|
|
@@ -106,6 +112,10 @@ var _i18n = require("@wordpress/i18n");
|
|
|
106
112
|
* WordPress dependencies
|
|
107
113
|
*/
|
|
108
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Internal dependencies
|
|
117
|
+
*/
|
|
118
|
+
|
|
109
119
|
/**
|
|
110
120
|
* A block selection object.
|
|
111
121
|
*
|
|
@@ -999,6 +1009,20 @@ function __unstableIsFullySelected(state) {
|
|
|
999
1009
|
const selectionFocus = getSelectionEnd(state);
|
|
1000
1010
|
return !selectionAnchor.attributeKey && !selectionFocus.attributeKey && typeof selectionAnchor.offset === 'undefined' && typeof selectionFocus.offset === 'undefined';
|
|
1001
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
|
+
}
|
|
1002
1026
|
/**
|
|
1003
1027
|
* Check whether the selection is mergeable.
|
|
1004
1028
|
*
|
|
@@ -1051,6 +1075,76 @@ function __unstableIsSelectionMergeable(state, isForward) {
|
|
|
1051
1075
|
const blocksToMerge = (0, _blocks.switchToBlockType)(blockToMerge, targetBlock.name);
|
|
1052
1076
|
return blocksToMerge && blocksToMerge.length;
|
|
1053
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
|
+
};
|
|
1054
1148
|
/**
|
|
1055
1149
|
* Returns an array containing all block client IDs in the editor in the order
|
|
1056
1150
|
* they appear. Optionally accepts a root client ID of the block list for which
|
|
@@ -1063,6 +1157,8 @@ function __unstableIsSelectionMergeable(state, isForward) {
|
|
|
1063
1157
|
*/
|
|
1064
1158
|
|
|
1065
1159
|
|
|
1160
|
+
exports.__unstableGetSelectedBlocksWithPartialSelection = __unstableGetSelectedBlocksWithPartialSelection;
|
|
1161
|
+
|
|
1066
1162
|
function getBlockOrder(state, rootClientId) {
|
|
1067
1163
|
return state.blocks.order[rootClientId || ''] || EMPTY_ARRAY;
|
|
1068
1164
|
}
|
|
@@ -1549,7 +1645,7 @@ function canRemoveBlock(state, clientId) {
|
|
|
1549
1645
|
const {
|
|
1550
1646
|
lock
|
|
1551
1647
|
} = attributes;
|
|
1552
|
-
const parentIsLocked = !!getTemplateLock(state, rootClientId); // If we don't have a lock on the blockType level, we
|
|
1648
|
+
const parentIsLocked = !!getTemplateLock(state, rootClientId); // If we don't have a lock on the blockType level, we defer to the parent templateLock.
|
|
1553
1649
|
|
|
1554
1650
|
if (lock === undefined || (lock === null || lock === void 0 ? void 0 : lock.remove) === undefined) {
|
|
1555
1651
|
return !parentIsLocked;
|
|
@@ -1595,7 +1691,7 @@ function canMoveBlock(state, clientId) {
|
|
|
1595
1691
|
const {
|
|
1596
1692
|
lock
|
|
1597
1693
|
} = attributes;
|
|
1598
|
-
const parentIsLocked = getTemplateLock(state, rootClientId) === 'all'; // If we don't have a lock on the blockType level, we
|
|
1694
|
+
const parentIsLocked = getTemplateLock(state, rootClientId) === 'all'; // If we don't have a lock on the blockType level, we defer to the parent templateLock.
|
|
1599
1695
|
|
|
1600
1696
|
if (lock === undefined || (lock === null || lock === void 0 ? void 0 : lock.move) === undefined) {
|
|
1601
1697
|
return !parentIsLocked;
|
|
@@ -1619,6 +1715,29 @@ function canMoveBlocks(state, clientIds) {
|
|
|
1619
1715
|
let rootClientId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1620
1716
|
return clientIds.every(clientId => canMoveBlock(state, clientId, rootClientId));
|
|
1621
1717
|
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Determines if the given block is allowed to be edited.
|
|
1720
|
+
*
|
|
1721
|
+
* @param {Object} state Editor state.
|
|
1722
|
+
* @param {string} clientId The block client Id.
|
|
1723
|
+
*
|
|
1724
|
+
* @return {boolean} Whether the given block is allowed to be edited.
|
|
1725
|
+
*/
|
|
1726
|
+
|
|
1727
|
+
|
|
1728
|
+
function canEditBlock(state, clientId) {
|
|
1729
|
+
const attributes = getBlockAttributes(state, clientId);
|
|
1730
|
+
|
|
1731
|
+
if (attributes === null) {
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
const {
|
|
1736
|
+
lock
|
|
1737
|
+
} = attributes; // When the edit is true, we cannot edit the block.
|
|
1738
|
+
|
|
1739
|
+
return !(lock !== null && lock !== void 0 && lock.edit);
|
|
1740
|
+
}
|
|
1622
1741
|
/**
|
|
1623
1742
|
* Determines if the given block type can be locked/unlocked by a user.
|
|
1624
1743
|
*
|