@atmo-dev/kit 0.18.0 → 0.19.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.
Files changed (114) hide show
  1. package/dist/articles/ArticleCard.svelte +97 -0
  2. package/dist/articles/ArticleCard.svelte.d.ts +20 -0
  3. package/dist/articles/ArticleCodeBlock.svelte +121 -0
  4. package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
  5. package/dist/articles/ArticleEditor.svelte +340 -0
  6. package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
  7. package/dist/articles/ArticleLinkEmbed.svelte +50 -0
  8. package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
  9. package/dist/articles/ArticleView.svelte +128 -0
  10. package/dist/articles/ArticleView.svelte.d.ts +46 -0
  11. package/dist/articles/PublicationIcon.svelte +37 -0
  12. package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
  13. package/dist/articles/article-link-embed.d.ts +36 -0
  14. package/dist/articles/article-link-embed.js +29 -0
  15. package/dist/articles/dates.d.ts +2 -0
  16. package/dist/articles/dates.js +12 -0
  17. package/dist/articles/images.d.ts +5 -0
  18. package/dist/articles/images.js +44 -0
  19. package/dist/articles/markdown.d.ts +15 -0
  20. package/dist/articles/markdown.js +52 -0
  21. package/dist/articles/paste.d.ts +11 -0
  22. package/dist/articles/paste.js +27 -0
  23. package/dist/articles/records.d.ts +166 -0
  24. package/dist/articles/records.js +423 -0
  25. package/dist/articles/styles.d.ts +4 -0
  26. package/dist/articles/styles.js +14 -0
  27. package/dist/articles-data.d.ts +8 -0
  28. package/dist/articles-data.js +8 -0
  29. package/dist/articles.d.ts +10 -0
  30. package/dist/articles.js +8 -0
  31. package/dist/components/ExternalEmbed.svelte +16 -2
  32. package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
  33. package/dist/components/IconMaker.svelte +119 -0
  34. package/dist/components/IconMaker.svelte.d.ts +9 -0
  35. package/dist/components/IconRail.svelte +9 -6
  36. package/dist/components/IconRail.svelte.d.ts +2 -0
  37. package/dist/components/LinkEmbed.svelte +24 -21
  38. package/dist/components/LinkEmbed.svelte.d.ts +3 -2
  39. package/dist/components/PaletteApply.svelte +62 -0
  40. package/dist/components/PaletteApply.svelte.d.ts +9 -0
  41. package/dist/components/PalettePicker.svelte +92 -0
  42. package/dist/components/PalettePicker.svelte.d.ts +13 -0
  43. package/dist/components/PostComments.svelte +129 -0
  44. package/dist/components/PostComments.svelte.d.ts +15 -0
  45. package/dist/components/RichText.svelte +199 -9
  46. package/dist/components/RichText.svelte.d.ts +17 -0
  47. package/dist/components/RichTextEditor.svelte +155 -13
  48. package/dist/components/RichTextEditor.svelte.d.ts +26 -3
  49. package/dist/components/composer/ComposerPost.svelte +20 -4
  50. package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
  51. package/dist/components/composer/PostComposer.svelte +29 -3
  52. package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
  53. package/dist/editor/EditorMenus.svelte +438 -0
  54. package/dist/editor/EditorMenus.svelte.d.ts +9 -0
  55. package/dist/editor/SlashOptions.svelte +45 -0
  56. package/dist/editor/SlashOptions.svelte.d.ts +12 -0
  57. package/dist/editor/article-commands.d.ts +44 -0
  58. package/dist/editor/article-commands.js +289 -0
  59. package/dist/editor/article-extensions.d.ts +8 -0
  60. package/dist/editor/article-extensions.js +315 -0
  61. package/dist/editor/article-menus.d.ts +2 -0
  62. package/dist/editor/article-menus.js +3 -0
  63. package/dist/editor/document.d.ts +5 -0
  64. package/dist/editor/document.js +163 -12
  65. package/dist/editor/image-node.d.ts +8 -0
  66. package/dist/editor/image-node.js +75 -0
  67. package/dist/editor/markdown-extensions.d.ts +1 -5
  68. package/dist/editor/markdown-extensions.js +37 -2
  69. package/dist/editor/slash-menu.svelte.d.ts +9 -0
  70. package/dist/editor/slash-menu.svelte.js +134 -0
  71. package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
  72. package/dist/embeds/PostLinkEmbed.svelte +12 -29
  73. package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
  74. package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
  75. package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
  76. package/dist/embeds/defaults.d.ts +4 -2
  77. package/dist/embeds/defaults.js +7 -3
  78. package/dist/embeds/load.d.ts +44 -0
  79. package/dist/embeds/load.js +139 -0
  80. package/dist/embeds/types.d.ts +18 -3
  81. package/dist/events/EventComments.svelte +4 -101
  82. package/dist/events/EventComments.svelte.d.ts +1 -1
  83. package/dist/events/EventView.svelte +5 -0
  84. package/dist/events/EventView.svelte.d.ts +3 -0
  85. package/dist/events/event-link-embed.d.ts +4 -1
  86. package/dist/events/event-link-embed.js +9 -1
  87. package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
  88. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
  89. package/dist/icon-maker/artwork.d.ts +11 -0
  90. package/dist/icon-maker/artwork.js +25 -0
  91. package/dist/icon-maker/index.d.ts +12 -0
  92. package/dist/icon-maker/index.js +73 -0
  93. package/dist/index.d.ts +10 -3
  94. package/dist/index.js +7 -1
  95. package/dist/palettes.d.ts +20 -0
  96. package/dist/palettes.js +37 -0
  97. package/dist/richtext/article-styles.d.ts +10 -0
  98. package/dist/richtext/article-styles.js +28 -0
  99. package/dist/richtext/document.d.ts +63 -1
  100. package/dist/richtext/document.js +54 -0
  101. package/dist/richtext/markdown.d.ts +19 -4
  102. package/dist/richtext/markdown.js +223 -18
  103. package/dist/richtext/serialize.d.ts +5 -1
  104. package/dist/richtext/serialize.js +163 -31
  105. package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
  106. package/dist/richtext/vendor/markdown-tree.js +2584 -26
  107. package/dist/richtext.d.ts +7 -5
  108. package/dist/richtext.js +1 -1
  109. package/dist/social/external-embeds.d.ts +5 -0
  110. package/dist/social/external-embeds.js +6 -1
  111. package/dist/social/posts.d.ts +2 -0
  112. package/dist/social/posts.js +43 -2
  113. package/dist/social/profile.js +2 -1
  114. package/package.json +28 -2
