tinacms 0.66.7 → 0.66.10

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.
@@ -10,50 +10,139 @@ 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 * as G from 'graphql';
14
- export declare const isNodeField: (type: G.GraphQLNamedType) => boolean;
15
- export declare const isCollectionField: (type: G.GraphQLNamedType) => boolean;
16
- export declare const isConnectionField: (type: G.GraphQLNamedType) => boolean;
13
+ import { Form, Field, TinaCMS } from '@tinacms/toolkit';
14
+ import type { DocumentBlueprint, FieldBlueprint, FormifiedDocumentNode, OnChangeEvent, FormNode, State, ChangeSet, BlueprintPath } from './types';
15
+ import { formifyCallback, onSubmitArgs } from '../use-graphql-forms';
16
+ interface RecursiveFormifiedDocumentNode<T extends object> extends Array<RecursiveFormifiedDocumentNode<T> | T> {
17
+ }
17
18
  /**
18
- * Selects the appropriate field from a GraphQLObject based on the selection's name
19
+ * Gets the value from an object for a given blueprint for _all_ possible values.
20
+ * eg. If the blueprint is `getCollection.documents.edges.[].node` and the value is:
21
+ * ```
22
+ * {
23
+ * getCollection: {
24
+ * documents: {
25
+ * edges: [{
26
+ * node: valueA
27
+ * },
28
+ * {
29
+ * node: valueB
30
+ * }]
31
+ * }
32
+ * }
33
+ * }
34
+ * ```
35
+ * The response would be an array containing `valueA` and `valueB`
36
+ *
19
37
  */
20
- export declare const getObjectField: (object: G.GraphQLObjectType<any, any>, selectionNode: G.FieldNode) => G.GraphQLField<any, any, {
21
- [key: string]: any;
22
- }>;
38
+ export declare const getValueForBlueprint: <T extends object>(state: object, path: string) => T | RecursiveFormifiedDocumentNode<T>;
23
39
  /**
24
- * Selects the appropriate type from a union based on the selection's typeCondition
40
+ * Returns the name of the field. In the example query, `title` and `t` would both be blueprint fields
25
41
  *
26
42
  * ```graphql
27
- * post {
28
- * # would return PostDocument
29
- * ...on PostDocument { ... }
43
+ * {
44
+ * getPostDocument(relativePath: $relativePath) {
45
+ * data {
46
+ * title,
47
+ * t: title # here `t` is an alias for title
48
+ * }
49
+ * }
30
50
  * }
31
51
  * ```
32
52
  */
33
- export declare const getSelectedUnionType: (unionType: G.GraphQLUnionType, selectionNode: G.InlineFragmentNode) => G.GraphQLObjectType<any, any>;
53
+ export declare const getFieldNameOrAlias: (fieldBlueprint: FieldBlueprint) => string;
54
+ export declare const buildForm: (doc: FormifiedDocumentNode, cms: TinaCMS, formify: formifyCallback, showInSidebar?: boolean, onSubmit?: (args: onSubmitArgs) => void) => Form;
55
+ export declare const formNodeId: (formNode: FormNode) => string;
56
+ export declare const formNodePath: (formNode: FormNode) => string;
57
+ export declare const formNodeNotIn: (formNode: FormNode, formNodes: FormNode[]) => boolean;
58
+ export declare const sequential: <A, B>(items: A[], callback: (args: A, idx: number) => Promise<B>) => Promise<B[]>;
59
+ export declare const getFormNodesForField: (fieldBlueprint: FieldBlueprint, formNode: FormNode, event: OnChangeEvent, state: State) => {
60
+ pathToChange: string;
61
+ formNodes: FormNode[];
62
+ eventLocation: any[];
63
+ existing: any;
64
+ };
65
+ export declare const getBlueprintAliasPath: (blueprint: DocumentBlueprint) => string;
66
+ export declare const getFieldAliasForBlueprint: (path: BlueprintPath[]) => string;
34
67
  /**
35
68
  *
36
- * Throws an error if the provided type is no a GraphQLUnionType
37
- */
38
- export declare function ensureNodeField(field: G.GraphQLNamedType): void;
39
- /**
69
+ * Determines the appropriate fields which should recieve an update from a form change
70
+ *
71
+ * In cases where there's polymorphic blocks, it's possible that an update would affect
72
+ * multiple locations that it shouldn't.
73
+ *
74
+ * An OnChange event name can look like: `blocks.2.title`, but if there are 2 block elements
75
+ * with a field of the same name, an event name it wouldn't be enough information for us.
76
+ *
77
+ * To get around this, the event sends the current `typename` along with it, and we use that
78
+ * to determine where in our blueprint the value should be updated.
40
79
  *
41
- * Throws an error if the provided type is no a GraphQLUnionType
42
80
  */
