@portabletext/editor 1.11.3 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -378,3 +378,14 @@ The Behavior API is a new way of interfacing with the Portable Text Editor. It a
378
378
  2. Imperatively trigger **events** using `editor.send(…)` which in turn can trigger behaviors defined using `defineBehavior`.
379
379
  3. Deriving editor **state** using **pure functions**.
380
380
  4. Subscribe to **emitted** editor **events** using `editor.on(…)`.
381
+
382
+ ## Development
383
+
384
+ ### Develop Together with Sanity Studio
385
+
386
+ 1. Run `pnpm build:editor` to make sure it builds correctly
387
+ 2. Now run `pnpm dev:editor` to run it in dev mode
388
+ 3. In another terminal, open your local version of the [sanity](https://github.com/sanity-io/sanity) monorepo
389
+ 4. `cd` into the `sanity` package and run `pnpm link <relative path to the **editor** package in this repo>`
390
+
391
+ Now, you should be able to run `pnpm dev:test-studio` in the `sanity` repo to test Studio with a locally running Portable Text Editor.
package/lib/index.d.mts CHANGED
@@ -4,7 +4,6 @@ import type {
4
4
  ArraySchemaType,
5
5
  BlockListDefinition,
6
6
  BlockStyleDefinition,
7
- KeyedSegment,
8
7
  ObjectSchemaType,
9
8
  PortableTextListBlock,
10
9
  PortableTextObject,
@@ -12,6 +11,7 @@ import type {
12
11
  } from '@sanity/types'
13
12
  import {
14
13
  BlockDecoratorDefinition,
14
+ KeyedSegment,
15
15
  Path,
16
16
  PortableTextBlock,
17
17
  PortableTextChild,
@@ -123,9 +123,12 @@ export declare type BehaviorActionIntend =
123
123
  | BehaviorEvent
124
124
  | {
125
125
  type: 'insert block object'
126
- name: string
127
- value?: {
128
- [prop: string]: unknown
126
+ placement: 'auto' | 'after'
127
+ blockObject: {
128
+ name: string
129
+ value?: {
130
+ [prop: string]: unknown
131
+ }
129
132
  }
130
133
  }
131
134
  | {
@@ -141,7 +144,10 @@ export declare type BehaviorActionIntend =
141
144
  }
142
145
  | {
143
146
  type: 'insert text block'
144
- decorators: Array<string>
147
+ placement: 'auto' | 'after'
148
+ textBlock?: {
149
+ children?: PortableTextTextBlock['children']
150
+ }
145
151
  }
146
152
  | {
147
153
  type: 'set block'
@@ -156,8 +162,13 @@ export declare type BehaviorActionIntend =
156
162
  props: Array<'style' | 'listItem' | 'level'>
157
163
  }
158
164
  | {
159
- type: 'delete'
160
- selection: NonNullable<EditorSelection>
165
+ type: 'delete block'
166
+ blockPath: [KeyedSegment]
167
+ }
168
+ | {
169
+ type: 'delete text'
170
+ anchor: BlockOffset
171
+ focus: BlockOffset
161
172
  }
162
173
  | {
163
174
  type: 'effect'
@@ -332,6 +343,14 @@ export declare interface BlockListItemRenderProps {
332
343
  value: string
333
344
  }
334
345
 
346
+ /**
347
+ * @alpha
348
+ */
349
+ export declare type BlockOffset = {
350
+ path: [KeyedSegment]
351
+ offset: number
352
+ }
353
+
335
354
  /** @beta */
336
355
  export declare interface BlockRenderProps {
337
356
  children: ReactElement
package/lib/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import type {
4
4
  ArraySchemaType,
5
5
  BlockListDefinition,
6
6
  BlockStyleDefinition,
7
- KeyedSegment,
8
7
  ObjectSchemaType,
9
8
  PortableTextListBlock,
10
9
  PortableTextObject,
@@ -12,6 +11,7 @@ import type {
12
11
  } from '@sanity/types'
13
12
  import {
14
13
  BlockDecoratorDefinition,
14
+ KeyedSegment,
15
15
  Path,
16
16
  PortableTextBlock,
17
17
  PortableTextChild,
@@ -123,9 +123,12 @@ export declare type BehaviorActionIntend =
123
123
  | BehaviorEvent
124
124
  | {
125
125
  type: 'insert block object'
126
- name: string
127
- value?: {
128
- [prop: string]: unknown
126
+ placement: 'auto' | 'after'
127
+ blockObject: {
128
+ name: string
129
+ value?: {
130
+ [prop: string]: unknown
131
+ }
129
132
  }
130
133
  }
131
134
  | {
@@ -141,7 +144,10 @@ export declare type BehaviorActionIntend =
141
144
  }
142
145
  | {
143
146
  type: 'insert text block'
144
- decorators: Array<string>
147
+ placement: 'auto' | 'after'
148
+ textBlock?: {
149
+ children?: PortableTextTextBlock['children']
150
+ }
145
151
  }
146
152
  | {
147
153
  type: 'set block'
@@ -156,8 +162,13 @@ export declare type BehaviorActionIntend =
156
162
  props: Array<'style' | 'listItem' | 'level'>
157
163
  }
158
164
  | {
159
- type: 'delete'
160
- selection: NonNullable<EditorSelection>
165
+ type: 'delete block'
166
+ blockPath: [KeyedSegment]
167
+ }
168
+ | {
169
+ type: 'delete text'
170
+ anchor: BlockOffset
171
+ focus: BlockOffset
161
172
  }
162
173
  | {
163
174
  type: 'effect'
@@ -332,6 +343,14 @@ export declare interface BlockListItemRenderProps {
332
343
  value: string
333
344
  }
334
345
 
346
+ /**
347
+ * @alpha
348
+ */
349
+ export declare type BlockOffset = {
350
+ path: [KeyedSegment]
351
+ offset: number
352
+ }
353
+
335
354
  /** @beta */
336
355
  export declare interface BlockRenderProps {
337
356
  children: ReactElement