@bwthomas/outline-numbering 0.2.0 → 0.3.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/dist/index.cjs +28 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/dist/{plugin-D5aGrqak.d.cts → plugin-B7531iUA.d.cts} +15 -1
- package/dist/{plugin-D5aGrqak.d.ts → plugin-B7531iUA.d.ts} +15 -1
- package/dist/tiptap.cjs +28 -17
- package/dist/tiptap.cjs.map +1 -1
- package/dist/tiptap.d.cts +1 -1
- package/dist/tiptap.d.ts +1 -1
- package/dist/tiptap.js +28 -17
- package/dist/tiptap.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -110,15 +110,16 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
110
110
|
const strategy = options.strategy ?? alphanumericStrategy;
|
|
111
111
|
const descendThroughContainers = options.descendThroughContainers ?? true;
|
|
112
112
|
const renderMarkerInline = options.renderMarkerInline ?? false;
|
|
113
|
+
const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
|
|
113
114
|
return new prosemirrorState.Plugin({
|
|
114
115
|
key: OUTLINE_NUMBERING_KEY,
|
|
115
116
|
state: {
|
|
116
117
|
init(_, { doc }) {
|
|
117
|
-
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
118
|
+
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
118
119
|
},
|
|
119
120
|
apply(tr, decorationSet) {
|
|
120
121
|
if (tr.docChanged) {
|
|
121
|
-
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
122
|
+
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
122
123
|
}
|
|
123
124
|
return decorationSet.map(tr.mapping, tr.doc);
|
|
124
125
|
}
|
|
@@ -130,25 +131,38 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
130
131
|
}
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
|
-
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false) {
|
|
134
|
+
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = []) {
|
|
134
135
|
const decorations = [];
|
|
136
|
+
const continueSet = new Set(continueAcrossNodeTypes);
|
|
137
|
+
function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
|
|
138
|
+
let childOffset = 0;
|
|
139
|
+
let runCounter = 0;
|
|
140
|
+
parent.forEach((child) => {
|
|
141
|
+
const childPos = parentChildrenStart + childOffset;
|
|
142
|
+
if (child.type.name === "orderedList") {
|
|
143
|
+
runCounter = walkOrderedList(child, childPos, depth, runCounter);
|
|
144
|
+
} else {
|
|
145
|
+
if (!continueSet.has(child.type.name)) {
|
|
146
|
+
runCounter = 0;
|
|
147
|
+
}
|
|
148
|
+
walk(child, childPos, depth, insideListItem);
|
|
149
|
+
}
|
|
150
|
+
childOffset += child.nodeSize;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
135
153
|
function walk(node, pos, depth, insideListItem) {
|
|
136
154
|
if (node.type.name === "orderedList") {
|
|
137
|
-
walkOrderedList(node, pos, depth);
|
|
155
|
+
walkOrderedList(node, pos, depth, 0);
|
|
138
156
|
return;
|
|
139
157
|
}
|
|
140
158
|
if (insideListItem && !descendThroughContainers) return;
|
|
141
159
|
if (!node.isBlock || node.isLeaf) return;
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
node.forEach((child) => {
|
|
145
|
-
walk(child, offset + childOffset, depth, insideListItem);
|
|
146
|
-
childOffset += child.nodeSize;
|
|
147
|
-
});
|
|
160
|
+
const childrenStart = pos + (node.type.name === "doc" ? 0 : 1);
|
|
161
|
+
iterateChildren(node, childrenStart, depth, insideListItem);
|
|
148
162
|
}
|
|
149
|
-
function walkOrderedList(node, pos, depth) {
|
|
163
|
+
function walkOrderedList(node, pos, depth, startCounter) {
|
|
150
164
|
const offset = pos + 1;
|
|
151
|
-
let counter =
|
|
165
|
+
let counter = startCounter;
|
|
152
166
|
let childOffset = 0;
|
|
153
167
|
node.forEach((child) => {
|
|
154
168
|
if (child.type.name !== "listItem") {
|
|
@@ -177,13 +191,10 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
|
|
|
177
191
|
}, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
|
|
178
192
|
);
|
|
179
193
|
}
|
|
180
|
-
|
|
181
|
-
child.forEach((grandchild) => {
|
|
182
|
-
walk(grandchild, grandOffset, depth + 1, true);
|
|
183
|
-
grandOffset += grandchild.nodeSize;
|
|
184
|
-
});
|
|
194
|
+
iterateChildren(child, itemPos + 1, depth + 1, true);
|
|
185
195
|
childOffset += child.nodeSize;
|
|
186
196
|
});
|
|
197
|
+
return counter;
|
|
187
198
|
}
|
|
188
199
|
walk(doc, 0, 0, false);
|
|
189
200
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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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AAA,IAAe,UAAA,CAAW,QAAA;AAAA,MAC5B,CAAC,CAAA;AACD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AAAA,EACH;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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);\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): DecorationSet {\n const decorations: Decoration[] = [];\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n walkOrderedList(node, pos, depth);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const offset = pos + (node.type.name === 'doc' ? 0 : 1);\n let childOffset = 0;\n node.forEach((child: any) => {\n walk(child, offset + childOffset, depth, insideListItem);\n childOffset += child.nodeSize;\n });\n }\n\n function walkOrderedList(node: any, pos: number, depth: number) {\n const offset = pos + 1;\n let counter = 0;\n let childOffset = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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 let grandOffset = itemPos + 1;\n child.forEach((grandchild: any) => {\n walk(grandchild, grandOffset, depth + 1, true);\n grandOffset += grandchild.nodeSize;\n });\n childOffset += child.nodeSize;\n });\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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S,OAAA,GAAU,MAAM,QAAA,EAAU;AAAA,UACjD,oBAAA,EAAsB,OAAO,KAAK,CAAA;AAAA,UAClC,qBAAA,EAAuB;AAAA,SACxB;AAAA,OACH;AAEA,MAAA,IAAI,kBAAA,EAAoB;AAMtB,QAAA,WAAA,CAAY,IAAA;AAAA,UACVA,0BAAA,CAAW,MAAA,CAAO,OAAA,GAAU,CAAA,EAAG,MAAM;AACnC,YAAA,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,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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\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): 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 node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as OutlineNumberingStrategy } from './plugin-
|
|
2
|
-
export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-
|
|
1
|
+
import { O as OutlineNumberingStrategy } from './plugin-B7531iUA.cjs';
|
|
2
|
+
export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-B7531iUA.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-
|
|
2
|
-
export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-
|
|
1
|
+
import { O as OutlineNumberingStrategy } from './plugin-B7531iUA.js';
|
|
2
|
+
export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-B7531iUA.js';
|
|
3
3
|
import 'prosemirror-state';
|
|
4
4
|
import 'prosemirror-view';
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -108,15 +108,16 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
108
108
|
const strategy = options.strategy ?? alphanumericStrategy;
|
|
109
109
|
const descendThroughContainers = options.descendThroughContainers ?? true;
|
|
110
110
|
const renderMarkerInline = options.renderMarkerInline ?? false;
|
|
111
|
+
const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
|
|
111
112
|
return new Plugin({
|
|
112
113
|
key: OUTLINE_NUMBERING_KEY,
|
|
113
114
|
state: {
|
|
114
115
|
init(_, { doc }) {
|
|
115
|
-
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
116
|
+
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
116
117
|
},
|
|
117
118
|
apply(tr, decorationSet) {
|
|
118
119
|
if (tr.docChanged) {
|
|
119
|
-
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
120
|
+
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
120
121
|
}
|
|
121
122
|
return decorationSet.map(tr.mapping, tr.doc);
|
|
122
123
|
}
|
|
@@ -128,25 +129,38 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
128
129
|
}
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
|
-
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false) {
|
|
132
|
+
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = []) {
|
|
132
133
|
const decorations = [];
|
|
134
|
+
const continueSet = new Set(continueAcrossNodeTypes);
|
|
135
|
+
function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
|
|
136
|
+
let childOffset = 0;
|
|
137
|
+
let runCounter = 0;
|
|
138
|
+
parent.forEach((child) => {
|
|
139
|
+
const childPos = parentChildrenStart + childOffset;
|
|
140
|
+
if (child.type.name === "orderedList") {
|
|
141
|
+
runCounter = walkOrderedList(child, childPos, depth, runCounter);
|
|
142
|
+
} else {
|
|
143
|
+
if (!continueSet.has(child.type.name)) {
|
|
144
|
+
runCounter = 0;
|
|
145
|
+
}
|
|
146
|
+
walk(child, childPos, depth, insideListItem);
|
|
147
|
+
}
|
|
148
|
+
childOffset += child.nodeSize;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
133
151
|
function walk(node, pos, depth, insideListItem) {
|
|
134
152
|
if (node.type.name === "orderedList") {
|
|
135
|
-
walkOrderedList(node, pos, depth);
|
|
153
|
+
walkOrderedList(node, pos, depth, 0);
|
|
136
154
|
return;
|
|
137
155
|
}
|
|
138
156
|
if (insideListItem && !descendThroughContainers) return;
|
|
139
157
|
if (!node.isBlock || node.isLeaf) return;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
node.forEach((child) => {
|
|
143
|
-
walk(child, offset + childOffset, depth, insideListItem);
|
|
144
|
-
childOffset += child.nodeSize;
|
|
145
|
-
});
|
|
158
|
+
const childrenStart = pos + (node.type.name === "doc" ? 0 : 1);
|
|
159
|
+
iterateChildren(node, childrenStart, depth, insideListItem);
|
|
146
160
|
}
|
|
147
|
-
function walkOrderedList(node, pos, depth) {
|
|
161
|
+
function walkOrderedList(node, pos, depth, startCounter) {
|
|
148
162
|
const offset = pos + 1;
|
|
149
|
-
let counter =
|
|
163
|
+
let counter = startCounter;
|
|
150
164
|
let childOffset = 0;
|
|
151
165
|
node.forEach((child) => {
|
|
152
166
|
if (child.type.name !== "listItem") {
|
|
@@ -175,13 +189,10 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
|
|
|
175
189
|
}, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
|
|
176
190
|
);
|
|
177
191
|
}
|
|
178
|
-
|
|
179
|
-
child.forEach((grandchild) => {
|
|
180
|
-
walk(grandchild, grandOffset, depth + 1, true);
|
|
181
|
-
grandOffset += grandchild.nodeSize;
|
|
182
|
-
});
|
|
192
|
+
iterateChildren(child, itemPos + 1, depth + 1, true);
|
|
183
193
|
childOffset += child.nodeSize;
|
|
184
194
|
});
|
|
195
|
+
return counter;
|
|
185
196
|
}
|
|
186
197
|
walk(doc, 0, 0, false);
|
|
187
198
|
return DecorationSet.create(doc, decorations);
|
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;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,KAAK,KAAA,EAAO;AACjB,MAAA,MAAA,IAAU,MAAA;AACV,MAAA,CAAA,IAAK,KAAA;AAAA,IACP;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,QAAA,CAAS,GAAW,SAAA,EAA4B;AAC9D,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,OAAO,IAAI,CAAA,EAAG;AACZ,IAAA,CAAA,EAAA;AACA,IAAA,MAAM,IAAA,GAAO,YAAY,EAAA,GAAK,EAAA;AAC9B,IAAA,MAAA,GAAS,MAAA,CAAO,YAAA,CAAa,IAAA,GAAQ,CAA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e,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;AAEA,MAAA,IAAI,cAAc,OAAA,GAAU,CAAA;AAC5B,MAAA,KAAA,CAAM,OAAA,CAAQ,CAAC,UAAA,KAAoB;AACjC,QAAA,IAAA,CAAK,UAAA,EAAY,WAAA,EAAa,KAAA,GAAQ,CAAA,EAAG,IAAI,CAAA;AAC7C,QAAA,WAAA,IAAe,UAAA,CAAW,QAAA;AAAA,MAC5B,CAAC,CAAA;AACD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AAAA,EACH;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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);\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): DecorationSet {\n const decorations: Decoration[] = [];\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n walkOrderedList(node, pos, depth);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const offset = pos + (node.type.name === 'doc' ? 0 : 1);\n let childOffset = 0;\n node.forEach((child: any) => {\n walk(child, offset + childOffset, depth, insideListItem);\n childOffset += child.nodeSize;\n });\n }\n\n function walkOrderedList(node: any, pos: number, depth: number) {\n const offset = pos + 1;\n let counter = 0;\n let childOffset = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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 let grandOffset = itemPos + 1;\n child.forEach((grandchild: any) => {\n walk(grandchild, grandOffset, depth + 1, true);\n grandOffset += grandchild.nodeSize;\n });\n childOffset += child.nodeSize;\n });\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,KAAK,KAAA,EAAO;AACjB,MAAA,MAAA,IAAU,MAAA;AACV,MAAA,CAAA,IAAK,KAAA;AAAA,IACP;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,QAAA,CAAS,GAAW,SAAA,EAA4B;AAC9D,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,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,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","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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\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): 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 node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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"]}
|
|
@@ -43,6 +43,20 @@ interface OutlineNumberingPluginOptions {
|
|
|
43
43
|
* `.outline-marker` instead of `::before`.
|
|
44
44
|
*/
|
|
45
45
|
renderMarkerInline: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Sibling node types that should NOT reset the orderedList counter when
|
|
48
|
+
* they appear between two orderedLists at the same level. Defaults to `[]`
|
|
49
|
+
* (every non-orderedList sibling resets). For example, an outline editor
|
|
50
|
+
* may want callouts/citations placed between list items not to interrupt
|
|
51
|
+
* the numbering of the surrounding list:
|
|
52
|
+
*
|
|
53
|
+
* [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV
|
|
54
|
+
* [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II
|
|
55
|
+
*
|
|
56
|
+
* Headings, paragraphs, and any other "hard break" sibling reset the
|
|
57
|
+
* counter even with this option set, unless they're listed too.
|
|
58
|
+
*/
|
|
59
|
+
continueAcrossNodeTypes: string[];
|
|
46
60
|
}
|
|
47
61
|
/**
|
|
48
62
|
* Stable plugin key — exposed so other plugins can read the current
|
|
@@ -55,6 +69,6 @@ declare function outlineNumberingPlugin(options?: Partial<OutlineNumberingPlugin
|
|
|
55
69
|
* programmatic use (tests, custom plugin composition); the plugin itself
|
|
56
70
|
* calls this internally.
|
|
57
71
|
*/
|
|
58
|
-
declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean): DecorationSet;
|
|
72
|
+
declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[]): DecorationSet;
|
|
59
73
|
|
|
60
74
|
export { type OutlineNumberingStrategy as O, OUTLINE_NUMBERING_KEY as a, type OutlineNumberingPluginOptions as b, computeDecorations as c, outlineNumberingPlugin as o };
|
|
@@ -43,6 +43,20 @@ interface OutlineNumberingPluginOptions {
|
|
|
43
43
|
* `.outline-marker` instead of `::before`.
|
|
44
44
|
*/
|
|
45
45
|
renderMarkerInline: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Sibling node types that should NOT reset the orderedList counter when
|
|
48
|
+
* they appear between two orderedLists at the same level. Defaults to `[]`
|
|
49
|
+
* (every non-orderedList sibling resets). For example, an outline editor
|
|
50
|
+
* may want callouts/citations placed between list items not to interrupt
|
|
51
|
+
* the numbering of the surrounding list:
|
|
52
|
+
*
|
|
53
|
+
* [ol[1, 2], citation, ol[3, 4]] → numbering stays I, II, III, IV
|
|
54
|
+
* [ol[1, 2], heading, ol[3, 4]] → numbering resets — I, II, I, II
|
|
55
|
+
*
|
|
56
|
+
* Headings, paragraphs, and any other "hard break" sibling reset the
|
|
57
|
+
* counter even with this option set, unless they're listed too.
|
|
58
|
+
*/
|
|
59
|
+
continueAcrossNodeTypes: string[];
|
|
46
60
|
}
|
|
47
61
|
/**
|
|
48
62
|
* Stable plugin key — exposed so other plugins can read the current
|
|
@@ -55,6 +69,6 @@ declare function outlineNumberingPlugin(options?: Partial<OutlineNumberingPlugin
|
|
|
55
69
|
* programmatic use (tests, custom plugin composition); the plugin itself
|
|
56
70
|
* calls this internally.
|
|
57
71
|
*/
|
|
58
|
-
declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean): DecorationSet;
|
|
72
|
+
declare function computeDecorations(doc: any, strategy: OutlineNumberingStrategy, descendThroughContainers?: boolean, renderMarkerInline?: boolean, continueAcrossNodeTypes?: string[]): DecorationSet;
|
|
59
73
|
|
|
60
74
|
export { type OutlineNumberingStrategy as O, OUTLINE_NUMBERING_KEY as a, type OutlineNumberingPluginOptions as b, computeDecorations as c, outlineNumberingPlugin as o };
|
package/dist/tiptap.cjs
CHANGED
|
@@ -67,15 +67,16 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
67
67
|
const strategy = options.strategy ?? alphanumericStrategy;
|
|
68
68
|
const descendThroughContainers = options.descendThroughContainers ?? true;
|
|
69
69
|
const renderMarkerInline = options.renderMarkerInline ?? false;
|
|
70
|
+
const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
|
|
70
71
|
return new prosemirrorState.Plugin({
|
|
71
72
|
key: OUTLINE_NUMBERING_KEY,
|
|
72
73
|
state: {
|
|
73
74
|
init(_, { doc }) {
|
|
74
|
-
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
75
|
+
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
75
76
|
},
|
|
76
77
|
apply(tr, decorationSet) {
|
|
77
78
|
if (tr.docChanged) {
|
|
78
|
-
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
79
|
+
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
79
80
|
}
|
|
80
81
|
return decorationSet.map(tr.mapping, tr.doc);
|
|
81
82
|
}
|
|
@@ -87,25 +88,38 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
|
-
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false) {
|
|
91
|
+
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = []) {
|
|
91
92
|
const decorations = [];
|
|
93
|
+
const continueSet = new Set(continueAcrossNodeTypes);
|
|
94
|
+
function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
|
|
95
|
+
let childOffset = 0;
|
|
96
|
+
let runCounter = 0;
|
|
97
|
+
parent.forEach((child) => {
|
|
98
|
+
const childPos = parentChildrenStart + childOffset;
|
|
99
|
+
if (child.type.name === "orderedList") {
|
|
100
|
+
runCounter = walkOrderedList(child, childPos, depth, runCounter);
|
|
101
|
+
} else {
|
|
102
|
+
if (!continueSet.has(child.type.name)) {
|
|
103
|
+
runCounter = 0;
|
|
104
|
+
}
|
|
105
|
+
walk(child, childPos, depth, insideListItem);
|
|
106
|
+
}
|
|
107
|
+
childOffset += child.nodeSize;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
92
110
|
function walk(node, pos, depth, insideListItem) {
|
|
93
111
|
if (node.type.name === "orderedList") {
|
|
94
|
-
walkOrderedList(node, pos, depth);
|
|
112
|
+
walkOrderedList(node, pos, depth, 0);
|
|
95
113
|
return;
|
|
96
114
|
}
|
|
97
115
|
if (insideListItem && !descendThroughContainers) return;
|
|
98
116
|
if (!node.isBlock || node.isLeaf) return;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
node.forEach((child) => {
|
|
102
|
-
walk(child, offset + childOffset, depth, insideListItem);
|
|
103
|
-
childOffset += child.nodeSize;
|
|
104
|
-
});
|
|
117
|
+
const childrenStart = pos + (node.type.name === "doc" ? 0 : 1);
|
|
118
|
+
iterateChildren(node, childrenStart, depth, insideListItem);
|
|
105
119
|
}
|
|
106
|
-
function walkOrderedList(node, pos, depth) {
|
|
120
|
+
function walkOrderedList(node, pos, depth, startCounter) {
|
|
107
121
|
const offset = pos + 1;
|
|
108
|
-
let counter =
|
|
122
|
+
let counter = startCounter;
|
|
109
123
|
let childOffset = 0;
|
|
110
124
|
node.forEach((child) => {
|
|
111
125
|
if (child.type.name !== "listItem") {
|
|
@@ -134,13 +148,10 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
|
|
|
134
148
|
}, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
|
|
135
149
|
);
|
|
136
150
|
}
|
|
137
|
-
|
|
138
|
-
child.forEach((grandchild) => {
|
|
139
|
-
walk(grandchild, grandOffset, depth + 1, true);
|
|
140
|
-
grandOffset += grandchild.nodeSize;
|
|
141
|
-
});
|
|
151
|
+
iterateChildren(child, itemPos + 1, depth + 1, true);
|
|
142
152
|
childOffset += child.nodeSize;
|
|
143
153
|
});
|
|
154
|
+
return counter;
|
|
144
155
|
}
|
|
145
156
|
walk(doc, 0, 0, false);
|
|
146
157
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
package/dist/tiptap.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/strategies.ts","../src/plugin.ts","../src/tiptap.ts"],"names":["PluginKey","Plugin","Decoration","DecorationSet","Extension"],"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;A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AC7C,QAAA,WAAA,IAAe,UAAA,CAAW,QAAA;AAAA,MAC5B,CAAC,CAAA;AACD,MAAA,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AAAA,EACH;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;AC3IO,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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);\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): DecorationSet {\n const decorations: Decoration[] = [];\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n walkOrderedList(node, pos, depth);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const offset = pos + (node.type.name === 'doc' ? 0 : 1);\n let childOffset = 0;\n node.forEach((child: any) => {\n walk(child, offset + childOffset, depth, insideListItem);\n childOffset += child.nodeSize;\n });\n }\n\n function walkOrderedList(node: any, pos: number, depth: number) {\n const offset = pos + 1;\n let counter = 0;\n let childOffset = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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 let grandOffset = itemPos + 1;\n child.forEach((grandchild: any) => {\n walk(grandchild, grandOffset, depth + 1, true);\n grandOffset += grandchild.nodeSize;\n });\n childOffset += child.nodeSize;\n });\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":["PluginKey","Plugin","Decoration","DecorationSet","Extension"],"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,EAA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ACnB,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,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;ACpLO,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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\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): 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 node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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"]}
|
package/dist/tiptap.d.cts
CHANGED
package/dist/tiptap.d.ts
CHANGED
package/dist/tiptap.js
CHANGED
|
@@ -65,15 +65,16 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
65
65
|
const strategy = options.strategy ?? alphanumericStrategy;
|
|
66
66
|
const descendThroughContainers = options.descendThroughContainers ?? true;
|
|
67
67
|
const renderMarkerInline = options.renderMarkerInline ?? false;
|
|
68
|
+
const continueAcrossNodeTypes = options.continueAcrossNodeTypes ?? [];
|
|
68
69
|
return new Plugin({
|
|
69
70
|
key: OUTLINE_NUMBERING_KEY,
|
|
70
71
|
state: {
|
|
71
72
|
init(_, { doc }) {
|
|
72
|
-
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
73
|
+
return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
73
74
|
},
|
|
74
75
|
apply(tr, decorationSet) {
|
|
75
76
|
if (tr.docChanged) {
|
|
76
|
-
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);
|
|
77
|
+
return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);
|
|
77
78
|
}
|
|
78
79
|
return decorationSet.map(tr.mapping, tr.doc);
|
|
79
80
|
}
|
|
@@ -85,25 +86,38 @@ function outlineNumberingPlugin(options = {}) {
|
|
|
85
86
|
}
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false) {
|
|
89
|
+
function computeDecorations(doc, strategy, descendThroughContainers = true, renderMarkerInline = false, continueAcrossNodeTypes = []) {
|
|
89
90
|
const decorations = [];
|
|
91
|
+
const continueSet = new Set(continueAcrossNodeTypes);
|
|
92
|
+
function iterateChildren(parent, parentChildrenStart, depth, insideListItem) {
|
|
93
|
+
let childOffset = 0;
|
|
94
|
+
let runCounter = 0;
|
|
95
|
+
parent.forEach((child) => {
|
|
96
|
+
const childPos = parentChildrenStart + childOffset;
|
|
97
|
+
if (child.type.name === "orderedList") {
|
|
98
|
+
runCounter = walkOrderedList(child, childPos, depth, runCounter);
|
|
99
|
+
} else {
|
|
100
|
+
if (!continueSet.has(child.type.name)) {
|
|
101
|
+
runCounter = 0;
|
|
102
|
+
}
|
|
103
|
+
walk(child, childPos, depth, insideListItem);
|
|
104
|
+
}
|
|
105
|
+
childOffset += child.nodeSize;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
90
108
|
function walk(node, pos, depth, insideListItem) {
|
|
91
109
|
if (node.type.name === "orderedList") {
|
|
92
|
-
walkOrderedList(node, pos, depth);
|
|
110
|
+
walkOrderedList(node, pos, depth, 0);
|
|
93
111
|
return;
|
|
94
112
|
}
|
|
95
113
|
if (insideListItem && !descendThroughContainers) return;
|
|
96
114
|
if (!node.isBlock || node.isLeaf) return;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
node.forEach((child) => {
|
|
100
|
-
walk(child, offset + childOffset, depth, insideListItem);
|
|
101
|
-
childOffset += child.nodeSize;
|
|
102
|
-
});
|
|
115
|
+
const childrenStart = pos + (node.type.name === "doc" ? 0 : 1);
|
|
116
|
+
iterateChildren(node, childrenStart, depth, insideListItem);
|
|
103
117
|
}
|
|
104
|
-
function walkOrderedList(node, pos, depth) {
|
|
118
|
+
function walkOrderedList(node, pos, depth, startCounter) {
|
|
105
119
|
const offset = pos + 1;
|
|
106
|
-
let counter =
|
|
120
|
+
let counter = startCounter;
|
|
107
121
|
let childOffset = 0;
|
|
108
122
|
node.forEach((child) => {
|
|
109
123
|
if (child.type.name !== "listItem") {
|
|
@@ -132,13 +146,10 @@ function computeDecorations(doc, strategy, descendThroughContainers = true, rend
|
|
|
132
146
|
}, { side: -1, key: `outline-marker-${depth}-${counter}-${markerText}` })
|
|
133
147
|
);
|
|
134
148
|
}
|
|
135
|
-
|
|
136
|
-
child.forEach((grandchild) => {
|
|
137
|
-
walk(grandchild, grandOffset, depth + 1, true);
|
|
138
|
-
grandOffset += grandchild.nodeSize;
|
|
139
|
-
});
|
|
149
|
+
iterateChildren(child, itemPos + 1, depth + 1, true);
|
|
140
150
|
childOffset += child.nodeSize;
|
|
141
151
|
});
|
|
152
|
+
return counter;
|
|
142
153
|
}
|
|
143
154
|
walk(doc, 0, 0, false);
|
|
144
155
|
return DecorationSet.create(doc, decorations);
|
package/dist/tiptap.js.map
CHANGED
|
@@ -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,IA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,EACH;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAO,aAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C;;;AC3IO,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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline);\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): DecorationSet {\n const decorations: Decoration[] = [];\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n walkOrderedList(node, pos, depth);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const offset = pos + (node.type.name === 'doc' ? 0 : 1);\n let childOffset = 0;\n node.forEach((child: any) => {\n walk(child, offset + childOffset, depth, insideListItem);\n childOffset += child.nodeSize;\n });\n }\n\n function walkOrderedList(node: any, pos: number, depth: number) {\n const offset = pos + 1;\n let counter = 0;\n let childOffset = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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 let grandOffset = itemPos + 1;\n child.forEach((grandchild: any) => {\n walk(grandchild, grandOffset, depth + 1, true);\n grandOffset += grandchild.nodeSize;\n });\n childOffset += child.nodeSize;\n });\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;AACb,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,MAAM,CAAA,IAAK,KAAA,EAAO;AACnC,IAAA,OAAO,KAAK,KAAA,EAAO;AACjB,MAAA,MAAA,IAAU,MAAA;AACV,MAAA,CAAA,IAAK,KAAA;AAAA,IACP;AAAA,EACF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C1E;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;;;ACpLO,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\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\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers, renderMarkerInline, continueAcrossNodeTypes);\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): 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 node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bwthomas/outline-numbering",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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>",
|