@portabletext/editor 1.55.4 → 1.55.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.
Files changed (54) hide show
  1. package/lib/_chunks-cjs/util.slice-text-block.cjs +67 -0
  2. package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -0
  3. package/lib/_chunks-es/util.slice-text-block.js +69 -0
  4. package/lib/_chunks-es/util.slice-text-block.js.map +1 -0
  5. package/lib/behaviors/index.d.cts +72 -52
  6. package/lib/behaviors/index.d.ts +72 -52
  7. package/lib/index.cjs +15 -15
  8. package/lib/index.cjs.map +1 -1
  9. package/lib/index.d.cts +117 -69
  10. package/lib/index.d.ts +117 -69
  11. package/lib/index.js +8 -8
  12. package/lib/index.js.map +1 -1
  13. package/lib/plugins/index.d.cts +71 -51
  14. package/lib/plugins/index.d.ts +71 -51
  15. package/lib/selectors/index.d.cts +68 -51
  16. package/lib/selectors/index.d.ts +68 -51
  17. package/lib/utils/index.cjs +12 -13
  18. package/lib/utils/index.cjs.map +1 -1
  19. package/lib/utils/index.d.cts +68 -51
  20. package/lib/utils/index.d.ts +68 -51
  21. package/lib/utils/index.js +14 -15
  22. package/lib/utils/index.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/behaviors/behavior.abstract.split.ts +8 -9
  25. package/src/behaviors/behavior.types.event.ts +3 -0
  26. package/src/behaviors/index.ts +2 -1
  27. package/src/converters/converter.portable-text.deserialize.test.ts +3 -5
  28. package/src/converters/converter.text-html.deserialize.test.ts +2 -2
  29. package/src/converters/converter.text-html.serialize.test.ts +2 -2
  30. package/src/converters/converter.text-plain.test.ts +3 -5
  31. package/src/editor/editor-schema-definition.ts +106 -0
  32. package/src/editor/editor-schema.ts +65 -107
  33. package/src/editor.ts +1 -1
  34. package/src/index.ts +16 -2
  35. package/src/internal-utils/apply-operation-to-portable-text.test.ts +2 -1
  36. package/src/internal-utils/build-index-maps.test.ts +2 -1
  37. package/src/internal-utils/create-test-snapshot.ts +2 -1
  38. package/src/internal-utils/drag-selection.test.ts +2 -1
  39. package/src/internal-utils/parse-blocks.test.ts +2 -1
  40. package/src/internal-utils/selection-text.ts +2 -1
  41. package/src/internal-utils/terse-pt.test.ts +2 -1
  42. package/src/internal-utils/test-editor.tsx +4 -1
  43. package/src/plugins/plugin.markdown.test.tsx +1 -1
  44. package/src/selectors/selector.get-selection-text.test.ts +2 -1
  45. package/src/selectors/selector.get-trimmed-selection.test.ts +2 -1
  46. package/src/utils/util.block-offset.test.ts +2 -1
  47. package/src/utils/util.slice-blocks.test.ts +2 -1
  48. package/src/utils/util.slice-text-block.test.ts +163 -0
  49. package/src/utils/util.slice-text-block.ts +89 -0
  50. package/src/utils/util.split-text-block.ts +7 -16
  51. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -23
  52. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +0 -1
  53. package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -25
  54. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +0 -1
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var selectionPoint = require("./selection-point.cjs"), util_childSelectionPointToBlockOffset = require("./util.child-selection-point-to-block-offset.cjs");
3
+ function isSelectionCollapsed(selection) {
4
+ return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
5
+ }
6
+ function selectionPointToBlockOffset({
7
+ context,
8
+ selectionPoint: selectionPoint$1
9
+ }) {
10
+ const blockKey = selectionPoint.getBlockKeyFromSelectionPoint(selectionPoint$1);
11
+ return selectionPoint$1.path.length === 1 && blockKey !== void 0 ? {
12
+ path: [{
13
+ _key: blockKey
14
+ }],
15
+ offset: selectionPoint$1.offset
16
+ } : util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset({
17
+ context,
18
+ selectionPoint: selectionPoint$1
19
+ });
20
+ }
21
+ function sliceTextBlock({
22
+ context,
23
+ block
24
+ }) {
25
+ const startPoint = selectionPoint.getSelectionStartPoint(context.selection), endPoint = selectionPoint.getSelectionEndPoint(context.selection);
26
+ if (!startPoint || !endPoint)
27
+ return block;
28
+ const startBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint);
29
+ if (startBlockKey !== endBlockKey || startBlockKey !== block._key)
30
+ return block;
31
+ const startChildKey = selectionPoint.getChildKeyFromSelectionPoint(startPoint), endChildKey = selectionPoint.getChildKeyFromSelectionPoint(endPoint);
32
+ if (!startChildKey || !endChildKey)
33
+ return block;
34
+ let startChildFound = !1;
35
+ const children = [];
36
+ for (const child of block.children) {
37
+ if (child._key === startChildKey) {
38
+ if (startChildFound = !0, selectionPoint.isSpan$1(context, child)) {
39
+ const text = child._key === endChildKey ? child.text.slice(startPoint.offset, endPoint.offset) : child.text.slice(startPoint.offset);
40
+ children.push({
41
+ ...child,
42
+ text
43
+ });
44
+ } else
45
+ children.push(child);
46
+ if (startChildKey === endChildKey)
47
+ break;
48
+ continue;
49
+ }
50
+ if (child._key === endChildKey) {
51
+ selectionPoint.isSpan$1(context, child) ? children.push({
52
+ ...child,
53
+ text: child.text.slice(0, endPoint.offset)
54
+ }) : children.push(child);
55
+ break;
56
+ }
57
+ startChildFound && children.push(child);
58
+ }
59
+ return {
60
+ ...block,
61
+ children
62
+ };
63
+ }
64
+ exports.isSelectionCollapsed = isSelectionCollapsed;
65
+ exports.selectionPointToBlockOffset = selectionPointToBlockOffset;
66
+ exports.sliceTextBlock = sliceTextBlock;
67
+ //# sourceMappingURL=util.slice-text-block.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.slice-text-block.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.slice-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n","import type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isSpan} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\n\nexport function sliceTextBlock({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n block: PortableTextTextBlock\n}): PortableTextTextBlock {\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n\n if (!startPoint || !endPoint) {\n return block\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {\n return block\n }\n\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startChildKey || !endChildKey) {\n return block\n }\n\n let startChildFound = false\n const children: Array<PortableTextChild> = []\n\n for (const child of block.children) {\n if (child._key === startChildKey) {\n startChildFound = true\n\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n children.push({\n ...child,\n text,\n })\n } else {\n children.push(child)\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n\n continue\n }\n\n if (child._key === endChildKey) {\n if (isSpan(context, child)) {\n children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n children.push(child)\n }\n\n break\n }\n\n if (startChildFound) {\n children.push(child)\n }\n }\n\n return {\n ...block,\n children,\n }\n}\n"],"names":["isSelectionCollapsed","selection","JSON","stringify","anchor","path","focus","offset","selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","length","undefined","_key","childSelectionPointToBlockOffset","sliceTextBlock","block","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startChildKey","getChildKeyFromSelectionPoint","endChildKey","startChildFound","children","child","isSpan","text","slice","push"],"mappings":";;AAKO,SAASA,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHC,KAAKC,UAAUF,UAAUG,OAAOC,IAAI,MAClCH,KAAKC,UAAUF,UAAUK,MAAMD,IAAI,KACrCJ,UAAUG,OAAOG,WAAWN,UAAUK,MAAMC,SANrC;AAQX;ACNO,SAASC,4BAA4B;AAAA,EAC1CC;AAAAA,EAAAA,gBACAC;AAIF,GAA4B;AAC1B,QAAMC,WAAWC,eAAAA,8BAA8BF,gBAAc;AAE7D,SAAIA,iBAAeL,KAAKQ,WAAW,KAAKF,aAAaG,SAC5C;AAAA,IACLT,MAAM,CAAC;AAAA,MAACU,MAAMJ;AAAAA,IAAAA,CAAS;AAAA,IACvBJ,QAAQG,iBAAeH;AAAAA,EAAAA,IAIpBS,uEAAiC;AAAA,IACtCP;AAAAA,IAAAA,gBACAC;AAAAA,EAAAA,C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KAAK;AAAA,EAAA;AAIvB,SAAO;AAAA,IACL,GAAGZ;AAAAA,IACHW;AAAAA,EAAAA;AAEJ;;;;"}
@@ -0,0 +1,69 @@
1
+ import { getBlockKeyFromSelectionPoint, getSelectionStartPoint, getSelectionEndPoint, getChildKeyFromSelectionPoint, isSpan$1 as isSpan } from "./selection-point.js";
2
+ import { childSelectionPointToBlockOffset } from "./util.child-selection-point-to-block-offset.js";
3
+ function isSelectionCollapsed(selection) {
4
+ return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
5
+ }
6
+ function selectionPointToBlockOffset({
7
+ context,
8
+ selectionPoint
9
+ }) {
10
+ const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
11
+ return selectionPoint.path.length === 1 && blockKey !== void 0 ? {
12
+ path: [{
13
+ _key: blockKey
14
+ }],
15
+ offset: selectionPoint.offset
16
+ } : childSelectionPointToBlockOffset({
17
+ context,
18
+ selectionPoint
19
+ });
20
+ }
21
+ function sliceTextBlock({
22
+ context,
23
+ block
24
+ }) {
25
+ const startPoint = getSelectionStartPoint(context.selection), endPoint = getSelectionEndPoint(context.selection);
26
+ if (!startPoint || !endPoint)
27
+ return block;
28
+ const startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
29
+ if (startBlockKey !== endBlockKey || startBlockKey !== block._key)
30
+ return block;
31
+ const startChildKey = getChildKeyFromSelectionPoint(startPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
32
+ if (!startChildKey || !endChildKey)
33
+ return block;
34
+ let startChildFound = !1;
35
+ const children = [];
36
+ for (const child of block.children) {
37
+ if (child._key === startChildKey) {
38
+ if (startChildFound = !0, isSpan(context, child)) {
39
+ const text = child._key === endChildKey ? child.text.slice(startPoint.offset, endPoint.offset) : child.text.slice(startPoint.offset);
40
+ children.push({
41
+ ...child,
42
+ text
43
+ });
44
+ } else
45
+ children.push(child);
46
+ if (startChildKey === endChildKey)
47
+ break;
48
+ continue;
49
+ }
50
+ if (child._key === endChildKey) {
51
+ isSpan(context, child) ? children.push({
52
+ ...child,
53
+ text: child.text.slice(0, endPoint.offset)
54
+ }) : children.push(child);
55
+ break;
56
+ }
57
+ startChildFound && children.push(child);
58
+ }
59
+ return {
60
+ ...block,
61
+ children
62
+ };
63
+ }
64
+ export {
65
+ isSelectionCollapsed,
66
+ selectionPointToBlockOffset,
67
+ sliceTextBlock
68
+ };
69
+ //# sourceMappingURL=util.slice-text-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.slice-text-block.js","sources":["../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.ts","../../src/utils/util.slice-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n","import type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isSpan} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\n\nexport function sliceTextBlock({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n block: PortableTextTextBlock\n}): PortableTextTextBlock {\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n\n if (!startPoint || !endPoint) {\n return block\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (startBlockKey !== endBlockKey || startBlockKey !== block._key) {\n return block\n }\n\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startChildKey || !endChildKey) {\n return block\n }\n\n let startChildFound = false\n const children: Array<PortableTextChild> = []\n\n for (const child of block.children) {\n if (child._key === startChildKey) {\n startChildFound = true\n\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n children.push({\n ...child,\n text,\n })\n } else {\n children.push(child)\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n\n continue\n }\n\n if (child._key === endChildKey) {\n if (isSpan(context, child)) {\n children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n children.push(child)\n }\n\n break\n }\n\n if (startChildFound) {\n children.push(child)\n }\n }\n\n return {\n ...block,\n children,\n }\n}\n"],"names":["isSelectionCollapsed","selection","JSON","stringify","anchor","path","focus","offset","selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","length","undefined","_key","childSelectionPointToBlockOffset","sliceTextBlock","block","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startChildKey","getChildKeyFromSelectionPoint","endChildKey","startChildFound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,SAASd,MAAM,IACnDuB,MAAME,KAAKC,MAAMd,WAAWZ,MAAM;AAExCsB,iBAASK,KAAK;AAAA,UACZ,GAAGJ;AAAAA,UACHE;AAAAA,QAAAA,CACD;AAAA,MAAA;AAEDH,iBAASK,KAAKJ,KAAK;AAGrB,UAAIL,kBAAkBE;AACpB;AAGF;AAAA,IAAA;AAGF,QAAIG,MAAMf,SAASY,aAAa;AAC1BI,aAAOtB,SAASqB,KAAK,IACvBD,SAASK,KAAK;AAAA,QACZ,GAAGJ;AAAAA,QACHE,MAAMF,MAAME,KAAKC,MAAM,GAAGZ,SAASd,MAAM;AAAA,MAAA,CAC1C,IAEDsB,SAASK,KAAKJ,KAAK;AAGrB;AAAA,IAAA;AAGEF,uBACFC,SAASK,KAAKJ,KAAK;AAAA,EAAA;AAIvB,SAAO;AAAA,IACL,GAAGZ;AAAAA,IACHW;AAAAA,EAAAA;AAEJ;"}
@@ -216,6 +216,13 @@ declare type AnnotationPath = [
216
216
  },
217
217
  ]
