@kizunacms/ui 0.0.0-stage → 0.1.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/LICENSE.MD +9 -0
- package/README.md +20 -2
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/admin.css +2158 -0
- package/dist/client.cjs +99 -0
- package/dist/client.d.cts +46 -0
- package/dist/client.d.mts +46 -0
- package/dist/client.mjs +45 -0
- package/dist/controls/AdminLink.cjs +21 -0
- package/dist/controls/AdminLink.d.cts +16 -0
- package/dist/controls/AdminLink.d.mts +16 -0
- package/dist/controls/AdminLink.mjs +20 -0
- package/dist/controls/Avatar.cjs +15 -0
- package/dist/controls/Avatar.d.cts +17 -0
- package/dist/controls/Avatar.d.mts +17 -0
- package/dist/controls/Avatar.mjs +14 -0
- package/dist/controls/Button.cjs +20 -0
- package/dist/controls/Button.d.cts +18 -0
- package/dist/controls/Button.d.mts +18 -0
- package/dist/controls/Button.mjs +18 -0
- package/dist/controls/ButtonTip.cjs +40 -0
- package/dist/controls/ButtonTip.mjs +39 -0
- package/dist/controls/Checkbox.cjs +27 -0
- package/dist/controls/Checkbox.d.cts +15 -0
- package/dist/controls/Checkbox.d.mts +15 -0
- package/dist/controls/Checkbox.mjs +26 -0
- package/dist/controls/ChipsInput.cjs +145 -0
- package/dist/controls/ChipsInput.mjs +143 -0
- package/dist/controls/ConfirmDialog.cjs +63 -0
- package/dist/controls/ConfirmDialog.d.cts +38 -0
- package/dist/controls/ConfirmDialog.d.mts +38 -0
- package/dist/controls/ConfirmDialog.mjs +62 -0
- package/dist/controls/Counter.cjs +18 -0
- package/dist/controls/Counter.mjs +17 -0
- package/dist/controls/InfoTip.cjs +29 -0
- package/dist/controls/InfoTip.d.cts +11 -0
- package/dist/controls/InfoTip.d.mts +11 -0
- package/dist/controls/InfoTip.mjs +28 -0
- package/dist/controls/LocalTime.cjs +62 -0
- package/dist/controls/LocalTime.d.cts +30 -0
- package/dist/controls/LocalTime.d.mts +30 -0
- package/dist/controls/LocalTime.mjs +61 -0
- package/dist/controls/Logo.cjs +56 -0
- package/dist/controls/Logo.d.cts +13 -0
- package/dist/controls/Logo.d.mts +13 -0
- package/dist/controls/Logo.mjs +54 -0
- package/dist/controls/MenuButton.cjs +118 -0
- package/dist/controls/MenuButton.d.cts +88 -0
- package/dist/controls/MenuButton.d.mts +88 -0
- package/dist/controls/MenuButton.mjs +117 -0
- package/dist/controls/Select.cjs +67 -0
- package/dist/controls/Select.d.cts +42 -0
- package/dist/controls/Select.d.mts +42 -0
- package/dist/controls/Select.mjs +66 -0
- package/dist/controls/Status.cjs +31 -0
- package/dist/controls/Status.d.cts +14 -0
- package/dist/controls/Status.d.mts +14 -0
- package/dist/controls/Status.mjs +30 -0
- package/dist/controls/TrailingButton.cjs +22 -0
- package/dist/controls/TrailingButton.d.cts +18 -0
- package/dist/controls/TrailingButton.d.mts +18 -0
- package/dist/controls/TrailingButton.mjs +21 -0
- package/dist/controls/icon.cjs +42 -0
- package/dist/controls/icon.mjs +38 -0
- package/dist/inputs/Affixed.cjs +49 -0
- package/dist/inputs/Affixed.mjs +47 -0
- package/dist/inputs/CheckboxField.cjs +22 -0
- package/dist/inputs/CheckboxField.d.cts +10 -0
- package/dist/inputs/CheckboxField.d.mts +10 -0
- package/dist/inputs/CheckboxField.mjs +21 -0
- package/dist/inputs/DateField.cjs +22 -0
- package/dist/inputs/DateField.d.cts +10 -0
- package/dist/inputs/DateField.d.mts +10 -0
- package/dist/inputs/DateField.mjs +21 -0
- package/dist/inputs/DateTimeField.cjs +56 -0
- package/dist/inputs/DateTimeField.d.cts +10 -0
- package/dist/inputs/DateTimeField.d.mts +10 -0
- package/dist/inputs/DateTimeField.mjs +55 -0
- package/dist/inputs/EmailField.cjs +20 -0
- package/dist/inputs/EmailField.d.cts +10 -0
- package/dist/inputs/EmailField.d.mts +10 -0
- package/dist/inputs/EmailField.mjs +19 -0
- package/dist/inputs/FallbackReset.cjs +23 -0
- package/dist/inputs/FallbackReset.mjs +21 -0
- package/dist/inputs/FieldFor.cjs +48 -0
- package/dist/inputs/FieldFor.d.cts +16 -0
- package/dist/inputs/FieldFor.d.mts +16 -0
- package/dist/inputs/FieldFor.mjs +46 -0
- package/dist/inputs/FieldFrame.cjs +97 -0
- package/dist/inputs/FieldFrame.d.cts +29 -0
- package/dist/inputs/FieldFrame.d.mts +29 -0
- package/dist/inputs/FieldFrame.mjs +95 -0
- package/dist/inputs/FieldList.cjs +39 -0
- package/dist/inputs/FieldList.d.cts +16 -0
- package/dist/inputs/FieldList.d.mts +16 -0
- package/dist/inputs/FieldList.mjs +38 -0
- package/dist/inputs/FileField.cjs +363 -0
- package/dist/inputs/FileField.d.cts +10 -0
- package/dist/inputs/FileField.d.mts +10 -0
- package/dist/inputs/FileField.mjs +362 -0
- package/dist/inputs/FocalPointPicker.cjs +114 -0
- package/dist/inputs/FocalPointPicker.mjs +113 -0
- package/dist/inputs/JsonField.cjs +21 -0
- package/dist/inputs/JsonField.d.cts +10 -0
- package/dist/inputs/JsonField.d.mts +10 -0
- package/dist/inputs/JsonField.mjs +20 -0
- package/dist/inputs/NumberField.cjs +42 -0
- package/dist/inputs/NumberField.d.cts +10 -0
- package/dist/inputs/NumberField.d.mts +10 -0
- package/dist/inputs/NumberField.mjs +41 -0
- package/dist/inputs/PasswordField.cjs +41 -0
- package/dist/inputs/PasswordField.d.cts +26 -0
- package/dist/inputs/PasswordField.d.mts +26 -0
- package/dist/inputs/PasswordField.mjs +39 -0
- package/dist/inputs/PickerButton.cjs +56 -0
- package/dist/inputs/PickerButton.mjs +55 -0
- package/dist/inputs/RelationshipField.cjs +162 -0
- package/dist/inputs/RelationshipField.d.cts +10 -0
- package/dist/inputs/RelationshipField.d.mts +10 -0
- package/dist/inputs/RelationshipField.mjs +161 -0
- package/dist/inputs/SelectField.cjs +79 -0
- package/dist/inputs/SelectField.d.cts +10 -0
- package/dist/inputs/SelectField.d.mts +10 -0
- package/dist/inputs/SelectField.mjs +78 -0
- package/dist/inputs/SlugField.cjs +71 -0
- package/dist/inputs/SlugField.d.cts +11 -0
- package/dist/inputs/SlugField.d.mts +11 -0
- package/dist/inputs/SlugField.mjs +69 -0
- package/dist/inputs/TextBox.cjs +41 -0
- package/dist/inputs/TextBox.d.cts +35 -0
- package/dist/inputs/TextBox.d.mts +35 -0
- package/dist/inputs/TextBox.mjs +39 -0
- package/dist/inputs/TextField.cjs +61 -0
- package/dist/inputs/TextField.d.cts +10 -0
- package/dist/inputs/TextField.d.mts +10 -0
- package/dist/inputs/TextField.mjs +60 -0
- package/dist/inputs/TitleField.cjs +76 -0
- package/dist/inputs/TitleField.mjs +75 -0
- package/dist/inputs/UrlField.cjs +20 -0
- package/dist/inputs/UrlField.d.cts +10 -0
- package/dist/inputs/UrlField.d.mts +10 -0
- package/dist/inputs/UrlField.mjs +19 -0
- package/dist/inputs/values.cjs +4 -0
- package/dist/inputs/values.d.cts +19 -0
- package/dist/inputs/values.d.mts +19 -0
- package/dist/inputs/values.mjs +4 -0
- package/dist/screens/AccountView.cjs +173 -0
- package/dist/screens/AccountView.d.cts +18 -0
- package/dist/screens/AccountView.d.mts +18 -0
- package/dist/screens/AccountView.mjs +172 -0
- package/dist/screens/AdminShell.cjs +136 -0
- package/dist/screens/AdminShell.d.cts +31 -0
- package/dist/screens/AdminShell.d.mts +31 -0
- package/dist/screens/AdminShell.mjs +135 -0
- package/dist/screens/AuthViews.cjs +260 -0
- package/dist/screens/AuthViews.d.cts +48 -0
- package/dist/screens/AuthViews.d.mts +48 -0
- package/dist/screens/AuthViews.mjs +255 -0
- package/dist/screens/CreateView.cjs +37 -0
- package/dist/screens/CreateView.d.cts +12 -0
- package/dist/screens/CreateView.d.mts +12 -0
- package/dist/screens/CreateView.mjs +36 -0
- package/dist/screens/DashboardView.cjs +39 -0
- package/dist/screens/DashboardView.d.cts +12 -0
- package/dist/screens/DashboardView.d.mts +12 -0
- package/dist/screens/DashboardView.mjs +38 -0
- package/dist/screens/DocumentForm.cjs +214 -0
- package/dist/screens/DocumentForm.d.cts +77 -0
- package/dist/screens/DocumentForm.d.mts +77 -0
- package/dist/screens/DocumentForm.mjs +213 -0
- package/dist/screens/DocumentView.cjs +53 -0
- package/dist/screens/DocumentView.d.cts +17 -0
- package/dist/screens/DocumentView.d.mts +17 -0
- package/dist/screens/DocumentView.mjs +52 -0
- package/dist/screens/FileView.cjs +74 -0
- package/dist/screens/FileView.d.cts +17 -0
- package/dist/screens/FileView.d.mts +17 -0
- package/dist/screens/FileView.mjs +73 -0
- package/dist/screens/FilesView.cjs +212 -0
- package/dist/screens/FilesView.d.cts +34 -0
- package/dist/screens/FilesView.d.mts +34 -0
- package/dist/screens/FilesView.mjs +211 -0
- package/dist/screens/GlobalView.cjs +28 -0
- package/dist/screens/GlobalView.d.cts +16 -0
- package/dist/screens/GlobalView.d.mts +16 -0
- package/dist/screens/GlobalView.mjs +27 -0
- package/dist/screens/ListParts.cjs +138 -0
- package/dist/screens/ListParts.mjs +135 -0
- package/dist/screens/ListView.cjs +155 -0
- package/dist/screens/ListView.d.cts +28 -0
- package/dist/screens/ListView.d.mts +28 -0
- package/dist/screens/ListView.mjs +154 -0
- package/dist/screens/LogoutView.cjs +45 -0
- package/dist/screens/LogoutView.d.cts +10 -0
- package/dist/screens/LogoutView.d.mts +10 -0
- package/dist/screens/LogoutView.mjs +44 -0
- package/dist/screens/MessageView.cjs +13 -0
- package/dist/screens/MessageView.d.cts +12 -0
- package/dist/screens/MessageView.d.mts +12 -0
- package/dist/screens/MessageView.mjs +12 -0
- package/dist/screens/ScreenHeader.cjs +101 -0
- package/dist/screens/ScreenHeader.d.cts +33 -0
- package/dist/screens/ScreenHeader.d.mts +33 -0
- package/dist/screens/ScreenHeader.mjs +98 -0
- package/dist/shared.cjs +55 -0
- package/dist/shared.d.cts +9 -0
- package/dist/shared.d.mts +9 -0
- package/dist/shared.mjs +9 -0
- package/dist/state/AdminProvider.cjs +188 -0
- package/dist/state/AdminProvider.d.cts +106 -0
- package/dist/state/AdminProvider.d.mts +106 -0
- package/dist/state/AdminProvider.mjs +186 -0
- package/dist/state/admin-path.cjs +132 -0
- package/dist/state/admin-path.d.cts +101 -0
- package/dist/state/admin-path.d.mts +101 -0
- package/dist/state/admin-path.mjs +131 -0
- package/dist/state/admin-sections.cjs +49 -0
- package/dist/state/admin-sections.d.cts +39 -0
- package/dist/state/admin-sections.d.mts +39 -0
- package/dist/state/admin-sections.mjs +48 -0
- package/dist/state/choice-search.cjs +95 -0
- package/dist/state/choice-search.mjs +94 -0
- package/dist/state/definition.cjs +53 -0
- package/dist/state/definition.d.cts +123 -0
- package/dist/state/definition.d.mts +123 -0
- package/dist/state/definition.mjs +48 -0
- package/dist/state/form-data.cjs +266 -0
- package/dist/state/form-data.d.cts +123 -0
- package/dist/state/form-data.d.mts +123 -0
- package/dist/state/form-data.mjs +245 -0
- package/dist/state/form-field.cjs +60 -0
- package/dist/state/form-field.d.cts +135 -0
- package/dist/state/form-field.d.mts +135 -0
- package/dist/state/form-field.mjs +56 -0
- package/dist/state/form-state.cjs +11 -0
- package/dist/state/form-state.d.cts +61 -0
- package/dist/state/form-state.d.mts +61 -0
- package/dist/state/form-state.mjs +11 -0
- package/dist/state/kept-focus.cjs +42 -0
- package/dist/state/kept-focus.mjs +41 -0
- package/dist/state/list-query.cjs +116 -0
- package/dist/state/list-query.d.cts +57 -0
- package/dist/state/list-query.d.mts +57 -0
- package/dist/state/list-query.mjs +108 -0
- package/dist/state/picker.cjs +48 -0
- package/dist/state/picker.mjs +47 -0
- package/dist/state/sidebar.cjs +15 -0
- package/dist/state/sidebar.d.cts +7 -0
- package/dist/state/sidebar.d.mts +7 -0
- package/dist/state/sidebar.mjs +14 -0
- package/dist/state/unsaved-guard.cjs +56 -0
- package/dist/state/unsaved-guard.mjs +54 -0
- package/dist/state/uploads.cjs +104 -0
- package/dist/state/uploads.mjs +102 -0
- package/package.json +89 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//#region src/state/admin-path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a path segment, and keeps one that was decoded already.
|
|
4
|
+
*/
|
|
5
|
+
const decoded = (segment) => {
|
|
6
|
+
try {
|
|
7
|
+
return decodeURIComponent(segment);
|
|
8
|
+
} catch {
|
|
9
|
+
return segment;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The screens at these paths open in place of a collection with the same name.
|
|
14
|
+
*/
|
|
15
|
+
const LOGIN_SEGMENT = "login";
|
|
16
|
+
const LOGOUT_SEGMENT = "logout";
|
|
17
|
+
const FORGOT_PASSWORD_SEGMENT = "forgot-password";
|
|
18
|
+
const RESET_PASSWORD_SEGMENT = "reset-password";
|
|
19
|
+
const ACCOUNT_SEGMENT = "account";
|
|
20
|
+
/**
|
|
21
|
+
* The screens under these paths also open in place of a collection with the same name.
|
|
22
|
+
*/
|
|
23
|
+
const GLOBALS_SEGMENT = "globals";
|
|
24
|
+
const STORAGE_SEGMENT = "storage";
|
|
25
|
+
const first = (value) => Array.isArray(value) ? value[0] : value;
|
|
26
|
+
const filled = (value) => value === void 0 || value.trim() === "" ? void 0 : value.trim();
|
|
27
|
+
const pageOf = (searchParams) => {
|
|
28
|
+
const page = Number(first(searchParams["page"]) ?? "1");
|
|
29
|
+
return Number.isInteger(page) && page > 0 ? page : 1;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Returns the screen an admin URL opens, from its path segments and query.
|
|
33
|
+
*/
|
|
34
|
+
const viewOf = (segments, searchParams, known) => {
|
|
35
|
+
const [collection, id, ...rest] = segments.map(decoded);
|
|
36
|
+
if (collection === void 0) return { kind: "home" };
|
|
37
|
+
if (id === void 0) switch (collection) {
|
|
38
|
+
case LOGIN_SEGMENT: return { kind: "login" };
|
|
39
|
+
case LOGOUT_SEGMENT: return { kind: "logout" };
|
|
40
|
+
case FORGOT_PASSWORD_SEGMENT: return { kind: "forgot" };
|
|
41
|
+
case ACCOUNT_SEGMENT: return { kind: "account" };
|
|
42
|
+
case RESET_PASSWORD_SEGMENT: {
|
|
43
|
+
const token = filled(first(searchParams["token"]));
|
|
44
|
+
return token === void 0 ? { kind: "forgot" } : {
|
|
45
|
+
kind: "reset",
|
|
46
|
+
token
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (collection === GLOBALS_SEGMENT) return id !== void 0 && rest.length === 0 && known.globals?.includes(id) === true ? {
|
|
51
|
+
kind: "global",
|
|
52
|
+
global: id,
|
|
53
|
+
section: collection
|
|
54
|
+
} : { kind: "notFound" };
|
|
55
|
+
if (collection === STORAGE_SEGMENT) {
|
|
56
|
+
const [fileId, ...beyond] = rest;
|
|
57
|
+
if (id === void 0 || known.stores?.includes(id) !== true || beyond.length > 0) return { kind: "notFound" };
|
|
58
|
+
if (fileId !== void 0) return {
|
|
59
|
+
kind: "file",
|
|
60
|
+
store: id,
|
|
61
|
+
id: fileId
|
|
62
|
+
};
|
|
63
|
+
const search = filled(first(searchParams["search"]));
|
|
64
|
+
return {
|
|
65
|
+
kind: "files",
|
|
66
|
+
store: id,
|
|
67
|
+
page: pageOf(searchParams),
|
|
68
|
+
...search === void 0 ? {} : { search }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (!known.collections.includes(collection) || rest.length > 0) return { kind: "notFound" };
|
|
72
|
+
if (id === void 0) {
|
|
73
|
+
const search = filled(first(searchParams["search"]));
|
|
74
|
+
const sort = filled(first(searchParams["sort"]));
|
|
75
|
+
return {
|
|
76
|
+
kind: "list",
|
|
77
|
+
collection,
|
|
78
|
+
page: pageOf(searchParams),
|
|
79
|
+
...search === void 0 ? {} : { search },
|
|
80
|
+
...sort === void 0 ? {} : { sort }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (id === "new") return {
|
|
84
|
+
kind: "create",
|
|
85
|
+
collection
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
kind: "document",
|
|
89
|
+
collection,
|
|
90
|
+
id
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const withQuery = (path, query) => {
|
|
94
|
+
const search = new URLSearchParams();
|
|
95
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0) search.set(key, value);
|
|
96
|
+
const text = search.toString();
|
|
97
|
+
return text === "" ? path : `${path}?${text}`;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Returns the URL of each admin screen under `adminPath`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* const hrefs = adminHrefs('/admin');
|
|
104
|
+
*
|
|
105
|
+
* hrefs.document('articles', article.id);
|
|
106
|
+
*/
|
|
107
|
+
const adminHrefs = (adminPath) => {
|
|
108
|
+
const root = adminPath.replace(/\/$/, "");
|
|
109
|
+
return {
|
|
110
|
+
login: () => `${root}/${LOGIN_SEGMENT}`,
|
|
111
|
+
logout: () => `${root}/${LOGOUT_SEGMENT}`,
|
|
112
|
+
forgot: () => `${root}/${FORGOT_PASSWORD_SEGMENT}`,
|
|
113
|
+
account: () => `${root}/${ACCOUNT_SEGMENT}`,
|
|
114
|
+
home: () => root === "" ? "/" : root,
|
|
115
|
+
list: (collection, query = {}) => withQuery(`${root}/${encodeURIComponent(collection)}`, {
|
|
116
|
+
search: query.search,
|
|
117
|
+
sort: query.sort,
|
|
118
|
+
page: query.page === void 0 || query.page === 1 ? void 0 : String(query.page)
|
|
119
|
+
}),
|
|
120
|
+
create: (collection) => `${root}/${encodeURIComponent(collection)}/new`,
|
|
121
|
+
document: (collection, id) => `${root}/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`,
|
|
122
|
+
global: (global) => `${root}/${global.section}/${encodeURIComponent(global.name)}`,
|
|
123
|
+
files: (store, query = {}) => withQuery(`${root}/${STORAGE_SEGMENT}/${encodeURIComponent(store)}`, {
|
|
124
|
+
search: query.search,
|
|
125
|
+
page: query.page === void 0 || query.page === 1 ? void 0 : String(query.page)
|
|
126
|
+
}),
|
|
127
|
+
file: (store, id) => `${root}/${STORAGE_SEGMENT}/${encodeURIComponent(store)}/${encodeURIComponent(id)}`
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
exports.adminHrefs = adminHrefs;
|
|
132
|
+
exports.viewOf = viewOf;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AdminSection } from "./definition.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/state/admin-path.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A page's query parameters, as the framework hands them to the page.
|
|
6
|
+
*/
|
|
7
|
+
type SearchParams = Record<string, string | string[] | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* The screen an admin URL opens.
|
|
10
|
+
*/
|
|
11
|
+
type AdminView = {
|
|
12
|
+
kind: 'home';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'login';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'logout';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'forgot';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'reset';
|
|
21
|
+
token: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'list';
|
|
24
|
+
collection: string;
|
|
25
|
+
page: number;
|
|
26
|
+
search?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The sort the URL asks for. The list uses its default sort when the collection has no such option.
|
|
29
|
+
*/
|
|
30
|
+
sort?: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'create';
|
|
33
|
+
collection: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'document';
|
|
36
|
+
collection: string;
|
|
37
|
+
id: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'global';
|
|
40
|
+
global: string;
|
|
41
|
+
section: AdminSection;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'files';
|
|
44
|
+
store: string;
|
|
45
|
+
page: number;
|
|
46
|
+
search?: string;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'file';
|
|
49
|
+
store: string;
|
|
50
|
+
id: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'account';
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'notFound';
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The page, search and sort in a list's URL.
|
|
58
|
+
*/
|
|
59
|
+
interface ListQuery {
|
|
60
|
+
page?: number;
|
|
61
|
+
search?: string;
|
|
62
|
+
sort?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the screen an admin URL opens, from its path segments and query.
|
|
66
|
+
*/
|
|
67
|
+
declare const viewOf: (segments: readonly string[], searchParams: SearchParams, known: {
|
|
68
|
+
collections: readonly string[];
|
|
69
|
+
globals?: readonly string[];
|
|
70
|
+
stores?: readonly string[];
|
|
71
|
+
}) => AdminView;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the URL of each admin screen under `adminPath`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const hrefs = adminHrefs('/admin');
|
|
77
|
+
*
|
|
78
|
+
* hrefs.document('articles', article.id);
|
|
79
|
+
*/
|
|
80
|
+
declare const adminHrefs: (adminPath: string) => {
|
|
81
|
+
login: () => string;
|
|
82
|
+
logout: () => string;
|
|
83
|
+
forgot: () => string;
|
|
84
|
+
account: () => string;
|
|
85
|
+
home: () => string;
|
|
86
|
+
list: (collection: string, query?: ListQuery) => string;
|
|
87
|
+
create: (collection: string) => string;
|
|
88
|
+
document: (collection: string, id: string) => string;
|
|
89
|
+
global: (global: {
|
|
90
|
+
name: string;
|
|
91
|
+
section: AdminSection;
|
|
92
|
+
}) => string;
|
|
93
|
+
files: (store: string, query?: Omit<ListQuery, "sort">) => string;
|
|
94
|
+
file: (store: string, id: string) => string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The URL of each admin screen, from `adminHrefs`.
|
|
98
|
+
*/
|
|
99
|
+
type AdminHrefs = ReturnType<typeof adminHrefs>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { AdminHrefs, AdminView, ListQuery, SearchParams, adminHrefs, viewOf };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AdminSection } from "./definition.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/state/admin-path.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A page's query parameters, as the framework hands them to the page.
|
|
6
|
+
*/
|
|
7
|
+
type SearchParams = Record<string, string | string[] | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* The screen an admin URL opens.
|
|
10
|
+
*/
|
|
11
|
+
type AdminView = {
|
|
12
|
+
kind: 'home';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'login';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'logout';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'forgot';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'reset';
|
|
21
|
+
token: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'list';
|
|
24
|
+
collection: string;
|
|
25
|
+
page: number;
|
|
26
|
+
search?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The sort the URL asks for. The list uses its default sort when the collection has no such option.
|
|
29
|
+
*/
|
|
30
|
+
sort?: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'create';
|
|
33
|
+
collection: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'document';
|
|
36
|
+
collection: string;
|
|
37
|
+
id: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'global';
|
|
40
|
+
global: string;
|
|
41
|
+
section: AdminSection;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'files';
|
|
44
|
+
store: string;
|
|
45
|
+
page: number;
|
|
46
|
+
search?: string;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'file';
|
|
49
|
+
store: string;
|
|
50
|
+
id: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'account';
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'notFound';
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The page, search and sort in a list's URL.
|
|
58
|
+
*/
|
|
59
|
+
interface ListQuery {
|
|
60
|
+
page?: number;
|
|
61
|
+
search?: string;
|
|
62
|
+
sort?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the screen an admin URL opens, from its path segments and query.
|
|
66
|
+
*/
|
|
67
|
+
declare const viewOf: (segments: readonly string[], searchParams: SearchParams, known: {
|
|
68
|
+
collections: readonly string[];
|
|
69
|
+
globals?: readonly string[];
|
|
70
|
+
stores?: readonly string[];
|
|
71
|
+
}) => AdminView;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the URL of each admin screen under `adminPath`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const hrefs = adminHrefs('/admin');
|
|
77
|
+
*
|
|
78
|
+
* hrefs.document('articles', article.id);
|
|
79
|
+
*/
|
|
80
|
+
declare const adminHrefs: (adminPath: string) => {
|
|
81
|
+
login: () => string;
|
|
82
|
+
logout: () => string;
|
|
83
|
+
forgot: () => string;
|
|
84
|
+
account: () => string;
|
|
85
|
+
home: () => string;
|
|
86
|
+
list: (collection: string, query?: ListQuery) => string;
|
|
87
|
+
create: (collection: string) => string;
|
|
88
|
+
document: (collection: string, id: string) => string;
|
|
89
|
+
global: (global: {
|
|
90
|
+
name: string;
|
|
91
|
+
section: AdminSection;
|
|
92
|
+
}) => string;
|
|
93
|
+
files: (store: string, query?: Omit<ListQuery, "sort">) => string;
|
|
94
|
+
file: (store: string, id: string) => string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The URL of each admin screen, from `adminHrefs`.
|
|
98
|
+
*/
|
|
99
|
+
type AdminHrefs = ReturnType<typeof adminHrefs>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { AdminHrefs, AdminView, ListQuery, SearchParams, adminHrefs, viewOf };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//#region src/state/admin-path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a path segment, and keeps one that was decoded already.
|
|
4
|
+
*/
|
|
5
|
+
const decoded = (segment) => {
|
|
6
|
+
try {
|
|
7
|
+
return decodeURIComponent(segment);
|
|
8
|
+
} catch {
|
|
9
|
+
return segment;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The screens at these paths open in place of a collection with the same name.
|
|
14
|
+
*/
|
|
15
|
+
const LOGIN_SEGMENT = "login";
|
|
16
|
+
const LOGOUT_SEGMENT = "logout";
|
|
17
|
+
const FORGOT_PASSWORD_SEGMENT = "forgot-password";
|
|
18
|
+
const RESET_PASSWORD_SEGMENT = "reset-password";
|
|
19
|
+
const ACCOUNT_SEGMENT = "account";
|
|
20
|
+
/**
|
|
21
|
+
* The screens under these paths also open in place of a collection with the same name.
|
|
22
|
+
*/
|
|
23
|
+
const GLOBALS_SEGMENT = "globals";
|
|
24
|
+
const STORAGE_SEGMENT = "storage";
|
|
25
|
+
const first = (value) => Array.isArray(value) ? value[0] : value;
|
|
26
|
+
const filled = (value) => value === void 0 || value.trim() === "" ? void 0 : value.trim();
|
|
27
|
+
const pageOf = (searchParams) => {
|
|
28
|
+
const page = Number(first(searchParams["page"]) ?? "1");
|
|
29
|
+
return Number.isInteger(page) && page > 0 ? page : 1;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Returns the screen an admin URL opens, from its path segments and query.
|
|
33
|
+
*/
|
|
34
|
+
const viewOf = (segments, searchParams, known) => {
|
|
35
|
+
const [collection, id, ...rest] = segments.map(decoded);
|
|
36
|
+
if (collection === void 0) return { kind: "home" };
|
|
37
|
+
if (id === void 0) switch (collection) {
|
|
38
|
+
case LOGIN_SEGMENT: return { kind: "login" };
|
|
39
|
+
case LOGOUT_SEGMENT: return { kind: "logout" };
|
|
40
|
+
case FORGOT_PASSWORD_SEGMENT: return { kind: "forgot" };
|
|
41
|
+
case ACCOUNT_SEGMENT: return { kind: "account" };
|
|
42
|
+
case RESET_PASSWORD_SEGMENT: {
|
|
43
|
+
const token = filled(first(searchParams["token"]));
|
|
44
|
+
return token === void 0 ? { kind: "forgot" } : {
|
|
45
|
+
kind: "reset",
|
|
46
|
+
token
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (collection === GLOBALS_SEGMENT) return id !== void 0 && rest.length === 0 && known.globals?.includes(id) === true ? {
|
|
51
|
+
kind: "global",
|
|
52
|
+
global: id,
|
|
53
|
+
section: collection
|
|
54
|
+
} : { kind: "notFound" };
|
|
55
|
+
if (collection === STORAGE_SEGMENT) {
|
|
56
|
+
const [fileId, ...beyond] = rest;
|
|
57
|
+
if (id === void 0 || known.stores?.includes(id) !== true || beyond.length > 0) return { kind: "notFound" };
|
|
58
|
+
if (fileId !== void 0) return {
|
|
59
|
+
kind: "file",
|
|
60
|
+
store: id,
|
|
61
|
+
id: fileId
|
|
62
|
+
};
|
|
63
|
+
const search = filled(first(searchParams["search"]));
|
|
64
|
+
return {
|
|
65
|
+
kind: "files",
|
|
66
|
+
store: id,
|
|
67
|
+
page: pageOf(searchParams),
|
|
68
|
+
...search === void 0 ? {} : { search }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (!known.collections.includes(collection) || rest.length > 0) return { kind: "notFound" };
|
|
72
|
+
if (id === void 0) {
|
|
73
|
+
const search = filled(first(searchParams["search"]));
|
|
74
|
+
const sort = filled(first(searchParams["sort"]));
|
|
75
|
+
return {
|
|
76
|
+
kind: "list",
|
|
77
|
+
collection,
|
|
78
|
+
page: pageOf(searchParams),
|
|
79
|
+
...search === void 0 ? {} : { search },
|
|
80
|
+
...sort === void 0 ? {} : { sort }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (id === "new") return {
|
|
84
|
+
kind: "create",
|
|
85
|
+
collection
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
kind: "document",
|
|
89
|
+
collection,
|
|
90
|
+
id
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const withQuery = (path, query) => {
|
|
94
|
+
const search = new URLSearchParams();
|
|
95
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0) search.set(key, value);
|
|
96
|
+
const text = search.toString();
|
|
97
|
+
return text === "" ? path : `${path}?${text}`;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Returns the URL of each admin screen under `adminPath`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* const hrefs = adminHrefs('/admin');
|
|
104
|
+
*
|
|
105
|
+
* hrefs.document('articles', article.id);
|
|
106
|
+
*/
|
|
107
|
+
const adminHrefs = (adminPath) => {
|
|
108
|
+
const root = adminPath.replace(/\/$/, "");
|
|
109
|
+
return {
|
|
110
|
+
login: () => `${root}/${LOGIN_SEGMENT}`,
|
|
111
|
+
logout: () => `${root}/${LOGOUT_SEGMENT}`,
|
|
112
|
+
forgot: () => `${root}/${FORGOT_PASSWORD_SEGMENT}`,
|
|
113
|
+
account: () => `${root}/${ACCOUNT_SEGMENT}`,
|
|
114
|
+
home: () => root === "" ? "/" : root,
|
|
115
|
+
list: (collection, query = {}) => withQuery(`${root}/${encodeURIComponent(collection)}`, {
|
|
116
|
+
search: query.search,
|
|
117
|
+
sort: query.sort,
|
|
118
|
+
page: query.page === void 0 || query.page === 1 ? void 0 : String(query.page)
|
|
119
|
+
}),
|
|
120
|
+
create: (collection) => `${root}/${encodeURIComponent(collection)}/new`,
|
|
121
|
+
document: (collection, id) => `${root}/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`,
|
|
122
|
+
global: (global) => `${root}/${global.section}/${encodeURIComponent(global.name)}`,
|
|
123
|
+
files: (store, query = {}) => withQuery(`${root}/${STORAGE_SEGMENT}/${encodeURIComponent(store)}`, {
|
|
124
|
+
search: query.search,
|
|
125
|
+
page: query.page === void 0 || query.page === 1 ? void 0 : String(query.page)
|
|
126
|
+
}),
|
|
127
|
+
file: (store, id) => `${root}/${STORAGE_SEGMENT}/${encodeURIComponent(store)}/${encodeURIComponent(id)}`
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { adminHrefs, viewOf };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/state/admin-sections.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns the sidebar's sections: Collections, each group, Settings and Files. A section with no links is left out.
|
|
4
|
+
*/
|
|
5
|
+
const adminSectionsOf = (definition, hrefs) => {
|
|
6
|
+
const collectionLink = (collection) => ({
|
|
7
|
+
key: collection.name,
|
|
8
|
+
label: collection.labels.plural,
|
|
9
|
+
href: hrefs.list(collection.name),
|
|
10
|
+
target: { collection: collection.name }
|
|
11
|
+
});
|
|
12
|
+
const globalLink = (global) => ({
|
|
13
|
+
key: `${global.section}/${global.name}`,
|
|
14
|
+
label: global.label,
|
|
15
|
+
href: hrefs.global(global),
|
|
16
|
+
target: { global: global.name }
|
|
17
|
+
});
|
|
18
|
+
const storeLink = (store) => ({
|
|
19
|
+
key: `storage/${store.name}`,
|
|
20
|
+
label: store.labels.plural,
|
|
21
|
+
href: hrefs.files(store.name),
|
|
22
|
+
target: { store: store.name }
|
|
23
|
+
});
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
title: "Collections",
|
|
27
|
+
links: definition.collections.filter((collection) => collection.group === void 0).map(collectionLink)
|
|
28
|
+
},
|
|
29
|
+
...(definition.groups ?? []).map((group) => ({
|
|
30
|
+
title: group.title,
|
|
31
|
+
links: definition.collections.filter((collection) => collection.group === group.name).map(collectionLink)
|
|
32
|
+
})),
|
|
33
|
+
{
|
|
34
|
+
title: "Settings",
|
|
35
|
+
links: (definition.globals ?? []).map(globalLink)
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "Files",
|
|
39
|
+
links: (definition.stores ?? []).map(storeLink)
|
|
40
|
+
}
|
|
41
|
+
].filter((section) => section.links.length > 0);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Returns the first link in the sidebar, or `undefined` when the sidebar has none.
|
|
45
|
+
*/
|
|
46
|
+
const firstHrefOf = (definition, hrefs) => adminSectionsOf(definition, hrefs)[0]?.links[0]?.href;
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.adminSectionsOf = adminSectionsOf;
|
|
49
|
+
exports.firstHrefOf = firstHrefOf;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AdminDefinition } from "./definition.cjs";
|
|
2
|
+
import { AdminHrefs } from "./admin-path.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/state/admin-sections.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* One link in the admin's sidebar.
|
|
7
|
+
*/
|
|
8
|
+
interface AdminNavLink {
|
|
9
|
+
key: string;
|
|
10
|
+
label: string;
|
|
11
|
+
href: string;
|
|
12
|
+
/**
|
|
13
|
+
* The collection, global or store the link opens.
|
|
14
|
+
*/
|
|
15
|
+
target: {
|
|
16
|
+
collection: string;
|
|
17
|
+
} | {
|
|
18
|
+
global: string;
|
|
19
|
+
} | {
|
|
20
|
+
store: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A titled group of links in the admin's sidebar.
|
|
25
|
+
*/
|
|
26
|
+
interface AdminNavSection {
|
|
27
|
+
title: string;
|
|
28
|
+
links: AdminNavLink[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the sidebar's sections: Collections, each group, Settings and Files. A section with no links is left out.
|
|
32
|
+
*/
|
|
33
|
+
declare const adminSectionsOf: (definition: AdminDefinition, hrefs: AdminHrefs) => AdminNavSection[];
|
|
34
|
+
/**
|
|
35
|
+
* Returns the first link in the sidebar, or `undefined` when the sidebar has none.
|
|
36
|
+
*/
|
|
37
|
+
declare const firstHrefOf: (definition: AdminDefinition, hrefs: AdminHrefs) => string | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AdminNavLink, AdminNavSection, adminSectionsOf, firstHrefOf };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AdminDefinition } from "./definition.mjs";
|
|
2
|
+
import { AdminHrefs } from "./admin-path.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/state/admin-sections.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* One link in the admin's sidebar.
|
|
7
|
+
*/
|
|
8
|
+
interface AdminNavLink {
|
|
9
|
+
key: string;
|
|
10
|
+
label: string;
|
|
11
|
+
href: string;
|
|
12
|
+
/**
|
|
13
|
+
* The collection, global or store the link opens.
|
|
14
|
+
*/
|
|
15
|
+
target: {
|
|
16
|
+
collection: string;
|
|
17
|
+
} | {
|
|
18
|
+
global: string;
|
|
19
|
+
} | {
|
|
20
|
+
store: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A titled group of links in the admin's sidebar.
|
|
25
|
+
*/
|
|
26
|
+
interface AdminNavSection {
|
|
27
|
+
title: string;
|
|
28
|
+
links: AdminNavLink[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the sidebar's sections: Collections, each group, Settings and Files. A section with no links is left out.
|
|
32
|
+
*/
|
|
33
|
+
declare const adminSectionsOf: (definition: AdminDefinition, hrefs: AdminHrefs) => AdminNavSection[];
|
|
34
|
+
/**
|
|
35
|
+
* Returns the first link in the sidebar, or `undefined` when the sidebar has none.
|
|
36
|
+
*/
|
|
37
|
+
declare const firstHrefOf: (definition: AdminDefinition, hrefs: AdminHrefs) => string | undefined;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AdminNavLink, AdminNavSection, adminSectionsOf, firstHrefOf };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/state/admin-sections.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns the sidebar's sections: Collections, each group, Settings and Files. A section with no links is left out.
|
|
4
|
+
*/
|
|
5
|
+
const adminSectionsOf = (definition, hrefs) => {
|
|
6
|
+
const collectionLink = (collection) => ({
|
|
7
|
+
key: collection.name,
|
|
8
|
+
label: collection.labels.plural,
|
|
9
|
+
href: hrefs.list(collection.name),
|
|
10
|
+
target: { collection: collection.name }
|
|
11
|
+
});
|
|
12
|
+
const globalLink = (global) => ({
|
|
13
|
+
key: `${global.section}/${global.name}`,
|
|
14
|
+
label: global.label,
|
|
15
|
+
href: hrefs.global(global),
|
|
16
|
+
target: { global: global.name }
|
|
17
|
+
});
|
|
18
|
+
const storeLink = (store) => ({
|
|
19
|
+
key: `storage/${store.name}`,
|
|
20
|
+
label: store.labels.plural,
|
|
21
|
+
href: hrefs.files(store.name),
|
|
22
|
+
target: { store: store.name }
|
|
23
|
+
});
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
title: "Collections",
|
|
27
|
+
links: definition.collections.filter((collection) => collection.group === void 0).map(collectionLink)
|
|
28
|
+
},
|
|
29
|
+
...(definition.groups ?? []).map((group) => ({
|
|
30
|
+
title: group.title,
|
|
31
|
+
links: definition.collections.filter((collection) => collection.group === group.name).map(collectionLink)
|
|
32
|
+
})),
|
|
33
|
+
{
|
|
34
|
+
title: "Settings",
|
|
35
|
+
links: (definition.globals ?? []).map(globalLink)
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "Files",
|
|
39
|
+
links: (definition.stores ?? []).map(storeLink)
|
|
40
|
+
}
|
|
41
|
+
].filter((section) => section.links.length > 0);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Returns the first link in the sidebar, or `undefined` when the sidebar has none.
|
|
45
|
+
*/
|
|
46
|
+
const firstHrefOf = (definition, hrefs) => adminSectionsOf(definition, hrefs)[0]?.links[0]?.href;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { adminSectionsOf, firstHrefOf };
|