note-blog-kit 0.1.0 → 0.2.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 +117 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/iterate-articles-9dzDflSn.d.ts +84 -0
- package/dist/iterate-articles-BeI9bBh3.d.cts +84 -0
- package/dist/next/index.cjs +376 -0
- package/dist/next/index.d.cts +102 -1
- package/dist/next/index.d.ts +102 -1
- package/dist/next/index.js +374 -0
- package/dist/react/index.cjs +316 -10
- package/dist/react/index.d.cts +84 -5
- package/dist/react/index.d.ts +84 -5
- package/dist/react/index.js +316 -11
- package/dist/server/index.cjs +354 -52
- package/dist/server/index.d.cts +19 -70
- package/dist/server/index.d.ts +19 -70
- package/dist/server/index.js +350 -53
- package/dist/styles.css +209 -0
- package/package.json +14 -13
package/dist/react/index.cjs
CHANGED
|
@@ -2,11 +2,326 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
|
|
5
|
+
// src/react/body/parse.ts
|
|
6
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
7
|
+
"p",
|
|
8
|
+
"br",
|
|
9
|
+
"h2",
|
|
10
|
+
"h3",
|
|
11
|
+
"h4",
|
|
12
|
+
"strong",
|
|
13
|
+
"em",
|
|
14
|
+
"s",
|
|
15
|
+
"a",
|
|
16
|
+
"ul",
|
|
17
|
+
"ol",
|
|
18
|
+
"li",
|
|
19
|
+
"blockquote",
|
|
20
|
+
"figure",
|
|
21
|
+
"figcaption",
|
|
22
|
+
"img",
|
|
23
|
+
"pre",
|
|
24
|
+
"code",
|
|
25
|
+
"hr",
|
|
26
|
+
"table",
|
|
27
|
+
"thead",
|
|
28
|
+
"tbody",
|
|
29
|
+
"tr",
|
|
30
|
+
"th",
|
|
31
|
+
"td",
|
|
32
|
+
"div"
|
|
33
|
+
]);
|
|
34
|
+
var DISCARD_TAGS = /* @__PURE__ */ new Set([
|
|
35
|
+
"script",
|
|
36
|
+
"style",
|
|
37
|
+
"iframe",
|
|
38
|
+
"frame",
|
|
39
|
+
"frameset",
|
|
40
|
+
"object",
|
|
41
|
+
"embed",
|
|
42
|
+
"applet",
|
|
43
|
+
"form",
|
|
44
|
+
"button",
|
|
45
|
+
"textarea",
|
|
46
|
+
"select",
|
|
47
|
+
"option",
|
|
48
|
+
"svg",
|
|
49
|
+
"math",
|
|
50
|
+
"template",
|
|
51
|
+
"noscript",
|
|
52
|
+
"title",
|
|
53
|
+
"xmp",
|
|
54
|
+
"plaintext",
|
|
55
|
+
"noembed",
|
|
56
|
+
"noframes"
|
|
57
|
+
]);
|
|
58
|
+
var VOID_TAGS = /* @__PURE__ */ new Set(["br", "hr", "img"]);
|
|
59
|
+
var NO_TEXT_TAGS = /* @__PURE__ */ new Set(["table", "thead", "tbody", "tr"]);
|
|
60
|
+
var CLOSES_P = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote", "figure", "pre", "hr", "table", "div"]);
|
|
61
|
+
var MAX_DEPTH = 128;
|
|
62
|
+
var TOKEN_RE = /<!--[\s\S]*?(?:-->|$)|<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s=>/"'<]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>"'<]+))?)*)\s*\/?>|[^<]+|</g;
|
|
63
|
+
var ATTR_RE = /([^\s=>/"'<]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"'<]+)))?/g;
|
|
64
|
+
var NAMED_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
|
|
65
|
+
function decodeEntities(text) {
|
|
66
|
+
return text.replace(/&(#x[0-9a-fA-F]{1,8}|#[0-9]{1,10}|[a-zA-Z]+);/g, (whole, name) => {
|
|
67
|
+
if (name[0] !== "#") return Object.hasOwn(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : whole;
|
|
68
|
+
const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number(name.slice(1));
|
|
69
|
+
const valid = code > 0 && code <= 1114111 && (code < 55296 || code > 57343);
|
|
70
|
+
return valid ? String.fromCodePoint(code) : "\uFFFD";
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function parseAttrs(source) {
|
|
74
|
+
const attrs = /* @__PURE__ */ Object.create(null);
|
|
75
|
+
for (const m of source.matchAll(ATTR_RE)) {
|
|
76
|
+
const name = m[1].toLowerCase();
|
|
77
|
+
if (!Object.hasOwn(attrs, name)) attrs[name] = decodeEntities(m[2] ?? m[3] ?? m[4] ?? "");
|
|
78
|
+
}
|
|
79
|
+
return attrs;
|
|
80
|
+
}
|
|
81
|
+
function parseBody(html) {
|
|
82
|
+
const root = { tag: "#root", attrs: /* @__PURE__ */ Object.create(null), children: [] };
|
|
83
|
+
const stack = [root];
|
|
84
|
+
const top = () => stack[stack.length - 1];
|
|
85
|
+
const closeTo = (tag) => {
|
|
86
|
+
for (let i = stack.length - 1; i > 0; i -= 1) {
|
|
87
|
+
if (stack[i].tag === tag) {
|
|
88
|
+
stack.length = i;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const append = (node) => {
|
|
94
|
+
if (typeof node === "string" && (NO_TEXT_TAGS.has(top().tag) || top().tag !== "pre" && node === "")) return;
|
|
95
|
+
top().children.push(node);
|
|
96
|
+
};
|
|
97
|
+
const lower = html.toLowerCase();
|
|
98
|
+
TOKEN_RE.lastIndex = 0;
|
|
99
|
+
for (let m = TOKEN_RE.exec(html); m !== null; m = TOKEN_RE.exec(html)) {
|
|
100
|
+
const [token, closing, rawName, rawAttrs] = m;
|
|
101
|
+
if (rawName === void 0) {
|
|
102
|
+
if (!token.startsWith("<!--")) append(decodeEntities(token));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const tag = rawName.toLowerCase();
|
|
106
|
+
if (DISCARD_TAGS.has(tag)) {
|
|
107
|
+
if (!closing) {
|
|
108
|
+
const end = lower.indexOf(`</${tag}`, TOKEN_RE.lastIndex);
|
|
109
|
+
TOKEN_RE.lastIndex = end === -1 ? html.length : end;
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (!ALLOWED_TAGS.has(tag)) continue;
|
|
114
|
+
if (closing) {
|
|
115
|
+
closeTo(tag);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (CLOSES_P.has(tag)) closeTo("p");
|
|
119
|
+
if (tag === "a" && stack.some((el2) => el2.tag === "a")) closeTo("a");
|
|
120
|
+
if (stack.length > MAX_DEPTH) continue;
|
|
121
|
+
if (tag === "tr" && top().tag === "table") {
|
|
122
|
+
const tbody = { tag: "tbody", attrs: /* @__PURE__ */ Object.create(null), children: [] };
|
|
123
|
+
append(tbody);
|
|
124
|
+
stack.push(tbody);
|
|
125
|
+
}
|
|
126
|
+
const el = { tag, attrs: parseAttrs(rawAttrs ?? ""), children: [] };
|
|
127
|
+
append(el);
|
|
128
|
+
if (!VOID_TAGS.has(tag)) stack.push(el);
|
|
129
|
+
}
|
|
130
|
+
return root.children;
|
|
131
|
+
}
|
|
132
|
+
|
|
5
133
|
// src/react/class-names.ts
|
|
6
134
|
function classNames(...names) {
|
|
7
135
|
return names.filter((name) => typeof name === "string" && name !== "").join(" ");
|
|
8
136
|
}
|
|
9
137
|
|
|
138
|
+
// src/react/safe-url.ts
|
|
139
|
+
function safeHttpUrl(url) {
|
|
140
|
+
if (typeof url !== "string" || !/^https?:\/\//i.test(url)) return null;
|
|
141
|
+
for (let i = 0; i < url.length; i += 1) {
|
|
142
|
+
const code = url.charCodeAt(i);
|
|
143
|
+
if (code <= 32 || code === 127) return null;
|
|
144
|
+
}
|
|
145
|
+
return url;
|
|
146
|
+
}
|
|
147
|
+
var ID_RE = /^nbk-[A-Za-z0-9\-_.:/]+$/;
|
|
148
|
+
var SAFE_VALUE = /^[A-Za-z0-9\-_.:/]+$/;
|
|
149
|
+
var IMAGE_PREFIX = "https://assets.st-note.com/";
|
|
150
|
+
var DIGITS = /^\d+$/;
|
|
151
|
+
var REL_TOKENS = /* @__PURE__ */ new Set(["nofollow", "noopener", "noreferrer", "sponsored"]);
|
|
152
|
+
var BODY_CLASS = {
|
|
153
|
+
p: "nbk-body__p",
|
|
154
|
+
h2: "nbk-body__h2",
|
|
155
|
+
h3: "nbk-body__h3",
|
|
156
|
+
h4: "nbk-body__h4",
|
|
157
|
+
a: "nbk-body__a",
|
|
158
|
+
ul: "nbk-body__ul",
|
|
159
|
+
ol: "nbk-body__ol",
|
|
160
|
+
blockquote: "nbk-body__blockquote",
|
|
161
|
+
figure: "nbk-body__figure",
|
|
162
|
+
figcaption: "nbk-body__figcaption",
|
|
163
|
+
img: "nbk-body__img",
|
|
164
|
+
pre: "nbk-body__pre",
|
|
165
|
+
code: "nbk-body__code",
|
|
166
|
+
hr: "nbk-body__hr",
|
|
167
|
+
table: "nbk-body__table",
|
|
168
|
+
th: "nbk-body__th",
|
|
169
|
+
td: "nbk-body__td"
|
|
170
|
+
};
|
|
171
|
+
function toNumber(value) {
|
|
172
|
+
return value !== void 0 && DIGITS.test(value) ? Number(value) : void 0;
|
|
173
|
+
}
|
|
174
|
+
function safeHref(value) {
|
|
175
|
+
if (value === void 0) return null;
|
|
176
|
+
if (!/^mailto:[^\s"<>]+$/i.test(value)) return safeHttpUrl(value);
|
|
177
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
178
|
+
if (value.charCodeAt(i) < 32 || value.charCodeAt(i) === 127) return null;
|
|
179
|
+
}
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
function safeHttpsUrl(value) {
|
|
183
|
+
const url = safeHttpUrl(value);
|
|
184
|
+
return url !== null && /^https:\/\//i.test(url) ? url : null;
|
|
185
|
+
}
|
|
186
|
+
function safeImageUrl(value) {
|
|
187
|
+
const url = safeHttpsUrl(value);
|
|
188
|
+
return url?.toLowerCase().startsWith(IMAGE_PREFIX) ? url : null;
|
|
189
|
+
}
|
|
190
|
+
function collectIds(nodes, ids) {
|
|
191
|
+
for (const node of nodes) {
|
|
192
|
+
if (typeof node === "string") continue;
|
|
193
|
+
if (node.attrs.id !== void 0 && ID_RE.test(node.attrs.id)) ids.add(node.attrs.id);
|
|
194
|
+
collectIds(node.children, ids);
|
|
195
|
+
}
|
|
196
|
+
return ids;
|
|
197
|
+
}
|
|
198
|
+
function DefaultToc({ items, title, linkableIds }) {
|
|
199
|
+
if (items.length === 0) return null;
|
|
200
|
+
const ids = new Set(linkableIds);
|
|
201
|
+
const seen = /* @__PURE__ */ new Map();
|
|
202
|
+
const keyOf = (id) => {
|
|
203
|
+
const count = seen.get(id) ?? 0;
|
|
204
|
+
seen.set(id, count + 1);
|
|
205
|
+
return count === 0 ? id : `${id}:${count}`;
|
|
206
|
+
};
|
|
207
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "nbk-toc", children: [
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-toc__title", children: title }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "nbk-toc__list", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
210
|
+
"li",
|
|
211
|
+
{
|
|
212
|
+
className: item.level === 2 ? "nbk-toc__item nbk-toc__item--h2" : "nbk-toc__item nbk-toc__item--h3",
|
|
213
|
+
children: ids.has(item.id) ? /* @__PURE__ */ jsxRuntime.jsx("a", { className: "nbk-toc__link", href: `#${item.id}`, children: item.text }) : item.text
|
|
214
|
+
},
|
|
215
|
+
keyOf(item.id)
|
|
216
|
+
)) })
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
function renderChildren(nodes, ctx) {
|
|
220
|
+
return nodes.map((node, index) => renderNode(node, ctx, index));
|
|
221
|
+
}
|
|
222
|
+
function renderEmbed(el, ctx, key) {
|
|
223
|
+
const service = el.attrs["data-nbk-embed-service"];
|
|
224
|
+
const embedKey = el.attrs["data-nbk-embed-key"];
|
|
225
|
+
const found = ctx.article.embeds.find((item) => item.key === embedKey);
|
|
226
|
+
const embed = found !== void 0 && safeHttpsUrl(found.url) !== null && SAFE_VALUE.test(found.service) ? found : null;
|
|
227
|
+
const children = renderChildren(el.children, { ...ctx, inEmbed: true });
|
|
228
|
+
const { embed: Embed } = ctx.components;
|
|
229
|
+
if (Embed) {
|
|
230
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Embed, { embed, service, children }, key);
|
|
231
|
+
}
|
|
232
|
+
const url = service === "note" ? safeHttpsUrl(embed?.url ?? el.attrs["data-nbk-embed-url"]) : null;
|
|
233
|
+
const { Link } = ctx;
|
|
234
|
+
return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "nbk-embed", "data-service": service, children: url === null ? children : /* @__PURE__ */ jsxRuntime.jsx(Link, { href: url, className: "nbk-embed__link", children: url }) }, key);
|
|
235
|
+
}
|
|
236
|
+
function renderNode(node, ctx, key) {
|
|
237
|
+
if (typeof node === "string") return node;
|
|
238
|
+
const { tag, attrs } = node;
|
|
239
|
+
const id = attrs.id !== void 0 && ID_RE.test(attrs.id) ? attrs.id : void 0;
|
|
240
|
+
if (tag === "div") {
|
|
241
|
+
if (!Object.hasOwn(attrs, "data-nbk-toc")) return renderChildren(node.children, ctx);
|
|
242
|
+
const Toc = ctx.components.toc ?? DefaultToc;
|
|
243
|
+
const linkableIds = ctx.article.toc.filter((item) => ctx.ids.has(item.id)).map((item) => item.id);
|
|
244
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Toc, { items: ctx.article.toc, linkableIds, title: ctx.tocTitle }, key);
|
|
245
|
+
}
|
|
246
|
+
const service = attrs["data-nbk-embed-service"];
|
|
247
|
+
if (tag === "figure" && service !== void 0 && SAFE_VALUE.test(service)) return renderEmbed(node, ctx, key);
|
|
248
|
+
if (tag === "img") {
|
|
249
|
+
const src = safeImageUrl(attrs.src);
|
|
250
|
+
if (src === null) return null;
|
|
251
|
+
const props2 = { src, alt: attrs.alt ?? "" };
|
|
252
|
+
const width = toNumber(attrs.width);
|
|
253
|
+
const height = toNumber(attrs.height);
|
|
254
|
+
if (width !== void 0) props2.width = width;
|
|
255
|
+
if (height !== void 0) props2.height = height;
|
|
256
|
+
const { img: Img } = ctx.components;
|
|
257
|
+
return Img ? /* @__PURE__ */ jsxRuntime.jsx(Img, { ...props2 }, key) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
258
|
+
"img",
|
|
259
|
+
{
|
|
260
|
+
className: BODY_CLASS.img,
|
|
261
|
+
src: props2.src,
|
|
262
|
+
alt: props2.alt,
|
|
263
|
+
width: props2.width,
|
|
264
|
+
height: props2.height,
|
|
265
|
+
loading: "lazy",
|
|
266
|
+
decoding: "async"
|
|
267
|
+
},
|
|
268
|
+
key
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const children = renderChildren(node.children, ctx);
|
|
272
|
+
if (tag === "h2" || tag === "h3" || tag === "h4") {
|
|
273
|
+
const { heading: Heading } = ctx.components;
|
|
274
|
+
if (Heading) {
|
|
275
|
+
const level = Number(tag[1]);
|
|
276
|
+
return id === void 0 ? /* @__PURE__ */ jsxRuntime.jsx(Heading, { level, children }, key) : /* @__PURE__ */ jsxRuntime.jsx(Heading, { level, id, children }, key);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const props = {};
|
|
280
|
+
if (BODY_CLASS[tag] !== void 0) props.className = BODY_CLASS[tag];
|
|
281
|
+
if (id !== void 0) props.id = id;
|
|
282
|
+
if (tag === "a") {
|
|
283
|
+
if (ctx.inEmbed) props.className = "nbk-embed__link";
|
|
284
|
+
const href = safeHref(attrs.href);
|
|
285
|
+
if (href !== null) props.href = href;
|
|
286
|
+
if (attrs.target === "_blank") props.target = "_blank";
|
|
287
|
+
const rel = (attrs.rel ?? "").split(/\s+/).filter((token) => REL_TOKENS.has(token));
|
|
288
|
+
if (props.target !== void 0) {
|
|
289
|
+
rel.push(...["nofollow", "noopener", "noreferrer"].filter((token) => !rel.includes(token)));
|
|
290
|
+
}
|
|
291
|
+
if (rel.length > 0) props.rel = rel.join(" ");
|
|
292
|
+
} else if (tag === "th" || tag === "td") {
|
|
293
|
+
const colSpan = toNumber(attrs.colspan);
|
|
294
|
+
const rowSpan = toNumber(attrs.rowspan);
|
|
295
|
+
if (colSpan !== void 0) props.colSpan = colSpan;
|
|
296
|
+
if (rowSpan !== void 0) props.rowSpan = rowSpan;
|
|
297
|
+
}
|
|
298
|
+
const Tag = tag;
|
|
299
|
+
if (tag === "br" || tag === "hr") return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...props }, key);
|
|
300
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...props, children }, key);
|
|
301
|
+
}
|
|
302
|
+
function NoteArticleBody({
|
|
303
|
+
article,
|
|
304
|
+
components = {},
|
|
305
|
+
readMoreHref,
|
|
306
|
+
linkComponent: Link = "a",
|
|
307
|
+
labels,
|
|
308
|
+
className
|
|
309
|
+
}) {
|
|
310
|
+
const nodes = parseBody(article.bodyHtml);
|
|
311
|
+
const ctx = {
|
|
312
|
+
article,
|
|
313
|
+
components,
|
|
314
|
+
Link,
|
|
315
|
+
tocTitle: labels?.toc ?? "\u76EE\u6B21",
|
|
316
|
+
ids: collectIds(nodes, /* @__PURE__ */ new Set())
|
|
317
|
+
};
|
|
318
|
+
const moreHref = article.isPartial ? readMoreHref ?? safeHttpUrl(article.url) : null;
|
|
319
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames("nbk-body", className), children: [
|
|
320
|
+
renderChildren(nodes, ctx),
|
|
321
|
+
moreHref !== null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-body__more", children: /* @__PURE__ */ jsxRuntime.jsx(Link, { href: moreHref, className: "nbk-body__more-link", children: labels?.readMore ?? "\u7D9A\u304D\u306F note \u3067" }) })
|
|
322
|
+
] });
|
|
323
|
+
}
|
|
324
|
+
|
|
10
325
|
// src/react/format-date.ts
|
|
11
326
|
var formatter = new Intl.DateTimeFormat("ja-JP", {
|
|
12
327
|
timeZone: "Asia/Tokyo",
|
|
@@ -18,16 +333,6 @@ function formatNoteDate(iso) {
|
|
|
18
333
|
const date = new Date(iso);
|
|
19
334
|
return Number.isNaN(date.getTime()) ? iso : formatter.format(date);
|
|
20
335
|
}
|
|
21
|
-
|
|
22
|
-
// src/react/safe-url.ts
|
|
23
|
-
function safeHttpUrl(url) {
|
|
24
|
-
if (typeof url !== "string" || !/^https?:\/\//i.test(url)) return null;
|
|
25
|
-
for (let i = 0; i < url.length; i += 1) {
|
|
26
|
-
const code = url.charCodeAt(i);
|
|
27
|
-
if (code <= 32 || code === 127) return null;
|
|
28
|
-
}
|
|
29
|
-
return url;
|
|
30
|
-
}
|
|
31
336
|
function NoteArticleCard({
|
|
32
337
|
article,
|
|
33
338
|
href,
|
|
@@ -98,6 +403,7 @@ function NotePagination({
|
|
|
98
403
|
] });
|
|
99
404
|
}
|
|
100
405
|
|
|
406
|
+
exports.NoteArticleBody = NoteArticleBody;
|
|
101
407
|
exports.NoteArticleCard = NoteArticleCard;
|
|
102
408
|
exports.NoteArticleList = NoteArticleList;
|
|
103
409
|
exports.NotePagination = NotePagination;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NoteArticleSummary } from '../index.cjs';
|
|
2
|
-
export {
|
|
3
|
-
import { ElementType, ReactNode, ReactElement } from 'react';
|
|
1
|
+
import { NoteArticle, NoteEmbed, NoteTocItem, NoteArticleSummary } from '../index.cjs';
|
|
2
|
+
export { NoteArticlePage, NoteAuthor, NoteEyecatch, NoteSource } from '../index.cjs';
|
|
3
|
+
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* リンクに使う要素。既定は `'a'`。
|
|
@@ -17,6 +17,85 @@ type NoteLinkComponent = ElementType<{
|
|
|
17
17
|
/** 見出しのレベル(`h2`〜`h6`) */
|
|
18
18
|
type NoteHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
19
19
|
|
|
20
|
+
/** 本文の画像を置き換えるコンポーネントの props */
|
|
21
|
+
interface NoteBodyImageProps {
|
|
22
|
+
/** 画像 URL(note の CDN の https の URL だけが渡される) */
|
|
23
|
+
src: string;
|
|
24
|
+
/** 代替テキスト(空文字は装飾画像) */
|
|
25
|
+
alt: string;
|
|
26
|
+
/** 幅(px)。本文の値が数字だけのときに渡る */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** 高さ(px)。本文の値が数字だけのときに渡る */
|
|
29
|
+
height?: number;
|
|
30
|
+
}
|
|
31
|
+
/** 本文の見出しを置き換えるコンポーネントの props */
|
|
32
|
+
interface NoteBodyHeadingProps {
|
|
33
|
+
/** 見出しのレベル(本文に出るのは h2〜h4。{@link NoteHeadingLevel} とは別) */
|
|
34
|
+
level: 2 | 3 | 4;
|
|
35
|
+
/** 目次のリンク先になる id(nbk- から始まる) */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** 見出しの中身 */
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/** 本文の埋め込みを置き換えるコンポーネントの props */
|
|
41
|
+
interface NoteBodyEmbedProps {
|
|
42
|
+
/** `article.embeds` の中で key が一致するもの。見つからないとき、URL が https でないとき、種類に許可しない文字があるときは null */
|
|
43
|
+
embed: NoteEmbed | null;
|
|
44
|
+
/** 埋め込みの種類(`note`・`external-article` など) */
|
|
45
|
+
service: NoteEmbed['service'];
|
|
46
|
+
/** 既定の中身(外部記事ならリンクカード。note の埋め込みは空) */
|
|
47
|
+
children?: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
/** 目次(本文中の目次の位置)を置き換えるコンポーネントの props */
|
|
50
|
+
interface NoteBodyTocProps {
|
|
51
|
+
/** `article.toc`(有料記事では有料部分の見出しも含む) */
|
|
52
|
+
items: NoteTocItem[];
|
|
53
|
+
/** 本文に見出しがある項目の id(ページ内リンクにできるもの) */
|
|
54
|
+
linkableIds: string[];
|
|
55
|
+
/** 見出しの文言(`labels.toc`、既定は「目次」) */
|
|
56
|
+
title: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
/** {@link NoteArticleBody} で置き換えられる要素 */
|
|
59
|
+
interface NoteBodyComponents {
|
|
60
|
+
/** 画像。置き換えると既定のクラス名と遅延読み込み(loading・decoding)は付かない */
|
|
61
|
+
img?: ComponentType<NoteBodyImageProps>;
|
|
62
|
+
/** 見出し(h2〜h4)。置き換えると既定のクラス名は付かない */
|
|
63
|
+
heading?: ComponentType<NoteBodyHeadingProps>;
|
|
64
|
+
/** 埋め込み(note の記事・外部記事など) */
|
|
65
|
+
embed?: ComponentType<NoteBodyEmbedProps>;
|
|
66
|
+
/** 本文中の目次の位置に出すもの */
|
|
67
|
+
toc?: ComponentType<NoteBodyTocProps>;
|
|
68
|
+
}
|
|
69
|
+
/** {@link NoteArticleBody} の props */
|
|
70
|
+
interface NoteArticleBodyProps {
|
|
71
|
+
/** 表示する記事(`getArticle` で取得したもの) */
|
|
72
|
+
article: NoteArticle;
|
|
73
|
+
/** 本文の要素を任意のコンポーネントに置き換える */
|
|
74
|
+
components?: NoteBodyComponents;
|
|
75
|
+
/**
|
|
76
|
+
* 「続きは note で」のリンク先。既定は `article.url`(http(s) でなければ出さない)。`isPartial` でなければ使わない。
|
|
77
|
+
* 利用者が渡す値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を渡さないこと。
|
|
78
|
+
* React 18 はこうした値をブロックしない
|
|
79
|
+
*/
|
|
80
|
+
readMoreHref?: string;
|
|
81
|
+
/** 「続きは note で」と note の埋め込みのリンクに使う要素。既定は `'a'` */
|
|
82
|
+
linkComponent?: NoteLinkComponent;
|
|
83
|
+
/** 文言の差し替え。既定は「続きは note で」「目次」 */
|
|
84
|
+
labels?: {
|
|
85
|
+
readMore?: ReactNode;
|
|
86
|
+
toc?: ReactNode;
|
|
87
|
+
};
|
|
88
|
+
/** 既定のクラス名(`nbk-body`)に追加するクラス名 */
|
|
89
|
+
className?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記事の本文。`getArticle` が返すサニタイズ済みの `bodyHtml` を React 要素として描画する
|
|
93
|
+
* (`dangerouslySetInnerHTML` は使わず、ここでも許可したタグ・属性だけを描画する)。
|
|
94
|
+
* 有料記事(`isPartial`)では、本文の後に「続きは note で」リンクを出す。
|
|
95
|
+
* 見た目は持たず、`nbk-body` から始まるクラス名を付ける。フックを使わないため、Server Component としても使える。
|
|
96
|
+
*/
|
|
97
|
+
declare function NoteArticleBody({ article, components, readMoreHref, linkComponent: Link, labels, className, }: NoteArticleBodyProps): ReactElement;
|
|
98
|
+
|
|
20
99
|
/** {@link NoteArticleCard} の props */
|
|
21
100
|
interface NoteArticleCardProps {
|
|
22
101
|
/** 表示する記事(`listArticles` などで取得したもの) */
|
|
@@ -107,5 +186,5 @@ interface NotePaginationProps {
|
|
|
107
186
|
*/
|
|
108
187
|
declare function NotePagination({ page, isLastPage, totalCount, perPage, getHref, linkComponent: Link, labels, className, }: NotePaginationProps): ReactElement;
|
|
109
188
|
|
|
110
|
-
export { NoteArticleCard, NoteArticleList, NoteArticleSummary, NotePagination };
|
|
111
|
-
export type { NoteArticleCardProps, NoteArticleListProps, NoteHeadingLevel, NoteLinkComponent, NotePaginationProps };
|
|
189
|
+
export { NoteArticle, NoteArticleBody, NoteArticleCard, NoteArticleList, NoteArticleSummary, NoteEmbed, NotePagination, NoteTocItem };
|
|
190
|
+
export type { NoteArticleBodyProps, NoteArticleCardProps, NoteArticleListProps, NoteBodyComponents, NoteBodyEmbedProps, NoteBodyHeadingProps, NoteBodyImageProps, NoteBodyTocProps, NoteHeadingLevel, NoteLinkComponent, NotePaginationProps };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NoteArticleSummary } from '../index.js';
|
|
2
|
-
export {
|
|
3
|
-
import { ElementType, ReactNode, ReactElement } from 'react';
|
|
1
|
+
import { NoteArticle, NoteEmbed, NoteTocItem, NoteArticleSummary } from '../index.js';
|
|
2
|
+
export { NoteArticlePage, NoteAuthor, NoteEyecatch, NoteSource } from '../index.js';
|
|
3
|
+
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* リンクに使う要素。既定は `'a'`。
|
|
@@ -17,6 +17,85 @@ type NoteLinkComponent = ElementType<{
|
|
|
17
17
|
/** 見出しのレベル(`h2`〜`h6`) */
|
|
18
18
|
type NoteHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
19
19
|
|
|
20
|
+
/** 本文の画像を置き換えるコンポーネントの props */
|
|
21
|
+
interface NoteBodyImageProps {
|
|
22
|
+
/** 画像 URL(note の CDN の https の URL だけが渡される) */
|
|
23
|
+
src: string;
|
|
24
|
+
/** 代替テキスト(空文字は装飾画像) */
|
|
25
|
+
alt: string;
|
|
26
|
+
/** 幅(px)。本文の値が数字だけのときに渡る */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** 高さ(px)。本文の値が数字だけのときに渡る */
|
|
29
|
+
height?: number;
|
|
30
|
+
}
|
|
31
|
+
/** 本文の見出しを置き換えるコンポーネントの props */
|
|
32
|
+
interface NoteBodyHeadingProps {
|
|
33
|
+
/** 見出しのレベル(本文に出るのは h2〜h4。{@link NoteHeadingLevel} とは別) */
|
|
34
|
+
level: 2 | 3 | 4;
|
|
35
|
+
/** 目次のリンク先になる id(nbk- から始まる) */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** 見出しの中身 */
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/** 本文の埋め込みを置き換えるコンポーネントの props */
|
|
41
|
+
interface NoteBodyEmbedProps {
|
|
42
|
+
/** `article.embeds` の中で key が一致するもの。見つからないとき、URL が https でないとき、種類に許可しない文字があるときは null */
|
|
43
|
+
embed: NoteEmbed | null;
|
|
44
|
+
/** 埋め込みの種類(`note`・`external-article` など) */
|
|
45
|
+
service: NoteEmbed['service'];
|
|
46
|
+
/** 既定の中身(外部記事ならリンクカード。note の埋め込みは空) */
|
|
47
|
+
children?: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
/** 目次(本文中の目次の位置)を置き換えるコンポーネントの props */
|
|
50
|
+
interface NoteBodyTocProps {
|
|
51
|
+
/** `article.toc`(有料記事では有料部分の見出しも含む) */
|
|
52
|
+
items: NoteTocItem[];
|
|
53
|
+
/** 本文に見出しがある項目の id(ページ内リンクにできるもの) */
|
|
54
|
+
linkableIds: string[];
|
|
55
|
+
/** 見出しの文言(`labels.toc`、既定は「目次」) */
|
|
56
|
+
title: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
/** {@link NoteArticleBody} で置き換えられる要素 */
|
|
59
|
+
interface NoteBodyComponents {
|
|
60
|
+
/** 画像。置き換えると既定のクラス名と遅延読み込み(loading・decoding)は付かない */
|
|
61
|
+
img?: ComponentType<NoteBodyImageProps>;
|
|
62
|
+
/** 見出し(h2〜h4)。置き換えると既定のクラス名は付かない */
|
|
63
|
+
heading?: ComponentType<NoteBodyHeadingProps>;
|
|
64
|
+
/** 埋め込み(note の記事・外部記事など) */
|
|
65
|
+
embed?: ComponentType<NoteBodyEmbedProps>;
|
|
66
|
+
/** 本文中の目次の位置に出すもの */
|
|
67
|
+
toc?: ComponentType<NoteBodyTocProps>;
|
|
68
|
+
}
|
|
69
|
+
/** {@link NoteArticleBody} の props */
|
|
70
|
+
interface NoteArticleBodyProps {
|
|
71
|
+
/** 表示する記事(`getArticle` で取得したもの) */
|
|
72
|
+
article: NoteArticle;
|
|
73
|
+
/** 本文の要素を任意のコンポーネントに置き換える */
|
|
74
|
+
components?: NoteBodyComponents;
|
|
75
|
+
/**
|
|
76
|
+
* 「続きは note で」のリンク先。既定は `article.url`(http(s) でなければ出さない)。`isPartial` でなければ使わない。
|
|
77
|
+
* 利用者が渡す値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を渡さないこと。
|
|
78
|
+
* React 18 はこうした値をブロックしない
|
|
79
|
+
*/
|
|
80
|
+
readMoreHref?: string;
|
|
81
|
+
/** 「続きは note で」と note の埋め込みのリンクに使う要素。既定は `'a'` */
|
|
82
|
+
linkComponent?: NoteLinkComponent;
|
|
83
|
+
/** 文言の差し替え。既定は「続きは note で」「目次」 */
|
|
84
|
+
labels?: {
|
|
85
|
+
readMore?: ReactNode;
|
|
86
|
+
toc?: ReactNode;
|
|
87
|
+
};
|
|
88
|
+
/** 既定のクラス名(`nbk-body`)に追加するクラス名 */
|
|
89
|
+
className?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記事の本文。`getArticle` が返すサニタイズ済みの `bodyHtml` を React 要素として描画する
|
|
93
|
+
* (`dangerouslySetInnerHTML` は使わず、ここでも許可したタグ・属性だけを描画する)。
|
|
94
|
+
* 有料記事(`isPartial`)では、本文の後に「続きは note で」リンクを出す。
|
|
95
|
+
* 見た目は持たず、`nbk-body` から始まるクラス名を付ける。フックを使わないため、Server Component としても使える。
|
|
96
|
+
*/
|
|
97
|
+
declare function NoteArticleBody({ article, components, readMoreHref, linkComponent: Link, labels, className, }: NoteArticleBodyProps): ReactElement;
|
|
98
|
+
|
|
20
99
|
/** {@link NoteArticleCard} の props */
|
|
21
100
|
interface NoteArticleCardProps {
|
|
22
101
|
/** 表示する記事(`listArticles` などで取得したもの) */
|
|
@@ -107,5 +186,5 @@ interface NotePaginationProps {
|
|
|
107
186
|
*/
|
|
108
187
|
declare function NotePagination({ page, isLastPage, totalCount, perPage, getHref, linkComponent: Link, labels, className, }: NotePaginationProps): ReactElement;
|
|
109
188
|
|
|
110
|
-
export { NoteArticleCard, NoteArticleList, NoteArticleSummary, NotePagination };
|
|
111
|
-
export type { NoteArticleCardProps, NoteArticleListProps, NoteHeadingLevel, NoteLinkComponent, NotePaginationProps };
|
|
189
|
+
export { NoteArticle, NoteArticleBody, NoteArticleCard, NoteArticleList, NoteArticleSummary, NoteEmbed, NotePagination, NoteTocItem };
|
|
190
|
+
export type { NoteArticleBodyProps, NoteArticleCardProps, NoteArticleListProps, NoteBodyComponents, NoteBodyEmbedProps, NoteBodyHeadingProps, NoteBodyImageProps, NoteBodyTocProps, NoteHeadingLevel, NoteLinkComponent, NotePaginationProps };
|