Skip to content

Commit

Permalink
refactor(global): update slate version, solve vue3 runtime problem
Browse files Browse the repository at this point in the history
  • Loading branch information
marsprince committed Mar 30, 2021
1 parent fcb9cfd commit 888addc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/slate-vue-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 11 additions & 9 deletions packages/slate-vue-shared/plugins/runtime-util.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 => {
return JSON.parse(JSON.stringify(node))
}

// 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
Expand Down Expand Up @@ -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)
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/slate-vue/components/children.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<childArr.length;i++) {
Expand All @@ -53,7 +53,7 @@ export const Children: any = tsx.component({
// when modify vnode, only new vnode or spliting vnode must be update, others will be reuse
// #62, #63: sometimes(like paste) no cacheVnode but have key, avoid getting in
if(editor._operation && KEY_TO_VNODE.get(key)) {
const operationPath = editor._operation.path as Path
const operationPath = (editor._operation as any).path as Path
// split_node
if(editor._operation.type === 'split_node') {
// only sibling
Expand Down Expand Up @@ -105,7 +105,7 @@ export const Children: any = tsx.component({
children.push(cacheVnode)
}
// set key and vnode
KEY_TO_VNODE.set(key, cacheVnode)
KEY_TO_VNODE.set(key, cacheVnode as any)
}
return <fragment>{children}</fragment>;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/slate-vue/components/leaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Leaf = tsx.component({
let children = (
<string text={text} editor={this.$editor} leaf={leaf}/>
);
if (leaf[PLACEHOLDER_SYMBOL]) {
if ((leaf as any)[PLACEHOLDER_SYMBOL]) {
children = (
<fragment>
<span
Expand All @@ -50,7 +50,7 @@ const Leaf = tsx.component({
opacity: '0.333',
}}
>
{leaf.placeholder}
{(leaf as any).placeholder}
</span>
{children}
</fragment>
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-vue/components/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Text = tsx.component({
},
render(h, ctx): VNode {
const { text, placeholder } = this
let decorations: Array<Range> = this.decorations;
let decorations: Array<any> = this.decorations;
if(!decorations) {
const editor = this.$editor
const p = VueEditor.findPath(editor, text)
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/slate-vue/plugins/runtime-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions packages/slate-vue/plugins/with-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 888addc

Please sign in to comment.