From c90f430312bc10f121a1e84904684595ff042889 Mon Sep 17 00:00:00 2001 From: Yousef El-Dardiry Date: Tue, 8 Mar 2022 13:39:22 +0100 Subject: [PATCH] code formatting --- .../extensions/Blocks/OrderedListPlugin.ts | 49 ++++++++++++------- .../core/src/extensions/Blocks/nodes/Block.ts | 2 +- .../src/extensions/Blocks/nodes/Content.ts | 10 ++-- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/packages/core/src/extensions/Blocks/OrderedListPlugin.ts b/packages/core/src/extensions/Blocks/OrderedListPlugin.ts index f09241b489..9010da30dc 100644 --- a/packages/core/src/extensions/Blocks/OrderedListPlugin.ts +++ b/packages/core/src/extensions/Blocks/OrderedListPlugin.ts @@ -1,4 +1,4 @@ -import {Plugin, PluginKey} from "prosemirror-state"; +import { Plugin, PluginKey } from "prosemirror-state"; const PLUGIN_KEY = new PluginKey(`ordered-list`); @@ -6,30 +6,41 @@ export const OrderedListPlugin = () => { return new Plugin({ key: PLUGIN_KEY, appendTransaction: (_transactions, _oldState, newState) => { - const newTr = newState.tr - let modified = false - let count = 1 - let skip = 0 + const newTr = newState.tr; + let modified = false; + let count = 1; + let skip = 0; newState.doc.descendants((node, pos) => { - if (node.type.name === "tcblock" && !node.attrs.listType) count = 1 - if (skip == 0 && node.type.name === "tcblock" && node.attrs.listType === "oli") { - skip = node.content.childCount + if (node.type.name === "tcblock" && !node.attrs.listType) { + count = 1; + } + if ( + skip === 0 && + node.type.name === "tcblock" && + node.attrs.listType === "oli" + ) { + skip = node.content.childCount; // This assumes that the content node is always the first child of the oli block, // as the content model grows this assumption may need to change if (node.content.child(0).attrs.position !== `${count}.`) { // TODO: @DAlperin currently sub-items just continue from the order of the parent, // sub-items should be ordered separately with letters or roman numerals or some such - newTr.setNodeMarkup(pos+1, undefined, {...node.attrs, position: `${count}.`}) - modified = true + newTr.setNodeMarkup(pos + 1, undefined, { + ...node.attrs, + position: `${count}.`, + }); + modified = true; } - count++ - } else if (skip > 0) skip-- - }) - if (modified){ - return newTr + count++; + } else if (skip > 0) { + skip--; + } + }); + if (modified) { + return newTr; } - return null - } - }) -} + return null; + }, + }); +}; diff --git a/packages/core/src/extensions/Blocks/nodes/Block.ts b/packages/core/src/extensions/Blocks/nodes/Block.ts index 9b5ac04678..29ab6e37a7 100644 --- a/packages/core/src/extensions/Blocks/nodes/Block.ts +++ b/packages/core/src/extensions/Blocks/nodes/Block.ts @@ -3,7 +3,7 @@ import { Selection } from "prosemirror-state"; import styles from "./Block.module.css"; import { PreviousBlockTypePlugin } from "../PreviousBlockTypePlugin"; import { textblockTypeInputRuleSameNodeType } from "../rule"; -import {OrderedListPlugin} from "../OrderedListPlugin"; +import { OrderedListPlugin } from "../OrderedListPlugin"; export interface IBlock { HTMLAttributes: Record; diff --git a/packages/core/src/extensions/Blocks/nodes/Content.ts b/packages/core/src/extensions/Blocks/nodes/Content.ts index 39ab511ae4..5c0a7d1497 100644 --- a/packages/core/src/extensions/Blocks/nodes/Content.ts +++ b/packages/core/src/extensions/Blocks/nodes/Content.ts @@ -18,12 +18,12 @@ export const ContentBlock = Node.create({ default: undefined, renderHTML: (attributes) => { return { - "data-position": attributes.position - } + "data-position": attributes.position, + }; }, - parseHTML: (element) => element.getAttribute("data-position") - } - } + parseHTML: (element) => element.getAttribute("data-position"), + }, + }; }, content: "inline*",