tinacms 0.0.0-e024aec-20250526035050 → 0.0.0-e1b6d05-20251114052813

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 (150) hide show
  1. package/dist/admin/api.d.ts +3 -0
  2. package/dist/admin/components/Page.d.ts +3 -9
  3. package/dist/admin/components/Sidebar.d.ts +0 -3
  4. package/dist/admin/pages/CollectionCreatePage.d.ts +1 -1
  5. package/dist/admin/pages/DashboardPage.d.ts +0 -3
  6. package/dist/admin/pages/ScreenPage.d.ts +0 -3
  7. package/dist/auth/AuthModal.d.ts +1 -4
  8. package/dist/auth/TinaCloudProvider.d.ts +0 -1
  9. package/dist/client.js +2 -2
  10. package/dist/client.mjs +2 -2
  11. package/dist/index.js +102643 -14901
  12. package/dist/index.mjs +102909 -15167
  13. package/dist/internalClient/index.d.ts +25 -0
  14. package/dist/react.d.ts +13 -6
  15. package/dist/react.js +60 -52
  16. package/dist/react.mjs +60 -52
  17. package/dist/rich-text/index.d.ts +6 -0
  18. package/dist/rich-text/index.js +18 -5
  19. package/dist/rich-text/index.mjs +18 -5
  20. package/dist/rich-text/static.d.ts +154 -0
  21. package/dist/rich-text/static.js +246 -0
  22. package/dist/rich-text/static.mjs +243 -0
  23. package/dist/tina-cms.d.ts +1 -1
  24. package/dist/toolkit/components/ProgressBar.d.ts +11 -0
  25. package/dist/toolkit/components/media/media-item.d.ts +11 -1
  26. package/dist/toolkit/components/ui/breadcrumb.d.ts +11 -0
  27. package/dist/toolkit/components/ui/dropdown-menu.d.ts +25 -0
  28. package/dist/toolkit/fields/components/password-field.d.ts +1 -1
  29. package/dist/toolkit/fields/components/reference/components/button.d.ts +2 -2
  30. package/dist/toolkit/fields/components/reference/components/command.d.ts +21 -33
  31. package/dist/toolkit/fields/components/reference/components/popover.d.ts +1 -1
  32. package/dist/toolkit/fields/components/reference/model/reference-link-props.d.ts +2 -0
  33. package/dist/toolkit/fields/components/select.d.ts +2 -2
  34. package/dist/toolkit/fields/components/text-field.d.ts +1 -1
  35. package/dist/toolkit/fields/plugins/group-field-plugin.d.ts +1 -1
  36. package/dist/toolkit/fields/plugins/group-list-field-plugin.d.ts +1 -0
  37. package/dist/toolkit/fields/plugins/list-field-meta.d.ts +1 -1
  38. package/dist/toolkit/fields/plugins/list-field-plugin.d.ts +1 -0
  39. package/dist/toolkit/fields/plugins/mdx-field-plugin/index.d.ts +2 -2
  40. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +20 -18
  41. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +14 -10
  42. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +5 -5
  43. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +17 -0
  44. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/error-message.d.ts +6 -0
  45. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-combobox.d.ts +6 -0
  46. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-toolbar-button.d.ts +6 -6
  47. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-leaf.d.ts +2 -11
  48. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +14 -10
  49. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-syntax-leaf.d.ts +2 -11
  50. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +112 -0
  51. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dialog.d.ts +12 -0
  52. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/dropdown-menu.d.ts +10 -10
  53. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/floating-toolbar.d.ts +2 -2
  54. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-element.d.ts +3 -0
  55. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/hr-toolbar-button.d.ts +18 -0
  56. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/icons.d.ts +2 -1
  57. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/image-toolbar-button.d.ts +6 -6
  58. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +6 -19
  59. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/inline-combobox.d.ts +1 -1
  60. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/input.d.ts +3 -3
  61. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-element.d.ts +4 -11
  62. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-floating-toolbar.d.ts +4 -5
  63. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/link-toolbar-button.d.ts +4 -4
  64. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +28 -11
  65. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-element.d.ts +3 -10
  66. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mermaid-toolbar-button.d.ts +6 -8
  67. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +15 -0
  68. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/popover.d.ts +7 -2
  69. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/quote-toolbar-button.d.ts +6 -6
  70. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/raw-markdown-toolbar-button.d.ts +6 -6
  71. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/resizable.d.ts +24 -21
  72. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/separator.d.ts +2 -2
  73. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +15 -11
  74. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/block-selection.d.ts +6 -0
  75. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +33 -0
  76. 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
  77. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +20 -0
  78. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +15 -0
  79. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/toolbar.d.ts +7 -7
  80. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +10 -0
  81. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-state.d.ts +22 -0
  82. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/hooks/use-create-editor.d.ts +6 -0
  83. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-block.d.ts +1 -1
  84. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-lists.d.ts +1 -1
  85. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-marks.d.ts +1 -1
  86. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/autoformat/autoformat-utils.d.ts +3 -5
  87. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/common.d.ts +11 -6
  88. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/formatting.d.ts +18 -2
  89. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/index.d.ts +0 -1
  90. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-html-block/index.d.ts +6 -0
  91. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-img-plugin/index.d.ts +2 -2
  92. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-invalid-markdown-plugin/index.d.ts +5 -5
  93. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/component.d.ts +7 -4
  94. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-mdx-plugins/index.d.ts +3 -5
  95. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/editor-plugins.d.ts +520 -0
  96. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +262 -207
  97. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/floating-toolbar-plugin.d.ts +1 -0
  98. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-overrides.d.ts +1 -1
  99. package/dist/toolkit/form-builder/create-branch-modal.d.ts +13 -0
  100. package/dist/toolkit/form-builder/editorial-workflow-constants.d.ts +17 -0
  101. package/dist/toolkit/form-builder/fields-builder.d.ts +1 -1
  102. package/dist/toolkit/form-builder/form-builder.d.ts +4 -16
  103. package/dist/toolkit/form-builder/index.d.ts +1 -0
  104. package/dist/toolkit/forms/field.d.ts +3 -0
  105. package/dist/toolkit/forms/form.d.ts +22 -3
  106. package/dist/toolkit/git-client/git-client.d.ts +25 -2
  107. package/dist/toolkit/git-client/git-file.d.ts +18 -0
  108. package/dist/toolkit/git-client/git-media-store.d.ts +13 -0
  109. package/dist/toolkit/git-client/use-git-file.d.ts +4 -0
  110. package/dist/toolkit/icons/Tina.d.ts +0 -5
  111. package/dist/toolkit/icons/TinaExtended.d.ts +4 -0
  112. package/dist/toolkit/icons/index.d.ts +1 -0
  113. package/dist/toolkit/index.d.ts +1 -1
  114. package/dist/toolkit/plugin-branch-switcher/branch-button.d.ts +4 -1
  115. package/dist/toolkit/plugin-branch-switcher/index.d.ts +0 -1
  116. package/dist/toolkit/react-modals/modal/modal-actions.d.ts +2 -1
  117. package/dist/toolkit/react-modals/modal/modal-header.d.ts +1 -1
  118. package/dist/toolkit/react-sidebar/components/VersionInfo.d.ts +2 -0
  119. package/dist/toolkit/react-sidebar/components/badge.d.ts +5 -0
  120. package/dist/toolkit/react-sidebar/components/callout.d.ts +5 -0
  121. package/dist/toolkit/react-sidebar/components/form-list.d.ts +1 -1
  122. package/dist/toolkit/react-sidebar/components/local-warning.d.ts +3 -1
  123. package/dist/toolkit/react-sidebar/components/nav.d.ts +6 -3
  124. package/dist/toolkit/react-sidebar/components/resize-handle.d.ts +0 -5
  125. package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +3 -7
  126. package/dist/toolkit/react-sidebar/components/sidebar.d.ts +0 -7
  127. package/dist/toolkit/react-sidebar/components/sync-status.d.ts +5 -8
  128. package/dist/toolkit/react-sidebar/index.d.ts +1 -1
  129. package/dist/toolkit/styles/button.d.ts +2 -2
  130. package/dist/toolkit/styles/dropdown-button.d.ts +75 -0
  131. package/dist/toolkit/styles/index.d.ts +1 -0
  132. package/dist/toolkit/tina-state.d.ts +11 -0
  133. package/dist/utils/cn.d.ts +2 -0
  134. package/package.json +38 -25
  135. package/dist/admin/pages/IndexingPage.d.ts +0 -2
  136. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block-element.d.ts +0 -11
  137. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-cell-element.d.ts +0 -27
  138. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-element.d.ts +0 -14
  139. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table-row-element.d.ts +0 -13
  140. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/core/with-correct-void-behavior.d.ts +0 -8
  141. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-code-block/index.d.ts +0 -3
  142. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/create-link-plugin/index.d.ts +0 -15
  143. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/custom/mermaid-plugin.d.ts +0 -2
  144. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/create-soft-break-plugin.d.ts +0 -7
  145. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/index.d.ts +0 -6
  146. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/on-key-down-soft-break.d.ts +0 -5
  147. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/soft-break/types.d.ts +0 -11
  148. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/code-block/index.d.ts +0 -11
  149. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/transforms/insert-empty-block.d.ts +0 -2
  150. package/dist/toolkit/plugin-branch-switcher/branch-banner.d.ts +0 -2
