How to use the prosemirror-model.Fragment.fromArray function in prosemirror-model

To help you get started, we’ve selected a few prosemirror-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubpub / pubpub-editor / src / addons / HighlightQuote / HighlightQuoteAddon.js View on Github external
&& singleChild
						&& matchesString
					) {
						const to = Number(node.textContent.match(/.*to=([0-9]+)/)[1]);
						const from = Number(node.textContent.match(/.*from=([0-9]+)/)[1]);
						const newNodeData = getHighlightContent(from, to);
						// let exact = '';
						// primaryEditorState.doc.slice(from, to).content.forEach((sliceNode)=>{ exact += sliceNode.textContent; });
						// let prefix = '';
						// primaryEditorState.doc.slice(Math.max(0, from - 10), Math.max(0, from)).content.forEach((sliceNode)=>{ prefix += sliceNode.textContent; });
						// let suffix = '';
						// primaryEditorState.doc.slice(Math.min(primaryEditorState.doc.nodeSize - 2, to), Math.min(primaryEditorState.doc.nodeSize - 2, to + 10)).content.forEach((sliceNode)=>{ suffix += sliceNode.textContent; });
						// console.log(to, from, exact, prefix, suffix);
						const newNode = node.type.schema.nodes.highlightQuote.create(newNodeData);
						/* TODO: this doesn't paste correctly inline */
						return new Slice(Fragment.fromArray([newNode, node.type.schema.nodes.paragraph.create()]), slice.openStart, slice.openEnd);
					}
					return slice;
				},
			},
github pubpub / pubpub-editor / src / plugins / highlightQuote.js View on Github external
// console.log(props.getHighlightContent, singleChild)
				if (props.getHighlightContent && singleChild && matchesString) {
					const to = Number(node.textContent.match(/.*to=([0-9]+)/)[1]);
					const from = Number(node.textContent.match(/.*from=([0-9]+)/)[1]);
					const newNodeData = props.getHighlightContent(from, to);
					// let exact = '';
					// primaryEditorState.doc.slice(from, to).content.forEach((sliceNode)=>{ exact += sliceNode.textContent; });
					// let prefix = '';
					// primaryEditorState.doc.slice(Math.max(0, from - 10), Math.max(0, from)).content.forEach((sliceNode)=>{ prefix += sliceNode.textContent; });
					// let suffix = '';
					// primaryEditorState.doc.slice(Math.min(primaryEditorState.doc.nodeSize - 2, to), Math.min(primaryEditorState.doc.nodeSize - 2, to + 10)).content.forEach((sliceNode)=>{ suffix += sliceNode.textContent; });
					// console.log(to, from, exact, prefix, suffix);
					const newNode = node.type.schema.nodes.highlightQuote.create(newNodeData);
					/* TODO: this doesn't paste correctly inline */
					return new Slice(
						Fragment.fromArray([newNode, node.type.schema.nodes.paragraph.create()]),
						slice.openStart,
						slice.openEnd,
					);
				}
				return slice;
			},
		},
github scrumpy / tiptap / packages / tiptap-commands / src / commands / markPasteRule.js View on Github external
.addToSet(child.marks)))

            pos = end
          }
        }

        // adding rest of text to nodes
        if (pos < text.length) {
          nodes.push(child.cut(pos))
        }
      } else {
        nodes.push(child.copy(handler(child.content)))
      }
    })

    return Fragment.fromArray(nodes)
  }
github tinacms / tinacms / packages / tinacms / fields / src / Wysiwyg / state / plugins / links / index.tsx View on Github external
child.cut(start, end).mark(link.create(attrs).addToSet(child.marks))
          )
        }
        pos = end
      })

      // copy over whatever is left
      if (pos < text.length) {
        linkified.push(child.cut(pos))
      }
    } else {
      linkified.push(child.copy(linkify(child.content)))
    }
  })

  return Fragment.fromArray(linkified)
}
github ProseMirror / prosemirror-transform / src / mark_step.js View on Github external
function mapFragment(fragment, f, parent) {
  let mapped = []
  for (let i = 0; i < fragment.childCount; i++) {
    let child = fragment.child(i)
    if (child.content.size) child = child.copy(mapFragment(child.content, f, child))
    if (child.isInline) child = f(child, parent, i)
    mapped.push(child)
  }
  return Fragment.fromArray(mapped)
}
github scrumpy / tiptap / packages / tiptap-commands / src / commands / pasteRule.js View on Github external
.mark(type.create(attrs)
              .addToSet(child.marks)))

            pos = end
          }
        } while (match)

        if (pos < text.length) {
          nodes.push(child.cut(pos))
        }
      } else {
        nodes.push(child.copy(handler(child.content)))
      }
    })

    return Fragment.fromArray(nodes)
  }
github zodiac-team / zodiac-ui / libs / editor / src / lib / utils / map-slice.ts View on Github external
for (let i = 0, size = content.childCount; i < size; i++) {
        const node = content.child(i)
        const transformed = node.isLeaf
            ? callback(node, parent, i)
            : callback(node.copy(mapFragment(node.content, callback, node)), parent, i)
        if (transformed) {
            if (transformed instanceof Fragment) {
                children.push(...getFragmentBackingArray(transformed))
            } else if (Array.isArray(transformed)) {
                children.push(...transformed)
            } else {
                children.push(transformed)
            }
        }
    }
    return Fragment.fromArray(children)
}