@usememos/editor 26.10.21 → 26.10.23
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 +32 -7
- package/dist/base.css +1 -1
- package/dist/index.js +361 -55
- package/dist/index.js.map +3 -3
- package/dist/react.js.map +2 -2
- package/dist/style.css +30 -32
- package/dist/theme.css +57 -32
- package/dist/types/editor.d.ts +7 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/sourceMode.d.ts +15 -0
- package/dist/types/theme.d.ts +21 -5
- package/dist/types/view/dom.d.ts +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
|
|
|
55
55
|
| `editable` | `boolean` | Default `true`. With `false`, no editing, and links open on click. |
|
|
56
56
|
| `taskToggle` | `boolean` | Default `false`. While `editable` is `false`, lets the user tick and untick task items, for example for a memo's owner. Each tick emits `change` with Markdown in which only that item's `[ ]` or `[x]` changed. Ignored while `editable` is `true`. |
|
|
57
57
|
| `mode` | `'rich' \| 'source'` | Default `'rich'`. `'source'` shows the whole document as its Markdown text, for people who prefer to edit the text itself. Switching changes no text, emits no `change` and keeps undo history. See [Source mode](#source-mode). |
|
|
58
|
+
| `smartLists` | `boolean` | Default `true`. In source mode, Enter continues a list or task item and Tab and Shift+Tab nest list items. `false` makes Enter insert a line break and Tab indent as in a code block. No effect in rich mode, where list items are blocks. Fixed for the editor's lifetime. |
|
|
58
59
|
| `autofocus` | `boolean \| 'start' \| 'end'` | Focuses the editor on creation, with the caret at the start or the end. |
|
|
59
60
|
| `attributes` | `Record<string, string>` | Attributes for the editable root, such as `autocorrect`, `autocapitalize` or `aria-label`. |
|
|
60
61
|
| `resolveUrl` | `(url, kind) => string \| null` | The URL to use for a link (`kind` `'link'`) or an image (`'image'`), or `null` to drop it: the link is not clickable, the image has no `src`. The saved Markdown keeps the original. Default `defaultResolveUrl`, exported: relative URLs, `http`, `https`, `mailto` and `tel`. Call it from your own policy to extend it, for example to allow `sms:` or to block `http:` images. |
|
|
@@ -304,9 +305,30 @@ new Editor({
|
|
|
304
305
|
});
|
|
305
306
|
```
|
|
306
307
|
|
|
307
|
-
Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `border`, `popupBackground`, `popupBorder`, `hover`, `danger`, and `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (each callout type's icon, and a light tint of it behind the text); the other tokens are `font`, `mono`, `fontSize`, `lineHeight`, `radius` and `blockGap` (numbers are pixels). Values can be any CSS, such as `var(--primary)`, so the editor can follow your app's own variables. Menus, the toolbar and the link popover take the same tokens.
|
|
308
|
+
Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `border`, `popupBackground`, `popupBorder`, `hover`, `danger`, `highlight` (behind `<mark>` in rendered HTML), and `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (each callout type's icon, and a light tint of it behind the text); the other tokens are `font`, `mono`, `fontSize`, `lineHeight`, `radius` and `blockGap` (numbers are pixels). Values can be any CSS, such as `var(--primary)`, so the editor can follow your app's own variables; `colors` sets such a value for both schemes at once, and `light` and `dark` override it per scheme. Menus, the toolbar and the link popover take the same tokens.
|
|
308
309
|
|
|
309
|
-
`
|
|
310
|
+
`fontSize` and `lineHeight` size the whole document, not only its paragraphs: headings are 1.5, 1.25 and 1.125 times `fontSize` (h4 to h6 the body size), code blocks, raw blocks and tables 0.875 times it, and the code block's language label 0.75. Each keeps the body's leading, the room `lineHeight` leaves around `fontSize`, so `fontSize: 14` with `lineHeight: 20` gives a 21px h1 on 27px lines, and code at 12.25px on 18.25px lines.
|
|
311
|
+
|
|
312
|
+
For an app styled with [shadcn/ui](https://ui.shadcn.com), `shadcnTheme` maps the tokens to shadcn's variables (`--foreground`, `--primary`, `--muted`, `--border`, `--popover`, `--radius`, …), so the editor follows the app's theme, light and dark included:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
import { Editor, shadcnTheme } from '@usememos/editor';
|
|
316
|
+
|
|
317
|
+
new Editor({ element, theme: shadcnTheme });
|
|
318
|
+
// or, with a change: { tokens: { ...shadcnTheme.tokens, radius: 4 } }
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
The same tokens can be set in CSS, with no JavaScript, as `--mbe-<name>-light` and `--mbe-<name>-dark` (`--mbe-accent-light`, `--mbe-code-bg-dark`; the names are in `theme.css`). They inherit, so set them on `:root` for every editor on the page, or on a container for the editors in it. `theme.css` reads them with the default palette as fallback; a value you leave out keeps the default:
|
|
322
|
+
|
|
323
|
+
```css
|
|
324
|
+
:root {
|
|
325
|
+
--mbe-accent-light: #0969da;
|
|
326
|
+
--mbe-accent-dark: #58a6ff;
|
|
327
|
+
--mbe-font: Inter, sans-serif;
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
`colorScheme` picks light or dark: `auto` (the default) follows `prefers-color-scheme`, or `data-theme="light"` or `data-theme="dark"`, or a `light` or `dark` class (as Tailwind and shadcn/ui toggle it), on the editor or an ancestor; `light` and `dark` force one; `inherit` follows the page's `color-scheme`, for apps that switch it themselves. Switching tokens or the scheme with `setOptions({ theme })` re-renders nothing.
|
|
310
332
|
|
|
311
333
|
The `theme` option's `classes` add your own classes to rendered elements, next to the editor's `mbe-*` classes, so the editor can share classes with the rest of your app:
|
|
312
334
|
|
|
@@ -356,7 +378,7 @@ To style the editor entirely with your own classes, import `@usememos/editor/bas
|
|
|
356
378
|
|
|
357
379
|
With blocks selected: ArrowUp and ArrowDown select the block above or below, Shift extends the selection, Mod+A selects every block, Backspace and Delete delete them, Mod+C, Mod+X and paste copy, cut and replace them as whole blocks, Mod+D duplicates them, and the block type keys, Tab and the mark keys apply to all of them. Enter, ArrowLeft and ArrowRight go back to editing text. Typing does nothing. See [Block selection](docs/architecture.md#block-selection).
|
|
358
380
|
|
|
359
|
-
In source mode the formatting keys do nothing and Enter
|
|
381
|
+
In source mode the formatting keys do nothing, and Enter and Tab edit list items as text; see [Source mode](#source-mode).
|
|
360
382
|
|
|
361
383
|
Markdown shortcuts at the start of a line: `#`–`######`, `-`, `*`, `+`, `1.`, `[ ]`, `[x]`, `>`, `[!note]` and the other callout types, `>>>` (collapsible section), ` ``` `, `---`. Inline: `**bold**`, `*italic*`, `_italic_`, `` `code` ``, `~~strike~~`.
|
|
362
384
|
|
|
@@ -407,15 +429,18 @@ With `mode: 'source'`, the editor shows the whole document as Markdown text, as
|
|
|
407
429
|
<MarkdownEditor value={markdown} onChange={setMarkdown} mode={showSource ? 'source' : 'rich'} />
|
|
408
430
|
```
|
|
409
431
|
|
|
432
|
+
The text is set in the `mono` font at the body's size and line height, as code blocks are, so list markers and indentation line up.
|
|
433
|
+
|
|
410
434
|
**Switching** is a change of view, not an edit. The text shown in source mode is exactly `getMarkdown()`. Going back to rich mode loads the text as `setMarkdown` does, so `getMarkdown()` returns it byte for byte, including lines edited in source mode. A switch emits no `change`, adds no undo step and does not move focus. Undo and redo work across it: undoing an edit made in the other mode restores it in the current mode. The caret stays in the same block, and keeps its column when the text before it in that block has no Markdown syntax; otherwise it goes to the start of the block's text. A switch requested while an input method is composing waits for the composition to end.
|
|
411
435
|
|
|
412
|
-
**What works in source mode.** Source mode is plain text editing, like a `<textarea>` or a code block. It has no autocomplete and no formatting keys.
|
|
436
|
+
**What works in source mode.** Source mode is plain text editing, like a `<textarea>` or a code block, that knows Markdown lists. It has no autocomplete and no formatting keys.
|
|
413
437
|
|
|
414
438
|
| | |
|
|
415
439
|
| --- | --- |
|
|
416
440
|
| Typing, deleting, input methods, spellcheck | As in a code block |
|
|
417
|
-
| Enter |
|
|
418
|
-
|
|
|
441
|
+
| Enter | On a list item, after its marker, starts the next item: the same marker and indentation, the next number, and an unticked `[ ]` after a task. Text after the caret moves to the new item, and the items after it in an ordered list are numbered again. On an empty item, removes the marker, or outdents a nested item, as in rich mode. Elsewhere, inside fenced code and before an item's marker, inserts a line break |
|
|
442
|
+
| Shift+Enter | Inserts a line break |
|
|
443
|
+
| Tab, Shift+Tab | On list items: Tab nests the items the selection touches under the item before them, at that item's text column, and Shift+Tab moves them out to their parent's level. Lines nested under them move with them, ordered lists they leave and join are numbered again, and an item that cannot move stays. Elsewhere, as in a code block: Tab inserts two spaces, or indents the selected lines by two spaces. Shift+Tab removes up to two spaces (or a tab) from the start of those lines |
|
|
419
444
|
| Paste | The clipboard's plain text (`text/plain`). Files go to `fileHandler` as in rich mode |
|
|
420
445
|
| Copy and cut | The selected text, as `text/plain` |
|
|
421
446
|
| Mod+Enter, undo, redo, Mod+A | As in rich mode |
|
|
@@ -424,7 +449,7 @@ With `mode: 'source'`, the editor shows the whole document as Markdown text, as
|
|
|
424
449
|
| Markdown shortcuts, autolinks | Do not run: the text is the Markdown |
|
|
425
450
|
| Autocomplete | Off. `suggestion()` popups, the slash menu and Ctrl+Space do not open |
|
|
426
451
|
| `fileHandler`, `handlePaste`, `handleDrop`, extension key bindings | As in rich mode |
|
|
427
|
-
| `commands.*` | `insertText` and `insertMarkdown` insert the text as written; `insertMarkdown` with `block: true` puts it on lines of its own. `indent
|
|
452
|
+
| `commands.*` | `insertText` and `insertMarkdown` insert the text as written; `insertMarkdown` with `block: true` puts it on lines of its own. `indent` and `outdent` work as Tab and Shift+Tab. `undo`, `undo`, `redo`, `selectAll`, `focus`, `blur` and `scrollIntoView` work. The mark, block type, link, image, table, divider, callout, section and `selectBlocks` commands return `false` |
|
|
428
453
|
| Placeholder | Shown when the text is empty |
|
|
429
454
|
| `addWidget` | Shown below the text. A widget remembers its place in the text, which moves with edits before it, and `insertMarkdown(md, { at: widget })` inserts there |
|
|
430
455
|
| `editable: false` | The text is read-only and can be selected and copied. `taskToggle` has no effect |
|
package/dist/base.css
CHANGED
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
/* Code keeps its lines and scrolls sideways, as GitHub shows it; raw source wraps. */
|
|
242
242
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre { white-space: pre; overflow-x: auto; tab-size: 2; }
|
|
243
243
|
:is(.mbe-root, .mbe-flow) > pre.mbe-raw { white-space: pre-wrap; tab-size: 2; }
|
|
244
|
-
/* Source mode: the document as plain text
|
|
244
|
+
/* Source mode: the document as plain text; theme.css sets its mono font. */
|
|
245
245
|
.mbe-root > .mbe-source { white-space: pre-wrap; tab-size: 4; overflow-wrap: anywhere; }
|
|
246
246
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre { margin: 0; }
|
|
247
247
|
:is(.mbe-root, .mbe-flow) > .mbe-code pre code { display: block; }
|
package/dist/index.js
CHANGED
|
@@ -3889,14 +3889,14 @@ var BlockParser = class {
|
|
|
3889
3889
|
while (this.tip !== this.doc) this.finalize(this.tip, count);
|
|
3890
3890
|
this.finalize(this.doc, count);
|
|
3891
3891
|
const children = [];
|
|
3892
|
-
const
|
|
3892
|
+
const sourceLines2 = [];
|
|
3893
3893
|
for (const child of this.doc.children) {
|
|
3894
3894
|
for (const node of this.toAst(child)) {
|
|
3895
3895
|
children.push(node);
|
|
3896
|
-
|
|
3896
|
+
sourceLines2.push({ start: child.startLine, end: child.endLine });
|
|
3897
3897
|
}
|
|
3898
3898
|
}
|
|
3899
|
-
return { type: "root", children, lines:
|
|
3899
|
+
return { type: "root", children, lines: sourceLines2, definitions: this.definitions };
|
|
3900
3900
|
}
|
|
3901
3901
|
/** Link reference definitions at the start of a paragraph's content. Keeps their source. */
|
|
3902
3902
|
extractReferences(content) {
|
|
@@ -3936,13 +3936,13 @@ var BlockParser = class {
|
|
|
3936
3936
|
* Advances by `count` characters, or by `count` columns if `columns` is
|
|
3937
3937
|
* set. A tab advanced by columns may be only partly consumed.
|
|
3938
3938
|
*/
|
|
3939
|
-
advanceOffset(count,
|
|
3939
|
+
advanceOffset(count, columns2) {
|
|
3940
3940
|
const line = this.line;
|
|
3941
3941
|
let c;
|
|
3942
3942
|
while (count > 0 && (c = line[this.offset]) !== void 0) {
|
|
3943
3943
|
if (c === " ") {
|
|
3944
3944
|
const toTab = 4 - this.column % 4;
|
|
3945
|
-
if (
|
|
3945
|
+
if (columns2) {
|
|
3946
3946
|
this.partiallyConsumedTab = toTab > count;
|
|
3947
3947
|
const advance = toTab > count ? count : toTab;
|
|
3948
3948
|
this.column += advance;
|
|
@@ -7619,7 +7619,6 @@ function htmlRuns(inline3) {
|
|
|
7619
7619
|
let depth = 0;
|
|
7620
7620
|
for (let j = i + 1; j < spans.length; j++) {
|
|
7621
7621
|
const t = spans[j].span;
|
|
7622
|
-
if (t.link) break;
|
|
7623
7622
|
if (!isHtml(t)) continue;
|
|
7624
7623
|
const tag = /^<(\/?)([A-Za-z][A-Za-z0-9-]*)\b[^>]*?(\/?)>$/.exec(t.text);
|
|
7625
7624
|
if (!tag || tag[2].toLowerCase() !== name || tag[3]) continue;
|
|
@@ -7631,7 +7630,6 @@ function htmlRuns(inline3) {
|
|
|
7631
7630
|
}
|
|
7632
7631
|
}
|
|
7633
7632
|
}
|
|
7634
|
-
if (spans.slice(i, end + 1).some((s) => s.span.link)) continue;
|
|
7635
7633
|
runs.push({ from, to: end === i ? to : spans[end].to });
|
|
7636
7634
|
i = end;
|
|
7637
7635
|
}
|
|
@@ -7654,59 +7652,89 @@ function renderInline(inline3, parent, ctx, decorations, reveal, cell) {
|
|
|
7654
7652
|
offsets.set(piece, offset);
|
|
7655
7653
|
offset += piece.span.text.length;
|
|
7656
7654
|
}
|
|
7657
|
-
|
|
7658
|
-
|
|
7655
|
+
const linkElement = (span) => {
|
|
7656
|
+
const a = doc.createElement("a");
|
|
7657
|
+
const href = ctx.resolveUrl(span.link, "link");
|
|
7658
|
+
if (href !== null) a.setAttribute("href", href);
|
|
7659
|
+
a.dataset.href = span.link;
|
|
7660
|
+
if (span.linkTitle) a.title = span.linkTitle;
|
|
7661
|
+
a.className = classes("mbe-link", ctx.classes.link);
|
|
7662
|
+
return a;
|
|
7663
|
+
};
|
|
7664
|
+
const runAt = (i) => runs.find((r) => r.from === offsets.get(pieces[i]));
|
|
7665
|
+
const runEnd = (i, run) => {
|
|
7666
|
+
let end = i;
|
|
7667
|
+
while (end < pieces.length && offsets.get(pieces[end]) < run.to) end++;
|
|
7668
|
+
return end;
|
|
7669
|
+
};
|
|
7670
|
+
const linkedRun = (i, run) => {
|
|
7659
7671
|
const span = pieces[i].span;
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7672
|
+
if (!span.link) return false;
|
|
7673
|
+
for (let j = i + 1, end = runEnd(i, run); j < end; j++) if (!sameLink(pieces[j].span, span)) return false;
|
|
7674
|
+
return true;
|
|
7675
|
+
};
|
|
7676
|
+
const renderRun = (i, run, into, linked) => {
|
|
7677
|
+
const html = [];
|
|
7678
|
+
const slots = [];
|
|
7679
|
+
const end = runEnd(i, run);
|
|
7680
|
+
for (let j = i; j < end; ) {
|
|
7681
|
+
const piece = pieces[j];
|
|
7682
|
+
if (isHtml(piece.span)) {
|
|
7683
|
+
html.push(piece.span.text);
|
|
7684
|
+
j++;
|
|
7685
|
+
continue;
|
|
7686
|
+
}
|
|
7687
|
+
const slot = doc.createDocumentFragment();
|
|
7688
|
+
const stop = (k) => k >= end || isHtml(pieces[k].span);
|
|
7689
|
+
if (linked) for (; !stop(j); j++) slot.appendChild(render2(pieces[j]));
|
|
7690
|
+
else j = renderPieces(j, stop, slot);
|
|
7691
|
+
slots.push(slot);
|
|
7692
|
+
html.push(slotMarker(slots.length - 1));
|
|
7693
|
+
}
|
|
7694
|
+
const view = ctx.view?.("html", html.join(""), "inline");
|
|
7695
|
+
if (!view) return null;
|
|
7696
|
+
fillSlots(view, slots.length, (n) => slots[n], doc);
|
|
7697
|
+
const text = inlineText(sliceInline(inline3, run.from, run.to));
|
|
7698
|
+
into.appendChild(atom(view, classes("mbe-view", "mbe-view-html", ctx.classes.token?.html), text));
|
|
7699
|
+
return end;
|
|
7700
|
+
};
|
|
7701
|
+
const renderPieces = (i, stop, into) => {
|
|
7702
|
+
while (i < pieces.length && !stop(i)) {
|
|
7703
|
+
const span = pieces[i].span;
|
|
7704
|
+
const run = runAt(i);
|
|
7705
|
+
if (run && !linkedRun(i, run)) {
|
|
7706
|
+
const next = renderRun(i, run, into, false);
|
|
7707
|
+
if (next !== null) {
|
|
7708
|
+
i = next;
|
|
7671
7709
|
continue;
|
|
7672
7710
|
}
|
|
7673
|
-
if (!slot) {
|
|
7674
|
-
slot = [];
|
|
7675
|
-
slots.push(slot);
|
|
7676
|
-
html.push(slotMarker(slots.length - 1));
|
|
7677
|
-
}
|
|
7678
|
-
slot.push(render2(piece));
|
|
7679
7711
|
}
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
const fragment = doc.createDocumentFragment();
|
|
7684
|
-
fragment.append(...slots[n]);
|
|
7685
|
-
return fragment;
|
|
7686
|
-
}, doc);
|
|
7687
|
-
const text = inlineText(sliceInline(inline3, run.from, run.to));
|
|
7688
|
-
parent.appendChild(atom(view, classes("mbe-view", "mbe-view-html", ctx.classes.token?.html), text));
|
|
7689
|
-
i = end;
|
|
7712
|
+
if (!span.link) {
|
|
7713
|
+
into.appendChild(render2(pieces[i]));
|
|
7714
|
+
i++;
|
|
7690
7715
|
continue;
|
|
7691
7716
|
}
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7717
|
+
const a = linkElement(span);
|
|
7718
|
+
const start = i;
|
|
7719
|
+
while (i < pieces.length && !stop(i) && sameLink(pieces[i].span, span)) {
|
|
7720
|
+
const inner = runAt(i);
|
|
7721
|
+
if (inner) {
|
|
7722
|
+
const whole = linkedRun(i, inner);
|
|
7723
|
+
if (!whole && i > start) break;
|
|
7724
|
+
const next = whole ? renderRun(i, inner, a, true) : null;
|
|
7725
|
+
if (next !== null) {
|
|
7726
|
+
i = next;
|
|
7727
|
+
continue;
|
|
7728
|
+
}
|
|
7729
|
+
}
|
|
7701
7730
|
a.appendChild(render2(pieces[i]));
|
|
7702
7731
|
i++;
|
|
7703
7732
|
}
|
|
7704
|
-
|
|
7705
|
-
} else {
|
|
7706
|
-
parent.appendChild(render2(pieces[i]));
|
|
7707
|
-
i++;
|
|
7733
|
+
into.appendChild(a);
|
|
7708
7734
|
}
|
|
7709
|
-
|
|
7735
|
+
return i;
|
|
7736
|
+
};
|
|
7737
|
+
renderPieces(0, () => false, parent);
|
|
7710
7738
|
}
|
|
7711
7739
|
function decorate(node, decorations, doc) {
|
|
7712
7740
|
for (let i = decorations.length - 1; i >= 0; i--) {
|
|
@@ -8691,6 +8719,23 @@ function delta(start, end, viewStart, viewEnd) {
|
|
|
8691
8719
|
}
|
|
8692
8720
|
|
|
8693
8721
|
// src/theme.ts
|
|
8722
|
+
var shadcnTheme = {
|
|
8723
|
+
tokens: {
|
|
8724
|
+
colors: {
|
|
8725
|
+
text: "var(--foreground)",
|
|
8726
|
+
muted: "var(--muted-foreground)",
|
|
8727
|
+
accent: "var(--primary)",
|
|
8728
|
+
codeBackground: "var(--muted)",
|
|
8729
|
+
border: "var(--border)",
|
|
8730
|
+
popupBackground: "var(--popover)",
|
|
8731
|
+
hover: "var(--accent)",
|
|
8732
|
+
danger: "var(--destructive)"
|
|
8733
|
+
},
|
|
8734
|
+
font: "inherit",
|
|
8735
|
+
mono: "var(--font-mono, ui-monospace, monospace)",
|
|
8736
|
+
radius: "calc(var(--radius) - 2px)"
|
|
8737
|
+
}
|
|
8738
|
+
};
|
|
8694
8739
|
function mergeClasses(maps) {
|
|
8695
8740
|
const out = {};
|
|
8696
8741
|
for (const map of maps) {
|
|
@@ -8713,6 +8758,7 @@ var COLOR_VARS = {
|
|
|
8713
8758
|
popupBorder: "--mbe-popup-border",
|
|
8714
8759
|
hover: "--mbe-hover",
|
|
8715
8760
|
danger: "--mbe-danger",
|
|
8761
|
+
highlight: "--mbe-highlight",
|
|
8716
8762
|
calloutNote: "--mbe-callout-note",
|
|
8717
8763
|
calloutTip: "--mbe-callout-tip",
|
|
8718
8764
|
calloutImportant: "--mbe-callout-important",
|
|
@@ -8732,9 +8778,9 @@ function tokenProperties(tokens) {
|
|
|
8732
8778
|
const props = /* @__PURE__ */ new Map();
|
|
8733
8779
|
if (!tokens) return props;
|
|
8734
8780
|
for (const scheme of ["light", "dark"]) {
|
|
8735
|
-
for (const [name,
|
|
8736
|
-
const
|
|
8737
|
-
if (
|
|
8781
|
+
for (const [name, prop] of Object.entries(COLOR_VARS)) {
|
|
8782
|
+
const value = tokens[scheme]?.[name] ?? tokens.colors?.[name];
|
|
8783
|
+
if (value) props.set(`${prop}-${scheme}`, value);
|
|
8738
8784
|
}
|
|
8739
8785
|
}
|
|
8740
8786
|
for (const [name, prop] of Object.entries(SIZE_VARS)) {
|
|
@@ -8810,6 +8856,260 @@ function sourceDeleteForward(state, next) {
|
|
|
8810
8856
|
if (from === text.length) return null;
|
|
8811
8857
|
return edit(state, from, next(text, from), "", from);
|
|
8812
8858
|
}
|
|
8859
|
+
var QUOTE_MARKERS = /^(?: {0,3}>[ \t]?)*/;
|
|
8860
|
+
var LIST_MARKER = /^(?:([-*+])|(\d{1,9})([.)]))(?=[ \t]|$)/;
|
|
8861
|
+
var THEMATIC_BREAK = /^([-*_])[ \t]*(?:\1[ \t]*){2,}$/;
|
|
8862
|
+
var FENCE = /^(`{3,}|~{3,})(.*)$/;
|
|
8863
|
+
function columns(space, start = 0) {
|
|
8864
|
+
let col = start;
|
|
8865
|
+
for (const c of space) col = c === " " ? col + 4 - col % 4 : col + 1;
|
|
8866
|
+
return col - start;
|
|
8867
|
+
}
|
|
8868
|
+
function parseMarker(body, at, indent) {
|
|
8869
|
+
if (THEMATIC_BREAK.test(body)) return null;
|
|
8870
|
+
const m = LIST_MARKER.exec(body);
|
|
8871
|
+
if (!m) return null;
|
|
8872
|
+
let pos = m[0].length;
|
|
8873
|
+
const space = /^[ \t]*/.exec(body.slice(pos))[0];
|
|
8874
|
+
const width = columns(space, indent + pos);
|
|
8875
|
+
pos += space.length;
|
|
8876
|
+
let box = -1;
|
|
8877
|
+
if (space && /^\[[ xX]\](?=[ \t]|$)/.test(body.slice(pos))) {
|
|
8878
|
+
box = at + pos;
|
|
8879
|
+
pos += 3;
|
|
8880
|
+
pos += /^[ \t]*/.exec(body.slice(pos))[0].length;
|
|
8881
|
+
}
|
|
8882
|
+
return {
|
|
8883
|
+
ordered: !m[1],
|
|
8884
|
+
char: m[1] ?? m[3],
|
|
8885
|
+
number: m[2] ? Number(m[2]) : 0,
|
|
8886
|
+
from: at,
|
|
8887
|
+
to: at + m[0].length,
|
|
8888
|
+
spaced: space.length > 0,
|
|
8889
|
+
box,
|
|
8890
|
+
content: at + pos,
|
|
8891
|
+
// CommonMark: one to four spaces after the marker set the text's column; more start indented code.
|
|
8892
|
+
column: indent + m[0].length + (width >= 1 && width <= 4 ? width : 1)
|
|
8893
|
+
};
|
|
8894
|
+
}
|
|
8895
|
+
function sourceLines(text) {
|
|
8896
|
+
const lines = [];
|
|
8897
|
+
let fence = null;
|
|
8898
|
+
for (let from = 0; ; ) {
|
|
8899
|
+
const nl = text.indexOf("\n", from);
|
|
8900
|
+
const to = nl === -1 ? text.length : nl;
|
|
8901
|
+
const line = text.slice(from, to);
|
|
8902
|
+
const quote2 = QUOTE_MARKERS.exec(line)[0];
|
|
8903
|
+
const space = /^[ \t]*/.exec(line.slice(quote2.length))[0];
|
|
8904
|
+
const indentEnd = from + quote2.length + space.length;
|
|
8905
|
+
const body = line.slice(quote2.length + space.length);
|
|
8906
|
+
const indent = columns(space);
|
|
8907
|
+
let code = fence !== null;
|
|
8908
|
+
const f = FENCE.exec(body);
|
|
8909
|
+
if (fence) {
|
|
8910
|
+
if (f && f[1][0] === fence.char && f[1].length >= fence.length && f[2].trim() === "") fence = null;
|
|
8911
|
+
} else if (f && !(f[1][0] === "`" && f[2].includes("`"))) {
|
|
8912
|
+
fence = { char: f[1][0], length: f[1].length };
|
|
8913
|
+
code = true;
|
|
8914
|
+
}
|
|
8915
|
+
lines.push({
|
|
8916
|
+
from,
|
|
8917
|
+
to,
|
|
8918
|
+
depth: quote2.split(">").length - 1,
|
|
8919
|
+
quoteEnd: from + quote2.length,
|
|
8920
|
+
indent,
|
|
8921
|
+
indentEnd,
|
|
8922
|
+
blank: body.trim() === "",
|
|
8923
|
+
item: code ? null : parseMarker(body, indentEnd, indent)
|
|
8924
|
+
});
|
|
8925
|
+
if (nl === -1) return lines;
|
|
8926
|
+
from = nl + 1;
|
|
8927
|
+
}
|
|
8928
|
+
}
|
|
8929
|
+
function mayBeItem(text, offset) {
|
|
8930
|
+
const end = text.indexOf("\n", offset);
|
|
8931
|
+
const line = text.slice(text.lastIndexOf("\n", offset - 1) + 1, end === -1 ? text.length : end);
|
|
8932
|
+
return LIST_MARKER.test(line.replace(QUOTE_MARKERS, "").trimStart());
|
|
8933
|
+
}
|
|
8934
|
+
function lineAt(lines, offset) {
|
|
8935
|
+
let i = 0;
|
|
8936
|
+
while (i + 1 < lines.length && lines[i + 1].from <= offset) i++;
|
|
8937
|
+
return i;
|
|
8938
|
+
}
|
|
8939
|
+
function previousSibling(lines, i) {
|
|
8940
|
+
const line = lines[i];
|
|
8941
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
8942
|
+
const l = lines[j];
|
|
8943
|
+
if (l.blank) continue;
|
|
8944
|
+
if (l.depth !== line.depth) return -1;
|
|
8945
|
+
if (l.indent > line.indent) continue;
|
|
8946
|
+
return l.item && l.indent === line.indent ? j : -1;
|
|
8947
|
+
}
|
|
8948
|
+
return -1;
|
|
8949
|
+
}
|
|
8950
|
+
function parentItem(lines, i) {
|
|
8951
|
+
const line = lines[i];
|
|
8952
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
8953
|
+
const l = lines[j];
|
|
8954
|
+
if (l.blank) continue;
|
|
8955
|
+
if (l.depth !== line.depth) return -1;
|
|
8956
|
+
if (l.indent < line.indent) return l.item ? j : -1;
|
|
8957
|
+
}
|
|
8958
|
+
return -1;
|
|
8959
|
+
}
|
|
8960
|
+
function listRun(lines, i) {
|
|
8961
|
+
const line = lines[i];
|
|
8962
|
+
const item = line.item;
|
|
8963
|
+
const same = (l) => l.item !== null && l.indent === line.indent && l.item.ordered === item.ordered && l.item.char === item.char;
|
|
8964
|
+
const run = [i];
|
|
8965
|
+
for (const step of [-1, 1]) {
|
|
8966
|
+
for (let j = i + step; j >= 0 && j < lines.length; j += step) {
|
|
8967
|
+
const l = lines[j];
|
|
8968
|
+
if (l.blank) continue;
|
|
8969
|
+
if (l.depth !== line.depth) break;
|
|
8970
|
+
if (l.indent > line.indent) continue;
|
|
8971
|
+
if (!same(l)) break;
|
|
8972
|
+
if (step < 0) run.unshift(j);
|
|
8973
|
+
else run.push(j);
|
|
8974
|
+
}
|
|
8975
|
+
}
|
|
8976
|
+
return run;
|
|
8977
|
+
}
|
|
8978
|
+
function renumber(lines, targets, fresh) {
|
|
8979
|
+
const changes = [];
|
|
8980
|
+
const done = /* @__PURE__ */ new Set();
|
|
8981
|
+
for (const target of targets) {
|
|
8982
|
+
if (!lines[target]?.item?.ordered) continue;
|
|
8983
|
+
const run = listRun(lines, target);
|
|
8984
|
+
if (done.has(run[0])) continue;
|
|
8985
|
+
done.add(run[0]);
|
|
8986
|
+
const settled = run.filter((j) => !fresh.has(j)).map((j) => lines[j].item.number);
|
|
8987
|
+
const lazy = settled.length >= 2 && settled.every((n) => n === settled[0]);
|
|
8988
|
+
const start = fresh.has(run[0]) ? 1 : lines[run[0]].item.number;
|
|
8989
|
+
run.forEach((j, k) => {
|
|
8990
|
+
const item = lines[j].item;
|
|
8991
|
+
const number = lazy ? fresh.has(j) ? settled[0] : item.number : start + k;
|
|
8992
|
+
if (number !== item.number) changes.push({ from: item.from, to: item.to - 1, insert: String(number) });
|
|
8993
|
+
});
|
|
8994
|
+
}
|
|
8995
|
+
return changes;
|
|
8996
|
+
}
|
|
8997
|
+
function mapThrough(offset, changes) {
|
|
8998
|
+
let shift = 0;
|
|
8999
|
+
for (const c of changes) {
|
|
9000
|
+
if (c.from > offset || c.from === offset && c.to > c.from) break;
|
|
9001
|
+
if (offset >= c.to) shift += c.insert.length - (c.to - c.from);
|
|
9002
|
+
else return c.from + shift + Math.min(offset - c.from, c.insert.length);
|
|
9003
|
+
}
|
|
9004
|
+
return offset + shift;
|
|
9005
|
+
}
|
|
9006
|
+
function applyChanges(text, changes) {
|
|
9007
|
+
let out = "";
|
|
9008
|
+
let last = 0;
|
|
9009
|
+
for (const c of changes) {
|
|
9010
|
+
out += text.slice(last, c.from) + c.insert;
|
|
9011
|
+
last = c.to;
|
|
9012
|
+
}
|
|
9013
|
+
return out + text.slice(last);
|
|
9014
|
+
}
|
|
9015
|
+
function finish(text, changes, anchor, focus, targets, fresh, mapped = false) {
|
|
9016
|
+
changes.sort((a2, b) => a2.from - b.from);
|
|
9017
|
+
let next = applyChanges(text, changes);
|
|
9018
|
+
let a = mapped ? anchor : mapThrough(anchor, changes);
|
|
9019
|
+
let f = mapped ? focus : mapThrough(focus, changes);
|
|
9020
|
+
const lines = sourceLines(next);
|
|
9021
|
+
const numbers = renumber(
|
|
9022
|
+
lines,
|
|
9023
|
+
targets.map((o) => lineAt(lines, o)),
|
|
9024
|
+
new Set(fresh.map((o) => lineAt(lines, o)))
|
|
9025
|
+
);
|
|
9026
|
+
if (numbers.length) {
|
|
9027
|
+
next = applyChanges(next, numbers);
|
|
9028
|
+
a = mapThrough(a, numbers);
|
|
9029
|
+
f = mapThrough(f, numbers);
|
|
9030
|
+
}
|
|
9031
|
+
return sourceState(next, a, f);
|
|
9032
|
+
}
|
|
9033
|
+
function shiftItems(text, lines, first, last, delta2, anchor, focus) {
|
|
9034
|
+
const line = lines[first];
|
|
9035
|
+
let end = last;
|
|
9036
|
+
for (let j = last + 1; j < lines.length; j++) {
|
|
9037
|
+
const l = lines[j];
|
|
9038
|
+
if (l.blank) continue;
|
|
9039
|
+
if (l.depth !== line.depth || l.indent <= lines[last].indent) break;
|
|
9040
|
+
end = j;
|
|
9041
|
+
}
|
|
9042
|
+
const changes = [];
|
|
9043
|
+
for (let j = first; j <= end; j++) {
|
|
9044
|
+
const l = lines[j];
|
|
9045
|
+
if (l.blank || l.depth !== line.depth) continue;
|
|
9046
|
+
changes.push({ from: l.quoteEnd, to: l.indentEnd, insert: " ".repeat(Math.max(0, l.indent + delta2)) });
|
|
9047
|
+
}
|
|
9048
|
+
let after = -1;
|
|
9049
|
+
for (let j = end + 1; j < lines.length; j++) {
|
|
9050
|
+
const l = lines[j];
|
|
9051
|
+
if (l.blank) continue;
|
|
9052
|
+
if (l.depth === line.depth && l.indent === line.indent && l.item) after = j;
|
|
9053
|
+
break;
|
|
9054
|
+
}
|
|
9055
|
+
const moved = mapThrough(line.indentEnd, changes);
|
|
9056
|
+
const following = after === -1 ? [] : [mapThrough(lines[after].indentEnd, changes)];
|
|
9057
|
+
return finish(text, changes, anchor, focus, [moved, ...following], [moved, ...delta2 < 0 ? following : []]);
|
|
9058
|
+
}
|
|
9059
|
+
function sourceEnter(state) {
|
|
9060
|
+
const { from, to } = sourceRange(state);
|
|
9061
|
+
const whole = sourceText(state.doc);
|
|
9062
|
+
const text = whole.slice(0, from) + whole.slice(to);
|
|
9063
|
+
if (!mayBeItem(text, from)) return insertSourceText(state, "\n");
|
|
9064
|
+
const lines = sourceLines(text);
|
|
9065
|
+
const i = lineAt(lines, from);
|
|
9066
|
+
const line = lines[i];
|
|
9067
|
+
const item = line.item;
|
|
9068
|
+
if (!item || !item.spaced || from < item.content) return insertSourceText(state, "\n");
|
|
9069
|
+
if (text.slice(item.content, line.to).trim() === "") {
|
|
9070
|
+
const parent = parentItem(lines, i);
|
|
9071
|
+
if (line.indent > 0 && parent !== -1) return shiftItems(text, lines, i, i, lines[parent].indent - line.indent, line.to, line.to);
|
|
9072
|
+
const next = lines.findIndex((l, j) => j > i && !l.blank);
|
|
9073
|
+
const changes2 = [{ from: line.quoteEnd, to: line.to, insert: "" }];
|
|
9074
|
+
const targets = next === -1 || !lines[next].item ? [] : [mapThrough(lines[next].indentEnd, changes2)];
|
|
9075
|
+
return finish(text, changes2, line.quoteEnd, line.quoteEnd, targets, []);
|
|
9076
|
+
}
|
|
9077
|
+
const marker = item.ordered ? `${item.number + 1}${item.char}` : item.char;
|
|
9078
|
+
const space = text.slice(item.to, item.box === -1 ? item.content : item.box);
|
|
9079
|
+
const box = item.box === -1 ? "" : "[ ]" + (text.slice(item.box + 3, item.content) || " ");
|
|
9080
|
+
const head = text.slice(line.from, line.indentEnd) + marker + space + box;
|
|
9081
|
+
const restStart = from + /^[ \t]*/.exec(text.slice(from, line.to))[0].length;
|
|
9082
|
+
const changes = [{ from, to: restStart, insert: "\n" + head }];
|
|
9083
|
+
const caret2 = from + 1 + head.length;
|
|
9084
|
+
return finish(text, changes, caret2, caret2, [caret2], [caret2], true);
|
|
9085
|
+
}
|
|
9086
|
+
function sourceIndentList(state, delta2) {
|
|
9087
|
+
const { from, to } = sourceRange(state);
|
|
9088
|
+
const text = sourceText(state.doc);
|
|
9089
|
+
if (!mayBeItem(text, from)) return null;
|
|
9090
|
+
const lines = sourceLines(text);
|
|
9091
|
+
const first = lineAt(lines, from);
|
|
9092
|
+
let last = lineAt(lines, to);
|
|
9093
|
+
if (last > first && to === lines[last].from) last--;
|
|
9094
|
+
const line = lines[first];
|
|
9095
|
+
if (!line.item) return null;
|
|
9096
|
+
for (let j = first + 1; j <= last; j++) {
|
|
9097
|
+
const l = lines[j];
|
|
9098
|
+
if (!l.blank && (l.depth !== line.depth || !l.item && l.indent <= line.indent)) return null;
|
|
9099
|
+
}
|
|
9100
|
+
let target;
|
|
9101
|
+
if (delta2 === 1) {
|
|
9102
|
+
const sibling = previousSibling(lines, first);
|
|
9103
|
+
if (sibling === -1) return state;
|
|
9104
|
+
target = lines[sibling].item.column;
|
|
9105
|
+
} else {
|
|
9106
|
+
if (line.indent === 0) return state;
|
|
9107
|
+
const parent = parentItem(lines, first);
|
|
9108
|
+
target = parent === -1 ? 0 : lines[parent].indent;
|
|
9109
|
+
}
|
|
9110
|
+
if (target === line.indent) return state;
|
|
9111
|
+
return shiftItems(text, lines, first, last, target - line.indent, state.selection.anchor.offset, state.selection.focus.offset);
|
|
9112
|
+
}
|
|
8813
9113
|
function mapOffset(offset, before, after) {
|
|
8814
9114
|
if (before === after) return offset;
|
|
8815
9115
|
let start = 0;
|
|
@@ -9005,6 +9305,7 @@ var Editor = class {
|
|
|
9005
9305
|
wasReadOnly = false;
|
|
9006
9306
|
/** Task checkboxes stay usable while read-only. */
|
|
9007
9307
|
taskToggle;
|
|
9308
|
+
smartLists;
|
|
9008
9309
|
options;
|
|
9009
9310
|
/** The extensions in priority order, ending with the default keymap unless one was given. */
|
|
9010
9311
|
extensions;
|
|
@@ -9071,6 +9372,7 @@ var Editor = class {
|
|
|
9071
9372
|
this.labels = { ...DEFAULT_LABELS, ...options.labels };
|
|
9072
9373
|
this.readOnly = options.editable === false;
|
|
9073
9374
|
this.taskToggle = options.taskToggle === true;
|
|
9375
|
+
this.smartLists = options.smartLists !== false;
|
|
9074
9376
|
const given = options.extensions ?? [];
|
|
9075
9377
|
this.extensions = given.some((e) => e.name === "defaultKeymap") ? given : [...given, defaultKeymap()];
|
|
9076
9378
|
this.bindings = this.extensions.flatMap(
|
|
@@ -9689,8 +9991,9 @@ var Editor = class {
|
|
|
9689
9991
|
const richFn = rich[name];
|
|
9690
9992
|
commands[name] = (...args) => this.modeValue === "source" ? fn ? fn(...args) : false : richFn(...args);
|
|
9691
9993
|
};
|
|
9692
|
-
|
|
9693
|
-
inSource("
|
|
9994
|
+
const indentSource = (delta2) => run((s) => (this.smartLists ? sourceIndentList(s, delta2) : null) ?? indentCode(s, delta2));
|
|
9995
|
+
inSource("indent", () => indentSource(1));
|
|
9996
|
+
inSource("outdent", () => indentSource(-1));
|
|
9694
9997
|
inSource("insertMarkdown", (markdown, options = {}) => this.insertSourceMarkdown(markdown, options));
|
|
9695
9998
|
for (const name of [
|
|
9696
9999
|
"toggleBold",
|
|
@@ -10413,6 +10716,8 @@ var Editor = class {
|
|
|
10413
10716
|
onSourceInput(type) {
|
|
10414
10717
|
switch (type) {
|
|
10415
10718
|
case "insertParagraph":
|
|
10719
|
+
this.run((s) => this.smartLists ? sourceEnter(s) : insertSourceText(s, "\n"));
|
|
10720
|
+
return true;
|
|
10416
10721
|
case "insertLineBreak":
|
|
10417
10722
|
this.run((s) => insertSourceText(s, "\n"));
|
|
10418
10723
|
return true;
|
|
@@ -12239,6 +12544,7 @@ export {
|
|
|
12239
12544
|
setLinkInRange,
|
|
12240
12545
|
setMarkInRange,
|
|
12241
12546
|
setTokenInRange,
|
|
12547
|
+
shadcnTheme,
|
|
12242
12548
|
sliceInline,
|
|
12243
12549
|
sortMarks,
|
|
12244
12550
|
startOf,
|