utopia-ui 3.0.0-alpha.255 → 3.0.0-alpha.256

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.
@@ -1,6 +1,8 @@
1
1
  import * as React from "react";
2
2
  import 'react-image-crop/dist/ReactCrop.css';
3
- export declare const AvatarWidget: ({ avatar, setAvatar }: {
3
+ interface AvatarWidgetProps {
4
4
  avatar: string;
5
5
  setAvatar: React.Dispatch<React.SetStateAction<any>>;
6
- }) => import("react/jsx-runtime").JSX.Element;
6
+ }
7
+ export declare const AvatarWidget: React.FC<AvatarWidgetProps>;
8
+ export {};
package/dist/index.js CHANGED
@@ -2520,7 +2520,7 @@ var SearchControl = function () {
2520
2520
  } }, { children: [jsx("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "tw-text-current tw-mr-2 tw-mt-0 tw-w-4" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" }) })), jsxs("div", { children: [jsx("div", __assign({ className: 'tw-text-sm tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-max-w-[17rem]' }, { children: (geo === null || geo === void 0 ? void 0 : geo.properties.name) ? geo === null || geo === void 0 ? void 0 : geo.properties.name : value })), jsxs("div", __assign({ className: 'tw-text-xs tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-max-w-[17rem]' }, { children: [((_a = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _a === void 0 ? void 0 : _a.city) && "".concat(capitalizeFirstLetter((_b = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _b === void 0 ? void 0 : _b.city), ", "), " ", ((_c = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _c === void 0 ? void 0 : _c.osm_value) && ((_d = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _d === void 0 ? void 0 : _d.osm_value) !== "yes" && ((_e = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _e === void 0 ? void 0 : _e.osm_value) !== "primary" && ((_f = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _f === void 0 ? void 0 : _f.osm_value) !== "path" && ((_g = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _g === void 0 ? void 0 : _g.osm_value) !== "secondary" && ((_h = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _h === void 0 ? void 0 : _h.osm_value) !== "residential" && ((_j = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _j === void 0 ? void 0 : _j.osm_value) !== "unclassified" && "".concat(capitalizeFirstLetter((_k = geo === null || geo === void 0 ? void 0 : geo.properties) === null || _k === void 0 ? void 0 : _k.osm_value), ", "), " ", geo.properties.state && "".concat(geo.properties.state, ", "), " ", geo.properties.country && geo.properties.country] }))] })] }), Math.random()));
2521
2521
  }), isGeoCoordinate(value) &&
2522
2522
  jsxs("div", __assign({ className: 'tw-flex tw-flex-row hover:tw-font-bold tw-cursor-pointer', onClick: function () {
2523
- L$1.marker(new LatLng(extractCoordinates(value)[0], extractCoordinates(value)[1]), { icon: MarkerIconFactory("circle", "#777", "RGBA(35, 31, 32, 0.2)", "circle-solid") }).addTo(map).bindPopup("<h3 class=\"tw-text-base tw-font-bold\">".concat(extractCoordinates(value)[0], ", ").concat(extractCoordinates(value)[1], "</h3>")).openPopup().addEventListener("popupclose", function (e) { console.log(e.target.remove()); });
2523
+ L$1.marker(new LatLng(extractCoordinates(value)[0], extractCoordinates(value)[1]), { icon: MarkerIconFactory("circle", "#777", "RGBA(35, 31, 32, 0.2)", "point") }).addTo(map).bindPopup("<h3 class=\"tw-text-base tw-font-bold\">".concat(extractCoordinates(value)[0], ", ").concat(extractCoordinates(value)[1], "</h3>")).openPopup().addEventListener("popupclose", function (e) { console.log(e.target.remove()); });
2524
2524
  map.setView(new LatLng(extractCoordinates(value)[0], extractCoordinates(value)[1]), 15, { duration: 1 });
2525
2525
  } }, { children: [jsx("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "tw-text-current tw-mr-2 tw-mt-0 tw-w-4" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" }) })), jsxs("div", { children: [jsx("div", __assign({ className: 'tw-text-sm tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-max-w-[17rem]' }, { children: value })), jsx("div", __assign({ className: 'tw-text-xs tw-overflow-hidden tw-text-ellipsis tw-whitespace-nowrap tw-max-w-[17rem]' }, { children: "Coordiante" }))] })] }))] }))] })) }));
2526
2526
  };
