@bagelink/vue 0.0.953 → 0.0.957

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":"AAsHA,OAAO,EAGN,KAAK,KAAK,EAQV,MAAM,eAAe,CAAA;yBAGL,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;WA2KxD,mBAAmB,CAAC;;;;;eAvKrB,KAAK,CAAC,CAAC,CAAC;oBACH;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE;KAsKmD,CAAC,4BAA2B;oBAChG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;;;;;YAK+B,OAAO,CAAC,OAAO,WAAW,CAAC;;AArLvE,wBAqL4E;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":"AAkJA,OAAO,EAGN,KAAK,KAAK,EAQV,MAAM,eAAe,CAAA;yBAGL,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;WAuMxD,mBAAmB,CAAC;;;;;eAnMrB,KAAK,CAAC,CAAC,CAAC;oBACH;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE;KAkMmD,CAAC,4BAA2B;oBAChG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;;;;;YAK+B,OAAO,CAAC,OAAO,WAAW,CAAC;;AAjNvE,wBAiN4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
@@ -1,7 +1,28 @@
1
1
  import { StorageFile } from '../../..';
2
2
  type StrKey = keyof StorageFile;
3
3
  type FSValue = string[] | string | number;
4
+ declare let __VLS_typeProps: {
5
+ label?: string;
6
+ multiple?: boolean;
7
+ files?: StorageFile | StorageFile[];
8
+ bindkey?: StrKey;
9
+ modelValue?: FSValue;
10
+ width?: string;
11
+ height?: string | 'auto';
12
+ topic?: string;
13
+ fill?: boolean;
14
+ oval?: boolean;
15
+ theme?: 'dropzone' | 'basic';
16
+ accept?: string;
17
+ required?: boolean;
18
+ };
4
19
  declare function browse(): void;
20
+ declare const __VLS_defaults: {
21
+ modelValue: () => FSValue;
22
+ };
23
+ type __VLS_PublicProps = {
24
+ 'modelValue'?: typeof __VLS_defaults['modelValue'];
25
+ } & typeof __VLS_typeProps;
5
26
  declare function __VLS_template(): {
6
27
  slots: {
7
28
  files?(_: {
@@ -72,38 +93,10 @@ declare function __VLS_template(): {
72
93
  attrs: Partial<{}>;
73
94
  };
74
95
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
75
- declare const __VLS_component: import('vue').DefineComponent<{
76
- label?: string;
77
- multiple?: boolean;
78
- files?: StorageFile | StorageFile[];
79
- bindkey?: StrKey;
80
- modelValue?: FSValue;
81
- width?: string;
82
- height?: string | "auto";
83
- topic?: string;
84
- fill?: boolean;
85
- oval?: boolean;
86
- theme?: "dropzone" | "basic";
87
- accept?: string;
88
- required?: boolean;
89
- }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
96
+ declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
90
97
  "update:modelValue": (...args: any[]) => void;
91
98
  addFileStart: (...args: any[]) => void;
92
- }, string, import('vue').PublicProps, Readonly<{
93
- label?: string;
94
- multiple?: boolean;
95
- files?: StorageFile | StorageFile[];
96
- bindkey?: StrKey;
97
- modelValue?: FSValue;
98
- width?: string;
99
- height?: string | "auto";
100
- topic?: string;
101
- fill?: boolean;
102
- oval?: boolean;
103
- theme?: "dropzone" | "basic";
104
- accept?: string;
105
- required?: boolean;
106
- }> & Readonly<{
99
+ }, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
107
100
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
108
101
  onAddFileStart?: ((...args: any[]) => any) | undefined;
109
102
  }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"FileUpload.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/FileUpload.vue"],"names":[],"mappings":"AA4lBA,OAAO,EAAmC,KAAK,WAAW,EAAkB,MAAM,eAAe,CAAA;AAKjG,KAAK,MAAM,GAAG,MAAM,WAAW,CAAA;AAE/B,KAAK,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAA;AA0JzC,iBAAS,MAAM,SAiBd;AA6BD,iBAAS,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA7KZ,MAAM;4BACJ,OAAO;uBACZ,MAAM;2BACF,OAAO;;YAiqBS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;0BApqBpB,MAAM;4BACJ,OAAO;uBACZ,MAAM;2BACF,OAAO;;;YAkqBgB,GAAG;;;WASxB,OAAO,IAA6B;EAEjD;AAuBD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe;YAhuBZ,MAAM;eACH,OAAO;YACV,WAAW,GAAG,WAAW,EAAE;cACzB,MAAM;iBACH,OAAO;YACZ,MAAM;aACL,MAAM,GAAG,MAAM;YAChB,MAAM;WACP,OAAO;WACP,OAAO;YACN,UAAU,GAAG,OAAO;aACnB,MAAM;eACJ,OAAO;;;;;YAZV,MAAM;eACH,OAAO;YACV,WAAW,GAAG,WAAW,EAAE;cACzB,MAAM;iBACH,OAAO;YACZ,MAAM;aACL,MAAM,GAAG,MAAM;YAChB,MAAM;WACP,OAAO;WACP,OAAO;YACN,UAAU,GAAG,OAAO;aACnB,MAAM;eACJ,OAAO;;;;kFA2tBjB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAWpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"FileUpload.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/FileUpload.vue"],"names":[],"mappings":"AAomBA,OAAO,EAAmC,KAAK,WAAW,EAAkB,MAAM,eAAe,CAAA;AAKjG,KAAK,MAAM,GAAG,MAAM,WAAW,CAAA;AAE/B,KAAK,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzC,QAAA,IAAI,eAAe,EAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,CAAA;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,CAAC;AAkJF,iBAAS,MAAM,SAiBd;AA+BD,QAAA,MAAM,cAAc;sBACI,OAAO;CAC9B,CAAC;AACF,KAAK,iBAAiB,GAAG;IACzB,YAAY,CAAC,EAAE,OAAO,cAAc,CAAC,YAAY,CAAC,CAAC;CAClD,GAAG,OAAO,eAAe,CAAC;AAI3B,iBAAS,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAhMZ,MAAM;4BACJ,OAAO;uBACZ,MAAM;2BACF,OAAO;;YAorBS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;0BAvrBpB,MAAM;4BACJ,OAAO;uBACZ,MAAM;2BACF,OAAO;;;YAqrBgB,GAAG;;;WASxB,OAAO,IAA6B;EAEjD;AA0BD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe;;;;;;kFAUnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAWpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
package/dist/index.cjs CHANGED
@@ -9623,15 +9623,40 @@ const _sfc_main$L = /* @__PURE__ */ vue.defineComponent({
9623
9623
  emit2("update:modelValue", val);
9624
9624
  }
9625
9625
  });
