tinacms 0.0.0-ad8dbc0-20241003000436 → 0.0.0-b012b6c-20250808011625

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 (165) hide show
  1. package/README.md +1 -1
  2. package/dist/admin/api.d.ts +4 -0
  3. package/dist/admin/components/GetCollection.d.ts +2 -2
  4. package/dist/admin/components/Page.d.ts +3 -9
  5. package/dist/admin/components/Sidebar.d.ts +0 -3
  6. package/dist/admin/components/ui/tooltip.d.ts +7 -0
  7. package/dist/admin/pages/CollectionCreatePage.d.ts +1 -1
  8. package/dist/admin/pages/CollectionListPage.d.ts +2 -2
  9. package/dist/admin/pages/DashboardPage.d.ts +0 -3
  10. package/dist/admin/pages/ScreenPage.d.ts +0 -3
  11. package/dist/admin/types.d.ts +3 -0
  12. package/dist/auth/TinaCloudProvider.d.ts +1 -1
  13. package/dist/cache/node-cache.d.ts +1 -0
  14. package/dist/client.js +101 -63
  15. package/dist/client.mjs +60 -37
  16. package/dist/hooks/create-page-plugin.d.ts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +103920 -14406
  19. package/dist/index.mjs +103944 -14426
  20. package/dist/internalClient/index.d.ts +28 -3
  21. package/dist/node-cache-5e8db9f0.mjs +63 -0
  22. package/dist/react.d.ts +14 -6
  23. package/dist/react.js +73 -53
  24. package/dist/react.mjs +73 -53
  25. package/dist/rich-text/index.d.ts +3 -0
  26. package/dist/rich-text/index.js +54 -15
  27. package/dist/rich-text/index.mjs +54 -15
  28. package/dist/rich-text/prism.js +1 -1
  29. package/dist/rich-text/prism.mjs +1 -1
  30. package/dist/rich-text/static.d.ts +148 -0
  31. package/dist/rich-text/static.js +239 -0
  32. package/dist/rich-text/static.mjs +236 -0
  33. package/dist/toolkit/components/ProgressBar.d.ts +11 -0
  34. package/dist/toolkit/components/media/media-item.d.ts +11 -1
  35. package/dist/toolkit/components/media/media-manager.d.ts +1 -1
  36. package/dist/toolkit/components/ui/breadcrumb.d.ts +11 -0
  37. package/dist/toolkit/components/ui/dropdown-menu.d.ts +25 -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/reference/reference-select.d.ts +2 -2
  44. package/dist/toolkit/fields/components/select.d.ts +2 -2
  45. package/dist/toolkit/fields/components/text-field.d.ts +1 -1
  46. package/dist/toolkit/fields/plugins/group-field-plugin.d.ts +1 -1
  47. package/dist/toolkit/fields/plugins/group-list-field-plugin.d.ts +1 -0
  48. package/dist/toolkit/fields/plugins/list-field-meta.d.ts +1 -1
  49. package/dist/toolkit/fields/plugins/list-field-plugin.d.ts +1 -0
  50. package/dist/toolkit/fields/plugins/mdx-field-plugin/index.d.ts +5 -2
  51. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +20 -18
  52. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/fixed-toolbar-buttons.d.ts +0 -4
  53. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +14 -10
  54. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +3 -3
  55. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +17 -0
  56. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/error-message.d.ts +6 -0
  57. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-combobox.d.ts +6 -0
  58. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-toolbar-button.d.ts +6 -6
  59. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-leaf.d.ts +2 -11
  60. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +14 -10
  61. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-syntax-leaf.d.ts +2 -11
  62. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +112 -0
  63. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dialog.d.ts +12 -0
  64. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dropdown-menu.d.ts +10 -10
  65. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/floating-toolbar.d.ts +2 -2
  66. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-element.d.ts +3 -0
  67. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-toolbar-button.d.ts +18 -0
  68. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/icons.d.ts +4 -1
  69. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/image-toolbar-button.d.ts +6 -6
  70. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +6 -7
  71. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/inline-combobox.d.ts +1 -1
  72. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/input.d.ts +3 -3
  73. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-element.d.ts +4 -11
  74. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-floating-toolbar.d.ts +4 -5
  75. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-toolbar-button.d.ts +4 -4
  76. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +28 -11
  77. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mark-toolbar-button.d.ts +4 -18
  78. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-element.d.ts +4 -0
  79. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-toolbar-button.d.ts +18 -0
  80. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +15 -0
  81. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/popover.d.ts +7 -2
  82. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/quote-toolbar-button.d.ts +6 -6
  83. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/raw-markdown-toolbar-button.d.ts +6 -6
  84. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/resizable.d.ts +42 -0
  85. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/separator.d.ts +2 -2
  86. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +15 -11
  87. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/block-selection.d.ts +6 -0
  88. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +33 -0
  89. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-dropdown-menu.d.ts +4 -0
  90. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +20 -0
  91. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +15 -0
  92. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/text-area.d.ts +5 -0
  93. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/toolbar.d.ts +7 -7
  94. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +10 -0
  95. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-state.d.ts +22 -0
  96. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/hooks/use-create-editor.d.ts +6 -0
  97. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/index.d.ts +1 -1
  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 +12 -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 +264 -156
  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 +11 -3
  114. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-provider.d.ts +3 -3
  115. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/is-url.d.ts +1 -2
  116. package/dist/toolkit/fields/plugins/wrap-field-with-meta.d.ts +8 -0
  117. package/dist/toolkit/form-builder/editorial-workflow-constants.d.ts +17 -0
  118. package/dist/toolkit/form-builder/fields-builder.d.ts +1 -1
  119. package/dist/toolkit/form-builder/form-builder.d.ts +15 -5
  120. package/dist/toolkit/forms/field.d.ts +3 -0
  121. package/dist/toolkit/forms/form.d.ts +22 -3
  122. package/dist/toolkit/git-client/git-client.d.ts +25 -2
  123. package/dist/toolkit/git-client/git-file.d.ts +18 -0
  124. package/dist/toolkit/git-client/git-media-store.d.ts +13 -0
  125. package/dist/toolkit/git-client/use-git-file.d.ts +4 -0
  126. package/dist/toolkit/icons/Tina.d.ts +0 -5
  127. package/dist/toolkit/index.d.ts +1 -1
  128. package/dist/toolkit/plugin-branch-switcher/branch-button.d.ts +1 -0
  129. package/dist/toolkit/plugin-branch-switcher/branch-switcher-legacy.d.ts +1 -1
  130. package/dist/toolkit/plugin-branch-switcher/branch-switcher.d.ts +1 -1
  131. package/dist/toolkit/plugin-branch-switcher/index.d.ts +0 -1
  132. package/dist/toolkit/react-cloud-config/cloud-config-plugin.d.ts +3 -3
  133. package/dist/toolkit/react-sidebar/components/VersionInfo.d.ts +2 -0
  134. package/dist/toolkit/react-sidebar/components/alert.d.ts +5 -0
  135. package/dist/toolkit/react-sidebar/components/form-list.d.ts +1 -1
  136. package/dist/toolkit/react-sidebar/components/nav.d.ts +6 -3
  137. package/dist/toolkit/react-sidebar/components/resize-handle.d.ts +0 -5
  138. package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +7 -10
  139. package/dist/toolkit/react-sidebar/components/sidebar-loading-placeholder.d.ts +2 -0
  140. package/dist/toolkit/react-sidebar/components/sidebar-no-forms-placeholder.d.ts +2 -0
  141. package/dist/toolkit/react-sidebar/components/sidebar.d.ts +0 -7
  142. package/dist/toolkit/react-sidebar/components/sync-status.d.ts +5 -8
  143. package/dist/toolkit/react-sidebar/index.d.ts +1 -1
  144. package/dist/toolkit/react-sidebar/sidebar.d.ts +2 -2
  145. package/dist/toolkit/styles/button.d.ts +2 -2
  146. package/dist/toolkit/tina-cms.d.ts +3 -3
  147. package/dist/toolkit/tina-state.d.ts +15 -0
  148. package/dist/unifiedClient/index.d.ts +8 -1
  149. package/dist/utils/cn.d.ts +2 -0
  150. package/package.json +75 -60
  151. package/dist/__vite-browser-external-d06ac358.mjs +0 -4
  152. package/dist/admin/pages/IndexingPage.d.ts +0 -2
  153. package/dist/node-cache-7fa2452c.mjs +0 -43
  154. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-element.d.ts +0 -11
  155. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/with-correct-void-behavior.d.ts +0 -8
  156. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-code-block/index.d.ts +0 -3
  157. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-link-plugin/index.d.ts +0 -15
  158. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/create-soft-break-plugin.d.ts +0 -7
  159. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/index.d.ts +0 -6
  160. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/on-key-down-soft-break.d.ts +0 -5
  161. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/types.d.ts +0 -11
  162. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/code-block/index.d.ts +0 -9
  163. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/insert-empty-block.d.ts +0 -2
  164. package/dist/toolkit/plugin-branch-switcher/branch-banner.d.ts +0 -2
  165. package/dist/toolkit/react-sidebar/components/no-forms-placeholder.d.ts +0 -8
