@uniformdev/canvas-next-rsc-client 19.55.2-alpha.48 → 19.55.2-alpha.54
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.d.mts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.esm.js +96 -26
- package/dist/index.js +106 -36
- package/dist/index.mjs +96 -26
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { AppDirectoryContextState, ComponentProps, PersonalizeProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
2
|
-
import * as react from 'react';
|
|
3
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { PropsWithChildren } from 'react';
|
|
5
|
+
import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
6
|
+
|
|
7
|
+
declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
|
|
4
10
|
|
|
5
11
|
declare const ContextUpdateTransferClient: ({ update, ts, }: {
|
|
6
12
|
update: Partial<AppDirectoryContextState>;
|
|
7
13
|
ts: number;
|
|
8
14
|
}) => null;
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
type PersonalizeClientProps = PersonalizeProps & {
|
|
17
|
+
indexes: number[];
|
|
18
|
+
};
|
|
19
|
+
declare const PersonalizeClient: (props: ComponentProps<PersonalizeClientProps>) => react.FunctionComponentElement<{
|
|
11
20
|
children?: react.ReactNode;
|
|
12
21
|
}>;
|
|
13
22
|
|
|
@@ -28,4 +37,4 @@ declare const useUniformContext: () => {
|
|
|
28
37
|
context: AppDirectoryContext | undefined;
|
|
29
38
|
};
|
|
30
39
|
|
|
31
|
-
export { ContextUpdateTransferClient, PersonalizeClient, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
|
40
|
+
export { ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { AppDirectoryContextState, ComponentProps, PersonalizeProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
2
|
-
import * as react from 'react';
|
|
3
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { PropsWithChildren } from 'react';
|
|
5
|
+
import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
6
|
+
|
|
7
|
+
declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
|
|
4
10
|
|
|
5
11
|
declare const ContextUpdateTransferClient: ({ update, ts, }: {
|
|
6
12
|
update: Partial<AppDirectoryContextState>;
|
|
7
13
|
ts: number;
|
|
8
14
|
}) => null;
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
type PersonalizeClientProps = PersonalizeProps & {
|
|
17
|
+
indexes: number[];
|
|
18
|
+
};
|
|
19
|
+
declare const PersonalizeClient: (props: ComponentProps<PersonalizeClientProps>) => react.FunctionComponentElement<{
|
|
11
20
|
children?: react.ReactNode;
|
|
12
21
|
}>;
|
|
13
22
|
|
|
@@ -28,4 +37,4 @@ declare const useUniformContext: () => {
|
|
|
28
37
|
context: AppDirectoryContext | undefined;
|
|
29
38
|
};
|
|
30
39
|
|
|
31
|
-
export { ContextUpdateTransferClient, PersonalizeClient, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
|
40
|
+
export { ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/components/
|
|
4
|
-
import {
|
|
3
|
+
// src/components/ClientContextualEditingComponentWrapper.tsx
|
|
4
|
+
import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
5
|
+
import {
|
|
6
|
+
PureContextualEditingComponentWrapper
|
|
7
|
+
} from "@uniformdev/canvas-react/core";
|
|
8
|
+
import { useSearchParams } from "next/navigation";
|
|
9
|
+
import { Suspense } from "react";
|
|
10
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
11
|
+
var ClientContextualEditingComponentWrapper = (props) => {
|
|
12
|
+
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ClientContextualEditingComponentWrapperInner, { ...props }) });
|
|
13
|
+
};
|
|
14
|
+
var ClientContextualEditingComponentWrapperInner = ({
|
|
15
|
+
children,
|
|
16
|
+
...rest
|
|
17
|
+
}) => {
|
|
18
|
+
const searchParams = useSearchParams();
|
|
19
|
+
const inContextMode = searchParams.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
|
|
20
|
+
if (!inContextMode) {
|
|
21
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsx(PureContextualEditingComponentWrapper, { ...rest, children });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/components/ClientContextUpdate.tsx
|
|
27
|
+
import { useParams, useSearchParams as useSearchParams2 } from "next/navigation";
|
|
28
|
+
import { Suspense as Suspense2, useEffect as useEffect2 } from "react";
|
|
5
29
|
|
|
6
30
|
// src/hooks/useUniformContext.ts
|
|
7
31
|
import { useEffect, useState } from "react";
|
|
@@ -23,14 +47,37 @@ var useUniformContext = () => {
|
|
|
23
47
|
};
|
|
24
48
|
};
|
|
25
49
|
|
|
50
|
+
// src/components/ClientContextUpdate.tsx
|
|
51
|
+
import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
|
|
52
|
+
var ClientContextUpdate = () => {
|
|
53
|
+
return /* @__PURE__ */ jsx2(Suspense2, { children: /* @__PURE__ */ jsx2(ClientContextUpdateInner, {}) });
|
|
54
|
+
};
|
|
55
|
+
var ClientContextUpdateInner = () => {
|
|
56
|
+
const params = useParams();
|
|
57
|
+
const searchParams = useSearchParams2();
|
|
58
|
+
const { context } = useUniformContext();
|
|
59
|
+
useEffect2(() => {
|
|
60
|
+
if (!context || typeof window === "undefined") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const convertedSearchParams = Object.fromEntries(searchParams.entries());
|
|
64
|
+
context.update({
|
|
65
|
+
params,
|
|
66
|
+
searchParams: convertedSearchParams
|
|
67
|
+
});
|
|
68
|
+
}, [params, searchParams, context]);
|
|
69
|
+
return /* @__PURE__ */ jsx2(Fragment2, {});
|
|
70
|
+
};
|
|
71
|
+
|
|
26
72
|
// src/components/ContextUpdateTransferClient.tsx
|
|
73
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
27
74
|
var ContextUpdateTransferClient = ({
|
|
28
75
|
update,
|
|
29
76
|
ts
|
|
30
77
|
}) => {
|
|
31
78
|
const { context } = useUniformContext();
|
|
32
79
|
const [lastLogged, setLastLogged] = useState2(void 0);
|
|
33
|
-
|
|
80
|
+
useEffect3(() => {
|
|
34
81
|
const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
|
|
35
82
|
const hasContext = typeof context !== "undefined";
|
|
36
83
|
if (shouldBeLogged && hasContext) {
|
|
@@ -44,59 +91,62 @@ var ContextUpdateTransferClient = ({
|
|
|
44
91
|
// src/components/PersonalizeClient.ts
|
|
45
92
|
import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
46
93
|
import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
|
|
47
|
-
import { createElement, Fragment,
|
|
94
|
+
import { createElement, Fragment as Fragment3, useEffect as useEffect4, useState as useState3 } from "react";
|
|
48
95
|
var PersonalizeClient = (props) => {
|
|
49
96
|
const { slots } = props;
|
|
50
97
|
const { context } = useUniformContext();
|
|
51
|
-
const
|
|
98
|
+
const [indexesToShow, setIndexesToShow] = useState3(props.indexes);
|
|
99
|
+
useEffect4(() => {
|
|
52
100
|
const result = runPersonalization({
|
|
53
101
|
...props,
|
|
54
102
|
contextInstance: context
|
|
55
103
|
});
|
|
56
|
-
|
|
104
|
+
setIndexesToShow(result.indexes);
|
|
57
105
|
}, [props, context]);
|
|
58
|
-
const slotsToShow =
|
|
106
|
+
const slotsToShow = indexesToShow.map((key) => {
|
|
59
107
|
var _a;
|
|
60
108
|
return (_a = slots[CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
|
|
61
109
|
});
|
|
62
|
-
return createElement(
|
|
110
|
+
return createElement(Fragment3, void 0, slotsToShow);
|
|
63
111
|
};
|
|
64
112
|
|
|
65
113
|
// src/components/TestClient.ts
|
|
66
114
|
import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
|
|
67
115
|
import { runTest } from "@uniformdev/canvas-next-rsc-shared";
|
|
68
|
-
import { createElement as createElement2, Fragment as
|
|
116
|
+
import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect5, useState as useState4 } from "react";
|
|
69
117
|
var TestClient = (props) => {
|
|
70
118
|
var _a;
|
|
71
119
|
const { slots } = props;
|
|
72
120
|
const { context } = useUniformContext();
|
|
73
|
-
const index =
|
|
121
|
+
const [index, setIndex] = useState4(0);
|
|
122
|
+
useEffect5(() => {
|
|
74
123
|
const result = runTest({
|
|
75
124
|
...props,
|
|
76
125
|
contextInstance: context
|
|
77
126
|
});
|
|
78
|
-
|
|
127
|
+
setIndex(result.index);
|
|
79
128
|
}, [props, context]);
|
|
80
129
|
if (typeof index !== "number") {
|
|
81
130
|
return null;
|
|
82
131
|
}
|
|
83
|
-
return createElement2(
|
|
132
|
+
return createElement2(Fragment4, void 0, (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
|
|
84
133
|
};
|
|
85
134
|
|
|
86
135
|
// src/components/UniformScriptClient.tsx
|
|
87
136
|
import {
|
|
88
137
|
createCanvasChannel,
|
|
89
|
-
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
138
|
+
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2,
|
|
90
139
|
isAllowedReferrer
|
|
91
140
|
} from "@uniformdev/canvas";
|
|
92
|
-
import { useRouter, useSearchParams } from "next/navigation";
|
|
93
|
-
import { useEffect as
|
|
94
|
-
import { Fragment as
|
|
141
|
+
import { useRouter, useSearchParams as useSearchParams3 } from "next/navigation";
|
|
142
|
+
import { useEffect as useEffect6, useMemo, useRef } from "react";
|
|
143
|
+
import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
|
|
95
144
|
var UniformScript = () => {
|
|
96
145
|
const router = useRouter();
|
|
97
|
-
const params =
|
|
98
|
-
const
|
|
99
|
-
const
|
|
146
|
+
const params = useSearchParams3();
|
|
147
|
+
const needsToRefreshRef = useRef(false);
|
|
148
|
+
const enabled = params.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2) === "true";
|
|
149
|
+
const channel = useMemo(() => {
|
|
100
150
|
var _a;
|
|
101
151
|
if (typeof window === "undefined") {
|
|
102
152
|
return;
|
|
@@ -107,18 +157,24 @@ var UniformScript = () => {
|
|
|
107
157
|
});
|
|
108
158
|
return instance;
|
|
109
159
|
}, []);
|
|
110
|
-
|
|
160
|
+
useEffect6(() => {
|
|
111
161
|
if (!channel) {
|
|
112
162
|
return;
|
|
113
163
|
}
|
|
114
164
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
115
|
-
|
|
165
|
+
const el = document.activeElement;
|
|
166
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
167
|
+
if (!isActiveElementEditable) {
|
|
168
|
+
router.refresh();
|
|
169
|
+
} else {
|
|
170
|
+
needsToRefreshRef.current = true;
|
|
171
|
+
}
|
|
116
172
|
});
|
|
117
173
|
return () => {
|
|
118
174
|
unsubscribeFromEditorUpdates();
|
|
119
175
|
};
|
|
120
176
|
}, [channel, router]);
|
|
121
|
-
|
|
177
|
+
useEffect6(() => {
|
|
122
178
|
if (typeof window === "undefined") {
|
|
123
179
|
return;
|
|
124
180
|
}
|
|
@@ -139,14 +195,26 @@ var UniformScript = () => {
|
|
|
139
195
|
existing.remove();
|
|
140
196
|
}
|
|
141
197
|
}, [enabled]);
|
|
142
|
-
|
|
198
|
+
useEffect6(() => {
|
|
199
|
+
const handleBlurChange = () => {
|
|
200
|
+
if (needsToRefreshRef.current) {
|
|
201
|
+
router.refresh();
|
|
202
|
+
needsToRefreshRef.current = false;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
206
|
+
return () => {
|
|
207
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
208
|
+
};
|
|
209
|
+
}, [router]);
|
|
210
|
+
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
143
211
|
};
|
|
144
212
|
|
|
145
213
|
// src/hooks/useInitUniformContext.ts
|
|
146
|
-
import { useEffect as
|
|
214
|
+
import { useEffect as useEffect7, useState as useState5 } from "react";
|
|
147
215
|
var useInitUniformContext = (callback) => {
|
|
148
|
-
const [called, setCalled] =
|
|
149
|
-
|
|
216
|
+
const [called, setCalled] = useState5(false);
|
|
217
|
+
useEffect7(() => {
|
|
150
218
|
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
151
219
|
return;
|
|
152
220
|
}
|
|
@@ -157,6 +225,8 @@ var useInitUniformContext = (callback) => {
|
|
|
157
225
|
}, [called, callback]);
|
|
158
226
|
};
|
|
159
227
|
export {
|
|
228
|
+
ClientContextUpdate,
|
|
229
|
+
ClientContextualEditingComponentWrapper,
|
|
160
230
|
ContextUpdateTransferClient,
|
|
161
231
|
PersonalizeClient,
|
|
162
232
|
TestClient,
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
|
+
ClientContextUpdate: () => ClientContextUpdate,
|
|
25
|
+
ClientContextualEditingComponentWrapper: () => ClientContextualEditingComponentWrapper,
|
|
24
26
|
ContextUpdateTransferClient: () => ContextUpdateTransferClient,
|
|
25
27
|
PersonalizeClient: () => PersonalizeClient,
|
|
26
28
|
TestClient: () => TestClient,
|
|
@@ -30,16 +32,38 @@ __export(src_exports, {
|
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(src_exports);
|
|
32
34
|
|
|
33
|
-
// src/components/
|
|
34
|
-
var
|
|
35
|
+
// src/components/ClientContextualEditingComponentWrapper.tsx
|
|
36
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
37
|
+
var import_core = require("@uniformdev/canvas-react/core");
|
|
38
|
+
var import_navigation = require("next/navigation");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var ClientContextualEditingComponentWrapper = (props) => {
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClientContextualEditingComponentWrapperInner, { ...props }) });
|
|
43
|
+
};
|
|
44
|
+
var ClientContextualEditingComponentWrapperInner = ({
|
|
45
|
+
children,
|
|
46
|
+
...rest
|
|
47
|
+
}) => {
|
|
48
|
+
const searchParams = (0, import_navigation.useSearchParams)();
|
|
49
|
+
const inContextMode = searchParams.get(import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
|
|
50
|
+
if (!inContextMode) {
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
52
|
+
}
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.PureContextualEditingComponentWrapper, { ...rest, children });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/components/ClientContextUpdate.tsx
|
|
57
|
+
var import_navigation2 = require("next/navigation");
|
|
58
|
+
var import_react3 = require("react");
|
|
35
59
|
|
|
36
60
|
// src/hooks/useUniformContext.ts
|
|
37
|
-
var
|
|
61
|
+
var import_react2 = require("react");
|
|
38
62
|
var useUniformContext = () => {
|
|
39
|
-
const [context, setContext] = (0,
|
|
63
|
+
const [context, setContext] = (0, import_react2.useState)(
|
|
40
64
|
typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
|
|
41
65
|
);
|
|
42
|
-
(0,
|
|
66
|
+
(0, import_react2.useEffect)(() => {
|
|
43
67
|
const listener = () => {
|
|
44
68
|
setContext(window.__UNIFORM_CONTEXT__);
|
|
45
69
|
};
|
|
@@ -53,14 +77,37 @@ var useUniformContext = () => {
|
|
|
53
77
|
};
|
|
54
78
|
};
|
|
55
79
|
|
|
80
|
+
// src/components/ClientContextUpdate.tsx
|
|
81
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
82
|
+
var ClientContextUpdate = () => {
|
|
83
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ClientContextUpdateInner, {}) });
|
|
84
|
+
};
|
|
85
|
+
var ClientContextUpdateInner = () => {
|
|
86
|
+
const params = (0, import_navigation2.useParams)();
|
|
87
|
+
const searchParams = (0, import_navigation2.useSearchParams)();
|
|
88
|
+
const { context } = useUniformContext();
|
|
89
|
+
(0, import_react3.useEffect)(() => {
|
|
90
|
+
if (!context || typeof window === "undefined") {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const convertedSearchParams = Object.fromEntries(searchParams.entries());
|
|
94
|
+
context.update({
|
|
95
|
+
params,
|
|
96
|
+
searchParams: convertedSearchParams
|
|
97
|
+
});
|
|
98
|
+
}, [params, searchParams, context]);
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
100
|
+
};
|
|
101
|
+
|
|
56
102
|
// src/components/ContextUpdateTransferClient.tsx
|
|
103
|
+
var import_react4 = require("react");
|
|
57
104
|
var ContextUpdateTransferClient = ({
|
|
58
105
|
update,
|
|
59
106
|
ts
|
|
60
107
|
}) => {
|
|
61
108
|
const { context } = useUniformContext();
|
|
62
|
-
const [lastLogged, setLastLogged] = (0,
|
|
63
|
-
(0,
|
|
109
|
+
const [lastLogged, setLastLogged] = (0, import_react4.useState)(void 0);
|
|
110
|
+
(0, import_react4.useEffect)(() => {
|
|
64
111
|
const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
|
|
65
112
|
const hasContext = typeof context !== "undefined";
|
|
66
113
|
if (shouldBeLogged && hasContext) {
|
|
@@ -72,86 +119,95 @@ var ContextUpdateTransferClient = ({
|
|
|
72
119
|
};
|
|
73
120
|
|
|
74
121
|
// src/components/PersonalizeClient.ts
|
|
75
|
-
var
|
|
122
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
76
123
|
var import_canvas_next_rsc_shared = require("@uniformdev/canvas-next-rsc-shared");
|
|
77
|
-
var
|
|
124
|
+
var import_react5 = require("react");
|
|
78
125
|
var PersonalizeClient = (props) => {
|
|
79
126
|
const { slots } = props;
|
|
80
127
|
const { context } = useUniformContext();
|
|
81
|
-
const
|
|
128
|
+
const [indexesToShow, setIndexesToShow] = (0, import_react5.useState)(props.indexes);
|
|
129
|
+
(0, import_react5.useEffect)(() => {
|
|
82
130
|
const result = (0, import_canvas_next_rsc_shared.runPersonalization)({
|
|
83
131
|
...props,
|
|
84
132
|
contextInstance: context
|
|
85
133
|
});
|
|
86
|
-
|
|
134
|
+
setIndexesToShow(result.indexes);
|
|
87
135
|
}, [props, context]);
|
|
88
|
-
const slotsToShow =
|
|
136
|
+
const slotsToShow = indexesToShow.map((key) => {
|
|
89
137
|
var _a;
|
|
90
|
-
return (_a = slots[
|
|
138
|
+
return (_a = slots[import_canvas2.CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
|
|
91
139
|
});
|
|
92
|
-
return (0,
|
|
140
|
+
return (0, import_react5.createElement)(import_react5.Fragment, void 0, slotsToShow);
|
|
93
141
|
};
|
|
94
142
|
|
|
95
143
|
// src/components/TestClient.ts
|
|
96
|
-
var
|
|
144
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
97
145
|
var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
|
|
98
|
-
var
|
|
146
|
+
var import_react6 = require("react");
|
|
99
147
|
var TestClient = (props) => {
|
|
100
148
|
var _a;
|
|
101
149
|
const { slots } = props;
|
|
102
150
|
const { context } = useUniformContext();
|
|
103
|
-
const index = (0,
|
|
151
|
+
const [index, setIndex] = (0, import_react6.useState)(0);
|
|
152
|
+
(0, import_react6.useEffect)(() => {
|
|
104
153
|
const result = (0, import_canvas_next_rsc_shared2.runTest)({
|
|
105
154
|
...props,
|
|
106
155
|
contextInstance: context
|
|
107
156
|
});
|
|
108
|
-
|
|
157
|
+
setIndex(result.index);
|
|
109
158
|
}, [props, context]);
|
|
110
159
|
if (typeof index !== "number") {
|
|
111
160
|
return null;
|
|
112
161
|
}
|
|
113
|
-
return (0,
|
|
162
|
+
return (0, import_react6.createElement)(import_react6.Fragment, void 0, (_a = slots == null ? void 0 : slots[import_canvas3.CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
|
|
114
163
|
};
|
|
115
164
|
|
|
116
165
|
// src/components/UniformScriptClient.tsx
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
var
|
|
120
|
-
var
|
|
166
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
167
|
+
var import_navigation3 = require("next/navigation");
|
|
168
|
+
var import_react7 = require("react");
|
|
169
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
121
170
|
var UniformScript = () => {
|
|
122
|
-
const router = (0,
|
|
123
|
-
const params = (0,
|
|
124
|
-
const
|
|
125
|
-
const
|
|
171
|
+
const router = (0, import_navigation3.useRouter)();
|
|
172
|
+
const params = (0, import_navigation3.useSearchParams)();
|
|
173
|
+
const needsToRefreshRef = (0, import_react7.useRef)(false);
|
|
174
|
+
const enabled = params.get(import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
|
|
175
|
+
const channel = (0, import_react7.useMemo)(() => {
|
|
126
176
|
var _a;
|
|
127
177
|
if (typeof window === "undefined") {
|
|
128
178
|
return;
|
|
129
179
|
}
|
|
130
|
-
const instance = (0,
|
|
180
|
+
const instance = (0, import_canvas4.createCanvasChannel)({
|
|
131
181
|
broadcastTo: [(_a = window.opener) != null ? _a : window.top],
|
|
132
182
|
listenTo: [window]
|
|
133
183
|
});
|
|
134
184
|
return instance;
|
|
135
185
|
}, []);
|
|
136
|
-
(0,
|
|
186
|
+
(0, import_react7.useEffect)(() => {
|
|
137
187
|
if (!channel) {
|
|
138
188
|
return;
|
|
139
189
|
}
|
|
140
190
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
141
|
-
|
|
191
|
+
const el = document.activeElement;
|
|
192
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
193
|
+
if (!isActiveElementEditable) {
|
|
194
|
+
router.refresh();
|
|
195
|
+
} else {
|
|
196
|
+
needsToRefreshRef.current = true;
|
|
197
|
+
}
|
|
142
198
|
});
|
|
143
199
|
return () => {
|
|
144
200
|
unsubscribeFromEditorUpdates();
|
|
145
201
|
};
|
|
146
202
|
}, [channel, router]);
|
|
147
|
-
(0,
|
|
203
|
+
(0, import_react7.useEffect)(() => {
|
|
148
204
|
if (typeof window === "undefined") {
|
|
149
205
|
return;
|
|
150
206
|
}
|
|
151
207
|
const existing = document.getElementById("uniform-script");
|
|
152
208
|
if (enabled) {
|
|
153
209
|
if (!existing) {
|
|
154
|
-
const textHost = (0,
|
|
210
|
+
const textHost = (0, import_canvas4.isAllowedReferrer)(window.document.referrer) ? window.document.referrer : "https://uniform.app/";
|
|
155
211
|
const bundleHost = new URL(textHost);
|
|
156
212
|
bundleHost.pathname = "/files/canvas-in-context-embed/index.js";
|
|
157
213
|
const script = document.createElement("script");
|
|
@@ -165,14 +221,26 @@ var UniformScript = () => {
|
|
|
165
221
|
existing.remove();
|
|
166
222
|
}
|
|
167
223
|
}, [enabled]);
|
|
168
|
-
|
|
224
|
+
(0, import_react7.useEffect)(() => {
|
|
225
|
+
const handleBlurChange = () => {
|
|
226
|
+
if (needsToRefreshRef.current) {
|
|
227
|
+
router.refresh();
|
|
228
|
+
needsToRefreshRef.current = false;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
232
|
+
return () => {
|
|
233
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
234
|
+
};
|
|
235
|
+
}, [router]);
|
|
236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {});
|
|
169
237
|
};
|
|
170
238
|
|
|
171
239
|
// src/hooks/useInitUniformContext.ts
|
|
172
|
-
var
|
|
240
|
+
var import_react8 = require("react");
|
|
173
241
|
var useInitUniformContext = (callback) => {
|
|
174
|
-
const [called, setCalled] = (0,
|
|
175
|
-
(0,
|
|
242
|
+
const [called, setCalled] = (0, import_react8.useState)(false);
|
|
243
|
+
(0, import_react8.useEffect)(() => {
|
|
176
244
|
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
177
245
|
return;
|
|
178
246
|
}
|
|
@@ -184,6 +252,8 @@ var useInitUniformContext = (callback) => {
|
|
|
184
252
|
};
|
|
185
253
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
254
|
0 && (module.exports = {
|
|
255
|
+
ClientContextUpdate,
|
|
256
|
+
ClientContextualEditingComponentWrapper,
|
|
187
257
|
ContextUpdateTransferClient,
|
|
188
258
|
PersonalizeClient,
|
|
189
259
|
TestClient,
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/components/
|
|
4
|
-
import {
|
|
3
|
+
// src/components/ClientContextualEditingComponentWrapper.tsx
|
|
4
|
+
import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
5
|
+
import {
|
|
6
|
+
PureContextualEditingComponentWrapper
|
|
7
|
+
} from "@uniformdev/canvas-react/core";
|
|
8
|
+
import { useSearchParams } from "next/navigation";
|
|
9
|
+
import { Suspense } from "react";
|
|
10
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
11
|
+
var ClientContextualEditingComponentWrapper = (props) => {
|
|
12
|
+
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(ClientContextualEditingComponentWrapperInner, { ...props }) });
|
|
13
|
+
};
|
|
14
|
+
var ClientContextualEditingComponentWrapperInner = ({
|
|
15
|
+
children,
|
|
16
|
+
...rest
|
|
17
|
+
}) => {
|
|
18
|
+
const searchParams = useSearchParams();
|
|
19
|
+
const inContextMode = searchParams.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
|
|
20
|
+
if (!inContextMode) {
|
|
21
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsx(PureContextualEditingComponentWrapper, { ...rest, children });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/components/ClientContextUpdate.tsx
|
|
27
|
+
import { useParams, useSearchParams as useSearchParams2 } from "next/navigation";
|
|
28
|
+
import { Suspense as Suspense2, useEffect as useEffect2 } from "react";
|
|
5
29
|
|
|
6
30
|
// src/hooks/useUniformContext.ts
|
|
7
31
|
import { useEffect, useState } from "react";
|
|
@@ -23,14 +47,37 @@ var useUniformContext = () => {
|
|
|
23
47
|
};
|
|
24
48
|
};
|
|
25
49
|
|
|
50
|
+
// src/components/ClientContextUpdate.tsx
|
|
51
|
+
import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
|
|
52
|
+
var ClientContextUpdate = () => {
|
|
53
|
+
return /* @__PURE__ */ jsx2(Suspense2, { children: /* @__PURE__ */ jsx2(ClientContextUpdateInner, {}) });
|
|
54
|
+
};
|
|
55
|
+
var ClientContextUpdateInner = () => {
|
|
56
|
+
const params = useParams();
|
|
57
|
+
const searchParams = useSearchParams2();
|
|
58
|
+
const { context } = useUniformContext();
|
|
59
|
+
useEffect2(() => {
|
|
60
|
+
if (!context || typeof window === "undefined") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const convertedSearchParams = Object.fromEntries(searchParams.entries());
|
|
64
|
+
context.update({
|
|
65
|
+
params,
|
|
66
|
+
searchParams: convertedSearchParams
|
|
67
|
+
});
|
|
68
|
+
}, [params, searchParams, context]);
|
|
69
|
+
return /* @__PURE__ */ jsx2(Fragment2, {});
|
|
70
|
+
};
|
|
71
|
+
|
|
26
72
|
// src/components/ContextUpdateTransferClient.tsx
|
|
73
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
27
74
|
var ContextUpdateTransferClient = ({
|
|
28
75
|
update,
|
|
29
76
|
ts
|
|
30
77
|
}) => {
|
|
31
78
|
const { context } = useUniformContext();
|
|
32
79
|
const [lastLogged, setLastLogged] = useState2(void 0);
|
|
33
|
-
|
|
80
|
+
useEffect3(() => {
|
|
34
81
|
const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
|
|
35
82
|
const hasContext = typeof context !== "undefined";
|
|
36
83
|
if (shouldBeLogged && hasContext) {
|
|
@@ -44,59 +91,62 @@ var ContextUpdateTransferClient = ({
|
|
|
44
91
|
// src/components/PersonalizeClient.ts
|
|
45
92
|
import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
46
93
|
import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
|
|
47
|
-
import { createElement, Fragment,
|
|
94
|
+
import { createElement, Fragment as Fragment3, useEffect as useEffect4, useState as useState3 } from "react";
|
|
48
95
|
var PersonalizeClient = (props) => {
|
|
49
96
|
const { slots } = props;
|
|
50
97
|
const { context } = useUniformContext();
|
|
51
|
-
const
|
|
98
|
+
const [indexesToShow, setIndexesToShow] = useState3(props.indexes);
|
|
99
|
+
useEffect4(() => {
|
|
52
100
|
const result = runPersonalization({
|
|
53
101
|
...props,
|
|
54
102
|
contextInstance: context
|
|
55
103
|
});
|
|
56
|
-
|
|
104
|
+
setIndexesToShow(result.indexes);
|
|
57
105
|
}, [props, context]);
|
|
58
|
-
const slotsToShow =
|
|
106
|
+
const slotsToShow = indexesToShow.map((key) => {
|
|
59
107
|
var _a;
|
|
60
108
|
return (_a = slots[CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
|
|
61
109
|
});
|
|
62
|
-
return createElement(
|
|
110
|
+
return createElement(Fragment3, void 0, slotsToShow);
|
|
63
111
|
};
|
|
64
112
|
|
|
65
113
|
// src/components/TestClient.ts
|
|
66
114
|
import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
|
|
67
115
|
import { runTest } from "@uniformdev/canvas-next-rsc-shared";
|
|
68
|
-
import { createElement as createElement2, Fragment as
|
|
116
|
+
import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect5, useState as useState4 } from "react";
|
|
69
117
|
var TestClient = (props) => {
|
|
70
118
|
var _a;
|
|
71
119
|
const { slots } = props;
|
|
72
120
|
const { context } = useUniformContext();
|
|
73
|
-
const index =
|
|
121
|
+
const [index, setIndex] = useState4(0);
|
|
122
|
+
useEffect5(() => {
|
|
74
123
|
const result = runTest({
|
|
75
124
|
...props,
|
|
76
125
|
contextInstance: context
|
|
77
126
|
});
|
|
78
|
-
|
|
127
|
+
setIndex(result.index);
|
|
79
128
|
}, [props, context]);
|
|
80
129
|
if (typeof index !== "number") {
|
|
81
130
|
return null;
|
|
82
131
|
}
|
|
83
|
-
return createElement2(
|
|
132
|
+
return createElement2(Fragment4, void 0, (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
|
|
84
133
|
};
|
|
85
134
|
|
|
86
135
|
// src/components/UniformScriptClient.tsx
|
|
87
136
|
import {
|
|
88
137
|
createCanvasChannel,
|
|
89
|
-
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
138
|
+
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2,
|
|
90
139
|
isAllowedReferrer
|
|
91
140
|
} from "@uniformdev/canvas";
|
|
92
|
-
import { useRouter, useSearchParams } from "next/navigation";
|
|
93
|
-
import { useEffect as
|
|
94
|
-
import { Fragment as
|
|
141
|
+
import { useRouter, useSearchParams as useSearchParams3 } from "next/navigation";
|
|
142
|
+
import { useEffect as useEffect6, useMemo, useRef } from "react";
|
|
143
|
+
import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
|
|
95
144
|
var UniformScript = () => {
|
|
96
145
|
const router = useRouter();
|
|
97
|
-
const params =
|
|
98
|
-
const
|
|
99
|
-
const
|
|
146
|
+
const params = useSearchParams3();
|
|
147
|
+
const needsToRefreshRef = useRef(false);
|
|
148
|
+
const enabled = params.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2) === "true";
|
|
149
|
+
const channel = useMemo(() => {
|
|
100
150
|
var _a;
|
|
101
151
|
if (typeof window === "undefined") {
|
|
102
152
|
return;
|
|
@@ -107,18 +157,24 @@ var UniformScript = () => {
|
|
|
107
157
|
});
|
|
108
158
|
return instance;
|
|
109
159
|
}, []);
|
|
110
|
-
|
|
160
|
+
useEffect6(() => {
|
|
111
161
|
if (!channel) {
|
|
112
162
|
return;
|
|
113
163
|
}
|
|
114
164
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
115
|
-
|
|
165
|
+
const el = document.activeElement;
|
|
166
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
167
|
+
if (!isActiveElementEditable) {
|
|
168
|
+
router.refresh();
|
|
169
|
+
} else {
|
|
170
|
+
needsToRefreshRef.current = true;
|
|
171
|
+
}
|
|
116
172
|
});
|
|
117
173
|
return () => {
|
|
118
174
|
unsubscribeFromEditorUpdates();
|
|
119
175
|
};
|
|
120
176
|
}, [channel, router]);
|
|
121
|
-
|
|
177
|
+
useEffect6(() => {
|
|
122
178
|
if (typeof window === "undefined") {
|
|
123
179
|
return;
|
|
124
180
|
}
|
|
@@ -139,14 +195,26 @@ var UniformScript = () => {
|
|
|
139
195
|
existing.remove();
|
|
140
196
|
}
|
|
141
197
|
}, [enabled]);
|
|
142
|
-
|
|
198
|
+
useEffect6(() => {
|
|
199
|
+
const handleBlurChange = () => {
|
|
200
|
+
if (needsToRefreshRef.current) {
|
|
201
|
+
router.refresh();
|
|
202
|
+
needsToRefreshRef.current = false;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
206
|
+
return () => {
|
|
207
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
208
|
+
};
|
|
209
|
+
}, [router]);
|
|
210
|
+
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
143
211
|
};
|
|
144
212
|
|
|
145
213
|
// src/hooks/useInitUniformContext.ts
|
|
146
|
-
import { useEffect as
|
|
214
|
+
import { useEffect as useEffect7, useState as useState5 } from "react";
|
|
147
215
|
var useInitUniformContext = (callback) => {
|
|
148
|
-
const [called, setCalled] =
|
|
149
|
-
|
|
216
|
+
const [called, setCalled] = useState5(false);
|
|
217
|
+
useEffect7(() => {
|
|
150
218
|
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
151
219
|
return;
|
|
152
220
|
}
|
|
@@ -157,6 +225,8 @@ var useInitUniformContext = (callback) => {
|
|
|
157
225
|
}, [called, callback]);
|
|
158
226
|
};
|
|
159
227
|
export {
|
|
228
|
+
ClientContextUpdate,
|
|
229
|
+
ClientContextualEditingComponentWrapper,
|
|
160
230
|
ContextUpdateTransferClient,
|
|
161
231
|
PersonalizeClient,
|
|
162
232
|
TestClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc-client",
|
|
3
|
-
"version": "19.55.2-alpha.
|
|
3
|
+
"version": "19.55.2-alpha.54+5c0508742",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"react-dom": "18.2.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@uniformdev/canvas": "19.55.2-alpha.
|
|
36
|
-
"@uniformdev/canvas-next-rsc-shared": "^19.55.2-alpha.
|
|
35
|
+
"@uniformdev/canvas": "19.55.2-alpha.54+5c0508742",
|
|
36
|
+
"@uniformdev/canvas-next-rsc-shared": "^19.55.2-alpha.54+5c0508742",
|
|
37
|
+
"@uniformdev/canvas-react": "^19.55.2-alpha.54+5c0508742"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
40
|
"node": ">=16.14.0"
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5c0508742475c257e8e24003c4515dd06252045b"
|
|
50
51
|
}
|