{"version":3,"file":"PlainTableContentEditor-C-XssoFy.chunk.mjs","sources":["../src/components/Editor/PlainTableContentEditor.vue"],"sourcesContent":["<!--\n  - SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors\n  - SPDX-License-Identifier: AGPL-3.0-or-later\n-->\n\n<template>\n\t<Wrapper :content-loaded=\"true\">\n\t\t<MainContainer>\n\t\t\t<ContentContainer :read-only=\"readOnly\" />\n\t\t</MainContainer>\n\t</Wrapper>\n</template>\n\n<script>\nimport { Editor } from '@tiptap/core'\nimport MainContainer from './MainContainer.vue'\nimport Wrapper from './Wrapper.vue'\n/* eslint-disable import/no-named-as-default */\nimport { UndoRedo } from '@tiptap/extensions'\nimport { provide, watch } from 'vue'\nimport { provideEditor } from '../../composables/useEditor.ts'\nimport { editorFlagsKey } from '../../composables/useEditorFlags.ts'\nimport { useEditorMethods } from '../../composables/useEditorMethods.ts'\nimport { editorWidthKey } from '../../composables/useEditorWidth.ts'\nimport { FocusTrap, PlainTable } from '../../extensions/index.js'\nimport { createMarkdownSerializer } from '../../extensions/Markdown.js'\nimport { EDITOR_UPLOAD } from '../Editor.provider.ts'\nimport ContentContainer from './ContentContainer.vue'\n\nexport default {\n\tname: 'PlainTableContentEditor',\n\tcomponents: { ContentContainer, MainContainer, Wrapper },\n\n\tprops: {\n\t\tcontent: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\treadOnly: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\t},\n\temits: ['update:content'],\n\n\tsetup(props) {\n\t\tconst extensions = [PlainTable, UndoRedo, FocusTrap]\n\t\tconst editor = new Editor({ extensions })\n\n\t\tconst { setEditable, setContent } = useEditorMethods(editor)\n\t\twatch(\n\t\t\t() => props.content,\n\t\t\t(content) => {\n\t\t\t\tsetContent(content)\n\t\t\t},\n\t\t)\n\n\t\tsetEditable(!props.readOnly)\n\t\twatch(\n\t\t\t() => props.readOnly,\n\t\t\t(readOnly) => {\n\t\t\t\tsetEditable(!readOnly)\n\t\t\t},\n\t\t)\n\n\t\tprovideEditor(editor)\n\t\tprovide(editorFlagsKey, {\n\t\t\tisPublic: false,\n\t\t\tisRichEditor: true,\n\t\t\tisRichWorkspace: false,\n\t\t\tuseTableOfContents: false,\n\t\t})\n\t\tprovide(editorWidthKey, null)\n\t\tprovide(EDITOR_UPLOAD, false)\n\t\treturn { editor, setContent }\n\t},\n\n\tcreated() {\n\t\t// Set content after the setup function\n\t\t// as it may render other vue components such as preview toggle\n\t\t// which breaks the context of the setup function.\n\t\tthis.setContent(this.content, { addToHistory: false })\n\t\tthis.editor.on('create', () => {\n\t\t\tthis.$emit('ready')\n\t\t\tthis.$parent.$emit('ready')\n\n\t\t\t// Emit initial content\n\t\t\ttry {\n\t\t\t\tconst markdown = createMarkdownSerializer(\n\t\t\t\t\tthis.editor.schema,\n\t\t\t\t).serialize(this.editor.state.doc)\n\t\t\t\tthis.emit('create:content', {\n\t\t\t\t\tjson: this.editor.state.doc,\n\t\t\t\t\tmarkdown,\n\t\t\t\t})\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error serializing table:', error)\n\t\t\t}\n\t\t})\n\t\tthis.editor.on('update', ({ editor }) => {\n\t\t\ttry {\n\t\t\t\tconst markdown = createMarkdownSerializer(editor.schema).serialize(\n\t\t\t\t\teditor.state.doc,\n\t\t\t\t)\n\t\t\t\tthis.emit('update:content', {\n\t\t\t\t\tjson: editor.state.doc,\n\t\t\t\t\tmarkdown,\n\t\t\t\t})\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error serializing table:', error)\n\t\t\t}\n\t\t})\n\t},\n\n\tbeforeDestroy() {\n\t\tthis.editor.destroy()\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Wrapper to emit events on our own and the parent component\n\t\t *\n\t\t * @param {string} event The event name\n\t\t * @param {any} data The data to pass along\n\t\t */\n\t\temit(event, data) {\n\t\t\tthis.$emit(event, data)\n\t\t\tthis.$parent?.$emit(event, data)\n\t\t},\n\t},\n}\n</script>\n\n<style lang=\"scss\">\n@use './../../css/prosemirror';\n@use './../../css/print';\n</style>\n"],"names":["_sfc_main","ContentContainer","MainContainer","Wrapper","props","extensions","PlainTable","UndoRedo","FocusTrap","editor","Editor","setEditable","setContent","useEditorMethods","watch","content","readOnly","provideEditor","provide","editorFlagsKey","editorWidthKey","EDITOR_UPLOAD","markdown","createMarkdownSerializer","error","event","data"],"mappings":"uqBA6BA,MAAAA,EAAA,CACA,KAAA,0BACA,WAAA,CAAA,iBAAAC,EAAA,cAAAC,EAAA,QAAAC,CAAA,EAEA,MAAA,CACA,QAAA,CACA,KAAA,OACA,SAAA,EACA,EACA,SAAA,CACA,KAAA,QACA,QAAA,EACA,CACA,EACA,MAAA,CAAA,gBAAA,EAEA,MAAAC,EAAA,CACA,MAAAC,EAAA,CAAAC,EAAAC,EAAAC,CAAA,EACAC,EAAA,IAAAC,EAAA,CAAA,WAAAL,CAAA,CAAA,EAEA,CAAA,YAAAM,EAAA,WAAAC,CAAA,EAAAC,EAAAJ,CAAA,EACA,OAAAK,EACA,IAAAV,EAAA,QACAW,GAAA,CACAH,EAAAG,CAAA,CACA,CACA,EAEAJ,EAAA,CAAAP,EAAA,QAAA,EACAU,EACA,IAAAV,EAAA,SACAY,GAAA,CACAL,EAAA,CAAAK,CAAA,CACA,CACA,EAEAC,EAAAR,CAAA,EACAS,EAAAC,EAAA,CACA,SAAA,GACA,aAAA,GACA,gBAAA,GACA,mBAAA,EACA,CAAA,EACAD,EAAAE,EAAA,IAAA,EACAF,EAAAG,EAAA,EAAA,EACA,CAAA,OAAAZ,EAAA,WAAAG,CAAA,CACA,EAEA,SAAA,CAIA,KAAA,WAAA,KAAA,QAAA,CAAA,aAAA,EAAA,CAAA,EACA,KAAA,OAAA,GAAA,SAAA,IAAA,CACA,KAAA,MAAA,OAAA,EACA,KAAA,QAAA,MAAA,OAAA,EAGA,GAAA,CACA,MAAAU,EAAAC,EACA,KAAA,OAAA,MACA,EA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