@uniformdev/canvas-react 18.38.2-alpha.6 → 19.1.1-alpha.1
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 +29 -254
- package/dist/index.esm.js +92 -19
- package/dist/index.js +92 -24
- package/dist/index.mjs +92 -19
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -69,137 +69,18 @@ type UniformComponentContextValue = {
|
|
|
69
69
|
declare function useUniformCurrentComponent(): UniformComponentContextValue;
|
|
70
70
|
/**
|
|
71
71
|
* Allows the rendering of a Canvas component instance (root or not), and its children if it has any.
|
|
72
|
-
* Note that the actual rendering happens inside `<
|
|
72
|
+
* Note that the actual rendering happens inside `<UniformSlot />`, this component only provides the services needed to achieve that.
|
|
73
73
|
* This component is used internally by `<UniformComposition />`, which you should use in most cases.
|
|
74
74
|
*/
|
|
75
75
|
declare function UniformComponent<TRenderProps = unknown>({ data, resolveRenderer, children, behaviorTracking, }: UniformComponentProps<TRenderProps>): JSX.Element | null;
|
|
76
76
|
|
|
77
|
-
/** @deprecated use `createUniformApiEnhancer` instead */
|
|
78
|
-
declare const createApiEnhancer: ({ apiUrl }: {
|
|
79
|
-
apiUrl: string;
|
|
80
|
-
}) => (message: UpdateCompositionMessage) => Promise<{
|
|
81
|
-
type: string;
|
|
82
|
-
parameters?: {
|
|
83
|
-
[key: string]: {
|
|
84
|
-
value: unknown;
|
|
85
|
-
type: string;
|
|
86
|
-
connectedData?: {
|
|
87
|
-
pointer: string;
|
|
88
|
-
syntax: "jptr";
|
|
89
|
-
} | undefined;
|
|
90
|
-
};
|
|
91
|
-
} | undefined;
|
|
92
|
-
variant?: string | undefined;
|
|
93
|
-
projectMapNodes?: {
|
|
94
|
-
id: string;
|
|
95
|
-
path: string;
|
|
96
|
-
projectMapId: string;
|
|
97
|
-
}[] | undefined;
|
|
98
|
-
slots?: {
|
|
99
|
-
[key: string]: {
|
|
100
|
-
type: string;
|
|
101
|
-
parameters?: {
|
|
102
|
-
[key: string]: {
|
|
103
|
-
value: unknown;
|
|
104
|
-
type: string;
|
|
105
|
-
connectedData?: {
|
|
106
|
-
pointer: string;
|
|
107
|
-
syntax: "jptr";
|
|
108
|
-
} | undefined;
|
|
109
|
-
};
|
|
110
|
-
} | undefined;
|
|
111
|
-
variant?: string | undefined;
|
|
112
|
-
slots?: {
|
|
113
|
-
[key: string]: any[];
|
|
114
|
-
} | undefined;
|
|
115
|
-
_id?: string | undefined;
|
|
116
|
-
_pattern?: string | undefined;
|
|
117
|
-
_dataResources?: {
|
|
118
|
-
[key: string]: {
|
|
119
|
-
type: string;
|
|
120
|
-
isPatternParameter?: boolean | undefined;
|
|
121
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
122
|
-
variables?: {
|
|
123
|
-
[key: string]: string;
|
|
124
|
-
} | undefined;
|
|
125
|
-
};
|
|
126
|
-
} | undefined;
|
|
127
|
-
_patternDataResources?: {
|
|
128
|
-
[key: string]: {
|
|
129
|
-
type: string;
|
|
130
|
-
isPatternParameter?: boolean | undefined;
|
|
131
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
132
|
-
variables?: {
|
|
133
|
-
[key: string]: string;
|
|
134
|
-
} | undefined;
|
|
135
|
-
};
|
|
136
|
-
} | undefined;
|
|
137
|
-
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
138
|
-
_overrides?: {
|
|
139
|
-
[key: string]: {
|
|
140
|
-
parameters?: {
|
|
141
|
-
[key: string]: {
|
|
142
|
-
value: unknown;
|
|
143
|
-
type: string;
|
|
144
|
-
connectedData?: {
|
|
145
|
-
pointer: string;
|
|
146
|
-
syntax: "jptr";
|
|
147
|
-
} | undefined;
|
|
148
|
-
};
|
|
149
|
-
} | undefined;
|
|
150
|
-
variant?: string | undefined;
|
|
151
|
-
};
|
|
152
|
-
} | undefined;
|
|
153
|
-
_overridability?: {
|
|
154
|
-
parameters?: {
|
|
155
|
-
[key: string]: "yes" | "no";
|
|
156
|
-
} | undefined;
|
|
157
|
-
variants?: boolean | undefined;
|
|
158
|
-
} | undefined;
|
|
159
|
-
}[];
|
|
160
|
-
} | undefined;
|
|
161
|
-
_id: string;
|
|
162
|
-
_slug?: string | null | undefined;
|
|
163
|
-
_name: string;
|
|
164
|
-
_dataResources?: {
|
|
165
|
-
[key: string]: {
|
|
166
|
-
type: string;
|
|
167
|
-
isPatternParameter?: boolean | undefined;
|
|
168
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
169
|
-
variables?: {
|
|
170
|
-
[key: string]: string;
|
|
171
|
-
} | undefined;
|
|
172
|
-
};
|
|
173
|
-
} | undefined;
|
|
174
|
-
_overrides?: {
|
|
175
|
-
[key: string]: {
|
|
176
|
-
parameters?: {
|
|
177
|
-
[key: string]: {
|
|
178
|
-
value: unknown;
|
|
179
|
-
type: string;
|
|
180
|
-
connectedData?: {
|
|
181
|
-
pointer: string;
|
|
182
|
-
syntax: "jptr";
|
|
183
|
-
} | undefined;
|
|
184
|
-
};
|
|
185
|
-
} | undefined;
|
|
186
|
-
variant?: string | undefined;
|
|
187
|
-
};
|
|
188
|
-
} | undefined;
|
|
189
|
-
_overridability?: {
|
|
190
|
-
parameters?: {
|
|
191
|
-
[key: string]: "yes" | "no";
|
|
192
|
-
} | undefined;
|
|
193
|
-
variants?: boolean | undefined;
|
|
194
|
-
} | undefined;
|
|
195
|
-
}>;
|
|
196
77
|
type UseUniformContextualEditingProps = {
|
|
197
78
|
initialCompositionValue?: RootComponentInstance;
|
|
198
79
|
/**
|
|
199
80
|
* A function to enhance the composition after receiving it from Canvas editor.
|
|
200
81
|
* WARNING: This enhancer will run on the client side. Make sure you're not exposing any secrets. You can use `createApiEnhancer` to create an enhancer based on an API route.
|
|
201
82
|
*/
|
|
202
|
-
enhance?: (composition: UpdateCompositionMessage) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
83
|
+
enhance?: ({ composition, hash, }: Pick<UpdateCompositionMessage, 'composition' | 'hash'>) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
203
84
|
};
|
|
204
85
|
/**
|
|
205
86
|
* Adds contextual editing capability to a Uniform app.
|
|
@@ -324,128 +205,6 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
|
|
|
324
205
|
} | undefined;
|
|
325
206
|
isContextualEditing: boolean;
|
|
326
207
|
};
|
|
327
|
-
/** @deprecated use useUniformContextualEditing instead */
|
|
328
|
-
declare const useContextualEditing: ({ initialCompositionValue, enhance, }: UseUniformContextualEditingProps) => {
|
|
329
|
-
composition: {
|
|
330
|
-
type: string;
|
|
331
|
-
parameters?: {
|
|
332
|
-
[key: string]: {
|
|
333
|
-
value: unknown;
|
|
334
|
-
type: string;
|
|
335
|
-
connectedData?: {
|
|
336
|
-
pointer: string;
|
|
337
|
-
syntax: "jptr";
|
|
338
|
-
} | undefined;
|
|
339
|
-
};
|
|
340
|
-
} | undefined;
|
|
341
|
-
variant?: string | undefined;
|
|
342
|
-
projectMapNodes?: {
|
|
343
|
-
id: string;
|
|
344
|
-
path: string;
|
|
345
|
-
projectMapId: string;
|
|
346
|
-
}[] | undefined;
|
|
347
|
-
slots?: {
|
|
348
|
-
[key: string]: {
|
|
349
|
-
type: string;
|
|
350
|
-
parameters?: {
|
|
351
|
-
[key: string]: {
|
|
352
|
-
value: unknown;
|
|
353
|
-
type: string;
|
|
354
|
-
connectedData?: {
|
|
355
|
-
pointer: string;
|
|
356
|
-
syntax: "jptr";
|
|
357
|
-
} | undefined;
|
|
358
|
-
};
|
|
359
|
-
} | undefined;
|
|
360
|
-
variant?: string | undefined;
|
|
361
|
-
slots?: {
|
|
362
|
-
[key: string]: any[];
|
|
363
|
-
} | undefined;
|
|
364
|
-
_id?: string | undefined;
|
|
365
|
-
_pattern?: string | undefined;
|
|
366
|
-
_dataResources?: {
|
|
367
|
-
[key: string]: {
|
|
368
|
-
type: string;
|
|
369
|
-
isPatternParameter?: boolean | undefined;
|
|
370
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
371
|
-
variables?: {
|
|
372
|
-
[key: string]: string;
|
|
373
|
-
} | undefined;
|
|
374
|
-
};
|
|
375
|
-
} | undefined;
|
|
376
|
-
_patternDataResources?: {
|
|
377
|
-
[key: string]: {
|
|
378
|
-
type: string;
|
|
379
|
-
isPatternParameter?: boolean | undefined;
|
|
380
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
381
|
-
variables?: {
|
|
382
|
-
[key: string]: string;
|
|
383
|
-
} | undefined;
|
|
384
|
-
};
|
|
385
|
-
} | undefined;
|
|
386
|
-
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
387
|
-
_overrides?: {
|
|
388
|
-
[key: string]: {
|
|
389
|
-
parameters?: {
|
|
390
|
-
[key: string]: {
|
|
391
|
-
value: unknown;
|
|
392
|
-
type: string;
|
|
393
|
-
connectedData?: {
|
|
394
|
-
pointer: string;
|
|
395
|
-
syntax: "jptr";
|
|
396
|
-
} | undefined;
|
|
397
|
-
};
|
|
398
|
-
} | undefined;
|
|
399
|
-
variant?: string | undefined;
|
|
400
|
-
};
|
|
401
|
-
} | undefined;
|
|
402
|
-
_overridability?: {
|
|
403
|
-
parameters?: {
|
|
404
|
-
[key: string]: "yes" | "no";
|
|
405
|
-
} | undefined;
|
|
406
|
-
variants?: boolean | undefined;
|
|
407
|
-
} | undefined;
|
|
408
|
-
}[];
|
|
409
|
-
} | undefined;
|
|
410
|
-
_id: string;
|
|
411
|
-
_slug?: string | null | undefined;
|
|
412
|
-
_name: string;
|
|
413
|
-
_dataResources?: {
|
|
414
|
-
[key: string]: {
|
|
415
|
-
type: string;
|
|
416
|
-
isPatternParameter?: boolean | undefined;
|
|
417
|
-
ignorePatternParameterDefault?: boolean | undefined;
|
|
418
|
-
variables?: {
|
|
419
|
-
[key: string]: string;
|
|
420
|
-
} | undefined;
|
|
421
|
-
};
|
|
422
|
-
} | undefined;
|
|
423
|
-
_overrides?: {
|
|
424
|
-
[key: string]: {
|
|
425
|
-
parameters?: {
|
|
426
|
-
[key: string]: {
|
|
427
|
-
value: unknown;
|
|
428
|
-
type: string;
|
|
429
|
-
connectedData?: {
|
|
430
|
-
pointer: string;
|
|
431
|
-
syntax: "jptr";
|
|
432
|
-
} | undefined;
|
|
433
|
-
};
|
|
434
|
-
} | undefined;
|
|
435
|
-
variant?: string | undefined;
|
|
436
|
-
};
|
|
437
|
-
} | undefined;
|
|
438
|
-
_overridability?: {
|
|
439
|
-
parameters?: {
|
|
440
|
-
[key: string]: "yes" | "no";
|
|
441
|
-
} | undefined;
|
|
442
|
-
variants?: boolean | undefined;
|
|
443
|
-
} | undefined;
|
|
444
|
-
} | undefined;
|
|
445
|
-
isContextualEditing: boolean;
|
|
446
|
-
};
|
|
447
|
-
/** @deprecated use UseUniformContextualEditingProps instead */
|
|
448
|
-
type UseContextualEditingProps = UseUniformContextualEditingProps;
|
|
449
208
|
|
|
450
209
|
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & {
|
|
451
210
|
/** The composition data */
|
|
@@ -468,12 +227,6 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
468
227
|
* It also takes care of enabling [Contextual Editing](https://docs.uniform.app/capabilities/composition/contextual-editing).
|
|
469
228
|
*/
|
|
470
229
|
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, }: UniformCompositionProps<TRenderProps>): JSX.Element;
|
|
471
|
-
/** @deprecated use `useUniformCurrentComposition` instead */
|
|
472
|
-
declare const useComposition: typeof useUniformCurrentComposition;
|
|
473
|
-
/** @deprecated use `UniformComposition` instead */
|
|
474
|
-
declare const Composition: typeof UniformComposition;
|
|
475
|
-
/** @deprecated use `UniformCompositionProps` instead */
|
|
476
|
-
type CompositionProps<TRenderProps = unknown> = UniformCompositionProps<TRenderProps>;
|
|
477
230
|
|
|
478
231
|
type CustomSlotChildRenderFunc = (options: {
|
|
479
232
|
child: ReactNode;
|
|
@@ -499,10 +252,32 @@ type UniformSlotProps<TSlotNames extends string> = {
|
|
|
499
252
|
};
|
|
500
253
|
/** Renders a named Slot within a Composition. */
|
|
501
254
|
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, children, emptyPlaceholder, }: UniformSlotProps<TSlotNames>): JSX.Element | null;
|
|
502
|
-
|
|
503
|
-
type
|
|
504
|
-
|
|
505
|
-
|
|
255
|
+
|
|
256
|
+
type ParameterTextValue = string | undefined;
|
|
257
|
+
type UniformTextProps = {
|
|
258
|
+
/**
|
|
259
|
+
* The name of the HTML tag to render.
|
|
260
|
+
* @default "span"
|
|
261
|
+
*/
|
|
262
|
+
as?: React$1.ElementType;
|
|
263
|
+
/** The ID of the parameter. */
|
|
264
|
+
parameterId: string;
|
|
265
|
+
/**
|
|
266
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
267
|
+
* @default false
|
|
268
|
+
*/
|
|
269
|
+
isMultiline?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
272
|
+
* @default "(value) => value"
|
|
273
|
+
*/
|
|
274
|
+
render?: (value: ParameterTextValue) => React$1.ReactNode;
|
|
275
|
+
} & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children'>;
|
|
276
|
+
/**
|
|
277
|
+
* Adds inline editing capability to text parameters
|
|
278
|
+
* @deprecated This component is unstable, and not ready for production usage.
|
|
279
|
+
**/
|
|
280
|
+
declare const UniformText: ({ as: Tag, parameterId, isMultiline, render, ...props }: UniformTextProps) => JSX.Element | null;
|
|
506
281
|
|
|
507
282
|
type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback'> & {
|
|
508
283
|
enabled: boolean;
|
|
@@ -527,4 +302,4 @@ declare const createComponentStoreResolver: (options: {
|
|
|
527
302
|
defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
|
|
528
303
|
}) => RenderComponentResolver;
|
|
529
304
|
|
|
530
|
-
export { ComponentProps, ComponentStore,
|
|
305
|
+
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
package/dist/index.esm.js
CHANGED
|
@@ -98,7 +98,8 @@ import {
|
|
|
98
98
|
CANVAS_PERSONALIZE_SLOT,
|
|
99
99
|
CANVAS_PERSONALIZE_TYPE,
|
|
100
100
|
CANVAS_TEST_SLOT,
|
|
101
|
-
CANVAS_TEST_TYPE
|
|
101
|
+
CANVAS_TEST_TYPE,
|
|
102
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
102
103
|
} from "@uniformdev/canvas";
|
|
103
104
|
import React5 from "react";
|
|
104
105
|
|
|
@@ -162,10 +163,9 @@ import {
|
|
|
162
163
|
EMPTY_COMPOSITION,
|
|
163
164
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
164
165
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
165
|
-
|
|
166
|
+
isUpdateCompositionInternalMessage
|
|
166
167
|
} from "@uniformdev/canvas";
|
|
167
168
|
import { useEffect, useMemo, useState } from "react";
|
|
168
|
-
var createApiEnhancer = createUniformApiEnhancer;
|
|
169
169
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
170
170
|
var useUniformContextualEditing = ({
|
|
171
171
|
initialCompositionValue,
|
|
@@ -191,8 +191,8 @@ var useUniformContextualEditing = ({
|
|
|
191
191
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
195
|
-
if (!
|
|
194
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
195
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
const enhancedComposition = await enhance(message);
|
|
@@ -244,7 +244,6 @@ function isInContextEditingMode() {
|
|
|
244
244
|
);
|
|
245
245
|
return isOpenedByInContextEditor && isAllowlistedReferrer;
|
|
246
246
|
}
|
|
247
|
-
var useContextualEditing = useUniformContextualEditing;
|
|
248
247
|
|
|
249
248
|
// src/components/UniformComposition.tsx
|
|
250
249
|
var UniformCompositionContext = createContext({
|
|
@@ -281,8 +280,6 @@ function UniformComposition({
|
|
|
281
280
|
))
|
|
282
281
|
);
|
|
283
282
|
}
|
|
284
|
-
var useComposition = useUniformCurrentComposition;
|
|
285
|
-
var Composition = UniformComposition;
|
|
286
283
|
|
|
287
284
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
288
285
|
function ContextualEditingComponentWrapper({
|
|
@@ -297,7 +294,7 @@ function ContextualEditingComponentWrapper({
|
|
|
297
294
|
var _a, _b, _c, _d;
|
|
298
295
|
const isPlaceholder = (component == null ? void 0 : component._id) === PLACEHOLDER_ID;
|
|
299
296
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
300
|
-
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
|
+
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
301
298
|
"script",
|
|
302
299
|
{
|
|
303
300
|
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -329,7 +326,7 @@ function UniformSlot({
|
|
|
329
326
|
}
|
|
330
327
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
331
328
|
if (!slot || !Array.isArray(slot)) {
|
|
332
|
-
if (process.env.NODE_ENV === "development") {
|
|
329
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== EMPTY_COMPOSITION2.type) {
|
|
333
330
|
console.warn(
|
|
334
331
|
`[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:`,
|
|
335
332
|
parentData
|
|
@@ -369,7 +366,7 @@ function renderComponent({
|
|
|
369
366
|
}) {
|
|
370
367
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
371
368
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
372
|
-
|
|
369
|
+
const testComponent = resolveSystem.test(
|
|
373
370
|
component,
|
|
374
371
|
key,
|
|
375
372
|
(variantComponent, key2) => {
|
|
@@ -388,8 +385,20 @@ function renderComponent({
|
|
|
388
385
|
});
|
|
389
386
|
}
|
|
390
387
|
);
|
|
388
|
+
return /* @__PURE__ */ React5.createElement(
|
|
389
|
+
ContextualEditingComponentWrapper,
|
|
390
|
+
{
|
|
391
|
+
component,
|
|
392
|
+
parentComponent,
|
|
393
|
+
slotName,
|
|
394
|
+
indexInSlot,
|
|
395
|
+
slotChildrenCount,
|
|
396
|
+
emptyPlaceholder
|
|
397
|
+
},
|
|
398
|
+
testComponent
|
|
399
|
+
);
|
|
391
400
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
392
|
-
|
|
401
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
393
402
|
component,
|
|
394
403
|
key,
|
|
395
404
|
(variantComponent, key2) => {
|
|
@@ -408,6 +417,18 @@ function renderComponent({
|
|
|
408
417
|
});
|
|
409
418
|
}
|
|
410
419
|
);
|
|
420
|
+
return /* @__PURE__ */ React5.createElement(
|
|
421
|
+
ContextualEditingComponentWrapper,
|
|
422
|
+
{
|
|
423
|
+
component,
|
|
424
|
+
parentComponent,
|
|
425
|
+
slotName,
|
|
426
|
+
indexInSlot,
|
|
427
|
+
slotChildrenCount,
|
|
428
|
+
emptyPlaceholder
|
|
429
|
+
},
|
|
430
|
+
personalizationComponent
|
|
431
|
+
);
|
|
411
432
|
} else if (RenderComponent) {
|
|
412
433
|
const props = convertComponentToProps(component);
|
|
413
434
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -431,7 +452,6 @@ function renderComponent({
|
|
|
431
452
|
}
|
|
432
453
|
return null;
|
|
433
454
|
}
|
|
434
|
-
var Slot = UniformSlot;
|
|
435
455
|
|
|
436
456
|
// src/components/UniformComponent.tsx
|
|
437
457
|
var UniformComponentContext = createContext2({});
|
|
@@ -485,7 +505,7 @@ function resolveChildren({
|
|
|
485
505
|
} else {
|
|
486
506
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
487
507
|
console.warn(
|
|
488
|
-
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<
|
|
508
|
+
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<UniformSlot name={slotName} />' to reliably render the slots.`
|
|
489
509
|
);
|
|
490
510
|
}
|
|
491
511
|
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ React6.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
@@ -495,6 +515,63 @@ function resolveChildren({
|
|
|
495
515
|
return renderChildren;
|
|
496
516
|
}
|
|
497
517
|
|
|
518
|
+
// src/components/UniformText.tsx
|
|
519
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
520
|
+
var UniformText = ({
|
|
521
|
+
as: Tag = "span",
|
|
522
|
+
parameterId,
|
|
523
|
+
isMultiline = false,
|
|
524
|
+
render = (value) => value,
|
|
525
|
+
...props
|
|
526
|
+
}) => {
|
|
527
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
528
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
529
|
+
const elementRef = useRef(null);
|
|
530
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
531
|
+
const parameter = useMemo2(() => {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
534
|
+
}, [componentData, parameterId]);
|
|
535
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
536
|
+
const isEditable = useMemo2(() => {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
539
|
+
}, [parameter]);
|
|
540
|
+
const handleOnFocus = useCallback(() => {
|
|
541
|
+
setIsFocused(true);
|
|
542
|
+
}, [setIsFocused]);
|
|
543
|
+
const handleOnBlur = useCallback(() => {
|
|
544
|
+
setIsFocused(false);
|
|
545
|
+
}, [setIsFocused]);
|
|
546
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
547
|
+
if (!parameter) {
|
|
548
|
+
console.warn(
|
|
549
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
550
|
+
);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
if (!isContextualEditing) {
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
555
|
+
}
|
|
556
|
+
return /* @__PURE__ */ React7.createElement(
|
|
557
|
+
Tag,
|
|
558
|
+
{
|
|
559
|
+
...props,
|
|
560
|
+
ref: elementRef,
|
|
561
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
562
|
+
"data-uniform-parameter-id": parameterId,
|
|
563
|
+
"data-uniform-parameter-type": "text",
|
|
564
|
+
"data-uniform-is-multiline": isMultiline,
|
|
565
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
566
|
+
contentEditable: isEditable,
|
|
567
|
+
suppressContentEditableWarning: true,
|
|
568
|
+
onFocus: handleOnFocus,
|
|
569
|
+
onBlur: handleOnBlur
|
|
570
|
+
},
|
|
571
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
572
|
+
);
|
|
573
|
+
};
|
|
574
|
+
|
|
498
575
|
// src/hooks/useCompositionEventEffect.ts
|
|
499
576
|
import {
|
|
500
577
|
CANVAS_DRAFT_STATE,
|
|
@@ -535,23 +612,19 @@ function useCompositionEventEffect({
|
|
|
535
612
|
}, [compositionId, enabled, projectId, effect]);
|
|
536
613
|
}
|
|
537
614
|
export {
|
|
538
|
-
Composition,
|
|
539
615
|
DefaultNotImplementedComponent,
|
|
540
616
|
NOT_IMPLEMENTED_COMPONENT,
|
|
541
|
-
Slot,
|
|
542
617
|
UniformComponent,
|
|
543
618
|
UniformComposition,
|
|
544
619
|
UniformSlot,
|
|
620
|
+
UniformText,
|
|
545
621
|
componentStore,
|
|
546
622
|
componentStoreResolver,
|
|
547
|
-
createApiEnhancer,
|
|
548
623
|
createComponentStore,
|
|
549
624
|
createComponentStoreResolver,
|
|
550
625
|
createUniformApiEnhancer,
|
|
551
626
|
registerUniformComponent,
|
|
552
|
-
useComposition,
|
|
553
627
|
useCompositionEventEffect,
|
|
554
|
-
useContextualEditing,
|
|
555
628
|
useUniformContextualEditing,
|
|
556
629
|
useUniformCurrentComponent,
|
|
557
630
|
useUniformCurrentComposition
|
package/dist/index.js
CHANGED
|
@@ -30,23 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
Composition: () => Composition,
|
|
34
33
|
DefaultNotImplementedComponent: () => DefaultNotImplementedComponent,
|
|
35
34
|
NOT_IMPLEMENTED_COMPONENT: () => NOT_IMPLEMENTED_COMPONENT,
|
|
36
|
-
Slot: () => Slot,
|
|
37
35
|
UniformComponent: () => UniformComponent,
|
|
38
36
|
UniformComposition: () => UniformComposition,
|
|
39
37
|
UniformSlot: () => UniformSlot,
|
|
38
|
+
UniformText: () => UniformText,
|
|
40
39
|
componentStore: () => componentStore,
|
|
41
40
|
componentStoreResolver: () => componentStoreResolver,
|
|
42
|
-
createApiEnhancer: () => createApiEnhancer,
|
|
43
41
|
createComponentStore: () => createComponentStore,
|
|
44
42
|
createComponentStoreResolver: () => createComponentStoreResolver,
|
|
45
43
|
createUniformApiEnhancer: () => import_canvas3.createUniformApiEnhancer,
|
|
46
44
|
registerUniformComponent: () => registerUniformComponent,
|
|
47
|
-
useComposition: () => useComposition,
|
|
48
45
|
useCompositionEventEffect: () => useCompositionEventEffect,
|
|
49
|
-
useContextualEditing: () => useContextualEditing,
|
|
50
46
|
useUniformContextualEditing: () => useUniformContextualEditing,
|
|
51
47
|
useUniformCurrentComponent: () => useUniformCurrentComponent,
|
|
52
48
|
useUniformCurrentComposition: () => useUniformCurrentComposition
|
|
@@ -198,7 +194,6 @@ var import_react3 = __toESM(require("react"));
|
|
|
198
194
|
// src/hooks/useUniformContextualEditing.ts
|
|
199
195
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
200
196
|
var import_react2 = require("react");
|
|
201
|
-
var createApiEnhancer = import_canvas3.createUniformApiEnhancer;
|
|
202
197
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
203
198
|
var useUniformContextualEditing = ({
|
|
204
199
|
initialCompositionValue,
|
|
@@ -224,8 +219,8 @@ var useUniformContextualEditing = ({
|
|
|
224
219
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
225
220
|
return;
|
|
226
221
|
}
|
|
227
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
228
|
-
if (!(0, import_canvas3.
|
|
222
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
223
|
+
if (!(0, import_canvas3.isUpdateCompositionInternalMessage)(message)) {
|
|
229
224
|
return;
|
|
230
225
|
}
|
|
231
226
|
const enhancedComposition = await enhance(message);
|
|
@@ -277,7 +272,6 @@ function isInContextEditingMode() {
|
|
|
277
272
|
);
|
|
278
273
|
return isOpenedByInContextEditor && isAllowlistedReferrer;
|
|
279
274
|
}
|
|
280
|
-
var useContextualEditing = useUniformContextualEditing;
|
|
281
275
|
|
|
282
276
|
// src/components/UniformComposition.tsx
|
|
283
277
|
var UniformCompositionContext = (0, import_react3.createContext)({
|
|
@@ -314,8 +308,6 @@ function UniformComposition({
|
|
|
314
308
|
))
|
|
315
309
|
);
|
|
316
310
|
}
|
|
317
|
-
var useComposition = useUniformCurrentComposition;
|
|
318
|
-
var Composition = UniformComposition;
|
|
319
311
|
|
|
320
312
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
321
313
|
function ContextualEditingComponentWrapper({
|
|
@@ -330,7 +322,7 @@ function ContextualEditingComponentWrapper({
|
|
|
330
322
|
var _a, _b, _c, _d;
|
|
331
323
|
const isPlaceholder = (component == null ? void 0 : component._id) === import_canvas4.PLACEHOLDER_ID;
|
|
332
324
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
333
|
-
return !isContextualEditing ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, children) : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
325
|
+
return !isContextualEditing ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
334
326
|
"script",
|
|
335
327
|
{
|
|
336
328
|
"data-role": import_canvas4.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -362,7 +354,7 @@ function UniformSlot({
|
|
|
362
354
|
}
|
|
363
355
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
364
356
|
if (!slot || !Array.isArray(slot)) {
|
|
365
|
-
if (process.env.NODE_ENV === "development") {
|
|
357
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== import_canvas5.EMPTY_COMPOSITION.type) {
|
|
366
358
|
console.warn(
|
|
367
359
|
`[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:`,
|
|
368
360
|
parentData
|
|
@@ -402,7 +394,7 @@ function renderComponent({
|
|
|
402
394
|
}) {
|
|
403
395
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
404
396
|
if (component.type === import_canvas5.CANVAS_TEST_TYPE) {
|
|
405
|
-
|
|
397
|
+
const testComponent = resolveSystem.test(
|
|
406
398
|
component,
|
|
407
399
|
key,
|
|
408
400
|
(variantComponent, key2) => {
|
|
@@ -421,8 +413,20 @@ function renderComponent({
|
|
|
421
413
|
});
|
|
422
414
|
}
|
|
423
415
|
);
|
|
416
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
417
|
+
ContextualEditingComponentWrapper,
|
|
418
|
+
{
|
|
419
|
+
component,
|
|
420
|
+
parentComponent,
|
|
421
|
+
slotName,
|
|
422
|
+
indexInSlot,
|
|
423
|
+
slotChildrenCount,
|
|
424
|
+
emptyPlaceholder
|
|
425
|
+
},
|
|
426
|
+
testComponent
|
|
427
|
+
);
|
|
424
428
|
} else if (component.type === import_canvas5.CANVAS_PERSONALIZE_TYPE) {
|
|
425
|
-
|
|
429
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
426
430
|
component,
|
|
427
431
|
key,
|
|
428
432
|
(variantComponent, key2) => {
|
|
@@ -441,6 +445,18 @@ function renderComponent({
|
|
|
441
445
|
});
|
|
442
446
|
}
|
|
443
447
|
);
|
|
448
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
449
|
+
ContextualEditingComponentWrapper,
|
|
450
|
+
{
|
|
451
|
+
component,
|
|
452
|
+
parentComponent,
|
|
453
|
+
slotName,
|
|
454
|
+
indexInSlot,
|
|
455
|
+
slotChildrenCount,
|
|
456
|
+
emptyPlaceholder
|
|
457
|
+
},
|
|
458
|
+
personalizationComponent
|
|
459
|
+
);
|
|
444
460
|
} else if (RenderComponent) {
|
|
445
461
|
const props = convertComponentToProps(component);
|
|
446
462
|
return /* @__PURE__ */ import_react5.default.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ import_react5.default.createElement(
|
|
@@ -464,7 +480,6 @@ function renderComponent({
|
|
|
464
480
|
}
|
|
465
481
|
return null;
|
|
466
482
|
}
|
|
467
|
-
var Slot = UniformSlot;
|
|
468
483
|
|
|
469
484
|
// src/components/UniformComponent.tsx
|
|
470
485
|
var UniformComponentContext = (0, import_react6.createContext)({});
|
|
@@ -518,7 +533,7 @@ function resolveChildren({
|
|
|
518
533
|
} else {
|
|
519
534
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
520
535
|
console.warn(
|
|
521
|
-
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<
|
|
536
|
+
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<UniformSlot name={slotName} />' to reliably render the slots.`
|
|
522
537
|
);
|
|
523
538
|
}
|
|
524
539
|
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ import_react6.default.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
@@ -528,16 +543,73 @@ function resolveChildren({
|
|
|
528
543
|
return renderChildren;
|
|
529
544
|
}
|
|
530
545
|
|
|
546
|
+
// src/components/UniformText.tsx
|
|
547
|
+
var import_react7 = __toESM(require("react"));
|
|
548
|
+
var UniformText = ({
|
|
549
|
+
as: Tag = "span",
|
|
550
|
+
parameterId,
|
|
551
|
+
isMultiline = false,
|
|
552
|
+
render = (value) => value,
|
|
553
|
+
...props
|
|
554
|
+
}) => {
|
|
555
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
556
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
557
|
+
const elementRef = (0, import_react7.useRef)(null);
|
|
558
|
+
const [isFocused, setIsFocused] = (0, import_react7.useState)(false);
|
|
559
|
+
const parameter = (0, import_react7.useMemo)(() => {
|
|
560
|
+
var _a;
|
|
561
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
562
|
+
}, [componentData, parameterId]);
|
|
563
|
+
const value = (0, import_react7.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
564
|
+
const isEditable = (0, import_react7.useMemo)(() => {
|
|
565
|
+
var _a, _b;
|
|
566
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
567
|
+
}, [parameter]);
|
|
568
|
+
const handleOnFocus = (0, import_react7.useCallback)(() => {
|
|
569
|
+
setIsFocused(true);
|
|
570
|
+
}, [setIsFocused]);
|
|
571
|
+
const handleOnBlur = (0, import_react7.useCallback)(() => {
|
|
572
|
+
setIsFocused(false);
|
|
573
|
+
}, [setIsFocused]);
|
|
574
|
+
const shouldSkipCustomRendering = (0, import_react7.useMemo)(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
575
|
+
if (!parameter) {
|
|
576
|
+
console.warn(
|
|
577
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
578
|
+
);
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
if (!isContextualEditing) {
|
|
582
|
+
return /* @__PURE__ */ import_react7.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
583
|
+
}
|
|
584
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
585
|
+
Tag,
|
|
586
|
+
{
|
|
587
|
+
...props,
|
|
588
|
+
ref: elementRef,
|
|
589
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
590
|
+
"data-uniform-parameter-id": parameterId,
|
|
591
|
+
"data-uniform-parameter-type": "text",
|
|
592
|
+
"data-uniform-is-multiline": isMultiline,
|
|
593
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
594
|
+
contentEditable: isEditable,
|
|
595
|
+
suppressContentEditableWarning: true,
|
|
596
|
+
onFocus: handleOnFocus,
|
|
597
|
+
onBlur: handleOnBlur
|
|
598
|
+
},
|
|
599
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
600
|
+
);
|
|
601
|
+
};
|
|
602
|
+
|
|
531
603
|
// src/hooks/useCompositionEventEffect.ts
|
|
532
604
|
var import_canvas7 = require("@uniformdev/canvas");
|
|
533
|
-
var
|
|
605
|
+
var import_react8 = require("react");
|
|
534
606
|
function useCompositionEventEffect({
|
|
535
607
|
enabled,
|
|
536
608
|
projectId,
|
|
537
609
|
compositionId,
|
|
538
610
|
effect
|
|
539
611
|
}) {
|
|
540
|
-
(0,
|
|
612
|
+
(0, import_react8.useEffect)(() => {
|
|
541
613
|
if (!enabled || !compositionId || !projectId) {
|
|
542
614
|
return;
|
|
543
615
|
}
|
|
@@ -565,23 +637,19 @@ function useCompositionEventEffect({
|
|
|
565
637
|
}
|
|
566
638
|
// Annotate the CommonJS export names for ESM import in node:
|
|
567
639
|
0 && (module.exports = {
|
|
568
|
-
Composition,
|
|
569
640
|
DefaultNotImplementedComponent,
|
|
570
641
|
NOT_IMPLEMENTED_COMPONENT,
|
|
571
|
-
Slot,
|
|
572
642
|
UniformComponent,
|
|
573
643
|
UniformComposition,
|
|
574
644
|
UniformSlot,
|
|
645
|
+
UniformText,
|
|
575
646
|
componentStore,
|
|
576
647
|
componentStoreResolver,
|
|
577
|
-
createApiEnhancer,
|
|
578
648
|
createComponentStore,
|
|
579
649
|
createComponentStoreResolver,
|
|
580
650
|
createUniformApiEnhancer,
|
|
581
651
|
registerUniformComponent,
|
|
582
|
-
useComposition,
|
|
583
652
|
useCompositionEventEffect,
|
|
584
|
-
useContextualEditing,
|
|
585
653
|
useUniformContextualEditing,
|
|
586
654
|
useUniformCurrentComponent,
|
|
587
655
|
useUniformCurrentComposition
|
package/dist/index.mjs
CHANGED
|
@@ -98,7 +98,8 @@ import {
|
|
|
98
98
|
CANVAS_PERSONALIZE_SLOT,
|
|
99
99
|
CANVAS_PERSONALIZE_TYPE,
|
|
100
100
|
CANVAS_TEST_SLOT,
|
|
101
|
-
CANVAS_TEST_TYPE
|
|
101
|
+
CANVAS_TEST_TYPE,
|
|
102
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
102
103
|
} from "@uniformdev/canvas";
|
|
103
104
|
import React5 from "react";
|
|
104
105
|
|
|
@@ -162,10 +163,9 @@ import {
|
|
|
162
163
|
EMPTY_COMPOSITION,
|
|
163
164
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
164
165
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
165
|
-
|
|
166
|
+
isUpdateCompositionInternalMessage
|
|
166
167
|
} from "@uniformdev/canvas";
|
|
167
168
|
import { useEffect, useMemo, useState } from "react";
|
|
168
|
-
var createApiEnhancer = createUniformApiEnhancer;
|
|
169
169
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
170
170
|
var useUniformContextualEditing = ({
|
|
171
171
|
initialCompositionValue,
|
|
@@ -191,8 +191,8 @@ var useUniformContextualEditing = ({
|
|
|
191
191
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
195
|
-
if (!
|
|
194
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
195
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
const enhancedComposition = await enhance(message);
|
|
@@ -244,7 +244,6 @@ function isInContextEditingMode() {
|
|
|
244
244
|
);
|
|
245
245
|
return isOpenedByInContextEditor && isAllowlistedReferrer;
|
|
246
246
|
}
|
|
247
|
-
var useContextualEditing = useUniformContextualEditing;
|
|
248
247
|
|
|
249
248
|
// src/components/UniformComposition.tsx
|
|
250
249
|
var UniformCompositionContext = createContext({
|
|
@@ -281,8 +280,6 @@ function UniformComposition({
|
|
|
281
280
|
))
|
|
282
281
|
);
|
|
283
282
|
}
|
|
284
|
-
var useComposition = useUniformCurrentComposition;
|
|
285
|
-
var Composition = UniformComposition;
|
|
286
283
|
|
|
287
284
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
288
285
|
function ContextualEditingComponentWrapper({
|
|
@@ -297,7 +294,7 @@ function ContextualEditingComponentWrapper({
|
|
|
297
294
|
var _a, _b, _c, _d;
|
|
298
295
|
const isPlaceholder = (component == null ? void 0 : component._id) === PLACEHOLDER_ID;
|
|
299
296
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
300
|
-
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
|
+
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
301
298
|
"script",
|
|
302
299
|
{
|
|
303
300
|
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -329,7 +326,7 @@ function UniformSlot({
|
|
|
329
326
|
}
|
|
330
327
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
331
328
|
if (!slot || !Array.isArray(slot)) {
|
|
332
|
-
if (process.env.NODE_ENV === "development") {
|
|
329
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== EMPTY_COMPOSITION2.type) {
|
|
333
330
|
console.warn(
|
|
334
331
|
`[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:`,
|
|
335
332
|
parentData
|
|
@@ -369,7 +366,7 @@ function renderComponent({
|
|
|
369
366
|
}) {
|
|
370
367
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
371
368
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
372
|
-
|
|
369
|
+
const testComponent = resolveSystem.test(
|
|
373
370
|
component,
|
|
374
371
|
key,
|
|
375
372
|
(variantComponent, key2) => {
|
|
@@ -388,8 +385,20 @@ function renderComponent({
|
|
|
388
385
|
});
|
|
389
386
|
}
|
|
390
387
|
);
|
|
388
|
+
return /* @__PURE__ */ React5.createElement(
|
|
389
|
+
ContextualEditingComponentWrapper,
|
|
390
|
+
{
|
|
391
|
+
component,
|
|
392
|
+
parentComponent,
|
|
393
|
+
slotName,
|
|
394
|
+
indexInSlot,
|
|
395
|
+
slotChildrenCount,
|
|
396
|
+
emptyPlaceholder
|
|
397
|
+
},
|
|
398
|
+
testComponent
|
|
399
|
+
);
|
|
391
400
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
392
|
-
|
|
401
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
393
402
|
component,
|
|
394
403
|
key,
|
|
395
404
|
(variantComponent, key2) => {
|
|
@@ -408,6 +417,18 @@ function renderComponent({
|
|
|
408
417
|
});
|
|
409
418
|
}
|
|
410
419
|
);
|
|
420
|
+
return /* @__PURE__ */ React5.createElement(
|
|
421
|
+
ContextualEditingComponentWrapper,
|
|
422
|
+
{
|
|
423
|
+
component,
|
|
424
|
+
parentComponent,
|
|
425
|
+
slotName,
|
|
426
|
+
indexInSlot,
|
|
427
|
+
slotChildrenCount,
|
|
428
|
+
emptyPlaceholder
|
|
429
|
+
},
|
|
430
|
+
personalizationComponent
|
|
431
|
+
);
|
|
411
432
|
} else if (RenderComponent) {
|
|
412
433
|
const props = convertComponentToProps(component);
|
|
413
434
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -431,7 +452,6 @@ function renderComponent({
|
|
|
431
452
|
}
|
|
432
453
|
return null;
|
|
433
454
|
}
|
|
434
|
-
var Slot = UniformSlot;
|
|
435
455
|
|
|
436
456
|
// src/components/UniformComponent.tsx
|
|
437
457
|
var UniformComponentContext = createContext2({});
|
|
@@ -485,7 +505,7 @@ function resolveChildren({
|
|
|
485
505
|
} else {
|
|
486
506
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
487
507
|
console.warn(
|
|
488
|
-
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<
|
|
508
|
+
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<UniformSlot name={slotName} />' to reliably render the slots.`
|
|
489
509
|
);
|
|
490
510
|
}
|
|
491
511
|
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ React6.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
@@ -495,6 +515,63 @@ function resolveChildren({
|
|
|
495
515
|
return renderChildren;
|
|
496
516
|
}
|
|
497
517
|
|
|
518
|
+
// src/components/UniformText.tsx
|
|
519
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
520
|
+
var UniformText = ({
|
|
521
|
+
as: Tag = "span",
|
|
522
|
+
parameterId,
|
|
523
|
+
isMultiline = false,
|
|
524
|
+
render = (value) => value,
|
|
525
|
+
...props
|
|
526
|
+
}) => {
|
|
527
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
528
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
529
|
+
const elementRef = useRef(null);
|
|
530
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
531
|
+
const parameter = useMemo2(() => {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
534
|
+
}, [componentData, parameterId]);
|
|
535
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
536
|
+
const isEditable = useMemo2(() => {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
539
|
+
}, [parameter]);
|
|
540
|
+
const handleOnFocus = useCallback(() => {
|
|
541
|
+
setIsFocused(true);
|
|
542
|
+
}, [setIsFocused]);
|
|
543
|
+
const handleOnBlur = useCallback(() => {
|
|
544
|
+
setIsFocused(false);
|
|
545
|
+
}, [setIsFocused]);
|
|
546
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
547
|
+
if (!parameter) {
|
|
548
|
+
console.warn(
|
|
549
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
550
|
+
);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
if (!isContextualEditing) {
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
555
|
+
}
|
|
556
|
+
return /* @__PURE__ */ React7.createElement(
|
|
557
|
+
Tag,
|
|
558
|
+
{
|
|
559
|
+
...props,
|
|
560
|
+
ref: elementRef,
|
|
561
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
562
|
+
"data-uniform-parameter-id": parameterId,
|
|
563
|
+
"data-uniform-parameter-type": "text",
|
|
564
|
+
"data-uniform-is-multiline": isMultiline,
|
|
565
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
566
|
+
contentEditable: isEditable,
|
|
567
|
+
suppressContentEditableWarning: true,
|
|
568
|
+
onFocus: handleOnFocus,
|
|
569
|
+
onBlur: handleOnBlur
|
|
570
|
+
},
|
|
571
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
572
|
+
);
|
|
573
|
+
};
|
|
574
|
+
|
|
498
575
|
// src/hooks/useCompositionEventEffect.ts
|
|
499
576
|
import {
|
|
500
577
|
CANVAS_DRAFT_STATE,
|
|
@@ -535,23 +612,19 @@ function useCompositionEventEffect({
|
|
|
535
612
|
}, [compositionId, enabled, projectId, effect]);
|
|
536
613
|
}
|
|
537
614
|
export {
|
|
538
|
-
Composition,
|
|
539
615
|
DefaultNotImplementedComponent,
|
|
540
616
|
NOT_IMPLEMENTED_COMPONENT,
|
|
541
|
-
Slot,
|
|
542
617
|
UniformComponent,
|
|
543
618
|
UniformComposition,
|
|
544
619
|
UniformSlot,
|
|
620
|
+
UniformText,
|
|
545
621
|
componentStore,
|
|
546
622
|
componentStoreResolver,
|
|
547
|
-
createApiEnhancer,
|
|
548
623
|
createComponentStore,
|
|
549
624
|
createComponentStoreResolver,
|
|
550
625
|
createUniformApiEnhancer,
|
|
551
626
|
registerUniformComponent,
|
|
552
|
-
useComposition,
|
|
553
627
|
useCompositionEventEffect,
|
|
554
|
-
useContextualEditing,
|
|
555
628
|
useUniformContextualEditing,
|
|
556
629
|
useUniformCurrentComponent,
|
|
557
630
|
useUniformCurrentComposition
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.1.1-alpha.1+3ec68fe9d",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"document": "api-extractor run --local"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@uniformdev/canvas": "
|
|
28
|
-
"@uniformdev/context": "
|
|
29
|
-
"@uniformdev/context-react": "
|
|
27
|
+
"@uniformdev/canvas": "19.1.1-alpha.1+3ec68fe9d",
|
|
28
|
+
"@uniformdev/context": "19.1.1-alpha.1+3ec68fe9d",
|
|
29
|
+
"@uniformdev/context-react": "19.1.1-alpha.1+3ec68fe9d"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">= 16 || 17 || 18",
|
|
33
33
|
"react-dom": ">=16"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/react": "18.0.
|
|
36
|
+
"@types/react": "18.0.37",
|
|
37
37
|
"react": "18.2.0",
|
|
38
38
|
"react-dom": "18.2.0"
|
|
39
39
|
},
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3ec68fe9d54c7128e57cc8a5c8116fe968f65865"
|
|
47
47
|
}
|