@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,315 @@
|
|
|
1
|
+
import { InputRule, Mark, markInputRule, Node } from '@tiptap/core';
|
|
2
|
+
import Blockquote from '@tiptap/extension-blockquote';
|
|
3
|
+
import CodeBlock from '@tiptap/extension-code-block';
|
|
4
|
+
import { ListItem, TaskItem, TaskList } from '@tiptap/extension-list';
|
|
5
|
+
import { CALLOUT_ICONS, CALLOUT_LABELS, calloutClass, calloutLabelClass, highlightClass } from '../richtext/article-styles.js';
|
|
6
|
+
import { CALLOUTS, isCallout } from '../richtext/document.js';
|
|
7
|
+
import { FOOTNOTE_ID } from '../richtext/markdown.js';
|
|
8
|
+
import { FOOTNOTE_DEFINITION, FOOTNOTE_REFERENCE, HIGHLIGHT, MATH } from './document.js';
|
|
9
|
+
/** `==marked==` text. Typing it makes one. */
|
|
10
|
+
const HighlightMark = Mark.create({
|
|
11
|
+
name: HIGHLIGHT,
|
|
12
|
+
parseHTML: () => [{ tag: 'mark' }],
|
|
13
|
+
renderHTML: () => ['mark', { class: highlightClass }, 0],
|
|
14
|
+
addInputRules() {
|
|
15
|
+
return [markInputRule({ find: /(?:^|\s)(==([^=\s](?:[^=]*[^=\s])?)==)$/, type: this.type })];
|
|
16
|
+
},
|
|
17
|
+
addKeyboardShortcuts() {
|
|
18
|
+
return { 'Mod-Shift-h': () => this.editor.commands.toggleMark(this.name) };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function iconElement(icon, size) {
|
|
22
|
+
const namespace = 'http://www.w3.org/2000/svg';
|
|
23
|
+
const svg = document.createElementNS(namespace, 'svg');
|
|
24
|
+
const attributes = {
|
|
25
|
+
viewBox: '0 0 24 24',
|
|
26
|
+
width: size,
|
|
27
|
+
height: size,
|
|
28
|
+
fill: 'none',
|
|
29
|
+
stroke: 'currentColor',
|
|
30
|
+
'stroke-width': 1.75,
|
|
31
|
+
'stroke-linecap': 'round',
|
|
32
|
+
'stroke-linejoin': 'round',
|
|
33
|
+
'aria-hidden': 'true'
|
|
34
|
+
};
|
|
35
|
+
for (const [name, value] of Object.entries(attributes))
|
|
36
|
+
svg.setAttribute(name, String(value));
|
|
37
|
+
for (const [, drawn] of icon) {
|
|
38
|
+
const path = document.createElementNS(namespace, 'path');
|
|
39
|
+
path.setAttribute('d', String(drawn.d));
|
|
40
|
+
path.setAttribute('fill', String(drawn.fill ?? 'none'));
|
|
41
|
+
svg.append(path);
|
|
42
|
+
}
|
|
43
|
+
return svg;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A quote, or with `callout` one of GitHub's five callouts, written `> [!NOTE]`. Typing
|
|
47
|
+
* `[!note] ` at the start of a quote makes one; its label changes the kind.
|
|
48
|
+
*/
|
|
49
|
+
const CalloutQuote = Blockquote.extend({
|
|
50
|
+
addAttributes() {
|
|
51
|
+
return {
|
|
52
|
+
callout: {
|
|
53
|
+
default: null,
|
|
54
|
+
parseHTML: (element) => {
|
|
55
|
+
const kind = element.getAttribute('data-callout');
|
|
56
|
+
return isCallout(kind) ? kind : null;
|
|
57
|
+
},
|
|
58
|
+
renderHTML: (attributes) => isCallout(attributes.callout) ? { 'data-callout': attributes.callout } : {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
addInputRules() {
|
|
63
|
+
const type = this.type;
|
|
64
|
+
return [
|
|
65
|
+
...(this.parent?.() ?? []),
|
|
66
|
+
new InputRule({
|
|
67
|
+
find: /^\[!(note|tip|important|warning|caution)\]\s$/i,
|
|
68
|
+
handler: ({ state, range, match }) => {
|
|
69
|
+
const { $from } = state.selection;
|
|
70
|
+
const quote = $from.depth > 1 ? $from.node($from.depth - 1) : undefined;
|
|
71
|
+
if (quote?.type !== type || $from.index($from.depth - 1) !== 0)
|
|
72
|
+
return null;
|
|
73
|
+
state.tr
|
|
74
|
+
.delete(range.from, range.to)
|
|
75
|
+
.setNodeMarkup($from.before($from.depth - 1), undefined, {
|
|
76
|
+
...quote.attrs,
|
|
77
|
+
callout: match[1].toLowerCase()
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
];
|
|
82
|
+
},
|
|
83
|
+
addNodeView() {
|
|
84
|
+
return ({ node, editor, getPos }) => {
|
|
85
|
+
const kind = node.attrs.callout;
|
|
86
|
+
if (!isCallout(kind)) {
|
|
87
|
+
const dom = document.createElement('blockquote');
|
|
88
|
+
return {
|
|
89
|
+
dom,
|
|
90
|
+
contentDOM: dom,
|
|
91
|
+
update: (next) => next.type === node.type && !isCallout(next.attrs.callout)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const dom = document.createElement('div');
|
|
95
|
+
dom.dataset.callout = kind;
|
|
96
|
+
dom.className = calloutClass(kind);
|
|
97
|
+
const label = document.createElement('label');
|
|
98
|
+
label.contentEditable = 'false';
|
|
99
|
+
label.className = `${calloutLabelClass(kind)} w-fit`;
|
|
100
|
+
const select = document.createElement('select');
|
|
101
|
+
select.setAttribute('aria-label', 'Callout type');
|
|
102
|
+
select.className =
|
|
103
|
+
'cursor-pointer appearance-none field-sizing-content rounded-sm border-0 bg-transparent bg-none p-0 font-semibold text-inherit focus:ring-0';
|
|
104
|
+
for (const [value, text] of [
|
|
105
|
+
...CALLOUTS.map((item) => [item, CALLOUT_LABELS[item]]),
|
|
106
|
+
['', 'Quote']
|
|
107
|
+
]) {
|
|
108
|
+
const option = document.createElement('option');
|
|
109
|
+
option.value = value;
|
|
110
|
+
option.textContent = text;
|
|
111
|
+
select.append(option);
|
|
112
|
+
}
|
|
113
|
+
select.value = kind;
|
|
114
|
+
select.disabled = !editor.isEditable;
|
|
115
|
+
select.addEventListener('change', () => {
|
|
116
|
+
const pos = getPos();
|
|
117
|
+
if (typeof pos !== 'number' || !editor.isEditable)
|
|
118
|
+
return;
|
|
119
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, {
|
|
120
|
+
...node.attrs,
|
|
121
|
+
callout: select.value || null
|
|
122
|
+
}));
|
|
123
|
+
editor.view.focus();
|
|
124
|
+
});
|
|
125
|
+
label.append(iconElement(CALLOUT_ICONS[kind], 16), select);
|
|
126
|
+
const content = document.createElement('div');
|
|
127
|
+
content.className = 'space-y-3';
|
|
128
|
+
dom.append(label, content);
|
|
129
|
+
return {
|
|
130
|
+
dom,
|
|
131
|
+
contentDOM: content,
|
|
132
|
+
update: (next) => next.type === node.type && next.attrs.callout === kind,
|
|
133
|
+
stopEvent: (event) => event.target instanceof Element && label.contains(event.target),
|
|
134
|
+
ignoreMutation: (mutation) => mutation.type !== 'selection' && !content.contains(mutation.target)
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
/** A code block with its language written in its corner. "math" is a displayed formula. */
|
|
140
|
+
const LanguageCodeBlock = CodeBlock.extend({
|
|
141
|
+
addNodeView() {
|
|
142
|
+
return ({ node, editor, getPos }) => {
|
|
143
|
+
let current = node;
|
|
144
|
+
const dom = document.createElement('div');
|
|
145
|
+
dom.className = 'relative';
|
|
146
|
+
const pre = document.createElement('pre');
|
|
147
|
+
pre.className = 'pt-9!';
|
|
148
|
+
const code = document.createElement('code');
|
|
149
|
+
pre.append(code);
|
|
150
|
+
const input = document.createElement('input');
|
|
151
|
+
input.type = 'text';
|
|
152
|
+
input.placeholder = 'Language';
|
|
153
|
+
input.setAttribute('aria-label', 'Language');
|
|
154
|
+
input.spellcheck = false;
|
|
155
|
+
input.autocapitalize = 'off';
|
|
156
|
+
input.className =
|
|
157
|
+
'absolute top-2.5 left-3 w-40 max-w-[calc(100%-1.5rem)] border-0 bg-transparent p-0 font-sans text-xs text-base-600 placeholder:text-base-500 focus:ring-0 focus:outline-none dark:text-base-400';
|
|
158
|
+
dom.append(pre, input);
|
|
159
|
+
const show = () => {
|
|
160
|
+
const language = typeof current.attrs.language === 'string' ? current.attrs.language : '';
|
|
161
|
+
code.className = language ? `${this.options.languageClassPrefix ?? ''}${language}` : '';
|
|
162
|
+
if (document.activeElement !== input)
|
|
163
|
+
input.value = language;
|
|
164
|
+
input.readOnly = !editor.isEditable;
|
|
165
|
+
};
|
|
166
|
+
show();
|
|
167
|
+
input.addEventListener('input', () => {
|
|
168
|
+
const pos = getPos();
|
|
169
|
+
if (typeof pos !== 'number' || !editor.isEditable)
|
|
170
|
+
return;
|
|
171
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, {
|
|
172
|
+
...current.attrs,
|
|
173
|
+
language: input.value.replace(/[`\s]/g, '') || null
|
|
174
|
+
}));
|
|
175
|
+
});
|
|
176
|
+
input.addEventListener('keydown', (event) => {
|
|
177
|
+
if (!['Enter', 'Escape', 'ArrowDown'].includes(event.key))
|
|
178
|
+
return;
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
const pos = getPos();
|
|
181
|
+
if (typeof pos === 'number')
|
|
182
|
+
editor
|
|
183
|
+
.chain()
|
|
184
|
+
.focus()
|
|
185
|
+
.setTextSelection(pos + 1)
|
|
186
|
+
.run();
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
dom,
|
|
190
|
+
contentDOM: code,
|
|
191
|
+
update: (next) => {
|
|
192
|
+
if (next.type !== current.type)
|
|
193
|
+
return false;
|
|
194
|
+
current = next;
|
|
195
|
+
show();
|
|
196
|
+
return true;
|
|
197
|
+
},
|
|
198
|
+
stopEvent: (event) => event.target === input,
|
|
199
|
+
ignoreMutation: (mutation) => mutation.type !== 'selection' && !code.contains(mutation.target)
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
/** TeX source in the line, written to Markdown between dollars. Typing `$x^2$` makes one. */
|
|
205
|
+
const MathMark = Mark.create({
|
|
206
|
+
name: MATH,
|
|
207
|
+
code: true,
|
|
208
|
+
excludes: '_',
|
|
209
|
+
inclusive: false,
|
|
210
|
+
parseHTML: () => [{ tag: 'span[data-math]' }],
|
|
211
|
+
renderHTML: () => ['span', { 'data-math': '' }, 0],
|
|
212
|
+
addInputRules() {
|
|
213
|
+
return [
|
|
214
|
+
// The dollars hug the formula, as when reading: "$5 and $" starts nothing.
|
|
215
|
+
markInputRule({ find: /(?:^|\s)(\$([^$\s](?:[^$]*[^$\s])?)\$)$/, type: this.type })
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
/** `[^id]` in the text. Typing it makes one. */
|
|
220
|
+
const FootnoteReference = Node.create({
|
|
221
|
+
name: FOOTNOTE_REFERENCE,
|
|
222
|
+
group: 'inline',
|
|
223
|
+
inline: true,
|
|
224
|
+
atom: true,
|
|
225
|
+
selectable: true,
|
|
226
|
+
addAttributes: () => ({ id: { default: '' } }),
|
|
227
|
+
parseHTML: () => [
|
|
228
|
+
{
|
|
229
|
+
tag: 'sup[data-footnote-ref]',
|
|
230
|
+
getAttrs: (element) => ({ id: element.getAttribute('data-footnote-ref') ?? '' })
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
renderHTML: ({ node }) => ['sup', { 'data-footnote-ref': node.attrs.id }, `[${node.attrs.id}]`],
|
|
234
|
+
renderText: ({ node }) => `[^${node.attrs.id}]`,
|
|
235
|
+
addInputRules() {
|
|
236
|
+
const type = this.type;
|
|
237
|
+
return [
|
|
238
|
+
new InputRule({
|
|
239
|
+
find: /\[\^([^\s[\]^]{1,100})\]$/,
|
|
240
|
+
handler: ({ state, range, match }) => {
|
|
241
|
+
state.tr.replaceWith(range.from, range.to, type.create({ id: match[1] }));
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
/** The note a reference points to. Typing `: ` after a reference at the start of a line makes one. */
|
|
248
|
+
const FootnoteDefinition = Node.create({
|
|
249
|
+
name: FOOTNOTE_DEFINITION,
|
|
250
|
+
group: 'block',
|
|
251
|
+
content: 'block+',
|
|
252
|
+
defining: true,
|
|
253
|
+
addAttributes: () => ({ id: { default: '' } }),
|
|
254
|
+
parseHTML: () => [
|
|
255
|
+
{
|
|
256
|
+
tag: 'div[data-footnote]',
|
|
257
|
+
getAttrs: (element) => ({ id: element.getAttribute('data-footnote') ?? '' })
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
renderHTML: ({ node }) => ['div', { 'data-footnote': node.attrs.id }, 0],
|
|
261
|
+
addInputRules() {
|
|
262
|
+
const type = this.type;
|
|
263
|
+
return [
|
|
264
|
+
new InputRule({
|
|
265
|
+
find: /: $/,
|
|
266
|
+
handler: ({ state }) => {
|
|
267
|
+
const { $from, empty } = state.selection;
|
|
268
|
+
const paragraph = $from.parent;
|
|
269
|
+
const reference = paragraph.firstChild;
|
|
270
|
+
// Exactly a reference, then the colon and space just typed.
|
|
271
|
+
if (!empty ||
|
|
272
|
+
$from.depth !== 1 ||
|
|
273
|
+
paragraph.type.name !== 'paragraph' ||
|
|
274
|
+
paragraph.childCount !== 2 ||
|
|
275
|
+
reference?.type.name !== FOOTNOTE_REFERENCE ||
|
|
276
|
+
!/^: ?$/.test(paragraph.lastChild?.text ?? '') ||
|
|
277
|
+
!FOOTNOTE_ID.test(reference.attrs.id))
|
|
278
|
+
return null;
|
|
279
|
+
const from = $from.before();
|
|
280
|
+
state.tr.replaceWith(from, $from.after(), type.create({ id: reference.attrs.id }, state.schema.nodes.paragraph.create()));
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
/** A task in a numbered or mixed list: the box is kept and shown, the list stays what it is. */
|
|
287
|
+
export const CheckableListItem = ListItem.extend({
|
|
288
|
+
addAttributes() {
|
|
289
|
+
return {
|
|
290
|
+
...this.parent?.(),
|
|
291
|
+
checked: {
|
|
292
|
+
default: null,
|
|
293
|
+
parseHTML: (element) => element.hasAttribute('data-task') ? element.getAttribute('data-task') === 'true' : null,
|
|
294
|
+
renderHTML: (attributes) => typeof attributes.checked === 'boolean' ? { 'data-task': String(attributes.checked) } : {}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
/**
|
|
300
|
+
* What article Markdown has beyond the basics: task lists, math, footnotes, highlights,
|
|
301
|
+
* callouts and code languages. The quote and code block here replace the starter kit's.
|
|
302
|
+
*/
|
|
303
|
+
export function articleExtensions() {
|
|
304
|
+
return [
|
|
305
|
+
HighlightMark,
|
|
306
|
+
CalloutQuote,
|
|
307
|
+
LanguageCodeBlock,
|
|
308
|
+
CheckableListItem,
|
|
309
|
+
TaskList,
|
|
310
|
+
TaskItem.configure({ nested: true }),
|
|
311
|
+
MathMark,
|
|
312
|
+
FootnoteReference,
|
|
313
|
+
FootnoteDefinition
|
|
314
|
+
];
|
|
315
|
+
}
|
|
@@ -2,7 +2,12 @@ import type { JSONContent } from '@tiptap/core';
|
|
|
2
2
|
import { type RichTextDocument } from '../richtext/document.js';
|
|
3
3
|
import type { Facet } from '../social/richtext.js';
|
|
4
4
|
export declare const LINK_EMBED = "linkEmbed";
|
|
5
|
+
export declare const IMAGE = "image";
|
|
6
|
+
export declare const MATH = "math";
|
|
7
|
+
export declare const FOOTNOTE_REFERENCE = "footnoteReference";
|
|
8
|
+
export declare const FOOTNOTE_DEFINITION = "footnoteDefinition";
|
|
5
9
|
type EmbedTest = ((url: string) => boolean) | undefined;
|
|
10
|
+
export declare const HIGHLIGHT = "highlight";
|
|
6
11
|
/** A URL alone, e.g. the whole text of a line; undefined for anything else. */
|
|
7
12
|
export declare function bareUrl(text: string): string | undefined;
|
|
8
13
|
/** A parsed document as editor content. Links that would be shown as embeds become embed blocks. */
|
package/dist/editor/document.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import { detectTokens } from '../richtext/detect.js';
|
|
2
|
-
import { paragraphParts, safeWebUrl } from '../richtext/document.js';
|
|
2
|
+
import { isCallout, paragraphParts, safeWebUrl } from '../richtext/document.js';
|
|
3
3
|
export const LINK_EMBED = 'linkEmbed';
|
|
4
|
+
export const IMAGE = 'image';
|
|
5
|
+
export const MATH = 'math';
|
|
6
|
+
export const FOOTNOTE_REFERENCE = 'footnoteReference';
|
|
7
|
+
export const FOOTNOTE_DEFINITION = 'footnoteDefinition';
|
|
4
8
|
const MAX_DEPTH = 32;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
9
|
+
export const HIGHLIGHT = 'highlight';
|
|
10
|
+
const MARKS = {
|
|
11
|
+
strong: 'bold',
|
|
12
|
+
emphasis: 'italic',
|
|
13
|
+
delete: 'strike',
|
|
14
|
+
highlight: HIGHLIGHT
|
|
15
|
+
};
|
|
16
|
+
const STYLES = {
|
|
17
|
+
bold: 'strong',
|
|
18
|
+
italic: 'emphasis',
|
|
19
|
+
strike: 'delete',
|
|
20
|
+
highlight: 'highlight'
|
|
21
|
+
};
|
|
7
22
|
function labelOf(nodes, depth = 0) {
|
|
8
23
|
if (depth > MAX_DEPTH)
|
|
9
24
|
return '';
|
|
10
25
|
return nodes
|
|
11
|
-
.map((node) => node.type === 'text' || node.type === 'code'
|
|
26
|
+
.map((node) => node.type === 'text' || node.type === 'code' || node.type === 'math'
|
|
12
27
|
? node.value
|
|
13
28
|
: node.type === 'break'
|
|
14
29
|
? '\n'
|
|
15
30
|
: node.type === 'mention' || node.type === 'tag'
|
|
16
31
|
? node.text
|
|
17
|
-
:
|
|
32
|
+
: node.type === 'footnoteReference'
|
|
33
|
+
? ''
|
|
34
|
+
: labelOf(node.children, depth + 1))
|
|
18
35
|
.join('');
|
|
19
36
|
}
|
|
20
37
|
/** A URL alone, e.g. the whole text of a line; undefined for anything else. */
|
|
@@ -42,6 +59,12 @@ function inlineContent(nodes, marks, depth = 0) {
|
|
|
42
59
|
return node.value
|
|
43
60
|
? [{ type: 'text', text: node.value.replace(/\n/g, ' '), marks: [{ type: 'code' }] }]
|
|
44
61
|
: [];
|
|
62
|
+
case 'math':
|
|
63
|
+
return node.value
|
|
64
|
+
? [{ type: 'text', text: node.value.replace(/\n/g, ' '), marks: [{ type: MATH }] }]
|
|
65
|
+
: [];
|
|
66
|
+
case 'footnoteReference':
|
|
67
|
+
return [{ type: FOOTNOTE_REFERENCE, attrs: { id: node.id } }];
|
|
45
68
|
case 'mention':
|
|
46
69
|
return node.actor.startsWith('did:')
|
|
47
70
|
? [{ type: 'mention', attrs: { id: node.actor, label: node.text.replace(/^[@@]/, '') } }]
|
|
@@ -60,6 +83,7 @@ function inlineContent(nodes, marks, depth = 0) {
|
|
|
60
83
|
case 'strong':
|
|
61
84
|
case 'emphasis':
|
|
62
85
|
case 'delete':
|
|
86
|
+
case 'highlight':
|
|
63
87
|
return inlineContent(node.children, marks.some((mark) => mark.type === MARKS[node.type])
|
|
64
88
|
? marks
|
|
65
89
|
: [...marks, { type: MARKS[node.type] }], depth + 1);
|
|
@@ -92,24 +116,58 @@ function blockContent(blocks, isEmbed, depth = 0) {
|
|
|
92
116
|
return [
|
|
93
117
|
{
|
|
94
118
|
type: 'blockquote',
|
|
119
|
+
...(isCallout(block.callout) ? { attrs: { callout: block.callout } } : {}),
|
|
120
|
+
content: atLeastOne(blockContent(block.children, isEmbed, depth + 1))
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
case 'math':
|
|
124
|
+
// Edited as a code block in the language "math".
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
type: 'codeBlock',
|
|
128
|
+
attrs: { language: MATH },
|
|
129
|
+
...(block.value ? { content: [{ type: 'text', text: block.value }] } : {})
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
case 'footnoteDefinition':
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
type: FOOTNOTE_DEFINITION,
|
|
136
|
+
attrs: { id: block.id },
|
|
95
137
|
content: atLeastOne(blockContent(block.children, isEmbed, depth + 1))
|
|
96
138
|
}
|
|
97
139
|
];
|
|
98
|
-
case 'list':
|
|
140
|
+
case 'list': {
|
|
141
|
+
const checked = block.checked ?? [];
|
|
142
|
+
const isTask = (index) => typeof checked[index] === 'boolean';
|
|
143
|
+
// A task list is a bulleted one whose items are all tasks.
|
|
144
|
+
if (!block.ordered && block.items.length && block.items.every((_, index) => isTask(index)))
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
type: 'taskList',
|
|
148
|
+
content: block.items.map((item, index) => ({
|
|
149
|
+
type: 'taskItem',
|
|
150
|
+
attrs: { checked: checked[index] === true },
|
|
151
|
+
content: startsWithParagraph(blockContent(item, isEmbed, depth + 1))
|
|
152
|
+
}))
|
|
153
|
+
}
|
|
154
|
+
];
|
|
99
155
|
return [
|
|
100
156
|
{
|
|
101
157
|
type: block.ordered ? 'orderedList' : 'bulletList',
|
|
102
158
|
...(block.ordered ? { attrs: { start: block.start ?? 1 } } : {}),
|
|
103
|
-
content: block.items.map((item) => {
|
|
104
|
-
const content = blockContent(item, isEmbed, depth + 1);
|
|
105
|
-
// A
|
|
159
|
+
content: block.items.map((item, index) => {
|
|
160
|
+
const content = startsWithParagraph(blockContent(item, isEmbed, depth + 1));
|
|
161
|
+
// A task among other items, or in a numbered list, keeps its box on the item.
|
|
106
162
|
return {
|
|
107
163
|
type: 'listItem',
|
|
108
|
-
|
|
164
|
+
...(isTask(index) ? { attrs: { checked: checked[index] } } : {}),
|
|
165
|
+
content
|
|
109
166
|
};
|
|
110
167
|
})
|
|
111
168
|
}
|
|
112
169
|
];
|
|
170
|
+
}
|
|
113
171
|
case 'codeBlock':
|
|
114
172
|
return [
|
|
115
173
|
{
|
|
@@ -120,11 +178,41 @@ function blockContent(blocks, isEmbed, depth = 0) {
|
|
|
120
178
|
];
|
|
121
179
|
case 'thematicBreak':
|
|
122
180
|
return [{ type: 'horizontalRule' }];
|
|
181
|
+
case 'image':
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
type: IMAGE,
|
|
185
|
+
attrs: { url: block.url, alt: block.alt ?? '', title: block.title ?? '' }
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
case 'table':
|
|
189
|
+
return [
|
|
190
|
+
{
|
|
191
|
+
type: 'table',
|
|
192
|
+
content: block.rows.map((row, rowIndex) => ({
|
|
193
|
+
type: 'tableRow',
|
|
194
|
+
content: row.map((cell, index) => ({
|
|
195
|
+
type: rowIndex ? 'tableCell' : 'tableHeader',
|
|
196
|
+
attrs: { align: block.align[index] ?? null },
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: 'paragraph',
|
|
200
|
+
content: inlineContent(cell, []).map((node) => node.type === 'hardBreak' ? { type: 'text', text: ' ' } : node)
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}))
|
|
204
|
+
}))
|
|
205
|
+
}
|
|
206
|
+
];
|
|
123
207
|
default:
|
|
124
208
|
return [];
|
|
125
209
|
}
|
|
126
210
|
});
|
|
127
211
|
}
|
|
212
|
+
/** A list item starts with a paragraph. */
|
|
213
|
+
function startsWithParagraph(content) {
|
|
214
|
+
return content[0]?.type === 'paragraph' ? content : [{ type: 'paragraph' }, ...content];
|
|
215
|
+
}
|
|
128
216
|
function atLeastOne(content) {
|
|
129
217
|
return content.length ? content : [{ type: 'paragraph' }];
|
|
130
218
|
}
|
|
@@ -162,9 +250,15 @@ function inlineNodes(content) {
|
|
|
162
250
|
const actor = String(node.attrs?.id ?? '');
|
|
163
251
|
return [{ type: 'mention', actor, text: `@${node.attrs?.label ?? actor}` }];
|
|
164
252
|
}
|
|
253
|
+
if (node.type === FOOTNOTE_REFERENCE) {
|
|
254
|
+
const id = typeof node.attrs?.id === 'string' ? node.attrs.id : '';
|
|
255
|
+
return id ? [{ type: 'footnoteReference', id }] : [];
|
|
256
|
+
}
|
|
165
257
|
if (node.type !== 'text' || !node.text)
|
|
166
258
|
return [];
|
|
167
259
|
const marks = node.marks ?? [];
|
|
260
|
+
if (marks.some((mark) => mark.type === MATH))
|
|
261
|
+
return [{ type: 'math', value: node.text }];
|
|
168
262
|
let inline = marks.some((mark) => mark.type === 'code')
|
|
169
263
|
? { type: 'code', value: node.text }
|
|
170
264
|
: { type: 'text', value: node.text };
|
|
@@ -197,7 +291,13 @@ function blockNodes(content, depth = 0) {
|
|
|
197
291
|
}
|
|
198
292
|
];
|
|
199
293
|
case 'blockquote':
|
|
200
|
-
return [
|
|
294
|
+
return [
|
|
295
|
+
{
|
|
296
|
+
type: 'blockquote',
|
|
297
|
+
children: blockNodes(node.content, depth + 1),
|
|
298
|
+
...(isCallout(node.attrs?.callout) ? { callout: node.attrs.callout } : {})
|
|
299
|
+
}
|
|
300
|
+
];
|
|
201
301
|
case 'bulletList':
|
|
202
302
|
case 'orderedList': {
|
|
203
303
|
const start = Number(node.attrs?.start);
|
|
@@ -208,12 +308,35 @@ function blockNodes(content, depth = 0) {
|
|
|
208
308
|
...(node.type === 'orderedList' && Number.isInteger(start) && start !== 1
|
|
209
309
|
? { start }
|
|
210
310
|
: {}),
|
|
211
|
-
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1))
|
|
311
|
+
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1)),
|
|
312
|
+
...((node.content ?? []).some((item) => typeof item.attrs?.checked === 'boolean')
|
|
313
|
+
? {
|
|
314
|
+
checked: (node.content ?? []).map((item) => typeof item.attrs?.checked === 'boolean' ? item.attrs.checked : null)
|
|
315
|
+
}
|
|
316
|
+
: {})
|
|
212
317
|
}
|
|
213
318
|
];
|
|
214
319
|
}
|
|
320
|
+
case 'taskList':
|
|
321
|
+
return [
|
|
322
|
+
{
|
|
323
|
+
type: 'list',
|
|
324
|
+
ordered: false,
|
|
325
|
+
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1)),
|
|
326
|
+
checked: (node.content ?? []).map((item) => item.attrs?.checked === true)
|
|
327
|
+
}
|
|
328
|
+
];
|
|
329
|
+
case FOOTNOTE_DEFINITION: {
|
|
330
|
+
const id = typeof node.attrs?.id === 'string' ? node.attrs.id : '';
|
|
331
|
+
return id
|
|
332
|
+
? [{ type: 'footnoteDefinition', id, children: blockNodes(node.content, depth + 1) }]
|
|
333
|
+
: [];
|
|
334
|
+
}
|
|
215
335
|
case 'codeBlock': {
|
|
216
336
|
const lang = typeof node.attrs?.language === 'string' ? node.attrs.language : '';
|
|
337
|
+
const value = (node.content ?? []).map((child) => child.text ?? '').join('');
|
|
338
|
+
if (lang === MATH)
|
|
339
|
+
return [{ type: 'math', value }];
|
|
217
340
|
return [
|
|
218
341
|
{
|
|
219
342
|
type: 'codeBlock',
|
|
@@ -224,6 +347,34 @@ function blockNodes(content, depth = 0) {
|
|
|
224
347
|
}
|
|
225
348
|
case 'horizontalRule':
|
|
226
349
|
return [{ type: 'thematicBreak' }];
|
|
350
|
+
case IMAGE: {
|
|
351
|
+
const url = typeof node.attrs?.url === 'string' ? node.attrs.url : '';
|
|
352
|
+
const alt = typeof node.attrs?.alt === 'string' ? node.attrs.alt : '';
|
|
353
|
+
const title = typeof node.attrs?.title === 'string' ? node.attrs.title : '';
|
|
354
|
+
return url
|
|
355
|
+
? [{ type: 'image', url, ...(alt ? { alt } : {}), ...(title ? { title } : {}) }]
|
|
356
|
+
: [];
|
|
357
|
+
}
|
|
358
|
+
case 'table': {
|
|
359
|
+
const rows = (node.content ?? []).map((row) => (row.content ?? []).map((cell) => (cell.content ?? []).flatMap((child, index) => [
|
|
360
|
+
...(index ? [{ type: 'text', value: ' ' }] : []),
|
|
361
|
+
...inlineNodes(child.content)
|
|
362
|
+
])));
|
|
363
|
+
if (!rows.length)
|
|
364
|
+
return [];
|
|
365
|
+
const width = Math.max(1, ...rows.map((row) => row.length));
|
|
366
|
+
const first = node.content?.[0]?.content ?? [];
|
|
367
|
+
return [
|
|
368
|
+
{
|
|
369
|
+
type: 'table',
|
|
370
|
+
align: Array.from({ length: width }, (_, index) => {
|
|
371
|
+
const align = first[index]?.attrs?.align;
|
|
372
|
+
return align === 'left' || align === 'center' || align === 'right' ? align : null;
|
|
373
|
+
}),
|
|
374
|
+
rows: rows.map((row) => Array.from({ length: width }, (_, index) => row[index] ?? []))
|
|
375
|
+
}
|
|
376
|
+
];
|
|
377
|
+
}
|
|
227
378
|
default:
|
|
228
379
|
return [];
|
|
229
380
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export type ImageNodeOptions = {
|
|
3
|
+
/** The address to load a destination from; undefined when it cannot be shown. */
|
|
4
|
+
src: (url: string) => string | undefined;
|
|
5
|
+
altLabel: string;
|
|
6
|
+
};
|
|
7
|
+
/** An image on its own line, written to Markdown as ``. */
|
|
8
|
+
export declare const ImageNode: Node<ImageNodeOptions, any>;
|