bge-ui 1.8.2 → 1.8.3

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.
@@ -1,6 +1,6 @@
1
1
  declare function validate(callback: any): Promise<any>;
2
- declare function resetFields(): void;
3
- declare function clearValidate(): void;
2
+ declare function resetFields(): Promise<void>;
3
+ declare function clearValidate(): Promise<void>;
4
4
  declare function validateField(): void;
5
5
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
6
6
  inline: BooleanConstructor;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { defineComponent, resolveComponent, openBlock, createElementBlock, normalizeClass, createElementVNode, createVNode, renderSlot, normalizeStyle, createStaticVNode, provide, reactive, toRefs, ref, watch, unref, getCurrentScope, onScopeDispose, readonly, computed, getCurrentInstance, onMounted, useSlots, inject, createTextVNode, toDisplayString, createCommentVNode, TransitionGroup, withCtx, createBlock, withModifiers, withDirectives, cloneVNode, Fragment, Text, Comment, onUnmounted, h, Transition, vShow, onBeforeMount, nextTick, Teleport, resolveDynamicComponent, shallowReactive, render as render$7, isVNode, vModelCheckbox, renderList, toRef, useAttrs, normalizeProps, mergeProps, onBeforeUpdate, withKeys, createSlots, guardReactiveProps, isRef } from "vue";
7
+ import { defineComponent, resolveComponent, openBlock, createElementBlock, normalizeClass, createElementVNode, createVNode, renderSlot, normalizeStyle, createStaticVNode, provide, reactive, toRefs, ref, watch, unref, getCurrentScope, onScopeDispose, readonly, computed, getCurrentInstance, onMounted, useSlots, inject, createTextVNode, toDisplayString, createCommentVNode, TransitionGroup, withCtx, nextTick, createBlock, withModifiers, withDirectives, cloneVNode, Fragment, Text, Comment, onUnmounted, h, Transition, vShow, onBeforeMount, Teleport, resolveDynamicComponent, shallowReactive, render as render$7, isVNode, vModelCheckbox, renderList, toRef, useAttrs, normalizeProps, mergeProps, onBeforeUpdate, withKeys, createSlots, guardReactiveProps, isRef } from "vue";
8
8
  const _hoisted_1$2e = ["disabled"];
9
9
  const _hoisted_2$1U = { class: "loading-icon" };
