@atlaskit/editor-plugin-block-type 12.1.19 → 12.1.20
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/CHANGELOG.md +9 -0
- package/dist/cjs/pm-plugins/commands/block-type.js +31 -25
- package/dist/cjs/pm-plugins/commands/wrapSelectionIn.js +6 -4
- package/dist/cjs/pm-plugins/utils.js +75 -18
- package/dist/es2019/pm-plugins/commands/block-type.js +31 -21
- package/dist/es2019/pm-plugins/commands/wrapSelectionIn.js +6 -4
- package/dist/es2019/pm-plugins/utils.js +65 -8
- package/dist/esm/pm-plugins/commands/block-type.js +31 -25
- package/dist/esm/pm-plugins/commands/wrapSelectionIn.js +6 -4
- package/dist/esm/pm-plugins/utils.js +74 -18
- package/dist/types/pm-plugins/commands/block-type.d.ts +2 -2
- package/dist/types/pm-plugins/commands/wrapSelectionIn.d.ts +1 -1
- package/dist/types/pm-plugins/utils.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/commands/block-type.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/commands/wrapSelectionIn.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-type
|
|
2
2
|
|
|
3
|
+
## 12.1.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1c4534dc921e6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1c4534dc921e6) -
|
|
8
|
+
Preserve small text formatting when converting selections to task lists across block menu, block
|
|
9
|
+
type, and paste flows
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 12.1.19
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -121,7 +121,7 @@ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBl
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
if (name === 'smallText' && marks.fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
124
|
-
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
|
|
124
|
+
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
|
|
125
125
|
tr: tr
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -134,7 +134,7 @@ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBl
|
|
|
134
134
|
return null;
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
function setSmallText() {
|
|
137
|
+
function setSmallText(fromBlockQuote) {
|
|
138
138
|
return function (_ref5) {
|
|
139
139
|
var tr = _ref5.tr;
|
|
140
140
|
var _tr$doc$type$schema2 = tr.doc.type.schema,
|
|
@@ -144,39 +144,45 @@ function setSmallText() {
|
|
|
144
144
|
return null;
|
|
145
145
|
}
|
|
146
146
|
var selection = tr.selection;
|
|
147
|
-
|
|
147
|
+
var applySmallFontSize = (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
|
|
148
|
+
return {
|
|
149
|
+
fontSize: 'small'
|
|
150
|
+
};
|
|
151
|
+
}, [paragraph]);
|
|
152
|
+
if (fromBlockQuote) {
|
|
153
|
+
var $from = selection.$from,
|
|
154
|
+
$to = selection.$to;
|
|
155
|
+
var range = $from.blockRange($to);
|
|
156
|
+
if (!range) {
|
|
157
|
+
return tr;
|
|
158
|
+
}
|
|
159
|
+
var targetLiftDepth = (0, _transform.liftTarget)(range);
|
|
160
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
161
|
+
tr.lift(range, targetLiftDepth);
|
|
162
|
+
}
|
|
163
|
+
var from = tr.mapping.map($from.pos);
|
|
164
|
+
var to = tr.mapping.map($to.pos);
|
|
165
|
+
tr.setBlockType(from, to, paragraph);
|
|
166
|
+
applySmallFontSize(from, to, tr);
|
|
167
|
+
} else if (selection instanceof _editorTables.CellSelection) {
|
|
148
168
|
var mapFrom = tr.steps.length;
|
|
149
169
|
selection.forEachCell(function (cell, pos) {
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
(0,
|
|
154
|
-
|
|
155
|
-
fontSize: 'small'
|
|
156
|
-
};
|
|
157
|
-
}, [paragraph])(mappedPos, mappedPos + cell.nodeSize, tr);
|
|
170
|
+
var from = tr.mapping.slice(mapFrom).map(pos);
|
|
171
|
+
var to = from + cell.nodeSize;
|
|
172
|
+
tr.setBlockType(from, to, paragraph);
|
|
173
|
+
(0, _utils2.convertTaskItemsToBlockTaskItems)(tr, from, to);
|
|
174
|
+
applySmallFontSize(from, to, tr);
|
|
158
175
|
});
|
|
159
176
|
} else {
|
|
160
|
-
// Step 1. Convert headings to paragraphs (for non-task content)
|
|
161
177
|
tr.setBlockType(selection.from, selection.to, paragraph);
|
|
162
|
-
|
|
163
|
-
// Step 2. Expand the selection range to include full list nodes
|
|
164
178
|
var expandedRange = (0, _utils2.getSelectionRangeExpandedToLists)(tr);
|
|
165
|
-
|
|
166
|
-
// Step 3. Convert taskItems → blockTaskItems so their content can hold the fontSize mark
|
|
167
179
|
(0, _utils2.convertTaskItemsToBlockTaskItems)(tr, expandedRange.from, expandedRange.to);
|
|
168
|
-
|
|
169
|
-
// Step 4. Apply fontSize mark to all paragraphs in range (including those inside new blockTaskItems)
|
|
170
|
-
(0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
|
|
171
|
-
return {
|
|
172
|
-
fontSize: 'small'
|
|
173
|
-
};
|
|
174
|
-
}, [paragraph])(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
180
|
+
applySmallFontSize(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
175
181
|
}
|
|
176
182
|
return tr;
|
|
177
183
|
};
|
|
178
184
|
}
|
|
179
|
-
function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
185
|
+
function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
|
|
180
186
|
return withCurrentHeadingLevel(function (previousHeadingLevel) {
|
|
181
187
|
return function (_ref6) {
|
|
182
188
|
var tr = _ref6.tr;
|
|
@@ -190,7 +196,7 @@ function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
|
190
196
|
previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
|
|
191
197
|
}
|
|
192
198
|
})(tr);
|
|
193
|
-
return setSmallText()({
|
|
199
|
+
return setSmallText(fromBlockQuote)({
|
|
194
200
|
tr: tr
|
|
195
201
|
});
|
|
196
202
|
};
|
|
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.wrapSelectionInBlockType = wrapSelectionInBlockType;
|
|
7
7
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
8
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
9
|
-
|
|
9
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
10
|
+
function wrapSelectionInBlockType(_nodeType) {
|
|
10
11
|
return function (_ref) {
|
|
11
12
|
var tr = _ref.tr;
|
|
12
13
|
var nodes = tr.doc.type.schema.nodes;
|
|
13
14
|
var _tr$doc$type$schema$m = tr.doc.type.schema.marks,
|
|
14
15
|
alignment = _tr$doc$type$schema$m.alignment,
|
|
15
|
-
indentation = _tr$doc$type$schema$m.indentation
|
|
16
|
+
indentation = _tr$doc$type$schema$m.indentation,
|
|
17
|
+
fontSize = _tr$doc$type$schema$m.fontSize;
|
|
16
18
|
if (nodes.paragraph && nodes.blockquote) {
|
|
17
|
-
/**Remove alignment and
|
|
18
|
-
var marksToRemove = [alignment, indentation];
|
|
19
|
+
/** Remove alignment, indentation, and unsupported blockquote marks from the selection */
|
|
20
|
+
var marksToRemove = (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? [alignment, indentation, fontSize] : [alignment, indentation];
|
|
19
21
|
var hasMark = function hasMark(mark) {
|
|
20
22
|
return marksToRemove.indexOf(mark.type) > -1;
|
|
21
23
|
};
|
|
@@ -9,9 +9,12 @@ exports.convertTaskItemsToBlockTaskItems = convertTaskItemsToBlockTaskItems;
|
|
|
9
9
|
exports.createWrappingTextBlockRule = exports.createJoinNodesRule = void 0;
|
|
10
10
|
exports.getSelectionRangeExpandedToLists = getSelectionRangeExpandedToLists;
|
|
11
11
|
exports.isNodeAWrappingBlockNode = exports.hasBlockQuoteInOptions = void 0;
|
|
12
|
+
exports.isSelectionInsideBlockquote = isSelectionInsideBlockquote;
|
|
12
13
|
exports.isSelectionInsideListNode = isSelectionInsideListNode;
|
|
13
14
|
var _mark = require("@atlaskit/editor-common/mark");
|
|
15
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
14
16
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
17
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
15
18
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
16
19
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
17
20
|
var _blockTypes = require("./block-types");
|
|
@@ -58,7 +61,8 @@ function getSelectedWrapperNodes(state) {
|
|
|
58
61
|
if (state.selection) {
|
|
59
62
|
var _state$selection = state.selection,
|
|
60
63
|
$from = _state$selection.$from,
|
|
61
|
-
$to = _state$selection.$to
|
|
64
|
+
$to = _state$selection.$to,
|
|
65
|
+
empty = _state$selection.empty;
|
|
62
66
|
var _state$schema$nodes = state.schema.nodes,
|
|
63
67
|
blockquote = _state$schema$nodes.blockquote,
|
|
64
68
|
panel = _state$schema$nodes.panel,
|
|
@@ -73,6 +77,15 @@ function getSelectedWrapperNodes(state) {
|
|
|
73
77
|
taskList = _state$schema$nodes.taskList;
|
|
74
78
|
var wrapperNodes = [blockquote, panel, orderedList, bulletList, listItem, codeBlock, decisionItem, decisionList, taskItem, taskList];
|
|
75
79
|
wrapperNodes.push(caption);
|
|
80
|
+
if (empty && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
81
|
+
for (var depth = 0; depth <= $from.depth; depth++) {
|
|
82
|
+
var node = $from.node(depth);
|
|
83
|
+
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
84
|
+
nodes.push(node.type);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return nodes;
|
|
88
|
+
}
|
|
76
89
|
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
77
90
|
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
78
91
|
nodes.push(node.type);
|
|
@@ -96,7 +109,24 @@ function areBlockTypesDisabled(state) {
|
|
|
96
109
|
listItem = _state$schema$nodes2.listItem,
|
|
97
110
|
taskList = _state$schema$nodes2.taskList,
|
|
98
111
|
taskItem = _state$schema$nodes2.taskItem;
|
|
99
|
-
var
|
|
112
|
+
var isSmallFontSizeEnabled = allowFontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true);
|
|
113
|
+
var excludedTypes = isSmallFontSizeEnabled ? [panel, bulletList, orderedList, listItem, taskList, taskItem] : [panel];
|
|
114
|
+
var disallowedWrapperTypes = nodesTypes.filter(function (type) {
|
|
115
|
+
return !excludedTypes.includes(type);
|
|
116
|
+
});
|
|
117
|
+
if (isSmallFontSizeEnabled) {
|
|
118
|
+
var selectionInsideList = isSelectionInsideListNode(state);
|
|
119
|
+
var selectionInsideQuote = isSelectionInsideBlockquote(state);
|
|
120
|
+
|
|
121
|
+
// Inside a blockquote (but not a list nested within one): the blockquote itself isn't a
|
|
122
|
+
// disallowing wrapper, but anything else is.
|
|
123
|
+
if (selectionInsideQuote && !selectionInsideList) {
|
|
124
|
+
return disallowedWrapperTypes.some(function (type) {
|
|
125
|
+
return type !== blockquote;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return disallowedWrapperTypes.length > 0;
|
|
129
|
+
}
|
|
100
130
|
if ((0, _experiments.editorExperiment)('platform_editor_blockquote_in_text_formatting_menu', true)) {
|
|
101
131
|
var hasQuote = false;
|
|
102
132
|
var hasNestedListInQuote = false;
|
|
@@ -116,13 +146,9 @@ function areBlockTypesDisabled(state) {
|
|
|
116
146
|
}
|
|
117
147
|
return !hasNestedListInQuote;
|
|
118
148
|
});
|
|
119
|
-
return
|
|
120
|
-
return !excludedTypes.includes(type);
|
|
121
|
-
}).length > 0 && (!hasQuote || hasNestedListInQuote);
|
|
149
|
+
return disallowedWrapperTypes.length > 0 && (!hasQuote || hasNestedListInQuote);
|
|
122
150
|
}
|
|
123
|
-
return
|
|
124
|
-
return !excludedTypes.includes(type);
|
|
125
|
-
}).length > 0;
|
|
151
|
+
return disallowedWrapperTypes.length > 0;
|
|
126
152
|
}
|
|
127
153
|
|
|
128
154
|
/**
|
|
@@ -149,12 +175,40 @@ function isSelectionInsideListNode(state) {
|
|
|
149
175
|
}
|
|
150
176
|
return true;
|
|
151
177
|
});
|
|
152
|
-
return insideList
|
|
178
|
+
return insideList || listNodeTypes.some(function (nodeType) {
|
|
179
|
+
return (0, _utils2.hasParentNodeOfType)(nodeType)(state.selection);
|
|
180
|
+
});
|
|
153
181
|
}
|
|
154
|
-
|
|
182
|
+
function isSelectionInsideBlockquote(state) {
|
|
183
|
+
if (!state.selection) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
155
186
|
var _state$selection4 = state.selection,
|
|
156
|
-
from = _state$selection4
|
|
157
|
-
to = _state$selection4
|
|
187
|
+
$from = _state$selection4.$from,
|
|
188
|
+
$to = _state$selection4.$to;
|
|
189
|
+
var blockquote = state.schema.nodes.blockquote;
|
|
190
|
+
|
|
191
|
+
// For collapsed selections, check if the cursor is inside a blockquote
|
|
192
|
+
if ($from.pos === $to.pos) {
|
|
193
|
+
return (0, _utils2.hasParentNodeOfType)(blockquote)(state.selection);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// For range selections, check if any node in the range is a blockquote,
|
|
197
|
+
// or if the selection starts/ends inside a blockquote
|
|
198
|
+
var insideQuote = false;
|
|
199
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
200
|
+
if (node.type === blockquote) {
|
|
201
|
+
insideQuote = true;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
});
|
|
206
|
+
return insideQuote || (0, _utils2.hasParentNodeOfType)(blockquote)(state.selection);
|
|
207
|
+
}
|
|
208
|
+
var blockStylingIsPresent = function blockStylingIsPresent(state) {
|
|
209
|
+
var _state$selection5 = state.selection,
|
|
210
|
+
from = _state$selection5.from,
|
|
211
|
+
to = _state$selection5.to;
|
|
158
212
|
var isBlockStyling = false;
|
|
159
213
|
state.doc.nodesBetween(from, to, function (node) {
|
|
160
214
|
if (_blockTypes.FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
|
|
@@ -168,9 +222,9 @@ var blockStylingIsPresent = function blockStylingIsPresent(state) {
|
|
|
168
222
|
var marksArePresent = function marksArePresent(state) {
|
|
169
223
|
var activeMarkTypes = _blockTypes.FORMATTING_MARK_TYPES.filter(function (mark) {
|
|
170
224
|
if (!!state.schema.marks[mark]) {
|
|
171
|
-
var _state$
|
|
172
|
-
$from = _state$
|
|
173
|
-
empty = _state$
|
|
225
|
+
var _state$selection6 = state.selection,
|
|
226
|
+
$from = _state$selection6.$from,
|
|
227
|
+
empty = _state$selection6.empty;
|
|
174
228
|
var marks = state.schema.marks;
|
|
175
229
|
if (empty) {
|
|
176
230
|
return !!marks[mark].isInSet(state.storedMarks || $from.marks());
|
|
@@ -252,8 +306,7 @@ function getSelectionRangeExpandedToLists(tr) {
|
|
|
252
306
|
function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
253
307
|
var _tr$doc$type$schema$n2 = tr.doc.type.schema.nodes,
|
|
254
308
|
taskItem = _tr$doc$type$schema$n2.taskItem,
|
|
255
|
-
blockTaskItem = _tr$doc$type$schema$n2.blockTaskItem
|
|
256
|
-
paragraph = _tr$doc$type$schema$n2.paragraph;
|
|
309
|
+
blockTaskItem = _tr$doc$type$schema$n2.blockTaskItem;
|
|
257
310
|
if (!blockTaskItem || !taskItem) {
|
|
258
311
|
return;
|
|
259
312
|
}
|
|
@@ -274,7 +327,11 @@ function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
|
274
327
|
var _taskItemsToConvert$i = taskItemsToConvert[i],
|
|
275
328
|
pos = _taskItemsToConvert$i.pos,
|
|
276
329
|
node = _taskItemsToConvert$i.node;
|
|
277
|
-
var blockTaskNode =
|
|
330
|
+
var blockTaskNode = (0, _transforms.createBlockTaskItem)({
|
|
331
|
+
attrs: node.attrs,
|
|
332
|
+
content: node.content,
|
|
333
|
+
schema: tr.doc.type.schema
|
|
334
|
+
});
|
|
278
335
|
tr.replaceWith(pos, pos + node.nodeSize, blockTaskNode);
|
|
279
336
|
}
|
|
280
337
|
}
|
|
@@ -112,7 +112,7 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
if (name === 'smallText' && marks.fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
115
|
-
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
|
|
115
|
+
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
|
|
116
116
|
tr
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -125,7 +125,7 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
|
|
|
125
125
|
return null;
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
export function setSmallText() {
|
|
128
|
+
export function setSmallText(fromBlockQuote) {
|
|
129
129
|
return function ({
|
|
130
130
|
tr
|
|
131
131
|
}) {
|
|
@@ -143,35 +143,45 @@ export function setSmallText() {
|
|
|
143
143
|
const {
|
|
144
144
|
selection
|
|
145
145
|
} = tr;
|
|
146
|
-
|
|
146
|
+
const applySmallFontSize = createToggleBlockMarkOnRangeNext(fontSize, () => ({
|
|
147
|
+
fontSize: 'small'
|
|
148
|
+
}), [paragraph]);
|
|
149
|
+
if (fromBlockQuote) {
|
|
150
|
+
const {
|
|
151
|
+
$from,
|
|
152
|
+
$to
|
|
153
|
+
} = selection;
|
|
154
|
+
const range = $from.blockRange($to);
|
|
155
|
+
if (!range) {
|
|
156
|
+
return tr;
|
|
157
|
+
}
|
|
158
|
+
const targetLiftDepth = liftTarget(range);
|
|
159
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
160
|
+
tr.lift(range, targetLiftDepth);
|
|
161
|
+
}
|
|
162
|
+
const from = tr.mapping.map($from.pos);
|
|
163
|
+
const to = tr.mapping.map($to.pos);
|
|
164
|
+
tr.setBlockType(from, to, paragraph);
|
|
165
|
+
applySmallFontSize(from, to, tr);
|
|
166
|
+
} else if (selection instanceof CellSelection) {
|
|
147
167
|
const mapFrom = tr.steps.length;
|
|
148
168
|
selection.forEachCell((cell, pos) => {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}), [paragraph])(mappedPos, mappedPos + cell.nodeSize, tr);
|
|
169
|
+
const from = tr.mapping.slice(mapFrom).map(pos);
|
|
170
|
+
const to = from + cell.nodeSize;
|
|
171
|
+
tr.setBlockType(from, to, paragraph);
|
|
172
|
+
convertTaskItemsToBlockTaskItems(tr, from, to);
|
|
173
|
+
applySmallFontSize(from, to, tr);
|
|
155
174
|
});
|
|
156
175
|
} else {
|
|
157
|
-
// Step 1. Convert headings to paragraphs (for non-task content)
|
|
158
176
|
tr.setBlockType(selection.from, selection.to, paragraph);
|
|
159
|
-
|
|
160
|
-
// Step 2. Expand the selection range to include full list nodes
|
|
161
177
|
const expandedRange = getSelectionRangeExpandedToLists(tr);
|
|
162
|
-
|
|
163
|
-
// Step 3. Convert taskItems → blockTaskItems so their content can hold the fontSize mark
|
|
164
178
|
convertTaskItemsToBlockTaskItems(tr, expandedRange.from, expandedRange.to);
|
|
165
|
-
|
|
166
|
-
// Step 4. Apply fontSize mark to all paragraphs in range (including those inside new blockTaskItems)
|
|
167
|
-
createToggleBlockMarkOnRangeNext(fontSize, () => ({
|
|
168
|
-
fontSize: 'small'
|
|
169
|
-
}), [paragraph])(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
179
|
+
applySmallFontSize(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
170
180
|
}
|
|
171
181
|
return tr;
|
|
172
182
|
};
|
|
173
183
|
}
|
|
174
|
-
export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
184
|
+
export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
|
|
175
185
|
return withCurrentHeadingLevel(previousHeadingLevel => ({
|
|
176
186
|
tr
|
|
177
187
|
}) => {
|
|
@@ -185,7 +195,7 @@ export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
|
185
195
|
previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
|
|
186
196
|
}
|
|
187
197
|
})(tr);
|
|
188
|
-
return setSmallText()({
|
|
198
|
+
return setSmallText(fromBlockQuote)({
|
|
189
199
|
tr
|
|
190
200
|
});
|
|
191
201
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
-
|
|
3
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
|
+
export function wrapSelectionInBlockType(_nodeType) {
|
|
4
5
|
return ({
|
|
5
6
|
tr
|
|
6
7
|
}) => {
|
|
@@ -9,11 +10,12 @@ export function wrapSelectionInBlockType(nodeType) {
|
|
|
9
10
|
} = tr.doc.type.schema;
|
|
10
11
|
const {
|
|
11
12
|
alignment,
|
|
12
|
-
indentation
|
|
13
|
+
indentation,
|
|
14
|
+
fontSize
|
|
13
15
|
} = tr.doc.type.schema.marks;
|
|
14
16
|
if (nodes.paragraph && nodes.blockquote) {
|
|
15
|
-
/**Remove alignment and
|
|
16
|
-
const marksToRemove = [alignment, indentation];
|
|
17
|
+
/** Remove alignment, indentation, and unsupported blockquote marks from the selection */
|
|
18
|
+
const marksToRemove = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? [alignment, indentation, fontSize] : [alignment, indentation];
|
|
17
19
|
const hasMark = mark => marksToRemove.indexOf(mark.type) > -1;
|
|
18
20
|
const not = fn => arg => !fn(arg);
|
|
19
21
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { anyMarkActive } from '@atlaskit/editor-common/mark';
|
|
2
|
+
import { createBlockTaskItem } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import { createRule, createWrappingJoinRule } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
5
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
6
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
7
|
import { WRAPPER_BLOCK_TYPES, FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES } from './block-types';
|
|
@@ -43,7 +45,8 @@ function getSelectedWrapperNodes(state) {
|
|
|
43
45
|
if (state.selection) {
|
|
44
46
|
const {
|
|
45
47
|
$from,
|
|
46
|
-
$to
|
|
48
|
+
$to,
|
|
49
|
+
empty
|
|
47
50
|
} = state.selection;
|
|
48
51
|
const {
|
|
49
52
|
blockquote,
|
|
@@ -60,6 +63,15 @@ function getSelectedWrapperNodes(state) {
|
|
|
60
63
|
} = state.schema.nodes;
|
|
61
64
|
const wrapperNodes = [blockquote, panel, orderedList, bulletList, listItem, codeBlock, decisionItem, decisionList, taskItem, taskList];
|
|
62
65
|
wrapperNodes.push(caption);
|
|
66
|
+
if (empty && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
67
|
+
for (let depth = 0; depth <= $from.depth; depth++) {
|
|
68
|
+
const node = $from.node(depth);
|
|
69
|
+
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
70
|
+
nodes.push(node.type);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return nodes;
|
|
74
|
+
}
|
|
63
75
|
state.doc.nodesBetween($from.pos, $to.pos, node => {
|
|
64
76
|
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
65
77
|
nodes.push(node.type);
|
|
@@ -83,7 +95,20 @@ export function areBlockTypesDisabled(state, allowFontSize = false) {
|
|
|
83
95
|
taskList,
|
|
84
96
|
taskItem
|
|
85
97
|
} = state.schema.nodes;
|
|
86
|
-
const
|
|
98
|
+
const isSmallFontSizeEnabled = allowFontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true);
|
|
99
|
+
const excludedTypes = isSmallFontSizeEnabled ? [panel, bulletList, orderedList, listItem, taskList, taskItem] : [panel];
|
|
100
|
+
const disallowedWrapperTypes = nodesTypes.filter(type => !excludedTypes.includes(type));
|
|
101
|
+
if (isSmallFontSizeEnabled) {
|
|
102
|
+
const selectionInsideList = isSelectionInsideListNode(state);
|
|
103
|
+
const selectionInsideQuote = isSelectionInsideBlockquote(state);
|
|
104
|
+
|
|
105
|
+
// Inside a blockquote (but not a list nested within one): the blockquote itself isn't a
|
|
106
|
+
// disallowing wrapper, but anything else is.
|
|
107
|
+
if (selectionInsideQuote && !selectionInsideList) {
|
|
108
|
+
return disallowedWrapperTypes.some(type => type !== blockquote);
|
|
109
|
+
}
|
|
110
|
+
return disallowedWrapperTypes.length > 0;
|
|
111
|
+
}
|
|
87
112
|
if (editorExperiment('platform_editor_blockquote_in_text_formatting_menu', true)) {
|
|
88
113
|
let hasQuote = false;
|
|
89
114
|
let hasNestedListInQuote = false;
|
|
@@ -104,9 +129,9 @@ export function areBlockTypesDisabled(state, allowFontSize = false) {
|
|
|
104
129
|
}
|
|
105
130
|
return !hasNestedListInQuote;
|
|
106
131
|
});
|
|
107
|
-
return
|
|
132
|
+
return disallowedWrapperTypes.length > 0 && (!hasQuote || hasNestedListInQuote);
|
|
108
133
|
}
|
|
109
|
-
return
|
|
134
|
+
return disallowedWrapperTypes.length > 0;
|
|
110
135
|
}
|
|
111
136
|
|
|
112
137
|
/**
|
|
@@ -135,7 +160,36 @@ export function isSelectionInsideListNode(state) {
|
|
|
135
160
|
}
|
|
136
161
|
return true;
|
|
137
162
|
});
|
|
138
|
-
return insideList;
|
|
163
|
+
return insideList || listNodeTypes.some(nodeType => hasParentNodeOfType(nodeType)(state.selection));
|
|
164
|
+
}
|
|
165
|
+
export function isSelectionInsideBlockquote(state) {
|
|
166
|
+
if (!state.selection) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const {
|
|
170
|
+
$from,
|
|
171
|
+
$to
|
|
172
|
+
} = state.selection;
|
|
173
|
+
const {
|
|
174
|
+
blockquote
|
|
175
|
+
} = state.schema.nodes;
|
|
176
|
+
|
|
177
|
+
// For collapsed selections, check if the cursor is inside a blockquote
|
|
178
|
+
if ($from.pos === $to.pos) {
|
|
179
|
+
return hasParentNodeOfType(blockquote)(state.selection);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// For range selections, check if any node in the range is a blockquote,
|
|
183
|
+
// or if the selection starts/ends inside a blockquote
|
|
184
|
+
let insideQuote = false;
|
|
185
|
+
state.doc.nodesBetween($from.pos, $to.pos, node => {
|
|
186
|
+
if (node.type === blockquote) {
|
|
187
|
+
insideQuote = true;
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
});
|
|
192
|
+
return insideQuote || hasParentNodeOfType(blockquote)(state.selection);
|
|
139
193
|
}
|
|
140
194
|
const blockStylingIsPresent = state => {
|
|
141
195
|
const {
|
|
@@ -244,8 +298,7 @@ export function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
|
244
298
|
const {
|
|
245
299
|
nodes: {
|
|
246
300
|
taskItem,
|
|
247
|
-
blockTaskItem
|
|
248
|
-
paragraph
|
|
301
|
+
blockTaskItem
|
|
249
302
|
}
|
|
250
303
|
} = tr.doc.type.schema;
|
|
251
304
|
if (!blockTaskItem || !taskItem) {
|
|
@@ -269,7 +322,11 @@ export function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
|
269
322
|
pos,
|
|
270
323
|
node
|
|
271
324
|
} = taskItemsToConvert[i];
|
|
272
|
-
const blockTaskNode =
|
|
325
|
+
const blockTaskNode = createBlockTaskItem({
|
|
326
|
+
attrs: node.attrs,
|
|
327
|
+
content: node.content,
|
|
328
|
+
schema: tr.doc.type.schema
|
|
329
|
+
});
|
|
273
330
|
tr.replaceWith(pos, pos + node.nodeSize, blockTaskNode);
|
|
274
331
|
}
|
|
275
332
|
}
|
|
@@ -104,7 +104,7 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
if (name === 'smallText' && marks.fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
107
|
-
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
|
|
107
|
+
return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
|
|
108
108
|
tr: tr
|
|
109
109
|
});
|
|
110
110
|
}
|
|
@@ -117,7 +117,7 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
|
|
|
117
117
|
return null;
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
export function setSmallText() {
|
|
120
|
+
export function setSmallText(fromBlockQuote) {
|
|
121
121
|
return function (_ref5) {
|
|
122
122
|
var tr = _ref5.tr;
|
|
123
123
|
var _tr$doc$type$schema2 = tr.doc.type.schema,
|
|
@@ -127,39 +127,45 @@ export function setSmallText() {
|
|
|
127
127
|
return null;
|
|
128
128
|
}
|
|
129
129
|
var selection = tr.selection;
|
|
130
|
-
|
|
130
|
+
var applySmallFontSize = createToggleBlockMarkOnRangeNext(fontSize, function () {
|
|
131
|
+
return {
|
|
132
|
+
fontSize: 'small'
|
|
133
|
+
};
|
|
134
|
+
}, [paragraph]);
|
|
135
|
+
if (fromBlockQuote) {
|
|
136
|
+
var $from = selection.$from,
|
|
137
|
+
$to = selection.$to;
|
|
138
|
+
var range = $from.blockRange($to);
|
|
139
|
+
if (!range) {
|
|
140
|
+
return tr;
|
|
141
|
+
}
|
|
142
|
+
var targetLiftDepth = liftTarget(range);
|
|
143
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
144
|
+
tr.lift(range, targetLiftDepth);
|
|
145
|
+
}
|
|
146
|
+
var from = tr.mapping.map($from.pos);
|
|
147
|
+
var to = tr.mapping.map($to.pos);
|
|
148
|
+
tr.setBlockType(from, to, paragraph);
|
|
149
|
+
applySmallFontSize(from, to, tr);
|
|
150
|
+
} else if (selection instanceof CellSelection) {
|
|
131
151
|
var mapFrom = tr.steps.length;
|
|
132
152
|
selection.forEachCell(function (cell, pos) {
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
fontSize: 'small'
|
|
139
|
-
};
|
|
140
|
-
}, [paragraph])(mappedPos, mappedPos + cell.nodeSize, tr);
|
|
153
|
+
var from = tr.mapping.slice(mapFrom).map(pos);
|
|
154
|
+
var to = from + cell.nodeSize;
|
|
155
|
+
tr.setBlockType(from, to, paragraph);
|
|
156
|
+
convertTaskItemsToBlockTaskItems(tr, from, to);
|
|
157
|
+
applySmallFontSize(from, to, tr);
|
|
141
158
|
});
|
|
142
159
|
} else {
|
|
143
|
-
// Step 1. Convert headings to paragraphs (for non-task content)
|
|
144
160
|
tr.setBlockType(selection.from, selection.to, paragraph);
|
|
145
|
-
|
|
146
|
-
// Step 2. Expand the selection range to include full list nodes
|
|
147
161
|
var expandedRange = getSelectionRangeExpandedToLists(tr);
|
|
148
|
-
|
|
149
|
-
// Step 3. Convert taskItems → blockTaskItems so their content can hold the fontSize mark
|
|
150
162
|
convertTaskItemsToBlockTaskItems(tr, expandedRange.from, expandedRange.to);
|
|
151
|
-
|
|
152
|
-
// Step 4. Apply fontSize mark to all paragraphs in range (including those inside new blockTaskItems)
|
|
153
|
-
createToggleBlockMarkOnRangeNext(fontSize, function () {
|
|
154
|
-
return {
|
|
155
|
-
fontSize: 'small'
|
|
156
|
-
};
|
|
157
|
-
}, [paragraph])(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
163
|
+
applySmallFontSize(tr.mapping.map(expandedRange.from, -1), tr.mapping.map(expandedRange.to, 1), tr);
|
|
158
164
|
}
|
|
159
165
|
return tr;
|
|
160
166
|
};
|
|
161
167
|
}
|
|
162
|
-
export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
168
|
+
export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
|
|
163
169
|
return withCurrentHeadingLevel(function (previousHeadingLevel) {
|
|
164
170
|
return function (_ref6) {
|
|
165
171
|
var tr = _ref6.tr;
|
|
@@ -173,7 +179,7 @@ export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
|
173
179
|
previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
|
|
174
180
|
}
|
|
175
181
|
})(tr);
|
|
176
|
-
return setSmallText()({
|
|
182
|
+
return setSmallText(fromBlockQuote)({
|
|
177
183
|
tr: tr
|
|
178
184
|
});
|
|
179
185
|
};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
-
|
|
3
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
|
+
export function wrapSelectionInBlockType(_nodeType) {
|
|
4
5
|
return function (_ref) {
|
|
5
6
|
var tr = _ref.tr;
|
|
6
7
|
var nodes = tr.doc.type.schema.nodes;
|
|
7
8
|
var _tr$doc$type$schema$m = tr.doc.type.schema.marks,
|
|
8
9
|
alignment = _tr$doc$type$schema$m.alignment,
|
|
9
|
-
indentation = _tr$doc$type$schema$m.indentation
|
|
10
|
+
indentation = _tr$doc$type$schema$m.indentation,
|
|
11
|
+
fontSize = _tr$doc$type$schema$m.fontSize;
|
|
10
12
|
if (nodes.paragraph && nodes.blockquote) {
|
|
11
|
-
/**Remove alignment and
|
|
12
|
-
var marksToRemove = [alignment, indentation];
|
|
13
|
+
/** Remove alignment, indentation, and unsupported blockquote marks from the selection */
|
|
14
|
+
var marksToRemove = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? [alignment, indentation, fontSize] : [alignment, indentation];
|
|
13
15
|
var hasMark = function hasMark(mark) {
|
|
14
16
|
return marksToRemove.indexOf(mark.type) > -1;
|
|
15
17
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { anyMarkActive } from '@atlaskit/editor-common/mark';
|
|
2
|
+
import { createBlockTaskItem } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import { createRule, createWrappingJoinRule } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
5
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
6
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
7
|
import { WRAPPER_BLOCK_TYPES, FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES } from './block-types';
|
|
@@ -46,7 +48,8 @@ function getSelectedWrapperNodes(state) {
|
|
|
46
48
|
if (state.selection) {
|
|
47
49
|
var _state$selection = state.selection,
|
|
48
50
|
$from = _state$selection.$from,
|
|
49
|
-
$to = _state$selection.$to
|
|
51
|
+
$to = _state$selection.$to,
|
|
52
|
+
empty = _state$selection.empty;
|
|
50
53
|
var _state$schema$nodes = state.schema.nodes,
|
|
51
54
|
blockquote = _state$schema$nodes.blockquote,
|
|
52
55
|
panel = _state$schema$nodes.panel,
|
|
@@ -61,6 +64,15 @@ function getSelectedWrapperNodes(state) {
|
|
|
61
64
|
taskList = _state$schema$nodes.taskList;
|
|
62
65
|
var wrapperNodes = [blockquote, panel, orderedList, bulletList, listItem, codeBlock, decisionItem, decisionList, taskItem, taskList];
|
|
63
66
|
wrapperNodes.push(caption);
|
|
67
|
+
if (empty && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
|
|
68
|
+
for (var depth = 0; depth <= $from.depth; depth++) {
|
|
69
|
+
var node = $from.node(depth);
|
|
70
|
+
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
71
|
+
nodes.push(node.type);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return nodes;
|
|
75
|
+
}
|
|
64
76
|
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
65
77
|
if (node.isBlock && wrapperNodes.indexOf(node.type) >= 0) {
|
|
66
78
|
nodes.push(node.type);
|
|
@@ -84,7 +96,24 @@ export function areBlockTypesDisabled(state) {
|
|
|
84
96
|
listItem = _state$schema$nodes2.listItem,
|
|
85
97
|
taskList = _state$schema$nodes2.taskList,
|
|
86
98
|
taskItem = _state$schema$nodes2.taskItem;
|
|
87
|
-
var
|
|
99
|
+
var isSmallFontSizeEnabled = allowFontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true);
|
|
100
|
+
var excludedTypes = isSmallFontSizeEnabled ? [panel, bulletList, orderedList, listItem, taskList, taskItem] : [panel];
|
|
101
|
+
var disallowedWrapperTypes = nodesTypes.filter(function (type) {
|
|
102
|
+
return !excludedTypes.includes(type);
|
|
103
|
+
});
|
|
104
|
+
if (isSmallFontSizeEnabled) {
|
|
105
|
+
var selectionInsideList = isSelectionInsideListNode(state);
|
|
106
|
+
var selectionInsideQuote = isSelectionInsideBlockquote(state);
|
|
107
|
+
|
|
108
|
+
// Inside a blockquote (but not a list nested within one): the blockquote itself isn't a
|
|
109
|
+
// disallowing wrapper, but anything else is.
|
|
110
|
+
if (selectionInsideQuote && !selectionInsideList) {
|
|
111
|
+
return disallowedWrapperTypes.some(function (type) {
|
|
112
|
+
return type !== blockquote;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return disallowedWrapperTypes.length > 0;
|
|
116
|
+
}
|
|
88
117
|
if (editorExperiment('platform_editor_blockquote_in_text_formatting_menu', true)) {
|
|
89
118
|
var hasQuote = false;
|
|
90
119
|
var hasNestedListInQuote = false;
|
|
@@ -104,13 +133,9 @@ export function areBlockTypesDisabled(state) {
|
|
|
104
133
|
}
|
|
105
134
|
return !hasNestedListInQuote;
|
|
106
135
|
});
|
|
107
|
-
return
|
|
108
|
-
return !excludedTypes.includes(type);
|
|
109
|
-
}).length > 0 && (!hasQuote || hasNestedListInQuote);
|
|
136
|
+
return disallowedWrapperTypes.length > 0 && (!hasQuote || hasNestedListInQuote);
|
|
110
137
|
}
|
|
111
|
-
return
|
|
112
|
-
return !excludedTypes.includes(type);
|
|
113
|
-
}).length > 0;
|
|
138
|
+
return disallowedWrapperTypes.length > 0;
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
/**
|
|
@@ -137,12 +162,40 @@ export function isSelectionInsideListNode(state) {
|
|
|
137
162
|
}
|
|
138
163
|
return true;
|
|
139
164
|
});
|
|
140
|
-
return insideList
|
|
165
|
+
return insideList || listNodeTypes.some(function (nodeType) {
|
|
166
|
+
return hasParentNodeOfType(nodeType)(state.selection);
|
|
167
|
+
});
|
|
141
168
|
}
|
|
142
|
-
|
|
169
|
+
export function isSelectionInsideBlockquote(state) {
|
|
170
|
+
if (!state.selection) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
143
173
|
var _state$selection4 = state.selection,
|
|
144
|
-
from = _state$selection4
|
|
145
|
-
to = _state$selection4
|
|
174
|
+
$from = _state$selection4.$from,
|
|
175
|
+
$to = _state$selection4.$to;
|
|
176
|
+
var blockquote = state.schema.nodes.blockquote;
|
|
177
|
+
|
|
178
|
+
// For collapsed selections, check if the cursor is inside a blockquote
|
|
179
|
+
if ($from.pos === $to.pos) {
|
|
180
|
+
return hasParentNodeOfType(blockquote)(state.selection);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// For range selections, check if any node in the range is a blockquote,
|
|
184
|
+
// or if the selection starts/ends inside a blockquote
|
|
185
|
+
var insideQuote = false;
|
|
186
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
187
|
+
if (node.type === blockquote) {
|
|
188
|
+
insideQuote = true;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
});
|
|
193
|
+
return insideQuote || hasParentNodeOfType(blockquote)(state.selection);
|
|
194
|
+
}
|
|
195
|
+
var blockStylingIsPresent = function blockStylingIsPresent(state) {
|
|
196
|
+
var _state$selection5 = state.selection,
|
|
197
|
+
from = _state$selection5.from,
|
|
198
|
+
to = _state$selection5.to;
|
|
146
199
|
var isBlockStyling = false;
|
|
147
200
|
state.doc.nodesBetween(from, to, function (node) {
|
|
148
201
|
if (FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
|
|
@@ -156,9 +209,9 @@ var blockStylingIsPresent = function blockStylingIsPresent(state) {
|
|
|
156
209
|
var marksArePresent = function marksArePresent(state) {
|
|
157
210
|
var activeMarkTypes = FORMATTING_MARK_TYPES.filter(function (mark) {
|
|
158
211
|
if (!!state.schema.marks[mark]) {
|
|
159
|
-
var _state$
|
|
160
|
-
$from = _state$
|
|
161
|
-
empty = _state$
|
|
212
|
+
var _state$selection6 = state.selection,
|
|
213
|
+
$from = _state$selection6.$from,
|
|
214
|
+
empty = _state$selection6.empty;
|
|
162
215
|
var marks = state.schema.marks;
|
|
163
216
|
if (empty) {
|
|
164
217
|
return !!marks[mark].isInSet(state.storedMarks || $from.marks());
|
|
@@ -240,8 +293,7 @@ export function getSelectionRangeExpandedToLists(tr) {
|
|
|
240
293
|
export function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
241
294
|
var _tr$doc$type$schema$n2 = tr.doc.type.schema.nodes,
|
|
242
295
|
taskItem = _tr$doc$type$schema$n2.taskItem,
|
|
243
|
-
blockTaskItem = _tr$doc$type$schema$n2.blockTaskItem
|
|
244
|
-
paragraph = _tr$doc$type$schema$n2.paragraph;
|
|
296
|
+
blockTaskItem = _tr$doc$type$schema$n2.blockTaskItem;
|
|
245
297
|
if (!blockTaskItem || !taskItem) {
|
|
246
298
|
return;
|
|
247
299
|
}
|
|
@@ -262,7 +314,11 @@ export function convertTaskItemsToBlockTaskItems(tr, from, to) {
|
|
|
262
314
|
var _taskItemsToConvert$i = taskItemsToConvert[i],
|
|
263
315
|
pos = _taskItemsToConvert$i.pos,
|
|
264
316
|
node = _taskItemsToConvert$i.node;
|
|
265
|
-
var blockTaskNode =
|
|
317
|
+
var blockTaskNode = createBlockTaskItem({
|
|
318
|
+
attrs: node.attrs,
|
|
319
|
+
content: node.content,
|
|
320
|
+
schema: tr.doc.type.schema
|
|
321
|
+
});
|
|
266
322
|
tr.replaceWith(pos, pos + node.nodeSize, blockTaskNode);
|
|
267
323
|
}
|
|
268
324
|
}
|
|
@@ -6,8 +6,8 @@ export type ClearFormattingInputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHO
|
|
|
6
6
|
export declare function setBlockType(name: TextBlockTypes): EditorCommand;
|
|
7
7
|
export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
|
|
8
8
|
export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
9
|
-
export declare function setSmallText(): EditorCommand;
|
|
10
|
-
export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
9
|
+
export declare function setSmallText(fromBlockQuote?: boolean): EditorCommand;
|
|
10
|
+
export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
11
11
|
export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
|
|
12
12
|
export declare function clearFormatting(inputMethod: ClearFormattingInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
13
13
|
export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
export declare function wrapSelectionInBlockType(
|
|
3
|
+
export declare function wrapSelectionInBlockType(_nodeType: NodeType): EditorCommand;
|
|
@@ -19,6 +19,7 @@ export declare function areBlockTypesDisabled(state: EditorState, allowFontSize?
|
|
|
19
19
|
* Used to determine which text styles should be enabled when the small font size experiment is active.
|
|
20
20
|
*/
|
|
21
21
|
export declare function isSelectionInsideListNode(state: EditorState): boolean;
|
|
22
|
+
export declare function isSelectionInsideBlockquote(state: EditorState): boolean;
|
|
22
23
|
export declare const checkFormattingIsPresent: (state: EditorState) => boolean;
|
|
23
24
|
export declare const hasBlockQuoteInOptions: (dropdownOptions: BlockType[]) => boolean;
|
|
24
25
|
/**
|
|
@@ -6,8 +6,8 @@ export type ClearFormattingInputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHO
|
|
|
6
6
|
export declare function setBlockType(name: TextBlockTypes): EditorCommand;
|
|
7
7
|
export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
|
|
8
8
|
export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
9
|
-
export declare function setSmallText(): EditorCommand;
|
|
10
|
-
export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
9
|
+
export declare function setSmallText(fromBlockQuote?: boolean): EditorCommand;
|
|
10
|
+
export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
11
11
|
export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
|
|
12
12
|
export declare function clearFormatting(inputMethod: ClearFormattingInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
13
13
|
export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
export declare function wrapSelectionInBlockType(
|
|
3
|
+
export declare function wrapSelectionInBlockType(_nodeType: NodeType): EditorCommand;
|
|
@@ -19,6 +19,7 @@ export declare function areBlockTypesDisabled(state: EditorState, allowFontSize?
|
|
|
19
19
|
* Used to determine which text styles should be enabled when the small font size experiment is active.
|
|
20
20
|
*/
|
|
21
21
|
export declare function isSelectionInsideListNode(state: EditorState): boolean;
|
|
22
|
+
export declare function isSelectionInsideBlockquote(state: EditorState): boolean;
|
|
22
23
|
export declare const checkFormattingIsPresent: (state: EditorState) => boolean;
|
|
23
24
|
export declare const hasBlockQuoteInOptions: (dropdownOptions: BlockType[]) => boolean;
|
|
24
25
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-type",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.20",
|
|
4
4
|
"description": "BlockType plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"@atlaskit/primitives": "^18.1.0",
|
|
50
50
|
"@atlaskit/prosemirror-history": "^0.2.0",
|
|
51
51
|
"@atlaskit/prosemirror-input-rules": "^3.6.0",
|
|
52
|
-
"@atlaskit/tmp-editor-statsig": "^52.
|
|
52
|
+
"@atlaskit/tmp-editor-statsig": "^52.1.0",
|
|
53
53
|
"@atlaskit/tokens": "^11.4.0",
|
|
54
54
|
"@babel/runtime": "^7.0.0",
|
|
55
55
|
"@compiled/react": "^0.20.0",
|
|
56
56
|
"@emotion/react": "^11.7.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@atlaskit/editor-common": "^112.
|
|
59
|
+
"@atlaskit/editor-common": "^112.15.0",
|
|
60
60
|
"react": "^18.2.0",
|
|
61
61
|
"react-dom": "^18.2.0",
|
|
62
62
|
"react-intl-next": "npm:react-intl@^5.18.1"
|