218
218
 
219
+ /**
220
+ * @public
221
+ */
222
+ declare type AnnotationSchemaType = BaseDefinition & {
223
+ fields: ReadonlyArray<FieldDefinition>
224
+ }
225
+
219
226
  /**
220
227
  * @public
221
228
  */
@@ -311,6 +318,13 @@ export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
311
318
  dom: EditorDom
312
319
  }) => TGuardResponse | false
313
320
 
321
+ /**
322
+ * @public
323
+ */
324
+ declare type BlockObjectSchemaType = BaseDefinition & {
325
+ fields: ReadonlyArray<FieldDefinition>
326
+ }
327
+
314
328
  /**
315
329
  * @beta
316
330
  */
@@ -430,6 +444,17 @@ declare type CustomBehaviorEventType<
430
444
  TType extends string = '',
431
445
  > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
432
446
 
447
+ /**
448
+ * @public
449
+ */
450
+ declare type DecoratorSchemaType = BaseDefinition & {
451
+ /**
452
+ * @deprecated
453
+ * Use `name` instead
454
+ */
455
+ value: string
456
+ }
457
+
433
458
  /**
434
459
  * @beta
435
460
  *
@@ -559,63 +584,18 @@ declare type EditorDom = {
559
584
  * @public
560
585
  */
