From 47f6b7926306435a9c50ccb16faea92b2ec7b851 Mon Sep 17 00:00:00 2001 From: Yuriy Demidov Date: Thu, 6 Jun 2024 11:03:48 +0300 Subject: [PATCH] refactor: add presets like from markdown-it (#264) Added presets similar to presets in markdown-it (zero, commonmark, default). And two additional ones: yfm and full. --- src/bundle/wysiwyg-preset.ts | 27 +------ src/commands/join.test.ts | 4 +- src/extensions/base/index.ts | 19 ----- src/extensions/base/specs.ts | 12 --- src/extensions/behavior/index.ts | 16 ++-- .../markdown/Blockquote/Blockquote.test.ts | 4 +- .../markdown/Blockquote/commands.test.ts | 4 +- src/extensions/markdown/Bold/Bold.test.ts | 4 +- src/extensions/markdown/Breaks/Breaks.test.ts | 4 +- src/extensions/markdown/Code/Code.test.ts | 4 +- .../markdown/CodeBlock/CodeBlock.test.ts | 4 +- .../markdown/Deflist/Deflist.test.ts | 4 +- .../markdown/Heading/Heading.test.ts | 4 +- .../HorizontalRule/HorizontalRule.test.ts | 4 +- src/extensions/markdown/Image/Image.test.ts | 4 +- src/extensions/markdown/Italic/Italic.test.ts | 4 +- src/extensions/markdown/Link/Link.test.ts | 4 +- src/extensions/markdown/Lists/Lists.test.ts | 4 +- .../markdown/Lists/commands.test.ts | 4 +- src/extensions/markdown/Mark/Mark.test.ts | 4 +- src/extensions/markdown/Strike/Strike.test.ts | 4 +- .../markdown/Subscript/Subscript.test.ts | 4 +- .../markdown/Superscript/Superscript.test.ts | 4 +- src/extensions/markdown/Table/Table.test.ts | 4 +- .../markdown/Underline/Underline.test.ts | 4 +- src/extensions/markdown/index.ts | 76 ------------------- src/extensions/markdown/specs.ts | 73 ------------------ src/extensions/yfm/Checkbox/Checkbox.test.ts | 4 +- src/extensions/yfm/Color/Color.test.ts | 4 +- .../yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts | 4 +- src/extensions/yfm/Math/Math.test.ts | 4 +- src/extensions/yfm/Mermaid/Mermaid.test.ts | 4 +- .../yfm/Monospace/Monospace.test.ts | 4 +- src/extensions/yfm/Video/Video.test.ts | 4 +- src/extensions/yfm/YfmCut/YfmCut.test.ts | 4 +- src/extensions/yfm/YfmFile/YfmFile.test.ts | 4 +- .../yfm/YfmHeading/YfmHeading.test.ts | 4 +- src/extensions/yfm/YfmNote/YfmNote.test.ts | 4 +- src/extensions/yfm/YfmTable/YfmTable.test.ts | 4 +- src/extensions/yfm/YfmTabs/YfmTabs.test.ts | 4 +- src/extensions/yfm/index.ts | 44 +---------- src/extensions/yfm/specs.ts | 45 +---------- src/presets/commonmark-specs.ts | 56 ++++++++++++++ src/presets/commonmark.ts | 65 ++++++++++++++++ src/presets/default-specs.ts | 13 ++++ src/presets/default.ts | 15 ++++ src/presets/full-specs.ts | 25 ++++++ src/presets/full.ts | 19 +++++ src/presets/yfm-specs.ts | 66 ++++++++++++++++ src/presets/yfm.ts | 68 +++++++++++++++++ src/presets/zero-specs.ts | 10 +++ src/presets/zero.ts | 20 +++++ 52 files changed, 438 insertions(+), 367 deletions(-) create mode 100644 src/presets/commonmark-specs.ts create mode 100644 src/presets/commonmark.ts create mode 100644 src/presets/default-specs.ts create mode 100644 src/presets/default.ts create mode 100644 src/presets/full-specs.ts create mode 100644 src/presets/full.ts create mode 100644 src/presets/yfm-specs.ts create mode 100644 src/presets/yfm.ts create mode 100644 src/presets/zero-specs.ts create mode 100644 src/presets/zero.ts diff --git a/src/bundle/wysiwyg-preset.ts b/src/bundle/wysiwyg-preset.ts index b92a932e..93a769e1 100644 --- a/src/bundle/wysiwyg-preset.ts +++ b/src/bundle/wysiwyg-preset.ts @@ -1,32 +1,18 @@ import {Node} from 'prosemirror-model'; import {ExtensionAuto} from '../core'; -import { - BasePreset, - BasePresetOptions, - BehaviorPreset, - BehaviorPresetOptions, - MarkdownBlocksPreset, - MarkdownBlocksPresetOptions, - MarkdownMarksPreset, - MarkdownMarksPresetOptions, - YfmPreset, - YfmPresetOptions, -} from '../extensions'; +import {BehaviorPreset, BehaviorPresetOptions} from '../extensions/behavior'; import {EditorModeKeymap, EditorModeKeymapOptions} from '../extensions/behavior/EditorModeKeymap'; import {BaseNode, YfmHeadingAttr, YfmNoteNode} from '../extensions/specs'; import {i18n as i18nPlaceholder} from '../i18n/placeholder'; +import {FullPreset, FullPresetOptions} from '../presets/full'; import {Action as A, formatter as f} from '../shortcuts'; import type {FileUploadHandler} from '../utils/upload'; import {wCommandMenuConfig, wSelectionMenuConfig} from './config/wysiwyg'; import {emojiDefs} from './emoji'; -export type ExtensionsOptions = BasePresetOptions & - MarkdownMarksPresetOptions & - Omit & - YfmPresetOptions & - BehaviorPresetOptions; +export type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions; export type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & { @@ -126,12 +112,7 @@ export const BundlePreset: ExtensionAuto = (builder, opts) }, }; - builder - .use(BehaviorPreset, options) - .use(BasePreset, options) - .use(MarkdownMarksPreset, options) - .use(MarkdownBlocksPreset, {...options, image: false, heading: false}) - .use(YfmPreset, options); + builder.use(BehaviorPreset, options).use(FullPreset, options); const ignoreActions = [ A.Undo, diff --git a/src/commands/join.test.ts b/src/commands/join.test.ts index 4d7f483e..96f2e9ca 100644 --- a/src/commands/join.test.ts +++ b/src/commands/join.test.ts @@ -3,7 +3,7 @@ import {Command, EditorState, Selection, TextSelection, Transaction} from 'prose import {builders} from 'prosemirror-test-builder'; import {ExtensionsManager} from '../core'; -import {BaseNode, BaseSpecsPreset} from '../extensions/base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../extensions/base/specs'; import { BlockquoteSpecs, DeflistNode, @@ -20,7 +20,7 @@ import {joinPreviousBlock} from './join'; const {schema} = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(Html).use(DeflistSpecs, {}), + builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs).use(Html).use(DeflistSpecs, {}), }).buildDeps(); const {doc, p, bq, htmlBlock, dList, dTerm, dDesc} = builders< diff --git a/src/extensions/base/index.ts b/src/extensions/base/index.ts index 38a4c13b..07bdfe6d 100644 --- a/src/extensions/base/index.ts +++ b/src/extensions/base/index.ts @@ -1,23 +1,4 @@ -import type {ExtensionAuto} from '../../core'; - -import {BaseInputRules} from './BaseInputRules'; -import {BaseKeymap} from './BaseKeymap'; -import {BaseSchema, BaseSchemaOptions} from './BaseSchema'; -import {BaseStyles} from './BaseStyles'; - export * from './BaseSchema'; export * from './BaseStyles'; export * from './BaseKeymap'; export * from './BaseInputRules'; - -export type BasePresetOptions = { - baseSchema?: BaseSchemaOptions; -}; - -export const BasePreset: ExtensionAuto = (builder, opts) => { - builder - .use(BaseSchema, opts.baseSchema ?? {}) - .use(BaseKeymap) - .use(BaseInputRules) - .use(BaseStyles); -}; diff --git a/src/extensions/base/specs.ts b/src/extensions/base/specs.ts index e15b5508..4e5b2aed 100644 --- a/src/extensions/base/specs.ts +++ b/src/extensions/base/specs.ts @@ -1,13 +1 @@ -import type {ExtensionAuto} from '../../core'; - -import {BaseSchemaSpecs, BaseSchemaSpecsOptions} from './BaseSchema/BaseSchemaSpecs'; - export * from './BaseSchema/BaseSchemaSpecs'; - -export type BaseSpecPresetOptions = { - baseSchema?: BaseSchemaSpecsOptions; -}; - -export const BaseSpecsPreset: ExtensionAuto = (builder, opts) => { - builder.use(BaseSchemaSpecs, opts.baseSchema ?? {}); -}; diff --git a/src/extensions/behavior/index.ts b/src/extensions/behavior/index.ts index 956019f5..c7e9f080 100644 --- a/src/extensions/behavior/index.ts +++ b/src/extensions/behavior/index.ts @@ -1,6 +1,5 @@ import type {ExtensionAuto} from '../../core'; import {PlaceholderOptions} from '../../utils/placeholder'; -import {Emoji, EmojiOptions} from '../yfm/Emoji'; import {ClicksOnEdges} from './ClicksOnEdges'; import {Clipboard, ClipboardOptions} from './Clipboard'; @@ -14,12 +13,17 @@ import {Selection} from './Selection'; import {SelectionContext, SelectionContextOptions} from './SelectionContext'; import {WidgetDecoration} from './WidgetDecoration'; +export * from './ClicksOnEdges'; +export * from './Clipboard'; +export * from './CommandMenu'; export * from './Cursor'; +export * from './FilePaste'; export * from './History'; -export * from './Clipboard'; -export * from './Selection'; export * from './Placeholder'; export * from './ReactRenderer'; +export * from './Selection'; +export * from './SelectionContext'; +export * from './WidgetDecoration'; export type BehaviorPresetOptions = { cursor?: CursorOptions; @@ -30,8 +34,6 @@ export type BehaviorPresetOptions = { selectionContext?: SelectionContextOptions; commandMenu?: CommandMenuOptions; - - emoji?: EmojiOptions; }; export const BehaviorPreset: ExtensionAuto = (builder, opts) => { @@ -45,10 +47,6 @@ export const BehaviorPreset: ExtensionAuto = (builder, op .use(WidgetDecoration) .use(SelectionContext, opts.selectionContext ?? {}); - if (opts.emoji) { - builder.use(Emoji, opts.emoji); - } - if (opts.commandMenu) builder.use(CommandMenu, opts.commandMenu); builder.use(FilePaste); builder.use(ClicksOnEdges); diff --git a/src/extensions/markdown/Blockquote/Blockquote.test.ts b/src/extensions/markdown/Blockquote/Blockquote.test.ts index 0a3defcf..62316709 100644 --- a/src/extensions/markdown/Blockquote/Blockquote.test.ts +++ b/src/extensions/markdown/Blockquote/Blockquote.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BlockquoteSpecs, blockquoteNodeName} from './BlockquoteSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs), }).buildDeps(); const {doc, p, q} = builders<'doc' | 'p' | 'q'>(schema, { diff --git a/src/extensions/markdown/Blockquote/commands.test.ts b/src/extensions/markdown/Blockquote/commands.test.ts index 6d0fa358..eaa5149d 100644 --- a/src/extensions/markdown/Blockquote/commands.test.ts +++ b/src/extensions/markdown/Blockquote/commands.test.ts @@ -4,7 +4,7 @@ import {builders} from 'prosemirror-test-builder'; import {ExtensionsManager} from '../../../core'; import {get$Cursor, isNodeSelection} from '../../../utils/selection'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {DeflistNode, DeflistSpecs} from '../Deflist/DeflistSpecs'; import {Html, HtmlAttr, HtmlNode} from '../Html'; @@ -13,7 +13,7 @@ import {joinPrevQuote} from './commands'; const {schema} = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(Html).use(DeflistSpecs, {}), + builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs).use(Html).use(DeflistSpecs, {}), }).buildDeps(); const {doc, p, bq, htmlBlock, dList, dTerm, dDesc} = builders< diff --git a/src/extensions/markdown/Bold/Bold.test.ts b/src/extensions/markdown/Bold/Bold.test.ts index 390ccc67..f705654e 100644 --- a/src/extensions/markdown/Bold/Bold.test.ts +++ b/src/extensions/markdown/Bold/Bold.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName} from './BoldSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BoldSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(BoldSpecs), }).buildDeps(); const {doc, p, b} = builders<'doc' | 'p', 'b'>(schema, { diff --git a/src/extensions/markdown/Breaks/Breaks.test.ts b/src/extensions/markdown/Breaks/Breaks.test.ts index 00b988b4..e640a067 100644 --- a/src/extensions/markdown/Breaks/Breaks.test.ts +++ b/src/extensions/markdown/Breaks/Breaks.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName} from '../../markdown/Bold/BoldSpecs'; import {BreakNodeName, BreaksSpecs} from './BreaksSpecs'; @@ -13,7 +13,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BreaksSpecs, {}).use(BoldSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(BreaksSpecs, {}).use(BoldSpecs), }).buildDeps(); const {doc, p, hb, sb, bold} = builders<'doc' | 'p' | 'hb' | 'sb', 'bold'>(schema, { diff --git a/src/extensions/markdown/Code/Code.test.ts b/src/extensions/markdown/Code/Code.test.ts index 6e8904f8..e2327700 100644 --- a/src/extensions/markdown/Code/Code.test.ts +++ b/src/extensions/markdown/Code/Code.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName} from '../Bold/BoldSpecs'; import {ItalicSpecs, italicMarkName} from '../Italic/ItalicSpecs'; @@ -15,7 +15,7 @@ const { serializer, } = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(BoldSpecs).use(CodeSpecs).use(ItalicSpecs), + builder.use(BaseSchemaSpecs, {}).use(BoldSpecs).use(CodeSpecs).use(ItalicSpecs), }).buildDeps(); const {doc, p, b, i, c} = builders<'doc' | 'p', 'b' | 'i' | 'c'>(schema, { diff --git a/src/extensions/markdown/CodeBlock/CodeBlock.test.ts b/src/extensions/markdown/CodeBlock/CodeBlock.test.ts index bcbafe9e..e45405a3 100644 --- a/src/extensions/markdown/CodeBlock/CodeBlock.test.ts +++ b/src/extensions/markdown/CodeBlock/CodeBlock.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {CodeBlockNodeAttr, CodeBlockSpecs, codeBlockNodeName} from './CodeBlockSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(CodeBlockSpecs, {}), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(CodeBlockSpecs, {}), }).buildDeps(); const {doc, p, cb} = builders<'doc' | 'p' | 'cb'>(schema, { diff --git a/src/extensions/markdown/Deflist/Deflist.test.ts b/src/extensions/markdown/Deflist/Deflist.test.ts index 2c6b5306..9649f010 100644 --- a/src/extensions/markdown/Deflist/Deflist.test.ts +++ b/src/extensions/markdown/Deflist/Deflist.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {DeflistNode, DeflistSpecs} from './DeflistSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(DeflistSpecs, {}), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(DeflistSpecs, {}), }).buildDeps(); const {doc, p, dl, dt, dd} = builders<'doc' | 'p' | 'dl' | 'dt' | 'dd'>(schema, { diff --git a/src/extensions/markdown/Heading/Heading.test.ts b/src/extensions/markdown/Heading/Heading.test.ts index b37ed93c..75316aa7 100644 --- a/src/extensions/markdown/Heading/Heading.test.ts +++ b/src/extensions/markdown/Heading/Heading.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName} from '../Bold/BoldSpecs'; import {HeadingSpecs} from './HeadingSpecs'; @@ -14,7 +14,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(HeadingSpecs, {}).use(BoldSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(HeadingSpecs, {}).use(BoldSpecs), }).buildDeps(); const {doc, b, p, h, h1, h2, h3, h4, h5, h6} = builders< diff --git a/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts b/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts index 6c7e4c71..b9090041 100644 --- a/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts +++ b/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import { HorizontalRuleSpecs, @@ -16,7 +16,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(HorizontalRuleSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(HorizontalRuleSpecs), }).buildDeps(); const {doc, p, hr, hr2, hr3} = builders<'doc' | 'p' | 'hr' | 'hr2' | 'hr3'>(schema, { diff --git a/src/extensions/markdown/Image/Image.test.ts b/src/extensions/markdown/Image/Image.test.ts index d4746665..8475a67f 100644 --- a/src/extensions/markdown/Image/Image.test.ts +++ b/src/extensions/markdown/Image/Image.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {ImageAttr, ImageSpecs, imageNodeName} from './ImageSpecs'; @@ -11,7 +11,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ImageSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(ImageSpecs), }).buildDeps(); const {doc, p, img, img2} = builders<'doc' | 'p' | 'img' | 'img2'>(schema, { diff --git a/src/extensions/markdown/Italic/Italic.test.ts b/src/extensions/markdown/Italic/Italic.test.ts index 39a322c5..836243a8 100644 --- a/src/extensions/markdown/Italic/Italic.test.ts +++ b/src/extensions/markdown/Italic/Italic.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {ItalicSpecs, italicMarkName} from './ItalicSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ItalicSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(ItalicSpecs), }).buildDeps(); const {doc, p, i} = builders<'doc' | 'p', 'i'>(schema, { diff --git a/src/extensions/markdown/Link/Link.test.ts b/src/extensions/markdown/Link/Link.test.ts index 9c067804..7ca858ce 100644 --- a/src/extensions/markdown/Link/Link.test.ts +++ b/src/extensions/markdown/Link/Link.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {LinkAttr, LinkSpecs, linkMarkName} from './LinkSpecs'; @@ -11,7 +11,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(LinkSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(LinkSpecs), }).buildDeps(); const {doc, p, a, lnk, lnk4} = builders<'doc' | 'p' | 'a' | 'lnk' | 'lnk4'>(schema, { diff --git a/src/extensions/markdown/Lists/Lists.test.ts b/src/extensions/markdown/Lists/Lists.test.ts index d41be985..6d1b1b1c 100644 --- a/src/extensions/markdown/Lists/Lists.test.ts +++ b/src/extensions/markdown/Lists/Lists.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {ListNode, ListsSpecs} from './ListsSpecs'; @@ -11,7 +11,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ListsSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(ListsSpecs), }).buildDeps(); const {doc, p, li, ul, ol} = builders<'doc' | 'p' | 'li' | 'ul' | 'ol'>(schema, { diff --git a/src/extensions/markdown/Lists/commands.test.ts b/src/extensions/markdown/Lists/commands.test.ts index ed5385be..74be557b 100644 --- a/src/extensions/markdown/Lists/commands.test.ts +++ b/src/extensions/markdown/Lists/commands.test.ts @@ -4,14 +4,14 @@ import {EditorView} from 'prosemirror-view'; import {ExtensionsManager} from '../../../core'; import {get$Cursor} from '../../../utils/selection'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {ListsSpecs} from './ListsSpecs'; import {liftIfCursorIsAtBeginningOfItem} from './commands'; import {ListNode} from './const'; const {schema} = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ListsSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(ListsSpecs), }).buildDeps(); const { diff --git a/src/extensions/markdown/Mark/Mark.test.ts b/src/extensions/markdown/Mark/Mark.test.ts index 539bf960..fdc9c294 100644 --- a/src/extensions/markdown/Mark/Mark.test.ts +++ b/src/extensions/markdown/Mark/Mark.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {MarkSpecs, markMarkName} from './MarkSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MarkSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(MarkSpecs), }).buildDeps(); const {doc, p, m} = builders<'doc' | 'p', 'm'>(schema, { diff --git a/src/extensions/markdown/Strike/Strike.test.ts b/src/extensions/markdown/Strike/Strike.test.ts index b49dbba5..9cf14c0e 100644 --- a/src/extensions/markdown/Strike/Strike.test.ts +++ b/src/extensions/markdown/Strike/Strike.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {StrikeSpecs, strikeMarkName} from './StrikeSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(StrikeSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(StrikeSpecs), }).buildDeps(); const {doc, p, s} = builders<'doc' | 'p', 's'>(schema, { diff --git a/src/extensions/markdown/Subscript/Subscript.test.ts b/src/extensions/markdown/Subscript/Subscript.test.ts index b0658853..74b199c0 100644 --- a/src/extensions/markdown/Subscript/Subscript.test.ts +++ b/src/extensions/markdown/Subscript/Subscript.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {SubscriptSpecs, subscriptMarkName} from './SubscriptSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(SubscriptSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(SubscriptSpecs), }).buildDeps(); const {doc, p, s} = builders<'doc' | 'p', 's'>(schema, { diff --git a/src/extensions/markdown/Superscript/Superscript.test.ts b/src/extensions/markdown/Superscript/Superscript.test.ts index f19d330f..dceeeddb 100644 --- a/src/extensions/markdown/Superscript/Superscript.test.ts +++ b/src/extensions/markdown/Superscript/Superscript.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {SuperscriptSpecs, superscriptMarkName} from './SuperscriptSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(SuperscriptSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(SuperscriptSpecs), }).buildDeps(); const {doc, p, s} = builders<'doc' | 'p', 's'>(schema, { diff --git a/src/extensions/markdown/Table/Table.test.ts b/src/extensions/markdown/Table/Table.test.ts index 42a3c58e..19459d4d 100644 --- a/src/extensions/markdown/Table/Table.test.ts +++ b/src/extensions/markdown/Table/Table.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BlockquoteSpecs, blockquoteNodeName} from '../Blockquote/BlockquoteSpecs'; import {TableSpecs} from './TableSpecs'; @@ -14,7 +14,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(TableSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs).use(TableSpecs), }).buildDeps(); const {doc, bq, table, thead, tbody, tr, thL, thC, thR, tdL, tdC, tdR} = builders< diff --git a/src/extensions/markdown/Underline/Underline.test.ts b/src/extensions/markdown/Underline/Underline.test.ts index bdd53999..d07d771a 100644 --- a/src/extensions/markdown/Underline/Underline.test.ts +++ b/src/extensions/markdown/Underline/Underline.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {UnderlineSpecs, underlineMarkName} from './UnderlineSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(UnderlineSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(UnderlineSpecs), }).buildDeps(); const {doc, p, u} = builders<'doc' | 'p', 'u'>(schema, { diff --git a/src/extensions/markdown/index.ts b/src/extensions/markdown/index.ts index 382066df..d6c8feb9 100644 --- a/src/extensions/markdown/index.ts +++ b/src/extensions/markdown/index.ts @@ -1,26 +1,3 @@ -import type {Extension, ExtensionAuto} from '../../core'; -import {isFunction} from '../../lodash'; - -import {Blockquote, BlockquoteOptions} from './Blockquote'; -import {Bold, BoldOptions} from './Bold'; -import {Breaks, BreaksOptions} from './Breaks'; -import {Code, CodeOptions} from './Code'; -import {CodeBlock, CodeBlockOptions} from './CodeBlock'; -import {Deflist, DeflistOptions} from './Deflist'; -import {Heading, HeadingOptions} from './Heading'; -import {HorizontalRule} from './HorizontalRule'; -import {Html} from './Html'; -import {Image} from './Image'; -import {Italic, ItalicOptions} from './Italic'; -import {Link, LinkOptions} from './Link'; -import {Lists, ListsOptions} from './Lists'; -import {Mark} from './Mark'; -import {Strike, StrikeOptions} from './Strike'; -import {Subscript} from './Subscript'; -import {Superscript} from './Superscript'; -import {Table} from './Table'; -import {Underline, UnderlineOptions} from './Underline'; - export * from './Bold'; export * from './Code'; export * from './Link'; @@ -41,56 +18,3 @@ export * from './Image'; export * from './Table'; export * from './Heading'; export * from './HorizontalRule'; - -export type MarkdownMarksPresetOptions = { - bold?: BoldOptions; - italic?: ItalicOptions; - strike?: StrikeOptions; - underline?: UnderlineOptions; - code?: CodeOptions; - link?: LinkOptions; -}; - -export const MarkdownMarksPreset: ExtensionAuto = (builder, opts) => { - builder - .use(Bold, opts.bold ?? {}) - .use(Code, opts.code ?? {}) - .use(Italic, opts.italic ?? {}) - .use(Strike, opts.strike ?? {}) - .use(Underline, opts.underline ?? {}) - .use(Link, opts.link ?? {}) - .use(Mark) - .use(Subscript) - .use(Superscript); -}; - -export type MarkdownBlocksPresetOptions = { - image?: false | Extension; - lists?: ListsOptions; - breaks?: BreaksOptions; - deflist?: DeflistOptions; - codeBlock?: CodeBlockOptions; - blockquote?: BlockquoteOptions; - heading?: false | Extension | HeadingOptions; -}; - -export const MarkdownBlocksPreset: ExtensionAuto = (builder, opts) => { - builder - .use(Html) - .use(Table) - .use(HorizontalRule) - .use(Lists, opts.lists ?? {}) - .use(Breaks, opts.breaks ?? {}) - .use(Deflist, opts.deflist ?? {}) - .use(CodeBlock, opts.codeBlock ?? {}) - .use(Blockquote, opts.blockquote ?? {}); - - if (opts.image !== false) { - builder.use(isFunction(opts.image) ? opts.image : Image); - } - - if (opts.heading !== false) { - if (isFunction(opts.heading)) builder.use(opts.heading); - else builder.use(Heading, opts.heading ?? {}); - } -}; diff --git a/src/extensions/markdown/specs.ts b/src/extensions/markdown/specs.ts index 62e8ead2..a5586dff 100644 --- a/src/extensions/markdown/specs.ts +++ b/src/extensions/markdown/specs.ts @@ -1,26 +1,3 @@ -import type {Extension, ExtensionAuto} from '../../core'; -import {isFunction} from '../../lodash'; - -import {BlockquoteSpecs} from './Blockquote/BlockquoteSpecs'; -import {BoldSpecs} from './Bold/BoldSpecs'; -import {BreaksSpecs, BreaksSpecsOptions} from './Breaks/BreaksSpecs'; -import {CodeSpecs} from './Code/CodeSpecs'; -import {CodeBlockSpecs, CodeBlockSpecsOptions} from './CodeBlock/CodeBlockSpecs'; -import {DeflistSpecs, DeflistSpecsOptions} from './Deflist/DeflistSpecs'; -import {HeadingSpecs, HeadingSpecsOptions} from './Heading/HeadingSpecs'; -import {HorizontalRuleSpecs} from './HorizontalRule/HorizontalRuleSpecs'; -import {Html} from './Html'; -import {ImageSpecs} from './Image/ImageSpecs'; -import {ItalicSpecs} from './Italic/ItalicSpecs'; -import {LinkSpecs} from './Link/LinkSpecs'; -import {ListsSpecs} from './Lists/ListsSpecs'; -import {MarkSpecs} from './Mark/MarkSpecs'; -import {StrikeSpecs} from './Strike/StrikeSpecs'; -import {SubscriptSpecs} from './Subscript/SubscriptSpecs'; -import {SuperscriptSpecs} from './Superscript/SuperscriptSpecs'; -import {TableSpecs} from './Table/TableSpecs'; -import {UnderlineSpecs} from './Underline/UnderlineSpecs'; - export * from './Bold/BoldSpecs'; export * from './Code/CodeSpecs'; export * from './Link/LinkSpecs'; @@ -41,53 +18,3 @@ export * from './Lists/ListsSpecs'; export * from './Table/TableSpecs'; export * from './Heading/HeadingSpecs'; export * from './HorizontalRule/HorizontalRuleSpecs'; - -export type MarkdownMarksSpecsPresetOptions = {}; - -export const MarkdownMarksSpecsPreset: ExtensionAuto = ( - builder, - _opts, -) => { - builder - .use(BoldSpecs) - .use(CodeSpecs) - .use(ItalicSpecs) - .use(StrikeSpecs) - .use(UnderlineSpecs) - .use(LinkSpecs) - .use(MarkSpecs) - .use(SubscriptSpecs) - .use(SuperscriptSpecs); -}; - -export type MarkdownBlocksSpecsPresetOptions = { - image?: false | Extension; - breaks?: BreaksSpecsOptions; - codeBlock?: CodeBlockSpecsOptions; - deflist?: DeflistSpecsOptions; - heading?: false | Extension | HeadingSpecsOptions; -}; - -export const MarkdownBlocksSpecsPreset: ExtensionAuto = ( - builder, - opts, -) => { - builder - .use(Html) - .use(ListsSpecs) - .use(TableSpecs) - .use(BreaksSpecs, opts.breaks ?? {}) - .use(BlockquoteSpecs) - .use(HorizontalRuleSpecs) - .use(DeflistSpecs, opts.deflist ?? {}) - .use(CodeBlockSpecs, opts.codeBlock ?? {}); - - if (opts.image !== false) { - builder.use(isFunction(opts.image) ? opts.image : ImageSpecs); - } - - if (opts.heading !== false) { - if (isFunction(opts.heading)) builder.use(opts.heading); - else builder.use(HeadingSpecs, opts.heading ?? {}); - } -}; diff --git a/src/extensions/yfm/Checkbox/Checkbox.test.ts b/src/extensions/yfm/Checkbox/Checkbox.test.ts index 99e42edc..c23b69d9 100644 --- a/src/extensions/yfm/Checkbox/Checkbox.test.ts +++ b/src/extensions/yfm/Checkbox/Checkbox.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName} from '../../markdown/specs'; import {CheckboxNode, CheckboxSpecs} from './CheckboxSpecs'; @@ -14,7 +14,7 @@ const { } = new ExtensionsManager({ extensions: (builder) => builder - .use(BaseSpecsPreset, {}) + .use(BaseSchemaSpecs, {}) .use(BoldSpecs) .use(CheckboxSpecs, {checkboxLabelPlaceholder: 'checkbox-placeholder'}), }).buildDeps(); diff --git a/src/extensions/yfm/Color/Color.test.ts b/src/extensions/yfm/Color/Color.test.ts index b7d5b72a..99773d46 100644 --- a/src/extensions/yfm/Color/Color.test.ts +++ b/src/extensions/yfm/Color/Color.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {ColorSpecs, colorMarkName} from './ColorSpecs'; @@ -13,7 +13,7 @@ const { serializer, } = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(ColorSpecs, { + builder.use(BaseSchemaSpecs, {}).use(ColorSpecs, { validateClassNameColorName: (color) => color !== 'something', parseStyleColorValue: (value: string) => (value === 'darkred' ? 'red' : null), }), diff --git a/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts b/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts index 5a735d6c..7b3293e7 100644 --- a/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts +++ b/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../../../extensions/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../../../extensions/specs'; import {EmojiSpecs} from './EmojiSpecs'; @@ -11,7 +11,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(EmojiSpecs, {defs: {ddd: 'x'}}), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(EmojiSpecs, {defs: {ddd: 'x'}}), }).buildDeps(); const {doc, p, emoji} = builders<'doc' | 'p' | 'emoji'>(schema, { diff --git a/src/extensions/yfm/Math/Math.test.ts b/src/extensions/yfm/Math/Math.test.ts index 118ebd81..b82fd1b6 100644 --- a/src/extensions/yfm/Math/Math.test.ts +++ b/src/extensions/yfm/Math/Math.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {MathNode, MathSpecs} from './MathSpecs'; @@ -11,7 +11,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MathSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(MathSpecs), }).buildDeps(); const {doc, p, mathB, mathI} = builders<'doc' | 'p' | 'mathB' | 'mathI'>(schema, { diff --git a/src/extensions/yfm/Mermaid/Mermaid.test.ts b/src/extensions/yfm/Mermaid/Mermaid.test.ts index ee1f96a5..496464d5 100644 --- a/src/extensions/yfm/Mermaid/Mermaid.test.ts +++ b/src/extensions/yfm/Mermaid/Mermaid.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../../extensions/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../../extensions/specs'; import {MermaidSpecs} from './MermaidSpecs'; import {MermaidAttrs, mermaidNodeName} from './const'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MermaidSpecs, {}), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(MermaidSpecs, {}), }).buildDeps(); const {doc, mermaid} = builders<'doc' | 'mermaid'>(schema, { diff --git a/src/extensions/yfm/Monospace/Monospace.test.ts b/src/extensions/yfm/Monospace/Monospace.test.ts index 329961be..f1fedccd 100644 --- a/src/extensions/yfm/Monospace/Monospace.test.ts +++ b/src/extensions/yfm/Monospace/Monospace.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {MonospaceSpecs, monospaceMarkName} from './MonospaceSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MonospaceSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(MonospaceSpecs), }).buildDeps(); const {doc, p, m} = builders<'doc' | 'p', 'm'>(schema, { diff --git a/src/extensions/yfm/Video/Video.test.ts b/src/extensions/yfm/Video/Video.test.ts index 554d35e5..90d7f253 100644 --- a/src/extensions/yfm/Video/Video.test.ts +++ b/src/extensions/yfm/Video/Video.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {VideoSpecs} from './VideoSpecs'; import {VideoAttr, videoNodeName} from './VideoSpecs/const'; @@ -13,7 +13,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(VideoSpecs, {}), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(VideoSpecs, {}), }).buildDeps(); const {doc, p} = builders<'doc' | 'p'>(schema, { diff --git a/src/extensions/yfm/YfmCut/YfmCut.test.ts b/src/extensions/yfm/YfmCut/YfmCut.test.ts index a73890c4..be949698 100644 --- a/src/extensions/yfm/YfmCut/YfmCut.test.ts +++ b/src/extensions/yfm/YfmCut/YfmCut.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import { BlockquoteSpecs, ImageAttr, @@ -23,7 +23,7 @@ const { } = new ExtensionsManager({ extensions: (builder) => builder - .use(BaseSpecsPreset, {}) + .use(BaseSchemaSpecs, {}) .use(ItalicSpecs) .use(BlockquoteSpecs) .use(YfmCutSpecs, {}) diff --git a/src/extensions/yfm/YfmFile/YfmFile.test.ts b/src/extensions/yfm/YfmFile/YfmFile.test.ts index 3eb1bc4e..188e656b 100644 --- a/src/extensions/yfm/YfmFile/YfmFile.test.ts +++ b/src/extensions/yfm/YfmFile/YfmFile.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {YfmFileSpecs, yfmFileNodeName} from './YfmFileSpecs'; @@ -12,7 +12,7 @@ const { markupParser: parser, serializer, } = new ExtensionsManager({ - extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(YfmFileSpecs), + extensions: (builder) => builder.use(BaseSchemaSpecs, {}).use(YfmFileSpecs), }).buildDeps(); const {same} = createMarkupChecker({parser, serializer}); diff --git a/src/extensions/yfm/YfmHeading/YfmHeading.test.ts b/src/extensions/yfm/YfmHeading/YfmHeading.test.ts index a8c02669..6a47ea46 100644 --- a/src/extensions/yfm/YfmHeading/YfmHeading.test.ts +++ b/src/extensions/yfm/YfmHeading/YfmHeading.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BoldSpecs, boldMarkName, headingNodeName} from '../../markdown/specs'; import {YfmConfigsSpecs} from '../specs'; @@ -16,7 +16,7 @@ const { } = new ExtensionsManager({ extensions: (builder) => builder - .use(BaseSpecsPreset, {}) + .use(BaseSchemaSpecs, {}) .use(YfmConfigsSpecs, {attrs: {allowedAttributes: ['id']}}) .use(YfmHeadingSpecs, {}) .use(BoldSpecs), diff --git a/src/extensions/yfm/YfmNote/YfmNote.test.ts b/src/extensions/yfm/YfmNote/YfmNote.test.ts index 86a87e09..6ed35afb 100644 --- a/src/extensions/yfm/YfmNote/YfmNote.test.ts +++ b/src/extensions/yfm/YfmNote/YfmNote.test.ts @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import { BlockquoteSpecs, ImageAttr, @@ -24,7 +24,7 @@ const { } = new ExtensionsManager({ extensions: (builder) => builder - .use(BaseSpecsPreset, {}) + .use(BaseSchemaSpecs, {}) .use(ItalicSpecs) .use(BlockquoteSpecs) .use(YfmNoteSpecs, {}) diff --git a/src/extensions/yfm/YfmTable/YfmTable.test.ts b/src/extensions/yfm/YfmTable/YfmTable.test.ts index 9593a93c..7f16b9df 100644 --- a/src/extensions/yfm/YfmTable/YfmTable.test.ts +++ b/src/extensions/yfm/YfmTable/YfmTable.test.ts @@ -6,7 +6,7 @@ import {dispatchPasteEvent} from '../../../../tests/dispatch-event'; import {parseDOM} from '../../../../tests/parse-dom'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BlockquoteSpecs, blockquoteNodeName} from '../../markdown/Blockquote/BlockquoteSpecs'; import {YfmTableNode, YfmTableSpecs} from './YfmTableSpecs'; @@ -18,7 +18,7 @@ const { serializer, } = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(YfmTableSpecs, {}), + builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs).use(YfmTableSpecs, {}), }).build(); const {doc, p, bq, table, tbody, tr, td} = builders< diff --git a/src/extensions/yfm/YfmTabs/YfmTabs.test.ts b/src/extensions/yfm/YfmTabs/YfmTabs.test.ts index 6ecca558..c6a6b428 100644 --- a/src/extensions/yfm/YfmTabs/YfmTabs.test.ts +++ b/src/extensions/yfm/YfmTabs/YfmTabs.test.ts @@ -2,7 +2,7 @@ import {builders} from 'prosemirror-test-builder'; import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; -import {BaseNode, BaseSpecsPreset} from '../../base/specs'; +import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; import {BlockquoteSpecs, blockquoteNodeName, italicMarkName} from '../../markdown/specs'; import {TabsNode, YfmTabsSpecs} from './YfmTabsSpecs'; @@ -24,7 +24,7 @@ const { serializer, } = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(YfmTabsSpecs, {}), + builder.use(BaseSchemaSpecs, {}).use(BlockquoteSpecs).use(YfmTabsSpecs, {}), }).buildDeps(); const {doc, p, bq, tab, tabs, tabPanel, tabsList} = builders< diff --git a/src/extensions/yfm/index.ts b/src/extensions/yfm/index.ts index a0b7b7d0..3ec7646c 100644 --- a/src/extensions/yfm/index.ts +++ b/src/extensions/yfm/index.ts @@ -1,20 +1,6 @@ -import {ExtensionAuto} from '../../core'; - -import {Checkbox, CheckboxOptions} from './Checkbox'; -import {Color} from './Color'; -import {ImgSize, ImgSizeOptions} from './ImgSize'; -import {Monospace} from './Monospace'; -import {Video, VideoOptions} from './Video'; -import {YfmConfigs, YfmConfigsOptions} from './YfmConfigs'; -import {YfmCut, YfmCutOptions} from './YfmCut'; -import {YfmFile, YfmFileOptions} from './YfmFile'; -import {YfmHeading, YfmHeadingOptions} from './YfmHeading'; -import {YfmNote, YfmNoteOptions} from './YfmNote'; -import {YfmTable, YfmTableOptions} from './YfmTable'; -import {YfmTabs} from './YfmTabs'; - export * from './Checkbox'; export * from './Color'; +export * from './Emoji'; export * from './ImgSize'; export * from './Monospace'; export * from './Video'; @@ -25,31 +11,3 @@ export * from './YfmHeading'; export * from './YfmNote'; export * from './YfmTable'; export * from './YfmTabs'; - -export type YfmPresetOptions = { - checkbox?: CheckboxOptions; - imgSize?: ImgSizeOptions; - video?: VideoOptions; - yfmConfigs?: YfmConfigsOptions; - yfmCut?: YfmCutOptions; - yfmFile?: YfmFileOptions; - yfmHeading?: YfmHeadingOptions; - yfmNote?: YfmNoteOptions; - yfmTable?: YfmTableOptions; -}; - -export const YfmPreset: ExtensionAuto = (builder, opts) => { - builder - .use(Checkbox, opts.checkbox ?? {}) - .use(Color) - .use(ImgSize, opts.imgSize ?? {}) - .use(Monospace) - .use(Video, opts.video ?? {}) - .use(YfmConfigs, opts.yfmConfigs ?? {}) - .use(YfmCut, opts.yfmCut ?? {}) - .use(YfmNote, opts.yfmNote ?? {}) - .use(YfmFile, opts.yfmFile ?? {}) - .use(YfmHeading, opts.yfmHeading ?? {}) - .use(YfmTable, opts.yfmTable ?? {}) - .use(YfmTabs); -}; diff --git a/src/extensions/yfm/specs.ts b/src/extensions/yfm/specs.ts index 4cd875fb..281b64d2 100644 --- a/src/extensions/yfm/specs.ts +++ b/src/extensions/yfm/specs.ts @@ -1,20 +1,6 @@ -import type {ExtensionAuto} from '../../core'; - -import {CheckboxSpecs, CheckboxSpecsOptions} from './Checkbox/CheckboxSpecs'; -import {ColorSpecs, ColorSpecsOptions} from './Color/ColorSpecs'; -import {ImgSizeSpecs, ImgSizeSpecsOptions} from './ImgSize/ImgSizeSpecs'; -import {MonospaceSpecs} from './Monospace/MonospaceSpecs'; -import {VideoSpecs, VideoSpecsOptions} from './Video/VideoSpecs'; -import {YfmConfigsSpecs, YfmConfigsSpecsOptions} from './YfmConfigs/YfmConfigsSpecs'; -import {YfmCutSpecs, YfmCutSpecsOptions} from './YfmCut/YfmCutSpecs'; -import {YfmFileSpecs} from './YfmFile/YfmFileSpecs'; -import {YfmHeadingSpecs, YfmHeadingSpecsOptions} from './YfmHeading/YfmHeadingSpecs'; -import {YfmNoteSpecs, YfmNoteSpecsOptions} from './YfmNote/YfmNoteSpecs'; -import {YfmTableSpecs, YfmTableSpecsOptions} from './YfmTable/YfmTableSpecs'; -import {YfmTabsSpecs, YfmTabsSpecsOptions} from './YfmTabs/YfmTabsSpecs'; - export * from './Checkbox/CheckboxSpecs'; export * from './Color/ColorSpecs'; +export * from './Emoji/EmojiSpecs'; export * from './ImgSize/ImgSizeSpecs'; export * from './Monospace/MonospaceSpecs'; export * from './Video/VideoSpecs'; @@ -25,32 +11,3 @@ export * from './YfmHeading/YfmHeadingSpecs'; export * from './YfmNote/YfmNoteSpecs'; export * from './YfmTable/YfmTableSpecs'; export * from './YfmTabs/YfmTabsSpecs'; - -export type YfmSpecsPresetOptions = { - checkbox?: CheckboxSpecsOptions; - color?: ColorSpecsOptions; - video?: VideoSpecsOptions; - imgSize?: ImgSizeSpecsOptions; - yfmConfigs?: YfmConfigsSpecsOptions; - yfmCut?: YfmCutSpecsOptions; - yfmNote?: YfmNoteSpecsOptions; - yfmTable?: YfmTableSpecsOptions; - yfmTabs?: YfmTabsSpecsOptions; - yfmHeading?: YfmHeadingSpecsOptions; -}; - -export const YfmSpecsPreset: ExtensionAuto = (builder, opts) => { - builder - .use(CheckboxSpecs, opts.checkbox ?? {}) - .use(ColorSpecs, opts.color ?? {}) - .use(ImgSizeSpecs, opts.imgSize ?? {}) - .use(MonospaceSpecs) - .use(VideoSpecs, opts.video ?? {}) - .use(YfmConfigsSpecs, opts.yfmConfigs ?? {}) - .use(YfmCutSpecs, opts.yfmCut ?? {}) - .use(YfmNoteSpecs, opts.yfmNote ?? {}) - .use(YfmFileSpecs) - .use(YfmHeadingSpecs, opts.yfmHeading ?? {}) - .use(YfmTableSpecs, opts.yfmTable ?? {}) - .use(YfmTabsSpecs, opts.yfmTabs ?? {}); -}; diff --git a/src/presets/commonmark-specs.ts b/src/presets/commonmark-specs.ts new file mode 100644 index 00000000..7dc852ef --- /dev/null +++ b/src/presets/commonmark-specs.ts @@ -0,0 +1,56 @@ +import type {Extension, ExtensionAuto} from '../core'; +import { + BlockquoteSpecs, + BoldSpecs, + BreaksSpecs, + BreaksSpecsOptions, + CodeBlockSpecs, + CodeBlockSpecsOptions, + CodeSpecs, + HeadingSpecs, + HeadingSpecsOptions, + HorizontalRuleSpecs, + Html, + ImageSpecs, + ItalicSpecs, + LinkSpecs, + ListsSpecs, +} from '../extensions/markdown/specs'; +import {isFunction} from '../lodash'; + +import {ZeroPreset, ZeroPresetOptions} from './zero'; + +export type CommonMarkSpecsPresetOptions = ZeroPresetOptions & { + image?: false | Extension; + breaks?: BreaksSpecsOptions; + codeBlock?: CodeBlockSpecsOptions; + heading?: false | Extension | HeadingSpecsOptions; +}; + +export const CommonMarkSpecsPreset: ExtensionAuto = ( + builder, + opts, +) => { + builder.use(ZeroPreset, opts); + + builder + .use(Html) + .use(BoldSpecs) + .use(ItalicSpecs) + .use(CodeSpecs) + .use(LinkSpecs) + .use(ListsSpecs) + .use(BlockquoteSpecs) + .use(HorizontalRuleSpecs) + .use(BreaksSpecs, opts.breaks ?? {}) + .use(CodeBlockSpecs, opts.codeBlock ?? {}); + + if (opts.image !== false) { + builder.use(isFunction(opts.image) ? opts.image : ImageSpecs); + } + + if (opts.heading !== false) { + if (isFunction(opts.heading)) builder.use(opts.heading); + else builder.use(HeadingSpecs, opts.heading ?? {}); + } +}; diff --git a/src/presets/commonmark.ts b/src/presets/commonmark.ts new file mode 100644 index 00000000..b4333497 --- /dev/null +++ b/src/presets/commonmark.ts @@ -0,0 +1,65 @@ +import type {Extension, ExtensionAuto} from '../core'; +import { + Blockquote, + BlockquoteOptions, + Bold, + BoldOptions, + Breaks, + BreaksOptions, + Code, + CodeBlock, + CodeBlockOptions, + CodeOptions, + Heading, + HeadingOptions, + HorizontalRule, + Html, + Image, + Italic, + ItalicOptions, + Link, + LinkOptions, + Lists, + ListsOptions, +} from '../extensions/markdown'; +import {isFunction} from '../lodash'; + +import {ZeroPreset, ZeroPresetOptions} from './zero'; + +export type CommonMarkPresetOptions = ZeroPresetOptions & { + bold?: BoldOptions; + code?: CodeOptions; + link?: LinkOptions; + lists?: ListsOptions; + italic?: ItalicOptions; + breaks?: BreaksOptions; + image?: false | Extension; + codeBlock?: CodeBlockOptions; + blockquote?: BlockquoteOptions; + heading?: false | Extension | HeadingOptions; +}; + +export const CommonMarkPreset: ExtensionAuto = (builder, opts) => { + builder.use(ZeroPreset, opts); + + builder + .use(Html) + .use(HorizontalRule) + .use(Code, opts.code ?? {}) + .use(Bold, opts.bold ?? {}) + .use(Link, opts.link ?? {}) + .use(Lists, opts.lists ?? {}) + .use(Italic, opts.italic ?? {}) + .use(Breaks, opts.breaks ?? {}) + .use(CodeBlock, opts.codeBlock ?? {}) + .use(Blockquote, opts.blockquote ?? {}); + + if (opts.image !== false) { + builder.use(isFunction(opts.image) ? opts.image : Image); + } + + if (opts.heading !== false) { + if (isFunction(opts.heading)) builder.use(opts.heading); + else builder.use(Heading, opts.heading ?? {}); + } +}; diff --git a/src/presets/default-specs.ts b/src/presets/default-specs.ts new file mode 100644 index 00000000..e99431ce --- /dev/null +++ b/src/presets/default-specs.ts @@ -0,0 +1,13 @@ +import type {ExtensionAuto} from '../core'; +import {StrikeSpecs, TableSpecs} from '../extensions/markdown/specs'; + +import {CommonMarkSpecsPreset, CommonMarkSpecsPresetOptions} from './commonmark-specs'; + +export type DefaultSpecsPresetOptions = CommonMarkSpecsPresetOptions & {}; + +export const DefaultSpecsPreset: ExtensionAuto = (builder, opts) => { + builder.use(CommonMarkSpecsPreset, opts); + + builder.use(StrikeSpecs); + builder.use(TableSpecs); +}; diff --git a/src/presets/default.ts b/src/presets/default.ts new file mode 100644 index 00000000..17039554 --- /dev/null +++ b/src/presets/default.ts @@ -0,0 +1,15 @@ +import type {ExtensionAuto} from '../core'; +import {Strike, StrikeOptions, Table} from '../extensions/markdown'; + +import {CommonMarkPreset, CommonMarkPresetOptions} from './commonmark'; + +export type DefaultPresetOptions = CommonMarkPresetOptions & { + strike?: StrikeOptions; +}; + +export const DefaultPreset: ExtensionAuto = (builder, opts) => { + builder.use(CommonMarkPreset, opts); + + builder.use(Strike, opts.strike ?? {}); + builder.use(Table); +}; diff --git a/src/presets/full-specs.ts b/src/presets/full-specs.ts new file mode 100644 index 00000000..e9f10be6 --- /dev/null +++ b/src/presets/full-specs.ts @@ -0,0 +1,25 @@ +import type {ExtensionAuto} from '../core'; +import { + ColorSpecs, + ColorSpecsOptions, + EmojiSpecs, + EmojiSpecsOptions, + MarkSpecs, +} from '../extensions/specs'; + +import {YfmSpecsPreset, YfmSpecsPresetOptions} from './yfm-specs'; + +export type FullSpecsPresetOptions = YfmSpecsPresetOptions & { + emoji?: EmojiSpecsOptions; + color: ColorSpecsOptions; +}; + +export const FullSpecsPreset: ExtensionAuto = (builder, opts) => { + builder.use(YfmSpecsPreset, opts); + + builder.use(MarkSpecs).use(ColorSpecs, opts.color); + + if (opts.emoji) { + builder.use(EmojiSpecs, opts.emoji); + } +}; diff --git a/src/presets/full.ts b/src/presets/full.ts new file mode 100644 index 00000000..b784f02f --- /dev/null +++ b/src/presets/full.ts @@ -0,0 +1,19 @@ +import type {ExtensionAuto} from '../core'; +import {Color, Emoji, EmojiOptions, Mark} from '../extensions'; + +import {YfmPreset, YfmPresetOptions} from './yfm'; + +export type FullPresetOptions = YfmPresetOptions & + YfmPresetOptions & { + emoji?: EmojiOptions; + }; + +export const FullPreset: ExtensionAuto = (builder, opts) => { + builder.use(YfmPreset, opts); + + builder.use(Mark).use(Color); + + if (opts.emoji) { + builder.use(Emoji, opts.emoji); + } +}; diff --git a/src/presets/yfm-specs.ts b/src/presets/yfm-specs.ts new file mode 100644 index 00000000..24875ff4 --- /dev/null +++ b/src/presets/yfm-specs.ts @@ -0,0 +1,66 @@ +import type {ExtensionAuto} from '../core'; +import { + DeflistSpecs, + DeflistSpecsOptions, + SubscriptSpecs, + SuperscriptSpecs, + UnderlineSpecs, +} from '../extensions/specs'; +import { + CheckboxSpecs, + CheckboxSpecsOptions, + ImgSizeSpecs, + ImgSizeSpecsOptions, + MonospaceSpecs, + VideoSpecs, + VideoSpecsOptions, + YfmConfigsSpecs, + YfmConfigsSpecsOptions, + YfmCutSpecs, + YfmCutSpecsOptions, + YfmFileSpecs, + YfmHeadingSpecs, + YfmHeadingSpecsOptions, + YfmNoteSpecs, + YfmNoteSpecsOptions, + YfmTableSpecs, + YfmTableSpecsOptions, + YfmTabsSpecs, + YfmTabsSpecsOptions, +} from '../extensions/yfm/specs'; + +import {DefaultSpecsPreset, DefaultSpecsPresetOptions} from './default-specs'; + +export type YfmSpecsPresetOptions = Omit & { + checkbox?: CheckboxSpecsOptions; + deflist?: DeflistSpecsOptions; + video?: VideoSpecsOptions; + imgSize?: ImgSizeSpecsOptions; + yfmConfigs?: YfmConfigsSpecsOptions; + yfmCut?: YfmCutSpecsOptions; + yfmNote?: YfmNoteSpecsOptions; + yfmTable?: YfmTableSpecsOptions; + yfmTabs?: YfmTabsSpecsOptions; + yfmHeading?: YfmHeadingSpecsOptions; +}; + +export const YfmSpecsPreset: ExtensionAuto = (builder, opts) => { + builder.use(DefaultSpecsPreset, {...opts, image: false, heading: false}); + + builder + .use(DeflistSpecs, opts.deflist ?? {}) + .use(SubscriptSpecs) + .use(SuperscriptSpecs) + .use(UnderlineSpecs) + .use(CheckboxSpecs, opts.checkbox ?? {}) + .use(ImgSizeSpecs, opts.imgSize ?? {}) + .use(MonospaceSpecs) + .use(VideoSpecs, opts.video ?? {}) + .use(YfmConfigsSpecs, opts.yfmConfigs ?? {}) + .use(YfmCutSpecs, opts.yfmCut ?? {}) + .use(YfmNoteSpecs, opts.yfmNote ?? {}) + .use(YfmFileSpecs) + .use(YfmHeadingSpecs, opts.yfmHeading ?? {}) + .use(YfmTableSpecs, opts.yfmTable ?? {}) + .use(YfmTabsSpecs, opts.yfmTabs ?? {}); +}; diff --git a/src/presets/yfm.ts b/src/presets/yfm.ts new file mode 100644 index 00000000..37a29e68 --- /dev/null +++ b/src/presets/yfm.ts @@ -0,0 +1,68 @@ +import type {ExtensionAuto} from '../core'; +import { + Deflist, + DeflistOptions, + Subscript, + Superscript, + Underline, + UnderlineOptions, +} from '../extensions/markdown'; +import { + Checkbox, + CheckboxOptions, + ImgSize, + ImgSizeOptions, + Monospace, + Video, + VideoOptions, + YfmConfigs, + YfmConfigsOptions, + YfmCut, + YfmCutOptions, + YfmFile, + YfmFileOptions, + YfmHeading, + YfmHeadingOptions, + YfmNote, + YfmNoteOptions, + YfmTable, + YfmTableOptions, + YfmTabs, +} from '../extensions/yfm'; + +import {DefaultPreset, DefaultPresetOptions} from './default'; + +export type YfmPresetOptions = Omit & { + checkbox?: CheckboxOptions; + deflist?: DeflistOptions; + underline?: UnderlineOptions; + imgSize?: ImgSizeOptions; + video?: VideoOptions; + yfmConfigs?: YfmConfigsOptions; + yfmCut?: YfmCutOptions; + yfmFile?: YfmFileOptions; + yfmHeading?: YfmHeadingOptions; + yfmNote?: YfmNoteOptions; + yfmTable?: YfmTableOptions; +}; + +export const YfmPreset: ExtensionAuto = (builder, opts) => { + builder.use(DefaultPreset, {...opts, image: false, heading: false}); + + builder + .use(Deflist, opts.deflist ?? {}) + .use(Subscript) + .use(Superscript) + .use(Underline, opts.underline ?? {}) + .use(Checkbox, opts.checkbox ?? {}) + .use(ImgSize, opts.imgSize ?? {}) + .use(Monospace) + .use(Video, opts.video ?? {}) + .use(YfmConfigs, opts.yfmConfigs ?? {}) + .use(YfmCut, opts.yfmCut ?? {}) + .use(YfmNote, opts.yfmNote ?? {}) + .use(YfmFile, opts.yfmFile ?? {}) + .use(YfmHeading, opts.yfmHeading ?? {}) + .use(YfmTable, opts.yfmTable ?? {}) + .use(YfmTabs); +}; diff --git a/src/presets/zero-specs.ts b/src/presets/zero-specs.ts new file mode 100644 index 00000000..4651c962 --- /dev/null +++ b/src/presets/zero-specs.ts @@ -0,0 +1,10 @@ +import type {ExtensionAuto} from '../core'; +import {BaseSchemaSpecs, BaseSchemaSpecsOptions} from '../extensions/base/specs'; + +export type ZeroSpecPresetOptions = { + baseSchema?: BaseSchemaSpecsOptions; +}; + +export const ZeroSpecsPreset: ExtensionAuto = (builder, opts) => { + builder.use(BaseSchemaSpecs, opts.baseSchema ?? {}); +}; diff --git a/src/presets/zero.ts b/src/presets/zero.ts new file mode 100644 index 00000000..de67bcc9 --- /dev/null +++ b/src/presets/zero.ts @@ -0,0 +1,20 @@ +import type {ExtensionAuto} from '../core'; +import { + BaseInputRules, + BaseKeymap, + BaseSchema, + BaseSchemaOptions, + BaseStyles, +} from '../extensions/base'; + +export type ZeroPresetOptions = { + baseSchema?: BaseSchemaOptions; +}; + +export const ZeroPreset: ExtensionAuto = (builder, opts) => { + builder + .use(BaseSchema, opts.baseSchema ?? {}) + .use(BaseKeymap) + .use(BaseInputRules) + .use(BaseStyles); +};