@servicetitan/form 22.3.0 → 22.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/dist/date-range-picker/date-range-picker.d.ts +1 -1
- package/dist/date-range-picker/date-range-picker.d.ts.map +1 -1
- package/dist/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/demo/date-range-picker.js.map +1 -1
- package/dist/demo/index.d.ts +0 -1
- package/dist/demo/index.d.ts.map +1 -1
- package/dist/demo/index.js +0 -1
- package/dist/demo/index.js.map +1 -1
- package/dist/demo/input-date-mask.d.ts.map +1 -1
- package/dist/demo/input-date-mask.js.map +1 -1
- package/dist/form-state-error-banner/form-state-error-banner.js +1 -1
- package/dist/form-state-error-banner/form-state-error-banner.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +14 -15
- package/src/date-range-picker/date-range-picker.tsx +1 -1
- package/src/demo/date-range-picker.tsx +1 -1
- package/src/demo/index.ts +0 -1
- package/src/demo/input-date-mask.tsx +0 -1
- package/src/form-state-error-banner/form-state-error-banner.tsx +1 -1
- package/src/index.ts +2 -4
- package/dist/date-range.d.ts +0 -5
- package/dist/date-range.d.ts.map +0 -1
- package/dist/date-range.js +0 -2
- package/dist/date-range.js.map +0 -1
- package/dist/demo/dropdown-state.d.ts +0 -3
- package/dist/demo/dropdown-state.d.ts.map +0 -1
- package/dist/demo/dropdown-state.js +0 -133
- package/dist/demo/dropdown-state.js.map +0 -1
- package/dist/dropdown-state.d.ts +0 -42
- package/dist/dropdown-state.d.ts.map +0 -1
- package/dist/dropdown-state.js +0 -314
- package/dist/dropdown-state.js.map +0 -1
- package/dist/form-helpers.d.ts +0 -70
- package/dist/form-helpers.d.ts.map +0 -1
- package/dist/form-helpers.js +0 -232
- package/dist/form-helpers.js.map +0 -1
- package/dist/form-validators.d.ts +0 -30
- package/dist/form-validators.d.ts.map +0 -1
- package/dist/form-validators.js +0 -56
- package/dist/form-validators.js.map +0 -1
- package/dist/persistent-form-state/domain-storage.d.ts +0 -14
- package/dist/persistent-form-state/domain-storage.d.ts.map +0 -1
- package/dist/persistent-form-state/domain-storage.js +0 -42
- package/dist/persistent-form-state/domain-storage.js.map +0 -1
- package/dist/persistent-form-state/in-memory-storage.d.ts +0 -13
- package/dist/persistent-form-state/in-memory-storage.d.ts.map +0 -1
- package/dist/persistent-form-state/in-memory-storage.js +0 -30
- package/dist/persistent-form-state/in-memory-storage.js.map +0 -1
- package/dist/persistent-form-state/index.d.ts +0 -2
- package/dist/persistent-form-state/index.d.ts.map +0 -1
- package/dist/persistent-form-state/index.js +0 -2
- package/dist/persistent-form-state/index.js.map +0 -1
- package/dist/persistent-form-state/persistent-form-state.d.ts +0 -18
- package/dist/persistent-form-state/persistent-form-state.d.ts.map +0 -1
- package/dist/persistent-form-state/persistent-form-state.js +0 -93
- package/dist/persistent-form-state/persistent-form-state.js.map +0 -1
- package/src/__tests__/__snapshots__/form-helpers.test.ts.snap +0 -37
- package/src/__tests__/form-helpers.test.ts +0 -229
- package/src/__tests__/form-validators.test.ts +0 -55
- package/src/date-range.ts +0 -4
- package/src/demo/dropdown-state.tsx +0 -233
- package/src/dropdown-state.ts +0 -205
- package/src/form-helpers.ts +0 -259
- package/src/form-validators.ts +0 -106
- package/src/persistent-form-state/__tests__/domain-storage.test.ts +0 -81
- package/src/persistent-form-state/domain-storage.ts +0 -43
- package/src/persistent-form-state/in-memory-storage.ts +0 -32
- package/src/persistent-form-state/index.ts +0 -1
- package/src/persistent-form-state/persistent-form-state.ts +0 -68
package/dist/dropdown-state.js
DELETED
@@ -1,314 +0,0 @@
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
-
};
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
-
};
|
10
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
11
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
12
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
13
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
16
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17
|
-
});
|
18
|
-
};
|
19
|
-
import { observable, computed, action, runInAction, makeObservable } from 'mobx';
|
20
|
-
import debounce from 'debounce';
|
21
|
-
function isGroupItem(item, groupedBy) {
|
22
|
-
const { items, field } = item;
|
23
|
-
return !!items && field === groupedBy;
|
24
|
-
}
|
25
|
-
export class DropdownState {
|
26
|
-
constructor({ dataSource, searchByGroup, state, lazy, } = {}) {
|
27
|
-
var _a, _b, _c;
|
28
|
-
Object.defineProperty(this, "loading", {
|
29
|
-
enumerable: true,
|
30
|
-
configurable: true,
|
31
|
-
writable: true,
|
32
|
-
value: false
|
33
|
-
});
|
34
|
-
Object.defineProperty(this, "search", {
|
35
|
-
enumerable: true,
|
36
|
-
configurable: true,
|
37
|
-
writable: true,
|
38
|
-
value: ''
|
39
|
-
});
|
40
|
-
Object.defineProperty(this, "dataSource", {
|
41
|
-
enumerable: true,
|
42
|
-
configurable: true,
|
43
|
-
writable: true,
|
44
|
-
value: void 0
|
45
|
-
});
|
46
|
-
Object.defineProperty(this, "searchByGroup", {
|
47
|
-
enumerable: true,
|
48
|
-
configurable: true,
|
49
|
-
writable: true,
|
50
|
-
value: void 0
|
51
|
-
});
|
52
|
-
Object.defineProperty(this, "sort", {
|
53
|
-
enumerable: true,
|
54
|
-
configurable: true,
|
55
|
-
writable: true,
|
56
|
-
value: void 0
|
57
|
-
});
|
58
|
-
Object.defineProperty(this, "filter", {
|
59
|
-
enumerable: true,
|
60
|
-
configurable: true,
|
61
|
-
writable: true,
|
62
|
-
value: void 0
|
63
|
-
});
|
64
|
-
Object.defineProperty(this, "group", {
|
65
|
-
enumerable: true,
|
66
|
-
configurable: true,
|
67
|
-
writable: true,
|
68
|
-
value: void 0
|
69
|
-
});
|
70
|
-
Object.defineProperty(this, "data", {
|
71
|
-
enumerable: true,
|
72
|
-
configurable: true,
|
73
|
-
writable: true,
|
74
|
-
value: []
|
75
|
-
});
|
76
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
77
|
-
Object.defineProperty(this, "onSearchChange", {
|
78
|
-
enumerable: true,
|
79
|
-
configurable: true,
|
80
|
-
writable: true,
|
81
|
-
value: (() => {
|
82
|
-
const fetch = debounce(() => this.fetch(), 100);
|
83
|
-
return (_0, data) => {
|
84
|
-
runInAction(() => {
|
85
|
-
this.search = data.value;
|
86
|
-
});
|
87
|
-
fetch();
|
88
|
-
};
|
89
|
-
})()
|
90
|
-
});
|
91
|
-
Object.defineProperty(this, "setSearch", {
|
92
|
-
enumerable: true,
|
93
|
-
configurable: true,
|
94
|
-
writable: true,
|
95
|
-
value: (search) => __awaiter(this, void 0, void 0, function* () {
|
96
|
-
this.search = search;
|
97
|
-
yield this.fetch();
|
98
|
-
})
|
99
|
-
});
|
100
|
-
Object.defineProperty(this, "setDataSource", {
|
101
|
-
enumerable: true,
|
102
|
-
configurable: true,
|
103
|
-
writable: true,
|
104
|
-
value: (dataSource) => __awaiter(this, void 0, void 0, function* () {
|
105
|
-
this.dataSource = dataSource;
|
106
|
-
yield this.fetch();
|
107
|
-
})
|
108
|
-
});
|
109
|
-
Object.defineProperty(this, "setSearchByGroup", {
|
110
|
-
enumerable: true,
|
111
|
-
configurable: true,
|
112
|
-
writable: true,
|
113
|
-
value: (searchByGroup) => __awaiter(this, void 0, void 0, function* () {
|
114
|
-
this.searchByGroup = searchByGroup;
|
115
|
-
yield this.fetch();
|
116
|
-
})
|
117
|
-
});
|
118
|
-
Object.defineProperty(this, "setSort", {
|
119
|
-
enumerable: true,
|
120
|
-
configurable: true,
|
121
|
-
writable: true,
|
122
|
-
value: (sort) => __awaiter(this, void 0, void 0, function* () {
|
123
|
-
this.sort = sort;
|
124
|
-
yield this.fetch();
|
125
|
-
})
|
126
|
-
});
|
127
|
-
Object.defineProperty(this, "setFilter", {
|
128
|
-
enumerable: true,
|
129
|
-
configurable: true,
|
130
|
-
writable: true,
|
131
|
-
value: (filter) => __awaiter(this, void 0, void 0, function* () {
|
132
|
-
this.filter = filter;
|
133
|
-
yield this.fetch();
|
134
|
-
})
|
135
|
-
});
|
136
|
-
Object.defineProperty(this, "setGroup", {
|
137
|
-
enumerable: true,
|
138
|
-
configurable: true,
|
139
|
-
writable: true,
|
140
|
-
value: (group) => __awaiter(this, void 0, void 0, function* () {
|
141
|
-
this.group = group;
|
142
|
-
yield this.fetch();
|
143
|
-
})
|
144
|
-
});
|
145
|
-
Object.defineProperty(this, "fetch", {
|
146
|
-
enumerable: true,
|
147
|
-
configurable: true,
|
148
|
-
writable: true,
|
149
|
-
value: () => __awaiter(this, void 0, void 0, function* () {
|
150
|
-
var _d;
|
151
|
-
this.loading = true;
|
152
|
-
const response = yield ((_d = this.dataSource) === null || _d === void 0 ? void 0 : _d.getData(this.state));
|
153
|
-
runInAction(() => {
|
154
|
-
var _a;
|
155
|
-
this.data = (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : [];
|
156
|
-
this.loading = false;
|
157
|
-
});
|
158
|
-
})
|
159
|
-
});
|
160
|
-
Object.defineProperty(this, "traverse", {
|
161
|
-
enumerable: true,
|
162
|
-
configurable: true,
|
163
|
-
writable: true,
|
164
|
-
value: (items, itemCallback, groupedBy) => {
|
165
|
-
if (!items) {
|
166
|
-
return;
|
167
|
-
}
|
168
|
-
for (const item of items) {
|
169
|
-
if (isGroupItem(item, groupedBy)) {
|
170
|
-
this.traverse(item.items, itemCallback, groupedBy);
|
171
|
-
}
|
172
|
-
else {
|
173
|
-
itemCallback(item);
|
174
|
-
}
|
175
|
-
}
|
176
|
-
}
|
177
|
-
});
|
178
|
-
makeObservable(this);
|
179
|
-
this.dataSource = dataSource !== null && dataSource !== void 0 ? dataSource : null;
|
180
|
-
this.searchByGroup = searchByGroup !== null && searchByGroup !== void 0 ? searchByGroup : false;
|
181
|
-
this.sort = (_a = state === null || state === void 0 ? void 0 : state.sort) !== null && _a !== void 0 ? _a : [{ field: 'text' }];
|
182
|
-
this.filter = (_b = state === null || state === void 0 ? void 0 : state.filter) !== null && _b !== void 0 ? _b : null;
|
183
|
-
this.group = (_c = state === null || state === void 0 ? void 0 : state.group) !== null && _c !== void 0 ? _c : [{ field: 'group' }];
|
184
|
-
if (!lazy) {
|
185
|
-
this.fetch();
|
186
|
-
}
|
187
|
-
}
|
188
|
-
get options() {
|
189
|
-
const result = new Map();
|
190
|
-
const flat = [];
|
191
|
-
const groupField = this.group[0].field;
|
192
|
-
this.traverse(this.data, item => {
|
193
|
-
var _a, _b;
|
194
|
-
const group = item[groupField];
|
195
|
-
if (group) {
|
196
|
-
if (result.has(group)) {
|
197
|
-
(_b = (_a = result.get(group)) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.push(item);
|
198
|
-
}
|
199
|
-
else {
|
200
|
-
result.set(group, {
|
201
|
-
value: group,
|
202
|
-
text: String(group),
|
203
|
-
options: [item],
|
204
|
-
});
|
205
|
-
}
|
206
|
-
}
|
207
|
-
else {
|
208
|
-
flat.push(item);
|
209
|
-
}
|
210
|
-
}, groupField);
|
211
|
-
return [...flat, ...Array.from(result.values())];
|
212
|
-
}
|
213
|
-
get state() {
|
214
|
-
var _a;
|
215
|
-
return {
|
216
|
-
sort: this.sort,
|
217
|
-
filter: this.searchFilter || this.filter
|
218
|
-
? this.searchFilter && this.filter
|
219
|
-
? { logic: 'and', filters: [this.searchFilter, this.filter] }
|
220
|
-
: (_a = this.searchFilter) !== null && _a !== void 0 ? _a : this.filter
|
221
|
-
: undefined,
|
222
|
-
group: this.group,
|
223
|
-
};
|
224
|
-
}
|
225
|
-
get searchFilter() {
|
226
|
-
if (!this.search) {
|
227
|
-
return undefined;
|
228
|
-
}
|
229
|
-
const filter = { operator: 'contains', value: this.search, ignoreCase: true };
|
230
|
-
return {
|
231
|
-
logic: 'or',
|
232
|
-
filters: [
|
233
|
-
Object.assign(Object.assign({}, filter), { field: 'text' }),
|
234
|
-
...(this.searchByGroup ? [Object.assign(Object.assign({}, filter), { field: 'group' })] : []),
|
235
|
-
],
|
236
|
-
};
|
237
|
-
}
|
238
|
-
}
|
239
|
-
__decorate([
|
240
|
-
observable,
|
241
|
-
__metadata("design:type", Object)
|
242
|
-
], DropdownState.prototype, "loading", void 0);
|
243
|
-
__decorate([
|
244
|
-
observable,
|
245
|
-
__metadata("design:type", Object)
|
246
|
-
], DropdownState.prototype, "search", void 0);
|
247
|
-
__decorate([
|
248
|
-
computed,
|
249
|
-
__metadata("design:type", Object),
|
250
|
-
__metadata("design:paramtypes", [])
|
251
|
-
], DropdownState.prototype, "options", null);
|
252
|
-
__decorate([
|
253
|
-
computed,
|
254
|
-
__metadata("design:type", Object),
|
255
|
-
__metadata("design:paramtypes", [])
|
256
|
-
], DropdownState.prototype, "state", null);
|
257
|
-
__decorate([
|
258
|
-
computed,
|
259
|
-
__metadata("design:type", Object),
|
260
|
-
__metadata("design:paramtypes", [])
|
261
|
-
], DropdownState.prototype, "searchFilter", null);
|
262
|
-
__decorate([
|
263
|
-
observable,
|
264
|
-
__metadata("design:type", Object)
|
265
|
-
], DropdownState.prototype, "dataSource", void 0);
|
266
|
-
__decorate([
|
267
|
-
observable,
|
268
|
-
__metadata("design:type", Boolean)
|
269
|
-
], DropdownState.prototype, "searchByGroup", void 0);
|
270
|
-
__decorate([
|
271
|
-
observable,
|
272
|
-
__metadata("design:type", Array)
|
273
|
-
], DropdownState.prototype, "sort", void 0);
|
274
|
-
__decorate([
|
275
|
-
observable,
|
276
|
-
__metadata("design:type", Object)
|
277
|
-
], DropdownState.prototype, "filter", void 0);
|
278
|
-
__decorate([
|
279
|
-
observable,
|
280
|
-
__metadata("design:type", Array)
|
281
|
-
], DropdownState.prototype, "group", void 0);
|
282
|
-
__decorate([
|
283
|
-
observable,
|
284
|
-
__metadata("design:type", Array)
|
285
|
-
], DropdownState.prototype, "data", void 0);
|
286
|
-
__decorate([
|
287
|
-
action,
|
288
|
-
__metadata("design:type", Object)
|
289
|
-
], DropdownState.prototype, "setSearch", void 0);
|
290
|
-
__decorate([
|
291
|
-
action,
|
292
|
-
__metadata("design:type", Object)
|
293
|
-
], DropdownState.prototype, "setDataSource", void 0);
|
294
|
-
__decorate([
|
295
|
-
action,
|
296
|
-
__metadata("design:type", Object)
|
297
|
-
], DropdownState.prototype, "setSearchByGroup", void 0);
|
298
|
-
__decorate([
|
299
|
-
action,
|
300
|
-
__metadata("design:type", Object)
|
301
|
-
], DropdownState.prototype, "setSort", void 0);
|
302
|
-
__decorate([
|
303
|
-
action,
|
304
|
-
__metadata("design:type", Object)
|
305
|
-
], DropdownState.prototype, "setFilter", void 0);
|
306
|
-
__decorate([
|
307
|
-
action,
|
308
|
-
__metadata("design:type", Object)
|
309
|
-
], DropdownState.prototype, "setGroup", void 0);
|
310
|
-
__decorate([
|
311
|
-
action,
|
312
|
-
__metadata("design:type", Object)
|
313
|
-
], DropdownState.prototype, "fetch", void 0);
|
314
|
-
//# sourceMappingURL=dropdown-state.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"dropdown-state.js","sourceRoot":"","sources":["../src/dropd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EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAE9E,OAAO;YACH,KAAK,EAAE,IAAI;YACX,OAAO,EAAE;gDACA,MAAM,KAAE,KAAK,EAAE,MAAM;gBAC1B,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,iCAAM,MAAM,KAAE,KAAK,EAAE,OAAO,IAAG,CAAC,CAAC,CAAC,EAAE,CAAC;aACjE;SACyB,CAAC;IACnC,CAAC;CAyGJ;AAtKe;IAAX,UAAU;;8CAAiB;AAChB;IAAX,UAAU;;6CAAa;AAEd;IAAT,QAAQ;;;4CA6BR;AAES;IAAT,QAAQ;;;0CAWR;AAES;IAAT,QAAQ;;;iDAcR;AAEW;IAAX,UAAU;;iDAA0C;AACzC;IAAX,UAAU;;oDAAgC;AAC/B;IAAX,UAAU;;2CAAgC;AAC/B;IAAX,UAAU;;6CAAkD;AACjD;IAAX,UAAU;;4CAAkC;AAEjC;IAAX,UAAU;;2CAA2C;AAiCtD;IADC,MAAM;;gDAIL;AAGF;IADC,MAAM;;oDAIL;AAGF;IADC,MAAM;;uDAIL;AAGF;IADC,MAAM;;8CAIL;AAGF;IADC,MAAM;;gDAIL;AAGF;IADC,MAAM;;+CAIL;AAGF;IADC,MAAM;;4CAUL"}
|
package/dist/form-helpers.d.ts
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
import { SyntheticEvent, ChangeEvent, Key, ReactNode } from 'react';
|
2
|
-
import { FieldState, FormState, ValidatableMapOrArray } from 'formstate';
|
3
|
-
export declare class CheckboxFieldState extends FieldState<boolean> {
|
4
|
-
onChangeHandler: (_0: any, checked: boolean) => void;
|
5
|
-
DEPRECATED_onChangeHandler: (_0: SyntheticEvent<HTMLInputElement>, data: {
|
6
|
-
checked?: boolean;
|
7
|
-
}) => void;
|
8
|
-
}
|
9
|
-
export declare class InputFieldState<T> extends FieldState<T> {
|
10
|
-
onChangeHandler: (_0: SyntheticEvent<HTMLInputElement>, data: {
|
11
|
-
value: T;
|
12
|
-
}) => void;
|
13
|
-
onChangeNativeHandler: (event: ChangeEvent<HTMLInputElement>) => void;
|
14
|
-
}
|
15
|
-
export declare class TextAreaFieldState<T> extends FieldState<T> {
|
16
|
-
/**
|
17
|
-
* react-semantic type for onChange event of TextArea component seems to have a bug with data object type
|
18
|
-
* so declaring data as any
|
19
|
-
*/
|
20
|
-
onChangeHandler: (_0: SyntheticEvent<HTMLTextAreaElement>, data: any) => void;
|
21
|
-
}
|
22
|
-
export declare class DropdownFieldState<T> extends FieldState<T> {
|
23
|
-
/**
|
24
|
-
* react-semantic type for onChange event of Dropdown component seems to have a bug with data object type
|
25
|
-
* so declaring data as any
|
26
|
-
*/
|
27
|
-
onChangeHandler: (_0: SyntheticEvent<HTMLElement>, data: any) => void;
|
28
|
-
}
|
29
|
-
export declare class DropdownSearchFieldState<T> extends FieldState<T> {
|
30
|
-
onChangeHandler: (_0: SyntheticEvent<HTMLElement>, data: {
|
31
|
-
searchQuery: T;
|
32
|
-
}) => void;
|
33
|
-
}
|
34
|
-
export declare class DatetimeFieldState extends FieldState<Date | null> {
|
35
|
-
onChangeHandler: (event: {
|
36
|
-
target: {
|
37
|
-
value: Date | null;
|
38
|
-
};
|
39
|
-
}) => void;
|
40
|
-
}
|
41
|
-
export interface Option<T> {
|
42
|
-
key: Key;
|
43
|
-
text: ReactNode;
|
44
|
-
value: T;
|
45
|
-
}
|
46
|
-
export declare function enumToOptions<T>(enumObject: T, nameProvider?: (value: T[keyof T]) => Option<T[keyof T]>['text']): Option<T[keyof T]>[];
|
47
|
-
export declare function getEnumKeys<T>(enumObject: T): (keyof T)[];
|
48
|
-
export declare function getEnumValues<T>(enumObject: T): T[keyof T][];
|
49
|
-
export declare type FormValues = string | number | boolean | (string | number | boolean)[];
|
50
|
-
export interface FormStateAsJS {
|
51
|
-
[index: string]: FormValues | Map<any, any> | Set<any> | FormStateAsJS;
|
52
|
-
}
|
53
|
-
export declare function traverseFormState<T extends ValidatableMapOrArray>(recursive: boolean, formState: FormState<T>, onFormVisit?: (key: string, form: FormState<any>) => void, onFieldVisit?: (key: string, field: FieldState<any>) => void): void;
|
54
|
-
export declare function BAD_formStateToJS<T extends ValidatableMapOrArray>(formState: FormState<T>): FormStateAsJS;
|
55
|
-
export declare type FormStateShape<T> = T extends FormState<infer U>[] ? FormStateMapOrObject<U>[] : FormStateMapOrObject<T>;
|
56
|
-
declare type FormStateMapOrObject<T> = T extends Map<infer K, infer V> ? FormStateObject<Record<K & (string | number | symbol), V>> : FormStateObject<T>;
|
57
|
-
declare type FormStateObject<T> = {
|
58
|
-
[P in keyof T]: T[P] extends FieldState<infer U> ? U : T[P] extends FormState<infer U> ? FormStateShape<U> : never;
|
59
|
-
};
|
60
|
-
export declare function formStateToJS<T extends ValidatableMapOrArray>(formState: FormState<T>): FormStateShape<T>;
|
61
|
-
export declare type RecursivePartial<T> = T extends (infer U)[] ? RecursivePartialObject<U>[] : RecursivePartialObject<T>;
|
62
|
-
declare type RecursivePartialObject<T> = {
|
63
|
-
[P in keyof T]?: T[P] extends Record<any, any> ? RecursivePartial<T[P]> : T[P];
|
64
|
-
};
|
65
|
-
export declare function setFormStateValues<T extends ValidatableMapOrArray>(formState: FormState<T>, data: RecursivePartial<FormStateShape<T>>, triggerValidation?: boolean): FormState<T>;
|
66
|
-
export declare function commitFormState<T extends ValidatableMapOrArray>(formState: FormState<T>): void;
|
67
|
-
export declare function camelCaseToTitleCase(value: string): string;
|
68
|
-
export declare function isFormStateChanged<T extends ValidatableMapOrArray>(formState: FormState<T>): import("mobx").IComputedValue<boolean>;
|
69
|
-
export {};
|
70
|
-
//# sourceMappingURL=form-helpers.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"form-helpers.d.ts","sourceRoot":"","sources":["../src/form-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC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C,CAAC,EACzC,iBAAiB,UAAQ,GAC1B,SAAS,CAAC,CAAC,CAAC,CAoDd;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,QAKvF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,UAGjD;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,0CAgB1F"}
|
package/dist/form-helpers.js
DELETED
@@ -1,232 +0,0 @@
|
|
1
|
-
import { FieldState, FormState } from 'formstate';
|
2
|
-
import { toJS, isObservableMap, runInAction, transaction, computed, comparer } from 'mobx';
|
3
|
-
export class CheckboxFieldState extends FieldState {
|
4
|
-
constructor() {
|
5
|
-
super(...arguments);
|
6
|
-
Object.defineProperty(this, "onChangeHandler", {
|
7
|
-
enumerable: true,
|
8
|
-
configurable: true,
|
9
|
-
writable: true,
|
10
|
-
value: (_0, checked) => {
|
11
|
-
this.onChange(checked);
|
12
|
-
}
|
13
|
-
});
|
14
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
15
|
-
Object.defineProperty(this, "DEPRECATED_onChangeHandler", {
|
16
|
-
enumerable: true,
|
17
|
-
configurable: true,
|
18
|
-
writable: true,
|
19
|
-
value: (_0, data) => {
|
20
|
-
this.onChange(!!data.checked);
|
21
|
-
}
|
22
|
-
});
|
23
|
-
}
|
24
|
-
}
|
25
|
-
export class InputFieldState extends FieldState {
|
26
|
-
constructor() {
|
27
|
-
super(...arguments);
|
28
|
-
Object.defineProperty(this, "onChangeHandler", {
|
29
|
-
enumerable: true,
|
30
|
-
configurable: true,
|
31
|
-
writable: true,
|
32
|
-
value: (_0, data) => {
|
33
|
-
this.onChange(data.value);
|
34
|
-
}
|
35
|
-
});
|
36
|
-
Object.defineProperty(this, "onChangeNativeHandler", {
|
37
|
-
enumerable: true,
|
38
|
-
configurable: true,
|
39
|
-
writable: true,
|
40
|
-
value: (event) => {
|
41
|
-
this.onChange(event.currentTarget.value);
|
42
|
-
}
|
43
|
-
});
|
44
|
-
}
|
45
|
-
}
|
46
|
-
export class TextAreaFieldState extends FieldState {
|
47
|
-
constructor() {
|
48
|
-
super(...arguments);
|
49
|
-
/**
|
50
|
-
* react-semantic type for onChange event of TextArea component seems to have a bug with data object type
|
51
|
-
* so declaring data as any
|
52
|
-
*/
|
53
|
-
Object.defineProperty(this, "onChangeHandler", {
|
54
|
-
enumerable: true,
|
55
|
-
configurable: true,
|
56
|
-
writable: true,
|
57
|
-
value: (_0, data) => {
|
58
|
-
this.onChange(data.value);
|
59
|
-
}
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
export class DropdownFieldState extends FieldState {
|
64
|
-
constructor() {
|
65
|
-
super(...arguments);
|
66
|
-
/**
|
67
|
-
* react-semantic type for onChange event of Dropdown component seems to have a bug with data object type
|
68
|
-
* so declaring data as any
|
69
|
-
*/
|
70
|
-
Object.defineProperty(this, "onChangeHandler", {
|
71
|
-
enumerable: true,
|
72
|
-
configurable: true,
|
73
|
-
writable: true,
|
74
|
-
value: (_0, data) => {
|
75
|
-
this.onChange(data.value);
|
76
|
-
}
|
77
|
-
});
|
78
|
-
}
|
79
|
-
}
|
80
|
-
export class DropdownSearchFieldState extends FieldState {
|
81
|
-
constructor() {
|
82
|
-
super(...arguments);
|
83
|
-
Object.defineProperty(this, "onChangeHandler", {
|
84
|
-
enumerable: true,
|
85
|
-
configurable: true,
|
86
|
-
writable: true,
|
87
|
-
value: (_0, data) => {
|
88
|
-
this.onChange(data.searchQuery);
|
89
|
-
}
|
90
|
-
});
|
91
|
-
}
|
92
|
-
}
|
93
|
-
export class DatetimeFieldState extends FieldState {
|
94
|
-
constructor() {
|
95
|
-
super(...arguments);
|
96
|
-
Object.defineProperty(this, "onChangeHandler", {
|
97
|
-
enumerable: true,
|
98
|
-
configurable: true,
|
99
|
-
writable: true,
|
100
|
-
value: (event) => {
|
101
|
-
this.onChange(event.target.value);
|
102
|
-
}
|
103
|
-
});
|
104
|
-
}
|
105
|
-
}
|
106
|
-
export function enumToOptions(enumObject, nameProvider) {
|
107
|
-
return getEnumKeys(enumObject).map(k => ({
|
108
|
-
key: k,
|
109
|
-
text: nameProvider ? nameProvider(enumObject[k]) : k,
|
110
|
-
value: enumObject[k],
|
111
|
-
}));
|
112
|
-
}
|
113
|
-
export function getEnumKeys(enumObject) {
|
114
|
-
let keys = Object.keys(enumObject);
|
115
|
-
if (keys.some(k => typeof enumObject[k] === 'number')) {
|
116
|
-
keys = keys.filter(k => typeof enumObject[k] === 'number');
|
117
|
-
}
|
118
|
-
return keys;
|
119
|
-
}
|
120
|
-
export function getEnumValues(enumObject) {
|
121
|
-
return getEnumKeys(enumObject).map(k => enumObject[k]);
|
122
|
-
}
|
123
|
-
export function traverseFormState(recursive, formState, onFormVisit, onFieldVisit) {
|
124
|
-
const visitChild = (key, child) => {
|
125
|
-
if (child instanceof FormState) {
|
126
|
-
if (recursive) {
|
127
|
-
traverseFormState(recursive, child, onFormVisit, onFieldVisit);
|
128
|
-
}
|
129
|
-
if (onFormVisit) {
|
130
|
-
onFormVisit(key, child);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
else if (onFieldVisit) {
|
134
|
-
onFieldVisit(key, child);
|
135
|
-
}
|
136
|
-
};
|
137
|
-
if (Array.isArray(formState.$)) {
|
138
|
-
formState.$.forEach((child, index) => visitChild(index.toString(), child));
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
(isObservableMap(formState.$)
|
142
|
-
? Array.from(formState.$)
|
143
|
-
: Object.entries(formState.$)).forEach(([key, child]) => visitChild(key, child));
|
144
|
-
}
|
145
|
-
}
|
146
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
147
|
-
export function BAD_formStateToJS(formState) {
|
148
|
-
const formValues = {};
|
149
|
-
traverseFormState(false, formState, (key, form) => (formValues[key] = BAD_formStateToJS(form)), (key, field) => (formValues[key] = toJS(field.value)));
|
150
|
-
return formValues;
|
151
|
-
}
|
152
|
-
export function formStateToJS(formState) {
|
153
|
-
const formValues = Array.isArray(formState.$) ? [] : {};
|
154
|
-
traverseFormState(false, formState, (key, form) => (formValues[key] = formStateToJS(form)), (key, field) => (formValues[key] = toJS(field.$)));
|
155
|
-
return formValues;
|
156
|
-
}
|
157
|
-
export function setFormStateValues(formState, data, triggerValidation = false) {
|
158
|
-
if (Array.isArray(formState.$) && data.length !== formState.$.length) {
|
159
|
-
throw new Error('Number of elements in data object node is different from number of element in form.' +
|
160
|
-
' All array nodes should match in size before values can be applied to form.');
|
161
|
-
}
|
162
|
-
transaction(() => {
|
163
|
-
traverseFormState(false, formState, (key, form) => {
|
164
|
-
if (data instanceof Map || isObservableMap(data)) {
|
165
|
-
if (data.has(key)) {
|
166
|
-
setFormStateValues(form, data.get(key));
|
167
|
-
}
|
168
|
-
}
|
169
|
-
else {
|
170
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
171
|
-
setFormStateValues(form, data[key]);
|
172
|
-
}
|
173
|
-
}
|
174
|
-
}, (key, field) => {
|
175
|
-
if (data instanceof Map || isObservableMap(data)) {
|
176
|
-
if (data.has(key)) {
|
177
|
-
runInAction(() => {
|
178
|
-
field.value = data.get(key);
|
179
|
-
field.$ = data.get(key);
|
180
|
-
});
|
181
|
-
}
|
182
|
-
}
|
183
|
-
else {
|
184
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
185
|
-
runInAction(() => {
|
186
|
-
field.value = data[key];
|
187
|
-
field.$ = data[key];
|
188
|
-
});
|
189
|
-
}
|
190
|
-
}
|
191
|
-
});
|
192
|
-
if (triggerValidation) {
|
193
|
-
const setValidatedSubFields = (form) => {
|
194
|
-
form.validatedSubFields = form.getValues();
|
195
|
-
};
|
196
|
-
traverseFormState(true, formState, (_0, form) => {
|
197
|
-
setValidatedSubFields(form);
|
198
|
-
});
|
199
|
-
setValidatedSubFields(formState);
|
200
|
-
formState.validate();
|
201
|
-
}
|
202
|
-
});
|
203
|
-
return formState;
|
204
|
-
}
|
205
|
-
export function commitFormState(formState) {
|
206
|
-
traverseFormState(true, formState, undefined, (_0, field) => {
|
207
|
-
field.dirty = false;
|
208
|
-
field._initValue = field.value;
|
209
|
-
});
|
210
|
-
}
|
211
|
-
export function camelCaseToTitleCase(value) {
|
212
|
-
const regexp = /[A-Z](?=[A-Z][a-z])|[^A-Z](?=[A-Z])|[A-Za-z](?=[^A-Za-z])/g;
|
213
|
-
return value.replace(regexp, '$& ');
|
214
|
-
}
|
215
|
-
export function isFormStateChanged(formState) {
|
216
|
-
return computed(() => {
|
217
|
-
let isChanged = false;
|
218
|
-
traverseFormState(true, formState, undefined, (_0, field) => {
|
219
|
-
const isValueChanged = () => {
|
220
|
-
if (field instanceof InputFieldState) {
|
221
|
-
if (field._initValue === undefined && field.value === '') {
|
222
|
-
return false;
|
223
|
-
}
|
224
|
-
}
|
225
|
-
return !comparer.structural(field._initValue, field.value);
|
226
|
-
};
|
227
|
-
isChanged = isChanged || (field.dirty === true && isValueChanged());
|
228
|
-
});
|
229
|
-
return isChanged;
|
230
|
-
});
|
231
|
-
}
|
232
|
-
//# sourceMappingURL=form-helpers.js.map
|
package/dist/form-helpers.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"form-helpers.js","sourceRoot":"","sources":["../src/form-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgD,MAAM,WAAW,CAAC;AAChG,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAE3F,MAAM,OAAO,kBAAmB,SAAQ,UAAmB;IAA3D;;QACI;;;;mBAAkB,CAAC,EAAO,EAAE,OAAgB,EAAE,EAAE;gBAC5C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;WAAC;QACF,gEAAgE;QAChE;;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