@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
|
@@ -28,7 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var use_style_exports = {};
|
|
30
30
|
__export(use_style_exports, {
|
|
31
|
-
|
|
31
|
+
serializedStyleClassName: () => serializedStyleClassName,
|
|
32
|
+
useStyle: () => useStyle,
|
|
33
|
+
useStyles: () => useStyles
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(use_style_exports);
|
|
34
36
|
var import_react = __toESM(require("react"));
|
|
@@ -42,15 +44,29 @@ function useStyle(style) {
|
|
|
42
44
|
const cache = (0, import_root_style_registry.useCache)();
|
|
43
45
|
const serialized = (0, import_serialize.serializeStyles)([style], cache.registered);
|
|
44
46
|
(0, import_utils.registerStyles)(cache, serialized, false);
|
|
45
|
-
|
|
47
|
+
useUniversalInsertionEffect(() => {
|
|
46
48
|
(0, import_utils.insertStyles)(cache, serialized, false);
|
|
47
49
|
});
|
|
50
|
+
return serializedStyleClassName(cache, serialized);
|
|
51
|
+
}
|
|
52
|
+
function useStyles(cache, styles) {
|
|
53
|
+
styles.forEach((s) => (0, import_utils.registerStyles)(cache, s, false));
|
|
54
|
+
useUniversalInsertionEffect(() => {
|
|
55
|
+
styles.forEach((s) => (0, import_utils.insertStyles)(cache, s, false));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function useUniversalInsertionEffect(effect) {
|
|
59
|
+
useInsertionEffect(effect);
|
|
48
60
|
if (isServer)
|
|
49
|
-
(
|
|
61
|
+
effect();
|
|
62
|
+
}
|
|
63
|
+
function serializedStyleClassName(cache, serialized) {
|
|
50
64
|
return `${cache.key}-${serialized.name}`;
|
|
51
65
|
}
|
|
52
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
67
|
0 && (module.exports = {
|
|
54
|
-
|
|
68
|
+
serializedStyleClassName,
|
|
69
|
+
useStyle,
|
|
70
|
+
useStyles
|
|
55
71
|
});
|
|
56
72
|
//# 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGlB,uBAAgC;AAChC,mBAAoE;AAEpE,iCAAyB;AAEzB,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,8BAA8B;AACpC,MAAM,qBAAqB,aAAAA,QAAM,2BAA2B,KAAK,aAAAA,QAAM;AAEhE,SAAS,SAAS,OAA0B;AACjD,QAAM,YAAQ,qCAAS;AACvB,QAAM,iBAAa,kCAAgB,CAAC,KAAK,GAAG,MAAM,UAAU;AAE5D,mCAAe,OAAO,YAAY,KAAK;AAEvC,8BAA4B,MAAM;AAChC,mCAAa,OAAO,YAAY,KAAK;AAAA,EACvC,CAAC;AAED,SAAO,yBAAyB,OAAO,UAAU;AACnD;AAEO,SAAS,UAAU,OAAqB,QAA4B;AACzE,SAAO,QAAQ,WAAK,6BAAe,OAAO,GAAG,KAAK,CAAC;AAEnD,8BAA4B,MAAM;AAChC,WAAO,QAAQ,WAAK,2BAAa,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":["React"]}
|
|
@@ -25,6 +25,7 @@ __export(TypographyPlugin_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(TypographyPlugin_exports);
|
|
27
27
|
var import_slate = require("slate");
|
|
28
|
+
var import_css = require("@emotion/css");
|
|
28
29
|
var import_controls = require("@makeswift/controls");
|
|
29
30
|
var import_clearActiveTypographyStyle = require("./clearActiveTypographyStyle");
|
|
30
31
|
var import_clearDeviceActiveTypography = require("./clearDeviceActiveTypography");
|
|
@@ -126,7 +127,7 @@ function TypographyPlugin() {
|
|
|
126
127
|
...props,
|
|
127
128
|
leaf: {
|
|
128
129
|
...props.leaf,
|
|
129
|
-
className:
|
|
130
|
+
className: (0, import_css.cx)(props.leaf.className, className)
|
|
130
131
|
}
|
|
131
132
|
});
|
|
132
133
|
}
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4E;AAC5E,iBAAmB;AACnB,sB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
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var normalizeTypographyDown_exports = {};
|
|
30
20
|
__export(normalizeTypographyDown_exports, {
|
|
@@ -33,7 +23,7 @@ __export(normalizeTypographyDown_exports, {
|
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(normalizeTypographyDown_exports);
|
|
35
25
|
var import_slate = require("slate");
|
|
36
|
-
var
|
|
26
|
+
var import_controls = require("@makeswift/controls");
|
|
37
27
|
var import__ = require(".");
|
|
38
28
|
function shallowMergeTypographies(commonTypography, typography) {
|
|
39
29
|
const devices = [
|
|
@@ -48,7 +38,7 @@ function shallowMergeTypographies(commonTypography, typography) {
|
|
|
48
38
|
const existingDeviceStyle = typography?.style.find((s) => s.deviceId === deviceId);
|
|
49
39
|
return {
|
|
50
40
|
deviceId,
|
|
51
|
-
value: (0,
|
|
41
|
+
value: (0, import_controls.shallowMerge)(existingDeviceStyle?.value ?? {}, commonDevice?.value ?? {})
|
|
52
42
|
};
|
|
53
43
|
})
|
|
54
44
|
};
|
|
@@ -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 {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,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":";;;;;;;;;;;;;;;AAAA;AAAA;
|
|
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":";;;;;;;;;;;;;;;AAAA;AAAA;AACA,0BAAc,0BADd;AAEA,0BAAc,4BAFd;AAGA,0BAAc,+BAHd;AAIA,0BAAc,2BAJd;AAKA,0BAAc,yBALd;AAMA,0BAAc,iCANd;AAOA,0BAAc,8BAPd;AAQA,0BAAc,+BARd;AASA,0BAAc,oBATd;AAUA,0BAAc,oBAVd;","names":[]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,37 +15,25 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var breakpoints_exports = {};
|
|
30
20
|
__export(breakpoints_exports, {
|
|
31
21
|
DEFAULT_BREAKPOINTS: () => DEFAULT_BREAKPOINTS,
|
|
32
22
|
DefaultBreakpointID: () => DefaultBreakpointID,
|
|
33
|
-
findBreakpointOverride: () => findBreakpointOverride,
|
|
23
|
+
findBreakpointOverride: () => import_controls2.findBreakpointOverride,
|
|
34
24
|
findNextFallback: () => findNextFallback,
|
|
35
|
-
getBaseBreakpoint: () => getBaseBreakpoint,
|
|
25
|
+
getBaseBreakpoint: () => import_controls2.getBaseBreakpoint,
|
|
36
26
|
getBreakpoint: () => getBreakpoint,
|
|
37
27
|
getBreakpointMediaQuery: () => getBreakpointMediaQuery,
|
|
38
28
|
getInitialState: () => getInitialState,
|
|
39
29
|
getViewportStyle: () => getViewportStyle,
|
|
40
|
-
join: () => join,
|
|
41
|
-
mergeOrCoalesceFallbacks: () => mergeOrCoalesceFallbacks,
|
|
42
|
-
mergeResponsiveValues: () => mergeResponsiveValues,
|
|
43
30
|
parseBreakpointsInput: () => parseBreakpointsInput,
|
|
44
|
-
reducer: () => reducer
|
|
45
|
-
shallowMergeFallbacks: () => shallowMergeFallbacks
|
|
31
|
+
reducer: () => reducer
|
|
46
32
|
});
|
|
47
33
|
module.exports = __toCommonJS(breakpoints_exports);
|
|
34
|
+
var import_controls = require("@makeswift/controls");
|
|
48
35
|
var import_actions = require("../actions");
|
|
49
|
-
var
|
|
50
|
-
var import_coalesce = __toESM(require("../../utils/coalesce"));
|
|
36
|
+
var import_controls2 = require("@makeswift/controls");
|
|
51
37
|
const DefaultBreakpointID = {
|
|
52
38
|
Desktop: "desktop",
|
|
53
39
|
Tablet: "tablet",
|
|
@@ -141,60 +127,12 @@ function validateBreakpointsInput(input) {
|
|
|
141
127
|
}
|
|
142
128
|
});
|
|
143
129
|
}
|
|
144
|
-
function sortBreakpoints(breakpoints) {
|
|
145
|
-
return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0));
|
|
146
|
-
}
|
|
147
130
|
const getBreakpoint = (state, breakpointId) => {
|
|
148
131
|
const breakpoint = state.find(({ id }) => id === breakpointId);
|
|
149
132
|
if (breakpoint == null)
|
|
150
133
|
throw new Error(`Unrecognized breakpoint ID: "${breakpointId}".`);
|
|
151
134
|
return breakpoint;
|
|
152
135
|
};
|
|
153
|
-
const getBaseBreakpoint = (breakpoints) => {
|
|
154
|
-
const breakpoint = sortBreakpoints(breakpoints)[0];
|
|
155
|
-
if (breakpoint == null)
|
|
156
|
-
throw new Error(`Cannot get base breakpoint.`);
|
|
157
|
-
return breakpoint;
|
|
158
|
-
};
|
|
159
|
-
function findBreakpointOverride(breakpoints, values = [], deviceId, strategy = defaultStrategy) {
|
|
160
|
-
const value = values.find(({ deviceId: d }) => d === deviceId);
|
|
161
|
-
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));
|
|
162
|
-
return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : void 0;
|
|
163
|
-
}
|
|
164
|
-
function defaultStrategy(value, fallbacks) {
|
|
165
|
-
return value || fallbacks[0];
|
|
166
|
-
}
|
|
167
|
-
function shallowMergeFallbacks(value, fallbacks) {
|
|
168
|
-
return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
|
|
169
|
-
deviceId: a.deviceId || b.deviceId,
|
|
170
|
-
value: (0, import_shallowMerge.default)(a.value, b.value)
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
function mergeOrCoalesce(a, b) {
|
|
174
|
-
if (typeof a === "object" && a !== null && !Array.isArray(a) && typeof b === "object" && b !== null && !Array.isArray(b)) {
|
|
175
|
-
return (0, import_shallowMerge.default)(a, b);
|
|
176
|
-
}
|
|
177
|
-
return (0, import_coalesce.default)(a, b);
|
|
178
|
-
}
|
|
179
|
-
function mergeOrCoalesceFallbacks(value, fallbacks) {
|
|
180
|
-
return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
|
|
181
|
-
deviceId: a.deviceId || b.deviceId,
|
|
182
|
-
value: mergeOrCoalesce(a.value, b.value)
|
|
183
|
-
}));
|
|
184
|
-
}
|
|
185
|
-
function join(breakpoints, responsiveValues, joinFn, strategy) {
|
|
186
|
-
return breakpoints.map(({ id }) => id).map((deviceId) => {
|
|
187
|
-
const value = joinFn(
|
|
188
|
-
responsiveValues.map((responsiveValue) => {
|
|
189
|
-
const deviceValue = responsiveValue && findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy);
|
|
190
|
-
return deviceValue == null ? void 0 : deviceValue.value;
|
|
191
|
-
})
|
|
192
|
-
);
|
|
193
|
-
if (value == null)
|
|
194
|
-
return null;
|
|
195
|
-
return { deviceId, value };
|
|
196
|
-
}).filter((override) => Boolean(override));
|
|
197
|
-
}
|
|
198
136
|
const getBreakpointMediaQuery = (breakpoint) => {
|
|
199
137
|
const parts = ["@media only screen"];
|
|
200
138
|
if (breakpoint.minWidth != null) {
|
|
@@ -213,7 +151,7 @@ const getViewportStyle = (state, deviceId) => {
|
|
|
213
151
|
};
|
|
214
152
|
};
|
|
215
153
|
function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallbackStrategy) {
|
|
216
|
-
const deviceOverride = findBreakpointOverride(
|
|
154
|
+
const deviceOverride = (0, import_controls.findBreakpointOverride)(
|
|
217
155
|
breakpoints,
|
|
218
156
|
value.filter((v) => v.deviceId !== activeDeviceId),
|
|
219
157
|
deviceId,
|
|
@@ -221,20 +159,6 @@ function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallback
|
|
|
221
159
|
);
|
|
222
160
|
return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null;
|
|
223
161
|
}
|
|
224
|
-
const mergeResponsiveValues = (breakpoints, source, override) => {
|
|
225
|
-
const devices = [
|
|
226
|
-
...new Set(
|
|
227
|
-
source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId))
|
|
228
|
-
)
|
|
229
|
-
];
|
|
230
|
-
return devices.map((deviceId) => ({
|
|
231
|
-
deviceId,
|
|
232
|
-
value: {
|
|
233
|
-
...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,
|
|
234
|
-
...(findBreakpointOverride(breakpoints, override, deviceId, (v) => v) || { value: {} }).value
|
|
235
|
-
}
|
|
236
|
-
}));
|
|
237
|
-
};
|
|
238
162
|
// Annotate the CommonJS export names for ESM import in node:
|
|
239
163
|
0 && (module.exports = {
|
|
240
164
|
DEFAULT_BREAKPOINTS,
|
|
@@ -246,11 +170,7 @@ const mergeResponsiveValues = (breakpoints, source, override) => {
|
|
|
246
170
|
getBreakpointMediaQuery,
|
|
247
171
|
getInitialState,
|
|
248
172
|
getViewportStyle,
|
|
249
|
-
join,
|
|
250
|
-
mergeOrCoalesceFallbacks,
|
|
251
|
-
mergeResponsiveValues,
|
|
252
173
|
parseBreakpointsInput,
|
|
253
|
-
reducer
|
|
254
|
-
shallowMergeFallbacks
|
|
174
|
+
reducer
|
|
255
175
|
});
|
|
256
176
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAAoC;AAEpC,0BAAyB;AACzB,sBAAqB;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/E,UAAQ,O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A,IACxF;AAAA,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":["shallowMerge","coalesce"]}
|
|
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAOO;AAEP,qBAAoC;AAEpC,IAAAA,mBASO;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,E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mC;AACzE,QAAM,QAAQ,CAAC,oBAAoB;AAEnC,MAAI,WAAW,YAAY,MAAM;AAC/B,UAAM,KAAK,eAAe,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,qBAAiB;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":["import_controls"]}
|
package/dist/esm/api/react.js
CHANGED
|
@@ -29,6 +29,13 @@ class MakeswiftHostApiClient {
|
|
|
29
29
|
MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId)
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
|
+
resolveSwatch(swatchId) {
|
|
33
|
+
return this.resolveResource(APIResourceType.Swatch, {
|
|
34
|
+
id: swatchId,
|
|
35
|
+
read: (id) => this.readSwatch(id),
|
|
36
|
+
fetch: (id) => this.fetchSwatch(id)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
32
39
|
readFile(fileId) {
|
|
33
40
|
return MakeswiftApiClient.getAPIResource(
|
|
34
41
|
this.makeswiftApiClient.getState(),
|
|
@@ -41,6 +48,13 @@ class MakeswiftHostApiClient {
|
|
|
41
48
|
MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId)
|
|
42
49
|
);
|
|
43
50
|
}
|
|
51
|
+
resolveFile(fileId) {
|
|
52
|
+
return this.resolveResource(APIResourceType.File, {
|
|
53
|
+
id: fileId,
|
|
54
|
+
read: (id) => this.readFile(id),
|
|
55
|
+
fetch: (id) => this.fetchFile(id)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
44
58
|
readTypography(typographyId) {
|
|
45
59
|
return MakeswiftApiClient.getAPIResource(
|
|
46
60
|
this.makeswiftApiClient.getState(),
|
|
@@ -53,6 +67,13 @@ class MakeswiftHostApiClient {
|
|
|
53
67
|
MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId)
|
|
54
68
|
);
|
|
55
69
|
}
|
|
70
|
+
resolveTypography(typographyId) {
|
|
71
|
+
return this.resolveResource(APIResourceType.Typography, {
|
|
72
|
+
id: typographyId,
|
|
73
|
+
read: (id) => this.readTypography(id),
|
|
74
|
+
fetch: (id) => this.fetchTypography(id)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
56
77
|
readGlobalElement(globalElementId) {
|
|
57
78
|
return MakeswiftApiClient.getAPIResource(
|
|
58
79
|
this.makeswiftApiClient.getState(),
|
|
@@ -110,6 +131,30 @@ class MakeswiftHostApiClient {
|
|
|
110
131
|
MakeswiftApiClient.fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.locale)
|
|
111
132
|
);
|
|
112
133
|
}
|
|
134
|
+
resolvePagePathnameSlice(pageId) {
|
|
135
|
+
return this.resolveResource(APIResourceType.PagePathnameSlice, {
|
|
136
|
+
id: pageId,
|
|
137
|
+
read: (id) => this.readPagePathnameSlice(id),
|
|
138
|
+
fetch: (id) => this.fetchPagePathnameSlice(id)
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
resolveResource(type, {
|
|
142
|
+
id,
|
|
143
|
+
read,
|
|
144
|
+
fetch
|
|
145
|
+
}) {
|
|
146
|
+
const _read = () => id != null ? read(id) : null;
|
|
147
|
+
let lastValue = null;
|
|
148
|
+
return {
|
|
149
|
+
name: `${type}:${id}`,
|
|
150
|
+
readStable: () => lastValue = _read(),
|
|
151
|
+
subscribe: (onUpdate) => this.subscribe(() => {
|
|
152
|
+
if (_read() !== lastValue)
|
|
153
|
+
onUpdate();
|
|
154
|
+
}),
|
|
155
|
+
fetch: async () => id != null ? fetch(id) : null
|
|
156
|
+
};
|
|
157
|
+
}
|
|
113
158
|
readTable(tableId) {
|
|
114
159
|
return MakeswiftApiClient.getAPIResource(
|
|
115
160
|
this.makeswiftApiClient.getState(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './graphql/types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type SerializedLocalizedResourcesMap = {\n [resourceId: string]: string | null\n}\n\ntype LocalizedResourcesMap = Map<string, string | null>\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport type MakeswiftClientOptions = {\n uri: string\n cacheData?: CacheData\n localizedResourcesMap?: SerializedLocalizedResourcesMap\n locale?: Intl.Locale\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n private localizedResourcesMap: LocalizedResourcesMap\n private locale: Intl.Locale | undefined\n\n constructor({ uri, cacheData, localizedResourcesMap = {}, locale }: MakeswiftClientOptions) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({ serializedState: cacheData })\n this.subscribe = this.makeswiftApiClient.subscribe\n this.localizedResourcesMap = new Map(Object.entries(localizedResourcesMap))\n this.locale = locale\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId),\n )\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId),\n )\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId),\n )\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.GlobalElement, globalElementId),\n )\n }\n\n readLocalizedGlobalElement(globalElementId: string): LocalizedGlobalElement | null {\n const localizedGlobalElementId = this.getLocalizedResourceId(globalElementId)\n\n if (localizedGlobalElementId == null) return null\n\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n localizedGlobalElementId,\n )\n }\n\n async fetchLocalizedGlobalElement(\n globalElementId: string,\n ): Promise<LocalizedGlobalElement | null> {\n const locale = this.locale\n\n if (locale == null) return null\n\n // If getLocalizedResourceId returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n const noLocalizedResource = this.getLocalizedResourceId(globalElementId) === null\n\n if (noLocalizedResource) return null\n\n // TODO(fikri): We're checking the cache here because the cache hit will fail on fetchAPIResource.\n // This is because in the cache we're saving the ID of the localizedGlobalElementId,\n // but we're reading the cache using the globalElementId.\n // This is very confusing and it can lead to more bugs. We need to refactor how we handle\n // localized global element.\n const cacheResult = this.readLocalizedGlobalElement(globalElementId)\n\n if (cacheResult) return cacheResult\n\n const result = await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n ),\n )\n\n this.setLocalizedResourceId({\n resourceId: globalElementId,\n localizedResourceId: result?.id ?? null,\n })\n\n return result\n }\n\n readPagePathnameSlice(pageId: string): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n )\n }\n\n async fetchPagePathnameSlice(pageId: string): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.locale),\n )\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n\n private getLocalizedResourceId(resourceId: string): string | undefined | null {\n return this.localizedResourcesMap?.get(resourceId)\n }\n\n setLocalizedResourceId({\n resourceId,\n localizedResourceId,\n }: {\n resourceId: string\n localizedResourceId: string | null\n }): void {\n this.localizedResourcesMap.set(resourceId, localizedResourceId)\n }\n}\n"],"mappings":"AAAA,YAAY,wBAAwB;AACpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAwCnC,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACA;AAAA,EAER,YAAY,EAAE,KAAK,WAAW,wBAAwB,CAAC,GAAG,OAAO,GAA2B;AAC1F,SAAK,gBAAgB,IAAI,cAAc,GAAG;AAC1C,SAAK,qBAAqB,mBAAmB,eAAe,EAAE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;AAAA,EACF;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,uBAAuB,YAA+C;AAC5E,WAAO,KAAK,uBAAuB,IAAI,UAAU;AAAA,EACnD;AAAA,EAEA,uBAAuB;AAAA,IACrB;AAAA,IACA;AAAA,EACF,GAGS;AACP,SAAK,sBAAsB,IAAI,YAAY,mBAAmB;AAAA,EAChE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './graphql/types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type SerializedLocalizedResourcesMap = {\n [resourceId: string]: string | null\n}\n\ntype LocalizedResourcesMap = Map<string, string | null>\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport type MakeswiftClientOptions = {\n uri: string\n cacheData?: CacheData\n localizedResourcesMap?: SerializedLocalizedResourcesMap\n locale?: Intl.Locale\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n private localizedResourcesMap: LocalizedResourcesMap\n private locale: Intl.Locale | undefined\n\n constructor({ uri, cacheData, localizedResourcesMap = {}, locale }: MakeswiftClientOptions) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({ serializedState: cacheData })\n this.subscribe = this.makeswiftApiClient.subscribe\n this.localizedResourcesMap = new Map(Object.entries(localizedResourcesMap))\n this.locale = locale\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId),\n )\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId),\n )\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId),\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.GlobalElement, globalElementId),\n )\n }\n\n readLocalizedGlobalElement(globalElementId: string): LocalizedGlobalElement | null {\n const localizedGlobalElementId = this.getLocalizedResourceId(globalElementId)\n\n if (localizedGlobalElementId == null) return null\n\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n localizedGlobalElementId,\n )\n }\n\n async fetchLocalizedGlobalElement(\n globalElementId: string,\n ): Promise<LocalizedGlobalElement | null> {\n const locale = this.locale\n\n if (locale == null) return null\n\n // If getLocalizedResourceId returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n const noLocalizedResource = this.getLocalizedResourceId(globalElementId) === null\n\n if (noLocalizedResource) return null\n\n // TODO(fikri): We're checking the cache here because the cache hit will fail on fetchAPIResource.\n // This is because in the cache we're saving the ID of the localizedGlobalElementId,\n // but we're reading the cache using the globalElementId.\n // This is very confusing and it can lead to more bugs. We need to refactor how we handle\n // localized global element.\n const cacheResult = this.readLocalizedGlobalElement(globalElementId)\n\n if (cacheResult) return cacheResult\n\n const result = await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n ),\n )\n\n this.setLocalizedResourceId({\n resourceId: globalElementId,\n localizedResourceId: result?.id ?? null,\n })\n\n return result\n }\n\n readPagePathnameSlice(pageId: string): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n )\n }\n\n async fetchPagePathnameSlice(pageId: string): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.locale),\n )\n }\n\n resolvePagePathnameSlice(pageId: string | undefined): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice(id),\n fetch: id => this.fetchPagePathnameSlice(id),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n\n private getLocalizedResourceId(resourceId: string): string | undefined | null {\n return this.localizedResourcesMap?.get(resourceId)\n }\n\n setLocalizedResourceId({\n resourceId,\n localizedResourceId,\n }: {\n resourceId: string\n localizedResourceId: string | null\n }): void {\n this.localizedResourcesMap.set(resourceId, localizedResourceId)\n }\n}\n"],"mappings":"AACA,YAAY,wBAAwB;AACpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAwCnC,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACA;AAAA,EAER,YAAY,EAAE,KAAK,WAAW,wBA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AM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,gBAAgB,OAAO,OAAO;AAAA,IACpE;AAAA,EACF;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,uBAAuB,YAA+C;AAC5E,WAAO,KAAK,uBAAuB,IAAI,UAAU;AAAA,EACnD;AAAA,EAEA,uBAAuB;AAAA,IACrB;AAAA,IACA;AAAA,EACF,GAGS;AACP,SAAK,sBAAsB,IAAI,YAAY,mBAAmB;AAAA,EAChE;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
3
|
import { forwardRef } from "react";
|
|
3
|
-
import scrollIntoView from "scroll-into-view-if-needed";
|
|
4
4
|
import NextLink from "next/link";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Link as LinkDef } from "../../../controls/link";
|
|
6
|
+
import { useResolvedValue } from "../../../runtimes/react/hooks/use-resolved-value";
|
|
7
7
|
const isValidHref = (href) => {
|
|
8
8
|
try {
|
|
9
9
|
const bases = ["http://n", "https://n"];
|
|
@@ -15,79 +15,24 @@ const isValidHref = (href) => {
|
|
|
15
15
|
};
|
|
16
16
|
const Link = forwardRef(function Link2({ link, onClick = () => {
|
|
17
17
|
}, ...restOfProps }, ref) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (link) {
|
|
27
|
-
switch (link.type) {
|
|
28
|
-
case "OPEN_PAGE": {
|
|
29
|
-
if (page) {
|
|
30
|
-
useNextLink = true;
|
|
31
|
-
href = `/${page.localizedPathname ?? page.pathname}`;
|
|
32
|
-
}
|
|
33
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
case "OPEN_URL": {
|
|
37
|
-
useNextLink = isValidHref(link.payload.url);
|
|
38
|
-
href = link.payload.url;
|
|
39
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case "SEND_EMAIL": {
|
|
43
|
-
useNextLink = false;
|
|
44
|
-
const { to, subject = "", body = "" } = link.payload;
|
|
45
|
-
if (to != null)
|
|
46
|
-
href = `mailto:${to}?subject=${subject}&body=${body}`;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case "CALL_PHONE": {
|
|
50
|
-
useNextLink = false;
|
|
51
|
-
href = `tel:${link.payload.phoneNumber}`;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case "SCROLL_TO_ELEMENT": {
|
|
55
|
-
useNextLink = false;
|
|
56
|
-
href = `#${elementId ?? ""}`;
|
|
57
|
-
block = link.payload.block;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
throw new RangeError(`Invalid link type "${link.type}."`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
18
|
+
const {
|
|
19
|
+
href,
|
|
20
|
+
target,
|
|
21
|
+
onClick: resolvedOnClick
|
|
22
|
+
} = useResolvedValue(
|
|
23
|
+
link,
|
|
24
|
+
(link2, resourceResolver) => LinkDef().resolveValue(link2, resourceResolver)
|
|
25
|
+
) ?? {};
|
|
64
26
|
function handleClick(event) {
|
|
65
27
|
onClick(event);
|
|
66
28
|
if (event.defaultPrevented)
|
|
67
29
|
return;
|
|
68
30
|
if (event.currentTarget.isContentEditable)
|
|
69
31
|
return event.preventDefault();
|
|
70
|
-
|
|
71
|
-
let hash;
|
|
72
|
-
try {
|
|
73
|
-
if (href != null)
|
|
74
|
-
hash = new URL(`http://www.example.com/${href}`).hash;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error(`Link received invalid href: ${href}`, error);
|
|
77
|
-
}
|
|
78
|
-
if (href != null && hash != null && href === hash) {
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
const view = event.view;
|
|
81
|
-
scrollIntoView(view.document.querySelector(hash), {
|
|
82
|
-
behavior: "smooth",
|
|
83
|
-
block
|
|
84
|
-
});
|
|
85
|
-
if (view.location.hash !== hash)
|
|
86
|
-
view.history.pushState({}, "", hash);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
32
|
+
return resolvedOnClick?.(event);
|
|
89
33
|
}
|
|
90
|
-
|
|
34
|
+
const useNextLink = href != null && link && (link.type === "OPEN_PAGE" || link.type === "OPEN_URL" && isValidHref(link.payload.url));
|
|
35
|
+
if (useNextLink) {
|
|
91
36
|
return /* @__PURE__ */ jsx(
|
|
92
37
|
NextLink,
|
|
93
38
|
{
|