From 4add1319ecde5f3ac9db83e3a5928e5c23dab178 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 14 Dec 2021 13:28:43 +0200 Subject: [PATCH] disable sublist creation from config --- editors/demo/src/Editoria/config/config.js | 3 +++ editors/demo/src/Editors.js | 2 +- .../BulletListService/BulletList.js | 14 ++++++++--- .../BulletListService/BulletListService.js | 5 +++- .../src/ListsService/JoinUpService/JoinUp.js | 23 ++++++++++++++++--- .../JoinUpService/JoinUpService.js | 12 ++++++---- .../src/ListsService/ListsService.js | 1 + .../OrderedListService/OrderedList.js | 14 ++++++++--- .../OrderedListService/OrderedListService.js | 21 +++++++++-------- .../src/ListsService/index.js | 12 +++++----- 10 files changed, 76 insertions(+), 31 deletions(-) diff --git a/editors/demo/src/Editoria/config/config.js b/editors/demo/src/Editoria/config/config.js index eef89f707..cdf2dec71 100644 --- a/editors/demo/src/Editoria/config/config.js +++ b/editors/demo/src/Editoria/config/config.js @@ -115,6 +115,9 @@ export default { ], // CommentsService: { readOnly: true }, + // OrderedListService: { subList: false }, + // BulletListService: { subList: false }, + // JoinUpService: { subList: false }, SchemaService: DefaultSchema, TitleService: { updateTitle }, RulesService: [emDash, ellipsis], diff --git a/editors/demo/src/Editors.js b/editors/demo/src/Editors.js index d19991a2e..abd0628fb 100644 --- a/editors/demo/src/Editors.js +++ b/editors/demo/src/Editors.js @@ -70,7 +70,7 @@ const Editors = () => { case 'ncbi': return <NCBI />; default: - return <HHMI />; + return <Editoria />; } }; diff --git a/wax-prosemirror-services/src/ListsService/BulletListService/BulletList.js b/wax-prosemirror-services/src/ListsService/BulletListService/BulletList.js index 5f10e03ba..d9a6a4859 100644 --- a/wax-prosemirror-services/src/ListsService/BulletListService/BulletList.js +++ b/wax-prosemirror-services/src/ListsService/BulletListService/BulletList.js @@ -26,12 +26,20 @@ class BulletList extends Tools { select = (state, activeViewId, activeView) => { const { - selection: { from }, + selection: { from, to }, } = state; + let status = true; + + if ('subList' in this.config && !this.config.subList) { + state.doc.nodesBetween(from, to, node => { + if (node.type.name === 'list_item') status = false; + }); + } + if (from === null) return false; const { disallowedTools } = activeView.props; - if (disallowedTools.includes('Lists')) return false; - return true; + if (disallowedTools.includes('Lists')) status = false; + return status; }; get active() { diff --git a/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js b/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js index 0c0193e73..be0192010 100644 --- a/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js +++ b/wax-prosemirror-services/src/ListsService/BulletListService/BulletListService.js @@ -4,6 +4,7 @@ import Service from '../../Service'; import BulletList from './BulletList'; class BulletListService extends Service { + name = 'BulletListService'; boot() { const shortCuts = this.container.get('ShortCuts'); // shortCuts.addShortCut({ @@ -12,7 +13,9 @@ class BulletListService extends Service { } register() { - this.container.bind('BulletList').to(BulletList); + this.container.bind('BulletList').toDynamicValue(() => { + return new BulletList(this.config); + }); const createNode = this.container.get('CreateNode'); createNode( { diff --git a/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUp.js b/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUp.js index f02acabf2..8760213b5 100644 --- a/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUp.js +++ b/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUp.js @@ -13,11 +13,28 @@ class JoinUp extends Tools { return joinUp; } - select(state) { - return joinUp(state); - } + select = (state, activeViewId, activeView) => { + const { + selection: { from, to }, + } = state; + let status = joinUp(state); + + if ('subList' in this.config && !this.config.subList) { + state.doc.nodesBetween(from, to, node => { + if (node.type.name === 'list_item') status = false; + }); + } + + return status; + }; get enable() { return joinUp; } + + get active() { + return state => { + return false; + }; + } } diff --git a/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUpService.js b/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUpService.js index 32e83e840..2d46d45bf 100644 --- a/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUpService.js +++ b/wax-prosemirror-services/src/ListsService/JoinUpService/JoinUpService.js @@ -1,11 +1,13 @@ -import Service from "../../Service"; -import JoinUp from "./JoinUp"; +import Service from '../../Service'; +import JoinUp from './JoinUp'; class JoinUpService extends Service { - boot() {} - + name = 'JoinUpService'; register() { - this.container.bind("JoinUp").to(JoinUp); + // this.container.bind('JoinUp').to(JoinUp); + this.container.bind('JoinUp').toDynamicValue(() => { + return new JoinUp(this.config); + }); } } diff --git a/wax-prosemirror-services/src/ListsService/ListsService.js b/wax-prosemirror-services/src/ListsService/ListsService.js index 4a87bf910..516a19d9f 100644 --- a/wax-prosemirror-services/src/ListsService/ListsService.js +++ b/wax-prosemirror-services/src/ListsService/ListsService.js @@ -2,6 +2,7 @@ import Service from '../Service'; import ListsServices from './index'; class ListsService extends Service { + name = 'ListsService'; dependencies = ListsServices; } diff --git a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedList.js b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedList.js index 564d67f04..313d24de3 100644 --- a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedList.js +++ b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedList.js @@ -24,12 +24,20 @@ class OrderedList extends Tools { select = (state, activeViewId, activeView) => { const { - selection: { from }, + selection: { from, to }, } = state; + let status = true; + + if ('subList' in this.config && !this.config.subList) { + state.doc.nodesBetween(from, to, node => { + if (node.type.name === 'list_item') status = false; + }); + } + if (from === null) return false; const { disallowedTools } = activeView.props; - if (disallowedTools.includes('Lists')) return false; - return true; + if (disallowedTools.includes('Lists')) status = false; + return status; }; get active() { diff --git a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js index 23aad6d5f..9c73e4410 100644 --- a/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js +++ b/wax-prosemirror-services/src/ListsService/OrderedListService/OrderedListService.js @@ -1,24 +1,27 @@ -import Service from "../../Service"; -import { wrapInList } from "prosemirror-schema-list"; -import { orderedListNode } from "wax-prosemirror-schema"; -import OrderedList from "./OrderedList"; +import Service from '../../Service'; +import { wrapInList } from 'prosemirror-schema-list'; +import { orderedListNode } from 'wax-prosemirror-schema'; +import OrderedList from './OrderedList'; class OrderedListService extends Service { + name = 'OrderedListService'; boot() { - const shortCuts = this.container.get("ShortCuts"); + const shortCuts = this.container.get('ShortCuts'); // shortCuts.addShortCut({ // "Shift-Ctrl-9": wrapInList(this.schema.nodes.orderedlist) // }); } register() { - this.container.bind("OrderedList").to(OrderedList); - const createNode = this.container.get("CreateNode"); + this.container.bind('OrderedList').toDynamicValue(() => { + return new OrderedList(this.config); + }); + const createNode = this.container.get('CreateNode'); createNode( { - orderedlist: orderedListNode + orderedlist: orderedListNode, }, - { toWaxSchema: true } + { toWaxSchema: true }, ); } } diff --git a/wax-prosemirror-services/src/ListsService/index.js b/wax-prosemirror-services/src/ListsService/index.js index 628800e85..c35db0480 100644 --- a/wax-prosemirror-services/src/ListsService/index.js +++ b/wax-prosemirror-services/src/ListsService/index.js @@ -1,13 +1,13 @@ -import BulletListService from "./BulletListService/BulletListService"; -import OrderedListService from "./OrderedListService/OrderedListService"; -import JoinUpService from "./JoinUpService/JoinUpService"; -import LiftService from "./LiftService/LiftService"; -import ListItemService from "./ListItemService/ListItemService"; +import BulletListService from './BulletListService/BulletListService'; +import OrderedListService from './OrderedListService/OrderedListService'; +import JoinUpService from './JoinUpService/JoinUpService'; +import LiftService from './LiftService/LiftService'; +import ListItemService from './ListItemService/ListItemService'; export default [ new BulletListService(), new OrderedListService(), new JoinUpService(), new LiftService(), - new ListItemService() + new ListItemService(), ]; -- GitLab