@titaui/pc 1.10.40 → 1.10.41

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.
@@ -73,144 +73,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
73
73
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
74
74
 
75
75
  // export type InputMethod = INPUT_METHOD.KEYBOARD | INPUT_METHOD.TOOLBAR;
76
- var enterKeyCommand = function enterKeyCommand(state, dispatch) {
77
- var selection = state.selection;
78
-
79
- if (selection.empty) {
80
- var $from = selection.$from;
81
- var _state$schema$nodes = state.schema.nodes,
82
- listItem = _state$schema$nodes.listItem,
83
- codeBlock = _state$schema$nodes.codeBlock;
84
- var node = $from.node($from.depth);
85
- var wrapper = $from.node($from.depth - 1);
86
-
87
- if (wrapper && wrapper.type === listItem) {
88
- /** Check if the wrapper has any visible content */
89
- var wrapperHasContent = (0, _document.hasVisibleContent)(wrapper);
90
-
91
- if ((0, _document.isNodeEmpty)(node) && !wrapperHasContent) {
92
- return (0, _outdentList.outdentList)()(state, dispatch);
93
- } else if (!(0, _prosemirrorUtils.hasParentNodeOfType)(codeBlock)(selection)) {
94
- return splitListItem(listItem)(state, dispatch);
95
- }
96
- }
97
- }
98
-
99
- return false;
100
- };
101
-
102
- exports.enterKeyCommand = enterKeyCommand;
103
-
104
- var backspaceKeyCommand = function backspaceKeyCommand(state, dispatch) {
105
- return baseCommand.chainCommands(_listBackspace.listBackspace, // if we're at the start of a list item, we need to either backspace
106
- // directly to an empty list item above, or outdent this node
107
- (0, _commands.filter)([function (state) {
108
- return state.selection.empty;
109
- }, // list items might have multiple paragraphs; only do this at the first one
110
- _commands.isFirstChildOfParent, _selection.isInsideListItem], baseCommand.chainCommands(deletePreviousEmptyListItem, (0, _outdentList.outdentList)())), // if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
111
- // the text to the previous list item, if one exists
112
- (0, _commands.filter)([function (state) {
113
- return state.selection.empty;
114
- }, _selection.canJoinToPreviousListItem], joinToPreviousListItem))(state, dispatch);
115
- };
116
-
117
- exports.backspaceKeyCommand = backspaceKeyCommand;
118
- var deleteKeyCommand = _joinListItemForward.joinListItemForward; // Get the depth of the nearest ancestor list
119
-
120
- exports.deleteKeyCommand = deleteKeyCommand;
121
-
122
- var rootListDepth = function rootListDepth(pos, nodes) {
123
- var bulletList = nodes.bulletList,
124
- orderedList = nodes.orderedList,
125
- listItem = nodes.listItem;
126
- var depth;
127
-
128
- for (var i = pos.depth - 1; i > 0; i--) {
129
- var node = pos.node(i);
130
-
131
- if (node.type === bulletList || node.type === orderedList) {
132
- depth = i;
133
- }
134
-
135
- if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
136
- break;
137
- }
138
- }
139
-
140
- return depth;
141
- };
142
-
143
- exports.rootListDepth = rootListDepth;
144
-
145
- function untoggleSelectedList(tr) {
146
- var _tr = tr,
147
- selection = _tr.selection;
148
- var depth = rootListDepth(selection.$to, tr.doc.type.schema.nodes);
149
- tr = (0, _transforms.liftFollowingList)(selection.$to.pos, selection.$to.end(depth), depth || 0, tr);
150
- tr = (0, _transforms.liftSelectionList)(selection, tr);
151
- }
152
76
 
