tinacms 0.0.0-95a293c-20250401070633 → 0.0.0-96fe3b4-20251217041317

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.
Files changed (181) hide show
  1. package/dist/admin/api.d.ts +4 -1
  2. package/dist/admin/components/{Sidebar.d.ts → AdminNav.d.ts} +0 -3
  3. package/dist/admin/components/Page.d.ts +3 -9
  4. package/dist/admin/components/ui/tooltip.d.ts +7 -0
  5. package/dist/admin/pages/CollectionCreatePage.d.ts +1 -1
  6. package/dist/admin/pages/CollectionListPage.d.ts +2 -2
  7. package/dist/admin/pages/DashboardPage.d.ts +0 -3
  8. package/dist/admin/pages/ScreenPage.d.ts +0 -3
  9. package/dist/auth/AuthModal.d.ts +1 -4
  10. package/dist/auth/TinaCloudProvider.d.ts +0 -1
  11. package/dist/cache/node-cache.d.ts +6 -2
  12. package/dist/client.js +240 -172
  13. package/dist/index.js +122333 -33790
  14. package/dist/internalClient/index.d.ts +55 -2
  15. package/dist/react.d.ts +13 -6
  16. package/dist/react.js +209 -204
  17. package/dist/rich-text/index.d.ts +6 -0
  18. package/dist/rich-text/index.js +234 -224
  19. package/dist/rich-text/prism.js +16 -18
  20. package/dist/rich-text/static.d.ts +154 -0
  21. package/dist/rich-text/{index.mjs → static.js} +99 -99
  22. package/dist/tina-cms.d.ts +1 -1
  23. package/dist/toolkit/components/ProgressBar.d.ts +11 -0
  24. package/dist/toolkit/components/media/media-item.d.ts +11 -1
  25. package/dist/toolkit/components/ui/breadcrumb.d.ts +11 -0
  26. package/dist/toolkit/components/ui/button.d.ts +11 -0
  27. package/dist/toolkit/components/ui/calendar.d.ts +8 -0
  28. package/dist/toolkit/components/ui/date-time-picker.d.ts +111 -0
  29. package/dist/toolkit/components/ui/dropdown-menu.d.ts +25 -0
  30. package/dist/toolkit/components/ui/input.d.ts +3 -0
  31. package/dist/toolkit/components/ui/popover.d.ts +7 -0
  32. package/dist/toolkit/components/ui/select.d.ts +13 -0
  33. package/dist/toolkit/fields/components/color-picker/block-widget.d.ts +3 -0
  34. package/dist/toolkit/fields/components/color-picker/color-input.d.ts +35 -0
  35. package/dist/toolkit/fields/components/color-picker/color-picker.d.ts +6 -2
  36. package/dist/toolkit/fields/components/color-picker/color-utils.d.ts +37 -0
  37. package/dist/toolkit/fields/components/color-picker/sketch-widget.d.ts +3 -0
  38. package/dist/toolkit/fields/components/password-field.d.ts +1 -1
  39. package/dist/toolkit/fields/components/reference/components/button.d.ts +2 -2
  40. package/dist/toolkit/fields/components/reference/components/command.d.ts +21 -33
  41. package/dist/toolkit/fields/components/reference/components/popover.d.ts +1 -1
  42. package/dist/toolkit/fields/components/reference/model/reference-link-props.d.ts +2 -0
  43. package/dist/toolkit/fields/components/select.d.ts +2 -2
  44. package/dist/toolkit/fields/components/text-field.d.ts +1 -1
  45. package/dist/toolkit/fields/plugins/button-toggle-field-plugin.d.ts +2 -2
  46. package/dist/toolkit/fields/plugins/checkbox-group-field-plugin.d.ts +2 -2
  47. package/dist/toolkit/fields/plugins/color-field-plugin.d.ts +1 -0
  48. package/dist/toolkit/fields/plugins/date-field-plugin.d.ts +0 -2
  49. package/dist/toolkit/fields/plugins/dnd-kit-wrapper.d.ts +49 -0
  50. package/dist/toolkit/fields/plugins/group-field-plugin.d.ts +1 -1
  51. package/dist/toolkit/fields/plugins/group-list-field-plugin.d.ts +3 -1
  52. package/dist/toolkit/fields/plugins/list-field-meta.d.ts +1 -1
  53. package/dist/toolkit/fields/plugins/list-field-plugin.d.ts +3 -0
  54. package/dist/toolkit/fields/plugins/mdx-field-plugin/index.d.ts +2 -2
  55. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +20 -18
  56. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +14 -10
  57. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +5 -5
  58. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +17 -0
  59. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/error-message.d.ts +6 -0
  60. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-combobox.d.ts +6 -0
  61. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-toolbar-button.d.ts +6 -6
  62. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-leaf.d.ts +2 -11
  63. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +14 -10
  64. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-syntax-leaf.d.ts +2 -11
  65. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +112 -0
  66. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dialog.d.ts +12 -0
  67. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dropdown-menu.d.ts +10 -10
  68. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/floating-toolbar.d.ts +2 -2
  69. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-element.d.ts +3 -0
  70. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-toolbar-button.d.ts +18 -0
  71. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/icons.d.ts +2 -1
  72. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/image-toolbar-button.d.ts +6 -6
  73. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +6 -19
  74. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/inline-combobox.d.ts +1 -1
  75. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/input.d.ts +3 -3
  76. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-element.d.ts +4 -11
  77. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-floating-toolbar.d.ts +4 -5
  78. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-toolbar-button.d.ts +4 -4
  79. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +28 -11
  80. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-element.d.ts +3 -10
  81. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-toolbar-button.d.ts +6 -8
  82. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +15 -0
  83. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/popover.d.ts +7 -2
  84. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/quote-toolbar-button.d.ts +6 -6
  85. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/raw-markdown-toolbar-button.d.ts +6 -6
  86. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/resizable.d.ts +24 -21
  87. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/separator.d.ts +2 -2
  88. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +15 -11
  89. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/block-selection.d.ts +6 -0
  90. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +33 -0
  91. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/{table-dropdown-menu.d.ts → table/table-dropdown-menu.d.ts} +1 -0
  92. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +20 -0
  93. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +15 -0
  94. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/toolbar.d.ts +7 -7
  95. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +10 -0
  96. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-state.d.ts +22 -0
  97. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/hooks/use-create-editor.d.ts +6 -0
  98. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-block.d.ts +1 -1
  99. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-lists.d.ts +1 -1
  100. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-marks.d.ts +1 -1
  101. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-utils.d.ts +3 -5
  102. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/common.d.ts +11 -6
  103. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/formatting.d.ts +18 -2
  104. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/index.d.ts +0 -1
  105. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-html-block/index.d.ts +6 -0
  106. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-img-plugin/index.d.ts +2 -2
  107. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-invalid-markdown-plugin/index.d.ts +5 -5
  108. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/component.d.ts +7 -4
  109. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/index.d.ts +3 -5
  110. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/editor-plugins.d.ts +520 -0
  111. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +263 -207
  112. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/floating-toolbar-plugin.d.ts +1 -0
  113. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-overrides.d.ts +1 -1
  114. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/is-url.d.ts +1 -2
  115. package/dist/toolkit/fields/plugins/radio-group-field-plugin.d.ts +2 -2
  116. package/dist/toolkit/fields/plugins/select-field-plugin.d.ts +2 -2
  117. package/dist/toolkit/fields/plugins/toggle-field-plugin.d.ts +2 -2
  118. package/dist/toolkit/form-builder/create-branch-modal.d.ts +13 -0
  119. package/dist/toolkit/form-builder/editorial-workflow-constants.d.ts +17 -0
  120. package/dist/toolkit/form-builder/fields-builder.d.ts +1 -1
  121. package/dist/toolkit/form-builder/form-builder.d.ts +8 -9
  122. package/dist/toolkit/form-builder/index.d.ts +1 -0
  123. package/dist/toolkit/forms/field.d.ts +3 -0
  124. package/dist/toolkit/forms/form.d.ts +22 -3
  125. package/dist/toolkit/git-client/git-client.d.ts +25 -2
  126. package/dist/toolkit/git-client/git-file.d.ts +18 -0
  127. package/dist/toolkit/git-client/git-media-store.d.ts +13 -0
  128. package/dist/toolkit/git-client/use-git-file.d.ts +4 -0
  129. package/dist/toolkit/icons/Tina.d.ts +0 -5
  130. package/dist/toolkit/icons/TinaExtended.d.ts +4 -0
  131. package/dist/toolkit/icons/index.d.ts +1 -0
  132. package/dist/toolkit/index.d.ts +1 -1
  133. package/dist/toolkit/plugin-branch-switcher/branch-button.d.ts +4 -1
  134. package/dist/toolkit/plugin-branch-switcher/index.d.ts +0 -1
  135. package/dist/toolkit/react-modals/modal/modal-actions.d.ts +2 -1
  136. package/dist/toolkit/react-modals/modal/modal-header.d.ts +1 -1
  137. package/dist/toolkit/react-sidebar/components/NavMenuTrigger.d.ts +11 -0
  138. package/dist/toolkit/react-sidebar/components/VersionInfo.d.ts +2 -0
  139. package/dist/toolkit/react-sidebar/components/badge.d.ts +6 -0
  140. package/dist/toolkit/react-sidebar/components/callout.d.ts +5 -0
  141. package/dist/toolkit/react-sidebar/components/form-list.d.ts +1 -1
  142. package/dist/toolkit/react-sidebar/components/local-warning.d.ts +3 -1
  143. package/dist/toolkit/react-sidebar/components/nav-components.d.ts +11 -0
  144. package/dist/toolkit/react-sidebar/components/nav-context.d.ts +15 -0
  145. package/dist/toolkit/react-sidebar/components/nav.d.ts +6 -3
  146. package/dist/toolkit/react-sidebar/components/resize-handle.d.ts +0 -5
  147. package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +28 -7
  148. package/dist/toolkit/react-sidebar/components/sidebar.d.ts +0 -7
  149. package/dist/toolkit/react-sidebar/components/sync-status.d.ts +5 -8
  150. package/dist/toolkit/react-sidebar/index.d.ts +4 -1
  151. package/dist/toolkit/styles/button.d.ts +2 -2
  152. package/dist/toolkit/styles/dropdown-button.d.ts +75 -0
  153. package/dist/toolkit/styles/index.d.ts +1 -0
  154. package/dist/toolkit/tina-cms.d.ts +3 -3
  155. package/dist/toolkit/tina-state.d.ts +11 -0
  156. package/dist/unifiedClient/index.d.ts +2 -2
  157. package/dist/utils/cn.d.ts +2 -0
  158. package/dist/utils/index.d.ts +1 -0
  159. package/package.json +59 -83
  160. package/dist/admin/pages/IndexingPage.d.ts +0 -2
  161. package/dist/client.mjs +0 -123
  162. package/dist/index.mjs +0 -35100
  163. package/dist/node-cache-5e8db9f0.mjs +0 -63
  164. package/dist/react.mjs +0 -246
  165. package/dist/rich-text/prism.mjs +0 -16
  166. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-element.d.ts +0 -11
  167. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-cell-element.d.ts +0 -27
  168. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-element.d.ts +0 -14
  169. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-row-element.d.ts +0 -13
  170. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/with-correct-void-behavior.d.ts +0 -8
  171. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-code-block/index.d.ts +0 -3
  172. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-link-plugin/index.d.ts +0 -15
  173. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/custom/mermaid-plugin.d.ts +0 -2
  174. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/create-soft-break-plugin.d.ts +0 -7
  175. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/index.d.ts +0 -6
  176. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/on-key-down-soft-break.d.ts +0 -5
  177. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/types.d.ts +0 -11
  178. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/code-block/index.d.ts +0 -11
  179. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/insert-empty-block.d.ts +0 -2
  180. package/dist/toolkit/plugin-branch-switcher/branch-banner.d.ts +0 -2
  181. package/dist/toolkit/react-datetime/DateTime.d.ts +0 -135