10
10
  const _sfc_main$2o = /* @__PURE__ */ defineComponent({
@@ -4891,11 +4891,24 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
4891
4891
  return callback && callback(true, validationErrors);
4892
4892
  return callback(false, validationErrors);
4893
4893
  }
4894
- function resetFields() {
4895
- console.log("resetFields");
4894
+ async function resetFields() {
4895
+ if (!props.model) {
4896
+ return;
4897
+ }
4898
+ for (const field of fields) {
4899
+ try {
4900
+ await field.resetField();
4901
+ } catch (errors2) {
4902
+ }
4903
+ }
4896
4904
  }
4897
- function clearValidate() {
4898
- console.log("clearValidate");
4905
+ async function clearValidate() {
4906
+ for (const field of fields) {
4907
+ try {
4908
+ await field.clearValidate();
4909
+ } catch (errors2) {
4910
+ }
4911
+ }
4899
4912
  }
4900
4913
  function validateField() {
4901
4914
  console.log("validateField");
@@ -6288,6 +6301,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
6288
6301
  },
6289
6302
  setup(__props) {
6290
6303
  const props = __props;
6304
+ let initialValue = void 0;
6291
6305
  const labelSlot = useSlots().label;
6292
6306
  const isShowLabel = computed(() => {
6293
6307
  return !!labelSlot || props.label;
@@ -6302,6 +6316,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
6302
6316
  const validateMessage = ref("");
6303
6317
  const validateState = ref("");
6304
6318
  const formItemRef = ref();
6319
+ let isResettingField = false;
6305
6320
  const fieldValue = computed(() => {
6306
6321
  const model = formContext == null ? void 0 : formContext.model;
6307
6322
  if (!model || !props.prop) {
@@ -6373,7 +6388,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
6373
6388
  }).map(({ trigger: trigger2, ...rule }) => rule);
6374
6389
  };
6375
6390
  const validate = async (trigger, callback) => {
6376
- if (!props.prop) {
6391
+ if (isResettingField || !props.prop) {
6377
6392
  return false;
6378
6393
  }
6379
6394
  const hasCallback = isFunction2(callback);
@@ -6396,11 +6411,26 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
6396
6411
  return hasCallback ? false : Promise.reject(fields);
6397
6412
  });
6398
6413
  };
6414
+ const clearValidate = async () => {
6415
+ setValidationState("");
6416
+ validateMessage.value = "";
6417
+ isResettingField = false;
6418
+ };
6419
+ const resetField = async () => {
6420
+ const model = formContext == null ? void 0 : formContext.model;
6421
+ if (!model || !props.prop)
6422
+ return;
6423
+ isResettingField = true;
6424
+ model[props.prop] = JSON.parse(JSON.stringify(initialValue));
6425
+ await nextTick();
6426
+ clearValidate();
6427
+ isResettingField = false;
6428
+ };
6399
6429
  const context = reactive({
6400
6430
  ...toRefs(props),
6401
6431
  $el: formItemRef,
6402
6432
  validateState,
6403
- // resetField,
6433
+ resetField,
6404
6434
  // clearValidate,
6405
6435
  validate
6406
6436
  });
@@ -6414,6 +6444,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
6414
6444
  );
6415
6445
  onMounted(() => {
6416
6446
  formContext == null ? void 0 : formContext.addField(context);
6447
+ initialValue = fieldValue.value ? JSON.parse(JSON.stringify(fieldValue.value)) : "";
6417
6448
  });
6418
6449
  return (_ctx, _cache) => {
6419
6450
  return openBlock(), createElementBlock("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bge-ui",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -19,7 +19,7 @@
19
19
  </div>
20
20
  </template>
21
21
  <script setup lang="ts">
22
- import { computed, inject, onMounted, provide, reactive, ref, toRefs, useSlots } from 'vue'
22
+ import { computed, inject, nextTick, onMounted, provide, reactive, ref, toRefs, useSlots } from 'vue'
23
23
  import { refDebounced } from '@vueuse/core'
24
24
  import AsyncValidator from 'async-validator'
25
25
 
@@ -31,7 +31,7 @@ const props = defineProps({
31
31
  required: Boolean,
32
32
  rules: [Array, Object]
33
33
  })
34
-
34
+ let initialValue: any = undefined
35
35
  const labelSlot = useSlots().label
36
36
  const isShowLabel = computed(() => {
37
37
  return !!labelSlot || props.label
@@ -179,11 +179,32 @@ const validate: any = async (trigger: any, callback: any) => {
179
179
  })
180
180
  }
181
181
 
182
+ const clearValidate = async () => {
183
+ setValidationState('')
184
+ validateMessage.value = ''
185
+ isResettingField = false
186
+ }
187
+
188
+ const resetField = async () => {
189
+ const model = formContext?.model
190
+ if (!model || !props.prop) return
191
+
192
+ // prevent validation from being triggered
193
+ isResettingField = true
194
+
195
+ model[props.prop as any] = JSON.parse(JSON.stringify(initialValue))
196
+
197
+ await nextTick()
198
+ clearValidate()
199
+
200
+ isResettingField = false
201
+ }
202
+
182
203
  const context: any = reactive({
183
204
  ...toRefs(props),
184
205
  $el: formItemRef,
185
206
  validateState,
186
- // resetField,
207
+ resetField,
187
208
  // clearValidate,
188
209
  validate,
189
210
  })
@@ -205,6 +226,7 @@ const shouldShowError = computed(
205
226
 
206
227
  onMounted(() => {
207
228
  formContext?.addField(context)
229
+ initialValue = fieldValue.value ? JSON.parse(JSON.stringify(fieldValue.value)) : ''
208
230
  })
209
231
  </script>
210
232
  <style lang="scss">
@@ -41,12 +41,25 @@ async function validate(callback: any) {
41
41
 
42
42
  return callback(false, validationErrors)
43
43
  }
44
- function resetFields() {
45
- console.log('resetFields')
44
+ async function resetFields() {
45
+ if (!props.model) {
46
+ return
47
+ }
48
+ for (const field of fields) {
49
+ try {
50
+ await field.resetField()
51
+ } catch (errors) {
52
+ }
53
+ }
46
54
  }
47
55
 
48
- function clearValidate() {
49
- console.log('clearValidate')
56
+ async function clearValidate() {
57
+ for (const field of fields) {
58
+ try {
59
+ await field.clearValidate()
60
+ } catch (errors) {
61
+ }
62
+ }
50
63
  }
51
64
 
52
65
  function validateField() {