diff --git a/.eslintrc.js b/.eslintrc.js index 95f1ddc87ab5c421d4c251f64dedbba796098a88..f238909d536e56dfa494bb185a2aae5d07675b58 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,5 @@ /* eslint-disable import/no-extraneous-dependencies */ -const { eslint } = require('@coko/lint') - +const { eslint } = require('@coko/lint'); /** * You can edit the eslint config file here. * @@ -22,6 +21,6 @@ eslint.rules = { 2, { ignore: ['children', 'className', 'onClick', 'theme'] }, ], -} +}; -module.exports = eslint +module.exports = eslint; diff --git a/.prettierrc.js b/.prettierrc.js index fd67d2bd71b6bd08872e920febf74ebe9824a06d..e6dba25110c29fe6198bb6bfe053d3b0e9e48664 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,5 +1,4 @@ -const { prettier } = require("@coko/lint"); - +const { prettier } = require('@coko/lint'); /** * You can edit the config here: * @@ -7,5 +6,5 @@ const { prettier } = require("@coko/lint"); * prettier.semi = true * */ - +prettier.semi = true; module.exports = prettier; diff --git a/wax-prosemirror-core/package.json b/wax-prosemirror-core/package.json index bd29d44d39584a363268f5a7c8dd22251f023c97..b2b7bc316211d8affee6162d3983da7a85a72faa 100644 --- a/wax-prosemirror-core/package.json +++ b/wax-prosemirror-core/package.json @@ -28,7 +28,10 @@ "react": "^16.13.1", "react-dom": "^16.13.1", "reflect-metadata": "^0.1.13", - "styled-components": "^4.2.0" + "styled-components": "^4.2.0", + "uuid": "^7.0.3", + "wax-prosemirror-services": "^0.0.10", + "wax-prosemirror-utilities": "^0.0.10" }, "devDependencies": { "mocha": "^3.4.2", diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index 8410e92fbef60ec54ef6b41feb7870dd09bc5d1e..a9534f3fd8e068d8f875477598c0b1beeace9ad4 100644 --- a/wax-prosemirror-core/src/Application.js +++ b/wax-prosemirror-core/src/Application.js @@ -1,26 +1,21 @@ -import { Container } from "inversify"; -import "reflect-metadata"; -import deepmerge from "deepmerge"; -import Config from "./config/Config"; -import defaultConfig from "./config/defaultConfig"; -import PmPlugins from "./PmPlugins"; +import { Container } from 'inversify'; +import 'reflect-metadata'; +import deepmerge from 'deepmerge'; +import Config from './config/Config'; +import defaultConfig from './config/defaultConfig'; +import PmPlugins from './PmPlugins'; export default class Application { - container = {}; - config = {}; - PmPlugins = {}; - schema = {}; - constructor(container) { this.container = container; - this.PmPlugins = container.get("PmPlugins"); + this.PmPlugins = container.get('PmPlugins'); } registerServices() { let count = 0; - while (count < this.config.get("config.services").length) { - const allServices = this.config.get("config.services"); - const service = this.config.get("config.services")[count]; + while (count < this.config.get('config.services').length) { + const allServices = this.config.get('config.services'); + const service = this.config.get('config.services')[count]; /* set App to every service so services can have access to containers and config @@ -28,7 +23,7 @@ export default class Application { service.setApp(this); if (service.dependencies) { - let servicePos = count; + const servicePos = count; allServices.splice(servicePos + 1, 0, ...service.dependencies); } @@ -41,11 +36,11 @@ export default class Application { } setConfig() { - this.config = this.container.get("Config"); + this.config = this.container.get('Config'); } bootServices() { - const services = this.config.get("config.services"); + const services = this.config.get('config.services'); services.forEach(plugin => { if (plugin.boot) { plugin.boot(); @@ -58,7 +53,7 @@ export default class Application { } getSchema() { - this.schema = this.container.get("Schema"); + this.schema = this.container.get('Schema'); return this.schema.getSchema(); } @@ -73,12 +68,12 @@ export default class Application { /* Merge Core Config with User Config */ const appConfig = deepmerge({ config: defaultConfig }, config, { customMerge: key => { - if (key === "services") { + if (key === 'services') { return (coreService, configService) => { return coreService.concat(configService); }; } - } + }, }); /* @@ -89,23 +84,17 @@ export default class Application { Set base bindings for the App to work */ - container - .bind("PmPlugins") - .to(PmPlugins) - .inSingletonScope(); + container.bind('PmPlugins').to(PmPlugins).inSingletonScope(); - container.bind("Wax").toFactory(() => new Application(container)); + container.bind('Wax').toFactory(() => new Application(container)); - container.bind("config").toConstantValue(appConfig); - container - .bind("Config") - .to(Config) - .inSingletonScope(); + container.bind('config').toConstantValue(appConfig); + container.bind('Config').to(Config).inSingletonScope(); /* Start the App */ - const app = container.get("Wax"); + const app = container.get('Wax'); app.setConfig(); appConfig.config.PmPlugins.forEach(configPlugin => { app.PmPlugins.add(configPlugin.key, configPlugin); diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index ba733eeb0dbbb3c9b19f96b31645246d1e93a3d2..ea784f4f819902bb714a076d17d7031f4c92042a 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -1,32 +1,32 @@ -import React, { useEffect, useState } from "react"; -import WaxProvider from "./WaxContext"; -import Application from "./Application"; +import React, { useEffect, useState } from 'react'; +import debounce from 'lodash/debounce'; +import styled from 'styled-components'; -import debounce from "lodash/debounce"; -import styled from "styled-components"; +import WaxProvider from './WaxContext'; +import Application from './Application'; -import WaxDOMSerializer from "./WaxDOMSerializer"; -import WaxDOMParser from "./WaxDOMParser"; +import WaxDOMSerializer from './WaxDOMSerializer'; +import WaxDOMParser from './WaxDOMParser'; -import WaxView from "./WaxView"; -import defaultPlugins from "./plugins/defaultPlugins"; -import Placeholder from "./plugins/placeholder"; +import WaxView from './WaxView'; +import defaultPlugins from './plugins/defaultPlugins'; +import Placeholder from './plugins/placeholder'; const parser = schema => { - const parser = WaxDOMParser.fromSchema(schema); + const WaxParser = WaxDOMParser.fromSchema(schema); return content => { - const container = document.createElement("article"); + const container = document.createElement('article'); container.innerHTML = content; - return parser.parse(container); + return WaxParser.parse(container); }; }; const serializer = schema => { - const serializer = WaxDOMSerializer.fromSchema(schema); + const WaxSerializer = WaxDOMSerializer.fromSchema(schema); return content => { - const container = document.createElement("article"); - container.appendChild(serializer.serializeFragment(content)); + const container = document.createElement('article'); + container.appendChild(WaxSerializer.serializeFragment(content)); return container.innerHTML; }; }; @@ -50,7 +50,7 @@ const LayoutWrapper = styled.div` `; const Wax = props => { - let finalPlugins; + let finalPlugins = []; const [application, setApplication] = useState(); useEffect(() => { @@ -71,23 +71,23 @@ const Wax = props => { TrackChange, value, user, - onChange + onChange, } = props; if (!application) return null; const WaxOnchange = onChange ? onChange : value => true; - const editorContent = value ? value : ""; + const editorContent = value ? value : ''; finalPlugins = defaultPlugins.concat([ createPlaceholder(placeholder), - ...application.getPlugins() + ...application.getPlugins(), ]); const WaxOptions = { schema, - plugins: finalPlugins + plugins: finalPlugins, }; const parse = parser(schema); @@ -99,10 +99,10 @@ const Wax = props => { WaxOnchange(serialize(value)); }, 1000, - { maxWait: 5000 } + { maxWait: 5000 }, ); - const Layout = application.container.get("Layout"); + const Layout = application.container.get('Layout'); if (layout) Layout.setLayout(layout); const WaxRender = Layout.layoutComponent; @@ -115,8 +115,8 @@ const Wax = props => { options={WaxOptions} placeholder={placeholder} fileUpload={fileUpload} - onBlur={onBlur || (value => true)} - onChange={finalOnChange || (value => true)} + onBlur={onBlur || (v => true)} + onChange={finalOnChange || (v => true)} debug={debug} TrackChange={TrackChange} user={user} diff --git a/wax-prosemirror-core/src/WaxContext.js b/wax-prosemirror-core/src/WaxContext.js index a4e012e9d88c02573dd02e6b644744a867b4dafc..6d5c226bcd902c42381577d2b31906ed6393c054 100644 --- a/wax-prosemirror-core/src/WaxContext.js +++ b/wax-prosemirror-core/src/WaxContext.js @@ -1,4 +1,4 @@ -import React, { useContext, useState } from "react"; +import React, { useContext, useState } from 'react'; export const WaxContext = React.createContext({ view: {}, @@ -6,7 +6,7 @@ export const WaxContext = React.createContext({ activeViewId: null, app: null, updateView: null, - updateActiveView: null + updateActiveView: null, }); export default props => { @@ -22,15 +22,15 @@ export default props => { ...context, view, activeView: activeView, - activeViewId: activeViewId || context.activeViewId + activeViewId: activeViewId || context.activeViewId, }); - } + }, }); return ( <WaxContext.Provider value={{ - ...context + ...context, }} > {props.children} @@ -39,7 +39,9 @@ export default props => { }; export const useInjection = identifier => { - const { app: { container } } = useContext(WaxContext); + const { + app: { container }, + } = useContext(WaxContext); if (!container) { throw new Error(); diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 5b1a7c08a8241e9a8fbb31ff60590353cfbfa71e..e3e2c78cf5a61f2a81b67daf5a99a89b30b2d1cd 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -1,25 +1,17 @@ -import React, { useEffect, useRef, useContext } from "react"; +import React, { useEffect, useRef, useContext } from 'react'; -import applyDevTools from "prosemirror-dev-tools"; -import { EditorState } from "prosemirror-state"; -import { EditorView } from "prosemirror-view"; +import applyDevTools from 'prosemirror-dev-tools'; +import { EditorState } from 'prosemirror-state'; +import { EditorView } from 'prosemirror-view'; -import "prosemirror-view/style/prosemirror.css"; +import 'prosemirror-view/style/prosemirror.css'; -import { trackedTransaction } from "wax-prosemirror-services"; -import { WaxContext } from "./WaxContext"; -import transformPasted from "./helpers/TransformPasted"; +import { trackedTransaction } from 'wax-prosemirror-services'; +import { WaxContext } from './WaxContext'; +import transformPasted from './helpers/TransformPasted'; export default props => { - const { - readonly, - onBlur, - options, - debug, - autoFocus, - TrackChange, - user - } = props; + const { readonly, onBlur, options, debug, autoFocus, user } = props; const editorRef = useRef(); let view; @@ -38,19 +30,19 @@ export default props => { ? view => { onBlur(view.state.doc.content); } - : null + : null, }, transformPasted: slice => { return transformPasted(slice, view); - } - } + }, + }, ); context.updateView( { - main: view + main: view, }, - "main" + 'main', ); if (debug) applyDevTools(view); if (autoFocus) view.focus(); @@ -68,15 +60,15 @@ export default props => { view.updateState(state); /*when a transaction comes from a view other than - main don't keep updating the view ,as this is - the central point of each transaction - */ - if (!transaction.getMeta("outsideView")) { + main don't keep updating the view ,as this is + the central point of each transaction + */ + if (!transaction.getMeta('outsideView')) { context.updateView( { - main: view + main: view, }, - "main" + 'main', ); } @@ -85,6 +77,6 @@ export default props => { const editor = <div ref={editorRef} />; return props.children({ - editor + editor, }); }; diff --git a/wax-prosemirror-core/src/config/Config.js b/wax-prosemirror-core/src/config/Config.js index d55a3be453aabd745a7450aed56e1ef85c7d8fbe..b69d732a1d25069034158dcbd14887b9001ee496 100644 --- a/wax-prosemirror-core/src/config/Config.js +++ b/wax-prosemirror-core/src/config/Config.js @@ -1,10 +1,10 @@ -import { set, get, isArrayLikeObject } from "lodash"; -import { injectable, inject } from "inversify"; +import { set, get, isArrayLikeObject } from 'lodash'; +import { injectable, inject } from 'inversify'; @injectable() export default class Config { _config = {}; - constructor(@inject("config") config) { + constructor(@inject('config') config) { this._config = config; } diff --git a/wax-prosemirror-core/src/helpers/TransformPasted.js b/wax-prosemirror-core/src/helpers/TransformPasted.js index d3708df11e40ac9950269d3e0a5aaa8e417a3124..884d4a1099d1ae4c21b8e270d2684aa1b2785cdd 100644 --- a/wax-prosemirror-core/src/helpers/TransformPasted.js +++ b/wax-prosemirror-core/src/helpers/TransformPasted.js @@ -1,38 +1,38 @@ -import { forEach } from "lodash"; -import { v4 as uuidv4 } from "uuid"; -import { DocumentHelpers } from "wax-prosemirror-utilities"; +import { forEach } from 'lodash'; +import { v4 as uuidv4 } from 'uuid'; +import { DocumentHelpers } from 'wax-prosemirror-utilities'; const transformPasted = (slice, view) => { const { content } = slice; const commentNodes = DocumentHelpers.findChildrenByMark( content, view.state.schema.marks.comment, - true + true, ); const notes = DocumentHelpers.findChildrenByType( content, view.state.schema.nodes.footnote, - true + true, ); const allComments = []; commentNodes.map(node => { node.node.marks.map(comment => { - if (comment.type.name === "comment") { + if (comment.type.name === 'comment') { allComments.push(comment); } }); }); - let groupedCommentsById = allComments.reduce((obj, mark) => { + const groupedCommentsById = allComments.reduce((obj, mark) => { obj[mark.attrs.id] = [...(obj[mark.attrs.id] || []), mark]; return obj; }, {}); forEach(Object.keys(groupedCommentsById), key => { - let id = uuidv4(); + const id = uuidv4(); forEach(groupedCommentsById[key], comment => { comment.attrs.id = id; }); diff --git a/wax-prosemirror-layouts/package.json b/wax-prosemirror-layouts/package.json index 61d296ece390d7169f4bf7425d2c588e10cde4b4..e05777436af2751059341b7e485b33f0494afb9f 100644 --- a/wax-prosemirror-layouts/package.json +++ b/wax-prosemirror-layouts/package.json @@ -13,6 +13,11 @@ "react": "^16.13.1", "react-dom": "^16.13.1", "react-panelgroup": "^1.0.10", - "styled-components": "^4.2.0" + "styled-components": "^4.2.0", + "wax-prosemirror-core": "^0.0.10", + "wax-prosemirror-components": "^0.0.10", + "wax-prosemirror-themes": "^0.0.10", + "wax-prosemirror-services": "^0.0.10", + "wax-prosemirror-utilities": "^0.0.10" } } diff --git a/wax-prosemirror-layouts/src/layouts/EditorElements.js b/wax-prosemirror-layouts/src/layouts/EditorElements.js index b8f77fd859b29292509e668cf65d0db763dde615..bff58dbea4d1a510afe180e2b942e5c2764b0a78 100644 --- a/wax-prosemirror-layouts/src/layouts/EditorElements.js +++ b/wax-prosemirror-layouts/src/layouts/EditorElements.js @@ -1,4 +1,4 @@ -import styled, { css } from "styled-components"; +import { css } from 'styled-components'; /* All styles regarding ProseMirror surface and elements */ @@ -42,7 +42,7 @@ export default css` } hr:after { - content: ""; + content: ''; display: block; height: 1px; background-color: silver; @@ -117,7 +117,7 @@ export default css` .selectedCell:after { z-index: 2; position: absolute; - content: ""; + content: ''; left: 0; right: 0; top: 0; @@ -156,15 +156,15 @@ export default css` } .invisible--space:before { - content: "·"; + content: '·'; } .invisible--break:before { - content: "¬"; + content: '¬'; } .invisible--par:after { - content: "¶"; + content: '¶'; } span.deletion { @@ -192,7 +192,7 @@ export default css` } [data-track]::before { - content: ""; + content: ''; position: absolute; border-left: 2px solid blue; left: -10px; diff --git a/wax-prosemirror-layouts/src/layouts/EditoriaLayout.js b/wax-prosemirror-layouts/src/layouts/EditoriaLayout.js index d77f088e657f0bb3dab96d8f9f329169f759d6a5..24d63cda65504f2597a3c19e814dfb75a1ace120 100644 --- a/wax-prosemirror-layouts/src/layouts/EditoriaLayout.js +++ b/wax-prosemirror-layouts/src/layouts/EditoriaLayout.js @@ -1,12 +1,12 @@ -import React, { useContext } from "react"; -import styled, { ThemeProvider } from "styled-components"; -import { InfoArea } from "wax-prosemirror-components"; -import { componentPlugin } from "wax-prosemirror-services"; -import EditorElements from "./EditorElements"; -import { cokoTheme } from "wax-prosemirror-themes"; -import { DocumentHelpers } from "wax-prosemirror-utilities"; -import { WaxContext } from "wax-prosemirror-core"; -import PanelGroup from "react-panelgroup"; +import React, { useContext } from 'react'; +import styled, { ThemeProvider } from 'styled-components'; +import PanelGroup from 'react-panelgroup'; +import { InfoArea } from 'wax-prosemirror-components'; +import { componentPlugin } from 'wax-prosemirror-services'; +import { cokoTheme } from 'wax-prosemirror-themes'; +import { DocumentHelpers } from 'wax-prosemirror-utilities'; +import { WaxContext } from 'wax-prosemirror-core'; +import EditorElements from './EditorElements'; const LayoutWrapper = styled.div` display: flex; @@ -16,7 +16,7 @@ const LayoutWrapper = styled.div` overflow: hidden; .divider { &:before { - content: "Notes"; + content: 'Notes'; position: relative; bottom: 14px; background: white; @@ -26,30 +26,30 @@ const LayoutWrapper = styled.div` } &:after { color: #a3a3a3; - content: ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . " - ". . . . . . . . . . . . . . . . . . . . "; + content: '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . ' + '. . . . . . . . . . . . . . . . . . . . '; float: left; font-weight: 400; white-space: nowrap; @@ -151,7 +151,7 @@ const SideMenuInner = styled.div` margin-left: 5%; width: 90%; } - [data-name="Display"] { + [data-name='Display'] { border-right: none; } } @@ -195,17 +195,17 @@ const hasNotes = main => { const notes = DocumentHelpers.findChildrenByType( main.state.doc, main.state.schema.nodes.footnote, - true + true, ); return notes; }; -const LeftSideBar = componentPlugin("leftSideBar"); -const RightSideBar = componentPlugin("rightSideBar"); -const TopBar = componentPlugin("topBar"); -const NotesArea = componentPlugin("notesArea"); -const RightArea = componentPlugin("rightArea"); -const WaxOverlays = componentPlugin("waxOverlays"); +const LeftSideBar = componentPlugin('leftSideBar'); +const RightSideBar = componentPlugin('rightSideBar'); +const TopBar = componentPlugin('topBar'); +const NotesArea = componentPlugin('notesArea'); +const RightArea = componentPlugin('rightArea'); +const WaxOverlays = componentPlugin('waxOverlays'); const withNotes = () => { return ( @@ -221,7 +221,9 @@ const withNotes = () => { }; const EditoriaLayout = ({ editor }) => { - const { view: { main } } = useContext(WaxContext); + const { + view: { main }, + } = useContext(WaxContext); let AreasWithNotes = null; if (main) { @@ -248,8 +250,8 @@ const EditoriaLayout = ({ editor }) => { <PanelGroup direction="column" panelWidths={[ - { size: surfaceHeight, resize: "dynamic" }, - { size: notesHeight, resize: "stretch" } + { size: surfaceHeight, resize: 'dynamic' }, + { size: notesHeight, resize: 'stretch' }, ]} onResizeEnd={onResizeEnd} > diff --git a/wax-prosemirror-services/src/BaseService/RedoService/RedoService.js b/wax-prosemirror-services/src/BaseService/RedoService/RedoService.js index 327a838a1350926d397cc262e3466739f587f346..017c9f612310ba9517d6ee292fec7e2dcc558f18 100644 --- a/wax-prosemirror-services/src/BaseService/RedoService/RedoService.js +++ b/wax-prosemirror-services/src/BaseService/RedoService/RedoService.js @@ -1,11 +1,11 @@ -import Service from "../../Service"; -import Redo from "./Redo"; +import Service from '../../Service'; +import Redo from './Redo'; class RedoService extends Service { - boot() {} + // boot() {} register() { - this.container.bind("Redo").to(Redo); + this.container.bind('Redo').to(Redo); } } diff --git a/wax-prosemirror-utilities/package.json b/wax-prosemirror-utilities/package.json index 18daa27bb2899645eca579b44113bab004d3e7a2..02917a48b50764c6fe534bf039f2c49f76708acc 100644 --- a/wax-prosemirror-utilities/package.json +++ b/wax-prosemirror-utilities/package.json @@ -10,6 +10,8 @@ "build": "BABEL_ENV=production rollup -c" }, "dependencies": { - "prosemirror-utils": "^0.9.6" + "prosemirror-utils": "^0.9.6", + "prosemirror-commands": "^1.1.3", + "uuid": "^7.0.3" } } diff --git a/wax-prosemirror-utilities/src/commands/Commands.js b/wax-prosemirror-utilities/src/commands/Commands.js index eb1d9647d1414e15ccdac5e72abe7160eca2b08b..40594b858e83c2ba663f00f6329e7a3a86dbfd0b 100644 --- a/wax-prosemirror-utilities/src/commands/Commands.js +++ b/wax-prosemirror-utilities/src/commands/Commands.js @@ -1,6 +1,5 @@ -import { Selection, TextSelection } from "prosemirror-state"; -import { v4 as uuidv4 } from "uuid"; -import { toggleMark } from "prosemirror-commands"; +import { v4 as uuidv4 } from 'uuid'; +import { toggleMark } from 'prosemirror-commands'; const setBlockType = (nodeType, attrs = {}) => { return (state, dispatch) => { @@ -9,11 +8,11 @@ const setBlockType = (nodeType, attrs = {}) => { state.doc.nodesBetween(from, to, (node, pos) => { if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return; let applicable = false; - if (node.type == nodeType) { + if (node.type === nodeType) { applicable = true; } else { - const $pos = state.doc.resolve(pos), - index = $pos.index(); + const $pos = state.doc.resolve(pos); + const index = $pos.index(); applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType); } if (applicable) { @@ -21,7 +20,7 @@ const setBlockType = (nodeType, attrs = {}) => { from, to, nodeType, - Object.assign({}, node.attrs, attrs) + Object.assign({}, node.attrs, attrs), ); } }); @@ -64,8 +63,8 @@ const canInsert = type => state => { }; const createTable = (state, dispatch) => { - let rowCount = window && window.prompt("How many rows?", 2); - let colCount = window && window.prompt("How many columns?", 2); + let rowCount = window && window.prompt('How many rows?', 2); + let colCount = window && window.prompt('How many columns?', 2); const cells = []; while (colCount--) { @@ -82,16 +81,24 @@ const createTable = (state, dispatch) => { }; const createLink = (state, dispatch) => { - const { selection: { $from, $to } } = state; + const { + selection: { $from, $to }, + } = state; dispatch( state.tr - .setMeta("addToHistory", false) - .addMark($from.pos, $to.pos, state.schema.marks.link.create({ href: "" })) + .setMeta('addToHistory', false) + .addMark( + $from.pos, + $to.pos, + state.schema.marks.link.create({ href: '' }), + ), ); }; const isOnSameTextBlock = state => { - const { selection: { $from, $to, from, to } } = state; + const { + selection: { $from, $to, from, to }, + } = state; if (from !== to && $from.parent === $to.parent && $from.parent.isTextblock) { return true; } @@ -102,7 +109,7 @@ const createComment = (state, dispatch, group) => { toggleMark(state.config.schema.marks.comment, { id: uuidv4(), group, - conversation: [] + conversation: [], })(state, dispatch); }; @@ -114,5 +121,5 @@ export default { createLink, createTable, markActive, - isOnSameTextBlock + isOnSameTextBlock, }; diff --git a/wax-prosemirror-utilities/src/document/DocumentHelpers.js b/wax-prosemirror-utilities/src/document/DocumentHelpers.js index f5fa3c1a2c5980af0dba40716ca2e0197d96d973..eb68c1c77c0b462732af3650f10a1424d9a8e64d 100644 --- a/wax-prosemirror-utilities/src/document/DocumentHelpers.js +++ b/wax-prosemirror-utilities/src/document/DocumentHelpers.js @@ -1,5 +1,8 @@ const findMark = (state, PMmark, toArr = false) => { - const { selection: { $from, $to }, doc } = state; + const { + selection: { $from, $to }, + doc, + } = state; const fromMark = $from.marks().find(mark => mark.type === PMmark); const toMark = $to.marks().find(mark => mark.type === PMmark); let markFound; @@ -12,7 +15,7 @@ const findMark = (state, PMmark, toArr = false) => { from, to: from + node.nodeSize, attrs: actualMark.attrs, - contained: !fromMark || !toMark || fromMark === toMark + contained: !fromMark || !toMark || fromMark === toMark, }; marksFound.push(markFound); } @@ -23,7 +26,10 @@ const findMark = (state, PMmark, toArr = false) => { }; const getSelectionMark = (state, PMmark) => { - const { selection: { $from, $to }, doc } = state; + const { + selection: { $from, $to }, + doc, + } = state; let markFound; doc.nodesBetween($from.pos, $to.pos, (node, from) => { if (node.marks) { @@ -32,7 +38,7 @@ const getSelectionMark = (state, PMmark) => { markFound = { from: $from.pos, to: $to.pos, - attrs: actualMark.attrs + attrs: actualMark.attrs, }; } } @@ -45,7 +51,10 @@ const getSelectionMark = (state, PMmark) => { that are pm will break them */ const findFragmentedMark = (state, PMmark) => { - const { selection: { $from, $to }, doc } = state; + const { + selection: { $from, $to }, + doc, + } = state; const fromPos = [$from.pos - 1, $from.pos]; const toPos = [$to.pos - 1, $to.pos]; let markFound; @@ -58,21 +67,20 @@ const findFragmentedMark = (state, PMmark) => { markFound = { from, to: from + node.nodeSize, - attrs: actualMark.attrs + attrs: actualMark.attrs, }; } } }); if (markFound) { return markFound; - break; } } return markFound; }; const findAllCommentsWithSameId = state => { - const commentMark = state.schema.marks["comment"]; + const commentMark = state.schema.marks.comment; const commentOnSelection = findFragmentedMark(state, commentMark); const commentNodes = findChildrenByMark(state.doc, commentMark, true); @@ -81,14 +89,13 @@ const findAllCommentsWithSameId = state => { commentNodes.map(node => { node.node.marks.filter(mark => { if ( - mark.type.name === "comment" && + mark.type.name === 'comment' && commentOnSelection.attrs.id === mark.attrs.id ) { allCommentsWithSameId.push(node); } }); }); - console.log(allCommentsWithSameId); return allCommentsWithSameId; }; @@ -144,5 +151,5 @@ export default { findChildrenByAttr, getSelectionMark, findFragmentedMark, - findAllCommentsWithSameId + findAllCommentsWithSameId, };