terminoir 0.8.0 → 0.9.0
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 +1 -0
- package/dist/components/MarkdownEditor.svelte +362 -0
- package/dist/components/MarkdownEditor.svelte.d.ts +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/markdownEditor/blocks.d.ts +27 -0
- package/dist/utils/markdownEditor/blocks.js +107 -0
- package/dist/utils/markdownEditor/triggers.d.ts +17 -0
- package/dist/utils/markdownEditor/triggers.js +69 -0
- package/dist/utils/markdownEditor/wikilink.d.ts +20 -0
- package/dist/utils/markdownEditor/wikilink.js +92 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -153,6 +153,7 @@ Building blocks so apps compose screens without CSS of their own. See the demo's
|
|
|
153
153
|
| `DataTable` | Columns, `cell` snippet, clickable rows, `hideOnMobile`, empty state |
|
|
154
154
|
| `List`, `ListItem`, `DescriptionList`, `FormRow` | Rows with leading/trailing slots; key–value pairs; label-left form rows |
|
|
155
155
|
| `SearchPicker` | Debounced async combobox (`search(q)`), keyboard navigation; grows to fill a row after chips |
|
|
156
|
+
| `MarkdownEditor` | Notion-style editor that reads and writes markdown (Milkdown): `/` block menu, block handle (`+` and drag to move), checklists, markdown shortcuts, undo. `linkSearch` enables `[[` links written as `[[id\|label]]`; `onlinkopen` gets the clicked target. Outside `value` changes apply while it is not focused; `onchange` fires only after a user edit |
|
|
156
157
|
| `PropertyRow` | Compact icon + label row for inline-edited values (record properties); hover highlights the row |
|
|
157
158
|
| `ChipSelect`, `DateField` | Value shown as a coloured `Chip` that opens a grouped option list (`ChipSelectOption`, `ChipSelectGroup`); date shown as "Today" / "Tomorrow" / weekday / "Nov 12" (`dayLabel`), `deadline` tints past and today, opens the native picker, Backspace clears |
|
|
158
159
|
| `TitleInput`, `FileButton`, `RadioCards` | Borderless heading input; button that opens a file picker; card-style radio group |
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import { defaultValueCtx, Editor, editorViewCtx, editorViewOptionsCtx, remarkStringifyOptionsCtx, rootCtx } from '@milkdown/kit/core';
|
|
4
|
+
import type { Ctx } from '@milkdown/kit/ctx';
|
|
5
|
+
import { block, BlockProvider } from '@milkdown/kit/plugin/block';
|
|
6
|
+
import { clipboard } from '@milkdown/kit/plugin/clipboard';
|
|
7
|
+
import { history } from '@milkdown/kit/plugin/history';
|
|
8
|
+
import { listener, listenerCtx } from '@milkdown/kit/plugin/listener';
|
|
9
|
+
import { commonmark } from '@milkdown/kit/preset/commonmark';
|
|
10
|
+
import { gfm } from '@milkdown/kit/preset/gfm';
|
|
11
|
+
import { TextSelection } from '@milkdown/kit/prose/state';
|
|
12
|
+
import { getMarkdown, replaceAll } from '@milkdown/kit/utils';
|
|
13
|
+
import { cn } from '../utils/cn.js';
|
|
14
|
+
import type { PickerOption } from '../utils/componentTypes.js';
|
|
15
|
+
import { moveIndex } from '../utils/listNav.js';
|
|
16
|
+
import { matchBlocks, placeholderPlugin, taskListItemView, tidyMarkdown, type BlockItem } from '../utils/markdownEditor/blocks.js';
|
|
17
|
+
import { triggerPlugin, type Trigger } from '../utils/markdownEditor/triggers.js';
|
|
18
|
+
import { wikilink, wikilinkNode } from '../utils/markdownEditor/wikilink.js';
|
|
19
|
+
import NavIcon from './NavIcon.svelte';
|
|
20
|
+
|
|
21
|
+
type MenuEntry = { id: string; label: string; icon?: string; iconColor?: string; description?: string; choose: () => void };
|
|
22
|
+
|
|
23
|
+
const LINK_SEARCH_DEBOUNCE_MS = 120;
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
value,
|
|
27
|
+
onchange,
|
|
28
|
+
label,
|
|
29
|
+
placeholder = 'Write, or type / for blocks',
|
|
30
|
+
linkSearch,
|
|
31
|
+
onlinkopen,
|
|
32
|
+
class: className = ''
|
|
33
|
+
}: {
|
|
34
|
+
/** Markdown. Outside changes are applied while the editor is not focused. */
|
|
35
|
+
value: string;
|
|
36
|
+
/** Called with the edited markdown (only after a user edit, never on load). */
|
|
37
|
+
onchange?: (markdown: string) => void;
|
|
38
|
+
/** Accessible name of the writing surface. */
|
|
39
|
+
label: string;
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
/** Enables `[[` links: options for the typed text. A chosen option is written as `[[id|label]]`. */
|
|
42
|
+
linkSearch?: (query: string) => Promise<PickerOption[]>;
|
|
43
|
+
/** A `[[link]]` was clicked; receives its target (the part before `|`). */
|
|
44
|
+
onlinkopen?: (target: string) => void;
|
|
45
|
+
class?: string;
|
|
46
|
+
} = $props();
|
|
47
|
+
|
|
48
|
+
const uid = $props.id();
|
|
49
|
+
let root = $state<HTMLDivElement>();
|
|
50
|
+
let host = $state<HTMLDivElement>();
|
|
51
|
+
let handle = $state<HTMLDivElement>();
|
|
52
|
+
let editor: Editor | undefined;
|
|
53
|
+
let provider: BlockProvider | undefined;
|
|
54
|
+
/** Normalized markdown of what the editor last loaded or emitted; changes equal to it are not edits. */
|
|
55
|
+
let known = '';
|
|
56
|
+
|
|
57
|
+
let trigger = $state<Trigger | null>(null);
|
|
58
|
+
let entries = $state<MenuEntry[]>([]);
|
|
59
|
+
let active = $state(0);
|
|
60
|
+
let searching = $state(false);
|
|
61
|
+
let searchSeq = 0;
|
|
62
|
+
|
|
63
|
+
function act<T>(fn: (ctx: Ctx) => T): T | undefined {
|
|
64
|
+
return editor?.action(fn);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function replaceTrigger(run: (ctx: Ctx) => void) {
|
|
68
|
+
const range = trigger;
|
|
69
|
+
if (!range) return;
|
|
70
|
+
act((ctx) => {
|
|
71
|
+
const view = ctx.get(editorViewCtx);
|
|
72
|
+
view.dispatch(view.state.tr.delete(range.from, range.to));
|
|
73
|
+
run(ctx);
|
|
74
|
+
view.focus();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function chooseBlock(item: BlockItem) {
|
|
79
|
+
replaceTrigger((ctx) => item.run(ctx));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function chooseLink(option: PickerOption) {
|
|
83
|
+
const range = trigger;
|
|
84
|
+
if (!range) return;
|
|
85
|
+
act((ctx) => {
|
|
86
|
+
const view = ctx.get(editorViewCtx);
|
|
87
|
+
const link = wikilinkNode.type(ctx).create({ target: option.id, label: option.label });
|
|
88
|
+
const tr = view.state.tr.replaceWith(range.from, range.to, link);
|
|
89
|
+
view.dispatch(tr.insertText(' ', range.from + link.nodeSize));
|
|
90
|
+
view.focus();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onKey(key: string): boolean {
|
|
95
|
+
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
96
|
+
active = moveIndex(active, key === 'ArrowDown' ? 1 : -1, entries.length);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const entry = entries[active];
|
|
100
|
+
if (!entry) return false;
|
|
101
|
+
entry.choose();
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
$effect(() => {
|
|
106
|
+
const current = trigger;
|
|
107
|
+
if (!current) {
|
|
108
|
+
entries = [];
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (current.kind === 'slash') {
|
|
112
|
+
entries = matchBlocks(current.query).map((item) => ({ id: item.id, label: item.label, icon: item.icon, choose: () => chooseBlock(item) }));
|
|
113
|
+
active = 0;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const query = current.query.trim();
|
|
117
|
+
if (!query || !linkSearch) {
|
|
118
|
+
entries = [];
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const seq = ++searchSeq;
|
|
122
|
+
const timer = setTimeout(async () => {
|
|
123
|
+
searching = true;
|
|
124
|
+
try {
|
|
125
|
+
const found = await linkSearch(query);
|
|
126
|
+
if (seq !== searchSeq) return;
|
|
127
|
+
entries = found.map((option) => ({ ...option, choose: () => chooseLink(option) }));
|
|
128
|
+
active = 0;
|
|
129
|
+
} catch {
|
|
130
|
+
if (seq === searchSeq) entries = [];
|
|
131
|
+
} finally {
|
|
132
|
+
if (seq === searchSeq) searching = false;
|
|
133
|
+
}
|
|
134
|
+
}, LINK_SEARCH_DEBOUNCE_MS);
|
|
135
|
+
return () => clearTimeout(timer);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
function emit(markdown: string) {
|
|
139
|
+
const tidy = tidyMarkdown(markdown);
|
|
140
|
+
if (tidy === known) return;
|
|
141
|
+
known = tidy;
|
|
142
|
+
onchange?.(tidy);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Load outside changes, but never under the writer's caret. */
|
|
146
|
+
$effect(() => {
|
|
147
|
+
const next = value;
|
|
148
|
+
if (!editor || tidyMarkdown(next) === known) return;
|
|
149
|
+
const focused = act((ctx) => ctx.get(editorViewCtx).hasFocus());
|
|
150
|
+
if (focused) return;
|
|
151
|
+
act(replaceAll(next));
|
|
152
|
+
known = tidyMarkdown(act(getMarkdown()) ?? next);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** The handle's `+`: open the `/` menu on a new line under the hovered block. */
|
|
156
|
+
function addBlockBelow() {
|
|
157
|
+
const target = provider?.active;
|
|
158
|
+
if (!target) return;
|
|
159
|
+
act((ctx) => {
|
|
160
|
+
const view = ctx.get(editorViewCtx);
|
|
161
|
+
const at = target.$pos.pos + target.node.nodeSize;
|
|
162
|
+
const paragraph = view.state.schema.nodes.paragraph.create(null, view.state.schema.text('/'));
|
|
163
|
+
const tr = view.state.tr.insert(at, paragraph);
|
|
164
|
+
view.dispatch(tr.setSelection(TextSelection.create(tr.doc, at + 2)).scrollIntoView());
|
|
165
|
+
view.focus();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function onHostClick(event: MouseEvent) {
|
|
170
|
+
const link = (event.target as HTMLElement).closest<HTMLElement>('[data-wikilink]');
|
|
171
|
+
if (link && onlinkopen) onlinkopen(link.dataset.wikilink ?? '');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
onMount(() => {
|
|
175
|
+
let disposed = false;
|
|
176
|
+
const made = Editor.make()
|
|
177
|
+
.config((ctx) => {
|
|
178
|
+
ctx.set(rootCtx, host!);
|
|
179
|
+
ctx.set(defaultValueCtx, value);
|
|
180
|
+
ctx.update(remarkStringifyOptionsCtx, (options) => ({ ...options, bullet: '-' as const, rule: '-' as const }));
|
|
181
|
+
ctx.update(editorViewOptionsCtx, (options) => ({
|
|
182
|
+
...options,
|
|
183
|
+
attributes: { class: 'terminoir-md__surface', 'aria-label': label, 'aria-multiline': 'true', role: 'textbox' }
|
|
184
|
+
}));
|
|
185
|
+
ctx.get(listenerCtx).markdownUpdated((_, markdown) => emit(markdown));
|
|
186
|
+
})
|
|
187
|
+
.use(commonmark)
|
|
188
|
+
.use(gfm)
|
|
189
|
+
.use(history)
|
|
190
|
+
.use(listener)
|
|
191
|
+
.use(clipboard)
|
|
192
|
+
.use(block)
|
|
193
|
+
.use(wikilink)
|
|
194
|
+
.use(taskListItemView)
|
|
195
|
+
.use(placeholderPlugin(placeholder))
|
|
196
|
+
.use(triggerPlugin({ onchange: (next) => (trigger = next), onkey: onKey }, Boolean(linkSearch)));
|
|
197
|
+
|
|
198
|
+
void made.create().then((created) => {
|
|
199
|
+
if (disposed) {
|
|
200
|
+
void created.destroy();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
editor = created;
|
|
204
|
+
known = tidyMarkdown(act(getMarkdown()) ?? value);
|
|
205
|
+
provider = new BlockProvider({ ctx: created.ctx, content: handle!, root, getOffset: () => 6 });
|
|
206
|
+
provider.update();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return () => {
|
|
210
|
+
disposed = true;
|
|
211
|
+
provider?.destroy();
|
|
212
|
+
void editor?.destroy();
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
</script>
|
|
216
|
+
|
|
217
|
+
<div class={cn('terminoir-md', className)} bind:this={root}>
|
|
218
|
+
<!-- Link chips are also reachable as text; the click only adds a shortcut to open them. -->
|
|
219
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
220
|
+
<div bind:this={host} onclick={onHostClick}></div>
|
|
221
|
+
<div class="terminoir-md__handle" bind:this={handle}>
|
|
222
|
+
<button type="button" class="terminoir-md__handle-button" aria-label="Add block below" onmousedown={(e) => e.preventDefault()} onclick={addBlockBelow}>
|
|
223
|
+
<NavIcon name="plus" />
|
|
224
|
+
</button>
|
|
225
|
+
<span class="terminoir-md__handle-grip" aria-hidden="true" title="Drag to move"><NavIcon name="grip-vertical" /></span>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
{#if trigger && (entries.length || trigger.kind === 'link')}
|
|
230
|
+
<ul
|
|
231
|
+
id={`${uid}-menu`}
|
|
232
|
+
class="terminoir-md__menu glass-popover"
|
|
233
|
+
role="listbox"
|
|
234
|
+
aria-label={trigger.kind === 'slash' ? 'Blocks' : 'Link to'}
|
|
235
|
+
style:left={`${trigger.left}px`}
|
|
236
|
+
style:top={`${trigger.top + 4}px`}
|
|
237
|
+
>
|
|
238
|
+
{#each entries as entry, index (entry.id)}
|
|
239
|
+
<!-- Focus stays in the editor, which handles arrow keys and Enter. -->
|
|
240
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
241
|
+
<li
|
|
242
|
+
role="option"
|
|
243
|
+
aria-selected={index === active}
|
|
244
|
+
class="terminoir-md__option"
|
|
245
|
+
class:terminoir-md__option--active={index === active}
|
|
246
|
+
onpointerdown={(event) => event.preventDefault()}
|
|
247
|
+
onpointerenter={() => (active = index)}
|
|
248
|
+
onclick={() => entry.choose()}
|
|
249
|
+
>
|
|
250
|
+
{#if entry.icon}<NavIcon name={entry.icon} color={entry.iconColor} />{/if}
|
|
251
|
+
<span class="terminoir-md__option-label">{entry.label}</span>
|
|
252
|
+
{#if entry.description}<span class="terminoir-md__option-description">{entry.description}</span>{/if}
|
|
253
|
+
</li>
|
|
254
|
+
{:else}
|
|
255
|
+
<li class="terminoir-md__empty" role="presentation">
|
|
256
|
+
{searching ? 'Searching…' : trigger.query.trim() ? 'No matches' : 'Type to search'}
|
|
257
|
+
</li>
|
|
258
|
+
{/each}
|
|
259
|
+
</ul>
|
|
260
|
+
{/if}
|
|
261
|
+
|
|
262
|
+
<style>
|
|
263
|
+
.terminoir-md { position: relative; }
|
|
264
|
+
.terminoir-md :global(.terminoir-md__surface) {
|
|
265
|
+
outline: none;
|
|
266
|
+
min-height: 6rem;
|
|
267
|
+
padding: var(--space-1) 0;
|
|
268
|
+
color: var(--foreground);
|
|
269
|
+
font-size: 0.9375rem;
|
|
270
|
+
line-height: 1.65;
|
|
271
|
+
white-space: pre-wrap;
|
|
272
|
+
word-wrap: break-word;
|
|
273
|
+
}
|
|
274
|
+
.terminoir-md :global(.terminoir-md__surface > * + *) { margin-top: var(--space-2); }
|
|
275
|
+
.terminoir-md :global(p) { margin: 0; }
|
|
276
|
+
.terminoir-md :global(h1) { font-size: 1.5rem; font-weight: 600; line-height: 1.3; margin: var(--space-5) 0 var(--space-2); }
|
|
277
|
+
.terminoir-md :global(h2) { font-size: 1.2rem; font-weight: 600; line-height: 1.35; margin: var(--space-4) 0 var(--space-2); }
|
|
278
|
+
.terminoir-md :global(h3) { font-size: 1.05rem; font-weight: 600; margin: var(--space-3) 0 var(--space-1); }
|
|
279
|
+
.terminoir-md :global(.terminoir-md__surface > :first-child) { margin-top: 0; }
|
|
280
|
+
.terminoir-md :global(ul),
|
|
281
|
+
.terminoir-md :global(ol) { margin: 0; padding-left: 1.5rem; }
|
|
282
|
+
.terminoir-md :global(li > div > p),
|
|
283
|
+
.terminoir-md :global(li > p) { margin: 0; }
|
|
284
|
+
.terminoir-md :global(li[data-item-type='task']) { list-style: none; display: flex; align-items: flex-start; gap: var(--space-2); margin-left: -1.5rem; }
|
|
285
|
+
.terminoir-md :global(li[data-item-type='task'] > .terminoir-md-task-body) { flex: 1; min-width: 0; }
|
|
286
|
+
.terminoir-md :global(li[data-item-type='task'][data-checked='true'] > .terminoir-md-task-body) { color: var(--muted-foreground); text-decoration: line-through; }
|
|
287
|
+
.terminoir-md :global(.terminoir-md-task-box) { margin-top: 0.4em; accent-color: var(--primary); cursor: pointer; }
|
|
288
|
+
.terminoir-md :global(blockquote) { margin: 0; padding-left: var(--space-3); border-left: 2px solid var(--border); color: var(--muted-foreground); }
|
|
289
|
+
.terminoir-md :global(code) { font-family: var(--font-mono); font-size: 0.875em; padding: 0.1em 0.3em; border-radius: 0.3em; background: var(--muted); }
|
|
290
|
+
.terminoir-md :global(pre) { font-family: var(--font-mono); font-size: 0.8125rem; padding: var(--space-3); border-radius: var(--radius-control); background: var(--muted); overflow-x: auto; }
|
|
291
|
+
.terminoir-md :global(pre code) { padding: 0; background: none; }
|
|
292
|
+
.terminoir-md :global(hr) { border: none; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
|
|
293
|
+
.terminoir-md :global(a) { color: var(--primary); text-underline-offset: 2px; }
|
|
294
|
+
.terminoir-md :global(table) { border-collapse: collapse; font-size: 0.875rem; }
|
|
295
|
+
.terminoir-md :global(th),
|
|
296
|
+
.terminoir-md :global(td) { border: 1px solid var(--border); padding: var(--space-1) var(--space-2); }
|
|
297
|
+
.terminoir-md :global(.terminoir-md-wikilink) {
|
|
298
|
+
display: inline-block;
|
|
299
|
+
padding: 0 0.4em;
|
|
300
|
+
border-radius: var(--radius-pill);
|
|
301
|
+
background: color-mix(in srgb, var(--primary) 16%, transparent);
|
|
302
|
+
color: var(--primary);
|
|
303
|
+
cursor: pointer;
|
|
304
|
+
}
|
|
305
|
+
.terminoir-md :global(.terminoir-md-wikilink.ProseMirror-selectednode) { outline: 1px solid var(--ring); }
|
|
306
|
+
.terminoir-md :global(.terminoir-md--empty::before) {
|
|
307
|
+
content: attr(data-placeholder);
|
|
308
|
+
position: absolute;
|
|
309
|
+
color: var(--muted-foreground);
|
|
310
|
+
pointer-events: none;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.terminoir-md__handle {
|
|
314
|
+
position: absolute;
|
|
315
|
+
display: flex;
|
|
316
|
+
align-items: center;
|
|
317
|
+
gap: 0.1rem;
|
|
318
|
+
color: var(--muted-foreground);
|
|
319
|
+
font-size: 0.75rem;
|
|
320
|
+
transition: opacity var(--duration-fast) ease;
|
|
321
|
+
}
|
|
322
|
+
.terminoir-md__handle:global([data-show='false']) { opacity: 0; pointer-events: none; }
|
|
323
|
+
.terminoir-md__handle-button,
|
|
324
|
+
.terminoir-md__handle-grip {
|
|
325
|
+
display: grid;
|
|
326
|
+
place-items: center;
|
|
327
|
+
width: 1.35rem;
|
|
328
|
+
height: 1.35rem;
|
|
329
|
+
border-radius: 0.3rem;
|
|
330
|
+
border: none;
|
|
331
|
+
background: none;
|
|
332
|
+
color: inherit;
|
|
333
|
+
cursor: pointer;
|
|
334
|
+
}
|
|
335
|
+
.terminoir-md__handle-grip { cursor: grab; }
|
|
336
|
+
.terminoir-md__handle-button:hover,
|
|
337
|
+
.terminoir-md__handle-grip:hover { background: color-mix(in srgb, var(--foreground) 8%, transparent); color: var(--foreground); }
|
|
338
|
+
|
|
339
|
+
.terminoir-md__menu {
|
|
340
|
+
position: fixed;
|
|
341
|
+
z-index: 60;
|
|
342
|
+
width: 16rem;
|
|
343
|
+
max-height: 18rem;
|
|
344
|
+
overflow-y: auto;
|
|
345
|
+
margin: 0;
|
|
346
|
+
padding: var(--space-1);
|
|
347
|
+
list-style: none;
|
|
348
|
+
}
|
|
349
|
+
.terminoir-md__option {
|
|
350
|
+
display: flex;
|
|
351
|
+
align-items: center;
|
|
352
|
+
gap: var(--space-2);
|
|
353
|
+
padding: 0.45rem 0.6rem;
|
|
354
|
+
border-radius: calc(var(--radius-control) - 0.2rem);
|
|
355
|
+
font-size: 0.875rem;
|
|
356
|
+
cursor: pointer;
|
|
357
|
+
}
|
|
358
|
+
.terminoir-md__option--active { background: color-mix(in srgb, var(--foreground) 8%, transparent); }
|
|
359
|
+
.terminoir-md__option-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
360
|
+
.terminoir-md__option-description { font-size: 0.75rem; color: var(--muted-foreground); flex-shrink: 0; }
|
|
361
|
+
.terminoir-md__empty { padding: 0.5rem 0.6rem; font-size: 0.8125rem; color: var(--muted-foreground); }
|
|
362
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PickerOption } from '../utils/componentTypes.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
/** Markdown. Outside changes are applied while the editor is not focused. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Called with the edited markdown (only after a user edit, never on load). */
|
|
6
|
+
onchange?: (markdown: string) => void;
|
|
7
|
+
/** Accessible name of the writing surface. */
|
|
8
|
+
label: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Enables `[[` links: options for the typed text. A chosen option is written as `[[id|label]]`. */
|
|
11
|
+
linkSearch?: (query: string) => Promise<PickerOption[]>;
|
|
12
|
+
/** A `[[link]]` was clicked; receives its target (the part before `|`). */
|
|
13
|
+
onlinkopen?: (target: string) => void;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const MarkdownEditor: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
17
|
+
type MarkdownEditor = ReturnType<typeof MarkdownEditor>;
|
|
18
|
+
export default MarkdownEditor;
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export type { ChipSelectGroup, ChipSelectOption } from './utils/componentTypes.j
|
|
|
79
79
|
export { default as DateField } from './components/DateField.svelte';
|
|
80
80
|
export { dayLabel, dayUrgency, parseYmd, type DayUrgency } from './utils/dayLabel.js';
|
|
81
81
|
export { default as SearchPicker } from './components/SearchPicker.svelte';
|
|
82
|
+
export { default as MarkdownEditor } from './components/MarkdownEditor.svelte';
|
|
82
83
|
export { default as FileButton } from './components/FileButton.svelte';
|
|
83
84
|
export { default as TitleInput } from './components/TitleInput.svelte';
|
|
84
85
|
export type { PickerOption } from './utils/componentTypes.js';
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ export { default as ChipSelect } from './components/ChipSelect.svelte';
|
|
|
71
71
|
export { default as DateField } from './components/DateField.svelte';
|
|
72
72
|
export { dayLabel, dayUrgency, parseYmd } from './utils/dayLabel.js';
|
|
73
73
|
export { default as SearchPicker } from './components/SearchPicker.svelte';
|
|
74
|
+
export { default as MarkdownEditor } from './components/MarkdownEditor.svelte';
|
|
74
75
|
export { default as FileButton } from './components/FileButton.svelte';
|
|
75
76
|
export { default as TitleInput } from './components/TitleInput.svelte';
|
|
76
77
|
export { default as RadioCards } from './components/RadioCards.svelte';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Block types offered by the `/` menu, task-list checkboxes, and markdown output tidying. */
|
|
2
|
+
import type { Ctx } from '@milkdown/kit/ctx';
|
|
3
|
+
import type { Node } from '@milkdown/kit/prose/model';
|
|
4
|
+
import { type EditorView } from '@milkdown/kit/prose/view';
|
|
5
|
+
export type BlockItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
/** Extra words the `/` query matches, e.g. "h1" or "todo". */
|
|
10
|
+
keywords: string;
|
|
11
|
+
run: (ctx: Ctx) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const BLOCK_ITEMS: BlockItem[];
|
|
14
|
+
export declare function matchBlocks(query: string): BlockItem[];
|
|
15
|
+
/** List items with a `checked` attribute (task lists) get a real checkbox. */
|
|
16
|
+
export declare const taskListItemView: import("@milkdown/kit/utils").$View<import("@milkdown/kit/utils").$Node, (initial: Node, view: EditorView, getPos: () => number | undefined) => {
|
|
17
|
+
dom: HTMLLIElement;
|
|
18
|
+
contentDOM: HTMLDivElement;
|
|
19
|
+
update(next: Node): boolean;
|
|
20
|
+
ignoreMutation: (mutation: {
|
|
21
|
+
target: globalThis.Node;
|
|
22
|
+
}) => boolean;
|
|
23
|
+
}>;
|
|
24
|
+
/** Hint text on an empty document. */
|
|
25
|
+
export declare function placeholderPlugin(text: string): import("@milkdown/kit/utils").$Prose;
|
|
26
|
+
/** Milkdown writes empty paragraphs as `<br />`; plain blank lines read better everywhere else. */
|
|
27
|
+
export declare function tidyMarkdown(markdown: string): string;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { editorViewCtx } from '@milkdown/kit/core';
|
|
2
|
+
import { createCodeBlockCommand, insertHrCommand, listItemSchema, turnIntoTextCommand, wrapInBlockquoteCommand, wrapInBulletListCommand, wrapInHeadingCommand, wrapInOrderedListCommand } from '@milkdown/kit/preset/commonmark';
|
|
3
|
+
import { Plugin } from '@milkdown/kit/prose/state';
|
|
4
|
+
import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
|
|
5
|
+
import { $prose, $view, callCommand } from '@milkdown/kit/utils';
|
|
6
|
+
function markNearestListItemAsTask(ctx) {
|
|
7
|
+
const view = ctx.get(editorViewCtx);
|
|
8
|
+
const { $from } = view.state.selection;
|
|
9
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
10
|
+
const node = $from.node(depth);
|
|
11
|
+
if (node.type.name === 'list_item') {
|
|
12
|
+
view.dispatch(view.state.tr.setNodeMarkup($from.before(depth), undefined, { ...node.attrs, checked: false }));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const BLOCK_ITEMS = [
|
|
18
|
+
{ id: 'text', label: 'Text', icon: 'paragraph', keywords: 'paragraph plain', run: (ctx) => callCommand(turnIntoTextCommand.key)(ctx) },
|
|
19
|
+
{ id: 'h1', label: 'Heading 1', icon: 'heading', keywords: 'h1 title', run: (ctx) => callCommand(wrapInHeadingCommand.key, 1)(ctx) },
|
|
20
|
+
{ id: 'h2', label: 'Heading 2', icon: 'heading', keywords: 'h2 subtitle', run: (ctx) => callCommand(wrapInHeadingCommand.key, 2)(ctx) },
|
|
21
|
+
{ id: 'h3', label: 'Heading 3', icon: 'heading', keywords: 'h3', run: (ctx) => callCommand(wrapInHeadingCommand.key, 3)(ctx) },
|
|
22
|
+
{
|
|
23
|
+
id: 'todo',
|
|
24
|
+
label: 'Checklist',
|
|
25
|
+
icon: 'square-check',
|
|
26
|
+
keywords: 'todo task checkbox',
|
|
27
|
+
run: (ctx) => {
|
|
28
|
+
callCommand(wrapInBulletListCommand.key)(ctx);
|
|
29
|
+
markNearestListItemAsTask(ctx);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{ id: 'bullet', label: 'Bulleted list', icon: 'list-ul', keywords: 'ul unordered', run: (ctx) => callCommand(wrapInBulletListCommand.key)(ctx) },
|
|
33
|
+
{ id: 'number', label: 'Numbered list', icon: 'list-ol', keywords: 'ol ordered', run: (ctx) => callCommand(wrapInOrderedListCommand.key)(ctx) },
|
|
34
|
+
{ id: 'quote', label: 'Quote', icon: 'quote-left', keywords: 'blockquote', run: (ctx) => callCommand(wrapInBlockquoteCommand.key)(ctx) },
|
|
35
|
+
{ id: 'code', label: 'Code', icon: 'code', keywords: 'codeblock pre', run: (ctx) => callCommand(createCodeBlockCommand.key)(ctx) },
|
|
36
|
+
{ id: 'divider', label: 'Divider', icon: 'minus', keywords: 'hr rule separator', run: (ctx) => callCommand(insertHrCommand.key)(ctx) }
|
|
37
|
+
];
|
|
38
|
+
export function matchBlocks(query) {
|
|
39
|
+
const q = query.trim().toLowerCase();
|
|
40
|
+
if (!q)
|
|
41
|
+
return BLOCK_ITEMS;
|
|
42
|
+
return BLOCK_ITEMS.filter((item) => `${item.label} ${item.keywords}`.toLowerCase().includes(q));
|
|
43
|
+
}
|
|
44
|
+
/** List items with a `checked` attribute (task lists) get a real checkbox. */
|
|
45
|
+
export const taskListItemView = $view(listItemSchema.node, () => (initial, view, getPos) => {
|
|
46
|
+
let node = initial;
|
|
47
|
+
const dom = document.createElement('li');
|
|
48
|
+
const box = document.createElement('input');
|
|
49
|
+
box.type = 'checkbox';
|
|
50
|
+
box.contentEditable = 'false';
|
|
51
|
+
box.className = 'terminoir-md-task-box';
|
|
52
|
+
box.addEventListener('mousedown', (event) => event.preventDefault());
|
|
53
|
+
box.addEventListener('click', () => {
|
|
54
|
+
const pos = getPos();
|
|
55
|
+
if (pos === undefined)
|
|
56
|
+
return;
|
|
57
|
+
view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked: !node.attrs.checked }));
|
|
58
|
+
});
|
|
59
|
+
const contentDOM = document.createElement('div');
|
|
60
|
+
contentDOM.className = 'terminoir-md-task-body';
|
|
61
|
+
function render() {
|
|
62
|
+
const isTask = node.attrs.checked != null;
|
|
63
|
+
dom.dataset.itemType = isTask ? 'task' : '';
|
|
64
|
+
dom.dataset.checked = String(Boolean(node.attrs.checked));
|
|
65
|
+
box.checked = Boolean(node.attrs.checked);
|
|
66
|
+
box.hidden = !isTask;
|
|
67
|
+
}
|
|
68
|
+
dom.append(box, contentDOM);
|
|
69
|
+
render();
|
|
70
|
+
return {
|
|
71
|
+
dom,
|
|
72
|
+
contentDOM,
|
|
73
|
+
update(next) {
|
|
74
|
+
if (next.type !== node.type)
|
|
75
|
+
return false;
|
|
76
|
+
node = next;
|
|
77
|
+
render();
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
ignoreMutation: (mutation) => mutation.target === box
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
/** Hint text on an empty document. */
|
|
84
|
+
export function placeholderPlugin(text) {
|
|
85
|
+
return $prose(() => new Plugin({
|
|
86
|
+
props: {
|
|
87
|
+
decorations(state) {
|
|
88
|
+
const { doc } = state;
|
|
89
|
+
const only = doc.firstChild;
|
|
90
|
+
if (doc.childCount !== 1 || !only?.isTextblock || only.content.size)
|
|
91
|
+
return null;
|
|
92
|
+
return DecorationSet.create(doc, [
|
|
93
|
+
Decoration.node(0, only.nodeSize, { class: 'terminoir-md--empty', 'data-placeholder': text })
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
/** Milkdown writes empty paragraphs as `<br />`; plain blank lines read better everywhere else. */
|
|
100
|
+
export function tidyMarkdown(markdown) {
|
|
101
|
+
return markdown
|
|
102
|
+
.split('\n')
|
|
103
|
+
.filter((line) => line.trim() !== '<br />')
|
|
104
|
+
.join('\n')
|
|
105
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
106
|
+
.trimEnd();
|
|
107
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type TriggerKind = 'slash' | 'link';
|
|
2
|
+
export type Trigger = {
|
|
3
|
+
kind: TriggerKind;
|
|
4
|
+
query: string;
|
|
5
|
+
/** Document range of the trigger text (`/qu` or `[[qu`), replaced when an item is chosen. */
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
/** Viewport position under the trigger, for the menu. */
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
};
|
|
12
|
+
export type TriggerHandlers = {
|
|
13
|
+
onchange: (trigger: Trigger | null) => void;
|
|
14
|
+
/** Return true when the open menu used the key. */
|
|
15
|
+
onkey: (key: string) => boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function triggerPlugin(handlers: TriggerHandlers, linksEnabled: boolean): import("@milkdown/kit/utils").$Prose;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watches the text before the caret for a menu trigger (`/` at a word start, or `[[`) and
|
|
3
|
+
* hands arrow/Enter/Tab/Escape to the open menu while focus stays in the editor.
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
|
|
6
|
+
import { $prose } from '@milkdown/kit/utils';
|
|
7
|
+
const SLASH = /(?:^|\s)\/([\w-]{0,24})$/;
|
|
8
|
+
const LINK = /\[\[([^[\]\n]{0,60})$/;
|
|
9
|
+
const MENU_KEYS = new Set(['ArrowDown', 'ArrowUp', 'Enter', 'Tab', 'Escape']);
|
|
10
|
+
const ATOM = '';
|
|
11
|
+
function triggerAt(state, linksEnabled) {
|
|
12
|
+
const { selection } = state;
|
|
13
|
+
if (!selection.empty)
|
|
14
|
+
return null;
|
|
15
|
+
const { $from } = selection;
|
|
16
|
+
if (!$from.parent.isTextblock || $from.parent.type.spec.code)
|
|
17
|
+
return null;
|
|
18
|
+
const before = $from.parent.textBetween(0, $from.parentOffset, undefined, ATOM);
|
|
19
|
+
const link = linksEnabled ? LINK.exec(before) : null;
|
|
20
|
+
if (link)
|
|
21
|
+
return { kind: 'link', query: link[1], from: $from.pos - link[0].length, to: $from.pos };
|
|
22
|
+
const slash = SLASH.exec(before);
|
|
23
|
+
if (slash)
|
|
24
|
+
return { kind: 'slash', query: slash[1], from: $from.pos - slash[1].length - 1, to: $from.pos };
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export function triggerPlugin(handlers, linksEnabled) {
|
|
28
|
+
const key = new PluginKey('terminoirTriggers');
|
|
29
|
+
/** A trigger closed with Escape stays closed until the caret leaves it. */
|
|
30
|
+
let dismissedFrom = null;
|
|
31
|
+
let open = false;
|
|
32
|
+
function report(view) {
|
|
33
|
+
const found = view.hasFocus() ? triggerAt(view.state, linksEnabled) : null;
|
|
34
|
+
if (!found || found.from === dismissedFrom) {
|
|
35
|
+
if (!found)
|
|
36
|
+
dismissedFrom = null;
|
|
37
|
+
if (open)
|
|
38
|
+
handlers.onchange(null);
|
|
39
|
+
open = false;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const coords = view.coordsAtPos(found.from);
|
|
43
|
+
open = true;
|
|
44
|
+
handlers.onchange({ ...found, left: coords.left, top: coords.bottom });
|
|
45
|
+
}
|
|
46
|
+
return $prose(() => new Plugin({
|
|
47
|
+
key,
|
|
48
|
+
view: () => ({ update: report }),
|
|
49
|
+
props: {
|
|
50
|
+
handleKeyDown(view, event) {
|
|
51
|
+
if (!open || !MENU_KEYS.has(event.key))
|
|
52
|
+
return false;
|
|
53
|
+
if (event.key === 'Escape') {
|
|
54
|
+
dismissedFrom = triggerAt(view.state, linksEnabled)?.from ?? null;
|
|
55
|
+
report(view);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return handlers.onkey(event.key);
|
|
59
|
+
},
|
|
60
|
+
handleDOMEvents: {
|
|
61
|
+
blur(view) {
|
|
62
|
+
// Let a click on a menu item land before the menu disappears.
|
|
63
|
+
setTimeout(() => report(view), 150);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const WIKILINK_NODE = "wikilink";
|
|
2
|
+
export type WikilinkAttrs = {
|
|
3
|
+
target: string;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
type MdastNode = {
|
|
7
|
+
type: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
children?: MdastNode[];
|
|
10
|
+
data?: unknown;
|
|
11
|
+
};
|
|
12
|
+
export declare function formatWikilink({ target, label }: WikilinkAttrs): string;
|
|
13
|
+
/** Split one text value into text and wikilink pieces (empty when it has no links). */
|
|
14
|
+
export declare function splitWikilinks(text: string): MdastNode[];
|
|
15
|
+
export declare const remarkWikilink: import("@milkdown/kit/utils").$Remark<"remarkWikilink", unknown>;
|
|
16
|
+
export declare const wikilinkNode: import("@milkdown/kit/utils").$Node;
|
|
17
|
+
/** Typing the closing `]]` of `[[Something]]` turns it into a link. */
|
|
18
|
+
export declare const wikilinkInputRule: import("@milkdown/kit/utils").$InputRule;
|
|
19
|
+
export declare const wikilink: (import("@milkdown/kit/ctx").MilkdownPlugin | import("@milkdown/kit/utils").$Node | import("@milkdown/kit/utils").$Ctx<unknown, "remarkWikilink"> | import("@milkdown/kit/utils").$InputRule)[];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `[[target]]` and `[[target|label]]` links as an inline atom, so they round-trip to markdown
|
|
3
|
+
* unescaped and render as chips. Parsing splits remark text nodes; stringifying writes them raw.
|
|
4
|
+
*/
|
|
5
|
+
import { InputRule } from '@milkdown/kit/prose/inputrules';
|
|
6
|
+
import { $inputRule, $node, $remark } from '@milkdown/kit/utils';
|
|
7
|
+
export const WIKILINK_NODE = 'wikilink';
|
|
8
|
+
const MDAST_TYPE = 'wikiLink';
|
|
9
|
+
const WIKILINK = /\[\[([^\]|\n]+)(?:\|([^\]\n]+))?\]\]/g;
|
|
10
|
+
export function formatWikilink({ target, label }) {
|
|
11
|
+
return label && label !== target ? `[[${target}|${label}]]` : `[[${target}]]`;
|
|
12
|
+
}
|
|
13
|
+
/** Split one text value into text and wikilink pieces (empty when it has no links). */
|
|
14
|
+
export function splitWikilinks(text) {
|
|
15
|
+
const parts = [];
|
|
16
|
+
let last = 0;
|
|
17
|
+
for (const match of text.matchAll(WIKILINK)) {
|
|
18
|
+
const start = match.index ?? 0;
|
|
19
|
+
if (start > last)
|
|
20
|
+
parts.push({ type: 'text', value: text.slice(last, start) });
|
|
21
|
+
const target = match[1].trim();
|
|
22
|
+
parts.push({ type: MDAST_TYPE, data: { target, label: (match[2] ?? target).trim() } });
|
|
23
|
+
last = start + match[0].length;
|
|
24
|
+
}
|
|
25
|
+
if (!parts.length)
|
|
26
|
+
return [];
|
|
27
|
+
if (last < text.length)
|
|
28
|
+
parts.push({ type: 'text', value: text.slice(last) });
|
|
29
|
+
return parts;
|
|
30
|
+
}
|
|
31
|
+
function splitTree(node) {
|
|
32
|
+
if (!node.children)
|
|
33
|
+
return;
|
|
34
|
+
node.children = node.children.flatMap((child) => {
|
|
35
|
+
if (child.type === 'text' && child.value) {
|
|
36
|
+
const parts = splitWikilinks(child.value);
|
|
37
|
+
return parts.length ? parts : [child];
|
|
38
|
+
}
|
|
39
|
+
splitTree(child);
|
|
40
|
+
return [child];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export const remarkWikilink = $remark('remarkWikilink', () => function () {
|
|
44
|
+
const data = this.data();
|
|
45
|
+
(data.toMarkdownExtensions ??= []).push({
|
|
46
|
+
handlers: { [MDAST_TYPE]: (node) => formatWikilink(node.data) }
|
|
47
|
+
});
|
|
48
|
+
return (tree) => splitTree(tree);
|
|
49
|
+
});
|
|
50
|
+
export const wikilinkNode = $node(WIKILINK_NODE, () => ({
|
|
51
|
+
inline: true,
|
|
52
|
+
group: 'inline',
|
|
53
|
+
atom: true,
|
|
54
|
+
selectable: true,
|
|
55
|
+
marks: '',
|
|
56
|
+
attrs: { target: { default: '' }, label: { default: '' } },
|
|
57
|
+
parseDOM: [
|
|
58
|
+
{
|
|
59
|
+
tag: 'span[data-wikilink]',
|
|
60
|
+
getAttrs: (dom) => {
|
|
61
|
+
const el = dom;
|
|
62
|
+
return { target: el.dataset.wikilink ?? '', label: el.textContent ?? '' };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
toDOM: (node) => [
|
|
67
|
+
'span',
|
|
68
|
+
{ 'data-wikilink': node.attrs.target, class: 'terminoir-md-wikilink', role: 'link', title: node.attrs.target },
|
|
69
|
+
node.attrs.label || node.attrs.target
|
|
70
|
+
],
|
|
71
|
+
parseMarkdown: {
|
|
72
|
+
match: (node) => node.type === MDAST_TYPE,
|
|
73
|
+
runner: (state, node, type) => {
|
|
74
|
+
state.addNode(type, node.data);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
toMarkdown: {
|
|
78
|
+
match: (node) => node.type.name === WIKILINK_NODE,
|
|
79
|
+
runner: (state, node) => {
|
|
80
|
+
state.addNode(MDAST_TYPE, undefined, undefined, { data: { target: node.attrs.target, label: node.attrs.label } });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
/** Typing the closing `]]` of `[[Something]]` turns it into a link. */
|
|
85
|
+
export const wikilinkInputRule = $inputRule((ctx) => new InputRule(/\[\[([^\]|\n]+)(?:\|([^\]\n]+))?\]\]$/, (state, match, start, end) => {
|
|
86
|
+
const target = match[1].trim();
|
|
87
|
+
if (!target)
|
|
88
|
+
return null;
|
|
89
|
+
const node = wikilinkNode.type(ctx).create({ target, label: (match[2] ?? target).trim() });
|
|
90
|
+
return state.tr.replaceWith(start, end, node);
|
|
91
|
+
}));
|
|
92
|
+
export const wikilink = [remarkWikilink, wikilinkNode, wikilinkInputRule].flat();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "terminoir",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Terminoir
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Terminoir — Liquid Glass design tokens and Svelte 5 UI components.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"style": "./css/index.css",
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
"@fontsource/source-code-pro": "^5.2.5",
|
|
86
86
|
"@fontsource/source-sans-3": "^5.2.5",
|
|
87
87
|
"@fontsource/source-serif-4": "^5.2.5",
|
|
88
|
+
"@milkdown/kit": "7.23.0",
|
|
88
89
|
"@surdeddd/liquidglass": "^0.12.0"
|
|
89
90
|
},
|
|
90
91
|
"devDependencies": {
|