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