@portabletext/editor 2.3.2 → 2.3.4

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 (38) hide show
  1. package/lib/_chunks-dts/behavior.types.action.d.cts +5 -142
  2. package/lib/_chunks-dts/behavior.types.action.d.ts +55 -192
  3. package/lib/index.cjs +43 -279
  4. package/lib/index.cjs.map +1 -1
  5. package/lib/index.js +5 -245
  6. package/lib/index.js.map +1 -1
  7. package/lib/utils/index.d.cts +2 -2
  8. package/lib/utils/index.d.ts +2 -2
  9. package/package.json +7 -5
  10. package/src/converters/converter.portable-text.deserialize.test.ts +6 -4
  11. package/src/converters/converter.text-html.deserialize.test.ts +15 -15
  12. package/src/converters/converter.text-html.serialize.test.ts +8 -8
  13. package/src/converters/converter.text-plain.test.ts +8 -8
  14. package/src/editor/create-editor.ts +12 -10
  15. package/src/editor/editor-schema.ts +2 -312
  16. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -2
  17. package/src/editor.ts +1 -1
  18. package/src/index.ts +3 -3
  19. package/src/internal-utils/__tests__/values.test.ts +2 -3
  20. package/src/internal-utils/apply-operation-to-portable-text.test.ts +2 -3
  21. package/src/internal-utils/build-index-maps.test.ts +2 -3
  22. package/src/internal-utils/create-test-snapshot.ts +2 -4
  23. package/src/internal-utils/drag-selection.test.ts +2 -5
  24. package/src/internal-utils/operation-to-patches.test.ts +5 -7
  25. package/src/internal-utils/parse-blocks.test.ts +21 -30
  26. package/src/internal-utils/selection-text.ts +2 -3
  27. package/src/internal-utils/terse-pt.test.ts +2 -3
  28. package/src/internal-utils/test-editor.tsx +1 -4
  29. package/src/internal-utils/to-slate-range.test.ts +2 -3
  30. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +1 -1
  31. package/src/plugins/plugin.markdown.test.tsx +1 -1
  32. package/src/selectors/selector.get-selection-text.test.ts +2 -3
  33. package/src/selectors/selector.get-trimmed-selection.test.ts +2 -3
  34. package/src/utils/util.block-offset.test.ts +2 -3
  35. package/src/utils/util.slice-blocks.test.ts +2 -3
  36. package/src/utils/util.slice-text-block.test.ts +2 -3
  37. package/src/editor/editor-schema-definition.ts +0 -105
  38. package/src/editor/legacy-schema.ts +0 -115
@@ -1,9 +1,8 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {describe, expect, it} from 'vitest'
2
- import {compileSchemaDefinition} from '../../editor/editor-schema'
3
- import {defineSchema} from '../../editor/editor-schema-definition'
4
3
  import {fromSlateValue, toSlateValue} from '../values'
5
4
 
6
- const schemaTypes = compileSchemaDefinition(defineSchema({}))
5
+ const schemaTypes = compileSchema(defineSchema({}))
7
6
 