561
586
  declare type EditorSchema = {
562
- annotations: ReadonlyArray<
563
- BaseDefinition & {
564
- fields: ReadonlyArray<{
565
- name: string
566
- type: string
567
- }>
568
- }
569
- >
587
+ annotations: ReadonlyArray<AnnotationSchemaType>
570
588
  block: {
571
589
  name: string
572
590
  }
573
- blockObjects: ReadonlyArray<
574
- BaseDefinition & {
575
- fields: ReadonlyArray<{
576
- name: string
577
- type: string
578
- }>
579
- }
580
- >
581
- decorators: ReadonlyArray<
582
- BaseDefinition & {
583
- /**
584
- * @deprecated
585
- * Use `name` instead
586
- */
587
- value: string
588
- }
589
- >
590
- inlineObjects: ReadonlyArray<
591
- BaseDefinition & {
592
- fields: ReadonlyArray<{
593
- name: string
594
- type: string
595
- }>
596
- }
597
- >
591
+ blockObjects: ReadonlyArray<BlockObjectSchemaType>
592
+ decorators: ReadonlyArray<DecoratorSchemaType>
593
+ inlineObjects: ReadonlyArray<InlineObjectSchemaType>
598
594
  span: {
599
595
  name: string
600
596
  }
601
- styles: ReadonlyArray<
602
- BaseDefinition & {
603
- /**
604
- * @deprecated
605
- * Use `name` instead
606
- */
607
- value: string
608
- }
609
- >
610
- lists: ReadonlyArray<
611
- BaseDefinition & {
612
- /**
613
- * @deprecated
614
- * Use `name` instead
615
- */
616
- value: string
617
- }
618
- >
597
+ styles: ReadonlyArray<StyleSchemaType>
598
+ lists: ReadonlyArray<ListSchemaType>
619
599
  }
