@plasmicapp/react-web 0.2.82 → 0.2.89

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.
Files changed (46) hide show
  1. package/dist/all.d.ts +92 -6
  2. package/dist/index.d.ts +2 -0
  3. package/dist/plume/button/index.d.ts +36 -0
  4. package/dist/plume/text-input/index.d.ts +36 -0
  5. package/dist/react-utils.d.ts +1 -1
  6. package/dist/react-web.cjs.development.js +248 -42
  7. package/dist/react-web.cjs.development.js.map +1 -1
  8. package/dist/react-web.cjs.production.min.js +1 -1
  9. package/dist/react-web.cjs.production.min.js.map +1 -1
  10. package/dist/react-web.esm.js +247 -43
  11. package/dist/react-web.esm.js.map +1 -1
  12. package/dist/render/PlasmicImg/index.d.ts +22 -4
  13. package/dist/stories/PlasmicImg.stories.d.ts +2 -2
  14. package/lib/plasmic.css +0 -3
  15. package/package.json +1 -1
  16. package/skinny/dist/collection-utils-3487dd27.js +238 -0
  17. package/skinny/dist/collection-utils-3487dd27.js.map +1 -0
  18. package/skinny/dist/index.d.ts +2 -0
  19. package/skinny/dist/plume/button/index.d.ts +36 -0
  20. package/skinny/dist/plume/button/index.js +27 -0
  21. package/skinny/dist/plume/button/index.js.map +1 -0
  22. package/skinny/dist/plume/checkbox/index.js +2 -1
  23. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  24. package/skinny/dist/plume/menu/index.js +3 -2
  25. package/skinny/dist/plume/menu/index.js.map +1 -1
  26. package/skinny/dist/plume/menu-button/index.js +2 -1
  27. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  28. package/skinny/dist/plume/select/index.js +3 -2
  29. package/skinny/dist/plume/select/index.js.map +1 -1
  30. package/skinny/dist/plume/switch/index.js +2 -1
  31. package/skinny/dist/plume/switch/index.js.map +1 -1
  32. package/skinny/dist/plume/text-input/index.d.ts +36 -0
  33. package/skinny/dist/plume/text-input/index.js +51 -0
  34. package/skinny/dist/plume/text-input/index.js.map +1 -0
  35. package/skinny/dist/plume/triggered-overlay/index.js +3 -3
  36. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  37. package/skinny/dist/plume-utils-27cd384f.js +35 -0
  38. package/skinny/dist/plume-utils-27cd384f.js.map +1 -0
  39. package/skinny/dist/props-utils-7c02c0a8.js +8 -0
  40. package/skinny/dist/props-utils-7c02c0a8.js.map +1 -0
  41. package/skinny/dist/react-utils-7c01e440.js.map +1 -1
  42. package/skinny/dist/react-utils.d.ts +1 -1
  43. package/skinny/dist/render/PlasmicImg/index.d.ts +22 -4
  44. package/skinny/dist/render/PlasmicImg/index.js +100 -27
  45. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  46. package/skinny/dist/stories/PlasmicImg.stories.d.ts +2 -2
