@bagelink/vue 0.0.1104 → 0.0.1109

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 +1 @@
1
- {"version":3,"file":"BglField.vue.d.ts","sourceRoot":"","sources":["../../../src/components/form/BglField.vue"],"names":[],"mappings":"AAAA,OAkGO,EAIN,KAAK,KAAK,EAWV,MAAM,eAAe,CAAA;yBAIL,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,eAChC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,cAClD,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,iBAC5F,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC;WAwJ1D,mBAAmB,CAAC;;;eArJpB,KAAK,CAAC,CAAC,CAAC;kBACL,MAAM;qBACH,GAAG;qBACH,MAAM;mBAkJ0E,CAAC,4BAA2B;oBACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;;OAKC,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AAlKzE,wBAkK4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"BglField.vue.d.ts","sourceRoot":"","sources":["../../../src/components/form/BglField.vue"],"names":[],"mappings":"AAAA,OAqIO,EAIN,KAAK,KAAK,EAYV,MAAM,eAAe,CAAA;yBAKL,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,eAChC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,cAClD,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,iBAC5F,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC;WA0L1D,mBAAmB,CAAC;;;eAvLpB,KAAK,CAAC,CAAC,CAAC;kBACL,MAAM;qBACH,GAAG;qBACH,MAAM;mBAoL0E,CAAC,4BAA2B;oBACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;;OAKC,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AApMzE,wBAoM4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/NumberInput.vue"],"names":[],"mappings":"AA4LA,OAAO,EAAQ,KAAK,aAAa,EAAO,MAAM,eAAe,CAAA;AAG7D,KAAK,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,CAAA;AAEzD,UAAU,gBAAgB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;;;;;;AA2SD,wBAQG"}
1
+ {"version":3,"file":"NumberInput.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/NumberInput.vue"],"names":[],"mappings":"AA4LA,OAAO,EAAQ,KAAK,aAAa,EAAO,MAAM,eAAe,CAAA;AAG7D,KAAK,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,CAAA;AAEzD,UAAU,gBAAgB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;;;;;;AAmTD,wBAQG"}
package/dist/index.cjs CHANGED
@@ -9811,91 +9811,6 @@ const _sfc_main$V = /* @__PURE__ */ vue.defineComponent({
9811
9811
  }
9812
9812
  });
9813
9813
  const Flag = /* @__PURE__ */ _export_sfc(_sfc_main$V, [["__scopeId", "data-v-f99f1900"]]);
9814
- const FORM_STATE_KEY = Symbol("bagelFormState");
9815
- function safeClone(obj) {
9816
- if (obj === null || typeof obj !== "object") return obj;
9817
- const seen = /* @__PURE__ */ new WeakSet();
9818
- return JSON.parse(JSON.stringify(obj, (key, value) => {
9819
- if (typeof value === "object" && value !== null) {
9820
- if (seen.has(value)) {
9821
- return void 0;
9822
- }
9823
- seen.add(value);
9824
- }
9825
- return value;
9826
- }));
9827
- }
9828
- function provideBagelFormState(initialData) {
9829
- const data2 = vue.ref(initialData);
9830
- const isDirty = vue.ref(false);
9831
- const getFieldData = (path) => {
9832
- if (!path) return "";
9833
- const keys4 = path.split(/[.[]/);
9834
- let current = data2.value;
9835
- for (let i2 = 0; i2 < keys4.length; i2++) {
9836
- const key = keys4[i2];
9837
- if (!current || typeof current !== "object" || !(key in current)) {
9838
- return "";
9839
- }
9840
- current = current[key];
9841
- }
9842
- return current ?? "";
9843
- };
9844
- const updateField = (path, value) => {
9845
- const keys4 = path.split(/[.[]/);
9846
- if (typeof data2.value !== "object" || data2.value === null) {
9847
- data2.value = {};
9848
- }
9849
- let current = data2.value;
9850
- for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9851
- const key = keys4[i2];
9852
- if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
9853
- current[key] = {};
9854
- }
9855
- current = current[key];
9856
- }
9857
- const safeValue = safeClone(value);
9858
- current[keys4[keys4.length - 1]] = safeValue;
9859
- isDirty.value = true;
9860
- };
9861
- const state2 = {
9862
- data: data2,
9863
- getFieldData,
9864
- updateField,
9865
- isDirty
9866
- };
9867
- vue.provide(FORM_STATE_KEY, state2);
9868
- return state2;
9869
- }
9870
- function useBagelFormState() {
9871
- const state2 = vue.inject(FORM_STATE_KEY);
9872
- if (!state2) throw new Error("BagelFormState must be provided");
9873
- return state2;
9874
- }
9875
- function useFormField(props2) {
9876
- const formState = vue.inject(FORM_STATE_KEY);
9877
- const fieldData = vue.computed({
9878
- get: () => {
9879
- if (!props2.fieldID || !formState) return props2.modelValue ?? props2.field.defaultValue ?? "";
9880
- const value = formState.getFieldData(props2.fieldID);
9881
- if (props2.field.$el === "form" && !value) return {};
9882
- return value ?? "";
9883
- },
9884
- set: (val) => {
9885
- if (!props2.fieldID || !formState) return;
9886
- const currentValue = formState.getFieldData(props2.fieldID);
9887
- if (JSON.stringify(val) === JSON.stringify(currentValue)) return;
9888
- if (props2.field.onUpdate) {
9889
- props2.field.onUpdate(val, currentValue);
9890
- }
9891
- formState.updateField(props2.fieldID, val);
9892
- }
9893
- });
9894
- return {
9895
- fieldData,
9896
- formState
9897
- };
9898
- }
9899
9814
  const state$1 = vue.reactive(/* @__PURE__ */ new Map());
