@uniformdev/canvas-react 19.35.2 → 19.35.3-alpha.82
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 +396 -0
- package/dist/index.esm.js +76 -59
- package/dist/index.js +104 -89
- package/dist/index.mjs +76 -59
- package/package.json +6 -6
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
2
|
+
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
3
|
+
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
|
|
4
|
+
export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
5
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props passed to a Canvas component implementation.
|
|
9
|
+
* TProps is the Canvas component's parameters object after
|
|
10
|
+
* all enhancers have been applied.
|
|
11
|
+
*/
|
|
12
|
+
type ComponentProps<TProps = unknown> = TProps & {
|
|
13
|
+
component: ComponentInstance;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Function that maps a Canvas component instance to its React component to render it.
|
|
17
|
+
* The resolver would commonly inspect the `type` and possibly `variant` of the component to decide.
|
|
18
|
+
*/
|
|
19
|
+
type RenderComponentResolver = (component: ComponentInstance) => React.ComponentType<ComponentProps<any>> | null;
|
|
20
|
+
/** Function that renders Canvas system internals */
|
|
21
|
+
type SystemRenderFunction = (component: ComponentInstance, key: Key, renderChild: (component: ComponentInstance, key: Key) => JSX.Element | null) => JSX.Element | null;
|
|
22
|
+
/** Configures rendering of system components (tests, pz) */
|
|
23
|
+
type SystemRenderConfig = {
|
|
24
|
+
test: SystemRenderFunction;
|
|
25
|
+
personalization: SystemRenderFunction;
|
|
26
|
+
};
|
|
27
|
+
type ComponentStore = {
|
|
28
|
+
register: (options: {
|
|
29
|
+
type: string;
|
|
30
|
+
variantId?: string;
|
|
31
|
+
component: React.ComponentType<ComponentProps<any>>;
|
|
32
|
+
}) => void;
|
|
33
|
+
get: (type: string, variantId?: string) => React.ComponentType<ComponentProps<any>> | undefined;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A default implementation of a component-not-implemented component.
|
|
38
|
+
* Useful for model-first workflows where frontend dev comes later.
|
|
39
|
+
* To make this work, it needs to be the default returned from the
|
|
40
|
+
* resolveRenderer() function when the component is unknown.
|
|
41
|
+
**/
|
|
42
|
+
declare function DefaultNotImplementedComponent(props: ComponentProps): React$1.JSX.Element | null;
|
|
43
|
+
|
|
44
|
+
type ParameterTextValue = string | undefined;
|
|
45
|
+
type UniformTextProps = {
|
|
46
|
+
/**
|
|
47
|
+
* The name of the HTML tag to render.
|
|
48
|
+
* @default "span"
|
|
49
|
+
*/
|
|
50
|
+
as?: React$1.ElementType;
|
|
51
|
+
/** The ID of the parameter. */
|
|
52
|
+
parameterId: string;
|
|
53
|
+
/**
|
|
54
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
isMultiline?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
60
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
placeholder?: string | ((parameter: {
|
|
64
|
+
id: string;
|
|
65
|
+
}) => string | undefined);
|
|
66
|
+
/**
|
|
67
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
68
|
+
* @default "(value) => value"
|
|
69
|
+
*/
|
|
70
|
+
render?: (value: ParameterTextValue) => React$1.ReactNode;
|
|
71
|
+
} & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children' | 'placeholder'>;
|
|
72
|
+
/**
|
|
73
|
+
* Adds inline editing capability to text parameters
|
|
74
|
+
* @deprecated This component is unstable, and not ready for production usage.
|
|
75
|
+
**/
|
|
76
|
+
declare const UniformText: ({ as: Tag, parameterId, isMultiline, placeholder, render, ...props }: UniformTextProps) => React$1.JSX.Element | null;
|
|
77
|
+
|
|
78
|
+
type UniformComponentProps<TRenderProps = unknown> = {
|
|
79
|
+
/** The data of the component instance */
|
|
80
|
+
data?: ComponentInstance | RootComponentInstance;
|
|
81
|
+
/** Resolves a React component to render a Canvas component, generally by inspecting type/variant */
|
|
82
|
+
resolveRenderer?: RenderComponentResolver;
|
|
83
|
+
/** Children to render. Can also be a function that takes ComponentProps as argument */
|
|
84
|
+
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => JSX.Element);
|
|
85
|
+
/**
|
|
86
|
+
* When to track behavior from enrichment tags on the current composition
|
|
87
|
+
* onView: adds enrichment score when the visitor views the tagged component in the browser viewport.
|
|
88
|
+
* onLoad: adds enrichment score as soon as the component mounts, regardless of viewport.
|
|
89
|
+
*
|
|
90
|
+
* NOTE: onView renders a `<div>` tag around components that have enrichment tags, to support IntersectionObserver.
|
|
91
|
+
* onLoad does not need to do this, and renders no wrapping tag.
|
|
92
|
+
*
|
|
93
|
+
* Default: onView
|
|
94
|
+
*/
|
|
95
|
+
behaviorTracking?: 'onLoad' | 'onView';
|
|
96
|
+
/**
|
|
97
|
+
* The default placeholder to pass to the parameter component that support inline editing (such as UniformText).
|
|
98
|
+
*/
|
|
99
|
+
contextualEditingDefaultPlaceholder?: UniformTextProps['placeholder'];
|
|
100
|
+
};
|
|
101
|
+
type UniformComponentContextValue = {
|
|
102
|
+
data?: UniformComponentProps['data'];
|
|
103
|
+
resolveRenderer?: UniformComponentProps['resolveRenderer'];
|
|
104
|
+
behaviorTracking?: UniformComponentProps['behaviorTracking'];
|
|
105
|
+
contextualEditingDefaultPlaceholder?: UniformComponentProps['contextualEditingDefaultPlaceholder'];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Gets the data of the closest `<UniformComponent />` ancestor.
|
|
109
|
+
*/
|
|
110
|
+
declare function useUniformCurrentComponent(): UniformComponentContextValue;
|
|
111
|
+
/**
|
|
112
|
+
* Allows the rendering of a Canvas component instance (root or not), and its children if it has any.
|
|
113
|
+
* Note that the actual rendering happens inside `<UniformSlot />`, this component only provides the services needed to achieve that.
|
|
114
|
+
* This component is used internally by `<UniformComposition />`, which you should use in most cases.
|
|
115
|
+
*/
|
|
116
|
+
declare function UniformComponent<TRenderProps = unknown>({ data, resolveRenderer, children, behaviorTracking, contextualEditingDefaultPlaceholder, }: UniformComponentProps<TRenderProps>): React$1.JSX.Element | null;
|
|
117
|
+
|
|
118
|
+
type UseUniformContextualEditingProps = {
|
|
119
|
+
initialCompositionValue?: RootComponentInstance;
|
|
120
|
+
/**
|
|
121
|
+
* A function to enhance the composition after receiving it from Canvas editor.
|
|
122
|
+
* 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.
|
|
123
|
+
*/
|
|
124
|
+
enhance?: ({ composition, hash, }: Pick<UpdateCompositionMessage, 'composition' | 'hash'>) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Adds contextual editing capability to a Uniform app.
|
|
128
|
+
* This hook is already integrated in `<UniformComposition />`, you won't need to use it directly, unless you have a custom setup.
|
|
129
|
+
*/
|
|
130
|
+
declare const useUniformContextualEditing: ({ initialCompositionValue, enhance, }: UseUniformContextualEditingProps) => {
|
|
131
|
+
composition: {
|
|
132
|
+
type: string;
|
|
133
|
+
parameters?: {
|
|
134
|
+
[key: string]: {
|
|
135
|
+
value: unknown;
|
|
136
|
+
type: string;
|
|
137
|
+
connectedData?: {
|
|
138
|
+
pointer: string;
|
|
139
|
+
syntax: "jptr";
|
|
140
|
+
} | undefined;
|
|
141
|
+
};
|
|
142
|
+
} | undefined;
|
|
143
|
+
variant?: string | undefined;
|
|
144
|
+
projectMapNodes?: {
|
|
145
|
+
id: string;
|
|
146
|
+
path: string;
|
|
147
|
+
projectMapId: string;
|
|
148
|
+
}[] | undefined;
|
|
149
|
+
slots?: {
|
|
150
|
+
[key: string]: {
|
|
151
|
+
type: string;
|
|
152
|
+
parameters?: {
|
|
153
|
+
[key: string]: {
|
|
154
|
+
value: unknown;
|
|
155
|
+
type: string;
|
|
156
|
+
connectedData?: {
|
|
157
|
+
pointer: string;
|
|
158
|
+
syntax: "jptr";
|
|
159
|
+
} | undefined;
|
|
160
|
+
};
|
|
161
|
+
} | undefined;
|
|
162
|
+
variant?: string | undefined;
|
|
163
|
+
slots?: {
|
|
164
|
+
[key: string]: any[];
|
|
165
|
+
} | undefined;
|
|
166
|
+
_id?: string | undefined;
|
|
167
|
+
_pattern?: string | undefined;
|
|
168
|
+
_dataResources?: {
|
|
169
|
+
[key: string]: {
|
|
170
|
+
type: string;
|
|
171
|
+
isPatternParameter?: boolean | undefined;
|
|
172
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
173
|
+
variables?: {
|
|
174
|
+
[key: string]: string;
|
|
175
|
+
} | undefined;
|
|
176
|
+
};
|
|
177
|
+
} | undefined;
|
|
178
|
+
_patternDataResources?: {
|
|
179
|
+
[key: string]: {
|
|
180
|
+
type: string;
|
|
181
|
+
isPatternParameter?: boolean | undefined;
|
|
182
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
183
|
+
variables?: {
|
|
184
|
+
[key: string]: string;
|
|
185
|
+
} | undefined;
|
|
186
|
+
};
|
|
187
|
+
} | undefined;
|
|
188
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
189
|
+
_overrides?: {
|
|
190
|
+
[key: string]: {
|
|
191
|
+
parameters?: {
|
|
192
|
+
[key: string]: {
|
|
193
|
+
value: unknown;
|
|
194
|
+
type: string;
|
|
195
|
+
connectedData?: {
|
|
196
|
+
pointer: string;
|
|
197
|
+
syntax: "jptr";
|
|
198
|
+
} | undefined;
|
|
199
|
+
};
|
|
200
|
+
} | undefined;
|
|
201
|
+
variant?: string | undefined;
|
|
202
|
+
};
|
|
203
|
+
} | undefined;
|
|
204
|
+
_overridability?: {
|
|
205
|
+
parameters?: {
|
|
206
|
+
[key: string]: "yes" | "no";
|
|
207
|
+
} | undefined;
|
|
208
|
+
variants?: boolean | undefined;
|
|
209
|
+
} | undefined;
|
|
210
|
+
}[];
|
|
211
|
+
} | undefined;
|
|
212
|
+
_id: string;
|
|
213
|
+
_slug?: string | null | undefined;
|
|
214
|
+
_name: string;
|
|
215
|
+
_dataResources?: {
|
|
216
|
+
[key: string]: {
|
|
217
|
+
type: string;
|
|
218
|
+
isPatternParameter?: boolean | undefined;
|
|
219
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
220
|
+
variables?: {
|
|
221
|
+
[key: string]: string;
|
|
222
|
+
} | undefined;
|
|
223
|
+
};
|
|
224
|
+
} | undefined;
|
|
225
|
+
_overrides?: {
|
|
226
|
+
[key: string]: {
|
|
227
|
+
parameters?: {
|
|
228
|
+
[key: string]: {
|
|
229
|
+
value: unknown;
|
|
230
|
+
type: string;
|
|
231
|
+
connectedData?: {
|
|
232
|
+
pointer: string;
|
|
233
|
+
syntax: "jptr";
|
|
234
|
+
} | undefined;
|
|
235
|
+
};
|
|
236
|
+
} | undefined;
|
|
237
|
+
variant?: string | undefined;
|
|
238
|
+
};
|
|
239
|
+
} | undefined;
|
|
240
|
+
_overridability?: {
|
|
241
|
+
parameters?: {
|
|
242
|
+
[key: string]: "yes" | "no";
|
|
243
|
+
} | undefined;
|
|
244
|
+
variants?: boolean | undefined;
|
|
245
|
+
} | undefined;
|
|
246
|
+
} | undefined;
|
|
247
|
+
isContextualEditing: boolean;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
type UniformCompositionProps<TRenderProps = unknown> = UniformComponentProps<TRenderProps> & {
|
|
251
|
+
/** The composition data */
|
|
252
|
+
data?: RootComponentInstance;
|
|
253
|
+
contextualEditingEnhancer?: UseUniformContextualEditingProps['enhance'];
|
|
254
|
+
};
|
|
255
|
+
type UniformCompositionContextValue = {
|
|
256
|
+
data: UniformCompositionProps['data'] | undefined;
|
|
257
|
+
resolveRenderer?: UniformCompositionProps['resolveRenderer'];
|
|
258
|
+
behaviorTracking?: UniformCompositionProps['behaviorTracking'];
|
|
259
|
+
isContextualEditing: boolean;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Gets the data of the closest `<UniformComposition />` ancestor.
|
|
263
|
+
*/
|
|
264
|
+
declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
265
|
+
/**
|
|
266
|
+
* The main component to render a Canvas composition.
|
|
267
|
+
* It renders the full tree of components, and provides some services to the children, such as `useUniformCurrentComposition`.
|
|
268
|
+
* It also takes care of enabling [Contextual Editing](https://docs.uniform.app/capabilities/composition/contextual-editing).
|
|
269
|
+
*/
|
|
270
|
+
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
271
|
+
|
|
272
|
+
type RichTextComponentProps<TNode extends RichTextNode = RichTextNode> = {
|
|
273
|
+
node: TNode;
|
|
274
|
+
};
|
|
275
|
+
type RichTextRendererComponent<TNode extends RichTextNode = RichTextNode> = React$1.ComponentType<PropsWithChildren<RichTextComponentProps<TNode>>>;
|
|
276
|
+
/**
|
|
277
|
+
* Function that maps a Rich Text node instance to its React component to render it.
|
|
278
|
+
* The resolver would commonly inspect the `type` of the component to decide.
|
|
279
|
+
*/
|
|
280
|
+
type RenderRichTextComponentResolver = (node: RichTextNode) => RichTextRendererComponent | null | undefined;
|
|
281
|
+
|
|
282
|
+
type UniformRichTextProps = {
|
|
283
|
+
/**
|
|
284
|
+
* The name of the HTML tag to render.
|
|
285
|
+
* @default "div"
|
|
286
|
+
*/
|
|
287
|
+
as?: React$1.ElementType;
|
|
288
|
+
/** The ID of the parameter. */
|
|
289
|
+
parameterId: string;
|
|
290
|
+
/**
|
|
291
|
+
* A function which can provide a custom react component
|
|
292
|
+
* for rendering a rich text node
|
|
293
|
+
*/
|
|
294
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
295
|
+
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
296
|
+
/**
|
|
297
|
+
* Adds rendering support for Uniform Rich Text parameters
|
|
298
|
+
*/
|
|
299
|
+
declare const UniformRichText: React$1.ForwardRefExoticComponent<{
|
|
300
|
+
/**
|
|
301
|
+
* The name of the HTML tag to render.
|
|
302
|
+
* @default "div"
|
|
303
|
+
*/
|
|
304
|
+
as?: React$1.ElementType<any> | undefined;
|
|
305
|
+
/** The ID of the parameter. */
|
|
306
|
+
parameterId: string;
|
|
307
|
+
/**
|
|
308
|
+
* A function which can provide a custom react component
|
|
309
|
+
* for rendering a rich text node
|
|
310
|
+
*/
|
|
311
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver | undefined;
|
|
312
|
+
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, "children"> & React$1.RefAttributes<unknown>>;
|
|
313
|
+
|
|
314
|
+
type UniformRichTextNodeProps = {
|
|
315
|
+
node: RichTextNode;
|
|
316
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Render a single RichText node
|
|
320
|
+
*/
|
|
321
|
+
declare function UniformRichTextNode({ node, ...props }: UniformRichTextNodeProps): React$1.JSX.Element | null;
|
|
322
|
+
|
|
323
|
+
type CustomSlotChildRenderFunc = (options: {
|
|
324
|
+
child: ReactNode;
|
|
325
|
+
component: ComponentInstance;
|
|
326
|
+
key: Key;
|
|
327
|
+
}) => JSX.Element;
|
|
328
|
+
type UniformSlotProps<TSlotNames extends string> = {
|
|
329
|
+
/** Name of the slot to render */
|
|
330
|
+
name: TSlotNames;
|
|
331
|
+
/**
|
|
332
|
+
* Function to resolve the React component to render for a given Canvas component type.
|
|
333
|
+
* If not specified, the resolveRenderer function on the nearest Layout will be used, if any.
|
|
334
|
+
*/
|
|
335
|
+
resolveRenderer?: RenderComponentResolver;
|
|
336
|
+
/** Optional render props enables wrapping all child components in the slot with some markup */
|
|
337
|
+
children?: CustomSlotChildRenderFunc;
|
|
338
|
+
/**
|
|
339
|
+
* Optional ReactNode to use as a placeholder in Canvas editor when the slot is empty.
|
|
340
|
+
* The node is used to render a placeholder with realistic dimensions and it's never shown to users.
|
|
341
|
+
* Pass `null` to disable the placeholder.
|
|
342
|
+
*/
|
|
343
|
+
emptyPlaceholder?: React$1.ReactNode;
|
|
344
|
+
};
|
|
345
|
+
/** Renders a named Slot within a Composition. */
|
|
346
|
+
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, children, emptyPlaceholder, }: UniformSlotProps<TSlotNames>): JSX.Element | null;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Returns the attributes needed to annotate a Uniform parameter for inline editing.
|
|
350
|
+
* Supports only text parameters at the moment.
|
|
351
|
+
* @deprecated Unstable, and not ready for production usage.
|
|
352
|
+
**/
|
|
353
|
+
declare const getParameterAttributes: typeof getParameterAttributes$1;
|
|
354
|
+
|
|
355
|
+
type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback'> & {
|
|
356
|
+
enabled: boolean;
|
|
357
|
+
effect: () => void;
|
|
358
|
+
};
|
|
359
|
+
/** Hook to manage a subscription to a realtime event on a composition */
|
|
360
|
+
declare function useCompositionEventEffect({ enabled, projectId, compositionId, effect, }: UseCompositionEventEffectOptions): void;
|
|
361
|
+
|
|
362
|
+
type UseUniformContextualEditingStateProps = {
|
|
363
|
+
/**
|
|
364
|
+
* When set to true, the hook will return the global contextual state no matter where its used.
|
|
365
|
+
* When set to false, it will return only the state relevant to the current component (determined using `useUniformCurrentComponent`).
|
|
366
|
+
* @default false
|
|
367
|
+
**/
|
|
368
|
+
global?: boolean;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Returns the state of contextual editing, when the app is open inside Canvas Editor.
|
|
372
|
+
* This hook can be used to improve the editing experience of your team.
|
|
373
|
+
* For example: You can use `selectedComponentReference` to control which element to show inside a carousel or an accordion.
|
|
374
|
+
*/
|
|
375
|
+
declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => {
|
|
376
|
+
isContextualEditing: boolean;
|
|
377
|
+
selectedComponentReference: Omit<_uniformdev_canvas.ContextualEditingComponentReference, "elements"> | undefined;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
declare const componentStore: ComponentStore;
|
|
381
|
+
declare const registerUniformComponent: ({ type, variantId, component, }: {
|
|
382
|
+
type: string;
|
|
383
|
+
variantId?: string | undefined;
|
|
384
|
+
component: React.ComponentType<ComponentProps<any>>;
|
|
385
|
+
}) => void;
|
|
386
|
+
declare const componentStoreResolver: RenderComponentResolver;
|
|
387
|
+
|
|
388
|
+
/** Can be used to override default component Not Implemented fallback */
|
|
389
|
+
declare const NOT_IMPLEMENTED_COMPONENT = "__not_implemented__";
|
|
390
|
+
declare const createComponentStore: () => ComponentStore;
|
|
391
|
+
declare const createComponentStoreResolver: (options: {
|
|
392
|
+
store: ComponentStore;
|
|
393
|
+
defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
|
|
394
|
+
}) => RenderComponentResolver;
|
|
395
|
+
|
|
396
|
+
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, RenderRichTextComponentResolver, RichTextComponentProps, RichTextRendererComponent, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformRichText, UniformRichTextNode, UniformRichTextNodeProps, UniformRichTextProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, UseUniformContextualEditingStateProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
|
package/dist/index.esm.js
CHANGED
|
@@ -557,11 +557,61 @@ function resolveChildren({
|
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
560
|
+
import {
|
|
561
|
+
getParameterAttributes
|
|
562
|
+
} from "@uniformdev/canvas";
|
|
560
563
|
import {
|
|
561
564
|
isRichTextValue,
|
|
562
565
|
isRichTextValueConsideredEmpty
|
|
563
566
|
} from "@uniformdev/richtext";
|
|
564
|
-
import React16, { useMemo as
|
|
567
|
+
import React16, { useMemo as useMemo3 } from "react";
|
|
568
|
+
|
|
569
|
+
// src/hooks/useUniformContextualEditingState.ts
|
|
570
|
+
import {
|
|
571
|
+
createCanvasChannel as createCanvasChannel2,
|
|
572
|
+
isUpdateContextualEditingStateInternalMessage
|
|
573
|
+
} from "@uniformdev/canvas";
|
|
574
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
575
|
+
var useUniformContextualEditingState = ({
|
|
576
|
+
global = false
|
|
577
|
+
} = {}) => {
|
|
578
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
579
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
580
|
+
const [selectedComponentReference, setSelectedComponentReference] = useState2();
|
|
581
|
+
const channel = useMemo2(() => {
|
|
582
|
+
if (!isContextualEditing) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const channel2 = createCanvasChannel2({
|
|
586
|
+
broadcastTo: [window],
|
|
587
|
+
listenTo: [window]
|
|
588
|
+
});
|
|
589
|
+
return channel2;
|
|
590
|
+
}, [isContextualEditing]);
|
|
591
|
+
useEffect2(() => {
|
|
592
|
+
if (!channel) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
596
|
+
var _a;
|
|
597
|
+
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
601
|
+
setSelectedComponentReference(void 0);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
605
|
+
});
|
|
606
|
+
return () => {
|
|
607
|
+
unsubscribe();
|
|
608
|
+
};
|
|
609
|
+
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
610
|
+
return {
|
|
611
|
+
isContextualEditing,
|
|
612
|
+
selectedComponentReference
|
|
613
|
+
};
|
|
614
|
+
};
|
|
565
615
|
|
|
566
616
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
567
617
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
@@ -672,18 +722,32 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
672
722
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
673
723
|
var UniformRichText = React16.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
674
724
|
const { data: componentData } = useUniformCurrentComponent();
|
|
675
|
-
const
|
|
725
|
+
const { selectedComponentReference } = useUniformContextualEditingState({ global: true });
|
|
726
|
+
const parameter = useMemo3(() => {
|
|
676
727
|
var _a;
|
|
677
728
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
678
729
|
}, [componentData, parameterId]);
|
|
679
|
-
const value =
|
|
730
|
+
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
680
731
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
681
732
|
return null;
|
|
682
|
-
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
733
|
+
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
734
|
+
Tag,
|
|
735
|
+
{
|
|
736
|
+
ref,
|
|
737
|
+
...props,
|
|
738
|
+
...getParameterAttributes({
|
|
739
|
+
component: componentData,
|
|
740
|
+
id: parameterId
|
|
741
|
+
}),
|
|
742
|
+
tabIndex: 0,
|
|
743
|
+
"data-uniform-selected-parameter": (selectedComponentReference == null ? void 0 : selectedComponentReference.id) === parameterId && selectedComponentReference.parentId === (componentData == null ? void 0 : componentData._id)
|
|
744
|
+
},
|
|
745
|
+
/* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
746
|
+
);
|
|
683
747
|
});
|
|
684
748
|
|
|
685
749
|
// src/components/UniformText.tsx
|
|
686
|
-
import React17, { useCallback, useMemo as
|
|
750
|
+
import React17, { useCallback, useMemo as useMemo4, useState as useState3 } from "react";
|
|
687
751
|
var UniformText = ({
|
|
688
752
|
as: Tag = "span",
|
|
689
753
|
parameterId,
|
|
@@ -695,8 +759,8 @@ var UniformText = ({
|
|
|
695
759
|
var _a, _b;
|
|
696
760
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
697
761
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
698
|
-
const [isFocused, setIsFocused] =
|
|
699
|
-
const parameter =
|
|
762
|
+
const [isFocused, setIsFocused] = useState3(false);
|
|
763
|
+
const parameter = useMemo4(() => {
|
|
700
764
|
var _a2;
|
|
701
765
|
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
702
766
|
}, [componentData, parameterId]);
|
|
@@ -724,7 +788,7 @@ var UniformText = ({
|
|
|
724
788
|
Tag,
|
|
725
789
|
{
|
|
726
790
|
...props,
|
|
727
|
-
...
|
|
791
|
+
...getParameterAttributes2({
|
|
728
792
|
component: componentData,
|
|
729
793
|
id: parameterId,
|
|
730
794
|
isMultiline
|
|
@@ -743,7 +807,7 @@ var UniformText = ({
|
|
|
743
807
|
import {
|
|
744
808
|
getParameterAttributes as defaultGetParameterAttributes
|
|
745
809
|
} from "@uniformdev/canvas";
|
|
746
|
-
var
|
|
810
|
+
var getParameterAttributes2 = (options) => {
|
|
747
811
|
return {
|
|
748
812
|
...defaultGetParameterAttributes(options),
|
|
749
813
|
suppressContentEditableWarning: true
|
|
@@ -756,14 +820,14 @@ import {
|
|
|
756
820
|
createEventBus,
|
|
757
821
|
subscribeToComposition
|
|
758
822
|
} from "@uniformdev/canvas";
|
|
759
|
-
import { useEffect as
|
|
823
|
+
import { useEffect as useEffect3 } from "react";
|
|
760
824
|
function useCompositionEventEffect({
|
|
761
825
|
enabled,
|
|
762
826
|
projectId,
|
|
763
827
|
compositionId,
|
|
764
828
|
effect
|
|
765
829
|
}) {
|
|
766
|
-
|
|
830
|
+
useEffect3(() => {
|
|
767
831
|
if (!enabled || !compositionId || !projectId) {
|
|
768
832
|
return;
|
|
769
833
|
}
|
|
@@ -789,53 +853,6 @@ function useCompositionEventEffect({
|
|
|
789
853
|
};
|
|
790
854
|
}, [compositionId, enabled, projectId, effect]);
|
|
791
855
|
}
|
|
792
|
-
|
|
793
|
-
// src/hooks/useUniformContextualEditingState.ts
|
|
794
|
-
import {
|
|
795
|
-
createCanvasChannel as createCanvasChannel2,
|
|
796
|
-
isUpdateContextualEditingStateInternalMessage
|
|
797
|
-
} from "@uniformdev/canvas";
|
|
798
|
-
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
799
|
-
var useUniformContextualEditingState = ({
|
|
800
|
-
global = false
|
|
801
|
-
} = {}) => {
|
|
802
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
803
|
-
const { data: componentData } = useUniformCurrentComponent();
|
|
804
|
-
const [selectedComponentReference, setSelectedComponentReference] = useState3();
|
|
805
|
-
const channel = useMemo4(() => {
|
|
806
|
-
if (!isContextualEditing) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
const channel2 = createCanvasChannel2({
|
|
810
|
-
broadcastTo: [window],
|
|
811
|
-
listenTo: [window]
|
|
812
|
-
});
|
|
813
|
-
return channel2;
|
|
814
|
-
}, [isContextualEditing]);
|
|
815
|
-
useEffect3(() => {
|
|
816
|
-
if (!channel) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
820
|
-
var _a;
|
|
821
|
-
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
825
|
-
setSelectedComponentReference(void 0);
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
829
|
-
});
|
|
830
|
-
return () => {
|
|
831
|
-
unsubscribe();
|
|
832
|
-
};
|
|
833
|
-
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
834
|
-
return {
|
|
835
|
-
isContextualEditing,
|
|
836
|
-
selectedComponentReference
|
|
837
|
-
};
|
|
838
|
-
};
|
|
839
856
|
export {
|
|
840
857
|
DefaultNotImplementedComponent,
|
|
841
858
|
NOT_IMPLEMENTED_COMPONENT,
|
|
@@ -850,7 +867,7 @@ export {
|
|
|
850
867
|
createComponentStore,
|
|
851
868
|
createComponentStoreResolver,
|
|
852
869
|
createUniformApiEnhancer,
|
|
853
|
-
getParameterAttributes,
|
|
870
|
+
getParameterAttributes2 as getParameterAttributes,
|
|
854
871
|
registerUniformComponent,
|
|
855
872
|
useCompositionEventEffect,
|
|
856
873
|
useUniformContextualEditing,
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
createComponentStore: () => createComponentStore,
|
|
44
44
|
createComponentStoreResolver: () => createComponentStoreResolver,
|
|
45
45
|
createUniformApiEnhancer: () => import_canvas3.createUniformApiEnhancer,
|
|
46
|
-
getParameterAttributes: () =>
|
|
46
|
+
getParameterAttributes: () => getParameterAttributes2,
|
|
47
47
|
registerUniformComponent: () => registerUniformComponent,
|
|
48
48
|
useCompositionEventEffect: () => useCompositionEventEffect,
|
|
49
49
|
useUniformContextualEditing: () => useUniformContextualEditing,
|
|
@@ -589,56 +589,101 @@ function resolveChildren({
|
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
592
|
+
var import_canvas8 = require("@uniformdev/canvas");
|
|
592
593
|
var import_richtext5 = require("@uniformdev/richtext");
|
|
593
|
-
var
|
|
594
|
+
var import_react17 = __toESM(require("react"));
|
|
595
|
+
|
|
596
|
+
// src/hooks/useUniformContextualEditingState.ts
|
|
597
|
+
var import_canvas7 = require("@uniformdev/canvas");
|
|
598
|
+
var import_react7 = require("react");
|
|
599
|
+
var useUniformContextualEditingState = ({
|
|
600
|
+
global = false
|
|
601
|
+
} = {}) => {
|
|
602
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
603
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
604
|
+
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react7.useState)();
|
|
605
|
+
const channel = (0, import_react7.useMemo)(() => {
|
|
606
|
+
if (!isContextualEditing) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const channel2 = (0, import_canvas7.createCanvasChannel)({
|
|
610
|
+
broadcastTo: [window],
|
|
611
|
+
listenTo: [window]
|
|
612
|
+
});
|
|
613
|
+
return channel2;
|
|
614
|
+
}, [isContextualEditing]);
|
|
615
|
+
(0, import_react7.useEffect)(() => {
|
|
616
|
+
if (!channel) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
620
|
+
var _a;
|
|
621
|
+
if (!(0, import_canvas7.isUpdateContextualEditingStateInternalMessage)(message)) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
625
|
+
setSelectedComponentReference(void 0);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
629
|
+
});
|
|
630
|
+
return () => {
|
|
631
|
+
unsubscribe();
|
|
632
|
+
};
|
|
633
|
+
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
634
|
+
return {
|
|
635
|
+
isContextualEditing,
|
|
636
|
+
selectedComponentReference
|
|
637
|
+
};
|
|
638
|
+
};
|
|
594
639
|
|
|
595
640
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
596
641
|
var import_richtext4 = require("@uniformdev/richtext");
|
|
597
|
-
var
|
|
642
|
+
var import_react16 = __toESM(require("react"));
|
|
598
643
|
|
|
599
644
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
600
|
-
var
|
|
645
|
+
var import_react8 = __toESM(require("react"));
|
|
601
646
|
var HeadingRichTextNode = ({ children, node }) => {
|
|
602
647
|
const { tag } = node;
|
|
603
648
|
const HTag = tag != null ? tag : "h1";
|
|
604
|
-
return /* @__PURE__ */
|
|
649
|
+
return /* @__PURE__ */ import_react8.default.createElement(HTag, null, children);
|
|
605
650
|
};
|
|
606
651
|
|
|
607
652
|
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
608
|
-
var
|
|
653
|
+
var import_react9 = __toESM(require("react"));
|
|
609
654
|
var LinebreakRichTextNode = () => {
|
|
610
|
-
return /* @__PURE__ */
|
|
655
|
+
return /* @__PURE__ */ import_react9.default.createElement("br", null);
|
|
611
656
|
};
|
|
612
657
|
|
|
613
658
|
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
614
659
|
var import_richtext = require("@uniformdev/richtext");
|
|
615
|
-
var
|
|
660
|
+
var import_react10 = __toESM(require("react"));
|
|
616
661
|
var LinkRichTextNode = ({ children, node }) => {
|
|
617
662
|
const { link } = node;
|
|
618
|
-
return /* @__PURE__ */
|
|
663
|
+
return /* @__PURE__ */ import_react10.default.createElement("a", { href: (0, import_richtext.linkParamValueToHref)(link) }, children);
|
|
619
664
|
};
|
|
620
665
|
|
|
621
666
|
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
622
|
-
var
|
|
667
|
+
var import_react11 = __toESM(require("react"));
|
|
623
668
|
var ListItemRichTextNode = ({ children, node }) => {
|
|
624
669
|
const { value } = node;
|
|
625
|
-
return /* @__PURE__ */
|
|
670
|
+
return /* @__PURE__ */ import_react11.default.createElement("li", { value: Number.isFinite(value) && value > 0 ? value : void 0 }, children);
|
|
626
671
|
};
|
|
627
672
|
|
|
628
673
|
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
629
|
-
var
|
|
674
|
+
var import_react12 = __toESM(require("react"));
|
|
630
675
|
var ListRichTextNode = ({ children, node }) => {
|
|
631
676
|
const { tag, start } = node;
|
|
632
677
|
const ListTag = tag != null ? tag : "ul";
|
|
633
|
-
return /* @__PURE__ */
|
|
678
|
+
return /* @__PURE__ */ import_react12.default.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
634
679
|
};
|
|
635
680
|
|
|
636
681
|
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
637
682
|
var import_richtext2 = require("@uniformdev/richtext");
|
|
638
|
-
var
|
|
683
|
+
var import_react13 = __toESM(require("react"));
|
|
639
684
|
var ParagraphRichTextNode = ({ children, node }) => {
|
|
640
685
|
const { format, direction } = node;
|
|
641
|
-
return /* @__PURE__ */
|
|
686
|
+
return /* @__PURE__ */ import_react13.default.createElement(
|
|
642
687
|
"p",
|
|
643
688
|
{
|
|
644
689
|
dir: (0, import_richtext2.isPureDirection)(direction) ? direction : void 0,
|
|
@@ -649,18 +694,18 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
649
694
|
};
|
|
650
695
|
|
|
651
696
|
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
652
|
-
var
|
|
697
|
+
var import_react14 = __toESM(require("react"));
|
|
653
698
|
var TabRichTextNode = () => {
|
|
654
|
-
return /* @__PURE__ */
|
|
699
|
+
return /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, " ");
|
|
655
700
|
};
|
|
656
701
|
|
|
657
702
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
658
703
|
var import_richtext3 = require("@uniformdev/richtext");
|
|
659
|
-
var
|
|
704
|
+
var import_react15 = __toESM(require("react"));
|
|
660
705
|
var TextRichTextNode = ({ node }) => {
|
|
661
706
|
const { text, format } = node;
|
|
662
707
|
const tags = (0, import_richtext3.getRichTextTagsFromTextFormat)(format);
|
|
663
|
-
return /* @__PURE__ */
|
|
708
|
+
return /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ import_react15.default.createElement(Tag, null, children), text) : text);
|
|
664
709
|
};
|
|
665
710
|
|
|
666
711
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
@@ -675,8 +720,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
675
720
|
if (!NodeRenderer) {
|
|
676
721
|
return null;
|
|
677
722
|
}
|
|
678
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
679
|
-
return /* @__PURE__ */
|
|
723
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ import_react16.default.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
724
|
+
return /* @__PURE__ */ import_react16.default.createElement(NodeRenderer, { node }, children);
|
|
680
725
|
}
|
|
681
726
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
682
727
|
["heading", HeadingRichTextNode],
|
|
@@ -685,12 +730,12 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
685
730
|
["list", ListRichTextNode],
|
|
686
731
|
["listitem", ListItemRichTextNode],
|
|
687
732
|
["paragraph", ParagraphRichTextNode],
|
|
688
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
733
|
+
["quote", ({ children }) => /* @__PURE__ */ import_react16.default.createElement("blockquote", null, children)],
|
|
689
734
|
[
|
|
690
735
|
"code",
|
|
691
|
-
({ children }) => /* @__PURE__ */
|
|
736
|
+
({ children }) => /* @__PURE__ */ import_react16.default.createElement("pre", null, /* @__PURE__ */ import_react16.default.createElement("code", null, children))
|
|
692
737
|
],
|
|
693
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
738
|
+
["root", ({ children }) => /* @__PURE__ */ import_react16.default.createElement(import_react16.default.Fragment, null, children)],
|
|
694
739
|
["text", TextRichTextNode],
|
|
695
740
|
["tab", TabRichTextNode]
|
|
696
741
|
]);
|
|
@@ -699,20 +744,34 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
699
744
|
};
|
|
700
745
|
|
|
701
746
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
702
|
-
var UniformRichText =
|
|
747
|
+
var UniformRichText = import_react17.default.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
703
748
|
const { data: componentData } = useUniformCurrentComponent();
|
|
704
|
-
const
|
|
749
|
+
const { selectedComponentReference } = useUniformContextualEditingState({ global: true });
|
|
750
|
+
const parameter = (0, import_react17.useMemo)(() => {
|
|
705
751
|
var _a;
|
|
706
752
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
707
753
|
}, [componentData, parameterId]);
|
|
708
|
-
const value = (0,
|
|
754
|
+
const value = (0, import_react17.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
709
755
|
if (!value || !(0, import_richtext5.isRichTextValue)(value) || (0, import_richtext5.isRichTextValueConsideredEmpty)(value))
|
|
710
756
|
return null;
|
|
711
|
-
return Tag === null ? /* @__PURE__ */
|
|
757
|
+
return Tag === null ? /* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react17.default.createElement(
|
|
758
|
+
Tag,
|
|
759
|
+
{
|
|
760
|
+
ref,
|
|
761
|
+
...props,
|
|
762
|
+
...(0, import_canvas8.getParameterAttributes)({
|
|
763
|
+
component: componentData,
|
|
764
|
+
id: parameterId
|
|
765
|
+
}),
|
|
766
|
+
tabIndex: 0,
|
|
767
|
+
"data-uniform-selected-parameter": (selectedComponentReference == null ? void 0 : selectedComponentReference.id) === parameterId && selectedComponentReference.parentId === (componentData == null ? void 0 : componentData._id)
|
|
768
|
+
},
|
|
769
|
+
/* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
770
|
+
);
|
|
712
771
|
});
|
|
713
772
|
|
|
714
773
|
// src/components/UniformText.tsx
|
|
715
|
-
var
|
|
774
|
+
var import_react18 = __toESM(require("react"));
|
|
716
775
|
var UniformText = ({
|
|
717
776
|
as: Tag = "span",
|
|
718
777
|
parameterId,
|
|
@@ -724,18 +783,18 @@ var UniformText = ({
|
|
|
724
783
|
var _a, _b;
|
|
725
784
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
726
785
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
727
|
-
const [isFocused, setIsFocused] = (0,
|
|
728
|
-
const parameter = (0,
|
|
786
|
+
const [isFocused, setIsFocused] = (0, import_react18.useState)(false);
|
|
787
|
+
const parameter = (0, import_react18.useMemo)(() => {
|
|
729
788
|
var _a2;
|
|
730
789
|
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
731
790
|
}, [componentData, parameterId]);
|
|
732
791
|
const value = parameter == null ? void 0 : parameter.value;
|
|
733
792
|
const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
734
793
|
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
735
|
-
const handleOnFocus = (0,
|
|
794
|
+
const handleOnFocus = (0, import_react18.useCallback)(() => {
|
|
736
795
|
setIsFocused(true);
|
|
737
796
|
}, [setIsFocused]);
|
|
738
|
-
const handleOnBlur = (0,
|
|
797
|
+
const handleOnBlur = (0, import_react18.useCallback)(() => {
|
|
739
798
|
setIsFocused(false);
|
|
740
799
|
}, [setIsFocused]);
|
|
741
800
|
if (!parameter) {
|
|
@@ -745,15 +804,15 @@ var UniformText = ({
|
|
|
745
804
|
return null;
|
|
746
805
|
}
|
|
747
806
|
if (!isContextualEditing) {
|
|
748
|
-
return /* @__PURE__ */
|
|
807
|
+
return /* @__PURE__ */ import_react18.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
749
808
|
}
|
|
750
809
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
751
810
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
752
|
-
return /* @__PURE__ */
|
|
811
|
+
return /* @__PURE__ */ import_react18.default.createElement(
|
|
753
812
|
Tag,
|
|
754
813
|
{
|
|
755
814
|
...props,
|
|
756
|
-
...
|
|
815
|
+
...getParameterAttributes2({
|
|
757
816
|
component: componentData,
|
|
758
817
|
id: parameterId,
|
|
759
818
|
isMultiline
|
|
@@ -769,35 +828,35 @@ var UniformText = ({
|
|
|
769
828
|
};
|
|
770
829
|
|
|
771
830
|
// src/helpers/getParameterAttributes.ts
|
|
772
|
-
var
|
|
773
|
-
var
|
|
831
|
+
var import_canvas9 = require("@uniformdev/canvas");
|
|
832
|
+
var getParameterAttributes2 = (options) => {
|
|
774
833
|
return {
|
|
775
|
-
...(0,
|
|
834
|
+
...(0, import_canvas9.getParameterAttributes)(options),
|
|
776
835
|
suppressContentEditableWarning: true
|
|
777
836
|
};
|
|
778
837
|
};
|
|
779
838
|
|
|
780
839
|
// src/hooks/useCompositionEventEffect.ts
|
|
781
|
-
var
|
|
782
|
-
var
|
|
840
|
+
var import_canvas10 = require("@uniformdev/canvas");
|
|
841
|
+
var import_react19 = require("react");
|
|
783
842
|
function useCompositionEventEffect({
|
|
784
843
|
enabled,
|
|
785
844
|
projectId,
|
|
786
845
|
compositionId,
|
|
787
846
|
effect
|
|
788
847
|
}) {
|
|
789
|
-
(0,
|
|
848
|
+
(0, import_react19.useEffect)(() => {
|
|
790
849
|
if (!enabled || !compositionId || !projectId) {
|
|
791
850
|
return;
|
|
792
851
|
}
|
|
793
852
|
let goodbye = void 0;
|
|
794
853
|
const loadEffect = async () => {
|
|
795
|
-
const eventBus = await (0,
|
|
854
|
+
const eventBus = await (0, import_canvas10.createEventBus)();
|
|
796
855
|
if (eventBus) {
|
|
797
|
-
goodbye = (0,
|
|
856
|
+
goodbye = (0, import_canvas10.subscribeToComposition)({
|
|
798
857
|
eventBus,
|
|
799
858
|
compositionId,
|
|
800
|
-
compositionState:
|
|
859
|
+
compositionState: import_canvas10.CANVAS_DRAFT_STATE,
|
|
801
860
|
projectId,
|
|
802
861
|
callback: effect,
|
|
803
862
|
event: "updated"
|
|
@@ -812,50 +871,6 @@ function useCompositionEventEffect({
|
|
|
812
871
|
};
|
|
813
872
|
}, [compositionId, enabled, projectId, effect]);
|
|
814
873
|
}
|
|
815
|
-
|
|
816
|
-
// src/hooks/useUniformContextualEditingState.ts
|
|
817
|
-
var import_canvas9 = require("@uniformdev/canvas");
|
|
818
|
-
var import_react19 = require("react");
|
|
819
|
-
var useUniformContextualEditingState = ({
|
|
820
|
-
global = false
|
|
821
|
-
} = {}) => {
|
|
822
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
823
|
-
const { data: componentData } = useUniformCurrentComponent();
|
|
824
|
-
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react19.useState)();
|
|
825
|
-
const channel = (0, import_react19.useMemo)(() => {
|
|
826
|
-
if (!isContextualEditing) {
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
const channel2 = (0, import_canvas9.createCanvasChannel)({
|
|
830
|
-
broadcastTo: [window],
|
|
831
|
-
listenTo: [window]
|
|
832
|
-
});
|
|
833
|
-
return channel2;
|
|
834
|
-
}, [isContextualEditing]);
|
|
835
|
-
(0, import_react19.useEffect)(() => {
|
|
836
|
-
if (!channel) {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
840
|
-
var _a;
|
|
841
|
-
if (!(0, import_canvas9.isUpdateContextualEditingStateInternalMessage)(message)) {
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
845
|
-
setSelectedComponentReference(void 0);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
849
|
-
});
|
|
850
|
-
return () => {
|
|
851
|
-
unsubscribe();
|
|
852
|
-
};
|
|
853
|
-
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
854
|
-
return {
|
|
855
|
-
isContextualEditing,
|
|
856
|
-
selectedComponentReference
|
|
857
|
-
};
|
|
858
|
-
};
|
|
859
874
|
// Annotate the CommonJS export names for ESM import in node:
|
|
860
875
|
0 && (module.exports = {
|
|
861
876
|
DefaultNotImplementedComponent,
|
package/dist/index.mjs
CHANGED
|
@@ -557,11 +557,61 @@ function resolveChildren({
|
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
560
|
+
import {
|
|
561
|
+
getParameterAttributes
|
|
562
|
+
} from "@uniformdev/canvas";
|
|
560
563
|
import {
|
|
561
564
|
isRichTextValue,
|
|
562
565
|
isRichTextValueConsideredEmpty
|
|
563
566
|
} from "@uniformdev/richtext";
|
|
564
|
-
import React16, { useMemo as
|
|
567
|
+
import React16, { useMemo as useMemo3 } from "react";
|
|
568
|
+
|
|
569
|
+
// src/hooks/useUniformContextualEditingState.ts
|
|
570
|
+
import {
|
|
571
|
+
createCanvasChannel as createCanvasChannel2,
|
|
572
|
+
isUpdateContextualEditingStateInternalMessage
|
|
573
|
+
} from "@uniformdev/canvas";
|
|
574
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
575
|
+
var useUniformContextualEditingState = ({
|
|
576
|
+
global = false
|
|
577
|
+
} = {}) => {
|
|
578
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
579
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
580
|
+
const [selectedComponentReference, setSelectedComponentReference] = useState2();
|
|
581
|
+
const channel = useMemo2(() => {
|
|
582
|
+
if (!isContextualEditing) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const channel2 = createCanvasChannel2({
|
|
586
|
+
broadcastTo: [window],
|
|
587
|
+
listenTo: [window]
|
|
588
|
+
});
|
|
589
|
+
return channel2;
|
|
590
|
+
}, [isContextualEditing]);
|
|
591
|
+
useEffect2(() => {
|
|
592
|
+
if (!channel) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
596
|
+
var _a;
|
|
597
|
+
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
601
|
+
setSelectedComponentReference(void 0);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
605
|
+
});
|
|
606
|
+
return () => {
|
|
607
|
+
unsubscribe();
|
|
608
|
+
};
|
|
609
|
+
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
610
|
+
return {
|
|
611
|
+
isContextualEditing,
|
|
612
|
+
selectedComponentReference
|
|
613
|
+
};
|
|
614
|
+
};
|
|
565
615
|
|
|
566
616
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
567
617
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
@@ -672,18 +722,32 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
672
722
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
673
723
|
var UniformRichText = React16.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
674
724
|
const { data: componentData } = useUniformCurrentComponent();
|
|
675
|
-
const
|
|
725
|
+
const { selectedComponentReference } = useUniformContextualEditingState({ global: true });
|
|
726
|
+
const parameter = useMemo3(() => {
|
|
676
727
|
var _a;
|
|
677
728
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
678
729
|
}, [componentData, parameterId]);
|
|
679
|
-
const value =
|
|
730
|
+
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
680
731
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
681
732
|
return null;
|
|
682
|
-
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
733
|
+
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
734
|
+
Tag,
|
|
735
|
+
{
|
|
736
|
+
ref,
|
|
737
|
+
...props,
|
|
738
|
+
...getParameterAttributes({
|
|
739
|
+
component: componentData,
|
|
740
|
+
id: parameterId
|
|
741
|
+
}),
|
|
742
|
+
tabIndex: 0,
|
|
743
|
+
"data-uniform-selected-parameter": (selectedComponentReference == null ? void 0 : selectedComponentReference.id) === parameterId && selectedComponentReference.parentId === (componentData == null ? void 0 : componentData._id)
|
|
744
|
+
},
|
|
745
|
+
/* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
746
|
+
);
|
|
683
747
|
});
|
|
684
748
|
|
|
685
749
|
// src/components/UniformText.tsx
|
|
686
|
-
import React17, { useCallback, useMemo as
|
|
750
|
+
import React17, { useCallback, useMemo as useMemo4, useState as useState3 } from "react";
|
|
687
751
|
var UniformText = ({
|
|
688
752
|
as: Tag = "span",
|
|
689
753
|
parameterId,
|
|
@@ -695,8 +759,8 @@ var UniformText = ({
|
|
|
695
759
|
var _a, _b;
|
|
696
760
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
697
761
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
698
|
-
const [isFocused, setIsFocused] =
|
|
699
|
-
const parameter =
|
|
762
|
+
const [isFocused, setIsFocused] = useState3(false);
|
|
763
|
+
const parameter = useMemo4(() => {
|
|
700
764
|
var _a2;
|
|
701
765
|
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
702
766
|
}, [componentData, parameterId]);
|
|
@@ -724,7 +788,7 @@ var UniformText = ({
|
|
|
724
788
|
Tag,
|
|
725
789
|
{
|
|
726
790
|
...props,
|
|
727
|
-
...
|
|
791
|
+
...getParameterAttributes2({
|
|
728
792
|
component: componentData,
|
|
729
793
|
id: parameterId,
|
|
730
794
|
isMultiline
|
|
@@ -743,7 +807,7 @@ var UniformText = ({
|
|
|
743
807
|
import {
|
|
744
808
|
getParameterAttributes as defaultGetParameterAttributes
|
|
745
809
|
} from "@uniformdev/canvas";
|
|
746
|
-
var
|
|
810
|
+
var getParameterAttributes2 = (options) => {
|
|
747
811
|
return {
|
|
748
812
|
...defaultGetParameterAttributes(options),
|
|
749
813
|
suppressContentEditableWarning: true
|
|
@@ -756,14 +820,14 @@ import {
|
|
|
756
820
|
createEventBus,
|
|
757
821
|
subscribeToComposition
|
|
758
822
|
} from "@uniformdev/canvas";
|
|
759
|
-
import { useEffect as
|
|
823
|
+
import { useEffect as useEffect3 } from "react";
|
|
760
824
|
function useCompositionEventEffect({
|
|
761
825
|
enabled,
|
|
762
826
|
projectId,
|
|
763
827
|
compositionId,
|
|
764
828
|
effect
|
|
765
829
|
}) {
|
|
766
|
-
|
|
830
|
+
useEffect3(() => {
|
|
767
831
|
if (!enabled || !compositionId || !projectId) {
|
|
768
832
|
return;
|
|
769
833
|
}
|
|
@@ -789,53 +853,6 @@ function useCompositionEventEffect({
|
|
|
789
853
|
};
|
|
790
854
|
}, [compositionId, enabled, projectId, effect]);
|
|
791
855
|
}
|
|
792
|
-
|
|
793
|
-
// src/hooks/useUniformContextualEditingState.ts
|
|
794
|
-
import {
|
|
795
|
-
createCanvasChannel as createCanvasChannel2,
|
|
796
|
-
isUpdateContextualEditingStateInternalMessage
|
|
797
|
-
} from "@uniformdev/canvas";
|
|
798
|
-
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
799
|
-
var useUniformContextualEditingState = ({
|
|
800
|
-
global = false
|
|
801
|
-
} = {}) => {
|
|
802
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
803
|
-
const { data: componentData } = useUniformCurrentComponent();
|
|
804
|
-
const [selectedComponentReference, setSelectedComponentReference] = useState3();
|
|
805
|
-
const channel = useMemo4(() => {
|
|
806
|
-
if (!isContextualEditing) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
const channel2 = createCanvasChannel2({
|
|
810
|
-
broadcastTo: [window],
|
|
811
|
-
listenTo: [window]
|
|
812
|
-
});
|
|
813
|
-
return channel2;
|
|
814
|
-
}, [isContextualEditing]);
|
|
815
|
-
useEffect3(() => {
|
|
816
|
-
if (!channel) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
820
|
-
var _a;
|
|
821
|
-
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
825
|
-
setSelectedComponentReference(void 0);
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
829
|
-
});
|
|
830
|
-
return () => {
|
|
831
|
-
unsubscribe();
|
|
832
|
-
};
|
|
833
|
-
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
834
|
-
return {
|
|
835
|
-
isContextualEditing,
|
|
836
|
-
selectedComponentReference
|
|
837
|
-
};
|
|
838
|
-
};
|
|
839
856
|
export {
|
|
840
857
|
DefaultNotImplementedComponent,
|
|
841
858
|
NOT_IMPLEMENTED_COMPONENT,
|
|
@@ -850,7 +867,7 @@ export {
|
|
|
850
867
|
createComponentStore,
|
|
851
868
|
createComponentStoreResolver,
|
|
852
869
|
createUniformApiEnhancer,
|
|
853
|
-
getParameterAttributes,
|
|
870
|
+
getParameterAttributes2 as getParameterAttributes,
|
|
854
871
|
registerUniformComponent,
|
|
855
872
|
useCompositionEventEffect,
|
|
856
873
|
useUniformContextualEditing,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.35.
|
|
3
|
+
"version": "19.35.3-alpha.82+4bc341093",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"document": "api-extractor run --local"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@uniformdev/canvas": "19.35.
|
|
28
|
-
"@uniformdev/context": "19.35.
|
|
29
|
-
"@uniformdev/context-react": "19.35.
|
|
30
|
-
"@uniformdev/richtext": "19.35.
|
|
27
|
+
"@uniformdev/canvas": "19.35.3-alpha.82+4bc341093",
|
|
28
|
+
"@uniformdev/context": "19.35.3-alpha.82+4bc341093",
|
|
29
|
+
"@uniformdev/context-react": "19.35.3-alpha.82+4bc341093",
|
|
30
|
+
"@uniformdev/richtext": "19.35.3-alpha.82+4bc341093"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">= 16 || 17 || 18",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4bc341093bc946900df2646fe53eca4bcddc693c"
|
|
48
48
|
}
|