2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
|
|
|
<div class="ngbfujlo">
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkTextarea :model-value="text" readonly style="margin: 0;"></MkTextarea>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton class="button" primary :disabled="posting || posted" @click="post()">
|
2022-12-19 11:01:30 +01:00
|
|
|
<i v-if="posted" class="ti ti-check"></i>
|
|
|
|
<i v-else class="ti ti-send"></i>
|
2021-04-20 16:22:59 +02:00
|
|
|
</MkButton>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 02:59:05 +01:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkTextarea from '../MkTextarea.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '../MkButton.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import { apiUrl } from '@/config';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { PostBlock } from '@/scripts/hpml/block';
|
|
|
|
import { Hpml } from '@/scripts/hpml/evaluator';
|
2023-04-01 06:42:40 +02:00
|
|
|
import { defaultStore } from '@/store';
|
2023-04-01 06:52:07 +02:00
|
|
|
import { $i } from '@/account';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-01-29 20:37:25 +01:00
|
|
|
components: {
|
|
|
|
MkTextarea,
|
|
|
|
MkButton,
|
|
|
|
},
|
|
|
|
props: {
|
2021-01-30 02:59:05 +01:00
|
|
|
block: {
|
|
|
|
type: Object as PropType<PostBlock>,
|
2022-12-03 11:42:05 +01:00
|
|
|
required: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2020-04-20 14:35:27 +02:00
|
|
|
hpml: {
|
2021-01-30 02:59:05 +01:00
|
|
|
type: Object as PropType<Hpml>,
|
2022-12-03 11:42:05 +01:00
|
|
|
required: true,
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-01-30 02:59:05 +01:00
|
|
|
text: this.hpml.interpolate(this.block.text),
|
2020-01-29 20:37:25 +01:00
|
|
|
posted: false,
|
|
|
|
posting: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2020-04-20 14:35:27 +02:00
|
|
|
'hpml.vars': {
|
2020-01-29 20:37:25 +01:00
|
|
|
handler() {
|
2021-01-30 02:59:05 +01:00
|
|
|
this.text = this.hpml.interpolate(this.block.text);
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2022-12-03 11:42:05 +01:00
|
|
|
deep: true,
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
methods: {
|
2020-04-19 02:05:20 +02:00
|
|
|
upload() {
|
2020-10-18 03:11:34 +02:00
|
|
|
const promise = new Promise((ok) => {
|
2021-01-30 02:59:05 +01:00
|
|
|
const canvas = this.hpml.canvases[this.block.canvasId];
|
2020-04-19 02:05:20 +02:00
|
|
|
canvas.toBlob(blob => {
|
2022-05-26 15:53:09 +02:00
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('file', blob);
|
2023-04-01 06:52:07 +02:00
|
|
|
formData.append('i', $i.token);
|
2023-04-01 06:42:40 +02:00
|
|
|
if (defaultStore.state.uploadFolder) {
|
|
|
|
formData.append('folderId', defaultStore.state.uploadFolder);
|
2020-04-21 17:34:56 +02:00
|
|
|
}
|
2020-04-19 02:05:20 +02:00
|
|
|
|
2022-12-03 11:42:05 +01:00
|
|
|
window.fetch(apiUrl + '/drive/files/create', {
|
2020-04-19 02:05:20 +02:00
|
|
|
method: 'POST',
|
2022-05-26 15:53:09 +02:00
|
|
|
body: formData,
|
2020-04-19 02:05:20 +02:00
|
|
|
})
|
2022-12-03 11:42:05 +01:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(f => {
|
|
|
|
ok(f);
|
|
|
|
});
|
2020-04-19 02:05:20 +02:00
|
|
|
});
|
|
|
|
});
|
2020-10-18 03:11:34 +02:00
|
|
|
os.promiseDialog(promise);
|
|
|
|
return promise;
|
2020-04-19 02:05:20 +02:00
|
|
|
},
|
|
|
|
async post() {
|
2020-01-29 20:37:25 +01:00
|
|
|
this.posting = true;
|
2021-01-30 02:59:05 +01:00
|
|
|
const file = this.block.attachCanvasImage ? await this.upload() : null;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.apiWithDialog('notes/create', {
|
2020-04-19 10:40:46 +02:00
|
|
|
text: this.text === '' ? null : this.text,
|
2020-04-19 02:05:20 +02:00
|
|
|
fileIds: file ? [file.id] : undefined,
|
2020-01-29 20:37:25 +01:00
|
|
|
}).then(() => {
|
|
|
|
this.posted = true;
|
|
|
|
});
|
2022-12-03 11:42:05 +01:00
|
|
|
},
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 10:29:39 +01:00
|
|
|
<style lang="scss" scoped>
|
2020-01-29 20:37:25 +01:00
|
|
|
.ngbfujlo {
|
2020-04-19 02:05:20 +02:00
|
|
|
position: relative;
|
2020-01-30 23:01:45 +01:00
|
|
|
padding: 32px;
|
2020-01-29 20:37:25 +01:00
|
|
|
border-radius: 6px;
|
2020-01-30 23:01:45 +01:00
|
|
|
box-shadow: 0 2px 8px var(--shadow);
|
2020-04-19 02:05:20 +02:00
|
|
|
z-index: 1;
|
2020-01-30 23:01:45 +01:00
|
|
|
|
|
|
|
> .button {
|
|
|
|
margin-top: 32px;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
@media (max-width: 600px) {
|
2020-01-30 23:01:45 +01:00
|
|
|
padding: 16px;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-01-30 23:01:45 +01:00
|
|
|
> .button {
|
2020-01-29 20:37:25 +01:00
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|