@nexload-sdk/payload-fields 1.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 +158 -0
- package/dist/date/date-cell.cjs +3 -0
- package/dist/date/date-cell.cjs.map +7 -0
- package/dist/date/date-cell.d.ts +7 -0
- package/dist/date/date-cell.d.ts.map +1 -0
- package/dist/date/date-cell.mjs +3 -0
- package/dist/date/date-cell.mjs.map +7 -0
- package/dist/date/date-picker.cjs +72 -0
- package/dist/date/date-picker.cjs.map +7 -0
- package/dist/date/date-picker.d.ts +5 -0
- package/dist/date/date-picker.d.ts.map +1 -0
- package/dist/date/date-picker.mjs +72 -0
- package/dist/date/date-picker.mjs.map +7 -0
- package/dist/date/format-date.d.ts +2 -0
- package/dist/date/format-date.d.ts.map +1 -0
- package/dist/date/index.d.ts +5 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +7 -0
- package/dist/slug/format-slug.d.ts +4 -0
- package/dist/slug/format-slug.d.ts.map +1 -0
- package/dist/slug/index.d.ts +9 -0
- package/dist/slug/index.d.ts.map +1 -0
- package/dist/slug/slug-field.cjs +17 -0
- package/dist/slug/slug-field.cjs.map +7 -0
- package/dist/slug/slug-field.d.ts +10 -0
- package/dist/slug/slug-field.d.ts.map +1 -0
- package/dist/slug/slug-field.mjs +17 -0
- package/dist/slug/slug-field.mjs.map +7 -0
- package/package.json +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
# @nexload-sdk/payload-fields
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<img src="https://img.shields.io/badge/Payload%20CMS-Fields-blueviolet?style=flat-square" alt="Payload CMS Fields" />
|
|
6
|
+
<img src="https://img.shields.io/badge/types-typescript-blue?style=flat-square" alt="typescript" />
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@nexload-sdk/payload-fields?style=flat-square" alt="npm version" />
|
|
8
|
+
<br><br>
|
|
9
|
+
<strong>A collection of powerful, production-ready, and beautifully designed fields for Payload CMS.</strong>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- 🎨 **Enhanced UX:** Custom React components for a polished and intuitive admin experience.
|
|
17
|
+
- 🚀 **Production-Ready:** Pre-configured with smart defaults for common use cases.
|
|
18
|
+
- 🇮🇷 **i18n-Ready:** Default labels are in Persian, but easily customizable.
|
|
19
|
+
- 🧩 **Composable & Extensible:** Easily override or extend any field configuration.
|
|
20
|
+
- ✍️ **Advanced Rich Text Editor:** A pre-configured Lexical editor with features like a fixed toolbar, tables, and more.
|
|
21
|
+
- 🗓️ **Sophisticated Date Field:** A sidebar-ready date field with a custom Persian calendar picker.
|
|
22
|
+
- 🔗 **Automatic Slug Field:** An intelligent slug field that auto-generates from a title field and includes a lock/unlock feature.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @nexload-sdk/payload-fields
|
|
30
|
+
# or
|
|
31
|
+
yarn add @nexload-sdk/payload-fields
|
|
32
|
+
# or
|
|
33
|
+
npm install @nexload-sdk/payload-fields
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
This package provides drop-in fields and an editor for your Payload CMS collections.
|
|
41
|
+
|
|
42
|
+
### 1. `dateField`
|
|
43
|
+
|
|
44
|
+
A sidebar-ready date field with a beautiful Persian date picker.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { dateField } from '@nexload-sdk/payload-fields';
|
|
48
|
+
import type { CollectionConfig } from 'payload/types';
|
|
49
|
+
|
|
50
|
+
const Posts: CollectionConfig = {
|
|
51
|
+
slug: 'posts',
|
|
52
|
+
fields: [
|
|
53
|
+
{
|
|
54
|
+
name: 'title',
|
|
55
|
+
type: 'text',
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
// Add the date field to the sidebar
|
|
59
|
+
...dateField(),
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. `slugField`
|
|
65
|
+
|
|
66
|
+
A smart slug field that automatically generates its value from another field (e.g., `title`). It appears in the sidebar and includes a "lock" to prevent accidental changes.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { slugField } from '@nexload-sdk/payload-fields';
|
|
70
|
+
import type { CollectionConfig } from 'payload/types';
|
|
71
|
+
|
|
72
|
+
const Articles: CollectionConfig = {
|
|
73
|
+
slug: 'articles',
|
|
74
|
+
fields: [
|
|
75
|
+
{
|
|
76
|
+
name: 'title',
|
|
77
|
+
type: 'text',
|
|
78
|
+
required: true,
|
|
79
|
+
},
|
|
80
|
+
// Creates 'slug' and 'slugLock' fields
|
|
81
|
+
// The slug is generated from the 'title' field by default
|
|
82
|
+
...slugField('title'),
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. `editor`
|
|
88
|
+
|
|
89
|
+
A feature-rich Lexical rich text editor.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { editor } from '@nexload-sdk/payload-fields';
|
|
93
|
+
import type { CollectionConfig } from 'payload/types';
|
|
94
|
+
|
|
95
|
+
const Pages: CollectionConfig = {
|
|
96
|
+
slug: 'pages',
|
|
97
|
+
fields: [
|
|
98
|
+
{
|
|
99
|
+
name: 'content',
|
|
100
|
+
type: 'richText',
|
|
101
|
+
editor: editor, // Use the pre-configured editor
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## API Reference
|
|
110
|
+
|
|
111
|
+
| Export | Type | Description |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| `dateField` | `(overrides?: DateField) => [DateField]` | A function that returns a sidebar-ready `date` field config. You can pass standard Payload `DateField` properties to override the defaults. |
|
|
114
|
+
| `slugField` | `(fieldToUse?: string, overrides?: Overrides) => [TextField, CheckboxField]` | A function that returns `slug` and `slugLock` field configs. Specify which field to use for generation (defaults to `title`). |
|
|
115
|
+
| `editor` | `RichTextAdapterProvider` | A pre-configured Lexical editor instance with enhanced features. |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Customization
|
|
120
|
+
|
|
121
|
+
All field functions allow you to pass an `overrides` object to customize their behavior, labels, or any other property, just like you would with a standard Payload field.
|
|
122
|
+
|
|
123
|
+
#### Overriding the `dateField` label:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
...dateField({
|
|
127
|
+
label: 'Publish Date',
|
|
128
|
+
admin: {
|
|
129
|
+
position: 'top',
|
|
130
|
+
}
|
|
131
|
+
}),
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### Overriding the `slugField` name and the field it uses:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
...slugField('headline', {
|
|
138
|
+
slugOverrides: {
|
|
139
|
+
name: 'articleSlug',
|
|
140
|
+
label: 'Article Slug',
|
|
141
|
+
},
|
|
142
|
+
checkboxOverrides: {
|
|
143
|
+
name: 'isSlugLocked',
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT © GecutWeb Contributors
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Branding
|
|
157
|
+
|
|
158
|
+
Built by [NexLoad SDK](https://github.com/gecut/nexload-sdk) · High-quality, reusable components and tools for modern web development.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.602Z)
|
|
2
|
+
"use strict";"use client";var f=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(t,r)=>{for(var e in r)f(t,e,{get:r[e],enumerable:!0})},g=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of c(r))!l.call(t,a)&&a!==e&&f(t,a,{get:()=>r[a],enumerable:!(n=s(r,a))||n.enumerable});return t};var D=t=>g(f({},"__esModule",{value:!0}),t);var E={};p(E,{DateCell:()=>u});module.exports=D(E);var i=require("date-fns-jalali");function m(t){if(!t)return"";let r=typeof t=="string"?new Date(t):t,e;try{e=(0,i.format)(r,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(n){console.error("error formatting date:",n),e=r.toLocaleDateString("fa-IR")}return e}var o=require("react/jsx-runtime"),u=({cellData:t})=>t?(0,o.jsx)(o.Fragment,{children:m(t)}):(0,o.jsx)(o.Fragment,{children:"\u2014"});0&&(module.exports={DateCell});
|
|
3
|
+
//# sourceMappingURL=date-cell.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/date/date-cell.tsx", "../../src/date/format-date.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport React from \"react\";\n\nimport { formatDate } from \"./format-date\";\n\ninterface Props { cellData?: string | Date | null }\n\nexport const DateCell: React.FC<Props> = ({ cellData, }) => {\n if (!cellData) return <>\u2014</>;\n\n return (\n <>\n {formatDate(cellData)}\n </>\n );\n};\n", "import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n"],
|
|
5
|
+
"mappings": ";sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAuC,2BAEhC,SAASC,EAAYC,EAA+B,CACzD,GAAI,CAACA,EAAO,MAAO,GAEnB,IAAMC,EAAO,OAAOD,GAAU,SAAW,IAAI,KAAKA,CAAK,EAAIA,EAEvDE,EACJ,GAAI,CACFA,KAAY,EAAAC,QACVF,EAAM,8CACR,CACF,OAASG,EAAK,CAEZ,QAAQ,MACN,yBAA0BA,CAC5B,EAEAF,EAAYD,EAAK,mBAAmB,OAAO,CAC7C,CAEA,OAAOC,CACT,CDbwB,IAAAG,EAAA,6BADXC,EAA4B,CAAC,CAAE,SAAAC,CAAU,IAC/CA,KAGH,mBACG,SAAAC,EAAWD,CAAQ,EACtB,KALoB,mBAAE,kBAAC",
|
|
6
|
+
"names": ["date_cell_exports", "__export", "DateCell", "__toCommonJS", "import_date_fns_jalali", "formatDate", "_date", "date", "formatted", "formatJalali", "err", "import_jsx_runtime", "DateCell", "cellData", "formatDate"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-cell.d.ts","sourceRoot":"","sources":["../../src/date/date-cell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,UAAU,KAAK;IAAG,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;CAAE;AAEnD,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAQpC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.585Z)
|
|
2
|
+
"use client";import{format as i}from"date-fns-jalali";function o(t){if(!t)return"";let e=typeof t=="string"?new Date(t):t,r;try{r=i(e,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(f){console.error("error formatting date:",f),r=e.toLocaleDateString("fa-IR")}return r}import{Fragment as a,jsx as n}from"react/jsx-runtime";var l=({cellData:t})=>t?n(a,{children:o(t)}):n(a,{children:"\u2014"});export{l as DateCell};
|
|
3
|
+
//# sourceMappingURL=date-cell.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/date/format-date.ts", "../../src/date/date-cell.tsx"],
|
|
4
|
+
"sourcesContent": ["import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n", "\"use client\";\n\nimport React from \"react\";\n\nimport { formatDate } from \"./format-date\";\n\ninterface Props { cellData?: string | Date | null }\n\nexport const DateCell: React.FC<Props> = ({ cellData, }) => {\n if (!cellData) return <>\u2014</>;\n\n return (\n <>\n {formatDate(cellData)}\n </>\n );\n};\n"],
|
|
5
|
+
"mappings": ";aAAA,OAAS,UAAUA,MAAoB,kBAEhC,SAASC,EAAYC,EAA+B,CACzD,GAAI,CAACA,EAAO,MAAO,GAEnB,IAAMC,EAAO,OAAOD,GAAU,SAAW,IAAI,KAAKA,CAAK,EAAIA,EAEvDE,EACJ,GAAI,CACFA,EAAYJ,EACVG,EAAM,8CACR,CACF,OAASE,EAAK,CAEZ,QAAQ,MACN,yBAA0BA,CAC5B,EAEAD,EAAYD,EAAK,mBAAmB,OAAO,CAC7C,CAEA,OAAOC,CACT,CCbwB,mBAAAE,EAAA,OAAAC,MAAA,oBADjB,IAAMC,EAA4B,CAAC,CAAE,SAAAC,CAAU,IAC/CA,EAGHF,EAAAD,EAAA,CACG,SAAAI,EAAWD,CAAQ,EACtB,EALoBF,EAAAD,EAAA,CAAE,kBAAC",
|
|
6
|
+
"names": ["formatJalali", "formatDate", "_date", "date", "formatted", "err", "Fragment", "jsx", "DateCell", "cellData", "formatDate"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.602Z)
|
|
2
|
+
"use strict";"use client";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var Z=(e,i)=>{for(var a in i)c(e,a,{get:i[a],enumerable:!0})},W=(e,i,a,I)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of A(i))!G.call(e,t)&&t!==a&&c(e,t,{get:()=>i[t],enumerable:!(I=u(i,t))||I.enumerable});return e};var X=e=>W(c({},"__esModule",{value:!0}),e);var F={};Z(F,{DatePicker:()=>h});module.exports=X(F);var C=require("@payloadcms/ui"),n=require("react"),s=require("react-day-picker/persian"),v=require("react-day-picker/style.css");var m=require("date-fns-jalali");function p(e){if(!e)return"";let i=typeof e=="string"?new Date(e):e,a;try{a=(0,m.format)(i,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(I){console.error("error formatting date:",I),a=i.toLocaleDateString("fa-IR")}return a}var B=`.jalali-date-field {
|
|
3
|
+
position: relative;
|
|
4
|
+
}
|
|
5
|
+
.jalali-date-field:focus-within > .jalali-date-picker {
|
|
6
|
+
max-height: 32rem;
|
|
7
|
+
min-height: 30rem;
|
|
8
|
+
padding: 1rem;
|
|
9
|
+
border: 1px solid var(--theme-elevation-150);
|
|
10
|
+
box-shadow: 0 1.5rem 3rem -2rem var(--theme-elevation-250);
|
|
11
|
+
opacity: 1;
|
|
12
|
+
}
|
|
13
|
+
.jalali-date-field .jalali-date-picker {
|
|
14
|
+
max-height: 0rem;
|
|
15
|
+
min-height: 0rem;
|
|
16
|
+
padding: 0rem;
|
|
17
|
+
border: 0px solid var(--theme-elevation-150);
|
|
18
|
+
box-shadow: 0 0 0 0 var(--theme-elevation-250);
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transition: box-shadow 0.3s ease-in-out, max-height 0.6s ease-in-out, min-height 0.3s ease-in-out, padding 0.1s ease-in-out, border 0.1s ease-in-out, opacity 0.15s ease-in-out;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
position: absolute;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
border-radius: var(--style-radius-l);
|
|
28
|
+
top: 110%;
|
|
29
|
+
font-family: var(--font-body);
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 100%;
|
|
32
|
+
min-width: 26rem;
|
|
33
|
+
max-width: 28rem;
|
|
34
|
+
z-index: 9999;
|
|
35
|
+
background: var(--theme-input-bg);
|
|
36
|
+
right: 50%;
|
|
37
|
+
translate: 50% 0;
|
|
38
|
+
}
|
|
39
|
+
@supports (backdrop-filter: blur(0.1rem)) {
|
|
40
|
+
.jalali-date-field .jalali-date-picker {
|
|
41
|
+
backdrop-filter: blur(1.5rem);
|
|
42
|
+
background: var(--theme-elevation-150)/40%;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
gap: 0.5rem;
|
|
50
|
+
width: 100%;
|
|
51
|
+
}
|
|
52
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input span {
|
|
53
|
+
font-size: 3rem;
|
|
54
|
+
}
|
|
55
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input {
|
|
56
|
+
-moz-appearance: textfield;
|
|
57
|
+
appearance: textfield;
|
|
58
|
+
text-align: center;
|
|
59
|
+
flex-grow: 1;
|
|
60
|
+
font-size: 1.5rem;
|
|
61
|
+
padding: 0.5rem;
|
|
62
|
+
border: 1px solid var(--theme-elevation-150);
|
|
63
|
+
border-radius: var(--style-radius-l);
|
|
64
|
+
}
|
|
65
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-outer-spin-button,
|
|
66
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-inner-spin-button {
|
|
67
|
+
/* display: none; <- Crashes Chrome on hover */
|
|
68
|
+
-webkit-appearance: none;
|
|
69
|
+
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
|
|
70
|
+
}
|
|
71
|
+
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvZGF0ZSIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFOztBQUVBO0VBQ0U7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBRUEsWUFDRTtFQU9GO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUVBO0VBQ0E7O0FBRUE7RUFuQ0Y7SUFvQ0k7SUFDQTs7O0FBR0Y7RUFDRTtFQUNBO0VBQ0E7RUFDQTtFQUNBOztBQUVBO0VBQ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0IHtcbiAgICAgICAgLW1vei1hcHBlYXJhbmNlOiB0ZXh0ZmllbGQ7XG4gICAgICAgIGFwcGVhcmFuY2U6IHRleHRmaWVsZDtcblxuICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG4gICAgICAgIGZsZXgtZ3JvdzogMTtcbiAgICAgICAgZm9udC1zaXplOiAxLjVyZW07XG4gICAgICAgIHBhZGRpbmc6IDAuNXJlbTtcbiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgdmFyKC0tdGhlbWUtZWxldmF0aW9uLTE1MCk7XG4gICAgICAgIGJvcmRlci1yYWRpdXM6IHZhcigtLXN0eWxlLXJhZGl1cy1sKTtcbiAgICAgIH1cblxuICAgICAgaW5wdXQ6Oi13ZWJraXQtb3V0ZXItc3Bpbi1idXR0b24sXG4gICAgICBpbnB1dDo6LXdlYmtpdC1pbm5lci1zcGluLWJ1dHRvbiB7XG4gICAgICAgIC8qIGRpc3BsYXk6IG5vbmU7IDwtIENyYXNoZXMgQ2hyb21lIG9uIGhvdmVyICovXG4gICAgICAgIC13ZWJraXQtYXBwZWFyYW5jZTogbm9uZTtcbiAgICAgICAgbWFyZ2luOiAwOyAvKiA8LS0gQXBwYXJlbnRseSBzb21lIG1hcmdpbiBhcmUgc3RpbGwgdGhlcmUgZXZlbiB0aG91Z2ggaXQncyBoaWRkZW4gKi9cbiAgICAgIH1cbiAgICB9XG4gIH1cbn1cbiJdfQ== */`;document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(B));var l=require("react/jsx-runtime"),h=({path:e,field:{label:i}})=>{let{value:a,setValue:I}=(0,C.useField)({path:e}),[t,b]=(0,n.useState)(void 0);(0,n.useEffect)(()=>{a&&b(new Date(a))},[a]);let o=g=>{b(g),g&&I(g.toISOString())};return(0,l.jsxs)("div",{className:"field-type text jalali-date-field",tabIndex:0,children:[i&&(0,l.jsx)("label",{className:"field-label",htmlFor:e,children:String(i)}),(0,l.jsx)("input",{readOnly:!0,type:"text",value:(a&&p(a))??void 0}),(0,l.jsxs)("div",{className:"jalali-date-picker",children:[(0,l.jsx)(s.DayPicker,{animate:!0,captionLayout:"dropdown",mode:"single",navLayout:"around",onSelect:o,required:!1,selected:t,showOutsideDays:!0}),(0,l.jsx)("hr",{}),(0,l.jsxs)("div",{className:"jalali-date-picker-input",children:[(0,l.jsx)("input",{max:59,min:0,onInput:g=>{if(!t)return;let r=g.target,d=new Date(t);d.setMinutes(r.valueAsNumber),o(d)},type:"number",value:(t==null?void 0:t.getMinutes())??0}),(0,l.jsx)("span",{children:":"}),(0,l.jsx)("input",{max:23,min:0,onInput:g=>{if(!t)return;let r=g.target,d=new Date(t);d.setHours(r.valueAsNumber),o(d)},type:"number",value:(t==null?void 0:t.getHours())??0})]})]})]})};0&&(module.exports={DatePicker});
|
|
72
|
+
//# sourceMappingURL=date-picker.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/date/date-picker.tsx", "../../src/date/format-date.ts", "../../src/date/index.scss"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { useField } from \"@payloadcms/ui\";\nimport { useEffect, useState } from \"react\";\nimport { DayPicker } from \"react-day-picker/persian\";\nimport \"react-day-picker/style.css\";\n\nimport { formatDate } from \"./format-date\";\nimport \"./index.scss\";\n\nimport type { DateFieldClientComponent } from \"payload\";\n\nexport const DatePicker: DateFieldClientComponent = ({\n path,\n field: { label, },\n}) => {\n const { value, setValue, } = useField<string | null>({ path, });\n const [\n selected,\n setSelected\n ] = useState<Date | undefined>(undefined);\n\n // init from value (edit mode)\n useEffect(\n () => {\n if (value) {\n setSelected(new Date(value));\n }\n }, [value]\n );\n\n const handleChange = (date: Date | undefined) => {\n setSelected(date);\n\n if (date) {\n setValue(date.toISOString());\n }\n };\n\n return (\n <div className=\"field-type text jalali-date-field\" tabIndex={0}>\n {label && (\n <label className=\"field-label\" htmlFor={path}>\n {String(label)}\n </label>\n )}\n <input\n readOnly\n type=\"text\"\n value={(value && formatDate(value)) ?? undefined}\n />\n <div className=\"jalali-date-picker\">\n <DayPicker\n animate\n captionLayout=\"dropdown\"\n mode=\"single\"\n navLayout=\"around\"\n onSelect={handleChange}\n required={false}\n selected={selected}\n showOutsideDays\n />\n <hr />\n <div className=\"jalali-date-picker-input\">\n <input\n max={59}\n min={0}\n onInput={(e) => {\n if (!selected) return;\n const target = e.target as HTMLInputElement;\n const newDate = new Date(selected);\n\n newDate.setMinutes(target.valueAsNumber);\n\n handleChange(newDate);\n }}\n type=\"number\"\n value={selected?.getMinutes() ?? 0}\n />\n <span>:</span>\n <input\n max={23}\n min={0}\n onInput={(e) => {\n if (!selected) return;\n const target = e.target as HTMLInputElement;\n const newDate = new Date(selected);\n\n newDate.setHours(target.valueAsNumber);\n\n handleChange(newDate);\n }}\n type=\"number\"\n value={selected?.getHours() ?? 0}\n />\n </div>\n </div>\n {/* {required && !selected && (\n <p className=\"field-error\">\u0644\u0637\u0641\u0627 \u062A\u0627\u0631\u06CC\u062E \u0631\u0627 \u0627\u0646\u062A\u062E\u0627\u0628 \u06A9\u0646\u06CC\u062F</p>\n )} */}\n </div>\n );\n};\n", "import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n", "const css = `.jalali-date-field {\n position: relative;\n}\n.jalali-date-field:focus-within > .jalali-date-picker {\n max-height: 32rem;\n min-height: 30rem;\n padding: 1rem;\n border: 1px solid var(--theme-elevation-150);\n box-shadow: 0 1.5rem 3rem -2rem var(--theme-elevation-250);\n opacity: 1;\n}\n.jalali-date-field .jalali-date-picker {\n max-height: 0rem;\n min-height: 0rem;\n padding: 0rem;\n border: 0px solid var(--theme-elevation-150);\n box-shadow: 0 0 0 0 var(--theme-elevation-250);\n opacity: 0;\n transition: box-shadow 0.3s ease-in-out, max-height 0.6s ease-in-out, min-height 0.3s ease-in-out, padding 0.1s ease-in-out, border 0.1s ease-in-out, opacity 0.15s ease-in-out;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: absolute;\n overflow: hidden;\n border-radius: var(--style-radius-l);\n top: 110%;\n font-family: var(--font-body);\n width: 100%;\n height: 100%;\n min-width: 26rem;\n max-width: 28rem;\n z-index: 9999;\n background: var(--theme-input-bg);\n right: 50%;\n translate: 50% 0;\n}\n@supports (backdrop-filter: blur(0.1rem)) {\n .jalali-date-field .jalali-date-picker {\n backdrop-filter: blur(1.5rem);\n background: var(--theme-elevation-150)/40%;\n }\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 0.5rem;\n width: 100%;\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input span {\n font-size: 3rem;\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input {\n -moz-appearance: textfield;\n appearance: textfield;\n text-align: center;\n flex-grow: 1;\n font-size: 1.5rem;\n padding: 0.5rem;\n border: 1px solid var(--theme-elevation-150);\n border-radius: var(--style-radius-l);\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-outer-spin-button,\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-inner-spin-button {\n /* display: none; <- Crashes Chrome on hover */\n -webkit-appearance: none;\n margin: 0; /* <-- Apparently some margin are still there even though it's hidden */\n}\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9w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a,EAErCJ,EAAaK,CAAO,CACtB,EACA,KAAK,SACL,OAAOP,GAAA,YAAAA,EAAU,aAAc,EACjC,GACF,GACF,GAIF,CAEJ",
|
|
6
|
+
"names": ["date_picker_exports", "__export", "DatePicker", "__toCommonJS", "import_ui", "import_react", "import_persian", "import_style", "import_date_fns_jalali", "formatDate", "_date", "date", "formatted", "formatJalali", "err", "css", "import_jsx_runtime", "DatePicker", "path", "label", "value", "setValue", "selected", "setSelected", "handleChange", "date", "formatDate", "e", "target", "newDate"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../src/date/date-picker.tsx"],"names":[],"mappings":"AAKA,OAAO,4BAA4B,CAAC;AAGpC,OAAO,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,eAAO,MAAM,UAAU,EAAE,wBA0FxB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.585Z)
|
|
2
|
+
"use client";import{useField as s}from"@payloadcms/ui";import{useEffect as C,useState as u}from"react";import{DayPicker as A}from"react-day-picker/persian";import"react-day-picker/style.css";import{format as m}from"date-fns-jalali";function b(t){if(!t)return"";let g=typeof t=="string"?new Date(t):t,e;try{e=m(g,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(I){console.error("error formatting date:",I),e=g.toLocaleDateString("fa-IR")}return e}var p=`.jalali-date-field {
|
|
3
|
+
position: relative;
|
|
4
|
+
}
|
|
5
|
+
.jalali-date-field:focus-within > .jalali-date-picker {
|
|
6
|
+
max-height: 32rem;
|
|
7
|
+
min-height: 30rem;
|
|
8
|
+
padding: 1rem;
|
|
9
|
+
border: 1px solid var(--theme-elevation-150);
|
|
10
|
+
box-shadow: 0 1.5rem 3rem -2rem var(--theme-elevation-250);
|
|
11
|
+
opacity: 1;
|
|
12
|
+
}
|
|
13
|
+
.jalali-date-field .jalali-date-picker {
|
|
14
|
+
max-height: 0rem;
|
|
15
|
+
min-height: 0rem;
|
|
16
|
+
padding: 0rem;
|
|
17
|
+
border: 0px solid var(--theme-elevation-150);
|
|
18
|
+
box-shadow: 0 0 0 0 var(--theme-elevation-250);
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transition: box-shadow 0.3s ease-in-out, max-height 0.6s ease-in-out, min-height 0.3s ease-in-out, padding 0.1s ease-in-out, border 0.1s ease-in-out, opacity 0.15s ease-in-out;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
position: absolute;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
border-radius: var(--style-radius-l);
|
|
28
|
+
top: 110%;
|
|
29
|
+
font-family: var(--font-body);
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 100%;
|
|
32
|
+
min-width: 26rem;
|
|
33
|
+
max-width: 28rem;
|
|
34
|
+
z-index: 9999;
|
|
35
|
+
background: var(--theme-input-bg);
|
|
36
|
+
right: 50%;
|
|
37
|
+
translate: 50% 0;
|
|
38
|
+
}
|
|
39
|
+
@supports (backdrop-filter: blur(0.1rem)) {
|
|
40
|
+
.jalali-date-field .jalali-date-picker {
|
|
41
|
+
backdrop-filter: blur(1.5rem);
|
|
42
|
+
background: var(--theme-elevation-150)/40%;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
gap: 0.5rem;
|
|
50
|
+
width: 100%;
|
|
51
|
+
}
|
|
52
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input span {
|
|
53
|
+
font-size: 3rem;
|
|
54
|
+
}
|
|
55
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input {
|
|
56
|
+
-moz-appearance: textfield;
|
|
57
|
+
appearance: textfield;
|
|
58
|
+
text-align: center;
|
|
59
|
+
flex-grow: 1;
|
|
60
|
+
font-size: 1.5rem;
|
|
61
|
+
padding: 0.5rem;
|
|
62
|
+
border: 1px solid var(--theme-elevation-150);
|
|
63
|
+
border-radius: var(--style-radius-l);
|
|
64
|
+
}
|
|
65
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-outer-spin-button,
|
|
66
|
+
.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-inner-spin-button {
|
|
67
|
+
/* display: none; <- Crashes Chrome on hover */
|
|
68
|
+
-webkit-appearance: none;
|
|
69
|
+
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
|
|
70
|
+
}
|
|
71
|
+
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvZGF0ZSIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFOztBQUVBO0VBQ0U7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBRUEsWUFDRTtFQU9GO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUVBO0VBQ0E7O0FBRUE7RUFuQ0Y7SUFvQ0k7SUFDQTs7O0FBR0Y7RUFDRTtFQUNBO0VBQ0E7RUFDQTtFQUNBOztBQUVBO0VBQ0U7O0FBR0Y7RUFDRTtFQUNBO0VBRUE7RUFDQTtFQUNBO0VBQ0E7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G4gICAgICAgIGFwcGVhcmFuY2U6IHRleHRmaWVsZDtcblxuICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG4gICAgICAgIGZsZXgtZ3JvdzogMTtcbiAgICAgICAgZm9udC1zaXplOiAxLjVyZW07XG4gICAgICAgIHBhZGRpbmc6IDAuNXJlbTtcbiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgdmFyKC0tdGhlbWUtZWxldmF0aW9uLTE1MCk7XG4gICAgICAgIGJvcmRlci1yYWRpdXM6IHZhcigtLXN0eWxlLXJhZGl1cy1sKTtcbiAgICAgIH1cblxuICAgICAgaW5wdXQ6Oi13ZWJraXQtb3V0ZXItc3Bpbi1idXR0b24sXG4gICAgICBpbnB1dDo6LXdlYmtpdC1pbm5lci1zcGluLWJ1dHRvbiB7XG4gICAgICAgIC8qIGRpc3BsYXk6IG5vbmU7IDwtIENyYXNoZXMgQ2hyb21lIG9uIGhvdmVyICovXG4gICAgICAgIC13ZWJraXQtYXBwZWFyYW5jZTogbm9uZTtcbiAgICAgICAgbWFyZ2luOiAwOyAvKiA8LS0gQXBwYXJlbnRseSBzb21lIG1hcmdpbiBhcmUgc3RpbGwgdGhlcmUgZXZlbiB0aG91Z2ggaXQncyBoaWRkZW4gKi9cbiAgICAgIH1cbiAgICB9XG4gIH1cbn1cbiJdfQ== */`;document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(p));import{jsx as l,jsxs as r}from"react/jsx-runtime";var y=({path:t,field:{label:g}})=>{let{value:e,setValue:I}=s({path:t}),[i,c]=u(void 0);C(()=>{e&&c(new Date(e))},[e]);let n=a=>{c(a),a&&I(a.toISOString())};return r("div",{className:"field-type text jalali-date-field",tabIndex:0,children:[g&&l("label",{className:"field-label",htmlFor:t,children:String(g)}),l("input",{readOnly:!0,type:"text",value:(e&&b(e))??void 0}),r("div",{className:"jalali-date-picker",children:[l(A,{animate:!0,captionLayout:"dropdown",mode:"single",navLayout:"around",onSelect:n,required:!1,selected:i,showOutsideDays:!0}),l("hr",{}),r("div",{className:"jalali-date-picker-input",children:[l("input",{max:59,min:0,onInput:a=>{if(!i)return;let o=a.target,d=new Date(i);d.setMinutes(o.valueAsNumber),n(d)},type:"number",value:i?.getMinutes()??0}),l("span",{children:":"}),l("input",{max:23,min:0,onInput:a=>{if(!i)return;let o=a.target,d=new Date(i);d.setHours(o.valueAsNumber),n(d)},type:"number",value:i?.getHours()??0})]})]})]})};export{y as DatePicker};
|
|
72
|
+
//# sourceMappingURL=date-picker.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/date/date-picker.tsx", "../../src/date/format-date.ts", "../../src/date/index.scss"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { useField } from \"@payloadcms/ui\";\nimport { useEffect, useState } from \"react\";\nimport { DayPicker } from \"react-day-picker/persian\";\nimport \"react-day-picker/style.css\";\n\nimport { formatDate } from \"./format-date\";\nimport \"./index.scss\";\n\nimport type { DateFieldClientComponent } from \"payload\";\n\nexport const DatePicker: DateFieldClientComponent = ({\n path,\n field: { label, },\n}) => {\n const { value, setValue, } = useField<string | null>({ path, });\n const [\n selected,\n setSelected\n ] = useState<Date | undefined>(undefined);\n\n // init from value (edit mode)\n useEffect(\n () => {\n if (value) {\n setSelected(new Date(value));\n }\n }, [value]\n );\n\n const handleChange = (date: Date | undefined) => {\n setSelected(date);\n\n if (date) {\n setValue(date.toISOString());\n }\n };\n\n return (\n <div className=\"field-type text jalali-date-field\" tabIndex={0}>\n {label && (\n <label className=\"field-label\" htmlFor={path}>\n {String(label)}\n </label>\n )}\n <input\n readOnly\n type=\"text\"\n value={(value && formatDate(value)) ?? undefined}\n />\n <div className=\"jalali-date-picker\">\n <DayPicker\n animate\n captionLayout=\"dropdown\"\n mode=\"single\"\n navLayout=\"around\"\n onSelect={handleChange}\n required={false}\n selected={selected}\n showOutsideDays\n />\n <hr />\n <div className=\"jalali-date-picker-input\">\n <input\n max={59}\n min={0}\n onInput={(e) => {\n if (!selected) return;\n const target = e.target as HTMLInputElement;\n const newDate = new Date(selected);\n\n newDate.setMinutes(target.valueAsNumber);\n\n handleChange(newDate);\n }}\n type=\"number\"\n value={selected?.getMinutes() ?? 0}\n />\n <span>:</span>\n <input\n max={23}\n min={0}\n onInput={(e) => {\n if (!selected) return;\n const target = e.target as HTMLInputElement;\n const newDate = new Date(selected);\n\n newDate.setHours(target.valueAsNumber);\n\n handleChange(newDate);\n }}\n type=\"number\"\n value={selected?.getHours() ?? 0}\n />\n </div>\n </div>\n {/* {required && !selected && (\n <p className=\"field-error\">\u0644\u0637\u0641\u0627 \u062A\u0627\u0631\u06CC\u062E \u0631\u0627 \u0627\u0646\u062A\u062E\u0627\u0628 \u06A9\u0646\u06CC\u062F</p>\n )} */}\n </div>\n );\n};\n", "import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n", "const css = `.jalali-date-field {\n position: relative;\n}\n.jalali-date-field:focus-within > .jalali-date-picker {\n max-height: 32rem;\n min-height: 30rem;\n padding: 1rem;\n border: 1px solid var(--theme-elevation-150);\n box-shadow: 0 1.5rem 3rem -2rem var(--theme-elevation-250);\n opacity: 1;\n}\n.jalali-date-field .jalali-date-picker {\n max-height: 0rem;\n min-height: 0rem;\n padding: 0rem;\n border: 0px solid var(--theme-elevation-150);\n box-shadow: 0 0 0 0 var(--theme-elevation-250);\n opacity: 0;\n transition: box-shadow 0.3s ease-in-out, max-height 0.6s ease-in-out, min-height 0.3s ease-in-out, padding 0.1s ease-in-out, border 0.1s ease-in-out, opacity 0.15s ease-in-out;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n position: absolute;\n overflow: hidden;\n border-radius: var(--style-radius-l);\n top: 110%;\n font-family: var(--font-body);\n width: 100%;\n height: 100%;\n min-width: 26rem;\n max-width: 28rem;\n z-index: 9999;\n background: var(--theme-input-bg);\n right: 50%;\n translate: 50% 0;\n}\n@supports (backdrop-filter: blur(0.1rem)) {\n .jalali-date-field .jalali-date-picker {\n backdrop-filter: blur(1.5rem);\n background: var(--theme-elevation-150)/40%;\n }\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 0.5rem;\n width: 100%;\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input span {\n font-size: 3rem;\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input {\n -moz-appearance: textfield;\n appearance: textfield;\n text-align: center;\n flex-grow: 1;\n font-size: 1.5rem;\n padding: 0.5rem;\n border: 1px solid var(--theme-elevation-150);\n border-radius: var(--style-radius-l);\n}\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-outer-spin-button,\n.jalali-date-field .jalali-date-picker .jalali-date-picker-input input::-webkit-inner-spin-button {\n /* display: none; <- Crashes Chrome on hover */\n -webkit-appearance: none;\n margin: 0; /* <-- Apparently some margin are still there even though it's hidden */\n}\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvZGF0ZSIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFOztBQUVBO0VBQ0U7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUF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hbGktZGF0ZS1waWNrZXItaW5wdXQge1xuICAgICAgZGlzcGxheTogZmxleDtcbiAgICAgIGFsaWduLWl0ZW1zOiBjZW50ZXI7XG4gICAgICBqdXN0aWZ5LWNvbnRlbnQ6IGNlbnRlcjtcbiAgICAgIGdhcDogMC41cmVtO1xuICAgICAgd2lkdGg6IDEwMCU7XG5cbiAgICAgIHNwYW4ge1xuICAgICAgICBmb250LXNpemU6IDNyZW07XG4gICAgICB9XG5cbiAgICAgIGlucHV0IHtcbiAgICAgICAgLW1vei1hcHBlYXJhbmNlOiB0ZXh0ZmllbGQ7XG4gICAgICAgIGFwcGVhcmFuY2U6IHRleHRmaWVsZDtcblxuICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7XG4gICAgICAgIGZsZXgtZ3JvdzogMTtcbiAgICAgICAgZm9udC1zaXplOiAxLjVyZW07XG4gICAgICAgIHBhZGRpbmc6IDAuNXJlbTtcbiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgdmFyKC0tdGhlbWUtZWxldmF0aW9uLTE1MCk7XG4gICAgICAgIGJvcmRlci1yYWRpdXM6IHZhcigtLXN0eWxlLXJhZGl1cy1sKTtcbiAgICAgIH1cblxuICAgICAgaW5wdXQ6Oi13ZWJraXQtb3V0ZXItc3Bpbi1idXR0b24sXG4gICAgICBpbnB1dDo6LXdlYmtpdC1pbm5lci1zcGluLWJ1dHRvbiB7XG4gICAgICAgIC8qIGRpc3BsYXk6IG5vbmU7IDwtIENyYXNoZXMgQ2hyb21lIG9uIGhvdmVyICovXG4gICAgICAgIC13ZWJraXQtYXBwZWFyYW5jZTogbm9uZTtcbiAgICAgICAgbWFyZ2luOiAwOyAvKiA8LS0gQXBwYXJlbnRseSBzb21lIG1hcmdpbiBhcmUgc3RpbGwgdGhlcmUgZXZlbiB0aG91Z2ggaXQncyBoaWRkZW4gKi9cbiAgICAgIH1cbiAgICB9XG4gIH1cbn1cbiJdfQ== */`;\ndocument.head\n .appendChild(document.createElement(\"style\"))\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CACF,EAAIC,EAA2B,MAAS,EAGxCC,EACE,IAAM,CACAN,GACFI,EAAY,IAAI,KAAKJ,CAAK,CAAC,CAE/B,EAAG,CAACA,CAAK,CACX,EAEA,IAAMO,EAAgBC,GAA2B,CAC/CJ,EAAYI,CAAI,EAEZA,GACFP,EAASO,EAAK,YAAY,CAAC,CAE/B,EAEA,OACEZ,EAAC,OAAI,UAAU,oCAAoC,SAAU,EAC1D,UAAAG,GACCJ,EAAC,SAAM,UAAU,cAAc,QAASG,EACrC,gBAAOC,CAAK,EACf,EAEFJ,EAAC,SACC,SAAQ,GACR,KAAK,OACL,OAAQK,GAASS,EAAWT,CAAK,IAAM,OACzC,EACAJ,EAAC,OAAI,UAAU,qBACb,UAAAD,EAACe,EAAA,CACC,QAAO,GACP,cAAc,WACd,KAAK,SACL,UAAU,SACV,SAAUH,EACV,SAAU,GACV,SAAUJ,EACV,gBAAe,GACjB,EACAR,EAAC,OAAG,EACJC,EAAC,OAAI,UAAU,2BACb,UAAAD,EAAC,SACC,IAAK,GACL,IAAK,EACL,QAAUgB,GAAM,CACd,GAAI,CAACR,EAAU,OACf,IAAMS,EAASD,EAAE,OACXE,EAAU,IAAI,KAAKV,CAAQ,EAEjCU,EAAQ,WAAWD,EAAO,aAAa,EAEvCL,EAAaM,CAAO,CACtB,EACA,KAAK,SACL,MAAOV,GAAU,WAAW,GAAK,EACnC,EACAR,EAAC,QAAK,aAAC,EACPA,EAAC,SACC,IAAK,GACL,IAAK,EACL,QAAUgB,GAAM,CACd,GAAI,CAACR,EAAU,OACf,IAAMS,EAASD,EAAE,OACXE,EAAU,IAAI,KAAKV,CAAQ,EAEjCU,EAAQ,SAASD,EAAO,aAAa,EAErCL,EAAaM,CAAO,CACtB,EACA,KAAK,SACL,MAAOV,GAAU,SAAS,GAAK,EACjC,GACF,GACF,GAIF,CAEJ",
|
|
6
|
+
"names": ["useField", "useEffect", "useState", "DayPicker", "formatJalali", "formatDate", "_date", "date", "formatted", "err", "css", "jsx", "jsxs", "DatePicker", "path", "label", "value", "setValue", "useField", "selected", "setSelected", "useState", "useEffect", "handleChange", "date", "formatDate", "DayPicker", "e", "target", "newDate"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-date.d.ts","sourceRoot":"","sources":["../../src/date/format-date.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAE,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAoBzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,KAAK,IAAI,GAAG,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnD,eAAO,MAAM,SAAS,EAAE,IAmBvB,CAAC;AAEF,cAAc,eAAe,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.602Z)
|
|
2
|
+
"use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var o in t)l(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of c(t))!u.call(e,i)&&i!==o&&l(e,i,{get:()=>t[i],enumerable:!(a=p(t,i))||a.enumerable});return e};var x=e=>f(l({},"__esModule",{value:!0}),e);var k={};m(k,{dateField:()=>g,editor:()=>y,formatDate:()=>F,formatSlug:()=>d,formatSlugHook:()=>n,slugField:()=>h});module.exports=x(k);var r=require("@payloadcms/richtext-lexical");var s=require("date-fns-jalali");function F(e){if(!e)return"";let t=typeof e=="string"?new Date(e):e,o;try{o=(0,s.format)(t,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(a){console.error("error formatting date:",a),o=t.toLocaleDateString("fa-IR")}return o}var g=(e={type:"date",name:"date"})=>[{index:!0,label:"\u062A\u0627\u0631\u06CC\u062E",...e||{},admin:{position:"sidebar",...(e==null?void 0:e.admin)||{},components:{Cell:{path:"@nexload-sdk/payload-tools/fields/date/date-cell#DateCell"},Field:{path:"@nexload-sdk/payload-tools/fields/date/date-picker#DatePicker"}}}}];function d(e){return e==null?void 0:e.replace(/ /g,"-").replace(/[^\w-]+/g,"").toLowerCase()}var n=e=>({data:t,operation:o,value:a})=>{if(typeof a=="string")return d(a);if(o==="create"||(t==null?void 0:t.slug)===void 0){let i=t==null?void 0:t[e];if(typeof i=="string")return d(i)}return a};var h=(e="title",t={})=>{let{slugOverrides:o,checkboxOverrides:a}=t,i={name:"slugLock",type:"checkbox",defaultValue:!0,admin:{hidden:!0,position:"sidebar"},...a};return[{name:"slug",type:"text",index:!0,label:"\u0627\u0633\u0644\u0627\u06AF",...o||{},hooks:{beforeValidate:[n(e)]},admin:{position:"sidebar",...(o==null?void 0:o.admin)||{},components:{Field:{path:"@nexload-sdk/payload-tools/fields/slug/slug-field#SlugComponent",clientProps:{fieldToUse:e,checkboxFieldPath:i.name}}}}},i]};var y=(0,r.lexicalEditor)({admin:{hideInsertParagraphAtEnd:!0,hideGutter:!0},features:({defaultFeatures:e})=>[...e,(0,r.HeadingFeature)({enabledHeadingSizes:["h1","h2","h3","h4"]}),(0,r.FixedToolbarFeature)({applyToFocusedEditor:!0}),(0,r.HorizontalRuleFeature)(),(0,r.UploadFeature)(),(0,r.EXPERIMENTAL_TableFeature)(),(0,r.RelationshipFeature)({enabledCollections:["products","articles"]})]});0&&(module.exports={dateField,editor,formatDate,formatSlug,formatSlugHook,slugField});
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/date/format-date.ts", "../src/date/index.ts", "../src/slug/format-slug.ts", "../src/slug/index.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n EXPERIMENTAL_TableFeature,\n HorizontalRuleFeature,\n UploadFeature,\n FixedToolbarFeature,\n HeadingFeature,\n lexicalEditor,\n RelationshipFeature,\n} from \"@payloadcms/richtext-lexical\";\nimport { RichTextAdapterProvider } from \"payload\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const editor: RichTextAdapterProvider<any, any, any> = lexicalEditor({\n admin: {\n hideInsertParagraphAtEnd: true,\n hideGutter: true,\n },\n features: ({ defaultFeatures }) => {\n return [\n ...defaultFeatures,\n HeadingFeature({\n enabledHeadingSizes: [\"h1\", \"h2\", \"h3\", \"h4\"],\n }),\n FixedToolbarFeature({ applyToFocusedEditor: true }),\n HorizontalRuleFeature(),\n UploadFeature(),\n EXPERIMENTAL_TableFeature(),\n RelationshipFeature({\n enabledCollections: [\"products\", \"articles\"],\n }),\n ];\n },\n});\n\nexport * from './date';\nexport * from './slug';\n", "import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n", "import type { DateField } from \"payload\";\n\ntype Date = (overrides?: DateField) => [DateField];\n\nexport const dateField: Date = (overrides = {\n type: \"date\",\n name: \"date\",\n}) => {\n const dateField: DateField = {\n index: true,\n label: \"\u062A\u0627\u0631\u06CC\u062E\",\n ...(overrides || {}),\n admin: {\n position: \"sidebar\",\n ...(overrides?.admin || {}),\n components: {\n Cell: { path: \"@nexload-sdk/payload-tools/fields/date/date-cell#DateCell\", },\n Field: { path: \"@nexload-sdk/payload-tools/fields/date/date-picker#DatePicker\", },\n },\n },\n };\n\n return [dateField];\n};\n\nexport * from './format-date';", "import type { FieldHook } from \"payload\";\n\nexport function formatSlug (val: string): string | undefined {\n const formatted = val\n ?.replace(\n / /g, \"-\"\n )\n .replace(\n /[^\\w-]+/g, \"\"\n )\n .toLowerCase();\n\n return formatted;\n}\n\nexport const formatSlugHook\n = (fallback: string): FieldHook => ({ data, operation, value, }) => {\n if (typeof value === \"string\") {\n return formatSlug(value);\n }\n\n if (operation === \"create\" || data?.slug === undefined) {\n const fallbackData = data?.[fallback];\n\n if (typeof fallbackData === \"string\") {\n return formatSlug(fallbackData);\n }\n }\n\n return value;\n };\n", "import { formatSlugHook } from \"./format-slug\";\n\nimport type { CheckboxField, TextField } from \"payload\";\n\ntype Overrides = {\n slugOverrides?: Partial<TextField>;\n checkboxOverrides?: Partial<CheckboxField>;\n};\n\ntype Slug = (\n fieldToUse?: string,\n overrides?: Overrides\n) => [TextField, CheckboxField];\n\nexport const slugField: Slug = (fieldToUse = \"title\", overrides = {}) => {\n const { slugOverrides, checkboxOverrides } = overrides;\n\n const checkBoxField: CheckboxField = {\n name: \"slugLock\",\n type: \"checkbox\",\n defaultValue: true,\n admin: {\n hidden: true,\n position: \"sidebar\",\n },\n ...checkboxOverrides,\n };\n\n // @ts-expect-error - ts mismatch Partial<TextField> with TextField\n const slugField: TextField = {\n name: \"slug\",\n type: \"text\",\n index: true,\n label: \"\u0627\u0633\u0644\u0627\u06AF\",\n ...(slugOverrides || {}),\n hooks: {\n // Kept this in for hook or API based updates\n beforeValidate: [formatSlugHook(fieldToUse)],\n },\n admin: {\n position: \"sidebar\",\n ...(slugOverrides?.admin || {}),\n components: {\n Field: {\n path: \"@nexload-sdk/payload-tools/fields/slug/slug-field#SlugComponent\",\n clientProps: {\n fieldToUse,\n checkboxFieldPath: checkBoxField.name,\n },\n },\n },\n },\n };\n\n return [slugField, checkBoxField];\n};\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ME,EAAkB,CAACC,EAAa,QAASC,EAAY,CAAC,IAAM,CACvE,GAAM,CAAE,cAAAC,EAAe,kBAAAC,CAAkB,EAAIF,EAEvCG,EAA+B,CACnC,KAAM,WACN,KAAM,WACN,aAAc,GACd,MAAO,CACL,OAAQ,GACR,SAAU,SACZ,EACA,GAAGD,CACL,EA4BA,MAAO,CAzBsB,CAC3B,KAAM,OACN,KAAM,OACN,MAAO,GACP,MAAO,iCACP,GAAID,GAAiB,CAAC,EACtB,MAAO,CAEL,eAAgB,CAACG,EAAeL,CAAU,CAAC,CAC7C,EACA,MAAO,CACL,SAAU,UACV,IAAIE,GAAA,YAAAA,EAAe,QAAS,CAAC,EAC7B,WAAY,CACV,MAAO,CACL,KAAM,kEACN,YAAa,CACX,WAAAF,EACA,kBAAmBI,EAAc,IACnC,CACF,CACF,CACF,CACF,EAEmBA,CAAa,CAClC,EJ3CO,IAAME,KAAiD,iBAAc,CAC1E,MAAO,CACL,yBAA0B,GAC1B,WAAY,EACd,EACA,SAAU,CAAC,CAAE,gBAAAC,CAAgB,IACpB,CACL,GAAGA,KACH,kBAAe,CACb,oBAAqB,CAAC,KAAM,KAAM,KAAM,IAAI,CAC9C,CAAC,KACD,uBAAoB,CAAE,qBAAsB,EAAK,CAAC,KAClD,yBAAsB,KACtB,iBAAc,KACd,6BAA0B,KAC1B,uBAAoB,CAClB,mBAAoB,CAAC,WAAY,UAAU,CAC7C,CAAC,CACH,CAEJ,CAAC",
|
|
6
|
+
"names": ["index_exports", "__export", "dateField", "editor", "formatDate", "formatSlug", "formatSlugHook", "slugField", "__toCommonJS", "import_richtext_lexical", "import_date_fns_jalali", "formatDate", "_date", "date", "formatted", "formatJalali", "err", "dateField", "overrides", "formatSlug", "val", "formatSlugHook", "fallback", "data", "operation", "value", "fallbackData", "slugField", "fieldToUse", "overrides", "slugOverrides", "checkboxOverrides", "checkBoxField", "formatSlugHook", "editor", "defaultFeatures"]
|
|
7
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGlD,eAAO,MAAM,MAAM,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAoBxD,CAAC;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.585Z)
|
|
2
|
+
import{EXPERIMENTAL_TableFeature as n,HorizontalRuleFeature as s,UploadFeature as p,FixedToolbarFeature as c,HeadingFeature as u,lexicalEditor as m,RelationshipFeature as f}from"@payloadcms/richtext-lexical";import{format as l}from"date-fns-jalali";function F(e){if(!e)return"";let t=typeof e=="string"?new Date(e):e,r;try{r=l(t,"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm")}catch(o){console.error("error formatting date:",o),r=t.toLocaleDateString("fa-IR")}return r}var y=(e={type:"date",name:"date"})=>[{index:!0,label:"\u062A\u0627\u0631\u06CC\u062E",...e||{},admin:{position:"sidebar",...e?.admin||{},components:{Cell:{path:"@nexload-sdk/payload-tools/fields/date/date-cell#DateCell"},Field:{path:"@nexload-sdk/payload-tools/fields/date/date-picker#DatePicker"}}}}];function i(e){return e?.replace(/ /g,"-").replace(/[^\w-]+/g,"").toLowerCase()}var d=e=>({data:t,operation:r,value:o})=>{if(typeof o=="string")return i(o);if(r==="create"||t?.slug===void 0){let a=t?.[e];if(typeof a=="string")return i(a)}return o};var T=(e="title",t={})=>{let{slugOverrides:r,checkboxOverrides:o}=t,a={name:"slugLock",type:"checkbox",defaultValue:!0,admin:{hidden:!0,position:"sidebar"},...o};return[{name:"slug",type:"text",index:!0,label:"\u0627\u0633\u0644\u0627\u06AF",...r||{},hooks:{beforeValidate:[d(e)]},admin:{position:"sidebar",...r?.admin||{},components:{Field:{path:"@nexload-sdk/payload-tools/fields/slug/slug-field#SlugComponent",clientProps:{fieldToUse:e,checkboxFieldPath:a.name}}}}},a]};var S=m({admin:{hideInsertParagraphAtEnd:!0,hideGutter:!0},features:({defaultFeatures:e})=>[...e,u({enabledHeadingSizes:["h1","h2","h3","h4"]}),c({applyToFocusedEditor:!0}),s(),p(),n(),f({enabledCollections:["products","articles"]})]});export{y as dateField,S as editor,F as formatDate,i as formatSlug,d as formatSlugHook,T as slugField};
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/date/format-date.ts", "../src/date/index.ts", "../src/slug/format-slug.ts", "../src/slug/index.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n EXPERIMENTAL_TableFeature,\n HorizontalRuleFeature,\n UploadFeature,\n FixedToolbarFeature,\n HeadingFeature,\n lexicalEditor,\n RelationshipFeature,\n} from \"@payloadcms/richtext-lexical\";\nimport { RichTextAdapterProvider } from \"payload\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const editor: RichTextAdapterProvider<any, any, any> = lexicalEditor({\n admin: {\n hideInsertParagraphAtEnd: true,\n hideGutter: true,\n },\n features: ({ defaultFeatures }) => {\n return [\n ...defaultFeatures,\n HeadingFeature({\n enabledHeadingSizes: [\"h1\", \"h2\", \"h3\", \"h4\"],\n }),\n FixedToolbarFeature({ applyToFocusedEditor: true }),\n HorizontalRuleFeature(),\n UploadFeature(),\n EXPERIMENTAL_TableFeature(),\n RelationshipFeature({\n enabledCollections: [\"products\", \"articles\"],\n }),\n ];\n },\n});\n\nexport * from './date';\nexport * from './slug';\n", "import { format as formatJalali } from \"date-fns-jalali\";\n\nexport function formatDate (_date?: Date | string): string {\n if (!_date) return \"\";\n\n const date = typeof _date === \"string\" ? new Date(_date) : _date;\n\n let formatted: string;\n try {\n formatted = formatJalali(\n date, \"EEEE d MMMM y \u0633\u0627\u0639\u062A HH:mm\"\n );\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n \"error formatting date:\", err\n );\n // if error, show ISO simple\n formatted = date.toLocaleDateString(\"fa-IR\");\n }\n\n return formatted;\n}\n", "import type { DateField } from \"payload\";\n\ntype Date = (overrides?: DateField) => [DateField];\n\nexport const dateField: Date = (overrides = {\n type: \"date\",\n name: \"date\",\n}) => {\n const dateField: DateField = {\n index: true,\n label: \"\u062A\u0627\u0631\u06CC\u062E\",\n ...(overrides || {}),\n admin: {\n position: \"sidebar\",\n ...(overrides?.admin || {}),\n components: {\n Cell: { path: \"@nexload-sdk/payload-tools/fields/date/date-cell#DateCell\", },\n Field: { path: \"@nexload-sdk/payload-tools/fields/date/date-picker#DatePicker\", },\n },\n },\n };\n\n return [dateField];\n};\n\nexport * from './format-date';", "import type { FieldHook } from \"payload\";\n\nexport function formatSlug (val: string): string | undefined {\n const formatted = val\n ?.replace(\n / /g, \"-\"\n )\n .replace(\n /[^\\w-]+/g, \"\"\n )\n .toLowerCase();\n\n return formatted;\n}\n\nexport const formatSlugHook\n = (fallback: string): FieldHook => ({ data, operation, value, }) => {\n if (typeof value === \"string\") {\n return formatSlug(value);\n }\n\n if (operation === \"create\" || data?.slug === undefined) {\n const fallbackData = data?.[fallback];\n\n if (typeof fallbackData === \"string\") {\n return formatSlug(fallbackData);\n }\n }\n\n return value;\n };\n", "import { formatSlugHook } from \"./format-slug\";\n\nimport type { CheckboxField, TextField } from \"payload\";\n\ntype Overrides = {\n slugOverrides?: Partial<TextField>;\n checkboxOverrides?: Partial<CheckboxField>;\n};\n\ntype Slug = (\n fieldToUse?: string,\n overrides?: Overrides\n) => [TextField, CheckboxField];\n\nexport const slugField: Slug = (fieldToUse = \"title\", overrides = {}) => {\n const { slugOverrides, checkboxOverrides } = overrides;\n\n const checkBoxField: CheckboxField = {\n name: \"slugLock\",\n type: \"checkbox\",\n defaultValue: true,\n admin: {\n hidden: true,\n position: \"sidebar\",\n },\n ...checkboxOverrides,\n };\n\n // @ts-expect-error - ts mismatch Partial<TextField> with TextField\n const slugField: TextField = {\n name: \"slug\",\n type: \"text\",\n index: true,\n label: \"\u0627\u0633\u0644\u0627\u06AF\",\n ...(slugOverrides || {}),\n hooks: {\n // Kept this in for hook or API based updates\n beforeValidate: [formatSlugHook(fieldToUse)],\n },\n admin: {\n position: \"sidebar\",\n ...(slugOverrides?.admin || {}),\n components: {\n Field: {\n path: \"@nexload-sdk/payload-tools/fields/slug/slug-field#SlugComponent\",\n clientProps: {\n fieldToUse,\n checkboxFieldPath: checkBoxField.name,\n },\n },\n },\n },\n };\n\n return [slugField, checkBoxField];\n};\n\nexport * from \"./format-slug\";\n"],
|
|
5
|
+
"mappings": ";AAAA,OACE,6BAAAA,EACA,yBAAAC,EACA,iBAAAC,EACA,uBAAAC,EACA,kBAAAC,EACA,iBAAAC,EACA,uBAAAC,MACK,+BCRP,OAAS,UAAUC,MAAoB,kBAEhC,SAASC,EAAYC,EAA+B,CACzD,GAAI,CAACA,EAAO,MAAO,GAEnB,IAAMC,EAAO,OAAOD,GAAU,SAAW,IAAI,KAAKA,CAAK,EAAIA,EAEvDE,EACJ,GAAI,CACFA,EAAYJ,EACVG,EAAM,8CACR,CACF,OAASE,EAAK,CAEZ,QAAQ,MACN,yBAA0BA,CAC5B,EAEAD,EAAYD,EAAK,mBAAmB,OAAO,CAC7C,CAEA,OAAOC,CACT,CClBO,IAAME,EAAkB,CAACC,EAAY,CAC1C,KAAM,OACN,KAAM,MACR,IAeS,CAdsB,CAC3B,MAAO,GACP,MAAO,iCACP,GAAIA,GAAa,CAAC,EAClB,MAAO,CACL,SAAU,UACV,GAAIA,GAAW,OAAS,CAAC,EACzB,WAAY,CACV,KAAM,CAAE,KAAM,2DAA6D,EAC3E,MAAO,CAAE,KAAM,+DAAiE,CAClF,CACF,CACF,CAEiB,ECpBZ,SAASC,EAAYC,EAAiC,CAU3D,OATk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,CAAC,CACH,CAEJ,CAAC",
|
|
6
|
+
"names": ["EXPERIMENTAL_TableFeature", "HorizontalRuleFeature", "UploadFeature", "FixedToolbarFeature", "HeadingFeature", "lexicalEditor", "RelationshipFeature", "formatJalali", "formatDate", "_date", "date", "formatted", "err", "dateField", "overrides", "formatSlug", "val", "formatSlugHook", "fallback", "data", "operation", "value", "fallbackData", "slugField", "fieldToUse", "overrides", "slugOverrides", "checkboxOverrides", "checkBoxField", "formatSlugHook", "editor", "lexicalEditor", "defaultFeatures", "HeadingFeature", "FixedToolbarFeature", "HorizontalRuleFeature", "UploadFeature", "EXPERIMENTAL_TableFeature", "RelationshipFeature"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-slug.d.ts","sourceRoot":"","sources":["../../src/slug/format-slug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,UAAU,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW3D;AAED,eAAO,MAAM,cAAc,GACtB,UAAU,MAAM,KAAG,SAcrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CheckboxField, TextField } from "payload";
|
|
2
|
+
type Overrides = {
|
|
3
|
+
slugOverrides?: Partial<TextField>;
|
|
4
|
+
checkboxOverrides?: Partial<CheckboxField>;
|
|
5
|
+
};
|
|
6
|
+
type Slug = (fieldToUse?: string, overrides?: Overrides) => [TextField, CheckboxField];
|
|
7
|
+
export declare const slugField: Slug;
|
|
8
|
+
export * from "./format-slug";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slug/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAExD,KAAK,SAAS,GAAG;IACf,aAAa,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF,KAAK,IAAI,GAAG,CACV,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,SAAS,KAClB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAEhC,eAAO,MAAM,SAAS,EAAE,IAyCvB,CAAC;AAEF,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.602Z)
|
|
2
|
+
"use strict";"use client";var m=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var I=(t,o)=>{for(var l in o)m(t,l,{get:o[l],enumerable:!0})},V=(t,o,l,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of w(o))!x.call(t,r)&&r!==l&&m(t,r,{get:()=>o[r],enumerable:!(s=W(o,r))||s.enumerable});return t};var G=t=>V(m({},"__esModule",{value:!0}),t);var R={};I(R,{SlugComponent:()=>A});module.exports=G(R);var n=require("@payloadcms/ui"),p=require("react");function C(t){return t==null?void 0:t.replace(/ /g,"-").replace(/[^\w-]+/g,"").toLowerCase()}var L=`.slug-field-component .label-wrapper {
|
|
3
|
+
display: flex;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: calc(var(--base) / 2);
|
|
7
|
+
}
|
|
8
|
+
.slug-field-component .lock-button {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding-bottom: 0.3125rem;
|
|
11
|
+
}
|
|
12
|
+
.slug-field-component .icon-button {
|
|
13
|
+
width: 1.5rem;
|
|
14
|
+
height: 1.5rem;
|
|
15
|
+
}
|
|
16
|
+
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvc2x1ZyIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDRTtFQUNFO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTs7QUFHRjtFQUNFO0VBQ0EiLCJzb3VyY2VzQ29udGVudCI6WyIuc2x1Zy1maWVsZC1jb21wb25lbnQge1xuICAubGFiZWwtd3JhcHBlciB7XG4gICAgZGlzcGxheTogZmxleDtcbiAgICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47XG4gICAgYWxpZ24taXRlbXM6IGNlbnRlcjtcbiAgICBnYXA6IGNhbGModmFyKC0tYmFzZSkgLyAyKTtcbiAgfVxuXG4gIC5sb2NrLWJ1dHRvbiB7XG4gICAgbWFyZ2luOiAwO1xuICAgIHBhZGRpbmctYm90dG9tOiAwLjMxMjVyZW07XG4gIH1cblxuICAuaWNvbi1idXR0b257XG4gICAgd2lkdGg6IDEuNXJlbTtcbiAgICBoZWlnaHQ6IDEuNXJlbTtcbiAgfVxufVxuIl19 */`;document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(L));var e=require("react/jsx-runtime"),v=t=>(0,e.jsx)("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...t,children:(0,e.jsxs)("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[(0,e.jsx)("path",{d:"M11 20c-3.75 0-5.625 0-6.939-.955a5 5 0 0 1-1.106-1.106C2 16.625 2 14.749 2 11s0-5.625.955-6.939A5 5 0 0 1 4.06 2.955C5.375 2 7.251 2 11 2h.5c3.273 0 4.91 0 6.113.737a5 5 0 0 1 1.65 1.65C20 5.59 20 7.228 20 10.5m-2.593 3.904a.638.638 0 0 1 1.186 0l.037.093a5.1 5.1 0 0 0 2.873 2.873l.093.037a.638.638 0 0 1 0 1.186l-.093.037a5.1 5.1 0 0 0-2.873 2.873l-.037.093a.638.638 0 0 1-1.186 0l-.037-.093a5.1 5.1 0 0 0-2.873-2.873l-.093-.037a.638.638 0 0 1 0-1.186l.093-.037a5.1 5.1 0 0 0 2.873-2.873z"}),(0,e.jsx)("path",{d:"M11 7H7v1m4-1h4v1m-4-1v8m0 0h-1m1 0h1"})]})}),N=t=>(0,e.jsx)("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...t,children:(0,e.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:1,children:[(0,e.jsx)("path",{d:"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z",strokeWidth:1.5}),(0,e.jsx)("path",{d:"M7.5 9V6.5A4.5 4.5 0 0 1 12 2c1.96 0 3.5 1.5 4 3",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5}),(0,e.jsx)("path",{d:"M11.996 15.5h.01",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:.9})]})}),Z=t=>(0,e.jsx)("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...t,children:(0,e.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:1,children:[(0,e.jsx)("path",{d:"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z",strokeWidth:1.5}),(0,e.jsx)("path",{d:"M7.5 9V6.5a4.5 4.5 0 0 1 9 0V9",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5}),(0,e.jsx)("path",{d:"M11.996 15.5h.01",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:.9})]})}),A=({field:t,fieldToUse:o,checkboxFieldPath:l,path:s,readOnly:r})=>{let{label:f}=t,g=s!=null&&s.includes(".")?`${s}.${l}`:l,{value:u,setValue:d}=(0,n.useField)({path:s||t.name}),{dispatchFields:h,getDataByPath:b}=(0,n.useForm)(),c=(0,n.useFormFields)(([i])=>{var a;return(a=i[g])==null?void 0:a.value}),y=(0,p.useCallback)(i=>{i.preventDefault();let a=b(o);if(a){let k=C(a);u!==k&&d(k)}else u!==""&&d("")},[d,u,o,b]),F=(0,p.useCallback)(i=>{i.preventDefault(),h({type:"UPDATE",path:g,value:!c})},[c,g,h]);return(0,e.jsxs)("div",{className:"field-type slug-field-component",children:[(0,e.jsxs)("div",{className:"label-wrapper",children:[(0,e.jsx)(n.FieldLabel,{htmlFor:`field-${s}`,label:f}),!c&&(0,e.jsx)(n.Button,{buttonStyle:"none",className:"lock-button",onClick:y,children:(0,e.jsx)(v,{className:"icon-button"})}),(0,e.jsx)(n.Button,{buttonStyle:"none",className:"lock-button",onClick:F,children:c?(0,e.jsx)(Z,{className:"icon-button"}):(0,e.jsx)(N,{className:"icon-button"})})]}),(0,e.jsx)(n.TextInput,{onChange:d,path:s||t.name,readOnly:!!(r||c),value:u})]})};0&&(module.exports={SlugComponent});
|
|
17
|
+
//# sourceMappingURL=slug-field.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/slug/slug-field.tsx", "../../src/slug/format-slug.ts", "../../src/slug/index.scss"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @stylistic/max-len */\n\"use client\";\nimport {\n useField,\n Button,\n TextInput,\n FieldLabel,\n useFormFields,\n useForm\n} from \"@payloadcms/ui\";\nimport { TextFieldClientProps } from \"payload\";\nimport React, { useCallback } from \"react\";\n\nimport { formatSlug } from \"./format-slug\";\nimport \"./index.scss\";\n\nconst HugeAiGenerator: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n >\n <path d=\"M11 20c-3.75 0-5.625 0-6.939-.955a5 5 0 0 1-1.106-1.106C2 16.625 2 14.749 2 11s0-5.625.955-6.939A5 5 0 0 1 4.06 2.955C5.375 2 7.251 2 11 2h.5c3.273 0 4.91 0 6.113.737a5 5 0 0 1 1.65 1.65C20 5.59 20 7.228 20 10.5m-2.593 3.904a.638.638 0 0 1 1.186 0l.037.093a5.1 5.1 0 0 0 2.873 2.873l.093.037a.638.638 0 0 1 0 1.186l-.093.037a5.1 5.1 0 0 0-2.873 2.873l-.037.093a.638.638 0 0 1-1.186 0l-.037-.093a5.1 5.1 0 0 0-2.873-2.873l-.093-.037a.638.638 0 0 1 0-1.186l.093-.037a5.1 5.1 0 0 0 2.873-2.873z\" />\n <path d=\"M11 7H7v1m4-1h4v1m-4-1v8m0 0h-1m1 0h1\" />\n </g>\n </svg>\n );\n};\nconst HugeUnlock: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g fill=\"none\" stroke=\"currentColor\" strokeWidth={1}>\n <path\n d=\"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z\"\n strokeWidth={1.5}\n />\n <path\n d=\"M7.5 9V6.5A4.5 4.5 0 0 1 12 2c1.96 0 3.5 1.5 4 3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n />\n <path\n d=\"M11.996 15.5h.01\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={0.9}\n />\n </g>\n </svg>\n );\n};\nconst HugeLock: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g fill=\"none\" stroke=\"currentColor\" strokeWidth={1}>\n <path\n d=\"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z\"\n strokeWidth={1.5}\n />\n <path\n d=\"M7.5 9V6.5a4.5 4.5 0 0 1 9 0V9\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n />\n <path\n d=\"M11.996 15.5h.01\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={0.9}\n />\n </g>\n </svg>\n );\n};\n\ntype SlugComponentProps = {\n fieldToUse: string\n checkboxFieldPath: string\n} & TextFieldClientProps;\n\nexport const SlugComponent: React.FC<SlugComponentProps> = ({\n field,\n fieldToUse,\n checkboxFieldPath: checkboxFieldPathFromProps,\n path,\n readOnly: readOnlyFromProps,\n}) => {\n const { label, } = field;\n\n const checkboxFieldPath = path?.includes(\".\")\n ? `${path}.${checkboxFieldPathFromProps}`\n : checkboxFieldPathFromProps;\n\n const { value, setValue, } = useField<string>({ path: path || field.name, });\n\n const { dispatchFields, getDataByPath, } = useForm();\n\n const isLocked = useFormFields(([fields]) => {\n return fields[checkboxFieldPath]?.value as string;\n });\n\n const handleGenerate = useCallback(\n (e: React.MouseEvent<Element>) => {\n e.preventDefault();\n\n const targetFieldValue = getDataByPath(fieldToUse) as string;\n\n if (targetFieldValue) {\n const formattedSlug = formatSlug(targetFieldValue);\n\n if (value !== formattedSlug) setValue(formattedSlug);\n } else {\n if (value !== \"\") setValue(\"\");\n }\n }, [\n setValue,\n value,\n fieldToUse,\n getDataByPath\n ]\n );\n\n const handleLock = useCallback(\n (e: React.MouseEvent<Element>) => {\n e.preventDefault();\n\n dispatchFields({\n type: \"UPDATE\",\n path: checkboxFieldPath,\n value: !isLocked,\n });\n }, [\n isLocked,\n checkboxFieldPath,\n dispatchFields\n ]\n );\n\n return (\n <div className=\"field-type slug-field-component\">\n <div className=\"label-wrapper\">\n <FieldLabel htmlFor={`field-${path}`} label={label} />\n {!isLocked && (\n <Button\n buttonStyle=\"none\"\n className=\"lock-button\"\n onClick={handleGenerate}\n >\n <HugeAiGenerator className=\"icon-button\" />\n </Button>\n )}\n <Button buttonStyle=\"none\" className=\"lock-button\" onClick={handleLock}>\n {isLocked\n ? (\n <HugeLock className=\"icon-button\" />\n )\n : (\n <HugeUnlock className=\"icon-button\" />\n )}\n </Button>\n </div>\n <TextInput\n onChange={setValue}\n path={path || field.name}\n readOnly={Boolean(readOnlyFromProps || isLocked)}\n value={value}\n />\n </div>\n );\n};\n", "import type { FieldHook } from \"payload\";\n\nexport function formatSlug (val: string): string | undefined {\n const formatted = val\n ?.replace(\n / /g, \"-\"\n )\n .replace(\n /[^\\w-]+/g, \"\"\n )\n .toLowerCase();\n\n return formatted;\n}\n\nexport const formatSlugHook\n = (fallback: string): FieldHook => ({ data, operation, value, }) => {\n if (typeof value === \"string\") {\n return formatSlug(value);\n }\n\n if (operation === \"create\" || data?.slug === undefined) {\n const fallbackData = data?.[fallback];\n\n if (typeof fallbackData === \"string\") {\n return formatSlug(fallbackData);\n }\n }\n\n return value;\n };\n", "const css = `.slug-field-component .label-wrapper {\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: calc(var(--base) / 2);\n}\n.slug-field-component .lock-button {\n margin: 0;\n padding-bottom: 0.3125rem;\n}\n.slug-field-component .icon-button {\n width: 1.5rem;\n height: 1.5rem;\n}\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvc2x1ZyIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDRTtFQUNFO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTs7QUFHRjtFQUNFO0VBQ0EiLCJzb3VyY2VzQ29udGVudCI6WyIuc2x1Zy1maWVsZC1jb21wb25lbnQge1xuICAubGFiZWwtd3JhcHBlciB7XG4gICAgZGlzcGxheTogZmxleDtcbiAgICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47XG4gICAgYWxpZ24taXRlbXM6IGNlbnRlcjtcbiAgICBnYXA6IGNhbGModmFyKC0tYmFzZSkgLyAyKTtcbiAgfVxuXG4gIC5sb2NrLWJ1dHRvbiB7XG4gICAgbWFyZ2luOiAwO1xuICAgIHBhZGRpbmctYm90dG9tOiAwLjMxMjVyZW07XG4gIH1cblxuICAuaWNvbi1idXR0b257XG4gICAgd2lkdGg6IDEuNXJlbTtcbiAgICBoZWlnaHQ6IDEuNXJlbTtcbiAgfVxufVxuIl19 */`;\ndocument.head\n .appendChild(document.createElement(\"style\"))\n .appendChild(document.createTextNode(css));\nexport {css};\n"],
|
|
5
|
+
"mappings": ";sbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAOO,0BAEPC,EAAmC,iBCT5B,SAASC,EAAYC,EAAiC,CAU3D,OATkBA,GAAA,YAAAA,EACd,QACA,KAAM,KAEP,QACC,WAAY,IAEb,aAGL,CCbA,IAAMC,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6wBAeZ,SAAS,KACJ,YAAY,SAAS,cAAc,OAAO,CAAC,EAC3C,YAAY,SAAS,eAAeA,CAAG,CAAC,EFQvC,IAAAC,EAAA,6BATAC,EAA4DC,MAE9D,OAAC,OACC,OAAQ,GACR,QAAQ,YACR,MAAO,GACP,MAAM,6BACL,GAAGA,EAEJ,oBAAC,KACC,KAAK,OACL,OAAO,eACP,cAAc,QACd,eAAe,QACf,YAAa,IAEb,oBAAC,QAAK,EAAE,8eAA8e,KACtf,OAAC,QAAK,EAAE,wCAAwC,GAClD,EACF,EAGEC,EAAuDD,MAEzD,OAAC,OACC,OAAQ,GACR,QAAQ,YACR,MAAO,GACP,MAAM,6BACL,GAAGA,EAEJ,oBAAC,KAAE,KAAK,OAAO,OAAO,eAAe,YAAa,EAChD,oBAAC,QACC,EAAE,6VACF,YAAa,IACf,KACA,OAAC,QACC,EAAE,mDACF,cAAc,QACd,eAAe,QACf,YAAa,IACf,KACA,OAAC,QACC,EAAE,mBACF,cAAc,QACd,eAAe,QACf,YAAa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SACE,QAAC,OAAI,UAAU,kCACb,qBAAC,OAAI,UAAU,gBACb,oBAAC,cAAW,QAAS,SAASN,CAAI,GAAI,MAAOE,EAAO,EACnD,CAACM,MACA,OAAC,UACC,YAAY,OACZ,UAAU,cACV,QAASG,EAET,mBAACnB,EAAA,CAAgB,UAAU,cAAc,EAC3C,KAEF,OAAC,UAAO,YAAY,OAAO,UAAU,cAAc,QAASwB,EACzD,SAAAR,KAEG,OAACb,EAAA,CAAS,UAAU,cAAc,KAGlC,OAACD,EAAA,CAAW,UAAU,cAAc,EAE1C,GACF,KACA,OAAC,aACC,SAAUW,EACV,KAAML,GAAQH,EAAM,KACpB,SAAU,GAAQI,GAAqBO,GACvC,MAAOJ,EACT,GACF,CAEJ",
|
|
6
|
+
"names": ["slug_field_exports", "__export", "SlugComponent", "__toCommonJS", "import_ui", "import_react", "formatSlug", "val", "css", "import_jsx_runtime", "HugeAiGenerator", "props", "HugeUnlock", "HugeLock", "SlugComponent", "field", "fieldToUse", "checkboxFieldPathFromProps", "path", "readOnlyFromProps", "label", "checkboxFieldPath", "value", "setValue", "dispatchFields", "getDataByPath", "isLocked", "fields", "_a", "handleGenerate", "e", "targetFieldValue", "formattedSlug", "formatSlug", "handleLock"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TextFieldClientProps } from "payload";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import "./index.scss";
|
|
4
|
+
type SlugComponentProps = {
|
|
5
|
+
fieldToUse: string;
|
|
6
|
+
checkboxFieldPath: string;
|
|
7
|
+
} & TextFieldClientProps;
|
|
8
|
+
export declare const SlugComponent: React.FC<SlugComponentProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=slug-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug-field.d.ts","sourceRoot":"","sources":["../../src/slug/slug-field.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAsB,MAAM,OAAO,CAAC;AAG3C,OAAO,cAAc,CAAC;AAqFtB,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;CAC1B,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAyFtD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v0.0.0 (build 2025-11-16T09:33:40.585Z)
|
|
2
|
+
"use client";import{useField as v,Button as b,TextInput as w,FieldLabel as x,useFormFields as I,useForm as V}from"@payloadcms/ui";import{useCallback as k}from"react";function h(e){return e?.replace(/ /g,"-").replace(/[^\w-]+/g,"").toLowerCase()}var W=`.slug-field-component .label-wrapper {
|
|
3
|
+
display: flex;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: calc(var(--base) / 2);
|
|
7
|
+
}
|
|
8
|
+
.slug-field-component .lock-button {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding-bottom: 0.3125rem;
|
|
11
|
+
}
|
|
12
|
+
.slug-field-component .icon-button {
|
|
13
|
+
width: 1.5rem;
|
|
14
|
+
height: 1.5rem;
|
|
15
|
+
}
|
|
16
|
+
/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvc2x1ZyIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDRTtFQUNFO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTs7QUFHRjtFQUNFO0VBQ0EiLCJzb3VyY2VzQ29udGVudCI6WyIuc2x1Zy1maWVsZC1jb21wb25lbnQge1xuICAubGFiZWwtd3JhcHBlciB7XG4gICAgZGlzcGxheTogZmxleDtcbiAgICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47XG4gICAgYWxpZ24taXRlbXM6IGNlbnRlcjtcbiAgICBnYXA6IGNhbGModmFyKC0tYmFzZSkgLyAyKTtcbiAgfVxuXG4gIC5sb2NrLWJ1dHRvbiB7XG4gICAgbWFyZ2luOiAwO1xuICAgIHBhZGRpbmctYm90dG9tOiAwLjMxMjVyZW07XG4gIH1cblxuICAuaWNvbi1idXR0b257XG4gICAgd2lkdGg6IDEuNXJlbTtcbiAgICBoZWlnaHQ6IDEuNXJlbTtcbiAgfVxufVxuIl19 */`;document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(W));import{jsx as t,jsxs as s}from"react/jsx-runtime";var G=e=>t("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...e,children:s("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[t("path",{d:"M11 20c-3.75 0-5.625 0-6.939-.955a5 5 0 0 1-1.106-1.106C2 16.625 2 14.749 2 11s0-5.625.955-6.939A5 5 0 0 1 4.06 2.955C5.375 2 7.251 2 11 2h.5c3.273 0 4.91 0 6.113.737a5 5 0 0 1 1.65 1.65C20 5.59 20 7.228 20 10.5m-2.593 3.904a.638.638 0 0 1 1.186 0l.037.093a5.1 5.1 0 0 0 2.873 2.873l.093.037a.638.638 0 0 1 0 1.186l-.093.037a5.1 5.1 0 0 0-2.873 2.873l-.037.093a.638.638 0 0 1-1.186 0l-.037-.093a5.1 5.1 0 0 0-2.873-2.873l-.093-.037a.638.638 0 0 1 0-1.186l.093-.037a5.1 5.1 0 0 0 2.873-2.873z"}),t("path",{d:"M11 7H7v1m4-1h4v1m-4-1v8m0 0h-1m1 0h1"})]})}),L=e=>t("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...e,children:s("g",{fill:"none",stroke:"currentColor",strokeWidth:1,children:[t("path",{d:"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z",strokeWidth:1.5}),t("path",{d:"M7.5 9V6.5A4.5 4.5 0 0 1 12 2c1.96 0 3.5 1.5 4 3",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5}),t("path",{d:"M11.996 15.5h.01",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:.9})]})}),N=e=>t("svg",{height:24,viewBox:"0 0 24 24",width:24,xmlns:"http://www.w3.org/2000/svg",...e,children:s("g",{fill:"none",stroke:"currentColor",strokeWidth:1,children:[t("path",{d:"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z",strokeWidth:1.5}),t("path",{d:"M7.5 9V6.5a4.5 4.5 0 0 1 9 0V9",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5}),t("path",{d:"M11.996 15.5h.01",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:.9})]})}),j=({field:e,fieldToUse:c,checkboxFieldPath:d,path:o,readOnly:C})=>{let{label:f}=e,i=o?.includes(".")?`${o}.${d}`:d,{value:r,setValue:a}=v({path:o||e.name}),{dispatchFields:u,getDataByPath:g}=V(),n=I(([l])=>l[i]?.value),y=k(l=>{l.preventDefault();let p=g(c);if(p){let m=h(p);r!==m&&a(m)}else r!==""&&a("")},[a,r,c,g]),F=k(l=>{l.preventDefault(),u({type:"UPDATE",path:i,value:!n})},[n,i,u]);return s("div",{className:"field-type slug-field-component",children:[s("div",{className:"label-wrapper",children:[t(x,{htmlFor:`field-${o}`,label:f}),!n&&t(b,{buttonStyle:"none",className:"lock-button",onClick:y,children:t(G,{className:"icon-button"})}),t(b,{buttonStyle:"none",className:"lock-button",onClick:F,children:n?t(N,{className:"icon-button"}):t(L,{className:"icon-button"})})]}),t(w,{onChange:a,path:o||e.name,readOnly:!!(C||n),value:r})]})};export{j as SlugComponent};
|
|
17
|
+
//# sourceMappingURL=slug-field.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/slug/slug-field.tsx", "../../src/slug/format-slug.ts", "../../src/slug/index.scss"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @stylistic/max-len */\n\"use client\";\nimport {\n useField,\n Button,\n TextInput,\n FieldLabel,\n useFormFields,\n useForm\n} from \"@payloadcms/ui\";\nimport { TextFieldClientProps } from \"payload\";\nimport React, { useCallback } from \"react\";\n\nimport { formatSlug } from \"./format-slug\";\nimport \"./index.scss\";\n\nconst HugeAiGenerator: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n >\n <path d=\"M11 20c-3.75 0-5.625 0-6.939-.955a5 5 0 0 1-1.106-1.106C2 16.625 2 14.749 2 11s0-5.625.955-6.939A5 5 0 0 1 4.06 2.955C5.375 2 7.251 2 11 2h.5c3.273 0 4.91 0 6.113.737a5 5 0 0 1 1.65 1.65C20 5.59 20 7.228 20 10.5m-2.593 3.904a.638.638 0 0 1 1.186 0l.037.093a5.1 5.1 0 0 0 2.873 2.873l.093.037a.638.638 0 0 1 0 1.186l-.093.037a5.1 5.1 0 0 0-2.873 2.873l-.037.093a.638.638 0 0 1-1.186 0l-.037-.093a5.1 5.1 0 0 0-2.873-2.873l-.093-.037a.638.638 0 0 1 0-1.186l.093-.037a5.1 5.1 0 0 0 2.873-2.873z\" />\n <path d=\"M11 7H7v1m4-1h4v1m-4-1v8m0 0h-1m1 0h1\" />\n </g>\n </svg>\n );\n};\nconst HugeUnlock: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g fill=\"none\" stroke=\"currentColor\" strokeWidth={1}>\n <path\n d=\"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z\"\n strokeWidth={1.5}\n />\n <path\n d=\"M7.5 9V6.5A4.5 4.5 0 0 1 12 2c1.96 0 3.5 1.5 4 3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n />\n <path\n d=\"M11.996 15.5h.01\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={0.9}\n />\n </g>\n </svg>\n );\n};\nconst HugeLock: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {\n return (\n <svg\n height={24}\n viewBox=\"0 0 24 24\"\n width={24}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <g fill=\"none\" stroke=\"currentColor\" strokeWidth={1}>\n <path\n d=\"M4.268 18.845c.225 1.67 1.608 2.979 3.292 3.056c1.416.065 2.855.099 4.44.099s3.024-.034 4.44-.1c1.684-.076 3.067-1.385 3.292-3.055c.147-1.09.268-2.207.268-3.345s-.121-2.255-.268-3.345c-.225-1.67-1.608-2.979-3.292-3.056A95 95 0 0 0 12 9c-1.585 0-3.024.034-4.44.1c-1.684.076-3.067 1.385-3.292 3.055C4.12 13.245 4 14.362 4 15.5s.121 2.255.268 3.345Z\"\n strokeWidth={1.5}\n />\n <path\n d=\"M7.5 9V6.5a4.5 4.5 0 0 1 9 0V9\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.5}\n />\n <path\n d=\"M11.996 15.5h.01\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={0.9}\n />\n </g>\n </svg>\n );\n};\n\ntype SlugComponentProps = {\n fieldToUse: string\n checkboxFieldPath: string\n} & TextFieldClientProps;\n\nexport const SlugComponent: React.FC<SlugComponentProps> = ({\n field,\n fieldToUse,\n checkboxFieldPath: checkboxFieldPathFromProps,\n path,\n readOnly: readOnlyFromProps,\n}) => {\n const { label, } = field;\n\n const checkboxFieldPath = path?.includes(\".\")\n ? `${path}.${checkboxFieldPathFromProps}`\n : checkboxFieldPathFromProps;\n\n const { value, setValue, } = useField<string>({ path: path || field.name, });\n\n const { dispatchFields, getDataByPath, } = useForm();\n\n const isLocked = useFormFields(([fields]) => {\n return fields[checkboxFieldPath]?.value as string;\n });\n\n const handleGenerate = useCallback(\n (e: React.MouseEvent<Element>) => {\n e.preventDefault();\n\n const targetFieldValue = getDataByPath(fieldToUse) as string;\n\n if (targetFieldValue) {\n const formattedSlug = formatSlug(targetFieldValue);\n\n if (value !== formattedSlug) setValue(formattedSlug);\n } else {\n if (value !== \"\") setValue(\"\");\n }\n }, [\n setValue,\n value,\n fieldToUse,\n getDataByPath\n ]\n );\n\n const handleLock = useCallback(\n (e: React.MouseEvent<Element>) => {\n e.preventDefault();\n\n dispatchFields({\n type: \"UPDATE\",\n path: checkboxFieldPath,\n value: !isLocked,\n });\n }, [\n isLocked,\n checkboxFieldPath,\n dispatchFields\n ]\n );\n\n return (\n <div className=\"field-type slug-field-component\">\n <div className=\"label-wrapper\">\n <FieldLabel htmlFor={`field-${path}`} label={label} />\n {!isLocked && (\n <Button\n buttonStyle=\"none\"\n className=\"lock-button\"\n onClick={handleGenerate}\n >\n <HugeAiGenerator className=\"icon-button\" />\n </Button>\n )}\n <Button buttonStyle=\"none\" className=\"lock-button\" onClick={handleLock}>\n {isLocked\n ? (\n <HugeLock className=\"icon-button\" />\n )\n : (\n <HugeUnlock className=\"icon-button\" />\n )}\n </Button>\n </div>\n <TextInput\n onChange={setValue}\n path={path || field.name}\n readOnly={Boolean(readOnlyFromProps || isLocked)}\n value={value}\n />\n </div>\n );\n};\n", "import type { FieldHook } from \"payload\";\n\nexport function formatSlug (val: string): string | undefined {\n const formatted = val\n ?.replace(\n / /g, \"-\"\n )\n .replace(\n /[^\\w-]+/g, \"\"\n )\n .toLowerCase();\n\n return formatted;\n}\n\nexport const formatSlugHook\n = (fallback: string): FieldHook => ({ data, operation, value, }) => {\n if (typeof value === \"string\") {\n return formatSlug(value);\n }\n\n if (operation === \"create\" || data?.slug === undefined) {\n const fallbackData = data?.[fallback];\n\n if (typeof fallbackData === \"string\") {\n return formatSlug(fallbackData);\n }\n }\n\n return value;\n };\n", "const css = `.slug-field-component .label-wrapper {\n display: flex;\n justify-content: space-between;\n align-items: center;\n gap: calc(var(--base) / 2);\n}\n.slug-field-component .lock-button {\n margin: 0;\n padding-bottom: 0.3125rem;\n}\n.slug-field-component .icon-button {\n width: 1.5rem;\n height: 1.5rem;\n}\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjoiL1VzZXJzL21tMjV6YW1hbmlhbi9Db2Rlcy9uZXhsb2FkLXNkay9wYWNrYWdlcy9wYXlsb2FkLWZpZWxkcy9zcmMvc2x1ZyIsInNvdXJjZXMiOlsiaW5kZXguc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDRTtFQUNFO0VBQ0E7RUFDQTtFQUNBOztBQUdGO0VBQ0U7RUFDQTs7QUFHRjtFQUNFO0VBQ0EiLCJzb3VyY2VzQ29udGVudCI6WyIuc2x1Zy1maWVsZC1jb21wb25lbnQge1xuICAubGFiZWwtd3JhcHBlciB7XG4gICAgZGlzcGxheTogZmxleDtcbiAgICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47XG4gICAgYWxpZ24taXRlbXM6IGNlbnRlcjtcbiAgICBnYXA6IGNhbGModmFyKC0tYmFzZSkgLyAyKTtcbiAgfVxuXG4gIC5sb2NrLWJ1dHRvbiB7XG4gICAgbWFyZ2luOiAwO1xuICAgIHBhZGRpbmctYm90dG9tOiAwLjMxMjVyZW07XG4gIH1cblxuICAuaWNvbi1idXR0b257XG4gICAgd2lkdGg6IDEuNXJlbTtcbiAgICBoZWlnaHQ6IDEuNXJlbTtcbiAgfVxufVxuIl19 */`;\ndocument.head\n .appendChild(document.createElement(\"style\"))\n .appendChild(document.createTextNode(css));\nexport {css};\n"],
|
|
5
|
+
"mappings": ";aAEA,OACE,YAAAA,EACA,UAAAC,EACA,aAAAC,EACA,cAAAC,EACA,iBAAAC,EACA,WAAAC,MACK,iBAEP,OAAgB,eAAAC,MAAmB,QCT5B,SAASC,EAAYC,EAAiC,CAU3D,OATkBA,GACd,QACA,KAAM,GACR,EACC,QACC,WAAY,EACd,EACC,YAAY,CAGjB,CCbA,IAAMC,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6wBAeZ,SAAS,KACJ,YAAY,SAAS,cAAc,OAAO,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AU,EAAIC,EAAiB,CAAE,KAAMN,GAAQH,EAAM,IAAM,CAAC,EAErE,CAAE,eAAAU,EAAgB,cAAAC,CAAe,EAAIC,EAAQ,EAE7CC,EAAWC,EAAc,CAAC,CAACC,CAAM,IAC9BA,EAAOT,CAAiB,GAAG,KACnC,EAEKU,EAAiBC,EACpBC,GAAiC,CAChCA,EAAE,eAAe,EAEjB,IAAMC,EAAmBR,EAAcV,CAAU,EAEjD,GAAIkB,EAAkB,CACpB,IAAMC,EAAgBC,EAAWF,CAAgB,EAE7CZ,IAAUa,GAAeZ,EAASY,CAAa,CACrD,MACMb,IAAU,IAAIC,EAAS,EAAE,CAEjC,EAAG,CACDA,EACAD,EACAN,EACAU,CACF,CACF,EAEMW,EAAaL,EAChBC,GAAiC,CAChCA,EAAE,eAAe,EAEjBR,EAAe,CACb,KAAM,SACN,KAAMJ,EACN,MAAO,CAACO,CACV,CAAC,CACH,EAAG,CACDA,EACAP,EACAI,CACF,CACF,EAEA,OACEhB,EAAC,OAAI,UAAU,kCACb,UAAAA,EAAC,OAAI,UAAU,gBACb,UAAAD,EAAC8B,EAAA,CAAW,QAAS,SAASpB,CAAI,GAAI,MAAOE,EAAO,EACnD,CAACQ,GACApB,EAAC+B,EAAA,CACC,YAAY,OACZ,UAAU,cACV,QAASR,EAET,SAAAvB,EAACE,EAAA,CAAgB,UAAU,cAAc,EAC3C,EAEFF,EAAC+B,EAAA,CAAO,YAAY,OAAO,UAAU,cAAc,QAASF,EACzD,SAAAT,EAEGpB,EAACK,EAAA,CAAS,UAAU,cAAc,EAGlCL,EAACI,EAAA,CAAW,UAAU,cAAc,EAE1C,GACF,EACAJ,EAACgC,EAAA,CACC,SAAUjB,EACV,KAAML,GAAQH,EAAM,KACpB,SAAU,GAAQI,GAAqBS,GACvC,MAAON,EACT,GACF,CAEJ",
|
|
6
|
+
"names": ["useField", "Button", "TextInput", "FieldLabel", "useFormFields", "useForm", "useCallback", "formatSlug", "val", "css", "jsx", "jsxs", "HugeAiGenerator", "props", "HugeUnlock", "HugeLock", "SlugComponent", "field", "fieldToUse", "checkboxFieldPathFromProps", "path", "readOnlyFromProps", "label", "checkboxFieldPath", "value", "setValue", "useField", "dispatchFields", "getDataByPath", "useForm", "isLocked", "useFormFields", "fields", "handleGenerate", "useCallback", "e", "targetFieldValue", "formattedSlug", "formatSlug", "handleLock", "FieldLabel", "Button", "TextInput"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexload-sdk/payload-fields",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "A collection of powerful, production-ready, and beautifully designed fields for Payload CMS, including an advanced date picker, automatic slug generator, and a feature-rich Lexical editor.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"payload",
|
|
10
|
+
"payloadcms",
|
|
11
|
+
"payload-cms",
|
|
12
|
+
"react",
|
|
13
|
+
"fields",
|
|
14
|
+
"custom-fields",
|
|
15
|
+
"typescript",
|
|
16
|
+
"lexical",
|
|
17
|
+
"editor",
|
|
18
|
+
"slug",
|
|
19
|
+
"date-picker",
|
|
20
|
+
"nexload",
|
|
21
|
+
"sdk"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./fields/date": {
|
|
35
|
+
"types": "./dist/fields/date/index.d.ts",
|
|
36
|
+
"import": "./dist/fields/date/index.mjs",
|
|
37
|
+
"require": "./dist/fields/date/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./fields/date/date-picker": {
|
|
40
|
+
"types": "./dist/fields/date/date-picker.d.ts",
|
|
41
|
+
"import": "./dist/fields/date/date-picker.mjs",
|
|
42
|
+
"require": "./dist/fields/date/date-picker.cjs"
|
|
43
|
+
},
|
|
44
|
+
"./fields/date/date-cell": {
|
|
45
|
+
"types": "./dist/fields/date/date-cell.d.ts",
|
|
46
|
+
"import": "./dist/fields/date/date-cell.mjs",
|
|
47
|
+
"require": "./dist/fields/date/date-cell.cjs"
|
|
48
|
+
},
|
|
49
|
+
"./fields/slug": {
|
|
50
|
+
"types": "./dist/fields/slug/index.d.ts",
|
|
51
|
+
"import": "./dist/fields/slug/index.mjs",
|
|
52
|
+
"require": "./dist/fields/slug/index.cjs"
|
|
53
|
+
},
|
|
54
|
+
"./fields/slug/slug-field": {
|
|
55
|
+
"types": "./dist/fields/slug/slug-field.d.ts",
|
|
56
|
+
"import": "./dist/fields/slug/slug-field.mjs",
|
|
57
|
+
"require": "./dist/fields/slug/slug-field.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@payloadcms/richtext-lexical": "^3.64.0",
|
|
62
|
+
"@payloadcms/ui": "^3.64.0",
|
|
63
|
+
"date-fns-jalali": "4.1.0-0",
|
|
64
|
+
"react-day-picker": "^9.11.1",
|
|
65
|
+
"payload": "^3.64.0",
|
|
66
|
+
"react": "^19.2.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/react": "^19.2.5",
|
|
70
|
+
"eslint": "^9.39.1",
|
|
71
|
+
"typescript": "^5.4.5",
|
|
72
|
+
"@nexload-sdk/bundler": "3.0.0",
|
|
73
|
+
"@nexload-sdk/eslint-config": "3.0.0",
|
|
74
|
+
"@nexload-sdk/typescript-config": "3.0.0"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "node esbuild.config.mjs",
|
|
78
|
+
"lint": "eslint . --ext .ts,.tsx"
|
|
79
|
+
}
|
|
80
|
+
}
|