lilact 0.30.1 → 0.31.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/lilact.development.js +68 -43
- package/dist/lilact.development.js.map +2 -2
- package/dist/lilact.development.min.js +23 -23
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +23 -23
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- package/docs/functions/components.cloneComponent.html +1 -1
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.hotReloadRoot.html +1 -1
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/components.replaceAllComponentInstances.html +1 -1
- package/docs/functions/components.replaceComponentEntity.html +1 -1
- package/docs/static/lilact.development.js +68 -43
- package/docs/static/lilact.development.js.map +2 -2
- package/docs/static/lilact.development.min.js +23 -23
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +23 -23
- package/docs/variables/components.cloneElement.html +1 -1
- package/examples/lilact.development.js +68 -43
- package/examples/lilact.development.js.map +2 -2
- package/examples/lilact.development.min.js +23 -23
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +23 -23
- package/package.json +1 -1
- package/src/components.jsx +104 -69
- package/src/lilact.jsx +1 -1
package/package.json
CHANGED
package/src/components.jsx
CHANGED
|
@@ -38,10 +38,30 @@ import { PropTypes } from './proptypes.jsx';
|
|
|
38
38
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
|
|
41
42
|
function getComponentEntity(entity) {
|
|
42
43
|
return entity?.[MEMOIZED] ? entity.component : entity;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const hotEntityAliases = new Map();
|
|
47
|
+
|
|
48
|
+
function resolveHotEntity(entity) {
|
|
49
|
+
entity = getComponentEntity(entity);
|
|
50
|
+
|
|
51
|
+
const visited = new Set();
|
|
52
|
+
|
|
53
|
+
while (
|
|
54
|
+
typeof entity === "function" &&
|
|
55
|
+
hotEntityAliases.has(entity) &&
|
|
56
|
+
!visited.has(entity)
|
|
57
|
+
) {
|
|
58
|
+
visited.add(entity);
|
|
59
|
+
entity = hotEntityAliases.get(entity);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return entity;
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
const componentInstances = new Map();
|
|
46
66
|
|
|
47
67
|
function registerComponentCore(core) {
|
|
@@ -105,7 +125,7 @@ export function replaceComponentEntity(componentCore, nextEntity) {
|
|
|
105
125
|
}
|
|
106
126
|
|
|
107
127
|
const oldEntity = getComponentEntity(componentCore.entity);
|
|
108
|
-
const newEntity =
|
|
128
|
+
const newEntity = resolveHotEntity(nextEntity);
|
|
109
129
|
|
|
110
130
|
if (oldEntity === newEntity) {
|
|
111
131
|
return true;
|
|
@@ -148,6 +168,16 @@ export function replaceAllComponentInstances(oldEntity, newEntity) {
|
|
|
148
168
|
return 0;
|
|
149
169
|
}
|
|
150
170
|
|
|
171
|
+
newEntity = resolveHotEntity(newEntity);
|
|
172
|
+
|
|
173
|
+
if (oldEntity === newEntity) {
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Keep this alias even when there are currently no instances.
|
|
178
|
+
// A future instance may still be created with oldEntity.
|
|
179
|
+
hotEntityAliases.set(oldEntity, newEntity);
|
|
180
|
+
|
|
151
181
|
const instances = componentInstances.get(oldEntity);
|
|
152
182
|
|
|
153
183
|
if (!instances) {
|
|
@@ -168,6 +198,7 @@ export function replaceAllComponentInstances(oldEntity, newEntity) {
|
|
|
168
198
|
return count;
|
|
169
199
|
}
|
|
170
200
|
|
|
201
|
+
|
|
171
202
|
/*
|
|
172
203
|
ComponentCache is for internal use. It is the heart of the JSX runtime,
|
|
173
204
|
it holds child components and detects which one is being rendered or updated.
|
|
@@ -194,19 +225,18 @@ class ComponentCache
|
|
|
194
225
|
bucket[IDX]++;
|
|
195
226
|
|
|
196
227
|
const oldEntity = getComponentEntity(componentCore.entity);
|
|
197
|
-
const newEntity =
|
|
228
|
+
const newEntity = resolveHotEntity(nextEntity);
|
|
198
229
|
|
|
199
230
|
const incompatible =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
231
|
+
typeof oldEntity !== typeof newEntity ||
|
|
232
|
+
(
|
|
233
|
+
typeof oldEntity === "function" &&
|
|
234
|
+
isClass(oldEntity) !== isClass(newEntity)
|
|
235
|
+
);
|
|
236
|
+
|
|
206
237
|
if (incompatible) {
|
|
207
238
|
componentCore = construct_func();
|
|
208
|
-
}
|
|
209
|
-
else if (newEntity) {
|
|
239
|
+
} else if (newEntity) {
|
|
210
240
|
replaceComponentEntity(componentCore, newEntity);
|
|
211
241
|
}
|
|
212
242
|
} else {
|
|
@@ -810,92 +840,97 @@ const renderErrorHandler = (c, e) =>
|
|
|
810
840
|
|
|
811
841
|
|
|
812
842
|
|
|
813
|
-
function constructFunc(core, parent)
|
|
814
|
-
{
|
|
843
|
+
function constructFunc(core, parent) {
|
|
815
844
|
let comp = core;
|
|
816
845
|
|
|
817
|
-
if(
|
|
818
|
-
// do nothing...
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
846
|
+
if (core[TEXT] === undefined) {
|
|
821
847
|
let entity = core.entity;
|
|
822
848
|
let memoized = false;
|
|
823
849
|
|
|
824
|
-
if(typeof
|
|
825
|
-
if(
|
|
850
|
+
if (typeof entity === "object") {
|
|
851
|
+
if (entity[MEMOIZED]) {
|
|
826
852
|
memoized = entity[MEMOIZED];
|
|
827
853
|
entity = entity.component;
|
|
828
|
-
}
|
|
829
|
-
else {
|
|
854
|
+
} else {
|
|
830
855
|
throw new Error("Invalid component.");
|
|
831
856
|
}
|
|
832
857
|
}
|
|
833
858
|
|
|
834
|
-
|
|
835
|
-
comp = new HTMLComponent(entity, core.props);
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
|
|
839
|
-
if( isClass(entity) ) {
|
|
840
|
-
if(entity?.defaultProps) {
|
|
841
|
-
core.props = { ...entity.defaultProps, ...core.props };
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
comp = new entity(core.props);
|
|
859
|
+
entity = resolveHotEntity(entity);
|
|
845
860
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
861
|
+
if (typeof entity === "string") {
|
|
862
|
+
comp = new HTMLComponent(entity, core.props);
|
|
863
|
+
} else if (isClass(entity)) {
|
|
864
|
+
if (entity?.defaultProps) {
|
|
865
|
+
core.props = {
|
|
866
|
+
...entity.defaultProps,
|
|
867
|
+
...core.props,
|
|
868
|
+
};
|
|
869
|
+
}
|
|
850
870
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
871
|
+
comp = new entity(core.props);
|
|
872
|
+
|
|
873
|
+
const desc = Object.getOwnPropertyDescriptor(comp, "state");
|
|
874
|
+
|
|
875
|
+
if (desc) {
|
|
876
|
+
if (
|
|
877
|
+
typeof desc.get !== "function" &&
|
|
878
|
+
typeof desc.set !== "function"
|
|
879
|
+
) {
|
|
880
|
+
comp[CORE].state = comp.state;
|
|
881
|
+
|
|
882
|
+
Object.defineProperty(comp, "state", {
|
|
883
|
+
get() {
|
|
884
|
+
return this[CORE].state;
|
|
885
|
+
},
|
|
886
|
+
set(value) {
|
|
887
|
+
if (this[CORE].state === undefined) {
|
|
888
|
+
this[CORE].state = value;
|
|
889
|
+
} else {
|
|
890
|
+
throw new Error(
|
|
891
|
+
"Assigning component state this way is not allowed."
|
|
892
|
+
);
|
|
861
893
|
}
|
|
862
|
-
}
|
|
863
|
-
}
|
|
894
|
+
},
|
|
895
|
+
});
|
|
864
896
|
}
|
|
865
897
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
898
|
+
} else if (typeof entity === "function") {
|
|
899
|
+
if (entity?.defaultProps) {
|
|
900
|
+
core.props = {
|
|
901
|
+
...entity.defaultProps,
|
|
902
|
+
...core.props,
|
|
903
|
+
};
|
|
904
|
+
}
|
|
871
905
|
|
|
872
|
-
|
|
906
|
+
comp = new Component(core.props);
|
|
907
|
+
comp.render = entity.bind(comp);
|
|
908
|
+
comp[CORE].hooks = [];
|
|
909
|
+
comp[CORE].hook_index = 0;
|
|
910
|
+
} else {
|
|
911
|
+
throw new Error("Error in constructing component.");
|
|
912
|
+
}
|
|
873
913
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
comp.render = entity.bind(comp);
|
|
877
|
-
comp[CORE].hooks = [];
|
|
878
|
-
comp[CORE].hook_index = 0;
|
|
879
|
-
}
|
|
880
|
-
else {
|
|
881
|
-
throw new Error("Error in constructing component.");
|
|
882
|
-
}
|
|
914
|
+
comp[CORE].entity = entity;
|
|
915
|
+
registerComponentCore(comp[CORE]);
|
|
883
916
|
|
|
884
|
-
|
|
885
|
-
|
|
917
|
+
if (core.container) {
|
|
918
|
+
comp[CORE].container = core.container;
|
|
919
|
+
}
|
|
886
920
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
}
|
|
921
|
+
if (memoized) {
|
|
922
|
+
comp[CORE][MEMOIZED] = true;
|
|
890
923
|
}
|
|
924
|
+
}
|
|
891
925
|
|
|
892
|
-
|
|
926
|
+
if (parent instanceof ComponentCore) {
|
|
927
|
+
comp[CORE].parent = parent;
|
|
893
928
|
}
|
|
894
929
|
|
|
895
|
-
if(parent instanceof ComponentCore) comp[CORE].parent = parent;
|
|
896
930
|
return comp;
|
|
897
931
|
}
|
|
898
932
|
|
|
933
|
+
|
|
899
934
|
function prepareCore(parent, core) {
|
|
900
935
|
try {
|
|
901
936
|
parent.cache ??= new ComponentCache(parent);
|