@@ -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>;
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
@@ -11,17 +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);
26
+ setData(processedData);
21
27
  parent.postMessage({
22
28
  type: "url-changed"
23
29
  });
24
- }, [id]);
30
+ }, [id, processedData]);
25
31
  React.useEffect(() => {
26
32
  if (quickEditEnabled) {
27
33
  let mouseDownHandler = function(e) {
@@ -113,12 +119,18 @@
113
119
  React.useEffect(() => {
114
120
  const { experimental___selectFormByFormId, ...rest } = props;
115
121
  parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
116
- window.addEventListener("message", (event) => {
122
+ const handleMessage = (event) => {
117
123
  if (event.data.type === "quickEditEnabled") {
118
124
  setQuickEditEnabled(event.data.value);
119
125
  }
120
126
  if (event.data.id === id && event.data.type === "updateData") {
121
- 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);
122
134
  setIsInTinaIframe(true);
123
135
  const anyTinaField = document.querySelector("[data-tina-field]");
124
136
  if (anyTinaField) {
@@ -133,8 +145,10 @@
133
145
  );
134
146
  }
135
147
  }
136
- });
148
+ };
149
+ window.addEventListener("message", handleMessage);
137
150
  return () => {
151
+ window.removeEventListener("message", handleMessage);
138
152
  parent.postMessage({ type: "close", id }, window.location.origin);
139
153
  };
140
154
  }, [id, setQuickEditEnabled]);
@@ -156,59 +170,53 @@
156
170
  return { edit };
157
171
  }
158
172
  const tinaField = (object, property, index) => {
159
- var _a, _b, _c;
160
- if (!object) {
173
+ const contentSource = object == null ? void 0 : object._content_source;
174
+ if (!contentSource) {
161
175
  return "";
162
176
  }
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("---");
177
+ const { queryId, path } = contentSource;
178
+ if (!property) {
179
+ return `${queryId}---${path.join(".")}`;
180
180
  }
181
- return "";
181
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
182
+ return `${queryId}---${fullPath.join(".")}`;
182
183
  };
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
- });
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;
196
212
  } else {
197
- if (isScalarOrUndefined(value)) {
198
- return;
199
- }
200
- const itemObject = value;
201
- addMetadata(id, itemObject, [...path, key]);
213
+ transformedObj[key] = addMetadata(id, value, currentPath);
202
214
  }