@@ -2987,7 +2987,7 @@ function useSelectPositionManager() {
2987
2987
  var updateItem = useUpdateItem();
2988
2988
  var hasUserPermission = useHasUserPermission();
2989
2989
  useEffect(function () {
2990
- if (selectPosition && markerClicked && 'text' in selectPosition) {
2990
+ if (selectPosition && markerClicked && 'text' in selectPosition && markerClicked.id !== selectPosition.id) {
2991
2991
  itemUpdateParent(__assign(__assign({}, selectPosition), { parent: markerClicked.id }));
2992
2992
  }
2993
2993
  }, [markerClicked]);
@@ -4791,84 +4791,129 @@ var AvatarWidget = function (_a) {
4791
4791
  var _d = useState(false), cropModalOpen = _d[0], setCropModalOpen = _d[1];
4792
4792
  var _e = useState(false), cropping = _e[0], setCropping = _e[1];
4793
4793
  var assetsApi = useAssetApi();
4794
- var imgRef = React.useRef(null);
4795
- var onImageChange = function (event) {
4796
- if (event.target.files && event.target.files[0]) {
4797
- setImage(URL.createObjectURL(event.target.files[0]));
4794
+ var imgRef = useRef(null);
4795
+ var onImageChange = useCallback(function (event) {
4796
+ var file = event.target.files && event.target.files[0];
4797
+ if (file) {
4798
+ var validFormats = ["image/jpeg", "image/png"];
4799
+ var maxSizeMB = 10;
4800
+ var maxSizeBytes = maxSizeMB * 1024 * 1024;
4801
+ if (!validFormats.includes(file.type)) {
4802
+ alert("Unsupported file format. Please upload a JPEG or PNG image.");
4803
+ return;
4804
+ }
4805
+ if (file.size > maxSizeBytes) {
4806
+ alert("File size exceeds ".concat(maxSizeMB, "MB. Please upload a smaller image."));
4807
+ return;
4808
+ }
4809
+ setImage(URL.createObjectURL(file));
4810
+ setCropModalOpen(true);
4798
4811
  }
4799
- setCropModalOpen(true);
4800
- };
4801
- function onImageLoad(e) {
4812
+ else {
4813
+ alert("No file selected or an error occurred while selecting the file.");
4814
+ }
4815
+ }, []);
4816
+ var onImageLoad = useCallback(function (e) {
4802
4817
  var _a = e.currentTarget, width = _a.width, height = _a.height;
4803
4818
  setCrop(centerAspectCrop(width, height, 1));
4804
- }
4805
- // This is to demonstate how to make and center a % aspect crop
4806
- // which is a bit trickier so we use some helper functions.
4807
- function centerAspectCrop(mediaWidth, mediaHeight, aspect) {
4819
+ }, []);
4820
+ var centerAspectCrop = function (mediaWidth, mediaHeight, aspect) {
4808
4821
  return centerCrop(makeAspectCrop({
4809
4822
  unit: 'px',
4810
4823
  width: mediaWidth / 2,
4811
4824
  }, aspect, mediaWidth, mediaHeight), mediaWidth, mediaHeight);
4812
- }
4813
- function renderCrop() {
4825
+ };
4826
+ function resizeImage(image, maxWidth, maxHeight) {
4814
4827
  return __awaiter(this, void 0, void 0, function () {
4815
- var image, scaleX, scaleY, canvas, ctx, pixelRatio, blob;
4828
+ var canvas, ctx, width, height, resizedImage;
4816
4829
  return __generator(this, function (_a) {
4817
4830
  switch (_a.label) {
4818
4831
  case 0:
4819
- image = imgRef.current;
4820
- if (!(crop && image)) return [3 /*break*/, 3];
4821
- scaleX = image.naturalWidth / image.width;
4822
- scaleY = image.naturalHeight / image.height;
4823
- canvas = new OffscreenCanvas(crop.width * scaleX, crop.height * scaleY);
4824
- ctx = canvas.getContext("2d");
4825
- pixelRatio = window.devicePixelRatio;
4826
- canvas.width = crop.width * pixelRatio * scaleX;
4827
- canvas.height = crop.height * pixelRatio * scaleY;
4832
+ canvas = document.createElement('canvas');
4833
+ ctx = canvas.getContext('2d');
4834
+ width = image.width;
4835
+ height = image.height;
4836
+ if (width > maxWidth) {
4837
+ height *= maxWidth / width;
4838
+ width = maxWidth;
4839
+ }
4840
+ if (height > maxHeight) {
4841
+ width *= maxHeight / height;
4842
+ height = maxHeight;
4843
+ }
4844
+ canvas.width = width;
4845
+ canvas.height = height;
4828
4846
  if (ctx) {
4829
- ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
4830
- ctx.drawImage(image, crop.x * scaleX, crop.y * scaleY, crop.width * scaleX, crop.height * scaleY, 0, 0, crop.width * scaleX, crop.height * scaleY);
4847
+ ctx.drawImage(image, 0, 0, width, height);
4831
4848
  }
4832
- return [4 /*yield*/, canvas.convertToBlob()];
4849
+ resizedImage = new Image();
4850
+ resizedImage.src = canvas.toDataURL();
4851
+ return [4 /*yield*/, resizedImage.decode()];
4833
4852
  case 1:
4834
- blob = _a.sent();
4835
- return [4 /*yield*/, resizeBlob(blob)];
4836
- case 2:
4837
4853
  _a.sent();
4838
- setCropping(false);
4839
- setImage("");
4840
- _a.label = 3;
4841
- case 3: return [2 /*return*/];
4854
+ return [2 /*return*/, resizedImage];
4842
4855
  }
4843
4856
  });
4844
4857
  });
4845
4858
  }
4846
- function resizeBlob(blob) {
4847
- return __awaiter(this, void 0, void 0, function () {
4848
- var img, canvas, ctx, resizedBlob, asset;
4849
- return __generator(this, function (_a) {
4850
- switch (_a.label) {
4851
- case 0:
4852
- img = new Image();
4853
- img.src = URL.createObjectURL(blob);
4854
- return [4 /*yield*/, img.decode()];
4855
- case 1:
4856
- _a.sent();
4857
- canvas = new OffscreenCanvas(400, 400);
4858
- ctx = canvas.getContext("2d");
4859
- ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(img, 0, 0, 400, 400);
4860
- return [4 /*yield*/, canvas.convertToBlob()];
4861
- case 2:
4862
- resizedBlob = _a.sent();
4863
- return [4 /*yield*/, assetsApi.upload(resizedBlob, "test")];
4864
- case 3:
4865
- asset = _a.sent();
4866
- setAvatar(asset.id);
4867
- return [2 /*return*/];
4868
- }
4869
- });
4859
+ var renderCrop = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
4860
+ var image, resizedImage, scaleX, scaleY, canvas, ctx, pixelRatio, blob;
4861
+ return __generator(this, function (_a) {
4862
+ switch (_a.label) {
4863
+ case 0:
4864
+ image = imgRef.current;
4865
+ if (!(crop && image)) return [3 /*break*/, 4];
4866
+ return [4 /*yield*/, resizeImage(image, 1024, 1024)];
4867
+ case 1:
4868
+ resizedImage = _a.sent();
4869
+ scaleX = resizedImage.naturalWidth / resizedImage.width;
4870
+ scaleY = resizedImage.naturalHeight / resizedImage.height;
4871
+ canvas = new OffscreenCanvas(crop.width * scaleX, crop.height * scaleY);
4872
+ ctx = canvas.getContext("2d");
4873
+ pixelRatio = window.devicePixelRatio;
4874
+ canvas.width = crop.width * pixelRatio * scaleX;
4875
+ canvas.height = crop.height * pixelRatio * scaleY;
4876
+ if (ctx) {
4877
+ ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
4878
+ ctx.drawImage(resizedImage, crop.x * scaleX, crop.y * scaleY, crop.width * scaleX, crop.height * scaleY, 0, 0, crop.width * scaleX, crop.height * scaleY);
4879
+ }
4880
+ return [4 /*yield*/, canvas.convertToBlob()];
4881
+ case 2:
4882
+ blob = _a.sent();
4883
+ return [4 /*yield*/, resizeBlob(blob)];
4884
+ case 3:
4885
+ _a.sent();
4886
+ setCropping(false);
4887
+ setImage("");
4888
+ _a.label = 4;
4889
+ case 4: return [2 /*return*/];
4890
+ }
4870
4891
  });
4871
- }
4892
+ }); }, [crop]);
4893
+ var resizeBlob = useCallback(function (blob) { return __awaiter(void 0, void 0, void 0, function () {
4894
+ var img, canvas, ctx, resizedBlob, asset;
4895
+ return __generator(this, function (_a) {
4896
+ switch (_a.label) {
4897
+ case 0:
4898
+ img = new Image();
4899
+ img.src = URL.createObjectURL(blob);
4900
+ return [4 /*yield*/, img.decode()];
4901
+ case 1:
4902
+ _a.sent();
4903
+ canvas = new OffscreenCanvas(400, 400);
4904
+ ctx = canvas.getContext("2d");
4905
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(img, 0, 0, 400, 400);
4906
+ return [4 /*yield*/, canvas.convertToBlob()];
4907
+ case 2:
4908
+ resizedBlob = _a.sent();
4909
+ return [4 /*yield*/, assetsApi.upload(resizedBlob, "avatar")];
4910
+ case 3:
4911
+ asset = _a.sent();
4912
+ setAvatar(asset.id);
4913
+ return [2 /*return*/];
4914
+ }
4915
+ });
4916
+ }); }, [assetsApi, setAvatar]);
4872
4917
  return (jsxs(Fragment, { children: [!cropping ?
4873
4918
  jsxs("label", __assign({ className: "custom-file-upload" }, { children: [jsx("input", { type: "file", accept: "image/*", className: "tw-file-input tw-w-full tw-max-w-xs", onChange: onImageChange }), jsx("div", __assign({ className: 'button tw-btn tw-btn-lg tw-btn-circle tw-animate-none' }, { children: jsx("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "tw-w-6 tw-h-6" }, { children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" }) })) })), avatar ?
4874
4919
  jsx("div", __assign({ className: 'tw-h-20 tw-w-20' }, { children: jsx("img", { src: assetsApi.url + avatar, className: 'tw-h-20 tw-w-20 tw-rounded-full' }) }))