@@ -1,10 +1,10 @@
1
- import { TokenObject } from '../auth/authenticate';
2
1
  import { BranchData, EventBus } from '@tinacms/toolkit';
3
2
  import { DocumentNode, GraphQLSchema } from 'graphql';
3
+ import { TokenObject } from '../auth/authenticate';
4
+ import { AuthProvider, Schema, TinaSchema } from '@tinacms/schema-tools';
5
+ import { SearchClient } from '@tinacms/search/dist/index-client';
4
6
  import gql from 'graphql-tag';
5
- import { TinaSchema, Schema, AuthProvider } from '@tinacms/schema-tools';
6
7
  import { TinaCloudProject } from './types';
7
- import { SearchClient } from '@tinacms/search/dist/index-client';
8
8
  export * from './authProvider';
9
9
  export type OnLoginFunc = (args: {
10
10
  token?: TokenObject;
@@ -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 {
@@ -185,3 +205,8 @@ export declare class LocalSearchClient implements SearchClient {
185
205
  put(docs: any[]): Promise<any>;
186
206
  supportsClientSideIndexing(): boolean;
187
207
  }
208
+ export type PackageVersionInfo = {
209
+ version: string;
210
+ publishedAt: string;
211
+ };
212
+ export type LatestVersionResponse = Record<string, PackageVersionInfo>;
@@ -0,0 +1,63 @@
1
+ const makeCacheDir = async (dir, fs, path, os) => {
2
+ const pathParts = dir.split(path.sep).filter(Boolean);
3
+ const cacheHash = pathParts[pathParts.length - 1];
4
+ const rootUser = pathParts[0];
5
+ let cacheDir = dir;
6
+ if (!fs.existsSync(path.join(path.sep, rootUser))) {
7
+ cacheDir = path.join(os.tmpdir(), cacheHash);
8
+ }
9
+ try {
10
+ fs.mkdirSync(cacheDir, { recursive: true });
11
+ } catch (error) {
12
+ throw new Error(`Failed to create cache directory: ${error.message}`);
13
+ }
14
+ return cacheDir;
15
+ };
16
+ const NodeCache = async (dir) => {
17
+ const fs = require("node:fs");
18
+ const path = require("node:path");
19
+ const os = require("node:os");
20
+ const { createHash } = require("node:crypto");
21
+ const cacheDir = await makeCacheDir(dir, fs, path, os);
22
+ return {
23
+ makeKey: (key) => {
24
+ const input = key && key instanceof Object ? JSON.stringify(key) : key || "";
25
+ return createHash("sha256").update(input).digest("hex");
26
+ },
27
+ get: async (key) => {
28
+ let readValue;
29
+ const cacheFilename = `${cacheDir}/${key}`;
30
+ try {
31
+ const data = await fs.promises.readFile(cacheFilename, "utf-8");
32
+ readValue = JSON.parse(data);
33
+ } catch (e) {
34
+ if (e.code !== "ENOENT") {
35
+ console.error(
36
+ `Failed to read cache file to ${cacheFilename}: ${e.message}`
37
+ );
38
+ }
39
+ }
40
+ return readValue;
41
+ },
42
+ set: async (key, value) => {
43
+ const cacheFilename = `${cacheDir}/${key}`;
44
+ try {
45
+ await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
46
+ encoding: "utf-8",
47
+ flag: "wx"
48
+ // Don't overwrite existing caches
49
+ });
50
+ } catch (e) {
51
+ if (e.code !== "EEXIST") {
52
+ console.error(
53
+ `Failed to write cache file to ${cacheFilename}: ${e.message}`
54
+ );
55
+ }
56
+ }
57
+ }
58
+ };
59
+ };
60
+ export {
61
+ NodeCache,
62
+ makeCacheDir
63
+ };
package/dist/react.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare function useTina<T extends object>(props: {
2
2
  query: string;
3
3
  variables: object;
4
4
  data: T;
5
+ experimental___selectFormByFormId?: () => string | false | undefined;
5
6
  }): {
6
7
  data: T;
7
8
  isClient: boolean;
@@ -14,16 +15,23 @@ export declare function useEditState(): {
14
15
  * to signal to Tina which DOM element the field
15
16
  * is working with.
16
17
  */
17
- 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 {
18
23
  _content_source?: {
19
24
  queryId: string;
20
25
  path: (number | string)[];
21
26
  };
22
- }) | undefined | null>(object: T, property?: keyof Omit<NonNullable<T>, "__typename" | "_sys">, index?: number) => string;
23
- export declare const addMetadata: <T extends object>(id: string, object: T & {
24
- type?: string;
25
- _content_source?: unknown;
26
- }, 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;
27
35
  /**
28
36
  * This is a pretty rudimentary approach to hashing the query and variables to
29
37
  * ensure we treat multiple queries on the page uniquely. It's possible
package/dist/react.js CHANGED
@@ -11,14 +11,23 @@
11
11
  () => hashFromQuery(stringifiedQuery),
12
12
  [stringifiedQuery]
13
13
  );
14
- const [data, setData] = React.useState(props.data);
14
+ const processedData = React.useMemo(() => {
15
+ if (props.data) {
16
+ const dataCopy = JSON.parse(JSON.stringify(props.data));
17
+ return addMetadata(id, dataCopy, []);
18
+ }
19
+ }, [props.data, id]);
20
+ const [data, setData] = React.useState(processedData);
15
21
  const [isClient, setIsClient] = React.useState(false);
16
22
  const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);
17
23
  const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);
18
24
  React.useEffect(() => {
19
25
  setIsClient(true);
20
- setData(props.data);
21
- }, [id]);
26
+ setData(processedData);
27
+ parent.postMessage({
28
+ type: "url-changed"
29
+ });
30
+ }, [id, processedData]);
22
31
  React.useEffect(() => {
23
32
  if (quickEditEnabled) {
24
33
  let mouseDownHandler = function(e) {
@@ -100,13 +109,28 @@
100
109
  }
101
110
  }, [quickEditEnabled, isInTinaIframe]);
102
111
  React.useEffect(() => {
103
- parent.postMessage({ type: "open", ...props, id }, window.location.origin);
104
- window.addEventListener("message", (event) => {
112
+ if (props == null ? void 0 : props.experimental___selectFormByFormId) {
113
+ parent.postMessage({
114
+ type: "user-select-form",
115
+ formId: props.experimental___selectFormByFormId()
116
+ });
117
+ }
118
+ }, [id]);
119
+ React.useEffect(() => {
120
+ const { experimental___selectFormByFormId, ...rest } = props;
121
+ parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
122
+ const handleMessage = (event) => {
105
123
  if (event.data.type === "quickEditEnabled") {
106
124
  setQuickEditEnabled(event.data.value);
107
125
  }
108
126
  if (event.data.id === id && event.data.type === "updateData") {
109
- setData(event.data.data);
127
+ const rawData = event.data.data;
128
+ const newlyProcessedData = addMetadata(
129
+ id,
130
+ JSON.parse(JSON.stringify(rawData)),
131
+ []
132
+ );
133
+ setData(newlyProcessedData);
110
134
  setIsInTinaIframe(true);
111
135
  const anyTinaField = document.querySelector("[data-tina-field]");
112
136
  if (anyTinaField) {
@@ -121,8 +145,10 @@
121
145
  );
122
146
  }
123
147
  }
124
- });
148
+ };
149
+ window.addEventListener("message", handleMessage);
125
150
  return () => {
151
+ window.removeEventListener("message", handleMessage);
126
152
  parent.postMessage({ type: "close", id }, window.location.origin);
127
153
  };
128
154
  }, [id, setQuickEditEnabled]);
@@ -144,59 +170,53 @@
144
170
  return { edit };
145
171
  }
146
172
  const tinaField = (object, property, index) => {
147
- var _a, _b, _c;
148
- if (!object) {
173
+ const contentSource = object == null ? void 0 : object._content_source;
174
+ if (!contentSource) {
149
175
  return "";
150
176
  }
151
- if (object._content_source) {
152
- if (!property) {
153
- return [
154
- (_a = object._content_source) == null ? void 0 : _a.queryId,
155
- object._content_source.path.join(".")
156
- ].join("---");
157
- }
158
- if (typeof index === "number") {
159
- return [
160
- (_b = object._content_source) == null ? void 0 : _b.queryId,
161
- [...object._content_source.path, property, index].join(".")
162
- ].join("---");
163
- }
164
- return [
165
- (_c = object._content_source) == null ? void 0 : _c.queryId,
166
- [...object._content_source.path, property].join(".")
167
- ].join("---");
177
+ const { queryId, path } = contentSource;
178
+ if (!property) {
179
+ return `${queryId}---${path.join(".")}`;
168
180
  }
169
- return "";
181
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
182
+ return `${queryId}---${fullPath.join(".")}`;
170
183
  };
171
- const addMetadata = (id, object, path) => {
172
- Object.entries(object).forEach(([key, value]) => {
173
- if (Array.isArray(value)) {
174
- value.forEach((item, index) => {
175
- if (isScalarOrUndefined(item)) {
176
- return;
177
- }
178
- if (Array.isArray(item)) {
179
- return;
180
- }
181
- const itemObject = item;
182
- addMetadata(id, itemObject, [...path, key, index]);
183
- });
184
+ const addMetadata = (id, obj, path = []) => {
185
+ if (obj === null) {
186
+ return obj;
187
+ }
188
+ if (isScalarOrUndefined(obj)) {
189
+ return obj;
190
+ }
191
+ if (obj instanceof String) {
192
+ return obj.valueOf();
193
+ }
194
+ if (Array.isArray(obj)) {
195
+ return obj.map(
196
+ (item, index) => addMetadata(id, item, [...path, index])
197
+ );
198
+ }
199
+ const transformedObj = {};
200
+ for (const [key, value] of Object.entries(obj)) {
201
+ const currentPath = [...path, key];
202
+ if ([
203
+ "__typename",
204
+ "_sys",
205
+ "_internalSys",
206
+ "_values",
207
+ "_internalValues",
208
+ "_content_source",
209
+ "_tina_metadata"
210
+ ].includes(key)) {
211
+ transformedObj[key] = value;
184
212
  } else {
185
- if (isScalarOrUndefined(value)) {
186
- return;
187
- }
188
- const itemObject = value;
189
- addMetadata(id, itemObject, [...path, key]);
213
+ transformedObj[key] = addMetadata(id, value, currentPath);
190
214
  }
191
- });
192
- if ((object == null ? void 0 : object.type) === "root") {
193
- return;
194
215
  }
195
- object._content_source = {
196
- queryId: id,
197
- path
198
- };
199
- return object;
216
+ if (transformedObj && typeof transformedObj === "object" && "type" in transformedObj && transformedObj.type === "root") {
217
+ return transformedObj;
218
+ }
219
+ return { ...transformedObj, _content_source: { queryId: id, path } };
200
220
  };
201
221
  function isScalarOrUndefined(value) {
202
222
  const type = typeof value;
package/dist/react.mjs CHANGED
@@ -8,14 +8,23 @@ function useTina(props) {
8
8
  () => hashFromQuery(stringifiedQuery),
9
9
  [stringifiedQuery]
10
10
  );
11
- const [data, setData] = React.useState(props.data);
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);
12
18
  const [isClient, setIsClient] = React.useState(false);
13
19
  const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);
14
20
  const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);
15
21
  React.useEffect(() => {
16
22
  setIsClient(true);
17
- setData(props.data);
18
- }, [id]);
23
+ setData(processedData);
24
+ parent.postMessage({
25
+ type: "url-changed"
26
+ });
27
+ }, [id, processedData]);
19
28
  React.useEffect(() => {
20
29
  if (quickEditEnabled) {
21
30
  let mouseDownHandler = function(e) {
@@ -97,13 +106,28 @@ function useTina(props) {
97
106
  }
98
107
  }, [quickEditEnabled, isInTinaIframe]);
99
108
  React.useEffect(() => {
100
- parent.postMessage({ type: "open", ...props, id }, window.location.origin);
101
- window.addEventListener("message", (event) => {
109
+ if (props == null ? void 0 : props.experimental___selectFormByFormId) {
110
+ parent.postMessage({
111
+ type: "user-select-form",
112
+ formId: props.experimental___selectFormByFormId()
113
+ });
114
+ }
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) => {
102
120
  if (event.data.type === "quickEditEnabled") {
103
121
  setQuickEditEnabled(event.data.value);
104
122
  }
105
123
  if (event.data.id === id && event.data.type === "updateData") {
106
- setData(event.data.data);
124
+ const rawData = event.data.data;
125
+ const newlyProcessedData = addMetadata(
126
+ id,
127
+ JSON.parse(JSON.stringify(rawData)),
128
+ []
129
+ );
130
+ setData(newlyProcessedData);
107
131
  setIsInTinaIframe(true);
108
132
  const anyTinaField = document.querySelector("[data-tina-field]");
109
133
  if (anyTinaField) {
@@ -118,8 +142,10 @@ function useTina(props) {
118
142
  );
119
143
  }
120
144
  }
121
- });
145
+ };
146
+ window.addEventListener("message", handleMessage);
122
147
  return () => {
148
+ window.removeEventListener("message", handleMessage);
123
149
  parent.postMessage({ type: "close", id }, window.location.origin);
124
150
  };
125
151
  }, [id, setQuickEditEnabled]);
@@ -141,59 +167,53 @@ function useEditState() {
141
167
  return { edit };
142
168
  }
143
169
  const tinaField = (object, property, index) => {
144
- var _a, _b, _c;
145
- if (!object) {
170
+ const contentSource = object == null ? void 0 : object._content_source;
171
+ if (!contentSource) {
146
172
  return "";
147
173
  }
148
- if (object._content_source) {
149
- if (!property) {
150
- return [
151
- (_a = object._content_source) == null ? void 0 : _a.queryId,
152
- object._content_source.path.join(".")
153
- ].join("---");
154
- }
155
- if (typeof index === "number") {
156
- return [
157
- (_b = object._content_source) == null ? void 0 : _b.queryId,
158
- [...object._content_source.path, property, index].join(".")
159
- ].join("---");
160
- }
161
- return [
162
- (_c = object._content_source) == null ? void 0 : _c.queryId,
163
- [...object._content_source.path, property].join(".")
164
- ].join("---");
174
+ const { queryId, path } = contentSource;
175
+ if (!property) {
176
+ return `${queryId}---${path.join(".")}`;
165
177
  }
166
- return "";
178
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
179
+ return `${queryId}---${fullPath.join(".")}`;
167
180
  };
168
- const addMetadata = (id, object, path) => {
169
- Object.entries(object).forEach(([key, value]) => {
170
- if (Array.isArray(value)) {
171
- value.forEach((item, index) => {
172
- if (isScalarOrUndefined(item)) {
173
- return;
174
- }
175
- if (Array.isArray(item)) {
176
- return;
177
- }
178
- const itemObject = item;
179
- addMetadata(id, itemObject, [...path, key, index]);
180
- });
181
+ const addMetadata = (id, obj, path = []) => {
182
+ if (obj === null) {
183
+ return obj;
184
+ }
185
+ if (isScalarOrUndefined(obj)) {
186
+ return obj;
187
+ }
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;
181
209
  } else {
182
- if (isScalarOrUndefined(value)) {
183
- return;
184
- }
185
- const itemObject = value;
186
- addMetadata(id, itemObject, [...path, key]);
210
+ transformedObj[key] = addMetadata(id, value, currentPath);
187
211
  }
188
- });
189
- if ((object == null ? void 0 : object.type) === "root") {
190
- return;
191
212
  }
192
- object._content_source = {
193
- queryId: id,
194
- path
195
- };
196
- return object;
213
+ if (transformedObj && typeof transformedObj === "object" && "type" in transformedObj && transformedObj.type === "root") {
214
+ return transformedObj;
215
+ }
216
+ return { ...transformedObj, _content_source: { queryId: id, path } };
197
217
  };
198
218
  function isScalarOrUndefined(value) {
199
219
  const type = typeof value;
@@ -65,6 +65,9 @@ type BaseComponents = {
65
65
  lang?: string;
66
66
  value: string;
67
67
  };
68
+ mermaid?: {
69
+ value: string;
70
+ };
68
71
  img?: {
69
72
  url: string;
70
73
  caption?: string;
@@ -72,7 +72,7 @@
72
72
  return MNode;
73
73
  };
74
74
  const Node = ({ components, child }) => {
75
- var _a, _b, _c, _d, _e, _f;
75
+ var _a, _b, _c, _d, _e, _f, _g;
76
76
  const { children, ...props } = child;
77
77
  switch (child.type) {
78
78
  case "h1":
@@ -117,16 +117,24 @@
117
117
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
118
118
  /* @__PURE__ */ React.createElement("a", { href: child.url }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }))
119
119
  );
