@allejo/decap-extras 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,38 @@
1
1
  //#region src/widgets.ts
2
+ /**
3
+ * Marks a widget field as optional, allowing it to be left empty in DecapCMS.
4
+ * This modifier can be applied to any widget type to make it non-required.
5
+ *
6
+ * **DecapCMS Configuration (TypeScript)**
7
+ *
8
+ * ```typescript
9
+ * optional(stringWidget("Middle Name", "middleName"))
10
+ * ```
11
+ *
12
+ * **DecapCMS Configuration (YAML)**
13
+ *
14
+ * ```yaml
15
+ * - label: Middle Name
16
+ * name: middleName
17
+ * widget: string
18
+ * required: false
19
+ * ```
20
+ *
21
+ * **Data Store YAML**
22
+ *
23
+ * ```yaml
24
+ * middleName: # Can be left empty
25
+ * ```
26
+ *
27
+ * The `optional` modifier can be used with all widget types including complex ones:
28
+ *
29
+ * ```typescript
30
+ * optional(objectWidget("Metadata", "metadata", [stringWidget("Author", "author")]))
31
+ * optional(listWidget("Tags", "tags", stringWidget("Tag", "value")))
32
+ * ```
33
+ *
34
+ * @link https://decapcms.org/docs/widgets/#common-widget-options
35
+ */
2
36
  function optional(widget) {
3
37
  return {
4
38
  ...widget,
@@ -6,6 +40,40 @@ function optional(widget) {
6
40
  __optional: true
7
41
  };
8
42
  }
43
+ /**
44
+ * Creates a Boolean widget configuration with the given label and name, and
45
+ * optional additional options.
46
+ *
47
+ * **DecapCMS Configuration (TypeScript)**
48
+ *
49
+ * ```typescript
50
+ * boolWidget("Published", "published")
51
+ * ```
52
+ *
53
+ * **DecapCMS Configuration (YAML)**
54
+ *
55
+ * ```yaml
56
+ * - label: Published
57
+ * name: published
58
+ * widget: boolean
59
+ * ```
60
+ *
61
+ * **Data Store YAML**
62
+ *
63
+ * ```yaml
64
+ * published: true
65
+ * ```
66
+ *
67
+ * The boolean widget creates a checkbox input in the editor. This can be made
68
+ * optional using the `optional` modifier:
69
+ *
70
+ * ```typescript
71
+ * optional(boolWidget("Draft", "isDraft"))
72
+ * ```
73
+ *
74
+ * @see optional
75
+ * @link https://decapcms.org/docs/widgets/#boolean
76
+ */
9
77
  function boolWidget(label, name, options) {
10
78
  return {
11
79
  label,
@@ -14,6 +82,40 @@ function boolWidget(label, name, options) {
14
82
  ...options ?? {}
15
83
  };
16
84
  }
85
+ /**
86
+ * Creates an Image widget configuration with the given label and name, and
87
+ * optional additional options.
88
+ *
89
+ * **DecapCMS Configuration (TypeScript)**
90
+ *
91
+ * ```typescript
92
+ * imageWidget("Featured Image", "featuredImage")
93
+ * ```
94
+ *
95
+ * **DecapCMS Configuration (YAML)**
96
+ *
97
+ * ```yaml
98
+ * - label: Featured Image
99
+ * name: featuredImage
100
+ * widget: image
101
+ * ```
102
+ *
103
+ * **Data Store YAML**
104
+ *
105
+ * ```yaml
106
+ * featuredImage: /images/hero.jpg
107
+ * ```
108
+ *
109
+ * The image widget provides file upload functionality with image preview
110
+ * capabilities. It can be made optional using the `optional` modifier:
111
+ *
112
+ * ```typescript
113
+ * optional(imageWidget("Avatar", "avatar"))
114
+ * ```
115
+ *
116
+ * @see optional
117
+ * @link https://decapcms.org/docs/widgets/#image
118
+ */
17
119
  function imageWidget(label, name, options) {
18
120
  return {
19
121
  label,
@@ -28,17 +130,61 @@ function listWidget(label, name, fields, options) {
28
130
  name,
29
131
  widget: "list",
30
132
  ...options ?? {},
31
- ...Array.isArray(fields) ? { fields } : { field: fields }
32
- };
33
- }
34
- function markdownWidget(label, name, options) {
35
- return {
36
- label,
37
- name,
38
- widget: "richtext",
39
- ...options ?? {}
133
+ ...Array.isArray(fields) ? { fields } : fields.widget === "object" ? { fields: fields.fields } : { field: fields }
40
134
  };
41
135
  }
136
+ /**
137
+ * Creates an Object widget configuration with the given label, name, fields, and
138
+ * optional additional options.
139
+ *
140
+ * The object widget groups multiple fields together as a nested object in the
141
+ * data store. This is useful for creating structured data with related properties.
142
+ *
143
+ * **DecapCMS Configuration (TypeScript)**
144
+ *
145
+ * ```typescript
146
+ * objectWidget("Author", "author", [
147
+ * stringWidget("Name", "name"),
148
+ * stringWidget("Email", "email"),
149
+ * ])
150
+ * ```
151
+ *
152
+ * **DecapCMS Configuration (YAML)**
153
+ *
154
+ * ```yaml
155
+ * - label: Author
156
+ * name: author
157
+ * widget: object
158
+ * fields:
159
+ * - label: Name
160
+ * name: name
161
+ * widget: string
162
+ * - label: Email
163
+ * name: email
164
+ * widget: string
165
+ * ```
166
+ *
167
+ * **Data Store YAML**
168
+ *
169
+ * ```yaml
170
+ * author:
171
+ * name: Jane Doe
172
+ * email: jane@example.com
173
+ * ```
174
+ *
175
+ * Objects can be nested within lists or other objects to create complex data
176
+ * structures. They can also be made optional using the `optional` modifier:
177
+ *
178
+ * ```typescript
179
+ * optional(objectWidget("Metadata", "metadata", [
180
+ * stringWidget("SEO Title", "seoTitle"),
181
+ * textWidget("Description", "description"),
182
+ * ]))
183
+ * ```
184
+ *
185
+ * @see optional
186
+ * @link https://decapcms.org/docs/widgets/#object
187
+ */
42
188
  function objectWidget(label, name, fields, options) {
43
189
  return {
44
190
  label,
@@ -48,6 +194,40 @@ function objectWidget(label, name, fields, options) {
48
194
  fields
49
195
  };
50
196
  }
197
+ /**
198
+ * Creates a Number widget configuration with the given label and name, and
199
+ * optional additional options.
200
+ *
201
+ * **DecapCMS Configuration (TypeScript)**
202
+ *
203
+ * ```typescript
204
+ * numberWidget("Priority", "priority")
205
+ * ```
206
+ *
207
+ * **DecapCMS Configuration (YAML)**
208
+ *
209
+ * ```yaml
210
+ * - label: Priority
211
+ * name: priority
212
+ * widget: number
213
+ * ```
214
+ *
215
+ * **Data Store YAML**
216
+ *
217
+ * ```yaml
218
+ * priority: 1
219
+ * ```
220
+ *
221
+ * The number widget provides numeric input with optional min, max, and step
222
+ * constraints. It can be made optional using the `optional` modifier:
223
+ *
224
+ * ```typescript
225
+ * optional(numberWidget("Views", "views"))
226
+ * ```
227
+ *
228
+ * @see optional
229
+ * @link https://decapcms.org/docs/widgets/#number
230
+ */
51
231
  function numberWidget(label, name, options) {
52
232
  return {
53
233
  label,
@@ -56,6 +236,46 @@ function numberWidget(label, name, options) {
56
236
  ...options ?? {}
57
237
  };
58
238
  }
239
+ /**
240
+ * Creates a Select widget configuration with the given label, name, choices, and
241
+ * optional additional options.
242
+ *
243
+ * The select widget creates a dropdown menu with predefined options. The `choices`
244
+ * array becomes the available options in the YAML configuration.
245
+ *
246
+ * **DecapCMS Configuration (TypeScript)**
247
+ *
248
+ * ```typescript
249
+ * selectWidget("Status", "status", ["draft", "published", "archived"] as const)
250
+ * ```
251
+ *
252
+ * **DecapCMS Configuration (YAML)**
253
+ *
254
+ * ```yaml
255
+ * - label: Status
256
+ * name: status
257
+ * widget: select
258
+ * options:
259
+ * - draft
260
+ * - published
261
+ * - archived
262
+ * ```
263
+ *
264
+ * **Data Store YAML**
265
+ *
266
+ * ```yaml
267
+ * status: published
268
+ * ```
269
+ *
270
+ * The select widget can be made optional using the `optional` modifier:
271
+ *
272
+ * ```typescript
273
+ * optional(selectWidget("Category", "category", ["tech", "lifestyle", "business"] as const))
274
+ * ```
275
+ *
276
+ * @see optional
277
+ * @link https://decapcms.org/docs/widgets/#select
278
+ */
59
279
  function selectWidget(label, name, choices, options) {
60
280
  return {
61
281
  label,
@@ -65,6 +285,44 @@ function selectWidget(label, name, choices, options) {
65
285
  options: choices ?? []
66
286
  };
67
287
  }
288
+ /**
289
+ * Creates a String widget configuration with the given label and name, and
290
+ * optional additional options.
291
+ *
292
+ * The string widget provides a single-line text input field for short text content.
293
+ * Unlike the text widget which provides multi-line input, the string widget is
294
+ * designed for concise, single-line values.
295
+ *
296
+ * **DecapCMS Configuration (TypeScript)**
297
+ *
298
+ * ```typescript
299
+ * stringWidget("Title", "title")
300
+ * ```
301
+ *
302
+ * **DecapCMS Configuration (YAML)**
303
+ *
304
+ * ```yaml
305
+ * - label: Title
306
+ * name: title
307
+ * widget: string
308
+ * ```
309
+ *
310
+ * **Data Store YAML**
311
+ *
312
+ * ```yaml
313
+ * title: Welcome to My Blog
314
+ * ```
315
+ *
316
+ * The string widget can be made optional using the `optional` modifier:
317
+ *
318
+ * ```typescript
319
+ * optional(stringWidget("Slug", "slug"))
320
+ * ```
321
+ *
322
+ * @see optional
323
+ * @see textWidget
324
+ * @link https://decapcms.org/docs/widgets/#string
325
+ */
68
326
  function stringWidget(label, name, options) {
69
327
  return {
70
328
  label,
@@ -73,6 +331,47 @@ function stringWidget(label, name, options) {
73
331
  ...options ?? {}
74
332
  };
75
333
  }
334
+ /**
335
+ * Creates a Text widget configuration with the given label and name, and
336
+ * optional additional options.
337
+ *
338
+ * The text widget provides a multi-line text input field for longer text content.
339
+ * Unlike the string widget which provides single-line input, the text widget is
340
+ * designed for paragraphs and multi-line content.
341
+ *
342
+ * **DecapCMS Configuration (TypeScript)**
343
+ *
344
+ * ```typescript
345
+ * textWidget("Description", "description")
346
+ * ```
347
+ *
348
+ * **DecapCMS Configuration (YAML)**
349
+ *
350
+ * ```yaml
351
+ * - label: Description
352
+ * name: description
353
+ * widget: text
354
+ * ```
355
+ *
356
+ * **Data Store YAML**
357
+ *
358
+ * ```yaml
359
+ * description: |-
360
+ * This is a longer description that spans
361
+ * multiple lines in the data store.
362
+ * ```
363
+ *
364
+ * The text widget can be made optional using the `optional` modifier:
365
+ *
366
+ * ```typescript
367
+ * optional(textWidget("Notes", "notes"))
368
+ * ```
369
+ *
370
+ * @see optional
371
+ * @see stringWidget
372
+ * @see markdownWidget
373
+ * @link https://decapcms.org/docs/widgets/#text
374
+ */
76
375
  function textWidget(label, name, options) {
77
376
  return {
78
377
  label,
@@ -115,5 +414,5 @@ const INLINE_MARKDOWN = {
115
414
  };
116
415
 
117
416
  //#endregion
118
- export { INLINE_MARKDOWN, RICH_MARKDOWN, boolWidget, imageWidget, listWidget, markdownWidget, numberWidget, objectWidget, optional, selectWidget, stringWidget, textWidget };
417
+ export { INLINE_MARKDOWN, RICH_MARKDOWN, boolWidget, imageWidget, listWidget, numberWidget, objectWidget, optional, selectWidget, stringWidget, textWidget };
119
418
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/widgets.ts"],"sourcesContent":["import type {\n\tCmsField,\n\tCmsFieldBoolean,\n\tCmsFieldFileOrImage,\n\tCmsFieldList,\n\tCmsFieldMarkdown,\n\tCmsFieldNumber,\n\tCmsFieldObject,\n\tCmsFieldSelect,\n\tCmsFieldStringOrText,\n} from 'decap-cms-core';\n\nimport type { OptionalWidget, WidgetOpts } from './api.js';\n\n// Widget Modifiers\n\nexport function optional<T extends CmsField>(widget: T): OptionalWidget<T> {\n\treturn {\n\t\t...widget,\n\t\trequired: false as const,\n\t\t__optional: true as const,\n\t};\n}\n\n// Primitive Widgets\n\nexport function boolWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldBoolean>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'boolean',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\nexport function imageWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldFileOrImage>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'image',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\nexport function listWidget<T extends string, F extends CmsField>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n): { label: string; name: T; widget: 'list'; field: F };\nexport function listWidget<T extends string, F extends CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n): { label: string; name: T; widget: 'list'; fields: F };\nexport function listWidget<T extends string, F extends CmsField | CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'list',\n\t\t...(options ?? {}),\n\t\t...(Array.isArray(fields) ? { fields } : { field: fields }),\n\t} as const;\n}\n\nexport function markdownWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldMarkdown>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'richtext' as 'string',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\nexport function objectWidget<T extends string, F extends CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldObject>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'object',\n\t\t...(options ?? {}),\n\t\tfields,\n\t} as const satisfies CmsField;\n}\n\nexport function numberWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldNumber>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'number',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\nexport function selectWidget<T extends string, O extends string[]>(\n\tlabel: string,\n\tname: T,\n\tchoices: O,\n\toptions?: WidgetOpts<CmsFieldSelect>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'select',\n\t\t...(options ?? {}),\n\t\toptions: choices ?? [],\n\t} as const satisfies CmsField;\n}\n\nexport function stringWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldStringOrText>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'string',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\nexport function textWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldStringOrText>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'text',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n// Reusable Widget Configurations\n\n/**\n * Stripped down Markdown widget configuration that does the following:\n *\n * - Allows bold, italic, lists (bullet + numbered), quotes\n * - No images or code block components\n * - Rich Text preview only\n */\nexport const RICH_MARKDOWN: WidgetOpts<CmsFieldMarkdown> = {\n\tbuttons: [\n\t\t'bold',\n\t\t'bulleted-list',\n\t\t'italic',\n\t\t'link',\n\t\t'numbered-list',\n\t\t'quote',\n\t],\n\teditor_components: [],\n\tmodes: ['rich_text'],\n};\n\n/**\n * Stripped down Markdown Widget configuration that allows only inline\n * elements (e.g., no lists, quotes, or headings) and rich text preview only.\n */\nexport const INLINE_MARKDOWN: WidgetOpts<CmsFieldMarkdown> = {\n\tbuttons: ['bold', 'italic', 'link'],\n\teditor_components: [],\n\tmodes: ['rich_text'],\n};\n"],"mappings":";AAgBA,SAAgB,SAA6B,QAA8B;CAC1E,OAAO;EACN,GAAG;EACH,UAAU;EACV,YAAY;CACb;AACD;AAIA,SAAgB,WACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AAEA,SAAgB,YACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AAcA,SAAgB,WACf,OACA,MACA,QACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB,GAAI,MAAM,QAAQ,MAAM,IAAI,EAAE,OAAO,IAAI,EAAE,OAAO,OAAO;CAC1D;AACD;AAEA,SAAgB,eACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AAEA,SAAgB,aACf,OACA,MACA,QACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB;CACD;AACD;AAEA,SAAgB,aACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AAEA,SAAgB,aACf,OACA,MACA,SACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB,SAAS,WAAW,CAAC;CACtB;AACD;AAEA,SAAgB,aACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AAEA,SAAgB,WACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;;;;;;;;AAWA,MAAa,gBAA8C;CAC1D,SAAS;EACR;EACA;EACA;EACA;EACA;EACA;CACD;CACA,mBAAmB,CAAC;CACpB,OAAO,CAAC,WAAW;AACpB;;;;;AAMA,MAAa,kBAAgD;CAC5D,SAAS;EAAC;EAAQ;EAAU;CAAM;CAClC,mBAAmB,CAAC;CACpB,OAAO,CAAC,WAAW;AACpB"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/widgets.ts"],"sourcesContent":["import type {\n\tCmsField,\n\tCmsFieldBoolean,\n\tCmsFieldFileOrImage,\n\tCmsFieldList,\n\tCmsFieldMarkdown,\n\tCmsFieldNumber,\n\tCmsFieldObject,\n\tCmsFieldSelect,\n\tCmsFieldStringOrText,\n} from 'decap-cms-core';\n\nimport type { OptionalWidget, WidgetOpts } from './api.js';\n\n// Widget Modifiers\n\n/**\n * Marks a widget field as optional, allowing it to be left empty in DecapCMS.\n * This modifier can be applied to any widget type to make it non-required.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * optional(stringWidget(\"Middle Name\", \"middleName\"))\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Middle Name\n * name: middleName\n * widget: string\n * required: false\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * middleName: # Can be left empty\n * ```\n *\n * The `optional` modifier can be used with all widget types including complex ones:\n *\n * ```typescript\n * optional(objectWidget(\"Metadata\", \"metadata\", [stringWidget(\"Author\", \"author\")]))\n * optional(listWidget(\"Tags\", \"tags\", stringWidget(\"Tag\", \"value\")))\n * ```\n *\n * @link https://decapcms.org/docs/widgets/#common-widget-options\n */\nexport function optional<T extends CmsField>(widget: T): OptionalWidget<T> {\n\treturn {\n\t\t...widget,\n\t\trequired: false as const,\n\t\t__optional: true as const,\n\t};\n}\n\n// Primitive Widgets\n\n/**\n * Creates a Boolean widget configuration with the given label and name, and\n * optional additional options.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * boolWidget(\"Published\", \"published\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Published\n * name: published\n * widget: boolean\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * published: true\n * ```\n *\n * The boolean widget creates a checkbox input in the editor. This can be made\n * optional using the `optional` modifier:\n *\n * ```typescript\n * optional(boolWidget(\"Draft\", \"isDraft\"))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#boolean\n */\nexport function boolWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldBoolean>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'boolean',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates an Image widget configuration with the given label and name, and\n * optional additional options.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * imageWidget(\"Featured Image\", \"featuredImage\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Featured Image\n * name: featuredImage\n * widget: image\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * featuredImage: /images/hero.jpg\n * ```\n *\n * The image widget provides file upload functionality with image preview\n * capabilities. It can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(imageWidget(\"Avatar\", \"avatar\"))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#image\n */\nexport function imageWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldFileOrImage>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'image',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates a List widget configuration with the given label, name, field(s), and\n * optional additional options.\n *\n * The `listWidget` function accepts either a single field (which gets expanded\n * for object types) or an array of fields. When passed an object widget, its\n * fields are automatically extracted and expanded.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * Single field example:\n *\n * ```typescript\n * listWidget(\"Tags\", \"tags\", stringWidget(\"Tag\", \"value\"))\n * ```\n *\n * Multiple fields example:\n *\n * ```typescript\n * listWidget(\"Authors\", \"authors\", [\n * stringWidget(\"Name\", \"name\"),\n * imageWidget(\"Avatar\", \"avatar\"),\n * ])\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * Single field:\n *\n * ```yaml\n * - label: Tags\n * name: tags\n * widget: list\n * field:\n * label: Tag\n * name: value\n * widget: string\n * ```\n *\n * Multiple fields:\n *\n * ```yaml\n * - label: Authors\n * name: authors\n * widget: list\n * fields:\n * - label: Name\n * name: name\n * widget: string\n * - label: Avatar\n * name: avatar\n * widget: image\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * tags:\n * - value: React\n * - value: TypeScript\n *\n * authors:\n * - name: Jane Doe\n * avatar: /images/jane.jpg\n * - name: John Smith\n * avatar: /images/john.jpg\n * ```\n *\n * The list widget can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(listWidget(\"Tags\", \"tags\", stringWidget(\"Tag\", \"value\")))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#list\n */\nexport function listWidget<T extends string, F extends CmsField>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n): { label: string; name: T; widget: 'list'; field: F };\nexport function listWidget<T extends string, F extends CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n): { label: string; name: T; widget: 'list'; fields: F };\nexport function listWidget<T extends string, F extends CmsField | CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldList>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'list',\n\t\t...(options ?? {}),\n\t\t...(Array.isArray(fields)\n\t\t\t? { fields }\n\t\t\t: fields.widget === 'object'\n\t\t\t\t? { fields: (fields as CmsFieldObject).fields }\n\t\t\t\t: { field: fields }),\n\t} as const;\n}\n\n/**\n * Creates an Object widget configuration with the given label, name, fields, and\n * optional additional options.\n *\n * The object widget groups multiple fields together as a nested object in the\n * data store. This is useful for creating structured data with related properties.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * objectWidget(\"Author\", \"author\", [\n * stringWidget(\"Name\", \"name\"),\n * stringWidget(\"Email\", \"email\"),\n * ])\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Author\n * name: author\n * widget: object\n * fields:\n * - label: Name\n * name: name\n * widget: string\n * - label: Email\n * name: email\n * widget: string\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * author:\n * name: Jane Doe\n * email: jane@example.com\n * ```\n *\n * Objects can be nested within lists or other objects to create complex data\n * structures. They can also be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(objectWidget(\"Metadata\", \"metadata\", [\n * stringWidget(\"SEO Title\", \"seoTitle\"),\n * textWidget(\"Description\", \"description\"),\n * ]))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#object\n */\nexport function objectWidget<T extends string, F extends CmsField[]>(\n\tlabel: string,\n\tname: T,\n\tfields: F,\n\toptions?: WidgetOpts<CmsFieldObject>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'object',\n\t\t...(options ?? {}),\n\t\tfields,\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates a Number widget configuration with the given label and name, and\n * optional additional options.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * numberWidget(\"Priority\", \"priority\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Priority\n * name: priority\n * widget: number\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * priority: 1\n * ```\n *\n * The number widget provides numeric input with optional min, max, and step\n * constraints. It can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(numberWidget(\"Views\", \"views\"))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#number\n */\nexport function numberWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldNumber>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'number',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates a Select widget configuration with the given label, name, choices, and\n * optional additional options.\n *\n * The select widget creates a dropdown menu with predefined options. The `choices`\n * array becomes the available options in the YAML configuration.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * selectWidget(\"Status\", \"status\", [\"draft\", \"published\", \"archived\"] as const)\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Status\n * name: status\n * widget: select\n * options:\n * - draft\n * - published\n * - archived\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * status: published\n * ```\n *\n * The select widget can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(selectWidget(\"Category\", \"category\", [\"tech\", \"lifestyle\", \"business\"] as const))\n * ```\n *\n * @see optional\n * @link https://decapcms.org/docs/widgets/#select\n */\nexport function selectWidget<T extends string, O extends string[]>(\n\tlabel: string,\n\tname: T,\n\tchoices: O,\n\toptions?: WidgetOpts<CmsFieldSelect>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'select',\n\t\t...(options ?? {}),\n\t\toptions: choices ?? [],\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates a String widget configuration with the given label and name, and\n * optional additional options.\n *\n * The string widget provides a single-line text input field for short text content.\n * Unlike the text widget which provides multi-line input, the string widget is\n * designed for concise, single-line values.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * stringWidget(\"Title\", \"title\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Title\n * name: title\n * widget: string\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * title: Welcome to My Blog\n * ```\n *\n * The string widget can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(stringWidget(\"Slug\", \"slug\"))\n * ```\n *\n * @see optional\n * @see textWidget\n * @link https://decapcms.org/docs/widgets/#string\n */\nexport function stringWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldStringOrText>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'string',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n/**\n * Creates a Text widget configuration with the given label and name, and\n * optional additional options.\n *\n * The text widget provides a multi-line text input field for longer text content.\n * Unlike the string widget which provides single-line input, the text widget is\n * designed for paragraphs and multi-line content.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * textWidget(\"Description\", \"description\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Description\n * name: description\n * widget: text\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * description: |-\n * This is a longer description that spans\n * multiple lines in the data store.\n * ```\n *\n * The text widget can be made optional using the `optional` modifier:\n *\n * ```typescript\n * optional(textWidget(\"Notes\", \"notes\"))\n * ```\n *\n * @see optional\n * @see stringWidget\n * @see markdownWidget\n * @link https://decapcms.org/docs/widgets/#text\n */\nexport function textWidget<T extends string>(\n\tlabel: string,\n\tname: T,\n\toptions?: WidgetOpts<CmsFieldStringOrText>,\n) {\n\treturn {\n\t\tlabel,\n\t\tname,\n\t\twidget: 'text',\n\t\t...(options ?? {}),\n\t} as const satisfies CmsField;\n}\n\n// Reusable Widget Configurations\n\n/**\n * Stripped down Markdown widget configuration that does the following:\n *\n * - Allows bold, italic, lists (bullet + numbered), quotes\n * - No images or code block components\n * - Rich Text preview only\n */\nexport const RICH_MARKDOWN: WidgetOpts<CmsFieldMarkdown> = {\n\tbuttons: [\n\t\t'bold',\n\t\t'bulleted-list',\n\t\t'italic',\n\t\t'link',\n\t\t'numbered-list',\n\t\t'quote',\n\t],\n\teditor_components: [],\n\tmodes: ['rich_text'],\n};\n\n/**\n * Stripped down Markdown Widget configuration that allows only inline\n * elements (e.g., no lists, quotes, or headings) and rich text preview only.\n */\nexport const INLINE_MARKDOWN: WidgetOpts<CmsFieldMarkdown> = {\n\tbuttons: ['bold', 'italic', 'link'],\n\teditor_components: [],\n\tmodes: ['rich_text'],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,SAA6B,QAA8B;CAC1E,OAAO;EACN,GAAG;EACH,UAAU;EACV,YAAY;CACb;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,WACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,YACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;AA2FA,SAAgB,WACf,OACA,MACA,QACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB,GAAI,MAAM,QAAQ,MAAM,IACrB,EAAE,OAAO,IACT,OAAO,WAAW,WACjB,EAAE,QAAS,OAA0B,OAAO,IAC5C,EAAE,OAAO,OAAO;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,aACf,OACA,MACA,QACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,aACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,aACf,OACA,MACA,SACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;EAChB,SAAS,WAAW,CAAC;CACtB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,aACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,WACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;AACD;;;;;;;;AAWA,MAAa,gBAA8C;CAC1D,SAAS;EACR;EACA;EACA;EACA;EACA;EACA;CACD;CACA,mBAAmB,CAAC;CACpB,OAAO,CAAC,WAAW;AACpB;;;;;AAMA,MAAa,kBAAgD;CAC5D,SAAS;EAAC;EAAQ;EAAU;CAAM;CAClC,mBAAmB,CAAC;CACpB,OAAO,CAAC,WAAW;AACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allejo/decap-extras",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A TypeScript utility library for Decap CMS with utility types to derive types from Decap CMS configuration files.",
5
5
  "keywords": [
6
6
  "decapcms"