@portabletext/editor 3.3.2 → 3.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 (307) hide show
  1. package/lib/_chunks-dts/index.d.ts +7 -1
  2. package/package.json +16 -19
  3. package/src/behaviors/_exports/index.ts +0 -1
  4. package/src/behaviors/behavior.abstract.annotation.ts +0 -77
  5. package/src/behaviors/behavior.abstract.decorator.ts +0 -39
  6. package/src/behaviors/behavior.abstract.delete.ts +0 -273
  7. package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
  8. package/src/behaviors/behavior.abstract.insert.ts +0 -525
  9. package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
  10. package/src/behaviors/behavior.abstract.list-item.ts +0 -70
  11. package/src/behaviors/behavior.abstract.move.ts +0 -79
  12. package/src/behaviors/behavior.abstract.select.ts +0 -118
  13. package/src/behaviors/behavior.abstract.serialize.ts +0 -96
  14. package/src/behaviors/behavior.abstract.split.ts +0 -170
  15. package/src/behaviors/behavior.abstract.style.ts +0 -55
  16. package/src/behaviors/behavior.abstract.ts +0 -139
  17. package/src/behaviors/behavior.config.ts +0 -7
  18. package/src/behaviors/behavior.core.annotations.ts +0 -62
  19. package/src/behaviors/behavior.core.block-element.ts +0 -116
  20. package/src/behaviors/behavior.core.block-objects.ts +0 -285
  21. package/src/behaviors/behavior.core.decorators.ts +0 -44
  22. package/src/behaviors/behavior.core.dnd.ts +0 -356
  23. package/src/behaviors/behavior.core.insert-break.ts +0 -266
  24. package/src/behaviors/behavior.core.insert.ts +0 -52
  25. package/src/behaviors/behavior.core.lists.ts +0 -691
  26. package/src/behaviors/behavior.core.ts +0 -44
  27. package/src/behaviors/behavior.perform-event.ts +0 -354
  28. package/src/behaviors/behavior.types.action.ts +0 -102
  29. package/src/behaviors/behavior.types.behavior.ts +0 -83
  30. package/src/behaviors/behavior.types.event.ts +0 -667
  31. package/src/behaviors/behavior.types.guard.ts +0 -11
  32. package/src/behaviors/index.ts +0 -17
  33. package/src/converters/converter.json.ts +0 -53
  34. package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
  35. package/src/converters/converter.portable-text.ts +0 -75
  36. package/src/converters/converter.text-html.deserialize.test.ts +0 -406
  37. package/src/converters/converter.text-html.serialize.test.ts +0 -246
  38. package/src/converters/converter.text-html.ts +0 -87
  39. package/src/converters/converter.text-markdown.ts +0 -67
  40. package/src/converters/converter.text-plain.test.ts +0 -245
  41. package/src/converters/converter.text-plain.ts +0 -126
  42. package/src/converters/converter.types.ts +0 -72
  43. package/src/converters/converters.core.ts +0 -18
  44. package/src/editor/Editable.tsx +0 -1012
  45. package/src/editor/PortableTextEditor.tsx +0 -791
  46. package/src/editor/components/drop-indicator.tsx +0 -17
  47. package/src/editor/components/render-block-object.tsx +0 -121
  48. package/src/editor/components/render-default-object.tsx +0 -21
  49. package/src/editor/components/render-element.tsx +0 -88
  50. package/src/editor/components/render-inline-object.tsx +0 -129
  51. package/src/editor/components/render-leaf.tsx +0 -64
  52. package/src/editor/components/render-span.tsx +0 -303
  53. package/src/editor/components/render-text-block.tsx +0 -265
  54. package/src/editor/components/render-text.tsx +0 -18
  55. package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
  56. package/src/editor/create-editor.ts +0 -323
  57. package/src/editor/create-slate-editor.tsx +0 -64
  58. package/src/editor/editor-actor-context.ts +0 -4
  59. package/src/editor/editor-context.tsx +0 -7
  60. package/src/editor/editor-dom.ts +0 -220
  61. package/src/editor/editor-machine.ts +0 -751
  62. package/src/editor/editor-provider.tsx +0 -111
  63. package/src/editor/editor-schema.ts +0 -6
  64. package/src/editor/editor-selector.ts +0 -89
  65. package/src/editor/editor-snapshot.ts +0 -68
  66. package/src/editor/event-to-change.tsx +0 -49
  67. package/src/editor/hooks/usePortableTextEditor.ts +0 -25
  68. package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
  69. package/src/editor/mutation-machine.ts +0 -322
  70. package/src/editor/plugins/create-with-event-listeners.ts +0 -271
  71. package/src/editor/plugins/createWithEditableAPI.ts +0 -529
  72. package/src/editor/plugins/createWithHotKeys.ts +0 -68
  73. package/src/editor/plugins/createWithObjectKeys.ts +0 -289
  74. package/src/editor/plugins/createWithPatches.ts +0 -272
  75. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
  76. package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
  77. package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
  78. package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
  79. package/src/editor/plugins/with-plugins.ts +0 -69
  80. package/src/editor/range-decorations-machine.ts +0 -421
  81. package/src/editor/relay-actor-context.ts +0 -4
  82. package/src/editor/relay-machine.ts +0 -152
  83. package/src/editor/sync-machine.ts +0 -961
  84. package/src/editor/use-editor.ts +0 -27
  85. package/src/editor/validate-selection-machine.test.ts +0 -47
  86. package/src/editor/validate-selection-machine.ts +0 -149
  87. package/src/editor/weakMaps.ts +0 -15
  88. package/src/editor/with-normalizing-node.ts +0 -14
  89. package/src/editor/with-performing-behavior-operation.ts +0 -21
  90. package/src/editor/withChanges.ts +0 -13
  91. package/src/editor/without-normalizing-conditional.ts +0 -13
  92. package/src/editor/withoutPatching.ts +0 -14
  93. package/src/editor.ts +0 -59
  94. package/src/history/behavior.operation.history.redo.ts +0 -67
  95. package/src/history/behavior.operation.history.undo.ts +0 -71
  96. package/src/history/event.history.undo.test.tsx +0 -672
  97. package/src/history/history.preserving-keys.test.tsx +0 -112
  98. package/src/history/remote-patches.ts +0 -20
  99. package/src/history/slate-plugin.history.ts +0 -142
  100. package/src/history/slate-plugin.redoing.ts +0 -21
  101. package/src/history/slate-plugin.undoing.ts +0 -21
  102. package/src/history/slate-plugin.without-history.ts +0 -23
  103. package/src/history/transform-operation.ts +0 -245
  104. package/src/history/undo-redo-collaboration.test.tsx +0 -541
  105. package/src/history/undo-redo.feature +0 -125
  106. package/src/history/undo-redo.test.tsx +0 -195
  107. package/src/history/undo-step.ts +0 -148
  108. package/src/index.ts +0 -98
  109. package/src/internal-utils/__tests__/ranges.test.ts +0 -23
  110. package/src/internal-utils/__tests__/values.test.ts +0 -110
  111. package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
  112. package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
  113. package/src/internal-utils/applyPatch.ts +0 -644
  114. package/src/internal-utils/block-keys.ts +0 -9
  115. package/src/internal-utils/build-index-maps.test.ts +0 -464
  116. package/src/internal-utils/build-index-maps.ts +0 -131
  117. package/src/internal-utils/collapse-selection.ts +0 -36
  118. package/src/internal-utils/compound-client-rect.ts +0 -28
  119. package/src/internal-utils/create-placeholder-block.ts +0 -21
  120. package/src/internal-utils/create-test-snapshot.ts +0 -28
  121. package/src/internal-utils/debug.ts +0 -12
  122. package/src/internal-utils/editor-selection.test.ts +0 -44
  123. package/src/internal-utils/editor-selection.ts +0 -56
  124. package/src/internal-utils/event-position.ts +0 -318
  125. package/src/internal-utils/global-scope.ts +0 -27
  126. package/src/internal-utils/globally-scoped-context.ts +0 -39
  127. package/src/internal-utils/is-hotkey.test.ts +0 -114
  128. package/src/internal-utils/is-hotkey.ts +0 -209
  129. package/src/internal-utils/mime-type.ts +0 -1
  130. package/src/internal-utils/move-range-by-operation.ts +0 -19
  131. package/src/internal-utils/operation-to-patches.test.ts +0 -522
  132. package/src/internal-utils/operation-to-patches.ts +0 -571
  133. package/src/internal-utils/portable-text-node.ts +0 -209
  134. package/src/internal-utils/schema.ts +0 -8
  135. package/src/internal-utils/selection-block-keys.ts +0 -20
  136. package/src/internal-utils/selection-focus-text.ts +0 -40
  137. package/src/internal-utils/selection-text.test.ts +0 -32
  138. package/src/internal-utils/selection-text.ts +0 -21
  139. package/src/internal-utils/selection.ts +0 -77
  140. package/src/internal-utils/sibling-utils.ts +0 -55
  141. package/src/internal-utils/slate-utils.test.tsx +0 -121
  142. package/src/internal-utils/slate-utils.ts +0 -417
  143. package/src/internal-utils/split-string.ts +0 -12
  144. package/src/internal-utils/stop-actor.ts +0 -43
  145. package/src/internal-utils/string-overlap.test.ts +0 -14
  146. package/src/internal-utils/string-overlap.ts +0 -28
  147. package/src/internal-utils/string-utils.ts +0 -7
  148. package/src/internal-utils/text-block-key.test.ts +0 -41
  149. package/src/internal-utils/text-block-key.ts +0 -26
  150. package/src/internal-utils/text-marks.test.ts +0 -41
  151. package/src/internal-utils/text-marks.ts +0 -22
  152. package/src/internal-utils/text-selection.test.ts +0 -211
  153. package/src/internal-utils/text-selection.ts +0 -121
  154. package/src/internal-utils/to-slate-range.test.ts +0 -278
  155. package/src/internal-utils/to-slate-range.ts +0 -171
  156. package/src/internal-utils/validateValue.ts +0 -443
  157. package/src/internal-utils/value-annotations.ts +0 -33
  158. package/src/internal-utils/values.test.ts +0 -282
  159. package/src/internal-utils/values.ts +0 -266
  160. package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
  161. package/src/operations/behavior.operation.annotation.add.ts +0 -99
  162. package/src/operations/behavior.operation.annotation.remove.ts +0 -150
  163. package/src/operations/behavior.operation.block.set.ts +0 -104
  164. package/src/operations/behavior.operation.block.unset.ts +0 -54
  165. package/src/operations/behavior.operation.child.set.ts +0 -107
  166. package/src/operations/behavior.operation.child.unset.ts +0 -116
  167. package/src/operations/behavior.operation.decorator.add.ts +0 -131
  168. package/src/operations/behavior.operation.delete.ts +0 -294
  169. package/src/operations/behavior.operation.insert.block.ts +0 -495
  170. package/src/operations/behavior.operation.insert.child.ts +0 -129
  171. package/src/operations/behavior.operation.insert.text.ts +0 -8
  172. package/src/operations/behavior.operation.move.backward.ts +0 -12
  173. package/src/operations/behavior.operation.move.block.ts +0 -44
  174. package/src/operations/behavior.operation.move.forward.ts +0 -11
  175. package/src/operations/behavior.operation.select.ts +0 -27
  176. package/src/operations/behavior.operations.ts +0 -221
  177. package/src/plugins/_exports/index.ts +0 -1
  178. package/src/plugins/index.ts +0 -3
  179. package/src/plugins/plugin.behavior.tsx +0 -24
  180. package/src/plugins/plugin.editor-ref.tsx +0 -17
  181. package/src/plugins/plugin.event-listener.tsx +0 -68
  182. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
  183. package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
  184. package/src/plugins/plugin.internal.change-ref.tsx +0 -19
  185. package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
  186. package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
  187. package/src/priority/priority.core.ts +0 -3
  188. package/src/priority/priority.sort.test.ts +0 -319
  189. package/src/priority/priority.sort.ts +0 -123
  190. package/src/priority/priority.types.ts +0 -24
  191. package/src/selectors/_exports/index.ts +0 -1
  192. package/src/selectors/drag-selection.test.ts +0 -578
  193. package/src/selectors/drag-selection.ts +0 -118
  194. package/src/selectors/index.ts +0 -54
  195. package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
  196. package/src/selectors/selector.get-active-annotations.ts +0 -36
  197. package/src/selectors/selector.get-active-decorators.ts +0 -29
  198. package/src/selectors/selector.get-active-list-item.ts +0 -38
  199. package/src/selectors/selector.get-active-style.ts +0 -38
  200. package/src/selectors/selector.get-anchor-block.ts +0 -22
  201. package/src/selectors/selector.get-anchor-child.ts +0 -36
  202. package/src/selectors/selector.get-anchor-span.ts +0 -17
  203. package/src/selectors/selector.get-anchor-text-block.ts +0 -18
  204. package/src/selectors/selector.get-block-offsets.ts +0 -34
  205. package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
  206. package/src/selectors/selector.get-caret-word-selection.ts +0 -134
  207. package/src/selectors/selector.get-first-block.ts +0 -14
  208. package/src/selectors/selector.get-focus-block-object.ts +0 -18
  209. package/src/selectors/selector.get-focus-block.ts +0 -23
  210. package/src/selectors/selector.get-focus-child.ts +0 -36
  211. package/src/selectors/selector.get-focus-inline-object.ts +0 -17
  212. package/src/selectors/selector.get-focus-list-block.ts +0 -18
  213. package/src/selectors/selector.get-focus-span.ts +0 -18
  214. package/src/selectors/selector.get-focus-text-block.ts +0 -18
  215. package/src/selectors/selector.get-last-block.ts +0 -16
  216. package/src/selectors/selector.get-mark-state.test.ts +0 -325
  217. package/src/selectors/selector.get-mark-state.ts +0 -263
  218. package/src/selectors/selector.get-next-block.ts +0 -29
  219. package/src/selectors/selector.get-next-inline-object.ts +0 -53
  220. package/src/selectors/selector.get-next-inline-objects.ts +0 -50
  221. package/src/selectors/selector.get-next-span.ts +0 -56
  222. package/src/selectors/selector.get-previous-block.ts +0 -29
  223. package/src/selectors/selector.get-previous-inline-object.ts +0 -50
  224. package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
  225. package/src/selectors/selector.get-previous-span.ts +0 -53
  226. package/src/selectors/selector.get-selected-blocks.ts +0 -61
  227. package/src/selectors/selector.get-selected-spans.test.ts +0 -347
  228. package/src/selectors/selector.get-selected-spans.ts +0 -155
  229. package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
  230. package/src/selectors/selector.get-selected-value.test.ts +0 -834
  231. package/src/selectors/selector.get-selected-value.ts +0 -66
  232. package/src/selectors/selector.get-selection-end-block.ts +0 -33
  233. package/src/selectors/selector.get-selection-end-child.ts +0 -33
  234. package/src/selectors/selector.get-selection-end-point.ts +0 -17
  235. package/src/selectors/selector.get-selection-start-block.ts +0 -33
  236. package/src/selectors/selector.get-selection-start-child.ts +0 -33
  237. package/src/selectors/selector.get-selection-start-point.ts +0 -17
  238. package/src/selectors/selector.get-selection-text.test.ts +0 -421
  239. package/src/selectors/selector.get-selection-text.ts +0 -27
  240. package/src/selectors/selector.get-selection.ts +0 -9
  241. package/src/selectors/selector.get-text-after.ts +0 -46
  242. package/src/selectors/selector.get-text-before.ts +0 -46
  243. package/src/selectors/selector.get-value.ts +0 -11
  244. package/src/selectors/selector.is-active-annotation.test.ts +0 -320
  245. package/src/selectors/selector.is-active-annotation.ts +0 -52
  246. package/src/selectors/selector.is-active-decorator.test.ts +0 -136
  247. package/src/selectors/selector.is-active-decorator.ts +0 -24
  248. package/src/selectors/selector.is-active-list-item.ts +0 -13
  249. package/src/selectors/selector.is-active-style.ts +0 -13
  250. package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
  251. package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
  252. package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
  253. package/src/selectors/selector.is-overlapping-selection.ts +0 -181
  254. package/src/selectors/selector.is-point-after-selection.ts +0 -97
  255. package/src/selectors/selector.is-point-before-selection.ts +0 -97
  256. package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
  257. package/src/selectors/selector.is-selection-collapsed.ts +0 -17
  258. package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
  259. package/src/selectors/selector.is-selection-expanded.ts +0 -9
  260. package/src/test/_exports/index.ts +0 -1
  261. package/src/test/gherkin-parameter-types.ts +0 -112
  262. package/src/test/index.ts +0 -1
  263. package/src/test/vitest/_exports/index.ts +0 -1
  264. package/src/test/vitest/index.ts +0 -3
  265. package/src/test/vitest/step-context.ts +0 -13
  266. package/src/test/vitest/step-definitions.tsx +0 -960
  267. package/src/test/vitest/test-editor.tsx +0 -198
  268. package/src/type-utils.ts +0 -29
  269. package/src/types/block-offset.ts +0 -9
  270. package/src/types/block-with-optional-key.ts +0 -25
  271. package/src/types/editor.ts +0 -509
  272. package/src/types/options.ts +0 -13
  273. package/src/types/paths.ts +0 -35
  274. package/src/types/slate-editor.ts +0 -50
  275. package/src/types/slate.ts +0 -27
  276. package/src/utils/_exports/index.ts +0 -1
  277. package/src/utils/asserters.ts +0 -9
  278. package/src/utils/index.ts +0 -24
  279. package/src/utils/key-generator.ts +0 -33
  280. package/src/utils/parse-blocks.test.ts +0 -836
  281. package/src/utils/parse-blocks.ts +0 -504
  282. package/src/utils/util.at-the-beginning-of-block.ts +0 -32
  283. package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
  284. package/src/utils/util.block-offset-to-selection-point.ts +0 -33
  285. package/src/utils/util.block-offset.test.ts +0 -375
  286. package/src/utils/util.block-offset.ts +0 -136
  287. package/src/utils/util.block-offsets-to-selection.ts +0 -38
  288. package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
  289. package/src/utils/util.get-block-end-point.ts +0 -35
  290. package/src/utils/util.get-block-start-point.ts +0 -31
  291. package/src/utils/util.get-selection-end-point.ts +0 -20
  292. package/src/utils/util.get-selection-start-point.ts +0 -20
  293. package/src/utils/util.get-text-block-text.ts +0 -8
  294. package/src/utils/util.is-empty-text-block.ts +0 -21
  295. package/src/utils/util.is-equal-selection-points.ts +0 -13
  296. package/src/utils/util.is-equal-selections.ts +0 -20
  297. package/src/utils/util.is-keyed-segment.ts +0 -8
  298. package/src/utils/util.is-selection-collapsed.ts +0 -16
  299. package/src/utils/util.is-selection-expanded.ts +0 -13
  300. package/src/utils/util.merge-text-blocks.ts +0 -40
  301. package/src/utils/util.reverse-selection.ts +0 -26
  302. package/src/utils/util.selection-point-to-block-offset.ts +0 -30
  303. package/src/utils/util.selection-point.ts +0 -22
  304. package/src/utils/util.slice-blocks.ts +0 -221
  305. package/src/utils/util.slice-text-block.test.ts +0 -190
  306. package/src/utils/util.slice-text-block.ts +0 -89
  307. package/src/utils/util.split-text-block.ts +0 -54
