@bagelink/vue 0.0.1260 → 0.0.1268

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.
Files changed (56) hide show
  1. package/dist/components/AddressSearch.vue.d.ts +6 -0
  2. package/dist/components/AddressSearch.vue.d.ts.map +1 -1
  3. package/dist/components/DataTable/DataTable.vue.d.ts.map +1 -1
  4. package/dist/components/DropDown.vue.d.ts +51 -48
  5. package/dist/components/DropDown.vue.d.ts.map +1 -1
  6. package/dist/components/form/BagelForm.vue.d.ts.map +1 -1
  7. package/dist/components/form/FieldArray.vue.d.ts.map +1 -1
  8. package/dist/components/form/inputs/DateInput.vue.d.ts +4 -1
  9. package/dist/components/form/inputs/DateInput.vue.d.ts.map +1 -1
  10. package/dist/components/form/inputs/PasswordInput.vue.d.ts.map +1 -1
  11. package/dist/components/form/inputs/RadioGroup.vue.d.ts +1 -1
  12. package/dist/components/form/inputs/RichText/composables/useCommands.d.ts.map +1 -1
  13. package/dist/components/form/inputs/RichText/composables/useEditor.d.ts +31 -23
  14. package/dist/components/form/inputs/RichText/composables/useEditor.d.ts.map +1 -1
  15. package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts +2 -1
  16. package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts.map +1 -1
  17. package/dist/components/form/inputs/RichText/config.d.ts +2 -1
  18. package/dist/components/form/inputs/RichText/config.d.ts.map +1 -1
  19. package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
  20. package/dist/components/form/inputs/RichText/utils/commands.d.ts +1 -0
  21. package/dist/components/form/inputs/RichText/utils/commands.d.ts.map +1 -1
  22. package/dist/components/form/inputs/RichText/utils/media.d.ts +5 -3
  23. package/dist/components/form/inputs/RichText/utils/media.d.ts.map +1 -1
  24. package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -1
  25. package/dist/components/form/inputs/SelectInput.vue.d.ts +12 -0
  26. package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
  27. package/dist/components/form/inputs/TelInput.vue.d.ts +9 -3
  28. package/dist/components/form/inputs/TelInput.vue.d.ts.map +1 -1
  29. package/dist/components/form/useBagelFormState.d.ts.map +1 -1
  30. package/dist/editor-7QC0nG_c.js +4 -0
  31. package/dist/editor-CpMNx6Eo.cjs +4 -0
  32. package/dist/index.cjs +1731 -1191
  33. package/dist/index.mjs +1732 -1192
  34. package/dist/style.css +90 -83
  35. package/dist/utils/index.d.ts +1 -0
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/components/DataTable/DataTable.vue +7 -1
  39. package/src/components/Dropdown.vue +5 -2
  40. package/src/components/form/BagelForm.vue +2 -13
  41. package/src/components/form/FieldArray.vue +3 -0
  42. package/src/components/form/inputs/DateInput.vue +341 -162
  43. package/src/components/form/inputs/PasswordInput.vue +5 -1
  44. package/src/components/form/inputs/RichText/components/EditorToolbar.vue +2 -2
  45. package/src/components/form/inputs/RichText/composables/useCommands.ts +53 -97
  46. package/src/components/form/inputs/RichText/composables/useEditor.ts +377 -270
  47. package/src/components/form/inputs/RichText/composables/useEditorKeyboard.ts +124 -58
  48. package/src/components/form/inputs/RichText/config.ts +27 -3
  49. package/src/components/form/inputs/RichText/editor.css +29 -0
  50. package/src/components/form/inputs/RichText/index.vue +129 -55
  51. package/src/components/form/inputs/RichText/richTextTypes.d.ts +35 -49
  52. package/src/components/form/inputs/RichText/utils/commands.ts +181 -0
  53. package/src/components/form/inputs/RichText/utils/media.ts +64 -3
  54. package/src/components/form/inputs/RichText/utils/selection.ts +40 -5
  55. package/src/components/form/useBagelFormState.ts +2 -14
  56. package/src/utils/index.ts +15 -0
package/dist/index.mjs CHANGED
@@ -1,53 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { defineComponent, reactive, provide, openBlock, createElementBlock, renderSlot, ref, computed, inject, watch, normalizeClass, createElementVNode, unref, createVNode, createCommentVNode, toDisplayString, Transition, withCtx, isRef, Fragment, renderList, createBlock, useSlots, resolveDirective, withDirectives, resolveDynamicComponent, mergeProps, withModifiers, withKeys, createTextVNode, normalizeStyle, useCssVars, onMounted, Comment, Text, nextTick, onBeforeUnmount, onUnmounted, resolveComponent, isVNode, h as h$2, getCurrentScope, onScopeDispose, toValue, getCurrentInstance, shallowRef, mergeModels, useModel, normalizeProps, vModelCheckbox, pushScopeId, popScopeId, guardReactiveProps, withScopeId, createApp, vModelText, toRef, createSlots, Teleport, render as render$e, onBeforeUpdate, vShow, vModelRadio, TransitionGroup, vModelDynamic, markRaw } from "vue";
4
+ import { defineComponent, reactive, provide, openBlock, createElementBlock, renderSlot, ref, computed, inject, watch, normalizeClass, createElementVNode, unref, createVNode, createCommentVNode, toDisplayString, Transition, withCtx, isRef, Fragment, renderList, createBlock, useSlots, resolveDirective, withDirectives, resolveDynamicComponent, mergeProps, withModifiers, withKeys, createTextVNode, normalizeStyle, useCssVars, onMounted, Comment, Text, nextTick, onBeforeUnmount, onUnmounted, resolveComponent, isVNode, h as h$2, getCurrentScope, onScopeDispose, toValue, getCurrentInstance, shallowRef, mergeModels, useModel, normalizeProps, vModelCheckbox, pushScopeId, popScopeId, guardReactiveProps, withScopeId, createApp, markRaw, vModelText, toRef, createSlots, Teleport, render as render$e, onBeforeUpdate, vShow, vModelRadio, TransitionGroup, vModelDynamic } from "vue";
5
5
  import { RouterLink } from "vue-router";
