@daracl/form 0.0.11 → 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 (50) 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/index.html +3 -4
  6. package/dist/main.css +1 -1
  7. package/dist/types/DateTimePicker.d.ts +5 -0
  8. package/package.json +3 -5
  9. package/src/DaraForm.ts +0 -431
  10. package/src/FieldInfoMap.ts +0 -356
  11. package/src/FormTemplate.ts +0 -207
  12. package/src/constants.ts +0 -100
  13. package/src/event/renderEvents.ts +0 -41
  14. package/src/index copy.html +0 -591
  15. package/src/index-grid.html +0 -655
  16. package/src/index-tab.html +0 -639
  17. package/src/index.html +0 -485
  18. package/src/indexVender.ts +0 -9
  19. package/src/renderer/ButtonRender.ts +0 -51
  20. package/src/renderer/CheckboxRender.ts +0 -214
  21. package/src/renderer/CustomRender.ts +0 -100
  22. package/src/renderer/DateRender.ts +0 -104
  23. package/src/renderer/DropdownRender.ts +0 -149
  24. package/src/renderer/FileRender.ts +0 -239
  25. package/src/renderer/GridRender.ts +0 -289
  26. package/src/renderer/GroupRender.ts +0 -47
  27. package/src/renderer/HiddenRender.ts +0 -36
  28. package/src/renderer/NumberRender.ts +0 -68
  29. package/src/renderer/PasswordRender.ts +0 -69
  30. package/src/renderer/RadioRender.ts +0 -191
  31. package/src/renderer/RangeRender.ts +0 -79
  32. package/src/renderer/Render.ts +0 -194
  33. package/src/renderer/TabRender.ts +0 -229
  34. package/src/renderer/TextAreaRender.ts +0 -72
  35. package/src/renderer/TextRender.ts +0 -68
  36. package/src/rule/fileValidator.ts +0 -26
  37. package/src/rule/numberValidator.ts +0 -96
  38. package/src/rule/regexpValidator.ts +0 -45
  39. package/src/rule/stringValidator.ts +0 -64
  40. package/src/rule/validator.ts +0 -49
  41. package/src/types/DataMap.d.ts +0 -17
  42. package/src/types/FormField.d.ts +0 -129
  43. package/src/types/FormOptions.d.ts +0 -91
  44. package/src/types/Message.d.ts +0 -40
  45. package/src/types/ValidResult.d.ts +0 -9
  46. package/src/util/Lanauage.ts +0 -127
  47. package/src/util/renderFactory.ts +0 -26
  48. package/src/util/styleUtils.ts +0 -85
  49. package/src/util/utils.ts +0 -283
  50. package/src/util/validUtils.ts +0 -53