153
- function toggleList(listType) {
154
- return function (state, dispatch) {
155
- var tr = state.tr;
156
- var listInsideSelection = (0, _selection.selectionContainsList)(tr);
157
- var listNodeType = state.schema.nodes[listType];
158
-
159
- if (listInsideSelection) {
160
- var selection = state.selection;
161
- var fromNode = selection.$from.node(selection.$from.depth - 2);
162
- var toNode = selection.$to.node(selection.$to.depth - 2);
163
-
164
- if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
165
- var _tr2 = state.tr;
166
- untoggleSelectedList(_tr2);
167
-
168
- if (dispatch) {
169
- dispatch(_tr2);
170
- }
171
-
172
- return true;
173
- }
174
-
175
- (0, _conversions.convertListType)({
176
- tr: tr,
177
- nextListNodeType: listNodeType
178
- });
179
- } else {
180
- // Need to have this before wrapInList so the wrapping is done with valid content
181
- // For example, if trying to convert centre or right aligned paragraphs to lists
182
- (0, _mark.sanitiseMarksInSelection)(tr, listNodeType);
183
- (0, _wrapAndJoinLists.wrapInListAndJoin)(listNodeType, tr);
184
- } // If document wasn't changed, return false from the command to indicate that the
185
- // editing action failed
186
-
187
-
188
- if (!tr.docChanged) {
189
- return false;
190
- }
191
-
192
- if (dispatch) {
193
- dispatch(tr);
194
- }
195
-
196
- return true;
197
- };
198
- }
199
-
200
- function toggleBulletList(view) {
201
- return toggleList('bulletList')(view.state, view.dispatch);
202
- }
203
-
204
- function toggleOrderedList(view) {
205
- return toggleList('orderedList')(view.state, view.dispatch);
206
- }
207
77
  /**
208
78
  * Implementation taken and modified for our needs from PM
209
79
  * @param itemType Node
210
80
  * Splits the list items, specific implementation take from PM
211
81
  */
212
-
213
-
214
82
  function splitListItem(itemType) {
215
83
  return function (state, dispatch) {
216
84
  var ref = state.selection;
@@ -243,7 +111,7 @@ function splitListItem(itemType) {
243
111
  var keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure
244
112
  // from the outer list item to the parent node of the cursor
245
113
 
246
- for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) {
114
+ for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d -= 1) {
247
115
  wrap = _prosemirrorModel.Fragment.from($from.node(d).copy(wrap));
248
116
  } // Add a second list item with an empty default start node
249
117
 
@@ -295,17 +163,46 @@ var deletePreviousEmptyListItem = function deletePreviousEmptyListItem(state, di
295
163
  return false;
296
164
  };
297
165
 
166
+ var enterKeyCommand = function enterKeyCommand(state, dispatch) {
167
+ var selection = state.selection;
168
+
169
+ if (selection.empty) {
170
+ var $from = selection.$from;
171
+ var _state$schema$nodes = state.schema.nodes,
172
+ listItem = _state$schema$nodes.listItem,
173
+ codeBlock = _state$schema$nodes.codeBlock;
174
+ var node = $from.node($from.depth);
175
+ var wrapper = $from.node($from.depth - 1);
176
+
177
+ if (wrapper && wrapper.type === listItem) {
178
+ /** Check if the wrapper has any visible content */
179
+ var wrapperHasContent = (0, _document.hasVisibleContent)(wrapper);
180
+
181
+ if ((0, _document.isNodeEmpty)(node) && !wrapperHasContent) {
182
+ return (0, _outdentList.outdentList)()(state, dispatch);
183
+ }
184
+
185
+ if (!(0, _prosemirrorUtils.hasParentNodeOfType)(codeBlock)(selection)) {
186
+ return splitListItem(listItem)(state, dispatch);
187
+ }
188
+ }
189
+ }
190
+
191
+ return false;
192
+ };
193
+
194
+ exports.enterKeyCommand = enterKeyCommand;
195
+
298
196
  var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
299
197
  var $from = state.selection.$from;
300
198
  var _state$schema$nodes2 = state.schema.nodes,
301
199
  paragraph = _state$schema$nodes2.paragraph,
302
- listItem = _state$schema$nodes2.listItem,
303
200
  codeBlock = _state$schema$nodes2.codeBlock,
304
201
  bulletList = _state$schema$nodes2.bulletList,
305
202
  orderedList = _state$schema$nodes2.orderedList; // const isGapCursorShown = state.selection instanceof GapCursorSelection;
306
203
 
307
204
  var $cutPos =
308
- /*isGapCursorShown ? state.doc.resolve($from.pos + 1) :*/
205
+ /* isGapCursorShown ? state.doc.resolve($from.pos + 1) : */
309
206
  $from;
310
207
  var $cut = (0, _commands.findCutBefore)($cutPos);
311
208
 
@@ -353,13 +250,12 @@ var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
353
250
 
354
251
  if (stepResult.failed) {
355
252
  return false;
356
- } else {
357
- tr = state.tr.step(step);
358
- } // }
253
+ }
254
+
255
+ tr = state.tr.step(step); // }
359
256
  // find out if there's now another list following and join them
360
257
  // as in, [list, p, list] => [list with p, list], and we want [joined list]
361
258
 
362
-
363
259
  var $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
364
260
 
365
261
  if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
@@ -377,6 +273,108 @@ var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
377
273
  return false;
378
274
  };
379
275
 
276
+ var backspaceKeyCommand = function backspaceKeyCommand(state, dispatch) {
277
+ return baseCommand.chainCommands(_listBackspace.listBackspace, // if we're at the start of a list item, we need to either backspace
278
+ // directly to an empty list item above, or outdent this node
279
+ (0, _commands.filter)([_commands.isEmptySelectionAtStart, // list items might have multiple paragraphs; only do this at the first one
280
+ _commands.isFirstChildOfParent, _selection.isInsideListItem], baseCommand.chainCommands(deletePreviousEmptyListItem, (0, _outdentList.outdentList)())), // if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
281
+ // the text to the previous list item, if one exists
282
+ (0, _commands.filter)([function (state) {
283
+ return state.selection.empty;
284
+ }, _selection.canJoinToPreviousListItem], joinToPreviousListItem))(state, dispatch);
285
+ };
286
+
287
+ exports.backspaceKeyCommand = backspaceKeyCommand;
288
+ var deleteKeyCommand = _joinListItemForward.joinListItemForward; // Get the depth of the nearest ancestor list
289
+
290
+ exports.deleteKeyCommand = deleteKeyCommand;
291
+
292
+ var rootListDepth = function rootListDepth(pos, nodes) {
293
+ var bulletList = nodes.bulletList,
294
+ orderedList = nodes.orderedList,
295
+ listItem = nodes.listItem;
296
+ var depth;
297
+
298
+ for (var i = pos.depth - 1; i > 0; i -= 1) {
299
+ var node = pos.node(i);
300
+
301
+ if (node.type === bulletList || node.type === orderedList) {
302
+ depth = i;
303
+ }
304
+
305
+ if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
306
+ break;
307
+ }
308
+ }
309
+
310
+ return depth;
311
+ };
312
+
313
+ exports.rootListDepth = rootListDepth;
314
+
315
+ function untoggleSelectedList(tr) {
316
+ var selection = tr.selection;
317
+ var depth = rootListDepth(selection.$to, tr.doc.type.schema.nodes);
318
+ var newtr = (0, _transforms.liftFollowingList)(selection.$to.pos, selection.$to.end(depth), depth || 0, tr);
319
+ newtr = (0, _transforms.liftSelectionList)(selection, tr);
320
+ return newtr;
321
+ }
322
+
323
+ function toggleList(listType) {
324
+ return function (state, dispatch) {
325
+ var tr = state.tr;
326
+ var listInsideSelection = (0, _selection.selectionContainsList)(tr);
327
+ var listNodeType = state.schema.nodes[listType];
328
+
329
+ if (listInsideSelection) {
330
+ var selection = state.selection;
331
+ var fromNode = selection.$from.node(selection.$from.depth - 2);
332
+ var toNode = selection.$to.node(selection.$to.depth - 2);
333
+
334
+ if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
335
+ var _tr = state.tr;
336
+ _tr = untoggleSelectedList(_tr);
337
+
338
+ if (dispatch) {
339
+ dispatch(_tr);
340
+ }
341
+
342
+ return true;
343
+ }
344
+
345
+ (0, _conversions.convertListType)({
346
+ tr: tr,
347
+ nextListNodeType: listNodeType
348
+ });
349
+ } else {
350
+ // Need to have this before wrapInList so the wrapping is done with valid content
351
+ // For example, if trying to convert centre or right aligned paragraphs to lists
352
+ (0, _mark.sanitiseMarksInSelection)(tr, listNodeType);
353
+ (0, _wrapAndJoinLists.wrapInListAndJoin)(listNodeType, tr);
354
+ } // If document wasn't changed, return false from the command to indicate that the
355
+ // editing action failed
356
+
357
+
358
+ if (!tr.docChanged) {
359
+ return false;
360
+ }
361
+
362
+ if (dispatch) {
363
+ dispatch(tr);
364
+ }
365
+
366
+ return true;
367
+ };
368
+ }
369
+
370
+ function toggleBulletList(view) {
371
+ return toggleList("bulletList")(view.state, view.dispatch);
372
+ }
373
+
374
+ function toggleOrderedList(view) {
375
+ return toggleList("orderedList")(view.state, view.dispatch);
376
+ }
377
+
380
378
  var insertContentDeleteRange = function insertContentDeleteRange(tr, getSelectionResolvedPos, insertions, deletions) {
381
379
  insertions.forEach(function (contentInsert) {
382
380
  var _contentInsert = _slicedToArray(contentInsert, 2),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titaui/pc",
3
- "version": "1.10.40",
3
+ "version": "1.10.41",
4
4
  "nameCN": "",
5
5
  "description": "",
6
6
  "main": "lib/index.js",