ywana-core8 0.0.750 → 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.umd.js CHANGED
@@ -4309,6 +4309,156 @@
4309
4309
  }, text));
4310
4310
  };
4311
4311
 
4312
+ var SCROLL_SENSITIVITY = 0.0005;
4313
+ var MAX_ZOOM = 5;
4314
+ var MIN_ZOOM = 0.1;
4315
+ var ImageViewer = function ImageViewer(_ref) {
4316
+ var image = _ref.image;
4317
+
4318
+ var _useState = React.useState({
4319
+ x: 0,
4320
+ y: 0
4321
+ }),
4322
+ offset = _useState[0],
4323
+ setOffset = _useState[1];
4324
+
4325
+ var _useState2 = React.useState(1),
4326
+ zoom = _useState2[0],
4327
+ setZoom = _useState2[1];
4328
+
4329
+ var _useState3 = React.useState(false),
4330
+ draggind = _useState3[0],
4331
+ setDragging = _useState3[1];
4332
+
4333
+ var touch = React.useRef({
4334
+ x: 0,
4335
+ y: 0
4336
+ });
4337
+ var canvasRef = React.useRef(null);
4338
+ var containerRef = React.useRef(null);
4339
+ var observer = React.useRef(null);
4340
+ var background = React.useMemo(function () {
4341
+ return new Image();
4342
+ }, [image]);
4343
+
4344
+ var clamp = function clamp(num, min, max) {
4345
+ return Math.min(Math.max(num, min), max);
4346
+ };
4347
+
4348
+ var handleWheel = function handleWheel(event) {
4349
+ var deltaY = event.deltaY;
4350
+
4351
+ if (!draggind) {
4352
+ setZoom(function (zoom) {
4353
+ return clamp(zoom + deltaY * SCROLL_SENSITIVITY * -1, MIN_ZOOM, MAX_ZOOM);
4354
+ });
4355
+ }
4356
+ };
4357
+
4358
+ var handleMouseMove = function handleMouseMove(event) {
4359
+ if (draggind) {
4360
+ var _touch$current = touch.current,
4361
+ x = _touch$current.x,
4362
+ y = _touch$current.y;
4363
+ var clientX = event.clientX,
4364
+ clientY = event.clientY;
4365
+ setOffset({
4366
+ x: offset.x + (x - clientX),
4367
+ y: offset.y + (y - clientY)
4368
+ });
4369
+ touch.current = {
4370
+ x: clientX,
4371
+ y: clientY
4372
+ };
4373
+ }
4374
+ };
4375
+
4376
+ var handleMouseDown = function handleMouseDown(event) {
4377
+ var clientX = event.clientX,
4378
+ clientY = event.clientY;
4379
+ touch.current = {
4380
+ x: clientX,
4381
+ y: clientY
4382
+ };
4383
+ setDragging(true);
4384
+ };
4385
+
4386
+ var handleMouseUp = function handleMouseUp() {
4387
+ return setDragging(false);
4388
+ };
4389
+
4390
+ var draw = function draw() {
4391
+ if (canvasRef.current) {
4392
+ var _canvasRef$current = canvasRef.current,
4393
+ width = _canvasRef$current.width,
4394
+ height = _canvasRef$current.height;
4395
+ var context = canvasRef.current.getContext("2d"); // Set canvas dimensions
4396
+
4397
+ canvasRef.current.width = width;
4398
+ canvasRef.current.height = height; // Clear canvas and scale it
4399
+
4400
+ context.translate(-offset.x, -offset.y);
4401
+ context.scale(zoom, zoom);
4402
+ context.clearRect(0, 0, width, height); // Make sure we're zooming to the center
4403
+
4404
+ var x = (context.canvas.width / zoom - background.width) / 2;
4405
+ var y = (context.canvas.height / zoom - background.height) / 2; // Draw image
4406
+
4407
+ context.drawImage(background, x, y);
4408
+ }
4409
+ };
4410
+
4411
+ React.useEffect(function () {
4412
+ observer.current = new ResizeObserver(function (entries) {
4413
+ entries.forEach(function (_ref2) {
4414
+ var target = _ref2.target;
4415
+ var width = background.width,
4416
+ height = background.height; // If width of the container is smaller than image, scale image down
4417
+
4418
+ if (target.clientWidth < width) {
4419
+ // Calculate scale
4420
+ var scale = target.clientWidth / width; // Redraw image
4421
+
4422
+ canvasRef.current.width = width * scale;
4423
+ canvasRef.current.height = height * scale;
4424
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0, width * scale, height * scale);
4425
+ }
4426
+ });
4427
+ });
4428
+ observer.current.observe(containerRef.current);
4429
+ return function () {
4430
+ return observer.current.unobserve(containerRef.current);
4431
+ };
4432
+ }, []);
4433
+ React.useEffect(function () {
4434
+ background.src = image;
4435
+
4436
+ if (canvasRef.current) {
4437
+ background.onload = function () {
4438
+ // Get the image dimensions
4439
+ var width = background.width,
4440
+ height = background.height;
4441
+ canvasRef.current.width = width;
4442
+ canvasRef.current.height = height; // Set image as background
4443
+
4444
+ canvasRef.current.getContext("2d").drawImage(background, 0, 0);
4445
+ };
4446
+ }
4447
+ }, [background]);
4448
+ React.useEffect(function () {
4449
+ draw();
4450
+ }, [zoom, offset]);
4451
+ return /*#__PURE__*/React__default["default"].createElement("div", {
4452
+ ref: containerRef
4453
+ }, /*#__PURE__*/React__default["default"].createElement("canvas", {
4454
+ onMouseDown: handleMouseDown,
4455
+ onMouseUp: handleMouseUp,
4456
+ onWheel: handleWheel,
4457
+ onMouseMove: handleMouseMove,
4458
+ ref: canvasRef
4459
+ }));
4460
+ };
4461
+
4312
4462
  /**
4313
4463
  * Content Form
4314
4464
  */
