@bwthomas/outline-numbering 0.4.0 → 0.5.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/README.md CHANGED
@@ -113,6 +113,7 @@ outlineNumberingPlugin({
113
113
  - **`strategy`** — any `OutlineNumberingStrategy`. Default: `alphanumericStrategy`.
114
114
  - **`descendThroughContainers`** — when `true` (default), ordered lists nested inside non-ordered containers (bullet lists, blockquotes, custom blocks) within a list item are discovered and numbered one level deeper than the enclosing item. When `false`, only ordered lists that are direct children of a list item are walked.
115
115
  - **`skipItem`** — `(item, {depth, pos, index}) => boolean`. A row this returns `true` for is passed over entirely: it takes no marker **and does not advance the counter**, so the row after it gets the number this one would have had. It keeps its `data-outline-depth`, and its children are still walked, so a nested list inside a skipped row still numbers. Default: `skipCardOnlyItems`.
116
+ - **`numberHeadings`** — `boolean | () => boolean`. When on, headings outside list items are numbered as outline levels: `h1` at depth 0 (`I.`), `h2` at depth 1 (`A.`), `h3` at depth 2 (`1.`). An ordered list after a heading starts one level below it, and a heading shares its level's counter with the points there, so an `h2` after two points under an `h1` reads `C.`. Each level resets under a new parent heading. Pass a function to toggle it at runtime, then dispatch `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` to recompute without a document change. Default: `false`.
116
117
 
117
118
  ### `skipCardOnlyItems` — the default, and why it changed in 0.4.0
118
119
 
package/dist/index.cjs CHANGED
@@ -133,15 +133,18 @@ function outlineNumberingPlugin(options = {}) {
133
133
  const renderMarkerInline = options.renderMarkerInline ?? false;
134
134
  const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
135
135
  const skipItem = options.skipItem ?? skipCardOnlyItems;
136
+ const numberHeadings = options.numberHeadings ?? false;
137
+ const headingsOn = () => typeof numberHeadings === "function" ? numberHeadings() : numberHeadings;
138
+ const compute = (doc) => computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());
136
139
  return new prosemirrorState.Plugin({
137
140
  key: OUTLINE_NUMBERING_KEY,
138
141
  state: {
139
142
  init(_, { doc }) {
140
- return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
143
+ return compute(doc);
141
144
  },
142
145
  apply(tr, decorationSet) {
143
- if (tr.docChanged) {
144
- return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
146
+ if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {
147
+ return compute(tr.doc);
145
148
  }
146
149
  return decorationSet.map(tr.mapping, tr.doc);
147
150
  }
@@ -153,16 +156,47 @@ function outlineNumberingPlugin(options = {}) {
153
156
  }
154
157
  });
155
158
  }
156
- function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems) {
159
+ function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems, numberHeadings = false) {
157
160
  const decorations = [];
158
161
  const continueSet = new Set(continueAcrossNodeTypes);
162
+ function markerWidget(pos, markerText, key) {
163
+ decorations.push(
164
+ prosemirrorView.Decoration.widget(pos, () => {
165
+ const span = document.createElement("span");
166
+ span.className = "outline-marker";
167
+ span.setAttribute("aria-hidden", "false");
168
+ span.setAttribute("data-outline-marker", markerText);
169
+ span.style.pointerEvents = "none";
170
+ span.textContent = markerText;
171
+ return span;
172
+ }, { side: -1, key })
173
+ );
174
+ }
159
175
  function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
160
176
  let childOffset = 0;
161
177
  let runCounter = 0;
178
+ const headingsHere = numberHeadings && !insideListItem;
179
+ const levelCounters = [];
180
+ let listDepth = depth;
162
181
  parent.forEach((child) => {
163
182
  const childPos = parentChildrenStart + childOffset;
164
- if (child.type.name === "orderedList") {
165
- runCounter = walkOrderedList(child, childPos, depth, runCounter);
183
+ if (child.type.name === "orderedList" && headingsHere) {
184
+ levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);
185
+ } else if (child.type.name === "orderedList") {
186
+ runCounter = walkOrderedList(child, childPos, listDepth, runCounter);
187
+ } else if (headingsHere && child.type.name === "heading") {
188
+ const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);
189
+ levelCounters.length = headingDepth + 1;
190
+ levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;
191
+ const markerText = strategy.format(levelCounters[headingDepth], headingDepth);
192
+ decorations.push(
193
+ prosemirrorView.Decoration.node(childPos, childPos + child.nodeSize, {
194
+ "data-outline-depth": String(headingDepth),
195
+ "data-outline-marker": markerText
196
+ })
197
+ );
198
+ if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);
199
+ listDepth = headingDepth + 1;
166
200
  } else {
167
201
  if (!continueSet.has(child.type.name)) {
168
202
  runCounter = 0;
@@ -214,19 +248,7 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
214
248
  "data-outline-marker": markerText
215
249
  })
216
250
  );
217
- if (renderMarkerInline) {
218
- decorations.push(
219
- prosemirrorView.Decoration.widget(itemPos + 1, () => {
220
- const span = document.createElement("span");
221
- span.className = "outline-marker";
222
- span.setAttribute("aria-hidden", "false");
223
- span.setAttribute("data-outline-marker", markerText);
224
- span.style.pointerEvents = "none";
225
- span.textContent = markerText;
226
- return span;
227
- }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
228
- );
229
- }
251
+ if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);
230
252
  iterateChildren(child, itemPos + 1, depth + 1, true);
231
253
  childOffset += child.nodeSize;
232
254
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts"],"names":["PluginKey","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AASO,SAAS,QAAQ,CAAA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I;AAAA,SAC1E;AAAA,MACF;AAKA,MAAA,eAAA,CAAgB,KAAA,EAAO,OAAA,GAAU,CAAA,EAAG,KAAA,GAAQ,GAAG,IAAI,CAAA;AACnD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C","file":"index.cjs","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, depth, runCounter);\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n if (renderMarkerInline) {\n // Widget at the start of the listItem renders the marker as part\n // of the DOM so screen readers voice it as content. Pure rendering —\n // not part of the document model, so copy/paste/transactions are\n // unchanged. `side: -1` puts it before any inline content;\n // `pointer-events: none` so clicks pass through to the listItem.\n decorations.push(\n Decoration.widget(itemPos + 1, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` }),\n );\n }\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n"]}
1
+ {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts"],"names":["PluginKey","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;AACzC,EAAA,MAAM,KAAA,GAAkD;AAAA,IACtD,CAAC,KAAM,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAAG,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAChD,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAAG,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAC5C,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG;AAAA,GACpD;AACA,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,KAAA,MAAW,CAAC,KAA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AAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C","file":"index.cjs","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n /**\n * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1\n * (A.), an h3 depth 2 (1.), each counter resetting under a new parent\n * heading. An orderedList after a heading starts one level below it, so the\n * points under an \"A.\" heading read 1., 2., 3. Only headings outside list\n * items count. Off by default.\n *\n * Pass a function to toggle it at runtime, then dispatch a transaction with\n * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin\n * recomputes without a document change.\n */\n numberHeadings: boolean | (() => boolean);\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n const numberHeadings = options.numberHeadings ?? false;\n const headingsOn = () => (typeof numberHeadings === 'function' ? numberHeadings() : numberHeadings);\n const compute = (doc: any) =>\n computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return compute(doc);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {\n return compute(tr.doc);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n numberHeadings: boolean = false,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** The marker widget renderMarkerInline puts at the start of a numbered node. */\n function markerWidget(pos: number, markerText: string, key: string) {\n decorations.push(\n Decoration.widget(pos, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key }),\n );\n }\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n // With numberHeadings, headings and lists share one counter per depth, and a list starts one level below the last heading.\n const headingsHere = numberHeadings && !insideListItem;\n const levelCounters: number[] = [];\n let listDepth = depth;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList' && headingsHere) {\n levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);\n } else if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, listDepth, runCounter);\n } else if (headingsHere && child.type.name === 'heading') {\n const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);\n levelCounters.length = headingDepth + 1;\n levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;\n const markerText = strategy.format(levelCounters[headingDepth], headingDepth);\n decorations.push(\n Decoration.node(childPos, childPos + child.nodeSize, {\n 'data-outline-depth': String(headingDepth),\n 'data-outline-marker': markerText,\n }),\n );\n if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);\n listDepth = headingDepth + 1;\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n // Widget at the start of the listItem renders the marker as part of the DOM so screen readers voice it; `side: -1` puts it before any inline content.\n if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutlineNumberingStrategy } from './plugin-BtIV_e2G.cjs';
2
- export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingItemInfo, c as OutlineNumberingPluginOptions, d as computeDecorations, n as numberEveryItem, o as outlineNumberingPlugin, s as skipCardOnlyItems } from './plugin-BtIV_e2G.cjs';
1
+ import { O as OutlineNumberingStrategy } from './plugin-Ds09i43H.cjs';
2
+ export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingItemInfo, c as OutlineNumberingPluginOptions, d as computeDecorations, n as numberEveryItem, o as outlineNumberingPlugin, s as skipCardOnlyItems } from './plugin-Ds09i43H.cjs';
3
3
  import 'prosemirror-state';
4
4
  import 'prosemirror-view';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutlineNumberingStrategy } from './plugin-BtIV_e2G.js';
