@nexload-sdk/payload-fields 2.0.1 → 3.1.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.
Files changed (82) hide show
  1. package/README.md +15 -67
  2. package/dist/admin/jalali-date-cell.cjs +58 -0
  3. package/dist/admin/jalali-date-cell.cjs.map +7 -0
  4. package/dist/admin/jalali-date-cell.d.ts +6 -0
  5. package/dist/admin/jalali-date-cell.d.ts.map +1 -0
  6. package/dist/admin/jalali-date-cell.mjs +32 -0
  7. package/dist/admin/jalali-date-cell.mjs.map +7 -0
  8. package/dist/admin/jalali-date-field.cjs +159 -0
  9. package/dist/admin/jalali-date-field.cjs.map +7 -0
  10. package/dist/admin/jalali-date-field.d.ts +11 -0
  11. package/dist/admin/jalali-date-field.d.ts.map +1 -0
  12. package/dist/admin/jalali-date-field.mjs +135 -0
  13. package/dist/admin/jalali-date-field.mjs.map +7 -0
  14. package/dist/admin/jalali-picker-value.cjs +42 -0
  15. package/dist/admin/jalali-picker-value.cjs.map +7 -0
  16. package/dist/admin/jalali-picker-value.d.ts +3 -0
  17. package/dist/admin/jalali-picker-value.d.ts.map +1 -0
  18. package/dist/admin/jalali-picker-value.mjs +18 -0
  19. package/dist/admin/jalali-picker-value.mjs.map +7 -0
  20. package/dist/admin/money-field.cjs +146 -0
  21. package/dist/admin/money-field.cjs.map +7 -0
  22. package/dist/admin/money-field.d.ts +10 -0
  23. package/dist/admin/money-field.d.ts.map +1 -0
  24. package/dist/admin/money-field.mjs +122 -0
  25. package/dist/admin/money-field.mjs.map +7 -0
  26. package/dist/admin/slug-field.cjs +135 -0
  27. package/dist/admin/slug-field.cjs.map +7 -0
  28. package/dist/admin/slug-field.d.ts +9 -0
  29. package/dist/admin/slug-field.d.ts.map +1 -0
  30. package/dist/admin/slug-field.mjs +115 -0
  31. package/dist/admin/slug-field.mjs.map +7 -0
  32. package/dist/date/format-date.d.ts +8 -1
  33. package/dist/date/format-date.d.ts.map +1 -1
  34. package/dist/date/index.cjs +117 -0
  35. package/dist/date/index.cjs.map +7 -0
  36. package/dist/date/index.d.ts +23 -4
  37. package/dist/date/index.d.ts.map +1 -1
  38. package/dist/date/index.mjs +86 -0
  39. package/dist/date/index.mjs.map +7 -0
  40. package/dist/date/picker-types.d.ts +2 -0
  41. package/dist/date/picker-types.d.ts.map +1 -0
  42. package/dist/index.cjs +411 -113
  43. package/dist/index.cjs.map +4 -4
  44. package/dist/index.d.ts +4 -4
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.mjs +394 -119
  47. package/dist/index.mjs.map +4 -4
  48. package/dist/money/index.cjs +147 -0
  49. package/dist/money/index.cjs.map +7 -0
  50. package/dist/money/index.d.ts +29 -0
  51. package/dist/money/index.d.ts.map +1 -0
  52. package/dist/money/index.mjs +117 -0
  53. package/dist/money/index.mjs.map +7 -0
  54. package/dist/plugin.d.ts +16 -0
  55. package/dist/plugin.d.ts.map +1 -0
  56. package/dist/slug/format-slug.d.ts +8 -2
  57. package/dist/slug/format-slug.d.ts.map +1 -1
  58. package/dist/slug/index.cjs +183 -0
  59. package/dist/slug/index.cjs.map +7 -0
  60. package/dist/slug/index.d.ts +12 -5
  61. package/dist/slug/index.d.ts.map +1 -1
  62. package/dist/slug/index.mjs +154 -0
  63. package/dist/slug/index.mjs.map +7 -0
  64. package/package.json +42 -27
  65. package/dist/date/date-cell.cjs +0 -60
  66. package/dist/date/date-cell.cjs.map +0 -7
  67. package/dist/date/date-cell.d.ts +0 -7
  68. package/dist/date/date-cell.d.ts.map +0 -1
  69. package/dist/date/date-cell.mjs +0 -34
  70. package/dist/date/date-cell.mjs.map +0 -7
  71. package/dist/date/date-picker.cjs +0 -221
  72. package/dist/date/date-picker.cjs.map +0 -7
  73. package/dist/date/date-picker.d.ts +0 -5
  74. package/dist/date/date-picker.d.ts.map +0 -1
  75. package/dist/date/date-picker.mjs +0 -197
  76. package/dist/date/date-picker.mjs.map +0 -7
  77. package/dist/slug/slug-field.cjs +0 -246
  78. package/dist/slug/slug-field.cjs.map +0 -7
  79. package/dist/slug/slug-field.d.ts +0 -10
  80. package/dist/slug/slug-field.d.ts.map +0 -1
  81. package/dist/slug/slug-field.mjs +0 -228
  82. package/dist/slug/slug-field.mjs.map +0 -7
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- // @nexload-sdk/payload-fields v2.0.0 (build 2026-06-21T16:01:23.950Z)
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:57.614Z)
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -21,151 +21,449 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
- dateField: () => dateField,
25
- editor: () => editor,
26
- formatDate: () => formatDate,
24
+ IRR: () => IRR,
25
+ IRT: () => IRT,
26
+ formatJalaliDate: () => formatJalaliDate,
27
+ formatMoney: () => formatMoney,
27
28
  formatSlug: () => formatSlug,
