How to use the prosemirror-transform.findWrapping 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 ProseMirror / website / example / schema / index.js View on Github external
function makeNoteGroup(state, dispatch) {
  // Get a range around the selected blocks
  let range = state.selection.$from.blockRange(state.selection.$to)
  // See if it is possible to wrap that range in a note group
  let wrapping = findWrapping(range, noteSchema.nodes.notegroup)
  // If not, the command doesn't apply
  if (!wrapping) return false
  // Otherwise, dispatch a transaction, using the `wrap` method to
  // create the step that does the actual wrapping.
  if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView())
  return true
}
// }
github ProseMirror / prosemirror-commands / src / commands.js View on Github external
return function(state, dispatch) {
    let {$from, $to} = state.selection
    let range = $from.blockRange($to), wrapping = range && findWrapping(range, nodeType, attrs)
    if (!wrapping) return false
    if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView())
    return true
  }
}
github chanzuckerberg / czi-prosemirror / xxx / wrapInList.js View on Github external
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 zodiac-team / zodiac-ui / libs / editor / src / plugins / block-type / keymap.ts View on Github external
return function(state: EditorState, dispatch) {
        let { tr } = state
        const { $from, $to } = state.selection
        const { paragraph } = state.schema.nodes
        const { alignment, indentation } = state.schema.marks

        /** Alignment or Indentation is not valid inside block types */
        const removeAlignTr = removeBlockMarks(state, [alignment, indentation])
        tr = removeAlignTr || tr

        const range = $from.blockRange($to) as any
        const wrapping = range && (findWrapping(range, type) as any)
        if (range && wrapping) {
            tr.wrap(range, wrapping).scrollIntoView()
        } else {
            /** We always want to append a block type */
            tr.replaceRangeWith(
                $to.pos + 1,
                $to.pos + 1,
                type.createAndFill({}, paragraph.create()),
            )
            tr.setSelection(Selection.near(tr.doc.resolve(state.selection.to + 1)))
        }
        if (dispatch) {
            dispatch(tr)
        }
        return true
    }