@portabletext/editor 1.5.4 → 1.5.5
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 +12 -36
- 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.esm.js
CHANGED
|
@@ -283,7 +283,7 @@ const breakingBlockObject = {
|
|
|
283
283
|
lists: coreListBehaviors
|
|
284
284
|
};
|
|
285
285
|
function createMarkdownBehaviors(config) {
|
|
286
|
-
const
|
|
286
|
+
const automaticBlockquoteOnSpace = {
|
|
287
287
|
on: "insert text",
|
|
288
288
|
guard: ({
|
|
289
289
|
context,
|
|
@@ -294,12 +294,8 @@ function createMarkdownBehaviors(config) {
|
|
|
294
294
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
295
295
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
296
296
|
return !1;
|
|
297
|
-
const
|
|
298
|
-
return
|
|
299
|
-
focusTextBlock,
|
|
300
|
-
focusSpan,
|
|
301
|
-
style: headingStyle
|
|
302
|
-
} : looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
297
|
+
const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
|
|
298
|
+
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
303
299
|
focusTextBlock,
|
|
304
300
|
focusSpan,
|
|
305
301
|
style: blockquoteStyle
|
|
@@ -329,7 +325,58 @@ function createMarkdownBehaviors(config) {
|
|
|
329
325
|
},
|
|
330
326
|
focus: {
|
|
331
327
|
path: focusSpan.path,
|
|
332
|
-
offset:
|
|
328
|
+
offset: 2
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}]]
|
|
332
|
+
}, automaticHeadingOnSpace = {
|
|
333
|
+
on: "insert text",
|
|
334
|
+
guard: ({
|
|
335
|
+
context,
|
|
336
|
+
event
|
|
337
|
+
}) => {
|
|
338
|
+
if (event.text !== " ")
|
|
339
|
+
return !1;
|
|
340
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
341
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
342
|
+
return !1;
|
|
343
|
+
const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
344
|
+
if (context.selection.focus.offset !== headingLevel)
|
|
345
|
+
return !1;
|
|
346
|
+
const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle(context.schema, headingLevel) : void 0;
|
|
347
|
+
return headingLevel !== void 0 && headingStyle !== void 0 ? {
|
|
348
|
+
focusTextBlock,
|
|
349
|
+
focusSpan,
|
|
350
|
+
style: headingStyle,
|
|
351
|
+
level: headingLevel
|
|
352
|
+
} : !1;
|
|
353
|
+
},
|
|
354
|
+
actions: [() => [{
|
|
355
|
+
type: "insert text",
|
|
356
|
+
text: " "
|
|
357
|
+
}], (_, {
|
|
358
|
+
focusTextBlock,
|
|
359
|
+
focusSpan,
|
|
360
|
+
style,
|
|
361
|
+
level
|
|
362
|
+
}) => [{
|
|
363
|
+
type: "unset block",
|
|
364
|
+
props: ["listItem", "level"],
|
|
365
|
+
paths: [focusTextBlock.path]
|
|
366
|
+
}, {
|
|
367
|
+
type: "set block",
|
|
368
|
+
style,
|
|
369
|
+
paths: [focusTextBlock.path]
|
|
370
|
+
}, {
|
|
371
|
+
type: "delete",
|
|
372
|
+
selection: {
|
|
373
|
+
anchor: {
|
|
374
|
+
path: focusSpan.path,
|
|
375
|
+
offset: 0
|
|
376
|
+
},
|
|
377
|
+
focus: {
|
|
378
|
+
path: focusSpan.path,
|
|
379
|
+
offset: level + 1
|
|
333
380
|
}
|
|
334
381
|
}
|
|
335
382
|
}]]
|
|
@@ -341,8 +388,8 @@ function createMarkdownBehaviors(config) {
|
|
|
341
388
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
342
389
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
343
390
|
return !1;
|
|
344
|
-
const defaultStyle = config.mapDefaultStyle(context.schema);
|
|
345
|
-
return
|
|
391
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle(context.schema);
|
|
392
|
+
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
346
393
|
defaultStyle,
|
|
347
394
|
focusTextBlock
|
|
348
395
|
} : !1;
|
|
@@ -366,18 +413,20 @@ function createMarkdownBehaviors(config) {
|
|
|
366
413
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
367
414
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
368
415
|
return !1;
|
|
369
|
-
const looksLikeUnorderedList =
|
|
370
|
-
if (looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
416
|
+
const looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema);
|
|
417
|
+
if (context.selection.focus.offset === 1 && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
371
418
|
return {
|
|
372
419
|
focusTextBlock,
|
|
373
420
|
focusSpan,
|
|
374
|
-
listItem: unorderedListStyle
|
|
421
|
+
listItem: unorderedListStyle,
|
|
422
|
+
listItemLength: 1
|
|
375
423
|
};
|
|
376
424
|
const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema);
|
|
377
|
-
return looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
425
|
+
return context.selection.focus.offset === 2 && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
378
426
|
focusTextBlock,
|
|
379
427
|
focusSpan,
|
|
380
|
-
listItem: orderedListStyle
|
|
428
|
+
listItem: orderedListStyle,
|
|
429
|
+
listItemLength: 2
|
|
381
430
|
} : !1;
|
|
382
431
|
},
|
|
383
432
|
actions: [() => [{
|
|
@@ -386,7 +435,8 @@ function createMarkdownBehaviors(config) {
|
|
|
386
435
|
}], (_, {
|
|
387
436
|
focusTextBlock,
|
|
388
437
|
focusSpan,
|
|
389
|
-
listItem
|
|
438
|
+
listItem,
|
|
439
|
+
listItemLength
|
|
390
440
|
}) => [{
|
|
391
441
|
type: "unset block",
|
|
392
442
|
props: ["style"],
|
|
@@ -405,12 +455,12 @@ function createMarkdownBehaviors(config) {
|
|
|
405
455
|
},
|
|
406
456
|
focus: {
|
|
407
457
|
path: focusSpan.path,
|
|
408
|
-
offset:
|
|
458
|
+
offset: listItemLength + 1
|
|
409
459
|
}
|
|
410
460
|
}
|
|
411
461
|
}]]
|
|
412
462
|
};
|
|
413
|
-
return [
|
|
463
|
+
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
414
464
|
}
|
|
415
465
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
416
466
|
if (!portableTextType)
|
|
@@ -3014,6 +3064,14 @@ function createWithUndoRedo(options) {
|
|
|
3014
3064
|
apply2(op);
|
|
3015
3065
|
return;
|
|
3016
3066
|
}
|
|
3067
|
+
if (isChangingRemotely(editor)) {
|
|
3068
|
+
apply2(op);
|
|
3069
|
+
return;
|
|
3070
|
+
}
|
|
3071
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
3072
|
+
apply2(op);
|
|
3073
|
+
return;
|
|
3074
|
+
}
|
|
3017
3075
|
const {
|
|
3018
3076
|
operations,
|
|
3019
3077
|
history
|