UNPKG

ngx-editor

Version:

Rich Text Editor for angular using ProseMirror

1 lines 6.21 kB
{"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 { Command } from 'prosemirror-commands';\nimport { EditorState, Transaction } 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 { Command } from 'prosemirror-commands';\nimport { EditorState, TextSelection, Transaction } 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<string, any> = {}): 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 } from 'prosemirror-state';\n\nimport { markApplies } from 'ngx-editor/helpers';\nimport { Command } from 'prosemirror-commands';\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":";;;MAGa,UAAU,GAAG;IACxB,OAAO,CAAC,KAAkB,EAAE,QAAoC;QAC9D,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;QACrC,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;YAC9B,MAAM,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;YACxC,MAAM,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;YAErE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACnC;aAAM;YACL,EAAE,CA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