native-document 1.0.254 → 1.0.256

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.254",
3
+ "version": "1.0.256",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -49,9 +49,6 @@ export default function FieldCollection(name, props = {}) {
49
49
  props,
50
50
  };
51
51
 
52
- this.$description.value.interceptMutations((items) =>
53
- items.map(item => Validator.isObservable(item) ? item : $.object(item)),
54
- );
55
52
  }
56
53
 
57
54
  BaseComponent.extends(FieldCollection);
@@ -149,9 +146,6 @@ FieldCollection.prototype.transition = function(transitionName) {
149
146
  FieldCollection.prototype.model = function(observable) {
150
147
  if(Validator.isObservable(observable)) {
151
148
  this.$description.value = observable;
152
- this.$description.value.interceptMutations((items) => {
153
- return items.map(item => Validator.isObservable(item) ? item : $.object(item));
154
- });
155
149
  return this;
156
150
  }
157
151
  this.$description.value.set(observable);
@@ -46,6 +46,8 @@ export default function Toast(content, props = {}) {
46
46
  props,
47
47
  };
48
48
  this.aria = { 'role': 'status', 'aria-live': 'polite' };
49
+
50
+ queueMicrotask(() => this.show());
49
51
  }
50
52
 
51
53
  BaseComponent.extends(Toast);
@@ -260,4 +262,9 @@ Toast.prototype.onClose = function(handler) {
260
262
  return this;
261
263
  };
262
264
 
265
+ Toast.error = (content, props = {}) => Toast(content, props).error();
266
+ Toast.success = (content, props = {}) => Toast(content, props).success();
267
+ Toast.warning = (content, props = {}) => Toast(content, props).warning();
268
+ Toast.info = (content, props = {}) => Toast(content, props).info();
269
+
263
270
  Toast.prototype.show = BaseComponent.prototype.toNdElement;
@@ -196,6 +196,7 @@ Observable.auto = (value, options = null) => {
196
196
  return new ObservableItem(value, options);
197
197
  };
198
198
  ObservableItem.auto = Observable.auto;
199
+ ObservableArray.auto = Observable.auto;
199
200
 
200
201
 
201
202
  Observable.init = function(initialValue, configs = null) {
@@ -8,6 +8,8 @@ import {nextTick} from '../utils/helpers';
8
8
  export const mutationMethods = ['push', 'pop', 'shift', 'unshift', 'reverse', 'sort', 'splice'];
9
9
  export const noMutationMethods = ['map', 'forEach', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat', 'includes', 'indexOf'];
10
10
 
11
+ const toObservable = (item) => item?.__$Observable ? item : ObservableArray.auto(item);
12
+
11
13
  /**
12
14
  * Reactive array container extending ObservableItem.
13
15
  * Wraps a native array and triggers reactivity on mutations (push, pop, splice, etc.).
@@ -22,11 +24,31 @@ export const noMutationMethods = ['map', 'forEach', 'filter', 'reduce', 'some',
22
24
  * const items = Observable.array([1, 2, 3]);
23
25
  * items.push(4); // triggers reactivity
24
26
  */
25
- const ObservableArray = function (target, configs = null) {
27
+ const ObservableArray = function (target, configs = { propagation: false, deep: true, reset: false }) {
26
28
  if(!Array.isArray(target)) {
27
29
  throw new NativeDocumentError('Observable.array : target must be an array');
28
30
  }
29
31
 
32
+
33
+ if(configs?.deep) {
34
+ target = target.map(toObservable);
35
+ this.interceptMutations((data, operations) => {
36
+ if(!operations.action || ['push', 'unshift', 'set', 'splice'].includes(operations.action)) {
37
+ if(operations.action === 'splice') {
38
+ for(let i = 2, length = data.length; i < length; ++i) {
39
+ data[i] = toObservable(data[i]);
40
+ }
41
+ return data;
42
+ }
43
+ if(operations.action === 'set') {
44
+ data[0] = data[0].map(toObservable);
45
+ return data;
46
+ }
47
+ return data.map(toObservable);
48
+ }
49
+ });
50
+ }
51
+
30
52
  ObservableItem.call(this, target, configs);
31
53
  if(process.env.NODE_ENV === 'development') {
32
54
  PluginsManager.emit('CreateObservableArray', this);
@@ -36,7 +58,7 @@ const ObservableArray = function (target, configs = null) {
36
58
  ObservableArray.prototype = Object.create(ObservableItem.prototype);
37
59
  ObservableArray.prototype.constructor = ObservableArray;
38
60
  ObservableArray.prototype.__$isObservableArray = true;
39
-
61
+ ObservableArray.auto = () => {};
40
62
 
41
63
  Object.defineProperty(ObservableArray.prototype, 'length', {
42
64
  get() {
@@ -48,13 +70,21 @@ Object.defineProperty(ObservableArray.prototype, 'length', {
48
70
  ObservableArray.prototype.$mutate = function(action, args, mutateFn) {
49
71
  if(this.$mutationInterceptor) {
50
72
  const value = this.$mutationInterceptor(args, { action });
51
- if(args !== undefined) {
73
+ if(value != null) {
52
74
  args = value;
53
75
  }
54
76
  }
55
77
  mutateFn(args);
56
78
  };
57
79
 
80
+ const $originalSet = ObservableArray.prototype.set;
81
+ ObservableArray.prototype.set = function(...values) {
82
+ return this.$mutate('set', values, (argsToUse) => {
83
+ $originalSet.call(this, ...argsToUse);
84
+ return argsToUse[0];
85
+ });
86
+ };
87
+
58
88
  mutationMethods.forEach((method) => {
59
89
  ObservableArray.prototype[method] = function(...values) {
60
90
  return this.$mutate(method, values, (argsToUse) => {
@@ -540,12 +570,12 @@ ObservableArray.prototype.fnClear = function () {
540
570
  return () => this.clear();
541
571
  };
542
572
 
543
- ObservableArray.prototype.rawValue = function () {
544
- const result = [];
545
- for(const element of this.$currentValue) {
546
- result.push(element?.__$Observable ? element.val() : element);
547
- }
548
- return result;
549
- };
573
+ // ObservableArray.prototype.resolve = function () {
574
+ // const result = [];
575
+ // for(const element of this.$currentValue) {
576
+ // result.push(element?.__$Observable ? element.val() : element);
577
+ // }
578
+ // return result;
579
+ // };
550
580
 
551
581
  export default ObservableArray;
@@ -1,7 +1,7 @@
1
1
  :root {
2
2
  --drawer-z-index: 1000;
3
3
  --drawer-background-color: white;
4
- --drawer-width: 400px;
4
+ --drawer-width: 500px;
5
5
  --drawer-backdrop-color: rgba(0, 0, 0, var(--opacity-backdrop));
6
6
  --drawer-panel-backdrop-color: hsl(from var(--gray-lite-1) h s l / .5);
7
7
  --drawer-panel-shadow: 0 0 20px rgba(0, 0, 0, 0.2);