@@ -800,77 +800,161 @@ function PlasmicIcon(props) {
800
800
  var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
801
801
  var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
802
802
  var ALL_SIZES = /*#__PURE__*/[].concat(IMG_SIZES, DEVICE_SIZES);
803
- var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(props, ref) {
803
+ var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(props, outerRef) {
804
804
  var src = props.src,
805
805
  className = props.className,
806
806
  displayWidth = props.displayWidth,
807
807
  displayHeight = props.displayHeight,
808
+ displayMinWidth = props.displayMinWidth,
809
+ displayMinHeight = props.displayMinHeight,
810
+ displayMaxWidth = props.displayMaxWidth,
811
+ displayMaxHeight = props.displayMaxHeight,
808
812
  quality = props.quality,
809
813
  loader = props.loader,
810
- containerRef = props.containerRef,
814
+ imgRef = props.imgRef,
811
815
  style = props.style,
812
- rest = _objectWithoutPropertiesLoose(props, ["src", "className", "displayWidth", "displayHeight", "quality", "loader", "containerRef", "style"]);
816
+ loading = props.loading,
817
+ rest = _objectWithoutPropertiesLoose(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
818
+
819
+ var imgProps = Object.assign({}, rest, {
820
+ // Default loading to "lazy" if not specified (which is different from the
821
+ // html img, which defaults to eager!)
822
+ loading: loading != null ? loading : "lazy"
823
+ });
813
824
 
814
825
  var _ref = typeof src === "string" || !src ? {
815
826
  fullWidth: undefined,
816
- fullHeight: undefined
827
+ fullHeight: undefined,
828
+ aspectRatio: undefined
817
829
  } : src,
818
830
  fullWidth = _ref.fullWidth,
819
- fullHeight = _ref.fullHeight;
831
+ fullHeight = _ref.fullHeight,
832
+ aspectRatio = _ref.aspectRatio;
820
833
 
821
834
  var srcStr = src ? typeof src === "string" ? src : src.src : ""; // Assume external image if either dimension is null and use usual <img>
822
- // (or if the image is an SVG)
823
835
 
824
- if (fullHeight == null || fullWidth == null || srcStr.endsWith(".svg")) {
836
+ if (fullHeight == null || fullWidth == null) {
825
837
  return React__default.createElement("img", Object.assign({
826
838
  src: srcStr,
827
839
  className: className,
828
840
  style: style
829
- }, rest, {
830
- ref: ref
841
+ }, imgProps, {
842
+ loading: loading,
843
+ ref: mergeRefs(imgRef, outerRef)
831
844
  }));
832
845
  }
833
846
 
847
+ if (isSvg(srcStr) && (displayHeight == null || displayHeight === "auto") && (displayWidth == null || displayWidth === "auto")) {
848
+ displayWidth = "100%";
849
+ }
850
+
834
851
  if (fullWidth && fullHeight && (!displayWidth || displayWidth === "auto") && !!getPixelLength(displayHeight)) {
835
852
  // If there's a pixel length specified for displayHeight but not displayWidth,
836
853
  // then we can derive the pixel length for displayWidth. Having an explicit
837
854
  // displayWidth makes this a fixed-size image, which makes it possible for us to
838
855
  // generate better markup!
839
- displayWidth = getPixelLength(displayHeight) * fullWidth / fullHeight;
856
+ if (!isSvg(srcStr)) {
857
+ // We shouldn't do it for SVGs though, because `fullWidth` and
858
+ // `fullHeight` might have rounded values so the final
859
+ // `displayWidth` could differ by 1px or so.
860
+ displayWidth = getPixelLength(displayHeight) * fullWidth / fullHeight;
861
+ }
862
+ }
863
+
864
+ var spacerWidth = fullWidth;
865
+ var spacerHeight = fullHeight;
866
+
867
+ if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
868
+ // For SVGs, fullWidth and fullHeight can be rounded values, which would
869
+ // cause some discrepancy between the actual aspect ratio and the aspect
870
+ // ratio from those values. So, for those cases, we set large width / height
871
+ // values to get a more precise ratio from the spacer.
872
+ spacerWidth = DEFAULT_SVG_WIDTH;
873
+ spacerHeight = Math.round(spacerWidth / aspectRatio);
840
874
  }
841
875
 
842
- var _getWidths = getWidths(displayWidth, fullWidth),
876
+ var _getWidths = getWidths(displayWidth, fullWidth, {
877
+ minWidth: displayMinWidth
878
+ }),
843
879
  sizes = _getWidths.sizes,
844
880
  widthDescs = _getWidths.widthDescs;
845
881
 
846
882
  var imageLoader = getImageLoader(loader);
847
- var spacerSvg = "<svg width=\"" + fullWidth + "\" height=\"" + fullHeight + "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>";
883
+ var spacerSvg = "<svg width=\"" + spacerWidth + "\" height=\"" + spacerHeight + "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>";
848
884
  var spacerSvgBase64 = typeof window === "undefined" ? Buffer.from(spacerSvg).toString("base64") : window.btoa(spacerSvg);
885
+
886
+ var wrapperStyle = _extends({}, style || {});
887
+
888
+ var spacerStyle = pick(style || {}, "objectFit", "objectPosition");
889
+
890
+ if (displayWidth != null && displayWidth !== "auto") {
891
+ // If width is set, set it on the wrapper along with min/max width
892
+ // and just use `width: 100%` on the spacer
893
+ spacerStyle.width = "100%";
894
+ wrapperStyle.width = displayWidth;
895
+ wrapperStyle.minWidth = displayMinWidth;
896
+ wrapperStyle.maxWidth = displayMaxWidth;
897
+ } else {
898
+ // Otherwise, we want auto sizing from the spacer, so set width there.
899
+ //
900
+ // But if we have min/max width, it should be set in the wrapper and it
901
+ // can be percentage values (and we add corresponding min/max width to
902
+ // 100% in the spacer). In general it ends up with the correct effect,
903
+ // but some edge cases might make `min-width: 100%` shrink the image more
904
+ // than it should.
905
+ spacerStyle.width = displayWidth;
906
+ wrapperStyle.width = "auto";
907
+
908
+ if (displayMinWidth) {
909
+ spacerStyle.minWidth = "100%";
910
+ wrapperStyle.minWidth = displayMinWidth;
911
+ }
912
+
913
+ if (displayMaxWidth != null && displayMaxWidth !== "none") {
914
+ spacerStyle.maxWidth = "100%";
915
+ wrapperStyle.maxWidth = displayMaxWidth;
916
+ }
917
+ }
918
+
919
+ if (displayHeight != null && displayHeight !== "auto") {
920
+ spacerStyle.height = "100%";
921
+ wrapperStyle.height = displayHeight;
922
+ wrapperStyle.minHeight = displayMinHeight;
923
+ wrapperStyle.maxHeight = displayMaxHeight;
924
+ } else {
925
+ spacerStyle.height = displayHeight;
926
+ wrapperStyle.height = "auto";
927
+
928
+ if (displayMinHeight) {
929
+ spacerStyle.minHeight = "100%";
930
+ wrapperStyle.minHeight = displayMinHeight;
931
+ }
932
+
933
+ if (displayMaxHeight != null && displayMaxHeight !== "none") {
934
+ spacerStyle.maxHeight = "100%";
935
+ wrapperStyle.maxHeight = displayMaxHeight;
936
+ }
937
+ }
938
+
849
939
  return React__default.createElement("div", {
850
940
  className: classNames$1(className, "__wab_img-wrapper"),
851
- ref: containerRef,
852
- style: _extends({}, style, {
853
- width: isPercentage(displayWidth) ? displayWidth : undefined,
854
- height: isPercentage(displayHeight) ? displayHeight : undefined
855
- })
941
+ ref: outerRef,
942
+ style: wrapperStyle
856
943
  }, React__default.createElement("img", {
857
944
  alt: "",
858
945
  "aria-hidden": true,
859
946
  className: "__wab_img-spacer-svg",
860
947
  src: "data:image/svg+xml;base64," + spacerSvgBase64,
861
- style: _extends({
862
- width: isPercentage(displayWidth) ? "100%" : displayWidth,
863
- height: isPercentage(displayHeight) ? "100%" : displayHeight
864
- }, style ? pick(style, "objectFit", "objectPosition") : {})
948
+ style: spacerStyle
865
949
  }), makePicture({
866
950
  imageLoader: imageLoader,
867
951
  widthDescs: widthDescs,
868
952
  sizes: sizes,
869
953
  src: srcStr,
870
954
  quality: quality,
871
- ref: ref,
955
+ ref: imgRef,
872
956
  style: style ? pick(style, "objectFit", "objectPosition") : undefined,
873
- imgProps: rest,
957
+ imgProps: imgProps,
874
958
  className: "__wab_img"
875
959
  }));
876
960
  });
@@ -916,7 +1000,7 @@ function makePicture(opts) {
916
1000
  width: wd.width
917
1001
  }) + " " + wd.desc;
918
1002
  }).join(", ") : undefined,
