@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.
Files changed (129) hide show
  1. package/build/cjs/core/ExtensionBuilder.d.ts +21 -0
  2. package/build/cjs/core/ExtensionBuilder.js +306 -4
  3. package/build/cjs/core/ExtensionBuilder.js.map +1 -1
  4. package/build/cjs/core/markdown/MarkdownSerializer.d.ts +4 -1
  5. package/build/cjs/core/markdown/MarkdownSerializer.js +86 -23
  6. package/build/cjs/core/markdown/MarkdownSerializer.js.map +1 -1
  7. package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.d.ts +13 -0
  8. package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.js +42 -0
  9. package/build/cjs/extensions/behavior/SelectionContext/TextSelectionTooltip.js.map +1 -0
  10. package/build/cjs/extensions/behavior/SelectionContext/index.js +10 -7
  11. package/build/cjs/extensions/behavior/SelectionContext/index.js.map +1 -1
  12. package/build/cjs/extensions/behavior/SelectionContext/tooltip.d.ts +11 -15
  13. package/build/cjs/extensions/behavior/SelectionContext/tooltip.js +24 -56
  14. package/build/cjs/extensions/behavior/SelectionContext/tooltip.js.map +1 -1
  15. package/build/cjs/extensions/behavior/SelectionContext/types.d.ts +10 -0
  16. package/build/cjs/extensions/behavior/SelectionContext/types.js +3 -0
  17. package/build/cjs/extensions/behavior/SelectionContext/types.js.map +1 -0
  18. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js +24 -34
  19. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js.map +1 -1
  20. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.d.ts +4 -0
  21. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.js +9 -0
  22. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/const.js.map +1 -0
  23. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.d.ts +3 -5
  24. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.js +22 -25
  25. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/index.js.map +1 -1
  26. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.d.ts +7 -0
  27. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.js +15 -0
  28. package/build/cjs/extensions/markdown/Heading/HeadingSpecs/utils.js.map +1 -0
  29. package/build/cjs/extensions/markdown/Heading/actions.d.ts +2 -2
  30. package/build/cjs/extensions/markdown/Heading/actions.js +3 -4
  31. package/build/cjs/extensions/markdown/Heading/actions.js.map +1 -1
  32. package/build/cjs/extensions/markdown/Heading/commands.d.ts +3 -1
  33. package/build/cjs/extensions/markdown/Heading/commands.js +16 -1
  34. package/build/cjs/extensions/markdown/Heading/commands.js.map +1 -1
  35. package/build/cjs/extensions/markdown/Heading/index.js +7 -9
  36. package/build/cjs/extensions/markdown/Heading/index.js.map +1 -1
  37. package/build/cjs/extensions/markdown/Lists/index.js +1 -0
  38. package/build/cjs/extensions/markdown/Lists/index.js.map +1 -1
  39. package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +14 -2
  40. package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +97 -51
  41. package/build/cjs/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -1
  42. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
  43. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +2 -2
  44. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js.map +1 -1
  45. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +3 -7
  46. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +72 -90
  47. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
  48. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.d.ts +3 -0
  49. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +14 -1
  50. package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js.map +1 -1
  51. package/build/cjs/extensions/yfm/YfmHeading/actions.js +2 -10
  52. package/build/cjs/extensions/yfm/YfmHeading/actions.js.map +1 -1
  53. package/build/cjs/extensions/yfm/YfmHeading/commands.d.ts +1 -4
  54. package/build/cjs/extensions/yfm/YfmHeading/commands.js +3 -21
  55. package/build/cjs/extensions/yfm/YfmHeading/commands.js.map +1 -1
  56. package/build/cjs/extensions/yfm/YfmHeading/index.d.ts +3 -22
  57. package/build/cjs/extensions/yfm/YfmHeading/index.js +2 -33
  58. package/build/cjs/extensions/yfm/YfmHeading/index.js.map +1 -1
  59. package/build/cjs/presets/yfm-specs.js +5 -1
  60. package/build/cjs/presets/yfm-specs.js.map +1 -1
  61. package/build/cjs/presets/yfm.js +5 -1
  62. package/build/cjs/presets/yfm.js.map +1 -1
  63. package/build/cjs/version.js +1 -1
  64. package/build/cjs/version.js.map +1 -1
  65. package/build/esm/core/ExtensionBuilder.d.ts +21 -0
  66. package/build/esm/core/ExtensionBuilder.js +306 -4
  67. package/build/esm/core/ExtensionBuilder.js.map +1 -1
  68. package/build/esm/core/markdown/MarkdownSerializer.d.ts +4 -1
  69. package/build/esm/core/markdown/MarkdownSerializer.js +86 -23
  70. package/build/esm/core/markdown/MarkdownSerializer.js.map +1 -1
  71. package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.d.ts +13 -0
  72. package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.js +38 -0
  73. package/build/esm/extensions/behavior/SelectionContext/TextSelectionTooltip.js.map +1 -0
  74. package/build/esm/extensions/behavior/SelectionContext/index.js +10 -7
  75. package/build/esm/extensions/behavior/SelectionContext/index.js.map +1 -1
  76. package/build/esm/extensions/behavior/SelectionContext/tooltip.d.ts +11 -15
  77. package/build/esm/extensions/behavior/SelectionContext/tooltip.js +24 -56
  78. package/build/esm/extensions/behavior/SelectionContext/tooltip.js.map +1 -1
  79. package/build/esm/extensions/behavior/SelectionContext/types.d.ts +10 -0
  80. package/build/esm/extensions/behavior/SelectionContext/types.js +2 -0
  81. package/build/esm/extensions/behavior/SelectionContext/types.js.map +1 -0
  82. package/build/esm/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js +24 -34
  83. package/build/esm/extensions/markdown/CodeBlock/CodeBlockSpecs/index.js.map +1 -1
  84. package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.d.ts +4 -0
  85. package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.js +6 -0
  86. package/build/esm/extensions/markdown/Heading/HeadingSpecs/const.js.map +1 -0
  87. package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.d.ts +3 -5
  88. package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.js +5 -10
  89. package/build/esm/extensions/markdown/Heading/HeadingSpecs/index.js.map +1 -1
  90. package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.d.ts +7 -0
  91. package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.js +12 -0
  92. package/build/esm/extensions/markdown/Heading/HeadingSpecs/utils.js.map +1 -0
  93. package/build/esm/extensions/markdown/Heading/actions.d.ts +2 -2
  94. package/build/esm/extensions/markdown/Heading/actions.js +3 -4
  95. package/build/esm/extensions/markdown/Heading/actions.js.map +1 -1
  96. package/build/esm/extensions/markdown/Heading/commands.d.ts +3 -1
  97. package/build/esm/extensions/markdown/Heading/commands.js +15 -1
  98. package/build/esm/extensions/markdown/Heading/commands.js.map +1 -1
  99. package/build/esm/extensions/markdown/Heading/index.js +9 -11
  100. package/build/esm/extensions/markdown/Heading/index.js.map +1 -1
  101. package/build/esm/extensions/markdown/Lists/index.js +1 -0
  102. package/build/esm/extensions/markdown/Lists/index.js.map +1 -1
  103. package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.d.ts +14 -2
  104. package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js +95 -49
  105. package/build/esm/extensions/markdown/Lists/plugins/CollapseListsPlugin.js.map +1 -1
  106. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
  107. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +3 -3
  108. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js.map +1 -1
  109. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +3 -7
  110. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +70 -90
  111. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
  112. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.d.ts +3 -0
  113. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +11 -0
  114. package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js.map +1 -1
  115. package/build/esm/extensions/yfm/YfmHeading/actions.js +2 -10
  116. package/build/esm/extensions/yfm/YfmHeading/actions.js.map +1 -1
  117. package/build/esm/extensions/yfm/YfmHeading/commands.d.ts +1 -4
  118. package/build/esm/extensions/yfm/YfmHeading/commands.js +3 -21
  119. package/build/esm/extensions/yfm/YfmHeading/commands.js.map +1 -1
  120. package/build/esm/extensions/yfm/YfmHeading/index.d.ts +3 -22
  121. package/build/esm/extensions/yfm/YfmHeading/index.js +0 -31
  122. package/build/esm/extensions/yfm/YfmHeading/index.js.map +1 -1
  123. package/build/esm/presets/yfm-specs.js +5 -1
  124. package/build/esm/presets/yfm-specs.js.map +1 -1
  125. package/build/esm/presets/yfm.js +5 -1
  126. package/build/esm/presets/yfm.js.map +1 -1
  127. package/build/esm/version.js +1 -1
  128. package/build/esm/version.js.map +1 -1
  129. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["extensions/markdown/Lists/index.ts"],"names":[],"mappings":"AA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AAM,CAAC,CAAC;YACzC,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAE5C,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjD,GAAG,QAAQ;SACd,CAAC;IACN,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE1B,OAAO,CAAC,SAAS,CACb,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC;QACX,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,SAAS,EAAE,YAAY;KAC1B,CAAC,EACF,OAAO,CAAC,QAAQ,CAAC,GAAG,CACvB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAC,mBAAmB,EAAE,IAAI,EAAE,YAAY,EAAC,CAAC,CAAC;IAEjF,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAEvC,OAAO;SACF,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;SAC1D,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["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 builder.addPlugin(mergeListsPlugin);\n\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
