@usememos/editor 26.10.23 → 26.10.25
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 +23 -8
- package/dist/base.css +16 -5
- package/dist/index.js +130 -27
- package/dist/index.js.map +3 -3
- package/dist/style.css +64 -10
- package/dist/theme.css +38 -12
- package/dist/types/icons.d.ts +2 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/labels.d.ts +3 -0
- package/dist/types/theme.d.ts +0 -7
- package/dist/types/view/dom.d.ts +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
|
|
|
50
50
|
| `value` | `string` | React only. The editor updates only when `value` differs from the last Markdown it emitted. |
|
|
51
51
|
| `defaultValue` | `string` | React only. Initial Markdown for uncontrolled use. |
|
|
52
52
|
| `markdown` | `{ breaks?, setext?, autolinks?, callouts?, details? }` | Markdown dialect. `breaks: true` reads a single newline as a line break and saves line breaks as plain newlines (as GitHub comments do). `setext: false` turns off setext headings, so `Title`⏎`---` is a paragraph and a divider. `autolinks: false` turns off GFM autolink literals, so a bare `https://…`, `www.…` or e-mail address stays text. `callouts: false` reads a GitHub alert such as `> [!NOTE]` as a plain quote and drops Callout from the slash menu. `details: false` reads `<details>` as raw HTML and drops Collapsible section from the slash menu. See [docs/syntax.md](docs/syntax.md). |
|
|
53
|
-
| `extensions` | `Extension[]` | Adds syntax and behavior. Built in: `math()` (`$…$` and `$$` blocks), `footnotes()` (`[^1]` and `[^1]: …`, shown as a raised label and a small note; `footnotes({ render: false })` keeps the source), `tags()` (`#tag`) and `mentions()` (`@name`). Extension syntax is saved verbatim, and shown as source unless the extension renders it (see `views`). |
|
|
53
|
+
| `extensions` | `Extension[]` | Adds syntax and behavior. Built in: `math()` (`$…$` and `$$` blocks), `footnotes()` (`[^1]` and `[^1]: …`, shown as a raised label and a small note whose text renders as Markdown, collected at the end as on GitHub when read-only; `footnotes({ render: false })` keeps the source), `tags()` (`#tag`) and `mentions()` (`@name`). Extension syntax is saved verbatim, and shown as source unless the extension renders it (see `views`). |
|
|
54
54
|
| `placeholder` | `string` | Shown when the document is empty. |
|
|
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`. |
|
|
@@ -286,7 +286,7 @@ const linkCardsBelow: Extension = {
|
|
|
286
286
|
|
|
287
287
|
### Theming
|
|
288
288
|
|
|
289
|
-
`style.css` is two stylesheets: `base.css` holds the layout the editor needs and all spacing between blocks, and `theme.css` the default look. The default look is quiet and compact, like a rendered Markdown view: a 16px body with 24px lines, 8px between blocks, headings close to the body size, muted quotes and list markers, code blocks on a light panel with no border whose long lines scroll sideways rather than wrap, and tables
|
|
289
|
+
`style.css` is two stylesheets: `base.css` holds the layout the editor needs and all spacing between blocks, and `theme.css` the default look. The default look is quiet and compact, like a rendered Markdown view: a 16px body with 24px lines, 8px between blocks, headings close to the body size, muted quotes and list markers, code blocks on a light panel with no border whose long lines scroll sideways rather than wrap, and tables that fill the width inside a round frame, with a tinted header row, a line between rows and no vertical lines, as claude.ai renders them. Editing and read-only look the same; only the cursor on links and checkboxes changes. It has no border or background of its own, so it fits inside your own card, comment box or chat input.
|
|
290
290
|
|
|
291
291
|
Every color, font and size in `theme.css` is a CSS custom property (`--mbe-text`, `--mbe-accent`, `--mbe-font`, …). Set them with the `theme` option's tokens, with a color set for light and one for dark; colors you leave out keep the defaults:
|
|
292
292
|
|
|
@@ -309,13 +309,28 @@ Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `b
|
|
|
309
309
|
|
|
310
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
311
|
|
|
312
|
-
|
|
312
|
+
An app that keeps its palette in CSS variables passes them as the values, and the editor follows the app's theme, light and dark included, since the variables change with it. With the names most Tailwind-based component kits use:
|
|
313
313
|
|
|
314
314
|
```ts
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
new Editor({
|
|
316
|
+
element,
|
|
317
|
+
theme: {
|
|
318
|
+
tokens: {
|
|
319
|
+
colors: {
|
|
320
|
+
text: 'var(--foreground)',
|
|
321
|
+
muted: 'var(--muted-foreground)',
|
|
322
|
+
accent: 'var(--primary)',
|
|
323
|
+
codeBackground: 'var(--muted)',
|
|
324
|
+
border: 'var(--border)',
|
|
325
|
+
popupBackground: 'var(--popover)',
|
|
326
|
+
hover: 'var(--accent)',
|
|
327
|
+
danger: 'var(--destructive)',
|
|
328
|
+
},
|
|
329
|
+
font: 'inherit',
|
|
330
|
+
radius: 'calc(var(--radius) - 2px)',
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
});
|
|
319
334
|
```
|
|
320
335
|
|
|
321
336
|
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:
|
|
@@ -328,7 +343,7 @@ The same tokens can be set in CSS, with no JavaScript, as `--mbe-<name>-light` a
|
|
|
328
343
|
}
|
|
329
344
|
```
|
|
330
345
|
|
|
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
|
|
346
|
+
`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-style theming toggles 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.
|
|
332
347
|
|
|
333
348
|
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:
|
|
334
349
|
|
package/dist/base.css
CHANGED
|
@@ -255,6 +255,13 @@
|
|
|
255
255
|
.mbe-root > .mbe-block-view { overflow: visible; }
|
|
256
256
|
/* A block view placed after its block, which stays editable text: not text itself, like a widget. */
|
|
257
257
|
.mbe-root > .mbe-block-after { cursor: default; white-space: normal; }
|
|
258
|
+
/* Footnotes, read-only: the definitions hide where they are written and the
|
|
259
|
+
referenced ones are collected in a section at the end (see footnotes()). */
|
|
260
|
+
.mbe-root > .mbe-footnote-collected { display: none; }
|
|
261
|
+
.mbe-root > .mbe-footnotes { margin-top: 16px; cursor: default; }
|
|
262
|
+
.mbe-root > .mbe-footnotes > .mbe-footnote + .mbe-footnote { margin-top: 4px; }
|
|
263
|
+
.mbe-root .mbe-footnote-backref { display: inline-flex; align-items: center; vertical-align: -0.125em; }
|
|
264
|
+
.mbe-root .mbe-footnote-backref .mbe-icon { width: 0.875em; height: 0.875em; }
|
|
258
265
|
/* Tags and mentions with an onClick, read-only: clickable, as links are. */
|
|
259
266
|
.mbe-root.mbe-readonly :is([data-mbe-tag], [data-mbe-mention]) { cursor: pointer; }
|
|
260
267
|
/* Rendered HTML: line breaks between its tags are not text. The Markdown
|
|
@@ -281,15 +288,19 @@
|
|
|
281
288
|
|
|
282
289
|
/* Table */
|
|
283
290
|
:is(.mbe-root, .mbe-flow) > .mbe-table { overflow-x: auto; }
|
|
284
|
-
/*
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
291
|
+
/* The table fills the editor's width and its columns share it by their
|
|
292
|
+
content, as claude.ai lays tables out; one whose longest words do not
|
|
293
|
+
fit scrolls. Cells wrap at words: the root's overflow-wrap: anywhere
|
|
294
|
+
would let the layout shrink any column to one character and break words
|
|
295
|
+
to make the table fit, break-word keeps every column as wide as its
|
|
296
|
+
longest word. */
|
|
297
|
+
:is(.mbe-root, .mbe-flow) > .mbe-table table { width: 100%; border-collapse: separate; border-spacing: 0; }
|
|
288
298
|
:is(.mbe-root, .mbe-flow) > .mbe-table th,
|
|
289
299
|
:is(.mbe-root, .mbe-flow) > .mbe-table td {
|
|
290
|
-
padding:
|
|
300
|
+
padding: 0.4375em 0.75em;
|
|
291
301
|
vertical-align: top;
|
|
292
302
|
text-align: start;
|
|
303
|
+
overflow-wrap: break-word;
|
|
293
304
|
outline: none;
|
|
294
305
|
}
|
|
295
306
|
/* An empty cell keeps room to click into while editing. */
|
package/dist/index.js
CHANGED
|
@@ -2424,6 +2424,9 @@ var DEFAULT_LABELS = {
|
|
|
2424
2424
|
todoList: "To-do list",
|
|
2425
2425
|
/** Accessible name of a task checkbox whose item has no text. */
|
|
2426
2426
|
task: "Task",
|
|
2427
|
+
/** The footnotes collected at the end of a read-only document, and a note's backlink to its reference. */
|
|
2428
|
+
footnotes: "Footnotes",
|
|
2429
|
+
backToReference: "Back to reference",
|
|
2427
2430
|
quote: "Quote",
|
|
2428
2431
|
/** The slash menu item, and the title of a callout's block menu section. */
|
|
2429
2432
|
callout: "Callout",
|
|
@@ -2563,6 +2566,8 @@ var ICONS = {
|
|
|
2563
2566
|
delete: TRASH,
|
|
2564
2567
|
/** `arrow-up` */
|
|
2565
2568
|
addRowAbove: ["m5 12 7-7 7 7", "M12 19V5"],
|
|
2569
|
+
/** `arrow-up`: a footnote's backlink to its reference. */
|
|
2570
|
+
backToReference: ["m5 12 7-7 7 7", "M12 19V5"],
|
|
2566
2571
|
/** `arrow-down` */
|
|
2567
2572
|
addRowBelow: ["M12 5v14", "m19 12-7 7-7-7"],
|
|
2568
2573
|
/** `arrow-left` */
|
|
@@ -7342,9 +7347,11 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
7342
7347
|
}
|
|
7343
7348
|
case "raw": {
|
|
7344
7349
|
const source = inlineText(block3.content);
|
|
7345
|
-
const
|
|
7346
|
-
const
|
|
7347
|
-
const
|
|
7350
|
+
const revealed = reveal?.has(REVEAL_BLOCK) === true;
|
|
7351
|
+
const section = block3.syntax === "html" && !revealed && ctx.views?.has("html") ? splitHtmlSection(source, ctx.markdown) : null;
|
|
7352
|
+
const footnote = block3.syntax === "footnote" && !revealed && ctx.views?.has("footnote") ? splitFootnote(source) : null;
|
|
7353
|
+
const nested = block3.syntax === "markdown" && !revealed && ctx.views?.get("markdown") === MARKDOWN_VIEW;
|
|
7354
|
+
const view = revealed ? null : nested ? renderMarkdown(source, ctx) : footnote ? renderFootnote(footnote, ctx) : ctx.view?.(block3.syntax, section ? section.html : source, "block");
|
|
7348
7355
|
if (view) {
|
|
7349
7356
|
root = view;
|
|
7350
7357
|
root.classList.add("mbe-view-block");
|
|
@@ -7496,6 +7503,30 @@ function appendBlocks(flow, blocks, ctx) {
|
|
|
7496
7503
|
}
|
|
7497
7504
|
updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new Set(), ctx.labels);
|
|
7498
7505
|
}
|
|
7506
|
+
var FOOTNOTE_DEFINITION = /^(\[\^((?:[^\]\s\\]|\\.)+)\]:)[ \t]*([\s\S]*)$/;
|
|
7507
|
+
var FOOTNOTE_REFERENCE = /\[\^((?:[^\]\s\\]|\\.)+)\]/g;
|
|
7508
|
+
var unescapeLabel = (label) => label.replace(/\\(.)/g, "$1");
|
|
7509
|
+
function splitFootnote(source) {
|
|
7510
|
+
const m = FOOTNOTE_DEFINITION.exec(source);
|
|
7511
|
+
return m ? { label: unescapeLabel(m[2]), head: `${m[1]} `, body: m[3] } : null;
|
|
7512
|
+
}
|
|
7513
|
+
function renderFootnote(definition, ctx) {
|
|
7514
|
+
const el = ctx.view?.("footnote", definition.head + slotMarker(0), "block") ?? null;
|
|
7515
|
+
if (el) fillSlots(el, 1, () => renderInlineMarkdown(definition.body, ctx), ctx.doc);
|
|
7516
|
+
return el;
|
|
7517
|
+
}
|
|
7518
|
+
function renderInlineMarkdown(source, ctx) {
|
|
7519
|
+
const flow = renderNodes(parseAst(source, ctx.markdown).children, ctx);
|
|
7520
|
+
const only = flow.childNodes.length === 1 ? flow.firstElementChild : null;
|
|
7521
|
+
if (flow.childNodes.length === 0 || only && only.tagName === "P") {
|
|
7522
|
+
const span = ctx.doc.createElement("span");
|
|
7523
|
+
if (only) span.append(...Array.from(only.childNodes));
|
|
7524
|
+
makeInert(span);
|
|
7525
|
+
return span;
|
|
7526
|
+
}
|
|
7527
|
+
makeInert(flow);
|
|
7528
|
+
return flow;
|
|
7529
|
+
}
|
|
7499
7530
|
var MARKDOWN_VIEW = () => false;
|
|
7500
7531
|
function renderMarkdown(source, ctx) {
|
|
7501
7532
|
const root = ctx.doc.createElement("div");
|
|
@@ -7850,6 +7881,14 @@ var BlockRenderer = class {
|
|
|
7850
7881
|
widgetsAfter;
|
|
7851
7882
|
/** Views of extension syntaxes, by syntax name. */
|
|
7852
7883
|
views;
|
|
7884
|
+
/**
|
|
7885
|
+
* Read-only: footnote definitions hide where they are written and the
|
|
7886
|
+
* referenced ones show again, in order of first reference, in a section
|
|
7887
|
+
* at the end of the document (see `footnoteSection`).
|
|
7888
|
+
*/
|
|
7889
|
+
collectFootnotes = false;
|
|
7890
|
+
/** The last footnote section, kept while what it shows is the same. */
|
|
7891
|
+
footnotes;
|
|
7853
7892
|
/** What a view gets besides its source: the editor. Set with `views`. */
|
|
7854
7893
|
viewContext;
|
|
7855
7894
|
/** Block views of extensions, with the extension's name, in extension order. */
|
|
@@ -8101,6 +8140,12 @@ var BlockRenderer = class {
|
|
|
8101
8140
|
}
|
|
8102
8141
|
this.loadedImages.clear();
|
|
8103
8142
|
for (const [id, entry] of [...this.hosted]) if (next.get(id)?.block !== entry.block) this.disposeHosted(id);
|
|
8143
|
+
const collecting = this.collectFootnotes && this.views?.has("footnote") === true;
|
|
8144
|
+
for (const { block: block3, el } of next.values()) {
|
|
8145
|
+
if (block3.type === "raw" && block3.syntax === "footnote") el.classList.toggle("mbe-footnote-collected", collecting);
|
|
8146
|
+
}
|
|
8147
|
+
const footnotes2 = collecting ? this.footnoteSection(doc, next, ctx, force) : null;
|
|
8148
|
+
if (!collecting) this.footnotes = void 0;
|
|
8104
8149
|
const nodes = [];
|
|
8105
8150
|
for (const [id, { block: block3, el, reveal }] of next) {
|
|
8106
8151
|
nodes.push(el);
|
|
@@ -8109,6 +8154,7 @@ var BlockRenderer = class {
|
|
|
8109
8154
|
const widgets = this.widgetsAfter?.(id);
|
|
8110
8155
|
if (widgets) nodes.push(...widgets);
|
|
8111
8156
|
}
|
|
8157
|
+
if (footnotes2) nodes.push(footnotes2);
|
|
8112
8158
|
if (force || this.rendered.size === 0) {
|
|
8113
8159
|
const fragment = this.root.ownerDocument.createDocumentFragment();
|
|
8114
8160
|
for (const el of nodes) {
|
|
@@ -8137,6 +8183,68 @@ var BlockRenderer = class {
|
|
|
8137
8183
|
this.rendered = next;
|
|
8138
8184
|
updateNeighborMarks(doc, (id) => next.get(id)?.el, this.numbers, this.collapsed, this.labels);
|
|
8139
8185
|
}
|
|
8186
|
+
/**
|
|
8187
|
+
* The footnotes section, as GitHub renders one: every definition that is
|
|
8188
|
+
* referenced, in order of first reference, each rendered as its block is
|
|
8189
|
+
* (see `renderFootnote`) with a backlink per reference. Definitions nothing
|
|
8190
|
+
* references are left out. Null when there is nothing to show. The element
|
|
8191
|
+
* is kept while the definitions and references are the same.
|
|
8192
|
+
*/
|
|
8193
|
+
footnoteSection(doc, next, ctx, force) {
|
|
8194
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
8195
|
+
for (const block3 of doc.blocks) {
|
|
8196
|
+
if (block3.type !== "raw" || block3.syntax !== "footnote") continue;
|
|
8197
|
+
const definition = splitFootnote(inlineText(block3.content));
|
|
8198
|
+
if (definition && !definitions.has(definition.label)) definitions.set(definition.label, definition);
|
|
8199
|
+
}
|
|
8200
|
+
if (definitions.size === 0) return null;
|
|
8201
|
+
const order = [];
|
|
8202
|
+
const counts = /* @__PURE__ */ new Map();
|
|
8203
|
+
for (const block3 of doc.blocks) {
|
|
8204
|
+
const el = next.get(block3.id)?.el;
|
|
8205
|
+
if (!el) continue;
|
|
8206
|
+
for (const ref of Array.from(el.querySelectorAll(".mbe-view-footnote"))) {
|
|
8207
|
+
for (const m of (ref.dataset.source ?? "").matchAll(FOOTNOTE_REFERENCE)) {
|
|
8208
|
+
const label = unescapeLabel(m[1]);
|
|
8209
|
+
if (!definitions.has(label)) continue;
|
|
8210
|
+
const count = (counts.get(label) ?? 0) + 1;
|
|
8211
|
+
counts.set(label, count);
|
|
8212
|
+
if (count === 1) order.push(label);
|
|
8213
|
+
}
|
|
8214
|
+
}
|
|
8215
|
+
}
|
|
8216
|
+
if (order.length === 0) return null;
|
|
8217
|
+
const key = JSON.stringify(order.map((label) => [label, definitions.get(label).body, counts.get(label)]));
|
|
8218
|
+
if (!force && this.footnotes?.key === key) return this.footnotes.el;
|
|
8219
|
+
const section = ctx.doc.createElement("section");
|
|
8220
|
+
section.className = "mbe-footnotes";
|
|
8221
|
+
section.contentEditable = "false";
|
|
8222
|
+
section.setAttribute("aria-label", this.labels.footnotes);
|
|
8223
|
+
for (const label of order) {
|
|
8224
|
+
const item = renderFootnote(definitions.get(label), ctx);
|
|
8225
|
+
if (!item) continue;
|
|
8226
|
+
for (let i = 1; i <= counts.get(label); i++) {
|
|
8227
|
+
const back = ctx.doc.createElement("button");
|
|
8228
|
+
back.type = "button";
|
|
8229
|
+
back.className = "mbe-footnote-backref";
|
|
8230
|
+
back.dataset.label = label;
|
|
8231
|
+
back.dataset.ref = String(i);
|
|
8232
|
+
back.setAttribute("aria-label", `${this.labels.backToReference} ${label}${i > 1 ? ` ${i}` : ""}`);
|
|
8233
|
+
const icon = ctx.icon?.("backToReference");
|
|
8234
|
+
if (icon) back.appendChild(icon);
|
|
8235
|
+
else back.textContent = "\u2191";
|
|
8236
|
+
if (i > 1) {
|
|
8237
|
+
const sup = ctx.doc.createElement("sup");
|
|
8238
|
+
sup.textContent = String(i);
|
|
8239
|
+
back.appendChild(sup);
|
|
8240
|
+
}
|
|
8241
|
+
item.appendChild(back);
|
|
8242
|
+
}
|
|
8243
|
+
section.appendChild(item);
|
|
8244
|
+
}
|
|
8245
|
+
this.footnotes = { key, el: section };
|
|
8246
|
+
return section;
|
|
8247
|
+
}
|
|
8140
8248
|
/** Marks blocks again after `collapsed` changed, without rendering any. */
|
|
8141
8249
|
updateSections(doc) {
|
|
8142
8250
|
updateNeighborMarks(doc, (id) => this.rendered.get(id)?.el, this.numbers, this.collapsed, this.labels);
|
|
@@ -8719,23 +8827,6 @@ function delta(start, end, viewStart, viewEnd) {
|
|
|
8719
8827
|
}
|
|
8720
8828
|
|
|
8721
8829
|
// 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
|
-
};
|
|
8739
8830
|
function mergeClasses(maps) {
|
|
8740
8831
|
const out = {};
|
|
8741
8832
|
for (const map of maps) {
|
|
@@ -9739,7 +9830,8 @@ var Editor = class {
|
|
|
9739
9830
|
if (toggle) this.taskToggle = options.taskToggle === true;
|
|
9740
9831
|
if (options.editable !== void 0 && options.editable === this.readOnly) {
|
|
9741
9832
|
this.readOnly = !options.editable;
|
|
9742
|
-
this.
|
|
9833
|
+
if (this.renderer.views?.has("footnote")) this.paint();
|
|
9834
|
+
else this.refreshRevealed();
|
|
9743
9835
|
this.applyReadOnly();
|
|
9744
9836
|
this.hideUi();
|
|
9745
9837
|
} else if (toggle) {
|
|
@@ -10378,6 +10470,7 @@ var Editor = class {
|
|
|
10378
10470
|
paint(force = false, lazy = false, hadFocus = this.hasFocus()) {
|
|
10379
10471
|
const views = this.renderer.views;
|
|
10380
10472
|
if (views && !this.pointerDown && !this.composing) this.renderer.revealed = revealedViews(this.state, views, !this.readOnly && hadFocus, this.hosted);
|
|
10473
|
+
this.renderer.collectFootnotes = this.readOnly;
|
|
10381
10474
|
this.renderer.render(this.state.doc, force, lazy);
|
|
10382
10475
|
this.applyHeadingIds();
|
|
10383
10476
|
this.applyReadOnly();
|
|
@@ -12235,12 +12328,23 @@ function footnotes(options = {}) {
|
|
|
12235
12328
|
views: { footnote: (source, element, kind, ctx) => (kind === "inline" ? renderReference : renderDefinition)(source, element, kind, ctx) },
|
|
12236
12329
|
onCreate: ({ editor }) => {
|
|
12237
12330
|
const onClick = (e) => {
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
const
|
|
12241
|
-
|
|
12331
|
+
if (editor.isEditable) return;
|
|
12332
|
+
const target = e.target;
|
|
12333
|
+
const ref = target.closest?.(".mbe-footnote-ref");
|
|
12334
|
+
const back = ref ? null : target.closest?.(".mbe-footnote-backref");
|
|
12335
|
+
if (!ref && !back) return;
|
|
12336
|
+
const inSection = (el) => el.closest(".mbe-footnotes") !== null;
|
|
12337
|
+
let to;
|
|
12338
|
+
if (ref) {
|
|
12339
|
+
const notes = [...editor.root.querySelectorAll(".mbe-footnote")].filter((d) => d.dataset.label === ref.dataset.label);
|
|
12340
|
+
to = notes.find(inSection) ?? notes[0];
|
|
12341
|
+
} else if (back) {
|
|
12342
|
+
const refs = [...editor.root.querySelectorAll(".mbe-footnote-ref")].filter((r) => r.dataset.label === back.dataset.label && !inSection(r));
|
|
12343
|
+
to = refs[Number(back.dataset.ref) - 1];
|
|
12344
|
+
}
|
|
12345
|
+
if (!to) return;
|
|
12242
12346
|
e.preventDefault();
|
|
12243
|
-
|
|
12347
|
+
to.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
12244
12348
|
};
|
|
12245
12349
|
editor.root.addEventListener("click", onClick);
|
|
12246
12350
|
return () => editor.root.removeEventListener("click", onClick);
|
|
@@ -12544,7 +12648,6 @@ export {
|
|
|
12544
12648
|
setLinkInRange,
|
|
12545
12649
|
setMarkInRange,
|
|
12546
12650
|
setTokenInRange,
|
|
12547
|
-
shadcnTheme,
|
|
12548
12651
|
sliceInline,
|
|
12549
12652
|
sortMarks,
|
|
12550
12653
|
startOf,
|