markdown-komponents 0.1.0 → 0.2.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/kotlin-kotlin-stdlib.mjs +1451 -662
- package/kotlin-kotlin-stdlib.mjs.map +1 -1
- package/markdown-komponents.d.mts +200 -0
- package/markdown-komponents.mjs +1580 -685
- package/markdown-komponents.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Hand-written TypeScript declarations for this package's public API.
|
|
2
|
+
//
|
|
3
|
+
// Kotlin/JS's own `generateTypeScriptDefinitions()` was tried first, but its generated `extends`
|
|
4
|
+
// clauses are broken for any exported class whose supertype chain touches an *external* class
|
|
5
|
+
// (this library's entire custom-element hierarchy is rooted in `HTMLElement`, and
|
|
6
|
+
// `TsStackMarkdownRenderer` is rooted in `@ts-stack/markdown`'s `Renderer`) — the emitted reference
|
|
7
|
+
// to that supertype's `$metadata$` companion doesn't resolve, and members overriding the external
|
|
8
|
+
// base are silently dropped from the declaration. Patching that generator output turned out to be
|
|
9
|
+
// more fragile than just declaring the (small, stable) consumer-facing surface directly.
|
|
10
|
+
//
|
|
11
|
+
// Keep this in sync with the real Kotlin source under src/jsMain/kotlin — it is NOT derived from it
|
|
12
|
+
// automatically. `@JsExport` in the Kotlin source is what makes these actually exist as runtime
|
|
13
|
+
// bindings; this file only describes their shape to TypeScript.
|
|
14
|
+
|
|
15
|
+
export interface MarkdownElement {
|
|
16
|
+
getMarkdown(): string;
|
|
17
|
+
|
|
18
|
+
/** True for elements that cannot live inside other blocks, but must be a direct child of markdown-document. */
|
|
19
|
+
readonly mustBeDirectChildOfDocument: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MarkdownRenderer {
|
|
23
|
+
heading(text: string, level: number, id: string | null | undefined): string;
|
|
24
|
+
paragraph(text: string): string;
|
|
25
|
+
blockquote(quote: string): string;
|
|
26
|
+
html(html: string): string;
|
|
27
|
+
hr(): string;
|
|
28
|
+
list(body: string, ordered: boolean): string;
|
|
29
|
+
listItem(text: string): string;
|
|
30
|
+
taskListItem(text: string, checked: boolean): string;
|
|
31
|
+
table(header: string, body: string): string;
|
|
32
|
+
tableRow(content: string): string;
|
|
33
|
+
tableHeaderRow(content: string): string;
|
|
34
|
+
tableCell(content: string): string;
|
|
35
|
+
tableHeaderCell(content: string): string;
|
|
36
|
+
code(code: string, lang: string | null | undefined, id: string | null | undefined): string;
|
|
37
|
+
codeSpan(text: string): string;
|
|
38
|
+
strong(text: string): string;
|
|
39
|
+
emphasis(text: string): string;
|
|
40
|
+
strikethrough(text: string): string;
|
|
41
|
+
link(href: string, title: string | null | undefined, text: string): string;
|
|
42
|
+
image(href: string, title: string | null | undefined, text: string): string;
|
|
43
|
+
toc(): string;
|
|
44
|
+
custom(tag: string, content: string): string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The library's own default `MarkdownRenderer`: renders straight to this library's `<markdown-*>` custom elements. */
|
|
48
|
+
export class MarkdownComponentsRenderer implements MarkdownRenderer {
|
|
49
|
+
constructor();
|
|
50
|
+
heading(text: string, level: number, id: string | null | undefined): string;
|
|
51
|
+
paragraph(text: string): string;
|
|
52
|
+
blockquote(quote: string): string;
|
|
53
|
+
html(html: string): string;
|
|
54
|
+
hr(): string;
|
|
55
|
+
list(body: string, ordered: boolean): string;
|
|
56
|
+
listItem(text: string): string;
|
|
57
|
+
taskListItem(text: string, checked: boolean): string;
|
|
58
|
+
table(header: string, body: string): string;
|
|
59
|
+
tableRow(content: string): string;
|
|
60
|
+
tableHeaderRow(content: string): string;
|
|
61
|
+
tableCell(content: string): string;
|
|
62
|
+
tableHeaderCell(content: string): string;
|
|
63
|
+
code(code: string, lang: string | null | undefined, id: string | null | undefined): string;
|
|
64
|
+
codeSpan(text: string): string;
|
|
65
|
+
strong(text: string): string;
|
|
66
|
+
emphasis(text: string): string;
|
|
67
|
+
strikethrough(text: string): string;
|
|
68
|
+
link(href: string, title: string | null | undefined, text: string): string;
|
|
69
|
+
image(href: string, title: string | null | undefined, text: string): string;
|
|
70
|
+
toc(): string;
|
|
71
|
+
custom(tag: string, content: string): string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Adapts `@ts-stack/markdown`'s token-driven `Renderer` callback API to this library's
|
|
76
|
+
* `MarkdownRenderer` contract. Subclass this (not `MarkdownRenderer` directly) when you need both
|
|
77
|
+
* an overridable per-construct method (e.g. `image()`) *and* ts-stack's `options` hook (e.g.
|
|
78
|
+
* `options.escape`) from one place — pass an instance to `parseMarkdownWithTsStackRenderer`.
|
|
79
|
+
*/
|
|
80
|
+
export class TsStackMarkdownRenderer {
|
|
81
|
+
constructor(delegate?: MarkdownRenderer);
|
|
82
|
+
protected readonly options: { escape?: (html: string, encode: boolean) => string };
|
|
83
|
+
/** Also called directly by this library's fenced-code-with-explicit-id block rule. */
|
|
84
|
+
codeWithAnchor(code: string, lang: string | null | undefined, id: string | null | undefined, escaped?: boolean | null): string;
|
|
85
|
+
code(code: string, lang: string | null | undefined, escaped: boolean | null | undefined, meta: string | null | undefined): string;
|
|
86
|
+
blockquote(quote: string): string;
|
|
87
|
+
html(html: string): string;
|
|
88
|
+
heading(text: string, level: number, raw: string): string;
|
|
89
|
+
hr(): string;
|
|
90
|
+
list(body: string, ordered: boolean | null | undefined): string;
|
|
91
|
+
listitem(text: string): string;
|
|
92
|
+
paragraph(text: string): string;
|
|
93
|
+
table(header: string, body: string): string;
|
|
94
|
+
tablerow(content: string): string;
|
|
95
|
+
tablecell(content: string, flags: any): string;
|
|
96
|
+
strong(text: string): string;
|
|
97
|
+
em(text: string): string;
|
|
98
|
+
codespan(text: string): string;
|
|
99
|
+
del(text: string): string;
|
|
100
|
+
link(href: string, title: string | null | undefined, text: string): string;
|
|
101
|
+
image(href: string, title: string | null | undefined, text: string): string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Parses `markdown` using `@ts-stack/markdown`, driving `renderer` (this library's own components
|
|
106
|
+
* by default) to produce the resulting `<markdown-*>` HTML. Assignable directly to
|
|
107
|
+
* `markdownDocument.parser`, e.g. `doc.parser = parseMarkdown`. For a renderer that also needs
|
|
108
|
+
* ts-stack's `options` hook, use `parseMarkdownWithTsStackRenderer` instead.
|
|
109
|
+
*/
|
|
110
|
+
export function parseMarkdown(markdown: string, renderer?: MarkdownRenderer): string;
|
|
111
|
+
|
|
112
|
+
/** Like `parseMarkdown`, but for a `renderer` that needs ts-stack's `options` hook alongside overriding per-construct methods. */
|
|
113
|
+
export function parseMarkdownWithTsStackRenderer(markdown: string, renderer: TsStackMarkdownRenderer): string;
|
|
114
|
+
|
|
115
|
+
export abstract class BaseMarkdownDocument extends HTMLElement {
|
|
116
|
+
/**
|
|
117
|
+
* Converts markdown text to the HTML string of `<markdown-*>` tags this element sets as
|
|
118
|
+
* `innerHTML`. Defaults to a passthrough that just wraps the text in a paragraph; plug in
|
|
119
|
+
* `parseMarkdown`/`parseMarkdownWithTsStackRenderer`, or any `(markdown: string) => string`.
|
|
120
|
+
*/
|
|
121
|
+
parser: (markdown: string) => string;
|
|
122
|
+
markdown: string;
|
|
123
|
+
toolbar: Element | null;
|
|
124
|
+
selectionRoot: Document;
|
|
125
|
+
onLinkClick: ((url: string) => void) | null;
|
|
126
|
+
autoNormalize: boolean;
|
|
127
|
+
readonly currentSelection: Selection | null;
|
|
128
|
+
readonly editable: boolean;
|
|
129
|
+
|
|
130
|
+
getSelection(): Selection | null;
|
|
131
|
+
contentLengthUntil(child: Node | null): number;
|
|
132
|
+
normalizeContent(): void;
|
|
133
|
+
contentLength(): number;
|
|
134
|
+
setToolbar(newToolbar: Element): void;
|
|
135
|
+
getMarkdown(): string;
|
|
136
|
+
getCurrentLeafBlock(): Element | null;
|
|
137
|
+
getLastLeafBlock(): Element | null;
|
|
138
|
+
onChange(): void;
|
|
139
|
+
|
|
140
|
+
makeBreak(): void;
|
|
141
|
+
makeBold(): void;
|
|
142
|
+
removeBold(): void;
|
|
143
|
+
wrapCurrentSelectionInNewElement(elementName: string): Element | null;
|
|
144
|
+
makeItalic(): void;
|
|
145
|
+
removeItalic(): void;
|
|
146
|
+
makeUnderline(): void;
|
|
147
|
+
makeStrike(): void;
|
|
148
|
+
removeStrike(): void;
|
|
149
|
+
makeCodeInline(): void;
|
|
150
|
+
listBulletedClick(): void;
|
|
151
|
+
listNumericClick(): void;
|
|
152
|
+
insertPhoto(url: string | null, text: string | null): void;
|
|
153
|
+
restoreStashedSelection(): void;
|
|
154
|
+
insertLink(): void;
|
|
155
|
+
header1Element(): void;
|
|
156
|
+
header2Element(): void;
|
|
157
|
+
header3Element(): void;
|
|
158
|
+
header4Element(): void;
|
|
159
|
+
header5Element(): void;
|
|
160
|
+
header6Element(): void;
|
|
161
|
+
pararaphElement(): void;
|
|
162
|
+
/** Reassignable wholesale (e.g. `doc.makeCodeBlock = () => {...}`) to fully replace the default behavior. */
|
|
163
|
+
makeCodeBlock(): void;
|
|
164
|
+
makeQuoteBlock(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** `<markdown-document>` */
|
|
168
|
+
export class MarkdownDocument extends BaseMarkdownDocument {}
|
|
169
|
+
|
|
170
|
+
/** `<markdown-editor>` — like `MarkdownDocument`, but with its own built-in toolbar. */
|
|
171
|
+
export class MarkdownEditor extends BaseMarkdownDocument {}
|
|
172
|
+
|
|
173
|
+
/** `<markdown-toolbar>` — opaque from the outside: only ever cast to and passed into `setToolbar()`. */
|
|
174
|
+
export class MarkdownToolbar extends HTMLElement {}
|
|
175
|
+
|
|
176
|
+
/** `<markdown-toc>` */
|
|
177
|
+
export class MarkdownToc extends HTMLElement {
|
|
178
|
+
markdownDocument: Element | null;
|
|
179
|
+
/** Rebuilds the table of contents from `markdownDocument`. Runs automatically when that property is set. */
|
|
180
|
+
refresh(): void;
|
|
181
|
+
getMarkdown(): string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** `<markdown-image>`. Open for subclassing to customize how an image renders, e.g. inlining a data URI differently. */
|
|
185
|
+
export class MarkdownImage extends HTMLElement implements MarkdownElement {
|
|
186
|
+
destination: string;
|
|
187
|
+
readonly mustBeDirectChildOfDocument: boolean;
|
|
188
|
+
/** Updates the shadow DOM to reflect current state. Override to customize how the image is displayed. */
|
|
189
|
+
protected render(): void;
|
|
190
|
+
setImageSrc(src: string): void;
|
|
191
|
+
getMarkdown(): string;
|
|
192
|
+
containsMarkdownTextContent(): boolean;
|
|
193
|
+
isDeletableAsAWhole(): boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** `<markdown-paragraph>` */
|
|
197
|
+
export class MarkdownParagraph extends HTMLElement {
|
|
198
|
+
getMarkdown(): string;
|
|
199
|
+
isEmpty(): boolean;
|
|
200
|
+
}
|