@portabletext/editor 1.44.6 → 1.44.7
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/index.cjs +30 -5
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +30 -5
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/editor/Editable.tsx +1 -0
- package/src/editor/__tests__/RangeDecorations.test.tsx +2 -2
- package/src/editor/range-decorations-machine.ts +33 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.44.
|
|
3
|
+
"version": "1.44.7",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"check:lint": "biome lint .",
|
|
132
132
|
"check:types": "tsc",
|
|
133
133
|
"check:types:watch": "tsc --watch",
|
|
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-compiler --plugin react-hooks --rule 'react-compiler/react-compiler: [warn
|
|
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-compiler --plugin react-hooks --rule 'react-compiler/react-compiler: [warn]' --rule 'react-hooks/rules-of-hooks: [error]' --rule 'react-hooks/exhaustive-deps: [error]' src",
|
|
135
135
|
"clean": "del .turbo && del lib && del node_modules",
|
|
136
136
|
"dev": "pkg-utils watch",
|
|
137
137
|
"lint:fix": "biome lint --write .",
|
package/src/editor/Editable.tsx
CHANGED
|
@@ -181,6 +181,7 @@ export const PortableTextEditable = forwardRef<
|
|
|
181
181
|
rangeDecorations: rangeDecorations ?? [],
|
|
182
182
|
},
|
|
183
183
|
})
|
|
184
|
+
useSelector(rangeDecorationsActor, (s) => s.context.updateCount)
|
|
184
185
|
const decorate = useMemo(
|
|
185
186
|
() => createDecorate(rangeDecorationsActor),
|
|
186
187
|
[rangeDecorationsActor],
|
|
@@ -120,7 +120,7 @@ describe('RangeDecorations', () => {
|
|
|
120
120
|
)
|
|
121
121
|
await waitFor(() => {
|
|
122
122
|
expect([rangeDecorationIteration, 'updated-with-different']).toEqual([
|
|
123
|
-
|
|
123
|
+
3,
|
|
124
124
|
'updated-with-different',
|
|
125
125
|
])
|
|
126
126
|
})
|
|
@@ -146,7 +146,7 @@ describe('RangeDecorations', () => {
|
|
|
146
146
|
)
|
|
147
147
|
await waitFor(() => {
|
|
148
148
|
expect([rangeDecorationIteration, 'updated-with-different']).toEqual([
|
|
149
|
-
|
|
149
|
+
4,
|
|
150
150
|
'updated-with-different',
|
|
151
151
|
])
|
|
152
152
|
})
|
|
@@ -52,6 +52,7 @@ export const rangeDecorationsMachine = setup({
|
|
|
52
52
|
readOnly: boolean
|
|
53
53
|
schema: EditorSchema
|
|
54
54
|
slateEditor: PortableTextSlateEditor
|
|
55
|
+
updateCount: number
|
|
55
56
|
},
|
|
56
57
|
input: {} as {
|
|
57
58
|
rangeDecorations: Array<RangeDecoration>
|
|
@@ -192,7 +193,14 @@ export const rangeDecorationsMachine = setup({
|
|
|
192
193
|
if (newRange !== null) {
|
|
193
194
|
rangeDecorationState.push({
|
|
194
195
|
...(newRange || slateRange),
|
|
195
|
-
rangeDecoration:
|
|
196
|
+
rangeDecoration: {
|
|
197
|
+
...decoratedRange.rangeDecoration,
|
|
198
|
+
selection: slateRangeToSelection({
|
|
199
|
+
schema: context.schema,
|
|
200
|
+
editor: context.slateEditor,
|
|
201
|
+
range: newRange,
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
196
204
|
})
|
|
197
205
|
}
|
|
198
206
|
}
|
|
@@ -206,6 +214,11 @@ export const rangeDecorationsMachine = setup({
|
|
|
206
214
|
return event.readOnly
|
|
207
215
|
},
|
|
208
216
|
}),
|
|
217
|
+
'increment update count': assign({
|
|
218
|
+
updateCount: ({context}) => {
|
|
219
|
+
return context.updateCount + 1
|
|
220
|
+
},
|
|
221
|
+
}),
|
|
209
222
|
},
|
|
210
223
|
actors: {
|
|
211
224
|
'slate operation listener': fromCallback(slateOperationCallback),
|
|
@@ -215,7 +228,23 @@ export const rangeDecorationsMachine = setup({
|
|
|
215
228
|
'has different decorations': ({context, event}) => {
|
|
216
229
|
assertEvent(event, 'range decorations updated')
|
|
217
230
|
|
|
218
|
-
|
|
231
|
+
const existingRangeDecorations = context.decoratedRanges.map(
|
|
232
|
+
(decoratedRange) => ({
|
|
233
|
+
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
234
|
+
focus: decoratedRange.rangeDecoration.selection?.focus,
|
|
235
|
+
}),
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
const newRangeDecorations = event.rangeDecorations.map(
|
|
239
|
+
(rangeDecoration) => ({
|
|
240
|
+
anchor: rangeDecoration.selection?.anchor,
|
|
241
|
+
focus: rangeDecoration.selection?.focus,
|
|
242
|
+
}),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
const different = !isEqual(existingRangeDecorations, newRangeDecorations)
|
|
246
|
+
|
|
247
|
+
return different
|
|
219
248
|
},
|
|
220
249
|
'not read only': ({context}) => !context.readOnly,
|
|
221
250
|
},
|
|
@@ -227,6 +256,7 @@ export const rangeDecorationsMachine = setup({
|
|
|
227
256
|
decoratedRanges: [],
|
|
228
257
|
schema: input.schema,
|
|
229
258
|
slateEditor: input.slateEditor,
|
|
259
|
+
updateCount: 0,
|
|
230
260
|
}),
|
|
231
261
|
invoke: {
|
|
232
262
|
src: 'slate operation listener',
|
|
@@ -256,10 +286,7 @@ export const rangeDecorationsMachine = setup({
|
|
|
256
286
|
'range decorations updated': {
|
|
257
287
|
target: '.idle',
|
|
258
288
|
guard: 'has different decorations',
|
|
259
|
-
actions: [
|
|
260
|
-
'update range decorations',
|
|
261
|
-
'update pending range decorations',
|
|
262
|
-
],
|
|
289
|
+
actions: ['update range decorations', 'increment update count'],
|
|
263
290
|
},
|
|
264
291
|
},
|
|
265
292
|
states: {
|