@daracl/form 0.0.12 → 0.0.13

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.
Files changed (49) hide show
  1. package/dist/daracl.form.js +2 -2
  2. package/dist/daracl.form.min.js +2 -2
  3. package/dist/daracl.form.min.js.LICENSE.txt +1 -1
  4. package/dist/daracl.vender.min.js +1 -1
  5. package/dist/main.css +1 -1
  6. package/package.json +3 -5
  7. package/src/DaraForm.ts +0 -431
  8. package/src/FieldInfoMap.ts +0 -356
  9. package/src/FormTemplate.ts +0 -207
  10. package/src/constants.ts +0 -100
  11. package/src/event/renderEvents.ts +0 -41
  12. package/src/index copy.html +0 -591
  13. package/src/index-grid.html +0 -655
  14. package/src/index-tab.html +0 -639
  15. package/src/index.html +0 -485
  16. package/src/indexVender.ts +0 -9
  17. package/src/renderer/ButtonRender.ts +0 -51
  18. package/src/renderer/CheckboxRender.ts +0 -214
  19. package/src/renderer/CustomRender.ts +0 -100
  20. package/src/renderer/DateRender.ts +0 -104
  21. package/src/renderer/DropdownRender.ts +0 -149
  22. package/src/renderer/FileRender.ts +0 -239
  23. package/src/renderer/GridRender.ts +0 -289
  24. package/src/renderer/GroupRender.ts +0 -47
  25. package/src/renderer/HiddenRender.ts +0 -36
  26. package/src/renderer/NumberRender.ts +0 -68
  27. package/src/renderer/PasswordRender.ts +0 -69
  28. package/src/renderer/RadioRender.ts +0 -191
  29. package/src/renderer/RangeRender.ts +0 -79
  30. package/src/renderer/Render.ts +0 -194
  31. package/src/renderer/TabRender.ts +0 -229
  32. package/src/renderer/TextAreaRender.ts +0 -72
  33. package/src/renderer/TextRender.ts +0 -68
  34. package/src/rule/fileValidator.ts +0 -26
  35. package/src/rule/numberValidator.ts +0 -96
  36. package/src/rule/regexpValidator.ts +0 -45
  37. package/src/rule/stringValidator.ts +0 -64
  38. package/src/rule/validator.ts +0 -49
  39. package/src/types/DataMap.d.ts +0 -17
  40. package/src/types/DateTimePicker.d.ts +0 -5
  41. package/src/types/FormField.d.ts +0 -129
  42. package/src/types/FormOptions.d.ts +0 -91
  43. package/src/types/Message.d.ts +0 -40
  44. package/src/types/ValidResult.d.ts +0 -9
  45. package/src/util/Lanauage.ts +0 -127
  46. package/src/util/renderFactory.ts +0 -26
  47. package/src/util/styleUtils.ts +0 -85
  48. package/src/util/utils.ts +0 -283
  49. package/src/util/validUtils.ts +0 -53
