tinacms 0.0.0-a1ff961-20250623024558 → 0.0.0-a23fec8-20251217045135
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.
- package/dist/admin/api.d.ts +4 -1
- package/dist/auth/AuthModal.d.ts +1 -4
- package/dist/auth/TinaCloudProvider.d.ts +0 -1
- package/dist/cache/node-cache.d.ts +6 -2
- package/dist/client.js +240 -181
- package/dist/index.js +120164 -118241
- package/dist/internalClient/index.d.ts +55 -2
- package/dist/react.js +209 -210
- package/dist/rich-text/index.d.ts +6 -0
- package/dist/rich-text/index.js +234 -230
- package/dist/rich-text/prism.js +16 -18
- package/dist/rich-text/static.d.ts +154 -0
- package/dist/rich-text/{index.mjs → static.js} +90 -96
- package/dist/tina-cms.d.ts +1 -1
- package/dist/toolkit/components/ProgressBar.d.ts +11 -0
- package/dist/toolkit/components/media/media-item.d.ts +10 -0
- package/dist/toolkit/components/ui/button.d.ts +11 -0
- package/dist/toolkit/components/ui/calendar.d.ts +8 -0
- package/dist/toolkit/components/ui/date-time-picker.d.ts +111 -0
- package/dist/toolkit/components/ui/input.d.ts +3 -0
- package/dist/toolkit/components/ui/popover.d.ts +7 -0
- package/dist/toolkit/components/ui/select.d.ts +13 -0
- package/dist/toolkit/fields/components/color-picker/block-widget.d.ts +3 -0
- package/dist/toolkit/fields/components/color-picker/color-input.d.ts +35 -0
- package/dist/toolkit/fields/components/color-picker/color-picker.d.ts +6 -2
- package/dist/toolkit/fields/components/color-picker/color-utils.d.ts +37 -0
- package/dist/toolkit/fields/components/color-picker/sketch-widget.d.ts +3 -0
- package/dist/toolkit/fields/components/select.d.ts +1 -1
- package/dist/toolkit/fields/plugins/button-toggle-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/checkbox-group-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/color-field-plugin.d.ts +1 -0
- package/dist/toolkit/fields/plugins/date-field-plugin.d.ts +0 -2
- package/dist/toolkit/fields/plugins/dnd-kit-wrapper.d.ts +49 -0
- package/dist/toolkit/fields/plugins/group-list-field-plugin.d.ts +3 -1
- package/dist/toolkit/fields/plugins/list-field-plugin.d.ts +3 -0
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/editor.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/blockquote-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/button.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-block/code-block-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/code-line-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/command.d.ts +7 -7
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/list-element.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/paragraph-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/slash-input-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-cell-element.d.ts +2 -2
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/table/table-row-element.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/use-floating-toolbar-hook.d.ts +1 -1
- package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +20 -19
- package/dist/toolkit/fields/plugins/radio-group-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/select-field-plugin.d.ts +2 -2
- package/dist/toolkit/fields/plugins/toggle-field-plugin.d.ts +2 -2
- package/dist/toolkit/form-builder/create-branch-modal.d.ts +13 -0
- package/dist/toolkit/form-builder/editorial-workflow-constants.d.ts +17 -0
- package/dist/toolkit/form-builder/form-builder.d.ts +0 -11
- package/dist/toolkit/form-builder/index.d.ts +1 -0
- package/dist/toolkit/icons/TinaExtended.d.ts +4 -0
- package/dist/toolkit/icons/index.d.ts +1 -0
- package/dist/toolkit/index.d.ts +1 -1
- package/dist/toolkit/plugin-branch-switcher/branch-button.d.ts +3 -1
- package/dist/toolkit/react-modals/modal/modal-actions.d.ts +2 -1
- package/dist/toolkit/react-modals/modal/modal-header.d.ts +1 -1
- package/dist/toolkit/react-sidebar/components/NavMenuTrigger.d.ts +11 -0
- package/dist/toolkit/react-sidebar/components/VersionInfo.d.ts +2 -0
- package/dist/toolkit/react-sidebar/components/badge.d.ts +6 -0
- package/dist/toolkit/react-sidebar/components/callout.d.ts +5 -0
- package/dist/toolkit/react-sidebar/components/local-warning.d.ts +3 -1
- package/dist/toolkit/react-sidebar/components/nav-components.d.ts +11 -0
- package/dist/toolkit/react-sidebar/components/nav-context.d.ts +15 -0
- package/dist/toolkit/react-sidebar/components/nav.d.ts +3 -2
- package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +26 -1
- package/dist/toolkit/react-sidebar/index.d.ts +3 -0
- package/dist/toolkit/styles/button.d.ts +1 -1
- package/dist/toolkit/styles/dropdown-button.d.ts +75 -0
- package/dist/toolkit/styles/index.d.ts +1 -0
- package/dist/unifiedClient/index.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +34 -65
- package/dist/admin/pages/IndexingPage.d.ts +0 -2
- package/dist/client.mjs +0 -132
- package/dist/index.mjs +0 -121720
- package/dist/node-cache-5e8db9f0.mjs +0 -63
- package/dist/react.mjs +0 -252
- package/dist/rich-text/prism.mjs +0 -16
- package/dist/toolkit/react-datetime/DateTime.d.ts +0 -135
- package/dist/toolkit/react-sidebar/components/alert.d.ts +0 -5
- /package/dist/admin/components/{Sidebar.d.ts → AdminNav.d.ts} +0 -0
|
@@ -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/
|
|
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
|
-
|
|
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.js
CHANGED
|
@@ -1,71 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
const processedData = React.useMemo(() => {
|
|
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) {
|
|
15
13
|
const dataCopy = JSON.parse(JSON.stringify(props.data));
|
|
16
14
|
return addMetadata(id, dataCopy, []);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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"
|
|
26
|
+
});
|
|
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]"
|
|
35
43
|
);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
fieldName = e.target.getAttribute(tinaAttribute);
|
|
41
|
-
} else {
|
|
42
|
-
const ancestor = e.target.closest(
|
|
43
|
-
"[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")
|
|
44
48
|
);
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
if (tinaAttribute2) {
|
|
51
|
-
e.preventDefault();
|
|
52
|
-
e.stopPropagation();
|
|
53
|
-
fieldName = ancestor.getAttribute(tinaAttribute2);
|
|
54
|
-
}
|
|
49
|
+
if (tinaAttribute2) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
fieldName = ancestor.getAttribute(tinaAttribute2);
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
}
|
|
56
|
+
if (fieldName) {
|
|
57
|
+
if (isInTinaIframe) {
|
|
58
|
+
parent.postMessage(
|
|
59
|
+
{ type: "field:selected", fieldName },
|
|
60
|
+
window.location.origin
|
|
61
|
+
);
|
|
64
62
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const style = document.createElement("style");
|
|
66
|
+
style.type = "text/css";
|
|
67
|
+
style.textContent = `
|
|
69
68
|
[data-tina-field] {
|
|
70
69
|
outline: 2px dashed rgba(34,150,254,0.5);
|
|
71
70
|
transition: box-shadow ease-out 150ms;
|
|
@@ -96,160 +95,160 @@
|
|
|
96
95
|
opacity: 1;
|
|
97
96
|
}
|
|
98
97
|
`;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return () => {
|
|
103
|
-
document.removeEventListener("click", mouseDownHandler, true);
|
|
104
|
-
document.body.classList.remove("__tina-quick-editing-enabled");
|
|
105
|
-
style.remove();
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}, [quickEditEnabled, isInTinaIframe]);
|
|
109
|
-
React.useEffect(() => {
|
|
110
|
-
if (props == null ? void 0 : props.experimental___selectFormByFormId) {
|
|
111
|
-
parent.postMessage({
|
|
112
|
-
type: "user-select-form",
|
|
113
|
-
formId: props.experimental___selectFormByFormId()
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}, [id]);
|
|
117
|
-
React.useEffect(() => {
|
|
118
|
-
const { experimental___selectFormByFormId, ...rest } = props;
|
|
119
|
-
parent.postMessage({ type: "open", ...rest, id }, window.location.origin);
|
|
120
|
-
const handleMessage = (event) => {
|
|
121
|
-
if (event.data.type === "quickEditEnabled") {
|
|
122
|
-
setQuickEditEnabled(event.data.value);
|
|
123
|
-
}
|
|
124
|
-
if (event.data.id === id && event.data.type === "updateData") {
|
|
125
|
-
const rawData = event.data.data;
|
|
126
|
-
const newlyProcessedData = addMetadata(
|
|
127
|
-
id,
|
|
128
|
-
JSON.parse(JSON.stringify(rawData)),
|
|
129
|
-
[]
|
|
130
|
-
);
|
|
131
|
-
setData(newlyProcessedData);
|
|
132
|
-
setIsInTinaIframe(true);
|
|
133
|
-
const anyTinaField = document.querySelector("[data-tina-field]");
|
|
134
|
-
if (anyTinaField) {
|
|
135
|
-
parent.postMessage(
|
|
136
|
-
{ type: "quick-edit", value: true },
|
|
137
|
-
window.location.origin
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
parent.postMessage(
|
|
141
|
-
{ type: "quick-edit", value: false },
|
|
142
|
-
window.location.origin
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
window.addEventListener("message", handleMessage);
|
|
98
|
+
document.head.appendChild(style);
|
|
99
|
+
document.body.classList.add("__tina-quick-editing-enabled");
|
|
100
|
+
document.addEventListener("click", mouseDownHandler, true);
|
|
148
101
|
return () => {
|
|
149
|
-
|
|
150
|
-
|
|
102
|
+
document.removeEventListener("click", mouseDownHandler, true);
|
|
103
|
+
document.body.classList.remove("__tina-quick-editing-enabled");
|
|
104
|
+
style.remove();
|
|
151
105
|
};
|
|
152
|
-
}, [id, setQuickEditEnabled]);
|
|
153
|
-
return { data, isClient };
|
|
154
|
-
}
|
|
155
|
-
function useEditState() {
|
|
156
|
-
const [edit, setEdit] = React.useState(false);
|
|
157
|
-
React.useEffect(() => {
|
|
158
|
-
if (typeof window !== "undefined") {
|
|
159
|
-
parent.postMessage({ type: "isEditMode" }, window.location.origin);
|
|
160
|
-
window.addEventListener("message", (event) => {
|
|
161
|
-
var _a;
|
|
162
|
-
if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
|
|
163
|
-
setEdit(true);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}, []);
|
|
168
|
-
return { edit };
|
|
169
|
-
}
|
|
170
|
-
const tinaField = (object, property, index) => {
|
|
171
|
-
const contentSource = object == null ? void 0 : object._content_source;
|
|
172
|
-
if (!contentSource) {
|
|
173
|
-
return "";
|
|
174
|
-
}
|
|
175
|
-
const { queryId, path } = contentSource;
|
|
176
|
-
if (!property) {
|
|
177
|
-
return `${queryId}---${path.join(".")}`;
|
|
178
|
-
}
|
|
179
|
-
const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
|
|
180
|
-
return `${queryId}---${fullPath.join(".")}`;
|
|
181
|
-
};
|
|
182
|
-
const addMetadata = (id, obj, path = []) => {
|
|
183
|
-
if (obj === null) {
|
|
184
|
-
return obj;
|
|
185
|
-
}
|
|
186
|
-
if (isScalarOrUndefined(obj)) {
|
|
187
|
-
return obj;
|
|
188
106
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
);
|
|
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
|
+
});
|
|
196
114
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"_values",
|
|
205
|
-
"_internalValues",
|
|
206
|
-
"_content_source",
|
|
207
|
-
"_tina_metadata"
|
|
208
|
-
].includes(key)) {
|
|
209
|
-
transformedObj[key] = value;
|
|
210
|
-
} else {
|
|
211
|
-
transformedObj[key] = addMetadata(id, value, currentPath);
|
|
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);
|
|
212
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
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
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
|
+
});
|
|
213
165
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (value instanceof Boolean)
|
|
236
|
-
return true;
|
|
237
|
-
return false;
|
|
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;
|
|
238
187
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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);
|
|
244
211
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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;
|