919
- sizes: imageLoader ? sizes : undefined,
1003
+ sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined,
920
1004
  style: _extends({}, style ? pick(style, "objectFit", "objectPosition") : {}, {
921
1005
  width: 0,
922
1006
  height: 0
@@ -924,6 +1008,12 @@ function makePicture(opts) {
924
1008
  })));
925
1009
  }
926
1010
 
1011
+ var DEFAULT_SVG_WIDTH = 10000;
1012
+
1013
+ function isSvg(src) {
1014
+ return src.endsWith(".svg") || src.startsWith("data:image/svg");
1015
+ }
1016
+
927
1017
  function getClosestPresetSize(width, fullWidth) {
928
1018
  var _ALL_SIZES$findIndex;
929
1019
 
@@ -952,17 +1042,19 @@ function getClosestPresetSize(width, fullWidth) {
952
1042
  */
953
1043
 
954
1044
 
955
- function getWidths(width, fullWidth) {
1045
+ function getWidths(width, fullWidth, extra) {
1046
+ var minWidth = extra == null ? void 0 : extra.minWidth;
956
1047
  var pixelWidth = getPixelLength(width);
1048
+ var pixelMinWidth = getPixelLength(minWidth);
957
1049
 
958
- if (pixelWidth != null) {
1050
+ if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
959
1051
  // If there's an exact width, then we just need to display it at 1x and 2x density
960
1052
  return {
961
1053
  widthDescs: [{
962
- width: getClosestPresetSize(pixelWidth, fullWidth),
1054
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth != null ? pixelMinWidth : 0), fullWidth),
963
1055
  desc: "1x"
964
1056
  }, {
965
- width: getClosestPresetSize(pixelWidth * 2, fullWidth),
1057
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth != null ? pixelMinWidth : 0) * 2, fullWidth),
966
1058
  desc: "2x"
967
1059
  }],
968
1060
  sizes: undefined
@@ -1008,16 +1100,6 @@ function getWidths(width, fullWidth) {
1008
1100
  };
1009
1101
  }
1010
1102
 
1011
- function isPercentage(width) {
1012
- var _parseNumeric;
1013
-
1014
- if (typeof width !== "string") {
1015
- return false;
1016
- }
1017
-
1018
- return ((_parseNumeric = parseNumeric(width)) == null ? void 0 : _parseNumeric.units) === "%";
1019
- }
1020
-
1021
1103
  function getPixelLength(length) {
1022
1104
  if (length == null || length == "") {
1023
1105
  return undefined;
@@ -1064,7 +1146,7 @@ function getImageLoader(loader) {
1064
1146
 
1065
1147
  var PLASMIC_IMAGE_LOADER = {
1066
1148
  supportsUrl: function supportsUrl(src) {
1067
- return src.startsWith("https://img.plasmic.app");
1149
+ return src.startsWith("https://img.plasmic.app") && !isSvg(src);
1068
1150
  },
1069
1151
  transformUrl: function transformUrl(opts) {
1070
1152
  var _opts$quality;
@@ -1416,6 +1498,53 @@ function getPlumeType(child) {
1416
1498
  return childType.__plumeType || (childType.getPlumeType == null ? void 0 : childType.getPlumeType(child.props));
1417
1499
  }
1418
1500
 
1501
+ function useButton(plasmicClass, props, config, ref) {
1502
+ var _ref, _ref2, _extends2, _overrides;
1503
+
1504
+ if (ref === void 0) {
1505
+ ref = null;
1506
+ }
1507
+
1508
+ var link = props.link,
1509
+ isDisabled = props.isDisabled,
1510
+ startIcon = props.startIcon,
1511
+ endIcon = props.endIcon,
1512
+ showStartIcon = props.showStartIcon,
1513
+ showEndIcon = props.showEndIcon,
1514
+ children = props.children,
1515
+ rest = _objectWithoutPropertiesLoose(props, ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"]);
1516
+
1517
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
1518
+ def: config.showStartIconVariant,
1519
+ active: showStartIcon
1520
+ }, {
1521
+ def: config.showEndIconVariant,
1522
+ active: showEndIcon
1523
+ }, {
1524
+ def: config.isDisabledVariant,
1525
+ active: isDisabled
1526
+ }));
1527
+
1528
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2), (_extends2 = {}, _extends2[config.contentSlot] = children, _extends2));
1529
+
1530
+ var overrides = (_overrides = {}, _overrides[config.root] = {
1531
+ as: !!link ? "a" : "button",
1532
+ props: _extends({
1533
+ ref: ref,
1534
+ disabled: isDisabled
1535
+ }, !!link && {
1536
+ href: link
1537
+ }, rest)
1538
+ }, _overrides);
1539
+ return {
1540
+ plasmicProps: {
1541
+ variants: variants,
1542
+ args: args,
1543
+ overrides: overrides
1544
+ }
1545
+ };
1546
+ }
1547
+
1419
1548
  function getStyleProps(props) {
1420
1549
  return pick(props, "className", "style");
1421
1550
  }
@@ -2673,6 +2802,83 @@ function useSwitch(plasmicClass, props, config, ref) {
2673
2802
  };
2674
2803
  }
2675
2804
 
2805
+ function useTextInput(plasmicClass, props, config, ref) {
2806
+ var _ref, _ref2, _overrides;
2807
+
2808
+ if (ref === void 0) {
2809
+ ref = null;
2810
+ }
2811
+
2812
+ var isDisabled = props.isDisabled,
2813
+ startIcon = props.startIcon,
2814
+ endIcon = props.endIcon,
2815
+ showStartIcon = props.showStartIcon,
2816
+ showEndIcon = props.showEndIcon,
2817
+ className = props.className,
2818
+ style = props.style,
2819
+ inputClassName = props.inputClassName,
2820
+ inputStyle = props.inputStyle,
2821
+ rest = _objectWithoutPropertiesLoose(props, ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"]);
2822
+
2823
+ var rootRef = useRef(null);
2824
+ var inputRef = useRef(null);
2825
+ useImperativeHandle(ref, function () {
2826
+ return {
2827
+ focus: function focus() {
2828
+ var _inputRef$current;
2829
+
2830
+ (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
2831
+ },
2832
+ blur: function blur() {
2833
+ var _inputRef$current2;
2834
+
2835
+ (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
2836
+ },
2837
+ getRoot: function getRoot() {
2838
+ return rootRef.current;
2839
+ },
2840
+ getInput: function getInput() {
2841
+ return inputRef.current;
2842
+ }
2843
+ };
2844
+ }, [rootRef, inputRef]);
2845
+
2846
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2847
+ def: config.showStartIconVariant,
2848
+ active: showStartIcon
2849
+ }, {
2850
+ def: config.showEndIconVariant,
2851
+ active: showEndIcon
2852
+ }, {
2853
+ def: config.isDisabledVariant,
2854
+ active: isDisabled
2855
+ }));
2856
+
2857
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2));
2858
+
2859
+ var overrides = (_overrides = {}, _overrides[config.root] = {
2860
+ props: {
2861
+ ref: rootRef,
2862
+ className: className,
2863
+ style: style
2864
+ }
2865
+ }, _overrides[config.input] = {
2866
+ props: _extends({
2867
+ disabled: isDisabled,
2868
+ ref: inputRef,
2869
+ className: inputClassName,
2870
+ style: inputStyle
2871
+ }, rest)
2872
+ }, _overrides);
2873
+ return {
2874
+ plasmicProps: {
2875
+ variants: variants,
2876
+ args: args,
2877
+ overrides: overrides
2878
+ }
2879
+ };
2880
+ }
2881
+
2676
2882
  function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
2677
2883
  var _extends2, _overrides;
2678
2884
 
@@ -2772,9 +2978,7 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
2772
2978
  restoreFocus: true
2773
2979
  }, createElement(DismissButton, {
2774
2980
  onDismiss: state.close
2775
- }), children, createElement(DismissButton, {
2776
- onDismiss: state.close
2777
- })), _extends2));
2981
+ }), children), _extends2));
2778
2982
 
2779
2983
  var overrides = (_overrides = {}, _overrides[config.root] = {
2780
2984
  props: mergeProps(overlayProps, getStyleProps(props), {
@@ -2799,5 +3003,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
2799
3003
  };
2800
3004
  }
2801
3005
 
2802
- export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useCheckbox, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTrigger, useTriggeredOverlay, wrapWithClassName };
3006
+ export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
2803
3007
  //# sourceMappingURL=react-web.esm.js.map