native-document 1.0.98 → 1.0.99

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.
@@ -10,6 +10,6 @@ export const DevToolsPlugin = {
10
10
  name: 'DevTools',
11
11
  onCreateObservable(observable) {
12
12
  DevToolService.createdObservable.set((last) => ++last);
13
- console.log('Création Capturé', observable.$value);
13
+ // console.log('Création Capturé', observable.$value);
14
14
  }
15
15
  };
@@ -1,5 +1,9 @@
1
1
 
2
2
  function Observable(name, instance, value, ...args) {
3
+ if(value === undefined) {
4
+ value = name;
5
+ name = 'unknown';
6
+ }
3
7
  if(!instance?.context) {
4
8
  return __OriginalObservable__(value, ...args);
5
9
  }
@@ -21,6 +25,10 @@ function Observable(name, instance, value, ...args) {
21
25
  };
22
26
 
23
27
  Observable.init = function(name, instance, value, ...args) {
28
+ if(value === undefined) {
29
+ value = name;
30
+ name = 'unknown';
31
+ }
24
32
  if(!instance?.context) {
25
33
  return __OriginalObservable__.init(value, ...args);
26
34
  }
@@ -1374,7 +1374,7 @@ var NativeComponents = (function (exports) {
1374
1374
  return cloned;
1375
1375
  };
1376
1376
 
1377
- const LocalStorage$1 = {
1377
+ const LocalStorage = {
1378
1378
  getJson(key) {
1379
1379
  let value = localStorage.getItem(key);
1380
1380
  try {
@@ -1410,23 +1410,23 @@ var NativeComponents = (function (exports) {
1410
1410
  }
1411
1411
  };
1412
1412
 
1413
- const $getFromStorage$1 = (key, value) => {
1414
- if(!LocalStorage$1.has(key)) {
1413
+ const $getFromStorage = (key, value) => {
1414
+ if(!LocalStorage.has(key)) {
1415
1415
  return value;
1416
1416
  }
1417
1417
  switch (typeof value) {
1418
- case 'object': return LocalStorage$1.getJson(key) ?? value;
1419
- case 'boolean': return LocalStorage$1.getBool(key) ?? value;
1420
- case 'number': return LocalStorage$1.getNumber(key) ?? value;
1421
- default: return LocalStorage$1.get(key, value) ?? value;
1418
+ case 'object': return LocalStorage.getJson(key) ?? value;
1419
+ case 'boolean': return LocalStorage.getBool(key) ?? value;
1420
+ case 'number': return LocalStorage.getNumber(key) ?? value;
1421
+ default: return LocalStorage.get(key, value) ?? value;
1422
1422
  }
1423
1423
  };
1424
1424
 
1425
- const $saveToStorage$1 = (value) => {
1425
+ const $saveToStorage = (value) => {
1426
1426
  switch (typeof value) {
1427
- case 'object': return LocalStorage$1.setJson;
1428
- case 'boolean': return LocalStorage$1.setBool;
1429
- default: return LocalStorage$1.set;
1427
+ case 'object': return LocalStorage.setJson;
1428
+ case 'boolean': return LocalStorage.setBool;
1429
+ default: return LocalStorage.set;
1430
1430
  }
1431
1431
  };
1432
1432
 
@@ -1466,12 +1466,12 @@ var NativeComponents = (function (exports) {
1466
1466
 
1467
1467
  const $createObservable = (value, options = {}) => {
1468
1468
  if(Array.isArray(value)) {
1469
- return Observable$1.array(value, options);
1469
+ return Observable.array(value, options);
1470
1470
  }
1471
1471
  if(typeof value === 'object') {
1472
- return Observable$1.object(value, options);
1472
+ return Observable.object(value, options);
1473
1473
  }
1474
- return Observable$1(value, options);
1474
+ return Observable(value, options);
1475
1475
  };
1476
1476
 
1477
1477
  const $api = {
@@ -1574,7 +1574,7 @@ var NativeComponents = (function (exports) {
1574
1574
  });
1575
1575
 
1576
1576
  // Create computed observable from dependency observers
1577
- const observer = Observable$1.computed(computation, depObservers);
1577
+ const observer = Observable.computed(computation, depObservers);
1578
1578
 
1579
1579
  $stores.set(name, { observer, subscribers: new Set(), resettable: false, composed: true });
1580
1580
  return observer;
@@ -1778,21 +1778,21 @@ var NativeComponents = (function (exports) {
1778
1778
  },
1779
1779
  createPersistent(name, value, localstorage_key) {
1780
1780
  localstorage_key = localstorage_key || name;
1781
- const observer = this.create(name, $getFromStorage$1(localstorage_key, value));
1782
- const saver = $saveToStorage$1(value);
1781
+ const observer = this.create(name, $getFromStorage(localstorage_key, value));
1782
+ const saver = $saveToStorage(value);
1783
1783
 
1784
1784
  observer.subscribe((val) => saver(localstorage_key, val));
1785
1785
  return observer;
1786
1786
  },
1787
1787
  createPersistentResettable(name, value, localstorage_key) {
1788
1788
  localstorage_key = localstorage_key || name;
1789
- const observer = this.createResettable(name, $getFromStorage$1(localstorage_key, value));
1790
- const saver = $saveToStorage$1(value);
1789
+ const observer = this.createResettable(name, $getFromStorage(localstorage_key, value));
1790
+ const saver = $saveToStorage(value);
1791
1791
  observer.subscribe((val) => saver(localstorage_key, val));
1792
1792
 
1793
1793
  const originalReset = observer.reset.bind(observer);
1794
1794
  observer.reset = () => {
1795
- LocalStorage$1.remove(localstorage_key);
1795
+ LocalStorage.remove(localstorage_key);
1796
1796
  originalReset();
1797
1797
  };
1798
1798
 
@@ -2436,18 +2436,18 @@ var NativeComponents = (function (exports) {
2436
2436
  const formatter = Formatters[type];
2437
2437
  const localeObservable = Store.follow('locale');
2438
2438
 
2439
- return Observable$1.computed(() => formatter(self.val(), localeObservable.val(), options),
2439
+ return Observable.computed(() => formatter(self.val(), localeObservable.val(), options),
2440
2440
  [self, localeObservable]
2441
2441
  );
2442
2442
  };
2443
2443
 
2444
2444
  ObservableItem.prototype.persist = function(key, options = {}) {
2445
- let value = $getFromStorage$1(key, this.$currentValue);
2445
+ let value = $getFromStorage(key, this.$currentValue);
2446
2446
  if(options.get) {
2447
2447
  value = options.get(value);
2448
2448
  }
2449
2449
  this.set(value);
2450
- const saver = $saveToStorage$1(this.$currentValue);
2450
+ const saver = $saveToStorage(this.$currentValue);
2451
2451
  this.subscribe((newValue) => {
2452
2452
  saver(key, options.set ? options.set(newValue) : newValue);
2453
2453
  });
@@ -2461,17 +2461,17 @@ var NativeComponents = (function (exports) {
2461
2461
  * @returns {ObservableItem}
2462
2462
  * @constructor
2463
2463
  */
2464
- function Observable$1(value, configs = null) {
2464
+ function Observable(value, configs = null) {
2465
2465
  return new ObservableItem(value, configs);
2466
2466
  }
2467
2467
 
2468
- const $$1 = Observable$1;
2468
+ const $$1 = Observable;
2469
2469
 
2470
2470
  /**
2471
2471
  *
2472
2472
  * @param {string} propertyName
2473
2473
  */
2474
- Observable$1.useValueProperty = function(propertyName = 'value') {
2474
+ Observable.useValueProperty = function(propertyName = 'value') {
2475
2475
  Object.defineProperty(ObservableItem.prototype, propertyName, {
2476
2476
  get() {
2477
2477
  return this.$currentValue;
@@ -2489,7 +2489,7 @@ var NativeComponents = (function (exports) {
2489
2489
  * @param id
2490
2490
  * @returns {ObservableItem|null}
2491
2491
  */
2492
- Observable$1.getById = function(id) {
2492
+ Observable.getById = function(id) {
2493
2493
  const item = MemoryManager.getObservableById(parseInt(id));
2494
2494
  if(!item) {
2495
2495
  throw new NativeDocumentError('Observable.getById : No observable found with id ' + id);
@@ -2501,7 +2501,7 @@ var NativeComponents = (function (exports) {
2501
2501
  *
2502
2502
  * @param {ObservableItem} observable
2503
2503
  */
2504
- Observable$1.cleanup = function(observable) {
2504
+ Observable.cleanup = function(observable) {
2505
2505
  observable.cleanup();
2506
2506
  };
2507
2507
 
@@ -2510,7 +2510,7 @@ var NativeComponents = (function (exports) {
2510
2510
  * @param {Boolean} enable
2511
2511
  * @param {{interval:Boolean, threshold:number}} options
2512
2512
  */
2513
- Observable$1.autoCleanup = function(enable = false, options = {}) {
2513
+ Observable.autoCleanup = function(enable = false, options = {}) {
2514
2514
  if(!enable) {
2515
2515
  return;
2516
2516
  }
@@ -3268,7 +3268,7 @@ var NativeComponents = (function (exports) {
3268
3268
  String.prototype.use = function(args) {
3269
3269
  const value = this;
3270
3270
 
3271
- return Observable$1.computed(() => {
3271
+ return Observable.computed(() => {
3272
3272
  return value.replace(/\$\{(.*?)}/g, (match, key) => {
3273
3273
  const data = args[key];
3274
3274
  if(Validator.isObservable(data)) {
@@ -3288,7 +3288,7 @@ var NativeComponents = (function (exports) {
3288
3288
  return value;
3289
3289
  }
3290
3290
  const [_, id] = value.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);
3291
- return Observable$1.getById(id);
3291
+ return Observable.getById(id);
3292
3292
  });
3293
3293
  };
3294
3294
 
@@ -3561,7 +3561,7 @@ var NativeComponents = (function (exports) {
3561
3561
  }
3562
3562
  }
3563
3563
 
3564
- const viewArray = Observable$1.array();
3564
+ const viewArray = Observable.array();
3565
3565
 
3566
3566
  const filters = Object.entries(filterCallbacks);
3567
3567
  const updateView = () => {
@@ -3632,6 +3632,68 @@ var NativeComponents = (function (exports) {
3632
3632
  });
3633
3633
  };
3634
3634
 
3635
+ ObservableArray.prototype.deepSubscribe = function(callback) {
3636
+ const updatedValue = nextTick(() => callback(this.val()));
3637
+ const $listeners = new WeakMap();
3638
+
3639
+ const bindItem = (item) => {
3640
+ if ($listeners.has(item)) {
3641
+ return;
3642
+ }
3643
+ if (item?.__$isObservableArray) {
3644
+ $listeners.set(item, item.deepSubscribe(updatedValue));
3645
+ return;
3646
+ }
3647
+ if (item?.__$isObservable) {
3648
+ item.subscribe(updatedValue);
3649
+ $listeners.set(item, () => item.unsubscribe(updatedValue));
3650
+ }
3651
+ };
3652
+
3653
+ const unbindItem = (item) => {
3654
+ const unsub = $listeners.get(item);
3655
+ if (unsub) {
3656
+ unsub();
3657
+ $listeners.delete(item);
3658
+ }
3659
+ };
3660
+
3661
+ this.$currentValue.forEach(bindItem);
3662
+ this.subscribe(updatedValue);
3663
+
3664
+ this.subscribe((items, _, operations) => {
3665
+ switch (operations?.action) {
3666
+ case 'push':
3667
+ case 'unshift':
3668
+ operations.args.forEach(bindItem);
3669
+ break;
3670
+
3671
+ case 'splice': {
3672
+ const [start, deleteCount, ...newItems] = operations.args;
3673
+ operations.result?.forEach(unbindItem);
3674
+ newItems.forEach(bindItem);
3675
+ break;
3676
+ }
3677
+
3678
+ case 'remove':
3679
+ unbindItem(operations.result);
3680
+ break;
3681
+
3682
+ case 'merge':
3683
+ operations.args.forEach(bindItem);
3684
+ break;
3685
+
3686
+ case 'clear':
3687
+ this.$currentValue.forEach(unbindItem);
3688
+ break;
3689
+ }
3690
+ });
3691
+
3692
+ return () => {
3693
+ this.$currentValue.forEach(unbindItem);
3694
+ };
3695
+ };
3696
+
3635
3697
  /**
3636
3698
  * Creates an observable array with reactive array methods.
3637
3699
  * All mutations trigger updates automatically.
@@ -3647,7 +3709,7 @@ var NativeComponents = (function (exports) {
3647
3709
  * items.push(4); // Triggers update
3648
3710
  * items.subscribe((arr) => console.log(arr));
3649
3711
  */
3650
- Observable$1.array = function(target = [], configs = null) {
3712
+ Observable.array = function(target = [], configs = null) {
3651
3713
  return new ObservableArray(target, configs);
3652
3714
  };
3653
3715
 
@@ -3656,8 +3718,8 @@ var NativeComponents = (function (exports) {
3656
3718
  * @param {Function} callback
3657
3719
  * @returns {Function}
3658
3720
  */
3659
- Observable$1.batch = function(callback) {
3660
- const $observer = Observable$1(0);
3721
+ Observable.batch = function(callback) {
3722
+ const $observer = Observable(0);
3661
3723
  const batch = function() {
3662
3724
  if(Validator.isAsyncFunction(callback)) {
3663
3725
  return (callback(...arguments)).then(() => {
@@ -3711,24 +3773,24 @@ var NativeComponents = (function (exports) {
3711
3773
  if(configs?.deep !== false) {
3712
3774
  const mappedItemValue = itemValue.map(item => {
3713
3775
  if(Validator.isJson(item)) {
3714
- return Observable$1.json(item, configs);
3776
+ return Observable.json(item, configs);
3715
3777
  }
3716
3778
  if(Validator.isArray(item)) {
3717
- return Observable$1.array(item, configs);
3779
+ return Observable.array(item, configs);
3718
3780
  }
3719
- return Observable$1(item, configs);
3781
+ return Observable(item, configs);
3720
3782
  });
3721
- this.$observables[key] = Observable$1.array(mappedItemValue, configs);
3783
+ this.$observables[key] = Observable.array(mappedItemValue, configs);
3722
3784
  continue;
3723
3785
  }
3724
- this.$observables[key] = Observable$1.array(itemValue, configs);
3786
+ this.$observables[key] = Observable.array(itemValue, configs);
3725
3787
  continue;
3726
3788
  }
3727
3789
  if(Validator.isObservable(itemValue) || Validator.isProxy(itemValue)) {
3728
3790
  this.$observables[key] = itemValue;
3729
3791
  continue;
3730
3792
  }
3731
- this.$observables[key] = Observable$1(itemValue, configs);
3793
+ this.$observables[key] = (typeof itemValue === 'object') ? Observable.object(itemValue, configs) : Observable(itemValue, configs);
3732
3794
  }
3733
3795
  };
3734
3796
 
@@ -3790,9 +3852,9 @@ var NativeComponents = (function (exports) {
3790
3852
  if(Validator.isObservable(firstElementFromOriginalValue) || Validator.isProxy(firstElementFromOriginalValue)) {
3791
3853
  const newValues = newValue.map(item => {
3792
3854
  if(Validator.isProxy(firstElementFromOriginalValue)) {
3793
- return Observable$1.init(item, configs);
3855
+ return Observable.init(item, configs);
3794
3856
  }
3795
- return Observable$1(item, configs);
3857
+ return Observable(item, configs);
3796
3858
  });
3797
3859
  targetItem.set(newValues);
3798
3860
  continue;
@@ -3820,7 +3882,7 @@ var NativeComponents = (function (exports) {
3820
3882
  };
3821
3883
  ObservableObject.prototype.$keys = ObservableObject.prototype.keys;
3822
3884
  ObservableObject.prototype.clone = function() {
3823
- return Observable$1.init(this.val(), this.configs);
3885
+ return Observable.init(this.val(), this.configs);
3824
3886
  };
3825
3887
  ObservableObject.prototype.$clone = ObservableObject.prototype.clone;
3826
3888
  ObservableObject.prototype.reset = function() {
@@ -3831,15 +3893,16 @@ var NativeComponents = (function (exports) {
3831
3893
  ObservableObject.prototype.originalSubscribe = ObservableObject.prototype.subscribe;
3832
3894
  ObservableObject.prototype.subscribe = function(callback) {
3833
3895
  const observables = this.observables();
3834
- const updatedValue = nextTick(() => {
3835
- this.$currentValue = this.val();
3836
- this.trigger();
3837
- });
3896
+ const updatedValue = nextTick(() => this.trigger());
3838
3897
 
3839
3898
  this.originalSubscribe(callback);
3840
3899
 
3841
- for(let i = 0, length = observables.length; i < length; i++) {
3900
+ for (let i = 0, length = observables.length; i < length; i++) {
3842
3901
  const observable = observables[i];
3902
+ if (observable.__$isObservableArray) {
3903
+ observable.deepSubscribe(updatedValue);
3904
+ continue
3905
+ }
3843
3906
  observable.subscribe(updatedValue);
3844
3907
  }
3845
3908
  };
@@ -3849,7 +3912,7 @@ var NativeComponents = (function (exports) {
3849
3912
 
3850
3913
  ObservableObject.prototype.update = ObservableObject.prototype.set;
3851
3914
 
3852
- Observable$1.init = function(initialValue, configs = null) {
3915
+ Observable.init = function(initialValue, configs = null) {
3853
3916
  return new ObservableObject(initialValue, configs)
3854
3917
  };
3855
3918
 
@@ -3858,8 +3921,8 @@ var NativeComponents = (function (exports) {
3858
3921
  * @param {any[]} data
3859
3922
  * @return Proxy[]
3860
3923
  */
3861
- Observable$1.arrayOfObject = function(data) {
3862
- return data.map(item => Observable$1.object(item));
3924
+ Observable.arrayOfObject = function(data) {
3925
+ return data.map(item => Observable.object(item));
3863
3926
  };
3864
3927
 
3865
3928
  /**
@@ -3867,7 +3930,7 @@ var NativeComponents = (function (exports) {
3867
3930
  * @param {ObservableItem|Object<ObservableItem>} data
3868
3931
  * @returns {{}|*|null}
3869
3932
  */
3870
- Observable$1.value = function(data) {
3933
+ Observable.value = function(data) {
3871
3934
  if(Validator.isObservable(data)) {
3872
3935
  return data.val();
3873
3936
  }
@@ -3878,15 +3941,15 @@ var NativeComponents = (function (exports) {
3878
3941
  const result = [];
3879
3942
  for(let i = 0, length = data.length; i < length; i++) {
3880
3943
  const item = data[i];
3881
- result.push(Observable$1.value(item));
3944
+ result.push(Observable.value(item));
3882
3945
  }
3883
3946
  return result;
3884
3947
  }
3885
3948
  return data;
3886
3949
  };
3887
3950
 
3888
- Observable$1.object = Observable$1.init;
3889
- Observable$1.json = Observable$1.init;
3951
+ Observable.object = Observable.init;
3952
+ Observable.json = Observable.init;
3890
3953
 
3891
3954
  /**
3892
3955
  * Creates a computed observable that automatically updates when its dependencies change.
@@ -3907,7 +3970,7 @@ var NativeComponents = (function (exports) {
3907
3970
  * const batch = Observable.batch(() => { ... });
3908
3971
  * const computed = Observable.computed(() => { ... }, batch);
3909
3972
  */
3910
- Observable$1.computed = function(callback, dependencies = []) {
3973
+ Observable.computed = function(callback, dependencies = []) {
3911
3974
  const initialValue = callback();
3912
3975
  const observable = new ObservableItem(initialValue);
3913
3976
  const updatedValue = nextTick(() => observable.set(callback()));
@@ -7576,10 +7639,10 @@ var NativeComponents = (function (exports) {
7576
7639
  this.$element = null;
7577
7640
  this.$configs = configs;
7578
7641
  this.$fields = new Map();
7579
- this.$submitting = Observable$1(false);
7580
- this.$errors = Observable$1(null);
7581
- this.$isDirty = Observable$1(false);
7582
- this.$isValid = Observable$1(false);
7642
+ this.$submitting = Observable(false);
7643
+ this.$errors = Observable(null);
7644
+ this.$isDirty = Observable(false);
7645
+ this.$isValid = Observable(false);
7583
7646
  }
7584
7647
 
7585
7648
  FormControl.defaultLayoutTemplate = null;
@@ -8900,7 +8963,7 @@ var NativeComponents = (function (exports) {
8900
8963
  defaultItem: null,
8901
8964
  value: (config?.data && Validator.isObservable(config.data))
8902
8965
  ? config.data
8903
- : Observable$1.array(config?.data || []),
8966
+ : Observable.array(config?.data || []),
8904
8967
  rules: null,
8905
8968
  layout: null,
8906
8969
  template: null,
@@ -8997,8 +9060,8 @@ var NativeComponents = (function (exports) {
8997
9060
  defaultItemData = Validator.isObservable(defaultItemData)
8998
9061
  ? defaultItemData
8999
9062
  : Validator.isObject(defaultItemData)
9000
- ? Observable$1.init(defaultItemData)
9001
- : Observable$1(defaultItemData);
9063
+ ? Observable.init(defaultItemData)
9064
+ : Observable(defaultItemData);
9002
9065
 
9003
9066
  this.$items = this.$items || new WeakMap();
9004
9067
 
@@ -11480,9 +11543,9 @@ var NativeComponents = (function (exports) {
11480
11543
  ...configs
11481
11544
  });
11482
11545
 
11483
- this.$currentPage = Observable$1(1);
11484
- this.$selectedRows = Observable$1.array();
11485
- this.$expandedRows = Observable$1.array();
11546
+ this.$currentPage = Observable(1);
11547
+ this.$selectedRows = Observable.array();
11548
+ this.$expandedRows = Observable.array();
11486
11549
  }
11487
11550
 
11488
11551
  DataTable.defaultToolbarTemplate = null;