@quickbuilder.io/rich-text 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +122 -2
- package/adapters.d.ts +1 -0
- package/adapters.js +1 -0
- package/collaboration.d.ts +1 -0
- package/collaboration.js +1 -0
- package/commands.d.ts +1 -0
- package/commands.js +1 -0
- package/content.d.ts +1 -0
- package/content.js +1 -0
- package/contracts.d.ts +1 -0
- package/contracts.js +1 -0
- package/dist/adapters.d.mts +11 -0
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +564 -0
- package/dist/adapters.js.map +1 -0
- package/dist/adapters.mjs +557 -0
- package/dist/adapters.mjs.map +1 -0
- package/dist/collaboration.d.mts +29 -0
- package/dist/collaboration.d.ts +29 -0
- package/dist/collaboration.js +758 -0
- package/dist/collaboration.js.map +1 -0
- package/dist/collaboration.mjs +733 -0
- package/dist/collaboration.mjs.map +1 -0
- package/dist/commands.d.mts +8 -0
- package/dist/commands.d.ts +8 -0
- package/dist/commands.js +42 -0
- package/dist/commands.js.map +1 -0
- package/dist/commands.mjs +38 -0
- package/dist/commands.mjs.map +1 -0
- package/dist/content-types-CYHsrMrs.d.mts +27 -0
- package/dist/content-types-CYHsrMrs.d.ts +27 -0
- package/dist/content.d.mts +19 -0
- package/dist/content.d.ts +19 -0
- package/dist/content.js +785 -0
- package/dist/content.js.map +1 -0
- package/dist/content.mjs +775 -0
- package/dist/content.mjs.map +1 -0
- package/dist/contracts.d.mts +199 -0
- package/dist/contracts.d.ts +199 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +1 -0
- package/dist/contracts.mjs +3 -0
- package/dist/contracts.mjs.map +1 -0
- package/dist/extensions.d.mts +363 -0
- package/dist/extensions.d.ts +363 -0
- package/dist/extensions.js +153 -0
- package/dist/extensions.js.map +1 -0
- package/dist/extensions.mjs +142 -0
- package/dist/extensions.mjs.map +1 -0
- package/dist/history.d.mts +12 -0
- package/dist/history.d.ts +12 -0
- package/dist/history.js +464 -0
- package/dist/history.js.map +1 -0
- package/dist/history.mjs +459 -0
- package/dist/history.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1438 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1372 -0
- package/dist/index.mjs.map +1 -0
- package/dist/markdown.d.mts +32 -0
- package/dist/markdown.d.ts +32 -0
- package/dist/markdown.js +739 -0
- package/dist/markdown.js.map +1 -0
- package/dist/markdown.mjs +735 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/runtime/dom.d.mts +148 -0
- package/dist/runtime/dom.d.ts +148 -0
- package/dist/runtime/dom.js +2145 -0
- package/dist/runtime/dom.js.map +1 -0
- package/dist/runtime/dom.mjs +2084 -0
- package/dist/runtime/dom.mjs.map +1 -0
- package/dist/schema.d.mts +23 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.js +157 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +137 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/serializer.d.mts +38 -0
- package/dist/serializer.d.ts +38 -0
- package/dist/serializer.js +504 -0
- package/dist/serializer.js.map +1 -0
- package/dist/serializer.mjs +491 -0
- package/dist/serializer.mjs.map +1 -0
- package/dist/svg-export-BtI8x_mG.d.mts +15 -0
- package/dist/svg-export-BtI8x_mG.d.ts +15 -0
- package/dist/transactions.d.mts +16 -0
- package/dist/transactions.d.ts +16 -0
- package/dist/transactions.js +637 -0
- package/dist/transactions.js.map +1 -0
- package/dist/transactions.mjs +631 -0
- package/dist/transactions.mjs.map +1 -0
- package/extensions.d.ts +1 -0
- package/extensions.js +1 -0
- package/history.d.ts +1 -0
- package/history.js +1 -0
- package/package.json +352 -4
- package/schema.d.ts +1 -0
- package/schema.js +1 -0
- package/serializer.d.ts +1 -0
- package/serializer.js +1 -0
- package/transactions.d.ts +1 -0
- package/transactions.js +1 -0
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/schema.ts
|
|
4
|
+
var QUICK_BUILDER_RICH_TEXT_SCHEMA_VERSION = 2;
|
|
5
|
+
var richTextAllowedTags = [
|
|
6
|
+
"a",
|
|
7
|
+
"b",
|
|
8
|
+
"blockquote",
|
|
9
|
+
"br",
|
|
10
|
+
"code",
|
|
11
|
+
"em",
|
|
12
|
+
"h1",
|
|
13
|
+
"h2",
|
|
14
|
+
"h3",
|
|
15
|
+
"h4",
|
|
16
|
+
"h5",
|
|
17
|
+
"h6",
|
|
18
|
+
"hr",
|
|
19
|
+
"i",
|
|
20
|
+
"img",
|
|
21
|
+
"input",
|
|
22
|
+
"label",
|
|
23
|
+
"li",
|
|
24
|
+
"mark",
|
|
25
|
+
"ol",
|
|
26
|
+
"p",
|
|
27
|
+
"pre",
|
|
28
|
+
"qb-video",
|
|
29
|
+
"s",
|
|
30
|
+
"span",
|
|
31
|
+
"sub",
|
|
32
|
+
"sup",
|
|
33
|
+
"strong",
|
|
34
|
+
"table",
|
|
35
|
+
"tbody",
|
|
36
|
+
"td",
|
|
37
|
+
"tfoot",
|
|
38
|
+
"th",
|
|
39
|
+
"thead",
|
|
40
|
+
"tr",
|
|
41
|
+
"u",
|
|
42
|
+
"ul"
|
|
43
|
+
];
|
|
44
|
+
var richTextVoidTags = ["br", "hr", "img", "input"];
|
|
45
|
+
var richTextAllowedTargets = ["_blank", "_self", "_parent", "_top"];
|
|
46
|
+
var richTextAlignmentTags = [
|
|
47
|
+
"blockquote",
|
|
48
|
+
"h1",
|
|
49
|
+
"h2",
|
|
50
|
+
"h3",
|
|
51
|
+
"h4",
|
|
52
|
+
"h5",
|
|
53
|
+
"h6",
|
|
54
|
+
"li",
|
|
55
|
+
"ol",
|
|
56
|
+
"p",
|
|
57
|
+
"pre",
|
|
58
|
+
"td",
|
|
59
|
+
"th",
|
|
60
|
+
"ul"
|
|
61
|
+
];
|
|
62
|
+
var richTextAllowedAlignments = ["left", "center", "right", "justify"];
|
|
63
|
+
var richTextAllowedFontFamilies = [
|
|
64
|
+
"default",
|
|
65
|
+
"carlito",
|
|
66
|
+
"source-sans-3",
|
|
67
|
+
"noto-sans",
|
|
68
|
+
"arimo",
|
|
69
|
+
"tinos",
|
|
70
|
+
"cousine"
|
|
71
|
+
];
|
|
72
|
+
var richTextAllowedFontSizes = [
|
|
73
|
+
"default",
|
|
74
|
+
"8",
|
|
75
|
+
"9",
|
|
76
|
+
"10",
|
|
77
|
+
"11",
|
|
78
|
+
"12",
|
|
79
|
+
"14",
|
|
80
|
+
"16",
|
|
81
|
+
"18",
|
|
82
|
+
"24",
|
|
83
|
+
"30",
|
|
84
|
+
"36",
|
|
85
|
+
"48",
|
|
86
|
+
"60",
|
|
87
|
+
"72",
|
|
88
|
+
"96"
|
|
89
|
+
];
|
|
90
|
+
var richTextAllowedLineHeights = ["1", "1.15", "1.5", "2"];
|
|
91
|
+
var richTextAllowedColors = [
|
|
92
|
+
"default",
|
|
93
|
+
"gray",
|
|
94
|
+
"brown",
|
|
95
|
+
"orange",
|
|
96
|
+
"yellow",
|
|
97
|
+
"green",
|
|
98
|
+
"blue",
|
|
99
|
+
"purple",
|
|
100
|
+
"pink",
|
|
101
|
+
"red"
|
|
102
|
+
];
|
|
103
|
+
function isRichTextAlignment(value) {
|
|
104
|
+
return richTextAllowedAlignments.includes(value);
|
|
105
|
+
}
|
|
106
|
+
function isRichTextFontFamily(value) {
|
|
107
|
+
return richTextAllowedFontFamilies.includes(value);
|
|
108
|
+
}
|
|
109
|
+
function isRichTextFontSize(value) {
|
|
110
|
+
return richTextAllowedFontSizes.includes(value);
|
|
111
|
+
}
|
|
112
|
+
function isRichTextLineHeight(value) {
|
|
113
|
+
return richTextAllowedLineHeights.includes(value);
|
|
114
|
+
}
|
|
115
|
+
function isRichTextColor(value) {
|
|
116
|
+
return richTextAllowedColors.includes(value);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/entities.ts
|
|
120
|
+
var entities = {
|
|
121
|
+
amp: "&",
|
|
122
|
+
lt: "<",
|
|
123
|
+
gt: ">",
|
|
124
|
+
quot: '"',
|
|
125
|
+
apos: "'",
|
|
126
|
+
nbsp: "\xA0",
|
|
127
|
+
copy: "\xA9",
|
|
128
|
+
reg: "\xAE",
|
|
129
|
+
trade: "\u2122",
|
|
130
|
+
mdash: "\u2014",
|
|
131
|
+
ndash: "\u2013",
|
|
132
|
+
hellip: "\u2026",
|
|
133
|
+
lsquo: "\u2018",
|
|
134
|
+
rsquo: "\u2019",
|
|
135
|
+
ldquo: "\u201C",
|
|
136
|
+
rdquo: "\u201D",
|
|
137
|
+
bull: "\u2022",
|
|
138
|
+
middot: "\xB7"
|
|
139
|
+
};
|
|
140
|
+
function decodeRichTextEntities(value) {
|
|
141
|
+
return value.replace(
|
|
142
|
+
/&(#x[\da-f]+|#\d+|[a-z][a-z\d]+);/gi,
|
|
143
|
+
(original, entity) => {
|
|
144
|
+
if (!entity.startsWith("#")) {
|
|
145
|
+
const decoded = entities[entity];
|
|
146
|
+
if (decoded === void 0)
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Unsupported named rich-text entity ${original}; use Unicode or a numeric entity`
|
|
149
|
+
);
|
|
150
|
+
return decoded;
|
|
151
|
+
}
|
|
152
|
+
const point = entity[1]?.toLowerCase() === "x" ? Number.parseInt(entity.slice(2), 16) : Number(entity.slice(1));
|
|
153
|
+
if (point < 1 || point > 1114111 || point >= 55296 && point <= 57343)
|
|
154
|
+
throw new Error("Invalid rich-text character entity");
|
|
155
|
+
return String.fromCodePoint(point);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/serializer.ts
|
|
161
|
+
var ACTIVE_CONTENT_TAG_PATTERN = /<\s*(script|style|iframe|object|embed|form)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi;
|
|
162
|
+
var ACTIVE_VOID_TAG_PATTERN = /<\s*(?:script|style|iframe|object|embed|link|meta|base)\b[^>]*\/?\s*>/gi;
|
|
163
|
+
var RICH_TEXT_VIDEO_PATTERN = /<qb-video\b((?:"[^"]*"|'[^']*'|[^'">])*)>[\s\S]*?<\/qb-video>/gi;
|
|
164
|
+
var RICH_TEXT_TAG_PATTERN = /<qb-video\b((?:"[^"]*"|'[^']*'|[^'">])*)>[\s\S]*?<\/qb-video>|<\/?([a-z][a-z0-9-]*)\b((?:"[^"]*"|'[^']*'|[^'">])*)>/gi;
|
|
165
|
+
var ATTRIBUTE_VALUE_PATTERN = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g;
|
|
166
|
+
var allowedTagSet = new Set(richTextAllowedTags);
|
|
167
|
+
var voidTagSet = new Set(richTextVoidTags);
|
|
168
|
+
var allowedTargetSet = new Set(richTextAllowedTargets);
|
|
169
|
+
var alignmentTagSet = new Set(richTextAlignmentTags);
|
|
170
|
+
var richTextMaximumUrlLength = 4096;
|
|
171
|
+
function validateRichTextVideo(src, title) {
|
|
172
|
+
src = src.trim();
|
|
173
|
+
title = title.trim();
|
|
174
|
+
if (!src || src.length > 2048 || !title || title.length > 200 || /[\u0000-\u0020\u007f\\]/u.test(src)) return;
|
|
175
|
+
const relative = /^\/(?!\/)/u.test(src);
|
|
176
|
+
if (!relative && !src.startsWith("https://")) return;
|
|
177
|
+
try {
|
|
178
|
+
const url = new URL(src, "https://rich-text.invalid");
|
|
179
|
+
if (url.protocol !== "https:" || url.username || url.password) return;
|
|
180
|
+
return { src, title };
|
|
181
|
+
} catch {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function readVideoAttributes(raw) {
|
|
186
|
+
const attributes = readHtmlAttributes(raw);
|
|
187
|
+
return validateRichTextVideo(attributes.get("data-src") ?? "", attributes.get("data-title") ?? "");
|
|
188
|
+
}
|
|
189
|
+
function sanitizeRichTextMarkup(value, options = {}) {
|
|
190
|
+
if (options.resolveImageSource !== void 0 && typeof options.resolveImageSource !== "function")
|
|
191
|
+
throw new TypeError("Invalid rich text image resolver.");
|
|
192
|
+
if (options.allowVideos !== void 0 && typeof options.allowVideos !== "boolean")
|
|
193
|
+
throw new TypeError("Invalid rich text video policy.");
|
|
194
|
+
if (options.videoPresentation !== void 0 && !["embed", "link"].includes(options.videoPresentation))
|
|
195
|
+
throw new TypeError("Invalid rich text video presentation.");
|
|
196
|
+
if (options.allowContentIdImages !== void 0 && typeof options.allowContentIdImages !== "boolean")
|
|
197
|
+
throw new TypeError("Invalid rich text Content-ID image policy.");
|
|
198
|
+
if (options.imageCrossOrigin !== void 0 && options.imageCrossOrigin !== "anonymous" && typeof options.imageCrossOrigin !== "function")
|
|
199
|
+
throw new TypeError("Invalid rich text image credentials policy.");
|
|
200
|
+
return sanitizeMarkup(value, options);
|
|
201
|
+
}
|
|
202
|
+
function sanitizeMarkup(value, options = {}) {
|
|
203
|
+
return value.replace(ACTIVE_CONTENT_TAG_PATTERN, "").replace(ACTIVE_VOID_TAG_PATTERN, "").replace(RICH_TEXT_TAG_PATTERN, (match, rawVideo, rawTagName, rawAttributes) => {
|
|
204
|
+
if (rawVideo !== void 0) {
|
|
205
|
+
if (options.allowVideos === false) return "";
|
|
206
|
+
const video = readVideoAttributes(rawVideo);
|
|
207
|
+
if (!video) return "";
|
|
208
|
+
if (options.videoPresentation === "link") {
|
|
209
|
+
return withBlockIdentity("<p>", rawVideo) + `<br><a href="${escapeHtmlAttribute(video.src)}">${escapeHtmlAttribute(video.title)}</a></p>`;
|
|
210
|
+
}
|
|
211
|
+
return withBlockIdentity(`<qb-video data-src="${escapeHtmlAttribute(video.src)}" data-title="${escapeHtmlAttribute(video.title)}" contenteditable="false">`, rawVideo) + "</qb-video>";
|
|
212
|
+
}
|
|
213
|
+
const tagName = rawTagName.toLowerCase();
|
|
214
|
+
if (tagName === "qb-video") return "";
|
|
215
|
+
if (!allowedTagSet.has(tagName)) {
|
|
216
|
+
return "";
|
|
217
|
+
}
|
|
218
|
+
if (match.startsWith("</")) {
|
|
219
|
+
return voidTagSet.has(tagName) ? "" : `</${tagName}>`;
|
|
220
|
+
}
|
|
221
|
+
if (voidTagSet.has(tagName)) {
|
|
222
|
+
if (tagName === "img") {
|
|
223
|
+
return withBlockIdentity(renderSafeImageTag(rawAttributes, options), rawAttributes);
|
|
224
|
+
}
|
|
225
|
+
if (tagName === "input") {
|
|
226
|
+
return withBlockIdentity(renderSafeTaskCheckbox(rawAttributes), rawAttributes);
|
|
227
|
+
}
|
|
228
|
+
return withBlockIdentity(`<${tagName}>`, rawAttributes);
|
|
229
|
+
}
|
|
230
|
+
if (tagName !== "a") {
|
|
231
|
+
return withBlockIdentity(renderSafeRichTextTag(tagName, rawAttributes), rawAttributes);
|
|
232
|
+
}
|
|
233
|
+
return renderSafeAnchorTag(rawAttributes);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function normalizeRichTextHtml(value) {
|
|
237
|
+
const sanitized = sanitizeRichTextMarkup(value);
|
|
238
|
+
return sanitized.trim() ? sanitized : "<p></p>";
|
|
239
|
+
}
|
|
240
|
+
function richTextHtmlToPlainText(html) {
|
|
241
|
+
if (html.length > 1e6) throw new RangeError("Rich text exceeds the serialization limit");
|
|
242
|
+
const text = sanitizeRichTextMarkup(html).replace(RICH_TEXT_VIDEO_PATTERN, (_element, raw) => `
|
|
243
|
+
${escapeHtmlAttribute(readVideoAttributes(raw)?.title ?? "")}
|
|
244
|
+
`).replace(/<!--[\s\S]*?-->/g, "").replace(/<(?:br|hr)\b[^>]*>/gi, "\n").replace(/<\/(?:p|h[1-6]|li|blockquote|pre|tr|table)>/gi, "\n").replace(/<\/(?:td|th)>/gi, " ").replace(/<[^>]*>/g, "");
|
|
245
|
+
return decodeRichTextEntities(text).replace(/\t+\n/g, "\n").trim();
|
|
246
|
+
}
|
|
247
|
+
function withBlockIdentity(tag, rawAttributes) {
|
|
248
|
+
const id = readHtmlAttributes(rawAttributes).get("data-qb-block-id");
|
|
249
|
+
if (!tag || tag.startsWith("<span") || !id || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(id)) return tag;
|
|
250
|
+
return tag.replace(/>$/, ` data-qb-block-id="${id}">`);
|
|
251
|
+
}
|
|
252
|
+
function renderSafeRichTextTag(tagName, rawAttributes) {
|
|
253
|
+
if (tagName === "span") {
|
|
254
|
+
return renderSafeSpanTag(rawAttributes);
|
|
255
|
+
}
|
|
256
|
+
if (tagName === "td" || tagName === "th") {
|
|
257
|
+
return renderSafeTableCellTag(tagName, rawAttributes);
|
|
258
|
+
}
|
|
259
|
+
if (tagName === "ul") {
|
|
260
|
+
const attributes2 = readHtmlAttributes(rawAttributes);
|
|
261
|
+
return attributes2.get("data-task-list") === "true" ? '<ul data-task-list="true">' : "<ul>";
|
|
262
|
+
}
|
|
263
|
+
if (tagName === "li") {
|
|
264
|
+
const attributes2 = readHtmlAttributes(rawAttributes);
|
|
265
|
+
const checked = attributes2.get("data-checked");
|
|
266
|
+
return checked === "true" || checked === "false" ? `<li data-checked="${checked}">` : "<li>";
|
|
267
|
+
}
|
|
268
|
+
if (!alignmentTagSet.has(tagName)) {
|
|
269
|
+
return `<${tagName}>`;
|
|
270
|
+
}
|
|
271
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
272
|
+
const renderedAttributes = [];
|
|
273
|
+
const alignment = attributes.get("data-align");
|
|
274
|
+
const lineHeight = attributes.get("data-line-height");
|
|
275
|
+
if (isRichTextAlignment(alignment)) renderedAttributes.push(`data-align="${alignment}"`);
|
|
276
|
+
if (isRichTextLineHeight(lineHeight)) renderedAttributes.push(`data-line-height="${lineHeight}"`);
|
|
277
|
+
return renderedAttributes.length > 0 ? `<${tagName} ${renderedAttributes.join(" ")}>` : `<${tagName}>`;
|
|
278
|
+
}
|
|
279
|
+
function renderSafeSpanTag(rawAttributes) {
|
|
280
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
281
|
+
const renderedAttributes = [];
|
|
282
|
+
const id = normalizeMentionAttribute(attributes.get("data-mention-id"), 128);
|
|
283
|
+
const label = normalizeMentionAttribute(attributes.get("data-mention-label"), 160);
|
|
284
|
+
const fontFamily = attributes.get("data-font-family");
|
|
285
|
+
const fontSize = attributes.get("data-font-size");
|
|
286
|
+
const textColor = attributes.get("data-text-color");
|
|
287
|
+
const highlightColor = attributes.get("data-highlight-color");
|
|
288
|
+
if (id && label) {
|
|
289
|
+
renderedAttributes.push(
|
|
290
|
+
`data-mention-id="${escapeHtmlAttribute(id)}"`,
|
|
291
|
+
`data-mention-label="${escapeHtmlAttribute(label)}"`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
if (isRichTextFontFamily(fontFamily) && fontFamily !== "default") renderedAttributes.push(`data-font-family="${fontFamily}"`);
|
|
295
|
+
if (isRichTextFontSize(fontSize) && fontSize !== "default") renderedAttributes.push(`data-font-size="${fontSize}"`);
|
|
296
|
+
if (isRichTextColor(textColor) && textColor !== "default") renderedAttributes.push(`data-text-color="${textColor}"`);
|
|
297
|
+
if (isRichTextColor(highlightColor) && highlightColor !== "default") renderedAttributes.push(`data-highlight-color="${highlightColor}"`);
|
|
298
|
+
return renderedAttributes.length > 0 ? `<span ${renderedAttributes.join(" ")}>` : "<span>";
|
|
299
|
+
}
|
|
300
|
+
function renderSafeTableCellTag(tagName, rawAttributes) {
|
|
301
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
302
|
+
const renderedAttributes = [];
|
|
303
|
+
const alignment = attributes.get("data-align");
|
|
304
|
+
const colSpan = normalizeTableSpan(attributes.get("colspan"));
|
|
305
|
+
const rowSpan = normalizeTableSpan(attributes.get("rowspan"));
|
|
306
|
+
const scope = attributes.get("scope");
|
|
307
|
+
if (isRichTextAlignment(alignment)) {
|
|
308
|
+
renderedAttributes.push(`data-align="${alignment}"`);
|
|
309
|
+
}
|
|
310
|
+
if (colSpan) {
|
|
311
|
+
renderedAttributes.push(`colspan="${colSpan}"`);
|
|
312
|
+
}
|
|
313
|
+
if (rowSpan) {
|
|
314
|
+
renderedAttributes.push(`rowspan="${rowSpan}"`);
|
|
315
|
+
}
|
|
316
|
+
if (tagName === "th" && scope && ["col", "row", "colgroup", "rowgroup"].includes(scope)) {
|
|
317
|
+
renderedAttributes.push(`scope="${scope}"`);
|
|
318
|
+
}
|
|
319
|
+
return renderedAttributes.length > 0 ? `<${tagName} ${renderedAttributes.join(" ")}>` : `<${tagName}>`;
|
|
320
|
+
}
|
|
321
|
+
function renderSafeAnchorTag(rawAttributes) {
|
|
322
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
323
|
+
const renderedAttributes = [];
|
|
324
|
+
const href = attributes.get("href");
|
|
325
|
+
const target = attributes.get("target");
|
|
326
|
+
if (href && isSafeRichTextHref(href)) {
|
|
327
|
+
renderedAttributes.push(`href="${escapeHtmlAttribute(href)}"`);
|
|
328
|
+
}
|
|
329
|
+
if (target && allowedTargetSet.has(target)) {
|
|
330
|
+
renderedAttributes.push(`target="${target}"`);
|
|
331
|
+
if (target === "_blank") {
|
|
332
|
+
renderedAttributes.push('rel="noopener noreferrer"');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return renderedAttributes.length > 0 ? `<a ${renderedAttributes.join(" ")}>` : "<a>";
|
|
336
|
+
}
|
|
337
|
+
function renderSafeImageTag(rawAttributes, options) {
|
|
338
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
339
|
+
const source = attributes.get("src");
|
|
340
|
+
const resolveSource = options.resolveImageSource;
|
|
341
|
+
if (!source || !resolveSource && !isAllowedImageSource(source, options)) return "";
|
|
342
|
+
const src = resolveSource ? resolveSource(source) : source;
|
|
343
|
+
if (src === null) return "";
|
|
344
|
+
if (!isAllowedImageSource(src, options)) throw new TypeError("Invalid replacement image URL.");
|
|
345
|
+
const renderedAttributes = [
|
|
346
|
+
`src="${escapeHtmlAttribute(src)}"`,
|
|
347
|
+
`alt="${escapeHtmlAttribute(normalizeTextAttribute(attributes.get("alt"), 512) ?? "")}"`
|
|
348
|
+
];
|
|
349
|
+
const title = normalizeTextAttribute(attributes.get("title"), 512);
|
|
350
|
+
const width = normalizeImageDimension(attributes.get("width"));
|
|
351
|
+
const height = normalizeImageDimension(attributes.get("height"));
|
|
352
|
+
if (title) renderedAttributes.push(`title="${escapeHtmlAttribute(title)}"`);
|
|
353
|
+
if (width) renderedAttributes.push(`width="${width}"`);
|
|
354
|
+
if (height) renderedAttributes.push(`height="${height}"`);
|
|
355
|
+
const credentials = typeof options.imageCrossOrigin === "function" ? options.imageCrossOrigin(src) : options.imageCrossOrigin;
|
|
356
|
+
if (credentials !== void 0 && credentials !== "anonymous") throw new TypeError("Invalid resolved image credentials policy.");
|
|
357
|
+
if ((credentials ?? attributes.get("crossorigin")) === "anonymous") renderedAttributes.push('crossorigin="anonymous"');
|
|
358
|
+
renderedAttributes.push('loading="lazy"', 'decoding="async"');
|
|
359
|
+
return `<img ${renderedAttributes.join(" ")}>`;
|
|
360
|
+
}
|
|
361
|
+
function isAllowedImageSource(value, options) {
|
|
362
|
+
if (isSafeRichTextImageSrc(value)) return true;
|
|
363
|
+
if (!options.allowContentIdImages || value.length > richTextMaximumUrlLength || !/^cid:/iu.test(value)) return false;
|
|
364
|
+
try {
|
|
365
|
+
const identity = decodeURIComponent(value.slice(4));
|
|
366
|
+
return identity.length > 0 && identity.length <= 200 && !/[^\u0021-\u007e]|[<>"]/u.test(identity);
|
|
367
|
+
} catch {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function renderSafeTaskCheckbox(rawAttributes) {
|
|
372
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
373
|
+
if (attributes.get("type")?.toLowerCase() !== "checkbox") return "";
|
|
374
|
+
const checked = attributes.get("checked") !== void 0 || /(?:^|\s)checked(?:\s|=|$)/i.test(rawAttributes);
|
|
375
|
+
return `<input type="checkbox"${checked ? ' checked=""' : ""} contenteditable="false">`;
|
|
376
|
+
}
|
|
377
|
+
function readHtmlAttributes(rawAttributes) {
|
|
378
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
379
|
+
for (const match of rawAttributes.matchAll(ATTRIBUTE_VALUE_PATTERN)) {
|
|
380
|
+
const name = match[1]?.toLowerCase();
|
|
381
|
+
const value = match[2] ?? match[3] ?? match[4] ?? "";
|
|
382
|
+
if (name) {
|
|
383
|
+
attributes.set(name, decodeHtmlAttribute(value.trim()));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return attributes;
|
|
387
|
+
}
|
|
388
|
+
function isSafeRichTextHref(value) {
|
|
389
|
+
const trimmed = value.trim();
|
|
390
|
+
if (!trimmed || trimmed.length > richTextMaximumUrlLength || /[\u0000-\u001f\u007f]/.test(trimmed)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
if (trimmed.startsWith("//")) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
if (/^(?:#|\/|\.\/|\.\.\/|\?)/.test(trimmed)) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
const url = new URL(trimmed);
|
|
401
|
+
return ["http:", "https:", "mailto:", "tel:"].includes(url.protocol.toLowerCase());
|
|
402
|
+
} catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function isSafeRichTextImageSrc(value) {
|
|
407
|
+
const trimmed = value.trim();
|
|
408
|
+
if (!trimmed || trimmed.length > richTextMaximumUrlLength || /[\u0000-\u001f\u007f]/.test(trimmed) || trimmed.startsWith("//")) return false;
|
|
409
|
+
if (/^(?:\/|\.\/|\.\.\/)/.test(trimmed)) return true;
|
|
410
|
+
try {
|
|
411
|
+
const url = new URL(trimmed);
|
|
412
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
413
|
+
} catch {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function normalizeTableSpan(value) {
|
|
418
|
+
if (!value || !/^\d{1,3}$/.test(value)) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const numericValue = Number(value);
|
|
422
|
+
return numericValue >= 1 && numericValue <= 100 ? String(numericValue) : null;
|
|
423
|
+
}
|
|
424
|
+
function normalizeMentionAttribute(value, maxLength) {
|
|
425
|
+
const normalized = value?.trim();
|
|
426
|
+
if (!normalized || normalized.length > maxLength || /[<>"'`]/.test(normalized)) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
return normalized;
|
|
430
|
+
}
|
|
431
|
+
function normalizeTextAttribute(value, maxLength) {
|
|
432
|
+
const normalized = value?.trim();
|
|
433
|
+
if (!normalized || normalized.length > maxLength) return null;
|
|
434
|
+
return normalized;
|
|
435
|
+
}
|
|
436
|
+
function normalizeImageDimension(value) {
|
|
437
|
+
if (!value || !/^\d{1,5}$/.test(value)) return null;
|
|
438
|
+
const numericValue = Number(value);
|
|
439
|
+
return numericValue >= 1 && numericValue <= 1e4 ? String(numericValue) : null;
|
|
440
|
+
}
|
|
441
|
+
function escapeHtmlAttribute(value) {
|
|
442
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
443
|
+
}
|
|
444
|
+
function decodeHtmlAttribute(value) {
|
|
445
|
+
return value.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|quot|apos|lt|gt));/gi, (entity, decimal, hexadecimal, named) => {
|
|
446
|
+
if (decimal || hexadecimal) {
|
|
447
|
+
const codePoint = decimal ? Number(decimal) : Number.parseInt(hexadecimal, 16);
|
|
448
|
+
if (!Number.isSafeInteger(codePoint) || codePoint <= 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) {
|
|
449
|
+
return "\uFFFD";
|
|
450
|
+
}
|
|
451
|
+
return String.fromCodePoint(codePoint);
|
|
452
|
+
}
|
|
453
|
+
const namedEntity = {
|
|
454
|
+
amp: "&",
|
|
455
|
+
apos: "'",
|
|
456
|
+
gt: ">",
|
|
457
|
+
lt: "<",
|
|
458
|
+
quot: '"'
|
|
459
|
+
};
|
|
460
|
+
return namedEntity[String(named).toLowerCase()] ?? entity;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/adapters.ts
|
|
465
|
+
var QUICK_BUILDER_RICH_TEXT_FRAMEWORKS = [
|
|
466
|
+
"react",
|
|
467
|
+
"next",
|
|
468
|
+
"vue",
|
|
469
|
+
"nuxt",
|
|
470
|
+
"angular",
|
|
471
|
+
"astro",
|
|
472
|
+
"svelte",
|
|
473
|
+
"solid",
|
|
474
|
+
"qwik",
|
|
475
|
+
"preact",
|
|
476
|
+
"react-native",
|
|
477
|
+
"webcomponents"
|
|
478
|
+
];
|
|
479
|
+
function createRichTextBinding(target, options = {}) {
|
|
480
|
+
const attributes = createRichTextAttributes(options);
|
|
481
|
+
const binding = {
|
|
482
|
+
target,
|
|
483
|
+
attributes
|
|
484
|
+
};
|
|
485
|
+
if (target === "react" || target === "next" || target === "preact") {
|
|
486
|
+
return {
|
|
487
|
+
...binding,
|
|
488
|
+
props: {
|
|
489
|
+
...attributes,
|
|
490
|
+
className: attributes.class,
|
|
491
|
+
contentEditable: attributes["aria-disabled"] !== "true",
|
|
492
|
+
suppressContentEditableWarning: true,
|
|
493
|
+
role: "textbox"
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
if (target === "vue" || target === "nuxt" || target === "svelte" || target === "solid" || target === "qwik" || target === "astro") {
|
|
498
|
+
return {
|
|
499
|
+
...binding,
|
|
500
|
+
binding: {
|
|
501
|
+
attrs: attributes,
|
|
502
|
+
class: attributes.class
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
if (target === "angular") {
|
|
507
|
+
return {
|
|
508
|
+
...binding,
|
|
509
|
+
hostBinding: {
|
|
510
|
+
attributes,
|
|
511
|
+
className: attributes.class
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
return binding;
|
|
516
|
+
}
|
|
517
|
+
function createReactRichTextBinding(options = {}) {
|
|
518
|
+
return createRichTextBinding("react", options);
|
|
519
|
+
}
|
|
520
|
+
function createVueRichTextBinding(options = {}) {
|
|
521
|
+
return createRichTextBinding("vue", options);
|
|
522
|
+
}
|
|
523
|
+
function createSvelteRichTextBinding(options = {}) {
|
|
524
|
+
return createRichTextBinding("svelte", options);
|
|
525
|
+
}
|
|
526
|
+
function createWebcomponentsRichTextBinding(options = {}) {
|
|
527
|
+
return createRichTextBinding("webcomponents", options);
|
|
528
|
+
}
|
|
529
|
+
function createRichTextAttributes(options) {
|
|
530
|
+
const safeHtml = normalizeRichTextHtml(options.value ?? "<p></p>");
|
|
531
|
+
const attributes = {
|
|
532
|
+
"data-qb-rich-text": "",
|
|
533
|
+
"data-qb-rich-text-schema-version": String(options.schemaVersion ?? QUICK_BUILDER_RICH_TEXT_SCHEMA_VERSION),
|
|
534
|
+
"data-qb-rich-text-html": safeHtml,
|
|
535
|
+
"data-qb-rich-text-plain-text": options.plainText ?? richTextHtmlToPlainText(safeHtml),
|
|
536
|
+
role: "textbox",
|
|
537
|
+
"aria-multiline": "true"
|
|
538
|
+
};
|
|
539
|
+
if (options.id) {
|
|
540
|
+
attributes.id = options.id;
|
|
541
|
+
}
|
|
542
|
+
if (options.className) {
|
|
543
|
+
attributes.class = options.className;
|
|
544
|
+
}
|
|
545
|
+
if (options.placeholder) {
|
|
546
|
+
attributes["aria-placeholder"] = options.placeholder;
|
|
547
|
+
}
|
|
548
|
+
if (options.disabled) {
|
|
549
|
+
attributes["aria-disabled"] = "true";
|
|
550
|
+
}
|
|
551
|
+
if (options.editable === false) {
|
|
552
|
+
attributes.contenteditable = "false";
|
|
553
|
+
}
|
|
554
|
+
return attributes;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
exports.QUICK_BUILDER_RICH_TEXT_FRAMEWORKS = QUICK_BUILDER_RICH_TEXT_FRAMEWORKS;
|
|
558
|
+
exports.createReactRichTextBinding = createReactRichTextBinding;
|
|
559
|
+
exports.createRichTextBinding = createRichTextBinding;
|
|
560
|
+
exports.createSvelteRichTextBinding = createSvelteRichTextBinding;
|
|
561
|
+
exports.createVueRichTextBinding = createVueRichTextBinding;
|
|
562
|
+
exports.createWebcomponentsRichTextBinding = createWebcomponentsRichTextBinding;
|
|
563
|
+
//# sourceMappingURL=adapters.js.map
|
|
564
|
+
//# sourceMappingURL=adapters.js.map
|