@threadlabs/looma 0.45.2 → 0.46.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/EXPRESSIVE-MARKDOWN.md +23 -17
- package/components/ui-section/ui-section.html +18 -7
- package/components/ui-site-header/ui-site-header.html +25 -6
- package/components/ui-site-header/ui-site-header.js +4 -3
- package/dist/index.js +1 -1
- package/docs/catalog.json +3 -3
- package/editor/chunks/expressmark.js +1562 -0
- package/editor/chunks/extensions.js +327 -1051
- package/editor/expressmark.d.ts +17 -5
- package/editor/expressmark.js +1 -1037
- package/editor/extensions/footnote.d.ts +7 -12
- package/editor/extensions/index.d.ts +2 -2
- package/editor/extensions/index.js +3 -3
- package/editor/extensions/link-definition.d.ts +10 -0
- package/editor/index.js +3 -3
- package/markdown/fixtures.d.ts +1 -1
- package/markdown/fixtures.js +22 -16
- package/markdown/index.d.ts +2 -3
- package/markdown/index.js +2 -3
- package/package.json +2 -9
- package/styles/ui-section.css +12 -3
- package/styles/ui-site-header.css +54 -6
- package/vanilla/UiSection.js +6 -5
- package/vanilla/UiSiteHeader.js +29 -44
- package/vue/UiSection.vue +19 -12
- package/vue/UiSiteHeader.d.ts +2 -2
- package/vue/UiSiteHeader.vue +157 -72
- package/vue/chunks/UiSection.js +32 -29
- package/vue/chunks/UiSiteHeader.js +27 -49
- package/vue/components.css +151 -8
- package/vue/editor/LoomaEditor.d.ts +1 -1
- package/vue/editor/index.js +225 -186
- package/editor/chunks/reference-display.js +0 -453
- package/editor/extensions/markdown.d.ts +0 -16
- package/markdown/markdown-it.d.ts +0 -21
- package/markdown/markdown-it.js +0 -562
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { Extension, Node, mergeAttributes } from "@tiptap/core";
|
|
2
|
-
import { NodeSelection, Plugin, PluginKey } from "@tiptap/pm/state";
|
|
3
|
-
//#region src/markdown/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Callout tones a document stores, in the order the editor offers them. The Callout component also
|
|
6
|
-
* takes `neutral` and `success`, which Markdown and the editor store as `note`.
|
|
7
|
-
*/
|
|
8
|
-
var LOOMA_CALLOUT_TONES = [
|
|
9
|
-
"note",
|
|
10
|
-
"tip",
|
|
11
|
-
"info",
|
|
12
|
-
"important",
|
|
13
|
-
"warning",
|
|
14
|
-
"danger"
|
|
15
|
-
];
|
|
16
|
-
/** Names that read as a stored tone: `caution` is `danger`, and `neutral` is the same muted aside as `note`. */
|
|
17
|
-
var LOOMA_CALLOUT_TONE_ALIASES = {
|
|
18
|
-
caution: "danger",
|
|
19
|
-
neutral: "note"
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Maps a tone name or alias, in any case, onto a stored tone.
|
|
23
|
-
* @failure Unknown and non-string values become `note`.
|
|
24
|
-
*/
|
|
25
|
-
function normalizeLoomaCalloutTone(value) {
|
|
26
|
-
if (typeof value !== "string") return "note";
|
|
27
|
-
const tone = value.toLowerCase();
|
|
28
|
-
return LOOMA_CALLOUT_TONES.includes(tone) ? tone : LOOMA_CALLOUT_TONE_ALIASES[tone] ?? "note";
|
|
29
|
-
}
|
|
30
|
-
/** The hues chips and swatches take as their tone, written `:chip[Label]{tone=green}`. */
|
|
31
|
-
var LOOMA_CHIP_TONES = [
|
|
32
|
-
"neutral",
|
|
33
|
-
"blue",
|
|
34
|
-
"green",
|
|
35
|
-
"yellow",
|
|
36
|
-
"red",
|
|
37
|
-
"purple"
|
|
38
|
-
];
|
|
39
|
-
/**
|
|
40
|
-
* Keeps a chip tone within the palette.
|
|
41
|
-
* @failure Unknown values become `neutral`.
|
|
42
|
-
*/
|
|
43
|
-
function normalizeLoomaChipTone(value) {
|
|
44
|
-
return LOOMA_CHIP_TONES.includes(value) ? value : "neutral";
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A mention handle, as `@handle` and the `#ref` of `@[Label]#ref` spell it: a letter, number or
|
|
48
|
-
* underscore, then letters, marks, numbers, underscores and hyphens.
|
|
49
|
-
*/
|
|
50
|
-
var LOOMA_MENTION_HANDLE = /^[\p{L}\p{N}_][\p{L}\p{M}\p{N}_-]*/u;
|
|
51
|
-
/**
|
|
52
|
-
* Names that open a `:::` container, matched without regard to case. A container with any other
|
|
53
|
-
* name is ordinary text.
|
|
54
|
-
*/
|
|
55
|
-
var LOOMA_CONTAINER_NAMES = /* @__PURE__ */ new Set([
|
|
56
|
-
...LOOMA_CALLOUT_TONES,
|
|
57
|
-
"caution",
|
|
58
|
-
"details",
|
|
59
|
-
"figure",
|
|
60
|
-
"tabs",
|
|
61
|
-
"code-group"
|
|
62
|
-
]);
|
|
63
|
-
var ATTRIBUTE_KEY = /[A-Za-z][\w-]*/y;
|
|
64
|
-
var ATTRIBUTE_ID = /#([\w-]+)/y;
|
|
65
|
-
var ATTRIBUTE_VALUE = /[^\s"'=<>`{}]+/y;
|
|
66
|
-
function sticky(pattern, source, index) {
|
|
67
|
-
pattern.lastIndex = index;
|
|
68
|
-
return pattern.exec(source);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Reads a brace attribute list starting at `source[start]`, which must be `{`.
|
|
72
|
-
* @contract Returns the attributes and the index just past the closing brace.
|
|
73
|
-
* @failure Returns null for anything that is not a complete, well-formed list, so the text stays literal.
|
|
74
|
-
*/
|
|
75
|
-
function readLoomaAttributes(source, start = 0) {
|
|
76
|
-
if (source[start] !== "{") return null;
|
|
77
|
-
const attributes = {};
|
|
78
|
-
let index = start + 1;
|
|
79
|
-
for (;;) {
|
|
80
|
-
while (source[index] === " " || source[index] === " ") index++;
|
|
81
|
-
if (source[index] === "}") return {
|
|
82
|
-
attributes,
|
|
83
|
-
end: index + 1
|
|
84
|
-
};
|
|
85
|
-
if (index > start + 1 && !/\s/.test(source[index - 1])) return null;
|
|
86
|
-
const id = sticky(ATTRIBUTE_ID, source, index);
|
|
87
|
-
if (id) {
|
|
88
|
-
attributes.id = id[1];
|
|
89
|
-
index += id[0].length;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const key = sticky(ATTRIBUTE_KEY, source, index);
|
|
93
|
-
if (!key) return null;
|
|
94
|
-
index += key[0].length;
|
|
95
|
-
if (source[index] !== "=") {
|
|
96
|
-
attributes[key[0]] = true;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
index++;
|
|
100
|
-
const quote = source[index];
|
|
101
|
-
if (quote === "\"" || quote === "'") {
|
|
102
|
-
const close = source.indexOf(quote, index + 1);
|
|
103
|
-
if (close < 0) return null;
|
|
104
|
-
attributes[key[0]] = source.slice(index + 1, close);
|
|
105
|
-
index = close + 1;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const value = sticky(ATTRIBUTE_VALUE, source, index);
|
|
109
|
-
if (!value) return null;
|
|
110
|
-
attributes[key[0]] = value[0];
|
|
111
|
-
index += value[0].length;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Reads a whole string as one brace attribute list.
|
|
116
|
-
* @failure Returns null unless the string is exactly one well-formed list.
|
|
117
|
-
*/
|
|
118
|
-
function parseLoomaAttributes(source) {
|
|
119
|
-
const read = readLoomaAttributes(source);
|
|
120
|
-
return read && read.end === source.length ? read.attributes : null;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Writes attributes as a brace list, `id` first as `#id`, then the rest in order.
|
|
124
|
-
* @contract `true` writes a bare key; values are quoted only when they need it. `false`, null and
|
|
125
|
-
* undefined values are left out, and an empty set writes an empty string. An ID that `#` cannot
|
|
126
|
-
* carry, or any ID when `hashId` is false, is written `id=…`.
|
|
127
|
-
*/
|
|
128
|
-
function formatLoomaAttributes(attributes, { hashId = true } = {}) {
|
|
129
|
-
const items = [];
|
|
130
|
-
const { id, ...rest } = attributes;
|
|
131
|
-
const hashed = hashId && typeof id === "string" && /^[\w-]+$/.test(id);
|
|
132
|
-
if (hashed) items.push(`#${id}`);
|
|
133
|
-
for (const [key, value] of Object.entries(hashed ? rest : attributes)) if (value === true) items.push(key);
|
|
134
|
-
else if (value === false || value === null || value === void 0) continue;
|
|
135
|
-
else {
|
|
136
|
-
const text = String(value);
|
|
137
|
-
items.push(/^[^\s"'=<>`{}]+$/.test(text) ? `${key}=${text}` : text.includes("\"") ? `${key}='${text}'` : `${key}="${text}"`);
|
|
138
|
-
}
|
|
139
|
-
return items.length ? `{${items.join(" ")}}` : "";
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* The anchor a heading's text derives: NFC, lowercase, keeping letters, numbers and combining
|
|
143
|
-
* marks, with every other run of characters one hyphen.
|
|
144
|
-
* @failure Text with no letters or numbers, such as only emoji, derives `heading`.
|
|
145
|
-
*/
|
|
146
|
-
function loomaHeadingSlug(text) {
|
|
147
|
-
return text.normalize("NFC").toLowerCase().replace(/[^\p{L}\p{N}\p{M}]+/gu, "-").replace(/^-+|-+$/g, "") || "heading";
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Gives every heading of a document its anchor, in document order.
|
|
151
|
-
* @contract A custom ID is kept unless an earlier heading already has it. Any other heading takes
|
|
152
|
-
* its slug, or the slug's first free suffix (`-1`, `-2`…), never one a later custom ID reserves.
|
|
153
|
-
*/
|
|
154
|
-
function assignLoomaHeadingIds(headings) {
|
|
155
|
-
const reserved = new Set(headings.map(({ id }) => id).filter((id) => Boolean(id)));
|
|
156
|
-
const used = /* @__PURE__ */ new Set();
|
|
157
|
-
return headings.map(({ text, id: custom }) => {
|
|
158
|
-
let id = custom || loomaHeadingSlug(text);
|
|
159
|
-
if (custom ? used.has(id) : used.has(id) || reserved.has(id)) {
|
|
160
|
-
const stem = id;
|
|
161
|
-
let suffix = 1;
|
|
162
|
-
while (used.has(`${stem}-${suffix}`) || reserved.has(`${stem}-${suffix}`)) suffix++;
|
|
163
|
-
id = `${stem}-${suffix}`;
|
|
164
|
-
}
|
|
165
|
-
used.add(id);
|
|
166
|
-
return id;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/** Reads a fence's info string: ```` ```ts title="a.ts" {1,3-5} :line-numbers ````. */
|
|
170
|
-
function parseLoomaFenceInfo(info) {
|
|
171
|
-
const source = info.trim();
|
|
172
|
-
const language = /^[^\s={:]+(?=[\s{:]|$)/.exec(source)?.[0];
|
|
173
|
-
const meta = (language ? source.slice(language.length) : source).trim();
|
|
174
|
-
const title = /(?:^|\s)title="([^"]*)"/.exec(meta)?.[1];
|
|
175
|
-
const rest = meta.replace(/(?:^|\s)title="[^"]*"/, "");
|
|
176
|
-
const lines = /* @__PURE__ */ new Set();
|
|
177
|
-
for (const range of /\{([\d\s,-]+)\}/.exec(rest)?.[1].split(",") ?? []) {
|
|
178
|
-
const [from = NaN, to = from] = range.split("-").map((part) => Number.parseInt(part, 10));
|
|
179
|
-
for (let line = from; line <= to; line++) lines.add(line);
|
|
180
|
-
}
|
|
181
|
-
const numbers = /:(no-)?line-numbers(?![\w-])/.exec(rest);
|
|
182
|
-
return {
|
|
183
|
-
...language ? { language } : {},
|
|
184
|
-
meta,
|
|
185
|
-
...title !== void 0 ? { title } : {},
|
|
186
|
-
lines: [...lines].sort((a, b) => a - b),
|
|
187
|
-
...numbers ? { lineNumbers: numbers[1] === void 0 } : {}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
var MAPPING_KEY = /^(?:[^\s#:'"\-?,[\]{}&*!|>%@`][^:\n]*?|"[^"\n]*"|'[^'\n]*')[ \t]*:(?:[ \t]|$)/;
|
|
191
|
-
var NOTATION = /[ \t]*(?:\/\/|#|--|<!--|\{?\/\*)[ \t]*\[!code highlight(?::(\d+))?\][ \t]*(?:-->|\*\/\}?)?[ \t]*$/;
|
|
192
|
-
var ESCAPED_NOTATION = /\[\\(\\*!code highlight)/g;
|
|
193
|
-
/**
|
|
194
|
-
* Applies code notation: a line ending in a `[!code highlight]` comment is highlighted and loses
|
|
195
|
-
* the comment, `[!code highlight:3]` covers three lines, and a marker alone on its line is removed
|
|
196
|
-
* with the line and applies to the lines after it. A backslash between `[` and `!` escapes a
|
|
197
|
-
* marker, `[\!code highlight]`, which then shows as text with one backslash fewer and highlights
|
|
198
|
-
* nothing.
|
|
199
|
-
* @contract Returns the code a reader sees and its highlighted line numbers, from 1, ascending.
|
|
200
|
-
* ponytail: matched on source lines, so a string that ends in the marker counts too.
|
|
201
|
-
*/
|
|
202
|
-
function applyLoomaCodeNotation(code) {
|
|
203
|
-
const kept = [];
|
|
204
|
-
const lines = /* @__PURE__ */ new Set();
|
|
205
|
-
for (const line of code.split("\n")) {
|
|
206
|
-
const match = NOTATION.exec(line);
|
|
207
|
-
if (!match) {
|
|
208
|
-
kept.push(line);
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
const rest = line.slice(0, match.index);
|
|
212
|
-
const own = rest.trim() !== "";
|
|
213
|
-
if (own) kept.push(rest);
|
|
214
|
-
for (let count = 0; count < Number(match[1] ?? 1); count++) lines.add(kept.length + (own ? 0 : 1) + count);
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
code: kept.join("\n").replace(ESCAPED_NOTATION, "[$1"),
|
|
218
|
-
lines: [...lines].sort((a, b) => a - b)
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Splits YAML front matter from the start of a document.
|
|
223
|
-
* @contract Front matter opens with a `---` line at the very start and closes at a `---` or `...`
|
|
224
|
-
* line, and what lies between is a YAML mapping: its first line that is not blank or a comment
|
|
225
|
-
* starts with a key, whose value may be a scalar, a list or a mapping. `source` is the block as
|
|
226
|
-
* written, delimiters included.
|
|
227
|
-
* @failure Returns null when the document has none.
|
|
228
|
-
*/
|
|
229
|
-
function splitLoomaFrontmatter(document) {
|
|
230
|
-
const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/.exec(document.slice(0, 8192));
|
|
231
|
-
const first = match?.[1].split(/\r?\n/).find((line) => line.trim() && !line.trimStart().startsWith("#"));
|
|
232
|
-
if (!match || !first || !MAPPING_KEY.test(first)) return null;
|
|
233
|
-
return {
|
|
234
|
-
source: match[0].trimEnd(),
|
|
235
|
-
yaml: match[1],
|
|
236
|
-
body: document.slice(match[0].length)
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
/** The colons a container opens and closes with, given how deeply containers nest inside it. */
|
|
240
|
-
function loomaContainerMarker(nestedDepth) {
|
|
241
|
-
return ":".repeat(3 + Math.max(0, nestedDepth));
|
|
242
|
-
}
|
|
243
|
-
/** A backtick fence longer than any run of backticks in the code, and at least three long. */
|
|
244
|
-
function loomaCodeFence(code) {
|
|
245
|
-
const longest = Math.max(0, ...(code.match(/`+/g) ?? []).map((run) => run.length));
|
|
246
|
-
return "`".repeat(Math.max(3, longest + 1));
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/editor/content.ts
|
|
250
|
-
/**
|
|
251
|
-
* A link destination the editor may store: a site-relative path, fragment, or query, or an
|
|
252
|
-
* absolute http, https, mailto, or tel URL.
|
|
253
|
-
*
|
|
254
|
-
* @failure Returns null for empty input, control characters, other schemes, and unparseable URLs.
|
|
255
|
-
*/
|
|
256
|
-
function validLinkHref(value) {
|
|
257
|
-
const href = value.trim();
|
|
258
|
-
if (!href || /[\u0000-\u001f\u007f]/.test(href)) return null;
|
|
259
|
-
if (/^(\/|#|\?)/.test(href)) return href;
|
|
260
|
-
try {
|
|
261
|
-
const url = new URL(href);
|
|
262
|
-
return [
|
|
263
|
-
"http:",
|
|
264
|
-
"https:",
|
|
265
|
-
"mailto:",
|
|
266
|
-
"tel:"
|
|
267
|
-
].includes(url.protocol) ? href : null;
|
|
268
|
-
} catch {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/editor/reference-display.ts
|
|
274
|
-
var referenceDisplayKey = new PluginKey("loomaReferenceDisplay");
|
|
275
|
-
var referenceDisplayMeta = "loomaReferenceDisplay";
|
|
276
|
-
/**
|
|
277
|
-
* Replaces presentation without editing the document or adding an undo/history entry.
|
|
278
|
-
* @lifecycle Values last until the next replacement or editor destruction; hosts own persistence.
|
|
279
|
-
*/
|
|
280
|
-
function setReferenceDisplay(editor, references) {
|
|
281
|
-
if (editor.isDestroyed) return;
|
|
282
|
-
editor.storage.loomaReferencePresentation?.enableMentions?.();
|
|
283
|
-
editor.view.dispatch(editor.state.tr.setMeta(referenceDisplayMeta, references).setMeta("addToHistory", false));
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* The current replaceable presentation; absent entries use the saved fallback.
|
|
287
|
-
* @ownership The returned map belongs to the host; replace it rather than mutating it.
|
|
288
|
-
*/
|
|
289
|
-
function getReferenceDisplay(editor) {
|
|
290
|
-
return editor.storage.loomaReferencePresentation?.references ?? {};
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Reads current host presentation, with a durable insertion-time fallback for offline copies.
|
|
294
|
-
* @failure Unsafe cached destinations fall back to the saved safe URL or no destination.
|
|
295
|
-
*/
|
|
296
|
-
function referenceDisplay(node, references = {}) {
|
|
297
|
-
const kind = node.type.name === "mention" ? "mention" : node.attrs.kind;
|
|
298
|
-
const display = references[`${kind}:${node.attrs.id}`];
|
|
299
|
-
const label = typeof display?.label === "string" ? display.label : typeof node.attrs.label === "string" ? node.attrs.label : String(node.attrs.id ?? "Reference");
|
|
300
|
-
const href = typeof display?.href === "string" ? validLinkHref(display.href) : null;
|
|
301
|
-
return {
|
|
302
|
-
label,
|
|
303
|
-
...kind === "link" ? { href: href ?? (typeof node.attrs.href === "string" ? validLinkHref(node.attrs.href) : null) ?? void 0 } : {}
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* An automatically labelled link; custom wording remains an ordinary text link.
|
|
308
|
-
* @contract Identity and insertion-time fallback stay in JSON; cached presentation stays outside it.
|
|
309
|
-
*/
|
|
310
|
-
var LoomaReference = Node.create({
|
|
311
|
-
name: "loomaReference",
|
|
312
|
-
inline: true,
|
|
313
|
-
group: "inline",
|
|
314
|
-
atom: true,
|
|
315
|
-
addAttributes: () => ({
|
|
316
|
-
id: {
|
|
317
|
-
default: null,
|
|
318
|
-
renderHTML: () => ({})
|
|
319
|
-
},
|
|
320
|
-
kind: {
|
|
321
|
-
default: "link",
|
|
322
|
-
renderHTML: () => ({})
|
|
323
|
-
},
|
|
324
|
-
href: {
|
|
325
|
-
default: null,
|
|
326
|
-
renderHTML: () => ({})
|
|
327
|
-
},
|
|
328
|
-
label: {
|
|
329
|
-
default: null,
|
|
330
|
-
renderHTML: () => ({})
|
|
331
|
-
},
|
|
332
|
-
target: {
|
|
333
|
-
default: "_self",
|
|
334
|
-
renderHTML: () => ({})
|
|
335
|
-
}
|
|
336
|
-
}),
|
|
337
|
-
parseHTML: () => [{
|
|
338
|
-
tag: "a[data-looma-reference]",
|
|
339
|
-
priority: 1001,
|
|
340
|
-
getAttrs: (element) => ({
|
|
341
|
-
id: element.getAttribute("data-looma-reference"),
|
|
342
|
-
kind: "link",
|
|
343
|
-
href: element.getAttribute("href"),
|
|
344
|
-
label: element.textContent,
|
|
345
|
-
target: element.getAttribute("target") ?? "_self"
|
|
346
|
-
})
|
|
347
|
-
}],
|
|
348
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
349
|
-
const display = referenceDisplay(node, this.editor ? getReferenceDisplay(this.editor) : {});
|
|
350
|
-
return [
|
|
351
|
-
"a",
|
|
352
|
-
mergeAttributes(HTMLAttributes, {
|
|
353
|
-
"data-looma-reference": node.attrs.id,
|
|
354
|
-
href: display.href,
|
|
355
|
-
target: node.attrs.target === "_blank" ? "_blank" : "_self",
|
|
356
|
-
rel: "noopener noreferrer"
|
|
357
|
-
}),
|
|
358
|
-
display.label
|
|
359
|
-
];
|
|
360
|
-
},
|
|
361
|
-
renderText({ node }) {
|
|
362
|
-
return referenceDisplay(node, this.editor ? getReferenceDisplay(this.editor) : {}).label;
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
/**
|
|
366
|
-
* Installs metadata-backed node views for references and existing stable-id mentions.
|
|
367
|
-
* @lifecycle Node views register until destroyed, including across editor reattachment.
|
|
368
|
-
*/
|
|
369
|
-
var LoomaReferencePresentation = Extension.create({
|
|
370
|
-
name: "loomaReferencePresentation",
|
|
371
|
-
addOptions: () => ({
|
|
372
|
-
references: {},
|
|
373
|
-
mentions: false
|
|
374
|
-
}),
|
|
375
|
-
addStorage() {
|
|
376
|
-
return { references: this.options.references };
|
|
377
|
-
},
|
|
378
|
-
addProseMirrorPlugins() {
|
|
379
|
-
const initial = this.options.references;
|
|
380
|
-
const refresh = /* @__PURE__ */ new Set();
|
|
381
|
-
const nodeView = (node, view, getPosition) => {
|
|
382
|
-
let current = node;
|
|
383
|
-
const mention = node.type.name === "mention";
|
|
384
|
-
const dom = document.createElement(mention ? "span" : "a");
|
|
385
|
-
if (mention) {
|
|
386
|
-
dom.className = "looma-mention";
|
|
387
|
-
dom.setAttribute("data-type", "mention");
|
|
388
|
-
} else dom.addEventListener("click", (event) => {
|
|
389
|
-
if (!(event instanceof MouseEvent) || !view.editable || event.metaKey || event.ctrlKey) return;
|
|
390
|
-
const position = getPosition();
|
|
391
|
-
if (position === void 0) return;
|
|
392
|
-
event.preventDefault();
|
|
393
|
-
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, position)));
|
|
394
|
-
view.focus();
|
|
395
|
-
});
|
|
396
|
-
const render = () => {
|
|
397
|
-
const display = referenceDisplay(current, referenceDisplayKey.getState(view.state));
|
|
398
|
-
dom.textContent = `${mention ? "@" : ""}${display.label}`;
|
|
399
|
-
if (mention) {
|
|
400
|
-
dom.setAttribute("data-id", current.attrs.id ?? "");
|
|
401
|
-
dom.setAttribute("data-label", display.label);
|
|
402
|
-
}
|
|
403
|
-
if (!mention) {
|
|
404
|
-
dom.setAttribute("data-looma-reference", current.attrs.id ?? "");
|
|
405
|
-
if (display.href) dom.setAttribute("href", display.href);
|
|
406
|
-
else dom.removeAttribute("href");
|
|
407
|
-
dom.setAttribute("target", current.attrs.target === "_blank" ? "_blank" : "_self");
|
|
408
|
-
dom.setAttribute("rel", "noopener noreferrer");
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
refresh.add(render);
|
|
412
|
-
render();
|
|
413
|
-
return {
|
|
414
|
-
dom,
|
|
415
|
-
update(next) {
|
|
416
|
-
if (next.type !== current.type) return false;
|
|
417
|
-
current = next;
|
|
418
|
-
render();
|
|
419
|
-
return true;
|
|
420
|
-
},
|
|
421
|
-
destroy: () => {
|
|
422
|
-
refresh.delete(render);
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
};
|
|
426
|
-
const nodeViews = {
|
|
427
|
-
loomaReference: nodeView,
|
|
428
|
-
...this.options.mentions && this.editor.schema.nodes.mention ? { mention: nodeView } : {}
|
|
429
|
-
};
|
|
430
|
-
this.storage.enableMentions = () => {
|
|
431
|
-
if (nodeViews.mention || !this.editor.schema.nodes.mention) return;
|
|
432
|
-
nodeViews.mention = nodeView;
|
|
433
|
-
this.editor.view.setProps({ nodeViews: { ...this.editor.view.props.nodeViews } });
|
|
434
|
-
};
|
|
435
|
-
return [new Plugin({
|
|
436
|
-
key: referenceDisplayKey,
|
|
437
|
-
state: {
|
|
438
|
-
init: () => initial,
|
|
439
|
-
apply: (transaction, previous) => {
|
|
440
|
-
const next = transaction.getMeta(referenceDisplayMeta) ?? previous;
|
|
441
|
-
this.storage.references = next;
|
|
442
|
-
return next;
|
|
443
|
-
}
|
|
444
|
-
},
|
|
445
|
-
props: { nodeViews },
|
|
446
|
-
view: () => ({ update: (view, previous) => {
|
|
447
|
-
if (referenceDisplayKey.getState(view.state) !== referenceDisplayKey.getState(previous)) refresh.forEach((render) => render());
|
|
448
|
-
} })
|
|
449
|
-
})];
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
//#endregion
|
|
453
|
-
export { normalizeLoomaChipTone as _, setReferenceDisplay as a, readLoomaAttributes as b, LOOMA_CONTAINER_NAMES as c, assignLoomaHeadingIds as d, formatLoomaAttributes as f, normalizeLoomaCalloutTone as g, loomaHeadingSlug as h, referenceDisplay as i, LOOMA_MENTION_HANDLE as l, loomaContainerMarker as m, LoomaReferencePresentation as n, LOOMA_CALLOUT_TONES as o, loomaCodeFence as p, getReferenceDisplay as r, LOOMA_CHIP_TONES as s, LoomaReference as t, applyLoomaCodeNotation as u, parseLoomaAttributes as v, splitLoomaFrontmatter as x, parseLoomaFenceInfo as y };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|
2
|
-
/** The markdown-it instance LoomaEditor reads Looma Markdown with; code keeps its notation as source. */
|
|
3
|
-
export declare const loomaMarkdown: import("markdown-it").default;
|
|
4
|
-
/**
|
|
5
|
-
* Renders Looma Markdown as the HTML the editor parses.
|
|
6
|
-
* @contract The result is not sanitized; pass it to the editor's `setContent`, whose schema
|
|
7
|
-
* keeps only content it knows. Front matter renders nothing.
|
|
8
|
-
*/
|
|
9
|
-
export declare function loomaMarkdownToHtml(source: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Writes an editor document as Looma Markdown, the form `loomaMarkdownToHtml` and Markupress read.
|
|
12
|
-
* @contract Every node in the default preset has a Markdown form. A table that fits GFM is a GFM
|
|
13
|
-
* table and any other is HTML. Content from extensions outside the preset is written as its saved
|
|
14
|
-
* HTML, and marks without a Markdown form other than underline and highlight are dropped.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loomaMarkdownFromDoc(doc: ProseMirrorNode): string;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import MarkdownIt from "markdown-it";
|
|
2
|
-
/** How a Looma Markdown instance renders. */
|
|
3
|
-
export interface LoomaMarkdownOptions {
|
|
4
|
-
/**
|
|
5
|
-
* `apply` (default) renders code as a reader sees it, without its `[!code highlight]` comments;
|
|
6
|
-
* `keep` keeps them in the code, for an editor that edits the source.
|
|
7
|
-
*/
|
|
8
|
-
codeNotation?: "apply" | "keep";
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Adds Looma Markdown to a markdown-it instance: containers, alerts, task lists, footnotes, the table of
|
|
12
|
-
* contents, chips, mentions, brace attributes, heading anchors, code meta and front matter.
|
|
13
|
-
* @contract Renders the canonical HTML, which is the HTML LoomaEditor saves. It is not sanitized.
|
|
14
|
-
* Linkify and raw HTML are instance options; `createLoomaMarkdownIt` turns both on.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loomaMarkdown(md: MarkdownIt, { codeNotation }?: LoomaMarkdownOptions): void;
|
|
17
|
-
/**
|
|
18
|
-
* A markdown-it instance for Looma Markdown: raw HTML and GFM autolinks on, with `loomaMarkdown`.
|
|
19
|
-
* @contract Each call returns a new instance that callers may extend.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createLoomaMarkdownIt(options?: LoomaMarkdownOptions): MarkdownIt;
|