@bieberkit/plugin-pages 0.0.1 → 0.6.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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * BieberKit
3
+ *
4
+ * @file plugins/pages/src/admin/lib/taxonomy-part.ts
5
+ * @description Declares the shared taxonomy admin screens and their localized menu entries.
6
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
7
+ * @copyright Copyright (c) 2026 Bieber Kieu
8
+ * @license Apache-2.0
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ *
22
+ * SPDX-License-Identifier: Apache-2.0
23
+ */
24
+ import { AdminPart, AdminView, Locale } from "@bieberkit/admin-core";
25
+ export type TaxonomyAdminPart = AdminPart<AdminView>;
26
+ interface Labels {
27
+ readonly title: string;
28
+ readonly term: string;
29
+ readonly read: string;
30
+ readonly manage: string;
31
+ }
32
+ /** Declares the admin entry of a publication taxonomy. */
33
+ export declare function taxonomyAdmin(module: "categories" | "tags", labels: Readonly<Record<Locale, Labels>>): TaxonomyAdminPart;
34
+ export {};
@@ -0,0 +1,58 @@
1
+ import { defineAdminPlugin } from "@bieberkit/admin-core";
2
+ // src/admin/lib/taxonomy-part.ts
3
+ /**
4
+ * BieberKit
5
+ *
6
+ * @file plugins/pages/src/admin/lib/taxonomy-part.ts
7
+ * @description Declares the shared taxonomy admin screens and their localized menu entries.
8
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
9
+ * @copyright Copyright (c) 2026 Bieber Kieu
10
+ * @license Apache-2.0
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ *
24
+ * SPDX-License-Identifier: Apache-2.0
25
+ */
26
+ /** Declares the admin entry of a publication taxonomy. */
27
+ function taxonomyAdmin(module, labels) {
28
+ const path = "/" + module;
29
+ const permission = module + ".read";
30
+ const manage = module + ".manage";
31
+ const title = module + ".title";
32
+ const messages = (language) => Promise.resolve({ default: {
33
+ [title]: labels[language].title,
34
+ [module + ".term"]: labels[language].term,
35
+ [module + ".codes.permission." + permission]: labels[language].read,
36
+ [module + ".codes.permission." + manage]: labels[language].manage
37
+ } });
38
+ return defineAdminPlugin({
39
+ name: "@bieberkit/plugin-" + module,
40
+ menu: [{
41
+ page: path,
42
+ group: "content",
43
+ permission
44
+ }],
45
+ pages: [{
46
+ path,
47
+ title,
48
+ permission,
49
+ load: async () => ({ default: (await import("../pages/TaxonomyPage.js")).taxonomyPage(module) })
50
+ }],
51
+ messages: {
52
+ en: () => messages("en"),
53
+ vi: () => messages("vi"),
54
+ zh: () => messages("zh")
55
+ }
56
+ });
57
+ }
58
+ export { taxonomyAdmin };
@@ -0,0 +1,62 @@
1
+ // src/admin/lib/taxonomy.ts
2
+ /**
3
+ * BieberKit
4
+ *
5
+ * @file plugins/pages/src/admin/lib/taxonomy.ts
6
+ * @description Reads taxonomy records and their saved publication choices for the admin.
7
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
8
+ * @copyright Copyright (c) 2026 Bieber Kieu
9
+ * @license Apache-2.0
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ *
23
+ * SPDX-License-Identifier: Apache-2.0
24
+ */
25
+ const record = (value) => typeof value === "object" && value !== null;
26
+ function publicationOf(value) {
27
+ if (!record(value)) return [];
28
+ const { publicationId, kind, title } = value;
29
+ if (typeof publicationId !== "string" || kind !== "page" && kind !== "article") return [];
30
+ return [{
31
+ id: publicationId,
32
+ kind,
33
+ ...typeof title === "string" ? { title } : {}
34
+ }];
35
+ }
36
+ function termOf(value) {
37
+ if (!record(value)) return void 0;
38
+ const { id, name, slug, version, publications } = value;
39
+ if (typeof id !== "string" || typeof name !== "string" || typeof slug !== "string" || typeof version !== "number") return void 0;
40
+ return {
41
+ id,
42
+ name,
43
+ slug,
44
+ version,
45
+ publications: Array.isArray(publications) ? publications.flatMap(publicationOf) : []
46
+ };
47
+ }
48
+ function readTerm(response) {
49
+ return record(response) ? termOf(response["data"]) : void 0;
50
+ }
51
+ function readTerms(response) {
52
+ if (!record(response) || !Array.isArray(response["data"])) return {
53
+ data: [],
54
+ total: 0
55
+ };
56
+ const data = response["data"].map(termOf).filter((row) => row !== void 0);
57
+ return {
58
+ data,
59
+ total: typeof response["total"] === "number" ? response["total"] : data.length
60
+ };
61
+ }
62
+ export { readTerm, readTerms };
@@ -0,0 +1,63 @@
1
+ // src/admin/messages/en.ts
2
+ /**
3
+ * BieberKit
4
+ *
5
+ * @file plugins/pages/src/admin/messages/en.ts
6
+ * @description Labels for the pages admin screen in en.
7
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
8
+ * @copyright Copyright (c) 2026 Bieber Kieu
9
+ * @license Apache-2.0
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ *
23
+ * SPDX-License-Identifier: Apache-2.0
24
+ */
25
+ const en = {
26
+ "pages.title": "Publications",
27
+ "pages.page": "Page",
28
+ "pages.article": "Article",
29
+ "pages.createPage": "New page",
30
+ "pages.createArticle": "New article",
31
+ "pages.name": "Title",
32
+ "pages.locale": "Locale",
33
+ "pages.slug": "Slug",
34
+ "pages.excerpt": "Excerpt",
35
+ "pages.content": "Content",
36
+ "pages.load": "Load translation",
37
+ "pages.save": "Save draft",
38
+ "pages.discard": "Discard changes",
39
+ "pages.publish": "Publish",
40
+ "pages.preview": "Create preview link",
41
+ "pages.openPreview": "Open preview",
42
+ "pages.empty": "No publications",
43
+ "pages.untitled": "Untitled",
44
+ "pages.saved": "Draft saved",
45
+ "pages.published": "Published",
46
+ "pages.edit": "Edit",
47
+ "pages.choose": "Choose a publication",
48
+ "pages.retry": "Try again",
49
+ "pages.codes.permission.pages.read": "Read publications",
50
+ "pages.codes.permission.pages.manage": "Edit publications",
51
+ "pages.codes.permission.pages.publish": "Publish pages and articles",
52
+ "pages.comments": "Public comments",
53
+ "pages.commentsAfterPublish": "Publish the article before adding public comments.",
54
+ "pages.commentName": "Display name",
55
+ "pages.commentBody": "Comment",
56
+ "pages.commentAdd": "Add public comment",
57
+ "pages.commentRemove": "Remove public comment",
58
+ "pages.commentConfirm": "Remove this public comment?",
59
+ "pages.taxonomyName": "Name",
60
+ "pages.taxonomyView": "View",
61
+ "pages.taxonomyEmpty": "No publications assigned."
62
+ };
63
+ export { en };
@@ -0,0 +1,63 @@
1
+ // src/admin/messages/vi.ts
2
+ /**
3
+ * BieberKit
4
+ *
5
+ * @file plugins/pages/src/admin/messages/vi.ts
6
+ * @description Labels for the pages admin screen in vi.
7
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
8
+ * @copyright Copyright (c) 2026 Bieber Kieu
9
+ * @license Apache-2.0
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ *
23
+ * SPDX-License-Identifier: Apache-2.0
24
+ */
25
+ const vi = {
26
+ "pages.title": "Xuất bản nội dung",
27
+ "pages.page": "Trang",
28
+ "pages.article": "Bài viết",
29
+ "pages.createPage": "Trang mới",
30
+ "pages.createArticle": "Bài viết mới",
31
+ "pages.name": "Tiêu đề",
32
+ "pages.locale": "Ngôn ngữ",
33
+ "pages.slug": "Slug",
34
+ "pages.excerpt": "Tóm tắt",
35
+ "pages.content": "Nội dung",
36
+ "pages.load": "Mở bản dịch",
37
+ "pages.save": "Lưu bản nháp",
38
+ "pages.discard": "Bỏ thay đổi",
39
+ "pages.publish": "Xuất bản",
40
+ "pages.preview": "Tạo liên kết xem trước",
41
+ "pages.openPreview": "Mở bản xem trước",
42
+ "pages.empty": "Chưa có nội dung",
43
+ "pages.untitled": "Chưa có tiêu đề",
44
+ "pages.saved": "Đã lưu bản nháp",
45
+ "pages.published": "Đã xuất bản",
46
+ "pages.edit": "Sửa",
47
+ "pages.choose": "Chọn nội dung để chỉnh sửa",
48
+ "pages.retry": "Thử lại",
49
+ "pages.codes.permission.pages.read": "Xem nội dung",
50
+ "pages.codes.permission.pages.manage": "Sửa nội dung",
51
+ "pages.codes.permission.pages.publish": "Xuất bản trang và bài viết",
52
+ "pages.comments": "Bình luận công khai",
53
+ "pages.commentsAfterPublish": "Xuất bản bài viết trước khi thêm bình luận công khai.",
54
+ "pages.commentName": "Tên hiển thị",
55
+ "pages.commentBody": "Bình luận",
56
+ "pages.commentAdd": "Thêm bình luận công khai",
57
+ "pages.commentRemove": "Xóa bình luận công khai",
58
+ "pages.commentConfirm": "Xóa bình luận công khai này?",
59
+ "pages.taxonomyName": "Tên",
60
+ "pages.taxonomyView": "Xem",
61
+ "pages.taxonomyEmpty": "Chưa gắn nội dung nào."
62
+ };
63
+ export { vi };
@@ -0,0 +1,63 @@
1
+ // src/admin/messages/zh.ts
2
+ /**
3
+ * BieberKit
4
+ *
5
+ * @file plugins/pages/src/admin/messages/zh.ts
6
+ * @description Labels for the pages admin screen in zh.
7
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
8
+ * @copyright Copyright (c) 2026 Bieber Kieu
9
+ * @license Apache-2.0
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ *
23
+ * SPDX-License-Identifier: Apache-2.0
24
+ */
25
+ const zh = {
26
+ "pages.title": "内容发布",
27
+ "pages.page": "页面",
28
+ "pages.article": "文章",
29
+ "pages.createPage": "新建页面",
30
+ "pages.createArticle": "新建文章",
31
+ "pages.name": "标题",
32
+ "pages.locale": "语言",
33
+ "pages.slug": "路径名",
34
+ "pages.excerpt": "摘要",
35
+ "pages.content": "内容",
36
+ "pages.load": "打开译文",
37
+ "pages.save": "保存草稿",
38
+ "pages.discard": "放弃更改",
39
+ "pages.publish": "发布",
40
+ "pages.preview": "创建预览链接",
41
+ "pages.openPreview": "打开预览",
42
+ "pages.empty": "暂无内容",
43
+ "pages.untitled": "未命名",
44
+ "pages.saved": "草稿已保存",
45
+ "pages.published": "已发布",
46
+ "pages.edit": "编辑",
47
+ "pages.choose": "选择要编辑的内容",
48
+ "pages.retry": "重试",
49
+ "pages.codes.permission.pages.read": "查看内容",
50
+ "pages.codes.permission.pages.manage": "编辑内容",
51
+ "pages.codes.permission.pages.publish": "发布页面和文章",
52
+ "pages.comments": "公开评论",
53
+ "pages.commentsAfterPublish": "请先发布文章,再添加公开评论。",
54
+ "pages.commentName": "显示名称",
55
+ "pages.commentBody": "评论",
56
+ "pages.commentAdd": "添加公开评论",
57
+ "pages.commentRemove": "删除公开评论",
58
+ "pages.commentConfirm": "是否删除此公开评论?",
59
+ "pages.taxonomyName": "名称",
60
+ "pages.taxonomyView": "查看",
61
+ "pages.taxonomyEmpty": "尚未关联任何内容。"
62
+ };
63
+ export { zh };
@@ -0,0 +1,151 @@
1
+ import { DraftForm } from "../components/DraftForm.js";
2
+ import { draftsApi, listPublications, newPublication, publicationsKey } from "../lib/publications.js";
3
+ import { useAdminClient, useCan, useLanguage, useText } from "@bieberkit/admin-antd";
4
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
5
+ import { Alert, Button, Form, Input, Skeleton, Space, Table } from "antd";
6
+ import { useState } from "react";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ // src/admin/pages/PublicationsPage.tsx
9
+ /**
10
+ * BieberKit
11
+ *
12
+ * @file plugins/pages/src/admin/pages/PublicationsPage.tsx
13
+ * @description Lists editorial records and opens a locale-specific draft.
14
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
15
+ * @copyright Copyright (c) 2026 Bieber Kieu
16
+ * @license Apache-2.0
17
+ *
18
+ * Licensed under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License.
20
+ * You may obtain a copy of the License at
21
+ *
22
+ * http://www.apache.org/licenses/LICENSE-2.0
23
+ *
24
+ * Unless required by applicable law or agreed to in writing, software
25
+ * distributed under the License is distributed on an "AS IS" BASIS,
26
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ * See the License for the specific language governing permissions and
28
+ * limitations under the License.
29
+ *
30
+ * SPDX-License-Identifier: Apache-2.0
31
+ */
32
+ function PublicationsPage() {
33
+ const client = useAdminClient();
34
+ const cache = useQueryClient();
35
+ const text = useText();
36
+ const { locale: language } = useLanguage();
37
+ const canManage = useCan("pages.manage");
38
+ const [page, setPage] = useState(1);
39
+ const [selected, select] = useState();
40
+ const id = selected?.id;
41
+ const [locale, setLocale] = useState(language);
42
+ const list = useQuery({
43
+ queryKey: [...publicationsKey, page],
44
+ queryFn: () => listPublications(client, page)
45
+ });
46
+ const create = useMutation({
47
+ mutationFn: (kind) => newPublication(client, kind),
48
+ onSuccess: async (created, kind) => {
49
+ if (created !== void 0) select({
50
+ id: created,
51
+ kind
52
+ });
53
+ await cache.invalidateQueries({ queryKey: publicationsKey });
54
+ }
55
+ });
56
+ const draft = useQuery({
57
+ queryKey: [
58
+ ...publicationsKey,
59
+ "draft",
60
+ id,
61
+ locale
62
+ ],
63
+ queryFn: () => id === void 0 ? Promise.resolve(null) : draftsApi(client, id, locale).get(),
64
+ enabled: id !== void 0
65
+ });
66
+ const error = create.error ?? draft.error ?? list.error;
67
+ return /* @__PURE__ */ jsxs(Space, {
68
+ orientation: "vertical",
69
+ size: "large",
70
+ style: { width: "100%" },
71
+ children: [
72
+ error && /* @__PURE__ */ jsx(Alert, {
73
+ title: error.message,
74
+ type: "error",
75
+ showIcon: true,
76
+ action: /* @__PURE__ */ jsx(Button, {
77
+ type: "link",
78
+ onClick: () => {
79
+ if (list.isError) list.refetch();
80
+ if (draft.isError) draft.refetch();
81
+ create.reset();
82
+ },
83
+ children: text("pages.retry")
84
+ })
85
+ }),
86
+ canManage && /* @__PURE__ */ jsxs(Space, { children: [/* @__PURE__ */ jsx(Button, {
87
+ loading: create.isPending,
88
+ onClick: () => create.mutate("page"),
89
+ children: text("pages.createPage")
90
+ }), /* @__PURE__ */ jsx(Button, {
91
+ loading: create.isPending,
92
+ onClick: () => create.mutate("article"),
93
+ children: text("pages.createArticle")
94
+ })] }),
95
+ /* @__PURE__ */ jsx(Table, {
96
+ rowKey: "id",
97
+ loading: list.isPending,
98
+ dataSource: list.data?.data ?? [],
99
+ locale: { emptyText: text("pages.empty") },
100
+ pagination: {
101
+ current: page,
102
+ total: list.data?.total ?? 0,
103
+ pageSize: 50,
104
+ showSizeChanger: false,
105
+ onChange: setPage
106
+ },
107
+ columns: [
108
+ {
109
+ key: "title",
110
+ title: text("pages.name"),
111
+ render: (_, row) => row.title ?? text("pages.untitled")
112
+ },
113
+ {
114
+ key: "kind",
115
+ title: text("pages.content"),
116
+ render: (_, row) => text("pages." + row.kind)
117
+ },
118
+ {
119
+ key: "edit",
120
+ render: (_, row) => /* @__PURE__ */ jsx(Button, {
121
+ onClick: () => select(row),
122
+ children: text("pages.edit")
123
+ })
124
+ }
125
+ ]
126
+ }),
127
+ id === void 0 ? /* @__PURE__ */ jsx("p", { children: text("pages.choose") }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Form, {
128
+ layout: "inline",
129
+ initialValues: { locale },
130
+ onFinish: (value) => {
131
+ if (value.locale.trim() !== "") setLocale(value.locale.trim());
132
+ },
133
+ children: [/* @__PURE__ */ jsx(Form.Item, {
134
+ name: "locale",
135
+ label: text("pages.locale"),
136
+ rules: [{ required: true }],
137
+ children: /* @__PURE__ */ jsx(Input, { maxLength: 32 })
138
+ }), /* @__PURE__ */ jsx(Button, {
139
+ htmlType: "submit",
140
+ children: text("pages.load")
141
+ })]
142
+ }), draft.isPending ? /* @__PURE__ */ jsx(Skeleton, { active: true }) : draft.data !== void 0 && /* @__PURE__ */ jsx(DraftForm, {
143
+ id,
144
+ locale,
145
+ initial: draft.data,
146
+ article: selected?.kind === "article"
147
+ }, id + "/" + locale)] })
148
+ ]
149
+ });
150
+ }
151
+ export { PublicationsPage as default };