native-document 1.0.207 → 1.0.209

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.207",
3
+ "version": "1.0.209",
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",
@@ -118,8 +118,6 @@ FormControl.prototype.fields = function(fieldBuilder) {
118
118
  dirties.push(field.$description.isDirty);
119
119
  }
120
120
 
121
- console.log(dirties);
122
-
123
121
  $.computed(() => {
124
122
  const isDirty = dirties.some((item) => item.val());
125
123
  this.$description.isDirty.set(isDirty);
@@ -131,8 +131,8 @@ Observable.batch = function(callback) {
131
131
  * Creates a computed observable that automatically updates when its dependencies change.
132
132
  * The callback is re-executed whenever any dependency observable changes.
133
133
  *
134
- * @param {Function} callback - Function that returns the computed value
135
- * @param {Array<ObservableItem|ObservableChecker|ObservableProxy>|Function} [dependencies=[]] - Array of observables to watch, or batch function
134
+ * @param {Array<ObservableItem|ObservableChecker|ObservableProxy>|Function} _callback - Function that returns the computed value
135
+ * @param {Array<ObservableItem|ObservableChecker|ObservableProxy>|Function} [_dependencies=[]] - Array of observables to watch, or batch function
136
136
  * @returns {ObservableItem} A new observable that updates automatically
137
137
  * @example
138
138
  * const firstName = Observable('John');
@@ -146,7 +146,14 @@ Observable.batch = function(callback) {
146
146
  * const batch = Observable.batch(() => { ... });
147
147
  * const computed = Observable.computed(() => { ... }, batch);
148
148
  */
149
- Observable.computed = function(callback, dependencies = []) {
149
+ Observable.computed = function(_callback, _dependencies = []) {
150
+ let callback = _callback, dependencies = _dependencies;
151
+ if(Array.isArray(_callback)) {
152
+ dependencies = _callback;
153
+ callback = _dependencies;
154
+ }
155
+
156
+
150
157
  const getValues = () => dependencies.map((item) => item.val());
151
158
  const initialValue = callback(...getValues());
152
159
  const observable = new ObservableItem(initialValue);
@@ -55,6 +55,9 @@ export default function ObservableResource(fn, deps, config) {
55
55
  }
56
56
  this.fetch();
57
57
  }
58
+
59
+ this.fetch = this.fetch.bind(this);
60
+ this.refresh = this.refresh.bind(this);
58
61
  }
59
62
 
60
63
  ObservableResource.prototype.$applyResult = function(result) {
@@ -104,8 +104,9 @@ export const bindBooleanAttribute = (element, attributeName, value) => {
104
104
  const defaultValue = isObservable? value.val() : value;
105
105
 
106
106
  const attributeRealName = BOOL_ATTRIBUTES_NAME[attributeName] || attributeName;
107
+ const isBooleanHandling = typeof defaultValue === 'boolean' || defaultValue == null;
107
108
 
108
- if(typeof defaultValue === 'boolean') {
109
+ if(isBooleanHandling) {
109
110
  element[attributeRealName] = defaultValue;
110
111
  }
111
112
  else {
@@ -113,7 +114,7 @@ export const bindBooleanAttribute = (element, attributeName, value) => {
113
114
  }
114
115
  if(isObservable) {
115
116
  if(attributeName === 'checked') {
116
- if(typeof defaultValue === 'boolean') {
117
+ if(isBooleanHandling) {
117
118
  element.addEventListener('input', () => value.set(element[attributeRealName]));
118
119
  }
119
120
  else {
@@ -384,6 +384,7 @@ NDElement.prototype.with = function(methods) {
384
384
 
385
385
  return this;
386
386
  };
387
+ NDElement.prototype.expose = NDElement.prototype.with;
387
388
 
388
389
  /**
389
390
  * Sets a single attribute on the element.
@@ -16,16 +16,6 @@ export default function NativeFetch($baseUrl) {
16
16
 
17
17
  this.fetch = async function(method, endpoint, params = {}, options = {}) {
18
18
  endpoint = endpoint || '';
19
- if(options.formData) {
20
- const formData = new FormData();
21
- for(const key in params) {
22
- if(params[key] == null) {
23
- continue;
24
- }
25
- formData.append(key, params[key]);
26
- }
27
- params = formData;
28
- }
29
19
  if(!endpoint.startsWith('http')) {
30
20
  endpoint = ($baseUrl.endsWith('/') ? $baseUrl : $baseUrl+'/') + endpoint;
31
21
  }
@@ -60,6 +50,17 @@ export default function NativeFetch($baseUrl) {
60
50
  if(parseToString) {
61
51
  configs.body = JSON.stringify(configs.body);
62
52
  }
53
+ else if(options.formData) {
54
+ const data = configs.body;
55
+ const formData = new FormData();
56
+ for(const key in data) {
57
+ if(data[key] == null) {
58
+ continue;
59
+ }
60
+ formData.append(key, data[key]);
61
+ }
62
+ configs.body = formData;
63
+ }
63
64
 
64
65
  let response = await fetch(endpoint, configs);
65
66
 
@@ -99,7 +100,7 @@ export default function NativeFetch($baseUrl) {
99
100
 
100
101
  export const resolveData = (data) => {
101
102
  if(data?.__$Observable) {
102
- return data.resolve();
103
+ return data.val();
103
104
  }
104
105
  for(const key in data) {
105
106
  const value = data[key];
@@ -107,7 +108,7 @@ export const resolveData = (data) => {
107
108
  continue;
108
109
  }
109
110
  if(value.__$Observable) {
110
- data[key] = value.resolve();
111
+ data[key] = value.val();
111
112
  continue;
112
113
  }
113
114
  if(typeof value === 'object') {
@@ -22,6 +22,7 @@ export interface NDElement {
22
22
  ref(target: RefItem | Record<string, unknown>, name: string): this;
23
23
  refSelf(target: RefItem | Record<string, unknown>, name: string): this;
24
24
  with<T extends MethodsObject>(methods: T): this & ExtractMethods<T>;
25
+ expose<T extends MethodsObject>(methods: T): this & ExtractMethods<T>;
25
26
  extend(methods: MethodsObject): NDElement;
26
27
  extend<T extends MethodsObject>(
27
28
  methods: T
@@ -329,8 +329,10 @@ export interface ObservableStatic {
329
329
  config?: ObservableResourceConfig<T> | boolean,
330
330
  ): ObservableResource<T>;
331
331
 
332
+ computed<T>(dependencies: ValidComputedDependencies | BatchFunction, callback: (...values: any[]) => T): ObservableItem<T>;
332
333
  computed<T>(callback: (...values: any[]) => T, dependencies?: ValidComputedDependencies | BatchFunction): ObservableItem<T>;
333
334
  computed<T>(callback: (...values: any[]) => T, batchFunction?: BatchFunction): ObservableItem<T>;
335
+ computed<T>(batchFunction: BatchFunction, callback: (...values: any[]) => T): ObservableItem<T>;
334
336
 
335
337
  batch<TArgs extends any[], TReturn>(
336
338
  callback: (...args: TArgs) => TReturn