@uniformdev/canvas-react 18.0.1-alpha.7 → 18.1.2-alpha.4
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.ts +105 -62
- package/dist/index.esm.js +171 -149
- package/dist/index.js +183 -159
- package/dist/index.mjs +171 -149
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,42 @@
|
|
|
1
|
-
// src/components/
|
|
2
|
-
import {
|
|
1
|
+
// src/components/DefaultNotImplementedComponent.tsx
|
|
2
|
+
import { CANVAS_LOCALIZATION_TYPE } from "@uniformdev/canvas";
|
|
3
|
+
import React from "react";
|
|
4
|
+
var wrapperStyles = {
|
|
5
|
+
borderLeft: "4px solid #e42535",
|
|
6
|
+
padding: "16px",
|
|
7
|
+
fontSize: "16px",
|
|
8
|
+
borderRadius: "0 8px 8px 0",
|
|
9
|
+
margin: "8px",
|
|
10
|
+
backgroundColor: "rgba(255, 255, 255, 0.45)",
|
|
11
|
+
color: "#1d3557"
|
|
12
|
+
};
|
|
13
|
+
function DefaultNotImplementedComponent(props) {
|
|
14
|
+
var _a;
|
|
15
|
+
const componentType = (_a = props.component) == null ? void 0 : _a.type;
|
|
16
|
+
if (!componentType) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (componentType === CANVAS_LOCALIZATION_TYPE) {
|
|
20
|
+
return /* @__PURE__ */ React.createElement("div", { style: wrapperStyles }, /* @__PURE__ */ React.createElement("p", null, "Seems like localization is not enabled in your application. Please read our documentation on how to", " ", /* @__PURE__ */ React.createElement(
|
|
21
|
+
"a",
|
|
22
|
+
{
|
|
23
|
+
href: "https://docs.uniform.app/guides/composition/localization#activate-front-end",
|
|
24
|
+
target: "_blank",
|
|
25
|
+
style: { fontWeight: "bolder", textDecoration: "underline" },
|
|
26
|
+
rel: "noreferrer"
|
|
27
|
+
},
|
|
28
|
+
"enable localization in your front-end application."
|
|
29
|
+
)));
|
|
30
|
+
}
|
|
31
|
+
return /* @__PURE__ */ React.createElement("div", { style: wrapperStyles }, /* @__PURE__ */ React.createElement("h2", null, "Component: ", /* @__PURE__ */ React.createElement("code", null, componentType)), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("code", null, /* @__PURE__ */ React.createElement("strong", null, componentType)), " ", "has no React implementation. It may need to be added to your ", /* @__PURE__ */ React.createElement("code", null, "resolveRenderer()"), " function."), /* @__PURE__ */ React.createElement("details", null, /* @__PURE__ */ React.createElement("summary", { style: { cursor: "pointer" } }, "Props"), /* @__PURE__ */ React.createElement("pre", null, JSON.stringify(props, null, 2))));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/components/UniformComponent.tsx
|
|
35
|
+
import {
|
|
36
|
+
CANVAS_ENRICHMENT_TAG_PARAM
|
|
37
|
+
} from "@uniformdev/canvas";
|
|
3
38
|
import { Track, TrackFragment, useUniformContext } from "@uniformdev/context-react";
|
|
4
|
-
import
|
|
39
|
+
import React4, { createContext, useContext } from "react";
|
|
5
40
|
|
|
6
41
|
// src/convertComponentToProps.ts
|
|
7
42
|
function convertComponentToProps(component) {
|
|
@@ -61,7 +96,7 @@ var componentStoreResolver = createComponentStoreResolver({
|
|
|
61
96
|
store: componentStore
|
|
62
97
|
});
|
|
63
98
|
|
|
64
|
-
// src/components/
|
|
99
|
+
// src/components/UniformSlot.tsx
|
|
65
100
|
import {
|
|
66
101
|
CANVAS_LOCALE_TAG_PARAM,
|
|
67
102
|
CANVAS_PERSONALIZE_TYPE,
|
|
@@ -69,7 +104,7 @@ import {
|
|
|
69
104
|
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
70
105
|
PLACEHOLDER_ID
|
|
71
106
|
} from "@uniformdev/canvas";
|
|
72
|
-
import
|
|
107
|
+
import React3 from "react";
|
|
73
108
|
|
|
74
109
|
// src/defaultSystemComponentResolver.tsx
|
|
75
110
|
import {
|
|
@@ -77,7 +112,7 @@ import {
|
|
|
77
112
|
mapSlotToTestVariations
|
|
78
113
|
} from "@uniformdev/canvas";
|
|
79
114
|
import { Personalize, Test } from "@uniformdev/context-react";
|
|
80
|
-
import * as
|
|
115
|
+
import * as React2 from "react";
|
|
81
116
|
var defaultSystemComponentResolver = {
|
|
82
117
|
test: (component, key, renderChild) => {
|
|
83
118
|
var _a, _b, _c, _d, _e;
|
|
@@ -85,7 +120,7 @@ var defaultSystemComponentResolver = {
|
|
|
85
120
|
const variants = (_b = (_a = testComponent.slots) == null ? void 0 : _a.test) != null ? _b : [];
|
|
86
121
|
const testName = (_e = (_d = (_c = testComponent.parameters) == null ? void 0 : _c.test) == null ? void 0 : _d.value) != null ? _e : "Untitled Test";
|
|
87
122
|
const finalVariants = mapSlotToTestVariations(variants);
|
|
88
|
-
return /* @__PURE__ */
|
|
123
|
+
return /* @__PURE__ */ React2.createElement(
|
|
89
124
|
Test,
|
|
90
125
|
{
|
|
91
126
|
key,
|
|
@@ -99,7 +134,7 @@ var defaultSystemComponentResolver = {
|
|
|
99
134
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
100
135
|
const pzComponent = component;
|
|
101
136
|
const processedVariants = mapSlotToPersonalizedVariations((_a = pzComponent == null ? void 0 : pzComponent.slots) == null ? void 0 : _a.pz);
|
|
102
|
-
return /* @__PURE__ */
|
|
137
|
+
return /* @__PURE__ */ React2.createElement(
|
|
103
138
|
Personalize,
|
|
104
139
|
{
|
|
105
140
|
key,
|
|
@@ -112,28 +147,24 @@ var defaultSystemComponentResolver = {
|
|
|
112
147
|
}
|
|
113
148
|
};
|
|
114
149
|
|
|
115
|
-
// src/components/
|
|
116
|
-
function
|
|
150
|
+
// src/components/UniformSlot.tsx
|
|
151
|
+
function UniformSlot({
|
|
117
152
|
name,
|
|
118
153
|
resolveRenderer,
|
|
119
154
|
children,
|
|
120
155
|
emptyPlaceholder
|
|
121
156
|
}) {
|
|
122
157
|
var _a;
|
|
123
|
-
const
|
|
124
|
-
if (!
|
|
125
|
-
throw new Error("Slot
|
|
126
|
-
}
|
|
127
|
-
const { composition: layout, resolveRenderer: parentResolveRenderer } = compositionContext;
|
|
128
|
-
if (!layout) {
|
|
129
|
-
throw new Error("Cannot use Slot without a Composition wrapper.");
|
|
158
|
+
const { data: parentData, resolveRenderer: parentResolveRenderer } = useUniformCurrentComponent();
|
|
159
|
+
if (!parentData) {
|
|
160
|
+
throw new Error("Cannot use Slot without a <UniformComponent /> wrapper.");
|
|
130
161
|
}
|
|
131
|
-
const slot = (_a =
|
|
162
|
+
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
132
163
|
if (!slot || !Array.isArray(slot)) {
|
|
133
164
|
if (process.env.NODE_ENV === "development") {
|
|
134
165
|
console.warn(
|
|
135
166
|
`[canvas-dev] slot '${name}' was rendered, but it was not defined on its component. This is expected if the slot is optional, otherwise it may indicate a typo. Component:`,
|
|
136
|
-
|
|
167
|
+
parentData
|
|
137
168
|
);
|
|
138
169
|
}
|
|
139
170
|
return null;
|
|
@@ -148,14 +179,14 @@ function Slot({
|
|
|
148
179
|
key: `inner-${index}`,
|
|
149
180
|
indexInSlot: index,
|
|
150
181
|
slotName: name,
|
|
151
|
-
parentComponent:
|
|
182
|
+
parentComponent: parentData,
|
|
152
183
|
slotChildrenCount: slot.length,
|
|
153
184
|
emptyPlaceholder
|
|
154
185
|
});
|
|
155
186
|
const elements = children ? children({ child, component, key: `wrapped-inner-${index}` }) : child;
|
|
156
|
-
return
|
|
187
|
+
return React3.createElement(React3.Fragment, { key: index }, elements);
|
|
157
188
|
});
|
|
158
|
-
return
|
|
189
|
+
return React3.createElement(React3.Fragment, void 0, finalChildren);
|
|
159
190
|
}
|
|
160
191
|
function renderComponent({
|
|
161
192
|
component,
|
|
@@ -186,7 +217,7 @@ function renderComponent({
|
|
|
186
217
|
const props = convertComponentToProps(component);
|
|
187
218
|
const shouldRenderContextualEditingTags = Boolean(component._id);
|
|
188
219
|
const isPlaceholder = component._id === PLACEHOLDER_ID;
|
|
189
|
-
return /* @__PURE__ */
|
|
220
|
+
return /* @__PURE__ */ React3.createElement(UniformComponent, { key, data: component, resolveRenderer }, !shouldRenderContextualEditingTags ? null : /* @__PURE__ */ React3.createElement(
|
|
190
221
|
"script",
|
|
191
222
|
{
|
|
192
223
|
key,
|
|
@@ -202,7 +233,7 @@ function renderComponent({
|
|
|
202
233
|
"data-is-localized": ((_a = component.parameters) == null ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
203
234
|
"data-component-title": (_d = (_c = (_b = component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : ""
|
|
204
235
|
}
|
|
205
|
-
), isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : /* @__PURE__ */
|
|
236
|
+
), isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : /* @__PURE__ */ React3.createElement(RenderComponent, { ...props }), !shouldRenderContextualEditingTags ? null : /* @__PURE__ */ React3.createElement("script", { "data-role": "component-end" }));
|
|
206
237
|
} else if (process.env.NODE_ENV !== "production") {
|
|
207
238
|
console.warn(
|
|
208
239
|
`[canvas] found component of type '${component.type}' which the resolveRenderer prop returned no component for. Nothing will be rendered. The resolveRenderer function may need to be extended to handle the new type.`,
|
|
@@ -211,44 +242,45 @@ function renderComponent({
|
|
|
211
242
|
}
|
|
212
243
|
return null;
|
|
213
244
|
}
|
|
245
|
+
var Slot = UniformSlot;
|
|
214
246
|
|
|
215
|
-
// src/components/
|
|
216
|
-
var
|
|
217
|
-
function
|
|
218
|
-
return useContext(
|
|
247
|
+
// src/components/UniformComponent.tsx
|
|
248
|
+
var UniformComponentContext = createContext({});
|
|
249
|
+
function useUniformCurrentComponent() {
|
|
250
|
+
return useContext(UniformComponentContext);
|
|
219
251
|
}
|
|
220
252
|
var componentStoreResolver2 = (component) => {
|
|
221
253
|
const resolved = componentStore.get(component.type);
|
|
222
254
|
return resolved || null;
|
|
223
255
|
};
|
|
224
|
-
function
|
|
256
|
+
function UniformComponent({
|
|
225
257
|
data,
|
|
226
258
|
resolveRenderer,
|
|
227
259
|
children,
|
|
228
260
|
behaviorTracking
|
|
229
261
|
}) {
|
|
230
262
|
var _a, _b, _c;
|
|
231
|
-
const
|
|
263
|
+
const parentData = useUniformCurrentComponent();
|
|
232
264
|
const contextContextProviderPresent = useUniformContext({ throwOnMissingProvider: false }) !== void 0;
|
|
233
265
|
if (!data) {
|
|
234
266
|
if (process.env.NODE_ENV === "development") {
|
|
235
|
-
console.warn(`[canvas-dev]
|
|
267
|
+
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
236
268
|
}
|
|
237
269
|
return null;
|
|
238
270
|
}
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
resolveRenderer: resolveRenderer || (
|
|
242
|
-
behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking :
|
|
271
|
+
const contextValue = {
|
|
272
|
+
data,
|
|
273
|
+
resolveRenderer: resolveRenderer || (parentData == null ? void 0 : parentData.resolveRenderer) || componentStoreResolver2,
|
|
274
|
+
behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView"
|
|
243
275
|
};
|
|
244
276
|
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
|
|
245
|
-
const TrackComponent =
|
|
277
|
+
const TrackComponent = contextValue.behaviorTracking === "onLoad" ? TrackFragment : Track;
|
|
246
278
|
const resolvedChildren = resolveChildren({
|
|
247
279
|
children,
|
|
248
280
|
data,
|
|
249
|
-
hasParentLayout: Boolean(
|
|
281
|
+
hasParentLayout: Boolean(parentData)
|
|
250
282
|
});
|
|
251
|
-
return /* @__PURE__ */
|
|
283
|
+
return /* @__PURE__ */ React4.createElement(UniformComponentContext.Provider, { value: contextValue }, contextContextProviderPresent ? /* @__PURE__ */ React4.createElement(TrackComponent, { behavior: enrichmentTags }, resolvedChildren) : resolvedChildren);
|
|
252
284
|
}
|
|
253
285
|
function resolveChildren({
|
|
254
286
|
children,
|
|
@@ -256,126 +288,38 @@ function resolveChildren({
|
|
|
256
288
|
hasParentLayout
|
|
257
289
|
}) {
|
|
258
290
|
var _a;
|
|
259
|
-
|
|
260
|
-
if (!compositionChildren && !hasParentLayout) {
|
|
291
|
+
if (!children && !hasParentLayout) {
|
|
261
292
|
const rootComponent = componentStore.get(data.type);
|
|
262
293
|
if (rootComponent) {
|
|
263
|
-
|
|
294
|
+
children = React4.createElement(rootComponent, convertComponentToProps(data));
|
|
264
295
|
} else {
|
|
265
296
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
266
297
|
console.warn(
|
|
267
298
|
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<Slot name={slotName} />' to reliably render the slots.`
|
|
268
299
|
);
|
|
269
300
|
}
|
|
270
|
-
|
|
301
|
+
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ React4.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
271
302
|
}
|
|
272
303
|
}
|
|
273
|
-
const renderChildren = typeof
|
|
304
|
+
const renderChildren = typeof children === "function" ? children(convertComponentToProps(data)) : children;
|
|
274
305
|
return renderChildren;
|
|
275
306
|
}
|
|
276
307
|
|
|
277
|
-
// src/components/
|
|
278
|
-
import {
|
|
279
|
-
import React4 from "react";
|
|
280
|
-
var wrapperStyles = {
|
|
281
|
-
borderLeft: "4px solid #e42535",
|
|
282
|
-
padding: "16px",
|
|
283
|
-
fontSize: "16px",
|
|
284
|
-
borderRadius: "0 8px 8px 0",
|
|
285
|
-
margin: "8px",
|
|
286
|
-
backgroundColor: "rgba(255, 255, 255, 0.45)",
|
|
287
|
-
color: "#1d3557"
|
|
288
|
-
};
|
|
289
|
-
function DefaultNotImplementedComponent(props) {
|
|
290
|
-
var _a;
|
|
291
|
-
const componentType = (_a = props.component) == null ? void 0 : _a.type;
|
|
292
|
-
if (!componentType) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
if (componentType === CANVAS_LOCALIZATION_TYPE) {
|
|
296
|
-
return /* @__PURE__ */ React4.createElement("div", { style: wrapperStyles }, /* @__PURE__ */ React4.createElement("p", null, "Seems like localization is not enabled in your application. Please read our documentation on how to", " ", /* @__PURE__ */ React4.createElement(
|
|
297
|
-
"a",
|
|
298
|
-
{
|
|
299
|
-
href: "https://docs.uniform.app/guides/composition/localization#activate-front-end",
|
|
300
|
-
target: "_blank",
|
|
301
|
-
style: { fontWeight: "bolder", textDecoration: "underline" },
|
|
302
|
-
rel: "noreferrer"
|
|
303
|
-
},
|
|
304
|
-
"enable localization in your front-end application."
|
|
305
|
-
)));
|
|
306
|
-
}
|
|
307
|
-
return /* @__PURE__ */ React4.createElement("div", { style: wrapperStyles }, /* @__PURE__ */ React4.createElement("h2", null, "Component: ", /* @__PURE__ */ React4.createElement("code", null, componentType)), /* @__PURE__ */ React4.createElement("p", null, /* @__PURE__ */ React4.createElement("code", null, /* @__PURE__ */ React4.createElement("strong", null, componentType)), " ", "has no React implementation. It may need to be added to your ", /* @__PURE__ */ React4.createElement("code", null, "resolveRenderer()"), " function."), /* @__PURE__ */ React4.createElement("details", null, /* @__PURE__ */ React4.createElement("summary", { style: { cursor: "pointer" } }, "Props"), /* @__PURE__ */ React4.createElement("pre", null, JSON.stringify(props, null, 2))));
|
|
308
|
-
}
|
|
308
|
+
// src/components/UniformComposition.tsx
|
|
309
|
+
import React5, { createContext as createContext2, useContext as useContext2 } from "react";
|
|
309
310
|
|
|
310
|
-
// src/hooks/
|
|
311
|
-
import {
|
|
312
|
-
CANVAS_DRAFT_STATE,
|
|
313
|
-
createEventBus,
|
|
314
|
-
subscribeToComposition
|
|
315
|
-
} from "@uniformdev/canvas";
|
|
316
|
-
import { useEffect } from "react";
|
|
317
|
-
function useCompositionEventEffect({
|
|
318
|
-
enabled,
|
|
319
|
-
projectId,
|
|
320
|
-
compositionId,
|
|
321
|
-
effect
|
|
322
|
-
}) {
|
|
323
|
-
useEffect(() => {
|
|
324
|
-
if (!enabled || !compositionId || !projectId) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
let goodbye = void 0;
|
|
328
|
-
const loadEffect = async () => {
|
|
329
|
-
const eventBus = await createEventBus();
|
|
330
|
-
if (eventBus) {
|
|
331
|
-
goodbye = subscribeToComposition({
|
|
332
|
-
eventBus,
|
|
333
|
-
compositionId,
|
|
334
|
-
compositionState: CANVAS_DRAFT_STATE,
|
|
335
|
-
projectId,
|
|
336
|
-
callback: effect,
|
|
337
|
-
event: "updated"
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
loadEffect();
|
|
342
|
-
return () => {
|
|
343
|
-
if (goodbye) {
|
|
344
|
-
goodbye();
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
}, [compositionId, enabled, projectId, effect]);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// src/hooks/useContextualEditing.ts
|
|
311
|
+
// src/hooks/useUniformContextualEditing.ts
|
|
351
312
|
import {
|
|
352
313
|
createCanvasChannel,
|
|
314
|
+
createUniformApiEnhancer,
|
|
315
|
+
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
353
316
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
354
317
|
isUpdateCompositionMessage
|
|
355
318
|
} from "@uniformdev/canvas";
|
|
356
|
-
import { useEffect
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
-
|
|
360
|
-
const response = await fetch(apiUrl, {
|
|
361
|
-
method: "post",
|
|
362
|
-
body: JSON.stringify({
|
|
363
|
-
composition: message.composition,
|
|
364
|
-
hash: message.hash
|
|
365
|
-
}),
|
|
366
|
-
headers: {
|
|
367
|
-
"Content-Type": "application/json"
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
const json = await response.json();
|
|
371
|
-
if (!response.ok) {
|
|
372
|
-
throw new Error("Error reading enhanced composition");
|
|
373
|
-
}
|
|
374
|
-
const body = json;
|
|
375
|
-
return body.composition;
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
|
-
var useContextualEditing = ({
|
|
319
|
+
import { useEffect, useMemo, useState } from "react";
|
|
320
|
+
var createApiEnhancer = createUniformApiEnhancer;
|
|
321
|
+
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
322
|
+
var useUniformContextualEditing = ({
|
|
379
323
|
initialCompositionValue,
|
|
380
324
|
enhance = (message) => message.composition
|
|
381
325
|
}) => {
|
|
@@ -391,30 +335,33 @@ var useContextualEditing = ({
|
|
|
391
335
|
});
|
|
392
336
|
return channel2;
|
|
393
337
|
}, []);
|
|
394
|
-
|
|
395
|
-
if (!channel) {
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
if (!channel || registeredCompositionIds.has(initialCompositionValue._id)) {
|
|
396
340
|
return;
|
|
397
341
|
}
|
|
398
342
|
const unsubscribe = channel.on("update-composition", async (message) => {
|
|
399
|
-
if (isUpdateCompositionMessage(message)) {
|
|
400
|
-
|
|
401
|
-
setContextualComposition(composition);
|
|
343
|
+
if (!isUpdateCompositionMessage(message)) {
|
|
344
|
+
return;
|
|
402
345
|
}
|
|
346
|
+
const enhancedComposition = await enhance(message);
|
|
347
|
+
setContextualComposition(enhancedComposition);
|
|
403
348
|
});
|
|
349
|
+
registeredCompositionIds.add(initialCompositionValue._id);
|
|
404
350
|
return () => {
|
|
405
351
|
unsubscribe();
|
|
352
|
+
registeredCompositionIds.delete(initialCompositionValue._id);
|
|
406
353
|
};
|
|
407
|
-
}, [channel, enhance]);
|
|
408
|
-
|
|
354
|
+
}, [channel, enhance, initialCompositionValue._id]);
|
|
355
|
+
useEffect(() => {
|
|
409
356
|
if (!isInContextEditingMode()) {
|
|
410
357
|
return;
|
|
411
358
|
}
|
|
412
|
-
const existingScript = document.getElementById(
|
|
359
|
+
const existingScript = document.getElementById(IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID);
|
|
413
360
|
if (existingScript) {
|
|
414
361
|
return;
|
|
415
362
|
}
|
|
416
363
|
const script = document.createElement("script");
|
|
417
|
-
script.id =
|
|
364
|
+
script.id = IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
418
365
|
script.src = getCanvasInContextEmbedScriptUrl();
|
|
419
366
|
script.async = true;
|
|
420
367
|
document.head.appendChild(script);
|
|
@@ -439,17 +386,92 @@ function isInContextEditingMode() {
|
|
|
439
386
|
);
|
|
440
387
|
return isOpenedByInContextEditor && isAllowlistedReferrer;
|
|
441
388
|
}
|
|
389
|
+
|
|
390
|
+
// src/components/UniformComposition.tsx
|
|
391
|
+
var UniformCompositionContext = createContext2({});
|
|
392
|
+
function useUniformCurrentComposition() {
|
|
393
|
+
return useContext2(UniformCompositionContext);
|
|
394
|
+
}
|
|
395
|
+
function UniformComposition({
|
|
396
|
+
data,
|
|
397
|
+
behaviorTracking = "onView",
|
|
398
|
+
children,
|
|
399
|
+
resolveRenderer,
|
|
400
|
+
contextualEditingEnhancer
|
|
401
|
+
}) {
|
|
402
|
+
const { composition } = useUniformContextualEditing({
|
|
403
|
+
initialCompositionValue: data,
|
|
404
|
+
enhance: contextualEditingEnhancer
|
|
405
|
+
});
|
|
406
|
+
return /* @__PURE__ */ React5.createElement(UniformCompositionContext.Provider, { value: { data: composition, behaviorTracking, resolveRenderer } }, /* @__PURE__ */ React5.createElement(
|
|
407
|
+
UniformComponent,
|
|
408
|
+
{
|
|
409
|
+
data: composition,
|
|
410
|
+
behaviorTracking,
|
|
411
|
+
resolveRenderer
|
|
412
|
+
},
|
|
413
|
+
children
|
|
414
|
+
));
|
|
415
|
+
}
|
|
416
|
+
var useComposition = useUniformCurrentComposition;
|
|
417
|
+
var Composition = UniformComposition;
|
|
418
|
+
|
|
419
|
+
// src/hooks/useCompositionEventEffect.ts
|
|
420
|
+
import {
|
|
421
|
+
CANVAS_DRAFT_STATE,
|
|
422
|
+
createEventBus,
|
|
423
|
+
subscribeToComposition
|
|
424
|
+
} from "@uniformdev/canvas";
|
|
425
|
+
import { useEffect as useEffect2 } from "react";
|
|
426
|
+
function useCompositionEventEffect({
|
|
427
|
+
enabled,
|
|
428
|
+
projectId,
|
|
429
|
+
compositionId,
|
|
430
|
+
effect
|
|
431
|
+
}) {
|
|
432
|
+
useEffect2(() => {
|
|
433
|
+
if (!enabled || !compositionId || !projectId) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
let goodbye = void 0;
|
|
437
|
+
const loadEffect = async () => {
|
|
438
|
+
const eventBus = await createEventBus();
|
|
439
|
+
if (eventBus) {
|
|
440
|
+
goodbye = subscribeToComposition({
|
|
441
|
+
eventBus,
|
|
442
|
+
compositionId,
|
|
443
|
+
compositionState: CANVAS_DRAFT_STATE,
|
|
444
|
+
projectId,
|
|
445
|
+
callback: effect,
|
|
446
|
+
event: "updated"
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
loadEffect();
|
|
451
|
+
return () => {
|
|
452
|
+
if (goodbye) {
|
|
453
|
+
goodbye();
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}, [compositionId, enabled, projectId, effect]);
|
|
457
|
+
}
|
|
442
458
|
export {
|
|
443
459
|
Composition,
|
|
444
460
|
DefaultNotImplementedComponent,
|
|
445
461
|
Slot,
|
|
462
|
+
UniformComponent,
|
|
463
|
+
UniformComposition,
|
|
464
|
+
UniformSlot,
|
|
446
465
|
componentStore,
|
|
447
466
|
componentStoreResolver,
|
|
448
467
|
createApiEnhancer,
|
|
449
468
|
createComponentStore,
|
|
450
469
|
createComponentStoreResolver,
|
|
470
|
+
createUniformApiEnhancer,
|
|
451
471
|
registerUniformComponent,
|
|
452
472
|
useComposition,
|
|
453
473
|
useCompositionEventEffect,
|
|
454
|
-
|
|
474
|
+
useUniformContextualEditing,
|
|
475
|
+
useUniformCurrentComponent,
|
|
476
|
+
useUniformCurrentComposition
|
|
455
477
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.2-alpha.4+e9d268bce",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@uniformdev/canvas": "18.
|
|
27
|
-
"@uniformdev/context": "18.
|
|
28
|
-
"@uniformdev/context-react": "18.
|
|
26
|
+
"@uniformdev/canvas": "18.1.2-alpha.4+e9d268bce",
|
|
27
|
+
"@uniformdev/context": "18.1.2-alpha.4+e9d268bce",
|
|
28
|
+
"@uniformdev/context-react": "18.1.2-alpha.4+e9d268bce"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"react": ">= 16",
|
|
31
|
+
"react": ">= 16 || 17 || 18",
|
|
32
32
|
"react-dom": ">=16"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/react": "18.0.
|
|
35
|
+
"@types/react": "18.0.27",
|
|
36
36
|
"react": "18.2.0",
|
|
37
37
|
"react-dom": "18.2.0"
|
|
38
38
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e9d268bcef28fc22632f4968ca988e3b0b92d146"
|
|
46
46
|
}
|