@@ -4,6 +4,7 @@
4
4
  import { Captions, X } from '@sketchyicons/svelte';
5
5
  import type {
6
6
  ComposerLimits,
7
+ ComposerLink,
7
8
  ComposerLinkPreview,
8
9
  ComposerPost as Post
9
10
  } from '../../social/composer.js';
@@ -31,6 +32,7 @@
31
32
  limits,
32
33
  searchActors,
33
34
  linkPreview,
35
+ fixedLink,
34
36
  onfocus,
35
37
  onremove
36
38
  }: {
@@ -49,6 +51,8 @@
49
51
  limits: ComposerLimits;
50
52
  searchActors?: ActorSearch;
51
53
  linkPreview?: ComposerLinkPreview;
54
+ /** A card given by the app. It replaces previews of links in the text. */
55
+ fixedLink?: ComposerLink;
52
56
  onfocus: () => void;
53
57
  onremove?: () => void;
54
58
  } = $props();
@@ -72,21 +76,33 @@
72
76
  let loadingLink = $state(false);
73
77
  let firstLink = $derived(post.facets.flatMap((f) => f.features).find((f) => f.uri)?.uri ?? '');
74
78
  $effect(() => {
79
+ if (fixedLink) {
80
+ const card = hasMedia || dismissed === fixedLink.uri ? undefined : fixedLink;
81
+ if (untrack(() => post.link?.uri) !== card?.uri) post.link = card && { ...card };
82
+ loadingLink = false;
83
+ return;
84
+ }
75
85
  const uri = firstLink;
76
86
  const preview = linkPreview;
77
- if (!preview || hasMedia || !uri || uri === dismissed) {
78
- if (post.link && (!preview || hasMedia || post.link.uri !== uri)) post.link = undefined;
87
+ if (!preview || hasMedia) {
88
+ if (post.link) post.link = undefined;
89
+ loadingLink = false;
90
+ return;
91
+ }
92
+ // The card outlives its link: deleting the URL, at once or a character at a time,
93
+ // leaves it attached. Only its own button, or another link, takes it away.
94
+ const shown = untrack(() => post.link?.uri);
95
+ if (!uri || uri === dismissed || uri === shown || shown?.startsWith(uri)) {
79
96
  loadingLink = false;
80
97
  return;
81
98
  }
82
- if (untrack(() => post.link?.uri) === uri) return;
83
99
  const controller = new AbortController();
84
100
  const timer = setTimeout(async () => {
85
101
  loadingLink = true;
86
102
  const card = await preview(uri, controller.signal).catch(() => undefined);
87
103
  if (controller.signal.aborted) return;
88
104
  loadingLink = false;
89
- post.link = card;
105
+ if (card) post.link = card;
90
106
  }, 500);
91
107
  return () => {
92
108
  clearTimeout(timer);
@@ -1,6 +1,6 @@
1
1
  import { type Snippet } from 'svelte';
2
2
  import type { Editor } from '@tiptap/core';
3
- import type { ComposerLimits, ComposerLinkPreview, ComposerPost as Post } from '../../social/composer.js';
3
+ import type { ComposerLimits, ComposerLink, ComposerLinkPreview, ComposerPost as Post } from '../../social/composer.js';
4
4
  import type { ActorSearch } from '../login/types.js';
5
5
  type $$ComponentProps = {
6
6
  post: Post;
@@ -21,6 +21,8 @@ type $$ComponentProps = {
21
21
  limits: ComposerLimits;
22
22
  searchActors?: ActorSearch;
23
23
  linkPreview?: ComposerLinkPreview;
24
+ /** A card given by the app. It replaces previews of links in the text. */
25
+ fixedLink?: ComposerLink;
24
26
  onfocus: () => void;
25
27
  onremove?: () => void;
26
28
  };
@@ -8,6 +8,7 @@
8
8
  ComposerGifSearch,
9
9
  ComposerLabels,
10
10
  ComposerLimits,
11
+ ComposerLink,
11
12
  ComposerLinkPreview,
12
13
  ComposerPost as Post,
13
14
  ComposerReplyRule
@@ -54,8 +55,19 @@
54
55
  gifCredit?: string;
55
56
  /** Enables link preview cards, e.g. `blueskyLinkPreview`. */
56
57
  linkPreview?: ComposerLinkPreview;
58
+ /**
59
+ * A card for the first post that needs no lookup, e.g. the page being shared. It stays,
60
+ * whatever links the text has, until the author removes it or attaches media, and can be
61
+ * posted without text.
62
+ */
63
+ link?: ComposerLink;
57
64
  /** Enables drafts. */
58
65
  drafts?: ComposerDrafts;
66
+ /**
67
+ * A line above the toolbar saying where this goes, for apps where posting is a side step:
68
+ * e.g. "This will be posted on Bluesky." Nothing is shown without it.
69
+ */
70
+ notice?: string;
59
71
  /** More toolbar buttons, after the built-in ones. */
60
72
  actions?: Snippet<[{ post: Post; insert: (text: string) => void; disabled: boolean }]>;
61
73
  class?: string;
@@ -118,6 +130,8 @@
118
130
  searchGifs,
119
131
  gifCredit,
120
132
  linkPreview,
133
+ link,
134
+ notice,
121
135
  drafts: draftStore,
122
136
  actions,
123
137
  class: className
@@ -128,7 +142,8 @@
128
142
  let reply = $derived(!!replyTo);
129
143
  let canDraft = $derived(!!draftStore && on('drafts') && !reply);
130
144
 
131
- let posts = $state<Post[]>([blankComposerPost(untrack(() => text))]);
145
+ const startingText = untrack(() => text);
146
+ let posts = $state<Post[]>([blankComposerPost(startingText)]);
132
147
  // Text editors by post id.
133
148
  let editors = $state.raw<Record<string, Editor | null>>({});
134
149
  let active = $state(0);
@@ -163,9 +178,17 @@
163
178
  let current = $derived(posts[Math.min(active, posts.length - 1)]);
164
179
  const lengthOf = (post: Post) => graphemeLength(post.text.trim());
165
180
  const hasMedia = (post: Post) => post.images.length > 0 || !!post.video || !!post.gif;
181
+ // A card can be posted on its own, as a quote can.
166
182
  const isEmpty = (post: Post, index: number) =>
167
- !lengthOf(post) && !hasMedia(post) && !(index === 0 && quote);
168
- let dirty = $derived(posts.some((post, index) => !isEmpty(post, index) || !!post.link));
183
+ !lengthOf(post) && !hasMedia(post) && !post.link && !(index === 0 && quote);
184
+ /** Still what the composer opened with: nothing of the author's would be lost. */
185
+ let untouched = $derived(
186
+ posts.length === 1 &&
187
+ !hasMedia(posts[0]) &&
188
+ posts[0].text.trim() === startingText.trim() &&
189
+ (!posts[0].link || posts[0].link.uri === link?.uri)
190
+ );
191
+ let dirty = $derived(!untouched && posts.some((post, index) => !isEmpty(post, index)));
169
192
  let missingAlt = $derived(
170
193
  requireAlt && posts.some((p) => p.images.some((image) => !image.alt.trim()))
171
194
  );
@@ -431,6 +454,7 @@
431
454
  {limits}
432
455
  {searchActors}
433
456
  linkPreview={on('linkPreviews') ? linkPreview : undefined}
457
+ fixedLink={index === 0 ? link : undefined}
434
458
  onfocus={() => (active = index)}
435
459
  onremove={posts.length > 1 ? () => removePost(index) : undefined}
436
460
  />
@@ -442,6 +466,8 @@
442
466
  {/if}
443
467
  </div>
444
468
 
469
+ {#if notice}<p class="shrink-0 px-4 pb-2 text-xs {muted}">{notice}</p>{/if}
470
+
445
471
  {#if on('interactions') || (on('contentWarnings') && contentWarnings.length && hasMedia(current))}
446
472
  <div class="flex shrink-0 flex-wrap items-center gap-2 px-4 pb-1.5">
447
473
  {#if on('interactions')}
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { ComposerContent, ComposerContentWarning, ComposerDrafts, ComposerFeatures, ComposerGifSearch, ComposerLabels, ComposerLimits, ComposerLinkPreview, ComposerPost as Post, ComposerReplyRule } from '../../social/composer.js';
2
+ import type { ComposerContent, ComposerContentWarning, ComposerDrafts, ComposerFeatures, ComposerGifSearch, ComposerLabels, ComposerLimits, ComposerLink, ComposerLinkPreview, ComposerPost as Post, ComposerReplyRule } from '../../social/composer.js';
3
3
  import type { ActorSearch } from '../login/types.js';
4
4
  export type PostComposerProps = {
5
5
  /**
@@ -53,8 +53,19 @@ export type PostComposerProps = {
53
53
  gifCredit?: string;
54
54
  /** Enables link preview cards, e.g. `blueskyLinkPreview`. */
55
55
  linkPreview?: ComposerLinkPreview;
56
+ /**
57
+ * A card for the first post that needs no lookup, e.g. the page being shared. It stays,
58
+ * whatever links the text has, until the author removes it or attaches media, and can be
59
+ * posted without text.
60
+ */
61
+ link?: ComposerLink;
56
62
  /** Enables drafts. */
57
63
  drafts?: ComposerDrafts;
64
+ /**
65
+ * A line above the toolbar saying where this goes, for apps where posting is a side step:
66
+ * e.g. "This will be posted on Bluesky." Nothing is shown without it.
67
+ */
68
+ notice?: string;
58
69
  /** More toolbar buttons, after the built-in ones. */
59
70
  actions?: Snippet<[{
60
71
  post: Post;
@@ -0,0 +1,438 @@
1
+ <script lang="ts">
2
+ import { tick } from 'svelte';
3
+ import { getMarkRange, isMacOS, isTextSelection, posToDOMRect, type Editor } from '@tiptap/core';
4
+ import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom';
5
+ import {
6
+ Check,
7
+ ChevronDown,
8
+ ExternalLink,
9
+ Image,
10
+ Link,
11
+ ListIndentDecrease,
12
+ ListIndentIncrease,
13
+ Pencil,
14
+ Redo2,
15
+ Undo2,
16
+ Unlink,
17
+ type IconNode
18
+ } from '@sketchyicons/svelte';
19
+ import Icon from '../components/Icon.svelte';
20
+ import { safeHttpUrl } from '../urls.js';
21
+ import {
22
+ ARTICLE_COMMANDS,
23
+ ARTICLE_MARKS,
24
+ availableCommands,
25
+ currentBlock,
26
+ inTable,
27
+ runCommand,
28
+ type ArticleCommand,
29
+ type ArticleCommandContext
30
+ } from './article-commands.js';
31
+
32
+ // Rendered inside a positioned element around the editor, which places the menus.
33
+ // What floats around the text of an article being written: formatting for a selection,
34
+ // a link's address, and on touch screens a toolbar above the keyboard.
35
+ let {
36
+ editor,
37
+ context
38
+ }: {
39
+ editor: Editor;
40
+ context: ArticleCommandContext;
41
+ } = $props();
42
+
43
+ const uid = $props.id();
44
+ const mod = isMacOS() ? '⌘' : 'Ctrl+';
45
+ const command = (id: string) => ARTICLE_COMMANDS.find((item) => item.id === id)!;
46
+ /** The blocks the toolbar has a button for; the rest are a `/` away. */
47
+ const quick = ['h1', 'h2', 'bullet', 'ordered', 'todo', 'quote'].map(command);
48
+
49
+ /** Bumped whenever the editor changes, so that what is read from it is read again. */
50
+ let version = $state(0);
51
+ let focused = $state(false);
52
+ /** While the mouse is held, a selection is still being made. */
53
+ let pressing = $state(false);
54
+ let coarse = $state(false);
55
+ let keyboard = $state(0);
56
+ let linking = $state(false);
57
+ let address = $state('');
58
+ let invalid = $state(false);
59
+ let turning = $state(false);
60
+ let floating = $state<HTMLDivElement>();
61
+ let field = $state<HTMLInputElement>();
62
+
63
+ let now = $derived.by(() => {
64
+ void version;
65
+ const { state } = editor;
66
+ const { selection } = state;
67
+ const link = state.schema.marks.link;
68
+ return {
69
+ from: selection.from,
70
+ to: selection.to,
71
+ empty: selection.empty,
72
+ text: isTextSelection(selection),
73
+ code: !!selection.$from.parent.type.spec.code,
74
+ editable: editor.isEditable,
75
+ table: inTable(state),
76
+ list: ['listItem', 'taskItem'].find((name) => editor.isActive(name)),
77
+ block: currentBlock(state),
78
+ marks: Object.fromEntries(ARTICLE_MARKS.map((mark) => [mark.id, editor.isActive(mark.id)])),
79
+ href: editor.isActive('link') ? String(editor.getAttributes('link').href ?? '') : '',
80
+ linked: selection.empty && link ? getMarkRange(selection.$from, link) : undefined,
81
+ undo: editor.can().undo(),
82
+ redo: editor.can().redo()
83
+ };
84
+ });
85
+
86
+ /** What the block can become here; read while the list is open. */
87
+ let blocks = $derived.by(() => {
88
+ void version;
89
+ return turning
90
+ ? availableCommands(editor, context).filter((item) => item.kind === 'block')
91
+ : [];
92
+ });
93
+
94
+ let mode = $derived(
95
+ !now.editable
96
+ ? undefined
97
+ : linking
98
+ ? 'link'
99
+ : coarse || !focused || pressing || now.code
100
+ ? undefined
101
+ : !now.empty && now.text
102
+ ? 'format'
103
+ : now.empty && now.href
104
+ ? 'preview'
105
+ : undefined
106
+ );
107
+
108
+ $effect(() => {
109
+ const changed = () => version++;
110
+ const focus = () => (focused = true);
111
+ const blur = ({ event }: { event: FocusEvent }) => {
112
+ if (event.relatedTarget instanceof Node && floating?.contains(event.relatedTarget)) return;
113
+ focused = false;
114
+ turning = false;
115
+ };
116
+ const dom = editor.view.dom;
117
+ const press = () => (pressing = true);
118
+ const release = () => (pressing = false);
119
+ const key = (event: KeyboardEvent) => {
120
+ if (event.key === 'Escape' && turning) {
121
+ event.preventDefault();
122
+ turning = false;
123
+ return;
124
+ }
125
+ if (event.key.toLowerCase() !== 'k' || !(event.metaKey || event.ctrlKey) || event.altKey)
126
+ return;
127
+ event.preventDefault();
128
+ void editLink();
129
+ };
130
+ editor.on('transaction', changed);
131
+ editor.on('focus', focus);
132
+ editor.on('blur', blur);
133
+ dom.addEventListener('mousedown', press);
134
+ dom.addEventListener('keydown', key);
135
+ document.addEventListener('mouseup', release);
136
+ focused = editor.isFocused;
137
+ return () => {
138
+ editor.off('transaction', changed);
139
+ editor.off('focus', focus);
140
+ editor.off('blur', blur);
141
+ dom.removeEventListener('mousedown', press);
142
+ dom.removeEventListener('keydown', key);
143
+ document.removeEventListener('mouseup', release);
144
+ };
145
+ });
146
+
147
+ $effect(() => {
148
+ const query = window.matchMedia('(pointer: coarse)');
149
+ const read = () => (coarse = query.matches);
150
+ read();
151
+ query.addEventListener('change', read);
152
+ return () => query.removeEventListener('change', read);
153
+ });
154
+
155
+ // The on-screen keyboard covers the bottom of the page without resizing it.
156
+ $effect(() => {
157
+ const viewport = window.visualViewport;
158
+ if (!coarse || !viewport) return;
159
+ const read = () =>
160
+ (keyboard = Math.max(0, window.innerHeight - viewport.height - viewport.offsetTop));
161
+ read();
162
+ viewport.addEventListener('resize', read);
163
+ viewport.addEventListener('scroll', read);
164
+ return () => {
165
+ viewport.removeEventListener('resize', read);
166
+ viewport.removeEventListener('scroll', read);
167
+ };
168
+ });
169
+
170
+ $effect(() => {
171
+ const element = floating;
172
+ if (!mode || !element) return;
173
+ const above = mode === 'format';
174
+ const [from, to] = now.linked ? [now.linked.from, now.linked.to] : [now.from, now.to];
175
+ const reference = {
176
+ getBoundingClientRect: () => posToDOMRect(editor.view, from, to),
177
+ contextElement: editor.view.dom
178
+ };
179
+ return autoUpdate(reference, element, () => {
180
+ void computePosition(reference, element, {
181
+ placement: above ? 'top-start' : 'bottom-start',
182
+ middleware: [offset(8), flip({ padding: 8 }), shift({ padding: 8 })]
183
+ }).then(({ x, y }) => {
184
+ element.style.left = `${x}px`;
185
+ element.style.top = `${y}px`;
186
+ element.style.visibility = '';
187
+ });
188
+ });
189
+ });
190
+ $effect(() => {
191
+ if (!mode) turning = false;
192
+ });
193
+
194
+ async function editLink() {
195
+ if (!editor.isEditable || !editor.schema.marks.link || now.code || !now.text) return;
196
+ address = now.href;
197
+ invalid = false;
198
+ turning = false;
199
+ linking = true;
200
+ await tick();
201
+ field?.focus();
202
+ field?.select();
203
+ }
204
+ function saveLink(event: SubmitEvent) {
205
+ event.preventDefault();
206
+ const typed = address.trim();
207
+ if (!typed) return removeLink();
208
+ const href = safeHttpUrl(/^[a-z][a-z0-9+.-]*:/i.test(typed) ? typed : `https://${typed}`);
209
+ if (!href) return void (invalid = true);
210
+ linking = false;
211
+ const chain = editor.chain().focus();
212
+ if (!now.empty) chain.setLink({ href }).setTextSelection(now.to).run();
213
+ else if (now.linked) chain.extendMarkRange('link').setLink({ href }).run();
214
+ else
215
+ chain
216
+ .insertContent({ type: 'text', text: typed, marks: [{ type: 'link', attrs: { href } }] })
217
+ .run();
218
+ }
219
+ function removeLink() {
220
+ linking = false;
221
+ editor.chain().focus().extendMarkRange('link').unsetLink().run();
222
+ }
223
+ function leftLink(event: FocusEvent) {
224
+ const next = event.relatedTarget;
225
+ if (next instanceof Node && floating?.contains(next)) return;
226
+ linking = false;
227
+ // Left for somewhere else on the page: the editor is no longer being written in.
228
+ if (!(next instanceof Node && editor.view.dom.contains(next))) focused = false;
229
+ }
230
+ function turnInto(item: ArticleCommand) {
231
+ turning = false;
232
+ runCommand(editor, item, context);
233
+ }
234
+ /** A second press undoes the first, as with bold. */
235
+ function toggleBlock(item: ArticleCommand) {
236
+ runCommand(editor, now.block === item.id ? command('text') : item, context);
237
+ }
238
+ const indent = (out: boolean) => {
239
+ if (!now.list) return;
240
+ const chain = editor.chain().focus();
241
+ (out ? chain.liftListItem(now.list) : chain.sinkListItem(now.list)).run();
242
+ };
243
+
244
+ const hold = (event: Event) => event.preventDefault();
245
+ const panel =
246
+ 'border border-base-300 bg-base-50 font-sans text-sm leading-normal text-base-950 dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-900 dark:text-base-50';
247
+ const tool =
248
+ 'inline-flex h-8 min-w-8 shrink-0 cursor-pointer items-center justify-center gap-1 rounded-md px-1.5 text-base-700 outline-none hover:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] focus-visible:outline-2 focus-visible:outline-accent-700 disabled:pointer-events-none disabled:opacity-40 aria-pressed:bg-accent-50 aria-pressed:text-accent-700 dark:text-base-300 dark:hover:bg-base-950 dark:focus-visible:outline-accent-300 dark:aria-pressed:bg-[color-mix(in_srgb,var(--accent-950)_65%,var(--base-950))] dark:aria-pressed:text-accent-300';
249
+ const rule = 'mx-1 h-5 w-px shrink-0 bg-base-300 dark:bg-base-800';
250
+ </script>
251
+
252
+ {#snippet button(
253
+ label: string,
254
+ icon: IconNode,
255
+ run: () => void,
256
+ pressed?: boolean,
257
+ disabled = false,
258
+ size = 16
259
+ )}
260
+ <button
261
+ type="button"
262
+ class={tool}
263
+ aria-label={label}
264
+ title={label}
265
+ aria-pressed={pressed}
266
+ {disabled}
267
+ onmousedown={hold}
268
+ onclick={run}><Icon img={icon} {size} /></button
269
+ >
270
+ {/snippet}
271
+
272
+ {#snippet marks(size: number)}
273
+ {#each ARTICLE_MARKS as mark (mark.id)}
274
+ {@const keys =
275
+ mark.key === mark.key.toLowerCase() ? mod : `${mod}${isMacOS() ? '⇧' : 'Shift+'}`}
276
+ {@render button(
277
+ `${mark.label} (${keys}${mark.key.toUpperCase()})`,
278
+ mark.icon,
279
+ () => mark.run(editor),
280
+ now.marks[mark.id],
281
+ false,
282
+ size
283
+ )}
284
+ {/each}
285
+ {@render button(`Link (${mod}K)`, Link, editLink, !!now.href, false, size)}
286
+ {/snippet}
287
+
288
+ {#if mode}
289
+ <div
290
+ bind:this={floating}
291
+ role={mode === 'format' ? 'toolbar' : 'group'}
292
+ aria-label={mode === 'format' ? 'Formatting' : 'Link'}
293
+ style:visibility="hidden"
294
+ class="absolute top-0 left-0 z-60 w-max max-w-[calc(100vw-1rem)] rounded-ui p-1 transition-opacity duration-100 motion-reduce:transition-none starting:opacity-0 {panel}"
295
+ onfocusout={leftLink}
296
+ >
297
+ {#if mode === 'link'}
298
+ <form class="flex items-center gap-1" onsubmit={saveLink}>
299
+ <input
300
+ bind:this={field}
301
+ bind:value={address}
302
+ type="text"
303
+ inputmode="url"
304
+ autocapitalize="off"
305
+ autocomplete="off"
306
+ spellcheck="false"
307
+ placeholder="Paste or type a link"
308
+ aria-label="Link address"
309
+ aria-invalid={invalid}
310
+ oninput={() => (invalid = false)}
311
+ onkeydown={(event) => {
312
+ if (event.key !== 'Escape') return;
313
+ event.preventDefault();
314
+ linking = false;
315
+ editor.commands.focus();
316
+ }}
317
+ class="h-8 w-64 max-w-[60vw] min-w-0 rounded-md border-0 bg-transparent px-2 text-sm text-base-950 placeholder:text-base-500 focus:ring-0 focus:outline-none aria-invalid:text-red-700 dark:text-base-50 dark:aria-invalid:text-red-400"
318
+ />
319
+ <button type="submit" class={tool} aria-label="Save link" title="Save link"
320
+ ><Icon img={Check} size={16} /></button
321
+ >
322
+ {#if now.href}{@render button('Remove link', Unlink, removeLink)}{/if}
323
+ </form>
324
+ {:else if mode === 'preview'}
325
+ <div class="flex items-center gap-1">
326
+ <a
327
+ href={safeHttpUrl(now.href)}
328
+ target="_blank"
329
+ rel="noopener noreferrer nofollow ugc"
330
+ onmousedown={hold}
331
+ class="flex h-8 max-w-64 min-w-0 items-center gap-1.5 rounded-md px-2 text-accent-700 hover:underline dark:text-accent-300"
332
+ ><span class="truncate">{now.href.replace(/^https?:\/\//, '')}</span><Icon
333
+ img={ExternalLink}
334
+ size={14}
335
+ class="shrink-0"
336
+ /></a
337
+ >
338
+ {@render button('Edit link', Pencil, editLink)}
339
+ {@render button('Remove link', Unlink, removeLink)}
340
+ </div>
341
+ {:else}
342
+ <div class="flex items-center">
343
+ {#if !now.table}
344
+ <button
345
+ type="button"
346
+ class="{tool} px-2 text-[.8125rem] font-medium"
347
+ aria-haspopup="listbox"
348
+ aria-expanded={turning}
349
+ aria-controls={turning ? `${uid}-blocks` : undefined}
350
+ aria-label="Turn into"
351
+ title="Turn into"
352
+ onmousedown={hold}
353
+ onclick={() => (turning = !turning)}
354
+ >{command(now.block).label}<Icon img={ChevronDown} size={14} /></button
355
+ >
356
+ <span class={rule}></span>
357
+ {/if}
358
+ {@render marks(16)}
359
+ </div>
360
+ {#if turning}
361
+ <div
362
+ id="{uid}-blocks"
363
+ role="listbox"
364
+ aria-label="Turn into"
365
+ class="absolute top-full left-0 mt-1.5 max-h-72 w-52 overflow-y-auto rounded-ui p-1.5 {panel}"
366
+ >
367
+ {#each blocks as item (item.id)}
368
+ <button
369
+ type="button"
370
+ role="option"
371
+ aria-selected={now.block === item.id}
372
+ onmousedown={hold}
373
+ onclick={() => turnInto(item)}
374
+ class="flex w-full cursor-pointer items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[.8125rem] font-medium text-base-800 outline-none hover:bg-accent-50 hover:text-accent-700 aria-selected:text-accent-700 dark:text-base-200 dark:hover:bg-[color-mix(in_srgb,var(--accent-950)_65%,var(--base-950))] dark:hover:text-accent-300 dark:aria-selected:text-accent-300"
375
+ >
376
+ <Icon img={item.icon} size={18} class="shrink-0" />
377
+ <span class="flex-1 truncate">{item.label}</span>
378
+ {#if now.block === item.id}<Icon img={Check} size={14} />{/if}
379
+ </button>
380
+ {/each}
381
+ </div>
382
+ {/if}
383
+ {/if}
384
+ </div>
385
+ {/if}
386
+
387
+ {#if coarse && focused && now.editable && !linking}
388
+ <!-- Room for the last line above the toolbar. -->
389
+ <div class="h-14" aria-hidden="true"></div>
390
+ <div
391
+ role="toolbar"
392
+ aria-label="Formatting"
393
+ style:bottom="{keyboard}px"
394
+ class="fixed inset-x-0 z-60 flex [scrollbar-width:none] items-center gap-0.5 overflow-x-auto overscroll-contain border-x-0 border-b-0 px-2 py-1.5 {panel}"
395
+ >
396
+ {#if !now.code}
397
+ {@render marks(18)}
398
+ <span class={rule}></span>
399
+ {/if}
400
+ {#if now.list}
401
+ {@render button('Outdent', ListIndentDecrease, () => indent(true), undefined, false, 18)}
402
+ {@render button('Indent', ListIndentIncrease, () => indent(false), undefined, false, 18)}
403
+ <span class={rule}></span>
404
+ {/if}
405
+ {#if !now.table}
406
+ {#each quick as item (item.id)}
407
+ {@render button(
408
+ item.label,
409
+ item.icon,
410
+ () => toggleBlock(item),
411
+ now.block === item.id,
412
+ false,
413
+ 18
414
+ )}
415
+ {/each}
416
+ {#if context.pickImages}
417
+ {@render button('Image', Image, () => context.pickImages?.(), undefined, false, 18)}
418
+ {/if}
419
+ <span class={rule}></span>
420
+ {/if}
421
+ {@render button(
422
+ 'Undo',
423
+ Undo2,
424
+ () => editor.chain().focus().undo().run(),
425
+ undefined,
426
+ !now.undo,
427
+ 18
428
+ )}
429
+ {@render button(
430
+ 'Redo',
431
+ Redo2,
432
+ () => editor.chain().focus().redo().run(),
433
+ undefined,
434
+ !now.redo,
435
+ 18
436
+ )}
437
+ </div>
438
+ {/if}
@@ -0,0 +1,9 @@
1
+ import { type Editor } from '@tiptap/core';
2
+ import { type ArticleCommandContext } from './article-commands.js';
3
+ type $$ComponentProps = {
4
+ editor: Editor;
5
+ context: ArticleCommandContext;
6
+ };
7
+ declare const EditorMenus: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type EditorMenus = ReturnType<typeof EditorMenus>;
9
+ export default EditorMenus;
@@ -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;