2
- export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingItemInfo, c as OutlineNumberingPluginOptions, d as computeDecorations, n as numberEveryItem, o as outlineNumberingPlugin, s as skipCardOnlyItems } from './plugin-BtIV_e2G.js';
1
+ import { O as OutlineNumberingStrategy } from './plugin-Ds09i43H.js';
2
+ export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingItemInfo, c as OutlineNumberingPluginOptions, d as computeDecorations, n as numberEveryItem, o as outlineNumberingPlugin, s as skipCardOnlyItems } from './plugin-Ds09i43H.js';
3
3
  import 'prosemirror-state';
4
4
  import 'prosemirror-view';
5
5
 
package/dist/index.js CHANGED
@@ -131,15 +131,18 @@ function outlineNumberingPlugin(options = {}) {
131
131
  const renderMarkerInline = options.renderMarkerInline ?? false;
132
132
  const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
133
133
  const skipItem = options.skipItem ?? skipCardOnlyItems;
134
+ const numberHeadings = options.numberHeadings ?? false;
135
+ const headingsOn = () => typeof numberHeadings === "function" ? numberHeadings() : numberHeadings;
136
+ const compute = (doc) => computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());
134
137
  return new Plugin({
135
138
  key: OUTLINE_NUMBERING_KEY,
136
139
  state: {
137
140
  init(_, { doc }) {
138
- return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
141
+ return compute(doc);
139
142
  },
140
143
  apply(tr, decorationSet) {
141
- if (tr.docChanged) {
142
- return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
144
+ if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {
145
+ return compute(tr.doc);
143
146
  }
144
147
  return decorationSet.map(tr.mapping, tr.doc);
145
148
  }
@@ -151,16 +154,47 @@ function outlineNumberingPlugin(options = {}) {
151
154
  }
152
155
  });
153
156
  }
154
- function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems) {
157
+ function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems, numberHeadings = false) {
155
158
  const decorations = [];
156
159
  const continueSet = new Set(continueAcrossNodeTypes);
160
+ function markerWidget(pos, markerText, key) {
161
+ decorations.push(
162
+ Decoration.widget(pos, () => {
163
+ const span = document.createElement("span");
164
+ span.className = "outline-marker";
165
+ span.setAttribute("aria-hidden", "false");
166
+ span.setAttribute("data-outline-marker", markerText);
167
+ span.style.pointerEvents = "none";
168
+ span.textContent = markerText;
169
+ return span;
170
+ }, { side: -1, key })
171
+ );
172
+ }
157
173
  function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
158
174
  let childOffset = 0;
159
175
  let runCounter = 0;
176
+ const headingsHere = numberHeadings && !insideListItem;
177
+ const levelCounters = [];
178
+ let listDepth = depth;
160
179
  parent.forEach((child) => {
161
180
  const childPos = parentChildrenStart + childOffset;
162
- if (child.type.name === "orderedList") {
163
- runCounter = walkOrderedList(child, childPos, depth, runCounter);
181
+ if (child.type.name === "orderedList" && headingsHere) {
182
+ levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);
183
+ } else if (child.type.name === "orderedList") {
184
+ runCounter = walkOrderedList(child, childPos, listDepth, runCounter);
185
+ } else if (headingsHere && child.type.name === "heading") {
186
+ const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);
187
+ levelCounters.length = headingDepth + 1;
188
+ levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;
189
+ const markerText = strategy.format(levelCounters[headingDepth], headingDepth);
190
+ decorations.push(
191
+ Decoration.node(childPos, childPos + child.nodeSize, {
192
+ "data-outline-depth": String(headingDepth),
193
+ "data-outline-marker": markerText
194
+ })
195
+ );
196
+ if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);
197
+ listDepth = headingDepth + 1;
164
198
  } else {
165
199
  if (!continueSet.has(child.type.name)) {
166
200
  runCounter = 0;
@@ -212,19 +246,7 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
212
246
  "data-outline-marker": markerText
213
247
  })
214
248
  );
