jsuites 6.2.1 → 6.3.1

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 (2) hide show
  1. package/dist/jsuites.js +324 -30
  2. package/package.json +1 -1
package/dist/jsuites.js CHANGED
@@ -12466,7 +12466,7 @@ Helpers.findElement = function(element, condition) {
12466
12466
  /* harmony default export */ var helpers = (Helpers);
12467
12467
  ;// CONCATENATED MODULE: ./src/utils/path.js
12468
12468
  const isValidPathObj = function(o) {
12469
- return typeof o === 'object' || typeof o === 'function';
12469
+ return o !== null && (typeof o === 'object' || typeof o === 'function');
12470
12470
  }
12471
12471
 
12472
12472
  function Path(pathString, value, remove) {
@@ -12490,11 +12490,7 @@ function Path(pathString, value, remove) {
12490
12490
  for (let i = 0; i < keys.length; i++) {
12491
12491
  const key = keys[i];
12492
12492
  // Check if the current object is valid and has the key
12493
- if (
12494
- currentObject != null &&
12495
- isValidPathObj(currentObject) &&
12496
- key in currentObject
12497
- ) {
12493
+ if (currentObject != null && isValidPathObj(currentObject) && key in currentObject) {
12498
12494
  currentObject = currentObject[key];
12499
12495
  } else {
12500
12496
  // Return undefined if the path is invalid or currentObject is null/undefined
@@ -14506,11 +14502,22 @@ function Tabs(el, options) {
14506
14502
  var prev = null;
14507
14503
  var next = null;
14508
14504
  var border = null;
14505
+ var header = null;
14506
+ var controls = null;
14507
+ var add = null;
14508
+
14509
+ // Event handler references for cleanup
14510
+ var headersClickHandler = null;
14511
+ var headersContextMenuHandler = null;
14509
14512
 
14510
14513
  // Helpers
14511
14514
  const setBorder = function(index) {
14512
14515
  if (obj.options.animation) {
14513
14516
  setTimeout(function() {
14517
+ // Guard against destroyed state
14518
+ if (!obj.headers || !obj.headers.children[index]) {
14519
+ return;
14520
+ }
14514
14521
  let rect = obj.headers.children[index].getBoundingClientRect();
14515
14522
 
14516
14523
  if (obj.options.palette === 'modern') {
@@ -14531,6 +14538,10 @@ function Tabs(el, options) {
14531
14538
  }
14532
14539
 
14533
14540
  var updateControls = function(x) {
14541
+ // Guard against destroyed state
14542
+ if (!obj.headers) {
14543
+ return;
14544
+ }
14534
14545
  if (typeof(obj.headers.scrollTo) == 'function') {
14535
14546
  obj.headers.scrollTo({
14536
14547
  left: x,
@@ -14845,7 +14856,7 @@ function Tabs(el, options) {
14845
14856
  }
14846
14857
 
14847
14858
  // Header
14848
- var header = document.createElement('div');
14859
+ header = document.createElement('div');
14849
14860
  header.className = 'jtabs-headers-container';
14850
14861
  header.appendChild(obj.headers);
14851
14862
  if (obj.options.maxWidth) {
@@ -14853,7 +14864,7 @@ function Tabs(el, options) {
14853
14864
  }
14854
14865
 
14855
14866
  // Controls
14856
- var controls = document.createElement('div');
14867
+ controls = document.createElement('div');
14857
14868
  controls.className = 'jtabs-controls';
14858
14869
  controls.setAttribute('draggable', 'false');
14859
14870
  header.appendChild(controls);
@@ -14869,7 +14880,7 @@ function Tabs(el, options) {
14869
14880
 
14870
14881
  // New button
14871
14882
  if (obj.options.allowCreate == true) {
14872
- var add = document.createElement('div');
14883
+ add = document.createElement('div');
14873
14884
  add.className = 'jtabs-add';
14874
14885
  add.onclick = function() {
14875
14886
  obj.create();
@@ -14938,7 +14949,7 @@ function Tabs(el, options) {
14938
14949
  }
14939
14950
 
14940
14951
  // Events
14941
- obj.headers.addEventListener("click", function(e) {
14952
+ headersClickHandler = function(e) {
14942
14953
  if (e.target.parentNode.classList.contains('jtabs-headers')) {
14943
14954
  var target = e.target;
14944
14955
  } else {
@@ -14954,11 +14965,13 @@ function Tabs(el, options) {
14954
14965
  if (typeof(obj.options.onclick) == 'function') {
14955
14966
  obj.options.onclick(el, obj, index, obj.headers.children[index], obj.content.children[index]);
14956
14967
  }
14957
- });
14968
+ };
14969
+ obj.headers.addEventListener("click", headersClickHandler);
14958
14970
 
14959
- obj.headers.addEventListener("contextmenu", function(e) {
14971
+ headersContextMenuHandler = function(e) {
14960
14972
  obj.selectIndex(e.target);
14961
- });
14973
+ };
14974
+ obj.headers.addEventListener("contextmenu", headersContextMenuHandler);
14962
14975
 
14963
14976
  if (obj.headers.children.length) {
14964
14977
  // Open first tab
@@ -15032,6 +15045,71 @@ function Tabs(el, options) {
15032
15045
  obj.init();
15033
15046
  }
15034
15047
 
15048
+ /**
15049
+ * Destroy the tabs instance and release all resources
15050
+ */
15051
+ obj.destroy = function() {
15052
+ // Remove event listeners from headers
15053
+ if (obj.headers) {
15054
+ if (headersClickHandler) {
15055
+ obj.headers.removeEventListener('click', headersClickHandler);
15056
+ }
15057
+ if (headersContextMenuHandler) {
15058
+ obj.headers.removeEventListener('contextmenu', headersContextMenuHandler);
15059
+ }
15060
+ }
15061
+
15062
+ // Clear onclick handlers
15063
+ if (prev) {
15064
+ prev.onclick = null;
15065
+ }
15066
+ if (next) {
15067
+ next.onclick = null;
15068
+ }
15069
+ if (add) {
15070
+ add.onclick = null;
15071
+ }
15072
+
15073
+ // Remove DOM elements
15074
+ if (header && header.parentNode) {
15075
+ header.parentNode.removeChild(header);
15076
+ }
15077
+ if (obj.content && obj.content.parentNode) {
15078
+ obj.content.parentNode.removeChild(obj.content);
15079
+ }
15080
+
15081
+ // Remove class from element
15082
+ el.classList.remove('jtabs');
15083
+ el.classList.remove('jtabs-animation');
15084
+ el.classList.remove('jtabs-modern');
15085
+
15086
+ // Remove instance reference
15087
+ delete el.tabs;
15088
+
15089
+ // Clear options callbacks to release closures
15090
+ if (obj.options) {
15091
+ obj.options.onclick = null;
15092
+ obj.options.onload = null;
15093
+ obj.options.onchange = null;
15094
+ obj.options.oncreate = null;
15095
+ obj.options.ondelete = null;
15096
+ obj.options.onbeforecreate = null;
15097
+ obj.options.onchangeposition = null;
15098
+ }
15099
+
15100
+ // Clear references
15101
+ obj.headers = null;
15102
+ obj.content = null;
15103
+ header = null;
15104
+ controls = null;
15105
+ prev = null;
15106
+ next = null;
15107
+ border = null;
15108
+ add = null;
15109
+ headersClickHandler = null;
15110
+ headersContextMenuHandler = null;
15111
+ }
15112
+
15035
15113
  el.tabs = obj;
15036
15114
 
15037
15115
  return obj;
@@ -15231,11 +15309,13 @@ function Color(el, options) {
15231
15309
  * Close color pallete
15232
15310
  */
15233
15311
  obj.close = function(ignoreEvents) {
15234
- if (container.classList.contains('jcolor-focus')) {
15312
+ if (container && container.classList.contains('jcolor-focus')) {
15235
15313
  // Remove focus
15236
15314
  container.classList.remove('jcolor-focus');
15237
15315
  // Make sure backdrop is hidden
15238
- backdrop.style.display = '';
15316
+ if (backdrop) {
15317
+ backdrop.style.display = '';
15318
+ }
15239
15319
  // Call related events
15240
15320
  if (! ignoreEvents && typeof(obj.options.onclose) == 'function') {
15241
15321
  obj.options.onclose(el, obj);
@@ -15244,7 +15324,7 @@ function Color(el, options) {
15244
15324
  tracking(obj, false);
15245
15325
  }
15246
15326
 
15247
- return obj.options.value;
15327
+ return obj.options.value ? obj.options.value : null;
15248
15328
  }
15249
15329
 
15250
15330
  /**
@@ -15655,7 +15735,7 @@ function Color(el, options) {
15655
15735
  el.appendChild(container);
15656
15736
  }
15657
15737
 
15658
- container.addEventListener("click", function(e) {
15738
+ containerClickHandler = function(e) {
15659
15739
  if (e.target.tagName == 'TD') {
15660
15740
  var value = e.target.getAttribute('data-value');
15661
15741
  if (value) {
@@ -15674,21 +15754,24 @@ function Color(el, options) {
15674
15754
  } else {
15675
15755
  obj.open();
15676
15756
  }
15677
- });
15757
+ };
15758
+ container.addEventListener("click", containerClickHandler);
15678
15759
 
15679
15760
  /**
15680
15761
  * If element is focus open the picker
15681
15762
  */
15682
- el.addEventListener("mouseup", function(e) {
15763
+ elMouseupHandler = function(e) {
15683
15764
  obj.open();
15684
- });
15765
+ };
15766
+ el.addEventListener("mouseup", elMouseupHandler);
15685
15767
 
15686
15768
  // If the picker is open on the spectrum tab, it changes the canvas size when the window size is changed
15687
- window.addEventListener('resize', function() {
15769
+ windowResizeHandler = function() {
15688
15770
  if (container.classList.contains('jcolor-focus') && jsuitesTabs.getActive() == 1) {
15689
15771
  resizeCanvas();
15690
15772
  }
15691
- });
15773
+ };
15774
+ window.addEventListener('resize', windowResizeHandler);
15692
15775
 
15693
15776
  // Default opened
15694
15777
  if (obj.options.opened == true) {
@@ -15732,6 +15815,73 @@ function Color(el, options) {
15732
15815
  }
15733
15816
  }
15734
15817
 
15818
+ // Store event handler references for cleanup
15819
+ var containerClickHandler = null;
15820
+ var elMouseupHandler = null;
15821
+ var windowResizeHandler = null;
15822
+
15823
+ /**
15824
+ * Destroy the color picker instance and release all resources
15825
+ */
15826
+ obj.destroy = function() {
15827
+ // Close if open (removes from tracking)
15828
+ obj.close(true);
15829
+
15830
+ // Remove event listeners
15831
+ if (container && containerClickHandler) {
15832
+ container.removeEventListener('click', containerClickHandler);
15833
+ }
15834
+ if (el && elMouseupHandler) {
15835
+ el.removeEventListener('mouseup', elMouseupHandler);
15836
+ }
15837
+ if (windowResizeHandler) {
15838
+ window.removeEventListener('resize', windowResizeHandler);
15839
+ }
15840
+
15841
+ // Destroy the tabs component if it has destroy method
15842
+ if (jsuitesTabs && typeof jsuitesTabs.destroy === 'function') {
15843
+ jsuitesTabs.destroy();
15844
+ }
15845
+
15846
+ // Clear rgbInputs references
15847
+ rgbInputs = [];
15848
+
15849
+ // Remove container from DOM
15850
+ if (container && container.parentNode) {
15851
+ container.parentNode.removeChild(container);
15852
+ }
15853
+
15854
+ // Clean up element
15855
+ if (el.tagName === 'INPUT') {
15856
+ el.classList.remove('jcolor-input');
15857
+ el.readOnly = false;
15858
+ el.style.color = '';
15859
+ el.style.backgroundColor = '';
15860
+ }
15861
+
15862
+ // Remove instance properties from el
15863
+ delete el.color;
15864
+ delete el.change;
15865
+ delete el.val;
15866
+
15867
+ // Clear options callbacks to release closures
15868
+ if (obj.options) {
15869
+ obj.options.onchange = null;
15870
+ obj.options.onclose = null;
15871
+ obj.options.onopen = null;
15872
+ obj.options.onload = null;
15873
+ }
15874
+
15875
+ // Clear references
15876
+ container = null;
15877
+ backdrop = null;
15878
+ content = null;
15879
+ resetButton = null;
15880
+ closeButton = null;
15881
+ tabs = null;
15882
+ jsuitesTabs = null;
15883
+ }
15884
+
15735
15885
  init();
15736
15886
 
15737
15887
  return obj;
@@ -18108,6 +18258,58 @@ function Picker(el, options) {
18108
18258
  }
18109
18259
  }
18110
18260
 
18261
+ /**
18262
+ * Destroy the picker instance and release all resources
18263
+ */
18264
+ obj.destroy = function() {
18265
+ // Close if open (removes from tracking)
18266
+ obj.close();
18267
+
18268
+ // Remove event listeners
18269
+ el.onmousedown = null;
18270
+ if (dropdownContent) {
18271
+ dropdownContent.onclick = null;
18272
+ }
18273
+
18274
+ // Remove created DOM elements
18275
+ if (dropdownHeader && dropdownHeader.parentNode) {
18276
+ dropdownHeader.parentNode.removeChild(dropdownHeader);
18277
+ }
18278
+ if (dropdownContent && dropdownContent.parentNode) {
18279
+ dropdownContent.parentNode.removeChild(dropdownContent);
18280
+ }
18281
+
18282
+ // Remove classes and attributes from el
18283
+ el.classList.remove('jpicker');
18284
+ el.classList.remove('jpicker-focus');
18285
+ el.removeAttribute('role');
18286
+ el.removeAttribute('aria-haspopup');
18287
+ el.removeAttribute('aria-expanded');
18288
+ el.removeAttribute('aria-controls');
18289
+ el.removeAttribute('tabindex');
18290
+
18291
+ // Remove instance properties from el
18292
+ delete el.picker;
18293
+ delete el.value;
18294
+ delete el.change;
18295
+ delete el.val;
18296
+
18297
+ // Clear options callbacks to release closures
18298
+ if (obj.options) {
18299
+ obj.options.onchange = null;
18300
+ obj.options.onclose = null;
18301
+ obj.options.onopen = null;
18302
+ obj.options.onload = null;
18303
+ obj.options.onselect = null;
18304
+ obj.options.onmouseover = null;
18305
+ obj.options.render = null;
18306
+ }
18307
+
18308
+ // Clear references
18309
+ dropdownHeader = null;
18310
+ dropdownContent = null;
18311
+ }
18312
+
18111
18313
  /**
18112
18314
  * Create floating picker
18113
18315
  */
@@ -18190,6 +18392,13 @@ function Toolbar(el, options) {
18190
18392
  var obj = { type:'toolbar' };
18191
18393
  obj.options = {};
18192
18394
 
18395
+ // Track internal components for cleanup
18396
+ var internalComponents = [];
18397
+
18398
+ // Event handler references for cleanup
18399
+ var elClickHandler = null;
18400
+ var windowResizeHandler = null;
18401
+
18193
18402
  // Default configuration
18194
18403
  var defaults = {
18195
18404
  app: null,
@@ -18260,8 +18469,88 @@ function Toolbar(el, options) {
18260
18469
  }
18261
18470
 
18262
18471
  obj.destroy = function() {
18263
- toolbar.remove();
18472
+ // Close if open (removes from tracking)
18473
+ obj.close();
18474
+
18475
+ // Destroy all internal components (pickers, etc.)
18476
+ for (var i = 0; i < internalComponents.length; i++) {
18477
+ var comp = internalComponents[i];
18478
+ if (comp) {
18479
+ // First destroy any nested components created in onload (stored on the picker instance)
18480
+ if (comp.components && comp.components.length) {
18481
+ for (var j = 0; j < comp.components.length; j++) {
18482
+ if (comp.components[j] && typeof comp.components[j].destroy === 'function') {
18483
+ comp.components[j].destroy();
18484
+ }
18485
+ }
18486
+ comp.components = null;
18487
+ }
18488
+ // Then destroy the picker/component itself
18489
+ if (typeof comp.destroy === 'function') {
18490
+ comp.destroy();
18491
+ }
18492
+ }
18493
+ }
18494
+ internalComponents = [];
18495
+
18496
+ // Clear onclick handlers from DOM elements (releases bound function references)
18497
+ if (toolbarContent) {
18498
+ var items = toolbarContent.querySelectorAll('.jtoolbar-item');
18499
+ for (var i = 0; i < items.length; i++) {
18500
+ items[i].onclick = null;
18501
+ items[i].updateState = null;
18502
+ }
18503
+ }
18504
+ if (toolbarFloating) {
18505
+ var items = toolbarFloating.querySelectorAll('.jtoolbar-item');
18506
+ for (var i = 0; i < items.length; i++) {
18507
+ items[i].onclick = null;
18508
+ items[i].updateState = null;
18509
+ }
18510
+ }
18511
+
18512
+ // Clear options items callbacks to release closures
18513
+ if (obj.options && obj.options.items) {
18514
+ for (var i = 0; i < obj.options.items.length; i++) {
18515
+ var item = obj.options.items[i];
18516
+ // Clear all callback references
18517
+ item.onclick = null;
18518
+ item.onchange = null;
18519
+ item.onload = null;
18520
+ item.render = null;
18521
+ item.updateState = null;
18522
+ item.onopen = null;
18523
+ item.onclose = null;
18524
+ }
18525
+ obj.options.items = null;
18526
+ }
18527
+
18528
+ // Remove event listeners
18529
+ if (elClickHandler) {
18530
+ el.removeEventListener('click', elClickHandler);
18531
+ elClickHandler = null;
18532
+ }
18533
+ if (windowResizeHandler) {
18534
+ window.removeEventListener('resize', windowResizeHandler);
18535
+ windowResizeHandler = null;
18536
+ }
18537
+
18538
+ // Clear DOM
18264
18539
  el.innerHTML = '';
18540
+
18541
+ // Clear references
18542
+ toolbarContent = null;
18543
+ toolbarFloating = null;
18544
+ toolbarArrow = null;
18545
+
18546
+ // Remove classes
18547
+ el.classList.remove('jtoolbar');
18548
+ el.classList.remove('jtoolbar-container');
18549
+ el.classList.remove('jtoolbar-mobile');
18550
+ el.classList.remove('jtoolbar-disabled');
18551
+
18552
+ // Remove instance reference
18553
+ delete el.toolbar;
18265
18554
  }
18266
18555
 
18267
18556
  obj.update = function(a, b) {
@@ -18323,7 +18612,8 @@ function Toolbar(el, options) {
18323
18612
  }
18324
18613
 
18325
18614
  if (items[i].type == 'select' || items[i].type == 'dropdown') {
18326
- Picker(toolbarItem, items[i]);
18615
+ var picker = Picker(toolbarItem, items[i]);
18616
+ internalComponents.push(picker);
18327
18617
  } else if (items[i].type == 'divisor') {
18328
18618
  toolbarItem.classList.add('jtoolbar-divisor');
18329
18619
  } else if (items[i].type == 'label') {
@@ -18417,7 +18707,9 @@ function Toolbar(el, options) {
18417
18707
  }
18418
18708
 
18419
18709
  obj.close = function() {
18420
- toolbarArrow.classList.remove('jtoolbar-arrow-selected')
18710
+ if (toolbarArrow) {
18711
+ toolbarArrow.classList.remove('jtoolbar-arrow-selected')
18712
+ }
18421
18713
  // End tracking
18422
18714
  tracking(obj, false);
18423
18715
  }
@@ -18460,7 +18752,7 @@ function Toolbar(el, options) {
18460
18752
  el.classList[state]('jtoolbar-disabled');
18461
18753
  }
18462
18754
 
18463
- el.onclick = function(e) {
18755
+ elClickHandler = function(e) {
18464
18756
  var element = helpers.findElement(e.target, 'jtoolbar-item');
18465
18757
  if (element) {
18466
18758
  obj.selectItem(element);
@@ -18469,11 +18761,13 @@ function Toolbar(el, options) {
18469
18761
  if (e.target.classList.contains('jtoolbar-arrow') || e.target.parentNode.classList.contains('jtoolbar-arrow')) {
18470
18762
  obj.open();
18471
18763
  }
18472
- }
18764
+ };
18765
+ el.addEventListener('click', elClickHandler);
18473
18766
 
18474
- window.addEventListener('resize', function() {
18767
+ windowResizeHandler = function() {
18475
18768
  obj.refresh();
18476
- });
18769
+ };
18770
+ window.addEventListener('resize', windowResizeHandler);
18477
18771
 
18478
18772
  // Toolbar
18479
18773
  el.classList.add('jtoolbar');
@@ -23149,7 +23443,7 @@ var jSuites = {
23149
23443
  ...dictionary,
23150
23444
  ...helpers,
23151
23445
  /** Current version */
23152
- version: '6.2.1',
23446
+ version: '6.3.1',
23153
23447
  /** Bind new extensions to Jsuites */
23154
23448
  setExtensions: function(o) {
23155
23449
  if (typeof(o) == 'object') {
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": "6.2.1",
29
+ "version": "6.3.1",
30
30
  "bugs": "https://github.com/jsuites/jsuites/issues",
31
31
  "homepage": "https://github.com/jsuites/jsuites",
32
32
  "docs": "https://jsuites.net",