@monster-orange/den-ui 0.7.4 → 0.7.6
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 +96 -0
- package/package.json +11 -1
- package/src/kit.d.ts +7 -0
- package/src/kit.js +10 -0
- 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/savestate.css +75 -0
- package/src/savestate.d.ts +73 -0
- package/src/savestate.js +294 -0
- 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 +74 -0
- package/src/whatsnew.js +13 -2
package/README.md
CHANGED
|
@@ -142,6 +142,7 @@ syncPinToggles }`.
|
|
|
142
142
|
DenUI.update.set({ version }); // the update pill; .hide()
|
|
143
143
|
DenUI.report.open({ prefill }); // ⌘⇧F and any [data-den-report] too
|
|
144
144
|
DenUI.busy.run(action, run, opts) // the working pop-up (busy.js)
|
|
145
|
+
DenUI.saveState(el, { save, copyText, watch }) // save-state line
|
|
145
146
|
|
|
146
147
|
### The adapter
|
|
147
148
|
|
|
@@ -161,6 +162,13 @@ paste where the team tracks issues. A product with more (a preview, a
|
|
|
161
162
|
sign-in flow, drafts) gives `info`, `diagnostics`, `preview`, `send`,
|
|
162
163
|
`githubSend`, `githubPoll` and `saveDraft`; see the top of `report.js`.
|
|
163
164
|
|
|
165
|
+
Each of `info()`'s `repos` may say its `visibility` (`"public"`,
|
|
166
|
+
`"private"` or `"internal"`) and an `audience` (who can see it, as words).
|
|
167
|
+
A public repo, or one that doesn't say, gets the "Public repository" pill
|
|
168
|
+
and the "visible to everyone" warning above Send. A private or internal
|
|
169
|
+
one gets its own pill, the audience, and a quiet line instead of the
|
|
170
|
+
warning. Both follow the repo chosen in Review.
|
|
171
|
+
|
|
164
172
|
### Strings
|
|
165
173
|
|
|
166
174
|
`src/strings.js` (export `./strings`) exports `en`, `es` and `ja`: every
|
|
@@ -380,6 +388,92 @@ browser test, on the image (Den's real server on the demo distribution,
|
|
|
380
388
|
is `src/kit.d.ts`. A test compiles a consumer against them with
|
|
381
389
|
`--strict`.
|
|
382
390
|
|
|
391
|
+
## The Markdown editor (0.7.5)
|
|
392
|
+
|
|
393
|
+
`src/markdown-editor.js` and `src/markdown-editor.css` (exports
|
|
394
|
+
`./markdown-editor`, `./markdown-editor.css`): a Markdown field,
|
|
395
|
+
ported from an existing editor. CodeMirror 6 on the Markdown text: the
|
|
396
|
+
document is the string that is stored, character for character, and the
|
|
397
|
+
live preview is drawn in place, as decoration only (no preview pane,
|
|
398
|
+
never converted to HTML and back).
|
|
399
|
+
|
|
400
|
+
import { mountMarkdownEditor } from "@monster-orange/den-ui/markdown-editor";
|
|
401
|
+
// link markdown-editor.css after tokens.css
|
|
402
|
+
const ed = mountMarkdownEditor(el, {
|
|
403
|
+
value: "", onChange: (text) => save(text),
|
|
404
|
+
label: "Notes", // or labelledBy; describedBy for help
|
|
405
|
+
mode: "full", // "full": a toolbar, Enter is a new line,
|
|
406
|
+
// ⌘/Ctrl+Enter submits; "lite": a chat box,
|
|
407
|
+
// Enter sends, Shift+Enter is a new line
|
|
408
|
+
onSubmit, onEscape, onBlur, placeholder, maxLength, rows,
|
|
409
|
+
disabled, readOnly, required, invalid, lang, uiLang, nonce,
|
|
410
|
+
});
|
|
411
|
+
await ed.ready; // CodeMirror has taken over
|
|
412
|
+
ed.setValue(""); ed.focus(); ed.run("bold");
|
|
413
|
+
ed.insertBlock(text); ed.insertLinkTo(label, url); ed.replaceEnd(n, text);
|
|
414
|
+
ed.update({ disabled: true }); ed.destroy();
|
|
415
|
+
|
|
416
|
+
- **Lazy.** The module imports no CodeMirror. On mount it loads
|
|
417
|
+
`@codemirror/state`, `view`, `commands` and `@lezer/markdown` with
|
|
418
|
+
`import()`, so a bundler puts them in a chunk of their own, and a plain
|
|
419
|
+
textarea takes the typing until it arrives (its toolbar works too). The
|
|
420
|
+
editor then goes on from the textarea's text, focus, caret and
|
|
421
|
+
selection. `loadMarkdownEditor()` warms the chunk early. The packages
|
|
422
|
+
are the kit's `dependencies`, pinned exactly. Den's own pages don't
|
|
423
|
+
load it.
|
|
424
|
+
- **The preview.** On a line the caret is not on, the markers hide and
|
|
425
|
+
the words show formatted; `- ` becomes a bullet. On the line being
|
|
426
|
+
edited every marker stays, muted. CommonMark without setext headings,
|
|
427
|
+
indented code, HTML, entities, reference links, images and autolinks,
|
|
428
|
+
plus strikethrough; only an http(s) link is drawn as a link.
|
|
429
|
+
- **IME.** An Enter that belongs to a composition (`view.composing`,
|
|
430
|
+
`isComposing`, keyCode 229, or within 100 ms of `compositionend`, as
|
|
431
|
+
Safari sends it) never sends, submits or adds a line. The preview is
|
|
432
|
+
frozen while a composition is open, and `maxLength` never cuts one.
|
|
433
|
+
- **Shortcuts.** ⌘/Ctrl+B, I, E (code), K (link), ⇧X (strike); Enter in
|
|
434
|
+
a list or quote continues it, and on an empty item ends it.
|
|
435
|
+
- **Words.** The toolbar's are `kit.md.*` in strings.js (en, es, ja), in
|
|
436
|
+
`uiLang`, else `<html lang>`.
|
|
437
|
+
- **Touch sizes.** On `(pointer: coarse)` or below 720px the toolbar's
|
|
438
|
+
buttons are `--tap` (44×44px) and the text is 16px (no zoom on focus);
|
|
439
|
+
elsewhere 28px and 15px.
|
|
440
|
+
- **CSP.** CodeMirror writes its base styles into a `<style>`: under a
|
|
441
|
+
strict `style-src`, pass the page's `nonce`.
|
|
442
|
+
- The content element has `data-md-dirty` while it holds unsaved text
|
|
443
|
+
(for an update pill's `askFirst`).
|
|
444
|
+
|
|
445
|
+
## The save-state line (`den-savestate`)
|
|
446
|
+
|
|
447
|
+
- `src/savestate.js`, `src/savestate.css` (exports `./savestate`,
|
|
448
|
+
`./savestate.css`): what an autosaving editor says about its text. It
|
|
449
|
+
works with any input, textarea or editor; the host gives the save.
|
|
450
|
+
|
|
451
|
+
const line = createSaveState(document.querySelector("#save-line"), {
|
|
452
|
+
save: () => api.saveDraft(field.value), // rejects on failure
|
|
453
|
+
copyText: () => `${title.value}\n\n${field.value}`,
|
|
454
|
+
watch: field, // input → changed(), focusout → flush()
|
|
455
|
+
});
|
|
456
|
+
// line.changed(), line.flush(), line.retry(), line.state(), line.destroy()
|
|
457
|
+
|
|
458
|
+
- The element becomes `<p class="den-savestate">` with `role="status"`,
|
|
459
|
+
`aria-live="off"` and `data-state` (`idle`, `saving`, `saved`,
|
|
460
|
+
`error`): a 6 px dot, then the words, 13 px on a 20 px line (idle is
|
|
461
|
+
empty and keeps its height).
|
|
462
|
+
- It saves 800 ms after the last change, and at once on blur and when the
|
|
463
|
+
page goes hidden. "Saving…" shows only when a save takes more than
|
|
464
|
+
400 ms; "Saved" (title "Saved at {time}", from `time.js`) stays until the
|
|
465
|
+
next save. A failure shows "Not saved. Retrying…" with Copy text (what
|
|
466
|
+
`copyText()` returns), retries at 2 s, 4 s and 8 s, then every 30 s, and
|
|
467
|
+
at once when the browser is back online.
|
|
468
|
+
- A visually hidden polite region beside the line says only the error and
|
|
469
|
+
its recovery; `aria-live="off"` keeps the routine "Saved" quiet.
|
|
470
|
+
- Only the dot's colour moves, over `--dur-fast`; none under reduced
|
|
471
|
+
motion. Its words are `kit.savestate.*` in `strings.js` (en, es, ja).
|
|
472
|
+
- `saveScheduler({ save, onChange })` is the same timing with no DOM.
|
|
473
|
+
- Link `savestate.css` in the page's `<head>`. Without that, savestate.js
|
|
474
|
+
links it from `opts.css`, else from beside another kit stylesheet on the
|
|
475
|
+
page.
|
|
476
|
+
|
|
383
477
|
## 0.7.1
|
|
384
478
|
|
|
385
479
|
The top bar's search sits in the same place in every product (issue 303).
|
|
@@ -511,6 +605,8 @@ button)`. A crumb left out of the list draws nothing, and no separator
|
|
|
511
605
|
on `<body>`: a heading, then the host's `items` as rows (`{ text, href?,
|
|
512
606
|
time?, read? }`) or the empty state. `bellPanelHtml(...)` takes `actions`
|
|
513
607
|
(buttons beside the heading), `lead`, `body` (the host's own rows),
|
|
608
|
+
`sections` (issue 101: `{ needs, earlier? }`, the rows of each; the kit
|
|
609
|
+
heads them "Needs you", always first, and "Earlier", in its own words),
|
|
514
610
|
`empty`, `after` and `foot`. A click on the bell toggles the panel.
|
|
515
611
|
Opening it focuses its first link or button. Esc closes it and focus goes
|
|
516
612
|
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.6",
|
|
4
4
|
"description": "Den's UI kit: tokens, fonts and shared components, framework-free",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./busy": "./src/busy.js",
|
|
21
21
|
"./busy-words": "./src/busy-words.js",
|
|
22
22
|
"./dialog": "./src/dialog.js",
|
|
23
|
+
"./savestate": "./src/savestate.js",
|
|
23
24
|
"./strings": "./src/strings.js",
|
|
24
25
|
"./icons": "./src/icons.js",
|
|
25
26
|
"./shell-html": "./src/shell-html.js",
|
|
@@ -34,6 +35,9 @@
|
|
|
34
35
|
"./report.css": "./src/report.css",
|
|
35
36
|
"./busy.css": "./src/busy.css",
|
|
36
37
|
"./dialog.css": "./src/dialog.css",
|
|
38
|
+
"./markdown-editor": "./src/markdown-editor.js",
|
|
39
|
+
"./markdown-editor.css": "./src/markdown-editor.css",
|
|
40
|
+
"./savestate.css": "./src/savestate.css",
|
|
37
41
|
"./inventory": {
|
|
38
42
|
"types": "./inventory/nav-inventory.d.ts",
|
|
39
43
|
"default": "./inventory/nav-inventory.js"
|
|
@@ -56,5 +60,11 @@
|
|
|
56
60
|
],
|
|
57
61
|
"bin": {
|
|
58
62
|
"den-ui-parity": "bin/den-ui-parity.mjs"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@codemirror/commands": "6.11.1",
|
|
66
|
+
"@codemirror/state": "6.7.6",
|
|
67
|
+
"@codemirror/view": "6.43.13",
|
|
68
|
+
"@lezer/markdown": "1.7.2"
|
|
59
69
|
}
|
|
60
70
|
}
|
package/src/kit.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ import type {
|
|
|
53
53
|
} from "./shell-html.js";
|
|
54
54
|
import type { syncPinToggles } from "./shell-client.js";
|
|
55
55
|
import type { UpdatePill } from "./update-pill.js";
|
|
56
|
+
import type { SaveState, SaveStateOptions } from "./savestate.js";
|
|
56
57
|
|
|
57
58
|
/** Every call to the product goes through it; the kit names no URL. */
|
|
58
59
|
export interface Adapter extends ReportAdapter {
|
|
@@ -158,6 +159,11 @@ export declare const busy: {
|
|
|
158
159
|
): Promise<T | null>;
|
|
159
160
|
configure: typeof configureBusy;
|
|
160
161
|
};
|
|
162
|
+
/** An autosaving editor's save-state line, in the kit's language. */
|
|
163
|
+
export declare function saveState(
|
|
164
|
+
el: HTMLElement,
|
|
165
|
+
opts: SaveStateOptions,
|
|
166
|
+
): SaveState;
|
|
161
167
|
export declare function hydrate(
|
|
162
168
|
root: ParentNode,
|
|
163
169
|
opts?: KitHydrateOptions,
|
|
@@ -208,6 +214,7 @@ export interface DenUIKit {
|
|
|
208
214
|
update: typeof update;
|
|
209
215
|
report: typeof report;
|
|
210
216
|
busy: typeof busy;
|
|
217
|
+
saveState: typeof saveState;
|
|
211
218
|
}
|
|
212
219
|
declare const DenUI: DenUIKit;
|
|
213
220
|
export default DenUI;
|
package/src/kit.js
CHANGED
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
* focus goes back to opener (else the
|
|
43
43
|
* control that opened it) on close
|
|
44
44
|
* DenUI.busy.run(action, run, opts) the working pop-up (busy.js)
|
|
45
|
+
* DenUI.saveState(el, { save, copyText, watch }) an autosaving
|
|
46
|
+
* editor's save-state line (savestate.js),
|
|
47
|
+
* in the kit's language
|
|
45
48
|
* DenUI.strings(lang, table) the product's own words, or its versions
|
|
46
49
|
* of the kit's; DenUI.t(key, vars)
|
|
47
50
|
*/
|
|
@@ -92,6 +95,7 @@ import {
|
|
|
92
95
|
import { configureReport, openReport } from "./report.js";
|
|
93
96
|
import { showUpdate } from "./update-pill.js";
|
|
94
97
|
import { busyAction, configureBusy } from "./busy.js";
|
|
98
|
+
import { createSaveState } from "./savestate.js";
|
|
95
99
|
|
|
96
100
|
const state = {
|
|
97
101
|
lang: "en",
|
|
@@ -183,6 +187,11 @@ export const busy = {
|
|
|
183
187
|
configure: configureBusy,
|
|
184
188
|
};
|
|
185
189
|
|
|
190
|
+
/** An autosaving editor's save-state line, in the kit's language. */
|
|
191
|
+
export function saveState(el, opts = {}) {
|
|
192
|
+
return createSaveState(el, { lang, ...opts });
|
|
193
|
+
}
|
|
194
|
+
|
|
186
195
|
/**
|
|
187
196
|
* Binds the drawn shell, the chip and Report (see the top), and the 0.7.0
|
|
188
197
|
* pieces it finds: the scope crumbs (opts.scope), the search
|
|
@@ -294,6 +303,7 @@ const DenUI = {
|
|
|
294
303
|
update,
|
|
295
304
|
report,
|
|
296
305
|
busy,
|
|
306
|
+
saveState,
|
|
297
307
|
};
|
|
298
308
|
|
|
299
309
|
if (typeof window !== "undefined") window.DenUI = DenUI;
|
|
@@ -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[];
|