43
- export declare function ensureUnionType(type: unknown): asserts type is G.GraphQLUnionType;
81
+ export declare const getBlueprintFieldsForEvent: (blueprint: DocumentBlueprint, event: OnChangeEvent) => FieldBlueprint[];
82
+ export declare const filterFieldBlueprintsByParentTypename: (fbp: FieldBlueprint, typename: any) => boolean;
44
83
  /**
45
84
  *
46
- * Throws an error if the provided type is no a GraphQLUnionType
85
+ * Returns the human-readable path to a blueprint or blueprint field.
86
+ * Optionally, appends a disambiguator to the string where necessary.
87
+ *
88
+ * eg. if a blocks field is polymporphic, specifying `true` for the disambiguator
89
+ *
90
+ * ```
91
+ * getPageDocument.data.blocks[].PageBlocksCta.title
92
+ * ```
47
93
  */
48
- export declare function ensureObjectType(type: unknown): asserts type is G.GraphQLObjectType;
94
+ export declare const getBlueprintNamePath: (blueprint: Pick<DocumentBlueprint, 'path'>, disambiguator?: boolean) => string;
95
+ export declare const stripIndices: (string: any) => any[];
96
+ export declare const replaceRealNum: (string: any) => any;
97
+ export declare const getMatchName: ({ field, prefix, blueprint }: {
98
+ field: any;
99
+ prefix: any;
100
+ blueprint: any;
101
+ }) => {
102
+ matchName: string;
103
+ fieldName: any;
104
+ };
105
+ export declare const getFormNodesFromEvent: (state: State, event: OnChangeEvent) => FormNode[];
106
+ export declare const printState: (state: State) => string;
107
+ export declare const printEvent: (event: OnChangeEvent) => {
108
+ type: "forms:fields:onChange" | "forms:reset";
109
+ value: unknown;
110
+ previousValue: unknown;
111
+ mutationType: import("./types").ChangeMutation | import("./types").ReferenceChangeMutation | import("./types").InsertMutation | import("./types").MoveMutation | import("./types").RemoveMutation | import("./types").ResetMutation | import("./types").GlobalMutation;
112
+ formId: string;
113
+ field: {
114
+ data: {
115
+ tinaField: {
116
+ name: string;
117
+ type: "string" | "object" | "reference";
118
+ list?: boolean;
119
+ parentTypename: string;
120
+ };
121
+ };
122
+ name: string;
123
+ };
124
+ };
125
+ export declare const getFormNodeBlueprint: (formNode: FormNode, state: State) => DocumentBlueprint;
126
+ export declare const getMoveMapping: (existing: any, from: any, to: any) => {
127
+ [key: number]: number;
128
+ };
129
+ export declare const matchLocation: (eventLocation: number[], formNode: FormNode) => boolean;
130
+ export declare const bumpLocation: (location: number[]) => number[];
131
+ export declare const maybeLowerLocation: (location: number[], at: number) => number[];
132
+ export declare const matchesAt: (location: number[], at: number) => boolean;
133
+ export declare const swapLocation: (location: number[], mapping: {
134
+ [key: number]: number;
135
+ }) => number[];
49
136
  /**
50
137
  *
51
- * Throws an error if the provided type is no a GraphQLUnionType
138
+ * Gets the sub-fields for an object field, if it's a polymorphic
139
+ * object then we also need to get the __typename, though
140
+ * we should probably supply that regardless. The current downside
141
+ * of this is that it needs to come from the server because we
142
+ * have no way of knowing what it would be from the client-side
52
143
  */
