How to use the prosemirror-transform.liftTarget function in prosemirror-transform

To help you get started, we’ve selected a few prosemirror-transform 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 / liftSelection.js View on Github external
tr.doc.nodesBetween(startPos, endPos, (node, pos) => {
    if (
      node.isText ||                          // Text node
      (node.isTextblock && !node.textContent) // Empty paragraph
    ) {
      const res = tr.doc.resolve(tr.mapping.map(pos));
      const sel = new NodeSelection(res);
      const range = nullthrows(sel.$from.blockRange(sel.$to));
      const target = liftTarget(range);
      if (target || target === 0) {
        tr = tr.lift(range, target);
      }
    }
  });
github ProseMirror / prosemirror-commands / src / commands.js View on Github external
export function liftEmptyBlock(state, dispatch) {
  let {$cursor} = state.selection
  if (!$cursor || $cursor.parent.content.size) return false
  if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) {
    let before = $cursor.before()
    if (canSplit(state.doc, before)) {
      if (dispatch) dispatch(state.tr.split(before).scrollIntoView())
      return true
    }
  }
  let range = $cursor.blockRange(), target = range && liftTarget(range)
  if (target == null) return false
  if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
  return true
}
github tinacms / tinacms / packages / @tinacms / fields / src / Wysiwyg / commands / blockquote-commands.ts View on Github external
export function liftBlockquote(state: EditorState, dispatch: Dispatch | null) {
  const range = getRangeForType(state, state.schema.nodes.blockquote)
  if (!range) return false

  const target = liftTarget(range)
  if (!target) return false

  if (dispatch) {
    dispatch(state.tr.lift(range, target)) //dont lift lists
  }
  return true
}
github ProseMirror / prosemirror-commands / src / commands.js View on Github external
match.matchType(conn[0] || after.type).validEnd) {
    if (dispatch) {
      let end = $cut.pos + after.nodeSize, wrap = Fragment.empty
      for (let i = conn.length - 1; i >= 0; i--)
        wrap = Fragment.from(conn[i].create(null, wrap))
      wrap = Fragment.from(before.copy(wrap))
      let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new Slice(wrap, 1, 0), conn.length, true))
      let joinAt = end + 2 * conn.length
      if (canJoin(tr.doc, joinAt)) tr.join(joinAt)
      dispatch(tr.scrollIntoView())
    }
    return true
  }

  let selAfter = Selection.findFrom($cut, 1)
  let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range)
  if (target != null && target >= $cut.depth) {
    if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
    return true
  }

  return false
}
github tinacms / tinacms / packages / tinacms / fields / src / Wysiwyg / commands / blockquote-commands.ts View on Github external
export function liftBlockquote(state: EditorState, dispatch: Function) {
  const range = getRangeForType(state, state.schema.nodes.blockquote)
  if (!range) return false

  const target = liftTarget(range)
  if (!target) return false

  if (dispatch) {
    dispatch(state.tr.lift(range, target)) //dont lift lists
  }
  return true
}
github chanzuckerberg / czi-prosemirror / xxx / lift.js View on Github external
export default function lift(
  tr: Transform,
): Transform {
  const {selection} = tr;
  if (!selection) {
    return tr;
  }
  const $from = selection.$from;
  const $to = selection.$to;
  const range = $from.blockRange($to);
  if (range) {
    const target = liftTarget(range);
    if (target !== null) {
      tr = tr.lift(range, target);
    }
  }
  return tr;
}
github ProseMirror / prosemirror-commands / src / commands.js View on Github external
export function lift(state, dispatch) {
  let {$from, $to} = state.selection
  let range = $from.blockRange($to), target = range && liftTarget(range)
  if (target == null) return false
  if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
  return true
}
github gamejolt / frontend-lib / components / content / content-editor / content-list.service.ts View on Github external
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 / liftToOuterList.js View on Github external
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));
}