@portabletext/editor 2.15.3 → 2.15.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.
- package/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/index.cjs +30 -24
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +28 -23
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +2 -2
- package/src/internal-utils/operation-to-patches.ts +34 -18
- package/src/operations/behavior.operation.child.unset.ts +14 -9
- package/src/test/vitest/step-definitions.tsx +4 -7
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react22 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
|
+
}): react22.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(): react22.JSX.Element;
|
|
196
196
|
export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, MarkdownPluginConfig, OneLinePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.4",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"slate-dom": "^0.118.1",
|
|
86
86
|
"slate-react": "0.117.4",
|
|
87
87
|
"xstate": "^5.23.0",
|
|
88
|
+
"@portabletext/block-tools": "^3.5.12",
|
|
88
89
|
"@portabletext/keyboard-shortcuts": "^1.1.1",
|
|
89
90
|
"@portabletext/patches": "^1.1.8",
|
|
90
|
-
"@portabletext/block-tools": "^3.5.12",
|
|
91
91
|
"@portabletext/schema": "^1.2.0"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
} from '@portabletext/patches'
|
|
10
10
|
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
11
11
|
import type {Path, PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
|
|
12
|
-
import {get} from 'lodash'
|
|
13
12
|
import {
|
|
14
13
|
Element,
|
|
15
14
|
Text,
|
|
@@ -214,31 +213,48 @@ export function setNodePatch(
|
|
|
214
213
|
return patches
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
const newPropNames = Object.keys(operation.newProperties)
|
|
217
|
+
|
|
218
|
+
for (const keyName of newPropNames) {
|
|
219
|
+
const value = (operation.newProperties as Record<string, unknown>)[
|
|
220
|
+
keyName
|
|
221
|
+
]
|
|
222
|
+
|
|
223
|
+
if (keyName === '_key') {
|
|
222
224
|
patches.push(
|
|
223
|
-
set(
|
|
225
|
+
set(value, [
|
|
224
226
|
{_key: blockKey},
|
|
225
227
|
'children',
|
|
226
228
|
block.children.indexOf(child),
|
|
227
229
|
keyName,
|
|
228
230
|
]),
|
|
229
231
|
)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
patches.push(
|
|
233
|
-
set(val, [
|
|
234
|
-
{_key: blockKey},
|
|
235
|
-
'children',
|
|
236
|
-
{_key: childKey},
|
|
237
|
-
keyName,
|
|
238
|
-
]),
|
|
239
|
-
)
|
|
232
|
+
|
|
233
|
+
continue
|
|
240
234
|
}
|
|
241
|
-
|
|
235
|
+
|
|
236
|
+
patches.push(
|
|
237
|
+
set(value, [
|
|
238
|
+
{_key: blockKey},
|
|
239
|
+
'children',
|
|
240
|
+
{_key: childKey},
|
|
241
|
+
keyName,
|
|
242
|
+
]),
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const propNames = Object.keys(operation.properties)
|
|
247
|
+
|
|
248
|
+
for (const keyName of propNames) {
|
|
249
|
+
if (keyName in operation.newProperties) {
|
|
250
|
+
continue
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
patches.push(
|
|
254
|
+
unset([{_key: blockKey}, 'children', {_key: childKey}, keyName]),
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
242
258
|
return patches
|
|
243
259
|
}
|
|
244
260
|
throw new Error('Could not find a valid child')
|
|
@@ -33,18 +33,14 @@ export const childUnsetOperationImplementation: BehaviorOperationImplementation<
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (operation.editor.isTextSpan(child)) {
|
|
36
|
-
if (operation.props.includes('text')) {
|
|
37
|
-
operation.editor.apply({
|
|
38
|
-
type: 'remove_text',
|
|
39
|
-
path: childPath,
|
|
40
|
-
offset: 0,
|
|
41
|
-
text: child.text,
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
36
|
const newNode: Record<string, unknown> = {}
|
|
46
37
|
|
|
47
38
|
for (const prop of operation.props) {
|
|
39
|
+
if (prop === 'text') {
|
|
40
|
+
// Unsetting `text` requires special treatment
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
|
|
48
44
|
if (prop === '_type') {
|
|
49
45
|
// It's not allowed to unset the _type of a span
|
|
50
46
|
continue
|
|
@@ -60,6 +56,15 @@ export const childUnsetOperationImplementation: BehaviorOperationImplementation<
|
|
|
60
56
|
|
|
61
57
|
Transforms.setNodes(operation.editor, newNode, {at: childPath})
|
|
62
58
|
|
|
59
|
+
if (operation.props.includes('text')) {
|
|
60
|
+
operation.editor.apply({
|
|
61
|
+
type: 'remove_text',
|
|
62
|
+
path: childPath,
|
|
63
|
+
offset: 0,
|
|
64
|
+
text: child.text,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
return
|
|
64
69
|
}
|
|
65
70
|
|
|
@@ -251,11 +251,9 @@ export const stepDefinitions = [
|
|
|
251
251
|
type: 'select',
|
|
252
252
|
at: selection,
|
|
253
253
|
})
|
|
254
|
-
})
|
|
255
254
|
|
|
256
|
-
await vi.waitFor(() => {
|
|
257
255
|
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
258
|
-
|
|
256
|
+
selection,
|
|
259
257
|
)
|
|
260
258
|
})
|
|
261
259
|
},
|
|
@@ -283,17 +281,16 @@ export const stepDefinitions = [
|
|
|
283
281
|
context.editor.getSnapshot().context,
|
|
284
282
|
text,
|
|
285
283
|
)
|
|
284
|
+
|
|
286
285
|
expect(selection).not.toBeNull()
|
|
287
286
|
|
|
288
287
|
context.editor.send({
|
|
289
288
|
type: 'select',
|
|
290
|
-
at:
|
|
289
|
+
at: selection,
|
|
291
290
|
})
|
|
292
|
-
})
|
|
293
291
|
|
|
294
|
-
await vi.waitFor(() => {
|
|
295
292
|
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
296
|
-
|
|
293
|
+
selection,
|
|
297
294
|
)
|
|
298
295
|
})
|
|
299
296
|
},
|