How to use the prosemirror-model.NodeRange 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 chanzuckerberg / czi-prosemirror / xxx / wrapInList.js View on Github external
}
  // This is at the top of an existing list item
  if (
    range.depth >= 2 &&
    $from.node(range.depth - 1).type.compatibleContent(nodeType) &&
    range.startIndex === 0
  ) {
    // Don't do anything if this is the top of the list
    if ($from.index(range.depth - 1) == 0) {
      return tr;
    }

    let $insert = tr.doc.resolve(range.start - 2);
    outerRange = new NodeRange($insert, $insert, range.depth);
    if (range.endIndex < range.parent.childCount) {
      range = new NodeRange(
        $from,
        tr.doc.resolve($to.end(range.depth)),
        range.depth,
      );
    }
    doJoin = true;
  }
  const wrappers = findWrapping(outerRange, nodeType, attrs, range);
  return doWrapInList(
    tr,
    range,
    wrappers,
    doJoin,
    nodeType,
  );
}
github gamejolt / frontend-lib / components / content / content-editor / content-list.service.ts View on Github external
endOfList = range.$to.end(range.depth);
		if (end < endOfList) {
			// There are siblings after the lifted items, which must become
			// children of the last item
			tr.step(
				new ReplaceAroundStep(
					end - 1,
					endOfList,
					end,
					endOfList,
					new Slice(Fragment.from(itemType.create(undefined, range.parent.copy())), 1, 0),
					1,
					true
				)
			);
			range = new NodeRange(
				tr.doc.resolve(range.$from.pos),
				tr.doc.resolve(endOfList),
				range.depth
			);
		}
		dispatch(tr.lift(range, liftTarget(range)!).scrollIntoView());
		return true;
	}
}
github chanzuckerberg / czi-prosemirror / xxx / wrapInList.js View on Github external
if (!range) {
    return tr;
  }
  // This is at the top of an existing list item
  if (
    range.depth >= 2 &&
    $from.node(range.depth - 1).type.compatibleContent(nodeType) &&
    range.startIndex === 0
  ) {
    // Don't do anything if this is the top of the list
    if ($from.index(range.depth - 1) == 0) {
      return tr;
    }

    let $insert = tr.doc.resolve(range.start - 2);
    outerRange = new NodeRange($insert, $insert, range.depth);
    if (range.endIndex < range.parent.childCount) {
      range = new NodeRange(
        $from,
        tr.doc.resolve($to.end(range.depth)),
        range.depth,
      );
    }
    doJoin = true;
  }
  const wrappers = findWrapping(outerRange, nodeType, attrs, range);
  return doWrapInList(
    tr,
    range,
    wrappers,
    doJoin,
    nodeType,
github chanzuckerberg / czi-prosemirror / xxx / liftToOuterList.js View on Github external
if (end < endOfList) {
    // There are siblings after the lifted items, which must become
    // children of the last item
    const frag = Fragment.from(itemType.create(null, range.parent.copy()));
    const slice = new Slice(frag, 1, 0);
    const step = new ReplaceAroundStep(
      end - 1,
      endOfList,
      end,
      endOfList,
      slice,
      1,
      true,
    );
    tr = tr.step(step);
    range = new NodeRange(
      tr.doc.resolve(range.$from.pos),
      tr.doc.resolve(endOfList),
      range.depth,
    );
  }
  return tr.lift(range, liftTarget(range));
}