9900
9815
  function useTabs(group) {
9901
9816
  if (!state$1.has(group)) {
@@ -10000,6 +9915,67 @@ const _sfc_main$U = /* @__PURE__ */ vue.defineComponent({
10000
9915
  }
10001
9916
  });
10002
9917
  const TabsNav = /* @__PURE__ */ _export_sfc(_sfc_main$U, [["__scopeId", "data-v-307612a9"]]);
9918
+ const FORM_STATE_KEY = Symbol("bagelFormState");
9919
+ function safeClone(obj) {
9920
+ if (obj === null || typeof obj !== "object") return obj;
9921
+ const seen = /* @__PURE__ */ new WeakSet();
9922
+ return JSON.parse(JSON.stringify(obj, (key, value) => {
9923
+ if (typeof value === "object" && value !== null) {
9924
+ if (seen.has(value)) {
9925
+ return void 0;
9926
+ }
9927
+ seen.add(value);
9928
+ }
9929
+ return value;
9930
+ }));
9931
+ }
9932
+ function provideBagelFormState(initialData) {
9933
+ const data2 = vue.ref(initialData);
9934
+ const isDirty = vue.ref(false);
9935
+ const getFieldData = (path) => {
9936
+ if (!path) return "";
9937
+ const keys4 = path.split(/[.[]/);
9938
+ let current = data2.value;
9939
+ for (let i2 = 0; i2 < keys4.length; i2++) {
9940
+ const key = keys4[i2];
9941
+ if (!current || typeof current !== "object" || !(key in current)) {
9942
+ return "";
9943
+ }
9944
+ current = current[key];
9945
+ }
9946
+ return current ?? "";
9947
+ };
9948
+ const updateField = (path, value) => {
9949
+ const keys4 = path.split(/[.[]/);
9950
+ if (typeof data2.value !== "object" || data2.value === null) {
9951
+ data2.value = {};
9952
+ }
9953
+ let current = data2.value;
9954
+ for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9955
+ const key = keys4[i2];
9956
+ if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
9957
+ current[key] = {};
9958
+ }
9959
+ current = current[key];
9960
+ }
9961
+ const safeValue = safeClone(value);
9962
+ current[keys4[keys4.length - 1]] = safeValue;
9963
+ isDirty.value = true;
9964
+ };
9965
+ const state2 = {
9966
+ data: data2,
9967
+ getFieldData,
9968
+ updateField,
9969
+ isDirty
9970
+ };
9971
+ vue.provide(FORM_STATE_KEY, state2);
9972
+ return state2;
9973
+ }
9974
+ function useBagelFormState() {
9975
+ const state2 = vue.inject(FORM_STATE_KEY);
9976
+ if (!state2) throw new Error("BagelFormState must be provided");
9977
+ return state2;
9978
+ }
10003
9979
  const _hoisted_1$K = { key: 1 };
10004
9980
  const _sfc_main$T = /* @__PURE__ */ vue.defineComponent({
10005
9981
  __name: "BglField",
@@ -10012,7 +9988,8 @@ const _sfc_main$T = /* @__PURE__ */ vue.defineComponent({
10012
9988
  emits: ["update:modelValue"],
10013
9989
  setup(__props, { emit: __emit }) {
10014
9990
  const props2 = __props;
10015
- const { fieldData } = useFormField(props2);
9991
+ const emit2 = __emit;
9992
+ const formState = vue.inject(FORM_STATE_KEY) ?? provideBagelFormState(props2.modelValue);
10016
9993
  const customAttrs = vue.ref({});
10017
9994
  const is4 = vue.computed(() => {
10018
9995
  if (props2.field.$el === "text") return TextInput;
@@ -10033,24 +10010,50 @@ const _sfc_main$T = /* @__PURE__ */ vue.defineComponent({
10033
10010
  if (props2.field.$el === "bglform") return _sfc_main$S;
10034
10011
  return props2.field.$el ?? "div";
10035
10012
  });
10013
+ const fieldData = vue.computed({
10014
+ get: () => {
10015
+ if (!props2.fieldID) return props2.field.defaultValue ?? (props2.field.$el === "form" ? {} : "");
10016
+ const value = formState.getFieldData(props2.fieldID);
10017
+ if (props2.field.$el === "form" && !value) return {};
10018
+ return value ?? "";
10019
+ },
10020
+ set: (val) => {
10021
+ if (!props2.fieldID) return;
10022
+ const currentValue = formState.getFieldData(props2.fieldID);
10023
+ if (JSON.stringify(val) === JSON.stringify(currentValue)) return;
10024
+ emit2("update:modelValue", val);
10025
+ if (props2.field.onUpdate) {
10026
+ props2.field.onUpdate(val, currentValue);
10027
+ }
10028
+ formState.updateField(props2.fieldID, val);
10029
+ }
10030
+ });
10031
+ const vIf = vue.computed(() => {
10032
+ if (props2.field["v-if"] === void 0 && props2.field.vIf === void 0) return true;
10033
+ if (typeof props2.field["v-if"] === "boolean" || typeof props2.field.vIf === "boolean") return props2.field["v-if"];
10034
+ if (typeof props2.field["v-if"] === "string" || typeof props2.field.vIf === "string") return true;
10035
+ if (typeof props2.field["v-if"] === "function") return props2.field["v-if"](fieldData.value, formState.data.value);
10036
+ if (typeof props2.field.vIf === "function") return props2.field.vIf(fieldData.value, formState.data.value);
10037
+ return true;
10038
+ });
10036
10039
  const computedOptions = vue.computed(
10037
- () => bindAttrs({ options: props2.field.options }, fieldData, props2.modelValue).options
10040
+ () => bindAttrs({ options: props2.field.options }, fieldData.value, formState.data.value).options
10038
10041
  );
10039
10042
  const computedAttrs = vue.computed(() => {
10040
10043
  const attrs = { ...customAttrs.value, ...props2.field.attrs };
10041
- return bindAttrs(attrs, fieldData, props2.modelValue);
10044
+ return bindAttrs(attrs, fieldData.value, formState.data.value);
10042
10045
  });
10043
10046
  const computedClass = vue.computed(
10044
10047
  () => {
10045
10048
  var _a2;
10046
- return classify(fieldData, props2.modelValue, props2.field.class, (_a2 = props2.field.attrs) == null ? void 0 : _a2.class);
10049
+ return classify(fieldData.value, formState.data.value, props2.field.class, (_a2 = props2.field.attrs) == null ? void 0 : _a2.class);
10047
10050
  }
10048
10051
  );
10049
10052
  return (_ctx, _cache) => {
10050
10053
  const _component_BglField = vue.resolveComponent("BglField", true);
10051
- return _ctx.field.vIf === void 0 || _ctx.field.vIf ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(is4.value), vue.mergeProps({ key: 0 }, computedAttrs.value, {
10052
- modelValue: vue.unref(fieldData),
10053
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.isRef(fieldData) ? fieldData.value = $event : null),
10054
+ return vIf.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(is4.value), vue.mergeProps({ key: 0 }, computedAttrs.value, {
10055
+ modelValue: fieldData.value,
10056
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldData.value = $event),
10054
10057
  fieldID: props2.fieldID,
10055
10058
  required: _ctx.field.required,
10056
10059
  class: computedClass.value,
@@ -20436,6 +20439,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
20436
20439
  flat: "",
20437
20440
  icon: "add",
20438
20441
  class: vue.normalizeClass(["radius", [{ "bgl-big-ctrl-num-btn": _ctx.layout === "vertical" }]]),
20442
+ tabindex: "-1",
20439
20443
  onClick: increment
20440
20444
  }, null, 8, ["class"])) : vue.createCommentVNode("", true),
20441
20445
  vue.withDirectives(vue.createElementVNode("input", {
@@ -20489,6 +20493,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
20489
20493
  flat: "",
20490
20494
  icon: "remove",
20491
20495
  class: vue.normalizeClass(["radius", [{ "bgl-big-ctrl-num-btn": _ctx.layout === "vertical" }]]),
20496
+ tabindex: "-1",
20492
20497
  onClick: decrement
20493
20498
  }, null, 8, ["class"])) : vue.createCommentVNode("", true),
20494
20499
  _ctx.spinner && (!_ctx.layout || !btnLayouts.includes(_ctx.layout)) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4$c, [
@@ -20498,6 +20503,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
20498
20503
  thin: "",
20499
20504
  class: "bgl-ctrl-num-btn ctrl-add color-gray top-bgl-ctrl-num-btn",
20500
20505
  disabled: !canAdd.value,
20506
+ tabindex: "-1",
20501
20507
  onClick: increment
20502
20508
  }, null, 8, ["disabled"]),
20503
20509
  vue.createVNode(vue.unref(Btn), {
@@ -20506,6 +20512,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
20506
20512
  thin: "",
20507
20513
  class: "bgl-ctrl-num-btn ctrl-remove color-gray",
20508
20514
  disabled: !canDecrement.value,
20515
+ tabindex: "-1",
20509
20516
  onClick: decrement
20510
20517
  }, null, 8, ["disabled"])
20511
20518
  ])) : vue.createCommentVNode("", true)
@@ -20515,7 +20522,7 @@ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
20515
20522
  };
20516
20523
  }
20517
20524
  });
