creo 0.2.6 → 0.2.7
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/AGENTS.md +156 -0
- package/CHANGELOG.md +138 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +130 -87
- package/dist/index.js.map +10 -10
- package/dist/internal/internal_view.d.ts +6 -1
- package/dist/public/primitive.d.ts +9 -10
- package/dist/public/primitives/primitives.d.ts +341 -111
- package/dist/public/view.d.ts +27 -8
- package/dist/render/html_render.d.ts +1 -0
- package/docs/create-app.md +110 -0
- package/docs/events.md +236 -0
- package/docs/getting-started.md +201 -0
- package/docs/how-to/data-fetching.md +155 -0
- package/docs/how-to/deploy-vercel.md +130 -0
- package/docs/how-to/router.md +111 -0
- package/docs/how-to/styles.md +124 -0
- package/docs/how-to/suspense.md +116 -0
- package/docs/index.md +66 -0
- package/docs/lifecycle.md +173 -0
- package/docs/primitives.md +195 -0
- package/docs/renderers.md +183 -0
- package/docs/state.md +131 -0
- package/docs/store.md +135 -0
- package/docs/view.md +205 -0
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -23,9 +23,6 @@ function hasScStructuralChange(prev, next) {
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
// src/public/primitive.ts
|
|
27
|
-
var $primitive = Symbol("primitive");
|
|
28
|
-
|
|
29
26
|
// src/internal/orchestrator.ts
|
|
30
27
|
class Orchestrator {
|
|
31
28
|
#currentEngine;
|
|
@@ -39,6 +36,14 @@ class Orchestrator {
|
|
|
39
36
|
var orchestrator = new Orchestrator;
|
|
40
37
|
|
|
41
38
|
// src/public/view.ts
|
|
39
|
+
function applyRef(ref, value) {
|
|
40
|
+
if (!ref)
|
|
41
|
+
return;
|
|
42
|
+
if (typeof ref === "function")
|
|
43
|
+
ref(value);
|
|
44
|
+
else
|
|
45
|
+
ref.current = value;
|
|
46
|
+
}
|
|
42
47
|
function view(body) {
|
|
43
48
|
return (props, slot) => {
|
|
44
49
|
orchestrator.currentEngine().view(body, props, slot, maybeGetUserKey(props));
|
|
@@ -50,6 +55,9 @@ function maybeGetUserKey(params) {
|
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
// src/public/primitive.ts
|
|
59
|
+
var $primitive = Symbol("primitive");
|
|
60
|
+
|
|
53
61
|
// src/public/primitives/primitives.ts
|
|
54
62
|
function html(tag) {
|
|
55
63
|
const fn = ({
|
|
@@ -348,6 +356,12 @@ function lis(arr) {
|
|
|
348
356
|
}
|
|
349
357
|
|
|
350
358
|
// src/internal/engine.ts
|
|
359
|
+
function getConsumerRef(view2) {
|
|
360
|
+
if (view2.flags & F_PRIMITIVE)
|
|
361
|
+
return;
|
|
362
|
+
return view2.props?.ref;
|
|
363
|
+
}
|
|
364
|
+
|
|
351
365
|
class Engine {
|
|
352
366
|
renderer;
|
|
353
367
|
#dirtyQueue = new Set;
|
|
@@ -376,7 +390,8 @@ class Engine {
|
|
|
376
390
|
unsubscribe: null,
|
|
377
391
|
parent,
|
|
378
392
|
scHost: null,
|
|
379
|
-
pos: -1
|
|
393
|
+
pos: -1,
|
|
394
|
+
publicRef: null
|
|
380
395
|
};
|
|
381
396
|
if (slot2) {
|
|
382
397
|
if (typeof slot2 === "string") {
|
|
@@ -432,6 +447,10 @@ class Engine {
|
|
|
432
447
|
child.parent = this.#collectFor ?? view2;
|
|
433
448
|
this.#collector?.push(child);
|
|
434
449
|
}
|
|
450
|
+
},
|
|
451
|
+
ref: (value) => {
|
|
452
|
+
view2.publicRef = value;
|
|
453
|
+
applyRef(getConsumerRef(view2), value);
|
|
435
454
|
}
|
|
436
455
|
});
|
|
437
456
|
}
|
|
@@ -485,6 +504,14 @@ class Engine {
|
|
|
485
504
|
return collector;
|
|
486
505
|
}
|
|
487
506
|
nextProps(view2, nextProps, nextSlot, preCollectedSc) {
|
|
507
|
+
const prevRef = getConsumerRef(view2);
|
|
508
|
+
const nextRef = nextProps?.ref;
|
|
509
|
+
if (prevRef !== nextRef) {
|
|
510
|
+
if (prevRef)
|
|
511
|
+
applyRef(prevRef, null);
|
|
512
|
+
if (nextRef && view2.publicRef != null)
|
|
513
|
+
applyRef(nextRef, view2.publicRef);
|
|
514
|
+
}
|
|
488
515
|
const prevSc = view2.sc;
|
|
489
516
|
view2.slot = nextSlot;
|
|
490
517
|
if (preCollectedSc) {
|
|
@@ -758,6 +785,8 @@ class Engine {
|
|
|
758
785
|
}
|
|
759
786
|
}
|
|
760
787
|
}
|
|
788
|
+
view2.body?.dispose?.();
|
|
789
|
+
applyRef(getConsumerRef(view2), null);
|
|
761
790
|
if (view2.unsubscribe)
|
|
762
791
|
for (const unsub of view2.unsubscribe)
|
|
763
792
|
unsub();
|
|
@@ -773,6 +802,8 @@ class Engine {
|
|
|
773
802
|
for (const child of view2.children)
|
|
774
803
|
this.#disposeVirtual(child);
|
|
775
804
|
}
|
|
805
|
+
view2.body?.dispose?.();
|
|
806
|
+
applyRef(getConsumerRef(view2), null);
|
|
776
807
|
if (view2.unsubscribe)
|
|
777
808
|
for (const unsub of view2.unsubscribe)
|
|
778
809
|
unsub();
|
|
@@ -839,45 +870,6 @@ function createApp(slot2, renderer, options) {
|
|
|
839
870
|
};
|
|
840
871
|
}
|
|
841
872
|
// src/render/html_render.ts
|
|
842
|
-
function isEventProp(key) {
|
|
843
|
-
return key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.charCodeAt(2) >= 65 && key.charCodeAt(2) <= 90;
|
|
844
|
-
}
|
|
845
|
-
var DOM_EVENT = {
|
|
846
|
-
Click: "click",
|
|
847
|
-
Dblclick: "dblclick",
|
|
848
|
-
PointerDown: "pointerdown",
|
|
849
|
-
PointerUp: "pointerup",
|
|
850
|
-
PointerMove: "pointermove",
|
|
851
|
-
Input: "input",
|
|
852
|
-
Change: "change",
|
|
853
|
-
KeyDown: "keydown",
|
|
854
|
-
KeyUp: "keyup",
|
|
855
|
-
Focus: "focus",
|
|
856
|
-
Blur: "blur",
|
|
857
|
-
MouseEnter: "mouseenter",
|
|
858
|
-
MouseLeave: "mouseleave",
|
|
859
|
-
PointerEnter: "pointerenter",
|
|
860
|
-
PointerLeave: "pointerleave",
|
|
861
|
-
Scroll: "scroll",
|
|
862
|
-
Load: "load",
|
|
863
|
-
Error: "error",
|
|
864
|
-
Toggle: "toggle",
|
|
865
|
-
VolumeChange: "volumechange",
|
|
866
|
-
Play: "play",
|
|
867
|
-
Pause: "pause",
|
|
868
|
-
Ended: "ended",
|
|
869
|
-
TimeUpdate: "timeupdate",
|
|
870
|
-
LoadedMetadata: "loadedmetadata",
|
|
871
|
-
LoadedData: "loadeddata",
|
|
872
|
-
CanPlay: "canplay",
|
|
873
|
-
CanPlayThrough: "canplaythrough",
|
|
874
|
-
DurationChange: "durationchange",
|
|
875
|
-
RateChange: "ratechange",
|
|
876
|
-
Seeking: "seeking",
|
|
877
|
-
Seeked: "seeked",
|
|
878
|
-
Stalled: "stalled",
|
|
879
|
-
Waiting: "waiting"
|
|
880
|
-
};
|
|
881
873
|
var $EV = Symbol.for("creo.ev");
|
|
882
874
|
var containerState = new WeakMap;
|
|
883
875
|
function getState(container) {
|
|
@@ -894,7 +886,7 @@ function getState(container) {
|
|
|
894
886
|
if (evObj) {
|
|
895
887
|
const handler = evObj[domEvent];
|
|
896
888
|
if (handler) {
|
|
897
|
-
handler(mapEventData(domEvent, e));
|
|
889
|
+
handler(mapEventData(domEvent, e, dom));
|
|
898
890
|
if (e.cancelBubble)
|
|
899
891
|
return;
|
|
900
892
|
}
|
|
@@ -912,8 +904,6 @@ function getState(container) {
|
|
|
912
904
|
var CAPTURE_EVENTS = new Set([
|
|
913
905
|
"focus",
|
|
914
906
|
"blur",
|
|
915
|
-
"mouseenter",
|
|
916
|
-
"mouseleave",
|
|
917
907
|
"pointerenter",
|
|
918
908
|
"pointerleave",
|
|
919
909
|
"scroll",
|
|
@@ -937,8 +927,6 @@ var CAPTURE_EVENTS = new Set([
|
|
|
937
927
|
"waiting"
|
|
938
928
|
]);
|
|
939
929
|
var NO_WALK_EVENTS = new Set([
|
|
940
|
-
"mouseenter",
|
|
941
|
-
"mouseleave",
|
|
942
930
|
"pointerenter",
|
|
943
931
|
"pointerleave"
|
|
944
932
|
]);
|
|
@@ -974,8 +962,7 @@ var POINTER_EVENTS = new Set([
|
|
|
974
962
|
"pointerdown",
|
|
975
963
|
"pointerup",
|
|
976
964
|
"pointermove",
|
|
977
|
-
"
|
|
978
|
-
"mouseleave",
|
|
965
|
+
"pointercancel",
|
|
979
966
|
"pointerenter",
|
|
980
967
|
"pointerleave"
|
|
981
968
|
]);
|
|
@@ -996,11 +983,32 @@ var MEDIA_EVENTS = new Set([
|
|
|
996
983
|
"stalled",
|
|
997
984
|
"waiting"
|
|
998
985
|
]);
|
|
999
|
-
function mapEventData(domEvent, e) {
|
|
986
|
+
function mapEventData(domEvent, e, currentTarget) {
|
|
1000
987
|
let data2;
|
|
1001
988
|
if (POINTER_EVENTS.has(domEvent)) {
|
|
1002
989
|
const pe = e;
|
|
1003
|
-
|
|
990
|
+
const pointerId = typeof pe.pointerId === "number" ? pe.pointerId : -1;
|
|
991
|
+
data2 = {
|
|
992
|
+
x: pe.clientX,
|
|
993
|
+
y: pe.clientY,
|
|
994
|
+
pointerId,
|
|
995
|
+
pointerType: typeof pe.pointerType === "string" ? pe.pointerType : "",
|
|
996
|
+
button: typeof pe.button === "number" ? pe.button : 0,
|
|
997
|
+
buttons: typeof pe.buttons === "number" ? pe.buttons : 0,
|
|
998
|
+
target: e.target,
|
|
999
|
+
currentTarget,
|
|
1000
|
+
capture: () => {
|
|
1001
|
+
if (pointerId >= 0 && currentTarget.setPointerCapture) {
|
|
1002
|
+
currentTarget.setPointerCapture(pointerId);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
release: () => {
|
|
1006
|
+
if (pointerId >= 0 && currentTarget.releasePointerCapture) {
|
|
1007
|
+
currentTarget.releasePointerCapture(pointerId);
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
nativeEvent: e
|
|
1011
|
+
};
|
|
1004
1012
|
} else if (domEvent === "input" || domEvent === "change") {
|
|
1005
1013
|
const target = e.target;
|
|
1006
1014
|
data2 = { value: target.value, checked: !!target.checked };
|
|
@@ -1081,6 +1089,9 @@ class HtmlRender {
|
|
|
1081
1089
|
if (props != null && props.autofocus === true && typeof element.focus === "function") {
|
|
1082
1090
|
element.focus();
|
|
1083
1091
|
}
|
|
1092
|
+
if (props != null) {
|
|
1093
|
+
applyRef(props.ref, element);
|
|
1094
|
+
}
|
|
1084
1095
|
}
|
|
1085
1096
|
} else {
|
|
1086
1097
|
view2.renderRef = true;
|
|
@@ -1188,59 +1199,88 @@ class HtmlRender {
|
|
|
1188
1199
|
return this.findInsertionPoint(parent);
|
|
1189
1200
|
}
|
|
1190
1201
|
setAttributes(element, props) {
|
|
1202
|
+
if (props == null)
|
|
1203
|
+
return;
|
|
1191
1204
|
for (const key in props) {
|
|
1192
1205
|
const value = props[key];
|
|
1193
|
-
if (key === "key" || value == null)
|
|
1206
|
+
if (key === "key" || key === "ref" || key === "on" || value == null)
|
|
1194
1207
|
continue;
|
|
1195
|
-
if (isEventProp(key)) {
|
|
1196
|
-
this.bindEvent(element, key, value);
|
|
1197
|
-
continue;
|
|
1198
|
-
}
|
|
1199
1208
|
this.setAttribute(element, key, value);
|
|
1200
1209
|
}
|
|
1210
|
+
const on = props.on;
|
|
1211
|
+
if (on) {
|
|
1212
|
+
for (const ev in on) {
|
|
1213
|
+
const handler = on[ev];
|
|
1214
|
+
if (handler)
|
|
1215
|
+
this.bindEvent(element, ev, handler);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1201
1218
|
}
|
|
1202
1219
|
diffAttributes(element, prev, next) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
if (
|
|
1208
|
-
this.unbindEvent(element, key);
|
|
1209
|
-
} else {
|
|
1220
|
+
if (prev) {
|
|
1221
|
+
for (const key in prev) {
|
|
1222
|
+
if (key === "key" || key === "ref" || key === "on")
|
|
1223
|
+
continue;
|
|
1224
|
+
if (next == null || !(key in next) || next[key] == null) {
|
|
1210
1225
|
this.removeAttribute(element, key);
|
|
1211
1226
|
}
|
|
1212
1227
|
}
|
|
1213
1228
|
}
|
|
1214
|
-
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1229
|
+
if (next) {
|
|
1230
|
+
for (const key in next) {
|
|
1231
|
+
const value = next[key];
|
|
1232
|
+
if (key === "key" || key === "ref" || key === "on" || value == null)
|
|
1233
|
+
continue;
|
|
1234
|
+
if (prev && prev[key] === value && !DOM_PROPERTIES.has(key))
|
|
1235
|
+
continue;
|
|
1236
|
+
this.setAttribute(element, key, value);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
const prevOn = prev?.on;
|
|
1240
|
+
const nextOn = next?.on;
|
|
1241
|
+
if (prevOn !== nextOn) {
|
|
1242
|
+
this.diffEvents(element, prevOn, nextOn);
|
|
1243
|
+
}
|
|
1244
|
+
const prevRef = prev?.ref;
|
|
1245
|
+
const nextRef = next?.ref;
|
|
1246
|
+
if (prevRef !== nextRef) {
|
|
1247
|
+
applyRef(prevRef, null);
|
|
1248
|
+
applyRef(nextRef, element);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
diffEvents(element, prev, next) {
|
|
1252
|
+
if (prev) {
|
|
1253
|
+
for (const ev in prev) {
|
|
1254
|
+
if (!next || next[ev] == null) {
|
|
1255
|
+
this.unbindEvent(element, ev);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (next) {
|
|
1260
|
+
for (const ev in next) {
|
|
1261
|
+
const value = next[ev];
|
|
1262
|
+
if (value == null)
|
|
1263
|
+
continue;
|
|
1264
|
+
if (prev && prev[ev] === value)
|
|
1265
|
+
continue;
|
|
1266
|
+
const domEvent = ev.toLowerCase();
|
|
1223
1267
|
const evObj = element[$EV];
|
|
1224
1268
|
if (evObj && domEvent in evObj) {
|
|
1225
1269
|
evObj[domEvent] = value;
|
|
1226
1270
|
} else {
|
|
1227
|
-
this.bindEvent(element,
|
|
1271
|
+
this.bindEvent(element, ev, value);
|
|
1228
1272
|
}
|
|
1229
|
-
} else {
|
|
1230
|
-
this.setAttribute(element, key, value);
|
|
1231
1273
|
}
|
|
1232
1274
|
}
|
|
1233
1275
|
}
|
|
1234
|
-
bindEvent(element,
|
|
1235
|
-
const
|
|
1236
|
-
const domEvent = DOM_EVENT[creoName] ?? creoName.toLowerCase();
|
|
1276
|
+
bindEvent(element, eventName, handler) {
|
|
1277
|
+
const domEvent = eventName.toLowerCase();
|
|
1237
1278
|
const evObj = element[$EV] ?? (element[$EV] = {});
|
|
1238
1279
|
evObj[domEvent] = handler;
|
|
1239
1280
|
ensureDelegated(this.container, domEvent);
|
|
1240
1281
|
}
|
|
1241
|
-
unbindEvent(element,
|
|
1242
|
-
const
|
|
1243
|
-
const domEvent = DOM_EVENT[creoName] ?? creoName.toLowerCase();
|
|
1282
|
+
unbindEvent(element, eventName) {
|
|
1283
|
+
const domEvent = eventName.toLowerCase();
|
|
1244
1284
|
const evObj = element[$EV];
|
|
1245
1285
|
if (evObj) {
|
|
1246
1286
|
delete evObj[domEvent];
|
|
@@ -1314,6 +1354,9 @@ class HtmlRender {
|
|
|
1314
1354
|
}
|
|
1315
1355
|
delete ref.element[$EV];
|
|
1316
1356
|
}
|
|
1357
|
+
const prevProps = ref.prevProps;
|
|
1358
|
+
if (prevProps)
|
|
1359
|
+
applyRef(prevProps.ref, null);
|
|
1317
1360
|
ref.element.parentNode?.removeChild(ref.element);
|
|
1318
1361
|
}
|
|
1319
1362
|
}
|
|
@@ -1398,9 +1441,6 @@ var VOID_TAGS = new Set([
|
|
|
1398
1441
|
"wbr"
|
|
1399
1442
|
]);
|
|
1400
1443
|
var DOM_PROPERTIES2 = new Set(["value", "checked", "selected", "indeterminate", "muted"]);
|
|
1401
|
-
function isEventProp2(key) {
|
|
1402
|
-
return key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.charCodeAt(2) >= 65 && key.charCodeAt(2) <= 90;
|
|
1403
|
-
}
|
|
1404
1444
|
function escapeHtml(str) {
|
|
1405
1445
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1406
1446
|
}
|
|
@@ -1437,12 +1477,14 @@ class HtmlStringRender {
|
|
|
1437
1477
|
return this.buildChildren(rec);
|
|
1438
1478
|
}
|
|
1439
1479
|
buildAttrs(props) {
|
|
1480
|
+
if (props == null)
|
|
1481
|
+
return "";
|
|
1440
1482
|
let result = "";
|
|
1441
1483
|
for (const key in props) {
|
|
1442
1484
|
const value = props[key];
|
|
1443
1485
|
if (key === "key" || value == null)
|
|
1444
1486
|
continue;
|
|
1445
|
-
if (
|
|
1487
|
+
if (key === "on" || key === "ref")
|
|
1446
1488
|
continue;
|
|
1447
1489
|
if (DOM_PROPERTIES2.has(key))
|
|
1448
1490
|
continue;
|
|
@@ -1605,6 +1647,7 @@ export {
|
|
|
1605
1647
|
aside,
|
|
1606
1648
|
article,
|
|
1607
1649
|
area,
|
|
1650
|
+
applyRef,
|
|
1608
1651
|
address,
|
|
1609
1652
|
abbr,
|
|
1610
1653
|
a,
|
|
@@ -1618,4 +1661,4 @@ export {
|
|
|
1618
1661
|
$primitive
|
|
1619
1662
|
};
|
|
1620
1663
|
|
|
1621
|
-
//# debugId=
|
|
1664
|
+
//# debugId=020C6F0F4AB24D1164756E2164756E21
|