@@ -2,7 +2,7 @@ import { BranchData, EventBus } from '@tinacms/toolkit';
2
2
  import { DocumentNode, GraphQLSchema } from 'graphql';
3
3
  import { TokenObject } from '../auth/authenticate';
4
4
  import { AuthProvider, Schema, TinaSchema } from '@tinacms/schema-tools';
5
- import { SearchClient } from '@tinacms/search/dist/index-client';
5
+ import { SearchClient } from '@tinacms/search/index-client';
6
6
  import gql from 'graphql-tag';
7
7
  import { TinaCloudProject } from './types';
8
8
  export * from './authProvider';
@@ -141,6 +141,26 @@ export declare class Client {
141
141
  }[]>;
142
142
  usingProtectedBranch(): boolean;
143
143
  createBranch({ baseBranch, branchName }: BranchData): Promise<string>;
144
+ getLatestVersion(): Promise<LatestVersionResponse>;
145
+ /**
146
+ * Initiate and poll for the results of an editorial workflow operation
147
+ *
148
+ * @param options Editorial workflow options
149
+ * @returns Object with branch and PR info when complete
150
+ */
151
+ executeEditorialWorkflow(options: {
152
+ branchName: string;
153
+ baseBranch: string;
154
+ prTitle?: string;
155
+ graphQLContentOp?: {
156
+ query: string;
157
+ variables: Record<string, unknown>;
158
+ };
159
+ onStatusUpdate?: (status: {
160
+ status: string;
161
+ message?: string;
162
+ }) => void;
163
+ }): Promise<any>;
144
164
  }
