@g1cloud/open-bluesea-core 1.0.0-alpha.10 → 1.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import { ComponentOptionsBase } from 'vue';
8
8
  import { ComponentOptionsMixin } from 'vue';
9
9
  import { ComponentProvideOptions } from 'vue';
10
10
  import { ComponentPublicInstance } from 'vue';
11
+ import { ComputedRef } from 'vue';
11
12
  import { CreateComponentPublicInstanceWithMixins } from 'vue';
12
13
  import { DebuggerEvent } from 'vue';
13
14
  import { DefineComponent } from 'vue';
@@ -1087,16 +1088,55 @@ export declare const emptyLabelProvider: <T>(_item: T) => undefined;
1087
1088
 
1088
1089
  export declare type EnabledItemProvider<T> = (item: T) => boolean;
1089
1090
 
1091
+ export declare const executeBetweenLengthValidation: (text: string, minLength: number | undefined, minLengthMessage: string | undefined, maxLength: number | undefined, maxLengthMessage: string | undefined, betweenLengthMessage: string | undefined, errors: ValidationError[]) => boolean;
1092
+
1093
+ export declare const executeBetweenValueValidation: (value: number, minValue: number | undefined, minValueMessage: string | undefined, maxValue: number | undefined, maxValueMessage: string | undefined, betweenValueMessage: string | undefined, errors: ValidationError[]) => boolean;
1094
+
1095
+ export declare const executeDateRangeValidation: (fromValue: string | undefined, toValue: string | undefined, validationMessage: string | undefined, erros: ValidationError[]) => boolean;
1096
+
1097
+ export declare const executeFieldValidationRule: <T>(value: T, rules: FieldValidationRule<T>[] | undefined, errors: ValidationError[], phase: ValidationPhase, fieldContext?: FieldContext<any>) => Promise<boolean>;
1098
+
1090
1099
  export declare const executeKeyProviderOrDefault: <T>(item: T, keyProvider: KeyProvider<T> | undefined, defaultKey: (item: T) => string) => string;
1091
1100
 
1092
1101
  export declare const executeLabelProviderOrDefault: <T>(item: T, labelProvider: LabelProvider<T> | undefined, defaultLabel: (item: T) => string) => string;
1093
1102
 
1103
+ export declare const executeRegExpValidation: (value: string, regexp: string | undefined, message: string | undefined, errors: ValidationError[]) => boolean;
1104
+
1105
+ export declare const executeRequiredValidation: (value: string | number | undefined, checkRequired: boolean, requiredMessage: string | undefined, errors: ValidationError[]) => boolean;
1106
+
1094
1107
  export declare type FieldContext<T> = {
1095
1108
  iteration?: IterationContext<T>;
1096
1109
  locale?: LocaleName;
1097
1110
  };
1098
1111
 
1099
- declare type FieldValidationRule<T> = (value: T, phase: ValidationPhase, fieldContext?: FieldContext<any>) => Promise<ValidationError[] | undefined> | ValidationError[] | undefined;
1112
+ export declare type FieldValidationRule<T> = (value: T, phase: ValidationPhase, fieldContext?: FieldContext<any>) => Promise<ValidationError[] | undefined> | ValidationError[] | undefined;
1113
+
1114
+ export declare type FieldValidator<T> = {
1115
+ stringValue: Ref<string | undefined>;
1116
+ value: Ref<UnwrapRef<T> | undefined>;
1117
+ valid: Ref<boolean>;
1118
+ errors: Ref<ValidationError[]>;
1119
+ touched: Ref<boolean>;
1120
+ handleInput: (event: Event) => Promise<void>;
1121
+ handleChange: (event: Event) => Promise<void>;
1122
+ handleFocus: (event: Event) => void;
1123
+ handleBlur: (event: Event) => void;
1124
+ validateValue: (value: UnwrapRef<T>, phase: ValidationPhase) => Promise<void>;
1125
+ validate: (phase?: ValidationPhase) => Promise<void>;
1126
+ clearErrors: () => void;
1127
+ getName: () => string;
1128
+ };
1129
+
1130
+ export declare const fieldValidator: <T>(option: FieldValidatorOption<T>) => FieldValidator<T>;
1131
+
1132
+ export declare type FieldValidatorOption<T> = {
1133
+ field?: Ref<HTMLElement | undefined>;
1134
+ disabled: Ref<boolean> | ComputedRef<boolean>;
1135
+ initialValue?: T;
1136
+ isValid?: (value: UnwrapRef<T> | undefined, phase: ValidationPhase) => undefined | ValidationError[] | Promise<ValidationError[]>;
1137
+ convertToValue?: (value: string | undefined) => UnwrapRef<T>;
1138
+ convertFromValue?: (value: UnwrapRef<T | undefined>) => string;
1139
+ };
1100
1140
 