9626
+ const objPathRegex = /[.\][]/;
9627
+ function setFieldData(key, val) {
9628
+ const data2 = { ...props2.modelValue };
9629
+ const keys4 = key.split(objPathRegex);
9630
+ let temp = data2;
9631
+ for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9632
+ if (!temp[keys4[i2]]) {
9633
+ temp[keys4[i2]] = {};
9634
+ }
9635
+ temp = temp[keys4[i2]];
9636
+ }
9637
+ temp[keys4[keys4.length - 1]] = val;
9638
+ return data2;
9639
+ }
9640
+ function getFieldData(obj, key) {
9641
+ const keys4 = key.split(objPathRegex);
9642
+ let result2 = obj;
9643
+ for (const k2 of keys4) {
9644
+ if (result2 && k2 in result2) {
9645
+ result2 = result2[k2];
9646
+ } else {
9647
+ return void 0;
9648
+ }
9649
+ }
9650
+ return result2;
9651
+ }
9626
9652
  const fieldData = vue.computed({
9627
9653
  set: (val) => {
9628
9654
  if (!props2.field.id) return;
9629
- const data2 = { ...props2.modelValue };
9630
- data2[props2.field.id] = val;
9655
+ const data2 = setFieldData(props2.field.id, val);
9631
9656
  emit2("update:modelValue", data2);
9632
9657
  },
9633
9658
  get: () => {
9634
- if (props2.field.id) return props2.modelValue[props2.field.id];
9659
+ if (props2.field.id) return getFieldData(props2.modelValue, props2.field.id);
9635
9660
  return props2.field.defaultValue ?? "";
9636
9661
  }
9637
9662
  });
@@ -18694,7 +18719,7 @@ const _hoisted_17 = ["src"];
18694
18719
  const _hoisted_18 = { class: "p-1 flex column hover fileUploadPlaceHolder justify-content-center mb-05" };
18695
18720
  const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
18696
18721
  __name: "FileUpload",
