@kalel1500/kalion-js 0.15.1-beta.0 → 0.15.2-beta.0
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.
- package/dist/kalion-js.common.js +146 -16
- package/dist/kalion-js.common.js.map +1 -1
- package/dist/kalion-js.d.ts +50 -2
- package/dist/kalion-js.js +145 -17
- package/dist/kalion-js.js.map +1 -1
- package/package.json +1 -1
package/dist/kalion-js.common.js
CHANGED
|
@@ -5258,6 +5258,17 @@ var DomService = class extends Instantiable {
|
|
|
5258
5258
|
//#region src/app/global.ts
|
|
5259
5259
|
var g = class g {
|
|
5260
5260
|
static errorModalIsShowed = false;
|
|
5261
|
+
static resolveElement(target, name, context = "g") {
|
|
5262
|
+
const targetName = name ?? "element";
|
|
5263
|
+
if (target === void 0) throw new Error(`[${context}] The "${targetName}" parameter is required.`);
|
|
5264
|
+
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
5265
|
+
if (!el) {
|
|
5266
|
+
const details = typeof target === "string" ? ` with selector: "${target}".` : ".";
|
|
5267
|
+
const notFoundMessage = name ? `No element found for "${targetName}"${details}` : `No element found${details}`;
|
|
5268
|
+
throw new Error(`[${context}] ${notFoundMessage}`);
|
|
5269
|
+
}
|
|
5270
|
+
return el;
|
|
5271
|
+
}
|
|
5261
5272
|
static isNotNull(variable) {
|
|
5262
5273
|
return variable !== null;
|
|
5263
5274
|
}
|
|
@@ -5285,44 +5296,55 @@ var g = class g {
|
|
|
5285
5296
|
g.errorModalIsShowed = true;
|
|
5286
5297
|
return false;
|
|
5287
5298
|
}
|
|
5288
|
-
static async fetchBase({ url, type = "GET", params = void 0 }, strict) {
|
|
5299
|
+
static async fetchBase({ url, type = "GET", params = void 0, headers = {} }, strict) {
|
|
5289
5300
|
try {
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
}
|
|
5301
|
+
const isFormData = params instanceof FormData;
|
|
5302
|
+
const finalHeaders = {
|
|
5303
|
+
"Accept": "application/json",
|
|
5304
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
5305
|
+
"X-CSRF-TOKEN": __const("token") ?? "",
|
|
5306
|
+
...!isFormData ? { "Content-Type": "application/json" } : {},
|
|
5307
|
+
...headers
|
|
5298
5308
|
};
|
|
5299
|
-
|
|
5309
|
+
const needsSpoofing = isFormData && [
|
|
5310
|
+
"PUT",
|
|
5311
|
+
"PATCH",
|
|
5312
|
+
"DELETE"
|
|
5313
|
+
].includes(type);
|
|
5314
|
+
if (needsSpoofing && params instanceof FormData) params.append("_method", type);
|
|
5315
|
+
const fetchParams = {
|
|
5316
|
+
method: needsSpoofing ? "POST" : type,
|
|
5317
|
+
headers: finalHeaders
|
|
5318
|
+
};
|
|
5319
|
+
if (type !== "GET" && params !== void 0) fetchParams.body = isFormData ? params : JSON.stringify(params);
|
|
5300
5320
|
const response = await fetch(url, fetchParams);
|
|
5301
5321
|
const result = await response.json();
|
|
5302
5322
|
if (typeof result === "string") {
|
|
5303
|
-
const reason = result === "" ? "
|
|
5323
|
+
const reason = result === "" ? "The server returned an empty response." : result;
|
|
5304
5324
|
return Promise.reject(reason);
|
|
5305
5325
|
}
|
|
5306
5326
|
result.ok = response.ok;
|
|
5307
5327
|
if (strict && !response.ok) return Promise.reject(result);
|
|
5308
5328
|
return Promise.resolve(result);
|
|
5309
5329
|
} catch (e) {
|
|
5310
|
-
console.error("
|
|
5330
|
+
console.error("Fetch request failed.");
|
|
5311
5331
|
return Promise.reject(e);
|
|
5312
5332
|
}
|
|
5313
5333
|
}
|
|
5314
|
-
static async fetch({ url, type = "GET", params = void 0 }) {
|
|
5334
|
+
static async fetch({ url, type = "GET", params = void 0, headers = {} }) {
|
|
5315
5335
|
return await g.fetchBase({
|
|
5316
5336
|
url,
|
|
5317
5337
|
type,
|
|
5318
|
-
params
|
|
5338
|
+
params,
|
|
5339
|
+
headers
|
|
5319
5340
|
}, false);
|
|
5320
5341
|
}
|
|
5321
|
-
static async fetchStrict({ url, type = "GET", params = void 0 }) {
|
|
5342
|
+
static async fetchStrict({ url, type = "GET", params = void 0, headers = {} }) {
|
|
5322
5343
|
return await g.fetchBase({
|
|
5323
5344
|
url,
|
|
5324
5345
|
type,
|
|
5325
|
-
params
|
|
5346
|
+
params,
|
|
5347
|
+
headers
|
|
5326
5348
|
}, true);
|
|
5327
5349
|
}
|
|
5328
5350
|
static async fetchString({ url, type = "GET", params = void 0 }) {
|
|
@@ -5594,6 +5616,93 @@ var g = class g {
|
|
|
5594
5616
|
}
|
|
5595
5617
|
};
|
|
5596
5618
|
//#endregion
|
|
5619
|
+
//#region src/app/Dropzone.ts
|
|
5620
|
+
var Dropzone = class {
|
|
5621
|
+
dropzone;
|
|
5622
|
+
fileInput;
|
|
5623
|
+
dragClasses;
|
|
5624
|
+
uploadFiles;
|
|
5625
|
+
onError;
|
|
5626
|
+
openPickerOnDropzoneClick;
|
|
5627
|
+
triggers;
|
|
5628
|
+
onClickHandler;
|
|
5629
|
+
onPreventDefault;
|
|
5630
|
+
onDragEnter;
|
|
5631
|
+
onDragLeave;
|
|
5632
|
+
onDrop;
|
|
5633
|
+
onFileChange;
|
|
5634
|
+
constructor(params) {
|
|
5635
|
+
this.dropzone = g.resolveElement(params.dropzone, "dropzone", "Dropzone");
|
|
5636
|
+
this.fileInput = g.resolveElement(params.input, "input", "Dropzone");
|
|
5637
|
+
this.dragClasses = params.dragClasses ?? [];
|
|
5638
|
+
this.uploadFiles = params.uploadFiles;
|
|
5639
|
+
this.onError = params.onError ?? ((error) => console.error("[Dropzone]", error));
|
|
5640
|
+
this.openPickerOnDropzoneClick = params.openPickerOnDropzoneClick ?? false;
|
|
5641
|
+
this.triggers = this.resolveTriggers(params.triggers);
|
|
5642
|
+
this.onClickHandler = () => this.fileInput.click();
|
|
5643
|
+
this.onPreventDefault = (e) => e.preventDefault();
|
|
5644
|
+
this.onDragEnter = () => {
|
|
5645
|
+
if (this.dragClasses.length) this.dropzone.classList.add(...this.dragClasses);
|
|
5646
|
+
};
|
|
5647
|
+
this.onDragLeave = () => {
|
|
5648
|
+
if (this.dragClasses.length) this.dropzone.classList.remove(...this.dragClasses);
|
|
5649
|
+
};
|
|
5650
|
+
this.onDrop = (e) => {
|
|
5651
|
+
const dt = e.dataTransfer;
|
|
5652
|
+
if (dt && dt.files.length) this.uploadFiles(dt.files).catch(this.onError);
|
|
5653
|
+
};
|
|
5654
|
+
this.onFileChange = () => {
|
|
5655
|
+
if (this.fileInput.files && this.fileInput.files.length) this.uploadFiles(this.fileInput.files).catch(this.onError);
|
|
5656
|
+
};
|
|
5657
|
+
this.init();
|
|
5658
|
+
}
|
|
5659
|
+
resolveTriggers(triggers) {
|
|
5660
|
+
if (!triggers) return [];
|
|
5661
|
+
return (Array.isArray(triggers) ? triggers : [triggers]).map((t) => g.resolveElement(t, "triggers", "Dropzone"));
|
|
5662
|
+
}
|
|
5663
|
+
init() {
|
|
5664
|
+
if (this.openPickerOnDropzoneClick) this.dropzone.addEventListener("click", this.onClickHandler);
|
|
5665
|
+
this.triggers.forEach((trigger) => trigger.addEventListener("click", this.onClickHandler));
|
|
5666
|
+
[
|
|
5667
|
+
"dragenter",
|
|
5668
|
+
"dragover",
|
|
5669
|
+
"dragleave",
|
|
5670
|
+
"drop"
|
|
5671
|
+
].forEach((eventName) => {
|
|
5672
|
+
this.dropzone.addEventListener(eventName, this.onPreventDefault, false);
|
|
5673
|
+
});
|
|
5674
|
+
["dragenter", "dragover"].forEach((eventName) => {
|
|
5675
|
+
this.dropzone.addEventListener(eventName, this.onDragEnter);
|
|
5676
|
+
});
|
|
5677
|
+
["dragleave", "drop"].forEach((eventName) => {
|
|
5678
|
+
this.dropzone.addEventListener(eventName, this.onDragLeave);
|
|
5679
|
+
});
|
|
5680
|
+
this.dropzone.addEventListener("drop", this.onDrop);
|
|
5681
|
+
this.fileInput.addEventListener("change", this.onFileChange);
|
|
5682
|
+
}
|
|
5683
|
+
/** Removes all event listeners registered by this instance. */
|
|
5684
|
+
destroy() {
|
|
5685
|
+
if (this.openPickerOnDropzoneClick) this.dropzone.removeEventListener("click", this.onClickHandler);
|
|
5686
|
+
this.triggers.forEach((trigger) => trigger.removeEventListener("click", this.onClickHandler));
|
|
5687
|
+
[
|
|
5688
|
+
"dragenter",
|
|
5689
|
+
"dragover",
|
|
5690
|
+
"dragleave",
|
|
5691
|
+
"drop"
|
|
5692
|
+
].forEach((eventName) => {
|
|
5693
|
+
this.dropzone.removeEventListener(eventName, this.onPreventDefault);
|
|
5694
|
+
});
|
|
5695
|
+
["dragenter", "dragover"].forEach((eventName) => {
|
|
5696
|
+
this.dropzone.removeEventListener(eventName, this.onDragEnter);
|
|
5697
|
+
});
|
|
5698
|
+
["dragleave", "drop"].forEach((eventName) => {
|
|
5699
|
+
this.dropzone.removeEventListener(eventName, this.onDragLeave);
|
|
5700
|
+
});
|
|
5701
|
+
this.dropzone.removeEventListener("drop", this.onDrop);
|
|
5702
|
+
this.fileInput.removeEventListener("change", this.onFileChange);
|
|
5703
|
+
}
|
|
5704
|
+
};
|
|
5705
|
+
//#endregion
|
|
5597
5706
|
//#region src/app/Html.ts
|
|
5598
5707
|
var Html = class {
|
|
5599
5708
|
static compareTailwindClassesHTML(htmlA, htmlB) {
|
|
@@ -5809,6 +5918,25 @@ var Notify = class Notify {
|
|
|
5809
5918
|
}
|
|
5810
5919
|
};
|
|
5811
5920
|
//#endregion
|
|
5921
|
+
//#region src/app/Spinner.ts
|
|
5922
|
+
var Spinner = class {
|
|
5923
|
+
$spinner;
|
|
5924
|
+
$spinnerBackdrop;
|
|
5925
|
+
constructor(parent) {
|
|
5926
|
+
const parentElement = g.resolveElement(parent, "parent", "Spinner");
|
|
5927
|
+
this.$spinner = parentElement?.querySelector("[data-is-spinner=\"true\"]");
|
|
5928
|
+
this.$spinnerBackdrop = parentElement?.querySelector("[data-is-spinner-backdrop=\"true\"]");
|
|
5929
|
+
}
|
|
5930
|
+
show() {
|
|
5931
|
+
this.$spinner?.classList.remove("hidden");
|
|
5932
|
+
this.$spinnerBackdrop?.classList.remove("hidden");
|
|
5933
|
+
}
|
|
5934
|
+
hide() {
|
|
5935
|
+
this.$spinner?.classList.add("hidden");
|
|
5936
|
+
this.$spinnerBackdrop?.classList.add("hidden");
|
|
5937
|
+
}
|
|
5938
|
+
};
|
|
5939
|
+
//#endregion
|
|
5812
5940
|
//#region src/app/SSelect.ts
|
|
5813
5941
|
var SLIM_EVENT_KEYS = [
|
|
5814
5942
|
"search",
|
|
@@ -6473,6 +6601,7 @@ exports.Component = Component;
|
|
|
6473
6601
|
exports.Constants = Constants;
|
|
6474
6602
|
exports.Cookie = Cookie;
|
|
6475
6603
|
exports.DomService = DomService;
|
|
6604
|
+
exports.Dropzone = Dropzone;
|
|
6476
6605
|
exports.EchoService = EchoService;
|
|
6477
6606
|
exports.EnumVo = EnumVo;
|
|
6478
6607
|
exports.FModal = FModal;
|
|
@@ -6491,6 +6620,7 @@ exports.Route = Route;
|
|
|
6491
6620
|
exports.SModal = SModal;
|
|
6492
6621
|
exports.SSelect = SSelect;
|
|
6493
6622
|
exports.SidebarState = SidebarState;
|
|
6623
|
+
exports.Spinner = Spinner;
|
|
6494
6624
|
exports.StorageProcessKeys = StorageProcessKeys;
|
|
6495
6625
|
exports.StringVo = StringVo;
|
|
6496
6626
|
exports.Test = Test;
|