Переход на Vue 3, в процессе

This commit is contained in:
Book Pauk
2021-10-29 15:27:04 +07:00
parent 00cb2dc274
commit 76e09ef34e
7 changed files with 31 additions and 25 deletions

View File

@@ -85,36 +85,42 @@ class App {
//sanitize
this.$root.sanitize = sanitizeHtml;
//global keyHooks
this.keyHooks = [];
this.keyHook = (event) => {
for (const hook of this.keyHooks)
//global event hooks
this.eventHooks = {};
this.eventHook = (hookName, event) => {
if (!this.eventHooks[hookName])
return;
for (const hook of this.eventHooks[hookName])
hook(event);
}
this.$root.addKeyHook = (hook) => {
if (this.keyHooks.indexOf(hook) < 0)
this.keyHooks.push(hook);
this.$root.addEventHook = (hookName, hook) => {
if (!this.eventHooks[hookName])
this.eventHooks[hookName] = [];
if (this.eventHooks[hookName].indexOf(hook) < 0)
this.eventHooks[hookName].push(hook);
}
this.$root.removeKeyHook = (hook) => {
const i = this.keyHooks.indexOf(hook);
this.$root.removeEventHook = (hookName, hook) => {
if (!this.eventHooks[hookName])
return;
const i = this.eventHooks[hookName].indexOf(hook);
if (i >= 0)
this.keyHooks.splice(i, 1);
this.eventHooks[hookName].splice(i, 1);
}
document.addEventListener('keyup', (event) => {
this.keyHook(event);
this.eventHook('key', event);
});
document.addEventListener('keypress', (event) => {
this.keyHook(event);
this.eventHook('key', event);
});
document.addEventListener('keydown', (event) => {
this.keyHook(event);
this.eventHook('key', event);
});
window.addEventListener('resize', () => {
this.$root.$emit('resize');
window.addEventListener('resize', (event) => {
this.eventHook('resize', event);
});
}

View File

@@ -62,9 +62,9 @@
:nodes="nodes"
node-key="key"
tick-strategy="leaf"
:selected.sync="selected"
:ticked.sync="ticked"
:expanded.sync="expanded"
v-model:selected="selected"
v-model:ticked="ticked"
v-model:expanded="expanded"
selected-color="black"
:filter="search"
no-nodes-label="Закладок пока нет"

View File

@@ -270,9 +270,9 @@ class ExternalLibs {
created() {
this.oldStartLink = '';
this.justOpened = true;
this.$root.addKeyHook(this.keyHook);
this.$root.addEventHook('key', this.keyHook);
this.$root.$on('resize', async() => {
this.$root.addEventHook('resize', async() => {
await utils.sleep(200);
this.frameResize();
});

View File

@@ -279,7 +279,7 @@ class Reader {
this.reader = this.$store.state.reader;
this.config = this.$store.state.config;
this.$root.addKeyHook(this.keyHook);
this.$root.addEventHook('key', this.keyHook);
this.lastActivePage = false;

View File

@@ -14,7 +14,7 @@
:data="tableData"
:columns="columns"
row-key="key"
:pagination.sync="pagination"
v-model:pagination="pagination"
separator="cell"
hide-bottom
virtual-scroll

View File

@@ -149,7 +149,7 @@ class TextPage {
await this.doPageAnimation();
}, 10);
this.$root.$on('resize', async() => {
this.$root.addEventHook('resize', async() => {
this.$nextTick(this.onResize);
await utils.sleep(500);
this.$nextTick(this.onResize);

View File

@@ -148,8 +148,8 @@ class StdDialog {
hotKeyCode = '';
created() {
if (this.$root.addKeyHook) {
this.$root.addKeyHook(this.keyHook);
if (this.$root.addEventHook) {
this.$root.addEventHook('key', this.keyHook);
}
}