@chatwoot/prosemirror-schema
Advanced tools
Comparing version 1.0.15 to 1.0.16
{ | ||
"name": "@chatwoot/prosemirror-schema", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"description": "Schema setup for using prosemirror in chatwoot. Based on 👉 https://github.com/ProseMirror/prosemirror-example-setup/", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -61,92 +61,94 @@ /** | ||
onKeyDown = () => false, | ||
}) => new Plugin({ | ||
key: new PluginKey('mentions'), | ||
}) => { | ||
return new Plugin({ | ||
key: new PluginKey('mentions'), | ||
view() { | ||
return { | ||
update: (view, prevState) => { | ||
const prev = this.key.getState(prevState); | ||
const next = this.key.getState(view.state); | ||
view() { | ||
return { | ||
update: (view, prevState) => { | ||
const prev = this.key.getState(prevState); | ||
const next = this.key.getState(view.state); | ||
const moved = | ||
const moved = | ||
prev.active && next.active && prev.range.from !== next.range.from; | ||
const started = !prev.active && next.active; | ||
const stopped = prev.active && !next.active; | ||
const changed = !started && !stopped && prev.text !== next.text; | ||
const started = !prev.active && next.active; | ||
const stopped = prev.active && !next.active; | ||
const changed = !started && !stopped && prev.text !== next.text; | ||
if (stopped || moved) | ||
onExit({ view, range: prev.range, text: prev.text }); | ||
if (changed && !moved) | ||
onChange({ view, range: next.range, text: next.text }); | ||
if (started || moved) | ||
onEnter({ view, range: next.range, text: next.text }); | ||
}, | ||
}; | ||
}, | ||
state: { | ||
init() { | ||
return { | ||
active: false, | ||
range: {}, | ||
text: null, | ||
if (stopped || moved) | ||
onExit({ view, range: prev.range, text: prev.text }); | ||
if (changed && !moved) | ||
onChange({ view, range: next.range, text: next.text }); | ||
if (started || moved) | ||
onEnter({ view, range: next.range, text: next.text }); | ||
}, | ||
}; | ||
}, | ||
apply(tr, prev) { | ||
const { selection } = tr; | ||
const next = { ...prev }; | ||
state: { | ||
init() { | ||
return { | ||
active: false, | ||
range: {}, | ||
text: null, | ||
}; | ||
}, | ||
if (selection.from === selection.to) { | ||
if ( | ||
selection.from < prev.range.from || | ||
apply(tr, prev) { | ||
const { selection } = tr; | ||
const next = { ...prev }; | ||
if (selection.from === selection.to) { | ||
if ( | ||
selection.from < prev.range.from || | ||
selection.from > prev.range.to | ||
) { | ||
next.active = false; | ||
} | ||
) { | ||
next.active = false; | ||
} | ||
const $position = selection.$from; | ||
const match = matcher($position); | ||
const $position = selection.$from; | ||
const match = matcher($position); | ||
if (match) { | ||
next.active = true; | ||
next.range = match.range; | ||
next.text = match.text; | ||
if (match) { | ||
next.active = true; | ||
next.range = match.range; | ||
next.text = match.text; | ||
} else { | ||
next.active = false; | ||
} | ||
} else { | ||
next.active = false; | ||
} | ||
} else { | ||
next.active = false; | ||
} | ||
if (!next.active) { | ||
next.range = {}; | ||
next.text = null; | ||
} | ||
if (!next.active) { | ||
next.range = {}; | ||
next.text = null; | ||
} | ||
return next; | ||
return next; | ||
}, | ||
}, | ||
}, | ||
props: { | ||
handleKeyDown(view, event) { | ||
const { active } = this.getState(view.state); | ||
props: { | ||
handleKeyDown(view, event) { | ||
const { active } = this.getState(view.state); | ||
if (!active) return false; | ||
if (!active) return false; | ||
return onKeyDown({ view, event }); | ||
}, | ||
decorations(editorState) { | ||
const { active, range } = this.getState(editorState); | ||
return onKeyDown({ view, event }); | ||
}, | ||
decorations(editorState) { | ||
const { active, range } = this.getState(editorState); | ||
if (!active) return null; | ||
if (!active) return null; | ||
return DecorationSet.create(editorState.doc, [ | ||
Decoration.inline(range.from, range.to, { | ||
nodeName: 'span', | ||
class: suggestionClass, | ||
}), | ||
]); | ||
return DecorationSet.create(editorState.doc, [ | ||
Decoration.inline(range.from, range.to, { | ||
nodeName: 'span', | ||
class: suggestionClass, | ||
}), | ||
]); | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184857
5182