@portabletext/editor 1.5.4 → 1.5.6
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/lib/index.esm.js +76 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +76 -18
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +76 -18
- package/lib/index.mjs.map +1 -1
- package/package.json +16 -40
- package/src/editor/behavior/behavior.markdown.ts +129 -27
- package/src/editor/plugins/createWithUndoRedo.ts +22 -0
- package/src/utils/ucs2Indices.ts +0 -67
package/lib/index.js
CHANGED
|
@@ -262,7 +262,7 @@ const breakingBlockObject = {
|
|
|
262
262
|
lists: coreListBehaviors
|
|
263
263
|
};
|
|
264
264
|
function createMarkdownBehaviors(config) {
|
|
265
|
-
const
|
|
265
|
+
const automaticBlockquoteOnSpace = {
|
|
266
266
|
on: "insert text",
|
|
267
267
|
guard: ({
|
|
268
268
|
context,
|
|
@@ -273,12 +273,8 @@ function createMarkdownBehaviors(config) {
|
|
|
273
273
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
274
274
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
275
275
|
return !1;
|
|
276
|
-
const
|
|
277
|
-
return
|
|
278
|
-
focusTextBlock,
|
|
279
|
-
focusSpan,
|
|
280
|
-
style: headingStyle
|
|
281
|
-
} : looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
276
|
+
const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
|
|
277
|
+
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
282
278
|
focusTextBlock,
|
|
283
279
|
focusSpan,
|
|
284
280
|
style: blockquoteStyle
|
|
@@ -308,7 +304,58 @@ function createMarkdownBehaviors(config) {
|
|
|
308
304
|
},
|
|
309
305
|
focus: {
|
|
310
306
|
path: focusSpan.path,
|
|
311
|
-
offset:
|
|
307
|
+
offset: 2
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}]]
|
|
311
|
+
}, automaticHeadingOnSpace = {
|
|
312
|
+
on: "insert text",
|
|
313
|
+
guard: ({
|
|
314
|
+
context,
|
|
315
|
+
event
|
|
316
|
+
}) => {
|
|
317
|
+
if (event.text !== " ")
|
|
318
|
+
return !1;
|
|
319
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
320
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
321
|
+
return !1;
|
|
322
|
+
const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
323
|
+
if (context.selection.focus.offset !== headingLevel)
|
|
324
|
+
return !1;
|
|
325
|
+
const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle(context.schema, headingLevel) : void 0;
|
|
326
|
+
return headingLevel !== void 0 && headingStyle !== void 0 ? {
|
|
327
|
+
focusTextBlock,
|
|
328
|
+
focusSpan,
|
|
329
|
+
style: headingStyle,
|
|
330
|
+
level: headingLevel
|
|
331
|
+
} : !1;
|
|
332
|
+
},
|
|
333
|
+
actions: [() => [{
|
|
334
|
+
type: "insert text",
|
|
335
|
+
text: " "
|
|
336
|
+
}], (_, {
|
|
337
|
+
focusTextBlock,
|
|
338
|
+
focusSpan,
|
|
339
|
+
style,
|
|
340
|
+
level
|
|
341
|
+
}) => [{
|
|
342
|
+
type: "unset block",
|
|
343
|
+
props: ["listItem", "level"],
|
|
344
|
+
paths: [focusTextBlock.path]
|
|
345
|
+
}, {
|
|
346
|
+
type: "set block",
|
|
347
|
+
style,
|
|
348
|
+
paths: [focusTextBlock.path]
|
|
349
|
+
}, {
|
|
350
|
+
type: "delete",
|
|
351
|
+
selection: {
|
|
352
|
+
anchor: {
|
|
353
|
+
path: focusSpan.path,
|
|
354
|
+
offset: 0
|
|
355
|
+
},
|
|
356
|
+
focus: {
|
|
357
|
+
path: focusSpan.path,
|
|
358
|
+
offset: level + 1
|
|
312
359
|
}
|
|
313
360
|
}
|
|
314
361
|
}]]
|
|
@@ -320,8 +367,8 @@ function createMarkdownBehaviors(config) {
|
|
|
320
367
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
321
368
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
322
369
|
return !1;
|
|
323
|
-
const defaultStyle = config.mapDefaultStyle(context.schema);
|
|
324
|
-
return
|
|
370
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle(context.schema);
|
|
371
|
+
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
325
372
|
defaultStyle,
|
|
326
373
|
focusTextBlock
|
|
327
374
|
} : !1;
|
|
@@ -345,18 +392,20 @@ function createMarkdownBehaviors(config) {
|
|
|
345
392
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
346
393
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
347
394
|
return !1;
|
|
348
|
-
const looksLikeUnorderedList =
|
|
349
|
-
if (looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
395
|
+
const looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema);
|
|
396
|
+
if (context.selection.focus.offset === 1 && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
350
397
|
return {
|
|
351
398
|
focusTextBlock,
|
|
352
399
|
focusSpan,
|
|
353
|
-
listItem: unorderedListStyle
|
|
400
|
+
listItem: unorderedListStyle,
|
|
401
|
+
listItemLength: 1
|
|
354
402
|
};
|
|
355
403
|
const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema);
|
|
356
|
-
return looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
404
|
+
return context.selection.focus.offset === 2 && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
357
405
|
focusTextBlock,
|
|
358
406
|
focusSpan,
|
|
359
|
-
listItem: orderedListStyle
|
|
407
|
+
listItem: orderedListStyle,
|
|
408
|
+
listItemLength: 2
|
|
360
409
|
} : !1;
|
|
361
410
|
},
|
|
362
411
|
actions: [() => [{
|
|
@@ -365,7 +414,8 @@ function createMarkdownBehaviors(config) {
|
|
|
365
414
|
}], (_, {
|
|
366
415
|
focusTextBlock,
|
|
367
416
|
focusSpan,
|
|
368
|
-
listItem
|
|
417
|
+
listItem,
|
|
418
|
+
listItemLength
|
|
369
419
|
}) => [{
|
|
370
420
|
type: "unset block",
|
|
371
421
|
props: ["style"],
|
|
@@ -384,12 +434,12 @@ function createMarkdownBehaviors(config) {
|
|
|
384
434
|
},
|
|
385
435
|
focus: {
|
|
386
436
|
path: focusSpan.path,
|
|
387
|
-
offset:
|
|
437
|
+
offset: listItemLength + 1
|
|
388
438
|
}
|
|
389
439
|
}
|
|
390
440
|
}]]
|
|
391
441
|
};
|
|
392
|
-
return [
|
|
442
|
+
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
393
443
|
}
|
|
394
444
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
395
445
|
if (!portableTextType)
|
|
@@ -2993,6 +3043,14 @@ function createWithUndoRedo(options) {
|
|
|
2993
3043
|
apply2(op);
|
|
2994
3044
|
return;
|
|
2995
3045
|
}
|
|
3046
|
+
if (isChangingRemotely(editor)) {
|
|
3047
|
+
apply2(op);
|
|
3048
|
+
return;
|
|
3049
|
+
}
|
|
3050
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
3051
|
+
apply2(op);
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
2996
3054
|
const {
|
|
2997
3055
|
operations,
|
|
2998
3056
|
history
|