145
165
  export declare const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = "http://localhost:4001/graphql";
146
166
  export declare class LocalClient extends Client {
@@ -153,17 +173,30 @@ export declare class LocalClient extends Client {
153
173
  export declare class TinaCMSSearchClient implements SearchClient {
154
174
  private client;
155
175
  private tinaSearchConfig?;
176
+ private fuzzyEnabled;
177
+ private defaultFuzzyOptions?;
156
178
  constructor(client: Client, tinaSearchConfig?: {
157
179
  stopwordLanguages?: string[];
180
+ fuzzyEnabled?: boolean;
181
+ fuzzyOptions?: {
182
+ maxDistance?: number;
183
+ minSimilarity?: number;
184
+ maxResults?: number;
185
+ useTranspositions?: boolean;
186
+ caseSensitive?: boolean;
187
+ };
158
188
  });
159
189
  query(query: string, options?: {
160
190
  limit?: number;
161
191
  cursor?: string;
192
+ fuzzy?: boolean;
193
+ fuzzyOptions?: any;
162
194
  }): Promise<{
163
195
  results: any[];
164
196
  nextCursor: string | null;
165
197
  total: number;
166
198
  prevCursor: string | null;
199
+ fuzzyMatches?: Record<string, any[]>;
167
200
  }>;
168
201
  del(ids: string[]): Promise<any>;
169
202
  put(docs: any[]): Promise<any>;
@@ -171,17 +204,37 @@ export declare class TinaCMSSearchClient implements SearchClient {
171
204
  }
172
205
  export declare class LocalSearchClient implements SearchClient {
173
206
  private client;
174
- constructor(client: Client);
207
+ private tinaSearchConfig?;
208
+ private fuzzyEnabled;
209
+ private defaultFuzzyOptions?;
210
+ constructor(client: Client, tinaSearchConfig?: {
211
+ fuzzyEnabled?: boolean;
212
+ fuzzyOptions?: {
213
+ maxDistance?: number;
214
+ minSimilarity?: number;
215
+ maxResults?: number;
216
+ useTranspositions?: boolean;
217
+ caseSensitive?: boolean;
218
+ };
219
+ });
175
220
  query(query: string, options?: {
176
221
  limit?: number;
177
222
  cursor?: string;
223
+ fuzzy?: boolean;
224
+ fuzzyOptions?: any;
178
225
  }): Promise<{
179
226
  results: any[];
180
227
  nextCursor: string | null;
181
228
  total: number;
182
229
  prevCursor: string | null;
230
+ fuzzyMatches?: Record<string, any[]>;
183
231
  }>;
184
232
  del(ids: string[]): Promise<any>;
185
233
  put(docs: any[]): Promise<any>;
186
234
  supportsClientSideIndexing(): boolean;
187
235
  }
236
+ export type PackageVersionInfo = {
237
+ version: string;
238
+ publishedAt: string;
239
+ };
240
+ export type LatestVersionResponse = Record<string, PackageVersionInfo>;
package/dist/react.d.ts CHANGED
@@ -15,16 +15,23 @@ export declare function useEditState(): {
15
15
  * to signal to Tina which DOM element the field
16
16
  * is working with.
17
17
  */
18
- export declare const tinaField: <T extends (object & {
18
+ /**
19
+ * Generate a field identifier for Tina to associate DOM elements with form fields.
20
+ * Format: "queryId---path.to.field" or "queryId---path.to.array.index"
21
+ */
22
+ export declare const tinaField: <T extends {
19
23
  _content_source?: {
20
24
  queryId: string;
21
25
  path: (number | string)[];
22
26
  };
23
- }) | undefined | null>(object: T, property?: keyof Omit<NonNullable<T>, "__typename" | "_sys">, index?: number) => string;
24
- export declare const addMetadata: <T extends object>(id: string, object: T & {
25
- type?: string;
26
- _content_source?: unknown;
27
- }, path: (string | number)[]) => T;
27
+ } | Record<string, unknown> | null | undefined>(object: T, property?: keyof Omit<NonNullable<T>, "__typename" | "_sys">, index?: number) => string;
28
+ /**
29
+ * FIX: This function is updated to be more robust. It explicitly checks for
30
+ * `null` and `String` objects to prevent them from being processed as
31
+ * iterable objects, which is the root cause of the "Objects are not valid
32
+ * as a React child" error.
33
+ */
34
+ export declare const addMetadata: <T extends object>(id: string, obj: T, path?: (string | number)[]) => T;
28
35
  /**
29
36
  * This is a pretty rudimentary approach to hashing the query and variables to
30
37
  * ensure we treat multiple queries on the page uniquely. It's possible
package/dist/react.js CHANGED
@@ -1,67 +1,70 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
- })(this, function(exports2, React) {
4
- "use strict";
5
- function useTina(props) {
6
- const stringifiedQuery = JSON.stringify({
7
- query: props.query,
8
- variables: props.variables
1
+ import React from "react";
2
+ function useTina(props) {
3
+ const stringifiedQuery = JSON.stringify({
4
+ query: props.query,
5
+ variables: props.variables
6
+ });
7
+ const id = React.useMemo(
8
+ () => hashFromQuery(stringifiedQuery),
9
+ [stringifiedQuery]
10
+ );
11
+ const processedData = React.useMemo(() => {
12
+ if (props.data) {
13
+ const dataCopy = JSON.parse(JSON.stringify(props.data));
14
+ return addMetadata(id, dataCopy, []);
15
+ }
16
+ }, [props.data, id]);
17
+ const [data, setData] = React.useState(processedData);
18
+ const [isClient, setIsClient] = React.useState(false);
19
+ const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);
20
+ const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);
21
+ React.useEffect(() => {
22
+ setIsClient(true);
23
+ setData(processedData);
24
+ parent.postMessage({
25
+ type: "url-changed"
9
26
  });
10
- const id = React.useMemo(
11
- () => hashFromQuery(stringifiedQuery),
12
- [stringifiedQuery]
13
- );
14
- const [data, setData] = React.useState(props.data);
15
- const [isClient, setIsClient] = React.useState(false);
16
- const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);
17
- const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);
18
- React.useEffect(() => {
19
- setIsClient(true);
20
- setData(props.data);
21
- parent.postMessage({
22
- type: "url-changed"
23
- });
24
- }, [id]);
25
- React.useEffect(() => {
26
- if (quickEditEnabled) {
27
- let mouseDownHandler = function(e) {
28
- const attributeNames = e.target.getAttributeNames();
29
- const tinaAttribute = attributeNames.find(
30
- (name) => name.startsWith("data-tina-field")
27
+ }, [id, processedData]);
28
+ React.useEffect(() => {
29
+ if (quickEditEnabled) {
30
+ let mouseDownHandler = function(e) {
31
+ const attributeNames = e.target.getAttributeNames();
32
+ const tinaAttribute = attributeNames.find(
33
+ (name) => name.startsWith("data-tina-field")
34
+ );
35
+ let fieldName;
36
+ if (tinaAttribute) {
37
+ e.preventDefault();
38
+ e.stopPropagation();
39
+ fieldName = e.target.getAttribute(tinaAttribute);
40
+ } else {
41
+ const ancestor = e.target.closest(
42
+ "[data-tina-field], [data-tina-field-overlay]"
31
43
  );
32
- let fieldName;
33
- if (tinaAttribute) {
34
- e.preventDefault();
35
- e.stopPropagation();
36
- fieldName = e.target.getAttribute(tinaAttribute);
37
- } else {
38
- const ancestor = e.target.closest(
39
- "[data-tina-field], [data-tina-field-overlay]"
44
+ if (ancestor) {
45
+ const attributeNames2 = ancestor.getAttributeNames();
46
+ const tinaAttribute2 = attributeNames2.find(
47
+ (name) => name.startsWith("data-tina-field")
40
48
  );
41
- if (ancestor) {
42
- const attributeNames2 = ancestor.getAttributeNames();
43
- const tinaAttribute2 = attributeNames2.find(
44
- (name) => name.startsWith("data-tina-field")
45
- );
46
- if (tinaAttribute2) {
47
- e.preventDefault();
48
- e.stopPropagation();
49
- fieldName = ancestor.getAttribute(tinaAttribute2);
50
- }
49
+ if (tinaAttribute2) {
50
+ e.preventDefault();
51
+ e.stopPropagation();
52
+ fieldName = ancestor.getAttribute(tinaAttribute2);
51
53
  }
52
54
  }
53
- if (fieldName) {
54
- if (isInTinaIframe) {
55
- parent.postMessage(
56
- { type: "field:selected", fieldName },
57
- window.location.origin
58
- );
59
- }
55
+ }
56
+ if (fieldName) {
57
+ if (isInTinaIframe) {
58
+ parent.postMessage(
59
+ { type: "field:selected", fieldName },
60
+ window.location.origin
61
+ );
60
62
  }
61
- };
62
- const style = document.createElement("style");
63
- style.type = "text/css";
64
- style.textContent = `
63
+ }
64
+ };
65
+ const style = document.createElement("style");
66
+ style.type = "text/css";
67
+ style.textContent = `
65
68
  [data-tina-field] {
66
69
  outline: 2px dashed rgba(34,150,254,0.5);
67
70
  transition: box-shadow ease-out 150ms;
@@ -92,158 +95,160 @@
92
95
  opacity: 1;
93
96
  }
94
97
  `;
95
- document.head.appendChild(style);
96
- document.body.classList.add("__tina-quick-editing-enabled");
97
- document.addEventListener("click", mouseDownHandler, true);
98
- return () => {
99
- document.removeEventListener("click", mouseDownHandler, true);
100
- document.body.classList.remove("__tina-quick-editing-enabled");
101
- style.remove();
102
- };
103
- }
104
- }, [quickEditEnabled, isInTinaIframe]);
105
- React.useEffect(() => {
106
- if (props == null ? void 0 : props.experimental___selectFormByFormId) {
107
- parent.postMessage({
108
- type: "user-select-form",
109
- formId: props.experimental___selectFormByFormId()
110
- });
111
- }
112
- }, [id]);
113
- React.useEffect(() => {
114
- const { experimental___selectFormByFormId, ...rest } = props;
115
- parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
116
- window.addEventListener("message", (event) => {
117
- if (event.data.type === "quickEditEnabled") {
118
- setQuickEditEnabled(event.data.value);
119
- }
120
- if (event.data.id === id && event.data.type === "updateData") {
121
- setData(event.data.data);
122
- setIsInTinaIframe(true);
123
- const anyTinaField = document.querySelector("[data-tina-field]");
124
- if (anyTinaField) {
125
- parent.postMessage(
126
- { type: "quick-edit", value: true },
127
- window.location.origin
128
- );
129
- } else {
130
- parent.postMessage(
131
- { type: "quick-edit", value: false },
132
- window.location.origin
133
- );
134
- }
135
- }
136
- });
98
+ document.head.appendChild(style);
99
+ document.body.classList.add("__tina-quick-editing-enabled");
100
+ document.addEventListener("click", mouseDownHandler, true);
137
101
  return () => {
138
- parent.postMessage({ type: "close", id }, window.location.origin);
102
+ document.removeEventListener("click", mouseDownHandler, true);
103
+ document.body.classList.remove("__tina-quick-editing-enabled");
104
+ style.remove();
139
105
  };
140
- }, [id, setQuickEditEnabled]);
141
- return { data, isClient };
142
- }
143
- function useEditState() {
144
- const [edit, setEdit] = React.useState(false);
145
- React.useEffect(() => {
146
- if (typeof window !== "undefined") {
147
- parent.postMessage({ type: "isEditMode" }, window.location.origin);
148
- window.addEventListener("message", (event) => {
149
- var _a;
150
- if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
151
- setEdit(true);
152
- }
153
- });
154
- }
155
- }, []);
156
- return { edit };
157
- }
158
- const tinaField = (object, property, index) => {
159
- var _a, _b, _c;
160
- if (!object) {
161
- return "";
162
106
  }
163
- if (object._content_source) {
164
- if (!property) {
165
- return [
166
- (_a = object._content_source) == null ? void 0 : _a.queryId,
167
- object._content_source.path.join(".")
168
- ].join("---");
169
- }
170
- if (typeof index === "number") {
171
- return [
172
- (_b = object._content_source) == null ? void 0 : _b.queryId,
173
- [...object._content_source.path, property, index].join(".")
174
- ].join("---");
175
- }
176
- return [
177
- (_c = object._content_source) == null ? void 0 : _c.queryId,
178
- [...object._content_source.path, property].join(".")
179
- ].join("---");
107
+ }, [quickEditEnabled, isInTinaIframe]);
108
+ React.useEffect(() => {
109
+ if (props == null ? void 0 : props.experimental___selectFormByFormId) {
110
+ parent.postMessage({
111
+ type: "user-select-form",
112
+ formId: props.experimental___selectFormByFormId()
113
+ });
180
114
  }
181
- return "";
182
- };
183
- const addMetadata = (id, object, path) => {
184
- Object.entries(object).forEach(([key, value]) => {
185
- if (Array.isArray(value)) {
186
- value.forEach((item, index) => {
187
- if (isScalarOrUndefined(item)) {
188
- return;
189
- }
190
- if (Array.isArray(item)) {
191
- return;
192
- }
193
- const itemObject = item;
194
- addMetadata(id, itemObject, [...path, key, index]);
195
- });
196
- } else {
197
- if (isScalarOrUndefined(value)) {
198
- return;
115
+ }, [id]);
116
+ React.useEffect(() => {
117
+ const { experimental___selectFormByFormId, ...rest } = props;
118
+ parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
119
+ const handleMessage = (event) => {
120
+ if (event.data.type === "quickEditEnabled") {
121
+ setQuickEditEnabled(event.data.value);
122
+ }
123
+ if (event.data.id === id && event.data.type === "updateData") {
124
+ const rawData = event.data.data;
125
+ const newlyProcessedData = addMetadata(
126
+ id,
127
+ JSON.parse(JSON.stringify(rawData)),
128
+ []
129
+ );
130
+ setData(newlyProcessedData);
131
+ setIsInTinaIframe(true);
132
+ const anyTinaField = document.querySelector("[data-tina-field]");
133
+ if (anyTinaField) {
134
+ parent.postMessage(
135
+ { type: "quick-edit", value: true },
136
+ window.location.origin
137
+ );
138
+ } else {
139
+ parent.postMessage(
140
+ { type: "quick-edit", value: false },
141
+ window.location.origin
142
+ );
199
143
  }
200
- const itemObject = value;
201
- addMetadata(id, itemObject, [...path, key]);
202
144
  }
203
- });
204
- if ((object == null ? void 0 : object.type) === "root") {
205
- return;
206
- }
207
- object._content_source = {
208
- queryId: id,
209
- path
210
145
  };
211
- return object;
212
- };
213
- function isScalarOrUndefined(value) {
214
- const type = typeof value;
215
- if (type === "string")
216
- return true;
217
- if (type === "number")
218
- return true;
219
- if (type === "boolean")
220
- return true;
221
- if (type === "undefined")
222
- return true;
223
- if (value == null)
224
- return true;
225
- if (value instanceof String)
226
- return true;
227
- if (value instanceof Number)
228
- return true;
229
- if (value instanceof Boolean)
230
- return true;
231
- return false;
146
+ window.addEventListener("message", handleMessage);
147
+ return () => {
148
+ window.removeEventListener("message", handleMessage);
149
+ parent.postMessage({ type: "close", id }, window.location.origin);
150
+ };
151
+ }, [id, setQuickEditEnabled]);
152
+ return { data, isClient };
153
+ }
154
+ function useEditState() {
155
+ const [edit, setEdit] = React.useState(false);
156
+ React.useEffect(() => {
157
+ if (typeof window !== "undefined") {
158
+ parent.postMessage({ type: "isEditMode" }, window.location.origin);
159
+ window.addEventListener("message", (event) => {
160
+ var _a;
161
+ if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
162
+ setEdit(true);
163
+ }
164
+ });
165
+ }
166
+ }, []);
167
+ return { edit };
168
+ }
169
+ const tinaField = (object, property, index) => {
170
+ const contentSource = object == null ? void 0 : object._content_source;
171
+ if (!contentSource) {
172
+ return "";
173
+ }
174
+ const { queryId, path } = contentSource;
175
+ if (!property) {
176
+ return `${queryId}---${path.join(".")}`;
177
+ }
178
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
179
+ return `${queryId}---${fullPath.join(".")}`;
180
+ };
181
+ const addMetadata = (id, obj, path = []) => {
182
+ if (obj === null) {
183
+ return obj;
184
+ }
185
+ if (isScalarOrUndefined(obj)) {
186
+ return obj;
232
187
  }
233
- const hashFromQuery = (input) => {
234
- let hash = 0;
235
- for (let i = 0; i < input.length; i++) {
236
- const char = input.charCodeAt(i);
237
- hash = (hash << 5) - hash + char & 4294967295;
188
+ if (obj instanceof String) {
189
+ return obj.valueOf();
190
+ }
191
+ if (Array.isArray(obj)) {
192
+ return obj.map(
193
+ (item, index) => addMetadata(id, item, [...path, index])
194
+ );
195
+ }
196
+ const transformedObj = {};
197
+ for (const [key, value] of Object.entries(obj)) {
198
+ const currentPath = [...path, key];
199
+ if ([
200
+ "__typename",
201
+ "_sys",
202
+ "_internalSys",
203
+ "_values",
204
+ "_internalValues",
205
+ "_content_source",
206
+ "_tina_metadata"
207
+ ].includes(key)) {
208
+ transformedObj[key] = value;
209
+ } else {
210
+ transformedObj[key] = addMetadata(id, value, currentPath);
238
211
  }
239
- const nonNegativeHash = Math.abs(hash);
240
- const alphanumericHash = nonNegativeHash.toString(36);
241
- return alphanumericHash;
242
- };
243
- exports2.addMetadata = addMetadata;
244
- exports2.hashFromQuery = hashFromQuery;
245
- exports2.tinaField = tinaField;
246
- exports2.useEditState = useEditState;
247
- exports2.useTina = useTina;
248
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
249
- });
212
+ }
213
+ if (transformedObj && typeof transformedObj === "object" && "type" in transformedObj && transformedObj.type === "root") {
214
+ return transformedObj;
215
+ }
216
+ return { ...transformedObj, _content_source: { queryId: id, path } };
217
+ };
218
+ function isScalarOrUndefined(value) {
219
+ const type = typeof value;
220
+ if (type === "string")
221
+ return true;
222
+ if (type === "number")
223
+ return true;
224
+ if (type === "boolean")
225
+ return true;
226
+ if (type === "undefined")
227
+ return true;
228
+ if (value == null)
229
+ return true;
230
+ if (value instanceof String)
231
+ return true;
232
+ if (value instanceof Number)
233
+ return true;
234
+ if (value instanceof Boolean)
235
+ return true;
236
+ return false;
237
+ }
238
+ const hashFromQuery = (input) => {
239
+ let hash = 0;
240
+ for (let i = 0; i < input.length; i++) {
241
+ const char = input.charCodeAt(i);
242
+ hash = (hash << 5) - hash + char & 4294967295;
243
+ }
244
+ const nonNegativeHash = Math.abs(hash);
245
+ const alphanumericHash = nonNegativeHash.toString(36);
246
+ return alphanumericHash;
247
+ };
248
+ export {
249
+ addMetadata,
250
+ hashFromQuery,
251
+ tinaField,
252
+ useEditState,
253
+ useTina
254
+ };
@@ -58,9 +58,15 @@ type BaseComponents = {
58
58
  lic?: {
59
59
  children: JSX.Element;
60
60
  };
61
+ /**
62
+ * @deprecated Use `blockquote` instead. This was incorrectly named and will be removed in a future version.
63
+ */
61
64
  block_quote?: {
62
65
  children: JSX.Element;
63
66
  };
67
+ blockquote?: {
68
+ children: JSX.Element;
69
+ };
64
70
  code_block?: {
65
71
  lang?: string;
66
72
  value: string;