nextjs-cms 0.9.6 → 0.9.7
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 +290 -290
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/lib/serverActions.d.ts +3 -3
- package/dist/api/root.d.ts +6 -6
- package/dist/api/root.d.ts.map +1 -1
- package/dist/api/routers/config.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/cli/lib/db-config.js +10 -10
- package/dist/core/db/table-checker/MysqlTable.js +8 -8
- 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/fields/date-range.d.ts +119 -0
- package/dist/core/fields/date-range.d.ts.map +1 -0
- package/dist/core/fields/date-range.js +182 -0
- package/dist/core/fields/date.d.ts +15 -3
- package/dist/core/fields/date.d.ts.map +1 -1
- package/dist/core/fields/date.js +34 -17
- package/dist/core/fields/dateRange.d.ts +133 -94
- package/dist/core/fields/dateRange.d.ts.map +1 -1
- package/dist/core/fields/dateRange.js +39 -8
- package/dist/core/fields/index.d.ts +3 -3
- package/dist/core/fields/index.d.ts.map +1 -1
- package/dist/core/fields/index.js +1 -1
- package/dist/core/sections/category.d.ts +4 -4
- package/dist/core/sections/hasItems.d.ts +4 -4
- package/dist/core/sections/section.d.ts +3 -3
- package/dist/core/sections/simple.d.ts +4 -4
- package/dist/translations/base/en.d.ts +3 -0
- package/dist/translations/base/en.d.ts.map +1 -1
- package/dist/translations/base/en.js +3 -0
- package/dist/translations/client.d.ts +40 -4
- package/dist/translations/client.d.ts.map +1 -1
- package/dist/translations/server.d.ts +40 -4
- package/dist/translations/server.d.ts.map +1 -1
- package/dist/utils/date-bounds.d.ts +10 -0
- package/dist/utils/date-bounds.d.ts.map +1 -0
- package/dist/utils/date-bounds.js +36 -0
- package/dist/utils/dateBounds.d.ts +10 -0
- package/dist/utils/dateBounds.d.ts.map +1 -0
- package/dist/utils/dateBounds.js +36 -0
- package/dist/validators/date-range.d.ts +11 -0
- package/dist/validators/date-range.d.ts.map +1 -0
- package/dist/validators/date-range.js +38 -0
- package/dist/validators/date.d.ts.map +1 -1
- package/dist/validators/date.js +23 -1
- package/dist/validators/dateRange.d.ts.map +1 -1
- package/dist/validators/dateRange.js +23 -1
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +1 -1
- package/package.json +3 -3
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/translations/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AA2BvD,eAAO,MAAQ,OAAO
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/translations/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AA2BvD,eAAO,MAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAE,eAAe;;GAAuD,CAAA;AAE7G,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAMzG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const dateBoundSchema: z.ZodUnion<readonly [z.ZodDate, z.ZodLiteral<"now">]>;
|
|
3
|
+
export type DateBoundValue = z.infer<typeof dateBoundSchema>;
|
|
4
|
+
export type SerializedDateBoundValue = string | 'now';
|
|
5
|
+
export type DateFieldFormat = 'date' | 'datetime' | 'timestamp';
|
|
6
|
+
export declare function resolveDateBoundValue(value: DateBoundValue | undefined): Date | undefined;
|
|
7
|
+
export declare function resolveSerializedDateBoundValue(value: SerializedDateBoundValue | undefined): Date | undefined;
|
|
8
|
+
export declare function serializeDateBoundValue(value: DateBoundValue | undefined): SerializedDateBoundValue | undefined;
|
|
9
|
+
export declare function formatDateForField(date: Date, format: DateFieldFormat): string;
|
|
10
|
+
//# sourceMappingURL=date-bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-bounds.d.ts","sourceRoot":"","sources":["../../src/utils/date-bounds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,eAAO,MAAM,eAAe,uDAAwC,CAAA;AAEpE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAC5D,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,KAAK,CAAA;AACrD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAA;AAE/D,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAMzF;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,wBAAwB,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAW7G;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,wBAAwB,GAAG,SAAS,CAM/G;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,MAAM,CAU9E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
export const dateBoundSchema = z.union([z.date(), z.literal('now')]);
|
|
4
|
+
export function resolveDateBoundValue(value) {
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return value === 'now' ? new Date() : value;
|
|
9
|
+
}
|
|
10
|
+
export function resolveSerializedDateBoundValue(value) {
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (value === 'now') {
|
|
15
|
+
return new Date();
|
|
16
|
+
}
|
|
17
|
+
const parsedDate = new Date(value);
|
|
18
|
+
return Number.isNaN(parsedDate.getTime()) ? undefined : parsedDate;
|
|
19
|
+
}
|
|
20
|
+
export function serializeDateBoundValue(value) {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return value === 'now' ? 'now' : value.toISOString();
|
|
25
|
+
}
|
|
26
|
+
export function formatDateForField(date, format) {
|
|
27
|
+
switch (format) {
|
|
28
|
+
case 'timestamp':
|
|
29
|
+
return dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
30
|
+
case 'datetime':
|
|
31
|
+
return dayjs(date).format('YYYY-MM-DD HH:mm:ss');
|
|
32
|
+
case 'date':
|
|
33
|
+
default:
|
|
34
|
+
return dayjs(date).format('YYYY-MM-DD');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const dateBoundSchema: z.ZodUnion<readonly [z.ZodDate, z.ZodLiteral<"now">]>;
|
|
3
|
+
export type DateBoundValue = z.infer<typeof dateBoundSchema>;
|
|
4
|
+
export type SerializedDateBoundValue = string | 'now';
|
|
5
|
+
export type DateFieldFormat = 'date' | 'datetime' | 'timestamp';
|
|
6
|
+
export declare function resolveDateBoundValue(value: DateBoundValue | undefined): Date | undefined;
|
|
7
|
+
export declare function resolveSerializedDateBoundValue(value: SerializedDateBoundValue | undefined): Date | undefined;
|
|
8
|
+
export declare function serializeDateBoundValue(value: DateBoundValue | undefined): SerializedDateBoundValue | undefined;
|
|
9
|
+
export declare function formatDateForField(date: Date, format: DateFieldFormat): string;
|
|
10
|
+
//# sourceMappingURL=dateBounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateBounds.d.ts","sourceRoot":"","sources":["../../src/utils/dateBounds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,eAAO,MAAM,eAAe,uDAAwC,CAAA;AAEpE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAC5D,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,KAAK,CAAA;AACrD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAA;AAE/D,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAMzF;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,wBAAwB,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAW7G;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,wBAAwB,GAAG,SAAS,CAM/G;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,MAAM,CAU9E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
export const dateBoundSchema = z.union([z.date(), z.literal('now')]);
|
|
4
|
+
export function resolveDateBoundValue(value) {
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return value === 'now' ? new Date() : value;
|
|
9
|
+
}
|
|
10
|
+
export function resolveSerializedDateBoundValue(value) {
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (value === 'now') {
|
|
15
|
+
return new Date();
|
|
16
|
+
}
|
|
17
|
+
const parsedDate = new Date(value);
|
|
18
|
+
return Number.isNaN(parsedDate.getTime()) ? undefined : parsedDate;
|
|
19
|
+
}
|
|
20
|
+
export function serializeDateBoundValue(value) {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return value === 'now' ? 'now' : value.toISOString();
|
|
25
|
+
}
|
|
26
|
+
export function formatDateForField(date, format) {
|
|
27
|
+
switch (format) {
|
|
28
|
+
case 'timestamp':
|
|
29
|
+
return dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
30
|
+
case 'datetime':
|
|
31
|
+
return dayjs(date).format('YYYY-MM-DD HH:mm:ss');
|
|
32
|
+
case 'date':
|
|
33
|
+
default:
|
|
34
|
+
return dayjs(date).format('YYYY-MM-DD');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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=date-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-range.d.ts","sourceRoot":"","sources":["../../src/validators/date-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAIzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,0BAA0B,EAAE,iBAAe;;CA+BtF,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import getString from '../translations/index.js';
|
|
3
|
+
import { formatDateForField, resolveSerializedDateBoundValue } from '../utils/date-bounds.js';
|
|
4
|
+
/**
|
|
5
|
+
* Returns a record of two Zod schemas keyed by startName and endName.
|
|
6
|
+
* Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
|
|
7
|
+
* register both date fields in a single call.
|
|
8
|
+
*/
|
|
9
|
+
export const dateRangeFieldSchema = (field, language = 'en') => {
|
|
10
|
+
const requiredMessage = getString('requiredField', language);
|
|
11
|
+
const base = z.date(requiredMessage).superRefine((value, ctx) => {
|
|
12
|
+
const minDate = resolveSerializedDateBoundValue(field.minDate);
|
|
13
|
+
if (minDate && value.getTime() < minDate.getTime()) {
|
|
14
|
+
ctx.addIssue({
|
|
15
|
+
code: 'custom',
|
|
16
|
+
message: getString('fieldDateMinValueError', language, {
|
|
17
|
+
field: field.label,
|
|
18
|
+
min: formatDateForField(minDate, field.format),
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const maxDate = resolveSerializedDateBoundValue(field.maxDate);
|
|
23
|
+
if (maxDate && value.getTime() > maxDate.getTime()) {
|
|
24
|
+
ctx.addIssue({
|
|
25
|
+
code: 'custom',
|
|
26
|
+
message: getString('fieldDateMaxValueError', language, {
|
|
27
|
+
field: field.label,
|
|
28
|
+
max: formatDateForField(maxDate, field.format),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const single = field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
|
|
34
|
+
return {
|
|
35
|
+
[field.startName]: single,
|
|
36
|
+
[field.endName]: single,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/validators/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/validators/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAIpE,eAAO,MAAM,eAAe,GAAI,OAAO,qBAAqB,EAAE,iBAAe,kFA2B5E,CAAA"}
|
package/dist/validators/date.js
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import getString from '../translations/index.js';
|
|
3
|
+
import { formatDateForField, resolveSerializedDateBoundValue } from '../utils/date-bounds.js';
|
|
3
4
|
export const dateFieldSchema = (field, language = 'en') => {
|
|
4
5
|
const requiredMessage = getString('requiredField', language);
|
|
5
|
-
const base = z.date(requiredMessage)
|
|
6
|
+
const base = z.date(requiredMessage).superRefine((value, ctx) => {
|
|
7
|
+
const minDate = resolveSerializedDateBoundValue(field.minDate);
|
|
8
|
+
if (minDate && value.getTime() < minDate.getTime()) {
|
|
9
|
+
ctx.addIssue({
|
|
10
|
+
code: 'custom',
|
|
11
|
+
message: getString('fieldDateMinValueError', language, {
|
|
12
|
+
field: field.label,
|
|
13
|
+
min: formatDateForField(minDate, field.format),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const maxDate = resolveSerializedDateBoundValue(field.maxDate);
|
|
18
|
+
if (maxDate && value.getTime() > maxDate.getTime()) {
|
|
19
|
+
ctx.addIssue({
|
|
20
|
+
code: 'custom',
|
|
21
|
+
message: getString('fieldDateMaxValueError', language, {
|
|
22
|
+
field: field.label,
|
|
23
|
+
max: formatDateForField(maxDate, field.format),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
6
28
|
return field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
|
|
7
29
|
};
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAIzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,0BAA0B,EAAE,iBAAe;;CA+BtF,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import getString from '../translations/index.js';
|
|
3
|
+
import { formatDateForField, resolveSerializedDateBoundValue } from '../utils/dateBounds.js';
|
|
3
4
|
/**
|
|
4
5
|
* Returns a record of two Zod schemas keyed by startName and endName.
|
|
5
6
|
* Form.tsx calls `schema.extend(dateRangeFieldSchema(input, language))` to
|
|
@@ -7,7 +8,28 @@ import getString from '../translations/index.js';
|
|
|
7
8
|
*/
|
|
8
9
|
export const dateRangeFieldSchema = (field, language = 'en') => {
|
|
9
10
|
const requiredMessage = getString('requiredField', language);
|
|
10
|
-
const base = z.date(requiredMessage)
|
|
11
|
+
const base = z.date(requiredMessage).superRefine((value, ctx) => {
|
|
12
|
+
const minDate = resolveSerializedDateBoundValue(field.minDate);
|
|
13
|
+
if (minDate && value.getTime() < minDate.getTime()) {
|
|
14
|
+
ctx.addIssue({
|
|
15
|
+
code: 'custom',
|
|
16
|
+
message: getString('fieldDateMinValueError', language, {
|
|
17
|
+
field: field.label,
|
|
18
|
+
min: formatDateForField(minDate, field.format),
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const maxDate = resolveSerializedDateBoundValue(field.maxDate);
|
|
23
|
+
if (maxDate && value.getTime() > maxDate.getTime()) {
|
|
24
|
+
ctx.addIssue({
|
|
25
|
+
code: 'custom',
|
|
26
|
+
message: getString('fieldDateMaxValueError', language, {
|
|
27
|
+
field: field.label,
|
|
28
|
+
max: formatDateForField(maxDate, field.format),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
11
33
|
const single = field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
|
|
12
34
|
return {
|
|
13
35
|
[field.startName]: single,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { checkboxFieldSchema } from './checkbox.js';
|
|
2
2
|
export { colorFieldSchema } from './color.js';
|
|
3
3
|
export * from './date.js';
|
|
4
|
-
export { dateRangeFieldSchema } from './
|
|
4
|
+
export { dateRangeFieldSchema } from './date-range.js';
|
|
5
5
|
export { documentFieldSchema } from './document.js';
|
|
6
6
|
export * from './map.js';
|
|
7
7
|
export * from './number.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/validators/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { checkboxFieldSchema } from './checkbox.js';
|
|
2
2
|
export { colorFieldSchema } from './color.js';
|
|
3
3
|
export * from './date.js';
|
|
4
|
-
export { dateRangeFieldSchema } from './
|
|
4
|
+
export { dateRangeFieldSchema } from './date-range.js';
|
|
5
5
|
export { documentFieldSchema } from './document.js';
|
|
6
6
|
export * from './map.js';
|
|
7
7
|
export * from './number.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -210,8 +210,8 @@
|
|
|
210
210
|
"tsx": "^4.20.6",
|
|
211
211
|
"typescript": "^5.9.2",
|
|
212
212
|
"@lzcms/eslint-config": "0.3.0",
|
|
213
|
-
"@lzcms/
|
|
214
|
-
"@lzcms/
|
|
213
|
+
"@lzcms/tsconfig": "0.1.0",
|
|
214
|
+
"@lzcms/prettier-config": "0.1.0"
|
|
215
215
|
},
|
|
216
216
|
"license": "MIT",
|
|
217
217
|
"keywords": [
|
|
@@ -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
|
-
}
|