native-document 1.0.181 → 1.0.182

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.181",
3
+ "version": "1.0.182",
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",
@@ -592,6 +592,7 @@ ObservableItem.prototype.valueOf = function() {
592
592
  */
593
593
  ObservableItem.prototype.persist = function(key, options = {}) {
594
594
  let value = $getFromStorage(key, this.$currentValue);
595
+ this.$persistKey = key;
595
596
  if(options.get) {
596
597
  value = options.get(value);
597
598
  }
@@ -608,6 +609,10 @@ ObservableItem.prototype.persist = function(key, options = {}) {
608
609
  return this;
609
610
  };
610
611
 
612
+ ObservableItem.prototype.persistKey = function() {
613
+ return this.$persistKey;
614
+ };
615
+
611
616
  /**
612
617
  * Creates a new ObservableItem with a deep clone of the current value.
613
618
  * For objects implementing a .clone() method, delegates to that method.
@@ -32,6 +32,7 @@ export default function NativeFetch($baseUrl) {
32
32
  ...(options.headers || {}),
33
33
  },
34
34
  };
35
+ let parseToString = false;
35
36
  if(params) {
36
37
  if(params instanceof FormData) {
37
38
  configs.body = params;
@@ -39,7 +40,8 @@ export default function NativeFetch($baseUrl) {
39
40
  else {
40
41
  if(method !== 'GET') {
41
42
  configs.headers['Content-Type'] = 'application/json';
42
- configs.body = JSON.stringify(params);
43
+ configs.body = params;
44
+ parseToString = true;
43
45
  } else {
44
46
  const queryString = new URLSearchParams(params).toString();
45
47
  if (queryString) {
@@ -52,6 +54,9 @@ export default function NativeFetch($baseUrl) {
52
54
  for(const interceptor of $interceptors.request) {
53
55
  configs = (await interceptor(configs, endpoint)) || configs;
54
56
  }
57
+ if(parseToString) {
58
+ configs.body = JSON.stringify(configs.body);
59
+ }
55
60
 
56
61
  let response = await fetch(endpoint, configs);
57
62
 
@@ -87,4 +92,28 @@ export default function NativeFetch($baseUrl) {
87
92
  this.get = function (endpoint, params = {}, options = {}) {
88
93
  return this.fetch('GET', endpoint, params, options);
89
94
  };
95
+ };
96
+
97
+ export const resolveData = (data) => {
98
+ if(data.__$Observable) {
99
+ return data.resolve();
100
+ }
101
+ for(const key in data) {
102
+ const value = data[key];
103
+ if(value.__$Observable) {
104
+ data[key] = value.resolve();
105
+ continue;
106
+ }
107
+ if(typeof data[key] === 'object') {
108
+ data[key] = resolveData(data[key]);
109
+ }
110
+ }
111
+ return data;
112
+ };
113
+
114
+ export const resolveObservableInterceptor = (configs) => {
115
+ if(configs.body && !(configs.body instanceof FormData)) {
116
+ configs.body = resolveData(configs.body);
117
+ }
118
+ return configs;
90
119
  };
@@ -57,7 +57,14 @@ function buildContent($desc) {
57
57
  }
58
58
 
59
59
  if($desc.initials || $desc.name) {
60
- return Span({class: 'avatar-initials'}, $desc.initials || $desc.name.split(' ').map(n => n[0]).join(''));
60
+ let initials = $desc.initials;
61
+ if(!initials) {
62
+ initials = $desc.name;
63
+ if($desc.anme.__$Observable) {
64
+ initials = $desc.name.format((name) => name.split(' ').map(n => n[0]).join(''));
65
+ }
66
+ }
67
+ return Span({class: 'avatar-initials'}, initials);
61
68
  }
62
69
 
63
70
  if($desc.icon) {
package/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
2
  export * from './types/native-fetch';
3
3
  export * from './types/service';
4
- export * as filters from './types/filters/index';
4
+ export * as filters from './types/filters/index';
5
+ export * from './types/localStorage'
package/utils.js CHANGED
@@ -1,7 +1,8 @@
1
- import NativeFetch from './src/fetch/NativeFetch';
1
+ import NativeFetch, { resolveObservableInterceptor } from './src/fetch/NativeFetch';
2
2
  import * as Cache from './src/core/utils/cache';
3
3
  import * as filters from './src/core/utils/filters/index';
4
4
  import {classPropertyAccumulator, cssPropertyAccumulator} from './src/core/utils/property-accumulator';
5
+ import {LocalStorage} from './src/core/utils/localstorage';
5
6
 
6
7
  const Service = Cache;
7
8
 
@@ -11,5 +12,7 @@ export {
11
12
  Service,
12
13
  filters,
13
14
  classPropertyAccumulator,
14
- cssPropertyAccumulator
15
+ cssPropertyAccumulator,
16
+ LocalStorage,
17
+ resolveObservableInterceptor,
15
18
  };