120
- case "code_block":
121
- const value = child.value;
120
+ case "code_block": {
121
+ let codeString = "";
122
+ if (Array.isArray(child.children)) {
123
+ codeString = child.children.map(
124
+ (line) => Array.isArray(line.children) ? line.children.map((t) => t.text).join("") : ""
125
+ ).join("\n");
126
+ } else if (typeof child.value === "string") {
127
+ codeString = child.value;
128
+ }
122
129
  if (components[child.type]) {
123
130
  const Component2 = components[child.type];
124
131
  return (
125
132
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
126
- /* @__PURE__ */ React.createElement(Component2, { ...props })
133
+ /* @__PURE__ */ React.createElement(Component2, { ...props, value: codeString })
127
134
  );
128
135
  }
129
- return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, value));
136
+ return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, codeString));
137
+ }
130
138
  case "hr":
131
139
  if (components[child.type]) {
132
140
  const Component2 = components[child.type];
@@ -150,33 +158,33 @@
150
158
  } else {
151
159
  if (child.name === "table") {
152
160
  const firstRowHeader = (_a = child.props) == null ? void 0 : _a.firstRowHeader;
153
- const rows = (firstRowHeader ? (_b = child.props) == null ? void 0 : _b.tableRows.filter((_, i) => i !== 0) : (_c = child.props) == null ? void 0 : _c.tableRows) || [];
161
+ const rows2 = (firstRowHeader ? (_b = child.props) == null ? void 0 : _b.tableRows.filter((_, i) => i !== 0) : (_c = child.props) == null ? void 0 : _c.tableRows) || [];
154
162
  const header = (_e = (_d = child.props) == null ? void 0 : _d.tableRows) == null ? void 0 : _e.at(0);
155
- const TableComponent = components["table"] || ((props2) => /* @__PURE__ */ React.createElement("table", { ...props2 }));
156
- const TrComponent = components["tr"] || ((props2) => /* @__PURE__ */ React.createElement("tr", { ...props2 }));
163
+ const TableComponent2 = components["table"] || ((props2) => /* @__PURE__ */ React.createElement("table", { ...props2 }));
164
+ const TrComponent2 = components["tr"] || ((props2) => /* @__PURE__ */ React.createElement("tr", { ...props2 }));
157
165
  const ThComponent = components["th"] || ((props2) => /* @__PURE__ */ React.createElement("th", { style: { textAlign: (props2 == null ? void 0 : props2.align) || "auto" }, ...props2 }));
158
- const TdComponent = components["td"] || ((props2) => /* @__PURE__ */ React.createElement("td", { style: { textAlign: (props2 == null ? void 0 : props2.align) || "auto" }, ...props2 }));
159
- const align = ((_f = child.props) == null ? void 0 : _f.align) || [];
160
- return /* @__PURE__ */ React.createElement(TableComponent, null, firstRowHeader && /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement(TrComponent, null, header.tableCells.map((c, i) => {
166
+ const TdComponent2 = components["td"] || ((props2) => /* @__PURE__ */ React.createElement("td", { style: { textAlign: (props2 == null ? void 0 : props2.align) || "auto" }, ...props2 }));
167
+ const align2 = ((_f = child.props) == null ? void 0 : _f.align) || [];
168
+ return /* @__PURE__ */ React.createElement(TableComponent2, null, firstRowHeader && /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement(TrComponent2, null, header.tableCells.map((c, i) => {
161
169
  return /* @__PURE__ */ React.createElement(
162
170
  TinaMarkdown,
163
171
  {
164
172
  key: i,
165
173
  components: {
166
- p: (props2) => /* @__PURE__ */ React.createElement(ThComponent, { align: align[i], ...props2 })
174
+ p: (props2) => /* @__PURE__ */ React.createElement(ThComponent, { align: align2[i], ...props2 })
167
175
  },
168
176
  content: c.value
169
177
  }
170
178
  );
171
- }))), /* @__PURE__ */ React.createElement("tbody", null, rows.map((row, i) => {
179
+ }))), /* @__PURE__ */ React.createElement("tbody", null, rows2.map((row, i) => {
172
180
  var _a2;
173
- return /* @__PURE__ */ React.createElement(TrComponent, { key: i }, (_a2 = row == null ? void 0 : row.tableCells) == null ? void 0 : _a2.map((c, i2) => {
181
+ return /* @__PURE__ */ React.createElement(TrComponent2, { key: i }, (_a2 = row == null ? void 0 : row.tableCells) == null ? void 0 : _a2.map((c, i2) => {
174
182
  return /* @__PURE__ */ React.createElement(
175
183
  TinaMarkdown,
176
184
  {
177
185
  key: i2,
178
186
  components: {
179
- p: (props2) => /* @__PURE__ */ React.createElement(TdComponent, { align: align[i2], ...props2 })
187
+ p: (props2) => /* @__PURE__ */ React.createElement(TdComponent2, { align: align2[i2], ...props2 })
180
188
  },
181
189
  content: c.value
182
190
  }
@@ -191,6 +199,37 @@
191
199
  return /* @__PURE__ */ React.createElement("span", null, `No component provided for ${child.name}`);
192
200
  }
193
201
  }
202
+ case "table":
203
+ const rows = child.children || [];
204
+ const TableComponent = components["table"] || ((props2) => /* @__PURE__ */ React.createElement("table", { style: { border: "1px solid #EDECF3" }, ...props2 }));
205
+ const TrComponent = components["tr"] || ((props2) => /* @__PURE__ */ React.createElement("tr", { ...props2 }));
206
+ const TdComponent = components["td"] || ((props2) => /* @__PURE__ */ React.createElement(
207
+ "td",
208
+ {
209
+ style: {
210
+ textAlign: (props2 == null ? void 0 : props2.align) || "auto",
211
+ border: "1px solid #EDECF3",
212
+ padding: "0.25rem"
213
+ },
214
+ ...props2
215
+ }
216
+ ));
217
+ const align = ((_g = child.props) == null ? void 0 : _g.align) || [];
218
+ return /* @__PURE__ */ React.createElement(TableComponent, null, /* @__PURE__ */ React.createElement("tbody", null, rows.map((row, i) => {
219
+ var _a2;
220
+ return /* @__PURE__ */ React.createElement(TrComponent, { key: i }, (_a2 = row.children) == null ? void 0 : _a2.map((cell, i2) => {
221
+ return /* @__PURE__ */ React.createElement(
222
+ TinaMarkdown,
223
+ {
224
+ key: i2,
225
+ components: {
226
+ p: (props2) => /* @__PURE__ */ React.createElement(TdComponent, { align: align[i2], ...props2 })
227
+ },
228
+ content: cell.children
229
+ }
230
+ );
231
+ }));
232
+ })));
194
233
  case "maybe_mdx":
195
234
  return null;
196
235
  case "html":