@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,258 +1,336 @@
1
- <template>
2
- <div class="card border">
3
- <div class="card-header" :class="{ 'd-none': !(props.removable || props.searchable || props.optionable) }">
4
- <div class="row align-items-center gx-1">
5
- <div class="col-12 col-md-3">
6
- <SelectOption :is-options="props.optionable" :option="props.option" :selectedoption="selectedoption"
7
- @change="handleSizeChange" />
8
- </div>
9
- <div class="col-12 col-md-9">
10
- <slot name="extra-tools"></slot>
11
- <div class="d-flex align-items-center justify-content-center justify-content-md-end">
12
- <div v-if="checked.checkcolumn.length > 0" class="me-1" :class="{ 'd-none': !props.removable }">
13
- <Button type="button" class="btn btn-outline-danger" @click.prevent="remove">
14
- <i class="bi bi-trash"></i>
15
- </Button>
16
- </div>
17
- <div class="d-flex align-items-center" :class="{ 'd-none': !props.searchable }">
18
- <Button class="btn btn-outline-secondary rounded-0 rounded-start" type="button" @click="searchMe">
19
- <i class="bi bi-search"></i>
20
- </Button>
21
- <Input v-model="searchdata" type="text" class="w-auto shadow-none rounded-0 rounded-end" topclass="mb-0"
22
- placeholder="Search..." @keyup.enter="searchMe" @keyup.delete="searchMe" />
23
- </div>
24
- </div>
25
- </div>
26
- </div>
27
- </div>
28
- <div class="card-body">
29
- <slot name="extra"></slot>
30
- <div class="table-responsive">
31
- <table
32
- class="table table-bordered table-striped border-custom table-sm align-middle m-0 datatable no-shrink-table">
33
- <slot name="customhead"></slot>
34
- <thead :class="{ 'd-none': slots.customhead }">
35
- <tr>
36
- <th class="align-middle" :class="{ 'd-none': !props.removable || !state.current_page }">
37
- <Checkbox v-model="checked.check" topclass="ms-2" :value="checked.check" :disabled="props.disabled"
38
- @click="checkAll" />
39
- </th>
40
- <th class="text-center align-middle" :class="{ 'd-none': !props.countable }">#</th>
41
- <slot name="thead"></slot>
42
- </tr>
43
- </thead>
44
-
45
- <slot name="custombody"></slot>
46
- <tbody :class="{ 'd-none': slots.custombody }">
47
- <tr v-for="(dt, i) in tableRows" :key="`${dt.id}-${i}`">
48
- <td class="align-middle" :class="{ 'd-none': !props.removable || !state.current_page }">
49
- <Checkbox v-model="checked.checkcolumn" topclass="ms-2" :value="dt.id" :disabled="props.disabled"
50
- @change="updateChecked" />
51
- </td>
52
- <td class="text-center align-middle" :class="{ 'd-none': !props.countable }">
53
- {{
54
- state.current_page
55
- ? state.per_page * (state.current_page - 1) + (i + 1)
56
- : i + 1
57
- }}
58
- </td>
59
- <slot name="tbody" :td="dt"></slot>
60
- </tr>
61
- </tbody>
62
- </table>
63
- </div>
64
- </div>
65
- <div class="card-footer" :class="{ 'd-none': state.total <= state.data.length }">
66
- <Pagination :data="state" @change="handlePageChange" />
67
- </div>
68
- </div>
69
- </template>
70
-
71
- <script setup lang="ts">
72
- import { debounce } from "lodash-es";
73
- import SelectOption from "./SelectOpption.vue";
74
- import Button from "@/ui/components/Button.vue";
75
- import Input from "@/ui/components/Input.vue";
76
- import Checkbox from "@/ui/components/Checkbox.vue";
77
- import Pagination from "./Pagination.vue";
78
- import { computed, reactive, ref, useSlots, watchEffect } from "vue";
79
- import { useGum, type GumTransport } from "@/ui/plugins/gum";
80
-
81
- interface DataRow {
82
- id: string | number;
83
- [key: string]: any;
84
- }
85
-
86
- interface DataPageState {
87
- data: DataRow[];
88
- current_page: number;
89
- last_page: number;
90
- per_page: number;
91
- total: number;
92
- from: number | null;
93
- to: number | null;
94
- path: string;
95
- }
96
-
97
- interface DataTableProps {
98
- path: string;
99
- search?: string;
100
- loop?: DataRow[] | false;
101
- option?: Array<string | number>;
102
- removable?: boolean;
103
- countable?: boolean;
104
- searchable?: boolean;
105
- optionable?: boolean;
106
- disabled?: boolean;
107
- /** Per-table transport override: "bindings" (SQLite, default from GumPlugin) or "http". */
108
- transport?: GumTransport;
109
- /** HTTP transport only: base URL prepended to `path`. */
110
- baseURL?: string;
111
- }
112
-
113
- const props = withDefaults(defineProps<DataTableProps>(), {
114
- search: "",
115
- loop: false,
116
- option: () => [10, 25, 50],
117
- removable: true,
118
- countable: true,
119
- searchable: true,
120
- optionable: true,
121
- disabled: false
122
- });
123
- const gum = useGum();
124
-
125
- const slots = useSlots();
126
-
127
- const emit = defineEmits<{ (event: "remove", value: Array<string | number>): void; }>();
128
-
129
- const state = reactive<DataPageState>({
130
- data: [],
131
- current_page: 1,
132
- last_page: 1,
133
- per_page: Number(props.option[0]) || 15,
134
- total: 0,
135
- from: null,
136
- to: null,
137
- path: props.path
138
- });
139
-
140
- const loading = ref(false);
141
-
142
- // checkbox select
143
- let checked = reactive<{ check: boolean; checkcolumn: Array<string | number>; }>({
144
- check: false,
145
- checkcolumn: []
146
- });
147
- const checkAll = () => {
148
- if (!checked.check) {
149
- state.data.forEach((dt: DataRow) => {
150
- if (!checked.checkcolumn.includes(dt.id)) {
151
- checked.checkcolumn.push(dt.id);
152
- }
153
- });
154
- } else {
155
- checked.checkcolumn = [];
156
- }
157
- };
158
- const updateChecked = () => checked.checkcolumn.length === state.data.length ? (checked.check = true) : (checked.check = false);
159
-
160
- // remove from parent
161
- const remove = () => {
162
- emit("remove", checked.checkcolumn);
163
- checked.check = false;
164
- };
165
-
166
- // for change data size show
167
- const selectedoption = ref<string | number | undefined>(Number(props.option[0]));
168
- const tableRows = computed<DataRow[]>(() => (props.loop ? props.loop : state.data));
169
-
170
- // search data
171
- const searchdata = ref(props.search || "");
172
- const searchMe = debounce(() => {
173
- load(1);
174
- }, 500);
175
-
176
- // fetch directly in-process; no router navigation/scroll restore (gum `navigate: false`)
177
- const load = async (page?: number) => {
178
- loading.value = true;
179
- try {
180
- const res = await gum.get(props.path, {
181
- navigate: false,
182
- transport: props.transport,
183
- baseURL: props.baseURL,
184
- query: {
185
- page: page ?? state.current_page,
186
- size: selectedoption.value,
187
- search: searchdata.value
188
- }
189
- });
190
- const envelope = (res?.data ?? {}) as Partial<DataPageState>;
191
- state.data = envelope.data ?? [];
192
- state.current_page = Number(envelope.current_page) || 1;
193
- state.last_page = Number(envelope.last_page) || 1;
194
- state.per_page = Number(envelope.per_page) || Number(selectedoption.value) || 15;
195
- state.total = Number(envelope.total) || 0;
196
- state.from = envelope.from ?? null;
197
- state.to = envelope.to ?? null;
198
- if (envelope.path) state.path = envelope.path;
199
- checked.checkcolumn = [];
200
- checked.check = false;
201
- } finally {
202
- loading.value = false;
203
- }
204
- };
205
-
206
- const handleSizeChange = (value: string | number) => {
207
- selectedoption.value = value;
208
- load(1);
209
- };
210
-
211
- const handlePageChange = (pageNo: string | number) => {
212
- let p = parseInt(String(pageNo), 10);
213
- if (Number.isNaN(p) || p < 1) p = 1;
214
- if (p > state.last_page) p = state.last_page;
215
- load(p);
216
- };
217
-
218
- // watch instance
219
- watchEffect(() => {
220
- if (props.option.length) {
221
- const match = props.option.find((x) => Number(x) === Number(state.per_page)) ?? props.option[0];
222
- selectedoption.value = match;
223
- }
224
- searchdata.value = props.search || "";
225
- });
226
-
227
- // initial + subsequent loads when path changes
228
- watchEffect(() => {
229
- if (props.path) load();
230
- });
231
-
232
- defineExpose({ load, state, loading });
233
- </script>
234
-
235
- <style lang="scss" scoped>
236
- .border-custom {
237
- border-color: var(--dk-table-border, #cccccc) !important;
238
- }
239
-
240
- .no-shrink-table th,
241
- .no-shrink-table td {
242
- white-space: nowrap;
243
- }
244
-
245
- /* By default (large screens and up) do not force a min-width:
246
- allow table to size normally so no horizontal scrollbar on large screens */
247
- @media (min-width: 992px) {
248
- .no-shrink-table {
249
- min-width: 0;
250
- }
251
- }
252
-
253
- @media (max-width: 991.98px) {
254
- .no-shrink-table {
255
- min-width: 1000px;
256
- }
257
- }
258
- </style>
1
+ <!-- ./src/ui/src/components/datatable/index.vue -->
2
+
3
+ <template>
4
+ <div class="card border">
5
+ <div class="card-header" :class="{ 'd-none': !(props.removable || props.searchable || props.optionable) }">
6
+ <div class="row align-items-center gx-1">
7
+ <div class="col-12 col-md-3">
8
+ <SelectOption :is-options="props.optionable" :option="props.option" :selectedoption="selectedoption" @change="handleSizeChange" />
9
+ </div>
10
+ <div class="col-12 col-md-9">
11
+ <slot name="extra-tools"></slot>
12
+ <div class="d-flex align-items-center justify-content-center justify-content-md-end">
13
+ <div v-if="checked.checkcolumn.length > 0" class="me-1" :class="{ 'd-none': !props.removable }">
14
+ <Button type="button" class="btn btn-outline-danger" @click.prevent="remove">
15
+ <i class="bi bi-trash"></i>
16
+ </Button>
17
+ </div>
18
+ <div class="d-flex align-items-center" :class="{ 'd-none': !props.searchable }">
19
+ <Button class="btn btn-outline-secondary rounded-0 rounded-start" type="button" @click="searchMe">
20
+ <i class="bi bi-search"></i>
21
+ </Button>
22
+ <Input
23
+ v-model="searchdata"
24
+ type="text"
25
+ class="w-auto shadow-none rounded-0 rounded-end"
26
+ topclass="mb-0"
27
+ placeholder="Search..."
28
+ @keyup.enter="searchMe"
29
+ @keyup.delete="searchMe"
30
+ />
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <div class="card-body">
37
+ <slot name="extra"></slot>
38
+ <div class="table-responsive">
39
+ <table class="table table-bordered table-striped border-custom table-sm align-middle m-0 datatable no-shrink-table">
40
+ <slot name="customhead"></slot>
41
+ <thead :class="{ 'd-none': slots.customhead }">
42
+ <tr>
43
+ <th class="align-middle" :class="{ 'd-none': !props.removable || !view.current_page }">
44
+ <Checkbox v-model="checked.check" topclass="ms-2" :value="checked.check" :disabled="props.disabled" @click="checkAll" />
45
+ </th>
46
+ <th class="text-center align-middle" :class="{ 'd-none': !props.countable }">#</th>
47
+ <slot name="thead"></slot>
48
+ </tr>
49
+ </thead>
50
+
51
+ <slot name="custombody"></slot>
52
+ <tbody :class="{ 'd-none': slots.custombody }">
53
+ <tr v-for="(dt, i) in tableRows" :key="`${dt.id}-${i}`">
54
+ <td class="align-middle" :class="{ 'd-none': !props.removable || !view.current_page }">
55
+ <Checkbox v-model="checked.checkcolumn" topclass="ms-2" :value="dt.id" :disabled="props.disabled" @change="updateChecked" />
56
+ </td>
57
+ <td class="text-center align-middle" :class="{ 'd-none': !props.countable }">
58
+ {{ view.current_page ? view.per_page * (view.current_page - 1) + (i + 1) : i + 1 }}
59
+ </td>
60
+ <slot name="tbody" :td="dt"></slot>
61
+ </tr>
62
+ </tbody>
63
+ </table>
64
+ </div>
65
+ </div>
66
+ <div class="card-footer" :class="{ 'd-none': view.total <= view.data.length }">
67
+ <Pagination :data="view" @change="handlePageChange" />
68
+ </div>
69
+ </div>
70
+ </template>
71
+
72
+ <script setup lang="ts">
73
+ import { debounce } from "lodash-es";
74
+ import { computed, reactive, ref, useSlots, watch, watchEffect } from "vue";
75
+ import Button from "@/ui/components/Button.vue";
76
+ import Checkbox from "@/ui/components/Checkbox.vue";
77
+ import Input from "@/ui/components/Input.vue";
78
+ import { type GumTransport, useGum } from "@/ui/plugins/gum";
79
+ import Pagination from "./Pagination.vue";
80
+ import SelectOption from "./SelectOpption.vue";
81
+
82
+ interface DataRow {
83
+ id: string | number;
84
+ [key: string]: any;
85
+ }
86
+
87
+ interface DataPageState {
88
+ data: DataRow[];
89
+ current_page: number;
90
+ last_page: number;
91
+ per_page: number;
92
+ total: number;
93
+ from: number | null;
94
+ to: number | null;
95
+ path: string;
96
+ }
97
+
98
+ interface DataTableProps {
99
+ /**
100
+ * Self-fetch mode: binding name (`app.demo.table`) or REST endpoint that returns
101
+ * the paginate envelope. The table owns its state and reloads when `path` changes.
102
+ */
103
+ path?: string;
104
+ /**
105
+ * Parent-owned mode: the paginate envelope (e.g. a Pinia store's list). When set,
106
+ * the table renders it instead of fetching `path`, so the page owns the rows.
107
+ */
108
+ data?: Partial<DataPageState> | null;
109
+ /**
110
+ * Fetcher mode: the built-in controls (search, size, page) call this instead of
111
+ * self-fetching `path` — e.g. `:fetcher="store.index"`. Called through `gum.getWith`.
112
+ */
113
+ fetcher?: (params: Record<string, unknown>) => Promise<unknown>;
114
+ /**
115
+ * Extra query params merged into every fetch/control call, so filters in the URL
116
+ * or on the page survive a search or a page change.
117
+ */
118
+ filters?: Record<string, unknown>;
119
+ search?: string;
120
+ loop?: DataRow[] | false;
121
+ option?: Array<string | number>;
122
+ removable?: boolean;
123
+ countable?: boolean;
124
+ searchable?: boolean;
125
+ optionable?: boolean;
126
+ disabled?: boolean;
127
+ /** Per-table transport override: "bindings" (SQLite, default from GumPlugin) or "http". */
128
+ transport?: GumTransport;
129
+ /** HTTP transport only: base URL prepended to `path`. */
130
+ baseURL?: string;
131
+ }
132
+
133
+ const props = withDefaults(defineProps<DataTableProps>(), {
134
+ filters: () => ({}),
135
+ search: "",
136
+ loop: false,
137
+ option: () => [10, 25, 50],
138
+ removable: true,
139
+ countable: true,
140
+ searchable: true,
141
+ optionable: true,
142
+ disabled: false
143
+ });
144
+ const gum = useGum();
145
+
146
+ const slots = useSlots();
147
+
148
+ const emit = defineEmits<(event: "remove", value: Array<string | number>) => void>();
149
+
150
+ // Internal envelope for self-fetch mode; `view` falls back to the parent's `data` when given.
151
+ const state = reactive<DataPageState>({
152
+ data: [],
153
+ current_page: 1,
154
+ last_page: 1,
155
+ per_page: Number(props.option[0]) || 15,
156
+ total: 0,
157
+ from: null,
158
+ to: null,
159
+ path: props.path ?? ""
160
+ });
161
+
162
+ const loading = ref(false);
163
+
164
+ // checkbox select
165
+ let checked = reactive<{ check: boolean; checkcolumn: Array<string | number> }>({
166
+ check: false,
167
+ checkcolumn: []
168
+ });
169
+ const checkAll = () => {
170
+ if (!checked.check) {
171
+ view.value.data.forEach((dt: DataRow) => {
172
+ if (!checked.checkcolumn.includes(dt.id)) {
173
+ checked.checkcolumn.push(dt.id);
174
+ }
175
+ });
176
+ } else {
177
+ checked.checkcolumn = [];
178
+ }
179
+ };
180
+ const updateChecked = () => (checked.checkcolumn.length === view.value.data.length ? (checked.check = true) : (checked.check = false));
181
+
182
+ // remove from parent
183
+ const remove = () => {
184
+ emit("remove", checked.checkcolumn);
185
+ checked.check = false;
186
+ };
187
+
188
+ // for change data size show
189
+ const selectedoption = ref<string | number | undefined>(Number(props.option[0]));
190
+
191
+ /** Normalize any paginate envelope (the parent's `data` or a fetch result) into a full `DataPageState`. */
192
+ const toEnvelope = (d: Partial<DataPageState>): DataPageState => ({
193
+ data: Array.isArray(d.data) ? d.data : [],
194
+ current_page: Number(d.current_page) || 1,
195
+ last_page: Number(d.last_page) || 1,
196
+ per_page: Number(d.per_page) || Number(selectedoption.value) || 15,
197
+ total: Number(d.total) || 0,
198
+ from: d.from ?? null,
199
+ to: d.to ?? null,
200
+ path: d.path ?? props.path ?? ""
201
+ });
202
+
203
+ /** Pull the paginate envelope out of a fetch result, tolerating a `{ data }` wrapper. */
204
+ const readEnvelope = (value: unknown): Partial<DataPageState> | null => {
205
+ if (!value || typeof value !== "object") return null;
206
+ const v = value as Record<string, unknown>;
207
+ if (Array.isArray(v.data)) return v as Partial<DataPageState>;
208
+ const inner = v.data;
209
+ if (inner && typeof inner === "object" && Array.isArray((inner as Record<string, unknown>).data)) {
210
+ return inner as Partial<DataPageState>;
211
+ }
212
+ return null;
213
+ };
214
+
215
+ /** What the table renders: the parent's `data` when provided, else the internal self-fetch `state`. */
216
+ const view = computed<DataPageState>(() => (props.data ? toEnvelope(props.data) : state));
217
+
218
+ const tableRows = computed<DataRow[]>(() => (props.loop ? props.loop : view.value.data));
219
+
220
+ // search data
221
+ const searchdata = ref(props.search || "");
222
+ const searchMe = debounce(() => {
223
+ load(1);
224
+ }, 500);
225
+
226
+ /** Extra query params merged last, so a caller-supplied filter survives a search/page/size change. */
227
+ const buildQuery = (page?: number): Record<string, unknown> => ({
228
+ page: page ?? view.value.current_page,
229
+ size: selectedoption.value,
230
+ search: searchdata.value,
231
+ ...props.filters
232
+ });
233
+
234
+ /**
235
+ * One entry point for every built-in control (search, size, page).
236
+ *
237
+ * - Fetcher mode (`:fetcher`): calls the parent's fetcher through `gum.getWith` and
238
+ * adopts the envelope it returns (or lets the parent's `data` prop drive the view).
239
+ * - Path mode (default): fetches the binding/endpoint in-process with
240
+ * `gum.get(path, { navigate: false })` and fills the internal `state`.
241
+ */
242
+ const load = async (page?: number) => {
243
+ const query = buildQuery(page);
244
+ loading.value = true;
245
+ try {
246
+ if (props.fetcher) {
247
+ const fetcher = props.fetcher;
248
+ const res = await gum.getWith({
249
+ fetcher: () => fetcher(query),
250
+ query,
251
+ navigate: false,
252
+ transport: props.transport,
253
+ baseURL: props.baseURL
254
+ });
255
+ if (!props.data) Object.assign(state, toEnvelope(readEnvelope(res) ?? {}));
256
+ } else if (props.path) {
257
+ const res = await gum.get(props.path, {
258
+ navigate: false,
259
+ transport: props.transport,
260
+ baseURL: props.baseURL,
261
+ query
262
+ });
263
+ Object.assign(state, toEnvelope(readEnvelope(res) ?? {}));
264
+ }
265
+ checked.checkcolumn = [];
266
+ checked.check = false;
267
+ } finally {
268
+ loading.value = false;
269
+ }
270
+ };
271
+
272
+ const handleSizeChange = (value: string | number) => {
273
+ selectedoption.value = value;
274
+ load(1);
275
+ };
276
+
277
+ const handlePageChange = (pageNo: string | number) => {
278
+ let p = parseInt(String(pageNo), 10);
279
+ if (Number.isNaN(p) || p < 1) p = 1;
280
+ if (p > view.value.last_page) p = view.value.last_page;
281
+ load(p);
282
+ };
283
+
284
+ // watch instance
285
+ watchEffect(() => {
286
+ if (props.option.length) {
287
+ const match = props.option.find((x) => Number(x) === Number(view.value.per_page)) ?? props.option[0];
288
+ selectedoption.value = match;
289
+ }
290
+ searchdata.value = props.search || "";
291
+ });
292
+
293
+ // initial + subsequent loads when `path` changes (self-fetch mode only)
294
+ watch(
295
+ () => props.path,
296
+ () => {
297
+ if (props.path && !props.data && !props.loop) load();
298
+ },
299
+ { immediate: true }
300
+ );
301
+
302
+ // external search term change re-queries from page 1 (self-fetch mode only)
303
+ watch(
304
+ () => props.search,
305
+ () => {
306
+ if (props.path && !props.data && !props.loop) load(1);
307
+ }
308
+ );
309
+
310
+ defineExpose({ load, state, view, loading });
311
+ </script>
312
+
313
+ <style lang="scss" scoped>
314
+ .border-custom {
315
+ border-color: var(--dk-table-border, #cccccc) !important;
316
+ }
317
+
318
+ .no-shrink-table th,
319
+ .no-shrink-table td {
320
+ white-space: nowrap;
321
+ }
322
+
323
+ /* By default (large screens and up) do not force a min-width:
324
+ allow table to size normally so no horizontal scrollbar on large screens */
325
+ @media (min-width: 992px) {
326
+ .no-shrink-table {
327
+ min-width: 0;
328
+ }
329
+ }
330
+
331
+ @media (max-width: 991.98px) {
332
+ .no-shrink-table {
333
+ min-width: 1000px;
334
+ }
335
+ }
336
+ </style>
@@ -1,13 +1,16 @@
1
- /// <reference types="vite/client" />
2
-
3
- declare const md: any & {
4
- __invoke: (name: string, ...args: unknown[]) => Promise<unknown>;
5
- [key: string]: any;
6
- };
7
- /** @deprecated alias for `md` (kept for compatibility) */
8
- declare const bindings: typeof md;
9
-
10
- interface Window {
11
- md: typeof md;
12
- bindings: typeof bindings;
13
- }
1
+ // ./src/ui/src/env.d.ts
2
+
3
+ /// <reference types="vite/client" />
4
+ /// <reference path="./bindings.d.ts" />
5
+
6
+ declare const md: any & {
7
+ __invoke: (name: string, ...args: unknown[]) => Promise<unknown>;
8
+ [key: string]: any;
9
+ };
10
+ /** @deprecated alias for `md` (kept for compatibility) */
11
+ // declare const bindings: typeof md;
12
+
13
+ interface Window {
14
+ md: typeof md;
15
+ bindings: typeof bindings;
16
+ }