@usememos/editor 26.10.12 → 26.10.14

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/dist/theme.css CHANGED
@@ -41,6 +41,12 @@
41
41
  0 2px 4px -2px light-dark(rgb(0 0 0 / 0.1), transparent);
42
42
  --mbe-block-code-bg: color-mix(in oklab, var(--mbe-code-bg) 45%, transparent);
43
43
  --mbe-quote-border: color-mix(in oklab, var(--mbe-muted) 25%, transparent);
44
+ /* Callout colors, close to GitHub's alerts. */
45
+ --mbe-callout-note: light-dark(var(--mbe-callout-note-light, oklch(0.55 0.17 255)), var(--mbe-callout-note-dark, oklch(0.68 0.15 255)));
46
+ --mbe-callout-tip: light-dark(var(--mbe-callout-tip-light, oklch(0.52 0.13 150)), var(--mbe-callout-tip-dark, oklch(0.72 0.17 150)));
47
+ --mbe-callout-important: light-dark(var(--mbe-callout-important-light, oklch(0.52 0.2 295)), var(--mbe-callout-important-dark, oklch(0.7 0.15 295)));
48
+ --mbe-callout-warning: light-dark(var(--mbe-callout-warning-light, oklch(0.55 0.12 75)), var(--mbe-callout-warning-dark, oklch(0.74 0.14 80)));
49
+ --mbe-callout-caution: light-dark(var(--mbe-callout-caution-light, oklch(0.55 0.2 25)), var(--mbe-callout-caution-dark, oklch(0.68 0.19 25)));
44
50
  }
45
51
  :where([data-theme='light']) :is(.mbe-root, .mbe-ui),
46
52
  .mbe-root[data-theme='light'],
@@ -65,12 +71,12 @@
65
71
  }
66
72
 
67
73
  /* Headings: close to the body size. */
68
- .mbe-root > :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; }
69
- .mbe-root > h1 { font-size: 24px; line-height: 32px; }
70
- .mbe-root > h2 { font-size: 20px; line-height: 28px; }
71
- .mbe-root > h3 { font-size: 18px; line-height: 26px; }
72
- .mbe-root > :is(h4, h5, h6) { font-size: 16px; line-height: 24px; }
73
- .mbe-root > h6 { color: var(--mbe-muted); }
74
+ :is(.mbe-root, .mbe-flow) > :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; }
75
+ :is(.mbe-root, .mbe-flow) > h1 { font-size: 24px; line-height: 32px; }
76
+ :is(.mbe-root, .mbe-flow) > h2 { font-size: 20px; line-height: 28px; }
77
+ :is(.mbe-root, .mbe-flow) > h3 { font-size: 18px; line-height: 26px; }
78
+ :is(.mbe-root, .mbe-flow) > :is(h4, h5, h6) { font-size: 16px; line-height: 24px; }
79
+ :is(.mbe-root, .mbe-flow) > h6 { color: var(--mbe-muted); }
74
80
 
75
81
  /* Block selection */
76
82
  .mbe-root > .mbe-block.mbe-block-selected {
@@ -104,18 +110,31 @@
104
110
  /* Footnotes, rendered: a reference is a small raised label, a definition a small muted note. */
105
111
  .mbe-root .mbe-footnote-ref { font-size: 0.75em; line-height: 0; color: var(--mbe-link); }
106
112
  .mbe-root.mbe-readonly .mbe-footnote-ref { cursor: pointer; }
107
- .mbe-root > .mbe-footnote { font-size: 0.875em; color: var(--mbe-muted); }
113
+ :is(.mbe-root, .mbe-flow) > .mbe-footnote { font-size: 0.875em; color: var(--mbe-muted); }
108
114
  .mbe-root .mbe-footnote-label { margin-inline-end: 0.375em; color: var(--mbe-link); }
109
115
 
110
116
  /* Quote */
111
- .mbe-root > blockquote {
117
+ :is(.mbe-root, .mbe-flow) > blockquote {
112
118
  border-inline-start: 3px solid var(--mbe-quote-border);
113
119
  padding-inline-start: 12px;
114
120
  color: var(--mbe-muted);
115
121
  }
116
122
 
123
+ /* Callouts: the type's color on the border and the title; the text keeps the body color. */
124
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout] { color: inherit; border-inline-start-color: var(--mbe-callout); }
125
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout='note'] { --mbe-callout: var(--mbe-callout-note); }
126
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout='tip'] { --mbe-callout: var(--mbe-callout-tip); }
127
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout='important'] { --mbe-callout: var(--mbe-callout-important); }
128
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout='warning'] { --mbe-callout: var(--mbe-callout-warning); }
129
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout='caution'] { --mbe-callout: var(--mbe-callout-caution); }
130
+ .mbe-root .mbe-callout-title { color: var(--mbe-callout); font-weight: 500; }
131
+
117
132
  /* Lists */
118
133
  .mbe-root .mbe-marker { color: var(--mbe-muted); }
