@tinacms/vercel-previews 0.0.7 → 0.0.9

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/index.es.js CHANGED
@@ -56,18 +56,27 @@ const useVisualEditing = ({
56
56
  query,
57
57
  variables
58
58
  });
59
- const id = React.useMemo(() => hashFromQuery(stringifiedQuery), [stringifiedQuery]);
59
+ const id = React.useMemo(
60
+ () => hashFromQuery(stringifiedQuery),
61
+ [stringifiedQuery]
62
+ );
60
63
  const { edit } = useEditState();
61
- const handleOpenEvent = useCallback((event) => {
62
- var _a, _b;
63
- if (edit) {
64
- parent.postMessage({ type: "field:selected", fieldName: (_b = (_a = event.detail) == null ? void 0 : _a.data) == null ? void 0 : _b.fieldName }, window.location.origin);
65
- } else {
66
- const tinaAdminBasePath = redirect.startsWith("/") ? redirect : `/${redirect}`;
67
- const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${event.detail.data.fieldName}`;
68
- window.location.assign(tinaAdminPath);
69
- }
70
- }, [edit]);
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
+ );
71
80
  useEffect(() => {
72
81
  window.addEventListener("edit:open", handleOpenEvent);
73
82
  return () => {
@@ -90,7 +99,9 @@ const useVisualEditing = ({
90
99
  return obj;
91
100
  }
92
101
  if (Array.isArray(obj)) {
93
- return obj.map((item, index) => appendMetadata(item, [...path, index], id2));
102
+ return obj.map(
103
+ (item, index) => appendMetadata(item, [...path, index], id2)
104
+ );
94
105
  }
95
106
  const transformedObj = {};
96
107
  for (const [key, value] of Object.entries(obj)) {
@@ -132,4 +143,8 @@ const hashFromQuery = (input) => {
132
143
  const alphanumericHash = nonNegativeHash.toString(36);
133
144
  return alphanumericHash;
134
145
  };
135
- export { hashFromQuery, useVisualEditing, vercelEditInfo };
146
+ export {
147
+ hashFromQuery,
148
+ useVisualEditing,
149
+ vercelEditInfo
150
+ };
package/dist/index.js CHANGED
@@ -2,13 +2,9 @@
2
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
3
  })(this, function(exports2, stega, React) {
4
4
  "use strict";
5
- function _interopDefaultLegacy(e) {
6
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
7
- }
8
- var React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
9
5
  function useEditState() {
10
- const [edit, setEdit] = React__default["default"].useState(false);
11
- React__default["default"].useEffect(() => {
6
+ const [edit, setEdit] = React.useState(false);
7
+ React.useEffect(() => {
12
8
  if (typeof window !== "undefined") {
13
9
  parent.postMessage({ type: "isEditMode" }, window.location.origin);
14
10
  window.addEventListener("message", (event) => {
@@ -62,18 +58,27 @@
62
58
  query,
63
59
  variables
64
60
  });
65
- const id = React__default["default"].useMemo(() => hashFromQuery(stringifiedQuery), [stringifiedQuery]);
61
+ const id = React.useMemo(
62
+ () => hashFromQuery(stringifiedQuery),
63
+ [stringifiedQuery]
64
+ );
66
65
  const { edit } = useEditState();
67
- const handleOpenEvent = React.useCallback((event) => {
68
- var _a, _b;
69
- if (edit) {
70
- parent.postMessage({ type: "field:selected", fieldName: (_b = (_a = event.detail) == null ? void 0 : _a.data) == null ? void 0 : _b.fieldName }, window.location.origin);
71
- } else {
72
- const tinaAdminBasePath = redirect.startsWith("/") ? redirect : `/${redirect}`;
73
- const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${event.detail.data.fieldName}`;
74
- window.location.assign(tinaAdminPath);
75
- }
76
- }, [edit]);
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
+ );
77
82
  React.useEffect(() => {
78
83
  window.addEventListener("edit:open", handleOpenEvent);
79
84
  return () => {
@@ -96,7 +101,9 @@
96
101
  return obj;
97
102
  }
98
103
  if (Array.isArray(obj)) {
99
- return obj.map((item, index) => appendMetadata(item, [...path, index], id2));
104
+ return obj.map(
105
+ (item, index) => appendMetadata(item, [...path, index], id2)
106
+ );
100
107
  }
101
108
  const transformedObj = {};
102
109
  for (const [key, value] of Object.entries(obj)) {
@@ -141,5 +148,5 @@
141
148
  exports2.hashFromQuery = hashFromQuery;
142
149
  exports2.useVisualEditing = useVisualEditing;
143
150
  exports2.vercelEditInfo = vercelEditInfo;
144
- Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
151
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
145
152
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/vercel-previews",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "./dist/index.es.js",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@vercel/stega": "^0.0.5",
44
- "tinacms": "1.5.11"
44
+ "tinacms": "1.5.13"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": ">=16.14"