@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.d.mts CHANGED
@@ -5825,7 +5825,7 @@ export declare const keyGenerator: () => string
5825
5825
  * @alpha
5826
5826
  */
5827
5827
  export declare type LinkBehaviorsConfig = {
5828
- mapLinkAnnotation?: (config: {
5828
+ linkAnnotation?: (context: {
5829
5829
  schema: PortableTextMemberSchemaTypes
5830
5830
  url: string
5831
5831
  }) =>
@@ -5851,7 +5851,7 @@ export declare type LoadingChange = {
5851
5851
  * @alpha
5852
5852
  */
5853
5853
  export declare type MarkdownBehaviorsConfig = {
5854
- mapBreakObject?: (schema: PortableTextMemberSchemaTypes) =>
5854
+ horizontalRuleObject?: (context: {schema: PortableTextMemberSchemaTypes}) =>
5855
5855
  | {
5856
5856
  name: string
5857
5857
  value?: {
@@ -5859,22 +5859,22 @@ export declare type MarkdownBehaviorsConfig = {
5859
5859
  }
5860
5860
  }
5861
5861
  | undefined
5862
- mapDefaultStyle?: (
5863
- schema: PortableTextMemberSchemaTypes,
5864
- ) => string | undefined
5865
- mapHeadingStyle?: (
5866
- schema: PortableTextMemberSchemaTypes,
5867
- level: number,
5868
- ) => string | undefined
5869
- mapBlockquoteStyle?: (
5870
- schema: PortableTextMemberSchemaTypes,
5871
- ) => string | undefined
5872
- mapUnorderedListStyle?: (
5873
- schema: PortableTextMemberSchemaTypes,
5874
- ) => string | undefined
5875
- mapOrderedListStyle?: (
5876
- schema: PortableTextMemberSchemaTypes,
5877
- ) => string | undefined
5862
+ defaultStyle?: (context: {
5863
+ schema: PortableTextMemberSchemaTypes
5864
+ }) => string | undefined
5865
+ headingStyle?: (context: {
5866
+ schema: PortableTextMemberSchemaTypes
5867
+ level: number
5868
+ }) => string | undefined
5869
+ blockquoteStyle?: (context: {
5870
+ schema: PortableTextMemberSchemaTypes
5871
+ }) => string | undefined
5872
+ unorderedListStyle?: (context: {
5873
+ schema: PortableTextMemberSchemaTypes
5874
+ }) => string | undefined
5875
+ orderedListStyle?: (context: {
5876
+ schema: PortableTextMemberSchemaTypes
5877
+ }) => string | undefined
5878
5878
  }
5879
5879
 
5880
5880
  /**
package/lib/index.d.ts CHANGED
@@ -5825,7 +5825,7 @@ export declare const keyGenerator: () => string
5825
5825
  * @alpha
5826
5826
  */
5827
5827
  export declare type LinkBehaviorsConfig = {
5828
- mapLinkAnnotation?: (config: {
5828
+ linkAnnotation?: (context: {
5829
5829
  schema: PortableTextMemberSchemaTypes
5830
5830
  url: string
5831
5831
  }) =>
@@ -5851,7 +5851,7 @@ export declare type LoadingChange = {
5851
5851
  * @alpha
5852
5852
  */
5853
5853
  export declare type MarkdownBehaviorsConfig = {
5854
- mapBreakObject?: (schema: PortableTextMemberSchemaTypes) =>
5854
+ horizontalRuleObject?: (context: {schema: PortableTextMemberSchemaTypes}) =>
5855
5855
  | {
5856
5856
  name: string
5857
5857
  value?: {
@@ -5859,22 +5859,22 @@ export declare type MarkdownBehaviorsConfig = {
5859
5859
  }
5860
5860
  }
5861
5861
  | undefined
5862
- mapDefaultStyle?: (
5863
- schema: PortableTextMemberSchemaTypes,
5864
- ) => string | undefined
5865
- mapHeadingStyle?: (
5866
- schema: PortableTextMemberSchemaTypes,
5867
- level: number,
5868
- ) => string | undefined
5869
- mapBlockquoteStyle?: (
5870
- schema: PortableTextMemberSchemaTypes,
5871
- ) => string | undefined
5872
- mapUnorderedListStyle?: (
5873
- schema: PortableTextMemberSchemaTypes,
5874
- ) => string | undefined
5875
- mapOrderedListStyle?: (
5876
- schema: PortableTextMemberSchemaTypes,
5877
- ) => string | undefined
5862
+ defaultStyle?: (context: {
5863
+ schema: PortableTextMemberSchemaTypes
5864
+ }) => string | undefined
5865
+ headingStyle?: (context: {
5866
+ schema: PortableTextMemberSchemaTypes
5867
+ level: number
5868
+ }) => string | undefined
5869
+ blockquoteStyle?: (context: {
5870
+ schema: PortableTextMemberSchemaTypes
5871
+ }) => string | undefined
5872
+ unorderedListStyle?: (context: {
5873
+ schema: PortableTextMemberSchemaTypes
5874
+ }) => string | undefined
5875
+ orderedListStyle?: (context: {
5876
+ schema: PortableTextMemberSchemaTypes
5877
+ }) => string | undefined
5878
5878
  }
5879
5879
 
5880
5880
  /**
package/lib/index.esm.js CHANGED
@@ -344,7 +344,9 @@ function createMarkdownBehaviors(config) {
344
344
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
345
345
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
346
346
  return !1;
347
- const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle?.(context.schema);
347
+ const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.blockquoteStyle?.({
348
+ schema: context.schema
349
+ });
348
350
  return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
349
351
  focusTextBlock,
350
352
  focusSpan,
@@ -385,20 +387,26 @@ function createMarkdownBehaviors(config) {
385
387
  context,
386
388
  event
387
389
  }) => {
388
- if (event.text !== "-")
390
+ const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
391
+ if (hrCharacter === void 0)
389
392
  return !1;
390
- const breakObject = config.mapBreakObject?.(context.schema), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
393
+ const breakObject = config.horizontalRuleObject?.({
394
+ schema: context.schema
395
+ }), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
391
396
  if (!breakObject || !focusBlock || !selectionCollapsed)
392
397
  return !1;
393
398
  const onlyText = focusBlock.node.children.every(isPortableTextSpan), blockText = focusBlock.node.children.map((child) => child.text ?? "").join("");
394
- return onlyText && blockText === "--" ? {
399
+ return onlyText && blockText === `${hrCharacter}${hrCharacter}` ? {
395
400
  breakObject,
396
- focusBlock
401
+ focusBlock,
402
+ hrCharacter
397
403
  } : !1;
398
404
  },
399
- actions: [() => [{
405
+ actions: [(_, {
406
+ hrCharacter
407
+ }) => [{
400
408
  type: "insert text",
401
- text: "-"
409
+ text: hrCharacter
402
410
  }], (_, {
403
411
  breakObject,
404
412
  focusBlock
@@ -432,15 +440,18 @@ function createMarkdownBehaviors(config) {
432
440
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
433
441
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
434
442
  return !1;
435
- const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
436
- if (context.selection.focus.offset !== headingLevel)
443
+ const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
444
+ if (context.selection.focus.offset !== level)
437
445
  return !1;
438
- const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle?.(context.schema, headingLevel) : void 0;
439
- return headingLevel !== void 0 && headingStyle !== void 0 ? {
446
+ const style = level !== void 0 ? config.headingStyle?.({
447
+ schema: context.schema,
448
+ level
449
+ }) : void 0;
450
+ return level !== void 0 && style !== void 0 ? {
440
451
  focusTextBlock,
441
452
  focusSpan,
442
- style: headingStyle,
443
- level: headingLevel
453
+ style,
454
+ level
444
455
  } : !1;
445
456
  },
446
457
  actions: [() => [{
@@ -480,7 +491,9 @@ function createMarkdownBehaviors(config) {
480
491
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
481
492
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
482
493
  return !1;
483
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle?.(context.schema);
494
+ const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.defaultStyle?.({
495
+ schema: context.schema
496
+ });
484
497
  return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
485
498
  defaultStyle,
486
499
  focusTextBlock
@@ -505,7 +518,11 @@ function createMarkdownBehaviors(config) {
505
518
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
506
519
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
507
520
  return !1;
508
- const defaultStyle = config.mapDefaultStyle?.(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle?.(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
521
+ const defaultStyle = config.defaultStyle?.({
522
+ schema: context.schema
523
+ }), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.unorderedListStyle?.({
524
+ schema: context.schema
525
+ }), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
509
526
  if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
510
527
  return {
511
528
  focusTextBlock,
@@ -514,7 +531,9 @@ function createMarkdownBehaviors(config) {
514
531
  listItemLength: 1,
515
532
  style: defaultStyle
516
533
  };
517
- const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle?.(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
534
+ const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.orderedListStyle?.({
535
+ schema: context.schema
536
+ }), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
518
537
  return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
519
538
  focusTextBlock,
520
539
  focusSpan,
@@ -561,7 +580,7 @@ function createLinkBehaviors(config) {
561
580
  context,
562
581
  event
563
582
  }) => {
564
- const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
583
+ const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
565
584
  url,
566
585
  schema: context.schema
567
586
  }) : void 0;
@@ -584,7 +603,7 @@ function createLinkBehaviors(config) {
584
603
  const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
585
604
  if (!focusSpan || !selectionCollapsed)
586
605
  return !1;
587
- const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
606
+ const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
588
607
  url,
589
608
  schema: context.schema
590
609
  }) : void 0;