@tinacms/schema-tools 0.1.9 → 0.2.1

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.
@@ -0,0 +1,462 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ declare type Doc = {
14
+ _sys: {
15
+ title?: string;
16
+ template: string;
17
+ breadcrumbs: string[];
18
+ path: string;
19
+ basename: string;
20
+ relativePath: string;
21
+ filename: string;
22
+ extension: string;
23
+ };
24
+ };
25
+ /**
26
+ *
27
+ */
28
+ export interface UICollection {
29
+ filename?: {
30
+ /**
31
+ * A callback which receives form values as an argument. The return value
32
+ * here will be used as the filename (the extension is not necessary)
33
+ *
34
+ * eg:
35
+ * ```ts
36
+ * slugify: (values) => values.title.toLowerCase().split(" ").join("-")
37
+ * ```
38
+ */
39
+ slugify?: (values: Record<string, any>) => string;
40
+ /**
41
+ * When set to `true`, editors won't be able to modify the filename
42
+ */
43
+ readonly?: boolean;
44
+ };
45
+ /**
46
+ * Forms for this collection will be editable from the global sidebar rather than the form panel
47
+ */
48
+ global?: boolean | {
49
+ icon?: any;
50
+ layout: 'fullscreen' | 'popup';
51
+ };
52
+ /**
53
+ * Provide the path that your document is viewable on your site
54
+ *
55
+ * eg:
56
+ * ```ts
57
+ * router: ({ document }) => {
58
+ * return `blog-posts/${document._sys.filename}`;
59
+ * }
60
+ * ```
61
+ */
62
+ router?: (args: {
63
+ document: Doc;
64
+ collection: Collection;
65
+ }) => string | undefined;
66
+ }
67
+ export declare type Option = string | {
68
+ label: string;
69
+ value: string;
70
+ };
71
+ import type React from 'react';
72
+ declare type Meta = {
73
+ active?: boolean;
74
+ dirty?: boolean;
75
+ error?: any;
76
+ };
77
+ declare type Component<Type, List> = (props: {
78
+ field: SchemaField & {
79
+ namespace: string[];
80
+ };
81
+ input: {
82
+ /**
83
+ * The full name of the field, for fields nested inside object
84
+ * fields, this will be the full path:
85
+ *
86
+ * `myObject.0.title`
87
+ */
88
+ name: string;
89
+ onBlur: (event?: React.FocusEvent<Type>) => void;
90
+ /**
91
+ * The value provided will be saved to the form so it
92
+ * should match the configured type:
93
+ *
94
+ * `input.onChange('some string')`
95
+ */
96
+ onChange: (event: React.ChangeEvent<Type>) => void;
97
+ onFocus: (event?: React.FocusEvent<Type>) => void;
98
+ type?: string;
99
+ value: List extends true ? Type[] : Type;
100
+ };
101
+ meta: Meta;
102
+ }) => any;
103
+ declare type UIField<Type, List extends boolean> = {
104
+ /**
105
+ * Override the label from parent object
106
+ */
107
+ label?: string;
108
+ /**
109
+ * Override the description from parent object
110
+ */
111
+ description?: string;
112
+ /**
113
+ * A React component which will be used in the Tina form. Be sure
114
+ * to import React into the config file.
115
+ *
116
+ * Note: Any Tailwind classes provided here will be compiled as part
117
+ * of the Tina stylesheet
118
+ *
119
+ * eg:
120
+ * ```tsx
121
+ * component: (props) => {
122
+ * const { input, field } = props
123
+ * return (
124
+ * <div className="my-4">
125
+ * <label
126
+ * htmlFor={input.name}
127
+ * className="block text-sm font-medium"
128
+ * >
129
+ * {field.name}
130
+ * </label>
131
+ * <div className="mt-1">
132
+ * <input
133
+ * id={input.name}
134
+ * className="py-2 px-4 block"
135
+ * type="text"
136
+ * {...input}
137
+ * />
138
+ * </div>
139
+ * </div>
140
+ * )
141
+ * }
142
+ * ```
143
+ *
144
+ * Note: If the form has already been registered with the cms, you
145
+ * can provide it's name here (eg. `textarea`)
146
+ */
147
+ component?: Component<Type, List> | string | null;
148
+ /**
149
+ * Optional: Prepare data for use in the component. This is useful
150
+ * if you don't have access to the component directly
151
+ */
152
+ parse?: (value: List extends true ? Type[] : Type, name: string, field: Field) => List extends true ? Type[] : Type;
153
+ /**
154
+ * Optional: Prepare data for saving. This is useful
155
+ * if you don't have access to the component directly
156
+ */
157
+ format?: (value: Type, name: string, field: Field) => List extends true ? Type[] : Type;
158
+ /**
159
+ * Optional: Return undefined when valid. Return a string or an object when there are errors.
160
+ *
161
+ * ```ts
162
+ * validate: (value) => {
163
+ * if(value.length > 40){
164
+ * return 'Title cannot be more than 40 characters long'
165
+ * }
166
+ * }
167
+ * ```
168
+ */
169
+ validate?(value: List extends true ? Type[] : Type, allValues: {
170
+ [key: string]: any;
171
+ }, meta: Meta, field: UIField<Type, List>): (List extends true ? Type[] : Type) | undefined | void;
172
+ /**
173
+ * @deprecated use `defaultItem` at the collection level instead
174
+ */
175
+ defaultValue?: List extends true ? Type[] : Type;
176
+ };
177
+ declare type FieldGeneric<Type, List extends boolean | undefined, ExtraFieldUIProps = {}> = List extends true ? {
178
+ list: true;
179
+ ui?: UIField<Type, true> & ExtraFieldUIProps;
180
+ } : List extends false ? {
181
+ list?: false;
182
+ ui?: UIField<Type, false> & ExtraFieldUIProps;
183
+ } : {
184
+ list?: undefined;
185
+ ui?: UIField<Type, false> & ExtraFieldUIProps;
186
+ };
187
+ export interface BaseField {
188
+ label?: string;
189
+ required?: boolean;
190
+ name: string;
191
+ description?: string;
192
+ }
193
+ export declare type StringField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & {
194
+ type: 'string';
195
+ isTitle?: boolean;
196
+ options?: Option[];
197
+ };
198
+ export declare type NumberField = (FieldGeneric<number, undefined> | FieldGeneric<number, true> | FieldGeneric<number, false>) & BaseField & {
199
+ type: 'number';
200
+ };
201
+ export declare type BooleanField = (FieldGeneric<boolean, undefined> | FieldGeneric<boolean, true> | FieldGeneric<boolean, false>) & BaseField & {
202
+ type: 'boolean';
203
+ };
204
+ declare type DateFormatProps = {
205
+ /**
206
+ * Customize the way the format is rendered
207
+ * ```
208
+ * dateFormat: 'YYYY MM DD'
209
+ * ```
210
+ */
211
+ dateFormat?: string;
212
+ timeFormat?: string;
213
+ };
214
+ export declare type DateTimeField = (FieldGeneric<string, undefined, DateFormatProps> | FieldGeneric<string, true, DateFormatProps> | FieldGeneric<string, false, DateFormatProps>) & BaseField & {
215
+ type: 'datetime';
216
+ };
217
+ export declare type ImageField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & {
218
+ type: 'image';
219
+ };
220
+ export declare type ReferenceField = (FieldGeneric<string, undefined> | FieldGeneric<string, false>) & BaseField & {
221
+ type: 'reference';
222
+ /**
223
+ * The names of the collections this field can use as a reference
224
+ * ```ts
225
+ * {
226
+ * type: 'reference',
227
+ * name: 'author',
228
+ * collections: ['author'],
229
+ * }
230
+ * ```
231
+ */
232
+ collections: string[];
233
+ };
234
+ declare type RichTextAst = {
235
+ type: 'root';
236
+ children: Record<string, unknown>[];
237
+ };
238
+ export declare type RichTextField = (FieldGeneric<RichTextAst, undefined> | FieldGeneric<RichTextAst, false>) & BaseField & {
239
+ type: 'rich-text';
240
+ /**
241
+ * When using Markdown or MDX formats, this field's value
242
+ * will be saved to the markdown body, while all other values
243
+ * will be stored as frontmatter
244
+ */
245
+ isBody?: boolean;
246
+ templates?: (Template & {
247
+ inline?: boolean;
248
+ /**
249
+ * If you have some custom shortcode logic in your markdown,
250
+ * you can specify it in the 'match' property and Tina will
251
+ * handle it as if it were a jsx element:
252
+ *
253
+ * ```
254
+ * # This is my markdown, it uses some custom shortcode
255
+ * syntax {{ myshortcode title="hello!" }}.
256
+ *
257
+ * {
258
+ * match: {
259
+ * start: "{{"
260
+ * end: "}}"
261
+ * }
262
+ * }
263
+ * ```
264
+ */
265
+ match?: {
266
+ start: string;
267
+ end: string;
268
+ };
269
+ })[];
270
+ };
271
+ declare type DefaultItem<ReturnType> = ReturnType | (() => ReturnType);
272
+ declare type ObjectUiProps = {
273
+ visualSelector?: boolean;
274
+ };
275
+ export declare type ObjectField = (FieldGeneric<string, undefined, ObjectUiProps> | FieldGeneric<string, true, ObjectUiProps> | FieldGeneric<string, false, ObjectUiProps>) & BaseField & ({
276
+ type: 'object';
277
+ fields: Field[];
278
+ templates?: undefined;
279
+ ui?: Template['ui'];
280
+ } | {
281
+ type: 'object';
282
+ fields?: undefined;
283
+ templates: Template[];
284
+ });
285
+ declare type Field = StringField | NumberField | BooleanField | DateTimeField | ImageField | ReferenceField | RichTextField | ObjectField;
286
+ declare type SchemaField = Field;
287
+ export type { SchemaField };
288
+ export interface Template {
289
+ label?: string;
290
+ name: string;
291
+ ui?: {
292
+ /**
293
+ * Override the properties passed to the field
294
+ * component. This is mostly useful for controlling
295
+ * the display value via callback on `itemProps.label`
296
+ */
297
+ itemProps?(item: Record<string, any>): {
298
+ key?: string;
299
+ /**
300
+ * Control the display value when object
301
+ * items are shown in a compact list, eg:
302
+ *
303
+ * ```ts
304
+ * itemProps: (values) => ({
305
+ * label: values?.title || 'Showcase Item',
306
+ * }),
307
+ * ```
308
+ */
309
+ label?: string;
310
+ };
311
+ defaultItem?: DefaultItem<Record<string, any>>;
312
+ /**
313
+ * When used in relation to the `visualSelector`,
314
+ * provide an image URL to be used as the preview
315
+ * in the blocks selector menu
316
+ */
317
+ previewSrc?: string;
318
+ };
319
+ fields: Field[];
320
+ }
321
+ export interface FieldCollection {
322
+ label?: string;
323
+ name: string;
324
+ path: string;
325
+ format?: 'json' | 'md' | 'markdown' | 'mdx';
326
+ ui?: UICollection & {
327
+ defaultItem?: DefaultItem<Record<string, any>>;
328
+ };
329
+ /**
330
+ * @deprecated - use `ui.defaultItem` instead
331
+ */
332
+ defaultItem?: DefaultItem<Record<string, any>>;
333
+ templates?: never;
334
+ /**
335
+ * Fields define the shape of the content and the user input.
336
+ *
337
+ * https://tina.io/docs/reference/fields/
338
+ */
339
+ fields: Field[];
340
+ }
341
+ export interface TemplateCollection {
342
+ label?: string;
343
+ name: string;
344
+ path: string;
345
+ format?: 'json' | 'md' | 'markdown' | 'mdx';
346
+ ui?: UICollection;
347
+ /**
348
+ * @deprecated - use `ui.defaultItem` on the each `template` instead
349
+ */
350
+ defaultItem?: DefaultItem<Record<string, any>>;
351
+ /**
352
+ * In most cases, just using fields is enough, however templates can be used when there are multiple variants of the same collection or object. For example in a "page" collection there might be a need for a marketing page template and a content page template, both under the collection "page".
353
+ *
354
+ * https://tina.io/docs/reference/templates/
355
+ */
356
+ templates?: Template[];
357
+ fields?: never;
358
+ }
359
+ export declare type Collection = FieldCollection | TemplateCollection;
360
+ export interface Schema {
361
+ /**
362
+ * Collections represent a type of content (EX, blog post, page, author, etc). We recommend using singular naming in a collection (Ex: use post and not posts).
363
+ *
364
+ * https://tina.io/docs/reference/collections/
365
+ */
366
+ collections: Collection[];
367
+ }
368
+ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined> {
369
+ /**
370
+ * The Schema is used to define the shape of the content.
371
+ *
372
+ * https://tina.io/docs/reference/schema/
373
+ */
374
+ schema: Schema;
375
+ /**
376
+ * The base branch to pull content from. Note that this is ignored for local development
377
+ */
378
+ branch: string | null;
379
+ /**
380
+ * Your clientId from app.tina.io
381
+ */
382
+ clientId: string | null;
383
+ /**
384
+ * Your read only token from app.tina.io
385
+ */
386
+ token: string | null;
387
+ /**
388
+ * Configurations for the autogenerated GraphQL HTTP client
389
+ */
390
+ client?: {
391
+ /**
392
+ * Autogenerated queries will traverse references to a given depth
393
+ * @default 2
394
+ */
395
+ referenceDepth?: number;
396
+ };
397
+ /**
398
+ * Tina is compiled as a single-page app and placed in the public directory
399
+ * of your application.
400
+ */
401
+ build: {
402
+ /**
403
+ * The folder where your application stores assets, eg. `"public"`
404
+ */
405
+ publicFolder: string;
406
+ /**
407
+ * The value specified here will determine the path when visiting the TinaCMS dashboard.
408
+ *
409
+ * Eg. `"admin"` will be viewable at `[your-development-url]/admin/index.html`
410
+ *
411
+ * 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)
412
+ */
413
+ outputFolder: string;
414
+ };
415
+ media?: {
416
+ /**
417
+ * Load a media store like Cloudinary
418
+ *
419
+ * ```ts
420
+ * loadCustomStore = async () => {
421
+ * const pack = await import("next-tinacms-cloudinary");
422
+ * return pack.TinaCloudCloudinaryMediaStore;
423
+ * }
424
+ * ```
425
+ */
426
+ loadCustomStore: () => Promise<Store>;
427
+ tina?: never;
428
+ } | {
429
+ /**
430
+ * Use Git-backed assets for media, these values will
431
+ * [Learn more](https://tina.io/docs/reference/media/repo-based/)
432
+ */
433
+ tina: {
434
+ /**
435
+ * The folder where your application stores assets, eg. `"public"`
436
+ */
437
+ publicFolder: string;
438
+ /**
439
+ * The root folder for media managed by Tina. For example, `"uploads"`
440
+ * would store content in `"<my-public-folder>/uploads"`
441
+ */
442
+ mediaRoot: string;
443
+ };
444
+ loadCustomStore?: never;
445
+ };
446
+ /**
447
+ * Used to override the default Tina Cloud API URL
448
+ *
449
+ * [mostly for internal use only]
450
+ */
451
+ tinaioConfig?: {
452
+ assetsApiUrlOverride?: string;
453
+ frontendUrlOverride?: string;
454
+ identityApiUrlOverride?: string;
455
+ contentApiUrlOverride?: string;
456
+ };
457
+ cmsCallback?: CMSCallback;
458
+ formifyCallback?: FormifyCallback;
459
+ documentCreatorCallback?: DocumentCreatorCallback;
460
+ }
461
+ export declare type TinaCMSConfig<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined> = Config<CMSCallback, FormifyCallback, DocumentCreatorCallback, Store>;
462
+ export {};
@@ -0,0 +1 @@
1
+
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ (function(factory) {
2
+ typeof define === "function" && define.amd ? define(factory) : factory();
3
+ })(function() {
4
+ "use strict";
5
+ });
@@ -10,11 +10,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { TinaCloudSchema } from '../types';
13
+ import { Schema } from '../types';
14
+ import { TinaCloudSchema } from '../types/index';
14
15
  export { validateTinaCloudSchemaConfig } from './tinaCloudSchemaConfig';