134
+ /* Collapsible sections: a muted toggle and a medium-weight title. */
135
+ .mbe-root .mbe-details-toggle { color: var(--mbe-muted); border-radius: 4px; }
136
+ .mbe-root .mbe-details-toggle:hover { color: var(--mbe-text); background: var(--mbe-hover); }
137
+ :is(.mbe-root, .mbe-flow) > .mbe-details { font-weight: 500; }
119
138
  /* appearance: none, so a disabled checkbox in read-only is not greyed out. */
120
139
  .mbe-root .mbe-checkbox {
121
140
  appearance: none;
@@ -131,7 +150,7 @@
131
150
  }
132
151
 
133
152
  /* Code: a quiet panel, with the language as a small label above the code. */
134
- .mbe-root > .mbe-code:not(.mbe-view-block) {
153
+ :is(.mbe-root, .mbe-flow) > .mbe-code:not(.mbe-view-block) {
135
154
  background: var(--mbe-block-code-bg);
136
155
  border-radius: var(--mbe-radius);
137
156
  overflow: hidden;
@@ -144,38 +163,76 @@
144
163
  .mbe-root .mbe-code-copy:hover { color: var(--mbe-text); background: var(--mbe-hover); }
145
164
  .mbe-root .mbe-code-copy.mbe-copied { color: var(--mbe-accent); }
146
165
  /* Block source text: code blocks and raw blocks. */
147
- .mbe-root > .mbe-code pre,
148
- .mbe-root > pre.mbe-raw { font-size: 14px; line-height: 22px; font-family: var(--mbe-mono); }
149
- .mbe-root > .mbe-code pre { padding: 2px 12px 10px; }
150
- .mbe-root > .mbe-code pre code { background: none; padding: 0; border-radius: 0; font: inherit; }
166
+ :is(.mbe-root, .mbe-flow) > .mbe-code pre,
167
+ :is(.mbe-root, .mbe-flow) > pre.mbe-raw { font-size: 14px; line-height: 22px; font-family: var(--mbe-mono); }
168
+ :is(.mbe-root, .mbe-flow) > .mbe-code pre { padding: 2px 12px 10px; }
169
+ :is(.mbe-root, .mbe-flow) > .mbe-code pre code { background: none; padding: 0; border-radius: 0; font: inherit; }
151
170
 
152
171
  /* Raw blocks: Markdown kept as source (HTML, structure the editor cannot hold, extension syntax) */
153
- .mbe-root > pre.mbe-raw { color: var(--mbe-muted); }
172
+ :is(.mbe-root, .mbe-flow) > pre.mbe-raw { color: var(--mbe-muted); }
173
+
174
+ /* Rendered HTML: its elements look like the Markdown they stand for, as on GitHub. */
175
+ .mbe-root .mbe-view-html blockquote:not(.mbe-flow *) {
176
+ border-inline-start: 3px solid var(--mbe-quote-border);
177
+ padding-inline-start: 12px;
178
+ color: var(--mbe-muted);
179
+ }
180
+ .mbe-root .mbe-view-html pre:not(.mbe-flow *) {
181
+ background: var(--mbe-block-code-bg);
182
+ border-radius: var(--mbe-radius);
183
+ padding: 10px 12px;
184
+ font-size: 14px;
185
+ line-height: 22px;
186
+ font-family: var(--mbe-mono);
187
+ }
188
+ .mbe-root .mbe-view-html pre code:not(.mbe-flow *) { background: none; padding: 0; border-radius: 0; font: inherit; }
189
+ .mbe-root .mbe-view-html :is(h1, h2, h3, h4, h5, h6):not(.mbe-flow *) { font-weight: 600; }
190
+ .mbe-root .mbe-view-html h1:not(.mbe-flow *) { font-size: 24px; line-height: 32px; }
191
+ .mbe-root .mbe-view-html h2:not(.mbe-flow *) { font-size: 20px; line-height: 28px; }
192
+ .mbe-root .mbe-view-html h3:not(.mbe-flow *) { font-size: 18px; line-height: 26px; }
193
+ .mbe-root .mbe-view-html h6:not(.mbe-flow *) { color: var(--mbe-muted); }
194
+ .mbe-root .mbe-view-html hr:not(.mbe-flow *) { border: none; border-top: 1px solid var(--mbe-border); }
195
+ .mbe-root .mbe-view-html a:not(.mbe-link) { color: var(--mbe-link); text-decoration: underline; text-underline-offset: 2px; }
196
+ .mbe-root .mbe-view-html table:not(.mbe-flow *) { border-collapse: collapse; font-size: 14px; line-height: 20px; }
197
+ .mbe-root .mbe-view-html :is(th, td):not(.mbe-flow *) { border: 1px solid var(--mbe-border); padding: 6px 10px; text-align: start; vertical-align: top; }
198
+ .mbe-root .mbe-view-html th:not(.mbe-flow *) { font-weight: 500; background: var(--mbe-block-code-bg); }
199
+ .mbe-root .mbe-view-html kbd {
200
+ font-family: var(--mbe-mono);
201
+ font-size: 0.8125em;
202
+ line-height: 1;
203
+ padding: 2px 5px;
204
+ border: 1px solid var(--mbe-border);
205
+ border-bottom-width: 2px;
206
+ border-radius: 4px;
207
+ background: var(--mbe-block-code-bg);
208
+ }
209
+ .mbe-root .mbe-view-html mark { background: color-mix(in oklab, #facc15 40%, transparent); color: inherit; }
154
210
 
155
211
  /* Divider */
156
- .mbe-root > .mbe-divider hr { border: none; border-top: 1px solid var(--mbe-border); }
212
+ :is(.mbe-root, .mbe-flow) > .mbe-divider hr { border: none; border-top: 1px solid var(--mbe-border); }
157
213
 
158
214
  /* Table: a light grid around every cell and a shaded header row, as in
159
215
  Notion and Outline. Separate borders, so the outer corners can be round. */
160
- .mbe-root > .mbe-table table {
216
+ :is(.mbe-root, .mbe-flow) > .mbe-table table {
161
217
  font-size: 14px;
162
218
  line-height: 20px;
163
219
  border: 1px solid var(--mbe-border);
164
220
  border-radius: var(--mbe-radius);
165
221
  }
166
- .mbe-root > .mbe-table :is(th, td) { padding: 6px 10px; min-width: 8em; }
167
- .mbe-root > .mbe-table :is(th, td):not(:first-child) { border-inline-start: 1px solid var(--mbe-border); }
168
- .mbe-root > .mbe-table tr:not(:first-child) > * { border-top: 1px solid var(--mbe-border); }
169
- .mbe-root > .mbe-table th { font-weight: 500; background: var(--mbe-block-code-bg); }
222
+ :is(.mbe-root, .mbe-flow) > .mbe-table :is(th, td) { padding: 6px 10px; min-width: 8em; }
223
+ :is(.mbe-root, .mbe-flow) > .mbe-table :is(th, td):not(:first-child) { border-inline-start: 1px solid var(--mbe-border); }
224
+ :is(.mbe-root, .mbe-flow) > .mbe-table tr:not(:first-child) > * { border-top: 1px solid var(--mbe-border); }
225
+ :is(.mbe-root, .mbe-flow) > .mbe-table th { font-weight: 500; background: var(--mbe-block-code-bg); }
170
226
  /* The header's fill stays inside the round corners. */
171
- .mbe-root > .mbe-table tr:first-child > :first-child { border-start-start-radius: calc(var(--mbe-radius) - 1px); }
172
- .mbe-root > .mbe-table tr:first-child > :last-child { border-start-end-radius: calc(var(--mbe-radius) - 1px); }
227
+ :is(.mbe-root, .mbe-flow) > .mbe-table tr:first-child > :first-child { border-start-start-radius: calc(var(--mbe-radius) - 1px); }
228
+ :is(.mbe-root, .mbe-flow) > .mbe-table tr:first-child > :last-child { border-start-end-radius: calc(var(--mbe-radius) - 1px); }
173
229
 
174
230
  /* Placeholders and hints */
175
231
  .mbe-root > .mbe-paragraph.mbe-empty:only-child::before,
176
232
  .mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before,
177
- .mbe-root > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
178
- .mbe-root > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before {
233
+ .mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
234
+ .mbe-root:not(.mbe-readonly) > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before,
235
+ .mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before {
179
236
  color: var(--mbe-muted);
180
237
  opacity: 0.7;
181
238
  }
@@ -190,6 +247,7 @@
190
247
  }
191
248
  .mbe-menu,
192
249
  .mbe-toolbar,
250
+ .mbe-link-card,
193
251
  .mbe-input-popover {
194
252
  color: var(--mbe-text);
195
253
  background: var(--mbe-popup-bg);
@@ -207,7 +265,10 @@
207
265
  .mbe-menu-loading { color: var(--mbe-muted); }
208
266
  .mbe-menu-detail { font-size: 12px; color: var(--mbe-muted); }
209
267
 
210
- .mbe-toolbar { border-radius: calc(var(--mbe-radius) + 2px); }
268
+ .mbe-toolbar,
269
+ .mbe-link-card { border-radius: calc(var(--mbe-radius) + 2px); }
270
+ .mbe-link-card-url { font-size: 13px; color: var(--mbe-link); text-decoration: none; }
271
+ .mbe-link-card-url:hover { text-decoration: underline; }
211
272
  .mbe-tool { border-radius: 7px; }
212
273
  .mbe-tool:hover,
213
274
  .mbe-tool.mbe-open { background: var(--mbe-hover); }
@@ -1,4 +1,4 @@
1
- import { type Block, type EditorState, type HeadingLevel, type ImageAlign, type ImageAtom, type ListType, type Mark, type Position, type Selection, type TableBlock, type RawBlock, type TextBlock, type Align } from './model.js';
1
+ import { type Block, type CalloutType, type EditorState, type HeadingLevel, type ImageAlign, type ImageAtom, type ListType, type Mark, type Position, type Selection, type TableBlock, type RawBlock, type TextBlock, type Align } from './model.js';
2
2
  import type { InlineSyntax } from './markdown/options.js';
3
3
  export type Command = (state: EditorState) => EditorState;
4
4
  /** A copy of a block with a new ID. */
@@ -23,10 +23,30 @@ export declare function insertText(state: EditorState, text: string): EditorStat
23
23
  * text; a wrapped line counts as one.
24
24
  */
25
25
  export declare function exitBlock(state: EditorState, dir: 1 | -1): EditorState;
26
+ /** Adds an empty paragraph at the end of the document, with the caret in it. */
27
+ export declare function appendParagraph(state: EditorState): EditorState;
26
28
  /** Shift+Enter: a hard line break. A newline in code; nothing in a table cell. */
27
29
  export declare function insertLineBreak(state: EditorState): EditorState;
28
30
  /** Enter. */
29
31
  export declare function splitBlock(state: EditorState): EditorState;
32
+ /** Enter in the title of a collapsed section: the new line goes after the section. */
33
+ export declare function splitCollapsedTitle(state: EditorState): EditorState;
34
+ /** The index of the `detailsEnd` that closes the section titled at `index`, or null. */
35
+ export declare function sectionEnd(blocks: readonly Block[], index: number): number | null;
36
+ /** The index of the title of the section that the `detailsEnd` at `index` closes, or null. */
37
+ export declare function sectionTitle(blocks: readonly Block[], index: number): number | null;
38
+ /**
39
+ * Blocks with every collapsible section whole: an end with no open section
40
+ * is dropped, and a title whose end is missing becomes a paragraph. Returns
41
+ * `blocks` itself when they already are.
42
+ */
43
+ export declare function closeSections(blocks: readonly Block[]): readonly Block[];
44
+ /**
45
+ * Keeps collapsible sections whole after an edit (see `closeSections`), so
46
+ * removing a title or an end unwraps its section. A caret on an end moves to
47
+ * the end of the text before it.
48
+ */
49
+ export declare function balanceSections(state: EditorState): EditorState;
30
50
  /** True if every character of the selection carries the mark (or, collapsed, the next typed text will). */
31
51
  export declare function isMarkActive(state: EditorState, mark: Mark): boolean;
32
52
  export declare function toggleMark(state: EditorState, mark: Mark): EditorState;
@@ -75,8 +95,11 @@ export type BlockTypeSpec = {
75
95
  } | {
76
96
  type: 'listItem';
77
97
  listType: ListType;
78
- } | {
98
+ }
99
+ /** A quote, or with `callout` a callout of that type. */
100
+ | {
79
101
  type: 'quote';
102
+ callout?: CalloutType;
80
103
  } | {
81
104
  type: 'code';
82
105
  language?: string;
@@ -86,6 +109,10 @@ export type BlockTypeSpec = {
86
109
  cols?: number;
87
110
  } | {
88
111
  type: 'divider';
112
+ }
113
+ /** A collapsible section: the block becomes its title, and an empty line its body. */
114
+ | {
115
+ type: 'details';
89
116
  };
90
117
  /**
91
118
  * Changes the type of every text block touched by the selection. Text and IDs
@@ -93,6 +120,16 @@ export type BlockTypeSpec = {
93
120
  * is the exception: adjacent blocks become one code block, a line per block.
94
121
  */
95
122
  export declare function setBlockType(state: EditorState, spec: BlockTypeSpec): EditorState;
123
+ /**
124
+ * The quote blocks that form one blockquote with the quote `blockId`: its
125
+ * neighbours with the same callout. Null when the block is not a quote.
126
+ */
127
+ export declare function quoteRun(state: EditorState, blockId: string): {
128
+ start: number;
129
+ end: number;
130
+ } | null;
131
+ /** Sets the callout of the whole blockquote with the quote `blockId`; null makes it a plain quote. */
132
+ export declare function setCallout(state: EditorState, blockId: string, callout: CalloutType | null): EditorState;
96
133
  /** The blocks the selection touches whose type the block type commands change. */
97
134
  export declare function convertibleBlocks(state: EditorState): Exclude<TextBlock, RawBlock>[];
98
135
  /**
@@ -153,7 +190,15 @@ export type TableAction = {
153
190
  export declare function tableAction(state: EditorState, action: TableAction): EditorState;
154
191
  /** Tab / Shift+Tab in a table: next or previous cell. Tab in the last cell adds a row. */
155
192
  export declare function moveCell(state: EditorState, delta: 1 | -1): EditorState;
156
- export declare function applyBlockInputRules(state: EditorState): EditorState | null;
193
+ /**
194
+ * Turns a paragraph into another block type when the text before the caret
195
+ * is a Markdown marker such as "# " or "- ". `dialect` turns off the markers
196
+ * for callouts and collapsible sections, as the Markdown options do.
197
+ */
198
+ export declare function applyBlockInputRules(state: EditorState, dialect?: {
199
+ callouts?: boolean;
200
+ details?: boolean;
201
+ }): EditorState | null;
157
202
  /**
158
203
  * Inline shortcuts: typing the closing delimiter of `**x**`, `*x*`, `_x_`,
159
204
  * `` `x` `` or `~~x~~` applies the mark and removes the delimiters.
@@ -6,7 +6,7 @@ import { type MarkdownOptions } from './markdown/options.js';
6
6
  import type { Extension } from './extension.js';
7
7
  import { type SuggestionState } from './suggest/controller.js';
8
8
  import { type Widget, type WidgetRender } from './widgets.js';
9
- import { type Block, type EditorState, type HeadingLevel, type Position, type Selection } from './model.js';
9
+ import { type Block, type CalloutType, type EditorState, type HeadingLevel, type Position, type Selection } from './model.js';
10
10
  import { type ToolbarItem } from './ui/toolbar.js';
11
11
  import { type ResolveUrl } from './view/dom.js';
12
12
  import { type Theme } from './theme.js';
@@ -73,6 +73,12 @@ export interface EditorOptions {
73
73
  toolbar?: boolean | {
74
74
  items?: readonly ToolbarItem[];
75
75
  };
76
+ /**
77
+ * Shows the link card while editing: the link's URL and buttons to open,
78
+ * copy, edit and remove it, when the pointer rests on a link or the caret
79
+ * is inside one. Default true.
80
+ */
81
+ linkCard?: boolean;
76
82
  /**
77
83
  * The element menus, the toolbar and other popups are appended to.
78
84
  * Default: the nearest open `<dialog>` or `aria-modal` ancestor of
@@ -81,6 +87,12 @@ export interface EditorOptions {
81
87
  popupContainer?: HTMLElement;
82
88
  /** IDs of built-in slash menu items to show, in order, or false for no slash menu. See SLASH_ITEM_IDS. */
83
89
  slashMenu?: false | readonly SlashItemId[];
90
+ /**
91
+ * Shows `labels.slashHint` in the empty paragraph that has the caret.
92
+ * Default false. Has no effect when `slashMenu` is false. Fixed for the
93
+ * editor's lifetime.
94
+ */
95
+ slashHint?: boolean;
84
96
  /** Shortcut for `on('change')`, with the new Markdown. */
85
97
  onChange?: (markdown: string, editor: Editor) => void;
86
98
  /** Shortcut for `on('submit')`, with the current Markdown. */
@@ -135,6 +147,8 @@ export interface SuggestionApi {
135
147
  }
136
148
  /** Names `isActive` and `getAttributes` understand. */
137
149
  export type ActiveName = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'taskList' | 'blockquote' | 'codeBlock' | 'table' | 'divider' | 'raw'
150
+ /** The title of a collapsible section. */
151
+ | 'details'
138
152
  /** The selection is exactly one image. */
139
153
  | 'image';
140
154
  /** A position that survives reloading the same Markdown: a block index and an offset. */
@@ -174,6 +188,16 @@ export interface EditorCommands {
174
188
  toggleOrderedList(): boolean;
175
189
  toggleTaskList(): boolean;
176
190
  toggleBlockquote(): boolean;
191
+ /** Turns the selected blocks into a callout of `type` (default `note`), or back into paragraphs when they are one already. */
192
+ toggleCallout(attrs?: {
193
+ type?: CalloutType;
194
+ }): boolean;
195
+ /** Changes the type of the callout with the caret, or turns the quote with the caret into a callout; `null` makes it a plain quote. */
196
+ setCallout(attrs: {
197
+ type: CalloutType | null;
198
+ }): boolean;
199
+ /** Turns the block with the caret into the title of a collapsible section with an empty body, or, on a title, removes the section and keeps its blocks. */
200
+ toggleDetails(): boolean;
177
201
  toggleCodeBlock(attrs?: {
178
202
  language?: string;
179
203
  }): boolean;
@@ -212,7 +236,7 @@ export interface EditorCommands {
212
236
  /** Scrolls the caret (the selection's focus end) into view, in scrolling containers and the window. */
213
237
  scrollIntoView(): boolean;
214
238
  }
215
- export declare const SLASH_ITEM_IDS: readonly ["text", "heading1", "heading2", "heading3", "bulletList", "numberedList", "todoList", "quote", "code", "table", "divider"];
239
+ export declare const SLASH_ITEM_IDS: readonly ["text", "heading1", "heading2", "heading3", "heading4", "bulletList", "numberedList", "todoList", "quote", "callout", "details", "code", "table", "divider"];
216
240
  export type SlashItemId = (typeof SLASH_ITEM_IDS)[number];
217
241
  export declare class Editor {
218
242
  /** The editable element the editor renders into: `options.element`, or for `useEditor`, the element `<EditorContent>` mounts. */
@@ -283,6 +307,9 @@ export declare class Editor {
283
307
  /** The link popover, and the field for an image's alt text. */
284
308
  private readonly inputPopover;
285
309
  private readonly blockHandle;
310
+ /** Collapsible sections shown collapsed, by the ID of their title. View state: not saved, not undone. */
311
+ private readonly collapsed;
312
+ private readonly linkCard;
286
313
  private readonly resizeHandles;
287
314
  /** The selected image's element, which carries the selected class. */
288
315
  private selectedImageEl;
@@ -323,7 +350,7 @@ export declare class Editor {
323
350
  get isDestroyed(): boolean;
324
351
  /** True if `name` applies at the selection: a mark on the selected text, or the type of the block with the caret. */
325
352
  isActive(name: ActiveName, attrs?: Readonly<Record<string, unknown>>): boolean;
326
- /** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block. */
353
+ /** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block, `callout` for a callout, `open` (saved as `<details open>`) and `collapsed` (shown collapsed now) for a section title. */
327
354
  getAttributes(name: ActiveName): Record<string, unknown>;
328
355
  getSelection(): Selection;
329
356
  /**
@@ -540,6 +567,8 @@ export declare class Editor {
540
567
  */
541
568
  private clickBelowLastBlock;
542
569
  private onClick;
570
+ /** Opens a resolved link URL, as a click on a link does: through `onLinkClick`, else in a new tab. */
571
+ private openHref;
543
572
  /** Copies the code of the code block holding `button`, and shows that it did for a moment. */
544
573
  private copyCode;
545
574
  /** The code block language input. */
@@ -561,6 +590,10 @@ export declare class Editor {
561
590
  /** The blocks of the block selection, in document order. Empty when the selection is text. */
562
591
  get selectedBlocks(): readonly Block[];
563
592
  private blockRange;
593
+ /** `range` grown so that a collapsible section with its title or its end in it is in it whole. */
594
+ private wholeSections;
595
+ /** The next block a block selection moves to from `index`: blocks shown on screen, not section ends. */
596
+ private nextSelectable;
564
597
  /** Selects whole blocks, from the block `anchor` to the block `head`. */
565
598
  private selectBlockRange;
566
599
  /** Leaves block selection, keeping the hidden caret as a collapsed selection. */
@@ -582,6 +615,8 @@ export declare class Editor {
582
615
  private blockMenuSections;
583
616
  /** The Align row of the block menu: a submenu of Left, Center and Right with the current one checked. */
584
617
  private alignMenuItem;
618
+ /** True if the blocks `a` and `b` are in the same callout. */
619
+ private inSameCallout;
585
620
  private closeBlockMenu;
586
621
  /**
587
622
  * A press anywhere but the block menu or the block handle closes the block menu,
@@ -589,6 +624,33 @@ export declare class Editor {
589
624
  */
590
625
  private onDocumentPointerDown;
591
626
  private updateUi;
627
+ /**
628
+ * Collapses or expands the collapsible section titled by the block
629
+ * `blockId`. This changes the view only: the Markdown, history and events
630
+ * stay as they are. A caret inside a section that collapses moves to the
631
+ * end of its title. Returns false when the block is not a section title.
632
+ */
633
+ setSectionCollapsed(blockId: string, collapsed: boolean): boolean;
634
+ /** True when the section titled by `blockId` is shown collapsed. */
635
+ isSectionCollapsed(blockId: string): boolean;
636
+ /** Sections that are not saved open start collapsed, as a Markdown renderer shows them. */
637
+ private collapseClosedSections;
638
+ /** Expands the collapsed sections around the selection's focus, so the caret is never hidden. */
639
+ private expandAroundSelection;
640
+ /** Blocks the caret passes over: dividers, section ends, and blocks inside a collapsed section. */
641
+ private skipsCaret;
642
+ /** The link the caret is inside, not at its edge, with its element. */
643
+ private caretLink;
644
+ /** The document position where a rendered link starts. */
645
+ private linkStart;
646
+ /** The link a rendered link element shows, or null for one outside the document's blocks. */
647
+ private linkTargetOf;
648
+ /** The selection of a link's whole text, from a rendered link element. */
649
+ private linkSelection;
650
+ /** Opens the link popover for a link, as Mod+K does with the caret in it. */
651
+ private editLink;
652
+ /** Removes a link and keeps its text, as one undo step. */
653
+ private removeLink;
592
654
  /** Marks the selected image's element, and hides the browser's selection highlight over it. */
593
655
  private paintSelectedImage;
594
656
  /** The selected image of `state` and its element, or null. */
@@ -0,0 +1 @@
1
+ export declare const EMOJI_DATA: string;
@@ -0,0 +1,21 @@
1
+ import { type Extension } from '@usememos/editor';
2
+ import { type Emoji } from './search.js';
3
+ export { type Emoji, parseEmoji, searchEmoji } from './search.js';
4
+ export interface EmojiOptions {
5
+ /** The suggestion's name, for `editor.suggestion.open(name)`. Default `emoji`. */
6
+ readonly name?: string;
7
+ /** Most emoji shown. Default 8. */
8
+ readonly limit?: number;
9
+ /** Characters typed after `:` before the popup opens, so `:)` and `a :b` stay quiet. Default 2. Ctrl+Space opens it sooner. */
10
+ readonly minLength?: number;
11
+ /** Accessible name of the popup. Default `Emoji`. */
12
+ readonly label?: string;
13
+ }
14
+ /** Every emoji the extension offers, loaded once on first use. */
15
+ export declare function loadEmoji(): Promise<readonly Emoji[]>;
16
+ /**
17
+ * Emoji autocomplete: typing `:` and two letters at the start of a word lists
18
+ * emoji by GitHub's names and tags (`:tada`, `:party`). A pick replaces the
19
+ * typed name with the emoji, so the Markdown holds the character itself.
20
+ */
21
+ export declare function emoji(options?: EmojiOptions): Extension;
@@ -0,0 +1,17 @@
1
+ export interface Emoji {
2
+ /** The character, such as "🎉". */
3
+ readonly emoji: string;
4
+ /** Its names, the first the main one, such as ["tada"]. Typed as `:tada:` on GitHub. */
5
+ readonly names: readonly string[];
6
+ /** Other words it is found by, such as ["party"]. */
7
+ readonly tags: readonly string[];
8
+ }
9
+ /** Reads the lines of `data.ts`: the emoji, its names and its tags, separated by tabs. */
10
+ export declare function parseEmoji(data: string): Emoji[];
11
+ /**
12
+ * Emoji whose names or tags match `query`, best first: a name equal to it,
13
+ * a name starting with it, a word of a name starting with it ("smile" finds
14
+ * "sweat_smile"), a tag starting with it, then a name containing it. Within
15
+ * a rank the data's order is kept, which puts common emoji first.
16
+ */
17
+ export declare function searchEmoji(emoji: readonly Emoji[], query: string, limit?: number): Emoji[];
@@ -25,6 +25,8 @@ declare const ICONS: {
25
25
  heading2: string[];
26
26
  /** `heading-3` */
27
27
  heading3: string[];
28
+ /** `heading-4` */
29
+ heading4: string[];
28
30
  /** `list` */
29
31
  bulletList: string[];
30
32
  /** `list-ordered` */
@@ -39,6 +41,28 @@ declare const ICONS: {
39
41
  }])[];
40
42
  /** `text-quote` */
41
43
  quote: string[];
44
+ /** `info`, as a Note callout */
45
+ callout: (string | [string, {
46
+ cx: string;
47
+ cy: string;
48
+ r: string;
49
+ }])[];
50
+ /** `info` */
51
+ calloutNote: (string | [string, {
52
+ cx: string;
53
+ cy: string;
54
+ r: string;
55
+ }])[];
56
+ /** `lightbulb` */
57
+ calloutTip: string[];
58
+ /** `message-square-warning` */
59
+ calloutImportant: string[];
60
+ /** `triangle-alert` */
61
+ calloutWarning: string[];
62
+ /** `octagon-alert` */
63
+ calloutCaution: string[];
64
+ /** `list-collapse` */
65
+ details: string[];
42
66
  /** `square-code` */
43
67
  code: (string | [string, {
44
68
  x: string;
@@ -139,6 +163,21 @@ declare const ICONS: {
139
163
  }])[];
140
164
  /** `code` */
141
165
  inlineCode: string[];
166
+ /** `external-link` */
167
+ openLink: string[];
168
+ /** `copy` */
169
+ copyLink: (string | [string, {
170
+ width: string;
171
+ height: string;
172
+ x: string;
173
+ y: string;
174
+ rx: string;
175
+ ry: string;
176
+ }])[];
177
+ /** `pencil` */
178
+ editLink: string[];
179
+ /** `unlink` */
180
+ removeLink: string[];
142
181
  /** `link` */
143
182
  link: string[];
144
183
  /** `image-off` */
@@ -3,13 +3,29 @@ export declare const DEFAULT_LABELS: {
3
3
  heading1: string;
4
4
  heading2: string;
5
5
  heading3: string;
6
+ heading4: string;
6
7
  bulletList: string;
7
8
  numberedList: string;
8
9
  todoList: string;
9
10
  /** Accessible name of a task checkbox whose item has no text. */
10
11
  task: string;
11
12
  quote: string;
13
+ /** The slash menu item, and the title of a callout's block menu section. */
14
+ callout: string;
15
+ /** Callout types: each callout's title, and its block menu items. */
16
+ calloutNote: string;
17
+ calloutTip: string;
18
+ calloutImportant: string;
19
+ calloutWarning: string;
20
+ calloutCaution: string;
12
21
  code: string;
22
+ /** The slash menu item that makes a collapsible section. */
23
+ details: string;
24
+ /** Shown in an empty section title. */
25
+ detailsHint: string;
26
+ /** The toggle of a collapsible section. */
27
+ expandSection: string;
28
+ collapseSection: string;
13
29
  table: string;
14
30
  divider: string;
15
31
  noResults: string;
@@ -32,6 +48,11 @@ export declare const DEFAULT_LABELS: {
32
48
  list: string;
33
49
  linkPlaceholder: string;
34
50
  removeLink: string;
51
+ /** The link card's buttons. */
52
+ openLink: string;
53
+ copyLink: string;
54
+ editLink: string;
55
+ /** Shown in the empty paragraph that has the caret, with the `slashHint` option. */
35
56
  slashHint: string;
36
57
  blockHandle: string;
37
58
  listHint: string;
@@ -2,3 +2,5 @@ import type { Root } from './ast.js';
2
2
  import { type MarkdownOptions } from './options.js';
3
3
  /** Parses Markdown source into a syntax tree. */
4
4
  export declare function parseAst(src: string, options?: MarkdownOptions): Root;
5
+ /** True when `text` at the start of a line would start an HTML block that can interrupt a paragraph (types 1 to 6). */
6
+ export declare function interruptsParagraph(text: string): boolean;
@@ -0,0 +1,37 @@
1
+ import { type Block } from '../model.js';
2
+ import type { BlockNode } from './ast.js';
3
+ import { type MarkdownOptions } from './options.js';
4
+ /**
5
+ * When top-level block `i` is an HTML block that leaves elements open, the
6
+ * index of the HTML block that closes them all. Returns `i` when there is
7
+ * nothing to join, including when the elements are never closed.
8
+ */
9
+ export declare function htmlSectionEnd(nodes: readonly BlockNode[], i: number): number;
10
+ /**
11
+ * Collapsible sections among top-level blocks: an HTML block that is only
12
+ * `<details>` (or `<details open>`) and a `<summary>` of plain text, and the
13
+ * HTML block that is only `</details>` closing it, with Markdown between
14
+ * them. Returns their indexes, each mapped to the block it becomes. Sections
15
+ * nest. HTML between them that leaves an element open, which a renderer
16
+ * would close at the section's end, keeps the sections around it as HTML.
17
+ */
18
+ export declare function detailsSections(nodes: readonly BlockNode[]): Map<number, Block>;
19
+ /** Marks where the blocks of slot `index` go in a section's HTML. Private-use characters, so they never meet real text. */
20
+ export declare const slotMarker: (index: number) => string;
21
+ /** Finds slot markers in text. */
22
+ export declare const SLOT_MARKER: RegExp;
23
+ export interface HtmlSection {
24
+ /**
25
+ * The section's HTML, with each run of Markdown blocks replaced by
26
+ * `slotMarker(index)` on a line of its own between blank lines.
27
+ */
28
+ readonly html: string;
29
+ /** The Markdown between the tags, as blocks, one list per slot. */
30
+ readonly slots: readonly (readonly Block[])[];
31
+ }
32
+ /**
33
+ * Splits an HTML block's source into its HTML and the Markdown between its
34
+ * tags, as CommonMark reads it. Null when the source holds no Markdown
35
+ * blocks: it is all HTML.
36
+ */
37
+ export declare function splitHtmlSection(source: string, options?: MarkdownOptions): HtmlSection | null;
@@ -26,6 +26,8 @@ export declare const AUTOLINK_EMAIL = "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0
26
26
  export declare function isUnicodeWhitespace(ch: string): boolean;
27
27
  /** Unicode punctuation as the spec defines it (categories P and S). */
28
28
  export declare function isUnicodePunctuation(ch: string): boolean;
29
+ /** Decodes the entity references in HTML text, such as a section title. */
30
+ export declare function decodeEntities(s: string): string;
29
31
  /** Applies backslash escapes and entities, for link destinations, titles and info strings. */
30
32
  export declare function unescapeString(s: string): string;
31
33
  /**
@@ -15,6 +15,18 @@ export interface MarkdownOptions {
15
15
  * `name@example.com` written without angle brackets are links. Default true.
16
16
  */
17
17
  readonly autolinks?: boolean;
18
+ /**
19
+ * GitHub alerts: a blockquote whose first line is `[!NOTE]`, `[!TIP]`,
20
+ * `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]` is a callout. Default true.
21
+ * With false, the marker is quoted text.
22
+ */
23
+ readonly callouts?: boolean;
24
+ /**
25
+ * Collapsible sections: `<details>` with a `<summary>` title, a blank line,
26
+ * Markdown, a blank line and `</details>` are a section whose title and body
27
+ * are edited in place. Default true. With false, the section is HTML.
28
+ */
29
+ readonly details?: boolean;
18
30
  /** Syntax outside CommonMark and GFM, such as math or footnotes. */
19
31
  readonly syntax?: readonly MarkdownSyntax[];
20
32
  }
@@ -66,6 +78,8 @@ export interface ResolvedMarkdown {
66
78
  readonly breaks: boolean;
67
79
  readonly setext: boolean;
68
80
  readonly autolinks: boolean;
81
+ readonly callouts: boolean;
82
+ readonly details: boolean;
69
83
  readonly syntax: readonly MarkdownSyntax[];
70
84
  readonly inline: readonly InlineSyntax[];
71
85
  readonly block: readonly BlockSyntax[];