jsuites 5.2.2 → 5.3.0

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/jsuites.js CHANGED
@@ -12719,7 +12719,7 @@ var jSuites = {
12719
12719
  ...dictionary,
12720
12720
  ...helpers,
12721
12721
  /** Current version */
12722
- version: '5.2.1',
12722
+ version: '5.3.0',
12723
12723
  /** Bind new extensions to Jsuites */
12724
12724
  setExtensions: function(o) {
12725
12725
  if (typeof(o) == 'object') {
@@ -12825,58 +12825,67 @@ const Events = function() {
12825
12825
 
12826
12826
  // Events
12827
12827
  const mouseDown = function(e) {
12828
+ // Verify current components tracking
12829
+ if (e.changedTouches && e.changedTouches[0]) {
12830
+ var x = e.changedTouches[0].clientX;
12831
+ var y = e.changedTouches[0].clientY;
12832
+ } else {
12833
+ var x = e.clientX;
12834
+ var y = e.clientY;
12835
+ }
12836
+
12837
+ // Editable
12838
+ let editable = e.target && e.target.tagName === 'DIV' && e.target.getAttribute('contentEditable');
12828
12839
  // Check if this is the floating
12829
- var item = jSuites.findElement(e.target, 'jpanel');
12840
+ let item = jSuites.findElement(e.target, 'jpanel');
12830
12841
  // Jfloating found
12831
- if (item && ! item.classList.contains("readonly")) {
12832
- // Add focus to the chart container
12833
- item.focus();
12842
+ if (item && ! item.classList.contains("readonly") && ! editable) {
12834
12843
  // Keep the tracking information
12835
- var rect = e.target.getBoundingClientRect();
12844
+ let rect = item.getBoundingClientRect();
12845
+ let angle = 0;
12846
+ if (item.style.rotate) {
12847
+ // Extract the angle value from the match and convert it to a number
12848
+ angle = parseFloat(item.style.rotate);
12849
+ }
12850
+ let action = 'move';
12851
+ if (e.target.getAttribute('data-action')) {
12852
+ action = e.target.getAttribute('data-action');
12853
+ } else {
12854
+ if (item.style.cursor) {
12855
+ action = 'resize';
12856
+ } else {
12857
+ item.style.cursor = 'move';
12858
+ }
12859
+ }
12860
+
12861
+ // Action
12836
12862
  editorAction = {
12863
+ action: action,
12864
+ a: angle,
12837
12865
  e: item,
12838
- x: e.clientX,
12839
- y: e.clientY,
12866
+ x: x,
12867
+ y: y,
12868
+ l: rect.left,
12869
+ t: rect.top,
12870
+ b: rect.bottom,
12871
+ r: rect.right,
12840
12872
  w: rect.width,
12841
12873
  h: rect.height,
12842
12874
  d: item.style.cursor,
12843
- resizing: item.style.cursor ? true : false,
12844
12875
  actioned: false,
12845
12876
  }
12846
-
12847
12877
  // Make sure width and height styling is OK
12848
12878
  if (! item.style.width) {
12849
12879
  item.style.width = rect.width + 'px';
12850
12880
  }
12851
-
12852
12881
  if (! item.style.height) {
12853
12882
  item.style.height = rect.height + 'px';
12854
12883
  }
12855
-
12856
- // Remove any selection from the page
12857
- var s = window.getSelection();
12858
- if (s.rangeCount) {
12859
- for (var i = 0; i < s.rangeCount; i++) {
12860
- s.removeRange(s.getRangeAt(i));
12861
- }
12862
- }
12863
-
12864
- e.preventDefault();
12865
- e.stopPropagation();
12866
12884
  } else {
12867
12885
  // No floating action found
12868
12886
  editorAction = false;
12869
12887
  }
12870
12888
 
12871
- // Verify current components tracking
12872
- if (e.changedTouches && e.changedTouches[0]) {
12873
- var x = e.changedTouches[0].clientX;
12874
- var y = e.changedTouches[0].clientY;
12875
- } else {
12876
- var x = e.clientX;
12877
- var y = e.clientY;
12878
- }
12879
-
12880
12889
  // Which component I am clicking
12881
12890
  var path = e.path || (e.composedPath && e.composedPath());
12882
12891
 
@@ -12897,6 +12906,28 @@ const Events = function() {
12897
12906
  isOpened(element);
12898
12907
  }
12899
12908
 
12909
+ const calculateAngle = function(x1, y1, x2, y2, x3, y3) {
12910
+ // Calculate dx and dy for the first line
12911
+ const dx1 = x2 - x1;
12912
+ const dy1 = y2 - y1;
12913
+ // Calculate dx and dy for the second line
12914
+ const dx2 = x3 - x1;
12915
+ const dy2 = y3 - y1;
12916
+ // Calculate the angle for the first line
12917
+ let angle1 = Math.atan2(dy1, dx1);
12918
+ // Calculate the angle for the second line
12919
+ let angle2 = Math.atan2(dy2, dx2);
12920
+ // Calculate the angle difference in radians
12921
+ let angleDifference = angle2 - angle1;
12922
+ // Convert the angle difference to degrees
12923
+ angleDifference = angleDifference * (180 / Math.PI);
12924
+ // Normalize the angle difference to be within [0, 360) degrees
12925
+ if (angleDifference < 0) {
12926
+ angleDifference += 360;
12927
+ }
12928
+ return angleDifference;
12929
+ }
12930
+
12900
12931
  const mouseUp = function(e) {
12901
12932
  if (editorAction && editorAction.e) {
12902
12933
  if (typeof(editorAction.e.refresh) == 'function' && state.actioned) {
@@ -12916,16 +12947,16 @@ const Events = function() {
12916
12947
 
12917
12948
  const mouseMove = function(e) {
12918
12949
  if (editorAction) {
12919
- var x = e.clientX || e.pageX;
12920
- var y = e.clientY || e.pageY;
12950
+ let x = e.clientX || e.pageX;
12951
+ let y = e.clientY || e.pageY;
12921
12952
 
12922
- // Action on going
12923
- if (! editorAction.resizing) {
12924
- if (state.x == null && state.y == null) {
12925
- state.x = x;
12926
- state.y = y;
12927
- }
12953
+ if (state.x == null && state.y == null) {
12954
+ state.x = x;
12955
+ state.y = y;
12956
+ }
12928
12957
 
12958
+ // Action on going
12959
+ if (editorAction.action === 'move') {
12929
12960
  var dx = x - state.x;
12930
12961
  var dy = y - state.y;
12931
12962
  var top = editorAction.e.offsetTop + dy;
@@ -12934,41 +12965,65 @@ const Events = function() {
12934
12965
  // Update position
12935
12966
  editorAction.e.style.top = top + 'px';
12936
12967
  editorAction.e.style.left = left + 'px';
12937
- editorAction.e.style.cursor = "move";
12938
-
12939
- state.x = x;
12940
- state.y = y;
12941
-
12942
12968
 
12943
12969
  // Update element
12944
- if (typeof(editorAction.e.refresh) == 'function') {
12970
+ if (typeof (editorAction.e.refresh) == 'function') {
12945
12971
  state.actioned = true;
12946
12972
  editorAction.e.refresh('position', top, left);
12947
12973
  }
12948
- } else {
12949
- var width = null;
12950
- var height = null;
12974
+ } else if (editorAction.action === 'rotate') {
12975
+ let ox = editorAction.l+editorAction.w/2;
12976
+ let oy = editorAction.t+editorAction.h/2;
12977
+ let angle = calculateAngle(ox, oy, editorAction.x, editorAction.y, x, y);
12978
+ angle = angle + editorAction.a % 360;
12979
+ angle = Math.round(angle / 2) * 2;
12980
+ editorAction.e.style.rotate = `${angle}deg`;
12981
+ // Update element
12982
+ if (typeof (editorAction.e.refresh) == 'function') {
12983
+ state.actioned = true;
12984
+ editorAction.e.refresh('rotate', angle);
12985
+ }
12986
+ } else if (editorAction.action === 'resize') {
12987
+ let top = null;
12988
+ let left = null;
12989
+ let width = null;
12990
+ let height = null;
12951
12991
 
12952
12992
  if (editorAction.d == 'e-resize' || editorAction.d == 'ne-resize' || editorAction.d == 'se-resize') {
12953
- // Update width
12954
- width = editorAction.w + (x - editorAction.x);
12955
- editorAction.e.style.width = width + 'px';
12993
+ width = editorAction.e.offsetWidth + (x - state.x);
12956
12994
 
12957
- // Update Height
12958
12995
  if (e.shiftKey) {
12959
- var newHeight = (x - editorAction.x) * (editorAction.h / editorAction.w);
12960
- height = editorAction.h + newHeight;
12961
- editorAction.e.style.height = height + 'px';
12962
- } else {
12963
- var newHeight = false;
12996
+ height = editorAction.e.offsetHeight + (x - state.x) * (editorAction.e.offsetHeight / editorAction.e.offsetWidth);
12997
+ }
12998
+ } else if (editorAction.d === 'w-resize' || editorAction.d == 'nw-resize'|| editorAction.d == 'sw-resize') {
12999
+ left = editorAction.e.offsetLeft + (x - state.x);
13000
+ width = editorAction.e.offsetLeft + editorAction.e.offsetWidth - left;
13001
+
13002
+ if (e.shiftKey) {
13003
+ height = editorAction.e.offsetHeight - (x - state.x) * (editorAction.e.offsetHeight / editorAction.e.offsetWidth);
12964
13004
  }
12965
13005
  }
12966
13006
 
12967
- if (! newHeight) {
12968
- if (editorAction.d == 's-resize' || editorAction.d == 'se-resize' || editorAction.d == 'sw-resize') {
12969
- height = editorAction.h + (y - editorAction.y);
12970
- editorAction.e.style.height = height + 'px';
13007
+ if (editorAction.d == 's-resize' || editorAction.d == 'se-resize' || editorAction.d == 'sw-resize') {
13008
+ if (! height) {
13009
+ height = editorAction.e.offsetHeight + (y - state.y);
12971
13010
  }
13011
+ } else if (editorAction.d === 'n-resize' || editorAction.d == 'ne-resize' || editorAction.d == 'nw-resize') {
13012
+ top = editorAction.e.offsetTop + (y - state.y);
13013
+ height = editorAction.e.offsetTop + editorAction.e.offsetHeight - top;
13014
+ }
13015
+
13016
+ if (top) {
13017
+ editorAction.e.style.top = top + 'px';
13018
+ }
13019
+ if (left) {
13020
+ editorAction.e.style.left = left + 'px';
13021
+ }
13022
+ if (width) {
13023
+ editorAction.e.style.width = width + 'px';
13024
+ }
13025
+ if (height) {
13026
+ editorAction.e.style.height = height + 'px';
12972
13027
  }
12973
13028
 
12974
13029
  // Update element
@@ -12977,13 +13032,26 @@ const Events = function() {
12977
13032
  editorAction.e.refresh('dimensions', width, height);
12978
13033
  }
12979
13034
  }
13035
+
13036
+ state.x = x;
13037
+ state.y = y;
12980
13038
  } else {
12981
- // Resizing action
12982
- var item = jSuites.findElement(e.target, 'jpanel');
13039
+ // Resize action
13040
+ let item = jSuites.findElement(e.target, 'jpanel');
12983
13041
  // Found eligible component
12984
13042
  if (item) {
12985
- if (item.getAttribute('tabindex')) {
12986
- var rect = item.getBoundingClientRect();
13043
+ // Resizing action
13044
+ let controls = item.classList.contains('jpanel-controls');
13045
+ if (controls) {
13046
+ let position = e.target.getAttribute('data-position');
13047
+ if (position) {
13048
+ item.style.cursor = position;
13049
+ } else {
13050
+ item.style.cursor = '';
13051
+ }
13052
+ } else if (item.getAttribute('tabindex')) {
13053
+ let rect = item.getBoundingClientRect();
13054
+ //console.log(e.clientY - rect.top, rect.width - (e.clientX - rect.left), cornerSize)
12987
13055
  if (e.clientY - rect.top < cornerSize) {
12988
13056
  if (rect.width - (e.clientX - rect.left) < cornerSize) {
12989
13057
  item.style.cursor = 'ne-resize';
@@ -13012,6 +13080,40 @@ const Events = function() {
13012
13080
  }
13013
13081
  }
13014
13082
 
13083
+ let position = ['n','ne','e','se','s','sw','w','nw','rotate'];
13084
+ position.forEach(function(v, k) {
13085
+ position[k] = document.createElement('div');
13086
+ position[k].classList.add('jpanel-action');
13087
+ if (v === 'rotate') {
13088
+ position[k].setAttribute('data-action', 'rotate');
13089
+ } else {
13090
+ position[k].setAttribute('data-action', 'resize');
13091
+ position[k].setAttribute('data-position', v + '-resize');
13092
+ }
13093
+ });
13094
+
13095
+ const focus = function(e) {
13096
+ // Check if this is the floating
13097
+ let item = jSuites.findElement(e.target, 'jpanel');
13098
+ if (item && ! item.classList.contains("readonly") && item.classList.contains('jpanel-controls')) {
13099
+ item.append(...position);
13100
+
13101
+ if (! item.classList.contains('jpanel-rotate')) {
13102
+ position[position.length-1].remove();
13103
+ }
13104
+ }
13105
+ }
13106
+
13107
+ const blur = function(e) {
13108
+ // Check if this is the floating
13109
+ let item = jSuites.findElement(e.target, 'jpanel');
13110
+ if (item && item.classList.contains('jpanel-controls')) {
13111
+ position.forEach(function(v) {
13112
+ v.remove();
13113
+ });
13114
+ }
13115
+ }
13116
+
13015
13117
  const mouseOver = function(e) {
13016
13118
  var message = e.target.getAttribute('data-tooltip');
13017
13119
  if (message) {
@@ -13036,14 +13138,6 @@ const Events = function() {
13036
13138
  }
13037
13139
  }
13038
13140
 
13039
- const dblClick = function(e) {
13040
- var item = jSuites.findElement(e.target, 'jpanel');
13041
- if (item && typeof(item.dblclick) == 'function') {
13042
- // Create edition
13043
- item.dblclick(e);
13044
- }
13045
- }
13046
-
13047
13141
  const contextMenu = function(e) {
13048
13142
  var item = document.activeElement;
13049
13143
  if (item && typeof(item.contextmenu) == 'function') {
@@ -13101,11 +13195,12 @@ const Events = function() {
13101
13195
  }
13102
13196
  }
13103
13197
 
13198
+ document.addEventListener('focusin', focus);
13199
+ document.addEventListener('focusout', blur);
13104
13200
  document.addEventListener('mouseup', mouseUp);
13105
13201
  document.addEventListener("mousedown", mouseDown);
13106
13202
  document.addEventListener('mousemove', mouseMove);
13107
13203
  document.addEventListener('mouseover', mouseOver);
13108
- document.addEventListener('dblclick', dblClick);
13109
13204
  document.addEventListener('keydown', keyDown);
13110
13205
  document.addEventListener('contextmenu', contextMenu);
13111
13206
  document.addEventListener('input', input);
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "main": "dist/jsuites.js",
28
28
  "types": "dist/jsuites.d.ts",
29
- "version": "5.2.2",
29
+ "version": "5.3.0",
30
30
  "bugs": "https://github.com/jsuites/jsuites/issues",
31
31
  "homepage": "https://github.com/jsuites/jsuites",
32
32
  "docs": "https://jsuites.net",