15
16
  export declare class TinaSchemaValidationError extends Error {
16
17
  constructor(message: any);
17
18
  }
18
19
  export declare const validateSchema: ({ schema, }: {
19
- schema: TinaCloudSchema<false>;
20
+ schema: Schema | TinaCloudSchema<false>;
20
21
  }) => void;
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { TinaCloudSchemaConfig } from '../types';
13
+ import { TinaCloudSchemaConfig } from '../types/index';
14
14
  import z from 'zod';
15
15
  export declare const tinaConfigZod: z.ZodObject<{
16
16
  client: z.ZodOptional<z.ZodObject<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -8,6 +8,11 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "import": "./dist/index.es.js",
10
10
  "require": "./dist/index.js"
11
+ },
12
+ "./dist/types": {
13
+ "types": "./dist/types.d.ts",
14
+ "import": "./dist/types.es.js",
15
+ "require": "./dist/types.js"
11
16
  }
12
17
  },
13
18
  "typings": "dist/index.d.ts",
@@ -19,6 +24,9 @@
19
24
  "entryPoints": [
20
25
  {
21
26
  "name": "src/index.ts"
27
+ },
28
+ {
29
+ "name": "src/types.ts"
22
30
  }
23
31
  ]
24
32
  },
@@ -1,101 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- import { TinaCloudSchema } from './SchemaTypes';
14
- /**
15
- * Used with `defineStaticConfig`
16
- *
17
- * These are mostly similar types as whats in `schemaTypes`
18
- * but since those have gone through several iterations
19
- * they're pretty messy. These should act as the happy path
20
- * for iframe/standalone setups which we hope to eventually
21
- * make the default/only path for all Tina users.
22
- */
23
- export declare type TinaCMSConfig<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined> = {
24
- schema: TinaCloudSchema<false>;
25
- /**
26
- * The base branch to pull content from. Note that this is ignored for local development
27
- */
28
- branch: string | null;
29
- /**
30
- * Your clientId from app.tina.io
31
- */
32
- clientId: string | null;
33
- /**
34
- * Your read only token from app.tina.io
35
- */
36
- token: string | null;
37
- /**
38
- * Configurations for the autogenerated GraphQL HTTP client
39
- */
40
- client?: {
41
- /**
42
- * Autogenerated queries will traverse references to a given depth
43
- * @default 2
44
- */
45
- referenceDepth?: number;
46
- };
47
- build: {
48
- /**
49
- * The folder where your application stores assets, eg. `"public"`
50
- */
51
- publicFolder: string;
52
- /**
53
- * TinaCMS is shipped as a single-page app, the value specified here will
54
- * determine the path when visiting the TinaCMS dashboard.
55
- *
56
- * Eg. `"admin"` will be viewable at `[your-development-url]/admin/index.html`
57
- */
58
- outputFolder: string;
59
- };
60
- media?: {
61
- /**
62
- * Load a media store like Cloudinary
63
- *
64
- * ```ts
65
- * loadCustomStore = async () => {
66
- * const pack = await import("next-tinacms-cloudinary");
67
- * return pack.TinaCloudCloudinaryMediaStore;
68
- * }
69
- * ```
70
- */
71
- loadCustomStore: () => Promise<Store>;
72
- tina?: never;
73
- } | {
74
- /**
75
- * Use Git-backed assets for media, these values will
76
- * [Learn more](https://tina.io/docs/reference/media/repo-based/)
77
- */
78
- tina: {
79
- /**
80
- * The folder where your application stores assets, eg. `"public"`
81
- */
82
- publicFolder: string;
83
- /**
84
- * The root folder for media managed by Tina. For example, `"uploads"`
85
- * would store content in `"<my-public-folder>/uploads"`
86
- */
87
- mediaRoot: string;
88
- };
89
- loadCustomStore?: never;
90
- };
91
- tinaioConfig?: {
92
- assetsApiUrlOverride?: string;
93
- frontendUrlOverride?: string;
94
- identityApiUrlOverride?: string;
95
- contentApiUrlOverride?: string;
96
- };
97
- cmsCallback?: CMSCallback;
98
- formifyCallback?: FormifyCallback;
99
- documentCreatorCallback?: DocumentCreatorCallback;
100
- };
101
- export {};