@uniformdev/canvas-react 19.14.0 → 19.14.1-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +38 -2
- package/dist/index.esm.js +128 -7
- package/dist/index.js +135 -12
- package/dist/index.mjs +128 -7
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React$1, { Key, ReactNode } from 'react';
|
|
1
|
+
import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
|
|
2
2
|
import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, SubscribeToCompositionOptions } from '@uniformdev/canvas';
|
|
3
3
|
export { createUniformApiEnhancer } from '@uniformdev/canvas';
|
|
4
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Props passed to a Canvas component implementation.
|
|
@@ -228,6 +229,41 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
|
|
|
228
229
|
*/
|
|
229
230
|
declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
|
|
230
231
|
|
|
232
|
+
type RichTextComponentProps<TNode extends RichTextNode = RichTextNode> = {
|
|
233
|
+
node: TNode;
|
|
234
|
+
};
|
|
235
|
+
type RichTextRendererComponent<TNode extends RichTextNode = RichTextNode> = React$1.ComponentType<PropsWithChildren<RichTextComponentProps<TNode>>>;
|
|
236
|
+
/**
|
|
237
|
+
* Function that maps a Rich Text node instance to its React component to render it.
|
|
238
|
+
* The resolver would commonly inspect the `type` of the component to decide.
|
|
239
|
+
*/
|
|
240
|
+
type RenderRichTextComponentResolver = (node: RichTextNode) => RichTextRendererComponent | null | undefined;
|
|
241
|
+
|
|
242
|
+
type UniformRichTextProps = {
|
|
243
|
+
/** The ID of the parameter. */
|
|
244
|
+
parameterId: string;
|
|
245
|
+
/**
|
|
246
|
+
* A function which can provide a custom react component
|
|
247
|
+
* for rendering a rich text node
|
|
248
|
+
*/
|
|
249
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Adds rendering support for Uniform Rich Text parameters
|
|
253
|
+
* @deprecated This component is unstable, and not ready for production usage.
|
|
254
|
+
*/
|
|
255
|
+
declare function UniformRichText({ parameterId, resolveRichTextRenderer }: UniformRichTextProps): React$1.JSX.Element | null;
|
|
256
|
+
|
|
257
|
+
type UniformRichTextNodeProps = {
|
|
258
|
+
node: RichTextNode;
|
|
259
|
+
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Render a single RichText node
|
|
263
|
+
* @deprecated This component is unstable, and not ready for production usage.
|
|
264
|
+
*/
|
|
265
|
+
declare function UniformRichTextNode({ node, ...props }: UniformRichTextNodeProps): React$1.JSX.Element | null;
|
|
266
|
+
|
|
231
267
|
type CustomSlotChildRenderFunc = (options: {
|
|
232
268
|
child: ReactNode;
|
|
233
269
|
component: ComponentInstance;
|
|
@@ -333,4 +369,4 @@ declare const createComponentStoreResolver: (options: {
|
|
|
333
369
|
defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
|
|
334
370
|
}) => RenderComponentResolver;
|
|
335
371
|
|
|
336
|
-
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, GetParameterAttributesProps, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
|
372
|
+
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, GetParameterAttributesProps, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, RenderRichTextComponentResolver, RichTextComponentProps, RichTextRendererComponent, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformRichText, UniformRichTextNode, UniformRichTextNodeProps, UniformRichTextProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
package/dist/index.esm.js
CHANGED
|
@@ -552,8 +552,127 @@ function resolveChildren({
|
|
|
552
552
|
return renderChildren;
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
556
|
+
import { isRichTextNode as isRichTextNode2 } from "@uniformdev/richtext";
|
|
557
|
+
import React16, { useMemo as useMemo2 } from "react";
|
|
558
|
+
|
|
559
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
560
|
+
import { isRichTextNode } from "@uniformdev/richtext";
|
|
561
|
+
import React15 from "react";
|
|
562
|
+
|
|
563
|
+
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
564
|
+
import React7 from "react";
|
|
565
|
+
var HeadingRichTextNode = ({ children, node }) => {
|
|
566
|
+
const { tag } = node;
|
|
567
|
+
const HTag = tag != null ? tag : "h1";
|
|
568
|
+
return /* @__PURE__ */ React7.createElement(HTag, null, children);
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
572
|
+
import React8 from "react";
|
|
573
|
+
var LinebreakRichTextNode = () => {
|
|
574
|
+
return /* @__PURE__ */ React8.createElement("br", null);
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
578
|
+
import { linkParamValueToHref } from "@uniformdev/richtext";
|
|
579
|
+
import React9 from "react";
|
|
580
|
+
var LinkRichTextNode = ({ children, node }) => {
|
|
581
|
+
const { link } = node;
|
|
582
|
+
return /* @__PURE__ */ React9.createElement("a", { href: linkParamValueToHref(link) }, children);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
586
|
+
import React10 from "react";
|
|
587
|
+
var ListItemRichTextNode = ({ children, node }) => {
|
|
588
|
+
const { value } = node;
|
|
589
|
+
return /* @__PURE__ */ React10.createElement("li", { value: Number.isFinite(value) && value > 0 ? value + 1 : void 0 }, children);
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
593
|
+
import React11 from "react";
|
|
594
|
+
var ListRichTextNode = ({ children, node }) => {
|
|
595
|
+
const { tag, start } = node;
|
|
596
|
+
const ListTag = tag != null ? tag : "ul";
|
|
597
|
+
return /* @__PURE__ */ React11.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
601
|
+
import { isPureDirection, isPureTextAlign } from "@uniformdev/richtext";
|
|
602
|
+
import React12 from "react";
|
|
603
|
+
var ParagraphRichTextNode = ({ children, node }) => {
|
|
604
|
+
const { format, direction } = node;
|
|
605
|
+
return /* @__PURE__ */ React12.createElement(
|
|
606
|
+
"p",
|
|
607
|
+
{
|
|
608
|
+
dir: isPureDirection(direction) ? direction : void 0,
|
|
609
|
+
style: isPureTextAlign(format) ? { textAlign: format } : void 0
|
|
610
|
+
},
|
|
611
|
+
children
|
|
612
|
+
);
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
616
|
+
import React13 from "react";
|
|
617
|
+
var TabRichTextNode = () => {
|
|
618
|
+
return /* @__PURE__ */ React13.createElement(React13.Fragment, null, " ");
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
622
|
+
import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
|
|
623
|
+
import React14 from "react";
|
|
624
|
+
var TextRichTextNode = ({ node }) => {
|
|
625
|
+
const { text, format } = node;
|
|
626
|
+
const tags = getRichTextTagsFromTextFormat(format);
|
|
627
|
+
return /* @__PURE__ */ React14.createElement(React14.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React14.createElement(Tag, null, children), text) : text);
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
631
|
+
function UniformRichTextNode({ node, ...props }) {
|
|
632
|
+
var _a;
|
|
633
|
+
if (!isRichTextNode(node))
|
|
634
|
+
return null;
|
|
635
|
+
let NodeRenderer = (_a = props.resolveRichTextRenderer) == null ? void 0 : _a.call(props, node);
|
|
636
|
+
if (typeof NodeRenderer === "undefined") {
|
|
637
|
+
NodeRenderer = resolveRichTextDefaultRenderer(node);
|
|
638
|
+
}
|
|
639
|
+
if (!NodeRenderer) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React15.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
643
|
+
return /* @__PURE__ */ React15.createElement(NodeRenderer, { node }, children);
|
|
644
|
+
}
|
|
645
|
+
var rendererMap = /* @__PURE__ */ new Map([
|
|
646
|
+
["heading", HeadingRichTextNode],
|
|
647
|
+
["linebreak", LinebreakRichTextNode],
|
|
648
|
+
["link", LinkRichTextNode],
|
|
649
|
+
["list", ListRichTextNode],
|
|
650
|
+
["listitem", ListItemRichTextNode],
|
|
651
|
+
["paragraph", ParagraphRichTextNode],
|
|
652
|
+
["quote", ({ children }) => /* @__PURE__ */ React15.createElement("blockquote", null, children)],
|
|
653
|
+
["root", ({ children }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, children)],
|
|
654
|
+
["text", TextRichTextNode],
|
|
655
|
+
["tab", TabRichTextNode]
|
|
656
|
+
]);
|
|
657
|
+
var resolveRichTextDefaultRenderer = (node) => {
|
|
658
|
+
return rendererMap.get(node.type);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
662
|
+
function UniformRichText({ parameterId, resolveRichTextRenderer }) {
|
|
663
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
664
|
+
const parameter = useMemo2(() => {
|
|
665
|
+
var _a;
|
|
666
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
667
|
+
}, [componentData, parameterId]);
|
|
668
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
669
|
+
if (!value || !isRichTextNode2(value == null ? void 0 : value.root))
|
|
670
|
+
return null;
|
|
671
|
+
return /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer });
|
|
672
|
+
}
|
|
673
|
+
|
|
555
674
|
// src/components/UniformText.tsx
|
|
556
|
-
import
|
|
675
|
+
import React17, { useCallback, useMemo as useMemo3, useState as useState2 } from "react";
|
|
557
676
|
var UniformText = ({
|
|
558
677
|
as: Tag = "span",
|
|
559
678
|
parameterId,
|
|
@@ -565,12 +684,12 @@ var UniformText = ({
|
|
|
565
684
|
const { data: componentData } = useUniformCurrentComponent();
|
|
566
685
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
567
686
|
const [isFocused, setIsFocused] = useState2(false);
|
|
568
|
-
const parameter =
|
|
687
|
+
const parameter = useMemo3(() => {
|
|
569
688
|
var _a;
|
|
570
689
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
571
690
|
}, [componentData, parameterId]);
|
|
572
|
-
const value =
|
|
573
|
-
const isEditable =
|
|
691
|
+
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
692
|
+
const isEditable = useMemo3(() => {
|
|
574
693
|
var _a, _b;
|
|
575
694
|
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
576
695
|
}, [parameter]);
|
|
@@ -580,7 +699,7 @@ var UniformText = ({
|
|
|
580
699
|
const handleOnBlur = useCallback(() => {
|
|
581
700
|
setIsFocused(false);
|
|
582
701
|
}, [setIsFocused]);
|
|
583
|
-
const shouldSkipCustomRendering =
|
|
702
|
+
const shouldSkipCustomRendering = useMemo3(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
584
703
|
if (!parameter) {
|
|
585
704
|
console.warn(
|
|
586
705
|
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
@@ -588,9 +707,9 @@ var UniformText = ({
|
|
|
588
707
|
return null;
|
|
589
708
|
}
|
|
590
709
|
if (!isContextualEditing) {
|
|
591
|
-
return /* @__PURE__ */
|
|
710
|
+
return /* @__PURE__ */ React17.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
592
711
|
}
|
|
593
|
-
return /* @__PURE__ */
|
|
712
|
+
return /* @__PURE__ */ React17.createElement(
|
|
594
713
|
Tag,
|
|
595
714
|
{
|
|
596
715
|
...props,
|
|
@@ -673,6 +792,8 @@ export {
|
|
|
673
792
|
NOT_IMPLEMENTED_COMPONENT,
|
|
674
793
|
UniformComponent,
|
|
675
794
|
UniformComposition,
|
|
795
|
+
UniformRichText,
|
|
796
|
+
UniformRichTextNode,
|
|
676
797
|
UniformSlot,
|
|
677
798
|
UniformText,
|
|
678
799
|
componentStore,
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,8 @@ __export(src_exports, {
|
|
|
34
34
|
NOT_IMPLEMENTED_COMPONENT: () => NOT_IMPLEMENTED_COMPONENT,
|
|
35
35
|
UniformComponent: () => UniformComponent,
|
|
36
36
|
UniformComposition: () => UniformComposition,
|
|
37
|
+
UniformRichText: () => UniformRichText,
|
|
38
|
+
UniformRichTextNode: () => UniformRichTextNode,
|
|
37
39
|
UniformSlot: () => UniformSlot,
|
|
38
40
|
UniformText: () => UniformText,
|
|
39
41
|
componentStore: () => componentStore,
|
|
@@ -581,8 +583,127 @@ function resolveChildren({
|
|
|
581
583
|
return renderChildren;
|
|
582
584
|
}
|
|
583
585
|
|
|
584
|
-
// src/components/
|
|
586
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
587
|
+
var import_richtext5 = require("@uniformdev/richtext");
|
|
588
|
+
var import_react16 = __toESM(require("react"));
|
|
589
|
+
|
|
590
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
591
|
+
var import_richtext4 = require("@uniformdev/richtext");
|
|
592
|
+
var import_react15 = __toESM(require("react"));
|
|
593
|
+
|
|
594
|
+
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
585
595
|
var import_react7 = __toESM(require("react"));
|
|
596
|
+
var HeadingRichTextNode = ({ children, node }) => {
|
|
597
|
+
const { tag } = node;
|
|
598
|
+
const HTag = tag != null ? tag : "h1";
|
|
599
|
+
return /* @__PURE__ */ import_react7.default.createElement(HTag, null, children);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
603
|
+
var import_react8 = __toESM(require("react"));
|
|
604
|
+
var LinebreakRichTextNode = () => {
|
|
605
|
+
return /* @__PURE__ */ import_react8.default.createElement("br", null);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
609
|
+
var import_richtext = require("@uniformdev/richtext");
|
|
610
|
+
var import_react9 = __toESM(require("react"));
|
|
611
|
+
var LinkRichTextNode = ({ children, node }) => {
|
|
612
|
+
const { link } = node;
|
|
613
|
+
return /* @__PURE__ */ import_react9.default.createElement("a", { href: (0, import_richtext.linkParamValueToHref)(link) }, children);
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
617
|
+
var import_react10 = __toESM(require("react"));
|
|
618
|
+
var ListItemRichTextNode = ({ children, node }) => {
|
|
619
|
+
const { value } = node;
|
|
620
|
+
return /* @__PURE__ */ import_react10.default.createElement("li", { value: Number.isFinite(value) && value > 0 ? value + 1 : void 0 }, children);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
624
|
+
var import_react11 = __toESM(require("react"));
|
|
625
|
+
var ListRichTextNode = ({ children, node }) => {
|
|
626
|
+
const { tag, start } = node;
|
|
627
|
+
const ListTag = tag != null ? tag : "ul";
|
|
628
|
+
return /* @__PURE__ */ import_react11.default.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
632
|
+
var import_richtext2 = require("@uniformdev/richtext");
|
|
633
|
+
var import_react12 = __toESM(require("react"));
|
|
634
|
+
var ParagraphRichTextNode = ({ children, node }) => {
|
|
635
|
+
const { format, direction } = node;
|
|
636
|
+
return /* @__PURE__ */ import_react12.default.createElement(
|
|
637
|
+
"p",
|
|
638
|
+
{
|
|
639
|
+
dir: (0, import_richtext2.isPureDirection)(direction) ? direction : void 0,
|
|
640
|
+
style: (0, import_richtext2.isPureTextAlign)(format) ? { textAlign: format } : void 0
|
|
641
|
+
},
|
|
642
|
+
children
|
|
643
|
+
);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
647
|
+
var import_react13 = __toESM(require("react"));
|
|
648
|
+
var TabRichTextNode = () => {
|
|
649
|
+
return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, " ");
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
653
|
+
var import_richtext3 = require("@uniformdev/richtext");
|
|
654
|
+
var import_react14 = __toESM(require("react"));
|
|
655
|
+
var TextRichTextNode = ({ node }) => {
|
|
656
|
+
const { text, format } = node;
|
|
657
|
+
const tags = (0, import_richtext3.getRichTextTagsFromTextFormat)(format);
|
|
658
|
+
return /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ import_react14.default.createElement(Tag, null, children), text) : text);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
662
|
+
function UniformRichTextNode({ node, ...props }) {
|
|
663
|
+
var _a;
|
|
664
|
+
if (!(0, import_richtext4.isRichTextNode)(node))
|
|
665
|
+
return null;
|
|
666
|
+
let NodeRenderer = (_a = props.resolveRichTextRenderer) == null ? void 0 : _a.call(props, node);
|
|
667
|
+
if (typeof NodeRenderer === "undefined") {
|
|
668
|
+
NodeRenderer = resolveRichTextDefaultRenderer(node);
|
|
669
|
+
}
|
|
670
|
+
if (!NodeRenderer) {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ import_react15.default.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
674
|
+
return /* @__PURE__ */ import_react15.default.createElement(NodeRenderer, { node }, children);
|
|
675
|
+
}
|
|
676
|
+
var rendererMap = /* @__PURE__ */ new Map([
|
|
677
|
+
["heading", HeadingRichTextNode],
|
|
678
|
+
["linebreak", LinebreakRichTextNode],
|
|
679
|
+
["link", LinkRichTextNode],
|
|
680
|
+
["list", ListRichTextNode],
|
|
681
|
+
["listitem", ListItemRichTextNode],
|
|
682
|
+
["paragraph", ParagraphRichTextNode],
|
|
683
|
+
["quote", ({ children }) => /* @__PURE__ */ import_react15.default.createElement("blockquote", null, children)],
|
|
684
|
+
["root", ({ children }) => /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, children)],
|
|
685
|
+
["text", TextRichTextNode],
|
|
686
|
+
["tab", TabRichTextNode]
|
|
687
|
+
]);
|
|
688
|
+
var resolveRichTextDefaultRenderer = (node) => {
|
|
689
|
+
return rendererMap.get(node.type);
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
693
|
+
function UniformRichText({ parameterId, resolveRichTextRenderer }) {
|
|
694
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
695
|
+
const parameter = (0, import_react16.useMemo)(() => {
|
|
696
|
+
var _a;
|
|
697
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
698
|
+
}, [componentData, parameterId]);
|
|
699
|
+
const value = (0, import_react16.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
700
|
+
if (!value || !(0, import_richtext5.isRichTextNode)(value == null ? void 0 : value.root))
|
|
701
|
+
return null;
|
|
702
|
+
return /* @__PURE__ */ import_react16.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer });
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/components/UniformText.tsx
|
|
706
|
+
var import_react17 = __toESM(require("react"));
|
|
586
707
|
var UniformText = ({
|
|
587
708
|
as: Tag = "span",
|
|
588
709
|
parameterId,
|
|
@@ -593,23 +714,23 @@ var UniformText = ({
|
|
|
593
714
|
}) => {
|
|
594
715
|
const { data: componentData } = useUniformCurrentComponent();
|
|
595
716
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
596
|
-
const [isFocused, setIsFocused] = (0,
|
|
597
|
-
const parameter = (0,
|
|
717
|
+
const [isFocused, setIsFocused] = (0, import_react17.useState)(false);
|
|
718
|
+
const parameter = (0, import_react17.useMemo)(() => {
|
|
598
719
|
var _a;
|
|
599
720
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
600
721
|
}, [componentData, parameterId]);
|
|
601
|
-
const value = (0,
|
|
602
|
-
const isEditable = (0,
|
|
722
|
+
const value = (0, import_react17.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
723
|
+
const isEditable = (0, import_react17.useMemo)(() => {
|
|
603
724
|
var _a, _b;
|
|
604
725
|
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
605
726
|
}, [parameter]);
|
|
606
|
-
const handleOnFocus = (0,
|
|
727
|
+
const handleOnFocus = (0, import_react17.useCallback)(() => {
|
|
607
728
|
setIsFocused(true);
|
|
608
729
|
}, [setIsFocused]);
|
|
609
|
-
const handleOnBlur = (0,
|
|
730
|
+
const handleOnBlur = (0, import_react17.useCallback)(() => {
|
|
610
731
|
setIsFocused(false);
|
|
611
732
|
}, [setIsFocused]);
|
|
612
|
-
const shouldSkipCustomRendering = (0,
|
|
733
|
+
const shouldSkipCustomRendering = (0, import_react17.useMemo)(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
613
734
|
if (!parameter) {
|
|
614
735
|
console.warn(
|
|
615
736
|
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
@@ -617,9 +738,9 @@ var UniformText = ({
|
|
|
617
738
|
return null;
|
|
618
739
|
}
|
|
619
740
|
if (!isContextualEditing) {
|
|
620
|
-
return /* @__PURE__ */
|
|
741
|
+
return /* @__PURE__ */ import_react17.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
621
742
|
}
|
|
622
|
-
return /* @__PURE__ */
|
|
743
|
+
return /* @__PURE__ */ import_react17.default.createElement(
|
|
623
744
|
Tag,
|
|
624
745
|
{
|
|
625
746
|
...props,
|
|
@@ -660,14 +781,14 @@ var getParameterAttributes = ({ id, component, placeholder }) => {
|
|
|
660
781
|
|
|
661
782
|
// src/hooks/useCompositionEventEffect.ts
|
|
662
783
|
var import_canvas7 = require("@uniformdev/canvas");
|
|
663
|
-
var
|
|
784
|
+
var import_react18 = require("react");
|
|
664
785
|
function useCompositionEventEffect({
|
|
665
786
|
enabled,
|
|
666
787
|
projectId,
|
|
667
788
|
compositionId,
|
|
668
789
|
effect
|
|
669
790
|
}) {
|
|
670
|
-
(0,
|
|
791
|
+
(0, import_react18.useEffect)(() => {
|
|
671
792
|
if (!enabled || !compositionId || !projectId) {
|
|
672
793
|
return;
|
|
673
794
|
}
|
|
@@ -699,6 +820,8 @@ function useCompositionEventEffect({
|
|
|
699
820
|
NOT_IMPLEMENTED_COMPONENT,
|
|
700
821
|
UniformComponent,
|
|
701
822
|
UniformComposition,
|
|
823
|
+
UniformRichText,
|
|
824
|
+
UniformRichTextNode,
|
|
702
825
|
UniformSlot,
|
|
703
826
|
UniformText,
|
|
704
827
|
componentStore,
|
package/dist/index.mjs
CHANGED
|
@@ -552,8 +552,127 @@ function resolveChildren({
|
|
|
552
552
|
return renderChildren;
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
556
|
+
import { isRichTextNode as isRichTextNode2 } from "@uniformdev/richtext";
|
|
557
|
+
import React16, { useMemo as useMemo2 } from "react";
|
|
558
|
+
|
|
559
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
560
|
+
import { isRichTextNode } from "@uniformdev/richtext";
|
|
561
|
+
import React15 from "react";
|
|
562
|
+
|
|
563
|
+
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
564
|
+
import React7 from "react";
|
|
565
|
+
var HeadingRichTextNode = ({ children, node }) => {
|
|
566
|
+
const { tag } = node;
|
|
567
|
+
const HTag = tag != null ? tag : "h1";
|
|
568
|
+
return /* @__PURE__ */ React7.createElement(HTag, null, children);
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
572
|
+
import React8 from "react";
|
|
573
|
+
var LinebreakRichTextNode = () => {
|
|
574
|
+
return /* @__PURE__ */ React8.createElement("br", null);
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
578
|
+
import { linkParamValueToHref } from "@uniformdev/richtext";
|
|
579
|
+
import React9 from "react";
|
|
580
|
+
var LinkRichTextNode = ({ children, node }) => {
|
|
581
|
+
const { link } = node;
|
|
582
|
+
return /* @__PURE__ */ React9.createElement("a", { href: linkParamValueToHref(link) }, children);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
586
|
+
import React10 from "react";
|
|
587
|
+
var ListItemRichTextNode = ({ children, node }) => {
|
|
588
|
+
const { value } = node;
|
|
589
|
+
return /* @__PURE__ */ React10.createElement("li", { value: Number.isFinite(value) && value > 0 ? value + 1 : void 0 }, children);
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
593
|
+
import React11 from "react";
|
|
594
|
+
var ListRichTextNode = ({ children, node }) => {
|
|
595
|
+
const { tag, start } = node;
|
|
596
|
+
const ListTag = tag != null ? tag : "ul";
|
|
597
|
+
return /* @__PURE__ */ React11.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
601
|
+
import { isPureDirection, isPureTextAlign } from "@uniformdev/richtext";
|
|
602
|
+
import React12 from "react";
|
|
603
|
+
var ParagraphRichTextNode = ({ children, node }) => {
|
|
604
|
+
const { format, direction } = node;
|
|
605
|
+
return /* @__PURE__ */ React12.createElement(
|
|
606
|
+
"p",
|
|
607
|
+
{
|
|
608
|
+
dir: isPureDirection(direction) ? direction : void 0,
|
|
609
|
+
style: isPureTextAlign(format) ? { textAlign: format } : void 0
|
|
610
|
+
},
|
|
611
|
+
children
|
|
612
|
+
);
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
616
|
+
import React13 from "react";
|
|
617
|
+
var TabRichTextNode = () => {
|
|
618
|
+
return /* @__PURE__ */ React13.createElement(React13.Fragment, null, " ");
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
622
|
+
import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
|
|
623
|
+
import React14 from "react";
|
|
624
|
+
var TextRichTextNode = ({ node }) => {
|
|
625
|
+
const { text, format } = node;
|
|
626
|
+
const tags = getRichTextTagsFromTextFormat(format);
|
|
627
|
+
return /* @__PURE__ */ React14.createElement(React14.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React14.createElement(Tag, null, children), text) : text);
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
631
|
+
function UniformRichTextNode({ node, ...props }) {
|
|
632
|
+
var _a;
|
|
633
|
+
if (!isRichTextNode(node))
|
|
634
|
+
return null;
|
|
635
|
+
let NodeRenderer = (_a = props.resolveRichTextRenderer) == null ? void 0 : _a.call(props, node);
|
|
636
|
+
if (typeof NodeRenderer === "undefined") {
|
|
637
|
+
NodeRenderer = resolveRichTextDefaultRenderer(node);
|
|
638
|
+
}
|
|
639
|
+
if (!NodeRenderer) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React15.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
643
|
+
return /* @__PURE__ */ React15.createElement(NodeRenderer, { node }, children);
|
|
644
|
+
}
|
|
645
|
+
var rendererMap = /* @__PURE__ */ new Map([
|
|
646
|
+
["heading", HeadingRichTextNode],
|
|
647
|
+
["linebreak", LinebreakRichTextNode],
|
|
648
|
+
["link", LinkRichTextNode],
|
|
649
|
+
["list", ListRichTextNode],
|
|
650
|
+
["listitem", ListItemRichTextNode],
|
|
651
|
+
["paragraph", ParagraphRichTextNode],
|
|
652
|
+
["quote", ({ children }) => /* @__PURE__ */ React15.createElement("blockquote", null, children)],
|
|
653
|
+
["root", ({ children }) => /* @__PURE__ */ React15.createElement(React15.Fragment, null, children)],
|
|
654
|
+
["text", TextRichTextNode],
|
|
655
|
+
["tab", TabRichTextNode]
|
|
656
|
+
]);
|
|
657
|
+
var resolveRichTextDefaultRenderer = (node) => {
|
|
658
|
+
return rendererMap.get(node.type);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/components/UniformRichText/UniformRichText.tsx
|
|
662
|
+
function UniformRichText({ parameterId, resolveRichTextRenderer }) {
|
|
663
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
664
|
+
const parameter = useMemo2(() => {
|
|
665
|
+
var _a;
|
|
666
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
667
|
+
}, [componentData, parameterId]);
|
|
668
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
669
|
+
if (!value || !isRichTextNode2(value == null ? void 0 : value.root))
|
|
670
|
+
return null;
|
|
671
|
+
return /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer });
|
|
672
|
+
}
|
|
673
|
+
|
|
555
674
|
// src/components/UniformText.tsx
|
|
556
|
-
import
|
|
675
|
+
import React17, { useCallback, useMemo as useMemo3, useState as useState2 } from "react";
|
|
557
676
|
var UniformText = ({
|
|
558
677
|
as: Tag = "span",
|
|
559
678
|
parameterId,
|
|
@@ -565,12 +684,12 @@ var UniformText = ({
|
|
|
565
684
|
const { data: componentData } = useUniformCurrentComponent();
|
|
566
685
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
567
686
|
const [isFocused, setIsFocused] = useState2(false);
|
|
568
|
-
const parameter =
|
|
687
|
+
const parameter = useMemo3(() => {
|
|
569
688
|
var _a;
|
|
570
689
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
571
690
|
}, [componentData, parameterId]);
|
|
572
|
-
const value =
|
|
573
|
-
const isEditable =
|
|
691
|
+
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
692
|
+
const isEditable = useMemo3(() => {
|
|
574
693
|
var _a, _b;
|
|
575
694
|
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
576
695
|
}, [parameter]);
|
|
@@ -580,7 +699,7 @@ var UniformText = ({
|
|
|
580
699
|
const handleOnBlur = useCallback(() => {
|
|
581
700
|
setIsFocused(false);
|
|
582
701
|
}, [setIsFocused]);
|
|
583
|
-
const shouldSkipCustomRendering =
|
|
702
|
+
const shouldSkipCustomRendering = useMemo3(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
584
703
|
if (!parameter) {
|
|
585
704
|
console.warn(
|
|
586
705
|
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
@@ -588,9 +707,9 @@ var UniformText = ({
|
|
|
588
707
|
return null;
|
|
589
708
|
}
|
|
590
709
|
if (!isContextualEditing) {
|
|
591
|
-
return /* @__PURE__ */
|
|
710
|
+
return /* @__PURE__ */ React17.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
592
711
|
}
|
|
593
|
-
return /* @__PURE__ */
|
|
712
|
+
return /* @__PURE__ */ React17.createElement(
|
|
594
713
|
Tag,
|
|
595
714
|
{
|
|
596
715
|
...props,
|
|
@@ -673,6 +792,8 @@ export {
|
|
|
673
792
|
NOT_IMPLEMENTED_COMPONENT,
|
|
674
793
|
UniformComponent,
|
|
675
794
|
UniformComposition,
|
|
795
|
+
UniformRichText,
|
|
796
|
+
UniformRichTextNode,
|
|
676
797
|
UniformSlot,
|
|
677
798
|
UniformText,
|
|
678
799
|
componentStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.14.
|
|
3
|
+
"version": "19.14.1-alpha.11+89dabee14",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
"document": "api-extractor run --local"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@uniformdev/canvas": "19.14.
|
|
28
|
-
"@uniformdev/context": "19.14.
|
|
29
|
-
"@uniformdev/context-react": "19.14.
|
|
27
|
+
"@uniformdev/canvas": "19.14.1-alpha.11+89dabee14",
|
|
28
|
+
"@uniformdev/context": "19.14.1-alpha.11+89dabee14",
|
|
29
|
+
"@uniformdev/context-react": "19.14.1-alpha.11+89dabee14",
|
|
30
|
+
"@uniformdev/richtext": "19.14.1-alpha.11+89dabee14"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"react": ">= 16 || 17 || 18",
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "89dabee148728ef7f329e18b7194766a9e6b9631"
|
|
47
48
|
}
|