nextjs-cms 0.9.30 → 0.9.31
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 -21
- package/README.md +279 -279
- package/dist/api/actions/pages.d.ts +3 -3
- package/dist/api/client.d.ts +30 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +82 -0
- package/dist/api/index.d.ts +1 -974
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +0 -13
- package/dist/api/lib/serverActions.d.ts +13 -49
- package/dist/api/lib/serverActions.d.ts.map +1 -1
- package/dist/api/lib/serverActions.js +103 -31
- package/dist/api/root.d.ts +18 -1916
- package/dist/api/root.d.ts.map +1 -1
- package/dist/api/root.js +18 -83
- package/dist/api/routers/config.d.ts.map +1 -1
- package/dist/api/routers/gallery.d.ts +1 -0
- package/dist/api/routers/gallery.d.ts.map +1 -1
- package/dist/api/routers/gallery.js +36 -8
- package/dist/api/routers/hasItemsSection.d.ts +5 -30
- package/dist/api/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/routers/navigation.d.ts +3 -3
- package/dist/api/routers/simpleSection.d.ts +3 -15
- package/dist/api/routers/simpleSection.d.ts.map +1 -1
- package/dist/api/server.d.ts +2748 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +100 -0
- package/dist/api/trpc/error-logging.d.ts +14 -0
- package/dist/api/trpc/error-logging.d.ts.map +1 -0
- package/dist/api/trpc/error-logging.js +75 -0
- package/dist/api/trpc/root.d.ts +3 -3
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/config.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -1
- package/dist/api/trpc/server.d.ts +9 -9
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/api/utils/async-caller-proxy.d.ts +2 -0
- package/dist/api/utils/async-caller-proxy.d.ts.map +1 -0
- package/dist/api/utils/async-caller-proxy.js +36 -0
- package/dist/api/utils/lazy-caller-proxy.d.ts +2 -0
- package/dist/api/utils/lazy-caller-proxy.d.ts.map +1 -0
- package/dist/api/utils/lazy-caller-proxy.js +36 -0
- package/dist/api/utils/router-types.d.ts +7 -0
- package/dist/api/utils/router-types.d.ts.map +1 -0
- package/dist/api/utils/router-types.js +0 -0
- package/dist/auth/trpc.d.ts +1 -1
- package/dist/auth/trpc.d.ts.map +1 -1
- package/dist/auth/trpc.js +0 -1
- package/dist/cli/lib/db-config.js +10 -10
- package/dist/cli/lib/update-sections.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.js +29 -24
- package/dist/core/db/table-checker/MysqlTable.js +10 -10
- package/dist/core/factories/section-factory-with-esbuild.js +9 -9
- package/dist/core/factories/section-factory-with-jiti.js +9 -9
- package/dist/core/sections/category.d.ts +42 -42
- package/dist/core/sections/hasItems.d.ts +42 -42
- package/dist/core/sections/section.d.ts +22 -22
- package/dist/core/sections/simple.d.ts +8 -8
- package/dist/plugins/loader.d.ts +3 -1
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +28 -6
- package/dist/plugins/manifest.d.ts +28 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +83 -0
- package/dist/plugins/registry.d.ts +22 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +25 -0
- package/dist/translations/client.d.ts +4 -4
- package/dist/utils/log.d.ts +18 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +28 -0
- package/package.json +3 -3
- package/dist/core/fields/dateRange.d.ts +0 -115
- package/dist/core/fields/dateRange.d.ts.map +0 -1
- package/dist/core/fields/dateRange.js +0 -149
- package/dist/translations/locale-cookie.d.ts +0 -24
- package/dist/translations/locale-cookie.d.ts.map +0 -1
- package/dist/translations/locale-cookie.js +0 -44
- package/dist/translations/locale-utils.d.ts +0 -8
- package/dist/translations/locale-utils.d.ts.map +0 -1
- package/dist/translations/locale-utils.js +0 -11
- package/dist/translations/localization.d.ts +0 -40
- package/dist/translations/localization.d.ts.map +0 -1
- package/dist/translations/localization.js +0 -48
- package/dist/validators/dateRange.d.ts +0 -11
- package/dist/validators/dateRange.d.ts.map +0 -1
- package/dist/validators/dateRange.js +0 -16
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { Field, baseFieldConfigSchema } from './field.js';
|
|
2
|
-
import { entityKind } from '../helpers/index.js';
|
|
3
|
-
import * as z from 'zod';
|
|
4
|
-
import dayjs from 'dayjs';
|
|
5
|
-
import getString from '../../translations/index.js';
|
|
6
|
-
const configSchema = z.strictObject({
|
|
7
|
-
startName: z.string().describe('The DB column name for the start date'),
|
|
8
|
-
endName: z.string().describe('The DB column name for the end date'),
|
|
9
|
-
format: z.enum(['date', 'datetime']).optional().describe('The format of the date columns'),
|
|
10
|
-
defaultStartValue: z.custom().optional().describe('Default value for the start date'),
|
|
11
|
-
defaultEndValue: z.custom().optional().describe('Default value for the end date'),
|
|
12
|
-
});
|
|
13
|
-
/**
|
|
14
|
-
* DateRangeField stores two DB columns: startName and endName.
|
|
15
|
-
*
|
|
16
|
-
* Because Field expects a single `name`, we pass `startName` as `name` to the
|
|
17
|
-
* super constructor (used for label generation / identity only).
|
|
18
|
-
* The field opts out of the normal single-column SQL path via hasSqlNameAndValue()=false
|
|
19
|
-
* and instead exposes setValues() / getSqlNamesAndValues() which submit.ts calls
|
|
20
|
-
* via an is(field, DateRangeField) guard — the same pattern used for SelectField.
|
|
21
|
-
*/
|
|
22
|
-
export class DateRangeField extends Field {
|
|
23
|
-
static [entityKind] = 'DateRangeField';
|
|
24
|
-
startName;
|
|
25
|
-
endName;
|
|
26
|
-
format;
|
|
27
|
-
startValue;
|
|
28
|
-
endValue;
|
|
29
|
-
constructor(config) {
|
|
30
|
-
// Pass startName as `name` so the base class label-generation / identity works
|
|
31
|
-
super({ ...config, name: config.startName }, 'date_range');
|
|
32
|
-
this.startName = config.startName;
|
|
33
|
-
this.endName = config.endName;
|
|
34
|
-
this.format = config.format ?? 'date';
|
|
35
|
-
this.startValue = config.defaultStartValue ?? undefined;
|
|
36
|
-
this.endValue = config.defaultEndValue ?? undefined;
|
|
37
|
-
}
|
|
38
|
-
// ─── Opt out of single-column SQL path ────────────────────────────────────
|
|
39
|
-
hasSqlNameAndValue() {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
// ─── Dual-column FormData reading (called by submit.ts) ───────────────────
|
|
43
|
-
setValues(postData) {
|
|
44
|
-
const start = postData.get(this.startName);
|
|
45
|
-
const end = postData.get(this.endName);
|
|
46
|
-
if (start)
|
|
47
|
-
this.startValue = start;
|
|
48
|
-
if (end)
|
|
49
|
-
this.endValue = end;
|
|
50
|
-
}
|
|
51
|
-
// ─── Dual-column SQL output (called by submit.ts) ─────────────────────────
|
|
52
|
-
getSqlNamesAndValues() {
|
|
53
|
-
return {
|
|
54
|
-
[this.startName]: this.formatDate(this.startValue),
|
|
55
|
-
[this.endName]: this.formatDate(this.endValue),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// ─── Standard Field interface ─────────────────────────────────────────────
|
|
59
|
-
getValue() {
|
|
60
|
-
return {
|
|
61
|
-
from: this.formatDate(this.startValue),
|
|
62
|
-
to: this.formatDate(this.endValue),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exportForClient() {
|
|
66
|
-
return {
|
|
67
|
-
...super.exportForClient(),
|
|
68
|
-
startName: this.startName,
|
|
69
|
-
endName: this.endName,
|
|
70
|
-
format: this.format,
|
|
71
|
-
startValue: this.startValue ?? null,
|
|
72
|
-
endValue: this.endValue ?? null,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
checkRequired() {
|
|
76
|
-
if (!this.required)
|
|
77
|
-
return;
|
|
78
|
-
if (!this.parseDate(this.startValue) || !this.parseDate(this.endValue)) {
|
|
79
|
-
throw new Error(getString('fieldIsRequired', this.language, { field: this.getLocalizedLabel() }));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async prepareForSubmission() {
|
|
83
|
-
const start = this.parseDate(this.startValue);
|
|
84
|
-
const end = this.parseDate(this.endValue);
|
|
85
|
-
if (this.required && (!start || !end)) {
|
|
86
|
-
throw new Error(getString('invalidDatePleaseProvideValid', this.language, { field: this.getLocalizedLabel() }));
|
|
87
|
-
}
|
|
88
|
-
if (start)
|
|
89
|
-
this.startValue = start.toISOString();
|
|
90
|
-
if (end)
|
|
91
|
-
this.endValue = end.toISOString();
|
|
92
|
-
}
|
|
93
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────
|
|
94
|
-
parseDate(value) {
|
|
95
|
-
if (value === undefined || value === null || value === '')
|
|
96
|
-
return null;
|
|
97
|
-
const date = new Date(value);
|
|
98
|
-
return isNaN(date.getTime()) ? null : date;
|
|
99
|
-
}
|
|
100
|
-
formatDate(value) {
|
|
101
|
-
const date = this.parseDate(value);
|
|
102
|
-
if (!date)
|
|
103
|
-
return null;
|
|
104
|
-
return this.format === 'datetime'
|
|
105
|
-
? dayjs(date).format('YYYY-MM-DD HH:mm:ss')
|
|
106
|
-
: dayjs(date).format('YYYY-MM-DD');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// ─── Config schema & factory ──────────────────────────────────────────────────
|
|
110
|
-
const optionsSchema = z.strictObject({
|
|
111
|
-
...baseFieldConfigSchema.omit({ name: true }).shape,
|
|
112
|
-
...configSchema.shape,
|
|
113
|
-
});
|
|
114
|
-
const dateRangeFieldConfigSchema = z.strictObject({
|
|
115
|
-
...optionsSchema.shape,
|
|
116
|
-
/**
|
|
117
|
-
* Auto-computed as `${startName}|${endName}`.
|
|
118
|
-
* Satisfies the `FieldConfig` union constraint that every config has a `name` property.
|
|
119
|
-
* Never set manually — use `startName` and `endName` instead.
|
|
120
|
-
*/
|
|
121
|
-
name: z.string(),
|
|
122
|
-
type: z.literal('date_range').describe('The type of the field'),
|
|
123
|
-
build: z
|
|
124
|
-
.function()
|
|
125
|
-
.output(z.instanceof(DateRangeField))
|
|
126
|
-
.describe('Build a DateRangeField instance from this config'),
|
|
127
|
-
});
|
|
128
|
-
/**
|
|
129
|
-
* Helper to create a date range field configuration.
|
|
130
|
-
* Uses `startName` and `endName` instead of the usual `name`.
|
|
131
|
-
* The `name` property is auto-computed as `${startName}|${endName}`.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* dateRangeField({ startName: 'event_start', endName: 'event_end', label: 'Event Dates' })
|
|
135
|
-
*/
|
|
136
|
-
export function dateRangeField(field) {
|
|
137
|
-
const result = optionsSchema.safeParse(field);
|
|
138
|
-
if (!result.success) {
|
|
139
|
-
throw new Error(`[DateRangeField: ${field.startName}/${field.endName}]: ${z.prettifyError(result.error)}`);
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
...field,
|
|
143
|
-
name: `${field.startName}|${field.endName}`,
|
|
144
|
-
type: 'date_range',
|
|
145
|
-
build() {
|
|
146
|
-
return new DateRangeField(field);
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cookie used to persist locale on the login page (no session).
|
|
3
|
-
* Read by auth layout when unauthenticated; set by login-page locale dropdown.
|
|
4
|
-
*/
|
|
5
|
-
export declare const LOCALE_COOKIE_NAME = "nextjs-cms-locale";
|
|
6
|
-
/**
|
|
7
|
-
* Set the login-page locale cookie (client-only).
|
|
8
|
-
* Call when user changes language on the login page; auth layout reads it when no session.
|
|
9
|
-
*/
|
|
10
|
-
export declare function setLoginPageLocaleCookie(locale: string): void;
|
|
11
|
-
/**
|
|
12
|
-
* Mark that user explicitly changed locale on login page.
|
|
13
|
-
* Used to determine whether to send locale to server on login.
|
|
14
|
-
*/
|
|
15
|
-
export declare function markLocaleChangedOnLogin(): void;
|
|
16
|
-
/**
|
|
17
|
-
* Check if user explicitly changed locale on login page.
|
|
18
|
-
*/
|
|
19
|
-
export declare function wasLocaleChangedOnLogin(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Clear the locale changed flag after login.
|
|
22
|
-
*/
|
|
23
|
-
export declare function clearLocaleChangedOnLogin(): void;
|
|
24
|
-
//# sourceMappingURL=locale-cookie.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-cookie.d.ts","sourceRoot":"","sources":["../../src/translations/locale-cookie.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,sBAAsB,CAAA;AASrD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAG7D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAG/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAGjD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cookie used to persist locale on the login page (no session).
|
|
3
|
-
* Read by auth layout when unauthenticated; set by login-page locale dropdown.
|
|
4
|
-
*/
|
|
5
|
-
export const LOCALE_COOKIE_NAME = 'nextjs-cms-locale';
|
|
6
|
-
/**
|
|
7
|
-
* SessionStorage key to track if user explicitly changed locale on login page.
|
|
8
|
-
*/
|
|
9
|
-
const LOCALE_CHANGED_KEY = 'nextjs-cms-locale-changed';
|
|
10
|
-
const MAX_AGE_YEAR = 60 * 60 * 24 * 365;
|
|
11
|
-
/**
|
|
12
|
-
* Set the login-page locale cookie (client-only).
|
|
13
|
-
* Call when user changes language on the login page; auth layout reads it when no session.
|
|
14
|
-
*/
|
|
15
|
-
export function setLoginPageLocaleCookie(locale) {
|
|
16
|
-
if (typeof document === 'undefined')
|
|
17
|
-
return;
|
|
18
|
-
document.cookie = `${LOCALE_COOKIE_NAME}=${encodeURIComponent(locale)}; path=/; max-age=${MAX_AGE_YEAR}; SameSite=Lax`;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Mark that user explicitly changed locale on login page.
|
|
22
|
-
* Used to determine whether to send locale to server on login.
|
|
23
|
-
*/
|
|
24
|
-
export function markLocaleChangedOnLogin() {
|
|
25
|
-
if (typeof sessionStorage === 'undefined')
|
|
26
|
-
return;
|
|
27
|
-
sessionStorage.setItem(LOCALE_CHANGED_KEY, 'true');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if user explicitly changed locale on login page.
|
|
31
|
-
*/
|
|
32
|
-
export function wasLocaleChangedOnLogin() {
|
|
33
|
-
if (typeof sessionStorage === 'undefined')
|
|
34
|
-
return false;
|
|
35
|
-
return sessionStorage.getItem(LOCALE_CHANGED_KEY) === 'true';
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Clear the locale changed flag after login.
|
|
39
|
-
*/
|
|
40
|
-
export function clearLocaleChangedOnLogin() {
|
|
41
|
-
if (typeof sessionStorage === 'undefined')
|
|
42
|
-
return;
|
|
43
|
-
sessionStorage.removeItem(LOCALE_CHANGED_KEY);
|
|
44
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Locale codes that use RTL layout. Used for `dir` and font selection. */
|
|
2
|
-
export declare const RTL_LOCALES: Set<string>;
|
|
3
|
-
/**
|
|
4
|
-
* Resolve the effective locale from the user's stored locale, supported list, and fallback.
|
|
5
|
-
* Used in layouts to determine `html` lang and `I18nProviderClient` locale.
|
|
6
|
-
*/
|
|
7
|
-
export declare function resolveLocale(userLocale: string | undefined, supported: readonly string[], fallback: string): string;
|
|
8
|
-
//# sourceMappingURL=locale-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-utils.d.ts","sourceRoot":"","sources":["../../src/translations/locale-utils.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,WAAW,aAA0B,CAAA;AAElD;;;GAGG;AACH,wBAAgB,aAAa,CACzB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,QAAQ,EAAE,MAAM,GACjB,MAAM,CAGR"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Locale codes that use RTL layout. Used for `dir` and font selection. */
|
|
2
|
-
export const RTL_LOCALES = new Set(['ar']);
|
|
3
|
-
/**
|
|
4
|
-
* Resolve the effective locale from the user's stored locale, supported list, and fallback.
|
|
5
|
-
* Used in layouts to determine `html` lang and `I18nProviderClient` locale.
|
|
6
|
-
*/
|
|
7
|
-
export function resolveLocale(userLocale, supported, fallback) {
|
|
8
|
-
if (!userLocale)
|
|
9
|
-
return fallback;
|
|
10
|
-
return supported.includes(userLocale) ? userLocale : fallback;
|
|
11
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Localization utilities for resolving localized strings.
|
|
3
|
-
* Supports Payload CMS-style translations where developers can provide
|
|
4
|
-
* translations directly in field labels and section titles.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* A localized string can be either:
|
|
8
|
-
* - A plain string (backward compatible)
|
|
9
|
-
* - An object with language codes as keys and translated strings as values
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Single language (backward compatible)
|
|
14
|
-
* label: 'Title'
|
|
15
|
-
*
|
|
16
|
-
* // Multiple languages
|
|
17
|
-
* label: {
|
|
18
|
-
* en: 'Title',
|
|
19
|
-
* ar: 'العنوان'
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export type LocalizedString = string | Record<string, string>;
|
|
24
|
-
/**
|
|
25
|
-
* Resolve a localized string to a specific locale.
|
|
26
|
-
* If the string is a plain string, it's returned as-is.
|
|
27
|
-
* If it's an object, the value for the given locale is returned.
|
|
28
|
-
* Falls back to the first available language or the fallback locale if the requested locale is not found.
|
|
29
|
-
*
|
|
30
|
-
* @param localized - The localized string (string or object with language codes)
|
|
31
|
-
* @param locale - The target locale code (e.g., 'en', 'ar')
|
|
32
|
-
* @param fallbackLocale - The fallback locale code if the requested locale is not found
|
|
33
|
-
* @returns The resolved string for the given locale
|
|
34
|
-
*/
|
|
35
|
-
export declare function resolveLocalizedString(localized: LocalizedString | undefined, locale: string, fallbackLocale?: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* Check if a value is a localized string object (not a plain string)
|
|
38
|
-
*/
|
|
39
|
-
export declare function isLocalizedObject(value: LocalizedString | undefined): value is Record<string, string>;
|
|
40
|
-
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/translations/localization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,EACd,cAAc,GAAE,MAAa,GAC9B,MAAM,CA8BR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAErG"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Localization utilities for resolving localized strings.
|
|
3
|
-
* Supports Payload CMS-style translations where developers can provide
|
|
4
|
-
* translations directly in field labels and section titles.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Resolve a localized string to a specific locale.
|
|
8
|
-
* If the string is a plain string, it's returned as-is.
|
|
9
|
-
* If it's an object, the value for the given locale is returned.
|
|
10
|
-
* Falls back to the first available language or the fallback locale if the requested locale is not found.
|
|
11
|
-
*
|
|
12
|
-
* @param localized - The localized string (string or object with language codes)
|
|
13
|
-
* @param locale - The target locale code (e.g., 'en', 'ar')
|
|
14
|
-
* @param fallbackLocale - The fallback locale code if the requested locale is not found
|
|
15
|
-
* @returns The resolved string for the given locale
|
|
16
|
-
*/
|
|
17
|
-
export function resolveLocalizedString(localized, locale, fallbackLocale = 'en') {
|
|
18
|
-
if (!localized) {
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
// If it's a plain string, return as-is (backward compatible)
|
|
22
|
-
if (typeof localized === 'string') {
|
|
23
|
-
return localized;
|
|
24
|
-
}
|
|
25
|
-
// If it's an object, resolve based on locale
|
|
26
|
-
if (typeof localized === 'object') {
|
|
27
|
-
// Try the requested locale first
|
|
28
|
-
if (localized[locale]) {
|
|
29
|
-
return localized[locale];
|
|
30
|
-
}
|
|
31
|
-
// Try the fallback locale
|
|
32
|
-
if (localized[fallbackLocale]) {
|
|
33
|
-
return localized[fallbackLocale];
|
|
34
|
-
}
|
|
35
|
-
// Fall back to the first available language
|
|
36
|
-
const firstKey = Object.keys(localized)[0];
|
|
37
|
-
if (firstKey && localized[firstKey]) {
|
|
38
|
-
return localized[firstKey];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Check if a value is a localized string object (not a plain string)
|
|
45
|
-
*/
|
|
46
|
-
export function isLocalizedObject(value) {
|
|
47
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod';
|
|
2
|
-
import type { DateRangeFieldClientConfig } from '../core/fields/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Returns a record of two Zod schemas keyed by startName and endName.
|
|
5
|
-
* Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
|
|
6
|
-
* register both date fields in a single call.
|
|
7
|
-
*/
|
|
8
|
-
export declare const dateRangeFieldSchema: (field: DateRangeFieldClientConfig, language?: string) => {
|
|
9
|
-
[x: string]: z.ZodDate | z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodDate]>>;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=dateRange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dateRange.d.ts","sourceRoot":"","sources":["../../src/validators/dateRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAGzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,0BAA0B,EAAE,iBAAe;;CAStF,CAAA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod';
|
|
2
|
-
import getString from '../translations/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Returns a record of two Zod schemas keyed by startName and endName.
|
|
5
|
-
* Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
|
|
6
|
-
* register both date fields in a single call.
|
|
7
|
-
*/
|
|
8
|
-
export const dateRangeFieldSchema = (field, language = 'en') => {
|
|
9
|
-
const requiredMessage = getString('requiredField', language);
|
|
10
|
-
const base = z.date(requiredMessage);
|
|
11
|
-
const single = field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
|
|
12
|
-
return {
|
|
13
|
-
[field.startName]: single,
|
|
14
|
-
[field.endName]: single,
|
|
15
|
-
};
|
|
16
|
-
};
|