20518
- const NumberInput = /* @__PURE__ */ _export_sfc(_sfc_main$F, [["__scopeId", "data-v-3a20cf4a"]]);
20525
+ const NumberInput = /* @__PURE__ */ _export_sfc(_sfc_main$F, [["__scopeId", "data-v-f265687e"]]);
20519
20526
  const _hoisted_1$w = ["value", "autofocus", "onKeydown", "onPaste"];
20520
20527
  const _sfc_main$E = /* @__PURE__ */ vue.defineComponent({
20521
20528
  __name: "OTP",
package/dist/index.mjs CHANGED
@@ -9809,91 +9809,6 @@ const _sfc_main$V = /* @__PURE__ */ defineComponent({
9809
9809
  }
9810
9810
  });
9811
9811
  const Flag = /* @__PURE__ */ _export_sfc(_sfc_main$V, [["__scopeId", "data-v-f99f1900"]]);
9812
- const FORM_STATE_KEY = Symbol("bagelFormState");
9813
- function safeClone(obj) {
9814
- if (obj === null || typeof obj !== "object") return obj;
9815
- const seen = /* @__PURE__ */ new WeakSet();
9816
- return JSON.parse(JSON.stringify(obj, (key, value) => {
9817
- if (typeof value === "object" && value !== null) {
9818
- if (seen.has(value)) {
9819
- return void 0;
9820
- }
9821
- seen.add(value);
9822
- }
9823
- return value;
9824
- }));
9825
- }
9826
- function provideBagelFormState(initialData) {
9827
- const data2 = ref(initialData);
9828
- const isDirty = ref(false);
9829
- const getFieldData = (path) => {
9830
- if (!path) return "";
9831
- const keys4 = path.split(/[.[]/);
9832
- let current = data2.value;
9833
- for (let i2 = 0; i2 < keys4.length; i2++) {
9834
- const key = keys4[i2];
9835
- if (!current || typeof current !== "object" || !(key in current)) {
9836
- return "";
9837
- }
9838
- current = current[key];
9839
- }
9840
- return current ?? "";
9841
- };
9842
- const updateField = (path, value) => {
9843
- const keys4 = path.split(/[.[]/);
9844
- if (typeof data2.value !== "object" || data2.value === null) {
9845
- data2.value = {};
9846
- }
9847
- let current = data2.value;
9848
- for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9849
- const key = keys4[i2];
9850
- if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
9851
- current[key] = {};
9852
- }
9853
- current = current[key];
9854
- }
9855
- const safeValue = safeClone(value);
9856
- current[keys4[keys4.length - 1]] = safeValue;
9857
- isDirty.value = true;
9858
- };
9859
- const state2 = {
9860
- data: data2,
9861
- getFieldData,
9862
- updateField,
9863
- isDirty
9864
- };
9865
- provide(FORM_STATE_KEY, state2);
9866
- return state2;
9867
- }
9868
- function useBagelFormState() {
9869
- const state2 = inject(FORM_STATE_KEY);
9870
- if (!state2) throw new Error("BagelFormState must be provided");
9871
- return state2;
9872
- }
9873
- function useFormField(props2) {
9874
- const formState = inject(FORM_STATE_KEY);
9875
- const fieldData = computed({
9876
- get: () => {
9877
- if (!props2.fieldID || !formState) return props2.modelValue ?? props2.field.defaultValue ?? "";
9878
- const value = formState.getFieldData(props2.fieldID);
9879
- if (props2.field.$el === "form" && !value) return {};
9880
- return value ?? "";
9881
- },
9882
- set: (val) => {
9883
- if (!props2.fieldID || !formState) return;
9884
- const currentValue = formState.getFieldData(props2.fieldID);
9885
- if (JSON.stringify(val) === JSON.stringify(currentValue)) return;
9886
- if (props2.field.onUpdate) {
9887
- props2.field.onUpdate(val, currentValue);
9888
- }
9889
- formState.updateField(props2.fieldID, val);
9890
- }
9891
- });
9892
- return {
9893
- fieldData,
9894
- formState
9895
- };
9896
- }
9897
9812
  const state$1 = reactive(/* @__PURE__ */ new Map());
9898
9813
  function useTabs(group) {
9899
9814
  if (!state$1.has(group)) {
@@ -9998,6 +9913,67 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
9998
9913
  }
9999
9914
  });
