@portabletext/editor 1.44.15 → 1.45.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.
Files changed (66) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +5 -5
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +28 -22
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +154 -129
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/parse-blocks.cjs +74 -22
  8. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
  9. package/lib/_chunks-es/behavior.core.js +5 -5
  10. package/lib/_chunks-es/behavior.core.js.map +1 -1
  11. package/lib/_chunks-es/behavior.markdown.js +28 -22
  12. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  13. package/lib/_chunks-es/editor-provider.js +161 -136
  14. package/lib/_chunks-es/editor-provider.js.map +1 -1
  15. package/lib/_chunks-es/parse-blocks.js +75 -23
  16. package/lib/_chunks-es/parse-blocks.js.map +1 -1
  17. package/lib/behaviors/index.cjs +18 -14
  18. package/lib/behaviors/index.cjs.map +1 -1
  19. package/lib/behaviors/index.d.cts +862 -636
  20. package/lib/behaviors/index.d.ts +862 -636
  21. package/lib/behaviors/index.js +18 -14
  22. package/lib/behaviors/index.js.map +1 -1
  23. package/lib/index.cjs +1 -1
  24. package/lib/index.cjs.map +1 -1
  25. package/lib/index.d.cts +40 -17
  26. package/lib/index.d.ts +40 -17
  27. package/lib/index.js +1 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/plugins/index.cjs +16 -7
  30. package/lib/plugins/index.cjs.map +1 -1
  31. package/lib/plugins/index.d.cts +20 -14
  32. package/lib/plugins/index.d.ts +20 -14
  33. package/lib/plugins/index.js +16 -7
  34. package/lib/plugins/index.js.map +1 -1
  35. package/lib/selectors/index.d.cts +20 -14
  36. package/lib/selectors/index.d.ts +20 -14
  37. package/lib/utils/index.d.cts +20 -14
  38. package/lib/utils/index.d.ts +20 -14
  39. package/package.json +2 -2
  40. package/src/behavior-actions/behavior.action.annotation.add.ts +26 -5
  41. package/src/behavior-actions/behavior.action.decorator.add.ts +4 -4
  42. package/src/behavior-actions/behavior.action.delete.text.ts +1 -4
  43. package/src/behavior-actions/behavior.action.delete.ts +2 -2
  44. package/src/behavior-actions/behavior.action.insert-inline-object.ts +14 -13
  45. package/src/behavior-actions/behavior.action.select.ts +1 -1
  46. package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
  47. package/src/behavior-actions/behavior.actions.ts +9 -20
  48. package/src/behaviors/behavior.abstract.decorator.ts +2 -2
  49. package/src/behaviors/behavior.abstract.insert.ts +9 -1
  50. package/src/behaviors/behavior.abstract.select.ts +2 -2
  51. package/src/behaviors/behavior.core.annotations.ts +1 -1
  52. package/src/behaviors/behavior.core.block-objects.ts +4 -4
  53. package/src/behaviors/behavior.decorator-pair.ts +3 -3
  54. package/src/behaviors/behavior.default.ts +4 -4
  55. package/src/behaviors/behavior.emoji-picker.ts +18 -14
  56. package/src/behaviors/behavior.markdown.ts +28 -22
  57. package/src/behaviors/behavior.types.event.ts +23 -14
  58. package/src/converters/converter.portable-text.deserialize.test.ts +12 -3
  59. package/src/converters/converter.text-html.deserialize.test.ts +3 -1
  60. package/src/editor/Editable.tsx +1 -1
  61. package/src/editor/define-schema.ts +29 -5
  62. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +2 -2
  63. package/src/editor/plugins/create-with-event-listeners.ts +4 -4
  64. package/src/internal-utils/parse-blocks.ts +109 -39
  65. package/src/plugins/plugin.decorator-shortcut.ts +3 -3
  66. package/src/plugins/plugin.one-line.tsx +8 -1
