@plasmicapp/react-web 0.2.112 → 0.2.113
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/LICENSE.md +21 -0
- package/dist/all.d.ts +36 -16
- package/dist/common.d.ts +3 -3
- package/dist/index-common.d.ts +3 -2
- package/dist/react-web.cjs.development.js +52 -31
- package/dist/react-web.cjs.development.js.map +1 -1
- package/dist/react-web.cjs.production.min.js +1 -1
- package/dist/react-web.cjs.production.min.js.map +1 -1
- package/dist/react-web.esm.js +41 -31
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/ssr.d.ts +1 -0
- package/package.json +4 -3
- package/skinny/dist/{collection-utils-57c273dc.js → collection-utils-43f97262.js} +14 -13
- package/skinny/dist/collection-utils-43f97262.js.map +1 -0
- package/skinny/dist/{common-182a0b0c.js → common-9ebe374e.js} +1 -1
- package/skinny/dist/common-9ebe374e.js.map +1 -0
- package/skinny/dist/common.d.ts +3 -3
- package/skinny/dist/index-common.d.ts +3 -2
- package/skinny/dist/index.js +40 -42
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/button/index.js +7 -7
- package/skinny/dist/plume/button/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +17 -17
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/menu/index.js +38 -39
- package/skinny/dist/plume/menu/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/index.js +22 -22
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/select/index.js +41 -43
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +16 -16
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/plume/text-input/index.js +10 -10
- package/skinny/dist/plume/text-input/index.js.map +1 -1
- package/skinny/dist/plume/triggered-overlay/index.js +14 -14
- package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
- package/skinny/dist/{plume-utils-d2476af1.js → plume-utils-d9811bf3.js} +2 -2
- package/skinny/dist/{plume-utils-27cd384f.js.map → plume-utils-d9811bf3.js.map} +1 -1
- package/skinny/dist/{props-utils-cac0cccf.js → props-utils-228208e6.js} +2 -2
- package/skinny/dist/{props-utils-7c02c0a8.js.map → props-utils-228208e6.js.map} +1 -1
- package/skinny/dist/{react-utils-35cb2a4e.js → react-utils-7bc53870.js} +6 -6
- package/skinny/dist/{react-utils-35cb2a4e.js.map → react-utils-7bc53870.js.map} +1 -1
- package/skinny/dist/render/PlasmicHead/index.js +6 -6
- package/skinny/dist/render/PlasmicImg/index.js +27 -27
- package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
- package/skinny/dist/render/ssr.d.ts +1 -0
- package/skinny/dist/{ssr-d3321868.js → ssr-b16a1854.js} +10 -9
- package/skinny/dist/ssr-b16a1854.js.map +1 -0
- package/skinny/dist/collection-utils-2745acd4.js +0 -238
- package/skinny/dist/collection-utils-2745acd4.js.map +0 -1
- package/skinny/dist/collection-utils-42de4441.js +0 -244
- package/skinny/dist/collection-utils-42de4441.js.map +0 -1
- package/skinny/dist/collection-utils-57c273dc.js.map +0 -1
- package/skinny/dist/collection-utils-bf37b8fb.js +0 -238
- package/skinny/dist/collection-utils-bf37b8fb.js.map +0 -1
- package/skinny/dist/common-182a0b0c.js.map +0 -1
- package/skinny/dist/common-98719219.js +0 -68
- package/skinny/dist/common-98719219.js.map +0 -1
- package/skinny/dist/common-9efbae57.js +0 -201
- package/skinny/dist/common-9efbae57.js.map +0 -1
- package/skinny/dist/context-4ca6f5cd.js +0 -6
- package/skinny/dist/context-4ca6f5cd.js.map +0 -1
- package/skinny/dist/plume-utils-1e225de5.js +0 -25
- package/skinny/dist/plume-utils-1e225de5.js.map +0 -1
- package/skinny/dist/plume-utils-27cd384f.js +0 -35
- package/skinny/dist/plume-utils-623b91cc.js +0 -35
- package/skinny/dist/plume-utils-623b91cc.js.map +0 -1
- package/skinny/dist/plume-utils-d2476af1.js.map +0 -1
- package/skinny/dist/props-utils-7c02c0a8.js +0 -8
- package/skinny/dist/props-utils-b2ad4997.js +0 -8
- package/skinny/dist/props-utils-b2ad4997.js.map +0 -1
- package/skinny/dist/props-utils-c60d3105.js +0 -8
- package/skinny/dist/props-utils-c60d3105.js.map +0 -1
- package/skinny/dist/props-utils-cac0cccf.js.map +0 -1
- package/skinny/dist/react-utils-6050fadc.js +0 -201
- package/skinny/dist/react-utils-6050fadc.js.map +0 -1
- package/skinny/dist/react-utils-7c01e440.js +0 -172
- package/skinny/dist/react-utils-7c01e440.js.map +0 -1
- package/skinny/dist/react-utils-b5dc6320.js +0 -155
- package/skinny/dist/react-utils-b5dc6320.js.map +0 -1
- package/skinny/dist/render/PlasmicHead.d.ts +0 -35
- package/skinny/dist/ssr-68913b60.js +0 -107
- package/skinny/dist/ssr-68913b60.js.map +0 -1
- package/skinny/dist/ssr-9ebd98ed.js +0 -158
- package/skinny/dist/ssr-9ebd98ed.js.map +0 -1
- package/skinny/dist/ssr-d3321868.js.map +0 -1
- package/skinny/dist/ssr-f4053cdd.js +0 -110
- package/skinny/dist/ssr-f4053cdd.js.map +0 -1
- package/skinny/dist/ssr-fbf922f6.js +0 -108
- package/skinny/dist/ssr-fbf922f6.js.map +0 -1
- package/skinny/dist/states/valtio copy.d.ts +0 -15
- package/skinny/dist/stories/UseDollarState.test.d.ts +0 -11
- package/skinny/dist/stories/UseDollarState2.stories.d.ts +0 -7
- package/skinny/dist/tslib.es6-d26ffe68.js +0 -132
- package/skinny/dist/tslib.es6-d26ffe68.js.map +0 -1
|
@@ -39,21 +39,21 @@ var plasmicHeadMeta = {
|
|
|
39
39
|
props: {
|
|
40
40
|
title: {
|
|
41
41
|
type: "string",
|
|
42
|
-
displayName: "Title"
|
|
42
|
+
displayName: "Title"
|
|
43
43
|
},
|
|
44
44
|
description: {
|
|
45
45
|
type: "string",
|
|
46
|
-
displayName: "Description"
|
|
46
|
+
displayName: "Description"
|
|
47
47
|
},
|
|
48
48
|
image: {
|
|
49
49
|
type: "imageUrl",
|
|
50
|
-
displayName: "Image"
|
|
50
|
+
displayName: "Image"
|
|
51
51
|
},
|
|
52
52
|
canonical: {
|
|
53
53
|
type: "string",
|
|
54
|
-
displayName: "Canonical URL"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
54
|
+
displayName: "Canonical URL"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
export { PlasmicHead, PlasmicHeadContext, plasmicHeadMeta };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { b as __spreadArray, c as __read, _ as __rest, a as __assign, p as pick } from '../../common-
|
|
1
|
+
import { b as __spreadArray, c as __read, _ as __rest, a as __assign, p as pick } from '../../common-9ebe374e.js';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import React__default from 'react';
|
|
4
|
-
import { d as mergeRefs } from '../../react-utils-
|
|
4
|
+
import { d as mergeRefs } from '../../react-utils-7bc53870.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Responsive `<img/>` replacement, based on `next/image`
|
|
@@ -10,13 +10,13 @@ import { d as mergeRefs } from '../../react-utils-35cb2a4e.js';
|
|
|
10
10
|
// TODO: make this configurable?
|
|
11
11
|
var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
12
12
|
var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
13
|
-
var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES)), __read(DEVICE_SIZES));
|
|
13
|
+
var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
|
|
14
14
|
var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
|
|
15
15
|
var src = props.src, className = props.className, displayWidth = props.displayWidth, displayHeight = props.displayHeight, displayMinWidth = props.displayMinWidth, displayMinHeight = props.displayMinHeight, displayMaxWidth = props.displayMaxWidth, displayMaxHeight = props.displayMaxHeight, quality = props.quality, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
|
|
16
16
|
var imgProps = Object.assign({}, rest, {
|
|
17
17
|
// Default loading to "lazy" if not specified (which is different from the
|
|
18
18
|
// html img, which defaults to eager!)
|
|
19
|
-
loading: loading !== null && loading !== void 0 ? loading : "lazy"
|
|
19
|
+
loading: loading !== null && loading !== void 0 ? loading : "lazy"
|
|
20
20
|
});
|
|
21
21
|
var _a = typeof src === "string" || !src
|
|
22
22
|
? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
|
|
@@ -65,10 +65,10 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
|
|
|
65
65
|
spacerHeight = Math.round(spacerWidth / aspectRatio);
|
|
66
66
|
}
|
|
67
67
|
var _b = getWidths(computedDisplayWidth, fullWidth, {
|
|
68
|
-
minWidth: displayMinWidth
|
|
68
|
+
minWidth: displayMinWidth
|
|
69
69
|
}), sizes = _b.sizes, widthDescs = _b.widthDescs;
|
|
70
70
|
var imageLoader = getImageLoader(loader);
|
|
71
|
-
var spacerSvg = "<svg width=\""
|
|
71
|
+
var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
|
|
72
72
|
var spacerSvgBase64 = typeof window === "undefined"
|
|
73
73
|
? Buffer.from(spacerSvg).toString("base64")
|
|
74
74
|
: window.btoa(spacerSvg);
|
|
@@ -123,7 +123,7 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
return (React__default.createElement("div", { className: classNames(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
|
|
126
|
-
React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,"
|
|
126
|
+
React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
|
|
127
127
|
makePicture({
|
|
128
128
|
imageLoader: imageLoader,
|
|
129
129
|
widthDescs: widthDescs,
|
|
@@ -133,7 +133,7 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
|
|
|
133
133
|
ref: imgRef,
|
|
134
134
|
style: style ? pick(style, "objectFit", "objectPosition") : undefined,
|
|
135
135
|
imgProps: imgProps,
|
|
136
|
-
className: "__wab_img"
|
|
136
|
+
className: "__wab_img"
|
|
137
137
|
})));
|
|
138
138
|
});
|
|
139
139
|
function makePicture(opts) {
|
|
@@ -144,28 +144,28 @@ function makePicture(opts) {
|
|
|
144
144
|
return (React__default.createElement("picture", { className: "__wab_picture" },
|
|
145
145
|
imageLoader && imageLoader.supportsUrl(src) && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
|
|
146
146
|
.map(function (wd) {
|
|
147
|
-
return imageLoader.transformUrl({
|
|
147
|
+
return "".concat(imageLoader.transformUrl({
|
|
148
148
|
src: src,
|
|
149
149
|
quality: quality,
|
|
150
150
|
width: wd.width,
|
|
151
|
-
format: "webp"
|
|
152
|
-
})
|
|
151
|
+
format: "webp"
|
|
152
|
+
}), " ").concat(wd.desc);
|
|
153
153
|
})
|
|
154
154
|
.join(", ") })),
|
|
155
155
|
React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
|
|
156
156
|
? imageLoader.transformUrl({
|
|
157
157
|
src: src,
|
|
158
158
|
quality: quality,
|
|
159
|
-
width: widthDescs[widthDescs.length - 1].width
|
|
159
|
+
width: widthDescs[widthDescs.length - 1].width
|
|
160
160
|
})
|
|
161
161
|
: src, srcSet: imageLoader && imageLoader.supportsUrl(src)
|
|
162
162
|
? widthDescs
|
|
163
163
|
.map(function (wd) {
|
|
164
|
-
return imageLoader.transformUrl({
|
|
164
|
+
return "".concat(imageLoader.transformUrl({
|
|
165
165
|
src: src,
|
|
166
166
|
quality: quality,
|
|
167
|
-
width: wd.width
|
|
168
|
-
})
|
|
167
|
+
width: wd.width
|
|
168
|
+
}), " ").concat(wd.desc);
|
|
169
169
|
})
|
|
170
170
|
.join(", ")
|
|
171
171
|
: undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
|
|
@@ -207,14 +207,14 @@ function getWidths(width, fullWidth, extra) {
|
|
|
207
207
|
widthDescs: [
|
|
208
208
|
{
|
|
209
209
|
width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
|
|
210
|
-
desc: "1x"
|
|
210
|
+
desc: "1x"
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
|
|
214
|
-
desc: "2x"
|
|
214
|
+
desc: "2x"
|
|
215
215
|
},
|
|
216
216
|
],
|
|
217
|
-
sizes: undefined
|
|
217
|
+
sizes: undefined
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
// Otherwise we don't know what sizes we'll end up, so we just cap it at
|
|
@@ -227,10 +227,10 @@ function getWidths(width, fullWidth, extra) {
|
|
|
227
227
|
widthDescs: [
|
|
228
228
|
{
|
|
229
229
|
width: getClosestPresetSize(fullWidth, fullWidth),
|
|
230
|
-
desc: "1x"
|
|
230
|
+
desc: "1x"
|
|
231
231
|
},
|
|
232
232
|
],
|
|
233
|
-
sizes: undefined
|
|
233
|
+
sizes: undefined
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
return {
|
|
@@ -246,9 +246,9 @@ function getWidths(width, fullWidth, extra) {
|
|
|
246
246
|
// fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
|
|
247
247
|
// ? undefined
|
|
248
248
|
// : size,
|
|
249
|
-
desc: size
|
|
249
|
+
desc: "".concat(size, "w")
|
|
250
250
|
}); }),
|
|
251
|
-
sizes: "100vw"
|
|
251
|
+
sizes: "100vw"
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
254
|
function getPixelLength(length) {
|
|
@@ -292,12 +292,12 @@ var PLASMIC_IMAGE_LOADER = {
|
|
|
292
292
|
transformUrl: function (opts) {
|
|
293
293
|
var _a;
|
|
294
294
|
var params = [
|
|
295
|
-
opts.width ? "w="
|
|
296
|
-
"q="
|
|
297
|
-
opts.format ? "f="
|
|
295
|
+
opts.width ? "w=".concat(opts.width) : undefined,
|
|
296
|
+
"q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
|
|
297
|
+
opts.format ? "f=".concat(opts.format) : undefined,
|
|
298
298
|
].filter(function (x) { return !!x; });
|
|
299
|
-
return opts.src
|
|
300
|
-
}
|
|
299
|
+
return "".concat(opts.src, "?").concat(params.join("&"));
|
|
300
|
+
}
|
|
301
301
|
};
|
|
302
302
|
|
|
303
303
|
export { PlasmicImg };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/render/PlasmicImg/index.tsx"],"sourcesContent":["/**\n * Responsive `<img/>` replacement, based on `next/image`\n */\n\nimport classNames from \"classnames\";\nimport React, { CSSProperties } from \"react\";\nimport { pick } from \"../../common\";\nimport { mergeRefs } from \"../../react-utils\";\n\nexport interface ImageLoader {\n supportsUrl: (url: string) => boolean;\n transformUrl: (opts: {\n src: string;\n width?: number;\n quality?: number;\n format?: \"webp\";\n }) => string;\n}\n\ntype ImgTagProps = Omit<\n React.ComponentProps<\"img\">,\n \"src\" | \"srcSet\" | \"ref\" | \"style\"\n>;\n\n// Default image sizes to snap to\n// TODO: make this configurable?\nconst IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];\nconst DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];\nconst ALL_SIZES = [...IMG_SIZES, ...DEVICE_SIZES];\n\nexport interface PlasmicImgProps extends ImgTagProps {\n /**\n * Either an object with the src string, and its full width and height,\n * or just a src string with unknown intrinsic dimensions.\n */\n src?:\n | string\n | {\n src:\n | string\n | {\n src: string;\n height: number;\n width: number;\n blurDataURL?: string;\n };\n fullHeight: number;\n fullWidth: number;\n // We might also get a more precise aspectRatio for SVGs\n // instead of relyiing on fullWidth / fullHeight, because\n // those values might be rounded and not so accurate.\n aspectRatio?: number;\n };\n\n /**\n * className applied to the wrapper element if one is used.\n */\n className?: string;\n\n /**\n * css width\n */\n displayWidth?: number | string;\n\n /**\n * css height\n */\n displayHeight?: number | string;\n\n /**\n * css min-width\n */\n displayMinWidth?: number | string;\n\n /**\n * css min-height\n */\n displayMinHeight?: number | string;\n\n /**\n * css max-width\n */\n displayMaxWidth?: number | string;\n\n /**\n * css max-height\n */\n displayMaxHeight?: number | string;\n\n /**\n * For variable quality formats like jpg, the quality from 0 to 100\n */\n quality?: number;\n\n /**\n * ImageLoader to use for loading different dimensions of the image.\n * If none specified, will not attempt to load different dimensions.\n */\n loader?: \"plasmic\" | ImageLoader;\n\n /**\n * Style applied to the wrapper element. objectFit and objectPosition\n * rules are applied to the img element.\n */\n style?: React.CSSProperties;\n\n /**\n * Ref for the img element. The normal <PlasmicImg ref={...} />\n * prop gives the root element instead, which may be the img element\n * or a wrapper element\n */\n imgRef?: React.Ref<HTMLImageElement>;\n}\n\nexport const PlasmicImg = React.forwardRef(function PlasmicImg(\n props: PlasmicImgProps,\n outerRef: React.Ref<HTMLElement>\n) {\n let {\n src,\n className,\n displayWidth,\n displayHeight,\n displayMinWidth,\n displayMinHeight,\n displayMaxWidth,\n displayMaxHeight,\n quality,\n loader,\n imgRef,\n style,\n loading,\n ...rest\n } = props;\n\n const imgProps = Object.assign({}, rest, {\n // Default loading to \"lazy\" if not specified (which is different from the\n // html img, which defaults to eager!)\n loading: loading ?? \"lazy\",\n });\n\n const { fullWidth, fullHeight, aspectRatio } =\n typeof src === \"string\" || !src\n ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }\n : src;\n const srcStr = src\n ? typeof src === \"string\"\n ? src\n : typeof src.src === \"string\"\n ? src.src\n : src.src.src\n : \"\";\n\n // Assume external image if either dimension is null and use usual <img>\n if (fullHeight == null || fullWidth == null) {\n return (\n <img\n src={srcStr}\n className={className}\n style={style}\n {...imgProps}\n loading={loading}\n ref={mergeRefs(imgRef, outerRef) as any}\n />\n );\n }\n\n if (\n isSvg(srcStr) &&\n (displayHeight == null || displayHeight === \"auto\") &&\n (displayWidth == null || displayWidth === \"auto\")\n ) {\n displayWidth = \"100%\";\n }\n\n let computedDisplayWidth = displayWidth;\n if (\n fullWidth &&\n fullHeight &&\n (!displayWidth || displayWidth === \"auto\") &&\n !!getPixelLength(displayHeight)\n ) {\n // If there's a pixel length specified for displayHeight but not displayWidth,\n // then we can derive the pixel length for displayWidth. Having an explicit\n // displayWidth makes this a fixed-size image, which makes it possible for us to\n // generate better markup!\n if (!isSvg(srcStr)) {\n // We shouldn't do it for SVGs though, because `fullWidth` and\n // `fullHeight` might have rounded values so the final\n // `displayWidth` could differ by 1px or so.\n computedDisplayWidth =\n (getPixelLength(displayHeight)! * fullWidth) / fullHeight;\n }\n }\n\n let spacerWidth = fullWidth;\n let spacerHeight = fullHeight;\n if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {\n // For SVGs, fullWidth and fullHeight can be rounded values, which would\n // cause some discrepancy between the actual aspect ratio and the aspect\n // ratio from those values. So, for those cases, we set large width / height\n // values to get a more precise ratio from the spacer.\n spacerWidth = DEFAULT_SVG_WIDTH;\n spacerHeight = Math.round(spacerWidth / aspectRatio);\n }\n\n const { sizes, widthDescs } = getWidths(computedDisplayWidth, fullWidth, {\n minWidth: displayMinWidth,\n });\n const imageLoader = getImageLoader(loader);\n const spacerSvg = `<svg width=\"${spacerWidth}\" height=\"${spacerHeight}\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>`;\n const spacerSvgBase64 =\n typeof window === \"undefined\"\n ? Buffer.from(spacerSvg).toString(\"base64\")\n : window.btoa(spacerSvg);\n\n let wrapperStyle: CSSProperties = { ...(style || {}) };\n let spacerStyle: CSSProperties = {\n ...pick(style || {}, \"objectFit\", \"objectPosition\"),\n };\n\n if (displayWidth != null && displayWidth !== \"auto\") {\n // If width is set, set it on the wrapper along with min/max width\n // and just use `width: 100%` on the spacer\n spacerStyle.width = \"100%\";\n // Rely on the styles set by `classname` on the wrapper:\n // wrapperStyle.width = displayWidth;\n // wrapperStyle.minWidth = displayMinWidth;\n // wrapperStyle.maxWidth = displayMaxWidth;\n } else {\n // Otherwise, we want auto sizing from the spacer, so set width there.\n //\n // But if we have min/max width, it should be set in the wrapper and it\n // can be percentage values (and we add corresponding min/max width to\n // 100% in the spacer). In general it ends up with the correct effect,\n // but some edge cases might make `min-width: 100%` shrink the image more\n // than it should.\n spacerStyle.width = displayWidth;\n wrapperStyle.width = \"auto\";\n if (displayMinWidth) {\n spacerStyle.minWidth = \"100%\";\n // Rely on min-width set by `classname` on the wrapper:\n // wrapperStyle.minWidth = displayMinWidth;\n }\n if (displayMaxWidth != null && displayMaxWidth !== \"none\") {\n spacerStyle.maxWidth = \"100%\";\n // Rely on max-width set by `classname` on the wrapper:\n // wrapperStyle.maxWidth = displayMaxWidth;\n }\n }\n\n if (displayHeight != null && displayHeight !== \"auto\") {\n spacerStyle.height = \"100%\";\n // wrapperStyle.height = displayHeight;\n // wrapperStyle.minHeight = displayMinHeight;\n // wrapperStyle.maxHeight = displayMaxHeight;\n } else {\n spacerStyle.height = displayHeight;\n wrapperStyle.height = \"auto\";\n if (displayMinHeight) {\n spacerStyle.minHeight = \"100%\";\n // wrapperStyle.minHeight = displayMinHeight;\n }\n if (displayMaxHeight != null && displayMaxHeight !== \"none\") {\n spacerStyle.maxHeight = \"100%\";\n // wrapperStyle.maxHeight = displayMaxHeight;\n }\n }\n\n return (\n <div\n className={classNames(className, \"__wab_img-wrapper\")}\n ref={outerRef as any}\n style={wrapperStyle}\n >\n <img\n alt=\"\"\n aria-hidden\n className=\"__wab_img-spacer-svg\"\n src={`data:image/svg+xml;base64,${spacerSvgBase64}`}\n style={spacerStyle}\n />\n {makePicture({\n imageLoader,\n widthDescs,\n sizes,\n src: srcStr,\n quality,\n ref: imgRef,\n style: style ? pick(style, \"objectFit\", \"objectPosition\") : undefined,\n imgProps,\n className: \"__wab_img\",\n })}\n </div>\n );\n});\n\nfunction makePicture(opts: {\n imageLoader?: ImageLoader;\n widthDescs: WidthDesc[];\n sizes?: string;\n src: string;\n quality?: number;\n style?: React.CSSProperties;\n className?: string;\n imgProps: ImgTagProps;\n ref?: React.Ref<HTMLImageElement>;\n}) {\n // If imageLoader is undefined, then this renders to just a normal\n // <img />. Else it will render to a <picture> with a <source> for\n // webp, and srcSet/sizes set according to width requirements.\n const {\n imageLoader,\n widthDescs,\n src,\n quality,\n style,\n className,\n sizes,\n imgProps,\n ref,\n } = opts;\n return (\n <picture className=\"__wab_picture\">\n {imageLoader && imageLoader.supportsUrl(src) && (\n <source\n type=\"image/webp\"\n srcSet={widthDescs\n .map(\n (wd) =>\n `${imageLoader.transformUrl({\n src,\n quality,\n width: wd.width,\n format: \"webp\",\n })} ${wd.desc}`\n )\n .join(\", \")}\n />\n )}\n <img\n {...imgProps}\n ref={ref}\n className={className}\n decoding=\"async\"\n src={\n imageLoader && imageLoader.supportsUrl(src)\n ? imageLoader.transformUrl({\n src,\n quality,\n width: widthDescs[widthDescs.length - 1].width,\n })\n : src\n }\n srcSet={\n imageLoader && imageLoader.supportsUrl(src)\n ? widthDescs\n .map(\n (wd) =>\n `${imageLoader.transformUrl({\n src,\n quality,\n width: wd.width,\n })} ${wd.desc}`\n )\n .join(\", \")\n : undefined\n }\n sizes={imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined}\n style={{\n ...(style ? pick(style, \"objectFit\", \"objectPosition\") : {}),\n width: 0,\n height: 0,\n }}\n />\n </picture>\n );\n}\n\nconst DEFAULT_SVG_WIDTH = 10000;\n\nfunction isSvg(src: string) {\n return src.endsWith(\".svg\") || src.startsWith(\"data:image/svg\");\n}\n\ninterface WidthDesc {\n width?: number;\n desc: string;\n}\n\nfunction getClosestPresetSize(width: number, fullWidth: number) {\n const nextBiggerIndex =\n ALL_SIZES.findIndex((w) => w >= width) ?? ALL_SIZES.length - 1;\n const nextBigger = ALL_SIZES[nextBiggerIndex];\n if (nextBigger >= fullWidth) {\n // If the requested width is larger than the fullWidth,\n // we just use the original width instead. It's impossible\n // to make an image bigger than fullWidth!\n return undefined;\n } else if (\n nextBiggerIndex + 1 < ALL_SIZES.length &&\n fullWidth <= ALL_SIZES[nextBiggerIndex + 1]\n ) {\n // If the fullWidth is just between nextBigger and the one after that,\n // then also might as well just use the original size (so, width is 30,\n // nextBigger is 32, then we just use the original as long as fullWidth is\n // less than 48)\n return undefined;\n }\n\n return nextBigger;\n}\n\n/**\n * Computes the appropriate srcSet and sizes to use\n */\nfunction getWidths(\n width: number | string | undefined,\n fullWidth: number,\n extra?: { minWidth: string | number | undefined }\n): { sizes: string | undefined; widthDescs: WidthDesc[] } {\n const minWidth = extra?.minWidth;\n const pixelWidth = getPixelLength(width);\n const pixelMinWidth = getPixelLength(minWidth);\n if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {\n // If there's an exact width, then we just need to display it at 1x and 2x density\n return {\n widthDescs: [\n {\n width: getClosestPresetSize(\n Math.max(pixelWidth, pixelMinWidth ?? 0),\n fullWidth\n ),\n desc: \"1x\",\n },\n {\n width: getClosestPresetSize(\n Math.max(pixelWidth, pixelMinWidth ?? 0) * 2,\n fullWidth\n ),\n desc: \"2x\",\n },\n ],\n sizes: undefined,\n };\n }\n // Otherwise we don't know what sizes we'll end up, so we just cap it at\n // device width. TODO: do better!\n const usefulSizes = DEVICE_SIZES.filter(\n (size) => !fullWidth || size < fullWidth\n );\n if (!!fullWidth && usefulSizes.length === 0) {\n // image fullWidth is smaller than all device sizes. So all we can do\n // is offer 1x\n return {\n widthDescs: [\n {\n width: getClosestPresetSize(fullWidth, fullWidth),\n desc: \"1x\",\n },\n ],\n sizes: undefined,\n };\n }\n return {\n widthDescs: usefulSizes.map((size) => ({\n width: getClosestPresetSize(size, fullWidth),\n // If this is the last (buggest) useful width, but it is\n // still within the bounds set by DEVICE_SIZES, then just\n // use the original, unresized image. This means if we match\n // the largest size, we use unresized and best quality image.\n // We only do this, though, if fullWidth is \"reasonable\" --\n // smaller than the largest size we would consider.\n // i === usefulSizes.length - 1 &&\n // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]\n // ? undefined\n // : size,\n desc: `${size}w`,\n })),\n sizes: \"100vw\",\n };\n}\n\nfunction getPixelLength(length: number | string | undefined) {\n if (length == null || length == \"\") {\n return undefined;\n }\n\n if (typeof length === \"number\") {\n return length;\n }\n\n const parsed = parseNumeric(length);\n if (parsed && (!parsed.units || parsed.units === \"px\")) {\n return parsed.num;\n }\n\n return undefined;\n}\n\nfunction parseNumeric(val: string) {\n // Parse strings like \"30\", \"30px\", \"30%\", \"30px /* blah blah */\"\n const res = val.match(\n /^\\s*(-?(?:\\d+\\.\\d*|\\d*\\.\\d+|\\d+))\\s*([a-z]*|%)\\s*(?:\\/\\*.*)?$/i\n );\n if (res == null) {\n return undefined;\n }\n const num = res[1];\n const units = res[2];\n return { num: +num, units };\n}\n\nfunction getImageLoader(loader: \"plasmic\" | ImageLoader | undefined) {\n if (loader == null) {\n return undefined;\n } else if (loader === \"plasmic\") {\n return PLASMIC_IMAGE_LOADER;\n } else {\n return loader;\n }\n}\n\nconst PLASMIC_IMAGE_LOADER: ImageLoader = {\n supportsUrl: (src) => {\n return src.startsWith(\"https://img.plasmic.app\") && !isSvg(src);\n },\n transformUrl: (opts) => {\n const params = [\n opts.width ? `w=${opts.width}` : undefined,\n `q=${opts.quality ?? 75}`,\n opts.format ? `f=${opts.format}` : undefined,\n ].filter((x) => !!x);\n return `${opts.src}?${params.join(\"&\")}`;\n },\n};\n"],"names":["React"],"mappings":";;;;;AAAA;;;AAwBA;AACA;AACA,IAAM,SAAS,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACtD,IAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACnE,IAAM,SAAS,0CAAO,SAAS,WAAK,YAAY,EAAC,CAAC;IAsFrC,UAAU,GAAGA,cAAK,CAAC,UAAU,CAAC,SAAS,UAAU,CAC5D,KAAsB,EACtB,QAAgC;IAG9B,IAAA,GAAG,GAcD,KAAK,IAdJ,EACH,SAAS,GAaP,KAAK,UAbE,EACT,YAAY,GAYV,KAAK,aAZK,EACZ,aAAa,GAWX,KAAK,cAXM,EACb,eAAe,GAUb,KAAK,gBAVQ,EACf,gBAAgB,GASd,KAAK,iBATS,EAChB,eAAe,GAQb,KAAK,gBARQ,EACf,gBAAgB,GAOd,KAAK,iBAPS,EAChB,OAAO,GAML,KAAK,QANA,EACP,MAAM,GAKJ,KAAK,OALD,EACN,MAAM,GAIJ,KAAK,OAJD,EACN,KAAK,GAGH,KAAK,MAHF,EACL,OAAO,GAEL,KAAK,QAFA,EACJ,IAAI,UACL,KAAK,EAfL,sLAeH,CADQ,CACC;IAEV,IAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE;;;QAGvC,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,MAAM;KAC3B,CAAC,CAAC;IAEG,IAAA,KACJ,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG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["/**\n * Responsive `<img/>` replacement, based on `next/image`\n */\n\nimport classNames from \"classnames\";\nimport React, { CSSProperties } from \"react\";\nimport { pick } from \"../../common\";\nimport { mergeRefs } from \"../../react-utils\";\n\nexport interface ImageLoader {\n supportsUrl: (url: string) => boolean;\n transformUrl: (opts: {\n src: string;\n width?: number;\n quality?: number;\n format?: \"webp\";\n }) => string;\n}\n\ntype ImgTagProps = Omit<\n React.ComponentProps<\"img\">,\n \"src\" | \"srcSet\" | \"ref\" | \"style\"\n>;\n\n// Default image sizes to snap to\n// TODO: make this configurable?\nconst IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];\nconst DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];\nconst ALL_SIZES = [...IMG_SIZES, ...DEVICE_SIZES];\n\nexport interface PlasmicImgProps extends ImgTagProps {\n /**\n * Either an object with the src string, and its full width and height,\n * or just a src string with unknown intrinsic dimensions.\n */\n src?:\n | string\n | {\n src:\n | string\n | {\n src: string;\n height: number;\n width: number;\n blurDataURL?: string;\n };\n fullHeight: number;\n fullWidth: number;\n // We might also get a more precise aspectRatio for SVGs\n // instead of relyiing on fullWidth / fullHeight, because\n // those values might be rounded and not so accurate.\n aspectRatio?: number;\n };\n\n /**\n * className applied to the wrapper element if one is used.\n */\n className?: string;\n\n /**\n * css width\n */\n displayWidth?: number | string;\n\n /**\n * css height\n */\n displayHeight?: number | string;\n\n /**\n * css min-width\n */\n displayMinWidth?: number | string;\n\n /**\n * css min-height\n */\n displayMinHeight?: number | string;\n\n /**\n * css max-width\n */\n displayMaxWidth?: number | string;\n\n /**\n * css max-height\n */\n displayMaxHeight?: number | string;\n\n /**\n * For variable quality formats like jpg, the quality from 0 to 100\n */\n quality?: number;\n\n /**\n * ImageLoader to use for loading different dimensions of the image.\n * If none specified, will not attempt to load different dimensions.\n */\n loader?: \"plasmic\" | ImageLoader;\n\n /**\n * Style applied to the wrapper element. objectFit and objectPosition\n * rules are applied to the img element.\n */\n style?: React.CSSProperties;\n\n /**\n * Ref for the img element. The normal <PlasmicImg ref={...} />\n * prop gives the root element instead, which may be the img element\n * or a wrapper element\n */\n imgRef?: React.Ref<HTMLImageElement>;\n}\n\nexport const PlasmicImg = React.forwardRef(function PlasmicImg(\n props: PlasmicImgProps,\n outerRef: React.Ref<HTMLElement>\n) {\n let {\n src,\n className,\n displayWidth,\n displayHeight,\n displayMinWidth,\n displayMinHeight,\n displayMaxWidth,\n displayMaxHeight,\n quality,\n loader,\n imgRef,\n style,\n loading,\n ...rest\n } = props;\n\n const imgProps = Object.assign({}, rest, {\n // Default loading to \"lazy\" if not specified (which is different from the\n // html img, which defaults to eager!)\n loading: loading ?? \"lazy\",\n });\n\n const { fullWidth, fullHeight, aspectRatio } =\n typeof src === \"string\" || !src\n ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }\n : src;\n const srcStr = src\n ? typeof src === \"string\"\n ? src\n : typeof src.src === \"string\"\n ? src.src\n : src.src.src\n : \"\";\n\n // Assume external image if either dimension is null and use usual <img>\n if (fullHeight == null || fullWidth == null) {\n return (\n <img\n src={srcStr}\n className={className}\n style={style}\n {...imgProps}\n loading={loading}\n ref={mergeRefs(imgRef, outerRef) as any}\n />\n );\n }\n\n if (\n isSvg(srcStr) &&\n (displayHeight == null || displayHeight === \"auto\") &&\n (displayWidth == null || displayWidth === \"auto\")\n ) {\n displayWidth = \"100%\";\n }\n\n let computedDisplayWidth = displayWidth;\n if (\n fullWidth &&\n fullHeight &&\n (!displayWidth || displayWidth === \"auto\") &&\n !!getPixelLength(displayHeight)\n ) {\n // If there's a pixel length specified for displayHeight but not displayWidth,\n // then we can derive the pixel length for displayWidth. Having an explicit\n // displayWidth makes this a fixed-size image, which makes it possible for us to\n // generate better markup!\n if (!isSvg(srcStr)) {\n // We shouldn't do it for SVGs though, because `fullWidth` and\n // `fullHeight` might have rounded values so the final\n // `displayWidth` could differ by 1px or so.\n computedDisplayWidth =\n (getPixelLength(displayHeight)! * fullWidth) / fullHeight;\n }\n }\n\n let spacerWidth = fullWidth;\n let spacerHeight = fullHeight;\n if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {\n // For SVGs, fullWidth and fullHeight can be rounded values, which would\n // cause some discrepancy between the actual aspect ratio and the aspect\n // ratio from those values. So, for those cases, we set large width / height\n // values to get a more precise ratio from the spacer.\n spacerWidth = DEFAULT_SVG_WIDTH;\n spacerHeight = Math.round(spacerWidth / aspectRatio);\n }\n\n const { sizes, widthDescs } = getWidths(computedDisplayWidth, fullWidth, {\n minWidth: displayMinWidth,\n });\n const imageLoader = getImageLoader(loader);\n const spacerSvg = `<svg width=\"${spacerWidth}\" height=\"${spacerHeight}\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>`;\n const spacerSvgBase64 =\n typeof window === \"undefined\"\n ? Buffer.from(spacerSvg).toString(\"base64\")\n : window.btoa(spacerSvg);\n\n let wrapperStyle: CSSProperties = { ...(style || {}) };\n let spacerStyle: CSSProperties = {\n ...pick(style || {}, \"objectFit\", \"objectPosition\"),\n };\n\n if (displayWidth != null && displayWidth !== \"auto\") {\n // If width is set, set it on the wrapper along with min/max width\n // and just use `width: 100%` on the spacer\n spacerStyle.width = \"100%\";\n // Rely on the styles set by `classname` on the wrapper:\n // wrapperStyle.width = displayWidth;\n // wrapperStyle.minWidth = displayMinWidth;\n // wrapperStyle.maxWidth = displayMaxWidth;\n } else {\n // Otherwise, we want auto sizing from the spacer, so set width there.\n //\n // But if we have min/max width, it should be set in the wrapper and it\n // can be percentage values (and we add corresponding min/max width to\n // 100% in the spacer). In general it ends up with the correct effect,\n // but some edge cases might make `min-width: 100%` shrink the image more\n // than it should.\n spacerStyle.width = displayWidth;\n wrapperStyle.width = \"auto\";\n if (displayMinWidth) {\n spacerStyle.minWidth = \"100%\";\n // Rely on min-width set by `classname` on the wrapper:\n // wrapperStyle.minWidth = displayMinWidth;\n }\n if (displayMaxWidth != null && displayMaxWidth !== \"none\") {\n spacerStyle.maxWidth = \"100%\";\n // Rely on max-width set by `classname` on the wrapper:\n // wrapperStyle.maxWidth = displayMaxWidth;\n }\n }\n\n if (displayHeight != null && displayHeight !== \"auto\") {\n spacerStyle.height = \"100%\";\n // wrapperStyle.height = displayHeight;\n // wrapperStyle.minHeight = displayMinHeight;\n // wrapperStyle.maxHeight = displayMaxHeight;\n } else {\n spacerStyle.height = displayHeight;\n wrapperStyle.height = \"auto\";\n if (displayMinHeight) {\n spacerStyle.minHeight = \"100%\";\n // wrapperStyle.minHeight = displayMinHeight;\n }\n if (displayMaxHeight != null && displayMaxHeight !== \"none\") {\n spacerStyle.maxHeight = \"100%\";\n // wrapperStyle.maxHeight = displayMaxHeight;\n }\n }\n\n return (\n <div\n className={classNames(className, \"__wab_img-wrapper\")}\n ref={outerRef as any}\n style={wrapperStyle}\n >\n <img\n alt=\"\"\n aria-hidden\n className=\"__wab_img-spacer-svg\"\n src={`data:image/svg+xml;base64,${spacerSvgBase64}`}\n style={spacerStyle}\n />\n {makePicture({\n imageLoader,\n widthDescs,\n sizes,\n src: srcStr,\n quality,\n ref: imgRef,\n style: style ? pick(style, \"objectFit\", \"objectPosition\") : undefined,\n imgProps,\n className: \"__wab_img\",\n })}\n </div>\n );\n});\n\nfunction makePicture(opts: {\n imageLoader?: ImageLoader;\n widthDescs: WidthDesc[];\n sizes?: string;\n src: string;\n quality?: number;\n style?: React.CSSProperties;\n className?: string;\n imgProps: ImgTagProps;\n ref?: React.Ref<HTMLImageElement>;\n}) {\n // If imageLoader is undefined, then this renders to just a normal\n // <img />. Else it will render to a <picture> with a <source> for\n // webp, and srcSet/sizes set according to width requirements.\n const {\n imageLoader,\n widthDescs,\n src,\n quality,\n style,\n className,\n sizes,\n imgProps,\n ref,\n } = opts;\n return (\n <picture className=\"__wab_picture\">\n {imageLoader && imageLoader.supportsUrl(src) && (\n <source\n type=\"image/webp\"\n srcSet={widthDescs\n .map(\n (wd) =>\n `${imageLoader.transformUrl({\n src,\n quality,\n width: wd.width,\n format: \"webp\",\n })} ${wd.desc}`\n )\n .join(\", \")}\n />\n )}\n <img\n {...imgProps}\n ref={ref}\n className={className}\n decoding=\"async\"\n src={\n imageLoader && imageLoader.supportsUrl(src)\n ? imageLoader.transformUrl({\n src,\n quality,\n width: widthDescs[widthDescs.length - 1].width,\n })\n : src\n }\n srcSet={\n imageLoader && imageLoader.supportsUrl(src)\n ? widthDescs\n .map(\n (wd) =>\n `${imageLoader.transformUrl({\n src,\n quality,\n width: wd.width,\n })} ${wd.desc}`\n )\n .join(\", \")\n : undefined\n }\n sizes={imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined}\n style={{\n ...(style ? pick(style, \"objectFit\", \"objectPosition\") : {}),\n width: 0,\n height: 0,\n }}\n />\n </picture>\n );\n}\n\nconst DEFAULT_SVG_WIDTH = 10000;\n\nfunction isSvg(src: string) {\n return src.endsWith(\".svg\") || src.startsWith(\"data:image/svg\");\n}\n\ninterface WidthDesc {\n width?: number;\n desc: string;\n}\n\nfunction getClosestPresetSize(width: number, fullWidth: number) {\n const nextBiggerIndex =\n ALL_SIZES.findIndex((w) => w >= width) ?? ALL_SIZES.length - 1;\n const nextBigger = ALL_SIZES[nextBiggerIndex];\n if (nextBigger >= fullWidth) {\n // If the requested width is larger than the fullWidth,\n // we just use the original width instead. It's impossible\n // to make an image bigger than fullWidth!\n return undefined;\n } else if (\n nextBiggerIndex + 1 < ALL_SIZES.length &&\n fullWidth <= ALL_SIZES[nextBiggerIndex + 1]\n ) {\n // If the fullWidth is just between nextBigger and the one after that,\n // then also might as well just use the original size (so, width is 30,\n // nextBigger is 32, then we just use the original as long as fullWidth is\n // less than 48)\n return undefined;\n }\n\n return nextBigger;\n}\n\n/**\n * Computes the appropriate srcSet and sizes to use\n */\nfunction getWidths(\n width: number | string | undefined,\n fullWidth: number,\n extra?: { minWidth: string | number | undefined }\n): { sizes: string | undefined; widthDescs: WidthDesc[] } {\n const minWidth = extra?.minWidth;\n const pixelWidth = getPixelLength(width);\n const pixelMinWidth = getPixelLength(minWidth);\n if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {\n // If there's an exact width, then we just need to display it at 1x and 2x density\n return {\n widthDescs: [\n {\n width: getClosestPresetSize(\n Math.max(pixelWidth, pixelMinWidth ?? 0),\n fullWidth\n ),\n desc: \"1x\",\n },\n {\n width: getClosestPresetSize(\n Math.max(pixelWidth, pixelMinWidth ?? 0) * 2,\n fullWidth\n ),\n desc: \"2x\",\n },\n ],\n sizes: undefined,\n };\n }\n // Otherwise we don't know what sizes we'll end up, so we just cap it at\n // device width. TODO: do better!\n const usefulSizes = DEVICE_SIZES.filter(\n (size) => !fullWidth || size < fullWidth\n );\n if (!!fullWidth && usefulSizes.length === 0) {\n // image fullWidth is smaller than all device sizes. So all we can do\n // is offer 1x\n return {\n widthDescs: [\n {\n width: getClosestPresetSize(fullWidth, fullWidth),\n desc: \"1x\",\n },\n ],\n sizes: undefined,\n };\n }\n return {\n widthDescs: usefulSizes.map((size) => ({\n width: getClosestPresetSize(size, fullWidth),\n // If this is the last (buggest) useful width, but it is\n // still within the bounds set by DEVICE_SIZES, then just\n // use the original, unresized image. This means if we match\n // the largest size, we use unresized and best quality image.\n // We only do this, though, if fullWidth is \"reasonable\" --\n // smaller than the largest size we would consider.\n // i === usefulSizes.length - 1 &&\n // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]\n // ? undefined\n // : size,\n desc: `${size}w`,\n })),\n sizes: \"100vw\",\n };\n}\n\nfunction getPixelLength(length: number | string | undefined) {\n if (length == null || length == \"\") {\n return undefined;\n }\n\n if (typeof length === \"number\") {\n return length;\n }\n\n const parsed = parseNumeric(length);\n if (parsed && (!parsed.units || parsed.units === \"px\")) {\n return parsed.num;\n }\n\n return undefined;\n}\n\nfunction parseNumeric(val: string) {\n // Parse strings like \"30\", \"30px\", \"30%\", \"30px /* blah blah */\"\n const res = val.match(\n /^\\s*(-?(?:\\d+\\.\\d*|\\d*\\.\\d+|\\d+))\\s*([a-z]*|%)\\s*(?:\\/\\*.*)?$/i\n );\n if (res == null) {\n return undefined;\n }\n const num = res[1];\n const units = res[2];\n return { num: +num, units };\n}\n\nfunction getImageLoader(loader: \"plasmic\" | ImageLoader | undefined) {\n if (loader == null) {\n return undefined;\n } else if (loader === \"plasmic\") {\n return PLASMIC_IMAGE_LOADER;\n } else {\n return loader;\n }\n}\n\nconst PLASMIC_IMAGE_LOADER: ImageLoader = {\n supportsUrl: (src) => {\n return src.startsWith(\"https://img.plasmic.app\") && !isSvg(src);\n },\n transformUrl: (opts) => {\n const params = [\n opts.width ? `w=${opts.width}` : undefined,\n `q=${opts.quality ?? 75}`,\n opts.format ? `f=${opts.format}` : undefined,\n ].filter((x) => !!x);\n return `${opts.src}?${params.join(\"&\")}`;\n },\n};\n"],"names":["React"],"mappings":";;;;;AAAA;;;AAwBA;AACA;AACA,IAAM,SAAS,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACtD,IAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACnE,IAAM,SAAS,0CAAO,SAAS,kBAAK,YAAY,SAAC,CAAC;IAsFrC,UAAU,GAAGA,cAAK,CAAC,UAAU,CAAC,SAAS,UAAU,CAC5D,KAAsB,EACtB,QAAgC;IAG9B,IAAA,GAAG,GAcD,KAAK,IAdJ,EACH,SAAS,GAaP,KAAK,UAbE,EACT,YAAY,GAYV,KAAK,aAZK,EACZ,aAAa,GAWX,KAAK,cAXM,EACb,eAAe,GAUb,KAAK,gBAVQ,EACf,gBAAgB,GASd,KAAK,iBATS,EAChB,eAAe,GAQb,KAAK,gBARQ,EACf,gBAAgB,GAOd,KAAK,iBAPS,EAChB,OAAO,GAML,KAAK,QANA,EACP,MAAM,GAKJ,KAAK,OALD,EACN,MAAM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AAS;YAC1C,YAAK,MAAA,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAE;YACzB,IAAI,CAAC,MAAM,GAAG,YAAK,IAAI,CAAC,MAAM,CAAE,GAAG,SAAS;SAC7C,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,GAAA,CAAC,CAAC;QACrB,OAAO,UAAG,IAAI,CAAC,GAAG,cAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC;KAC1C;CACF;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useIsSSR as useAriaIsSSR } from "@react-aria/ssr";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { PlasmicTranslator } from "./translation";
|
|
4
|
+
export { PlasmicDataSourceContextProvider, useCurrentUser, } from "@plasmicapp/data-sources-context";
|
|
4
5
|
export interface PlasmicRootContextValue {
|
|
5
6
|
platform?: "nextjs" | "gatsby";
|
|
6
7
|
}
|
|
@@ -34,10 +34,10 @@ function genTranslatableString(elt) {
|
|
|
34
34
|
node.props.children) ||
|
|
35
35
|
(hasKey(node, "children") && node.children) ||
|
|
36
36
|
[];
|
|
37
|
-
var contents = ""
|
|
37
|
+
var contents = "".concat(React__default.Children.toArray(nodeChildren)
|
|
38
38
|
.map(function (child) { return getText(child); })
|
|
39
39
|
.filter(function (child) { return !!child; })
|
|
40
|
-
.join("");
|
|
40
|
+
.join(""));
|
|
41
41
|
if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
|
|
42
42
|
return contents;
|
|
43
43
|
}
|
|
@@ -46,16 +46,16 @@ function genTranslatableString(elt) {
|
|
|
46
46
|
components[componentId] = React__default.isValidElement(node)
|
|
47
47
|
? React__default.cloneElement(node, {
|
|
48
48
|
key: componentId,
|
|
49
|
-
children: undefined
|
|
49
|
+
children: undefined
|
|
50
50
|
})
|
|
51
51
|
: node;
|
|
52
|
-
return "<"
|
|
52
|
+
return "<".concat(componentId, ">").concat(contents, "</").concat(componentId, ">");
|
|
53
53
|
};
|
|
54
54
|
var str = getText(elt);
|
|
55
55
|
return {
|
|
56
56
|
str: str,
|
|
57
57
|
components: components,
|
|
58
|
-
componentsCount: componentsCount
|
|
58
|
+
componentsCount: componentsCount
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function Trans(_a) {
|
|
@@ -81,13 +81,14 @@ function hasKey(v, key) {
|
|
|
81
81
|
|
|
82
82
|
var PlasmicRootContext = React.createContext(undefined);
|
|
83
83
|
function PlasmicRootProvider(props) {
|
|
84
|
-
var _a = props, platform = _a.platform, children = _a.children, userAuthToken = _a.userAuthToken;
|
|
84
|
+
var _a = props, platform = _a.platform, children = _a.children, userAuthToken = _a.userAuthToken, user = _a.user;
|
|
85
85
|
var context = React.useMemo(function () { return ({
|
|
86
|
-
platform: platform
|
|
86
|
+
platform: platform
|
|
87
87
|
}); }, [platform]);
|
|
88
88
|
var dataSourceContextValue = React.useMemo(function () { return ({
|
|
89
89
|
userAuthToken: userAuthToken,
|
|
90
|
-
|
|
90
|
+
user: user
|
|
91
|
+
}); }, [userAuthToken, user]);
|
|
91
92
|
return (React.createElement(PlasmicRootContext.Provider, { value: context },
|
|
92
93
|
React.createElement(SSRProvider, null,
|
|
93
94
|
React.createElement(PlasmicDataSourceContextProvider, { value: dataSourceContextValue },
|
|
@@ -112,4 +113,4 @@ function useEnsureSSRProvider() {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
export { PlasmicRootProvider as P, Trans as T, useEnsureSSRProvider as a, genTranslatableString as g, useIsSSR as u };
|
|
115
|
-
//# sourceMappingURL=ssr-
|
|
116
|
+
//# sourceMappingURL=ssr-b16a1854.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-b16a1854.js","sources":["../../src/render/translation.tsx","../../src/render/ssr.tsx"],"sourcesContent":["import React from \"react\";\n\nexport type PlasmicTranslator = (\n str: string,\n opts?: {\n components?: {\n [key: string]: React.ReactElement;\n };\n }\n) => React.ReactNode;\n\nexport const PlasmicTranslatorContext =\n React.createContext<PlasmicTranslator | undefined>(undefined);\n\nexport interface TransProps {\n children?: React.ReactNode;\n}\n\nfunction isIterable(val: any): val is Iterable<any> {\n return val != null && typeof val[Symbol.iterator] === \"function\";\n}\n\nexport function genTranslatableString(elt: React.ReactNode) {\n const components: {\n [key: string]: React.ReactElement;\n } = {};\n let componentsCount = 0;\n\n const getText = (node: React.ReactNode): string => {\n if (!node) {\n return \"\";\n }\n if (\n typeof node === \"number\" ||\n typeof node === \"boolean\" ||\n typeof node === \"string\"\n ) {\n return node.toString();\n }\n if (typeof node !== \"object\") {\n return \"\";\n }\n if (Array.isArray(node) || isIterable(node)) {\n return Array.from(node)\n .map((child) => getText(child))\n .filter((child) => !!child)\n .join(\"\");\n }\n const nodeChildren: React.ReactNode =\n (hasKey(node, \"props\") &&\n hasKey(node.props, \"children\") &&\n (node.props.children as React.ReactNode | undefined)) ||\n (hasKey(node, \"children\") && node.children) ||\n [];\n const contents = `${React.Children.toArray(nodeChildren)\n .map((child) => getText(child))\n .filter((child) => !!child)\n .join(\"\")}`;\n if (React.isValidElement(node) && node.type === React.Fragment) {\n return contents;\n }\n const componentId = componentsCount + 1;\n componentsCount++;\n components[componentId] = React.isValidElement(node)\n ? React.cloneElement(node as any, {\n key: componentId,\n children: undefined,\n })\n : (node as never);\n return `<${componentId}>${contents}</${componentId}>`;\n };\n\n const str = getText(elt);\n return {\n str,\n components,\n componentsCount,\n };\n}\n\nexport function Trans({ children }: TransProps) {\n const _t = React.useContext(PlasmicTranslatorContext);\n if (!_t) {\n warnNoTranslationFunctionAtMostOnce();\n return children;\n }\n\n const { str, components, componentsCount } = genTranslatableString(children);\n return _t(str, componentsCount > 0 ? { components } : undefined);\n}\n\nlet hasWarned = false;\nfunction warnNoTranslationFunctionAtMostOnce() {\n if (!hasWarned) {\n console.warn(\n \"Using Plasmic Translation but no translation function has been provided\"\n );\n hasWarned = true;\n }\n}\n\nfunction hasKey<K extends string>(v: any, key: K): v is Record<K, any> {\n return typeof v === \"object\" && v !== null && key in v;\n}\n","import { PlasmicDataSourceContextProvider } from \"@plasmicapp/data-sources-context\";\nimport { SSRProvider, useIsSSR as useAriaIsSSR } from \"@react-aria/ssr\";\nimport * as React from \"react\";\nimport { PlasmicHeadContext } from \"./PlasmicHead\";\nimport { PlasmicTranslator, PlasmicTranslatorContext } from \"./translation\";\nexport {\n PlasmicDataSourceContextProvider,\n useCurrentUser,\n} from \"@plasmicapp/data-sources-context\";\n\nexport interface PlasmicRootContextValue {\n platform?: \"nextjs\" | \"gatsby\";\n}\n\nconst PlasmicRootContext = React.createContext<\n PlasmicRootContextValue | undefined\n>(undefined);\n\nexport interface PlasmicRootProviderProps {\n platform?: \"nextjs\" | \"gatsby\";\n children?: React.ReactNode;\n translator?: PlasmicTranslator;\n Head?: React.ComponentType<any>;\n}\n\nexport function PlasmicRootProvider(props: PlasmicRootProviderProps) {\n const { platform, children, userAuthToken, user } = props as any;\n const context = React.useMemo(\n () => ({\n platform,\n }),\n [platform]\n );\n const dataSourceContextValue = React.useMemo(\n () => ({\n userAuthToken,\n user,\n }),\n [userAuthToken, user]\n );\n return (\n <PlasmicRootContext.Provider value={context}>\n <SSRProvider>\n <PlasmicDataSourceContextProvider value={dataSourceContextValue}>\n <PlasmicTranslatorContext.Provider value={props.translator}>\n <PlasmicHeadContext.Provider value={props.Head}>\n {children}\n </PlasmicHeadContext.Provider>\n </PlasmicTranslatorContext.Provider>\n </PlasmicDataSourceContextProvider>\n </SSRProvider>\n </PlasmicRootContext.Provider>\n );\n}\n\nexport const useIsSSR = useAriaIsSSR;\n\nexport function useHasPlasmicRoot() {\n return !!React.useContext(PlasmicRootContext);\n}\n\nlet hasWarnedSSR = false;\n/**\n * Warns the user if PlasmicRootProvider is not used\n */\nexport function useEnsureSSRProvider() {\n const hasRoot = useHasPlasmicRoot();\n if (hasRoot || hasWarnedSSR || process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n hasWarnedSSR = true;\n console.warn(\n `Plasmic: To ensure your components work correctly with server-side rendering, please use PlasmicRootProvider at the root of your application. See https://docs.plasmic.app/learn/ssr`\n );\n}\n"],"names":["React","useAriaIsSSR"],"mappings":";;;;;;AAWO,IAAM,wBAAwB,GACnCA,cAAK,CAAC,aAAa,CAAgC,SAAS,CAAC,CAAC;AAMhE,SAAS,UAAU,CAAC,GAAQ;IAC1B,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC;AACnE,CAAC;SAEe,qBAAqB,CAAC,GAAoB;IACxD,IAAM,UAAU,GAEZ,EAAE,CAAC;IACP,IAAI,eAAe,GAAG,CAAC,CAAC;IAExB,IAAM,OAAO,GAAG,UAAC,IAAqB;QACpC,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,EAAE,CAAC;SACX;QACD,IACE,OAAO,IAAI,KAAK,QAAQ;YACxB,OAAO,IAAI,KAAK,SAAS;YACzB,OAAO,IAAI,KAAK,QAAQ,EACxB;YACA,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;SACxB;QACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,EAAE,CAAC;SACX;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;iBACpB,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,OAAO,CAAC,KAAK,CAAC,GAAA,CAAC;iBAC9B,MAAM,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,CAAC,KAAK,GAAA,CAAC;iBAC1B,IAAI,CAAC,EAAE,CAAC,CAAC;SACb;QACD,IAAM,YAAY,GAChB,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;YAC7B,IA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AU;oBACxD,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAC3C,QAAQ,CACmB,CACI,CACH,CACvB,CACc,EAC9B;AACJ,CAAC;IAEY,QAAQ,GAAGC,WAAa;SAErB,iBAAiB;IAC/B,OAAO,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAChD,CAAC;AAED,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB;;;SAGgB,oBAAoB;IAClC,IAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,IAAI,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;QACrE,OAAO;KACR;IAED,YAAY,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,IAAI,CACV,uLAAuL,CACxL,CAAC;AACJ;;;;"}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { a as __assign, d as isString } from './tslib.es6-d26ffe68.js';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import { Item, Section } from '@react-stately/collections';
|
|
4
|
-
import { t as toChildArray, g as getElementTypeName } from './react-utils-7c01e440.js';
|
|
5
|
-
import { g as getPlumeType, P as PLUME_STRICT_MODE } from './plume-utils-27cd384f.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* In general, we try not to expose react-aria's Collections API to Plume users.
|
|
9
|
-
* The Collections API is how react-aria users pass data about collections of
|
|
10
|
-
* things using the built-in Item and Section components, which are abstract,
|
|
11
|
-
* metadata-only components that don't render anything but only serve to specify
|
|
12
|
-
* data. For example, here's how you would use react-spectrum's Picker:
|
|
13
|
-
*
|
|
14
|
-
* <Picker>
|
|
15
|
-
* <Section title="Asia">
|
|
16
|
-
* <Item key="taiwan">Taiwan</Item>
|
|
17
|
-
* <Item key="japan">Japan</Item>
|
|
18
|
-
* <Item key="china">China</Item>
|
|
19
|
-
* </Section>
|
|
20
|
-
* <Section title="Europe">
|
|
21
|
-
* <Item key="germany">Germany</Item>
|
|
22
|
-
* <Item key="france">France</Item>
|
|
23
|
-
* </Section>
|
|
24
|
-
* </Picker>
|
|
25
|
-
*
|
|
26
|
-
* You would re-use this same Item/Section components to pass similar things to
|
|
27
|
-
* Menu, Tabs, etc.
|
|
28
|
-
*
|
|
29
|
-
* For Plasmic, this API is too abstract. The user has explicitly designed components
|
|
30
|
-
* like Select.Option and Select.OptionGroup, and it is weird that they don't actually
|
|
31
|
-
* use these components. It is more natural to do:
|
|
32
|
-
*
|
|
33
|
-
* <Select>
|
|
34
|
-
* <Select.OptionGroup title="Asia">
|
|
35
|
-
* <Select.Option key="taiwan">Taiwan</Select>
|
|
36
|
-
* </Select.OptionGroup>
|
|
37
|
-
* </Select>
|
|
38
|
-
*
|
|
39
|
-
* For Plume, we let users directly use the components they designed, both to collect
|
|
40
|
-
* information and to perform actual rendering. For example, for Plume,
|
|
41
|
-
* you'd use Select.Option instead of Item, and Select.OptionGroup instead of Section.
|
|
42
|
-
* This means that the Select.Option props will collect the same information Item
|
|
43
|
-
* does.
|
|
44
|
-
*
|
|
45
|
-
* A component like Select.Option then serves two purposes:
|
|
46
|
-
*
|
|
47
|
-
* 1. Allow users to specify the collection of data, like in the above example
|
|
48
|
-
* Here, we're mainly interested in the props in those ReactElements so
|
|
49
|
-
* we can pass the Item/Section data onto react-aria's APIs. We are not
|
|
50
|
-
* actually rendering these elements.
|
|
51
|
-
* 2. Once react-aria's Collections API has gone through them and built
|
|
52
|
-
* Collection "nodes", we then create cloned versions of these elements
|
|
53
|
-
* with the corresponding node passed in as a secret prop. These ReactElements
|
|
54
|
-
* are then actually used to _render_ the corresponding Option / OptionGroup.
|
|
55
|
-
*
|
|
56
|
-
* This file contains helper functions to help with implementing the above.
|
|
57
|
-
*
|
|
58
|
-
* Note also that most of the collections-based react-aria components expose
|
|
59
|
-
* a parallel API that accepts a list of "items" and a render prop, instead
|
|
60
|
-
* of list of Item/Section elements. This is for efficiency, but we are opting
|
|
61
|
-
* to only support the composite-component pattern for now for simplicity.
|
|
62
|
-
*/
|
|
63
|
-
/**
|
|
64
|
-
* Given children of a component like Select or Menu, derive the items
|
|
65
|
-
* that we will pass into the Collections API. These will be
|
|
66
|
-
* ReactElement<ItemLikeProps|SectionLikeProps>[].
|
|
67
|
-
*
|
|
68
|
-
* Will also assign keys to items by their index in the collection,
|
|
69
|
-
* and collect the keys of disabled items.
|
|
70
|
-
*/
|
|
71
|
-
function deriveItemsFromChildren(children, opts) {
|
|
72
|
-
if (!children) {
|
|
73
|
-
return {
|
|
74
|
-
items: [],
|
|
75
|
-
disabledKeys: [],
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError;
|
|
79
|
-
// For Plume items without an explicit key, we assign a key as the index
|
|
80
|
-
// of the collection.
|
|
81
|
-
var itemCount = 0;
|
|
82
|
-
var sectionCount = 0;
|
|
83
|
-
var ensureValue = function (element) {
|
|
84
|
-
if (!propInChild(element, "value")) {
|
|
85
|
-
if (opts.requireItemValue && PLUME_STRICT_MODE) {
|
|
86
|
-
throw new Error("Must specify a \"value\" prop for " + getElementTypeName(element));
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return cloneChild(element, { value: "" + itemCount++ });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Still increment count even if key is present, so that the
|
|
94
|
-
// auto-assigned key really reflects the index
|
|
95
|
-
itemCount++;
|
|
96
|
-
return element;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var disabledKeys = [];
|
|
100
|
-
var flattenedChildren = function (children) {
|
|
101
|
-
return toChildArray(children).flatMap(function (child) {
|
|
102
|
-
var _a;
|
|
103
|
-
if (React__default.isValidElement(child)) {
|
|
104
|
-
if (child.type === React__default.Fragment) {
|
|
105
|
-
return flattenedChildren(child.props.children);
|
|
106
|
-
}
|
|
107
|
-
var type = getPlumeType(child);
|
|
108
|
-
if (type === itemPlumeType) {
|
|
109
|
-
child = ensureValue(child);
|
|
110
|
-
var childKey = getItemLikeKey(child);
|
|
111
|
-
if (getChildProp(child, "isDisabled") && !!childKey) {
|
|
112
|
-
disabledKeys.push(childKey);
|
|
113
|
-
}
|
|
114
|
-
return [child];
|
|
115
|
-
}
|
|
116
|
-
if (type === sectionPlumeType) {
|
|
117
|
-
return [
|
|
118
|
-
cloneChild(child, {
|
|
119
|
-
// key of section doesn't actually matter, just needs
|
|
120
|
-
// to be unique
|
|
121
|
-
key: (_a = child.key) !== null && _a !== void 0 ? _a : "section-" + sectionCount++,
|
|
122
|
-
children: flattenedChildren(getChildProp(child, "children")),
|
|
123
|
-
}),
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
{
|
|
128
|
-
throw new Error(invalidChildError !== null && invalidChildError !== void 0 ? invalidChildError : "Unexpected child");
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
return { items: flattenedChildren(children), disabledKeys: disabledKeys };
|
|
133
|
-
}
|
|
134
|
-
function useDerivedItemsFromChildren(children, opts) {
|
|
135
|
-
var itemPlumeType = opts.itemPlumeType, sectionPlumeType = opts.sectionPlumeType, invalidChildError = opts.invalidChildError, requireItemValue = opts.requireItemValue;
|
|
136
|
-
return React__default.useMemo(function () {
|
|
137
|
-
return deriveItemsFromChildren(children, {
|
|
138
|
-
itemPlumeType: itemPlumeType,
|
|
139
|
-
sectionPlumeType: sectionPlumeType,
|
|
140
|
-
invalidChildError: invalidChildError,
|
|
141
|
-
requireItemValue: requireItemValue,
|
|
142
|
-
});
|
|
143
|
-
}, [
|
|
144
|
-
children,
|
|
145
|
-
itemPlumeType,
|
|
146
|
-
sectionPlumeType,
|
|
147
|
-
invalidChildError,
|
|
148
|
-
requireItemValue,
|
|
149
|
-
]);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Given a Collection node, create the React element that we should use
|
|
153
|
-
* to render it.
|
|
154
|
-
*/
|
|
155
|
-
function renderCollectionNode(node) {
|
|
156
|
-
// node.rendered should already have our item-like or section-like Plume
|
|
157
|
-
// component elements, so we just need to clone them with a secret
|
|
158
|
-
// _node prop that we use to render.
|
|
159
|
-
return cloneChild(node.rendered, {
|
|
160
|
-
_node: node,
|
|
161
|
-
key: node.key,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Renders a item-like or section-like Plume component element into an
|
|
166
|
-
* Item or a Section element.
|
|
167
|
-
*/
|
|
168
|
-
function renderAsCollectionChild(child, opts) {
|
|
169
|
-
var _a;
|
|
170
|
-
var plumeType = getPlumeType(child);
|
|
171
|
-
if (plumeType === opts.itemPlumeType) {
|
|
172
|
-
var option = child;
|
|
173
|
-
// We look at the children passed to the item-like element, and derive key
|
|
174
|
-
// or textValue from it if it is a string
|
|
175
|
-
var content = getChildProp(option, "children");
|
|
176
|
-
// The children render prop needs to return an <Item/>
|
|
177
|
-
return (React__default.createElement(Item
|
|
178
|
-
// We use ItemLike.value if the user explicitly specified a value,
|
|
179
|
-
// and we fallback to key. If the user specified neither, then
|
|
180
|
-
// the Collections API will generate a unique key for this item.
|
|
181
|
-
, {
|
|
182
|
-
// We use ItemLike.value if the user explicitly specified a value,
|
|
183
|
-
// and we fallback to key. If the user specified neither, then
|
|
184
|
-
// the Collections API will generate a unique key for this item.
|
|
185
|
-
key: getItemLikeKey(option),
|
|
186
|
-
// textValue is either explicitly specified by the user, or we
|
|
187
|
-
// try to derive it if `content` is a string.
|
|
188
|
-
textValue: (_a = getChildProp(option, "textValue")) !== null && _a !== void 0 ? _a : (isString(content)
|
|
189
|
-
? content
|
|
190
|
-
: propInChild(option, "value")
|
|
191
|
-
? getChildProp(option, "value")
|
|
192
|
-
: option.key), "aria-label": getChildProp(option, "aria-label") }, option));
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
var group = child;
|
|
196
|
-
return (React__default.createElement(Section
|
|
197
|
-
// Note that we are using the whole section-like element as the title
|
|
198
|
-
// here, and not group.props.title; we want the entire section-like
|
|
199
|
-
// Plume element to end up as Node.rendered.
|
|
200
|
-
, {
|
|
201
|
-
// Note that we are using the whole section-like element as the title
|
|
202
|
-
// here, and not group.props.title; we want the entire section-like
|
|
203
|
-
// Plume element to end up as Node.rendered.
|
|
204
|
-
title: group, "aria-label": getChildProp(group, "aria-label"),
|
|
205
|
-
// We are flattening and deriving the descendant Options as items here.
|
|
206
|
-
// group.props.children should've already been cleaned up by
|
|
207
|
-
// deriveItemsFromChildren()
|
|
208
|
-
items: getChildProp(group, "children") }, function (c) { return renderAsCollectionChild(c, opts); }));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function getItemLikeKey(element) {
|
|
212
|
-
var _a;
|
|
213
|
-
return (_a = getChildProp(element, "value")) !== null && _a !== void 0 ? _a : element.key;
|
|
214
|
-
}
|
|
215
|
-
// PlasmicLoader-aware function to get prop from child.
|
|
216
|
-
function getChildProp(child, prop) {
|
|
217
|
-
return "componentProps" in child.props
|
|
218
|
-
? child.props.componentProps[prop]
|
|
219
|
-
: child.props[prop];
|
|
220
|
-
}
|
|
221
|
-
// PlasmicLoader-aware function to check `if (prop in element.props)`.
|
|
222
|
-
function propInChild(child, prop) {
|
|
223
|
-
return "componentProps" in child.props
|
|
224
|
-
? prop in child.props.componentProps
|
|
225
|
-
: prop in child.props;
|
|
226
|
-
}
|
|
227
|
-
// PlasmicLoader-aware function to clone React element.
|
|
228
|
-
function cloneChild(child, props) {
|
|
229
|
-
if (child.type.getPlumeType) {
|
|
230
|
-
// If React element has getPlumeType(), assume that it is PlasmicLoader,
|
|
231
|
-
// so add nodeProps to componentProps instead of element props.
|
|
232
|
-
return React__default.cloneElement(child, __assign({ componentProps: __assign(__assign({}, child.props.componentProps), props) }, (props.key ? { key: props.key } : {})));
|
|
233
|
-
}
|
|
234
|
-
return React__default.cloneElement(child, props);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export { renderAsCollectionChild as a, getChildProp as g, renderCollectionNode as r, useDerivedItemsFromChildren as u };
|
|
238
|
-
//# sourceMappingURL=collection-utils-2745acd4.js.map
|