@portabletext/editor 1.15.1 → 1.15.3

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 (69) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +496 -0
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -231
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selectors.cjs +234 -0
  6. package/lib/_chunks-cjs/selectors.cjs.map +1 -0
  7. package/lib/_chunks-es/behavior.core.js +498 -0
  8. package/lib/_chunks-es/behavior.core.js.map +1 -0
  9. package/lib/_chunks-es/selector.get-text-before.js +2 -233
  10. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  11. package/lib/_chunks-es/selectors.js +235 -0
  12. package/lib/_chunks-es/selectors.js.map +1 -0
  13. package/lib/behaviors/index.cjs +460 -0
  14. package/lib/behaviors/index.cjs.map +1 -0
  15. package/lib/behaviors/index.d.cts +869 -0
  16. package/lib/behaviors/index.d.ts +869 -0
  17. package/lib/behaviors/index.js +464 -0
  18. package/lib/behaviors/index.js.map +1 -0
  19. package/lib/index.cjs +51 -1035
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +146 -669
  22. package/lib/index.d.ts +146 -669
  23. package/lib/index.js +44 -1027
  24. package/lib/index.js.map +1 -1
  25. package/lib/selectors/index.cjs +16 -16
  26. package/lib/selectors/index.cjs.map +1 -1
  27. package/lib/selectors/index.d.cts +8 -12
  28. package/lib/selectors/index.d.ts +8 -12
  29. package/lib/selectors/index.js +3 -2
  30. package/lib/selectors/index.js.map +1 -1
  31. package/package.json +11 -5
  32. package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +4 -6
  33. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-block-object.ts +1 -1
  34. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-break.ts +1 -1
  35. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-inline-object.ts +1 -1
  36. package/src/{editor/behavior → behavior-actions}/behavior.action.list-item.ts +2 -2
  37. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.set.ts +1 -1
  38. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.unset.ts +1 -1
  39. package/src/{editor/behavior → behavior-actions}/behavior.actions.ts +20 -20
  40. package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +2 -6
  41. package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
  42. package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +6 -6
  43. package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
  44. package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +17 -17
  45. package/src/{editor/behavior → behaviors}/behavior.links.ts +5 -5
  46. package/src/{editor/behavior → behaviors}/behavior.markdown.ts +25 -43
  47. package/src/{editor/behavior → behaviors}/behavior.types.ts +39 -46
  48. package/src/behaviors/index.ts +29 -0
  49. package/src/editor/PortableTextEditor.tsx +2 -2
  50. package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
  51. package/src/editor/create-editor.ts +28 -48
  52. package/src/editor/define-schema.ts +8 -3
  53. package/src/editor/editor-machine.ts +21 -36
  54. package/src/editor/editor-selector.ts +1 -13
  55. package/src/editor/editor-snapshot.ts +4 -6
  56. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  57. package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
  58. package/src/editor/utils/utils.block-offset.ts +1 -1
  59. package/src/index.ts +14 -31
  60. package/src/selectors/index.ts +2 -4
  61. package/src/selectors/selector.get-active-list-item.ts +1 -1
  62. package/src/selectors/selectors.ts +1 -1
  63. package/src/type-utils.ts +17 -0
  64. package/src/utils/__tests__/operationToPatches.test.ts +3 -3
  65. package/src/utils/__tests__/patchToOperations.test.ts +3 -3
  66. package/src/utils/__tests__/values.test.ts +2 -2
  67. /package/src/{editor/behavior → behavior-actions}/behavior.action.insert-span.ts +0 -0
  68. /package/src/{editor/behavior → behavior-actions}/behavior.action.style.ts +0 -0
  69. /package/src/{editor/behavior → behaviors}/behavior.core.ts +0 -0
@@ -1,16 +1,14 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
- import type {
3
- EditorSelection,
4
- PortableTextMemberSchemaTypes,
5
- } from '../types/editor'
2
+ import type {EditorSelection} from '../types/editor'
3
+ import type {EditorSchema} from './define-schema'
6
4
 
7
5
  /**
8
6
  * @alpha
9
7
  */
10
8
  export type EditorContext = {
11
9
  keyGenerator: () => string
12
- schema: PortableTextMemberSchemaTypes
13
- selection: NonNullable<EditorSelection>
10
+ schema: EditorSchema
11
+ selection: EditorSelection
14
12
  value: Array<PortableTextBlock>
15
13
  }
16
14
 
@@ -18,6 +18,9 @@ import {
18
18
  } from 'slate'
19
19
  import type {DOMNode} from 'slate-dom'
20
20
  import {ReactEditor} from 'slate-react'