1101
1141
  /**
1102
1142
  * HTMLElement, Component(vue) 로부터 실제 HTMLElement 를 찾아온다.
@@ -1120,6 +1160,8 @@ declare type FieldValidationRule<T> = (value: T, phase: ValidationPhase, fieldCo
1120
1160
  */
1121
1161
  export declare const findElement: (maybeElement: Ref<HTMLElement | Component | undefined | null> | undefined) => HTMLElement | undefined;
1122
1162
 
1163
+ export declare const findFieldValidatorElements: (element?: HTMLElement) => NodeListOf<HTMLElement> | undefined;
1164
+
1123
1165
  /**
1124
1166
  * 첫 번재 focusable 한 element 를 찾는다.
1125
1167
  * @param element
@@ -1217,6 +1259,43 @@ export declare const formatUtil: {
1217
1259
  toPlainText(textIncludedHTMLElement?: string): string;
1218
1260
  };
1219
1261
 
1262
+ export declare type FormValidationError = ValidationError & {
1263
+ name?: string;
1264
+ };
1265
+
1266
+ export declare type FormValidationRule = (phase?: ValidationPhase) => Promise<FormValidationError[] | undefined>;
1267
+
1268
+ export declare type FormValidator = {
1269
+ /**
1270
+ * Form 안의 모든 FieldValidator 에 대해서 validation 을 수행하고, 그 결과를 리턴한다.
1271
+ */
1272
+ validationResult: () => Promise<FormValidationError[] | undefined>;
1273
+ /**
1274
+ * Form 안의 모든 FieldValidator 에 대해서 validation 을 수행한다.
1275
+ */
1276
+ validate: () => Promise<void>;
1277
+ /**
1278
+ * Form 안의 FieldValidator 를 모두 가져온다.
1279
+ */
1280
+ getFieldValidators: () => FieldValidator<unknown>[];
1281
+ /**
1282
+ * name 속성으로 FieldValidator 를 가져온다.
1283
+ * @param name
1284
+ */
1285
+ getFieldValidator: (name: string) => FieldValidator<unknown> | undefined;
1286
+ /**
1287
+ * validation result 를 모두 제거하고, validation 을 수행하지 않은 상태로 돌아간다.
1288
+ */
1289
+ clear: () => void;
1290
+ };
1291
+
1292
+ export declare const formValidator: (option: FormValidatorOption) => FormValidator;
1293
+
1294
+ export declare type FormValidatorOption = {
1295
+ element?: Ref<HTMLElement | Component | undefined | null>;
1296
+ rules?: FormValidationRule[];
1297
+ };
1298
+
1220
1299
  export declare type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
1221
1300
 
