Skip to content
Snippets Groups Projects
Commit f6089f8e authored by chris's avatar chris
Browse files

view

parent 5e9f8e6c
No related branches found
No related tags found
1 merge request!590Build wax view
...@@ -6,6 +6,7 @@ import { EditoriaLayout, EditoriaMobileLayout } from './layout'; ...@@ -6,6 +6,7 @@ import { EditoriaLayout, EditoriaMobileLayout } from './layout';
import { config, configMobile } from './config'; import { config, configMobile } from './config';
import { demo } from './demo'; import { demo } from './demo';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { TablesService } from 'wax-table-service';
const renderImage = file => { const renderImage = file => {
const reader = new FileReader(); const reader = new FileReader();
...@@ -32,6 +33,7 @@ const user = { ...@@ -32,6 +33,7 @@ const user = {
// }]; // }];
const Editoria = () => { const Editoria = () => {
const [myConfig, setMyConfig] = useState(config);
const [width] = useWindowSize(); const [width] = useWindowSize();
let layout = EditoriaLayout; let layout = EditoriaLayout;
...@@ -48,10 +50,22 @@ const Editoria = () => { ...@@ -48,10 +50,22 @@ const Editoria = () => {
const EditoriaComponent = useMemo( const EditoriaComponent = useMemo(
() => ( () => (
<> <>
<button
onClick={() => {
console.log(myConfig);
myConfig.PmPlugins = [];
myConfig.services = [...myConfig.services, new TablesService()];
setMyConfig({ ...myConfig });
}}
>
{' '}
change config
</button>
<Wax <Wax
ref={editorRef} ref={editorRef}
key={key} key={key}
config={finalConfig} config={myConfig}
autoFocus autoFocus
placeholder="Type Something..." placeholder="Type Something..."
fileUpload={file => renderImage(file)} fileUpload={file => renderImage(file)}
...@@ -68,7 +82,7 @@ const Editoria = () => { ...@@ -68,7 +82,7 @@ const Editoria = () => {
</> </>
), ),
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
[layout, finalConfig], [layout, myConfig],
); );
return <>{EditoriaComponent}</>; return <>{EditoriaComponent}</>;
}; };
......
...@@ -52,8 +52,7 @@ async function DummyPromise(userInput, { askKb }) { ...@@ -52,8 +52,7 @@ async function DummyPromise(userInput, { askKb }) {
} else { } else {
// JSON response test // JSON response test
const json = JSON.stringify({ const json = JSON.stringify({
content: content: askKb ? 'KB will be queried' : 'Just a normal call',
askKb ? 'KB will be queried' : 'Just a normal call',
citations: ['citation 1', 'citation 2', 'citation 3'], citations: ['citation 1', 'citation 2', 'citation 3'],
links: ['https://coko.foundation/', 'https://waxjs.net/about/'], links: ['https://coko.foundation/', 'https://waxjs.net/about/'],
}); });
...@@ -234,7 +233,7 @@ export default { ...@@ -234,7 +233,7 @@ export default {
'SpecialCharacters', 'SpecialCharacters',
'CodeBlock', 'CodeBlock',
'ToggleAi', 'ToggleAi',
'Tables', // 'Tables',
'TrackingAndEditing', 'TrackingAndEditing',
'FullScreen', 'FullScreen',
], ],
...@@ -306,13 +305,13 @@ export default { ...@@ -306,13 +305,13 @@ export default {
], ],
updateTags: saveTags, updateTags: saveTags,
}, },
YjsService: { // YjsService: {
// eslint-disable-next-line no-restricted-globals // // eslint-disable-next-line no-restricted-globals
connectionUrl: 'ws://localhost:5010', // connectionUrl: 'ws://localhost:5010',
// connectionUrl: 'ws://0.tcp.ap.ngrok.io:17607', // // connectionUrl: 'ws://0.tcp.ap.ngrok.io:17607',
docIdentifier: 'prosemirror-r5dw4q2fe2eedreeeeeweewwewerc', // docIdentifier: 'prosemirror-r5dw4q2fe2eedreeeeeweewwewerc',
YjsType: 'prosemirror', // YjsType: 'prosemirror',
}, // },
AskAiContentService: { AskAiContentService: {
AskAiContentTransformation: DummyPromise, AskAiContentTransformation: DummyPromise,
...@@ -325,7 +324,7 @@ export default { ...@@ -325,7 +324,7 @@ export default {
}, },
services: [ services: [
new YjsService(), // new YjsService(),
new BlockDropDownToolGroupService(), new BlockDropDownToolGroupService(),
new AskAiContentService(), new AskAiContentService(),
new CustomTagService(), new CustomTagService(),
...@@ -337,7 +336,7 @@ export default { ...@@ -337,7 +336,7 @@ export default {
new TrackChangeService(), new TrackChangeService(),
new CommentsService(), new CommentsService(),
new ImageService(), new ImageService(),
new TablesService(), // new TablesService(),
new BaseService(), new BaseService(),
// new NoteService(), // new NoteService(),
new CodeBlockService(), new CodeBlockService(),
......
import { Container } from 'inversify'; import { Container } from 'inversify';
import 'reflect-metadata'; import 'reflect-metadata';
import deepmerge from 'deepmerge'; import deepmerge from 'deepmerge';
import { v4 as uuidv4 } from 'uuid';
import Config from './config/Config'; import Config from './config/Config';
import defaultConfig from './config/defaultConfig'; import defaultConfig from './config/defaultConfig';
import PmPlugins from './PmPlugins'; import PmPlugins from './PmPlugins';
export default class Application { export default class Application {
constructor(container) { constructor(container) {
this.id = uuidv4();
this.container = container; this.container = container;
this.PmPlugins = container.get('PmPlugins'); this.PmPlugins = container.get('PmPlugins');
} }
...@@ -101,12 +104,12 @@ export default class Application { ...@@ -101,12 +104,12 @@ export default class Application {
Set base bindings for the App to work Set base bindings for the App to work
*/ */
container.bind('PmPlugins').to(PmPlugins).inSingletonScope(); container.bind('PmPlugins').to(PmPlugins);
container.bind('Wax').toFactory(() => new Application(container)); container.bind('Wax').toFactory(() => new Application(container));
container.bind('config').toConstantValue(appConfig); container.bind('config').toFactory(() => appConfig);
container.bind('Config').to(Config).inSingletonScope(); container.bind('Config').to(Config);
/* /*
Start the App Start the App
......
...@@ -35,6 +35,7 @@ const Wax = forwardRef((props, ref) => { ...@@ -35,6 +35,7 @@ const Wax = forwardRef((props, ref) => {
autoFocus, autoFocus,
browserSpellCheck, browserSpellCheck,
className, className,
config,
customValues, customValues,
fileUpload, fileUpload,
layout, layout,
...@@ -49,6 +50,11 @@ const Wax = forwardRef((props, ref) => { ...@@ -49,6 +50,11 @@ const Wax = forwardRef((props, ref) => {
scrollThreshold, scrollThreshold,
} = props; } = props;
useEffect(() => {
const newApplication = createApplication(props);
setApplication(newApplication);
}, [config.PmPlugins.length]);
if (!application) return null; if (!application) return null;
const finalOnChange = content => { const finalOnChange = content => {
......
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
/* eslint react/destructuring-assignment: 0 */ /* eslint react/destructuring-assignment: 0 */
import React, { useContext, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
export const WaxContext = React.createContext({ export const WaxContext = React.createContext({
pmViews: {}, pmViews: {},
...@@ -41,14 +41,17 @@ export default props => { ...@@ -41,14 +41,17 @@ export default props => {
}, },
}); });
return ( useEffect(() => {
<WaxContext.Provider if (props.app.config.get('config.PmPlugins').length === 0) {
value={{ setContext({
...context, ...context,
}} app: props.app,
> });
{props.children} }
</WaxContext.Provider> }, [props.app.id]);
return (
<WaxContext.Provider value={context}>{props.children}</WaxContext.Provider>
); );
}; };
......
...@@ -7,7 +7,6 @@ import React, { ...@@ -7,7 +7,6 @@ import React, {
useEffect, useEffect,
forwardRef, forwardRef,
useImperativeHandle, useImperativeHandle,
useState,
} from 'react'; } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { EditorState } from 'prosemirror-state'; import { EditorState } from 'prosemirror-state';
...@@ -40,7 +39,6 @@ const WaxView = forwardRef((props, ref) => { ...@@ -40,7 +39,6 @@ const WaxView = forwardRef((props, ref) => {
customValues, customValues,
readonly, readonly,
autoFocus, autoFocus,
reconfigureState,
user, user,
placeholder, placeholder,
targetFormat, targetFormat,
...@@ -51,18 +49,19 @@ const WaxView = forwardRef((props, ref) => { ...@@ -51,18 +49,19 @@ const WaxView = forwardRef((props, ref) => {
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { createPortal } = useContext(PortalContext); const { createPortal } = useContext(PortalContext);
const [mounted, setMounted] = useState(false); // const [mounted, setMounted] = useState(false);
context.app.setContext({ ...context, createPortal }); context.app.setContext({ ...context, createPortal });
const schema = context.app.getSchema(); const schema = context.app.getSchema();
const setEditorRef = useCallback( const setEditorRef = useCallback(
node => { node => {
if (node) { if (node) {
if (!mounted) { // if (!mounted) {
context.app.bootServices(); context.app.bootServices();
context.app.getShortCuts(); context.app.getShortCuts();
context.app.getRules(); context.app.getRules();
} // }
const options = WaxOptions({ const options = WaxOptions({
...props, ...props,
schema, schema,
...@@ -86,7 +85,7 @@ const WaxView = forwardRef((props, ref) => { ...@@ -86,7 +85,7 @@ const WaxView = forwardRef((props, ref) => {
}, },
); );
setMounted(true); // setMounted(true);
context.updateView( context.updateView(
{ {
...@@ -104,7 +103,7 @@ const WaxView = forwardRef((props, ref) => { ...@@ -104,7 +103,7 @@ const WaxView = forwardRef((props, ref) => {
} }
return node; return node;
}, },
[readonly, customValues], [readonly, customValues, context.app.id],
); );
useEffect(() => { useEffect(() => {
...@@ -112,52 +111,36 @@ const WaxView = forwardRef((props, ref) => { ...@@ -112,52 +111,36 @@ const WaxView = forwardRef((props, ref) => {
}, []); }, []);
useEffect(() => { useEffect(() => {
console.log('in reconfigure');
// const parse = parser(schema); // const parse = parser(schema);
if (!reconfigureState) return; if (context.app.config.get('config.PmPlugins').length === 0) {
let finalPlugins = [];
const createPlaceholder = () => {
return Placeholder({ content: placeholder });
};
finalPlugins = defaultPlugins.concat([
createPlaceholder(placeholder),
...context.app.getPlugins(),
]);
(reconfigureState?.plugins || []).forEach(plugin => { const reconfigureOptions = {
const pluginKey = Object.keys(plugin)[0]; // doc: parse(value),
const pluginValue = plugin[pluginKey]; schema,
plugins: finalPlugins,
};
if (context.app.PmPlugins.get(pluginKey)) { context.pmViews.main.updateState(EditorState.create(reconfigureOptions));
context.app.PmPlugins.replace(pluginKey, pluginValue);
} else { if (context.pmViews.main.dispatch) {
context.app.PmPlugins.add(pluginKey, pluginValue); context.pmViews.main.dispatch(
context.pmViews?.main.state.tr.setMeta('addToHistory', false),
);
} }
});
console.log(
'in reconfigure down',
reconfigureState,
context.app.getPlugins(),
);
let finalPlugins = [];
const createPlaceholder = () => {
return Placeholder({ content: placeholder });
};
finalPlugins = defaultPlugins.concat([
createPlaceholder(placeholder),
...context.app.getPlugins(),
]);
const reconfigureOptions = {
// doc: parse(value),
schema,
plugins: finalPlugins,
};
context.pmViews.main.updateState(EditorState.create(reconfigureOptions));
if (context.pmViews.main.dispatch) {
context.pmViews.main.dispatch(
context.pmViews?.main.state.tr.setMeta('addToHistory', false),
);
} }
return true; return true;
}, [JSON.stringify(reconfigureState)]); }, [context.app.id]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
getContent() { getContent() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment