native-document 1.0.37 → 1.0.39

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.
@@ -4,6 +4,9 @@ export interface ObservableItem<T = any> {
4
4
  readonly $previousValue: T;
5
5
  readonly $isCleanedUp: boolean;
6
6
 
7
+ $value: T;
8
+ $memoryId: number | null;
9
+
7
10
  val(): T;
8
11
  set(value: T | ((prev: T) => T)): void;
9
12
  trigger(operations?: ObservableOperation): void;
@@ -68,6 +71,7 @@ export type ObservableProxy<T extends Record<string, any>> = {
68
71
  readonly __isProxy__: true;
69
72
  readonly $value: T;
70
73
  $clone(): ObservableProxy<T>;
74
+ $updateWith(values: Partial<T>): void;
71
75
  } & {
72
76
  [K in keyof T]: T[K] extends (infer U)[]
73
77
  ? ObservableArray<U>
@@ -82,24 +86,6 @@ export interface BatchFunction<TArgs extends any[] = any[], TReturn = any> {
82
86
  }
83
87
 
84
88
  export type ValidComputedDependencies = Array<ObservableItem | ObservableArray<any> | ObservableChecker | ObservableProxy<any>>;
85
- export interface ObservableStatic {
86
- <T>(value: T): ObservableItem<T>;
87
- array<T>(target: T[]): ObservableArray<T>;
88
- init<T extends Record<string, any>>(value: T): ObservableProxy<T>;
89
- object<T extends Record<string, any>>(value: T): ObservableProxy<T>;
90
- json<T extends Record<string, any>>(value: T): ObservableProxy<T>;
91
-
92
- computed<T>(callback: () => T, dependencies?: ValidComputedDependencies): ObservableItem<T>;
93
- computed<T>(callback: () => T, batchFunction?: BatchFunction): ObservableItem<T>;
94
-
95
- batch(callback: Function): BatchFunction;
96
- value(data: any): any;
97
- update(target: any, data: any): void;
98
-
99
- getById(id: number): ObservableItem | null;
100
- cleanup(observable: ObservableItem): void;
101
- autoCleanup(enable?: boolean, options?: { interval?: number; threshold?: number }): void;
102
- }
103
89
 
104
90
  export interface AutoCleanupOptions {
105
91
  interval?: number;
@@ -114,7 +100,7 @@ export interface ObservableStatic {
114
100
  object<T extends Record<string, any>>(value: T): ObservableProxy<T>;
115
101
  json<T extends Record<string, any>>(value: T): ObservableProxy<T>;
116
102
 
117
- computed<T>(callback: () => T, dependencies?: ObservableItem[]): ObservableItem<T>;
103
+ computed<T>(callback: () => T, dependencies?: ValidComputedDependencies | BatchFunction): ObservableItem<T>;
118
104
  computed<T>(callback: () => T, batchFunction?: BatchFunction): ObservableItem<T>;
119
105
 
120
106
  batch<TArgs extends any[], TReturn>(
@@ -127,4 +113,5 @@ export interface ObservableStatic {
127
113
  getById(id: number): ObservableItem | null;
128
114
  cleanup(observable: ObservableItem): void;
129
115
  autoCleanup(enable?: boolean, options?: AutoCleanupOptions): void;
116
+ arrayOfObject<T extends Record<string, any>>(data: T[]): ObservableProxy<T>[];
130
117
  }
@@ -10,7 +10,7 @@ export interface Set<T> {
10
10
  export interface Map<K, V> {
11
11
  clear(): void;
12
12
  delete(key: K): boolean;
13
- forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
13
+ forEach(callbackFn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
14
14
  get(key: K): V | undefined;
15
15
  has(key: K): boolean;
16
16
  set(key: K, value: V): this;
@@ -4,7 +4,7 @@ interface BindingData {
4
4
  classes?: Record<string, (...data: any[]) => any>;
5
5
  styles?: Record<string, (...data: any[]) => any>;
6
6
  value?: (...data: any[]) => any;
7
- events?: Record<string, (this: Element, event: Event, ...data: any[]) => void>;
7
+ attach?: (element: Element, ...data: any[]) => void;
8
8
  }
9
9
 
10
10
  interface ProcessedAttributes {
@@ -28,9 +28,14 @@ export declare class TemplateCloner {
28
28
 
29
29
  style(fn: (...data: any[]) => any): BindingHydrator;
30
30
  class(fn: (...data: any[]) => any): BindingHydrator;
31
- value(fn: (...data: any[]) => any): BindingHydrator;
31
+ value(callbackOrProperty: string | ((...data: any[]) => any)): BindingHydrator;
32
32
  attr(fn: (...data: any[]) => any): BindingHydrator;
33
33
  event(fn: (event: Event, ...data: any[]) => void): BindingHydrator;
34
+
35
+ property(propertyName: string): BindingHydrator;
36
+ property(fn: (...data: any[]) => any): BindingHydrator;
37
+
38
+ attach(fn: (element: Element, ...data: any[]) => void): BindingHydrator;
34
39
  }
35
40
 
36
41
  export declare function useCache(fn: TemplateBuilder): CachedTemplateFunction;
@@ -1,116 +0,0 @@
1
- import {EVENTS} from "../utils/events";
2
- import {NDElement} from "./NDElement";
3
- import Validator from "../utils/validator";
4
-
5
- (function() {
6
- const DelegatedEventsCallbackStore = {};
7
-
8
- const addCallbackToCallbacksStore = function(element, eventName, callback) {
9
- if(!element) return;
10
- if(!DelegatedEventsCallbackStore[eventName]) {
11
- const eventStore = new WeakMap();
12
- DelegatedEventsCallbackStore[eventName] = eventStore;
13
- eventStore.set(element, callback);
14
- return;
15
- }
16
- const eventStore = DelegatedEventsCallbackStore[eventName];
17
-
18
- if(!eventStore.has(element)) {
19
- eventStore.set(element, callback);
20
- return;
21
- }
22
- const existingCallbacks = eventStore.get(element);
23
- if(!Validator.isArray(existingCallbacks)) {
24
- eventStore.set(element, [store[eventName], callback]);
25
- return;
26
- }
27
- existingCallbacks.push(callback);
28
- }
29
-
30
- const handleDelegatedCallbacks = function(container, eventName) {
31
- container.addEventListener(eventName, (event) => {
32
- const eventStore = DelegatedEventsCallbackStore[eventName];
33
- if(!eventStore) {
34
- return;
35
- }
36
- let target = event.target;
37
- while(target && target !== container) {
38
- const callback = eventStore.get(target);
39
- if(!callback) {
40
- target = target.parentElement;
41
- continue;
42
- }
43
-
44
- if(Validator.isFunction(callback)) {
45
- callback.call(target, event);
46
- }
47
- else {
48
- for(let i = 0; i < callback.length; i++) {
49
- callback[i].call(target, event);
50
- }
51
- }
52
- return;
53
- }
54
- });
55
- };
56
-
57
-
58
- const preventDefaultWrapper = function(element, eventName, callback) {
59
- element.addEventListener(eventName, (event) => {
60
- event.preventDefault();
61
- callback && callback.call(element, event);
62
- });
63
- return this;
64
- }
65
- const stopPropagationWrapper = function(element, eventName, callback) {
66
- element.addEventListener(eventName, (event) => {
67
- event.stopPropagation();
68
- callback && callback.call(element, event);
69
- });
70
- return this;
71
- };
72
- const preventDefaultAndStopPropagationWrapper = function(element, eventName, callback) {
73
- element.addEventListener(eventName, (event) => {
74
- event.stopPropagation();
75
- event.preventDefault();
76
- callback && callback.call(element, event);
77
- });
78
- return this;
79
- };
80
- const captureEventWrapper = function(element, eventName, directHandler) {
81
- if(directHandler) {
82
- element.addEventListener(eventName, directHandler);
83
- return this;
84
- }
85
- handleDelegatedCallbacks(element, eventName);
86
- return this;
87
- }
88
-
89
- for(const event of EVENTS) {
90
- const eventName = event.toLowerCase();
91
- NDElement.prototype['on'+event] = function(callback) {
92
- this.$element.addEventListener(eventName, callback);
93
- return this;
94
- };
95
- NDElement.prototype['onPrevent'+event] = function(callback) {
96
- return preventDefaultWrapper(this.$element, eventName, callback);
97
- };
98
- NDElement.prototype['onStop'+event] = function(callback) {
99
- return stopPropagationWrapper(this.$element, eventName, callback);
100
- };
101
- NDElement.prototype['onPreventStop'+event] = function(callback) {
102
- return preventDefaultAndStopPropagationWrapper(this.$element, eventName, callback);
103
- };
104
-
105
- NDElement.prototype['when'+event] = function(callback) {
106
- addCallbackToCallbacksStore(this.$element, eventName, callback);
107
- return this;
108
- };
109
-
110
- NDElement.prototype['capture'+event] = function(directHandler) {
111
- captureEventWrapper(this.$element, eventName, directHandler);
112
- return this;
113
- };
114
- };
115
-
116
- }())