package/src/DaraForm.ts DELETED
@@ -1,431 +0,0 @@
1
- import { FormOptions } from "@t/FormOptions";
2
- import { FormField } from "@t/FormField";
3
- import * as utils from "./util/utils";
4
- import { ValidResult } from "@t/ValidResult";
5
- import { Message } from "@t/Message";
6
- import Lanauage from "./util/Lanauage";
7
- import { stringValidator } from "./rule/stringValidator";
8
- import { numberValidator } from "./rule/numberValidator";
9
- import { regexpValidator } from "./rule/regexpValidator";
10
- import FieldInfoMap from "src/FieldInfoMap";
11
- import FormTemplate from "./FormTemplate";
12
- import { FORM_MODE } from "./constants";
13
-
14
- declare const APP_VERSION: string;
15
-
16
- const defaultOptions = {
17
- style: {
18
- width: "100%",
19
- labelWidth: 3,
20
- valueWidth: 9,
21
- position: "left-right",
22
- },
23
- mode: "new",
24
- useTypeValue: true,
25
- autoCreate: true,
26
- notValidMessage: "This form is not valid.",
27
- fields: [],
28
- } as FormOptions;
29
-
30
- interface FieldMap {
31
- [key: string]: FormField;
32
- }
33
-
34
- interface DaraFormMap {
35
- [key: string]: DaraForm;
36
- }
37
-
38
- // all instance
39
- const allInstance: DaraFormMap = {};
40
-
41
- const SEQ_ATTR_KEY = "data-form-uid";
42
-
43
- let DARA_FORM_SEQ = 0;
44
- /**
45
- * DaraForm class
46
- *
47
- * @class DaraForm
48
- * @typedef {DaraForm}
49
- */
50
- export default class DaraForm {
51
- public static VERSION = `${APP_VERSION}`;
52
-
53
- private readonly options;
54
-
55
- private orginFormStyleClass;
56
-
57
- private selector: string;
58
- private formElement: Element;
59
-
60
- private fieldInfoMap: FieldInfoMap;
61
-
62
- private formValue: any = {};
63
-
64
- public formTemplate: FormTemplate;
65
-
66
- constructor(formElement: Element, options: FormOptions, message?: Message) {
67
- this.options = utils.merge({}, defaultOptions, options) as FormOptions;
68
-
69
- Lanauage.set(message);
70
-
71
- if (formElement) {
72
- this.orginFormStyleClass = formElement.className;
73
- formElement.classList.add("daracl-form");
74
-
75
- this.selector = `df_${++DARA_FORM_SEQ}`;
76
- formElement.setAttribute("name", this.selector);
77
- formElement.setAttribute(SEQ_ATTR_KEY, this.selector);
78
-
79
- if (this.options.style.width) {
80
- formElement.setAttribute("style", `width:${this.options.style.width};`);
81
- }
82
-
83
- this.formElement = formElement;
84
- this.changeMode(this.options.mode ?? "new");
85
- this.createForm(this.options.fields);
86
-
87
- if (this.options.autoCreate !== false) {
88
- allInstance[this.selector] = this;
89
- }
90
- } else {
91
- throw new Error(`${formElement} form selector not found`);
92
- }
93
- }
94
-
95
- public static create(formElement: Element, options: FormOptions, message?: Message): DaraForm {
96
- return new DaraForm(formElement, options, message);
97
- }
98
-
99
- public static setMessage(message: Message): void {
100
- Lanauage.set(message);
101
- }
102
-
103
- private createForm(fields: FormField[]) {
104
- this.fieldInfoMap = new FieldInfoMap(this.selector, this);
105
- //this.formElement.innerHTML = "";
106
- this.formTemplate = new FormTemplate(this, this.formElement, this.fieldInfoMap);
107
-
108
- if (this.options.autoCreate === false) {
109
- return;
110
- }
111
-
112
- fields.forEach((field) => {
113
- this.formTemplate.addRow(field);
114
- });
115
- this.conditionCheck();
116
-
117
- if (this.options.onMounted) {
118
- this.options.onMounted.call(this);
119
- }
120
- }
121
-
122
- /**
123
- * change mode
124
- *
125
- * @param mode form_mode default new
126
- */
127
- public changeMode = (mode: FORM_MODE): void => {
128
- this.options.mode = mode;
129
- this.formElement.setAttribute("data-df-mode", mode);
130
- };
131
-
132
- /**
133
- * 폼 데이터 reset
134
- */
135
- public resetForm = () => {
136
- const fieldMap = this.fieldInfoMap.getAllFieldInfo();
137
- for (const seq in fieldMap) {
138
- const fieldInfo = fieldMap[seq];
139
- const renderInfo = fieldInfo.$instance;
140
-
141
- if (renderInfo && typeof renderInfo.reset === "function") {
142
- renderInfo.reset();
143
- }
144
- }
145
- this.formValue = {};
146
- this.conditionCheck();
147
- };
148
-
149
- /**
150
- * field 값 reset
151
- * @param fieldName 필드명
152
- */
153
- public resetField = (fieldName: string) => {
154
- this.fieldInfoMap.getFieldName(fieldName).$instance.reset();
155
- this.formValue[fieldName] = "";
156
- this.conditionCheck();
157
- };
158
-
159
- /**
160
- * 필드 element 얻기
161
- *
162
- * @param {string} fieldName
163
- * @returns {*}
164
- */
165
- public getFieldElement(fieldName: string) {
166
- const field = this.fieldInfoMap.getFieldName(fieldName);
167
-
168
- if (field?.$instance) {
169
- return field.$instance.getElement();
170
- }
171
-
172
- return null;
173
- }
174
-
175
- public getField(fieldName: string): FormField {
176
- return this.fieldInfoMap.getFieldName(fieldName);
177
- }
178
-
179
- /**
180
- * field 값 얻기
181
- *
182
- * @param fieldName 필드명
183
- * @returns
184
- */
185
- public getFieldValue = (fieldName: string) => {
186
- const field = this.fieldInfoMap.getFieldName(fieldName);
187
-
188
- if (field) {
189
- return field.$instance.getValue();
190
- }
191
- return null;
192
- };
193
-
194
- /**
195
- * 폼 필드 값 얻기
196
- * @param isValid 폼 유효성 검사 여부 default:false|undefined true일경우 검사.
197
- * @returns
198
- */
199
- public getValue = (isValid: boolean): any => {
200
- return this.fieldInfoMap.getAllFieldValue(this.formValue, isValid);
201
- };
202
-
203
- public getFormDataValue = (isValid: boolean): any => {
204
- return this.fieldInfoMap.getFormDataValue(this.formValue, isValid);
205
- };
206
-
207
- /**
208
- * 폼 필드 value 셋팅
209
- * @param values
210
- */
211
- public setValue = (values: any, dataClear?: boolean | undefined) => {
212
- if (dataClear !== false) {
213
- this.resetForm();
214
- }
215
-
216
- Object.keys(values).forEach((fieldName) => {
217
- this._setFieldValue(fieldName, values[fieldName]);
218
- });
219
- this.conditionCheck();
220
- };
221
-
222
- public setFieldValue = (fieldName: string, value: any) => {
223
- this._setFieldValue(fieldName, value);
224
- this.conditionCheck();
225
- };
226
-
227
- private _setFieldValue(fieldName: string, value: any) {
228
- this.formValue[fieldName] = value;
229
- const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
230
-
231
- if (fieldInfo) {
232
- fieldInfo.$instance.setValue(value);
233
- }
234
- }
235
-
236
- public setFieldItems = (fieldName: string, values: any) => {
237
- const field = this.fieldInfoMap.getFieldName(fieldName);
238
-
239
- if (field) {
240
- return field.$instance.setValueItems(values);
241
- }
242
- };
243
-
244
- /**
245
- * field 추가
246
- *
247
- * @param {FormField} field
248
- */
249
- public addField = (field: FormField) => {
250
- this.options.fields.push(field);
251
- this.formTemplate.addRow(field);
252
- this.conditionCheck();
253
- };
254
-
255
- /**
256
- * field 제거
257
- *
258
- * @param {string} fieldName
259
- */
260
- public removeField = (fieldName: string) => {
261
- const element = this.getFieldElement(fieldName);
262
-
263
- if (element != null) {
264
- element.closest(".df-row")?.remove();
265
- }
266
-
267
- this.fieldInfoMap.removeFieldInfo(fieldName);
268
- };
269
-
270
- /**
271
- * 폼 유효성 검증 여부
272
- *
273
- * @returns {boolean}
274
- */
275
- public isValidForm = (): boolean => {
276
- const result = this.validForm();
277
-
278
- return result.length < 1;
279
- };
280
-
281
- /**
282
- * 유효성 검증 폼 검증여부 리턴
283
- *
284
- * @returns {any[]}
285
- */
286
- public validForm = (): any[] => {
287
- let validResult = [] as any;
288
- let autoFocusFlag = this.options.autoFocus !== false;
289
- let firstFlag = true;
290
-
291
- const fieldMap = this.fieldInfoMap.getAllFieldInfo();
292
- for (const fieldKey in fieldMap) {
293
- const fieldInfo = fieldMap[fieldKey];
294
-
295
- let fieldValid = this.fieldInfoMap.getFieldValidation(fieldInfo, autoFocusFlag);
296
-
297
- if (fieldValid !== true) {
298
- autoFocusFlag = false;
299
-
300
- if (utils.isGridType(fieldInfo)) {
301
- validResult = validResult.concat(fieldValid);
302
- } else {
303
- if (firstFlag) {
304
- this.validTabCheck(fieldInfo);
305
- firstFlag = false;
306
- }
307
- validResult.push(fieldValid);
308
- }
309
- }
310
- }
311
-
312
- return validResult;
313
- };
314
-
315
- private validTabCheck(fieldInfo: FormField) {
316
- if (fieldInfo.$parent) {
317
- if (fieldInfo.$parent.renderType == "tab") {
318
- fieldInfo.$parent.$instance.setActive(fieldInfo.$key);
319
- }
320
- this.validTabCheck(fieldInfo.$parent);
321
- }
322
- }
323
-
324
- public isValidField = (fieldName: string): boolean => {
325
- const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
326
-
327
- if (utils.isUndefined(fieldInfo)) {
328
- throw new Error(`Field name [${fieldName}] not found`);
329
- }
330
-
331
- const renderInfo = fieldInfo.$instance;
332
- if (renderInfo) {
333
- return renderInfo.valid() === true;
334
- }
335
-
336
- return true;
337
- };
338
-
339
- /**
340
- * 설정 옵션 얻기
341
- */
342
- public getOptions = () => {
343
- return this.options;
344
- };
345
-
346
- public conditionCheck() {
347
- this.fieldInfoMap.conditionCheck();
348
- }
349
-
350
- public setFieldDisabled(fieldName: string, flag: boolean) {
351
- const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
352
- fieldInfo.$instance.setDisabled(flag);
353
- }
354
-
355
- /**
356
- * 설명 추가
357
- *
358
- * @public
359
- * @param {string} fieldName
360
- * @param {string} desc
361
- */
362
- public setFieldDescription(fieldName: string, desc: string) {
363
- const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
364
- fieldInfo.$instance.setDescription(desc);
365
- }
366
-
367
- public destroy = () => {
368
- this.formElement.className = this.orginFormStyleClass;
369
- this.formElement.replaceChildren();
370
-
371
- for (const key in this) {
372
- if (utils.hasOwnProp(this, key)) {
373
- delete this[key];
374
- delete allInstance[this.selector];
375
- }
376
- }
377
- };
378
-
379
- public static validator = {
380
- string: (value: string, field: FormField) => {
381
- return stringValidator(value, field);
382
- },
383
- number: (value: string, field: FormField) => {
384
- return numberValidator(value, field);
385
- },
386
- regexp: (value: string, field: FormField) => {
387
- let result: ValidResult = { name: field.name, constraint: [] };
388
- return regexpValidator(value, field, result);
389
- },
390
- };
391
-
392
- public static instance(ele: Element | String) {
393
- let element;
394
- if (utils.isString(ele)) {
395
- element = document.querySelector(ele);
396
- } else {
397
- element = ele;
398
- }
399
- element = element as Element;
400
- let selector = element.getAttribute(SEQ_ATTR_KEY);
401
-
402
- if (utils.isUndefined(selector) || utils.isBlank(selector)) {
403
- const keys = Object.keys(allInstance);
404
- if (keys.length > 1) {
405
- throw new Error(`selector empty : [${selector}]`);
406
- }
407
- selector = keys[0];
408
-
409
- return allInstance[selector];
410
- }
411
- }
412
- /**
413
- * 모든 field 얻기
414
- */
415
- public getFields = (): any[] => {
416
- return this.options.fields;
417
- };
418
-
419
- /**
420
- * field setting
421
- * @param fields
422
- */
423
- public setFields = (fields: any[]) => {
424
- this.options.fields = fields;
425
- this.createForm(fields);
426
- };
427
-
428
- public getFieldInfoMap() {
429
- return this.fieldInfoMap;
430
- }
431
- }