prosemirror-trailing-node
Advanced tools
Comparing version
@@ -6,18 +6,17 @@ // src/trailing-node-plugin.ts | ||
function trailingNode(options) { | ||
const { | ||
ignoredNodes = [], | ||
nodeName = "paragraph" | ||
} = options ?? {}; | ||
const ignoredNodeNames = uniqueArray([...ignoredNodes, nodeName]); | ||
let type; | ||
let types; | ||
var _ref = options !== null && options !== void 0 ? options : {}, | ||
_ref$ignoredNodes = _ref.ignoredNodes, | ||
ignoredNodes = _ref$ignoredNodes === void 0 ? [] : _ref$ignoredNodes, | ||
_ref$nodeName = _ref.nodeName, | ||
nodeName = _ref$nodeName === void 0 ? "paragraph" : _ref$nodeName; | ||
var ignoredNodeNames = uniqueArray([...ignoredNodes, nodeName]); | ||
var type; | ||
var types; | ||
return new Plugin({ | ||
key: trailingNodePluginKey, | ||
appendTransaction(_, __, state) { | ||
const { | ||
doc, | ||
tr | ||
} = state; | ||
const shouldInsertNodeAtEnd = trailingNodePluginKey.getState(state); | ||
const endPosition = doc.content.size; | ||
var doc = state.doc, | ||
tr = state.tr; | ||
var shouldInsertNodeAtEnd = trailingNodePluginKey.getState(state); | ||
var endPosition = doc.content.size; | ||
if (!shouldInsertNodeAtEnd) { | ||
@@ -29,19 +28,20 @@ return; | ||
state: { | ||
init: (_, { | ||
doc, | ||
schema | ||
}) => { | ||
const nodeType = schema.nodes[nodeName]; | ||
init: (_, _ref2) => { | ||
var _doc$lastChild; | ||
var doc = _ref2.doc, | ||
schema = _ref2.schema; | ||
var nodeType = schema.nodes[nodeName]; | ||
if (!nodeType) { | ||
throw new Error(`Invalid node being used for trailing node extension: '${nodeName}'`); | ||
throw new Error("Invalid node being used for trailing node extension: '".concat(nodeName, "'")); | ||
} | ||
type = nodeType; | ||
types = Object.values(schema.nodes).map(node => node).filter(node => !ignoredNodeNames.includes(node.name)); | ||
return includes(types, doc.lastChild?.type); | ||
return includes(types, (_doc$lastChild = doc.lastChild) === null || _doc$lastChild === void 0 ? void 0 : _doc$lastChild.type); | ||
}, | ||
apply: (tr, value) => { | ||
var _tr$doc$lastChild; | ||
if (!tr.docChanged) { | ||
return value; | ||
} | ||
return includes(types, tr.doc.lastChild?.type); | ||
return includes(types, (_tr$doc$lastChild = tr.doc.lastChild) === null || _tr$doc$lastChild === void 0 ? void 0 : _tr$doc$lastChild.type); | ||
} | ||
@@ -48,0 +48,0 @@ } |
{ | ||
"name": "prosemirror-trailing-node", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "A trailing node plugin for the prosemirror editor.", | ||
@@ -33,4 +33,4 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-trailing-node", | ||
"dependencies": { | ||
"@remirror/core-constants": "3.0.0-beta.0", | ||
"@remirror/core-helpers": "4.0.0-beta.0", | ||
"@remirror/core-constants": "3.0.0-beta.1", | ||
"@remirror/core-helpers": "4.0.0-beta.1", | ||
"escape-string-regexp": "^4.0.0" | ||
@@ -37,0 +37,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
56696
10.25%325
14.84%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed