@usememos/editor 26.10.14 → 26.10.15
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 +7 -7
- package/dist/base.css +52 -16
- package/dist/index.js +239 -93
- package/dist/index.js.map +3 -3
- package/dist/style.css +75 -16
- package/dist/theme.css +15 -5
- package/dist/types/commands.d.ts +3 -3
- package/dist/types/markdown/lower.d.ts +11 -1
- package/dist/types/model.d.ts +22 -2
- package/dist/types/theme.d.ts +1 -1
- package/dist/types/view/dom.d.ts +7 -1
- package/dist/types/view/reveal.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
|
|
|
68
68
|
| `slashMenu` | `false \| string[]` | Built-in slash menu items to show, in order, or `false` for none: `text`, `heading1`, `heading2`, `heading3`, `heading4`, `bulletList`, `numberedList`, `todoList`, `quote`, `callout`, `details`, `code`, `table`, `divider`. |
|
|
69
69
|
| `slashHint` | `boolean` | Shows `labels.slashHint` ("Type '/' for commands") in the empty paragraph that has the caret. Default `false`. No effect when `slashMenu` is `false`. When the document is a single empty paragraph, `placeholder` shows instead. |
|
|
70
70
|
| `labels` | `Partial<Labels>` | Overrides UI strings, for localization. See `src/labels.ts`. |
|
|
71
|
-
| `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout
|
|
71
|
+
| `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout icons and the callout menu), `openLink`, `copyLink`, `editLink` and `removeLink` (the link card), `imageAlignLeft`, `imageAlignCenter` and `imageAlignRight` (an image block's Align choices), `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
|
|
72
72
|
| `onChange` | `(markdown: string, editor) => void` | Called after document changes, at most once per animation frame. |
|
|
73
73
|
| `onSubmit` | `(markdown: string, editor) => void` | Called on Mod+Enter or Ctrl+Enter with the current Markdown, for comment boxes and chat inputs. |
|
|
74
74
|
| `onFocus`, `onBlur` | `(editor) => void` | Focus events. |
|
|
@@ -101,8 +101,8 @@ function Composer() {
|
|
|
101
101
|
| `state` | The document and selection, immutable. |
|
|
102
102
|
| `commands.*` | Edits. Each applies one change, records one undo step, and returns `true` if it did something: `toggleBold`, `toggleItalic`, `toggleStrike`, `toggleCode`, `setParagraph`, `toggleHeading({ level })`, `toggleBulletList`, `toggleOrderedList`, `toggleTaskList`, `toggleBlockquote`, `toggleCallout({ type? })`, `setCallout({ type })`, `toggleDetails`, `toggleCodeBlock({ language? })`, `setLink({ href })`, `unsetLink`, `updateImage({ alt?, title?, align?, width? })`, `insertText(text, { range? })`, `insertMarkdown(markdown, options?)`, `insertTable({ rows?, cols? })`, `insertDivider`, `indent`, `outdent`, `undo`, `redo`, `selectAll`, `selectBlocks`, `focus(position?)`, `blur`, `scrollIntoView`. `selectBlocks` selects the blocks the selection touches as whole blocks, as Escape does; it returns `false` when read-only. `updateImage` changes the selected image; `null` removes its title, alignment or width, and a new width drops a height so the image keeps its aspect ratio. `toggleCallout` turns the selected blocks into a callout (`note` unless `type` says otherwise: `note`, `tip`, `important`, `warning` or `caution`), or back into paragraphs. `setCallout` changes the type of the whole callout or quote with the caret; `type: null` makes it a plain quote. `toggleDetails` makes the block with the caret the title of a collapsible section, or, on a title, removes the section and keeps its blocks. `toggleCallout`, `setCallout` and `toggleDetails` return `false` when the `markdown` option turns that syntax off. `scrollIntoView` changes nothing in the document: it scrolls the caret into view in the editor's scrolling containers and the window, for example after an `insertMarkdown` from code. |
|
|
103
103
|
| `run(fn)` | Applies a custom command: a function from state to a new state, or `null`. The pure commands are exported as `commands` from the package. |
|
|
104
|
-
| `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, `image` (the selection is exactly one image), or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote
|
|
105
|
-
| `getAttributes(name)` | `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) of the selected image, `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block, `callout` of a callout (`getAttributes('blockquote')
|
|
104
|
+
| `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, `image` (the selection is exactly one image), or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote` (also true in a list inside a quote), `details` (a collapsible section's title or end), `codeBlock`, `table`, `divider`, `raw`. `attrs` narrows it, for example `isActive('heading', { level: 2 })`. |
|
|
105
|
+
| `getAttributes(name)` | `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) of the selected image, `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block, `callout` of a callout (`getAttributes('blockquote')`, also in a list item inside a callout), `open` (saved open) and `collapsed` (shown collapsed) of a collapsible section title (`getAttributes('details')`). |
|
|
106
106
|
| `setSectionCollapsed(blockId, collapsed)`, `isSectionCollapsed(blockId)` | Collapse or expand the collapsible section whose title is `blockId`, or read whether it is collapsed. This changes the view only, not the Markdown or the history. `setSectionCollapsed` returns `false` when the block is not a section title. |
|
|
107
107
|
| `selectedBlocks` | The blocks of a block selection, in document order, or an empty array when the selection is text. |
|
|
108
108
|
| `getSelection()`, `setSelection(selection)` | Read or move the selection. `setSelection` also takes a `SelectionJSON`, and clamps one that does not fit the document. |
|
|
@@ -265,7 +265,7 @@ new Editor({
|
|
|
265
265
|
});
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `border`, `popupBackground`, `popupBorder`, `hover`, `danger`, and `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (each callout type's
|
|
268
|
+
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.
|
|
269
269
|
|
|
270
270
|
`colorScheme` picks light or dark: `auto` (the default) follows `prefers-color-scheme`, or `data-theme="light"` or `data-theme="dark"` 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.
|
|
271
271
|
|
|
@@ -287,7 +287,7 @@ new Editor({
|
|
|
287
287
|
});
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
Keys use the names of `isActive`: `paragraph`, `heading` (by level), `blockquote`, `bulletList`, `orderedList` and `taskList` (each list item; blocks are flat, so there is no list element), `codeBlock`, `table`, `divider` (the `<hr>`), `raw`, `image`, `bold`, `italic`, `strike`, `code`, `link`, and `token` (inline tokens of an extension syntax, by name). Extensions can add classes too; the editor's own `theme` wins for the same key. `setOptions({ theme })` changes them while the editor runs.
|
|
290
|
+
Keys use the names of `isActive`: `paragraph`, `heading` (by level), `blockquote`, `bulletList`, `orderedList` and `taskList` (each list item; blocks are flat, so there is no list element; an item in a quote also gets the `blockquote` classes), `codeBlock`, `table`, `divider` (the `<hr>`), `raw`, `image`, `bold`, `italic`, `strike`, `code`, `link`, and `token` (inline tokens of an extension syntax, by name). Extensions can add classes too; the editor's own `theme` wins for the same key. `setOptions({ theme })` changes them while the editor runs.
|
|
291
291
|
|
|
292
292
|
To style the editor entirely with your own classes, import `@usememos/editor/base.css` instead of `style.css`. Spacing between blocks stays in `base.css`, and its rules are more specific than a single class, so margins in your classes do not change it.
|
|
293
293
|
|
|
@@ -336,7 +336,7 @@ A callout is a quote with a type, saved as a [GitHub alert](https://docs.github.
|
|
|
336
336
|
> Back up your data first.
|
|
337
337
|
```
|
|
338
338
|
|
|
339
|
-
The types are Note, Tip, Important, Warning and Caution. A callout
|
|
339
|
+
The types are Note, Tip, Important, Warning and Caution. A callout is a softly tinted box in its type's color, with the type's icon beside the first line; the type's name is the icon's accessible label. Make one with Callout in the slash menu (a Note), or type `[!tip] ` at the start of a paragraph or a quote. Enter adds a line to the callout; Enter on an empty line ends it. Callouts and quotes can hold lists: type `- `, `1. ` or `[ ] ` at the start of a line in one. Clicking the icon, or Mod+/ inside the callout, opens its menu: the five types, and Delete for the whole callout. Pasting an alert copied from a GitHub page keeps it a callout. Renderers without alert support, including CommonMark, show a plain quote whose first line is `[!WARNING]`.
|
|
340
340
|
|
|
341
341
|
## Collapsible sections
|
|
342
342
|
|
|
@@ -362,7 +362,7 @@ Only a `<details>` written the way the editor saves it loads as a section: the o
|
|
|
362
362
|
|
|
363
363
|
Blocks you did not edit are saved exactly as they were loaded, byte for byte, including the blank lines between them. `getMarkdown()` right after loading returns the input unchanged.
|
|
364
364
|
|
|
365
|
-
Blocks you edited, and new blocks, are written in a normalized style: `*` for italic, `**` for bold, `-` for bullets, ATX headings, fenced code, tight lists, renumbered ordered lists, and inline links instead of reference links. Soft line breaks become spaces, unless `markdown.breaks` is on. Structure the editor cannot edit as blocks (a
|
|
365
|
+
Blocks you edited, and new blocks, are written in a normalized style: `*` for italic, `**` for bold, `-` for bullets, ATX headings, fenced code, tight lists, renumbered ordered lists, and inline links instead of reference links. Soft line breaks become spaces, unless `markdown.breaks` is on. Structure the editor cannot edit as blocks (a code block or heading inside a quote, a code block or second paragraph inside a list item, lists nested more than five levels) is kept as a raw block: the original Markdown, saved verbatim. It shows rendered, and its source shows for editing when the caret is in it or it is clicked. Math and footnote blocks from the extensions are raw blocks too.
|
|
366
366
|
|
|
367
367
|
## Develop
|
|
368
368
|
|
package/dist/base.css
CHANGED
|
@@ -56,16 +56,46 @@
|
|
|
56
56
|
:is(.mbe-root, .mbe-flow) > h3.mbe-block { margin-top: 20px; margin-bottom: 6px; }
|
|
57
57
|
:is(.mbe-root, .mbe-flow) > :is(h4, h5, h6).mbe-block { margin-top: 16px; margin-bottom: 4px; }
|
|
58
58
|
|
|
59
|
-
/* Quote: the renderer marks a quote block that follows another
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
/* Quote: the renderer marks a quote block that follows another of the same
|
|
60
|
+
quote, and one followed by another (see updateNeighborMarks). Margins are
|
|
61
|
+
0 between the parts of a quote and padding makes the space, so the border
|
|
62
|
+
stays unbroken and consecutive quote blocks read as one quote. A list in a
|
|
63
|
+
quote is a run of blockquote list items (see renderBlock): its items sit
|
|
64
|
+
2px apart, as outside quotes, with the gap around the list. */
|
|
65
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-quote-continued] { margin-bottom: 0; }
|
|
66
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] { margin-top: 0; padding-top: var(--mbe-block-gap); }
|
|
67
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-quote-joined] { margin-top: 0; }
|
|
68
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-quote-joined]:not([data-list-start]) { padding-top: 2px; }
|
|
63
69
|
|
|
64
|
-
/* Callouts: a
|
|
65
|
-
first block of a callout shows
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
/* Callouts: a padded box with the type's icon in a start column, level with
|
|
71
|
+
the first line. Only the first block of a callout shows the icon; the
|
|
72
|
+
renderer marks a block followed by another of the callout with
|
|
73
|
+
data-quote-continued, so the box pads only its first and last lines.
|
|
74
|
+
Clicking the icon opens the type menu. */
|
|
75
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-callout] {
|
|
76
|
+
--mbe-callout-pad: 12px;
|
|
77
|
+
position: relative;
|
|
78
|
+
padding-block: var(--mbe-callout-pad);
|
|
79
|
+
padding-inline: calc(var(--mbe-callout-pad) + 28px) 16px;
|
|
80
|
+
}
|
|
81
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-callout][data-quote-joined] { padding-top: var(--mbe-block-gap); }
|
|
82
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-callout][data-quote-continued] { padding-bottom: 0; }
|
|
83
|
+
.mbe-root .mbe-callout-icon {
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: var(--mbe-callout-pad);
|
|
86
|
+
inset-inline-start: calc(var(--mbe-callout-pad) - 2px);
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
justify-content: center;
|
|
90
|
+
width: 24px;
|
|
91
|
+
height: 1.5em;
|
|
92
|
+
height: 1lh;
|
|
93
|
+
user-select: none;
|
|
94
|
+
-webkit-user-select: none;
|
|
95
|
+
}
|
|
96
|
+
.mbe-root .mbe-callout-icon > .mbe-icon { width: 18px; height: 18px; }
|
|
97
|
+
:is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] > .mbe-callout-icon { display: none; }
|
|
98
|
+
.mbe-root:not(.mbe-readonly) > blockquote > .mbe-callout-icon { cursor: pointer; }
|
|
69
99
|
|
|
70
100
|
/* Collapsible sections: the title has a toggle in the indent column, and the
|
|
71
101
|
blocks inside are indented by one step per section around them (see
|
|
@@ -112,11 +142,17 @@
|
|
|
112
142
|
}
|
|
113
143
|
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-list-start] { margin-top: var(--mbe-block-gap); }
|
|
114
144
|
/* Attribute rules instead of an inline custom property, so list items share computed styles. */
|
|
115
|
-
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='1'] { padding-inline-start: var(--mbe-indent-size); }
|
|
116
|
-
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='2'] { padding-inline-start: calc(2 * var(--mbe-indent-size)); }
|
|
117
|
-
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='3'] { padding-inline-start: calc(3 * var(--mbe-indent-size)); }
|
|
118
|
-
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='4'] { padding-inline-start: calc(4 * var(--mbe-indent-size)); }
|
|
119
|
-
:is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='5'] { padding-inline-start: calc(5 * var(--mbe-indent-size)); }
|
|
145
|
+
:is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='1'] { padding-inline-start: var(--mbe-indent-size); }
|
|
146
|
+
:is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='2'] { padding-inline-start: calc(2 * var(--mbe-indent-size)); }
|
|
147
|
+
:is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='3'] { padding-inline-start: calc(3 * var(--mbe-indent-size)); }
|
|
148
|
+
:is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='4'] { padding-inline-start: calc(4 * var(--mbe-indent-size)); }
|
|
149
|
+
:is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='5'] { padding-inline-start: calc(5 * var(--mbe-indent-size)); }
|
|
150
|
+
/* In a quote the item's padding is the quote's, so the marker takes the indent. */
|
|
151
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='1'] > .mbe-marker { margin-inline-start: var(--mbe-indent-size); }
|
|
152
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='2'] > .mbe-marker { margin-inline-start: calc(2 * var(--mbe-indent-size)); }
|
|
153
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='3'] > .mbe-marker { margin-inline-start: calc(3 * var(--mbe-indent-size)); }
|
|
154
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='4'] > .mbe-marker { margin-inline-start: calc(4 * var(--mbe-indent-size)); }
|
|
155
|
+
:is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='5'] > .mbe-marker { margin-inline-start: calc(5 * var(--mbe-indent-size)); }
|
|
120
156
|
.mbe-root .mbe-marker {
|
|
121
157
|
flex: none;
|
|
122
158
|
box-sizing: border-box;
|
|
@@ -253,7 +289,7 @@
|
|
|
253
289
|
.mbe-root .mbe-empty-content { position: relative; }
|
|
254
290
|
.mbe-root > .mbe-paragraph.mbe-empty:only-child::before,
|
|
255
291
|
.mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before,
|
|
256
|
-
.mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
|
|
292
|
+
.mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote:not(.mbe-list-item))::before,
|
|
257
293
|
.mbe-root:not(.mbe-readonly) > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before,
|
|
258
294
|
.mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before {
|
|
259
295
|
opacity: 0.5;
|
|
@@ -262,7 +298,7 @@
|
|
|
262
298
|
}
|
|
263
299
|
.mbe-root > .mbe-paragraph.mbe-empty:only-child::before { content: var(--mbe-placeholder, ''); }
|
|
264
300
|
.mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before { content: var(--mbe-slash-hint, ''); }
|
|
265
|
-
.mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
|
|
301
|
+
.mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote:not(.mbe-list-item))::before,
|
|
266
302
|
.mbe-root:not(.mbe-readonly) > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before,
|
|
267
303
|
.mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before { content: attr(data-hint); }
|
|
268
304
|
|