cradova 3.13.2 → 3.14.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/index.js +243 -113
- package/dist/primitives/classes.d.ts +40 -16
- package/dist/primitives/types.d.ts +7 -6
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -342,7 +342,6 @@ var compManager = {
|
|
|
342
342
|
resetComponent(component);
|
|
343
343
|
const newHtml = component(component, ...component._args || []);
|
|
344
344
|
if (newHtml instanceof HTMLElement) {
|
|
345
|
-
node.replaceWith(newHtml);
|
|
346
345
|
node.insertAdjacentElement("beforebegin", newHtml);
|
|
347
346
|
node.remove();
|
|
348
347
|
component.reference = newHtml;
|
|
@@ -530,116 +529,29 @@ class SilentStore {
|
|
|
530
529
|
}
|
|
531
530
|
}
|
|
532
531
|
|
|
533
|
-
class List {
|
|
534
|
-
_data;
|
|
535
|
-
_dirtyIndices;
|
|
536
|
-
notifier;
|
|
537
|
-
constructor(initialData, notifier) {
|
|
538
|
-
this._data = initialData || [];
|
|
539
|
-
this._dirtyIndices = new Set;
|
|
540
|
-
this.notifier = notifier;
|
|
541
|
-
this._dirtyIndices.add("all");
|
|
542
|
-
}
|
|
543
|
-
get items() {
|
|
544
|
-
return {
|
|
545
|
-
[Symbol.iterator]: () => {
|
|
546
|
-
return this._data[Symbol.iterator]();
|
|
547
|
-
},
|
|
548
|
-
next: () => {
|
|
549
|
-
return this._data[Symbol.iterator]().next();
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
get length() {
|
|
554
|
-
return this._data.length;
|
|
555
|
-
}
|
|
556
|
-
get(index) {
|
|
557
|
-
return this._data[index];
|
|
558
|
-
}
|
|
559
|
-
indexOf(item) {
|
|
560
|
-
return this._data.indexOf(item);
|
|
561
|
-
}
|
|
562
|
-
update(index, newItemData) {
|
|
563
|
-
if (index >= 0 && index < this._data.length && this._data[index] !== newItemData) {
|
|
564
|
-
this._data[index] = newItemData;
|
|
565
|
-
this._dirtyIndices.add(index);
|
|
566
|
-
this.notifier("itemUpdated", { index, newItemData });
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
push(itemData, index) {
|
|
570
|
-
if (index === undefined || index > this._data.length || index < 0) {
|
|
571
|
-
index = this._data.length;
|
|
572
|
-
}
|
|
573
|
-
this._data.splice(index, 0, itemData);
|
|
574
|
-
this._dirtyIndices.add("all");
|
|
575
|
-
this.notifier("dataChanged", { type: "add", index });
|
|
576
|
-
}
|
|
577
|
-
map(callback) {
|
|
578
|
-
return this._data.map(callback);
|
|
579
|
-
}
|
|
580
|
-
remove(index, count = 1) {
|
|
581
|
-
if (index >= 0 && index < this._data.length && count > 0) {
|
|
582
|
-
this._data.splice(index, count);
|
|
583
|
-
this._dirtyIndices.add("all");
|
|
584
|
-
this.notifier("dataChanged", { type: "remove", index });
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
_set(newData) {
|
|
588
|
-
this._data = newData || [];
|
|
589
|
-
this._dirtyIndices.clear();
|
|
590
|
-
this._dirtyIndices.add("all");
|
|
591
|
-
return ["dataChanged"];
|
|
592
|
-
}
|
|
593
|
-
_isDirty(index = "all") {
|
|
594
|
-
if (this._dirtyIndices.has(index)) {
|
|
595
|
-
this._dirtyIndices.delete(index);
|
|
596
|
-
return true;
|
|
597
|
-
}
|
|
598
|
-
return false;
|
|
599
|
-
}
|
|
600
|
-
_clearAllDirty() {
|
|
601
|
-
this._dirtyIndices.clear();
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
532
|
class Signal {
|
|
606
533
|
pn;
|
|
607
|
-
isList = false;
|
|
608
534
|
subscribers = {};
|
|
609
535
|
store;
|
|
610
536
|
silentStore = undefined;
|
|
611
537
|
passers;
|
|
612
538
|
constructor(initial, props) {
|
|
613
|
-
if (!initial || typeof initial !== "object") {
|
|
614
|
-
throw new Error("Initial signal value must be an
|
|
615
|
-
}
|
|
616
|
-
if (!Array.isArray(initial)) {
|
|
617
|
-
this.store = new Store(initial, (key) => {
|
|
618
|
-
this.publish(key);
|
|
619
|
-
});
|
|
620
|
-
this.silentStore = new SilentStore(this.store);
|
|
621
|
-
} else {
|
|
622
|
-
this.isList = true;
|
|
623
|
-
this.store = new List(initial, (eventType) => {
|
|
624
|
-
this.publish(eventType);
|
|
625
|
-
});
|
|
539
|
+
if (!initial || typeof initial !== "object" || Array.isArray(initial)) {
|
|
540
|
+
throw new Error("Initial signal value must be an object");
|
|
626
541
|
}
|
|
542
|
+
this.store = new Store(initial, (key) => {
|
|
543
|
+
this.publish(key);
|
|
544
|
+
});
|
|
545
|
+
this.silentStore = new SilentStore(this.store);
|
|
627
546
|
if (props && props.persistName) {
|
|
628
547
|
this.pn = props.persistName;
|
|
629
548
|
const key = localStorage.getItem(props.persistName);
|
|
630
549
|
if (key && key !== "undefined") {
|
|
631
550
|
const restored = JSON.parse(key);
|
|
632
|
-
|
|
633
|
-
this.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
this.silentStore = new SilentStore(this.store);
|
|
637
|
-
} else if (Array.isArray(restored)) {
|
|
638
|
-
this.isList = true;
|
|
639
|
-
this.store = new List(restored, (eventType) => {
|
|
640
|
-
this.publish(eventType);
|
|
641
|
-
});
|
|
642
|
-
}
|
|
551
|
+
this.store = new Store(Object.assign(initial, restored), (key2) => {
|
|
552
|
+
this.publish(key2);
|
|
553
|
+
});
|
|
554
|
+
this.silentStore = new SilentStore(this.store);
|
|
643
555
|
}
|
|
644
556
|
}
|
|
645
557
|
}
|
|
@@ -659,7 +571,7 @@ class Signal {
|
|
|
659
571
|
}
|
|
660
572
|
});
|
|
661
573
|
if (this.pn) {
|
|
662
|
-
localStorage.setItem(this.pn, JSON.stringify(this.
|
|
574
|
+
localStorage.setItem(this.pn, JSON.stringify(this.store));
|
|
663
575
|
}
|
|
664
576
|
}
|
|
665
577
|
set(NEW) {
|
|
@@ -686,7 +598,7 @@ class Signal {
|
|
|
686
598
|
}
|
|
687
599
|
}
|
|
688
600
|
if (this.pn) {
|
|
689
|
-
localStorage.setItem(this.pn, JSON.stringify(this.
|
|
601
|
+
localStorage.setItem(this.pn, JSON.stringify(this.store));
|
|
690
602
|
}
|
|
691
603
|
}
|
|
692
604
|
notify(eventName, listener) {
|
|
@@ -696,11 +608,7 @@ class Signal {
|
|
|
696
608
|
}
|
|
697
609
|
if (typeof eventName === "function") {
|
|
698
610
|
listener = eventName;
|
|
699
|
-
|
|
700
|
-
eventName = ["dataChanged", "itemUpdated"];
|
|
701
|
-
} else {
|
|
702
|
-
eventName = Object.keys(this.store);
|
|
703
|
-
}
|
|
611
|
+
eventName = Object.keys(this.store);
|
|
704
612
|
}
|
|
705
613
|
if (typeof listener !== "function" || !eventName) {
|
|
706
614
|
console.error(` ✘ Cradova err: listener or eventName ${String(listener)} is not a valid listener function or string`);
|
|
@@ -727,11 +635,7 @@ class Signal {
|
|
|
727
635
|
}
|
|
728
636
|
if (typeof eventName === "function") {
|
|
729
637
|
element = eventName;
|
|
730
|
-
|
|
731
|
-
eventName = "__ALL__";
|
|
732
|
-
} else {
|
|
733
|
-
eventName = "__ALL__";
|
|
734
|
-
}
|
|
638
|
+
eventName = "__ALL__";
|
|
735
639
|
}
|
|
736
640
|
const isComp = !isArrowFunc(element);
|
|
737
641
|
let el;
|
|
@@ -776,7 +680,7 @@ class Signal {
|
|
|
776
680
|
if (this.passers) {
|
|
777
681
|
return this.passers;
|
|
778
682
|
}
|
|
779
|
-
const keys = Object.keys(this.store);
|
|
683
|
+
const keys = Object.keys(this.store.$_internal_data);
|
|
780
684
|
this.passers = {};
|
|
781
685
|
for (const key of keys) {
|
|
782
686
|
this.passers[key] = [key, this];
|
|
@@ -797,12 +701,12 @@ class Page {
|
|
|
797
701
|
_unload_CB;
|
|
798
702
|
_activate_CB;
|
|
799
703
|
constructor(pageParams) {
|
|
800
|
-
const { template,
|
|
704
|
+
const { template, title } = pageParams;
|
|
801
705
|
if (typeof template !== "function") {
|
|
802
706
|
throw new Error(` ✘ Cradova err: template function for the page is not a function`);
|
|
803
707
|
}
|
|
804
708
|
this._html = template;
|
|
805
|
-
this._name =
|
|
709
|
+
this._name = title || document.title;
|
|
806
710
|
}
|
|
807
711
|
set onDeactivate(cb) {
|
|
808
712
|
this._unload_CB = cb;
|
|
@@ -1050,6 +954,231 @@ class RefInstance {
|
|
|
1050
954
|
return [this, name];
|
|
1051
955
|
}
|
|
1052
956
|
}
|
|
957
|
+
|
|
958
|
+
class List {
|
|
959
|
+
state;
|
|
960
|
+
item;
|
|
961
|
+
length;
|
|
962
|
+
options;
|
|
963
|
+
renderingRange;
|
|
964
|
+
container;
|
|
965
|
+
firstItemIndex = 0;
|
|
966
|
+
lastItemIndex = 0;
|
|
967
|
+
rendered = false;
|
|
968
|
+
subscribers = [];
|
|
969
|
+
constructor(state, item, options) {
|
|
970
|
+
this.state = state;
|
|
971
|
+
this.item = item || ((item2) => div(String(item2)));
|
|
972
|
+
this.length = state.length;
|
|
973
|
+
this.options = options;
|
|
974
|
+
this.renderingRange = Math.round(Math.min(this.length > 50 ? this.length * 0.5 : this.length, window.innerHeight / (this.options?.itemHeight || 1)));
|
|
975
|
+
this.lastItemIndex = this.renderingRange - 1;
|
|
976
|
+
this.container = document.createElement("div");
|
|
977
|
+
if (this.options?.className) {
|
|
978
|
+
this.container.className = this.options?.className;
|
|
979
|
+
}
|
|
980
|
+
if (this.options?.id) {
|
|
981
|
+
this.container.id = this.options?.id;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
get Element() {
|
|
985
|
+
if (this.rendered) {
|
|
986
|
+
return this.container;
|
|
987
|
+
}
|
|
988
|
+
for (let i2 = 0;i2 < this.renderingRange; i2++) {
|
|
989
|
+
const item = this.item(this.state[i2]);
|
|
990
|
+
item.setAttribute("data-index", i2.toString());
|
|
991
|
+
this.container.appendChild(item);
|
|
992
|
+
}
|
|
993
|
+
this.rendered = true;
|
|
994
|
+
const domObser = () => {
|
|
995
|
+
const observer = new IntersectionObserver((entries) => {
|
|
996
|
+
entries.forEach((entry) => {
|
|
997
|
+
if (entry.isIntersecting) {
|
|
998
|
+
const isBottom = entry.target === this.container.lastElementChild;
|
|
999
|
+
const isTop = !isBottom;
|
|
1000
|
+
observer.unobserve(entry.target);
|
|
1001
|
+
const index = Number(entry.target.getAttribute("data-index"));
|
|
1002
|
+
if (isBottom) {
|
|
1003
|
+
for (let i2 = index + 1;i2 < this.length; i2++) {
|
|
1004
|
+
const item = this.item(this.state[i2]);
|
|
1005
|
+
item.setAttribute("data-index", i2.toString());
|
|
1006
|
+
this.container.appendChild(item);
|
|
1007
|
+
}
|
|
1008
|
+
for (let i2 = index - this.renderingRange;i2 > 0; i2--) {
|
|
1009
|
+
this.container.removeChild(this.container.children[i2]);
|
|
1010
|
+
}
|
|
1011
|
+
this.firstItemIndex = Number(this.container.firstElementChild?.getAttribute("data-index") || 0);
|
|
1012
|
+
this.lastItemIndex = Number(this.container.lastElementChild?.getAttribute("data-index") || 0);
|
|
1013
|
+
}
|
|
1014
|
+
if (isTop) {
|
|
1015
|
+
for (let i2 = index - 1;i2 > 0; i2--) {
|
|
1016
|
+
const item = this.item(this.state[i2]);
|
|
1017
|
+
item.setAttribute("data-index", i2.toString());
|
|
1018
|
+
this.container.appendChild(item);
|
|
1019
|
+
}
|
|
1020
|
+
for (let i2 = index + this.renderingRange;i2 < this.length; i2++) {
|
|
1021
|
+
this.container.removeChild(this.container.children[i2]);
|
|
1022
|
+
}
|
|
1023
|
+
this.lastItemIndex = Number(this.container.lastElementChild?.getAttribute("data-index") || 0);
|
|
1024
|
+
this.firstItemIndex = Number(this.container.firstElementChild?.getAttribute("data-index") || 0);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
observer.observe(this.container.lastElementChild);
|
|
1030
|
+
observer.observe(this.container.firstElementChild);
|
|
1031
|
+
};
|
|
1032
|
+
window.addEventListener("scroll", domObser);
|
|
1033
|
+
window.CradovaEvent.after_page_is_killed.push(() => {
|
|
1034
|
+
window.removeEventListener("scroll", domObser);
|
|
1035
|
+
});
|
|
1036
|
+
return this.container;
|
|
1037
|
+
}
|
|
1038
|
+
computed(element) {
|
|
1039
|
+
if (!element) {
|
|
1040
|
+
console.error(` ✘ Cradova err: element ${String(element)} is not a valid element or function`);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const isComp = !isArrowFunc(element);
|
|
1044
|
+
let el;
|
|
1045
|
+
if (isComp) {
|
|
1046
|
+
el = toComp(element);
|
|
1047
|
+
} else {
|
|
1048
|
+
el = element?.();
|
|
1049
|
+
}
|
|
1050
|
+
if (el === undefined || !(el instanceof HTMLElement)) {
|
|
1051
|
+
console.error(` ✘ Cradova err: ${String(element)} is not a valid element or function`);
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
const listener = () => {
|
|
1055
|
+
if (!document.body.contains(listener.element)) {
|
|
1056
|
+
listener.element?.remove();
|
|
1057
|
+
this.subscribers.filter((f) => listener.idx !== f.idx);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
let newEl;
|
|
1061
|
+
if (isComp) {
|
|
1062
|
+
newEl = toComp(element);
|
|
1063
|
+
} else {
|
|
1064
|
+
newEl = element?.();
|
|
1065
|
+
}
|
|
1066
|
+
if (newEl === undefined || !(newEl instanceof HTMLElement)) {
|
|
1067
|
+
console.error(` ✘ Cradova err: ${String(element)} is not a valid element or function`);
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
listener.element.insertAdjacentElement("beforebegin", newEl);
|
|
1071
|
+
listener.element.remove();
|
|
1072
|
+
listener.element = newEl;
|
|
1073
|
+
};
|
|
1074
|
+
listener.element = el;
|
|
1075
|
+
listener.idx = this.subscribers.length;
|
|
1076
|
+
this.subscribers.push(listener);
|
|
1077
|
+
return el;
|
|
1078
|
+
}
|
|
1079
|
+
diffDOMBeforeUpdatingState(newState) {
|
|
1080
|
+
this.length = newState.length;
|
|
1081
|
+
this.renderingRange = Math.round(Math.min(this.length > 100 ? this.length * 0.5 : this.length, window.innerHeight / (this.options?.itemHeight || 1)));
|
|
1082
|
+
this.lastItemIndex = this.firstItemIndex + this.renderingRange;
|
|
1083
|
+
for (let i2 = this.lastItemIndex;i2 >= this.firstItemIndex; i2--) {
|
|
1084
|
+
if ((this.state[i2] === undefined || newState[i2] === undefined) && this.container.children[i2] !== undefined) {
|
|
1085
|
+
this.container.removeChild(this.container.children[i2]);
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
if (JSON.stringify(this.state[i2]) === JSON.stringify(newState[i2])) {
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
const item = this.item(newState[i2]);
|
|
1092
|
+
item.setAttribute("data-index", i2.toString());
|
|
1093
|
+
if (this.container.children[i2]) {
|
|
1094
|
+
this.container.replaceChild(item, this.container.children[i2]);
|
|
1095
|
+
} else {
|
|
1096
|
+
this.container.appendChild(item);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
this.lastItemIndex = Number(this.container.lastElementChild?.getAttribute("data-index") || 0);
|
|
1100
|
+
this.firstItemIndex = Number(this.container.firstElementChild?.getAttribute("data-index") || 0);
|
|
1101
|
+
this.state = newState;
|
|
1102
|
+
this.subscribers.forEach((sub) => {
|
|
1103
|
+
const isComp = !isArrowFunc(sub);
|
|
1104
|
+
if (isComp) {
|
|
1105
|
+
compManager.recall(sub);
|
|
1106
|
+
} else {
|
|
1107
|
+
sub?.();
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
get data() {
|
|
1112
|
+
return {
|
|
1113
|
+
[Symbol.iterator]: () => {
|
|
1114
|
+
return this.state[Symbol.iterator]();
|
|
1115
|
+
},
|
|
1116
|
+
next: () => {
|
|
1117
|
+
return this.state[Symbol.iterator]().next();
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
get(index) {
|
|
1122
|
+
return this.state[index];
|
|
1123
|
+
}
|
|
1124
|
+
indexOf(item) {
|
|
1125
|
+
return this.state.indexOf(item);
|
|
1126
|
+
}
|
|
1127
|
+
update(index, newItemData) {
|
|
1128
|
+
const newState = [...this.state];
|
|
1129
|
+
if (index >= 0 && index < this.state.length && this.state[index] !== newItemData) {
|
|
1130
|
+
newState[index] = newItemData;
|
|
1131
|
+
}
|
|
1132
|
+
this.diffDOMBeforeUpdatingState(newState);
|
|
1133
|
+
}
|
|
1134
|
+
push(itemData) {
|
|
1135
|
+
const newState = [...this.state];
|
|
1136
|
+
newState.push(itemData);
|
|
1137
|
+
this.diffDOMBeforeUpdatingState(newState);
|
|
1138
|
+
}
|
|
1139
|
+
map(callback) {
|
|
1140
|
+
const newState = [...this.state];
|
|
1141
|
+
return newState.map(callback);
|
|
1142
|
+
}
|
|
1143
|
+
splice(index, count = 1, ...items) {
|
|
1144
|
+
const newState = [...this.state];
|
|
1145
|
+
if (index >= 0 && index < this.state.length && count > 0) {
|
|
1146
|
+
newState.splice(index, count, ...items);
|
|
1147
|
+
}
|
|
1148
|
+
this.diffDOMBeforeUpdatingState(newState);
|
|
1149
|
+
}
|
|
1150
|
+
set(newData) {
|
|
1151
|
+
const newState = [...this.state];
|
|
1152
|
+
this.state = newData instanceof Function ? newData(this.state) : newData || [];
|
|
1153
|
+
this.diffDOMBeforeUpdatingState(newState);
|
|
1154
|
+
}
|
|
1155
|
+
destroy() {
|
|
1156
|
+
this.container.remove();
|
|
1157
|
+
this.container = null;
|
|
1158
|
+
this.state.length = 0;
|
|
1159
|
+
this.state = null;
|
|
1160
|
+
this.item = null;
|
|
1161
|
+
this.length = 0;
|
|
1162
|
+
this.options = null;
|
|
1163
|
+
this.renderingRange = 0;
|
|
1164
|
+
this.firstItemIndex = 0;
|
|
1165
|
+
this.lastItemIndex = 0;
|
|
1166
|
+
}
|
|
1167
|
+
notify(listener) {
|
|
1168
|
+
if (!listener) {
|
|
1169
|
+
console.error(` ✘ Cradova err: listener ${String(listener)} is not a valid listener function or string`);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (typeof listener !== "function") {
|
|
1173
|
+
console.error(` ✘ Cradova err: listener or eventName ${String(listener)} is not a valid listener function or string`);
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
if (!isArrowFunc(listener)) {
|
|
1177
|
+
listener = toCompNoRender(listener);
|
|
1178
|
+
}
|
|
1179
|
+
this.subscribers.push(listener);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1053
1182
|
export {
|
|
1054
1183
|
video,
|
|
1055
1184
|
useExternalEffect,
|
|
@@ -1101,6 +1230,7 @@ export {
|
|
|
1101
1230
|
Router,
|
|
1102
1231
|
RefInstance,
|
|
1103
1232
|
Page,
|
|
1233
|
+
List,
|
|
1104
1234
|
$switch,
|
|
1105
1235
|
$case
|
|
1106
1236
|
};
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import type { browserPageType, Comp, CradovaPageType } from "./types.js";
|
|
2
|
-
declare class List<Type extends any[]> {
|
|
3
|
-
notifier: (eventType: "dataChanged" | "itemUpdated", newItemData: Type[number]) => void;
|
|
4
|
-
constructor(initialData: Type, notifier: (eventType: "dataChanged" | "itemUpdated", newItemData: Type[number]) => void);
|
|
5
|
-
get items(): IterableIterator<Type[number]>;
|
|
6
|
-
get length(): number;
|
|
7
|
-
get(index: number): any;
|
|
8
|
-
indexOf(item: Type[number]): number;
|
|
9
|
-
update(index: number, newItemData: Type[number]): void;
|
|
10
|
-
push(itemData: Type[number], index?: number): void;
|
|
11
|
-
map<T>(callback: (item: Type[number], index: number) => T): T[];
|
|
12
|
-
remove(index: number, count?: number): void;
|
|
13
|
-
}
|
|
14
2
|
/**
|
|
15
3
|
* Cradova Signal
|
|
16
4
|
* ----
|
|
@@ -21,8 +9,8 @@ declare class List<Type extends any[]> {
|
|
|
21
9
|
* - persist changes to localStorage
|
|
22
10
|
* @constructor initial: Record<string, any>, props: {persist}
|
|
23
11
|
*/
|
|
24
|
-
export declare class Signal<Type = any> {
|
|
25
|
-
store: Type
|
|
12
|
+
export declare class Signal<Type extends Record<string, any> = any> {
|
|
13
|
+
store: Type;
|
|
26
14
|
silentStore: Type extends Array<any> ? never : Type;
|
|
27
15
|
passers?: Record<keyof Type, [string, Signal<Type>]>;
|
|
28
16
|
constructor(initial: Type, props?: {
|
|
@@ -42,7 +30,7 @@ export declare class Signal<Type = any> {
|
|
|
42
30
|
* @param name of event.
|
|
43
31
|
* @param callback function to call.
|
|
44
32
|
*/
|
|
45
|
-
notify<T extends keyof Type>(eventName: (T | "dataChanged" | "itemUpdated" | T[]) | (() => HTMLElement | void) | Comp | ((ctx: Comp) => HTMLElement), listener?: (() =>
|
|
33
|
+
notify<T extends keyof Type>(eventName: (T | "dataChanged" | "itemUpdated" | T[]) | (() => HTMLElement | void) | Comp | ((ctx: Comp) => HTMLElement), listener?: (() => void) | Comp | ((ctx: Comp) => HTMLElement)): void;
|
|
46
34
|
computed<T extends keyof Type>(eventName: (T | "dataChanged" | "itemUpdated") | (() => HTMLElement) | Comp | ((ctx: Comp) => HTMLElement), element?: (() => HTMLElement) | Comp | ((ctx: Comp) => HTMLElement)): HTMLElement | undefined;
|
|
47
35
|
/**
|
|
48
36
|
* Cradova Signal
|
|
@@ -65,6 +53,7 @@ export declare class Signal<Type = any> {
|
|
|
65
53
|
* @param template
|
|
66
54
|
*/
|
|
67
55
|
export declare class Page {
|
|
56
|
+
_unload_CB?: (this: Page) => Promise<void> | void;
|
|
68
57
|
_activate_CB?: (this: Page) => Promise<void> | void;
|
|
69
58
|
constructor(pageParams: CradovaPageType);
|
|
70
59
|
set onDeactivate(cb: (this: Page) => Promise<void> | void);
|
|
@@ -152,4 +141,39 @@ export declare class RefInstance<T = unknown> {
|
|
|
152
141
|
*/
|
|
153
142
|
bind(name: string): [RefInstance<T>, string];
|
|
154
143
|
}
|
|
155
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Cradova List
|
|
146
|
+
* ---
|
|
147
|
+
* A virtual list store and component for efficient rendering of large lists.
|
|
148
|
+
*/
|
|
149
|
+
export declare class List<T> {
|
|
150
|
+
length: number;
|
|
151
|
+
private rendered;
|
|
152
|
+
subscribers: Function[];
|
|
153
|
+
constructor(state: T[], item?: (item: T) => HTMLElement, options?: {
|
|
154
|
+
itemHeight: number;
|
|
155
|
+
className?: string;
|
|
156
|
+
id?: string;
|
|
157
|
+
});
|
|
158
|
+
get Element(): HTMLElement;
|
|
159
|
+
computed<T extends keyof List<T>>(element?: (() => HTMLElement) | Comp | ((ctx: Comp) => HTMLElement)): HTMLElement | undefined;
|
|
160
|
+
private diffDOMBeforeUpdatingState;
|
|
161
|
+
get data(): IterableIterator<T>;
|
|
162
|
+
get(index: number): T;
|
|
163
|
+
indexOf(item: T): number;
|
|
164
|
+
update(index: number, newItemData: T): void;
|
|
165
|
+
push(itemData: T): void;
|
|
166
|
+
map<K>(callback: (item: T, index: number) => K): K[];
|
|
167
|
+
splice(index: number, count?: number, ...items: T[]): void;
|
|
168
|
+
set(newData: T[] | ((prevItem: T[]) => T[])): void;
|
|
169
|
+
destroy(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Cradova Signal
|
|
172
|
+
* ----
|
|
173
|
+
* subscribe to an event
|
|
174
|
+
*
|
|
175
|
+
* @param name of event.
|
|
176
|
+
* @param callback function to call.
|
|
177
|
+
*/
|
|
178
|
+
notify<T extends keyof List<T>>(listener?: (() => void) | Comp | ((ctx: Comp) => HTMLElement)): void;
|
|
179
|
+
}
|
|
@@ -6,12 +6,13 @@ interface Attributes<E extends HTMLElement> {
|
|
|
6
6
|
style?: Partial<CSS.Properties>;
|
|
7
7
|
[key: `data-${string}`]: string | undefined;
|
|
8
8
|
[key: `aria-${string}`]: string | undefined;
|
|
9
|
-
[key: `on${string}`]: ((this: E, event:
|
|
9
|
+
[key: `on${string}`]: ((this: E, event: StandardEvents) => void) | undefined;
|
|
10
10
|
}
|
|
11
|
-
type StandardEvents
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
type StandardEvents = KeyboardEvent | MouseEvent | TouchEvent | WheelEvent | DragEvent | ClipboardEvent | CompositionEvent | FocusEvent | InputEvent | AnimationEvent | TransitionEvent | Event;
|
|
12
|
+
type OmitFunctions<E> = {
|
|
13
|
+
[K in keyof E as E[K] extends Function ? never : K]: E[K];
|
|
14
|
+
};
|
|
15
|
+
export type VJS_params_TYPE<E extends HTMLElement> = (undefined | undefined[] | string | string[] | HTMLElement | HTMLElement[] | DocumentFragment | DocumentFragment[] | (() => HTMLElement) | (() => HTMLElement)[] | ((ctx: Comp) => HTMLElement) | ((ctx: Comp) => HTMLElement)[] | [string, Signal<any>] | Attributes<E> | OmitFunctions<E>)[];
|
|
15
16
|
export type CradovaPageType = {
|
|
16
17
|
/**
|
|
17
18
|
* Cradova page
|
|
@@ -19,7 +20,7 @@ export type CradovaPageType = {
|
|
|
19
20
|
* title of the page
|
|
20
21
|
* .
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
title?: string;
|
|
23
24
|
/**
|
|
24
25
|
* Cradova page
|
|
25
26
|
* ---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cradova",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"description": "Build Powerful ⚡ Web Apps with Ease",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"url": "git+https://github.com/CodeDynasty-dev/Cradova.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"compile": "bun bundle.ts",
|
|
17
|
+
"compile": "bun bundle.ts && run clean",
|
|
18
18
|
"lint": "eslint . --fix",
|
|
19
|
-
"tsc": "tsc --target esnext tests/index.ts --watch --moduleResolution NodeNext --module NodeNext"
|
|
19
|
+
"tsc": "tsc --target esnext tests/index.ts --watch --moduleResolution NodeNext --module NodeNext",
|
|
20
|
+
"clean": "rm -rf tests/dist && cp -r dist tests/dist"
|
|
20
21
|
},
|
|
21
22
|
"keywords": [
|
|
22
23
|
"frontend library",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
},
|
|
55
56
|
"homepage": "https://github.com/CodeDynasty-dev/cradova",
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"csstype": "^3.1.
|
|
58
|
+
"csstype": "^3.1.3"
|
|
58
59
|
},
|
|
59
60
|
"docmach": {
|
|
60
61
|
"docs-directory": "docs/docs",
|
|
@@ -62,6 +63,6 @@
|
|
|
62
63
|
"assets-folder": "docs/assets"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"docmach": "^1.0.
|
|
66
|
+
"docmach": "^1.0.18"
|
|
66
67
|
}
|
|
67
68
|
}
|