@niyamulahsan/create-deskapp 1.2.4 → 1.2.6

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 (104) hide show
  1. package/package.json +16 -16
  2. package/template/.env.example +20 -13
  3. package/template/AGENTS.md +699 -0
  4. package/template/package.json +3 -0
  5. package/template/src/config/app.ts +26 -24
  6. package/template/src/config/winsetup.ts +93 -91
  7. package/template/src/core/api/binding-error.ts +57 -0
  8. package/template/src/core/api/bindings.generated.ts +2 -0
  9. package/template/src/core/api/generate.manifest.ts +84 -80
  10. package/template/src/core/api/registry.ts +58 -48
  11. package/template/src/core/config.ts +101 -99
  12. package/template/src/core/database/aggregate.ts +89 -85
  13. package/template/src/core/database/config.ts +50 -48
  14. package/template/src/core/database/connection.ts +116 -114
  15. package/template/src/core/database/migrate-hooks.ts +86 -84
  16. package/template/src/core/database/paginate.ts +226 -224
  17. package/template/src/core/database/reset.ts +21 -19
  18. package/template/src/core/database/seed.ts +169 -167
  19. package/template/src/core/database/status.ts +37 -35
  20. package/template/src/core/env.ts +108 -106
  21. package/template/src/core/facade.ts +63 -61
  22. package/template/src/core/maker/db/fresh.ts +10 -8
  23. package/template/src/core/maker/db/generate.ts +13 -11
  24. package/template/src/core/maker/db/helpers.ts +92 -96
  25. package/template/src/core/maker/db/migrate.ts +37 -35
  26. package/template/src/core/maker/db/mod.ts +93 -91
  27. package/template/src/core/maker/db/module-migrate.ts +56 -54
  28. package/template/src/core/maker/db/push.ts +23 -21
  29. package/template/src/core/maker/db/reset.ts +8 -6
  30. package/template/src/core/maker/db/seed.ts +9 -7
  31. package/template/src/core/maker/db/status.ts +8 -6
  32. package/template/src/core/maker/help.ts +59 -57
  33. package/template/src/core/maker/make/controller.ts +25 -22
  34. package/template/src/core/maker/make/helpers.ts +97 -91
  35. package/template/src/core/maker/make/mod.ts +69 -67
  36. package/template/src/core/maker/make/model.ts +16 -14
  37. package/template/src/core/maker/make/module.ts +53 -39
  38. package/template/src/core/maker/make/seeder.ts +23 -21
  39. package/template/src/core/maker/make/test.ts +33 -30
  40. package/template/src/core/maker/mod.ts +85 -83
  41. package/template/src/core/maker/run/mod.ts +134 -132
  42. package/template/src/core/maker/stub.ts +26 -24
  43. package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
  44. package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
  45. package/template/src/core/maker/stubs/facade/facade.stub +21 -0
  46. package/template/src/core/maker/stubs/model/model.stub +10 -8
  47. package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
  48. package/template/src/core/maker/stubs/test/test.stub +9 -7
  49. package/template/src/core/maker/sync-config.ts +93 -94
  50. package/template/src/core/utils/password.ts +29 -27
  51. package/template/src/core/utils/playwright.ts +123 -121
  52. package/template/src/core/utils/queue.ts +68 -66
  53. package/template/src/core/utils/scheduler.ts +62 -60
  54. package/template/src/core/utils/storage.ts +3 -1
  55. package/template/src/core/utils/validation.ts +37 -35
  56. package/template/src/database/schema.ts +2 -0
  57. package/template/src/main.ts +120 -118
  58. package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
  59. package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
  60. package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
  61. package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
  62. package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
  63. package/template/src/modules/app/controllers/demo.controller.ts +120 -118
  64. package/template/src/modules/app/controllers/net.controller.ts +50 -48
  65. package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
  66. package/template/src/modules/app/controllers/storage.controller.ts +231 -229
  67. package/template/src/modules/app/controllers/window.controller.ts +2 -0
  68. package/template/src/modules/app/facade.ts +21 -0
  69. package/template/src/preload.ts +25 -2
  70. package/template/src/ui/src/App.vue +4 -2
  71. package/template/src/ui/src/app.ts +38 -23
  72. package/template/src/ui/src/bindings.d.ts +18 -16
  73. package/template/src/ui/src/components/Button.vue +34 -32
  74. package/template/src/ui/src/components/Checkbox.vue +26 -29
  75. package/template/src/ui/src/components/Input.vue +221 -227
  76. package/template/src/ui/src/components/InputGroup.vue +141 -0
  77. package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
  78. package/template/src/ui/src/components/Modal.vue +65 -55
  79. package/template/src/ui/src/components/Spinner.vue +44 -42
  80. package/template/src/ui/src/components/Switch.vue +62 -65
  81. package/template/src/ui/src/components/TextArea.vue +108 -121
  82. package/template/src/ui/src/components/Toast.vue +55 -56
  83. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
  84. package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
  85. package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
  86. package/template/src/ui/src/components/datatable/index.vue +336 -258
  87. package/template/src/ui/src/env.d.ts +16 -13
  88. package/template/src/ui/src/global.d.ts +21 -2
  89. package/template/src/ui/src/helpers/nformatter.ts +12 -10
  90. package/template/src/ui/src/pages/dashboard/index.vue +690 -687
  91. package/template/src/ui/src/plugins/browserDetect.ts +57 -0
  92. package/template/src/ui/src/plugins/gum.ts +576 -549
  93. package/template/src/ui/src/plugins/pulse.ts +181 -147
  94. package/template/src/ui/src/plugins/routeProgress.ts +89 -0
  95. package/template/src/ui/src/router/index.ts +44 -25
  96. package/template/src/ui/src/stores/example.ts +2 -0
  97. package/template/src/ui/vite.config.ts +40 -38
  98. package/template/src/window/app-menu.ts +89 -87
  99. package/template/src/window/config.ts +14 -12
  100. package/template/src/window/context-menu.ts +23 -21
  101. package/template/src/window/dialogs.ts +92 -90
  102. package/template/src/window/manager.ts +2 -0
  103. package/template/src/window/native.ts +47 -45
  104. package/template/src/window/tray.ts +132 -130