28
29
  formatSlugHook: () => formatSlugHook,
29
- slugField: () => slugField
30
+ jalaliDateField: () => jalaliDateField,
31
+ moneyField: () => moneyField,
32
+ parseMoneyToMinorUnits: () => parseMoneyToMinorUnits,
33
+ payloadFieldsPlugin: () => payloadFieldsPlugin,
34
+ resolveCurrency: () => resolveCurrency,
35
+ slugField: () => slugField,
36
+ withJalaliTimestamps: () => withJalaliTimestamps
30
37
  });
31
38
  module.exports = __toCommonJS(index_exports);
32
- var import_richtext_lexical = require("@payloadcms/richtext-lexical");
33
-
34
- // src/date/format-date.ts
35
- var import_date_fns_jalali = require("date-fns-jalali");
36
- function formatDate(_date) {
37
- if (!_date) return "";
38
- const date = typeof _date === "string" ? new Date(_date) : _date;
39
- let formatted;
40
- try {
41
- formatted = (0, import_date_fns_jalali.format)(
42
- date,
43
- "EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm"
44
- );
45
- } catch (err) {
46
- console.error(
47
- "error formatting date:",
48
- err
49
- );
50
- formatted = date.toLocaleDateString("fa-IR");
51
- }
52
- return formatted;
53
- }
54
-
55
- // src/date/index.ts
56
- var dateField = (overrides = {
57
- type: "date",
58
- name: "date"
59
- }) => {
60
- const dateField2 = {
61
- index: true,
62
- label: "\u062A\u0627\u0631\u06CC\u062E",
63
- ...overrides || {},
64
- admin: {
65
- position: "sidebar",
66
- ...(overrides == null ? void 0 : overrides.admin) || {},
67
- components: {
68
- Cell: { path: "@nexload-sdk/payload-fields/date/date-cell#DateCell" },
69
- Field: { path: "@nexload-sdk/payload-fields/date/date-picker#DatePicker" }
70
- }
71
- }
72
- };
73
- return [dateField2];
74
- };
75
39
 
76
40
  // src/slug/format-slug.ts