10000
9915
  const TabsNav = /* @__PURE__ */ _export_sfc(_sfc_main$U, [["__scopeId", "data-v-307612a9"]]);
9916
+ const FORM_STATE_KEY = Symbol("bagelFormState");
9917
+ function safeClone(obj) {
9918
+ if (obj === null || typeof obj !== "object") return obj;
9919
+ const seen = /* @__PURE__ */ new WeakSet();
9920
+ return JSON.parse(JSON.stringify(obj, (key, value) => {
9921
+ if (typeof value === "object" && value !== null) {
9922
+ if (seen.has(value)) {
9923
+ return void 0;
9924
+ }
9925
+ seen.add(value);
9926
+ }
9927
+ return value;
9928
+ }));
9929
+ }
9930
+ function provideBagelFormState(initialData) {
9931
+ const data2 = ref(initialData);
9932
+ const isDirty = ref(false);
9933
+ const getFieldData = (path) => {
9934
+ if (!path) return "";
9935
+ const keys4 = path.split(/[.[]/);
9936
+ let current = data2.value;
9937
+ for (let i2 = 0; i2 < keys4.length; i2++) {
9938
+ const key = keys4[i2];
9939
+ if (!current || typeof current !== "object" || !(key in current)) {
9940
+ return "";
9941
+ }
9942
+ current = current[key];
9943
+ }
9944
+ return current ?? "";
9945
+ };
9946
+ const updateField = (path, value) => {
9947
+ const keys4 = path.split(/[.[]/);
9948
+ if (typeof data2.value !== "object" || data2.value === null) {
9949
+ data2.value = {};
9950
+ }
9951
+ let current = data2.value;
9952
+ for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9953
+ const key = keys4[i2];
9954
+ if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
9955
+ current[key] = {};
9956
+ }
9957
+ current = current[key];
9958
+ }
9959
+ const safeValue = safeClone(value);
9960
+ current[keys4[keys4.length - 1]] = safeValue;
9961
+ isDirty.value = true;
9962
+ };
9963
+ const state2 = {
9964
+ data: data2,
9965
+ getFieldData,
9966
+ updateField,
9967
+ isDirty
9968
+ };
9969
+ provide(FORM_STATE_KEY, state2);
9970
+ return state2;
9971
+ }
9972
+ function useBagelFormState() {
9973
+ const state2 = inject(FORM_STATE_KEY);
9974
+ if (!state2) throw new Error("BagelFormState must be provided");
9975
+ return state2;
9976
+ }
10001
9977
  const _hoisted_1$K = { key: 1 };
