Questions about transactions, node positions, immutability, etc #5879
-
Hello, I have a project with 2 components:
I'm passing (via props) a Here is the (simplified) code of the two components: Sidebar.vue: <template>
<div v-if="select_editor">
<SelectMargin
:editor="select_editor"
:selected="selected"
@select-margin="(p) => do_select_margin(p)"
/>
</template>
<script setup>
import { ref, computed, unref, watch } from 'vue'
import { useEditorStore } from '@/stores/editor'
import SelectMargin from '@/components/editor/tiptap/margin/SelectMargin.vue'
const { getEditor, editors } = useEditorStore()
const select_editor = editors.get('current')
const some_pos = select_editor.value.$pos(1234)
const selected = ref({
node: some_pos.node,
pos: some_pos.pos
})
const do_select_margin = ({side, level, breakpoint}) => {
const s = unref(selected)
select_editor.value.chain().focus().setMargin({
side: side,
level: level,
breakpoint: breakpoint,
selected: s
}).run()
const foo = select_editor.value.$pos(s.pos+1)
selected.value.node = foo.node
}
})
</script> SelectMargin.vue: <template>
<Listbox as="div" v-model="ml">
<ListboxButton>left: {{ ml }}</ListboxButton>
<ListboxOptions>
<ListboxOption v-for="level in levels" :key="level" :value="level" >
<button>{{ level }}</button>
</ListboxOption>
</ListboxOptions>
</Listbox>
</div>
</template>
<script setup>
import { watch, ref, computed } from 'vue'
import { getSelectedAttrs } from '@/components/editor/tiptap/utils'
const props = defineProps({
editor: Object,
selected: Object,
})
const emits = defineEmits(['select-margin'])
const levels = computed(() => props.extension.options.levels)
const get_side = (side) => {
try {
return getSelectedAttrs(props, side)
} catch (e) {
return 'none'
}
}
const set_side = (side, value) => {
emits('select-margin', {
side: side,
level: value,
breakpoint: props.breakpoint
})
}
const ml = computed({
get() { return get_side('ml') },
set(value) { set_side('ml', value) }
}) Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You are really going to have to simplify this example. There is way too much going on to even understand what your question is |
Beta Was this translation helpful? Give feedback.
Ah, okay. Yea Nodes are immutable so you are keeping a reference to an object that is not being mutated.
So, you can either try to hack around this by "refreshing" the value or somehow making this variable by derived from the state of the editor (e.g. storing the selected value in an extensions storage & listing for changes to that storage object).