@makeswift/runtime 0.9.2 → 0.9.4
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/Box.cjs.js +1 -3
- package/dist/Box.cjs.js.map +1 -1
- package/dist/Box.es.js +2 -4
- package/dist/Box.es.js.map +1 -1
- package/dist/Button.cjs.js +1 -3
- package/dist/Button.cjs.js.map +1 -1
- package/dist/Button.es.js +2 -4
- package/dist/Button.es.js.map +1 -1
- package/dist/Carousel.cjs.js +1 -3
- package/dist/Carousel.cjs.js.map +1 -1
- package/dist/Carousel.es.js +2 -4
- package/dist/Carousel.es.js.map +1 -1
- package/dist/Countdown.cjs.js +1 -3
- package/dist/Countdown.cjs.js.map +1 -1
- package/dist/Countdown.es.js +2 -4
- package/dist/Countdown.es.js.map +1 -1
- package/dist/Divider.cjs.js +1 -3
- package/dist/Divider.cjs.js.map +1 -1
- package/dist/Divider.es.js +2 -4
- package/dist/Divider.es.js.map +1 -1
- package/dist/Embed.es.js +1 -1
- package/dist/Form.cjs.js +1 -3
- package/dist/Form.cjs.js.map +1 -1
- package/dist/Form.es.js +2 -4
- package/dist/Form.es.js.map +1 -1
- package/dist/Image.cjs.js +1 -3
- package/dist/Image.cjs.js.map +1 -1
- package/dist/Image.es.js +2 -4
- package/dist/Image.es.js.map +1 -1
- package/dist/LiveProvider.cjs.js +1 -3
- package/dist/LiveProvider.cjs.js.map +1 -1
- package/dist/LiveProvider.es.js +2 -4
- package/dist/LiveProvider.es.js.map +1 -1
- package/dist/Navigation.cjs.js +1 -3
- package/dist/Navigation.cjs.js.map +1 -1
- package/dist/Navigation.es.js +2 -4
- package/dist/Navigation.es.js.map +1 -1
- package/dist/PreviewProvider.cjs.js +3 -5
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +3 -5
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +4 -7
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +4 -7
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/ReadOnlyTextV2.cjs.js +11 -14
- package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
- package/dist/ReadOnlyTextV2.es.js +10 -13
- package/dist/ReadOnlyTextV2.es.js.map +1 -1
- package/dist/Root.cjs.js +1 -3
- package/dist/Root.cjs.js.map +1 -1
- package/dist/Root.es.js +2 -4
- package/dist/Root.es.js.map +1 -1
- package/dist/SocialLinks.cjs.js +1 -3
- package/dist/SocialLinks.cjs.js.map +1 -1
- package/dist/SocialLinks.es.js +2 -4
- package/dist/SocialLinks.es.js.map +1 -1
- package/dist/Text.cjs.js +2 -4
- package/dist/Text.cjs.js.map +1 -1
- package/dist/Text.es.js +2 -4
- package/dist/Text.es.js.map +1 -1
- package/dist/Video.es.js +1 -1
- package/dist/components.cjs.js +1 -3
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -3
- package/dist/components.es.js.map +1 -1
- package/dist/control-serialization.es.js +1 -1
- package/dist/controls.cjs.js +18 -15
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +2 -3
- package/dist/controls.es.js.map +1 -1
- package/dist/index.cjs.js +205 -57
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs10.js +261 -172
- package/dist/index.cjs10.js.map +1 -1
- package/dist/index.cjs5.js +99 -5
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs6.js +23 -700
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.cjs7.js +13 -37
- package/dist/index.cjs7.js.map +1 -1
- package/dist/index.cjs8.js +39 -17
- package/dist/index.cjs8.js.map +1 -1
- package/dist/index.cjs9.js +269 -16
- package/dist/index.cjs9.js.map +1 -1
- package/dist/index.es.js +187 -41
- package/dist/index.es.js.map +1 -1
- package/dist/index.es10.js +262 -173
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es5.js +91 -2
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +23 -695
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es7.js +14 -33
- package/dist/index.es7.js.map +1 -1
- package/dist/index.es8.js +37 -17
- package/dist/index.es8.js.map +1 -1
- package/dist/index.es9.js +264 -15
- package/dist/index.es9.js.map +1 -1
- package/dist/next.cjs.js +1 -3
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +2 -4
- package/dist/next.es.js.map +1 -1
- package/dist/react-page.cjs.js +97 -9
- package/dist/react-page.cjs.js.map +1 -1
- package/dist/react-page.es.js +95 -9
- package/dist/react-page.es.js.map +1 -1
- package/dist/react.cjs.js +1 -3
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.es.js +1 -3
- package/dist/react.es.js.map +1 -1
- package/dist/slate.cjs.js +260 -97
- package/dist/slate.cjs.js.map +1 -1
- package/dist/slate.es.js +249 -92
- package/dist/slate.es.js.map +1 -1
- package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +0 -17
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
- package/dist/types/src/controls/control.d.ts +3 -2
- package/dist/types/src/controls/control.d.ts.map +1 -1
- package/dist/types/src/controls/icon-radio-group.d.ts +5 -2
- package/dist/types/src/controls/icon-radio-group.d.ts.map +1 -1
- package/dist/types/src/controls/index.d.ts +1 -0
- package/dist/types/src/controls/index.d.ts.map +1 -1
- package/dist/types/src/controls/list.d.ts +2 -0
- package/dist/types/src/controls/list.d.ts.map +1 -1
- package/dist/types/src/controls/shape.d.ts +2 -0
- package/dist/types/src/controls/shape.d.ts.map +1 -1
- package/dist/types/src/controls/style-v2.d.ts.map +1 -1
- package/dist/types/src/controls/typography.d.ts +31 -0
- package/dist/types/src/controls/typography.d.ts.map +1 -0
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/descriptors.d.ts +6 -3
- package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/introspection.d.ts +1 -1
- package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/control.d.ts +3 -2
- package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/typography.d.ts +21 -0
- package/dist/types/src/runtimes/react/controls/typography.d.ts.map +1 -0
- package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts +5 -0
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/InlinePlugin/index.d.ts +16 -0
- package/dist/types/src/slate/InlinePlugin/index.d.ts.map +1 -0
- package/dist/types/src/slate/InlinePlugin/onChange.d.ts +4 -0
- package/dist/types/src/slate/InlinePlugin/onChange.d.ts.map +1 -0
- package/dist/types/src/slate/InlinePlugin/types.d.ts +9 -0
- package/dist/types/src/slate/InlinePlugin/types.d.ts.map +1 -0
- package/dist/types/src/slate/LinkPlugin/getValue.d.ts +5 -0
- package/dist/types/src/slate/LinkPlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/LinkPlugin/index.d.ts +15 -0
- package/dist/types/src/slate/LinkPlugin/index.d.ts.map +1 -0
- package/dist/types/src/slate/LinkPlugin/onChange.d.ts +4 -0
- package/dist/types/src/slate/LinkPlugin/onChange.d.ts.map +1 -0
- package/dist/types/src/slate/LinkPlugin/types.d.ts +5 -0
- package/dist/types/src/slate/LinkPlugin/types.d.ts.map +1 -0
- package/dist/types/src/slate/TextAlignPlugin/index.d.ts +2 -0
- package/dist/types/src/slate/TextAlignPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/index.d.ts +9 -0
- package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/index.d.ts +2 -0
- package/dist/types/src/slate/index.d.ts.map +1 -1
- package/dist/types.cjs2.js +753 -0
- package/dist/types.cjs2.js.map +1 -0
- package/dist/types.es2.js +736 -0
- package/dist/types.es2.js.map +1 -0
- package/dist/typography.cjs.js +56 -0
- package/dist/typography.cjs.js.map +1 -0
- package/dist/typography.es.js +41 -0
- package/dist/typography.es.js.map +1 -0
- package/package.json +1 -1
- package/dist/deepEqual.cjs.js +0 -40
- package/dist/deepEqual.cjs.js.map +0 -1
- package/dist/deepEqual.es.js +0 -39
- package/dist/deepEqual.es.js.map +0 -1
- package/dist/index.cjs11.js +0 -375
- package/dist/index.cjs11.js.map +0 -1
- package/dist/index.es11.js +0 -368
- package/dist/index.es11.js.map +0 -1
- package/dist/leaf.cjs.js +0 -182
- package/dist/leaf.cjs.js.map +0 -1
- package/dist/leaf.es.js +0 -179
- package/dist/leaf.es.js.map +0 -1
- package/dist/select.cjs.js +0 -21
- package/dist/select.cjs.js.map +0 -1
- package/dist/select.es.js +0 -16
- package/dist/select.es.js.map +0 -1
- package/dist/text-input.cjs.js +0 -26
- package/dist/text-input.cjs.js.map +0 -1
- package/dist/text-input.es.js +0 -18
- package/dist/text-input.es.js.map +0 -1
package/dist/index.es11.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
import { useCallback, useState, useEffect, forwardRef, useImperativeHandle, useMemo } from "react";
|
|
33
|
-
import { Range, createEditor } from "slate";
|
|
34
|
-
import { ReactEditor, withReact, Slate, Editable } from "slate-react";
|
|
35
|
-
import { cx } from "@emotion/css";
|
|
36
|
-
import { g as getBox } from "./box-models.es.js";
|
|
37
|
-
import { Z as useStyle, bb as BlockType, bc as InlineType, b2 as richTextDTOtoDAO, b1 as richTextDTOtoSelection, bk as BuilderEditMode } from "./react-page.es.js";
|
|
38
|
-
import "@emotion/serialize";
|
|
39
|
-
import "@emotion/utils";
|
|
40
|
-
import { L as Leaf } from "./leaf.es.js";
|
|
41
|
-
import { n as useResponsiveStyle, u as useIsInBuilder, O as useBuilderEditMode, Q as pollBoxModel } from "./index.es.js";
|
|
42
|
-
import "./state/breakpoints.es.js";
|
|
43
|
-
import { w as withBlock, o as onKeyDown } from "./index.es6.js";
|
|
44
|
-
import isHotkey from "is-hotkey";
|
|
45
|
-
import { jsx } from "react/jsx-runtime";
|
|
46
|
-
import { L as Link } from "./index.es3.js";
|
|
47
|
-
import { d as deepEqual } from "./deepEqual.es.js";
|
|
48
|
-
import { w as withTypography } from "./index.es5.js";
|
|
49
|
-
import { w as withBuilder } from "./index.es8.js";
|
|
50
|
-
import { u as useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.es.js";
|
|
51
|
-
import "css-box-model";
|
|
52
|
-
import "./actions.es.js";
|
|
53
|
-
import "redux";
|
|
54
|
-
import "redux-thunk";
|
|
55
|
-
import "use-sync-external-store/shim/with-selector";
|
|
56
|
-
import "next/dynamic";
|
|
57
|
-
import "./text-input.es.js";
|
|
58
|
-
import "./combobox.es.js";
|
|
59
|
-
import "./select.es.js";
|
|
60
|
-
import "use-sync-external-store/shim";
|
|
61
|
-
import "./types.es.js";
|
|
62
|
-
import "color";
|
|
63
|
-
import "scroll-into-view-if-needed";
|
|
64
|
-
import "react-dom";
|
|
65
|
-
import "html-react-parser";
|
|
66
|
-
import "next/head";
|
|
67
|
-
import "zod";
|
|
68
|
-
import "@emotion/server/create-instance";
|
|
69
|
-
import "next/document";
|
|
70
|
-
import "cors";
|
|
71
|
-
import "path-to-regexp";
|
|
72
|
-
import "cookie";
|
|
73
|
-
import "http-proxy";
|
|
74
|
-
import "set-cookie-parser";
|
|
75
|
-
import "./constants.es.js";
|
|
76
|
-
import "uuid";
|
|
77
|
-
import "corporate-ipsum";
|
|
78
|
-
import "next/link";
|
|
79
|
-
function BlockElement({
|
|
80
|
-
element,
|
|
81
|
-
attributes,
|
|
82
|
-
children
|
|
83
|
-
}) {
|
|
84
|
-
const blockStyles = [useStyle({
|
|
85
|
-
margin: 0
|
|
86
|
-
}), useStyle(useResponsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
|
|
87
|
-
textAlign
|
|
88
|
-
})))];
|
|
89
|
-
const quoteStyles = useStyle({
|
|
90
|
-
padding: "0.5em 10px",
|
|
91
|
-
fontSize: "1.25em",
|
|
92
|
-
fontWeight: "300",
|
|
93
|
-
borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
|
|
94
|
-
});
|
|
95
|
-
switch (element.type) {
|
|
96
|
-
case BlockType.Text:
|
|
97
|
-
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, attributes), {
|
|
98
|
-
className: cx(...blockStyles),
|
|
99
|
-
children
|
|
100
|
-
}));
|
|
101
|
-
case BlockType.Paragraph:
|
|
102
|
-
return /* @__PURE__ */ jsx("p", __spreadProps(__spreadValues({}, attributes), {
|
|
103
|
-
className: cx(...blockStyles),
|
|
104
|
-
children
|
|
105
|
-
}));
|
|
106
|
-
case BlockType.Heading1:
|
|
107
|
-
return /* @__PURE__ */ jsx("h1", __spreadProps(__spreadValues({}, attributes), {
|
|
108
|
-
className: cx(...blockStyles),
|
|
109
|
-
children
|
|
110
|
-
}));
|
|
111
|
-
case BlockType.Heading2:
|
|
112
|
-
return /* @__PURE__ */ jsx("h2", __spreadProps(__spreadValues({}, attributes), {
|
|
113
|
-
className: cx(...blockStyles),
|
|
114
|
-
children
|
|
115
|
-
}));
|
|
116
|
-
case BlockType.Heading3:
|
|
117
|
-
return /* @__PURE__ */ jsx("h3", __spreadProps(__spreadValues({}, attributes), {
|
|
118
|
-
className: cx(...blockStyles),
|
|
119
|
-
children
|
|
120
|
-
}));
|
|
121
|
-
case BlockType.Heading4:
|
|
122
|
-
return /* @__PURE__ */ jsx("h4", __spreadProps(__spreadValues({}, attributes), {
|
|
123
|
-
className: cx(...blockStyles),
|
|
124
|
-
children
|
|
125
|
-
}));
|
|
126
|
-
case BlockType.Heading5:
|
|
127
|
-
return /* @__PURE__ */ jsx("h5", __spreadProps(__spreadValues({}, attributes), {
|
|
128
|
-
className: cx(...blockStyles),
|
|
129
|
-
children
|
|
130
|
-
}));
|
|
131
|
-
case BlockType.Heading6:
|
|
132
|
-
return /* @__PURE__ */ jsx("h6", __spreadProps(__spreadValues({}, attributes), {
|
|
133
|
-
className: cx(...blockStyles),
|
|
134
|
-
children
|
|
135
|
-
}));
|
|
136
|
-
case BlockType.BlockQuote:
|
|
137
|
-
return /* @__PURE__ */ jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
|
|
138
|
-
className: cx(...blockStyles, quoteStyles),
|
|
139
|
-
children
|
|
140
|
-
}));
|
|
141
|
-
case BlockType.OrderedList:
|
|
142
|
-
return /* @__PURE__ */ jsx("ol", __spreadProps(__spreadValues({}, attributes), {
|
|
143
|
-
className: cx(...blockStyles),
|
|
144
|
-
style: {
|
|
145
|
-
listStylePosition: "inside"
|
|
146
|
-
},
|
|
147
|
-
children
|
|
148
|
-
}));
|
|
149
|
-
case BlockType.UnorderedList:
|
|
150
|
-
return /* @__PURE__ */ jsx("ul", __spreadProps(__spreadValues({}, attributes), {
|
|
151
|
-
className: cx(...blockStyles),
|
|
152
|
-
style: {
|
|
153
|
-
listStylePosition: "inside"
|
|
154
|
-
},
|
|
155
|
-
children
|
|
156
|
-
}));
|
|
157
|
-
case BlockType.ListItem:
|
|
158
|
-
return /* @__PURE__ */ jsx("li", __spreadProps(__spreadValues({}, attributes), {
|
|
159
|
-
className: cx(...blockStyles),
|
|
160
|
-
children
|
|
161
|
-
}));
|
|
162
|
-
case BlockType.ListItemChild:
|
|
163
|
-
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, attributes), {
|
|
164
|
-
className: cx(...blockStyles),
|
|
165
|
-
children
|
|
166
|
-
}));
|
|
167
|
-
default:
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function StyledLink(_a) {
|
|
172
|
-
var _b = _a, {
|
|
173
|
-
className
|
|
174
|
-
} = _b, restOfProps = __objRest(_b, [
|
|
175
|
-
"className"
|
|
176
|
-
]);
|
|
177
|
-
return /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({}, restOfProps), {
|
|
178
|
-
className: cx(useStyle({
|
|
179
|
-
textDecoration: "none"
|
|
180
|
-
}), className)
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
function InlineElement({
|
|
184
|
-
element,
|
|
185
|
-
attributes,
|
|
186
|
-
children
|
|
187
|
-
}) {
|
|
188
|
-
switch (element.type) {
|
|
189
|
-
case InlineType.Code:
|
|
190
|
-
return /* @__PURE__ */ jsx("code", __spreadProps(__spreadValues({}, attributes), {
|
|
191
|
-
children
|
|
192
|
-
}));
|
|
193
|
-
case InlineType.SuperScript:
|
|
194
|
-
return /* @__PURE__ */ jsx("sup", __spreadProps(__spreadValues({}, attributes), {
|
|
195
|
-
children
|
|
196
|
-
}));
|
|
197
|
-
case InlineType.SubScript:
|
|
198
|
-
return /* @__PURE__ */ jsx("sub", __spreadProps(__spreadValues({}, attributes), {
|
|
199
|
-
children
|
|
200
|
-
}));
|
|
201
|
-
case InlineType.Link:
|
|
202
|
-
return /* @__PURE__ */ jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
|
|
203
|
-
link: element.link,
|
|
204
|
-
children
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function Element(_c) {
|
|
209
|
-
var _d = _c, {
|
|
210
|
-
element
|
|
211
|
-
} = _d, props = __objRest(_d, [
|
|
212
|
-
"element"
|
|
213
|
-
]);
|
|
214
|
-
switch (element.type) {
|
|
215
|
-
case InlineType.Code:
|
|
216
|
-
case InlineType.SuperScript:
|
|
217
|
-
case InlineType.SubScript:
|
|
218
|
-
case InlineType.Link:
|
|
219
|
-
return /* @__PURE__ */ jsx(InlineElement, __spreadValues({
|
|
220
|
-
element
|
|
221
|
-
}, props));
|
|
222
|
-
case BlockType.Paragraph:
|
|
223
|
-
case BlockType.Heading1:
|
|
224
|
-
case BlockType.Heading2:
|
|
225
|
-
case BlockType.Heading3:
|
|
226
|
-
case BlockType.BlockQuote:
|
|
227
|
-
case BlockType.OrderedList:
|
|
228
|
-
case BlockType.UnorderedList:
|
|
229
|
-
case BlockType.ListItem:
|
|
230
|
-
case BlockType.ListItemChild:
|
|
231
|
-
return /* @__PURE__ */ jsx(BlockElement, __spreadValues({
|
|
232
|
-
element
|
|
233
|
-
}, props));
|
|
234
|
-
default:
|
|
235
|
-
return /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
236
|
-
children: props.children
|
|
237
|
-
}));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const COMMIT_DEBOUNCE_DELAY = 500;
|
|
241
|
-
function useSyncWithBuilder(editor, text) {
|
|
242
|
-
const [shouldCommit, setShouldCommit] = useState(true);
|
|
243
|
-
const isInBuilder = useIsInBuilder();
|
|
244
|
-
useEffect(() => {
|
|
245
|
-
if (shouldCommit && text && isInBuilder) {
|
|
246
|
-
const nextValue = richTextDTOtoDAO(text);
|
|
247
|
-
const nextSelection = richTextDTOtoSelection(text);
|
|
248
|
-
if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {
|
|
249
|
-
editor.children = nextValue;
|
|
250
|
-
editor.selection = nextSelection;
|
|
251
|
-
editor.onChange();
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}, [editor, shouldCommit, text]);
|
|
255
|
-
useEffect(() => {
|
|
256
|
-
if (shouldCommit)
|
|
257
|
-
return;
|
|
258
|
-
const timeoutId = window.setTimeout(() => {
|
|
259
|
-
setShouldCommit(true);
|
|
260
|
-
}, COMMIT_DEBOUNCE_DELAY);
|
|
261
|
-
return () => {
|
|
262
|
-
window.clearTimeout(timeoutId);
|
|
263
|
-
};
|
|
264
|
-
}, [shouldCommit]);
|
|
265
|
-
return useCallback(() => setShouldCommit(false), []);
|
|
266
|
-
}
|
|
267
|
-
function useSyncDOMSelection(editor, isEnabled) {
|
|
268
|
-
useIsomorphicLayoutEffect(() => {
|
|
269
|
-
if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor))
|
|
270
|
-
return;
|
|
271
|
-
try {
|
|
272
|
-
const root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
273
|
-
const domSelection = root.getSelection();
|
|
274
|
-
const newDomRange = ReactEditor.toDOMRange(editor, editor.selection);
|
|
275
|
-
if (newDomRange) {
|
|
276
|
-
if (Range.isBackward(editor.selection)) {
|
|
277
|
-
domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.endContainer, newDomRange.endOffset, newDomRange.startContainer, newDomRange.startOffset);
|
|
278
|
-
} else {
|
|
279
|
-
domSelection == null ? void 0 : domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
domSelection == null ? void 0 : domSelection.removeAllRanges();
|
|
283
|
-
}
|
|
284
|
-
} catch (e) {
|
|
285
|
-
console.error(e);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
const defaultText = [{
|
|
290
|
-
type: BlockType.Paragraph,
|
|
291
|
-
children: [{
|
|
292
|
-
text: ""
|
|
293
|
-
}]
|
|
294
|
-
}];
|
|
295
|
-
const EditableText = forwardRef(function EditableText2({
|
|
296
|
-
id,
|
|
297
|
-
text,
|
|
298
|
-
width,
|
|
299
|
-
margin
|
|
300
|
-
}, ref) {
|
|
301
|
-
const [editor] = useState(() => withBlock(withTypography(withBuilder(withReact(createEditor())))));
|
|
302
|
-
const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false);
|
|
303
|
-
useSyncDOMSelection(editor, isPreservingDOMSElection);
|
|
304
|
-
const delaySync = useSyncWithBuilder(editor, text);
|
|
305
|
-
const editMode = useBuilderEditMode();
|
|
306
|
-
const [propControllers, setPropControllers] = useState(null);
|
|
307
|
-
const controller = propControllers == null ? void 0 : propControllers.text;
|
|
308
|
-
useEffect(() => {
|
|
309
|
-
if (controller == null)
|
|
310
|
-
return;
|
|
311
|
-
const element = ReactEditor.toDOMNode(editor, editor);
|
|
312
|
-
return pollBoxModel({
|
|
313
|
-
element,
|
|
314
|
-
onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
|
|
315
|
-
});
|
|
316
|
-
}, [editor, controller]);
|
|
317
|
-
useImperativeHandle(ref, () => ({
|
|
318
|
-
getDomNode() {
|
|
319
|
-
return ReactEditor.toDOMNode(editor, editor);
|
|
320
|
-
},
|
|
321
|
-
getBoxModel() {
|
|
322
|
-
return getBox(ReactEditor.toDOMNode(editor, editor));
|
|
323
|
-
},
|
|
324
|
-
setPropControllers
|
|
325
|
-
}), [editor, setPropControllers]);
|
|
326
|
-
const initialValue = useMemo(() => text ? richTextDTOtoDAO(text) : defaultText, [text]);
|
|
327
|
-
useEffect(() => {
|
|
328
|
-
controller == null ? void 0 : controller.setSlateEditor(editor);
|
|
329
|
-
}, [controller, editor]);
|
|
330
|
-
const handleFocus = useCallback(() => {
|
|
331
|
-
controller == null ? void 0 : controller.focus();
|
|
332
|
-
setIsPreservingDOMSelection(true);
|
|
333
|
-
}, [controller]);
|
|
334
|
-
const handleKeyDown = useCallback((e) => {
|
|
335
|
-
if (isHotkey("mod+shift+z", e))
|
|
336
|
-
return controller == null ? void 0 : controller.redo();
|
|
337
|
-
if (isHotkey("mod+z", e))
|
|
338
|
-
return controller == null ? void 0 : controller.undo();
|
|
339
|
-
if (isHotkey("escape")(e))
|
|
340
|
-
return controller == null ? void 0 : controller.blur();
|
|
341
|
-
onKeyDown(e, editor);
|
|
342
|
-
}, [controller, editor]);
|
|
343
|
-
const handleBlur = useCallback((e) => {
|
|
344
|
-
if (e.relatedTarget == null)
|
|
345
|
-
return;
|
|
346
|
-
setIsPreservingDOMSelection(false);
|
|
347
|
-
ReactEditor.deselect(editor);
|
|
348
|
-
}, []);
|
|
349
|
-
return /* @__PURE__ */ jsx(Slate, {
|
|
350
|
-
editor,
|
|
351
|
-
value: initialValue,
|
|
352
|
-
onChange: delaySync,
|
|
353
|
-
children: /* @__PURE__ */ jsx(Editable, {
|
|
354
|
-
id,
|
|
355
|
-
renderLeaf: Leaf,
|
|
356
|
-
renderElement: Element,
|
|
357
|
-
onFocus: handleFocus,
|
|
358
|
-
onKeyDown: handleKeyDown,
|
|
359
|
-
onBlur: handleBlur,
|
|
360
|
-
className: cx(width, margin),
|
|
361
|
-
readOnly: editMode !== BuilderEditMode.CONTENT,
|
|
362
|
-
placeholder: "Write some text..."
|
|
363
|
-
})
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
var EditableText$1 = EditableText;
|
|
367
|
-
export { EditableText, EditableText$1 as default };
|
|
368
|
-
//# sourceMappingURL=index.es11.js.map
|
package/dist/index.es11.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.es11.js","sources":["../src/components/builtin/Text/components/Element/block.tsx","../src/components/builtin/Text/components/Element/inline.tsx","../src/components/builtin/Text/components/Element/element.tsx","../src/components/builtin/Text/EditableText/useSyncWithBuilder.tsx","../src/components/builtin/Text/EditableText/useSyncDOMSelection.tsx","../src/components/builtin/Text/EditableText/editable-text.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\nimport { Block, BlockType } from '../../../../../slate'\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Block\n}\n\nexport function BlockElement({ element, attributes, children }: InlineRenderElementProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([element.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n const quoteStyles = useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n })\n\n switch (element.type) {\n case BlockType.Text:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n case BlockType.Paragraph:\n return (\n <p {...attributes} className={cx(...blockStyles)}>\n {children}\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 {...attributes} className={cx(...blockStyles)}>\n {children}\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote {...attributes} className={cx(...blockStyles, quoteStyles)}>\n {children}\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul {...attributes} className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n {children}\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li {...attributes} className={cx(...blockStyles)}>\n {children}\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span {...attributes} className={cx(...blockStyles)}>\n {children}\n </span>\n )\n\n default:\n return null\n }\n}\n","import { cx } from '@emotion/css'\nimport { ComponentPropsWithoutRef } from 'react'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { Link } from '../../../../shared/Link'\nimport { Inline, InlineType } from '../../../../../slate'\n\nfunction StyledLink({ className, ...restOfProps }: ComponentPropsWithoutRef<typeof Link>) {\n return <Link {...restOfProps} className={cx(useStyle({ textDecoration: 'none' }), className)} />\n}\n\nexport interface InlineRenderElementProps extends RenderElementProps {\n element: Inline\n}\n\nexport function InlineElement({ element, attributes, children }: InlineRenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n case InlineType.Link:\n return (\n <StyledLink {...attributes} link={element.link}>\n {children}\n </StyledLink>\n )\n }\n}\n","import { RenderElementProps } from 'slate-react'\nimport { BlockElement } from './block'\nimport { InlineElement } from './inline'\nimport { InlineType, BlockType } from '../../../../../slate'\n\nexport function Element({ element, ...props }: RenderElementProps) {\n switch (element.type) {\n case InlineType.Code:\n case InlineType.SuperScript:\n case InlineType.SubScript:\n case InlineType.Link:\n return <InlineElement element={element} {...props} />\n case BlockType.Paragraph:\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement element={element} {...props} />\n default:\n return <span {...props.attributes}>{props.children}</span>\n }\n}\n","import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { richTextDTOtoDAO, richTextDTOtoSelection } from '../../../../controls'\nimport { RichTextValue } from '../../../../prop-controllers'\nimport deepEqual from '../../../../utils/deepEqual'\nimport { useIsInBuilder } from '../../../../runtimes/react'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextValue) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n","import { ReactEditor } from 'slate-react'\nimport { useIsomorphicLayoutEffect } from '../../../hooks/useIsomorphicLayoutEffect'\nimport { Editor, Range as SlateRange } from 'slate'\n\n/**\n * Clicking outside of the host blurs our `<Editable />`.\n * `<Editable />` only updates the DOM's selection to match slate when it is focused.\n * In the case of a panel being clicked this hook updates the DOM selection to match slate.\n */\nexport function useSyncDOMSelection(editor: Editor, isEnabled: boolean) {\n useIsomorphicLayoutEffect(() => {\n if (!isEnabled || editor.selection == null || ReactEditor.isFocused(editor)) return\n try {\n const root = ReactEditor.findDocumentOrShadowRoot(editor) as Document\n const domSelection = root.getSelection()\n const newDomRange: Range | null = ReactEditor.toDOMRange(editor, editor.selection)\n\n if (newDomRange) {\n if (SlateRange.isBackward(editor.selection!)) {\n domSelection?.setBaseAndExtent(\n newDomRange.endContainer,\n newDomRange.endOffset,\n newDomRange.startContainer,\n newDomRange.startOffset,\n )\n } else {\n domSelection?.setBaseAndExtent(\n newDomRange.startContainer,\n newDomRange.startOffset,\n newDomRange.endContainer,\n newDomRange.endOffset,\n )\n }\n } else {\n domSelection?.removeAllRanges()\n }\n } catch (e) {\n console.error(e)\n }\n })\n}\n","import {\n FocusEvent,\n forwardRef,\n KeyboardEvent,\n Ref,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react'\n\nimport { createEditor } from 'slate'\nimport { Slate, Editable, withReact, ReactEditor } from 'slate-react'\n\nimport { ElementIDValue, RichTextValue } from '../../../../prop-controllers/descriptors'\nimport { cx } from '@emotion/css'\nimport { DescriptorsPropControllers } from '../../../../prop-controllers/instances'\nimport { Descriptors } from '../../../../runtimes/react/controls/rich-text'\nimport { getBox } from '../../../../box-model'\nimport { PropControllersHandle } from '../../../../state/modules/prop-controller-handles'\nimport { richTextDTOtoDAO } from '../../../../controls'\nimport { Leaf } from '../components/Leaf'\nimport { Element } from '../components/Element'\nimport { useSyncWithBuilder } from './useSyncWithBuilder'\nimport isHotkey from 'is-hotkey'\nimport { useBuilderEditMode } from '../../../../runtimes/react'\nimport { BuilderEditMode } from '../../../../state/modules/builder-edit-mode'\nimport { onKeyDown, withBlock, withTypography, withBuilder } from '../../../../slate'\nimport { pollBoxModel } from '../../../../runtimes/react/poll-box-model'\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextDAO, BlockType } from '../../../../slate'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst defaultText: RichTextDAO = [{ type: BlockType.Paragraph, children: [{ text: '' }] }]\n\nexport const EditableText = forwardRef(function EditableText(\n { id, text, width, margin }: Props,\n ref: Ref<PropControllersHandle<Descriptors>>,\n) {\n const [editor] = useState(() => withBlock(withTypography(withBuilder(withReact(createEditor())))))\n const [isPreservingDOMSElection, setIsPreservingDOMSelection] = useState(false)\n useSyncDOMSelection(editor, isPreservingDOMSElection)\n const delaySync = useSyncWithBuilder(editor, text)\n const editMode = useBuilderEditMode()\n\n const [propControllers, setPropControllers] =\n useState<DescriptorsPropControllers<Descriptors> | null>(null)\n const controller = propControllers?.text\n\n useEffect(() => {\n if (controller == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => controller.changeBoxModel(boxModel),\n })\n }, [editor, controller])\n\n useImperativeHandle(\n ref,\n () => ({\n getDomNode() {\n return ReactEditor.toDOMNode(editor, editor)\n },\n getBoxModel() {\n return getBox(ReactEditor.toDOMNode(editor, editor))\n },\n setPropControllers,\n }),\n [editor, setPropControllers],\n )\n\n const initialValue = useMemo(() => (text ? richTextDTOtoDAO(text) : defaultText), [text])\n\n useEffect(() => {\n controller?.setSlateEditor(editor)\n }, [controller, editor])\n\n const handleFocus = useCallback(() => {\n controller?.focus()\n setIsPreservingDOMSelection(true)\n }, [controller])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return controller?.redo()\n if (isHotkey('mod+z', e)) return controller?.undo()\n if (isHotkey('escape')(e)) return controller?.blur()\n onKeyDown(e, editor)\n },\n [controller, editor],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // When clicking outside of the iframe (`relatedTarget` is null) we want to preserve the DOM selection.\n if (e.relatedTarget == null) return\n // Otherwise we want to deselect on blur and stop preserving selection.\n setIsPreservingDOMSelection(false)\n ReactEditor.deselect(editor)\n }, [])\n\n return (\n <Slate editor={editor} value={initialValue} onChange={delaySync}>\n <Editable\n id={id}\n renderLeaf={Leaf}\n renderElement={Element}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n className={cx(width, margin)}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n})\n\nexport default EditableText\n"],"names":["element","attributes","children","blockStyles","useStyle","margin","useResponsiveStyle","textAlign","quoteStyles","padding","fontSize","fontWeight","borderLeft","type","BlockType","Text","cx","Paragraph","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","className","restOfProps","textDecoration","InlineType","Code","SuperScript","SubScript","Link","link","props","COMMIT_DEBOUNCE_DELAY","editor","text","shouldCommit","setShouldCommit","useState","isInBuilder","useIsInBuilder","useEffect","nextValue","richTextDTOtoDAO","nextSelection","richTextDTOtoSelection","deepEqual","selection","onChange","timeoutId","window","setTimeout","clearTimeout","useCallback","isEnabled","useIsomorphicLayoutEffect","ReactEditor","isFocused","root","findDocumentOrShadowRoot","domSelection","getSelection","newDomRange","toDOMRange","SlateRange","isBackward","setBaseAndExtent","endContainer","endOffset","startContainer","startOffset","removeAllRanges","e","console","error","defaultText","EditableText","forwardRef","id","width","ref","withBlock","withTypography","withBuilder","withReact","createEditor","isPreservingDOMSElection","setIsPreservingDOMSelection","useSyncDOMSelection","delaySync","useSyncWithBuilder","editMode","useBuilderEditMode","propControllers","setPropControllers","controller","toDOMNode","pollBoxModel","onBoxModelChange","boxModel","changeBoxModel","useImperativeHandle","getDomNode","getBoxModel","getBox","initialValue","useMemo","setSlateEditor","handleFocus","focus","handleKeyDown","isHotkey","redo","undo","blur","onKeyDown","handleBlur","relatedTarget","deselect","Leaf","Element","BuilderEditMode","CONTENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU6B,sBAAA;AAAA,EAAEA;AAAAA,EAASC;AAAAA,EAAYC;AAAAA,GAAsC;AAClFC,QAAAA,cAAc,CAClBC,SAAS;AAAA,IAAEC,QAAQ;AAAA,EAAA,CAAX,GACRD,SAASE,mBAAmB,CAACN,QAAQO,SAAT,GAAqB,CAAC,CAACA,YAAY,YAAa;AAAA,IAAEA;AAAAA,EAAAA,EAAnD,CAAnB,CAFU;AAKdC,QAAAA,cAAcJ,SAAS;AAAA,IAC3BK,SAAS;AAAA,IACTC,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,CAJc;AAOpBZ,UAAAA,QAAQa;AAAAA,SACTC,UAAUC;AACb,0EACYd;QAAY,WAAWe,GAAG,GAAGb,WAAJ;AAAA,QAChCD;AAAAA,MAAAA,EAFL;AAAA,SAKGY,UAAUG;AACb,uEACShB;QAAY,WAAWe,GAAG,GAAGb,WAAJ;AAAA,QAC7BD;AAAAA,MAAAA,EAFL;AAAA,SAKGY,UAAUI;AACb,wEACUjB;QAAY,WAAWe,GAAG,GAAGb,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAAA,SAKGY,UAAUK;AACb,wEACUlB;QAAY,WAAWe,GAAG,GAAGb,WAAJ;AAAA,QAC9BD;AAAAA,MAAAA,EAFL;AAA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|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
|
-
var next = require("./index.cjs.js");
|
|
34
|
-
var reactPage = require("./react-page.cjs.js");
|
|
35
|
-
var state_breakpoints = require("./state/breakpoints.cjs.js");
|
|
36
|
-
var jsxRuntime = require("react/jsx-runtime");
|
|
37
|
-
function typographyFragementToRichTextTypography(typography) {
|
|
38
|
-
if (typography == null)
|
|
39
|
-
return void 0;
|
|
40
|
-
return {
|
|
41
|
-
id: typography.id,
|
|
42
|
-
style: typography.style.map(({
|
|
43
|
-
deviceId,
|
|
44
|
-
value
|
|
45
|
-
}) => {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
47
|
-
return {
|
|
48
|
-
deviceId,
|
|
49
|
-
value: {
|
|
50
|
-
fontFamily: (_a = value.fontFamily) != null ? _a : void 0,
|
|
51
|
-
lineHeight: (_b = value.lineHeight) != null ? _b : void 0,
|
|
52
|
-
letterSpacing: (_c = value.letterSpacing) != null ? _c : void 0,
|
|
53
|
-
fontWeight: (_d = value.fontWeight) != null ? _d : void 0,
|
|
54
|
-
textAlign: (_e = value.textAlign) != null ? _e : void 0,
|
|
55
|
-
uppercase: (_f = value.uppercase) != null ? _f : void 0,
|
|
56
|
-
underline: (_g = value.underline) != null ? _g : void 0,
|
|
57
|
-
strikethrough: (_h = value.strikethrough) != null ? _h : void 0,
|
|
58
|
-
italic: (_i = value.italic) != null ? _i : void 0,
|
|
59
|
-
fontSize: (_j = value.fontSize) != null ? _j : void 0,
|
|
60
|
-
color: (_k = value.color) != null ? _k : void 0
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
})
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function getTypographyStyleSwatchIds(style) {
|
|
67
|
-
var _a;
|
|
68
|
-
return (_a = style == null ? void 0 : style.map((override) => override.value).flatMap((typographyStyle) => {
|
|
69
|
-
var _a2;
|
|
70
|
-
return (_a2 = typographyStyle.color) == null ? void 0 : _a2.swatchId;
|
|
71
|
-
}).filter(reactPage.isNonNullable)) != null ? _a : [];
|
|
72
|
-
}
|
|
73
|
-
const withColor = (swatches) => (deviceRawTypographyValue) => {
|
|
74
|
-
var _b, _c;
|
|
75
|
-
const {
|
|
76
|
-
value,
|
|
77
|
-
deviceId
|
|
78
|
-
} = deviceRawTypographyValue;
|
|
79
|
-
if (value.color == null) {
|
|
80
|
-
const _a = value, {
|
|
81
|
-
color
|
|
82
|
-
} = _a, nextValue = __objRest(_a, [
|
|
83
|
-
"color"
|
|
84
|
-
]);
|
|
85
|
-
return {
|
|
86
|
-
deviceId,
|
|
87
|
-
value: nextValue
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
deviceId,
|
|
92
|
-
value: __spreadProps(__spreadValues({}, value), {
|
|
93
|
-
color: {
|
|
94
|
-
swatch: swatches.find((s) => {
|
|
95
|
-
var _a2;
|
|
96
|
-
return s && s.id === ((_a2 = value.color) == null ? void 0 : _a2.swatchId);
|
|
97
|
-
}),
|
|
98
|
-
alpha: (_c = (_b = value.color) == null ? void 0 : _b.alpha) != null ? _c : void 0
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
const getDeviceId = ({
|
|
104
|
-
deviceId
|
|
105
|
-
}) => deviceId;
|
|
106
|
-
function useEnhancedTypography(value) {
|
|
107
|
-
var _a, _b, _c;
|
|
108
|
-
const typography = typographyFragementToRichTextTypography(next.useTypography((_a = value == null ? void 0 : value.id) != null ? _a : null));
|
|
109
|
-
const source = (_b = typography == null ? void 0 : typography.style) != null ? _b : [];
|
|
110
|
-
const override = (_c = value == null ? void 0 : value.style) != null ? _c : [];
|
|
111
|
-
const breakpoints = next.useBreakpoints();
|
|
112
|
-
const swatchIds = [...getTypographyStyleSwatchIds(value == null ? void 0 : value.style), ...getTypographyStyleSwatchIds(typography == null ? void 0 : typography.style)];
|
|
113
|
-
const swatches = next.useSwatches(swatchIds).filter(reactPage.isNonNullable);
|
|
114
|
-
const enhancedSource = source.map(withColor(swatches));
|
|
115
|
-
const enhancedOverride = override.map(withColor(swatches));
|
|
116
|
-
const devices = [...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId)))];
|
|
117
|
-
return devices.map((deviceId) => {
|
|
118
|
-
var _a2, _b2;
|
|
119
|
-
const deviceSource = (_a2 = state_breakpoints.findBreakpointOverride(breakpoints, enhancedSource, deviceId)) == null ? void 0 : _a2.value;
|
|
120
|
-
const deviceOverride = (_b2 = state_breakpoints.findBreakpointOverride(breakpoints, enhancedOverride, deviceId)) == null ? void 0 : _b2.value;
|
|
121
|
-
if (deviceSource && deviceOverride) {
|
|
122
|
-
return {
|
|
123
|
-
deviceId,
|
|
124
|
-
value: __spreadValues(__spreadValues({}, deviceSource), deviceOverride)
|
|
125
|
-
};
|
|
126
|
-
} else if (deviceOverride) {
|
|
127
|
-
return {
|
|
128
|
-
deviceId,
|
|
129
|
-
value: deviceOverride
|
|
130
|
-
};
|
|
131
|
-
} else if (deviceSource) {
|
|
132
|
-
return {
|
|
133
|
-
deviceId,
|
|
134
|
-
value: deviceSource
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
}).filter(reactPage.isNonNullable);
|
|
139
|
-
}
|
|
140
|
-
function useTypographyClassName(value) {
|
|
141
|
-
return reactPage.useStyle(next.useResponsiveStyle([value], ([value2]) => {
|
|
142
|
-
if (value2 === void 0)
|
|
143
|
-
return {};
|
|
144
|
-
let styles = {};
|
|
145
|
-
if (value2.color != null)
|
|
146
|
-
styles.color = next.colorToString(value2.color);
|
|
147
|
-
if (value2.fontFamily != null)
|
|
148
|
-
styles.fontFamily = value2.fontFamily;
|
|
149
|
-
if (value2.fontSize != null && value2.fontSize.value != null && value2.fontSize.unit != null)
|
|
150
|
-
styles.fontSize = `${value2.fontSize.value}${value2.fontSize.unit}`;
|
|
151
|
-
if (value2.fontWeight != null)
|
|
152
|
-
styles.fontWeight = value2.fontWeight;
|
|
153
|
-
if (value2.lineHeight != null)
|
|
154
|
-
styles.lineHeight = value2.lineHeight;
|
|
155
|
-
if (value2.letterSpacing != null)
|
|
156
|
-
styles.letterSpacing = `${value2.letterSpacing / 10}em`;
|
|
157
|
-
if (value2.uppercase != null)
|
|
158
|
-
styles.textTransform = value2.uppercase === true ? "uppercase" : "initial";
|
|
159
|
-
if (value2.underline != null || value2.strikethrough != null)
|
|
160
|
-
styles.textDecoration = [Boolean(value2.underline) && "underline", Boolean(value2.strikethrough) && "line-through"].filter(Boolean).join(" ");
|
|
161
|
-
if (value2.italic != null)
|
|
162
|
-
styles.fontStyle = value2.italic === true ? "italic" : "initial";
|
|
163
|
-
return styles;
|
|
164
|
-
}, state_breakpoints.shallowMergeFallbacks));
|
|
165
|
-
}
|
|
166
|
-
function Leaf(_a) {
|
|
167
|
-
var _b = _a, {
|
|
168
|
-
leaf
|
|
169
|
-
} = _b, props = __objRest(_b, [
|
|
170
|
-
"leaf"
|
|
171
|
-
]);
|
|
172
|
-
const enhancedTypography = useEnhancedTypography(leaf.typography);
|
|
173
|
-
const typographyClassName = useTypographyClassName(enhancedTypography);
|
|
174
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
175
|
-
className: typographyClassName,
|
|
176
|
-
children: props.children
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
exports.Leaf = Leaf;
|
|
180
|
-
exports.useEnhancedTypography = useEnhancedTypography;
|
|
181
|
-
exports.useTypographyClassName = useTypographyClassName;
|
|
182
|
-
//# sourceMappingURL=leaf.cjs.js.map
|
package/dist/leaf.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"leaf.cjs.js","sources":["../src/components/builtin/Text/components/Leaf/leaf.tsx"],"sourcesContent":["import { RenderLeafProps } from 'slate-react'\nimport { CSSObject } from '@emotion/serialize'\nimport { Swatch, Typography } from '../../../../../api'\nimport { DeviceOverride, ResponsiveValue } from '../../../../../prop-controllers'\nimport { useTypography, useSwatches } from '../../../../../runtimes/react/hooks/makeswift-api'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { isNonNullable } from '../../../../utils/isNonNullable'\nimport { useResponsiveStyle } from '../../../../utils/responsive-style'\nimport { ColorValue } from '../../../../utils/types'\nimport {\n findBreakpointOverride,\n shallowMergeFallbacks,\n} from '../../../../../state/modules/breakpoints'\nimport { useBreakpoints } from '../../../../../runtimes/react'\nimport { RichTextTypography } from '../../../../../slate'\n\nexport type RichTextTypographyValue = RichTextTypography['style'][number]['value']\n\nfunction typographyFragementToRichTextTypography(\n typography: Typography | null,\n): RichTextTypography | undefined {\n if (typography == null) return undefined\n return {\n id: typography.id,\n style: typography.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\ntype EnhancedTypographyValue = Omit<RichTextTypographyValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function getTypographyStyleSwatchIds(\n style: RichTextTypography['style'] | Typography['style'] | null | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<RichTextTypographyValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(value?: RichTextTypography): EnhancedTypography {\n const typography = typographyFragementToRichTextTypography(useTypography(value?.id ?? null))\n const source = typography?.style ?? []\n const override = value?.style ?? []\n const breakpoints = useBreakpoints()\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(value?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findBreakpointOverride(breakpoints, enhancedSource, deviceId)?.value\n const deviceOverride = findBreakpointOverride(breakpoints, enhancedOverride, deviceId)?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n return useStyle(\n useResponsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n [value],\n ([value]) => {\n if (value === undefined) return {}\n\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n },\n shallowMergeFallbacks,\n ),\n )\n}\n\nexport function Leaf({ leaf, ...props }: RenderLeafProps) {\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span {...props.attributes} className={typographyClassName}>\n {props.children}\n </span>\n )\n}\n"],"names":["typography","undefined","id","style","map","deviceId","value","fontFamily","lineHeight","letterSpacing","fontWeight","textAlign","uppercase","underline","strikethrough","italic","fontSize","color","override","flatMap","typographyStyle","swatchId","filter","isNonNullable","withColor","swatches","deviceRawTypographyValue","nextValue","swatch","find","s","alpha","getDeviceId","typographyFragementToRichTextTypography","useTypography","source","breakpoints","useBreakpoints","swatchIds","getTypographyStyleSwatchIds","useSwatches","enhancedSource","enhancedOverride","devices","Set","concat","deviceSource","findBreakpointOverride","deviceOverride","useStyle","useResponsiveStyle","styles","colorToString","unit","textTransform","textDecoration","Boolean","join","fontStyle","shallowMergeFallbacks","leaf","props","enhancedTypography","useEnhancedTypography","typographyClassName","useTypographyClassName","attributes","children"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,iDACEA,YACgC;AAChC,MAAIA,cAAc;AAAaC,WAAAA;AACxB,SAAA;AAAA,IACLC,IAAIF,WAAWE;AAAAA,IACfC,OAAOH,WAAWG,MAAMC,IAAI,CAAC;AAAA,MAAEC;AAAAA,MAAUC;AAAAA,UAAa;;AAAA;AAAA,QACpDD;AAAAA,QACAC,OAAO;AAAA,UACLC,YAAYD,YAAMC,eAAND,YAAoBL;AAAAA,UAChCO,YAAYF,YAAME,eAANF,YAAoBL;AAAAA,UAChCQ,eAAeH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