+ {"version":3,"file":"index.js","sourceRoot":"../../../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C;YAC7C,WAAW,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzC,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAE5C,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjD,GAAG,QAAQ;SACd,CAAC;IACN,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE1B,OAAO,CAAC,SAAS,CACb,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC;QACX,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,SAAS,EAAE,YAAY;KAC1B,CAAC,EACF,OAAO,CAAC,QAAQ,CAAC,GAAG,CACvB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAC,mBAAmB,EAAE,IAAI,EAAE,YAAY,EAAC,CAAC,CAAC;IAEjF,6EAA6E;IAC7E,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAEvC,OAAO;SACF,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;SAC1D,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;SACxD,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["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
- import { findChildren } from 'prosemirror-utils';
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
- export declare function collapseEmptyListItems(tr: Transaction, nodes: ReturnType<typeof findChildren>): number;
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,71 +1,117 @@
1
1
  import { Fragment } from 'prosemirror-model';
2
- import { Plugin, TextSelection } from 'prosemirror-state';
2
+ import { Plugin, Selection } from 'prosemirror-state';
3
3
  // @ts-ignore // TODO: fix cjs build
4
- import { findChildren, hasParentNode } from 'prosemirror-utils';
5
- import { getChildrenOfNode } from "../../../../utils/index.js";
4
+ import { hasParentNode } from 'prosemirror-utils';
6
5
  import { isListItemNode, isListNode, liType } from "../utils.js";
6
+ const MAX_COLLAPSE_DEPTH = 100;
7
+ /**
8
+ * Collapses redundant nested lists inside list items
9
+ *
10
+ * Converts structures where a list item starts with
11
+ * a nested list into a flat list structure
12
+ *
13
+ * IMPORTANT: must be registered AFTER MergeListsPlugin.
14
+ * Collapsing may create adjacent lists that require merging
15
+ */
7
16
  export const collapseListsPlugin = () => new Plugin({
8
17
  appendTransaction(trs, oldState, newState) {
18
+ // early exit if document unchanged
9
19
  const docChanged = trs.some((tr) => tr.docChanged);
10
- if (!docChanged)
20
+ if (!docChanged) {
11
21
  return null;
22
+ }
23
+ // early exit if not inside a list
12
24
  const hasParentList = hasParentNode(isListNode)(newState.selection) ||
13
25
  hasParentNode(isListNode)(oldState.selection);
14
- if (!hasParentList)
26
+ if (!hasParentList) {
15
27
  return null;
28
+ }
16
29
  const { tr } = newState;
17
- let prevStepsCount = -1;
18
- let currentStepsCount = 0;
19
- // execute until there are no nested lists.
20
- while (prevStepsCount !== currentStepsCount) {
21
- const listNodes = findChildren(tr.doc, isListNode, true);
22
- prevStepsCount = currentStepsCount;
23
- currentStepsCount = collapseEmptyListItems(tr, listNodes);
30
+ // collapse of redundant nested lists
31
+ const lastCollapsePos = collapseAllNestedListItems(tr);
32
+ // restore cursor position
33
+ if (lastCollapsePos !== null) {
34
+ const clampedPos = Math.min(lastCollapsePos, tr.doc.content.size);
35
+ tr.setSelection(Selection.near(tr.doc.resolve(clampedPos)));
24
36
  }
25
37
  return tr.docChanged ? tr : null;
26
38
  },
27
39
  });
28
- export function collapseEmptyListItems(tr, nodes) {
29
- const stepsCountBefore = tr.steps.length;
30
- // TODO: fix cjs build
31
- nodes.reverse().forEach((list) => {
32
- const listNode = list.node;
33
- const listPos = list.pos;
34
- const childrenOfList = getChildrenOfNode(listNode).reverse();
35
- childrenOfList.forEach(({ node: itemNode, offset }) => {
36
- if (isListItemNode(itemNode)) {
37
- const { firstChild } = itemNode;
38
- const listItemNodePos = listPos + 1 + offset;
39
- // if the first child of a list element is a list,
40
- // then collapse is required
41
- if (firstChild && isListNode(firstChild)) {
42
- const nestedList = firstChild.content;
43
- // nodes at the same level as the list
44
- const remainingNodes = itemNode.content.content.slice(1);
45
- const listItems = remainingNodes.length
46
- ? nestedList.append(Fragment.from(liType(tr.doc.type.schema).create(null, remainingNodes)))
47
- : nestedList;
48
- const mappedStart = tr.mapping.map(listItemNodePos);
49
- const mappedEnd = tr.mapping.map(listItemNodePos + itemNode.nodeSize);
50
- tr.replaceWith(mappedStart, mappedEnd, listItems);
51
- const closestTextNodePos = findClosestTextNodePos(tr.doc, mappedStart + nestedList.size);
52
- if (closestTextNodePos) {
53
- tr.setSelection(TextSelection.create(tr.doc, closestTextNodePos));
54
- }
55
- }
56
- }
40
+ /**
41
+ * Finds list items with redundant nesting, collapses them recursively,
42
+ * and applies replacements in reverse document order
43
+ */
44
+ export function collapseAllNestedListItems(tr) {
45
+ const replacements = [];
46
+ const schema = tr.doc.type.schema;
47
+ // skipUntil prevents re-processing children that were already collapsed
48
+ // by the recursive call in collapseListItemContent
49
+ let skipUntil = -1;
50
+ tr.doc.descendants((node, pos) => {
51
+ if (pos < skipUntil || node.isTextblock) {
52
+ return false;
53
+ }
54
+ if (!isListItemNode(node)) {
55
+ return true;
56
+ }
57
+ const { firstChild } = node;
58
+ if (!firstChild || !isListNode(firstChild)) {
59
+ return true;
60
+ }
61
+ const collapsedContent = collapseListItemContent(node, schema, 0);
62
+ if (collapsedContent === null) {
63
+ return true;
64
+ }
65
+ replacements.push({
66
+ from: pos,
67
+ to: pos + node.nodeSize,
68
+ content: collapsedContent,
57
69
  });
70
+ skipUntil = pos + node.nodeSize;
71
+ return false;
58
72
  });
59
- return tr.steps.length - stepsCountBefore;
73
+ if (replacements.length === 0) {
74
+ return null;
75
+ }
76
+ // apply from end to start so earlier positions stay valid
77
+ for (let i = replacements.length - 1; i >= 0; i--) {
78
+ const { from, to, content } = replacements[i];
79
+ tr.replaceWith(from, to, content);
80
+ }
81
+ // map the original end of the last replacement to its post-edit position
82
+ const last = replacements[replacements.length - 1];
83
+ return tr.mapping.map(last.to);
60
84
  }
61
- function findClosestTextNodePos(doc, pos) {
62
- while (pos < doc.content.size) {
63
- const node = doc.nodeAt(pos);
64
- if (node && node.isText) {
65
- return pos;
85
+ /**
86
+ * Recursively collapses a list item with redundant nesting
87
+ * into a Fragment of flat list items
88
+ *
89
+ * A redundantly nested list item has a list as its first child
90
+ * (instead of a paragraph)
91
+ */
92
+ function collapseListItemContent(itemNode, schema, depth) {
93
+ const { firstChild } = itemNode;
94
+ if (!firstChild || !isListNode(firstChild)) {
95
+ return null;
96
+ }
97
+ if (depth >= MAX_COLLAPSE_DEPTH) {
98
+ return null;
99
+ }
100
+ // .slice(1) = all children except firstChild
101
+ const remaining = itemNode.content.content.slice(1);
102
+ let result = Fragment.empty;
103
+ firstChild.forEach((child) => {
104
+ if (isListItemNode(child)) {
105
+ const collapsed = collapseListItemContent(child, schema, depth + 1);
106
+ result = result.append(collapsed ?? Fragment.from(child));
107
+ }
108
+ else {
109
+ result = result.append(Fragment.from(child));
66
110
  }
67
- pos++;
111
+ });
112
+ if (remaining.length) {
113
+ result = result.append(Fragment.from(liType(schema).create(null, remaining)));
68
114
  }
69
- return null;
115
+ return result;
70
116
  }
71
117
  //# sourceMappingURL=CollapseListsPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CollapseListsPlugin.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Lists/plugins/CollapseListsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAY,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAC;AAC1E,oCAAoC;AACpC,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAC,iBAAiB,EAAC,mCAA0B;AACpD,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,MAAM,EAAC,oBAAiB;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACpC,IAAI,MAAM,CAAC;IACP,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACrC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC;QAE7B,MAAM,aAAa,GACf,aAAa,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC7C,aAAa,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAClD,IAA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QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,GAAG,CAAC;QACf,CAAC;QACD,GAAG,EAAE,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {Fragment, type Node} from 'prosemirror-model';\nimport {Plugin, TextSelection, type Transaction} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildren, hasParentNode} from 'prosemirror-utils';\n\nimport {getChildrenOfNode} from '../../../../utils';\nimport {isListItemNode, isListNode, liType} from '../utils';\n\nexport const collapseListsPlugin = () =>\n new Plugin({\n appendTransaction(trs, oldState, newState) {\n const docChanged = trs.some((tr) => tr.docChanged);\n if (!docChanged) return null;\n\n const hasParentList =\n hasParentNode(isListNode)(newState.selection) ||\n hasParentNode(isListNode)(oldState.selection);\n if (!hasParentList) return null;\n\n const {tr} = newState;\n let prevStepsCount = -1;\n let currentStepsCount = 0;\n\n // execute until there are no nested lists.\n while (prevStepsCount !== currentStepsCount) {\n const listNodes = findChildren(tr.doc, isListNode, true);\n prevStepsCount = currentStepsCount;\n currentStepsCount = collapseEmptyListItems(tr, listNodes);\n }\n\n return tr.docChanged ? tr : null;\n },\n });\n\nexport function collapseEmptyListItems(\n tr: Transaction,\n nodes: ReturnType<typeof findChildren>,\n): number {\n const stepsCountBefore = tr.steps.length;\n // TODO: fix cjs build\n nodes.reverse().forEach((list: {node: Node; pos: number}) => {\n const listNode = list.node;\n const listPos = list.pos;\n const childrenOfList = getChildrenOfNode(listNode).reverse();\n\n childrenOfList.forEach(({node: itemNode, offset}) => {\n if (isListItemNode(itemNode)) {\n const {firstChild} = itemNode;\n const listItemNodePos = listPos + 1 + offset;\n\n // if the first child of a list element is a list,\n // then collapse is required\n if (firstChild && isListNode(firstChild)) {\n const nestedList = firstChild.content;\n\n // nodes at the same level as the list\n const remainingNodes = itemNode.content.content.slice(1);\n\n const listItems = remainingNodes.length\n ? nestedList.append(\n Fragment.from(\n liType(tr.doc.type.schema).create(null, remainingNodes),\n ),\n )\n : nestedList;\n\n const mappedStart = tr.mapping.map(listItemNodePos);\n const mappedEnd = tr.mapping.map(listItemNodePos + itemNode.nodeSize);\n\n tr.replaceWith(mappedStart, mappedEnd, listItems);\n\n const closestTextNodePos = findClosestTextNodePos(\n tr.doc,\n mappedStart + nestedList.size,\n );\n if (closestTextNodePos) {\n tr.setSelection(TextSelection.create(tr.doc, closestTextNodePos));\n }\n }\n }\n });\n });\n\n return tr.steps.length - stepsCountBefore;\n}\n\nfunction findClosestTextNodePos(doc: Node, pos: number): number | null {\n while (pos < doc.content.size) {\n const node = doc.nodeAt(pos);\n if (node && node.isText) {\n return pos;\n }\n pos++;\n }\n return null;\n}\n"]}
1
+ {"version":3,"file":"CollapseListsPlugin.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Lists/plugins/CollapseListsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAyB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AACtE,oCAAoC;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,MAAM,EAAC,oBAAiB;AAE5D,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACpC,IAAI,MAAM,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,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// @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
  };
@@ -1,9 +1,9 @@
1
- import { headingLevelAttr } from "../../../markdown/Heading/HeadingSpecs/index.js";
1
+ import { headingLevelAttr, headingLineNumberAttr } from "../../../markdown/Heading/HeadingSpecs/index.js";
2
2
  export { headingLevelAttr, headingNodeName } from "../../../markdown/Heading/HeadingSpecs/index.js";
3
3
  export const YfmHeadingAttr = {
4
4
  Level: headingLevelAttr,
5
+ DataLine: headingLineNumberAttr,
5
6
  Id: 'id',
6
- DataLine: 'data-line',
7
- Folding: 'folded',
7
+ Folding: 'folded', // TODO: move to FoldingHeadingExtension
8
8
  };
9
9
  //# sourceMappingURL=const.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"const.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,wDAA+C;AAGxE,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,wDAA+C;AAEzF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,KAAK,EAAE,gBAAgB;IACvB,EAAE,EAAE,IAAI;IACR,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,QAAQ;CACX,CAAC","sourcesContent":["import {headingLevelAttr} 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 Id: 'id',\n DataLine: 'data-line',\n Folding: 'folded',\n} as const;\n"]}
1
+ {"version":3,"file":"const.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,qBAAqB,EAAC,wDAA+C;AAG/F,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,wDAA+C;AAEzF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,qBAAqB;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 { NodeSpec } from "../../../../pm/model.js";
2
+ import { type HeadingSpecsOptions } from "../../../markdown/Heading/HeadingSpecs/index.js";
3
3
  export { YfmHeadingAttr } from "./const.js";
4
- export type YfmHeadingSpecsOptions = {
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,103 +1,83 @@
1
+ import { headingToMarkdown, } from "../../../markdown/Heading/HeadingSpecs/index.js";
1
2
  import { YfmHeadingAttr, headingNodeName } from "./const.js";
2
3
  import { headingIdsPlugin } from "./markdown/heading-ids.js";
3
- import { getNodeAttrs } from "./utils.js";
4
- const DEFAULT_PLACEHOLDER = (node) => 'Heading ' + node.attrs[YfmHeadingAttr.Level];
4
+ import { getNodeAttrs, renderYfmHeadingAttributes, renderYfmHeadingMarkup } from "./utils.js";
5
5
  export { YfmHeadingAttr } from "./const.js";
6
+ export { renderYfmHeadingAttributes, renderYfmHeadingMarkup } from "./utils.js";
6
7
  /** YfmHeading extension needs markdown-it-attrs plugin */
7
- export const YfmHeadingSpecs = (builder, opts) => {
8
+ export const YfmHeadingSpecs = (builder, _opts) => {
8
9
  builder.configureMd((md) => md.use(headingIdsPlugin));
9
- builder.addNode(headingNodeName, () => ({
10
- spec: {
11
- attrs: {
12
- [YfmHeadingAttr.Id]: { default: '' },
13
- [YfmHeadingAttr.Level]: { default: 1 },
14
- [YfmHeadingAttr.DataLine]: { default: null },
15
- [YfmHeadingAttr.Folding]: { default: null },
10
+ builder.overrideNodeSpec(headingNodeName, (prev) => ({
11
+ ...prev,
12
+ attrs: {
13
+ ...prev.attrs,
14
+ [YfmHeadingAttr.Id]: { default: '' },
15
+ [YfmHeadingAttr.Folding]: { default: null },
16
+ },
17
+ selectable: true,
18
+ parseDOM: [
19
+ { tag: 'h1', getAttrs: getNodeAttrs(1), priority: 100, consuming: true },
20
+ { tag: 'h2', getAttrs: getNodeAttrs(2), priority: 100, consuming: true },
21
+ { tag: 'h3', getAttrs: getNodeAttrs(3), priority: 100, consuming: true },
22
+ { tag: 'h4', getAttrs: getNodeAttrs(4), priority: 100, consuming: true },
23
+ { tag: 'h5', getAttrs: getNodeAttrs(5), priority: 100, consuming: true },
24
+ { tag: 'h6', getAttrs: getNodeAttrs(6), priority: 100, consuming: true },
25
+ {
26
+ // ignore anchor link inside headings
27
+ tag: 'a.yfm-anchor',
28
+ context: `${headingNodeName}/`,
29
+ skip: true,
30
+ ignore: true,
31
+ priority: 1000,
16
32
  },
17
- content: '(text | inline)*',
18
- group: 'block',
19
- defining: true,
20
- selectable: true,
21
- parseDOM: [
22
- { tag: 'h1', getAttrs: getNodeAttrs(1), priority: 100, consuming: true },
23
- { tag: 'h2', getAttrs: getNodeAttrs(2), priority: 100, consuming: true },
24
- { tag: 'h3', getAttrs: getNodeAttrs(3), priority: 100, consuming: true },
25
- { tag: 'h4', getAttrs: getNodeAttrs(4), priority: 100, consuming: true },
26
- { tag: 'h5', getAttrs: getNodeAttrs(5), priority: 100, consuming: true },
27
- { tag: 'h6', getAttrs: getNodeAttrs(6), priority: 100, consuming: true },
33
+ ],
34
+ toDOM(node) {
35
+ const id = node.attrs[YfmHeadingAttr.Id];
36
+ const lineNumber = node.attrs[YfmHeadingAttr.DataLine];
37
+ const folding = node.attrs[YfmHeadingAttr.Folding];
38
+ return [
39
+ 'h' + node.attrs[YfmHeadingAttr.Level],
28
40
  {
29
- // ignore anchor link inside headings
30
- tag: 'a.yfm-anchor',
31
- context: `${headingNodeName}/`,
32
- skip: true,
33
- ignore: true,
34
- priority: 1000,
35
- },
36
- ],
37
- toDOM(node) {
38
- const id = node.attrs[YfmHeadingAttr.Id];
39
- const lineNumber = node.attrs[YfmHeadingAttr.DataLine];
40
- const folding = node.attrs[YfmHeadingAttr.Folding];
41
- return [
42
- 'h' + node.attrs[YfmHeadingAttr.Level],
43
- {
44
- id: id || null,
45
- [YfmHeadingAttr.DataLine]: lineNumber,
46
- [`data-${YfmHeadingAttr.Folding}`]: folding,
47
- },
48
- 0,
49
- // [
50
- // 'a',
51
- // {
52
- // href: `#${node.attrs[YfmHeadingAttr.Id]}`,
53
- // class: 'yfm-anchor',
54
- // 'aria-hidden': 'true',
55
- // contenteditable: 'false',
56
- // },
57
- // ],
58
- // ['span', 0],
59
- ];
60
- },
61
- placeholder: {
62
- content: builder.context.get('placeholder')?.heading ??
63
- opts.headingPlaceholder ??
64
- DEFAULT_PLACEHOLDER,
65
- alwaysVisible: true,
66
- },
67
- },
68
- fromMd: {
69
- tokenSpec: {
70
- name: headingNodeName,
71
- type: 'block',
72
- getAttrs: (token) => {
73
- if (token.type.endsWith('_close'))
74
- return {};
75
- const attrs = Object.fromEntries(token.attrs || []);
76
- // if (!attrs[YfmHeadingAttr.Id]) {
77
- // // calculate id if it was not specified
78
- // // tokens[index + 1] is child inline token
79
- // attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
80
- // }
81
- // attrs have id only if it explicitly specified manually
82
- return {
83
- [YfmHeadingAttr.Level]: Number(token.tag.slice(1)),
84
- [YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,
85
- ...attrs,
86
- };
41
+ id: id || null,
42
+ [YfmHeadingAttr.DataLine]: lineNumber,
43
+ [`data-${YfmHeadingAttr.Folding}`]: folding,
87
44
  },
88
- },
45
+ 0,
46
+ // [
47
+ // 'a',
48
+ // {
49
+ // href: `#${node.attrs[YfmHeadingAttr.Id]}`,
50
+ // class: 'yfm-anchor',
51
+ // 'aria-hidden': 'true',
52
+ // contenteditable: 'false',
53
+ // },
54
+ // ],
55
+ // ['span', 0],
56
+ ];
89
57
  },
90
- toMd: (state, node) => {
91
- const folding = node.attrs[YfmHeadingAttr.Folding];
92
- const level = node.attrs[YfmHeadingAttr.Level];
93
- state.write(state.repeat('#', level) + (typeof folding === 'boolean' ? '+' : '') + ' ');
94
- state.renderInline(node);
95
- const anchor = node.attrs[YfmHeadingAttr.Id];
96
- if (anchor /*&& anchor !== node.firstChild?.textContent*/) {
97
- state.write(` {#${anchor}}`);
98
- }
99
- state.closeBlock(node);
58
+ }));
59
+ builder.overrideMarkdownTokenParserSpec(headingNodeName, (prev) => ({
60
+ ...prev,
61
+ getAttrs: (token) => {
62
+ if (token.type.endsWith('_close'))
63
+ return {};
64
+ const attrs = Object.fromEntries(token.attrs || []);
65
+ // if (!attrs[YfmHeadingAttr.Id]) {
66
+ // // calculate id if it was not specified
67
+ // // tokens[index + 1] is child inline token
68
+ // attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);
69
+ // }
70
+ // attrs have id only if it explicitly specified manually
71
+ return {
72
+ [YfmHeadingAttr.Level]: Number(token.tag.slice(1)),
73
+ [YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,
74
+ ...attrs,
75
+ };
100
76
  },
101
77
  }));
78
+ builder.overrideNodeSerializerSpec(headingNodeName, () => headingToMarkdown({
79
+ renderMarkup: renderYfmHeadingMarkup,
80
+ renderAttributes: renderYfmHeadingAttributes,
81
+ }));
102
82
  };
103
83
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,mBAAgB;AACxD,OAAO,EAAC,gBAAgB,EAAC,kCAA+B;AAC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,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC;YACxF,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;YAE7C,IAAI,MAAM,CAAC,8CAA8C,EAAE,CAAC;gBACxD,KAAK,CAAC,KAAK,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC;YACjC,CAAC;YAED,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;KACJ,CAAC,CAAC,CAAC;AACR,CAAC,CAAC","sourcesContent":["import type {ExtensionAuto} from '#core';\nimport type {Node, NodeSpec} from '#pm/model';\n\nimport {YfmHeadingAttr, headingNodeName} from './const';\nimport {headingIdsPlugin} from './markdown/heading-ids';\nimport {getNodeAttrs} from './utils';\n\nconst DEFAULT_PLACEHOLDER = (node: Node) => 'Heading ' + node.attrs[YfmHeadingAttr.Level];\n\nexport {YfmHeadingAttr} from './const';\n\nexport type YfmHeadingSpecsOptions = {\n /**\n * @deprecated: use placeholder option in BehaviorPreset instead.\n */\n headingPlaceholder?: NonNullable<NodeSpec['placeholder']>['content'];\n};\n\n/** YfmHeading extension needs markdown-it-attrs plugin */\nexport const YfmHeadingSpecs: ExtensionAuto<YfmHeadingSpecsOptions> = (builder, opts) => {\n builder.configureMd((md) => md.use(headingIdsPlugin));\n builder.addNode(headingNodeName, () => ({\n spec: {\n attrs: {\n [YfmHeadingAttr.Id]: {default: ''},\n [YfmHeadingAttr.Level]: {default: 1},\n [YfmHeadingAttr.DataLine]: {default: null},\n [YfmHeadingAttr.Folding]: {default: null},\n },\n content: '(text | inline)*',\n group: 'block',\n defining: true,\n selectable: true,\n parseDOM: [\n {tag: 'h1', getAttrs: getNodeAttrs(1), priority: 100, consuming: true},\n {tag: 'h2', getAttrs: getNodeAttrs(2), priority: 100, consuming: true},\n {tag: 'h3', getAttrs: getNodeAttrs(3), priority: 100, consuming: true},\n {tag: 'h4', getAttrs: getNodeAttrs(4), priority: 100, consuming: true},\n {tag: 'h5', getAttrs: getNodeAttrs(5), priority: 100, consuming: true},\n {tag: 'h6', getAttrs: getNodeAttrs(6), priority: 100, consuming: true},\n {\n // ignore anchor link inside headings\n tag: 'a.yfm-anchor',\n context: `${headingNodeName}/`,\n skip: true,\n ignore: true,\n priority: 1000,\n },\n ],\n toDOM(node) {\n const id = node.attrs[YfmHeadingAttr.Id];\n const lineNumber = node.attrs[YfmHeadingAttr.DataLine];\n const folding = node.attrs[YfmHeadingAttr.Folding];\n return [\n 'h' + node.attrs[YfmHeadingAttr.Level],\n {\n id: id || null,\n [YfmHeadingAttr.DataLine]: lineNumber,\n [`data-${YfmHeadingAttr.Folding}`]: folding,\n },\n 0,\n // [\n // 'a',\n // {\n // href: `#${node.attrs[YfmHeadingAttr.Id]}`,\n // class: 'yfm-anchor',\n // 'aria-hidden': 'true',\n // contenteditable: 'false',\n // },\n // ],\n // ['span', 0],\n ];\n },\n placeholder: {\n content:\n builder.context.get('placeholder')?.heading ??\n opts.headingPlaceholder ??\n DEFAULT_PLACEHOLDER,\n alwaysVisible: true,\n },\n },\n fromMd: {\n tokenSpec: {\n name: headingNodeName,\n type: 'block',\n getAttrs: (token) => {\n if (token.type.endsWith('_close')) return {};\n\n const attrs = Object.fromEntries(token.attrs || []);\n // if (!attrs[YfmHeadingAttr.Id]) {\n // // calculate id if it was not specified\n // // tokens[index + 1] is child inline token\n // attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);\n // }\n\n // attrs have id only if it explicitly specified manually\n return {\n [YfmHeadingAttr.Level]: Number(token.tag.slice(1)),\n [YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,\n ...attrs,\n };\n },\n },\n },\n toMd: (state, node) => {\n const folding = node.attrs[YfmHeadingAttr.Folding];\n const level = node.attrs[YfmHeadingAttr.Level];\n\n state.write(state.repeat('#', level) + (typeof folding === 'boolean' ? '+' : '') + ' ');\n state.renderInline(node);\n\n const anchor = node.attrs[YfmHeadingAttr.Id];\n\n if (anchor /*&& anchor !== node.firstChild?.textContent*/) {\n state.write(` {#${anchor}}`);\n }\n\n state.closeBlock(node);\n },\n }));\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,iBAAiB,GACpB,wDAAqD;AAEtD,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,mBAAgB;AACxD,OAAO,EAAC,gBAAgB,EAAC,kCAA+B;AACxD,OAAO,EAAC,YAAY,EAAE,0BAA0B,EAAE,sBAAsB,EAAC,mBAAgB;AAEzF,OAAO,EAAC,cAAc,EAAC,mBAAgB;AACvC,OAAO,EAAC,0BAA0B,EAAE,sBAAsB,EAAC,mBAAgB;AAI3E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAA0C,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;IACrF,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEtD,OAAO,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjD,GAAG,IAAI;QACP,KAAK,EAAE;YACH,GAAG,IAAI,CAAC,KAAK;YACb,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAC,OAAO,EAAE,EAAE,EAAC;YAClC,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC;SAC5C;QACD,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;YACN,EAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,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AAC;AACN,CAAC,CAAC","sourcesContent":["import type {ExtensionAuto} from '#core';\nimport {\n type HeadingSpecsOptions,\n headingToMarkdown,\n} from 'src/extensions/markdown/Heading/HeadingSpecs';\n\nimport {YfmHeadingAttr, headingNodeName} from './const';\nimport {headingIdsPlugin} from './markdown/heading-ids';\nimport {getNodeAttrs, renderYfmHeadingAttributes, renderYfmHeadingMarkup} from './utils';\n\nexport {YfmHeadingAttr} from './const';\nexport {renderYfmHeadingAttributes, renderYfmHeadingMarkup} from './utils';\n\nexport type YfmHeadingSpecsOptions = HeadingSpecsOptions & {};\n\n/** YfmHeading extension needs markdown-it-attrs plugin */\nexport const YfmHeadingSpecs: ExtensionAuto<YfmHeadingSpecsOptions> = (builder, _opts) => {\n builder.configureMd((md) => md.use(headingIdsPlugin));\n\n builder.overrideNodeSpec(headingNodeName, (prev) => ({\n ...prev,\n attrs: {\n ...prev.attrs,\n [YfmHeadingAttr.Id]: {default: ''},\n [YfmHeadingAttr.Folding]: {default: null},\n },\n selectable: true,\n parseDOM: [\n {tag: 'h1', getAttrs: getNodeAttrs(1), priority: 100, consuming: true},\n {tag: 'h2', getAttrs: getNodeAttrs(2), priority: 100, consuming: true},\n {tag: 'h3', getAttrs: getNodeAttrs(3), priority: 100, consuming: true},\n {tag: 'h4', getAttrs: getNodeAttrs(4), priority: 100, consuming: true},\n {tag: 'h5', getAttrs: getNodeAttrs(5), priority: 100, consuming: true},\n {tag: 'h6', getAttrs: getNodeAttrs(6), priority: 100, consuming: true},\n {\n // ignore anchor link inside headings\n tag: 'a.yfm-anchor',\n context: `${headingNodeName}/`,\n skip: true,\n ignore: true,\n priority: 1000,\n },\n ],\n toDOM(node) {\n const id = node.attrs[YfmHeadingAttr.Id];\n const lineNumber = node.attrs[YfmHeadingAttr.DataLine];\n const folding = node.attrs[YfmHeadingAttr.Folding];\n return [\n 'h' + node.attrs[YfmHeadingAttr.Level],\n {\n id: id || null,\n [YfmHeadingAttr.DataLine]: lineNumber,\n [`data-${YfmHeadingAttr.Folding}`]: folding,\n },\n 0,\n // [\n // 'a',\n // {\n // href: `#${node.attrs[YfmHeadingAttr.Id]}`,\n // class: 'yfm-anchor',\n // 'aria-hidden': 'true',\n // contenteditable: 'false',\n // },\n // ],\n // ['span', 0],\n ];\n },\n }));\n\n builder.overrideMarkdownTokenParserSpec(headingNodeName, (prev) => ({\n ...prev,\n getAttrs: (token) => {\n if (token.type.endsWith('_close')) return {};\n\n const attrs = Object.fromEntries(token.attrs || []);\n // if (!attrs[YfmHeadingAttr.Id]) {\n // // calculate id if it was not specified\n // // tokens[index + 1] is child inline token\n // attrs[YfmHeadingAttr.Id] = slugify(tokens[index + 1].content);\n // }\n\n // attrs have id only if it explicitly specified manually\n return {\n [YfmHeadingAttr.Level]: Number(token.tag.slice(1)),\n [YfmHeadingAttr.Folding]: token.meta?.folding === true ? true : null,\n ...attrs,\n };\n },\n }));\n\n builder.overrideNodeSerializerSpec(headingNodeName, () =>\n headingToMarkdown({\n renderMarkup: renderYfmHeadingMarkup,\n renderAttributes: renderYfmHeadingAttributes,\n }),\n );\n};\n"]}
@@ -1,5 +1,8 @@
1
1
  import type { TagParseRule } from 'prosemirror-model';
2
+ import type { SerializerNodeToken } from "../../../../core/index.js";
2
3
  import { type HeadingLevel } from "../const.js";
3
4
  export { hasParentHeading, headingRule } from "../../../markdown/Heading/utils.js";
4
5
  export { headingType } from "../../../markdown/Heading/HeadingSpecs/index.js";
5
6
  export declare const getNodeAttrs: (level: HeadingLevel) => TagParseRule["getAttrs"];
7
+ export declare const renderYfmHeadingMarkup: SerializerNodeToken;
8
+ export declare const renderYfmHeadingAttributes: SerializerNodeToken;
@@ -22,4 +22,15 @@ function getFoldingAttr(node) {
22
22
  // lower: true,
23
23
  // remove: /[*+~.()'"!:@]/g,
24
24
  // });
25
+ export const renderYfmHeadingMarkup = (state, node) => {
26
+ const folding = node.attrs[YfmHeadingAttr.Folding];
27
+ const level = node.attrs[YfmHeadingAttr.Level];
28
+ state.write(state.repeat('#', level) + (typeof folding === 'boolean' ? '+' : '') + ' ');
29
+ };
30
+ export const renderYfmHeadingAttributes = (state, node) => {
31
+ const anchor = node.attrs[YfmHeadingAttr.Id];
32
+ if (anchor /*&& anchor !== node.firstChild?.textContent*/) {
33
+ state.write(` {#${anchor}}`);
34
+ }
35
+ };
25
36
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,cAAc,EAAC,oBAAiB;AAC3D,OAAO,EAAC,gBAAgB,EAAE,WAAW,EAAC,2CAAwC;AAC9E,OAAO,EAAC,WAAW,EAAC,wDAA+C;AAEnE,mCAAmC;AAEnC,MAAM,CAAC,MAAM,YAAY,GACrB,CAAC,KAAmB,EAA4B,EAAE,CAClD,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACP,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,KAAK;IAC7B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE;IAClD,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC;CACjD,CAAC,CAAC;AAEP,SAAS,cAAc,CAAC,IAAiB;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;IAClE,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,0CAA0C;AAC1C,yCAAyC;AACzC,yGAAyG;AACzG,kBAAkB;AAClB,uBAAuB;AACvB,oCAAoC;AACpC,UAAU","sourcesContent":["import type {TagParseRule} from 'prosemirror-model';\n\nimport {type HeadingLevel, YfmHeadingAttr} from '../const';\nexport {hasParentHeading, headingRule} from '../../../markdown/Heading/utils';\nexport {headingType} from '../../../markdown/Heading/HeadingSpecs';\n\n// const slug = require('slugify');\n\nexport const getNodeAttrs =\n (level: HeadingLevel): TagParseRule['getAttrs'] =>\n (node) => ({\n [YfmHeadingAttr.Level]: level,\n [YfmHeadingAttr.Id]: node.getAttribute('id') || '',\n [YfmHeadingAttr.Folding]: getFoldingAttr(node),\n });\n\nfunction getFoldingAttr(node: HTMLElement): boolean | null {\n const value = node.getAttribute(`data-${YfmHeadingAttr.Folding}`);\n if (value === 'true') return true;\n if (value === 'false') return false;\n return null;\n}\n\n// export const slugify = (str: string) =>\n// // same config as in yfm-transform\n// // https://github.com/yandex-cloud/yfm-transform/blob/master/lib/plugins/anchors/index.js#L97-L100\n// slug(str, {\n// lower: true,\n// remove: /[*+~.()'\"!:@]/g,\n// });\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"../../../../../../src","sources":["extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,cAAc,EAAC,oBAAiB;AAC3D,OAAO,EAAC,gBAAgB,EAAE,WAAW,EAAC,2CAAwC;AAC9E,OAAO,EAAC,WAAW,EAAC,wDAA+C;AAEnE,mCAAmC;AAEnC,MAAM,CAAC,MAAM,YAAY,GACrB,CAAC,KAAmB,EAA4B,EAAE,CAClD,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACP,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,KAAK;IAC7B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE;IAClD,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC;CACjD,CAAC,CAAC;AAEP,SAAS,cAAc,CAAC,IAAiB;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;IAClE,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,0CAA0C;AAC1C,yCAAyC;AACzC,yGAAyG;AACzG,kBAAkB;AAClB,uBAAuB;AACvB,oCAAoC;AACpC,UAAU;AAEV,MAAM,CAAC,MAAM,sBAAsB,GAAwB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACvE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAE/C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC;AAC5F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAwB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAE7C,IAAI,MAAM,CAAC,8CAA8C,EAAE,CAAC;QACxD,KAAK,CAAC,KAAK,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type {TagParseRule} from 'prosemirror-model';\n\nimport type {SerializerNodeToken} from '#core';\n\nimport {type HeadingLevel, YfmHeadingAttr} from '../const';\nexport {hasParentHeading, headingRule} from '../../../markdown/Heading/utils';\nexport {headingType} from '../../../markdown/Heading/HeadingSpecs';\n\n// const slug = require('slugify');\n\nexport const getNodeAttrs =\n (level: HeadingLevel): TagParseRule['getAttrs'] =>\n (node) => ({\n [YfmHeadingAttr.Level]: level,\n [YfmHeadingAttr.Id]: node.getAttribute('id') || '',\n [YfmHeadingAttr.Folding]: getFoldingAttr(node),\n });\n\nfunction getFoldingAttr(node: HTMLElement): boolean | null {\n const value = node.getAttribute(`data-${YfmHeadingAttr.Folding}`);\n if (value === 'true') return true;\n if (value === 'false') return false;\n return null;\n}\n\n// export const slugify = (str: string) =>\n// // same config as in yfm-transform\n// // https://github.com/yandex-cloud/yfm-transform/blob/master/lib/plugins/anchors/index.js#L97-L100\n// slug(str, {\n// lower: true,\n// remove: /[*+~.()'\"!:@]/g,\n// });\n\nexport const renderYfmHeadingMarkup: SerializerNodeToken = (state, node) => {\n const folding = node.attrs[YfmHeadingAttr.Folding];\n const level = node.attrs[YfmHeadingAttr.Level];\n\n state.write(state.repeat('#', level) + (typeof folding === 'boolean' ? '+' : '') + ' ');\n};\n\nexport const renderYfmHeadingAttributes: SerializerNodeToken = (state, node) => {\n const anchor = node.attrs[YfmHeadingAttr.Id];\n\n if (anchor /*&& anchor !== node.firstChild?.textContent*/) {\n state.write(` {#${anchor}}`);\n }\n};\n"]}
@@ -1,11 +1,3 @@
1
- import { hasParentHeading } from "./YfmHeadingSpecs/utils.js";
2
- import { toHeading } from "./commands.js";
3
- export const headingAction = (level) => {
4
- const cmd = toHeading(level);
5
- return {
6
- isActive: hasParentHeading(level),
7
- isEnable: cmd,
8
- run: cmd,
9
- };
10
- };
1
+ import { headingAction as headingActionBase } from "../../markdown/Heading/actions.js";
2
+ export const headingAction = (level) => headingActionBase({}, level);
11
3
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"../../../../../src","sources":["extensions/yfm/YfmHeading/actions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,mCAAgC;AACzD,OAAO,EAAC,SAAS,EAAC,sBAAmB;AAGrC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAmB,EAAc,EAAE;IAC7D,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO;QACH,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC;QACjC,QAAQ,EAAE,GAAG;QACb,GAAG,EAAE,GAAG;KACX,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type {ActionSpec} from '../../../core';\n\nimport {hasParentHeading} from './YfmHeadingSpecs/utils';\nimport {toHeading} from './commands';\nimport type {HeadingLevel} from './const';\n\nexport const headingAction = (level: HeadingLevel): ActionSpec => {\n const cmd = toHeading(level);\n return {\n isActive: hasParentHeading(level),\n isEnable: cmd,\n run: cmd,\n };\n};\n"]}
1
+ {"version":3,"file":"actions.js","sourceRoot":"../../../../../src","sources":["extensions/yfm/YfmHeading/actions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,IAAI,iBAAiB,EAAC,0CAAgD;AAI3F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAmB,EAAc,EAAE,CAC7D,iBAAiB,CAAC,EAAc,EAAE,KAAK,CAAC,CAAC","sourcesContent":["import type {ActionSpec} from '#core';\nimport type {NodeType} from '#pm/model';\nimport {headingAction as headingActionBase} from 'src/extensions/markdown/Heading/actions';\n\nimport type {HeadingLevel} from './const';\n\nexport const headingAction = (level: HeadingLevel): ActionSpec =>\n headingActionBase({} as NodeType, level);\n"]}