203
- });
204
- if ((object == null ? void 0 : object.type) === "root") {
205
- return;
206
215
  }
207
- object._content_source = {
208
- queryId: id,
209
- path
210
- };
211
- 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 } };
212
220
  };
213
221
  function isScalarOrUndefined(value) {
214
222
  const type = typeof value;
package/dist/react.mjs CHANGED
@@ -8,17 +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);
23
+ setData(processedData);
18
24
  parent.postMessage({
19
25
  type: "url-changed"
20
26
  });
21
- }, [id]);
27
+ }, [id, processedData]);
22
28
  React.useEffect(() => {
23
29
  if (quickEditEnabled) {
24
30
  let mouseDownHandler = function(e) {
@@ -110,12 +116,18 @@ function useTina(props) {
110
116
  React.useEffect(() => {
111
117
  const { experimental___selectFormByFormId, ...rest } = props;
112
118
  parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
113
- window.addEventListener("message", (event) => {
119
+ const handleMessage = (event) => {
114
120
  if (event.data.type === "quickEditEnabled") {
115
121
  setQuickEditEnabled(event.data.value);
116
122
  }
117
123
  if (event.data.id === id && event.data.type === "updateData") {
118
- 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);
119
131
  setIsInTinaIframe(true);
120
132
  const anyTinaField = document.querySelector("[data-tina-field]");
121
133
  if (anyTinaField) {
@@ -130,8 +142,10 @@ function useTina(props) {
130
142
  );
131
143
  }
132
144
  }
133
- });
145
+ };
146
+ window.addEventListener("message", handleMessage);
134
147
  return () => {
148
+ window.removeEventListener("message", handleMessage);
135
149
  parent.postMessage({ type: "close", id }, window.location.origin);
136
150
  };
137
151
  }, [id, setQuickEditEnabled]);
@@ -153,59 +167,53 @@ function useEditState() {
153
167
  return { edit };
154
168
  }
155
169
  const tinaField = (object, property, index) => {
156
- var _a, _b, _c;
157
- if (!object) {
170
+ const contentSource = object == null ? void 0 : object._content_source;
171
+ if (!contentSource) {
158
172
  return "";
159
173
  }
160
- if (object._content_source) {
161
- if (!property) {
162
- return [
163
- (_a = object._content_source) == null ? void 0 : _a.queryId,
164
- object._content_source.path.join(".")
165
- ].join("---");
166
- }
167
- if (typeof index === "number") {
168
- return [
169
- (_b = object._content_source) == null ? void 0 : _b.queryId,
170
- [...object._content_source.path, property, index].join(".")
171
- ].join("---");
172
- }
173
- return [
174
- (_c = object._content_source) == null ? void 0 : _c.queryId,
175
- [...object._content_source.path, property].join(".")
176
- ].join("---");
174
+ const { queryId, path } = contentSource;
175
+ if (!property) {
176
+ return `${queryId}---${path.join(".")}`;
177
177
  }
178
- return "";
178
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
179
+ return `${queryId}---${fullPath.join(".")}`;
179
180
  };
180
- const addMetadata = (id, object, path) => {
181
- Object.entries(object).forEach(([key, value]) => {
182
- if (Array.isArray(value)) {
183
- value.forEach((item, index) => {
184
- if (isScalarOrUndefined(item)) {
185
- return;
186
- }
187
- if (Array.isArray(item)) {
188
- return;
189
- }
190
- const itemObject = item;
191
- addMetadata(id, itemObject, [...path, key, index]);
192
- });
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;
193
209
  } else {
194
- if (isScalarOrUndefined(value)) {
195
- return;
196
- }
197
- const itemObject = value;
198
- addMetadata(id, itemObject, [...path, key]);
210
+ transformedObj[key] = addMetadata(id, value, currentPath);
199
211
  }
200
- });
201
- if ((object == null ? void 0 : object.type) === "root") {
202
- return;
203
212
  }
204
- object._content_source = {
205
- queryId: id,
206
- path
207
- };
208
- 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 } };
209
217
  };
210
218
  function isScalarOrUndefined(value) {
211
219
  const type = typeof value;
@@ -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;
@@ -82,7 +82,6 @@
82
82
  case "h5":
83
83
  case "h6":
84
84
  case "p":
85
- case "blockquote":
86
85
  case "ol":
87
86
  case "ul":
88
87
  case "li":
@@ -99,6 +98,14 @@
99
98
  return /* @__PURE__ */ React.createElement(Component2, { ...props }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }));
100
99
  }
101
100
  return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: child.children }));
