@portabletext/editor 2.6.8 → 2.6.10-canary.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/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/index.cjs +60 -13
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +61 -14
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +6 -6
- package/src/behaviors/behavior.abstract.delete.ts +53 -0
- package/src/editor/__tests__/self-solving.test.tsx +1 -33
- package/src/editor/mutation-machine.ts +11 -14
- package/src/editor/plugins/createWithPatches.ts +2 -2
package/lib/plugins/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react12 from "react";
|
|
3
3
|
import React from "react";
|
|
4
4
|
/**
|
|
5
5
|
* @beta
|
|
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
|
|
|
181
181
|
*/
|
|
182
182
|
declare function MarkdownPlugin(props: {
|
|
183
183
|
config: MarkdownPluginConfig;
|
|
184
|
-
}):
|
|
184
|
+
}): react12.JSX.Element;
|
|
185
185
|
/**
|
|
186
186
|
* @beta
|
|
187
187
|
* Restrict the editor to one line. The plugin takes care of blocking
|
|
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
|
|
|
192
192
|
*
|
|
193
193
|
* @deprecated Install the plugin from `@portabletext/plugin-one-line`
|
|
194
194
|
*/
|
|
195
|
-
declare function OneLinePlugin():
|
|
195
|
+
declare function OneLinePlugin(): react12.JSX.Element;
|
|
196
196
|
export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _sanity_types8 from "@sanity/types";
|
|
3
3
|
import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
|
|
4
4
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
5
|
/**
|
|
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
|
|
|
143
143
|
context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
|
|
144
144
|
targetBlock: PortableTextTextBlock;
|
|
145
145
|
incomingBlock: PortableTextTextBlock;
|
|
146
|
-
}): PortableTextTextBlock<
|
|
146
|
+
}): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
|
|
147
147
|
/**
|
|
148
148
|
* @public
|
|
149
149
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.10-canary.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"immer": "^10.1.1",
|
|
75
75
|
"lodash": "^4.17.21",
|
|
76
76
|
"lodash.startcase": "^4.4.0",
|
|
77
|
-
"react-compiler-runtime": "19.1.0-rc.
|
|
77
|
+
"react-compiler-runtime": "19.1.0-rc.3",
|
|
78
78
|
"slate": "0.118.1",
|
|
79
79
|
"slate-dom": "^0.118.1",
|
|
80
80
|
"slate-react": "0.117.4",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
89
|
-
"@sanity/pkg-utils": "^8.1.
|
|
89
|
+
"@sanity/pkg-utils": "^8.1.4",
|
|
90
90
|
"@sanity/schema": "^4.6.0",
|
|
91
91
|
"@sanity/types": "^4.6.0",
|
|
92
92
|
"@testing-library/react": "^16.3.0",
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
"@vitejs/plugin-react": "^4.7.0",
|
|
101
101
|
"@vitest/browser": "^3.2.4",
|
|
102
102
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
103
|
-
"babel-plugin-react-compiler": "19.1.0-rc.
|
|
103
|
+
"babel-plugin-react-compiler": "19.1.0-rc.3",
|
|
104
104
|
"eslint": "8.57.1",
|
|
105
|
-
"eslint-plugin-react-hooks": "6.0.0-rc.
|
|
105
|
+
"eslint-plugin-react-hooks": "6.0.0-rc.2",
|
|
106
106
|
"jsdom": "^26.0.0",
|
|
107
107
|
"react": "^19.1.1",
|
|
108
108
|
"react-dom": "^19.1.1",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"scripts": {
|
|
132
132
|
"build": "pkg-utils build --strict --check --clean",
|
|
133
133
|
"check:lint": "biome lint .",
|
|
134
|
-
"check:react-compiler": "eslint --cache --no-inline-config --no-eslintrc --ignore-pattern '**/__tests__/**' --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-hooks --rule 'react-hooks/
|
|
134
|
+
"check:react-compiler": "eslint --cache --no-inline-config --no-eslintrc --ignore-pattern '**/__tests__/**' --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-hooks --rule 'react-hooks/rules-of-hooks: [error]' --rule 'react-hooks/exhaustive-deps: [error]' src",
|
|
135
135
|
"check:types": "tsc",
|
|
136
136
|
"check:types:watch": "tsc --watch",
|
|
137
137
|
"clean": "del .turbo && del lib && del node_modules",
|
|
@@ -103,6 +103,59 @@ export const abstractDeleteBehaviors = [
|
|
|
103
103
|
return false
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
const nextBlock = selectors.getNextBlock({
|
|
107
|
+
...snapshot,
|
|
108
|
+
context: {
|
|
109
|
+
...snapshot.context,
|
|
110
|
+
selection: event.at,
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
const focusTextBlock = selectors.getFocusTextBlock({
|
|
114
|
+
...snapshot,
|
|
115
|
+
context: {
|
|
116
|
+
...snapshot.context,
|
|
117
|
+
selection: event.at,
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
if (!nextBlock || !focusTextBlock) {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!utils.isEmptyTextBlock(snapshot.context, focusTextBlock.node)) {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const nextBlockStartPoint = utils.getBlockStartPoint({
|
|
130
|
+
context: snapshot.context,
|
|
131
|
+
block: nextBlock,
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
return {focusTextBlock, nextBlockStartPoint}
|
|
135
|
+
},
|
|
136
|
+
actions: [
|
|
137
|
+
(_, {focusTextBlock, nextBlockStartPoint}) => [
|
|
138
|
+
raise({
|
|
139
|
+
type: 'delete.block',
|
|
140
|
+
at: focusTextBlock.path,
|
|
141
|
+
}),
|
|
142
|
+
raise({
|
|
143
|
+
type: 'select',
|
|
144
|
+
at: {
|
|
145
|
+
anchor: nextBlockStartPoint,
|
|
146
|
+
focus: nextBlockStartPoint,
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
],
|
|
150
|
+
],
|
|
151
|
+
}),
|
|
152
|
+
defineBehavior({
|
|
153
|
+
on: 'delete',
|
|
154
|
+
guard: ({snapshot, event}) => {
|
|
155
|
+
if (event.direction !== 'forward') {
|
|
156
|
+
return false
|
|
157
|
+
}
|
|
158
|
+
|
|
106
159
|
const nextBlock = selectors.getNextBlock(snapshot)
|
|
107
160
|
const focusTextBlock = selectors.getFocusTextBlock(snapshot)
|
|
108
161
|
|
|
@@ -147,39 +147,7 @@ describe('Feature: Self-solving', () => {
|
|
|
147
147
|
})
|
|
148
148
|
expect(onChange).toHaveBeenNthCalledWith(8, {
|
|
149
149
|
type: 'mutation',
|
|
150
|
-
patches: [spanPatch, blockPatch],
|
|
151
|
-
snapshot: [
|
|
152
|
-
block({
|
|
153
|
-
_key: 'b1',
|
|
154
|
-
children: [
|
|
155
|
-
span({
|
|
156
|
-
_key: 's1',
|
|
157
|
-
text: 'foo',
|
|
158
|
-
marks: [],
|
|
159
|
-
}),
|
|
160
|
-
],
|
|
161
|
-
style: 'normal',
|
|
162
|
-
markDefs: [],
|
|
163
|
-
}),
|
|
164
|
-
],
|
|
165
|
-
value: [
|
|
166
|
-
block({
|
|
167
|
-
_key: 'b1',
|
|
168
|
-
children: [
|
|
169
|
-
span({
|
|
170
|
-
_key: 's1',
|
|
171
|
-
text: 'foo',
|
|
172
|
-
marks: [],
|
|
173
|
-
}),
|
|
174
|
-
],
|
|
175
|
-
style: 'normal',
|
|
176
|
-
markDefs: [],
|
|
177
|
-
}),
|
|
178
|
-
],
|
|
179
|
-
})
|
|
180
|
-
expect(onChange).toHaveBeenNthCalledWith(9, {
|
|
181
|
-
type: 'mutation',
|
|
182
|
-
patches: [strongPatch],
|
|
150
|
+
patches: [spanPatch, blockPatch, strongPatch],
|
|
183
151
|
snapshot: [
|
|
184
152
|
block({
|
|
185
153
|
_key: 'b1',
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
enqueueActions,
|
|
11
11
|
fromCallback,
|
|
12
12
|
not,
|
|
13
|
+
raise,
|
|
13
14
|
setup,
|
|
14
|
-
stateIn,
|
|
15
15
|
type AnyEventObject,
|
|
16
16
|
} from 'xstate'
|
|
17
17
|
import {debugWithName} from '../internal-utils/debug'
|
|
@@ -41,7 +41,7 @@ export const mutationMachine = setup({
|
|
|
41
41
|
},
|
|
42
42
|
events: {} as
|
|
43
43
|
| {
|
|
44
|
-
type: '
|
|
44
|
+
type: 'emit changes'
|
|
45
45
|
}
|
|
46
46
|
| {
|
|
47
47
|
type: 'patch'
|
|
@@ -164,12 +164,12 @@ export const mutationMachine = setup({
|
|
|
164
164
|
input.slateEditor.apply = originalApply
|
|
165
165
|
}
|
|
166
166
|
}),
|
|
167
|
-
'mutation
|
|
167
|
+
'mutation interval': fromCallback(({sendBack}) => {
|
|
168
168
|
const interval = setInterval(
|
|
169
169
|
() => {
|
|
170
|
-
sendBack({type: '
|
|
170
|
+
sendBack({type: 'emit changes'})
|
|
171
171
|
},
|
|
172
|
-
process.env.NODE_ENV === 'test' ? 250 :
|
|
172
|
+
process.env.NODE_ENV === 'test' ? 250 : 1000,
|
|
173
173
|
)
|
|
174
174
|
|
|
175
175
|
return () => {
|
|
@@ -179,12 +179,11 @@ export const mutationMachine = setup({
|
|
|
179
179
|
},
|
|
180
180
|
guards: {
|
|
181
181
|
'is read-only': ({context}) => context.readOnly,
|
|
182
|
-
'is typing': stateIn({typing: 'typing'}),
|
|
183
182
|
'slate is normalizing': ({context}) =>
|
|
184
183
|
Editor.isNormalizing(context.slateEditor),
|
|
185
184
|
},
|
|
186
185
|
delays: {
|
|
187
|
-
'type debounce':
|
|
186
|
+
'type debounce': 250,
|
|
188
187
|
},
|
|
189
188
|
}).createMachine({
|
|
190
189
|
id: 'mutation',
|
|
@@ -232,6 +231,7 @@ export const mutationMachine = setup({
|
|
|
232
231
|
'type debounce': {
|
|
233
232
|
target: 'idle',
|
|
234
233
|
actions: [
|
|
234
|
+
raise({type: 'emit changes'}),
|
|
235
235
|
() => {
|
|
236
236
|
debug('exit: typing->typing')
|
|
237
237
|
},
|
|
@@ -241,6 +241,7 @@ export const mutationMachine = setup({
|
|
|
241
241
|
on: {
|
|
242
242
|
'not typing': {
|
|
243
243
|
target: 'idle',
|
|
244
|
+
actions: [raise({type: 'emit changes'})],
|
|
244
245
|
},
|
|
245
246
|
'typing': {
|
|
246
247
|
target: 'typing',
|
|
@@ -291,15 +292,11 @@ export const mutationMachine = setup({
|
|
|
291
292
|
},
|
|
292
293
|
],
|
|
293
294
|
invoke: {
|
|
294
|
-
src: 'mutation
|
|
295
|
+
src: 'mutation interval',
|
|
295
296
|
},
|
|
296
297
|
on: {
|
|
297
|
-
'
|
|
298
|
-
guard: and([
|
|
299
|
-
not('is read-only'),
|
|
300
|
-
not('is typing'),
|
|
301
|
-
'slate is normalizing',
|
|
302
|
-
]),
|
|
298
|
+
'emit changes': {
|
|
299
|
+
guard: and([not('is read-only'), 'slate is normalizing']),
|
|
303
300
|
target: 'idle',
|
|
304
301
|
actions: [
|
|
305
302
|
'emit pending patch events',
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
27
27
|
import type {EditorActor} from '../editor-machine'
|
|
28
28
|
import type {RelayActor} from '../relay-machine'
|
|
29
|
-
import {
|
|
29
|
+
import {getCurrentUndoStepId} from '../with-undo-step'
|
|
30
30
|
import {withoutSaving} from './createWithUndoRedo'
|
|
31
31
|
|
|
32
32
|
const debug = debugWithName('plugin:withPatches')
|
|
@@ -266,7 +266,7 @@ export function createWithPatches({
|
|
|
266
266
|
editorActor.send({
|
|
267
267
|
type: 'internal.patch',
|
|
268
268
|
patch: {...patch, origin: 'local'},
|
|
269
|
-
operationId:
|
|
269
|
+
operationId: getCurrentUndoStepId(editor),
|
|
270
270
|
value: editor.value,
|
|
271
271
|
})
|
|
272
272
|
}
|