@kedataindo/docflow-plugins 0.0.4 → 0.0.5
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/chunk-CLCSH4NX.js +1078 -0
- package/dist/chunk-MZZTJIFJ.js +1417 -0
- package/dist/citations.cjs +1458 -0
- package/dist/citations.d.cts +132 -0
- package/dist/citations.d.ts +132 -0
- package/dist/citations.js +18 -0
- package/dist/index.cjs +2553 -21
- package/dist/index.d.cts +215 -2
- package/dist/index.d.ts +215 -2
- package/dist/index.js +1127 -18
- package/package.json +26 -9
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { CslItemData } from '@kedataindo/docflow-core';
|
|
2
|
+
|
|
3
|
+
type CitationMode = 'normal' | 'author-only' | 'suppress-author';
|
|
4
|
+
/**
|
|
5
|
+
* Structured citation attributes stored on citation/footnote nodes. Nodes
|
|
6
|
+
* store references only — every rendered string is derived by the engine
|
|
7
|
+
* from CSL-JSON sources + the active CSL style (phase-6 plan §2 decision 1).
|
|
8
|
+
*/
|
|
9
|
+
interface CitationAttrs {
|
|
10
|
+
sourceId: string | null;
|
|
11
|
+
locator?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
mode?: CitationMode;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
suffix?: string;
|
|
16
|
+
}
|
|
17
|
+
interface CiteEngineOptions {
|
|
18
|
+
sources?: CslItemData[];
|
|
19
|
+
style?: string;
|
|
20
|
+
}
|
|
21
|
+
interface CitationCluster {
|
|
22
|
+
citationId: string;
|
|
23
|
+
attrs: CitationAttrs;
|
|
24
|
+
}
|
|
25
|
+
type ChangeListener = () => void;
|
|
26
|
+
/** Stable, unique-enough id for a citation cluster instance in a document. */
|
|
27
|
+
declare function nextCitationId(): string;
|
|
28
|
+
declare function sanitizeCiteprocHtml(html: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Document-scoped citation engine. Wraps citeproc-js: holds the CSL-JSON
|
|
31
|
+
* source map + active style, recomputes ALL clusters in document order on
|
|
32
|
+
* every change (correct ibid./short-form handling for note styles), and
|
|
33
|
+
* emits a single 'change' so every node view repaints from one source of
|
|
34
|
+
* truth (phase-6 plan §2 decision 2).
|
|
35
|
+
*
|
|
36
|
+
* The engine is plain TS — no editor/DOM imports — so it is unit-testable
|
|
37
|
+
* headlessly and reusable from any host.
|
|
38
|
+
*/
|
|
39
|
+
declare class CiteEngine {
|
|
40
|
+
private sources;
|
|
41
|
+
private style;
|
|
42
|
+
private clusters;
|
|
43
|
+
private order;
|
|
44
|
+
private rendered;
|
|
45
|
+
private bibliography;
|
|
46
|
+
private listeners;
|
|
47
|
+
constructor(options?: CiteEngineOptions);
|
|
48
|
+
getStyle(): string;
|
|
49
|
+
/** 'note' styles (Chicago notes-bib) cite via footnotes; 'in-text' cite inline. */
|
|
50
|
+
isNoteStyle(): boolean;
|
|
51
|
+
getSource(id: string): CslItemData | undefined;
|
|
52
|
+
getSourceIds(): string[];
|
|
53
|
+
getCitedSourceIds(): string[];
|
|
54
|
+
/** Live style switch: reload the CSL, recompute everything, repaint (6A-7). */
|
|
55
|
+
setStyle(styleId: string): void;
|
|
56
|
+
updateSources(sources: CslItemData[], emit?: boolean): void;
|
|
57
|
+
onChange(cb: ChangeListener): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the cluster registry with the current document state, in
|
|
60
|
+
* document order. The caller (editor sync) walks the PM doc; the engine
|
|
61
|
+
* recomputes only when the ordered signature actually changed.
|
|
62
|
+
*/
|
|
63
|
+
syncCitations(ordered: CitationCluster[]): boolean;
|
|
64
|
+
private lastSignature;
|
|
65
|
+
/** Last computed in-text/note text for a cluster ('' when unknown/missing). */
|
|
66
|
+
renderCluster(citationId: string): string;
|
|
67
|
+
/** Bibliography entries (citeproc-sorted), sanitized HTML strings. */
|
|
68
|
+
getBibliography(): string[];
|
|
69
|
+
private emitChange;
|
|
70
|
+
/**
|
|
71
|
+
* Rebuild a fresh CSL.Engine and replay all clusters in document order.
|
|
72
|
+
* citeproc is stateful (ibid., subsequent-short forms), so a full ordered
|
|
73
|
+
* replay is the only reliable way to keep every cluster consistent after
|
|
74
|
+
* any edit — the same derived-view pattern used for pagination/collab.
|
|
75
|
+
*/
|
|
76
|
+
private recompute;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Pure citation-node spec builder — NO tiptap imports. Lives apart from
|
|
81
|
+
* `citation.ts` so the standalone `citations.ts` entrypoint (server-side
|
|
82
|
+
* export bundle, see `apps/server/src/routes/export.ts`) can re-export it
|
|
83
|
+
* WITHOUT pulling the editor extension graph into the server bundle.
|
|
84
|
+
*
|
|
85
|
+
* Two consumers:
|
|
86
|
+
* - `citation.ts` `insertCitationWithSource` (dispatches its OWN transaction
|
|
87
|
+
* per interactive insert, Phase 6 behavior unchanged).
|
|
88
|
+
* - The 7E-4 sidebar content-array insert path, which builds N specs and
|
|
89
|
+
* dispatches ONCE via `view.dispatch(tr.insertContent(array))` (the plan
|
|
90
|
+
* §2 decision 6 — N markers must NOT become N transactions / N Yjs
|
|
91
|
+
* history entries).
|
|
92
|
+
*
|
|
93
|
+
* The helper is the single source of truth for the note-vs-inline branching
|
|
94
|
+
* so the sidebar does not duplicate it.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
type CitationNodeSpec = {
|
|
98
|
+
type: 'footnote' | 'citation';
|
|
99
|
+
attrs: Record<string, unknown>;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Build ONE citation node spec (inline `citation` or note-style `footnote`)
|
|
103
|
+
* WITHOUT dispatching. Returns `null` only if the engine is missing the
|
|
104
|
+
* schema primitive — `insertCitationWithSource` additionally guards against
|
|
105
|
+
* `editor.schema.nodes['footnote']` being absent since the helper itself
|
|
106
|
+
* cannot reach the schema.
|
|
107
|
+
*
|
|
108
|
+
* PURE: takes the engine + attrs, returns a node spec, no editor mutation.
|
|
109
|
+
*/
|
|
110
|
+
declare function buildCitationNodes(engine: CiteEngine, attrs: {
|
|
111
|
+
sourceId: string;
|
|
112
|
+
locator?: string;
|
|
113
|
+
}): CitationNodeSpec;
|
|
114
|
+
|
|
115
|
+
interface CslStyleInfo {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
/** 'note' styles render citations as footnotes; 'in-text' render inline. */
|
|
119
|
+
category: 'note' | 'in-text';
|
|
120
|
+
xml: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* CSL styles bundled with the citation engine. Bundling (instead of runtime
|
|
124
|
+
* fetch) keeps the editor standalone/offline-capable — the same guarantee the
|
|
125
|
+
* embedded source snapshot provides (see phase-6 plan §2 decision 5).
|
|
126
|
+
*/
|
|
127
|
+
declare const CSL_STYLES: Record<string, CslStyleInfo>;
|
|
128
|
+
declare const DEFAULT_CSL_STYLE = "chicago-notes-bibliography";
|
|
129
|
+
/** The single bundled locale. Multi-locale rendering is deferred (phase 6 §7). */
|
|
130
|
+
declare const CSL_LOCALE_EN_US: string;
|
|
131
|
+
|
|
132
|
+
export { CSL_LOCALE_EN_US, CSL_STYLES, type CitationAttrs, type CitationCluster, type CitationMode, CiteEngine, type CiteEngineOptions, type CslStyleInfo, DEFAULT_CSL_STYLE, buildCitationNodes, nextCitationId, sanitizeCiteprocHtml };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { CslItemData } from '@kedataindo/docflow-core';
|
|
2
|
+
|
|
3
|
+
type CitationMode = 'normal' | 'author-only' | 'suppress-author';
|
|
4
|
+
/**
|
|
5
|
+
* Structured citation attributes stored on citation/footnote nodes. Nodes
|
|
6
|
+
* store references only — every rendered string is derived by the engine
|
|
7
|
+
* from CSL-JSON sources + the active CSL style (phase-6 plan §2 decision 1).
|
|
8
|
+
*/
|
|
9
|
+
interface CitationAttrs {
|
|
10
|
+
sourceId: string | null;
|
|
11
|
+
locator?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
mode?: CitationMode;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
suffix?: string;
|
|
16
|
+
}
|
|
17
|
+
interface CiteEngineOptions {
|
|
18
|
+
sources?: CslItemData[];
|
|
19
|
+
style?: string;
|
|
20
|
+
}
|
|
21
|
+
interface CitationCluster {
|
|
22
|
+
citationId: string;
|
|
23
|
+
attrs: CitationAttrs;
|
|
24
|
+
}
|
|
25
|
+
type ChangeListener = () => void;
|
|
26
|
+
/** Stable, unique-enough id for a citation cluster instance in a document. */
|
|
27
|
+
declare function nextCitationId(): string;
|
|
28
|
+
declare function sanitizeCiteprocHtml(html: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Document-scoped citation engine. Wraps citeproc-js: holds the CSL-JSON
|
|
31
|
+
* source map + active style, recomputes ALL clusters in document order on
|
|
32
|
+
* every change (correct ibid./short-form handling for note styles), and
|
|
33
|
+
* emits a single 'change' so every node view repaints from one source of
|
|
34
|
+
* truth (phase-6 plan §2 decision 2).
|
|
35
|
+
*
|
|
36
|
+
* The engine is plain TS — no editor/DOM imports — so it is unit-testable
|
|
37
|
+
* headlessly and reusable from any host.
|
|
38
|
+
*/
|
|
39
|
+
declare class CiteEngine {
|
|
40
|
+
private sources;
|
|
41
|
+
private style;
|
|
42
|
+
private clusters;
|
|
43
|
+
private order;
|
|
44
|
+
private rendered;
|
|
45
|
+
private bibliography;
|
|
46
|
+
private listeners;
|
|
47
|
+
constructor(options?: CiteEngineOptions);
|
|
48
|
+
getStyle(): string;
|
|
49
|
+
/** 'note' styles (Chicago notes-bib) cite via footnotes; 'in-text' cite inline. */
|
|
50
|
+
isNoteStyle(): boolean;
|
|
51
|
+
getSource(id: string): CslItemData | undefined;
|
|
52
|
+
getSourceIds(): string[];
|
|
53
|
+
getCitedSourceIds(): string[];
|
|
54
|
+
/** Live style switch: reload the CSL, recompute everything, repaint (6A-7). */
|
|
55
|
+
setStyle(styleId: string): void;
|
|
56
|
+
updateSources(sources: CslItemData[], emit?: boolean): void;
|
|
57
|
+
onChange(cb: ChangeListener): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the cluster registry with the current document state, in
|
|
60
|
+
* document order. The caller (editor sync) walks the PM doc; the engine
|
|
61
|
+
* recomputes only when the ordered signature actually changed.
|
|
62
|
+
*/
|
|
63
|
+
syncCitations(ordered: CitationCluster[]): boolean;
|
|
64
|
+
private lastSignature;
|
|
65
|
+
/** Last computed in-text/note text for a cluster ('' when unknown/missing). */
|
|
66
|
+
renderCluster(citationId: string): string;
|
|
67
|
+
/** Bibliography entries (citeproc-sorted), sanitized HTML strings. */
|
|
68
|
+
getBibliography(): string[];
|
|
69
|
+
private emitChange;
|
|
70
|
+
/**
|
|
71
|
+
* Rebuild a fresh CSL.Engine and replay all clusters in document order.
|
|
72
|
+
* citeproc is stateful (ibid., subsequent-short forms), so a full ordered
|
|
73
|
+
* replay is the only reliable way to keep every cluster consistent after
|
|
74
|
+
* any edit — the same derived-view pattern used for pagination/collab.
|
|
75
|
+
*/
|
|
76
|
+
private recompute;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Pure citation-node spec builder — NO tiptap imports. Lives apart from
|
|
81
|
+
* `citation.ts` so the standalone `citations.ts` entrypoint (server-side
|
|
82
|
+
* export bundle, see `apps/server/src/routes/export.ts`) can re-export it
|
|
83
|
+
* WITHOUT pulling the editor extension graph into the server bundle.
|
|
84
|
+
*
|
|
85
|
+
* Two consumers:
|
|
86
|
+
* - `citation.ts` `insertCitationWithSource` (dispatches its OWN transaction
|
|
87
|
+
* per interactive insert, Phase 6 behavior unchanged).
|
|
88
|
+
* - The 7E-4 sidebar content-array insert path, which builds N specs and
|
|
89
|
+
* dispatches ONCE via `view.dispatch(tr.insertContent(array))` (the plan
|
|
90
|
+
* §2 decision 6 — N markers must NOT become N transactions / N Yjs
|
|
91
|
+
* history entries).
|
|
92
|
+
*
|
|
93
|
+
* The helper is the single source of truth for the note-vs-inline branching
|
|
94
|
+
* so the sidebar does not duplicate it.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
type CitationNodeSpec = {
|
|
98
|
+
type: 'footnote' | 'citation';
|
|
99
|
+
attrs: Record<string, unknown>;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Build ONE citation node spec (inline `citation` or note-style `footnote`)
|
|
103
|
+
* WITHOUT dispatching. Returns `null` only if the engine is missing the
|
|
104
|
+
* schema primitive — `insertCitationWithSource` additionally guards against
|
|
105
|
+
* `editor.schema.nodes['footnote']` being absent since the helper itself
|
|
106
|
+
* cannot reach the schema.
|
|
107
|
+
*
|
|
108
|
+
* PURE: takes the engine + attrs, returns a node spec, no editor mutation.
|
|
109
|
+
*/
|
|
110
|
+
declare function buildCitationNodes(engine: CiteEngine, attrs: {
|
|
111
|
+
sourceId: string;
|
|
112
|
+
locator?: string;
|
|
113
|
+
}): CitationNodeSpec;
|
|
114
|
+
|
|
115
|
+
interface CslStyleInfo {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
/** 'note' styles render citations as footnotes; 'in-text' render inline. */
|
|
119
|
+
category: 'note' | 'in-text';
|
|
120
|
+
xml: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* CSL styles bundled with the citation engine. Bundling (instead of runtime
|
|
124
|
+
* fetch) keeps the editor standalone/offline-capable — the same guarantee the
|
|
125
|
+
* embedded source snapshot provides (see phase-6 plan §2 decision 5).
|
|
126
|
+
*/
|
|
127
|
+
declare const CSL_STYLES: Record<string, CslStyleInfo>;
|
|
128
|
+
declare const DEFAULT_CSL_STYLE = "chicago-notes-bibliography";
|
|
129
|
+
/** The single bundled locale. Multi-locale rendering is deferred (phase 6 §7). */
|
|
130
|
+
declare const CSL_LOCALE_EN_US: string;
|
|
131
|
+
|
|
132
|
+
export { CSL_LOCALE_EN_US, CSL_STYLES, type CitationAttrs, type CitationCluster, type CitationMode, CiteEngine, type CiteEngineOptions, type CslStyleInfo, DEFAULT_CSL_STYLE, buildCitationNodes, nextCitationId, sanitizeCiteprocHtml };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CSL_LOCALE_EN_US,
|
|
3
|
+
CSL_STYLES,
|
|
4
|
+
CiteEngine,
|
|
5
|
+
DEFAULT_CSL_STYLE,
|
|
6
|
+
buildCitationNodes,
|
|
7
|
+
nextCitationId,
|
|
8
|
+
sanitizeCiteprocHtml
|
|
9
|
+
} from "./chunk-MZZTJIFJ.js";
|
|
10
|
+
export {
|
|
11
|
+
CSL_LOCALE_EN_US,
|
|
12
|
+
CSL_STYLES,
|
|
13
|
+
CiteEngine,
|
|
14
|
+
DEFAULT_CSL_STYLE,
|
|
15
|
+
buildCitationNodes,
|
|
16
|
+
nextCitationId,
|
|
17
|
+
sanitizeCiteprocHtml
|
|
18
|
+
};
|