@tectra-ng/utils 0.0.1 → 0.2.1
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/LICENSE +21 -0
- package/README.md +40 -1
- package/auto-focus/README.md +19 -0
- package/breakpoint/README.md +23 -0
- package/clipboard/README.md +37 -0
- package/clock/README.md +21 -0
- package/currency/README.md +17 -0
- package/date/README.md +46 -0
- package/debounce-input/README.md +31 -0
- package/drag-scroll/README.md +25 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs +100 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs +54 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs +225 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clock.mjs +59 -0
- package/fesm2022/tectra-ng-utils-clock.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-currency.mjs +63 -0
- package/fesm2022/tectra-ng-utils-currency.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-date.mjs +200 -0
- package/fesm2022/tectra-ng-utils-date.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs +156 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs +199 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-file.mjs +78 -0
- package/fesm2022/tectra-ng-utils-file.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs +238 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter.mjs +88 -0
- package/fesm2022/tectra-ng-utils-filter.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs +70 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs +162 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs +117 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-http.mjs +189 -0
- package/fesm2022/tectra-ng-utils-http.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs +297 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-plural.mjs +98 -0
- package/fesm2022/tectra-ng-utils-plural.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-polling.mjs +109 -0
- package/fesm2022/tectra-ng-utils-polling.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-random.mjs +20 -0
- package/fesm2022/tectra-ng-utils-random.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs +87 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs +136 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-selection.mjs +52 -0
- package/fesm2022/tectra-ng-utils-selection.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs +92 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stream.mjs +30 -0
- package/fesm2022/tectra-ng-utils-stream.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs +350 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-text.mjs +173 -0
- package/fesm2022/tectra-ng-utils-text.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-title.mjs +99 -0
- package/fesm2022/tectra-ng-utils-title.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-validators.mjs +232 -0
- package/fesm2022/tectra-ng-utils-validators.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils.mjs +4 -0
- package/fesm2022/tectra-ng-utils.mjs.map +1 -0
- package/file/README.md +19 -0
- package/filter/README.md +22 -0
- package/filter-state/README.md +36 -0
- package/form-changes/README.md +26 -0
- package/form-validation/README.md +40 -0
- package/go-back/README.md +28 -0
- package/http/README.md +34 -0
- package/in-view/README.md +34 -0
- package/package.json +173 -3
- package/plural/README.md +21 -0
- package/polling/README.md +34 -0
- package/random/README.md +10 -0
- package/relative-time/README.md +29 -0
- package/scroll-end/README.md +25 -0
- package/selection/README.md +24 -0
- package/stop-propagation/README.md +15 -0
- package/stream/README.md +14 -0
- package/style-class/README.md +34 -0
- package/text/README.md +25 -0
- package/title/README.md +26 -0
- package/types/tectra-ng-utils-auto-focus.d.ts +22 -0
- package/types/tectra-ng-utils-auto-focus.d.ts.map +1 -0
- package/types/tectra-ng-utils-breakpoint.d.ts +15 -0
- package/types/tectra-ng-utils-breakpoint.d.ts.map +1 -0
- package/types/tectra-ng-utils-clipboard.d.ts +48 -0
- package/types/tectra-ng-utils-clipboard.d.ts.map +1 -0
- package/types/tectra-ng-utils-clock.d.ts +18 -0
- package/types/tectra-ng-utils-clock.d.ts.map +1 -0
- package/types/tectra-ng-utils-currency.d.ts +11 -0
- package/types/tectra-ng-utils-currency.d.ts.map +1 -0
- package/types/tectra-ng-utils-date.d.ts +65 -0
- package/types/tectra-ng-utils-date.d.ts.map +1 -0
- package/types/tectra-ng-utils-debounce-input.d.ts +38 -0
- package/types/tectra-ng-utils-debounce-input.d.ts.map +1 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts +41 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts.map +1 -0
- package/types/tectra-ng-utils-file.d.ts +18 -0
- package/types/tectra-ng-utils-file.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter-state.d.ts +55 -0
- package/types/tectra-ng-utils-filter-state.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter.d.ts +21 -0
- package/types/tectra-ng-utils-filter.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-changes.d.ts +22 -0
- package/types/tectra-ng-utils-form-changes.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-validation.d.ts +45 -0
- package/types/tectra-ng-utils-form-validation.d.ts.map +1 -0
- package/types/tectra-ng-utils-go-back.d.ts +25 -0
- package/types/tectra-ng-utils-go-back.d.ts.map +1 -0
- package/types/tectra-ng-utils-http.d.ts +47 -0
- package/types/tectra-ng-utils-http.d.ts.map +1 -0
- package/types/tectra-ng-utils-in-view.d.ts +80 -0
- package/types/tectra-ng-utils-in-view.d.ts.map +1 -0
- package/types/tectra-ng-utils-plural.d.ts +21 -0
- package/types/tectra-ng-utils-plural.d.ts.map +1 -0
- package/types/tectra-ng-utils-polling.d.ts +61 -0
- package/types/tectra-ng-utils-polling.d.ts.map +1 -0
- package/types/tectra-ng-utils-random.d.ts +4 -0
- package/types/tectra-ng-utils-random.d.ts.map +1 -0
- package/types/tectra-ng-utils-relative-time.d.ts +22 -0
- package/types/tectra-ng-utils-relative-time.d.ts.map +1 -0
- package/types/tectra-ng-utils-scroll-end.d.ts +38 -0
- package/types/tectra-ng-utils-scroll-end.d.ts.map +1 -0
- package/types/tectra-ng-utils-selection.d.ts +21 -0
- package/types/tectra-ng-utils-selection.d.ts.map +1 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts +22 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts.map +1 -0
- package/types/tectra-ng-utils-stream.d.ts +3 -0
- package/types/tectra-ng-utils-stream.d.ts.map +1 -0
- package/types/tectra-ng-utils-style-class.d.ts +91 -0
- package/types/tectra-ng-utils-style-class.d.ts.map +1 -0
- package/types/tectra-ng-utils-text.d.ts +26 -0
- package/types/tectra-ng-utils-text.d.ts.map +1 -0
- package/types/tectra-ng-utils-title.d.ts +31 -0
- package/types/tectra-ng-utils-title.d.ts.map +1 -0
- package/types/tectra-ng-utils-validators.d.ts +67 -0
- package/types/tectra-ng-utils-validators.d.ts.map +1 -0
- package/types/tectra-ng-utils.d.ts +2 -0
- package/types/tectra-ng-utils.d.ts.map +1 -0
- package/validators/README.md +42 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { DestroyRef, Directive, booleanAttribute, inject, input, numberAttribute, output } from "@angular/core";
|
|
3
|
+
var TxDebounceInput = class TxDebounceInput {
|
|
4
|
+
debounceTime = input(1e3, {
|
|
5
|
+
...ngDevMode ? { debugName: "debounceTime" } : /* istanbul ignore next */ {},
|
|
6
|
+
transform: numberAttribute
|
|
7
|
+
});
|
|
8
|
+
distinct = input(false, {
|
|
9
|
+
...ngDevMode ? { debugName: "distinct" } : /* istanbul ignore next */ {},
|
|
10
|
+
transform: booleanAttribute
|
|
11
|
+
});
|
|
12
|
+
minLength = input(0, {
|
|
13
|
+
...ngDevMode ? { debugName: "minLength" } : /* istanbul ignore next */ {},
|
|
14
|
+
transform: numberAttribute
|
|
15
|
+
});
|
|
16
|
+
debounceInput = output();
|
|
17
|
+
debounceValue = output();
|
|
18
|
+
timeout = null;
|
|
19
|
+
pending = null;
|
|
20
|
+
lastValue = null;
|
|
21
|
+
constructor() {
|
|
22
|
+
inject(DestroyRef).onDestroy(() => this.cancel());
|
|
23
|
+
}
|
|
24
|
+
schedule(event) {
|
|
25
|
+
this.cancel();
|
|
26
|
+
this.pending = event;
|
|
27
|
+
this.timeout = setTimeout(() => this.emit(event), this.debounceTime());
|
|
28
|
+
}
|
|
29
|
+
flush(event) {
|
|
30
|
+
const pending = this.pending ?? event;
|
|
31
|
+
this.cancel();
|
|
32
|
+
if (pending) this.emit(pending, true);
|
|
33
|
+
}
|
|
34
|
+
cancel() {
|
|
35
|
+
if (this.timeout) clearTimeout(this.timeout);
|
|
36
|
+
this.timeout = null;
|
|
37
|
+
this.pending = null;
|
|
38
|
+
}
|
|
39
|
+
emit(event, forced = false) {
|
|
40
|
+
this.timeout = null;
|
|
41
|
+
this.pending = null;
|
|
42
|
+
const value = valueOf(event);
|
|
43
|
+
if (value.length > 0 && value.trim().length < this.minLength()) return;
|
|
44
|
+
if (!forced && this.distinct() && value === this.lastValue) return;
|
|
45
|
+
this.lastValue = value;
|
|
46
|
+
this.debounceInput.emit(event);
|
|
47
|
+
this.debounceValue.emit(value);
|
|
48
|
+
}
|
|
49
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
50
|
+
minVersion: "12.0.0",
|
|
51
|
+
version: "22.2.3",
|
|
52
|
+
ngImport: i0,
|
|
53
|
+
type: TxDebounceInput,
|
|
54
|
+
deps: [],
|
|
55
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
56
|
+
});
|
|
57
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
58
|
+
minVersion: "17.1.0",
|
|
59
|
+
version: "22.2.3",
|
|
60
|
+
type: TxDebounceInput,
|
|
61
|
+
isStandalone: true,
|
|
62
|
+
selector: "[txDebounceInput]",
|
|
63
|
+
inputs: {
|
|
64
|
+
debounceTime: {
|
|
65
|
+
classPropertyName: "debounceTime",
|
|
66
|
+
publicName: "debounceTime",
|
|
67
|
+
isSignal: true,
|
|
68
|
+
isRequired: false,
|
|
69
|
+
transformFunction: null
|
|
70
|
+
},
|
|
71
|
+
distinct: {
|
|
72
|
+
classPropertyName: "distinct",
|
|
73
|
+
publicName: "distinct",
|
|
74
|
+
isSignal: true,
|
|
75
|
+
isRequired: false,
|
|
76
|
+
transformFunction: null
|
|
77
|
+
},
|
|
78
|
+
minLength: {
|
|
79
|
+
classPropertyName: "minLength",
|
|
80
|
+
publicName: "minLength",
|
|
81
|
+
isSignal: true,
|
|
82
|
+
isRequired: false,
|
|
83
|
+
transformFunction: null
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
outputs: {
|
|
87
|
+
debounceInput: "debounceInput",
|
|
88
|
+
debounceValue: "debounceValue"
|
|
89
|
+
},
|
|
90
|
+
host: { listeners: {
|
|
91
|
+
"input": "schedule($event)",
|
|
92
|
+
"keydown.enter": "flush($event)"
|
|
93
|
+
} },
|
|
94
|
+
exportAs: ["txDebounceInput"],
|
|
95
|
+
ngImport: i0
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
99
|
+
minVersion: "12.0.0",
|
|
100
|
+
version: "22.2.3",
|
|
101
|
+
ngImport: i0,
|
|
102
|
+
type: TxDebounceInput,
|
|
103
|
+
decorators: [{
|
|
104
|
+
type: Directive,
|
|
105
|
+
args: [{
|
|
106
|
+
selector: "[txDebounceInput]",
|
|
107
|
+
exportAs: "txDebounceInput",
|
|
108
|
+
host: {
|
|
109
|
+
"(input)": "schedule($event)",
|
|
110
|
+
"(keydown.enter)": "flush($event)"
|
|
111
|
+
}
|
|
112
|
+
}]
|
|
113
|
+
}],
|
|
114
|
+
ctorParameters: () => [],
|
|
115
|
+
propDecorators: {
|
|
116
|
+
debounceTime: [{
|
|
117
|
+
type: i0.Input,
|
|
118
|
+
args: [{
|
|
119
|
+
isSignal: true,
|
|
120
|
+
alias: "debounceTime",
|
|
121
|
+
required: false
|
|
122
|
+
}]
|
|
123
|
+
}],
|
|
124
|
+
distinct: [{
|
|
125
|
+
type: i0.Input,
|
|
126
|
+
args: [{
|
|
127
|
+
isSignal: true,
|
|
128
|
+
alias: "distinct",
|
|
129
|
+
required: false
|
|
130
|
+
}]
|
|
131
|
+
}],
|
|
132
|
+
minLength: [{
|
|
133
|
+
type: i0.Input,
|
|
134
|
+
args: [{
|
|
135
|
+
isSignal: true,
|
|
136
|
+
alias: "minLength",
|
|
137
|
+
required: false
|
|
138
|
+
}]
|
|
139
|
+
}],
|
|
140
|
+
debounceInput: [{
|
|
141
|
+
type: i0.Output,
|
|
142
|
+
args: ["debounceInput"]
|
|
143
|
+
}],
|
|
144
|
+
debounceValue: [{
|
|
145
|
+
type: i0.Output,
|
|
146
|
+
args: ["debounceValue"]
|
|
147
|
+
}]
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
function valueOf(event) {
|
|
151
|
+
const target = event.target;
|
|
152
|
+
return typeof target?.value === "string" ? target.value : "";
|
|
153
|
+
}
|
|
154
|
+
export { TxDebounceInput };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=tectra-ng-utils-debounce-input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-debounce-input.mjs","names":[],"sources":["../../../../packages/utils/debounce-input/src/debounce-input.directive.ts"],"sourcesContent":["import { DestroyRef, Directive, booleanAttribute, inject, input, numberAttribute, output } from '@angular/core';\n\n@Directive({\n selector: '[txDebounceInput]',\n exportAs: 'txDebounceInput',\n host: {\n '(input)': 'schedule($event)',\n '(keydown.enter)': 'flush($event)',\n },\n})\nexport class TxDebounceInput {\n readonly debounceTime = input<number, unknown>(1000, { transform: numberAttribute });\n readonly distinct = input<boolean, unknown>(false, { transform: booleanAttribute });\n readonly minLength = input<number, unknown>(0, { transform: numberAttribute });\n\n readonly debounceInput = output<Event>();\n readonly debounceValue = output<string>();\n\n private timeout: ReturnType<typeof setTimeout> | null = null;\n private pending: Event | null = null;\n private lastValue: string | null = null;\n\n constructor() {\n inject(DestroyRef).onDestroy(() => this.cancel());\n }\n\n schedule(event: Event): void {\n this.cancel();\n this.pending = event;\n this.timeout = setTimeout(() => this.emit(event), this.debounceTime());\n }\n\n flush(event?: Event): void {\n const pending = this.pending ?? event;\n this.cancel();\n if (pending) {\n this.emit(pending, true);\n }\n }\n\n cancel(): void {\n if (this.timeout) {\n clearTimeout(this.timeout);\n }\n this.timeout = null;\n this.pending = null;\n }\n\n private emit(event: Event, forced = false): void {\n this.timeout = null;\n this.pending = null;\n const value = valueOf(event);\n if (value.length > 0 && value.trim().length < this.minLength()) {\n return;\n }\n if (!forced && this.distinct() && value === this.lastValue) {\n return;\n }\n this.lastValue = value;\n this.debounceInput.emit(event);\n this.debounceValue.emit(value);\n }\n}\n\nfunction valueOf(event: Event): string {\n const target = event.target as { value?: unknown } | null;\n return typeof target?.value === 'string' ? target.value : '';\n}\n"],"mappings":";;AAUA,IAAa,kBAAb,MAAa,gBAAe;CACjB,eAAe,MAAuB,KAAI;EAAA,GAAA,YAAA,EAAA,WAAA,eAAA,+BAAA,CAAA;EAAI,WAAW;CAAe,CAAA;CACxE,WAAW,MAAwB,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CACvE,YAAY,MAAuB,GAAC;EAAA,GAAA,YAAA,EAAA,WAAA,YAAA,+BAAA,CAAA;EAAI,WAAW;CAAe,CAAA;CAElE,gBAAgB,OAAM;CACtB,gBAAgB,OAAM;CAEvB,UAAgD;CAChD,UAAwB;CACxB,YAA2B;CAEnC,cAAA;EACE,OAAO,UAAU,CAAC,CAAC,gBAAgB,KAAK,OAAM,CAAE;CAClD;CAEA,SAAS,OAAY;EACnB,KAAK,OAAM;EACX,KAAK,UAAU;EACf,KAAK,UAAU,iBAAiB,KAAK,KAAK,KAAK,GAAG,KAAK,aAAY,CAAE;CACvE;CAEA,MAAM,OAAa;EACjB,MAAM,UAAU,KAAK,WAAW;EAChC,KAAK,OAAM;EACX,IAAI,SACF,KAAK,KAAK,SAAS,IAAI;CAE3B;CAEA,SAAM;EACJ,IAAI,KAAK,SACP,aAAa,KAAK,OAAO;EAE3B,KAAK,UAAU;EACf,KAAK,UAAU;CACjB;CAEQ,KAAK,OAAc,SAAS,OAAK;EACvC,KAAK,UAAU;EACf,KAAK,UAAU;EACf,MAAM,QAAQ,QAAQ,KAAK;EAC3B,IAAI,MAAM,SAAS,KAAK,MAAM,KAAI,CAAE,CAAC,SAAS,KAAK,UAAS,GAC1D;EAEF,IAAI,CAAC,UAAU,KAAK,SAAQ,KAAM,UAAU,KAAK,WAC/C;EAEF,KAAK,YAAY;EACjB,KAAK,cAAc,KAAK,KAAK;EAC7B,KAAK,cAAc,KAAK,KAAK;CAC/B;CAnDW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAf,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAe,cAAA;EAAA,UAAA;EAAA,QAAA;GAAA,cAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,UAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,WAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,SAAA;GAAA,eAAA;GAAA,eAAA;EAAA;EAAA,MAAA,EAAA,WAAA;GAAA,SAAA;GAAA,iBAAA;EAAA,EAAA;EAAA,UAAA,CAAA,iBAAA;EAAA,UAAA;CAAA,CAAA;;AAAf,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAe,YAAA,CAAA;EAR3B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,WAAW;IACX,mBAAmB;GACpB;EACF,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDD,SAAS,QAAQ,OAAY;CAC3B,MAAM,SAAS,MAAM;CACrB,OAAO,OAAO,QAAQ,UAAU,WAAW,OAAO,QAAQ;AAC5D"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { DestroyRef, Directive, ElementRef, booleanAttribute, inject, input, output, signal } from "@angular/core";
|
|
3
|
+
const DRAG_THRESHOLD = 4;
|
|
4
|
+
const IGNORED = "button, a, input, textarea, select, label, [contenteditable=\"true\"], [data-drag-ignore]";
|
|
5
|
+
var TxDragScroll = class TxDragScroll {
|
|
6
|
+
host = inject(ElementRef).nativeElement;
|
|
7
|
+
panMode = input(false, {
|
|
8
|
+
...ngDevMode ? { debugName: "panMode" } : /* istanbul ignore next */ {},
|
|
9
|
+
transform: booleanAttribute
|
|
10
|
+
});
|
|
11
|
+
disabled = input(false, {
|
|
12
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
13
|
+
transform: booleanAttribute
|
|
14
|
+
});
|
|
15
|
+
panMove = output();
|
|
16
|
+
dragStart = output();
|
|
17
|
+
dragEnd = output();
|
|
18
|
+
isDragging = signal(false, ...ngDevMode ? [{ debugName: "isDragging" }] : /* istanbul ignore next */ []);
|
|
19
|
+
pointerId = null;
|
|
20
|
+
start = {
|
|
21
|
+
x: 0,
|
|
22
|
+
y: 0,
|
|
23
|
+
left: 0,
|
|
24
|
+
top: 0
|
|
25
|
+
};
|
|
26
|
+
last = {
|
|
27
|
+
x: 0,
|
|
28
|
+
y: 0
|
|
29
|
+
};
|
|
30
|
+
moved = false;
|
|
31
|
+
swallowClick = (event) => {
|
|
32
|
+
if (this.moved) {
|
|
33
|
+
event.stopPropagation();
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
this.moved = false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
constructor() {
|
|
39
|
+
this.host.addEventListener?.("click", this.swallowClick, true);
|
|
40
|
+
inject(DestroyRef).onDestroy(() => this.host.removeEventListener?.("click", this.swallowClick, true));
|
|
41
|
+
}
|
|
42
|
+
onPointerDown(event) {
|
|
43
|
+
if (this.disabled() || event.button !== 0 || event.pointerType === "touch" || event.target instanceof Element && event.target.closest(IGNORED)) return;
|
|
44
|
+
this.pointerId = event.pointerId;
|
|
45
|
+
this.start = {
|
|
46
|
+
x: event.clientX,
|
|
47
|
+
y: event.clientY,
|
|
48
|
+
left: this.host.scrollLeft,
|
|
49
|
+
top: this.host.scrollTop
|
|
50
|
+
};
|
|
51
|
+
this.last = {
|
|
52
|
+
x: event.clientX,
|
|
53
|
+
y: event.clientY
|
|
54
|
+
};
|
|
55
|
+
this.moved = false;
|
|
56
|
+
}
|
|
57
|
+
onPointerMove(event) {
|
|
58
|
+
if (this.pointerId !== event.pointerId) return;
|
|
59
|
+
const dx = event.clientX - this.start.x;
|
|
60
|
+
const dy = event.clientY - this.start.y;
|
|
61
|
+
if (!this.moved && Math.abs(dx) + Math.abs(dy) < DRAG_THRESHOLD) return;
|
|
62
|
+
if (!this.moved) {
|
|
63
|
+
this.moved = true;
|
|
64
|
+
this.isDragging.set(true);
|
|
65
|
+
this.host.setPointerCapture?.(event.pointerId);
|
|
66
|
+
this.dragStart.emit();
|
|
67
|
+
}
|
|
68
|
+
if (this.panMode()) this.panMove.emit({
|
|
69
|
+
dx: event.clientX - this.last.x,
|
|
70
|
+
dy: event.clientY - this.last.y
|
|
71
|
+
});
|
|
72
|
+
else {
|
|
73
|
+
this.host.scrollLeft = this.start.left - dx;
|
|
74
|
+
this.host.scrollTop = this.start.top - dy;
|
|
75
|
+
}
|
|
76
|
+
this.last = {
|
|
77
|
+
x: event.clientX,
|
|
78
|
+
y: event.clientY
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
onPointerUp(event) {
|
|
82
|
+
if (this.pointerId !== event.pointerId) return;
|
|
83
|
+
this.host.releasePointerCapture?.(event.pointerId);
|
|
84
|
+
this.pointerId = null;
|
|
85
|
+
if (this.isDragging()) {
|
|
86
|
+
this.isDragging.set(false);
|
|
87
|
+
this.dragEnd.emit();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
91
|
+
minVersion: "12.0.0",
|
|
92
|
+
version: "22.2.3",
|
|
93
|
+
ngImport: i0,
|
|
94
|
+
type: TxDragScroll,
|
|
95
|
+
deps: [],
|
|
96
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
97
|
+
});
|
|
98
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
99
|
+
minVersion: "17.1.0",
|
|
100
|
+
version: "22.2.3",
|
|
101
|
+
type: TxDragScroll,
|
|
102
|
+
isStandalone: true,
|
|
103
|
+
selector: "[txDragScroll]",
|
|
104
|
+
inputs: {
|
|
105
|
+
panMode: {
|
|
106
|
+
classPropertyName: "panMode",
|
|
107
|
+
publicName: "panMode",
|
|
108
|
+
isSignal: true,
|
|
109
|
+
isRequired: false,
|
|
110
|
+
transformFunction: null
|
|
111
|
+
},
|
|
112
|
+
disabled: {
|
|
113
|
+
classPropertyName: "disabled",
|
|
114
|
+
publicName: "disabled",
|
|
115
|
+
isSignal: true,
|
|
116
|
+
isRequired: false,
|
|
117
|
+
transformFunction: null
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
outputs: {
|
|
121
|
+
panMove: "panMove",
|
|
122
|
+
dragStart: "dragStart",
|
|
123
|
+
dragEnd: "dragEnd"
|
|
124
|
+
},
|
|
125
|
+
host: {
|
|
126
|
+
listeners: {
|
|
127
|
+
"pointerdown": "onPointerDown($event)",
|
|
128
|
+
"pointermove": "onPointerMove($event)",
|
|
129
|
+
"pointerup": "onPointerUp($event)",
|
|
130
|
+
"pointercancel": "onPointerUp($event)"
|
|
131
|
+
},
|
|
132
|
+
properties: {
|
|
133
|
+
"class.tx-drag-scroll--dragging": "isDragging()",
|
|
134
|
+
"style.cursor": "disabled() ? null : isDragging() ? \"grabbing\" : \"grab\"",
|
|
135
|
+
"style.user-select": "isDragging() ? \"none\" : null"
|
|
136
|
+
},
|
|
137
|
+
classAttribute: "tx-drag-scroll"
|
|
138
|
+
},
|
|
139
|
+
exportAs: ["txDragScroll"],
|
|
140
|
+
ngImport: i0
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
144
|
+
minVersion: "12.0.0",
|
|
145
|
+
version: "22.2.3",
|
|
146
|
+
ngImport: i0,
|
|
147
|
+
type: TxDragScroll,
|
|
148
|
+
decorators: [{
|
|
149
|
+
type: Directive,
|
|
150
|
+
args: [{
|
|
151
|
+
selector: "[txDragScroll]",
|
|
152
|
+
exportAs: "txDragScroll",
|
|
153
|
+
host: {
|
|
154
|
+
class: "tx-drag-scroll",
|
|
155
|
+
"[class.tx-drag-scroll--dragging]": "isDragging()",
|
|
156
|
+
"[style.cursor]": "disabled() ? null : isDragging() ? \"grabbing\" : \"grab\"",
|
|
157
|
+
"[style.user-select]": "isDragging() ? \"none\" : null",
|
|
158
|
+
"(pointerdown)": "onPointerDown($event)",
|
|
159
|
+
"(pointermove)": "onPointerMove($event)",
|
|
160
|
+
"(pointerup)": "onPointerUp($event)",
|
|
161
|
+
"(pointercancel)": "onPointerUp($event)"
|
|
162
|
+
}
|
|
163
|
+
}]
|
|
164
|
+
}],
|
|
165
|
+
ctorParameters: () => [],
|
|
166
|
+
propDecorators: {
|
|
167
|
+
panMode: [{
|
|
168
|
+
type: i0.Input,
|
|
169
|
+
args: [{
|
|
170
|
+
isSignal: true,
|
|
171
|
+
alias: "panMode",
|
|
172
|
+
required: false
|
|
173
|
+
}]
|
|
174
|
+
}],
|
|
175
|
+
disabled: [{
|
|
176
|
+
type: i0.Input,
|
|
177
|
+
args: [{
|
|
178
|
+
isSignal: true,
|
|
179
|
+
alias: "disabled",
|
|
180
|
+
required: false
|
|
181
|
+
}]
|
|
182
|
+
}],
|
|
183
|
+
panMove: [{
|
|
184
|
+
type: i0.Output,
|
|
185
|
+
args: ["panMove"]
|
|
186
|
+
}],
|
|
187
|
+
dragStart: [{
|
|
188
|
+
type: i0.Output,
|
|
189
|
+
args: ["dragStart"]
|
|
190
|
+
}],
|
|
191
|
+
dragEnd: [{
|
|
192
|
+
type: i0.Output,
|
|
193
|
+
args: ["dragEnd"]
|
|
194
|
+
}]
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
export { TxDragScroll };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=tectra-ng-utils-drag-scroll.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-drag-scroll.mjs","names":[],"sources":["../../../../packages/utils/drag-scroll/src/drag-scroll.directive.ts"],"sourcesContent":["import { DestroyRef, Directive, ElementRef, booleanAttribute, inject, input, output, signal } from '@angular/core';\n\nexport interface TxDragPanDelta {\n dx: number;\n dy: number;\n}\n\nconst DRAG_THRESHOLD = 4;\nconst IGNORED = 'button, a, input, textarea, select, label, [contenteditable=\"true\"], [data-drag-ignore]';\n\n@Directive({\n selector: '[txDragScroll]',\n exportAs: 'txDragScroll',\n host: {\n class: 'tx-drag-scroll',\n '[class.tx-drag-scroll--dragging]': 'isDragging()',\n '[style.cursor]': 'disabled() ? null : isDragging() ? \"grabbing\" : \"grab\"',\n '[style.user-select]': 'isDragging() ? \"none\" : null',\n '(pointerdown)': 'onPointerDown($event)',\n '(pointermove)': 'onPointerMove($event)',\n '(pointerup)': 'onPointerUp($event)',\n '(pointercancel)': 'onPointerUp($event)',\n },\n})\nexport class TxDragScroll {\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\n readonly panMode = input<boolean, unknown>(false, { transform: booleanAttribute });\n readonly disabled = input<boolean, unknown>(false, { transform: booleanAttribute });\n\n readonly panMove = output<TxDragPanDelta>();\n readonly dragStart = output<void>();\n readonly dragEnd = output<void>();\n\n readonly isDragging = signal(false);\n\n private pointerId: number | null = null;\n private start = { x: 0, y: 0, left: 0, top: 0 };\n private last = { x: 0, y: 0 };\n private moved = false;\n private readonly swallowClick = (event: MouseEvent): void => {\n if (this.moved) {\n event.stopPropagation();\n event.preventDefault();\n this.moved = false;\n }\n };\n\n constructor() {\n this.host.addEventListener?.('click', this.swallowClick, true);\n inject(DestroyRef).onDestroy(() => this.host.removeEventListener?.('click', this.swallowClick, true));\n }\n\n protected onPointerDown(event: PointerEvent): void {\n if (this.disabled() || event.button !== 0 || event.pointerType === 'touch' || (event.target instanceof Element && event.target.closest(IGNORED))) {\n return;\n }\n this.pointerId = event.pointerId;\n this.start = { x: event.clientX, y: event.clientY, left: this.host.scrollLeft, top: this.host.scrollTop };\n this.last = { x: event.clientX, y: event.clientY };\n this.moved = false;\n }\n\n protected onPointerMove(event: PointerEvent): void {\n if (this.pointerId !== event.pointerId) {\n return;\n }\n const dx = event.clientX - this.start.x;\n const dy = event.clientY - this.start.y;\n if (!this.moved && Math.abs(dx) + Math.abs(dy) < DRAG_THRESHOLD) {\n return;\n }\n if (!this.moved) {\n this.moved = true;\n this.isDragging.set(true);\n this.host.setPointerCapture?.(event.pointerId);\n this.dragStart.emit();\n }\n if (this.panMode()) {\n this.panMove.emit({ dx: event.clientX - this.last.x, dy: event.clientY - this.last.y });\n } else {\n this.host.scrollLeft = this.start.left - dx;\n this.host.scrollTop = this.start.top - dy;\n }\n this.last = { x: event.clientX, y: event.clientY };\n }\n\n protected onPointerUp(event: PointerEvent): void {\n if (this.pointerId !== event.pointerId) {\n return;\n }\n this.host.releasePointerCapture?.(event.pointerId);\n this.pointerId = null;\n if (this.isDragging()) {\n this.isDragging.set(false);\n this.dragEnd.emit();\n }\n }\n}\n"],"mappings":";;AAOA,MAAM,iBAAiB;AACvB,MAAM,UAAU;AAgBhB,IAAa,eAAb,MAAa,aAAY;CACN,OAAO,OAAgC,UAAU,CAAC,CAAC;CAE3D,UAAU,MAAwB,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,UAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CACtE,WAAW,MAAwB,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CAEvE,UAAU,OAAM;CAChB,YAAY,OAAM;CAClB,UAAU,OAAM;CAEhB,aAAa,OAAO,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CAE3B,YAA2B;CAC3B,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,MAAM;EAAG,KAAK;CAAC;CACrC,OAAO;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mBAAmB;GACpB;EACF,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Pipe, inject } from "@angular/core";
|
|
3
|
+
import { TxLocaleService } from "@tectra-ng/core/i18n";
|
|
4
|
+
const UNITS = [
|
|
5
|
+
"B",
|
|
6
|
+
"KB",
|
|
7
|
+
"MB",
|
|
8
|
+
"GB",
|
|
9
|
+
"TB",
|
|
10
|
+
"PB"
|
|
11
|
+
];
|
|
12
|
+
function formatFileSize(bytes, options = {}) {
|
|
13
|
+
const { decimals = 1, base = 1024, locale = "en-US", empty = "-" } = options;
|
|
14
|
+
if (bytes === null || bytes === void 0 || !Number.isFinite(bytes) || bytes < 0) return empty;
|
|
15
|
+
const exponent = bytes < base ? 0 : Math.min(UNITS.length - 1, Math.floor(Math.log(bytes) / Math.log(base)));
|
|
16
|
+
const value = bytes / base ** exponent;
|
|
17
|
+
return `${new Intl.NumberFormat(locale, { maximumFractionDigits: exponent === 0 ? 0 : decimals }).format(value)} ${UNITS[exponent]}`;
|
|
18
|
+
}
|
|
19
|
+
function downloadBlob(blob, filename = "file", document = globalThis.document) {
|
|
20
|
+
const view = document?.defaultView;
|
|
21
|
+
if (!document || !view) return;
|
|
22
|
+
const url = view.URL.createObjectURL(blob);
|
|
23
|
+
downloadFile(url, filename, document);
|
|
24
|
+
view.setTimeout(() => view.URL.revokeObjectURL(url));
|
|
25
|
+
}
|
|
26
|
+
function downloadFile(url, filename, document = globalThis.document) {
|
|
27
|
+
if (!document?.body) return;
|
|
28
|
+
const anchor = document.createElement("a");
|
|
29
|
+
anchor.href = url;
|
|
30
|
+
anchor.download = filename ?? url.split(/[?#]/)[0].split("/").pop() ?? "file";
|
|
31
|
+
anchor.rel = "noopener";
|
|
32
|
+
anchor.style.display = "none";
|
|
33
|
+
document.body.appendChild(anchor);
|
|
34
|
+
anchor.click();
|
|
35
|
+
document.body.removeChild(anchor);
|
|
36
|
+
}
|
|
37
|
+
var TxFileSizePipe = class TxFileSizePipe {
|
|
38
|
+
localeService = inject(TxLocaleService);
|
|
39
|
+
transform(bytes, options = {}) {
|
|
40
|
+
return formatFileSize(bytes, {
|
|
41
|
+
...options,
|
|
42
|
+
locale: options.locale ?? this.localeService.locale().intl
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
46
|
+
minVersion: "12.0.0",
|
|
47
|
+
version: "22.2.3",
|
|
48
|
+
ngImport: i0,
|
|
49
|
+
type: TxFileSizePipe,
|
|
50
|
+
deps: [],
|
|
51
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
52
|
+
});
|
|
53
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
54
|
+
minVersion: "14.0.0",
|
|
55
|
+
version: "22.2.3",
|
|
56
|
+
ngImport: i0,
|
|
57
|
+
type: TxFileSizePipe,
|
|
58
|
+
isStandalone: true,
|
|
59
|
+
name: "txFileSize",
|
|
60
|
+
pure: false
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
64
|
+
minVersion: "12.0.0",
|
|
65
|
+
version: "22.2.3",
|
|
66
|
+
ngImport: i0,
|
|
67
|
+
type: TxFileSizePipe,
|
|
68
|
+
decorators: [{
|
|
69
|
+
type: Pipe,
|
|
70
|
+
args: [{
|
|
71
|
+
name: "txFileSize",
|
|
72
|
+
pure: false
|
|
73
|
+
}]
|
|
74
|
+
}]
|
|
75
|
+
});
|
|
76
|
+
export { TxFileSizePipe, downloadBlob, downloadFile, formatFileSize };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=tectra-ng-utils-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-file.mjs","names":[],"sources":["../../../../packages/utils/file/src/file.ts"],"sourcesContent":["import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\n\nexport interface TxFileSizeOptions {\n decimals?: number;\n base?: 1000 | 1024;\n locale?: string;\n empty?: string;\n}\n\nconst UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];\n\nexport function formatFileSize(bytes: number | null | undefined, options: TxFileSizeOptions = {}): string {\n const { decimals = 1, base = 1024, locale = 'en-US', empty = '-' } = options;\n if (bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0) {\n return empty;\n }\n const exponent = bytes < base ? 0 : Math.min(UNITS.length - 1, Math.floor(Math.log(bytes) / Math.log(base)));\n const value = bytes / base ** exponent;\n const number = new Intl.NumberFormat(locale, { maximumFractionDigits: exponent === 0 ? 0 : decimals }).format(value);\n return `${number} ${UNITS[exponent]}`;\n}\n\nexport function downloadBlob(blob: Blob, filename = 'file', document: Document | undefined = globalThis.document): void {\n const view = document?.defaultView;\n if (!document || !view) {\n return;\n }\n const url = view.URL.createObjectURL(blob);\n downloadFile(url, filename, document);\n view.setTimeout(() => view.URL.revokeObjectURL(url));\n}\n\nexport function downloadFile(url: string, filename?: string, document: Document | undefined = globalThis.document): void {\n if (!document?.body) {\n return;\n }\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.download = filename ?? url.split(/[?#]/)[0].split('/').pop() ?? 'file';\n anchor.rel = 'noopener';\n anchor.style.display = 'none';\n document.body.appendChild(anchor);\n anchor.click();\n document.body.removeChild(anchor);\n}\n\n@Pipe({ name: 'txFileSize', pure: false })\nexport class TxFileSizePipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n\n transform(bytes: number | null | undefined, options: TxFileSizeOptions = {}): string {\n return formatFileSize(bytes, { ...options, locale: options.locale ?? this.localeService.locale().intl });\n }\n}\n"],"mappings":";;;AAUA,MAAM,QAAQ;CAAC;CAAK;CAAM;CAAM;CAAM;CAAM;AAAI;AAEhD,SAAgB,eAAe,OAAkC,UAA6B,CAAA,GAAE;CAC9F,MAAM,EAAE,WAAW,GAAG,OAAO,MAAM,SAAS,SAAS,QAA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