620
600
 
621
601
  /** @public */
@@ -673,6 +653,14 @@ export declare function execute(
673
653
  declare type ExtractNamespace<TType extends string> =
674
654
  TType extends `${infer Namespace}.${string}` ? Namespace : TType
675
655
 
656
+ /**
657
+ * @public
658
+ */
659
+ declare type FieldDefinition = {
660
+ name: string
661
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object'
662
+ }
663
+
676
664
  /**
677
665
  * @beta
678
666
  */
@@ -680,6 +668,13 @@ export declare function forward(
680
668
  event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,
681
669
  ): PickFromUnion<BehaviorAction, 'type', 'forward'>
682
670
 
671
+ /**
672
+ * @public
673
+ */
674
+ declare type InlineObjectSchemaType = BaseDefinition & {
675
+ fields: ReadonlyArray<FieldDefinition>
676
+ }
677
+
683
678
  /**
684
679
  * Used to represent native InputEvents that hold a DataTransfer object.
685
680
  *
@@ -698,7 +693,10 @@ declare type InputBehaviorEvent = {
698
693
  }
699
694
  }
700
695
 
701
- declare type InsertPlacement = 'auto' | 'after' | 'before'
696
+ /**
697
+ * @beta
698
+ */
699
+ export declare type InsertPlacement = 'auto' | 'after' | 'before'
702
700
 
703
701
  declare type KeyboardBehaviorEvent =
704
702
  | {
@@ -716,6 +714,17 @@ declare type KeyboardBehaviorEvent =
716
714
  >
717
715
  }
718
716
 
717
+ /**
718
+ * @public
719
+ */
720
+ declare type ListSchemaType = BaseDefinition & {
721
+ /**
722
+ * @deprecated
723
+ * Use `name` instead
724
+ */
725
+ value: string
726
+ }
727
+
719
728
  declare type MIMEType = `${string}/${string}`
720
729
 
721
730
  declare type MouseBehaviorEvent = {
@@ -823,6 +832,17 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
823
832
 
824
833
  declare type StrictExtract<T, U extends T> = U
825
834
 
835
+ /**
836
+ * @public
837
+ */
838
+ declare type StyleSchemaType = BaseDefinition & {
839
+ /**
840
+ * @deprecated
841
+ * Use `name` instead
842
+ */
843
+ value: string
844
+ }
845
+
826
846
  /**
827
847
  * @beta
828
848
  */
@@ -216,6 +216,13 @@ declare type AnnotationPath = [
216
216
  },
217
217
  ]
218
218
 
219
+ /**
220
+ * @public
221
+ */
222
+ declare type AnnotationSchemaType = BaseDefinition & {
223
+ fields: ReadonlyArray<FieldDefinition>
224
+ }
225
+
219
226
  /**
220
227
  * @public
221
228
  */
@@ -311,6 +318,13 @@ export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
311
318
  dom: EditorDom
312
319
  }) => TGuardResponse | false