package/lib/index.d.cts CHANGED
@@ -79,7 +79,7 @@ declare type AbstractBehaviorEvent =
79
79
  | {
80
80
  type: StrictExtract<AbstractBehaviorEventType, 'decorator.toggle'>
81
81
  decorator: string
82
- offsets?: {
82
+ at?: {
83
83
  anchor: BlockOffset
84
84
  focus: BlockOffset
85
85
  }
@@ -151,6 +151,12 @@ declare type AbstractBehaviorEvent =
151
151
  blocks: Array<PortableTextBlock>
152
152
  placement: InsertPlacement
153
153
  }
154
+ | {
155
+ type: StrictExtract<AbstractBehaviorEventType, 'insert.break'>
156
+ }
157
+ | {
158
+ type: StrictExtract<AbstractBehaviorEventType, 'insert.soft break'>
159
+ }
154
160
  | {
155
161
  type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
156
162
  listItem: string
@@ -208,6 +214,8 @@ declare const abstractBehaviorEventTypes: readonly [
208
214
  'deserialization.success',
209
215
  'deserialization.failure',
210
216
  'insert.blocks',
217
+ 'insert.break',
218
+ 'insert.soft break',
211
219
  'list item.add',
212
220
  'list item.remove',
213
221
  'list item.toggle',
@@ -5080,6 +5088,11 @@ declare type ExternalEditorEvent =
5080
5088
  declare type ExtractNamespace<TType extends string> =
5081
5089
  TType extends `${infer Namespace}.${string}` ? Namespace : TType
5082
5090
 
5091
+ declare type FieldDefinition = {
5092
+ name: string
5093
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object'
5094
+ }
5095
+
5083
5096
  /**
5084
5097
  * The editor received focus
5085
5098
  * @beta */
@@ -6105,9 +6118,21 @@ export declare type SchemaDefinition<
6105
6118
  TBaseDefinition extends BaseDefinition = BaseDefinition,
6106
6119
  > = {
6107
6120
  decorators?: ReadonlyArray<TBaseDefinition>
6108
- blockObjects?: ReadonlyArray<TBaseDefinition>
6109
- inlineObjects?: ReadonlyArray<TBaseDefinition>
6110
- annotations?: ReadonlyArray<TBaseDefinition>
6121
+ blockObjects?: ReadonlyArray<
6122
+ TBaseDefinition & {
6123
+ fields?: ReadonlyArray<FieldDefinition>
6124
+ }
6125
+ >
6126
+ inlineObjects?: ReadonlyArray<
6127
+ TBaseDefinition & {
6128
+ fields?: ReadonlyArray<FieldDefinition>
6129
+ }
6130
+ >
6131
+ annotations?: ReadonlyArray<
6132
+ TBaseDefinition & {
6133
+ fields?: ReadonlyArray<FieldDefinition>
6134
+ }
6135
+ >
6111
6136
  lists?: ReadonlyArray<TBaseDefinition>
6112
6137
  styles?: ReadonlyArray<TBaseDefinition>
6113
6138
  }
@@ -6180,7 +6205,7 @@ declare type SyntheticBehaviorEvent =
6180
6205
  | {
6181
6206
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
6182
6207
  decorator: string
6183
- offsets?: {
6208
+ at?: {
6184
6209
  anchor: BlockOffset
6185
6210
  focus: BlockOffset
6186
6211
  }
@@ -6191,7 +6216,7 @@ declare type SyntheticBehaviorEvent =
6191
6216
  }
6192
6217
  | {
6193
6218
  type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
6194
- selection: NonNullable<EditorSelection>
6219
+ at: NonNullable<EditorSelection>
6195
6220
  }
6196
6221
  | {
6197
6222
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
@@ -6207,8 +6232,10 @@ declare type SyntheticBehaviorEvent =
6207
6232
  }
6208
6233
  | {
6209
6234
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
6210
- anchor: BlockOffset
6211
- focus: BlockOffset
6235
+ at: {
6236
+ anchor: BlockOffset
6237
+ focus: BlockOffset
6238
+ }
6212
6239
  }
6213
6240
  | {
6214
6241
  type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
@@ -6228,12 +6255,6 @@ declare type SyntheticBehaviorEvent =
6228
6255
  }
6229
6256
  }
6230
6257
  }
6231
- | {
6232
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
6233
- }
6234
- | {
6235
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
6236
- }
6237
6258
  | {
6238
6259
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
6239
6260
  block: BlockWithOptionalKey
@@ -6262,7 +6283,10 @@ declare type SyntheticBehaviorEvent =
6262
6283
  }
6263
6284
  | {
6264
6285
  type: StrictExtract<SyntheticBehaviorEventType, 'select'>
6265
- selection: EditorSelection
6286
+ at: EditorSelection
6287
+ }
6288
+ | {
6289
+ type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
6266
6290
  }
6267
6291
 
6268
6292
  declare type SyntheticBehaviorEventNamespace =
@@ -6291,13 +6315,12 @@ declare const syntheticBehaviorEventTypes: readonly [
6291
6315
  'history.redo',
6292
6316
  'history.undo',
6293
6317
  'insert.inline object',
6294
- 'insert.break',
6295
- 'insert.soft break',
6296
6318
  'insert.block',
6297
6319
  'insert.span',
6298
6320
  'insert.text',
6299
6321
  'move.block',
6300
6322
  'select',
6323
+ 'split.block',
6301
6324
  ]
6302
6325
 
6303
6326
  declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
package/lib/index.d.ts CHANGED
@@ -79,7 +79,7 @@ declare type AbstractBehaviorEvent =
79
79
  | {
80
80
  type: StrictExtract<AbstractBehaviorEventType, 'decorator.toggle'>
81
81
  decorator: string
82
- offsets?: {
82
+ at?: {
83
83
  anchor: BlockOffset
84
84
  focus: BlockOffset
85
85
  }
@@ -151,6 +151,12 @@ declare type AbstractBehaviorEvent =
151
151
  blocks: Array<PortableTextBlock>
152
152
  placement: InsertPlacement
153
153
  }
154
+ | {
155
+ type: StrictExtract<AbstractBehaviorEventType, 'insert.break'>
156
+ }
157
+ | {
158
+ type: StrictExtract<AbstractBehaviorEventType, 'insert.soft break'>
159
+ }
154
160
  | {
155
161
  type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
156
162
  listItem: string
@@ -208,6 +214,8 @@ declare const abstractBehaviorEventTypes: readonly [
208
214
  'deserialization.success',
209
215
  'deserialization.failure',
210
216
  'insert.blocks',
217
+ 'insert.break',
218
+ 'insert.soft break',
211
219
  'list item.add',
212
220
  'list item.remove',
213
221
  'list item.toggle',
@@ -5080,6 +5088,11 @@ declare type ExternalEditorEvent =
5080
5088
  declare type ExtractNamespace<TType extends string> =
5081
5089
  TType extends `${infer Namespace}.${string}` ? Namespace : TType
5082
5090
 
5091
+ declare type FieldDefinition = {
5092
+ name: string
5093
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object'
5094
+ }
5095
+
5083
5096
  /**
5084
5097
  * The editor received focus
5085
5098
  * @beta */
@@ -6105,9 +6118,21 @@ export declare type SchemaDefinition<
6105
6118
  TBaseDefinition extends BaseDefinition = BaseDefinition,
6106
6119
  > = {
6107
6120
  decorators?: ReadonlyArray<TBaseDefinition>
6108
- blockObjects?: ReadonlyArray<TBaseDefinition>
6109
- inlineObjects?: ReadonlyArray<TBaseDefinition>
6110
- annotations?: ReadonlyArray<TBaseDefinition>
6121
+ blockObjects?: ReadonlyArray<
6122
+ TBaseDefinition & {
6123
+ fields?: ReadonlyArray<FieldDefinition>
6124
+ }
6125
+ >
6126
+ inlineObjects?: ReadonlyArray<
6127
+ TBaseDefinition & {
6128
+ fields?: ReadonlyArray<FieldDefinition>
6129
+ }
6130
+ >
6131
+ annotations?: ReadonlyArray<
6132
+ TBaseDefinition & {
6133
+ fields?: ReadonlyArray<FieldDefinition>
6134
+ }
6135
+ >
6111
6136
  lists?: ReadonlyArray<TBaseDefinition>
6112
6137
  styles?: ReadonlyArray<TBaseDefinition>
6113
6138
  }
@@ -6180,7 +6205,7 @@ declare type SyntheticBehaviorEvent =
6180
6205
  | {
6181
6206
  type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
6182
6207
  decorator: string
6183
- offsets?: {
6208
+ at?: {
6184
6209
  anchor: BlockOffset
6185
6210
  focus: BlockOffset
6186
6211
  }
@@ -6191,7 +6216,7 @@ declare type SyntheticBehaviorEvent =
6191
6216
  }
6192
6217
  | {
6193
6218
  type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
6194
- selection: NonNullable<EditorSelection>
6219
+ at: NonNullable<EditorSelection>
6195
6220
  }
6196
6221
  | {
6197
6222
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
@@ -6207,8 +6232,10 @@ declare type SyntheticBehaviorEvent =
6207
6232
  }
6208
6233
  | {
6209
6234
  type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
6210
- anchor: BlockOffset
6211
- focus: BlockOffset
6235
+ at: {
6236
+ anchor: BlockOffset
6237
+ focus: BlockOffset
6238
+ }
6212
6239
  }
6213
6240
  | {
6214
6241
  type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
@@ -6228,12 +6255,6 @@ declare type SyntheticBehaviorEvent =
6228
6255
  }
6229
6256
  }
6230
6257
  }
6231
- | {
6232
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
6233
- }
6234
- | {
6235
- type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
6236
- }
6237
6258
  | {
6238
6259
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
6239
6260
  block: BlockWithOptionalKey
@@ -6262,7 +6283,10 @@ declare type SyntheticBehaviorEvent =
6262
6283
  }
6263
6284
  | {
6264
6285
  type: StrictExtract<SyntheticBehaviorEventType, 'select'>
6265
- selection: EditorSelection
6286
+ at: EditorSelection
6287
+ }
6288
+ | {
6289
+ type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
6266
6290
  }
6267
6291
 
6268
6292
  declare type SyntheticBehaviorEventNamespace =
@@ -6291,13 +6315,12 @@ declare const syntheticBehaviorEventTypes: readonly [
6291
6315
  'history.redo',
6292
6316
  'history.undo',
6293
6317
  'insert.inline object',
6294
- 'insert.break',
6295
- 'insert.soft break',
6296
6318
  'insert.block',
6297
6319
  'insert.span',
6298
6320
  'insert.text',
6299
6321
  'move.block',
6300
6322
  'select',
6323
+ 'split.block',
6301
6324
  ]
6302
6325
 
6303
6326
  declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
package/lib/index.js CHANGED
@@ -1443,7 +1443,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
1443
1443
  type: "behavior event",
1444
1444
  behaviorEvent: {
1445
1445
  type: "select",
1446
- selection: isSelectionCollapsed$1(dragSelection) ? dragSelection : {
1446
+ at: isSelectionCollapsed$1(dragSelection) ? dragSelection : {
1447
1447
  anchor: getSelectionEndPoint(dragSelection),
1448
1448
  focus: getSelectionEndPoint(dragSelection),
1449
1449
  backward: !1