ywana-core8 0.0.751 → 0.0.752

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4315,6 +4315,156 @@ var EmptyMessage = function EmptyMessage(_ref) {
4315
4315
  }, text));
4316
4316
  };
4317
4317
 
4318
+ var SCROLL_SENSITIVITY = 0.0005;
4319
+ var MAX_ZOOM = 5;
4320
+ var MIN_ZOOM = 0.1;
4321
+ var ImageViewer = function ImageViewer(_ref) {
4322
+ var image = _ref.image;
4323
+
4324
+ var _useState = React.useState({
4325
+ x: 0,
4326
+ y: 0
4327
+ }),
4328
+ offset = _useState[0],
4329
+ setOffset = _useState[1];
4330
+
4331
+ var _useState2 = React.useState(1),
4332
+ zoom = _useState2[0],
4333
+ setZoom = _useState2[1];
4334
+
4335
+ var _useState3 = React.useState(false),
4336
+ draggind = _useState3[0],
4337
+ setDragging = _useState3[1];
4338
+
4339
+ var touch = React.useRef({
4340
+ x: 0,
4341
+ y: 0
4342
+ });
4343
+ var canvasRef = React.useRef(null);
4344
+ var containerRef = React.useRef(null);
4345
+ var observer = React.useRef(null);
4346
+ var background = React.useMemo(function () {
4347
+ return new Image();
4348
+ }, [image]);
4349
+
4350
+ var clamp = function clamp(num, min, max) {
4351
+ return Math.min(Math.max(num, min), max);
4352
+ };
4353
+
4354
+ var handleWheel = function handleWheel(event) {
4355
+ var deltaY = event.deltaY;
4356
+
4357
+ if (!draggind) {
4358
+ setZoom(function (zoom) {
4359
+ return clamp(zoom + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM);
4360
+ });
4361
+ }
4362
+ };
4363
+
4364
+ var handleMouseMove = function handleMouseMove(event) {
4365
+ if (draggind) {
4366
+ var _touch$current = touch.current,
4367
+ x = _touch$current.x,
4368
+ y = _touch$current.y;
4369
+ var clientX = event.clientX,
4370
+ clientY = event.clientY;
4371
+ setOffset({
4372
+ x: offset.x + (x - clientX),
4373
+ y: offset.y + (y - clientY)
4374
+ });
4375
+ touch.current = {
4376
+ x: clientX,
4377
+ y: clientY
4378
+ };
4379
+ }
4380
+ };
4381
+
4382
+ var handleMouseDown = function handleMouseDown(event) {
4383
+ var clientX = event.clientX,
4384
+ clientY = event.clientY;
4385
+ touch.current = {
4386
+ x: clientX,
4387
+ y: clientY
4388
+ };
4389
+ setDragging(true);
4390
+ };
4391
+
4392
+ var handleMouseUp = function handleMouseUp() {
4393
+ return setDragging(false);
4394
+ };
4395
+
4396
+ var draw = function draw() {
4397
+ if (canvasRef.current) {
4398
+ var _canvasRef$current = canvasRef.current,
4399
+ width = _canvasRef$current.width,
4400
+ height = _canvasRef$current.height;
4401
+ var context = canvasRef.current.getContext("2d"); // Set canvas dimensions
4402
+
4403
+ canvasRef.current.width = width;
4404
+ canvasRef.current.height = height; // Clear canvas and scale it
4405
+
4406
+ context.translate(-offset.x, -offset.y);
4407
+ context.scale(zoom, zoom);
4408
+ context.clearRect(0, 0, width, height); // Make sure we're zooming to the center
4409
+
4410
+ var x = (context.canvas.width / zoom - background.width) / 2;
4411
+ var y = (context.canvas.height / zoom - background.height) / 2; // Draw image
4412
+
4413
+ context.drawImage(background, x, y);
4414
+ }
4415
+ };
4416
+
4417
+ React.useEffect(function () {
4418
+ observer.current = new ResizeObserver(function (entries) {
4419
+ entries.forEach(function (_ref2) {
4420
+ var target = _ref2.target;
4421
+ var width = background.width,
4422
+ height = background.height; // If width of the container is smaller than image, scale image down
4423
+
4424
+ if (target.clientWidth < width) {
4425
+ // Calculate scale
4426
+ var scale = target.clientWidth / width; // Redraw image
4427
+
4428
+ canvasRef.current.width = width * scale;
4429
+ canvasRef.current.height = height * scale;
4430
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0, width * scale, height * scale);
4431
+ }
4432
+ });
4433
+ });
4434
+ observer.current.observe(containerRef.current);
4435
+ return function () {
4436
+ return observer.current.unobserve(containerRef.current);
4437
+ };
4438
+ }, []);
4439
+ React.useEffect(function () {
4440
+ background.src = image;
4441
+
4442
+ if (canvasRef.current) {
4443
+ background.onload = function () {
4444
+ // Get the image dimensions
4445
+ var width = background.width,
4446
+ height = background.height;
4447
+ canvasRef.current.width = width;
4448
+ canvasRef.current.height = height; // Set image as background
4449
+
4450
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0);
4451
+ };
4452
+ }
4453
+ }, [background]);
4454
+ React.useEffect(function () {
4455
+ draw();
4456
+ }, [zoom, offset]);
4457
+ return /*#__PURE__*/React__default["default"].createElement("div", {
4458
+ ref: containerRef
4459
+ }, /*#__PURE__*/React__default["default"].createElement("canvas", {
4460
+ onMouseDown: handleMouseDown,
4461
+ onMouseUp: handleMouseUp,
4462
+ onWheel: handleWheel,
4463
+ onMouseMove: handleMouseMove,
4464
+ ref: canvasRef
4465
+ }));
4466
+ };
4467
+
4318
4468
  /**
4319
4469
  * Content Form
4320
4470
  */
@@ -6353,6 +6503,9 @@ var CollectionEditor$1 = function CollectionEditor(props) {
6353
6503
  var _temp5 = function _temp5() {
6354
6504
  if (onChange) onChange(form);
6355
6505
  setPageContext(Object.assign({}, pageContext));
6506
+ site.notify({
6507
+ title: "Datos Guardados"
6508
+ });
6356
6509
  };
6357
6510
 
6358
6511
  var _temp6 = function () {
@@ -11014,6 +11167,7 @@ exports.Form = Form;
11014
11167
  exports.HTTPClient = HTTPClient;
11015
11168
  exports.Header = Header;
11016
11169
  exports.Icon = Icon;
11170
+ exports.ImageViewer = ImageViewer;
11017
11171
  exports.Kanban = Kanban;
11018
11172
  exports.KanbanCard = KanbanCard;
11019
11173
  exports.KanbanColumn = KanbanColumn;