@monster-orange/den-ui 0.7.4 → 0.7.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/README.md +63 -0
- package/package.json +9 -1
- package/src/markdown-editor.css +230 -0
- package/src/markdown-editor.d.ts +187 -0
- package/src/markdown-editor.js +1122 -0
- package/src/report.d.ts +7 -1
- package/src/report.js +32 -2
- package/src/shell-html.d.ts +5 -0
- package/src/shell-html.js +43 -2
- package/src/shell.css +16 -0
- package/src/strings.js +58 -0
- package/src/whatsnew.js +13 -2
package/README.md
CHANGED
|
@@ -161,6 +161,13 @@ paste where the team tracks issues. A product with more (a preview, a
|
|
|
161
161
|
sign-in flow, drafts) gives `info`, `diagnostics`, `preview`, `send`,
|
|
162
162
|
`githubSend`, `githubPoll` and `saveDraft`; see the top of `report.js`.
|
|
163
163
|
|
|
164
|
+
Each of `info()`'s `repos` may say its `visibility` (`"public"`,
|
|
165
|
+
`"private"` or `"internal"`) and an `audience` (who can see it, as words).
|
|
166
|
+
A public repo, or one that doesn't say, gets the "Public repository" pill
|
|
167
|
+
and the "visible to everyone" warning above Send. A private or internal
|
|
168
|
+
one gets its own pill, the audience, and a quiet line instead of the
|
|
169
|
+
warning. Both follow the repo chosen in Review.
|
|
170
|
+
|
|
164
171
|
### Strings
|
|
165
172
|
|
|
166
173
|
`src/strings.js` (export `./strings`) exports `en`, `es` and `ja`: every
|
|
@@ -380,6 +387,60 @@ browser test, on the image (Den's real server on the demo distribution,
|
|
|
380
387
|
is `src/kit.d.ts`. A test compiles a consumer against them with
|
|
381
388
|
`--strict`.
|
|
382
389
|
|
|
390
|
+
## The Markdown editor (0.7.5)
|
|
391
|
+
|
|
392
|
+
`src/markdown-editor.js` and `src/markdown-editor.css` (exports
|
|
393
|
+
`./markdown-editor`, `./markdown-editor.css`): a Markdown field,
|
|
394
|
+
ported from an existing editor. CodeMirror 6 on the Markdown text: the
|
|
395
|
+
document is the string that is stored, character for character, and the
|
|
396
|
+
live preview is drawn in place, as decoration only (no preview pane,
|
|
397
|
+
never converted to HTML and back).
|
|
398
|
+
|
|
399
|
+
import { mountMarkdownEditor } from "@monster-orange/den-ui/markdown-editor";
|
|
400
|
+
// link markdown-editor.css after tokens.css
|
|
401
|
+
const ed = mountMarkdownEditor(el, {
|
|
402
|
+
value: "", onChange: (text) => save(text),
|
|
403
|
+
label: "Notes", // or labelledBy; describedBy for help
|
|
404
|
+
mode: "full", // "full": a toolbar, Enter is a new line,
|
|
405
|
+
// ⌘/Ctrl+Enter submits; "lite": a chat box,
|
|
406
|
+
// Enter sends, Shift+Enter is a new line
|
|
407
|
+
onSubmit, onEscape, onBlur, placeholder, maxLength, rows,
|
|
408
|
+
disabled, readOnly, required, invalid, lang, uiLang, nonce,
|
|
409
|
+
});
|
|
410
|
+
await ed.ready; // CodeMirror has taken over
|
|
411
|
+
ed.setValue(""); ed.focus(); ed.run("bold");
|
|
412
|
+
ed.insertBlock(text); ed.insertLinkTo(label, url); ed.replaceEnd(n, text);
|
|
413
|
+
ed.update({ disabled: true }); ed.destroy();
|
|
414
|
+
|
|
415
|
+
- **Lazy.** The module imports no CodeMirror. On mount it loads
|
|
416
|
+
`@codemirror/state`, `view`, `commands` and `@lezer/markdown` with
|
|
417
|
+
`import()`, so a bundler puts them in a chunk of their own, and a plain
|
|
418
|
+
textarea takes the typing until it arrives (its toolbar works too). The
|
|
419
|
+
editor then goes on from the textarea's text, focus, caret and
|
|
420
|
+
selection. `loadMarkdownEditor()` warms the chunk early. The packages
|
|
421
|
+
are the kit's `dependencies`, pinned exactly. Den's own pages don't
|
|
422
|
+
load it.
|
|
423
|
+
- **The preview.** On a line the caret is not on, the markers hide and
|
|
424
|
+
the words show formatted; `- ` becomes a bullet. On the line being
|
|
425
|
+
edited every marker stays, muted. CommonMark without setext headings,
|
|
426
|
+
indented code, HTML, entities, reference links, images and autolinks,
|
|
427
|
+
plus strikethrough; only an http(s) link is drawn as a link.
|
|
428
|
+
- **IME.** An Enter that belongs to a composition (`view.composing`,
|
|
429
|
+
`isComposing`, keyCode 229, or within 100 ms of `compositionend`, as
|
|
430
|
+
Safari sends it) never sends, submits or adds a line. The preview is
|
|
431
|
+
frozen while a composition is open, and `maxLength` never cuts one.
|
|
432
|
+
- **Shortcuts.** ⌘/Ctrl+B, I, E (code), K (link), ⇧X (strike); Enter in
|
|
433
|
+
a list or quote continues it, and on an empty item ends it.
|
|
434
|
+
- **Words.** The toolbar's are `kit.md.*` in strings.js (en, es, ja), in
|
|
435
|
+
`uiLang`, else `<html lang>`.
|
|
436
|
+
- **Touch sizes.** On `(pointer: coarse)` or below 720px the toolbar's
|
|
437
|
+
buttons are `--tap` (44×44px) and the text is 16px (no zoom on focus);
|
|
438
|
+
elsewhere 28px and 15px.
|
|
439
|
+
- **CSP.** CodeMirror writes its base styles into a `<style>`: under a
|
|
440
|
+
strict `style-src`, pass the page's `nonce`.
|
|
441
|
+
- The content element has `data-md-dirty` while it holds unsaved text
|
|
442
|
+
(for an update pill's `askFirst`).
|
|
443
|
+
|
|
383
444
|
## 0.7.1
|
|
384
445
|
|
|
385
446
|
The top bar's search sits in the same place in every product (issue 303).
|
|
@@ -511,6 +572,8 @@ button)`. A crumb left out of the list draws nothing, and no separator
|
|
|
511
572
|
on `<body>`: a heading, then the host's `items` as rows (`{ text, href?,
|
|
512
573
|
time?, read? }`) or the empty state. `bellPanelHtml(...)` takes `actions`
|
|
513
574
|
(buttons beside the heading), `lead`, `body` (the host's own rows),
|
|
575
|
+
`sections` (issue 101: `{ needs, earlier? }`, the rows of each; the kit
|
|
576
|
+
heads them "Needs you", always first, and "Earlier", in its own words),
|
|
514
577
|
`empty`, `after` and `foot`. A click on the bell toggles the panel.
|
|
515
578
|
Opening it focuses its first link or button. Esc closes it and focus goes
|
|
516
579
|
back to the bell, in Safari too (`focusBack` from `dialog.js`). A click
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monster-orange/den-ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Den's UI kit: tokens, fonts and shared components, framework-free",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"./report.css": "./src/report.css",
|
|
35
35
|
"./busy.css": "./src/busy.css",
|
|
36
36
|
"./dialog.css": "./src/dialog.css",
|
|
37
|
+
"./markdown-editor": "./src/markdown-editor.js",
|
|
38
|
+
"./markdown-editor.css": "./src/markdown-editor.css",
|
|
37
39
|
"./inventory": {
|
|
38
40
|
"types": "./inventory/nav-inventory.d.ts",
|
|
39
41
|
"default": "./inventory/nav-inventory.js"
|
|
@@ -56,5 +58,11 @@
|
|
|
56
58
|
],
|
|
57
59
|
"bin": {
|
|
58
60
|
"den-ui-parity": "bin/den-ui-parity.mjs"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@codemirror/commands": "6.11.1",
|
|
64
|
+
"@codemirror/state": "6.7.6",
|
|
65
|
+
"@codemirror/view": "6.43.13",
|
|
66
|
+
"@lezer/markdown": "1.7.2"
|
|
59
67
|
}
|
|
60
68
|
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/* den-ui: the Markdown editor's look (markdown-editor.js). Tokens only, both
|
|
2
|
+
modes: no colour of its own. Linked, never injected. The box looks like a
|
|
3
|
+
text input (border, radius, the accent focus ring), so it sits in a form
|
|
4
|
+
unchanged. Safari: no flex gap on the editor itself, explicit
|
|
5
|
+
min-heights, -webkit-user-modify left to CodeMirror. Knobs, set on
|
|
6
|
+
.md-field: --md-min-height (full: from `rows`; lite: 48px) and
|
|
7
|
+
--md-max-height (full 360px, lite 200px). */
|
|
8
|
+
.md-field {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
background: var(--raised);
|
|
13
|
+
border: 1px solid var(--border-strong);
|
|
14
|
+
border-radius: var(--radius);
|
|
15
|
+
transition: border-color var(--dur-fast) var(--ease);
|
|
16
|
+
}
|
|
17
|
+
.md-field:hover {
|
|
18
|
+
border-color: var(--faint);
|
|
19
|
+
}
|
|
20
|
+
.md-field:focus-within {
|
|
21
|
+
border-color: var(--accent);
|
|
22
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
|
|
23
|
+
}
|
|
24
|
+
.md-field[data-invalid="true"] {
|
|
25
|
+
border-color: var(--bad);
|
|
26
|
+
}
|
|
27
|
+
.md-field[data-disabled="true"] {
|
|
28
|
+
background: var(--sunken);
|
|
29
|
+
color: var(--faint);
|
|
30
|
+
cursor: not-allowed;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.md-toolbar {
|
|
34
|
+
position: relative;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-wrap: wrap;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 2px;
|
|
39
|
+
padding: 4px 6px;
|
|
40
|
+
border-bottom: 1px solid var(--border);
|
|
41
|
+
}
|
|
42
|
+
.md-toolbar-sep {
|
|
43
|
+
width: 1px;
|
|
44
|
+
height: 18px;
|
|
45
|
+
margin: 0 4px;
|
|
46
|
+
background: var(--border);
|
|
47
|
+
}
|
|
48
|
+
.md-tool {
|
|
49
|
+
display: inline-flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: center;
|
|
52
|
+
width: 28px;
|
|
53
|
+
height: 28px;
|
|
54
|
+
padding: 0;
|
|
55
|
+
border: 0;
|
|
56
|
+
border-radius: var(--radius-button);
|
|
57
|
+
background: transparent;
|
|
58
|
+
color: var(--muted);
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
}
|
|
61
|
+
.md-tool:hover {
|
|
62
|
+
background: var(--sunken);
|
|
63
|
+
color: var(--text);
|
|
64
|
+
}
|
|
65
|
+
.md-tool:focus-visible {
|
|
66
|
+
outline: 2px solid var(--accent);
|
|
67
|
+
outline-offset: 1px;
|
|
68
|
+
}
|
|
69
|
+
.md-tool[disabled] {
|
|
70
|
+
opacity: 0.5;
|
|
71
|
+
cursor: not-allowed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* The editor and its plain-textarea stand-in share one metric, so the swap does not jump. */
|
|
75
|
+
.md-editor-host,
|
|
76
|
+
.md-fallback {
|
|
77
|
+
font-family: var(--sans);
|
|
78
|
+
font-size: 15px;
|
|
79
|
+
line-height: 1.5;
|
|
80
|
+
color: var(--text);
|
|
81
|
+
}
|
|
82
|
+
.md-fallback {
|
|
83
|
+
display: block;
|
|
84
|
+
width: 100%;
|
|
85
|
+
box-sizing: border-box;
|
|
86
|
+
padding: 10px 12px;
|
|
87
|
+
border: 0;
|
|
88
|
+
background: transparent;
|
|
89
|
+
resize: vertical;
|
|
90
|
+
font: inherit;
|
|
91
|
+
font-size: 15px;
|
|
92
|
+
line-height: 1.5;
|
|
93
|
+
color: var(--text);
|
|
94
|
+
}
|
|
95
|
+
.md-fallback:focus {
|
|
96
|
+
outline: none;
|
|
97
|
+
}
|
|
98
|
+
.md-fallback::placeholder {
|
|
99
|
+
color: var(--faint);
|
|
100
|
+
}
|
|
101
|
+
.md-field .md-fallback,
|
|
102
|
+
.md-field .md-editor-host .cm-content {
|
|
103
|
+
min-height: var(--md-min-height, 88px);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.md-editor-host .cm-editor {
|
|
107
|
+
background: transparent;
|
|
108
|
+
color: inherit;
|
|
109
|
+
}
|
|
110
|
+
.md-editor-host .cm-editor.cm-focused {
|
|
111
|
+
outline: none;
|
|
112
|
+
}
|
|
113
|
+
.md-editor-host .cm-scroller {
|
|
114
|
+
font-family: inherit;
|
|
115
|
+
line-height: inherit;
|
|
116
|
+
max-height: var(--md-max-height, 360px);
|
|
117
|
+
overflow: auto;
|
|
118
|
+
}
|
|
119
|
+
.md-editor-host .cm-content {
|
|
120
|
+
padding: 10px 12px;
|
|
121
|
+
caret-color: var(--text);
|
|
122
|
+
box-sizing: border-box;
|
|
123
|
+
}
|
|
124
|
+
.md-editor-host .cm-line {
|
|
125
|
+
padding: 0;
|
|
126
|
+
}
|
|
127
|
+
/* readable: the muted text passes contrast (faint is for marks) */
|
|
128
|
+
.md-editor-host .cm-placeholder {
|
|
129
|
+
color: var(--muted);
|
|
130
|
+
}
|
|
131
|
+
.md-editor-host .cm-cursor {
|
|
132
|
+
border-left-color: var(--text);
|
|
133
|
+
}
|
|
134
|
+
.md-editor-host .cm-selectionBackground,
|
|
135
|
+
.md-editor-host .cm-focused .cm-selectionBackground {
|
|
136
|
+
background: color-mix(in srgb, var(--accent) 20%, transparent);
|
|
137
|
+
}
|
|
138
|
+
.md-editor-host .cm-content[aria-disabled="true"] {
|
|
139
|
+
color: var(--faint);
|
|
140
|
+
cursor: not-allowed;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* The live preview (livePreview in markdown-editor.js). */
|
|
144
|
+
.md-strong {
|
|
145
|
+
font-weight: 700;
|
|
146
|
+
}
|
|
147
|
+
.md-em {
|
|
148
|
+
font-style: italic;
|
|
149
|
+
}
|
|
150
|
+
.md-del {
|
|
151
|
+
text-decoration: line-through;
|
|
152
|
+
}
|
|
153
|
+
.md-code {
|
|
154
|
+
font-family: var(--mono);
|
|
155
|
+
font-size: 0.92em;
|
|
156
|
+
padding: 0 0.2em;
|
|
157
|
+
border-radius: var(--radius-button);
|
|
158
|
+
background: var(--sunken);
|
|
159
|
+
}
|
|
160
|
+
.md-link {
|
|
161
|
+
color: var(--accent-text);
|
|
162
|
+
text-decoration: underline;
|
|
163
|
+
text-underline-offset: 2px;
|
|
164
|
+
}
|
|
165
|
+
.md-marker {
|
|
166
|
+
color: var(--faint);
|
|
167
|
+
}
|
|
168
|
+
.md-listmark {
|
|
169
|
+
color: var(--muted);
|
|
170
|
+
}
|
|
171
|
+
.md-bullet {
|
|
172
|
+
display: inline-block;
|
|
173
|
+
min-width: 0.8em;
|
|
174
|
+
color: var(--muted);
|
|
175
|
+
}
|
|
176
|
+
.md-h {
|
|
177
|
+
font-weight: 700;
|
|
178
|
+
}
|
|
179
|
+
.md-h1 {
|
|
180
|
+
font-size: 1.2em;
|
|
181
|
+
}
|
|
182
|
+
.md-h2 {
|
|
183
|
+
font-size: 1.1em;
|
|
184
|
+
}
|
|
185
|
+
.md-quote {
|
|
186
|
+
border-left: 3px solid var(--border-strong);
|
|
187
|
+
padding-left: 10px !important;
|
|
188
|
+
color: var(--muted);
|
|
189
|
+
}
|
|
190
|
+
.md-fence {
|
|
191
|
+
font-family: var(--mono);
|
|
192
|
+
font-size: 0.92em;
|
|
193
|
+
background: var(--sunken);
|
|
194
|
+
}
|
|
195
|
+
.md-hr {
|
|
196
|
+
color: var(--faint);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* The chat (mode "lite"): the composer row's own box. */
|
|
200
|
+
.md-lite {
|
|
201
|
+
min-width: 0;
|
|
202
|
+
}
|
|
203
|
+
.md-lite .md-editor-host .cm-content,
|
|
204
|
+
.md-lite .md-fallback {
|
|
205
|
+
min-height: var(--md-min-height, 48px);
|
|
206
|
+
}
|
|
207
|
+
/* the stand-in is the editor's height from its first frame: one row, no resize handle, a long placeholder clipped, never wrapped taller */
|
|
208
|
+
.md-lite .md-fallback {
|
|
209
|
+
resize: none;
|
|
210
|
+
overflow: hidden;
|
|
211
|
+
}
|
|
212
|
+
.md-lite .md-editor-host .cm-scroller {
|
|
213
|
+
max-height: var(--md-max-height, 200px);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* Touch sizes: on a touch screen or a narrow one (the kit's own
|
|
217
|
+
breakpoints), each toolbar button is the kit's tap (--tap, 44×44px) and
|
|
218
|
+
the text is 16px, so iOS does not zoom in on focus. Desktop keeps the
|
|
219
|
+
sizes above. */
|
|
220
|
+
@media (pointer: coarse), (max-width: 720px) {
|
|
221
|
+
.md-tool {
|
|
222
|
+
min-width: var(--tap);
|
|
223
|
+
min-height: var(--tap);
|
|
224
|
+
}
|
|
225
|
+
.md-editor-host,
|
|
226
|
+
.md-fallback,
|
|
227
|
+
.md-field .md-fallback {
|
|
228
|
+
font-size: 16px;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kit's Markdown editor (0.7.5): CodeMirror 6 on the Markdown text, the
|
|
3
|
+
* live preview drawn in place, IME-safe, loaded lazily. Link
|
|
4
|
+
* markdown-editor.css after tokens.css.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** "full": a form field with a toolbar; Enter is a new line, ⌘/Ctrl+Enter submits. "lite": a chat box, no toolbar; Enter sends, Shift+Enter is a new line. */
|
|
8
|
+
export type MarkdownMode = "full" | "lite";
|
|
9
|
+
export type InlineFormat = "bold" | "italic" | "code" | "strike";
|
|
10
|
+
export type BlockFormat = "heading" | "bullet" | "ordered" | "quote";
|
|
11
|
+
export type MarkdownFormat = InlineFormat | BlockFormat | "link";
|
|
12
|
+
|
|
13
|
+
export interface MarkdownEditorOptions {
|
|
14
|
+
/** The text it opens with: the Markdown source, kept byte for byte. */
|
|
15
|
+
value?: string;
|
|
16
|
+
/** Every change the person makes, as the whole Markdown source. Never called for setValue. */
|
|
17
|
+
onChange?: (value: string) => void;
|
|
18
|
+
/** Default "full". */
|
|
19
|
+
mode?: MarkdownMode;
|
|
20
|
+
/** The editing surface's id (the stand-in textarea has it first). Default: one made up. */
|
|
21
|
+
id?: string;
|
|
22
|
+
/** The editor's accessible name (aria-label). Give this or labelledBy. */
|
|
23
|
+
label?: string;
|
|
24
|
+
/** The id of the element that names it (aria-labelledby). */
|
|
25
|
+
labelledBy?: string;
|
|
26
|
+
/** The ids of the elements that describe it: help, an error (aria-describedby). */
|
|
27
|
+
describedBy?: string;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
/** full: ⌘/Ctrl+Enter; lite: Enter. Never while an IME is composing. */
|
|
30
|
+
onSubmit?: () => void;
|
|
31
|
+
/** Escape inside the editor; it stops there (a dialog around it stays open). */
|
|
32
|
+
onEscape?: () => void;
|
|
33
|
+
/** Focus left the field, the toolbar included. */
|
|
34
|
+
onBlur?: () => void;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
/** No toolbar, no edits; the text can still be selected and copied. */
|
|
37
|
+
readOnly?: boolean;
|
|
38
|
+
/** Counts the Markdown SOURCE (what is stored), as a textarea's maxLength does. An open IME composition is never cut. */
|
|
39
|
+
maxLength?: number;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
/** Marks it invalid (aria-invalid, the danger border) when its message is shown elsewhere. */
|
|
42
|
+
invalid?: boolean;
|
|
43
|
+
/** The text's language (the lang attribute), for spelling and line breaking. */
|
|
44
|
+
lang?: string;
|
|
45
|
+
/** The language of the toolbar's words: en, es or ja. Default: <html lang>, else en. */
|
|
46
|
+
uiLang?: string;
|
|
47
|
+
/** full: the editing area's minimum height in text rows (default 3). */
|
|
48
|
+
rows?: number;
|
|
49
|
+
/** full: false hides the toolbar (the shortcuts still work). */
|
|
50
|
+
toolbar?: boolean;
|
|
51
|
+
/** No link button (a field whose text may not hold a link). */
|
|
52
|
+
noLinks?: boolean;
|
|
53
|
+
autoFocus?: boolean;
|
|
54
|
+
/** Where the caret goes when the editor arrives (default: where it was in the stand-in, else nowhere). */
|
|
55
|
+
initialCaret?: number;
|
|
56
|
+
/** The page's CSP nonce: CodeMirror writes its base styles into a <style>. */
|
|
57
|
+
nonce?: string;
|
|
58
|
+
/** Classes added to the field's box (.md-field). */
|
|
59
|
+
className?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What `update` may change after mounting. */
|
|
63
|
+
export type MarkdownEditorUpdate = Partial<
|
|
64
|
+
Omit<MarkdownEditorOptions, "value" | "mode" | "id" | "nonce" | "rows">
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export interface MarkdownEditor {
|
|
68
|
+
/** Resolves when CodeMirror has taken over from the stand-in; rejects when it could not load (the stand-in stays and works). */
|
|
69
|
+
readonly ready: Promise<void>;
|
|
70
|
+
/** The Markdown source now. */
|
|
71
|
+
getValue(): string;
|
|
72
|
+
/** A value from outside (a send cleared it, a server answered): onChange is not called, and it is the new unsaved-changes baseline. */
|
|
73
|
+
setValue(value: string): void;
|
|
74
|
+
focus(): void;
|
|
75
|
+
/** What a toolbar button or shortcut does, on the selection. */
|
|
76
|
+
run(format: MarkdownFormat): void;
|
|
77
|
+
/** Put a block where the caret is, on lines of its own. */
|
|
78
|
+
insertBlock(block: string): void;
|
|
79
|
+
/** Put a link where the caret is, the selected words (else `label`) as its words. */
|
|
80
|
+
insertLinkTo(label: string, url: string): void;
|
|
81
|
+
/** Replace the last `count` characters with `text`, the caret after it. */
|
|
82
|
+
replaceEnd(count: number, text: string): void;
|
|
83
|
+
/** Change options: names, state, callbacks, the toolbar. */
|
|
84
|
+
update(options: MarkdownEditorUpdate): void;
|
|
85
|
+
/** Takes the editor and its box away. */
|
|
86
|
+
destroy(): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Mounts an editor in `el`. A plain textarea takes the typing until
|
|
91
|
+
* CodeMirror arrives (one dynamic import, its own chunk in a bundle); then
|
|
92
|
+
* the editor goes on from its text, focus, caret and selection. The
|
|
93
|
+
* content element carries `data-md-dirty` while it holds unsaved text.
|
|
94
|
+
*/
|
|
95
|
+
export declare function mountMarkdownEditor(
|
|
96
|
+
el: Element,
|
|
97
|
+
options?: MarkdownEditorOptions,
|
|
98
|
+
): MarkdownEditor;
|
|
99
|
+
|
|
100
|
+
/** Loads CodeMirror ahead of the first editor (once; shared). */
|
|
101
|
+
export declare function loadMarkdownEditor(): Promise<void>;
|
|
102
|
+
|
|
103
|
+
// The pure parts, for a product's own tests or a server.
|
|
104
|
+
|
|
105
|
+
export interface KeyLike {
|
|
106
|
+
key: string;
|
|
107
|
+
shiftKey: boolean;
|
|
108
|
+
altKey?: boolean;
|
|
109
|
+
ctrlKey?: boolean;
|
|
110
|
+
metaKey?: boolean;
|
|
111
|
+
isComposing?: boolean;
|
|
112
|
+
keyCode?: number;
|
|
113
|
+
}
|
|
114
|
+
/** True while the key belongs to an IME composition (isComposing, or keyCode 229). */
|
|
115
|
+
export declare function composingKey(
|
|
116
|
+
e: Pick<KeyLike, "isComposing" | "keyCode">,
|
|
117
|
+
): boolean;
|
|
118
|
+
/** Within this long after compositionend, an Enter is the composition's (Safari): 100 ms. */
|
|
119
|
+
export declare const COMPOSITION_GRACE_MS: number;
|
|
120
|
+
/** What Enter does in a mode; "ime" while composing; null for another key. */
|
|
121
|
+
export declare function enterAction(
|
|
122
|
+
e: KeyLike,
|
|
123
|
+
mode: MarkdownMode,
|
|
124
|
+
composing?: boolean,
|
|
125
|
+
): "submit" | "newline" | "ime" | null;
|
|
126
|
+
|
|
127
|
+
/** A text edit: changes in the old text's positions, the selection in the new. */
|
|
128
|
+
export interface MarkdownEdit {
|
|
129
|
+
changes: Array<{ from: number; to: number; insert: string }>;
|
|
130
|
+
anchor: number;
|
|
131
|
+
head: number;
|
|
132
|
+
}
|
|
133
|
+
export declare function toggleInline(
|
|
134
|
+
doc: string,
|
|
135
|
+
from: number,
|
|
136
|
+
to: number,
|
|
137
|
+
format: InlineFormat,
|
|
138
|
+
): MarkdownEdit;
|
|
139
|
+
export declare function insertLink(
|
|
140
|
+
doc: string,
|
|
141
|
+
from: number,
|
|
142
|
+
to: number,
|
|
143
|
+
placeholder?: string,
|
|
144
|
+
): MarkdownEdit;
|
|
145
|
+
export declare function toggleBlock(
|
|
146
|
+
doc: string,
|
|
147
|
+
from: number,
|
|
148
|
+
to: number,
|
|
149
|
+
format: BlockFormat,
|
|
150
|
+
): MarkdownEdit;
|
|
151
|
+
export declare function continueBlock(
|
|
152
|
+
doc: string,
|
|
153
|
+
pos: number,
|
|
154
|
+
): MarkdownEdit | null;
|
|
155
|
+
export declare function insertBlock(
|
|
156
|
+
doc: string,
|
|
157
|
+
from: number,
|
|
158
|
+
to: number,
|
|
159
|
+
block: string,
|
|
160
|
+
): MarkdownEdit;
|
|
161
|
+
export declare function insertLinkTo(
|
|
162
|
+
doc: string,
|
|
163
|
+
from: number,
|
|
164
|
+
to: number,
|
|
165
|
+
label: string,
|
|
166
|
+
url: string,
|
|
167
|
+
): MarkdownEdit;
|
|
168
|
+
export declare function applyEdit(doc: string, edit: MarkdownEdit): string;
|
|
169
|
+
|
|
170
|
+
/** One drawing instruction of the live preview. */
|
|
171
|
+
export type LiveRange =
|
|
172
|
+
| { kind: "hide"; from: number; to: number }
|
|
173
|
+
| { kind: "mark"; from: number; to: number; cls: string }
|
|
174
|
+
| { kind: "line"; from: number; cls: string }
|
|
175
|
+
| { kind: "bullet"; from: number; to: number };
|
|
176
|
+
/** A Lezer Markdown parser (from markdownParser). */
|
|
177
|
+
export interface MarkdownParser {
|
|
178
|
+
parse(text: string): unknown;
|
|
179
|
+
}
|
|
180
|
+
/** The preview's parser, made from the @lezer/markdown module given. */
|
|
181
|
+
export declare function markdownParser(md: unknown): MarkdownParser;
|
|
182
|
+
/** Every drawing instruction for `text`, given the selections whose lines are being edited. */
|
|
183
|
+
export declare function livePreview(
|
|
184
|
+
text: string,
|
|
185
|
+
selection: ReadonlyArray<readonly [number, number]>,
|
|
186
|
+
parser: MarkdownParser,
|
|
187
|
+
): LiveRange[];
|