101
+ case "blockquote":
102
+ const BlockquoteComponent = components.blockquote || components.block_quote;
103
+ if (BlockquoteComponent) {
104
+ return /* @__PURE__ */ React.createElement(BlockquoteComponent, { ...props }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }));
105
+ }
106
+ return React.createElement("blockquote", {
107
+ children: /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children })
108
+ });
102
109
  case "img":
103
110
  if (components[child.type]) {
104
111
  const Component2 = components[child.type];
@@ -117,17 +124,23 @@
117
124
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
118
125
  /* @__PURE__ */ React.createElement("a", { href: child.url }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }))
119
126
  );
120
- case "mermaid":
121
127
  case "code_block": {
122
- const value = child.value;
128
+ let codeString = "";
129
+ if (Array.isArray(child.children)) {
130
+ codeString = child.children.map(
131
+ (line) => Array.isArray(line.children) ? line.children.map((t) => t.text).join("") : ""
132
+ ).join("\n");
133
+ } else if (typeof child.value === "string") {
134
+ codeString = child.value;
135
+ }
123
136
  if (components[child.type]) {
124
137
  const Component2 = components[child.type];
125
138
  return (
126
139
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
127
- /* @__PURE__ */ React.createElement(Component2, { ...props })
140
+ /* @__PURE__ */ React.createElement(Component2, { ...props, value: codeString })
128
141
  );
129
142
  }
130
- return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, value));
143
+ return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, codeString));
131
144
  }
