@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
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var image_exports = {};
|
|
20
|
-
__export(image_exports, {
|
|
21
|
-
useImageControlValue: () => useImageControlValue
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(image_exports);
|
|
24
|
-
var import_ts_pattern = require("ts-pattern");
|
|
25
|
-
var import_controls2 = require("../../../controls");
|
|
26
|
-
var import_makeswift_api = require("../hooks/makeswift-api");
|
|
27
|
-
function useImageControlValue(data, definition) {
|
|
28
|
-
const format = definition.config.format ?? import_controls2.Image.Format.URL;
|
|
29
|
-
const fileId = (0, import_ts_pattern.match)(data).with(import_ts_pattern.P.string, (id) => id).with({ type: "makeswift-file" }, ({ id }) => id).otherwise(() => null);
|
|
30
|
-
const file = (0, import_makeswift_api.useFile)(fileId);
|
|
31
|
-
return (0, import_ts_pattern.match)([file, data, format]).with([{ __typename: "File" }, import_ts_pattern.P.any, import_controls2.Image.Format.URL], ([file2]) => file2.publicUrl).with(
|
|
32
|
-
[{ __typename: "File", dimensions: import_ts_pattern.P.not(import_ts_pattern.P.nullish) }, import_ts_pattern.P.any, import_controls2.Image.Format.WithDimensions],
|
|
33
|
-
([file2]) => ({
|
|
34
|
-
url: file2.publicUrl,
|
|
35
|
-
dimensions: file2.dimensions
|
|
36
|
-
})
|
|
37
|
-
).with([import_ts_pattern.P.any, { type: "external-file" }, import_controls2.Image.Format.URL], ([, d]) => d.url).with(
|
|
38
|
-
[
|
|
39
|
-
import_ts_pattern.P.any,
|
|
40
|
-
{ type: "external-file", width: import_ts_pattern.P.number, height: import_ts_pattern.P.number },
|
|
41
|
-
import_controls2.Image.Format.WithDimensions
|
|
42
|
-
],
|
|
43
|
-
([, d]) => ({
|
|
44
|
-
url: d.url,
|
|
45
|
-
dimensions: { width: d.width, height: d.height }
|
|
46
|
-
})
|
|
47
|
-
).otherwise(() => void 0);
|
|
48
|
-
}
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
useImageControlValue
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/image.ts"],"sourcesContent":["import { P, match } from 'ts-pattern'\n\nimport { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { Image, ImageDefinition } from '../../../controls'\n\nimport { useFile } from '../hooks/makeswift-api'\n\nexport function useImageControlValue(\n data: DataType<ImageDefinition> | undefined,\n definition: ImageDefinition,\n): ResolvedValueType<ImageDefinition> {\n const format = definition.config.format ?? Image.Format.URL\n\n const fileId = match(data)\n .with(P.string, id => id)\n .with({ type: 'makeswift-file' }, ({ id }) => id)\n .otherwise(() => null)\n\n const file = useFile(fileId)\n\n return match([file, data, format])\n .with([{ __typename: 'File' }, P.any, Image.Format.URL], ([file]) => file.publicUrl)\n .with(\n [{ __typename: 'File', dimensions: P.not(P.nullish) }, P.any, Image.Format.WithDimensions],\n ([file]) => ({\n url: file.publicUrl,\n dimensions: file.dimensions,\n }),\n )\n .with([P.any, { type: 'external-file' }, Image.Format.URL], ([, d]) => d.url)\n .with(\n [\n P.any,\n { type: 'external-file', width: P.number, height: P.number },\n Image.Format.WithDimensions,\n ],\n ([, d]) => ({\n url: d.url,\n dimensions: { width: d.width, height: d.height },\n }),\n )\n .otherwise(() => undefined)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAyB;AAIzB,IAAAA,mBAAuC;AAEvC,2BAAwB;AAEjB,SAAS,qBACd,MACA,YACoC;AACpC,QAAM,SAAS,WAAW,OAAO,UAAU,uBAAM,OAAO;AAExD,QAAM,aAAS,yBAAM,IAAI,EACtB,KAAK,oBAAE,QAAQ,QAAM,EAAE,EACvB,KAAK,EAAE,MAAM,iBAAiB,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,EAC/C,UAAU,MAAM,IAAI;AAEvB,QAAM,WAAO,8BAAQ,MAAM;AAE3B,aAAO,yBAAM,CAAC,MAAM,MAAM,MAAM,CAAC,EAC9B,KAAK,CAAC,EAAE,YAAY,OAAO,GAAG,oBAAE,KAAK,uBAAM,OAAO,GAAG,GAAG,CAAC,CAACC,KAAI,MAAMA,MAAK,SAAS,EAClF;AAAA,IACC,CAAC,EAAE,YAAY,QAAQ,YAAY,oBAAE,IAAI,oBAAE,OAAO,EAAE,GAAG,oBAAE,KAAK,uBAAM,OAAO,cAAc;AAAA,IACzF,CAAC,CAACA,KAAI,OAAO;AAAA,MACX,KAAKA,MAAK;AAAA,MACV,YAAYA,MAAK;AAAA,IACnB;AAAA,EACF,EACC,KAAK,CAAC,oBAAE,KAAK,EAAE,MAAM,gBAAgB,GAAG,uBAAM,OAAO,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAC3E;AAAA,IACC;AAAA,MACE,oBAAE;AAAA,MACF,EAAE,MAAM,iBAAiB,OAAO,oBAAE,QAAQ,QAAQ,oBAAE,OAAO;AAAA,MAC3D,uBAAM,OAAO;AAAA,IACf;AAAA,IACA,CAAC,CAAC,EAAE,CAAC,OAAO;AAAA,MACV,KAAK,EAAE;AAAA,MACP,YAAY,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAAA,IACjD;AAAA,EACF,EACC,UAAU,MAAM,MAAS;AAC9B;","names":["import_controls","file"]}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var link_exports = {};
|
|
30
|
-
__export(link_exports, {
|
|
31
|
-
useLinkControlValue: () => useLinkControlValue
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(link_exports);
|
|
34
|
-
var import_react = require("react");
|
|
35
|
-
var import_scroll_into_view_if_needed = __toESM(require("scroll-into-view-if-needed"));
|
|
36
|
-
var import__ = require("../");
|
|
37
|
-
var import_makeswift_api = require("../hooks/makeswift-api");
|
|
38
|
-
function useLinkControlValue(link, _definition) {
|
|
39
|
-
const pageId = link && link.type === "OPEN_PAGE" ? link.payload.pageId : null;
|
|
40
|
-
const page = (0, import_makeswift_api.usePagePathnameSlice)(pageId ?? null);
|
|
41
|
-
const elementKey = link?.type === "SCROLL_TO_ELEMENT" ? link.payload.elementIdConfig?.elementKey : null;
|
|
42
|
-
const elementId = (0, import__.useElementId)(elementKey);
|
|
43
|
-
let href = "#";
|
|
44
|
-
let target;
|
|
45
|
-
let block;
|
|
46
|
-
if (link) {
|
|
47
|
-
switch (link.type) {
|
|
48
|
-
case "OPEN_PAGE": {
|
|
49
|
-
if (page)
|
|
50
|
-
href = `/${page.localizedPathname ?? page.pathname}`;
|
|
51
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case "OPEN_URL": {
|
|
55
|
-
href = link.payload.url;
|
|
56
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case "SEND_EMAIL": {
|
|
60
|
-
const { to, subject = "", body = "" } = link.payload;
|
|
61
|
-
if (to != null)
|
|
62
|
-
href = `mailto:${to}?subject=${subject}&body=${body}`;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case "CALL_PHONE": {
|
|
66
|
-
href = `tel:${link.payload.phoneNumber}`;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case "SCROLL_TO_ELEMENT": {
|
|
70
|
-
href = `#${elementId ?? ""}`;
|
|
71
|
-
block = link.payload.block;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
default:
|
|
75
|
-
throw new RangeError(`Invalid link type "${link.type}."`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const handleClick = (0, import_react.useCallback)(
|
|
79
|
-
(event) => {
|
|
80
|
-
if (event.defaultPrevented)
|
|
81
|
-
return;
|
|
82
|
-
if (link && link.type === "SCROLL_TO_ELEMENT") {
|
|
83
|
-
let hash;
|
|
84
|
-
try {
|
|
85
|
-
hash = new URL(`http://www.example.com/${href}`).hash;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(`Link received invalid href: ${href}`, error);
|
|
88
|
-
}
|
|
89
|
-
if (href != null && href === hash) {
|
|
90
|
-
event.preventDefault();
|
|
91
|
-
const view = event.view;
|
|
92
|
-
(0, import_scroll_into_view_if_needed.default)(view.document.querySelector(hash), {
|
|
93
|
-
behavior: "smooth",
|
|
94
|
-
block
|
|
95
|
-
});
|
|
96
|
-
if (view.location.hash !== hash)
|
|
97
|
-
view.history.pushState({}, "", hash);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
[link, href, block]
|
|
102
|
-
);
|
|
103
|
-
const res = (0, import_react.useMemo)(() => ({ href, target, onClick: handleClick }), [href, target, handleClick]);
|
|
104
|
-
return res;
|
|
105
|
-
}
|
|
106
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
-
0 && (module.exports = {
|
|
108
|
-
useLinkControlValue
|
|
109
|
-
});
|
|
110
|
-
//# sourceMappingURL=link.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/link.ts"],"sourcesContent":["import { MouseEvent, useCallback, useMemo } from 'react'\n\nimport { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { LinkDefinition } from '../../../controls'\n\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport { useElementId } from '../'\nimport { usePagePathnameSlice } from '../hooks/makeswift-api'\n\nexport function useLinkControlValue(\n link: DataType<LinkDefinition> | undefined,\n _definition: LinkDefinition,\n): ResolvedValueType<LinkDefinition> {\n const pageId = link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null\n const page = usePagePathnameSlice(pageId ?? null)\n\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n let href = '#'\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) href = `/${page.localizedPathname ?? page.pathname}`\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n href = `#${elementId ?? ''}`\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n const handleClick = useCallback(\n (event: MouseEvent<Element>) => {\n if (event.defaultPrevented) return\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n },\n [link, href, block],\n )\n\n const res = useMemo(() => ({ href, target, onClick: handleClick }), [href, target, handleClick])\n\n return res\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AAMjD,wCAA2B;AAC3B,eAA6B;AAC7B,2BAAqC;AAE9B,SAAS,oBACd,MACA,aACmC;AACnC,QAAM,SAAS,QAAQ,KAAK,SAAS,cAAc,KAAK,QAAQ,SAAS;AACzE,QAAM,WAAO,2CAAqB,UAAU,IAAI;AAEhD,QAAM,aACJ,MAAM,SAAS,sBAAsB,KAAK,QAAQ,iBAAiB,aAAa;AAClF,QAAM,gBAAY,uBAAa,UAAU;AAEzC,MAAI,OAAO;AACX,MAAI;AACJ,MAAI;AAEJ,MAAI,MAAM;AACR,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK,aAAa;AAChB,YAAI;AAAM,iBAAO,IAAI,KAAK,qBAAqB,KAAK,QAAQ;AAE5D,iBAAS,KAAK,QAAQ,eAAe,WAAW;AAEhD;AAAA,MACF;AAAA,MAEA,KAAK,YAAY;AACf,eAAO,KAAK,QAAQ;AAEpB,iBAAS,KAAK,QAAQ,eAAe,WAAW;AAEhD;AAAA,MACF;AAAA,MAEA,KAAK,cAAc;AACjB,cAAM,EAAE,IAAI,UAAU,IAAI,OAAO,GAAG,IAAI,KAAK;AAE7C,YAAI,MAAM;AAAM,iBAAO,UAAU,EAAE,YAAY,OAAO,SAAS,IAAI;AAEnE;AAAA,MACF;AAAA,MAEA,KAAK,cAAc;AACjB,eAAO,OAAO,KAAK,QAAQ,WAAW;AAEtC;AAAA,MACF;AAAA,MAEA,KAAK,qBAAqB;AACxB,eAAO,IAAI,aAAa,EAAE;AAC1B,gBAAQ,KAAK,QAAQ;AAErB;AAAA,MACF;AAAA,MAEA;AACE,cAAM,IAAI,WAAW,sBAAuB,KAAa,IAAI,IAAI;AAAA,IACrE;AAAA,EACF;AAEA,QAAM,kBAAc;AAAA,IAClB,CAAC,UAA+B;AAC9B,UAAI,MAAM;AAAkB;AAE5B,UAAI,QAAQ,KAAK,SAAS,qBAAqB;AAC7C,YAAI;AAEJ,YAAI;AACF,iBAAO,IAAI,IAAI,0BAA0B,IAAI,EAAE,EAAE;AAAA,QACnD,SAAS,OAAO;AACd,kBAAQ,MAAM,+BAA+B,IAAI,IAAI,KAAK;AAAA,QAC5D;AAEA,YAAI,QAAQ,QAAQ,SAAS,MAAM;AACjC,gBAAM,eAAe;AACrB,gBAAM,OAAO,MAAM;AAEnB,gDAAAA,SAAe,KAAK,SAAS,cAAc,IAAI,GAAI;AAAA,YACjD,UAAU;AAAA,YACV;AAAA,UACF,CAAC;AAED,cAAI,KAAK,SAAS,SAAS;AAAM,iBAAK,QAAQ,UAAU,CAAC,GAAG,IAAI,IAAI;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,MAAM,MAAM,KAAK;AAAA,EACpB;AAEA,QAAM,UAAM,sBAAQ,OAAO,EAAE,MAAM,QAAQ,SAAS,YAAY,IAAI,CAAC,MAAM,QAAQ,WAAW,CAAC;AAE/F,SAAO;AACT;","names":["scrollIntoView"]}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var list_exports = {};
|
|
20
|
-
__export(list_exports, {
|
|
21
|
-
ListControlValue: () => ListControlValue
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(list_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_control = require("./control");
|
|
27
|
-
function ListControlValue({
|
|
28
|
-
definition,
|
|
29
|
-
data,
|
|
30
|
-
children,
|
|
31
|
-
control
|
|
32
|
-
}) {
|
|
33
|
-
const [controls, setControls] = (0, import_react.useState)(/* @__PURE__ */ new Map());
|
|
34
|
-
(0, import_react.useEffect)(() => {
|
|
35
|
-
if (control == null || data == null)
|
|
36
|
-
return;
|
|
37
|
-
const childControls = control.childControls(data.map((item) => item.id));
|
|
38
|
-
control.setChildControls(childControls);
|
|
39
|
-
setControls(childControls);
|
|
40
|
-
}, [data, control]);
|
|
41
|
-
return (data ?? []).reduce(
|
|
42
|
-
(renderFn, item) => (listControlValue) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
-
import_control.ControlValue,
|
|
44
|
-
{
|
|
45
|
-
definition: definition.config.type,
|
|
46
|
-
data: item.value,
|
|
47
|
-
control: controls?.get(item.id),
|
|
48
|
-
children: (value) => renderFn([value, ...listControlValue])
|
|
49
|
-
}
|
|
50
|
-
),
|
|
51
|
-
children
|
|
52
|
-
)([]);
|
|
53
|
-
}
|
|
54
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
-
0 && (module.exports = {
|
|
56
|
-
ListControlValue
|
|
57
|
-
});
|
|
58
|
-
//# sourceMappingURL=list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/list.tsx"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nimport { ControlInstance, type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { ListDefinition, ListControl } from '../../../controls'\n\nimport { ControlValue } from './control'\n\ntype ListControlValueProps = {\n definition: ListDefinition\n data: DataType<ListDefinition> | undefined\n children(value: ResolvedValueType<ListDefinition>): JSX.Element\n control: ListControl\n}\n\nexport function ListControlValue({\n definition,\n data,\n children,\n control,\n}: ListControlValueProps): JSX.Element {\n const [controls, setControls] = useState<Map<string, ControlInstance> | undefined>(new Map())\n\n useEffect(() => {\n if (control == null || data == null) return\n\n // This is not ideal because we're setting the itemsControl from the ListControlValue.\n // This is because right now we don't have a subscribeToValue function inside the control.\n // We can improve this by adding the subscribeToValue to createPropController and by\n // moving the setItemsControl to the control itself.\n const childControls = control.childControls(data.map(item => item.id))\n control.setChildControls(childControls)\n setControls(childControls)\n }, [data, control])\n\n return (data ?? []).reduce(\n (renderFn, item) => listControlValue => (\n <ControlValue\n definition={definition.config.type}\n data={item.value}\n control={controls?.get(item.id)}\n >\n {value => renderFn([value, ...listControlValue])}\n </ControlValue>\n ),\n children,\n )([])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCM;AArCN,mBAAoC;AAMpC,qBAA6B;AAStB,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAmD,oBAAI,IAAI,CAAC;AAE5F,8BAAU,MAAM;AACd,QAAI,WAAW,QAAQ,QAAQ;AAAM;AAMrC,UAAM,gBAAgB,QAAQ,cAAc,KAAK,IAAI,UAAQ,KAAK,EAAE,CAAC;AACrE,YAAQ,iBAAiB,aAAa;AACtC,gBAAY,aAAa;AAAA,EAC3B,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,UAAQ,QAAQ,CAAC,GAAG;AAAA,IAClB,CAAC,UAAU,SAAS,sBAClB;AAAA,MAAC;AAAA;AAAA,QACC,YAAY,WAAW,OAAO;AAAA,QAC9B,MAAM,KAAK;AAAA,QACX,SAAS,UAAU,IAAI,KAAK,EAAE;AAAA,QAE7B,qBAAS,SAAS,CAAC,OAAO,GAAG,gBAAgB,CAAC;AAAA;AAAA,IACjD;AAAA,IAEF;AAAA,EACF,EAAE,CAAC,CAAC;AACN;","names":[]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var shape_exports = {};
|
|
20
|
-
__export(shape_exports, {
|
|
21
|
-
ShapeControlValue: () => ShapeControlValue
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(shape_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_control = require("./control");
|
|
26
|
-
function ShapeControlValue({ definition, data, children, control }) {
|
|
27
|
-
return Object.entries(definition.config.type).reduceRight(
|
|
28
|
-
(renderFn, [key, controlDefinition]) => (shapeControlValue) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
29
|
-
import_control.ControlValue,
|
|
30
|
-
{
|
|
31
|
-
definition: controlDefinition,
|
|
32
|
-
data: data?.[key],
|
|
33
|
-
control: control?.child(key),
|
|
34
|
-
children: (value) => renderFn({ ...shapeControlValue, [key]: value })
|
|
35
|
-
}
|
|
36
|
-
),
|
|
37
|
-
children
|
|
38
|
-
)({});
|
|
39
|
-
}
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
ShapeControlValue
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=shape.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/shape.tsx"],"sourcesContent":["import { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { ShapeControl, ShapeDefinition } from '../../../controls'\n\nimport { ControlValue } from './control'\n\ntype ShapeControlValueProps = {\n definition: ShapeDefinition\n data: DataType<ShapeDefinition> | undefined\n children(value: ResolvedValueType<ShapeDefinition>): JSX.Element\n control: ShapeControl\n}\n\nexport function ShapeControlValue({ definition, data, children, control }: ShapeControlValueProps) {\n return Object.entries(definition.config.type).reduceRight(\n (renderFn, [key, controlDefinition]) =>\n shapeControlValue => (\n <ControlValue\n definition={controlDefinition}\n data={data?.[key]}\n control={control?.child(key)}\n >\n {value => renderFn({ ...shapeControlValue, [key]: value })}\n </ControlValue>\n ),\n children,\n )({} as ResolvedValueType<ShapeDefinition>)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBQ;AAbR,qBAA6B;AAStB,SAAS,kBAAkB,EAAE,YAAY,MAAM,UAAU,QAAQ,GAA2B;AACjG,SAAO,OAAO,QAAQ,WAAW,OAAO,IAAI,EAAE;AAAA,IAC5C,CAAC,UAAU,CAAC,KAAK,iBAAiB,MAChC,uBACE;AAAA,MAAC;AAAA;AAAA,QACC,YAAY;AAAA,QACZ,MAAM,OAAO,GAAG;AAAA,QAChB,SAAS,SAAS,MAAM,GAAG;AAAA,QAE1B,qBAAS,SAAS,EAAE,GAAG,mBAAmB,CAAC,GAAG,GAAG,MAAM,CAAC;AAAA;AAAA,IAC3D;AAAA,IAEJ;AAAA,EACF,EAAE,CAAC,CAAuC;AAC5C;","names":[]}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var style_v2_exports = {};
|
|
20
|
-
__export(style_v2_exports, {
|
|
21
|
-
StyleV2ControlValue: () => StyleV2ControlValue,
|
|
22
|
-
useFormattedStyleV2: () => useFormattedStyleV2
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(style_v2_exports);
|
|
25
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
-
var import_use_style = require("../use-style");
|
|
27
|
-
var import_breakpoints = require("../../../state/modules/breakpoints");
|
|
28
|
-
var import_control = require("./control");
|
|
29
|
-
var import_components = require("../components");
|
|
30
|
-
var import_use_breakpoints = require("../hooks/use-breakpoints");
|
|
31
|
-
function useStyleControlCssObject(styleControlData, controlDefinition) {
|
|
32
|
-
const breakpoints = (0, import_use_breakpoints.useBreakpoints)();
|
|
33
|
-
return {
|
|
34
|
-
...controlDefinition.config.getStyle(
|
|
35
|
-
(0, import_breakpoints.findBreakpointOverride)(
|
|
36
|
-
breakpoints,
|
|
37
|
-
styleControlData,
|
|
38
|
-
(0, import_breakpoints.getBaseBreakpoint)(breakpoints).id,
|
|
39
|
-
import_breakpoints.mergeOrCoalesceFallbacks
|
|
40
|
-
)?.value
|
|
41
|
-
),
|
|
42
|
-
...breakpoints.reduce((styles, breakpoint) => {
|
|
43
|
-
return {
|
|
44
|
-
...styles,
|
|
45
|
-
[(0, import_breakpoints.getBreakpointMediaQuery)(breakpoint)]: controlDefinition.config.getStyle(
|
|
46
|
-
(0, import_breakpoints.findBreakpointOverride)(
|
|
47
|
-
breakpoints,
|
|
48
|
-
styleControlData,
|
|
49
|
-
breakpoint.id,
|
|
50
|
-
import_breakpoints.mergeOrCoalesceFallbacks
|
|
51
|
-
)?.value
|
|
52
|
-
)
|
|
53
|
-
};
|
|
54
|
-
}, {})
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function useFormattedStyleV2(styleControlData, controlDefinition) {
|
|
58
|
-
const styles = useStyleControlCssObject(styleControlData, controlDefinition);
|
|
59
|
-
return (0, import_use_style.useStyle)(styles);
|
|
60
|
-
}
|
|
61
|
-
function StyleV2ControlValue({
|
|
62
|
-
definition,
|
|
63
|
-
data,
|
|
64
|
-
children,
|
|
65
|
-
control
|
|
66
|
-
}) {
|
|
67
|
-
return (data ?? []).reduceRight(
|
|
68
|
-
(renderFn, { deviceId, value }) => (responsiveValue) => {
|
|
69
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_control.ControlValue, { definition: definition.config.type, data: value, control: control?.child(), children: (value2) => renderFn([
|
|
70
|
-
{ deviceId, value: value2 },
|
|
71
|
-
...responsiveValue
|
|
72
|
-
]) });
|
|
73
|
-
},
|
|
74
|
-
(value) => {
|
|
75
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
-
import_components.RenderHook,
|
|
77
|
-
{
|
|
78
|
-
hook: useFormattedStyleV2,
|
|
79
|
-
parameters: [value, definition],
|
|
80
|
-
children: (value2) => children(value2)
|
|
81
|
-
},
|
|
82
|
-
definition.controlType
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
)([]);
|
|
86
|
-
}
|
|
87
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
-
0 && (module.exports = {
|
|
89
|
-
StyleV2ControlValue,
|
|
90
|
-
useFormattedStyleV2
|
|
91
|
-
});
|
|
92
|
-
//# sourceMappingURL=style-v2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/style-v2.tsx"],"sourcesContent":["import { CSSObject } from '@emotion/css'\nimport {\n type ResponsiveValue,\n type ResolvedValueType,\n type DataType,\n type DeviceOverride,\n} from '@makeswift/controls'\n\nimport { StyleV2Definition, StyleV2Control } from '../../../controls/style-v2/style-v2'\n\nimport { useStyle } from '../use-style'\nimport {\n findBreakpointOverride,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n mergeOrCoalesceFallbacks,\n} from '../../../state/modules/breakpoints'\n\nimport { ControlValue } from './control'\nimport { RenderHook } from '../components'\nimport { useBreakpoints } from '../hooks/use-breakpoints'\n\nfunction useStyleControlCssObject(\n styleControlData: ResponsiveValue<ResolvedValueType<StyleV2Definition>>,\n controlDefinition: StyleV2Definition,\n): CSSObject {\n const breakpoints = useBreakpoints()\n\n return {\n ...controlDefinition.config.getStyle(\n findBreakpointOverride(\n breakpoints,\n styleControlData,\n getBaseBreakpoint(breakpoints).id,\n mergeOrCoalesceFallbacks,\n )?.value,\n ),\n ...breakpoints.reduce((styles, breakpoint) => {\n return {\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: controlDefinition.config.getStyle(\n findBreakpointOverride(\n breakpoints,\n styleControlData,\n breakpoint.id,\n mergeOrCoalesceFallbacks,\n )?.value,\n ),\n }\n }, {}),\n }\n}\n\nexport function useFormattedStyleV2(\n styleControlData: ResponsiveValue<ResolvedValueType<StyleV2Definition>>,\n controlDefinition: StyleV2Definition,\n): ResolvedValueType<StyleV2Definition> {\n const styles = useStyleControlCssObject(styleControlData, controlDefinition)\n\n return useStyle(styles)\n}\n\ntype ValueProps = {\n definition: StyleV2Definition\n data: DataType<StyleV2Definition> | undefined\n children(value: string): JSX.Element\n control?: StyleV2Control\n}\n\nexport function StyleV2ControlValue({\n definition,\n data,\n children,\n control,\n}: ValueProps): JSX.Element {\n return (data ?? []).reduceRight(\n (renderFn, { deviceId, value }: DeviceOverride<DataType<StyleV2Definition>>) =>\n responsiveValue => {\n return (\n <ControlValue definition={definition.config.type} data={value} control={control?.child()}>\n {value =>\n renderFn([\n { deviceId, value: value as ResolvedValueType<typeof definition.config.type> },\n ...responsiveValue,\n ])\n }\n </ControlValue>\n )\n },\n (value: ResponsiveValue<ResolvedValueType<StyleV2Definition>>) => {\n return (\n <RenderHook\n key={definition.controlType}\n hook={useFormattedStyleV2}\n parameters={[value, definition]}\n >\n {value => children(value)}\n </RenderHook>\n )\n },\n )([])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+EU;AArEV,uBAAyB;AACzB,yBAKO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,6BAA+B;AAE/B,SAAS,yBACP,kBACA,mBACW;AACX,QAAM,kBAAc,uCAAe;AAEnC,SAAO;AAAA,IACL,GAAG,kBAAkB,OAAO;AAAA,UAC1B;AAAA,QACE;AAAA,QACA;AAAA,YACA,sCAAkB,WAAW,EAAE;AAAA,QAC/B;AAAA,MACF,GAAG;AAAA,IACL;AAAA,IACA,GAAG,YAAY,OAAO,CAAC,QAAQ,eAAe;AAC5C,aAAO;AAAA,QACL,GAAG;AAAA,QACH,KAAC,4CAAwB,UAAU,CAAC,GAAG,kBAAkB,OAAO;AAAA,cAC9D;AAAA,YACE;AAAA,YACA;AAAA,YACA,WAAW;AAAA,YACX;AAAA,UACF,GAAG;AAAA,QACL;AAAA,MACF;AAAA,IACF,GAAG,CAAC,CAAC;AAAA,EACP;AACF;AAEO,SAAS,oBACd,kBACA,mBACsC;AACtC,QAAM,SAAS,yBAAyB,kBAAkB,iBAAiB;AAE3E,aAAO,2BAAS,MAAM;AACxB;AASO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4B;AAC1B,UAAQ,QAAQ,CAAC,GAAG;AAAA,IAClB,CAAC,UAAU,EAAE,UAAU,MAAM,MAC3B,qBAAmB;AACjB,aACE,4CAAC,+BAAa,YAAY,WAAW,OAAO,MAAM,MAAM,OAAO,SAAS,SAAS,MAAM,GACpF,WAAAA,WACC,SAAS;AAAA,QACP,EAAE,UAAU,OAAOA,OAA0D;AAAA,QAC7E,GAAG;AAAA,MACL,CAAC,GAEL;AAAA,IAEJ;AAAA,IACF,CAAC,UAAiE;AAChE,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,MAAM;AAAA,UACN,YAAY,CAAC,OAAO,UAAU;AAAA,UAE7B,WAAAA,WAAS,SAASA,MAAK;AAAA;AAAA,QAJnB,WAAW;AAAA,MAKlB;AAAA,IAEJ;AAAA,EACF,EAAE,CAAC,CAAC;AACN;","names":["value"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/coalesce.ts"],"sourcesContent":["const coalesce = <T>(...args: Array<T>): T => {\n let i: number\n\n for (i = 0; i < args.length - 1; i += 1) {\n if (args[i] != null) return args[i]\n }\n\n return args[i]\n}\n\nexport default coalesce\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,WAAW,IAAO,SAAsB;AAC5C,MAAI;AAEJ,OAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG;AACvC,QAAI,KAAK,CAAC,KAAK;AAAM,aAAO,KAAK,CAAC;AAAA,EACpC;AAEA,SAAO,KAAK,CAAC;AACf;AAEA,IAAO,mBAAQ;","names":[]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var shallowMerge_exports = {};
|
|
30
|
-
__export(shallowMerge_exports, {
|
|
31
|
-
default: () => shallowMerge
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(shallowMerge_exports);
|
|
34
|
-
var import_keys = __toESM(require("./keys"));
|
|
35
|
-
var import_coalesce = __toESM(require("./coalesce"));
|
|
36
|
-
function shallowMerge(a, b) {
|
|
37
|
-
const bKeys = (0, import_keys.default)(b);
|
|
38
|
-
const merged = { ...a };
|
|
39
|
-
bKeys.forEach((key) => {
|
|
40
|
-
merged[key] = (0, import_coalesce.default)(merged[key], b[key]);
|
|
41
|
-
});
|
|
42
|
-
return merged;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=shallowMerge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/shallowMerge.ts"],"sourcesContent":["import keys from './keys'\nimport coalesce from './coalesce'\n\nexport default function shallowMerge<\n A extends Record<string, unknown>,\n B extends Record<string, unknown>,\n>(a: A, b: B): A & B {\n const bKeys = keys(b)\n const merged = { ...a } as A & B\n\n bKeys.forEach(key => {\n // @ts-expect-error: `coalesce` returns `null | undefined` regardless of input guarantees.\n merged[key] = coalesce(merged[key], b[key])\n })\n\n return merged\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,sBAAqB;AAEN,SAAR,aAGL,GAAM,GAAa;AACnB,QAAM,YAAQ,YAAAA,SAAK,CAAC;AACpB,QAAM,SAAS,EAAE,GAAG,EAAE;AAEtB,QAAM,QAAQ,SAAO;AAEnB,WAAO,GAAG,QAAI,gBAAAC,SAAS,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC;AAAA,EAC5C,CAAC;AAED,SAAO;AACT;","names":["keys","coalesce"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Color from "color";
|
|
2
|
-
import { useSwatch } from "../hooks/makeswift-api";
|
|
3
|
-
function useColorValue(data, definition) {
|
|
4
|
-
const swatchId = data?.swatchId ?? null;
|
|
5
|
-
const swatch = useSwatch(swatchId);
|
|
6
|
-
const alpha = data?.alpha ?? 1;
|
|
7
|
-
if (swatch == null) {
|
|
8
|
-
const { defaultValue } = definition.config;
|
|
9
|
-
if (defaultValue === void 0)
|
|
10
|
-
return void 0;
|
|
11
|
-
let defaultColor;
|
|
12
|
-
try {
|
|
13
|
-
defaultColor = Color(definition.config.defaultValue);
|
|
14
|
-
} catch {
|
|
15
|
-
defaultColor = Color();
|
|
16
|
-
}
|
|
17
|
-
return defaultColor.rgb().string();
|
|
18
|
-
}
|
|
19
|
-
return Color({ h: swatch.hue, s: swatch.saturation, l: swatch.lightness }).alpha(alpha).rgb().string();
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
useColorValue
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=color.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/color.ts"],"sourcesContent":["import Color from 'color'\n\nimport { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { ColorDefinition } from '../../../controls'\n\nimport { useSwatch } from '../hooks/makeswift-api'\n\nexport function useColorValue(\n data: DataType<ColorDefinition> | undefined,\n definition: ColorDefinition,\n): ResolvedValueType<ColorDefinition> {\n const swatchId = data?.swatchId ?? null\n const swatch = useSwatch(swatchId)\n const alpha = data?.alpha ?? 1\n\n if (swatch == null) {\n const { defaultValue } = definition.config\n\n if (defaultValue === undefined) return undefined\n\n let defaultColor\n try {\n defaultColor = Color(definition.config.defaultValue)\n } catch {\n defaultColor = Color()\n }\n\n return defaultColor.rgb().string()\n }\n\n return Color({ h: swatch.hue, s: swatch.saturation, l: swatch.lightness })\n .alpha(alpha)\n .rgb()\n .string()\n}\n"],"mappings":"AAAA,OAAO,WAAW;AAMlB,SAAS,iBAAiB;AAEnB,SAAS,cACd,MACA,YACoC;AACpC,QAAM,WAAW,MAAM,YAAY;AACnC,QAAM,SAAS,UAAU,QAAQ;AACjC,QAAM,QAAQ,MAAM,SAAS;AAE7B,MAAI,UAAU,MAAM;AAClB,UAAM,EAAE,aAAa,IAAI,WAAW;AAEpC,QAAI,iBAAiB;AAAW,aAAO;AAEvC,QAAI;AACJ,QAAI;AACF,qBAAe,MAAM,WAAW,OAAO,YAAY;AAAA,IACrD,QAAQ;AACN,qBAAe,MAAM;AAAA,IACvB;AAEA,WAAO,aAAa,IAAI,EAAE,OAAO;AAAA,EACnC;AAEA,SAAO,MAAM,EAAE,GAAG,OAAO,KAAK,GAAG,OAAO,YAAY,GAAG,OAAO,UAAU,CAAC,EACtE,MAAM,KAAK,EACX,IAAI,EACJ,OAAO;AACZ;","names":[]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { P, match } from "ts-pattern";
|
|
2
|
-
import { Image } from "../../../controls";
|
|
3
|
-
import { useFile } from "../hooks/makeswift-api";
|
|
4
|
-
function useImageControlValue(data, definition) {
|
|
5
|
-
const format = definition.config.format ?? Image.Format.URL;
|
|
6
|
-
const fileId = match(data).with(P.string, (id) => id).with({ type: "makeswift-file" }, ({ id }) => id).otherwise(() => null);
|
|
7
|
-
const file = useFile(fileId);
|
|
8
|
-
return match([file, data, format]).with([{ __typename: "File" }, P.any, Image.Format.URL], ([file2]) => file2.publicUrl).with(
|
|
9
|
-
[{ __typename: "File", dimensions: P.not(P.nullish) }, P.any, Image.Format.WithDimensions],
|
|
10
|
-
([file2]) => ({
|
|
11
|
-
url: file2.publicUrl,
|
|
12
|
-
dimensions: file2.dimensions
|
|
13
|
-
})
|
|
14
|
-
).with([P.any, { type: "external-file" }, Image.Format.URL], ([, d]) => d.url).with(
|
|
15
|
-
[
|
|
16
|
-
P.any,
|
|
17
|
-
{ type: "external-file", width: P.number, height: P.number },
|
|
18
|
-
Image.Format.WithDimensions
|
|
19
|
-
],
|
|
20
|
-
([, d]) => ({
|
|
21
|
-
url: d.url,
|
|
22
|
-
dimensions: { width: d.width, height: d.height }
|
|
23
|
-
})
|
|
24
|
-
).otherwise(() => void 0);
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
useImageControlValue
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/image.ts"],"sourcesContent":["import { P, match } from 'ts-pattern'\n\nimport { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { Image, ImageDefinition } from '../../../controls'\n\nimport { useFile } from '../hooks/makeswift-api'\n\nexport function useImageControlValue(\n data: DataType<ImageDefinition> | undefined,\n definition: ImageDefinition,\n): ResolvedValueType<ImageDefinition> {\n const format = definition.config.format ?? Image.Format.URL\n\n const fileId = match(data)\n .with(P.string, id => id)\n .with({ type: 'makeswift-file' }, ({ id }) => id)\n .otherwise(() => null)\n\n const file = useFile(fileId)\n\n return match([file, data, format])\n .with([{ __typename: 'File' }, P.any, Image.Format.URL], ([file]) => file.publicUrl)\n .with(\n [{ __typename: 'File', dimensions: P.not(P.nullish) }, P.any, Image.Format.WithDimensions],\n ([file]) => ({\n url: file.publicUrl,\n dimensions: file.dimensions,\n }),\n )\n .with([P.any, { type: 'external-file' }, Image.Format.URL], ([, d]) => d.url)\n .with(\n [\n P.any,\n { type: 'external-file', width: P.number, height: P.number },\n Image.Format.WithDimensions,\n ],\n ([, d]) => ({\n url: d.url,\n dimensions: { width: d.width, height: d.height },\n }),\n )\n .otherwise(() => undefined)\n}\n"],"mappings":"AAAA,SAAS,GAAG,aAAa;AAIzB,SAAS,aAA8B;AAEvC,SAAS,eAAe;AAEjB,SAAS,qBACd,MACA,YACoC;AACpC,QAAM,SAAS,WAAW,OAAO,UAAU,MAAM,OAAO;AAExD,QAAM,SAAS,MAAM,IAAI,EACtB,KAAK,EAAE,QAAQ,QAAM,EAAE,EACvB,KAAK,EAAE,MAAM,iBAAiB,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,EAC/C,UAAU,MAAM,IAAI;AAEvB,QAAM,OAAO,QAAQ,MAAM;AAE3B,SAAO,MAAM,CAAC,MAAM,MAAM,MAAM,CAAC,EAC9B,KAAK,CAAC,EAAE,YAAY,OAAO,GAAG,EAAE,KAAK,MAAM,OAAO,GAAG,GAAG,CAAC,CAACA,KAAI,MAAMA,MAAK,SAAS,EAClF;AAAA,IACC,CAAC,EAAE,YAAY,QAAQ,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,MAAM,OAAO,cAAc;AAAA,IACzF,CAAC,CAACA,KAAI,OAAO;AAAA,MACX,KAAKA,MAAK;AAAA,MACV,YAAYA,MAAK;AAAA,IACnB;AAAA,EACF,EACC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,gBAAgB,GAAG,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAC3E;AAAA,IACC;AAAA,MACE,EAAE;AAAA,MACF,EAAE,MAAM,iBAAiB,OAAO,EAAE,QAAQ,QAAQ,EAAE,OAAO;AAAA,MAC3D,MAAM,OAAO;AAAA,IACf;AAAA,IACA,CAAC,CAAC,EAAE,CAAC,OAAO;AAAA,MACV,KAAK,EAAE;AAAA,MACP,YAAY,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAAA,IACjD;AAAA,EACF,EACC,UAAU,MAAM,MAAS;AAC9B;","names":["file"]}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from "react";
|
|
2
|
-
import scrollIntoView from "scroll-into-view-if-needed";
|
|
3
|
-
import { useElementId } from "../";
|
|
4
|
-
import { usePagePathnameSlice } from "../hooks/makeswift-api";
|
|
5
|
-
function useLinkControlValue(link, _definition) {
|
|
6
|
-
const pageId = link && link.type === "OPEN_PAGE" ? link.payload.pageId : null;
|
|
7
|
-
const page = usePagePathnameSlice(pageId ?? null);
|
|
8
|
-
const elementKey = link?.type === "SCROLL_TO_ELEMENT" ? link.payload.elementIdConfig?.elementKey : null;
|
|
9
|
-
const elementId = useElementId(elementKey);
|
|
10
|
-
let href = "#";
|
|
11
|
-
let target;
|
|
12
|
-
let block;
|
|
13
|
-
if (link) {
|
|
14
|
-
switch (link.type) {
|
|
15
|
-
case "OPEN_PAGE": {
|
|
16
|
-
if (page)
|
|
17
|
-
href = `/${page.localizedPathname ?? page.pathname}`;
|
|
18
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
case "OPEN_URL": {
|
|
22
|
-
href = link.payload.url;
|
|
23
|
-
target = link.payload.openInNewTab ? "_blank" : "_self";
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
case "SEND_EMAIL": {
|
|
27
|
-
const { to, subject = "", body = "" } = link.payload;
|
|
28
|
-
if (to != null)
|
|
29
|
-
href = `mailto:${to}?subject=${subject}&body=${body}`;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
case "CALL_PHONE": {
|
|
33
|
-
href = `tel:${link.payload.phoneNumber}`;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
case "SCROLL_TO_ELEMENT": {
|
|
37
|
-
href = `#${elementId ?? ""}`;
|
|
38
|
-
block = link.payload.block;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
default:
|
|
42
|
-
throw new RangeError(`Invalid link type "${link.type}."`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const handleClick = useCallback(
|
|
46
|
-
(event) => {
|
|
47
|
-
if (event.defaultPrevented)
|
|
48
|
-
return;
|
|
49
|
-
if (link && link.type === "SCROLL_TO_ELEMENT") {
|
|
50
|
-
let hash;
|
|
51
|
-
try {
|
|
52
|
-
hash = new URL(`http://www.example.com/${href}`).hash;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error(`Link received invalid href: ${href}`, error);
|
|
55
|
-
}
|
|
56
|
-
if (href != null && href === hash) {
|
|
57
|
-
event.preventDefault();
|
|
58
|
-
const view = event.view;
|
|
59
|
-
scrollIntoView(view.document.querySelector(hash), {
|
|
60
|
-
behavior: "smooth",
|
|
61
|
-
block
|
|
62
|
-
});
|
|
63
|
-
if (view.location.hash !== hash)
|
|
64
|
-
view.history.pushState({}, "", hash);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
[link, href, block]
|
|
69
|
-
);
|
|
70
|
-
const res = useMemo(() => ({ href, target, onClick: handleClick }), [href, target, handleClick]);
|
|
71
|
-
return res;
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
useLinkControlValue
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=link.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/link.ts"],"sourcesContent":["import { MouseEvent, useCallback, useMemo } from 'react'\n\nimport { type DataType, type ResolvedValueType } from '@makeswift/controls'\n\nimport { LinkDefinition } from '../../../controls'\n\nimport scrollIntoView from 'scroll-into-view-if-needed'\nimport { useElementId } from '../'\nimport { usePagePathnameSlice } from '../hooks/makeswift-api'\n\nexport function useLinkControlValue(\n link: DataType<LinkDefinition> | undefined,\n _definition: LinkDefinition,\n): ResolvedValueType<LinkDefinition> {\n const pageId = link && link.type === 'OPEN_PAGE' ? link.payload.pageId : null\n const page = usePagePathnameSlice(pageId ?? null)\n\n const elementKey =\n link?.type === 'SCROLL_TO_ELEMENT' ? link.payload.elementIdConfig?.elementKey : null\n const elementId = useElementId(elementKey)\n\n let href = '#'\n let target: '_blank' | '_self' | undefined\n let block: 'start' | 'center' | 'end' | undefined\n\n if (link) {\n switch (link.type) {\n case 'OPEN_PAGE': {\n if (page) href = `/${page.localizedPathname ?? page.pathname}`\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'OPEN_URL': {\n href = link.payload.url\n\n target = link.payload.openInNewTab ? '_blank' : '_self'\n\n break\n }\n\n case 'SEND_EMAIL': {\n const { to, subject = '', body = '' } = link.payload\n\n if (to != null) href = `mailto:${to}?subject=${subject}&body=${body}`\n\n break\n }\n\n case 'CALL_PHONE': {\n href = `tel:${link.payload.phoneNumber}`\n\n break\n }\n\n case 'SCROLL_TO_ELEMENT': {\n href = `#${elementId ?? ''}`\n block = link.payload.block\n\n break\n }\n\n default:\n throw new RangeError(`Invalid link type \"${(link as any).type}.\"`)\n }\n }\n\n const handleClick = useCallback(\n (event: MouseEvent<Element>) => {\n if (event.defaultPrevented) return\n\n if (link && link.type === 'SCROLL_TO_ELEMENT') {\n let hash: string | undefined\n\n try {\n hash = new URL(`http://www.example.com/${href}`).hash\n } catch (error) {\n console.error(`Link received invalid href: ${href}`, error)\n }\n\n if (href != null && href === hash) {\n event.preventDefault()\n const view = event.view as unknown as Window\n\n scrollIntoView(view.document.querySelector(hash)!, {\n behavior: 'smooth',\n block,\n })\n\n if (view.location.hash !== hash) view.history.pushState({}, '', hash)\n }\n }\n },\n [link, href, block],\n )\n\n const res = useMemo(() => ({ href, target, onClick: handleClick }), [href, target, handleClick])\n\n return res\n}\n"],"mappings":"AAAA,SAAqB,aAAa,eAAe;AAMjD,OAAO,oBAAoB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AAE9B,SAAS,oBACd,MACA,aACmC;AACnC,QAAM,SAAS,QAAQ,KAAK,SAAS,cAAc,KAAK,QAAQ,SAAS;AACzE,QAAM,OAAO,qBAAqB,UAAU,IAAI;AAEhD,QAAM,aACJ,MAAM,SAAS,sBAAsB,KAAK,QAAQ,iBAAiB,aAAa;AAClF,QAAM,YAAY,aAAa,UAAU;AAEzC,MAAI,OAAO;AACX,MAAI;AACJ,MAAI;AAEJ,MAAI,MAAM;AACR,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK,aAAa;AAChB,YAAI;AAAM,iBAAO,IAAI,KAAK,qBAAqB,KAAK,QAAQ;AAE5D,iBAAS,KAAK,QAAQ,eAAe,WAAW;AAEhD;AAAA,MACF;AAAA,MAEA,KAAK,YAAY;AACf,eAAO,KAAK,QAAQ;AAEpB,iBAAS,KAAK,QAAQ,eAAe,WAAW;AAEhD;AAAA,MACF;AAAA,MAEA,KAAK,cAAc;AACjB,cAAM,EAAE,IAAI,UAAU,IAAI,OAAO,GAAG,IAAI,KAAK;AAE7C,YAAI,MAAM;AAAM,iBAAO,UAAU,EAAE,YAAY,OAAO,SAAS,IAAI;AAEnE;AAAA,MACF;AAAA,MAEA,KAAK,cAAc;AACjB,eAAO,OAAO,KAAK,QAAQ,WAAW;AAEtC;AAAA,MACF;AAAA,MAEA,KAAK,qBAAqB;AACxB,eAAO,IAAI,aAAa,EAAE;AAC1B,gBAAQ,KAAK,QAAQ;AAErB;AAAA,MACF;AAAA,MAEA;AACE,cAAM,IAAI,WAAW,sBAAuB,KAAa,IAAI,IAAI;AAAA,IACrE;AAAA,EACF;AAEA,QAAM,cAAc;AAAA,IAClB,CAAC,UAA+B;AAC9B,UAAI,MAAM;AAAkB;AAE5B,UAAI,QAAQ,KAAK,SAAS,qBAAqB;AAC7C,YAAI;AAEJ,YAAI;AACF,iBAAO,IAAI,IAAI,0BAA0B,IAAI,EAAE,EAAE;AAAA,QACnD,SAAS,OAAO;AACd,kBAAQ,MAAM,+BAA+B,IAAI,IAAI,KAAK;AAAA,QAC5D;AAEA,YAAI,QAAQ,QAAQ,SAAS,MAAM;AACjC,gBAAM,eAAe;AACrB,gBAAM,OAAO,MAAM;AAEnB,yBAAe,KAAK,SAAS,cAAc,IAAI,GAAI;AAAA,YACjD,UAAU;AAAA,YACV;AAAA,UACF,CAAC;AAED,cAAI,KAAK,SAAS,SAAS;AAAM,iBAAK,QAAQ,UAAU,CAAC,GAAG,IAAI,IAAI;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,MAAM,MAAM,KAAK;AAAA,EACpB;AAEA,QAAM,MAAM,QAAQ,OAAO,EAAE,MAAM,QAAQ,SAAS,YAAY,IAAI,CAAC,MAAM,QAAQ,WAAW,CAAC;AAE/F,SAAO;AACT;","names":[]}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { ControlValue } from "./control";
|
|
4
|
-
function ListControlValue({
|
|
5
|
-
definition,
|
|
6
|
-
data,
|
|
7
|
-
children,
|
|
8
|
-
control
|
|
9
|
-
}) {
|
|
10
|
-
const [controls, setControls] = useState(/* @__PURE__ */ new Map());
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (control == null || data == null)
|
|
13
|
-
return;
|
|
14
|
-
const childControls = control.childControls(data.map((item) => item.id));
|
|
15
|
-
control.setChildControls(childControls);
|
|
16
|
-
setControls(childControls);
|
|
17
|
-
}, [data, control]);
|
|
18
|
-
return (data ?? []).reduce(
|
|
19
|
-
(renderFn, item) => (listControlValue) => /* @__PURE__ */ jsx(
|
|
20
|
-
ControlValue,
|
|
21
|
-
{
|
|
22
|
-
definition: definition.config.type,
|
|
23
|
-
data: item.value,
|
|
24
|
-
control: controls?.get(item.id),
|
|
25
|
-
children: (value) => renderFn([value, ...listControlValue])
|
|
26
|
-
}
|
|
27
|
-
),
|
|
28
|
-
children
|
|
29
|
-
)([]);
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
ListControlValue
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=list.js.map
|