@@ -1,16 +1,18 @@
1
- /**
2
- * bindings.d.ts - types the Electron `bindings` global exposed by preload.
3
- *
4
- * `bindings` is a Proxy: any `bindings.<name>` access yields a function that
5
- * invokes `deskapp:<name>` in the main process via IPC and returns a Promise.
6
- * Backend controllers register handlers under `<module>.<controller>.<handler>`
7
- * (see src/core/api/registry.ts).
8
- */
9
-
10
- export interface Bindings {
11
- [name: string]: (...args: unknown[]) => Promise<unknown>;
12
- }
13
-
14
- declare global {
15
- const bindings: Bindings;
16
- }
1
+ // ./src/ui/src/bindings.d.ts
2
+
3
+ /**
4
+ * bindings.d.ts - types the Electron `bindings` global exposed by preload.
5
+ *
6
+ * `bindings` is a Proxy: any `bindings.<name>` access yields a function that
7
+ * invokes `deskapp:<name>` in the main process via IPC and returns a Promise.
8
+ * Backend controllers register handlers under `<module>.<controller>.<handler>`
9
+ * (see src/core/api/registry.ts).
10
+ */
11
+
12
+ export interface Bindings {
13
+ [name: string]: (...args: unknown[]) => Promise<unknown>;
14
+ }
15
+
16
+ declare global {
17
+ const bindings: Bindings;
18
+ }
@@ -1,32 +1,34 @@
1
- <template>
2
- <button class="shadow-none" :type="props.type" v-bind="$attrs">
3
- <slot v-if="hasDefaultSlot"></slot>
4
- <template v-else>
5
- <span v-if="props.label" class="text-capitalize" :class="{ 'me-1': props.icon }">
6
- {{ props.label }}
7
- </span>
8
- <span v-if="props.icon"><i :class="props.icon"></i></span>
9
- </template>
10
- </button>
11
- </template>
12
-
13
- <script setup lang="ts">
14
- import { computed, useSlots } from "vue";
15
-
16
- interface ButtonProps {
17
- label?: string;
18
- icon?: string;
19
- type?: "button" | "submit" | "reset";
20
- }
21
-
22
- defineOptions({ name: "Button", inheritAttrs: false });
23
-
24
- const slots = useSlots();
25
- const props = withDefaults(defineProps<ButtonProps>(), {
26
- type: "button"
27
- });
28
-
29
- const hasDefaultSlot = computed(() => Boolean(slots.default?.().length));
30
- </script>
31
-
32
- <style lang="scss" scoped></style>
1
+ <!-- ./src/ui/src/components/Button.vue -->
2
+
3
+ <template>
4
+ <button class="shadow-none" :type="props.type" v-bind="$attrs">
5
+ <slot v-if="hasDefaultSlot"></slot>
6
+ <template v-else>
7
+ <span v-if="props.label" class="text-capitalize" :class="{ 'me-1': props.icon }">
8
+ {{ props.label }}
9
+ </span>
10
+ <span v-if="props.icon"><i :class="props.icon"></i></span>
11
+ </template>
12
+ </button>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { computed, useSlots } from "vue";
17
+
18
+ interface ButtonProps {
19
+ label?: string;
20
+ icon?: string;
21
+ type?: "button" | "submit" | "reset";
22
+ }
23
+
24
+ defineOptions({ name: "Button", inheritAttrs: false });
25
+
26
+ const slots = useSlots();
27
+ const props = withDefaults(defineProps<ButtonProps>(), {
28
+ type: "button"
29
+ });
30
+
31
+ const hasDefaultSlot = computed(() => Boolean(slots.default?.().length));
32
+ </script>
33
+
34
+ <style lang="scss" scoped></style>
@@ -1,29 +1,26 @@
1
- <template>
2
- <div class="form-check mb-0" :class="props.topclass">
3
- <input
4
- :id="String(props.id)"
5
- v-model="model"
6
- class="form-check-input shadow-none border-secondary"
7
- type="checkbox"
8
- v-bind="$attrs" />
9
- <label v-if="props.label" class="form-check-label" :for="String(props.id)">{{ props.label }}</label>
10
- </div>
11
- </template>
12
-
13
- <script setup lang="ts">
14
- defineOptions({ name: "Checkbox", inheritAttrs: false });
15
-
16
- interface CheckboxProps {
17
- id?: string | number;
18
- label?: string;
19
- topclass?: string;
20
- }
21
-
22
- const props = defineProps<CheckboxProps>();
23
-
24
- type CheckboxModel = boolean | Array<string | number>;
25
-
26
- const model = defineModel<CheckboxModel>({ default: false });
27
- </script>
28
-
29
- <style lang="scss" scoped></style>
1
+ <!-- ./src/ui/src/components/Checkbox.vue -->
2
+
3
+ <template>
4
+ <div class="form-check mb-0" :class="props.topclass">
5
+ <input :id="String(props.id)" v-model="model" class="form-check-input shadow-none" type="checkbox" v-bind="$attrs">
6
+ <label v-if="props.label" class="form-check-label" :for="String(props.id)">{{ props.label }}</label>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ defineOptions({ name: "Checkbox", inheritAttrs: false });
12
+
13
+ interface CheckboxProps {
14
+ id?: string | number;
15
+ label?: string;
16
+ topclass?: string;
17
+ }
18
+
19
+ const props = defineProps<CheckboxProps>();
20
+
21
+ type CheckboxModel = boolean | Array<string | number>;
22
+
23
+ const model = defineModel<CheckboxModel>({ default: false });
24
+ </script>
25
+
26
+ <style lang="scss" scoped></style>
@@ -1,227 +1,221 @@
1
- <template>
2
- <div :class="topclass">
3
- <div class="position-relative">
4
- <label
5
- :for="inputId"
6
- class="d-flex align-items-center mb-1"
7
- :class="{ 'd-none': !inputLabel }">
8
- <div class="position-relative">
9
- <span class="text-capitalize" v-html="inputLabel"></span>
10
- <span
11
- class="position-absolute text-danger rounded-circle bg-danger must"
12
- :class="{ 'd-none': !props.must }"></span>
13
- </div>
14
- <div
15
- class="text-end ms-auto text-primary fw-semibold"
16
- :class="{ 'd-none': !props.hood }"
17
- style="font-size: 12px; margin-top: 0.15rem"
18
- v-html="hoodHtml"></div>
19
- </label>
20
- <input
21
- ref="inputRef"
22
- class="form-control"
23
- :value="props.modelValue"
24
- :maxlength="maxLengthAttr"
25
- :readonly="props.readonly"
26
- v-bind="$attrs"
27
- :autocomplete="inputAutocomplete"
28
- @input="updateModel" />
29
- <div
30
- class="position-absolute bottom-0 end-0 pe-1 text-secondary max"
31
- :class="{ 'd-none': !max }">
32
- {{ maxCounter }}
33
- </div>
34
- </div>
35
- <div
36
- :id="`${inputId}Help`"
37
- class="form-text mt-1 text-danger"
38
- :class="{ 'd-none': !props.err }">
39
- {{ props.err }}
40
- </div>
41
- </div>
42
- </template>
43
-
44
- <script setup lang="ts">
45
- import { computed, nextTick, onMounted, ref, useAttrs } from "vue";
46
-
47
- const $attrs = useAttrs();
48
- const inputRef = ref<HTMLInputElement | null>(null);
49
- type InputCategory =
50
- | "number"
51
- | "decimal"
52
- | "+decimal-"
53
- | "mobile"
54
- | "tax-period"
55
- | "bin"
56
- | "challan-number"
57
- | string;
58
-
59
- interface InputProps {
60
- focus?: boolean;
61
- must?: boolean;
62
- err?: string | boolean;
63
- modelValue?: string | number;
64
- category?: InputCategory;
65
- hood?: string | boolean | number;
66
- readonly?: boolean;
67
- }
68
-
69
- const props = withDefaults(defineProps<InputProps>(), {
70
- err: false,
71
- modelValue: ""
72
- });
73
-
74
- const topclass = computed(() => ($attrs.topclass as string | undefined) || "mb-2");
75
- const inputId = computed(() => ($attrs.id as string | undefined) || "");
76
- const inputLabel = computed(() => ($attrs.label as string | undefined) || "");
77
- const inputType = computed(() => ($attrs.type as string | undefined) || "text");
78
-
79
- const max = computed<number | null>(() => {
80
- const raw = $attrs.maxlength as string | number | undefined;
81
- return raw != null ? Number(raw) : null;
82
- });
83
-
84
- const inputAutocomplete = computed(() => {
85
- const attrAutocomplete = $attrs.autocomplete as string | undefined;
86
- if (attrAutocomplete) {
87
- return attrAutocomplete;
88
- }
89
- return ["number", "decimal"].includes(props.category ?? "") ? "off" : "on";
90
- });
91
-
92
- const maxLengthAttr = computed<number | undefined>(() => max.value ?? undefined);
93
-
94
- const hoodHtml = computed(() =>
95
- props.hood === false || props.hood == null ? "" : String(props.hood)
96
- );
97
-
98
- const maxCounter = computed(() => {
99
- if (max.value == null) {
100
- return "";
101
- }
102
-
103
- return max.value - String(props.modelValue).length;
104
- });
105
-
106
- const emit = defineEmits<(event: "update:modelValue", value: string | number) => void>();
107
- const updateModel = (e: Event) => {
108
- const target = e.target as HTMLInputElement;
109
-
110
- if (props.category === "number") {
111
- emit("update:modelValue", (target.value = target.value.replace(/[^\d]/gi, "")));
112
- } else if (props.category === "decimal") {
113
- let val = target.value;
114
-
115
- // Remove everything except digits, decimal point, and minus sign
116
- val = val.replace(/[^0-9.]/g, "");
117
-
118
- // Allow only one decimal point
119
- const parts = val.split(".");
120
- if (parts.length > 2) {
121
- val = `${parts[0]}.${parts.slice(1).join("")}`;
122
- }
123
-
124
- emit("update:modelValue", (target.value = val));
125
- } else if (props.category === "+decimal-") {
126
- let val = target.value;
127
-
128
- // Remove everything except digits, decimal point, and minus sign
129
- val = val.replace(/[^0-9.-]/g, ""); // if need minus sign
130
-
131
- // Move minus sign to the front if it exists anywhere
132
- const isNegative = val.includes("-");
133
- val = val.replace(/-/g, ""); // remove all minus signs
134
- if (isNegative) {
135
- val = `-${val}`;
136
- }
137
-
138
- // Allow only one decimal point
139
- const parts = val.split(".");
140
- if (parts.length > 2) {
141
- val = `${parts[0]}.${parts.slice(1).join("")}`;
142
- }
143
-
144
- emit("update:modelValue", (target.value = val));
145
- } else if (props.category === "mobile") {
146
- let digits = target.value.replace(/[^\d]/g, ""); // only digits
147
- let val = digits;
148
- if (target.value.includes("+")) {
149
- val = `+${digits}`;
150
- }
151
- emit("update:modelValue", (target.value = val));
152
- } else if (props.category === "tax-period") {
153
- let val = target.value.replace(/[^\d-]/g, ""); // Only numbers and hyphen
154
- val = val.replace(/-/g, ""); // Remove all hyphens
155
- val = val.slice(0, 6); // Only 6 digits (YYYYMM)
156
-
157
- if (val.length > 4) {
158
- let year = val.slice(0, 4);
159
- let month = val.slice(4, 6);
160
-
161
- // Only correct if both month digits entered
162
- if (month.length === 2) {
163
- let m = parseInt(month, 10);
164
- // Clamp month between 1 and 12
165
- if (m < 1) m = 1;
166
- if (m > 12) m = 12;
167
- // Always pad to 2 digits
168
- month = m.toString().padStart(2, "0");
169
- }
170
-
171
- val = `${year}-${month}`;
172
- }
173
-
174
- emit("update:modelValue", (target.value = val));
175
- } else if (props.category === "bin") {
176
- let digits = target.value.replace(/[^\d]/g, "");
177
- digits = digits.slice(0, 14);
178
- let formatted = digits;
179
- if (digits.length > 9) {
180
- formatted = `${digits.slice(0, 9)}-${digits.slice(9, 14)}`;
181
- }
182
- emit("update:modelValue", (target.value = formatted));
183
- } else if (props.category === 'echallan-number') {
184
- // Format: V + 9 digits (V000517226)
185
- let raw = (target.value || '').toUpperCase();
186
-
187
- // keep only digits, but allow V (we’ll force V at start)
188
- let digits = raw.replace(/[^\d]/g, '').slice(0, 9);
189
-
190
- // always prefix V
191
- let formatted = `V ${digits}`;
192
-
193
- emit('update:modelValue', (target.value = formatted));
194
-
195
- } else if (props.category === "challan-number") {
196
- let digits = target.value.replace(/[^\d]/g, "");
197
- digits = digits.slice(0, 16);
198
- let formatted = digits;
199
- if (digits.length > 4) {
200
- formatted = `${digits.slice(0, 4)}-${digits.slice(4, 16)}`;
201
- }
202
- emit("update:modelValue", (target.value = formatted));
203
- } else {
204
- emit("update:modelValue", target.value);
205
- }
206
- };
207
-
208
- onMounted(() => {
209
- const shouldFocus = props.focus !== false && props.focus !== undefined;
210
- if (!shouldFocus) return;
211
-
212
- nextTick(() => inputRef.value?.focus());
213
- });
214
- </script>
215
-
216
- <style lang="scss" scoped>
217
- .must {
218
- width: 4px;
219
- height: 4px;
220
- margin-left: 2px;
221
- margin-top: 5px;
222
- }
223
-
224
- .max {
225
- font-size: 0.6rem;
226
- }
227
- </style>
1
+ <!-- ./src/ui/src/components/Input.vue -->
2
+
3
+ <template>
4
+ <div :class="topclass">
5
+ <div class="position-relative">
6
+ <label :for="inputId" class="d-flex align-items-center mb-1" :class="{ 'd-none': !inputLabel }">
7
+ <div class="position-relative">
8
+ <span class="text-capitalize" v-html="inputLabel"></span>
9
+ <span class="position-absolute text-danger rounded-circle bg-danger must" :class="{ 'd-none': !props.must }"></span>
10
+ </div>
11
+ <div
12
+ class="text-end ms-auto text-primary fw-semibold"
13
+ :class="{ 'd-none': !props.hood }"
14
+ style="font-size: 12px; margin-top: 0.15rem"
15
+ v-html="hoodHtml"
16
+ ></div>
17
+ </label>
18
+ <input
19
+ ref="inputRef"
20
+ class="form-control shadow-none"
21
+ :value="props.modelValue"
22
+ :maxlength="maxLengthAttr"
23
+ :readonly="props.readonly"
24
+ v-bind="$attrs"
25
+ :autocomplete="inputAutocomplete"
26
+ @input="updateModel"
27
+ >
28
+ <div class="position-absolute bottom-0 end-0 pe-1 text-secondary max" :class="{ 'd-none': !max }">
29
+ {{ maxCounter }}
30
+ </div>
31
+ </div>
32
+ <div :id="`${inputId}Help`" class="form-text mt-1 text-danger" :class="{ 'd-none': !props.err }">
33
+ {{ props.err }}
34
+ </div>
35
+ </div>
36
+ </template>
37
+
38
+ <script setup lang="ts">
39
+ import { computed, nextTick, onMounted, ref, useAttrs } from "vue";
40
+ import { browserDetect } from "@/ui/plugins/browserDetect";
41
+
42
+ defineOptions({ name: "Input", inheritAttrs: false });
43
+
44
+ const { isFirefox } = browserDetect;
45
+
46
+ const $attrs = useAttrs();
47
+ const inputRef = ref<HTMLInputElement | null>(null);
48
+ type InputCategory = "number" | "decimal" | "+decimal-" | "mobile" | "tax-period" | "bin" | "challan-number" | string;
49
+
50
+ interface InputProps {
51
+ focus?: boolean;
52
+ must?: boolean;
53
+ err?: string | boolean;
54
+ modelValue?: string | number;
55
+ category?: InputCategory;
56
+ hood?: string | boolean | number;
57
+ readonly?: boolean;
58
+ }
59
+
60
+ const props = withDefaults(defineProps<InputProps>(), {
61
+ err: false,
62
+ modelValue: ""
63
+ });
64
+
65
+ const topclass = computed(() => ($attrs.topclass as string | undefined) || "mb-2");
66
+ const inputId = computed(() => ($attrs.id as string | undefined) || "");
67
+ const inputLabel = computed(() => ($attrs.label as string | undefined) || "");
68
+ const inputType = computed(() => ($attrs.type as string | undefined) || "text");
69
+
70
+ const max = computed<number | null>(() => {
71
+ const raw = $attrs.maxlength as string | number | undefined;
72
+ return raw != null ? Number(raw) : null;
73
+ });
74
+
75
+ const inputAutocomplete = computed(() => {
76
+ const attrAutocomplete = $attrs.autocomplete as string | undefined;
77
+ if (attrAutocomplete) {
78
+ return attrAutocomplete;
79
+ }
80
+ return ["number", "decimal"].includes(props.category ?? "") ? "off" : "on";
81
+ });
82
+
83
+ const maxLengthAttr = computed<number | undefined>(() => max.value ?? undefined);
84
+
85
+ const hoodHtml = computed(() => (props.hood === false || props.hood == null ? "" : String(props.hood)));
86
+
87
+ const maxCounter = computed(() => {
88
+ if (max.value == null) {
89
+ return "";
90
+ }
91
+
92
+ if (!isFirefox && inputType.value === "month") {
93
+ return "";
94
+ }
95
+
96
+ return max.value - String(props.modelValue).length;
97
+ });
98
+
99
+ const emit = defineEmits<(event: "update:modelValue", value: string | number) => void>();
100
+ const updateModel = (e: Event) => {
101
+ const target = e.target as HTMLInputElement;
102
+
103
+ if (props.category === "number") {
104
+ emit("update:modelValue", (target.value = target.value.replace(/[^\d]/gi, "")));
105
+ } else if (props.category === "decimal") {
106
+ let val = target.value;
107
+
108
+ // Remove everything except digits, decimal point, and minus sign
109
+ val = val.replace(/[^0-9.]/g, "");
110
+
111
+ // Allow only one decimal point
112
+ const parts = val.split(".");
113
+ if (parts.length > 2) {
114
+ val = `${parts[0]}.${parts.slice(1).join("")}`;
115
+ }
116
+
117
+ emit("update:modelValue", (target.value = val));
118
+ } else if (props.category === "+decimal-") {
119
+ let val = target.value;
120
+
121
+ // Remove everything except digits, decimal point, and minus sign
122
+ val = val.replace(/[^0-9.-]/g, ""); // if need minus sign
123
+
124
+ // Move minus sign to the front if it exists anywhere
125
+ const isNegative = val.includes("-");
126
+ val = val.replace(/-/g, ""); // remove all minus signs
127
+ if (isNegative) {
128
+ val = `-${val}`;
129
+ }
130
+
131
+ // Allow only one decimal point
132
+ const parts = val.split(".");
133
+ if (parts.length > 2) {
134
+ val = `${parts[0]}.${parts.slice(1).join("")}`;
135
+ }
136
+
137
+ emit("update:modelValue", (target.value = val));
138
+ } else if (props.category === "mobile") {
139
+ let digits = target.value.replace(/[^\d]/g, ""); // only digits
140
+ let val = digits;
141
+ if (target.value.includes("+")) {
142
+ val = `+${digits}`;
143
+ }
144
+ emit("update:modelValue", (target.value = val));
145
+ } else if (props.category === "tax-period") {
146
+ let val = target.value.replace(/[^\d-]/g, ""); // Only numbers and hyphen
147
+ val = val.replace(/-/g, ""); // Remove all hyphens
148
+ val = val.slice(0, 6); // Only 6 digits (YYYYMM)
149
+
150
+ if (val.length > 4) {
151
+ let year = val.slice(0, 4);
152
+ let month = val.slice(4, 6);
153
+
154
+ // Only correct if both month digits entered
155
+ if (month.length === 2) {
156
+ let m = parseInt(month, 10);
157
+ // Clamp month between 1 and 12
158
+ if (m < 1) m = 1;
159
+ if (m > 12) m = 12;
160
+ // Always pad to 2 digits
161
+ month = m.toString().padStart(2, "0");
162
+ }
163
+
164
+ val = `${year}-${month}`;
165
+ }
166
+
167
+ emit("update:modelValue", (target.value = val));
168
+ } else if (props.category === "bin") {
169
+ let digits = target.value.replace(/[^\d]/g, "");
170
+ digits = digits.slice(0, 14);
171
+ let formatted = digits;
172
+ if (digits.length > 9) {
173
+ formatted = `${digits.slice(0, 9)}-${digits.slice(9, 14)}`;
174
+ }
175
+ emit("update:modelValue", (target.value = formatted));
176
+ } else if (props.category === "echallan-number") {
177
+ // Format: V + 9 digits (V000517226)
178
+ let raw = (target.value || "").toUpperCase();
179
+
180
+ // keep only digits, but allow V (we’ll force V at start)
181
+ let digits = raw.replace(/[^\d]/g, "").slice(0, 9);
182
+
183
+ // always prefix V
184
+ let formatted = `V${digits}`;
185
+
186
+ emit("update:modelValue", (target.value = formatted));
187
+ } else if (props.category === "challan-number") {
188
+ let digits = target.value.replace(/[^\d]/g, "");
189
+ digits = digits.slice(0, 16);
190
+ let formatted = digits;
191
+ if (digits.length > 4) {
192
+ formatted = `${digits.slice(0, 4)}-${digits.slice(4, 16)}`;
193
+ }
194
+ emit("update:modelValue", (target.value = formatted));
195
+ } else {
196
+ emit("update:modelValue", target.value);
197
+ }
198
+ };
199
+
200
+ onMounted(async () => {
201
+ const shouldFocus = props.focus !== false && props.focus !== undefined;
202
+ if (!shouldFocus) return;
203
+
204
+ await nextTick();
205
+ // preventScroll: focusing inside a modal must not scroll the modal/page
206
+ inputRef.value?.focus({ preventScroll: true });
207
+ });
208
+ </script>
209
+
210
+ <style lang="scss" scoped>
211
+ .must {
212
+ width: 4px;
213
+ height: 4px;
214
+ margin-left: 2px;
215
+ margin-top: 5px;
216
+ }
217
+
218
+ .max {
219
+ font-size: 0.6rem;
220
+ }
221
+ </style>