215
- if (renderMarkerInline) {
216
- decorations.push(
217
- Decoration.widget(itemPos + 1, () => {
218
- const span = document.createElement("span");
219
- span.className = "outline-marker";
220
- span.setAttribute("aria-hidden", "false");
221
- span.setAttribute("data-outline-marker", markerText);
222
- span.style.pointerEvents = "none";
223
- span.textContent = markerText;
224
- return span;
225
- }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
226
- );
227
- }
249
+ if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);
228
250
  iterateChildren(child, itemPos + 1, depth + 1, true);
229
251
  childOffset += child.nodeSize;
230
252
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts"],"names":[],"mappings":";;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;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,MACF;AAKA,MAAA,eAAA,CAAgB,KAAA,EAAO,OAAA,GAAU,CAAA,EAAG,KAAA,GAAQ,GAAG,IAAI,CAAA;AACnD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAO,aAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C","file":"index.js","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, depth, runCounter);\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n if (renderMarkerInline) {\n // Widget at the start of the listItem renders the marker as part\n // of the DOM so screen readers voice it as content. Pure rendering —\n // not part of the document model, so copy/paste/transactions are\n // unchanged. `side: -1` puts it before any inline content;\n // `pointer-events: none` so clicks pass through to the listItem.\n decorations.push(\n Decoration.widget(itemPos + 1, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` }),\n );\n }\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n"]}
1
+ {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts"],"names":[],"mappings":";;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;AACzC,EAAA,MAAM,KAAA,GAAkD;AAAA,IACtD,CAAC,KAAM,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAAG,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAChD,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAAG,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAC5C,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG;AAAA,GACpD;AACA,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,MAAM,CAAA,IAAK,KAAA,EAAO;AACnC,IAAA,OAAO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bering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n /**\n * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1\n * (A.), an h3 depth 2 (1.), each counter resetting under a new parent\n * heading. An orderedList after a heading starts one level below it, so the\n * points under an \"A.\" heading read 1., 2., 3. Only headings outside list\n * items count. Off by default.\n *\n * Pass a function to toggle it at runtime, then dispatch a transaction with\n * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin\n * recomputes without a document change.\n */\n numberHeadings: boolean | (() => boolean);\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n const numberHeadings = options.numberHeadings ?? false;\n const headingsOn = () => (typeof numberHeadings === 'function' ? numberHeadings() : numberHeadings);\n const compute = (doc: any) =>\n computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return compute(doc);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {\n return compute(tr.doc);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n numberHeadings: boolean = false,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** The marker widget renderMarkerInline puts at the start of a numbered node. */\n function markerWidget(pos: number, markerText: string, key: string) {\n decorations.push(\n Decoration.widget(pos, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key }),\n );\n }\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n // With numberHeadings, headings and lists share one counter per depth, and a list starts one level below the last heading.\n const headingsHere = numberHeadings && !insideListItem;\n const levelCounters: number[] = [];\n let listDepth = depth;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList' && headingsHere) {\n levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);\n } else if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, listDepth, runCounter);\n } else if (headingsHere && child.type.name === 'heading') {\n const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);\n levelCounters.length = headingDepth + 1;\n levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;\n const markerText = strategy.format(levelCounters[headingDepth], headingDepth);\n decorations.push(\n Decoration.node(childPos, childPos + child.nodeSize, {\n 'data-outline-depth': String(headingDepth),\n 'data-outline-marker': markerText,\n }),\n );\n if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);\n listDepth = headingDepth + 1;\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n // Widget at the start of the listItem renders the marker as part of the DOM so screen readers voice it; `side: -1` puts it before any inline content.\n if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n"]}
@@ -73,6 +73,18 @@ interface OutlineNumberingPluginOptions {
73
73
  * that knows its own schema can be exact where the default has to generalise.
74
74
  */
75
75
  skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;
76
+ /**
77
+ * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1
78
+ * (A.), an h3 depth 2 (1.), each counter resetting under a new parent
79
+ * heading. An orderedList after a heading starts one level below it, so the
80
+ * points under an "A." heading read 1., 2., 3. Only headings outside list
81
+ * items count. Off by default.
82
+ *
83
+ * Pass a function to toggle it at runtime, then dispatch a transaction with
84
+ * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin
85
+ * recomputes without a document change.
86
+ */
87
+ numberHeadings: boolean | (() => boolean);
76
88
  }
77
89
  /** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */
78
90
  interface OutlineNumberingItemInfo {
@@ -121,6 +133,6 @@ declare function outlineNumberingPlugin(options?: Partial<OutlineNumberingPlugin
121
133
  * programmatic use (tests, custom plugin composition); the plugin itself
122
134
  * calls this internally.
123
135
  */
124
- declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[], skipItem?: (item: any, info: OutlineNumberingItemInfo) => boolean): DecorationSet;
136
+ declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[], skipItem?: (item: any, info: OutlineNumberingItemInfo) => boolean, numberHeadings?: boolean): DecorationSet;
125
137
 
126
138
  export { type OutlineNumberingStrategy as O, OUTLINE_NUMBERING_KEY as a, type OutlineNumberingItemInfo as b, type OutlineNumberingPluginOptions as c, computeDecorations as d, numberEveryItem as n, outlineNumberingPlugin as o, skipCardOnlyItems as s };
@@ -73,6 +73,18 @@ interface OutlineNumberingPluginOptions {
73
73
  * that knows its own schema can be exact where the default has to generalise.
74
74
  */
75
75
  skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;
76
+ /**
77
+ * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1
78
+ * (A.), an h3 depth 2 (1.), each counter resetting under a new parent
79
+ * heading. An orderedList after a heading starts one level below it, so the
80
+ * points under an "A." heading read 1., 2., 3. Only headings outside list
81
+ * items count. Off by default.
82
+ *
83
+ * Pass a function to toggle it at runtime, then dispatch a transaction with
84
+ * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin
85
+ * recomputes without a document change.
86
+ */
87
+ numberHeadings: boolean | (() => boolean);
76
88
  }
77
89
  /** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */
78
90
  interface OutlineNumberingItemInfo {
@@ -121,6 +133,6 @@ declare function outlineNumberingPlugin(options?: Partial<OutlineNumberingPlugin
121
133
  * programmatic use (tests, custom plugin composition); the plugin itself
122
134
  * calls this internally.
123
135
  */
124
- declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[], skipItem?: (item: any, info: OutlineNumberingItemInfo) => boolean): DecorationSet;
136
+ declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[], skipItem?: (item: any, info: OutlineNumberingItemInfo) => boolean, numberHeadings?: boolean): DecorationSet;
125
137
 
126
138
  export { type OutlineNumberingStrategy as O, OUTLINE_NUMBERING_KEY as a, type OutlineNumberingItemInfo as b, type OutlineNumberingPluginOptions as c, computeDecorations as d, numberEveryItem as n, outlineNumberingPlugin as o, skipCardOnlyItems as s };
package/dist/tiptap.cjs CHANGED
@@ -87,15 +87,18 @@ function outlineNumberingPlugin(options = {}) {
87
87
  const renderMarkerInline = options.renderMarkerInline ?? false;
88
88
  const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
89
89
  const skipItem = options.skipItem ?? skipCardOnlyItems;
90
+ const numberHeadings = options.numberHeadings ?? false;
91
+ const headingsOn = () => typeof numberHeadings === "function" ? numberHeadings() : numberHeadings;
92
+ const compute = (doc) => computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());
90
93
  return new prosemirrorState.Plugin({
91
94
  key: OUTLINE_NUMBERING_KEY,
92
95
  state: {
93
96
  init(_, { doc }) {
94
- return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
97
+ return compute(doc);
95
98
  },
96
99
  apply(tr, decorationSet) {
97
- if (tr.docChanged) {
98
- return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
100
+ if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {
101
+ return compute(tr.doc);
99
102
  }
100
103
  return decorationSet.map(tr.mapping, tr.doc);
101
104
  }
@@ -107,16 +110,47 @@ function outlineNumberingPlugin(options = {}) {
107
110
  }
108
111
  });
109
112
  }
110
- function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems) {
113
+ function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems, numberHeadings = false) {
111
114
  const decorations = [];
112
115
  const continueSet = new Set(continueAcrossNodeTypes);
116
+ function markerWidget(pos, markerText, key) {
117
+ decorations.push(
118
+ prosemirrorView.Decoration.widget(pos, () => {
119
+ const span = document.createElement("span");
120
+ span.className = "outline-marker";
121
+ span.setAttribute("aria-hidden", "false");
122
+ span.setAttribute("data-outline-marker", markerText);
123
+ span.style.pointerEvents = "none";
124
+ span.textContent = markerText;
125
+ return span;
126
+ }, { side: -1, key })
127
+ );
128
+ }
113
129
  function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
114
130
  let childOffset = 0;
115
131
  let runCounter = 0;
132
+ const headingsHere = numberHeadings && !insideListItem;
133
+ const levelCounters = [];
134
+ let listDepth = depth;
116
135
  parent.forEach((child) => {
117
136
  const childPos = parentChildrenStart + childOffset;
118
- if (child.type.name === "orderedList") {
119
- runCounter = walkOrderedList(child, childPos, depth, runCounter);
137
+ if (child.type.name === "orderedList" && headingsHere) {
138
+ levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);
139
+ } else if (child.type.name === "orderedList") {
140
+ runCounter = walkOrderedList(child, childPos, listDepth, runCounter);
141
+ } else if (headingsHere && child.type.name === "heading") {
142
+ const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);
143
+ levelCounters.length = headingDepth + 1;
144
+ levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;
145
+ const markerText = strategy.format(levelCounters[headingDepth], headingDepth);
146
+ decorations.push(
147
+ prosemirrorView.Decoration.node(childPos, childPos + child.nodeSize, {
148
+ "data-outline-depth": String(headingDepth),
149
+ "data-outline-marker": markerText
150
+ })
151
+ );
152
+ if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);
153
+ listDepth = headingDepth + 1;
120
154
  } else {
121
155
  if (!continueSet.has(child.type.name)) {
122
156
  runCounter = 0;
@@ -168,19 +202,7 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
168
202
  "data-outline-marker": markerText
169
203
  })
170
204
  );
171
- if (renderMarkerInline) {
172
- decorations.push(
173
- prosemirrorView.Decoration.widget(itemPos + 1, () => {
174
- const span = document.createElement("span");
175
- span.className = "outline-marker";
176
- span.setAttribute("aria-hidden", "false");
177
- span.setAttribute("data-outline-marker", markerText);
178
- span.style.pointerEvents = "none";
179
- span.textContent = markerText;
180
- return span;
181
- }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
182
- );
183
- }
205
+ if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);
184
206
  iterateChildren(child, itemPos + 1, depth + 1, true);
185
207
  childOffset += child.nodeSize;
186
208
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts","../src/tipt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Ae,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;ACxRO,IAAM,gBAAA,GAAmBC,eAAU,MAAA,CAAgC;AAAA,EACxE,IAAA,EAAM,kBAAA;AAAA,EAEN,UAAA,GAAa;AACX,IAAA,OAAO,EAAC;AAAA,EACV,CAAA;AAAA,EAEA,qBAAA,GAAwB;AACtB,IAAA,OAAO,CAAC,sBAAA,CAAuB,IAAA,CAAK,OAAO,CAAC,CAAA;AAAA,EAC9C;AACF,CAAC","file":"tiptap.cjs","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, depth, runCounter);\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n if (renderMarkerInline) {\n // Widget at the start of the listItem renders the marker as part\n // of the DOM so screen readers voice it as content. Pure rendering —\n // not part of the document model, so copy/paste/transactions are\n // unchanged. `side: -1` puts it before any inline content;\n // `pointer-events: none` so clicks pass through to the listItem.\n decorations.push(\n Decoration.widget(itemPos + 1, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` }),\n );\n }\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n","/**\n * Tiptap wrapper around the framework-agnostic ProseMirror plugin.\n *\n * This module is published under the `/tiptap` subpath. Tiptap consumers:\n *\n * import { OutlineNumbering } from '@bwthomas/outline-numbering/tiptap';\n * import { decimalStrategy } from '@bwthomas/outline-numbering';\n * new Editor({ extensions: [OutlineNumbering.configure({ strategy: decimalStrategy })] });\n *\n * Raw ProseMirror users do not need to load this file — import\n * `outlineNumberingPlugin` from the package root instead.\n */\nimport { Extension } from '@tiptap/core';\nimport {\n OutlineNumberingPluginOptions,\n outlineNumberingPlugin,\n} from './plugin';\n\nexport type OutlineNumberingOptions = Partial<OutlineNumberingPluginOptions>;\n\nexport const OutlineNumbering = Extension.create<OutlineNumberingOptions>({\n name: 'outlineNumbering',\n\n addOptions() {\n return {};\n },\n\n addProseMirrorPlugins() {\n return [outlineNumberingPlugin(this.options)];\n },\n});\n"]}
1
+ {"version":3,"sources":["../src/strategies.ts","../src/plugin.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,kBAAA,EAAoB,YAAA,CAAa,OAAA,GAAU,CAAA,EAAG,UAAA,EAAY,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,EAAI,UAAU,CAAA,CAAE,CAAA;AAKhH,MAAA,eAAA,CAAgB,KAAA,EAAO,OAAA,GAAU,CAAA,EAAG,KAAA,GAAQ,GAAG,IAAI,CAAA;AACnD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;AC3TO,IAAM,gBAAA,GAAmBC,eAAU,MAAA,CAAgC;AAAA,EACxE,IAAA,EAAM,kBAAA;AAAA,EAEN,UAAA,GAAa;AACX,IAAA,OAAO,EAAC;AAAA,EACV,CAAA;AAAA,EAEA,qBAAA,GAAwB;AACtB,IAAA,OAAO,CAAC,sBAAA,CAAuB,IAAA,CAAK,OAAO,CAAC,CAAA;AAAA,EAC9C;AACF,CAAC","file":"tiptap.cjs","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n /**\n * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1\n * (A.), an h3 depth 2 (1.), each counter resetting under a new parent\n * heading. An orderedList after a heading starts one level below it, so the\n * points under an \"A.\" heading read 1., 2., 3. Only headings outside list\n * items count. Off by default.\n *\n * Pass a function to toggle it at runtime, then dispatch a transaction with\n * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin\n * recomputes without a document change.\n */\n numberHeadings: boolean | (() => boolean);\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n const numberHeadings = options.numberHeadings ?? false;\n const headingsOn = () => (typeof numberHeadings === 'function' ? numberHeadings() : numberHeadings);\n const compute = (doc: any) =>\n computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return compute(doc);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {\n return compute(tr.doc);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n numberHeadings: boolean = false,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** The marker widget renderMarkerInline puts at the start of a numbered node. */\n function markerWidget(pos: number, markerText: string, key: string) {\n decorations.push(\n Decoration.widget(pos, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key }),\n );\n }\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n // With numberHeadings, headings and lists share one counter per depth, and a list starts one level below the last heading.\n const headingsHere = numberHeadings && !insideListItem;\n const levelCounters: number[] = [];\n let listDepth = depth;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList' && headingsHere) {\n levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);\n } else if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, listDepth, runCounter);\n } else if (headingsHere && child.type.name === 'heading') {\n const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);\n levelCounters.length = headingDepth + 1;\n levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;\n const markerText = strategy.format(levelCounters[headingDepth], headingDepth);\n decorations.push(\n Decoration.node(childPos, childPos + child.nodeSize, {\n 'data-outline-depth': String(headingDepth),\n 'data-outline-marker': markerText,\n }),\n );\n if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);\n listDepth = headingDepth + 1;\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n // Widget at the start of the listItem renders the marker as part of the DOM so screen readers voice it; `side: -1` puts it before any inline content.\n if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n","/**\n * Tiptap wrapper around the framework-agnostic ProseMirror plugin.\n *\n * This module is published under the `/tiptap` subpath. Tiptap consumers:\n *\n * import { OutlineNumbering } from '@bwthomas/outline-numbering/tiptap';\n * import { decimalStrategy } from '@bwthomas/outline-numbering';\n * new Editor({ extensions: [OutlineNumbering.configure({ strategy: decimalStrategy })] });\n *\n * Raw ProseMirror users do not need to load this file — import\n * `outlineNumberingPlugin` from the package root instead.\n */\nimport { Extension } from '@tiptap/core';\nimport {\n OutlineNumberingPluginOptions,\n outlineNumberingPlugin,\n} from './plugin';\n\nexport type OutlineNumberingOptions = Partial<OutlineNumberingPluginOptions>;\n\nexport const OutlineNumbering = Extension.create<OutlineNumberingOptions>({\n name: 'outlineNumbering',\n\n addOptions() {\n return {};\n },\n\n addProseMirrorPlugins() {\n return [outlineNumberingPlugin(this.options)];\n },\n});\n"]}
package/dist/tiptap.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import { c as OutlineNumberingPluginOptions } from './plugin-BtIV_e2G.cjs';
2
+ import { c as OutlineNumberingPluginOptions } from './plugin-Ds09i43H.cjs';
3
3
  import 'prosemirror-state';
4
4
  import 'prosemirror-view';
5
5
 
package/dist/tiptap.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import { c as OutlineNumberingPluginOptions } from './plugin-BtIV_e2G.js';
2
+ import { c as OutlineNumberingPluginOptions } from './plugin-Ds09i43H.js';
3
3
  import 'prosemirror-state';
4
4
  import 'prosemirror-view';
5
5
 
package/dist/tiptap.js CHANGED
@@ -85,15 +85,18 @@ function outlineNumberingPlugin(options = {}) {
85
85
  const renderMarkerInline = options.renderMarkerInline ?? false;
86
86
  const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
87
87
  const skipItem = options.skipItem ?? skipCardOnlyItems;
88
+ const numberHeadings = options.numberHeadings ?? false;
89
+ const headingsOn = () => typeof numberHeadings === "function" ? numberHeadings() : numberHeadings;
90
+ const compute = (doc) => computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());
88
91
  return new Plugin({
89
92
  key: OUTLINE_NUMBERING_KEY,
90
93
  state: {
91
94
  init(_, { doc }) {
92
- return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
95
+ return compute(doc);
93
96
  },
94
97
  apply(tr, decorationSet) {
95
- if (tr.docChanged) {
96
- return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);
98
+ if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {
99
+ return compute(tr.doc);
97
100
  }
98
101
  return decorationSet.map(tr.mapping, tr.doc);
99
102
  }
@@ -105,16 +108,47 @@ function outlineNumberingPlugin(options = {}) {
105
108
  }
106
109
  });
107
110
  }
108
- function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems) {
111
+ function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = [], skipItem = skipCardOnlyItems, numberHeadings = false) {
109
112
  const decorations = [];
110
113
  const continueSet = new Set(continueAcrossNodeTypes);
114
+ function markerWidget(pos, markerText, key) {
115
+ decorations.push(
116
+ Decoration.widget(pos, () => {
117
+ const span = document.createElement("span");
118
+ span.className = "outline-marker";
119
+ span.setAttribute("aria-hidden", "false");
120
+ span.setAttribute("data-outline-marker", markerText);
121
+ span.style.pointerEvents = "none";
122
+ span.textContent = markerText;
123
+ return span;
124
+ }, { side: -1, key })
125
+ );
126
+ }
111
127
  function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
112
128
  let childOffset = 0;
113
129
  let runCounter = 0;
130
+ const headingsHere = numberHeadings && !insideListItem;
131
+ const levelCounters = [];
132
+ let listDepth = depth;
114
133
  parent.forEach((child) => {
115
134
  const childPos = parentChildrenStart + childOffset;
116
- if (child.type.name === "orderedList") {
117
- runCounter = walkOrderedList(child, childPos, depth, runCounter);
135
+ if (child.type.name === "orderedList" && headingsHere) {
136
+ levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);
137
+ } else if (child.type.name === "orderedList") {
138
+ runCounter = walkOrderedList(child, childPos, listDepth, runCounter);
139
+ } else if (headingsHere && child.type.name === "heading") {
140
+ const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);
141
+ levelCounters.length = headingDepth + 1;
142
+ levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;
143
+ const markerText = strategy.format(levelCounters[headingDepth], headingDepth);
144
+ decorations.push(
145
+ Decoration.node(childPos, childPos + child.nodeSize, {
146
+ "data-outline-depth": String(headingDepth),
147
+ "data-outline-marker": markerText
148
+ })
149
+ );
150
+ if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);
151
+ listDepth = headingDepth + 1;
118
152
  } else {
119
153
  if (!continueSet.has(child.type.name)) {
120
154
  runCounter = 0;
@@ -166,19 +200,7 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
166
200
  "data-outline-marker": markerText
167
201
  })
168
202
  );
169
- if (renderMarkerInline) {
170
- decorations.push(
171
- Decoration.widget(itemPos + 1, () => {
172
- const span = document.createElement("span");
173
- span.className = "outline-marker";
174
- span.setAttribute("aria-hidden", "false");
175
- span.setAttribute("data-outline-marker", markerText);
176
- span.style.pointerEvents = "none";
177
- span.textContent = markerText;
178
- return span;
179
- }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
180
- );
181
- }
203
+ if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);
182
204
  iterateChildren(child, itemPos + 1, depth + 1, true);
183
205
  childOffset += child.nodeSize;
184
206
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts","../src/tiptap.ts"],"names":[],"mappings":";;;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;AACzC,EAAA,MAAM,KAAA,GAAkD;AAAA,IACtD,CAAC,KAAM,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAAG,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAChD,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAAG,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAC5C,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG;AAAA,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AAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA;AAC1C,YAAA,IAAA,CAAK,SAAA,GAAY,gBAAA;AACjB,YAAA,IAAA,CAAK,YAAA,CAAa,eAAe,OAAO,CAAA;AACxC,YAAA,IAAA,CAAK,YAAA,CAAa,uBAAuB,UAAU,CAAA;AACnD,YAAA,IAAA,CAAK,MAAM,aAAA,GAAgB,MAAA;AAC3B,YAAA,IAAA,CAAK,WAAA,GAAc,UAAA;AACnB,YAAA,OAAO,IAAA;AAAA,UACT,CAAA,EAAG,EAAE,IAAA,EAAM,EAAA,EAAI,GAAA,EAAK,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,EAAI,UAAU,CAAA,CAAA,EAAI;AAAA,SAC1E;AAAA,MACF;AAKA,MAAA,eAAA,CAAgB,KAAA,EAAO,OAAA,GAAU,CAAA,EAAG,KAAA,GAAQ,GAAG,IAAI,CAAA;AACnD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAO,aAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;ACxRO,IAAM,gBAAA,GAAmB,UAAU,MAAA,CAAgC;AAAA,EACxE,IAAA,EAAM,kBAAA;AAAA,EAEN,UAAA,GAAa;AACX,IAAA,OAAO,EAAC;AAAA,EACV,CAAA;AAAA,EAEA,qBAAA,GAAwB;AACtB,IAAA,OAAO,CAAC,sBAAA,CAAuB,IAAA,CAAK,OAAO,CAAC,CAAA;AAAA,EAC9C;AACF,CAAC","file":"tiptap.js","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, depth, runCounter);\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n if (renderMarkerInline) {\n // Widget at the start of the listItem renders the marker as part\n // of the DOM so screen readers voice it as content. Pure rendering —\n // not part of the document model, so copy/paste/transactions are\n // unchanged. `side: -1` puts it before any inline content;\n // `pointer-events: none` so clicks pass through to the listItem.\n decorations.push(\n Decoration.widget(itemPos + 1, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` }),\n );\n }\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n","/**\n * Tiptap wrapper around the framework-agnostic ProseMirror plugin.\n *\n * This module is published under the `/tiptap` subpath. Tiptap consumers:\n *\n * import { OutlineNumbering } from '@bwthomas/outline-numbering/tiptap';\n * import { decimalStrategy } from '@bwthomas/outline-numbering';\n * new Editor({ extensions: [OutlineNumbering.configure({ strategy: decimalStrategy })] });\n *\n * Raw ProseMirror users do not need to load this file — import\n * `outlineNumberingPlugin` from the package root instead.\n */\nimport { Extension } from '@tiptap/core';\nimport {\n OutlineNumberingPluginOptions,\n outlineNumberingPlugin,\n} from './plugin';\n\nexport type OutlineNumberingOptions = Partial<OutlineNumberingPluginOptions>;\n\nexport const OutlineNumbering = Extension.create<OutlineNumberingOptions>({\n name: 'outlineNumbering',\n\n addOptions() {\n return {};\n },\n\n addProseMirrorPlugins() {\n return [outlineNumberingPlugin(this.options)];\n },\n});\n"]}
1
+ {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts","../src/tiptap.ts"],"names":[],"mappings":";;;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;AACzC,EAAA,MAAM,KAAA,GAAkD;AAAA,IACtD,CAAC,KAAM,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAAG,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAChD,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAAG,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAC5C,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG;AAAA,GACpD;AACA,EAAA,IAAI,MAAA,GAAS,EAAA;AAC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B;AACtB,IAAA,OAAO,CAAC,sBAAA,CAAuB,IAAA,CAAK,OAAO,CAAC,CAAA;AAAA,EAC9C;AACF,CAAC","file":"tiptap.js","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n /**\n * When true, also emit a widget decoration `<span class=\"outline-marker\">…</span>`\n * at the start of each numbered listItem. Off by default for back-compat — the\n * historical pattern is `::before { content: attr(data-outline-marker); }` in\n * consumer CSS, which leaves the marker invisible to screen readers (SR users\n * hear only \"list item\"). Turn on to make markers part of the rendered DOM\n * so SR voicing includes them; the consumer's CSS must then style\n * `.outline-marker` instead of `::before`.\n */\n renderMarkerInline: boolean;\n /**\n * Sibling node types that should NOT reset the orderedList counter when\n * they appear between two orderedLists at the same level. Defaults to `[]`\n * (every non-orderedList sibling resets). For example, an outline editor\n * may want callouts/citations placed between list items not to interrupt\n * the numbering of the surrounding list:\n *\n * [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV\n * [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II\n *\n * Headings, paragraphs, and any other \"hard break\" sibling reset the\n * counter even with this option set, unless they're listed too.\n */\n continueAcrossNodeTypes: string[];\n /**\n * Decides whether a listItem is passed over by the numbering entirely — it\n * takes no marker AND does not advance the counter, so the item after it\n * gets the number this one would have had. Its children are still walked, so\n * a nested list inside a skipped row still numbers.\n *\n * Defaults to {@link skipCardOnlyItems}, which passes over a row that holds\n * no words of its own but does hold a block — a citation card, a callout, an\n * embed. Such a row is a CONTAINER a reader does not count, and numbering it\n * makes the outline's own numbering disagree with what the reader sees.\n *\n * Pass {@link numberEveryItem} for the pre-0.4 behaviour, or any predicate\n * of your own — the item and its position are both supplied, so a consumer\n * that knows its own schema can be exact where the default has to generalise.\n */\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean;\n /**\n * Numbers headings as outline levels: an h1 is depth 0 (I.), an h2 depth 1\n * (A.), an h3 depth 2 (1.), each counter resetting under a new parent\n * heading. An orderedList after a heading starts one level below it, so the\n * points under an \"A.\" heading read 1., 2., 3. Only headings outside list\n * items count. Off by default.\n *\n * Pass a function to toggle it at runtime, then dispatch a transaction with\n * `tr.setMeta(OUTLINE_NUMBERING_KEY, { refresh: true })` so the plugin\n * recomputes without a document change.\n */\n numberHeadings: boolean | (() => boolean);\n}\n\n/** Where a candidate listItem sits, supplied to {@link OutlineNumberingPluginOptions.skipItem}. */\nexport interface OutlineNumberingItemInfo {\n /** 0-based nesting depth, the same value passed to the strategy. */\n depth: number;\n /** Document position of the listItem node. */\n pos: number;\n /** 0-based index of this listItem among its parent list's listItem children. */\n index: number;\n}\n\n/** True for a node that holds list items, so the default predicate can tell a\n * row that merely nests a sublist from a row that holds a card. Name-based\n * with a group fallback, because the schema is the consumer's, not ours. */\nfunction isListLike(node: any): boolean {\n const name = node.type.name;\n if (name === 'orderedList' || name === 'bulletList') return true;\n const group: string = node.type.spec?.group ?? '';\n return group.split(' ').includes('list');\n}\n\n/**\n * The default {@link OutlineNumberingPluginOptions.skipItem}: pass over a row\n * whose own leading paragraph is empty but which carries another, non-list\n * block — a citation card, a callout, an embed.\n *\n * The test is on the LEADING child, not on \"does the row contain any text\",\n * and that distinction was measured rather than reasoned. A citation node\n * declares `content: 'text*'`, so it is a TEXTBLOCK CARRYING TEXT — the very\n * shape a \"row with no words\" test reads as words. `listItem` content is\n * `paragraph block*`, so a row's first child is always its own structural\n * paragraph, and whether THAT is empty is the thing that separates a row\n * someone wrote in from a row that is only a container.\n *\n * listItem(paragraph(\"Methods\")) → NUMBERED. Has words.\n * listItem(paragraph(\"\")) → NUMBERED. An empty row someone\n * is about to type into must keep\n * its number, or it appears the\n * moment they press a key.\n * listItem(paragraph(\"\"), citation(…)) → SKIPPED. A card-only row.\n * listItem(paragraph(\"Methods\"), citation(…)) → NUMBERED. The row has its own\n * words; the card is beside them.\n * listItem(paragraph(\"\"), orderedList(…)) → NUMBERED. A row that only\n * groups a sublist is still a row.\n */\nexport function skipCardOnlyItems(item: any): boolean {\n let leadingIsEmpty = false;\n let hasOtherBlock = false;\n item.forEach((child: any, _offset: number, index: number) => {\n if (index === 0) {\n leadingIsEmpty = child.isTextblock && child.textContent.trim().length === 0;\n } else if (!isListLike(child)) {\n hasOtherBlock = true;\n }\n });\n return leadingIsEmpty && hasOtherBlock;\n}\n\n/** The pre-0.4 behaviour: every listItem takes a number. Pass as `skipItem`. */\nexport function numberEveryItem(): boolean {\n return false;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n const renderMarkerInline = options.renderMarkerInline ?? false;\n const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];\n const skipItem = options.skipItem ?? skipCardOnlyItems;\n const numberHeadings = options.numberHeadings ?? false;\n const headingsOn = () => (typeof numberHeadings === 'function' ? numberHeadings() : numberHeadings);\n const compute = (doc: any) =>\n computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes, skipItem, headingsOn());\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return compute(doc);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged || tr.getMeta(OUTLINE_NUMBERING_KEY)?.refresh) {\n return compute(tr.doc);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n renderMarkerInline: boolean = false,\n continueAcrossNodeTypes: string[] = [],\n skipItem: (item: any, info: OutlineNumberingItemInfo) => boolean = skipCardOnlyItems,\n numberHeadings: boolean = false,\n): DecorationSet {\n const decorations: Decoration[] = [];\n const continueSet = new Set(continueAcrossNodeTypes);\n\n /** The marker widget renderMarkerInline puts at the start of a numbered node. */\n function markerWidget(pos: number, markerText: string, key: string) {\n decorations.push(\n Decoration.widget(pos, () => {\n const span = document.createElement('span');\n span.className = 'outline-marker';\n span.setAttribute('aria-hidden', 'false');\n span.setAttribute('data-outline-marker', markerText);\n span.style.pointerEvents = 'none';\n span.textContent = markerText;\n return span;\n }, { side: -1, key }),\n );\n }\n\n /** Walk a parent's children, handling orderedLists with run-counter\n * continuity. The runCounter accumulates across consecutive\n * orderedList siblings (and any siblings whose type is in\n * continueSet); any other sibling resets the run. */\n function iterateChildren(parent: any, parentChildrenStart: number, depth: number, insideListItem: boolean) {\n let childOffset = 0;\n let runCounter = 0;\n // With numberHeadings, headings and lists share one counter per depth, and a list starts one level below the last heading.\n const headingsHere = numberHeadings && !insideListItem;\n const levelCounters: number[] = [];\n let listDepth = depth;\n parent.forEach((child: any) => {\n const childPos = parentChildrenStart + childOffset;\n if (child.type.name === 'orderedList' && headingsHere) {\n levelCounters[listDepth] = walkOrderedList(child, childPos, listDepth, levelCounters[listDepth] ?? 0);\n } else if (child.type.name === 'orderedList') {\n runCounter = walkOrderedList(child, childPos, listDepth, runCounter);\n } else if (headingsHere && child.type.name === 'heading') {\n const headingDepth = depth + Math.max(0, (child.attrs?.level ?? 1) - 1);\n levelCounters.length = headingDepth + 1;\n levelCounters[headingDepth] = (levelCounters[headingDepth] ?? 0) + 1;\n const markerText = strategy.format(levelCounters[headingDepth], headingDepth);\n decorations.push(\n Decoration.node(childPos, childPos + child.nodeSize, {\n 'data-outline-depth': String(headingDepth),\n 'data-outline-marker': markerText,\n }),\n );\n if (renderMarkerInline) markerWidget(childPos + 1, markerText, `outline-heading-marker-${headingDepth}-${markerText}`);\n listDepth = headingDepth + 1;\n } else {\n if (!continueSet.has(child.type.name)) {\n runCounter = 0;\n }\n walk(child, childPos, depth, insideListItem);\n }\n childOffset += child.nodeSize;\n });\n }\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n // Direct call (e.g. recursion landed on an orderedList without\n // going through a parent's iterateChildren). Treat as a fresh run.\n walkOrderedList(node, pos, depth, 0);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const childrenStart = pos + (node.type.name === 'doc' ? 0 : 1);\n iterateChildren(node, childrenStart, depth, insideListItem);\n }\n\n /** Walk one orderedList, emitting decorations for its listItem\n * children. `startCounter` is the running counter inherited from\n * any preceding orderedList siblings in the same run. Returns the\n * counter value after the last listItem so the caller can pass it\n * to the next orderedList in the run. */\n function walkOrderedList(node: any, pos: number, depth: number, startCounter: number): number {\n const offset = pos + 1;\n let counter = startCounter;\n let childOffset = 0;\n let itemIndex = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n const itemPos = offset + childOffset;\n // A skipped row takes no marker and does not advance the counter, so the\n // row after it gets the number this one would have had. It still carries\n // `data-outline-depth`, because a consumer's CSS indents from that and a\n // row that lost its depth would jump to the left margin — a worse defect\n // than the number it was there to remove. Its children are still walked\n // below, so a nested list inside a card row still numbers.\n if (skipItem(child, { depth, pos: itemPos, index: itemIndex })) {\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-skipped': '',\n }),\n );\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n itemIndex++;\n return;\n }\n counter++;\n itemIndex++;\n const markerText = strategy.format(counter, depth);\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': markerText,\n }),\n );\n\n // Widget at the start of the listItem renders the marker as part of the DOM so screen readers voice it; `side: -1` puts it before any inline content.\n if (renderMarkerInline) markerWidget(itemPos + 1, markerText, `outline-marker-${depth}-${counter}-${markerText}`);\n\n // Recurse into the listItem's children with depth+1, using the\n // same run-counter logic so nested adjacent orderedLists also\n // continue across continue-set siblings.\n iterateChildren(child, itemPos + 1, depth + 1, true);\n childOffset += child.nodeSize;\n });\n return counter;\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n","/**\n * Tiptap wrapper around the framework-agnostic ProseMirror plugin.\n *\n * This module is published under the `/tiptap` subpath. Tiptap consumers:\n *\n * import { OutlineNumbering } from '@bwthomas/outline-numbering/tiptap';\n * import { decimalStrategy } from '@bwthomas/outline-numbering';\n * new Editor({ extensions: [OutlineNumbering.configure({ strategy: decimalStrategy })] });\n *\n * Raw ProseMirror users do not need to load this file — import\n * `outlineNumberingPlugin` from the package root instead.\n */\nimport { Extension } from '@tiptap/core';\nimport {\n OutlineNumberingPluginOptions,\n outlineNumberingPlugin,\n} from './plugin';\n\nexport type OutlineNumberingOptions = Partial<OutlineNumberingPluginOptions>;\n\nexport const OutlineNumbering = Extension.create<OutlineNumberingOptions>({\n name: 'outlineNumbering',\n\n addOptions() {\n return {};\n },\n\n addProseMirrorPlugins() {\n return [outlineNumberingPlugin(this.options)];\n },\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bwthomas/outline-numbering",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Framework-agnostic ProseMirror plugin (with Tiptap wrapper) for nested ordered-list numbering with pluggable strategies: alphanumeric (Harvard / Purdue OWL I/A/1/a), decimal, legal, arabic, lower-roman, or custom.",
5
5
  "license": "MIT",
6
6
  "author": "Blake Thomas <bwthomas@users.noreply.github.com>",