@uniformdev/canvas-react 19.49.1 → 19.49.4-alpha.67
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/core.d.mts +41 -0
- package/dist/core.d.ts +41 -0
- package/dist/core.js +90 -0
- package/dist/core.mjs +55 -0
- package/dist/index.d.mts +6 -30
- package/dist/index.d.ts +6 -30
- package/dist/index.esm.js +82 -33
- package/dist/index.js +89 -44
- package/dist/index.mjs +82 -33
- package/package.json +32 -12
package/dist/core.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
type ParameterTextValue = string | undefined;
|
|
5
|
+
type PureUniformTextProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the HTML tag to render.
|
|
8
|
+
* @default "span"
|
|
9
|
+
*/
|
|
10
|
+
as?: React.ElementType;
|
|
11
|
+
/** The ID of the parameter. */
|
|
12
|
+
parameterId: string;
|
|
13
|
+
/** The component that contains the parameter. */
|
|
14
|
+
component: ComponentInstance;
|
|
15
|
+
skipCustomRendering: boolean;
|
|
16
|
+
isContextualEditing: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
isMultiline?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
24
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
25
|
+
* @default undefined
|
|
26
|
+
*/
|
|
27
|
+
placeholder?: string | ((parameter: {
|
|
28
|
+
id: string;
|
|
29
|
+
}) => string | undefined);
|
|
30
|
+
/**
|
|
31
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
32
|
+
* @default "(value) => value"
|
|
33
|
+
*/
|
|
34
|
+
render?: (value: ParameterTextValue) => React.ReactNode;
|
|
35
|
+
} & Omit<React.HTMLAttributes<HTMLSpanElement>, 'children' | 'placeholder'>;
|
|
36
|
+
/**
|
|
37
|
+
* Renders text parameters. Offers inline editing capability out of the box.
|
|
38
|
+
*/
|
|
39
|
+
declare const PureUniformText: ({ as: Tag, parameterId, component, skipCustomRendering, isContextualEditing, isMultiline, placeholder, render, ...props }: PureUniformTextProps) => React.JSX.Element | null;
|
|
40
|
+
|
|
41
|
+
export { PureUniformText, PureUniformTextProps };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
type ParameterTextValue = string | undefined;
|
|
5
|
+
type PureUniformTextProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the HTML tag to render.
|
|
8
|
+
* @default "span"
|
|
9
|
+
*/
|
|
10
|
+
as?: React.ElementType;
|
|
11
|
+
/** The ID of the parameter. */
|
|
12
|
+
parameterId: string;
|
|
13
|
+
/** The component that contains the parameter. */
|
|
14
|
+
component: ComponentInstance;
|
|
15
|
+
skipCustomRendering: boolean;
|
|
16
|
+
isContextualEditing: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
isMultiline?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
24
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
25
|
+
* @default undefined
|
|
26
|
+
*/
|
|
27
|
+
placeholder?: string | ((parameter: {
|
|
28
|
+
id: string;
|
|
29
|
+
}) => string | undefined);
|
|
30
|
+
/**
|
|
31
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
32
|
+
* @default "(value) => value"
|
|
33
|
+
*/
|
|
34
|
+
render?: (value: ParameterTextValue) => React.ReactNode;
|
|
35
|
+
} & Omit<React.HTMLAttributes<HTMLSpanElement>, 'children' | 'placeholder'>;
|
|
36
|
+
/**
|
|
37
|
+
* Renders text parameters. Offers inline editing capability out of the box.
|
|
38
|
+
*/
|
|
39
|
+
declare const PureUniformText: ({ as: Tag, parameterId, component, skipCustomRendering, isContextualEditing, isMultiline, placeholder, render, ...props }: PureUniformTextProps) => React.JSX.Element | null;
|
|
40
|
+
|
|
41
|
+
export { PureUniformText, PureUniformTextProps };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/core.ts
|
|
31
|
+
var core_exports = {};
|
|
32
|
+
__export(core_exports, {
|
|
33
|
+
PureUniformText: () => PureUniformText
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(core_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/PureUniformText.tsx
|
|
38
|
+
var import_react = __toESM(require("react"));
|
|
39
|
+
|
|
40
|
+
// src/helpers/getParameterAttributes.ts
|
|
41
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
42
|
+
var getParameterAttributes = (options) => {
|
|
43
|
+
return {
|
|
44
|
+
...(0, import_canvas.getParameterAttributes)(options),
|
|
45
|
+
suppressContentEditableWarning: true
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/components/PureUniformText.tsx
|
|
50
|
+
var PureUniformText = ({
|
|
51
|
+
as: Tag = "span",
|
|
52
|
+
parameterId,
|
|
53
|
+
component,
|
|
54
|
+
skipCustomRendering,
|
|
55
|
+
isContextualEditing,
|
|
56
|
+
isMultiline = false,
|
|
57
|
+
placeholder,
|
|
58
|
+
render = (value) => value,
|
|
59
|
+
...props
|
|
60
|
+
}) => {
|
|
61
|
+
var _a;
|
|
62
|
+
const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[parameterId];
|
|
63
|
+
const value = parameter == null ? void 0 : parameter.value;
|
|
64
|
+
if (!parameter) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (!isContextualEditing) {
|
|
68
|
+
return /* @__PURE__ */ import_react.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
69
|
+
}
|
|
70
|
+
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
71
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
72
|
+
Tag,
|
|
73
|
+
{
|
|
74
|
+
...props,
|
|
75
|
+
...getParameterAttributes({
|
|
76
|
+
component,
|
|
77
|
+
id: parameterId,
|
|
78
|
+
isMultiline
|
|
79
|
+
}),
|
|
80
|
+
"data-uniform-parameter-type": "text",
|
|
81
|
+
"data-uniform-placeholder": computedPlaceholder,
|
|
82
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
83
|
+
},
|
|
84
|
+
skipCustomRendering ? value : render(value)
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
PureUniformText
|
|
90
|
+
});
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/components/PureUniformText.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
// src/helpers/getParameterAttributes.ts
|
|
5
|
+
import {
|
|
6
|
+
getParameterAttributes as defaultGetParameterAttributes
|
|
7
|
+
} from "@uniformdev/canvas";
|
|
8
|
+
var getParameterAttributes = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
...defaultGetParameterAttributes(options),
|
|
11
|
+
suppressContentEditableWarning: true
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/components/PureUniformText.tsx
|
|
16
|
+
var PureUniformText = ({
|
|
17
|
+
as: Tag = "span",
|
|
18
|
+
parameterId,
|
|
19
|
+
component,
|
|
20
|
+
skipCustomRendering,
|
|
21
|
+
isContextualEditing,
|
|
22
|
+
isMultiline = false,
|
|
23
|
+
placeholder,
|
|
24
|
+
render = (value) => value,
|
|
25
|
+
...props
|
|
26
|
+
}) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[parameterId];
|
|
29
|
+
const value = parameter == null ? void 0 : parameter.value;
|
|
30
|
+
if (!parameter) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!isContextualEditing) {
|
|
34
|
+
return /* @__PURE__ */ React.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
35
|
+
}
|
|
36
|
+
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
37
|
+
return /* @__PURE__ */ React.createElement(
|
|
38
|
+
Tag,
|
|
39
|
+
{
|
|
40
|
+
...props,
|
|
41
|
+
...getParameterAttributes({
|
|
42
|
+
component,
|
|
43
|
+
id: parameterId,
|
|
44
|
+
isMultiline
|
|
45
|
+
}),
|
|
46
|
+
"data-uniform-parameter-type": "text",
|
|
47
|
+
"data-uniform-placeholder": computedPlaceholder,
|
|
48
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
49
|
+
},
|
|
50
|
+
skipCustomRendering ? value : render(value)
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
PureUniformText
|
|
55
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
|
2
2
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
3
3
|
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
|
|
4
4
|
export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
5
|
+
import { PureUniformTextProps } from './core.mjs';
|
|
5
6
|
import { RichTextNode } from '@uniformdev/richtext';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -41,38 +42,11 @@ type ComponentStore = {
|
|
|
41
42
|
**/
|
|
42
43
|
declare function DefaultNotImplementedComponent(props: ComponentProps): React$1.JSX.Element | null;
|
|
43
44
|
|
|
44
|
-
type
|
|
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'>;
|
|
45
|
+
type UniformTextProps = Omit<PureUniformTextProps, 'skipCustomRendering' | 'isContextualEditing' | 'component'>;
|
|
72
46
|
/**
|
|
73
47
|
* Renders text parameters. Offers inline editing capability out of the box.
|
|
74
48
|
*/
|
|
75
|
-
declare const UniformText: ({ as:
|
|
49
|
+
declare const UniformText: ({ as: tag, parameterId, isMultiline, placeholder, render, ...props }: UniformTextProps) => React$1.JSX.Element | null;
|
|
76
50
|
|
|
77
51
|
type UniformComponentProps<TRenderProps = unknown> = {
|
|
78
52
|
/** The data of the component instance */
|
|
@@ -269,8 +243,10 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
269
243
|
*/
|
|
270
244
|
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
271
245
|
|
|
272
|
-
type UniformPlaygroundDecorator = (
|
|
246
|
+
type UniformPlaygroundDecorator = (props: {
|
|
247
|
+
/** The rendered component instance, needs to wrapped and rendered by the decorator */
|
|
273
248
|
children: React$1.ReactNode;
|
|
249
|
+
/** The component instance data */
|
|
274
250
|
data: ComponentInstance | RootComponentInstance;
|
|
275
251
|
}) => React$1.ReactElement;
|
|
276
252
|
type UniformPlaygroundProps = {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
|
2
2
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
3
3
|
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
|
|
4
4
|
export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
5
|
+
import { PureUniformTextProps } from './core.js';
|
|
5
6
|
import { RichTextNode } from '@uniformdev/richtext';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -41,38 +42,11 @@ type ComponentStore = {
|
|
|
41
42
|
**/
|
|
42
43
|
declare function DefaultNotImplementedComponent(props: ComponentProps): React$1.JSX.Element | null;
|
|
43
44
|
|
|
44
|
-
type
|
|
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'>;
|
|
45
|
+
type UniformTextProps = Omit<PureUniformTextProps, 'skipCustomRendering' | 'isContextualEditing' | 'component'>;
|
|
72
46
|
/**
|
|
73
47
|
* Renders text parameters. Offers inline editing capability out of the box.
|
|
74
48
|
*/
|
|
75
|
-
declare const UniformText: ({ as:
|
|
49
|
+
declare const UniformText: ({ as: tag, parameterId, isMultiline, placeholder, render, ...props }: UniformTextProps) => React$1.JSX.Element | null;
|
|
76
50
|
|
|
77
51
|
type UniformComponentProps<TRenderProps = unknown> = {
|
|
78
52
|
/** The data of the component instance */
|
|
@@ -269,8 +243,10 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
269
243
|
*/
|
|
270
244
|
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
271
245
|
|
|
272
|
-
type UniformPlaygroundDecorator = (
|
|
246
|
+
type UniformPlaygroundDecorator = (props: {
|
|
247
|
+
/** The rendered component instance, needs to wrapped and rendered by the decorator */
|
|
273
248
|
children: React$1.ReactNode;
|
|
249
|
+
/** The component instance data */
|
|
274
250
|
data: ComponentInstance | RootComponentInstance;
|
|
275
251
|
}) => React$1.ReactElement;
|
|
276
252
|
type UniformPlaygroundProps = {
|
package/dist/index.esm.js
CHANGED
|
@@ -186,7 +186,7 @@ import {
|
|
|
186
186
|
CANVAS_LOCALE_TAG_PARAM,
|
|
187
187
|
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
188
188
|
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
189
|
-
|
|
189
|
+
isComponentPlaceholderId
|
|
190
190
|
} from "@uniformdev/canvas";
|
|
191
191
|
import React4 from "react";
|
|
192
192
|
|
|
@@ -331,7 +331,7 @@ function ContextualEditingComponentWrapper({
|
|
|
331
331
|
children
|
|
332
332
|
}) {
|
|
333
333
|
var _a, _b, _c, _d, _e;
|
|
334
|
-
const isPlaceholder = (component == null ? void 0 : component._id)
|
|
334
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
335
335
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
336
336
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
337
337
|
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
@@ -577,7 +577,7 @@ var UniformPlayground = ({
|
|
|
577
577
|
if (!composition) {
|
|
578
578
|
return null;
|
|
579
579
|
}
|
|
580
|
-
let component = /* @__PURE__ */ React7.createElement(
|
|
580
|
+
let component = /* @__PURE__ */ React7.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React7.createElement(
|
|
581
581
|
UniformComponent,
|
|
582
582
|
{
|
|
583
583
|
data: composition,
|
|
@@ -586,7 +586,7 @@ var UniformPlayground = ({
|
|
|
586
586
|
contextualEditingDefaultPlaceholder
|
|
587
587
|
},
|
|
588
588
|
children
|
|
589
|
-
);
|
|
589
|
+
));
|
|
590
590
|
decorators.forEach((Decorator) => {
|
|
591
591
|
component = /* @__PURE__ */ React7.createElement(Decorator, { data: composition }, component);
|
|
592
592
|
});
|
|
@@ -604,11 +604,16 @@ var UniformPlayground = ({
|
|
|
604
604
|
{
|
|
605
605
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
606
606
|
},
|
|
607
|
-
|
|
607
|
+
renderedComponent
|
|
608
608
|
);
|
|
609
609
|
};
|
|
610
610
|
|
|
611
611
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
612
|
+
import {
|
|
613
|
+
ATTRIBUTE_COMPONENT_ID,
|
|
614
|
+
ATTRIBUTE_PARAMETER_ID,
|
|
615
|
+
ATTRIBUTE_PARAMETER_TYPE
|
|
616
|
+
} from "@uniformdev/canvas";
|
|
612
617
|
import {
|
|
613
618
|
isRichTextValue,
|
|
614
619
|
isRichTextValueConsideredEmpty
|
|
@@ -731,60 +736,104 @@ var UniformRichText = React17.forwardRef(function UniformRichText2({ parameterId
|
|
|
731
736
|
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
732
737
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
733
738
|
return null;
|
|
734
|
-
return Tag === null ? /* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React17.createElement(
|
|
739
|
+
return Tag === null ? /* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React17.createElement(
|
|
740
|
+
Tag,
|
|
741
|
+
{
|
|
742
|
+
ref,
|
|
743
|
+
...props,
|
|
744
|
+
...{
|
|
745
|
+
[ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
746
|
+
[ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
747
|
+
[ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
/* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
751
|
+
);
|
|
735
752
|
});
|
|
736
753
|
|
|
737
754
|
// src/components/UniformText.tsx
|
|
738
|
-
import
|
|
739
|
-
|
|
755
|
+
import React19, { useState as useState2 } from "react";
|
|
756
|
+
|
|
757
|
+
// src/components/PureUniformText.tsx
|
|
758
|
+
import React18 from "react";
|
|
759
|
+
var PureUniformText = ({
|
|
740
760
|
as: Tag = "span",
|
|
741
761
|
parameterId,
|
|
762
|
+
component,
|
|
763
|
+
skipCustomRendering,
|
|
764
|
+
isContextualEditing,
|
|
742
765
|
isMultiline = false,
|
|
743
766
|
placeholder,
|
|
744
767
|
render = (value) => value,
|
|
745
768
|
...props
|
|
746
769
|
}) => {
|
|
747
|
-
var _a
|
|
748
|
-
const
|
|
749
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
750
|
-
const [isFocused, setIsFocused] = useState2(false);
|
|
751
|
-
const parameter = useMemo4(() => {
|
|
752
|
-
var _a2;
|
|
753
|
-
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
754
|
-
}, [componentData, parameterId]);
|
|
770
|
+
var _a;
|
|
771
|
+
const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[parameterId];
|
|
755
772
|
const value = parameter == null ? void 0 : parameter.value;
|
|
756
|
-
const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
757
|
-
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
758
|
-
const handleOnFocus = useCallback(() => {
|
|
759
|
-
setIsFocused(true);
|
|
760
|
-
}, [setIsFocused]);
|
|
761
|
-
const handleOnBlur = useCallback(() => {
|
|
762
|
-
setIsFocused(false);
|
|
763
|
-
}, [setIsFocused]);
|
|
764
773
|
if (!parameter) {
|
|
765
774
|
return null;
|
|
766
775
|
}
|
|
767
776
|
if (!isContextualEditing) {
|
|
768
777
|
return /* @__PURE__ */ React18.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
769
778
|
}
|
|
770
|
-
const
|
|
771
|
-
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
779
|
+
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
772
780
|
return /* @__PURE__ */ React18.createElement(
|
|
773
781
|
Tag,
|
|
774
782
|
{
|
|
775
783
|
...props,
|
|
776
784
|
...getParameterAttributes({
|
|
777
|
-
component
|
|
785
|
+
component,
|
|
778
786
|
id: parameterId,
|
|
779
787
|
isMultiline
|
|
780
788
|
}),
|
|
781
789
|
"data-uniform-parameter-type": "text",
|
|
782
790
|
"data-uniform-placeholder": computedPlaceholder,
|
|
783
|
-
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
784
|
-
onFocus: handleOnFocus,
|
|
785
|
-
onBlur: handleOnBlur
|
|
791
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
786
792
|
},
|
|
787
|
-
|
|
793
|
+
skipCustomRendering ? value : render(value)
|
|
794
|
+
);
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// src/components/UniformText.tsx
|
|
798
|
+
var UniformText = ({
|
|
799
|
+
as: tag = "span",
|
|
800
|
+
parameterId,
|
|
801
|
+
isMultiline = false,
|
|
802
|
+
placeholder,
|
|
803
|
+
render = (value) => value,
|
|
804
|
+
...props
|
|
805
|
+
}) => {
|
|
806
|
+
var _a, _b, _c;
|
|
807
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
808
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
809
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
810
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
811
|
+
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
812
|
+
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
813
|
+
if (!parameter) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
817
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
818
|
+
return /* @__PURE__ */ React19.createElement(
|
|
819
|
+
PureUniformText,
|
|
820
|
+
{
|
|
821
|
+
...props,
|
|
822
|
+
as: tag,
|
|
823
|
+
parameterId,
|
|
824
|
+
component: componentData,
|
|
825
|
+
skipCustomRendering: shouldSkipCustomRendering,
|
|
826
|
+
isContextualEditing,
|
|
827
|
+
placeholder: computedPlaceholder,
|
|
828
|
+
render,
|
|
829
|
+
isMultiline,
|
|
830
|
+
onFocus: () => {
|
|
831
|
+
setIsFocused(true);
|
|
832
|
+
},
|
|
833
|
+
onBlur: () => {
|
|
834
|
+
setIsFocused(false);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
788
837
|
);
|
|
789
838
|
};
|
|
790
839
|
|
|
@@ -844,14 +893,14 @@ import {
|
|
|
844
893
|
createCanvasChannel as createCanvasChannel2,
|
|
845
894
|
isUpdateContextualEditingStateInternalMessage
|
|
846
895
|
} from "@uniformdev/canvas";
|
|
847
|
-
import { useEffect as useEffect3, useMemo as
|
|
896
|
+
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
848
897
|
var useUniformContextualEditingState = ({
|
|
849
898
|
global = false
|
|
850
899
|
} = {}) => {
|
|
851
900
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
852
901
|
const { data: componentData } = useUniformCurrentComponent();
|
|
853
902
|
const [selectedComponentReference, setSelectedComponentReference] = useState3();
|
|
854
|
-
const channel =
|
|
903
|
+
const channel = useMemo4(() => {
|
|
855
904
|
if (!isContextualEditing) {
|
|
856
905
|
return;
|
|
857
906
|
}
|
package/dist/index.js
CHANGED
|
@@ -365,7 +365,7 @@ function ContextualEditingComponentWrapper({
|
|
|
365
365
|
children
|
|
366
366
|
}) {
|
|
367
367
|
var _a, _b, _c, _d, _e;
|
|
368
|
-
const isPlaceholder = (component == null ? void 0 : component._id)
|
|
368
|
+
const isPlaceholder = (0, import_canvas4.isComponentPlaceholderId)(component == null ? void 0 : component._id);
|
|
369
369
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
370
370
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
371
371
|
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(
|
|
@@ -611,7 +611,7 @@ var UniformPlayground = ({
|
|
|
611
611
|
if (!composition) {
|
|
612
612
|
return null;
|
|
613
613
|
}
|
|
614
|
-
let component = /* @__PURE__ */ import_react7.default.createElement(
|
|
614
|
+
let component = /* @__PURE__ */ import_react7.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react7.default.createElement(
|
|
615
615
|
UniformComponent,
|
|
616
616
|
{
|
|
617
617
|
data: composition,
|
|
@@ -620,7 +620,7 @@ var UniformPlayground = ({
|
|
|
620
620
|
contextualEditingDefaultPlaceholder
|
|
621
621
|
},
|
|
622
622
|
children
|
|
623
|
-
);
|
|
623
|
+
));
|
|
624
624
|
decorators.forEach((Decorator) => {
|
|
625
625
|
component = /* @__PURE__ */ import_react7.default.createElement(Decorator, { data: composition }, component);
|
|
626
626
|
});
|
|
@@ -638,11 +638,12 @@ var UniformPlayground = ({
|
|
|
638
638
|
{
|
|
639
639
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
640
640
|
},
|
|
641
|
-
|
|
641
|
+
renderedComponent
|
|
642
642
|
);
|
|
643
643
|
};
|
|
644
644
|
|
|
645
645
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
646
|
+
var import_canvas8 = require("@uniformdev/canvas");
|
|
646
647
|
var import_richtext5 = require("@uniformdev/richtext");
|
|
647
648
|
var import_react17 = __toESM(require("react"));
|
|
648
649
|
|
|
@@ -762,93 +763,137 @@ var UniformRichText = import_react17.default.forwardRef(function UniformRichText
|
|
|
762
763
|
const value = (0, import_react17.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
763
764
|
if (!value || !(0, import_richtext5.isRichTextValue)(value) || (0, import_richtext5.isRichTextValueConsideredEmpty)(value))
|
|
764
765
|
return null;
|
|
765
|
-
return Tag === null ? /* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react17.default.createElement(
|
|
766
|
+
return Tag === null ? /* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react17.default.createElement(
|
|
767
|
+
Tag,
|
|
768
|
+
{
|
|
769
|
+
ref,
|
|
770
|
+
...props,
|
|
771
|
+
...{
|
|
772
|
+
[import_canvas8.ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
773
|
+
[import_canvas8.ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
774
|
+
[import_canvas8.ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
/* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
778
|
+
);
|
|
766
779
|
});
|
|
767
780
|
|
|
768
781
|
// src/components/UniformText.tsx
|
|
782
|
+
var import_react19 = __toESM(require("react"));
|
|
783
|
+
|
|
784
|
+
// src/components/PureUniformText.tsx
|
|
769
785
|
var import_react18 = __toESM(require("react"));
|
|
770
|
-
var
|
|
786
|
+
var PureUniformText = ({
|
|
771
787
|
as: Tag = "span",
|
|
772
788
|
parameterId,
|
|
789
|
+
component,
|
|
790
|
+
skipCustomRendering,
|
|
791
|
+
isContextualEditing,
|
|
773
792
|
isMultiline = false,
|
|
774
793
|
placeholder,
|
|
775
794
|
render = (value) => value,
|
|
776
795
|
...props
|
|
777
796
|
}) => {
|
|
778
|
-
var _a
|
|
779
|
-
const
|
|
780
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
781
|
-
const [isFocused, setIsFocused] = (0, import_react18.useState)(false);
|
|
782
|
-
const parameter = (0, import_react18.useMemo)(() => {
|
|
783
|
-
var _a2;
|
|
784
|
-
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
785
|
-
}, [componentData, parameterId]);
|
|
797
|
+
var _a;
|
|
798
|
+
const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[parameterId];
|
|
786
799
|
const value = parameter == null ? void 0 : parameter.value;
|
|
787
|
-
const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
788
|
-
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
789
|
-
const handleOnFocus = (0, import_react18.useCallback)(() => {
|
|
790
|
-
setIsFocused(true);
|
|
791
|
-
}, [setIsFocused]);
|
|
792
|
-
const handleOnBlur = (0, import_react18.useCallback)(() => {
|
|
793
|
-
setIsFocused(false);
|
|
794
|
-
}, [setIsFocused]);
|
|
795
800
|
if (!parameter) {
|
|
796
801
|
return null;
|
|
797
802
|
}
|
|
798
803
|
if (!isContextualEditing) {
|
|
799
804
|
return /* @__PURE__ */ import_react18.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
800
805
|
}
|
|
801
|
-
const
|
|
802
|
-
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
806
|
+
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
803
807
|
return /* @__PURE__ */ import_react18.default.createElement(
|
|
804
808
|
Tag,
|
|
805
809
|
{
|
|
806
810
|
...props,
|
|
807
811
|
...getParameterAttributes({
|
|
808
|
-
component
|
|
812
|
+
component,
|
|
809
813
|
id: parameterId,
|
|
810
814
|
isMultiline
|
|
811
815
|
}),
|
|
812
816
|
"data-uniform-parameter-type": "text",
|
|
813
817
|
"data-uniform-placeholder": computedPlaceholder,
|
|
814
|
-
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
815
|
-
onFocus: handleOnFocus,
|
|
816
|
-
onBlur: handleOnBlur
|
|
818
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
817
819
|
},
|
|
818
|
-
|
|
820
|
+
skipCustomRendering ? value : render(value)
|
|
821
|
+
);
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// src/components/UniformText.tsx
|
|
825
|
+
var UniformText = ({
|
|
826
|
+
as: tag = "span",
|
|
827
|
+
parameterId,
|
|
828
|
+
isMultiline = false,
|
|
829
|
+
placeholder,
|
|
830
|
+
render = (value) => value,
|
|
831
|
+
...props
|
|
832
|
+
}) => {
|
|
833
|
+
var _a, _b, _c;
|
|
834
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
835
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
836
|
+
const [isFocused, setIsFocused] = (0, import_react19.useState)(false);
|
|
837
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
838
|
+
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
839
|
+
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
840
|
+
if (!parameter) {
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
844
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
845
|
+
return /* @__PURE__ */ import_react19.default.createElement(
|
|
846
|
+
PureUniformText,
|
|
847
|
+
{
|
|
848
|
+
...props,
|
|
849
|
+
as: tag,
|
|
850
|
+
parameterId,
|
|
851
|
+
component: componentData,
|
|
852
|
+
skipCustomRendering: shouldSkipCustomRendering,
|
|
853
|
+
isContextualEditing,
|
|
854
|
+
placeholder: computedPlaceholder,
|
|
855
|
+
render,
|
|
856
|
+
isMultiline,
|
|
857
|
+
onFocus: () => {
|
|
858
|
+
setIsFocused(true);
|
|
859
|
+
},
|
|
860
|
+
onBlur: () => {
|
|
861
|
+
setIsFocused(false);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
819
864
|
);
|
|
820
865
|
};
|
|
821
866
|
|
|
822
867
|
// src/helpers/getParameterAttributes.ts
|
|
823
|
-
var
|
|
868
|
+
var import_canvas9 = require("@uniformdev/canvas");
|
|
824
869
|
var getParameterAttributes = (options) => {
|
|
825
870
|
return {
|
|
826
|
-
...(0,
|
|
871
|
+
...(0, import_canvas9.getParameterAttributes)(options),
|
|
827
872
|
suppressContentEditableWarning: true
|
|
828
873
|
};
|
|
829
874
|
};
|
|
830
875
|
|
|
831
876
|
// src/hooks/useCompositionEventEffect.ts
|
|
832
|
-
var
|
|
833
|
-
var
|
|
877
|
+
var import_canvas10 = require("@uniformdev/canvas");
|
|
878
|
+
var import_react20 = require("react");
|
|
834
879
|
function useCompositionEventEffect({
|
|
835
880
|
enabled,
|
|
836
881
|
projectId,
|
|
837
882
|
compositionId,
|
|
838
883
|
effect
|
|
839
884
|
}) {
|
|
840
|
-
(0,
|
|
885
|
+
(0, import_react20.useEffect)(() => {
|
|
841
886
|
if (!enabled || !compositionId || !projectId) {
|
|
842
887
|
return;
|
|
843
888
|
}
|
|
844
889
|
let goodbye = void 0;
|
|
845
890
|
const loadEffect = async () => {
|
|
846
|
-
const eventBus = await (0,
|
|
891
|
+
const eventBus = await (0, import_canvas10.createEventBus)();
|
|
847
892
|
if (eventBus) {
|
|
848
|
-
goodbye = (0,
|
|
893
|
+
goodbye = (0, import_canvas10.subscribeToComposition)({
|
|
849
894
|
eventBus,
|
|
850
895
|
compositionId,
|
|
851
|
-
compositionState:
|
|
896
|
+
compositionState: import_canvas10.CANVAS_DRAFT_STATE,
|
|
852
897
|
projectId,
|
|
853
898
|
callback: effect,
|
|
854
899
|
event: "updated"
|
|
@@ -865,31 +910,31 @@ function useCompositionEventEffect({
|
|
|
865
910
|
}
|
|
866
911
|
|
|
867
912
|
// src/hooks/useUniformContextualEditingState.ts
|
|
868
|
-
var
|
|
869
|
-
var
|
|
913
|
+
var import_canvas11 = require("@uniformdev/canvas");
|
|
914
|
+
var import_react21 = require("react");
|
|
870
915
|
var useUniformContextualEditingState = ({
|
|
871
916
|
global = false
|
|
872
917
|
} = {}) => {
|
|
873
918
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
874
919
|
const { data: componentData } = useUniformCurrentComponent();
|
|
875
|
-
const [selectedComponentReference, setSelectedComponentReference] = (0,
|
|
876
|
-
const channel = (0,
|
|
920
|
+
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react21.useState)();
|
|
921
|
+
const channel = (0, import_react21.useMemo)(() => {
|
|
877
922
|
if (!isContextualEditing) {
|
|
878
923
|
return;
|
|
879
924
|
}
|
|
880
|
-
const channel2 = (0,
|
|
925
|
+
const channel2 = (0, import_canvas11.createCanvasChannel)({
|
|
881
926
|
broadcastTo: [window],
|
|
882
927
|
listenTo: [window]
|
|
883
928
|
});
|
|
884
929
|
return channel2;
|
|
885
930
|
}, [isContextualEditing]);
|
|
886
|
-
(0,
|
|
931
|
+
(0, import_react21.useEffect)(() => {
|
|
887
932
|
if (!channel) {
|
|
888
933
|
return;
|
|
889
934
|
}
|
|
890
935
|
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
891
936
|
var _a;
|
|
892
|
-
if (!(0,
|
|
937
|
+
if (!(0, import_canvas11.isUpdateContextualEditingStateInternalMessage)(message)) {
|
|
893
938
|
return;
|
|
894
939
|
}
|
|
895
940
|
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
package/dist/index.mjs
CHANGED
|
@@ -186,7 +186,7 @@ import {
|
|
|
186
186
|
CANVAS_LOCALE_TAG_PARAM,
|
|
187
187
|
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
|
188
188
|
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
189
|
-
|
|
189
|
+
isComponentPlaceholderId
|
|
190
190
|
} from "@uniformdev/canvas";
|
|
191
191
|
import React4 from "react";
|
|
192
192
|
|
|
@@ -331,7 +331,7 @@ function ContextualEditingComponentWrapper({
|
|
|
331
331
|
children
|
|
332
332
|
}) {
|
|
333
333
|
var _a, _b, _c, _d, _e;
|
|
334
|
-
const isPlaceholder = (component == null ? void 0 : component._id)
|
|
334
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
335
335
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
336
336
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
337
337
|
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
@@ -577,7 +577,7 @@ var UniformPlayground = ({
|
|
|
577
577
|
if (!composition) {
|
|
578
578
|
return null;
|
|
579
579
|
}
|
|
580
|
-
let component = /* @__PURE__ */ React7.createElement(
|
|
580
|
+
let component = /* @__PURE__ */ React7.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ React7.createElement(
|
|
581
581
|
UniformComponent,
|
|
582
582
|
{
|
|
583
583
|
data: composition,
|
|
@@ -586,7 +586,7 @@ var UniformPlayground = ({
|
|
|
586
586
|
contextualEditingDefaultPlaceholder
|
|
587
587
|
},
|
|
588
588
|
children
|
|
589
|
-
);
|
|
589
|
+
));
|
|
590
590
|
decorators.forEach((Decorator) => {
|
|
591
591
|
component = /* @__PURE__ */ React7.createElement(Decorator, { data: composition }, component);
|
|
592
592
|
});
|
|
@@ -604,11 +604,16 @@ var UniformPlayground = ({
|
|
|
604
604
|
{
|
|
605
605
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
606
606
|
},
|
|
607
|
-
|
|
607
|
+
renderedComponent
|
|
608
608
|
);
|
|
609
609
|
};
|
|
610
610
|
|
|
611
611
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
612
|
+
import {
|
|
613
|
+
ATTRIBUTE_COMPONENT_ID,
|
|
614
|
+
ATTRIBUTE_PARAMETER_ID,
|
|
615
|
+
ATTRIBUTE_PARAMETER_TYPE
|
|
616
|
+
} from "@uniformdev/canvas";
|
|
612
617
|
import {
|
|
613
618
|
isRichTextValue,
|
|
614
619
|
isRichTextValueConsideredEmpty
|
|
@@ -731,60 +736,104 @@ var UniformRichText = React17.forwardRef(function UniformRichText2({ parameterId
|
|
|
731
736
|
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
732
737
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
733
738
|
return null;
|
|
734
|
-
return Tag === null ? /* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React17.createElement(
|
|
739
|
+
return Tag === null ? /* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React17.createElement(
|
|
740
|
+
Tag,
|
|
741
|
+
{
|
|
742
|
+
ref,
|
|
743
|
+
...props,
|
|
744
|
+
...{
|
|
745
|
+
[ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
746
|
+
[ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
747
|
+
[ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
/* @__PURE__ */ React17.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
751
|
+
);
|
|
735
752
|
});
|
|
736
753
|
|
|
737
754
|
// src/components/UniformText.tsx
|
|
738
|
-
import
|
|
739
|
-
|
|
755
|
+
import React19, { useState as useState2 } from "react";
|
|
756
|
+
|
|
757
|
+
// src/components/PureUniformText.tsx
|
|
758
|
+
import React18 from "react";
|
|
759
|
+
var PureUniformText = ({
|
|
740
760
|
as: Tag = "span",
|
|
741
761
|
parameterId,
|
|
762
|
+
component,
|
|
763
|
+
skipCustomRendering,
|
|
764
|
+
isContextualEditing,
|
|
742
765
|
isMultiline = false,
|
|
743
766
|
placeholder,
|
|
744
767
|
render = (value) => value,
|
|
745
768
|
...props
|
|
746
769
|
}) => {
|
|
747
|
-
var _a
|
|
748
|
-
const
|
|
749
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
750
|
-
const [isFocused, setIsFocused] = useState2(false);
|
|
751
|
-
const parameter = useMemo4(() => {
|
|
752
|
-
var _a2;
|
|
753
|
-
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
754
|
-
}, [componentData, parameterId]);
|
|
770
|
+
var _a;
|
|
771
|
+
const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[parameterId];
|
|
755
772
|
const value = parameter == null ? void 0 : parameter.value;
|
|
756
|
-
const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
757
|
-
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
758
|
-
const handleOnFocus = useCallback(() => {
|
|
759
|
-
setIsFocused(true);
|
|
760
|
-
}, [setIsFocused]);
|
|
761
|
-
const handleOnBlur = useCallback(() => {
|
|
762
|
-
setIsFocused(false);
|
|
763
|
-
}, [setIsFocused]);
|
|
764
773
|
if (!parameter) {
|
|
765
774
|
return null;
|
|
766
775
|
}
|
|
767
776
|
if (!isContextualEditing) {
|
|
768
777
|
return /* @__PURE__ */ React18.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
769
778
|
}
|
|
770
|
-
const
|
|
771
|
-
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
779
|
+
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
772
780
|
return /* @__PURE__ */ React18.createElement(
|
|
773
781
|
Tag,
|
|
774
782
|
{
|
|
775
783
|
...props,
|
|
776
784
|
...getParameterAttributes({
|
|
777
|
-
component
|
|
785
|
+
component,
|
|
778
786
|
id: parameterId,
|
|
779
787
|
isMultiline
|
|
780
788
|
}),
|
|
781
789
|
"data-uniform-parameter-type": "text",
|
|
782
790
|
"data-uniform-placeholder": computedPlaceholder,
|
|
783
|
-
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
784
|
-
onFocus: handleOnFocus,
|
|
785
|
-
onBlur: handleOnBlur
|
|
791
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {}
|
|
786
792
|
},
|
|
787
|
-
|
|
793
|
+
skipCustomRendering ? value : render(value)
|
|
794
|
+
);
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// src/components/UniformText.tsx
|
|
798
|
+
var UniformText = ({
|
|
799
|
+
as: tag = "span",
|
|
800
|
+
parameterId,
|
|
801
|
+
isMultiline = false,
|
|
802
|
+
placeholder,
|
|
803
|
+
render = (value) => value,
|
|
804
|
+
...props
|
|
805
|
+
}) => {
|
|
806
|
+
var _a, _b, _c;
|
|
807
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
808
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
809
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
810
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
811
|
+
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
812
|
+
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
813
|
+
if (!parameter) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
817
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
818
|
+
return /* @__PURE__ */ React19.createElement(
|
|
819
|
+
PureUniformText,
|
|
820
|
+
{
|
|
821
|
+
...props,
|
|
822
|
+
as: tag,
|
|
823
|
+
parameterId,
|
|
824
|
+
component: componentData,
|
|
825
|
+
skipCustomRendering: shouldSkipCustomRendering,
|
|
826
|
+
isContextualEditing,
|
|
827
|
+
placeholder: computedPlaceholder,
|
|
828
|
+
render,
|
|
829
|
+
isMultiline,
|
|
830
|
+
onFocus: () => {
|
|
831
|
+
setIsFocused(true);
|
|
832
|
+
},
|
|
833
|
+
onBlur: () => {
|
|
834
|
+
setIsFocused(false);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
788
837
|
);
|
|
789
838
|
};
|
|
790
839
|
|
|
@@ -844,14 +893,14 @@ import {
|
|
|
844
893
|
createCanvasChannel as createCanvasChannel2,
|
|
845
894
|
isUpdateContextualEditingStateInternalMessage
|
|
846
895
|
} from "@uniformdev/canvas";
|
|
847
|
-
import { useEffect as useEffect3, useMemo as
|
|
896
|
+
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
848
897
|
var useUniformContextualEditingState = ({
|
|
849
898
|
global = false
|
|
850
899
|
} = {}) => {
|
|
851
900
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
852
901
|
const { data: componentData } = useUniformCurrentComponent();
|
|
853
902
|
const [selectedComponentReference, setSelectedComponentReference] = useState3();
|
|
854
|
-
const channel =
|
|
903
|
+
const channel = useMemo4(() => {
|
|
855
904
|
if (!isContextualEditing) {
|
|
856
905
|
return;
|
|
857
906
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.49.
|
|
3
|
+
"version": "19.49.4-alpha.67+9773e3b65",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.esm.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"node": "./dist/index.mjs",
|
|
13
|
+
"default": "./dist/index.esm.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
13
19
|
},
|
|
14
|
-
"
|
|
20
|
+
"./core": {
|
|
21
|
+
"types": "./dist/core.d.ts",
|
|
22
|
+
"import": "./dist/core.mjs",
|
|
23
|
+
"require": "./dist/core.js"
|
|
24
|
+
}
|
|
15
25
|
},
|
|
16
26
|
"types": "./dist/index.d.ts",
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
"*": [
|
|
30
|
+
"./dist/index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"core": [
|
|
33
|
+
"./dist/core.d.ts"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
17
37
|
"sideEffects": false,
|
|
18
38
|
"scripts": {
|
|
19
39
|
"build": "tsup",
|
|
@@ -25,17 +45,17 @@
|
|
|
25
45
|
"document": "api-extractor run --local"
|
|
26
46
|
},
|
|
27
47
|
"dependencies": {
|
|
28
|
-
"@uniformdev/canvas": "19.49.
|
|
29
|
-
"@uniformdev/context": "19.49.
|
|
30
|
-
"@uniformdev/context-react": "19.49.
|
|
31
|
-
"@uniformdev/richtext": "19.49.
|
|
48
|
+
"@uniformdev/canvas": "19.49.4-alpha.67+9773e3b65",
|
|
49
|
+
"@uniformdev/context": "19.49.4-alpha.67+9773e3b65",
|
|
50
|
+
"@uniformdev/context-react": "19.49.4-alpha.67+9773e3b65",
|
|
51
|
+
"@uniformdev/richtext": "19.49.4-alpha.67+9773e3b65"
|
|
32
52
|
},
|
|
33
53
|
"peerDependencies": {
|
|
34
54
|
"react": ">= 16 || 17 || 18",
|
|
35
55
|
"react-dom": ">=16"
|
|
36
56
|
},
|
|
37
57
|
"devDependencies": {
|
|
38
|
-
"@types/react": "18.2.
|
|
58
|
+
"@types/react": "18.2.21",
|
|
39
59
|
"react": "18.2.0",
|
|
40
60
|
"react-dom": "18.2.0"
|
|
41
61
|
},
|
|
@@ -45,5 +65,5 @@
|
|
|
45
65
|
"publishConfig": {
|
|
46
66
|
"access": "public"
|
|
47
67
|
},
|
|
48
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "9773e3b65168255768f5cbecf2536988fa0e03af"
|
|
49
69
|
}
|