8
7
  describe('toSlateValue', () => {
9
8
  it('checks undefined', () => {
@@ -1,12 +1,11 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {describe, expect, test} from 'vitest'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import {applyOperationToPortableText} from './apply-operation-to-portable-text'
5
4
  import {createTestKeyGenerator} from './test-key-generator'
6
5
 
7
6
  function createContext() {
8
7
  const keyGenerator = createTestKeyGenerator()
9
- const schema = compileSchemaDefinition(defineSchema({}))
8
+ const schema = compileSchema(defineSchema({}))
10
9
 
11
10
  return {
12
11
  keyGenerator,
@@ -1,7 +1,6 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
3
  import {describe, expect, test} from 'vitest'
3
- import {compileSchemaDefinition} from '../editor/editor-schema'
4
- import {defineSchema} from '../editor/editor-schema-definition'
5
4
  import {defaultKeyGenerator} from '../editor/key-generator'
6
5
  import {buildIndexMaps} from './build-index-maps'
7
6
 
@@ -38,7 +37,7 @@ function textBlock(
38
37
  }
39
38
  }
40
39
 
41
- const schema = compileSchemaDefinition(
40
+ const schema = compileSchema(
42
41
  defineSchema({
43
42
  blockObjects: [{name: 'image'}],
44
43
  }),
@@ -1,6 +1,5 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {EditorSnapshot} from '..'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import {createTestKeyGenerator} from './test-key-generator'
5
4
 
6
5
  export function createTestSnapshot(snapshot: {
@@ -9,8 +8,7 @@ export function createTestSnapshot(snapshot: {
9
8
  }): EditorSnapshot {
10
9
  const context = {
11
10
  converters: snapshot.context?.converters ?? [],
12
- schema:
13
- snapshot.context?.schema ?? compileSchemaDefinition(defineSchema({})),
11
+ schema: snapshot.context?.schema ?? compileSchema(defineSchema({})),
14
12
  keyGenerator: snapshot.context?.keyGenerator ?? createTestKeyGenerator(),
15
13
  readOnly: snapshot.context?.readOnly ?? false,
16
14
  value: snapshot.context?.value ?? [],
@@ -1,6 +1,5 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {describe, expect, test} from 'vitest'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import type {EditorSelection} from '../types/editor'
5
4
  import {createTestSnapshot} from './create-test-snapshot'
6
5
  import {getDragSelection} from './drag-selection'
@@ -57,9 +56,7 @@ describe(getDragSelection.name, () => {
57
56
  return createTestSnapshot({
58
57
  context: {
59
58
  keyGenerator,
60
- schema: compileSchemaDefinition(
61
- defineSchema({blockObjects: [{name: 'image'}]}),
62
- ),
59
+ schema: compileSchema(defineSchema({blockObjects: [{name: 'image'}]})),
63
60
  selection,
64
61
  value: [foo, baz, image],
65
62
  },
@@ -1,13 +1,10 @@
1
+ import {compileSchemaDefinitionToPortableTextMemberSchemaTypes} from '@portabletext/sanity-bridge'
2
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
3
  import type {PortableTextTextBlock} from '@sanity/types'
2
4
  import {createEditor, type Descendant} from 'slate'
3
5
  import {beforeEach, describe, expect, it} from 'vitest'
4
6
  import {createActor} from 'xstate'
5
7
  import {editorMachine} from '../editor/editor-machine'
6
- import {
7
- compileSchemaDefinition,
8
- compileSchemaDefinitionToLegacySchema,
9
- } from '../editor/editor-schema'
10
- import {defineSchema} from '../editor/editor-schema-definition'
11
8
  import {defaultKeyGenerator} from '../editor/key-generator'
12
9
  import {withPlugins} from '../editor/plugins/with-plugins'
13
10
  import {relayMachine} from '../editor/relay-machine'
@@ -23,8 +20,9 @@ import {
23
20
  const schemaDefinition = defineSchema({
24
21
  inlineObjects: [{name: 'someObject'}],
25
22
  })
26
- const schema = compileSchemaDefinition(schemaDefinition)
27
- const legacySchema = compileSchemaDefinitionToLegacySchema(schemaDefinition)
23
+ const schema = compileSchema(schemaDefinition)
24
+ const legacySchema =
25
+ compileSchemaDefinitionToPortableTextMemberSchemaTypes(schemaDefinition)
28
26
  const editorActor = createActor(editorMachine, {
29
27
  input: {
30
28
  schema,
@@ -1,6 +1,5 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {describe, expect, test} from 'vitest'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import {parseBlock, parseSpan} from './parse-blocks'
5
4
  import {createTestKeyGenerator} from './test-key-generator'
6
5
 
@@ -11,7 +10,7 @@ describe(parseBlock.name, () => {
11
10
  block: null,
12
11
  context: {
13
12
  keyGenerator: createTestKeyGenerator(),
14
- schema: compileSchemaDefinition(defineSchema({})),
13
+ schema: compileSchema(defineSchema({})),
15
14
  },
16
15
  options: {refreshKeys: false, validateFields: true},
17
16
  }),
@@ -24,7 +23,7 @@ describe(parseBlock.name, () => {
24
23
  block: undefined,
25
24
  context: {
26
25
  keyGenerator: createTestKeyGenerator(),
27
- schema: compileSchemaDefinition(defineSchema({})),
26
+ schema: compileSchema(defineSchema({})),
28
27
  },
29
28
  options: {refreshKeys: false, validateFields: true},
30
29
  }),
@@ -38,7 +37,7 @@ describe(parseBlock.name, () => {
38
37
  block: {},
39
38
  context: {
40
39
  keyGenerator: createTestKeyGenerator(),
41
- schema: compileSchemaDefinition(defineSchema({})),
40
+ schema: compileSchema(defineSchema({})),
42
41
  },
43
42
  options: {refreshKeys: false, validateFields: true},
44
43
  }),
@@ -51,7 +50,7 @@ describe(parseBlock.name, () => {
51
50
  block: {_key: 'k0'},
52
51
  context: {
53
52
  keyGenerator: createTestKeyGenerator(),
54
- schema: compileSchemaDefinition(
53
+ schema: compileSchema(
55
54
  defineSchema({blockObjects: [{name: 'image'}]}),
56
55
  ),
57
56
  },
@@ -66,7 +65,7 @@ describe(parseBlock.name, () => {
66
65
  block: {_type: 'image'},
67
66
  context: {
68
67
  keyGenerator: createTestKeyGenerator(),
69
- schema: compileSchemaDefinition(
68
+ schema: compileSchema(
70
69
  defineSchema({blockObjects: [{name: 'image'}]}),
71
70
  ),
72
71
  },
@@ -86,7 +85,7 @@ describe(parseBlock.name, () => {
86
85
  block: {_type: 'block'},
87
86
  context: {
88
87
  keyGenerator: createTestKeyGenerator(),
89
- schema: compileSchemaDefinition(defineSchema({})),
88
+ schema: compileSchema(defineSchema({})),
90
89
  },
91
90
  options: {refreshKeys: false, validateFields: true},
92
91
  }),
@@ -107,7 +106,7 @@ describe(parseBlock.name, () => {
107
106
  })
108
107
 
109
108
  test('custom _type', () => {
110
- const schema = compileSchemaDefinition(defineSchema({}))
109
+ const schema = compileSchema(defineSchema({}))
111
110
  expect(
112
111
  parseBlock({
113
112
  block: {_type: 'text'},
@@ -148,7 +147,7 @@ describe(parseBlock.name, () => {
148
147
  },
149
148
  context: {
150
149
  keyGenerator: createTestKeyGenerator(),
151
- schema: compileSchemaDefinition(defineSchema({})),
150
+ schema: compileSchema(defineSchema({})),
152
151
  },
153
152
  options: {refreshKeys: false, validateFields: true},
154
153
  }),
@@ -182,7 +181,7 @@ describe(parseBlock.name, () => {
182
181
  },
183
182
  context: {
184
183
  keyGenerator: createTestKeyGenerator(),
185
- schema: compileSchemaDefinition(
184
+ schema: compileSchema(
186
185
  defineSchema({
187
186
  inlineObjects: [{name: 'stock-ticker'}],
188
187
  decorators: [{name: 'em'}],
@@ -235,9 +234,7 @@ describe(parseBlock.name, () => {
235
234
  block: {_type: 'block', listItem: 'bullet'},
236
235
  context: {
237
236
  keyGenerator: createTestKeyGenerator(),
238
- schema: compileSchemaDefinition(
239
- defineSchema({lists: [{name: 'bullet'}]}),
240
- ),
237
+ schema: compileSchema(defineSchema({lists: [{name: 'bullet'}]})),
241
238
  },
242
239
  options: {refreshKeys: false, validateFields: true},
243
240
  }),
@@ -264,9 +261,7 @@ describe(parseBlock.name, () => {
264
261
  block: {_type: 'block', listItem: 'number'},
265
262
  context: {
266
263
  keyGenerator: createTestKeyGenerator(),
267
- schema: compileSchemaDefinition(
268
- defineSchema({lists: [{name: 'bullet'}]}),
269
- ),
264
+ schema: compileSchema(defineSchema({lists: [{name: 'bullet'}]})),
270
265
  },
271
266
  options: {refreshKeys: false, validateFields: true},
272
267
  }),
@@ -295,7 +290,7 @@ describe(parseSpan.name, () => {
295
290
  span: undefined,
296
291
  context: {
297
292
  keyGenerator: createTestKeyGenerator(),
298
- schema: compileSchemaDefinition(defineSchema({})),
293
+ schema: compileSchema(defineSchema({})),
299
294
  },
300
295
  markDefKeyMap: new Map(),
301
296
  options: {refreshKeys: false, validateFields: true},
@@ -309,7 +304,7 @@ describe(parseSpan.name, () => {
309
304
  span: null,
310
305
  context: {
311
306
  keyGenerator: createTestKeyGenerator(),
312
- schema: compileSchemaDefinition(defineSchema({})),
307
+ schema: compileSchema(defineSchema({})),
313
308
  },
314
309
  markDefKeyMap: new Map(),
315
310
  options: {refreshKeys: false, validateFields: true},
@@ -323,7 +318,7 @@ describe(parseSpan.name, () => {
323
318
  span: {},
324
319
  context: {
325
320
  keyGenerator: createTestKeyGenerator(),
326
- schema: compileSchemaDefinition(defineSchema({})),
321
+ schema: compileSchema(defineSchema({})),
327
322
  },
328
323
  markDefKeyMap: new Map(),
329
324
  options: {refreshKeys: false, validateFields: true},
@@ -337,7 +332,7 @@ describe(parseSpan.name, () => {
337
332
  span: {_type: 'stock-ticker'},
338
333
  context: {
339
334
  keyGenerator: createTestKeyGenerator(),
340
- schema: compileSchemaDefinition(defineSchema({})),
335
+ schema: compileSchema(defineSchema({})),
341
336
  },
342
337
  markDefKeyMap: new Map(),
343
338
  options: {refreshKeys: false, validateFields: true},
@@ -351,7 +346,7 @@ describe(parseSpan.name, () => {
351
346
  span: {_type: 'span'},
352
347
  context: {
353
348
  keyGenerator: createTestKeyGenerator(),
354
- schema: compileSchemaDefinition(defineSchema({})),
349
+ schema: compileSchema(defineSchema({})),
355
350
  },
356
351
  markDefKeyMap: new Map(),
357
352
  options: {refreshKeys: false, validateFields: true},
@@ -370,7 +365,7 @@ describe(parseSpan.name, () => {
370
365
  span: {_type: 'span', foo: 'bar'},
371
366
  context: {
372
367
  keyGenerator: createTestKeyGenerator(),
373
- schema: compileSchemaDefinition(defineSchema({})),
368
+ schema: compileSchema(defineSchema({})),
374
369
  },
375
370
  markDefKeyMap: new Map(),
376
371
  options: {refreshKeys: false, validateFields: true},
@@ -392,7 +387,7 @@ describe(parseSpan.name, () => {
392
387
  },
393
388
  context: {
394
389
  keyGenerator: createTestKeyGenerator(),
395
- schema: compileSchemaDefinition(defineSchema({})),
390
+ schema: compileSchema(defineSchema({})),
396
391
  },
397
392
  markDefKeyMap: new Map(),
398
393
  options: {refreshKeys: false, validateFields: true},
@@ -414,9 +409,7 @@ describe(parseSpan.name, () => {
414
409
  },
415
410
  context: {
416
411
  keyGenerator: createTestKeyGenerator(),
417
- schema: compileSchemaDefinition(
418
- defineSchema({decorators: [{name: 'strong'}]}),
419
- ),
412
+ schema: compileSchema(defineSchema({decorators: [{name: 'strong'}]})),
420
413
  },
421
414
  markDefKeyMap: new Map(),
422
415
  options: {refreshKeys: false, validateFields: true},
@@ -438,9 +431,7 @@ describe(parseSpan.name, () => {
438
431
  },
439
432
  context: {
440
433
  keyGenerator: createTestKeyGenerator(),
441
- schema: compileSchemaDefinition(
442
- defineSchema({decorators: [{name: 'strong'}]}),
443
- ),
434
+ schema: compileSchema(defineSchema({decorators: [{name: 'strong'}]})),
444
435
  },
445
436
  markDefKeyMap: new Map(),
446
437
  options: {refreshKeys: false, validateFields: true},
@@ -1,6 +1,5 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import type {EditorSelection} from '../types/editor'
5
4
  import {sliceBlocks} from '../utils/util.slice-blocks'
6
5
  import {getTersePt} from './terse-pt'
@@ -14,7 +13,7 @@ export function getSelectionText(
14
13
  }
15
14
 
16
15
  const slice = sliceBlocks({
17
- context: {schema: compileSchemaDefinition(defineSchema({})), selection},
16
+ context: {schema: compileSchema(defineSchema({})), selection},
18
17
  blocks: value,
19
18
  })
20
19
 
@@ -1,6 +1,5 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {expect, test} from 'vitest'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
5
4
  import {getTersePt, parseTersePt, parseTersePtString} from './terse-pt'
6
5
 
@@ -108,7 +107,7 @@ test(parseTersePt.name, () => {
108
107
  expect(
109
108
  parseTersePt(
110
109
  {
111
- schema: compileSchemaDefinition(defineSchema({})),
110
+ schema: compileSchema(defineSchema({})),
112
111
  keyGenerator: createTestKeyGenerator(),
113
112
  },
114
113
  parseTersePtString('{image}|foo|>>#h4:bar|-:baz,fizz|,{stock-ticker},'),
@@ -1,3 +1,4 @@
1
+ import {defineSchema, type SchemaDefinition} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
3
  import {page} from '@vitest/browser/context'
3
4
  import React from 'react'
@@ -7,10 +8,6 @@ import type {Editor} from '../editor'
7
8
  import {PortableTextEditable} from '../editor/Editable'
8
9
  import type {EditorActor} from '../editor/editor-machine'
9
10
  import {EditorProvider} from '../editor/editor-provider'
10
- import {
11
- defineSchema,
12
- type SchemaDefinition,
13
- } from '../editor/editor-schema-definition'
14
11
  import type {EditorEmittedEvent} from '../editor/relay-machine'
15
12
  import {EditorRefPlugin} from '../plugins/plugin.editor-ref'
16
13
  import {EventListenerPlugin} from '../plugins/plugin.event-listener'
@@ -1,11 +1,10 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import {describe, expect, test} from 'vitest'
2
- import {compileSchemaDefinition} from '../editor/editor-schema'
3
- import {defineSchema} from '../editor/editor-schema-definition'
4
3
  import {createTestKeyGenerator} from './test-key-generator'
5
4
  import {toSlateRange} from './to-slate-range'
6
5
 
7
6
  describe(toSlateRange.name, () => {
8
- const schema = compileSchemaDefinition(
7
+ const schema = compileSchema(
9
8
  defineSchema({
10
9
  blockObjects: [{name: 'image'}],
11
10
  inlineObjects: [
@@ -1,9 +1,9 @@
1
+ import {defineSchema} from '@portabletext/schema'
1
2
  import {page, userEvent} from '@vitest/browser/context'
2
3
  import React from 'react'
3
4
  import {describe, expect, test, vi} from 'vitest'
4
5
  import {render} from 'vitest-browser-react'
5
6
  import {EditorProvider, PortableTextEditable, type Editor} from '..'
6
- import {defineSchema} from '../editor/editor-schema-definition'
7
7
  import {getTersePt} from '../internal-utils/terse-pt'
8
8
  import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
9
9
  import {EditorRefPlugin} from './plugin.editor-ref'
@@ -1,10 +1,10 @@
1
+ import {defineSchema} from '@portabletext/schema'
1
2
  import {page, userEvent} from '@vitest/browser/context'
2
3
  import React from 'react'
3
4
  import {describe, expect, test, vi} from 'vitest'
4
5
  import {render} from 'vitest-browser-react'
5
6
  import {PortableTextEditable, type Editor} from '..'
6
7
  import {EditorProvider} from '../editor/editor-provider'
7
- import {defineSchema} from '../editor/editor-schema-definition'
8
8
  import {getTersePt} from '../internal-utils/terse-pt'
9
9
  import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
10
10
  import {getTextMarks} from '../internal-utils/text-marks'
@@ -1,8 +1,7 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
3
  import {expect, test} from 'vitest'
3
4
  import type {EditorSelection} from '..'
4
- import {compileSchemaDefinition} from '../editor/editor-schema'
5
- import {defineSchema} from '../editor/editor-schema-definition'
6
5
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
7
6
  import {getSelectionText} from './selector.get-selection-text'
8
7
 
@@ -72,7 +71,7 @@ test(getSelectionText.name, () => {
72
71
  ) {
73
72
  return createTestSnapshot({
74
73
  context: {
75
- schema: compileSchemaDefinition(
74
+ schema: compileSchema(
76
75
  defineSchema({
77
76
  inlineObjects: [{name: 'stock-ticker'}],
78
77
  }),
@@ -1,7 +1,6 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
3
  import {describe, expect, test} from 'vitest'
3
- import {compileSchemaDefinition} from '../editor/editor-schema'
4
- import {defineSchema} from '../editor/editor-schema-definition'
5
4
  import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
6
5
  import {parseBlock} from '../internal-utils/parse-blocks'
7
6
  import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
@@ -14,7 +13,7 @@ function snapshot(
14
13
  value: Array<Partial<PortableTextBlock>>,
15
14
  selection: EditorSelection,
16
15
  ) {
17
- const schema = compileSchemaDefinition(
16
+ const schema = compileSchema(
18
17
  defineSchema({
19
18
  blockObjects: [{name: 'image'}],
20
19
  inlineObjects: [{name: 'stock-ticker'}],
@@ -1,10 +1,9 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock} from '@sanity/types'
2
3
  import {expect, test} from 'vitest'
3
- import {compileSchemaDefinition} from '../editor/editor-schema'
4
- import {defineSchema} from '../editor/editor-schema-definition'
5
4
  import {blockOffsetToSpanSelectionPoint} from './util.block-offset'
6
5
 
7
- const schema = compileSchemaDefinition(defineSchema({}))
6
+ const schema = compileSchema(defineSchema({}))
8
7
 
9
8
  test(blockOffsetToSpanSelectionPoint.name, () => {
10
9
  const value: Array<PortableTextBlock> = [
@@ -1,7 +1,6 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
2
3
  import {describe, expect, test} from 'vitest'
3
- import {compileSchemaDefinition} from '../editor/editor-schema'
4
- import {defineSchema} from '../editor/editor-schema-definition'
5
4
  import {sliceBlocks} from './util.slice-blocks'
6
5
 
7
6
  const b1: PortableTextTextBlock = {
@@ -59,7 +58,7 @@ const b4: PortableTextTextBlock = {
59
58
  ],
60
59
  }
61
60
 
62
- const schema = compileSchemaDefinition(defineSchema({}))
61
+ const schema = compileSchema(defineSchema({}))
63
62
  const blocks: Array<PortableTextBlock> = [b1, b2, b3, b4]
64
63
 
65
64
  describe(sliceBlocks.name, () => {
@@ -1,3 +1,4 @@
1
+ import {compileSchema, defineSchema} from '@portabletext/schema'
1
2
  import type {
2
3
  PortableTextObject,
3
4
  PortableTextSpan,
@@ -5,11 +6,9 @@ import type {
5
6
  } from '@sanity/types'
6
7
  import {describe, expect, test} from 'vitest'
7
8
  import {keyGenerator} from '..'
8
- import {compileSchemaDefinition} from '../editor/editor-schema'
9
- import {defineSchema} from '../editor/editor-schema-definition'
10
9
  import {sliceTextBlock} from './util.slice-text-block'
11
10
 
12
- const schema = compileSchemaDefinition(
11
+ const schema = compileSchema(
13
12
  defineSchema({
14
13
  inlineObjects: [{name: 'stock-ticker'}],
15
14
  }),
@@ -1,105 +0,0 @@
1
- /**
2
- * @public
3
- */
4
- export type BaseDefinition = {
5
- name: string
6
- title?: string
7
- }
8
-
9
- /**
10
- * @public
11
- */
12
- export type FieldDefinition = BaseDefinition & {
13
- type: 'string' | 'number' | 'boolean' | 'array' | 'object'
14
- }
15
-
16
- /**
17
- * @public
18
- */
19
- export type DecoratorDefinition<
20
- TBaseDefinition extends BaseDefinition = BaseDefinition,
21
- > = TBaseDefinition
22
-
23
- /**
24
- * @public
25
- */
26
- export type AnnotationDefinition<
27
- TBaseDefinition extends BaseDefinition = BaseDefinition,
28
- > = TBaseDefinition & {
29
- fields?: ReadonlyArray<FieldDefinition>
30
- }
31
-
32
- /**
33
- * @public
34
- */
35
- export type BlockObjectDefinition<
36
- TBaseDefinition extends BaseDefinition = BaseDefinition,
37
- > = TBaseDefinition & {
38
- fields?: ReadonlyArray<FieldDefinition>
39
- }
40
-
41
- /**
42
- * @public
43
- */
44
- export type InlineObjectDefinition<
45
- TBaseDefinition extends BaseDefinition = BaseDefinition,
46
- > = TBaseDefinition & {
47
- fields?: ReadonlyArray<FieldDefinition>
48
- }
49
-
50
- /**
51
- * @public
52
- */
53
- export type ListDefinition<
54
- TBaseDefinition extends BaseDefinition = BaseDefinition,
55
- > = TBaseDefinition
56
-
57
- /**
58
- * @public
59
- */
60
- export type StyleDefinition<
61
- TBaseDefinition extends BaseDefinition = BaseDefinition,
62
- > = TBaseDefinition
63
-
64
- /**
65
- * @public
66
- */
67
- export type SchemaDefinition<
68
- TBaseDefinition extends BaseDefinition = BaseDefinition,
69
- > = {
70
- decorators?: ReadonlyArray<DecoratorDefinition<TBaseDefinition>>
71
- blockObjects?: ReadonlyArray<BlockObjectDefinition<TBaseDefinition>>
72
- inlineObjects?: ReadonlyArray<InlineObjectDefinition<TBaseDefinition>>
73
- annotations?: ReadonlyArray<AnnotationDefinition<TBaseDefinition>>
74
- lists?: ReadonlyArray<ListDefinition<TBaseDefinition>>
75
- styles?: ReadonlyArray<StyleDefinition<TBaseDefinition>>
76
- }
77
-
78
- /**
79
- * @public
80
- * A helper wrapper that adds editor support, such as autocomplete and type checking, for a schema definition.
81
- * @example
82
- * ```ts
83
- * import { defineSchema } from '@portabletext/editor'
84
- *
85
- * const schemaDefinition = defineSchema({
86
- * decorators: [{name: 'strong'}, {name: 'em'}, {name: 'underline'}],
87
- * annotations: [{name: 'link'}],
88
- * styles: [
89
- * {name: 'normal'},
90
- * {name: 'h1'},
91
- * {name: 'h2'},
92
- * {name: 'h3'},
93
- * {name: 'blockquote'},
94
- * ],
95
- * lists: [],
96
- * inlineObjects: [],
97
- * blockObjects: [],
98
- * }
99
- * ```
100
- */
101
- export function defineSchema<const TSchemaDefinition extends SchemaDefinition>(
102
- definition: TSchemaDefinition,
103
- ): TSchemaDefinition {
104
- return definition
105
- }