10002
9978
  const _sfc_main$T = /* @__PURE__ */ defineComponent({
10003
9979
  __name: "BglField",
@@ -10010,7 +9986,8 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
10010
9986
  emits: ["update:modelValue"],
10011
9987
  setup(__props, { emit: __emit }) {
10012
9988
  const props2 = __props;
10013
- const { fieldData } = useFormField(props2);
9989
+ const emit2 = __emit;
9990
+ const formState = inject(FORM_STATE_KEY) ?? provideBagelFormState(props2.modelValue);
10014
9991
  const customAttrs = ref({});
10015
9992
  const is4 = computed(() => {
10016
9993
  if (props2.field.$el === "text") return TextInput;
@@ -10031,24 +10008,50 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
10031
10008
  if (props2.field.$el === "bglform") return _sfc_main$S;
10032
10009
  return props2.field.$el ?? "div";
10033
10010
  });
10011
+ const fieldData = computed({
10012
+ get: () => {
10013
+ if (!props2.fieldID) return props2.field.defaultValue ?? (props2.field.$el === "form" ? {} : "");
10014
+ const value = formState.getFieldData(props2.fieldID);
10015
+ if (props2.field.$el === "form" && !value) return {};
10016
+ return value ?? "";
10017
+ },
10018
+ set: (val) => {
10019
+ if (!props2.fieldID) return;
10020
+ const currentValue = formState.getFieldData(props2.fieldID);
10021
+ if (JSON.stringify(val) === JSON.stringify(currentValue)) return;
10022
+ emit2("update:modelValue", val);
10023
+ if (props2.field.onUpdate) {
10024
+ props2.field.onUpdate(val, currentValue);
10025
+ }
10026
+ formState.updateField(props2.fieldID, val);
10027
+ }
10028
+ });
10029
+ const vIf = computed(() => {
10030
+ if (props2.field["v-if"] === void 0 && props2.field.vIf === void 0) return true;
10031
+ if (typeof props2.field["v-if"] === "boolean" || typeof props2.field.vIf === "boolean") return props2.field["v-if"];
10032
+ if (typeof props2.field["v-if"] === "string" || typeof props2.field.vIf === "string") return true;
10033
+ if (typeof props2.field["v-if"] === "function") return props2.field["v-if"](fieldData.value, formState.data.value);
10034
+ if (typeof props2.field.vIf === "function") return props2.field.vIf(fieldData.value, formState.data.value);
10035
+ return true;
10036
+ });
10034
10037
  const computedOptions = computed(
10035
- () => bindAttrs({ options: props2.field.options }, fieldData, props2.modelValue).options
10038
+ () => bindAttrs({ options: props2.field.options }, fieldData.value, formState.data.value).options
10036
10039
  );
10037
10040
  const computedAttrs = computed(() => {
10038
10041
  const attrs = { ...customAttrs.value, ...props2.field.attrs };
10039
- return bindAttrs(attrs, fieldData, props2.modelValue);
10042
+ return bindAttrs(attrs, fieldData.value, formState.data.value);
10040
10043
  });
10041
10044
  const computedClass = computed(
10042
10045
  () => {
10043
10046
  var _a2;
10044
- return classify(fieldData, props2.modelValue, props2.field.class, (_a2 = props2.field.attrs) == null ? void 0 : _a2.class);
10047
+ return classify(fieldData.value, formState.data.value, props2.field.class, (_a2 = props2.field.attrs) == null ? void 0 : _a2.class);
10045
10048
  }
10046
10049
  );
10047
10050
  return (_ctx, _cache) => {
10048
10051
  const _component_BglField = resolveComponent("BglField", true);
10049
- return _ctx.field.vIf === void 0 || _ctx.field.vIf ? (openBlock(), createBlock(resolveDynamicComponent(is4.value), mergeProps({ key: 0 }, computedAttrs.value, {
10050
- modelValue: unref(fieldData),
10051
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(fieldData) ? fieldData.value = $event : null),
10052
+ return vIf.value ? (openBlock(), createBlock(resolveDynamicComponent(is4.value), mergeProps({ key: 0 }, computedAttrs.value, {
10053
+ modelValue: fieldData.value,
10054
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldData.value = $event),
10052
10055
  fieldID: props2.fieldID,
10053
10056
  required: _ctx.field.required,
10054
10057
  class: computedClass.value,
@@ -20434,6 +20437,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
20434
20437
  flat: "",
20435
20438
  icon: "add",
20436
20439
  class: normalizeClass(["radius", [{ "bgl-big-ctrl-num-btn": _ctx.layout === "vertical" }]]),
20440
+ tabindex: "-1",
20437
20441
  onClick: increment
20438
20442
  }, null, 8, ["class"])) : createCommentVNode("", true),
20439
20443
  withDirectives(createElementVNode("input", {
@@ -20487,6 +20491,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
20487
20491
  flat: "",
20488
20492
  icon: "remove",
20489
20493
  class: normalizeClass(["radius", [{ "bgl-big-ctrl-num-btn": _ctx.layout === "vertical" }]]),
20494
+ tabindex: "-1",
20490
20495
  onClick: decrement
20491
20496
  }, null, 8, ["class"])) : createCommentVNode("", true),
20492
20497
  _ctx.spinner && (!_ctx.layout || !btnLayouts.includes(_ctx.layout)) ? (openBlock(), createElementBlock("div", _hoisted_4$c, [
@@ -20496,6 +20501,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
20496
20501
  thin: "",
20497
20502
  class: "bgl-ctrl-num-btn ctrl-add color-gray top-bgl-ctrl-num-btn",
20498
20503
  disabled: !canAdd.value,
20504
+ tabindex: "-1",
20499
20505
  onClick: increment
20500
20506
  }, null, 8, ["disabled"]),
20501
20507
  createVNode(unref(Btn), {
@@ -20504,6 +20510,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
20504
20510
  thin: "",
20505
20511
  class: "bgl-ctrl-num-btn ctrl-remove color-gray",
20506
20512
  disabled: !canDecrement.value,
20513
+ tabindex: "-1",
20507
20514
  onClick: decrement
20508
20515
  }, null, 8, ["disabled"])
20509
20516
  ])) : createCommentVNode("", true)
@@ -20513,7 +20520,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
20513
20520
  };
20514
20521
  }
20515
20522
  });
20516
- const NumberInput = /* @__PURE__ */ _export_sfc(_sfc_main$F, [["__scopeId", "data-v-3a20cf4a"]]);
20523
+ const NumberInput = /* @__PURE__ */ _export_sfc(_sfc_main$F, [["__scopeId", "data-v-f265687e"]]);
20517
20524
  const _hoisted_1$w = ["value", "autofocus", "onKeydown", "onPaste"];
20518
20525
  const _sfc_main$E = /* @__PURE__ */ defineComponent({
20519
20526
  __name: "OTP",
package/dist/style.css CHANGED
@@ -1251,14 +1251,14 @@ pre code.hljs{
1251
1251
  direction: ltr;
1252
1252
  }
1253
1253
 
1254
- .txtInputIconStart .iconStart[data-v-3a20cf4a] {
1254
+ .txtInputIconStart .iconStart[data-v-f265687e] {
1255
1255
  color: var(--input-color);
1256
1256
  position: absolute;
1257
1257
  inset-inline-start:calc(var(--input-height) / 3 - 0.25rem);
1258
1258
  margin-top: calc(var(--input-height) / 2 );
1259
1259
  line-height: 0;
1260
1260
  }
1261
- .textInputSpinnerWrap .spinner[data-v-3a20cf4a] {
1261
+ .textInputSpinnerWrap .spinner[data-v-f265687e] {
1262
1262
  color: var(--input-color);
1263
1263
  position: absolute;
1264
1264
  inset-inline-end: 0;
@@ -1268,18 +1268,18 @@ pre code.hljs{
1268
1268
  flex-direction: column;
1269
1269
  gap: 0;
1270
1270
  }
1271
- .top-bgl-ctrl-num-btn[data-v-3a20cf4a]{
1271
+ .top-bgl-ctrl-num-btn[data-v-f265687e]{
1272
1272
  margin-top: calc(var(--input-height) / 10) !important;
1273
1273
  }
1274
- .bgl-ctrl-num-btn[data-v-3a20cf4a]{
1274
+ .bgl-ctrl-num-btn[data-v-f265687e]{
1275
1275
  height: calc(var(--input-height) / 2.5) !important;
1276
1276
  isolation: isolate;
1277
1277
  }
1278
- .bgl-big-ctrl-num-btn[data-v-3a20cf4a]{
1278
+ .bgl-big-ctrl-num-btn[data-v-f265687e]{
1279
1279
  width: 100% !important;
1280
1280
  isolation: isolate;
1281
1281
  }
1282
- .bgl-number-input[data-v-3a20cf4a]{
1282
+ .bgl-number-input[data-v-f265687e]{
1283
1283
  padding-inline-end: 1.75rem !important;
1284
1284
  }
1285
1285
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "0.0.1104",
4
+ "version": "0.0.1109",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -13,10 +13,12 @@ import {
13
13
  classify,
14
14
  NumberInput,
15
15
  UploadInput,
16
+ type BagelFormState,
16
17
  BglForm
17
18
  } from '@bagelink/vue'
18
- import { useFormField } from '../../composables/useFormField'
19
+ import { inject } from 'vue'
19
20
  import TabsNav from '../layout/TabsNav.vue'
21
+ import { FORM_STATE_KEY, provideBagelFormState } from './useBagelFormState'
20
22
 
21
23
  const props = defineProps<{
22
24
  field: Field<T>
@@ -29,7 +31,7 @@ const emit = defineEmits<{
29
31
  'update:modelValue': [value: any]
30
32
  }>()
31
33
 
32
- const { fieldData } = useFormField(props)
34
+ const formState = inject<BagelFormState<T>>(FORM_STATE_KEY) ?? provideBagelFormState(props.modelValue)
33
35
 
34
36
  const customAttrs = $ref<{ [key: string]: any }>({})
35
37
 
@@ -53,17 +55,50 @@ const is = $computed(() => {
53
55
  return props.field.$el ?? 'div'
54
56
  })
55
57
 
58
+ const fieldData = $computed({
59
+ get: () => {
60
+ if (!props.fieldID) return props.field.defaultValue ?? (props.field.$el === 'form' ? {} : '')
61
+ const value = formState.getFieldData(props.fieldID)
62
+ if (props.field.$el === 'form' && !value) return {}
63
+ return value ?? ''
64
+ },
65
+ set: (val: any) => {
66
+ if (!props.fieldID) return
67
+ const currentValue = formState.getFieldData(props.fieldID)
68
+ if (JSON.stringify(val) === JSON.stringify(currentValue)) return
69
+
70
+ emit('update:modelValue', val)
71
+ if (props.field.onUpdate) {
72
+ props.field.onUpdate(val, currentValue)
73
+ }
74
+ formState.updateField(props.fieldID, val)
75
+ }
76
+ })
77
+
78
+ const vIf = $computed(() => {
79
+ if (props.field['v-if'] === undefined && props.field.vIf === undefined) return true
80
+ if (typeof props.field['v-if'] === 'boolean' || typeof props.field.vIf === 'boolean') return props.field['v-if']
81
+ if (typeof props.field['v-if'] === 'string' || typeof props.field.vIf === 'string') return true
82
+ if (typeof props.field['v-if'] === 'function') return props.field['v-if'](fieldData, formState.data.value as T)
83
+ if (typeof props.field.vIf === 'function') return props.field.vIf(fieldData, formState.data.value as T)
84
+ return true
85
+ })
86
+
87
+ // const computedFieldData = $computed(
88
+ // () => props.field.transform?.(fieldData, formState.data.value as T) ?? fieldData
89
+ // )
90
+
56
91
  const computedOptions = $computed(
57
- () => bindAttrs({ options: props.field.options }, fieldData, props.modelValue).options
92
+ () => bindAttrs({ options: props.field.options }, fieldData, formState.data.value).options
58
93
  )
59
94
 
60
95
  const computedAttrs = $computed(() => {
61
96
  const attrs = { ...customAttrs, ...props.field.attrs }
62
- return bindAttrs(attrs, fieldData, props.modelValue)
97
+ return bindAttrs(attrs, fieldData, formState.data.value)
63
98
  })
64
99
 
65
100
  const computedClass = $computed(
66
- () => classify(fieldData, props.modelValue, props.field.class, props.field.attrs?.class)
101
+ () => classify(fieldData, formState.data.value, props.field.class, props.field.attrs?.class)
67
102
  )
68
103
  </script>
69
104
 
@@ -71,7 +106,7 @@ const computedClass = $computed(
71
106
  <component
72
107
  v-bind="computedAttrs"
73
108
  :is="is"
74
- v-if="field.vIf === undefined || field.vIf"
109
+ v-if="vIf"
75
110
  v-model="fieldData"
76
111
  :fieldID="props.fieldID"
77
112
  :required="field.required"
@@ -104,7 +104,7 @@ watch(() => modelValue, (newVal) => {
104
104
  <label :for="id">
105
105
  {{ label }}
106
106
  <div class="gap-025" :class="{ 'column flex': layout === 'vertical', 'flex': layout === 'horizontal' }">
107
- <Btn v-if="layout && btnLayouts.includes(layout)" flat icon="add" class="radius" :class="[{ 'bgl-big-ctrl-num-btn': layout === 'vertical' }]" @click="increment" />
107
+ <Btn v-if="layout && btnLayouts.includes(layout)" flat icon="add" class="radius" :class="[{ 'bgl-big-ctrl-num-btn': layout === 'vertical' }]" tabindex="-1" @click="increment" />
108
108
 
109
109
  <input
110
110
  :id
@@ -138,10 +138,10 @@ watch(() => modelValue, (newVal) => {
138
138
  v-if="icon"
139
139
  :icon
140
140
  />
141
- <Btn v-if="layout && btnLayouts.includes(layout)" flat icon="remove" class="radius" :class="[{ 'bgl-big-ctrl-num-btn': layout === 'vertical' }]" @click="decrement" />
141
+ <Btn v-if="layout && btnLayouts.includes(layout)" flat icon="remove" class="radius" :class="[{ 'bgl-big-ctrl-num-btn': layout === 'vertical' }]" tabindex="-1" @click="decrement" />
142
142
  <div v-if="spinner && (!layout || !btnLayouts.includes(layout))" class="flex column spinner">
143
- <Btn icon="add" flat thin class="bgl-ctrl-num-btn ctrl-add color-gray top-bgl-ctrl-num-btn" :disabled="!canAdd" @click="increment" />
144
- <Btn icon="remove" flat thin class="bgl-ctrl-num-btn ctrl-remove color-gray" :disabled="!canDecrement" @click="decrement" />
143
+ <Btn icon="add" flat thin class="bgl-ctrl-num-btn ctrl-add color-gray top-bgl-ctrl-num-btn" :disabled="!canAdd" tabindex="-1" @click="increment" />
144
+ <Btn icon="remove" flat thin class="bgl-ctrl-num-btn ctrl-remove color-gray" :disabled="!canDecrement" tabindex="-1" @click="decrement" />
145
145
  </div>
146
146
  </div>
147
147
  </label>