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