@praxisjs/runtime 0.7.1 → 0.8.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.
- package/CHANGELOG.md +39 -0
- package/dist/children.d.ts.map +1 -1
- package/dist/children.js +2 -1
- package/dist/children.js.map +1 -1
- package/dist/component.d.ts +2 -3
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +133 -60
- package/dist/component.js.map +1 -1
- package/dist/context.d.ts +13 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +24 -2
- package/dist/context.js.map +1 -1
- package/dist/dom/constants.d.ts +1 -1
- package/dist/dom/constants.d.ts.map +1 -1
- package/dist/dom/constants.js +24 -83
- package/dist/dom/constants.js.map +1 -1
- package/dist/dom/create.d.ts +1 -1
- package/dist/dom/create.d.ts.map +1 -1
- package/dist/dom/create.js +3 -3
- package/dist/dom/create.js.map +1 -1
- package/dist/dom/events.d.ts +28 -0
- package/dist/dom/events.d.ts.map +1 -1
- package/dist/dom/events.js +163 -17
- package/dist/dom/events.js.map +1 -1
- package/dist/dom/props.d.ts +4 -0
- package/dist/dom/props.d.ts.map +1 -1
- package/dist/dom/props.js +61 -8
- package/dist/dom/props.js.map +1 -1
- package/dist/dom/range.d.ts +4 -0
- package/dist/dom/range.d.ts.map +1 -0
- package/dist/dom/range.js +43 -0
- package/dist/dom/range.js.map +1 -0
- package/dist/dom/remove.d.ts.map +1 -1
- package/dist/dom/remove.js +2 -8
- package/dist/dom/remove.js.map +1 -1
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +7 -5
- package/dist/element.js.map +1 -1
- package/dist/hmr.d.ts +35 -0
- package/dist/hmr.d.ts.map +1 -0
- package/dist/hmr.js +85 -0
- package/dist/hmr.js.map +1 -0
- package/dist/hydration-context.d.ts +9 -1
- package/dist/hydration-context.d.ts.map +1 -1
- package/dist/hydration-context.js +34 -13
- package/dist/hydration-context.js.map +1 -1
- package/dist/hydration.d.ts.map +1 -1
- package/dist/hydration.js +4 -11
- package/dist/hydration.js.map +1 -1
- package/dist/index.d.ts +16 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/dist/list.d.ts +72 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +786 -0
- package/dist/list.js.map +1 -0
- package/dist/portal.d.ts.map +1 -1
- package/dist/portal.js +3 -0
- package/dist/portal.js.map +1 -1
- package/dist/reactive.d.ts +2 -2
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +109 -34
- package/dist/reactive.js.map +1 -1
- package/dist/scope.d.ts +14 -4
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +55 -15
- package/dist/scope.js.map +1 -1
- package/dist/template.d.ts +48 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +270 -0
- package/dist/template.js.map +1 -0
- package/package.json +15 -6
- package/src/children.ts +2 -1
- package/src/component.ts +135 -63
- package/src/context.ts +35 -4
- package/src/dom/constants.ts +25 -82
- package/src/dom/create.ts +3 -3
- package/src/dom/events.ts +184 -16
- package/src/dom/props.ts +70 -9
- package/src/dom/range.ts +45 -0
- package/src/dom/remove.ts +3 -7
- package/src/element.ts +8 -6
- package/src/hmr.ts +110 -0
- package/src/hydration-context.ts +34 -13
- package/src/hydration.ts +4 -9
- package/src/index.ts +54 -7
- package/src/list.ts +886 -0
- package/src/portal.ts +3 -0
- package/src/reactive.ts +147 -40
- package/src/scope.ts +63 -16
- package/src/template.ts +271 -0
- package/dist/__tests__/children.test.d.ts +0 -2
- package/dist/__tests__/children.test.d.ts.map +0 -1
- package/dist/__tests__/children.test.js +0 -241
- package/dist/__tests__/children.test.js.map +0 -1
- package/dist/__tests__/component.test.d.ts +0 -2
- package/dist/__tests__/component.test.d.ts.map +0 -1
- package/dist/__tests__/component.test.js +0 -347
- package/dist/__tests__/component.test.js.map +0 -1
- package/dist/__tests__/context.test.d.ts +0 -2
- package/dist/__tests__/context.test.d.ts.map +0 -1
- package/dist/__tests__/context.test.js +0 -111
- package/dist/__tests__/context.test.js.map +0 -1
- package/dist/__tests__/dom.test.d.ts +0 -2
- package/dist/__tests__/dom.test.d.ts.map +0 -1
- package/dist/__tests__/dom.test.js +0 -429
- package/dist/__tests__/dom.test.js.map +0 -1
- package/dist/__tests__/hydration.test.d.ts +0 -2
- package/dist/__tests__/hydration.test.d.ts.map +0 -1
- package/dist/__tests__/hydration.test.js +0 -299
- package/dist/__tests__/hydration.test.js.map +0 -1
- package/dist/__tests__/portal.test.d.ts +0 -2
- package/dist/__tests__/portal.test.d.ts.map +0 -1
- package/dist/__tests__/portal.test.js +0 -157
- package/dist/__tests__/portal.test.js.map +0 -1
- package/dist/__tests__/remove.test.d.ts +0 -2
- package/dist/__tests__/remove.test.d.ts.map +0 -1
- package/dist/__tests__/remove.test.js +0 -45
- package/dist/__tests__/remove.test.js.map +0 -1
- package/dist/__tests__/render.test.d.ts +0 -2
- package/dist/__tests__/render.test.d.ts.map +0 -1
- package/dist/__tests__/render.test.js +0 -97
- package/dist/__tests__/render.test.js.map +0 -1
- package/dist/__tests__/scope.test.d.ts +0 -2
- package/dist/__tests__/scope.test.d.ts.map +0 -1
- package/dist/__tests__/scope.test.js +0 -110
- package/dist/__tests__/scope.test.js.map +0 -1
- package/src/__tests__/children.test.ts +0 -276
- package/src/__tests__/component.test.ts +0 -381
- package/src/__tests__/context.test.ts +0 -128
- package/src/__tests__/dom.test.ts +0 -483
- package/src/__tests__/hydration.test.ts +0 -360
- package/src/__tests__/portal.test.ts +0 -177
- package/src/__tests__/remove.test.ts +0 -51
- package/src/__tests__/render.test.ts +0 -119
- package/src/__tests__/scope.test.ts +0 -120
- package/tsconfig.json +0 -8
package/dist/dom/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/dom/events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["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, startBatch } from "@praxisjs/core/internal";
|
|
2
|
+
import { EVENT_MAP } from "./constants";
|
|
3
|
+
const HANDLERS = Symbol("praxis.handlers");
|
|
4
|
+
// One shared listener per element and event type dispatches to the handlers stored on the
|
|
5
|
+
// element, so binding a handler allocates no wrapper. Handlers run inside a batch so several
|
|
6
|
+
// signal writes in one event flush their effects once.
|
|
7
|
+
function dispatch(event) {
|
|
8
|
+
const slot = this[HANDLERS]?.[event.type];
|
|
9
|
+
if (slot === undefined)
|
|
10
|
+
return;
|
|
11
|
+
startBatch();
|
|
12
|
+
try {
|
|
13
|
+
if (typeof slot === "function") {
|
|
14
|
+
slot.call(this, event);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
for (const handler of slot.slice())
|
|
18
|
+
handler.call(this, event);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
endBatch();
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
export function addEvent(el, eventName, handler, scope) {
|
|
17
26
|
// Components forward optional handlers (`onSubmit={this.onSubmit}`) as-is, and addEventListener
|
|
18
27
|
// has always treated a missing listener as a no-op.
|
|
19
28
|
if (handler == null)
|
|
20
29
|
return;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
if (typeof handler !== "function") {
|
|
31
|
+
el.addEventListener(eventName, handler);
|
|
32
|
+
scope.add(() => { el.removeEventListener(eventName, handler); });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const host = el;
|
|
36
|
+
const handlers = (host[HANDLERS] ??= {});
|
|
37
|
+
const slot = handlers[eventName];
|
|
38
|
+
if (slot === undefined) {
|
|
39
|
+
// `in` tells a slot emptied by a disposed scope (listener still attached) from a new event type.
|
|
40
|
+
if (!(eventName in handlers))
|
|
41
|
+
el.addEventListener(eventName, dispatch);
|
|
42
|
+
handlers[eventName] = handler;
|
|
43
|
+
}
|
|
44
|
+
else if (typeof slot === "function") {
|
|
45
|
+
// Same as addEventListener: registering an identical listener twice is a no-op.
|
|
46
|
+
if (slot === handler)
|
|
47
|
+
return;
|
|
48
|
+
handlers[eventName] = [slot, handler];
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (slot.includes(handler))
|
|
52
|
+
return;
|
|
53
|
+
slot.push(handler);
|
|
54
|
+
}
|
|
55
|
+
scope.listen(el, eventName, handler);
|
|
56
|
+
}
|
|
57
|
+
const OWNER = Symbol("praxis.owner");
|
|
58
|
+
const GENERATION = Symbol("praxis.generation");
|
|
59
|
+
// Every event prop maps to its own event type (EVENT_MAP has no two props for one type), so an
|
|
60
|
+
// entry is created once per prop and found by type when an event comes in.
|
|
61
|
+
const byType = new Map();
|
|
62
|
+
// Keyed by event prop name (`onClick`), so binding a handler costs one lookup. `null` marks a prop
|
|
63
|
+
// that is not an event.
|
|
64
|
+
const byProp = new Map();
|
|
65
|
+
const watched = [];
|
|
66
|
+
const roots = new Set();
|
|
67
|
+
/** The delegated event type an event prop binds, or null when `key` is not an event prop. */
|
|
68
|
+
export function delegatedProp(key) {
|
|
69
|
+
let entry = byProp.get(key);
|
|
70
|
+
if (entry === undefined) {
|
|
71
|
+
const type = EVENT_MAP.get(key);
|
|
72
|
+
entry = null;
|
|
73
|
+
if (type !== undefined) {
|
|
74
|
+
entry = { key, type, slot: Symbol(`praxis.on.${type}`), attached: Symbol(`praxis.attached.${type}`), watched: false };
|
|
75
|
+
byType.set(type, entry);
|
|
76
|
+
}
|
|
77
|
+
byProp.set(key, entry);
|
|
78
|
+
}
|
|
79
|
+
return entry;
|
|
80
|
+
}
|
|
81
|
+
function dispatchDelegated(event) {
|
|
82
|
+
const host = this;
|
|
83
|
+
const handler = host[byType.get(event.type).slot];
|
|
84
|
+
if (handler === undefined || host[OWNER].gen !== host[GENERATION])
|
|
85
|
+
return;
|
|
86
|
+
startBatch();
|
|
87
|
+
try {
|
|
88
|
+
handler.call(this, event);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
endBatch();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function attachOnDemand(event) {
|
|
95
|
+
const { type, slot, attached } = byType.get(event.type);
|
|
96
|
+
for (const node of event.composedPath()) {
|
|
97
|
+
if (node === this)
|
|
98
|
+
return;
|
|
99
|
+
const host = node;
|
|
100
|
+
if (host[slot] !== undefined && host[attached] === undefined) {
|
|
101
|
+
host[attached] = true;
|
|
102
|
+
node.addEventListener(type, dispatchDelegated);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function watchType(entry) {
|
|
107
|
+
entry.watched = true;
|
|
108
|
+
watched.push(entry);
|
|
109
|
+
document.addEventListener(entry.type, attachOnDemand, true);
|
|
110
|
+
for (const root of roots)
|
|
111
|
+
root.addEventListener(entry.type, attachOnDemand, true);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Registers a render container (or portal target) whose subtree gets delegated handlers even while
|
|
115
|
+
* it is not in the document. Returns the function that unregisters it.
|
|
116
|
+
*/
|
|
117
|
+
export function addEventRoot(root) {
|
|
118
|
+
roots.add(root);
|
|
119
|
+
for (const entry of watched)
|
|
120
|
+
root.addEventListener(entry.type, attachOnDemand, true);
|
|
121
|
+
return () => {
|
|
122
|
+
roots.delete(root);
|
|
123
|
+
for (const entry of watched)
|
|
124
|
+
root.removeEventListener(entry.type, attachOnDemand, true);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Binds `handler` for the event of `entry` (see delegatedProp) on `el` without attaching a
|
|
129
|
+
* listener now (see above). Falls back to addEvent when no render container is registered (an
|
|
130
|
+
* element mounted outside render()), when the element already has a delegated handler for this
|
|
131
|
+
* type, or when it was bound by another scope.
|
|
132
|
+
*/
|
|
133
|
+
export function addDelegatedEvent(el, entry, handler, scope) {
|
|
134
|
+
if (handler == null)
|
|
135
|
+
return;
|
|
136
|
+
const host = el;
|
|
137
|
+
const key = entry.slot;
|
|
138
|
+
if (roots.size === 0 ||
|
|
139
|
+
typeof handler !== "function" ||
|
|
140
|
+
host[key] !== undefined ||
|
|
141
|
+
(host[OWNER] !== undefined && host[OWNER] !== scope)) {
|
|
142
|
+
addEvent(el, entry.type, handler, scope);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (!entry.watched)
|
|
146
|
+
watchType(entry);
|
|
147
|
+
host[key] = handler;
|
|
148
|
+
host[OWNER] = scope;
|
|
149
|
+
host[GENERATION] = scope.gen;
|
|
150
|
+
}
|
|
151
|
+
export function removeListener(el, eventName, handler) {
|
|
152
|
+
const handlers = el[HANDLERS];
|
|
153
|
+
const slot = handlers?.[eventName];
|
|
154
|
+
if (handlers === undefined || slot === undefined)
|
|
155
|
+
return;
|
|
156
|
+
if (typeof slot === "function") {
|
|
157
|
+
if (slot !== handler)
|
|
158
|
+
return;
|
|
159
|
+
// The shared listener stays registered: with an empty slot it does nothing, and leaving it
|
|
160
|
+
// saves a native call per handler when thousands of rows are disposed at once.
|
|
161
|
+
handlers[eventName] = undefined;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const index = slot.indexOf(handler);
|
|
165
|
+
if (index === -1)
|
|
166
|
+
return;
|
|
167
|
+
slot.splice(index, 1);
|
|
168
|
+
if (slot.length === 1)
|
|
169
|
+
handlers[eventName] = slot[0];
|
|
24
170
|
}
|
|
25
171
|
//# sourceMappingURL=events.js.map
|
package/dist/dom/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/dom/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/dom/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOxC,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,C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AAC,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/dom/props.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Scope } from "../scope";
|
|
2
|
+
export declare function hasWritableProperty(el: Element, key: string): boolean;
|
|
3
|
+
export declare function setProp(el: Element, key: string, value: unknown): void;
|
|
2
4
|
export declare function applyProp(el: Element, key: string, value: unknown, scope: Scope): void;
|
|
5
|
+
/** A reactive `class` prop, bound like any other reactive prop but with no key dispatch per run. */
|
|
6
|
+
export declare function bindClass(el: Element, read: () => unknown, scope: Scope): void;
|
|
3
7
|
//# sourceMappingURL=props.d.ts.map
|
package/dist/dom/props.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/dom/props.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/dom/props.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAuEtC,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAgBrE;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAYtE;AAED,wBAAgB,SAAS,CACvB,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,KAAK,GACX,IAAI,CAwBN;AA6CD,oGAAoG;AACpG,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAG9E"}
|
package/dist/dom/props.js
CHANGED
|
@@ -5,7 +5,17 @@ function applyClass(el, value) {
|
|
|
5
5
|
if (value === null || value === undefined) {
|
|
6
6
|
el.removeAttribute("class");
|
|
7
7
|
}
|
|
8
|
+
else if (el instanceof HTMLElement) {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
10
|
+
const next = String(value);
|
|
11
|
+
// Reading is cheap; writing invalidates the element's style even when nothing changes, which
|
|
12
|
+
// is what a first binding run does on every element whose class starts empty.
|
|
13
|
+
if (el.className !== next)
|
|
14
|
+
el.className = next;
|
|
15
|
+
}
|
|
8
16
|
else {
|
|
17
|
+
// SVG elements expose className as an SVGAnimatedString, so the attribute is the way in (as
|
|
18
|
+
// for any element of another kind, or of another window).
|
|
9
19
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
10
20
|
el.setAttribute("class", String(value));
|
|
11
21
|
}
|
|
@@ -32,7 +42,12 @@ function applyStyle(el, value) {
|
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
function applyAttr(el, key, value) {
|
|
35
|
-
if (
|
|
45
|
+
if (typeof value === "boolean" && key.startsWith("aria-")) {
|
|
46
|
+
// ARIA states are the strings "true" and "false", not HTML boolean attributes: an empty or
|
|
47
|
+
// missing aria-selected/aria-expanded reads as unset to assistive technology.
|
|
48
|
+
el.setAttribute(key, value ? "true" : "false");
|
|
49
|
+
}
|
|
50
|
+
else if (value === false || value === null || value === undefined) {
|
|
36
51
|
el.removeAttribute(key);
|
|
37
52
|
}
|
|
38
53
|
else if (value === true) {
|
|
@@ -59,7 +74,7 @@ function lookupWritable(proto, key) {
|
|
|
59
74
|
// must be excluded here or assignment below throws. The prototype walk is cached per
|
|
60
75
|
// prototype because every element of a given tag repeats the same lookups; a property defined on
|
|
61
76
|
// a prototype after its first lookup (e.g. a late polyfill) is therefore not picked up.
|
|
62
|
-
function hasWritableProperty(el, key) {
|
|
77
|
+
export function hasWritableProperty(el, key) {
|
|
63
78
|
const own = Object.getOwnPropertyDescriptor(el, key);
|
|
64
79
|
if (own)
|
|
65
80
|
return own.set !== undefined || own.writable === true;
|
|
@@ -76,7 +91,7 @@ function hasWritableProperty(el, key) {
|
|
|
76
91
|
}
|
|
77
92
|
return writable;
|
|
78
93
|
}
|
|
79
|
-
function setProp(el, key, value) {
|
|
94
|
+
export function setProp(el, key, value) {
|
|
80
95
|
if (key === "class" || key === "className") {
|
|
81
96
|
applyClass(el, value);
|
|
82
97
|
}
|
|
@@ -103,16 +118,54 @@ export function applyProp(el, key, value, scope) {
|
|
|
103
118
|
untrack(() => { value(el); });
|
|
104
119
|
return;
|
|
105
120
|
}
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
// Every event prop starts with "on": checking that first keeps other props off the map lookup.
|
|
122
|
+
const type = normalizedKey.startsWith("on") ? EVENT_MAP.get(normalizedKey) : undefined;
|
|
123
|
+
if (type !== undefined) {
|
|
124
|
+
addEvent(el, type, value, scope);
|
|
108
125
|
return;
|
|
109
126
|
}
|
|
110
127
|
if (typeof value === "function") {
|
|
111
|
-
|
|
112
|
-
setProp(el, normalizedKey, value());
|
|
113
|
-
});
|
|
128
|
+
bindProp(el, normalizedKey, value, scope);
|
|
114
129
|
return;
|
|
115
130
|
}
|
|
116
131
|
setProp(el, normalizedKey, value);
|
|
117
132
|
}
|
|
133
|
+
// State the user can change behind a binding's back (typing, toggling a <details>, the media
|
|
134
|
+
// controls, scrolling): always written, so a re-run puts the bound value back exactly as before.
|
|
135
|
+
const LIVE_PROPS = new Set([
|
|
136
|
+
"value", "checked", "selected", "indeterminate", "selectedIndex", "open",
|
|
137
|
+
"muted", "volume", "currentTime", "playbackRate", "scrollTop", "scrollLeft",
|
|
138
|
+
]);
|
|
139
|
+
const UNSET = Symbol("unset");
|
|
140
|
+
// One function for every binding, reading its state from the effect: no closure per binding.
|
|
141
|
+
function runBinding() {
|
|
142
|
+
const binding = this.ctx;
|
|
143
|
+
const value = binding.read();
|
|
144
|
+
// A binding re-runs when anything it read changes; most re-runs produce the same primitive,
|
|
145
|
+
// and skipping that write saves a DOM call and the style or attribute work behind it.
|
|
146
|
+
if (value === binding.last && (typeof value !== "object" || value === null))
|
|
147
|
+
return;
|
|
148
|
+
binding.last = value;
|
|
149
|
+
setProp(binding.el, binding.key, value);
|
|
150
|
+
}
|
|
151
|
+
function runLiveBinding() {
|
|
152
|
+
const binding = this.ctx;
|
|
153
|
+
setProp(binding.el, binding.key, binding.read());
|
|
154
|
+
}
|
|
155
|
+
function bindProp(el, key, read, scope) {
|
|
156
|
+
scope.contextEffect(LIVE_PROPS.has(key) ? runLiveBinding : runBinding, { el, key, read, last: UNSET });
|
|
157
|
+
}
|
|
158
|
+
function runClassBinding() {
|
|
159
|
+
const binding = this.ctx;
|
|
160
|
+
const value = binding.read();
|
|
161
|
+
if (value === binding.last && (typeof value !== "object" || value === null))
|
|
162
|
+
return;
|
|
163
|
+
binding.last = value;
|
|
164
|
+
applyClass(binding.el, value);
|
|
165
|
+
}
|
|
166
|
+
/** A reactive `class` prop, bound like any other reactive prop but with no key dispatch per run. */
|
|
167
|
+
export function bindClass(el, read, scope) {
|
|
168
|
+
// Same record shape as bindProp's, so the effects of both kinds stay one shape.
|
|
169
|
+
scope.contextEffect(runClassBinding, { el, key: "class", read, last: UNSET });
|
|
170
|
+
}
|
|
118
171
|
//# sourceMappingURL=props.js.map
|
package/dist/dom/props.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/dom/props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/dom/props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAmB,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,SAAS,UAAU,CAAC,EAAW,EAAE,KAAc;IAC7C,IAAI,KAAK,KAA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B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,KAAK,KAAK,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;QAAE,OAAO;IACpF,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;IACrB,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,SAAS,CAAC,EAAW,EAAE,IAAmB,EAAE,KAAY;IACtE,gFAAgF;IAChF,KAAK,CAAC,aAAa,CAAC,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function moveNode(parent: Node, node: Node, ref: Node | null): void;
|
|
2
|
+
export declare function moveRange(parent: Node, first: Node, last: Node, ref: Node | null): void;
|
|
3
|
+
export declare function removeRange(parent: Node, first: Node, last: Node): void;
|
|
4
|
+
//# sourceMappingURL=range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/dom/range.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAOzE;AAID,wBAAgB,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAYvF;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAYvE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// moveBefore() keeps focus, iframes, playing media and running CSS animations/transitions of the
|
|
2
|
+
// moved subtree, which a remove + insert resets. It only applies inside a connected tree (both nodes
|
|
3
|
+
// already share the parent here), so a detached parent such as a DocumentFragment uses insertBefore.
|
|
4
|
+
export function moveNode(parent, node, ref) {
|
|
5
|
+
const target = parent;
|
|
6
|
+
if (target.moveBefore !== undefined && target.isConnected) {
|
|
7
|
+
target.moveBefore(node, ref);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
parent.insertBefore(node, ref);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Every node from `first` to `last` (inclusive) moves, not only the tracked ones, so anything a
|
|
14
|
+
// nested reactive child inserted between them after mount travels with them.
|
|
15
|
+
export function moveRange(parent, first, last, ref) {
|
|
16
|
+
if (first === last) {
|
|
17
|
+
moveNode(parent, first, ref);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let node = first;
|
|
21
|
+
for (;;) {
|
|
22
|
+
const next = node.nextSibling;
|
|
23
|
+
moveNode(parent, node, ref);
|
|
24
|
+
if (node === last)
|
|
25
|
+
return;
|
|
26
|
+
node = next;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function removeRange(parent, first, last) {
|
|
30
|
+
if (first === last) {
|
|
31
|
+
parent.removeChild(first);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let node = first;
|
|
35
|
+
for (;;) {
|
|
36
|
+
const next = node.nextSibling;
|
|
37
|
+
parent.removeChild(node);
|
|
38
|
+
if (node === last)
|
|
39
|
+
return;
|
|
40
|
+
node = next;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/dom/range.ts"],"names":[],"mappings":"AAIA,iGAAiG;AACjG,qGAAqG;AACrG,qGAAqG;AACrG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,CAAC;AACH,CAAC"}
|
package/dist/dom/remove.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../src/dom/remove.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../src/dom/remove.ts"],"names":[],"mappings":"AAMA,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAW/C"}
|
package/dist/dom/remove.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { removeRange } from "./range";
|
|
1
2
|
// Replaces Range.deleteContents(): creating a Range per removal is several times slower than
|
|
2
3
|
// walking the siblings, and unreachable Ranges stay registered with the document until collected.
|
|
3
4
|
// Walking first → last (rather than only the tracked nodes) also removes anything a nested reactive
|
|
@@ -11,13 +12,6 @@ export function removeNodes(nodes) {
|
|
|
11
12
|
node.parentNode?.removeChild(node);
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
while (node) {
|
|
16
|
-
const next = node.nextSibling;
|
|
17
|
-
parent.removeChild(node);
|
|
18
|
-
if (node === last)
|
|
19
|
-
return;
|
|
20
|
-
node = next;
|
|
21
|
-
}
|
|
15
|
+
removeRange(parent, first, last);
|
|
22
16
|
}
|
|
23
17
|
//# sourceMappingURL=remove.js.map
|
package/dist/dom/remove.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../src/dom/remove.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,kGAAkG;AAClG,oGAAoG;AACpG,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC;IAEhC,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../src/dom/remove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,6FAA6F;AAC7F,kGAAkG;AAClG,oGAAoG;AACpG,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC;IAEhC,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;IAED,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/element.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,KAAK,GACX,WAAW,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,KAAK,GACX,WAAW,GAAG,UAAU,CAmB1B"}
|
package/dist/element.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { mountChildren } from "./children";
|
|
2
2
|
import { createElement } from "./dom/create";
|
|
3
3
|
import { applyProp } from "./dom/props";
|
|
4
|
-
import {
|
|
4
|
+
import { recording, recordProps } from "./hydration-context";
|
|
5
5
|
export function mountElement(tag, props, scope) {
|
|
6
6
|
const el = createElement(tag);
|
|
7
7
|
// During a hydration build pass, retain (props, scope) so reconcile() can
|
|
8
8
|
// replay them onto whichever real element it ends up keeping instead.
|
|
9
|
-
if (
|
|
9
|
+
if (recording)
|
|
10
10
|
recordProps(el, props, scope);
|
|
11
|
+
// Children before props: a prop that depends on them (a <select>'s value picking one of its
|
|
12
|
+
// options, a ref reading the subtree) would otherwise run against an empty element.
|
|
13
|
+
if (props.children !== undefined) {
|
|
14
|
+
mountChildren(el, props.children, scope);
|
|
15
|
+
}
|
|
11
16
|
for (const key in props) {
|
|
12
17
|
if (key === "children")
|
|
13
18
|
continue;
|
|
14
19
|
applyProp(el, key, props[key], scope);
|
|
15
20
|
}
|
|
16
|
-
if (props.children !== undefined) {
|
|
17
|
-
mountChildren(el, props.children, scope);
|
|
18
|
-
}
|
|
19
21
|
return el;
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=element.js.map
|
package/dist/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAI7D,MAAM,UAAU,YAAY,CAC1B,GAAW,EACX,KAA8B,EAC9B,KAAY;IAEZ,MAAM,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAE9B,0EAA0E;IAC1E,sEAAsE;IACtE,IAAI,SAAS;QAAE,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAE7C,4FAA4F;IAC5F,oFAAoF;IACpF,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,UAAU;YAAE,SAAS;QACjC,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/hmr.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ComponentConstructor } from "@praxisjs/shared/internal";
|
|
2
|
+
import type { Scope } from "./scope";
|
|
3
|
+
/** A mounted instance of a registered component: what it needs to be mounted again in place. */
|
|
4
|
+
export interface HotInstance {
|
|
5
|
+
ctor: ComponentConstructor;
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
parentScope: Scope;
|
|
8
|
+
scope: Scope;
|
|
9
|
+
start: Comment;
|
|
10
|
+
end: Comment;
|
|
11
|
+
}
|
|
12
|
+
/** True once a component class was registered: mountComponent then tracks hot instances. */
|
|
13
|
+
export declare let hotEnabled: boolean;
|
|
14
|
+
/** Set by the component module, which owns mounting (kept out of here to avoid an import cycle). */
|
|
15
|
+
export declare function setHotRemount(fn: (hot: HotInstance, ctor: ComponentConstructor) => void): void;
|
|
16
|
+
/** The newest class registered under the id of `ctor`, or `ctor` itself. */
|
|
17
|
+
export declare function latestClass(ctor: ComponentConstructor): ComponentConstructor;
|
|
18
|
+
export declare function isHotClass(ctor: ComponentConstructor): boolean;
|
|
19
|
+
/** Records a mounted instance of a registered class until its scope is disposed. */
|
|
20
|
+
export declare function trackHotInstance(hot: HotInstance): void;
|
|
21
|
+
/**
|
|
22
|
+
* Registers `ctor` under `id`. Called by the code the Vite plugin appends to each module in
|
|
23
|
+
* development, every time the module runs. Mounted instances of a class registered before under
|
|
24
|
+
* the same id are mounted again with `ctor`, in one microtask for every class of the update, so a
|
|
25
|
+
* parent and its children edited together render once. Returns false for a class that is not a
|
|
26
|
+
* component, which is not registered.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerHot(ctor: unknown, id: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether an updated module can replace its previous version in place: every export is a
|
|
31
|
+
* registered component class. Anything else (a helper, a constant, a store) may be held by the
|
|
32
|
+
* modules that import it, so the update has to reach them (Vite then re-runs or reloads them).
|
|
33
|
+
*/
|
|
34
|
+
export declare function acceptsHotUpdate(module: Record<string, unknown> | undefined): boolean;
|
|
35
|
+
//# sourceMappingURL=hmr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEnF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AASrC,gGAAgG;AAChG,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;CACd;AAOD,4FAA4F;AAC5F,eAAO,IAAI,UAAU,SAAQ,CAAC;AAS9B,oGAAoG;AACpG,wBAAgB,aAAa,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,oBAAoB,KAAK,IAAI,GAAG,IAAI,CAE9F;AAED,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,IAAI,EAAE,oBAAoB,GAAG,oBAAoB,CAG5E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAIvD;AAsBD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAa9D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,OAAO,CAIrF"}
|
package/dist/hmr.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isComponent } from "@praxisjs/shared/internal";
|
|
2
|
+
/** True once a component class was registered: mountComponent then tracks hot instances. */
|
|
3
|
+
export let hotEnabled = false;
|
|
4
|
+
// A WeakMap, not a static property: a subclass would inherit a property and resolve to its base.
|
|
5
|
+
const ids = new WeakMap();
|
|
6
|
+
const records = new Map();
|
|
7
|
+
const stale = new Set();
|
|
8
|
+
let remount = null;
|
|
9
|
+
/** Set by the component module, which owns mounting (kept out of here to avoid an import cycle). */
|
|
10
|
+
export function setHotRemount(fn) {
|
|
11
|
+
remount = fn;
|
|
12
|
+
}
|
|
13
|
+
/** The newest class registered under the id of `ctor`, or `ctor` itself. */
|
|
14
|
+
export function latestClass(ctor) {
|
|
15
|
+
const id = ids.get(ctor);
|
|
16
|
+
return id === undefined ? ctor : records.get(id).current;
|
|
17
|
+
}
|
|
18
|
+
export function isHotClass(ctor) {
|
|
19
|
+
return ids.has(ctor);
|
|
20
|
+
}
|
|
21
|
+
/** Records a mounted instance of a registered class until its scope is disposed. */
|
|
22
|
+
export function trackHotInstance(hot) {
|
|
23
|
+
const record = records.get(ids.get(hot.ctor));
|
|
24
|
+
record.instances.add(hot);
|
|
25
|
+
hot.scope.add(() => { record.instances.delete(hot); });
|
|
26
|
+
}
|
|
27
|
+
function flush() {
|
|
28
|
+
const records = [...stale];
|
|
29
|
+
stale.clear();
|
|
30
|
+
let error;
|
|
31
|
+
let failed = false;
|
|
32
|
+
for (const record of records) {
|
|
33
|
+
for (const hot of [...record.instances]) {
|
|
34
|
+
// Gone with a parent remounted before it, or already mounted with the new class.
|
|
35
|
+
if (!record.instances.has(hot) || hot.ctor === record.current)
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
remount(hot, record.current);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (!failed)
|
|
42
|
+
error = e;
|
|
43
|
+
failed = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (failed)
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Registers `ctor` under `id`. Called by the code the Vite plugin appends to each module in
|
|
52
|
+
* development, every time the module runs. Mounted instances of a class registered before under
|
|
53
|
+
* the same id are mounted again with `ctor`, in one microtask for every class of the update, so a
|
|
54
|
+
* parent and its children edited together render once. Returns false for a class that is not a
|
|
55
|
+
* component, which is not registered.
|
|
56
|
+
*/
|
|
57
|
+
export function registerHot(ctor, id) {
|
|
58
|
+
if (!isComponent(ctor))
|
|
59
|
+
return false;
|
|
60
|
+
hotEnabled = true;
|
|
61
|
+
ids.set(ctor, id);
|
|
62
|
+
const record = records.get(id);
|
|
63
|
+
if (record === undefined) {
|
|
64
|
+
records.set(id, { current: ctor, instances: new Set() });
|
|
65
|
+
}
|
|
66
|
+
else if (record.current !== ctor) {
|
|
67
|
+
record.current = ctor;
|
|
68
|
+
if (stale.size === 0)
|
|
69
|
+
queueMicrotask(flush);
|
|
70
|
+
stale.add(record);
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether an updated module can replace its previous version in place: every export is a
|
|
76
|
+
* registered component class. Anything else (a helper, a constant, a store) may be held by the
|
|
77
|
+
* modules that import it, so the update has to reach them (Vite then re-runs or reloads them).
|
|
78
|
+
*/
|
|
79
|
+
export function acceptsHotUpdate(module) {
|
|
80
|
+
if (module === undefined)
|
|
81
|
+
return false;
|
|
82
|
+
const values = Object.values(module);
|
|
83
|
+
return values.length > 0 && values.every((value) => typeof value === "function" && ids.has(value));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=hmr.js.map
|
package/dist/hmr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.js","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,MAAM,2BAA2B,CAAC;AA0BnF,4FAA4F;AAC5F,MAAM,CAAC,IAAI,UAAU,GAAG,KAAK,CAAC;AAE9B,iGAAiG;AACjG,MAAM,GAAG,GAAG,IAAI,OAAO,EAAgC,CAAC;AACxD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;AAC7C,MAAM,KAAK,GAAG,IAAI,GAAG,EAA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