@nexload-sdk/payload-fields 2.0.0 → 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 +45 -30
  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
@@ -0,0 +1,18 @@
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:56.848Z)
2
+
3
+ // src/admin/jalali-picker-value.ts
4
+ import { getDateLib } from "react-day-picker/persian";
5
+ function canonicalizeJalaliPickerDate(date, appearance) {
6
+ const result = appearance === "monthOnly" ? getDateLib().startOfMonth(date) : new Date(date);
7
+ if (appearance === "dayOnly" || appearance === "monthOnly") result.setHours(
8
+ 12,
9
+ 0,
10
+ 0,
11
+ 0
12
+ );
13
+ return result;
14
+ }
15
+ export {
16
+ canonicalizeJalaliPickerDate
17
+ };
18
+ //# sourceMappingURL=jalali-picker-value.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/admin/jalali-picker-value.ts"],
4
+ "sourcesContent": ["import { getDateLib } from \"react-day-picker/persian\";\n\nimport type { JalaliPickerAppearance } from \"../date/picker-types\";\n\nexport function canonicalizeJalaliPickerDate (\n date: Date, appearance: JalaliPickerAppearance\n): Date {\n const result = appearance === \"monthOnly\"\n ? getDateLib().startOfMonth(date)\n : new Date(date);\n\n if (appearance === \"dayOnly\" || appearance === \"monthOnly\") result.setHours(\n 12, 0, 0, 0\n );\n\n return result;\n}\n"],
5
+ "mappings": ";;;AAAA,SAAS,kBAAkB;AAIpB,SAAS,6BACd,MAAY,YACN;AACN,QAAM,SAAS,eAAe,cAC1B,WAAW,EAAE,aAAa,IAAI,IAC9B,IAAI,KAAK,IAAI;AAEjB,MAAI,eAAe,aAAa,eAAe,YAAa,QAAO;AAAA,IACjE;AAAA,IAAI;AAAA,IAAG;AAAA,IAAG;AAAA,EACZ;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,146 @@
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:57.614Z)
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/admin/money-field.tsx
23
+ var money_field_exports = {};
24
+ __export(money_field_exports, {
25
+ MoneyFieldComponent: () => MoneyFieldComponent
26
+ });
27
+ module.exports = __toCommonJS(money_field_exports);
28
+ var import_ui = require("@payloadcms/ui");
29
+ var import_react = require("react");
30
+
31
+ // src/money/index.ts
32
+ var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
33
+ var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
34
+ function resolveCurrency(currency) {
35
+ const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
36
+ if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
37
+ return result;
38
+ }
39
+ function normalizedNumber(value) {
40
+ const persian = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
41
+ const arabic = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
42
+ return value.trim().replace(
43
+ /[۰-۹٠-٩]/g,
44
+ (digit) => String(Math.max(
45
+ persian.indexOf(digit),
46
+ arabic.indexOf(digit)
47
+ ) % 10)
48
+ ).replace(
49
+ /[٬,\s]/g,
50
+ ""
51
+ ).replace(
52
+ /٫/g,
53
+ "."
54
+ );
55
+ }
56
+ function parseMoneyToMinorUnits(input, currency) {
57
+ const definition = resolveCurrency(currency);
58
+ const value = normalizedNumber(input);
59
+ if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
60
+ const negative = value.startsWith("-");
61
+ const [
62
+ whole,
63
+ fraction = ""
64
+ ] = (negative ? value.slice(1) : value).split(".");
65
+ if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
66
+ const digits = `${whole}${fraction.padEnd(
67
+ definition.fractionDigits,
68
+ "0"
69
+ )}`.replace(
70
+ /^0+(?=\d)/,
71
+ ""
72
+ ) || "0";
73
+ const minor = Number(`${negative ? "-" : ""}${digits}`);
74
+ if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
75
+ return minor;
76
+ }
77
+ function formatMoney(value, currency, display = {}) {
78
+ if (value === null || value === void 0) return null;
79
+ if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
80
+ const definition = resolveCurrency(currency);
81
+ const locale = display.locale ?? (display.digits === "latin" ? "fa-IR-u-nu-latn" : "fa-IR");
82
+ const major = value / 10 ** definition.fractionDigits;
83
+ const formatted = new Intl.NumberFormat(
84
+ locale,
85
+ { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }
86
+ ).format(major);
87
+ return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
88
+ }
89
+
90
+ // src/admin/money-field.tsx
91
+ var import_jsx_runtime = require("react/jsx-runtime");
92
+ var MoneyFieldComponent = ({
93
+ field,
94
+ path,
95
+ currency,
96
+ display,
97
+ readOnly
98
+ }) => {
99
+ const { value, setValue } = (0, import_ui.useField)({ path });
100
+ const [
101
+ input,
102
+ setInput
103
+ ] = (0, import_react.useState)("");
104
+ (0, import_react.useEffect)(
105
+ () => setInput(typeof value === "number" ? formatMoney(
106
+ value,
107
+ currency,
108
+ { ...display, showCurrency: false }
109
+ ) ?? "" : ""),
110
+ [
111
+ currency,
112
+ display,
113
+ value
114
+ ]
115
+ );
116
+ const change = (next) => {
117
+ setInput(next);
118
+ if (!next.trim()) return setValue(null);
119
+ try {
120
+ setValue(parseMoneyToMinorUnits(
121
+ next,
122
+ currency
123
+ ));
124
+ } catch {
125
+ setValue(next);
126
+ }
127
+ };
128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "field-type money-field", children: [
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.FieldLabel, { htmlFor: `field-${path}`, label: field.label, required: field.required }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
131
+ "input",
132
+ {
133
+ inputMode: "decimal",
134
+ onChange: (event) => change(event.target.value),
135
+ readOnly,
136
+ value: input
137
+ }
138
+ ),
139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: currency.label })
140
+ ] });
141
+ };
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ MoneyFieldComponent
145
+ });
146
+ //# sourceMappingURL=money-field.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/admin/money-field.tsx", "../../src/money/index.ts"],
4
+ "sourcesContent": ["\"use client\";\n\nimport { FieldLabel, useField } from \"@payloadcms/ui\";\nimport { useEffect, useState } from \"react\";\n\nimport { formatMoney, parseMoneyToMinorUnits, type MoneyCurrencyDefinition, type MoneyDisplayOptions } from \"../money\";\n\nimport type { NumberFieldClientProps } from \"payload\";\n\ntype Props = { currency: MoneyCurrencyDefinition, display: MoneyDisplayOptions, allowNegative: boolean };\n\nexport const MoneyFieldComponent = ({\n field, path, currency, display, readOnly,\n}: NumberFieldClientProps & Props) => {\n const { value, setValue, } = useField<number | string | null>({ path, });\n const [\n input,\n setInput\n ] = useState(\"\");\n useEffect(\n () => setInput(typeof value === \"number\"\n ? (formatMoney(\n value, currency, { ...display, showCurrency: false, }\n ) ?? \"\")\n : \"\"), [\n currency,\n display,\n value\n ]\n );\n const change = (next: string) => {\n setInput(next);\n if (!next.trim()) return setValue(null);\n try {\n setValue(parseMoneyToMinorUnits(\n next, currency\n ));\n } catch { setValue(next); }\n };\n return (\n <div className=\"field-type money-field\">\n <FieldLabel htmlFor={`field-${path}`} label={field.label} required={field.required} />\n <input\n inputMode=\"decimal\" onChange={(event) => change(event.target.value)} readOnly={readOnly}\n value={input}\n />\n <span>\n {currency.label}\n </span>\n </div>\n );\n};\n", "import type { NumberField } from \"payload\";\n\nexport type MoneyCurrencyDefinition = {\n code: string\n label: string\n fractionDigits: number\n};\nexport type MoneyCurrency = \"IRR\" | \"IRT\" | MoneyCurrencyDefinition;\nexport type MoneyDisplayOptions = {\n locale?: string\n digits?: \"persian\" | \"latin\"\n grouping?: boolean\n showCurrency?: boolean\n};\nexport type MoneyFieldOptions = {\n name: string\n currency: MoneyCurrency\n minMinorUnits?: number\n maxMinorUnits?: number\n allowNegative?: boolean\n display?: MoneyDisplayOptions\n overrides?: Partial<NumberField>\n};\n\nexport const IRR: Readonly<MoneyCurrencyDefinition> = { code: \"IRR\", label: \"\u0631\u06CC\u0627\u0644\", fractionDigits: 0, };\nexport const IRT: Readonly<MoneyCurrencyDefinition> = { code: \"IRT\", label: \"\u062A\u0648\u0645\u0627\u0646\", fractionDigits: 0, };\n\nexport function resolveCurrency (currency: MoneyCurrency): MoneyCurrencyDefinition {\n const result = currency === \"IRR\" ? IRR : currency === \"IRT\" ? IRT : currency;\n if (\n !result.code.trim()\n || !result.label.trim()\n || !Number.isInteger(result.fractionDigits)\n || result.fractionDigits < 0\n || result.fractionDigits > 20\n ) throw new Error(\"Invalid money currency definition.\");\n return result;\n}\n\nfunction normalizedNumber (value: string): string {\n const persian = \"\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9\";\n const arabic = \"\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669\";\n return value.trim().replace(\n /[\u06F0-\u06F9\u0660-\u0669]/g, (digit) => String(Math.max(\n persian.indexOf(digit), arabic.indexOf(digit)\n ) % 10)\n )\n .replace(\n /[\u066C,\\s]/g, \"\"\n )\n .replace(\n /\u066B/g, \".\"\n );\n}\n\nexport function parseMoneyToMinorUnits (\n input: string, currency: MoneyCurrency\n): number {\n const definition = resolveCurrency(currency);\n const value = normalizedNumber(input);\n if (!(/^-?\\d+(?:\\.\\d+)?$/).test(value)) throw new TypeError(\"Invalid money input.\");\n const negative = value.startsWith(\"-\");\n const [\n whole,\n fraction = \"\"\n ] = (negative ? value.slice(1) : value).split(\".\");\n if (fraction.length > definition.fractionDigits) throw new RangeError(\"Money input has unsupported precision.\");\n const digits = `${whole}${fraction.padEnd(\n definition.fractionDigits, \"0\"\n )}`.replace(\n /^0+(?=\\d)/, \"\"\n ) || \"0\";\n const minor = Number(`${negative ? \"-\" : \"\"}${digits}`);\n if (!Number.isSafeInteger(minor)) throw new RangeError(\"Money value is outside the safe integer range.\");\n return minor;\n}\n\nexport function formatMoney (\n value: number | null | undefined,\n currency: MoneyCurrency,\n display: MoneyDisplayOptions = {}\n): string | null {\n if (value === null || value === undefined) return null;\n if (!Number.isSafeInteger(value)) throw new RangeError(\"Money value is outside the safe integer range.\");\n const definition = resolveCurrency(currency);\n const locale = display.locale ?? (display.digits === \"latin\" ? \"fa-IR-u-nu-latn\" : \"fa-IR\");\n const major = value / 10 ** definition.fractionDigits;\n const formatted = new Intl.NumberFormat(\n locale, { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits, }\n ).format(major);\n return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;\n}\n\nexport function moneyField (options: MoneyFieldOptions): NumberField {\n const overrides = options.overrides ?? {};\n if (overrides.name && overrides.name !== options.name) throw new Error(\"Money field name is protected.\");\n if (overrides.type && overrides.type !== \"number\") throw new Error(\"Money field type is protected.\");\n const currency = resolveCurrency(options.currency);\n if (\n options.minMinorUnits !== undefined\n && (\n !Number.isSafeInteger(options.minMinorUnits)\n || (\n options.maxMinorUnits !== undefined\n && options.minMinorUnits > options.maxMinorUnits\n )\n )\n ) throw new Error(\"Invalid money bounds.\");\n if (options.maxMinorUnits !== undefined && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error(\"Invalid money bounds.\");\n const consumerValidate = overrides.validate;\n const validate: NumberField[\"validate\"] = (\n value: unknown, args: { required?: boolean } | undefined\n ) => {\n if (value === null || value === undefined || value === \"\") return args?.required ? \"\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.\" : true;\n 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.\";\n if (!options.allowNegative && value < 0) return \"\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.\";\n if (options.minMinorUnits !== undefined && value < options.minMinorUnits) return \"\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n if (options.maxMinorUnits !== undefined && value > options.maxMinorUnits) return \"\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n return consumerValidate\n ? (consumerValidate as (value: number, args: unknown) => string | true)(\n value, args\n )\n : true;\n };\n const display = {\n locale: \"fa-IR\", digits: \"persian\" as const, grouping: true, showCurrency: true, ...options.display,\n };\n return {\n ...overrides,\n name: options.name,\n type: \"number\",\n validate,\n admin: {\n ...overrides.admin,\n components: {\n ...overrides.admin?.components,\n Field: {\n path: \"@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent\",\n clientProps: {\n currency,\n display,\n allowNegative: options.allowNegative ?? false,\n },\n },\n },\n },\n custom: { ...overrides.custom, nexload: { ...(overrides.custom?.nexload as object), money: currency, }, },\n } as NumberField;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAAqC;AACrC,mBAAoC;;;ACqB7B,IAAM,MAAyC,EAAE,MAAM,OAAO,OAAO,4BAAQ,gBAAgB,EAAG;AAChG,IAAM,MAAyC,EAAE,MAAM,OAAO,OAAO,kCAAS,gBAAgB,EAAG;AAEjG,SAAS,gBAAiB,UAAkD;AACjF,QAAM,SAAS,aAAa,QAAQ,MAAM,aAAa,QAAQ,MAAM;AACrE,MACE,CAAC,OAAO,KAAK,KAAK,KACf,CAAC,OAAO,MAAM,KAAK,KACnB,CAAC,OAAO,UAAU,OAAO,cAAc,KACvC,OAAO,iBAAiB,KACxB,OAAO,iBAAiB,GAC3B,OAAM,IAAI,MAAM,oCAAoC;AACtD,SAAO;AACT;AAEA,SAAS,iBAAkB,OAAuB;AAChD,QAAM,UAAU;AAChB,QAAM,SAAS;AACf,SAAO,MAAM,KAAK,EAAE;AAAA,IAClB;AAAA,IAAa,CAAC,UAAU,OAAO,KAAK;AAAA,MAClC,QAAQ,QAAQ,KAAK;AAAA,MAAG,OAAO,QAAQ,KAAK;AAAA,IAC9C,IAAI,EAAE;AAAA,EACR,EACG;AAAA,IACC;AAAA,IAAW;AAAA,EACb,EACC;AAAA,IACC;AAAA,IAAM;AAAA,EACR;AACJ;AAEO,SAAS,uBACd,OAAe,UACP;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AM;AAAA,EAAU;AAAA,EAAS;AAClC,MAAsC;AACpC,QAAM,EAAE,OAAO,SAAU,QAAI,oBAAiC,EAAE,KAAM,CAAC;AACvE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EACF,QAAI,uBAAS,EAAE;AACf;AAAA,IACE,MAAM,SAAS,OAAO,UAAU,WAC3B;AAAA,MACD;AAAA,MAAO;AAAA,MAAU,EAAE,GAAG,SAAS,cAAc,MAAO;AAAA,IACtD,KAAK,KACH,EAAE;AAAA,IAAG;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,CAAC,SAAiB;AAC/B,aAAS,IAAI;AACb,QAAI,CAAC,KAAK,KAAK,EAAG,QAAO,SAAS,IAAI;AACtC,QAAI;AACF,eAAS;AAAA,QACP;AAAA,QAAM;AAAA,MACR,CAAC;AAAA,IACH,QAAQ;AAAE,eAAS,IAAI;AAAA,IAAG;AAAA,EAC5B;AACA,SACE,6CAAC,SAAI,WAAU,0BACb;AAAA,gDAAC,wBAAW,SAAS,SAAS,IAAI,IAAI,OAAO,MAAM,OAAO,UAAU,MAAM,UAAU;AAAA,IACpF;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QAAU,UAAU,CAAC,UAAU,OAAO,MAAM,OAAO,KAAK;AAAA,QAAG;AAAA,QACrE,OAAO;AAAA;AAAA,IACT;AAAA,IACA,4CAAC,UACE,mBAAS,OACZ;AAAA,KACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ import { type MoneyCurrencyDefinition, type MoneyDisplayOptions } from "../money";
2
+ import type { NumberFieldClientProps } from "payload";
3
+ type Props = {
4
+ currency: MoneyCurrencyDefinition;
5
+ display: MoneyDisplayOptions;
6
+ allowNegative: boolean;
7
+ };
8
+ export declare const MoneyFieldComponent: ({ field, path, currency, display, readOnly, }: NumberFieldClientProps & Props) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=money-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money-field.d.ts","sourceRoot":"","sources":["../../src/admin/money-field.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAuC,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,KAAK,KAAK,GAAG;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzG,eAAO,MAAM,mBAAmB,GAAI,+CAEjC,sBAAsB,GAAG,KAAK,4CAsChC,CAAC"}
@@ -0,0 +1,122 @@
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:56.848Z)
2
+ "use client";
3
+
4
+ // src/admin/money-field.tsx
5
+ import { FieldLabel, useField } from "@payloadcms/ui";
6
+ import { useEffect, useState } from "react";
7
+
8
+ // src/money/index.ts
9
+ var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
10
+ var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
11
+ function resolveCurrency(currency) {
12
+ const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
13
+ if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
14
+ return result;
15
+ }
16
+ function normalizedNumber(value) {
17
+ const persian = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
18
+ const arabic = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
19
+ return value.trim().replace(
20
+ /[۰-۹٠-٩]/g,
21
+ (digit) => String(Math.max(
22
+ persian.indexOf(digit),
23
+ arabic.indexOf(digit)
24
+ ) % 10)
25
+ ).replace(
26
+ /[٬,\s]/g,
27
+ ""
28
+ ).replace(
29
+ /٫/g,
30
+ "."
31
+ );
32
+ }
33
+ function parseMoneyToMinorUnits(input, currency) {
34
+ const definition = resolveCurrency(currency);
35
+ const value = normalizedNumber(input);
36
+ if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
37
+ const negative = value.startsWith("-");
38
+ const [
39
+ whole,
40
+ fraction = ""
41
+ ] = (negative ? value.slice(1) : value).split(".");
42
+ if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
43
+ const digits = `${whole}${fraction.padEnd(
44
+ definition.fractionDigits,
45
+ "0"
46
+ )}`.replace(
47
+ /^0+(?=\d)/,
48
+ ""
49
+ ) || "0";
50
+ const minor = Number(`${negative ? "-" : ""}${digits}`);
51
+ if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
52
+ return minor;
53
+ }
54
+ function formatMoney(value, currency, display = {}) {
55
+ if (value === null || value === void 0) return null;
56
+ if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
57
+ const definition = resolveCurrency(currency);
58
+ const locale = display.locale ?? (display.digits === "latin" ? "fa-IR-u-nu-latn" : "fa-IR");
59
+ const major = value / 10 ** definition.fractionDigits;
60
+ const formatted = new Intl.NumberFormat(
61
+ locale,
62
+ { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }
63
+ ).format(major);
64
+ return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
65
+ }
66
+
67
+ // src/admin/money-field.tsx
68
+ import { jsx, jsxs } from "react/jsx-runtime";
69
+ var MoneyFieldComponent = ({
70
+ field,
71
+ path,
72
+ currency,
73
+ display,
74
+ readOnly
75
+ }) => {
76
+ const { value, setValue } = useField({ path });
77
+ const [
78
+ input,
79
+ setInput
80
+ ] = useState("");
81
+ useEffect(
82
+ () => setInput(typeof value === "number" ? formatMoney(
83
+ value,
84
+ currency,
85
+ { ...display, showCurrency: false }
86
+ ) ?? "" : ""),
87
+ [
88
+ currency,
89
+ display,
90
+ value
91
+ ]
92
+ );
93
+ const change = (next) => {
94
+ setInput(next);
95
+ if (!next.trim()) return setValue(null);
96
+ try {
97
+ setValue(parseMoneyToMinorUnits(
98
+ next,
99
+ currency
100
+ ));
101
+ } catch {
102
+ setValue(next);
103
+ }
104
+ };
105
+ return /* @__PURE__ */ jsxs("div", { className: "field-type money-field", children: [
106
+ /* @__PURE__ */ jsx(FieldLabel, { htmlFor: `field-${path}`, label: field.label, required: field.required }),
107
+ /* @__PURE__ */ jsx(
108
+ "input",
109
+ {
110
+ inputMode: "decimal",
111
+ onChange: (event) => change(event.target.value),
112
+ readOnly,
113
+ value: input
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsx("span", { children: currency.label })
117
+ ] });
118
+ };
119
+ export {
120
+ MoneyFieldComponent
121
+ };
122
+ //# sourceMappingURL=money-field.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/admin/money-field.tsx", "../../src/money/index.ts"],
4
+ "sourcesContent": ["\"use client\";\n\nimport { FieldLabel, useField } from \"@payloadcms/ui\";\nimport { useEffect, useState } from \"react\";\n\nimport { formatMoney, parseMoneyToMinorUnits, type MoneyCurrencyDefinition, type MoneyDisplayOptions } from \"../money\";\n\nimport type { NumberFieldClientProps } from \"payload\";\n\ntype Props = { currency: MoneyCurrencyDefinition, display: MoneyDisplayOptions, allowNegative: boolean };\n\nexport const MoneyFieldComponent = ({\n field, path, currency, display, readOnly,\n}: NumberFieldClientProps & Props) => {\n const { value, setValue, } = useField<number | string | null>({ path, });\n const [\n input,\n setInput\n ] = useState(\"\");\n useEffect(\n () => setInput(typeof value === \"number\"\n ? (formatMoney(\n value, currency, { ...display, showCurrency: false, }\n ) ?? \"\")\n : \"\"), [\n currency,\n display,\n value\n ]\n );\n const change = (next: string) => {\n setInput(next);\n if (!next.trim()) return setValue(null);\n try {\n setValue(parseMoneyToMinorUnits(\n next, currency\n ));\n } catch { setValue(next); }\n };\n return (\n <div className=\"field-type money-field\">\n <FieldLabel htmlFor={`field-${path}`} label={field.label} required={field.required} />\n <input\n inputMode=\"decimal\" onChange={(event) => change(event.target.value)} readOnly={readOnly}\n value={input}\n />\n <span>\n {currency.label}\n </span>\n </div>\n );\n};\n", "import type { NumberField } from \"payload\";\n\nexport type MoneyCurrencyDefinition = {\n code: string\n label: string\n fractionDigits: number\n};\nexport type MoneyCurrency = \"IRR\" | \"IRT\" | MoneyCurrencyDefinition;\nexport type MoneyDisplayOptions = {\n locale?: string\n digits?: \"persian\" | \"latin\"\n grouping?: boolean\n showCurrency?: boolean\n};\nexport type MoneyFieldOptions = {\n name: string\n currency: MoneyCurrency\n minMinorUnits?: number\n maxMinorUnits?: number\n allowNegative?: boolean\n display?: MoneyDisplayOptions\n overrides?: Partial<NumberField>\n};\n\nexport const IRR: Readonly<MoneyCurrencyDefinition> = { code: \"IRR\", label: \"\u0631\u06CC\u0627\u0644\", fractionDigits: 0, };\nexport const IRT: Readonly<MoneyCurrencyDefinition> = { code: \"IRT\", label: \"\u062A\u0648\u0645\u0627\u0646\", fractionDigits: 0, };\n\nexport function resolveCurrency (currency: MoneyCurrency): MoneyCurrencyDefinition {\n const result = currency === \"IRR\" ? IRR : currency === \"IRT\" ? IRT : currency;\n if (\n !result.code.trim()\n || !result.label.trim()\n || !Number.isInteger(result.fractionDigits)\n || result.fractionDigits < 0\n || result.fractionDigits > 20\n ) throw new Error(\"Invalid money currency definition.\");\n return result;\n}\n\nfunction normalizedNumber (value: string): string {\n const persian = \"\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9\";\n const arabic = \"\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669\";\n return value.trim().replace(\n /[\u06F0-\u06F9\u0660-\u0669]/g, (digit) => String(Math.max(\n persian.indexOf(digit), arabic.indexOf(digit)\n ) % 10)\n )\n .replace(\n /[\u066C,\\s]/g, \"\"\n )\n .replace(\n /\u066B/g, \".\"\n );\n}\n\nexport function parseMoneyToMinorUnits (\n input: string, currency: MoneyCurrency\n): number {\n const definition = resolveCurrency(currency);\n const value = normalizedNumber(input);\n if (!(/^-?\\d+(?:\\.\\d+)?$/).test(value)) throw new TypeError(\"Invalid money input.\");\n const negative = value.startsWith(\"-\");\n const [\n whole,\n fraction = \"\"\n ] = (negative ? value.slice(1) : value).split(\".\");\n if (fraction.length > definition.fractionDigits) throw new RangeError(\"Money input has unsupported precision.\");\n const digits = `${whole}${fraction.padEnd(\n definition.fractionDigits, \"0\"\n )}`.replace(\n /^0+(?=\\d)/, \"\"\n ) || \"0\";\n const minor = Number(`${negative ? \"-\" : \"\"}${digits}`);\n if (!Number.isSafeInteger(minor)) throw new RangeError(\"Money value is outside the safe integer range.\");\n return minor;\n}\n\nexport function formatMoney (\n value: number | null | undefined,\n currency: MoneyCurrency,\n display: MoneyDisplayOptions = {}\n): string | null {\n if (value === null || value === undefined) return null;\n if (!Number.isSafeInteger(value)) throw new RangeError(\"Money value is outside the safe integer range.\");\n const definition = resolveCurrency(currency);\n const locale = display.locale ?? (display.digits === \"latin\" ? \"fa-IR-u-nu-latn\" : \"fa-IR\");\n const major = value / 10 ** definition.fractionDigits;\n const formatted = new Intl.NumberFormat(\n locale, { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits, }\n ).format(major);\n return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;\n}\n\nexport function moneyField (options: MoneyFieldOptions): NumberField {\n const overrides = options.overrides ?? {};\n if (overrides.name && overrides.name !== options.name) throw new Error(\"Money field name is protected.\");\n if (overrides.type && overrides.type !== \"number\") throw new Error(\"Money field type is protected.\");\n const currency = resolveCurrency(options.currency);\n if (\n options.minMinorUnits !== undefined\n && (\n !Number.isSafeInteger(options.minMinorUnits)\n || (\n options.maxMinorUnits !== undefined\n && options.minMinorUnits > options.maxMinorUnits\n )\n )\n ) throw new Error(\"Invalid money bounds.\");\n if (options.maxMinorUnits !== undefined && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error(\"Invalid money bounds.\");\n const consumerValidate = overrides.validate;\n const validate: NumberField[\"validate\"] = (\n value: unknown, args: { required?: boolean } | undefined\n ) => {\n if (value === null || value === undefined || value === \"\") return args?.required ? \"\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.\" : true;\n 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.\";\n if (!options.allowNegative && value < 0) return \"\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.\";\n if (options.minMinorUnits !== undefined && value < options.minMinorUnits) return \"\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n if (options.maxMinorUnits !== undefined && value > options.maxMinorUnits) return \"\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n return consumerValidate\n ? (consumerValidate as (value: number, args: unknown) => string | true)(\n value, args\n )\n : true;\n };\n const display = {\n locale: \"fa-IR\", digits: \"persian\" as const, grouping: true, showCurrency: true, ...options.display,\n };\n return {\n ...overrides,\n name: options.name,\n type: \"number\",\n validate,\n admin: {\n ...overrides.admin,\n components: {\n ...overrides.admin?.components,\n Field: {\n path: \"@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent\",\n clientProps: {\n currency,\n display,\n allowNegative: options.allowNegative ?? false,\n },\n },\n },\n },\n custom: { ...overrides.custom, nexload: { ...(overrides.custom?.nexload as object), money: currency, }, },\n } as NumberField;\n}\n"],
5
+ "mappings": ";;;;AAEA,SAAS,YAAY,gBAAgB;AACrC,SAAS,WAAW,gBAAgB;;;ACqB7B,IAAM,MAAyC,EAAE,MAAM,OAAO,OAAO,4BAAQ,gBAAgB,EAAG;AAChG,IAAM,MAAyC,EAAE,MAAM,OAAO,OAAO,kCAAS,gBAAgB,EAAG;AAEjG,SAAS,gBAAiB,UAAkD;AACjF,QAAM,SAAS,aAAa,QAAQ,MAAM,aAAa,QAAQ,MAAM;AACrE,MACE,CAAC,OAAO,KAAK,KAAK,KACf,CAAC,OAAO,MAAM,KAAK,KACnB,CAAC,OAAO,UAAU,OAAO,cAAc,KACvC,OAAO,iBAAiB,KACxB,OAAO,iBAAiB,GAC3B,OAAM,IAAI,MAAM,oCAAoC;AACtD,SAAO;AACT;AAEA,SAAS,iBAAkB,OAAuB;AAChD,QAAM,UAAU;AAChB,QAAM,SAAS;AACf,SAAO,MAAM,KAAK,EAAE;AAAA,IAClB;AAAA,IAAa,CAAC,UAAU,OAAO,KAAK;AAAA,MAClC,QAAQ,QAAQ,KAAK;AAAA,MAAG,OAAO,QAAQ,KAAK;AAAA,IAC9C,IAAI,EAAE;AAAA,EACR,EACG;AAAA,IACC;AAAA,IAAW;AAAA,EACb,EACC;AAAA,IACC;AAAA,IAAM;AAAA,EACR;AACJ;AAEO,SAAS,uBACd,OAAe,UACP;AACR,QAAM,aAAa,gBAAgB,QAAQ;AAC3C,QAAM,QAAQ,iBAAiB,KAAK;AACpC,MAAI,CAAE,oBAAqB,KAAK,KAAK,EAAG,OAAM,IAAI,UAAU,sBAAsB;AAClF,QAAM,WAAW,MAAM,WAAW,GAAG;AACrC,QAAM;AAAA,IACJ;AAAA,IACA,WAAW;AAAA,EACb,KAAK,WAAW,MAAM,MAAM,CAAC,IAAI,OAAO,MAAM,GAAG;AACj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AO;AAAA,IACtD,KAAK,KACH,EAAE;AAAA,IAAG;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,CAAC,SAAiB;AAC/B,aAAS,IAAI;AACb,QAAI,CAAC,KAAK,KAAK,EAAG,QAAO,SAAS,IAAI;AACtC,QAAI;AACF,eAAS;AAAA,QACP;AAAA,QAAM;AAAA,MACR,CAAC;AAAA,IACH,QAAQ;AAAE,eAAS,IAAI;AAAA,IAAG;AAAA,EAC5B;AACA,SACE,qBAAC,SAAI,WAAU,0BACb;AAAA,wBAAC,cAAW,SAAS,SAAS,IAAI,IAAI,OAAO,MAAM,OAAO,UAAU,MAAM,UAAU;AAAA,IACpF;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QAAU,UAAU,CAAC,UAAU,OAAO,MAAM,OAAO,KAAK;AAAA,QAAG;AAAA,QACrE,OAAO;AAAA;AAAA,IACT;AAAA,IACA,oBAAC,UACE,mBAAS,OACZ;AAAA,KACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,135 @@
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:57.614Z)
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/admin/slug-field.tsx
23
+ var slug_field_exports = {};
24
+ __export(slug_field_exports, {
25
+ SlugFieldComponent: () => SlugFieldComponent
26
+ });
27
+ module.exports = __toCommonJS(slug_field_exports);
28
+ var import_ui = require("@payloadcms/ui");
29
+ var import_react = require("react");
30
+ var import_jsx_runtime = require("react/jsx-runtime");
31
+ var SlugFieldComponent = ({
32
+ field,
33
+ path,
34
+ source,
35
+ lockName,
36
+ generator,
37
+ readOnly
38
+ }) => {
39
+ const { value, setValue } = (0, import_ui.useField)({ path });
40
+ const { getDataByPath, dispatchFields } = (0, import_ui.useForm)();
41
+ const { config } = (0, import_ui.useConfig)();
42
+ const [
43
+ busy,
44
+ setBusy
45
+ ] = (0, import_react.useState)(false);
46
+ const parent = (0, import_react.useMemo)(
47
+ () => (path ?? field.name).split(".").slice(
48
+ 0,
49
+ -1
50
+ ),
51
+ [
52
+ field.name,
53
+ path
54
+ ]
55
+ );
56
+ const lockPath = [
57
+ ...parent,
58
+ lockName
59
+ ].join(".");
60
+ const locked = (0, import_ui.useFormFields)(([fields]) => {
61
+ var _a;
62
+ return Boolean((_a = fields[lockPath]) == null ? void 0 : _a.value);
63
+ });
64
+ const generate = (0, import_react.useCallback)(
65
+ async () => {
66
+ var _a;
67
+ const sourceValue = getDataByPath(source);
68
+ if (!generator || !sourceValue) return;
69
+ setBusy(true);
70
+ try {
71
+ const response = await fetch(
72
+ `${config.serverURL}${config.routes.api}/payload-fields/generate-slug`,
73
+ {
74
+ method: "POST",
75
+ headers: { "Content-Type": "application/json" },
76
+ body: JSON.stringify({ generator, sourceValue, currentSlug: value })
77
+ }
78
+ );
79
+ const payload = await response.json();
80
+ if (!response.ok || typeof payload.slug !== "string") throw new Error(((_a = payload.error) == null ? void 0 : _a.message) ?? "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.");
81
+ setValue(payload.slug);
82
+ } finally {
83
+ setBusy(false);
84
+ }
85
+ },
86
+ [
87
+ config.routes.api,
88
+ config.serverURL,
89
+ generator,
90
+ getDataByPath,
91
+ setValue,
92
+ source,
93
+ value
94
+ ]
95
+ );
96
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "field-type slug-field-component", children: [
97
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.FieldLabel, { htmlFor: `field-${path}`, label: field.label }),
98
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
100
+ import_ui.TextInput,
101
+ {
102
+ onChange: setValue,
103
+ path,
104
+ readOnly: Boolean(readOnly || locked),
105
+ value
106
+ }
107
+ ),
108
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
109
+ import_ui.Button,
110
+ {
111
+ buttonStyle: "none",
112
+ disabled: !generator || busy || readOnly,
113
+ onClick: () => void generate(),
114
+ type: "button",
115
+ children: "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF"
116
+ }
117
+ ),
118
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
119
+ import_ui.Button,
120
+ {
121
+ buttonStyle: "none",
122
+ disabled: readOnly,
123
+ onClick: () => dispatchFields({ type: "UPDATE", path: lockPath, value: !locked }),
124
+ type: "button",
125
+ children: locked ? "\u0642\u0641\u0644" : "\u0648\u06CC\u0631\u0627\u06CC\u0634"
126
+ }
127
+ )
128
+ ] })
129
+ ] });
130
+ };
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {
133
+ SlugFieldComponent
134
+ });
135
+ //# sourceMappingURL=slug-field.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/admin/slug-field.tsx"],
4
+ "sourcesContent": ["\"use client\";\n\nimport {\n Button, FieldLabel, TextInput, useConfig, useField, useForm, useFormFields\n} from \"@payloadcms/ui\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nimport type { TextFieldClientProps } from \"payload\";\n\ntype Props = { source: string, lockName: string, generator?: string };\n\nexport const SlugFieldComponent = ({\n field, path, source, lockName, generator, readOnly,\n}: TextFieldClientProps & Props) => {\n const { value, setValue, } = useField<string>({ path, });\n const { getDataByPath, dispatchFields, } = useForm();\n const { config, } = useConfig();\n const [\n busy,\n setBusy\n ] = useState(false);\n const parent = useMemo(\n () => (path ?? field.name).split(\".\").slice(\n 0, -1\n ), [\n field.name,\n path\n ]\n );\n const lockPath = [\n ...parent,\n lockName\n ].join(\".\");\n const locked = useFormFields(([fields]) => Boolean(fields[lockPath]?.value));\n const generate = useCallback(\n async () => {\n const sourceValue = getDataByPath(source) as string | undefined;\n if (!generator || !sourceValue) return;\n setBusy(true);\n try {\n const response = await fetch(\n `${config.serverURL}${config.routes.api}/payload-fields/generate-slug`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\", },\n body: JSON.stringify({ generator, sourceValue, currentSlug: value, }),\n }\n );\n const payload = await response.json() as { slug?: string, error?: { message?: string } };\n if (!response.ok || typeof payload.slug !== \"string\") throw new Error(payload.error?.message ?? \"\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.\");\n setValue(payload.slug);\n } finally { setBusy(false); }\n }, [\n config.routes.api,\n config.serverURL,\n generator,\n getDataByPath,\n setValue,\n source,\n value\n ]\n );\n return (\n <div className=\"field-type slug-field-component\">\n <FieldLabel htmlFor={`field-${path}`} label={field.label} />\n <div>\n <TextInput\n onChange={setValue} path={path} readOnly={Boolean(readOnly || locked)}\n value={value}\n />\n <Button\n buttonStyle=\"none\" disabled={!generator || busy || readOnly} onClick={() => void generate()}\n type=\"button\"\n >\n \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF\n </Button>\n <Button\n buttonStyle=\"none\" disabled={readOnly} onClick={() => dispatchFields({ type: \"UPDATE\", path: lockPath, value: !locked, })}\n type=\"button\"\n >\n {locked ? \"\u0642\u0641\u0644\" : \"\u0648\u06CC\u0631\u0627\u06CC\u0634\"}\n </Button>\n </div>\n </div>\n );\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAEO;AACP,mBAA+C;AA0DzC;AApDC,IAAM,qBAAqB,CAAC;AAAA,EACjC;AAAA,EAAO;AAAA,EAAM;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAW;AAC5C,MAAoC;AAClC,QAAM,EAAE,OAAO,SAAU,QAAI,oBAAiB,EAAE,KAAM,CAAC;AACvD,QAAM,EAAE,eAAe,eAAgB,QAAI,mBAAQ;AACnD,QAAM,EAAE,OAAQ,QAAI,qBAAU;AAC9B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EACF,QAAI,uBAAS,KAAK;AAClB,QAAM,aAAS;AAAA,IACb,OAAO,QAAQ,MAAM,MAAM,MAAM,GAAG,EAAE;AAAA,MACpC;AAAA,MAAG;AAAA,IACL;AAAA,IAAG;AAAA,MACD,MAAM;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACA,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH;AAAA,EACF,EAAE,KAAK,GAAG;AACV,QAAM,aAAS,yBAAc,CAAC,CAAC,MAAM,MAAG;AAjC1C;AAiC6C,oBAAQ,YAAO,QAAQ,MAAf,mBAAkB,KAAK;AAAA,GAAC;AAC3E,QAAM,eAAW;AAAA,IACf,YAAY;AAnChB;AAoCM,YAAM,cAAc,cAAc,MAAM;AACxC,UAAI,CAAC,aAAa,CAAC,YAAa;AAChC,cAAQ,IAAI;AACZ,UAAI;AACF,cAAM,WAAW,MAAM;AAAA,UACrB,GAAG,OAAO,SAAS,GAAG,OAAO,OAAO,GAAG;AAAA,UAAiC;AAAA,YACtE,QAAQ;AAAA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 lockName: string;
5
+ generator?: string;
6
+ };
7
+ export declare const SlugFieldComponent: ({ field, path, source, lockName, generator, readOnly, }: TextFieldClientProps & Props) => import("react/jsx-runtime").JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=slug-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug-field.d.ts","sourceRoot":"","sources":["../../src/admin/slug-field.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,KAAK,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE,eAAO,MAAM,kBAAkB,GAAI,yDAEhC,oBAAoB,GAAG,KAAK,4CAuE9B,CAAC"}
@@ -0,0 +1,115 @@
1
+ // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:56.848Z)
2
+ "use client";
3
+
4
+ // src/admin/slug-field.tsx
5
+ import {
6
+ Button,
7
+ FieldLabel,
8
+ TextInput,
9
+ useConfig,
10
+ useField,
11
+ useForm,
12
+ useFormFields
13
+ } from "@payloadcms/ui";
14
+ import { useCallback, useMemo, useState } from "react";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var SlugFieldComponent = ({
17
+ field,
18
+ path,
19
+ source,
20
+ lockName,
21
+ generator,
22
+ readOnly
23
+ }) => {
24
+ const { value, setValue } = useField({ path });
25
+ const { getDataByPath, dispatchFields } = useForm();
26
+ const { config } = useConfig();
27
+ const [
28
+ busy,
29
+ setBusy
30
+ ] = useState(false);
31
+ const parent = useMemo(
32
+ () => (path ?? field.name).split(".").slice(
33
+ 0,
34
+ -1
35
+ ),
36
+ [
37
+ field.name,
38
+ path
39
+ ]
40
+ );
41
+ const lockPath = [
42
+ ...parent,
43
+ lockName
44
+ ].join(".");
45
+ const locked = useFormFields(([fields]) => Boolean(fields[lockPath]?.value));
46
+ const generate = useCallback(
47
+ async () => {
48
+ const sourceValue = getDataByPath(source);
49
+ if (!generator || !sourceValue) return;
50
+ setBusy(true);
51
+ try {
52
+ const response = await fetch(
53
+ `${config.serverURL}${config.routes.api}/payload-fields/generate-slug`,
54
+ {
55
+ method: "POST",
56
+ headers: { "Content-Type": "application/json" },
57
+ body: JSON.stringify({ generator, sourceValue, currentSlug: value })
58
+ }
59
+ );
60
+ const payload = await response.json();
61
+ if (!response.ok || typeof payload.slug !== "string") throw new Error(payload.error?.message ?? "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.");
62
+ setValue(payload.slug);
63
+ } finally {
64
+ setBusy(false);
65
+ }
66
+ },
67
+ [
68
+ config.routes.api,
69
+ config.serverURL,
70
+ generator,
71
+ getDataByPath,
72
+ setValue,
73
+ source,
74
+ value
75
+ ]
76
+ );
77
+ return /* @__PURE__ */ jsxs("div", { className: "field-type slug-field-component", children: [
78
+ /* @__PURE__ */ jsx(FieldLabel, { htmlFor: `field-${path}`, label: field.label }),
79
+ /* @__PURE__ */ jsxs("div", { children: [
80
+ /* @__PURE__ */ jsx(
81
+ TextInput,
82
+ {
83
+ onChange: setValue,
84
+ path,
85
+ readOnly: Boolean(readOnly || locked),
86
+ value
87
+ }
88
+ ),
89
+ /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ buttonStyle: "none",
93
+ disabled: !generator || busy || readOnly,
94
+ onClick: () => void generate(),
95
+ type: "button",
96
+ children: "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF"
97
+ }
98
+ ),
99
+ /* @__PURE__ */ jsx(
100
+ Button,
101
+ {
102
+ buttonStyle: "none",
103
+ disabled: readOnly,
104
+ onClick: () => dispatchFields({ type: "UPDATE", path: lockPath, value: !locked }),
105
+ type: "button",
106
+ children: locked ? "\u0642\u0641\u0644" : "\u0648\u06CC\u0631\u0627\u06CC\u0634"
107
+ }
108
+ )
109
+ ] })
110
+ ] });
111
+ };
112
+ export {
113
+ SlugFieldComponent
114
+ };
115
+ //# sourceMappingURL=slug-field.mjs.map