@cntwg/html-helper 0.0.16 → 0.0.17

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,4 +1,4 @@
1
- // [v0.1.051-20221009]
1
+ // [v0.1.053-20221022]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -232,19 +232,21 @@ class THtmlItemsListContainer {
232
232
  return isSUCCEED ? index : -1;
233
233
  }
234
234
 
235
- delItem(index, opt){
236
- const forceCI = typeof opt === 'boolean' ? opt : true;
235
+ delItem(index, opt, optEx){
237
236
  const _items = this.#_items;
238
- const item = _items.delItemEx(index, forceCI);
239
- const isSUCCEED = isHTMLElement(item);
237
+ const item = _items.delItemEx(index, opt);
238
+ const isSUCCEED = item !== undefined;
240
239
  if (isSUCCEED) {
241
- const index = _items.curIndex;
242
- if (index === -1) {
243
- this.rstCurIndex();
244
- } else {
245
- this.setCurIndex(_items.curIndex);
240
+ if (this.#_host && isHTMLElement(item)) item.remove();
241
+ const doProcEx = typeof optEx === 'boolean' ? optEx : true;
242
+ if (doProcEx) {
243
+ const index = _items.curIndex;
244
+ if (index === -1) {
245
+ this.rstCurIndex();
246
+ } else {
247
+ this.setCurIndex(index);
248
+ };
246
249
  };
247
- if (this.#_host) item.remove();
248
250
  };
249
251
  return isSUCCEED;
250
252
  }
@@ -509,38 +511,44 @@ class THtmlItemsListController extends THtmlItemsListContainer {
509
511
 
510
512
  delItem(index, opt){
511
513
  const item = super.getItem(index);
514
+ let isSUCCEED = item !== undefined;
512
515
  const _status = this.#_status;
513
- let isSUCCEED = isHTMLElement(item);
514
516
  if (isSUCCEED) {
515
517
  _status.execDelItem = true;
516
518
  _status.execDelItemCI = this.curIndex;
517
519
  _status.execDelItemDI = Number(index);
518
- isSUCCEED = super.delItem(index, opt);
520
+ isSUCCEED = super.delItem(index, opt, false);
521
+ if (isSUCCEED) {
522
+ const _options = this.#_options;
523
+ if (!_status.catchEventOnHost && isHTMLElement(item)) {
524
+ // remove event handler on element if it was set by addItem()
525
+ item.removeEventListener('click', this.#_on_will_select_item);
526
+ };
527
+ if (this.isEmpty()) {
528
+ this.#_selects.clear();
529
+ if (_options.showStubsIfEmpty) {
530
+ // show default stub-item
531
+ _status.isStubItemShown = this.#_stubs.showDefItem();
532
+ };
533
+ this.#_triggerEvent('list-clear');
534
+ } else {
535
+ this.#_selects.delete(item);
536
+ this.#_triggerEvent('item-removed', {
537
+ index: Number(index),
538
+ item: item,
539
+ });
540
+ const current = this.curIndex;
541
+ if (current === -1) {
542
+ this.rstCurIndex();
543
+ } else {
544
+ this.setCurIndex(current);
545
+ };
546
+ };
547
+ };
519
548
  _status.execDelItemDI = -1;
520
549
  _status.execDelItemCI = -1;
521
550
  _status.execDelItem = false;
522
551
  };
523
- if (isSUCCEED) {
524
- const _options = this.#_options;
525
- if (!_status.catchEventOnHost) {
526
- // remove event handler on element if it was set by addItem()
527
- item.removeEventListener('click', this.#_on_will_select_item);
528
- };
529
- if (this.isEmpty()) {
530
- this.#_selects.clear();
531
- if (_options.showStubsIfEmpty) {
532
- // show default stub-item
533
- _status.isStubItemShown = this.#_stubs.showDefItem();
534
- };
535
- this.#_triggerEvent('list-clear');
536
- } else {
537
- this.#_selects.delete(item);
538
- this.#_triggerEvent('item-removed', {
539
- index: Number(index),
540
- item: item,
541
- });
542
- };
543
- };
544
552
  return isSUCCEED;
545
553
  }
546
554
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-helper",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "A base HTML-helper library for js",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",