native-document 1.0.28 → 1.0.30
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/dist/native-document.dev.js +144 -2
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/index.d.ts +4 -0
- package/index.js +1 -0
- package/package.json +2 -3
- package/readme.md +2 -2
- package/src/data/Observable.js +0 -2
- package/src/data/ObservableItem.js +13 -6
- package/src/data/observable-helpers/array.js +3 -0
- package/src/data/observable-helpers/computed.js +3 -0
- package/src/utils/args-types.js +10 -1
- package/src/utils/plugins-manager.js +66 -5
- package/src/utils/property-accumulator.js +43 -0
- package/src/wrappers/ElementCreator.js +7 -0
- package/src/wrappers/NDElement.js +2 -0
- package/types/args-types.d.ts +58 -0
- package/types/plugins-manager.d.ts +65 -0
- package/types/polyfill.d.ts +10 -0
- package/types/property-accumulator.d.ts +33 -0
- package/types/validator.ts +55 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {NDElement} from "./elements";
|
|
2
|
+
import {ObservableItem} from "./observable";
|
|
3
|
+
import { Map} from "./polyfill";
|
|
4
|
+
|
|
5
|
+
type FrameworkEvents = {
|
|
6
|
+
// Observable Events
|
|
7
|
+
'CreateObservable': (observable: ObservableItem) => void;
|
|
8
|
+
'ObservableBeforeChange': (observable: ObservableItem) => void;
|
|
9
|
+
'ObservableAfterChange': (observable: ObservableItem) => void;
|
|
10
|
+
'ObservableSubscribe': (observable: ObservableItem, target?: any) => void;
|
|
11
|
+
'ObservableUnsubscribe': (observable: ObservableItem) => void;
|
|
12
|
+
'CreateObservableArray': (observer: ObservableItem) => void;
|
|
13
|
+
'CreateObservableComputed': (observable: ObservableItem, dependencies: ObservableItem[]) => void;
|
|
14
|
+
|
|
15
|
+
// Element Events
|
|
16
|
+
'NDElementCreated': (element: HTMLElement, ndElement: NDElement) => void;
|
|
17
|
+
'Setup': (element: HTMLElement, attributes?: any, customWrapper?: Function) => void;
|
|
18
|
+
'BeforeProcessChildren': (parent: HTMLElement | DocumentFragment) => void;
|
|
19
|
+
'AfterProcessChildren': (parent: HTMLElement | DocumentFragment) => void;
|
|
20
|
+
'BeforeProcessComponent': (component: Function) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type EventMethodName = `on${Capitalize<keyof FrameworkEvents>}`;
|
|
24
|
+
|
|
25
|
+
interface Plugin {
|
|
26
|
+
$name?: string;
|
|
27
|
+
|
|
28
|
+
init?(): void;
|
|
29
|
+
cleanup?(): void;
|
|
30
|
+
|
|
31
|
+
// NativeDocument Framework Events
|
|
32
|
+
onCreateObservable?: (observable: ObservableItem) => void;
|
|
33
|
+
onObservableBeforeChange?: (observable: ObservableItem) => void;
|
|
34
|
+
onObservableAfterChange?: (observable: ObservableItem) => void;
|
|
35
|
+
onObservableSubscribe?: (observable: ObservableItem, target?: any) => void;
|
|
36
|
+
onObservableUnsubscribe?: (observable: ObservableItem) => void;
|
|
37
|
+
onCreateObservableArray?: (observer: ObservableItem) => void;
|
|
38
|
+
onCreateObservableComputed?: (observable: ObservableItem, dependencies: ObservableItem[]) => void;
|
|
39
|
+
onNDElementCreated?: (element: HTMLElement, ndElement: NDElement) => void;
|
|
40
|
+
onSetup?: (element: HTMLElement, attributes?: any, customWrapper?: Function) => void;
|
|
41
|
+
onBeforeProcessChildren?: (parent: HTMLElement | DocumentFragment) => void;
|
|
42
|
+
onAfterProcessChildren?: (parent: HTMLElement | DocumentFragment) => void;
|
|
43
|
+
onBeforeProcessComponent?: (component: Function) => void;
|
|
44
|
+
|
|
45
|
+
// Other possible events
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface IPluginsManager {
|
|
50
|
+
list(): Map<string, Plugin>;
|
|
51
|
+
|
|
52
|
+
add(name: string, plugin: Plugin): void;
|
|
53
|
+
|
|
54
|
+
remove(pluginName: string): void;
|
|
55
|
+
|
|
56
|
+
emit(event: string, ...data: any[]): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare const PluginsManager: IPluginsManager;
|
|
60
|
+
|
|
61
|
+
export type TypedPlugin<T extends Record<string, (...args: any[]) => void> = {}> = Plugin & {
|
|
62
|
+
[K in keyof T as K extends string ? `on${Capitalize<K>}` : never]: T[K];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default PluginsManager;
|
package/types/polyfill.d.ts
CHANGED
|
@@ -5,4 +5,14 @@ export interface Set<T> {
|
|
|
5
5
|
forEach(callbackFn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
|
|
6
6
|
has(value: T): boolean;
|
|
7
7
|
readonly size: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Map<K, V> {
|
|
11
|
+
clear(): void;
|
|
12
|
+
delete(key: K): boolean;
|
|
13
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
14
|
+
get(key: K): V | undefined;
|
|
15
|
+
has(key: K): boolean;
|
|
16
|
+
set(key: K, value: V): this;
|
|
17
|
+
readonly size: number;
|
|
8
18
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {ObservableItem} from "./observable";
|
|
2
|
+
|
|
3
|
+
type CssPropertyValueType = string | ObservableItem | number;
|
|
4
|
+
type ClassPropertyValueType = boolean | ObservableItem;
|
|
5
|
+
|
|
6
|
+
interface cssPropertyAccumulator {
|
|
7
|
+
add(key: string, value: CssPropertyValueType): void;
|
|
8
|
+
value(): string | Record<string, CssPropertyValueType>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface classPropertyAccumulator {
|
|
12
|
+
add(key: string, value?: ClassPropertyValueType): void;
|
|
13
|
+
value(): string | Record<string, ClassPropertyValueType>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type CssInitialValue = string | Record<string, CssPropertyValueType> | string[];
|
|
18
|
+
type ClassInitialValue = string | Record<string, ClassPropertyValueType> | string[];
|
|
19
|
+
|
|
20
|
+
export declare const cssPropertyAccumulator: (initialValue?: CssInitialValue) => cssPropertyAccumulator;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export declare const classPropertyAccumulator: (initialValue?: ClassInitialValue) => classPropertyAccumulator;
|
|
24
|
+
|
|
25
|
+
// Export des types pour usage externe
|
|
26
|
+
export type {
|
|
27
|
+
cssPropertyAccumulator as CssPropertyAccumulatorType,
|
|
28
|
+
classPropertyAccumulator as ClassPropertyAccumulatorType,
|
|
29
|
+
CssPropertyValueType,
|
|
30
|
+
ClassPropertyValueType,
|
|
31
|
+
CssInitialValue,
|
|
32
|
+
ClassInitialValue
|
|
33
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {ObservableChecker, ObservableItem, ObservableProxy} from "./observable";
|
|
2
|
+
import { NDElement, ValidChild } from "./elements";
|
|
3
|
+
|
|
4
|
+
export type ValidChildren = ValidChild | ValidChild[];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validator utility class with type guards
|
|
8
|
+
*/
|
|
9
|
+
declare const Validator: {
|
|
10
|
+
isObservable(value: any): value is ObservableItem;
|
|
11
|
+
|
|
12
|
+
isProxy(value: any): value is ObservableProxy<any>;
|
|
13
|
+
|
|
14
|
+
isObservableChecker(value: any): value is ObservableChecker;
|
|
15
|
+
|
|
16
|
+
isArray(value: any): value is Array<any>;
|
|
17
|
+
|
|
18
|
+
isString(value: any): value is string;
|
|
19
|
+
|
|
20
|
+
isNumber(value: any): value is number;
|
|
21
|
+
|
|
22
|
+
isBoolean(value: any): value is boolean;
|
|
23
|
+
|
|
24
|
+
isFunction(value: any): value is Function;
|
|
25
|
+
|
|
26
|
+
isAsyncFunction(value: any): value is (...args: any[]) => Promise<any>;
|
|
27
|
+
|
|
28
|
+
isObject(value: any): value is object;
|
|
29
|
+
|
|
30
|
+
isJson(value: any): value is Record<string, any>;
|
|
31
|
+
|
|
32
|
+
isElement(value: any): value is HTMLElement | DocumentFragment | Text;
|
|
33
|
+
|
|
34
|
+
isFragment(value: any): value is DocumentFragment;
|
|
35
|
+
|
|
36
|
+
isStringOrObservable(value: any): value is string | ObservableItem<string>;
|
|
37
|
+
|
|
38
|
+
isValidChild(child: any): child is ValidChild;
|
|
39
|
+
|
|
40
|
+
isNDElement(child: any): child is NDElement;
|
|
41
|
+
|
|
42
|
+
isValidChildren(children: any): children is ValidChildren;
|
|
43
|
+
|
|
44
|
+
validateChildren(children: any): ValidChildren;
|
|
45
|
+
|
|
46
|
+
containsObservables(data: any): boolean;
|
|
47
|
+
|
|
48
|
+
containsObservableReference(data: any): data is string;
|
|
49
|
+
|
|
50
|
+
validateAttributes(attributes: any): Record<string, any> | null | undefined;
|
|
51
|
+
|
|
52
|
+
validateEventCallback(callback: any): asserts callback is Function;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { Validator };
|