@blogmcp/sdk 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/review/page.d.ts +1 -1
- package/dist/core/review/page.js +1 -1
- package/dist/core/review/plan.d.ts +1 -1
- package/dist/core/review/plan.js +8 -4
- package/dist/core/review/stamp.d.ts +4 -2
- package/dist/core/review/stamp.js +47 -47
- package/package.json +3 -3
- package/src/core/review/page.ts +1 -1
- package/src/core/review/plan.ts +4 -2
- package/src/core/review/stamp.ts +18 -5
|
@@ -35,7 +35,7 @@ export declare function renderReviewStatusHtml(reason: ReviewFailureReason, opts
|
|
|
35
35
|
* to an exact version: the page holds the review token, so what runs on it must not change under it.
|
|
36
36
|
* Self-host the file (`@blogmcp/review/global`) under a strict CSP or to add Subresource Integrity.
|
|
37
37
|
*/
|
|
38
|
-
export declare const REVIEW_LAYER_SCRIPT_URL = "https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.
|
|
38
|
+
export declare const REVIEW_LAYER_SCRIPT_URL = "https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.1/dist/blogmcp-review.global.js";
|
|
39
39
|
/** Id of the JSON island `reviewBootstrapHtml` writes the session into. */
|
|
40
40
|
export declare const REVIEW_SESSION_ELEMENT_ID = "blogmcp-review-session";
|
|
41
41
|
export interface ReviewBootstrapOptions {
|
package/dist/core/review/page.js
CHANGED
|
@@ -49,7 +49,7 @@ function R(t, e = {}) {
|
|
|
49
49
|
const n = v(t, e.lang);
|
|
50
50
|
return `<section class="blogmcp-review-status" role="status" data-reason="${o(t)}"><h1>${o(n.title)}</h1><p>${o(n.body)}</p></section>`;
|
|
51
51
|
}
|
|
52
|
-
const k = "https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.
|
|
52
|
+
const k = "https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.1/dist/blogmcp-review.global.js", s = "blogmcp-review-session";
|
|
53
53
|
function b(t) {
|
|
54
54
|
return JSON.stringify(t).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
55
55
|
}
|
|
@@ -20,7 +20,7 @@ export interface ReviewPlanUnit {
|
|
|
20
20
|
type: string;
|
|
21
21
|
/** Element tags (upper case) a site may render this block as; empty = any. Unused for components. */
|
|
22
22
|
tags: readonly string[];
|
|
23
|
-
/** The block's leading text, normalised (`normalizeReviewText`); '' when it has none. */
|
|
23
|
+
/** The block's leading text, normalised (`normalizeReviewText`); '' when it has none. For a component: its children's. */
|
|
24
24
|
text: string;
|
|
25
25
|
}
|
|
26
26
|
export interface ReviewPlan {
|
package/dist/core/review/plan.js
CHANGED
|
@@ -17,15 +17,15 @@ function g(r) {
|
|
|
17
17
|
function a(r) {
|
|
18
18
|
return c(g(r)).slice(0, o);
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const d = ["H1", "H2", "H3", "H4", "H5", "H6"], u = ["P", "FIGURE", "IMG", "PICTURE"];
|
|
21
21
|
function x(r) {
|
|
22
22
|
if (!r) return { type: "span", tags: [], text: "" };
|
|
23
23
|
const e = r;
|
|
24
24
|
switch (e.type) {
|
|
25
25
|
case "heading":
|
|
26
|
-
return { type: "heading", tags:
|
|
26
|
+
return { type: "heading", tags: d, text: a(e.text ?? "") };
|
|
27
27
|
case "paragraph":
|
|
28
|
-
return { type: "paragraph", tags:
|
|
28
|
+
return { type: "paragraph", tags: u, text: a(e.text ?? "") };
|
|
29
29
|
case "list":
|
|
30
30
|
return { type: "list", tags: ["UL", "OL"], text: a(e.items?.[0]?.text ?? "") };
|
|
31
31
|
case "code":
|
|
@@ -47,7 +47,11 @@ function y(r) {
|
|
|
47
47
|
return {
|
|
48
48
|
bodyOffset: n.bodyOffset,
|
|
49
49
|
units: n.units.map(
|
|
50
|
-
(t) => t.kind === "component" ?
|
|
50
|
+
(t) => t.kind === "component" ? (
|
|
51
|
+
// A component's text is its children's (a Callout's paragraph): it pairs the component
|
|
52
|
+
// with what a site renders when that site does not mark the root `data-mdx-component`.
|
|
53
|
+
{ nodeId: t.nodeId, sourceRange: t.sourceRange, kind: "component", type: t.name, tags: [], text: a(t.children ?? "") }
|
|
54
|
+
) : { nodeId: t.nodeId, sourceRange: t.sourceRange, kind: "markdown", ...x(t.token) }
|
|
51
55
|
)
|
|
52
56
|
};
|
|
53
57
|
}
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* attribute on that element: `data-mdx-node-id`. No element is added, moved or wrapped. `restore()`
|
|
9
9
|
* takes the attributes off again.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* A component the site renders without `data-mdx-component` is paired through its children's
|
|
12
|
+
* text (its first block gets the id). Blocks that cannot be paired (a raw HTML block, a component
|
|
13
|
+
* with no text of its own and no marker, a heading the site moved into its own header) just stay
|
|
14
|
+
* unstamped: comments there fall back to
|
|
13
15
|
* quote + context (level 0), which works with any renderer. A renderer that already stamps
|
|
14
16
|
* `data-mdx-node-id` (`@blogmcp/render-embed-*`) is left as it is.
|
|
15
17
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { normalizeReviewText as
|
|
2
|
-
const w = "data-blogmcp-review-root",
|
|
3
|
-
function
|
|
4
|
-
const e = t.getAttribute(
|
|
1
|
+
import { normalizeReviewText as _ } from "./plan.js";
|
|
2
|
+
const w = "data-blogmcp-review-root", b = "data-blogmcp-review-field", L = "data-blogmcp-review-ignore", d = "data-mdx-node-id", x = "data-mdx-component", T = /^[A-Za-z0-9_.:-]{1,64}$/;
|
|
3
|
+
function p(t) {
|
|
4
|
+
const e = t.getAttribute(x);
|
|
5
5
|
return e || null;
|
|
6
6
|
}
|
|
7
7
|
const N = /* @__PURE__ */ new Set([
|
|
@@ -23,84 +23,84 @@ const N = /* @__PURE__ */ new Set([
|
|
|
23
23
|
"PICTURE",
|
|
24
24
|
"DL",
|
|
25
25
|
"DETAILS"
|
|
26
|
-
]), M = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "BLOGMCP-REVIEW"]),
|
|
27
|
-
function
|
|
26
|
+
]), M = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "BLOGMCP-REVIEW"]), P = 6, A = 12;
|
|
27
|
+
function S(t) {
|
|
28
28
|
const e = [], s = (r) => {
|
|
29
|
-
for (const
|
|
30
|
-
if (!(
|
|
31
|
-
if (
|
|
32
|
-
e.push(
|
|
29
|
+
for (const i of Array.from(r.children))
|
|
30
|
+
if (!(i.hasAttribute(L) || i.hasAttribute(b)) && !M.has(i.tagName.toUpperCase())) {
|
|
31
|
+
if (p(i) || N.has(i.tagName.toUpperCase())) {
|
|
32
|
+
e.push(i);
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
s(
|
|
35
|
+
s(i);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
return s(t), e;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
const s =
|
|
40
|
+
function R(t, e) {
|
|
41
|
+
const s = _(e.textContent ?? "").slice(0, t.length);
|
|
42
42
|
if (!t || !s) return !1;
|
|
43
|
-
const r = Math.min(t.length, s.length,
|
|
44
|
-
return r < Math.min(
|
|
43
|
+
const r = Math.min(t.length, s.length, A * 2);
|
|
44
|
+
return r < Math.min(A, t.length) ? !1 : t.slice(0, r) === s.slice(0, r);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
const s =
|
|
48
|
-
return t.kind === "component" ? s === t.type : s || t.tags.length > 0 && !t.tags.includes(e.tagName.toUpperCase()) ? !1 : t.text ?
|
|
46
|
+
function I(t, e) {
|
|
47
|
+
const s = p(e);
|
|
48
|
+
return t.kind === "component" ? s ? s === t.type : !!t.text && R(t.text, e) : s || t.tags.length > 0 && !t.tags.includes(e.tagName.toUpperCase()) ? !1 : t.text ? R(t.text, e) : t.tags.length > 0 && (t.type === "hr" || !(e.textContent ?? "").trim());
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function O(t) {
|
|
51
51
|
return t.split("/")[0] ?? "";
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const s = new Map(e.units.map((n) => [n.nodeId, n])), r = /* @__PURE__ */ new Map(),
|
|
55
|
-
if (
|
|
56
|
-
for (const n of
|
|
57
|
-
const o =
|
|
53
|
+
function y(t, e) {
|
|
54
|
+
const s = new Map(e.units.map((n) => [n.nodeId, n])), r = /* @__PURE__ */ new Map(), i = [], E = Array.from(t.querySelectorAll(`[${d}]`));
|
|
55
|
+
if (E.length > 0)
|
|
56
|
+
for (const n of E) {
|
|
57
|
+
const o = O(n.getAttribute(d) ?? "");
|
|
58
58
|
s.has(o) && !r.has(o) && r.set(o, n);
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
const n = e.units, o =
|
|
62
|
-
let
|
|
63
|
-
for (;
|
|
64
|
-
const a = n[
|
|
65
|
-
if (
|
|
66
|
-
|
|
61
|
+
const n = e.units, o = S(t);
|
|
62
|
+
let l = 0, c = 0;
|
|
63
|
+
for (; l < n.length && c < o.length; ) {
|
|
64
|
+
const a = n[l], f = o[c];
|
|
65
|
+
if (I(a, f)) {
|
|
66
|
+
f.setAttribute(d, a.nodeId), i.push(f), r.set(a.nodeId, f), l++, c++;
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
69
|
let g = null;
|
|
70
|
-
for (let m = 1; m <=
|
|
71
|
-
for (let
|
|
72
|
-
const h = m -
|
|
73
|
-
if (
|
|
74
|
-
g = [
|
|
70
|
+
for (let m = 1; m <= P && !g; m++)
|
|
71
|
+
for (let u = 0; u <= m; u++) {
|
|
72
|
+
const h = m - u;
|
|
73
|
+
if (l + u < n.length && c + h < o.length && I(n[l + u], o[c + h])) {
|
|
74
|
+
g = [u, h];
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
g ? (
|
|
78
|
+
g ? (l += g[0], c += g[1]) : l++;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
const
|
|
81
|
+
const C = (n) => {
|
|
82
82
|
let o = n instanceof Element ? n : n?.parentElement ?? null;
|
|
83
83
|
if (o = o?.closest(`[${d}]`) ?? null, !o || !t.contains(o)) return null;
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
86
|
-
const a =
|
|
87
|
-
return { id:
|
|
84
|
+
const l = O(o.getAttribute(d) ?? ""), c = s.get(l);
|
|
85
|
+
if (!c) return null;
|
|
86
|
+
const a = p(o), f = a && T.test(a) ? a : c.kind === "component" && T.test(c.type) ? c.type : o.tagName.toLowerCase();
|
|
87
|
+
return { id: l, component: f, sourceRange: { ...c.sourceRange } };
|
|
88
88
|
};
|
|
89
89
|
return {
|
|
90
90
|
level: r.size > 0 ? 1 : 0,
|
|
91
91
|
matched: r.size,
|
|
92
92
|
total: e.units.length,
|
|
93
93
|
elements: r,
|
|
94
|
-
nodeRef:
|
|
94
|
+
nodeRef: C,
|
|
95
95
|
restore() {
|
|
96
|
-
for (const n of
|
|
97
|
-
|
|
96
|
+
for (const n of i) n.removeAttribute(d);
|
|
97
|
+
i.length = 0;
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
b as REVIEW_FIELD_ATTR,
|
|
103
|
+
L as REVIEW_IGNORE_ATTR,
|
|
104
104
|
w as REVIEW_ROOT_ATTR,
|
|
105
|
-
|
|
105
|
+
y as stampReviewDom
|
|
106
106
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blogmcp/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Headless SDK for Knowledge Base blog — core client, Vue composables, Nuxt adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@blogmcp/mdx-schema": "^0.8.
|
|
78
|
-
"@blogmcp/sanitize": "^0.8.
|
|
77
|
+
"@blogmcp/mdx-schema": "^0.8.1",
|
|
78
|
+
"@blogmcp/sanitize": "^0.8.1",
|
|
79
79
|
"marked": "^15.0.7"
|
|
80
80
|
},
|
|
81
81
|
"optionalDependencies": {
|
package/src/core/review/page.ts
CHANGED
|
@@ -90,7 +90,7 @@ export function renderReviewStatusHtml(reason: ReviewFailureReason, opts: { lang
|
|
|
90
90
|
* to an exact version: the page holds the review token, so what runs on it must not change under it.
|
|
91
91
|
* Self-host the file (`@blogmcp/review/global`) under a strict CSP or to add Subresource Integrity.
|
|
92
92
|
*/
|
|
93
|
-
export const REVIEW_LAYER_SCRIPT_URL = 'https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.
|
|
93
|
+
export const REVIEW_LAYER_SCRIPT_URL = 'https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.1/dist/blogmcp-review.global.js'
|
|
94
94
|
/** Id of the JSON island `reviewBootstrapHtml` writes the session into. */
|
|
95
95
|
export const REVIEW_SESSION_ELEMENT_ID = 'blogmcp-review-session'
|
|
96
96
|
|
package/src/core/review/plan.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface ReviewPlanUnit {
|
|
|
21
21
|
type: string
|
|
22
22
|
/** Element tags (upper case) a site may render this block as; empty = any. Unused for components. */
|
|
23
23
|
tags: readonly string[]
|
|
24
|
-
/** The block's leading text, normalised (`normalizeReviewText`); '' when it has none. */
|
|
24
|
+
/** The block's leading text, normalised (`normalizeReviewText`); '' when it has none. For a component: its children's. */
|
|
25
25
|
text: string
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -110,7 +110,9 @@ export function createReviewPlan(content: string): ReviewPlan {
|
|
|
110
110
|
bodyOffset: plan.bodyOffset,
|
|
111
111
|
units: plan.units.map((u) =>
|
|
112
112
|
u.kind === 'component'
|
|
113
|
-
?
|
|
113
|
+
? // A component's text is its children's (a Callout's paragraph): it pairs the component
|
|
114
|
+
// with what a site renders when that site does not mark the root `data-mdx-component`.
|
|
115
|
+
{ nodeId: u.nodeId, sourceRange: u.sourceRange, kind: 'component', type: u.name, tags: [], text: hint(u.children ?? '') }
|
|
114
116
|
: { nodeId: u.nodeId, sourceRange: u.sourceRange, kind: 'markdown', ...describe(u.token) },
|
|
115
117
|
),
|
|
116
118
|
}
|
package/src/core/review/stamp.ts
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* attribute on that element: `data-mdx-node-id`. No element is added, moved or wrapped. `restore()`
|
|
9
9
|
* takes the attributes off again.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* A component the site renders without `data-mdx-component` is paired through its children's
|
|
12
|
+
* text (its first block gets the id). Blocks that cannot be paired (a raw HTML block, a component
|
|
13
|
+
* with no text of its own and no marker, a heading the site moved into its own header) just stay
|
|
14
|
+
* unstamped: comments there fall back to
|
|
13
15
|
* quote + context (level 0), which works with any renderer. A renderer that already stamps
|
|
14
16
|
* `data-mdx-node-id` (`@blogmcp/render-embed-*`) is left as it is.
|
|
15
17
|
*/
|
|
@@ -76,7 +78,12 @@ function textMatches(want: string, el: Element): boolean {
|
|
|
76
78
|
|
|
77
79
|
function pairs(unit: ReviewPlanUnit, el: Element): boolean {
|
|
78
80
|
const component = componentOf(el)
|
|
79
|
-
if (unit.kind === 'component')
|
|
81
|
+
if (unit.kind === 'component') {
|
|
82
|
+
if (component) return component === unit.type
|
|
83
|
+
// A site component without `data-mdx-component`: its first block, by the children's text.
|
|
84
|
+
// Components with no text of their own (a gallery) stay unpaired.
|
|
85
|
+
return !!unit.text && textMatches(unit.text, el)
|
|
86
|
+
}
|
|
80
87
|
if (component) return false
|
|
81
88
|
if (unit.tags.length > 0 && !unit.tags.includes(el.tagName.toUpperCase())) return false
|
|
82
89
|
if (unit.text) return textMatches(unit.text, el)
|
|
@@ -160,8 +167,14 @@ export function stampReviewDom(root: Element, plan: ReviewPlan): ReviewStamp {
|
|
|
160
167
|
const unit = byId.get(id)
|
|
161
168
|
if (!unit) return null
|
|
162
169
|
const named = componentOf(el)
|
|
163
|
-
// A site's own attribute value must not make the round invalid: fall back to the
|
|
164
|
-
|
|
170
|
+
// A site's own attribute value must not make the round invalid: fall back to the plan's
|
|
171
|
+
// component name (a component paired by its text), else the tag.
|
|
172
|
+
const component =
|
|
173
|
+
named && COMPONENT_RE.test(named)
|
|
174
|
+
? named
|
|
175
|
+
: unit.kind === 'component' && COMPONENT_RE.test(unit.type)
|
|
176
|
+
? unit.type
|
|
177
|
+
: el.tagName.toLowerCase()
|
|
165
178
|
return { id, component, sourceRange: { ...unit.sourceRange } }
|
|
166
179
|
}
|
|
167
180
|
|