@nexload-sdk/payload-fields 3.1.0 → 4.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/README.md +196 -17
- package/dist/address/index.d.ts +13 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/admin/formatted-cell.d.ts +6 -0
- package/dist/admin/formatted-cell.d.ts.map +1 -0
- package/dist/admin/formatted-cell.js +18 -0
- package/dist/admin/formatted-cell.js.map +7 -0
- package/dist/admin/jalali-date-cell.d.ts +3 -3
- package/dist/admin/jalali-date-cell.d.ts.map +1 -1
- package/dist/admin/jalali-date-cell.js +27 -0
- package/dist/admin/jalali-date-cell.js.map +7 -0
- package/dist/admin/jalali-date-field.d.ts +4 -3
- package/dist/admin/jalali-date-field.d.ts.map +1 -1
- package/dist/admin/jalali-date-field.js +250 -0
- package/dist/admin/jalali-date-field.js.map +7 -0
- package/dist/admin/money-cell.d.ts +10 -0
- package/dist/admin/money-cell.d.ts.map +1 -0
- package/dist/admin/money-cell.js +124 -0
- package/dist/admin/money-cell.js.map +7 -0
- package/dist/admin/money-field.d.ts +3 -2
- package/dist/admin/money-field.d.ts.map +1 -1
- package/dist/admin/money-field.js +183 -0
- package/dist/admin/money-field.js.map +7 -0
- package/dist/admin/slug-field.d.ts.map +1 -1
- package/dist/admin/slug-field.js +210 -0
- package/dist/admin/slug-field.js.map +7 -0
- package/dist/admin/validated-text-field.d.ts +6 -0
- package/dist/admin/validated-text-field.d.ts.map +1 -0
- package/dist/admin/validated-text-field.js +35 -0
- package/dist/admin/validated-text-field.js.map +7 -0
- package/dist/bank/index.d.ts +7 -0
- package/dist/bank/index.d.ts.map +1 -0
- package/dist/common/index.d.ts +35 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/contact/index.d.ts +9 -0
- package/dist/contact/index.d.ts.map +1 -0
- package/dist/date/format-date.d.ts.map +1 -1
- package/dist/date/index.d.ts +37 -4
- package/dist/date/index.d.ts.map +1 -1
- package/dist/date/index.js +258 -0
- package/dist/date/index.js.map +7 -0
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.d.ts.map +1 -0
- package/dist/i18n/messages.js +97 -0
- package/dist/i18n/messages.js.map +7 -0
- package/dist/identity/index.d.ts +9 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1038 -0
- package/dist/index.js.map +7 -0
- package/dist/internal/protect.d.ts +7 -0
- package/dist/internal/protect.d.ts.map +1 -0
- package/dist/internal/validated-text.d.ts +24 -0
- package/dist/internal/validated-text.d.ts.map +1 -0
- package/dist/internal/validated-text.js +161 -0
- package/dist/internal/validated-text.js.map +7 -0
- package/dist/money/index.d.ts +6 -0
- package/dist/money/index.d.ts.map +1 -1
- package/dist/money/index.js +212 -0
- package/dist/money/index.js.map +7 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/schema/index.d.ts +51 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +735 -0
- package/dist/schema/index.js.map +7 -0
- package/dist/slug/format-slug.d.ts +1 -1
- package/dist/slug/format-slug.d.ts.map +1 -1
- package/dist/slug/index.d.ts +1 -0
- package/dist/slug/index.d.ts.map +1 -1
- package/dist/slug/{index.mjs → index.js} +47 -43
- package/dist/slug/index.js.map +7 -0
- package/package.json +64 -27
- package/dist/admin/jalali-date-cell.cjs +0 -58
- package/dist/admin/jalali-date-cell.cjs.map +0 -7
- package/dist/admin/jalali-date-cell.mjs +0 -32
- package/dist/admin/jalali-date-cell.mjs.map +0 -7
- package/dist/admin/jalali-date-field.cjs +0 -159
- package/dist/admin/jalali-date-field.cjs.map +0 -7
- package/dist/admin/jalali-date-field.mjs +0 -135
- package/dist/admin/jalali-date-field.mjs.map +0 -7
- package/dist/admin/jalali-picker-value.cjs +0 -42
- package/dist/admin/jalali-picker-value.cjs.map +0 -7
- package/dist/admin/jalali-picker-value.d.ts +0 -3
- package/dist/admin/jalali-picker-value.d.ts.map +0 -1
- package/dist/admin/jalali-picker-value.mjs +0 -18
- package/dist/admin/jalali-picker-value.mjs.map +0 -7
- package/dist/admin/money-field.cjs +0 -146
- package/dist/admin/money-field.cjs.map +0 -7
- package/dist/admin/money-field.mjs +0 -122
- package/dist/admin/money-field.mjs.map +0 -7
- package/dist/admin/slug-field.cjs +0 -135
- package/dist/admin/slug-field.cjs.map +0 -7
- package/dist/admin/slug-field.mjs +0 -115
- package/dist/admin/slug-field.mjs.map +0 -7
- package/dist/date/index.cjs +0 -117
- package/dist/date/index.cjs.map +0 -7
- package/dist/date/index.mjs +0 -86
- package/dist/date/index.mjs.map +0 -7
- package/dist/index.cjs +0 -469
- package/dist/index.cjs.map +0 -7
- package/dist/index.mjs +0 -425
- package/dist/index.mjs.map +0 -7
- package/dist/money/index.cjs +0 -147
- package/dist/money/index.cjs.map +0 -7
- package/dist/money/index.mjs +0 -117
- package/dist/money/index.mjs.map +0 -7
- package/dist/slug/index.cjs +0 -183
- package/dist/slug/index.cjs.map +0 -7
- package/dist/slug/index.mjs.map +0 -7
package/README.md
CHANGED
|
@@ -1,35 +1,214 @@
|
|
|
1
1
|
# @nexload-sdk/payload-fields
|
|
2
2
|
|
|
3
|
-
Semantic Payload CMS factories for
|
|
3
|
+
**Semantic Payload CMS field factories and Admin UI components for Unicode slugs, Jalali dates, integer money, and Iranian identity fields.**
|
|
4
|
+
|
|
5
|
+
[Documentation](https://gecut.github.io/nexload-sdk/packages/payload-fields/) · [API reference](https://gecut.github.io/nexload-sdk/packages/payload-fields/api/)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@nexload-sdk/payload-fields)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
> [!IMPORTANT]
|
|
13
|
+
> Version 4.0.0 is pending in `.changeset/`: the package is now ESM-only targeting Payload `>=3.85.0 <4.0.0` (React 19), slugs are unique by default, validation messages adapt to `fa` vs other locales, and `./schema` adds `@nexload-sdk/payload-schema` integration.
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
|
|
17
|
+
- [Overview](#overview)
|
|
18
|
+
- [Philosophy](#philosophy)
|
|
19
|
+
- [Install](#install)
|
|
20
|
+
- [Quick start](#quick-start)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [API](#api)
|
|
23
|
+
- [Configuration](#configuration)
|
|
24
|
+
- [Runtime and compatibility](#runtime-and-compatibility)
|
|
25
|
+
- [Caveats](#caveats)
|
|
26
|
+
- [Migration](#migration)
|
|
27
|
+
- [Related packages](#related-packages)
|
|
28
|
+
- [License](#license)
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
`@nexload-sdk/payload-fields` provides production-ready Payload CMS field factories, `beforeValidate` normalization hooks, and React 19 Admin UI components tailored for Persian and Iranian applications. It solves percent-encoded Unicode slugs, Gregorian-only admin datepickers, floating-point currency rounding, and repeated validation logic for Iranian mobile numbers, national codes, bank cards, Sheba/IBANs, and addresses. It is for Payload 3 teams building Persian or bilingual admin panels.
|
|
33
|
+
|
|
34
|
+
What it is not:
|
|
35
|
+
|
|
36
|
+
- Not a general schema compiler (pair with `@nexload-sdk/payload-schema` via `./schema` for Zod projection).
|
|
37
|
+
- Not a Lexical editor preset (use `@nexload-sdk/payload-editor`).
|
|
38
|
+
- Not an admin localization or logger preset (use `@nexload-sdk/payload-preset`).
|
|
39
|
+
|
|
40
|
+
## Philosophy
|
|
41
|
+
|
|
42
|
+
- **Canonical storage, localized display:** Slugs, phone numbers, national codes, and money are normalized to clean canonical values on write and formatted for humans in the Admin UI.
|
|
43
|
+
- **Integer-only money:** `moneyField` stores safe integer minor units (`IRR`, `IRT`, or a custom `{ code, label, fractionDigits }` currency definition) to eliminate floating-point drift.
|
|
44
|
+
- **Timezone-stable Jalali dates:** `dayOnly` and `monthOnly` dates store canonical noon (`12:00:00`) in `timeZone` (`Asia/Tehran` by default) so dates do not shift across browser timezones.
|
|
45
|
+
- **Explicit server/client isolation:** Field factories run in Node/Payload config while `"use client"` Admin components live behind `./admin/*` subpaths.
|
|
4
46
|
|
|
5
47
|
## Install
|
|
6
48
|
|
|
7
49
|
```bash
|
|
8
50
|
pnpm add @nexload-sdk/payload-fields
|
|
51
|
+
# or
|
|
52
|
+
npm install @nexload-sdk/payload-fields
|
|
53
|
+
# or
|
|
54
|
+
yarn add @nexload-sdk/payload-fields
|
|
55
|
+
# or
|
|
56
|
+
bun add @nexload-sdk/payload-fields
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For optional `@nexload-sdk/payload-fields/schema` support:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm add @nexload-sdk/payload-schema zod
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Package | Range | Required / Optional |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| `payload` | `>=3.85.0 <4.0.0` | Required |
|
|
68
|
+
| `@payloadcms/ui` | `>=3.85.0 <4.0.0` | Required |
|
|
69
|
+
| `react` | `^19.0.1 \|\| ^19.1.2 \|\| ^19.2.1` | Required |
|
|
70
|
+
| `react-dom` | `^19.0.1 \|\| ^19.1.2 \|\| ^19.2.1` | Required |
|
|
71
|
+
| `@nexload-sdk/payload-schema` | `>=2.0.0 <4.0.0` | Optional (for `./schema`) |
|
|
72
|
+
| `zod` | `>=4.1.0 <5.0.0` | Optional (for `./schema`) |
|
|
73
|
+
|
|
74
|
+
## Quick start
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import {
|
|
78
|
+
iranAddressField,
|
|
79
|
+
iranMobileField,
|
|
80
|
+
jalaliDateField,
|
|
81
|
+
jalaliDateRangeField,
|
|
82
|
+
moneyField,
|
|
83
|
+
nationalCodeField,
|
|
84
|
+
payloadFieldsPlugin,
|
|
85
|
+
slugField,
|
|
86
|
+
} from "@nexload-sdk/payload-fields";
|
|
87
|
+
import type { CollectionConfig } from "payload";
|
|
88
|
+
|
|
89
|
+
export const Customers: CollectionConfig = {
|
|
90
|
+
slug: "customers",
|
|
91
|
+
fields: [
|
|
92
|
+
{ name: "name", type: "text", required: true },
|
|
93
|
+
...slugField({ source: "name" }),
|
|
94
|
+
jalaliDateField({ name: "birthDate", pickerAppearance: "dayOnly" }),
|
|
95
|
+
jalaliDateRangeField({ start: "subscriptionStart", end: "subscriptionEnd" }),
|
|
96
|
+
moneyField({ name: "credit", currency: "IRT", minMinorUnits: 0 }),
|
|
97
|
+
iranMobileField({ name: "mobile", required: true }),
|
|
98
|
+
nationalCodeField({ name: "nationalCode" }),
|
|
99
|
+
iranAddressField({ recipient: false }),
|
|
100
|
+
],
|
|
101
|
+
};
|
|
9
102
|
```
|
|
10
103
|
|
|
104
|
+
Register `payloadFieldsPlugin()` in `payload.config.ts` if clients submit money as formatted strings or use custom slug generators.
|
|
105
|
+
|
|
11
106
|
## Usage
|
|
12
107
|
|
|
108
|
+
### Field catalog
|
|
109
|
+
|
|
110
|
+
| Factory | Stored Type | Canonical Value | Admin Component |
|
|
111
|
+
| --- | --- | --- | --- |
|
|
112
|
+
| `slugField(options)` | `text` + `checkbox` | URL-safe Unicode slug (`"کتاب"`, `"کتاب-2"`) | `SlugFieldComponent` |
|
|
113
|
+
| `jalaliDateField(options)` | `date` | ISO 8601 UTC instant | `JalaliDateFieldComponent` + `JalaliDateCell` |
|
|
114
|
+
| `jalaliDateRangeField(options)` | `row` (`startsAt`, `endsAt`) | Two ISO 8601 instants (`endsAt >= startsAt`) | `JalaliDateFieldComponent` + `JalaliDateCell` |
|
|
115
|
+
| `withJalaliTimestamps(fields, options)` | adds virtual `text` fields | Virtual `createdAtJalali` / `updatedAtJalali` | Standard read-only input |
|
|
116
|
+
| `moneyField(options)` | `number` | Safe integer minor units | `MoneyFieldComponent` + `MoneyCell` |
|
|
117
|
+
| `iranMobileField(options)` | `text` | `09XXXXXXXXX` (default) or `+989XXXXXXXXX` with `storage: "e164"` | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
118
|
+
| `iranLandlineField(options)` | `text` | `0XXXXXXXXXX` | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
119
|
+
| `nationalCodeField(options)` | `text` | 10-digit national code with checksum validation | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
120
|
+
| `legalIdField(options)` | `text` | 11-digit legal entity ID with checksum validation | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
121
|
+
| `postalCodeField(options)` | `text` | 10-digit postal code | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
122
|
+
| `bankCardField(options)` | `text` | 16-digit Luhn-checked card | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
123
|
+
| `shebaField(options)` | `text` | 26-char IBAN (`IR...`) with ISO 7064 validation | `ValidatedTextFieldComponent` + `FormattedCell` |
|
|
124
|
+
| `ltrTextField(options)` | `text` | Raw text with `nexload-ltr` class and optional `monospace` styling | Standard LTR text input |
|
|
125
|
+
| `sortOrderField(options)` | `number` | Non-negative integer (default `0`) | Sidebar number input |
|
|
126
|
+
| `iranAddressField(options)` | `group` | Province, city, line, postalCode, recipient | Native group with 31 provinces |
|
|
127
|
+
|
|
128
|
+
### Schema adapter (`@nexload-sdk/payload-fields/schema`)
|
|
129
|
+
|
|
130
|
+
Use `schemaFields` to define entities with `@nexload-sdk/payload-schema` and derive both Payload fields and Zod schemas:
|
|
131
|
+
|
|
13
132
|
```ts
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
133
|
+
import { defineEntity } from "@nexload-sdk/payload-schema";
|
|
134
|
+
import { schemaFields } from "@nexload-sdk/payload-fields/schema";
|
|
135
|
+
|
|
136
|
+
export const customerEntity = defineEntity({
|
|
137
|
+
name: "Customer",
|
|
138
|
+
fields: {
|
|
139
|
+
mobile: schemaFields.iranMobile(),
|
|
140
|
+
nationalCode: schemaFields.nationalCode(),
|
|
141
|
+
price: schemaFields.money({ currency: "IRT" }),
|
|
142
|
+
birthDate: schemaFields.jalaliDate({ nullable: true }),
|
|
143
|
+
...schemaFields.slug({ source: "name" }),
|
|
144
|
+
},
|
|
145
|
+
});
|
|
22
146
|
```
|
|
23
147
|
|
|
24
|
-
|
|
148
|
+
## API
|
|
149
|
+
|
|
150
|
+
| Subpath | Key exports | Summary |
|
|
151
|
+
| --- | --- | --- |
|
|
152
|
+
| `@nexload-sdk/payload-fields` | All field factories, `withJalaliTimestamps`, `payloadFieldsPlugin`, `PAYLOAD_FIELDS_PLUGIN_ORDER`, `IRR`, `IRT`, `resolveCurrency`, `parseMoneyToMinorUnits`, `formatMoney`, `formatJalaliDate`, `toStoredJalaliInstant`, and option types | Main server/config entry |
|
|
153
|
+
| `@nexload-sdk/payload-fields/slug` | `slugField`, `formatSlug`, `SlugFieldOptions`, `SlugFieldResult` | Standalone slug factory & formatter |
|
|
154
|
+
| `@nexload-sdk/payload-fields/date` | `jalaliDateField`, `jalaliDateRangeField`, `withJalaliTimestamps`, `toStoredJalaliInstant`, `formatJalaliDate` | Standalone Jalali date utilities |
|
|
155
|
+
| `@nexload-sdk/payload-fields/money` | `moneyField`, `IRR`, `IRT`, `resolveCurrency`, `parseMoneyToMinorUnits`, `formatMoney` | Standalone money field & helpers |
|
|
156
|
+
| `@nexload-sdk/payload-fields/schema` | `schemaFields` | `@nexload-sdk/payload-schema` adapter |
|
|
157
|
+
| `@nexload-sdk/payload-fields/admin/slug-field` | `SlugFieldComponent` | Admin slug field UI |
|
|
158
|
+
| `@nexload-sdk/payload-fields/admin/jalali-date-field` | `JalaliDateFieldComponent` | Admin Jalali datepicker UI |
|
|
159
|
+
| `@nexload-sdk/payload-fields/admin/jalali-date-cell` | `JalaliDateCell` | List cell for Jalali dates |
|
|
160
|
+
| `@nexload-sdk/payload-fields/admin/money-field` | `MoneyFieldComponent` | Admin formatted money input |
|
|
161
|
+
| `@nexload-sdk/payload-fields/admin/money-cell` | `MoneyCell` | List cell for money values |
|
|
162
|
+
| `@nexload-sdk/payload-fields/admin/validated-text-field` | `ValidatedTextFieldComponent` | Admin input for Iranian text fields |
|
|
163
|
+
| `@nexload-sdk/payload-fields/admin/formatted-cell` | `FormattedCell` | List cell for Iranian text fields |
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
`payloadFieldsPlugin(options)` accepts:
|
|
168
|
+
|
|
169
|
+
| Option | Type | Default | Description |
|
|
170
|
+
| --- | --- | --- | --- |
|
|
171
|
+
| `slugGenerators` | `Record<string, SlugGenerator>` | `undefined` | Named async slug generators invoked by the plugin's slug endpoint |
|
|
172
|
+
| `generateSlugAccess` | `SlugGenerationAccess` | `undefined` | Access predicate `{ req } => boolean \| Promise<boolean>` for slug generation |
|
|
173
|
+
|
|
174
|
+
The plugin sets `slug: "nexload-fields"` and `order: 900` (`PAYLOAD_FIELDS_PLUGIN_ORDER`).
|
|
175
|
+
|
|
176
|
+
## Runtime and compatibility
|
|
177
|
+
|
|
178
|
+
- **Module format:** ESM-only (`type: "module"`).
|
|
179
|
+
- **Runtime:** Field factories and `payloadFieldsPlugin` run in Node.js / Payload config. Admin components under `./admin/*` are React 19 `"use client"` components.
|
|
180
|
+
- **Payload version:** `payload` and `@payloadcms/ui` `>=3.85.0 <4.0.0` with React 19.
|
|
181
|
+
- **Bilingual validation:** Errors follow `req.i18n.language` / `useTranslation()` (`fa*` receives Persian; all other locales receive English).
|
|
182
|
+
|
|
183
|
+
## Caveats
|
|
184
|
+
|
|
185
|
+
> [!CAUTION]
|
|
186
|
+
> `payloadFieldsPlugin()` is **required** when money values are submitted via REST or Local API as strings (such as `"۱۲۳٬۴۵۶"` or `"123456"`). Payload core runs `parseFloat()` on number fields before field hooks run, which strips or corrupts Persian digits and separators; the plugin's `beforeOperation` hook normalizes strings to safe integers first. Plain numeric values work without the plugin. The hook is registered on collections and globals and normalizes money fields in blocks referenced by slug from `config.blocks`.
|
|
187
|
+
|
|
188
|
+
> [!WARNING]
|
|
189
|
+
> `slugField` is unique by default (`unique: true`), but automatic collision suffixing (`-2`, `-3`) only runs for top-level slug fields. For slugs nested inside arrays, groups, or named tabs, pass `unique: false` (otherwise database unique errors apply instead of suffixes).
|
|
190
|
+
|
|
191
|
+
> [!NOTE]
|
|
192
|
+
> `iranAddressField` and `jalaliDateRangeField` are not included in `@nexload-sdk/payload-fields/schema` in 4.0. Also, the plugin only sees collections and globals that exist when it runs. If another plugin with `order >= 900` adds money fields, place it before `payloadFieldsPlugin()` when it uses order 900, or give it an order below 900.
|
|
193
|
+
|
|
194
|
+
## Migration
|
|
195
|
+
|
|
196
|
+
### From 3.x to 4.0
|
|
197
|
+
|
|
198
|
+
1. **ESM-only & Payload 3.85+:** Package is strictly ESM-only and requires `payload` / `@payloadcms/ui` `>=3.85.0 <4.0.0` and React 19.
|
|
199
|
+
2. **Monorepo path:** Moved from `packages/refactoring/payload-fields` to `packages/payload-fields`.
|
|
200
|
+
3. **Unique slugs:** Resolve existing duplicate top-level slugs in your database before migrating, or pass `unique: false`.
|
|
201
|
+
4. **Jalali storage:** `dayOnly` and `monthOnly` dates store canonical noon in `timeZone` (`Asia/Tehran` by default).
|
|
202
|
+
5. **Bilingual messages:** Non-`fa` admin locales now receive English validation messages instead of Persian.
|
|
203
|
+
6. **Money strings:** Add `payloadFieldsPlugin()` if clients send money as strings.
|
|
204
|
+
7. **Import map:** Run `pnpm payload generate:importmap` after upgrading to refresh Admin component paths.
|
|
25
205
|
|
|
26
|
-
|
|
206
|
+
## Related packages
|
|
27
207
|
|
|
28
|
-
|
|
208
|
+
- [persian](../persian/README.md) — Core Persian/Iranian normalization and validation primitives
|
|
209
|
+
- [payload-schema](../payload-schema/README.md) — Canonical entity definitions used by `./schema`
|
|
210
|
+
- [payload-preset](../payload-preset/README.md) — Composed preset that includes `payloadFieldsPlugin()`
|
|
29
211
|
|
|
30
|
-
|
|
31
|
-
- Replace `slugField("title")` with `slugField({ source: "title" })`.
|
|
32
|
-
- Replace `...dateField()` with `jalaliDateField({ name: "date" })`.
|
|
33
|
-
- Replace decimal price storage with `moneyField`; API values are minor-unit integers.
|
|
212
|
+
## License
|
|
34
213
|
|
|
35
|
-
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GroupField } from "payload";
|
|
2
|
+
export type IranAddressFieldOptions = {
|
|
3
|
+
name?: string;
|
|
4
|
+
label?: {
|
|
5
|
+
fa: string;
|
|
6
|
+
en: string;
|
|
7
|
+
};
|
|
8
|
+
required?: boolean;
|
|
9
|
+
recipient?: boolean;
|
|
10
|
+
overrides?: Partial<GroupField>;
|
|
11
|
+
};
|
|
12
|
+
export declare function iranAddressField(options?: IranAddressFieldOptions): GroupField;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/address/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,UAAU,EAAmD,MAAM,SAAS,CAAC;AAQlG,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,gBAAgB,CAAE,OAAO,GAAE,uBAA4B,GAAG,UAAU,CA0EnF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DefaultCellComponentProps } from "payload";
|
|
2
|
+
import type { ValidatedTextKind } from "../internal/validated-text";
|
|
3
|
+
export declare const FormattedCell: ({ kind, ...props }: DefaultCellComponentProps & {
|
|
4
|
+
kind: ValidatedTextKind;
|
|
5
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=formatted-cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatted-cell.d.ts","sourceRoot":"","sources":["../../src/admin/formatted-cell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAOzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,eAAO,MAAM,aAAa,GAAI,oBAAoB,yBAAyB,GAAG;IAAE,IAAI,EAAE,iBAAiB,CAAA;CAAE,4CAMxG,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v4.0.0 (build 2026-11-25T11:31:43.661Z)
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/admin/formatted-cell.tsx
|
|
5
|
+
import { DefaultCell } from "@payloadcms/ui";
|
|
6
|
+
import { formatCardNumber, formatSheba } from "@nexload-sdk/persian/bank";
|
|
7
|
+
import { formatIranMobile } from "@nexload-sdk/persian/mobile";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var FormattedCell = ({ kind, ...props }) => {
|
|
10
|
+
const { cellData } = props;
|
|
11
|
+
const value = cellData === null || cellData === void 0 || cellData === "" ? "" : String(cellData);
|
|
12
|
+
const formatted = !value ? "\u2014" : kind === "mobile" ? formatIranMobile(value) : kind === "card" ? formatCardNumber(value) : kind === "sheba" ? formatSheba(value) : value;
|
|
13
|
+
return /* @__PURE__ */ jsx(DefaultCell, { ...props, cellData: formatted ?? value });
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
FormattedCell
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=formatted-cell.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/admin/formatted-cell.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { DefaultCellComponentProps } from \"payload\";\n\nimport { DefaultCell } from \"@payloadcms/ui\";\n\nimport { formatCardNumber, formatSheba } from \"@nexload-sdk/persian/bank\";\nimport { formatIranMobile } from \"@nexload-sdk/persian/mobile\";\n\nimport type { ValidatedTextKind } from \"../internal/validated-text\";\n\nexport const FormattedCell = ({ kind, ...props }: DefaultCellComponentProps & { kind: ValidatedTextKind }) => {\n const { cellData, } = props;\n const value = cellData === null || cellData === undefined || cellData === \"\" ? \"\" : String(cellData);\n const formatted = !value ? \"\u2014\" : kind === \"mobile\" ? formatIranMobile(value) : kind === \"card\" ? formatCardNumber(value) : kind === \"sheba\" ? formatSheba(value) : value;\n\n return <DefaultCell {...props} cellData={formatted ?? value} />;\n};\n"],
|
|
5
|
+
"mappings": ";;;;AAIA,SAAS,mBAAmB;AAE5B,SAAS,kBAAkB,mBAAmB;AAC9C,SAAS,wBAAwB;AASxB;AALF,IAAM,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,MAA+D;AAC5G,QAAM,EAAE,SAAU,IAAI;AACtB,QAAM,QAAQ,aAAa,QAAQ,aAAa,UAAa,aAAa,KAAK,KAAK,OAAO,QAAQ;AACnG,QAAM,YAAY,CAAC,QAAQ,WAAM,SAAS,WAAW,iBAAiB,KAAK,IAAI,SAAS,SAAS,iBAAiB,KAAK,IAAI,SAAS,UAAU,YAAY,KAAK,IAAI;AAEnK,SAAO,oBAAC,eAAa,GAAG,OAAO,UAAU,aAAa,OAAO;AAC/D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
export declare const JalaliDateCell: ({
|
|
1
|
+
import type { DateFieldClient, DefaultCellComponentProps } from "payload";
|
|
2
|
+
import { type JalaliDateDisplayOptions, type JalaliDateValue } from "../date/format-date";
|
|
3
|
+
export declare const JalaliDateCell: ({ display, ...props }: DefaultCellComponentProps<DateFieldClient, JalaliDateValue> & {
|
|
4
4
|
display?: JalaliDateDisplayOptions;
|
|
5
5
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
//# sourceMappingURL=jalali-date-cell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jalali-date-cell.d.ts","sourceRoot":"","sources":["../../src/admin/jalali-date-cell.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"jalali-date-cell.d.ts","sourceRoot":"","sources":["../../src/admin/jalali-date-cell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAI1E,OAAO,EAAoB,KAAK,wBAAwB,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE5G,eAAO,MAAM,cAAc,GAAI,uBAG5B,yBAAyB,CAAC,eAAe,EAAE,eAAe,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,wBAAwB,CAAA;CAAE,4CAEtG,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v4.0.0 (build 2026-11-25T11:31:43.661Z)
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/admin/jalali-date-cell.tsx
|
|
5
|
+
import { DefaultCell } from "@payloadcms/ui";
|
|
6
|
+
|
|
7
|
+
// src/date/format-date.ts
|
|
8
|
+
import { formatJalali, TEHRAN_TIME_ZONE } from "@nexload-sdk/persian/date";
|
|
9
|
+
function formatJalaliDate(value, options = {}) {
|
|
10
|
+
return formatJalali(value, {
|
|
11
|
+
format: options.dateStyle === "short" ? "short" : options.dateStyle === "long" || options.dateStyle === "full" ? "long" : "medium",
|
|
12
|
+
time: options.timeStyle,
|
|
13
|
+
digits: options.digits,
|
|
14
|
+
timeZone: options.timeZone ?? TEHRAN_TIME_ZONE
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/admin/jalali-date-cell.tsx
|
|
19
|
+
import { jsx } from "react/jsx-runtime";
|
|
20
|
+
var JalaliDateCell = ({
|
|
21
|
+
display,
|
|
22
|
+
...props
|
|
23
|
+
}) => /* @__PURE__ */ jsx(DefaultCell, { ...props, cellData: formatJalaliDate(props.cellData, display) ?? "\u2014" });
|
|
24
|
+
export {
|
|
25
|
+
JalaliDateCell
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=jalali-date-cell.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/admin/jalali-date-cell.tsx", "../../src/date/format-date.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { DateFieldClient, DefaultCellComponentProps } from \"payload\";\n\nimport { DefaultCell } from \"@payloadcms/ui\";\n\nimport { formatJalaliDate, type JalaliDateDisplayOptions, type JalaliDateValue } from \"../date/format-date\";\n\nexport const JalaliDateCell = ({\n display,\n ...props\n}: DefaultCellComponentProps<DateFieldClient, JalaliDateValue> & { display?: JalaliDateDisplayOptions }) => (\n <DefaultCell {...props} cellData={formatJalaliDate(props.cellData, display) ?? \"\u2014\"} />\n);\n", "import { formatJalali, TEHRAN_TIME_ZONE } from \"@nexload-sdk/persian/date\";\n\nexport type JalaliDateValue = Date | string | number | null | undefined;\nexport type JalaliDateDisplayOptions = {\n dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\"\n timeStyle?: \"short\" | \"medium\"\n digits?: \"persian\" | \"latin\"\n timeZone?: string\n};\n\nexport function formatJalaliDate (\n value: JalaliDateValue, options: JalaliDateDisplayOptions = {}\n): string | null {\n return formatJalali(value, {\n format: options.dateStyle === \"short\" ? \"short\" : options.dateStyle === \"long\" || options.dateStyle === \"full\" ? \"long\" : \"medium\",\n time: options.timeStyle,\n digits: options.digits,\n timeZone: options.timeZone ?? TEHRAN_TIME_ZONE,\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAIA,SAAS,mBAAmB;;;ACJ5B,SAAS,cAAc,wBAAwB;AAUxC,SAAS,iBACd,OAAwB,UAAoC,CAAC,GAC9C;AACf,SAAO,aAAa,OAAO;AAAA,IACzB,QAAQ,QAAQ,cAAc,UAAU,UAAU,QAAQ,cAAc,UAAU,QAAQ,cAAc,SAAS,SAAS;AAAA,IAC1H,MAAM,QAAQ;AAAA,IACd,QAAQ,QAAQ;AAAA,IAChB,UAAU,QAAQ,YAAY;AAAA,EAChC,CAAC;AACH;;;ADPE;AAJK,IAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA,GAAG;AACL,MACE,oBAAC,eAAa,GAAG,OAAO,UAAU,iBAAiB,MAAM,UAAU,OAAO,KAAK,UAAK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import type { DateFieldClientProps } from "payload";
|
|
1
2
|
import "react-day-picker/style.css";
|
|
2
|
-
import { type JalaliDateDisplayOptions } from "../date/format-date";
|
|
3
3
|
import type { JalaliPickerAppearance } from "../date/picker-types";
|
|
4
|
-
import type
|
|
4
|
+
import { type JalaliDateDisplayOptions } from "../date/format-date";
|
|
5
5
|
type Props = {
|
|
6
6
|
appearance: JalaliPickerAppearance;
|
|
7
7
|
display: JalaliDateDisplayOptions;
|
|
8
|
+
timeZone?: string;
|
|
8
9
|
};
|
|
9
|
-
export declare const JalaliDateFieldComponent: ({ field, path, appearance, display, readOnly, }: DateFieldClientProps & Props) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const JalaliDateFieldComponent: ({ field, path: providedPath, appearance, display, timeZone, readOnly, }: DateFieldClientProps & Props) => import("react/jsx-runtime").JSX.Element;
|
|
10
11
|
export {};
|
|
11
12
|
//# sourceMappingURL=jalali-date-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jalali-date-field.d.ts","sourceRoot":"","sources":["../../src/admin/jalali-date-field.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jalali-date-field.d.ts","sourceRoot":"","sources":["../../src/admin/jalali-date-field.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAUpD,OAAO,4BAA4B,CAAC;AAYpC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAoB,KAAK,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAItF,KAAK,KAAK,GAAG;IACX,UAAU,EAAE,sBAAsB,CAAA;IAClC,OAAO,EAAE,wBAAwB,CAAA;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAC;AA0BF,eAAO,MAAM,wBAAwB,GAAI,yEAEtC,oBAAoB,GAAG,KAAK,4CAiG9B,CAAC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v4.0.0 (build 2026-11-25T11:31:43.661Z)
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/admin/jalali-date-field.tsx
|
|
5
|
+
import {
|
|
6
|
+
FieldDescription,
|
|
7
|
+
FieldError,
|
|
8
|
+
FieldLabel,
|
|
9
|
+
useField,
|
|
10
|
+
useTranslation
|
|
11
|
+
} from "@payloadcms/ui";
|
|
12
|
+
import { useCallback, useState } from "react";
|
|
13
|
+
import "react-day-picker/style.css";
|
|
14
|
+
import { DayPicker, enUS, faIR } from "react-day-picker/persian";
|
|
15
|
+
import {
|
|
16
|
+
formatJalaliPattern,
|
|
17
|
+
gregorianToJalali,
|
|
18
|
+
jalaliToGregorian,
|
|
19
|
+
parseJalaliDate as parseJalaliDate2,
|
|
20
|
+
TEHRAN_TIME_ZONE as TEHRAN_TIME_ZONE3,
|
|
21
|
+
toJalali
|
|
22
|
+
} from "@nexload-sdk/persian/date";
|
|
23
|
+
|
|
24
|
+
// src/date/format-date.ts
|
|
25
|
+
import { formatJalali, TEHRAN_TIME_ZONE } from "@nexload-sdk/persian/date";
|
|
26
|
+
function formatJalaliDate(value, options = {}) {
|
|
27
|
+
return formatJalali(value, {
|
|
28
|
+
format: options.dateStyle === "short" ? "short" : options.dateStyle === "long" || options.dateStyle === "full" ? "long" : "medium",
|
|
29
|
+
time: options.timeStyle,
|
|
30
|
+
digits: options.digits,
|
|
31
|
+
timeZone: options.timeZone ?? TEHRAN_TIME_ZONE
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/date/index.ts
|
|
36
|
+
import { fromJalali, parseJalaliDate, TEHRAN_TIME_ZONE as TEHRAN_TIME_ZONE2, toValidDate } from "@nexload-sdk/persian/date";
|
|
37
|
+
import { toEnglishDigits } from "@nexload-sdk/persian/digits";
|
|
38
|
+
|
|
39
|
+
// src/i18n/messages.ts
|
|
40
|
+
import { CARD_ERROR_MESSAGES_FA, SHEBA_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/bank";
|
|
41
|
+
import { LANDLINE_ERROR_MESSAGES_FA, LEGAL_ID_ERROR_MESSAGES_FA, NATIONAL_CODE_ERROR_MESSAGES_FA, POSTAL_CODE_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/identity";
|
|
42
|
+
import { MOBILE_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/mobile";
|
|
43
|
+
var messages = {
|
|
44
|
+
fa: {
|
|
45
|
+
invalid: "\u0645\u0642\u062F\u0627\u0631 \u0648\u0627\u0631\u062F \u0634\u062F\u0647 \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
|
|
46
|
+
required: "\u0627\u06CC\u0646 \u0641\u06CC\u0644\u062F \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.",
|
|
47
|
+
"mobile.invalid": MOBILE_ERROR_MESSAGES_FA.invalid,
|
|
48
|
+
"landline.invalid": LANDLINE_ERROR_MESSAGES_FA.invalid,
|
|
49
|
+
"nationalCode.invalid_format": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_format,
|
|
50
|
+
"nationalCode.repeated_digits": NATIONAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
|
|
51
|
+
"nationalCode.invalid_checksum": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_checksum,
|
|
52
|
+
"legalId.invalid_format": LEGAL_ID_ERROR_MESSAGES_FA.invalid_format,
|
|
53
|
+
"legalId.invalid_checksum": LEGAL_ID_ERROR_MESSAGES_FA.invalid_checksum,
|
|
54
|
+
"postalCode.invalid_format": POSTAL_CODE_ERROR_MESSAGES_FA.invalid_format,
|
|
55
|
+
"postalCode.repeated_digits": POSTAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
|
|
56
|
+
"card.invalid_format": CARD_ERROR_MESSAGES_FA.invalid_format,
|
|
57
|
+
"card.invalid_checksum": CARD_ERROR_MESSAGES_FA.invalid_checksum,
|
|
58
|
+
"sheba.invalid_format": SHEBA_ERROR_MESSAGES_FA.invalid_format,
|
|
59
|
+
"sheba.invalid_checksum": SHEBA_ERROR_MESSAGES_FA.invalid_checksum,
|
|
60
|
+
"money.integer": "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u06CC\u06A9 \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F.",
|
|
61
|
+
"money.negative": "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.",
|
|
62
|
+
"money.min": "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
63
|
+
"money.max": "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
64
|
+
"date.invalid": "\u062A\u0627\u0631\u06CC\u062E \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
|
|
65
|
+
"date.min": "\u062A\u0627\u0631\u06CC\u062E \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
66
|
+
"date.max": "\u062A\u0627\u0631\u06CC\u062E \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
67
|
+
"dateRange.order": "\u062A\u0627\u0631\u06CC\u062E \u067E\u0627\u06CC\u0627\u0646 \u0646\u0628\u0627\u06CC\u062F \u0642\u0628\u0644 \u0627\u0632 \u062A\u0627\u0631\u06CC\u062E \u0634\u0631\u0648\u0639 \u0628\u0627\u0634\u062F.",
|
|
68
|
+
"dateRange.start": "\u062A\u0627\u0631\u06CC\u062E \u0634\u0631\u0648\u0639",
|
|
69
|
+
"dateRange.end": "\u062A\u0627\u0631\u06CC\u062E \u067E\u0627\u06CC\u0627\u0646",
|
|
70
|
+
"slug.taken": "\u0627\u06CC\u0646 \u0627\u0633\u0644\u0627\u06AF \u0642\u0628\u0644\u0627\u064B \u0627\u0633\u062A\u0641\u0627\u062F\u0647 \u0634\u062F\u0647 \u0627\u0633\u062A.",
|
|
71
|
+
"slug.unauthenticated": "\u0628\u0631\u0627\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627\u06CC\u062F \u0648\u0627\u0631\u062F \u0634\u0648\u06CC\u062F.",
|
|
72
|
+
"slug.forbidden": "\u0627\u062C\u0627\u0632\u0647 \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0631\u0627 \u0646\u062F\u0627\u0631\u06CC\u062F.",
|
|
73
|
+
"slug.invalidInput": "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
|
|
74
|
+
"slug.notFound": "\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.",
|
|
75
|
+
"slug.failed": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.",
|
|
76
|
+
"sortOrder.integer": "\u062A\u0631\u062A\u06CC\u0628 \u0628\u0627\u06CC\u062F \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0628\u0627\u0634\u062F.",
|
|
77
|
+
"ui.clear": "\u067E\u0627\u06A9 \u06A9\u0631\u062F\u0646",
|
|
78
|
+
"ui.generateSlug": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF",
|
|
79
|
+
"ui.lock": "\u0642\u0641\u0644",
|
|
80
|
+
"ui.edit": "\u0648\u06CC\u0631\u0627\u06CC\u0634"
|
|
81
|
+
},
|
|
82
|
+
en: {
|
|
83
|
+
invalid: "Invalid value.",
|
|
84
|
+
required: "This field is required.",
|
|
85
|
+
"mobile.invalid": "Invalid mobile number.",
|
|
86
|
+
"landline.invalid": "Invalid phone number.",
|
|
87
|
+
"nationalCode.invalid_format": "Invalid national code.",
|
|
88
|
+
"nationalCode.repeated_digits": "Invalid national code.",
|
|
89
|
+
"nationalCode.invalid_checksum": "Invalid national code.",
|
|
90
|
+
"legalId.invalid_format": "Invalid legal ID.",
|
|
91
|
+
"legalId.invalid_checksum": "Invalid legal ID.",
|
|
92
|
+
"postalCode.invalid_format": "Invalid postal code.",
|
|
93
|
+
"postalCode.repeated_digits": "Invalid postal code.",
|
|
94
|
+
"card.invalid_format": "Invalid card number.",
|
|
95
|
+
"card.invalid_checksum": "Invalid card number.",
|
|
96
|
+
"sheba.invalid_format": "Invalid Sheba.",
|
|
97
|
+
"sheba.invalid_checksum": "Invalid Sheba.",
|
|
98
|
+
"money.integer": "Amount must be an integer.",
|
|
99
|
+
"money.negative": "Negative amounts are not allowed.",
|
|
100
|
+
"money.min": "Amount is below the minimum.",
|
|
101
|
+
"money.max": "Amount exceeds the maximum.",
|
|
102
|
+
"date.invalid": "Invalid date.",
|
|
103
|
+
"date.min": "Date is before the minimum.",
|
|
104
|
+
"date.max": "Date exceeds the maximum.",
|
|
105
|
+
"dateRange.order": "End date must be on or after the start date.",
|
|
106
|
+
"dateRange.start": "Start date",
|
|
107
|
+
"dateRange.end": "End date",
|
|
108
|
+
"slug.taken": "This slug is already taken.",
|
|
109
|
+
"slug.unauthenticated": "Sign in to generate a slug.",
|
|
110
|
+
"slug.forbidden": "You cannot generate a slug.",
|
|
111
|
+
"slug.invalidInput": "Invalid slug input.",
|
|
112
|
+
"slug.notFound": "Slug generator not found.",
|
|
113
|
+
"slug.failed": "Slug generation failed.",
|
|
114
|
+
"sortOrder.integer": "Order must be an integer.",
|
|
115
|
+
"ui.clear": "Clear",
|
|
116
|
+
"ui.generateSlug": "Generate slug",
|
|
117
|
+
"ui.lock": "Lock",
|
|
118
|
+
"ui.edit": "Edit"
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function resolveLanguage(language) {
|
|
122
|
+
return language?.startsWith("fa") ? "fa" : "en";
|
|
123
|
+
}
|
|
124
|
+
function t(language, key) {
|
|
125
|
+
const dictionary = messages[resolveLanguage(language)];
|
|
126
|
+
return Object.hasOwn(dictionary, key) ? dictionary[key] : dictionary.invalid;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/date/index.ts
|
|
130
|
+
function toStoredJalaliInstant(picked, appearance, timeZone = TEHRAN_TIME_ZONE2) {
|
|
131
|
+
const dateOnly = appearance === "dayOnly" || appearance === "monthOnly";
|
|
132
|
+
return fromJalali({
|
|
133
|
+
year: picked.year,
|
|
134
|
+
month: picked.month,
|
|
135
|
+
day: appearance === "monthOnly" ? 1 : picked.day,
|
|
136
|
+
hour: dateOnly ? 12 : picked.hour ?? 0,
|
|
137
|
+
minute: dateOnly ? 0 : picked.minute ?? 0
|
|
138
|
+
}, { timeZone }).toISOString();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/admin/jalali-date-field.tsx
|
|
142
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
143
|
+
function parseInput(text, appearance, timeZone, currentDay) {
|
|
144
|
+
const [dayText, timeText, extra] = text.trim().split(/\s+/);
|
|
145
|
+
const day = appearance === "timeOnly" ? currentDay : dayText;
|
|
146
|
+
const time = appearance === "timeOnly" ? dayText : timeText;
|
|
147
|
+
if (extra || !day || appearance === "timeOnly" && timeText) return null;
|
|
148
|
+
const hasTime = appearance === "dayAndTime" || appearance === "timeOnly";
|
|
149
|
+
if (hasTime !== Boolean(time)) return null;
|
|
150
|
+
const parsed = parseJalaliDate2(day, { timeZone: appearance === "monthOnly" ? "UTC" : timeZone, time });
|
|
151
|
+
if (!parsed) return null;
|
|
152
|
+
return appearance === "monthOnly" ? toStoredJalaliInstant(toJalali(parsed, { timeZone: "UTC" }), appearance, timeZone) : parsed.toISOString();
|
|
153
|
+
}
|
|
154
|
+
var JalaliDateFieldComponent = ({
|
|
155
|
+
field,
|
|
156
|
+
path: providedPath,
|
|
157
|
+
appearance,
|
|
158
|
+
display,
|
|
159
|
+
timeZone = display.timeZone ?? TEHRAN_TIME_ZONE3,
|
|
160
|
+
readOnly
|
|
161
|
+
}) => {
|
|
162
|
+
const { i18n } = useTranslation();
|
|
163
|
+
const lang = resolveLanguage(i18n.language);
|
|
164
|
+
const invalidMessage = t(lang, "date.invalid");
|
|
165
|
+
const [draft, setDraft] = useState(null);
|
|
166
|
+
const validate = useCallback(
|
|
167
|
+
(currentValue) => draft?.invalid && draft.value === currentValue ? invalidMessage : true,
|
|
168
|
+
[draft, invalidMessage]
|
|
169
|
+
);
|
|
170
|
+
const { value, setValue, path, showError, errorMessage, disabled } = useField({
|
|
171
|
+
potentiallyStalePath: providedPath,
|
|
172
|
+
validate
|
|
173
|
+
});
|
|
174
|
+
const locked = readOnly || disabled;
|
|
175
|
+
const dateFormat = "yyyy/MM/dd";
|
|
176
|
+
const timeFormat = "HH:mm";
|
|
177
|
+
const pattern = appearance === "timeOnly" ? timeFormat : appearance === "dayAndTime" ? `${dateFormat} ${timeFormat}` : dateFormat;
|
|
178
|
+
const dateText = formatJalaliPattern(value, dateFormat, { timeZone });
|
|
179
|
+
const parts = value && dateText ? toJalali(value, { timeZone }) : void 0;
|
|
180
|
+
const gregorian = parts ? jalaliToGregorian(parts.year, parts.month, parts.day) : void 0;
|
|
181
|
+
const selected = gregorian ? new Date(gregorian.year, gregorian.month - 1, gregorian.day, 12) : void 0;
|
|
182
|
+
const activeDraft = draft?.value === value ? draft : null;
|
|
183
|
+
const invalid = !locked && activeDraft?.invalid;
|
|
184
|
+
const text = readOnly ? formatJalaliDate(value, display) ?? "" : activeDraft?.text ?? formatJalaliPattern(value, pattern, { timeZone, digits: display.digits }) ?? "";
|
|
185
|
+
const inputId = `field-${path.replace(/\./g, "__")}`;
|
|
186
|
+
const errorId = `${inputId}-invalid`;
|
|
187
|
+
const chooseDay = (date) => {
|
|
188
|
+
setDraft(null);
|
|
189
|
+
if (!date) {
|
|
190
|
+
setValue(null);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const picked = gregorianToJalali(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
194
|
+
setValue(toStoredJalaliInstant({ ...picked, hour: parts?.hour, minute: parts?.minute }, appearance, timeZone));
|
|
195
|
+
};
|
|
196
|
+
return /* @__PURE__ */ jsxs("div", { className: `field-type jalali-date-field${showError || invalid ? " error" : ""}`, children: [
|
|
197
|
+
/* @__PURE__ */ jsx(FieldLabel, { htmlFor: inputId, label: field.label, localized: field.localized, path, required: field.required }),
|
|
198
|
+
/* @__PURE__ */ jsx(FieldError, { message: errorMessage, path, showError }),
|
|
199
|
+
/* @__PURE__ */ jsx(
|
|
200
|
+
"input",
|
|
201
|
+
{
|
|
202
|
+
"aria-describedby": invalid ? errorId : void 0,
|
|
203
|
+
"aria-invalid": Boolean(invalid || showError),
|
|
204
|
+
dir: "ltr",
|
|
205
|
+
id: inputId,
|
|
206
|
+
onBlur: () => {
|
|
207
|
+
if (!activeDraft?.invalid) setDraft(null);
|
|
208
|
+
},
|
|
209
|
+
onChange: (event) => {
|
|
210
|
+
const input = event.target.value;
|
|
211
|
+
if (!input.trim()) {
|
|
212
|
+
setDraft(null);
|
|
213
|
+
setValue(null);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const currentDay = appearance === "timeOnly" ? dateText ?? formatJalaliPattern(/* @__PURE__ */ new Date(), dateFormat, { timeZone }) : null;
|
|
217
|
+
const instant = parseInput(input, appearance, timeZone, currentDay);
|
|
218
|
+
setDraft({ text: input, value: instant ?? value, invalid: instant === null });
|
|
219
|
+
if (instant !== null || !activeDraft?.invalid) setValue(instant ?? value);
|
|
220
|
+
},
|
|
221
|
+
placeholder: pattern,
|
|
222
|
+
readOnly: locked,
|
|
223
|
+
type: "text",
|
|
224
|
+
value: text
|
|
225
|
+
}
|
|
226
|
+
),
|
|
227
|
+
invalid && /* @__PURE__ */ jsx("p", { id: errorId, role: "alert", children: invalidMessage }),
|
|
228
|
+
/* @__PURE__ */ jsx(FieldDescription, { description: field.admin?.description, path }),
|
|
229
|
+
appearance !== "timeOnly" && /* @__PURE__ */ jsx(
|
|
230
|
+
DayPicker,
|
|
231
|
+
{
|
|
232
|
+
captionLayout: "dropdown",
|
|
233
|
+
defaultMonth: selected,
|
|
234
|
+
dir: lang === "fa" ? "rtl" : "ltr",
|
|
235
|
+
disabled: locked,
|
|
236
|
+
locale: lang === "fa" ? faIR : enUS,
|
|
237
|
+
mode: "single",
|
|
238
|
+
numerals: display.digits === "latin" ? "latn" : "arabext",
|
|
239
|
+
onSelect: locked ? void 0 : chooseDay,
|
|
240
|
+
selected,
|
|
241
|
+
showOutsideDays: true
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
!locked && (value || activeDraft) && /* @__PURE__ */ jsx("button", { onClick: () => chooseDay(void 0), type: "button", children: t(lang, "ui.clear") })
|
|
245
|
+
] });
|
|
246
|
+
};
|
|
247
|
+
export {
|
|
248
|
+
JalaliDateFieldComponent
|
|
249
|
+
};
|
|
250
|
+
//# sourceMappingURL=jalali-date-field.js.map
|