From 888addc4f4ef6e27cf03a4bbf373a38c7f2c6b0f Mon Sep 17 00:00:00 2001 From: liujia02 Date: Tue, 30 Mar 2021 11:00:40 +0800 Subject: [PATCH] refactor(global): update slate version, solve vue3 runtime problem --- packages/slate-vue-shared/package.json | 2 +- .../slate-vue-shared/plugins/runtime-util.ts | 20 ++++++++++--------- packages/slate-vue/components/children.tsx | 6 +++--- packages/slate-vue/components/leaf.tsx | 4 ++-- packages/slate-vue/components/text.tsx | 2 +- packages/slate-vue/package.json | 2 +- packages/slate-vue/plugins/runtime-util.ts | 4 ++-- packages/slate-vue/plugins/with-vue.ts | 2 ++ yarn.lock | 14 +++++++++---- 9 files changed, 33 insertions(+), 23 deletions(-) diff --git a/packages/slate-vue-shared/package.json b/packages/slate-vue-shared/package.json index 44ba439..5a9422c 100644 --- a/packages/slate-vue-shared/package.json +++ b/packages/slate-vue-shared/package.json @@ -3,7 +3,7 @@ "version": "0.2.0", "dependencies": { "is-hotkey": "^0.2.0", - "slate": "^0.59.0", + "slate": "^0.60.2", "vue": "^2.6.11" }, "main": "./dist/index.cjs.js", diff --git a/packages/slate-vue-shared/plugins/runtime-util.ts b/packages/slate-vue-shared/plugins/runtime-util.ts index a637f63..54f3e4e 100644 --- a/packages/slate-vue-shared/plugins/runtime-util.ts +++ b/packages/slate-vue-shared/plugins/runtime-util.ts @@ -1,9 +1,9 @@ -import { Editor, Operation, Node, Path, Text, Descendant, NodeEntry, Transforms as SlateTransforms, Location } from 'slate'; +import { Editor, Operation, Node, Path, Text, Descendant, NodeEntry, Transforms as SlateTransforms, Location, Element } from 'slate'; import { NODE_TO_KEY } from '../utils'; -import Vue from 'vue' +import { VueEditor } from './vue-editor'; export const getChildren = (node: Node): any => { - return Editor.isEditor(node) ? node._state: node.children + return Editor.isEditor(node) ? (node as VueEditor)._state: (node as Element).children } export const clone = (node: any): any => { @@ -11,7 +11,7 @@ export const clone = (node: any): any => { } // a minimum version of Editor.transform for runtime -export const transform = function(editor: Editor, op: Operation) { +export const transform = function(editor: Editor, op: Operation, Vue?: any) { switch (op.type) { case 'insert_node': { const { path, node } = op @@ -118,12 +118,14 @@ export const transform = function(editor: Editor, op: Operation) { throw new Error(`Cannot set the "${key}" property of nodes!`) } - const value = newProperties[key] + const value = (newProperties as any)[key] - if (value == null) { - Vue.delete(node, key) - } else { - Vue.set(node, key, value) + if(Vue) { + if (value == null) { + Vue.delete(node, key) + } else { + Vue.set(node, key, value) + } } } diff --git a/packages/slate-vue/components/children.tsx b/packages/slate-vue/components/children.tsx index 419ff33..7b1542a 100644 --- a/packages/slate-vue/components/children.tsx +++ b/packages/slate-vue/components/children.tsx @@ -38,7 +38,7 @@ export const Children: any = tsx.component({ !editor.isInline(node) && Editor.hasInlines(editor, node) const children = [] - const childArr = Editor.isEditor(node) ? node._state as any : (node as Element).children + const childArr: any = Editor.isEditor(node) ? (node as VueEditor)._state : (node as Element).children // cacheVnode in manual to reuse let cacheVnode = null; for(let i=0;i{children}; } diff --git a/packages/slate-vue/components/leaf.tsx b/packages/slate-vue/components/leaf.tsx index b1d6aa8..c234e1a 100644 --- a/packages/slate-vue/components/leaf.tsx +++ b/packages/slate-vue/components/leaf.tsx @@ -35,7 +35,7 @@ const Leaf = tsx.component({ let children = ( ); - if (leaf[PLACEHOLDER_SYMBOL]) { + if ((leaf as any)[PLACEHOLDER_SYMBOL]) { children = ( - {leaf.placeholder} + {(leaf as any).placeholder} {children} diff --git a/packages/slate-vue/components/text.tsx b/packages/slate-vue/components/text.tsx index 064654f..ab315ab 100644 --- a/packages/slate-vue/components/text.tsx +++ b/packages/slate-vue/components/text.tsx @@ -71,7 +71,7 @@ const Text = tsx.component({ }, render(h, ctx): VNode { const { text, placeholder } = this - let decorations: Array = this.decorations; + let decorations: Array = this.decorations; if(!decorations) { const editor = this.$editor const p = VueEditor.findPath(editor, text) diff --git a/packages/slate-vue/package.json b/packages/slate-vue/package.json index 47784ac..1b9cf90 100644 --- a/packages/slate-vue/package.json +++ b/packages/slate-vue/package.json @@ -4,7 +4,7 @@ "dependencies": { "direction": "^1.0.4", "is-hotkey": "^0.2.0", - "slate": "^0.59.0", + "slate": "^0.60.2", "slate-vue-shared": "^0.2.0", "vue": "^2.6.11", "vue-tsx-support": "^3.0.0" diff --git a/packages/slate-vue/plugins/runtime-util.ts b/packages/slate-vue/plugins/runtime-util.ts index d760660..005cad1 100644 --- a/packages/slate-vue/plugins/runtime-util.ts +++ b/packages/slate-vue/plugins/runtime-util.ts @@ -3,7 +3,7 @@ import { NODE_TO_KEY } from 'slate-vue-shared'; import Vue from 'vue' export const getChildren = (node: Node): any => { - return Editor.isEditor(node) ? node._state: node.children + return Editor.isEditor(node) ? (node as any)._state: (node as any).children } export const clone = (node: any): any => { @@ -118,7 +118,7 @@ export const transform = function(editor: Editor, op: Operation) { throw new Error(`Cannot set the "${key}" property of nodes!`) } - const value = newProperties[key] + const value = (newProperties as any)[key] if (value == null) { Vue.delete(node, key) diff --git a/packages/slate-vue/plugins/with-vue.ts b/packages/slate-vue/plugins/with-vue.ts index 859f66e..4113c3f 100644 --- a/packages/slate-vue/plugins/with-vue.ts +++ b/packages/slate-vue/plugins/with-vue.ts @@ -2,6 +2,8 @@ import { Editor, Node, Path, Operation, Transforms, Range } from 'slate' import { VueEditor } from './vue-editor' import { Key, isDOMText, getPlainText, EDITOR_TO_ON_CHANGE, NODE_TO_KEY } from 'slate-vue-shared' + +// TODO: common runtime in shared import {vueRuntime} from './vue-runtime'; import {transform} from './runtime-util'; diff --git a/yarn.lock b/yarn.lock index ea01ecb..ddfdc78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7173,6 +7173,11 @@ immer@^5.0.0: version "5.3.6" resolved "https://registry.yarnpkg.com/immer/-/immer-5.3.6.tgz#51eab8cbbeb13075fe2244250f221598818cac04" +immer@^7.0.0: + version "7.0.15" + resolved "https://registry.yarnpkg.com/immer/-/immer-7.0.15.tgz#dc3bc6db87401659d2e737c67a21b227c484a4ad" + integrity sha512-yM7jo9+hvYgvdCQdqvhCNRRio0SCXc8xDPzA25SvKWa7b1WVPjLwQs1VYU5JPXjcJPTqAa5NP5dqpORGYBQ2AA== + import-fresh@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-2.0.0.tgz#d81355c15612d386c61f9ddd3922d4304822a546" @@ -11139,13 +11144,14 @@ slate-hyperscript@^0.59.0: dependencies: is-plain-object "^3.0.0" -slate@^0.59.0: - version "0.59.0" - resolved "https://registry.yarnpkg.com/slate/-/slate-0.59.0.tgz#3169daf2f036e84aa149f60e0d12ef2fc4c0839e" +slate@^0.60.2: + version "0.60.2" + resolved "https://registry.yarnpkg.com/slate/-/slate-0.60.2.tgz#1725949bf5dd7334d90a2efdc0e29479abe532b5" + integrity sha512-VM9neWcTuPglLBLzG4Pot8oarGkvjEHWXBxuRDrnrGYUbs6CdEZRRtKPM+2Ku61GcoBZqobq3S182NzFDrnwvQ== dependencies: "@types/esrever" "^0.2.0" esrever "^0.2.0" - immer "^5.0.0" + immer "^7.0.0" is-plain-object "^3.0.0" tiny-warning "^1.0.3"