{"version":3,"file":"ngx-editor-commands.mjs","sources":["../../../projects/ngx-editor/commands/removeLink.ts","../../../projects/ngx-editor/commands/applyMark.ts","../../../projects/ngx-editor/commands/removeMark.ts","../../../projects/ngx-editor/commands/ngx-editor-commands.ts"],"sourcesContent":["import { EditorState, Transaction, type Command } from 'prosemirror-state';\n\nexport const removeLink = (): Command => {\n return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {\n const { doc, selection, tr } = state;\n const { $head: { pos }, from, to } = selection;\n\n // if the cursor is on the link without any selection\n if (from === to) {\n const $pos = doc.resolve(pos);\n const linkStart = pos - $pos.textOffset;\n const linkEnd = linkStart + $pos.parent.child($pos.index()).nodeSize;\n\n tr.removeMark(linkStart, linkEnd);\n } else {\n tr.removeMark(from, to);\n }\n\n if (!tr.docChanged) {\n return false;\n }\n\n dispatch?.(tr);\n return true;\n };\n};\n\nexport default removeLink;\n","import { MarkType } from 'prosemirror-model';\nimport { EditorState, TextSelection, Transaction, type Command } from 'prosemirror-state';\n\nimport { markApplies } from 'ngx-editor/helpers';\n\n// Ref: https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.js\nexport const applyMark = (type: MarkType, attrs: Record = {}): Command => {\n return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {\n const { tr, selection } = state;\n const { empty, ranges, $from, $to } = selection;\n\n if (empty && selection instanceof TextSelection) {\n const { $cursor } = selection;\n\n if (!$cursor || !markApplies(state.doc, ranges, type)) {\n return false;\n }\n\n tr.addStoredMark(type.create(attrs));\n if (!tr.storedMarksSet) {\n return false;\n }\n\n dispatch?.(tr);\n } else {\n tr.addMark($from.pos, $to.pos, type.create(attrs));\n\n if (!tr.docChanged) {\n return false;\n }\n\n dispatch?.(tr.scrollIntoView());\n }\n\n return true;\n };\n};\n","import { MarkType } from 'prosemirror-model';\nimport { EditorState, TextSelection, Transaction, type Command } from 'prosemirror-state';\n\nimport { markApplies } from 'ngx-editor/helpers';\n\nexport const removeMark = (type: MarkType): Command => {\n return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {\n const { tr, selection, storedMarks, doc } = state;\n const { empty, ranges } = selection;\n\n if (empty && selection instanceof TextSelection) {\n const { $cursor } = selection;\n\n if (!$cursor || !markApplies(state.doc, ranges, type)) {\n return false;\n }\n\n if (type.isInSet(storedMarks || $cursor.marks())) {\n tr.removeStoredMark(type);\n dispatch?.(tr);\n return true;\n }\n } else {\n for (const range of ranges) {\n const { $from, $to } = range;\n const hasMark = doc.rangeHasMark($from.pos, $to.pos, type);\n\n if (hasMark) {\n tr.removeMark($from.pos, $to.pos, type);\n }\n }\n\n if (!tr.docChanged) {\n return false;\n }\n\n dispatch?.(tr.scrollIntoView());\n }\n\n return false;\n };\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,MAAc;AACtC,IAAA,OAAO,CAAC,KAAkB,EAAE,QAAoC,KAAa;QAC3E,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;AACrC,QAAA,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC;;QAG/C,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9B,YAAA,MAAM,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;AACxC,YAAA,MAAM,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;AAErE,YAAA,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACnC,SAAA;AAAM,aAAA;AACL,YAAA,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACzB,SAA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