6
- const bagelFormUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
7
- __proto__: null,
8
- get arrField() {
9
- return arrField;
10
- },
11
- get bglForm() {
12
- return bglForm;
13
- },
14
- get checkField() {
15
- return checkField;
16
- },
17
- get dateField() {
18
- return dateField;
19
- },
20
- get findBglFieldById() {
21
- return findBglFieldById;
22
- },
23
- get frmRow() {
24
- return frmRow;
25
- },
26
- get getBaseField() {
27
- return getBaseField;
28
- },
29
- get numField() {
30
- return numField;
31
- },
32
- get richText() {
33
- return richText;
34
- },
35
- get selectField() {
36
- return selectField;
37
- },
38
- get slctField() {
39
- return slctField;
40
- },
41
- get telField() {
42
- return telField;
43
- },
44
- get txtField() {
45
- return txtField;
46
- },
47
- get uploadField() {
48
- return uploadField;
49
- }
50
- }, Symbol.toStringTag, { value: "Module" }));
51
6
  const _sfc_main$1m = /* @__PURE__ */ defineComponent({
52
7
  __name: "Accordion",
53
8
  setup(__props) {
@@ -10770,7 +10725,7 @@ function useTableData(options) {
10770
10725
  return currentData.map(transform).sort((a2, z2) => {
10771
10726
  const aValue = a2[computedSortField.value] ?? "";
10772
10727
  const bValue = z2[computedSortField.value] ?? "";
10773
- if (isDate(aValue) && isDate(bValue)) {
10728
+ if (isDate$2(aValue) && isDate$2(bValue)) {
10774
10729
  return sortDirection.value === "ASC" ? new Date(aValue).getTime() - new Date(bValue).getTime() : new Date(bValue).getTime() - new Date(aValue).getTime();
10775
10730
  }
10776
10731
  const numAValue = Number.parseInt(`${aValue}`.replaceAll(NON_DIGIT_REGEX, ""), 10);
@@ -11513,7 +11468,7 @@ const _sfc_main$X = /* @__PURE__ */ defineComponent({
11513
11468
  emits: /* @__PURE__ */ mergeModels(["update:selectedItems", "orderBy", "select", "lastItemVisible"], ["update:loading", "update:itemHeight", "update:selectedItems"]),
11514
11469
  setup(__props, { emit: __emit }) {
11515
11470
  useCssVars((_ctx) => ({
11516
- "3ee4947a": unref(computedItemHeight)
11471
+ "40bb5b9a": unref(computedItemHeight)
11517
11472
  }));
11518
11473
  const props2 = __props;
11519
11474
  const emit2 = __emit;
@@ -11576,7 +11531,12 @@ const _sfc_main$X = /* @__PURE__ */ defineComponent({
11576
11531
  function renderFieldForRow(field, row) {
11577
11532
  const { renderField } = useSchemaField({
11578
11533
  mode: "table",
11579
- getRowData: () => row
11534
+ getRowData: () => {
11535
+ if (field.id) {
11536
+ return { [field.id]: getNestedValue(row, field.id) };
11537
+ }
11538
+ return row;
11539
+ }
11580
11540
  });
11581
11541
  return renderField({ ...field, label: "" }, slots);
11582
11542
  }
@@ -11692,7 +11652,7 @@ const _sfc_main$X = /* @__PURE__ */ defineComponent({
11692
11652
  };
11693
11653
  }
11694
11654
  });
11695
- const DataTable = /* @__PURE__ */ _export_sfc(_sfc_main$X, [["__scopeId", "data-v-3668ec69"]]);
11655
+ const DataTable = /* @__PURE__ */ _export_sfc(_sfc_main$X, [["__scopeId", "data-v-89f6838b"]]);
11696
11656
  function useDraggable(options = {}) {
11697
11657
  const isDragging = ref(false);
11698
11658
  const dragElement = ref(null);
@@ -14802,7 +14762,9 @@ const _sfc_main$V = /* @__PURE__ */ defineComponent({
14802
14762
  round: { type: Boolean },
14803
14763
  placement: {},
14804
14764
  noAutoFocus: { type: Boolean },
14805
- positioningDisabled: { type: Boolean }
14765
+ positioningDisabled: { type: Boolean },
14766
+ autoHide: { type: Boolean },
14767
+ triggers: {}
14806
14768
  }, {
14807
14769
  "shown": {
14808
14770
  type: Boolean,
@@ -14835,6 +14797,8 @@ const _sfc_main$V = /* @__PURE__ */ defineComponent({
14835
14797
  disabled: _ctx.disabled,
14836
14798
  noAutoFocus: _ctx.noAutoFocus,
14837
14799
  placement: _ctx.placement,
14800
+ autoHide: _ctx.autoHide,
14801
+ triggers: _ctx.triggers,
14838
14802
  onHide: _cache[1] || (_cache[1] = ($event) => emit2("hide")),
14839
14803
  onShow: _cache[2] || (_cache[2] = ($event) => emit2("show"))
14840
14804
  }, {
@@ -14861,7 +14825,7 @@ const _sfc_main$V = /* @__PURE__ */ defineComponent({
14861
14825
  ])
14862
14826
  ]),
14863
14827
  _: 3
14864
- }, 8, ["shown", "disabled", "noAutoFocus", "placement"]);
14828
+ }, 8, ["shown", "disabled", "noAutoFocus", "placement", "autoHide", "triggers"]);
14865
14829
  };
14866
14830
  }
14867
14831
  });
@@ -14914,6 +14878,385 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
14914
14878
  }
14915
14879
  });
14916
14880
  const Flag = /* @__PURE__ */ _export_sfc(_sfc_main$T, [["__scopeId", "data-v-f99f1900"]]);
14881
+ function getBaseField(id, labelOrRest = {}, rest = {}) {
14882
+ if (typeof labelOrRest === "object") return { id, ...labelOrRest };
14883
+ return { id, label: labelOrRest, ...rest };
14884
+ }
14885
+ function richText(id, label, options) {
14886
+ return {
14887
+ $el: "richtext",
14888
+ class: options == null ? void 0 : options.class,
14889
+ required: options == null ? void 0 : options.required,
14890
+ id,
14891
+ label,
14892
+ vIf: options == null ? void 0 : options.vIf,
14893
+ placeholder: options == null ? void 0 : options.placeholder,
14894
+ attrs: {}
14895
+ };
14896
+ }
14897
+ function txtField(id, label, options) {
14898
+ return {
14899
+ $el: "text",
14900
+ class: options == null ? void 0 : options.class,
14901
+ required: options == null ? void 0 : options.required,
14902
+ id,
14903
+ label,
14904
+ vIf: options == null ? void 0 : options.vIf,
14905
+ disabled: options == null ? void 0 : options.disabled,
14906
+ placeholder: options == null ? void 0 : options.placeholder,
14907
+ defaultValue: options == null ? void 0 : options.defaultValue,
14908
+ attrs: {
14909
+ type: options == null ? void 0 : options.type,
14910
+ pattern: options == null ? void 0 : options.pattern,
14911
+ multiline: options == null ? void 0 : options.multiline
14912
+ }
14913
+ };
14914
+ }
14915
+ function selectField(id, label, options, config) {
14916
+ return {
14917
+ $el: "select",
14918
+ id,
14919
+ options,
14920
+ class: config == null ? void 0 : config.class,
14921
+ placeholder: config == null ? void 0 : config.placeholder,
14922
+ required: config == null ? void 0 : config.required,
14923
+ label,
14924
+ defaultValue: config == null ? void 0 : config.defaultValue,
14925
+ vIf: config == null ? void 0 : config.vIf,
14926
+ attrs: {
14927
+ disabled: config == null ? void 0 : config.disabled,
14928
+ searchable: config == null ? void 0 : config.searchable,
14929
+ multiselect: config == null ? void 0 : config.multiselect,
14930
+ onSearch: config == null ? void 0 : config.onSearch,
14931
+ clearable: config == null ? void 0 : config.clearable
14932
+ }
14933
+ };
14934
+ }
14935
+ const slctField = selectField;
14936
+ function checkField(id, label, options) {
14937
+ return {
14938
+ $el: "check",
14939
+ class: options == null ? void 0 : options.class,
14940
+ required: options == null ? void 0 : options.required,
14941
+ id,
14942
+ label
14943
+ };
14944
+ }
14945
+ function dateField(id, label, options) {
14946
+ return {
14947
+ $el: "date",
14948
+ class: options == null ? void 0 : options.class,
14949
+ required: options == null ? void 0 : options.required,
14950
+ id,
14951
+ disabled: options == null ? void 0 : options.disabled,
14952
+ label,
14953
+ defaultValue: options == null ? void 0 : options.defaultValue,
14954
+ vIf: options == null ? void 0 : options.vIf,
14955
+ attrs: {
14956
+ disabled: options == null ? void 0 : options.disabled
14957
+ }
14958
+ };
14959
+ }
14960
+ function numField$1(id, label, options) {
14961
+ return {
14962
+ $el: "number",
14963
+ class: options == null ? void 0 : options.class,
14964
+ required: options == null ? void 0 : options.required,
14965
+ defaultValue: options == null ? void 0 : options.defaultValue,
14966
+ id,
14967
+ label,
14968
+ disabled: options == null ? void 0 : options.disabled,
14969
+ placeholder: options == null ? void 0 : options.placeholder,
14970
+ helptext: options == null ? void 0 : options.helptext,
14971
+ vIf: options == null ? void 0 : options.vIf,
14972
+ attrs: {
14973
+ step: options == null ? void 0 : options.step,
14974
+ min: options == null ? void 0 : options.min,
14975
+ max: options == null ? void 0 : options.max,
14976
+ layout: options == null ? void 0 : options.layout,
14977
+ padZero: options == null ? void 0 : options.padZero,
14978
+ center: options == null ? void 0 : options.center
14979
+ }
14980
+ };
14981
+ }
14982
+ function frmRow$1(...children2) {
14983
+ return {
14984
+ $el: "div",
14985
+ class: "flex gap-1 m_block align-items-end",
14986
+ children: children2
14987
+ };
14988
+ }
14989
+ function uploadField(id, label, options) {
14990
+ return {
14991
+ $el: "upload",
14992
+ id,
14993
+ label,
14994
+ vIf: options == null ? void 0 : options.vIf,
14995
+ attrs: {
14996
+ ...options
14997
+ }
14998
+ };
14999
+ }
15000
+ function bglForm(idOrField, ...schema) {
15001
+ if (typeof idOrField === "string") {
15002
+ return {
15003
+ $el: "bagelform",
15004
+ id: idOrField,
15005
+ attrs: {
15006
+ schema: [idOrField, ...schema]
15007
+ }
15008
+ };
15009
+ }
15010
+ return {
15011
+ $el: "bagelform",
15012
+ attrs: {
15013
+ schema: [idOrField, ...schema]
15014
+ }
15015
+ };
15016
+ }
15017
+ function telField(id, label, options) {
15018
+ return {
15019
+ $el: markRaw(TelInput),
15020
+ id,
15021
+ label,
15022
+ vIf: options == null ? void 0 : options.vIf,
15023
+ attrs: options
15024
+ };
15025
+ }
15026
+ function findBglFieldById(id, _schema) {
15027
+ for (const field of _schema) {
15028
+ if (field.id === id) return field;
15029
+ if (field.children && Number(field.children.length) > 0) {
15030
+ const fieldChildren = field.children.filter((c2) => typeof c2 === "object" && "$el" in c2);
15031
+ const child = findBglFieldById(id, fieldChildren);
15032
+ if (child) return child;
15033
+ }
15034
+ }
15035
+ return void 0;
15036
+ }
15037
+ function arrField(id, label, schema, options) {
15038
+ return {
15039
+ label,
15040
+ id,
15041
+ $el: "array",
15042
+ vIf: options == null ? void 0 : options.vIf,
15043
+ attrs: { schema, delete: true, add: true, ...options }
15044
+ };
15045
+ }
15046
+ const bagelFormUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
15047
+ __proto__: null,
15048
+ arrField,
15049
+ bglForm,
15050
+ checkField,
15051
+ dateField,
15052
+ findBglFieldById,
15053
+ frmRow: frmRow$1,
15054
+ getBaseField,
15055
+ numField: numField$1,
15056
+ richText,
15057
+ selectField,
15058
+ slctField,
15059
+ telField,
15060
+ txtField,
15061
+ uploadField
15062
+ }, Symbol.toStringTag, { value: "Module" }));
15063
+ const state$1 = reactive({
15064
+ defaultLang: "",
15065
+ availableLangs: [],
15066
+ lang: "en"
15067
+ });
15068
+ function $tdb(langEl) {
15069
+ if (!langEl) {
15070
+ console.warn("No language element provided for $tdb function");
15071
+ return "";
15072
+ }
15073
+ return langEl[state$1.lang] || langEl[state$1.defaultLang] || "";
15074
+ }
15075
+ function useLang() {
15076
+ const lang = computed({
15077
+ get: () => state$1.lang,
15078
+ set: (val) => state$1.lang = val
15079
+ });
15080
+ const availableLangs = computed({
15081
+ get: () => state$1.availableLangs,
15082
+ set: (val) => state$1.availableLangs = val
15083
+ });
15084
+ const defaultLang = computed({
15085
+ get: () => state$1.defaultLang,
15086
+ set: (val) => state$1.defaultLang = val
15087
+ });
15088
+ return {
15089
+ lang,
15090
+ $tdb,
15091
+ availableLangs,
15092
+ defaultLang
15093
+ };
15094
+ }
15095
+ function formatString(str, format2) {
15096
+ if (format2 === "titleCase") {
15097
+ return str.split("_").map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase()).join(" ");
15098
+ }
15099
+ if (format2 === "pascal") {
15100
+ return str.split("_").map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase()).join("");
15101
+ }
15102
+ if (format2 === "camel") {
15103
+ return str.split("_").map((word, index2) => index2 === 0 ? word : word[0].toUpperCase() + word.slice(1)).join("");
15104
+ }
15105
+ if (format2 === "snake") {
15106
+ return [...str].map((letter) => {
15107
+ if (letter === letter.toUpperCase()) {
15108
+ return `_${letter.toLowerCase()}`;
15109
+ }
15110
+ return letter;
15111
+ }).join("");
15112
+ }
15113
+ return str;
15114
+ }
15115
+ const debouncers = /* @__PURE__ */ new Map();
15116
+ function debounce(fn2, wait = 500) {
15117
+ clearTimeout(debouncers.get(fn2));
15118
+ const timeout = setTimeout(() => {
15119
+ fn2();
15120
+ debouncers.delete(fn2);
15121
+ }, wait);
15122
+ debouncers.set(fn2, timeout);
15123
+ }
15124
+ function slugify(str) {
15125
+ return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").split(/[\s-]+/).join("-");
15126
+ }
15127
+ function keyToLabel(key) {
15128
+ if (key === void 0) return key;
15129
+ return key.split("_").map((k2) => k2.charAt(0).toUpperCase() + k2.slice(1)).join(" ") || key;
15130
+ }
15131
+ async function copyText(text, cb) {
15132
+ await navigator.clipboard.writeText(text);
15133
+ if (cb) cb("Copied to clipboard");
15134
+ }
15135
+ function initials(...strArr) {
15136
+ strArr = strArr.flatMap((str) => str.split(/\s/));
15137
+ return strArr.map((str) => str.charAt(0)).join("");
15138
+ }
15139
+ function useEscape(event, closeModel) {
15140
+ if (event.key === "Escape") {
15141
+ closeModel();
15142
+ }
15143
+ }
15144
+ function classify(fieldVal, row, ...classes) {
15145
+ return classes.map((cls) => {
15146
+ if (typeof cls === "function") return cls(fieldVal, row);
15147
+ return cls;
15148
+ }).join(" ");
15149
+ }
15150
+ function bindAttrs(attrs, fieldVal, row) {
15151
+ if (!attrs) return {};
15152
+ const exclude = ["class"];
15153
+ const arr = Object.entries(attrs).filter(([key]) => !exclude.includes(key)).map(([key, value]) => [
15154
+ key,
15155
+ typeof value === "function" ? value(fieldVal, row) : value
15156
+ ]);
15157
+ const resolvedAttrs = Object.fromEntries(arr);
15158
+ return resolvedAttrs;
15159
+ }
15160
+ function iffer(field, itemData) {
15161
+ var _a2;
15162
+ if (field["v-if"] === void 0) return true;
15163
+ if (typeof field["v-if"] === "boolean") return field["v-if"];
15164
+ if (typeof field["v-if"] === "string") return true;
15165
+ if (typeof field["v-if"] === "function")
15166
+ return (_a2 = field["v-if"]) == null ? void 0 : _a2.call(field, itemData == null ? void 0 : itemData[field.id], itemData);
15167
+ return true;
15168
+ }
15169
+ function denullify(itemData, fieldID) {
15170
+ if (!fieldID) return;
15171
+ return itemData ? itemData[fieldID] : void 0;
15172
+ }
15173
+ const isDate$2 = (dateToTest) => !Number.isNaN(Date.parse(dateToTest));
15174
+ function getFallbackSchema(data2, showFields) {
15175
+ const keys4 = Array.from(new Set((data2 ?? []).flatMap(Object.keys)));
15176
+ const schema = keys4.map((id) => ({
15177
+ id,
15178
+ label: keyToLabel(id),
15179
+ transform: (val) => {
15180
+ const dateFields = ["created_at", "updated_at"];
15181
+ if (dateFields.includes(id)) return val ? new Date(val).toLocaleString() : val;
15182
+ return val;
15183
+ }
15184
+ }));
15185
+ return showFields ? schema.filter((f2) => showFields.includes(f2.id) || !f2.id) : schema;
15186
+ }
15187
+ function sleep(ms = 100) {
15188
+ return new Promise((resolve) => setTimeout(resolve, ms));
15189
+ }
15190
+ function appendScript(src, options) {
15191
+ return new Promise((resolve, reject3) => {
15192
+ if (options == null ? void 0 : options.id) {
15193
+ if (document.getElementById(options.id)) {
15194
+ resolve();
15195
+ return;
15196
+ }
15197
+ } else if (document.querySelector(`script[src="${src}"]`)) {
15198
+ resolve();
15199
+ return;
15200
+ }
15201
+ const script2 = document.createElement("script");
15202
+ script2.src = src;
15203
+ if (options == null ? void 0 : options.id) {
15204
+ script2.id = options.id;
15205
+ }
15206
+ script2.onload = () => {
15207
+ resolve();
15208
+ };
15209
+ script2.onerror = reject3;
15210
+ document.head.append(script2);
15211
+ });
15212
+ }
15213
+ function appendStyle(src) {
15214
+ return new Promise((resolve, reject3) => {
15215
+ if (document.querySelector(`link[href="${src}"]`)) {
15216
+ resolve();
15217
+ return;
15218
+ }
15219
+ const link = document.createElement("link");
15220
+ link.href = src;
15221
+ link.rel = "stylesheet";
15222
+ link.onload = () => {
15223
+ resolve();
15224
+ };
15225
+ link.onerror = reject3;
15226
+ document.head.append(link);
15227
+ });
15228
+ }
15229
+ function normalizeURL(url) {
15230
+ if (url.startsWith("https://")) return url;
15231
+ url = url.replace(/http:\/\//, "");
15232
+ return `https://${url}`;
15233
+ }
15234
+ function normalizeDimension(value, defaultMetric = "px") {
15235
+ if (typeof value === "number") return `${value}${defaultMetric}`;
15236
+ return value;
15237
+ }
15238
+ const fileBaseUrl = "https://files.bagel.design".replace(/\/$/, "");
15239
+ const bagelBaseUrl = void 0;
15240
+ function pathKeyToURL(pathKey) {
15241
+ const urlRE = /^https?:\/\/|^\/\//;
15242
+ if (!pathKey || urlRE.test(pathKey)) return pathKey;
15243
+ if (pathKey.startsWith("static/")) {
15244
+ return `${bagelBaseUrl}/${pathKey}`;
15245
+ }
15246
+ return `${fileBaseUrl}/${pathKey}`;
15247
+ }
15248
+ function getNestedValue(obj, path, defaultValue = void 0) {
15249
+ if (!path) return obj;
15250
+ const keys4 = path.split(/[.[]/);
15251
+ let current = obj;
15252
+ for (const key of keys4) {
15253
+ if (!current || typeof current !== "object" || !(key in current)) {
15254
+ return defaultValue;
15255
+ }
15256
+ current = current[key];
15257
+ }
15258
+ return current ?? defaultValue;
15259
+ }
14917
15260
  const _sfc_main$S = /* @__PURE__ */ defineComponent({
14918
15261
  __name: "BagelForm",
14919
15262
  props: {
@@ -14963,15 +15306,6 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
14963
15306
  return false;
14964
15307
  }
14965
15308
  });
14966
- function getNestedValue(obj, path) {
14967
- const keys4 = path.split(".");
14968
- let current = obj;
14969
- for (const key of keys4) {
14970
- if (current === void 0 || current === null) return void 0;
14971
- current = current[key];
14972
- }
14973
- return current;
14974
- }
14975
15309
  function updateFormData(fieldId, value) {
14976
15310
  const keys4 = fieldId.split(".");
14977
15311
  const newData = safeClone2(formData.value);
@@ -15011,7 +15345,7 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
15011
15345
  return {
15012
15346
  ...formData.value,
15013
15347
  // Add a special getter to handle nested paths
15014
- get: (path) => getNestedValue(formData.value, path)
15348
+ get: (path) => getNestedValue(formData.value, path, "")
15015
15349
  };
15016
15350
  },
15017
15351
  onUpdate: (field, value) => {
@@ -15439,33 +15773,31 @@ const _hoisted_3$o = {
15439
15773
  key: 0,
15440
15774
  class: "required"
15441
15775
  };
15442
- const _hoisted_4$g = { class: "date-picker-container" };
15443
- const _hoisted_5$f = { class: "flex gap-075 p-05 m_flex-wrap calendar-container justify-content-center h-100p" };
15444
- const _hoisted_6$c = { class: "calendar-section m_border-none pe-05 m_p-0" };
15445
- const _hoisted_7$9 = { class: "flex space-between pb-1" };
15446
- const _hoisted_8$6 = { class: "flex gap-05" };
15447
- const _hoisted_9$5 = { class: "month-year" };
15448
- const _hoisted_10$5 = {
15776
+ const _hoisted_4$g = { class: "calendar-section m_border-none pe-05 m_p-0" };
15777
+ const _hoisted_5$f = { class: "flex space-between pb-1" };
15778
+ const _hoisted_6$c = { class: "flex gap-05" };
15779
+ const _hoisted_7$9 = { class: "month-year" };
15780
+ const _hoisted_8$6 = {
15449
15781
  key: 0,
15450
15782
  class: "calendar-grid grid gap-025"
15451
15783
  };
15452
- const _hoisted_11$5 = ["disabled", "onClick"];
15453
- const _hoisted_12$5 = {
15784
+ const _hoisted_9$5 = ["disabled", "onClick"];
15785
+ const _hoisted_10$5 = {
15454
15786
  key: 1,
15455
15787
  class: "month-grid grid gap-05 p-05"
15456
15788
  };
15457
- const _hoisted_13$4 = ["disabled", "onClick"];
15458
- const _hoisted_14$4 = {
15789
+ const _hoisted_11$5 = ["disabled", "onClick"];
15790
+ const _hoisted_12$5 = {
15459
15791
  key: 2,
15460
15792
  class: "year-grid grid gap-05 p-0"
15461
15793
  };
15462
- const _hoisted_15$4 = ["disabled", "onClick"];
15463
- const _hoisted_16$4 = {
15794
+ const _hoisted_13$4 = ["disabled", "onClick"];
15795
+ const _hoisted_14$4 = {
15464
15796
  key: 0,
15465
15797
  class: "time-picker border-start flex column gap-1 w-120px"
15466
15798
  };
15467
- const _hoisted_17$4 = { class: "flex gap-025" };
15468
- const _hoisted_18$2 = { class: "txt-center opacity-6 txt14" };
15799
+ const _hoisted_15$4 = { class: "flex gap-025" };
15800
+ const _hoisted_16$4 = { class: "txt-center opacity-6 txt14" };
15469
15801
  const _sfc_main$M = /* @__PURE__ */ defineComponent({
15470
15802
  __name: "DateInput",
15471
15803
  props: {
@@ -15479,7 +15811,7 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
15479
15811
  max: {},
15480
15812
  timezone: { default: "UTC" },
15481
15813
  mode: { default: "day" },
15482
- firstDayOfWeek: { default: WEEK_START_DAY.MONDAY },
15814
+ firstDayOfWeek: { default: WEEK_START_DAY.SUNDAY },
15483
15815
  locale: { default: "" },
15484
15816
  center: { type: Boolean }
15485
15817
  },
@@ -15487,235 +15819,392 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
15487
15819
  setup(__props, { emit: __emit }) {
15488
15820
  const props2 = __props;
15489
15821
  const emit2 = __emit;
15490
- let isOpen = ref(false);
15491
- let currentMonth = ref(/* @__PURE__ */ new Date());
15492
- let currentView = ref("days");
15822
+ const isOpen = ref(false);
15823
+ const currentMonth = ref(/* @__PURE__ */ new Date());
15824
+ const currentView = ref("days");
15493
15825
  const time = new Time(props2.firstDayOfWeek, props2.locale);
15494
- function formatDisplayDate(date2) {
15495
- if (!date2) return "";
15496
- const dateObj = typeof date2 === "string" ? new Date(date2) : date2;
15497
- if (props2.enableTime) {
15498
- return dateObj.toLocaleString(props2.locale || void 0, {
15826
+ function useFormatting() {
15827
+ const formatDisplayDate = (date2) => {
15828
+ if (!date2) return "";
15829
+ const dateObj = typeof date2 === "string" ? new Date(date2) : date2;
15830
+ const options = {
15499
15831
  year: "numeric",
15500
15832
  month: "short",
15501
15833
  day: "numeric",
15502
- hour: "2-digit",
15503
- minute: "2-digit",
15834
+ ...props2.enableTime && {
15835
+ hour: "2-digit",
15836
+ minute: "2-digit"
15837
+ },
15504
15838
  timeZone: props2.timezone
15505
- });
15506
- }
15507
- return dateObj.toLocaleString(props2.locale || void 0, {
15508
- year: "numeric",
15509
- month: "short",
15510
- day: "numeric",
15511
- timeZone: props2.timezone
15512
- });
15839
+ };
15840
+ return dateObj.toLocaleString(props2.locale || void 0, options);
15841
+ };
15842
+ const formatDate = (date2) => {
15843
+ if (!date2) return "";
15844
+ const dateObj = typeof date2 === "string" ? new Date(date2) : date2;
15845
+ return props2.enableTime ? dateObj.toISOString().slice(0, 16) : dateObj.toISOString().split("T")[0];
15846
+ };
15847
+ const parseUserInput = (input) => {
15848
+ const date2 = new Date(input);
15849
+ if (!Number.isNaN(date2.getTime())) {
15850
+ return date2;
15851
+ }
15852
+ const parts = input.split(/[/.-]/);
15853
+ if (parts.length === 3) {
15854
+ const [day, month, year] = parts.map((p2) => Number.parseInt(p2, 10));
15855
+ if (!Number.isNaN(day) && !Number.isNaN(month) && !Number.isNaN(year)) {
15856
+ const date22 = new Date(year, month - 1, day);
15857
+ if (date22.getFullYear() === year && date22.getMonth() === month - 1 && date22.getDate() === day) {
15858
+ return date22;
15859
+ }
15860
+ }
15861
+ }
15862
+ return null;
15863
+ };
15864
+ return {
15865
+ formatDisplayDate,
15866
+ formatDate,
15867
+ parseUserInput
15868
+ };
15513
15869
  }
15514
- function formatDate(date2) {
15515
- if (!date2) return "";
15516
- const dateObj = typeof date2 === "string" ? new Date(date2) : date2;
15517
- return props2.enableTime ? dateObj.toISOString().slice(0, 16) : dateObj.toISOString().split("T")[0];
15870
+ function useDateValidation() {
15871
+ const isDateDisabled2 = (date2) => {
15872
+ if (!date2) return true;
15873
+ const minDate = props2.min ? new Date(props2.min) : null;
15874
+ const maxDate = props2.max ? new Date(props2.max) : null;
15875
+ if (minDate && date2 < minDate) return true;
15876
+ if (maxDate && date2 > maxDate) return true;
15877
+ return false;
15878
+ };
15879
+ const isYearDisabled2 = (year) => {
15880
+ const minDate = props2.min ? new Date(props2.min) : null;
15881
+ const maxDate = props2.max ? new Date(props2.max) : null;
15882
+ if (minDate && year < minDate.getFullYear()) return true;
15883
+ if (maxDate && year > maxDate.getFullYear()) return true;
15884
+ return false;
15885
+ };
15886
+ return {
15887
+ isDateDisabled: isDateDisabled2,
15888
+ isYearDisabled: isYearDisabled2
15889
+ };
15518
15890
  }
15519
- const formattedDisplayValue = computed(() => formatDisplayDate(props2.modelValue));
15520
- const formattedMin = computed(() => formatDate(props2.min));
15521
- const formattedMax = computed(() => formatDate(props2.max));
15522
- const selectedDate = computed(() => {
15523
- if (!props2.modelValue) return null;
15524
- return typeof props2.modelValue === "string" ? new Date(props2.modelValue) : props2.modelValue;
15525
- });
15526
- const currentMonthDays = computed(() => {
15527
- const year = currentMonth.value.getFullYear();
15528
- const month = currentMonth.value.getMonth();
15529
- return time.getCalendarMonthSplitInWeeks(year, month).flat();
15530
- });
15531
- const currentMonthValue = computed(() => ({
15532
- month: currentMonth.value.getMonth(),
15533
- year: currentMonth.value.getFullYear(),
15534
- formatted: {
15535
- month: time.getLocalizedNameOfMonth(currentMonth.value, "long"),
15536
- year: time.getLocalizedDateString(currentMonth.value).split("/").pop()
15537
- // Get just the year part
15538
- }
15539
- }));
15540
- const months = computed(() => Array.from({ length: 12 }, (_2, i2) => {
15541
- const date2 = new Date(currentMonthValue.value.year, i2, 1);
15891
+ function useDateState() {
15892
+ const { formatDisplayDate, formatDate } = useFormatting();
15893
+ const formattedDisplayValue2 = computed(() => formatDisplayDate(props2.modelValue));
15894
+ const formattedMin2 = computed(() => formatDate(props2.min));
15895
+ const formattedMax2 = computed(() => formatDate(props2.max));
15896
+ const selectedDate2 = computed(() => {
15897
+ if (!props2.modelValue) return null;
15898
+ return typeof props2.modelValue === "string" ? new Date(props2.modelValue) : props2.modelValue;
15899
+ });
15542
15900
  return {
15543
- name: time.getLocalizedNameOfMonth(date2, "short"),
15544
- value: i2,
15545
- disabled: isDateDisabled(date2)
15901
+ formattedDisplayValue: formattedDisplayValue2,
15902
+ formattedMin: formattedMin2,
15903
+ formattedMax: formattedMax2,
15904
+ selectedDate: selectedDate2
15546
15905
  };
15547
- }));
15548
- const years = computed(() => {
15549
- const startYear = currentMonthValue.value.year - 10;
15550
- return Array.from({ length: 21 }, (_2, i2) => ({
15551
- value: startYear + i2,
15552
- disabled: isYearDisabled(startYear + i2)
15906
+ }
15907
+ const { isDateDisabled, isYearDisabled } = useDateValidation();
15908
+ const { formattedDisplayValue, formattedMin, formattedMax, selectedDate } = useDateState();
15909
+ function useCalendarView() {
15910
+ const currentMonthDays2 = computed(() => {
15911
+ const year = currentMonth.value.getFullYear();
15912
+ const month = currentMonth.value.getMonth();
15913
+ return time.getCalendarMonthSplitInWeeks(year, month).flat();
15914
+ });
15915
+ const currentMonthValue2 = computed(() => ({
15916
+ month: currentMonth.value.getMonth(),
15917
+ year: currentMonth.value.getFullYear(),
15918
+ formatted: {
15919
+ month: time.getLocalizedNameOfMonth(currentMonth.value, "long"),
15920
+ year: time.getLocalizedDateString(currentMonth.value).split("/").pop()
15921
+ }
15553
15922
  }));
15554
- });
15555
- const weekDays = computed(() => {
15556
- const weekStart = /* @__PURE__ */ new Date();
15557
- weekStart.setDate(weekStart.getDate() - weekStart.getDay() + (props2.firstDayOfWeek === WEEK_START_DAY.MONDAY ? 1 : 0));
15558
- return Array.from({ length: 7 }, (_2, i2) => {
15559
- const day = new Date(weekStart);
15560
- day.setDate(weekStart.getDate() + i2);
15561
- return time.getLocalizedNameOfWeekday(day, "short");
15923
+ const months2 = computed(() => Array.from({ length: 12 }, (_2, i2) => {
15924
+ const date2 = new Date(currentMonthValue2.value.year, i2, 1);
15925
+ return {
15926
+ name: time.getLocalizedNameOfMonth(date2, "short"),
15927
+ value: i2,
15928
+ disabled: isDateDisabled(date2)
15929
+ };
15930
+ }));
15931
+ const years2 = computed(() => {
15932
+ const startYear = currentMonthValue2.value.year - 10;
15933
+ return Array.from({ length: 21 }, (_2, i2) => ({
15934
+ value: startYear + i2,
15935
+ disabled: isYearDisabled(startYear + i2)
15936
+ }));
15562
15937
  });
15563
- });
15564
- function isDateDisabled(date2) {
15565
- if (!date2) return true;
15566
- const minDate = props2.min ? new Date(props2.min) : null;
15567
- const maxDate = props2.max ? new Date(props2.max) : null;
15568
- if (minDate && date2 < minDate) return true;
15569
- if (maxDate && date2 > maxDate) return true;
15570
- return false;
15571
- }
15572
- function isYearDisabled(year) {
15573
- const minDate = props2.min ? new Date(props2.min) : null;
15574
- const maxDate = props2.max ? new Date(props2.max) : null;
15575
- if (minDate && year < minDate.getFullYear()) return true;
15576
- if (maxDate && year > maxDate.getFullYear()) return true;
15577
- return false;
15578
- }
15579
- function selectMonth(monthIndex) {
15580
- currentMonth.value = new Date(currentMonth.value.getFullYear(), monthIndex, 1);
15581
- currentView.value = "days";
15582
- }
15583
- function selectYear(year) {
15584
- currentMonth.value = new Date(year, currentMonth.value.getMonth(), 1);
15585
- currentView.value = "months";
15586
- }
15587
- function previousMonth() {
15588
- currentMonth.value = new Date(currentMonth.value.getFullYear(), currentMonth.value.getMonth() - 1, 1);
15938
+ const weekDays2 = computed(() => {
15939
+ const weekStart = /* @__PURE__ */ new Date();
15940
+ weekStart.setDate(weekStart.getDate() - weekStart.getDay() + (props2.firstDayOfWeek === WEEK_START_DAY.MONDAY ? 1 : 0));
15941
+ return Array.from({ length: 7 }, (_2, i2) => {
15942
+ const day = new Date(weekStart);
15943
+ day.setDate(weekStart.getDate() + i2);
15944
+ return time.getLocalizedNameOfWeekday(day, "short");
15945
+ });
15946
+ });
15947
+ const isSelected2 = (date2) => {
15948
+ if (!date2 || !selectedDate.value) return false;
15949
+ return date2.getFullYear() === selectedDate.value.getFullYear() && date2.getMonth() === selectedDate.value.getMonth() && date2.getDate() === selectedDate.value.getDate();
15950
+ };
15951
+ const isToday2 = (date2) => {
15952
+ if (!date2) return false;
15953
+ return time.dateIsToday(date2);
15954
+ };
15955
+ const isNotInMonth2 = (date2) => {
15956
+ return time.isTrailingOrLeadingDate(date2, currentMonth.value.getMonth());
15957
+ };
15958
+ return {
15959
+ currentMonthDays: currentMonthDays2,
15960
+ currentMonthValue: currentMonthValue2,
15961
+ months: months2,
15962
+ years: years2,
15963
+ weekDays: weekDays2,
15964
+ isSelected: isSelected2,
15965
+ isToday: isToday2,
15966
+ isNotInMonth: isNotInMonth2
15967
+ };
15589
15968
  }
15590
- function nextMonth() {
15591
- currentMonth.value = new Date(currentMonth.value.getFullYear(), currentMonth.value.getMonth() + 1, 1);
15969
+ function useNavigation() {
15970
+ const selectMonth2 = (monthIndex) => {
15971
+ currentMonth.value = new Date(currentMonth.value.getFullYear(), monthIndex, 1);
15972
+ currentView.value = "days";
15973
+ };
15974
+ const selectYear2 = (year) => {
15975
+ currentMonth.value = new Date(year, currentMonth.value.getMonth(), 1);
15976
+ currentView.value = "months";
15977
+ };
15978
+ const previousMonth2 = () => {
15979
+ currentMonth.value = new Date(currentMonth.value.getFullYear(), currentMonth.value.getMonth() - 1, 1);
15980
+ };
15981
+ const nextMonth2 = () => {
15982
+ currentMonth.value = new Date(currentMonth.value.getFullYear(), currentMonth.value.getMonth() + 1, 1);
15983
+ };
15984
+ const previousYear2 = () => {
15985
+ const offset2 = currentView.value === "months" ? 1 : 21;
15986
+ currentMonth.value = new Date(currentMonth.value.getFullYear() - offset2, currentMonth.value.getMonth(), 1);
15987
+ };
15988
+ const nextYear2 = () => {
15989
+ const offset2 = currentView.value === "months" ? 1 : 21;
15990
+ currentMonth.value = new Date(currentMonth.value.getFullYear() + offset2, currentMonth.value.getMonth(), 1);
15991
+ };
15992
+ return {
15993
+ selectMonth: selectMonth2,
15994
+ selectYear: selectYear2,
15995
+ previousMonth: previousMonth2,
15996
+ nextMonth: nextMonth2,
15997
+ previousYear: previousYear2,
15998
+ nextYear: nextYear2
15999
+ };
15592
16000
  }
15593
- function previousYear() {
15594
- const offset2 = currentView.value === "months" ? 1 : 21;
15595
- currentMonth.value = new Date(currentMonth.value.getFullYear() - offset2, currentMonth.value.getMonth(), 1);
16001
+ function useTimeHandling() {
16002
+ const hours2 = computed(() => {
16003
+ var _a2;
16004
+ return ((_a2 = selectedDate.value) == null ? void 0 : _a2.getHours()) ?? 0;
16005
+ });
16006
+ const minutes2 = computed(() => {
16007
+ var _a2;
16008
+ return ((_a2 = selectedDate.value) == null ? void 0 : _a2.getMinutes()) ?? 0;
16009
+ });
16010
+ const handleHourInput2 = (value) => {
16011
+ if (!selectedDate.value) return;
16012
+ const newDate = new Date(selectedDate.value);
16013
+ newDate.setHours(value);
16014
+ emit2("update:modelValue", newDate.toISOString());
16015
+ };
16016
+ const handleMinuteInput2 = (value) => {
16017
+ if (!selectedDate.value) return;
16018
+ const newDate = new Date(selectedDate.value);
16019
+ newDate.setMinutes(value);
16020
+ emit2("update:modelValue", newDate.toISOString());
16021
+ };
16022
+ const timezoneDisplay2 = computed(() => {
16023
+ if (!props2.enableTime) return "";
16024
+ try {
16025
+ return (/* @__PURE__ */ new Date()).toLocaleString("en-US", {
16026
+ timeZoneName: "short",
16027
+ timeZone: props2.timezone
16028
+ }).split(" ").pop();
16029
+ } catch {
16030
+ return "UTC";
16031
+ }
16032
+ });
16033
+ return {
16034
+ hours: hours2,
16035
+ minutes: minutes2,
16036
+ handleHourInput: handleHourInput2,
16037
+ handleMinuteInput: handleMinuteInput2,
16038
+ timezoneDisplay: timezoneDisplay2
16039
+ };
15596
16040
  }
15597
- function nextYear() {
15598
- const offset2 = currentView.value === "months" ? 1 : 21;
15599
- currentMonth.value = new Date(currentMonth.value.getFullYear() + offset2, currentMonth.value.getMonth(), 1);
16041
+ function useInputHandling() {
16042
+ const { parseUserInput } = useFormatting();
16043
+ const inputValue2 = ref("");
16044
+ const handleInput2 = (event) => {
16045
+ const input = event.target;
16046
+ inputValue2.value = input.value;
16047
+ const date2 = parseUserInput(input.value);
16048
+ if (date2) {
16049
+ if (props2.enableTime) {
16050
+ emit2("update:modelValue", date2.toISOString());
16051
+ } else {
16052
+ const utcDate = new Date(Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate()));
16053
+ emit2("update:modelValue", utcDate.toISOString().split("T")[0]);
16054
+ }
16055
+ }
16056
+ };
16057
+ const handleFocus2 = (e) => {
16058
+ e.preventDefault();
16059
+ e.stopPropagation();
16060
+ isOpen.value = true;
16061
+ };
16062
+ const handleClick2 = (e) => {
16063
+ e.preventDefault();
16064
+ e.stopPropagation();
16065
+ };
16066
+ const handleKeydown2 = (event) => {
16067
+ if (event.key === "Escape") {
16068
+ isOpen.value = false;
16069
+ } else if (event.key === "Enter" && inputValue2.value) {
16070
+ const date2 = parseUserInput(inputValue2.value);
16071
+ if (date2) {
16072
+ if (props2.enableTime) {
16073
+ emit2("update:modelValue", date2.toISOString());
16074
+ } else {
16075
+ const utcDate = new Date(Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate()));
16076
+ emit2("update:modelValue", utcDate.toISOString().split("T")[0]);
16077
+ }
16078
+ isOpen.value = false;
16079
+ }
16080
+ }
16081
+ };
16082
+ return {
16083
+ inputValue: inputValue2,
16084
+ handleInput: handleInput2,
16085
+ handleFocus: handleFocus2,
16086
+ handleClick: handleClick2,
16087
+ handleKeydown: handleKeydown2
16088
+ };
15600
16089
  }
16090
+ const { inputValue, handleInput, handleFocus, handleClick, handleKeydown } = useInputHandling();
16091
+ const { currentMonthDays, currentMonthValue, months, years, weekDays, isSelected, isToday, isNotInMonth } = useCalendarView();
16092
+ const { selectMonth, selectYear, previousMonth, nextMonth, previousYear, nextYear } = useNavigation();
16093
+ const { hours, minutes, handleHourInput, handleMinuteInput, timezoneDisplay } = useTimeHandling();
15601
16094
  function selectDate(date2) {
15602
16095
  var _a2, _b;
15603
16096
  if (!date2 || !props2.editMode) return;
16097
+ const tzOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
15604
16098
  const newDate = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
15605
16099
  if (props2.enableTime) {
15606
16100
  const currentHours = ((_a2 = selectedDate.value) == null ? void 0 : _a2.getHours()) ?? (/* @__PURE__ */ new Date()).getHours();
15607
16101
  const currentMinutes = ((_b = selectedDate.value) == null ? void 0 : _b.getMinutes()) ?? (/* @__PURE__ */ new Date()).getMinutes();
15608
16102
  newDate.setHours(currentHours);
15609
16103
  newDate.setMinutes(currentMinutes);
16104
+ if (props2.timezone === "UTC") {
16105
+ newDate.setMinutes(newDate.getMinutes() + tzOffset);
16106
+ }
15610
16107
  emit2("update:modelValue", newDate.toISOString());
15611
16108
  } else {
15612
- newDate.setUTCHours(0, 0, 0, 0);
15613
- emit2("update:modelValue", newDate.toISOString().split("T")[0]);
16109
+ const utcDate = new Date(Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate()));
16110
+ emit2("update:modelValue", utcDate.toISOString().split("T")[0]);
15614
16111
  isOpen.value = false;
15615
16112
  }
15616
16113
  }
15617
- const hours = computed(() => {
15618
- var _a2;
15619
- return ((_a2 = selectedDate.value) == null ? void 0 : _a2.getHours()) ?? 0;
15620
- });
15621
- const minutes = computed(() => {
15622
- var _a2;
15623
- return ((_a2 = selectedDate.value) == null ? void 0 : _a2.getMinutes()) ?? 0;
15624
- });
15625
- function handleHourInput(value) {
15626
- if (!selectedDate.value) return;
15627
- const newDate = new Date(selectedDate.value);
15628
- newDate.setHours(value);
15629
- emit2("update:modelValue", newDate.toISOString());
15630
- }
15631
- function handleMinuteInput(value) {
15632
- if (!selectedDate.value) return;
15633
- const newDate = new Date(selectedDate.value);
15634
- newDate.setMinutes(value);
15635
- emit2("update:modelValue", newDate.toISOString());
15636
- }
15637
- function isSelected(date2) {
15638
- if (!date2 || !selectedDate.value) return false;
15639
- return date2.toISOString().split("T")[0] === selectedDate.value.toISOString().split("T")[0];
15640
- }
15641
- function isToday(date2) {
15642
- if (!date2) return false;
15643
- return time.dateIsToday(date2);
15644
- }
15645
- const timezoneDisplay = computed(() => {
15646
- if (!props2.enableTime) return "";
15647
- try {
15648
- return (/* @__PURE__ */ new Date()).toLocaleString("en-US", {
15649
- timeZoneName: "short",
15650
- timeZone: props2.timezone
15651
- }).split(" ").pop();
15652
- } catch {
15653
- return "UTC";
15654
- }
16114
+ const datePickerRef = ref(null);
16115
+ const calendarRef = ref(null);
16116
+ onMounted(() => {
16117
+ const handleDocumentClick = (e) => {
16118
+ var _a2, _b;
16119
+ const target = e.target;
16120
+ if (!((_a2 = datePickerRef.value) == null ? void 0 : _a2.contains(target)) && !((_b = calendarRef.value) == null ? void 0 : _b.contains(target))) {
16121
+ isOpen.value = false;
16122
+ }
16123
+ };
16124
+ document.addEventListener("click", handleDocumentClick);
16125
+ onBeforeUnmount(() => {
16126
+ document.removeEventListener("click", handleDocumentClick);
16127
+ });
15655
16128
  });
15656
- function isNotInMonth(date2) {
15657
- return time.isTrailingOrLeadingDate(date2, currentMonth.value.getMonth());
15658
- }
15659
16129
  return (_ctx, _cache) => {
15660
16130
  return openBlock(), createElementBlock("div", {
15661
16131
  class: normalizeClass(["bagel-input", { small: _ctx.small }]),
15662
- title: _ctx.label
16132
+ title: _ctx.label,
16133
+ onFocusin: _cache[6] || (_cache[6] = //@ts-ignore
16134
+ (...args) => unref(handleFocus) && unref(handleFocus)(...args))
15663
16135
  }, [
15664
16136
  _ctx.label ? (openBlock(), createElementBlock("label", _hoisted_2$t, [
15665
16137
  createTextVNode(toDisplayString(_ctx.label) + " ", 1),
15666
16138
  _ctx.required ? (openBlock(), createElementBlock("span", _hoisted_3$o, "*")) : createCommentVNode("", true)
15667
16139
  ])) : createCommentVNode("", true),
15668
16140
  createVNode(unref(_sfc_main$V), {
15669
- shown: unref(isOpen),
16141
+ shown: isOpen.value,
15670
16142
  placement: "bottom-start",
15671
- onApplyShow: _cache[4] || (_cache[4] = ($event) => isRef(isOpen) ? isOpen.value = true : isOpen = true),
15672
- onApplyHide: _cache[5] || (_cache[5] = ($event) => isRef(isOpen) ? isOpen.value = false : isOpen = false)
16143
+ autoHide: false,
16144
+ triggers: ["click"]
15673
16145
  }, {
15674
16146
  trigger: withCtx(() => [
15675
- createElementVNode("div", _hoisted_4$g, [
16147
+ createElementVNode("div", {
16148
+ ref_key: "datePickerRef",
16149
+ ref: datePickerRef,
16150
+ class: "date-picker-container",
16151
+ onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {
16152
+ }, ["stop"])),
16153
+ onClick: _cache[1] || (_cache[1] = withModifiers(() => {
16154
+ }, ["stop"]))
16155
+ }, [
15676
16156
  createVNode(unref(TextInput), {
15677
- modelValue: formattedDisplayValue.value,
16157
+ modelValue: unref(formattedDisplayValue),
15678
16158
  icon: "calendar",
15679
- min: formattedMin.value,
15680
- max: formattedMax.value,
16159
+ min: unref(formattedMin),
16160
+ max: unref(formattedMax),
15681
16161
  required: _ctx.required,
15682
16162
  disabled: !_ctx.editMode,
15683
16163
  class: normalizeClass(["date-input", {
15684
16164
  "txt-center": _ctx.center
15685
16165
  }]),
15686
- readonly: "",
15687
- onClick: _cache[0] || (_cache[0] = ($event) => isRef(isOpen) ? isOpen.value = true : isOpen = true)
15688
- }, null, 8, ["modelValue", "min", "max", "required", "disabled", "class"])
15689
- ])
16166
+ readonly: false,
16167
+ onInput: unref(handleInput),
16168
+ onFocus: unref(handleFocus),
16169
+ onClick: unref(handleClick),
16170
+ onKeydown: unref(handleKeydown)
16171
+ }, null, 8, ["modelValue", "min", "max", "required", "disabled", "class", "onInput", "onFocus", "onClick", "onKeydown"])
16172
+ ], 544)
15690
16173
  ]),
15691
16174
  default: withCtx(() => [
15692
- createElementVNode("div", _hoisted_5$f, [
15693
- createElementVNode("div", _hoisted_6$c, [
15694
- createElementVNode("div", _hoisted_7$9, [
15695
- unref(currentView) === "days" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
16175
+ createElementVNode("div", {
16176
+ ref_key: "calendarRef",
16177
+ ref: calendarRef,
16178
+ class: "ltr flex gap-075 p-05 m_flex-wrap calendar-container justify-content-center h-100p",
16179
+ onClick: _cache[5] || (_cache[5] = withModifiers(() => {
16180
+ }, ["stop"]))
16181
+ }, [
16182
+ createElementVNode("div", _hoisted_4$g, [
16183
+ createElementVNode("div", _hoisted_5$f, [
16184
+ currentView.value === "days" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
15696
16185
  createVNode(unref(Btn), {
15697
16186
  flat: "",
15698
16187
  icon: "chevron_left",
15699
- onClick: previousMonth
15700
- }),
15701
- createElementVNode("div", _hoisted_8$6, [
16188
+ onClick: unref(previousMonth)
16189
+ }, null, 8, ["onClick"]),
16190
+ createElementVNode("div", _hoisted_6$c, [
15702
16191
  createVNode(unref(Btn), {
15703
16192
  flat: "",
15704
16193
  class: "month-btn",
15705
- onClick: _cache[1] || (_cache[1] = ($event) => isRef(currentView) ? currentView.value = "months" : currentView = "months")
16194
+ onClick: _cache[2] || (_cache[2] = ($event) => currentView.value = "months")
15706
16195
  }, {
15707
16196
  default: withCtx(() => [
15708
- createTextVNode(toDisplayString(currentMonthValue.value.formatted.month), 1)
16197
+ createTextVNode(toDisplayString(unref(currentMonthValue).formatted.month), 1)
15709
16198
  ]),
15710
16199
  _: 1
15711
16200
  }),
15712
16201
  createVNode(unref(Btn), {
15713
16202
  flat: "",
15714
16203
  class: "year-btn",
15715
- onClick: _cache[2] || (_cache[2] = ($event) => isRef(currentView) ? currentView.value = "years" : currentView = "years")
16204
+ onClick: _cache[3] || (_cache[3] = ($event) => currentView.value = "years")
15716
16205
  }, {
15717
16206
  default: withCtx(() => [
15718
- createTextVNode(toDisplayString(currentMonthValue.value.formatted.year), 1)
16207
+ createTextVNode(toDisplayString(unref(currentMonthValue).formatted.year), 1)
15719
16208
  ]),
15720
16209
  _: 1
15721
16210
  })
@@ -15723,114 +16212,114 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
15723
16212
  createVNode(unref(Btn), {
15724
16213
  flat: "",
15725
16214
  icon: "chevron_right",
15726
- onClick: nextMonth
15727
- })
16215
+ onClick: unref(nextMonth)
16216
+ }, null, 8, ["onClick"])
15728
16217
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
15729
16218
  createVNode(unref(Btn), {
15730
16219
  flat: "",
15731
16220
  icon: "chevron_left",
15732
- onClick: previousYear
15733
- }),
15734
- createElementVNode("span", _hoisted_9$5, toDisplayString(currentMonthValue.value.formatted.year), 1),
16221
+ onClick: unref(previousYear)
16222
+ }, null, 8, ["onClick"]),
16223
+ createElementVNode("span", _hoisted_7$9, toDisplayString(unref(currentMonthValue).formatted.year), 1),
15735
16224
  createVNode(unref(Btn), {
15736
16225
  flat: "",
15737
16226
  icon: "chevron_right",
15738
- onClick: nextYear
15739
- })
16227
+ onClick: unref(nextYear)
16228
+ }, null, 8, ["onClick"])
15740
16229
  ], 64))
15741
16230
  ]),
15742
- unref(currentView) === "days" ? (openBlock(), createElementBlock("div", _hoisted_10$5, [
15743
- (openBlock(true), createElementBlock(Fragment, null, renderList(weekDays.value, (day) => {
16231
+ currentView.value === "days" ? (openBlock(), createElementBlock("div", _hoisted_8$6, [
16232
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(weekDays), (day) => {
15744
16233
  return openBlock(), createElementBlock("div", {
15745
16234
  key: day,
15746
16235
  class: "txt-center txt-12 opacity-6"
15747
16236
  }, toDisplayString(day), 1);
15748
16237
  }), 128)),
15749
- (openBlock(true), createElementBlock(Fragment, null, renderList(currentMonthDays.value, (date2) => {
16238
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(currentMonthDays), (date2) => {
15750
16239
  return openBlock(), createElementBlock("button", {
15751
16240
  key: date2 == null ? void 0 : date2.toISOString(),
15752
16241
  type: "button",
15753
16242
  class: normalizeClass(["day aspect-ratio-1 flex align-items-center justify-content-center pointer round txt14 p-0", {
15754
- "selected": isSelected(date2),
15755
- "today": isToday(date2),
15756
- "disabled": isDateDisabled(date2),
15757
- "not-in-month": isNotInMonth(date2)
16243
+ "selected": unref(isSelected)(date2),
16244
+ "today": unref(isToday)(date2),
16245
+ "disabled": unref(isDateDisabled)(date2),
16246
+ "not-in-month": unref(isNotInMonth)(date2)
15758
16247
  }]),
15759
- disabled: isDateDisabled(date2),
16248
+ disabled: unref(isDateDisabled)(date2),
15760
16249
  onClick: ($event) => selectDate(date2)
15761
- }, toDisplayString(date2 == null ? void 0 : date2.getDate()), 11, _hoisted_11$5);
16250
+ }, toDisplayString(date2 == null ? void 0 : date2.getDate()), 11, _hoisted_9$5);
15762
16251
  }), 128))
15763
- ])) : unref(currentView) === "months" ? (openBlock(), createElementBlock("div", _hoisted_12$5, [
15764
- (openBlock(true), createElementBlock(Fragment, null, renderList(months.value, (month) => {
16252
+ ])) : currentView.value === "months" ? (openBlock(), createElementBlock("div", _hoisted_10$5, [
16253
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(months), (month) => {
15765
16254
  return openBlock(), createElementBlock("button", {
15766
16255
  key: month.value,
15767
16256
  class: normalizeClass(["month-item flex align-items-center justify-content-center pointer rounded p-05 txt14 border-none", {
15768
- selected: month.value === currentMonthValue.value.month,
16257
+ selected: month.value === unref(currentMonthValue).month,
15769
16258
  disabled: month.disabled
15770
16259
  }]),
15771
16260
  disabled: month.disabled,
15772
- onClick: ($event) => selectMonth(month.value)
15773
- }, toDisplayString(month.name), 11, _hoisted_13$4);
16261
+ onClick: ($event) => unref(selectMonth)(month.value)
16262
+ }, toDisplayString(month.name), 11, _hoisted_11$5);
15774
16263
  }), 128))
15775
- ])) : (openBlock(), createElementBlock("div", _hoisted_14$4, [
15776
- (openBlock(true), createElementBlock(Fragment, null, renderList(years.value, (year) => {
16264
+ ])) : (openBlock(), createElementBlock("div", _hoisted_12$5, [
16265
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(years), (year) => {
15777
16266
  return openBlock(), createElementBlock("button", {
15778
16267
  key: year.value,
15779
16268
  class: normalizeClass(["year-item flex align-items-center justify-content-center pointer rounded p-05 txt14 border-none", {
15780
- selected: year.value === currentMonthValue.value.year,
16269
+ selected: year.value === unref(currentMonthValue).year,
15781
16270
  disabled: year.disabled
15782
16271
  }]),
15783
16272
  disabled: year.disabled,
15784
- onClick: ($event) => selectYear(year.value)
15785
- }, toDisplayString(year.value), 11, _hoisted_15$4);
16273
+ onClick: ($event) => unref(selectYear)(year.value)
16274
+ }, toDisplayString(year.value), 11, _hoisted_13$4);
15786
16275
  }), 128))
15787
16276
  ]))
15788
16277
  ]),
15789
- _ctx.enableTime && unref(currentView) === "days" ? (openBlock(), createElementBlock("div", _hoisted_16$4, [
15790
- createElementVNode("div", _hoisted_17$4, [
16278
+ _ctx.enableTime && currentView.value === "days" ? (openBlock(), createElementBlock("div", _hoisted_14$4, [
16279
+ createElementVNode("div", _hoisted_15$4, [
15791
16280
  createVNode(unref(NumberInput), {
15792
16281
  center: "",
15793
- "model-value": hours.value,
15794
- disabled: !selectedDate.value,
16282
+ "model-value": unref(hours),
16283
+ disabled: !unref(selectedDate),
15795
16284
  min: 0,
15796
16285
  max: 23,
15797
16286
  layout: "vertical",
15798
16287
  padZero: 2,
15799
- "onUpdate:modelValue": handleHourInput
15800
- }, null, 8, ["model-value", "disabled"]),
15801
- _cache[6] || (_cache[6] = createElementVNode("p", { class: "pb-075" }, " : ", -1)),
16288
+ "onUpdate:modelValue": unref(handleHourInput)
16289
+ }, null, 8, ["model-value", "disabled", "onUpdate:modelValue"]),
16290
+ _cache[7] || (_cache[7] = createElementVNode("p", { class: "pb-075" }, " : ", -1)),
15802
16291
  createVNode(unref(NumberInput), {
15803
16292
  center: "",
15804
- "model-value": minutes.value,
15805
- disabled: !selectedDate.value,
16293
+ "model-value": unref(minutes),
16294
+ disabled: !unref(selectedDate),
15806
16295
  min: 0,
15807
16296
  max: 59,
15808
16297
  padZero: 2,
15809
16298
  layout: "vertical",
15810
- "onUpdate:modelValue": handleMinuteInput
15811
- }, null, 8, ["model-value", "disabled"])
16299
+ "onUpdate:modelValue": unref(handleMinuteInput)
16300
+ }, null, 8, ["model-value", "disabled", "onUpdate:modelValue"])
15812
16301
  ]),
15813
- createElementVNode("span", _hoisted_18$2, toDisplayString(timezoneDisplay.value), 1),
15814
- selectedDate.value ? (openBlock(), createBlock(unref(Btn), {
16302
+ createElementVNode("span", _hoisted_16$4, toDisplayString(unref(timezoneDisplay)), 1),
16303
+ unref(selectedDate) ? (openBlock(), createBlock(unref(Btn), {
15815
16304
  key: 0,
15816
16305
  flat: "",
15817
- onClick: _cache[3] || (_cache[3] = ($event) => isRef(isOpen) ? isOpen.value = false : isOpen = false)
16306
+ onClick: _cache[4] || (_cache[4] = ($event) => isOpen.value = false)
15818
16307
  }, {
15819
- default: withCtx(() => _cache[7] || (_cache[7] = [
16308
+ default: withCtx(() => _cache[8] || (_cache[8] = [
15820
16309
  createTextVNode(" Done ")
15821
16310
  ])),
15822
16311
  _: 1
15823
16312
  })) : createCommentVNode("", true)
15824
16313
  ])) : createCommentVNode("", true)
15825
- ])
16314
+ ], 512)
15826
16315
  ]),
15827
16316
  _: 1
15828
16317
  }, 8, ["shown"])
15829
- ], 10, _hoisted_1$F);
16318
+ ], 42, _hoisted_1$F);
15830
16319
  };
15831
16320
  }
15832
16321
  });
15833
- const DateInput = /* @__PURE__ */ _export_sfc(_sfc_main$M, [["__scopeId", "data-v-a2f98d6e"]]);
16322
+ const DateInput = /* @__PURE__ */ _export_sfc(_sfc_main$M, [["__scopeId", "data-v-5d1b6a15"]]);
15834
16323
  const _hoisted_1$E = ["title"];
15835
16324
  const _hoisted_2$s = { key: 0 };
15836
16325
  const _hoisted_3$n = {
@@ -16397,11 +16886,11 @@ function compareAsc(dateLeft, dateRight) {
16397
16886
  return diff;
16398
16887
  }
16399
16888
  }
16400
- function isDate$2(value) {
16889
+ function isDate$1(value) {
16401
16890
  return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
16402
16891
  }
16403
16892
  function isValid(date2) {
16404
- if (!isDate$2(date2) && typeof date2 !== "number") {
16893
+ if (!isDate$1(date2) && typeof date2 !== "number") {
16405
16894
  return false;
16406
16895
  }
16407
16896
  const _date = toDate(date2);
@@ -20083,7 +20572,7 @@ const bl = (e, t) => e == null ? void 0 : e.querySelector(`[data-dp-element="${t
20083
20572
  return l2 && e.preventDefault(), t();
20084
20573
  }, on$1 = (e, t, l2, a2, n2, c2) => {
20085
20574
  const v2 = parse$1(e, t.slice(0, e.length), /* @__PURE__ */ new Date(), { locale: c2 });
20086
- return isValid(v2) && isDate$2(v2) ? a2 || n2 ? v2 : set(v2, {
20575
+ return isValid(v2) && isDate$1(v2) ? a2 || n2 ? v2 : set(v2, {
20087
20576
  hours: +l2.hours,
20088
20577
  minutes: +(l2 == null ? void 0 : l2.minutes),
20089
20578
  seconds: +(l2 == null ? void 0 : l2.seconds),
@@ -25657,7 +26146,7 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
25657
26146
  }
25658
26147
  });
25659
26148
  const OTP = /* @__PURE__ */ _export_sfc(_sfc_main$G, [["__scopeId", "data-v-8e8db33e"]]);
25660
- const _hoisted_1$y = { class: "relative" };
26149
+ const _hoisted_1$y = { class: "relative passwordInput" };
25661
26150
  const _hoisted_2$n = { class: "m-password position-bottom-end flex column justify-content-center" };
25662
26151
  const _sfc_main$F = /* @__PURE__ */ defineComponent({
25663
26152
  __name: "PasswordInput",
@@ -26072,53 +26561,27 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
26072
26561
  }
26073
26562
  });
26074
26563
  const RangeInput = /* @__PURE__ */ _export_sfc(_sfc_main$C, [["__scopeId", "data-v-25d991e5"]]);
26075
- const tableTools = [
26076
- "mergeCells",
26077
- "splitCells",
26078
- "addRowBefore",
26079
- "addRowAfter",
26080
- "deleteRow",
26081
- "insertColumnLeft",
26082
- "insertColumnRight",
26083
- "deleteColumn",
26084
- "alignLeft",
26085
- "alignCenter",
26086
- "alignRight",
26087
- "alignJustify",
26088
- "deleteTable"
26089
- ];
26090
- const defaultToolbarConfig = [
26564
+ const basicToolbarConfig = [
26091
26565
  "h2",
26092
26566
  "h3",
26093
26567
  "h4",
26094
26568
  "h5",
26095
26569
  "h6",
26096
26570
  "separator",
26097
- "bold",
26098
- "italic",
26099
- "underline",
26100
- "separator",
26101
- "fontColor",
26102
- "bgColor",
26103
- "separator",
26104
26571
  "p",
26105
26572
  "blockquote",
26106
26573
  "orderedList",
26107
26574
  "unorderedList",
26108
- "indent",
26109
- "outdent",
26575
+ "separator",
26576
+ "bold",
26577
+ "italic",
26578
+ "underline",
26110
26579
  "separator",
26111
26580
  "link",
26112
26581
  "image",
26113
- // 'youtube',
26114
- "separator",
26115
- "splitView",
26582
+ "embed",
26116
26583
  "clear",
26117
- "insertTable",
26118
- ...tableTools,
26119
- "separator",
26120
- "undo",
26121
- "redo",
26584
+ "splitView",
26122
26585
  "fullScreen"
26123
26586
  ];
26124
26587
  const toolbarOptions = [
@@ -26136,7 +26599,7 @@ const toolbarOptions = [
26136
26599
  { name: "unorderedList", label: "Unordered List", icon: "format_list_bulleted" },
26137
26600
  { name: "link", label: "Link", icon: "add_link" },
26138
26601
  { name: "image", label: "Image", icon: "add_photo_alternate" },
26139
- { name: "youtube", label: "YouTube", icon: "youtube_activity" },
26602
+ { name: "embed", label: "Embed", icon: "media_link" },
26140
26603
  { name: "splitView", label: "Split View", icon: "code" },
26141
26604
  { name: "clear", label: "Clear Formatting", icon: "format_clear" },
26142
26605
  { name: "alignLeft", label: "Align Left", icon: "format_align_left" },
@@ -26226,7 +26689,7 @@ const _hoisted_1$t = {
26226
26689
  const _sfc_main$A = /* @__PURE__ */ defineComponent({
26227
26690
  __name: "EditorToolbar",
26228
26691
  props: {
26229
- config: { default: defaultToolbarConfig },
26692
+ config: { default: basicToolbarConfig },
26230
26693
  selectedStyles: {}
26231
26694
  },
26232
26695
  emits: ["action"],
@@ -26281,45 +26744,50 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
26281
26744
  };
26282
26745
  }
26283
26746
  });
26284
- const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-bcd681b9"]]);
26285
- function createCommandExecutor(state2, commands) {
26286
- return {
26287
- execute(command, value) {
26288
- const cmd = commands[command];
26289
- if (cmd) {
26290
- cmd.execute(state2, value);
26291
- }
26292
- },
26293
- isActive(command) {
26294
- var _a2;
26295
- const cmd = commands[command];
26296
- return ((_a2 = cmd.isActive) == null ? void 0 : _a2.call(cmd, state2)) || false;
26297
- },
26298
- getValue(command) {
26299
- var _a2;
26300
- const cmd = commands[command];
26301
- return ((_a2 = cmd.getValue) == null ? void 0 : _a2.call(cmd, state2)) || null;
26302
- }
26303
- };
26304
- }
26747
+ const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-9d8a6eb6"]]);
26305
26748
  function isStyleActive(style, doc) {
26306
26749
  const selection = doc.getSelection();
26307
26750
  if (!selection || !selection.rangeCount) return false;
26308
26751
  const range2 = selection.getRangeAt(0);
26309
26752
  const container = range2.commonAncestorContainer;
26310
- const parent = container.nodeType === 3 ? container.parentElement : container;
26753
+ const parent = container.nodeType === Node.TEXT_NODE ? container.parentElement : container;
26311
26754
  if (!parent) return false;
26312
- const checkParent = (element, tags) => {
26313
- if (!element) return false;
26314
- if (tags.includes(element.tagName.toLowerCase())) return true;
26315
- return checkParent(element.parentElement, tags);
26316
- };
26317
- const styleTags = {
26755
+ const checkParent = (element, tags2) => {
26756
+ if (!element || !element.tagName) return false;
26757
+ const tagName = element.tagName.toLowerCase();
26758
+ if (tags2.includes(tagName)) return true;
26759
+ return checkParent(element.parentElement, tags2);
26760
+ };
26761
+ const styleMappings = {
26762
+ // Inline styles
26318
26763
  bold: ["strong", "b"],
26319
26764
  italic: ["em", "i"],
26320
- underline: ["u"]
26321
- };
26322
- return checkParent(parent, styleTags[style] ?? [style]);
26765
+ underline: ["u"],
26766
+ // Block styles
26767
+ h1: ["h1"],
26768
+ h2: ["h2"],
26769
+ h3: ["h3"],
26770
+ h4: ["h4"],
26771
+ h5: ["h5"],
26772
+ h6: ["h6"],
26773
+ p: ["p"],
26774
+ blockquote: ["blockquote"],
26775
+ // List styles
26776
+ orderedList: ["ol"],
26777
+ unorderedList: ["ul"]
26778
+ };
26779
+ if (["splitView", "codeView", "fullScreen"].includes(style)) {
26780
+ return false;
26781
+ }
26782
+ if (style === "orderedList" || style === "unorderedList") {
26783
+ const listParent = parent.closest(style === "orderedList" ? "ol" : "ul");
26784
+ return !!listParent;
26785
+ }
26786
+ const tags = styleMappings[style];
26787
+ if (tags) {
26788
+ return checkParent(parent, tags);
26789
+ }
26790
+ return checkParent(parent, [style]);
26323
26791
  }
26324
26792
  function analyzeSelection(doc, range2) {
26325
26793
  const container = range2.commonAncestorContainer;
@@ -26523,7 +26991,7 @@ function formatting(state2) {
26523
26991
  };
26524
26992
  return { text, block, list, clear };
26525
26993
  }
26526
- const { frmRow: frmRow$1, numField: numField$1 } = bagelFormUtils;
26994
+ const { frmRow, numField } = bagelFormUtils;
26527
26995
  function insertImage(modal, state2) {
26528
26996
  const { range: range2, doc } = state2;
26529
26997
  if (!range2 || !doc) return;
@@ -26532,9 +27000,9 @@ function insertImage(modal, state2) {
26532
27000
  schema: [
26533
27001
  { id: "src", $el: "file", attrs: { bindkey: "url" } },
26534
27002
  { id: "alt", $el: "text", label: "Alt Text" },
26535
- frmRow$1(
26536
- numField$1("width", "Width", { min: 1 }),
26537
- numField$1("height", "Height", { min: 1 })
27003
+ frmRow(
27004
+ numField("width", "Width", { min: 1 }),
27005
+ numField("height", "Height", { min: 1 })
26538
27006
  ),
26539
27007
  { id: "figcaption", $el: "check", label: "Show Caption" }
26540
27008
  ],
@@ -26579,6 +27047,52 @@ function insertLink(modal, state2) {
26579
27047
  }
26580
27048
  });
26581
27049
  }
27050
+ function insertEmbed(modal, state2) {
27051
+ const { range: range2, doc } = state2;
27052
+ if (!range2 || !doc) return;
27053
+ modal.showModalForm({
27054
+ title: "Insert Embed",
27055
+ schema: [
27056
+ { id: "url", $el: "text", label: "URL", attrs: { placeholder: "Enter URL (YouTube, Vimeo, etc.)" } },
27057
+ frmRow(
27058
+ numField("width", "Width", { min: 200, placeholder: "560" }),
27059
+ numField("height", "Height", { min: 200, placeholder: "315" })
27060
+ ),
27061
+ { id: "allowFullscreen", $el: "check", label: "Allow Fullscreen", value: true }
27062
+ ],
27063
+ onSubmit: (data2) => {
27064
+ if (!data2.url) return;
27065
+ const url = new URL(data2.url);
27066
+ let embedUrl = data2.url;
27067
+ if (url.hostname.includes("youtube.com") || url.hostname === "youtu.be") {
27068
+ const videoId = url.hostname === "youtu.be" ? url.pathname.slice(1) : url.searchParams.get("v");
27069
+ if (videoId) {
27070
+ embedUrl = `https://www.youtube.com/embed/${videoId}`;
27071
+ }
27072
+ } else if (url.hostname.includes("vimeo.com")) {
27073
+ const videoId = url.pathname.split("/").pop();
27074
+ if (videoId) {
27075
+ embedUrl = `https://player.vimeo.com/video/${videoId}`;
27076
+ }
27077
+ }
27078
+ const iframe = doc.createElement("iframe");
27079
+ Object.assign(iframe, {
27080
+ src: embedUrl,
27081
+ width: data2.width || 560,
27082
+ height: data2.height || 315,
27083
+ frameBorder: "0",
27084
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
27085
+ allowFullscreen: data2.allowFullscreen
27086
+ });
27087
+ const wrapper = doc.createElement("div");
27088
+ wrapper.style.textAlign = "center";
27089
+ wrapper.style.margin = "1em 0";
27090
+ wrapper.appendChild(iframe);
27091
+ range2.deleteContents();
27092
+ range2.insertNode(wrapper);
27093
+ }
27094
+ });
27095
+ }
26582
27096
  function insertTable(rows, cols, state2) {
26583
27097
  if (!state2.doc) return;
26584
27098
  const table = state2.doc.createElement("table");
@@ -26700,145 +27214,393 @@ function alignColumn(range2, alignment) {
26700
27214
  }
26701
27215
  }
26702
27216
  }
26703
- function useCommands(state2, debug) {
26704
- const format2 = () => formatting(state2);
26705
- const commands = {
26706
- // Text formatting commands
26707
- bold: {
26708
- name: "Bold",
26709
- execute: (state22) => {
26710
- format2().text("bold");
26711
- },
26712
- isActive: (state22) => state22.selectedStyles.has("bold")
26713
- },
26714
- italic: {
26715
- name: "Italic",
26716
- execute: (state22) => {
26717
- format2().text("italic");
26718
- },
26719
- isActive: (state22) => state22.selectedStyles.has("italic")
26720
- },
26721
- underline: {
26722
- name: "Underline",
26723
- execute: (state22) => {
26724
- format2().text("underline");
26725
- },
26726
- isActive: (state22) => state22.selectedStyles.has("underline")
26727
- },
26728
- // Block formatting commands
26729
- h1: { name: "Heading 1", execute: (state22) => {
26730
- format2().block("h1", "h1");
26731
- }, isActive: (state22) => state22.selectedStyles.has("h1") },
26732
- h2: { name: "Heading 2", execute: (state22) => {
26733
- format2().block("h2", "h2");
26734
- }, isActive: (state22) => state22.selectedStyles.has("h2") },
26735
- h3: { name: "Heading 3", execute: (state22) => {
26736
- format2().block("h3", "h3");
26737
- }, isActive: (state22) => state22.selectedStyles.has("h3") },
26738
- h4: { name: "Heading 4", execute: (state22) => {
26739
- format2().block("h4", "h4");
26740
- }, isActive: (state22) => state22.selectedStyles.has("h4") },
26741
- h5: { name: "Heading 5", execute: (state22) => {
26742
- format2().block("h5", "h5");
26743
- }, isActive: (state22) => state22.selectedStyles.has("h5") },
26744
- h6: { name: "Heading 6", execute: (state22) => {
26745
- format2().block("h6", "h6");
26746
- }, isActive: (state22) => state22.selectedStyles.has("h6") },
26747
- p: { name: "Paragraph", execute: (state22) => {
26748
- format2().block("p", "p");
26749
- }, isActive: (state22) => state22.selectedStyles.has("p") },
26750
- blockquote: {
26751
- name: "Blockquote",
26752
- execute: (state22) => {
26753
- format2().block("blockquote", "blockquote");
26754
- },
26755
- isActive: (state22) => state22.selectedStyles.has("blockquote")
27217
+ function createCommand(name, execute, isActive) {
27218
+ return {
27219
+ name,
27220
+ execute: (state2, value) => {
27221
+ if (!state2.doc) return;
27222
+ execute(state2, value);
26756
27223
  },
26757
- // List commands
26758
- orderedList: {
26759
- name: "Ordered List",
26760
- execute: (state22) => {
26761
- format2().list("orderedList");
26762
- },
26763
- isActive: (state22) => state22.selectedStyles.has("orderedList")
27224
+ isActive
27225
+ };
27226
+ }
27227
+ function createFormattingCommand(state2, type3, command, tag) {
27228
+ const format2 = formatting(state2);
27229
+ return createCommand(
27230
+ command,
27231
+ () => {
27232
+ var _a2, _b;
27233
+ if (!state2.doc) return;
27234
+ if (type3 === "text") {
27235
+ if (command === "bold") state2.doc.execCommand("bold", false);
27236
+ else if (command === "italic") state2.doc.execCommand("italic", false);
27237
+ else if (command === "underline") state2.doc.execCommand("underline", false);
27238
+ else format2.text(command);
27239
+ } else if (type3 === "block") {
27240
+ state2.doc.execCommand("formatBlock", false, `<${command}>`);
27241
+ } else if (type3 === "list") {
27242
+ const selection = state2.doc.getSelection();
27243
+ if (!selection || !selection.rangeCount) return;
27244
+ const range2 = selection.getRangeAt(0);
27245
+ if (range2.collapsed && (!((_a2 = range2.startContainer.textContent) == null ? void 0 : _a2.trim()) || range2.startContainer === state2.doc.body)) {
27246
+ const list = state2.doc.createElement(command === "orderedList" ? "ol" : "ul");
27247
+ const li = state2.doc.createElement("li");
27248
+ li.innerHTML = "&nbsp;<br>";
27249
+ list.appendChild(li);
27250
+ const currentBlock = range2.startContainer.nodeType === 1 ? range2.startContainer : range2.startContainer.parentElement;
27251
+ if ((currentBlock == null ? void 0 : currentBlock.tagName.toLowerCase()) === "p" && isNodeEmpty$1(currentBlock)) {
27252
+ (_b = currentBlock.parentNode) == null ? void 0 : _b.replaceChild(list, currentBlock);
27253
+ } else {
27254
+ range2.insertNode(list);
27255
+ }
27256
+ range2.selectNodeContents(li);
27257
+ range2.collapse(true);
27258
+ selection.removeAllRanges();
27259
+ selection.addRange(range2);
27260
+ } else {
27261
+ state2.doc.execCommand(
27262
+ command === "orderedList" ? "insertOrderedList" : "insertUnorderedList",
27263
+ false
27264
+ );
27265
+ }
27266
+ }
26764
27267
  },
26765
- unorderedList: {
26766
- name: "Unordered List",
26767
- execute: (state22) => {
26768
- format2().list("unorderedList");
26769
- },
26770
- isActive: (state22) => state22.selectedStyles.has("unorderedList")
26771
- },
26772
- // Table commands
26773
- insertTable: {
26774
- name: "Insert Table",
26775
- execute: (state22, value) => {
26776
- const [rows, cols] = (value == null ? void 0 : value.split("x").map(Number)) || [3, 3];
26777
- insertTable(rows, cols, state22);
26778
- }
26779
- },
26780
- deleteTable: { name: "Delete Table", execute: (state22) => state22.range && deleteTable(state22.range) },
26781
- mergeCells: { name: "Merge Cells", execute: (state22) => state22.range && state22.doc && mergeCells(state22.range, state22.doc) },
26782
- splitCells: { name: "Split Cells", execute: (state22) => state22.range && state22.doc && splitCell(state22.range, state22.doc) },
26783
- addRowBefore: { name: "Add Row Before", execute: (state22) => state22.range && state22.doc && addRow("before", state22.range, state22.doc) },
26784
- addRowAfter: { name: "Add Row After", execute: (state22) => state22.range && state22.doc && addRow("after", state22.range, state22.doc) },
26785
- deleteRow: { name: "Delete Row", execute: (state22) => state22.range && deleteRow(state22.range) },
26786
- insertColumnLeft: { name: "Insert Column Left", execute: (state22) => state22.range && insertColumn("before", state22.range) },
26787
- insertColumnRight: { name: "Insert Column Right", execute: (state22) => state22.range && insertColumn("after", state22.range) },
26788
- deleteColumn: { name: "Delete Column", execute: (state22) => state22.range && deleteColumn(state22.range) },
26789
- // Alignment commands
26790
- alignLeft: { name: "Align Left", execute: (state22) => state22.range && alignColumn(state22.range, "left") },
26791
- alignCenter: { name: "Align Center", execute: (state22) => state22.range && alignColumn(state22.range, "center") },
26792
- alignRight: { name: "Align Right", execute: (state22) => state22.range && alignColumn(state22.range, "right") },
26793
- alignJustify: { name: "Align Justify", execute: (state22) => state22.range && alignColumn(state22.range, "justify") },
26794
- // Media commands
26795
- image: { name: "Insert Image", execute: (state22) => state22.modal && insertImage(state22.modal, state22) },
26796
- link: { name: "Insert Link", execute: (state22) => state22.modal && state22.range && insertLink(state22.modal, state22) },
26797
- // Other commands
26798
- clear: { name: "Clear Formatting", execute: (state22) => {
26799
- format2().clear();
26800
- } },
26801
- indent: { name: "Indent", execute: (state22) => {
26802
- format2().text("indent");
26803
- } },
26804
- outdent: { name: "Outdent", execute: (state22) => {
26805
- format2().text("outdent");
26806
- } },
26807
- fullScreen: {
26808
- name: "Full Screen",
26809
- execute: (state22) => {
26810
- state22.isFullscreen = !state22.isFullscreen;
26811
- },
26812
- isActive: (state22) => state22.isFullscreen
27268
+ () => state2.selectedStyles.has(command)
27269
+ );
27270
+ }
27271
+ function isNodeEmpty$1(node) {
27272
+ var _a2;
27273
+ const text = ((_a2 = node.textContent) == null ? void 0 : _a2.trim()) || "";
27274
+ if (text) return false;
27275
+ const brElements = node.getElementsByTagName("br");
27276
+ if (brElements.length === 0) return true;
27277
+ return brElements.length === 1 && node.childNodes.length === 1;
27278
+ }
27279
+ function createCommandRegistry(state2) {
27280
+ const format2 = formatting(state2);
27281
+ const historyCommands = {
27282
+ undo: createCommand("Undo", () => {
27283
+ var _a2;
27284
+ return (_a2 = state2.doc) == null ? void 0 : _a2.execCommand("undo", false);
27285
+ }),
27286
+ redo: createCommand("Redo", () => {
27287
+ var _a2;
27288
+ return (_a2 = state2.doc) == null ? void 0 : _a2.execCommand("redo", false);
27289
+ })
27290
+ };
27291
+ const textCommands = ["bold", "italic", "underline"].reduce((acc, cmd) => ({
27292
+ ...acc,
27293
+ [cmd]: createFormattingCommand(state2, "text", cmd)
27294
+ }), {});
27295
+ const headingCommands = ["h1", "h2", "h3", "h4", "h5", "h6"].reduce((acc, cmd) => ({
27296
+ ...acc,
27297
+ [cmd]: createFormattingCommand(state2, "block", cmd)
27298
+ }), {});
27299
+ const blockCommands = {
27300
+ p: createFormattingCommand(state2, "block", "p"),
27301
+ blockquote: createFormattingCommand(state2, "block", "blockquote")
27302
+ };
27303
+ const listCommands = {
27304
+ orderedList: createFormattingCommand(state2, "list", "orderedList"),
27305
+ unorderedList: createFormattingCommand(state2, "list", "unorderedList")
27306
+ };
27307
+ const tableCommands = {
27308
+ insertTable: createCommand("Insert Table", (state22, value) => {
27309
+ const [rows, cols] = (value == null ? void 0 : value.split("x").map(Number)) || [3, 3];
27310
+ insertTable(rows, cols, state22);
27311
+ }),
27312
+ deleteTable: createCommand("Delete Table", (state22) => state22.range && deleteTable(state22.range)),
27313
+ mergeCells: createCommand("Merge Cells", (state22) => state22.range && state22.doc && mergeCells(state22.range, state22.doc)),
27314
+ splitCells: createCommand("Split Cells", (state22) => state22.range && state22.doc && splitCell(state22.range, state22.doc)),
27315
+ addRowBefore: createCommand("Add Row Before", (state22) => state22.range && state22.doc && addRow("before", state22.range, state22.doc)),
27316
+ addRowAfter: createCommand("Add Row After", (state22) => state22.range && state22.doc && addRow("after", state22.range, state22.doc)),
27317
+ deleteRow: createCommand("Delete Row", (state22) => state22.range && deleteRow(state22.range)),
27318
+ insertColumnLeft: createCommand("Insert Column Left", (state22) => state22.range && insertColumn("before", state22.range)),
27319
+ insertColumnRight: createCommand("Insert Column Right", (state22) => state22.range && insertColumn("after", state22.range)),
27320
+ deleteColumn: createCommand("Delete Column", (state22) => state22.range && deleteColumn(state22.range))
27321
+ };
27322
+ const alignmentCommands = ["Left", "Center", "Right", "Justify"].reduce((acc, align) => ({
27323
+ ...acc,
27324
+ [`align${align}`]: createCommand(`Align ${align}`, (state22) => state22.range && alignColumn(state22.range, align.toLowerCase()))
27325
+ }), {});
27326
+ const viewCommands = {
27327
+ fullScreen: createCommand("Full Screen", (state22) => {
27328
+ state22.isFullscreen = !state22.isFullscreen;
27329
+ }, (state22) => state22.isFullscreen),
27330
+ splitView: createCommand("Split View", (state22) => {
27331
+ state22.isSplitView = !state22.isSplitView;
27332
+ }, (state22) => state22.isSplitView),
27333
+ codeView: createCommand("Code View", (state22) => {
27334
+ state22.isCodeView = !state22.isCodeView;
27335
+ }, (state22) => state22.isCodeView)
27336
+ };
27337
+ const mediaCommands = {
27338
+ image: createCommand("Insert Image", (state22) => state22.modal && insertImage(state22.modal, state22)),
27339
+ link: createCommand("Insert Link", (state22) => state22.modal && state22.range && insertLink(state22.modal, state22)),
27340
+ embed: createCommand("Insert Embed", (state22) => state22.modal && insertEmbed(state22.modal, state22))
27341
+ };
27342
+ const otherCommands = {
27343
+ clear: createCommand("Clear Formatting", () => {
27344
+ format2.clear();
27345
+ }),
27346
+ indent: createCommand("Indent", () => {
27347
+ format2.text("indent");
27348
+ }),
27349
+ outdent: createCommand("Outdent", () => {
27350
+ format2.text("outdent");
27351
+ })
27352
+ };
27353
+ return {
27354
+ ...historyCommands,
27355
+ ...textCommands,
27356
+ ...headingCommands,
27357
+ ...blockCommands,
27358
+ ...listCommands,
27359
+ ...tableCommands,
27360
+ ...alignmentCommands,
27361
+ ...viewCommands,
27362
+ ...mediaCommands,
27363
+ ...otherCommands
27364
+ };
27365
+ }
27366
+ function createCommandExecutor(state2, commands) {
27367
+ return {
27368
+ execute(command, value) {
27369
+ const cmd = commands[command];
27370
+ if (cmd) {
27371
+ cmd.execute(state2, value);
27372
+ }
26813
27373
  },
26814
- splitView: {
26815
- name: "Split View",
26816
- execute: (state22) => {
26817
- state22.isSplitView = !state22.isSplitView;
26818
- },
26819
- isActive: (state22) => state22.isSplitView
27374
+ isActive(command) {
27375
+ var _a2;
27376
+ const cmd = commands[command];
27377
+ return ((_a2 = cmd.isActive) == null ? void 0 : _a2.call(cmd, state2)) || false;
26820
27378
  },
26821
- codeView: {
26822
- name: "Code View",
26823
- execute: (state22) => {
26824
- state22.isCodeView = !state22.isCodeView;
26825
- },
26826
- isActive: (state22) => state22.isCodeView
27379
+ getValue(command) {
27380
+ var _a2;
27381
+ const cmd = commands[command];
27382
+ return ((_a2 = cmd.getValue) == null ? void 0 : _a2.call(cmd, state2)) || null;
26827
27383
  }
26828
27384
  };
27385
+ }
27386
+ function useCommands(state2, debug) {
27387
+ const commands = createCommandRegistry(state2);
26829
27388
  const executor = createCommandExecutor(state2, commands);
26830
27389
  return {
26831
27390
  execute: (command, value) => {
27391
+ if (!state2.doc) return;
27392
+ console.log("[useCommands.execute] Starting command execution:", command, value);
26832
27393
  debug == null ? void 0 : debug.logCommand(command, value);
27394
+ if (["splitView", "codeView", "fullScreen"].includes(command)) {
27395
+ console.log("[useCommands.execute] Handling view state command:", command);
27396
+ switch (command) {
27397
+ case "splitView":
27398
+ state2.isSplitView = !state2.isSplitView;
27399
+ return;
27400
+ case "codeView":
27401
+ state2.isCodeView = !state2.isCodeView;
27402
+ return;
27403
+ case "fullScreen":
27404
+ state2.isFullscreen = !state2.isFullscreen;
27405
+ return;
27406
+ }
27407
+ }
27408
+ console.log("[useCommands.execute] Focusing editor");
27409
+ state2.doc.body.focus();
27410
+ console.log("[useCommands.execute] Executing command");
26833
27411
  executor.execute(command, value);
27412
+ const newContent = state2.doc.body.innerHTML;
27413
+ console.log("[useCommands.execute] Checking content changes");
27414
+ console.log("[useCommands.execute] Old content length:", state2.content.length);
27415
+ console.log("[useCommands.execute] New content length:", newContent.length);
27416
+ if (newContent !== state2.content) {
27417
+ console.log("[useCommands.execute] Content changed, updating state");
27418
+ state2.content = newContent;
27419
+ }
27420
+ console.log("[useCommands.execute] Checking selection changes");
27421
+ const selection = state2.doc.getSelection();
27422
+ if (selection == null ? void 0 : selection.rangeCount) {
27423
+ const hasSelectionChanged = !state2.selection || state2.selection !== selection || state2.rangeCount !== selection.rangeCount;
27424
+ console.log("[useCommands.execute] Selection changed:", hasSelectionChanged);
27425
+ if (hasSelectionChanged) {
27426
+ console.log("[useCommands.execute] Updating selection state");
27427
+ state2.selection = selection;
27428
+ state2.range = selection.getRangeAt(0).cloneRange();
27429
+ state2.rangeCount = selection.rangeCount;
27430
+ }
27431
+ }
26834
27432
  },
26835
27433
  isActive: executor.isActive,
26836
27434
  getValue: executor.getValue
26837
27435
  };
26838
27436
  }
27437
+ class EditorDebugger {
27438
+ constructor(maxActions = 1e3) {
27439
+ __publicField(this, "session");
27440
+ __publicField(this, "maxActions");
27441
+ __publicField(this, "isDevelopment");
27442
+ this.maxActions = maxActions;
27443
+ this.session = this.createNewSession();
27444
+ this.isDevelopment = false;
27445
+ }
27446
+ createNewSession() {
27447
+ return {
27448
+ id: `session_${Date.now()}`,
27449
+ startTime: Date.now(),
27450
+ actions: []
27451
+ };
27452
+ }
27453
+ getNodeDescription(node) {
27454
+ var _a2;
27455
+ if (node.nodeType === Node.TEXT_NODE) {
27456
+ return `Text("${(_a2 = node.textContent) == null ? void 0 : _a2.slice(0, 20)}${node.textContent && node.textContent.length > 20 ? "..." : ""}")`;
27457
+ }
27458
+ const element = node;
27459
+ return `${element.tagName.toLowerCase()}${element.id ? `#${element.id}` : ""}`;
27460
+ }
27461
+ captureState(state2) {
27462
+ if (!state2.doc || !state2.selection) {
27463
+ return {
27464
+ content: "",
27465
+ selection: null,
27466
+ activeStyles: [],
27467
+ caretPosition: null
27468
+ };
27469
+ }
27470
+ const { selection } = state2;
27471
+ const range2 = selection.rangeCount ? selection.getRangeAt(0) : null;
27472
+ return {
27473
+ content: state2.doc.body.innerHTML,
27474
+ selection: range2 ? {
27475
+ start: range2.startOffset,
27476
+ end: range2.endOffset,
27477
+ collapsed: range2.collapsed,
27478
+ text: range2.toString()
27479
+ } : null,
27480
+ activeStyles: Array.from(state2.selectedStyles),
27481
+ caretPosition: range2 ? {
27482
+ node: this.getNodeDescription(range2.startContainer),
27483
+ offset: range2.startOffset
27484
+ } : null
27485
+ };
27486
+ }
27487
+ logCommand(command, value, state2) {
27488
+ this.addAction({
27489
+ type: "command",
27490
+ name: command,
27491
+ timestamp: Date.now(),
27492
+ details: { value },
27493
+ state: this.captureState(state2)
27494
+ });
27495
+ }
27496
+ logPaste(data2, state2) {
27497
+ this.addAction({
27498
+ type: "paste",
27499
+ name: "paste",
27500
+ timestamp: Date.now(),
27501
+ details: {
27502
+ html: data2.getData("text/html"),
27503
+ text: data2.getData("text/plain"),
27504
+ types: Array.from(data2.types)
27505
+ },
27506
+ state: this.captureState(state2)
27507
+ });
27508
+ }
27509
+ logKeyboard(event, state2) {
27510
+ this.addAction({
27511
+ type: "keyboard",
27512
+ name: "keypress",
27513
+ timestamp: Date.now(),
27514
+ details: {
27515
+ key: event.key,
27516
+ code: event.code,
27517
+ ctrl: event.ctrlKey,
27518
+ alt: event.altKey,
27519
+ shift: event.shiftKey,
27520
+ meta: event.metaKey
27521
+ },
27522
+ state: this.captureState(state2)
27523
+ });
27524
+ }
27525
+ logSelection(state2) {
27526
+ this.addAction({
27527
+ type: "selection",
27528
+ name: "selection_change",
27529
+ timestamp: Date.now(),
27530
+ details: {},
27531
+ state: this.captureState(state2)
27532
+ });
27533
+ }
27534
+ logInput(inputType, data2, state2) {
27535
+ this.addAction({
27536
+ type: "input",
27537
+ name: inputType,
27538
+ timestamp: Date.now(),
27539
+ details: { data: data2 },
27540
+ state: this.captureState(state2)
27541
+ });
27542
+ }
27543
+ addAction(action) {
27544
+ this.session.actions.push(action);
27545
+ if (this.session.actions.length > this.maxActions) {
27546
+ this.session.actions.shift();
27547
+ }
27548
+ if (this.isDevelopment) {
27549
+ console.log("Editor Action:", action);
27550
+ }
27551
+ }
27552
+ getSession() {
27553
+ return this.session;
27554
+ }
27555
+ clearSession() {
27556
+ this.session = this.createNewSession();
27557
+ }
27558
+ exportSession() {
27559
+ return JSON.stringify(this.session, null, 2);
27560
+ }
27561
+ downloadSession() {
27562
+ const blob = new Blob([this.exportSession()], { type: "application/json" });
27563
+ const url = URL.createObjectURL(blob);
27564
+ const a2 = document.createElement("a");
27565
+ a2.href = url;
27566
+ a2.download = `editor_session_${this.session.id}.json`;
27567
+ document.body.appendChild(a2);
27568
+ a2.click();
27569
+ document.body.removeChild(a2);
27570
+ URL.revokeObjectURL(url);
27571
+ }
27572
+ exportSessionWithPrompt(userMessage) {
27573
+ const prompt = {
27574
+ message: userMessage || "here is a debug log, can you analyze and fix accordingly?",
27575
+ session: this.session
27576
+ };
27577
+ return JSON.stringify(prompt, null, 2);
27578
+ }
27579
+ }
27580
+ function preserveIframes(content) {
27581
+ const temp = document.createElement("div");
27582
+ temp.innerHTML = content;
27583
+ const iframes = [];
27584
+ temp.querySelectorAll("iframe").forEach((iframe, index2) => {
27585
+ const placeholder = `<!--iframe-${index2}-->`;
27586
+ iframes.push(iframe.cloneNode(true));
27587
+ iframe.replaceWith(placeholder);
27588
+ });
27589
+ return {
27590
+ html: temp.innerHTML,
27591
+ iframes
27592
+ };
27593
+ }
27594
+ function restoreIframes(doc, content, iframes) {
27595
+ const placeholderPattern = /<!--iframe-(\d+)-->/g;
27596
+ doc.body.innerHTML = content.replace(placeholderPattern, (_2, index2) => {
27597
+ const iframe = iframes[Number(index2)];
27598
+ return iframe ? iframe.outerHTML : "";
27599
+ });
27600
+ }
26839
27601
  function useEditor() {
26840
- const editorDebugger = ref();
26841
27602
  const modal = useModal();
27603
+ let cleanupListeners = null;
26842
27604
  const state2 = reactive({
26843
27605
  content: "",
26844
27606
  doc: void 0,
@@ -26852,95 +27614,142 @@ function useEditor() {
26852
27614
  redoStack: [],
26853
27615
  rangeCount: 0,
26854
27616
  range: null,
26855
- modal
27617
+ modal,
27618
+ debug: void 0
26856
27619
  });
26857
- function updateActiveStyles() {
26858
- if (!state2.doc) return;
26859
- const styles = /* @__PURE__ */ new Set();
26860
- const styleTypes = [
26861
- "bold",
26862
- "italic",
26863
- "underline",
26864
- "h1",
26865
- "h2",
26866
- "h3",
26867
- "h4",
26868
- "h5",
26869
- "h6",
26870
- "blockquote",
26871
- "table",
26872
- "p",
26873
- "ol",
26874
- "li"
26875
- ];
26876
- styleTypes.forEach((style) => {
26877
- if (state2.doc && isStyleActive(style, state2.doc)) {
26878
- styles.add(style);
27620
+ const updateState = {
27621
+ styles: () => {
27622
+ if (!state2.doc) return;
27623
+ console.log("[updateState.styles] Starting style update");
27624
+ const styles = /* @__PURE__ */ new Set();
27625
+ const styleTypes = [
27626
+ "bold",
27627
+ "italic",
27628
+ "underline",
27629
+ "h1",
27630
+ "h2",
27631
+ "h3",
27632
+ "h4",
27633
+ "h5",
27634
+ "h6",
27635
+ "blockquote",
27636
+ "table",
27637
+ "p",
27638
+ "ol",
27639
+ "li"
27640
+ ];
27641
+ styleTypes.forEach((style) => {
27642
+ if (state2.doc && isStyleActive(style, state2.doc)) {
27643
+ styles.add(style);
27644
+ }
27645
+ });
27646
+ console.log("[updateState.styles] New styles:", Array.from(styles));
27647
+ state2.selectedStyles = styles;
27648
+ },
27649
+ content: (source) => {
27650
+ if (!state2.doc) return;
27651
+ console.log("[updateState.content] Starting content update, source:", source);
27652
+ const currentContent = state2.doc.body.innerHTML;
27653
+ console.log("[updateState.content] Current content length:", currentContent.length);
27654
+ console.log("[updateState.content] State content length:", state2.content.length);
27655
+ if (currentContent !== state2.content) {
27656
+ console.log("[updateState.content] Content changed, pushing to undo stack");
27657
+ state2.undoStack.push(state2.content);
27658
+ state2.redoStack = [];
27659
+ }
27660
+ const selection = state2.doc.getSelection();
27661
+ const range2 = (selection == null ? void 0 : selection.rangeCount) ? selection.getRangeAt(0).cloneRange() : null;
27662
+ console.log("[updateState.content] Has selection:", !!selection, "Has range:", !!range2);
27663
+ if (source === "html") {
27664
+ console.log("[updateState.content] Processing HTML content");
27665
+ const preserved = preserveIframes(state2.content);
27666
+ console.log("[updateState.content] Preserved iframes count:", preserved.iframes.length);
27667
+ state2.doc.body.innerHTML = preserved.html;
27668
+ setTimeout(() => {
27669
+ console.log("[updateState.content] Restoring iframes");
27670
+ if (state2.doc) {
27671
+ restoreIframes(state2.doc, state2.content, preserved.iframes);
27672
+ if (range2 && selection) {
27673
+ try {
27674
+ selection.removeAllRanges();
27675
+ selection.addRange(range2);
27676
+ console.log("[updateState.content] Selection restored");
27677
+ } catch (e) {
27678
+ console.warn("[updateState.content] Could not restore selection:", e);
27679
+ }
27680
+ }
27681
+ }
27682
+ }, 0);
27683
+ } else {
27684
+ console.log("[updateState.content] Setting text content");
27685
+ state2.doc.body.textContent = state2.content;
26879
27686
  }
26880
- });
26881
- state2.selectedStyles = styles;
26882
- }
26883
- function updateContent(source) {
26884
- if (!state2.doc) return;
26885
- state2.undoStack.push(state2.content);
26886
- state2.redoStack = [];
26887
- if (source === "html") {
26888
- state2.doc.body.innerHTML = state2.content;
26889
- } else {
26890
- state2.doc.body.textContent = state2.content;
26891
- }
26892
- updateActiveStyles();
26893
- }
26894
- function updateSelection() {
26895
- if (!state2.doc) return;
26896
- state2.selection = state2.doc.getSelection();
26897
- if (!state2.selection) return;
26898
- try {
26899
- if (!state2.doc.body.contains(state2.selection.anchorNode)) {
26900
- state2.doc.body.focus();
27687
+ },
27688
+ selection: () => {
27689
+ if (!state2.doc) return;
27690
+ console.log("[updateState.selection] Starting selection update");
27691
+ const newSelection = state2.doc.getSelection();
27692
+ if (!newSelection) {
27693
+ console.log("[updateState.selection] No selection available");
26901
27694
  return;
26902
27695
  }
26903
- state2.rangeCount = state2.selection.rangeCount;
26904
- if (!state2.rangeCount) {
26905
- const range2 = state2.doc.createRange();
26906
- range2.selectNodeContents(state2.doc.body);
26907
- range2.collapse(false);
26908
- state2.selection.removeAllRanges();
26909
- state2.selection.addRange(range2);
27696
+ try {
27697
+ if (!state2.doc.body.contains(newSelection.anchorNode)) {
27698
+ console.log("[updateState.selection] Selection outside editor body, refocusing");
27699
+ state2.doc.body.focus();
27700
+ return;
27701
+ }
27702
+ const hasSelectionChanged = !state2.selection || state2.selection !== newSelection || state2.rangeCount !== newSelection.rangeCount || newSelection.rangeCount > 0 && state2.range && (state2.range.startContainer !== newSelection.getRangeAt(0).startContainer || state2.range.startOffset !== newSelection.getRangeAt(0).startOffset || state2.range.endContainer !== newSelection.getRangeAt(0).endContainer || state2.range.endOffset !== newSelection.getRangeAt(0).endOffset);
27703
+ console.log("[updateState.selection] Selection changed:", hasSelectionChanged);
27704
+ if (hasSelectionChanged) {
27705
+ state2.selection = newSelection;
27706
+ state2.rangeCount = newSelection.rangeCount;
27707
+ if (newSelection.rangeCount > 0) {
27708
+ state2.range = newSelection.getRangeAt(0).cloneRange();
27709
+ console.log("[updateState.selection] New range:", {
27710
+ startOffset: state2.range.startOffset,
27711
+ endOffset: state2.range.endOffset,
27712
+ collapsed: state2.range.collapsed
27713
+ });
27714
+ }
27715
+ requestAnimationFrame(() => {
27716
+ console.log("[updateState.selection] Updating styles in RAF");
27717
+ updateState.styles();
27718
+ });
27719
+ }
27720
+ } catch (e) {
27721
+ console.warn("[updateState.selection] Selection error:", e);
27722
+ state2.selection = null;
27723
+ state2.range = null;
27724
+ state2.rangeCount = 0;
27725
+ state2.selectedStyles = /* @__PURE__ */ new Set();
26910
27726
  }
26911
- state2.range = state2.selection.getRangeAt(0).cloneRange();
26912
- updateActiveStyles();
26913
- } catch (e) {
26914
- console.warn("Selection error:", e);
26915
- state2.selection = null;
26916
- state2.range = null;
26917
- state2.rangeCount = 0;
26918
- state2.selectedStyles = /* @__PURE__ */ new Set();
26919
27727
  }
26920
- }
26921
- function setupEventListeners(doc) {
26922
- doc.addEventListener("input", () => {
26923
- state2.content = doc.body.innerHTML;
26924
- updateActiveStyles();
26925
- });
26926
- doc.addEventListener("selectionchange", () => {
26927
- updateSelection();
26928
- });
26929
- doc.addEventListener("mouseup", () => {
26930
- updateSelection();
26931
- });
26932
- doc.addEventListener("keyup", (e) => {
26933
- if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key)) {
26934
- updateSelection();
27728
+ };
27729
+ const history = {
27730
+ undo: () => {
27731
+ if (state2.undoStack.length === 0) return;
27732
+ state2.redoStack.push(state2.content);
27733
+ const lastContent = state2.undoStack.pop();
27734
+ if (lastContent !== void 0) {
27735
+ state2.content = lastContent;
27736
+ updateState.content("html");
26935
27737
  }
26936
- });
26937
- const cleanEmptyTags = () => {
27738
+ },
27739
+ redo: () => {
27740
+ if (state2.redoStack.length === 0) return;
27741
+ state2.undoStack.push(state2.content);
27742
+ const nextContent = state2.redoStack.pop();
27743
+ if (nextContent !== void 0) {
27744
+ state2.content = nextContent;
27745
+ updateState.content("html");
27746
+ }
27747
+ }
27748
+ };
27749
+ const cleanup = {
27750
+ emptyTags: (doc) => {
26938
27751
  var _a2, _b;
26939
- const walker = doc.createTreeWalker(
26940
- doc.body,
26941
- NodeFilter.SHOW_ELEMENT,
26942
- null
26943
- );
27752
+ const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_ELEMENT, null);
26944
27753
  const nodesToRemove = [];
26945
27754
  let node = walker.nextNode();
26946
27755
  while (node) {
@@ -26955,12 +27764,10 @@ function useEditor() {
26955
27764
  const isEmpty = !textContent && !innerHTML;
26956
27765
  const isDirectChildOfBody = node.parentElement === doc.body;
26957
27766
  if (isEmpty || hasOnlyNbsp || hasOnlyBr && !isDirectChildOfBody) {
26958
- if (isDirectChildOfBody) {
26959
- if (!node.matches("p")) {
26960
- const p2 = doc.createElement("p");
26961
- p2.innerHTML = "<br>";
26962
- (_b = node.parentNode) == null ? void 0 : _b.replaceChild(p2, node);
26963
- }
27767
+ if (isDirectChildOfBody && !node.matches("p")) {
27768
+ const p2 = doc.createElement("p");
27769
+ p2.innerHTML = "<br>";
27770
+ (_b = node.parentNode) == null ? void 0 : _b.replaceChild(p2, node);
26964
27771
  } else {
26965
27772
  nodesToRemove.push(node);
26966
27773
  }
@@ -26970,237 +27777,283 @@ function useEditor() {
26970
27777
  nodesToRemove.forEach((node2) => {
26971
27778
  node2.remove();
26972
27779
  });
27780
+ },
27781
+ normalizeContent: (doc) => {
27782
+ if (!doc.body.firstElementChild) {
27783
+ const p2 = doc.createElement("p");
27784
+ p2.dir = doc.body.dir;
27785
+ p2.innerHTML = "<br>";
27786
+ doc.body.appendChild(p2);
27787
+ } else {
27788
+ const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
27789
+ const textNodes = [];
27790
+ let node;
27791
+ while (node = walker.nextNode()) {
27792
+ if (node.parentElement === doc.body) {
27793
+ textNodes.push(node);
27794
+ }
27795
+ }
27796
+ textNodes.forEach((textNode) => {
27797
+ var _a2;
27798
+ if ((_a2 = textNode.textContent) == null ? void 0 : _a2.trim()) {
27799
+ const p2 = doc.createElement("p");
27800
+ p2.dir = doc.body.dir;
27801
+ p2.appendChild(textNode.cloneNode());
27802
+ doc.body.replaceChild(p2, textNode);
27803
+ } else {
27804
+ doc.body.removeChild(textNode);
27805
+ }
27806
+ });
27807
+ }
27808
+ }
27809
+ };
27810
+ function setupEventListeners(doc) {
27811
+ console.log("[setupEventListeners] Starting setup");
27812
+ if (cleanupListeners) {
27813
+ console.log("[setupEventListeners] Cleaning up existing listeners");
27814
+ cleanupListeners();
27815
+ cleanupListeners = null;
27816
+ }
27817
+ let isUpdating = false;
27818
+ let contentUpdateTimeout = null;
27819
+ let selectionUpdateTimeout = null;
27820
+ let updateCount = 0;
27821
+ const events = {
27822
+ input: () => {
27823
+ updateCount++;
27824
+ console.log(`[input event #${updateCount}] Starting, isUpdating:`, isUpdating);
27825
+ if (isUpdating) {
27826
+ console.log(`[input event #${updateCount}] Skipped - already updating`);
27827
+ return;
27828
+ }
27829
+ isUpdating = true;
27830
+ if (contentUpdateTimeout) {
27831
+ console.log(`[input event #${updateCount}] Clearing previous timeout`);
27832
+ window.clearTimeout(contentUpdateTimeout);
27833
+ }
27834
+ contentUpdateTimeout = window.setTimeout(() => {
27835
+ console.log(`[input event #${updateCount}] Timeout fired`);
27836
+ const newContent = doc.body.innerHTML;
27837
+ if (newContent !== state2.content) {
27838
+ console.log(`[input event #${updateCount}] Content changed, updating state`);
27839
+ state2.content = newContent;
27840
+ } else {
27841
+ console.log(`[input event #${updateCount}] Content unchanged`);
27842
+ }
27843
+ isUpdating = false;
27844
+ }, 100);
27845
+ },
27846
+ selectionchange: () => {
27847
+ updateCount++;
27848
+ console.log(`[selectionchange #${updateCount}] Starting, isUpdating:`, isUpdating);
27849
+ if (isUpdating) {
27850
+ console.log(`[selectionchange #${updateCount}] Skipped - already updating`);
27851
+ return;
27852
+ }
27853
+ if (selectionUpdateTimeout) {
27854
+ console.log(`[selectionchange #${updateCount}] Clearing previous timeout`);
27855
+ window.clearTimeout(selectionUpdateTimeout);
27856
+ }
27857
+ selectionUpdateTimeout = window.setTimeout(() => {
27858
+ console.log(`[selectionchange #${updateCount}] Timeout fired`);
27859
+ if (!isUpdating) {
27860
+ updateState.selection();
27861
+ } else {
27862
+ console.log(`[selectionchange #${updateCount}] Skipped - still updating`);
27863
+ }
27864
+ }, 150);
27865
+ },
27866
+ mouseup: () => {
27867
+ updateCount++;
27868
+ console.log(`[mouseup #${updateCount}] Starting, isUpdating:`, isUpdating);
27869
+ if (isUpdating) return;
27870
+ updateState.selection();
27871
+ },
27872
+ keyup: (e) => {
27873
+ updateCount++;
27874
+ console.log(`[keyup #${updateCount}] Key:`, e.key, "isUpdating:", isUpdating);
27875
+ if (isUpdating) return;
27876
+ if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key)) {
27877
+ updateState.selection();
27878
+ }
27879
+ }
26973
27880
  };
26974
- const observer = new MutationObserver(() => {
26975
- cleanEmptyTags();
26976
- });
26977
- observer.observe(doc.body, {
26978
- childList: true,
26979
- subtree: true,
26980
- characterData: true
26981
- });
27881
+ Object.entries(events).forEach(([event, handler]) => {
27882
+ doc.addEventListener(event, handler);
27883
+ console.log("[setupEventListeners] Added listener for:", event);
27884
+ });
27885
+ cleanupListeners = () => {
27886
+ console.log("[setupEventListeners] Cleaning up event listeners");
27887
+ if (contentUpdateTimeout) window.clearTimeout(contentUpdateTimeout);
27888
+ if (selectionUpdateTimeout) window.clearTimeout(selectionUpdateTimeout);
27889
+ Object.entries(events).forEach(([event, handler]) => {
27890
+ doc.removeEventListener(event, handler);
27891
+ });
27892
+ };
27893
+ return cleanupListeners;
26982
27894
  }
26983
27895
  function init(doc) {
27896
+ console.log("[init] Starting initialization");
27897
+ if (state2.hasInit) {
27898
+ console.log("[init] Already initialized, cleaning up first");
27899
+ if (cleanupListeners) {
27900
+ cleanupListeners();
27901
+ cleanupListeners = null;
27902
+ }
27903
+ }
26984
27904
  state2.doc = doc;
26985
27905
  state2.hasInit = true;
26986
- setupEventListeners(doc);
26987
- updateContent("html");
26988
- }
26989
- function handleUndo() {
26990
- if (state2.undoStack.length === 0) return;
26991
- state2.redoStack.push(state2.content);
26992
- const lastContent = state2.undoStack.pop();
26993
- if (lastContent !== void 0) {
26994
- state2.content = lastContent;
26995
- updateContent("html");
26996
- }
26997
- }
26998
- function handleRedo() {
26999
- if (state2.redoStack.length === 0) return;
27000
- state2.undoStack.push(state2.content);
27001
- const nextContent = state2.redoStack.pop();
27002
- if (nextContent !== void 0) {
27003
- state2.content = nextContent;
27004
- updateContent("html");
27005
- }
27006
- }
27007
- function handleToolbarAction(action, value) {
27008
- if (!state2.doc) return;
27009
- if (action === "undo") {
27010
- handleUndo();
27011
- return;
27012
- }
27013
- if (action === "redo") {
27014
- handleRedo();
27015
- return;
27016
- }
27017
- if (action === "fullScreen") {
27018
- state2.isFullscreen = !state2.isFullscreen;
27019
- return;
27020
- }
27021
- if (action === "splitView") {
27022
- state2.isSplitView = !state2.isSplitView;
27023
- return;
27906
+ if (state2.content) {
27907
+ const preserved = preserveIframes(state2.content);
27908
+ doc.body.innerHTML = preserved.html;
27909
+ setTimeout(() => {
27910
+ if (state2.doc) {
27911
+ restoreIframes(doc, state2.content, preserved.iframes);
27912
+ }
27913
+ }, 0);
27024
27914
  }
27025
- if (action === "codeView") {
27026
- state2.isCodeView = !state2.isCodeView;
27027
- return;
27915
+ cleanup.normalizeContent(doc);
27916
+ const range2 = doc.createRange();
27917
+ const selection = doc.getSelection();
27918
+ if (selection) {
27919
+ range2.selectNodeContents(doc.body);
27920
+ range2.collapse(false);
27921
+ selection.removeAllRanges();
27922
+ selection.addRange(range2);
27923
+ state2.range = range2.cloneRange();
27924
+ state2.selection = selection;
27925
+ state2.rangeCount = selection.rangeCount;
27926
+ }
27927
+ cleanupListeners = setupEventListeners(doc);
27928
+ }
27929
+ function initDebugger() {
27930
+ if (!state2.debug) {
27931
+ const debugInstance = new EditorDebugger();
27932
+ const debug = {
27933
+ debugger: debugInstance,
27934
+ logCommand: (command, value) => {
27935
+ debugInstance.logCommand(command, value, state2);
27936
+ },
27937
+ getSession: () => debugInstance.getSession(),
27938
+ clearSession: () => {
27939
+ debugInstance.clearSession();
27940
+ },
27941
+ downloadSession: () => {
27942
+ debugInstance.downloadSession();
27943
+ },
27944
+ exportDebugWithPrompt: (message2) => debugInstance.exportSessionWithPrompt(message2)
27945
+ };
27946
+ state2.debug = debug;
27028
27947
  }
27029
- const format2 = formatting(state2);
27030
- state2.doc.body.focus();
27031
- switch (action) {
27032
- case "bold":
27033
- case "italic":
27034
- case "underline":
27035
- format2.text(action);
27036
- break;
27037
- case "orderedList":
27038
- format2.list("ol");
27039
- break;
27040
- case "unorderedList":
27041
- format2.list("ul");
27042
- break;
27043
- case "blockquote":
27044
- case "p":
27045
- case "h1":
27046
- case "h2":
27047
- case "h3":
27048
- case "h4":
27049
- case "h5":
27050
- case "h6":
27051
- format2.block(action, action);
27052
- break;
27053
- case "insertTable": {
27054
- const [rows, cols] = (value == null ? void 0 : value.split("x").map(Number)) || [3, 3];
27055
- insertTable(rows, cols, state2);
27056
- break;
27948
+ }
27949
+ if (typeof window !== "undefined") {
27950
+ window.addEventListener("beforeunload", () => {
27951
+ if (cleanupListeners) {
27952
+ cleanupListeners();
27057
27953
  }
27058
- case "deleteTable":
27059
- if (state2.range) deleteTable(state2.range);
27060
- break;
27061
- case "mergeCells":
27062
- if (state2.range && state2.doc) mergeCells(state2.range, state2.doc);
27063
- break;
27064
- case "splitCells":
27065
- if (state2.range && state2.doc) splitCell(state2.range, state2.doc);
27066
- break;
27067
- case "addRowBefore":
27068
- case "addRowAfter":
27069
- if (state2.range && state2.doc) {
27070
- addRow(action === "addRowBefore" ? "before" : "after", state2.range, state2.doc);
27071
- }
27072
- break;
27073
- case "deleteRow":
27074
- if (state2.range) deleteRow(state2.range);
27075
- break;
27076
- case "insertColumnLeft":
27077
- case "insertColumnRight":
27078
- if (state2.range) {
27079
- insertColumn(action === "insertColumnLeft" ? "before" : "after", state2.range);
27080
- }
27081
- break;
27082
- case "deleteColumn":
27083
- if (state2.range) deleteColumn(state2.range);
27084
- break;
27085
- case "alignLeft":
27086
- case "alignCenter":
27087
- case "alignRight":
27088
- case "alignJustify":
27089
- if (state2.range) {
27090
- alignColumn(state2.range, action.replace("align", "").toLowerCase());
27091
- }
27092
- break;
27093
- case "clear":
27094
- format2.clear();
27095
- break;
27096
- default:
27097
- format2.text(action);
27098
- }
27099
- updateContent("html");
27954
+ });
27100
27955
  }
27101
- const getDebugSession = () => {
27102
- var _a2;
27103
- return (_a2 = editorDebugger.value) == null ? void 0 : _a2.getSession();
27104
- };
27105
- const clearDebugSession = () => {
27106
- var _a2;
27107
- return (_a2 = editorDebugger.value) == null ? void 0 : _a2.clearSession();
27108
- };
27109
- const downloadDebugSession = () => {
27110
- var _a2;
27111
- return (_a2 = editorDebugger.value) == null ? void 0 : _a2.downloadSession();
27112
- };
27113
- const logCommand = (command, value) => {
27114
- var _a2;
27115
- return (_a2 = editorDebugger.value) == null ? void 0 : _a2.logCommand(command, value, state2);
27116
- };
27117
- const exportDebugWithPrompt = (message2) => {
27118
- var _a2;
27119
- return (_a2 = editorDebugger.value) == null ? void 0 : _a2.exportSessionWithPrompt(message2);
27120
- };
27121
27956
  return {
27122
27957
  state: state2,
27123
27958
  init,
27124
- handleToolbarAction,
27125
- updateContent,
27126
- handleUndo,
27127
- handleRedo,
27128
- // Debug methods
27129
- debug: {
27130
- getSession: getDebugSession,
27131
- clearSession: clearDebugSession,
27132
- downloadSession: downloadDebugSession,
27133
- logCommand,
27134
- exportDebugWithPrompt
27135
- }
27136
- };
27137
- }
27138
- function useEditorKeyboard(doc, handleToolbarAction) {
27959
+ updateState,
27960
+ history,
27961
+ initDebugger,
27962
+ cleanup: () => {
27963
+ if (cleanupListeners) {
27964
+ cleanupListeners();
27965
+ cleanupListeners = null;
27966
+ }
27967
+ }
27968
+ };
27969
+ }
27970
+ const shortcuts = [
27971
+ { key: "b", command: "bold" },
27972
+ { key: "i", command: "italic" },
27973
+ { key: "u", command: "underline" },
27974
+ { key: "z", command: "undo" },
27975
+ { key: "z", modifiers: { shift: true }, command: "redo" },
27976
+ { key: "y", command: "redo" },
27977
+ { key: ".", modifiers: { shift: true }, command: "orderedList" },
27978
+ { key: "/", modifiers: { shift: true }, command: "unorderedList" },
27979
+ { key: "]", command: "indent" },
27980
+ { key: "[", command: "outdent" },
27981
+ ...Array.from({ length: 6 }, (_2, i2) => ({
27982
+ key: String(i2 + 1),
27983
+ modifiers: { alt: true },
27984
+ command: `h${i2 + 1}`
27985
+ }))
27986
+ ];
27987
+ function useEditorKeyboard(doc, executor) {
27139
27988
  doc.addEventListener("keydown", (e) => {
27140
- if (e.ctrlKey || e.metaKey) {
27141
- switch (e.key) {
27142
- case "b":
27143
- e.preventDefault();
27144
- handleToolbarAction("bold");
27145
- break;
27146
- case "i":
27147
- e.preventDefault();
27148
- handleToolbarAction("italic");
27149
- break;
27150
- case "u":
27151
- e.preventDefault();
27152
- handleToolbarAction("underline");
27153
- break;
27154
- case "z":
27155
- e.preventDefault();
27156
- if (e.shiftKey) {
27157
- handleToolbarAction("redo");
27158
- } else {
27159
- handleToolbarAction("undo");
27160
- }
27161
- break;
27162
- case "y":
27163
- e.preventDefault();
27164
- handleToolbarAction("redo");
27165
- break;
27166
- // List shortcuts
27167
- case ".":
27168
- if (e.shiftKey) {
27169
- e.preventDefault();
27170
- handleToolbarAction("orderedList");
27171
- }
27172
- break;
27173
- case "/":
27174
- if (e.shiftKey) {
27989
+ var _a2, _b;
27990
+ if (e.key === "Enter" && !e.shiftKey) {
27991
+ const selection = doc.getSelection();
27992
+ if (!selection || !selection.rangeCount) return;
27993
+ const range2 = selection.getRangeAt(0);
27994
+ const container = range2.commonAncestorContainer;
27995
+ const listItem = (_a2 = container.nodeType === 3 ? container.parentElement : container) == null ? void 0 : _a2.closest("li");
27996
+ if (listItem) {
27997
+ if (range2.collapsed && isAtEndOfNode(listItem, range2)) {
27998
+ if (isNodeEmpty(listItem)) {
27175
27999
  e.preventDefault();
27176
- handleToolbarAction("unorderedList");
27177
- }
27178
- break;
27179
- // Heading shortcuts
27180
- case "1":
27181
- case "2":
27182
- case "3":
27183
- case "4":
27184
- case "5":
27185
- case "6":
27186
- if (e.altKey) {
28000
+ const list = listItem.parentElement;
28001
+ if (!list) return;
28002
+ listItem.remove();
28003
+ if (!list.querySelector("li")) {
28004
+ const p2 = doc.createElement("p");
28005
+ p2.innerHTML = "<br>";
28006
+ (_b = list.parentNode) == null ? void 0 : _b.replaceChild(p2, list);
28007
+ range2.selectNodeContents(p2);
28008
+ range2.collapse(true);
28009
+ selection.removeAllRanges();
28010
+ selection.addRange(range2);
28011
+ }
28012
+ } else {
27187
28013
  e.preventDefault();
27188
- handleToolbarAction(`h${e.key}`);
28014
+ const newLi = doc.createElement("li");
28015
+ newLi.innerHTML = "&nbsp;<br>";
28016
+ listItem.insertAdjacentElement("afterend", newLi);
28017
+ range2.selectNodeContents(newLi);
28018
+ range2.collapse(true);
28019
+ selection.removeAllRanges();
28020
+ selection.addRange(range2);
27189
28021
  }
27190
- break;
27191
- // Indentation
27192
- case "]":
27193
- e.preventDefault();
27194
- handleToolbarAction("indent");
27195
- break;
27196
- case "[":
27197
- e.preventDefault();
27198
- handleToolbarAction("outdent");
27199
- break;
28022
+ }
27200
28023
  }
27201
28024
  }
28025
+ if (!e.ctrlKey && !e.metaKey) return;
28026
+ const matchingShortcut = shortcuts.find((shortcut) => {
28027
+ const keyMatch = shortcut.key === e.key;
28028
+ const modifiersMatch = !shortcut.modifiers || (!shortcut.modifiers.ctrl || e.ctrlKey || e.metaKey) && (!shortcut.modifiers.alt || e.altKey) && (!shortcut.modifiers.shift || e.shiftKey);
28029
+ return keyMatch && modifiersMatch;
28030
+ });
28031
+ if (matchingShortcut) {
28032
+ e.preventDefault();
28033
+ executor.execute(matchingShortcut.command);
28034
+ }
27202
28035
  });
27203
28036
  }
28037
+ function isAtEndOfNode(node, range2) {
28038
+ var _a2;
28039
+ if (node.nodeType === 3) {
28040
+ return range2.startOffset === node.length;
28041
+ }
28042
+ const { lastChild: lastChild2 } = node;
28043
+ if (!lastChild2) return true;
28044
+ if (lastChild2.nodeType === 3) {
28045
+ return range2.startContainer === lastChild2 && range2.startOffset === ((_a2 = lastChild2.textContent) == null ? void 0 : _a2.length);
28046
+ }
28047
+ return range2.startContainer === node && range2.startOffset === node.childNodes.length;
28048
+ }
28049
+ function isNodeEmpty(node) {
28050
+ var _a2;
28051
+ const text = ((_a2 = node.textContent) == null ? void 0 : _a2.replace(/\s/g, "")) || "";
28052
+ if (text) return false;
28053
+ const brElements = node.getElementsByTagName("br");
28054
+ if (brElements.length === 0) return true;
28055
+ return brElements.length === 1 && node.childNodes.length <= 2;
28056
+ }
27204
28057
  const _hoisted_1$s = { class: "bagel-input" };
27205
28058
  const _hoisted_2$i = { class: "content-area radius-05" };
27206
28059
  const _hoisted_3$e = {
@@ -27221,58 +28074,104 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
27221
28074
  const emit2 = __emit;
27222
28075
  const iframe = ref();
27223
28076
  const editor = useEditor();
27224
- const commands = useCommands(editor.state, props2.debug ? editor.debug : void 0);
27225
- const debugMethods = computed(() => props2.debug ? editor.debug : void 0);
28077
+ const isInitializing = ref(false);
28078
+ const hasInitialized = ref(false);
28079
+ if (props2.debug) {
28080
+ editor.initDebugger();
28081
+ }
28082
+ const commands = useCommands(editor.state, editor.state.debug);
28083
+ const debugMethods = computed(() => editor.state.debug);
27226
28084
  const hasRTL = computed(() => /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/.test(props2.modelValue));
28085
+ onUnmounted(() => {
28086
+ editor.cleanup();
28087
+ });
27227
28088
  async function initEditor() {
27228
28089
  var _a2;
27229
- if (!iframe.value) {
27230
- setTimeout(initEditor, 100);
28090
+ console.log("[initEditor] Starting, isInitializing:", isInitializing.value, "hasInitialized:", hasInitialized.value);
28091
+ if (isInitializing.value || !iframe.value || hasInitialized.value) {
28092
+ console.log("[initEditor] Skipped - already initializing/initialized or no iframe");
27231
28093
  return;
27232
28094
  }
27233
- editor.state.content = props2.modelValue || "";
27234
- const doc = iframe.value.contentDocument || ((_a2 = iframe.value.contentWindow) == null ? void 0 : _a2.document);
27235
- if (!doc) return;
27236
- doc.designMode = "on";
27237
- doc.body.contentEditable = "true";
27238
- doc.body.dir = hasRTL.value ? "rtl" : "ltr";
27239
- const style = doc.createElement("style");
27240
- style.textContent = (await import("./editor-BKPRpAjr.js")).default;
27241
- doc.head.appendChild(style);
27242
- editor.init(doc);
27243
- useEditorKeyboard(doc, commands.execute);
27244
- if (!doc.body.firstElementChild) {
27245
- const p2 = doc.createElement("p");
27246
- p2.dir = doc.body.dir;
27247
- p2.innerHTML = "<br>";
27248
- doc.body.appendChild(p2);
27249
- } else {
27250
- const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
27251
- const textNodes = [];
27252
- let node;
27253
- while (node = walker.nextNode()) {
27254
- if (node.parentElement === doc.body) {
27255
- textNodes.push(node);
27256
- }
28095
+ isInitializing.value = true;
28096
+ try {
28097
+ const editorStyles = await import("./editor-7QC0nG_c.js");
28098
+ const htmlContent = `
28099
+ <!DOCTYPE html>
28100
+ <html>
28101
+ <head>
28102
+ <meta charset="UTF-8">
28103
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
28104
+ <meta http-equiv="Content-Security-Policy" content="
28105
+ default-src * data: blob: 'unsafe-inline' 'unsafe-eval';
28106
+ img-src * data: blob:;
28107
+ style-src * 'unsafe-inline';
28108
+ script-src * 'unsafe-inline' 'unsafe-eval';
28109
+ frame-src * data: blob:;
28110
+ connect-src *;
28111
+ media-src *;
28112
+ ">
28113
+ <base target="_blank">
28114
+ <style id="editor-styles">${editorStyles.default}</style>
28115
+ </head>
28116
+ <body>${props2.modelValue || ""}</body>
28117
+ </html>
28118
+ `;
28119
+ const doc = iframe.value.contentDocument || ((_a2 = iframe.value.contentWindow) == null ? void 0 : _a2.document);
28120
+ if (!doc) {
28121
+ console.warn("[initEditor] No document found");
28122
+ return;
27257
28123
  }
27258
- textNodes.forEach((textNode) => {
27259
- var _a3;
27260
- if ((_a3 = textNode.textContent) == null ? void 0 : _a3.trim()) {
27261
- const p2 = doc.createElement("p");
27262
- p2.dir = doc.body.dir;
27263
- p2.appendChild(textNode.cloneNode());
27264
- doc.body.replaceChild(p2, textNode);
27265
- } else {
27266
- doc.body.removeChild(textNode);
28124
+ doc.open();
28125
+ doc.write(htmlContent);
28126
+ doc.close();
28127
+ await new Promise((resolve) => setTimeout(resolve, 0));
28128
+ doc.designMode = "on";
28129
+ doc.body.contentEditable = "true";
28130
+ doc.body.dir = hasRTL.value ? "rtl" : "ltr";
28131
+ editor.init(doc);
28132
+ useEditorKeyboard(doc, commands);
28133
+ if (!doc.body.firstElementChild) {
28134
+ const p2 = doc.createElement("p");
28135
+ p2.dir = doc.body.dir;
28136
+ p2.innerHTML = "<br>";
28137
+ doc.body.appendChild(p2);
28138
+ } else {
28139
+ const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
28140
+ const textNodes = [];
28141
+ let node;
28142
+ while (node = walker.nextNode()) {
28143
+ if (node.parentElement === doc.body) {
28144
+ textNodes.push(node);
28145
+ }
27267
28146
  }
27268
- });
28147
+ textNodes.forEach((textNode) => {
28148
+ var _a3;
28149
+ if ((_a3 = textNode.textContent) == null ? void 0 : _a3.trim()) {
28150
+ const p2 = doc.createElement("p");
28151
+ p2.dir = doc.body.dir;
28152
+ p2.appendChild(textNode.cloneNode());
28153
+ doc.body.replaceChild(p2, textNode);
28154
+ } else {
28155
+ doc.body.removeChild(textNode);
28156
+ }
28157
+ });
28158
+ }
28159
+ doc.body.focus();
28160
+ hasInitialized.value = true;
28161
+ } catch (error) {
28162
+ console.error("[initEditor] Error during initialization:", error);
28163
+ } finally {
28164
+ isInitializing.value = false;
27269
28165
  }
27270
- doc.body.focus();
27271
28166
  }
27272
- watch(() => props2.modelValue, (newValue) => {
28167
+ watch(() => props2.modelValue, (newValue, oldValue) => {
27273
28168
  if (newValue !== editor.state.content) {
27274
- editor.state.content = newValue;
27275
- editor.updateContent("html");
28169
+ if (!oldValue || Math.abs(newValue.length - oldValue.length) > 50) {
28170
+ console.log("[watch] Significant content change, resetting initialization state");
28171
+ hasInitialized.value = false;
28172
+ editor.state.content = newValue;
28173
+ editor.updateState.content("html");
28174
+ }
27276
28175
  }
27277
28176
  });
27278
28177
  watch(() => editor.state.content, (newValue) => {
@@ -27305,6 +28204,8 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
27305
28204
  ref: iframe,
27306
28205
  class: "editableContent",
27307
28206
  title: "Editor",
28207
+ sandbox: "allow-same-origin allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-presentation allow-scripts allow-top-navigation allow-top-navigation-by-user-activation",
28208
+ src: "about:blank",
27308
28209
  onLoad: initEditor
27309
28210
  }, null, 544)
27310
28211
  ]),
@@ -27313,7 +28214,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
27313
28214
  modelValue: unref(editor).state.content,
27314
28215
  "onUpdate:modelValue": [
27315
28216
  _cache[0] || (_cache[0] = ($event) => unref(editor).state.content = $event),
27316
- _cache[1] || (_cache[1] = ($event) => unref(editor).updateContent("html"))
28217
+ _cache[1] || (_cache[1] = ($event) => unref(editor).updateState.content("html"))
27317
28218
  ],
27318
28219
  language: "html"
27319
28220
  }, null, 8, ["modelValue"])) : createCommentVNode("", true)
@@ -27362,7 +28263,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
27362
28263
  };
27363
28264
  }
27364
28265
  });
27365
- const RichText = /* @__PURE__ */ _export_sfc(_sfc_main$z, [["__scopeId", "data-v-08117333"]]);
28266
+ const RichText = /* @__PURE__ */ _export_sfc(_sfc_main$z, [["__scopeId", "data-v-b58de58d"]]);
27366
28267
  const _hoisted_1$r = { class: "flex gap-05" };
27367
28268
  const _hoisted_2$h = ["disabled"];
27368
28269
  const _hoisted_3$d = { key: 1 };
@@ -31116,7 +32017,7 @@ const isPlainObject = (val) => {
31116
32017
  const prototype2 = getPrototypeOf(val);
31117
32018
  return (prototype2 === null || prototype2 === Object.prototype || Object.getPrototypeOf(prototype2) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
31118
32019
  };
31119
- const isDate$1 = kindOfTest("Date");
32020
+ const isDate = kindOfTest("Date");
31120
32021
  const isFile = kindOfTest("File");
31121
32022
  const isBlob = kindOfTest("Blob");
31122
32023
  const isFileList = kindOfTest("FileList");
@@ -31411,7 +32312,7 @@ const utils$1 = {
31411
32312
  isResponse,
31412
32313
  isHeaders,
31413
32314
  isUndefined,
31414
- isDate: isDate$1,
32315
+ isDate,
31415
32316
  isFile,
31416
32317
  isBlob,
31417
32318
  isRegExp,
@@ -41385,15 +42286,15 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
41385
42286
  }
41386
42287
  });
41387
42288
  const TabbedLayout = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["__scopeId", "data-v-915732c1"]]);
41388
- const state$1 = reactive(/* @__PURE__ */ new Map());
42289
+ const state = reactive(/* @__PURE__ */ new Map());
41389
42290
  function useTabs(group) {
41390
- if (!state$1.has(group)) {
41391
- state$1.set(group, reactive({ currentTab: void 0 }));
42291
+ if (!state.has(group)) {
42292
+ state.set(group, reactive({ currentTab: void 0 }));
41392
42293
  }
41393
42294
  const currentTab = computed({
41394
- get: () => state$1.get(group).currentTab,
42295
+ get: () => state.get(group).currentTab,
41395
42296
  set: (val) => {
41396
- state$1.get(group).currentTab = val;
42297
+ state.get(group).currentTab = val;
41397
42298
  }
41398
42299
  });
41399
42300
  return { currentTab };
@@ -43569,19 +44470,7 @@ function safeClone(obj) {
43569
44470
  function provideBagelFormState(initialData) {
43570
44471
  const data2 = ref(initialData);
43571
44472
  const isDirty = ref(false);
43572
- const getFieldData = (path) => {
43573
- if (!path) return "";
43574
- const keys4 = path.split(/[.[]/);
43575
- let current = data2.value;
43576
- for (let i2 = 0; i2 < keys4.length; i2++) {
43577
- const key = keys4[i2];
43578
- if (!current || typeof current !== "object" || !(key in current)) {
43579
- return "";
43580
- }
43581
- current = current[key];
43582
- }
43583
- return current ?? "";
43584
- };
44473
+ const getFieldData = (path) => getNestedValue(data2.value, path, "");
43585
44474
  const updateField = (path, value) => {
43586
44475
  const keys4 = path.split(/[.[]/);
43587
44476
  if (typeof data2.value !== "object" || data2.value === null) {
@@ -44395,356 +45284,6 @@ const ripple = {
44395
45284
  }
44396
45285
  }
44397
45286
  };
44398
- function getBaseField(id, labelOrRest = {}, rest = {}) {
44399
- if (typeof labelOrRest === "object") return { id, ...labelOrRest };
44400
- return { id, label: labelOrRest, ...rest };
44401
- }
44402
- function richText(id, label, options) {
44403
- return {
44404
- $el: "richtext",
44405
- class: options == null ? void 0 : options.class,
44406
- required: options == null ? void 0 : options.required,
44407
- id,
44408
- label,
44409
- vIf: options == null ? void 0 : options.vIf,
44410
- placeholder: options == null ? void 0 : options.placeholder,
44411
- attrs: {}
44412
- };
44413
- }
44414
- function txtField(id, label, options) {
44415
- return {
44416
- $el: "text",
44417
- class: options == null ? void 0 : options.class,
44418
- required: options == null ? void 0 : options.required,
44419
- id,
44420
- label,
44421
- vIf: options == null ? void 0 : options.vIf,
44422
- disabled: options == null ? void 0 : options.disabled,
44423
- placeholder: options == null ? void 0 : options.placeholder,
44424
- defaultValue: options == null ? void 0 : options.defaultValue,
44425
- attrs: {
44426
- type: options == null ? void 0 : options.type,
44427
- pattern: options == null ? void 0 : options.pattern,
44428
- multiline: options == null ? void 0 : options.multiline
44429
- }
44430
- };
44431
- }
44432
- function selectField(id, label, options, config) {
44433
- return {
44434
- $el: "select",
44435
- id,
44436
- options,
44437
- class: config == null ? void 0 : config.class,
44438
- placeholder: config == null ? void 0 : config.placeholder,
44439
- required: config == null ? void 0 : config.required,
44440
- label,
44441
- defaultValue: config == null ? void 0 : config.defaultValue,
44442
- vIf: config == null ? void 0 : config.vIf,
44443
- attrs: {
44444
- disabled: config == null ? void 0 : config.disabled,
44445
- searchable: config == null ? void 0 : config.searchable,
44446
- multiselect: config == null ? void 0 : config.multiselect,
44447
- onSearch: config == null ? void 0 : config.onSearch,
44448
- clearable: config == null ? void 0 : config.clearable
44449
- }
44450
- };
44451
- }
44452
- const slctField = selectField;
44453
- function checkField(id, label, options) {
44454
- return {
44455
- $el: "check",
44456
- class: options == null ? void 0 : options.class,
44457
- required: options == null ? void 0 : options.required,
44458
- id,
44459
- label
44460
- };
44461
- }
44462
- function dateField(id, label, options) {
44463
- return {
44464
- $el: "date",
44465
- class: options == null ? void 0 : options.class,
44466
- required: options == null ? void 0 : options.required,
44467
- id,
44468
- disabled: options == null ? void 0 : options.disabled,
44469
- label,
44470
- defaultValue: options == null ? void 0 : options.defaultValue,
44471
- vIf: options == null ? void 0 : options.vIf,
44472
- attrs: {
44473
- disabled: options == null ? void 0 : options.disabled
44474
- }
44475
- };
44476
- }
44477
- function numField(id, label, options) {
44478
- return {
44479
- $el: "number",
44480
- class: options == null ? void 0 : options.class,
44481
- required: options == null ? void 0 : options.required,
44482
- defaultValue: options == null ? void 0 : options.defaultValue,
44483
- id,
44484
- label,
44485
- disabled: options == null ? void 0 : options.disabled,
44486
- placeholder: options == null ? void 0 : options.placeholder,
44487
- helptext: options == null ? void 0 : options.helptext,
44488
- vIf: options == null ? void 0 : options.vIf,
44489
- attrs: {
44490
- step: options == null ? void 0 : options.step,
44491
- min: options == null ? void 0 : options.min,
44492
- max: options == null ? void 0 : options.max,
44493
- layout: options == null ? void 0 : options.layout,
44494
- padZero: options == null ? void 0 : options.padZero,
44495
- center: options == null ? void 0 : options.center
44496
- }
44497
- };
44498
- }
44499
- function frmRow(...children2) {
44500
- return {
44501
- $el: "div",
44502
- class: "flex gap-1 m_block align-items-end",
44503
- children: children2
44504
- };
44505
- }
44506
- function uploadField(id, label, options) {
44507
- return {
44508
- $el: "upload",
44509
- id,
44510
- label,
44511
- vIf: options == null ? void 0 : options.vIf,
44512
- attrs: {
44513
- ...options
44514
- }
44515
- };
44516
- }
44517
- function bglForm(idOrField, ...schema) {
44518
- if (typeof idOrField === "string") {
44519
- return {
44520
- $el: "bagelform",
44521
- id: idOrField,
44522
- attrs: {
44523
- schema: [idOrField, ...schema]
44524
- }
44525
- };
44526
- }
44527
- return {
44528
- $el: "bagelform",
44529
- attrs: {
44530
- schema: [idOrField, ...schema]
44531
- }
44532
- };
44533
- }
44534
- function telField(id, label, options) {
44535
- return {
44536
- $el: markRaw(TelInput),
44537
- id,
44538
- label,
44539
- vIf: options == null ? void 0 : options.vIf,
44540
- attrs: options
44541
- };
44542
- }
44543
- function findBglFieldById(id, _schema) {
44544
- for (const field of _schema) {
44545
- if (field.id === id) return field;
44546
- if (field.children && Number(field.children.length) > 0) {
44547
- const fieldChildren = field.children.filter((c2) => typeof c2 === "object" && "$el" in c2);
44548
- const child = findBglFieldById(id, fieldChildren);
44549
- if (child) return child;
44550
- }
44551
- }
44552
- return void 0;
44553
- }
44554
- function arrField(id, label, schema, options) {
44555
- return {
44556
- label,
44557
- id,
44558
- $el: "array",
44559
- vIf: options == null ? void 0 : options.vIf,
44560
- attrs: { schema, delete: true, add: true, ...options }
44561
- };
44562
- }
44563
- const state = reactive({
44564
- defaultLang: "",
44565
- availableLangs: [],
44566
- lang: "en"
44567
- });
44568
- function $tdb(langEl) {
44569
- if (!langEl) {
44570
- console.warn("No language element provided for $tdb function");
44571
- return "";
44572
- }
44573
- return langEl[state.lang] || langEl[state.defaultLang] || "";
44574
- }
44575
- function useLang() {
44576
- const lang = computed({
44577
- get: () => state.lang,
44578
- set: (val) => state.lang = val
44579
- });
44580
- const availableLangs = computed({
44581
- get: () => state.availableLangs,
44582
- set: (val) => state.availableLangs = val
44583
- });
44584
- const defaultLang = computed({
44585
- get: () => state.defaultLang,
44586
- set: (val) => state.defaultLang = val
44587
- });
44588
- return {
44589
- lang,
44590
- $tdb,
44591
- availableLangs,
44592
- defaultLang
44593
- };
44594
- }
44595
- function formatString(str, format2) {
44596
- if (format2 === "titleCase") {
44597
- return str.split("_").map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase()).join(" ");
44598
- }
44599
- if (format2 === "pascal") {
44600
- return str.split("_").map((word) => word[0].toUpperCase() + word.slice(1).toLocaleLowerCase()).join("");
44601
- }
44602
- if (format2 === "camel") {
44603
- return str.split("_").map((word, index2) => index2 === 0 ? word : word[0].toUpperCase() + word.slice(1)).join("");
44604
- }
44605
- if (format2 === "snake") {
44606
- return [...str].map((letter) => {
44607
- if (letter === letter.toUpperCase()) {
44608
- return `_${letter.toLowerCase()}`;
44609
- }
44610
- return letter;
44611
- }).join("");
44612
- }
44613
- return str;
44614
- }
44615
- const debouncers = /* @__PURE__ */ new Map();
44616
- function debounce(fn2, wait = 500) {
44617
- clearTimeout(debouncers.get(fn2));
44618
- const timeout = setTimeout(() => {
44619
- fn2();
44620
- debouncers.delete(fn2);
44621
- }, wait);
44622
- debouncers.set(fn2, timeout);
44623
- }
44624
- function slugify(str) {
44625
- return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").split(/[\s-]+/).join("-");
44626
- }
44627
- function keyToLabel(key) {
44628
- if (key === void 0) return key;
44629
- return key.split("_").map((k2) => k2.charAt(0).toUpperCase() + k2.slice(1)).join(" ") || key;
44630
- }
44631
- async function copyText(text, cb) {
44632
- await navigator.clipboard.writeText(text);
44633
- if (cb) cb("Copied to clipboard");
44634
- }
44635
- function initials(...strArr) {
44636
- strArr = strArr.flatMap((str) => str.split(/\s/));
44637
- return strArr.map((str) => str.charAt(0)).join("");
44638
- }
44639
- function useEscape(event, closeModel) {
44640
- if (event.key === "Escape") {
44641
- closeModel();
44642
- }
44643
- }
44644
- function classify(fieldVal, row, ...classes) {
44645
- return classes.map((cls) => {
44646
- if (typeof cls === "function") return cls(fieldVal, row);
44647
- return cls;
44648
- }).join(" ");
44649
- }
44650
- function bindAttrs(attrs, fieldVal, row) {
44651
- if (!attrs) return {};
44652
- const exclude = ["class"];
44653
- const arr = Object.entries(attrs).filter(([key]) => !exclude.includes(key)).map(([key, value]) => [
44654
- key,
44655
- typeof value === "function" ? value(fieldVal, row) : value
44656
- ]);
44657
- const resolvedAttrs = Object.fromEntries(arr);
44658
- return resolvedAttrs;
44659
- }
44660
- function iffer(field, itemData) {
44661
- var _a2;
44662
- if (field["v-if"] === void 0) return true;
44663
- if (typeof field["v-if"] === "boolean") return field["v-if"];
44664
- if (typeof field["v-if"] === "string") return true;
44665
- if (typeof field["v-if"] === "function")
44666
- return (_a2 = field["v-if"]) == null ? void 0 : _a2.call(field, itemData == null ? void 0 : itemData[field.id], itemData);
44667
- return true;
44668
- }
44669
- function denullify(itemData, fieldID) {
44670
- if (!fieldID) return;
44671
- return itemData ? itemData[fieldID] : void 0;
44672
- }
44673
- const isDate = (dateToTest) => !Number.isNaN(Date.parse(dateToTest));
44674
- function getFallbackSchema(data2, showFields) {
44675
- const keys4 = Array.from(new Set((data2 ?? []).flatMap(Object.keys)));
44676
- const schema = keys4.map((id) => ({
44677
- id,
44678
- label: keyToLabel(id),
44679
- transform: (val) => {
44680
- const dateFields = ["created_at", "updated_at"];
44681
- if (dateFields.includes(id)) return val ? new Date(val).toLocaleString() : val;
44682
- return val;
44683
- }
44684
- }));
44685
- return showFields ? schema.filter((f2) => showFields.includes(f2.id) || !f2.id) : schema;
44686
- }
44687
- function sleep(ms = 100) {
44688
- return new Promise((resolve) => setTimeout(resolve, ms));
44689
- }
44690
- function appendScript(src, options) {
44691
- return new Promise((resolve, reject3) => {
44692
- if (options == null ? void 0 : options.id) {
44693
- if (document.getElementById(options.id)) {
44694
- resolve();
44695
- return;
44696
- }
44697
- } else if (document.querySelector(`script[src="${src}"]`)) {
44698
- resolve();
44699
- return;
44700
- }
44701
- const script2 = document.createElement("script");
44702
- script2.src = src;
44703
- if (options == null ? void 0 : options.id) {
44704
- script2.id = options.id;
44705
- }
44706
- script2.onload = () => {
44707
- resolve();
44708
- };
44709
- script2.onerror = reject3;
44710
- document.head.append(script2);
44711
- });
44712
- }
44713
- function appendStyle(src) {
44714
- return new Promise((resolve, reject3) => {
44715
- if (document.querySelector(`link[href="${src}"]`)) {
44716
- resolve();
44717
- return;
44718
- }
44719
- const link = document.createElement("link");
44720
- link.href = src;
44721
- link.rel = "stylesheet";
44722
- link.onload = () => {
44723
- resolve();
44724
- };
44725
- link.onerror = reject3;
44726
- document.head.append(link);
44727
- });
44728
- }
44729
- function normalizeURL(url) {
44730
- if (url.startsWith("https://")) return url;
44731
- url = url.replace(/http:\/\//, "");
44732
- return `https://${url}`;
44733
- }
44734
- function normalizeDimension(value, defaultMetric = "px") {
44735
- if (typeof value === "number") return `${value}${defaultMetric}`;
44736
- return value;
44737
- }
44738
- const fileBaseUrl = "https://files.bagel.design".replace(/\/$/, "");
44739
- const bagelBaseUrl = void 0;
44740
- function pathKeyToURL(pathKey) {
44741
- const urlRE = /^https?:\/\/|^\/\//;
44742
- if (!pathKey || urlRE.test(pathKey)) return pathKey;
44743
- if (pathKey.startsWith("static/")) {
44744
- return `${bagelBaseUrl}/${pathKey}`;
44745
- }
44746
- return `${fileBaseUrl}/${pathKey}`;
44747
- }
44748
45287
  const clickOutside = {
44749
45288
  beforeMount(el, binding) {
44750
45289
  el.clickOutsideEvent = (event) => {
@@ -45363,10 +45902,11 @@ export {
45363
45902
  denullify,
45364
45903
  formatString,
45365
45904
  getFallbackSchema,
45905
+ getNestedValue,
45366
45906
  i18nTInjectionKey,
45367
45907
  iffer,
45368
45908
  initials,
45369
- isDate,
45909
+ isDate$2 as isDate,
45370
45910
  keyToLabel,
45371
45911
  localRef,
45372
45912
  normalizeDimension,