Skip to content

Commit

Permalink
feat: old/new merge style
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Feb 5, 2021
1 parent f1d71bb commit b011dcc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 9 additions & 1 deletion public/plugins/ext-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
Statics: 这个key 订是扩展 Editor 的方法
其实也可以直接 Object.assign(Editor, { 这样的方式去扩展 })
*/
import { createEditor, Editor, Text, Node, Transforms } from 'slate';

export default {
name: 'ext-editor',
statics: {
version: '1.0.0'
version: '1.0.0',
current: (inEditor) => {
const selection = inEditor.selection;
if (!selection) return null;
const [node, _] = Editor.above(inEditor, selection.anchor.path);
return node;
}
}
};
22 changes: 12 additions & 10 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import noop from '@jswork/noop';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { createEditor, Editor, Text, Node, Transforms } from 'slate';
import { createEditor, Editor, Transforms } from 'slate';
import nxCompose from '@jswork/next-compose';
import NxSlateSerialize from '@jswork/next-slate-serialize';
import NxDeslateSerialize from '@jswork/next-slate-deserialize';
import NxSlateDefaults from '@jswork/next-slate-defaults';
import {
Slate,
Editable,
withReact,
DefaultElement,
ReactEditor
} from 'slate-react';
import NxCssText from '@jswork/next-css-text';
import { Slate, Editable, withReact, ReactEditor } from 'slate-react';
import isHotkey from 'is-hotkey';

const CLASS_NAME = 'react-rte-slate';
Expand Down Expand Up @@ -123,16 +118,23 @@ export default class ReactRteSlate extends Component {
return true;
}

getOldStyle(inRef) {
const { current } = inRef;
if (!current) return null;
const css = current.style.cssText;
return NxCssText.css2obj(css);
}

renderElement = (inProps) => {
const { element, children, attributes } = inProps;
const { plugins } = this.props;
const plugin = plugins.find((plg) => plg.name === element.type);
const style = this.getOldStyle(attributes.ref);
const newProps = {
element,
children,
attributes: { ...attributes, style: element.style }
attributes: { ...attributes, style: { ...style, ...element.style } }
};
// if (!plugin) return <DefaultElement {...newProps} />;
return plugin.hooks.element(this, newProps);
};

Expand Down

0 comments on commit b011dcc

Please sign in to comment.