@bagelink/vue 1.0.41 → 1.0.47

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.mjs CHANGED
@@ -1626,7 +1626,7 @@ const _hoisted_10$7 = {
1626
1626
  key: 4,
1627
1627
  class: "event-flyout__row is-topic"
1628
1628
  };
1629
- const _hoisted_11$6 = {
1629
+ const _hoisted_11$7 = {
1630
1630
  key: 5,
1631
1631
  class: "event-flyout__row is-description"
1632
1632
  };
@@ -1853,7 +1853,7 @@ const _sfc_main$1c = /* @__PURE__ */ defineComponent({
1853
1853
  }, null, 8, ["icon"]),
1854
1854
  createTextVNode(" " + toDisplayString(calendarEvent.value.topic), 1)
1855
1855
  ])) : createCommentVNode("", true),
1856
- calendarEvent.value.description ? (openBlock(), createElementBlock("div", _hoisted_11$6, [
1856
+ calendarEvent.value.description ? (openBlock(), createElementBlock("div", _hoisted_11$7, [
1857
1857
  createVNode(unref(_sfc_main$s), {
1858
1858
  icon: icons.description
1859
1859
  }, null, 8, ["icon"]),
@@ -10686,6 +10686,8 @@ const SRC_VALUE_COMPONENTS = /* @__PURE__ */ new Set(["img", "iframe"]);
10686
10686
  function useTableData(options) {
10687
10687
  const sortField = ref("");
10688
10688
  const sortDirection = ref("ASC");
10689
+ const schemaState = ref("loading");
10690
+ const resolvedSchema = ref([]);
10689
10691
  function getValue(value) {
10690
10692
  if (value === void 0 || value === null) {
10691
10693
  return void 0;
@@ -10700,31 +10702,50 @@ function useTableData(options) {
10700
10702
  return void 0;
10701
10703
  }
10702
10704
  }
10703
- const computedSchema = computed(() => {
10704
- const dataValue = options.data.value || [];
10705
- const schema = useBglSchema({
10706
- schema: getValue(options.schema),
10707
- columns: getValue(options.columns),
10708
- data: dataValue
10709
- });
10710
- if (Array.isArray(schema) && schema.length > 0) {
10711
- return schema.filter((field) => field && field.id);
10712
- }
10713
- if (Array.isArray(dataValue) && dataValue.length > 0) {
10714
- const firstItem = dataValue[0];
10715
- return Object.keys(firstItem || {}).filter((key) => key !== "id" && !key.startsWith("_")).map((key) => ({
10716
- id: key,
10717
- label: keyToLabel(key),
10718
- $el: "div",
10719
- transform: (val) => {
10720
- const dateFields = ["created_at", "updated_at"];
10721
- if (dateFields.includes(key)) return val ? new Date(val).toLocaleString() : val;
10722
- return val;
10723
- }
10724
- }));
10705
+ async function resolveSchemaAsync() {
10706
+ try {
10707
+ schemaState.value = "loading";
10708
+ const dataValue = options.data.value || [];
10709
+ const schema = await useBglSchema({
10710
+ schema: getValue(options.schema),
10711
+ columns: getValue(options.columns),
10712
+ data: dataValue
10713
+ });
10714
+ if (Array.isArray(schema) && schema.length > 0) {
10715
+ resolvedSchema.value = schema.filter((field) => field && field.id);
10716
+ } else if (Array.isArray(dataValue) && dataValue.length > 0) {
10717
+ const firstItem = dataValue[0];
10718
+ resolvedSchema.value = Object.keys(firstItem || {}).filter((key) => key !== "id" && !key.startsWith("_")).map((key) => ({
10719
+ id: key,
10720
+ label: keyToLabel(key),
10721
+ $el: "div",
10722
+ transform: (val) => {
10723
+ const dateFields = ["created_at", "updated_at"];
10724
+ if (dateFields.includes(key)) return val ? new Date(val).toLocaleString() : val;
10725
+ return val;
10726
+ }
10727
+ }));
10728
+ } else {
10729
+ resolvedSchema.value = [];
10730
+ }
10731
+ schemaState.value = "loaded";
10732
+ } catch (error) {
10733
+ console.error("Error resolving schema:", error);
10734
+ schemaState.value = "error";
10735
+ resolvedSchema.value = [];
10725
10736
  }
10726
- return [];
10737
+ }
10738
+ watch([
10739
+ () => getValue(options.schema),
10740
+ () => getValue(options.columns),
10741
+ () => options.data.value
10742
+ ], () => {
10743
+ resolveSchemaAsync();
10744
+ }, { immediate: true });
10745
+ onMounted(() => {
10746
+ resolveSchemaAsync();
10727
10747
  });
10748
+ const computedSchema = computed(() => resolvedSchema.value);
10728
10749
  function transform(rowData) {
10729
10750
  const transformed = { ...rowData };
10730
10751
  const schemaFields = computedSchema.value.filter((f2) => f2.id);
@@ -10806,7 +10827,8 @@ function useTableData(options) {
10806
10827
  sortField: computed(() => sortField.value),
10807
10828
  sortDirection: computed(() => sortDirection.value),
10808
10829
  toggleSort,
10809
- cleanTransformedData
10830
+ cleanTransformedData,
10831
+ schemaState: computed(() => schemaState.value)
10810
10832
  };
10811
10833
  }
10812
10834
  const _hoisted_1$P = { class: "data-preview" };
@@ -11510,15 +11532,19 @@ const _hoisted_1$O = {
11510
11532
  key: 0,
11511
11533
  class: "loading-table-wrapper z-99 h-100 w-100 absolute inset"
11512
11534
  };
11513
- const _hoisted_2$A = { class: "infinite-wrapper" };
11514
- const _hoisted_3$u = { class: "row first-row" };
11515
- const _hoisted_4$k = { key: 0 };
11516
- const _hoisted_5$j = ["onClick"];
11517
- const _hoisted_6$g = { class: "flex" };
11518
- const _hoisted_7$c = ["onClick"];
11519
- const _hoisted_8$7 = { key: 0 };
11520
- const _hoisted_9$6 = ["value"];
11521
- const _hoisted_10$6 = { key: 1 };
11535
+ const _hoisted_2$A = {
11536
+ key: 1,
11537
+ class: "flex-center h-300px txt-red"
11538
+ };
11539
+ const _hoisted_3$u = { class: "infinite-wrapper" };
11540
+ const _hoisted_4$k = { class: "row first-row" };
11541
+ const _hoisted_5$j = { key: 0 };
11542
+ const _hoisted_6$g = ["onClick"];
11543
+ const _hoisted_7$c = { class: "flex" };
11544
+ const _hoisted_8$7 = ["onClick"];
11545
+ const _hoisted_9$6 = { key: 0 };
11546
+ const _hoisted_10$6 = ["value"];
11547
+ const _hoisted_11$6 = { key: 1 };
11522
11548
  const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11523
11549
  __name: "DataTable",
11524
11550
  props: /* @__PURE__ */ mergeModels({
@@ -11539,7 +11565,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11539
11565
  emits: /* @__PURE__ */ mergeModels(["orderBy", "select", "lastItemVisible"], ["update:loading", "update:itemHeight", "update:selectedItems"]),
11540
11566
  setup(__props, { emit: __emit }) {
11541
11567
  useCssVars((_ctx) => ({
11542
- "31aad8d2": unref(computedItemHeight)
11568
+ "03db8ce0": unref(computedItemHeight)
11543
11569
  }));
11544
11570
  const props2 = __props;
11545
11571
  const emit2 = __emit;
@@ -11557,7 +11583,8 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11557
11583
  sortField,
11558
11584
  sortDirection,
11559
11585
  toggleSort,
11560
- cleanTransformedData
11586
+ cleanTransformedData,
11587
+ schemaState
11561
11588
  } = useTableData({ data: data2, schema, columns, useServerSort, onSort: (field, direction) => {
11562
11589
  emit2("orderBy", `${field} ${direction}`.trim());
11563
11590
  } });
@@ -11628,14 +11655,14 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11628
11655
  );
11629
11656
  return (_ctx, _cache) => {
11630
11657
  return openBlock(), createElementBlock("div", mergeProps({ class: "table-list-wrap h-100" }, unref(containerProps), {
11631
- class: { "loading-table": loading.value }
11658
+ class: { "loading-table": loading.value || unref(schemaState) === "loading" }
11632
11659
  }), [
11633
- loading.value ? (openBlock(), createElementBlock("div", _hoisted_1$O, _cache[4] || (_cache[4] = [
11660
+ loading.value || unref(schemaState) === "loading" ? (openBlock(), createElementBlock("div", _hoisted_1$O, _cache[4] || (_cache[4] = [
11634
11661
  createElementVNode("div", { class: "loading-table-animation absolute oval" }, null, -1)
11635
- ]))) : (openBlock(), createElementBlock("div", normalizeProps(mergeProps({ key: 1 }, unref(wrapperProps))), [
11636
- createElementVNode("table", _hoisted_2$A, [
11637
- createElementVNode("thead", _hoisted_3$u, [
11638
- unref(isSelectable) ? (openBlock(), createElementBlock("th", _hoisted_4$k, [
11662
+ ]))) : unref(schemaState) === "error" ? (openBlock(), createElementBlock("div", _hoisted_2$A, " Error loading table schema ")) : (openBlock(), createElementBlock("div", normalizeProps(mergeProps({ key: 2 }, unref(wrapperProps))), [
11663
+ createElementVNode("table", _hoisted_3$u, [
11664
+ createElementVNode("thead", _hoisted_4$k, [
11665
+ unref(isSelectable) ? (openBlock(), createElementBlock("th", _hoisted_5$j, [
11639
11666
  createElementVNode("input", {
11640
11667
  ref_key: "allSelectorEl",
11641
11668
  ref: allSelectorEl,
@@ -11652,7 +11679,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11652
11679
  class: "col",
11653
11680
  onClick: ($event) => unref(toggleSort)((field == null ? void 0 : field.id) || "")
11654
11681
  }, [
11655
- createElementVNode("div", _hoisted_6$g, [
11682
+ createElementVNode("div", _hoisted_7$c, [
11656
11683
  createTextVNode(toDisplayString(field.label || unref(keyToLabel)(field == null ? void 0 : field.id)) + " ", 1),
11657
11684
  createElementVNode("div", {
11658
11685
  class: normalizeClass(["list-arrows", { sorted: unref(sortField) === (field == null ? void 0 : field.id) }])
@@ -11663,7 +11690,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11663
11690
  }, null, 8, ["class"])
11664
11691
  ], 2)
11665
11692
  ])
11666
- ], 8, _hoisted_5$j);
11693
+ ], 8, _hoisted_6$g);
11667
11694
  }), 128))
11668
11695
  ]),
11669
11696
  createElementVNode("tbody", null, [
@@ -11673,7 +11700,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11673
11700
  class: normalizeClass(["row row-item position-relative", { selected: (row == null ? void 0 : row.id) && unref(computedSelectedItems).includes(row.id) }]),
11674
11701
  onClick: ($event) => unref(toggleSelectItem)(row)
11675
11702
  }, [
11676
- unref(isSelectable) ? (openBlock(), createElementBlock("td", _hoisted_8$7, [
11703
+ unref(isSelectable) ? (openBlock(), createElementBlock("td", _hoisted_9$6, [
11677
11704
  createElementVNode("div", {
11678
11705
  onClick: _cache[3] || (_cache[3] = withModifiers(() => {
11679
11706
  }, ["stop"]))
@@ -11682,7 +11709,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11682
11709
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => selectedItems.value = $event),
11683
11710
  type: "checkbox",
11684
11711
  value: (row == null ? void 0 : row.id) || ""
11685
- }, null, 8, _hoisted_9$6), [
11712
+ }, null, 8, _hoisted_10$6), [
11686
11713
  [vModelCheckbox, selectedItems.value]
11687
11714
  ])
11688
11715
  ])
@@ -11696,12 +11723,12 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11696
11723
  key: 0,
11697
11724
  row,
11698
11725
  field
11699
- }, void 0, true) : (openBlock(), createElementBlock("div", _hoisted_10$6, [
11726
+ }, void 0, true) : (openBlock(), createElementBlock("div", _hoisted_11$6, [
11700
11727
  (openBlock(), createBlock(resolveDynamicComponent(renderFieldForRow(field, row))))
11701
11728
  ]))
11702
11729
  ]);
11703
11730
  }), 128))
11704
- ], 10, _hoisted_7$c);
11731
+ ], 10, _hoisted_8$7);
11705
11732
  }), 128)),
11706
11733
  props2.onLastItemVisible !== void 0 ? (openBlock(), createElementBlock("tr", {
11707
11734
  key: 0,
@@ -11716,7 +11743,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
11716
11743
  };
11717
11744
  }
11718
11745
  });
11719
- const DataTable = /* @__PURE__ */ _export_sfc(_sfc_main$Y, [["__scopeId", "data-v-43f28baa"]]);
11746
+ const DataTable = /* @__PURE__ */ _export_sfc(_sfc_main$Y, [["__scopeId", "data-v-30ec790f"]]);
11720
11747
  function useDraggable(options = {}) {
11721
11748
  const isDragging = ref(false);
11722
11749
  const dragElement = ref(null);
@@ -15129,13 +15156,16 @@ function findBglFieldById(id, _schema) {
15129
15156
  }
15130
15157
  return void 0;
15131
15158
  }
15132
- function arrField(id, label, schema, options) {
15159
+ function arrField(id, label, schemaOrType, options) {
15160
+ const attrs = { delete: true, add: true, ...options };
15161
+ if (typeof schemaOrType === "string") attrs.type = schemaOrType;
15162
+ else attrs.schema = schemaOrType;
15133
15163
  return {
15134
15164
  label,
15135
15165
  id,
15136
15166
  $el: "array",
15137
15167
  vIf: options == null ? void 0 : options.vIf,
15138
- attrs: { schema, delete: true, add: true, ...options }
15168
+ attrs
15139
15169
  };
15140
15170
  }
15141
15171
  const bagelFormUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -15514,18 +15544,18 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
15514
15544
  };
15515
15545
  }
15516
15546
  });
15517
- const _hoisted_1$L = { class: "label mb-05" };
15518
- const _hoisted_2$y = {
15547
+ const _hoisted_1$L = {
15519
15548
  key: 0,
15520
- class: "ps-025 border-start mb-05"
15549
+ class: "label mb-05"
15521
15550
  };
15551
+ const _hoisted_2$y = { class: "ps-025 border-start mb-05" };
15522
15552
  const _hoisted_3$t = {
15523
15553
  key: 0,
15524
15554
  class: "flex-center h-300px"
15525
15555
  };
15526
15556
  const _hoisted_4$j = {
15527
15557
  key: 1,
15528
- class: "flex-center h-300px txt-red"
15558
+ class: "py-1"
15529
15559
  };
15530
15560
  const _hoisted_5$i = {
15531
15561
  key: 0,
@@ -15551,7 +15581,8 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15551
15581
  delete: { type: Boolean, default: true },
15552
15582
  transform: {},
15553
15583
  schema: {},
15554
- modelValue: {}
15584
+ modelValue: {},
15585
+ type: { default: "object" }
15555
15586
  },
15556
15587
  emits: ["update:modelValue"],
15557
15588
  setup(__props, { emit: __emit }) {
@@ -15561,7 +15592,23 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15561
15592
  const internalData = ref(props2.modelValue || []);
15562
15593
  const schemaState = ref("loaded");
15563
15594
  const resolvedSchemaData = ref([]);
15595
+ watch(() => props2.modelValue, (newValue) => {
15596
+ internalData.value = newValue || [];
15597
+ }, { deep: true });
15598
+ const primitiveSchema = computed(() => {
15599
+ if (props2.type === "text") {
15600
+ return [{ id: "value", type: "text", label: "" }];
15601
+ } else if (props2.type === "number") {
15602
+ return [{ id: "value", type: "number", label: "" }];
15603
+ }
15604
+ return [];
15605
+ });
15564
15606
  async function resolveSchema() {
15607
+ if (props2.type !== "object") {
15608
+ resolvedSchemaData.value = primitiveSchema.value;
15609
+ schemaState.value = "loaded";
15610
+ return;
15611
+ }
15565
15612
  if (!props2.schema) {
15566
15613
  resolvedSchemaData.value = [];
15567
15614
  schemaState.value = "loaded";
@@ -15585,9 +15632,7 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15585
15632
  resolvedSchemaData.value = [];
15586
15633
  }
15587
15634
  }
15588
- onMounted(() => {
15589
- resolveSchema();
15590
- });
15635
+ onMounted(resolveSchema);
15591
15636
  function emitValue() {
15592
15637
  emit2("update:modelValue", internalData.value);
15593
15638
  }
@@ -15596,25 +15641,46 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15596
15641
  emitValue();
15597
15642
  }
15598
15643
  function addItem() {
15599
- internalData.value.push({});
15644
+ const defaultValues = {
15645
+ text: "",
15646
+ number: 0,
15647
+ object: {}
15648
+ };
15649
+ internalData.value.push(defaultValues[props2.type]);
15600
15650
  emitValue();
15601
15651
  }
15602
15652
  function toggleMinimized(index2) {
15603
15653
  minimizedItems.value[index2] = !minimizedItems.value[index2];
15604
15654
  }
15605
15655
  function updateItem(index2, value) {
15606
- internalData.value[index2] = value;
15656
+ if (props2.type === "text" || props2.type === "number") {
15657
+ internalData.value[index2] = props2.type === "number" ? Number(value.value) : value.value;
15658
+ } else {
15659
+ internalData.value[index2] = value;
15660
+ }
15607
15661
  emitValue();
15608
15662
  }
15663
+ const isPrimitiveType = computed(() => props2.type === "text" || props2.type === "number");
15664
+ const canRenderItems = computed(
15665
+ () => isPrimitiveType.value || props2.type === "object" && resolvedSchemaData.value.length > 0
15666
+ );
15667
+ const showMinimizeButton = computed(() => resolvedSchemaData.value.length > 4);
15609
15668
  return (_ctx, _cache) => {
15669
+ const _component_Icon = resolveComponent("Icon");
15610
15670
  return openBlock(), createElementBlock("div", {
15611
15671
  class: normalizeClass(props2.class)
15612
15672
  }, [
15613
- createElementVNode("p", _hoisted_1$L, toDisplayString(_ctx.label), 1),
15614
- resolvedSchemaData.value.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_2$y, [
15615
- schemaState.value === "loading" ? (openBlock(), createElementBlock("div", _hoisted_3$t, [
15616
- createVNode(unref(Loading))
15617
- ])) : schemaState.value === "error" ? (openBlock(), createElementBlock("div", _hoisted_4$j, " Error ")) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
15673
+ _ctx.label ? (openBlock(), createElementBlock("p", _hoisted_1$L, toDisplayString(_ctx.label), 1)) : createCommentVNode("", true),
15674
+ createElementVNode("div", _hoisted_2$y, [
15675
+ schemaState.value !== "loaded" ? (openBlock(), createElementBlock("div", _hoisted_3$t, [
15676
+ schemaState.value === "loading" ? (openBlock(), createBlock(unref(Loading), { key: 0 })) : schemaState.value === "error" ? (openBlock(), createBlock(_component_Icon, {
15677
+ key: 1,
15678
+ icon: "error",
15679
+ color: "red"
15680
+ })) : createCommentVNode("", true)
15681
+ ])) : !canRenderItems.value ? (openBlock(), createElementBlock("div", _hoisted_4$j, _cache[0] || (_cache[0] = [
15682
+ createElementVNode("p", { class: "opacity-7" }, " No schema available ", -1)
15683
+ ]))) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
15618
15684
  (openBlock(true), createElementBlock(Fragment, null, renderList(internalData.value, (item, i2) => {
15619
15685
  return openBlock(), createElementBlock("div", {
15620
15686
  key: i2,
@@ -15624,12 +15690,12 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15624
15690
  }, [
15625
15691
  minimizedItems.value[i2] ? (openBlock(), createElementBlock("p", _hoisted_5$i, toDisplayString(_ctx.label) + " " + toDisplayString(i2 + 1), 1)) : (openBlock(), createBlock(unref(_sfc_main$T), {
15626
15692
  key: 1,
15627
- "model-value": item,
15693
+ "model-value": isPrimitiveType.value ? { value: item } : item,
15628
15694
  schema: resolvedSchemaData.value,
15629
15695
  "onUpdate:modelValue": (val) => updateItem(i2, val)
15630
15696
  }, null, 8, ["model-value", "schema", "onUpdate:modelValue"])),
15631
15697
  createElementVNode("div", _hoisted_6$f, [
15632
- resolvedSchemaData.value.length > 4 ? (openBlock(), createBlock(unref(Btn), {
15698
+ showMinimizeButton.value ? (openBlock(), createBlock(unref(Btn), {
15633
15699
  key: 0,
15634
15700
  class: "block rotate-180 txt10 opacity-7 p-025",
15635
15701
  flat: "",
@@ -15662,11 +15728,7 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15662
15728
  _: 1
15663
15729
  })) : createCommentVNode("", true)
15664
15730
  ], 64))
15665
- ])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(internalData.value, (_2, i2) => {
15666
- return openBlock(), createElementBlock("div", { key: i2 }, _cache[0] || (_cache[0] = [
15667
- createElementVNode("p", null, "No schema available", -1)
15668
- ]));
15669
- }), 128))
15731
+ ])
15670
15732
  ], 2);
15671
15733
  };
15672
15734
  }