53
- export declare function ensureOperationDefinition(type: G.DefinitionNode): asserts type is G.OperationDefinitionNode;
54
- export declare function getNameAndAlias(fieldNode: G.FieldNode, list?: boolean): {
55
- name: string;
56
- alias: string;
57
- list: boolean;
144
+ export declare const getSubFields: (changeSet: ChangeSet) => {
145
+ fields: Field[];
146
+ __typename: string;
58
147
  };
59
- export declare const metaFields: G.SelectionNode[];
148
+ export {};
@@ -10,8 +10,20 @@ 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 { Form } from '@tinacms/toolkit';
13
+ import { Form, AnyField } from '@tinacms/toolkit';
14
14
  import type { FormOptions, TinaCMS } from '@tinacms/toolkit';
15
+ export declare function useGraphqlFormsUnstable<T extends object>({ variables, onSubmit, query, formify, eventList, }: {
16
+ query: string;
17
+ variables: object;
18
+ onSubmit?: (args: onSubmitArgs) => void;
19
+ formify?: formifyCallback;
20
+ /**
21
+ * This is a test utility which allows us to keep track of all the events
22
+ * received by this hook. See `experimental-examples/unit-test-example/pages/index.js
23
+ * for usage.
24
+ */
25
+ eventList?: [];
26
+ }): [T, Boolean];
15
27
  export declare function useGraphqlForms<T extends object>({ variables, onSubmit, formify, query, }: {
16
28
  query: string;
17
29
  variables: object;
@@ -27,7 +39,16 @@ export declare const transformDocumentIntoMutationRequestPayload: (document: {
27
39
  includeCollection?: boolean;
28
40
  includeTemplate?: boolean;
29
41
  }) => any;
42
+ export declare const generateFormCreatorsUnstable: (cms: TinaCMS, showInSidebar?: boolean) => {
43
+ createForm: (formConfig: any) => Form<any, AnyField>;
44
+ createGlobalForm: GlobalFormCreator;
45
+ };
30
46
  declare type FormCreator = (formConfig: FormOptions<any>) => Form;
47
+ declare type GlobalFormCreator = (formConfig: FormOptions<any>, options?: GlobalFormOptions) => Form;
48
+ interface GlobalFormOptions {
49
+ icon?: any;
50
+ layout: 'fullscreen' | 'popup';
51
+ }
31
52
  export interface FormifyArgs {
32
53
  formConfig: FormOptions<any>;
33
54
  createForm: FormCreator;
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export * from './client';
14
14
  export * from './auth';
15
15
  export * from './utils';
16
16
  export * from './tina-cms';
17
- export { useGraphqlForms } from './hooks/use-graphql-forms';
17
+ export { useGraphqlForms, useGraphqlFormsUnstable, } from './hooks/use-graphql-forms';
18
18
  export { useDocumentCreatorPlugin } from './hooks/use-content-creator';
19
19
  export * from '@tinacms/toolkit';
20
20
  export { TinaAdmin } from './admin';
@@ -23,9 +23,8 @@ export { TinaAdminApi } from './admin/api';
23
23
  import { TinaCMSProvider2, TinaCMSProviderDefaultProps } from './tina-cms';
24
24
  export type { TinaCMSProviderDefaultProps };
25
25
  export default TinaCMSProvider2;
26
- import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
26
+ import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from '@tinacms/schema-tools';
27
27
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
28
- export declare type TinaSchema = TinaCloudSchema;
29
28
  export declare type TinaCloudCollection = TinaCloudCollectionBase<false>;
30
29
  export declare type TinaCollection = TinaCloudCollectionBase<false>;
31
30
  export declare type TinaField = TinaFieldBase;