nexus-shared 1.1.20 → 2.0.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 +21 -0
- package/README.md +903 -0
- package/dist/Client.Index.d.ts +44 -0
- package/dist/Client.Index.js +49 -0
- package/dist/Components/Documents/Button.d.ts +29 -0
- package/dist/Components/Documents/Button.js +11 -0
- package/dist/Components/Documents/Menu.d.ts +102 -0
- package/dist/Components/Documents/Menu.js +238 -0
- package/dist/Components/Documents/SplitButton.d.ts +64 -0
- package/dist/Components/Documents/SplitButton.js +127 -0
- package/dist/Components/Documents/TabButtons.d.ts +62 -0
- package/dist/Components/Documents/TabButtons.js +19 -0
- package/dist/Components/Forms/ApiForm.d.ts +21 -0
- package/dist/Components/Forms/ApiForm.js +99 -0
- package/dist/Components/Forms/Crud.d.ts +17 -0
- package/dist/Components/Forms/Crud.js +556 -0
- package/dist/Components/Forms/CrudParts.d.ts +15 -0
- package/dist/Components/Forms/CrudParts.js +36 -0
- package/dist/Components/Forms/Form.d.ts +52 -0
- package/dist/Components/Forms/Form.js +319 -0
- package/dist/Components/Forms/SubmitForm.d.ts +65 -0
- package/dist/Components/Forms/SubmitForm.js +198 -0
- package/dist/Components/Inputs/Calendar.d.ts +69 -0
- package/dist/Components/Inputs/Calendar.js +258 -0
- package/dist/Components/Inputs/CheckBox.d.ts +53 -0
- package/dist/Components/Inputs/CheckBox.js +87 -0
- package/dist/Components/Inputs/CheckBoxGroup.d.ts +20 -0
- package/dist/Components/Inputs/CheckBoxGroup.js +80 -0
- package/dist/Components/Inputs/ChoiceField.d.ts +122 -0
- package/dist/Components/Inputs/ChoiceField.js +169 -0
- package/dist/Components/Inputs/DatePicker.d.ts +54 -0
- package/dist/Components/Inputs/DatePicker.js +246 -0
- package/dist/Components/Inputs/DateRangePicker.d.ts +62 -0
- package/dist/Components/Inputs/DateRangePicker.js +283 -0
- package/dist/Components/Inputs/DateTimePicker.d.ts +75 -0
- package/dist/Components/Inputs/DateTimePicker.js +399 -0
- package/dist/Components/Inputs/Dropdown.d.ts +117 -0
- package/dist/Components/Inputs/Dropdown.js +839 -0
- package/dist/Components/Inputs/DropdownParts.d.ts +84 -0
- package/dist/Components/Inputs/DropdownParts.js +102 -0
- package/dist/Components/Inputs/EditorShell.d.ts +45 -0
- package/dist/Components/Inputs/EditorShell.js +214 -0
- package/dist/Components/Inputs/Field.d.ts +53 -0
- package/dist/Components/Inputs/Field.js +16 -0
- package/dist/Components/Inputs/GroupForm.d.ts +20 -0
- package/dist/Components/Inputs/GroupForm.js +170 -0
- package/dist/Components/Inputs/InputField.d.ts +59 -0
- package/dist/Components/Inputs/InputField.js +169 -0
- package/dist/Components/Inputs/InputRenderer.d.ts +35 -0
- package/dist/Components/Inputs/InputRenderer.js +99 -0
- package/dist/Components/Inputs/MarkdownEditor.d.ts +67 -0
- package/dist/Components/Inputs/MarkdownEditor.js +289 -0
- package/dist/Components/Inputs/NumberBox.d.ts +53 -0
- package/dist/Components/Inputs/NumberBox.js +228 -0
- package/dist/Components/Inputs/RadioGroup.d.ts +20 -0
- package/dist/Components/Inputs/RadioGroup.js +43 -0
- package/dist/Components/Inputs/ReadOnlyNotice.d.ts +36 -0
- package/dist/Components/Inputs/ReadOnlyNotice.js +116 -0
- package/dist/Components/Inputs/RichTextEditor.d.ts +103 -0
- package/dist/Components/Inputs/RichTextEditor.js +1170 -0
- package/dist/Components/Inputs/RichTextParts.d.ts +63 -0
- package/dist/Components/Inputs/RichTextParts.js +157 -0
- package/dist/Components/Inputs/RowsInput.d.ts +104 -0
- package/dist/Components/Inputs/RowsInput.js +259 -0
- package/dist/Components/Inputs/Slider.d.ts +87 -0
- package/dist/Components/Inputs/Slider.js +216 -0
- package/dist/Components/Inputs/TabularForm.d.ts +23 -0
- package/dist/Components/Inputs/TabularForm.js +283 -0
- package/dist/Components/Inputs/TextArea.d.ts +43 -0
- package/dist/Components/Inputs/TextArea.js +31 -0
- package/dist/Components/Inputs/TextBox.d.ts +52 -0
- package/dist/Components/Inputs/TextBox.js +58 -0
- package/dist/Components/Inputs/TextField.d.ts +31 -0
- package/dist/Components/Inputs/TextField.js +35 -0
- package/dist/Components/Inputs/TimePanel.d.ts +34 -0
- package/dist/Components/Inputs/TimePanel.js +288 -0
- package/dist/Components/Inputs/TimePicker.d.ts +54 -0
- package/dist/Components/Inputs/TimePicker.js +239 -0
- package/dist/Components/Inputs/TreeView.d.ts +160 -0
- package/dist/Components/Inputs/TreeView.js +947 -0
- package/dist/Components/Layouts/MessageBox.d.ts +71 -0
- package/dist/Components/Layouts/MessageBox.js +104 -0
- package/dist/Components/Layouts/Popup.d.ts +92 -0
- package/dist/Components/Layouts/Popup.js +376 -0
- package/dist/Components/Layouts/PopupContext.d.ts +2 -0
- package/dist/Components/Layouts/PopupContext.js +4 -0
- package/dist/Components/Layouts/PopupDock.d.ts +22 -0
- package/dist/Components/Layouts/PopupDock.js +121 -0
- package/dist/Components/Layouts/PopupHost.d.ts +56 -0
- package/dist/Components/Layouts/PopupHost.js +163 -0
- package/dist/Components/Layouts/PopupRules.d.ts +30 -0
- package/dist/Components/Layouts/PopupRules.js +63 -0
- package/dist/Components/Layouts/ThemePicker.d.ts +13 -0
- package/dist/Components/Layouts/ThemePicker.js +22 -0
- package/dist/Components/Layouts/ThemeScript.d.ts +14 -0
- package/dist/Components/Layouts/ThemeScript.js +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.d.ts +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.js +29 -0
- package/dist/Components/Layouts/Toaster.d.ts +76 -0
- package/dist/Components/Layouts/Toaster.js +172 -0
- package/dist/Components/Viewers/DataTable.d.ts +25 -0
- package/dist/Components/Viewers/DataTable.js +542 -0
- package/dist/Components/Viewers/DataTableParts.d.ts +134 -0
- package/dist/Components/Viewers/DataTableParts.js +145 -0
- package/dist/Components/Viewers/MarkdownView.d.ts +26 -0
- package/dist/Components/Viewers/MarkdownView.js +79 -0
- package/dist/Components/Viewers/RichTextView.d.ts +18 -0
- package/dist/Components/Viewers/RichTextView.js +17 -0
- package/dist/Helpers/AnimationHelpers.d.ts +6 -0
- package/dist/Helpers/AnimationHelpers.js +35 -0
- package/dist/Helpers/ApiClient.d.ts +74 -0
- package/dist/Helpers/ApiClient.js +197 -0
- package/dist/Helpers/ApiFormHelpers.d.ts +26 -0
- package/dist/Helpers/ApiFormHelpers.js +56 -0
- package/dist/Helpers/ApiModules.d.ts +135 -0
- package/dist/Helpers/ApiModules.js +194 -0
- package/dist/Helpers/ApiResponses.d.ts +41 -0
- package/dist/Helpers/ApiResponses.js +159 -0
- package/dist/Helpers/ApiRoutes.d.ts +150 -0
- package/dist/Helpers/ApiRoutes.js +191 -0
- package/dist/Helpers/ApiToasts.d.ts +21 -0
- package/dist/Helpers/ApiToasts.js +22 -0
- package/dist/Helpers/ClassHelpers.d.ts +3 -0
- package/dist/Helpers/ClassHelpers.js +4 -0
- package/dist/Helpers/CrudBackend.d.ts +56 -0
- package/dist/Helpers/CrudBackend.js +119 -0
- package/dist/Helpers/CrudHelpers.d.ts +76 -0
- package/dist/Helpers/CrudHelpers.js +202 -0
- package/dist/Helpers/DateHelpers.d.ts +88 -0
- package/dist/Helpers/DateHelpers.js +363 -0
- package/dist/Helpers/DatePreferences.d.ts +14 -0
- package/dist/Helpers/DatePreferences.js +94 -0
- package/dist/Helpers/DateTimeHelpers.d.ts +87 -0
- package/dist/Helpers/DateTimeHelpers.js +286 -0
- package/dist/Helpers/DragHelpers.d.ts +129 -0
- package/dist/Helpers/DragHelpers.js +281 -0
- package/dist/Helpers/DropdownHelpers.d.ts +56 -0
- package/dist/Helpers/DropdownHelpers.js +180 -0
- package/dist/Helpers/FormDrafts.d.ts +18 -0
- package/dist/Helpers/FormDrafts.js +76 -0
- package/dist/Helpers/FormStore.d.ts +231 -0
- package/dist/Helpers/FormStore.js +734 -0
- package/dist/Helpers/InputParamsHelpers.d.ts +79 -0
- package/dist/Helpers/InputParamsHelpers.js +388 -0
- package/dist/Helpers/MarkdownEditing.d.ts +27 -0
- package/dist/Helpers/MarkdownEditing.js +250 -0
- package/dist/Helpers/MarkdownHelpers.d.ts +82 -0
- package/dist/Helpers/MarkdownHelpers.js +775 -0
- package/dist/Helpers/MessageBuilder.d.ts +74 -0
- package/dist/Helpers/MessageBuilder.js +254 -0
- package/dist/Helpers/NepaliCalendar.d.ts +25 -0
- package/dist/Helpers/NepaliCalendar.js +107 -0
- package/dist/Helpers/NumberHelpers.d.ts +71 -0
- package/dist/Helpers/NumberHelpers.js +202 -0
- package/dist/Helpers/Permissions.d.ts +62 -0
- package/dist/Helpers/Permissions.js +133 -0
- package/dist/Helpers/PopoverHelpers.d.ts +43 -0
- package/dist/Helpers/PopoverHelpers.js +91 -0
- package/dist/Helpers/RichTextHelpers.d.ts +77 -0
- package/dist/Helpers/RichTextHelpers.js +1072 -0
- package/dist/Helpers/RowsStore.d.ts +160 -0
- package/dist/Helpers/RowsStore.js +584 -0
- package/dist/Helpers/TableColumns.d.ts +40 -0
- package/dist/Helpers/TableColumns.js +254 -0
- package/dist/Helpers/TableExport.d.ts +30 -0
- package/dist/Helpers/TableExport.js +97 -0
- package/dist/Helpers/TableHelpers.d.ts +102 -0
- package/dist/Helpers/TableHelpers.js +281 -0
- package/dist/Helpers/TableStore.d.ts +142 -0
- package/dist/Helpers/TableStore.js +530 -0
- package/dist/Helpers/ThemeHelpers.d.ts +15 -0
- package/dist/Helpers/ThemeHelpers.js +16 -0
- package/dist/Helpers/TimeHelpers.d.ts +73 -0
- package/dist/Helpers/TimeHelpers.js +253 -0
- package/dist/Helpers/TreeStore.d.ts +188 -0
- package/dist/Helpers/TreeStore.js +577 -0
- package/dist/Helpers/ValidationHelpers.d.ts +124 -0
- package/dist/Helpers/ValidationHelpers.js +301 -0
- package/dist/Interfaces/ApiInterfaces.d.ts +149 -0
- package/dist/Interfaces/ApiInterfaces.js +24 -0
- package/dist/Interfaces/CrudInterfaces.d.ts +171 -0
- package/{src/sso-client.tsx → dist/Interfaces/CrudInterfaces.js} +1 -1
- package/dist/Interfaces/DateInterfaces.d.ts +154 -0
- package/dist/Interfaces/DateInterfaces.js +29 -0
- package/dist/Interfaces/FormInterfaces.d.ts +352 -0
- package/dist/Interfaces/FormInterfaces.js +1 -0
- package/dist/Interfaces/InputInterfaces.d.ts +141 -0
- package/dist/Interfaces/InputInterfaces.js +1 -0
- package/dist/Interfaces/MessageInterfaces.d.ts +111 -0
- package/dist/Interfaces/MessageInterfaces.js +5 -0
- package/dist/Interfaces/TableInterfaces.d.ts +291 -0
- package/dist/Interfaces/TableInterfaces.js +1 -0
- package/dist/Interfaces/ThemeInterfaces.d.ts +17 -0
- package/dist/Interfaces/ThemeInterfaces.js +17 -0
- package/dist/Interfaces/TypeInterfaces.d.ts +4 -0
- package/dist/Interfaces/TypeInterfaces.js +1 -0
- package/dist/Server.Index.d.ts +2 -0
- package/dist/Server.Index.js +5 -0
- package/dist/Services/ApiProxy.d.ts +32 -0
- package/dist/Services/ApiProxy.js +111 -0
- package/dist/Services/BrowserApi.d.ts +78 -0
- package/dist/Services/BrowserApi.js +111 -0
- package/dist/Services/ServerApi.d.ts +49 -0
- package/dist/Services/ServerApi.js +75 -0
- package/dist/Services/ThemeService.d.ts +17 -0
- package/dist/Services/ThemeService.js +83 -0
- package/dist/Shared.Index.d.ts +43 -0
- package/dist/Shared.Index.js +47 -0
- package/package.json +82 -33
- package/src/Styles/Nexus.Base.css +70 -0
- package/src/Styles/Nexus.Button.css +151 -0
- package/src/Styles/Nexus.Calendar.css +275 -0
- package/src/Styles/Nexus.Choice.css +345 -0
- package/src/Styles/Nexus.Crud.css +84 -0
- package/src/Styles/Nexus.DateTime.css +81 -0
- package/src/Styles/Nexus.Dropdown.css +774 -0
- package/src/Styles/Nexus.Editor.css +297 -0
- package/src/Styles/Nexus.Form.css +298 -0
- package/src/Styles/Nexus.Index.css +34 -0
- package/src/Styles/Nexus.Input.css +637 -0
- package/src/Styles/Nexus.Markdown.css +265 -0
- package/src/Styles/Nexus.Menu.css +249 -0
- package/src/Styles/Nexus.Popup.css +731 -0
- package/src/Styles/Nexus.RichText.css +463 -0
- package/src/Styles/Nexus.Rows.css +566 -0
- package/src/Styles/Nexus.Slider.css +278 -0
- package/src/Styles/Nexus.Tab.Buttons.css +364 -0
- package/src/Styles/Nexus.Table.css +1014 -0
- package/src/Styles/Nexus.Theme.Picker.css +159 -0
- package/src/Styles/Nexus.Themes.css +194 -0
- package/src/Styles/Nexus.Time.css +147 -0
- package/src/Styles/Nexus.Toast.css +265 -0
- package/src/Styles/Nexus.Tokens.css +72 -0
- package/src/Styles/Nexus.Tree.css +435 -0
- package/src/api-services/authentication-service.tsx +0 -23
- package/src/api-services/preference-service.tsx +0 -5
- package/src/api-services/system-service.tsx +0 -34
- package/src/client.ts +0 -31
- package/src/components/documents/button.tsx +0 -142
- package/src/components/documents/icon-box.tsx +0 -93
- package/src/components/documents/page-title.tsx +0 -7
- package/src/components/documents/tab-button.tsx +0 -172
- package/src/components/documents/tag.tsx +0 -30
- package/src/components/index.js +0 -0
- package/src/components/inputs/checkbox-input.tsx +0 -66
- package/src/components/inputs/input-box.tsx +0 -48
- package/src/components/inputs/input-element.tsx +0 -65
- package/src/components/inputs/input-form.tsx +0 -164
- package/src/components/inputs/input.tsx +0 -181
- package/src/components/inputs/number-input.tsx +0 -108
- package/src/components/inputs/radiobox-input.tsx +0 -53
- package/src/components/inputs/textarea-input.tsx +0 -47
- package/src/components/inputs/textbox-input.tsx +0 -45
- package/src/components/layouts/global-dialogbox.tsx +0 -431
- package/src/components/layouts/global-layout.tsx +0 -59
- package/src/components/layouts/layout-helpers.tsx +0 -20
- package/src/components/layouts/panels/user-panel.tsx +0 -112
- package/src/components/layouts/utility-menu.tsx +0 -49
- package/src/components/panels/theme-panel.tsx +0 -46
- package/src/helpers/bitwise-helpers.tsx +0 -11
- package/src/helpers/browser-helpers.tsx +0 -156
- package/src/helpers/datasource-helpers.tsx +0 -99
- package/src/helpers/element-helpers.tsx +0 -57
- package/src/helpers/input-helpers.tsx +0 -74
- package/src/helpers/string-helpers.tsx +0 -28
- package/src/helpers/utility-helpers.tsx +0 -45
- package/src/helpers/validation-helpers.tsx +0 -302
- package/src/index.ts +0 -26
- package/src/interface.ts +0 -19
- package/src/interfaces/auth-token-interfaces.tsx +0 -6
- package/src/interfaces/browser-interfaces.tsx +0 -36
- package/src/interfaces/button-interfaces.tsx +0 -63
- package/src/interfaces/datasource-interfaces.tsx +0 -22
- package/src/interfaces/datatable-interfaces.tsx +0 -25
- package/src/interfaces/dialogbox-interfaces.tsx +0 -5
- package/src/interfaces/exception-interfaces.tsx +0 -99
- package/src/interfaces/http-interfaces.tsx +0 -129
- package/src/interfaces/icon-interfaces.tsx +0 -129
- package/src/interfaces/input-interfaces.tsx +0 -410
- package/src/interfaces/layout-interfaces.tsx +0 -191
- package/src/interfaces/menu-interfaces.tsx +0 -49
- package/src/interfaces/message-interfaces.tsx +0 -32
- package/src/interfaces/permission-interfaces.tsx +0 -9
- package/src/interfaces/storage-interfaces.tsx +0 -5
- package/src/interfaces/system-interfaces.tsx +0 -22
- package/src/interfaces/theme-interfaces.tsx +0 -123
- package/src/interfaces/type-interfaces.tsx +0 -28
- package/src/interfaces/user-interfaces.tsx +0 -47
- package/src/nexus-client.tsx +0 -21
- package/src/nexus.environments.tsx +0 -66
- package/src/proxy-api/proxy-backend.tsx +0 -60
- package/src/proxy-api/proxy-constants.tsx +0 -28
- package/src/proxy-api/proxy-helpers.tsx +0 -91
- package/src/proxy-api-client.tsx +0 -1
- package/src/proxy-api-server.tsx +0 -2
- package/src/services/http-client-services.tsx +0 -75
- package/src/services/http-services.tsx +0 -158
- package/src/services/loader-service.tsx +0 -185
- package/src/services/localstorage-service.tsx +0 -119
- package/src/services/message-services.tsx +0 -383
- package/src/services/theme-service.tsx +0 -161
- package/src/services/user-services.tsx +0 -10
- package/src/sso-config/auth-token-validation.ts +0 -16
- package/src/sso-config/callback-route.tsx +0 -35
- package/src/sso-config/cookie-encryption.ts +0 -51
- package/src/sso-config/cookie-helpers.tsx +0 -102
- package/src/sso-config/forgot-password-route.tsx +0 -36
- package/src/sso-config/oauth-callback-state.ts +0 -61
- package/src/sso-config/pkce-helpers.ts +0 -9
- package/src/sso-config/provider-complete-route.tsx +0 -18
- package/src/sso-config/redirect-context-actions.tsx +0 -45
- package/src/sso-config/redirect-context-helpers.tsx +0 -159
- package/src/sso-config/redirect-context-persist.tsx +0 -18
- package/src/sso-config/redirect-context-route.tsx +0 -45
- package/src/sso-config/refresh-route.tsx +0 -23
- package/src/sso-config/sign-in-route.tsx +0 -74
- package/src/sso-config/sign-out-route.tsx +0 -57
- package/src/sso-config/sign-up-route.tsx +0 -57
- package/src/sso-config/sso-backend-flow.ts +0 -38
- package/src/sso-config/sso-complete-route.tsx +0 -50
- package/src/sso-config/sso-config.ts +0 -59
- package/src/sso-config/sso-interfaces.tsx +0 -99
- package/src/sso-config/sso-response-helpers.tsx +0 -20
- package/src/sso-server.tsx +0 -21
- package/src/styles/nexus.animation.css +0 -269
- package/src/styles/nexus.core.css +0 -119
- package/src/styles/nexus.dialog.css +0 -144
- package/src/styles/nexus.icon.css +0 -51
- package/src/styles/nexus.input.css +0 -207
- package/src/styles/nexus.loader.css +0 -11
- package/src/styles/nexus.logic.css +0 -47
- package/src/styles/nexus.utility.css +0 -347
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
|
+
export class CrudBackend {
|
|
3
|
+
/** Reads a whole list: an array, or the rows of a page. */
|
|
4
|
+
readList(result) {
|
|
5
|
+
if (Array.isArray(result))
|
|
6
|
+
return result;
|
|
7
|
+
return [...this.readPage(result).rows];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Changes an action's answer makes to rows, by key: a mass flag that answers each record's new status. Rows without
|
|
11
|
+
* an entry take the change the action stands for (a toggled flag). Default: none.
|
|
12
|
+
*/
|
|
13
|
+
answeredChanges(result, rowKey) {
|
|
14
|
+
void result;
|
|
15
|
+
void rowKey;
|
|
16
|
+
return new Map();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The keys of the records an action changed, when its answer lists them: a mass trash where some records could not
|
|
20
|
+
* move. `null` when the answer does not say, and every record sent counts as changed. Default `null`.
|
|
21
|
+
*/
|
|
22
|
+
answeredKeys(result, rowKey) {
|
|
23
|
+
void result;
|
|
24
|
+
void rowKey;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The Nexus record status of a flagged record (`ERecordStatus.Flagged`). */
|
|
29
|
+
export const NEXUS_FLAGGED_STATUS = 15;
|
|
30
|
+
/** The Nexus record status of an active record (`ERecordStatus.Active`). */
|
|
31
|
+
export const NEXUS_ACTIVE_STATUS = 0;
|
|
32
|
+
/**
|
|
33
|
+
* The Nexus backend: pages as `{ searchKeyword, skipCount, maxCount, sorting, sortType }` answered with
|
|
34
|
+
* `{ results, totalCount, filterCount }`, newest first unless a column is sorted; mass actions send the ids
|
|
35
|
+
* (`{ description, accountIds }` for descriptions); a flagged record has `recordStatus` 15, a pinned one `isPinned`.
|
|
36
|
+
*/
|
|
37
|
+
export class NexusCrudBackend extends CrudBackend {
|
|
38
|
+
pageRequest(query, sortKey) {
|
|
39
|
+
return {
|
|
40
|
+
searchKeyword: query.search,
|
|
41
|
+
skipCount: (query.page - 1) * query.pageSize,
|
|
42
|
+
maxCount: query.pageSize,
|
|
43
|
+
sorting: query.sort ? (sortKey ?? query.sort.key) : "creationTime",
|
|
44
|
+
sortType: query.sort ? query.sort.direction : "desc",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
readPage(result) {
|
|
48
|
+
if (Array.isArray(result))
|
|
49
|
+
return { rows: result };
|
|
50
|
+
if (!isRecord(result))
|
|
51
|
+
return { rows: [] };
|
|
52
|
+
const rows = (Array.isArray(result.results) ? result.results : []);
|
|
53
|
+
const total = Number(result.totalCount);
|
|
54
|
+
const matches = Number(result.filterCount);
|
|
55
|
+
return {
|
|
56
|
+
rows,
|
|
57
|
+
total: Number.isFinite(total) ? total : rows.length,
|
|
58
|
+
matches: Number.isFinite(matches) ? matches : Number.isFinite(total) ? total : rows.length,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
massRequest(action, keys, values) {
|
|
62
|
+
return action === "description" ? { description: values?.description ?? null, accountIds: keys } : keys;
|
|
63
|
+
}
|
|
64
|
+
isFlagged(row) {
|
|
65
|
+
return Number(row.recordStatus) === NEXUS_FLAGGED_STATUS;
|
|
66
|
+
}
|
|
67
|
+
withFlag(row, on) {
|
|
68
|
+
return { ...row, recordStatus: on ? NEXUS_FLAGGED_STATUS : NEXUS_ACTIVE_STATUS };
|
|
69
|
+
}
|
|
70
|
+
isPinned(row) {
|
|
71
|
+
return row.isPinned === true;
|
|
72
|
+
}
|
|
73
|
+
withPin(row, on) {
|
|
74
|
+
return { ...row, isPinned: on };
|
|
75
|
+
}
|
|
76
|
+
/** Mass answers list the records they changed, with their new `recordStatus` and `isPinned`. */
|
|
77
|
+
answeredChanges(result, rowKey) {
|
|
78
|
+
const changes = new Map();
|
|
79
|
+
const items = Array.isArray(result) ? result : isRecord(result) && Array.isArray(result.results) ? result.results : [];
|
|
80
|
+
for (const item of items) {
|
|
81
|
+
if (!isRecord(item))
|
|
82
|
+
continue;
|
|
83
|
+
const key = item[rowKey];
|
|
84
|
+
if (key === undefined || key === null)
|
|
85
|
+
continue;
|
|
86
|
+
const change = {};
|
|
87
|
+
if ("recordStatus" in item)
|
|
88
|
+
change.recordStatus = item.recordStatus;
|
|
89
|
+
if ("isPinned" in item)
|
|
90
|
+
change.isPinned = item.isPinned;
|
|
91
|
+
if (Object.keys(change).length)
|
|
92
|
+
changes.set(String(key), change);
|
|
93
|
+
}
|
|
94
|
+
return changes;
|
|
95
|
+
}
|
|
96
|
+
/** Mass answers list the records they changed (as records, or as ids); other answers say nothing. */
|
|
97
|
+
answeredKeys(result, rowKey) {
|
|
98
|
+
const items = Array.isArray(result) ? result : isRecord(result) && Array.isArray(result.results) ? result.results : null;
|
|
99
|
+
if (!items)
|
|
100
|
+
return null;
|
|
101
|
+
const keys = new Set();
|
|
102
|
+
for (const item of items) {
|
|
103
|
+
const key = isRecord(item) ? item[rowKey] : item;
|
|
104
|
+
if (typeof key === "string" || typeof key === "number")
|
|
105
|
+
keys.add(String(key));
|
|
106
|
+
}
|
|
107
|
+
return keys;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let current = null;
|
|
111
|
+
/** Registers the app's backend conventions, once, beside its API modules. */
|
|
112
|
+
export function defineCrudBackend(backend) {
|
|
113
|
+
current = backend;
|
|
114
|
+
return backend;
|
|
115
|
+
}
|
|
116
|
+
/** The registered backend conventions, or the Nexus ones. */
|
|
117
|
+
export function getCrudBackend() {
|
|
118
|
+
return (current ??= new NexusCrudBackend());
|
|
119
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ApiEndpoint } from "../Interfaces/ApiInterfaces.ts";
|
|
2
|
+
import type { CrudActionName, CrudEndpoints, CrudMassActionName, CrudMode, CrudRowActionName } from "../Interfaces/CrudInterfaces.ts";
|
|
3
|
+
import type { MessageActionName } from "../Interfaces/MessageInterfaces.ts";
|
|
4
|
+
import type { TablePaging } from "../Interfaces/TableInterfaces.ts";
|
|
5
|
+
/** Every list, in the order the CRUD shows them. */
|
|
6
|
+
export declare const CRUD_MODES: readonly CrudMode[];
|
|
7
|
+
/** The built-in actions on one record, per list, in their menu order. */
|
|
8
|
+
export declare const CRUD_ROW_ACTIONS: Readonly<Record<CrudMode, readonly CrudRowActionName[]>>;
|
|
9
|
+
/** The built-in actions on selected records, per list. */
|
|
10
|
+
export declare const CRUD_MASS_ACTIONS: Readonly<Record<CrudMode, readonly CrudMassActionName[]>>;
|
|
11
|
+
/**
|
|
12
|
+
* The built-in actions a list offers, in menu order, of those `allowed`. A controller without a trash (`trashless`: no
|
|
13
|
+
* trash endpoint, or trash not asked for) offers Delete where Move to trash would be. A trash the user may not use never
|
|
14
|
+
* turns into Delete.
|
|
15
|
+
*/
|
|
16
|
+
export declare function crudRowActions(mode: CrudMode, allowed: (action: CrudRowActionName) => boolean, trashless?: boolean): CrudRowActionName[];
|
|
17
|
+
/** The built-in actions on selected records a list offers, with the same Delete for a controller without a trash. */
|
|
18
|
+
export declare function crudMassActions(mode: CrudMode, allowed: (action: CrudMassActionName) => boolean, trashless?: boolean): CrudMassActionName[];
|
|
19
|
+
/** The endpoint of a list: its full list for tables that page in the browser, its pages for server tables. */
|
|
20
|
+
export declare function crudListEndpoint(api: CrudEndpoints, mode: CrudMode, paging: TablePaging): ApiEndpoint | undefined;
|
|
21
|
+
/** The endpoint of a row action. `view` needs none of its own: it shows the row (and calls `details` when there is one). */
|
|
22
|
+
export declare function crudRowEndpoint(api: CrudEndpoints, action: CrudRowActionName): ApiEndpoint | undefined;
|
|
23
|
+
/** The lists a CRUD can offer: asked for, with an endpoint, and allowed. */
|
|
24
|
+
export declare function availableModes(api: CrudEndpoints, paging: TablePaging, wanted: readonly CrudMode[], can: (endpoint: ApiEndpoint) => boolean): CrudMode[];
|
|
25
|
+
/**
|
|
26
|
+
* Whether a built-in action can run: asked for, with an endpoint, and allowed. View also works without a `details`
|
|
27
|
+
* endpoint (it shows the row), but a `details` endpoint the user may not call hides it, as in the old CRUD.
|
|
28
|
+
*/
|
|
29
|
+
export declare function actionAllowed(action: CrudActionName, api: CrudEndpoints, wanted: readonly CrudActionName[], can: (endpoint: ApiEndpoint) => boolean): boolean;
|
|
30
|
+
/** Whether a mass action can run: its row action is wanted, and its mass endpoint exists and is allowed. */
|
|
31
|
+
export declare function massActionAllowed(action: CrudMassActionName, api: CrudEndpoints, wanted: readonly CrudActionName[], can: (endpoint: ApiEndpoint) => boolean): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a record leaves the list shown after an action. Archive, trash, restore, recover, delete, and moving back to
|
|
34
|
+
* the trash take it to another list, and unflagging leaves the flagged list. Pinning and unpinning never do: a pinned
|
|
35
|
+
* record stays in the list it is in. `markOn` is the record's new flag.
|
|
36
|
+
*/
|
|
37
|
+
export declare function leavesList(action: CrudRowActionName | CrudMassActionName, mode: CrudMode, markOn?: boolean): boolean;
|
|
38
|
+
/** The message builder's action for a built-in action: "Guest archived.", "Unpin 3 guests?" */
|
|
39
|
+
export declare function crudMessageAction(action: CrudRowActionName | CrudMassActionName, markOn?: boolean): MessageActionName;
|
|
40
|
+
/** What every CRUD follows, whatever module it shows. `configureCrud` changes it once, for the whole app. */
|
|
41
|
+
export interface CrudSettings {
|
|
42
|
+
/**
|
|
43
|
+
* Most records a user may pin. Default 100. Lowering it never unpins anything: a user over the new limit keeps their
|
|
44
|
+
* pins and can unpin, and may pin again once they are under it.
|
|
45
|
+
*/
|
|
46
|
+
maxPins: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Changes what every CRUD follows, once, where the app registers its API modules: `configureCrud({ maxPins: 50 })`.
|
|
50
|
+
* Values left out keep what they had.
|
|
51
|
+
*/
|
|
52
|
+
export declare function configureCrud(changes: Partial<CrudSettings>): CrudSettings;
|
|
53
|
+
/** The settings every CRUD follows. */
|
|
54
|
+
export declare function getCrudSettings(): CrudSettings;
|
|
55
|
+
/**
|
|
56
|
+
* How many more records may be pinned: the limit less the records pinned, never below zero. `pinned` is `undefined`
|
|
57
|
+
* when nothing counts the pins (no `pins` endpoint), and then there is no limit to keep.
|
|
58
|
+
*/
|
|
59
|
+
export declare function pinRoom(pinned: number | undefined, max?: number): number;
|
|
60
|
+
/** Default time a CRUD keeps a list: 5 minutes. */
|
|
61
|
+
export declare const CRUD_CACHE_LIFETIME: number;
|
|
62
|
+
/** Lists kept while a page is open, by key, each for a lifetime. Plain values; nothing is written to storage. */
|
|
63
|
+
export declare class CrudCache<T = unknown> {
|
|
64
|
+
private entries;
|
|
65
|
+
readonly lifetime: number;
|
|
66
|
+
private now;
|
|
67
|
+
constructor(lifetime?: number, now?: () => number);
|
|
68
|
+
get(key: string): T | undefined;
|
|
69
|
+
set(key: string, value: T): void;
|
|
70
|
+
/** Replaces a value, keeping its age, so a changed list does not live longer than the list it came from. */
|
|
71
|
+
update(key: string, value: T): void;
|
|
72
|
+
/** Drops every entry whose key passes the test. */
|
|
73
|
+
drop(test: (key: string) => boolean): void;
|
|
74
|
+
clear(): void;
|
|
75
|
+
get size(): number;
|
|
76
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The rules of the CRUD component, with no React: which lists and actions a controller offers, which actions each list
|
|
3
|
+
* shows, which records leave a list after an action, the settings every CRUD follows (how many records may be pinned),
|
|
4
|
+
* and the cache of lists kept while the page is open.
|
|
5
|
+
*/
|
|
6
|
+
/** Every list, in the order the CRUD shows them. */
|
|
7
|
+
export const CRUD_MODES = ["normal", "flag", "archive", "trash", "deleted"];
|
|
8
|
+
const ACTIVE_ROW_ACTIONS = ["view", "edit", "flag", "pin", "archive", "trash"];
|
|
9
|
+
const ACTIVE_MASS_ACTIONS = ["flag", "pin", "archive", "description", "trash"];
|
|
10
|
+
/** The built-in actions on one record, per list, in their menu order. */
|
|
11
|
+
export const CRUD_ROW_ACTIONS = {
|
|
12
|
+
normal: ACTIVE_ROW_ACTIONS,
|
|
13
|
+
flag: ACTIVE_ROW_ACTIONS,
|
|
14
|
+
archive: ["view", "restore", "trash"],
|
|
15
|
+
trash: ["view", "recover", "delete"],
|
|
16
|
+
deleted: ["view", "trashFromDelete"],
|
|
17
|
+
};
|
|
18
|
+
/** The built-in actions on selected records, per list. */
|
|
19
|
+
export const CRUD_MASS_ACTIONS = {
|
|
20
|
+
normal: ACTIVE_MASS_ACTIONS,
|
|
21
|
+
flag: ACTIVE_MASS_ACTIONS,
|
|
22
|
+
archive: ["restore", "description", "trash"],
|
|
23
|
+
trash: ["recover", "description", "delete"],
|
|
24
|
+
deleted: ["trashFromDelete"],
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The built-in actions a list offers, in menu order, of those `allowed`. A controller without a trash (`trashless`: no
|
|
28
|
+
* trash endpoint, or trash not asked for) offers Delete where Move to trash would be. A trash the user may not use never
|
|
29
|
+
* turns into Delete.
|
|
30
|
+
*/
|
|
31
|
+
export function crudRowActions(mode, allowed, trashless = false) {
|
|
32
|
+
const list = [];
|
|
33
|
+
for (const action of CRUD_ROW_ACTIONS[mode]) {
|
|
34
|
+
if (action === "trash" && trashless) {
|
|
35
|
+
if (allowed("delete"))
|
|
36
|
+
list.push("delete");
|
|
37
|
+
}
|
|
38
|
+
else if (allowed(action))
|
|
39
|
+
list.push(action);
|
|
40
|
+
}
|
|
41
|
+
return list;
|
|
42
|
+
}
|
|
43
|
+
/** The built-in actions on selected records a list offers, with the same Delete for a controller without a trash. */
|
|
44
|
+
export function crudMassActions(mode, allowed, trashless = false) {
|
|
45
|
+
const list = [];
|
|
46
|
+
for (const action of CRUD_MASS_ACTIONS[mode]) {
|
|
47
|
+
if (action === "trash" && trashless) {
|
|
48
|
+
if (allowed("delete"))
|
|
49
|
+
list.push("delete");
|
|
50
|
+
}
|
|
51
|
+
else if (allowed(action))
|
|
52
|
+
list.push(action);
|
|
53
|
+
}
|
|
54
|
+
return list;
|
|
55
|
+
}
|
|
56
|
+
/** The endpoint of a list: its full list for tables that page in the browser, its pages for server tables. */
|
|
57
|
+
export function crudListEndpoint(api, mode, paging) {
|
|
58
|
+
return paging === "server" ? api.pages?.[mode] : api.lists?.[mode];
|
|
59
|
+
}
|
|
60
|
+
/** The endpoint of a row action. `view` needs none of its own: it shows the row (and calls `details` when there is one). */
|
|
61
|
+
export function crudRowEndpoint(api, action) {
|
|
62
|
+
if (action === "view")
|
|
63
|
+
return api.details;
|
|
64
|
+
if (action === "edit")
|
|
65
|
+
return api.update;
|
|
66
|
+
return api[action];
|
|
67
|
+
}
|
|
68
|
+
/** The lists a CRUD can offer: asked for, with an endpoint, and allowed. */
|
|
69
|
+
export function availableModes(api, paging, wanted, can) {
|
|
70
|
+
return CRUD_MODES.filter(mode => wanted.includes(mode)).filter(mode => {
|
|
71
|
+
const endpoint = crudListEndpoint(api, mode, paging);
|
|
72
|
+
return Boolean(endpoint) && can(endpoint);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether a built-in action can run: asked for, with an endpoint, and allowed. View also works without a `details`
|
|
77
|
+
* endpoint (it shows the row), but a `details` endpoint the user may not call hides it, as in the old CRUD.
|
|
78
|
+
*/
|
|
79
|
+
export function actionAllowed(action, api, wanted, can) {
|
|
80
|
+
if (!wanted.includes(action))
|
|
81
|
+
return false;
|
|
82
|
+
if (action === "create")
|
|
83
|
+
return Boolean(api.create) && can(api.create);
|
|
84
|
+
if (action === "description")
|
|
85
|
+
return Boolean(api.mass?.description) && can(api.mass.description);
|
|
86
|
+
if (action === "view")
|
|
87
|
+
return !api.details || can(api.details);
|
|
88
|
+
const endpoint = crudRowEndpoint(api, action);
|
|
89
|
+
return Boolean(endpoint) && can(endpoint);
|
|
90
|
+
}
|
|
91
|
+
/** Whether a mass action can run: its row action is wanted, and its mass endpoint exists and is allowed. */
|
|
92
|
+
export function massActionAllowed(action, api, wanted, can) {
|
|
93
|
+
if (!wanted.includes(action))
|
|
94
|
+
return false;
|
|
95
|
+
const endpoint = api.mass?.[action];
|
|
96
|
+
return Boolean(endpoint) && can(endpoint);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether a record leaves the list shown after an action. Archive, trash, restore, recover, delete, and moving back to
|
|
100
|
+
* the trash take it to another list, and unflagging leaves the flagged list. Pinning and unpinning never do: a pinned
|
|
101
|
+
* record stays in the list it is in. `markOn` is the record's new flag.
|
|
102
|
+
*/
|
|
103
|
+
export function leavesList(action, mode, markOn) {
|
|
104
|
+
switch (action) {
|
|
105
|
+
case "archive":
|
|
106
|
+
case "restore":
|
|
107
|
+
case "trash":
|
|
108
|
+
case "recover":
|
|
109
|
+
case "delete":
|
|
110
|
+
case "trashFromDelete":
|
|
111
|
+
return true;
|
|
112
|
+
case "flag":
|
|
113
|
+
return mode === "flag" && markOn === false;
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** The message builder's action for a built-in action: "Guest archived.", "Unpin 3 guests?" */
|
|
119
|
+
export function crudMessageAction(action, markOn) {
|
|
120
|
+
switch (action) {
|
|
121
|
+
case "flag":
|
|
122
|
+
return markOn === false ? "unflag" : "flag";
|
|
123
|
+
case "pin":
|
|
124
|
+
return markOn === false ? "unpin" : "pin";
|
|
125
|
+
case "trashFromDelete":
|
|
126
|
+
return "trash";
|
|
127
|
+
case "description":
|
|
128
|
+
return "update";
|
|
129
|
+
case "edit":
|
|
130
|
+
case "view":
|
|
131
|
+
return "save";
|
|
132
|
+
default:
|
|
133
|
+
return action;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const DEFAULT_CRUD_SETTINGS = { maxPins: 100 };
|
|
137
|
+
let crudSettings = DEFAULT_CRUD_SETTINGS;
|
|
138
|
+
/**
|
|
139
|
+
* Changes what every CRUD follows, once, where the app registers its API modules: `configureCrud({ maxPins: 50 })`.
|
|
140
|
+
* Values left out keep what they had.
|
|
141
|
+
*/
|
|
142
|
+
export function configureCrud(changes) {
|
|
143
|
+
crudSettings = { ...crudSettings, ...changes };
|
|
144
|
+
return crudSettings;
|
|
145
|
+
}
|
|
146
|
+
/** The settings every CRUD follows. */
|
|
147
|
+
export function getCrudSettings() {
|
|
148
|
+
return crudSettings;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* How many more records may be pinned: the limit less the records pinned, never below zero. `pinned` is `undefined`
|
|
152
|
+
* when nothing counts the pins (no `pins` endpoint), and then there is no limit to keep.
|
|
153
|
+
*/
|
|
154
|
+
export function pinRoom(pinned, max = getCrudSettings().maxPins) {
|
|
155
|
+
if (pinned === undefined)
|
|
156
|
+
return Number.POSITIVE_INFINITY;
|
|
157
|
+
return Math.max(0, max - pinned);
|
|
158
|
+
}
|
|
159
|
+
/** Default time a CRUD keeps a list: 5 minutes. */
|
|
160
|
+
export const CRUD_CACHE_LIFETIME = 5 * 60 * 1000;
|
|
161
|
+
/** Lists kept while a page is open, by key, each for a lifetime. Plain values; nothing is written to storage. */
|
|
162
|
+
export class CrudCache {
|
|
163
|
+
entries = new Map();
|
|
164
|
+
lifetime;
|
|
165
|
+
now;
|
|
166
|
+
constructor(lifetime = CRUD_CACHE_LIFETIME, now = Date.now) {
|
|
167
|
+
this.lifetime = lifetime;
|
|
168
|
+
this.now = now;
|
|
169
|
+
}
|
|
170
|
+
get(key) {
|
|
171
|
+
const entry = this.entries.get(key);
|
|
172
|
+
if (!entry)
|
|
173
|
+
return undefined;
|
|
174
|
+
if (this.now() - entry.at > this.lifetime) {
|
|
175
|
+
this.entries.delete(key);
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
return entry.value;
|
|
179
|
+
}
|
|
180
|
+
set(key, value) {
|
|
181
|
+
if (this.lifetime > 0)
|
|
182
|
+
this.entries.set(key, { value, at: this.now() });
|
|
183
|
+
}
|
|
184
|
+
/** Replaces a value, keeping its age, so a changed list does not live longer than the list it came from. */
|
|
185
|
+
update(key, value) {
|
|
186
|
+
const entry = this.entries.get(key);
|
|
187
|
+
if (entry)
|
|
188
|
+
entry.value = value;
|
|
189
|
+
}
|
|
190
|
+
/** Drops every entry whose key passes the test. */
|
|
191
|
+
drop(test) {
|
|
192
|
+
for (const key of [...this.entries.keys()])
|
|
193
|
+
if (test(key))
|
|
194
|
+
this.entries.delete(key);
|
|
195
|
+
}
|
|
196
|
+
clear() {
|
|
197
|
+
this.entries.clear();
|
|
198
|
+
}
|
|
199
|
+
get size() {
|
|
200
|
+
return this.entries.size;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type CalendarType, type DateInput, type DateParts, type DatePreferences, type DateRange, type DateRangeInput, type DateScript } from "../Interfaces/DateInterfaces.ts";
|
|
2
|
+
export declare const ISO_DATE_PATTERN: RegExp;
|
|
3
|
+
/** Day number of a Gregorian date: days since 1970-01-01, proleptic, no zone (Howard Hinnant's algorithm). */
|
|
4
|
+
export declare function daysFromCivil(year: number, month: number, day: number): number;
|
|
5
|
+
/** The Gregorian date of a day number. */
|
|
6
|
+
export declare function civilFromDays(dayNumber: number): DateParts;
|
|
7
|
+
export declare const partsToIsoDate: ({ year, month, day }: DateParts) => string;
|
|
8
|
+
/** The parts of an ISO date. The text must be a valid date (`isIsoDate`). */
|
|
9
|
+
export declare function isoDateToParts(iso: string): DateParts;
|
|
10
|
+
export declare const isoDateToDayNumber: (iso: string) => number;
|
|
11
|
+
export declare const dayNumberToIsoDate: (dayNumber: number) => string;
|
|
12
|
+
export declare function gregorianMonthLength(year: number, month: number): number;
|
|
13
|
+
/** Whether text is an ISO date that exists: "2026-02-30" is not. */
|
|
14
|
+
export declare function isIsoDate(text: unknown): text is string;
|
|
15
|
+
/**
|
|
16
|
+
* Turns anything a date can arrive as into an ISO date, or `null`:
|
|
17
|
+
* - "2026-09-17" (or "2026-9-7") stays that day;
|
|
18
|
+
* - an ISO date-time with a zone, "2026-09-16T18:15:00Z", becomes the browser's local date of that instant;
|
|
19
|
+
* - one without a zone, "2026-09-17T00:00:00", keeps its date part;
|
|
20
|
+
* - a `Date` is read in local time, like `new Date()` for today.
|
|
21
|
+
* Text that is not a date, or a day that does not exist, gives `null`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toIsoDate(input: DateInput): string | null;
|
|
24
|
+
/** A `Date` at midnight of the day: in UTC (the default, for JSON and APIs) or in the browser's local time. */
|
|
25
|
+
export declare function isoDateToDate(iso: string, zone?: "utc" | "local"): Date;
|
|
26
|
+
/** Today's date where the browser is. */
|
|
27
|
+
export declare function todayIsoDate(): string;
|
|
28
|
+
export declare const addDays: (iso: string, days: number) => string;
|
|
29
|
+
/** Negative when `a` is before `b`. ISO dates compare as text. */
|
|
30
|
+
export declare const compareIsoDates: (a: string, b: string) => number;
|
|
31
|
+
/** Days from one date to another: `diffDays("2026-09-17", "2026-09-20")` is 3. */
|
|
32
|
+
export declare const diffDays: (from: string, to: string) => number;
|
|
33
|
+
/** 0 for Sunday to 6 for Saturday. */
|
|
34
|
+
export declare const weekdayOf: (iso: string) => number;
|
|
35
|
+
export declare function clampIsoDate(iso: string, min?: string | null, max?: string | null): string;
|
|
36
|
+
/** The days the calendar covers: Gregorian years 1 to 9999, Bikram Sambat 1975 to 2100 (AD 1918 to 2044). */
|
|
37
|
+
export declare const CALENDAR_RANGE: Record<CalendarType, {
|
|
38
|
+
readonly min: string;
|
|
39
|
+
readonly max: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function daysInMonth(year: number, month: number, calendar: CalendarType): number;
|
|
42
|
+
/** Whether the parts name a day of the calendar. */
|
|
43
|
+
export declare function isValidParts(parts: DateParts, calendar: CalendarType): boolean;
|
|
44
|
+
/** The day as parts of the calendar, or `null` when the Nepali table does not reach it. */
|
|
45
|
+
export declare function toCalendar(iso: string, calendar: CalendarType): DateParts | null;
|
|
46
|
+
/** The ISO date of parts in the calendar, or `null` when the day does not exist. */
|
|
47
|
+
export declare function fromCalendar(parts: DateParts, calendar: CalendarType): string | null;
|
|
48
|
+
/** The same day of another month, or the month's last day when it is shorter. Years stay inside the calendar. */
|
|
49
|
+
export declare function addMonths(parts: DateParts, months: number, calendar: CalendarType): DateParts;
|
|
50
|
+
/** Nepali dates use Devanagari digits and names only when both the calendar and the script say so. */
|
|
51
|
+
export declare const usesDevanagari: (calendar: CalendarType, script: DateScript | undefined) => boolean;
|
|
52
|
+
export declare function getMonthNames(calendar: CalendarType, script?: DateScript, short?: boolean): readonly string[];
|
|
53
|
+
export declare function getWeekdayNames(calendar: CalendarType, script?: DateScript, length?: "long" | "short" | "min"): readonly string[];
|
|
54
|
+
export declare const toDevanagariDigits: (text: string) => string;
|
|
55
|
+
export declare const toLatinDigits: (text: string) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Writes a day with a format of tokens: `YYYY` `YY` year, `MMMM` `MMM` month name, `MM` `M` month number, `DD` `D` day,
|
|
58
|
+
* `dddd` `ddd` weekday name. "YYYY-MM-DD" gives 2026-09-17; "dddd, MMMM D, YYYY" gives Thursday, September 17, 2026.
|
|
59
|
+
* In the Nepali calendar with the Devanagari script, digits and names are Nepali: २०८३-०६-०१.
|
|
60
|
+
* Returns "" for an empty or invalid input. A day outside the Nepali table is written as its ISO date.
|
|
61
|
+
*/
|
|
62
|
+
export declare function formatDate(input: DateInput, options?: Partial<DatePreferences>): string;
|
|
63
|
+
/** Writes parts of a calendar with a format. `weekday` (0 = Sunday) is needed only for the `dddd` and `ddd` tokens. */
|
|
64
|
+
export declare function formatDateParts(parts: DateParts, calendar: CalendarType, format: string, script?: DateScript, weekday?: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* Reads a date the user typed, following the order of the format's tokens: with "DD/MM/YYYY", "17/9/2026" and
|
|
67
|
+
* "17-09-2026" both give "2026-09-17". Month names are matched by their start in any spelling ("Sep", "September",
|
|
68
|
+
* "Asoj", "असोज"), weekday names are ignored, Devanagari digits are read, and a four-digit number is the year wherever
|
|
69
|
+
* it stands. In the Nepali calendar the text is a Nepali date, and the result is still the Gregorian ISO date.
|
|
70
|
+
* Returns `null` for text that is not a date.
|
|
71
|
+
*/
|
|
72
|
+
export declare function parseDateText(text: string, options?: Partial<DatePreferences>): string | null;
|
|
73
|
+
/** Between the start and the end of a range written as text: an en dash with a space on each side. */
|
|
74
|
+
export declare const DATE_RANGE_SEPARATOR = " \u2013 ";
|
|
75
|
+
/** Reads a range input as two ISO dates, `null` for an end not given. A start after the end is swapped. */
|
|
76
|
+
export declare function toDateRange(input: DateRangeInput): DateRange;
|
|
77
|
+
/**
|
|
78
|
+
* Writes a range as "start – end" in a calendar and format: "2026-09-17 – 2026-09-24". With only a start it is
|
|
79
|
+
* "2026-09-17 –", with only an end "– 2026-09-24", and "" when empty.
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatDateRange(input: DateRangeInput, options?: Partial<DatePreferences>): string;
|
|
82
|
+
/**
|
|
83
|
+
* Reads a range the user typed: two dates, each read like `parseDateText`, around " – ", " - ", "—", "→", or " to ",
|
|
84
|
+
* e.g. "17/9/2026 - 24/9/2026" or "2026-09-17 to 2026-09-24". A date on its own, or with a separator after it, gives
|
|
85
|
+
* `[date, null]`; a separator before it gives `[null, date]`; an end before the start is swapped. "" gives an empty
|
|
86
|
+
* range, and text that is not a range gives `null`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function parseDateRangeText(text: string, options?: Partial<DatePreferences>): DateRange | null;
|