@uniformdev/canvas-next-rsc-client 19.55.2-alpha.52 → 19.55.2-alpha.57
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.esm.js +65 -25
- package/dist/index.js +74 -32
- package/dist/index.mjs +65 -25
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { ManifestV2, ContextOptions } from '@uniformdev/context';
|
|
1
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
3
|
import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { PropsWithChildren } from 'react';
|
|
6
|
+
import * as _uniformdev_canvas_next_rsc_shared from '@uniformdev/canvas-next-rsc-shared';
|
|
5
7
|
import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
6
8
|
|
|
9
|
+
type ClientContextComponent = (props: {
|
|
10
|
+
manifest: ManifestV2;
|
|
11
|
+
}) => JSX.Element | null;
|
|
12
|
+
|
|
7
13
|
declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
|
|
8
14
|
|
|
9
15
|
declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
|
|
@@ -13,6 +19,8 @@ declare const ContextUpdateTransferClient: ({ update, ts, }: {
|
|
|
13
19
|
ts: number;
|
|
14
20
|
}) => null;
|
|
15
21
|
|
|
22
|
+
declare const DefaultUniformClientContext: ClientContextComponent;
|
|
23
|
+
|
|
16
24
|
type PersonalizeClientProps = PersonalizeProps & {
|
|
17
25
|
indexes: number[];
|
|
18
26
|
};
|
|
@@ -26,6 +34,9 @@ declare const TestClient: (props: ComponentProps<TestProps>) => react.FunctionCo
|
|
|
26
34
|
|
|
27
35
|
declare const UniformScript: () => react_jsx_runtime.JSX.Element;
|
|
28
36
|
|
|
37
|
+
type CreateClientUniformContextOptions = Omit<ContextOptions, 'transitionStore'>;
|
|
38
|
+
declare const createClientUniformContext: (options: CreateClientUniformContextOptions) => _uniformdev_canvas_next_rsc_shared.AppDirectoryContext;
|
|
39
|
+
|
|
29
40
|
declare const useInitUniformContext: (callback: () => AppDirectoryContext) => void;
|
|
30
41
|
|
|
31
42
|
declare global {
|
|
@@ -37,4 +48,4 @@ declare const useUniformContext: () => {
|
|
|
37
48
|
context: AppDirectoryContext | undefined;
|
|
38
49
|
};
|
|
39
50
|
|
|
40
|
-
export { ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
|
51
|
+
export { ClientContextComponent, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { ManifestV2, ContextOptions } from '@uniformdev/context';
|
|
1
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
3
|
import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { PropsWithChildren } from 'react';
|
|
6
|
+
import * as _uniformdev_canvas_next_rsc_shared from '@uniformdev/canvas-next-rsc-shared';
|
|
5
7
|
import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
6
8
|
|
|
9
|
+
type ClientContextComponent = (props: {
|
|
10
|
+
manifest: ManifestV2;
|
|
11
|
+
}) => JSX.Element | null;
|
|
12
|
+
|
|
7
13
|
declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
|
|
8
14
|
|
|
9
15
|
declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
|
|
@@ -13,6 +19,8 @@ declare const ContextUpdateTransferClient: ({ update, ts, }: {
|
|
|
13
19
|
ts: number;
|
|
14
20
|
}) => null;
|
|
15
21
|
|
|
22
|
+
declare const DefaultUniformClientContext: ClientContextComponent;
|
|
23
|
+
|
|
16
24
|
type PersonalizeClientProps = PersonalizeProps & {
|
|
17
25
|
indexes: number[];
|
|
18
26
|
};
|
|
@@ -26,6 +34,9 @@ declare const TestClient: (props: ComponentProps<TestProps>) => react.FunctionCo
|
|
|
26
34
|
|
|
27
35
|
declare const UniformScript: () => react_jsx_runtime.JSX.Element;
|
|
28
36
|
|
|
37
|
+
type CreateClientUniformContextOptions = Omit<ContextOptions, 'transitionStore'>;
|
|
38
|
+
declare const createClientUniformContext: (options: CreateClientUniformContextOptions) => _uniformdev_canvas_next_rsc_shared.AppDirectoryContext;
|
|
39
|
+
|
|
29
40
|
declare const useInitUniformContext: (callback: () => AppDirectoryContext) => void;
|
|
30
41
|
|
|
31
42
|
declare global {
|
|
@@ -37,4 +48,4 @@ declare const useUniformContext: () => {
|
|
|
37
48
|
context: AppDirectoryContext | undefined;
|
|
38
49
|
};
|
|
39
50
|
|
|
40
|
-
export { ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, useInitUniformContext, useUniformContext };
|
|
51
|
+
export { ClientContextComponent, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
|
package/dist/index.esm.js
CHANGED
|
@@ -88,15 +88,49 @@ var ContextUpdateTransferClient = ({
|
|
|
88
88
|
return null;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
// src/context/createClientUniformContext.ts
|
|
92
|
+
import { createUniformContext } from "@uniformdev/canvas-next-rsc-shared";
|
|
93
|
+
var createClientUniformContext = (options) => {
|
|
94
|
+
return createUniformContext({
|
|
95
|
+
...options,
|
|
96
|
+
serverCookieValue: void 0
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/hooks/useInitUniformContext.ts
|
|
101
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
102
|
+
var useInitUniformContext = (callback) => {
|
|
103
|
+
const [called, setCalled] = useState3(false);
|
|
104
|
+
useEffect4(() => {
|
|
105
|
+
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
window.__UNIFORM_CONTEXT__ = callback();
|
|
109
|
+
setCalled(true);
|
|
110
|
+
const event = new Event("uniform.context.loaded");
|
|
111
|
+
window.dispatchEvent(event);
|
|
112
|
+
}, [called, callback]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/components/DefaultUniformClientContext.tsx
|
|
116
|
+
var DefaultUniformClientContext = ({ manifest }) => {
|
|
117
|
+
useInitUniformContext(() => {
|
|
118
|
+
return createClientUniformContext({
|
|
119
|
+
manifest
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
|
|
91
125
|
// src/components/PersonalizeClient.ts
|
|
92
126
|
import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
93
127
|
import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
|
|
94
|
-
import { createElement, Fragment as Fragment3, useEffect as
|
|
128
|
+
import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
|
|
95
129
|
var PersonalizeClient = (props) => {
|
|
96
130
|
const { slots } = props;
|
|
97
131
|
const { context } = useUniformContext();
|
|
98
|
-
const [indexesToShow, setIndexesToShow] =
|
|
99
|
-
|
|
132
|
+
const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
|
|
133
|
+
useEffect5(() => {
|
|
100
134
|
const result = runPersonalization({
|
|
101
135
|
...props,
|
|
102
136
|
contextInstance: context
|
|
@@ -113,13 +147,13 @@ var PersonalizeClient = (props) => {
|
|
|
113
147
|
// src/components/TestClient.ts
|
|
114
148
|
import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
|
|
115
149
|
import { runTest } from "@uniformdev/canvas-next-rsc-shared";
|
|
116
|
-
import { createElement as createElement2, Fragment as Fragment4, useEffect as
|
|
150
|
+
import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
|
|
117
151
|
var TestClient = (props) => {
|
|
118
152
|
var _a;
|
|
119
153
|
const { slots } = props;
|
|
120
154
|
const { context } = useUniformContext();
|
|
121
|
-
const [index, setIndex] =
|
|
122
|
-
|
|
155
|
+
const [index, setIndex] = useState5(0);
|
|
156
|
+
useEffect6(() => {
|
|
123
157
|
const result = runTest({
|
|
124
158
|
...props,
|
|
125
159
|
contextInstance: context
|
|
@@ -139,11 +173,12 @@ import {
|
|
|
139
173
|
isAllowedReferrer
|
|
140
174
|
} from "@uniformdev/canvas";
|
|
141
175
|
import { useRouter, useSearchParams as useSearchParams3 } from "next/navigation";
|
|
142
|
-
import { useEffect as
|
|
176
|
+
import { useEffect as useEffect7, useMemo, useRef } from "react";
|
|
143
177
|
import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
|
|
144
178
|
var UniformScript = () => {
|
|
145
179
|
const router = useRouter();
|
|
146
180
|
const params = useSearchParams3();
|
|
181
|
+
const needsToRefreshRef = useRef(false);
|
|
147
182
|
const enabled = params.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2) === "true";
|
|
148
183
|
const channel = useMemo(() => {
|
|
149
184
|
var _a;
|
|
@@ -156,18 +191,24 @@ var UniformScript = () => {
|
|
|
156
191
|
});
|
|
157
192
|
return instance;
|
|
158
193
|
}, []);
|
|
159
|
-
|
|
194
|
+
useEffect7(() => {
|
|
160
195
|
if (!channel) {
|
|
161
196
|
return;
|
|
162
197
|
}
|
|
163
198
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
164
|
-
|
|
199
|
+
const el = document.activeElement;
|
|
200
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
201
|
+
if (!isActiveElementEditable) {
|
|
202
|
+
router.refresh();
|
|
203
|
+
} else {
|
|
204
|
+
needsToRefreshRef.current = true;
|
|
205
|
+
}
|
|
165
206
|
});
|
|
166
207
|
return () => {
|
|
167
208
|
unsubscribeFromEditorUpdates();
|
|
168
209
|
};
|
|
169
210
|
}, [channel, router]);
|
|
170
|
-
|
|
211
|
+
useEffect7(() => {
|
|
171
212
|
if (typeof window === "undefined") {
|
|
172
213
|
return;
|
|
173
214
|
}
|
|
@@ -188,30 +229,29 @@ var UniformScript = () => {
|
|
|
188
229
|
existing.remove();
|
|
189
230
|
}
|
|
190
231
|
}, [enabled]);
|
|
191
|
-
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/hooks/useInitUniformContext.ts
|
|
195
|
-
import { useEffect as useEffect7, useState as useState5 } from "react";
|
|
196
|
-
var useInitUniformContext = (callback) => {
|
|
197
|
-
const [called, setCalled] = useState5(false);
|
|
198
232
|
useEffect7(() => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
const handleBlurChange = () => {
|
|
234
|
+
if (needsToRefreshRef.current) {
|
|
235
|
+
router.refresh();
|
|
236
|
+
needsToRefreshRef.current = false;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
240
|
+
return () => {
|
|
241
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
242
|
+
};
|
|
243
|
+
}, [router]);
|
|
244
|
+
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
207
245
|
};
|
|
208
246
|
export {
|
|
209
247
|
ClientContextUpdate,
|
|
210
248
|
ClientContextualEditingComponentWrapper,
|
|
211
249
|
ContextUpdateTransferClient,
|
|
250
|
+
DefaultUniformClientContext,
|
|
212
251
|
PersonalizeClient,
|
|
213
252
|
TestClient,
|
|
214
253
|
UniformScript,
|
|
254
|
+
createClientUniformContext,
|
|
215
255
|
useInitUniformContext,
|
|
216
256
|
useUniformContext
|
|
217
257
|
};
|
package/dist/index.js
CHANGED
|
@@ -24,9 +24,11 @@ __export(src_exports, {
|
|
|
24
24
|
ClientContextUpdate: () => ClientContextUpdate,
|
|
25
25
|
ClientContextualEditingComponentWrapper: () => ClientContextualEditingComponentWrapper,
|
|
26
26
|
ContextUpdateTransferClient: () => ContextUpdateTransferClient,
|
|
27
|
+
DefaultUniformClientContext: () => DefaultUniformClientContext,
|
|
27
28
|
PersonalizeClient: () => PersonalizeClient,
|
|
28
29
|
TestClient: () => TestClient,
|
|
29
30
|
UniformScript: () => UniformScript,
|
|
31
|
+
createClientUniformContext: () => createClientUniformContext,
|
|
30
32
|
useInitUniformContext: () => useInitUniformContext,
|
|
31
33
|
useUniformContext: () => useUniformContext
|
|
32
34
|
});
|
|
@@ -118,16 +120,50 @@ var ContextUpdateTransferClient = ({
|
|
|
118
120
|
return null;
|
|
119
121
|
};
|
|
120
122
|
|
|
121
|
-
// src/
|
|
122
|
-
var import_canvas2 = require("@uniformdev/canvas");
|
|
123
|
+
// src/context/createClientUniformContext.ts
|
|
123
124
|
var import_canvas_next_rsc_shared = require("@uniformdev/canvas-next-rsc-shared");
|
|
125
|
+
var createClientUniformContext = (options) => {
|
|
126
|
+
return (0, import_canvas_next_rsc_shared.createUniformContext)({
|
|
127
|
+
...options,
|
|
128
|
+
serverCookieValue: void 0
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/hooks/useInitUniformContext.ts
|
|
124
133
|
var import_react5 = require("react");
|
|
134
|
+
var useInitUniformContext = (callback) => {
|
|
135
|
+
const [called, setCalled] = (0, import_react5.useState)(false);
|
|
136
|
+
(0, import_react5.useEffect)(() => {
|
|
137
|
+
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
window.__UNIFORM_CONTEXT__ = callback();
|
|
141
|
+
setCalled(true);
|
|
142
|
+
const event = new Event("uniform.context.loaded");
|
|
143
|
+
window.dispatchEvent(event);
|
|
144
|
+
}, [called, callback]);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/components/DefaultUniformClientContext.tsx
|
|
148
|
+
var DefaultUniformClientContext = ({ manifest }) => {
|
|
149
|
+
useInitUniformContext(() => {
|
|
150
|
+
return createClientUniformContext({
|
|
151
|
+
manifest
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return null;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/components/PersonalizeClient.ts
|
|
158
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
159
|
+
var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
|
|
160
|
+
var import_react6 = require("react");
|
|
125
161
|
var PersonalizeClient = (props) => {
|
|
126
162
|
const { slots } = props;
|
|
127
163
|
const { context } = useUniformContext();
|
|
128
|
-
const [indexesToShow, setIndexesToShow] = (0,
|
|
129
|
-
(0,
|
|
130
|
-
const result = (0,
|
|
164
|
+
const [indexesToShow, setIndexesToShow] = (0, import_react6.useState)(props.indexes);
|
|
165
|
+
(0, import_react6.useEffect)(() => {
|
|
166
|
+
const result = (0, import_canvas_next_rsc_shared2.runPersonalization)({
|
|
131
167
|
...props,
|
|
132
168
|
contextInstance: context
|
|
133
169
|
});
|
|
@@ -137,20 +173,20 @@ var PersonalizeClient = (props) => {
|
|
|
137
173
|
var _a;
|
|
138
174
|
return (_a = slots[import_canvas2.CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
|
|
139
175
|
});
|
|
140
|
-
return (0,
|
|
176
|
+
return (0, import_react6.createElement)(import_react6.Fragment, void 0, slotsToShow);
|
|
141
177
|
};
|
|
142
178
|
|
|
143
179
|
// src/components/TestClient.ts
|
|
144
180
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
145
|
-
var
|
|
146
|
-
var
|
|
181
|
+
var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
|
|
182
|
+
var import_react7 = require("react");
|
|
147
183
|
var TestClient = (props) => {
|
|
148
184
|
var _a;
|
|
149
185
|
const { slots } = props;
|
|
150
186
|
const { context } = useUniformContext();
|
|
151
|
-
const [index, setIndex] = (0,
|
|
152
|
-
(0,
|
|
153
|
-
const result = (0,
|
|
187
|
+
const [index, setIndex] = (0, import_react7.useState)(0);
|
|
188
|
+
(0, import_react7.useEffect)(() => {
|
|
189
|
+
const result = (0, import_canvas_next_rsc_shared3.runTest)({
|
|
154
190
|
...props,
|
|
155
191
|
contextInstance: context
|
|
156
192
|
});
|
|
@@ -159,19 +195,20 @@ var TestClient = (props) => {
|
|
|
159
195
|
if (typeof index !== "number") {
|
|
160
196
|
return null;
|
|
161
197
|
}
|
|
162
|
-
return (0,
|
|
198
|
+
return (0, import_react7.createElement)(import_react7.Fragment, void 0, (_a = slots == null ? void 0 : slots[import_canvas3.CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
|
|
163
199
|
};
|
|
164
200
|
|
|
165
201
|
// src/components/UniformScriptClient.tsx
|
|
166
202
|
var import_canvas4 = require("@uniformdev/canvas");
|
|
167
203
|
var import_navigation3 = require("next/navigation");
|
|
168
|
-
var
|
|
204
|
+
var import_react8 = require("react");
|
|
169
205
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
170
206
|
var UniformScript = () => {
|
|
171
207
|
const router = (0, import_navigation3.useRouter)();
|
|
172
208
|
const params = (0, import_navigation3.useSearchParams)();
|
|
209
|
+
const needsToRefreshRef = (0, import_react8.useRef)(false);
|
|
173
210
|
const enabled = params.get(import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
|
|
174
|
-
const channel = (0,
|
|
211
|
+
const channel = (0, import_react8.useMemo)(() => {
|
|
175
212
|
var _a;
|
|
176
213
|
if (typeof window === "undefined") {
|
|
177
214
|
return;
|
|
@@ -182,18 +219,24 @@ var UniformScript = () => {
|
|
|
182
219
|
});
|
|
183
220
|
return instance;
|
|
184
221
|
}, []);
|
|
185
|
-
(0,
|
|
222
|
+
(0, import_react8.useEffect)(() => {
|
|
186
223
|
if (!channel) {
|
|
187
224
|
return;
|
|
188
225
|
}
|
|
189
226
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
190
|
-
|
|
227
|
+
const el = document.activeElement;
|
|
228
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
229
|
+
if (!isActiveElementEditable) {
|
|
230
|
+
router.refresh();
|
|
231
|
+
} else {
|
|
232
|
+
needsToRefreshRef.current = true;
|
|
233
|
+
}
|
|
191
234
|
});
|
|
192
235
|
return () => {
|
|
193
236
|
unsubscribeFromEditorUpdates();
|
|
194
237
|
};
|
|
195
238
|
}, [channel, router]);
|
|
196
|
-
(0,
|
|
239
|
+
(0, import_react8.useEffect)(() => {
|
|
197
240
|
if (typeof window === "undefined") {
|
|
198
241
|
return;
|
|
199
242
|
}
|
|
@@ -214,31 +257,30 @@ var UniformScript = () => {
|
|
|
214
257
|
existing.remove();
|
|
215
258
|
}
|
|
216
259
|
}, [enabled]);
|
|
217
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {});
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// src/hooks/useInitUniformContext.ts
|
|
221
|
-
var import_react8 = require("react");
|
|
222
|
-
var useInitUniformContext = (callback) => {
|
|
223
|
-
const [called, setCalled] = (0, import_react8.useState)(false);
|
|
224
260
|
(0, import_react8.useEffect)(() => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
261
|
+
const handleBlurChange = () => {
|
|
262
|
+
if (needsToRefreshRef.current) {
|
|
263
|
+
router.refresh();
|
|
264
|
+
needsToRefreshRef.current = false;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
268
|
+
return () => {
|
|
269
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
270
|
+
};
|
|
271
|
+
}, [router]);
|
|
272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {});
|
|
233
273
|
};
|
|
234
274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
235
275
|
0 && (module.exports = {
|
|
236
276
|
ClientContextUpdate,
|
|
237
277
|
ClientContextualEditingComponentWrapper,
|
|
238
278
|
ContextUpdateTransferClient,
|
|
279
|
+
DefaultUniformClientContext,
|
|
239
280
|
PersonalizeClient,
|
|
240
281
|
TestClient,
|
|
241
282
|
UniformScript,
|
|
283
|
+
createClientUniformContext,
|
|
242
284
|
useInitUniformContext,
|
|
243
285
|
useUniformContext
|
|
244
286
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -88,15 +88,49 @@ var ContextUpdateTransferClient = ({
|
|
|
88
88
|
return null;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
// src/context/createClientUniformContext.ts
|
|
92
|
+
import { createUniformContext } from "@uniformdev/canvas-next-rsc-shared";
|
|
93
|
+
var createClientUniformContext = (options) => {
|
|
94
|
+
return createUniformContext({
|
|
95
|
+
...options,
|
|
96
|
+
serverCookieValue: void 0
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/hooks/useInitUniformContext.ts
|
|
101
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
102
|
+
var useInitUniformContext = (callback) => {
|
|
103
|
+
const [called, setCalled] = useState3(false);
|
|
104
|
+
useEffect4(() => {
|
|
105
|
+
if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
window.__UNIFORM_CONTEXT__ = callback();
|
|
109
|
+
setCalled(true);
|
|
110
|
+
const event = new Event("uniform.context.loaded");
|
|
111
|
+
window.dispatchEvent(event);
|
|
112
|
+
}, [called, callback]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/components/DefaultUniformClientContext.tsx
|
|
116
|
+
var DefaultUniformClientContext = ({ manifest }) => {
|
|
117
|
+
useInitUniformContext(() => {
|
|
118
|
+
return createClientUniformContext({
|
|
119
|
+
manifest
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
|
|
91
125
|
// src/components/PersonalizeClient.ts
|
|
92
126
|
import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
93
127
|
import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
|
|
94
|
-
import { createElement, Fragment as Fragment3, useEffect as
|
|
128
|
+
import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
|
|
95
129
|
var PersonalizeClient = (props) => {
|
|
96
130
|
const { slots } = props;
|
|
97
131
|
const { context } = useUniformContext();
|
|
98
|
-
const [indexesToShow, setIndexesToShow] =
|
|
99
|
-
|
|
132
|
+
const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
|
|
133
|
+
useEffect5(() => {
|
|
100
134
|
const result = runPersonalization({
|
|
101
135
|
...props,
|
|
102
136
|
contextInstance: context
|
|
@@ -113,13 +147,13 @@ var PersonalizeClient = (props) => {
|
|
|
113
147
|
// src/components/TestClient.ts
|
|
114
148
|
import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
|
|
115
149
|
import { runTest } from "@uniformdev/canvas-next-rsc-shared";
|
|
116
|
-
import { createElement as createElement2, Fragment as Fragment4, useEffect as
|
|
150
|
+
import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
|
|
117
151
|
var TestClient = (props) => {
|
|
118
152
|
var _a;
|
|
119
153
|
const { slots } = props;
|
|
120
154
|
const { context } = useUniformContext();
|
|
121
|
-
const [index, setIndex] =
|
|
122
|
-
|
|
155
|
+
const [index, setIndex] = useState5(0);
|
|
156
|
+
useEffect6(() => {
|
|
123
157
|
const result = runTest({
|
|
124
158
|
...props,
|
|
125
159
|
contextInstance: context
|
|
@@ -139,11 +173,12 @@ import {
|
|
|
139
173
|
isAllowedReferrer
|
|
140
174
|
} from "@uniformdev/canvas";
|
|
141
175
|
import { useRouter, useSearchParams as useSearchParams3 } from "next/navigation";
|
|
142
|
-
import { useEffect as
|
|
176
|
+
import { useEffect as useEffect7, useMemo, useRef } from "react";
|
|
143
177
|
import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
|
|
144
178
|
var UniformScript = () => {
|
|
145
179
|
const router = useRouter();
|
|
146
180
|
const params = useSearchParams3();
|
|
181
|
+
const needsToRefreshRef = useRef(false);
|
|
147
182
|
const enabled = params.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2) === "true";
|
|
148
183
|
const channel = useMemo(() => {
|
|
149
184
|
var _a;
|
|
@@ -156,18 +191,24 @@ var UniformScript = () => {
|
|
|
156
191
|
});
|
|
157
192
|
return instance;
|
|
158
193
|
}, []);
|
|
159
|
-
|
|
194
|
+
useEffect7(() => {
|
|
160
195
|
if (!channel) {
|
|
161
196
|
return;
|
|
162
197
|
}
|
|
163
198
|
const unsubscribeFromEditorUpdates = channel.on("editor-state-updated", () => {
|
|
164
|
-
|
|
199
|
+
const el = document.activeElement;
|
|
200
|
+
const isActiveElementEditable = el == null ? void 0 : el.isContentEditable;
|
|
201
|
+
if (!isActiveElementEditable) {
|
|
202
|
+
router.refresh();
|
|
203
|
+
} else {
|
|
204
|
+
needsToRefreshRef.current = true;
|
|
205
|
+
}
|
|
165
206
|
});
|
|
166
207
|
return () => {
|
|
167
208
|
unsubscribeFromEditorUpdates();
|
|
168
209
|
};
|
|
169
210
|
}, [channel, router]);
|
|
170
|
-
|
|
211
|
+
useEffect7(() => {
|
|
171
212
|
if (typeof window === "undefined") {
|
|
172
213
|
return;
|
|
173
214
|
}
|
|
@@ -188,30 +229,29 @@ var UniformScript = () => {
|
|
|
188
229
|
existing.remove();
|
|
189
230
|
}
|
|
190
231
|
}, [enabled]);
|
|
191
|
-
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/hooks/useInitUniformContext.ts
|
|
195
|
-
import { useEffect as useEffect7, useState as useState5 } from "react";
|
|
196
|
-
var useInitUniformContext = (callback) => {
|
|
197
|
-
const [called, setCalled] = useState5(false);
|
|
198
232
|
useEffect7(() => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
const handleBlurChange = () => {
|
|
234
|
+
if (needsToRefreshRef.current) {
|
|
235
|
+
router.refresh();
|
|
236
|
+
needsToRefreshRef.current = false;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
document.addEventListener("blur", handleBlurChange, true);
|
|
240
|
+
return () => {
|
|
241
|
+
document.removeEventListener("focus", handleBlurChange, true);
|
|
242
|
+
};
|
|
243
|
+
}, [router]);
|
|
244
|
+
return /* @__PURE__ */ jsx3(Fragment5, {});
|
|
207
245
|
};
|
|
208
246
|
export {
|
|
209
247
|
ClientContextUpdate,
|
|
210
248
|
ClientContextualEditingComponentWrapper,
|
|
211
249
|
ContextUpdateTransferClient,
|
|
250
|
+
DefaultUniformClientContext,
|
|
212
251
|
PersonalizeClient,
|
|
213
252
|
TestClient,
|
|
214
253
|
UniformScript,
|
|
254
|
+
createClientUniformContext,
|
|
215
255
|
useInitUniformContext,
|
|
216
256
|
useUniformContext
|
|
217
257
|
};
|
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.57+ce05e047a",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -32,9 +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.
|
|
37
|
-
"@uniformdev/canvas-react": "^19.55.2-alpha.
|
|
35
|
+
"@uniformdev/canvas": "19.55.2-alpha.57+ce05e047a",
|
|
36
|
+
"@uniformdev/canvas-next-rsc-shared": "^19.55.2-alpha.57+ce05e047a",
|
|
37
|
+
"@uniformdev/canvas-react": "^19.55.2-alpha.57+ce05e047a"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=16.14.0"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ce05e047a1116e4b1edeb495b1d0a3943bbe9833"
|
|
51
51
|
}
|