@gravity-ui/markdown-editor 15.37.0 → 15.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/core/ExtensionBuilder.d.ts +21 -0
- package/build/cjs/core/ExtensionBuilder.js +306 -4
- package/build/cjs/core/ExtensionBuilder.js.map +1 -1
- package/build/cjs/core/markdown/MarkdownSerializer.d.ts +4 -1
- package/build/cjs/core/markdown/MarkdownSerializer.js +86 -23
- package/build/cjs/core/markdown/MarkdownSerializer.js.map +1 -1
- package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.d.ts +13 -0
- package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.js +42 -0
- package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.js.map +1 -0
- package/build/cjs/extensions/behavior/SelectionContext/index.js +10 -7
- package/build/cjs/extensions/behavior/SelectionContext/index.js.map +1 -1
- package/build/cjs/extensions/behavior/SelectionContext/tooltip.d.ts +11 -15
- package/build/cjs/extensions/behavior/SelectionContext/tooltip.js +24 -56
- package/build/cjs/extensions/behavior/SelectionContext/tooltip.js.map +1 -1
- package/build/cjs/extensions/behavior/SelectionContext/types.d.ts +10 -0
- package/build/cjs/extensions/behavior/SelectionContext/types.js +3 -0
- package/build/cjs/extensions/behavior/SelectionContext/types.js.map +1 -0
- package/build/cjs/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js +24 -34
- package/build/cjs/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js.map +1 -1
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.d.ts +4 -0
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.js +9 -0
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.js.map +1 -0
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.d.ts +3 -5
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.js +22 -25
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.js.map +1 -1
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.d.ts +7 -0
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.js +15 -0
- package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.js.map +1 -0
- package/build/cjs/extensions/markdown/Heading/actions.d.ts +2 -2
- package/build/cjs/extensions/markdown/Heading/actions.js +3 -4
- package/build/cjs/extensions/markdown/Heading/actions.js.map +1 -1
- package/build/cjs/extensions/markdown/Heading/commands.d.ts +3 -1
- package/build/cjs/extensions/markdown/Heading/commands.js +16 -1
- package/build/cjs/extensions/markdown/Heading/commands.js.map +1 -1
- package/build/cjs/extensions/markdown/Heading/index.js +7 -9
- package/build/cjs/extensions/markdown/Heading/index.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/index.js +1 -0
- package/build/cjs/extensions/markdown/Lists/index.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +14 -2
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +97 -51
- package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +2 -2
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +3 -7
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +72 -90
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.d.ts +3 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +14 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/actions.js +2 -10
- package/build/cjs/extensions/yfm/YfmHeading/actions.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/commands.d.ts +1 -4
- package/build/cjs/extensions/yfm/YfmHeading/commands.js +3 -21
- package/build/cjs/extensions/yfm/YfmHeading/commands.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/index.d.ts +3 -22
- package/build/cjs/extensions/yfm/YfmHeading/index.js +2 -33
- package/build/cjs/extensions/yfm/YfmHeading/index.js.map +1 -1
- package/build/cjs/presets/yfm-specs.js +5 -1
- package/build/cjs/presets/yfm-specs.js.map +1 -1
- package/build/cjs/presets/yfm.js +5 -1
- package/build/cjs/presets/yfm.js.map +1 -1
- package/build/cjs/version.js +1 -1
- package/build/cjs/version.js.map +1 -1
- package/build/esm/core/ExtensionBuilder.d.ts +21 -0
- package/build/esm/core/ExtensionBuilder.js +306 -4
- package/build/esm/core/ExtensionBuilder.js.map +1 -1
- package/build/esm/core/markdown/MarkdownSerializer.d.ts +4 -1
- package/build/esm/core/markdown/MarkdownSerializer.js +86 -23
- package/build/esm/core/markdown/MarkdownSerializer.js.map +1 -1
- package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.d.ts +13 -0
- package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.js +38 -0
- package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.js.map +1 -0
- package/build/esm/extensions/behavior/SelectionContext/index.js +10 -7
- package/build/esm/extensions/behavior/SelectionContext/index.js.map +1 -1
- package/build/esm/extensions/behavior/SelectionContext/tooltip.d.ts +11 -15
- package/build/esm/extensions/behavior/SelectionContext/tooltip.js +24 -56
- package/build/esm/extensions/behavior/SelectionContext/tooltip.js.map +1 -1
- package/build/esm/extensions/behavior/SelectionContext/types.d.ts +10 -0
- package/build/esm/extensions/behavior/SelectionContext/types.js +2 -0
- package/build/esm/extensions/behavior/SelectionContext/types.js.map +1 -0
- package/build/esm/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js +24 -34
- package/build/esm/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js.map +1 -1
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.d.ts +4 -0
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.js +6 -0
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.js.map +1 -0
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.d.ts +3 -5
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.js +5 -10
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.js.map +1 -1
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.d.ts +7 -0
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.js +12 -0
- package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.js.map +1 -0
- package/build/esm/extensions/markdown/Heading/actions.d.ts +2 -2
- package/build/esm/extensions/markdown/Heading/actions.js +3 -4
- package/build/esm/extensions/markdown/Heading/actions.js.map +1 -1
- package/build/esm/extensions/markdown/Heading/commands.d.ts +3 -1
- package/build/esm/extensions/markdown/Heading/commands.js +15 -1
- package/build/esm/extensions/markdown/Heading/commands.js.map +1 -1
- package/build/esm/extensions/markdown/Heading/index.js +9 -11
- package/build/esm/extensions/markdown/Heading/index.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/index.js +1 -0
- package/build/esm/extensions/markdown/Lists/index.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +14 -2
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +95 -49
- package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +3 -3
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +3 -7
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +70 -90
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.d.ts +3 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +11 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/actions.js +2 -10
- package/build/esm/extensions/yfm/YfmHeading/actions.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/commands.d.ts +1 -4
- package/build/esm/extensions/yfm/YfmHeading/commands.js +3 -21
- package/build/esm/extensions/yfm/YfmHeading/commands.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/index.d.ts +3 -22
- package/build/esm/extensions/yfm/YfmHeading/index.js +0 -31
- package/build/esm/extensions/yfm/YfmHeading/index.js.map +1 -1
- package/build/esm/presets/yfm-specs.js +5 -1
- package/build/esm/presets/yfm-specs.js.map +1 -1
- package/build/esm/presets/yfm.js +5 -1
- package/build/esm/presets/yfm.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Heading = exports.HeadingAction = exports.headingType = exports.headingNodeName = void 0;
|
|
4
|
-
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
5
4
|
const keymap_1 = require("../../../utils/keymap.js");
|
|
6
5
|
const HeadingSpecs_1 = require("./HeadingSpecs/index.js");
|
|
7
6
|
const actions_1 = require("./actions.js");
|
|
@@ -16,22 +15,21 @@ Object.defineProperty(exports, "HeadingAction", { enumerable: true, get: functio
|
|
|
16
15
|
const Heading = (builder, opts) => {
|
|
17
16
|
builder.use(HeadingSpecs_1.HeadingSpecs, opts);
|
|
18
17
|
builder
|
|
19
|
-
.addKeymap((
|
|
18
|
+
.addKeymap(() => {
|
|
20
19
|
const { h1Key, h2Key, h3Key, h4Key, h5Key, h6Key } = opts ?? {};
|
|
21
|
-
const cmd4lvl = (level) => (0, prosemirror_commands_1.setBlockType)((0, HeadingSpecs_1.headingType)(schema), { [const_1.headingLevelAttr]: level });
|
|
22
20
|
const bindings = { Backspace: commands_1.resetHeading };
|
|
23
21
|
if (h1Key)
|
|
24
|
-
bindings[h1Key] = (0, keymap_1.withLogAction)('heading1',
|
|
22
|
+
bindings[h1Key] = (0, keymap_1.withLogAction)('heading1', (0, commands_1.toHeading)(1));
|
|
25
23
|
if (h2Key)
|
|
26
|
-
bindings[h2Key] = (0, keymap_1.withLogAction)('heading2',
|
|
24
|
+
bindings[h2Key] = (0, keymap_1.withLogAction)('heading2', (0, commands_1.toHeading)(2));
|
|
27
25
|
if (h3Key)
|
|
28
|
-
bindings[h3Key] = (0, keymap_1.withLogAction)('heading3',
|
|
26
|
+
bindings[h3Key] = (0, keymap_1.withLogAction)('heading3', (0, commands_1.toHeading)(3));
|
|
29
27
|
if (h4Key)
|
|
30
|
-
bindings[h4Key] = (0, keymap_1.withLogAction)('heading4',
|
|
28
|
+
bindings[h4Key] = (0, keymap_1.withLogAction)('heading4', (0, commands_1.toHeading)(4));
|
|
31
29
|
if (h5Key)
|
|
32
|
-
bindings[h5Key] = (0, keymap_1.withLogAction)('heading5',
|
|
30
|
+
bindings[h5Key] = (0, keymap_1.withLogAction)('heading5', (0, commands_1.toHeading)(5));
|
|
33
31
|
if (h6Key)
|
|
34
|
-
bindings[h6Key] = (0, keymap_1.withLogAction)('heading6',
|
|
32
|
+
bindings[h6Key] = (0, keymap_1.withLogAction)('heading6', (0, commands_1.toHeading)(6));
|
|
35
33
|
return bindings;
|
|
36
34
|
})
|
|
37
35
|
.addInputRules(({ schema }) => ({ rules: [(0, utils_1.headingRule)((0, HeadingSpecs_1.headingType)(schema), 6)] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Heading/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Heading/index.ts"],"names":[],"mappings":";;;AACA,qDAAoD;AAEpD,0DAAmF;AACnF,0CAAwC;AACxC,4CAAmD;AACnD,sCAAsC;AACtC,sCAAoC;AAEpC,wDAA4D;AAApD,+GAAA,eAAe,OAAA;AAAE,2GAAA,WAAW,OAAA;AACpC,oCAAsC;AAA9B,sGAAA,aAAa,OAAA;AAWd,MAAM,OAAO,GAAkC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACpE,OAAO,CAAC,GAAG,CAAC,2BAAY,EAAE,IAAI,CAAC,CAAC;IAEhC,OAAO;SACF,SAAS,CAAC,GAAG,EAAE;QACZ,MAAM,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,GAAG,IAAI,IAAI,EAAE,CAAC;QAE9D,MAAM,QAAQ,GAAW,EAAC,SAAS,EAAE,uBAAY,EAAC,CAAC;QACnD,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAa,EAAC,UAAU,EAAE,IAAA,oBAAS,EAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAa,EAAC,UAAU,EAAE,IAAA,oBAAS,EAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAa,EAAC,UAAU,EAAE,IAAA,oBAAS,EAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,KAAK;YAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAa,EAAC,UAA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EAAE,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,IAAA,uBAAa,EAAC,IAAA,0BAAW,EAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;SAClF,SAAS,CAAC,qBAAa,CAAC,IAAI,EAAE,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,IAAA,uBAAa,EAAC,IAAA,0BAAW,EAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC;AAzBW,QAAA,OAAO,WAyBlB","sourcesContent":["import type {Action, ExtensionAuto, Keymap} from '../../../core';\nimport {withLogAction} from '../../../utils/keymap';\n\nimport {HeadingSpecs, type HeadingSpecsOptions, headingType} from './HeadingSpecs';\nimport {headingAction} from './actions';\nimport {resetHeading, toHeading} from './commands';\nimport {HeadingAction} from './const';\nimport {headingRule} from './utils';\n\nexport {headingNodeName, headingType} from './HeadingSpecs';\nexport {HeadingAction} from './const';\n\nexport type HeadingOptions = HeadingSpecsOptions & {\n h1Key?: string | null;\n h2Key?: string | null;\n h3Key?: string | null;\n h4Key?: string | null;\n h5Key?: string | null;\n h6Key?: string | null;\n};\n\nexport const Heading: ExtensionAuto<HeadingOptions> = (builder, opts) => {\n builder.use(HeadingSpecs, opts);\n\n builder\n .addKeymap(() => {\n const {h1Key, h2Key, h3Key, h4Key, h5Key, h6Key} = opts ?? {};\n\n const bindings: Keymap = {Backspace: resetHeading};\n if (h1Key) bindings[h1Key] = withLogAction('heading1', toHeading(1));\n if (h2Key) bindings[h2Key] = withLogAction('heading2', toHeading(2));\n if (h3Key) bindings[h3Key] = withLogAction('heading3', toHeading(3));\n if (h4Key) bindings[h4Key] = withLogAction('heading4', toHeading(4));\n if (h5Key) bindings[h5Key] = withLogAction('heading5', toHeading(5));\n if (h6Key) bindings[h6Key] = withLogAction('heading6', toHeading(6));\n return bindings;\n })\n .addInputRules(({schema}) => ({rules: [headingRule(headingType(schema), 6)]}));\n\n builder\n .addAction(HeadingAction.ToH1, ({schema}) => headingAction(headingType(schema), 1))\n .addAction(HeadingAction.ToH2, ({schema}) => headingAction(headingType(schema), 2))\n .addAction(HeadingAction.ToH3, ({schema}) => headingAction(headingType(schema), 3))\n .addAction(HeadingAction.ToH4, ({schema}) => headingAction(headingType(schema), 4))\n .addAction(HeadingAction.ToH5, ({schema}) => headingAction(headingType(schema), 5))\n .addAction(HeadingAction.ToH6, ({schema}) => headingAction(headingType(schema), 6));\n};\n\ndeclare global {\n namespace WysiwygEditor {\n interface Actions {\n [HeadingAction.ToH1]: Action;\n [HeadingAction.ToH2]: Action;\n [HeadingAction.ToH3]: Action;\n [HeadingAction.ToH4]: Action;\n [HeadingAction.ToH5]: Action;\n [HeadingAction.ToH6]: Action;\n }\n }\n}\n"]}
|
|
@@ -39,6 +39,7 @@ const Lists = (builder, opts) => {
|
|
|
39
39
|
Backspace: commands_1.joinPrevList,
|
|
40
40
|
}), builder.Priority.Low);
|
|
41
41
|
builder.use(inputrules_1.ListsInputRulesExtension, { bulletListInputRule: opts?.ulInputRules });
|
|
42
|
+
// Order matters: merge must run before collapse (see CollapseListsPlugin.ts)
|
|
42
43
|
builder.addPlugin(MergeListsPlugin_1.mergeListsPlugin);
|
|
43
44
|
builder.addPlugin(CollapseListsPlugin_1.collapseListsPlugin);
|
|
44
45
|
builder
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Lists/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAGpE,qDAAoD;AAEpD,sDAAgE;AAChE,0CAAkC;AAClC,4CAA6F;AAC7F,sCAAmC;AACnC,gDAAmF;AACnF,0EAAkE;AAClE,oEAA4D;AAE5D,oDAAyE;AAAjE,sGAAA,QAAQ,OAAA;AAAE,uGAAA,SAAS,OAAA;AAAE,oGAAA,MAAM,OAAA;AAAE,oGAAA,MAAM,OAAA;AAAE,oGAAA,MAAM,OAAA;AAQ5C,MAAM,KAAK,GAAgC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cesContent":["import {liftListItem, splitListItem} from 'prosemirror-schema-list';\n\nimport type {Action, ExtensionAuto, Keymap} from '../../../core';\nimport {withLogAction} from '../../../utils/keymap';\n\nimport {ListsSpecs, blType, liType, olType} from './ListsSpecs';\nimport {actions} from './actions';\nimport {joinPrevList, liftEmptyListItem, sinkOnlySelectedListItem, toList} from './commands';\nimport {ListAction} from './const';\nimport {ListsInputRulesExtension, type ListsInputRulesOptions} from './inputrules';\nimport {collapseListsPlugin} from './plugins/CollapseListsPlugin';\nimport {mergeListsPlugin} from './plugins/MergeListsPlugin';\n\nexport {ListNode, ListsAttr, blType, liType, olType} from './ListsSpecs';\n\nexport type ListsOptions = {\n ulKey?: string | null;\n olKey?: string | null;\n ulInputRules?: ListsInputRulesOptions['bulletListInputRule'];\n};\n\nexport const Lists: ExtensionAuto<ListsOptions> = (builder, opts) => {\n builder.use(ListsSpecs);\n\n builder.addKeymap(({schema}) => {\n const {ulKey, olKey} = opts ?? {};\n const bindings: Keymap = {};\n if (ulKey) bindings[ulKey] = withLogAction('bulletList', toList(blType(schema)));\n if (olKey) bindings[olKey] = withLogAction('orderedList', toList(olType(schema)));\n\n return {\n Tab: sinkOnlySelectedListItem(liType(schema)),\n 'Shift-Tab': liftListItem(liType(schema)),\n Backspace: liftEmptyListItem(liType(schema)),\n\n 'Mod-[': liftListItem(liType(schema)),\n 'Mod-]': sinkOnlySelectedListItem(liType(schema)),\n\n ...bindings,\n };\n }, builder.Priority.High);\n\n builder.addKeymap(\n ({schema}) => ({\n Enter: splitListItem(liType(schema)),\n Backspace: joinPrevList,\n }),\n builder.Priority.Low,\n );\n\n builder.use(ListsInputRulesExtension, {bulletListInputRule: opts?.ulInputRules});\n\n // Order matters: merge must run before collapse (see CollapseListsPlugin.ts)\n builder.addPlugin(mergeListsPlugin);\n builder.addPlugin(collapseListsPlugin);\n\n builder\n .addAction(ListAction.ToBulletList, actions.toBulletList)\n .addAction(ListAction.ToOrderedList, actions.toOrderedList)\n .addAction(ListAction.SinkListItem, actions.sinkListItem)\n .addAction(ListAction.LiftListItem, actions.liftListItem);\n};\n\ndeclare global {\n namespace WysiwygEditor {\n interface Actions {\n [ListAction.ToBulletList]: Action;\n [ListAction.ToOrderedList]: Action;\n [ListAction.SinkListItem]: Action;\n [ListAction.LiftListItem]: Action;\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { Plugin, type Transaction } from 'prosemirror-state';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Collapses redundant nested lists inside list items
|
|
4
|
+
*
|
|
5
|
+
* Converts structures where a list item starts with
|
|
6
|
+
* a nested list into a flat list structure
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: must be registered AFTER MergeListsPlugin.
|
|
9
|
+
* Collapsing may create adjacent lists that require merging
|
|
10
|
+
*/
|
|
3
11
|
export declare const collapseListsPlugin: () => Plugin<any>;
|
|
4
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Finds list items with redundant nesting, collapses them recursively,
|
|
14
|
+
* and applies replacements in reverse document order
|
|
15
|
+
*/
|
|
16
|
+
export declare function collapseAllNestedListItems(tr: Transaction): number | null;
|
|
@@ -1,76 +1,122 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.collapseListsPlugin = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.collapseAllNestedListItems = collapseAllNestedListItems;
|
|
5
5
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
6
6
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
7
|
// @ts-ignore // TODO: fix cjs build
|
|
8
8
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
9
|
-
const utils_1 = require("
|
|
10
|
-
const
|
|
9
|
+
const utils_1 = require("../utils.js");
|
|
10
|
+
const MAX_COLLAPSE_DEPTH = 100;
|
|
11
|
+
/**
|
|
12
|
+
* Collapses redundant nested lists inside list items
|
|
13
|
+
*
|
|
14
|
+
* Converts structures where a list item starts with
|
|
15
|
+
* a nested list into a flat list structure
|
|
16
|
+
*
|
|
17
|
+
* IMPORTANT: must be registered AFTER MergeListsPlugin.
|
|
18
|
+
* Collapsing may create adjacent lists that require merging
|
|
19
|
+
*/
|
|
11
20
|
const collapseListsPlugin = () => new prosemirror_state_1.Plugin({
|
|
12
21
|
appendTransaction(trs, oldState, newState) {
|
|
22
|
+
// early exit if document unchanged
|
|
13
23
|
const docChanged = trs.some((tr) => tr.docChanged);
|
|
14
|
-
if (!docChanged)
|
|
24
|
+
if (!docChanged) {
|
|
15
25
|
return null;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
}
|
|
27
|
+
// early exit if not inside a list
|
|
28
|
+
const hasParentList = (0, prosemirror_utils_1.hasParentNode)(utils_1.isListNode)(newState.selection) ||
|
|
29
|
+
(0, prosemirror_utils_1.hasParentNode)(utils_1.isListNode)(oldState.selection);
|
|
30
|
+
if (!hasParentList) {
|
|
19
31
|
return null;
|
|
32
|
+
}
|
|
20
33
|
const { tr } = newState;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
currentStepsCount = collapseEmptyListItems(tr, listNodes);
|
|
34
|
+
// collapse of redundant nested lists
|
|
35
|
+
const lastCollapsePos = collapseAllNestedListItems(tr);
|
|
36
|
+
// restore cursor position
|
|
37
|
+
if (lastCollapsePos !== null) {
|
|
38
|
+
const clampedPos = Math.min(lastCollapsePos, tr.doc.content.size);
|
|
39
|
+
tr.setSelection(prosemirror_state_1.Selection.near(tr.doc.resolve(clampedPos)));
|
|
28
40
|
}
|
|
29
41
|
return tr.docChanged ? tr : null;
|
|
30
42
|
},
|
|
31
43
|
});
|
|
32
44
|
exports.collapseListsPlugin = collapseListsPlugin;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Finds list items with redundant nesting, collapses them recursively,
|
|
47
|
+
* and applies replacements in reverse document order
|
|
48
|
+
*/
|
|
49
|
+
function collapseAllNestedListItems(tr) {
|
|
50
|
+
const replacements = [];
|
|
51
|
+
const schema = tr.doc.type.schema;
|
|
52
|
+
// skipUntil prevents re-processing children that were already collapsed
|
|
53
|
+
// by the recursive call in collapseListItemContent
|
|
54
|
+
let skipUntil = -1;
|
|
55
|
+
tr.doc.descendants((node, pos) => {
|
|
56
|
+
if (pos < skipUntil || node.isTextblock) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (!(0, utils_1.isListItemNode)(node)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const { firstChild } = node;
|
|
63
|
+
if (!firstChild || !(0, utils_1.isListNode)(firstChild)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const collapsedContent = collapseListItemContent(node, schema, 0);
|
|
67
|
+
if (collapsedContent === null) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
replacements.push({
|
|
71
|
+
from: pos,
|
|
72
|
+
to: pos + node.nodeSize,
|
|
73
|
+
content: collapsedContent,
|
|
62
74
|
});
|
|
75
|
+
skipUntil = pos + node.nodeSize;
|
|
76
|
+
return false;
|
|
63
77
|
});
|
|
64
|
-
|
|
78
|
+
if (replacements.length === 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
// apply from end to start so earlier positions stay valid
|
|
82
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
83
|
+
const { from, to, content } = replacements[i];
|
|
84
|
+
tr.replaceWith(from, to, content);
|
|
85
|
+
}
|
|
86
|
+
// map the original end of the last replacement to its post-edit position
|
|
87
|
+
const last = replacements[replacements.length - 1];
|
|
88
|
+
return tr.mapping.map(last.to);
|
|
65
89
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Recursively collapses a list item with redundant nesting
|
|
92
|
+
* into a Fragment of flat list items
|
|
93
|
+
*
|
|
94
|
+
* A redundantly nested list item has a list as its first child
|
|
95
|
+
* (instead of a paragraph)
|
|
96
|
+
*/
|
|
97
|
+
function collapseListItemContent(itemNode, schema, depth) {
|
|
98
|
+
const { firstChild } = itemNode;
|
|
99
|
+
if (!firstChild || !(0, utils_1.isListNode)(firstChild)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (depth >= MAX_COLLAPSE_DEPTH) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
// .slice(1) = all children except firstChild
|
|
106
|
+
const remaining = itemNode.content.content.slice(1);
|
|
107
|
+
let result = prosemirror_model_1.Fragment.empty;
|
|
108
|
+
firstChild.forEach((child) => {
|
|
109
|
+
if ((0, utils_1.isListItemNode)(child)) {
|
|
110
|
+
const collapsed = collapseListItemContent(child, schema, depth + 1);
|
|
111
|
+
result = result.append(collapsed ?? prosemirror_model_1.Fragment.from(child));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
result = result.append(prosemirror_model_1.Fragment.from(child));
|
|
71
115
|
}
|
|
72
|
-
|
|
116
|
+
});
|
|
117
|
+
if (remaining.length) {
|
|
118
|
+
result = result.append(prosemirror_model_1.Fragment.from((0, utils_1.liType)(schema).create(null, remaining)));
|
|
73
119
|
}
|
|
74
|
-
return
|
|
120
|
+
return result;
|
|
75
121
|
}
|
|
76
122
|
//# sourceMappingURL=CollapseListsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollapseListsPlugin.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Lists/plugins/CollapseListsPlugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CollapseListsPlugin.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Lists/plugins/CollapseListsPlugin.ts"],"names":[],"mappings":";;;AA4DA,gEAkDC;AA9GD,yDAAmE;AACnE,yDAAsE;AACtE,oCAAoC;AACpC,yDAAgD;AAEhD,uCAA4D;AAE5D,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;;;;;;;GAQG;AACI,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACpC,IAAI,0BAAM,CAAC;IACP,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACrC,mCAAmC;QACnC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,kCAAkC;QAClC,MAAM,aAAa,GACf,IAAA,iCAAa,EAAC,kBAAU,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC7C,IAAA,iCAAa,EAAC,kBAAU,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,EAAC,EAAE,EAAC,GAAG,QAAQ,CAAC;QAEtB,qCAAqC;QACrC,MAAM,eAAe,GAAG,0BAA0B,CAAC,EAAE,CAAC,CAAC;QAEvD,0BAA0B;QAC1B,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC,GAAG,CAAC,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,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACzB,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACpE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,4BAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,4BAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,4BAAQ,CAAC,IAAI,CAAC,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import {Fragment, type Node, type Schema} from 'prosemirror-model';\nimport {Plugin, Selection, type Transaction} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {hasParentNode} from 'prosemirror-utils';\n\nimport {isListItemNode, isListNode, liType} from '../utils';\n\nconst MAX_COLLAPSE_DEPTH = 100;\n\n/**\n * Collapses redundant nested lists inside list items\n *\n * Converts structures where a list item starts with\n * a nested list into a flat list structure\n *\n * IMPORTANT: must be registered AFTER MergeListsPlugin.\n * Collapsing may create adjacent lists that require merging\n */\nexport const collapseListsPlugin = () =>\n new Plugin({\n appendTransaction(trs, oldState, newState) {\n // early exit if document unchanged\n const docChanged = trs.some((tr) => tr.docChanged);\n if (!docChanged) {\n return null;\n }\n\n // early exit if not inside a list\n const hasParentList =\n hasParentNode(isListNode)(newState.selection) ||\n hasParentNode(isListNode)(oldState.selection);\n if (!hasParentList) {\n return null;\n }\n\n const {tr} = newState;\n\n // collapse of redundant nested lists\n const lastCollapsePos = collapseAllNestedListItems(tr);\n\n // restore cursor position\n if (lastCollapsePos !== null) {\n const clampedPos = Math.min(lastCollapsePos, tr.doc.content.size);\n tr.setSelection(Selection.near(tr.doc.resolve(clampedPos)));\n }\n\n return tr.docChanged ? tr : null;\n },\n });\n\ninterface Replacement {\n from: number;\n to: number;\n content: Fragment;\n}\n\n/**\n * Finds list items with redundant nesting, collapses them recursively,\n * and applies replacements in reverse document order\n */\nexport function collapseAllNestedListItems(tr: Transaction): number | null {\n const replacements: Replacement[] = [];\n const schema = tr.doc.type.schema;\n\n // skipUntil prevents re-processing children that were already collapsed\n // by the recursive call in collapseListItemContent\n let skipUntil = -1;\n\n tr.doc.descendants((node, pos) => {\n if (pos < skipUntil || node.isTextblock) {\n return false;\n }\n\n if (!isListItemNode(node)) {\n return true;\n }\n\n const {firstChild} = node;\n if (!firstChild || !isListNode(firstChild)) {\n return true;\n }\n\n const collapsedContent = collapseListItemContent(node, schema, 0);\n if (collapsedContent === null) {\n return true;\n }\n\n replacements.push({\n from: pos,\n to: pos + node.nodeSize,\n content: collapsedContent,\n });\n skipUntil = pos + node.nodeSize;\n\n return false;\n });\n\n if (replacements.length === 0) {\n return null;\n }\n\n // apply from end to start so earlier positions stay valid\n for (let i = replacements.length - 1; i >= 0; i--) {\n const {from, to, content} = replacements[i];\n tr.replaceWith(from, to, content);\n }\n\n // map the original end of the last replacement to its post-edit position\n const last = replacements[replacements.length - 1];\n return tr.mapping.map(last.to);\n}\n\n/**\n * Recursively collapses a list item with redundant nesting\n * into a Fragment of flat list items\n *\n * A redundantly nested list item has a list as its first child\n * (instead of a paragraph)\n */\nfunction collapseListItemContent(itemNode: Node, schema: Schema, depth: number): Fragment | null {\n const {firstChild} = itemNode;\n if (!firstChild || !isListNode(firstChild)) {\n return null;\n }\n if (depth >= MAX_COLLAPSE_DEPTH) {\n return null;\n }\n\n // .slice(1) = all children except firstChild\n const remaining = itemNode.content.content.slice(1);\n\n let result = Fragment.empty;\n firstChild.forEach((child) => {\n if (isListItemNode(child)) {\n const collapsed = collapseListItemContent(child, schema, depth + 1);\n result = result.append(collapsed ?? Fragment.from(child));\n } else {\n result = result.append(Fragment.from(child));\n }\n });\n\n if (remaining.length) {\n result = result.append(Fragment.from(liType(schema).create(null, remaining)));\n }\n\n return result;\n}\n"]}
|
|
@@ -2,7 +2,7 @@ export type { HeadingLevel } from "../../../markdown/Heading/const.js";
|
|
|
2
2
|
export { headingLevelAttr, headingNodeName } from "../../../markdown/Heading/HeadingSpecs/index.js";
|
|
3
3
|
export declare const YfmHeadingAttr: {
|
|
4
4
|
readonly Level: "level";
|
|
5
|
-
readonly Id: "id";
|
|
6
5
|
readonly DataLine: "data-line";
|
|
6
|
+
readonly Id: "id";
|
|
7
7
|
readonly Folding: "folded";
|
|
8
8
|
};
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "headingLevelAttr", { enumerable: true, get: func
|
|
|
7
7
|
Object.defineProperty(exports, "headingNodeName", { enumerable: true, get: function () { return HeadingSpecs_2.headingNodeName; } });
|
|
8
8
|
exports.YfmHeadingAttr = {
|
|
9
9
|
Level: HeadingSpecs_1.headingLevelAttr,
|
|
10
|
+
DataLine: HeadingSpecs_1.headingLineNumberAttr,
|
|
10
11
|
Id: 'id',
|
|
11
|
-
|
|
12
|
-
Folding: 'folded',
|
|
12
|
+
Folding: 'folded', // TODO: move to FoldingHeadingExtension
|
|
13
13
|
};
|
|
14
14
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/const.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/const.ts"],"names":[],"mappings":";;;AAAA,kFAA+F;AAG/F,gFAAyF;AAAjF,gHAAA,gBAAgB,OAAA;AAAE,+GAAA,eAAe,OAAA;AAE5B,QAAA,cAAc,GAAG;IAC1B,KAAK,EAAE,+BAAgB;IACvB,QAAQ,EAAE,oCAAqB;IAC/B,EAAE,EAAE,IAAI;IACR,OAAO,EAAE,QAAQ,EAAE,wCAAwC;CACrD,CAAC","sourcesContent":["import {headingLevelAttr, headingLineNumberAttr} from '../../../markdown/Heading/HeadingSpecs';\nexport type {HeadingLevel} from '../../../markdown/Heading/const';\n\nexport {headingLevelAttr, headingNodeName} from '../../../markdown/Heading/HeadingSpecs';\n\nexport const YfmHeadingAttr = {\n Level: headingLevelAttr,\n DataLine: headingLineNumberAttr,\n Id: 'id',\n Folding: 'folded', // TODO: move to FoldingHeadingExtension\n} as const;\n"]}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAuto } from "../../../../core/index.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type HeadingSpecsOptions } from "../../../markdown/Heading/HeadingSpecs/index.js";
|
|
3
3
|
export { YfmHeadingAttr } from "./const.js";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
* @deprecated: use placeholder option in BehaviorPreset instead.
|
|
7
|
-
*/
|
|
8
|
-
headingPlaceholder?: NonNullable<NodeSpec['placeholder']>['content'];
|
|
9
|
-
};
|
|
4
|
+
export { renderYfmHeadingAttributes, renderYfmHeadingMarkup } from "./utils.js";
|
|
5
|
+
export type YfmHeadingSpecsOptions = HeadingSpecsOptions & {};
|
|
10
6
|
/** YfmHeading extension needs markdown-it-attrs plugin */
|
|
11
7
|
export declare const YfmHeadingSpecs: ExtensionAuto<YfmHeadingSpecsOptions>;
|
|
@@ -1,108 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YfmHeadingSpecs = exports.YfmHeadingAttr = void 0;
|
|
3
|
+
exports.YfmHeadingSpecs = exports.renderYfmHeadingMarkup = exports.renderYfmHeadingAttributes = exports.YfmHeadingAttr = void 0;
|
|
4
|
+
const HeadingSpecs_1 = require("../../../markdown/Heading/HeadingSpecs/index.js");
|
|
4
5
|
const const_1 = require("./const.js");
|
|
5
6
|
const heading_ids_1 = require("./markdown/heading-ids.js");
|
|
6
7
|
const utils_1 = require("./utils.js");
|
|
7
|
-
const DEFAULT_PLACEHOLDER = (node) => 'Heading ' + node.attrs[const_1.YfmHeadingAttr.Level];
|
|
8
8
|
var const_2 = require("./const.js");
|
|
9
9
|
Object.defineProperty(exports, "YfmHeadingAttr", { enumerable: true, get: function () { return const_2.YfmHeadingAttr; } });
|
|
10
|
+
var utils_2 = require("./utils.js");
|
|
11
|
+
Object.defineProperty(exports, "renderYfmHeadingAttributes", { enumerable: true, get: function () { return utils_2.renderYfmHeadingAttributes; } });
|
|
12
|
+
Object.defineProperty(exports, "renderYfmHeadingMarkup", { enumerable: true, get: function () { return utils_2.renderYfmHeadingMarkup; } });
|
|
10
13
|
/** YfmHeading extension needs markdown-it-attrs plugin */
|
|
11
|
-
const YfmHeadingSpecs = (builder,
|
|
14
|
+
const YfmHeadingSpecs = (builder, _opts) => {
|
|
12
15
|
builder.configureMd((md) => md.use(heading_ids_1.headingIdsPlugin));
|
|
13
|
-
builder.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
builder.overrideNodeSpec(const_1.headingNodeName, (prev) => ({
|
|
17
|
+
...prev,
|
|
18
|
+
attrs: {
|
|
19
|
+
...prev.attrs,
|
|
20
|
+
[const_1.YfmHeadingAttr.Id]: { default: '' },
|
|
21
|
+
[const_1.YfmHeadingAttr.Folding]: { default: null },
|
|
22
|
+
},
|
|
23
|
+
selectable: true,
|
|
24
|
+
parseDOM: [
|
|
25
|
+
{ tag: 'h1', getAttrs: (0, utils_1.getNodeAttrs)(1), priority: 100, consuming: true },
|
|
26
|
+
{ tag: 'h2', getAttrs: (0, utils_1.getNodeAttrs)(2), priority: 100, consuming: true },
|
|
27
|
+
{ tag: 'h3', getAttrs: (0, utils_1.getNodeAttrs)(3), priority: 100, consuming: true },
|
|
28
|
+
{ tag: 'h4', getAttrs: (0, utils_1.getNodeAttrs)(4), priority: 100, consuming: true },
|
|
29
|
+
{ tag: 'h5', getAttrs: (0, utils_1.getNodeAttrs)(5), priority: 100, consuming: true },
|
|
30
|
+
{ tag: 'h6', getAttrs: (0, utils_1.getNodeAttrs)(6), priority: 100, consuming: true },
|
|
31
|
+
{
|
|
32
|
+
// ignore anchor link inside headings
|
|
33
|
+
tag: 'a.yfm-anchor',
|
|
34
|
+
context: `${const_1.headingNodeName}/`,
|
|
35
|
+
skip: true,
|
|
36
|
+
ignore: true,
|
|
37
|
+
priority: 1000,
|
|
20
38
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{ tag: 'h3', getAttrs: (0, utils_1.getNodeAttrs)(3), priority: 100, consuming: true },
|
|
29
|
-
{ tag: 'h4', getAttrs: (0, utils_1.getNodeAttrs)(4), priority: 100, consuming: true },
|
|
30
|
-
{ tag: 'h5', getAttrs: (0, utils_1.getNodeAttrs)(5), priority: 100, consuming: true },
|
|
31
|
-
{ tag: 'h6', getAttrs: (0, utils_1.getNodeAttrs)(6), priority: 100, consuming: true },
|
|
39
|
+
],
|
|
40
|
+
toDOM(node) {
|
|
41
|
+
const id = node.attrs[const_1.YfmHeadingAttr.Id];
|
|
42
|
+
const lineNumber = node.attrs[const_1.YfmHeadingAttr.DataLine];
|
|
43
|
+
const folding = node.attrs[const_1.YfmHeadingAttr.Folding];
|
|
44
|
+
return [
|
|
45
|
+
'h' + node.attrs[const_1.YfmHeadingAttr.Level],
|
|
32
46
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
skip: true,
|
|
37
|
-
ignore: true,
|
|
38
|
-
priority: 1000,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
toDOM(node) {
|
|
42
|
-
const id = node.attrs[const_1.YfmHeadingAttr.Id];
|
|
43
|
-
const lineNumber = node.attrs[const_1.YfmHeadingAttr.DataLine];
|
|
44
|
-
const folding = node.attrs[const_1.YfmHeadingAttr.Folding];
|
|
45
|
-
return [
|
|
46
|
-
'h' + node.attrs[const_1.YfmHeadingAttr.Level],
|
|
47
|
-
{
|
|
48
|
-
id: id || null,
|
|
49
|
-
[const_1.YfmHeadingAttr.DataLine]: lineNumber,
|
|
50
|
-
[`data-${const_1.YfmHeadingAttr.Folding}`]: folding,
|
|
51
|
-
},
|
|
52
|
-
0,
|
|
53
|
-
// [
|
|
54
|
-
// 'a',
|
|
55
|
-
// {
|
|
56
|
-
// href: `#${node.attrs[YfmHeadingAttr.Id]}`,
|
|
57
|
-
// class: 'yfm-anchor',
|
|
58
|
-
// 'aria-hidden': 'true',
|
|
59
|
-
// contenteditable: 'false',
|
|
60
|
-
// },
|
|
61
|
-
// ],
|
|
62
|
-
// ['span', 0],
|
|
63
|
-
];
|
|
64
|
-
},
|
|
65
|
-
placeholder: {
|
|
66
|
-
content: builder.context.get('placeholder')?.heading ??
|
|
67
|
-
opts.headingPlaceholder ??
|
|
68
|
-
DEFAULT_PLACEHOLDER,
|
|
69
|
-
alwaysVisible: true,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
fromMd: {
|
|
73
|
-
tokenSpec: {
|
|
74
|
-
name: const_1.headingNodeName,
|
|
75
|
-
type: 'block',
|
|
76
|
-
getAttrs: (token) => {
|
|
77
|
-
if (token.type.endsWith('_close'))
|
|
78
|
-
return {};
|
|
79
|
-
const attrs = Object.fromEntries(token.attrs || []);
|
|
80
|
-
// if (!attrs[YfmHeadingAttr.Id]) {
|
|
81
|
-
// // calculate id if it was not specified
|
|
82
|
-
// // tokens[index + 1] is child inline token
|
|
83
|
-
// attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
|
|
84
|
-
// }
|
|
85
|
-
// attrs have id only if it explicitly specified manually
|
|
86
|
-
return {
|
|
87
|
-
[const_1.YfmHeadingAttr.Level]: Number(token.tag.slice(1)),
|
|
88
|
-
[const_1.YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,
|
|
89
|
-
...attrs,
|
|
90
|
-
};
|
|
47
|
+
id: id || null,
|
|
48
|
+
[const_1.YfmHeadingAttr.DataLine]: lineNumber,
|
|
49
|
+
[`data-${const_1.YfmHeadingAttr.Folding}`]: folding,
|
|
91
50
|
},
|
|
92
|
-
|
|
51
|
+
0,
|
|
52
|
+
// [
|
|
53
|
+
// 'a',
|
|
54
|
+
// {
|
|
55
|
+
// href: `#${node.attrs[YfmHeadingAttr.Id]}`,
|
|
56
|
+
// class: 'yfm-anchor',
|
|
57
|
+
// 'aria-hidden': 'true',
|
|
58
|
+
// contenteditable: 'false',
|
|
59
|
+
// },
|
|
60
|
+
// ],
|
|
61
|
+
// ['span', 0],
|
|
62
|
+
];
|
|
93
63
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
64
|
+
}));
|
|
65
|
+
builder.overrideMarkdownTokenParserSpec(const_1.headingNodeName, (prev) => ({
|
|
66
|
+
...prev,
|
|
67
|
+
getAttrs: (token) => {
|
|
68
|
+
if (token.type.endsWith('_close'))
|
|
69
|
+
return {};
|
|
70
|
+
const attrs = Object.fromEntries(token.attrs || []);
|
|
71
|
+
// if (!attrs[YfmHeadingAttr.Id]) {
|
|
72
|
+
// // calculate id if it was not specified
|
|
73
|
+
// // tokens[index + 1] is child inline token
|
|
74
|
+
// attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
|
|
75
|
+
// }
|
|
76
|
+
// attrs have id only if it explicitly specified manually
|
|
77
|
+
return {
|
|
78
|
+
[const_1.YfmHeadingAttr.Level]: Number(token.tag.slice(1)),
|
|
79
|
+
[const_1.YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,
|
|
80
|
+
...attrs,
|
|
81
|
+
};
|
|
104
82
|
},
|
|
105
83
|
}));
|
|
84
|
+
builder.overrideNodeSerializerSpec(const_1.headingNodeName, () => (0, HeadingSpecs_1.headingToMarkdown)({
|
|
85
|
+
renderMarkup: utils_1.renderYfmHeadingMarkup,
|
|
86
|
+
renderAttributes: utils_1.renderYfmHeadingAttributes,
|
|
87
|
+
}));
|
|
106
88
|
};
|
|
107
89
|
exports.YfmHeadingSpecs = YfmHeadingSpecs;
|
|
108
90
|
//# sourceMappingURL=index.js.map
|