@portabletext/editor 1.0.2 → 1.0.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.
package/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # @portabletext/editor
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/portabletext/portabletext/master/logo-white.svg?sanitize=true">
3
+ <img alt="Portable Text Logo" src="https://raw.githubusercontent.com/portabletext/portabletext/master/logo.svg?sanitize=true">
4
+ </picture>
2
5
 
3
- This is the successor to `@sanity/portable-text-editor` 🥳
6
+ <div align="center">
7
+ <h1>Portable Text Editor</h1>
8
+ </div>
9
+
10
+ > The official editor for editing [Portable Text](https://github.com/portabletext/portabletext) – the JSON based rich text specification for modern content editing platforms.
package/lib/index.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="react" />
2
-
3
1
  import {ArrayDefinition} from '@sanity/types'
4
2
  import {ArraySchemaType} from '@sanity/types'
5
3
  import {BaseSyntheticEvent} from 'react'
@@ -21,6 +19,7 @@ import {Node as Node_2} from 'slate'
21
19
  import {ObjectSchemaType} from '@sanity/types'
22
20
  import {Observable} from 'rxjs'
23
21
  import {Operation} from 'slate'
22
+ import {Patch} from '@portabletext/patches/types'
24
23
  import {Path} from '@sanity/types'
25
24
  import {PortableTextBlock} from '@sanity/types'
26
25
  import {PortableTextChild} from '@sanity/types'
@@ -31,7 +30,6 @@ import {PortableTextTextBlock} from '@sanity/types'
31
30
  import {PropsWithChildren} from 'react'
32
31
  import {ReactEditor} from 'slate-react'
33
32
  import {ReactElement} from 'react'
34
- import {ReactNode} from 'react'
35
33
  import {RefAttributes} from 'react'
36
34
  import {RefObject} from 'react'
37
35
  import {SpanSchemaType} from '@sanity/types'
@@ -129,12 +127,6 @@ export declare type BlurChange = {
129
127
  event: FocusEvent_2<HTMLDivElement, Element>
130
128
  }
131
129
 
132
- /**
133
- * Try to compact a set of patches
134
- *
135
- */
136
- export declare function compactPatches(patches: Patch[]): Patch[]
137
-
138
130
  /**
139
131
  * The editor was either connected or disconnected to the network
140
132
  * To show out of sync warnings etc when in collaborative mode.
@@ -152,20 +144,6 @@ export declare type createEditorOptions = {
152
144
  maxBlocks?: number
153
145
  }
154
146
 
155
- export declare type DecPatch = {
156
- path: Path
157
- origin?: Origin
158
- type: 'dec'
159
- value: JSONValue
160
- }
161
-
162
- export declare type DiffMatchPatch = {
163
- path: Path
164
- type: 'diffMatchPatch'
165
- origin?: Origin
166
- value: string
167
- }
168
-
169
147
  /** @beta */
170
148
  export declare interface EditableAPI {
171
149
  activeAnnotations: () => PortableTextObject[]
@@ -303,24 +281,6 @@ export declare type HotkeyOptions = {
303
281
  custom?: Record<string, (event: BaseSyntheticEvent, editor: PortableTextEditor) => void>
304
282
  }
305
283
 
306
- export declare type IncPatch = {
307
- path: Path
308
- origin?: Origin
309
- type: 'inc'
310
- value: JSONValue
311
- }
312
-
313
- export declare type InsertPatch = {
314
- path: Path
315
- origin?: Origin
316
- type: 'insert'
317
- position: InsertPosition_2
318
- items: JSONValue[]
319
- }
320
-
321
- declare type InsertPosition_2 = 'before' | 'after' | 'replace'
322
- export {InsertPosition_2 as InsertPosition}
323
-
324
284
  /**
325
285
  * The editor has an invalid value
326
286
  * @beta */
@@ -353,15 +313,6 @@ export declare type InvalidValueResolution = {
353
313
  }
354
314
  }
355
315
 
356
- export declare type JSONValue =
357
- | number
358
- | string
359
- | boolean
360
- | {
361
- [key: string]: JSONValue
362
- }
363
- | JSONValue[]
364
-
365
316
  export declare const keyGenerator: () => string
366
317
 
367
318
  /**
@@ -403,8 +354,6 @@ export declare type OnPasteResult =
403
354
 
404
355
  export declare type OnPasteResultOrPromise = OnPasteResult | Promise<OnPasteResult>
405
356
 
406
- export declare type Origin = 'remote' | 'local' | 'internal'
407
-
408
357
  /** @beta */
409
358
  export declare interface PasteData {
410
359
  event: ClipboardEvent_2
@@ -413,15 +362,6 @@ export declare interface PasteData {
413
362
  value: PortableTextBlock[] | undefined
414
363
  }
415
364
 
416
- export declare type Patch =
417
- | SetPatch
418
- | SetIfMissingPatch
419
- | UnsetPatch
420
- | InsertPatch
421
- | DiffMatchPatch
422
- | IncPatch
423
- | DecPatch
424
-
425
365
  /**
426
366
  * The editor has produced a patch
427
367
  * @beta */
@@ -442,22 +382,22 @@ export declare type PatchObservable = Observable<{
442
382
  export declare const PortableTextEditable: ForwardRefExoticComponent<
443
383
  Omit<
444
384
  Omit<TextareaHTMLAttributes<HTMLDivElement>, 'onPaste' | 'onCopy' | 'onBeforeInput'> & {
445
- hotkeys?: HotkeyOptions | undefined
446
- onBeforeInput?: ((event: InputEvent) => void) | undefined
447
- onPaste?: OnPasteFn | undefined
448
- onCopy?: OnCopyFn | undefined
385
+ hotkeys?: HotkeyOptions
386
+ onBeforeInput?: (event: InputEvent) => void
387
+ onPaste?: OnPasteFn
388
+ onCopy?: OnCopyFn
449
389
  ref: MutableRefObject<HTMLDivElement | null>
450
- rangeDecorations?: RangeDecoration[] | undefined
451
- renderAnnotation?: RenderAnnotationFunction | undefined
452
- renderBlock?: RenderBlockFunction | undefined
453
- renderChild?: RenderChildFunction | undefined
454
- renderDecorator?: RenderDecoratorFunction | undefined
455
- renderListItem?: RenderListItemFunction | undefined
456
- renderPlaceholder?: (() => ReactNode) | undefined
457
- renderStyle?: RenderStyleFunction | undefined
458
- scrollSelectionIntoView?: ScrollSelectionIntoViewFunction | undefined
459
- selection?: EditorSelection | undefined
460
- spellCheck?: boolean | undefined
390
+ rangeDecorations?: RangeDecoration[]
391
+ renderAnnotation?: RenderAnnotationFunction
392
+ renderBlock?: RenderBlockFunction
393
+ renderChild?: RenderChildFunction
394
+ renderDecorator?: RenderDecoratorFunction
395
+ renderListItem?: RenderListItemFunction
396
+ renderPlaceholder?: RenderPlaceholderFunction
397
+ renderStyle?: RenderStyleFunction
398
+ scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
399
+ selection?: EditorSelection
400
+ spellCheck?: boolean
461
401
  } & Omit<HTMLProps<HTMLDivElement>, 'onPaste' | 'onBeforeInput' | 'as'>,
462
402
  'ref'
463
403
  > &
@@ -482,7 +422,7 @@ export declare type PortableTextEditableProps = Omit<
482
422
  renderChild?: RenderChildFunction
483
423
  renderDecorator?: RenderDecoratorFunction
484
424
  renderListItem?: RenderListItemFunction
485
- renderPlaceholder?: () => ReactNode
425
+ renderPlaceholder?: RenderPlaceholderFunction
486
426
  renderStyle?: RenderStyleFunction
487
427
  scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
488
428
  selection?: EditorSelection
@@ -838,6 +778,9 @@ export declare type RenderEditableFunction = (props: PortableTextEditableProps)
838
778
  /** @beta */
839
779
  export declare type RenderListItemFunction = (props: BlockListItemRenderProps) => JSX.Element
840
780
 
781
+ /** @beta */
782
+ export declare type RenderPlaceholderFunction = () => React.ReactNode
783
+
841
784
  /** @beta */
842
785
  export declare type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element
843
786
 
@@ -855,20 +798,6 @@ export declare type SelectionChange = {
855
798
  selection: EditorSelection
856
799
  }
857
800
 
858
- export declare type SetIfMissingPatch = {
859
- path: Path
860
- origin?: Origin
861
- type: 'setIfMissing'
862
- value: JSONValue
863
- }
864
-
865
- export declare type SetPatch = {
866
- path: Path
867
- type: 'set'
868
- origin?: Origin
869
- value: JSONValue
870
- }
871
-
872
801
  /**
873
802
  * The editor performed a undo history step
874
803
  * @beta */
@@ -884,12 +813,6 @@ export declare type UnsetChange = {
884
813
  previousValue: PortableTextBlock[]
885
814
  }
886
815
 
887
- export declare type UnsetPatch = {
888
- path: Path
889
- origin?: Origin
890
- type: 'unset'
891
- }
892
-
893
816
  /**
894
817
  * Get the current editor object from the React context.
895
818
  */
@@ -908,4 +831,6 @@ export declare type ValueChange = {
908
831
  value: PortableTextBlock[] | undefined
909
832
  }
910
833
 
834
+ export * from '@portabletext/patches/types'
835
+
911
836
  export {}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="react" />
2
-
3
1
  import {ArrayDefinition} from '@sanity/types'
4
2
  import {ArraySchemaType} from '@sanity/types'
5
3
  import {BaseSyntheticEvent} from 'react'
@@ -21,6 +19,7 @@ import {Node as Node_2} from 'slate'
21
19
  import {ObjectSchemaType} from '@sanity/types'
22
20
  import {Observable} from 'rxjs'
23
21
  import {Operation} from 'slate'
22
+ import {Patch} from '@portabletext/patches/types'
24
23
  import {Path} from '@sanity/types'
25
24
  import {PortableTextBlock} from '@sanity/types'
26
25
  import {PortableTextChild} from '@sanity/types'
@@ -31,7 +30,6 @@ import {PortableTextTextBlock} from '@sanity/types'
31
30
  import {PropsWithChildren} from 'react'
32
31
  import {ReactEditor} from 'slate-react'
33
32
  import {ReactElement} from 'react'
34
- import {ReactNode} from 'react'
35
33
  import {RefAttributes} from 'react'
36
34
  import {RefObject} from 'react'
37
35
  import {SpanSchemaType} from '@sanity/types'
@@ -129,12 +127,6 @@ export declare type BlurChange = {
129
127
  event: FocusEvent_2<HTMLDivElement, Element>
130
128
  }
131
129
 
132
- /**
133
- * Try to compact a set of patches
134
- *
135
- */
136
- export declare function compactPatches(patches: Patch[]): Patch[]
137
-
138
130
  /**
139
131
  * The editor was either connected or disconnected to the network
140
132
  * To show out of sync warnings etc when in collaborative mode.
@@ -152,20 +144,6 @@ export declare type createEditorOptions = {
152
144
  maxBlocks?: number
153
145
  }
154
146
 
155
- export declare type DecPatch = {
156
- path: Path
157
- origin?: Origin
158
- type: 'dec'
159
- value: JSONValue
160
- }
161
-
162
- export declare type DiffMatchPatch = {
163
- path: Path
164
- type: 'diffMatchPatch'
165
- origin?: Origin
166
- value: string
167
- }
168
-
169
147
  /** @beta */
170
148
  export declare interface EditableAPI {
171
149
  activeAnnotations: () => PortableTextObject[]
@@ -303,24 +281,6 @@ export declare type HotkeyOptions = {
303
281
  custom?: Record<string, (event: BaseSyntheticEvent, editor: PortableTextEditor) => void>
304
282
  }
305
283
 
306
- export declare type IncPatch = {
307
- path: Path
308
- origin?: Origin
309
- type: 'inc'
310
- value: JSONValue
311
- }
312
-
313
- export declare type InsertPatch = {
314
- path: Path
315
- origin?: Origin
316
- type: 'insert'
317
- position: InsertPosition_2
318
- items: JSONValue[]
319
- }
320
-
321
- declare type InsertPosition_2 = 'before' | 'after' | 'replace'
322
- export {InsertPosition_2 as InsertPosition}
323
-
324
284
  /**
325
285
  * The editor has an invalid value
326
286
  * @beta */
@@ -353,15 +313,6 @@ export declare type InvalidValueResolution = {
353
313
  }
354
314
  }
355
315
 
356
- export declare type JSONValue =
357
- | number
358
- | string
359
- | boolean
360
- | {
361
- [key: string]: JSONValue
362
- }
363
- | JSONValue[]
364
-
365
316
  export declare const keyGenerator: () => string
366
317
 
367
318
  /**
@@ -403,8 +354,6 @@ export declare type OnPasteResult =
403
354
 
404
355
  export declare type OnPasteResultOrPromise = OnPasteResult | Promise<OnPasteResult>
405
356
 
406
- export declare type Origin = 'remote' | 'local' | 'internal'
407
-
408
357
  /** @beta */
409
358
  export declare interface PasteData {
410
359
  event: ClipboardEvent_2
@@ -413,15 +362,6 @@ export declare interface PasteData {
413
362
  value: PortableTextBlock[] | undefined
414
363
  }
415
364
 
416
- export declare type Patch =
417
- | SetPatch
418
- | SetIfMissingPatch
419
- | UnsetPatch
420
- | InsertPatch
421
- | DiffMatchPatch
422
- | IncPatch
423
- | DecPatch
424
-
425
365
  /**
426
366
  * The editor has produced a patch
427
367
  * @beta */
@@ -442,22 +382,22 @@ export declare type PatchObservable = Observable<{
442
382
  export declare const PortableTextEditable: ForwardRefExoticComponent<
443
383
  Omit<
444
384
  Omit<TextareaHTMLAttributes<HTMLDivElement>, 'onPaste' | 'onCopy' | 'onBeforeInput'> & {
445
- hotkeys?: HotkeyOptions | undefined
446
- onBeforeInput?: ((event: InputEvent) => void) | undefined
447
- onPaste?: OnPasteFn | undefined
448
- onCopy?: OnCopyFn | undefined
385
+ hotkeys?: HotkeyOptions
386
+ onBeforeInput?: (event: InputEvent) => void
387
+ onPaste?: OnPasteFn
388
+ onCopy?: OnCopyFn
449
389
  ref: MutableRefObject<HTMLDivElement | null>
450
- rangeDecorations?: RangeDecoration[] | undefined
451
- renderAnnotation?: RenderAnnotationFunction | undefined
452
- renderBlock?: RenderBlockFunction | undefined
453
- renderChild?: RenderChildFunction | undefined
454
- renderDecorator?: RenderDecoratorFunction | undefined
455
- renderListItem?: RenderListItemFunction | undefined
456
- renderPlaceholder?: (() => ReactNode) | undefined
457
- renderStyle?: RenderStyleFunction | undefined
458
- scrollSelectionIntoView?: ScrollSelectionIntoViewFunction | undefined
459
- selection?: EditorSelection | undefined
460
- spellCheck?: boolean | undefined
390
+ rangeDecorations?: RangeDecoration[]
391
+ renderAnnotation?: RenderAnnotationFunction
392
+ renderBlock?: RenderBlockFunction
393
+ renderChild?: RenderChildFunction
394
+ renderDecorator?: RenderDecoratorFunction
395
+ renderListItem?: RenderListItemFunction
396
+ renderPlaceholder?: RenderPlaceholderFunction
397
+ renderStyle?: RenderStyleFunction
398
+ scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
399
+ selection?: EditorSelection
400
+ spellCheck?: boolean
461
401
  } & Omit<HTMLProps<HTMLDivElement>, 'onPaste' | 'onBeforeInput' | 'as'>,
462
402
  'ref'
463
403
  > &
@@ -482,7 +422,7 @@ export declare type PortableTextEditableProps = Omit<
482
422
  renderChild?: RenderChildFunction
483
423
  renderDecorator?: RenderDecoratorFunction
484
424
  renderListItem?: RenderListItemFunction
485
- renderPlaceholder?: () => ReactNode
425
+ renderPlaceholder?: RenderPlaceholderFunction
486
426
  renderStyle?: RenderStyleFunction
487
427
  scrollSelectionIntoView?: ScrollSelectionIntoViewFunction
488
428
  selection?: EditorSelection
@@ -838,6 +778,9 @@ export declare type RenderEditableFunction = (props: PortableTextEditableProps)
838
778
  /** @beta */
839
779
  export declare type RenderListItemFunction = (props: BlockListItemRenderProps) => JSX.Element
840
780
 
781
+ /** @beta */
782
+ export declare type RenderPlaceholderFunction = () => React.ReactNode
783
+
841
784
  /** @beta */
842
785
  export declare type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element
843
786
 
@@ -855,20 +798,6 @@ export declare type SelectionChange = {
855
798
  selection: EditorSelection
856
799
  }
857
800
 
858
- export declare type SetIfMissingPatch = {
859
- path: Path
860
- origin?: Origin
861
- type: 'setIfMissing'
862
- value: JSONValue
863
- }
864
-
865
- export declare type SetPatch = {
866
- path: Path
867
- type: 'set'
868
- origin?: Origin
869
- value: JSONValue
870
- }
871
-
872
801
  /**
873
802
  * The editor performed a undo history step
874
803
  * @beta */
@@ -884,12 +813,6 @@ export declare type UnsetChange = {
884
813
  previousValue: PortableTextBlock[]
885
814
  }
886
815
 
887
- export declare type UnsetPatch = {
888
- path: Path
889
- origin?: Origin
890
- type: 'unset'
891
- }
892
-
893
816
  /**
894
817
  * Get the current editor object from the React context.
895
818
  */
@@ -908,4 +831,6 @@ export declare type ValueChange = {
908
831
  value: PortableTextBlock[] | undefined
909
832
  }
910
833
 
834
+ export * from '@portabletext/patches/types'
835
+
911
836
  export {}