132
145
  case "hr":
133
146
  if (components[child.type]) {
@@ -79,7 +79,6 @@ const Node = ({ components, child }) => {
79
79
  case "h5":
80
80
  case "h6":
81
81
  case "p":
82
- case "blockquote":
83
82
  case "ol":
84
83
  case "ul":
85
84
  case "li":
@@ -96,6 +95,14 @@ const Node = ({ components, child }) => {
96
95
  return /* @__PURE__ */ React.createElement(Component2, { ...props }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }));
97
96
  }
98
97
  return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: child.children }));
98
+ case "blockquote":
99
+ const BlockquoteComponent = components.blockquote || components.block_quote;
100
+ if (BlockquoteComponent) {
101
+ return /* @__PURE__ */ React.createElement(BlockquoteComponent, { ...props }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }));
102
+ }
103
+ return React.createElement("blockquote", {
104
+ children: /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children })
105
+ });
99
106
  case "img":
100
107
  if (components[child.type]) {
101
108
  const Component2 = components[child.type];
@@ -114,17 +121,23 @@ const Node = ({ components, child }) => {
114
121
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
115
122
  /* @__PURE__ */ React.createElement("a", { href: child.url }, /* @__PURE__ */ React.createElement(TinaMarkdown, { components, content: children }))
116
123
  );
117
- case "mermaid":
118
124
  case "code_block": {
119
- const value = child.value;
125
+ let codeString = "";
126
+ if (Array.isArray(child.children)) {
127
+ codeString = child.children.map(
128
+ (line) => Array.isArray(line.children) ? line.children.map((t) => t.text).join("") : ""
129
+ ).join("\n");
130
+ } else if (typeof child.value === "string") {
131
+ codeString = child.value;
132
+ }
120
133
  if (components[child.type]) {
121
134
  const Component2 = components[child.type];
122
135
  return (
123
136
  // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types
124
- /* @__PURE__ */ React.createElement(Component2, { ...props })
137
+ /* @__PURE__ */ React.createElement(Component2, { ...props, value: codeString })
125
138
  );
126
139
  }
127
- return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, value));
140
+ return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, codeString));
128
141
  }
129
142
  case "hr":
