diff --git a/wax-prosemirror-plugins/index.js b/wax-prosemirror-plugins/index.js index 819d258b5e5fcd2f7faa176493b63799d35f2056..b6732428ae192dfafffe0b2638d493264486f89a 100644 --- a/wax-prosemirror-plugins/index.js +++ b/wax-prosemirror-plugins/index.js @@ -6,3 +6,4 @@ export { default as highlightPlugin } from './src/highlightPlugin'; export { default as mathPlugin } from './src/math/math-plugin'; export { default as mathSelectPlugin } from './src/math/math-select'; +export { default as FindAndReplacePlugin } from './src/findAndReplace/FindAndReplacePlugin'; diff --git a/wax-prosemirror-plugins/src/FindAndReplacePlugin.js b/wax-prosemirror-plugins/src/FindAndReplacePlugin.js deleted file mode 100644 index 96b65597222bb19213a5633fb5f8a1b061713bf2..0000000000000000000000000000000000000000 --- a/wax-prosemirror-plugins/src/FindAndReplacePlugin.js +++ /dev/null @@ -1,107 +0,0 @@ -import ReactDOM from "react-dom"; -import React from "react"; -import { EditorState, Plugin, PluginKey } from "prosemirror-state"; -import { TextSelection } from "prosemirror-state"; -import { EditorView } from "prosemirror-view"; - -const Component = ({ state }) => { - return <div>11111{state.selection.from}</div>; -}; - -const findNodesWithSameMark = (doc, from, to, markType) => { - let ii = from; - const finder = mark => mark.type === markType; - let firstMark = null; - let fromNode = null; - let toNode = null; - - while (ii <= to) { - const node = doc.nodeAt(ii); - if (!node || !node.marks) { - return null; - } - const mark = node.marks.find(finder); - if (!mark) { - return null; - } - if (firstMark && mark !== firstMark) { - return null; - } - fromNode = fromNode || node; - firstMark = firstMark || mark; - toNode = node; - ii++; - } - - let fromPos = from; - let toPos = to; - - let jj = 0; - ii = from - 1; - while (ii > jj) { - const node = doc.nodeAt(ii); - const mark = node && node.marks.find(finder); - if (!mark || mark !== firstMark) { - break; - } - fromPos = ii; - fromNode = node; - ii--; - } - - ii = to + 1; - jj = doc.nodeSize - 2; - while (ii < jj) { - const node = doc.nodeAt(ii); - const mark = node && node.marks.find(finder); - if (!mark || mark !== firstMark) { - break; - } - toPos = ii; - toNode = node; - ii++; - } - - return { - mark: firstMark, - from: { - node: fromNode, - pos: fromPos - }, - to: { - node: toNode, - pos: toPos - } - }; -}; - -const WithStatePlugin = Component => ({ state }) => { - // const { doc, selection, schema } = state; - // const markType = schema.marks.strong; - // if (!markType) { - // return null; - // } - // const { from, to } = selection; - // const result = findNodesWithSameMark(doc, from, to, markType); - //return result ? <Component state={state} /> : null; - return <Component state={state} />; -}; - -export const FindAndReplaceKey = new PluginKey("findandreplace"); - -const FindAndReplacePlugin = new Plugin({ - key: FindAndReplaceKey, - state: { - init() { - return { - renderArea: "rightSideBar", - component: WithStatePlugin(Component) - }; - }, - apply(tr, oldState, newState) { - return this.getState(newState); - } - } -}); - -export default FindAndReplacePlugin; diff --git a/wax-prosemirror-plugins/src/comments/CommentPlugin.js b/wax-prosemirror-plugins/src/comments/CommentPlugin.js index 2d61ca2aa537faecd218b37418e50f37684c5250..5b292dd7648d34722c2c152790c19c53a9e54243 100644 --- a/wax-prosemirror-plugins/src/comments/CommentPlugin.js +++ b/wax-prosemirror-plugins/src/comments/CommentPlugin.js @@ -93,7 +93,6 @@ export default props => { const commentPluginState = state && commentPlugin.getState(state); return commentPluginState.createDecoration; }, - setCommentActive: state => {}, }, }); }; diff --git a/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js b/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js new file mode 100644 index 0000000000000000000000000000000000000000..2aba2f2cd85524cc339031d06e2b3b8518a4e1dd --- /dev/null +++ b/wax-prosemirror-plugins/src/findAndReplace/FindAndReplacePlugin.js @@ -0,0 +1,25 @@ +/* eslint-disable */ +import { Plugin, PluginKey } from 'prosemirror-state'; +import { Decoration, DecorationSet } from 'prosemirror-view'; + +const findAndReplacePlugin = new PluginKey('findAndReplacePlugin'); + +export default props => { + return new Plugin({ + key: findAndReplacePlugin, + state: { + init: (_, state) => { + return {}; + }, + apply(tr, prev, _, newState) {}, + }, + props: { + decorations: state => { + const findAndReplacePluginState = + state && findAndReplacePlugin.getState(state); + // return findAndReplacePluginState.createDecoration; + }, + getSearchTerm: state => {}, + }, + }); +}; diff --git a/wax-prosemirror-services/src/FindAndReplaceService/FindAndReplaceService.js b/wax-prosemirror-services/src/FindAndReplaceService/FindAndReplaceService.js index 179cf6c0e2bd0bcd7b6cf7470f6212e933b99010..fbe424b88eb23b33b21084b8c8d32c71a817608e 100644 --- a/wax-prosemirror-services/src/FindAndReplaceService/FindAndReplaceService.js +++ b/wax-prosemirror-services/src/FindAndReplaceService/FindAndReplaceService.js @@ -1,10 +1,16 @@ +import { FindAndReplacePlugin } from 'wax-prosemirror-plugins'; import Service from '../Service'; import FindAndReplace from './FindAndReplace'; class FindAndReplaceService extends Service { name = 'FindAndReplaceService'; - boot() {} + boot() { + this.app.PmPlugins.add( + 'findAndReplacePlugin', + FindAndReplacePlugin('findAndReplacePlugin'), + ); + } register() { this.container.bind('FindAndReplace').to(FindAndReplace);