native-document 1.0.162 → 1.0.164

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.
@@ -1344,6 +1344,10 @@ var NativeComponents = (function (exports) {
1344
1344
  return new ObservableArray(this.resolve());
1345
1345
  };
1346
1346
 
1347
+ ObservableArray.prototype.isNotEmpty = function () {
1348
+ return this.is((x) => x.length > 0);
1349
+ };
1350
+
1347
1351
  const ObservableObject = function(target, configs) {
1348
1352
  ObservableItem.call(this, target);
1349
1353
  this.$observables = {};
@@ -1623,7 +1627,7 @@ var NativeComponents = (function (exports) {
1623
1627
  };
1624
1628
 
1625
1629
  ObservableItem.prototype.isNotEmpty = function () {
1626
- return $checker(this, x => x == null || x === '' || (Array.isArray(x) && x.length !== 0));
1630
+ return $checker(this, x => x != null && x !== '' && !(Array.isArray(x) && x.length === 0));
1627
1631
  };
1628
1632
 
1629
1633
  ObservableItem.prototype.isIncludes = function (value) {
@@ -2211,6 +2215,10 @@ var NativeComponents = (function (exports) {
2211
2215
  });
2212
2216
  };
2213
2217
 
2218
+ Observable.setLocale = function(locale) {
2219
+ Formatters.locale = locale.__$Observable ? locale : Observable(locale);
2220
+ };
2221
+
2214
2222
 
2215
2223
  /**
2216
2224
  *
@@ -2376,10 +2384,6 @@ var NativeComponents = (function (exports) {
2376
2384
  return data;
2377
2385
  };
2378
2386
 
2379
- ObservableItem.prototype.resolve = function () {
2380
- return Observable.value(this);
2381
- };
2382
-
2383
2387
  Observable.object = Observable.init;
2384
2388
  Observable.json = Observable.init;
2385
2389
 
@@ -2392,6 +2396,10 @@ var NativeComponents = (function (exports) {
2392
2396
  return new ObservableResource(fn, deps, config);
2393
2397
  };
2394
2398
 
2399
+ ObservableItem.prototype.resolve = function () {
2400
+ return Observable.value(this);
2401
+ };
2402
+
2395
2403
  const BOOLEAN_ATTRIBUTES = new Set([
2396
2404
  'checked',
2397
2405
  'selected',
@@ -3299,6 +3307,23 @@ var NativeComponents = (function (exports) {
3299
3307
  return this;
3300
3308
  };
3301
3309
 
3310
+ NDElement.prototype.destroyOnUnmount = function() {
3311
+ this.unmounted(() => {
3312
+ this.$element?.querySelectorAll('[data--nd-before-unmount]').forEach(child => {
3313
+ child.remove();
3314
+ child.__$controller?.abort();
3315
+ child.__$controller = null;
3316
+ $lifeCycleObservers.delete(child);
3317
+ });
3318
+
3319
+ this.$element.__$controller?.abort();
3320
+ this.$element.__$controller = null;
3321
+ $lifeCycleObservers.delete(this.$element);
3322
+ this.$element = null;
3323
+ });
3324
+ return this;
3325
+ };
3326
+
3302
3327
  NDElement.prototype.mounted = function(callback) {
3303
3328
  return this.lifecycle({ mounted: callback });
3304
3329
  };
@@ -3315,6 +3340,7 @@ var NativeComponents = (function (exports) {
3315
3340
  const originalRemove = el.remove.bind(el);
3316
3341
 
3317
3342
  let $isUnmounting = false;
3343
+ this.$element.setAttribute('data--nd-before-unmount', '1');
3318
3344
 
3319
3345
  el.remove = async () => {
3320
3346
  if($isUnmounting) {
@@ -3408,6 +3434,7 @@ var NativeComponents = (function (exports) {
3408
3434
  return this;
3409
3435
  }
3410
3436
  this.$element.setAttribute(name, value);
3437
+ return this;
3411
3438
  };
3412
3439
 
3413
3440
  NDElement.prototype.attrs = function(attrs) {
@@ -12119,62 +12146,107 @@ var NativeComponents = (function (exports) {
12119
12146
  // ----------------------------------------------------------------
12120
12147
  EVENTS.forEach(eventSourceName => {
12121
12148
  const eventName = eventSourceName.toLowerCase();
12122
- NDElement.prototype['on'+eventSourceName] = function(callback = null) {
12123
- this.$element.addEventListener(eventName, callback);
12149
+ NDElement.prototype['on'+eventSourceName] = function(callback = null, options = {}) {
12150
+ this.$element.addEventListener(eventName, callback, {
12151
+ signal: this.$getSignal(),
12152
+ ...options
12153
+ });
12124
12154
  return this;
12125
12155
  };
12126
12156
  });
12127
12157
 
12128
12158
  EVENTS_WITH_STOP.forEach(eventSourceName => {
12129
12159
  const eventName = eventSourceName.toLowerCase();
12130
- NDElement.prototype['onStop'+eventSourceName] = function(callback = null) {
12131
- _stop(this.$element, eventName, callback);
12160
+ NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options = {}) {
12161
+ _stop(this.$element, eventName, callback, {
12162
+ signal: this.$getSignal(),
12163
+ ...options
12164
+ });
12132
12165
  return this;
12133
12166
  };
12134
- NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null) {
12135
- _preventStop(this.$element, eventName, callback);
12167
+ NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options = {}) {
12168
+ _preventStop(this.$element, eventName, callback, {
12169
+ signal: this.$getSignal(),
12170
+ ...options
12171
+ });
12136
12172
  return this;
12137
12173
  };
12138
12174
  });
12139
12175
 
12140
12176
  EVENTS_WITH_PREVENT.forEach(eventSourceName => {
12141
12177
  const eventName = eventSourceName.toLowerCase();
12142
- NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null) {
12143
- _prevent(this.$element, eventName, callback);
12178
+ NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options = {}) {
12179
+ _prevent(this.$element, eventName, callback, {
12180
+ signal: this.$getSignal(),
12181
+ ...options
12182
+ });
12144
12183
  return this;
12145
12184
  };
12146
12185
  });
12147
12186
 
12187
+ NDElement.prototype.$getSignal = function() {
12188
+ if(!this.$element.__$controller) {
12189
+ this.$element.__$controller = new AbortController();
12190
+ }
12191
+ return this.$element.__$controller.signal;
12192
+ };
12193
+
12148
12194
  NDElement.prototype.on = function(name, callback, options) {
12149
- this.$element.addEventListener(name.toLowerCase(), callback, options);
12195
+ this.$element.addEventListener(name.toLowerCase(), callback, {
12196
+ signal: this.$getSignal(),
12197
+ ...options
12198
+ });
12199
+ return this;
12200
+ };
12201
+
12202
+ NDElement.prototype.off = function(name, callback) {
12203
+ this.$element.removeEventListener(name.toLowerCase(), callback);
12204
+ return this;
12205
+ };
12206
+
12207
+ NDElement.prototype.once = function(name, callback) {
12208
+ this.$element.addEventListener(name.toLowerCase(), callback, {
12209
+ signal: this.$getSignal(),
12210
+ once: true
12211
+ });
12212
+ return this;
12213
+ };
12214
+
12215
+ NDElement.prototype.emit = function(name, detail = null) {
12216
+ const event = new CustomEvent(name, {
12217
+ detail,
12218
+ bubbles: true,
12219
+ cancelable: true,
12220
+ });
12221
+ this.$element.dispatchEvent(event);
12150
12222
  return this;
12151
12223
  };
12152
12224
 
12153
- const _prevent = function(element, eventName, callback) {
12225
+ const _prevent = function(element, eventName, callback, options) {
12154
12226
  const handler = (event) => {
12155
12227
  event.preventDefault();
12156
12228
  callback && callback.call(element, event);
12157
12229
  };
12158
- element.addEventListener(eventName, handler);
12230
+ element.addEventListener(eventName, handler, options);
12159
12231
  return this;
12160
12232
  };
12161
12233
 
12162
- const _stop = function(element, eventName, callback) {
12234
+ const _stop = function(element, eventName, callback, options) {
12163
12235
  const handler = (event) => {
12164
12236
  event.stopPropagation();
12165
12237
  callback && callback.call(element, event);
12166
12238
  };
12167
- element.addEventListener(eventName, handler);
12239
+ element.addEventListener(eventName, handler, options);
12168
12240
  return this;
12169
12241
  };
12170
12242
 
12171
- const _preventStop = function(element, eventName, callback) {
12243
+ const _preventStop = function(element, eventName, callback, options) {
12172
12244
  const handler = (event) => {
12173
12245
  event.stopPropagation();
12174
12246
  event.preventDefault();
12175
12247
  callback && callback.call(element, event);
12176
12248
  };
12177
- element.addEventListener(eventName, handler);
12249
+ element.addEventListener(eventName, handler, options);
12178
12250
  return this;
12179
12251
  };
12180
12252
 
@@ -1797,6 +1797,10 @@ var NativeDocument = (function (exports) {
1797
1797
  return new ObservableArray(this.resolve());
1798
1798
  };
1799
1799
 
1800
+ ObservableArray.prototype.isNotEmpty = function () {
1801
+ return this.is((x) => x.length > 0);
1802
+ };
1803
+
1800
1804
  const ObservableObject = function(target, configs) {
1801
1805
  ObservableItem.call(this, target);
1802
1806
  this.$observables = {};
@@ -2076,7 +2080,7 @@ var NativeDocument = (function (exports) {
2076
2080
  };
2077
2081
 
2078
2082
  ObservableItem.prototype.isNotEmpty = function () {
2079
- return $checker(this, x => x == null || x === '' || (Array.isArray(x) && x.length !== 0));
2083
+ return $checker(this, x => x != null && x !== '' && !(Array.isArray(x) && x.length === 0));
2080
2084
  };
2081
2085
 
2082
2086
  ObservableItem.prototype.isIncludes = function (value) {
@@ -2676,6 +2680,10 @@ var NativeDocument = (function (exports) {
2676
2680
  });
2677
2681
  };
2678
2682
 
2683
+ Observable.setLocale = function(locale) {
2684
+ Formatters.locale = locale.__$Observable ? locale : Observable(locale);
2685
+ };
2686
+
2679
2687
 
2680
2688
  /**
2681
2689
  *
@@ -2844,10 +2852,6 @@ var NativeDocument = (function (exports) {
2844
2852
  return data;
2845
2853
  };
2846
2854
 
2847
- ObservableItem.prototype.resolve = function () {
2848
- return Observable.value(this);
2849
- };
2850
-
2851
2855
  Observable.object = Observable.init;
2852
2856
  Observable.json = Observable.init;
2853
2857
 
@@ -2860,6 +2864,10 @@ var NativeDocument = (function (exports) {
2860
2864
  return new ObservableResource(fn, deps, config);
2861
2865
  };
2862
2866
 
2867
+ ObservableItem.prototype.resolve = function () {
2868
+ return Observable.value(this);
2869
+ };
2870
+
2863
2871
  /**
2864
2872
  *
2865
2873
  * @param {HTMLElement} element
@@ -3829,6 +3837,23 @@ var NativeDocument = (function (exports) {
3829
3837
  return this;
3830
3838
  };
3831
3839
 
3840
+ NDElement.prototype.destroyOnUnmount = function() {
3841
+ this.unmounted(() => {
3842
+ this.$element?.querySelectorAll('[data--nd-before-unmount]').forEach(child => {
3843
+ child.remove();
3844
+ child.__$controller?.abort();
3845
+ child.__$controller = null;
3846
+ $lifeCycleObservers.delete(child);
3847
+ });
3848
+
3849
+ this.$element.__$controller?.abort();
3850
+ this.$element.__$controller = null;
3851
+ $lifeCycleObservers.delete(this.$element);
3852
+ this.$element = null;
3853
+ });
3854
+ return this;
3855
+ };
3856
+
3832
3857
  NDElement.prototype.mounted = function(callback) {
3833
3858
  return this.lifecycle({ mounted: callback });
3834
3859
  };
@@ -3845,6 +3870,7 @@ var NativeDocument = (function (exports) {
3845
3870
  const originalRemove = el.remove.bind(el);
3846
3871
 
3847
3872
  let $isUnmounting = false;
3873
+ this.$element.setAttribute('data--nd-before-unmount', '1');
3848
3874
 
3849
3875
  el.remove = async () => {
3850
3876
  if($isUnmounting) {
@@ -3949,6 +3975,7 @@ var NativeDocument = (function (exports) {
3949
3975
  return this;
3950
3976
  }
3951
3977
  this.$element.setAttribute(name, value);
3978
+ return this;
3952
3979
  };
3953
3980
 
3954
3981
  NDElement.prototype.attrs = function(attrs) {
@@ -4203,62 +4230,107 @@ var NativeDocument = (function (exports) {
4203
4230
  // ----------------------------------------------------------------
4204
4231
  EVENTS.forEach(eventSourceName => {
4205
4232
  const eventName = eventSourceName.toLowerCase();
4206
- NDElement.prototype['on'+eventSourceName] = function(callback = null) {
4207
- this.$element.addEventListener(eventName, callback);
4233
+ NDElement.prototype['on'+eventSourceName] = function(callback = null, options = {}) {
4234
+ this.$element.addEventListener(eventName, callback, {
4235
+ signal: this.$getSignal(),
4236
+ ...options
4237
+ });
4208
4238
  return this;
4209
4239
  };
4210
4240
  });
4211
4241
 
4212
4242
  EVENTS_WITH_STOP.forEach(eventSourceName => {
4213
4243
  const eventName = eventSourceName.toLowerCase();
4214
- NDElement.prototype['onStop'+eventSourceName] = function(callback = null) {
4215
- _stop(this.$element, eventName, callback);
4244
+ NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options = {}) {
4245
+ _stop(this.$element, eventName, callback, {
4246
+ signal: this.$getSignal(),
4247
+ ...options
4248
+ });
4216
4249
  return this;
4217
4250
  };
4218
- NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null) {
4219
- _preventStop(this.$element, eventName, callback);
4251
+ NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options = {}) {
4252
+ _preventStop(this.$element, eventName, callback, {
4253
+ signal: this.$getSignal(),
4254
+ ...options
4255
+ });
4220
4256
  return this;
4221
4257
  };
4222
4258
  });
4223
4259
 
4224
4260
  EVENTS_WITH_PREVENT.forEach(eventSourceName => {
4225
4261
  const eventName = eventSourceName.toLowerCase();
4226
- NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null) {
4227
- _prevent(this.$element, eventName, callback);
4262
+ NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options = {}) {
4263
+ _prevent(this.$element, eventName, callback, {
4264
+ signal: this.$getSignal(),
4265
+ ...options
4266
+ });
4228
4267
  return this;
4229
4268
  };
4230
4269
  });
4231
4270
 
4271
+ NDElement.prototype.$getSignal = function() {
4272
+ if(!this.$element.__$controller) {
4273
+ this.$element.__$controller = new AbortController();
4274
+ }
4275
+ return this.$element.__$controller.signal;
4276
+ };
4277
+
4232
4278
  NDElement.prototype.on = function(name, callback, options) {
4233
- this.$element.addEventListener(name.toLowerCase(), callback, options);
4279
+ this.$element.addEventListener(name.toLowerCase(), callback, {
4280
+ signal: this.$getSignal(),
4281
+ ...options
4282
+ });
4283
+ return this;
4284
+ };
4285
+
4286
+ NDElement.prototype.off = function(name, callback) {
4287
+ this.$element.removeEventListener(name.toLowerCase(), callback);
4234
4288
  return this;
4235
4289
  };
4236
4290
 
4237
- const _prevent = function(element, eventName, callback) {
4291
+ NDElement.prototype.once = function(name, callback) {
4292
+ this.$element.addEventListener(name.toLowerCase(), callback, {
4293
+ signal: this.$getSignal(),
4294
+ once: true
4295
+ });
4296
+ return this;
4297
+ };
4298
+
4299
+ NDElement.prototype.emit = function(name, detail = null) {
4300
+ const event = new CustomEvent(name, {
4301
+ detail,
4302
+ bubbles: true,
4303
+ cancelable: true,
4304
+ });
4305
+ this.$element.dispatchEvent(event);
4306
+ return this;
4307
+ };
4308
+
4309
+ const _prevent = function(element, eventName, callback, options) {
4238
4310
  const handler = (event) => {
4239
4311
  event.preventDefault();
4240
4312
  callback && callback.call(element, event);
4241
4313
  };
4242
- element.addEventListener(eventName, handler);
4314
+ element.addEventListener(eventName, handler, options);
4243
4315
  return this;
4244
4316
  };
4245
4317
 
4246
- const _stop = function(element, eventName, callback) {
4318
+ const _stop = function(element, eventName, callback, options) {
4247
4319
  const handler = (event) => {
4248
4320
  event.stopPropagation();
4249
4321
  callback && callback.call(element, event);
4250
4322
  };
4251
- element.addEventListener(eventName, handler);
4323
+ element.addEventListener(eventName, handler, options);
4252
4324
  return this;
4253
4325
  };
4254
4326
 
4255
- const _preventStop = function(element, eventName, callback) {
4327
+ const _preventStop = function(element, eventName, callback, options) {
4256
4328
  const handler = (event) => {
4257
4329
  event.stopPropagation();
4258
4330
  event.preventDefault();
4259
4331
  callback && callback.call(element, event);
4260
4332
  };
4261
- element.addEventListener(eventName, handler);
4333
+ element.addEventListener(eventName, handler, options);
4262
4334
  return this;
4263
4335
  };
4264
4336
 
@@ -4868,27 +4940,30 @@ var NativeDocument = (function (exports) {
4868
4940
  if(!$cacheNode) {
4869
4941
  $cacheNode = $viewCreator(this);
4870
4942
  }
4871
- if(!$components) {
4872
- return $cacheNode;
4873
- }
4874
- for(const index in $components) {
4875
- const updater = $components[index];
4876
- updater(...data);
4943
+ if(!$components) return $cacheNode;
4944
+
4945
+ const updates = data[0];
4946
+ if(updates && typeof updates === 'object') {
4947
+ for(const key in updates) {
4948
+ if($components[key]) {
4949
+ $components[key](updates[key]);
4950
+ }
4951
+ }
4877
4952
  }
4878
4953
  return $cacheNode;
4879
4954
  };
4880
4955
 
4881
4956
  this.createSection = (name, fn) => {
4882
4957
  $components = $components || {};
4883
- const anchor = Anchor('Component '+name);
4958
+ const anchor = Anchor('Component ' + name);
4884
4959
 
4885
- $components[name] = function(...args) {
4960
+ $components[name] = function(content) {
4886
4961
  anchor.removeChildren();
4887
4962
  if(!fn) {
4888
- anchor.append(args);
4963
+ anchor.append(content);
4889
4964
  return;
4890
4965
  }
4891
- anchor.appendChild(fn(...args));
4966
+ anchor.appendChild(fn(content));
4892
4967
  };
4893
4968
  return anchor;
4894
4969
  };
@@ -5783,7 +5858,7 @@ var NativeDocument = (function (exports) {
5783
5858
  }
5784
5859
  }
5785
5860
  child = null;
5786
- element.appendElementRaw(fragment);
5861
+ element.appendChildRaw(fragment);
5787
5862
  },
5788
5863
  removeOne: (element, index) => {
5789
5864
  removeCacheItem(element, true);
@@ -7190,7 +7265,25 @@ var NativeDocument = (function (exports) {
7190
7265
  });
7191
7266
 
7192
7267
  const RouteParamPatterns = {
7268
+ id: '[0-9]+',
7269
+ uuid: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',
7270
+ slug: '[a-z0-9]+(?:-[a-z0-9]+)*',
7271
+ hash: '[a-f0-9]{32,64}',
7272
+
7273
+ alpha: '[a-zA-Z]+',
7274
+ alphanum: '[a-zA-Z0-9]+',
7275
+ string: '[^/]+',
7276
+ any: '.*',
7277
+
7278
+ int: '[0-9]+',
7279
+ float: '[0-9]+\\.[0-9]+',
7280
+ number: '[0-9]+(\\.[0-9]+)?',
7281
+ positive: '[1-9][0-9]*',
7193
7282
 
7283
+ locale: '[a-z]{2}(-[A-Z]{2})?',
7284
+ lang: '[a-z]{2}',
7285
+
7286
+ token: '[A-Za-z0-9_\\-]+',
7194
7287
  };
7195
7288
 
7196
7289
  /**
@@ -7610,9 +7703,7 @@ var NativeDocument = (function (exports) {
7610
7703
  };
7611
7704
 
7612
7705
  const removeLastNodeInserted = () => {
7613
- if(Validator.isAnchor($lastNodeInserted)) {
7614
- $lastNodeInserted.remove();
7615
- }
7706
+ $lastNodeInserted?.remove();
7616
7707
  };
7617
7708
 
7618
7709
  const cleanContainer = () => {