@_tc/template-core 0.2.0-bate.9 → 0.2.1
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/AGENT_README.md +2 -2
- package/README.md +67 -30
- package/cjs/app/controller/project.js +1 -1
- package/cjs/app/controller/view.js +1 -1
- package/cjs/app/extends/db.js +4 -4
- package/cjs/app/middlewares/error-handle.js +1 -1
- package/cjs/app/middlewares/project-handler.js +1 -1
- package/cjs/app/utils/i18n.js +1 -0
- package/cjs/app/view/entry.tpl +1 -0
- package/cjs/packages/common/i18n/default.js +1 -1
- package/cjs/packages/common/i18n/en-US.js +1 -1
- package/cjs/packages/common/index.js +1 -1
- package/esm/app/controller/project.js +12 -11
- package/esm/app/controller/view.js +1 -0
- package/esm/app/extends/db.js +64 -60
- package/esm/app/middlewares/error-handle.js +16 -15
- package/esm/app/middlewares/project-handler.js +8 -7
- package/esm/app/utils/i18n.js +36 -0
- package/esm/app/view/entry.tpl +1 -0
- package/esm/packages/common/i18n/default.js +13 -0
- package/esm/packages/common/i18n/en-US.js +13 -0
- package/esm/packages/common/index.js +9 -9
- package/fe/frontend/apps/dash/Dashboard.js +6 -4
- package/fe/frontend/apps/dash/dash.entry.js +2 -0
- package/fe/frontend/src/common/generateMenuData.d.ts +4 -1
- package/fe/frontend/src/common/generateMenuData.js +3 -3
- package/fe/frontend/src/common/language.d.ts +1 -2
- package/fe/frontend/src/common/language.js +10 -10
- package/fe/frontend/src/common/request.js +3 -1
- package/fe/frontend/src/components/AsyncSelect/AsyncSelect.js +10 -2
- package/fe/frontend/src/components/BasePage/HeaderView.js +2 -2
- package/fe/frontend/src/components/LanguageSwitch/LanguageSwitch.js +13 -9
- package/fe/frontend/src/components/ThemeSwitch/ThemeSwitch.js +4 -3
- package/fe/frontend/src/defaultPages/NotFoundPage/index.js +4 -3
- package/fe/frontend/src/defaultPages/SchemaPage/components/CallCom/DetailPanel.js +14 -9
- package/fe/frontend/src/defaultPages/SchemaPage/components/CallCom/PopFrom.js +8 -7
- package/fe/frontend/src/defaultPages/SchemaPage/components/SchemaSearch/index.js +6 -12
- package/fe/frontend/src/defaultPages/SchemaPage/components/SchemaTable/index.js +25 -18
- package/fe/frontend/src/defaultPages/SchemaPage/index.js +5 -3
- package/fe/frontend/src/defaultPages/SidebarSlotPageTmp.js +4 -2
- package/fe/frontend/src/hooks/useText.d.ts +3 -0
- package/fe/frontend/src/hooks/useText.js +14 -0
- package/fe/frontend/src/index.d.ts +1 -0
- package/fe/frontend/src/index.js +3 -2
- package/fe/frontend/src/language/index.d.ts +0 -2
- package/fe/frontend/src/language/index.js +1 -7
- package/fe/frontend/src/language/resources.d.ts +2 -0
- package/fe/frontend/src/language/resources.js +9 -0
- package/fe/packages/common/i18n/default.d.ts +15 -0
- package/fe/packages/common/i18n/default.js +16 -0
- package/fe/packages/common/i18n/en-US.d.ts +15 -0
- package/fe/packages/common/i18n/en-US.js +18 -2
- package/fe/packages/common/i18n/index.js +13 -0
- package/fe/packages/common/i18n/locales.js +7 -0
- package/fe/packages/react/ui/components/Date/Calendar.js +9 -5
- package/fe/packages/react/ui/components/Date/LocaleContext.d.ts +22 -1
- package/fe/packages/react/ui/components/Date/LocaleContext.js +28 -3
- package/fe/packages/react/ui/components/Date/LocaleProvider.d.ts +1 -1
- package/fe/packages/react/ui/components/Date/LocaleProvider.js +7 -16
- package/fe/packages/react/ui/components/Date/index.js +2 -2
- package/fe/packages/react/ui/components/Date/locales.d.ts +2 -0
- package/fe/packages/react/ui/components/Date/locales.js +29 -13
- package/fe/packages/react/ui/components/TableSearch/TableSearch.js +21 -1
- package/fe/packages/react/ui/components/TableSearch/lang.d.ts +2 -0
- package/fe/packages/react/ui/components/TableSearch/lang.js +18 -7
- package/fe/packages/react/ui/components/Textarea/Textarea.d.ts +1 -1
- package/fe/packages/react/ui/components/Textarea/Textarea.js +1 -1
- package/model/frontend/src/common/language.d.ts +1 -2
- package/model/frontend/src/hooks/useText.d.ts +3 -0
- package/model/frontend/src/language/index.d.ts +0 -2
- package/model/frontend/src/language/resources.d.ts +2 -0
- package/model/packages/common/i18n/default.d.ts +15 -0
- package/model/packages/common/i18n/en-US.d.ts +15 -0
- package/model/packages/react/ui/components/Date/LocaleContext.d.ts +22 -1
- package/model/packages/react/ui/components/Date/LocaleProvider.d.ts +1 -1
- package/model/packages/react/ui/components/Date/locales.d.ts +2 -0
- package/model/packages/react/ui/components/TableSearch/lang.d.ts +2 -0
- package/model/packages/react/ui/components/Textarea/Textarea.d.ts +1 -1
- package/package.json +1 -1
- package/types/app/utils/i18n.d.ts +12 -0
- package/types/packages/common/i18n/default.d.ts +19 -0
- package/types/packages/common/i18n/en-US.d.ts +21 -2
- package/types/packages/common/i18n/index.d.ts +21 -0
- package/types/packages/common/i18n/locales.d.ts +10 -0
- package/types/packages/common/i18n/types.d.ts +40 -0
|
@@ -7,6 +7,21 @@ export declare const defaultEnglishResources: {
|
|
|
7
7
|
readonly submit: "Submit";
|
|
8
8
|
readonly reset: "Reset";
|
|
9
9
|
};
|
|
10
|
+
readonly server: {
|
|
11
|
+
readonly errors: {
|
|
12
|
+
readonly network: "Network error";
|
|
13
|
+
readonly invalidRequest: "Invalid request";
|
|
14
|
+
readonly getProjectFailed: "Failed to get project";
|
|
15
|
+
readonly dbNodeSqliteUnavailable: "[db] The default database depends on Node.js built-in {sqliteSpecifier}, which is unavailable in the current runtime. Upgrade Node.js or override app/extends/db.ts in the business project.{cause}";
|
|
16
|
+
readonly dbDatabaseSyncUnavailable: "[db] {sqliteSpecifier} does not provide DatabaseSync, so the default SQLite database cannot be initialized.";
|
|
17
|
+
readonly dbNamespaceRequired: "[db] namespace cannot be empty";
|
|
18
|
+
readonly dbKeyRequired: "[db] key cannot be empty";
|
|
19
|
+
readonly dbLimitInvalid: "[db] limit must be an integer greater than 0";
|
|
20
|
+
readonly dbOffsetInvalid: "[db] offset must be an integer greater than or equal to 0";
|
|
21
|
+
readonly dbValueNotSerializable: "[db] value must be serializable by JSON.stringify.{cause}";
|
|
22
|
+
readonly dbClosed: "[db] SQLite database connection is closed";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
10
25
|
readonly components: {
|
|
11
26
|
readonly breadcrumb: {
|
|
12
27
|
readonly close: "Close";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
//#region packages/common/i18n/en-US.ts
|
|
2
2
|
/**
|
|
3
|
-
* UI
|
|
3
|
+
* UI 组件库默认英文语言资源。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 这里只放组件内置文案,业务项目可以通过 I18nProvider.resources 覆盖或追加。
|
|
6
6
|
*/
|
|
7
7
|
var defaultEnglishResources = {
|
|
8
|
+
/** 通用操作文案。 */
|
|
8
9
|
common: {
|
|
9
10
|
tip: "Prompt",
|
|
10
11
|
confirm: "Confirm",
|
|
@@ -13,6 +14,20 @@ var defaultEnglishResources = {
|
|
|
13
14
|
submit: "Submit",
|
|
14
15
|
reset: "Reset"
|
|
15
16
|
},
|
|
17
|
+
server: { errors: {
|
|
18
|
+
network: "Network error",
|
|
19
|
+
invalidRequest: "Invalid request",
|
|
20
|
+
getProjectFailed: "Failed to get project",
|
|
21
|
+
dbNodeSqliteUnavailable: "[db] The default database depends on Node.js built-in {sqliteSpecifier}, which is unavailable in the current runtime. Upgrade Node.js or override app/extends/db.ts in the business project.{cause}",
|
|
22
|
+
dbDatabaseSyncUnavailable: "[db] {sqliteSpecifier} does not provide DatabaseSync, so the default SQLite database cannot be initialized.",
|
|
23
|
+
dbNamespaceRequired: "[db] namespace cannot be empty",
|
|
24
|
+
dbKeyRequired: "[db] key cannot be empty",
|
|
25
|
+
dbLimitInvalid: "[db] limit must be an integer greater than 0",
|
|
26
|
+
dbOffsetInvalid: "[db] offset must be an integer greater than or equal to 0",
|
|
27
|
+
dbValueNotSerializable: "[db] value must be serializable by JSON.stringify.{cause}",
|
|
28
|
+
dbClosed: "[db] SQLite database connection is closed"
|
|
29
|
+
} },
|
|
30
|
+
/** UI 组件内置文案,按组件名分组。 */
|
|
16
31
|
components: {
|
|
17
32
|
breadcrumb: { close: "Close" },
|
|
18
33
|
confirmDialog: {
|
|
@@ -64,6 +79,7 @@ var defaultEnglishResources = {
|
|
|
64
79
|
rotateRight: "Rotate right",
|
|
65
80
|
flipHorizontal: "Flip horizontal",
|
|
66
81
|
flipVertical: "Flip vertical",
|
|
82
|
+
/** {index} 会在运行时由调用方传入的插值数据替换。 */
|
|
67
83
|
previewImage: "Preview image {index}"
|
|
68
84
|
},
|
|
69
85
|
modal: {
|
|
@@ -2,6 +2,7 @@ import "./default.js";
|
|
|
2
2
|
import "./en-US.js";
|
|
3
3
|
import { defaultLanguage, languageLocalKey, translations } from "./locales.js";
|
|
4
4
|
//#region packages/common/i18n/index.ts
|
|
5
|
+
/** 判断某个消息节点是否是可继续递归访问的普通字典。 */
|
|
5
6
|
var isPlainI18nDictionary = (value) => {
|
|
6
7
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7
8
|
};
|
|
@@ -65,6 +66,10 @@ var translate = (state, key, fillingData, options) => {
|
|
|
65
66
|
const value = getI18nPathValue(state.resources[language], key) ?? getI18nPathValue(state.resources[fallbackLanguage], key) ?? options?.fallback ?? key;
|
|
66
67
|
return typeof value === "string" ? interpolateI18nMessage(value, fillingData) : value;
|
|
67
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* 获取可用于持久化语言的浏览器 window。
|
|
71
|
+
* Node、SSR 或测试环境下没有 window 时返回 undefined。
|
|
72
|
+
*/
|
|
68
73
|
var getBrowserWindow = () => {
|
|
69
74
|
return globalThis.window;
|
|
70
75
|
};
|
|
@@ -92,6 +97,11 @@ var createInitialState = () => ({
|
|
|
92
97
|
storageKey: languageLocalKey,
|
|
93
98
|
persist: true
|
|
94
99
|
});
|
|
100
|
+
/**
|
|
101
|
+
* 创建模块内部使用的最小 store。
|
|
102
|
+
*
|
|
103
|
+
* 这里只实现 getState / setState / subscribe,避免 common 层为了 i18n 引入状态管理依赖。
|
|
104
|
+
*/
|
|
95
105
|
var createI18nStore = () => {
|
|
96
106
|
let state;
|
|
97
107
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -148,6 +158,7 @@ var createI18nStore = () => {
|
|
|
148
158
|
}
|
|
149
159
|
};
|
|
150
160
|
};
|
|
161
|
+
/** 全局 i18n store,React 适配层和非 React 代码共享这一份状态。 */
|
|
151
162
|
var i18nStore = createI18nStore();
|
|
152
163
|
/**
|
|
153
164
|
* 对外使用的 i18n 函数。
|
|
@@ -156,7 +167,9 @@ var i18nStore = createI18nStore();
|
|
|
156
167
|
var i18n = (key, fillingData, options) => {
|
|
157
168
|
return translate(i18nStore.getState(), key, fillingData, options);
|
|
158
169
|
};
|
|
170
|
+
/** i18n 的简写别名。 */
|
|
159
171
|
var t = i18n;
|
|
172
|
+
/** 兼容历史调用的别名,行为等同于 i18n。 */
|
|
160
173
|
var getLanguage = i18n;
|
|
161
174
|
//#endregion
|
|
162
175
|
export { getI18nPathValue, getLanguage, i18n, i18nStore, interpolateI18nMessage, isPlainI18nDictionary, mergeI18nDictionary, mergeI18nResources, t, translate };
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { defaultLanguageResources } from "./default.js";
|
|
2
2
|
import { defaultEnglishResources } from "./en-US.js";
|
|
3
3
|
//#region packages/common/i18n/locales.ts
|
|
4
|
+
/** 默认语言,作为初始化语言和翻译兜底语言使用。 */
|
|
4
5
|
var defaultLanguage = "zh-CN";
|
|
6
|
+
/** 默认保存用户语言偏好的 localStorage key。 */
|
|
5
7
|
var languageLocalKey = "tc_language";
|
|
8
|
+
/**
|
|
9
|
+
* 内置语言资源。
|
|
10
|
+
*
|
|
11
|
+
* 业务项目可以通过 I18nProvider.resources、setResources 或 addResources 覆盖和追加。
|
|
12
|
+
*/
|
|
6
13
|
var translations = {
|
|
7
14
|
"zh-CN": defaultLanguageResources,
|
|
8
15
|
"en-US": defaultEnglishResources
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useI18nStore } from "../../i18n/useI18n.js";
|
|
2
|
+
import "../../i18n/index.js";
|
|
1
3
|
import { cn } from "../../lib/utils.js";
|
|
2
4
|
import { Button } from "../Button/Button.js";
|
|
3
5
|
import "../Button/index.js";
|
|
@@ -8,14 +10,16 @@ import { useMemo, useState } from "react";
|
|
|
8
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
11
|
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react";
|
|
10
12
|
import { addMonths, addYears, eachDayOfInterval, endOfDay, endOfMonth, endOfWeek, format, isAfter, isBefore, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, subDays, subMonths, subYears } from "date-fns";
|
|
11
|
-
import { zhCN } from "date-fns/locale";
|
|
13
|
+
import { enUS, zhCN } from "date-fns/locale";
|
|
12
14
|
//#region packages/react/ui/components/Date/Calendar.tsx
|
|
13
15
|
function Calendar({ mode = ModeType.Single, value, onChange, disabledDate, showTime, className, locale: customLocale, quickRanges }) {
|
|
16
|
+
const language = useI18nStore((state) => state.language);
|
|
14
17
|
const contextLocale = useDateLocale();
|
|
15
18
|
const locale = useMemo(() => ({
|
|
16
19
|
...contextLocale,
|
|
17
20
|
...customLocale
|
|
18
21
|
}), [contextLocale, customLocale]);
|
|
22
|
+
const dateFnsLocale = language === "zh-CN" ? zhCN : enUS;
|
|
19
23
|
const [pendingValue, setPendingValue] = useState(value ?? null);
|
|
20
24
|
const [currentMonth, setCurrentMonth] = useState(() => {
|
|
21
25
|
if (value instanceof Date) return value;
|
|
@@ -28,11 +32,11 @@ function Calendar({ mode = ModeType.Single, value, onChange, disabledDate, showT
|
|
|
28
32
|
const monthEnd = endOfMonth(monthStart);
|
|
29
33
|
const daysInGrid = eachDayOfInterval({
|
|
30
34
|
start: startOfWeek(monthStart, {
|
|
31
|
-
locale:
|
|
35
|
+
locale: dateFnsLocale,
|
|
32
36
|
weekStartsOn: 0
|
|
33
37
|
}),
|
|
34
38
|
end: endOfWeek(monthEnd, {
|
|
35
|
-
locale:
|
|
39
|
+
locale: dateFnsLocale,
|
|
36
40
|
weekStartsOn: 0
|
|
37
41
|
})
|
|
38
42
|
});
|
|
@@ -46,7 +50,7 @@ function Calendar({ mode = ModeType.Single, value, onChange, disabledDate, showT
|
|
|
46
50
|
daysInGrid.push(...extraDays);
|
|
47
51
|
}
|
|
48
52
|
return daysInGrid;
|
|
49
|
-
}, [currentMonth]);
|
|
53
|
+
}, [currentMonth, dateFnsLocale]);
|
|
50
54
|
const weekDays = locale.weekDays;
|
|
51
55
|
const isRangeMode = mode === ModeType.Range;
|
|
52
56
|
const builtInQuickRanges = useMemo(() => [
|
|
@@ -238,7 +242,7 @@ function Calendar({ mode = ModeType.Single, value, onChange, disabledDate, showT
|
|
|
238
242
|
}),
|
|
239
243
|
/* @__PURE__ */ jsx("div", {
|
|
240
244
|
className: "font-medium text-sm",
|
|
241
|
-
children: format(currentMonth, locale.monthFormat, { locale:
|
|
245
|
+
children: format(currentMonth, locale.monthFormat, { locale: dateFnsLocale })
|
|
242
246
|
}),
|
|
243
247
|
/* @__PURE__ */ jsxs("div", {
|
|
244
248
|
className: "flex items-center gap-1",
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { type DateLocaleConfig } from "./locales";
|
|
2
|
+
export declare const DateLocaleContext: import("react").Context<Partial<DateLocaleConfig> | undefined>;
|
|
3
|
+
export declare const useDateLocale: () => {
|
|
4
|
+
placeholder: string;
|
|
5
|
+
placeholderDateTime: string;
|
|
6
|
+
placeholderRange: string;
|
|
7
|
+
placeholderDateTimeRange: string;
|
|
8
|
+
weekDays: string[];
|
|
9
|
+
selectTime: string;
|
|
10
|
+
startTime: string;
|
|
11
|
+
endTime: string;
|
|
12
|
+
confirm: string;
|
|
13
|
+
monthFormat: string;
|
|
14
|
+
quickRanges: string;
|
|
15
|
+
quickRangeToday: string;
|
|
16
|
+
quickRangeYesterday: string;
|
|
17
|
+
quickRangeLast7Days: string;
|
|
18
|
+
quickRangeLast30Days: string;
|
|
19
|
+
quickRangeThisMonth: string;
|
|
20
|
+
quickRangeLastYear: string;
|
|
21
|
+
clear: string;
|
|
22
|
+
};
|
|
@@ -1,11 +1,36 @@
|
|
|
1
|
+
import { useI18nStore } from "../../i18n/useI18n.js";
|
|
2
|
+
import "../../i18n/index.js";
|
|
3
|
+
import { defaultLocale, getDateLocale } from "./locales.js";
|
|
1
4
|
import { useDateLocaleStore } from "./dateLocaleStore.js";
|
|
5
|
+
import { createContext, useContext, useMemo } from "react";
|
|
2
6
|
//#region packages/react/ui/components/Date/LocaleContext.tsx
|
|
7
|
+
var DateLocaleContext = createContext(void 0);
|
|
3
8
|
/**
|
|
4
9
|
* Hook for accessing the current Date component locale.
|
|
5
|
-
* Backed by
|
|
10
|
+
* Backed by the shared i18n store, so Date updates with the global language.
|
|
6
11
|
*/
|
|
7
12
|
var useDateLocale = () => {
|
|
8
|
-
|
|
13
|
+
const language = useI18nStore((state) => state.language);
|
|
14
|
+
const fallbackLanguage = useI18nStore((state) => state.fallbackLanguage);
|
|
15
|
+
const resources = useI18nStore((state) => state.resources);
|
|
16
|
+
const storeLocale = useDateLocaleStore((state) => state.locale);
|
|
17
|
+
const localeOverride = useContext(DateLocaleContext);
|
|
18
|
+
const storeLocaleOverride = storeLocale === defaultLocale ? void 0 : storeLocale;
|
|
19
|
+
return useMemo(() => ({
|
|
20
|
+
...getDateLocale({
|
|
21
|
+
language,
|
|
22
|
+
fallbackLanguage,
|
|
23
|
+
resources
|
|
24
|
+
}),
|
|
25
|
+
...storeLocaleOverride,
|
|
26
|
+
...localeOverride
|
|
27
|
+
}), [
|
|
28
|
+
fallbackLanguage,
|
|
29
|
+
language,
|
|
30
|
+
localeOverride,
|
|
31
|
+
resources,
|
|
32
|
+
storeLocaleOverride
|
|
33
|
+
]);
|
|
9
34
|
};
|
|
10
35
|
//#endregion
|
|
11
|
-
export { useDateLocale };
|
|
36
|
+
export { DateLocaleContext, useDateLocale };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type DateLocaleConfig } from "./locales";
|
|
3
3
|
export interface DateLocaleProviderProps {
|
|
4
|
-
locale?: DateLocaleConfig
|
|
4
|
+
locale?: Partial<DateLocaleConfig>;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
export declare function DateLocaleProvider({ locale, children }: DateLocaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
1
|
+
import { DateLocaleContext } from "./LocaleContext.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
3
|
//#region packages/react/ui/components/Date/LocaleProvider.tsx
|
|
6
4
|
/**
|
|
7
5
|
* Date 组件文案配置 Provider
|
|
@@ -14,18 +12,11 @@ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
|
14
12
|
* </DateLocaleProvider>
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
17
|
-
function DateLocaleProvider({ locale
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return () => resetLocale();
|
|
23
|
-
}, [
|
|
24
|
-
locale,
|
|
25
|
-
replaceLocale,
|
|
26
|
-
resetLocale
|
|
27
|
-
]);
|
|
28
|
-
return /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
15
|
+
function DateLocaleProvider({ locale, children }) {
|
|
16
|
+
return /* @__PURE__ */ jsx(DateLocaleContext.Provider, {
|
|
17
|
+
value: locale,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
29
20
|
}
|
|
30
21
|
//#endregion
|
|
31
22
|
export { DateLocaleProvider };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defaultLocale, enUSLocale, zhCNLocale } from "./locales.js";
|
|
1
|
+
import { defaultLocale, enUSLocale, getDateLocale, zhCNLocale } from "./locales.js";
|
|
2
2
|
import { useDateLocaleStore } from "./dateLocaleStore.js";
|
|
3
3
|
import { useDateLocale } from "./LocaleContext.js";
|
|
4
4
|
import { DatePicker } from "./Date.js";
|
|
5
5
|
import { DateLocaleProvider } from "./LocaleProvider.js";
|
|
6
|
-
export { DateLocaleProvider, DatePicker, defaultLocale, enUSLocale, useDateLocale, useDateLocaleStore, zhCNLocale };
|
|
6
|
+
export { DateLocaleProvider, DatePicker, defaultLocale, enUSLocale, getDateLocale, useDateLocale, useDateLocaleStore, zhCNLocale };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nTranslateState } from "../../../../common/i18n/index";
|
|
1
2
|
export interface DateLocaleConfig {
|
|
2
3
|
placeholder: string;
|
|
3
4
|
placeholderDateTime: string;
|
|
@@ -18,6 +19,7 @@ export interface DateLocaleConfig {
|
|
|
18
19
|
quickRangeLastYear: string;
|
|
19
20
|
clear: string;
|
|
20
21
|
}
|
|
22
|
+
export declare const getDateLocale: (state: I18nTranslateState) => DateLocaleConfig;
|
|
21
23
|
export declare const zhCNLocale: DateLocaleConfig;
|
|
22
24
|
export declare const enUSLocale: DateLocaleConfig;
|
|
23
25
|
export declare const defaultLocale: DateLocaleConfig;
|
|
@@ -1,25 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultEnglishResources } from "../../../../common/i18n/en-US.js";
|
|
1
|
+
import { i18nStore, translate } from "../../../../common/i18n/index.js";
|
|
3
2
|
//#region packages/react/ui/components/Date/locales.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
3
|
+
var getDateLocale = (state) => ({
|
|
4
|
+
placeholder: translate(state, "components.date.placeholder"),
|
|
5
|
+
placeholderDateTime: translate(state, "components.date.placeholderDateTime"),
|
|
6
|
+
placeholderRange: translate(state, "components.date.placeholderRange"),
|
|
7
|
+
placeholderDateTimeRange: translate(state, "components.date.placeholderDateTimeRange"),
|
|
8
|
+
weekDays: [...translate(state, "components.date.weekDays")],
|
|
9
|
+
selectTime: translate(state, "components.date.selectTime"),
|
|
10
|
+
startTime: translate(state, "components.date.startTime"),
|
|
11
|
+
endTime: translate(state, "components.date.endTime"),
|
|
12
|
+
confirm: translate(state, "components.date.confirm"),
|
|
13
|
+
monthFormat: translate(state, "components.date.monthFormat"),
|
|
14
|
+
quickRanges: translate(state, "components.date.quickRanges"),
|
|
15
|
+
quickRangeToday: translate(state, "components.date.quickRangeToday"),
|
|
16
|
+
quickRangeYesterday: translate(state, "components.date.quickRangeYesterday"),
|
|
17
|
+
quickRangeLast7Days: translate(state, "components.date.quickRangeLast7Days"),
|
|
18
|
+
quickRangeLast30Days: translate(state, "components.date.quickRangeLast30Days"),
|
|
19
|
+
quickRangeThisMonth: translate(state, "components.date.quickRangeThisMonth"),
|
|
20
|
+
quickRangeLastYear: translate(state, "components.date.quickRangeLastYear"),
|
|
21
|
+
clear: translate(state, "components.date.clear")
|
|
22
|
+
});
|
|
23
|
+
var getDateLocaleByLanguage = (language) => getDateLocale({
|
|
24
|
+
language,
|
|
25
|
+
fallbackLanguage: i18nStore.getState().fallbackLanguage,
|
|
26
|
+
resources: i18nStore.getState().resources
|
|
27
|
+
});
|
|
6
28
|
/**
|
|
7
29
|
* 默认中文文案
|
|
8
30
|
*/
|
|
9
|
-
var zhCNLocale = {
|
|
10
|
-
...dateDefaultLocale,
|
|
11
|
-
weekDays: [...dateDefaultLocale.weekDays]
|
|
12
|
-
};
|
|
31
|
+
var zhCNLocale = { ...getDateLocaleByLanguage("zh-CN") };
|
|
13
32
|
/**
|
|
14
33
|
* 默认英文文案
|
|
15
34
|
*/
|
|
16
|
-
var enUSLocale = {
|
|
17
|
-
...dateDefaultEnglishLocale,
|
|
18
|
-
weekDays: [...dateDefaultEnglishLocale.weekDays]
|
|
19
|
-
};
|
|
35
|
+
var enUSLocale = { ...getDateLocaleByLanguage("en-US") };
|
|
20
36
|
/**
|
|
21
37
|
* 默认使用中文文案
|
|
22
38
|
*/
|
|
23
39
|
var defaultLocale = zhCNLocale;
|
|
24
40
|
//#endregion
|
|
25
|
-
export { defaultLocale, enUSLocale, zhCNLocale };
|
|
41
|
+
export { defaultLocale, enUSLocale, getDateLocale, zhCNLocale };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useI18nStore } from "../../i18n/useI18n.js";
|
|
2
|
+
import "../../i18n/index.js";
|
|
1
3
|
import { cn } from "../../lib/utils.js";
|
|
2
4
|
import { Button } from "../Button/Button.js";
|
|
3
5
|
import "../Button/index.js";
|
|
@@ -6,6 +8,7 @@ import "../Dropdown/index.js";
|
|
|
6
8
|
import Search from "../Search/Search.js";
|
|
7
9
|
import "../Search/index.js";
|
|
8
10
|
import { ExportType } from "../../lib/export.js";
|
|
11
|
+
import { defaultLocale, getTableSearchLocale } from "./lang.js";
|
|
9
12
|
import { useTableSearchLocaleStore } from "./tableSearchLocaleStore.js";
|
|
10
13
|
import { useMemo, useRef, useState } from "react";
|
|
11
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -27,7 +30,24 @@ var TableSearch = (props) => {
|
|
|
27
30
|
const handleExpand = () => {
|
|
28
31
|
setIsExpanded(!isExpanded);
|
|
29
32
|
};
|
|
30
|
-
const
|
|
33
|
+
const language = useI18nStore((state) => state.language);
|
|
34
|
+
const fallbackLanguage = useI18nStore((state) => state.fallbackLanguage);
|
|
35
|
+
const resources = useI18nStore((state) => state.resources);
|
|
36
|
+
const storeLocale = useTableSearchLocaleStore((state) => state.locale);
|
|
37
|
+
const storeLocaleOverride = storeLocale === defaultLocale ? void 0 : storeLocale;
|
|
38
|
+
const locale = useMemo(() => ({
|
|
39
|
+
...getTableSearchLocale({
|
|
40
|
+
language,
|
|
41
|
+
fallbackLanguage,
|
|
42
|
+
resources
|
|
43
|
+
}),
|
|
44
|
+
...storeLocaleOverride
|
|
45
|
+
}), [
|
|
46
|
+
fallbackLanguage,
|
|
47
|
+
language,
|
|
48
|
+
resources,
|
|
49
|
+
storeLocaleOverride
|
|
50
|
+
]);
|
|
31
51
|
const defaultExportItems = useMemo(() => exportMenuItems || [{
|
|
32
52
|
key: "export-current-page",
|
|
33
53
|
label: locale.exportCurrentPage,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nTranslateState } from "../../../../common/i18n/index";
|
|
1
2
|
export interface TableSearchLocaleConfig {
|
|
2
3
|
reset: string;
|
|
3
4
|
search: string;
|
|
@@ -7,6 +8,7 @@ export interface TableSearchLocaleConfig {
|
|
|
7
8
|
exportCurrentPage: string;
|
|
8
9
|
exportCurrentQuery: string;
|
|
9
10
|
}
|
|
11
|
+
export declare const getTableSearchLocale: (state: I18nTranslateState) => TableSearchLocaleConfig;
|
|
10
12
|
export declare const zhCNLocale: TableSearchLocaleConfig;
|
|
11
13
|
export declare const enUSLocale: TableSearchLocaleConfig;
|
|
12
14
|
export declare const defaultLocale: TableSearchLocaleConfig;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultEnglishResources } from "../../../../common/i18n/en-US.js";
|
|
1
|
+
import { i18nStore, translate } from "../../../../common/i18n/index.js";
|
|
3
2
|
//#region packages/react/ui/components/TableSearch/lang.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
var getTableSearchLocale = (state) => ({
|
|
4
|
+
reset: translate(state, "components.tableSearch.reset"),
|
|
5
|
+
search: translate(state, "components.tableSearch.search"),
|
|
6
|
+
export: translate(state, "components.tableSearch.export"),
|
|
7
|
+
expand: translate(state, "components.tableSearch.expand"),
|
|
8
|
+
collapse: translate(state, "components.tableSearch.collapse"),
|
|
9
|
+
exportCurrentPage: translate(state, "components.tableSearch.exportCurrentPage"),
|
|
10
|
+
exportCurrentQuery: translate(state, "components.tableSearch.exportCurrentQuery")
|
|
11
|
+
});
|
|
12
|
+
var getTableSearchLocaleByLanguage = (language) => getTableSearchLocale({
|
|
13
|
+
language,
|
|
14
|
+
fallbackLanguage: i18nStore.getState().fallbackLanguage,
|
|
15
|
+
resources: i18nStore.getState().resources
|
|
16
|
+
});
|
|
17
|
+
var zhCNLocale = { ...getTableSearchLocaleByLanguage("zh-CN") };
|
|
18
|
+
var enUSLocale = { ...getTableSearchLocaleByLanguage("en-US") };
|
|
8
19
|
var defaultLocale = zhCNLocale;
|
|
9
20
|
var btnConfig = defaultLocale;
|
|
10
21
|
var updateBtnConfig = (config) => {
|
|
11
22
|
Object.assign(btnConfig, config);
|
|
12
23
|
};
|
|
13
24
|
//#endregion
|
|
14
|
-
export { btnConfig, defaultLocale, enUSLocale, updateBtnConfig, zhCNLocale };
|
|
25
|
+
export { btnConfig, defaultLocale, enUSLocale, getTableSearchLocale, updateBtnConfig, zhCNLocale };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChangeEvent, TextareaHTMLAttributes } from "react";
|
|
2
|
-
export type TextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
2
|
+
export type TextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onChange' | 'defaultValue'> & {
|
|
3
3
|
value?: string;
|
|
4
4
|
onChange?: (v: string, e: ChangeEvent<HTMLTextAreaElement>) => void;
|
|
5
5
|
defaultValue?: string;
|
|
@@ -21,7 +21,7 @@ var Textarea = forwardRef(({ className, textareaClassName, value: controlledValu
|
|
|
21
21
|
setInternalValue
|
|
22
22
|
]);
|
|
23
23
|
return /* @__PURE__ */ jsxs("div", {
|
|
24
|
-
className: cn("tc-ui-textarea relative
|
|
24
|
+
className: cn("tc-ui-textarea relative", className),
|
|
25
25
|
children: [/* @__PURE__ */ jsx("textarea", {
|
|
26
26
|
ref: setRefs,
|
|
27
27
|
value,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { I18nAddResourcesOptions, I18nDictionary, I18nInterpolationValues, I18nLanguage, I18nResources, I18nSetResourcesOptions, I18nTranslateOptions } from "../../../../fe/packages/react/ui/i18n/index";
|
|
2
2
|
export declare const addLanguageResources: (language: I18nLanguage, messages: I18nDictionary, options?: I18nAddResourcesOptions) => void;
|
|
3
|
-
export declare const addResources: (language: I18nLanguage, messages: I18nDictionary, options?: I18nAddResourcesOptions) => void;
|
|
4
|
-
export declare const addLanguage: (language: I18nLanguage, messages?: I18nDictionary, options?: I18nAddResourcesOptions) => void;
|
|
5
3
|
export declare const setLanguage: (language: I18nLanguage) => void;
|
|
6
4
|
export declare const setFallbackLanguage: (language: I18nLanguage) => void;
|
|
7
5
|
export declare const setResources: (resources: I18nResources, options?: I18nSetResourcesOptions) => void;
|
|
@@ -9,6 +7,7 @@ export declare const getCurrentLanguage: () => string;
|
|
|
9
7
|
export declare const getFallbackLanguage: () => string;
|
|
10
8
|
export declare const getI18nResources: () => Partial<Record<string, I18nDictionary>>;
|
|
11
9
|
export declare const getSupportedLanguages: () => string[];
|
|
10
|
+
export declare const registerFrontendI18nResources: (resources?: I18nResources) => Promise<void>;
|
|
12
11
|
export declare const getText: (key: string, fillingData?: I18nInterpolationValues, options?: I18nTranslateOptions) => string;
|
|
13
12
|
export declare const t: <T = string>(key: string, fillingData?: I18nInterpolationValues, options?: I18nTranslateOptions) => string | T;
|
|
14
13
|
export type { I18nAddResourcesOptions, I18nDictionary, I18nInterpolationValues, I18nLanguage, I18nResources, I18nSetResourcesOptions, I18nTranslateOptions, };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { I18nInterpolationValues, I18nTranslateOptions } from "../../../../fe/packages/react/ui/i18n/index";
|
|
2
|
+
export type TextTranslator = <T = string>(key: string, fillingData?: I18nInterpolationValues, options?: I18nTranslateOptions) => T | string;
|
|
3
|
+
export declare const useText: () => TextTranslator;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { I18nResources } from "../../../../fe/packages/react/ui/i18n/index";
|
|
2
1
|
export declare const i18nKeyPrefix = "$i18n::";
|
|
3
|
-
export declare const frontendI18nResources: I18nResources;
|
|
4
2
|
export declare const withI18nKey: (key: string) => string;
|
|
5
3
|
export declare const frontendLangKeys: {
|
|
6
4
|
readonly appTitle: string;
|
|
@@ -7,6 +7,21 @@ export declare const defaultLanguageResources: {
|
|
|
7
7
|
readonly submit: "提交";
|
|
8
8
|
readonly reset: "重置";
|
|
9
9
|
};
|
|
10
|
+
readonly server: {
|
|
11
|
+
readonly errors: {
|
|
12
|
+
readonly network: "网络错误";
|
|
13
|
+
readonly invalidRequest: "请求不合法";
|
|
14
|
+
readonly getProjectFailed: "获取项目异常";
|
|
15
|
+
readonly dbNodeSqliteUnavailable: "[db] 默认数据库依赖 Node.js 内置 {sqliteSpecifier},当前运行环境不可用。请升级 Node.js,或在业务项目覆盖 app/extends/db.ts。{cause}";
|
|
16
|
+
readonly dbDatabaseSyncUnavailable: "[db] {sqliteSpecifier} 未提供 DatabaseSync,无法初始化默认 SQLite 数据库。";
|
|
17
|
+
readonly dbNamespaceRequired: "[db] namespace 不能为空";
|
|
18
|
+
readonly dbKeyRequired: "[db] key 不能为空";
|
|
19
|
+
readonly dbLimitInvalid: "[db] limit 必须是大于 0 的整数";
|
|
20
|
+
readonly dbOffsetInvalid: "[db] offset 必须是大于等于 0 的整数";
|
|
21
|
+
readonly dbValueNotSerializable: "[db] value 必须可以被 JSON.stringify 序列化。{cause}";
|
|
22
|
+
readonly dbClosed: "[db] SQLite 数据库连接已关闭";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
10
25
|
readonly components: {
|
|
11
26
|
readonly breadcrumb: {
|
|
12
27
|
readonly close: "关闭";
|
|
@@ -7,6 +7,21 @@ export declare const defaultEnglishResources: {
|
|
|
7
7
|
readonly submit: "Submit";
|
|
8
8
|
readonly reset: "Reset";
|
|
9
9
|
};
|
|
10
|
+
readonly server: {
|
|
11
|
+
readonly errors: {
|
|
12
|
+
readonly network: "Network error";
|
|
13
|
+
readonly invalidRequest: "Invalid request";
|
|
14
|
+
readonly getProjectFailed: "Failed to get project";
|
|
15
|
+
readonly dbNodeSqliteUnavailable: "[db] The default database depends on Node.js built-in {sqliteSpecifier}, which is unavailable in the current runtime. Upgrade Node.js or override app/extends/db.ts in the business project.{cause}";
|
|
16
|
+
readonly dbDatabaseSyncUnavailable: "[db] {sqliteSpecifier} does not provide DatabaseSync, so the default SQLite database cannot be initialized.";
|
|
17
|
+
readonly dbNamespaceRequired: "[db] namespace cannot be empty";
|
|
18
|
+
readonly dbKeyRequired: "[db] key cannot be empty";
|
|
19
|
+
readonly dbLimitInvalid: "[db] limit must be an integer greater than 0";
|
|
20
|
+
readonly dbOffsetInvalid: "[db] offset must be an integer greater than or equal to 0";
|
|
21
|
+
readonly dbValueNotSerializable: "[db] value must be serializable by JSON.stringify.{cause}";
|
|
22
|
+
readonly dbClosed: "[db] SQLite database connection is closed";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
10
25
|
readonly components: {
|
|
11
26
|
readonly breadcrumb: {
|
|
12
27
|
readonly close: "Close";
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { type DateLocaleConfig } from "./locales";
|
|
2
|
+
export declare const DateLocaleContext: import("react").Context<Partial<DateLocaleConfig> | undefined>;
|
|
3
|
+
export declare const useDateLocale: () => {
|
|
4
|
+
placeholder: string;
|
|
5
|
+
placeholderDateTime: string;
|
|
6
|
+
placeholderRange: string;
|
|
7
|
+
placeholderDateTimeRange: string;
|
|
8
|
+
weekDays: string[];
|
|
9
|
+
selectTime: string;
|
|
10
|
+
startTime: string;
|
|
11
|
+
endTime: string;
|
|
12
|
+
confirm: string;
|
|
13
|
+
monthFormat: string;
|
|
14
|
+
quickRanges: string;
|
|
15
|
+
quickRangeToday: string;
|
|
16
|
+
quickRangeYesterday: string;
|
|
17
|
+
quickRangeLast7Days: string;
|
|
18
|
+
quickRangeLast30Days: string;
|
|
19
|
+
quickRangeThisMonth: string;
|
|
20
|
+
quickRangeLastYear: string;
|
|
21
|
+
clear: string;
|
|
22
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type DateLocaleConfig } from "./locales";
|
|
3
3
|
export interface DateLocaleProviderProps {
|
|
4
|
-
locale?: DateLocaleConfig
|
|
4
|
+
locale?: Partial<DateLocaleConfig>;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
export declare function DateLocaleProvider({ locale, children }: DateLocaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nTranslateState } from "@tc/common/i18n";
|
|
1
2
|
export interface DateLocaleConfig {
|
|
2
3
|
placeholder: string;
|
|
3
4
|
placeholderDateTime: string;
|
|
@@ -18,6 +19,7 @@ export interface DateLocaleConfig {
|
|
|
18
19
|
quickRangeLastYear: string;
|
|
19
20
|
clear: string;
|
|
20
21
|
}
|
|
22
|
+
export declare const getDateLocale: (state: I18nTranslateState) => DateLocaleConfig;
|
|
21
23
|
export declare const zhCNLocale: DateLocaleConfig;
|
|
22
24
|
export declare const enUSLocale: DateLocaleConfig;
|
|
23
25
|
export declare const defaultLocale: DateLocaleConfig;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nTranslateState } from "@tc/common/i18n";
|
|
1
2
|
export interface TableSearchLocaleConfig {
|
|
2
3
|
reset: string;
|
|
3
4
|
search: string;
|
|
@@ -7,6 +8,7 @@ export interface TableSearchLocaleConfig {
|
|
|
7
8
|
exportCurrentPage: string;
|
|
8
9
|
exportCurrentQuery: string;
|
|
9
10
|
}
|
|
11
|
+
export declare const getTableSearchLocale: (state: I18nTranslateState) => TableSearchLocaleConfig;
|
|
10
12
|
export declare const zhCNLocale: TableSearchLocaleConfig;
|
|
11
13
|
export declare const enUSLocale: TableSearchLocaleConfig;
|
|
12
14
|
export declare const defaultLocale: TableSearchLocaleConfig;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChangeEvent, TextareaHTMLAttributes } from "react";
|
|
2
|
-
export type TextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
2
|
+
export type TextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onChange' | 'defaultValue'> & {
|
|
3
3
|
value?: string;
|
|
4
4
|
onChange?: (v: string, e: ChangeEvent<HTMLTextAreaElement>) => void;
|
|
5
5
|
defaultValue?: string;
|
package/package.json
CHANGED