@daracl/form 0.0.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -0
  3. package/dist/DaraForm.d.ts +129 -0
  4. package/dist/FieldInfoMap.d.ts +97 -0
  5. package/dist/FormTemplate.d.ts +60 -0
  6. package/dist/constants.d.ts +35 -0
  7. package/dist/daracl.form.js +7629 -0
  8. package/dist/daracl.form.js.map +1 -0
  9. package/dist/daracl.form.min.css +6 -0
  10. package/dist/daracl.form.min.css.map +1 -0
  11. package/dist/daracl.form.min.js +7 -0
  12. package/dist/daracl.form.min.js.LICENSE.txt +5 -0
  13. package/dist/daracl.form.min.js.map +1 -0
  14. package/dist/event/renderEvents.d.ts +6 -0
  15. package/dist/index.cjs +4540 -0
  16. package/dist/index.cjs.map +7 -0
  17. package/dist/index.css +1074 -0
  18. package/dist/index.css.map +7 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/index.html +591 -0
  21. package/dist/index.js +4852 -0
  22. package/dist/index.js.map +7 -0
  23. package/dist/renderer/ButtonRender.d.ts +14 -0
  24. package/dist/renderer/CheckboxRender.d.ts +18 -0
  25. package/dist/renderer/CustomRender.d.ts +19 -0
  26. package/dist/renderer/DateRender.d.ts +15 -0
  27. package/dist/renderer/DropdownRender.d.ts +17 -0
  28. package/dist/renderer/FileRender.d.ts +38 -0
  29. package/dist/renderer/GridRender.d.ts +35 -0
  30. package/dist/renderer/GroupRender.d.ts +16 -0
  31. package/dist/renderer/HiddenRender.d.ts +13 -0
  32. package/dist/renderer/NumberRender.d.ts +14 -0
  33. package/dist/renderer/PasswordRender.d.ts +14 -0
  34. package/dist/renderer/RadioRender.d.ts +18 -0
  35. package/dist/renderer/RangeRender.d.ts +15 -0
  36. package/dist/renderer/Render.d.ts +43 -0
  37. package/dist/renderer/TabRender.d.ts +34 -0
  38. package/dist/renderer/TextAreaRender.d.ts +14 -0
  39. package/dist/renderer/TextRender.d.ts +14 -0
  40. package/dist/rule/fileValidator.d.ts +11 -0
  41. package/dist/rule/numberValidator.d.ts +10 -0
  42. package/dist/rule/regexpValidator.d.ts +11 -0
  43. package/dist/rule/stringValidator.d.ts +10 -0
  44. package/dist/rule/validator.d.ts +11 -0
  45. package/dist/types/DataMap.d.ts +17 -0
  46. package/dist/types/FormField.d.ts +129 -0
  47. package/dist/types/FormOptions.d.ts +91 -0
  48. package/dist/types/Message.d.ts +40 -0
  49. package/dist/types/ValidResult.d.ts +9 -0
  50. package/dist/util/Lanauage.d.ts +38 -0
  51. package/dist/util/renderFactory.d.ts +3 -0
  52. package/dist/util/styleUtils.d.ts +14 -0
  53. package/dist/util/utils.d.ts +62 -0
  54. package/dist/util/validUtils.d.ts +9 -0
  55. package/package.json +137 -0
  56. package/src/index.ts +7 -0
  57. package/style/daracl.form.scss +690 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,4540 @@
