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