introduces v-editable and makes most text elements editable

tiptap
koehr 5 years ago
parent 773ce67d70
commit 456fc9f4bc

@ -128,3 +128,6 @@ button.edit-pencil {
border: none; border: none;
cursor: pointer; cursor: pointer;
} }
[contenteditable="true"] { text-decoration: underline dotted; }
[contenteditable="true"]:focus { text-decoration: none; }

@ -1,7 +1,7 @@
<template> <template>
<p> <p>
<span class="title">{{ params[0] }}</span> <span v-editable:0="editable" class="title">{{ params[0] }}</span>
<span>{{ params[1] }}</span> <span v-editable:1="editable">{{ params[1] }}</span>
</p> </p>
</template> </template>
@ -11,6 +11,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
@Component @Component
export default class DeckCardDescription extends Vue { export default class DeckCardDescription extends Vue {
@Prop() public readonly params!: string[] @Prop() public readonly params!: string[]
@Prop() public readonly editable!: boolean
} }
</script> </script>

@ -1,5 +1,5 @@
<template> <template>
<p>{{ params[0] }}</p> <p v-editable:0="editable">{{ params[0] }}</p>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -8,6 +8,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
@Component @Component
export default class DeckCardNote extends Vue { export default class DeckCardNote extends Vue {
@Prop() public readonly params!: string[] @Prop() public readonly params!: string[]
@Prop() public readonly editable!: boolean
} }
</script> </script>

@ -1,7 +1,7 @@
<template> <template>
<p> <p>
<span class="title">{{ params[0] }}</span> <span class="title" v-editable:0="editable">{{ params[0] }}</span>
<span class="description">{{ params[1] }}</span> <span class="description" v-editable:1="editable">{{ params[1] }}</span>
</p> </p>
</template> </template>
@ -11,6 +11,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
@Component @Component
export default class DeckCardProperty extends Vue { export default class DeckCardProperty extends Vue {
@Prop() public readonly params!: string[] @Prop() public readonly params!: string[]
@Prop() public readonly editable!: boolean
} }
</script> </script>

@ -1,5 +1,5 @@
<template> <template>
<h4>{{ params[0] }}</h4> <h4 v-editable:0="editable">{{ params[0] }}</h4>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -8,6 +8,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
@Component @Component
export default class DeckCardSection extends Vue { export default class DeckCardSection extends Vue {
@Prop() public readonly params!: string[] @Prop() public readonly params!: string[]
@Prop() public readonly editable!: boolean
} }
</script> </script>

@ -1,8 +1,5 @@
<template> <template>
<h3 :contenteditable="editable" <h3 v-editable:0="editable">{{ params[0] }}</h3>
@keypress.enter.prevent="$emit('edit', { param: 0, value: $event.target.innerText })">
{{ params[0] }}
</h3>
</template> </template>
<script lang="ts"> <script lang="ts">

@ -1,5 +1,5 @@
<template> <template>
<p>{{ params[0] }}</p> <p v-editable:0="editable">{{ params[0] }}</p>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -8,6 +8,7 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
@Component @Component
export default class DeckCardText extends Vue { export default class DeckCardText extends Vue {
@Prop() public readonly params!: string[] @Prop() public readonly params!: string[]
@Prop() public readonly editable!: boolean
} }
</script> </script>

@ -251,21 +251,4 @@ export default class DeckCard extends Vue {
height: 3rem; height: 3rem;
margin-top: -3rem; margin-top: -3rem;
} }
[contenteditable="true"] {
position: relative;
}
[contenteditable="true"]::after {
content: ' ';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border-bottom: 1px dotted white;
mix-blend-mode: difference;
}
[contenteditable="true"]:focus::after {
border-bottom: none;
}
</style> </style>

@ -15,6 +15,24 @@ declare module 'vue/types/vue' {
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$storage = new StorageHandler() Vue.prototype.$storage = new StorageHandler()
Vue.directive('editable', (el, { value, arg }, vnode) => {
el.contentEditable = value ? 'true' : 'false'
el.addEventListener('keypress', event => {
// allow line break via Shift + Enter
if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault()
console.log('edit event on enter', el.innerText)
if (!vnode.context) return
vnode.context.$emit('edit', { param: arg, value: el.innerText })
}
})
el.addEventListener('blur', () => {
console.log('edit event on blur', el.innerText)
if (!vnode.context) return
vnode.context.$emit('edit', { param: arg, value: el.innerText })
})
})
new Vue({ new Vue({
router, router,
render: h => h(App) render: h => h(App)

Loading…
Cancel
Save