Skip to content

Commit 81a504a

Browse files
committed
WIP
1 parent 70d8bb4 commit 81a504a

4 files changed

Lines changed: 49 additions & 20 deletions

File tree

src/components/Editor/PreviewOptions.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@
2727
<NcActionCaption :name="t('text', 'Preview options')" />
2828
<NcActionRadio data-text-preview-option="text-only"
2929
close-after-click
30+
name="preview-option"
3031
value="text-only"
31-
@change="$emit('change')">
32+
:checked="value === 'text-only'"
33+
@change="e => $emit('update:value', e.currentTarget.value)">
3234
{{ t('text', 'Text only') }}
3335
</NcActionRadio>
3436
<NcActionRadio data-text-preview-option="link-preview"
3537
close-after-click
36-
:checked="true"
37-
value="link-preview">
38+
name="preview-option"
39+
value="link-preview"
40+
:checked="value === 'link-preview'"
41+
@change="e => $emit('update:value', e.currentTarget.value)">
3842
{{ t('text', 'Show link preview') }}
3943
</NcActionRadio>
4044
</NcActions>
@@ -46,6 +50,12 @@ import DotsVerticalIcon from 'vue-material-design-icons/DotsVertical.vue'
4650
4751
export default {
4852
name: 'PreviewOptions',
53+
props: {
54+
value: {
55+
type: String,
56+
required: true,
57+
},
58+
},
4959
components: {
5060
DotsVerticalIcon,
5161
NcActions,

src/nodes/ParagraphView.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
<template>
2424
<NodeViewWrapper class="vue-component" as="p">
2525
<PreviewOptions v-if="editor.isEditable && href"
26-
@change="convertToLink" />
26+
:value.sync="value"
27+
@update:value="convertToPreview" />
2728
<NodeViewContent class="paragraph-content" />
2829
</NodeViewWrapper>
2930
</template>
3031

3132
<script>
3233
import { NodeViewContent, nodeViewProps, NodeViewWrapper } from '@tiptap/vue-2'
3334
import PreviewOptions from '../components/Editor/PreviewOptions.vue'
35+
import { useEditorMixin } from '../components/Editor.provider.js'
3436
import { getCurrentUser } from '@nextcloud/auth'
3537
import debounce from 'debounce'
3638
@@ -46,8 +48,10 @@ export default {
4648
return {
4749
href: null,
4850
isLoggedIn: getCurrentUser(),
51+
value: 'text-only',
4952
}
5053
},
54+
mixins: [ useEditorMixin ],
5155
watch: {
5256
node: {
5357
handler(newNode) {
@@ -71,6 +75,14 @@ export default {
7175
this.debouncedUpdateText?.cancel()
7276
},
7377
methods: {
78+
convertToPreview(...args) {
79+
console.info(...args)
80+
this.$editor.chain()
81+
.focus()
82+
.setTextSelection(this.getPos())
83+
.togglePreview({ href: this.href })
84+
.run()
85+
},
7486
getTextReference(node) {
7587
if (!node?.childCount) {
7688
return null

src/nodes/Preview.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,13 @@ export default Node.create({
7878

7979
addCommands() {
8080
return {
81-
setPreview: attributes => ({ commands }) => {
82-
return commands.wrapIn(this.name, attributes)
81+
setPreview: attrs => ({ commands }) => {
82+
const attributes = { ...attrs, title: 'preview' }
83+
return commands.setNode(this.name, attributes)
8384
},
84-
togglePreview: attributes => ({ commands, state }) => {
85-
if (!isNodeActive(state, this.name)) {
86-
return commands.setPreview(attributes)
87-
}
88-
89-
if (!isNodeActive(state, this.name, attributes)) {
90-
return commands.updateAttributes(this.name, attributes)
91-
}
92-
93-
return commands.unsetPreview()
94-
},
95-
unsetPreview: () => ({ commands }) => {
96-
return commands.lift(this.name)
85+
togglePreview: attrs => ({ commands }) => {
86+
const attributes = { ...attrs, title: 'preview' }
87+
return commands.toggleNode(this.name, 'paragraph', attributes)
9788
},
9889
}
9990
},

src/nodes/Preview.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
contenteditable="false">
2727
<NodeViewContent style="display:none" />
2828
<PreviewOptions v-if="editor.isEditable"
29-
@change="convertToLink" />
29+
:value.sync="value"
30+
@update:value="convertToParagraph" />
3031
<NcReferenceList :text="node.attrs.href"
3132
:limit="1" />
3233
</NodeViewWrapper>
@@ -46,6 +47,21 @@ export default {
4647
PreviewOptions,
4748
},
4849
props: nodeViewProps,
50+
data() {
51+
return {
52+
value: 'link-preview',
53+
}
54+
},
55+
methods: {
56+
convertToParagraph(...args) {
57+
console.info(...args)
58+
this.$editor.chain()
59+
.focus()
60+
.setTextSelection(this.getPos())
61+
.setNode('paragaph')
62+
.run()
63+
},
64+
},
4965
}
5066
</script>
5167

0 commit comments

Comments
 (0)