@kalel1500/kalion-js 0.12.0-beta.0 → 0.13.0-beta.1

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.
@@ -1230,11 +1230,10 @@ class SSelect {
1230
1230
  url.searchParams.set("search", search2);
1231
1231
  url.searchParams.set("limit", fetchLimit.toString());
1232
1232
  url.searchParams.set("exclude", selectedValues.join(","));
1233
- const response = await fetch(url.toString());
1234
- const resp = await response.json();
1233
+ const resp = await g.fetchStrict({ url: url.toString() });
1235
1234
  const rawData = (resp == null ? void 0 : resp.data) || [];
1236
1235
  if (!rawData.length) {
1237
- throw new Error((resp == null ? void 0 : resp.error) || "No results found");
1236
+ throw new Error("No results found");
1238
1237
  }
1239
1238
  const selectedSet = new Set(selectedValues.map((v) => String(v)));
1240
1239
  return rawData.map((item) => {
@@ -7358,15 +7357,49 @@ var AlertType = /* @__PURE__ */ ((AlertType2) => {
7358
7357
  AlertType2["warning"] = "warning";
7359
7358
  return AlertType2;
7360
7359
  })(AlertType || {});
7360
+ const flowbiteFunctions = {
7361
+ initAccordions,
7362
+ initCollapses,
7363
+ initCarousels,
7364
+ initDismisses,
7365
+ initDropdowns,
7366
+ initModals,
7367
+ initDrawers,
7368
+ initTabs,
7369
+ initTooltips,
7370
+ initPopovers,
7371
+ initDials,
7372
+ initInputCounters,
7373
+ initCopyClipboards,
7374
+ initDatepickers
7375
+ };
7376
+ function handleFlowbiteInit(initOption) {
7377
+ if (!initOption) return;
7378
+ if (initOption === true) {
7379
+ initFlowbite();
7380
+ } else if (Array.isArray(initOption)) {
7381
+ initOption.forEach((componentName) => {
7382
+ const fn = flowbiteFunctions[componentName];
7383
+ if (fn) fn();
7384
+ });
7385
+ } else {
7386
+ const fn = flowbiteFunctions[initOption];
7387
+ if (fn) fn();
7388
+ }
7389
+ }
7361
7390
  const _FModal = class _FModal {
7362
7391
  constructor(id, options) {
7363
7392
  __publicField(this, "modal");
7393
+ __publicField(this, "id");
7364
7394
  __publicField(this, "showLoading");
7395
+ __publicField(this, "destroyOnHide");
7365
7396
  __publicField(this, "$modalElement");
7366
7397
  __publicField(this, "$spinnerElements");
7367
7398
  __publicField(this, "$messageElements");
7368
7399
  var _a, _b, _c, _d, _e, _f;
7400
+ this.id = id;
7369
7401
  this.showLoading = (options == null ? void 0 : options.showLoading) ?? false;
7402
+ this.destroyOnHide = (options == null ? void 0 : options.destroyOnHide) ?? false;
7370
7403
  this.$modalElement = document.querySelector(`#${id}`);
7371
7404
  this.$spinnerElements = ((_a = this.$modalElement) == null ? void 0 : _a.querySelectorAll(`.fmodal-spinner`)) ?? null;
7372
7405
  this.$messageElements = {
@@ -7400,6 +7433,7 @@ const _FModal = class _FModal {
7400
7433
  onShow: (modal) => {
7401
7434
  if (options == null ? void 0 : options.onShow) {
7402
7435
  options.onShow(this);
7436
+ handleFlowbiteInit(options == null ? void 0 : options.initFlowbiteAfterOnShow);
7403
7437
  }
7404
7438
  },
7405
7439
  onToggle: () => {
@@ -7412,12 +7446,10 @@ const _FModal = class _FModal {
7412
7446
  ...options == null ? void 0 : options.instanceOptions
7413
7447
  }
7414
7448
  );
7415
- let abortController = _FModal.registry.get(id);
7416
- if (abortController) {
7417
- abortController.abort();
7418
- }
7419
- abortController = new AbortController();
7420
- _FModal.registry.set(id, abortController);
7449
+ this.removeListener();
7450
+ const abortController = new AbortController();
7451
+ _FModal.registryAbort.set(id, abortController);
7452
+ _FModal.registryModal.set(id, this.modal);
7421
7453
  (_f = this.$modalElement) == null ? void 0 : _f.addEventListener(
7422
7454
  "click",
7423
7455
  async (e) => {
@@ -7426,21 +7458,24 @@ const _FModal = class _FModal {
7426
7458
  const $btnConfirm = target.closest(`[data-fmodal-confirm="${id}"]`);
7427
7459
  const $btnDeny = target.closest(`[data-fmodal-deny="${id}"]`);
7428
7460
  if ($btnHide) {
7429
- this.modal.hide();
7461
+ this.hide();
7430
7462
  }
7431
7463
  if ($btnConfirm || $btnDeny) {
7432
7464
  const $actionBtn = $btnConfirm ? $btnConfirm : $btnDeny;
7433
7465
  const action = $btnConfirm ? options == null ? void 0 : options.onConfirm : options == null ? void 0 : options.onDeny;
7434
7466
  const actionName = $btnConfirm ? "onConfirm" : "onDeny";
7435
7467
  if (!action) {
7436
- this.modal.hide();
7468
+ this.hide();
7437
7469
  return;
7438
7470
  }
7439
7471
  this.toggleBtn("disable", $actionBtn);
7440
7472
  try {
7441
7473
  const shouldHide = await action(this);
7474
+ if (actionName === "onConfirm") {
7475
+ handleFlowbiteInit(options == null ? void 0 : options.initFlowbiteAfterOnConfirm);
7476
+ }
7442
7477
  if (shouldHide) {
7443
- this.modal.hide();
7478
+ this.hide();
7444
7479
  }
7445
7480
  } catch (error) {
7446
7481
  console.error(`Error in ${actionName}: `, error);
@@ -7455,11 +7490,31 @@ const _FModal = class _FModal {
7455
7490
  { signal: abortController.signal }
7456
7491
  );
7457
7492
  }
7458
- destroy(id) {
7459
- const abortController = _FModal.registry.get(id);
7493
+ hide() {
7494
+ this.modal.hide();
7495
+ if (this.destroyOnHide) {
7496
+ this.destroy();
7497
+ }
7498
+ }
7499
+ destroy() {
7500
+ _FModal.destroy(this.id);
7501
+ }
7502
+ static destroy(id) {
7503
+ _FModal.removeListener(id);
7504
+ const modalInstance = _FModal.registryModal.get(id);
7505
+ if (modalInstance) {
7506
+ modalInstance.destroy();
7507
+ _FModal.registryModal.delete(id);
7508
+ }
7509
+ }
7510
+ removeListener() {
7511
+ _FModal.removeListener(this.id);
7512
+ }
7513
+ static removeListener(id) {
7514
+ const abortController = _FModal.registryAbort.get(id);
7460
7515
  if (abortController) {
7461
7516
  abortController.abort();
7462
- _FModal.registry.delete(id);
7517
+ _FModal.registryAbort.delete(id);
7463
7518
  }
7464
7519
  }
7465
7520
  showMessage({ message, type, autoHide = false, hideAfter = 3e3 }) {
@@ -7547,7 +7602,8 @@ const _FModal = class _FModal {
7547
7602
  }
7548
7603
  }
7549
7604
  };
7550
- __publicField(_FModal, "registry", /* @__PURE__ */ new Map());
7605
+ __publicField(_FModal, "registryAbort", /* @__PURE__ */ new Map());
7606
+ __publicField(_FModal, "registryModal", /* @__PURE__ */ new Map());
7551
7607
  let FModal = _FModal;
7552
7608
  function getDefaultExportFromCjs(x) {
7553
7609
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -11101,83 +11157,82 @@ __publicField(_SModal, "Toast", Swal.mixin({
11101
11157
  }));
11102
11158
  let SModal = _SModal;
11103
11159
  const _Route = class _Route {
11104
- static page(uri, callback, makeDataRequest = false) {
11105
- if (Array.isArray(callback) && typeof makeDataRequest === "boolean") {
11106
- const controller = callback[0];
11107
- const method = callback[1];
11108
- __privateGet(_Route, _ROUTES)["PAGES"][uri] = {
11109
- uri,
11110
- controller,
11111
- method,
11112
- makeDataRequest
11113
- };
11160
+ /**
11161
+ * Instancia una clase o devuelve el objeto literal tal cual.
11162
+ */
11163
+ static resolveController(controller) {
11164
+ return typeof controller === "function" ? new controller() : controller;
11165
+ }
11166
+ /**
11167
+ * Recorre un grupo de rutas y ejecuta el método del controlador
11168
+ * si el predicado devuelve true.
11169
+ */
11170
+ static runControllers(routes, shouldRun) {
11171
+ Object.values(routes).forEach((entry) => {
11172
+ if (!shouldRun(entry)) return;
11173
+ const controller = _Route.resolveController(entry.controller);
11174
+ controller[entry.method]();
11175
+ });
11176
+ }
11177
+ /**
11178
+ * Comprueba si el paquete de rutas (Ziggy) está disponible e inicializado.
11179
+ */
11180
+ static isRouteAvailable() {
11181
+ var _a;
11182
+ try {
11183
+ const r = route();
11184
+ return Boolean((_a = r == null ? void 0 : r.t) == null ? void 0 : _a.hasOwnProperty("url"));
11185
+ } catch {
11186
+ return false;
11114
11187
  }
11115
11188
  }
11189
+ // ─── Registro de rutas ────────────────────────────────────────────────────
11190
+ static page(uri, callback, makeDataRequest = false) {
11191
+ if (!Array.isArray(callback)) return;
11192
+ const [controller, method] = callback;
11193
+ __privateGet(_Route, _ROUTES)["PAGES"][uri] = {
11194
+ uri,
11195
+ controller,
11196
+ method,
11197
+ makeDataRequest
11198
+ };
11199
+ }
11116
11200
  static component(callback, uris) {
11117
- if (Array.isArray(callback) && Array.isArray(uris)) {
11118
- const controller = callback[0];
11119
- const method = callback[1];
11120
- __privateGet(_Route, _ROUTES)["COMPONENTS"][`${controller.name}_${method}`] = {
11121
- controller,
11122
- method,
11123
- uris
11124
- };
11125
- }
11201
+ if (!Array.isArray(callback) || !Array.isArray(uris)) return;
11202
+ const [controller, method] = callback;
11203
+ const key = `${controller.name ?? "anonymous"}_${method}`;
11204
+ __privateGet(_Route, _ROUTES)["COMPONENTS"][key] = { controller, method, uris };
11126
11205
  }
11127
11206
  static all(callback, except) {
11128
- if (Array.isArray(callback) && Array.isArray(except)) {
11129
- const controller = callback[0];
11130
- const method = callback[1];
11131
- __privateGet(_Route, _ROUTES)["ALL"][`${controller.name}_${method}`] = {
11132
- controller,
11133
- method,
11134
- except
11135
- };
11136
- }
11207
+ if (!Array.isArray(callback) || !Array.isArray(except)) return;
11208
+ const [controller, method] = callback;
11209
+ const key = `${controller.name ?? "anonymous"}_${method}`;
11210
+ __privateGet(_Route, _ROUTES)["ALL"][key] = { controller, method, except };
11137
11211
  }
11212
+ // ─── Dispatch ─────────────────────────────────────────────────────────────
11138
11213
  static dispatch() {
11139
- if (!_Route.existsRoutesDefinition()) return;
11214
+ if (!_Route.isRouteAvailable()) return;
11140
11215
  Object.values(__privateGet(_Route, _ROUTES)["PAGES"]).forEach((page) => {
11141
11216
  var _a;
11142
- if (route().current() === page.uri) {
11143
- const controller = new page.controller();
11144
- if (!page.makeDataRequest) {
11145
- let data = (_a = document.getElementById("page-data")) == null ? void 0 : _a.dataset.pageData;
11146
- if (data) {
11147
- data = JSON.parse(data);
11148
- }
11149
- controller[page.method](data);
11150
- return;
11151
- }
11152
- g.fetchStrict({ url: route(page.uri, route().params) }).then((viewData) => {
11153
- controller[page.method](viewData);
11154
- }).catch((e) => {
11155
- g.catchCode({ error: e });
11156
- });
11217
+ if (route().current() !== page.uri) return;
11218
+ const controller = _Route.resolveController(page.controller);
11219
+ if (!page.makeDataRequest) {
11220
+ const raw = (_a = document.getElementById("page-data")) == null ? void 0 : _a.dataset.pageData;
11221
+ const data = raw ? JSON.parse(raw) : void 0;
11222
+ controller[page.method](data);
11157
11223
  return;
11158
11224
  }
11225
+ g.fetchStrict({ url: route(page.uri, route().params) }).then((viewData) => controller[page.method](viewData)).catch((e) => g.catchCode({ error: e }));
11159
11226
  });
11160
- Object.values(__privateGet(_Route, _ROUTES)["COMPONENTS"]).forEach((component) => {
11161
- const onRoutes = component.uris;
11162
- const currentRoute = route().current();
11163
- if (currentRoute !== void 0 && onRoutes.includes(currentRoute)) {
11164
- const controller = new component.controller();
11165
- controller[component.method]();
11166
- }
11227
+ _Route.runControllers(__privateGet(_Route, _ROUTES)["COMPONENTS"], (entry) => {
11228
+ const current = route().current();
11229
+ return current !== void 0 && entry.uris.includes(current);
11167
11230
  });
11168
- Object.values(__privateGet(_Route, _ROUTES)["ALL"]).forEach((component) => {
11169
- const exceptRoutes = component.except;
11170
- const currentRoute = route().current();
11171
- if (currentRoute !== void 0 && !exceptRoutes.includes(currentRoute)) {
11172
- const controller = new component.controller();
11173
- controller[component.method]();
11174
- }
11231
+ _Route.runControllers(__privateGet(_Route, _ROUTES)["ALL"], (entry) => {
11232
+ const current = route().current();
11233
+ return current !== void 0 && !entry.except.includes(current);
11175
11234
  });
11176
11235
  }
11177
- static existsRoutesDefinition() {
11178
- const routeVariable = route();
11179
- return routeVariable.t.hasOwnProperty("url");
11180
- }
11181
11236
  };
11182
11237
  _ROUTES = new WeakMap();
11183
11238
  __privateAdd(_Route, _ROUTES, {