130
143
  if (components[child.type]) {
@@ -0,0 +1,154 @@
1
+ /**
2
+ * This is a static-ready version of the TinaMarkdown component.
3
+ * The primary change is the removal of the `MemoNode` wrapper, which used
4
+ * the `React.useMemo` hook. This hook is for client-side performance
5
+ * optimization and is not needed for server-side rendering (SSR).
6
+ * By rendering the `Node` component directly, the component becomes
7
+ * fully static and can be rendered on the server.
8
+ */
9
+ import React from 'react';
10
+ type BaseComponents = {
11
+ h1?: {
12
+ children: JSX.Element;
13
+ };
14
+ h2?: {
15
+ children: JSX.Element;
16
+ };
17
+ h3?: {
18
+ children: JSX.Element;
19
+ };
20
+ h4?: {
21
+ children: JSX.Element;
22
+ };
23
+ h5?: {
24
+ children: JSX.Element;
25
+ };
26
+ h6?: {
27
+ children: JSX.Element;
28
+ };
29
+ p?: {
30
+ children: JSX.Element;
31
+ };
32
+ a?: {
33
+ url: string;
34
+ children: JSX.Element;
35
+ };
36
+ italic?: {
37
+ children: JSX.Element;
38
+ };
39
+ bold?: {
40
+ children: JSX.Element;
41
+ };
42
+ strikethrough?: {
43
+ children: JSX.Element;
44
+ };
45
+ underline?: {
46
+ children: JSX.Element;
47
+ };
48
+ code?: {
49
+ children: JSX.Element;
50
+ };
51
+ text?: {
52
+ children: string;
53
+ };
54
+ ul?: {
55
+ children: JSX.Element;
56
+ };
57
+ ol?: {
58
+ children: JSX.Element;
59
+ };
60
+ li?: {
61
+ children: JSX.Element;
62
+ };
63
+ lic?: {
64
+ children: JSX.Element;
65
+ };
66
+ /**
67
+ * @deprecated Use `blockquote` instead. This was incorrectly named and will be removed in a future version.
68
+ */
69
+ block_quote?: {
70
+ children: JSX.Element;
71
+ };
72
+ blockquote?: {
73
+ children: JSX.Element;
74
+ };
75
+ code_block?: {
76
+ lang?: string;
77
+ value: string;
78
+ };
79
+ mermaid?: {
80
+ value: string;
81
+ };
82
+ img?: {
83
+ url: string;
84
+ caption?: string;
85
+ alt?: string;
86
+ };
87
+ hr?: {};
88
+ break?: {};
89
+ maybe_mdx?: {
90
+ children: JSX.Element;
91
+ };
92
+ html?: {
93
+ value: string;
94
+ };
95
+ html_inline?: {
96
+ value: string;
97
+ };
98
+ table?: {
99
+ align?: ('left' | 'right' | 'center')[];
100
+ tableRows: {
101
+ tableCells: {
102
+ value: TinaMarkdownContent;
103
+ }[];
104
+ }[];
105
+ };
106
+ component_missing?: {
107
+ name: string;
108
+ };
109
+ };
110
+ type BaseComponentSignature = {
111
+ [BK in keyof BaseComponents]: (props: BaseComponents[BK]) => JSX.Element;
112
+ };
113
+ /**
114
+ * Define the allowed components and their props
115
+ * ```ts
116
+ * const components:
117
+ * Components<{
118
+ * BlockQuote: {
119
+ * children: TinaMarkdownContent;
120
+ * authorName: string;
121
+ * };
122
+ * }> = {
123
+ * BlockQuote: (props: {
124
+ * children: TinaMarkdownContent;
125
+ * authorName: string;
126
+ * }) => {
127
+ * return (
128
+ * <div>
129
+ * <blockquote>
130
+ * <TinaMarkdown content={props.children} />
131
+ * {props.authorName}
132
+ * </blockquote>
133
+ * </div>
134
+ * );
135
+ * }
136
+ * }
137
+ * }
138
+ * ```
139
+ */
140
+ export type Components<ComponentAndProps extends object> = {
141
+ [K in keyof ComponentAndProps]: (props: ComponentAndProps[K]) => JSX.Element;
142
+ } & BaseComponentSignature;
143
+ export type TinaMarkdownContent = {
144
+ type: string;
145
+ children: TinaMarkdownContent[];
146
+ [key: string]: any;
147
+ };
148
+ export declare const StaticTinaMarkdown: <CustomComponents extends {
149
+ [key: string]: object;
150
+ } = any>({ content, components, }: {
151
+ content: TinaMarkdownContent | TinaMarkdownContent[];
152
+ components?: Components<{}> | Components<{ [BK in keyof CustomComponents]: (props: CustomComponents[BK]) => JSX.Element; }>;
153
+ }) => React.JSX.Element;
154
+ export {};