feat: Integrate input rules and paste rules into the core (#1997)
* refactoring * improve link regex * WIP: add new markPasteRule und linkify to image mark * move copy of inputrule to core * trigger codeblock inputrule on enter * refactoring * add regex match to markpasterulematch * refactoring * improve link regex * WIP: add new markPasteRule und linkify to image mark * move copy of inputrule to core * trigger codeblock inputrule on enter * refactoring * add regex match to markpasterulematch * update linkify * wip * wip * log * wip * remove debug code * wip * wip * wip * wip * wip * wip * wip * wip * rename matcher * add data to ExtendedRegExpMatchArray * remove logging * add code option to marks, prevent inputrules in code mark * remove link regex * fix codeblock inputrule on enter * refactoring * refactoring * refactoring * refactoring * fix position bug * add test * export InputRule and PasteRule * clean up link demo * fix types
This commit is contained in:
37
packages/core/src/helpers/createChainableState.ts
Normal file
37
packages/core/src/helpers/createChainableState.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { EditorState, Transaction } from 'prosemirror-state'
|
||||
|
||||
export default function createChainableState(config: {
|
||||
transaction: Transaction,
|
||||
state: EditorState,
|
||||
}): EditorState {
|
||||
const { state, transaction } = config
|
||||
let { selection } = transaction
|
||||
let { doc } = transaction
|
||||
let { storedMarks } = transaction
|
||||
|
||||
return {
|
||||
...state,
|
||||
schema: state.schema,
|
||||
plugins: state.plugins,
|
||||
apply: state.apply.bind(state),
|
||||
applyTransaction: state.applyTransaction.bind(state),
|
||||
reconfigure: state.reconfigure.bind(state),
|
||||
toJSON: state.toJSON.bind(state),
|
||||
get storedMarks() {
|
||||
return storedMarks
|
||||
},
|
||||
get selection() {
|
||||
return selection
|
||||
},
|
||||
get doc() {
|
||||
return doc
|
||||
},
|
||||
get tr() {
|
||||
selection = transaction.selection
|
||||
doc = transaction.doc
|
||||
storedMarks = transaction.storedMarks
|
||||
|
||||
return transaction
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -108,10 +108,11 @@ export default function getSchemaByResolvedExtensions(extensions: Extensions): S
|
||||
|
||||
const schema: MarkSpec = cleanUpSchemaItem({
|
||||
...extraMarkFields,
|
||||
inclusive: callOrReturn(getExtensionField<NodeConfig['inclusive']>(extension, 'inclusive', context)),
|
||||
excludes: callOrReturn(getExtensionField<NodeConfig['excludes']>(extension, 'excludes', context)),
|
||||
group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),
|
||||
spanning: callOrReturn(getExtensionField<NodeConfig['spanning']>(extension, 'spanning', context)),
|
||||
inclusive: callOrReturn(getExtensionField<MarkConfig['inclusive']>(extension, 'inclusive', context)),
|
||||
excludes: callOrReturn(getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context)),
|
||||
group: callOrReturn(getExtensionField<MarkConfig['group']>(extension, 'group', context)),
|
||||
spanning: callOrReturn(getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context)),
|
||||
code: callOrReturn(getExtensionField<MarkConfig['code']>(extension, 'code', context)),
|
||||
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
|
||||
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
|
||||
})),
|
||||
|
||||
Reference in New Issue
Block a user