article-content-renderer-vue2 0.3.0 → 0.3.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/README.md +12 -17
- package/dist/article-content-renderer-vue2.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +350 -346
- package/dist/types/components/ArticleContentRenderer.vue.d.ts +5 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var E = (
|
|
1
|
+
var F = Object.defineProperty, Y = Object.defineProperties;
|
|
2
|
+
var K = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var B = Object.getOwnPropertySymbols;
|
|
4
|
+
var G = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var E = (n, r, t) => r in n ? F(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t, m = (n, r) => {
|
|
6
6
|
for (var t in r || (r = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var t of
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}, A = (
|
|
13
|
-
var
|
|
14
|
-
import
|
|
15
|
-
const
|
|
16
|
-
function
|
|
17
|
-
if (typeof
|
|
18
|
-
const t =
|
|
7
|
+
G.call(r, t) && E(n, t, r[t]);
|
|
8
|
+
if (B)
|
|
9
|
+
for (var t of B(r))
|
|
10
|
+
W.call(r, t) && E(n, t, r[t]);
|
|
11
|
+
return n;
|
|
12
|
+
}, A = (n, r) => Y(n, K(r));
|
|
13
|
+
var O = (n, r, t) => E(n, typeof r != "symbol" ? r + "" : r, t);
|
|
14
|
+
import $ from "vue";
|
|
15
|
+
const H = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]), X = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]), J = "https://article-content-renderer.invalid/", N = "https://www.doitme.link/";
|
|
16
|
+
function Q(n, r) {
|
|
17
|
+
if (typeof n != "string") return n;
|
|
18
|
+
const t = n.trim();
|
|
19
19
|
if (!t.startsWith(N)) return t;
|
|
20
|
-
const
|
|
21
|
-
return `${
|
|
20
|
+
const i = (r.trim() || N).replace(/\/+$/u, ""), s = t.slice(N.length).replace(/^\/+/, "");
|
|
21
|
+
return `${i}/${s}`;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
if (typeof
|
|
25
|
-
const t =
|
|
23
|
+
function _(n, r) {
|
|
24
|
+
if (typeof n != "string") return null;
|
|
25
|
+
const t = n.trim();
|
|
26
26
|
if (!t || /[\u0000-\u001F\u007F]/u.test(t)) return null;
|
|
27
27
|
try {
|
|
28
|
-
const e = new URL(t,
|
|
29
|
-
return (r === "link" ?
|
|
28
|
+
const e = new URL(t, J);
|
|
29
|
+
return (r === "link" ? H : X).has(e.protocol) ? t : null;
|
|
30
30
|
} catch (e) {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function x(n, r) {
|
|
35
35
|
const t = new Set(
|
|
36
|
-
typeof
|
|
36
|
+
typeof n == "string" ? n.trim().split(/\s+/u).filter(Boolean) : []
|
|
37
37
|
);
|
|
38
38
|
return r === "_blank" && (t.add("noopener"), t.add("noreferrer")), t.size > 0 ? [...t].join(" ") : void 0;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const Z = /* @__PURE__ */ new Set([
|
|
41
41
|
"paragraph",
|
|
42
42
|
"heading",
|
|
43
43
|
"blockquote",
|
|
@@ -49,53 +49,53 @@ const J = /* @__PURE__ */ new Set([
|
|
|
49
49
|
"articleButton",
|
|
50
50
|
"table"
|
|
51
51
|
]);
|
|
52
|
-
function
|
|
53
|
-
return typeof
|
|
52
|
+
function h(n) {
|
|
53
|
+
return typeof n == "object" && n !== null && !Array.isArray(n);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
55
|
+
function P(n) {
|
|
56
|
+
return h(n) ? n : {};
|
|
57
57
|
}
|
|
58
|
-
function f(
|
|
59
|
-
var
|
|
60
|
-
const
|
|
61
|
-
for (const [u,
|
|
58
|
+
function f(n, r, t, e) {
|
|
59
|
+
var l;
|
|
60
|
+
const i = h(t) ? t : {}, s = h(t) ? e : t, o = {}, a = {};
|
|
61
|
+
for (const [u, g] of Object.entries(i))
|
|
62
62
|
if (u === "class")
|
|
63
|
-
o.class =
|
|
63
|
+
o.class = g;
|
|
64
64
|
else if (u === "style")
|
|
65
|
-
o.style =
|
|
66
|
-
else if (u.startsWith("on") && typeof
|
|
65
|
+
o.style = g;
|
|
66
|
+
else if (u.startsWith("on") && typeof g == "function") {
|
|
67
67
|
const y = u.slice(2).toLowerCase();
|
|
68
|
-
o.on = A(m({}, (
|
|
69
|
-
} else
|
|
70
|
-
return Object.keys(
|
|
68
|
+
o.on = A(m({}, (l = o.on) != null ? l : {}), { [y]: g });
|
|
69
|
+
} else g !== void 0 && g !== !1 && (a[u] = g);
|
|
70
|
+
return Object.keys(a).length > 0 && (o.attrs = a), n.createElement(r, o, s);
|
|
71
71
|
}
|
|
72
|
-
function k(
|
|
73
|
-
return Array.isArray(
|
|
72
|
+
function k(n) {
|
|
73
|
+
return Array.isArray(n) ? n : [];
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return `${
|
|
75
|
+
function p(n, ...r) {
|
|
76
|
+
return `${n}/${r.map(String).join("/")}`;
|
|
77
77
|
}
|
|
78
|
-
function w(
|
|
79
|
-
return
|
|
78
|
+
function w(n) {
|
|
79
|
+
return n === "left" || n === "center" || n === "right" || n === "justify";
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
81
|
+
function tt(n) {
|
|
82
|
+
return n === "left" || n === "center" || n === "right";
|
|
83
83
|
}
|
|
84
|
-
function R(
|
|
85
|
-
return
|
|
84
|
+
function R(n) {
|
|
85
|
+
return n === "_blank" || n === "_self";
|
|
86
86
|
}
|
|
87
|
-
function b(
|
|
88
|
-
|
|
87
|
+
function b(n, r) {
|
|
88
|
+
n.reportIssue(r);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
if (!
|
|
90
|
+
function et(n, r, t) {
|
|
91
|
+
if (!h(n) || n.type !== "text" || typeof n.text != "string" || !n.text)
|
|
92
92
|
return null;
|
|
93
|
-
let e =
|
|
94
|
-
const
|
|
95
|
-
for (let s = 0; s <
|
|
96
|
-
const o =
|
|
97
|
-
if (!
|
|
98
|
-
const
|
|
93
|
+
let e = n.text;
|
|
94
|
+
const i = k(n.marks);
|
|
95
|
+
for (let s = 0; s < i.length; s += 1) {
|
|
96
|
+
const o = i[s];
|
|
97
|
+
if (!h(o) || typeof o.type != "string") continue;
|
|
98
|
+
const a = p(r, "marks", s);
|
|
99
99
|
switch (o.type) {
|
|
100
100
|
case "bold":
|
|
101
101
|
e = f(t, "strong", { class: "acp-mark acp-mark--bold" }, [e]);
|
|
@@ -113,25 +113,25 @@ function Z(i, r, t) {
|
|
|
113
113
|
e = f(t, "code", { class: "acp-mark acp-mark--code" }, [e]);
|
|
114
114
|
break;
|
|
115
115
|
case "link": {
|
|
116
|
-
const
|
|
116
|
+
const l = P(o.attrs), u = _(l.href, "link");
|
|
117
117
|
if (!u) {
|
|
118
118
|
b(t, {
|
|
119
119
|
code: "UNSAFE_URL",
|
|
120
|
-
path:
|
|
120
|
+
path: p(a, "attrs", "href"),
|
|
121
121
|
message: "The link URL is empty, malformed, or uses a disallowed protocol.",
|
|
122
122
|
nodeType: "link"
|
|
123
123
|
});
|
|
124
124
|
break;
|
|
125
125
|
}
|
|
126
|
-
const
|
|
126
|
+
const g = R(l.target) ? l.target : "_blank";
|
|
127
127
|
e = f(
|
|
128
128
|
t,
|
|
129
129
|
"a",
|
|
130
130
|
{
|
|
131
131
|
class: "acp-link",
|
|
132
132
|
href: u,
|
|
133
|
-
target:
|
|
134
|
-
rel:
|
|
133
|
+
target: g,
|
|
134
|
+
rel: x(void 0, g)
|
|
135
135
|
},
|
|
136
136
|
[e]
|
|
137
137
|
);
|
|
@@ -141,50 +141,50 @@ function Z(i, r, t) {
|
|
|
141
141
|
}
|
|
142
142
|
return e;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
return k(
|
|
144
|
+
function V(n, r, t) {
|
|
145
|
+
return k(n).map((e, i) => et(e, p(r, i), t)).filter((e) => e !== null);
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
return !
|
|
147
|
+
function q(n, r, t) {
|
|
148
|
+
return !h(n) || n.type !== "listItem" ? null : f(
|
|
149
149
|
t,
|
|
150
150
|
"li",
|
|
151
151
|
{ class: "acp-list-item", "data-node-type": "listItem" },
|
|
152
|
-
|
|
152
|
+
S(n.content, p(r, "content"), t)
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
return !
|
|
155
|
+
function rt(n, r, t) {
|
|
156
|
+
return !h(n) || n.type !== "tableCell" ? null : f(
|
|
157
157
|
t,
|
|
158
158
|
"td",
|
|
159
159
|
{ class: "acp-table-cell", "data-node-type": "tableCell" },
|
|
160
|
-
|
|
160
|
+
S(n.content, p(r, "content"), t)
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
|
-
function
|
|
164
|
-
if (!
|
|
165
|
-
const e = k(
|
|
163
|
+
function nt(n, r, t) {
|
|
164
|
+
if (!h(n) || n.type !== "tableRow") return null;
|
|
165
|
+
const e = k(n.content).map((i, s) => rt(i, p(r, "content", s), t)).filter((i) => i !== null);
|
|
166
166
|
return f(t, "tr", { class: "acp-table-row", "data-node-type": "tableRow" }, e);
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
var
|
|
170
|
-
if (
|
|
171
|
-
const r = typeof
|
|
172
|
-
href:
|
|
173
|
-
}, R(
|
|
168
|
+
function C(n) {
|
|
169
|
+
var i;
|
|
170
|
+
if (h(n) && n.target !== void 0 && !R(n.target) || h(n) && n.rel !== void 0 && typeof n.rel != "string") return null;
|
|
171
|
+
const r = typeof n == "string" ? { href: n } : h(n) && typeof n.href == "string" ? m(m({
|
|
172
|
+
href: n.href
|
|
173
|
+
}, R(n.target) ? { target: n.target } : {}), typeof n.rel == "string" ? { rel: n.rel } : {}) : null;
|
|
174
174
|
if (!r) return null;
|
|
175
|
-
const t =
|
|
175
|
+
const t = _(r.href, "link");
|
|
176
176
|
if (!t) return null;
|
|
177
|
-
const e = (
|
|
177
|
+
const e = (i = r.target) != null ? i : "_self";
|
|
178
178
|
return {
|
|
179
179
|
href: t,
|
|
180
180
|
target: e,
|
|
181
|
-
rel:
|
|
181
|
+
rel: x(r.rel, e)
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
function
|
|
185
|
-
var
|
|
186
|
-
const e =
|
|
187
|
-
if (typeof e.text != "string" || !e.text || !
|
|
184
|
+
function it(n, r, t) {
|
|
185
|
+
var g;
|
|
186
|
+
const e = P(n.attrs), i = e.style === "text" || e.style === "button", s = e.style === "link";
|
|
187
|
+
if (typeof e.text != "string" || !e.text || !i && !s || i && (typeof e.id != "string" || !e.id) || s && e.id !== void 0 && (typeof e.id != "string" || !e.id))
|
|
188
188
|
return null;
|
|
189
189
|
const o = Object.freeze(s ? m(A(m(m({}, typeof e.id == "string" ? { id: e.id } : {}), typeof e.title == "string" ? { title: e.title } : {}), {
|
|
190
190
|
text: e.text,
|
|
@@ -194,10 +194,10 @@ function rt(i, r, t) {
|
|
|
194
194
|
}, typeof e.title == "string" ? { title: e.title } : {}), {
|
|
195
195
|
text: e.text,
|
|
196
196
|
style: e.style
|
|
197
|
-
})),
|
|
198
|
-
let
|
|
197
|
+
})), a = Object.freeze({ type: "articleButton", attrs: o });
|
|
198
|
+
let l = null;
|
|
199
199
|
if (o.style === "link")
|
|
200
|
-
o.href !== void 0 && (
|
|
200
|
+
o.href !== void 0 && (l = C(o.href), l || b(t, {
|
|
201
201
|
code: "UNSAFE_URL",
|
|
202
202
|
path: `${r}/attrs/href`,
|
|
203
203
|
message: "The articleButton link href is not a usable safe URL.",
|
|
@@ -213,8 +213,8 @@ function rt(i, r, t) {
|
|
|
213
213
|
else
|
|
214
214
|
try {
|
|
215
215
|
const y = Object.freeze({ type: "articleButton", attrs: o }), L = t.resolveArticleButtonLink(o, y);
|
|
216
|
-
|
|
217
|
-
code: typeof L == "string" ||
|
|
216
|
+
l = C(L), l || b(t, {
|
|
217
|
+
code: typeof L == "string" || h(L) && typeof L.href == "string" ? "UNSAFE_URL" : "LINK_RESOLUTION_FAILED",
|
|
218
218
|
path: r,
|
|
219
219
|
message: "The articleButton link resolver returned no usable safe URL.",
|
|
220
220
|
nodeType: "articleButton"
|
|
@@ -227,7 +227,7 @@ function rt(i, r, t) {
|
|
|
227
227
|
nodeType: "articleButton"
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
const u = (
|
|
230
|
+
const u = (g = l == null ? void 0 : l.href) != null ? g : null;
|
|
231
231
|
return f(
|
|
232
232
|
t,
|
|
233
233
|
"a",
|
|
@@ -238,49 +238,49 @@ function rt(i, r, t) {
|
|
|
238
238
|
!u && "acp-article-button--disabled"
|
|
239
239
|
],
|
|
240
240
|
href: u != null ? u : void 0,
|
|
241
|
-
target:
|
|
242
|
-
rel:
|
|
241
|
+
target: l == null ? void 0 : l.target,
|
|
242
|
+
rel: l == null ? void 0 : l.rel,
|
|
243
243
|
title: o.title,
|
|
244
244
|
"data-node-type": "articleButton",
|
|
245
245
|
"data-article-button-id": o.id,
|
|
246
246
|
"data-article-button-style": o.style,
|
|
247
247
|
"aria-disabled": u ? void 0 : "true",
|
|
248
248
|
onClick: (y) => {
|
|
249
|
-
u || y.preventDefault(), t.emitArticleButtonClick({ attrs: o, node:
|
|
249
|
+
u || y.preventDefault(), t.emitArticleButtonClick({ attrs: o, node: a, href: u, event: y });
|
|
250
250
|
}
|
|
251
251
|
},
|
|
252
252
|
o.text
|
|
253
253
|
);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
256
|
-
if (!
|
|
255
|
+
function v(n, r, t) {
|
|
256
|
+
if (!h(n) || typeof n.type != "string" || !Z.has(n.type))
|
|
257
257
|
return null;
|
|
258
|
-
const e =
|
|
259
|
-
switch (
|
|
258
|
+
const e = P(n.attrs);
|
|
259
|
+
switch (n.type) {
|
|
260
260
|
case "paragraph": {
|
|
261
|
-
const
|
|
261
|
+
const i = w(e.textAlign) ? e.textAlign : void 0;
|
|
262
262
|
return f(
|
|
263
263
|
t,
|
|
264
264
|
"p",
|
|
265
265
|
{
|
|
266
266
|
class: "acp-paragraph",
|
|
267
267
|
"data-node-type": "paragraph",
|
|
268
|
-
style:
|
|
268
|
+
style: i ? { textAlign: i } : void 0
|
|
269
269
|
},
|
|
270
|
-
|
|
270
|
+
V(n.content, p(r, "content"), t)
|
|
271
271
|
);
|
|
272
272
|
}
|
|
273
273
|
case "heading": {
|
|
274
|
-
const
|
|
274
|
+
const i = Number.isInteger(e.level) && Number(e.level) >= 1 && Number(e.level) <= 6 ? Number(e.level) : 1, s = w(e.textAlign) ? e.textAlign : void 0;
|
|
275
275
|
return f(
|
|
276
276
|
t,
|
|
277
|
-
`h${
|
|
277
|
+
`h${i}`,
|
|
278
278
|
{
|
|
279
|
-
class: ["acp-heading", `acp-heading--${
|
|
279
|
+
class: ["acp-heading", `acp-heading--${i}`],
|
|
280
280
|
"data-node-type": "heading",
|
|
281
281
|
style: s ? { textAlign: s } : void 0
|
|
282
282
|
},
|
|
283
|
-
|
|
283
|
+
V(n.content, p(r, "content"), t)
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
286
|
case "blockquote":
|
|
@@ -288,50 +288,50 @@ function D(i, r, t) {
|
|
|
288
288
|
t,
|
|
289
289
|
"blockquote",
|
|
290
290
|
{ class: "acp-blockquote", "data-node-type": "blockquote" },
|
|
291
|
-
|
|
291
|
+
S(n.content, p(r, "content"), t)
|
|
292
292
|
);
|
|
293
293
|
case "bulletList": {
|
|
294
|
-
const
|
|
295
|
-
return f(t, "ul", { class: "acp-list acp-list--bullet", "data-node-type": "bulletList" },
|
|
294
|
+
const i = k(n.content).map((s, o) => q(s, p(r, "content", o), t)).filter((s) => s !== null);
|
|
295
|
+
return f(t, "ul", { class: "acp-list acp-list--bullet", "data-node-type": "bulletList" }, i);
|
|
296
296
|
}
|
|
297
297
|
case "orderedList": {
|
|
298
|
-
const
|
|
298
|
+
const i = Number.isInteger(e.start) && Number(e.start) >= 1 ? Number(e.start) : 1, s = k(n.content).map((o, a) => q(o, p(r, "content", a), t)).filter((o) => o !== null);
|
|
299
299
|
return f(
|
|
300
300
|
t,
|
|
301
301
|
"ol",
|
|
302
302
|
{
|
|
303
303
|
class: "acp-list acp-list--ordered",
|
|
304
304
|
"data-node-type": "orderedList",
|
|
305
|
-
start:
|
|
305
|
+
start: i
|
|
306
306
|
},
|
|
307
307
|
s
|
|
308
308
|
);
|
|
309
309
|
}
|
|
310
310
|
case "codeBlock": {
|
|
311
|
-
const
|
|
311
|
+
const i = typeof e.language == "string" && e.language ? e.language : void 0, s = k(n.content).filter((o) => h(o) && o.type === "text" && typeof o.text == "string").map((o) => o.text).join("");
|
|
312
312
|
return f(
|
|
313
313
|
t,
|
|
314
314
|
"pre",
|
|
315
315
|
{
|
|
316
316
|
class: "acp-code-block",
|
|
317
317
|
"data-node-type": "codeBlock",
|
|
318
|
-
"data-language":
|
|
318
|
+
"data-language": i
|
|
319
319
|
},
|
|
320
|
-
[f(t, "code", { class:
|
|
320
|
+
[f(t, "code", { class: i ? `language-${i}` : void 0 }, s)]
|
|
321
321
|
);
|
|
322
322
|
}
|
|
323
323
|
case "horizontalRule":
|
|
324
324
|
return f(t, "hr", { class: "acp-horizontal-rule", "data-node-type": "horizontalRule" });
|
|
325
325
|
case "image": {
|
|
326
|
-
const
|
|
327
|
-
if (!
|
|
326
|
+
const i = _(Q(e.src, t.imageBaseUrl), "image");
|
|
327
|
+
if (!i)
|
|
328
328
|
return b(t, {
|
|
329
329
|
code: "UNSAFE_URL",
|
|
330
|
-
path:
|
|
330
|
+
path: p(r, "attrs", "src"),
|
|
331
331
|
message: "The image URL is empty, malformed, or uses a disallowed protocol.",
|
|
332
332
|
nodeType: "image"
|
|
333
333
|
}), null;
|
|
334
|
-
const s =
|
|
334
|
+
const s = tt(e.imageAlign) ? e.imageAlign : "center", o = Number.isInteger(e.width) && Number(e.width) >= 1 && Number(e.width) <= 1e4 ? Number(e.width) : void 0, a = Number.isInteger(e.height) && Number(e.height) >= 1 && Number(e.height) <= 1e4 ? Number(e.height) : void 0;
|
|
335
335
|
return f(
|
|
336
336
|
t,
|
|
337
337
|
"div",
|
|
@@ -343,55 +343,55 @@ function D(i, r, t) {
|
|
|
343
343
|
[
|
|
344
344
|
f(t, "img", {
|
|
345
345
|
class: "acp-image__element",
|
|
346
|
-
src:
|
|
346
|
+
src: i,
|
|
347
347
|
alt: typeof e.alt == "string" ? e.alt : "",
|
|
348
348
|
title: typeof e.title == "string" ? e.title : void 0,
|
|
349
349
|
width: o,
|
|
350
|
-
height:
|
|
350
|
+
height: a,
|
|
351
351
|
"data-image-align": s
|
|
352
352
|
})
|
|
353
353
|
]
|
|
354
354
|
);
|
|
355
355
|
}
|
|
356
356
|
case "articleButton":
|
|
357
|
-
return
|
|
357
|
+
return it(n, r, t);
|
|
358
358
|
case "table": {
|
|
359
|
-
const
|
|
359
|
+
const i = k(n.content).map((s, o) => nt(s, p(r, "content", o), t)).filter((s) => s !== null);
|
|
360
360
|
return f(
|
|
361
361
|
t,
|
|
362
362
|
"div",
|
|
363
363
|
{ class: "acp-table-wrapper", "data-node-type": "table" },
|
|
364
|
-
[f(t, "table", { class: "acp-table" }, [f(t, "tbody",
|
|
364
|
+
[f(t, "table", { class: "acp-table" }, [f(t, "tbody", i)])]
|
|
365
365
|
);
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
return null;
|
|
369
369
|
}
|
|
370
|
-
function
|
|
371
|
-
return k(
|
|
370
|
+
function S(n, r, t) {
|
|
371
|
+
return k(n).map((e, i) => v(e, p(r, i), t)).filter((e) => e !== null);
|
|
372
372
|
}
|
|
373
|
-
function
|
|
374
|
-
const t = k(
|
|
373
|
+
function st(n, r) {
|
|
374
|
+
const t = k(n.content), e = /* @__PURE__ */ new Map();
|
|
375
375
|
r.customSlots.forEach((s) => {
|
|
376
|
-
var
|
|
376
|
+
var a;
|
|
377
377
|
if (!Number.isInteger(s.location) || s.location < 1 || s.location > t.length)
|
|
378
378
|
return;
|
|
379
|
-
const o = (
|
|
379
|
+
const o = (a = e.get(s.location)) != null ? a : [];
|
|
380
380
|
o.push(s), e.set(s.location, o);
|
|
381
381
|
});
|
|
382
|
-
const
|
|
382
|
+
const i = [];
|
|
383
383
|
return t.forEach((s, o) => {
|
|
384
384
|
var u;
|
|
385
|
-
const
|
|
386
|
-
(u = e.get(
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
}),
|
|
385
|
+
const a = o + 1;
|
|
386
|
+
(u = e.get(a)) == null || u.forEach((g) => i.push(...g.content));
|
|
387
|
+
const l = v(s, p("/content", o), r);
|
|
388
|
+
l && typeof l != "string" && i.push(l);
|
|
389
|
+
}), i;
|
|
390
390
|
}
|
|
391
|
-
function
|
|
392
|
-
return !
|
|
391
|
+
function ot(n, r) {
|
|
392
|
+
return !h(n) || n.type !== "doc" ? [] : st(n, r);
|
|
393
393
|
}
|
|
394
|
-
const
|
|
394
|
+
const at = /* @__PURE__ */ new Set([
|
|
395
395
|
"paragraph",
|
|
396
396
|
"heading",
|
|
397
397
|
"blockquote",
|
|
@@ -402,28 +402,28 @@ const st = /* @__PURE__ */ new Set([
|
|
|
402
402
|
"image",
|
|
403
403
|
"articleButton",
|
|
404
404
|
"table"
|
|
405
|
-
]),
|
|
406
|
-
function I(
|
|
407
|
-
return typeof
|
|
405
|
+
]), ct = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), lt = /* @__PURE__ */ new Set(["left", "center", "right"]), dt = /* @__PURE__ */ new Set(["bold", "italic", "strike", "underline", "code"]);
|
|
406
|
+
function I(n) {
|
|
407
|
+
return typeof n == "object" && n !== null && !Array.isArray(n);
|
|
408
408
|
}
|
|
409
|
-
function
|
|
410
|
-
return `${
|
|
409
|
+
function c(n, r) {
|
|
410
|
+
return `${n}/${String(r).replaceAll("~", "~0").replaceAll("/", "~1")}`;
|
|
411
411
|
}
|
|
412
|
-
function d(
|
|
413
|
-
let t =
|
|
414
|
-
for (const e of r) t =
|
|
412
|
+
function d(n, ...r) {
|
|
413
|
+
let t = n;
|
|
414
|
+
for (const e of r) t = c(t, e);
|
|
415
415
|
return t;
|
|
416
416
|
}
|
|
417
|
-
class
|
|
417
|
+
class ut {
|
|
418
418
|
constructor() {
|
|
419
|
-
|
|
419
|
+
O(this, "issues", []);
|
|
420
420
|
}
|
|
421
421
|
validate(r) {
|
|
422
422
|
if (!I(r))
|
|
423
423
|
return this.add("INVALID_ROOT", "", "The document must be an object."), this.result();
|
|
424
424
|
this.checkProperties(r, "", ["type", "content"], ["type", "content"]), r.type !== "doc" && this.add("INVALID_ROOT", "/type", 'The root node type must be "doc".');
|
|
425
425
|
const t = this.requireArray(r.content, "/content");
|
|
426
|
-
return t == null || t.forEach((e,
|
|
426
|
+
return t == null || t.forEach((e, i) => this.validateBlock(e, c("/content", i))), this.result();
|
|
427
427
|
}
|
|
428
428
|
result() {
|
|
429
429
|
return {
|
|
@@ -431,23 +431,23 @@ class ct {
|
|
|
431
431
|
issues: this.issues
|
|
432
432
|
};
|
|
433
433
|
}
|
|
434
|
-
add(r, t, e,
|
|
435
|
-
this.issues.push(m({ code: r, path: t, message: e },
|
|
434
|
+
add(r, t, e, i) {
|
|
435
|
+
this.issues.push(m({ code: r, path: t, message: e }, i ? { nodeType: i } : {}));
|
|
436
436
|
}
|
|
437
|
-
checkProperties(r, t, e,
|
|
437
|
+
checkProperties(r, t, e, i = [], s) {
|
|
438
438
|
const o = new Set(e);
|
|
439
|
-
for (const
|
|
440
|
-
o.has(
|
|
439
|
+
for (const a of Object.keys(r))
|
|
440
|
+
o.has(a) || this.add(
|
|
441
441
|
"UNKNOWN_PROPERTY",
|
|
442
|
-
|
|
443
|
-
`Property "${
|
|
442
|
+
c(t, a),
|
|
443
|
+
`Property "${a}" is not allowed.`,
|
|
444
444
|
s
|
|
445
445
|
);
|
|
446
|
-
for (const
|
|
447
|
-
|
|
446
|
+
for (const a of i)
|
|
447
|
+
a in r || this.add(
|
|
448
448
|
"MISSING_PROPERTY",
|
|
449
|
-
|
|
450
|
-
`Required property "${
|
|
449
|
+
c(t, a),
|
|
450
|
+
`Required property "${a}" is missing.`,
|
|
451
451
|
s
|
|
452
452
|
);
|
|
453
453
|
}
|
|
@@ -458,13 +458,13 @@ class ct {
|
|
|
458
458
|
return r === void 0 ? [] : this.requireArray(r, t, e);
|
|
459
459
|
}
|
|
460
460
|
requireNonEmptyArray(r, t, e) {
|
|
461
|
-
const
|
|
462
|
-
return
|
|
461
|
+
const i = this.requireArray(r, t, e);
|
|
462
|
+
return i && i.length === 0 && this.add(
|
|
463
463
|
"INVALID_CONTENT",
|
|
464
464
|
t,
|
|
465
465
|
`Node "${e}" must contain at least one child.`,
|
|
466
466
|
e
|
|
467
|
-
),
|
|
467
|
+
), i;
|
|
468
468
|
}
|
|
469
469
|
requireRecord(r, t, e) {
|
|
470
470
|
return I(r) ? r : (this.add("INVALID_TYPE", t, "Expected an object.", e), null);
|
|
@@ -472,22 +472,22 @@ class ct {
|
|
|
472
472
|
optionalRecord(r, t, e) {
|
|
473
473
|
return r === void 0 ? {} : this.requireRecord(r, t, e);
|
|
474
474
|
}
|
|
475
|
-
requireString(r, t, e,
|
|
476
|
-
return typeof r != "string" ? (this.add("INVALID_TYPE", t, "Expected a string.", e), !1) : !
|
|
475
|
+
requireString(r, t, e, i = {}) {
|
|
476
|
+
return typeof r != "string" ? (this.add("INVALID_TYPE", t, "Expected a string.", e), !1) : !i.allowEmpty && r.length === 0 ? (this.add("INVALID_VALUE", t, "The string must not be empty.", e), !1) : i.maxLength !== void 0 && r.length > i.maxLength ? (this.add(
|
|
477
477
|
"INVALID_VALUE",
|
|
478
478
|
t,
|
|
479
|
-
`The string must contain at most ${
|
|
479
|
+
`The string must contain at most ${i.maxLength} characters.`,
|
|
480
480
|
e
|
|
481
481
|
), !1) : !0;
|
|
482
482
|
}
|
|
483
|
-
optionalString(r, t, e,
|
|
484
|
-
r !== void 0 && this.requireString(r, t, e,
|
|
483
|
+
optionalString(r, t, e, i = {}) {
|
|
484
|
+
r !== void 0 && this.requireString(r, t, e, i);
|
|
485
485
|
}
|
|
486
|
-
requireInteger(r, t, e,
|
|
486
|
+
requireInteger(r, t, e, i, s) {
|
|
487
487
|
if (!Number.isInteger(r))
|
|
488
488
|
return this.add("INVALID_TYPE", t, "Expected an integer.", e), !1;
|
|
489
489
|
const o = r;
|
|
490
|
-
return
|
|
490
|
+
return i !== void 0 && o < i ? (this.add("INVALID_VALUE", t, `Value must be at least ${i}.`, e), !1) : s !== void 0 && o > s ? (this.add("INVALID_VALUE", t, `Value must be at most ${s}.`, e), !1) : !0;
|
|
491
491
|
}
|
|
492
492
|
validateBlock(r, t) {
|
|
493
493
|
if (!I(r)) {
|
|
@@ -496,11 +496,11 @@ class ct {
|
|
|
496
496
|
}
|
|
497
497
|
const e = r.type;
|
|
498
498
|
if (typeof e != "string") {
|
|
499
|
-
this.add("MISSING_PROPERTY",
|
|
499
|
+
this.add("MISSING_PROPERTY", c(t, "type"), "A block node requires a type.");
|
|
500
500
|
return;
|
|
501
501
|
}
|
|
502
|
-
if (!
|
|
503
|
-
this.add("UNKNOWN_NODE",
|
|
502
|
+
if (!at.has(e)) {
|
|
503
|
+
this.add("UNKNOWN_NODE", c(t, "type"), `Unknown block node "${e}".`, e);
|
|
504
504
|
return;
|
|
505
505
|
}
|
|
506
506
|
switch (e) {
|
|
@@ -538,34 +538,34 @@ class ct {
|
|
|
538
538
|
}
|
|
539
539
|
validateParagraph(r, t) {
|
|
540
540
|
const e = "paragraph";
|
|
541
|
-
this.checkProperties(r, t, ["type", "attrs", "content"], ["type"], e), this.validateTextAlignAttrs(r.attrs,
|
|
541
|
+
this.checkProperties(r, t, ["type", "attrs", "content"], ["type"], e), this.validateTextAlignAttrs(r.attrs, c(t, "attrs"), e, !1), this.validateInlineContent(r.content, c(t, "content"), e);
|
|
542
542
|
}
|
|
543
543
|
validateHeading(r, t) {
|
|
544
544
|
const e = "heading";
|
|
545
545
|
this.checkProperties(r, t, ["type", "attrs", "content"], ["type", "attrs"], e);
|
|
546
|
-
const
|
|
547
|
-
|
|
546
|
+
const i = this.requireRecord(r.attrs, c(t, "attrs"), e);
|
|
547
|
+
i && (this.checkProperties(i, c(t, "attrs"), ["level", "textAlign"], ["level"], e), this.requireInteger(i.level, d(t, "attrs", "level"), e, 1, 6), this.validateTextAlign(i.textAlign, d(t, "attrs", "textAlign"), e)), this.validateInlineContent(r.content, c(t, "content"), e);
|
|
548
548
|
}
|
|
549
|
-
validateTextAlignAttrs(r, t, e,
|
|
550
|
-
const s =
|
|
551
|
-
s && (this.checkProperties(s, t, ["textAlign"], [], e), this.validateTextAlign(s.textAlign,
|
|
549
|
+
validateTextAlignAttrs(r, t, e, i) {
|
|
550
|
+
const s = i ? this.requireRecord(r, t, e) : this.optionalRecord(r, t, e);
|
|
551
|
+
s && (this.checkProperties(s, t, ["textAlign"], [], e), this.validateTextAlign(s.textAlign, c(t, "textAlign"), e));
|
|
552
552
|
}
|
|
553
553
|
validateTextAlign(r, t, e) {
|
|
554
|
-
r !== void 0 && (typeof r != "string" ? this.add("INVALID_TYPE", t, "Text alignment must be a string.", e) :
|
|
554
|
+
r !== void 0 && (typeof r != "string" ? this.add("INVALID_TYPE", t, "Text alignment must be a string.", e) : ct.has(r) || this.add("INVALID_VALUE", t, `Unsupported text alignment "${r}".`, e));
|
|
555
555
|
}
|
|
556
556
|
validateInlineContent(r, t, e) {
|
|
557
|
-
const
|
|
558
|
-
|
|
557
|
+
const i = this.optionalArray(r, t, e);
|
|
558
|
+
i == null || i.forEach((s, o) => this.validateText(s, c(t, o), !0));
|
|
559
559
|
}
|
|
560
560
|
validateText(r, t, e) {
|
|
561
561
|
if (!I(r)) {
|
|
562
562
|
this.add("INVALID_TYPE", t, "A text node must be an object.", "text");
|
|
563
563
|
return;
|
|
564
564
|
}
|
|
565
|
-
const
|
|
566
|
-
if (this.checkProperties(r, t,
|
|
567
|
-
const s = this.requireArray(r.marks,
|
|
568
|
-
s == null || s.forEach((o,
|
|
565
|
+
const i = e ? ["type", "text", "marks"] : ["type", "text"];
|
|
566
|
+
if (this.checkProperties(r, t, i, ["type", "text"], "text"), r.type !== "text" && this.add("INVALID_CONTENT", c(t, "type"), "Expected a text node.", "text"), this.requireString(r.text, c(t, "text"), "text"), e && r.marks !== void 0) {
|
|
567
|
+
const s = this.requireArray(r.marks, c(t, "marks"), "text");
|
|
568
|
+
s == null || s.forEach((o, a) => this.validateMark(o, d(t, "marks", a)));
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
validateMark(r, t) {
|
|
@@ -574,20 +574,20 @@ class ct {
|
|
|
574
574
|
return;
|
|
575
575
|
}
|
|
576
576
|
if (typeof r.type != "string") {
|
|
577
|
-
this.add("MISSING_PROPERTY",
|
|
577
|
+
this.add("MISSING_PROPERTY", c(t, "type"), "A mark requires a type.");
|
|
578
578
|
return;
|
|
579
579
|
}
|
|
580
|
-
if (
|
|
580
|
+
if (dt.has(r.type)) {
|
|
581
581
|
this.checkProperties(r, t, ["type"], ["type"], r.type);
|
|
582
582
|
return;
|
|
583
583
|
}
|
|
584
584
|
if (r.type !== "link") {
|
|
585
|
-
this.add("UNKNOWN_MARK",
|
|
585
|
+
this.add("UNKNOWN_MARK", c(t, "type"), `Unknown mark "${r.type}".`, r.type);
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
588
588
|
this.checkProperties(r, t, ["type", "attrs"], ["type", "attrs"], "link");
|
|
589
|
-
const e = this.requireRecord(r.attrs,
|
|
590
|
-
e && (this.checkProperties(e,
|
|
589
|
+
const e = this.requireRecord(r.attrs, c(t, "attrs"), "link");
|
|
590
|
+
e && (this.checkProperties(e, c(t, "attrs"), ["href", "target"], ["href"], "link"), this.requireString(e.href, d(t, "attrs", "href"), "link"), e.target !== void 0 && e.target !== "_blank" && e.target !== "_self" && this.add(
|
|
591
591
|
"INVALID_VALUE",
|
|
592
592
|
d(t, "attrs", "target"),
|
|
593
593
|
'Link target must be "_blank" or "_self".',
|
|
@@ -597,83 +597,83 @@ class ct {
|
|
|
597
597
|
validateBlockquote(r, t) {
|
|
598
598
|
const e = "blockquote";
|
|
599
599
|
this.checkProperties(r, t, ["type", "content"], ["type", "content"], e);
|
|
600
|
-
const
|
|
601
|
-
|
|
600
|
+
const i = this.requireNonEmptyArray(r.content, c(t, "content"), e);
|
|
601
|
+
i == null || i.forEach((s, o) => this.validateBlock(s, d(t, "content", o)));
|
|
602
602
|
}
|
|
603
603
|
validateBulletList(r, t) {
|
|
604
604
|
const e = "bulletList";
|
|
605
605
|
this.checkProperties(r, t, ["type", "content"], ["type", "content"], e);
|
|
606
|
-
const
|
|
607
|
-
|
|
606
|
+
const i = this.requireNonEmptyArray(r.content, c(t, "content"), e);
|
|
607
|
+
i == null || i.forEach((s, o) => this.validateListItem(s, d(t, "content", o)));
|
|
608
608
|
}
|
|
609
609
|
validateOrderedList(r, t) {
|
|
610
610
|
const e = "orderedList";
|
|
611
611
|
this.checkProperties(r, t, ["type", "attrs", "content"], ["type", "content"], e);
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
const s = this.requireNonEmptyArray(r.content,
|
|
615
|
-
s == null || s.forEach((o,
|
|
612
|
+
const i = this.optionalRecord(r.attrs, c(t, "attrs"), e);
|
|
613
|
+
i && (this.checkProperties(i, c(t, "attrs"), ["start"], [], e), i.start !== void 0 && this.requireInteger(i.start, d(t, "attrs", "start"), e, 1));
|
|
614
|
+
const s = this.requireNonEmptyArray(r.content, c(t, "content"), e);
|
|
615
|
+
s == null || s.forEach((o, a) => this.validateListItem(o, d(t, "content", a)));
|
|
616
616
|
}
|
|
617
617
|
validateListItem(r, t) {
|
|
618
|
-
const e = "listItem",
|
|
619
|
-
if (!
|
|
620
|
-
this.checkProperties(
|
|
621
|
-
const s = this.requireNonEmptyArray(
|
|
622
|
-
s == null || s.forEach((o,
|
|
618
|
+
const e = "listItem", i = this.requireRecord(r, t, e);
|
|
619
|
+
if (!i) return;
|
|
620
|
+
this.checkProperties(i, t, ["type", "content"], ["type", "content"], e), i.type !== e && this.add("INVALID_CONTENT", c(t, "type"), "Expected a listItem node.", e);
|
|
621
|
+
const s = this.requireNonEmptyArray(i.content, c(t, "content"), e);
|
|
622
|
+
s == null || s.forEach((o, a) => this.validateBlock(o, d(t, "content", a)));
|
|
623
623
|
}
|
|
624
624
|
validateCodeBlock(r, t) {
|
|
625
625
|
const e = "codeBlock";
|
|
626
626
|
this.checkProperties(r, t, ["type", "attrs", "content"], ["type"], e);
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
const s = this.optionalArray(r.content,
|
|
627
|
+
const i = this.optionalRecord(r.attrs, c(t, "attrs"), e);
|
|
628
|
+
i && (this.checkProperties(i, c(t, "attrs"), ["language"], [], e), this.optionalString(i.language, d(t, "attrs", "language"), e, { maxLength: 32 }));
|
|
629
|
+
const s = this.optionalArray(r.content, c(t, "content"), e);
|
|
630
630
|
s && (s.length > 1 && this.add(
|
|
631
631
|
"INVALID_CONTENT",
|
|
632
|
-
|
|
632
|
+
c(t, "content"),
|
|
633
633
|
"A codeBlock may contain at most one text node.",
|
|
634
634
|
e
|
|
635
635
|
), s.forEach(
|
|
636
|
-
(o,
|
|
636
|
+
(o, a) => this.validateText(o, d(t, "content", a), !1)
|
|
637
637
|
));
|
|
638
638
|
}
|
|
639
639
|
validateImage(r, t) {
|
|
640
640
|
const e = "image";
|
|
641
641
|
this.checkProperties(r, t, ["type", "attrs"], ["type", "attrs"], e);
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
642
|
+
const i = this.requireRecord(r.attrs, c(t, "attrs"), e);
|
|
643
|
+
i && (this.checkProperties(
|
|
644
|
+
i,
|
|
645
|
+
c(t, "attrs"),
|
|
646
646
|
["src", "alt", "title", "width", "height", "imageAlign"],
|
|
647
647
|
["src"],
|
|
648
648
|
e
|
|
649
|
-
), this.requireString(
|
|
649
|
+
), this.requireString(i.src, d(t, "attrs", "src"), e), this.optionalString(i.alt, d(t, "attrs", "alt"), e, { allowEmpty: !0 }), this.optionalString(i.title, d(t, "attrs", "title"), e, { allowEmpty: !0 }), i.width !== void 0 && this.requireInteger(i.width, d(t, "attrs", "width"), e, 1, 1e4), i.height !== void 0 && this.requireInteger(i.height, d(t, "attrs", "height"), e, 1, 1e4), i.imageAlign !== void 0 && (typeof i.imageAlign != "string" ? this.add("INVALID_TYPE", d(t, "attrs", "imageAlign"), "Image alignment must be a string.", e) : lt.has(i.imageAlign) || this.add(
|
|
650
650
|
"INVALID_VALUE",
|
|
651
651
|
d(t, "attrs", "imageAlign"),
|
|
652
|
-
`Unsupported image alignment "${
|
|
652
|
+
`Unsupported image alignment "${i.imageAlign}".`,
|
|
653
653
|
e
|
|
654
654
|
)));
|
|
655
655
|
}
|
|
656
656
|
validateArticleButton(r, t) {
|
|
657
657
|
const e = "articleButton";
|
|
658
658
|
this.checkProperties(r, t, ["type", "attrs"], ["type", "attrs"], e);
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
659
|
+
const i = this.requireRecord(r.attrs, c(t, "attrs"), e);
|
|
660
|
+
i && (this.checkProperties(
|
|
661
|
+
i,
|
|
662
|
+
c(t, "attrs"),
|
|
663
663
|
["id", "title", "text", "style", "href"],
|
|
664
664
|
["text", "style"],
|
|
665
665
|
e
|
|
666
|
-
),
|
|
666
|
+
), i.style === "text" || i.style === "button" ? "id" in i ? this.requireString(i.id, d(t, "attrs", "id"), e) : this.add(
|
|
667
667
|
"MISSING_PROPERTY",
|
|
668
668
|
d(t, "attrs", "id"),
|
|
669
669
|
'Required property "id" is missing for an articleButton with text or button style.',
|
|
670
670
|
e
|
|
671
|
-
) : this.optionalString(
|
|
671
|
+
) : this.optionalString(i.id, d(t, "attrs", "id"), e), this.optionalString(i.title, d(t, "attrs", "title"), e), this.requireString(i.text, d(t, "attrs", "text"), e), this.optionalString(i.href, d(t, "attrs", "href"), e), i.style !== "text" && i.style !== "button" && i.style !== "link" && this.add(
|
|
672
672
|
"INVALID_VALUE",
|
|
673
673
|
d(t, "attrs", "style"),
|
|
674
674
|
'Article button style must be "text", "button", or "link".',
|
|
675
675
|
e
|
|
676
|
-
),
|
|
676
|
+
), i.href !== void 0 && i.style !== "link" && this.add(
|
|
677
677
|
"INVALID_VALUE",
|
|
678
678
|
d(t, "attrs", "href"),
|
|
679
679
|
'Article button href may only be present when style is "link".',
|
|
@@ -683,14 +683,14 @@ class ct {
|
|
|
683
683
|
validateTable(r, t) {
|
|
684
684
|
const e = "table";
|
|
685
685
|
this.checkProperties(r, t, ["type", "content"], ["type", "content"], e);
|
|
686
|
-
const
|
|
687
|
-
if (!
|
|
686
|
+
const i = this.requireNonEmptyArray(r.content, c(t, "content"), e);
|
|
687
|
+
if (!i) return;
|
|
688
688
|
let s = null;
|
|
689
|
-
|
|
690
|
-
const
|
|
689
|
+
i.forEach((o, a) => {
|
|
690
|
+
const l = d(t, "content", a), u = this.validateTableRow(o, l);
|
|
691
691
|
u !== null && (s === null ? s = u : u !== s && this.add(
|
|
692
692
|
"TABLE_COLUMN_MISMATCH",
|
|
693
|
-
|
|
693
|
+
c(l, "content"),
|
|
694
694
|
`Expected ${s} table cells but received ${u}.`,
|
|
695
695
|
"tableRow"
|
|
696
696
|
));
|
|
@@ -698,48 +698,100 @@ class ct {
|
|
|
698
698
|
}
|
|
699
699
|
validateTableRow(r, t) {
|
|
700
700
|
var o;
|
|
701
|
-
const e = "tableRow",
|
|
702
|
-
if (!
|
|
703
|
-
this.checkProperties(
|
|
704
|
-
const s = this.requireNonEmptyArray(
|
|
705
|
-
return s == null || s.forEach((
|
|
701
|
+
const e = "tableRow", i = this.requireRecord(r, t, e);
|
|
702
|
+
if (!i) return null;
|
|
703
|
+
this.checkProperties(i, t, ["type", "content"], ["type", "content"], e), i.type !== e && this.add("INVALID_CONTENT", c(t, "type"), "Expected a tableRow node.", e);
|
|
704
|
+
const s = this.requireNonEmptyArray(i.content, c(t, "content"), e);
|
|
705
|
+
return s == null || s.forEach((a, l) => this.validateTableCell(a, d(t, "content", l))), (o = s == null ? void 0 : s.length) != null ? o : null;
|
|
706
706
|
}
|
|
707
707
|
validateTableCell(r, t) {
|
|
708
|
-
const e = "tableCell",
|
|
709
|
-
if (!
|
|
710
|
-
this.checkProperties(
|
|
711
|
-
const s = this.requireNonEmptyArray(
|
|
712
|
-
s == null || s.forEach((o,
|
|
708
|
+
const e = "tableCell", i = this.requireRecord(r, t, e);
|
|
709
|
+
if (!i) return;
|
|
710
|
+
this.checkProperties(i, t, ["type", "content"], ["type", "content"], e), i.type !== e && this.add("INVALID_CONTENT", c(t, "type"), "Expected a tableCell node.", e);
|
|
711
|
+
const s = this.requireNonEmptyArray(i.content, c(t, "content"), e);
|
|
712
|
+
s == null || s.forEach((o, a) => this.validateBlock(o, d(t, "content", a)));
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
|
-
function
|
|
716
|
-
return new
|
|
715
|
+
function ft(n) {
|
|
716
|
+
return new ut().validate(n);
|
|
717
717
|
}
|
|
718
|
-
const
|
|
718
|
+
const U = Object.freeze({
|
|
719
719
|
version: 1,
|
|
720
|
-
validate:
|
|
721
|
-
render:
|
|
722
|
-
}),
|
|
723
|
-
function
|
|
724
|
-
return
|
|
720
|
+
validate: ft,
|
|
721
|
+
render: ot
|
|
722
|
+
}), j = /* @__PURE__ */ new Map([[U.version, U]]), Rt = Object.freeze([...j.keys()]), z = 1;
|
|
723
|
+
function M(n) {
|
|
724
|
+
return j.get(n);
|
|
725
725
|
}
|
|
726
|
-
function
|
|
726
|
+
function gt(n, r = {}) {
|
|
727
727
|
var s;
|
|
728
|
-
const t = (s = r.protocolVersion) != null ? s :
|
|
729
|
-
return e ? e.validate(
|
|
728
|
+
const t = (s = r.protocolVersion) != null ? s : z, e = M(t);
|
|
729
|
+
return e ? e.validate(n) : { valid: !1, issues: [{
|
|
730
730
|
code: "UNSUPPORTED_PROTOCOL",
|
|
731
731
|
path: "",
|
|
732
732
|
message: `Article Content Protocol version ${t} is not supported.`
|
|
733
733
|
}] };
|
|
734
734
|
}
|
|
735
|
-
function
|
|
735
|
+
function pt() {
|
|
736
736
|
return [];
|
|
737
737
|
}
|
|
738
|
-
function
|
|
739
|
-
return `${
|
|
738
|
+
function T(n) {
|
|
739
|
+
return `${n.code}:${n.path}:${n.message}`;
|
|
740
740
|
}
|
|
741
|
-
|
|
741
|
+
function ht(n) {
|
|
742
|
+
const r = n.slots();
|
|
743
|
+
return n.props.customSlots.map((t) => {
|
|
744
|
+
var s, o, a, l;
|
|
745
|
+
const e = { id: t.id, location: t.location }, i = (l = (a = (o = (s = n.scopedSlots)[t.id]) == null ? void 0 : o.call(s, e)) != null ? a : r[t.id]) != null ? l : [];
|
|
746
|
+
return A(m({}, t), { content: i });
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
function yt(n, r) {
|
|
750
|
+
Array.isArray(n) ? n.forEach((t) => t(r)) : n == null || n(r);
|
|
751
|
+
}
|
|
752
|
+
const mt = $.extend({
|
|
753
|
+
name: "ArticleContentRenderIssueReporter",
|
|
754
|
+
props: {
|
|
755
|
+
issues: {
|
|
756
|
+
type: Array,
|
|
757
|
+
required: !0
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
data() {
|
|
761
|
+
return {
|
|
762
|
+
reportedFingerprint: ""
|
|
763
|
+
};
|
|
764
|
+
},
|
|
765
|
+
watch: {
|
|
766
|
+
issues: {
|
|
767
|
+
immediate: !0,
|
|
768
|
+
deep: !0,
|
|
769
|
+
handler(n) {
|
|
770
|
+
const r = n.map(T).join("|");
|
|
771
|
+
r !== this.reportedFingerprint && (this.reportedFingerprint = r, this.$nextTick(() => n.forEach((t) => this.$emit("render-error", t))));
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
render(n) {
|
|
776
|
+
var r, t;
|
|
777
|
+
return (t = (r = this.$slots.default) == null ? void 0 : r[0]) != null ? t : n();
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
function D(n, r, t, e) {
|
|
781
|
+
var a;
|
|
782
|
+
const i = (a = t[0]) != null ? a : n(), s = r.listeners["render-error"], o = n(
|
|
783
|
+
mt,
|
|
784
|
+
{
|
|
785
|
+
props: { issues: e },
|
|
786
|
+
on: s ? { "render-error": s } : void 0
|
|
787
|
+
},
|
|
788
|
+
[i]
|
|
789
|
+
);
|
|
790
|
+
return t.length > 1 ? [o, ...t.slice(1)] : o;
|
|
791
|
+
}
|
|
792
|
+
const kt = {
|
|
742
793
|
name: "ArticleContentRenderer",
|
|
794
|
+
functional: !0,
|
|
743
795
|
props: {
|
|
744
796
|
document: {
|
|
745
797
|
type: null,
|
|
@@ -747,7 +799,7 @@ const gt = K.extend({
|
|
|
747
799
|
},
|
|
748
800
|
protocolVersion: {
|
|
749
801
|
type: Number,
|
|
750
|
-
default:
|
|
802
|
+
default: z
|
|
751
803
|
},
|
|
752
804
|
strict: {
|
|
753
805
|
type: Boolean,
|
|
@@ -755,7 +807,7 @@ const gt = K.extend({
|
|
|
755
807
|
},
|
|
756
808
|
customSlots: {
|
|
757
809
|
type: Array,
|
|
758
|
-
default:
|
|
810
|
+
default: pt
|
|
759
811
|
},
|
|
760
812
|
imageBaseUrl: {
|
|
761
813
|
type: String,
|
|
@@ -766,57 +818,12 @@ const gt = K.extend({
|
|
|
766
818
|
default: void 0
|
|
767
819
|
}
|
|
768
820
|
},
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
validation() {
|
|
776
|
-
return ut(this.document, { protocolVersion: this.protocolVersion });
|
|
777
|
-
}
|
|
778
|
-
},
|
|
779
|
-
watch: {
|
|
780
|
-
validation: {
|
|
781
|
-
immediate: !0,
|
|
782
|
-
deep: !0,
|
|
783
|
-
handler(i) {
|
|
784
|
-
i.issues.forEach((r) => this.$emit("render-error", r));
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
document: {
|
|
788
|
-
deep: !0,
|
|
789
|
-
handler() {
|
|
790
|
-
this.reportedRuntimeIssues.clear();
|
|
791
|
-
}
|
|
792
|
-
},
|
|
793
|
-
protocolVersion() {
|
|
794
|
-
this.reportedRuntimeIssues.clear();
|
|
795
|
-
},
|
|
796
|
-
resolveArticleButtonLink() {
|
|
797
|
-
this.reportedRuntimeIssues.clear();
|
|
798
|
-
},
|
|
799
|
-
imageBaseUrl() {
|
|
800
|
-
this.reportedRuntimeIssues.clear();
|
|
801
|
-
}
|
|
802
|
-
},
|
|
803
|
-
methods: {
|
|
804
|
-
resolveCustomSlots() {
|
|
805
|
-
return this.customSlots.map((i) => {
|
|
806
|
-
var e, n, s, o;
|
|
807
|
-
const r = { id: i.id, location: i.location }, t = (o = (s = (n = (e = this.$scopedSlots)[i.id]) == null ? void 0 : n.call(e, r)) != null ? s : this.$slots[i.id]) != null ? o : [];
|
|
808
|
-
return A(m({}, i), { content: t });
|
|
809
|
-
});
|
|
810
|
-
},
|
|
811
|
-
reportRuntimeIssue(i) {
|
|
812
|
-
const r = ht(i);
|
|
813
|
-
this.reportedRuntimeIssues.has(r) || (this.reportedRuntimeIssues.add(r), this.$nextTick(() => this.$emit("render-error", i)));
|
|
814
|
-
}
|
|
815
|
-
},
|
|
816
|
-
render(i) {
|
|
817
|
-
const r = x(this.protocolVersion);
|
|
818
|
-
if (!r || this.strict && !this.validation.valid)
|
|
819
|
-
return i(
|
|
821
|
+
render(n, r) {
|
|
822
|
+
const { props: t } = r, e = gt(t.document, {
|
|
823
|
+
protocolVersion: t.protocolVersion
|
|
824
|
+
}), i = M(t.protocolVersion), s = [];
|
|
825
|
+
if (!i || t.strict && !e.valid) {
|
|
826
|
+
const a = n(
|
|
820
827
|
"div",
|
|
821
828
|
{
|
|
822
829
|
class: "acp-render-error",
|
|
@@ -827,38 +834,35 @@ const gt = K.extend({
|
|
|
827
834
|
},
|
|
828
835
|
"Invalid article content"
|
|
829
836
|
);
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
+
return D(n, r, [a], e.issues);
|
|
838
|
+
}
|
|
839
|
+
const o = i.render(t.document, {
|
|
840
|
+
createElement: n,
|
|
841
|
+
customSlots: ht(r),
|
|
842
|
+
imageBaseUrl: t.imageBaseUrl,
|
|
843
|
+
resolveArticleButtonLink: t.resolveArticleButtonLink,
|
|
844
|
+
emitArticleButtonClick: (a) => yt(r.listeners["article-button-click"], a),
|
|
845
|
+
reportIssue: (a) => s.push(a)
|
|
837
846
|
});
|
|
838
|
-
return
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
});
|
|
851
|
-
function pt(i, r, t, e, n, s, o, l) {
|
|
852
|
-
var c = typeof i == "function" ? i.options : i;
|
|
847
|
+
return D(n, r, o, [
|
|
848
|
+
...e.issues,
|
|
849
|
+
...s.filter(
|
|
850
|
+
(a, l, u) => u.findIndex((g) => T(g) === T(a)) === l
|
|
851
|
+
)
|
|
852
|
+
]);
|
|
853
|
+
}
|
|
854
|
+
}, bt = $.extend(kt);
|
|
855
|
+
function At(n, r, t, e, i, s, o, a) {
|
|
856
|
+
var l = typeof n == "function" ? n.options : n;
|
|
853
857
|
return {
|
|
854
|
-
exports:
|
|
855
|
-
options:
|
|
858
|
+
exports: n,
|
|
859
|
+
options: l
|
|
856
860
|
};
|
|
857
861
|
}
|
|
858
|
-
var
|
|
859
|
-
|
|
862
|
+
var It = /* @__PURE__ */ At(
|
|
863
|
+
bt
|
|
860
864
|
);
|
|
861
|
-
const
|
|
865
|
+
const Lt = It.exports, Tt = Object.freeze({
|
|
862
866
|
fileFormat: "article-content-protocol",
|
|
863
867
|
fileFormatVersion: 1,
|
|
864
868
|
mediaType: "application/vnd.article-content-protocol+json",
|
|
@@ -885,17 +889,17 @@ const mt = yt.exports, It = Object.freeze({
|
|
|
885
889
|
"text"
|
|
886
890
|
]),
|
|
887
891
|
markTypes: Object.freeze(["bold", "italic", "strike", "underline", "code", "link"])
|
|
888
|
-
}),
|
|
889
|
-
install(
|
|
890
|
-
|
|
892
|
+
}), _t = {
|
|
893
|
+
install(n) {
|
|
894
|
+
n.component("ArticleContentRenderer", Lt);
|
|
891
895
|
}
|
|
892
896
|
};
|
|
893
897
|
export {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
898
|
+
Tt as ARTICLE_CONTENT_PROTOCOL_V1,
|
|
899
|
+
Lt as ArticleContentRenderer,
|
|
900
|
+
_t as ArticleContentRendererPlugin,
|
|
901
|
+
z as CURRENT_PROTOCOL_VERSION,
|
|
902
|
+
Rt as SUPPORTED_PROTOCOL_VERSIONS,
|
|
903
|
+
Lt as default,
|
|
904
|
+
gt as validateArticleDocument
|
|
901
905
|
};
|