@@ -6344,12 +6494,15 @@
6344
6494
  var CollectionEditor$1 = function CollectionEditor(props) {
6345
6495
  var save = function save() {
6346
6496
  try {
6347
- var _temp3 = function _temp3() {
6497
+ var _temp5 = function _temp5() {
6348
6498
  if (onChange) onChange(form);
6349
6499
  setPageContext(Object.assign({}, pageContext));
6500
+ site.notify({
6501
+ title: "Datos Guardados"
6502
+ });
6350
6503
  };
6351
6504
 
6352
- var _temp4 = function () {
6505
+ var _temp6 = function () {
6353
6506
  if (patch) {
6354
6507
  return Promise.resolve(pageContext.patch(form.id, form)).then(function () {});
6355
6508
  } else {
@@ -6357,7 +6510,7 @@
6357
6510
  }
6358
6511
  }();
6359
6512
 
6360
- return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
6513
+ return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6));
6361
6514
  } catch (e) {
6362
6515
  return Promise.reject(e);
6363
6516
  }
@@ -6367,7 +6520,7 @@
6367
6520
  try {
6368
6521
  var accept = site.confirm("¿ Esta seguro ?");
6369
6522
 
6370
- var _temp6 = function () {
6523
+ var _temp2 = function () {
6371
6524
  if (accept === true) {
6372
6525
  return Promise.resolve(pageContext.remove(selected.id)).then(function () {
6373
6526
  pageContext.clear();
@@ -6376,12 +6529,14 @@
6376
6529
  }
6377
6530
  }();
6378
6531
 
6379
- return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(function () {}) : void 0);
6532
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
6380
6533
  } catch (e) {
6381
6534
  return Promise.reject(e);
6382
6535
  }
6383
6536
  };
6384
6537
 
6538
+ var site = React.useContext(SiteContext);
6539
+
6385
6540
  var _useContext5 = React.useContext(PageContext),
6386
6541
  pageContext = _useContext5[0],
6387
6542
  setPageContext = _useContext5[1];
@@ -11006,6 +11161,7 @@
11006
11161
  exports.HTTPClient = HTTPClient;
11007
11162
  exports.Header = Header;
11008
11163
  exports.Icon = Icon;
11164
+ exports.ImageViewer = ImageViewer;
11009
11165
  exports.Kanban = Kanban;
11010
11166
  exports.KanbanCard = KanbanCard;
11011
11167
  exports.KanbanColumn = KanbanColumn;