313
320
 
321
+ /**
322
+ * @public
323
+ */
324
+ declare type BlockObjectSchemaType = BaseDefinition & {
325
+ fields: ReadonlyArray<FieldDefinition>
326
+ }
327
+
314
328
  /**
315
329
  * @beta
316
330
  */
@@ -430,6 +444,17 @@ declare type CustomBehaviorEventType<
430
444
  TType extends string = '',
431
445
  > = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
432
446
 
447
+ /**
448
+ * @public
449
+ */
450
+ declare type DecoratorSchemaType = BaseDefinition & {
451
+ /**
452
+ * @deprecated
453
+ * Use `name` instead
454
+ */
455
+ value: string
456
+ }
457
+
433
458
  /**
434
459
  * @beta
435
460
  *
@@ -559,63 +584,18 @@ declare type EditorDom = {
559
584
  * @public
560
585
  */
561
586
  declare type EditorSchema = {
562
- annotations: ReadonlyArray<
563
- BaseDefinition & {
564
- fields: ReadonlyArray<{
565
- name: string
566
- type: string
567
- }>
568
- }
569
- >
587
+ annotations: ReadonlyArray<AnnotationSchemaType>
570
588
  block: {
571
589
  name: string
572
590
  }
573
- blockObjects: ReadonlyArray<
574
- BaseDefinition & {
575
- fields: ReadonlyArray<{
576
- name: string
577
- type: string
578
- }>
579
- }
580
- >
581
- decorators: ReadonlyArray<
582
- BaseDefinition & {
583
- /**
584
- * @deprecated
585
- * Use `name` instead
586
- */
587
- value: string
588
- }
589
- >
590
- inlineObjects: ReadonlyArray<
591
- BaseDefinition & {
592
- fields: ReadonlyArray<{
593
- name: string
594
- type: string
595
- }>
596
- }
597
- >
591
+ blockObjects: ReadonlyArray<BlockObjectSchemaType>
592
+ decorators: ReadonlyArray<DecoratorSchemaType>
593
+ inlineObjects: ReadonlyArray<InlineObjectSchemaType>
598
594
  span: {
599
595
  name: string
600
596
  }
601
- styles: ReadonlyArray<
602
- BaseDefinition & {
603
- /**
604
- * @deprecated
605
- * Use `name` instead
606
- */
607
- value: string
608
- }
609
- >
610
- lists: ReadonlyArray<
611
- BaseDefinition & {
612
- /**
613
- * @deprecated
614
- * Use `name` instead
615
- */
616
- value: string
617
- }
618
- >
597
+ styles: ReadonlyArray<StyleSchemaType>
598
+ lists: ReadonlyArray<ListSchemaType>
619
599
  }