18697
- props: {
18722
+ props: /* @__PURE__ */ vue.mergeModels({
18698
18723
  label: {},
18699
18724
  multiple: { type: Boolean },
18700
18725
  files: {},
@@ -18708,44 +18733,62 @@ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
18708
18733
  theme: {},
18709
18734
  accept: {},
18710
18735
  required: { type: Boolean }
18711
- },
18712
- emits: ["update:modelValue", "addFileStart"],
18736
+ }, {
18737
+ "modelValue": { default: () => [] },
18738
+ "modelModifiers": {}
18739
+ }),
18740
+ emits: /* @__PURE__ */ vue.mergeModels(["update:modelValue", "addFileStart"], ["update:modelValue"]),
18713
18741
  setup(__props, { emit: __emit }) {
18714
18742
  const props2 = __props;
18715
18743
  const emit2 = __emit;
18716
18744
  const bindKey2 = props2.bindkey || "id";
18717
18745
  const bagel = useBagel();
18718
18746
  const isImage = (str) => IMAGE_FORMATS_REGEXP.test(str);
18719
- let file_bindkeys = vue.ref(props2.modelValue || []);
18747
+ const file_bindkeys = vue.useModel(__props, "modelValue");
18720
18748
  const storageFiles = vue.ref([]);
18721
- async function fetchFiles() {
18749
+ async function fetchTopicFiles() {
18722
18750
  const files = await bagel.get(`/files?topic=${props2.topic}`);
18723
18751
  storageFiles.value.push(...files);
18724
18752
  }
18725
- vue.onMounted(() => {
18726
- if (props2.topic) fetchFiles();
18727
- if (!props2.files && [file_bindkeys.value].flat().length > 0) {
18728
- const ids = [file_bindkeys.value].flat().filter(Boolean);
18729
- if (!(ids == null ? void 0 : ids.length)) return;
18730
- if (bindKey2 === "url") {
18731
- ids.forEach((url) => {
18732
- storageFiles.value.push({ url });
18733
- });
18734
- return;
18735
- }
18736
- if (props2.multiple) {
18737
- ids.forEach((id) => {
18738
- void bagel.get(`/files/${id}`).then((file) => {
18739
- storageFiles.value.push(file);
18740
- }).catch(console.error);
18741
- });
18742
- } else {
18743
- void bagel.get(`/files/${ids[0]}`).then((file) => {
18753
+ function loadFiles() {
18754
+ const ids = [file_bindkeys.value].flat().filter(Boolean);
18755
+ if (!ids.length) {
18756
+ storageFiles.value.splice(0, storageFiles.value.length);
18757
+ return;
18758
+ }
18759
+ const currentIds = storageFiles.value.map((file) => file[bindKey2]);
18760
+ const idsToAdd = ids.filter((id) => !currentIds.includes(id));
18761
+ const idsToRemove = currentIds.filter((id) => (typeof id === "string" || typeof id === "number") && !ids.includes(id));
18762
+ idsToRemove.forEach((id) => {
18763
+ const index2 = storageFiles.value.findIndex((file) => file[bindKey2] === id);
18764
+ if (index2 !== -1) storageFiles.value.splice(index2, 1);
18765
+ });
18766
+ if (bindKey2 === "url") {
18767
+ idsToAdd.forEach((url) => {
18768
+ storageFiles.value.push({ url });
18769
+ });
18770
+ return;
18771
+ }
18772
+ if (props2.multiple) {
18773
+ idsToAdd.forEach((id) => {
18774
+ void bagel.get(`/files/${id}`).then((file) => {
18744
18775
  storageFiles.value.push(file);
18745
18776
  }).catch(console.error);
18746
- }
18777
+ });
18778
+ } else {
18779
+ void bagel.get(`/files/${idsToAdd[0]}`).then((file) => {
18780
+ storageFiles.value.push(file);
18781
+ }).catch(console.error);
18782
+ }
18783
+ }
18784
+ vue.onMounted(() => {
18785
+ if (props2.topic) fetchTopicFiles();
18786
+ if (!props2.files && [file_bindkeys.value].flat().length > 0) {
18787
+ loadFiles();
18747
18788
  }
18748
18789
  });
18790
+ vue.watch(() => props2.topic, fetchTopicFiles);
18791
+ vue.watch(() => props2.modelValue, loadFiles);
18749
18792
  vue.watch(
18750
18793
  () => props2.files,
18751
18794
  (newFiles) => {
@@ -18762,17 +18805,6 @@ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
18762
18805
  function compareLists(a2, b2) {
18763
18806
  return [a2].flat().every((id) => [b2].flat().includes(id)) && [b2].flat().every((id) => [a2].flat().includes(id));
18764
18807
  }
18765
- vue.watch(() => props2.modelValue, (newVal = []) => {
18766
- console.log(newVal, "newVal");
18767
- const isSame = compareLists(file_bindkeys.value, newVal);
18768
- if (!isSame) {
18769
- file_bindkeys.value = newVal;
18770
- for (const fle of storageFiles.value) {
18771
- const index2 = [file_bindkeys.value].flat().findIndex((key) => fle[bindKey2] === key);
18772
- if (index2 === -1) storageFiles.value.splice(index2, 1);
18773
- }
18774
- }
18775
- });
18776
18808
  function updateModelValue() {
18777
18809
  let idValue;
18778
18810
  if (props2.multiple) {
@@ -18783,7 +18815,6 @@ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
18783
18815
  const isSame = compareLists(file_bindkeys.value, idValue);
18784
18816
  if (!isSame) {
18785
18817
  file_bindkeys.value = idValue;
18786
- emit2("update:modelValue", file_bindkeys.value);
18787
18818
  }
18788
18819
  }
18789
18820
  const fileQueue = vue.ref([]);
@@ -19102,7 +19133,7 @@ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
19102
19133
  };
19103
19134
  }
19104
19135
  });
19105
- const $el = /* @__PURE__ */ _export_sfc(_sfc_main$D, [["__scopeId", "data-v-0dfbee23"]]);
19136
+ const $el = /* @__PURE__ */ _export_sfc(_sfc_main$D, [["__scopeId", "data-v-30231b53"]]);
19106
19137
  const _hoisted_1$u = ["title"];
19107
19138
  const _hoisted_2$k = { key: 0 };
19108
19139
  const _hoisted_3$g = ["value", "placeholder"];
package/dist/index.mjs CHANGED
@@ -9621,15 +9621,40 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
9621
9621
  emit2("update:modelValue", val);
9622
9622
  }
9623
9623
  });
9624
+ const objPathRegex = /[.\][]/;
9625
+ function setFieldData(key, val) {
9626
+ const data2 = { ...props2.modelValue };
9627
+ const keys4 = key.split(objPathRegex);
9628
+ let temp = data2;
9629
+ for (let i2 = 0; i2 < keys4.length - 1; i2++) {
9630
+ if (!temp[keys4[i2]]) {
9631
+ temp[keys4[i2]] = {};
9632
+ }
9633
+ temp = temp[keys4[i2]];
9634
+ }
9635
+ temp[keys4[keys4.length - 1]] = val;
9636
+ return data2;
9637
+ }
9638
+ function getFieldData(obj, key) {
9639
+ const keys4 = key.split(objPathRegex);
9640
+ let result2 = obj;
9641
+ for (const k2 of keys4) {
9642
+ if (result2 && k2 in result2) {
9643
+ result2 = result2[k2];
9644
+ } else {
9645
+ return void 0;
9646
+ }
9647
+ }
9648
+ return result2;
9649
+ }
9624
9650
  const fieldData = computed({
9625
9651
  set: (val) => {
9626
9652
  if (!props2.field.id) return;
9627
- const data2 = { ...props2.modelValue };
9628
- data2[props2.field.id] = val;
9653
+ const data2 = setFieldData(props2.field.id, val);
9629
9654
  emit2("update:modelValue", data2);
9630
9655
  },
9631
9656
  get: () => {
9632
- if (props2.field.id) return props2.modelValue[props2.field.id];
9657
+ if (props2.field.id) return getFieldData(props2.modelValue, props2.field.id);
9633
9658
  return props2.field.defaultValue ?? "";
9634
9659
  }
9635
9660
  });
@@ -18692,7 +18717,7 @@ const _hoisted_17 = ["src"];
18692
18717
  const _hoisted_18 = { class: "p-1 flex column hover fileUploadPlaceHolder justify-content-center mb-05" };
18693
18718
  const _sfc_main$D = /* @__PURE__ */ defineComponent({
18694
18719
  __name: "FileUpload",
18695
- props: {
18720
+ props: /* @__PURE__ */ mergeModels({
18696
18721
  label: {},
18697
18722
  multiple: { type: Boolean },
18698
18723
  files: {},
@@ -18706,44 +18731,62 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
18706
18731
  theme: {},
18707
18732
  accept: {},
18708
18733
  required: { type: Boolean }
18709
- },
18710
- emits: ["update:modelValue", "addFileStart"],
18734
+ }, {
18735
+ "modelValue": { default: () => [] },
18736
+ "modelModifiers": {}
18737
+ }),
18738
+ emits: /* @__PURE__ */ mergeModels(["update:modelValue", "addFileStart"], ["update:modelValue"]),
18711
18739
  setup(__props, { emit: __emit }) {
18712
18740
  const props2 = __props;
18713
18741
  const emit2 = __emit;
18714
18742
  const bindKey2 = props2.bindkey || "id";
18715
18743
  const bagel = useBagel();
18716
18744
  const isImage = (str) => IMAGE_FORMATS_REGEXP.test(str);
18717
- let file_bindkeys = ref(props2.modelValue || []);
18745
+ const file_bindkeys = useModel(__props, "modelValue");
18718
18746
  const storageFiles = ref([]);
18719
- async function fetchFiles() {
18747
+ async function fetchTopicFiles() {
18720
18748
  const files = await bagel.get(`/files?topic=${props2.topic}`);
18721
18749
  storageFiles.value.push(...files);
18722
18750
  }
18723
- onMounted(() => {
18724
- if (props2.topic) fetchFiles();
18725
- if (!props2.files && [file_bindkeys.value].flat().length > 0) {
18726
- const ids = [file_bindkeys.value].flat().filter(Boolean);
18727
- if (!(ids == null ? void 0 : ids.length)) return;
18728
- if (bindKey2 === "url") {
18729
- ids.forEach((url) => {
18730
- storageFiles.value.push({ url });
18731
- });
18732
- return;
18733
- }
18734
- if (props2.multiple) {
18735
- ids.forEach((id) => {
18736
- void bagel.get(`/files/${id}`).then((file) => {
18737
- storageFiles.value.push(file);
18738
- }).catch(console.error);
18739
- });
18740
- } else {
18741
- void bagel.get(`/files/${ids[0]}`).then((file) => {
18751
+ function loadFiles() {
18752
+ const ids = [file_bindkeys.value].flat().filter(Boolean);
18753
+ if (!ids.length) {
18754
+ storageFiles.value.splice(0, storageFiles.value.length);
18755
+ return;
18756
+ }
18757
+ const currentIds = storageFiles.value.map((file) => file[bindKey2]);
18758
+ const idsToAdd = ids.filter((id) => !currentIds.includes(id));
18759
+ const idsToRemove = currentIds.filter((id) => (typeof id === "string" || typeof id === "number") && !ids.includes(id));
18760
+ idsToRemove.forEach((id) => {
18761
+ const index2 = storageFiles.value.findIndex((file) => file[bindKey2] === id);
18762
+ if (index2 !== -1) storageFiles.value.splice(index2, 1);
18763
+ });
18764
+ if (bindKey2 === "url") {
18765
+ idsToAdd.forEach((url) => {
18766
+ storageFiles.value.push({ url });
18767
+ });
18768
+ return;
18769
+ }
18770
+ if (props2.multiple) {
18771
+ idsToAdd.forEach((id) => {
18772
+ void bagel.get(`/files/${id}`).then((file) => {
18742
18773
  storageFiles.value.push(file);
18743
18774
  }).catch(console.error);
18744
- }
18775
+ });
18776
+ } else {
18777
+ void bagel.get(`/files/${idsToAdd[0]}`).then((file) => {
18778
+ storageFiles.value.push(file);
18779
+ }).catch(console.error);
18780
+ }
18781
+ }
18782
+ onMounted(() => {
18783
+ if (props2.topic) fetchTopicFiles();
18784
+ if (!props2.files && [file_bindkeys.value].flat().length > 0) {
18785
+ loadFiles();
18745
18786
  }
18746
18787
  });
18788
+ watch(() => props2.topic, fetchTopicFiles);
18789
+ watch(() => props2.modelValue, loadFiles);
18747
18790
  watch(
18748
18791
  () => props2.files,
18749
18792
  (newFiles) => {
@@ -18760,17 +18803,6 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
18760
18803
  function compareLists(a2, b2) {
18761
18804
  return [a2].flat().every((id) => [b2].flat().includes(id)) && [b2].flat().every((id) => [a2].flat().includes(id));
18762
18805
  }
18763
- watch(() => props2.modelValue, (newVal = []) => {
18764
- console.log(newVal, "newVal");
18765
- const isSame = compareLists(file_bindkeys.value, newVal);
18766
- if (!isSame) {
18767
- file_bindkeys.value = newVal;
18768
- for (const fle of storageFiles.value) {
18769
- const index2 = [file_bindkeys.value].flat().findIndex((key) => fle[bindKey2] === key);
18770
- if (index2 === -1) storageFiles.value.splice(index2, 1);
18771
- }
18772
- }
18773
- });
18774
18806
  function updateModelValue() {
18775
18807
  let idValue;
18776
18808
  if (props2.multiple) {
@@ -18781,7 +18813,6 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
18781
18813
  const isSame = compareLists(file_bindkeys.value, idValue);
18782
18814
  if (!isSame) {
18783
18815
  file_bindkeys.value = idValue;
18784
- emit2("update:modelValue", file_bindkeys.value);
18785
18816
  }
18786
18817
  }
18787
18818
  const fileQueue = ref([]);
@@ -19100,7 +19131,7 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
19100
19131
  };
19101
19132
  }
19102
19133
  });
19103
- const $el = /* @__PURE__ */ _export_sfc(_sfc_main$D, [["__scopeId", "data-v-0dfbee23"]]);
19134
+ const $el = /* @__PURE__ */ _export_sfc(_sfc_main$D, [["__scopeId", "data-v-30231b53"]]);
19104
19135
  const _hoisted_1$u = ["title"];
19105
19136
  const _hoisted_2$k = { key: 0 };
19106
19137
  const _hoisted_3$g = ["value", "placeholder"];
package/dist/style.css CHANGED
@@ -707,7 +707,7 @@ data[data-v-6c27f163] {
707
707
  }
708
708
  }
709
709
 
710
- .fileUploadWrap[data-v-0dfbee23] {
710
+ .fileUploadWrap[data-v-30231b53] {
711
711
  outline: 1px solid var(--border-color);
712
712
  border-radius: var(--input-border-radius);
713
713
  text-align: center;
@@ -719,7 +719,7 @@ data[data-v-6c27f163] {
719
719
  background: var(--input-bg);
720
720
  height: 215px;
721
721
  }
722
- .bagel-input .fileUploadWrap.fileDropZone[data-v-0dfbee23] {
722
+ .bagel-input .fileUploadWrap.fileDropZone[data-v-30231b53] {
723
723
  background: var(--input-bg);
724
724
  display: flex;
725
725
  align-items: center;
@@ -727,14 +727,14 @@ data[data-v-6c27f163] {
727
727
  color: var(--bgl-gray);
728
728
  flex-direction: column;
729
729
  }
730
- .fileUploadWrap.dragover[data-v-0dfbee23],
731
- .fileUploadWrap[data-v-0dfbee23]:hover {
730
+ .fileUploadWrap.dragover[data-v-30231b53],
731
+ .fileUploadWrap[data-v-30231b53]:hover {
732
732
  box-shadow: inset 0 0 10px #00000012;
733
733
  }
734
- .fileUploadWrap[style*="height: auto;"][data-v-0dfbee23] {
734
+ .fileUploadWrap[style*="height: auto;"][data-v-30231b53] {
735
735
  min-height: 215px;
736
736
  }
737
- .multi-image-item-preview[data-v-0dfbee23] {
737
+ .multi-image-item-preview[data-v-30231b53] {
738
738
  border: 1px solid var(--border-color) !important;
739
739
  border-radius: var(--input-border-radius);
740
740
  margin: 0.5rem !important;
@@ -748,12 +748,12 @@ data[data-v-6c27f163] {
748
748
  gap: 1rem;
749
749
  align-items: center;
750
750
  }
751
- .multi-image-item-preview p[data-v-0dfbee23] {
751
+ .multi-image-item-preview p[data-v-30231b53] {
752
752
  overflow: hidden;
753
753
  text-overflow: ellipsis;
754
754
  white-space: nowrap;
755
755
  }
756
- .multi-preview[data-v-0dfbee23]{
756
+ .multi-preview[data-v-30231b53]{
757
757
  width: 40px;
758
758
  height: 40px;
759
759
  border-radius: var(--input-border-radius);
@@ -764,17 +764,17 @@ data[data-v-6c27f163] {
764
764
  align-items: center;
765
765
  display: flex;
766
766
  }
767
- .bgl-single-preview[data-v-0dfbee23]{
767
+ .bgl-single-preview[data-v-30231b53]{
768
768
  height: 100%;
769
769
  position: relative;
770
770
  }
771
- .bgl-single-preview + .fileUploadPlaceHolder[data-v-0dfbee23]{
771
+ .bgl-single-preview + .fileUploadPlaceHolder[data-v-30231b53]{
772
772
  position: absolute;
773
773
  inset: 0;
774
774
  margin: auto;
775
775
  top: calc(50% - 2rem);
776
776
  }
777
- .single-image-item-preview[data-v-0dfbee23] {
777
+ .single-image-item-preview[data-v-30231b53] {
778
778
  height: 100%;
779
779
  min-height: 100%;
780
780
  position: relative;
@@ -782,13 +782,13 @@ data[data-v-6c27f163] {
782
782
  align-items: center;
783
783
  justify-content: center;
784
784
  }
785
- .fileUploadWrap[style*="height: auto"] .single-image-item-preview[data-v-0dfbee23] {
785
+ .fileUploadWrap[style*="height: auto"] .single-image-item-preview[data-v-30231b53] {
786
786
  min-height: 215px;
787
787
  }
788
- .fileUploadWrap[style*="height: auto"] .single-preview[data-v-0dfbee23] {
788
+ .fileUploadWrap[style*="height: auto"] .single-preview[data-v-30231b53] {
789
789
  margin: 0rem !important;
790
790
  }
791
- .single-preview[data-v-0dfbee23]{
791
+ .single-preview[data-v-30231b53]{
792
792
  border-radius: var(--input-border-radius);
793
793
  margin: 1rem;
794
794
  padding: 0px;
@@ -797,7 +797,7 @@ data[data-v-6c27f163] {
797
797
  object-fit: cover;
798
798
  background: var(--bgl-gray-light);
799
799
  }
800
- .single-image-item-preview[data-v-0dfbee23]:hover::after{
800
+ .single-image-item-preview[data-v-30231b53]:hover::after{
801
801
  content: "zoom_in";
802
802
  font-size: 32px;
803
803
  font-family: "Material Symbols Outlined", serif;
@@ -807,20 +807,20 @@ data[data-v-6c27f163] {
807
807
  z-index: 9;
808
808
  pointer-events: none;
809
809
  }
810
- .single-image-item-preview:hover img[data-v-0dfbee23]{
810
+ .single-image-item-preview:hover img[data-v-30231b53]{
811
811
  filter: brightness(70%);
812
812
  }
813
- .bgl_fill-image.single-image-item-preview[data-v-0dfbee23] {
813
+ .bgl_fill-image.single-image-item-preview[data-v-30231b53] {
814
814
  height: 100%;
815
815
  }
816
- .bgl_fill-image.single-image-item-preview .single-preview[data-v-0dfbee23]{
816
+ .bgl_fill-image.single-image-item-preview .single-preview[data-v-30231b53]{
817
817
  border-radius: unset;
818
818
  object-fit: cover;
819
819
  box-shadow: unset;
820
820
  width: 100%;
821
821
  height: auto;
822
822
  }
823
- .single-image-item-preview .pie[data-v-0dfbee23] {
823
+ .single-image-item-preview .pie[data-v-30231b53] {
824
824
  transform-origin: top;
825
825
  transform: scale(1.4);
826
826
  position: absolute;
@@ -834,31 +834,31 @@ data[data-v-6c27f163] {
834
834
  border: none !important;
835
835
  padding: 0 !important;
836
836
  }
837
- .bgl_oval-upload[data-v-0dfbee23] {
837
+ .bgl_oval-upload[data-v-30231b53] {
838
838
  border-radius: 100% !important;
839
839
  overflow: hidden;
840
840
  }
841
- .bgl_oval-upload p[data-v-0dfbee23] {
841
+ .bgl_oval-upload p[data-v-30231b53] {
842
842
  padding: 0.75rem !important;
843
843
  font-size: 12px
844
844
  }
845
- .bgl_oval-upload .fileUploadPlaceHolder[data-v-0dfbee23]{
845
+ .bgl_oval-upload .fileUploadPlaceHolder[data-v-30231b53]{
846
846
  top: 0;
847
847
  }
848
- .bgl_oval-upload .pie[data-v-0dfbee23] {
848
+ .bgl_oval-upload .pie[data-v-30231b53] {
849
849
  transform: scale(1);
850
850
  }
851
- .bgl_oval-upload span.bgl_icon-font.color-primary[data-v-0dfbee23] {
851
+ .bgl_oval-upload span.bgl_icon-font.color-primary[data-v-30231b53] {
852
852
  transform: scale(0.4) !important;
853
853
  }
854
- .bgl_oval-upload .single-image-item-preview[data-v-0dfbee23]{
854
+ .bgl_oval-upload .single-image-item-preview[data-v-30231b53]{
855
855
  height: 100%;
856
856
  }
857
- .bgl_oval-upload .single-preview[data-v-0dfbee23] {
857
+ .bgl_oval-upload .single-preview[data-v-30231b53] {
858
858
  margin: 0;
859
859
  height: 100% !important;
860
860
  }
861
- .pie[data-v-0dfbee23] {
861
+ .pie[data-v-30231b53] {
862
862
  width: 30px;
863
863
  height: 30px;
864
864
  position: relative;
@@ -866,7 +866,7 @@ data[data-v-6c27f163] {
866
866
  align-items: center;
867
867
  justify-content: center;
868
868
  }
869
- .pie[data-v-0dfbee23]:before {
869
+ .pie[data-v-30231b53]:before {
870
870
  content: '';
871
871
  position: absolute;
872
872
  border-radius: 50%;
@@ -884,26 +884,26 @@ data[data-v-6c27f163] {
884
884
  #000 calc(100% - var(--b))
885
885
  );
886
886
  }
887
- .pie .success[data-v-0dfbee23] {
887
+ .pie .success[data-v-30231b53] {
888
888
  transform: scale(0);
889
889
  opacity: 0;
890
890
  transition: all 0.3s ease-in-out;
891
891
  }
892
- .pie .progress[data-v-0dfbee23] {
892
+ .pie .progress[data-v-30231b53] {
893
893
  position: absolute;
894
894
  font-size: 10px;
895
895
  }
896
- .pie.complete .progress[data-v-0dfbee23] {
896
+ .pie.complete .progress[data-v-30231b53] {
897
897
  display: none;
898
898
  }
899
- .pie.complete .success[data-v-0dfbee23] {
899
+ .pie.complete .success[data-v-30231b53] {
900
900
  transform: scale(1.3);
901
901
  opacity: 1;
902
902
  }
903
- .pie.complete[data-v-0dfbee23]:before {
903
+ .pie.complete[data-v-30231b53]:before {
904
904
  background: conic-gradient(var(--bgl-green) calc(var(--p) * 1%), #0000 0);
905
905
  }
906
- .pie.complete[data-v-0dfbee23] {
906
+ .pie.complete[data-v-30231b53] {
907
907
  color: var(--bgl-green);
908
908
  }
909
909
 
@@ -3598,6 +3598,12 @@ to {
3598
3598
  .align-content-center {
3599
3599
  align-content: center;
3600
3600
  }
3601
+ .align-content-start {
3602
+ align-content: start;
3603
+ }
3604
+ .align-content-end {
3605
+ align-content: end;
3606
+ }
3601
3607
  .align-content-space-between {
3602
3608
  align-content: space-between;
3603
3609
  }
@@ -6934,6 +6940,14 @@ to {
6934
6940
  align-content: center;
6935
6941
  }
6936
6942
 
6943
+ .m_align-content-start {
6944
+ align-content: start;
6945
+ }
6946
+
6947
+ .m_align-content-end {
6948
+ align-content: end;
6949
+ }
6950
+
6937
6951
  .m_align-content-space-between {
6938
6952
  align-content: space-between;
6939
6953
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "0.0.953",
4
+ "version": "0.0.957",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -48,15 +48,43 @@ const formData = $computed({
48
48
  },
49
49
  })
50
50
 
51
+ const objPathRegex = /[.\][]/
52
+
53
+ function setFieldData(key: string, val: any) {
54
+ const data = { ...props.modelValue }
55
+ const keys = key.split(objPathRegex)
56
+ let temp = data
57
+ for (let i = 0; i < keys.length - 1; i++) {
58
+ if (!temp[keys[i]]) {
59
+ temp[keys[i]] = {}
60
+ }
61
+ temp = temp[keys[i]]
62
+ }
63
+ temp[keys[keys.length - 1]] = val
64
+ return data
65
+ }
66
+
67
+ function getFieldData(obj: Record<string, any>, key: string) {
68
+ const keys = key.split(objPathRegex)
69
+ let result = obj
70
+ for (const k of keys) {
71
+ if (result && k in result) {
72
+ result = result[k]
73
+ } else {
74
+ return undefined
75
+ }
76
+ }
77
+ return result
78
+ }
79
+
51
80
  const fieldData = $computed({
52
81
  set: (val: any) => {
53
82
  if (!props.field.id) return
54
- const data = { ...props.modelValue }
55
- data[props.field.id] = val
83
+ const data = setFieldData(props.field.id, val)
56
84
  emit('update:modelValue', data)
57
85
  },
58
86
  get: () => {
59
- if (props.field.id) return props.modelValue[props.field.id]
87
+ if (props.field.id) return getFieldData(props.modelValue, props.field.id)
60
88
  return props.field.defaultValue ?? ''
61
89
  },
62
90
  })
@@ -38,45 +38,66 @@ interface QueueFile {
38
38
 
39
39
  const isImage = (str: string) => IMAGE_FORMATS_REGEXP.test(str)
40
40
 
41
- let file_bindkeys = $ref<FSValue>(props.modelValue || [])
41
+ const file_bindkeys = defineModel('modelValue', { default: () => [] as FSValue })
42
42
  const storageFiles = $ref<StorageFile[]>([])
43
43
 
44
- async function fetchFiles() {
44
+ async function fetchTopicFiles() {
45
45
  const files = await bagel.get<StorageFile[]>(`/files?topic=${props.topic}`)
46
46
  storageFiles.push(...files)
47
47
  }
48
48
 
49
- onMounted(() => {
50
- if (props.topic) fetchFiles()
51
- if (!props.files && [file_bindkeys].flat().length > 0) {
52
- const ids = [file_bindkeys].flat().filter(Boolean) as (string | number)[] | undefined
53
- if (!ids?.length) return
54
- if (bindKey === 'url') {
55
- ids.forEach((url) => {
56
- storageFiles.push({ url } as StorageFile)
57
- })
58
- return
59
- }
60
- if (props.multiple) {
61
- ids.forEach((id) => {
62
- void bagel
63
- .get<StorageFile>(`/files/${id}`)
64
- .then((file) => {
65
- storageFiles.push(file)
66
- })
67
- .catch(console.error)
68
- })
69
- } else {
49
+ function loadFiles() {
50
+ const ids = ([file_bindkeys.value].flat().filter(Boolean) as unknown) as (string | number)[]
51
+ if (!ids.length) {
52
+ storageFiles.splice(0, storageFiles.length)
53
+ return
54
+ }
55
+
56
+ const currentIds = storageFiles.map(file => file[bindKey])
57
+ const idsToAdd = ids.filter(id => !currentIds.includes(id))
58
+ const idsToRemove = currentIds.filter((id): id is string | number => (typeof id === 'string' || typeof id === 'number') && !ids.includes(id))
59
+
60
+ idsToRemove.forEach((id) => {
61
+ const index = storageFiles.findIndex(file => file[bindKey] === id)
62
+ if (index !== -1) storageFiles.splice(index, 1)
63
+ })
64
+
65
+ if (bindKey === 'url') {
66
+ idsToAdd.forEach((url) => {
67
+ storageFiles.push({ url } as StorageFile)
68
+ })
69
+ return
70
+ }
71
+
72
+ if (props.multiple) {
73
+ idsToAdd.forEach((id) => {
70
74
  void bagel
71
- .get<StorageFile>(`/files/${ids[0]}`)
75
+ .get<StorageFile>(`/files/${id}`)
72
76
  .then((file) => {
73
77
  storageFiles.push(file)
74
78
  })
75
79
  .catch(console.error)
76
- }
80
+ })
81
+ } else {
82
+ void bagel
83
+ .get<StorageFile>(`/files/${idsToAdd[0]}`)
84
+ .then((file) => {
85
+ storageFiles.push(file)
86
+ })
87
+ .catch(console.error)
88
+ }
89
+ }
90
+
91
+ onMounted(() => {
92
+ if (props.topic) fetchTopicFiles()
93
+ if (!props.files && [file_bindkeys.value].flat().length > 0) {
94
+ loadFiles()
77
95
  }
78
96
  })
79
97
 
98
+ watch(() => props.topic, fetchTopicFiles)
99
+ watch(() => props.modelValue, loadFiles)
100
+
80
101
  watch(
81
102
  () => props.files,
82
103
  (newFiles) => {
@@ -100,18 +121,6 @@ function compareLists(a: any, b: any) {
100
121
  .every((id: any) => [b].flat().includes(id)) && [b].flat().every(id => [a].flat().includes(id))
101
122
  }
102
123
 
103
- watch(() => props.modelValue, (newVal: FSValue = []) => {
104
- console.log(newVal, 'newVal')
105
- const isSame = compareLists(file_bindkeys, newVal)
106
- if (!isSame) {
107
- file_bindkeys = newVal
108
- for (const fle of storageFiles) {
109
- const index = [file_bindkeys].flat().findIndex(key => fle[bindKey] === key)
110
- if (index === -1) storageFiles.splice(index, 1)
111
- }
112
- }
113
- })
114
-
115
124
  function updateModelValue() {
116
125
  let idValue: FSValue
117
126
  if (props.multiple) {
@@ -119,10 +128,9 @@ function updateModelValue() {
119
128
  } else {
120
129
  idValue = (storageFiles[0][bindKey] as string) || ''
121
130
  }
122
- const isSame = compareLists(file_bindkeys, idValue)
131
+ const isSame = compareLists(file_bindkeys.value, idValue)
123
132
  if (!isSame) {
124
- file_bindkeys = idValue
125
- emit('update:modelValue', file_bindkeys)
133
+ file_bindkeys.value = idValue
126
134
  }
127
135
  }
128
136
 
@@ -77,6 +77,14 @@
77
77
  align-content: center;
78
78
  }
79
79
 
80
+ .align-content-start {
81
+ align-content: start;
82
+ }
83
+
84
+ .align-content-end {
85
+ align-content: end;
86
+ }
87
+
80
88
  .align-content-space-between {
81
89
  align-content: space-between;
82
90
  }
@@ -102,6 +102,14 @@
102
102
  align-content: center;
103
103
  }
104
104
 
105
+ .m_align-content-start {
106
+ align-content: start;
107
+ }
108
+
109
+ .m_align-content-end {
110
+ align-content: end;
111
+ }
112
+
105
113
  .m_align-content-space-between {
106
114
  align-content: space-between;
107
115
  }