@allejo/decap-extras 0.0.6 → 0.0.8

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,9 +130,51 @@ function listWidget(label, name, fields, options) {
28
130
  name,
29
131
  widget: "list",
30
132
  ...options ?? {},
31
- ...Array.isArray(fields) ? { fields } : { field: fields }
133
+ ...Array.isArray(fields) ? { fields } : fields.widget === "object" ? { fields: fields.fields } : { field: fields }
32
134
  };
33
135
  }
136
+ /**
137
+ * Creates a Markdown widget configuration with the given label and name, and
138
+ * optional additional options.
139
+ *
140
+ * **DecapCMS Configuration (TypeScript)**
141
+ *
142
+ * ```typescript
143
+ * markdownWidget("Biography", "biography")
144
+ * ```
145
+ *
146
+ * **DecapCMS Configuration (YAML)**
147
+ *
148
+ * ```yaml
149
+ * - label: Biography
150
+ * name: biography
151
+ * widget: richtext
152
+ * ```
153
+ *
154
+ * **Data Store YAML**
155
+ *
156
+ * ```yaml
157
+ * biography: |-
158
+ * Hello, world. I was born in the year 2000.
159
+ * ```
160
+ *
161
+ * There are pre-configured constants available for use with the `options`
162
+ * parameter:
163
+ *
164
+ * - INLINE_MARKDOWN
165
+ * - RICH_MARKDOWN
166
+ *
167
+ * For example, to use the `RICH_MARKDOWN` configuration, you can do the following:
168
+ *
169
+ * ```typescript
170
+ * markdownWidget("Biography", "biography", RICH_MARKDOWN)
171
+ * ```
172
+ *
173
+ * @see INLINE_MARKDOWN
174
+ * @see RICH_MARKDOWN
175
+ *
176
+ * @link https://decapcms.org/docs/widgets/#Richtext%20(Beta)
177
+ */
34
178
  function markdownWidget(label, name, options) {
35
179
  return {
36
180
  label,
@@ -39,6 +183,58 @@ function markdownWidget(label, name, options) {
39
183
  ...options ?? {}
40
184
  };
41
185
  }
186
+ /**
187
+ * Creates an Object widget configuration with the given label, name, fields, and
188
+ * optional additional options.
189
+ *
190
+ * The object widget groups multiple fields together as a nested object in the
191
+ * data store. This is useful for creating structured data with related properties.
192
+ *
193
+ * **DecapCMS Configuration (TypeScript)**
194
+ *
195
+ * ```typescript
196
+ * objectWidget("Author", "author", [
197
+ * stringWidget("Name", "name"),
198
+ * stringWidget("Email", "email"),
199
+ * ])
200
+ * ```
201
+ *
202
+ * **DecapCMS Configuration (YAML)**
203
+ *
204
+ * ```yaml
205
+ * - label: Author
206
+ * name: author
207
+ * widget: object
208
+ * fields:
209
+ * - label: Name
210
+ * name: name
211
+ * widget: string
212
+ * - label: Email
213
+ * name: email
214
+ * widget: string
215
+ * ```
216
+ *
217
+ * **Data Store YAML**
218
+ *
219
+ * ```yaml
220
+ * author:
221
+ * name: Jane Doe
222
+ * email: jane@example.com
223
+ * ```
224
+ *
225
+ * Objects can be nested within lists or other objects to create complex data
226
+ * structures. They can also be made optional using the `optional` modifier:
227
+ *
228
+ * ```typescript
229
+ * optional(objectWidget("Metadata", "metadata", [
230
+ * stringWidget("SEO Title", "seoTitle"),
231
+ * textWidget("Description", "description"),
232
+ * ]))
233
+ * ```
234
+ *
235
+ * @see optional
236
+ * @link https://decapcms.org/docs/widgets/#object
237
+ */
42
238
  function objectWidget(label, name, fields, options) {
43
239
  return {
44
240
  label,
@@ -48,6 +244,40 @@ function objectWidget(label, name, fields, options) {
48
244
  fields
49
245
  };
50
246
  }
247
+ /**
248
+ * Creates a Number widget configuration with the given label and name, and
249
+ * optional additional options.
250
+ *
251
+ * **DecapCMS Configuration (TypeScript)**
252
+ *
253
+ * ```typescript
254
+ * numberWidget("Priority", "priority")
255
+ * ```
256
+ *
257
+ * **DecapCMS Configuration (YAML)**
258
+ *
259
+ * ```yaml
260
+ * - label: Priority
261
+ * name: priority
262
+ * widget: number
263
+ * ```
264
+ *
265
+ * **Data Store YAML**
266
+ *
267
+ * ```yaml
268
+ * priority: 1
269
+ * ```
270
+ *
271
+ * The number widget provides numeric input with optional min, max, and step
272
+ * constraints. It can be made optional using the `optional` modifier:
273
+ *
274
+ * ```typescript
275
+ * optional(numberWidget("Views", "views"))
276
+ * ```
277
+ *
278
+ * @see optional
279
+ * @link https://decapcms.org/docs/widgets/#number
280
+ */
51
281
  function numberWidget(label, name, options) {
52
282
  return {
53
283
  label,
@@ -56,6 +286,46 @@ function numberWidget(label, name, options) {
56
286
  ...options ?? {}
57
287
  };
58
288
  }
289
+ /**
290
+ * Creates a Select widget configuration with the given label, name, choices, and
291
+ * optional additional options.
292
+ *
293
+ * The select widget creates a dropdown menu with predefined options. The `choices`
294
+ * array becomes the available options in the YAML configuration.
295
+ *
296
+ * **DecapCMS Configuration (TypeScript)**
297
+ *
298
+ * ```typescript
299
+ * selectWidget("Status", "status", ["draft", "published", "archived"] as const)
300
+ * ```
301
+ *
302
+ * **DecapCMS Configuration (YAML)**
303
+ *
304
+ * ```yaml
305
+ * - label: Status
306
+ * name: status
307
+ * widget: select
308
+ * options:
309
+ * - draft
310
+ * - published
311
+ * - archived
312
+ * ```
313
+ *
314
+ * **Data Store YAML**
315
+ *
316
+ * ```yaml
317
+ * status: published
318
+ * ```
319
+ *
320
+ * The select widget can be made optional using the `optional` modifier:
321
+ *
322
+ * ```typescript
323
+ * optional(selectWidget("Category", "category", ["tech", "lifestyle", "business"] as const))
324
+ * ```
325
+ *
326
+ * @see optional
327
+ * @link https://decapcms.org/docs/widgets/#select
328
+ */
59
329
  function selectWidget(label, name, choices, options) {
60
330
  return {
61
331
  label,
@@ -65,6 +335,44 @@ function selectWidget(label, name, choices, options) {
65
335
  options: choices ?? []
66
336
  };
67
337
  }
338
+ /**
339
+ * Creates a String widget configuration with the given label and name, and
340
+ * optional additional options.
341
+ *
342
+ * The string widget provides a single-line text input field for short text content.
343
+ * Unlike the text widget which provides multi-line input, the string widget is
344
+ * designed for concise, single-line values.
345
+ *
346
+ * **DecapCMS Configuration (TypeScript)**
347
+ *
348
+ * ```typescript
349
+ * stringWidget("Title", "title")
350
+ * ```
351
+ *
352
+ * **DecapCMS Configuration (YAML)**
353
+ *
354
+ * ```yaml
355
+ * - label: Title
356
+ * name: title
357
+ * widget: string
358
+ * ```
359
+ *
360
+ * **Data Store YAML**
361
+ *
362
+ * ```yaml
363
+ * title: Welcome to My Blog
364
+ * ```
365
+ *
366
+ * The string widget can be made optional using the `optional` modifier:
367
+ *
368
+ * ```typescript
369
+ * optional(stringWidget("Slug", "slug"))
370
+ * ```
371
+ *
372
+ * @see optional
373
+ * @see textWidget
374
+ * @link https://decapcms.org/docs/widgets/#string
375
+ */
68
376
  function stringWidget(label, name, options) {
69
377
  return {
70
378
  label,
@@ -73,6 +381,47 @@ function stringWidget(label, name, options) {
73
381
  ...options ?? {}
74
382
  };
75
383
  }
384
+ /**
385
+ * Creates a Text widget configuration with the given label and name, and
386
+ * optional additional options.
387
+ *
388
+ * The text widget provides a multi-line text input field for longer text content.
389
+ * Unlike the string widget which provides single-line input, the text widget is
390
+ * designed for paragraphs and multi-line content.
391
+ *
392
+ * **DecapCMS Configuration (TypeScript)**
393
+ *
394
+ * ```typescript
395
+ * textWidget("Description", "description")
396
+ * ```
397
+ *
398
+ * **DecapCMS Configuration (YAML)**
399
+ *
400
+ * ```yaml
401
+ * - label: Description
402
+ * name: description
403
+ * widget: text
404
+ * ```
405
+ *
406
+ * **Data Store YAML**
407
+ *
408
+ * ```yaml
409
+ * description: |-
410
+ * This is a longer description that spans
411
+ * multiple lines in the data store.
412
+ * ```
413
+ *
414
+ * The text widget can be made optional using the `optional` modifier:
415
+ *
416
+ * ```typescript
417
+ * optional(textWidget("Notes", "notes"))
418
+ * ```
419
+ *
420
+ * @see optional
421
+ * @see stringWidget
422
+ * @see markdownWidget
423
+ * @link https://decapcms.org/docs/widgets/#text
424
+ */
76
425
  function textWidget(label, name, options) {
77
426
  return {
78
427
  label,
@@ -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 a Markdown widget configuration with the given label and name, and\n * optional additional options.\n *\n * **DecapCMS Configuration (TypeScript)**\n *\n * ```typescript\n * markdownWidget(\"Biography\", \"biography\")\n * ```\n *\n * **DecapCMS Configuration (YAML)**\n *\n * ```yaml\n * - label: Biography\n * name: biography\n * widget: richtext\n * ```\n *\n * **Data Store YAML**\n *\n * ```yaml\n * biography: |-\n * Hello, world. I was born in the year 2000.\n * ```\n *\n * There are pre-configured constants available for use with the `options`\n * parameter:\n *\n * - INLINE_MARKDOWN\n * - RICH_MARKDOWN\n *\n * For example, to use the `RICH_MARKDOWN` configuration, you can do the following:\n *\n * ```typescript\n * markdownWidget(\"Biography\", \"biography\", RICH_MARKDOWN)\n * ```\n *\n * @see INLINE_MARKDOWN\n * @see RICH_MARKDOWN\n *\n * @link https://decapcms.org/docs/widgets/#Richtext%20(Beta)\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\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,eACf,OACA,MACA,SACC;CACD,OAAO;EACN;EACA;EACA,QAAQ;EACR,GAAI,WAAW,CAAC;CACjB;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.8",
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"