77
- function formatSlug(val) {
78
- const formatted = val == null ? void 0 : val.replace(
79
- / /g,
41
+ var persianDigits = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
42
+ var arabicDigits = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
43
+ function normalizeDigits(value) {
44
+ return value.replace(
45
+ /[۰-۹٠-٩]/g,
46
+ (digit) => {
47
+ const index = persianDigits.indexOf(digit);
48
+ return String(index >= 0 ? index : arabicDigits.indexOf(digit));
49
+ }
50
+ );
51
+ }
52
+ function getPath(value, path) {
53
+ return path.split(".").reduce(
54
+ (current, key) => {
55
+ if (current && typeof current === "object") return current[key];
56
+ return void 0;
57
+ },
58
+ value
59
+ );
60
+ }
61
+ function hasPath(value, path) {
62
+ return path.split(".").every((key) => {
63
+ if (!value || typeof value !== "object" || !(key in value)) return false;
64
+ value = value[key];
65
+ return true;
66
+ });
67
+ }
68
+ function formatSlug(value) {
69
+ return normalizeDigits(value.normalize("NFKC")).replace(
70
+ /[يى]/g,
71
+ "\u06CC"
72
+ ).replace(
73
+ /ك/g,
74
+ "\u06A9"
75
+ ).replace(
76
+ /[\u064B-\u065F\u0670]/g,
77
+ ""
78
+ ).replace(
79
+ /[\s_]+/g,
80
+ "-"
81
+ ).replace(
82
+ /[^\p{L}\p{N}-]+/gu,
83
+ ""
84
+ ).replace(
85
+ /-+/g,
80
86
  "-"
81
87
  ).replace(
82
- /[^\w-]+/g,
88
+ /^-+|-+$/g,
83
89
  ""
84
- ).toLowerCase();
85
- return formatted;
90
+ );
86
91
  }
87
- var formatSlugHook = (fallback) => ({ data, operation, value }) => {
88
- if (typeof value === "string") {
89
- return formatSlug(value);
92
+ var formatSlugHook = (options) => ({
93
+ data,
94
+ operation,
95
+ originalDoc,
96
+ siblingData,
97
+ previousSiblingDoc,
98
+ value
99
+ }) => {
100
+ const lock = (siblingData == null ? void 0 : siblingData[options.lockName]) ?? (data == null ? void 0 : data[options.lockName]);
101
+ const previousSlug = (previousSiblingDoc == null ? void 0 : previousSiblingDoc[options.name]) ?? (originalDoc == null ? void 0 : originalDoc[options.name]);
102
+ const sourceChanged = hasPath(
103
+ data,
104
+ options.source
105
+ ) && getPath(
106
+ data,
107
+ options.source
108
+ ) !== getPath(
109
+ originalDoc,
110
+ options.source
111
+ );
112
+ const source = hasPath(
113
+ data,
114
+ options.source
115
+ ) ? getPath(
116
+ data,
117
+ options.source
118
+ ) : getPath(
119
+ originalDoc,
120
+ options.source
121
+ );
122
+ if (lock !== false && typeof source === "string" && source.trim() && (operation === "create" || options.regenerateOnSourceChange && sourceChanged)) {
123
+ return formatSlug(source);
90
124
  }
91
- if (operation === "create" || (data == null ? void 0 : data.slug) === void 0) {
92
- const fallbackData = data == null ? void 0 : data[fallback];
93
- if (typeof fallbackData === "string") {
94
- return formatSlug(fallbackData);
95
- }
125
+ if (operation === "update" && lock !== false && sourceChanged && !source && previousSlug !== void 0) {
126
+ return previousSlug;
96
127
  }
128
+ if (lock !== false && operation === "update" && previousSlug !== void 0) return previousSlug;
129
+ if (typeof value === "string") return formatSlug(value);
97
130
  return value;
98
131
  };
99
132
 
100
133
  // src/slug/index.ts
101
- var slugField = (fieldToUse = "title", overrides = {}) => {
102
- const { slugOverrides, checkboxOverrides } = overrides;
103
- const checkBoxField = {
104
- name: "slugLock",
134
+ function slugField(options = {}) {
135
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
136
+ const name = options.name ?? "slug";
137
+ const lockName = options.lockName ?? `${name}Lock`;
138
+ const source = options.source ?? "title";
139
+ const localized = ((_b = (_a = options.overrides) == null ? void 0 : _a.slug) == null ? void 0 : _b.localized) === true;
140
+ if (((_d = (_c = options.overrides) == null ? void 0 : _c.slug) == null ? void 0 : _d.name) && options.overrides.slug.name !== name) throw new Error("Slug field name is protected.");
141
+ if (((_f = (_e = options.overrides) == null ? void 0 : _e.lock) == null ? void 0 : _f.name) && options.overrides.lock.name !== lockName) throw new Error("Slug lock name is protected.");
142
+ if (((_h = (_g = options.overrides) == null ? void 0 : _g.lock) == null ? void 0 : _h.localized) !== void 0 && options.overrides.lock.localized !== localized) throw new Error("Slug lock localization must match slug localization.");
143
+ if (((_j = (_i = options.overrides) == null ? void 0 : _i.slug) == null ? void 0 : _j.type) && options.overrides.slug.type !== "text") throw new Error("Slug field type is protected.");
144
+ if (((_l = (_k = options.overrides) == null ? void 0 : _k.lock) == null ? void 0 : _l.type) && options.overrides.lock.type !== "checkbox") throw new Error("Slug lock type is protected.");
145
+ const slugOverrides = ((_m = options.overrides) == null ? void 0 : _m.slug) ?? {};
146
+ const lockOverrides = ((_n = options.overrides) == null ? void 0 : _n.lock) ?? {};
147
+ const consumerHooks = ((_o = slugOverrides.hooks) == null ? void 0 : _o.beforeValidate) ?? [];
148
+ const slug = {
149
+ ...slugOverrides,
150
+ name,
151
+ type: "text",
152
+ index: slugOverrides.index ?? true,
153
+ localized,
154
+ admin: {
155
+ ...slugOverrides.admin,
156
+ position: ((_p = slugOverrides.admin) == null ? void 0 : _p.position) ?? "sidebar",
157
+ components: {
158
+ ...(_q = slugOverrides.admin) == null ? void 0 : _q.components,
159
+ Field: {
160
+ path: "@nexload-sdk/payload-fields/admin/slug-field#SlugFieldComponent",
161
+ clientProps: { source, lockName, generator: options.generator }
162
+ }
163
+ }
164
+ },
165
+ custom: { ...slugOverrides.custom, nexload: { ...(_r = slugOverrides.custom) == null ? void 0 : _r.nexload, slug: { source, lockName, generator: options.generator } } },
166
+ hooks: {
167
+ ...slugOverrides.hooks,
168
+ beforeValidate: [
169
+ ...consumerHooks,
170
+ formatSlugHook({ name, lockName, source, regenerateOnSourceChange: options.regenerateOnSourceChange ?? true })
171
+ ]
172
+ }
173
+ };
174
+ const lock = {
175
+ ...lockOverrides,
176
+ name: lockName,
105
177
  type: "checkbox",
178
+ localized,
106
179
  defaultValue: true,
180
+ admin: { ...lockOverrides.admin, hidden: true, position: ((_s = lockOverrides.admin) == null ? void 0 : _s.position) ?? "sidebar" }
181
+ };
182
+ return [
183
+ slug,
184
+ lock
185
+ ];
186
+ }
187
+
188
+ // src/date/format-date.ts
189
+ function formatJalaliDate(value, options = {}) {
190
+ if (value === null || value === void 0) return null;
191
+ const date = value instanceof Date ? value : new Date(value);
192
+ if (Number.isNaN(date.getTime())) return null;
193
+ const locale = options.digits === "latin" ? "fa-IR-u-ca-persian-nu-latn" : "fa-IR-u-ca-persian";
194
+ return new Intl.DateTimeFormat(
195
+ locale,
196
+ {
197
+ dateStyle: options.dateStyle ?? "medium",
198
+ ...options.timeStyle ? { timeStyle: options.timeStyle } : {},
199
+ ...options.timeZone ? { timeZone: options.timeZone } : {}
200
+ }
201
+ ).format(date);
202
+ }
203
+
204
+ // src/date/index.ts
205
+ function jalaliDateField(options) {
206
+ var _a, _b, _c;
207
+ const overrides = options.overrides ?? {};
208
+ if (overrides.name && overrides.name !== options.name) throw new Error("Jalali date field name is protected.");
209
+ if (overrides.type && overrides.type !== "date") throw new Error("Jalali date field type is protected.");
210
+ const appearance = options.pickerAppearance ?? "dayOnly";
211
+ const display = {
212
+ digits: "persian",
213
+ dateStyle: "medium",
214
+ ...appearance === "dayAndTime" || appearance === "timeOnly" ? { timeStyle: "short" } : {},
215
+ ...options.display
216
+ };
217
+ return {
218
+ ...overrides,
219
+ name: options.name,
220
+ type: "date",
107
221
  admin: {
108
- hidden: true,
109
- position: "sidebar"
222
+ ...overrides.admin,
223
+ date: { ...(_a = overrides.admin) == null ? void 0 : _a.date, pickerAppearance: appearance },
224
+ components: {
225
+ ...(_b = overrides.admin) == null ? void 0 : _b.components,
226
+ Field: { path: "@nexload-sdk/payload-fields/admin/jalali-date-field#JalaliDateFieldComponent", clientProps: { appearance, display } },
227
+ Cell: { path: "@nexload-sdk/payload-fields/admin/jalali-date-cell#JalaliDateCell", clientProps: { display } }
228
+ }
110
229
  },
111
- ...checkboxOverrides
230
+ custom: { ...overrides.custom, nexload: { ...(_c = overrides.custom) == null ? void 0 : _c.nexload, jalaliDate: { appearance, display } } }
112
231
  };
113
- const slugField2 = {
114
- name: "slug",
115
- type: "text",
116
- index: true,
117
- label: "\u0627\u0633\u0644\u0627\u06AF",
118
- ...slugOverrides || {},
119
- hooks: {
120
- // Kept this in for hook or API based updates
121
- beforeValidate: [formatSlugHook(fieldToUse)]
122
- },
232
+ }
233
+ function withJalaliTimestamps(fields, options = {}) {
234
+ var _a, _b;
235
+ const output = [...fields];
236
+ const add = (name, source, override) => {
237
+ var _a2;
238
+ if (output.some((field) => "name" in field && field.name === name)) throw new Error(`Duplicate Jalali timestamp field: ${name}`);
239
+ output.push({
240
+ ...override,
241
+ name,
242
+ type: "text",
243
+ virtual: true,
244
+ admin: { ...override == null ? void 0 : override.admin, readOnly: true },
245
+ hooks: {
246
+ ...override == null ? void 0 : override.hooks,
247
+ afterRead: [
248
+ ...((_a2 = override == null ? void 0 : override.hooks) == null ? void 0 : _a2.afterRead) ?? [],
249
+ ({ siblingData }) => formatJalaliDate(
250
+ siblingData == null ? void 0 : siblingData[source],
251
+ options.display
252
+ )
253
+ ]
254
+ }
255
+ });
256
+ };
257
+ if (options.createdAt !== false) add(
258
+ "createdAtJalali",
259
+ "createdAt",
260
+ (_a = options.overrides) == null ? void 0 : _a.createdAt
261
+ );
262
+ if (options.updatedAt !== false) add(
263
+ "updatedAtJalali",
264
+ "updatedAt",
265
+ (_b = options.overrides) == null ? void 0 : _b.updatedAt
266
+ );
267
+ return output;
268
+ }
269
+
270
+ // src/money/index.ts
271
+ var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
272
+ var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
273
+ function resolveCurrency(currency) {
274
+ const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
275
+ if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
276
+ return result;
277
+ }
278
+ function normalizedNumber(value) {
279
+ const persian = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
280
+ const arabic = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
281
+ return value.trim().replace(
282
+ /[۰-۹٠-٩]/g,
283
+ (digit) => String(Math.max(
284
+ persian.indexOf(digit),
285
+ arabic.indexOf(digit)
286
+ ) % 10)
287
+ ).replace(
288
+ /[٬,\s]/g,
289
+ ""
290
+ ).replace(
291
+ /٫/g,
292
+ "."
293
+ );
294
+ }
295
+ function parseMoneyToMinorUnits(input, currency) {
296
+ const definition = resolveCurrency(currency);
297
+ const value = normalizedNumber(input);
298
+ if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
299
+ const negative = value.startsWith("-");
300
+ const [
301
+ whole,
302
+ fraction = ""
303
+ ] = (negative ? value.slice(1) : value).split(".");
304
+ if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
305
+ const digits = `${whole}${fraction.padEnd(
306
+ definition.fractionDigits,
307
+ "0"
308
+ )}`.replace(
309
+ /^0+(?=\d)/,
310
+ ""
311
+ ) || "0";
312
+ const minor = Number(`${negative ? "-" : ""}${digits}`);
313
+ if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
314
+ return minor;
315
+ }
316
+ function formatMoney(value, currency, display = {}) {
317
+ if (value === null || value === void 0) return null;
318
+ if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
319
+ const definition = resolveCurrency(currency);
320
+ const locale = display.locale ?? (display.digits === "latin" ? "fa-IR-u-nu-latn" : "fa-IR");
321
+ const major = value / 10 ** definition.fractionDigits;
322
+ const formatted = new Intl.NumberFormat(
323
+ locale,
324
+ { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }
325
+ ).format(major);
326
+ return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
327
+ }
328
+ function moneyField(options) {
329
+ var _a, _b;
330
+ const overrides = options.overrides ?? {};
331
+ if (overrides.name && overrides.name !== options.name) throw new Error("Money field name is protected.");
332
+ if (overrides.type && overrides.type !== "number") throw new Error("Money field type is protected.");
333
+ const currency = resolveCurrency(options.currency);
334
+ if (options.minMinorUnits !== void 0 && (!Number.isSafeInteger(options.minMinorUnits) || options.maxMinorUnits !== void 0 && options.minMinorUnits > options.maxMinorUnits)) throw new Error("Invalid money bounds.");
335
+ if (options.maxMinorUnits !== void 0 && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error("Invalid money bounds.");
336
+ const consumerValidate = overrides.validate;
337
+ const validate = (value, args) => {
338
+ if (value === null || value === void 0 || value === "") return (args == null ? void 0 : args.required) ? "\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A." : true;
339
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) return "\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.";
340
+ if (!options.allowNegative && value < 0) return "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.";
341
+ if (options.minMinorUnits !== void 0 && value < options.minMinorUnits) return "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
342
+ if (options.maxMinorUnits !== void 0 && value > options.maxMinorUnits) return "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
343
+ return consumerValidate ? consumerValidate(
344
+ value,
345
+ args
346
+ ) : true;
347
+ };
348
+ const display = {
349
+ locale: "fa-IR",
350
+ digits: "persian",
351
+ grouping: true,
352
+ showCurrency: true,
353
+ ...options.display
354
+ };
355
+ return {
356
+ ...overrides,
357
+ name: options.name,
358
+ type: "number",
359
+ validate,
123
360
  admin: {
124
- position: "sidebar",
125
- ...(slugOverrides == null ? void 0 : slugOverrides.admin) || {},
361
+ ...overrides.admin,
126
362
  components: {
363
+ ...(_a = overrides.admin) == null ? void 0 : _a.components,
127
364
  Field: {
128
- path: "@nexload-sdk/payload-fields/slug/slug-field#SlugComponent",
365
+ path: "@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent",
129
366
  clientProps: {
130
- fieldToUse,
131
- checkboxFieldPath: checkBoxField.name
367
+ currency,
368
+ display,
369
+ allowNegative: options.allowNegative ?? false
132
370
  }
133
371
  }
134
372
  }
135
- }
373
+ },
374
+ custom: { ...overrides.custom, nexload: { ...(_b = overrides.custom) == null ? void 0 : _b.nexload, money: currency } }
136
375
  };
137
- return [slugField2, checkBoxField];
138
- };
376
+ }
139
377
 
140
- // src/index.ts
141
- var editor = (0, import_richtext_lexical.lexicalEditor)({
142
- admin: {
143
- hideInsertParagraphAtEnd: true,
144
- hideGutter: true
145
- },
146
- features: ({ defaultFeatures }) => {
147
- return [
148
- ...defaultFeatures,
149
- (0, import_richtext_lexical.HeadingFeature)({
150
- enabledHeadingSizes: ["h1", "h2", "h3", "h4"]
151
- }),
152
- (0, import_richtext_lexical.FixedToolbarFeature)({ applyToFocusedEditor: true }),
153
- (0, import_richtext_lexical.HorizontalRuleFeature)(),
154
- (0, import_richtext_lexical.UploadFeature)(),
155
- (0, import_richtext_lexical.EXPERIMENTAL_TableFeature)(),
156
- (0, import_richtext_lexical.RelationshipFeature)({
157
- enabledCollections: ["products", "articles"]
158
- })
159
- ];
160
- }
161
- });
378
+ // src/plugin.ts
379
+ function failure(code, message, status) {
380
+ return Response.json(
381
+ { error: { code, message } },
382
+ { status }
383
+ );
384
+ }
385
+ function payloadFieldsPlugin(options = {}) {
386
+ return (config) => ({
387
+ ...config,
388
+ endpoints: [
389
+ ...config.endpoints ?? [],
390
+ {
391
+ path: "/payload-fields/generate-slug",
392
+ method: "post",
393
+ handler: async (req) => {
394
+ var _a;
395
+ if (!req.user) return failure(
396
+ "PAYLOAD_FIELDS_UNAUTHENTICATED",
397
+ "\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.",
398
+ 401
399
+ );
400
+ if (options.generateSlugAccess && !await options.generateSlugAccess({ req })) return failure(
401
+ "PAYLOAD_FIELDS_FORBIDDEN",
402
+ "\u0627\u062C\u0627\u0632\u0647 \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0631\u0627 \u0646\u062F\u0627\u0631\u06CC\u062F.",
403
+ 403
404
+ );
405
+ let body;
406
+ try {
407
+ body = await ((_a = req.json) == null ? void 0 : _a.call(req));
408
+ } catch {
409
+ return failure(
410
+ "PAYLOAD_FIELDS_INVALID_INPUT",
411
+ "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
412
+ 400
413
+ );
414
+ }
415
+ if (!body || typeof body !== "object" || Array.isArray(body)) return failure(
416
+ "PAYLOAD_FIELDS_INVALID_INPUT",
417
+ "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
418
+ 400
419
+ );
420
+ const input = body;
421
+ if (typeof input.generator !== "string" || typeof input.sourceValue !== "string" || input.currentSlug !== void 0 && typeof input.currentSlug !== "string") return failure(
422
+ "PAYLOAD_FIELDS_INVALID_INPUT",
423
+ "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
424
+ 400
425
+ );
426
+ const generator = options.slugGenerators && Object.prototype.hasOwnProperty.call(
427
+ options.slugGenerators,
428
+ input.generator
429
+ ) ? options.slugGenerators[input.generator] : void 0;
430
+ if (!generator) return failure(
431
+ "PAYLOAD_FIELDS_GENERATOR_NOT_FOUND",
432
+ "\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.",
433
+ 404
434
+ );
435
+ try {
436
+ const result = await generator(
437
+ { sourceValue: input.sourceValue, currentSlug: input.currentSlug },
438
+ { req }
439
+ );
440
+ return Response.json({ slug: formatSlug(result) });
441
+ } catch {
442
+ return failure(
443
+ "PAYLOAD_FIELDS_GENERATION_FAILED",
444
+ "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.",
445
+ 500
446
+ );
447
+ }
448
+ }
449
+ }
450
+ ]
451
+ });
452
+ }
162
453
  // Annotate the CommonJS export names for ESM import in node:
163
454
  0 && (module.exports = {
164
- dateField,
165
- editor,
166
- formatDate,
455
+ IRR,
456
+ IRT,
457
+ formatJalaliDate,
458
+ formatMoney,
167
459
  formatSlug,
168
460
  formatSlugHook,
169
- slugField
461
+ jalaliDateField,
462
+ moneyField,
463
+ parseMoneyToMinorUnits,
464
+ payloadFieldsPlugin,
465
+ resolveCurrency,
466
+ slugField,
467
+ withJalaliTimestamps
170
468
  });
171
469
  //# sourceMappingURL=index.cjs.map