@portabletext/editor 1.0.12 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -26,6 +26,7 @@ const debug = debugWithName('plugin:withPortableTextMarkModel')
26
26
  export function createWithPortableTextMarkModel(
27
27
  types: PortableTextMemberSchemaTypes,
28
28
  change$: Subject<EditorChange>,
29
+ keyGenerator: () => string,
29
30
  ): (editor: PortableTextSlateEditor) => PortableTextSlateEditor {
30
31
  return function withPortableTextMarkModel(editor: PortableTextSlateEditor) {
31
32
  const {apply, normalizeNode} = editor
@@ -255,21 +256,17 @@ export function createWithPortableTextMarkModel(
255
256
  Array.isArray(node.marks) &&
256
257
  node.marks.length > 0
257
258
  ) {
258
- apply(op)
259
- Transforms.splitNodes(editor, {
260
- match: Text.isText,
261
- at: {...selection.focus, offset: selection.focus.offset},
262
- })
263
259
  const marksWithoutAnnotationMarks: string[] = (
264
260
  {
265
261
  ...(Editor.marks(editor) || {}),
266
262
  }.marks || []
267
263
  ).filter((mark) => decorators.includes(mark))
268
- Transforms.setNodes(
269
- editor,
270
- {marks: marksWithoutAnnotationMarks},
271
- {at: Path.next(selection.focus.path)},
272
- )
264
+ Transforms.insertNodes(editor, {
265
+ _type: 'span',
266
+ _key: keyGenerator(),
267
+ text: op.text,
268
+ marks: marksWithoutAnnotationMarks,
269
+ })
273
270
  debug('Inserting text at end of annotation')
274
271
  return
275
272
  }
@@ -469,17 +466,24 @@ export function createWithPortableTextMarkModel(
469
466
  */
470
467
  function mergeSpans(editor: PortableTextSlateEditor) {
471
468
  const {selection} = editor
469
+
472
470
  if (selection) {
473
- for (const [node, path] of Array.from(
471
+ const textNodesInSelection = Array.from(
474
472
  Editor.nodes(editor, {
475
473
  at: Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]]),
474
+ match: Text.isText,
475
+ reverse: true,
476
476
  }),
477
- ).reverse()) {
477
+ )
478
+
479
+ for (const [node, path] of textNodesInSelection) {
478
480
  const [parent] = path.length > 1 ? Editor.node(editor, Path.parent(path)) : [undefined]
479
481
  const nextPath = [path[0], path[1] + 1]
482
+
480
483
  if (editor.isTextBlock(parent)) {
481
484
  const nextNode = parent.children[nextPath[1]]
482
- if (Text.isText(node) && Text.isText(nextNode) && isEqual(nextNode.marks, node.marks)) {
485
+
486
+ if (Text.isText(nextNode) && isEqual(nextNode.marks, node.marks)) {
483
487
  debug('Merging spans')
484
488
  Transforms.mergeNodes(editor, {at: nextPath, voids: true})
485
489
  editor.onChange()
@@ -78,7 +78,11 @@ export const withPlugins = <T extends Editor>(
78
78
  patches$,
79
79
  blockSchemaType: schemaTypes.block,
80
80
  })
81
- const withPortableTextMarkModel = createWithPortableTextMarkModel(schemaTypes, change$)
81
+ const withPortableTextMarkModel = createWithPortableTextMarkModel(
82
+ schemaTypes,
83
+ change$,
84
+ keyGenerator,
85
+ )
82
86
  const withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes)
83
87
 
84
88
  const withPlaceholderBlock = createWithPlaceholderBlock()
@@ -28,7 +28,6 @@ import {debugWithName} from './debug'
28
28
  import {fromSlateValue} from './values'
29
29
 
30
30
  const debug = debugWithName('operationToPatches')
31
- debug.enabled = false
32
31
 
33
32
  export function createOperationToPatches(types: PortableTextMemberSchemaTypes): PatchFunctions {
34
33
  const textBlockName = types.block.name