@portabletext/editor 3.3.0 → 3.3.1
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-es/use-editor.js +8 -4
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/index.js +40 -6
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/editor/PortableTextEditor.tsx +3 -1
- package/src/editor/plugins/createWithPatches.ts +4 -2
- package/src/editor/sync-machine.ts +8 -3
- package/src/internal-utils/apply-operation-to-portable-text.ts +3 -1
- package/src/internal-utils/event-position.ts +43 -4
- package/src/internal-utils/global-scope.ts +12 -4
- package/src/priority/priority.sort.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"slate-react": "^0.120.0",
|
|
74
74
|
"xstate": "^5.24.0",
|
|
75
75
|
"@portabletext/block-tools": "^4.1.7",
|
|
76
|
-
"@portabletext/keyboard-shortcuts": "^2.1.0",
|
|
77
76
|
"@portabletext/markdown": "^1.0.3",
|
|
77
|
+
"@portabletext/keyboard-shortcuts": "^2.1.0",
|
|
78
78
|
"@portabletext/patches": "^2.0.0",
|
|
79
79
|
"@portabletext/schema": "^2.0.0"
|
|
80
80
|
},
|
|
@@ -599,7 +599,9 @@ export class PortableTextEditor extends Component<
|
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
static isObjectPath = (_editor: PortableTextEditor, path: Path): boolean => {
|
|
602
|
-
if (!path || !Array.isArray(path))
|
|
602
|
+
if (!path || !Array.isArray(path)) {
|
|
603
|
+
return false
|
|
604
|
+
}
|
|
603
605
|
const isChildObjectEditPath = path.length > 3 && path[1] === 'children'
|
|
604
606
|
const isBlockObjectEditPath = path.length > 1 && path[1] !== 'children'
|
|
605
607
|
return isBlockObjectEditPath || isChildObjectEditPath
|
|
@@ -64,8 +64,9 @@ export function createWithPatches({
|
|
|
64
64
|
withoutPatching(editor, () => {
|
|
65
65
|
pluginWithoutHistory(editor, () => {
|
|
66
66
|
for (const patch of patches) {
|
|
67
|
-
if (debug.enabled)
|
|
67
|
+
if (debug.enabled) {
|
|
68
68
|
debug(`Handling remote patch ${JSON.stringify(patch)}`)
|
|
69
|
+
}
|
|
69
70
|
|
|
70
71
|
try {
|
|
71
72
|
changed = applyPatch(editor, patch)
|
|
@@ -125,11 +126,12 @@ export function createWithPatches({
|
|
|
125
126
|
)
|
|
126
127
|
|
|
127
128
|
if (!isPatching(editor)) {
|
|
128
|
-
if (debugVerbose && debug.enabled)
|
|
129
|
+
if (debugVerbose && debug.enabled) {
|
|
129
130
|
debug(
|
|
130
131
|
`Editor is not producing patch for operation ${operation.type}`,
|
|
131
132
|
operation,
|
|
132
133
|
)
|
|
134
|
+
}
|
|
133
135
|
return editor
|
|
134
136
|
}
|
|
135
137
|
|
|
@@ -663,8 +663,9 @@ function syncBlock({
|
|
|
663
663
|
context.keyGenerator,
|
|
664
664
|
)
|
|
665
665
|
|
|
666
|
-
if (debug.enabled)
|
|
666
|
+
if (debug.enabled) {
|
|
667
667
|
debug('Validating and inserting new block in the end of the value', block)
|
|
668
|
+
}
|
|
668
669
|
|
|
669
670
|
if (validation.valid || validation.resolution?.autoResolve) {
|
|
670
671
|
const slateBlock = toSlateBlock(block, {
|
|
@@ -740,7 +741,9 @@ function syncBlock({
|
|
|
740
741
|
|
|
741
742
|
if (validation.valid || validation.resolution?.autoResolve) {
|
|
742
743
|
if (oldBlock._key === block._key) {
|
|
743
|
-
if (debug.enabled)
|
|
744
|
+
if (debug.enabled) {
|
|
745
|
+
debug('Updating block', oldBlock, block)
|
|
746
|
+
}
|
|
744
747
|
|
|
745
748
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
746
749
|
withRemoteChanges(slateEditor, () => {
|
|
@@ -756,7 +759,9 @@ function syncBlock({
|
|
|
756
759
|
})
|
|
757
760
|
})
|
|
758
761
|
} else {
|
|
759
|
-
if (debug.enabled)
|
|
762
|
+
if (debug.enabled) {
|
|
763
|
+
debug('Replacing block', oldBlock, block)
|
|
764
|
+
}
|
|
760
765
|
|
|
761
766
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
762
767
|
withRemoteChanges(slateEditor, () => {
|
|
@@ -145,7 +145,9 @@ function applyOperationToPortableTextImmutable(
|
|
|
145
145
|
|
|
146
146
|
case 'insert_text': {
|
|
147
147
|
const {path, offset, text} = operation
|
|
148
|
-
if (text.length === 0)
|
|
148
|
+
if (text.length === 0) {
|
|
149
|
+
return root
|
|
150
|
+
}
|
|
149
151
|
|
|
150
152
|
const span = getSpan(context, root, path)
|
|
151
153
|
if (!span) {
|
|
@@ -148,7 +148,13 @@ export function getEventNode({
|
|
|
148
148
|
return undefined
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
let node: Node | undefined
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
node = DOMEditor.toSlateNode(slateEditor, event.target)
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error(error)
|
|
157
|
+
}
|
|
152
158
|
|
|
153
159
|
return node
|
|
154
160
|
}
|
|
@@ -168,7 +174,18 @@ function getEventPositionBlock({
|
|
|
168
174
|
return undefined
|
|
169
175
|
}
|
|
170
176
|
|
|
171
|
-
|
|
177
|
+
let firstBlockElement: HTMLElement | undefined
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
firstBlockElement = DOMEditor.toDOMNode(slateEditor, firstBlock)
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error(error)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!firstBlockElement) {
|
|
186
|
+
return undefined
|
|
187
|
+
}
|
|
188
|
+
|
|
172
189
|
const firstBlockRect = firstBlockElement.getBoundingClientRect()
|
|
173
190
|
|
|
174
191
|
if (event.pageY < firstBlockRect.top) {
|
|
@@ -181,14 +198,36 @@ function getEventPositionBlock({
|
|
|
181
198
|
return undefined
|
|
182
199
|
}
|
|
183
200
|
|
|
184
|
-
|
|
201
|
+
let lastBlockElement: HTMLElement | undefined
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
lastBlockElement = DOMEditor.toDOMNode(slateEditor, lastBlock)
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.error(error)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!lastBlockElement) {
|
|
210
|
+
return undefined
|
|
211
|
+
}
|
|
212
|
+
|
|
185
213
|
const lastBlockRef = lastBlockElement.getBoundingClientRect()
|
|
186
214
|
|
|
187
215
|
if (event.pageY > lastBlockRef.bottom) {
|
|
188
216
|
return 'end'
|
|
189
217
|
}
|
|
190
218
|
|
|
191
|
-
|
|
219
|
+
let element: HTMLElement | undefined
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
element = DOMEditor.toDOMNode(slateEditor, node)
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(error)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!element) {
|
|
228
|
+
return undefined
|
|
229
|
+
}
|
|
230
|
+
|
|
192
231
|
const elementRect = element.getBoundingClientRect()
|
|
193
232
|
const top = elementRect.top
|
|
194
233
|
const height = elementRect.height
|
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
* - The `global` variable is the global scope in Node.js
|
|
9
9
|
*/
|
|
10
10
|
function getGlobalScope() {
|
|
11
|
-
if (typeof globalThis !== 'undefined')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (typeof
|
|
11
|
+
if (typeof globalThis !== 'undefined') {
|
|
12
|
+
return globalThis
|
|
13
|
+
}
|
|
14
|
+
if (typeof window !== 'undefined') {
|
|
15
|
+
return window
|
|
16
|
+
}
|
|
17
|
+
if (typeof self !== 'undefined') {
|
|
18
|
+
return self
|
|
19
|
+
}
|
|
20
|
+
if (typeof global !== 'undefined') {
|
|
21
|
+
return global
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
throw new Error('@portabletext/editor: could not locate global scope')
|
|
17
25
|
}
|
|
@@ -47,7 +47,9 @@ export function sortByPriority<
|
|
|
47
47
|
|
|
48
48
|
// Helper function to add an edge to the graph
|
|
49
49
|
function addEdge(fromId: string, toId: string) {
|
|
50
|
-
if (!graph.has(fromId) || !graph.has(toId))
|
|
50
|
+
if (!graph.has(fromId) || !graph.has(toId)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
51
53
|
graph.get(fromId)?.add(toId)
|
|
52
54
|
inDegree.set(toId, (inDegree.get(toId) ?? 0) + 1)
|
|
53
55
|
}
|