@makeswift/runtime 0.21.3 → 0.22.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/cjs/api/react.js +45 -0
- package/dist/cjs/api/react.js.map +1 -1
- package/dist/cjs/components/shared/Link/index.js +14 -69
- package/dist/cjs/components/shared/Link/index.js.map +1 -1
- package/dist/cjs/components/utils/responsive-style.js +2 -1
- package/dist/cjs/components/utils/responsive-style.js.map +1 -1
- package/dist/cjs/controls/link.js +46 -2
- package/dist/cjs/controls/link.js.map +1 -1
- package/dist/cjs/controls/rich-text/rich-text.js +12 -0
- package/dist/cjs/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +12 -0
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/controls/slot.js +12 -0
- package/dist/cjs/controls/slot.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js +203 -0
- package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
- package/dist/cjs/runtimes/react/components/ElementData.js +1 -1
- package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/control.js +11 -156
- package/dist/cjs/runtimes/react/controls/control.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +9 -3
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +2 -2
- package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js +12 -9
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/slot.js +5 -4
- package/dist/cjs/runtimes/react/controls/slot.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/style.js +6 -47
- package/dist/cjs/runtimes/react/controls/style.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/typography.js +49 -51
- package/dist/cjs/runtimes/react/controls/typography.js.map +1 -1
- package/dist/cjs/runtimes/react/controls.js +15 -111
- package/dist/cjs/runtimes/react/controls.js.map +1 -1
- package/dist/cjs/{utils/coalesce.js → runtimes/react/hooks/use-css-id.js} +13 -14
- package/dist/cjs/runtimes/react/hooks/use-css-id.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +85 -0
- package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resolved-value.js +9 -2
- package/dist/cjs/runtimes/react/hooks/use-resolved-value.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +68 -0
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +115 -0
- package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
- package/dist/cjs/runtimes/react/resolvable-record.js +67 -0
- package/dist/cjs/runtimes/react/resolvable-record.js.map +1 -0
- package/dist/cjs/runtimes/react/use-style.js +20 -4
- package/dist/cjs/runtimes/react/use-style.js.map +1 -1
- package/dist/cjs/slate/TypographyPlugin/index.js +2 -1
- package/dist/cjs/slate/TypographyPlugin/index.js.map +1 -1
- package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js +2 -12
- package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
- package/dist/cjs/slate/index.js.map +1 -1
- package/dist/cjs/state/modules/breakpoints.js +7 -87
- package/dist/cjs/state/modules/breakpoints.js.map +1 -1
- package/dist/esm/api/react.js +45 -0
- package/dist/esm/api/react.js.map +1 -1
- package/dist/esm/components/shared/Link/index.js +14 -69
- package/dist/esm/components/shared/Link/index.js.map +1 -1
- package/dist/esm/components/utils/responsive-style.js +2 -3
- package/dist/esm/components/utils/responsive-style.js.map +1 -1
- package/dist/esm/controls/link.js +37 -2
- package/dist/esm/controls/link.js.map +1 -1
- package/dist/esm/controls/rich-text/rich-text.js +16 -1
- package/dist/esm/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js +14 -1
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/controls/slot.js +14 -1
- package/dist/esm/controls/slot.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js +179 -0
- package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
- package/dist/esm/runtimes/react/components/ElementData.js +2 -2
- package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/esm/runtimes/react/controls/control.js +11 -175
- package/dist/esm/runtimes/react/controls/control.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
- package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +8 -2
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +14 -9
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/runtimes/react/controls/slot.js +4 -3
- package/dist/esm/runtimes/react/controls/slot.js.map +1 -1
- package/dist/esm/runtimes/react/controls/style.js +6 -37
- package/dist/esm/runtimes/react/controls/style.js.map +1 -1
- package/dist/esm/runtimes/react/controls/typography.js +49 -48
- package/dist/esm/runtimes/react/controls/typography.js.map +1 -1
- package/dist/esm/runtimes/react/controls.js +14 -129
- package/dist/esm/runtimes/react/controls.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-css-id.js +8 -0
- package/dist/esm/runtimes/react/hooks/use-css-id.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js +53 -0
- package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resolved-value.js +9 -2
- package/dist/esm/runtimes/react/hooks/use-resolved-value.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +34 -0
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +94 -0
- package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
- package/dist/esm/runtimes/react/resolvable-record.js +43 -0
- package/dist/esm/runtimes/react/resolvable-record.js.map +1 -0
- package/dist/esm/runtimes/react/use-style.js +17 -3
- package/dist/esm/runtimes/react/use-style.js.map +1 -1
- package/dist/esm/slate/TypographyPlugin/index.js +2 -1
- package/dist/esm/slate/TypographyPlugin/index.js.map +1 -1
- package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js +1 -1
- package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
- package/dist/esm/slate/index.js.map +1 -1
- package/dist/esm/state/modules/breakpoints.js +9 -70
- package/dist/esm/state/modules/breakpoints.js.map +1 -1
- package/dist/types/api/react.d.ts +11 -1
- package/dist/types/api/react.d.ts.map +1 -1
- package/dist/types/components/builtin/Button/Button.d.ts +2 -2
- package/dist/types/components/shared/Link/index.d.ts.map +1 -1
- package/dist/types/components/utils/responsive-style.d.ts +1 -1
- package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
- package/dist/types/controls/link.d.ts +16 -2
- package/dist/types/controls/link.d.ts.map +1 -1
- package/dist/types/controls/rich-text/rich-text.d.ts +2 -1
- package/dist/types/controls/rich-text/rich-text.d.ts.map +1 -1
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +2 -1
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/controls/slot.d.ts +2 -1
- package/dist/types/controls/slot.d.ts.map +1 -1
- package/dist/types/locale.d.ts +1 -1
- package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts +40 -0
- package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +2 -0
- package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/control.d.ts +1 -1
- package/dist/types/runtimes/react/controls/control.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts +1 -1
- package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +3 -3
- package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/slot.d.ts +4 -1
- package/dist/types/runtimes/react/controls/slot.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/style.d.ts +4 -3
- package/dist/types/runtimes/react/controls/style.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/typography.d.ts +5 -6
- package/dist/types/runtimes/react/controls/typography.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls.d.ts +1 -1
- package/dist/types/runtimes/react/controls.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-css-id.d.ts +2 -0
- package/dist/types/runtimes/react/hooks/use-css-id.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts +2 -2
- package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts +7 -0
- package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -0
- package/dist/types/runtimes/react/resolvable-record.d.ts +3 -0
- package/dist/types/runtimes/react/resolvable-record.d.ts.map +1 -0
- package/dist/types/runtimes/react/use-style.d.ts +4 -0
- package/dist/types/runtimes/react/use-style.d.ts.map +1 -1
- package/dist/types/slate/BlockPlugin/index.d.ts +5 -5
- package/dist/types/slate/LinkPlugin/getValue.d.ts +1 -1
- package/dist/types/slate/LinkPlugin/index.d.ts +1 -1
- package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/slate/TypographyPlugin/normalizeTypographyDown.d.ts.map +1 -1
- package/dist/types/slate/index.d.ts +1 -0
- package/dist/types/slate/index.d.ts.map +1 -1
- package/dist/types/slate/test-helpers/slate-test-helper.d.ts +4 -4
- package/dist/types/slate/test-helpers/test-elements.d.ts +1 -1
- package/dist/types/state/modules/breakpoints.d.ts +2 -21
- package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/runtimes/react/controls/color.js +0 -58
- package/dist/cjs/runtimes/react/controls/color.js.map +0 -1
- package/dist/cjs/runtimes/react/controls/image.js +0 -53
- package/dist/cjs/runtimes/react/controls/image.js.map +0 -1
- package/dist/cjs/runtimes/react/controls/link.js +0 -110
- package/dist/cjs/runtimes/react/controls/link.js.map +0 -1
- package/dist/cjs/runtimes/react/controls/list.js +0 -58
- package/dist/cjs/runtimes/react/controls/list.js.map +0 -1
- package/dist/cjs/runtimes/react/controls/shape.js +0 -44
- package/dist/cjs/runtimes/react/controls/shape.js.map +0 -1
- package/dist/cjs/runtimes/react/controls/style-v2.js +0 -92
- package/dist/cjs/runtimes/react/controls/style-v2.js.map +0 -1
- package/dist/cjs/utils/coalesce.js.map +0 -1
- package/dist/cjs/utils/shallowMerge.js +0 -44
- package/dist/cjs/utils/shallowMerge.js.map +0 -1
- package/dist/esm/runtimes/react/controls/color.js +0 -24
- package/dist/esm/runtimes/react/controls/color.js.map +0 -1
- package/dist/esm/runtimes/react/controls/image.js +0 -29
- package/dist/esm/runtimes/react/controls/image.js.map +0 -1
- package/dist/esm/runtimes/react/controls/link.js +0 -76
- package/dist/esm/runtimes/react/controls/link.js.map +0 -1
- package/dist/esm/runtimes/react/controls/list.js +0 -34
- package/dist/esm/runtimes/react/controls/list.js.map +0 -1
- package/dist/esm/runtimes/react/controls/shape.js +0 -20
- package/dist/esm/runtimes/react/controls/shape.js.map +0 -1
- package/dist/esm/runtimes/react/controls/style-v2.js +0 -72
- package/dist/esm/runtimes/react/controls/style-v2.js.map +0 -1
- package/dist/esm/utils/coalesce.js +0 -13
- package/dist/esm/utils/coalesce.js.map +0 -1
- package/dist/esm/utils/shallowMerge.js +0 -14
- package/dist/esm/utils/shallowMerge.js.map +0 -1
- package/dist/types/runtimes/react/controls/color.d.ts +0 -4
- package/dist/types/runtimes/react/controls/color.d.ts.map +0 -1
- package/dist/types/runtimes/react/controls/image.d.ts +0 -4
- package/dist/types/runtimes/react/controls/image.d.ts.map +0 -1
- package/dist/types/runtimes/react/controls/link.d.ts +0 -4
- package/dist/types/runtimes/react/controls/link.d.ts.map +0 -1
- package/dist/types/runtimes/react/controls/list.d.ts +0 -12
- package/dist/types/runtimes/react/controls/list.d.ts.map +0 -1
- package/dist/types/runtimes/react/controls/shape.d.ts +0 -12
- package/dist/types/runtimes/react/controls/shape.d.ts.map +0 -1
- package/dist/types/runtimes/react/controls/style-v2.d.ts +0 -13
- package/dist/types/runtimes/react/controls/style-v2.d.ts.map +0 -1
- package/dist/types/utils/coalesce.d.ts +0 -3
- package/dist/types/utils/coalesce.d.ts.map +0 -1
- package/dist/types/utils/shallowMerge.d.ts +0 -2
- package/dist/types/utils/shallowMerge.d.ts.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useMemo, useEffect, useRef } from "react";
|
|
2
|
+
import { serializeStyles } from "@emotion/serialize";
|
|
3
|
+
import {
|
|
4
|
+
isNotNil,
|
|
5
|
+
getBaseBreakpoint
|
|
6
|
+
} from "@makeswift/controls";
|
|
7
|
+
import { useCache } from "../../../next/root-style-registry";
|
|
8
|
+
import { getBreakpointMediaQuery } from "../../../state/modules/breakpoints";
|
|
9
|
+
import { styleV1Css } from "../controls/style";
|
|
10
|
+
import { typographyCss } from "../controls/typography";
|
|
11
|
+
import { useBreakpoints } from "./use-breakpoints";
|
|
12
|
+
import { useCssId } from "./use-css-id";
|
|
13
|
+
import { useStyles, serializedStyleClassName } from "../use-style";
|
|
14
|
+
import { pollBoxModel } from "../poll-box-model";
|
|
15
|
+
function useStylesheetFactory() {
|
|
16
|
+
const breakpoints = useBreakpoints();
|
|
17
|
+
const cache = useCache();
|
|
18
|
+
const componentUid = useCssId();
|
|
19
|
+
const computedStyles = useRef({}).current;
|
|
20
|
+
const boxModelCallbacks = useRef({}).current;
|
|
21
|
+
return useMemo(() => {
|
|
22
|
+
const getStylesheet = (styleSheetId) => ({
|
|
23
|
+
breakpoints() {
|
|
24
|
+
return breakpoints;
|
|
25
|
+
},
|
|
26
|
+
defineStyle(style, onBoxModelChange) {
|
|
27
|
+
const serialized = serializeStyle(breakpoints, style, cache);
|
|
28
|
+
const uid = `u-${componentUid}-${styleSheetId}`;
|
|
29
|
+
computedStyles[uid] = serialized;
|
|
30
|
+
const className = serializedStyleClassName(cache, serialized);
|
|
31
|
+
if (!onBoxModelChange)
|
|
32
|
+
return className;
|
|
33
|
+
boxModelCallbacks[uid] = onBoxModelChange;
|
|
34
|
+
return `${className} ${uid}`;
|
|
35
|
+
},
|
|
36
|
+
child(id) {
|
|
37
|
+
return getStylesheet(`${styleSheetId}-${id}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
get(propName) {
|
|
42
|
+
return getStylesheet(propName);
|
|
43
|
+
},
|
|
44
|
+
useDefinedStyles() {
|
|
45
|
+
useStyles(cache, Object.values(computedStyles));
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const unsubscribes = Object.entries(boxModelCallbacks).map(
|
|
48
|
+
([uid, callback]) => callback != null ? pollBoxModel({
|
|
49
|
+
element: document.querySelector(`.${uid}`),
|
|
50
|
+
onBoxModelChange: callback
|
|
51
|
+
}) : void 0
|
|
52
|
+
).filter(isNotNil);
|
|
53
|
+
return () => unsubscribes.forEach((fn) => fn());
|
|
54
|
+
}, [Object.keys(boxModelCallbacks).join(" ")]);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}, [breakpoints, cache, componentUid]);
|
|
58
|
+
}
|
|
59
|
+
function isTypographyStyle(style) {
|
|
60
|
+
return Array.isArray(style);
|
|
61
|
+
}
|
|
62
|
+
function isStyleV2(style) {
|
|
63
|
+
return typeof style === "object" && "getStyle" in style && typeof style.getStyle === "function";
|
|
64
|
+
}
|
|
65
|
+
function styleV2Css(breakpoints, style) {
|
|
66
|
+
return {
|
|
67
|
+
...style.getStyle(getBaseBreakpoint(breakpoints)),
|
|
68
|
+
...breakpoints.reduce(
|
|
69
|
+
(styles, breakpoint) => ({
|
|
70
|
+
...styles,
|
|
71
|
+
[getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint)
|
|
72
|
+
}),
|
|
73
|
+
{}
|
|
74
|
+
)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function resolvedStyleToCss(breakpoints, style) {
|
|
78
|
+
if (isTypographyStyle(style)) {
|
|
79
|
+
return typographyCss(breakpoints, style);
|
|
80
|
+
}
|
|
81
|
+
if (isStyleV2(style)) {
|
|
82
|
+
return styleV2Css(breakpoints, style);
|
|
83
|
+
}
|
|
84
|
+
const { properties, styleData } = style;
|
|
85
|
+
return styleV1Css(breakpoints, styleData, properties);
|
|
86
|
+
}
|
|
87
|
+
function serializeStyle(breakpoints, style, cache) {
|
|
88
|
+
const css = resolvedStyleToCss(breakpoints, style);
|
|
89
|
+
return serializeStyles([css], cache.registered);
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
useStylesheetFactory
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=use-stylesheet-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n} from '@makeswift/controls'\n\nimport { useCache } from '../../../next/root-style-registry'\nimport { getBreakpointMediaQuery } from '../../../state/modules/breakpoints'\n\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAyB,uBAAuB;AAIhD;AAAA,EAOE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AAExC,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAE9B,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,WAAW,gCAAgC;AACpD,SAAS,oBAAoB;AAOtB,SAAS,uBAA0C;AACxD,QAAM,cAAc,eAAe;AACnC,QAAM,QAAQ,SAAS;AACvB,QAAM,eAAe,SAAS;AAE9B,QAAM,iBAAiB,OAAyC,CAAC,CAAC,EAAE;AACpE,QAAM,oBAAoB,OAA4D,CAAC,CAAC,EAAE;AAE1F,SAAO,QAAQ,MAAM;AACnB,UAAM,gBAAgB,CAAC,kBAAsC;AAAA,MAC3D,cAA2B;AACzB,eAAO;AAAA,MACT;AAAA,MAEA,YACE,OACA,kBACQ;AACR,cAAM,aAAa,eAAe,aAAa,OAAO,KAAK;AAC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AA,QACH,CAAC,wBAAwB,UAAU,CAAC,GAAG,MAAM,SAAS,UAAU;AAAA,MAClE;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,aAA0B,OAAsB;AAC1E,MAAI,kBAAkB,KAAK,GAAG;AAC5B,WAAO,cAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,SAAO,WAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,SAAO,gBAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function resolvableRecord(resolvables) {
|
|
2
|
+
let resolvedValues = {};
|
|
3
|
+
return {
|
|
4
|
+
name: "resolvable-record",
|
|
5
|
+
subscribe: (onUpdate) => {
|
|
6
|
+
const unsubscribes = Object.values(resolvables).map((s) => s.subscribe(onUpdate));
|
|
7
|
+
return () => {
|
|
8
|
+
unsubscribes.forEach((u) => u());
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
readStable: () => {
|
|
12
|
+
const { isDirty, resolved } = Object.entries(resolvables).reduce(
|
|
13
|
+
({ isDirty: isDirty2, resolved: resolved2 }, [propName, subscription]) => {
|
|
14
|
+
const lastPropValue = resolvedValues[propName];
|
|
15
|
+
const propValue = subscription.readStable();
|
|
16
|
+
return {
|
|
17
|
+
isDirty: isDirty2 || propValue !== lastPropValue,
|
|
18
|
+
resolved: {
|
|
19
|
+
...resolved2,
|
|
20
|
+
[propName]: propValue
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
{ isDirty: false, resolved: {} }
|
|
25
|
+
);
|
|
26
|
+
if (isDirty) {
|
|
27
|
+
resolvedValues = resolved;
|
|
28
|
+
}
|
|
29
|
+
return resolvedValues;
|
|
30
|
+
},
|
|
31
|
+
triggerResolve: async () => {
|
|
32
|
+
return await Promise.all(
|
|
33
|
+
Object.entries(resolvables).map(
|
|
34
|
+
([propName, sub]) => sub.triggerResolve(resolvedValues[propName])
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
resolvableRecord
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=resolvable-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/resolvable-record.tsx"],"sourcesContent":["import { type Resolvable } from '@makeswift/controls'\n\nexport function resolvableRecord(\n resolvables: Record<string, Resolvable<unknown>>,\n): Resolvable<Record<string, unknown>> {\n let resolvedValues: Record<string, unknown> = {}\n\n return {\n name: 'resolvable-record',\n subscribe: (onUpdate: () => void): (() => void) => {\n const unsubscribes = Object.values(resolvables).map(s => s.subscribe(onUpdate))\n return () => {\n unsubscribes.forEach(u => u())\n }\n },\n\n readStable: () => {\n const { isDirty, resolved } = Object.entries(resolvables).reduce(\n ({ isDirty, resolved }, [propName, subscription]) => {\n const lastPropValue = resolvedValues[propName]\n const propValue = subscription.readStable()\n return {\n isDirty: isDirty || propValue !== lastPropValue,\n resolved: {\n ...resolved,\n [propName]: propValue,\n },\n }\n },\n { isDirty: false, resolved: {} },\n )\n\n if (isDirty) {\n resolvedValues = resolved\n }\n\n return resolvedValues\n },\n\n triggerResolve: async () => {\n return await Promise.all(\n Object.entries(resolvables).map(([propName, sub]) =>\n sub.triggerResolve(resolvedValues[propName]),\n ),\n )\n },\n }\n}\n"],"mappings":"AAEO,SAAS,iBACd,aACqC;AACrC,MAAI,iBAA0C,CAAC;AAE/C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,WAAW,CAAC,aAAuC;AACjD,YAAM,eAAe,OAAO,OAAO,WAAW,EAAE,IAAI,OAAK,EAAE,UAAU,QAAQ,CAAC;AAC9E,aAAO,MAAM;AACX,qBAAa,QAAQ,OAAK,EAAE,CAAC;AAAA,MAC/B;AAAA,IACF;AAAA,IAEA,YAAY,MAAM;AAChB,YAAM,EAAE,SAAS,SAAS,IAAI,OAAO,QAAQ,WAAW,EAAE;AAAA,QACxD,CAAC,EAAE,SAAAA,UAAS,UAAAC,UAAS,GAAG,CAAC,UAAU,YAAY,MAAM;AACnD,gBAAM,gBAAgB,eAAe,QAAQ;AAC7C,gBAAM,YAAY,aAAa,WAAW;AAC1C,iBAAO;AAAA,YACL,SAASD,YAAW,cAAc;AAAA,YAClC,UAAU;AAAA,cACR,GAAGC;AAAA,cACH,CAAC,QAAQ,GAAG;AAAA,YACd;AAAA,UACF;AAAA,QACF;AAAA,QACA,EAAE,SAAS,OAAO,UAAU,CAAC,EAAE;AAAA,MACjC;AAEA,UAAI,SAAS;AACX,yBAAiB;AAAA,MACnB;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,YAAY;AAC1B,aAAO,MAAM,QAAQ;AAAA,QACnB,OAAO,QAAQ,WAAW,EAAE;AAAA,UAAI,CAAC,CAAC,UAAU,GAAG,MAC7C,IAAI,eAAe,eAAe,QAAQ,CAAC;AAAA,QAC7C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["isDirty","resolved"]}
|
|
@@ -9,14 +9,28 @@ function useStyle(style) {
|
|
|
9
9
|
const cache = useCache();
|
|
10
10
|
const serialized = serializeStyles([style], cache.registered);
|
|
11
11
|
registerStyles(cache, serialized, false);
|
|
12
|
-
|
|
12
|
+
useUniversalInsertionEffect(() => {
|
|
13
13
|
insertStyles(cache, serialized, false);
|
|
14
14
|
});
|
|
15
|
+
return serializedStyleClassName(cache, serialized);
|
|
16
|
+
}
|
|
17
|
+
function useStyles(cache, styles) {
|
|
18
|
+
styles.forEach((s) => registerStyles(cache, s, false));
|
|
19
|
+
useUniversalInsertionEffect(() => {
|
|
20
|
+
styles.forEach((s) => insertStyles(cache, s, false));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function useUniversalInsertionEffect(effect) {
|
|
24
|
+
useInsertionEffect(effect);
|
|
15
25
|
if (isServer)
|
|
16
|
-
|
|
26
|
+
effect();
|
|
27
|
+
}
|
|
28
|
+
function serializedStyleClassName(cache, serialized) {
|
|
17
29
|
return `${cache.key}-${serialized.name}`;
|
|
18
30
|
}
|
|
19
31
|
export {
|
|
20
|
-
|
|
32
|
+
serializedStyleClassName,
|
|
33
|
+
useStyle,
|
|
34
|
+
useStyles
|
|
21
35
|
};
|
|
22
36
|
//# sourceMappingURL=use-style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles } from '@emotion/utils'\nimport { useCache } from '../../next/root-style-registry'\n\nconst isServer = typeof window === 'undefined'\nconst useInsertionEffectSpecifier = 'useInsertionEffect'\nconst useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect\n\nexport function useStyle(style: CSSObject): string {\n const cache = useCache()\n const serialized = serializeStyles([style], cache.registered)\n\n registerStyles(cache, serialized, false)\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/use-style.ts"],"sourcesContent":["import React from 'react'\nimport { CSSObject } from '@emotion/css'\nimport { EmotionCache } from '@emotion/cache'\nimport { serializeStyles } from '@emotion/serialize'\nimport { registerStyles, insertStyles, type SerializedStyles } from '@emotion/utils'\n\nimport { useCache } from '../../next/root-style-registry'\n\nconst isServer = typeof window === 'undefined'\nconst useInsertionEffectSpecifier = 'useInsertionEffect'\nconst useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect\n\nexport function useStyle(style: CSSObject): string {\n const cache = useCache()\n const serialized = serializeStyles([style], cache.registered)\n\n registerStyles(cache, serialized, false)\n\n useUniversalInsertionEffect(() => {\n insertStyles(cache, serialized, false)\n })\n\n return serializedStyleClassName(cache, serialized)\n}\n\nexport function useStyles(cache: EmotionCache, styles: SerializedStyles[]) {\n styles.forEach(s => registerStyles(cache, s, false))\n\n useUniversalInsertionEffect(() => {\n styles.forEach(s => insertStyles(cache, s, false))\n })\n}\n\nfunction useUniversalInsertionEffect(effect: () => void) {\n useInsertionEffect(effect)\n if (isServer) effect()\n}\n\nexport function serializedStyleClassName(\n cache: EmotionCache,\n serialized: SerializedStyles,\n): string {\n // see https://github.com/emotion-js/emotion/blob/main/packages/utils/src/index.ts#L26\n return `${cache.key}-${serialized.name}`\n}\n"],"mappings":"AAAA,OAAO,WAAW;AAGlB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,oBAA2C;AAEpE,SAAS,gBAAgB;AAEzB,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,8BAA8B;AACpC,MAAM,qBAAqB,MAAM,2BAA2B,KAAK,MAAM;AAEhE,SAAS,SAAS,OAA0B;AACjD,QAAM,QAAQ,SAAS;AACvB,QAAM,aAAa,gBAAgB,CAAC,KAAK,GAAG,MAAM,UAAU;AAE5D,iBAAe,OAAO,YAAY,KAAK;AAEvC,8BAA4B,MAAM;AAChC,iBAAa,OAAO,YAAY,KAAK;AAAA,EACvC,CAAC;AAED,SAAO,yBAAyB,OAAO,UAAU;AACnD;AAEO,SAAS,UAAU,OAAqB,QAA4B;AACzE,SAAO,QAAQ,OAAK,eAAe,OAAO,GAAG,KAAK,CAAC;AAEnD,8BAA4B,MAAM;AAChC,WAAO,QAAQ,OAAK,aAAa,OAAO,GAAG,KAAK,CAAC;AAAA,EACnD,CAAC;AACH;AAEA,SAAS,4BAA4B,QAAoB;AACvD,qBAAmB,MAAM;AACzB,MAAI;AAAU,WAAO;AACvB;AAEO,SAAS,yBACd,OACA,YACQ;AAER,SAAO,GAAG,MAAM,GAAG,IAAI,WAAW,IAAI;AACxC;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Editor, Text, Transforms } from "slate";
|
|
2
|
+
import { cx } from "@emotion/css";
|
|
2
3
|
import { unstable_Typography } from "@makeswift/controls";
|
|
3
4
|
import { clearActiveTypographyStyle } from "./clearActiveTypographyStyle";
|
|
4
5
|
import { clearDeviceActiveTypography } from "./clearDeviceActiveTypography";
|
|
@@ -100,7 +101,7 @@ function TypographyPlugin() {
|
|
|
100
101
|
...props,
|
|
101
102
|
leaf: {
|
|
102
103
|
...props.leaf,
|
|
103
|
-
className:
|
|
104
|
+
className: cx(props.leaf.className, className)
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/index.ts"],"sourcesContent":["import { BaseEditor, Descendant, Editor, NodeEntry, Text, Transforms } from 'slate'\nimport { unstable_Typography } from '@makeswift/controls'\n\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\nimport { getValue } from './getValue'\nimport { getSelection } from '../selectors'\nimport { Plugin } from '../../controls/rich-text-v2/plugin'\nimport { normalizeTypographyUp } from './normalizeTypographyUp'\nimport { normalizeTypographyDown } from './normalizeTypographyDown'\nimport { normalizeSimilarText } from './normalizeSimilarText'\n\nexport const TypographyActions = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport const TYPOGRAPHY_KEY = 'typography'\n\nexport interface TypographyEditor extends BaseEditor {\n typographyNormalizationDirection?: 'up' | 'neutral' | 'down'\n}\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n\n if (\n 'typography' in normalizationNode &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, TYPOGRAPHY_KEY, { at: normalizationPath })\n return\n }\n\n if ('slice' in normalizationNode && normalizationNode?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: normalizationPath })\n return\n }\n\n if (normalizeSimilarText(editor, entry)) return\n\n if (editor.typographyNormalizationDirection === 'up' && normalizeTypographyUp(editor, entry))\n return\n\n if (\n (editor.typographyNormalizationDirection === 'down' ||\n editor.typographyNormalizationDirection == null) &&\n normalizeTypographyDown(editor, entry)\n )\n return\n\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TypographyPlugin() {\n return Plugin({\n withPlugin: withTypography,\n control: {\n definition: unstable_Typography(),\n onChange: (editor, value) => {\n Editor.withoutNormalizing(editor, () => {\n const at = getSelection(editor)\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n if (atRef.current) {\n Transforms.setNodes<Descendant>(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: Text.isText,\n split: true,\n },\n )\n }\n\n if (atRef.current) {\n const nodesToUpdate = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n ) as NodeEntry<Text>[]\n\n if (nodesToUpdate.length !== value?.length)\n return console.error(\n `TypographyControl.onChange received the wrong number of arguments.\n Called with ${value?.length} values mapping to ${nodesToUpdate.length} nodes.`,\n )\n\n for (const [index, [, path]] of nodesToUpdate.entries()) {\n Transforms.setNodes(\n editor,\n {\n typography: value?.at(index),\n },\n { at: path, match: Text.isText },\n )\n }\n }\n\n atRef.unref()\n })\n },\n getValue,\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text.typography : undefined\n },\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className:
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/index.ts"],"sourcesContent":["import { BaseEditor, Descendant, Editor, NodeEntry, Text, Transforms } from 'slate'\nimport { cx } from '@emotion/css'\nimport { unstable_Typography } from '@makeswift/controls'\n\nimport { clearActiveTypographyStyle } from './clearActiveTypographyStyle'\nimport { clearDeviceActiveTypography } from './clearDeviceActiveTypography'\nimport { detachActiveTypography } from './detachActiveTypography'\nimport { setActiveTypographyId } from './setActiveTypographyId'\nimport { setActiveTypographyStyle } from './setActiveTypographyStyle'\nimport { getValue } from './getValue'\nimport { getSelection } from '../selectors'\nimport { Plugin } from '../../controls/rich-text-v2/plugin'\nimport { normalizeTypographyUp } from './normalizeTypographyUp'\nimport { normalizeTypographyDown } from './normalizeTypographyDown'\nimport { normalizeSimilarText } from './normalizeSimilarText'\n\nexport const TypographyActions = {\n setActiveTypographyId,\n setActiveTypographyStyle,\n clearActiveTypographyStyle,\n clearDeviceActiveTypography,\n detachActiveTypography,\n}\n\nexport const TYPOGRAPHY_KEY = 'typography'\n\nexport interface TypographyEditor extends BaseEditor {\n typographyNormalizationDirection?: 'up' | 'neutral' | 'down'\n}\n\nexport function withTypography(editor: Editor) {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n const [normalizationNode, normalizationPath] = entry\n\n if (\n 'typography' in normalizationNode &&\n normalizationNode?.typography?.id == null &&\n normalizationNode?.typography?.style.length === 0\n ) {\n Transforms.unsetNodes(editor, TYPOGRAPHY_KEY, { at: normalizationPath })\n return\n }\n\n if ('slice' in normalizationNode && normalizationNode?.slice != null) {\n Transforms.unsetNodes(editor, 'slice', { at: normalizationPath })\n return\n }\n\n if (normalizeSimilarText(editor, entry)) return\n\n if (editor.typographyNormalizationDirection === 'up' && normalizeTypographyUp(editor, entry))\n return\n\n if (\n (editor.typographyNormalizationDirection === 'down' ||\n editor.typographyNormalizationDirection == null) &&\n normalizeTypographyDown(editor, entry)\n )\n return\n\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TypographyPlugin() {\n return Plugin({\n withPlugin: withTypography,\n control: {\n definition: unstable_Typography(),\n onChange: (editor, value) => {\n Editor.withoutNormalizing(editor, () => {\n const at = getSelection(editor)\n if (!at) return\n const atRef = Editor.rangeRef(editor, at)\n if (atRef.current) {\n Transforms.setNodes<Descendant>(\n editor,\n {\n slice: true,\n },\n {\n at: atRef.current,\n match: Text.isText,\n split: true,\n },\n )\n }\n\n if (atRef.current) {\n const nodesToUpdate = Array.from(\n Editor.nodes(editor, {\n at: atRef.current,\n match: node => Text.isText(node) && node.slice === true,\n }),\n ) as NodeEntry<Text>[]\n\n if (nodesToUpdate.length !== value?.length)\n return console.error(\n `TypographyControl.onChange received the wrong number of arguments.\n Called with ${value?.length} values mapping to ${nodesToUpdate.length} nodes.`,\n )\n\n for (const [index, [, path]] of nodesToUpdate.entries()) {\n Transforms.setNodes(\n editor,\n {\n typography: value?.at(index),\n },\n { at: path, match: Text.isText },\n )\n }\n }\n\n atRef.unref()\n })\n },\n getValue,\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text.typography : undefined\n },\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className: cx(props.leaf.className, className),\n },\n })\n },\n })\n}\n"],"mappings":"AAAA,SAAiC,QAAmB,MAAM,kBAAkB;AAC5E,SAAS,UAAU;AACnB,SAAS,2BAA2B;AAEpC,SAAS,kCAAkC;AAC3C,SAAS,mCAAmC;AAC5C,SAAS,8BAA8B;AACvC,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AAE9B,MAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,iBAAiB;AAMvB,SAAS,eAAe,QAAgB;AAC7C,QAAM,EAAE,cAAc,IAAI;AAC1B,S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D,CAAC;AAAA,YACH;AAEA,gBAAI,cAAc,WAAW,OAAO;AAClC,qBAAO,QAAQ;AAAA,gBACb;AAAA,0BACU,OAAO,MAAM,sBAAsB,cAAc,MAAM;AAAA,cACnE;AAEF,uBAAW,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,cAAc,QAAQ,GAAG;AACvD,yBAAW;AAAA,gBACT;AAAA,gBACA;AAAA,kBACE,YAAY,OAAO,GAAG,KAAK;AAAA,gBAC7B;AAAA,gBACA,EAAE,IAAI,MAAM,OAAO,KAAK,OAAO;AAAA,cACjC;AAAA,YACF;AAAA,UACF;AAEA,gBAAM,MAAM;AAAA,QACd,CAAC;AAAA,MACH;AAAA,MACA;AAAA,MACA,cAAc,CAAC,SAAe;AAC5B,eAAO,KAAK,OAAO,IAAI,IAAI,KAAK,aAAa;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,YAAY,CAAC,YAAY,cAAc,WAAS;AAC9C,aAAO,WAAW;AAAA,QAChB,GAAG;AAAA,QACH,MAAM;AAAA,UACJ,GAAG,MAAM;AAAA,UACT,WAAW,GAAG,MAAM,KAAK,WAAW,SAAS;AAAA,QAC/C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor, Element, Transforms } from "slate";
|
|
2
|
-
import shallowMerge from "
|
|
2
|
+
import { shallowMerge } from "@makeswift/controls";
|
|
3
3
|
import { TYPOGRAPHY_KEY } from ".";
|
|
4
4
|
function shallowMergeTypographies(commonTypography, typography) {
|
|
5
5
|
const devices = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/normalizeTypographyDown.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms } from 'slate'\nimport { RichTextTypography } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/slate/TypographyPlugin/normalizeTypographyDown.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms } from 'slate'\nimport { RichTextTypography, shallowMerge } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport { TYPOGRAPHY_KEY } from '.'\n\nexport function shallowMergeTypographies(\n commonTypography?: RichTextTypography,\n typography?: RichTextTypography,\n) {\n const devices = [\n ...new Set(\n commonTypography?.style\n .map(node => node.deviceId)\n .concat(typography?.style.map(node => node.deviceId) ?? []),\n ),\n ]\n\n return {\n id: commonTypography?.id ?? typography?.id,\n style: devices.map(deviceId => {\n const commonDevice = commonTypography?.style.find(s => s.deviceId === deviceId)\n const existingDeviceStyle = typography?.style.find(s => s.deviceId === deviceId)\n\n return {\n deviceId,\n value: shallowMerge(existingDeviceStyle?.value ?? {}, commonDevice?.value ?? {}),\n }\n }),\n }\n}\n\nexport function normalizeTypographyDown(editor: MakeswiftEditor, entry: NodeEntry): boolean {\n const [normalizationNode, normalizationPath] = entry\n\n if (\n Element.isElement(normalizationNode) &&\n normalizationNode.typography != null &&\n normalizationNode.children.length\n ) {\n Editor.withoutNormalizing(editor, () => {\n Transforms.unsetNodes(editor, TYPOGRAPHY_KEY, { at: normalizationPath })\n for (let i = 0; i < normalizationNode.children.length; i++) {\n const resultingTypography = shallowMergeTypographies(\n normalizationNode.typography,\n normalizationNode.children.at(i)?.typography,\n )\n Transforms.setNodes(\n editor,\n { typography: resultingTypography },\n { at: [...normalizationPath, i] },\n )\n }\n })\n return true\n }\n\n return false\n}\n"],"mappings":"AAAA,SAAS,QAAQ,SAAoB,kBAAkB;AACvD,SAA6B,oBAAoB;AAGjD,SAAS,sBAAsB;AAExB,SAAS,yBACd,kBACA,YACA;AACA,QAAM,UAAU;AAAA,IACd,GAAG,IAAI;AAAA,MACL,kBAAkB,MACf,IAAI,UAAQ,KAAK,QAAQ,EACzB,OAAO,YAAY,MAAM,IAAI,UAAQ,KAAK,QAAQ,KAAK,CAAC,CAAC;AAAA,IAC9D;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI,kBAAkB,MAAM,YAAY;AAAA,IACxC,OAAO,QAAQ,IAAI,cAAY;AAC7B,YAAM,eAAe,kBAAkB,MAAM,KAAK,OAAK,EAAE,aAAa,QAAQ;AAC9E,YAAM,sBAAsB,YAAY,MAAM,KAAK,OAAK,EAAE,aAAa,QAAQ;AAE/E,aAAO;AAAA,QACL;AAAA,QACA,OAAO,aAAa,qBAAqB,SAAS,CAAC,GAAG,cAAc,SAAS,CAAC,CAAC;AAAA,MACjF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,SAAS,wBAAwB,QAAyB,OAA2B;AAC1F,QAAM,CAAC,mBAAmB,iBAAiB,IAAI;AAE/C,MACE,QAAQ,UAAU,iBAAiB,KACnC,kBAAkB,cAAc,QAChC,kBAAkB,SAAS,QAC3B;AACA,WAAO,mBAAmB,QAAQ,MAAM;AACtC,iBAAW,WAAW,QAAQ,gBAAgB,EAAE,IAAI,kBAAkB,CAAC;AACvE,eAAS,IAAI,GAAG,IAAI,kBAAkB,SAAS,QAAQ,KAAK;AAC1D,cAAM,sBAAsB;AAAA,UAC1B,kBAAkB;AAAA,UAClB,kBAAkB,SAAS,GAAG,CAAC,GAAG;AAAA,QACpC;AACA,mBAAW;AAAA,UACT;AAAA,UACA,EAAE,YAAY,oBAAoB;AAAA,UAClC,EAAE,IAAI,CAAC,GAAG,mBAAmB,CAAC,EAAE;AAAA,QAClC;AAAA,MACF;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/slate/index.ts"],"sourcesContent":["export * from './BlockPlugin'\nexport * from './BuilderPlugin'\nexport * from './InlineModePlugin'\nexport * from './InlinePlugin'\nexport * from './LinkPlugin'\nexport * from './LocalChangesPlugin'\nexport * from './TextAlignPlugin'\nexport * from './TypographyPlugin'\nexport * from './types'\nexport * from './utils'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/slate/index.ts"],"sourcesContent":["export { type NodeJSON, type ValueJSON, type InlineJSON, type MarkJSON } from '@makeswift/controls'\nexport * from './BlockPlugin'\nexport * from './BuilderPlugin'\nexport * from './InlineModePlugin'\nexport * from './InlinePlugin'\nexport * from './LinkPlugin'\nexport * from './LocalChangesPlugin'\nexport * from './TextAlignPlugin'\nexport * from './TypographyPlugin'\nexport * from './types'\nexport * from './utils'\n"],"mappings":"AACA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findBreakpointOverride
|
|
3
|
+
} from "@makeswift/controls";
|
|
1
4
|
import { ActionTypes } from "../actions";
|
|
2
|
-
import
|
|
3
|
-
|
|
5
|
+
import {
|
|
6
|
+
findBreakpointOverride as findBreakpointOverride2,
|
|
7
|
+
getBaseBreakpoint
|
|
8
|
+
} from "@makeswift/controls";
|
|
4
9
|
const DefaultBreakpointID = {
|
|
5
10
|
Desktop: "desktop",
|
|
6
11
|
Tablet: "tablet",
|
|
@@ -94,60 +99,12 @@ function validateBreakpointsInput(input) {
|
|
|
94
99
|
}
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
|
-
function sortBreakpoints(breakpoints) {
|
|
98
|
-
return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0));
|
|
99
|
-
}
|
|
100
102
|
const getBreakpoint = (state, breakpointId) => {
|
|
101
103
|
const breakpoint = state.find(({ id }) => id === breakpointId);
|
|
102
104
|
if (breakpoint == null)
|
|
103
105
|
throw new Error(`Unrecognized breakpoint ID: "${breakpointId}".`);
|
|
104
106
|
return breakpoint;
|
|
105
107
|
};
|
|
106
|
-
const getBaseBreakpoint = (breakpoints) => {
|
|
107
|
-
const breakpoint = sortBreakpoints(breakpoints)[0];
|
|
108
|
-
if (breakpoint == null)
|
|
109
|
-
throw new Error(`Cannot get base breakpoint.`);
|
|
110
|
-
return breakpoint;
|
|
111
|
-
};
|
|
112
|
-
function findBreakpointOverride(breakpoints, values = [], deviceId, strategy = defaultStrategy) {
|
|
113
|
-
const value = values.find(({ deviceId: d }) => d === deviceId);
|
|
114
|
-
const fallbacks = breakpoints.slice(0, breakpoints.findIndex((d) => d.id === deviceId) + 1).reverse().map((d) => values.find((v) => v.deviceId === d.id)).filter((override) => Boolean(override));
|
|
115
|
-
return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : void 0;
|
|
116
|
-
}
|
|
117
|
-
function defaultStrategy(value, fallbacks) {
|
|
118
|
-
return value || fallbacks[0];
|
|
119
|
-
}
|
|
120
|
-
function shallowMergeFallbacks(value, fallbacks) {
|
|
121
|
-
return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
|
|
122
|
-
deviceId: a.deviceId || b.deviceId,
|
|
123
|
-
value: shallowMerge(a.value, b.value)
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
function mergeOrCoalesce(a, b) {
|
|
127
|
-
if (typeof a === "object" && a !== null && !Array.isArray(a) && typeof b === "object" && b !== null && !Array.isArray(b)) {
|
|
128
|
-
return shallowMerge(a, b);
|
|
129
|
-
}
|
|
130
|
-
return coalesce(a, b);
|
|
131
|
-
}
|
|
132
|
-
function mergeOrCoalesceFallbacks(value, fallbacks) {
|
|
133
|
-
return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
|
|
134
|
-
deviceId: a.deviceId || b.deviceId,
|
|
135
|
-
value: mergeOrCoalesce(a.value, b.value)
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
function join(breakpoints, responsiveValues, joinFn, strategy) {
|
|
139
|
-
return breakpoints.map(({ id }) => id).map((deviceId) => {
|
|
140
|
-
const value = joinFn(
|
|
141
|
-
responsiveValues.map((responsiveValue) => {
|
|
142
|
-
const deviceValue = responsiveValue && findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy);
|
|
143
|
-
return deviceValue == null ? void 0 : deviceValue.value;
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
if (value == null)
|
|
147
|
-
return null;
|
|
148
|
-
return { deviceId, value };
|
|
149
|
-
}).filter((override) => Boolean(override));
|
|
150
|
-
}
|
|
151
108
|
const getBreakpointMediaQuery = (breakpoint) => {
|
|
152
109
|
const parts = ["@media only screen"];
|
|
153
110
|
if (breakpoint.minWidth != null) {
|
|
@@ -174,35 +131,17 @@ function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallback
|
|
|
174
131
|
);
|
|
175
132
|
return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null;
|
|
176
133
|
}
|
|
177
|
-
const mergeResponsiveValues = (breakpoints, source, override) => {
|
|
178
|
-
const devices = [
|
|
179
|
-
...new Set(
|
|
180
|
-
source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId))
|
|
181
|
-
)
|
|
182
|
-
];
|
|
183
|
-
return devices.map((deviceId) => ({
|
|
184
|
-
deviceId,
|
|
185
|
-
value: {
|
|
186
|
-
...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,
|
|
187
|
-
...(findBreakpointOverride(breakpoints, override, deviceId, (v) => v) || { value: {} }).value
|
|
188
|
-
}
|
|
189
|
-
}));
|
|
190
|
-
};
|
|
191
134
|
export {
|
|
192
135
|
DEFAULT_BREAKPOINTS,
|
|
193
136
|
DefaultBreakpointID,
|
|
194
|
-
findBreakpointOverride,
|
|
137
|
+
findBreakpointOverride2 as findBreakpointOverride,
|
|
195
138
|
findNextFallback,
|
|
196
139
|
getBaseBreakpoint,
|
|
197
140
|
getBreakpoint,
|
|
198
141
|
getBreakpointMediaQuery,
|
|
199
142
|
getInitialState,
|
|
200
143
|
getViewportStyle,
|
|
201
|
-
join,
|
|
202
|
-
mergeOrCoalesceFallbacks,
|
|
203
|
-
mergeResponsiveValues,
|
|
204
144
|
parseBreakpointsInput,
|
|
205
|
-
reducer
|
|
206
|
-
shallowMergeFallbacks
|
|
145
|
+
reducer
|
|
207
146
|
};
|
|
208
147
|
//# sourceMappingURL=breakpoints.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { Viewport } from 'csstype'\n\nimport {\n type Data,\n type ResponsiveValue,\n type DeviceOverride,\n type Device as DeviceId,\n} from '@makeswift/controls'\n\nimport { Action, ActionTypes } from '../actions'\n\nimport shallowMerge from '../../utils/shallowMerge'\nimport coalesce from '../../utils/coalesce'\n\nexport { type ResponsiveValue, type DeviceOverride } from '@makeswift/controls'\n\nexport type BreakpointId = DeviceId\n\nexport type Breakpoint = {\n id: BreakpointId\n label?: string\n viewportWidth?: number\n minWidth?: number\n maxWidth?: number\n}\n\nexport type Breakpoints = Breakpoint[]\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = (typeof DefaultBreakpointID)[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n\n// Sort breakpoints by minWidth in descending order\nfunction sortBreakpoints(breakpoints: Breakpoints): Breakpoints {\n return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0))\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBaseBreakpoint = (breakpoints: Breakpoints): Breakpoint => {\n const breakpoint = sortBreakpoints(breakpoints)[0]\n\n if (breakpoint == null) throw new Error(`Cannot get base breakpoint.`)\n\n return breakpoint\n}\n\nexport function findBreakpointOverride<S>(\n breakpoints: Breakpoints,\n values: ResponsiveValue<S> = [],\n deviceId: string,\n strategy: FallbackStrategy<S> = defaultStrategy,\n): DeviceOverride<S> | undefined {\n const value = values.find(({ deviceId: d }) => d === deviceId)\n const fallbacks = breakpoints\n .slice(0, breakpoints.findIndex(d => d.id === deviceId) + 1)\n .reverse()\n .map(d => values.find(v => v.deviceId === d.id))\n .filter((override): override is DeviceOverride<S> => Boolean(override))\n\n return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined\n}\n\nexport type FallbackStrategy<V> = (\n arg0: DeviceOverride<V> | undefined,\n arg1: ResponsiveValue<V>,\n) => DeviceOverride<V> | undefined\n\nfunction defaultStrategy<V>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return value || fallbacks[0]\n}\n\nexport function shallowMergeFallbacks<V extends Record<string, unknown>>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: shallowMerge(a.value, b.value),\n }))\n}\n\nfunction mergeOrCoalesce<A extends Data>(a: A, b: A): A {\n if (\n typeof a === 'object' &&\n a !== null &&\n !Array.isArray(a) &&\n typeof b === 'object' &&\n b !== null &&\n !Array.isArray(b)\n ) {\n return shallowMerge(a, b) as A\n }\n return coalesce(a, b)\n}\n\nexport function mergeOrCoalesceFallbacks<V extends Data>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: mergeOrCoalesce(a.value, b.value),\n }))\n}\n\nexport type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never\n\nexport function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(\n breakpoints: Breakpoints,\n responsiveValues: A,\n joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,\n strategy?: FallbackStrategy<V>,\n): ResponsiveValue<R> {\n return breakpoints\n .map(({ id }) => id)\n .map(deviceId => {\n const value = joinFn(\n responsiveValues.map(responsiveValue => {\n const deviceValue =\n responsiveValue &&\n findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy)\n\n return deviceValue == null ? undefined : deviceValue.value\n }) as unknown as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },\n )\n\n if (value == null) return null\n\n return { deviceId, value }\n })\n .filter((override): override is NonNullable<typeof override> => Boolean(override))\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n\nexport const mergeResponsiveValues = <A>(\n breakpoints: Breakpoints,\n source: DeviceOverride<A>[],\n override: DeviceOverride<A>[],\n): DeviceOverride<A>[] => {\n const devices = [\n ...new Set(\n source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)),\n ),\n ]\n\n return devices.map(deviceId => ({\n deviceId,\n value: {\n ...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,\n ...(findBreakpointOverride(breakpoints, override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n"],"mappings":"AASA,SAAiB,mBAAmB;AAEpC,OAAO,kBAAkB;AACzB,OAAO,cAAc;AAkBd,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,gBAAgB,cAAc,qBAA4B;AACxE,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuB;AAC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EACF;AAEA,SAAO,QAAQ,IAAI,eAAa;AAAA,IAC9B;AAAA,IACA,OAAO;AAAA,MACL,IAAI,uBAAuB,aAAa,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG;AAAA,MAC5E,IAAI,uBAAuB,aAAa,UAAU,UAAU,OAAK,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG;AAAA,IACxF;AAAA,EACF,EAAE;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/breakpoints.ts"],"sourcesContent":["import { Viewport } from 'csstype'\n\nimport {\n findBreakpointOverride,\n type ResponsiveValue,\n type BreakpointId,\n type Breakpoint,\n type Breakpoints,\n type FallbackStrategy,\n} from '@makeswift/controls'\n\nimport { Action, ActionTypes } from '../actions'\n\nexport {\n findBreakpointOverride,\n getBaseBreakpoint,\n type ResponsiveValue,\n type DeviceOverride,\n type Breakpoint,\n type BreakpointId,\n type Breakpoints,\n type FallbackStrategy,\n} from '@makeswift/controls'\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = (typeof DefaultBreakpointID)[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n"],"mappings":"AAEA;AAAA,EACE;AAAA,OAMK;AAEP,SAAiB,mBAAmB;AAEpC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OAOK;AAIA,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,U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AAe,WAAW,QAAQ,KAAK;AAAA,EACpD;AAEA,MAAI,WAAW,YAAY,MAAM;AAC/B,UAAM,KAAK,eAAe,WAAW,QAAQ,KAAK;AAAA,EACpD;AAEA,SAAO,MAAM,KAAK,OAAO;AAC3B;AAEO,MAAM,mBAAmB,CAC9B,OACA,aACiD;AACjD,QAAM,SAAS,cAAc,OAAO,QAAQ;AAE5C,SACE,UAAU;AAAA,IACR,OAAO,OAAO,iBAAiB,OAAO,OAAO,gBAAgB;AAAA,IAC7D,UAAU,OAAO;AAAA,EACnB;AAEJ;AAEO,SAAS,iBACd,aACA,OACA,UACA,gBACA,kBACmB;AACnB,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,MAAM,OAAO,OAAK,EAAE,aAAa,cAAc;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,kBAAkB,cAAc,aAAa,eAAe,QAAQ,MAAM;AACpF;","names":["findBreakpointOverride"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type FetchableValue } from '@makeswift/controls';
|
|
1
2
|
import * as MakeswiftApiClient from '../state/makeswift-api-client';
|
|
2
|
-
import { File, GlobalElement, LocalizedGlobalElement, Page, PagePathnameSlice, Site, Snippet, Swatch, Table, Typography } from './graphql/types';
|
|
3
|
+
import { APIResourceType, File, GlobalElement, LocalizedGlobalElement, Page, PagePathnameSlice, Site, Snippet, Swatch, Table, Typography } from './graphql/types';
|
|
3
4
|
import { GraphQLClient } from './graphql/client';
|
|
4
5
|
export type SerializedLocalizedResourcesMap = {
|
|
5
6
|
[resourceId: string]: string | null;
|
|
@@ -39,16 +40,25 @@ export declare class MakeswiftHostApiClient {
|
|
|
39
40
|
constructor({ uri, cacheData, localizedResourcesMap, locale }: MakeswiftClientOptions);
|
|
40
41
|
readSwatch(swatchId: string): Swatch | null;
|
|
41
42
|
fetchSwatch(swatchId: string): Promise<Swatch | null>;
|
|
43
|
+
resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null>;
|
|
42
44
|
readFile(fileId: string): File | null;
|
|
43
45
|
fetchFile(fileId: string): Promise<File | null>;
|
|
46
|
+
resolveFile(fileId: string | undefined): FetchableValue<File | null>;
|
|
44
47
|
readTypography(typographyId: string): Typography | null;
|
|
45
48
|
fetchTypography(typographyId: string): Promise<Typography | null>;
|
|
49
|
+
resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null>;
|
|
46
50
|
readGlobalElement(globalElementId: string): GlobalElement | null;
|
|
47
51
|
fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null>;
|
|
48
52
|
readLocalizedGlobalElement(globalElementId: string): LocalizedGlobalElement | null;
|
|
49
53
|
fetchLocalizedGlobalElement(globalElementId: string): Promise<LocalizedGlobalElement | null>;
|
|
50
54
|
readPagePathnameSlice(pageId: string): PagePathnameSlice | null;
|
|
51
55
|
fetchPagePathnameSlice(pageId: string): Promise<PagePathnameSlice | null>;
|
|
56
|
+
resolvePagePathnameSlice(pageId: string | undefined): FetchableValue<PagePathnameSlice | null>;
|
|
57
|
+
resolveResource<R>(type: APIResourceType, { id, read, fetch, }: {
|
|
58
|
+
id: string | undefined;
|
|
59
|
+
read: (id: string) => R | null;
|
|
60
|
+
fetch: (id: string) => Promise<R | null>;
|
|
61
|
+
}): FetchableValue<R | null>;
|
|
52
62
|
readTable(tableId: string): Table | null;
|
|
53
63
|
fetchTable(tableId: string): Promise<Table | null>;
|
|
54
64
|
createTableRecord(tableId: string, columns: any): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/api/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/api/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,kBAAkB,M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C,CAAC,GAAG,IAAI,CAAC,CAAA;KACzC,GACA,cAAc,CAAC,CAAC,GAAG,IAAI,CAAC;IAc3B,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAQlC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAMlD,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAQrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAQrC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAQ9C,OAAO,CAAC,sBAAsB;IAI9B,sBAAsB,CAAC,EACrB,UAAU,EACV,mBAAmB,GACpB,EAAE;QACD,UAAU,EAAE,MAAM,CAAA;QAClB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAA;KACnC,GAAG,IAAI;CAGT"}
|
|
@@ -48,7 +48,7 @@ declare const Button: import("react").ForwardRefExoticComponent<BaseProps<Elemen
|
|
|
48
48
|
elementKey: string;
|
|
49
49
|
propName: string;
|
|
50
50
|
} | null | undefined;
|
|
51
|
-
block: "center" | "start" | "end";
|
|
51
|
+
block: "center" | "start" | "end" | "nearest";
|
|
52
52
|
};
|
|
53
53
|
} | undefined;
|
|
54
54
|
onClick?: ((event: import("react").MouseEvent<HTMLAnchorElement, MouseEvent>) => unknown) | undefined;
|
|
@@ -84,7 +84,7 @@ declare const Button: import("react").ForwardRefExoticComponent<BaseProps<Elemen
|
|
|
84
84
|
elementKey: string;
|
|
85
85
|
propName: string;
|
|
86
86
|
} | null | undefined;
|
|
87
|
-
block: "center" | "start" | "end";
|
|
87
|
+
block: "center" | "start" | "end" | "nearest";
|
|
88
88
|
};
|
|
89
89
|
} | undefined;
|
|
90
90
|
onClick?: ((event: import("react").MouseEvent<HTMLAnchorElement, MouseEvent>) => unknown) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/shared/Link/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/shared/Link/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAwC,UAAU,EAAE,MAAM,OAAO,CAAA;AAGxE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAKtD,KAAK,SAAS,GAAG;IACf,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAA;CAC5D,CAAA;AAmBD,eAAO,MAAM,IAAI,6PAiDf,CAAA"}
|
|
@@ -2,7 +2,7 @@ import { WidthProperty } from 'csstype';
|
|
|
2
2
|
import { CSSObject } from '@emotion/css';
|
|
3
3
|
import type { ResponsiveValueType as ExtractResponsiveValue } from '@makeswift/controls';
|
|
4
4
|
import type { LengthData, ResponsiveBorderRadiusData, ResponsiveMarginData, ResponsivePaddingData, ResponsiveValue, ResponsiveLengthData, ResponsiveTextStyleData } from '@makeswift/prop-controllers';
|
|
5
|
-
import { FallbackStrategy, Breakpoints } from '
|
|
5
|
+
import { FallbackStrategy, type Breakpoints } from '@makeswift/controls';
|
|
6
6
|
import { PaddingPropertyData } from '../../css/padding';
|
|
7
7
|
import { MarginPropertyData } from '../../css/margin';
|
|
8
8
|
import { BorderRadiusPropertyData } from '../../css/border-radius';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responsive-style.d.ts","sourceRoot":"","sources":["../../../../src/components/utils/responsive-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,KAAK,EAAE,mBAAmB,IAAI,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAExF,OAAO,KAAK,EACV,UAAU,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"responsive-style.d.ts","sourceRoot":"","sources":["../../../../src/components/utils/responsive-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,KAAK,EAAE,mBAAmB,IAAI,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAExF,OAAO,KAAK,EACV,UAAU,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,gBAAgB,EAEhB,KAAK,WAAW,EACjB,MAAM,qBAAqB,CAAA;AAO5B,OAAO,EAAE,mBAAmB,EAA8B,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAA6B,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,wBAAwB,EAAmC,MAAM,yBAAyB,CAAA;AACnG,OAAO,EAAE,kBAAkB,EAA6B,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,OAAO,EAAa,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAC/F,WAAW,EAAE,WA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xB,KAAK,EAAE,uBAAuB,GAAG,SAAS,GACzC,SAAS,CAiCX;AAED,wBAAgB,sBAAsB,CACpC,GAAG,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,GACzD,SAAS,CAEX"}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { type MouseEvent } from 'react';
|
|
2
|
-
import { type DeserializedRecord, LinkDefinition as BaseLinkDefinition } from '@makeswift/controls';
|
|
3
|
-
|
|
3
|
+
import { type DeserializedRecord, LinkDefinition as BaseLinkDefinition, LinkSchema } from '@makeswift/controls';
|
|
4
|
+
type DataType = z.infer<typeof LinkDefinition.schema.data>;
|
|
5
|
+
type ScrollOptions = z.infer<typeof LinkSchema.scrollOptions>;
|
|
6
|
+
type MouseEventType = MouseEvent<Element>;
|
|
7
|
+
export declare function validateElementRef(href: string): string | undefined;
|
|
8
|
+
export declare class LinkDefinition extends BaseLinkDefinition<MouseEventType> {
|
|
4
9
|
static deserialize(data: DeserializedRecord): LinkDefinition;
|
|
10
|
+
resolveOnClick(data: DataType | undefined, href: string, scrollOptions: ScrollOptions | undefined): {
|
|
11
|
+
(event: MouseEvent<Element>): void;
|
|
12
|
+
$scrollOptions: {
|
|
13
|
+
behavior?: "auto" | "smooth" | "instant" | undefined;
|
|
14
|
+
block?: "center" | "start" | "end" | "nearest" | undefined;
|
|
15
|
+
inline?: "center" | "start" | "end" | "nearest" | undefined;
|
|
16
|
+
} | undefined;
|
|
17
|
+
};
|
|
5
18
|
}
|
|
6
19
|
export declare function Link(config?: {
|
|
7
20
|
label?: string;
|
|
8
21
|
}): LinkDefinition;
|
|
22
|
+
export {};
|
|
9
23
|
//# sourceMappingURL=link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/controls/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/controls/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,OAAO,EACL,KAAK,kBAAkB,EACvB,cAAc,IAAI,kBAAkB,EACpC,UAAU,EACX,MAAM,qBAAqB,CAAA;AAE5B,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC1D,KAAK,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AAEzC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,sBAO9C;AAED,qBAAa,cAAe,SAAQ,kBAAkB,CAAC,cAAc,CAAC;IACpE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,cAAc;IAS5D,cAAc,CACZ,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,aAAa,GAAG,SAAS;gBAEhB,WAAW,OAAO,CAAC;;;;;;;CAyB9C;AAED,wBAAgB,IAAI,CAAC,MAAM,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAEhE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { RichTextV1Definition, type DeserializedRecord,
|
|
2
|
+
import { RichTextV1Definition, SendMessage, type DeserializedRecord, type ResourceResolver, type Stylesheet, type Resolvable, type DataType } from '@makeswift/controls';
|
|
3
3
|
import { RichTextControl } from './control';
|
|
4
4
|
declare abstract class BaseDefinition extends RichTextV1Definition<ReactNode, RichTextControl> {
|
|
5
5
|
}
|
|
6
6
|
declare class Definition extends BaseDefinition {
|
|
7
7
|
static deserialize(data: DeserializedRecord): Definition;
|
|
8
|
+
resolveValue(data: DataType<BaseDefinition> | undefined, _resolver: ResourceResolver, _stylesheet: Stylesheet, control?: RichTextControl): Resolvable<ReactNode | undefined>;
|
|
8
9
|
createInstance(sendMessage: SendMessage<any>): RichTextControl;
|
|
9
10
|
}
|
|
10
11
|
export { Definition as RichTextV1Definition, RichTextControl as RichTextV1Control };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-text.d.ts","sourceRoot":"","sources":["../../../../src/controls/rich-text/rich-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"rich-text.d.ts","sourceRoot":"","sources":["../../../../src/controls/rich-text/rich-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,oBAAoB,EACpB,WAAW,EAEX,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAA;AAI5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,uBAAe,cAAe,SAAQ,oBAAoB,CAAC,SAAS,EAAE,eAAe,CAAC;CAAG;AAEzF,cAAM,UAAW,SAAQ,cAAc;IACrC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,UAAU;IAQxD,YAAY,CACV,IAAI,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,SAAS,EAC1C,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,UAAU,EACvB,OAAO,CAAC,EAAE,eAAe,GACxB,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;IAYpC,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC;CAG7C;AAED,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,eAAe,IAAI,iBAAiB,EAAE,CAAA"}
|