@xenosystem/blocks 0.23.1 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-NFOBZJDF.js → chunk-5NDMACVU.js} +3 -256
- package/dist/{chunk-5VOA3OSG.js → chunk-JEY4JFVJ.js} +9 -313
- package/dist/chunk-KC2QBI2I.js +314 -0
- package/dist/chunk-MDNEMOZD.js +259 -0
- package/dist/docs/collaboration.d.ts +60 -0
- package/dist/docs/collaboration.js +49 -0
- package/dist/docs/core.d.ts +10 -3
- package/dist/docs/core.js +14 -10
- package/dist/docs/format.d.ts +3 -123
- package/dist/docs/format.js +5 -3
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.js +13 -9
- package/dist/format-BoLLqtrs.d.ts +124 -0
- package/package.json +32 -3
|
@@ -1,242 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var XDOC_EXTENSION = ".xdoc";
|
|
5
|
-
var DOCUMENT_NODE_TYPES = Object.freeze([
|
|
6
|
-
"doc",
|
|
7
|
-
"paragraph",
|
|
8
|
-
"text",
|
|
9
|
-
"heading",
|
|
10
|
-
"blockquote",
|
|
11
|
-
"bulletList",
|
|
12
|
-
"orderedList",
|
|
13
|
-
"listItem",
|
|
14
|
-
"taskList",
|
|
15
|
-
"taskItem",
|
|
16
|
-
"codeBlock",
|
|
17
|
-
"horizontalRule",
|
|
18
|
-
"hardBreak",
|
|
19
|
-
"table",
|
|
20
|
-
"tableRow",
|
|
21
|
-
"tableCell",
|
|
22
|
-
"tableHeader",
|
|
23
|
-
"image",
|
|
24
|
-
"callout",
|
|
25
|
-
"toggleBlock",
|
|
26
|
-
"pageBreak"
|
|
27
|
-
]);
|
|
28
|
-
var DOCUMENT_MARK_TYPES = Object.freeze([
|
|
29
|
-
"bold",
|
|
30
|
-
"italic",
|
|
31
|
-
"strike",
|
|
32
|
-
"code",
|
|
33
|
-
"underline",
|
|
34
|
-
"link",
|
|
35
|
-
"subscript",
|
|
36
|
-
"superscript",
|
|
37
|
-
"highlight",
|
|
38
|
-
"wikiLink"
|
|
39
|
-
]);
|
|
40
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
41
|
-
var SAFE_LINK = /^(https?:\/\/|mailto:)/i;
|
|
42
|
-
var SAFE_IMAGE = /^(https:\/\/|data:image\/(png|jpe?g|gif|webp);base64,)/i;
|
|
43
|
-
var CALLOUT_TYPES = /* @__PURE__ */ new Set(["info", "warning", "error", "success", "tip"]);
|
|
44
|
-
var ALIGN = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
|
|
45
|
-
var COLOUR_VALUE = /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]{3,20}|var\(--[a-zA-Z0-9-]{1,60}\))$/;
|
|
46
|
-
var LANGUAGE = /^[a-zA-Z0-9_+#.-]{0,40}$/;
|
|
47
|
-
var LIMITS = Object.freeze({ depth: 64, nodes: 5e4, text: 2e6 });
|
|
48
|
-
var isNull = (v) => v === null || v === void 0;
|
|
49
|
-
var optString = (max) => (v) => isNull(v) || typeof v === "string" && v.length <= max;
|
|
50
|
-
var align = (v) => isNull(v) || typeof v === "string" && ALIGN.has(v);
|
|
51
|
-
var int = (lo, hi) => (v) => isNull(v) || Number.isInteger(v) && v >= lo && v <= hi;
|
|
52
|
-
var bool = (v) => isNull(v) || typeof v === "boolean";
|
|
53
|
-
var colwidth = (v) => isNull(v) || Array.isArray(v) && v.length <= 64 && v.every((n) => Number.isInteger(n) && n >= 0 && n <= 1e4);
|
|
54
|
-
var dims = (v) => isNull(v) || typeof v === "number" && v >= 0 && v <= 1e5 || typeof v === "string" && /^\d{1,6}(px|%)?$/.test(v);
|
|
55
|
-
var NODE_ATTRS = {
|
|
56
|
-
paragraph: { textAlign: align },
|
|
57
|
-
heading: { level: int(1, 6), textAlign: align },
|
|
58
|
-
orderedList: { start: int(0, 1e6), type: optString(8) },
|
|
59
|
-
taskItem: { checked: bool },
|
|
60
|
-
codeBlock: { language: (v) => isNull(v) || typeof v === "string" && LANGUAGE.test(v) },
|
|
61
|
-
tableCell: { colspan: int(1, 1e3), rowspan: int(1, 1e3), colwidth },
|
|
62
|
-
tableHeader: { colspan: int(1, 1e3), rowspan: int(1, 1e3), colwidth },
|
|
63
|
-
image: { src: (v) => typeof v === "string" && v.length <= 8e6 && SAFE_IMAGE.test(v), alt: optString(1e3), title: optString(1e3), width: dims, height: dims },
|
|
64
|
-
callout: { type: (v) => isNull(v) || typeof v === "string" && CALLOUT_TYPES.has(v) },
|
|
65
|
-
toggleBlock: { open: bool, summary: optString(500) }
|
|
66
|
-
};
|
|
67
|
-
var MARK_ATTRS = {
|
|
68
|
-
link: {
|
|
69
|
-
href: (v) => typeof v === "string" && v.length <= 4e3 && SAFE_LINK.test(v.trim()),
|
|
70
|
-
target: (v) => isNull(v) || v === "_blank",
|
|
71
|
-
rel: optString(200),
|
|
72
|
-
class: (v) => isNull(v)
|
|
73
|
-
},
|
|
74
|
-
highlight: { color: (v) => isNull(v) || typeof v === "string" && COLOUR_VALUE.test(v) },
|
|
75
|
-
wikiLink: { pageId: (v) => isNull(v) || typeof v === "string" && (UUID.test(v) || /^[A-Za-z0-9_-]{1,128}$/.test(v)), pageTitle: optString(500) }
|
|
76
|
-
};
|
|
77
|
-
function validateContent(content, options = {}) {
|
|
78
|
-
const nodes = /* @__PURE__ */ new Set([...DOCUMENT_NODE_TYPES, ...options.extraNodes ?? []]);
|
|
79
|
-
const marks = /* @__PURE__ */ new Set([...DOCUMENT_MARK_TYPES, ...options.extraMarks ?? []]);
|
|
80
|
-
const extraN = new Set(options.extraNodes ?? []);
|
|
81
|
-
const extraM = new Set(options.extraMarks ?? []);
|
|
82
|
-
const problems = [];
|
|
83
|
-
let count = 0;
|
|
84
|
-
let text = 0;
|
|
85
|
-
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
86
|
-
const attrs = (where, kind, value, rules) => {
|
|
87
|
-
if (isNull(value)) return;
|
|
88
|
-
if (!isObj(value)) {
|
|
89
|
-
problems.push({ path: where, code: "bad_shape", detail: `${kind}.attrs is not an object` });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
for (const [k, v] of Object.entries(value)) {
|
|
93
|
-
const rule = rules?.[k];
|
|
94
|
-
if (!rule) {
|
|
95
|
-
if (!isNull(v)) problems.push({ path: where, code: "bad_attr", detail: `${kind} does not take "${k}"` });
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (!rule(v)) problems.push({ path: where, code: "bad_attr", detail: `${kind}.${k} is not allowed` });
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const walk = (n, where, depth) => {
|
|
102
|
-
if (problems.length > 50) return;
|
|
103
|
-
if (depth > LIMITS.depth) {
|
|
104
|
-
problems.push({ path: where, code: "too_deep", detail: `deeper than ${LIMITS.depth}` });
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (++count > LIMITS.nodes) {
|
|
108
|
-
if (count === LIMITS.nodes + 1) problems.push({ path: where, code: "too_large", detail: `more than ${LIMITS.nodes} nodes` });
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (!isObj(n) || typeof n.type !== "string") {
|
|
112
|
-
problems.push({ path: where, code: "bad_shape", detail: "a node needs a string type" });
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (!nodes.has(n.type)) {
|
|
116
|
-
problems.push({ path: where, code: "unknown_node", detail: n.type });
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (!extraN.has(n.type)) attrs(where, n.type, n.attrs, NODE_ATTRS[n.type]);
|
|
120
|
-
if (n.type === "text") {
|
|
121
|
-
if (typeof n.text !== "string" || !n.text) problems.push({ path: where, code: "bad_shape", detail: "a text node needs text" });
|
|
122
|
-
else if ((text += n.text.length) > LIMITS.text) problems.push({ path: where, code: "too_large", detail: `more than ${LIMITS.text} characters` });
|
|
123
|
-
} else if (n.text !== void 0) problems.push({ path: where, code: "bad_shape", detail: `${n.type} cannot carry text` });
|
|
124
|
-
if (n.marks !== void 0) {
|
|
125
|
-
if (!Array.isArray(n.marks)) problems.push({ path: where, code: "bad_shape", detail: "marks is not a list" });
|
|
126
|
-
else n.marks.forEach((m, i) => {
|
|
127
|
-
if (!isObj(m) || typeof m.type !== "string") problems.push({ path: `${where}.marks[${i}]`, code: "bad_shape", detail: "a mark needs a string type" });
|
|
128
|
-
else if (!marks.has(m.type)) problems.push({ path: `${where}.marks[${i}]`, code: "unknown_mark", detail: m.type });
|
|
129
|
-
else if (!extraM.has(m.type)) attrs(`${where}.marks[${i}]`, m.type, m.attrs, MARK_ATTRS[m.type]);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (n.content !== void 0) {
|
|
133
|
-
if (!Array.isArray(n.content)) problems.push({ path: where, code: "bad_shape", detail: "content is not a list" });
|
|
134
|
-
else n.content.forEach((c, i) => walk(c, `${where}.content[${i}]`, depth + 1));
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
if (!isObj(content) || content.type !== "doc") return [{ path: "content", code: "bad_shape", detail: "the root must be a doc node" }];
|
|
138
|
-
walk(content, "content", 0);
|
|
139
|
-
return problems;
|
|
140
|
-
}
|
|
141
|
-
var XdocError = class extends Error {
|
|
142
|
-
problems;
|
|
143
|
-
constructor(message, problems = []) {
|
|
144
|
-
super(message);
|
|
145
|
-
this.name = "XdocError";
|
|
146
|
-
this.problems = problems;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
var emptyContent = () => ({ type: "doc", content: [{ type: "paragraph" }] });
|
|
150
|
-
function parseXdoc(input, options = {}) {
|
|
151
|
-
let raw = input;
|
|
152
|
-
if (typeof input === "string") {
|
|
153
|
-
try {
|
|
154
|
-
raw = JSON.parse(input);
|
|
155
|
-
} catch {
|
|
156
|
-
throw new XdocError("Not a XENO document: the file is not JSON");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new XdocError("Not a XENO document");
|
|
160
|
-
const r = raw;
|
|
161
|
-
if (r.format !== void 0 && r.format !== XDOC_FORMAT) throw new XdocError(`Not a XENO document (format "${String(r.format)}")`);
|
|
162
|
-
if (r.version !== void 0 && (!Number.isInteger(r.version) || r.version > XDOC_VERSION)) {
|
|
163
|
-
throw new XdocError(`This document was written by a newer XENO Docs (version ${String(r.version)})`);
|
|
164
|
-
}
|
|
165
|
-
const problems = validateContent(r.content, options);
|
|
166
|
-
if (problems.length) throw new XdocError(`The document contains content this editor cannot show (${problems[0].detail})`, problems);
|
|
167
|
-
const now = Date.now();
|
|
168
|
-
const num = (v, d) => typeof v === "number" && Number.isFinite(v) ? v : d;
|
|
169
|
-
const content = r.content;
|
|
170
|
-
return {
|
|
171
|
-
format: XDOC_FORMAT,
|
|
172
|
-
version: XDOC_VERSION,
|
|
173
|
-
...typeof r.id === "string" ? { id: r.id } : {},
|
|
174
|
-
title: typeof r.title === "string" ? r.title : "",
|
|
175
|
-
content,
|
|
176
|
-
created: num(r.created, now),
|
|
177
|
-
lastModified: num(r.lastModified, now),
|
|
178
|
-
wordCount: num(r.wordCount, wordCount(content)),
|
|
179
|
-
...r.commentThreads && typeof r.commentThreads === "object" ? { commentThreads: r.commentThreads } : {}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function serializeXdoc(doc, options = {}) {
|
|
183
|
-
const problems = validateContent(doc.content, options);
|
|
184
|
-
if (problems.length) throw new XdocError(`The document contains content that cannot be saved (${problems[0].detail})`, problems);
|
|
185
|
-
const file = {
|
|
186
|
-
format: XDOC_FORMAT,
|
|
187
|
-
version: XDOC_VERSION,
|
|
188
|
-
...doc.id ? { id: doc.id } : {},
|
|
189
|
-
title: doc.title,
|
|
190
|
-
content: doc.content,
|
|
191
|
-
created: doc.created,
|
|
192
|
-
lastModified: doc.lastModified,
|
|
193
|
-
wordCount: doc.wordCount ?? wordCount(doc.content),
|
|
194
|
-
...doc.commentThreads && typeof doc.commentThreads === "object" ? { commentThreads: doc.commentThreads } : {}
|
|
195
|
-
};
|
|
196
|
-
return JSON.stringify(file, null, options.pretty === false ? void 0 : 2);
|
|
197
|
-
}
|
|
198
|
-
var BLOCKS = /* @__PURE__ */ new Set(["paragraph", "heading", "blockquote", "listItem", "taskItem", "codeBlock", "tableCell", "tableHeader", "callout", "toggleBlock"]);
|
|
199
|
-
function plainText(content) {
|
|
200
|
-
const out = [];
|
|
201
|
-
const walk = (n) => {
|
|
202
|
-
if (!n) return;
|
|
203
|
-
if (n.type === "text" && typeof n.text === "string") out.push(n.text);
|
|
204
|
-
else if (n.type === "hardBreak") out.push(" ");
|
|
205
|
-
if (n.type === "toggleBlock" && typeof n.attrs?.summary === "string") out.push(` ${n.attrs.summary} `);
|
|
206
|
-
for (const c of n.content ?? []) walk(c);
|
|
207
|
-
if (BLOCKS.has(n.type)) out.push(" ");
|
|
208
|
-
};
|
|
209
|
-
walk(content);
|
|
210
|
-
return out.join("").replace(/\s+/g, " ").trim();
|
|
211
|
-
}
|
|
212
|
-
function wordCount(content) {
|
|
213
|
-
const t = plainText(content);
|
|
214
|
-
return t ? t.split(" ").length : 0;
|
|
215
|
-
}
|
|
216
|
-
function pageLinksIn(content) {
|
|
217
|
-
const seen = /* @__PURE__ */ new Set();
|
|
218
|
-
const walk = (n) => {
|
|
219
|
-
if (!n) return;
|
|
220
|
-
for (const m of n.marks ?? []) {
|
|
221
|
-
const id = m.type === "wikiLink" ? m.attrs?.pageId : null;
|
|
222
|
-
if (typeof id === "string" && id) seen.add(id.toLowerCase());
|
|
223
|
-
}
|
|
224
|
-
for (const c of n.content ?? []) walk(c);
|
|
225
|
-
};
|
|
226
|
-
walk(content);
|
|
227
|
-
return [...seen];
|
|
228
|
-
}
|
|
229
|
-
function nodeTypesIn(content) {
|
|
230
|
-
const seen = /* @__PURE__ */ new Set();
|
|
231
|
-
const walk = (n) => {
|
|
232
|
-
if (!n) return;
|
|
233
|
-
seen.add(n.type);
|
|
234
|
-
for (const m of n.marks ?? []) seen.add(`mark:${m.type}`);
|
|
235
|
-
for (const c of n.content ?? []) walk(c);
|
|
236
|
-
};
|
|
237
|
-
walk(content);
|
|
238
|
-
return seen;
|
|
239
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
SAFE_LINK
|
|
3
|
+
} from "./chunk-MDNEMOZD.js";
|
|
240
4
|
|
|
241
5
|
// src/docs/document/markdown.ts
|
|
242
6
|
var PAGE_LINK = /^xeno-doc:([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
@@ -578,23 +342,6 @@ function parseInlineMarkdown(text) {
|
|
|
578
342
|
}
|
|
579
343
|
|
|
580
344
|
export {
|
|
581
|
-
XDOC_FORMAT,
|
|
582
|
-
XDOC_VERSION,
|
|
583
|
-
XDOC_EXTENSION,
|
|
584
|
-
DOCUMENT_NODE_TYPES,
|
|
585
|
-
DOCUMENT_MARK_TYPES,
|
|
586
|
-
SAFE_LINK,
|
|
587
|
-
SAFE_IMAGE,
|
|
588
|
-
LIMITS,
|
|
589
|
-
validateContent,
|
|
590
|
-
XdocError,
|
|
591
|
-
emptyContent,
|
|
592
|
-
parseXdoc,
|
|
593
|
-
serializeXdoc,
|
|
594
|
-
plainText,
|
|
595
|
-
wordCount,
|
|
596
|
-
pageLinksIn,
|
|
597
|
-
nodeTypesIn,
|
|
598
345
|
documentToMarkdown,
|
|
599
346
|
markdownToDocument
|
|
600
347
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDocumentExtensions
|
|
3
|
+
} from "./chunk-KC2QBI2I.js";
|
|
1
4
|
import {
|
|
2
5
|
DOCUMENT_MARK_TYPES,
|
|
3
6
|
DOCUMENT_NODE_TYPES,
|
|
4
|
-
SAFE_IMAGE,
|
|
5
7
|
SAFE_LINK,
|
|
6
8
|
XdocError,
|
|
7
9
|
emptyContent,
|
|
@@ -12,308 +14,7 @@ import {
|
|
|
12
14
|
serializeXdoc,
|
|
13
15
|
validateContent,
|
|
14
16
|
wordCount
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
|
|
17
|
-
// src/docs/document/extensions/Callout.ts
|
|
18
|
-
import { Node, mergeAttributes } from "@tiptap/core";
|
|
19
|
-
var Callout = Node.create({
|
|
20
|
-
name: "callout",
|
|
21
|
-
group: "block",
|
|
22
|
-
content: "block+",
|
|
23
|
-
defining: true,
|
|
24
|
-
addAttributes() {
|
|
25
|
-
return {
|
|
26
|
-
type: {
|
|
27
|
-
default: "info",
|
|
28
|
-
parseHTML: (element) => element.getAttribute("data-callout-type") || "info",
|
|
29
|
-
renderHTML: (attributes) => ({
|
|
30
|
-
"data-callout-type": attributes.type
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
parseHTML() {
|
|
36
|
-
return [
|
|
37
|
-
{ tag: "div[data-callout-type]" },
|
|
38
|
-
{ tag: "div.callout" }
|
|
39
|
-
];
|
|
40
|
-
},
|
|
41
|
-
renderHTML({ HTMLAttributes }) {
|
|
42
|
-
const type = HTMLAttributes["data-callout-type"] || "info";
|
|
43
|
-
return [
|
|
44
|
-
"div",
|
|
45
|
-
mergeAttributes(HTMLAttributes, {
|
|
46
|
-
class: `callout ${type}`,
|
|
47
|
-
"data-callout-type": type
|
|
48
|
-
}),
|
|
49
|
-
0
|
|
50
|
-
];
|
|
51
|
-
},
|
|
52
|
-
addCommands() {
|
|
53
|
-
return {
|
|
54
|
-
setCallout: (attrs) => ({ commands }) => {
|
|
55
|
-
return commands.wrapIn(this.name, attrs);
|
|
56
|
-
},
|
|
57
|
-
toggleCallout: (attrs) => ({ commands }) => {
|
|
58
|
-
return commands.toggleWrap(this.name, attrs);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// src/docs/document/extensions/ToggleBlock.ts
|
|
65
|
-
import { Node as Node2, mergeAttributes as mergeAttributes2 } from "@tiptap/core";
|
|
66
|
-
var ToggleBlock = Node2.create({
|
|
67
|
-
name: "toggleBlock",
|
|
68
|
-
group: "block",
|
|
69
|
-
content: "block+",
|
|
70
|
-
defining: true,
|
|
71
|
-
addAttributes() {
|
|
72
|
-
return {
|
|
73
|
-
open: {
|
|
74
|
-
default: true,
|
|
75
|
-
parseHTML: (element) => element.getAttribute("data-open") !== "false",
|
|
76
|
-
renderHTML: (attributes) => ({
|
|
77
|
-
"data-open": String(attributes.open)
|
|
78
|
-
})
|
|
79
|
-
},
|
|
80
|
-
summary: {
|
|
81
|
-
default: "Toggle",
|
|
82
|
-
parseHTML: (element) => element.getAttribute("data-summary") || "Toggle",
|
|
83
|
-
renderHTML: (attributes) => ({
|
|
84
|
-
"data-summary": attributes.summary
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
parseHTML() {
|
|
90
|
-
return [
|
|
91
|
-
{ tag: "div[data-toggle-block]" },
|
|
92
|
-
{
|
|
93
|
-
tag: "details",
|
|
94
|
-
getAttrs: (element) => ({
|
|
95
|
-
open: element.hasAttribute("open"),
|
|
96
|
-
summary: element.querySelector("summary")?.textContent || "Toggle"
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
];
|
|
100
|
-
},
|
|
101
|
-
renderHTML({ HTMLAttributes }) {
|
|
102
|
-
return [
|
|
103
|
-
"details",
|
|
104
|
-
mergeAttributes2(HTMLAttributes, {
|
|
105
|
-
"data-toggle-block": "true",
|
|
106
|
-
...HTMLAttributes["data-open"] === "true" ? { open: "open" } : {}
|
|
107
|
-
}),
|
|
108
|
-
["summary", {}, HTMLAttributes["data-summary"] || "Toggle"],
|
|
109
|
-
["div", { class: "toggle-content" }, 0]
|
|
110
|
-
];
|
|
111
|
-
},
|
|
112
|
-
addCommands() {
|
|
113
|
-
return {
|
|
114
|
-
setToggleBlock: () => ({ commands }) => {
|
|
115
|
-
return commands.insertContent({
|
|
116
|
-
type: this.name,
|
|
117
|
-
attrs: { summary: "Click to expand", open: true },
|
|
118
|
-
content: [{ type: "paragraph", content: [{ type: "text", text: "Content here..." }] }]
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// src/docs/document/extensions/PageBreak.ts
|
|
126
|
-
import { Node as Node3, mergeAttributes as mergeAttributes3 } from "@tiptap/core";
|
|
127
|
-
var PageBreak = Node3.create({
|
|
128
|
-
name: "pageBreak",
|
|
129
|
-
group: "block",
|
|
130
|
-
atom: true,
|
|
131
|
-
selectable: true,
|
|
132
|
-
draggable: false,
|
|
133
|
-
parseHTML() {
|
|
134
|
-
return [
|
|
135
|
-
{ tag: "div[data-page-break]" },
|
|
136
|
-
{
|
|
137
|
-
tag: "div",
|
|
138
|
-
getAttrs: (element) => element.style.pageBreakAfter === "always" ? {} : false
|
|
139
|
-
}
|
|
140
|
-
];
|
|
141
|
-
},
|
|
142
|
-
renderHTML({ HTMLAttributes }) {
|
|
143
|
-
return [
|
|
144
|
-
"div",
|
|
145
|
-
mergeAttributes3(HTMLAttributes, {
|
|
146
|
-
"data-page-break": "true",
|
|
147
|
-
class: "page-break",
|
|
148
|
-
contenteditable: "false",
|
|
149
|
-
style: "page-break-after: always;"
|
|
150
|
-
}),
|
|
151
|
-
["div", { class: "page-break-rule" }],
|
|
152
|
-
["span", { class: "page-break-label" }, "Page Break"],
|
|
153
|
-
["div", { class: "page-break-rule" }]
|
|
154
|
-
];
|
|
155
|
-
},
|
|
156
|
-
addCommands() {
|
|
157
|
-
return {
|
|
158
|
-
setPageBreak: () => ({ commands }) => {
|
|
159
|
-
return commands.insertContent({ type: this.name });
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
addKeyboardShortcuts() {
|
|
164
|
-
return {
|
|
165
|
-
"Mod-Enter": () => this.editor.commands.setPageBreak()
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// src/docs/document/extensions/WikiLink.ts
|
|
171
|
-
import { Mark, mergeAttributes as mergeAttributes4 } from "@tiptap/core";
|
|
172
|
-
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
173
|
-
var WikiLinkMark = Mark.create({
|
|
174
|
-
name: "wikiLink",
|
|
175
|
-
priority: 1e3,
|
|
176
|
-
addOptions() {
|
|
177
|
-
return {
|
|
178
|
-
onClickLink: () => {
|
|
179
|
-
},
|
|
180
|
-
HTMLAttributes: {
|
|
181
|
-
class: "wiki-link"
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
},
|
|
185
|
-
addAttributes() {
|
|
186
|
-
return {
|
|
187
|
-
pageId: {
|
|
188
|
-
default: null,
|
|
189
|
-
parseHTML: (element) => element.getAttribute("data-page-id"),
|
|
190
|
-
renderHTML: (attributes) => ({
|
|
191
|
-
"data-page-id": attributes.pageId
|
|
192
|
-
})
|
|
193
|
-
},
|
|
194
|
-
pageTitle: {
|
|
195
|
-
default: "",
|
|
196
|
-
parseHTML: (element) => element.getAttribute("data-page-title"),
|
|
197
|
-
renderHTML: (attributes) => ({
|
|
198
|
-
"data-page-title": attributes.pageTitle
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
},
|
|
203
|
-
parseHTML() {
|
|
204
|
-
return [
|
|
205
|
-
{
|
|
206
|
-
tag: "span[data-wiki-link]"
|
|
207
|
-
}
|
|
208
|
-
];
|
|
209
|
-
},
|
|
210
|
-
renderHTML({ HTMLAttributes }) {
|
|
211
|
-
return [
|
|
212
|
-
"span",
|
|
213
|
-
mergeAttributes4(
|
|
214
|
-
this.options.HTMLAttributes,
|
|
215
|
-
HTMLAttributes,
|
|
216
|
-
{ "data-wiki-link": "" }
|
|
217
|
-
),
|
|
218
|
-
0
|
|
219
|
-
];
|
|
220
|
-
},
|
|
221
|
-
addCommands() {
|
|
222
|
-
return {
|
|
223
|
-
setWikiLink: (attrs) => ({ commands }) => {
|
|
224
|
-
return commands.setMark(this.name, attrs);
|
|
225
|
-
},
|
|
226
|
-
unsetWikiLink: () => ({ commands }) => {
|
|
227
|
-
return commands.unsetMark(this.name);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
},
|
|
231
|
-
addProseMirrorPlugins() {
|
|
232
|
-
const { onClickLink } = this.options;
|
|
233
|
-
return [
|
|
234
|
-
new Plugin({
|
|
235
|
-
key: new PluginKey("wikiLinkClick"),
|
|
236
|
-
props: {
|
|
237
|
-
handleClick(view, pos) {
|
|
238
|
-
const { state } = view;
|
|
239
|
-
const $pos = state.doc.resolve(pos);
|
|
240
|
-
const marks = $pos.marks();
|
|
241
|
-
for (const mark of marks) {
|
|
242
|
-
if (mark.type.name === "wikiLink") {
|
|
243
|
-
const { pageId, pageTitle } = mark.attrs;
|
|
244
|
-
if (pageId || pageTitle) {
|
|
245
|
-
onClickLink(pageId || "", pageTitle || "");
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
];
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// src/docs/document/schema.ts
|
|
259
|
-
import StarterKit from "@tiptap/starter-kit";
|
|
260
|
-
import Underline from "@tiptap/extension-underline";
|
|
261
|
-
import TextAlign from "@tiptap/extension-text-align";
|
|
262
|
-
import Placeholder from "@tiptap/extension-placeholder";
|
|
263
|
-
import TaskList from "@tiptap/extension-task-list";
|
|
264
|
-
import TaskItem from "@tiptap/extension-task-item";
|
|
265
|
-
import Table from "@tiptap/extension-table";
|
|
266
|
-
import TableRow from "@tiptap/extension-table-row";
|
|
267
|
-
import TableCell from "@tiptap/extension-table-cell";
|
|
268
|
-
import TableHeader from "@tiptap/extension-table-header";
|
|
269
|
-
import Image from "@tiptap/extension-image";
|
|
270
|
-
import Link from "@tiptap/extension-link";
|
|
271
|
-
import Subscript from "@tiptap/extension-subscript";
|
|
272
|
-
import Superscript from "@tiptap/extension-superscript";
|
|
273
|
-
import Highlight from "@tiptap/extension-highlight";
|
|
274
|
-
import Typography from "@tiptap/extension-typography";
|
|
275
|
-
var SafeImage = Image.extend({
|
|
276
|
-
parseHTML() {
|
|
277
|
-
return [{ tag: "img[src]", getAttrs: (el) => SAFE_IMAGE.test(el.getAttribute("src") ?? "") ? null : false }];
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
function createDocumentExtensions(options = {}) {
|
|
281
|
-
const list = [
|
|
282
|
-
StarterKit.configure({
|
|
283
|
-
...options.codeBlock ? { codeBlock: false } : {},
|
|
284
|
-
heading: { levels: [1, 2, 3, 4, 5, 6] },
|
|
285
|
-
...options.history === false ? { history: false } : {}
|
|
286
|
-
}),
|
|
287
|
-
Underline,
|
|
288
|
-
TextAlign.configure({ types: ["heading", "paragraph"] }),
|
|
289
|
-
Placeholder.configure({ placeholder: options.placeholder ?? 'Start writing, or press "/" for commands...' }),
|
|
290
|
-
TaskList,
|
|
291
|
-
TaskItem.configure({ nested: true }),
|
|
292
|
-
Table.configure({ resizable: options.resizableTables ?? false }),
|
|
293
|
-
TableRow,
|
|
294
|
-
TableCell,
|
|
295
|
-
TableHeader,
|
|
296
|
-
SafeImage.configure({ inline: false }),
|
|
297
|
-
Link.configure({
|
|
298
|
-
openOnClick: false,
|
|
299
|
-
autolink: true,
|
|
300
|
-
HTMLAttributes: { rel: "noopener noreferrer nofollow", target: "_blank" },
|
|
301
|
-
// the format refuses anything else; the editor must not be able to produce what the format refuses
|
|
302
|
-
isAllowedUri: (url) => SAFE_LINK.test(String(url).trim())
|
|
303
|
-
}),
|
|
304
|
-
Subscript,
|
|
305
|
-
Superscript,
|
|
306
|
-
Highlight.configure({ multicolor: true }),
|
|
307
|
-
Typography,
|
|
308
|
-
Callout,
|
|
309
|
-
ToggleBlock,
|
|
310
|
-
PageBreak,
|
|
311
|
-
WikiLinkMark.configure({ onClickLink: options.onOpenPage ?? (() => {
|
|
312
|
-
}) })
|
|
313
|
-
];
|
|
314
|
-
if (options.codeBlock) list.push(options.codeBlock);
|
|
315
|
-
return list;
|
|
316
|
-
}
|
|
17
|
+
} from "./chunk-MDNEMOZD.js";
|
|
317
18
|
|
|
318
19
|
// src/docs/document/surface.ts
|
|
319
20
|
import { Editor } from "@tiptap/core";
|
|
@@ -396,11 +97,12 @@ var ACTIVE = {
|
|
|
396
97
|
toggle: ["toggleBlock"],
|
|
397
98
|
link: ["link"]
|
|
398
99
|
};
|
|
399
|
-
function editorHandle(editor, promptLink) {
|
|
100
|
+
function editorHandle(editor, promptLink, shared = false) {
|
|
400
101
|
return {
|
|
401
102
|
getJSON: () => editor.getJSON(),
|
|
103
|
+
// a shared document is changed only by edits: a host seeds or replaces it through the collaboration module
|
|
402
104
|
setContent: (content) => {
|
|
403
|
-
editor.commands.setContent(content, false);
|
|
105
|
+
if (!shared) editor.commands.setContent(content, false);
|
|
404
106
|
},
|
|
405
107
|
setEditable: (editable) => editor.setEditable(editable),
|
|
406
108
|
focus: () => {
|
|
@@ -429,7 +131,7 @@ function mountDocumentSurface(element, controller, options = {}) {
|
|
|
429
131
|
const editor = new Editor({
|
|
430
132
|
element,
|
|
431
133
|
extensions: [...createDocumentExtensions({ ...options, onOpenPage: (id, title) => controller.openPage(id, title) }), ...options.extensions ?? []],
|
|
432
|
-
content: state.unsupported.length || state.status === "unsupported" ? "" : state.content,
|
|
134
|
+
content: options.shared || state.unsupported.length || state.status === "unsupported" ? "" : state.content,
|
|
433
135
|
editable: !state.readOnly,
|
|
434
136
|
editorProps: {
|
|
435
137
|
attributes: {
|
|
@@ -443,7 +145,7 @@ function mountDocumentSurface(element, controller, options = {}) {
|
|
|
443
145
|
onUpdate: () => controller.contentChanged(),
|
|
444
146
|
onSelectionUpdate: () => controller.selectionChanged()
|
|
445
147
|
});
|
|
446
|
-
const unbind = controller.attach(editorHandle(editor, options.promptLink));
|
|
148
|
+
const unbind = controller.attach(editorHandle(editor, options.promptLink, !!options.shared));
|
|
447
149
|
return () => {
|
|
448
150
|
unbind();
|
|
449
151
|
editor.destroy();
|
|
@@ -673,12 +375,6 @@ var DocumentController = class {
|
|
|
673
375
|
};
|
|
674
376
|
|
|
675
377
|
export {
|
|
676
|
-
Callout,
|
|
677
|
-
ToggleBlock,
|
|
678
|
-
PageBreak,
|
|
679
|
-
WikiLinkMark,
|
|
680
|
-
SafeImage,
|
|
681
|
-
createDocumentExtensions,
|
|
682
378
|
runFormat,
|
|
683
379
|
editorHandle,
|
|
684
380
|
mountDocumentSurface,
|