@portabletext/editor 1.9.0 → 1.10.0

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.js CHANGED
@@ -323,7 +323,9 @@ function createMarkdownBehaviors(config) {
323
323
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
324
324
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
325
325
  return !1;
326
- const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle?.(context.schema);
326
+ const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.blockquoteStyle?.({
327
+ schema: context.schema
328
+ });
327
329
  return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
328
330
  focusTextBlock,
329
331
  focusSpan,
@@ -364,20 +366,26 @@ function createMarkdownBehaviors(config) {
364
366
  context,
365
367
  event
366
368
  }) => {
367
- if (event.text !== "-")
369
+ const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
370
+ if (hrCharacter === void 0)
368
371
  return !1;
369
- const breakObject = config.mapBreakObject?.(context.schema), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
372
+ const breakObject = config.horizontalRuleObject?.({
373
+ schema: context.schema
374
+ }), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
370
375
  if (!breakObject || !focusBlock || !selectionCollapsed)
371
376
  return !1;
372
377
  const onlyText = focusBlock.node.children.every(isPortableTextSpan), blockText = focusBlock.node.children.map((child) => child.text ?? "").join("");
373
- return onlyText && blockText === "--" ? {
378
+ return onlyText && blockText === `${hrCharacter}${hrCharacter}` ? {
374
379
  breakObject,
375
- focusBlock
380
+ focusBlock,
381
+ hrCharacter
376
382
  } : !1;
377
383
  },
378
- actions: [() => [{
384
+ actions: [(_, {
385
+ hrCharacter
386
+ }) => [{
379
387
  type: "insert text",
380
- text: "-"
388
+ text: hrCharacter
381
389
  }], (_, {
382
390
  breakObject,
383
391
  focusBlock
@@ -411,15 +419,18 @@ function createMarkdownBehaviors(config) {
411
419
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
412
420
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
413
421
  return !1;
414
- const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
415
- if (context.selection.focus.offset !== headingLevel)
422
+ const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
423
+ if (context.selection.focus.offset !== level)
416
424
  return !1;
417
- const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle?.(context.schema, headingLevel) : void 0;
418
- return headingLevel !== void 0 && headingStyle !== void 0 ? {
425
+ const style = level !== void 0 ? config.headingStyle?.({
426
+ schema: context.schema,
427
+ level
428
+ }) : void 0;
429
+ return level !== void 0 && style !== void 0 ? {
419
430
  focusTextBlock,
420
431
  focusSpan,
421
- style: headingStyle,
422
- level: headingLevel
432
+ style,
433
+ level
423
434
  } : !1;
424
435
  },
425
436
  actions: [() => [{
@@ -459,7 +470,9 @@ function createMarkdownBehaviors(config) {
459
470
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
460
471
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
461
472
  return !1;
462
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle?.(context.schema);
473
+ const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.defaultStyle?.({
474
+ schema: context.schema
475
+ });
463
476
  return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
464
477
  defaultStyle,
465
478
  focusTextBlock
@@ -484,7 +497,11 @@ function createMarkdownBehaviors(config) {
484
497
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
485
498
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
486
499
  return !1;
487
- const defaultStyle = config.mapDefaultStyle?.(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle?.(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
500
+ const defaultStyle = config.defaultStyle?.({
501
+ schema: context.schema
502
+ }), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.unorderedListStyle?.({
503
+ schema: context.schema
504
+ }), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
488
505
  if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
489
506
  return {
490
507
  focusTextBlock,
@@ -493,7 +510,9 @@ function createMarkdownBehaviors(config) {
493
510
  listItemLength: 1,
494
511
  style: defaultStyle
495
512
  };
496
- const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle?.(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
513
+ const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.orderedListStyle?.({
514
+ schema: context.schema
515
+ }), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
497
516
  return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
498
517
  focusTextBlock,
499
518
  focusSpan,
@@ -540,7 +559,7 @@ function createLinkBehaviors(config) {
540
559
  context,
541
560
  event
542
561
  }) => {
543
- const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
562
+ const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
544
563
  url,
545
564
  schema: context.schema
546
565
  }) : void 0;
@@ -563,7 +582,7 @@ function createLinkBehaviors(config) {
563
582
  const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
564
583
  if (!focusSpan || !selectionCollapsed)
565
584
  return !1;
566
- const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
585
+ const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
567
586
  url,
568
587
  schema: context.schema
569
588
  }) : void 0;