620
600
 
621
601
  /** @public */
@@ -673,6 +653,14 @@ export declare function execute(
673
653
  declare type ExtractNamespace<TType extends string> =
674
654
  TType extends `${infer Namespace}.${string}` ? Namespace : TType
675
655
 
656
+ /**
657
+ * @public
658
+ */
659
+ declare type FieldDefinition = {
660
+ name: string
661
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object'
662
+ }
663
+
676
664
  /**
677
665
  * @beta
678
666
  */
@@ -680,6 +668,13 @@ export declare function forward(
680
668
  event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,
681
669
  ): PickFromUnion<BehaviorAction, 'type', 'forward'>
682
670
 
671
+ /**
672
+ * @public
673
+ */
674
+ declare type InlineObjectSchemaType = BaseDefinition & {
675
+ fields: ReadonlyArray<FieldDefinition>
676
+ }
677
+
683
678
  /**
684
679
  * Used to represent native InputEvents that hold a DataTransfer object.
685
680
  *
@@ -698,7 +693,10 @@ declare type InputBehaviorEvent = {
698
693
  }
699
694
  }
700
695
 
701
- declare type InsertPlacement = 'auto' | 'after' | 'before'
696
+ /**
697
+ * @beta
698
+ */
699
+ export declare type InsertPlacement = 'auto' | 'after' | 'before'
702
700
 
703
701
  declare type KeyboardBehaviorEvent =
704
702
  | {
@@ -716,6 +714,17 @@ declare type KeyboardBehaviorEvent =
716
714
  >
717
715
  }
718
716
 
717
+ /**
718
+ * @public
719
+ */
720
+ declare type ListSchemaType = BaseDefinition & {
721
+ /**
722
+ * @deprecated
723
+ * Use `name` instead
724
+ */
725
+ value: string
726
+ }
727
+
719
728
  declare type MIMEType = `${string}/${string}`
720
729
 
721
730
  declare type MouseBehaviorEvent = {
@@ -823,6 +832,17 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
823
832
 
824
833
  declare type StrictExtract<T, U extends T> = U
825
834
 
835
+ /**
836
+ * @public
837
+ */
838
+ declare type StyleSchemaType = BaseDefinition & {
839
+ /**
840
+ * @deprecated
841
+ * Use `name` instead
842
+ */
843
+ value: string
844
+ }
845
+
826
846
  /**
827
847
  * @beta
828
848
  */
package/lib/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), types = require("@sanity/types"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), types = require("@sanity/types"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -417,7 +417,7 @@ function getEventPosition({
417
417
  return;
418
418
  const eventSelectionFocusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(eventSelection.focus);
419
419
  if (eventSelectionFocusBlockKey !== void 0)
420
- return util_selectionPointToBlockOffset.isSelectionCollapsed(eventSelection) && eventBlock && eventSelectionFocusBlockKey !== eventBlock._key ? {
420
+ return util_sliceTextBlock.isSelectionCollapsed(eventSelection) && eventBlock && eventSelectionFocusBlockKey !== eventBlock._key ? {
421
421
  block: eventPositionBlock,
422
422
  isEditor: !1,
423
423
  selection: {
@@ -3163,13 +3163,13 @@ const addAnnotationOperationImplementation = ({
3163
3163
  schema: context.schema,
3164
3164
  editor,
3165
3165
  range: selection
3166
- }), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
3166
+ }), anchorOffset = editorSelection ? util_sliceTextBlock.selectionPointToBlockOffset({
3167
3167
  context: {
3168
3168
  ...context,
3169
3169
  value
3170
3170
  },
3171
3171
  selectionPoint: editorSelection.anchor
3172
- }) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
3172
+ }) : void 0, focusOffset = editorSelection ? util_sliceTextBlock.selectionPointToBlockOffset({
3173
3173
  context: {
3174
3174
  ...context,
3175
3175
  value
@@ -6832,7 +6832,7 @@ const coreDndBehaviors = [
6832
6832
  snapshot
6833
6833
  }) => {
6834
6834
  const selection = snapshot.context.selection;
6835
- if (!selection || util_selectionPointToBlockOffset.isSelectionCollapsed(selection))
6835
+ if (!selection || util_sliceTextBlock.isSelectionCollapsed(selection))
6836
6836
  return !1;
6837
6837
  const selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
6838
6838
  return !selectionStartBlock || !selectionEndBlock ? !1 : !selectionPoint.isTextBlock(snapshot.context, selectionStartBlock.node) && selectionPoint.isTextBlock(snapshot.context, selectionEndBlock.node) ? {
@@ -6852,7 +6852,7 @@ const coreDndBehaviors = [
6852
6852
  snapshot
6853
6853
  }) => {
6854
6854
  const selection = snapshot.context.selection;
6855
- return !selection || util_selectionPointToBlockOffset.isSelectionCollapsed(selection) ? !1 : {
6855
+ return !selection || util_sliceTextBlock.isSelectionCollapsed(selection) ? !1 : {
6856
6856
  selection
6857
6857
  };
6858
6858
  },
@@ -6871,7 +6871,7 @@ const coreDndBehaviors = [
6871
6871
  snapshot
6872
6872
  }) => {
6873
6873
  const selection = snapshot.context.selection;
6874
- if (!selection || !util_selectionPointToBlockOffset.isSelectionCollapsed(selection))
6874
+ if (!selection || !util_sliceTextBlock.isSelectionCollapsed(selection))
6875
6875
  return !1;
6876
6876
  const selectionStartPoint = selectionPoint.getSelectionStartPoint(selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
6877
6877
  if (!focusTextBlock)
@@ -6883,13 +6883,13 @@ const coreDndBehaviors = [
6883
6883
  anchor: selectionStartPoint,
6884
6884
  focus: blockEndPoint
6885
6885
  }, newTextBlock = selectionPoint.parseBlock({
6886
- block: selector_isSelectionExpanded.getSelectedValue({
6887
- ...snapshot,
6886
+ block: util_sliceTextBlock.sliceTextBlock({
6888
6887
  context: {
6889
6888
  ...snapshot.context,
6890
6889
  selection: newTextBlockSelection
6891
- }
6892
- }).at(0),
6890
+ },
6891
+ block: focusTextBlock.node
6892
+ }),
6893
6893
  context: snapshot.context,
6894
6894
  options: {
6895
6895
  refreshKeys: !0,
@@ -6904,7 +6904,7 @@ const coreDndBehaviors = [
6904
6904
  actions: [(_, {
6905
6905
  newTextBlock,
6906
6906
  newTextBlockSelection
6907
- }) => util_selectionPointToBlockOffset.isSelectionCollapsed(newTextBlockSelection) ? [behaviors_index.raise({
6907
+ }) => util_sliceTextBlock.isSelectionCollapsed(newTextBlockSelection) ? [behaviors_index.raise({
6908
6908
  type: "insert.block",
6909
6909
  block: newTextBlock,
6910
6910
  placement: "after",
@@ -8057,9 +8057,6 @@ function resolveEnabledListItems(blockType) {
8057
8057
  function findBlockType(type) {
8058
8058
  return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
8059
8059
  }
8060
- function defineSchema(definition) {
8061
- return definition;
8062
- }
8063
8060
  const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
8064
8061
  image: temporaryImageName,
8065
8062
  url: temporaryUrlName
@@ -11433,6 +11430,9 @@ function EditorProvider(props) {
11433
11430
  t8
11434
11431
  ] }), $[28] = internalEditor_0.editor, $[29] = t4, $[30] = t8, $[31] = t9) : t9 = $[31], t9;
11435
11432
  }
11433
+ function defineSchema(definition) {
11434
+ return definition;
11435
+ }
11436
11436
  const usePortableTextEditorSelection = () => {
11437
11437
  const $ = reactCompilerRuntime.c(3), editorActor = React.useContext(EditorActorContext), [selection, setSelection] = React.useState(null);
11438
11438
  let t0, t1;