21
+ import {isListItemActive} from '../../behavior-actions/behavior.action.list-item'
22
+ import {isStyleActive} from '../../behavior-actions/behavior.action.style'
23
+ import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
21
24
  import type {
22
25
  EditableAPI,
23
26
  EditableAPIDeleteOptions,
@@ -31,9 +34,6 @@ import {
31
34
  KEY_TO_VALUE_ELEMENT,
32
35
  SLATE_TO_PORTABLE_TEXT_RANGE,
33
36
  } from '../../utils/weakMaps'
34
- import {isListItemActive} from '../behavior/behavior.action.list-item'
35
- import {isStyleActive} from '../behavior/behavior.action.style'
36
- import type {BehaviorActionImplementation} from '../behavior/behavior.actions'
37
37
  import type {EditorActor} from '../editor-machine'
38
38
  import {isDecoratorActive} from './createWithPortableTextMarkModel'
39
39
 
@@ -8,6 +8,7 @@ import {isPortableTextBlock, isPortableTextSpan} from '@portabletext/toolkit'
8
8
  import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
9
9
  import {isEqual, uniq} from 'lodash'
10
10
  import {Editor, Element, Node, Path, Range, Text, Transforms} from 'slate'
11
+ import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
11
12
  import type {
12
13
  PortableTextMemberSchemaTypes,
13
14
  PortableTextSlateEditor,
@@ -16,7 +17,6 @@ import {debugWithName} from '../../utils/debug'
16
17
  import {getNextSpan, getPreviousSpan} from '../../utils/sibling-utils'
17
18
  import {isChangingRemotely} from '../../utils/withChanges'
18
19
  import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
19
- import type {BehaviorActionImplementation} from '../behavior/behavior.actions'
20
20
  import type {EditorActor} from '../editor-machine'
21
21
 
22
22
  const debug = debugWithName('plugin:withPortableTextMarkModel')
@@ -4,7 +4,7 @@ import {
4
4
  type KeyedSegment,
5
5
  type PortableTextBlock,
6
6
  } from '@sanity/types'
7
- import type {BlockOffset} from '../behavior/behavior.types'
7
+ import type {BlockOffset} from '../../behaviors/behavior.types'
8
8
 
9
9
  export function blockOffsetToSpanSelectionPoint({
10
10
  value,
package/src/index.ts CHANGED
@@ -1,31 +1,15 @@
1
1
  export type {Patch} from '@portabletext/patches'
2
2
  export type {PortableTextBlock, PortableTextChild} from '@sanity/types'
3
- export {
4
- createCodeEditorBehaviors,
5
- type CodeEditorBehaviorsConfig,
6
- } from './editor/behavior/behavior.code-editor'
7
- export {coreBehavior, coreBehaviors} from './editor/behavior/behavior.core'
8
- export {
9
- createLinkBehaviors,
10
- type LinkBehaviorsConfig,
11
- } from './editor/behavior/behavior.links'
12
- export {
13
- createMarkdownBehaviors,
14
- type MarkdownBehaviorsConfig,
15
- } from './editor/behavior/behavior.markdown'
16
- export {
17
- defineBehavior,
18
- type BehaviorEvent,
19
- type Behavior,
20
- type BehaviorActionIntend,
21
- type BehaviorActionIntendSet,
22
- type SyntheticBehaviorEvent,
23
- type BehaviorGuard,
24
- type BlockOffset,
25
- type NativeBehaviorEvent,
26
- type OmitFromUnion,
27
- type PickFromUnion,
28
- } from './editor/behavior/behavior.types'
3
+ export type {
4
+ Behavior,
5
+ BehaviorActionIntend,
6
+ BehaviorActionIntendSet,
7
+ BehaviorEvent,
8
+ BehaviorGuard,
9
+ BlockOffset,
10
+ NativeBehaviorEvent,
11
+ SyntheticBehaviorEvent,
12
+ } from './behaviors/index'
29
13
  export type {Editor, EditorConfig, EditorEvent} from './editor/create-editor'
30
14
  export type {SlateEditor} from './editor/create-slate-editor'
31
15
  export {
@@ -33,6 +17,8 @@ export {
33
17
  type BaseDefinition,
34
18
  type SchemaDefinition,
35
19
  } from './editor/define-schema'
20
+ export type {PortableTextMemberSchemaTypes} from './types/editor'
21
+ export type {EditorSchema} from './editor/define-schema'
36
22
  export {PortableTextEditable} from './editor/Editable'
37
23
  export type {PortableTextEditableProps} from './editor/Editable'
38
24
  export {EditorEventListener} from './editor/editor-event-listener'
@@ -51,11 +37,7 @@ export {
51
37
  useEditor,
52
38
  type EditorProviderProps,
53
39
  } from './editor/editor-provider'
54
- export {
55
- useEditorSelector,
56
- type EditorSelector,
57
- type EditorSelectorSnapshot,
58
- } from './editor/editor-selector'
40
+ export {useEditorSelector, type EditorSelector} from './editor/editor-selector'
59
41
  export type {EditorContext, EditorSnapshot} from './editor/editor-snapshot'
60
42
  export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
61
43
  export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
@@ -63,5 +45,6 @@ export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
63
45
  export type {AddedAnnotationPaths} from './editor/plugins/createWithEditableAPI'
64
46
  export {PortableTextEditor} from './editor/PortableTextEditor'
65
47
  export type {PortableTextEditorProps} from './editor/PortableTextEditor'
48
+ export type {OmitFromUnion, PickFromUnion} from './type-utils'
66
49
  export * from './types/editor'
67
50
  export type {HotkeyOptions} from './types/options'
@@ -1,7 +1,4 @@
1
- export type {
2
- EditorSelector,
3
- EditorSelectorSnapshot,
4
- } from '../editor/editor-selector'
1
+ export type {EditorSelector} from '../editor/editor-selector'
5
2
  export type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
6
3
  export type {
7
4
  EditorSelection,
@@ -13,3 +10,4 @@ export {getActiveListItem} from './selector.get-active-list-item'
13
10
  export {getSelectionText} from './selector.get-selection-text'
14
11
  export {getBlockTextBefore} from './selector.get-text-before'
15
12
  export * from './selectors'
13
+ export type {EditorSchema} from '../editor/define-schema'
@@ -1,5 +1,5 @@
1
1
  import type {PortableTextListBlock} from '@sanity/types'
2
- import {createGuards} from '../editor/behavior/behavior.guards'
2
+ import {createGuards} from '../behavior-actions/behavior.guards'
3
3
  import type {EditorSelector} from '../editor/editor-selector'
4
4
  import {getSelectedBlocks} from './selectors'
5
5
 
@@ -9,7 +9,7 @@ import {
9
9
  type PortableTextSpan,
10
10
  type PortableTextTextBlock,
11
11
  } from '@sanity/types'
12
- import {createGuards} from '../editor/behavior/behavior.guards'
12
+ import {createGuards} from '../behavior-actions/behavior.guards'
13
13
  import type {EditorSelector} from '../editor/editor-selector'
14
14
 
15
15
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @alpha
3
+ */
4
+ export type PickFromUnion<
5
+ TUnion,
6
+ TTagKey extends keyof TUnion,
7
+ TPickedTags extends TUnion[TTagKey],
8
+ > = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
9
+
10
+ /**
11
+ * @alpha
12
+ */
13
+ export type OmitFromUnion<
14
+ TUnion,
15
+ TTagKey extends keyof TUnion,
16
+ TOmittedTags extends TUnion[TTagKey],
17
+ > = TUnion extends Record<TTagKey, TOmittedTags> ? never : TUnion
@@ -2,15 +2,15 @@ import type {PortableTextTextBlock} from '@sanity/types'
2
2
  import {createEditor, type Descendant} from 'slate'
3
3
  import {beforeEach, describe, expect, it} from 'vitest'
4
4
  import {createActor} from 'xstate'
5
+ import {coreBehaviors} from '../../behaviors/behavior.core'
5
6
  import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
6
- import {coreBehaviors} from '../../editor/behavior/behavior.core'
7
+ import {createEditorSchema} from '../../editor/create-editor-schema'
7
8
  import {editorMachine} from '../../editor/editor-machine'
8
9
  import {defaultKeyGenerator} from '../../editor/key-generator'
9
10
  import {withPlugins} from '../../editor/plugins/with-plugins'
10
- import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes'
11
11
  import {createOperationToPatches} from '../operationToPatches'
12
12
 
13
- const schemaTypes = getPortableTextMemberSchemaTypes(schemaType)
13
+ const schemaTypes = createEditorSchema(schemaType)
14
14
 
15
15
  const operationToPatches = createOperationToPatches(schemaTypes)
16
16
 
@@ -2,16 +2,16 @@ import type {Patch} from '@portabletext/patches'
2
2
  import {createEditor, type Descendant} from 'slate'
3
3
  import {beforeEach, describe, expect, it} from 'vitest'
4
4
  import {createActor} from 'xstate'
5
+ import {coreBehaviors} from '../../behaviors/behavior.core'
5
6
  import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
6
- import {coreBehaviors} from '../../editor/behavior/behavior.core'
7
+ import {createEditorSchema} from '../../editor/create-editor-schema'
7
8
  import {editorMachine} from '../../editor/editor-machine'
8
9
  import {defaultKeyGenerator} from '../../editor/key-generator'
9
10
  import {withPlugins} from '../../editor/plugins/with-plugins'
10
11
  import {createApplyPatch} from '../applyPatch'
11
- import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes'
12
12
  import {VOID_CHILD_KEY} from '../values'
13
13
 
14
- const schemaTypes = getPortableTextMemberSchemaTypes(schemaType)
14
+ const schemaTypes = createEditorSchema(schemaType)
15
15
 
16
16
  const patchToOperations = createApplyPatch(schemaTypes)
17
17
 
@@ -1,9 +1,9 @@
1
1
  import {describe, expect, it} from 'vitest'
2
2
  import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
3
- import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes'
3
+ import {createEditorSchema} from '../../editor/create-editor-schema'
4
4
  import {fromSlateValue, toSlateValue} from '../values'
5
5
 
6
- const schemaTypes = getPortableTextMemberSchemaTypes(schemaType)
6
+ const schemaTypes = createEditorSchema(schemaType)
7
7
 
8
8
  describe('toSlateValue', () => {
9
9
  it('checks undefined', () => {