@@ -1,509 +0,0 @@
1
- import type {Patch} from '@portabletext/patches'
2
- import type {
3
- ArraySchemaType,
4
- BlockDecoratorDefinition,
5
- BlockListDefinition,
6
- BlockStyleDefinition,
7
- ObjectSchemaType,
8
- Path,
9
- PortableTextBlock,
10
- PortableTextChild,
11
- PortableTextObject,
12
- PortableTextTextBlock,
13
- TypedObject,
14
- } from '@sanity/types'
15
- import type {
16
- ClipboardEvent,
17
- FocusEvent,
18
- JSX,
19
- PropsWithChildren,
20
- ReactElement,
21
- RefObject,
22
- } from 'react'
23
- import type {Observable, Subject} from 'rxjs'
24
- import type {PortableTextEditableProps} from '../editor/Editable'
25
- import type {PortableTextEditor} from '../editor/PortableTextEditor'
26
- import type {BlockPath} from './paths'
27
-
28
- /** @beta */
29
- export interface EditableAPIDeleteOptions {
30
- mode?: 'blocks' | 'children' | 'selected'
31
- }
32
-
33
- /**
34
- * @public
35
- */
36
- export type AddedAnnotationPaths = {
37
- /**
38
- * @deprecated An annotation may be applied to multiple blocks, resulting
39
- * in multiple `markDef`'s being created. Use `markDefPaths` instead.
40
- */
41
- markDefPath: Path
42
- markDefPaths: Array<Path>
43
- /**
44
- * @deprecated Does not return anything meaningful since an annotation
45
- * can span multiple blocks and spans. If references the span closest
46
- * to the focus point of the selection.
47
- */
48
- spanPath: Path
49
- }
50
-
51
- /** @beta */
52
- export interface EditableAPI {
53
- activeAnnotations: () => PortableTextObject[]
54
- isAnnotationActive: (annotationType: PortableTextObject['_type']) => boolean
55
- addAnnotation: <TSchemaType extends {name: string}>(
56
- type: TSchemaType,
57
- value?: {[prop: string]: unknown},
58
- ) => AddedAnnotationPaths | undefined
59
- blur: () => void
60
- delete: (
61
- selection: EditorSelection,
62
- options?: EditableAPIDeleteOptions,
63
- ) => void
64
- findByPath: (
65
- path: Path,
66
- ) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
67
- findDOMNode: (
68
- element: PortableTextBlock | PortableTextChild,
69
- ) => Node | undefined
70
- focus: () => void
71
- focusBlock: () => PortableTextBlock | undefined
72
- focusChild: () => PortableTextChild | undefined
73
- getSelection: () => EditorSelection
74
- getFragment: () => PortableTextBlock[] | undefined
75
- getValue: () => PortableTextBlock[] | undefined
76
- hasBlockStyle: (style: string) => boolean
77
- hasListStyle: (listStyle: string) => boolean
78
- insertBlock: <TSchemaType extends {name: string}>(
79
- type: TSchemaType,
80
- value?: {[prop: string]: unknown},
81
- ) => Path
82
- insertChild: <TSchemaType extends {name: string}>(
83
- type: TSchemaType,
84
- value?: {[prop: string]: unknown},
85
- ) => Path
86
- insertBreak: () => void
87
- isCollapsedSelection: () => boolean
88
- isExpandedSelection: () => boolean
89
- isMarkActive: (mark: string) => boolean
90
- isSelectionsOverlapping: (
91
- selectionA: EditorSelection,
92
- selectionB: EditorSelection,
93
- ) => boolean
94
- isVoid: (element: PortableTextBlock | PortableTextChild) => boolean
95
- marks: () => string[]
96
- redo: () => void
97
- removeAnnotation: <TSchemaType extends {name: string}>(
98
- type: TSchemaType,
99
- ) => void
100
- select: (selection: EditorSelection) => void
101
- toggleBlockStyle: (blockStyle: string) => void
102
- toggleList: (listStyle: string) => void
103
- toggleMark: (mark: string) => void
104
- undo: () => void
105
- }
106
-
107
- /** @public */
108
- export type EditorSelectionPoint = {path: Path; offset: number}
109
- /** @public */
110
- export type EditorSelection = {
111
- anchor: EditorSelectionPoint
112
- focus: EditorSelectionPoint
113
- backward?: boolean
114
- } | null
115
-
116
- /**
117
- * The editor has mutated it's content.
118
- * @beta */
119
- export type MutationChange = {
120
- type: 'mutation'
121
- patches: Patch[]
122
- snapshot: PortableTextBlock[] | undefined
123
- }
124
-
125
- /**
126
- * The editor has produced a patch
127
- * @beta */
128
- export type PatchChange = {
129
- type: 'patch'
130
- patch: Patch
131
- }
132
-
133
- /**
134
- * The editor has received a new (props) value
135
- * @beta */
136
- export type ValueChange = {
137
- type: 'value'
138
- value: PortableTextBlock[] | undefined
139
- }
140
-
141
- /**
142
- * The editor has a new selection
143
- * @beta */
144
- export type SelectionChange = {
145
- type: 'selection'
146
- selection: EditorSelection
147
- }
148
-
149
- /**
150
- * The editor received focus
151
- * @beta */
152
- export type FocusChange = {
153
- type: 'focus'
154
- event: FocusEvent<HTMLDivElement, Element>
155
- }
156
-
157
- /**
158
- * @beta
159
- * @deprecated Use `'patch'` changes instead
160
- */
161
- export type UnsetChange = {
162
- type: 'unset'
163
- previousValue: PortableTextBlock[]
164
- }
165
-
166
- /**
167
- * The editor blurred
168
- * @beta */
169
- export type BlurChange = {
170
- type: 'blur'
171
- event: FocusEvent<HTMLDivElement, Element>
172
- }
173
-
174
- /**
175
- * The editor is currently loading something
176
- * Could be used to show a spinner etc.
177
- * @beta
178
- * @deprecated Will be removed in the next major version
179
- */
180
- export type LoadingChange = {
181
- type: 'loading'
182
- isLoading: boolean
183
- }
184
-
185
- /**
186
- * The editor content is ready to be edited by the user
187
- * @beta */
188
- export type ReadyChange = {
189
- type: 'ready'
190
- }
191
-
192
- /**
193
- * The editor produced an error
194
- * @beta
195
- * @deprecated The change is no longer emitted
196
- * */
197
- export type ErrorChange = {
198
- type: 'error'
199
- name: string // short computer readable name
200
- level: 'warning' | 'error'
201
- description: string
202
- data?: unknown
203
- }
204
-
205
- /**
206
- * The editor has invalid data in the value that can be resolved by the user
207
- * @beta */
208
- export type InvalidValueResolution = {
209
- autoResolve?: boolean
210
- patches: Patch[]
211
- description: string
212
- action: string
213
- item: PortableTextBlock[] | PortableTextBlock | PortableTextChild | undefined
214
-
215
- /**
216
- * i18n keys for the description and action
217
- *
218
- * These are in addition to the description and action properties, to decouple the editor from
219
- * the i18n system, and allow usage without it. The i18n keys take precedence over the
220
- * description and action properties, if i18n framework is available.
221
- */
222
- i18n: {
223
- description: `inputs.portable-text.invalid-value.${Lowercase<string>}.description`
224
- action: `inputs.portable-text.invalid-value.${Lowercase<string>}.action`
225
- values?: Record<string, string | number | string[]>
226
- }
227
- }
228
-
229
- /**
230
- * The editor has an invalid value
231
- * @beta */
232
- export type InvalidValue = {
233
- type: 'invalidValue'
234
- resolution: InvalidValueResolution | null
235
- value: PortableTextBlock[] | undefined
236
- }
237
-
238
- /**
239
- * The editor performed a undo history step
240
- * @beta
241
- * @deprecated The change is no longer emitted
242
- * */
243
- export type UndoChange = {
244
- type: 'undo'
245
- patches: Patch[]
246
- timestamp: Date
247
- }
248
-
249
- /**
250
- * The editor performed redo history step
251
- * @beta
252
- * @deprecated The change is no longer emitted
253
- * */
254
- export type RedoChange = {
255
- type: 'redo'
256
- patches: Patch[]
257
- timestamp: Date
258
- }
259
-
260
- /**
261
- * The editor was either connected or disconnected to the network
262
- * To show out of sync warnings etc when in collaborative mode.
263
- * @beta
264
- * @deprecated The change is no longer emitted
265
- * */
266
- export type ConnectionChange = {
267
- type: 'connection'
268
- value: 'online' | 'offline'
269
- }
270
-
271
- /**
272
- * When the editor changes, it will emit a change item describing the change
273
- * @beta */
274
- export type EditorChange =
275
- | BlurChange
276
- | ConnectionChange
277
- | ErrorChange
278
- | FocusChange
279
- | InvalidValue
280
- | LoadingChange
281
- | MutationChange
282
- | PatchChange
283
- | ReadyChange
284
- | RedoChange
285
- | SelectionChange
286
- | UndoChange
287
- | UnsetChange
288
- | ValueChange
289
-
290
- /**
291
- * @beta
292
- */
293
- export type EditorChanges = Subject<EditorChange>
294
-
295
- /** @beta */
296
- export type OnPasteResult =
297
- | {
298
- insert?: TypedObject[]
299
- path?: Path
300
- }
301
- | undefined
302
-
303
- /**
304
- * @beta
305
- */
306
- export type OnPasteResultOrPromise = OnPasteResult | Promise<OnPasteResult>
307
-
308
- /** @beta */
309
- export interface PasteData {
310
- event: ClipboardEvent
311
- path: Path
312
- schemaTypes: PortableTextMemberSchemaTypes
313
- value: PortableTextBlock[] | undefined
314
- }
315
-
316
- /**
317
- * @beta
318
- * It is encouraged not to return `Promise<undefined>` from the `OnPasteFn` as
319
- * a mechanism to fall back to the native paste behaviour. This doesn't work in
320
- * all cases. Always return plain `undefined` if possible.
321
- **/
322
- export type OnPasteFn = (data: PasteData) => OnPasteResultOrPromise
323
-
324
- /** @beta */
325
- export type OnBeforeInputFn = (event: InputEvent) => void
326
-
327
- /** @beta */
328
- export type OnCopyFn = (
329
- event: ClipboardEvent<HTMLDivElement | HTMLSpanElement>,
330
- ) => undefined | unknown
331
-
332
- /** @beta */
333
- export type PatchObservable = Observable<{
334
- patches: Patch[]
335
- snapshot: PortableTextBlock[] | undefined
336
- }>
337
-
338
- /** @beta */
339
- export interface BlockRenderProps {
340
- children: ReactElement<any>
341
- editorElementRef: RefObject<HTMLElement | null>
342
- focused: boolean
343
- level?: number
344
- listItem?: string
345
- path: BlockPath
346
- selected: boolean
347
- style?: string
348
- schemaType: ObjectSchemaType
349
- /** @deprecated Use `schemaType` instead */
350
- type: ObjectSchemaType
351
- value: PortableTextBlock
352
- }
353
-
354
- /** @beta */
355
- export interface BlockChildRenderProps {
356
- annotations: PortableTextObject[]
357
- children: ReactElement<any>
358
- editorElementRef: RefObject<HTMLElement | null>
359
- focused: boolean
360
- path: Path
361
- selected: boolean
362
- schemaType: ObjectSchemaType
363
- /** @deprecated Use `schemaType` instead */
364
- type: ObjectSchemaType
365
- value: PortableTextChild
366
- }
367
-
368
- /** @beta */
369
- export interface BlockAnnotationRenderProps {
370
- block: PortableTextBlock
371
- children: ReactElement<any>
372
- editorElementRef: RefObject<HTMLElement | null>
373
- focused: boolean
374
- path: Path
375
- schemaType: ObjectSchemaType
376
- selected: boolean
377
- /** @deprecated Use `schemaType` instead */
378
- type: ObjectSchemaType
379
- value: PortableTextObject
380
- }
381
- /** @beta */
382
- export interface BlockDecoratorRenderProps {
383
- children: ReactElement<any>
384
- editorElementRef: RefObject<HTMLElement | null>
385
- focused: boolean
386
- path: Path
387
- schemaType: BlockDecoratorDefinition
388
- selected: boolean
389
- /** @deprecated Use `schemaType` instead */
390
- type: BlockDecoratorDefinition
391
- value: string
392
- }
393
- /** @beta */
394
- export interface BlockListItemRenderProps {
395
- block: PortableTextTextBlock
396
- children: ReactElement<any>
397
- editorElementRef: RefObject<HTMLElement | null>
398
- focused: boolean
399
- level: number
400
- path: Path
401
- schemaType: BlockListDefinition
402
- selected: boolean
403
- value: string
404
- }
405
-
406
- /** @beta */
407
- export type RenderBlockFunction = (props: BlockRenderProps) => JSX.Element
408
-
409
- /** @beta */
410
- export type RenderChildFunction = (props: BlockChildRenderProps) => JSX.Element
411
-
412
- /** @beta */
413
- export type RenderEditableFunction = (
414
- props: PortableTextEditableProps,
415
- ) => JSX.Element
416
-
417
- /** @beta */
418
- export type RenderAnnotationFunction = (
419
- props: BlockAnnotationRenderProps,
420
- ) => JSX.Element
421
-
422
- /** @beta */
423
- export type RenderPlaceholderFunction = () => React.ReactNode
424
-
425
- /** @beta */
426
- export type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element
427
-
428
- /** @beta */
429
- export interface BlockStyleRenderProps {
430
- block: PortableTextTextBlock
431
- children: ReactElement<any>
432
- editorElementRef: RefObject<HTMLElement | null>
433
- focused: boolean
434
- path: Path
435
- selected: boolean
436
- schemaType: BlockStyleDefinition
437
- value: string
438
- }
439
-
440
- /** @beta */
441
- export type RenderListItemFunction = (
442
- props: BlockListItemRenderProps,
443
- ) => JSX.Element
444
-
445
- /** @beta */
446
- export type RenderDecoratorFunction = (
447
- props: BlockDecoratorRenderProps,
448
- ) => JSX.Element
449
-
450
- /** @beta */
451
- export type ScrollSelectionIntoViewFunction = (
452
- editor: PortableTextEditor,
453
- domRange: globalThis.Range,
454
- ) => void
455
-
456
- /**
457
- * Parameters for the callback that will be called for a RangeDecoration's onMoved.
458
- * @alpha */
459
- export interface RangeDecorationOnMovedDetails {
460
- rangeDecoration: RangeDecoration
461
- newSelection: EditorSelection
462
- origin: 'remote' | 'local'
463
- }
464
- /**
465
- * A range decoration is a UI affordance that wraps a given selection range in the editor
466
- * with a custom component. This can be used to highlight search results,
467
- * mark validation errors on specific words, draw user presence and similar.
468
- * @alpha */
469
- export interface RangeDecoration {
470
- /**
471
- * A component for rendering the range decoration.
472
- * The component will receive the children (text) of the range decoration as its children.
473
- *
474
- * @example
475
- * ```ts
476
- * (rangeComponentProps: PropsWithChildren) => (
477
- * <SearchResultHighlight>
478
- * {rangeComponentProps.children}
479
- * </SearchResultHighlight>
480
- * )
481
- * ```
482
- */
483
- component: (props: PropsWithChildren) => ReactElement<any>
484
- /**
485
- * The editor content selection range
486
- */
487
- selection: EditorSelection
488
- /**
489
- * A optional callback that will be called when the range decoration potentially moves according to user edits.
490
- */
491
- onMoved?: (details: RangeDecorationOnMovedDetails) => void
492
- /**
493
- * A custom payload that can be set on the range decoration
494
- */
495
- payload?: Record<string, unknown>
496
- }
497
-
498
- /** @beta */
499
- export type PortableTextMemberSchemaTypes = {
500
- annotations: (ObjectSchemaType & {i18nTitleKey?: string})[]
501
- block: ObjectSchemaType
502
- blockObjects: ObjectSchemaType[]
503
- decorators: BlockDecoratorDefinition[]
504
- inlineObjects: ObjectSchemaType[]
505
- portableText: ArraySchemaType<PortableTextBlock>
506
- span: ObjectSchemaType
507
- styles: BlockStyleDefinition[]
508
- lists: BlockListDefinition[]
509
- }
@@ -1,13 +0,0 @@
1
- import type {BaseSyntheticEvent} from 'react'
2
- import type {PortableTextEditor} from '../editor/PortableTextEditor'
3
-
4
- /**
5
- * @beta
6
- */
7
- export type HotkeyOptions = {
8
- marks?: Record<string, string>
9
- custom?: Record<
10
- string,
11
- (event: BaseSyntheticEvent, editor: PortableTextEditor) => void
12
- >
13
- }
@@ -1,35 +0,0 @@
1
- import type {Path} from '@sanity/types'
2
-
3
- /**
4
- * @public
5
- */
6
- export type BlockPath = [{_key: string}]
7
-
8
- /**
9
- * @public
10
- */
11
- export function isBlockPath(path: Path): path is BlockPath {
12
- const firstSegment = path.at(0)
13
-
14
- return (
15
- path.length === 1 &&
16
- firstSegment !== undefined &&
17
- isRecord(firstSegment) &&
18
- '_key' in firstSegment &&
19
- typeof firstSegment._key === 'string'
20
- )
21
- }
22
-
23
- function isRecord(value: unknown): value is Record<string, unknown> {
24
- return !!value && (typeof value === 'object' || typeof value === 'function')
25
- }
26
-
27
- /**
28
- * @public
29
- */
30
- export type AnnotationPath = [{_key: string}, 'markDefs', {_key: string}]
31
-
32
- /**
33
- * @public
34
- */
35
- export type ChildPath = [{_key: string}, 'children', {_key: string}]
@@ -1,50 +0,0 @@
1
- import type {
2
- PortableTextBlock,
3
- PortableTextListBlock,
4
- PortableTextSpan,
5
- PortableTextTextBlock,
6
- } from '@sanity/types'
7
- import type {KeyboardEvent} from 'react'
8
- import type {Descendant, Operation as SlateOperation} from 'slate'
9
- import type {ReactEditor} from 'slate-react'
10
- import type {DecoratedRange} from '../editor/range-decorations-machine'
11
-
12
- type HistoryItem = {
13
- operations: SlateOperation[]
14
- timestamp: Date
15
- }
16
-
17
- interface History {
18
- redos: HistoryItem[]
19
- undos: HistoryItem[]
20
- }
21
-
22
- export interface PortableTextSlateEditor extends ReactEditor {
23
- _key: 'editor'
24
- _type: 'editor'
25
- createPlaceholderBlock: () => Descendant
26
- history: History
27
- isTextBlock: (value: unknown) => value is PortableTextTextBlock
28
- isTextSpan: (value: unknown) => value is PortableTextSpan
29
- isListBlock: (value: unknown) => value is PortableTextListBlock
30
- value: Array<PortableTextBlock>
31
- decoratedRanges: Array<DecoratedRange>
32
- decoratorState: Record<string, boolean | undefined>
33
- blockIndexMap: Map<string, number>
34
- listIndexMap: Map<string, number>
35
-
36
- /**
37
- * Use hotkeys
38
- */
39
- pteWithHotKeys: (event: KeyboardEvent<HTMLDivElement>) => void
40
-
41
- /**
42
- * Undo
43
- */
44
- undo: () => void
45
-
46
- /**
47
- * Redo
48
- */
49
- redo: () => void
50
- }
@@ -1,27 +0,0 @@
1
- import type {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
2
- import type {BaseEditor, Descendant} from 'slate'
3
- import type {ReactEditor} from 'slate-react'
4
- import type {PortableTextSlateEditor} from './slate-editor'
5
-
6
- export interface VoidElement {
7
- _type: string
8
- _key: string
9
- children: Descendant[]
10
- __inline: boolean
11
- value: Record<string, unknown>
12
- }
13
-
14
- export interface SlateTextBlock extends Omit<
15
- PortableTextTextBlock,
16
- 'children'
17
- > {
18
- children: Descendant[]
19
- }
20
-
21
- declare module 'slate' {
22
- interface CustomTypes {
23
- Editor: BaseEditor & ReactEditor & PortableTextSlateEditor
24
- Element: SlateTextBlock | VoidElement
25
- Text: PortableTextSpan
26
- }
27
- }
@@ -1 +0,0 @@
1
- export * from '../index'
@@ -1,9 +0,0 @@
1
- import type {TypedObject} from '@sanity/types'
2
-
3
- export function isTypedObject(object: unknown): object is TypedObject {
4
- return isRecord(object) && typeof object._type === 'string'
5
- }
6
-
7
- export function isRecord(value: unknown): value is Record<string, unknown> {
8
- return !!value && (typeof value === 'object' || typeof value === 'function')
9
- }
@@ -1,24 +0,0 @@
1
- export {
2
- blockOffsetToSpanSelectionPoint,
3
- spanSelectionPointToBlockOffset,
4
- } from './util.block-offset'
5
- export {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'
6
- export {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'
7
- export {blockOffsetsToSelection} from './util.block-offsets-to-selection'
8
- export {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'
9
- export {getBlockEndPoint} from './util.get-block-end-point'
10
- export {getBlockStartPoint} from './util.get-block-start-point'
11
- export {getSelectionEndPoint} from './util.get-selection-end-point'
12
- export {getSelectionStartPoint} from './util.get-selection-start-point'
13
- export {getTextBlockText} from './util.get-text-block-text'
14
- export {isEmptyTextBlock} from './util.is-empty-text-block'
15
- export {isEqualSelectionPoints} from './util.is-equal-selection-points'
16
- export {isEqualSelections} from './util.is-equal-selections'
17
- export {isKeyedSegment} from './util.is-keyed-segment'
18
- export {isSelectionCollapsed} from './util.is-selection-collapsed'
19
- export {isSpan, isTextBlock} from '@portabletext/schema'
20
- export {mergeTextBlocks} from './util.merge-text-blocks'
21
- export {reverseSelection} from './util.reverse-selection'
22
- export {selectionPointToBlockOffset} from './util.selection-point-to-block-offset'
23
- export {sliceBlocks} from './util.slice-blocks'
24
- export {splitTextBlock} from './util.split-text-block'
@@ -1,33 +0,0 @@
1
- /**
2
- * @public
3
- */
4
- export const defaultKeyGenerator = (): string => randomKey(12)
5
-
6
- const getByteHexTable = (() => {
7
- let table: any[]
8
- return () => {
9
- if (table) {
10
- return table
11
- }
12
-
13
- table = []
14
- for (let i = 0; i < 256; ++i) {
15
- table[i] = (i + 0x100).toString(16).slice(1)
16
- }
17
- return table
18
- }
19
- })()
20
-
21
- // WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html
22
- function whatwgRNG(length = 16) {
23
- const rnds8 = new Uint8Array(length)
24
- crypto.getRandomValues(rnds8)
25
- return rnds8
26
- }
27
-
28
- function randomKey(length?: number): string {
29
- const table = getByteHexTable()
30
- return whatwgRNG(length)
31
- .reduce((str, n) => str + table[n], '')
32
- .slice(0, length)
33
- }