@tinacms/schema-tools 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +31 -8
- package/dist/index.js +31 -8
- package/dist/types/SchemaTypes.d.ts +2 -1
- package/dist/types.d.ts +9 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -164,13 +164,24 @@ class TinaSchema {
|
|
|
164
164
|
return globalTemplate;
|
|
165
165
|
};
|
|
166
166
|
this.getCollectionByFullPath = (filepath) => {
|
|
167
|
-
const
|
|
168
|
-
return filepath.replace(/\\/g, "/").startsWith(
|
|
167
|
+
const possibleCollections = this.getCollections().filter((collection) => {
|
|
168
|
+
return filepath.replace(/\\/g, "/").startsWith(collection.path.replace(/\/?$/, "/"));
|
|
169
169
|
});
|
|
170
|
-
if (
|
|
170
|
+
if (possibleCollections.length === 0) {
|
|
171
171
|
throw new Error(`Unable to find collection for file at ${filepath}`);
|
|
172
172
|
}
|
|
173
|
-
|
|
173
|
+
if (possibleCollections.length === 1) {
|
|
174
|
+
return possibleCollections[0];
|
|
175
|
+
}
|
|
176
|
+
if (possibleCollections.length > 1) {
|
|
177
|
+
const longestMatch = possibleCollections.reduce((acc, collection) => {
|
|
178
|
+
if (collection.path.length > acc.path.length) {
|
|
179
|
+
return collection;
|
|
180
|
+
}
|
|
181
|
+
return acc;
|
|
182
|
+
});
|
|
183
|
+
return longestMatch;
|
|
184
|
+
}
|
|
174
185
|
};
|
|
175
186
|
this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
|
|
176
187
|
let template;
|
|
@@ -378,11 +389,19 @@ const resolveField = (field, schema) => {
|
|
|
378
389
|
options: field.options
|
|
379
390
|
};
|
|
380
391
|
}
|
|
392
|
+
if (field.options[0] && typeof field.options[0] === "object" && field.options[0].icon) {
|
|
393
|
+
return {
|
|
394
|
+
component: "button-toggle",
|
|
395
|
+
...field,
|
|
396
|
+
...extraFields,
|
|
397
|
+
options: field.options
|
|
398
|
+
};
|
|
399
|
+
}
|
|
381
400
|
return {
|
|
382
401
|
component: "select",
|
|
383
402
|
...field,
|
|
384
403
|
...extraFields,
|
|
385
|
-
options: [{ label: `Choose an option`, value: "" }, ...field.options]
|
|
404
|
+
options: field.ui && field.ui.component !== "select" ? field.options : [{ label: `Choose an option`, value: "" }, ...field.options]
|
|
386
405
|
};
|
|
387
406
|
}
|
|
388
407
|
if (field.list) {
|
|
@@ -540,16 +559,20 @@ const nameProp = z.string({
|
|
|
540
559
|
fatal: true
|
|
541
560
|
});
|
|
542
561
|
});
|
|
543
|
-
const Option = z.union([
|
|
562
|
+
const Option = z.union([
|
|
563
|
+
z.string(),
|
|
564
|
+
z.object({ label: z.string(), value: z.string() }),
|
|
565
|
+
z.object({ icon: z.any(), value: z.string() })
|
|
566
|
+
], {
|
|
544
567
|
errorMap: () => {
|
|
545
568
|
return {
|
|
546
|
-
message: "Invalid option array. Must be a string[] or {label: string, value: string}[]"
|
|
569
|
+
message: "Invalid option array. Must be a string[] or {label: string, value: string}[] or {icon: React.ComponentType<any>, value: string}[]"
|
|
547
570
|
};
|
|
548
571
|
}
|
|
549
572
|
});
|
|
550
573
|
const TinaField = z.object({
|
|
551
574
|
name: nameProp,
|
|
552
|
-
label: z.string().optional(),
|
|
575
|
+
label: z.string().or(z.boolean()).optional(),
|
|
553
576
|
description: z.string().optional(),
|
|
554
577
|
required: z.boolean().optional()
|
|
555
578
|
});
|
package/dist/index.js
CHANGED
|
@@ -191,13 +191,24 @@
|
|
|
191
191
|
return globalTemplate;
|
|
192
192
|
};
|
|
193
193
|
this.getCollectionByFullPath = (filepath) => {
|
|
194
|
-
const
|
|
195
|
-
return filepath.replace(/\\/g, "/").startsWith(
|
|
194
|
+
const possibleCollections = this.getCollections().filter((collection) => {
|
|
195
|
+
return filepath.replace(/\\/g, "/").startsWith(collection.path.replace(/\/?$/, "/"));
|
|
196
196
|
});
|
|
197
|
-
if (
|
|
197
|
+
if (possibleCollections.length === 0) {
|
|
198
198
|
throw new Error(`Unable to find collection for file at ${filepath}`);
|
|
199
199
|
}
|
|
200
|
-
|
|
200
|
+
if (possibleCollections.length === 1) {
|
|
201
|
+
return possibleCollections[0];
|
|
202
|
+
}
|
|
203
|
+
if (possibleCollections.length > 1) {
|
|
204
|
+
const longestMatch = possibleCollections.reduce((acc, collection) => {
|
|
205
|
+
if (collection.path.length > acc.path.length) {
|
|
206
|
+
return collection;
|
|
207
|
+
}
|
|
208
|
+
return acc;
|
|
209
|
+
});
|
|
210
|
+
return longestMatch;
|
|
211
|
+
}
|
|
201
212
|
};
|
|
202
213
|
this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
|
|
203
214
|
let template;
|
|
@@ -405,11 +416,19 @@
|
|
|
405
416
|
options: field.options
|
|
406
417
|
};
|
|
407
418
|
}
|
|
419
|
+
if (field.options[0] && typeof field.options[0] === "object" && field.options[0].icon) {
|
|
420
|
+
return {
|
|
421
|
+
component: "button-toggle",
|
|
422
|
+
...field,
|
|
423
|
+
...extraFields,
|
|
424
|
+
options: field.options
|
|
425
|
+
};
|
|
426
|
+
}
|
|
408
427
|
return {
|
|
409
428
|
component: "select",
|
|
410
429
|
...field,
|
|
411
430
|
...extraFields,
|
|
412
|
-
options: [{ label: `Choose an option`, value: "" }, ...field.options]
|
|
431
|
+
options: field.ui && field.ui.component !== "select" ? field.options : [{ label: `Choose an option`, value: "" }, ...field.options]
|
|
413
432
|
};
|
|
414
433
|
}
|
|
415
434
|
if (field.list) {
|
|
@@ -567,16 +586,20 @@
|
|
|
567
586
|
fatal: true
|
|
568
587
|
});
|
|
569
588
|
});
|
|
570
|
-
const Option = z.z.union([
|
|
589
|
+
const Option = z.z.union([
|
|
590
|
+
z.z.string(),
|
|
591
|
+
z.z.object({ label: z.z.string(), value: z.z.string() }),
|
|
592
|
+
z.z.object({ icon: z.z.any(), value: z.z.string() })
|
|
593
|
+
], {
|
|
571
594
|
errorMap: () => {
|
|
572
595
|
return {
|
|
573
|
-
message: "Invalid option array. Must be a string[] or {label: string, value: string}[]"
|
|
596
|
+
message: "Invalid option array. Must be a string[] or {label: string, value: string}[] or {icon: React.ComponentType<any>, value: string}[]"
|
|
574
597
|
};
|
|
575
598
|
}
|
|
576
599
|
});
|
|
577
600
|
const TinaField = z.z.object({
|
|
578
601
|
name: nameProp,
|
|
579
|
-
label: z.z.string().optional(),
|
|
602
|
+
label: z.z.string().or(z.z.boolean()).optional(),
|
|
580
603
|
description: z.z.string().optional(),
|
|
581
604
|
required: z.z.boolean().optional()
|
|
582
605
|
});
|
|
@@ -173,7 +173,8 @@ export interface TinaField {
|
|
|
173
173
|
}
|
|
174
174
|
declare type ScalarType<WithNamespace extends boolean> = WithNamespace extends true ? ScalarTypeWithNamespace : ScalarTypeInner;
|
|
175
175
|
export declare type Option = string | {
|
|
176
|
-
label
|
|
176
|
+
label?: string;
|
|
177
|
+
icon?: FC;
|
|
177
178
|
value: string;
|
|
178
179
|
};
|
|
179
180
|
declare type ScalarTypeInner = TinaField & TinaScalarField & {
|
package/dist/types.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ declare type FieldGeneric<Type, List extends boolean | undefined, ExtraFieldUIPr
|
|
|
193
193
|
ui?: UIField<Type, false> & ExtraFieldUIProps;
|
|
194
194
|
};
|
|
195
195
|
export interface BaseField {
|
|
196
|
-
label?: string;
|
|
196
|
+
label?: string | boolean;
|
|
197
197
|
required?: boolean;
|
|
198
198
|
name: string;
|
|
199
199
|
description?: string;
|
|
@@ -384,6 +384,7 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
384
384
|
onLogin?: (args: {
|
|
385
385
|
token: TokenObject;
|
|
386
386
|
}) => Promise<void>;
|
|
387
|
+
onLogout?: () => Promise<void>;
|
|
387
388
|
};
|
|
388
389
|
};
|
|
389
390
|
/**
|
|
@@ -431,6 +432,13 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
431
432
|
* Note that for most framworks you can omit the `index.html` portion, for Next.js see the [rewrites section](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
|
|
432
433
|
*/
|
|
433
434
|
outputFolder: string;
|
|
435
|
+
/**
|
|
436
|
+
*
|
|
437
|
+
* the host option for the vite config. This is useful when trying to run tinacms dev in a docker container.
|
|
438
|
+
*
|
|
439
|
+
* See https://vitejs.dev/config/server-options.html#server-host for more details
|
|
440
|
+
*/
|
|
441
|
+
host?: string | boolean;
|
|
434
442
|
};
|
|
435
443
|
media?: {
|
|
436
444
|
/**
|