@tinacms/vercel-previews 0.0.0-feaa40f-20241112045116 → 0.0.0-feb93be-20251224065424

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 (3) hide show
  1. package/dist/index.js +127 -142
  2. package/package.json +6 -13
  3. package/dist/index.mjs +0 -150
package/dist/index.js CHANGED
@@ -1,152 +1,137 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@vercel/stega"), require("react")) : typeof define === "function" && define.amd ? define(["exports", "@vercel/stega", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/vercel-previews"] = {}, global.NOOP, global.NOOP));
3
- })(this, function(exports2, stega, React) {
4
- "use strict";
5
- function useEditState() {
6
- const [edit, setEdit] = React.useState(false);
7
- React.useEffect(() => {
8
- if (typeof window !== "undefined") {
9
- parent.postMessage({ type: "isEditMode" }, window.location.origin);
10
- window.addEventListener("message", (event) => {
11
- var _a;
12
- if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
13
- setEdit(true);
14
- }
15
- });
16
- }
17
- }, []);
18
- return { edit };
19
- }
20
- const tinaField = (object, property, index) => {
21
- var _a, _b, _c;
22
- if (!object) {
23
- return "";
24
- }
25
- if (object._content_source) {
26
- if (!property) {
27
- return [
28
- (_a = object._content_source) == null ? void 0 : _a.queryId,
29
- object._content_source.path.join(".")
30
- ].join("---");
31
- }
32
- if (typeof index === "number") {
33
- return [
34
- (_b = object._content_source) == null ? void 0 : _b.queryId,
35
- [...object._content_source.path, property, index].join(".")
36
- ].join("---");
37
- }
38
- return [
39
- (_c = object._content_source) == null ? void 0 : _c.queryId,
40
- [...object._content_source.path, property].join(".")
41
- ].join("---");
1
+ import { vercelStegaCombine } from "@vercel/stega";
2
+ import React, { useCallback, useEffect } from "react";
3
+ function useEditState() {
4
+ const [edit, setEdit] = React.useState(false);
5
+ React.useEffect(() => {
6
+ if (typeof window !== "undefined") {
7
+ parent.postMessage({ type: "isEditMode" }, window.location.origin);
8
+ window.addEventListener("message", (event) => {
9
+ var _a;
10
+ if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
11
+ setEdit(true);
12
+ }
13
+ });
42
14
  }
15
+ }, []);
16
+ return { edit };
17
+ }
18
+ const tinaField = (object, property, index) => {
19
+ const contentSource = object == null ? void 0 : object._content_source;
20
+ if (!contentSource) {
43
21
  return "";
44
- };
45
- const vercelEditInfo = (obj, field, index) => {
46
- const fieldName = tinaField(obj, field, index);
47
- return JSON.stringify({ origin: "tinacms", data: { fieldName } });
48
- };
49
- const useVisualEditing = ({
50
- data,
22
+ }
23
+ const { queryId, path } = contentSource;
24
+ if (!property) {
25
+ return `${queryId}---${path.join(".")}`;
26
+ }
27
+ const fullPath = typeof index === "number" ? [...path, property, index] : [...path, property];
28
+ return `${queryId}---${fullPath.join(".")}`;
29
+ };
30
+ const vercelEditInfo = (obj, field, index) => {
31
+ const fieldName = tinaField(obj, field, index);
32
+ return JSON.stringify({ origin: "tinacms", data: { fieldName } });
33
+ };
34
+ const useVisualEditing = ({
35
+ data,
36
+ query,
37
+ variables,
38
+ enabled,
39
+ redirect,
40
+ stringEncoding
41
+ }) => {
42
+ const stringifiedQuery = JSON.stringify({
51
43
  query,
52
- variables,
53
- enabled,
54
- redirect,
55
- stringEncoding
56
- }) => {
57
- const stringifiedQuery = JSON.stringify({
58
- query,
59
- variables
60
- });
61
- const id = React.useMemo(
62
- () => hashFromQuery(stringifiedQuery),
63
- [stringifiedQuery]
64
- );
65
- const { edit } = useEditState();
66
- const handleOpenEvent = React.useCallback(
67
- (event) => {
68
- var _a, _b;
69
- if (edit) {
70
- parent.postMessage(
71
- { type: "field:selected", fieldName: (_b = (_a = event.detail) == null ? void 0 : _a.data) == null ? void 0 : _b.fieldName },
72
- window.location.origin
73
- );
74
- } else {
75
- const tinaAdminBasePath = redirect.startsWith("/") ? redirect : `/${redirect}`;
76
- const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${event.detail.data.fieldName}`;
77
- window.location.assign(tinaAdminPath);
78
- }
79
- },
80
- [edit]
81
- );
82
- React.useEffect(() => {
83
- window.addEventListener("edit:open", handleOpenEvent);
84
- return () => {
85
- window.removeEventListener("edit:open", handleOpenEvent);
86
- };
87
- }, [redirect, edit]);
88
- function appendMetadata(obj, path = [], id2) {
89
- if (typeof obj !== "object" || obj === null) {
90
- if (typeof obj === "string" && stringEncoding) {
91
- if (typeof stringEncoding === "boolean") {
92
- if (stringEncoding) {
93
- return encodeEditInfo(path, obj, id2);
94
- }
95
- } else if (stringEncoding.skipPaths) {
96
- if (!stringEncoding.skipPaths(path.join("."), obj)) {
97
- return encodeEditInfo(path, obj, id2);
98
- }
99
- }
100
- }
101
- return obj;
102
- }
103
- if (Array.isArray(obj)) {
104
- return obj.map(
105
- (item, index) => appendMetadata(item, [...path, index], id2)
44
+ variables
45
+ });
46
+ const id = React.useMemo(
47
+ () => hashFromQuery(stringifiedQuery),
48
+ [stringifiedQuery]
49
+ );
50
+ const { edit } = useEditState();
51
+ const handleOpenEvent = useCallback(
52
+ (event) => {
53
+ var _a, _b;
54
+ if (edit) {
55
+ parent.postMessage(
56
+ { type: "field:selected", fieldName: (_b = (_a = event.detail) == null ? void 0 : _a.data) == null ? void 0 : _b.fieldName },
57
+ window.location.origin
106
58
  );
59
+ } else {
60
+ const tinaAdminBasePath = redirect.startsWith("/") ? redirect : `/${redirect}`;
61
+ const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${event.detail.data.fieldName}`;
62
+ window.location.assign(tinaAdminPath);
107
63
  }
108
- const transformedObj = {};
109
- for (const [key, value] of Object.entries(obj)) {
110
- const currentPath = [...path, key];
111
- if ([
112
- "__typename",
113
- "_sys",
114
- "_internalSys",
115
- "_values",
116
- "_internalValues",
117
- "_content_source",
118
- "_tina_metadata"
119
- ].includes(key)) {
120
- transformedObj[key] = value;
121
- } else {
122
- transformedObj[key] = appendMetadata(value, currentPath, id2);
64
+ },
65
+ [edit]
66
+ );
67
+ useEffect(() => {
68
+ window.addEventListener("edit:open", handleOpenEvent);
69
+ return () => {
70
+ window.removeEventListener("edit:open", handleOpenEvent);
71
+ };
72
+ }, [redirect, edit]);
73
+ function appendMetadata(obj, path = [], id2) {
74
+ if (typeof obj !== "object" || obj === null) {
75
+ if (typeof obj === "string" && stringEncoding) {
76
+ if (typeof stringEncoding === "boolean") {
77
+ if (stringEncoding) {
78
+ return encodeEditInfo(path, obj, id2);
79
+ }
80
+ } else if (stringEncoding.skipPaths) {
81
+ if (!stringEncoding.skipPaths(path.join("."), obj)) {
82
+ return encodeEditInfo(path, obj, id2);
83
+ }
123
84
  }
124
85
  }
125
- return { ...transformedObj, _content_source: { queryId: id2, path } };
86
+ return obj;
126
87
  }
127
- if (enabled) {
128
- return appendMetadata(data, [], id);
88
+ if (Array.isArray(obj)) {
89
+ return obj.map(
90
+ (item, index) => appendMetadata(item, [...path, index], id2)
91
+ );
129
92
  }
130
- return data;
131
- };
132
- function encodeEditInfo(path, value, id) {
133
- return stega.vercelStegaCombine(value, {
134
- origin: "tina.io",
135
- data: { fieldName: `${id}---${path.join(".")}` }
136
- });
137
- }
138
- const hashFromQuery = (input) => {
139
- let hash = 0;
140
- for (let i = 0; i < input.length; i++) {
141
- const char = input.charCodeAt(i);
142
- hash = (hash << 5) - hash + char & 4294967295;
93
+ const transformedObj = {};
94
+ for (const [key, value] of Object.entries(obj)) {
95
+ const currentPath = [...path, key];
96
+ if ([
97
+ "__typename",
98
+ "_sys",
99
+ "_internalSys",
100
+ "_values",
101
+ "_internalValues",
102
+ "_content_source",
103
+ "_tina_metadata"
104
+ ].includes(key)) {
105
+ transformedObj[key] = value;
106
+ } else {
107
+ transformedObj[key] = appendMetadata(value, currentPath, id2);
108
+ }
143
109
  }
144
- const nonNegativeHash = Math.abs(hash);
145
- const alphanumericHash = nonNegativeHash.toString(36);
146
- return alphanumericHash;
147
- };
148
- exports2.hashFromQuery = hashFromQuery;
149
- exports2.useVisualEditing = useVisualEditing;
150
- exports2.vercelEditInfo = vercelEditInfo;
151
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
152
- });
110
+ return { ...transformedObj, _content_source: { queryId: id2, path } };
111
+ }
112
+ if (enabled) {
113
+ return appendMetadata(data, [], id);
114
+ }
115
+ return data;
116
+ };
117
+ function encodeEditInfo(path, value, id) {
118
+ return vercelStegaCombine(value, {
119
+ origin: "tina.io",
120
+ data: { fieldName: `${id}---${path.join(".")}` }
121
+ });
122
+ }
123
+ const hashFromQuery = (input) => {
124
+ let hash = 0;
125
+ for (let i = 0; i < input.length; i++) {
126
+ const char = input.charCodeAt(i);
127
+ hash = (hash << 5) - hash + char & 4294967295;
128
+ }
129
+ const nonNegativeHash = Math.abs(hash);
130
+ const alphanumericHash = nonNegativeHash.toString(36);
131
+ return alphanumericHash;
132
+ };
133
+ export {
134
+ hashFromQuery,
135
+ useVisualEditing,
136
+ vercelEditInfo
137
+ };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tinacms/vercel-previews",
3
- "version": "0.0.0-feaa40f-20241112045116",
3
+ "type": "module",
4
+ "version": "0.0.0-feb93be-20251224065424",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
- "module": "./dist/index.mjs",
7
7
  "keywords": [
8
8
  "tinacms",
9
9
  "cms",
@@ -12,13 +12,6 @@
12
12
  "files": [
13
13
  "dist"
14
14
  ],
15
- "exports": {
16
- ".": {
17
- "types": "./dist/index.d.ts",
18
- "import": "./dist/index.mjs",
19
- "require": "./dist/index.js"
20
- }
21
- },
22
15
  "buildConfig": {
23
16
  "entryPoints": [
24
17
  "src/index.ts"
@@ -34,14 +27,14 @@
34
27
  },
35
28
  "license": "Apache-2.0",
36
29
  "devDependencies": {
37
- "@types/react": "^18.3.10",
30
+ "@types/react": "^18.3.18",
38
31
  "react": "^18.3.1",
39
- "typescript": "^5.6.2",
40
- "@tinacms/scripts": "1.3.0"
32
+ "typescript": "^5.7.3",
33
+ "@tinacms/scripts": "1.4.2"
41
34
  },
42
35
  "dependencies": {
43
36
  "@vercel/stega": "^0.0.5",
44
- "tinacms": "0.0.0-feaa40f-20241112045116"
37
+ "tinacms": "0.0.0-feb93be-20251224065424"
45
38
  },
46
39
  "peerDependencies": {
47
40
  "react": ">=16.14"
package/dist/index.mjs DELETED
@@ -1,150 +0,0 @@
1
- import { vercelStegaCombine } from "@vercel/stega";
2
- import React, { useCallback, useEffect } from "react";
3
- function useEditState() {
4
- const [edit, setEdit] = React.useState(false);
5
- React.useEffect(() => {
6
- if (typeof window !== "undefined") {
7
- parent.postMessage({ type: "isEditMode" }, window.location.origin);
8
- window.addEventListener("message", (event) => {
9
- var _a;
10
- if (((_a = event.data) == null ? void 0 : _a.type) === "tina:editMode") {
11
- setEdit(true);
12
- }
13
- });
14
- }
15
- }, []);
16
- return { edit };
17
- }
18
- const tinaField = (object, property, index) => {
19
- var _a, _b, _c;
20
- if (!object) {
21
- return "";
22
- }
23
- if (object._content_source) {
24
- if (!property) {
25
- return [
26
- (_a = object._content_source) == null ? void 0 : _a.queryId,
27
- object._content_source.path.join(".")
28
- ].join("---");
29
- }
30
- if (typeof index === "number") {
31
- return [
32
- (_b = object._content_source) == null ? void 0 : _b.queryId,
33
- [...object._content_source.path, property, index].join(".")
34
- ].join("---");
35
- }
36
- return [
37
- (_c = object._content_source) == null ? void 0 : _c.queryId,
38
- [...object._content_source.path, property].join(".")
39
- ].join("---");
40
- }
41
- return "";
42
- };
43
- const vercelEditInfo = (obj, field, index) => {
44
- const fieldName = tinaField(obj, field, index);
45
- return JSON.stringify({ origin: "tinacms", data: { fieldName } });
46
- };
47
- const useVisualEditing = ({
48
- data,
49
- query,
50
- variables,
51
- enabled,
52
- redirect,
53
- stringEncoding
54
- }) => {
55
- const stringifiedQuery = JSON.stringify({
56
- query,
57
- variables
58
- });
59
- const id = React.useMemo(
60
- () => hashFromQuery(stringifiedQuery),
61
- [stringifiedQuery]
62
- );
63
- const { edit } = useEditState();
64
- const handleOpenEvent = useCallback(
65
- (event) => {
66
- var _a, _b;
67
- if (edit) {
68
- parent.postMessage(
69
- { type: "field:selected", fieldName: (_b = (_a = event.detail) == null ? void 0 : _a.data) == null ? void 0 : _b.fieldName },
70
- window.location.origin
71
- );
72
- } else {
73
- const tinaAdminBasePath = redirect.startsWith("/") ? redirect : `/${redirect}`;
74
- const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${event.detail.data.fieldName}`;
75
- window.location.assign(tinaAdminPath);
76
- }
77
- },
78
- [edit]
79
- );
80
- useEffect(() => {
81
- window.addEventListener("edit:open", handleOpenEvent);
82
- return () => {
83
- window.removeEventListener("edit:open", handleOpenEvent);
84
- };
85
- }, [redirect, edit]);
86
- function appendMetadata(obj, path = [], id2) {
87
- if (typeof obj !== "object" || obj === null) {
88
- if (typeof obj === "string" && stringEncoding) {
89
- if (typeof stringEncoding === "boolean") {
90
- if (stringEncoding) {
91
- return encodeEditInfo(path, obj, id2);
92
- }
93
- } else if (stringEncoding.skipPaths) {
94
- if (!stringEncoding.skipPaths(path.join("."), obj)) {
95
- return encodeEditInfo(path, obj, id2);
96
- }
97
- }
98
- }
99
- return obj;
100
- }
101
- if (Array.isArray(obj)) {
102
- return obj.map(
103
- (item, index) => appendMetadata(item, [...path, index], id2)
104
- );
105
- }
106
- const transformedObj = {};
107
- for (const [key, value] of Object.entries(obj)) {
108
- const currentPath = [...path, key];
109
- if ([
110
- "__typename",
111
- "_sys",
112
- "_internalSys",
113
- "_values",
114
- "_internalValues",
115
- "_content_source",
116
- "_tina_metadata"
117
- ].includes(key)) {
118
- transformedObj[key] = value;
119
- } else {
120
- transformedObj[key] = appendMetadata(value, currentPath, id2);
121
- }
122
- }
123
- return { ...transformedObj, _content_source: { queryId: id2, path } };
124
- }
125
- if (enabled) {
126
- return appendMetadata(data, [], id);
127
- }
128
- return data;
129
- };
130
- function encodeEditInfo(path, value, id) {
131
- return vercelStegaCombine(value, {
132
- origin: "tina.io",
133
- data: { fieldName: `${id}---${path.join(".")}` }
134
- });
135
- }
136
- const hashFromQuery = (input) => {
137
- let hash = 0;
138
- for (let i = 0; i < input.length; i++) {
139
- const char = input.charCodeAt(i);
140
- hash = (hash << 5) - hash + char & 4294967295;
141
- }
142
- const nonNegativeHash = Math.abs(hash);
143
- const alphanumericHash = nonNegativeHash.toString(36);
144
- return alphanumericHash;
145
- };
146
- export {
147
- hashFromQuery,
148
- useVisualEditing,
149
- vercelEditInfo
150
- };