@rocapine/react-native-onboarding-ui 1.30.0 → 1.31.0
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/UI/Pages/ComposableScreen/elements/TextElement.d.ts +47 -2
- package/dist/UI/Pages/ComposableScreen/elements/TextElement.d.ts.map +1 -1
- package/dist/UI/Pages/ComposableScreen/elements/TextElement.js +46 -6
- package/dist/UI/Pages/ComposableScreen/elements/TextElement.js.map +1 -1
- package/package.json +1 -1
- package/src/UI/Pages/ComposableScreen/elements/TextElement.tsx +75 -5
|
@@ -3,8 +3,36 @@ import { z } from "zod";
|
|
|
3
3
|
import { BaseBoxProps } from "./BaseBoxProps";
|
|
4
4
|
import { UIElement } from "../types";
|
|
5
5
|
import { RenderContext } from "./shared";
|
|
6
|
+
export type TextSpan = {
|
|
7
|
+
text: string;
|
|
8
|
+
fontWeight?: string;
|
|
9
|
+
fontStyle?: "normal" | "italic";
|
|
10
|
+
fontFamily?: string | "inherit";
|
|
11
|
+
fontSize?: number;
|
|
12
|
+
letterSpacing?: number;
|
|
13
|
+
color?: string;
|
|
14
|
+
textDecorationLine?: "none" | "underline" | "line-through" | "underline line-through";
|
|
15
|
+
};
|
|
16
|
+
export declare const TextSpanSchema: z.ZodObject<{
|
|
17
|
+
text: z.ZodString;
|
|
18
|
+
fontWeight: z.ZodOptional<z.ZodString>;
|
|
19
|
+
fontStyle: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
normal: "normal";
|
|
21
|
+
italic: "italic";
|
|
22
|
+
}>>;
|
|
23
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
24
|
+
fontSize: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
letterSpacing: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
color: z.ZodOptional<z.ZodString>;
|
|
27
|
+
textDecorationLine: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
none: "none";
|
|
29
|
+
underline: "underline";
|
|
30
|
+
"line-through": "line-through";
|
|
31
|
+
"underline line-through": "underline line-through";
|
|
32
|
+
}>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
6
34
|
export type TextElementProps = BaseBoxProps & {
|
|
7
|
-
content: string;
|
|
35
|
+
content: string | TextSpan[];
|
|
8
36
|
mode?: "plain" | "expression";
|
|
9
37
|
fontSize?: number;
|
|
10
38
|
fontWeight?: string;
|
|
@@ -85,7 +113,24 @@ export declare const TextElementPropsSchema: z.ZodObject<{
|
|
|
85
113
|
shadowOpacity: z.ZodOptional<z.ZodNumber>;
|
|
86
114
|
shadowRadius: z.ZodOptional<z.ZodNumber>;
|
|
87
115
|
elevation: z.ZodOptional<z.ZodNumber>;
|
|
88
|
-
content: z.ZodString
|
|
116
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
|
|
117
|
+
text: z.ZodString;
|
|
118
|
+
fontWeight: z.ZodOptional<z.ZodString>;
|
|
119
|
+
fontStyle: z.ZodOptional<z.ZodEnum<{
|
|
120
|
+
normal: "normal";
|
|
121
|
+
italic: "italic";
|
|
122
|
+
}>>;
|
|
123
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
124
|
+
fontSize: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
letterSpacing: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
color: z.ZodOptional<z.ZodString>;
|
|
127
|
+
textDecorationLine: z.ZodOptional<z.ZodEnum<{
|
|
128
|
+
none: "none";
|
|
129
|
+
underline: "underline";
|
|
130
|
+
"line-through": "line-through";
|
|
131
|
+
"underline line-through": "underline line-through";
|
|
132
|
+
}>>;
|
|
133
|
+
}, z.core.$strip>>]>;
|
|
89
134
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
90
135
|
plain: "plain";
|
|
91
136
|
expression: "expression";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextElement.d.ts","sourceRoot":"","sources":["../../../../../src/UI/Pages/ComposableScreen/elements/TextElement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAgD,MAAM,UAAU,CAAC;AAGvF,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TextElement.d.ts","sourceRoot":"","sources":["../../../../../src/UI/Pages/ComposableScreen/elements/TextElement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAgD,MAAM,UAAU,CAAC;AAGvF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EACf,MAAM,GACN,WAAW,GACX,cAAc,GACd,wBAAwB,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;iBAWzB,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAWjC,CAAC;AAoCH,KAAK,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE1D,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,aAAa,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,8BAA8B,KAAK,KAAG,KAAK,CAAC,YA6FhF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextElementComponent = exports.TextElementPropsSchema = void 0;
|
|
3
|
+
exports.TextElementComponent = exports.TextElementPropsSchema = exports.TextSpanSchema = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const react_native_1 = require("react-native");
|
|
@@ -8,8 +8,20 @@ const react_native_onboarding_1 = require("@rocapine/react-native-onboarding");
|
|
|
8
8
|
const BaseBoxProps_1 = require("./BaseBoxProps");
|
|
9
9
|
const shared_1 = require("./shared");
|
|
10
10
|
const GradientBox_1 = require("./GradientBox");
|
|
11
|
+
exports.TextSpanSchema = zod_1.z.object({
|
|
12
|
+
text: zod_1.z.string(),
|
|
13
|
+
fontWeight: zod_1.z.string().optional(),
|
|
14
|
+
fontStyle: zod_1.z.enum(["normal", "italic"]).optional(),
|
|
15
|
+
fontFamily: zod_1.z.string().optional(),
|
|
16
|
+
fontSize: zod_1.z.number().optional(),
|
|
17
|
+
letterSpacing: zod_1.z.number().optional(),
|
|
18
|
+
color: zod_1.z.string().optional(),
|
|
19
|
+
textDecorationLine: zod_1.z
|
|
20
|
+
.enum(["none", "underline", "line-through", "underline line-through"])
|
|
21
|
+
.optional(),
|
|
22
|
+
});
|
|
11
23
|
exports.TextElementPropsSchema = BaseBoxProps_1.BaseBoxPropsSchema.extend({
|
|
12
|
-
content: zod_1.z.string(),
|
|
24
|
+
content: zod_1.z.union([zod_1.z.string(), zod_1.z.array(exports.TextSpanSchema)]),
|
|
13
25
|
mode: zod_1.z.enum(["plain", "expression"]).optional(),
|
|
14
26
|
fontSize: zod_1.z.number().optional(),
|
|
15
27
|
fontWeight: zod_1.z.string().optional(),
|
|
@@ -20,13 +32,39 @@ exports.TextElementPropsSchema = BaseBoxProps_1.BaseBoxPropsSchema.extend({
|
|
|
20
32
|
letterSpacing: zod_1.z.number().optional(),
|
|
21
33
|
lineHeight: zod_1.z.number().optional(),
|
|
22
34
|
});
|
|
35
|
+
/**
|
|
36
|
+
* Renders one inline span. Isolated as its own component so the
|
|
37
|
+
* `useResolvedFontStyle` hook is called once per stable component instance —
|
|
38
|
+
* calling the hook in a `.map` loop inside the parent would break rules of
|
|
39
|
+
* hooks when the span count changes.
|
|
40
|
+
*/
|
|
41
|
+
const RichTextSpan = ({ span, baseFontFamily, }) => {
|
|
42
|
+
const fontFamily = (0, shared_1.resolveInheritedFontFamily)(span.fontFamily, baseFontFamily);
|
|
43
|
+
const resolved = (0, react_native_onboarding_1.useResolvedFontStyle)(fontFamily, span.fontWeight);
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: {
|
|
45
|
+
fontFamily: resolved.fontFamily,
|
|
46
|
+
fontWeight: resolved.resolvedToVariant
|
|
47
|
+
? undefined
|
|
48
|
+
: span.fontWeight,
|
|
49
|
+
fontStyle: span.fontStyle,
|
|
50
|
+
fontSize: span.fontSize,
|
|
51
|
+
letterSpacing: span.letterSpacing,
|
|
52
|
+
color: span.color,
|
|
53
|
+
textDecorationLine: span.textDecorationLine,
|
|
54
|
+
}, children: span.text }));
|
|
55
|
+
};
|
|
23
56
|
const TextElementComponent = ({ element, ctx, parentType }) => {
|
|
24
57
|
var _a, _b, _c;
|
|
25
58
|
const { theme, variables } = ctx;
|
|
26
59
|
const p = element.props;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
60
|
+
const isExpression = p.mode === "expression";
|
|
61
|
+
const content = Array.isArray(p.content)
|
|
62
|
+
? isExpression
|
|
63
|
+
? p.content.map((s) => (Object.assign(Object.assign({}, s), { text: (0, shared_1.interpolate)(s.text, variables) })))
|
|
64
|
+
: p.content
|
|
65
|
+
: isExpression
|
|
66
|
+
? (0, shared_1.interpolate)(p.content, variables)
|
|
67
|
+
: p.content;
|
|
30
68
|
const inheritedFontFamily = (0, shared_1.resolveInheritedFontFamily)(p.fontFamily, theme.typography.defaultFontFamily);
|
|
31
69
|
const resolvedFont = (0, react_native_onboarding_1.useResolvedFontStyle)(inheritedFontFamily, p.fontWeight);
|
|
32
70
|
const textNode = ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: {
|
|
@@ -59,7 +97,9 @@ const TextElementComponent = ({ element, ctx, parentType }) => {
|
|
|
59
97
|
borderRadius: p.backgroundGradient ? undefined : p.borderRadius,
|
|
60
98
|
borderColor: p.backgroundGradient ? undefined : p.borderColor,
|
|
61
99
|
opacity: p.backgroundGradient ? undefined : p.opacity,
|
|
62
|
-
}, children: content
|
|
100
|
+
}, children: typeof content === "string"
|
|
101
|
+
? content
|
|
102
|
+
: content.map((s, i) => ((0, jsx_runtime_1.jsx)(RichTextSpan, { span: s, baseFontFamily: inheritedFontFamily }, i))) }));
|
|
63
103
|
if (p.backgroundGradient) {
|
|
64
104
|
return ((0, jsx_runtime_1.jsx)(GradientBox_1.GradientBox, { gradient: p.backgroundGradient, style: {
|
|
65
105
|
flex: p.flex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextElement.js","sourceRoot":"","sources":["../../../../../src/UI/Pages/ComposableScreen/elements/TextElement.tsx"],"names":[],"mappings":";;;;AACA,6BAAwB;AACxB,+CAAoC;AACpC,+EAAyE;AACzE,iDAAkE;AAElE,qCAAuF;AACvF,+CAA4C;
|
|
1
|
+
{"version":3,"file":"TextElement.js","sourceRoot":"","sources":["../../../../../src/UI/Pages/ComposableScreen/elements/TextElement.tsx"],"names":[],"mappings":";;;;AACA,6BAAwB;AACxB,+CAAoC;AACpC,+EAAyE;AACzE,iDAAkE;AAElE,qCAAuF;AACvF,+CAA4C;AAiB/B,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE;IAClD,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACpC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,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,CAAC,CAAC,OAAO;gBAClB,iBAAiB,EAAE,CAAC,CAAC,iBAAiB;gBACtC,eAAe,EAAE,CAAC,CAAC,eAAe;gBAClC,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,gBAAgB,EAAE,CAAC,CAAC,gBAAgB;gBACpC,cAAc,EAAE,CAAC,CAAC,cAAc;gBAChC,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,YAAY,EAAE,CAAC,CAAC,YAAY;gBAC5B,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,QAAQ,EAAE,QAAQ;aACnB,YAEA,QAAQ,GACG,CACf,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA7FW,QAAA,oBAAoB,wBA6F/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"description": "UI components and renderers for Rocapine Onboarding Studio - Built on top of the headless SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -7,8 +7,36 @@ import { UIElement } from "../types";
|
|
|
7
7
|
import { RenderContext, interpolate, dim, resolveInheritedFontFamily } from "./shared";
|
|
8
8
|
import { GradientBox } from "./GradientBox";
|
|
9
9
|
|
|
10
|
+
export type TextSpan = {
|
|
11
|
+
text: string;
|
|
12
|
+
fontWeight?: string;
|
|
13
|
+
fontStyle?: "normal" | "italic";
|
|
14
|
+
fontFamily?: string | "inherit";
|
|
15
|
+
fontSize?: number;
|
|
16
|
+
letterSpacing?: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
textDecorationLine?:
|
|
19
|
+
| "none"
|
|
20
|
+
| "underline"
|
|
21
|
+
| "line-through"
|
|
22
|
+
| "underline line-through";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const TextSpanSchema = z.object({
|
|
26
|
+
text: z.string(),
|
|
27
|
+
fontWeight: z.string().optional(),
|
|
28
|
+
fontStyle: z.enum(["normal", "italic"]).optional(),
|
|
29
|
+
fontFamily: z.string().optional(),
|
|
30
|
+
fontSize: z.number().optional(),
|
|
31
|
+
letterSpacing: z.number().optional(),
|
|
32
|
+
color: z.string().optional(),
|
|
33
|
+
textDecorationLine: z
|
|
34
|
+
.enum(["none", "underline", "line-through", "underline line-through"])
|
|
35
|
+
.optional(),
|
|
36
|
+
});
|
|
37
|
+
|
|
10
38
|
export type TextElementProps = BaseBoxProps & {
|
|
11
|
-
content: string;
|
|
39
|
+
content: string | TextSpan[];
|
|
12
40
|
mode?: "plain" | "expression";
|
|
13
41
|
fontSize?: number;
|
|
14
42
|
fontWeight?: string;
|
|
@@ -21,7 +49,7 @@ export type TextElementProps = BaseBoxProps & {
|
|
|
21
49
|
};
|
|
22
50
|
|
|
23
51
|
export const TextElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
24
|
-
content: z.string(),
|
|
52
|
+
content: z.union([z.string(), z.array(TextSpanSchema)]),
|
|
25
53
|
mode: z.enum(["plain", "expression"]).optional(),
|
|
26
54
|
fontSize: z.number().optional(),
|
|
27
55
|
fontWeight: z.string().optional(),
|
|
@@ -33,6 +61,40 @@ export const TextElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
|
33
61
|
lineHeight: z.number().optional(),
|
|
34
62
|
});
|
|
35
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Renders one inline span. Isolated as its own component so the
|
|
66
|
+
* `useResolvedFontStyle` hook is called once per stable component instance —
|
|
67
|
+
* calling the hook in a `.map` loop inside the parent would break rules of
|
|
68
|
+
* hooks when the span count changes.
|
|
69
|
+
*/
|
|
70
|
+
const RichTextSpan = ({
|
|
71
|
+
span,
|
|
72
|
+
baseFontFamily,
|
|
73
|
+
}: {
|
|
74
|
+
span: TextSpan;
|
|
75
|
+
baseFontFamily: string | undefined;
|
|
76
|
+
}): React.ReactElement => {
|
|
77
|
+
const fontFamily = resolveInheritedFontFamily(span.fontFamily, baseFontFamily);
|
|
78
|
+
const resolved = useResolvedFontStyle(fontFamily, span.fontWeight);
|
|
79
|
+
return (
|
|
80
|
+
<Text
|
|
81
|
+
style={{
|
|
82
|
+
fontFamily: resolved.fontFamily,
|
|
83
|
+
fontWeight: resolved.resolvedToVariant
|
|
84
|
+
? undefined
|
|
85
|
+
: (span.fontWeight as any),
|
|
86
|
+
fontStyle: span.fontStyle,
|
|
87
|
+
fontSize: span.fontSize,
|
|
88
|
+
letterSpacing: span.letterSpacing,
|
|
89
|
+
color: span.color,
|
|
90
|
+
textDecorationLine: span.textDecorationLine,
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{span.text}
|
|
94
|
+
</Text>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
36
98
|
type TextUIElement = Extract<UIElement, { type: "Text" }>;
|
|
37
99
|
|
|
38
100
|
type Props = {
|
|
@@ -44,8 +106,12 @@ type Props = {
|
|
|
44
106
|
export const TextElementComponent = ({ element, ctx, parentType }: Props): React.ReactElement => {
|
|
45
107
|
const { theme, variables } = ctx;
|
|
46
108
|
const p = element.props;
|
|
47
|
-
const
|
|
48
|
-
|
|
109
|
+
const isExpression = p.mode === "expression";
|
|
110
|
+
const content: string | TextSpan[] = Array.isArray(p.content)
|
|
111
|
+
? isExpression
|
|
112
|
+
? p.content.map((s) => ({ ...s, text: interpolate(s.text, variables) }))
|
|
113
|
+
: p.content
|
|
114
|
+
: isExpression
|
|
49
115
|
? interpolate(p.content, variables)
|
|
50
116
|
: p.content;
|
|
51
117
|
const inheritedFontFamily = resolveInheritedFontFamily(
|
|
@@ -88,7 +154,11 @@ export const TextElementComponent = ({ element, ctx, parentType }: Props): React
|
|
|
88
154
|
opacity: p.backgroundGradient ? undefined : p.opacity,
|
|
89
155
|
}}
|
|
90
156
|
>
|
|
91
|
-
{content
|
|
157
|
+
{typeof content === "string"
|
|
158
|
+
? content
|
|
159
|
+
: content.map((s, i) => (
|
|
160
|
+
<RichTextSpan key={i} span={s} baseFontFamily={inheritedFontFamily} />
|
|
161
|
+
))}
|
|
92
162
|
</Text>
|
|
93
163
|
);
|
|
94
164
|
|