@atmo-dev/kit 0.18.1 → 0.19.1
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/articles/ArticleCard.svelte +97 -0
- package/dist/articles/ArticleCard.svelte.d.ts +20 -0
- package/dist/articles/ArticleCodeBlock.svelte +121 -0
- package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
- package/dist/articles/ArticleEditor.svelte +340 -0
- package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
- package/dist/articles/ArticleLinkEmbed.svelte +50 -0
- package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
- package/dist/articles/ArticleView.svelte +128 -0
- package/dist/articles/ArticleView.svelte.d.ts +46 -0
- package/dist/articles/PublicationIcon.svelte +37 -0
- package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
- package/dist/articles/article-link-embed.d.ts +36 -0
- package/dist/articles/article-link-embed.js +29 -0
- package/dist/articles/dates.d.ts +2 -0
- package/dist/articles/dates.js +12 -0
- package/dist/articles/images.d.ts +5 -0
- package/dist/articles/images.js +44 -0
- package/dist/articles/markdown.d.ts +15 -0
- package/dist/articles/markdown.js +52 -0
- package/dist/articles/paste.d.ts +11 -0
- package/dist/articles/paste.js +27 -0
- package/dist/articles/records.d.ts +166 -0
- package/dist/articles/records.js +423 -0
- package/dist/articles/styles.d.ts +4 -0
- package/dist/articles/styles.js +14 -0
- package/dist/articles-data.d.ts +8 -0
- package/dist/articles-data.js +8 -0
- package/dist/articles.d.ts +10 -0
- package/dist/articles.js +8 -0
- package/dist/components/ExternalEmbed.svelte +16 -2
- package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
- package/dist/components/IconMaker.svelte +119 -0
- package/dist/components/IconMaker.svelte.d.ts +9 -0
- package/dist/components/IconRail.svelte +9 -6
- package/dist/components/IconRail.svelte.d.ts +2 -0
- package/dist/components/LinkEmbed.svelte +24 -21
- package/dist/components/LinkEmbed.svelte.d.ts +3 -2
- package/dist/components/PaletteApply.svelte +62 -0
- package/dist/components/PaletteApply.svelte.d.ts +9 -0
- package/dist/components/PalettePicker.svelte +92 -0
- package/dist/components/PalettePicker.svelte.d.ts +13 -0
- package/dist/components/PostComments.svelte +129 -0
- package/dist/components/PostComments.svelte.d.ts +15 -0
- package/dist/components/RichText.svelte +199 -9
- package/dist/components/RichText.svelte.d.ts +17 -0
- package/dist/components/RichTextEditor.svelte +164 -13
- package/dist/components/RichTextEditor.svelte.d.ts +26 -3
- package/dist/components/composer/ComposerPost.svelte +10 -0
- package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
- package/dist/components/composer/PostComposer.svelte +28 -2
- package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
- package/dist/editor/EditorMenus.svelte +438 -0
- package/dist/editor/EditorMenus.svelte.d.ts +9 -0
- package/dist/editor/SlashOptions.svelte +45 -0
- package/dist/editor/SlashOptions.svelte.d.ts +12 -0
- package/dist/editor/article-commands.d.ts +44 -0
- package/dist/editor/article-commands.js +289 -0
- package/dist/editor/article-extensions.d.ts +8 -0
- package/dist/editor/article-extensions.js +315 -0
- package/dist/editor/article-menus.d.ts +2 -0
- package/dist/editor/article-menus.js +3 -0
- package/dist/editor/document.d.ts +5 -0
- package/dist/editor/document.js +163 -12
- package/dist/editor/image-node.d.ts +8 -0
- package/dist/editor/image-node.js +75 -0
- package/dist/editor/markdown-extensions.d.ts +1 -5
- package/dist/editor/markdown-extensions.js +37 -2
- package/dist/editor/slash-menu.svelte.d.ts +9 -0
- package/dist/editor/slash-menu.svelte.js +134 -0
- package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
- package/dist/embeds/PostLinkEmbed.svelte +12 -29
- package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
- package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/defaults.d.ts +4 -2
- package/dist/embeds/defaults.js +7 -3
- package/dist/embeds/load.d.ts +44 -0
- package/dist/embeds/load.js +139 -0
- package/dist/embeds/types.d.ts +18 -3
- package/dist/events/EventComments.svelte +4 -101
- package/dist/events/EventComments.svelte.d.ts +1 -1
- package/dist/events/EventView.svelte +5 -0
- package/dist/events/EventView.svelte.d.ts +3 -0
- package/dist/events/event-link-embed.d.ts +4 -1
- package/dist/events/event-link-embed.js +9 -1
- package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
- package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
- package/dist/icon-maker/artwork.d.ts +11 -0
- package/dist/icon-maker/artwork.js +25 -0
- package/dist/icon-maker/index.d.ts +12 -0
- package/dist/icon-maker/index.js +73 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +7 -1
- package/dist/palettes.d.ts +20 -0
- package/dist/palettes.js +37 -0
- package/dist/richtext/article-styles.d.ts +10 -0
- package/dist/richtext/article-styles.js +28 -0
- package/dist/richtext/document.d.ts +63 -1
- package/dist/richtext/document.js +54 -0
- package/dist/richtext/markdown.d.ts +19 -4
- package/dist/richtext/markdown.js +223 -18
- package/dist/richtext/serialize.d.ts +5 -1
- package/dist/richtext/serialize.js +163 -31
- package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
- package/dist/richtext/vendor/markdown-tree.js +2584 -26
- package/dist/richtext.d.ts +7 -5
- package/dist/richtext.js +1 -1
- package/dist/social/external-embeds.d.ts +5 -0
- package/dist/social/external-embeds.js +6 -1
- package/dist/social/mention-suggestions.svelte.js +18 -7
- package/dist/social/posts.d.ts +2 -0
- package/dist/social/posts.js +43 -2
- package/dist/social/profile.js +2 -1
- package/package.json +28 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Icon from '../components/Icon.svelte';
|
|
3
|
+
import type { ArticleCommand } from './article-commands.js';
|
|
4
|
+
|
|
5
|
+
// The rows of the slash menu. The menu element around them is the listbox.
|
|
6
|
+
let {
|
|
7
|
+
state
|
|
8
|
+
}: {
|
|
9
|
+
state: {
|
|
10
|
+
id: string;
|
|
11
|
+
items: ArticleCommand[];
|
|
12
|
+
selected: number;
|
|
13
|
+
choose: (index: number) => void;
|
|
14
|
+
};
|
|
15
|
+
} = $props();
|
|
16
|
+
|
|
17
|
+
// Keep the chosen row in view without scrolling the page.
|
|
18
|
+
$effect(() => {
|
|
19
|
+
const option = document.getElementById(`${state.id}-${state.selected}`);
|
|
20
|
+
const list = option?.parentElement;
|
|
21
|
+
if (!option || !list) return;
|
|
22
|
+
if (option.offsetTop < list.scrollTop) list.scrollTop = option.offsetTop - 6;
|
|
23
|
+
else if (option.offsetTop + option.offsetHeight > list.scrollTop + list.clientHeight)
|
|
24
|
+
list.scrollTop = option.offsetTop + option.offsetHeight - list.clientHeight + 6;
|
|
25
|
+
});
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
{#each state.items as item, index (item.id)}
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
role="option"
|
|
32
|
+
id={`${state.id}-${index}`}
|
|
33
|
+
aria-selected={index === state.selected}
|
|
34
|
+
onmousedown={(event) => event.preventDefault()}
|
|
35
|
+
onmousemove={() => (state.selected = index)}
|
|
36
|
+
onclick={() => state.choose(index)}
|
|
37
|
+
class="flex w-full cursor-pointer items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-base-800 outline-none aria-selected:bg-accent-50 aria-selected:text-accent-700 dark:text-base-200 dark:aria-selected:bg-[color-mix(in_srgb,var(--accent-950)_65%,var(--base-950))] dark:aria-selected:text-accent-300"
|
|
38
|
+
>
|
|
39
|
+
<Icon img={item.icon} size={18} class="shrink-0" />
|
|
40
|
+
<span class="min-w-0 flex-1 truncate text-[.8125rem] font-medium">{item.label}</span>
|
|
41
|
+
{#if item.hint}
|
|
42
|
+
<span class="font-mono text-xs text-base-500" aria-hidden="true">{item.hint}</span>
|
|
43
|
+
{/if}
|
|
44
|
+
</button>
|
|
45
|
+
{/each}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ArticleCommand } from './article-commands.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
state: {
|
|
4
|
+
id: string;
|
|
5
|
+
items: ArticleCommand[];
|
|
6
|
+
selected: number;
|
|
7
|
+
choose: (index: number) => void;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare const SlashOptions: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
11
|
+
type SlashOptions = ReturnType<typeof SlashOptions>;
|
|
12
|
+
export default SlashOptions;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import { type EditorState } from '@tiptap/pm/state';
|
|
3
|
+
import { type IconNode } from '@sketchyicons/svelte';
|
|
4
|
+
/** What the commands need from the app around the editor. */
|
|
5
|
+
export type ArticleCommandContext = {
|
|
6
|
+
/** Opens the file picker; undefined when images cannot be added. */
|
|
7
|
+
pickImages?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export type ArticleCommand = {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
icon: IconNode;
|
|
13
|
+
/** What to type to get the same, shown beside the label. */
|
|
14
|
+
hint?: string;
|
|
15
|
+
/** More words to find it by. */
|
|
16
|
+
keywords?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `block` turns the current block into something, `insert` adds something new, `table`
|
|
19
|
+
* changes the table the cursor is in.
|
|
20
|
+
*/
|
|
21
|
+
kind: 'block' | 'insert' | 'table';
|
|
22
|
+
available?: (context: ArticleCommandContext, editor: Editor) => boolean;
|
|
23
|
+
run: (editor: Editor, context: ArticleCommandContext) => void;
|
|
24
|
+
};
|
|
25
|
+
export type ArticleMark = {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
icon: IconNode;
|
|
29
|
+
/** The key pressed with Cmd or Ctrl; uppercase also needs Shift. */
|
|
30
|
+
key: string;
|
|
31
|
+
run: (editor: Editor) => void;
|
|
32
|
+
};
|
|
33
|
+
export declare function inTable(state: EditorState): boolean;
|
|
34
|
+
/** The id of the `block` command the cursor's block is: what it is nearest wrapped in. */
|
|
35
|
+
export declare function currentBlock(state: EditorState): string;
|
|
36
|
+
/** Everything the slash menu offers; the selection menu and the toolbar use parts of it. */
|
|
37
|
+
export declare const ARTICLE_COMMANDS: readonly ArticleCommand[];
|
|
38
|
+
export declare const ARTICLE_MARKS: readonly ArticleMark[];
|
|
39
|
+
/** The commands that apply where the cursor is: a table cell holds one line of text. */
|
|
40
|
+
export declare function availableCommands(editor: Editor, context: ArticleCommandContext): ArticleCommand[];
|
|
41
|
+
/** Commands matching what was typed after the slash, best first. */
|
|
42
|
+
export declare function findCommands(query: string, editor: Editor, context: ArticleCommandContext): ArticleCommand[];
|
|
43
|
+
/** Run a command. Turning a block into what it already is changes nothing. */
|
|
44
|
+
export declare function runCommand(editor: Editor, command: ArticleCommand, context: ArticleCommandContext): undefined;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
2
|
+
import { Bold, Code, Heading1, Heading2, Heading3, Highlighter, Image, Info, Italic, List, ListOrdered, ListTodo, Minus, Plus, Sigma, SquareCode, Strikethrough, Superscript, Table, TextQuote, Trash2, Type } from '@sketchyicons/svelte';
|
|
3
|
+
import { isCallout } from '../richtext/document.js';
|
|
4
|
+
import { FOOTNOTE_DEFINITION, FOOTNOTE_REFERENCE, HIGHLIGHT, MATH } from './document.js';
|
|
5
|
+
const focus = (editor) => editor.chain().focus();
|
|
6
|
+
export function inTable(state) {
|
|
7
|
+
const { $from } = state.selection;
|
|
8
|
+
for (let depth = $from.depth; depth > 0; depth--)
|
|
9
|
+
if ($from.node(depth).type.name === 'table')
|
|
10
|
+
return true;
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
/** The id of the `block` command the cursor's block is: what it is nearest wrapped in. */
|
|
14
|
+
export function currentBlock(state) {
|
|
15
|
+
const { $from } = state.selection;
|
|
16
|
+
const block = $from.parent;
|
|
17
|
+
if (block.type.name === 'codeBlock')
|
|
18
|
+
return block.attrs.language === MATH ? 'math' : 'code';
|
|
19
|
+
if (block.type.name === 'heading')
|
|
20
|
+
return `h${block.attrs.level}`;
|
|
21
|
+
for (let depth = $from.depth - 1; depth > 0; depth--) {
|
|
22
|
+
const node = $from.node(depth);
|
|
23
|
+
switch (node.type.name) {
|
|
24
|
+
case 'bulletList':
|
|
25
|
+
return 'bullet';
|
|
26
|
+
case 'orderedList':
|
|
27
|
+
return 'ordered';
|
|
28
|
+
case 'taskList':
|
|
29
|
+
return 'todo';
|
|
30
|
+
case 'blockquote':
|
|
31
|
+
return isCallout(node.attrs.callout) ? 'callout' : 'quote';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return 'text';
|
|
35
|
+
}
|
|
36
|
+
const heading = (level, icon) => ({
|
|
37
|
+
id: `h${level}`,
|
|
38
|
+
label: `Heading ${level}`,
|
|
39
|
+
icon,
|
|
40
|
+
hint: '#'.repeat(level),
|
|
41
|
+
keywords: 'title',
|
|
42
|
+
kind: 'block',
|
|
43
|
+
run: (editor) => focus(editor).setHeading({ level }).run()
|
|
44
|
+
});
|
|
45
|
+
const quote = (callout) => (editor) => {
|
|
46
|
+
if (editor.isActive('blockquote'))
|
|
47
|
+
focus(editor).updateAttributes('blockquote', { callout }).run();
|
|
48
|
+
else
|
|
49
|
+
focus(editor).wrapIn('blockquote', { callout }).run();
|
|
50
|
+
};
|
|
51
|
+
/** A list item starts with a line of text, so its first line cannot become a quote. */
|
|
52
|
+
const canQuote = (_context, editor) => editor.isActive('blockquote') || editor.can().wrapIn('blockquote');
|
|
53
|
+
/** A reference at the cursor with the next free number, and its note at the end to write in. */
|
|
54
|
+
function insertFootnote(editor) {
|
|
55
|
+
const { state } = editor;
|
|
56
|
+
const reference = state.schema.nodes[FOOTNOTE_REFERENCE];
|
|
57
|
+
const definition = state.schema.nodes[FOOTNOTE_DEFINITION];
|
|
58
|
+
if (!reference || !definition)
|
|
59
|
+
return;
|
|
60
|
+
const used = new Set();
|
|
61
|
+
state.doc.descendants((node) => {
|
|
62
|
+
if (node.type === reference || node.type === definition)
|
|
63
|
+
used.add(String(node.attrs.id));
|
|
64
|
+
});
|
|
65
|
+
let number = 1;
|
|
66
|
+
while (used.has(String(number)))
|
|
67
|
+
number++;
|
|
68
|
+
const id = String(number);
|
|
69
|
+
const tr = state.tr.replaceSelectionWith(reference.create({ id }));
|
|
70
|
+
const end = tr.doc.content.size;
|
|
71
|
+
tr.insert(end, definition.create({ id }, state.schema.nodes.paragraph.create()));
|
|
72
|
+
tr.setSelection(TextSelection.create(tr.doc, end + 2));
|
|
73
|
+
editor.view.dispatch(tr.scrollIntoView());
|
|
74
|
+
editor.view.focus();
|
|
75
|
+
}
|
|
76
|
+
/** Everything the slash menu offers; the selection menu and the toolbar use parts of it. */
|
|
77
|
+
export const ARTICLE_COMMANDS = [
|
|
78
|
+
{
|
|
79
|
+
id: 'text',
|
|
80
|
+
label: 'Text',
|
|
81
|
+
icon: Type,
|
|
82
|
+
keywords: 'paragraph plain',
|
|
83
|
+
kind: 'block',
|
|
84
|
+
run: (editor) => focus(editor).clearNodes().run()
|
|
85
|
+
},
|
|
86
|
+
heading(1, Heading1),
|
|
87
|
+
heading(2, Heading2),
|
|
88
|
+
heading(3, Heading3),
|
|
89
|
+
{
|
|
90
|
+
id: 'bullet',
|
|
91
|
+
label: 'Bulleted list',
|
|
92
|
+
icon: List,
|
|
93
|
+
hint: '-',
|
|
94
|
+
keywords: 'unordered ul',
|
|
95
|
+
kind: 'block',
|
|
96
|
+
run: (editor) => focus(editor).toggleBulletList().run()
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 'ordered',
|
|
100
|
+
label: 'Numbered list',
|
|
101
|
+
icon: ListOrdered,
|
|
102
|
+
hint: '1.',
|
|
103
|
+
keywords: 'ordered ol',
|
|
104
|
+
kind: 'block',
|
|
105
|
+
run: (editor) => focus(editor).toggleOrderedList().run()
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 'todo',
|
|
109
|
+
label: 'To-do list',
|
|
110
|
+
icon: ListTodo,
|
|
111
|
+
hint: '[ ]',
|
|
112
|
+
keywords: 'task checkbox check',
|
|
113
|
+
kind: 'block',
|
|
114
|
+
run: (editor) => focus(editor).toggleTaskList().run()
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'quote',
|
|
118
|
+
label: 'Quote',
|
|
119
|
+
icon: TextQuote,
|
|
120
|
+
hint: '>',
|
|
121
|
+
keywords: 'blockquote citation',
|
|
122
|
+
kind: 'block',
|
|
123
|
+
available: canQuote,
|
|
124
|
+
run: quote(null)
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'callout',
|
|
128
|
+
label: 'Callout',
|
|
129
|
+
icon: Info,
|
|
130
|
+
keywords: 'note tip important warning caution alert',
|
|
131
|
+
kind: 'block',
|
|
132
|
+
available: canQuote,
|
|
133
|
+
run: quote('note')
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: 'code',
|
|
137
|
+
label: 'Code',
|
|
138
|
+
icon: SquareCode,
|
|
139
|
+
hint: '```',
|
|
140
|
+
keywords: 'snippet pre',
|
|
141
|
+
kind: 'block',
|
|
142
|
+
// Named, or a formula turned into code would stay one: the block's attributes carry over.
|
|
143
|
+
run: (editor) => focus(editor).setCodeBlock({ language: '' }).run()
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 'math',
|
|
147
|
+
label: 'Math',
|
|
148
|
+
icon: Sigma,
|
|
149
|
+
keywords: 'formula equation tex latex',
|
|
150
|
+
kind: 'block',
|
|
151
|
+
run: (editor) => focus(editor).setCodeBlock({ language: MATH }).run()
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'divider',
|
|
155
|
+
label: 'Divider',
|
|
156
|
+
icon: Minus,
|
|
157
|
+
hint: '---',
|
|
158
|
+
keywords: 'horizontal rule line separator hr',
|
|
159
|
+
kind: 'insert',
|
|
160
|
+
run: (editor) => focus(editor).setHorizontalRule().run()
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'image',
|
|
164
|
+
label: 'Image',
|
|
165
|
+
icon: Image,
|
|
166
|
+
keywords: 'picture photo upload',
|
|
167
|
+
kind: 'insert',
|
|
168
|
+
available: (context) => !!context.pickImages,
|
|
169
|
+
run: (_editor, context) => context.pickImages?.()
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'table',
|
|
173
|
+
label: 'Table',
|
|
174
|
+
icon: Table,
|
|
175
|
+
keywords: 'grid rows columns',
|
|
176
|
+
kind: 'insert',
|
|
177
|
+
run: (editor) => focus(editor).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: 'footnote',
|
|
181
|
+
label: 'Footnote',
|
|
182
|
+
icon: Superscript,
|
|
183
|
+
hint: '[^1]',
|
|
184
|
+
keywords: 'note reference source',
|
|
185
|
+
kind: 'insert',
|
|
186
|
+
run: insertFootnote
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: 'row',
|
|
190
|
+
label: 'Add row',
|
|
191
|
+
icon: Plus,
|
|
192
|
+
keywords: 'table below',
|
|
193
|
+
kind: 'table',
|
|
194
|
+
run: (editor) => focus(editor).addRowAfter().run()
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: 'column',
|
|
198
|
+
label: 'Add column',
|
|
199
|
+
icon: Plus,
|
|
200
|
+
keywords: 'table right',
|
|
201
|
+
kind: 'table',
|
|
202
|
+
run: (editor) => focus(editor).addColumnAfter().run()
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: 'deleteRow',
|
|
206
|
+
label: 'Delete row',
|
|
207
|
+
icon: Minus,
|
|
208
|
+
keywords: 'table remove',
|
|
209
|
+
kind: 'table',
|
|
210
|
+
run: (editor) => focus(editor).deleteRow().run()
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 'deleteColumn',
|
|
214
|
+
label: 'Delete column',
|
|
215
|
+
icon: Minus,
|
|
216
|
+
keywords: 'table remove',
|
|
217
|
+
kind: 'table',
|
|
218
|
+
run: (editor) => focus(editor).deleteColumn().run()
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: 'deleteTable',
|
|
222
|
+
label: 'Delete table',
|
|
223
|
+
icon: Trash2,
|
|
224
|
+
keywords: 'remove',
|
|
225
|
+
kind: 'table',
|
|
226
|
+
run: (editor) => focus(editor).deleteTable().run()
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
export const ARTICLE_MARKS = [
|
|
230
|
+
{ id: 'bold', label: 'Bold', icon: Bold, key: 'b', run: (e) => focus(e).toggleBold().run() },
|
|
231
|
+
{
|
|
232
|
+
id: 'italic',
|
|
233
|
+
label: 'Italic',
|
|
234
|
+
icon: Italic,
|
|
235
|
+
key: 'i',
|
|
236
|
+
run: (e) => focus(e).toggleItalic().run()
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: 'strike',
|
|
240
|
+
label: 'Strikethrough',
|
|
241
|
+
icon: Strikethrough,
|
|
242
|
+
key: 'S',
|
|
243
|
+
run: (e) => focus(e).toggleStrike().run()
|
|
244
|
+
},
|
|
245
|
+
{ id: 'code', label: 'Code', icon: Code, key: 'e', run: (e) => focus(e).toggleCode().run() },
|
|
246
|
+
{
|
|
247
|
+
id: HIGHLIGHT,
|
|
248
|
+
label: 'Highlight',
|
|
249
|
+
icon: Highlighter,
|
|
250
|
+
key: 'H',
|
|
251
|
+
run: (e) => focus(e).toggleMark(HIGHLIGHT).run()
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
/** The commands that apply where the cursor is: a table cell holds one line of text. */
|
|
255
|
+
export function availableCommands(editor, context) {
|
|
256
|
+
const table = inTable(editor.state);
|
|
257
|
+
return ARTICLE_COMMANDS.filter((command) => (command.kind === 'table') === table && (command.available?.(context, editor) ?? true));
|
|
258
|
+
}
|
|
259
|
+
/** Commands matching what was typed after the slash, best first. */
|
|
260
|
+
export function findCommands(query, editor, context) {
|
|
261
|
+
// "/ " is a slash in the text, not a search.
|
|
262
|
+
if (/^\s/.test(query))
|
|
263
|
+
return [];
|
|
264
|
+
const all = availableCommands(editor, context);
|
|
265
|
+
const wanted = query.trim().toLowerCase();
|
|
266
|
+
if (!wanted)
|
|
267
|
+
return all;
|
|
268
|
+
const rank = (command) => {
|
|
269
|
+
const label = command.label.toLowerCase();
|
|
270
|
+
if (label.startsWith(wanted) || command.id.toLowerCase() === wanted)
|
|
271
|
+
return 0;
|
|
272
|
+
if (label.split(' ').some((word) => word.startsWith(wanted)))
|
|
273
|
+
return 1;
|
|
274
|
+
if ((command.keywords ?? '').split(' ').some((word) => word.startsWith(wanted)))
|
|
275
|
+
return 2;
|
|
276
|
+
return label.includes(wanted) ? 3 : -1;
|
|
277
|
+
};
|
|
278
|
+
return all
|
|
279
|
+
.map((command) => ({ command, rank: rank(command) }))
|
|
280
|
+
.filter((entry) => entry.rank >= 0)
|
|
281
|
+
.sort((a, b) => a.rank - b.rank)
|
|
282
|
+
.map((entry) => entry.command);
|
|
283
|
+
}
|
|
284
|
+
/** Run a command. Turning a block into what it already is changes nothing. */
|
|
285
|
+
export function runCommand(editor, command, context) {
|
|
286
|
+
if (command.kind === 'block' && currentBlock(editor.state) === command.id)
|
|
287
|
+
return void editor.commands.focus();
|
|
288
|
+
command.run(editor, context);
|
|
289
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Node, type AnyExtension } from '@tiptap/core';
|
|
2
|
+
/** A task in a numbered or mixed list: the box is kept and shown, the list stays what it is. */
|
|
3
|
+
export declare const CheckableListItem: Node<import("@tiptap/extension-list").ListItemOptions, any>;
|
|
4
|
+
/**
|
|
5
|
+
* What article Markdown has beyond the basics: task lists, math, footnotes, highlights,
|
|
6
|
+
* callouts and code languages. The quote and code block here replace the starter kit's.
|
|
7
|
+
*/
|
|
8
|
+
export declare function articleExtensions(): AnyExtension[];
|