@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,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_AdminProvider = require("./AdminProvider.cjs");
|
|
4
|
+
const require_form_state = require("./form-state.cjs");
|
|
5
|
+
const require_form_data = require("./form-data.cjs");
|
|
6
|
+
let react = require("react");
|
|
7
|
+
//#region src/state/choice-search.ts
|
|
8
|
+
const SEARCH_DELAY = 250;
|
|
9
|
+
/**
|
|
10
|
+
* How close to the end of the list, in pixels, the next page starts loading.
|
|
11
|
+
*/
|
|
12
|
+
const PAGE_IN_DISTANCE = 48;
|
|
13
|
+
/**
|
|
14
|
+
* Searches what a relationship or file field picks from as the editor types, and loads more as the list scrolls.
|
|
15
|
+
*/
|
|
16
|
+
const useChoiceSearch = (field) => {
|
|
17
|
+
const { action } = require_AdminProvider.useAdmin();
|
|
18
|
+
const firstPage = field.options ?? [];
|
|
19
|
+
const firstResults = {
|
|
20
|
+
search: "",
|
|
21
|
+
ids: firstPage.map((option) => option.value),
|
|
22
|
+
total: field.optionCount ?? firstPage.length
|
|
23
|
+
};
|
|
24
|
+
const [known, setKnown] = (0, react.useState)(() => new Map([...field.selected ?? [], ...firstPage].map((option) => [option.value, option])));
|
|
25
|
+
const [results, setResults] = (0, react.useState)(firstResults);
|
|
26
|
+
const [search, setSearch] = (0, react.useState)("");
|
|
27
|
+
const [loading, setLoading] = (0, react.useState)(false);
|
|
28
|
+
const latest = (0, react.useRef)(0);
|
|
29
|
+
const load = async (text, offset) => {
|
|
30
|
+
const target = field.input === "file" ? field.store : field.to;
|
|
31
|
+
if (target === void 0) return;
|
|
32
|
+
latest.current += 1;
|
|
33
|
+
const request = latest.current;
|
|
34
|
+
setLoading(true);
|
|
35
|
+
const formData = new FormData();
|
|
36
|
+
formData.set("$intent", require_form_data.SEARCH_INTENT);
|
|
37
|
+
formData.set(field.input === "file" ? "$store" : "$collection", target);
|
|
38
|
+
formData.set("search", text);
|
|
39
|
+
formData.set("offset", String(offset));
|
|
40
|
+
const answer = await action(require_form_state.INITIAL_FORM_STATE, formData).catch(() => require_form_state.INITIAL_FORM_STATE);
|
|
41
|
+
if (request !== latest.current) return;
|
|
42
|
+
setLoading(false);
|
|
43
|
+
const choices = answer.choices;
|
|
44
|
+
if (choices === void 0) return;
|
|
45
|
+
setKnown((before) => new Map([...before, ...choices.options.map((option) => [option.value, option])]));
|
|
46
|
+
const ids = choices.options.map((option) => option.value);
|
|
47
|
+
setResults((shown) => ({
|
|
48
|
+
search: text,
|
|
49
|
+
ids: offset === 0 ? ids : [...shown.ids, ...ids],
|
|
50
|
+
total: choices.total
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
(0, react.useEffect)(() => {
|
|
54
|
+
if (search === "") {
|
|
55
|
+
latest.current += 1;
|
|
56
|
+
setLoading(false);
|
|
57
|
+
setResults(firstResults);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const timer = setTimeout(() => void load(search, 0), SEARCH_DELAY);
|
|
61
|
+
return () => clearTimeout(timer);
|
|
62
|
+
}, [search]);
|
|
63
|
+
const pageIn = (event) => {
|
|
64
|
+
const list = event.currentTarget;
|
|
65
|
+
if (loading || results.ids.length >= results.total) return;
|
|
66
|
+
if (list.scrollTop + list.clientHeight >= list.scrollHeight - PAGE_IN_DISTANCE) load(results.search, results.ids.length);
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Keeps a file the editor just uploaded, so the field can show it.
|
|
70
|
+
*/
|
|
71
|
+
const remember = (option) => setKnown((before) => new Map([...before, [option.value, option]]));
|
|
72
|
+
const searching = search !== results.search;
|
|
73
|
+
return {
|
|
74
|
+
known,
|
|
75
|
+
ids: searching ? [] : results.ids,
|
|
76
|
+
search,
|
|
77
|
+
setSearch,
|
|
78
|
+
/**
|
|
79
|
+
* Whether a search or the next page is on its way.
|
|
80
|
+
*/
|
|
81
|
+
loading: loading || searching,
|
|
82
|
+
/**
|
|
83
|
+
* Whether the list shows what the editor typed, so an empty one means nothing matches.
|
|
84
|
+
*/
|
|
85
|
+
settled: !loading && !searching,
|
|
86
|
+
pageIn,
|
|
87
|
+
remember,
|
|
88
|
+
labelOf: (id) => {
|
|
89
|
+
const option = known.get(id);
|
|
90
|
+
return option?.filename ?? option?.label ?? id;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.useChoiceSearch = useChoiceSearch;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useAdmin } from "./AdminProvider.mjs";
|
|
3
|
+
import { INITIAL_FORM_STATE } from "./form-state.mjs";
|
|
4
|
+
import { SEARCH_INTENT } from "./form-data.mjs";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
//#region src/state/choice-search.ts
|
|
7
|
+
const SEARCH_DELAY = 250;
|
|
8
|
+
/**
|
|
9
|
+
* How close to the end of the list, in pixels, the next page starts loading.
|
|
10
|
+
*/
|
|
11
|
+
const PAGE_IN_DISTANCE = 48;
|
|
12
|
+
/**
|
|
13
|
+
* Searches what a relationship or file field picks from as the editor types, and loads more as the list scrolls.
|
|
14
|
+
*/
|
|
15
|
+
const useChoiceSearch = (field) => {
|
|
16
|
+
const { action } = useAdmin();
|
|
17
|
+
const firstPage = field.options ?? [];
|
|
18
|
+
const firstResults = {
|
|
19
|
+
search: "",
|
|
20
|
+
ids: firstPage.map((option) => option.value),
|
|
21
|
+
total: field.optionCount ?? firstPage.length
|
|
22
|
+
};
|
|
23
|
+
const [known, setKnown] = useState(() => new Map([...field.selected ?? [], ...firstPage].map((option) => [option.value, option])));
|
|
24
|
+
const [results, setResults] = useState(firstResults);
|
|
25
|
+
const [search, setSearch] = useState("");
|
|
26
|
+
const [loading, setLoading] = useState(false);
|
|
27
|
+
const latest = useRef(0);
|
|
28
|
+
const load = async (text, offset) => {
|
|
29
|
+
const target = field.input === "file" ? field.store : field.to;
|
|
30
|
+
if (target === void 0) return;
|
|
31
|
+
latest.current += 1;
|
|
32
|
+
const request = latest.current;
|
|
33
|
+
setLoading(true);
|
|
34
|
+
const formData = new FormData();
|
|
35
|
+
formData.set("$intent", SEARCH_INTENT);
|
|
36
|
+
formData.set(field.input === "file" ? "$store" : "$collection", target);
|
|
37
|
+
formData.set("search", text);
|
|
38
|
+
formData.set("offset", String(offset));
|
|
39
|
+
const answer = await action(INITIAL_FORM_STATE, formData).catch(() => INITIAL_FORM_STATE);
|
|
40
|
+
if (request !== latest.current) return;
|
|
41
|
+
setLoading(false);
|
|
42
|
+
const choices = answer.choices;
|
|
43
|
+
if (choices === void 0) return;
|
|
44
|
+
setKnown((before) => new Map([...before, ...choices.options.map((option) => [option.value, option])]));
|
|
45
|
+
const ids = choices.options.map((option) => option.value);
|
|
46
|
+
setResults((shown) => ({
|
|
47
|
+
search: text,
|
|
48
|
+
ids: offset === 0 ? ids : [...shown.ids, ...ids],
|
|
49
|
+
total: choices.total
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (search === "") {
|
|
54
|
+
latest.current += 1;
|
|
55
|
+
setLoading(false);
|
|
56
|
+
setResults(firstResults);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const timer = setTimeout(() => void load(search, 0), SEARCH_DELAY);
|
|
60
|
+
return () => clearTimeout(timer);
|
|
61
|
+
}, [search]);
|
|
62
|
+
const pageIn = (event) => {
|
|
63
|
+
const list = event.currentTarget;
|
|
64
|
+
if (loading || results.ids.length >= results.total) return;
|
|
65
|
+
if (list.scrollTop + list.clientHeight >= list.scrollHeight - PAGE_IN_DISTANCE) load(results.search, results.ids.length);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Keeps a file the editor just uploaded, so the field can show it.
|
|
69
|
+
*/
|
|
70
|
+
const remember = (option) => setKnown((before) => new Map([...before, [option.value, option]]));
|
|
71
|
+
const searching = search !== results.search;
|
|
72
|
+
return {
|
|
73
|
+
known,
|
|
74
|
+
ids: searching ? [] : results.ids,
|
|
75
|
+
search,
|
|
76
|
+
setSearch,
|
|
77
|
+
/**
|
|
78
|
+
* Whether a search or the next page is on its way.
|
|
79
|
+
*/
|
|
80
|
+
loading: loading || searching,
|
|
81
|
+
/**
|
|
82
|
+
* Whether the list shows what the editor typed, so an empty one means nothing matches.
|
|
83
|
+
*/
|
|
84
|
+
settled: !loading && !searching,
|
|
85
|
+
pageIn,
|
|
86
|
+
remember,
|
|
87
|
+
labelOf: (id) => {
|
|
88
|
+
const option = known.get(id);
|
|
89
|
+
return option?.filename ?? option?.label ?? id;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { useChoiceSearch };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/state/definition.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns a document's title, or its id when it has none.
|
|
4
|
+
*/
|
|
5
|
+
const titleOf = (collection, document) => {
|
|
6
|
+
const title = collection.titleField === void 0 ? void 0 : document[collection.titleField];
|
|
7
|
+
return typeof title === "string" && title.trim() !== "" ? title : String(document["id"] ?? "");
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Returns the editor a document's `createdBy` or `updatedBy` names, or `undefined` when it names none.
|
|
11
|
+
*/
|
|
12
|
+
const changedByOf = (value) => {
|
|
13
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
14
|
+
const { id, name } = value;
|
|
15
|
+
return typeof id === "string" && typeof name === "string" ? {
|
|
16
|
+
id,
|
|
17
|
+
name
|
|
18
|
+
} : void 0;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns a label as it reads inside a sentence, with its first letter in lowercase. A label that starts with an
|
|
22
|
+
* acronym keeps its capitals.
|
|
23
|
+
*/
|
|
24
|
+
const inSentence = (label) => /^[A-Z][A-Z]/.test(label) ? label : label.charAt(0).toLowerCase() + label.slice(1);
|
|
25
|
+
/**
|
|
26
|
+
* Returns the first letters of a name's first and last words.
|
|
27
|
+
*/
|
|
28
|
+
const initialsOf = (name) => {
|
|
29
|
+
const words = name.trim().split(/\s+/).filter((word) => word !== "");
|
|
30
|
+
return `${words[0]?.charAt(0) ?? ""}${words.length > 1 ? words.at(-1)?.charAt(0) ?? "" : ""}`.toUpperCase();
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Returns a role's name in words, like "Careers editor" for `careersEditor`.
|
|
34
|
+
*/
|
|
35
|
+
const roleLabelOf = (role) => {
|
|
36
|
+
const words = role.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
|
|
37
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns the fields the first account fills in beside its email and password: the editors collection's required fields.
|
|
41
|
+
*/
|
|
42
|
+
const setupFieldsOf = (definition) => (definition.collections.find((collection) => collection.login?.admin === true)?.fields ?? []).filter((field) => field.required && !field.readOnly && ![
|
|
43
|
+
"email",
|
|
44
|
+
"password",
|
|
45
|
+
"roles"
|
|
46
|
+
].includes(field.name));
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.changedByOf = changedByOf;
|
|
49
|
+
exports.inSentence = inSentence;
|
|
50
|
+
exports.initialsOf = initialsOf;
|
|
51
|
+
exports.roleLabelOf = roleLabelOf;
|
|
52
|
+
exports.setupFieldsOf = setupFieldsOf;
|
|
53
|
+
exports.titleOf = titleOf;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { FormField } from "./form-field.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/state/definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The words the admin uses for one document and for several.
|
|
6
|
+
*/
|
|
7
|
+
interface Labels {
|
|
8
|
+
singular: string;
|
|
9
|
+
plural: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A collection as the admin shows it.
|
|
13
|
+
*/
|
|
14
|
+
interface AdminCollection {
|
|
15
|
+
name: string;
|
|
16
|
+
labels: Labels;
|
|
17
|
+
/**
|
|
18
|
+
* The sidebar group the collection sits in.
|
|
19
|
+
*
|
|
20
|
+
* @default the Collections section, above every group
|
|
21
|
+
*/
|
|
22
|
+
group?: string;
|
|
23
|
+
fields: FormField[];
|
|
24
|
+
/**
|
|
25
|
+
* The field that names a document in lists and headers.
|
|
26
|
+
*/
|
|
27
|
+
titleField?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Set when the collection's documents log in. `admin` marks the collection editors log in to the admin from, and
|
|
30
|
+
* `invites` says the CMS can email an account a link to set its password.
|
|
31
|
+
*/
|
|
32
|
+
login?: {
|
|
33
|
+
admin: boolean;
|
|
34
|
+
invites: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A global as the admin shows it.
|
|
39
|
+
*/
|
|
40
|
+
interface AdminGlobal {
|
|
41
|
+
name: string;
|
|
42
|
+
label: string;
|
|
43
|
+
section: AdminSection;
|
|
44
|
+
fields: FormField[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The section of the admin that globals are listed under.
|
|
48
|
+
*/
|
|
49
|
+
type AdminSection = 'globals';
|
|
50
|
+
/**
|
|
51
|
+
* A store of images as the admin shows it, in a library of its own.
|
|
52
|
+
*/
|
|
53
|
+
interface AdminStore {
|
|
54
|
+
name: string;
|
|
55
|
+
labels: Labels;
|
|
56
|
+
/**
|
|
57
|
+
* The fields an editor fills in on each file: the alt text and the store's own fields.
|
|
58
|
+
*/
|
|
59
|
+
fields: FormField[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The CMS as the admin shows it, as plain data that passes from the server to the browser.
|
|
63
|
+
*/
|
|
64
|
+
interface AdminDefinition {
|
|
65
|
+
name: string;
|
|
66
|
+
collections: AdminCollection[];
|
|
67
|
+
globals?: AdminGlobal[];
|
|
68
|
+
stores?: AdminStore[];
|
|
69
|
+
/**
|
|
70
|
+
* The sidebar groups collections sit in, in order.
|
|
71
|
+
*/
|
|
72
|
+
groups?: {
|
|
73
|
+
name: string;
|
|
74
|
+
title: string;
|
|
75
|
+
}[];
|
|
76
|
+
/**
|
|
77
|
+
* Whether the CMS can email a link to set a new password.
|
|
78
|
+
*/
|
|
79
|
+
passwordReset: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The editor who is logged in to the admin.
|
|
83
|
+
*/
|
|
84
|
+
interface AdminEditor {
|
|
85
|
+
id: string;
|
|
86
|
+
email: string;
|
|
87
|
+
name: string;
|
|
88
|
+
roles: string[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The editor who created or last changed a document.
|
|
92
|
+
*/
|
|
93
|
+
interface ChangedBy {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns a document's title, or its id when it has none.
|
|
99
|
+
*/
|
|
100
|
+
declare const titleOf: (collection: AdminCollection, document: Record<string, unknown>) => string;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the editor a document's `createdBy` or `updatedBy` names, or `undefined` when it names none.
|
|
103
|
+
*/
|
|
104
|
+
declare const changedByOf: (value: unknown) => ChangedBy | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Returns a label as it reads inside a sentence, with its first letter in lowercase. A label that starts with an
|
|
107
|
+
* acronym keeps its capitals.
|
|
108
|
+
*/
|
|
109
|
+
declare const inSentence: (label: string) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the first letters of a name's first and last words.
|
|
112
|
+
*/
|
|
113
|
+
declare const initialsOf: (name: string) => string;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a role's name in words, like "Careers editor" for `careersEditor`.
|
|
116
|
+
*/
|
|
117
|
+
declare const roleLabelOf: (role: string) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the fields the first account fills in beside its email and password: the editors collection's required fields.
|
|
120
|
+
*/
|
|
121
|
+
declare const setupFieldsOf: (definition: AdminDefinition) => FormField[];
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AdminCollection, AdminDefinition, AdminEditor, AdminGlobal, AdminSection, AdminStore, ChangedBy, Labels, changedByOf, inSentence, initialsOf, roleLabelOf, setupFieldsOf, titleOf };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { FormField } from "./form-field.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/state/definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The words the admin uses for one document and for several.
|
|
6
|
+
*/
|
|
7
|
+
interface Labels {
|
|
8
|
+
singular: string;
|
|
9
|
+
plural: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A collection as the admin shows it.
|
|
13
|
+
*/
|
|
14
|
+
interface AdminCollection {
|
|
15
|
+
name: string;
|
|
16
|
+
labels: Labels;
|
|
17
|
+
/**
|
|
18
|
+
* The sidebar group the collection sits in.
|
|
19
|
+
*
|
|
20
|
+
* @default the Collections section, above every group
|
|
21
|
+
*/
|
|
22
|
+
group?: string;
|
|
23
|
+
fields: FormField[];
|
|
24
|
+
/**
|
|
25
|
+
* The field that names a document in lists and headers.
|
|
26
|
+
*/
|
|
27
|
+
titleField?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Set when the collection's documents log in. `admin` marks the collection editors log in to the admin from, and
|
|
30
|
+
* `invites` says the CMS can email an account a link to set its password.
|
|
31
|
+
*/
|
|
32
|
+
login?: {
|
|
33
|
+
admin: boolean;
|
|
34
|
+
invites: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A global as the admin shows it.
|
|
39
|
+
*/
|
|
40
|
+
interface AdminGlobal {
|
|
41
|
+
name: string;
|
|
42
|
+
label: string;
|
|
43
|
+
section: AdminSection;
|
|
44
|
+
fields: FormField[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The section of the admin that globals are listed under.
|
|
48
|
+
*/
|
|
49
|
+
type AdminSection = 'globals';
|
|
50
|
+
/**
|
|
51
|
+
* A store of images as the admin shows it, in a library of its own.
|
|
52
|
+
*/
|
|
53
|
+
interface AdminStore {
|
|
54
|
+
name: string;
|
|
55
|
+
labels: Labels;
|
|
56
|
+
/**
|
|
57
|
+
* The fields an editor fills in on each file: the alt text and the store's own fields.
|
|
58
|
+
*/
|
|
59
|
+
fields: FormField[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The CMS as the admin shows it, as plain data that passes from the server to the browser.
|
|
63
|
+
*/
|
|
64
|
+
interface AdminDefinition {
|
|
65
|
+
name: string;
|
|
66
|
+
collections: AdminCollection[];
|
|
67
|
+
globals?: AdminGlobal[];
|
|
68
|
+
stores?: AdminStore[];
|
|
69
|
+
/**
|
|
70
|
+
* The sidebar groups collections sit in, in order.
|
|
71
|
+
*/
|
|
72
|
+
groups?: {
|
|
73
|
+
name: string;
|
|
74
|
+
title: string;
|
|
75
|
+
}[];
|
|
76
|
+
/**
|
|
77
|
+
* Whether the CMS can email a link to set a new password.
|
|
78
|
+
*/
|
|
79
|
+
passwordReset: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The editor who is logged in to the admin.
|
|
83
|
+
*/
|
|
84
|
+
interface AdminEditor {
|
|
85
|
+
id: string;
|
|
86
|
+
email: string;
|
|
87
|
+
name: string;
|
|
88
|
+
roles: string[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The editor who created or last changed a document.
|
|
92
|
+
*/
|
|
93
|
+
interface ChangedBy {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns a document's title, or its id when it has none.
|
|
99
|
+
*/
|
|
100
|
+
declare const titleOf: (collection: AdminCollection, document: Record<string, unknown>) => string;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the editor a document's `createdBy` or `updatedBy` names, or `undefined` when it names none.
|
|
103
|
+
*/
|
|
104
|
+
declare const changedByOf: (value: unknown) => ChangedBy | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Returns a label as it reads inside a sentence, with its first letter in lowercase. A label that starts with an
|
|
107
|
+
* acronym keeps its capitals.
|
|
108
|
+
*/
|
|
109
|
+
declare const inSentence: (label: string) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the first letters of a name's first and last words.
|
|
112
|
+
*/
|
|
113
|
+
declare const initialsOf: (name: string) => string;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a role's name in words, like "Careers editor" for `careersEditor`.
|
|
116
|
+
*/
|
|
117
|
+
declare const roleLabelOf: (role: string) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the fields the first account fills in beside its email and password: the editors collection's required fields.
|
|
120
|
+
*/
|
|
121
|
+
declare const setupFieldsOf: (definition: AdminDefinition) => FormField[];
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AdminCollection, AdminDefinition, AdminEditor, AdminGlobal, AdminSection, AdminStore, ChangedBy, Labels, changedByOf, inSentence, initialsOf, roleLabelOf, setupFieldsOf, titleOf };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/state/definition.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns a document's title, or its id when it has none.
|
|
4
|
+
*/
|
|
5
|
+
const titleOf = (collection, document) => {
|
|
6
|
+
const title = collection.titleField === void 0 ? void 0 : document[collection.titleField];
|
|
7
|
+
return typeof title === "string" && title.trim() !== "" ? title : String(document["id"] ?? "");
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Returns the editor a document's `createdBy` or `updatedBy` names, or `undefined` when it names none.
|
|
11
|
+
*/
|
|
12
|
+
const changedByOf = (value) => {
|
|
13
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
14
|
+
const { id, name } = value;
|
|
15
|
+
return typeof id === "string" && typeof name === "string" ? {
|
|
16
|
+
id,
|
|
17
|
+
name
|
|
18
|
+
} : void 0;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns a label as it reads inside a sentence, with its first letter in lowercase. A label that starts with an
|
|
22
|
+
* acronym keeps its capitals.
|
|
23
|
+
*/
|
|
24
|
+
const inSentence = (label) => /^[A-Z][A-Z]/.test(label) ? label : label.charAt(0).toLowerCase() + label.slice(1);
|
|
25
|
+
/**
|
|
26
|
+
* Returns the first letters of a name's first and last words.
|
|
27
|
+
*/
|
|
28
|
+
const initialsOf = (name) => {
|
|
29
|
+
const words = name.trim().split(/\s+/).filter((word) => word !== "");
|
|
30
|
+
return `${words[0]?.charAt(0) ?? ""}${words.length > 1 ? words.at(-1)?.charAt(0) ?? "" : ""}`.toUpperCase();
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Returns a role's name in words, like "Careers editor" for `careersEditor`.
|
|
34
|
+
*/
|
|
35
|
+
const roleLabelOf = (role) => {
|
|
36
|
+
const words = role.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
|
|
37
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns the fields the first account fills in beside its email and password: the editors collection's required fields.
|
|
41
|
+
*/
|
|
42
|
+
const setupFieldsOf = (definition) => (definition.collections.find((collection) => collection.login?.admin === true)?.fields ?? []).filter((field) => field.required && !field.readOnly && ![
|
|
43
|
+
"email",
|
|
44
|
+
"password",
|
|
45
|
+
"roles"
|
|
46
|
+
].includes(field.name));
|
|
47
|
+
//#endregion
|
|
48
|
+
export { changedByOf, inSentence, initialsOf, roleLabelOf, setupFieldsOf, titleOf };
|