1222
1301
  export declare type FunctionPropertyNames<T> = {
@@ -1256,6 +1335,8 @@ export declare class IllegalAccessError {
1256
1335
 
1257
1336
  export declare const isTooltipDisplayed: () => boolean;
1258
1337
 
1338
+ export declare const isValidationFailedError: (err: unknown) => err is ValidationFailedError;
1339
+
1259
1340
  export declare type IterationContext<T> = {
1260
1341
  componentName: string;
1261
1342
  record: T;
@@ -1268,6 +1349,8 @@ export declare type KeyProvider<T> = (item: T) => string | undefined;
1268
1349
 
1269
1350
  export declare type LabelProvider<T> = (item: T) => string | undefined;
1270
1351
 
1352
+ export declare const loadFieldValidator: <T>(field: HTMLElement) => FieldValidator<T> | undefined;
1353
+
1271
1354
  export declare type LocaleName = string;
1272
1355
 
1273
1356
  export declare type MenuItem = {
@@ -1492,6 +1575,8 @@ export declare type StoredFile = {
1492
1575
  thumbnailFile?: File;
1493
1576
  };
1494
1577
 
1578
+ export declare const storeFieldValidator: <T>(field: HTMLElement, validator: FieldValidator<T>) => void;
1579
+
1495
1580
  export declare type TimeZone = string;
1496
1581
 
1497
1582
  export declare type TooltipEntry = {
@@ -1524,12 +1609,21 @@ export declare const useModalHandle: () => ModalHandle;
1524
1609
 
1525
1610
  export declare const useSavePoint: () => SavePoint | undefined;
1526
1611
 
1527
- declare type ValidationError = {
1612
+ export declare const validateField: (field: HTMLElement | string, phase?: ValidationPhase) => Promise<void>;
1613
+
1614
+ export declare const validateFields: (fields: (HTMLElement | string)[], phase?: ValidationPhase) => Promise<void>;
1615
+
1616
+ export declare type ValidationError = {
1528
1617
  code: string;
1529
1618
  message: string | undefined;
1530
1619
  };
1531
1620
 
1532
- declare type ValidationPhase = 'input' | 'change' | 'blur' | 'form';
1621
+ export declare class ValidationFailedError {
1622
+ errors: FormValidationError[];
1623
+ constructor(errors: FormValidationError[]);
1624
+ }
1625
+
1626
+ export declare type ValidationPhase = 'input' | 'change' | 'blur' | 'form';
1533
1627
 
1534
1628
  /**
1535
1629
  * ```
@@ -1100,6 +1100,22 @@ const storeFieldValidator = (field, validator) => {
1100
1100
  field._bsFieldValidator = validator;
1101
1101
  field.setAttribute("data-bs-field-validator", "");
1102
1102
  };
1103
+ const loadFieldValidator = (field) => {
1104
+ return field._bsFieldValidator;
1105
+ };
1106
+ const findFieldValidatorElements = (element) => {
1107
+ return element?.querySelectorAll("[data-bs-field-validator]");
1108
+ };
1109
+ const validateField = async (field, phase) => {
1110
+ const element = typeof field === "string" ? document.getElementsByName(field)[0] : field;
1111
+ const validator = element ? loadFieldValidator(element) : void 0;
1112
+ await validator?.validate(phase);
1113
+ };
1114
+ const validateFields = async (fields, phase) => {
1115
+ for (const field of fields) {
1116
+ await validateField(field, phase);
1117
+ }
1118
+ };
1103
1119
  const fieldValidator = (option) => {
1104
1120
  const stringValue = ref();
1105
1121
  const value = ref(option.initialValue);
@@ -5455,6 +5471,60 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
5455
5471
  };
5456
5472
  }
5457
5473
  });
5474
+ class ValidationFailedError {
5475
+ constructor(errors) {
5476
+ this.errors = errors;
5477
+ }
5478
+ }
5479
+ const isValidationFailedError = (err) => {
5480
+ return err instanceof ValidationFailedError;
5481
+ };
5482
+ const formValidator = (option) => {
5483
+ const getFieldValidators = () => {
5484
+ const element = option.element ? findElement(option.element) : void 0;
5485
+ return Array.from(findFieldValidatorElements(element) || []).map((el) => loadFieldValidator(el)).filter(notNull);
5486
+ };
5487
+ const getFieldValidator = (name) => {
5488
+ return getFieldValidators().find((validator) => validator.getName() === name);
5489
+ };
5490
+ const validationResult = async (phase = "form") => {
5491
+ const validators = getFieldValidators();
5492
+ const invalids = [];
5493
+ for (const validator of validators) {
5494
+ await validator.validate(phase);
5495
+ if (!validator.valid.value) invalids.push(validator);
5496
+ }
5497
+ if (invalids.length > 0) {
5498
+ return invalids.flatMap((invalid) => invalid.errors.value.map((error) => ({ name: invalid.getName(), ...error })));
5499
+ }
5500
+ const errors = [];
5501
+ if (option.rules) {
5502
+ for (const rule of option.rules) {
5503
+ const result = await rule(phase);
5504
+ result?.forEach((error) => errors.push(error));
5505
+ }
5506
+ }
5507
+ return errors.length > 0 ? errors : void 0;
5508
+ };
5509
+ const validate = async (phase = "form") => {
5510
+ const result = await validationResult(phase);
5511
+ if (result) {
5512
+ throw new ValidationFailedError(result);
5513
+ }
5514
+ };
5515
+ const clear = () => {
5516
+ getFieldValidators().forEach((validator) => {
5517
+ validator.clearErrors();
5518
+ });
5519
+ };
5520
+ return {
5521
+ validationResult,
5522
+ validate,
5523
+ getFieldValidators,
5524
+ getFieldValidator,
5525
+ clear
5526
+ };
5527
+ };
5458
5528
  class IllegalAccessError {
5459
5529
  }
5460
5530
  export {
@@ -5494,6 +5564,7 @@ export {
5494
5564
  IllegalAccessError,
5495
5565
  NAMED_COLORS,
5496
5566
  SavePointImpl,
5567
+ ValidationFailedError,
5497
5568
  alarmEntries,
5498
5569
  cancelProvidedSavePoint,
5499
5570
  closeAlarm,
@@ -5505,14 +5576,23 @@ export {
5505
5576
  defaultLabelProvider,
5506
5577
  emptyKeyProvider,
5507
5578
  emptyLabelProvider,
5579
+ executeBetweenLengthValidation,
5580
+ executeBetweenValueValidation,
5581
+ executeDateRangeValidation,
5582
+ executeFieldValidationRule,
5508
5583
  executeKeyProviderOrDefault,
5509
5584
  executeLabelProviderOrDefault,
5585
+ executeRegExpValidation,
5586
+ executeRequiredValidation,
5587
+ fieldValidator,
5510
5588
  findElement,
5589
+ findFieldValidatorElements,
5511
5590
  findFirstFocusableElement,
5512
5591
  findInputComponents,
5513
5592
  findLastFocusableElement,
5514
5593
  focusFirstElement,
5515
5594
  focusLastElement,
5595
+ formValidator,
5516
5596
  formatUtil,
5517
5597
  getComponentRootElement,
5518
5598
  getIcon,
@@ -5520,6 +5600,8 @@ export {
5520
5600
  hideLoading,
5521
5601
  hideTooltip,
5522
5602
  isTooltipDisplayed,
5603
+ isValidationFailedError,
5604
+ loadFieldValidator,
5523
5605
  modalHandleKey,
5524
5606
  modalPluginKey,
5525
5607
  notNull,
@@ -5534,6 +5616,7 @@ export {
5534
5616
  showLoadingIcon,
5535
5617
  showNotification,
5536
5618
  showTooltip,
5619
+ storeFieldValidator,
5537
5620
  tooltipEntry,
5538
5621
  tryUntil,
5539
5622
  useBlueseaConfig,
@@ -5547,6 +5630,8 @@ export {
5547
5630
  VFocusLoop as vFocusLoop,
5548
5631
  vFocusOnLoad,
5549
5632
  vTooltip,
5633
+ validateField,
5634
+ validateFields,
5550
5635
  waitDuring,
5551
5636
  waitUntil,
5552
5637
  withLoading
@@ -1102,6 +1102,22 @@
1102
1102
  field._bsFieldValidator = validator;
1103
1103
  field.setAttribute("data-bs-field-validator", "");
1104
1104
  };
1105
+ const loadFieldValidator = (field) => {
1106
+ return field._bsFieldValidator;
1107
+ };
1108
+ const findFieldValidatorElements = (element) => {
1109
+ return element?.querySelectorAll("[data-bs-field-validator]");
1110
+ };
1111
+ const validateField = async (field, phase) => {
1112
+ const element = typeof field === "string" ? document.getElementsByName(field)[0] : field;
1113
+ const validator = element ? loadFieldValidator(element) : void 0;
1114
+ await validator?.validate(phase);
1115
+ };
1116
+ const validateFields = async (fields, phase) => {
1117
+ for (const field of fields) {
1118
+ await validateField(field, phase);
1119
+ }
1120
+ };
1105
1121
  const fieldValidator = (option) => {
1106
1122
  const stringValue = vue.ref();
1107
1123
  const value = vue.ref(option.initialValue);
@@ -5465,6 +5481,60 @@
5465
5481
  };
5466
5482
  }
5467
5483
  });
5484
+ class ValidationFailedError {
5485
+ constructor(errors) {
5486
+ this.errors = errors;
5487
+ }
5488
+ }
5489
+ const isValidationFailedError = (err) => {
5490
+ return err instanceof ValidationFailedError;
5491
+ };
5492
+ const formValidator = (option) => {
5493
+ const getFieldValidators = () => {
5494
+ const element = option.element ? findElement(option.element) : void 0;
5495
+ return Array.from(findFieldValidatorElements(element) || []).map((el) => loadFieldValidator(el)).filter(notNull);
5496
+ };
5497
+ const getFieldValidator = (name) => {
5498
+ return getFieldValidators().find((validator) => validator.getName() === name);
5499
+ };
5500
+ const validationResult = async (phase = "form") => {
5501
+ const validators = getFieldValidators();
5502
+ const invalids = [];
5503
+ for (const validator of validators) {
5504
+ await validator.validate(phase);
5505
+ if (!validator.valid.value) invalids.push(validator);
5506
+ }
5507
+ if (invalids.length > 0) {
5508
+ return invalids.flatMap((invalid) => invalid.errors.value.map((error) => ({ name: invalid.getName(), ...error })));
5509
+ }
5510
+ const errors = [];
5511
+ if (option.rules) {
5512
+ for (const rule of option.rules) {
5513
+ const result = await rule(phase);
5514
+ result?.forEach((error) => errors.push(error));
5515
+ }
5516
+ }
5517
+ return errors.length > 0 ? errors : void 0;
5518
+ };
5519
+ const validate = async (phase = "form") => {
5520
+ const result = await validationResult(phase);
5521
+ if (result) {
5522
+ throw new ValidationFailedError(result);
5523
+ }
5524
+ };
5525
+ const clear = () => {
5526
+ getFieldValidators().forEach((validator) => {
5527
+ validator.clearErrors();
5528
+ });
5529
+ };
5530
+ return {
5531
+ validationResult,
5532
+ validate,
5533
+ getFieldValidators,
5534
+ getFieldValidator,
5535
+ clear
5536
+ };
5537
+ };
5468
5538
  class IllegalAccessError {
5469
5539
  }
5470
5540
  exports2.BSAlertModal = _sfc_main$4;
@@ -5503,6 +5573,7 @@
5503
5573
  exports2.IllegalAccessError = IllegalAccessError;
5504
5574
  exports2.NAMED_COLORS = NAMED_COLORS;
5505
5575
  exports2.SavePointImpl = SavePointImpl;
5576
+ exports2.ValidationFailedError = ValidationFailedError;
5506
5577
  exports2.alarmEntries = alarmEntries;
5507
5578
  exports2.cancelProvidedSavePoint = cancelProvidedSavePoint;
5508
5579
  exports2.closeAlarm = closeAlarm;
@@ -5514,14 +5585,23 @@
5514
5585
  exports2.defaultLabelProvider = defaultLabelProvider;
5515
5586
  exports2.emptyKeyProvider = emptyKeyProvider;
5516
5587
  exports2.emptyLabelProvider = emptyLabelProvider;
5588
+ exports2.executeBetweenLengthValidation = executeBetweenLengthValidation;
5589
+ exports2.executeBetweenValueValidation = executeBetweenValueValidation;
5590
+ exports2.executeDateRangeValidation = executeDateRangeValidation;
5591
+ exports2.executeFieldValidationRule = executeFieldValidationRule;
5517
5592
  exports2.executeKeyProviderOrDefault = executeKeyProviderOrDefault;
5518
5593
  exports2.executeLabelProviderOrDefault = executeLabelProviderOrDefault;
5594
+ exports2.executeRegExpValidation = executeRegExpValidation;
5595
+ exports2.executeRequiredValidation = executeRequiredValidation;
5596
+ exports2.fieldValidator = fieldValidator;
5519
5597
  exports2.findElement = findElement;
5598
+ exports2.findFieldValidatorElements = findFieldValidatorElements;
5520
5599
  exports2.findFirstFocusableElement = findFirstFocusableElement;
5521
5600
  exports2.findInputComponents = findInputComponents;
5522
5601
  exports2.findLastFocusableElement = findLastFocusableElement;
5523
5602
  exports2.focusFirstElement = focusFirstElement;
5524
5603
  exports2.focusLastElement = focusLastElement;
5604
+ exports2.formValidator = formValidator;
5525
5605
  exports2.formatUtil = formatUtil;
5526
5606
  exports2.getComponentRootElement = getComponentRootElement;
5527
5607
  exports2.getIcon = getIcon;
@@ -5529,6 +5609,8 @@
5529
5609
  exports2.hideLoading = hideLoading;
5530
5610
  exports2.hideTooltip = hideTooltip;
5531
5611
  exports2.isTooltipDisplayed = isTooltipDisplayed;
5612
+ exports2.isValidationFailedError = isValidationFailedError;
5613
+ exports2.loadFieldValidator = loadFieldValidator;
5532
5614
  exports2.modalHandleKey = modalHandleKey;
5533
5615
  exports2.modalPluginKey = modalPluginKey;
5534
5616
  exports2.notNull = notNull;
@@ -5543,6 +5625,7 @@
5543
5625
  exports2.showLoadingIcon = showLoadingIcon;
5544
5626
  exports2.showNotification = showNotification;
5545
5627
  exports2.showTooltip = showTooltip;
5628
+ exports2.storeFieldValidator = storeFieldValidator;
5546
5629
  exports2.tooltipEntry = tooltipEntry;
5547
5630
  exports2.tryUntil = tryUntil;
5548
5631
  exports2.useBlueseaConfig = useBlueseaConfig;
@@ -5556,6 +5639,8 @@
5556
5639
  exports2.vFocusLoop = VFocusLoop;
5557
5640
  exports2.vFocusOnLoad = vFocusOnLoad;
5558
5641
  exports2.vTooltip = vTooltip;
5642
+ exports2.validateField = validateField;
5643
+ exports2.validateFields = validateFields;
5559
5644
  exports2.waitDuring = waitDuring;
5560
5645
  exports2.waitUntil = waitUntil;
5561
5646
  exports2.withLoading = withLoading;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vue UI Library for Management Console.",
4
4
  "license": "Proprietary",
5
5
  "private": false,
6
- "version": "1.0.0-alpha.10",
6
+ "version": "1.0.0-alpha.11",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">= 24.3.0"