@@ -1,69 +0,0 @@
1
- import { FormField } from "@t/FormField";
2
- import Render from "./Render";
3
- import { stringValidator } from "src/rule/stringValidator";
4
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
5
- import { inputEvent } from "src/event/renderEvents";
6
- import DaraForm from "src/DaraForm";
7
-
8
- export default class PasswordRender extends Render {
9
- private element: HTMLInputElement;
10
-
11
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
12
- super(daraForm, field, rowElement);
13
-
14
- this.mounted();
15
- this.setDefaultOption();
16
- this.setDefaultInfo();
17
- }
18
-
19
- mounted() {
20
- inputEvent(this.field, this.element, this);
21
- }
22
-
23
- createField() {
24
- const field = this.field;
25
-
26
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
27
-
28
- fieldContainerElement.innerHTML = `
29
- <div class="df-field">
30
- <input type="password" name="${field.$xssName}" class="form-field password help-icon" autocomplete="off" />
31
- </div>
32
- ${Render.getDescriptionTemplate(field)}
33
- <div class="help-message"></div>
34
- `;
35
-
36
- this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`) as HTMLInputElement;
37
- }
38
-
39
- getValue() {
40
- return this.element.value;
41
- }
42
-
43
- setValue(value: any, changeCheckFlag?: boolean): void {
44
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
45
- this.element.value = this.field.$value;
46
- return;
47
- }
48
- this.field.$value = value;
49
- this.element.value = value;
50
- }
51
-
52
- reset() {
53
- this.setDefaultInfo();
54
- this.setDisabled(false);
55
- resetRowElementStyleClass(this.rowElement);
56
- }
57
-
58
- getElement(): HTMLElement {
59
- return this.element;
60
- }
61
-
62
- valid(): any {
63
- const validResult = stringValidator(this.getValue(), this.field);
64
-
65
- invalidMessage(this.field, this.rowElement, validResult);
66
-
67
- return validResult;
68
- }
69
- }
@@ -1,191 +0,0 @@
1
- import { FormField, ValuesInfo } from "@t/FormField";
2
- import Render from "./Render";
3
- import { ValidResult } from "@t/ValidResult";
4
- import { RULES } from "src/constants";
5
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
6
- import { customChangeEventCall } from "src/event/renderEvents";
7
- import DaraForm from "src/DaraForm";
8
- import * as utils from "src/util/utils";
9
-
10
- export default class RadioRender extends Render {
11
- private defaultCheckValue;
12
-
13
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
14
- super(daraForm, field, rowElement);
15
-
16
- this.defaultCheckValue = "";
17
- let initDefaultValue = [] as any;
18
- if (!utils.isUndefined(field.defaultValue)) {
19
- initDefaultValue = field.defaultValue;
20
- }
21
-
22
- const valueKey = RadioRender.valuesValueKey(field);
23
- let initDefaultValueFlag = false;
24
- this.field.listItem?.list?.forEach((item) => {
25
- let itemValue = item[valueKey];
26
- if (item.selected) {
27
- this.defaultCheckValue = itemValue;
28
- }
29
-
30
- if (initDefaultValue == itemValue) {
31
- initDefaultValueFlag = true;
32
- }
33
- });
34
-
35
- // 처리 할것.
36
-
37
- if (initDefaultValueFlag) {
38
- this.defaultCheckValue = initDefaultValue;
39
- } else if (!this.defaultCheckValue) {
40
- this.defaultCheckValue = this.field.listItem?.list?.length > 0 ? this.field.listItem?.list[0][valueKey] : "";
41
- }
42
-
43
- this.mounted();
44
- this.setDefaultOption();
45
- this.setValue(this.defaultCheckValue, false);
46
- }
47
-
48
- public mounted() {
49
- this.initEvent();
50
- }
51
-
52
- public initEvent() {
53
- const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
54
-
55
- checkboxes.forEach((ele) => {
56
- ele.addEventListener("change", (e: Event) => {
57
- customChangeEventCall(this.field, e, this, this.getValue());
58
-
59
- this.valid();
60
- });
61
- });
62
- }
63
-
64
- public getSelector() {
65
- return `input[type="radio"][name="${this.field.$xssName}"]`;
66
- }
67
-
68
- createField() {
69
- const field = this.field;
70
-
71
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
72
-
73
- const templates: string[] = [];
74
- const fieldName = field.$xssName;
75
-
76
- const labelKey = Render.valuesLabelKey(field);
77
- const valueKey = Render.valuesValueKey(field);
78
-
79
- templates.push(`<div class="df-field"><div class="field-group">`);
80
-
81
- field.listItem?.list?.forEach((val) => {
82
- const radioVal = val[valueKey];
83
-
84
- templates.push(
85
- `<span class="field ${field.orientation == "vertical" ? "vertical" : "horizontal"}">
86
- <label>
87
- <input type="radio" name="${fieldName}" value="${radioVal}" class="form-field radio" ${val.selected ? "checked" : ""} ${val.disabled ? "disabled" : ""}/>
88
- ${Render.valuesLabelValue(labelKey, val)}
89
- </label>
90
- </span>
91
- `
92
- );
93
- });
94
- templates.push(`<i class="daracl-icon help-icon"></i></div></div>
95
- ${Render.getDescriptionTemplate(field)}
96
- <div class="help-message"></div>
97
- `);
98
-
99
- fieldContainerElement.innerHTML = templates.join("");
100
-
101
- this.initEvent();
102
- }
103
-
104
- public setValueItems(items: any): void {
105
- const containerEle = this.rowElement.querySelector(".df-field-container");
106
- if (containerEle) {
107
- if (this.field.listItem) {
108
- this.field.listItem.list = items;
109
- } else {
110
- this.field.listItem = {
111
- list: items,
112
- } as ValuesInfo;
113
- }
114
-
115
- this.createField();
116
-
117
- if (!utils.isBlank(this.field.$value)) {
118
- const currentValue = this.field.$value;
119
- this.field.$value = "";
120
- this.setValue(currentValue);
121
- }
122
- }
123
- }
124
-
125
- getValue() {
126
- return (this.rowElement.querySelector(`[name="${this.field.$xssName}"]:checked`) as HTMLInputElement)?.value;
127
- }
128
-
129
- setValue(value: any, changeCheckFlag?: boolean): void {
130
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
131
- value = this.field.$value;
132
- }
133
-
134
- this.field.$value = value;
135
- if (value === true) {
136
- (this.rowElement.querySelector(`[name="${this.field.$xssName}"]`) as HTMLInputElement).checked = true;
137
- return;
138
- }
139
-
140
- if (value === false) {
141
- (this.rowElement.querySelector(`[name="${this.field.$xssName}"]`) as HTMLInputElement).checked = false;
142
- return;
143
- }
144
-
145
- const elements = this.rowElement.querySelectorAll(this.getSelector());
146
-
147
- elements.forEach((ele) => {
148
- let radioEle = ele as HTMLInputElement;
149
- if (radioEle.value == value) {
150
- radioEle.checked = true;
151
- } else {
152
- radioEle.checked = false;
153
- }
154
- });
155
- }
156
-
157
- reset() {
158
- this.setValue(this.defaultCheckValue, false);
159
- this.setDisabled(false);
160
- resetRowElementStyleClass(this.rowElement);
161
- }
162
-
163
- getElement(): any {
164
- return this.rowElement.querySelectorAll(this.getSelector());
165
- }
166
-
167
- public focus() {
168
- const elements = this.getElement();
169
-
170
- if (elements && elements.length > 0) {
171
- this.getElement()[0].focus();
172
- }
173
- }
174
-
175
- valid(): any {
176
- const value = this.getValue();
177
-
178
- let validResult: ValidResult | boolean = true;
179
-
180
- if (this.field.required) {
181
- if (utils.isBlank(value)) {
182
- validResult = { name: this.field.name, constraint: [] };
183
- validResult.constraint.push(RULES.REQUIRED);
184
- }
185
- }
186
-
187
- invalidMessage(this.field, this.rowElement, validResult);
188
-
189
- return validResult;
190
- }
191
- }
@@ -1,79 +0,0 @@
1
- import { FormField } from "@t/FormField";
2
- import Render from "./Render";
3
- import { numberValidator } from "src/rule/numberValidator";
4
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
5
- import { customChangeEventCall, numberInputEvent } from "src/event/renderEvents";
6
- import DaraForm from "src/DaraForm";
7
-
8
- export default class RangeRender extends Render {
9
- private element: HTMLInputElement;
10
- private rangeNumElement: Element;
11
-
12
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
13
- super(daraForm, field, rowElement);
14
-
15
- this.rangeNumElement = rowElement.querySelector(".range-num") as Element;
16
-
17
- this.mounted();
18
- this.setDefaultOption();
19
- this.setDefaultInfo();
20
- }
21
-
22
- mounted() {
23
- this.element.addEventListener("input", (e: any) => {
24
- this.rangeNumElement.innerHTML = e.target.value;
25
-
26
- this.element.setAttribute("title", e.target.value);
27
- customChangeEventCall(this.field, e, this, this.getValue());
28
- this.valid();
29
- });
30
- }
31
-
32
- createField() {
33
- const field = this.field;
34
-
35
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
36
-
37
- fieldContainerElement.innerHTML = `
38
- <div class="df-field">
39
- <span class="range-num">${field.defaultValue ? field.defaultValue : 0}</span>
40
- <input type="range" name="${field.$xssName}" class="form-field range help-icon" min="${field.rule.minimum}" max="${field.rule.maximum}"/>
41
- </div>
42
- ${Render.getDescriptionTemplate(field)}
43
- <div class="help-message"></div>
44
- `;
45
-
46
- this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`) as HTMLInputElement;
47
- }
48
-
49
- getValue() {
50
- return this.element.value;
51
- }
52
-
53
- setValue(value: any, changeCheckFlag?: boolean): void {
54
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
55
- this.element.value = this.field.$value;
56
- return;
57
- }
58
- this.field.$value = value;
59
- this.element.value = value;
60
- }
61
-
62
- reset() {
63
- this.setDefaultInfo();
64
- this.setDisabled(false);
65
- resetRowElementStyleClass(this.rowElement);
66
- }
67
-
68
- getElement(): HTMLElement {
69
- return this.element;
70
- }
71
-
72
- valid(): any {
73
- const validResult = numberValidator(this.getValue(), this.field);
74
-
75
- invalidMessage(this.field, this.rowElement, validResult);
76
-
77
- return validResult;
78
- }
79
- }
@@ -1,194 +0,0 @@
1
- import { FormField } from "@t/FormField";
2
- import { ValidResult } from "@t/ValidResult";
3
- import DaraForm from "src/DaraForm";
4
- import * as utils from "src/util/utils";
5
-
6
- export default abstract class Render {
7
- protected daraForm;
8
- protected rowElement;
9
- protected field;
10
-
11
- private enableView: boolean = true;
12
-
13
- constructor(form: DaraForm, field: FormField, rowElement: HTMLElement) {
14
- this.daraForm = form;
15
- this.field = field;
16
- this.rowElement = rowElement;
17
- this.createField();
18
-
19
- if (field.tooltip) rowElement.querySelector(".df-tooltip")?.setAttribute("tooltip", field.tooltip);
20
- }
21
-
22
- public setDefaultInfo() {
23
- if (utils.isUndefined(this.field.defaultValue)) {
24
- this.setValue("", false);
25
- } else {
26
- this.setValue(this.field.defaultValue, false);
27
- }
28
-
29
- if (!utils.isUndefined(this.field.placeholder)) {
30
- const ele = this.getElement();
31
- if (ele instanceof Element) {
32
- ele.setAttribute("placeholder", this.field.placeholder);
33
- }
34
- }
35
- }
36
-
37
- public setDefaultOption() {
38
- this.setDisabled(this.field.disabled ?? false);
39
- }
40
-
41
- public addChildField(element: Element) {
42
- this.rowElement.querySelector(".df-field-container")?.append(element);
43
- }
44
-
45
- static isDataRender(): boolean {
46
- return true;
47
- }
48
-
49
- static isChildrenCreate(): boolean {
50
- return true;
51
- }
52
-
53
- public getForm(): DaraForm {
54
- return this.daraForm;
55
- }
56
-
57
- public abstract mounted(): void;
58
- public abstract getValue(): any;
59
- public abstract setValue(value: any, changeCheckFlag?: boolean): void;
60
- public abstract reset(): void;
61
- public abstract getElement(): any;
62
- public abstract valid(): ValidResult | boolean;
63
- public abstract createField(): void;
64
-
65
- public setValueItems(value: any): void {}
66
-
67
- public static getDescriptionTemplate(field: FormField): string {
68
- return field.description ? `<div class="df-description">${field.description}</div>` : "";
69
- }
70
-
71
- public changeEventCall(field: FormField, e: Event | null, rederInfo: Render, fieldValue: any): boolean | undefined {
72
- if (field.onChange) {
73
- let changeInfo: any = {
74
- field: field,
75
- evt: e,
76
- oldValue: field.$value,
77
- value: fieldValue,
78
- };
79
-
80
- if (field.listItem?.list) {
81
- let valuesItem = [];
82
- const valueKey = Render.valuesValueKey(field);
83
-
84
- for (let val of field.listItem.list) {
85
- let changeVal = val[valueKey];
86
- if (utils.isString(fieldValue)) {
87
- if (changeVal == fieldValue) {
88
- valuesItem.push(val);
89
- break;
90
- }
91
- } else if (utils.isArray(fieldValue)) {
92
- if (fieldValue.includes(changeVal)) {
93
- valuesItem.push(val);
94
- }
95
- }
96
- }
97
-
98
- changeInfo.valueItems = valuesItem;
99
- }
100
-
101
- if (changeInfo.oldValue != changeInfo.value && field.onChange.call(null, changeInfo) === false) {
102
- rederInfo.setValue(field.$value, false);
103
- return false;
104
- }
105
-
106
- field.$value = changeInfo.value;
107
- }
108
-
109
- this.daraForm.conditionCheck();
110
- }
111
-
112
- public focus() {
113
- this.getElement().focus();
114
- }
115
-
116
- public isEnableView() {
117
- return this.enableView;
118
- }
119
-
120
- public show() {
121
- this.enableView = true;
122
- this.rowElement.classList.remove("df-hidden");
123
- }
124
-
125
- public hide() {
126
- this.enableView = false;
127
- if (!this.rowElement.classList.contains("df-hidden")) {
128
- this.rowElement.classList.add("df-hidden");
129
- }
130
- }
131
-
132
- /**
133
- * 설명 추가
134
- *
135
- * @public
136
- * @param {string} desc
137
- */
138
- public setDescription(desc: string) {
139
- const descEle = this.rowElement.querySelector(".df-description");
140
- if (descEle) {
141
- descEle.innerHTML = desc;
142
- } else {
143
- const fieldEle = this.rowElement.querySelector(".df-field");
144
- if (fieldEle) {
145
- const parser = new DOMParser();
146
- this.field.description = desc;
147
- const descEle = parser.parseFromString(Render.getDescriptionTemplate(this.field), "text/html").querySelector(".df-description");
148
-
149
- if (descEle) fieldEle.parentNode?.insertBefore(descEle, fieldEle.nextSibling);
150
- }
151
- }
152
- }
153
-
154
- public setActive(id: string): void {
155
- //console.log("parent");
156
- }
157
-
158
- public setDisabled(flag: boolean) {
159
- const ele = this.getElement();
160
- if (ele instanceof HTMLElement) {
161
- if (flag === false) {
162
- this.getElement().removeAttribute("disabled");
163
- } else {
164
- this.getElement().setAttribute("disabled", true);
165
- }
166
- }
167
- }
168
-
169
- public commonValidator() {
170
- //this.field.diff
171
- }
172
-
173
- public static valuesValueKey(field: FormField): string {
174
- return field.listItem?.valueField ? field.listItem.valueField : "value";
175
- }
176
-
177
- public static valuesLabelKey(field: FormField): string {
178
- return field.listItem?.labelField ? field.listItem.labelField : "label";
179
- }
180
-
181
- public static valuesLabelValue(label: string, val: any) {
182
- let replaceFlag = false;
183
- const resultValue = label.replace(/\{\{([A-Za-z0-9_.]*)\}\}/g, (match, key) => {
184
- replaceFlag = true;
185
- return val[key] || "";
186
- });
187
-
188
- if (replaceFlag) {
189
- return resultValue;
190
- }
191
-
192
- return val[label] || "";
193
- }
194
- }