1
+ "use strict";
2
+
3
+ // src/util/utils.ts
4
+ var xssFilter = {
5
+ "&": "&",
6
+ "<": "&lt;",
7
+ ">": "&gt;",
8
+ '"': "&quot;",
9
+ "'": "&#39;"
10
+ };
11
+ var replaceXss = (inputText) => {
12
+ let returnText = inputText;
13
+ if (returnText) {
14
+ Object.keys(xssFilter).forEach((key) => {
15
+ returnText = returnText.replaceAll(key, xssFilter[key]);
16
+ });
17
+ }
18
+ return returnText;
19
+ };
20
+ var hasOwnProp = (obj, key) => {
21
+ return obj.hasOwnProperty(key);
22
+ };
23
+ var isBlank = (value) => {
24
+ if (value === null)
25
+ return true;
26
+ if (value === "")
27
+ return true;
28
+ if (typeof value === "undefined")
29
+ return true;
30
+ if (typeof value === "string" && (value === "" || value.replace(/\s/g, "") === ""))
31
+ return true;
32
+ return false;
33
+ };
34
+ var isUndefined = (value) => {
35
+ return typeof value === "undefined";
36
+ };
37
+ var isFunction = (value) => {
38
+ return typeof value === "function";
39
+ };
40
+ var isString = (value) => {
41
+ return typeof value === "string";
42
+ };
43
+ var isNumber = (value) => {
44
+ if (isBlank(value)) {
45
+ return false;
46
+ }
47
+ value = +value;
48
+ return !isNaN(value);
49
+ };
50
+ var isArray = (value) => {
51
+ return Array.isArray(value);
52
+ };
53
+ var isEmpty = (value) => isUndefined(value) || value == null;
54
+ var isTabType = (field) => {
55
+ return field && field.renderType === "tab";
56
+ };
57
+ var isGridType = (field) => {
58
+ return field && field.renderType === "grid";
59
+ };
60
+ var replaceXssField = (field) => {
61
+ field.$xssName = getXssFieldName(field);
62
+ field.label = replaceXss(field.label);
63
+ return field;
64
+ };
65
+ var ignoreValueField = (field) => {
66
+ return isGridType(field.$parent) || isTabType(field.$parent);
67
+ };
68
+ var getXssFieldName = (field) => {
69
+ if (isUndefined(field.$xssName)) {
70
+ let returnText = field.name;
71
+ if (returnText) {
72
+ Object.keys(xssFilter).forEach((key) => {
73
+ returnText = returnText.replaceAll(key, "_");
74
+ });
75
+ }
76
+ return "df_" + returnText;
77
+ }
78
+ return field.$xssName;
79
+ };
80
+ var getHashCode = (str) => {
81
+ let hash = 0;
82
+ if (str.length == 0)
83
+ return hash;
84
+ for (let i = 0; i < str.length; i++) {
85
+ let tmpChar = str.charCodeAt(i);
86
+ hash = (hash << 5) - hash + tmpChar;
87
+ hash = hash & hash;
88
+ }
89
+ return String(hash).replaceAll(/-/g, "_");
90
+ };
91
+ var isHiddenField = (field) => {
92
+ if (field.renderType === "hidden") {
93
+ return true;
94
+ }
95
+ return false;
96
+ };
97
+ var templateToElement = (htmlTemplate) => {
98
+ const template = document.createElement("template");
99
+ template.innerHTML = htmlTemplate;
100
+ return template.content.firstElementChild;
101
+ };
102
+ function isPlainObject(obj) {
103
+ if (typeof obj !== "object" || obj === null) {
104
+ return false;
105
+ }
106
+ let proto = obj;
107
+ while (Object.getPrototypeOf(proto) !== null) {
108
+ proto = Object.getPrototypeOf(proto);
109
+ }
110
+ return Object.getPrototypeOf(obj) === proto;
111
+ }
112
+ function isObject(value) {
113
+ return typeof value === "object" && value !== null && !Array.isArray(value);
114
+ }
115
+ function isDate(value) {
116
+ return value instanceof Date && !isNaN(value.valueOf());
117
+ }
118
+ var merge = (...value) => {
119
+ let reval = value[0];
120
+ if (!isPlainObject(reval) || isEmpty(reval)) {
121
+ return reval;
122
+ }
123
+ let i = 1;
124
+ if (Object.keys(reval).length > 0) {
125
+ i = 0;
126
+ reval = isArray(reval) ? [] : {};
127
+ }
128
+ const argLen = value.length;
129
+ for (; i < argLen; i += 1) {
130
+ cloneDeep(reval, value[i]);
131
+ }
132
+ return reval;
133
+ };
134
+ function cloneDeep(dst, src) {
135
+ if (isObject(src)) {
136
+ return cloneObjectDeep(dst, src);
137
+ }
138
+ if (isArray(src)) {
139
+ return cloneArrayDeep(dst, src);
140
+ }
141
+ if (isDate(src)) {
142
+ return new src.constructor(src);
143
+ }
144
+ return src;
145
+ }
146
+ function cloneObjectDeep(dst, src) {
147
+ if (isFunction(src)) {
148
+ return src;
149
+ }
150
+ for (const key of Object.keys(src)) {
151
+ const val = src[key];
152
+ if (isUndefined(val)) {
153
+ continue;
154
+ }
155
+ if (val === null) {
156
+ dst[key] = val;
157
+ } else if (isFunction(val)) {
158
+ dst[key] = val;
159
+ } else if (isEmpty(dst[key])) {
160
+ dst[key] = cloneDeep(isArray(val) ? [] : {}, val);
161
+ } else if (!isObject(val)) {
162
+ dst[key] = val;
163
+ } else {
164
+ cloneDeep(dst[key], val);
165
+ }
166
+ }
167
+ return dst;
168
+ }
169
+ function cloneArrayDeep(dst, src) {
170
+ const isObj = isPlainObject(dst);
171
+ for (let i = 0; i < src.length; i += 1) {
172
+ const val = src[i];
173
+ let newVal;
174
+ if (val == null) {
175
+ newVal = val;
176
+ } else {
177
+ newVal = cloneDeep(isArray(val) ? [] : {}, val);
178
+ }
179
+ if (isObj) {
180
+ dst[i] = newVal;
181
+ } else {
182
+ dst.push(newVal);
183
+ }
184
+ }
185
+ return dst;
186
+ }
187
+
188
+ // src/renderer/Render.ts
189
+ var Render = class _Render {
190
+ constructor(form, field, rowElement) {
191
+ this.enableView = true;
192
+ this.daraForm = form;
193
+ this.field = field;
194
+ this.rowElement = rowElement;
195
+ this.createField();
196
+ if (field.tooltip)
197
+ rowElement.querySelector(".df-tooltip")?.setAttribute("tooltip", field.tooltip);
198
+ }
199
+ setDefaultInfo() {
200
+ if (isUndefined(this.field.defaultValue)) {
201
+ this.setValue("", false);
202
+ } else {
203
+ this.setValue(this.field.defaultValue, false);
204
+ }
205
+ if (!isUndefined(this.field.placeholder)) {
206
+ const ele = this.getElement();
207
+ if (ele instanceof Element) {
208
+ ele.setAttribute("placeholder", this.field.placeholder);
209
+ }
210
+ }
211
+ }
212
+ setDefaultOption() {
213
+ this.setDisabled(this.field.disabled ?? false);
214
+ }
215
+ addChildField(element) {
216
+ this.rowElement.querySelector(".df-field-container")?.append(element);
217
+ }
218
+ static isDataRender() {
219
+ return true;
220
+ }
221
+ static isChildrenCreate() {
222
+ return true;
223
+ }
224
+ getForm() {
225
+ return this.daraForm;
226
+ }
227
+ setValueItems(value) {
228
+ }
229
+ static getDescriptionTemplate(field) {
230
+ return field.description ? `<div class="df-description">${field.description}</div>` : "";
231
+ }
232
+ changeEventCall(field, e, rederInfo, fieldValue) {
233
+ if (field.onChange) {
234
+ let changeInfo = {
235
+ field,
236
+ evt: e,
237
+ oldValue: field.$value,
238
+ value: fieldValue
239
+ };
240
+ if (field.listItem?.list) {
241
+ let valuesItem = [];
242
+ const valueKey = _Render.valuesValueKey(field);
243
+ for (let val of field.listItem.list) {
244
+ let changeVal = val[valueKey];
245
+ if (isString(fieldValue)) {
246
+ if (changeVal == fieldValue) {
247
+ valuesItem.push(val);
248
+ break;
249
+ }
250
+ } else if (isArray(fieldValue)) {
251
+ if (fieldValue.includes(changeVal)) {
252
+ valuesItem.push(val);
253
+ }
254
+ }
255
+ }
256
+ changeInfo.valueItems = valuesItem;
257
+ }
258
+ if (changeInfo.oldValue != changeInfo.value && field.onChange.call(null, changeInfo) === false) {
259
+ rederInfo.setValue(field.$value, false);
260
+ return false;
261
+ }
262
+ field.$value = changeInfo.value;
263
+ }
264
+ this.daraForm.conditionCheck();
265
+ }
266
+ focus() {
267
+ this.getElement().focus();
268
+ }
269
+ isEnableView() {
270
+ return this.enableView;
271
+ }
272
+ show() {
273
+ this.enableView = true;
274
+ this.rowElement.classList.remove("df-hidden");
275
+ }
276
+ hide() {
277
+ this.enableView = false;
278
+ if (!this.rowElement.classList.contains("df-hidden")) {
279
+ this.rowElement.classList.add("df-hidden");
280
+ }
281
+ }
282
+ /**
283
+ * 설명 추가
284
+ *
285
+ * @public
286
+ * @param {string} desc
287
+ */
288
+ setDescription(desc) {
289
+ const descEle = this.rowElement.querySelector(".df-description");
290
+ if (descEle) {
291
+ descEle.innerHTML = desc;
292
+ } else {
293
+ const fieldEle = this.rowElement.querySelector(".df-field");
294
+ if (fieldEle) {
295
+ const parser = new DOMParser();
296
+ this.field.description = desc;
297
+ const descEle2 = parser.parseFromString(_Render.getDescriptionTemplate(this.field), "text/html").querySelector(".df-description");
298
+ if (descEle2)
299
+ fieldEle.parentNode?.insertBefore(descEle2, fieldEle.nextSibling);
300
+ }
301
+ }
302
+ }
303
+ setActive(id) {
304
+ }
305
+ setDisabled(flag) {
306
+ const ele = this.getElement();
307
+ if (ele instanceof HTMLElement) {
308
+ if (flag === false) {
309
+ this.getElement().removeAttribute("disabled");
310
+ } else {
311
+ this.getElement().setAttribute("disabled", true);
312
+ }
313
+ }
314
+ }
315
+ commonValidator() {
316
+ }
317
+ static valuesValueKey(field) {
318
+ return field.listItem?.valueField ? field.listItem.valueField : "value";
319
+ }
320
+ static valuesLabelKey(field) {
321
+ return field.listItem?.labelField ? field.listItem.labelField : "label";
322
+ }
323
+ static valuesLabelValue(label, val) {
324
+ let replaceFlag = false;
325
+ const resultValue = label.replace(/\{\{([A-Za-z0-9_.]*)\}\}/g, (match, key) => {
326
+ replaceFlag = true;
327
+ return val[key] || "";
328
+ });
329
+ if (replaceFlag) {
330
+ return resultValue;
331
+ }
332
+ return val[label] || "";
333
+ }
334
+ };
335
+
336
+ // src/rule/regexpValidator.ts
337
+ var regexp = {
338
+ mobile: /^\d{3}-\d{3,4}-\d{4}$/,
339
+ email: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
340
+ url: /^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*(?:\.(?:[a-zA-Z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/,
341
+ number: /\d$/,
342
+ alpha: /^[a-zA-Z]+$/,
343
+ "alpha-num": /^[a-zA-Z0-9]+$/,
344
+ variable: /^[a-zA-Z0-9_$][a-zA-Z0-9_$]*$/,
345
+ "number-char": /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]/,
346
+ "upper-char": /^(?=.*?[A-Z])(?=.*?[a-z])/,
347
+ "upper-char-special": /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-])/,
348
+ "upper-char-special-number": /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]/
349
+ };
350
+ var regexpValidator = (value, field, result) => {
351
+ if (!field.$instance.isEnableView()) {
352
+ return { name: field.name, constraint: [] };
353
+ }
354
+ if (typeof result === "undefined") {
355
+ result = { name: field.name, constraint: [] };
356
+ }
357
+ const regexpType = field.regexpType;
358
+ if (regexpType) {
359
+ if (!regexp[regexpType].test(value)) {
360
+ result.regexp = regexpType;
361
+ return result;
362
+ }
363
+ }
364
+ return result;
365
+ };
366
+
367
+ // src/rule/validator.ts
368
+ var validator = (value, field, result) => {
369
+ if (field.validator) {
370
+ result.validator = field.validator(field, value);
371
+ if (typeof result.validator === "object") {
372
+ return result;
373
+ }
374
+ }
375
+ result = regexpValidator(value, field, result);
376
+ if (result.regexp) {
377
+ return result;
378
+ }
379
+ if (field.different) {
380
+ const diffFieldName = field.different.field;
381
+ const diffField = field.$instance.getForm().getField(diffFieldName);
382
+ if (!isEmpty(diffField) && field.$instance.getValue() == diffField.$instance.getValue()) {
383
+ result.message = field.different.message;
384
+ return result;
385
+ }
386
+ }
387
+ if (field.identical) {
388
+ const diffFieldName = field.identical.field;
389
+ const diffField = field.$instance.getForm().getField(diffFieldName);
390
+ if (!isEmpty(diffField) && field.$instance.getValue() != diffField.$instance.getValue()) {
391
+ result.message = field.identical.message;
392
+ return result;
393
+ }
394
+ }
395
+ return true;
396
+ };
397
+
398
+ // src/rule/numberValidator.ts
399
+ var numberValidator = (value, field) => {
400
+ if (!field.$instance.isEnableView()) {
401
+ return true;
402
+ }
403
+ const result = { name: field.name, constraint: [] };
404
+ const numValue = Number(value);
405
+ if (field.required && isBlank(value)) {
406
+ result.constraint.push(RULES.REQUIRED);
407
+ return result;
408
+ }
409
+ if (!isNumber(value)) {
410
+ result.constraint.push(RULES.NAN);
411
+ return result;
412
+ }
413
+ if (validator(value, field, result) !== true) {
414
+ return result;
415
+ }
416
+ const rule = field.rule;
417
+ if (rule) {
418
+ const isMinimum = isNumber(rule.minimum), isMaximum = isNumber(rule.maximum);
419
+ let minRule = false, minExclusive = false, maxRule = false, maxExclusive = false;
420
+ if (isMinimum) {
421
+ if (rule.exclusiveMinimum && numValue <= rule.minimum) {
422
+ minExclusive = true;
423
+ } else if (numValue < rule.minimum) {
424
+ minRule = true;
425
+ }
426
+ }
427
+ if (isMaximum) {
428
+ if (rule.exclusiveMaximum && numValue >= rule.maximum) {
429
+ maxExclusive = true;
430
+ } else if (numValue > rule.maximum) {
431
+ maxRule = true;
432
+ }
433
+ }
434
+ if (isMinimum && isMaximum && (minRule || minExclusive || maxRule || maxExclusive)) {
435
+ if (rule.exclusiveMinimum && rule.exclusiveMaximum && (minExclusive || maxExclusive)) {
436
+ result.constraint.push(RULES.BETWEEN_EXCLUSIVE_MINMAX);
437
+ } else if (minExclusive) {
438
+ result.constraint.push(RULES.BETWEEN_EXCLUSIVE_MIN);
439
+ } else if (maxExclusive) {
440
+ result.constraint.push(RULES.BETWEEN_EXCLUSIVE_MAX);
441
+ } else {
442
+ result.constraint.push(RULES.BETWEEN);
443
+ }
444
+ } else {
445
+ if (minExclusive) {
446
+ result.constraint.push(RULES.EXCLUSIVE_MIN);
447
+ }
448
+ if (maxExclusive) {
449
+ result.constraint.push(RULES.EXCLUSIVE_MAX);
450
+ }
451
+ if (minRule) {
452
+ result.constraint.push(RULES.MIN);
453
+ }
454
+ if (maxRule) {
455
+ result.constraint.push(RULES.MAX);
456
+ }
457
+ }
458
+ }
459
+ if (result.constraint.length > 0) {
460
+ return result;
461
+ }
462
+ return true;
463
+ };
464
+
465
+ // src/util/validUtils.ts
466
+ var invalidMessage = (field, rowElement, validResult) => {
467
+ if (validResult === true) {
468
+ rowElement.classList.remove("invalid");
469
+ if (!rowElement.classList.contains("valid")) {
470
+ rowElement.classList.add("valid");
471
+ }
472
+ const helpMessageElement = rowElement.querySelector(".help-message");
473
+ if (helpMessageElement) {
474
+ helpMessageElement.innerHTML = "";
475
+ }
476
+ return;
477
+ }
478
+ rowElement.classList.remove("valid");
479
+ if (!rowElement.classList.contains("invalid")) {
480
+ rowElement.classList.add("invalid");
481
+ }
482
+ if (validResult !== false) {
483
+ const message2 = Lanauage_default.validMessage(field, validResult);
484
+ if (validResult.message) {
485
+ message2.push(validResult.message);
486
+ }
487
+ const helpMessageElement = rowElement.querySelector(".help-message");
488
+ if (helpMessageElement && message2.length > 0) {
489
+ const msgHtml = [];
490
+ message2.forEach((item) => {
491
+ msgHtml.push(`<div>${item}</div>`);
492
+ });
493
+ helpMessageElement.innerHTML = msgHtml.join("");
494
+ }
495
+ }
496
+ };
497
+ var resetRowElementStyleClass = (rowElement) => {
498
+ rowElement.classList.remove("invalid");
499
+ rowElement.classList.remove("valid");
500
+ };
501
+
502
+ // src/event/renderEvents.ts
503
+ var inputEvent = (field, element, renderInfo) => {
504
+ element.addEventListener("input", (e) => {
505
+ customChangeEventCall(field, e, renderInfo, renderInfo.getValue());
506
+ renderInfo.valid();
507
+ });
508
+ };
509
+ var numberInputEvent = (field, element, renderInfo) => {
510
+ element.addEventListener("keyup", (e) => {
511
+ const val = e.target.value;
512
+ if (!isNumber(val)) {
513
+ element.value = val.replace(/[^0-9\.\-\+]/g, "");
514
+ e.preventDefault();
515
+ }
516
+ customChangeEventCall(field, e, renderInfo, renderInfo.getValue());
517
+ renderInfo.valid();
518
+ });
519
+ };
520
+ var dropdownChangeEvent = (field, element, renderInfo) => {
521
+ element.addEventListener("change", (e) => {
522
+ customChangeEventCall(field, e, renderInfo, renderInfo.getValue());
523
+ renderInfo.valid();
524
+ });
525
+ };
526
+ var customChangeEventCall = (field, e, renderInfo, value) => {
527
+ renderInfo.changeEventCall(field, e, renderInfo, value);
528
+ };
529
+
530
+ // src/renderer/NumberRender.ts
531
+ var NumberRender = class extends Render {
532
+ constructor(field, rowElement, daraForm) {
533
+ super(daraForm, field, rowElement);
534
+ this.mounted();
535
+ this.setDefaultOption();
536
+ this.setDefaultInfo();
537
+ }
538
+ mounted() {
539
+ numberInputEvent(this.field, this.element, this);
540
+ }
541
+ createField() {
542
+ const field = this.field;
543
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
544
+ fieldContainerElement.innerHTML = `
545
+ <div class="df-field">
546
+ <input type="text" name="${field.$xssName}" class="form-field number help-icon" />
547
+ </div>
548
+ ${Render.getDescriptionTemplate(field)}
549
+ <div class="help-message"></div>
550
+ `;
551
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
552
+ }
553
+ getValue() {
554
+ return this.element.value;
555
+ }
556
+ setValue(value, changeCheckFlag) {
557
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
558
+ this.element.value = this.field.$value;
559
+ return;
560
+ }
561
+ this.field.$value = value;
562
+ this.element.value = value;
563
+ }
564
+ reset() {
565
+ this.setDefaultInfo();
566
+ this.setDisabled(false);
567
+ resetRowElementStyleClass(this.rowElement);
568
+ }
569
+ getElement() {
570
+ return this.element;
571
+ }
572
+ valid() {
573
+ const validResult = numberValidator(this.getValue(), this.field);
574
+ invalidMessage(this.field, this.rowElement, validResult);
575
+ return validResult;
576
+ }
577
+ };
578
+
579
+ // src/rule/stringValidator.ts
580
+ var stringValidator = (value, field) => {
581
+ if (!field.$instance.isEnableView()) {
582
+ return true;
583
+ }
584
+ let result = { name: field.name, constraint: [] };
585
+ if (field.required && isBlank(value)) {
586
+ result.constraint.push(RULES.REQUIRED);
587
+ return result;
588
+ }
589
+ const validResult = validator(value, field, result);
590
+ if (validResult !== true) {
591
+ return validResult;
592
+ }
593
+ const rule = field.rule;
594
+ if (rule) {
595
+ const valueLength = value.length;
596
+ const isMinNumber = isNumber(rule.minLength), isMaxNumber = isNumber(rule.maxLength);
597
+ let minRule = false, maxRule = false;
598
+ if (isMinNumber && valueLength < rule.minLength) {
599
+ minRule = true;
600
+ }
601
+ if (isMaxNumber && valueLength > rule.maxLength) {
602
+ maxRule = true;
603
+ }
604
+ if (isMinNumber && isMaxNumber && (minRule || maxRule)) {
605
+ result.constraint.push(RULES.BETWEEN);
606
+ } else {
607
+ if (minRule) {
608
+ result.constraint.push(RULES.MIN_LENGTH);
609
+ }
610
+ if (maxRule) {
611
+ result.constraint.push(RULES.MAX_LENGTH);
612
+ }
613
+ }
614
+ if (result.constraint.length > 0) {
615
+ return result;
616
+ }
617
+ }
618
+ return true;
619
+ };
620
+
621
+ // src/renderer/TextAreaRender.ts
622
+ var TextAreaRender = class extends Render {
623
+ constructor(field, rowElement, daraForm) {
624
+ super(daraForm, field, rowElement);
625
+ this.mounted();
626
+ this.setDefaultOption();
627
+ this.setDefaultInfo();
628
+ }
629
+ mounted() {
630
+ inputEvent(this.field, this.element, this);
631
+ }
632
+ createField() {
633
+ const field = this.field;
634
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
635
+ let rows = field.customOptions?.rows;
636
+ rows = +rows > 0 ? rows : 3;
637
+ fieldContainerElement.innerHTML = `
638
+ <div class="df-field">
639
+ <textarea name="${field.$xssName}" rows="${rows}" class="form-field textarea help-icon"></textarea>
640
+ </div>
641
+ ${Render.getDescriptionTemplate(field)}
642
+ <div class="help-message"></div>
643
+ `;
644
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
645
+ }
646
+ getValue() {
647
+ return this.element.value;
648
+ }
649
+ setValue(value, changeCheckFlag) {
650
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
651
+ this.element.value = this.field.$value;
652
+ return;
653
+ }
654
+ this.field.$value = value;
655
+ this.element.value = value;
656
+ }
657
+ reset() {
658
+ this.setDefaultInfo();
659
+ this.setDisabled(false);
660
+ resetRowElementStyleClass(this.rowElement);
661
+ }
662
+ getElement() {
663
+ return this.element;
664
+ }
665
+ valid() {
666
+ const validResult = stringValidator(this.getValue(), this.field);
667
+ invalidMessage(this.field, this.rowElement, validResult);
668
+ return validResult;
669
+ }
670
+ };
671
+
672
+ // src/renderer/DropdownRender.ts
673
+ var DropdownRender = class _DropdownRender extends Render {
674
+ constructor(field, rowElement, daraForm) {
675
+ super(daraForm, field, rowElement);
676
+ let initDefaultValue = "";
677
+ if (!isUndefined(field.defaultValue)) {
678
+ initDefaultValue = field.defaultValue;
679
+ }
680
+ const valueKey = _DropdownRender.valuesValueKey(field);
681
+ let initDefaultValueFlag = false;
682
+ this.field.listItem?.list?.forEach((item) => {
683
+ let itemValue = item[valueKey];
684
+ if (item.selected) {
685
+ this.defaultSelected = itemValue;
686
+ }
687
+ if (itemValue == initDefaultValue) {
688
+ initDefaultValueFlag = true;
689
+ }
690
+ });
691
+ if (initDefaultValueFlag) {
692
+ this.defaultSelected = initDefaultValue;
693
+ } else if (!this.defaultSelected) {
694
+ if (field.customOptions?.disableDefaultOption === true) {
695
+ this.defaultSelected = this.field.listItem?.list?.length > 0 ? this.field.listItem.list[0][valueKey] || "" : "";
696
+ }
697
+ }
698
+ if (isUndefined(this.defaultSelected)) {
699
+ this.defaultSelected = "";
700
+ }
701
+ this.mounted();
702
+ this.setDefaultOption();
703
+ this.setValue(this.defaultSelected, false);
704
+ }
705
+ mounted() {
706
+ dropdownChangeEvent(this.field, this.element, this);
707
+ }
708
+ createField() {
709
+ const field = this.field;
710
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
711
+ let template = ` <div class="df-field"><select name="${field.$xssName}" class="form-field dropdown">
712
+ ${this.dropdownValuesTemplate(field)}
713
+ </select> <i class="help-icon"></i></div>
714
+ ${Render.getDescriptionTemplate(field)}
715
+ <div class="help-message"></div>
716
+ `;
717
+ fieldContainerElement.innerHTML = template;
718
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
719
+ }
720
+ setValueItems(items) {
721
+ if (this.field.listItem) {
722
+ this.field.listItem.list = items;
723
+ } else {
724
+ this.field.listItem = {
725
+ list: items
726
+ };
727
+ }
728
+ this.element.innerHTML = this.dropdownValuesTemplate(this.field);
729
+ if (!isBlank(this.field.$value)) {
730
+ const currentValue = this.field.$value;
731
+ this.field.$value = "";
732
+ this.setValue(currentValue);
733
+ }
734
+ }
735
+ getValue() {
736
+ return this.element.value;
737
+ }
738
+ setValue(value, changeCheckFlag) {
739
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
740
+ this.element.value = this.field.$value;
741
+ return;
742
+ }
743
+ this.field.$value = value;
744
+ this.element.value = value;
745
+ }
746
+ reset() {
747
+ this.setValue(this.defaultSelected, false);
748
+ this.setDisabled(false);
749
+ resetRowElementStyleClass(this.rowElement);
750
+ }
751
+ getElement() {
752
+ return this.element;
753
+ }
754
+ valid() {
755
+ const value = this.getValue();
756
+ let validResult = true;
757
+ if (this.field.required) {
758
+ if (value.length < 1) {
759
+ validResult = { name: this.field.name, constraint: [] };
760
+ validResult.constraint.push(RULES.REQUIRED);
761
+ }
762
+ }
763
+ invalidMessage(this.field, this.rowElement, validResult);
764
+ return validResult;
765
+ }
766
+ dropdownValuesTemplate(field) {
767
+ const labelKey = Render.valuesLabelKey(field);
768
+ const valueKey = Render.valuesValueKey(field);
769
+ let template = "";
770
+ if (field.customOptions?.disableDefaultOption !== true) {
771
+ template += `<option value="">${Lanauage_default.getMessage("selection")}</option>`;
772
+ }
773
+ field.listItem?.list?.forEach((val) => {
774
+ const attr = `${val.selected ? "selected" : ""} ${val.disabled ? "disabled" : ""}`;
775
+ if (isUndefined(val[valueKey]) && val.label) {
776
+ template += `<option value="${val.value || ""}" ${attr}>${val.label}</option>`;
777
+ } else {
778
+ template += `<option value="${val[valueKey]}" ${attr}>${Render.valuesLabelValue(labelKey, val)}</option>`;
779
+ }
780
+ });
781
+ return template;
782
+ }
783
+ };
784
+
785
+ // src/renderer/TextRender.ts
786
+ var TextRender = class extends Render {
787
+ constructor(field, rowElement, daraForm) {
788
+ super(daraForm, field, rowElement);
789
+ this.mounted();
790
+ this.setDefaultOption();
791
+ this.setDefaultInfo();
792
+ }
793
+ mounted() {
794
+ inputEvent(this.field, this.element, this);
795
+ }
796
+ createField() {
797
+ const field = this.field;
798
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
799
+ fieldContainerElement.innerHTML = `
800
+ <div class="df-field">
801
+ <input type="text" name="${field.$xssName}" class="form-field text help-icon" />
802
+ </div>
803
+ ${Render.getDescriptionTemplate(field)}
804
+ <div class="help-message"></div>
805
+ `;
806
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
807
+ }
808
+ getValue() {
809
+ return this.element.value;
810
+ }
811
+ setValue(value, changeCheckFlag) {
812
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
813
+ this.element.value = this.field.$value;
814
+ return;
815
+ }
816
+ this.field.$value = value;
817
+ this.element.value = value;
818
+ }
819
+ reset() {
820
+ this.setDefaultInfo();
821
+ this.setDisabled(false);
822
+ resetRowElementStyleClass(this.rowElement);
823
+ }
824
+ getElement() {
825
+ return this.element;
826
+ }
827
+ valid() {
828
+ const validResult = stringValidator(this.getValue(), this.field);
829
+ invalidMessage(this.field, this.rowElement, validResult);
830
+ return validResult;
831
+ }
832
+ };
833
+
834
+ // src/renderer/CheckboxRender.ts
835
+ var CheckboxRender = class _CheckboxRender extends Render {
836
+ constructor(field, rowElement, daraForm) {
837
+ super(daraForm, field, rowElement);
838
+ this.defaultCheckValue = [];
839
+ this.defaultCheckValue = [];
840
+ let initDefaultValue = [];
841
+ if (!isUndefined(field.defaultValue)) {
842
+ if (isArray(field.defaultValue)) {
843
+ initDefaultValue = field.defaultValue;
844
+ } else {
845
+ initDefaultValue = [field.defaultValue];
846
+ }
847
+ }
848
+ const valueKey = _CheckboxRender.valuesValueKey(field);
849
+ if (isUndefined(this.field.listItem)) {
850
+ this.setValueItems([{ label: "", value: "Y" }]);
851
+ }
852
+ let initDefaultValueFlag = false;
853
+ this.field.listItem?.list?.forEach((item) => {
854
+ let itemValue = item[valueKey];
855
+ if (item.selected) {
856
+ this.defaultCheckValue.push(itemValue ? itemValue : true);
857
+ }
858
+ if (initDefaultValue.includes(itemValue)) {
859
+ initDefaultValueFlag = true;
860
+ }
861
+ });
862
+ this.defaultCheckValue = initDefaultValueFlag ? initDefaultValue : this.defaultCheckValue;
863
+ this.mounted();
864
+ this.setDefaultOption();
865
+ this.setValue(this.defaultCheckValue, false);
866
+ }
867
+ mounted() {
868
+ this.initEvent();
869
+ }
870
+ initEvent() {
871
+ const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
872
+ checkboxes.forEach((ele) => {
873
+ ele.addEventListener("change", (e) => {
874
+ customChangeEventCall(this.field, e, this, this.getValue());
875
+ this.valid();
876
+ });
877
+ });
878
+ }
879
+ getSelector() {
880
+ return `input[type="checkbox"][name="${this.field.$xssName}"]`;
881
+ }
882
+ createField() {
883
+ const field = this.field;
884
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
885
+ const templates = [];
886
+ const fieldName = field.$xssName;
887
+ const labelKey = Render.valuesLabelKey(field);
888
+ const valueKey = Render.valuesValueKey(field);
889
+ templates.push(` <div class="df-field"><div class="field-group">`);
890
+ field.listItem?.list?.forEach((val) => {
891
+ const checkVal = val[valueKey];
892
+ templates.push(`
893
+ <span class="field ${field.listItem.orientation == "vertical" ? "vertical" : "horizontal"}">
894
+ <label>
895
+ <input type="checkbox" name="${fieldName}" value="${checkVal ? replaceXss(checkVal) : ""}" class="form-field checkbox" ${val.selected ? "checked" : ""} ${val.disabled ? "disabled" : ""} />
896
+ ${Render.valuesLabelValue(labelKey, val)}
897
+ </label>
898
+ </span>
899
+ `);
900
+ });
901
+ templates.push(`<i class="daracl-icon help-icon"></i></div></div> ${Render.getDescriptionTemplate(field)}<div class="help-message"></div>`);
902
+ fieldContainerElement.innerHTML = templates.join("");
903
+ }
904
+ setValueItems(items) {
905
+ const containerEle = this.rowElement.querySelector(".df-field-container");
906
+ if (containerEle) {
907
+ if (this.field.listItem) {
908
+ this.field.listItem.list = items;
909
+ } else {
910
+ this.field.listItem = {
911
+ list: items
912
+ };
913
+ }
914
+ this.createField();
915
+ if (!isBlank(this.field.$value)) {
916
+ const currentValue = this.field.$value;
917
+ this.field.$value = "";
918
+ this.setValue(currentValue);
919
+ }
920
+ }
921
+ }
922
+ getValue() {
923
+ const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
924
+ if (checkboxes.length > 1) {
925
+ const checkValue = [];
926
+ checkboxes.forEach((ele) => {
927
+ const checkEle = ele;
928
+ if (checkEle.checked) {
929
+ checkValue.push(checkEle.value);
930
+ }
931
+ });
932
+ return checkValue;
933
+ } else {
934
+ const checkElement = this.rowElement.querySelector(`[name="${this.field.$xssName}"]`);
935
+ if (checkElement?.checked) {
936
+ return checkElement.value ? checkElement.value : true;
937
+ }
938
+ return checkElement.value ? "" : false;
939
+ }
940
+ }
941
+ setValue(value, changeCheckFlag) {
942
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
943
+ value = this.field.$value;
944
+ }
945
+ this.field.$value = value;
946
+ if (value === true) {
947
+ this.rowElement.querySelector(`[name="${this.field.$xssName}"]`).checked = true;
948
+ return;
949
+ }
950
+ if (value === false) {
951
+ this.rowElement.querySelector(`[name="${this.field.$xssName}"]`).checked = false;
952
+ return;
953
+ }
954
+ let valueArr = [];
955
+ if (Array.isArray(value)) {
956
+ valueArr = value;
957
+ } else {
958
+ valueArr.push(value);
959
+ }
960
+ const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
961
+ checkboxes.forEach((ele) => {
962
+ ele.checked = false;
963
+ });
964
+ valueArr.forEach((val) => {
965
+ const ele = this.rowElement.querySelector(`[name="${this.field.$xssName}"][value="${val}"]`);
966
+ if (ele)
967
+ ele.checked = true;
968
+ });
969
+ }
970
+ reset() {
971
+ if (this.field.listItem?.list?.length == 1 && this.defaultCheckValue.length == 1) {
972
+ this.setValue(true, false);
973
+ } else {
974
+ this.setValue(this.defaultCheckValue, false);
975
+ }
976
+ this.setDisabled(false);
977
+ resetRowElementStyleClass(this.rowElement);
978
+ }
979
+ getElement() {
980
+ return this.rowElement.querySelectorAll(`[name="${this.field.$xssName}"]`);
981
+ }
982
+ focus() {
983
+ const elements = this.getElement();
984
+ if (elements && elements.length > 0) {
985
+ this.getElement()[0].focus();
986
+ }
987
+ }
988
+ valid() {
989
+ const value = this.getValue();
990
+ let validResult = true;
991
+ if (this.field.required && isArray(value)) {
992
+ if (value.length < 1) {
993
+ validResult = { name: this.field.name, constraint: [] };
994
+ validResult.constraint.push(RULES.REQUIRED);
995
+ }
996
+ }
997
+ invalidMessage(this.field, this.rowElement, validResult);
998
+ return validResult;
999
+ }
1000
+ };
1001
+
1002
+ // src/renderer/RadioRender.ts
1003
+ var RadioRender = class _RadioRender extends Render {
1004
+ constructor(field, rowElement, daraForm) {
1005
+ super(daraForm, field, rowElement);
1006
+ this.defaultCheckValue = "";
1007
+ let initDefaultValue = [];
1008
+ if (!isUndefined(field.defaultValue)) {
1009
+ initDefaultValue = field.defaultValue;
1010
+ }
1011
+ const valueKey = _RadioRender.valuesValueKey(field);
1012
+ let initDefaultValueFlag = false;
1013
+ this.field.listItem?.list?.forEach((item) => {
1014
+ let itemValue = item[valueKey];
1015
+ if (item.selected) {
1016
+ this.defaultCheckValue = itemValue;
1017
+ }
1018
+ if (initDefaultValue == itemValue) {
1019
+ initDefaultValueFlag = true;
1020
+ }
1021
+ });
1022
+ if (initDefaultValueFlag) {
1023
+ this.defaultCheckValue = initDefaultValue;
1024
+ } else if (!this.defaultCheckValue) {
1025
+ this.defaultCheckValue = this.field.listItem?.list?.length > 0 ? this.field.listItem?.list[0][valueKey] : "";
1026
+ }
1027
+ this.mounted();
1028
+ this.setDefaultOption();
1029
+ this.setValue(this.defaultCheckValue, false);
1030
+ }
1031
+ mounted() {
1032
+ this.initEvent();
1033
+ }
1034
+ initEvent() {
1035
+ const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
1036
+ checkboxes.forEach((ele) => {
1037
+ ele.addEventListener("change", (e) => {
1038
+ customChangeEventCall(this.field, e, this, this.getValue());
1039
+ this.valid();
1040
+ });
1041
+ });
1042
+ }
1043
+ getSelector() {
1044
+ return `input[type="radio"][name="${this.field.$xssName}"]`;
1045
+ }
1046
+ createField() {
1047
+ const field = this.field;
1048
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1049
+ const templates = [];
1050
+ const fieldName = field.$xssName;
1051
+ const labelKey = Render.valuesLabelKey(field);
1052
+ const valueKey = Render.valuesValueKey(field);
1053
+ templates.push(`<div class="df-field"><div class="field-group">`);
1054
+ field.listItem?.list?.forEach((val) => {
1055
+ const radioVal = val[valueKey];
1056
+ templates.push(
1057
+ `<span class="field ${field.orientation == "vertical" ? "vertical" : "horizontal"}">
1058
+ <label>
1059
+ <input type="radio" name="${fieldName}" value="${radioVal}" class="form-field radio" ${val.selected ? "checked" : ""} ${val.disabled ? "disabled" : ""}/>
1060
+ ${Render.valuesLabelValue(labelKey, val)}
1061
+ </label>
1062
+ </span>
1063
+ `
1064
+ );
1065
+ });
1066
+ templates.push(`<i class="daracl-icon help-icon"></i></div></div>
1067
+ ${Render.getDescriptionTemplate(field)}
1068
+ <div class="help-message"></div>
1069
+ `);
1070
+ fieldContainerElement.innerHTML = templates.join("");
1071
+ this.initEvent();
1072
+ }
1073
+ setValueItems(items) {
1074
+ const containerEle = this.rowElement.querySelector(".df-field-container");
1075
+ if (containerEle) {
1076
+ if (this.field.listItem) {
1077
+ this.field.listItem.list = items;
1078
+ } else {
1079
+ this.field.listItem = {
1080
+ list: items
1081
+ };
1082
+ }
1083
+ this.createField();
1084
+ if (!isBlank(this.field.$value)) {
1085
+ const currentValue = this.field.$value;
1086
+ this.field.$value = "";
1087
+ this.setValue(currentValue);
1088
+ }
1089
+ }
1090
+ }
1091
+ getValue() {
1092
+ return this.rowElement.querySelector(`[name="${this.field.$xssName}"]:checked`)?.value;
1093
+ }
1094
+ setValue(value, changeCheckFlag) {
1095
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
1096
+ value = this.field.$value;
1097
+ }
1098
+ this.field.$value = value;
1099
+ if (value === true) {
1100
+ this.rowElement.querySelector(`[name="${this.field.$xssName}"]`).checked = true;
1101
+ return;
1102
+ }
1103
+ if (value === false) {
1104
+ this.rowElement.querySelector(`[name="${this.field.$xssName}"]`).checked = false;
1105
+ return;
1106
+ }
1107
+ const elements = this.rowElement.querySelectorAll(this.getSelector());
1108
+ elements.forEach((ele) => {
1109
+ let radioEle = ele;
1110
+ if (radioEle.value == value) {
1111
+ radioEle.checked = true;
1112
+ } else {
1113
+ radioEle.checked = false;
1114
+ }
1115
+ });
1116
+ }
1117
+ reset() {
1118
+ this.setValue(this.defaultCheckValue, false);
1119
+ this.setDisabled(false);
1120
+ resetRowElementStyleClass(this.rowElement);
1121
+ }
1122
+ getElement() {
1123
+ return this.rowElement.querySelectorAll(this.getSelector());
1124
+ }
1125
+ focus() {
1126
+ const elements = this.getElement();
1127
+ if (elements && elements.length > 0) {
1128
+ this.getElement()[0].focus();
1129
+ }
1130
+ }
1131
+ valid() {
1132
+ const value = this.getValue();
1133
+ let validResult = true;
1134
+ if (this.field.required) {
1135
+ if (isBlank(value)) {
1136
+ validResult = { name: this.field.name, constraint: [] };
1137
+ validResult.constraint.push(RULES.REQUIRED);
1138
+ }
1139
+ }
1140
+ invalidMessage(this.field, this.rowElement, validResult);
1141
+ return validResult;
1142
+ }
1143
+ };
1144
+
1145
+ // src/renderer/PasswordRender.ts
1146
+ var PasswordRender = class extends Render {
1147
+ constructor(field, rowElement, daraForm) {
1148
+ super(daraForm, field, rowElement);
1149
+ this.mounted();
1150
+ this.setDefaultOption();
1151
+ this.setDefaultInfo();
1152
+ }
1153
+ mounted() {
1154
+ inputEvent(this.field, this.element, this);
1155
+ }
1156
+ createField() {
1157
+ const field = this.field;
1158
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1159
+ fieldContainerElement.innerHTML = `
1160
+ <div class="df-field">
1161
+ <input type="password" name="${field.$xssName}" class="form-field password help-icon" autocomplete="off" />
1162
+ </div>
1163
+ ${Render.getDescriptionTemplate(field)}
1164
+ <div class="help-message"></div>
1165
+ `;
1166
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
1167
+ }
1168
+ getValue() {
1169
+ return this.element.value;
1170
+ }
1171
+ setValue(value, changeCheckFlag) {
1172
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
1173
+ this.element.value = this.field.$value;
1174
+ return;
1175
+ }
1176
+ this.field.$value = value;
1177
+ this.element.value = value;
1178
+ }
1179
+ reset() {
1180
+ this.setDefaultInfo();
1181
+ this.setDisabled(false);
1182
+ resetRowElementStyleClass(this.rowElement);
1183
+ }
1184
+ getElement() {
1185
+ return this.element;
1186
+ }
1187
+ valid() {
1188
+ const validResult = stringValidator(this.getValue(), this.field);
1189
+ invalidMessage(this.field, this.rowElement, validResult);
1190
+ return validResult;
1191
+ }
1192
+ };
1193
+
1194
+ // src/rule/fileValidator.ts
1195
+ var fileValidator = (element, field, fileList) => {
1196
+ const result = { name: field.name, constraint: [] };
1197
+ if (field.required && fileList.length < 1) {
1198
+ result.constraint.push(RULES.REQUIRED);
1199
+ return result;
1200
+ }
1201
+ if (result.constraint.length > 0) {
1202
+ return result;
1203
+ }
1204
+ return true;
1205
+ };
1206
+
1207
+ // src/renderer/FileRender.ts
1208
+ var FileRender = class extends Render {
1209
+ constructor(field, rowElement, daraForm) {
1210
+ super(daraForm, field, rowElement);
1211
+ this.removeIds = [];
1212
+ this.uploadFiles = {};
1213
+ this.fileList = [];
1214
+ this.fileSeq = 0;
1215
+ this.element = rowElement.querySelector(`[name="${field.$xssName}"]`);
1216
+ this.fileList = field.listItem?.list || [];
1217
+ this.mounted();
1218
+ this.setDefaultOption();
1219
+ }
1220
+ mounted() {
1221
+ this.element.addEventListener("change", (e) => {
1222
+ const files = e.target?.files;
1223
+ if (files) {
1224
+ let fileList = [];
1225
+ for (let item of files) {
1226
+ fileList.push(item);
1227
+ }
1228
+ this.addFiles(fileList);
1229
+ }
1230
+ customChangeEventCall(this.field, e, this, this.fileList);
1231
+ this.valid();
1232
+ });
1233
+ this.fileList.forEach((file) => {
1234
+ file.$seq = this.fileSeq += 1;
1235
+ });
1236
+ this.setFileList(this.fileList);
1237
+ }
1238
+ createField() {
1239
+ const field = this.field;
1240
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1241
+ fieldContainerElement.innerHTML = `
1242
+ <div class="df-field">
1243
+ <span class="file-wrapper">
1244
+ <label class="file-label">
1245
+ <input type="file" name="${field.$xssName}" class="form-field file" multiple />
1246
+ ${Lanauage_default.getMessage("fileButton")}
1247
+ </label>
1248
+ <i class="daracl-icon help-icon"></i>
1249
+ </span>
1250
+ </div>
1251
+ ${Render.getDescriptionTemplate(field)}
1252
+ <div class="daracl-file-list"></div>
1253
+ <div class="help-message"></div>
1254
+ `;
1255
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
1256
+ }
1257
+ addFiles(files) {
1258
+ let addFlag = false;
1259
+ const newFiles = [];
1260
+ for (let item of files) {
1261
+ const fileCheckList = this.fileList.filter((fileItem) => fileItem.fileName == item.name && fileItem.fileSize == item.size && fileItem.lastModified == item.lastModified);
1262
+ if (fileCheckList.length > 0)
1263
+ continue;
1264
+ this.fileSeq += 1;
1265
+ this.uploadFiles[this.fileSeq] = item;
1266
+ let newFileInfo = {
1267
+ fileName: item.name,
1268
+ $seq: this.fileSeq,
1269
+ fileSize: item.size,
1270
+ lastModified: item.lastModified
1271
+ };
1272
+ newFiles.push(newFileInfo);
1273
+ addFlag = true;
1274
+ }
1275
+ if (addFlag) {
1276
+ this.setFileList(newFiles);
1277
+ this.fileList.push(...newFiles);
1278
+ }
1279
+ }
1280
+ setFileList(fileList, initFlag) {
1281
+ const fileListElement = this.rowElement.querySelector(".daracl-file-list");
1282
+ if (fileListElement) {
1283
+ if (initFlag === true) {
1284
+ fileListElement.innerHTML = "";
1285
+ }
1286
+ const fileTemplateHtml = [];
1287
+ fileList.forEach((file) => {
1288
+ fileTemplateHtml.push(`
1289
+ <div class="file-item" data-seq="${file.$seq}">
1290
+ ${file.fileId ? '<span class="file-icon download"></span>' : '<span class="file-icon"></span>'} <span class="file-icon remove"></span>
1291
+ <span class="file-name">${file.fileName}</span >
1292
+ </div>`);
1293
+ });
1294
+ fileListElement.insertAdjacentHTML("beforeend", fileTemplateHtml.join(""));
1295
+ fileList.forEach((item) => {
1296
+ this.removeFileEvent(item, fileListElement);
1297
+ this.downloadFileEvent(item, fileListElement);
1298
+ });
1299
+ }
1300
+ }
1301
+ /**
1302
+ * 파일 다운로드 이벤트 처리.
1303
+ *
1304
+ * @param item
1305
+ * @param fileListElement
1306
+ */
1307
+ downloadFileEvent(item, fileListElement) {
1308
+ const ele = fileListElement.querySelector(`[data-seq="${item.$seq}"] .download`);
1309
+ if (ele) {
1310
+ ele.addEventListener("click", (evt) => {
1311
+ const fileItemElement = evt.target.closest(".file-item");
1312
+ if (fileItemElement) {
1313
+ const attrSeq = fileItemElement.getAttribute("data-seq");
1314
+ if (attrSeq) {
1315
+ const seq = parseInt(attrSeq, 10);
1316
+ const idx = this.fileList.findIndex((v) => v.$seq === seq);
1317
+ const item2 = this.fileList[idx];
1318
+ if (item2["url"]) {
1319
+ location.href = item2["url"];
1320
+ return;
1321
+ }
1322
+ if (this.field.fileDownload) {
1323
+ this.field.fileDownload.call(null, { file: item2, field: this.field });
1324
+ return;
1325
+ }
1326
+ }
1327
+ }
1328
+ });
1329
+ }
1330
+ }
1331
+ /**
1332
+ * 파일 삭제 처리.
1333
+ *
1334
+ * @param item
1335
+ * @param fileListElement
1336
+ */
1337
+ removeFileEvent(item, fileListElement) {
1338
+ const ele = fileListElement.querySelector(`[data-seq="${item.$seq}"] .remove`);
1339
+ if (ele) {
1340
+ ele.addEventListener("click", (evt) => {
1341
+ const fileItemElement = evt.target.closest(".file-item");
1342
+ if (fileItemElement) {
1343
+ const attrSeq = fileItemElement.getAttribute("data-seq");
1344
+ if (attrSeq) {
1345
+ const seq = parseInt(attrSeq, 10);
1346
+ const removeIdx = this.fileList.findIndex((v) => v.$seq === seq);
1347
+ const removeItem = this.fileList[removeIdx];
1348
+ this.fileList.splice(removeIdx, 1);
1349
+ delete this.uploadFiles[seq];
1350
+ fileItemElement.remove();
1351
+ if (removeItem.fileId) {
1352
+ this.removeIds.push(removeItem.fileId);
1353
+ }
1354
+ }
1355
+ }
1356
+ this.valid();
1357
+ });
1358
+ }
1359
+ }
1360
+ getValue() {
1361
+ return {
1362
+ uploadFile: Object.values(this.uploadFiles),
1363
+ removeIds: this.removeIds
1364
+ };
1365
+ }
1366
+ setValueItems(value) {
1367
+ this.fileList = [];
1368
+ this.uploadFiles = [];
1369
+ this.removeIds = [];
1370
+ for (let file of value) {
1371
+ file.$seq = this.fileSeq += 1;
1372
+ this.fileList.push(file);
1373
+ }
1374
+ this.setFileList(this.fileList, true);
1375
+ }
1376
+ setValue(value) {
1377
+ if (isArray(value)) {
1378
+ this.setValueItems(value);
1379
+ }
1380
+ this.element.value = "";
1381
+ }
1382
+ reset() {
1383
+ this.setValue("");
1384
+ this.setValueItems([]);
1385
+ resetRowElementStyleClass(this.rowElement);
1386
+ }
1387
+ getElement() {
1388
+ return this.element;
1389
+ }
1390
+ valid() {
1391
+ const validResult = fileValidator(this.element, this.field, this.fileList);
1392
+ invalidMessage(this.field, this.rowElement, validResult);
1393
+ return validResult;
1394
+ }
1395
+ };
1396
+
1397
+ // src/renderer/CustomRender.ts
1398
+ var CustomRender = class extends Render {
1399
+ constructor(field, rowElement, daraForm) {
1400
+ super(daraForm, field, rowElement);
1401
+ if (field.renderer) {
1402
+ this.customFunction = field.renderer;
1403
+ this.mounted();
1404
+ this.setDefaultOption();
1405
+ this.setDefaultInfo();
1406
+ } else {
1407
+ this.customFunction = {};
1408
+ }
1409
+ }
1410
+ mounted() {
1411
+ if (this.customFunction.mounted) {
1412
+ this.customFunction.mounted.call(this, this.field, this.rowElement);
1413
+ }
1414
+ }
1415
+ static isDataRender() {
1416
+ return false;
1417
+ }
1418
+ createField() {
1419
+ const field = this.field;
1420
+ const fieldTemplate = isEmpty(field.template) ? "" : isString(field.template) ? field.template : field.template();
1421
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1422
+ fieldContainerElement.innerHTML = ` <div class="df-field">
1423
+ ${fieldTemplate}
1424
+ </div>
1425
+ ${Render.getDescriptionTemplate(field)}
1426
+ <div class="help-message"></div>`;
1427
+ }
1428
+ getValue() {
1429
+ if (this.customFunction.getValue) {
1430
+ return this.customFunction.getValue.call(this, this.field, this.rowElement);
1431
+ }
1432
+ return "";
1433
+ }
1434
+ setValue(value, changeCheckFlag) {
1435
+ if (this.customFunction.setValue) {
1436
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
1437
+ value = this.field.$value;
1438
+ }
1439
+ this.customFunction.setValue.call(this, value, this.field, this.rowElement);
1440
+ }
1441
+ this.field.$value = value;
1442
+ }
1443
+ reset() {
1444
+ this.setDefaultInfo();
1445
+ resetRowElementStyleClass(this.rowElement);
1446
+ }
1447
+ getElement() {
1448
+ if (this.customFunction.getElement) {
1449
+ return this.customFunction.getElement.call(this, this.field, this.rowElement);
1450
+ }
1451
+ return null;
1452
+ }
1453
+ valid() {
1454
+ if (this.customFunction.valid) {
1455
+ const validResult2 = this.customFunction.valid.call(this, this.field, this.rowElement);
1456
+ invalidMessage(this.field, this.rowElement, validResult2);
1457
+ return;
1458
+ }
1459
+ const validResult = stringValidator(this.getValue(), this.field);
1460
+ invalidMessage(this.field, this.rowElement, validResult);
1461
+ return validResult;
1462
+ }
1463
+ /**
1464
+ * focus
1465
+ */
1466
+ focus() {
1467
+ if (this.customFunction.focus) {
1468
+ this.customFunction.focus.call(this, this.field, this.rowElement);
1469
+ }
1470
+ }
1471
+ };
1472
+
1473
+ // src/renderer/GroupRender.ts
1474
+ var GroupRender = class extends Render {
1475
+ constructor(field, rowElement, daraForm) {
1476
+ super(daraForm, field, rowElement);
1477
+ }
1478
+ mounted() {
1479
+ }
1480
+ static isDataRender() {
1481
+ return false;
1482
+ }
1483
+ createField() {
1484
+ return "";
1485
+ }
1486
+ getValue() {
1487
+ return null;
1488
+ }
1489
+ setValue(value) {
1490
+ }
1491
+ reset() {
1492
+ }
1493
+ getElement() {
1494
+ return this.rowElement;
1495
+ }
1496
+ valid() {
1497
+ return true;
1498
+ }
1499
+ addChildField(element) {
1500
+ let addContainer = this.rowElement.querySelector(".df-field-container");
1501
+ if (addContainer) {
1502
+ addContainer.append(element);
1503
+ } else {
1504
+ this.rowElement.append(element);
1505
+ }
1506
+ }
1507
+ focus() {
1508
+ }
1509
+ };
1510
+
1511
+ // src/renderer/HiddenRender.ts
1512
+ var HiddenRender = class extends Render {
1513
+ constructor(field, rowElement, daraForm) {
1514
+ super(daraForm, field, rowElement);
1515
+ this.field.$value = field.defaultValue;
1516
+ }
1517
+ mounted() {
1518
+ }
1519
+ createField() {
1520
+ return ``;
1521
+ }
1522
+ getValue() {
1523
+ return this.field.$value;
1524
+ }
1525
+ setValue(value) {
1526
+ this.field.$value = value;
1527
+ }
1528
+ reset() {
1529
+ this.setValue(this.field.defaultValue);
1530
+ }
1531
+ getElement() {
1532
+ return;
1533
+ }
1534
+ valid() {
1535
+ return true;
1536
+ }
1537
+ };
1538
+
1539
+ // src/renderer/ButtonRender.ts
1540
+ var ButtonRender = class extends Render {
1541
+ constructor(field, rowElement, daraForm) {
1542
+ super(daraForm, field, rowElement);
1543
+ this.mounted();
1544
+ this.setDefaultOption();
1545
+ }
1546
+ mounted() {
1547
+ this.rowElement.querySelector(`#${this.field.$key}`)?.addEventListener("click", (evt) => {
1548
+ if (this.field.onClick) {
1549
+ this.field.onClick.call(null, this.field);
1550
+ }
1551
+ });
1552
+ }
1553
+ static isDataRender() {
1554
+ return false;
1555
+ }
1556
+ createField() {
1557
+ const field = this.field;
1558
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1559
+ fieldContainerElement.innerHTML = `
1560
+ <button type="button" id="${field.$key}" class="df-btn">${field.label}</button> ${Render.getDescriptionTemplate(field)}
1561
+ `;
1562
+ }
1563
+ getValue() {
1564
+ return "";
1565
+ }
1566
+ setValue(value) {
1567
+ }
1568
+ reset() {
1569
+ this.setDisabled(false);
1570
+ }
1571
+ getElement() {
1572
+ return null;
1573
+ }
1574
+ valid() {
1575
+ return true;
1576
+ }
1577
+ };
1578
+
1579
+ // src/renderer/RangeRender.ts
1580
+ var RangeRender = class extends Render {
1581
+ constructor(field, rowElement, daraForm) {
1582
+ super(daraForm, field, rowElement);
1583
+ this.rangeNumElement = rowElement.querySelector(".range-num");
1584
+ this.mounted();
1585
+ this.setDefaultOption();
1586
+ this.setDefaultInfo();
1587
+ }
1588
+ mounted() {
1589
+ this.element.addEventListener("input", (e) => {
1590
+ this.rangeNumElement.innerHTML = e.target.value;
1591
+ this.element.setAttribute("title", e.target.value);
1592
+ customChangeEventCall(this.field, e, this, this.getValue());
1593
+ this.valid();
1594
+ });
1595
+ }
1596
+ createField() {
1597
+ const field = this.field;
1598
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
1599
+ fieldContainerElement.innerHTML = `
1600
+ <div class="df-field">
1601
+ <span class="range-num">${field.defaultValue ? field.defaultValue : 0}</span>
1602
+ <input type="range" name="${field.$xssName}" class="form-field range help-icon" min="${field.rule.minimum}" max="${field.rule.maximum}"/>
1603
+ </div>
1604
+ ${Render.getDescriptionTemplate(field)}
1605
+ <div class="help-message"></div>
1606
+ `;
1607
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
1608
+ }
1609
+ getValue() {
1610
+ return this.element.value;
1611
+ }
1612
+ setValue(value, changeCheckFlag) {
1613
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
1614
+ this.element.value = this.field.$value;
1615
+ return;
1616
+ }
1617
+ this.field.$value = value;
1618
+ this.element.value = value;
1619
+ }
1620
+ reset() {
1621
+ this.setDefaultInfo();
1622
+ this.setDisabled(false);
1623
+ resetRowElementStyleClass(this.rowElement);
1624
+ }
1625
+ getElement() {
1626
+ return this.element;
1627
+ }
1628
+ valid() {
1629
+ const validResult = numberValidator(this.getValue(), this.field);
1630
+ invalidMessage(this.field, this.rowElement, validResult);
1631
+ return validResult;
1632
+ }
1633
+ };
1634
+
1635
+ // node_modules/@daracl/datetimepicker/dist/index.js
1636
+ var __getOwnPropNames = Object.getOwnPropertyNames;
1637
+ var __esm = (fn, res) => function __init() {
1638
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
1639
+ };
1640
+ var __commonJS = (cb, mod) => function __require() {
1641
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
1642
+ };
1643
+ var localeMessage;
1644
+ var Language;
1645
+ var Lanauage_default2;
1646
+ var init_Lanauage = __esm({
1647
+ "src/Lanauage.ts"() {
1648
+ "use strict";
1649
+ localeMessage = {
1650
+ year: "Year",
1651
+ month: "Month",
1652
+ day: "Day",
1653
+ am: "AM",
1654
+ pm: "PM",
1655
+ today: "Today",
1656
+ ok: "Ok",
1657
+ months: {
1658
+ full: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1659
+ abbr: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
1660
+ },
1661
+ weeks: {
1662
+ full: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
1663
+ abbr: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
1664
+ }
1665
+ };
1666
+ Language = class {
1667
+ constructor() {
1668
+ this.lang = localeMessage;
1669
+ }
1670
+ setDefaultMessage(lang) {
1671
+ localeMessage = Object.assign(localeMessage, lang);
1672
+ }
1673
+ /**
1674
+ * 다국어 메시지 등록
1675
+ *
1676
+ * @public
1677
+ * @param {?Message} [lang] 둥록할 메시지
1678
+ */
1679
+ set(lang) {
1680
+ this.lang = Object.assign({}, localeMessage, lang);
1681
+ }
1682
+ /**
1683
+ * 메시지 얻기
1684
+ *
1685
+ * @public
1686
+ * @param {string} messageKey 메시지 키
1687
+ * @returns {*}
1688
+ */
1689
+ getMessage(messageKey) {
1690
+ return this.lang[messageKey];
1691
+ }
1692
+ getMonthsMessage(idx, mode = "abbr") {
1693
+ return this.lang.months[mode][idx] || "";
1694
+ }
1695
+ getWeeksMessage(idx, mode = "abbr") {
1696
+ return this.lang.weeks[mode][idx] || "";
1697
+ }
1698
+ getMonthsIdx(val, mode = "abbr") {
1699
+ return mode == "full" ? this.lang.months.full.indexOf(val) : this.lang.months.abbr.indexOf(val);
1700
+ }
1701
+ getWeeksIdx(val, mode = "abbr") {
1702
+ return mode == "full" ? this.lang.weeks.full.indexOf(val) : this.lang.weeks.abbr.indexOf(val);
1703
+ }
1704
+ };
1705
+ Lanauage_default2 = new Language();
1706
+ }
1707
+ });
1708
+ var EXPRESSIONS_FORMAT;
1709
+ var MAX_CHAR_LENGTH;
1710
+ var DEFAULT_FORMAT;
1711
+ var DAY_STYLE_CLASS;
1712
+ var DateViewMode;
1713
+ var init_constants = __esm({
1714
+ "src/constants.ts"() {
1715
+ "use strict";
1716
+ EXPRESSIONS_FORMAT = ["YY", "YYYY", "MMMM", "MMM", "MM", "M", "dddd", "ddd", "dd", "d", "DD", "D", "S", "HH", "H", "hh", "h", "mm", "m", "ss", "s", "SSS", "zzzz", "zzz", "zz", "z", "a", "A"];
1717
+ MAX_CHAR_LENGTH = 0;
1718
+ DEFAULT_FORMAT = {
1719
+ year: "YYYY",
1720
+ month: "YYYY-MM",
1721
+ date: "YYYY-MM-DD",
1722
+ time: "HH:mm",
1723
+ datetime: "YYYY-MM-DD HH:mm"
1724
+ };
1725
+ DAY_STYLE_CLASS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
1726
+ DateViewMode = /* @__PURE__ */ ((DateViewMode2) => {
1727
+ DateViewMode2["year"] = "year";
1728
+ DateViewMode2["month"] = "month";
1729
+ DateViewMode2["date"] = "date";
1730
+ DateViewMode2["datetime"] = "datetime";
1731
+ DateViewMode2["time"] = "time";
1732
+ return DateViewMode2;
1733
+ })(DateViewMode || {});
1734
+ EXPRESSIONS_FORMAT.forEach((item) => {
1735
+ MAX_CHAR_LENGTH = Math.max(item.length, MAX_CHAR_LENGTH);
1736
+ });
1737
+ }
1738
+ });
1739
+ var xssFilter2;
1740
+ var utils_default;
1741
+ var init_utils = __esm({
1742
+ "src/util/utils.ts"() {
1743
+ "use strict";
1744
+ xssFilter2 = {
1745
+ "&": "&amp;",
1746
+ "<": "&lt;",
1747
+ ">": "&gt;",
1748
+ '"': "&quot;",
1749
+ "'": "&#39;"
1750
+ };
1751
+ utils_default = {
1752
+ replace(str) {
1753
+ let returnText = str;
1754
+ if (returnText) {
1755
+ Object.keys(xssFilter2).forEach((key) => {
1756
+ returnText = returnText.replaceAll(key, xssFilter2[key]);
1757
+ });
1758
+ }
1759
+ return returnText;
1760
+ },
1761
+ unReplace(inputText) {
1762
+ let returnText = inputText;
1763
+ if (returnText) {
1764
+ Object.keys(xssFilter2).forEach((key) => {
1765
+ returnText = returnText.replaceAll(xssFilter2[key], key);
1766
+ });
1767
+ }
1768
+ return returnText;
1769
+ },
1770
+ unFieldName(fieldName) {
1771
+ if (fieldName) {
1772
+ return this.unReplace(fieldName).replaceAll('"', '\\"');
1773
+ }
1774
+ return "";
1775
+ },
1776
+ isBlank(value) {
1777
+ if (value === null)
1778
+ return true;
1779
+ if (value === "")
1780
+ return true;
1781
+ if (typeof value === "undefined")
1782
+ return true;
1783
+ if (typeof value === "string" && (value === "" || value.replace(/\s/g, "") === ""))
1784
+ return true;
1785
+ return false;
1786
+ },
1787
+ isUndefined(value) {
1788
+ return typeof value === "undefined";
1789
+ },
1790
+ isFunction(value) {
1791
+ return typeof value === "function";
1792
+ },
1793
+ isString(value) {
1794
+ return typeof value === "string";
1795
+ },
1796
+ isNumber(value) {
1797
+ if (this.isBlank(value)) {
1798
+ return false;
1799
+ }
1800
+ return !isNaN(value);
1801
+ },
1802
+ isArray(value) {
1803
+ return Array.isArray(value);
1804
+ },
1805
+ getHashCode(str) {
1806
+ let hash = 0;
1807
+ if (str.length == 0)
1808
+ return hash;
1809
+ for (let i = 0; i < str.length; i++) {
1810
+ let tmpChar = str.charCodeAt(i);
1811
+ hash = (hash << 5) - hash + tmpChar;
1812
+ hash = hash & hash;
1813
+ }
1814
+ return hash;
1815
+ },
1816
+ pad(str, length) {
1817
+ str = String(str);
1818
+ while (str.length < length) {
1819
+ str = "0" + str;
1820
+ }
1821
+ return str;
1822
+ },
1823
+ closestElement(el, checkElement) {
1824
+ let currentEl = el;
1825
+ while (currentEl) {
1826
+ if (currentEl == checkElement) {
1827
+ return true;
1828
+ }
1829
+ currentEl = currentEl.parentElement;
1830
+ }
1831
+ return false;
1832
+ }
1833
+ };
1834
+ }
1835
+ });
1836
+ function getH(date) {
1837
+ let hour = date.getHours();
1838
+ if (hour > 12) {
1839
+ hour -= 12;
1840
+ } else if (hour < 1) {
1841
+ hour = 12;
1842
+ }
1843
+ return hour;
1844
+ }
1845
+ function getMeridiem(date, isUpper, isShort) {
1846
+ const hour = date.getHours();
1847
+ let m = hour < 12 ? "am" : "pm";
1848
+ m = Lanauage_default2.getMessage(m);
1849
+ m = isUpper ? m.toUpperCase() : m;
1850
+ return m;
1851
+ }
1852
+ var format_default;
1853
+ var expressionsFunction;
1854
+ var init_format = __esm({
1855
+ "src/format/index.ts"() {
1856
+ "use strict";
1857
+ init_Lanauage();
1858
+ init_constants();
1859
+ init_utils();
1860
+ format_default = (date, format) => {
1861
+ format = format || "YYYY-MM-DD";
1862
+ const len = format.length;
1863
+ let result = [];
1864
+ for (let i = 0; i < len; ) {
1865
+ let minLen = Math.min(MAX_CHAR_LENGTH, len - i);
1866
+ let j = minLen;
1867
+ for (; j > 0; j--) {
1868
+ const v = format.substring(i, i + j);
1869
+ if (EXPRESSIONS_FORMAT.includes(v)) {
1870
+ try {
1871
+ result.push(expressionsFunction[v](date));
1872
+ } catch (e) {
1873
+ console.log(EXPRESSIONS_FORMAT.includes(v), v, e);
1874
+ }
1875
+ break;
1876
+ }
1877
+ }
1878
+ if (j < 1) {
1879
+ result.push(format.substring(i, i + 1));
1880
+ i += 1;
1881
+ } else {
1882
+ i += j;
1883
+ }
1884
+ }
1885
+ return result.join("");
1886
+ };
1887
+ expressionsFunction = {
1888
+ YY: (date) => {
1889
+ return String(date.getFullYear()).slice(-2);
1890
+ },
1891
+ YYYY: (date) => {
1892
+ return String(date.getFullYear());
1893
+ },
1894
+ M: (date) => {
1895
+ return String(date.getMonth() + 1);
1896
+ },
1897
+ MM: (date) => {
1898
+ return utils_default.pad(date.getMonth() + 1, 2);
1899
+ },
1900
+ MMM: (date) => {
1901
+ return Lanauage_default2.getMonthsMessage(date.getMonth());
1902
+ },
1903
+ MMMM: (date) => {
1904
+ return Lanauage_default2.getMonthsMessage(date.getMonth(), "full");
1905
+ },
1906
+ D: (date) => {
1907
+ return String(date.getDate());
1908
+ },
1909
+ DD: (date) => {
1910
+ return utils_default.pad(date.getDate(), 2);
1911
+ },
1912
+ d: (date) => {
1913
+ return String(date.getDate());
1914
+ },
1915
+ dd: (date) => {
1916
+ return utils_default.pad(date.getDate(), 2);
1917
+ },
1918
+ ddd: (date) => {
1919
+ return Lanauage_default2.getWeeksMessage(date.getDay());
1920
+ },
1921
+ dddd: (date) => {
1922
+ return Lanauage_default2.getWeeksMessage(date.getDay(), "full");
1923
+ },
1924
+ H: (date) => {
1925
+ return String(date.getHours());
1926
+ },
1927
+ HH: (date) => {
1928
+ return utils_default.pad(date.getHours(), 2);
1929
+ },
1930
+ h: (date) => {
1931
+ return getH(date);
1932
+ },
1933
+ hh: (date) => {
1934
+ return utils_default.pad(getH(date), 2);
1935
+ },
1936
+ a: (date) => {
1937
+ return String(date.getFullYear()).slice(-2);
1938
+ },
1939
+ A: (date) => {
1940
+ return getMeridiem(date, true, true);
1941
+ },
1942
+ m: (date) => {
1943
+ return String(date.getMinutes());
1944
+ },
1945
+ mm: (date) => {
1946
+ return utils_default.pad(date.getMinutes(), 2);
1947
+ },
1948
+ s: (date) => {
1949
+ return String(date.getSeconds());
1950
+ },
1951
+ ss: (date) => {
1952
+ return utils_default.pad(date.getSeconds(), 2);
1953
+ },
1954
+ SSS: (date) => {
1955
+ return utils_default.pad(date.getMilliseconds(), 3);
1956
+ }
1957
+ };
1958
+ }
1959
+ });
1960
+ var parser_default;
1961
+ var matchFind;
1962
+ var digitsCheck;
1963
+ var word;
1964
+ var expressionsFunction2;
1965
+ var init_parser = __esm({
1966
+ "src/util/parser.ts"() {
1967
+ "use strict";
1968
+ init_Lanauage();
1969
+ init_constants();
1970
+ parser_default = (dateStr, format) => {
1971
+ if (dateStr.length > 1e3) {
1972
+ return null;
1973
+ }
1974
+ format = format || DEFAULT_FORMAT.date;
1975
+ const dateInfo = {
1976
+ year: (/* @__PURE__ */ new Date()).getFullYear(),
1977
+ month: 0,
1978
+ day: 1,
1979
+ hour: 0,
1980
+ minute: 0,
1981
+ second: 0,
1982
+ millisecond: 0,
1983
+ isPm: false,
1984
+ isH: false,
1985
+ charIdx: 0
1986
+ };
1987
+ const len = format.length;
1988
+ let startIdx = 0;
1989
+ for (let i = 0; i < len; ) {
1990
+ let minLen = Math.min(MAX_CHAR_LENGTH, len - i);
1991
+ let j = minLen;
1992
+ for (; j > 0; j--) {
1993
+ const v = format.substring(i, i + j);
1994
+ if (EXPRESSIONS_FORMAT.includes(v)) {
1995
+ const expInfo = expressionsFunction2[v];
1996
+ const val = matchFind(dateStr.substring(startIdx), expInfo[0]);
1997
+ expInfo[1](dateInfo, val);
1998
+ startIdx += val.length;
1999
+ break;
2000
+ }
2001
+ }
2002
+ if (j < 1) {
2003
+ i += 1;
2004
+ startIdx += 1;
2005
+ } else {
2006
+ i += j;
2007
+ }
2008
+ }
2009
+ if (dateInfo.hour != null && !dateInfo.isH) {
2010
+ if (dateInfo.isPm && +dateInfo.hour !== 12) {
2011
+ dateInfo.hour = +dateInfo.hour + 12;
2012
+ } else if (!dateInfo.isPm && +dateInfo.hour === 12) {
2013
+ dateInfo.hour = 0;
2014
+ }
2015
+ }
2016
+ let date;
2017
+ date = new Date(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute, dateInfo.second, dateInfo.millisecond);
2018
+ return date;
2019
+ };
2020
+ matchFind = (val, regexp2) => {
2021
+ const match = regexp2.exec(val);
2022
+ return match == null ? "" : match[0];
2023
+ };
2024
+ digitsCheck = {
2025
+ twoOptional: /\d\d?/,
2026
+ two: /\d\d/,
2027
+ three: /\d{3}/,
2028
+ four: /\d{4}/
2029
+ };
2030
+ word = /[^\s]+/;
2031
+ expressionsFunction2 = {
2032
+ YY: [
2033
+ digitsCheck["two"],
2034
+ (dateInfo, val) => {
2035
+ dateInfo.year = +(("" + (/* @__PURE__ */ new Date()).getFullYear()).substring(0, 2) + val);
2036
+ return dateInfo;
2037
+ }
2038
+ ],
2039
+ YYYY: [
2040
+ digitsCheck["four"],
2041
+ (dateInfo, val) => {
2042
+ dateInfo.year = +val;
2043
+ return dateInfo;
2044
+ }
2045
+ ],
2046
+ M: [
2047
+ digitsCheck["twoOptional"],
2048
+ (dateInfo, val) => {
2049
+ dateInfo.month = +val - 1;
2050
+ return dateInfo;
2051
+ }
2052
+ ],
2053
+ MM: [
2054
+ digitsCheck["two"],
2055
+ (dateInfo, val) => {
2056
+ dateInfo.month = +val - 1;
2057
+ return dateInfo;
2058
+ }
2059
+ ],
2060
+ MMM: [
2061
+ word,
2062
+ (dateInfo, val) => {
2063
+ dateInfo.month = Lanauage_default2.getMonthsIdx(val, "abbr");
2064
+ return dateInfo;
2065
+ }
2066
+ ],
2067
+ MMMM: [
2068
+ word,
2069
+ (dateInfo, val) => {
2070
+ dateInfo.month = Lanauage_default2.getMonthsIdx(val, "full");
2071
+ return dateInfo;
2072
+ }
2073
+ ],
2074
+ D: [
2075
+ digitsCheck["twoOptional"],
2076
+ (dateInfo, val) => {
2077
+ dateInfo.day = +val;
2078
+ return dateInfo;
2079
+ }
2080
+ ],
2081
+ DD: [
2082
+ digitsCheck["two"],
2083
+ (dateInfo, val) => {
2084
+ dateInfo.day = +val;
2085
+ return dateInfo;
2086
+ }
2087
+ ],
2088
+ d: [
2089
+ digitsCheck["twoOptional"],
2090
+ (dateInfo, val) => {
2091
+ dateInfo.day = +val;
2092
+ return dateInfo;
2093
+ }
2094
+ ],
2095
+ dd: [
2096
+ digitsCheck["two"],
2097
+ (dateInfo, val) => {
2098
+ dateInfo.day = +val;
2099
+ return dateInfo;
2100
+ }
2101
+ ],
2102
+ ddd: [
2103
+ word,
2104
+ (dateInfo, val) => {
2105
+ return dateInfo;
2106
+ }
2107
+ ],
2108
+ dddd: [
2109
+ word,
2110
+ (dateInfo, val) => {
2111
+ return dateInfo;
2112
+ }
2113
+ ],
2114
+ H: [
2115
+ digitsCheck["twoOptional"],
2116
+ (dateInfo, val) => {
2117
+ dateInfo.hour = +val;
2118
+ dateInfo.isH = true;
2119
+ return dateInfo;
2120
+ }
2121
+ ],
2122
+ HH: [
2123
+ digitsCheck["two"],
2124
+ (dateInfo, val) => {
2125
+ dateInfo.hour = +val;
2126
+ dateInfo.isH = true;
2127
+ return dateInfo;
2128
+ }
2129
+ ],
2130
+ h: [
2131
+ digitsCheck["twoOptional"],
2132
+ (dateInfo, val) => {
2133
+ dateInfo.hour = +val;
2134
+ return dateInfo;
2135
+ }
2136
+ ],
2137
+ hh: [
2138
+ digitsCheck["two"],
2139
+ (dateInfo, val) => {
2140
+ dateInfo.hour = +val;
2141
+ return dateInfo;
2142
+ }
2143
+ ],
2144
+ a: [
2145
+ word,
2146
+ (dateInfo, val) => {
2147
+ if (Lanauage_default2.getMessage("am") != val.toLowerCase()) {
2148
+ dateInfo.isPm = true;
2149
+ }
2150
+ return dateInfo;
2151
+ }
2152
+ ],
2153
+ A: [
2154
+ word,
2155
+ (dateInfo, val) => {
2156
+ if (Lanauage_default2.getMessage("am") != val.toLowerCase()) {
2157
+ dateInfo.isPm = true;
2158
+ }
2159
+ return dateInfo;
2160
+ }
2161
+ ],
2162
+ m: [
2163
+ digitsCheck["twoOptional"],
2164
+ (dateInfo, val) => {
2165
+ dateInfo.minute = +val;
2166
+ return dateInfo;
2167
+ }
2168
+ ],
2169
+ mm: [
2170
+ digitsCheck["two"],
2171
+ (dateInfo, val) => {
2172
+ dateInfo.minute = +val;
2173
+ return dateInfo;
2174
+ }
2175
+ ],
2176
+ s: [
2177
+ digitsCheck["twoOptional"],
2178
+ (dateInfo, val) => {
2179
+ dateInfo.second = +val;
2180
+ return dateInfo;
2181
+ }
2182
+ ],
2183
+ ss: [
2184
+ digitsCheck["two"],
2185
+ (dateInfo, val) => {
2186
+ dateInfo.second = +val;
2187
+ return dateInfo;
2188
+ }
2189
+ ],
2190
+ SSS: [
2191
+ digitsCheck["three"],
2192
+ (dateInfo, val) => {
2193
+ dateInfo.millisecond = +val;
2194
+ return dateInfo;
2195
+ }
2196
+ ]
2197
+ };
2198
+ }
2199
+ });
2200
+ var DaraDate;
2201
+ var init_DaraDate = __esm({
2202
+ "src/DaraDate.ts"() {
2203
+ "use strict";
2204
+ init_format();
2205
+ DaraDate = class _DaraDate {
2206
+ constructor(dt) {
2207
+ this.date = dt;
2208
+ }
2209
+ setYear(num) {
2210
+ this.date.setFullYear(num);
2211
+ return this;
2212
+ }
2213
+ addYear(num) {
2214
+ this.date.setFullYear(this.date.getFullYear() + num);
2215
+ return this;
2216
+ }
2217
+ addMonth(num) {
2218
+ this.date.setMonth(this.date.getMonth() + num);
2219
+ return this;
2220
+ }
2221
+ setMonth(num) {
2222
+ this.date.setMonth(num);
2223
+ return this;
2224
+ }
2225
+ setDate(num) {
2226
+ this.date.setDate(num);
2227
+ return this;
2228
+ }
2229
+ addDate(num) {
2230
+ this.date.setDate(this.date.getDate() + num);
2231
+ return this;
2232
+ }
2233
+ addWeek(num) {
2234
+ this.date.setDate(this.date.getDate() + num * 7);
2235
+ return this;
2236
+ }
2237
+ addHours(num) {
2238
+ this.date.setHours(this.date.getHours() + num);
2239
+ return this;
2240
+ }
2241
+ setHour(num) {
2242
+ this.date.setHours(num);
2243
+ return this;
2244
+ }
2245
+ addMinutes(num) {
2246
+ this.date.setMinutes(this.date.getMinutes() + num);
2247
+ return this;
2248
+ }
2249
+ setMinutes(num) {
2250
+ this.date.setMinutes(num);
2251
+ return this;
2252
+ }
2253
+ addSeconds(num) {
2254
+ this.date.setSeconds(this.date.getSeconds() + num);
2255
+ return this;
2256
+ }
2257
+ addMilliseconds(num) {
2258
+ this.date.setMilliseconds(this.date.getMilliseconds() + num);
2259
+ return this;
2260
+ }
2261
+ compare(date) {
2262
+ if (this.date.valueOf() < date.valueOf()) {
2263
+ return -1;
2264
+ } else if (this.date.valueOf() > date.valueOf()) {
2265
+ return 1;
2266
+ }
2267
+ return 0;
2268
+ }
2269
+ getYear() {
2270
+ return this.date.getFullYear();
2271
+ }
2272
+ getMonth() {
2273
+ return this.date.getMonth() + 1;
2274
+ }
2275
+ getDate() {
2276
+ return this.date.getDate();
2277
+ }
2278
+ getDay() {
2279
+ return this.date.getDay();
2280
+ }
2281
+ getTime() {
2282
+ return this.date.getTime();
2283
+ }
2284
+ format(format) {
2285
+ return format_default(this.date, format);
2286
+ }
2287
+ clone() {
2288
+ return new _DaraDate(new Date(this.date.valueOf()));
2289
+ }
2290
+ };
2291
+ }
2292
+ });
2293
+ function hiddenElement() {
2294
+ if (document.getElementById("hiddenDaraDatetimeElement") == null) {
2295
+ document.querySelector("body")?.insertAdjacentHTML("beforeend", `<div id="hiddenDaraDatetimeElement" class="daracl-datetime-hidden"></div>`);
2296
+ }
2297
+ return document.getElementById("hiddenDaraDatetimeElement");
2298
+ }
2299
+ function getDocSize() {
2300
+ return {
2301
+ clientHeight: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
2302
+ clientWidth: Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
2303
+ };
2304
+ }
2305
+ var DEFAULT_OPTIONS;
2306
+ var daraDatetimeIdx;
2307
+ var DateTimePicker;
2308
+ var init_DateTimePicker = __esm({
2309
+ "src/DateTimePicker.ts"() {
2310
+ "use strict";
2311
+ init_format();
2312
+ init_parser();
2313
+ init_Lanauage();
2314
+ init_utils();
2315
+ init_DaraDate();
2316
+ init_constants();
2317
+ DEFAULT_OPTIONS = {
2318
+ inline: false,
2319
+ // layer or innerhtml
2320
+ weekStartDay: 0,
2321
+ initialDate: "",
2322
+ autoClose: true,
2323
+ isRTL: false,
2324
+ mode: "date",
2325
+ enableTodayBtn: true,
2326
+ showMonthAfterYear: false,
2327
+ format: "",
2328
+ zIndex: 1e3,
2329
+ minDate: "",
2330
+ maxDate: "",
2331
+ beforeDrawDate: (dt) => {
2332
+ return {
2333
+ check: false,
2334
+ style: "",
2335
+ tooltip: ""
2336
+ };
2337
+ }
2338
+ };
2339
+ daraDatetimeIdx = 0;
2340
+ DateTimePicker = class _DateTimePicker {
2341
+ constructor(selector, options, message2) {
2342
+ this.isInput = false;
2343
+ this.isVisible = false;
2344
+ this.minYear = -1;
2345
+ this.maxYear = -1;
2346
+ this.minMonth = -1;
2347
+ this.maxMonth = -1;
2348
+ this.dayOrder = [0, 1, 2, 3, 4, 5, 6];
2349
+ this._documentClickEvent = (e) => {
2350
+ if (this.isVisible && e.target != this.targetElement && !utils_default.closestElement(e.target, this.datetimeElement)) {
2351
+ this.hide();
2352
+ }
2353
+ };
2354
+ this.options = Object.assign({}, DEFAULT_OPTIONS, options);
2355
+ daraDatetimeIdx += 1;
2356
+ let selectorElement;
2357
+ if (typeof selector === "string") {
2358
+ selectorElement = document.querySelector(selector);
2359
+ } else {
2360
+ selectorElement = selector;
2361
+ }
2362
+ if (!selectorElement) {
2363
+ throw new Error(`${selector} datetimepicker element not found`);
2364
+ }
2365
+ this._viewMode = Object.keys(DateViewMode).includes(this.options.mode) ? this.options.mode : "date";
2366
+ this.initMode = this._viewMode;
2367
+ Lanauage_default2.set(message2);
2368
+ if (this.initMode == "year") {
2369
+ this.dateFormat = this.options.format || DEFAULT_FORMAT.year;
2370
+ } else if (this.initMode == "month") {
2371
+ this.dateFormat = this.options.format || DEFAULT_FORMAT.month;
2372
+ } else if (this.initMode == "time") {
2373
+ this.dateFormat = this.options.format || DEFAULT_FORMAT.time;
2374
+ } else if (this.initMode == "datetime") {
2375
+ this.dateFormat = this.options.format || DEFAULT_FORMAT.datetime;
2376
+ } else {
2377
+ this.dateFormat = this.options.format || DEFAULT_FORMAT.date;
2378
+ }
2379
+ let viewDate;
2380
+ if (this.options.initialDate) {
2381
+ if (typeof this.options.initialDate === "string") {
2382
+ viewDate = new DaraDate(parser_default(this.options.initialDate, this.dateFormat) || /* @__PURE__ */ new Date());
2383
+ } else {
2384
+ viewDate = new DaraDate(this.options.initialDate);
2385
+ }
2386
+ } else {
2387
+ viewDate = new DaraDate(/* @__PURE__ */ new Date());
2388
+ this.options.initialDate = viewDate.format(this.dateFormat);
2389
+ }
2390
+ this.setWeekDays();
2391
+ this.todayDate = viewDate.format(DEFAULT_FORMAT.date);
2392
+ this.currentDate = viewDate;
2393
+ this.targetElement = selectorElement;
2394
+ this.minDate = this._minDate();
2395
+ this.maxDate = this._maxDate();
2396
+ if (this.options.inline) {
2397
+ this.datetimeElement = selectorElement;
2398
+ this.datetimeElement.className = `daracl-datetime-wrapper ddtp-${daraDatetimeIdx} embed`;
2399
+ } else {
2400
+ this.isInput = true;
2401
+ this.targetElement.setAttribute("value", viewDate.format(this.dateFormat));
2402
+ const datetimeElement = document.createElement("div");
2403
+ datetimeElement.className = `daracl-datetime-wrapper ddtp-${daraDatetimeIdx} layer`;
2404
+ datetimeElement.setAttribute("style", `z-index:${this.options.zIndex};`);
2405
+ hiddenElement()?.appendChild(datetimeElement);
2406
+ this.datetimeElement = datetimeElement;
2407
+ this.initTargetEvent();
2408
+ }
2409
+ this.createDatetimeTemplate();
2410
+ if (this.isTimeMode()) {
2411
+ this.hourInputEle = this.datetimeElement.querySelector(".ddtp-hour");
2412
+ this.minuteInputEle = this.datetimeElement.querySelector(".ddtp-minute");
2413
+ } else {
2414
+ this.hourInputEle = {};
2415
+ this.minuteInputEle = {};
2416
+ }
2417
+ this.changeViewMode(this._viewMode);
2418
+ this.initHeaderEvent();
2419
+ this.initDateEvent();
2420
+ this.initTimeEvent();
2421
+ }
2422
+ static {
2423
+ this.VERSION = `${APP_VERSION}`;
2424
+ }
2425
+ static {
2426
+ this.format = format_default;
2427
+ }
2428
+ static {
2429
+ this.parser = parser_default;
2430
+ }
2431
+ setWeekDays() {
2432
+ let weekStartDay = this.options.weekStartDay;
2433
+ if (weekStartDay == 0)
2434
+ return;
2435
+ if (weekStartDay < 0 || weekStartDay > 6) {
2436
+ weekStartDay = 0;
2437
+ }
2438
+ for (let i = 0; i < 7; i++) {
2439
+ let day = weekStartDay + i;
2440
+ this.dayOrder[i] = day < 7 ? day : day - 7;
2441
+ }
2442
+ }
2443
+ static create(selector, options, message2) {
2444
+ return new _DateTimePicker(selector, options, message2);
2445
+ }
2446
+ /**
2447
+ * default date format setting
2448
+ * @example
2449
+ ```
2450
+ setDefaultFormat({
2451
+ year: "YYYY",
2452
+ month: "YYYY-MM",
2453
+ date: "YYYY-MM-DD",
2454
+ time: "HH:mm",
2455
+ datetime: "YYYY-MM-DD HH:mm",
2456
+ });
2457
+ ```
2458
+ * @public
2459
+ * @static
2460
+ * @param {*} dateFormat
2461
+ */
2462
+ static setDefaultFormat(dateFormat) {
2463
+ Object.assign(DEFAULT_FORMAT, dateFormat);
2464
+ }
2465
+ _minDate() {
2466
+ let minDate = this.options.minDate;
2467
+ if (minDate != "") {
2468
+ if (typeof minDate === "string") {
2469
+ const dt = parser_default(minDate, this.dateFormat);
2470
+ if (!dt) {
2471
+ return -1;
2472
+ }
2473
+ minDate = dt;
2474
+ }
2475
+ this.minYear = minDate.getFullYear();
2476
+ this.minMonth = +(this.minYear + utils_default.pad(minDate.getMonth(), 2));
2477
+ return new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate(), 0, 0).getTime();
2478
+ }
2479
+ return -1;
2480
+ }
2481
+ _maxDate() {
2482
+ let maxDate = this.options.maxDate;
2483
+ if (maxDate != "") {
2484
+ if (typeof maxDate === "string") {
2485
+ const dt = parser_default(maxDate, this.dateFormat);
2486
+ if (!dt) {
2487
+ return -1;
2488
+ }
2489
+ maxDate = dt;
2490
+ }
2491
+ this.maxYear = maxDate.getFullYear();
2492
+ this.maxMonth = +(this.maxYear + utils_default.pad(maxDate.getMonth(), 2));
2493
+ return new Date(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate(), 23, 59).getTime();
2494
+ }
2495
+ return -1;
2496
+ }
2497
+ set viewMode(mode) {
2498
+ if (this._viewMode === mode) {
2499
+ return;
2500
+ }
2501
+ this._viewMode = mode;
2502
+ this.changeViewMode(mode);
2503
+ }
2504
+ get viewMode() {
2505
+ return this._viewMode;
2506
+ }
2507
+ /**
2508
+ * 모드 change
2509
+ * @param mode
2510
+ */
2511
+ changeViewMode(mode) {
2512
+ this.datetimeElement.querySelector(".ddtp-datetime")?.setAttribute("view-mode", mode);
2513
+ if (mode === "year") {
2514
+ this.yearDraw();
2515
+ } else if (mode === "month") {
2516
+ this.monthDraw();
2517
+ } else {
2518
+ this.dayDraw();
2519
+ }
2520
+ }
2521
+ /**
2522
+ * init header event
2523
+ *
2524
+ * @public
2525
+ */
2526
+ initHeaderEvent() {
2527
+ const isRTL = this.options.isRTL;
2528
+ this.datetimeElement.querySelector(".ddtp-move-btn.prev")?.addEventListener("click", (e) => {
2529
+ this.moveDate(isRTL ? "next" : "prev", e);
2530
+ });
2531
+ this.datetimeElement.querySelector(".ddtp-move-btn.next")?.addEventListener("click", (e) => {
2532
+ this.moveDate(isRTL ? "prev" : "next", e);
2533
+ });
2534
+ this.datetimeElement.querySelector(".ddtp-header-year")?.addEventListener("click", (e) => {
2535
+ this.viewMode = "year";
2536
+ });
2537
+ this.datetimeElement.querySelector(".ddtp-header-month")?.addEventListener("click", (e) => {
2538
+ this.viewMode = "month";
2539
+ });
2540
+ }
2541
+ /**
2542
+ * 날짜 달력 이벤트처리.
2543
+ */
2544
+ initDateEvent() {
2545
+ this.datetimeElement.querySelector(".ddtp-day-body")?.addEventListener("click", (e) => {
2546
+ const targetEle = e.target;
2547
+ if (targetEle.classList.contains("ddtp-day") || targetEle.closest(".ddtp-day")) {
2548
+ const selectDate = targetEle.getAttribute("data-day") || "1";
2549
+ const mmDD = selectDate.split(",");
2550
+ this.currentDate.setMonth(+mmDD[0] - 1);
2551
+ this.currentDate.setDate(+mmDD[1]);
2552
+ if (this.isDayDisabled(this.currentDate)) {
2553
+ return;
2554
+ }
2555
+ this.datetimeElement.querySelector(".select")?.classList.remove("select");
2556
+ targetEle.classList.add("select");
2557
+ if (this.isTimeMode()) {
2558
+ this.currentDate.setHour(+this.hourInputEle.value);
2559
+ this.currentDate.setMinutes(+this.minuteInputEle.value);
2560
+ }
2561
+ this.dateChangeEvent(e);
2562
+ }
2563
+ });
2564
+ this.datetimeElement.querySelector(".time-today")?.addEventListener("click", (e) => {
2565
+ const initDate = new DaraDate(parser_default(this.todayDate, DEFAULT_FORMAT.date) || /* @__PURE__ */ new Date());
2566
+ this.currentDate.setYear(initDate.getYear());
2567
+ this.currentDate.setMonth(initDate.getMonth() - 1);
2568
+ this.currentDate.setDate(initDate.getDate());
2569
+ this.changeViewMode(this.initMode);
2570
+ });
2571
+ }
2572
+ isTimeMode() {
2573
+ return this._viewMode === "time" || this._viewMode === "datetime";
2574
+ }
2575
+ /**
2576
+ * 시간 분 설정 이벤트 처리.
2577
+ *
2578
+ * @public
2579
+ */
2580
+ initTimeEvent() {
2581
+ if (!this.isTimeMode())
2582
+ return;
2583
+ let hh = this.currentDate.format("HH");
2584
+ const hourInputEle = this.datetimeElement.querySelector(".ddtp-hour");
2585
+ const hourRangeEle = this.datetimeElement.querySelector(".ddtp-hour-range");
2586
+ hourInputEle.value = hh;
2587
+ hourRangeEle.value = hh;
2588
+ hourInputEle.addEventListener("input", (e) => {
2589
+ const targetElement = e.target;
2590
+ const addVal = utils_default.pad(targetElement.value, 2);
2591
+ hourInputEle.value = addVal;
2592
+ hourRangeEle.value = addVal;
2593
+ });
2594
+ hourRangeEle.addEventListener("input", (e) => {
2595
+ const targetElement = e.target;
2596
+ hourInputEle.value = utils_default.pad(targetElement.value, 2);
2597
+ });
2598
+ let mm = this.currentDate.format("mm");
2599
+ const minuteInputEle = this.datetimeElement.querySelector(".ddtp-minute");
2600
+ const minuteRangeEle = this.datetimeElement.querySelector(".ddtp-minute-range");
2601
+ minuteInputEle.value = mm;
2602
+ minuteRangeEle.value = mm;
2603
+ minuteInputEle.addEventListener("input", (e) => {
2604
+ const targetElement = e.target;
2605
+ const addVal = utils_default.pad(targetElement.value, 2);
2606
+ minuteInputEle.value = addVal;
2607
+ minuteRangeEle.value = addVal;
2608
+ });
2609
+ minuteRangeEle.addEventListener("input", (e) => {
2610
+ const targetElement = e.target;
2611
+ minuteInputEle.value = utils_default.pad(targetElement.value, 2);
2612
+ });
2613
+ this.datetimeElement.querySelector(".time-select")?.addEventListener("click", (e) => {
2614
+ this.currentDate.setHour(+hourInputEle.value);
2615
+ this.currentDate.setMinutes(+minuteInputEle.value);
2616
+ this.dateChangeEvent(e);
2617
+ });
2618
+ }
2619
+ /**
2620
+ * 날짜 이동
2621
+ * @param moveMode // 앞뒤 이동 prev, next
2622
+ * @returns
2623
+ */
2624
+ moveDate(moveMode, e) {
2625
+ if (this._viewMode === "date" || this._viewMode === "datetime") {
2626
+ this.currentDate.setDate(1);
2627
+ this.currentDate.addMonth("prev" === moveMode ? -1 : 1);
2628
+ this.dayDraw();
2629
+ return;
2630
+ }
2631
+ if (this._viewMode === "month") {
2632
+ this.currentDate.setDate(1);
2633
+ this.currentDate.addYear("prev" === moveMode ? -1 : 1);
2634
+ this.monthDraw();
2635
+ return;
2636
+ }
2637
+ if (this._viewMode === "year") {
2638
+ this.currentDate.setDate(1);
2639
+ this.currentDate.addYear("prev" === moveMode ? -16 : 16);
2640
+ this.yearDraw();
2641
+ }
2642
+ }
2643
+ /**
2644
+ * get date value
2645
+ *
2646
+ * @returns
2647
+ */
2648
+ getDateValue() {
2649
+ return this.currentDate.format(this.dateFormat);
2650
+ }
2651
+ /**
2652
+ * 옵션 셋팅
2653
+ * @static
2654
+ * @param {DateTimePickerOptions} options
2655
+ */
2656
+ static setOptions(options) {
2657
+ DEFAULT_OPTIONS = Object.assign({}, DEFAULT_OPTIONS, options);
2658
+ }
2659
+ /**
2660
+ * 달력 보이기 처리.
2661
+ *
2662
+ * @returns
2663
+ */
2664
+ show() {
2665
+ if (this.isVisible) {
2666
+ return;
2667
+ }
2668
+ this.isVisible = true;
2669
+ const docSize = getDocSize();
2670
+ this.datetimeElement.classList.remove("hide");
2671
+ this.datetimeElement.classList.add("show");
2672
+ const rect = this.targetElement.getBoundingClientRect();
2673
+ const scrollTop = window.scrollY || document.documentElement.scrollTop;
2674
+ const scrollLeft = window.scrollX || document.documentElement.scrollLeft;
2675
+ const offsetTop = rect.top + scrollTop;
2676
+ let top = offsetTop + this.targetElement.offsetHeight + 2;
2677
+ const left = rect.left + scrollLeft;
2678
+ if (top + this.datetimeElement.offsetHeight > docSize.clientHeight) {
2679
+ const newTop = offsetTop - (this.datetimeElement.offsetHeight + 2);
2680
+ top = newTop > 0 ? newTop : top;
2681
+ }
2682
+ this.datetimeElement.setAttribute("style", `top:${top}px;left:${left}px;z-index:${this.options.zIndex}`);
2683
+ document.addEventListener("click", this._documentClickEvent);
2684
+ }
2685
+ /**
2686
+ * 달력 숨기기
2687
+ */
2688
+ hide() {
2689
+ this.isVisible = false;
2690
+ if (this.options.onClose) {
2691
+ if (this.options.onClose() === false) {
2692
+ return;
2693
+ }
2694
+ }
2695
+ this.datetimeElement.classList.remove("show");
2696
+ this.datetimeElement.classList.add("hide");
2697
+ document.removeEventListener("click", this._documentClickEvent);
2698
+ }
2699
+ /**
2700
+ * 타켓 이벤트 처리.
2701
+ */
2702
+ initTargetEvent() {
2703
+ if (this.targetElement) {
2704
+ this.targetElement.addEventListener("click", (e) => {
2705
+ this.show();
2706
+ });
2707
+ }
2708
+ }
2709
+ /**
2710
+ * 날짜 변경후 이벤트
2711
+ */
2712
+ afterChangeDatepicker() {
2713
+ const formatValue = this.currentDate.format(this.dateFormat);
2714
+ if (this.options.afterChangeDatepicker && utils_default.isFunction(this.options.afterChangeDatepicker)) {
2715
+ this.options.afterChangeDatepicker(formatValue, this.viewMode);
2716
+ }
2717
+ }
2718
+ /**
2719
+ * 날짜 변경 전 이벤트.
2720
+ * @returns void
2721
+ */
2722
+ beforeChangeDatepicker() {
2723
+ const formatValue = this.currentDate.format(this.dateFormat);
2724
+ if (this.options.beforeChangeDatepicker && utils_default.isFunction(this.options.beforeChangeDatepicker)) {
2725
+ const reval = this.options.beforeChangeDatepicker(formatValue, (result) => {
2726
+ if (result === false) {
2727
+ return;
2728
+ }
2729
+ this.refresh(false);
2730
+ });
2731
+ if (reval === false) {
2732
+ return;
2733
+ }
2734
+ this.refresh(false);
2735
+ return;
2736
+ }
2737
+ this.refresh(false);
2738
+ }
2739
+ dateChangeEvent(e) {
2740
+ const formatValue = this.currentDate.format(this.dateFormat);
2741
+ if (this.options.onSelect) {
2742
+ if (this.options.onSelect(formatValue, this.viewMode, e) === false) {
2743
+ return;
2744
+ }
2745
+ }
2746
+ if (this.isInput) {
2747
+ this.targetElement.setAttribute("value", formatValue);
2748
+ }
2749
+ if (!this.options.inline && this.options.autoClose) {
2750
+ this.hide();
2751
+ }
2752
+ }
2753
+ /**
2754
+ * datepicker template 그리기
2755
+ */
2756
+ createDatetimeTemplate() {
2757
+ const showMonthAfterYear = this.options.showMonthAfterYear;
2758
+ let datetimeTemplate = `<div class="ddtp-datetime ${this.options.isRTL ? "rtl" : ""}" view-mode="${this._viewMode}">
2759
+ <div class="ddtp-header">
2760
+ <span class="${showMonthAfterYear ? "ddtp-header-year" : "ddtp-header-month"}"></span>
2761
+ <span class="${showMonthAfterYear ? "ddtp-header-month" : "ddtp-header-year"}"></span>
2762
+
2763
+ <span class="ddtp-date-move">
2764
+ <a href="javascript:;" class="ddtp-move-btn prev">
2765
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>
2766
+ </a>
2767
+ <a href="javascript:;" class="ddtp-move-btn next">
2768
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>
2769
+ </a>
2770
+ </span>
2771
+ </div>
2772
+ <div class="ddtp-body">
2773
+ <table class="ddtp-days">
2774
+ <thead class="ddtp-day-header">
2775
+ <tr>
2776
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[0]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[0])}</td>
2777
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[1]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[1])}</td>
2778
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[2]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[2])}</td>
2779
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[3]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[3])}</td>
2780
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[4]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[4])}</td>
2781
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[5]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[5])}</td>
2782
+ <td class="ddtp-day-label ${DAY_STYLE_CLASS[this.dayOrder[6]]}">${Lanauage_default2.getWeeksMessage(this.dayOrder[6])}</td>
2783
+ </tr>
2784
+ </thead>
2785
+ <tbody class="ddtp-day-body">
2786
+ </tbody>
2787
+
2788
+ <tfoot class="ddtp-day-footer">
2789
+ <td colspan="7">
2790
+ <div style="text-align:center;margin-top: 5px;${this.options.enableTodayBtn ? "" : "display:none;"}"><button type="button" class="time-today">${Lanauage_default2.getMessage("today")}</button></div>
2791
+ <div class="footer-tooltip"></div>
2792
+ </td>
2793
+ </tfoot>
2794
+ </table>
2795
+
2796
+ <div class="ddtp-times">
2797
+ <div class="time-container">
2798
+ <div class="ddtp-time">
2799
+ <span>H: </span><input type="number" class="ddtp-hour" min="0" max="23">
2800
+ <input type="range" min="0" max="23" class="ddtp-hour-range">
2801
+ </div>
2802
+ <div class="ddtp-time">
2803
+ <span>M: </span><input type="number" class="ddtp-minute" min="0" max="59">
2804
+ <input type="range" min="0" max="59" class="ddtp-minute-range">
2805
+ </div>
2806
+ </div>
2807
+ <div class="time-btn">
2808
+ <button type="button" class="time-select">${Lanauage_default2.getMessage("ok")}</button>
2809
+ </div>
2810
+ </div>
2811
+
2812
+ <div class="ddtp-months">
2813
+ </div>
2814
+
2815
+ <div class="ddtp-years">
2816
+ </div>
2817
+ </div>
2818
+ </div>`;
2819
+ this.datetimeElement.innerHTML = datetimeTemplate;
2820
+ }
2821
+ refresh(beforeChangeDatepickerCheck) {
2822
+ if (this._viewMode === "date" || this._viewMode === "datetime") {
2823
+ this.dayDraw(beforeChangeDatepickerCheck);
2824
+ return;
2825
+ }
2826
+ if (this._viewMode === "month") {
2827
+ this.monthDraw(beforeChangeDatepickerCheck);
2828
+ return;
2829
+ }
2830
+ if (this._viewMode === "year") {
2831
+ this.yearDraw(beforeChangeDatepickerCheck);
2832
+ }
2833
+ }
2834
+ /**
2835
+ * 년 달력 그리기
2836
+ */
2837
+ yearDraw(beforeChangeDatepickerCheck) {
2838
+ const currentYear = this.currentDate.format("YYYY");
2839
+ if (beforeChangeDatepickerCheck !== false && this.initMode == "year") {
2840
+ this.beforeChangeDatepicker();
2841
+ return;
2842
+ }
2843
+ const startYear = +currentYear - 8;
2844
+ this.datetimeElement.querySelector(".ddtp-header-year").textContent = `${startYear} ~ ${startYear + 15}`;
2845
+ const beforeDrawDateFlag = utils_default.isFunction(this.options.beforeDrawDate);
2846
+ const beforeDrawDateFn = beforeDrawDateFlag ? this.options.beforeDrawDate : false;
2847
+ const calHTML = [];
2848
+ for (let i = 0; i < 16; i++) {
2849
+ const year = startYear + i;
2850
+ const disabled = this.isYearDisabled(year);
2851
+ let addStylceClass = disabled ? " disabled" : "";
2852
+ let tooltip = "";
2853
+ if (beforeDrawDateFlag && beforeDrawDateFn) {
2854
+ const reval = beforeDrawDateFn({ mode: this._viewMode, date: year });
2855
+ addStylceClass += reval.style ? " " + reval.style : "";
2856
+ tooltip = reval.tooltip;
2857
+ tooltip = tooltip ? `title="${tooltip}"` : "";
2858
+ }
2859
+ calHTML.push(`<div class="ddtp-year ${addStylceClass}" data-year="${year}" ${tooltip}>${year}</div>`);
2860
+ }
2861
+ this.datetimeElement.querySelector(".ddtp-years").innerHTML = calHTML.join("");
2862
+ if (this.initMode == "year") {
2863
+ this.afterChangeDatepicker();
2864
+ }
2865
+ this.datetimeElement.querySelectorAll(".ddtp-year")?.forEach((yearEle) => {
2866
+ yearEle.addEventListener("click", (e) => {
2867
+ const targetEle = e.target;
2868
+ if (targetEle) {
2869
+ const year = targetEle.getAttribute("data-year");
2870
+ if (year) {
2871
+ const numYear = +year;
2872
+ if (this.isYearDisabled(numYear)) {
2873
+ return;
2874
+ }
2875
+ if (this.initMode == "year") {
2876
+ if (this.isYearDisabled(numYear)) {
2877
+ return;
2878
+ }
2879
+ this.currentDate.setYear(numYear);
2880
+ this.dateChangeEvent(e);
2881
+ return;
2882
+ }
2883
+ this.currentDate.setYear(numYear);
2884
+ this.viewMode = this.initMode;
2885
+ }
2886
+ }
2887
+ });
2888
+ });
2889
+ }
2890
+ /**
2891
+ * 월 달력 그리기
2892
+ */
2893
+ monthDraw(beforeChangeDatepickerCheck) {
2894
+ if (beforeChangeDatepickerCheck !== false && this.initMode == "month") {
2895
+ this.beforeChangeDatepicker();
2896
+ return;
2897
+ }
2898
+ const year = this.currentDate.format("YYYY");
2899
+ this.datetimeElement.querySelector(".ddtp-header-year").textContent = `${year}`;
2900
+ const monthElements = this.datetimeElement.querySelectorAll(".ddtp-months > .ddtp-month");
2901
+ if (monthElements.length > 0) {
2902
+ if (this.isYearDisabled(+year)) {
2903
+ monthElements.forEach((monthEle) => {
2904
+ if (!monthEle.classList.contains("disabled")) {
2905
+ monthEle.classList.add("disabled");
2906
+ }
2907
+ });
2908
+ return;
2909
+ }
2910
+ monthElements.forEach((monthEle, idx) => {
2911
+ if (this.isMonthDisabled(+year, idx)) {
2912
+ if (!monthEle.classList.contains("disabled")) {
2913
+ monthEle.classList.add("disabled");
2914
+ }
2915
+ } else {
2916
+ monthEle.classList.remove("disabled");
2917
+ }
2918
+ });
2919
+ if (this.initMode == "month") {
2920
+ this.afterChangeDatepicker();
2921
+ }
2922
+ return;
2923
+ }
2924
+ this.datetimeElement.querySelector(".ddtp-header-month").textContent = this.currentDate.format("MMMM");
2925
+ const beforeDrawDateFlag = utils_default.isFunction(this.options.beforeDrawDate);
2926
+ const beforeDrawDateFn = beforeDrawDateFlag ? this.options.beforeDrawDate : false;
2927
+ const calHTML = [];
2928
+ for (let i = 0; i < 12; i++) {
2929
+ const disabled = this.isMonthDisabled(+year, i);
2930
+ let addStylceClass = disabled ? " disabled" : "";
2931
+ let tooltip = "";
2932
+ if (beforeDrawDateFlag && beforeDrawDateFn) {
2933
+ const reval = beforeDrawDateFn({ mode: this._viewMode, date: year + "/" + (i + 1) });
2934
+ addStylceClass += reval.style ? " " + reval.style : "";
2935
+ tooltip = reval.tooltip;
2936
+ tooltip = tooltip ? `title="${tooltip}"` : "";
2937
+ }
2938
+ calHTML.push(`<div class="ddtp-month ${addStylceClass}" data-month="${i}" ${tooltip}>${Lanauage_default2.getMonthsMessage(i, "abbr")}</div>`);
2939
+ }
2940
+ this.datetimeElement.querySelector(".ddtp-months").innerHTML = calHTML.join("");
2941
+ if (this.initMode == "month") {
2942
+ this.afterChangeDatepicker();
2943
+ }
2944
+ this.datetimeElement.querySelectorAll(".ddtp-month")?.forEach((monthEle) => {
2945
+ monthEle.addEventListener("click", (e) => {
2946
+ const targetEle = e.target;
2947
+ if (targetEle) {
2948
+ const month = targetEle.getAttribute("data-month");
2949
+ if (month) {
2950
+ if (this.isMonthDisabled(this.currentDate.getYear(), +month)) {
2951
+ return false;
2952
+ }
2953
+ if (this.initMode == "month") {
2954
+ this.currentDate.setMonth(+month);
2955
+ this.dateChangeEvent(e);
2956
+ return;
2957
+ }
2958
+ this.currentDate.setMonth(+month);
2959
+ this.viewMode = this.initMode;
2960
+ this.dayDraw();
2961
+ }
2962
+ }
2963
+ });
2964
+ });
2965
+ }
2966
+ /**
2967
+ * 날짜 그리기
2968
+ */
2969
+ dayDraw(beforeChangeDatepickerCheck) {
2970
+ if (beforeChangeDatepickerCheck !== false && (this.initMode == "date" || this.initMode == "datetime")) {
2971
+ this.beforeChangeDatepicker();
2972
+ return;
2973
+ }
2974
+ let monthFirstDate = this.currentDate.clone();
2975
+ const currentMonth = monthFirstDate.getMonth();
2976
+ monthFirstDate.setDate(1);
2977
+ this.datetimeElement.querySelector(".ddtp-header-year").textContent = monthFirstDate.format("YYYY");
2978
+ this.datetimeElement.querySelector(".ddtp-header-month").textContent = monthFirstDate.format("MMMM");
2979
+ let day = monthFirstDate.getDay();
2980
+ day = day - this.dayOrder[0];
2981
+ if (day >= 0) {
2982
+ monthFirstDate.addDate(-day);
2983
+ } else {
2984
+ monthFirstDate.addDate(-(7 + day));
2985
+ }
2986
+ const beforeDrawDateFlag = utils_default.isFunction(this.options.beforeDrawDate);
2987
+ const beforeDrawDateFn = beforeDrawDateFlag ? this.options.beforeDrawDate : false;
2988
+ const calHTML = [];
2989
+ for (let i = 0; i < 42; i++) {
2990
+ let dateItem;
2991
+ if (i == 0) {
2992
+ dateItem = monthFirstDate;
2993
+ } else {
2994
+ dateItem = monthFirstDate.clone().addDate(i);
2995
+ }
2996
+ const dateItemFormat = dateItem.format(DEFAULT_FORMAT.date);
2997
+ if (i % 7 == 0) {
2998
+ calHTML.push((i == 0 ? "" : "</tr>") + "<tr>");
2999
+ }
3000
+ let disabled = this.isDayDisabled(dateItem);
3001
+ let addStylceClass = DAY_STYLE_CLASS[this.dayOrder[i % 7]];
3002
+ const dateItemMonth = dateItem.getMonth();
3003
+ if (dateItemMonth != currentMonth) {
3004
+ if (dateItemMonth < currentMonth) {
3005
+ addStylceClass += dateItemMonth == 1 ? " new" : " old";
3006
+ } else {
3007
+ addStylceClass += currentMonth == 1 && dateItemMonth == 12 ? " old" : " new";
3008
+ }
3009
+ }
3010
+ addStylceClass += this.todayDate == dateItemFormat ? " today" : "";
3011
+ addStylceClass += disabled ? " disabled" : "";
3012
+ let tooltip = "";
3013
+ if (beforeDrawDateFlag && beforeDrawDateFn) {
3014
+ const reval = beforeDrawDateFn({ mode: this._viewMode, item: dateItem, date: dateItem.format(this.dateFormat) });
3015
+ addStylceClass += reval.style ? " " + reval.style : "";
3016
+ addStylceClass += reval.check ? " event" : "";
3017
+ tooltip = reval.tooltip;
3018
+ tooltip = tooltip ? `title="${tooltip}"` : "";
3019
+ }
3020
+ calHTML.push(`<td class="ddtp-day ${addStylceClass}" data-day="${dateItem.format("M,D")}" ${tooltip}>`);
3021
+ calHTML.push(`<span>${dateItem.format("d")}</span>`);
3022
+ calHTML.push("</td>");
3023
+ }
3024
+ calHTML.push("</tr>");
3025
+ this.datetimeElement.querySelector(".ddtp-day-body").innerHTML = calHTML.join("");
3026
+ if (this.initMode == "date" || this.initMode == "datetime") {
3027
+ this.afterChangeDatepicker();
3028
+ }
3029
+ }
3030
+ isDayDisabled(dateItem) {
3031
+ if (this.minDate != -1 && this.minDate > dateItem.getTime() || this.maxDate != -1 && this.maxDate < dateItem.getTime()) {
3032
+ return true;
3033
+ }
3034
+ return false;
3035
+ }
3036
+ isYearDisabled(year) {
3037
+ if (this.minYear != -1 && this.minYear > year || this.maxYear != -1 && this.maxYear < year) {
3038
+ return true;
3039
+ }
3040
+ return false;
3041
+ }
3042
+ isMonthDisabled(year, month) {
3043
+ if (this.isYearDisabled(year)) {
3044
+ return true;
3045
+ }
3046
+ let yearMonth = +(year + utils_default.pad(month, 2));
3047
+ if (this.minMonth != -1 && this.minMonth > yearMonth || this.maxMonth != -1 && this.maxMonth < yearMonth) {
3048
+ return true;
3049
+ }
3050
+ return false;
3051
+ }
3052
+ static setMessage(message2) {
3053
+ Lanauage_default2.setDefaultMessage(message2);
3054
+ }
3055
+ };
3056
+ }
3057
+ });
3058
+ var init_daracl_datetimepicker = __esm({
3059
+ "style/daracl.datetimepicker.scss"() {
3060
+ }
3061
+ });
3062
+ var require_src = __commonJS({
3063
+ "src/index.ts"(exports2, module2) {
3064
+ init_DateTimePicker();
3065
+ init_daracl_datetimepicker();
3066
+ module2.exports = DateTimePicker;
3067
+ }
3068
+ });
3069
+ var dist_default = require_src();
3070
+
3071
+ // src/renderer/DateRender.ts
3072
+ var DateRender = class extends Render {
3073
+ constructor(field, rowElement, daraForm) {
3074
+ super(daraForm, field, rowElement);
3075
+ this.mounted();
3076
+ this.setDefaultOption();
3077
+ this.setDefaultInfo();
3078
+ }
3079
+ mounted() {
3080
+ let dateOnSelectEvent;
3081
+ this.field.customOptions = Object.assign({}, this.field.customOptions);
3082
+ if (typeof this.field.customOptions.onSelect !== "undefined") {
3083
+ dateOnSelectEvent = typeof this.field.customOptions.onSelect;
3084
+ }
3085
+ if (isUndefined(this.field.customOptions.mode)) {
3086
+ if (this.field.renderType == "datemonth" || this.field.renderType == "datehour") {
3087
+ this.field.customOptions.mode = this.field.renderType.replace("date", "");
3088
+ } else {
3089
+ this.field.customOptions.mode = this.field.renderType;
3090
+ }
3091
+ }
3092
+ this.field.customOptions.onSelect = (dt, e) => {
3093
+ if (dateOnSelectEvent) {
3094
+ dateOnSelectEvent.call(null, dt, e);
3095
+ }
3096
+ this.setValue(dt);
3097
+ };
3098
+ this.dateObj = new dist_default(this.element, this.field.customOptions, {});
3099
+ }
3100
+ createField() {
3101
+ const field = this.field;
3102
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
3103
+ fieldContainerElement.innerHTML = `
3104
+ <div class="df-field">
3105
+ <input type="text" name="${field.$xssName}" class="form-field text help-icon" autocomplete="off"/>
3106
+ </div>
3107
+ ${Render.getDescriptionTemplate(field)}
3108
+ <div class="help-message"></div>
3109
+ `;
3110
+ this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`);
3111
+ }
3112
+ getValue() {
3113
+ return this.element.value;
3114
+ }
3115
+ setValue(value, changeCheckFlag) {
3116
+ if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
3117
+ this.element.value = this.field.$value;
3118
+ return;
3119
+ }
3120
+ this.field.$value = value;
3121
+ this.element.value = value;
3122
+ }
3123
+ reset() {
3124
+ this.setDefaultInfo();
3125
+ this.setDisabled(false);
3126
+ resetRowElementStyleClass(this.rowElement);
3127
+ }
3128
+ getElement() {
3129
+ return this.element;
3130
+ }
3131
+ valid() {
3132
+ const validResult = stringValidator(this.getValue(), this.field);
3133
+ invalidMessage(this.field, this.rowElement, validResult);
3134
+ return validResult;
3135
+ }
3136
+ };
3137
+
3138
+ // src/util/styleUtils.ts
3139
+ var styleUtils_default = {
3140
+ /**
3141
+ * field style 처리
3142
+ *
3143
+ * @param formOptions FormOptions
3144
+ * @param field FormField
3145
+ * @param beforeField FormField
3146
+ * @returns FieldStyle
3147
+ */
3148
+ fieldStyle(formOptions, field, beforeField, isLabelHide) {
3149
+ const fieldStyle = {
3150
+ rowStyleClass: field.orientation === "horizontal" ? "horizontal" : "vertical",
3151
+ fieldClass: "",
3152
+ fieldStyle: "",
3153
+ labelClass: "",
3154
+ labelStyle: "",
3155
+ labelAlignClass: "",
3156
+ valueClass: "",
3157
+ valueStyle: "",
3158
+ tabAlignClass: ""
3159
+ };
3160
+ const defaultLabelWidth = beforeField?.style?.labelWidth ?? formOptions.style.labelWidth ?? "3";
3161
+ let defaultValueWidth = beforeField?.style?.valueWidth ?? formOptions.style.valueWidth ?? "9";
3162
+ const position = beforeField?.style?.position ?? formOptions.style.position;
3163
+ const width = field.style?.width;
3164
+ const positionArr = FIELD_POSITION_STYLE[field.style?.position] ?? FIELD_POSITION_STYLE[position] ?? FIELD_POSITION_STYLE.top;
3165
+ fieldStyle.fieldClass = `${positionArr[0]} ${field.style?.customClass || ""}`;
3166
+ if (width) {
3167
+ if (isNumber(width)) {
3168
+ fieldStyle.fieldClass += isNumber(width) ? ` col-xs-${width}` : "";
3169
+ } else {
3170
+ fieldStyle.fieldStyle = isNumber(width) ? "" : `width:${width};`;
3171
+ }
3172
+ }
3173
+ fieldStyle.tabAlignClass = "tab-al-" + (["right", "center"].includes(field.style?.tabAlign) ? field.style.tabAlign : "left");
3174
+ const labelWidth = field.style?.labelWidth || defaultLabelWidth;
3175
+ fieldStyle.labelAlignClass = positionArr[1];
3176
+ if (!isLabelHide && labelWidth && !["top", "bottom"].includes(positionArr[0])) {
3177
+ if (isNumber(labelWidth)) {
3178
+ const labelWidthValue = +labelWidth;
3179
+ defaultValueWidth = 12 - labelWidthValue;
3180
+ fieldStyle.labelClass = `col-xs-${labelWidthValue}`;
3181
+ fieldStyle.valueClass = fieldStyle.labelStyle ? "col-full" : `col-xs-${defaultValueWidth}`;
3182
+ } else {
3183
+ fieldStyle.labelStyle = `width:${labelWidth};`;
3184
+ }
3185
+ }
3186
+ const valueWidth = field.style?.valueWidth || defaultValueWidth;
3187
+ if (isLabelHide && !["left", "right"].includes(positionArr[0])) {
3188
+ fieldStyle.valueClass = "col-full";
3189
+ } else {
3190
+ if (valueWidth && !["top", "bottom"].includes(positionArr[0])) {
3191
+ if (isNumber(valueWidth)) {
3192
+ fieldStyle.valueClass = fieldStyle.labelStyle ? "col-full" : `col-xs-${valueWidth}`;
3193
+ } else {
3194
+ fieldStyle.valueStyle = `width:${valueWidth};`;
3195
+ }
3196
+ } else {
3197
+ fieldStyle.valueClass = fieldStyle.labelStyle ? "col-full" : "";
3198
+ }
3199
+ }
3200
+ fieldStyle.fieldClass = spaceReplace(fieldStyle.fieldClass);
3201
+ fieldStyle.labelClass = spaceReplace(fieldStyle.labelClass);
3202
+ fieldStyle.valueClass = spaceReplace(fieldStyle.valueClass);
3203
+ return fieldStyle;
3204
+ }
3205
+ };
3206
+ function spaceReplace(str) {
3207
+ return str.replace(/\s+/g, " ").trim();
3208
+ }
3209
+
3210
+ // src/renderer/TabRender.ts
3211
+ var TabRender = class extends Render {
3212
+ constructor(field, rowElement, daraForm) {
3213
+ super(daraForm, field, rowElement);
3214
+ if (field.renderer) {
3215
+ this.customFunction = field.renderer;
3216
+ } else {
3217
+ this.customFunction = {};
3218
+ }
3219
+ this.mounted();
3220
+ }
3221
+ mounted() {
3222
+ if (this.customFunction.mounted) {
3223
+ this.customFunction.mounted.call(this, this.field, this.rowElement);
3224
+ }
3225
+ this.tabContainerElement.querySelectorAll(".tab-item").forEach((tabItem) => {
3226
+ tabItem.addEventListener("click", (e) => {
3227
+ this.clickEventHandler(tabItem, e);
3228
+ });
3229
+ });
3230
+ }
3231
+ /**
3232
+ * tab item click
3233
+ *
3234
+ * @param {Element} tabItem
3235
+ * @param {*} evt
3236
+ */
3237
+ clickEventHandler(tabItem, evt) {
3238
+ this.setActive(tabItem.getAttribute("data-tab-id") ?? "");
3239
+ }
3240
+ setActive(tabId) {
3241
+ const tabItem = this.tabContainerElement.querySelector(`[data-tab-id="${tabId}"]`);
3242
+ if (!tabItem)
3243
+ return;
3244
+ if (!tabItem.classList.contains("active")) {
3245
+ for (let item of tabItem?.parentElement?.children ?? []) {
3246
+ item.classList.remove("active");
3247
+ }
3248
+ tabItem.classList.add("active");
3249
+ }
3250
+ const tabPanel = this.rowElement.querySelector(`[tab-panel-id="${tabId}"]`);
3251
+ if (!tabPanel?.classList.contains("active")) {
3252
+ for (let item of tabPanel?.parentElement?.children ?? []) {
3253
+ item.classList.remove("active");
3254
+ }
3255
+ tabPanel?.classList.add("active");
3256
+ }
3257
+ }
3258
+ static isDataRender() {
3259
+ return false;
3260
+ }
3261
+ static isChildrenCreate() {
3262
+ return false;
3263
+ }
3264
+ /**
3265
+ * tab template
3266
+ *
3267
+ * @param {FormField} field
3268
+ * @param {FormTemplate} formTemplate
3269
+ * @param {FormOptions} options
3270
+ * @returns {string} template string
3271
+ */
3272
+ createField() {
3273
+ const field = this.field;
3274
+ const formTemplate = this.daraForm.formTemplate;
3275
+ const options = this.daraForm.getOptions();
3276
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
3277
+ let fieldStyle = styleUtils_default.fieldStyle(options, field);
3278
+ fieldContainerElement.innerHTML = `
3279
+ <div class="df-field ">
3280
+ <div class="tab-header ${fieldStyle.tabAlignClass}"></div>
3281
+ </div>
3282
+ <div class="df-tab-body"></div>
3283
+ `;
3284
+ if (field.children) {
3285
+ let firstFlag = true;
3286
+ const formOptions = this.getForm().getOptions();
3287
+ let fieldStyle2 = styleUtils_default.fieldStyle(formOptions, field, null, formTemplate.isLabelHide(field));
3288
+ for (const childField of field.children) {
3289
+ childField.$parent = field;
3290
+ formTemplate.addRowFieldInfo(childField);
3291
+ let id = childField.$key;
3292
+ let tabTemplate = `<span class="tab-item ${firstFlag ? "active" : ""}" data-tab-id="${id}"><a href="javascript:;">${childField.label}</a></span>`;
3293
+ let tabBodyTemplate = `<div class="tab-panel ${firstFlag ? "active" : ""}" tab-panel-id="${id}">${Render.getDescriptionTemplate(childField)}
3294
+ <div class="tab-group"></div>
3295
+ </div>`;
3296
+ const tabElement = templateToElement(tabTemplate);
3297
+ const tabBodyElement = templateToElement(tabBodyTemplate);
3298
+ firstFlag = false;
3299
+ if (tabElement) {
3300
+ fieldContainerElement.querySelector(".tab-header")?.appendChild(tabElement);
3301
+ }
3302
+ if (tabBodyElement) {
3303
+ fieldContainerElement.querySelector(".df-tab-body")?.appendChild(tabBodyElement);
3304
+ if (childField.children) {
3305
+ let tabFormOptions = {
3306
+ style: {
3307
+ width: formOptions.style.width ?? "100%",
3308
+ labelWidth: formOptions.style.labelWidth ?? 3,
3309
+ valueWidth: formOptions.style.valueWidth ?? 9,
3310
+ position: formOptions.style.position ?? "left-right"
3311
+ },
3312
+ useTypeValue: formOptions.useTypeValue,
3313
+ autoCreate: false,
3314
+ notValidMessage: "This form is not valid.",
3315
+ fields: []
3316
+ };
3317
+ childField.$tabForm = new DaraForm(document.createElement("div"), tabFormOptions);
3318
+ childField.$instance = new childField.$renderType(childField, tabBodyElement?.querySelector(".tab-group"), childField.$tabForm);
3319
+ childField.$tabForm.formTemplate.childTemplate(childField, fieldStyle2);
3320
+ }
3321
+ }
3322
+ }
3323
+ this.tabContainerElement = fieldContainerElement;
3324
+ }
3325
+ }
3326
+ getValue() {
3327
+ if (this.customFunction.getValue) {
3328
+ return this.customFunction.getValue.call(this, this.field, this.rowElement);
3329
+ }
3330
+ let allTabValue = {};
3331
+ let useTypeValue = this.getForm().getOptions().useTypeValue;
3332
+ for (const childField of this.field.children) {
3333
+ const childFieldValue = childField.$tabForm?.getValue(false);
3334
+ if (useTypeValue) {
3335
+ allTabValue[childField.$validName] = childFieldValue;
3336
+ } else {
3337
+ for (let [key, value] of Object.entries(childFieldValue)) {
3338
+ allTabValue[key] = value;
3339
+ }
3340
+ }
3341
+ }
3342
+ return allTabValue;
3343
+ }
3344
+ setValue(value) {
3345
+ for (const childField of this.field.children) {
3346
+ let tabChildValue = value[childField.$validName];
3347
+ if (tabChildValue) {
3348
+ childField.$tabForm?.setValue(tabChildValue);
3349
+ }
3350
+ }
3351
+ }
3352
+ reset() {
3353
+ }
3354
+ getElement() {
3355
+ return this.rowElement;
3356
+ }
3357
+ valid() {
3358
+ if (this.customFunction.valid) {
3359
+ const validResult = this.customFunction.valid.call(this, this.field, this.rowElement);
3360
+ invalidMessage(this.field, this.rowElement, validResult);
3361
+ return;
3362
+ }
3363
+ const field = this.field;
3364
+ for (const childField of field.children) {
3365
+ const validResult = childField.$tabForm?.validForm();
3366
+ if (validResult && validResult.length > 0) {
3367
+ const firstItem = validResult[0];
3368
+ if (firstItem.message) {
3369
+ firstItem.message = "[" + this.field.label + "] " + firstItem.message;
3370
+ return firstItem;
3371
+ }
3372
+ }
3373
+ }
3374
+ return true;
3375
+ }
3376
+ focus() {
3377
+ }
3378
+ };
3379
+
3380
+ // src/renderer/GridRender.ts
3381
+ var $$idx = 0;
3382
+ var GridRender = class extends Render {
3383
+ constructor(field, rowElement, daraForm) {
3384
+ super(daraForm, field, rowElement);
3385
+ this.allAddRowInfo = {};
3386
+ if (field.renderer) {
3387
+ this.customFunction = field.renderer;
3388
+ } else {
3389
+ this.customFunction = {};
3390
+ }
3391
+ const gridFormOptions = {
3392
+ style: {
3393
+ width: "100%",
3394
+ labelWidth: 3,
3395
+ valueWidth: 9,
3396
+ position: "left-right"
3397
+ },
3398
+ autoCreate: false,
3399
+ notValidMessage: "This form is not valid.",
3400
+ fields: []
3401
+ };
3402
+ this.gridForm = new DaraForm(document.createElement("div"), gridFormOptions);
3403
+ this.mounted();
3404
+ this.setDefaultOption();
3405
+ this.setDefaultInfo();
3406
+ }
3407
+ mounted() {
3408
+ this.addRow();
3409
+ if (this.customFunction.mounted) {
3410
+ this.customFunction.mounted.call(this, this.field, this.rowElement);
3411
+ }
3412
+ this.rowElement.querySelector(".df-grid-add-row-btn")?.addEventListener("click", (evt) => {
3413
+ this.addRow();
3414
+ });
3415
+ }
3416
+ static isDataRender() {
3417
+ return false;
3418
+ }
3419
+ static isChildrenCreate() {
3420
+ return false;
3421
+ }
3422
+ createField() {
3423
+ const field = this.field;
3424
+ const fieldContainerElement = this.rowElement.querySelector(".df-field-container");
3425
+ let theadTemplate = [];
3426
+ let colgroupTemplate = [];
3427
+ let addBtnTemplate = [];
3428
+ addBtnTemplate.push("");
3429
+ if (field.children) {
3430
+ colgroupTemplate.push("<colgroup>");
3431
+ theadTemplate.push("<tr>");
3432
+ colgroupTemplate.push(`<col style="width:38px">`);
3433
+ theadTemplate.push("<th>");
3434
+ if (field.gridOptions?.disableAddButton !== true) {
3435
+ theadTemplate.push(`<button type="button" class="df-btn df-grid-add-row-btn" title="Add"><i class="df-icon df-add-icon"></i></button>`);
3436
+ }
3437
+ theadTemplate.push("</th>");
3438
+ for (const childField of field.children) {
3439
+ colgroupTemplate.push(`<col style="width:${childField.style?.width ?? "*"}">`);
3440
+ theadTemplate.push(`<th class="df-grid-header">${childField.label}</th>`);
3441
+ }
3442
+ colgroupTemplate.push("</colgroup>");
3443
+ theadTemplate.push("</tr>");
3444
+ }
3445
+ fieldContainerElement.innerHTML = `
3446
+ <div class="df-grid-field">
3447
+ ${addBtnTemplate.join("")}
3448
+ <div class="df-grid-container ${field.style?.position ?? ""}" style="height:${field.gridOptions?.height ?? "auto"};">
3449
+ <table class="df-grid">${colgroupTemplate.join("")}<thead>${theadTemplate.join("")}</thead><tbody></tbody></table>
3450
+ </div>
3451
+ </div>
3452
+ `;
3453
+ }
3454
+ /**
3455
+ * add row
3456
+ */
3457
+ addRow(valueItem) {
3458
+ let rowTemplate = [];
3459
+ const options = this.daraForm.getOptions();
3460
+ const formTemplate = this.gridForm.formTemplate;
3461
+ const parentName = this.field.$xssName;
3462
+ ++$$idx;
3463
+ let addColumns = [];
3464
+ rowTemplate.push(`<tr class="grid-row">`);
3465
+ rowTemplate.push("<td>");
3466
+ if (this.field.gridOptions?.disableRemoveButton !== true) {
3467
+ rowTemplate.push(`<button type="button" data-row-idx="${$$idx}" class="df-btn df-grid-row-remove"><i class="df-icon df-remove-icon"></i></button>`);
3468
+ }
3469
+ rowTemplate.push("</td>");
3470
+ for (const childField of this.field.children) {
3471
+ let fieldStyle = styleUtils_default.fieldStyle(options, childField, null, true);
3472
+ let columnField = merge({}, childField);
3473
+ addColumns.push(columnField);
3474
+ columnField.$orgin = childField;
3475
+ columnField.name = columnField.name + "_" + $$idx;
3476
+ columnField.$xssName = parentName + "_" + getXssFieldName(columnField);
3477
+ formTemplate.addRowFieldInfo(columnField);
3478
+ rowTemplate.push(`<td id="${columnField.$xssName}"><div class="df-field-container ${columnField.required ? "required" : ""} " style="${fieldStyle.valueStyle}"></div></td>`);
3479
+ }
3480
+ rowTemplate.push("</tr>");
3481
+ this.allAddRowInfo[$$idx] = addColumns;
3482
+ const addRowElement = templateToElement(rowTemplate.join(""));
3483
+ if (addRowElement) {
3484
+ this.rowElement.querySelector("tbody")?.append(addRowElement);
3485
+ addRowElement.querySelector(".df-grid-row-remove")?.addEventListener("click", (evt) => {
3486
+ this.removeRow(evt);
3487
+ });
3488
+ }
3489
+ valueItem = valueItem ?? {};
3490
+ for (let columnField of addColumns) {
3491
+ columnField.$instance = new columnField.$renderType(columnField, addRowElement?.querySelector(`#${columnField.$xssName}`), this.gridForm);
3492
+ if (valueItem[columnField.$orgin.name]) {
3493
+ columnField.$instance.setValue(valueItem[columnField.$orgin.name]);
3494
+ }
3495
+ }
3496
+ }
3497
+ /**
3498
+ * remove row
3499
+ *
3500
+ * @param evt event
3501
+ */
3502
+ removeRow(evt) {
3503
+ const target = evt.target;
3504
+ const rowElement = target.closest("tr");
3505
+ if (rowElement) {
3506
+ if (rowElement.parentElement?.childElementCount == 1)
3507
+ return;
3508
+ let rowIdx = evt.currentTarget?.getAttribute("data-row-idx") || "-1";
3509
+ this.removeFieldInfo(rowIdx);
3510
+ rowElement.remove();
3511
+ }
3512
+ }
3513
+ /**
3514
+ *
3515
+ * @param rowIdx row index
3516
+ */
3517
+ removeFieldInfo(rowIdx) {
3518
+ let removeFieldArrs = [];
3519
+ if (isEmpty(rowIdx)) {
3520
+ for (let key in this.allAddRowInfo) {
3521
+ removeFieldArrs = removeFieldArrs.concat(this.allAddRowInfo[key]);
3522
+ }
3523
+ this.allAddRowInfo = {};
3524
+ } else if (rowIdx) {
3525
+ const rowIdxNum = parseInt(rowIdx, 10);
3526
+ removeFieldArrs = removeFieldArrs.concat(this.allAddRowInfo[rowIdxNum]);
3527
+ delete this.allAddRowInfo[rowIdxNum];
3528
+ }
3529
+ for (let columnField of removeFieldArrs) {
3530
+ this.gridForm.getFieldInfoMap().removeFieldInfo(columnField.name);
3531
+ }
3532
+ }
3533
+ allRemoveRow() {
3534
+ this.rowElement.querySelector("tbody")?.replaceChildren();
3535
+ this.removeFieldInfo();
3536
+ }
3537
+ getValue() {
3538
+ if (this.customFunction.getValue) {
3539
+ return this.customFunction.getValue.call(this, this.field, this.rowElement);
3540
+ }
3541
+ let result = [];
3542
+ const children = this.field.children;
3543
+ const childrenLength = children.length;
3544
+ for (let idx in this.allAddRowInfo) {
3545
+ const rowColumns = this.allAddRowInfo[idx];
3546
+ let rowInfo = {};
3547
+ for (let childIdx = 0; childIdx < childrenLength; childIdx++) {
3548
+ let childField = children[childIdx];
3549
+ rowInfo[childField.name] = this.gridForm.getFieldValue(rowColumns[childIdx].name);
3550
+ }
3551
+ result.push(rowInfo);
3552
+ }
3553
+ return result;
3554
+ }
3555
+ setValue(value) {
3556
+ this.field.$value = value;
3557
+ let valueArr = [];
3558
+ if (Array.isArray(value)) {
3559
+ valueArr = value;
3560
+ } else {
3561
+ if (isPlainObject(value)) {
3562
+ valueArr.push(value);
3563
+ }
3564
+ }
3565
+ this.allRemoveRow();
3566
+ for (let valueItem of valueArr) {
3567
+ this.addRow(valueItem);
3568
+ }
3569
+ }
3570
+ reset() {
3571
+ this.setDefaultInfo();
3572
+ resetRowElementStyleClass(this.rowElement);
3573
+ }
3574
+ getElement() {
3575
+ if (this.customFunction.getElement) {
3576
+ return this.customFunction.getElement.call(this, this.field, this.rowElement);
3577
+ }
3578
+ return null;
3579
+ }
3580
+ valid() {
3581
+ if (this.customFunction.valid) {
3582
+ const validResult2 = this.customFunction.valid.call(this, this.field, this.rowElement);
3583
+ invalidMessage(this.field, this.rowElement, validResult2);
3584
+ return;
3585
+ }
3586
+ const validResult = this.gridForm.validForm();
3587
+ if (validResult.length > 0) {
3588
+ const firstItem = validResult[0];
3589
+ if (firstItem.message) {
3590
+ firstItem.message = "[" + this.field.label + "] " + firstItem.message;
3591
+ return firstItem;
3592
+ }
3593
+ }
3594
+ return true;
3595
+ }
3596
+ focus() {
3597
+ }
3598
+ };
3599
+
3600
+ // src/constants.ts
3601
+ var RULES = {
3602
+ NAN: "nan",
3603
+ MIN: "minimum",
3604
+ EXCLUSIVE_MIN: "exclusiveMinimum",
3605
+ MAX: "maximum",
3606
+ EXCLUSIVE_MAX: "exclusiveMaximum",
3607
+ MIN_LENGTH: "minLength",
3608
+ MAX_LENGTH: "maxLength",
3609
+ BETWEEN: "between",
3610
+ BETWEEN_EXCLUSIVE_MIN: "betweenExclusiveMin",
3611
+ BETWEEN_EXCLUSIVE_MAX: "betweenExclusiveMax",
3612
+ BETWEEN_EXCLUSIVE_MINMAX: "betweenExclusiveMinMax",
3613
+ REGEXP: "regexp",
3614
+ REQUIRED: "required",
3615
+ VALIDATOR: "validator"
3616
+ };
3617
+ var FIELD_PREFIX = "dff";
3618
+ var RENDER_TEMPLATE = {
3619
+ number: NumberRender,
3620
+ textarea: TextAreaRender,
3621
+ dropdown: DropdownRender,
3622
+ checkbox: CheckboxRender,
3623
+ radio: RadioRender,
3624
+ text: TextRender,
3625
+ password: PasswordRender,
3626
+ file: FileRender,
3627
+ custom: CustomRender,
3628
+ group: GroupRender,
3629
+ hidden: HiddenRender,
3630
+ button: ButtonRender,
3631
+ range: RangeRender,
3632
+ datehour: DateRender,
3633
+ datemonth: DateRender,
3634
+ date: DateRender,
3635
+ datetime: DateRender,
3636
+ tab: TabRender,
3637
+ grid: GridRender
3638
+ };
3639
+ var FIELD_POSITION_STYLE = {
3640
+ "top-left": ["top", "txt-left"],
3641
+ "top-center": ["top", "txt-center"],
3642
+ "top-right": ["top", "txt-right"],
3643
+ "left-left": ["", "txt-left"],
3644
+ "left-center": ["", "txt-center"],
3645
+ "left-right": ["", "txt-right"],
3646
+ "right-right": ["right", "txt-right"],
3647
+ "right-center": ["right", "txt-center"],
3648
+ "right-left": ["right", "txt-left"],
3649
+ "bottom-left": ["bottom", "txt-left"],
3650
+ "bottom-center": ["bottom", "txt-center"],
3651
+ "bottom-right": ["bottom", "txt-right"]
3652
+ };
3653
+ FIELD_POSITION_STYLE["top"] = FIELD_POSITION_STYLE["top-left"];
3654
+ FIELD_POSITION_STYLE["right"] = FIELD_POSITION_STYLE["right-right"];
3655
+ FIELD_POSITION_STYLE["left"] = FIELD_POSITION_STYLE["left-left"];
3656
+ FIELD_POSITION_STYLE["bottom"] = FIELD_POSITION_STYLE["bottom-left"];
3657
+
3658
+ // src/util/Lanauage.ts
3659
+ var localeMessage2 = {
3660
+ required: "{label} \uD544\uC218 \uC785\uB825\uC0AC\uD56D\uC785\uB2C8\uB2E4.",
3661
+ fileButton: "\uD30C\uC77C\uCC3E\uAE30",
3662
+ selection: "\uC120\uD0DD",
3663
+ string: {
3664
+ minLength: "{minLength} \uAE00\uC790 \uC774\uC0C1\uC73C\uB85C \uC785\uB825\uD558\uC138\uC694.",
3665
+ maxLength: "{maxLength} \uAE00\uC790 \uC774\uD558\uB85C \uC785\uB825\uD558\uC138\uC694.",
3666
+ between: "{minLength} ~ {maxLength} \uC0AC\uC774\uC758 \uAE00\uC790\uB97C \uC785\uB825\uD558\uC138\uC694."
3667
+ },
3668
+ number: {
3669
+ nan: "\uC22B\uC790\uB9CC \uC785\uB825 \uAC00\uB2A5 \uD569\uB2C8\uB2E4.",
3670
+ minimum: "{minimum} \uAC12\uACFC \uAC19\uAC70\uB098 \uCEE4\uC57C \uD569\uB2C8\uB2E4",
3671
+ exclusiveMinimum: "{minimum} \uBCF4\uB2E4 \uCEE4\uC57C \uD569\uB2C8\uB2E4",
3672
+ maximum: "{maximum} \uAC12\uACFC \uAC19\uAC70\uB098 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4",
3673
+ exclusiveMaximum: "{maximum} \uBCF4\uB2E4 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4.",
3674
+ between: "{minimum}~{maximum} \uC0AC\uC774\uC758 \uAC12\uC744 \uC785\uB825\uD558\uC138\uC694.",
3675
+ betweenExclusiveMin: "{minimum} \uBCF4\uB2E4 \uD06C\uACE0 {maximum} \uBCF4\uB2E4 \uAC19\uAC70\uB098 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4",
3676
+ betweenExclusiveMax: "{minimum} \uBCF4\uB2E4 \uAC19\uAC70\uB098 \uD06C\uACE0 {maximum} \uBCF4\uB2E4 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4",
3677
+ betweenExclusiveMinMax: "{minimum} \uBCF4\uB2E4 \uD06C\uACE0 {maximum} \uBCF4\uB2E4 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4"
3678
+ },
3679
+ regexp: {
3680
+ mobile: "\uD578\uB4DC\uD3F0 \uBC88\uD638\uAC00 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
3681
+ email: "\uC774\uBA54\uC77C\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
3682
+ url: "URL\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
3683
+ alpha: "\uC601\uBB38\uB9CC \uC785\uB825 \uAC00\uB2A5 \uD569\uB2C8\uB2E4.",
3684
+ "alpha-num": "\uC601\uBB38\uACFC \uC22B\uC790\uB9CC \uC785\uB825 \uAC00\uB2A5 \uD569\uB2C8\uB2E4.",
3685
+ number: "\uC22B\uC790\uB9CC \uC785\uB825 \uAC00\uB2A5 \uD569\uB2C8\uB2E4.",
3686
+ variable: "\uAC12\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
3687
+ "number-char": "\uC22B\uC790, \uBB38\uC790 \uAC01\uAC01 \uD558\uB098 \uC774\uC0C1 \uD3EC\uD568 \uB418\uC5B4\uC57C \uD569\uB2C8\uB2E4.",
3688
+ "upper-char": "\uB300\uBB38\uC790\uAC00 \uD558\uB098 \uC774\uC0C1 \uD3EC\uD568 \uB418\uC5B4\uC57C \uD569\uB2C8\uB2E4.",
3689
+ "upper-char-special": "\uB300\uBB38\uC790,\uC18C\uBB38\uC790,\uD2B9\uC218\uBB38\uC790 \uAC01\uAC01 \uD558\uB098 \uC774\uC0C1 \uD3EC\uD568 \uB418\uC5B4\uC57C \uD569\uB2C8\uB2E4.",
3690
+ "upper-char-special-number": "\uB300\uBB38\uC790,\uC18C\uBB38\uC790,\uD2B9\uC218\uBB38\uC790,\uC22B\uC790 \uAC01\uAC01 \uD558\uB098 \uC774\uC0C1 \uD3EC\uD568 \uB418\uC5B4\uC57C\uD569\uB2C8\uB2E4."
3691
+ }
3692
+ };
3693
+ var Language2 = class {
3694
+ constructor() {
3695
+ this.lang = localeMessage2;
3696
+ }
3697
+ /**
3698
+ * 다국어 메시지 등록
3699
+ *
3700
+ * @public
3701
+ * @param {?Message} [lang] 둥록할 메시지
3702
+ */
3703
+ set(lang) {
3704
+ this.lang = Object.assign({}, localeMessage2, lang);
3705
+ }
3706
+ /**
3707
+ * 메시지 얻기
3708
+ *
3709
+ * @public
3710
+ * @param {string} messageKey 메시지 키
3711
+ * @returns {*}
3712
+ */
3713
+ getMessage(messageKey) {
3714
+ return this.lang[messageKey];
3715
+ }
3716
+ /**
3717
+ * ValidResult 값을 메시지로 변경.
3718
+ *
3719
+ * @public
3720
+ * @param {FormField} field
3721
+ * @param {ValidResult} validResult
3722
+ * @returns {string[]}
3723
+ */
3724
+ validMessage(field, validResult) {
3725
+ let messageFormat = "";
3726
+ let messageFormats = [];
3727
+ if (validResult.regexp) {
3728
+ messageFormat = this.lang.regexp[validResult.regexp];
3729
+ messageFormats.push(messageFormat);
3730
+ }
3731
+ (validResult.constraint ?? []).forEach((constraint) => {
3732
+ if (constraint === RULES.REQUIRED) {
3733
+ messageFormat = message(this.lang.required, field);
3734
+ messageFormats.push(messageFormat);
3735
+ }
3736
+ if (field.renderType == "number" || field.renderType == "range") {
3737
+ messageFormat = this.lang.number[constraint];
3738
+ messageFormats.push(messageFormat);
3739
+ } else {
3740
+ messageFormat = this.lang.string[constraint];
3741
+ messageFormats.push(messageFormat);
3742
+ }
3743
+ });
3744
+ const reMessage = [];
3745
+ const msgParam = Object.assign({}, { name: field.name, label: field.label }, field.rule);
3746
+ messageFormats.forEach((msgFormat) => {
3747
+ if (msgFormat) {
3748
+ reMessage.push(message(msgFormat, msgParam));
3749
+ }
3750
+ });
3751
+ if (validResult.validator) {
3752
+ reMessage.push(validResult.validator.message);
3753
+ }
3754
+ return reMessage;
3755
+ }
3756
+ };
3757
+ function message(msgFormat, msgParam) {
3758
+ return msgFormat.replace(/\{{1,1}([A-Za-z0-9_.]*)\}{1,1}/g, (match, key) => {
3759
+ return typeof msgParam[key] !== "undefined" ? msgParam[key] : match;
3760
+ });
3761
+ }
3762
+ var Lanauage_default = new Language2();
3763
+
3764
+ // src/util/renderFactory.ts
3765
+ var getRenderer = (field) => {
3766
+ let render;
3767
+ if (field.renderType) {
3768
+ render = RENDER_TEMPLATE[field.renderType];
3769
+ }
3770
+ if (render && (render.isDataRender() === false || !isUndefined(field.name))) {
3771
+ return render;
3772
+ }
3773
+ if (isUndefined(field.name)) {
3774
+ if (field.children) {
3775
+ return RENDER_TEMPLATE["group"];
3776
+ } else {
3777
+ return RENDER_TEMPLATE["hidden"];
3778
+ }
3779
+ }
3780
+ return RENDER_TEMPLATE["text"];
3781
+ };
3782
+
3783
+ // src/FieldInfoMap.ts
3784
+ var FieldInfoMap = class {
3785
+ constructor(selector, form) {
3786
+ this.fieldIdx = 0;
3787
+ this.allFieldInfo = {};
3788
+ this.keyNameMap = {};
3789
+ this.conditionFields = [];
3790
+ this.fieldPrefix = `${FIELD_PREFIX}_${getHashCode(selector)}`;
3791
+ this.form = form;
3792
+ }
3793
+ /**
3794
+ * add Field 정보
3795
+ *
3796
+ * @public
3797
+ * @param {FormField} field 폼필드 정보
3798
+ */
3799
+ addField(field) {
3800
+ replaceXssField(field);
3801
+ this.fieldIdx += 1;
3802
+ field.$key = `${this.fieldPrefix}_${this.fieldIdx}`;
3803
+ field.$validName = field.name ?? field.label;
3804
+ this.keyNameMap[field.$validName] = field.$key;
3805
+ this.allFieldInfo[field.$key] = field;
3806
+ field.$renderType = getRenderer(field);
3807
+ if (field.conditional) {
3808
+ this.conditionFields.push(field.$key);
3809
+ }
3810
+ }
3811
+ /**
3812
+ * 필드명으로 필드 정부 구하기
3813
+ *
3814
+ * @public
3815
+ * @param {string} fieldName 필드명
3816
+ * @returns {FormField}
3817
+ */
3818
+ getFieldName(fieldName) {
3819
+ return this.allFieldInfo[this.keyNameMap[fieldName]];
3820
+ }
3821
+ /**
3822
+ * 필드 키로 정보 구하기
3823
+ *
3824
+ * @public
3825
+ * @param {string} fieldKey
3826
+ * @returns {FormField}
3827
+ */
3828
+ get(fieldKey) {
3829
+ return this.allFieldInfo[fieldKey];
3830
+ }
3831
+ /**
3832
+ * 필드명 있는지 여부 체크.
3833
+ *
3834
+ * @public
3835
+ * @param {string} fieldName 필드명
3836
+ * @returns {boolean}
3837
+ */
3838
+ hasFieldName(fieldName) {
3839
+ if (this.keyNameMap[fieldName] && this.allFieldInfo[this.keyNameMap[fieldName]]) {
3840
+ return true;
3841
+ }
3842
+ return false;
3843
+ }
3844
+ /**
3845
+ * 모든 필드 정보
3846
+ *
3847
+ * @public
3848
+ * @returns {NumberFieldMap}
3849
+ */
3850
+ getAllFieldInfo() {
3851
+ return this.allFieldInfo;
3852
+ }
3853
+ /**
3854
+ * 필드 정보 맵에서 지우기
3855
+ *
3856
+ * @public
3857
+ * @param {string} fieldName
3858
+ */
3859
+ removeFieldInfo(fieldName) {
3860
+ delete this.allFieldInfo[this.keyNameMap[fieldName]];
3861
+ }
3862
+ /**
3863
+ * 모든 필드값 구하기
3864
+ *
3865
+ * @public
3866
+ * @param {boolean} validationCheck
3867
+ * @returns {*}
3868
+ */
3869
+ getAllFieldValue(formValue, validationCheck) {
3870
+ const useTypeValue = this.form.getOptions().useTypeValue;
3871
+ if (validationCheck !== true) {
3872
+ for (let [key, fieldInfo] of Object.entries(this.allFieldInfo)) {
3873
+ formValue = addFormValue(formValue, fieldInfo, useTypeValue);
3874
+ }
3875
+ return formValue;
3876
+ }
3877
+ return new Promise((resolve, reject) => {
3878
+ for (let [key, fieldInfo] of Object.entries(this.allFieldInfo)) {
3879
+ if (!fieldInfo.$instance.isEnableView()) {
3880
+ continue;
3881
+ }
3882
+ let fieldValid = this.getFieldValidation(fieldInfo, true);
3883
+ if (fieldValid !== true) {
3884
+ reject(new Error(fieldValid.message, { cause: fieldValid }));
3885
+ return;
3886
+ }
3887
+ formValue = addFormValue(formValue, fieldInfo, useTypeValue);
3888
+ }
3889
+ resolve(formValue);
3890
+ });
3891
+ }
3892
+ getFormDataValue(formValue, validationCheck) {
3893
+ if (validationCheck !== true) {
3894
+ let reval = new FormData();
3895
+ for (let [key, value] of Object.entries(formValue)) {
3896
+ reval.set(key, value);
3897
+ }
3898
+ for (let [key, fieldInfo] of Object.entries(this.allFieldInfo)) {
3899
+ addFieldFormData(reval, fieldInfo, fieldInfo.$instance.getValue());
3900
+ }
3901
+ return reval;
3902
+ }
3903
+ return new Promise((resolve, reject) => {
3904
+ let reval = new FormData();
3905
+ for (let [key, value] of Object.entries(formValue)) {
3906
+ reval.set(key, value);
3907
+ }
3908
+ for (let [key, fieldInfo] of Object.entries(this.allFieldInfo)) {
3909
+ if (!fieldInfo.$instance.isEnableView()) {
3910
+ continue;
3911
+ }
3912
+ let fieldValid = this.getFieldValidation(fieldInfo, true);
3913
+ if (fieldValid !== true) {
3914
+ reject(new Error(fieldValid.message, { cause: fieldValid }));
3915
+ return;
3916
+ }
3917
+ addFieldFormData(reval, fieldInfo, fieldInfo.$instance.getValue());
3918
+ }
3919
+ resolve(reval);
3920
+ });
3921
+ }
3922
+ /**
3923
+ *
3924
+ *
3925
+ * @param field
3926
+ * @returns
3927
+ */
3928
+ isConditionFieldCheck(field) {
3929
+ let parent = field;
3930
+ while (typeof parent !== "undefined") {
3931
+ if (!this.isConditionField(parent)) {
3932
+ return false;
3933
+ }
3934
+ parent = parent.$parent;
3935
+ }
3936
+ return true;
3937
+ }
3938
+ /**
3939
+ * field 활성 비활성화 여부.
3940
+ *
3941
+ * @param field form field
3942
+ * @returns
3943
+ */
3944
+ isConditionField(field) {
3945
+ if (!this.conditionFields.includes(field.$key)) {
3946
+ return true;
3947
+ }
3948
+ let condFlag = false;
3949
+ if (field.conditional.custom) {
3950
+ condFlag = field.conditional.custom.call(null, field);
3951
+ } else {
3952
+ if (field.conditional.field) {
3953
+ const condField = this.getFieldName(field.conditional.field);
3954
+ if (condField) {
3955
+ if (field.conditional.eq == condField.$instance.getValue()) {
3956
+ condFlag = true;
3957
+ }
3958
+ }
3959
+ }
3960
+ }
3961
+ return condFlag;
3962
+ }
3963
+ /**
3964
+ * 컬럼 로우 보이고 안보이기 체크.
3965
+ *
3966
+ * @public
3967
+ */
3968
+ conditionCheck() {
3969
+ this.conditionFields.forEach((fieldKey) => {
3970
+ const fieldInfo = this.allFieldInfo[fieldKey];
3971
+ let condFlag = this.isConditionField(fieldInfo);
3972
+ if (condFlag) {
3973
+ fieldInfo.$instance.show();
3974
+ } else {
3975
+ fieldInfo.$instance.hide();
3976
+ }
3977
+ });
3978
+ }
3979
+ /**
3980
+ * field validation check
3981
+ *
3982
+ * @param fieldInfo FormField
3983
+ * @returns boolean true or ValidResult
3984
+ */
3985
+ getFieldValidation(fieldInfo, focusFlag) {
3986
+ if (!this.isConditionFieldCheck(fieldInfo)) {
3987
+ return true;
3988
+ }
3989
+ const renderInfo = fieldInfo.$instance;
3990
+ let fieldValid = renderInfo.valid();
3991
+ if (fieldValid === true)
3992
+ return true;
3993
+ if (focusFlag) {
3994
+ renderInfo.focus();
3995
+ }
3996
+ fieldValid = fieldValid;
3997
+ if (isUndefined(fieldValid.message)) {
3998
+ fieldValid.message = Lanauage_default.validMessage(fieldInfo, fieldValid)[0];
3999
+ }
4000
+ return fieldValid;
4001
+ }
4002
+ };
4003
+ function addFormValue(formData, fieldInfo, useTypeValue) {
4004
+ if (ignoreValueField(fieldInfo)) {
4005
+ return formData;
4006
+ }
4007
+ const fieldValue = fieldInfo.$instance.getValue();
4008
+ if (fieldInfo.renderType === "file") {
4009
+ const uploadFiles = fieldValue["uploadFile"];
4010
+ formData[fieldInfo.$validName] = uploadFiles;
4011
+ formData[fieldInfo.$validName + "RemoveIds"] = fieldValue["removeIds"];
4012
+ } else {
4013
+ if (useTypeValue !== true) {
4014
+ if (isTabType(fieldInfo)) {
4015
+ for (let [key, value] of Object.entries(fieldValue)) {
4016
+ formData[key] = value;
4017
+ }
4018
+ } else {
4019
+ if (!isEmpty(fieldInfo.name)) {
4020
+ formData[fieldInfo.name] = fieldValue;
4021
+ }
4022
+ }
4023
+ } else {
4024
+ formData[fieldInfo.$validName] = fieldValue;
4025
+ }
4026
+ }
4027
+ return formData;
4028
+ }
4029
+ function addFieldFormData(formData, fieldInfo, useTypeValue) {
4030
+ if (ignoreValueField(fieldInfo)) {
4031
+ return formData;
4032
+ }
4033
+ const fieldValue = fieldInfo.$instance.getValue();
4034
+ if (fieldInfo.renderType === "file") {
4035
+ const uploadFiles = fieldValue["uploadFile"];
4036
+ formData.delete(fieldInfo.$validName);
4037
+ for (let uploadFile of uploadFiles) {
4038
+ formData.append(fieldInfo.$validName, uploadFile);
4039
+ }
4040
+ formData.set(fieldInfo.$validName + "RemoveIds", fieldValue["removeIds"]);
4041
+ } else {
4042
+ if (useTypeValue !== true) {
4043
+ if (isTabType(fieldInfo)) {
4044
+ for (let [key, value] of Object.entries(fieldValue)) {
4045
+ formData.set(key, value);
4046
+ }
4047
+ } else {
4048
+ if (!isEmpty(fieldInfo.name)) {
4049
+ formData.set(fieldInfo.$validName, fieldValue);
4050
+ }
4051
+ }
4052
+ } else {
4053
+ formData.set(fieldInfo.$validName, fieldValue);
4054
+ }
4055
+ }
4056
+ return formData;
4057
+ }
4058
+
4059
+ // src/FormTemplate.ts
4060
+ var FormTemplate = class {
4061
+ constructor(daraform, formElement, fieldInfoMap) {
4062
+ this.addRowFields = [];
4063
+ this.daraform = daraform;
4064
+ this.options = daraform.getOptions();
4065
+ this.formElement = formElement;
4066
+ this.fieldInfoMap = fieldInfoMap;
4067
+ }
4068
+ /**
4069
+ * field row 추가.
4070
+ *
4071
+ * @param field
4072
+ */
4073
+ addRow(field) {
4074
+ if (this.checkHiddenField(field)) {
4075
+ return;
4076
+ }
4077
+ this.addRowFields = [];
4078
+ this.addRowTemplate(field);
4079
+ }
4080
+ /**
4081
+ * 그룹 템플릿
4082
+ *
4083
+ * @param {FormField} field
4084
+ * @returns {string} row template
4085
+ */
4086
+ addRowTemplate(field) {
4087
+ let labelHideFlag = this.isLabelHide(field);
4088
+ let fieldStyle = styleUtils_default.fieldStyle(this.options, field, null, labelHideFlag);
4089
+ this.addRowFieldInfo(field);
4090
+ const rowElement = templateToElement(`
4091
+ <div class="df-row form-group ${fieldStyle.fieldClass}" id="${field.$key}">
4092
+ ${labelHideFlag ? "" : `<div class="df-label ${fieldStyle.labelClass} ${fieldStyle.labelAlignClass}" title="${field.label ?? ""}" style="${fieldStyle.labelStyle}">${this.getLabelTemplate(field)}</div>`}
4093
+
4094
+ <div class="df-field-container ${fieldStyle.valueClass} ${field.required ? "required" : ""}" style="${fieldStyle.valueStyle}"></div>
4095
+ </div>
4096
+ `);
4097
+ if (rowElement) {
4098
+ this.createField(field, rowElement);
4099
+ this.formElement.append(rowElement);
4100
+ if (field.children) {
4101
+ this.childTemplate(field, fieldStyle);
4102
+ }
4103
+ }
4104
+ }
4105
+ createField(field, element) {
4106
+ field.$instance = new field.$renderType(field, element, this.daraform);
4107
+ }
4108
+ /**
4109
+ * child template
4110
+ *
4111
+ * @param {FormField} field
4112
+ * @param {FieldStyle} parentFieldStyle
4113
+ * @returns {*}
4114
+ */
4115
+ childTemplate(field, parentFieldStyle) {
4116
+ let beforeField = null;
4117
+ let firstFlag = true;
4118
+ let isEmptyLabel = false;
4119
+ if (!field.$renderType.isChildrenCreate()) {
4120
+ return;
4121
+ }
4122
+ const rowElement = document.createElement("div");
4123
+ rowElement.classList.add("df-row", parentFieldStyle.rowStyleClass ?? "");
4124
+ let idx = 0;
4125
+ for (const childField of field.children) {
4126
+ if (isEmpty(childField)) {
4127
+ throw new Error(`parent field :[${field.$validName}], children index ${idx}, empty [${childField}]`);
4128
+ }
4129
+ childField.$parent = field;
4130
+ ++idx;
4131
+ if (this.checkHiddenField(childField)) {
4132
+ continue;
4133
+ }
4134
+ this.addRowFieldInfo(childField);
4135
+ if (firstFlag) {
4136
+ beforeField = childField;
4137
+ }
4138
+ let labelHideFlag = this.isLabelHide(childField);
4139
+ let childFieldStyle;
4140
+ let labelTemplate = "";
4141
+ if (labelHideFlag) {
4142
+ childFieldStyle = styleUtils_default.fieldStyle(this.options, childField, beforeField, !isEmptyLabel);
4143
+ labelTemplate = isEmptyLabel ? `<span class="df-label empty ${childFieldStyle.labelClass}" style="${childFieldStyle.labelStyle}"></span>` : "";
4144
+ } else {
4145
+ childFieldStyle = styleUtils_default.fieldStyle(this.options, childField, beforeField, false);
4146
+ labelTemplate = `<span class="df-label ${childFieldStyle.labelClass} ${childFieldStyle.labelAlignClass}" title="${childField.label ?? ""}" style="${childFieldStyle.labelStyle}">${this.getLabelTemplate(childField)}</span>`;
4147
+ }
4148
+ const groupElement = templateToElement(`<div class="form-group ${childFieldStyle.fieldClass}" style="${childFieldStyle.fieldStyle}" id="${childField.$key}">
4149
+ ${labelTemplate}
4150
+ <span class="df-field-container ${childFieldStyle.valueClass} ${childField.required ? "required" : ""}" style="${childFieldStyle.valueStyle}"></span>
4151
+ </div>`);
4152
+ if (groupElement) {
4153
+ this.createField(childField, groupElement);
4154
+ rowElement.append(groupElement);
4155
+ if (childField.children) {
4156
+ this.childTemplate(childField, childField.children ? childFieldStyle : parentFieldStyle);
4157
+ }
4158
+ }
4159
+ if (!labelHideFlag) {
4160
+ isEmptyLabel = true;
4161
+ }
4162
+ firstFlag = false;
4163
+ }
4164
+ field.$instance.addChildField(rowElement);
4165
+ }
4166
+ /**
4167
+ * label template
4168
+ *
4169
+ * @param {FormField} field form field
4170
+ * @returns {string} template string
4171
+ */
4172
+ getLabelTemplate(field) {
4173
+ const requiredTemplate = field.required ? `<span class="required"></span>` : "";
4174
+ const tooltipTemplate = isBlank(field.tooltip) ? "" : `<span class="df-tooltip">?<span class="tooltip">${field.tooltip}</span></span>`;
4175
+ return `${field.label ?? ""} ${tooltipTemplate} ${requiredTemplate}`;
4176
+ }
4177
+ /**
4178
+ * label 숨김 여부
4179
+ *
4180
+ * @param field formfield
4181
+ * @returns
4182
+ */
4183
+ isLabelHide(field) {
4184
+ return field.style?.labelHide || isUndefined(field.label);
4185
+ }
4186
+ checkHiddenField(field) {
4187
+ if (isHiddenField(field)) {
4188
+ this.fieldInfoMap.addField(field);
4189
+ field.$instance = new field.$renderType(field, null, this.daraform);
4190
+ return true;
4191
+ }
4192
+ return false;
4193
+ }
4194
+ /**
4195
+ * add row file map
4196
+ *
4197
+ * @param {FormField} field
4198
+ */
4199
+ addRowFieldInfo(field) {
4200
+ if (!isBlank(field.name) && this.fieldInfoMap.hasFieldName(field.name)) {
4201
+ throw new Error(`Duplicate field name "${field.name}"`);
4202
+ }
4203
+ this.fieldInfoMap.addField(field);
4204
+ this.addRowFields.push(field.$key);
4205
+ }
4206
+ };
4207
+
4208
+ // src/DaraForm.ts
4209
+ var defaultOptions = {
4210
+ style: {
4211
+ width: "100%",
4212
+ labelWidth: 3,
4213
+ valueWidth: 9,
4214
+ position: "left-right"
4215
+ },
4216
+ mode: "new",
4217
+ useTypeValue: true,
4218
+ autoCreate: true,
4219
+ notValidMessage: "This form is not valid.",
4220
+ fields: []
4221
+ };
4222
+ var allInstance = {};
4223
+ var SEQ_ATTR_KEY = "data-form-uid";
4224
+ var DARA_FORM_SEQ = 0;
4225
+ var DaraForm = class _DaraForm {
4226
+ constructor(formElement, options, message2) {
4227
+ this.formValue = {};
4228
+ /**
4229
+ * change mode
4230
+ *
4231
+ * @param mode form_mode default new
4232
+ */
4233
+ this.changeMode = (mode) => {
4234
+ this.options.mode = mode;
4235
+ this.formElement.setAttribute("data-df-mode", mode);
4236
+ };
4237
+ /**
4238
+ * 폼 데이터 reset
4239
+ */
4240
+ this.resetForm = () => {
4241
+ const fieldMap = this.fieldInfoMap.getAllFieldInfo();
4242
+ for (const seq in fieldMap) {
4243
+ const fieldInfo = fieldMap[seq];
4244
+ const renderInfo = fieldInfo.$instance;
4245
+ if (renderInfo && typeof renderInfo.reset === "function") {
4246
+ renderInfo.reset();
4247
+ }
4248
+ }
4249
+ this.formValue = {};
4250
+ this.conditionCheck();
4251
+ };
4252
+ /**
4253
+ * field 값 reset
4254
+ * @param fieldName 필드명
4255
+ */
4256
+ this.resetField = (fieldName) => {
4257
+ this.fieldInfoMap.getFieldName(fieldName).$instance.reset();
4258
+ this.formValue[fieldName] = "";
4259
+ this.conditionCheck();
4260
+ };
4261
+ /**
4262
+ * field 값 얻기
4263
+ *
4264
+ * @param fieldName 필드명
4265
+ * @returns
4266
+ */
4267
+ this.getFieldValue = (fieldName) => {
4268
+ const field = this.fieldInfoMap.getFieldName(fieldName);
4269
+ if (field) {
4270
+ return field.$instance.getValue();
4271
+ }
4272
+ return null;
4273
+ };
4274
+ /**
4275
+ * 폼 필드 값 얻기
4276
+ * @param isValid 폼 유효성 검사 여부 default:false|undefined true일경우 검사.
4277
+ * @returns
4278
+ */
4279
+ this.getValue = (isValid) => {
4280
+ return this.fieldInfoMap.getAllFieldValue(this.formValue, isValid);
4281
+ };
4282
+ this.getFormDataValue = (isValid) => {
4283
+ return this.fieldInfoMap.getFormDataValue(this.formValue, isValid);
4284
+ };
4285
+ /**
4286
+ * 폼 필드 value 셋팅
4287
+ * @param values
4288
+ */
4289
+ this.setValue = (values, dataClear) => {
4290
+ if (dataClear !== false) {
4291
+ this.resetForm();
4292
+ }
4293
+ Object.keys(values).forEach((fieldName) => {
4294
+ this._setFieldValue(fieldName, values[fieldName]);
4295
+ });
4296
+ this.conditionCheck();
4297
+ };
4298
+ this.setFieldValue = (fieldName, value) => {
4299
+ this._setFieldValue(fieldName, value);
4300
+ this.conditionCheck();
4301
+ };
4302
+ this.setFieldItems = (fieldName, values) => {
4303
+ const field = this.fieldInfoMap.getFieldName(fieldName);
4304
+ if (field) {
4305
+ return field.$instance.setValueItems(values);
4306
+ }
4307
+ };
4308
+ /**
4309
+ * field 추가
4310
+ *
4311
+ * @param {FormField} field
4312
+ */
4313
+ this.addField = (field) => {
4314
+ this.options.fields.push(field);
4315
+ this.formTemplate.addRow(field);
4316
+ this.conditionCheck();
4317
+ };
4318
+ /**
4319
+ * field 제거
4320
+ *
4321
+ * @param {string} fieldName
4322
+ */
4323
+ this.removeField = (fieldName) => {
4324
+ const element = this.getFieldElement(fieldName);
4325
+ if (element != null) {
4326
+ element.closest(".df-row")?.remove();
4327
+ }
4328
+ this.fieldInfoMap.removeFieldInfo(fieldName);
4329
+ };
4330
+ /**
4331
+ * 폼 유효성 검증 여부
4332
+ *
4333
+ * @returns {boolean}
4334
+ */
4335
+ this.isValidForm = () => {
4336
+ const result = this.validForm();
4337
+ return result.length < 1;
4338
+ };
4339
+ /**
4340
+ * 유효성 검증 폼 검증여부 리턴
4341
+ *
4342
+ * @returns {any[]}
4343
+ */
4344
+ this.validForm = () => {
4345
+ let validResult = [];
4346
+ let autoFocusFlag = this.options.autoFocus !== false;
4347
+ let firstFlag = true;
4348
+ const fieldMap = this.fieldInfoMap.getAllFieldInfo();
4349
+ for (const fieldKey in fieldMap) {
4350
+ const fieldInfo = fieldMap[fieldKey];
4351
+ let fieldValid = this.fieldInfoMap.getFieldValidation(fieldInfo, autoFocusFlag);
4352
+ if (fieldValid !== true) {
4353
+ autoFocusFlag = false;
4354
+ if (isGridType(fieldInfo)) {
4355
+ validResult = validResult.concat(fieldValid);
4356
+ } else {
4357
+ if (firstFlag) {
4358
+ this.validTabCheck(fieldInfo);
4359
+ firstFlag = false;
4360
+ }
4361
+ validResult.push(fieldValid);
4362
+ }
4363
+ }
4364
+ }
4365
+ return validResult;
4366
+ };
4367
+ this.isValidField = (fieldName) => {
4368
+ const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
4369
+ if (isUndefined(fieldInfo)) {
4370
+ throw new Error(`Field name [${fieldName}] not found`);
4371
+ }
4372
+ const renderInfo = fieldInfo.$instance;
4373
+ if (renderInfo) {
4374
+ return renderInfo.valid() === true;
4375
+ }
4376
+ return true;
4377
+ };
4378
+ /**
4379
+ * 설정 옵션 얻기
4380
+ */
4381
+ this.getOptions = () => {
4382
+ return this.options;
4383
+ };
4384
+ this.destroy = () => {
4385
+ this.formElement.className = this.orginFormStyleClass;
4386
+ this.formElement.replaceChildren();
4387
+ for (const key in this) {
4388
+ if (hasOwnProp(this, key)) {
4389
+ delete this[key];
4390
+ delete allInstance[this.selector];
4391
+ }
4392
+ }
4393
+ };
4394
+ /**
4395
+ * 모든 field 얻기
4396
+ */
4397
+ this.getFields = () => {
4398
+ return this.options.fields;
4399
+ };
4400
+ /**
4401
+ * field setting
4402
+ * @param fields
4403
+ */
4404
+ this.setFields = (fields) => {
4405
+ this.options.fields = fields;
4406
+ this.createForm(fields);
4407
+ };
4408
+ this.options = merge({}, defaultOptions, options);
4409
+ Lanauage_default.set(message2);
4410
+ if (formElement) {
4411
+ this.orginFormStyleClass = formElement.className;
4412
+ formElement.classList.add("daracl-form");
4413
+ this.selector = `df_${++DARA_FORM_SEQ}`;
4414
+ formElement.setAttribute("name", this.selector);
4415
+ formElement.setAttribute(SEQ_ATTR_KEY, this.selector);
4416
+ if (this.options.style.width) {
4417
+ formElement.setAttribute("style", `width:${this.options.style.width};`);
4418
+ }
4419
+ this.formElement = formElement;
4420
+ this.changeMode(this.options.mode ?? "new");
4421
+ this.createForm(this.options.fields);
4422
+ if (this.options.autoCreate !== false) {
4423
+ allInstance[this.selector] = this;
4424
+ }
4425
+ } else {
4426
+ throw new Error(`${formElement} form selector not found`);
4427
+ }
4428
+ }
4429
+ static {
4430
+ this.VERSION = `${APP_VERSION}`;
4431
+ }
4432
+ static create(formElement, options, message2) {
4433
+ return new _DaraForm(formElement, options, message2);
4434
+ }
4435
+ static setMessage(message2) {
4436
+ Lanauage_default.set(message2);
4437
+ }
4438
+ createForm(fields) {
4439
+ this.fieldInfoMap = new FieldInfoMap(this.selector, this);
4440
+ this.formTemplate = new FormTemplate(this, this.formElement, this.fieldInfoMap);
4441
+ if (this.options.autoCreate === false) {
4442
+ return;
4443
+ }
4444
+ fields.forEach((field) => {
4445
+ this.formTemplate.addRow(field);
4446
+ });
4447
+ this.conditionCheck();
4448
+ if (this.options.onMounted) {
4449
+ this.options.onMounted.call(this);
4450
+ }
4451
+ }
4452
+ /**
4453
+ * 필드 element 얻기
4454
+ *
4455
+ * @param {string} fieldName
4456
+ * @returns {*}
4457
+ */
4458
+ getFieldElement(fieldName) {
4459
+ const field = this.fieldInfoMap.getFieldName(fieldName);
4460
+ if (field?.$instance) {
4461
+ return field.$instance.getElement();
4462
+ }
4463
+ return null;
4464
+ }
4465
+ getField(fieldName) {
4466
+ return this.fieldInfoMap.getFieldName(fieldName);
4467
+ }
4468
+ _setFieldValue(fieldName, value) {
4469
+ this.formValue[fieldName] = value;
4470
+ const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
4471
+ if (fieldInfo) {
4472
+ fieldInfo.$instance.setValue(value);
4473
+ }
4474
+ }
4475
+ validTabCheck(fieldInfo) {
4476
+ if (fieldInfo.$parent) {
4477
+ if (fieldInfo.$parent.renderType == "tab") {
4478
+ fieldInfo.$parent.$instance.setActive(fieldInfo.$key);
4479
+ }
4480
+ this.validTabCheck(fieldInfo.$parent);
4481
+ }
4482
+ }
4483
+ conditionCheck() {
4484
+ this.fieldInfoMap.conditionCheck();
4485
+ }
4486
+ setFieldDisabled(fieldName, flag) {
4487
+ const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
4488
+ fieldInfo.$instance.setDisabled(flag);
4489
+ }
4490
+ /**
4491
+ * 설명 추가
4492
+ *
4493
+ * @public
4494
+ * @param {string} fieldName
4495
+ * @param {string} desc
4496
+ */
4497
+ setFieldDescription(fieldName, desc) {
4498
+ const fieldInfo = this.fieldInfoMap.getFieldName(fieldName);
4499
+ fieldInfo.$instance.setDescription(desc);
4500
+ }
4501
+ static {
4502
+ this.validator = {
4503
+ string: (value, field) => {
4504
+ return stringValidator(value, field);
4505
+ },
4506
+ number: (value, field) => {
4507
+ return numberValidator(value, field);
4508
+ },
4509
+ regexp: (value, field) => {
4510
+ let result = { name: field.name, constraint: [] };
4511
+ return regexpValidator(value, field, result);
4512
+ }
4513
+ };
4514
+ }
4515
+ static instance(ele) {
4516
+ let element;
4517
+ if (isString(ele)) {
4518
+ element = document.querySelector(ele);
4519
+ } else {
4520
+ element = ele;
4521
+ }
4522
+ element = element;
4523
+ let selector = element.getAttribute(SEQ_ATTR_KEY);
4524
+ if (isUndefined(selector) || isBlank(selector)) {
4525
+ const keys = Object.keys(allInstance);
4526
+ if (keys.length > 1) {
4527
+ throw new Error(`selector empty : [${selector}]`);
4528
+ }
4529
+ selector = keys[0];
4530
+ return allInstance[selector];
4531
+ }
4532
+ }
4533
+ getFieldInfoMap() {
4534
+ return this.fieldInfoMap;
4535
+ }
4536
+ };
4537
+
4538
+ // src/index.ts
4539
+ module.exports = DaraForm;
4540
+ //# sourceMappingURL=index.cjs.map