native-document 1.0.203 → 1.0.204
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 +1 -1
- package/src/components/BaseComponent.d.ts +4 -1
- package/src/components/BaseComponent.js +31 -0
- package/src/components/BaseComponentEvents.d.ts +164 -0
- package/src/components/button/Button.js +1 -1
- package/src/components/form/FormControl.js +3 -0
- package/src/components/form/field/FieldCollection.js +1 -0
- package/src/core/data/Observable.js +10 -1
- package/src/core/data/ObservableItem.js +3 -1
- package/src/core/data/Ref.js +38 -0
- package/src/core/wrappers/NDElement.js +8 -2
- package/src/ui/components/form/FieldCollectionRender.js +3 -2
- package/types/observable.d.ts +4 -0
- package/types/ref.d.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.204",
|
|
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",
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { ValidChild, GlobalAttributes, NdStyleMap } from '../../types/elements';
|
|
2
2
|
import type { ObservableItem } from '../../types/observable';
|
|
3
3
|
import type { CssPropertyAccumulator, ClassPropertyAccumulator } from '../../types/property-accumulator';
|
|
4
|
+
import {BaseComponentEvents} from "./BaseComponentEvents";
|
|
4
5
|
|
|
5
6
|
export type EditableProps = Omit<GlobalAttributes, 'class' | 'style'> & {
|
|
6
7
|
class: ClassPropertyAccumulator;
|
|
7
8
|
style: CssPropertyAccumulator;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
|
-
export interface BaseComponent {
|
|
11
|
+
export interface BaseComponent extends BaseComponentEvents {
|
|
11
12
|
setDescription(description: Record<string, unknown>): this;
|
|
12
13
|
postBuild(callback: (element: HTMLElement) => void): this;
|
|
13
14
|
refSelf(target: Record<string, unknown>, name: string): this;
|
|
@@ -22,6 +23,8 @@ export interface BaseComponent {
|
|
|
22
23
|
visibility(condition: boolean | ObservableItem<boolean>): this;
|
|
23
24
|
context(context: unknown): this;
|
|
24
25
|
ghostDom(element: ValidChild): this;
|
|
26
|
+
|
|
27
|
+
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
export declare namespace BaseComponent {
|
|
@@ -2,6 +2,8 @@ import {classPropertyAccumulator, cssPropertyAccumulator} from '../core/utils/pr
|
|
|
2
2
|
import {Observable} from '../core/data/Observable';
|
|
3
3
|
import {ShowIf} from '../core/elements/control/show-if';
|
|
4
4
|
import {NDElement} from '../core/wrappers/NDElement';
|
|
5
|
+
import {EVENTS} from '../core/utils/events';
|
|
6
|
+
import {call} from '@babel/traverse/lib/path/context';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
*
|
|
@@ -31,6 +33,30 @@ Object.defineProperty( BaseComponent.prototype, 'nd', {
|
|
|
31
33
|
},
|
|
32
34
|
});
|
|
33
35
|
|
|
36
|
+
|
|
37
|
+
EVENTS.forEach((eventSourceName) => {
|
|
38
|
+
const eventName = eventSourceName.toLowerCase();
|
|
39
|
+
const fnName = 'on'+eventSourceName;
|
|
40
|
+
|
|
41
|
+
BaseComponent.prototype[fnName] = function(callback = null, options = null) {
|
|
42
|
+
|
|
43
|
+
const callbackWrapper = (...args) => {
|
|
44
|
+
callback.apply(this, args);
|
|
45
|
+
this.emit ? this.emit(eventName, ...args) : null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
this.postBuild((element) => {
|
|
49
|
+
if(element[fnName]) {
|
|
50
|
+
element[fnName](callbackWrapper, options);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
element.nd[fnName](callbackWrapper, options);
|
|
54
|
+
});
|
|
55
|
+
return this;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
34
60
|
/**
|
|
35
61
|
* @param {Function} Component
|
|
36
62
|
* @param {...Function} parents
|
|
@@ -97,9 +123,14 @@ BaseComponent.prototype.ghostDom = NDElement.prototype.ghostDom;
|
|
|
97
123
|
* @returns {this}
|
|
98
124
|
*/
|
|
99
125
|
BaseComponent.prototype.refSelf = function(target, name) {
|
|
126
|
+
if(target.__$Ref) {
|
|
127
|
+
target.$store(this, this.$element);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
100
130
|
target[name] = this;
|
|
101
131
|
return this;
|
|
102
132
|
};
|
|
133
|
+
BaseComponent.prototype.ref = BaseComponent.prototype.refSelf;
|
|
103
134
|
|
|
104
135
|
BaseComponent.prototype.$build = function() {
|
|
105
136
|
if(this.$beforeRender) {
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export interface BaseComponentEvents {
|
|
4
|
+
onClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
5
|
+
onPreventClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
6
|
+
onStopClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
7
|
+
onPreventStopClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
8
|
+
onDblClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
9
|
+
onPreventDblClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
10
|
+
onStopDblClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
11
|
+
onPreventStopDblClick(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
12
|
+
onMouseDown(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
13
|
+
onPreventMouseDown(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
14
|
+
onStopMouseDown(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
15
|
+
onPreventStopMouseDown(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
16
|
+
onMouseEnter(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
17
|
+
onMouseLeave(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
18
|
+
onMouseMove(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
19
|
+
onStopMouseMove(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
20
|
+
onMouseOut(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
21
|
+
onStopMouseOut(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
22
|
+
onMouseOver(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
23
|
+
onStopMouseOver(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
24
|
+
onMouseUp(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
25
|
+
onPreventMouseUp(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
26
|
+
onStopMouseUp(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
27
|
+
onPreventStopMouseUp(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
28
|
+
onWheel(callback: (event: WheelEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
29
|
+
onPreventWheel(callback: (event: WheelEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
30
|
+
onStopWheel(callback: (event: WheelEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
31
|
+
onPreventStopWheel(callback: (event: WheelEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
32
|
+
onKeyDown(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
33
|
+
onPreventKeyDown(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
34
|
+
onStopKeyDown(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
35
|
+
onPreventStopKeyDown(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
36
|
+
onKeyPress(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
37
|
+
onPreventKeyPress(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
38
|
+
onStopKeyPress(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
39
|
+
onPreventStopKeyPress(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
40
|
+
onKeyUp(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
41
|
+
onStopKeyUp(callback: (event: KeyboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
42
|
+
onBlur(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
43
|
+
onChange(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
44
|
+
onStopChange(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
45
|
+
onFocus(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
46
|
+
onInput(callback: (event: InputEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
47
|
+
onStopInput(callback: (event: InputEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
48
|
+
onInvalid(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
49
|
+
onPreventInvalid(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
50
|
+
onStopInvalid(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
51
|
+
onPreventStopInvalid(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
52
|
+
onReset(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
53
|
+
onPreventReset(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
54
|
+
onStopReset(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
55
|
+
onPreventStopReset(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
56
|
+
onSearch(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
57
|
+
onStopSearch(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
58
|
+
onSelect(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
59
|
+
onStopSelect(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
60
|
+
onSubmit(callback: (event: SubmitEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
61
|
+
onPreventSubmit(callback: (event: SubmitEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
62
|
+
onStopSubmit(callback: (event: SubmitEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
63
|
+
onPreventStopSubmit(callback: (event: SubmitEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
64
|
+
onDrag(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
65
|
+
onStopDrag(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
66
|
+
onDragEnd(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
67
|
+
onStopDragEnd(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
68
|
+
onDragEnter(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
69
|
+
onStopDragEnter(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
70
|
+
onDragLeave(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
71
|
+
onStopDragLeave(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
72
|
+
onDragOver(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
73
|
+
onPreventDragOver(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
74
|
+
onStopDragOver(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
75
|
+
onPreventStopDragOver(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
76
|
+
onDragStart(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
77
|
+
onStopDragStart(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
78
|
+
onDrop(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
79
|
+
onPreventDrop(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
80
|
+
onStopDrop(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
81
|
+
onPreventStopDrop(callback: (event: DragEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
82
|
+
onAfterPrint(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
83
|
+
onBeforePrint(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
84
|
+
onBeforeUnload(callback: (event: BeforeUnloadEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
85
|
+
onPreventBeforeUnload(callback: (event: BeforeUnloadEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
86
|
+
onStopBeforeUnload(callback: (event: BeforeUnloadEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
87
|
+
onPreventStopBeforeUnload(callback: (event: BeforeUnloadEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
88
|
+
onError(callback: (event: ErrorEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
89
|
+
onHashChange(callback: (event: HashChangeEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
90
|
+
onStopHashChange(callback: (event: HashChangeEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
91
|
+
onLoad(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
92
|
+
onOffline(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
93
|
+
onOnline(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
94
|
+
onPageHide(callback: (event: PageTransitionEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
95
|
+
onPageShow(callback: (event: PageTransitionEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
96
|
+
onResize(callback: (event: UIEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
97
|
+
onScroll(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
98
|
+
onUnload(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
99
|
+
onAbort(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
100
|
+
onCanPlay(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
101
|
+
onCanPlayThrough(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
102
|
+
onDurationChange(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
103
|
+
onEmptied(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
104
|
+
onEnded(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
105
|
+
onLoadedData(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
106
|
+
onLoadedMetadata(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
107
|
+
onLoadStart(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
108
|
+
onPause(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
109
|
+
onPlay(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
110
|
+
onPlaying(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
111
|
+
onProgress(callback: (event: ProgressEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
112
|
+
onRateChange(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
113
|
+
onSeeked(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
114
|
+
onSeeking(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
115
|
+
onStalled(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
116
|
+
onSuspend(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
117
|
+
onTimeUpdate(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
118
|
+
onVolumeChange(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
119
|
+
onWaiting(callback: (event: Event) => void, options?: AddEventListenerOptions | null): this;
|
|
120
|
+
onTouchCancel(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
121
|
+
onPreventTouchCancel(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
122
|
+
onStopTouchCancel(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
123
|
+
onPreventStopTouchCancel(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
124
|
+
onTouchEnd(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
125
|
+
onPreventTouchEnd(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
126
|
+
onStopTouchEnd(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
127
|
+
onPreventStopTouchEnd(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
128
|
+
onTouchMove(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
129
|
+
onPreventTouchMove(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
130
|
+
onStopTouchMove(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
131
|
+
onPreventStopTouchMove(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
132
|
+
onTouchStart(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
133
|
+
onPreventTouchStart(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
134
|
+
onStopTouchStart(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
135
|
+
onPreventStopTouchStart(callback: (event: TouchEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
136
|
+
onAnimationEnd(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
137
|
+
onStopAnimationEnd(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
138
|
+
onAnimationIteration(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
139
|
+
onStopAnimationIteration(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
140
|
+
onAnimationStart(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
141
|
+
onStopAnimationStart(callback: (event: AnimationEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
142
|
+
onTransitionEnd(callback: (event: TransitionEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
143
|
+
onStopTransitionEnd(callback: (event: TransitionEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
144
|
+
onCopy(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
145
|
+
onPreventCopy(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
146
|
+
onStopCopy(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
147
|
+
onPreventStopCopy(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
148
|
+
onCut(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
149
|
+
onPreventCut(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
150
|
+
onStopCut(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
151
|
+
onPreventStopCut(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
152
|
+
onPaste(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
153
|
+
onPreventPaste(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
154
|
+
onStopPaste(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
155
|
+
onPreventStopPaste(callback: (event: ClipboardEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
156
|
+
onFocusIn(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
157
|
+
onStopFocusIn(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
158
|
+
onFocusOut(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
159
|
+
onStopFocusOut(callback: (event: FocusEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
160
|
+
onContextMenu(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
161
|
+
onPreventContextMenu(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
162
|
+
onStopContextMenu(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
163
|
+
onPreventStopContextMenu(callback: (event: MouseEvent) => void, options?: AddEventListenerOptions | null): this;
|
|
164
|
+
}
|
|
@@ -109,6 +109,7 @@ FormControl.prototype.fields = function(fieldBuilder) {
|
|
|
109
109
|
if(typeof fieldBuilder !== 'function') {
|
|
110
110
|
throw new NativeDocumentError('FormControl.fields() expects a function');
|
|
111
111
|
}
|
|
112
|
+
|
|
112
113
|
this.$description.fieldBuilder = (...args) => {
|
|
113
114
|
const result = fieldBuilder(...args);
|
|
114
115
|
const dirties = [];
|
|
@@ -117,6 +118,8 @@ FormControl.prototype.fields = function(fieldBuilder) {
|
|
|
117
118
|
dirties.push(field.$description.isDirty);
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
console.log(dirties);
|
|
122
|
+
|
|
120
123
|
$.computed(() => {
|
|
121
124
|
const isDirty = dirties.some((item) => item.val());
|
|
122
125
|
this.$description.isDirty.set(isDirty);
|
|
@@ -11,6 +11,7 @@ import './observable-helpers/observable.is-to';
|
|
|
11
11
|
import './observable-helpers/observable.prototypes';
|
|
12
12
|
import ObservableResource from './ObservableResource';
|
|
13
13
|
import {Formatters} from '../utils/formatters';
|
|
14
|
+
import Ref from './Ref';
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
16
17
|
* @param {*} value
|
|
@@ -235,6 +236,14 @@ Observable.resource = function(fn, deps = [], options = false) {
|
|
|
235
236
|
return new ObservableResource(fn, deps, config);
|
|
236
237
|
};
|
|
237
238
|
|
|
239
|
+
Observable.ref = function() {
|
|
240
|
+
return new Ref(false);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
Observable.collection = function() {
|
|
244
|
+
return new Ref(true);
|
|
245
|
+
};
|
|
246
|
+
|
|
238
247
|
ObservableItem.prototype.resolve = function () {
|
|
239
248
|
return Observable.value(this);
|
|
240
|
-
};
|
|
249
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export function RefItem(multiple = false) {
|
|
4
|
+
this.$component = multiple ? [] : null;
|
|
5
|
+
this.$node = multiple ? [] : null;
|
|
6
|
+
|
|
7
|
+
this.$multiple = multiple;
|
|
8
|
+
}
|
|
9
|
+
export default function Ref(multiple = false) {
|
|
10
|
+
const ref = new RefItem(multiple);
|
|
11
|
+
|
|
12
|
+
return new Proxy(ref, {
|
|
13
|
+
get(target, property) {
|
|
14
|
+
if(target[property]) {
|
|
15
|
+
return target[property];
|
|
16
|
+
}
|
|
17
|
+
if(property === '__$Ref') {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if(target.$component != null) {
|
|
21
|
+
return typeof target.$component[property] === 'function'
|
|
22
|
+
? target.$component[property].bind(target.$component)
|
|
23
|
+
: target.$component[property];
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
RefItem.prototype.$store = function(component = null, node = null) {
|
|
30
|
+
if(this.$multiple) {
|
|
31
|
+
this.$component.push(component);
|
|
32
|
+
this.$node.push(node);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.$component = component;
|
|
37
|
+
this.$node = node;
|
|
38
|
+
};
|
|
@@ -76,6 +76,10 @@ NDElement.prototype.valueOf = function() {
|
|
|
76
76
|
* refs.emailInput.focus();
|
|
77
77
|
*/
|
|
78
78
|
NDElement.prototype.ref = function(target, name) {
|
|
79
|
+
if(target.__$Ref) {
|
|
80
|
+
target.$store(this, this.$element);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
79
83
|
target[name] = this.$element;
|
|
80
84
|
return this;
|
|
81
85
|
};
|
|
@@ -96,9 +100,11 @@ NDElement.prototype.ref = function(target, name) {
|
|
|
96
100
|
* refs.counter.increment();
|
|
97
101
|
*/
|
|
98
102
|
NDElement.prototype.refSelf = function(target, name) {
|
|
103
|
+
if(target.__$Ref) {
|
|
104
|
+
target.$store(this, this.$element);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
99
107
|
target[name] = this;
|
|
100
|
-
// TODO: @DIM to check
|
|
101
|
-
// target[name] = new NDElement(this.$element);
|
|
102
108
|
return this;
|
|
103
109
|
};
|
|
104
110
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {Div,
|
|
1
|
+
import {Div, ForEachArray} from '../../../../elements';
|
|
2
|
+
import {Button} from '../../../components/button';
|
|
2
3
|
import { $ } from '../../../core/data/Observable';
|
|
3
4
|
|
|
4
5
|
import './field-collection.css';
|
|
@@ -40,7 +41,7 @@ export default function FieldCollectionRender($desc, instance) {
|
|
|
40
41
|
isLast: $isLast,
|
|
41
42
|
item,
|
|
42
43
|
remove: () => {
|
|
43
|
-
instance.
|
|
44
|
+
instance.remove(item);
|
|
44
45
|
},
|
|
45
46
|
moveUp: () => {
|
|
46
47
|
const i = $items.indexOf(item);
|
package/types/observable.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FilterResult, PredicateMap } from './filters';
|
|
2
|
+
import Ref, {RefItem} from './ref';
|
|
2
3
|
|
|
3
4
|
export type Unsubscribe = () => void;
|
|
4
5
|
|
|
@@ -340,6 +341,9 @@ export interface ObservableStatic {
|
|
|
340
341
|
setLocale(locale: string | ObservableItem<string>): void;
|
|
341
342
|
useValueProperty(propertyName?: string): void;
|
|
342
343
|
|
|
344
|
+
ref<T = any>(): RefItem<T> & T;
|
|
345
|
+
collection<T = any>(): RefItem<T[]> & T[];
|
|
346
|
+
|
|
343
347
|
getById(id: number): ObservableItem | null;
|
|
344
348
|
cleanup(observable: ObservableItem): void;
|
|
345
349
|
autoCleanup(enable?: boolean, options?: AutoCleanupOptions): void;
|
package/types/ref.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
export declare class RefItem<T = any> {
|
|
3
|
+
$component: T | T[] | null;
|
|
4
|
+
$node: HTMLElement | HTMLElement[] | null;
|
|
5
|
+
$multiple: boolean;
|
|
6
|
+
|
|
7
|
+
constructor(multiple?: boolean);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Assigns a component instance and its DOM node to the ref.
|
|
11
|
+
* In multiple mode, pushes to the internal arrays.
|
|
12
|
+
*
|
|
13
|
+
* @param component - Component instance to store
|
|
14
|
+
* @param node - Associated DOM node
|
|
15
|
+
*/
|
|
16
|
+
$store(component?: T | null, node?: HTMLElement | null): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare function Ref<T = any>(multiple?: false): RefItem<T> & T;
|
|
20
|
+
export declare function Ref<T = any>(multiple: true): RefItem<T[]> & { [K in keyof T]: T[K] };
|
|
21
|
+
|
|
22
|
+
export { Ref as default };
|