@praxisjs/runtime 0.7.1 → 0.8.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/CHANGELOG.md +33 -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 +55 -7
- 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 +65 -8
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @praxisjs/runtime
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 75115a9: Component hot module replacement. In the dev server, `@praxisjs/vite-plugin` registers each top-level class of the app's modules with `@praxisjs/runtime` (`_$hmrRegister`), and a module whose exports are all component classes accepts its own update: every mounted instance of an edited component renders again in place with the new class, without a page reload. Modules that export anything else keep Vite's default handling.
|
|
8
|
+
- 75115a9: Fix fragments dropping function children: `<>{() => x}</>` now mounts a reactive region, like element children. `@praxisjs/runtime` exports `mountChildren`, which `@praxisjs/jsx` uses to mount fragment children.
|
|
9
|
+
- 75115a9: Add keyed list reconciliation. `For` (keyed by `by`, or by item identity) and `Index` (by position) in `@praxisjs/runtime` render each key once, keep its row while the key stays, and create, move or remove only the rows that changed, with the minimum number of moves (LIS) and `moveBefore()` where available. They support fallbacks, Promise-based enter/leave transitions, hydration of prerendered rows, and isolate row render errors. `@praxisjs/jsx` types components that set `static __jsxRawProps = true` by their exact constructor props, so `For` infers its item type. `@praxisjs/vite-plugin` rewrites keyed `{() => list.map((item) => <Row key={…} />)}` children into `For` and warns about keyed `.map()` calls it cannot rewrite (`keyedLists` option).
|
|
10
|
+
- 75115a9: Rendering and reactivity performance overhaul. `@praxisjs/core` has a new push-pull reactive graph (linked dependencies reused across runs, version-checked computeds, glitch-free effects) and keeps component internals on the instance. `@praxisjs/decorators` shares one accessor pair per `@State`/`@Prop` field, creates `@Computed` lazily, and `@Component` no longer wraps the class. `@praxisjs/runtime` adds the compiled-template helpers, a shared event dispatcher, leaner scopes and reactive children, skipped no-op prop writes, cheaper component mounting and a detached fill for large `For` renders, and fixes a static `<select>` value being lost. `@praxisjs/vite-plugin` compiles JSX trees of host elements into templates cloned per render (`templates` option, on by default).
|
|
11
|
+
- 75115a9: Smaller startup: `render()` hydrates only after the new `enableHydration()` (called by `ssgPlugin()`), so apps that don't prerender leave the hydration code out. **Breaking:** an app that hydrates server-rendered HTML without `ssgPlugin()` must call `enableHydration()` before `render()`. Also, compiled templates whose tree the HTML parser reads back unchanged are emitted as markup and parsed once (`_$html`); decorated fields, methods and classes call shorter lowering helpers; the list view's internal members are `#private`.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 75115a9: DevTools: a Performance panel and `profiler` that record signal writes, effect runs and computed recomputations with their cost, grouped by the component that created each effect; `@Debug({ log, break })`, reactive observation of accessor fields (props included), promise-aware method timing, `@Trace({ slow })`, inert decorators in production builds, and a faster registry. Core exposes the observer hooks the profiler uses (`setReactiveObserver`, `setCurrentOwner`, `getEffectOwner` in `@praxisjs/core/internal`), which cost one null check while no observer is installed; the runtime marks the rendering component as the owner of the effects it creates.
|
|
16
|
+
- 75115a9: Edge-case fixes in the new fast paths. `@praxisjs/vite-plugin` keeps a claimed field's initializer in the field's own scope instead of moving it into the constructor, where a constructor parameter or local of the same name shadowed what it read (and `new.target` fields are claimed too). `selector()` from `@praxisjs/core` compares against the current source value when read outside an effect, also inside a batch or an event handler before its subscribers are notified. `@praxisjs/runtime` keeps updating a hydrated element through a reactive child that fills it alone, rebuilds compiled templates when `render()` runs with another global document (a new SSG window), and always writes `open`, `selectedIndex`, media and scroll props from reactive bindings so a re-run restores what the user changed. Compiled templates keep the leading whitespace of JSX text (`{v} / {m}` lost its first space) and keep tabs inside a line, as the JSX transform does. Methods of `@Bind`, `@Emit` and the other built-in method decorators can be spied on with `vi.spyOn(instance, name)` before their first read again. `@praxisjs/router`'s `Link` removes its `class` attribute when it stops being active instead of leaving `class=""`.
|
|
17
|
+
- 75115a9: Published packages no longer contain their tests: package builds compile `src` without `src/**/__tests__` (through a `tsconfig.build.json`), and each package's `files` leaves test sources and stale compiled tests out of the tarball. `pnpm typecheck` still type-checks the tests.
|
|
18
|
+
- 75115a9: Cheaper creation of rows and components. `@praxisjs/runtime` builds and clones compiled templates in the inert `<template>` document (live document for templates with custom elements) and no longer touches `document` at import time, binds template event props without a listener (one capture listener per event type on the document and on each render container attaches an element's own listener on first use, same dispatch semantics), runs reactive props and children through shared functions with per-binding records instead of closures, creates text natively without JS wrappers, forks a reactive child's scope only when a run asks for it, stops wrapping single-root components in comments, writes only-child text with `textContent` and inserts arrays without a fragment. Compiled event props bind through a per-module target (`_$event`/`_$onEvent`) and reactive `class` props through `_$className`, skipping the generic prop dispatch. `@praxisjs/core`'s `getComponentAnchor()` returns a `Node` (a single-root component is anchored on its root) and every `selector()` shares one bucket class, `createContextEffect()` runs an effect whose shared function reads its state from `this.ctx`; effects record their owner even when no reactive observer is installed (`getEffectOwner()` reads it from the node). `@praxisjs/vite-plugin` also compiles lone elements that have something static or a reactive child, emits the delegated event bindings, emits a template that is an arrow function's whole body or a `return` operand as plain statements, leaves no placeholder for a reactive only child, hoists one event target per event prop name and module, emits a dedicated binding for a reactive `class`/`className`, and no longer wraps a JSX tree used as an attribute value of a compiled element in braces. Both packages keep one inert instance of each hot internal class (graph nodes and links, selector buckets, scopes, list rows, reactive children) so their V8 hidden classes survive a full GC after a list is cleared, and every list row gets the same hidden class whatever it renders.
|
|
19
|
+
- 75115a9: Update reactive text in place. A reactive child that returns a string or number rewrites its existing text node, and skips the write when the text is unchanged, instead of replacing the node on every re-run.
|
|
20
|
+
- 75115a9: Smaller production bundles. The framework and feature packages are marked `"sideEffects": false`, so bundlers leave out the modules an app does not use (`For`/`Index` and `selector()` were kept in every bundle by their shape keepers). `@praxisjs/core`'s graph gates its observer instrumentation on a boolean that minifiers fold away when no observer is ever installed. `@praxisjs/runtime` passes `Index`'s positional update to the list view, so `For`-only apps leave it out, and builds its event prop table from camel-case names. `@praxisjs/devtools` is built one file per module and its decorators check `process.env.NODE_ENV` inline, so `@Trace`/`@Debug` in production code no longer bundle the registry and the panel. `@praxisjs/vite-plugin` serves TypeScript's decorator helpers and the claimed fields' helper from one virtual module (`virtual:praxisjs/decorators`) instead of writing them into every decorated file, and replaces the identical copies `tsc` wrote into ES module libraries.
|
|
21
|
+
- Updated dependencies [75115a9]
|
|
22
|
+
- Updated dependencies [75115a9]
|
|
23
|
+
- Updated dependencies [75115a9]
|
|
24
|
+
- Updated dependencies [75115a9]
|
|
25
|
+
- Updated dependencies [75115a9]
|
|
26
|
+
- Updated dependencies [75115a9]
|
|
27
|
+
- Updated dependencies [75115a9]
|
|
28
|
+
- Updated dependencies [75115a9]
|
|
29
|
+
- Updated dependencies [75115a9]
|
|
30
|
+
- Updated dependencies [75115a9]
|
|
31
|
+
- Updated dependencies [75115a9]
|
|
32
|
+
- @praxisjs/decorators@2.0.0
|
|
33
|
+
- @praxisjs/core@2.3.0
|
|
34
|
+
- @praxisjs/shared@0.3.2
|
|
35
|
+
|
|
3
36
|
## 0.7.1
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/dist/children.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,aAAa,CAC3B,MAAM,EAAE,IAAI,EACZ,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,KAAK,GACX,IAAI,
|
|
1
|
+
{"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,aAAa,CAC3B,MAAM,EAAE,IAAI,EACZ,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,KAAK,GACX,IAAI,CAyBN"}
|
package/dist/children.js
CHANGED
|
@@ -3,7 +3,8 @@ export function mountChildren(parent, children, scope) {
|
|
|
3
3
|
if (children === null || children === undefined || children === false)
|
|
4
4
|
return;
|
|
5
5
|
if (typeof children === "string" || typeof children === "number") {
|
|
6
|
-
|
|
6
|
+
// append() builds the text node natively: no JS wrapper is created for it.
|
|
7
|
+
parent.append(String(children));
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
10
|
if (typeof children === "function") {
|
package/dist/children.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"children.js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,CAAC;QACD,OAAO;IACT,CAAC;AACH,CAAC"}
|
package/dist/component.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ComponentConstructor } from "@praxisjs/shared/internal";
|
|
2
2
|
import type { Scope } from "./scope";
|
|
3
|
-
export declare function mountComponent(ctor: ComponentConstructor, props: Record<string, unknown>, parentScope: Scope): Node[];
|
|
4
|
-
export { isComponent };
|
|
3
|
+
export declare function mountComponent(ctor: ComponentConstructor, props: Record<string, unknown>, parentScope: Scope, bounds?: [Comment, Comment] | null): Node[];
|
|
5
4
|
//# sourceMappingURL=component.d.ts.map
|
package/dist/component.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAOtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAsDrC,wBAAgB,cAAc,CAC5B,IAAI,EAAE,oBAAoB,EAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,WAAW,EAAE,KAAK,EAElB,MAAM,GAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,IAAW,GACvC,IAAI,EAAE,CAgFR"}
|
package/dist/component.js
CHANGED
|
@@ -1,78 +1,151 @@
|
|
|
1
|
-
import { setComponentAnchor, setComponentMounted,
|
|
1
|
+
import { getComponentStart, pauseTracking, resumeTracking, setCurrentOwner, setComponentAnchor, setComponentMounted, } from "@praxisjs/core/internal";
|
|
2
2
|
import { initSlots } from "@praxisjs/decorators";
|
|
3
|
-
import { isComponent } from "@praxisjs/shared/internal";
|
|
4
3
|
import { mountChildren } from "./children";
|
|
5
|
-
import {
|
|
4
|
+
import { swapScope } from "./context";
|
|
5
|
+
import { hotEnabled, isHotClass, latestClass, setHotRemount, trackHotInstance } from "./hmr";
|
|
6
|
+
import { recording, onHydrationReplace } from "./hydration-context";
|
|
7
|
+
// One object per component carries both lifecycle steps: mounting (drained in a shared microtask)
|
|
8
|
+
// and disposal (registered in the component's scope), instead of a closure for each.
|
|
9
|
+
class ComponentLife {
|
|
10
|
+
constructor(instance, ref) {
|
|
11
|
+
this.disposed = false;
|
|
12
|
+
this.instance = instance;
|
|
13
|
+
this.ref = ref;
|
|
14
|
+
}
|
|
15
|
+
mount() {
|
|
16
|
+
if (this.disposed)
|
|
17
|
+
return;
|
|
18
|
+
setComponentMounted(this.instance, true);
|
|
19
|
+
this.instance.onMount?.();
|
|
20
|
+
this.ref?.(this.instance);
|
|
21
|
+
}
|
|
22
|
+
dispose() {
|
|
23
|
+
this.disposed = true;
|
|
24
|
+
this.instance.onUnmount?.();
|
|
25
|
+
setComponentMounted(this.instance, false);
|
|
26
|
+
this.ref?.(null);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
6
29
|
let pendingMounts = [];
|
|
7
30
|
// One shared microtask drains every component mounted in the same synchronous pass, in mount
|
|
8
31
|
// order (children before parents). A throwing onMount is rethrown on its own microtask so it
|
|
9
32
|
// can't stop the others, as it couldn't when each component had a microtask of its own.
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
queueMicrotask(() => { throw e; });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
33
|
+
function drainMounts() {
|
|
34
|
+
const queue = pendingMounts;
|
|
35
|
+
pendingMounts = [];
|
|
36
|
+
for (const life of queue) {
|
|
37
|
+
try {
|
|
38
|
+
life.mount();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
queueMicrotask(() => { throw e; });
|
|
42
|
+
}
|
|
24
43
|
}
|
|
25
|
-
pendingMounts.push(run);
|
|
26
44
|
}
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
function scheduleMount(life) {
|
|
46
|
+
if (pendingMounts.length === 0)
|
|
47
|
+
queueMicrotask(drainMounts);
|
|
48
|
+
pendingMounts.push(life);
|
|
49
|
+
}
|
|
50
|
+
export function mountComponent(ctor, props, parentScope,
|
|
51
|
+
// Hot remount only: the comments of the instance being replaced, kept as the new one's bounds.
|
|
52
|
+
bounds = null) {
|
|
53
|
+
const prevSub = pauseTracking();
|
|
54
|
+
try {
|
|
55
|
+
// A registered class (development, see hmr.ts) always mounts its newest version, and every
|
|
56
|
+
// instance gets comment bounds, which stay in place when it is mounted again.
|
|
57
|
+
let hot = false;
|
|
58
|
+
if (hotEnabled) {
|
|
59
|
+
ctor = latestClass(ctor);
|
|
60
|
+
hot = isHotClass(ctor);
|
|
61
|
+
}
|
|
29
62
|
const scope = parentScope.fork();
|
|
30
|
-
// Strip ref — managed by the runtime, not forwarded to the component.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
// Strip ref — managed by the runtime, not forwarded to the component. The component copies its
|
|
64
|
+
// props itself, so they are only copied here when there is a ref to leave out.
|
|
65
|
+
let instanceProps = props;
|
|
66
|
+
let ref;
|
|
67
|
+
if ("ref" in props) {
|
|
68
|
+
const { ref: refFn, ...rest } = props;
|
|
69
|
+
instanceProps = rest;
|
|
70
|
+
if (typeof refFn === "function")
|
|
71
|
+
ref = refFn;
|
|
72
|
+
}
|
|
73
|
+
const instance = new ctor(instanceProps);
|
|
36
74
|
const rawChildren = instanceProps.children;
|
|
37
75
|
if (rawChildren != null) {
|
|
38
76
|
initSlots(instance, rawChildren);
|
|
39
77
|
}
|
|
40
|
-
const start = document.createComment(`[${ctor.name}]`);
|
|
41
|
-
const end = document.createComment(`[/${ctor.name}]`);
|
|
42
|
-
let disposed = false;
|
|
43
|
-
setComponentAnchor(instance, end);
|
|
44
78
|
instance.onBeforeMount?.();
|
|
45
|
-
const container = document.createDocumentFragment();
|
|
46
|
-
container.appendChild(start);
|
|
47
79
|
let dom = null;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
const prevScope = swapScope(scope);
|
|
81
|
+
const prevOwner = setCurrentOwner(instance);
|
|
82
|
+
try {
|
|
83
|
+
dom = instance.render();
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
const fallback = instance.onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
87
|
+
if (fallback != null)
|
|
88
|
+
dom = fallback;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
setCurrentOwner(prevOwner);
|
|
92
|
+
swapScope(prevScope);
|
|
93
|
+
}
|
|
94
|
+
let nodes;
|
|
95
|
+
if (hot) {
|
|
96
|
+
const container = document.createDocumentFragment();
|
|
97
|
+
const start = bounds === null ? container.appendChild(document.createComment(`[${ctor.name}]`)) : bounds[0];
|
|
98
|
+
mountChildren(container, dom, scope);
|
|
99
|
+
const end = bounds === null ? container.appendChild(document.createComment(`[/${ctor.name}]`)) : bounds[1];
|
|
100
|
+
setComponentAnchor(instance, end);
|
|
101
|
+
nodes = Array.from(container.childNodes);
|
|
102
|
+
trackHotInstance({ ctor, props, parentScope, scope, start, end });
|
|
103
|
+
}
|
|
104
|
+
else if (dom instanceof Node && dom.nodeType !== 11) {
|
|
105
|
+
// A single root node can't change, so it bounds the component by itself: no comments.
|
|
106
|
+
nodes = [dom];
|
|
107
|
+
setComponentAnchor(instance, dom);
|
|
108
|
+
if (recording)
|
|
109
|
+
onHydrationReplace(dom, (real) => { setComponentAnchor(instance, real); });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Several nodes, or ones a reactive child may replace: comments mark where the component
|
|
113
|
+
// starts and ends, unless its render already brought them (see getComponentStart).
|
|
114
|
+
const bounded = getComponentStart(instance) !== undefined;
|
|
115
|
+
const container = document.createDocumentFragment();
|
|
116
|
+
if (!bounded)
|
|
117
|
+
container.appendChild(document.createComment(`[${ctor.name}]`));
|
|
118
|
+
mountChildren(container, dom, scope);
|
|
119
|
+
if (!bounded) {
|
|
120
|
+
const end = document.createComment(`[/${ctor.name}]`);
|
|
121
|
+
container.appendChild(end);
|
|
122
|
+
setComponentAnchor(instance, end);
|
|
56
123
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
scheduleMount(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
124
|
+
nodes = Array.from(container.childNodes);
|
|
125
|
+
}
|
|
126
|
+
const life = new ComponentLife(instance, ref);
|
|
127
|
+
scheduleMount(life);
|
|
128
|
+
scope.add(life);
|
|
129
|
+
return nodes;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
resumeTracking(prevSub);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Mounts `hot` again with `ctor` between the comments it already has: the reactive children and
|
|
136
|
+
// lists around it keep their references to those comments.
|
|
137
|
+
function remountHot(hot, ctor) {
|
|
138
|
+
const { start, end } = hot;
|
|
139
|
+
const parent = end.parentNode;
|
|
140
|
+
// Detached (kept aside by its owner): there is no place to render into, so it is left as it is.
|
|
141
|
+
if (parent === null || start.parentNode !== parent)
|
|
142
|
+
return;
|
|
143
|
+
hot.scope.dispose();
|
|
144
|
+
for (let node = start.nextSibling; node !== null && node !== end; node = start.nextSibling)
|
|
145
|
+
parent.removeChild(node);
|
|
146
|
+
const nodes = mountComponent(ctor, hot.props, hot.parentScope, [start, end]);
|
|
147
|
+
for (const node of nodes)
|
|
148
|
+
parent.insertBefore(node, end);
|
|
76
149
|
}
|
|
77
|
-
|
|
150
|
+
setHotRemount(remountHot);
|
|
78
151
|
//# sourceMappingURL=component.js.map
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAoB,MAAM,OAAO,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAMpE,kGAAkG;AAClG,qFAAqF;AACrF,MAAM,aAAa;IAKjB,YAAY,QAAkB,EAAE,GAAoD;QAClF,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,IAAI,CA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AAK,IAAI,IAAI,IAAI,KAAK,GAAG,EAAE,IAAI,GAAG,KAAK,CAAC,WAAW;QAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACrH,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7E,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,aAAa,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { Scope } from "./scope";
|
|
2
|
+
/** Owner of a child scope that is created only once something asks for it (see swapLazyScope). */
|
|
3
|
+
export interface LazyScopeHost {
|
|
4
|
+
parentScope: Scope;
|
|
5
|
+
scope: Scope | null;
|
|
6
|
+
}
|
|
2
7
|
export declare function getCurrentScope(): Scope;
|
|
8
|
+
/**
|
|
9
|
+
* Makes `host` the scope source while no scope is current: its child scope is forked from
|
|
10
|
+
* `host.parentScope` the first time code asks for the current scope, so a run that registers
|
|
11
|
+
* nothing (a reactive text binding) creates no scope at all. Returns the previous host, which the
|
|
12
|
+
* caller must restore in a `finally`, together with the current scope (set it to `host.scope`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function swapLazyScope(host: LazyScopeHost | null): LazyScopeHost | null;
|
|
3
15
|
export declare function runInScope<T>(scope: Scope, fn: () => T): T;
|
|
16
|
+
export declare function swapScope(scope: Scope | null): Scope | null;
|
|
4
17
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIrC,wBAAgB,eAAe,IAAI,KAAK,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIrC,kGAAkG;AAClG,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAID,wBAAgB,eAAe,IAAI,KAAK,CAUvC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,GAAG,aAAa,GAAG,IAAI,CAI9E;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ1D;AAID,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAI3D"}
|
package/dist/context.js
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
let _currentScope = null;
|
|
2
|
+
let lazyHost = null;
|
|
2
3
|
export function getCurrentScope() {
|
|
3
|
-
if (
|
|
4
|
-
|
|
4
|
+
if (_currentScope === null) {
|
|
5
|
+
if (lazyHost === null) {
|
|
6
|
+
throw new Error("[PraxisJS] jsx() called outside of a render context. Make sure to call render() with a factory function.");
|
|
7
|
+
}
|
|
8
|
+
_currentScope = lazyHost.scope ??= lazyHost.parentScope.fork();
|
|
5
9
|
}
|
|
6
10
|
return _currentScope;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Makes `host` the scope source while no scope is current: its child scope is forked from
|
|
14
|
+
* `host.parentScope` the first time code asks for the current scope, so a run that registers
|
|
15
|
+
* nothing (a reactive text binding) creates no scope at all. Returns the previous host, which the
|
|
16
|
+
* caller must restore in a `finally`, together with the current scope (set it to `host.scope`).
|
|
17
|
+
*/
|
|
18
|
+
export function swapLazyScope(host) {
|
|
19
|
+
const prev = lazyHost;
|
|
20
|
+
lazyHost = host;
|
|
21
|
+
return prev;
|
|
22
|
+
}
|
|
8
23
|
export function runInScope(scope, fn) {
|
|
9
24
|
const prev = _currentScope;
|
|
10
25
|
_currentScope = scope;
|
|
@@ -15,4 +30,11 @@ export function runInScope(scope, fn) {
|
|
|
15
30
|
_currentScope = prev;
|
|
16
31
|
}
|
|
17
32
|
}
|
|
33
|
+
// Same as runInScope without a closure per call, for hot paths that create many scopes in a row.
|
|
34
|
+
// Callers must restore the returned scope in a `finally`.
|
|
35
|
+
export function swapScope(scope) {
|
|
36
|
+
const prev = _currentScope;
|
|
37
|
+
_currentScope = scope;
|
|
38
|
+
return prev;
|
|
39
|
+
}
|
|
18
40
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,IAAI,aAAa,GAAiB,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,IAAI,aAAa,GAAiB,IAAI,CAAC;AAQvC,IAAI,QAAQ,GAAyB,IAAI,CAAC;AAE1C,MAAM,UAAU,eAAe;IAC7B,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;QAC3B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,0GAA0G,CAC3G,CAAC;QACJ,CAAC;QACD,aAAa,GAAG,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAA0B;IACtD,MAAM,IAAI,GAAG,QAAQ,CAAC;IACtB,QAAQ,GAAG,IAAI,CAAC;IAChB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,KAAY,EAAE,EAAW;IACrD,MAAM,IAAI,GAAG,aAAa,CAAC;IAC3B,aAAa,GAAG,KAAK,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,KAAmB;IAC3C,MAAM,IAAI,GAAG,aAAa,CAAC;IAC3B,aAAa,GAAG,KAAK,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/dom/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
2
2
|
export declare const SVG_TAGS: Set<string>;
|
|
3
|
-
export declare const EVENT_MAP:
|
|
3
|
+
export declare const EVENT_MAP: ReadonlyMap<string, string>;
|
|
4
4
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/dom/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D,eAAO,MAAM,QAAQ,aA2BnB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/dom/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D,eAAO,MAAM,QAAQ,aA2BnB,CAAC;AAKH,eAAO,MAAM,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CA+BjD,CAAC"}
|
package/dist/dom/constants.js
CHANGED
|
@@ -27,100 +27,41 @@ export const SVG_TAGS = new Set([
|
|
|
27
27
|
"textPath",
|
|
28
28
|
"foreignObject",
|
|
29
29
|
]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
onMouseEnter: "mouseenter",
|
|
37
|
-
onMouseLeave: "mouseleave",
|
|
38
|
-
onMouseMove: "mousemove",
|
|
39
|
-
onMouseOver: "mouseover",
|
|
40
|
-
onMouseOut: "mouseout",
|
|
41
|
-
onContextMenu: "contextmenu",
|
|
30
|
+
// Event props and the DOM event each one listens to. Every prop is "on" + the event name in camel
|
|
31
|
+
// case and listens to that name in lowercase, so only the camel-case names are spelled out, which
|
|
32
|
+
// keeps the table small in bundles. A Map: looking a prop up is a single probe.
|
|
33
|
+
export const EVENT_MAP = /* @__PURE__ */ eventMap(
|
|
34
|
+
// Mouse
|
|
35
|
+
"Click DblClick MouseDown MouseUp MouseEnter MouseLeave MouseMove MouseOver MouseOut ContextMenu " +
|
|
42
36
|
// Keyboard
|
|
43
|
-
|
|
44
|
-
onKeyUp: "keyup",
|
|
45
|
-
onKeyPress: "keypress",
|
|
37
|
+
"KeyDown KeyUp KeyPress " +
|
|
46
38
|
// Focus
|
|
47
|
-
|
|
48
|
-
onBlur: "blur",
|
|
39
|
+
"Focus Blur " +
|
|
49
40
|
// Pointer
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
onPointerMove: "pointermove",
|
|
53
|
-
onPointerEnter: "pointerenter",
|
|
54
|
-
onPointerLeave: "pointerleave",
|
|
55
|
-
onPointerOver: "pointerover",
|
|
56
|
-
onPointerOut: "pointerout",
|
|
57
|
-
onPointerCancel: "pointercancel",
|
|
58
|
-
onGotPointerCapture: "gotpointercapture",
|
|
59
|
-
onLostPointerCapture: "lostpointercapture",
|
|
41
|
+
"PointerDown PointerUp PointerMove PointerEnter PointerLeave PointerOver PointerOut PointerCancel " +
|
|
42
|
+
"GotPointerCapture LostPointerCapture " +
|
|
60
43
|
// Touch
|
|
61
|
-
|
|
62
|
-
onTouchEnd: "touchend",
|
|
63
|
-
onTouchMove: "touchmove",
|
|
44
|
+
"TouchStart TouchEnd TouchMove " +
|
|
64
45
|
// Drag
|
|
65
|
-
|
|
66
|
-
onDragStart: "dragstart",
|
|
67
|
-
onDragEnd: "dragend",
|
|
68
|
-
onDragEnter: "dragenter",
|
|
69
|
-
onDragLeave: "dragleave",
|
|
70
|
-
onDragOver: "dragover",
|
|
71
|
-
onDrop: "drop",
|
|
46
|
+
"Drag DragStart DragEnd DragEnter DragLeave DragOver Drop " +
|
|
72
47
|
// Scroll / Wheel
|
|
73
|
-
|
|
74
|
-
onScrollEnd: "scrollend",
|
|
75
|
-
onWheel: "wheel",
|
|
48
|
+
"Scroll ScrollEnd Wheel " +
|
|
76
49
|
// Form
|
|
77
|
-
|
|
78
|
-
onInput: "input",
|
|
79
|
-
onBeforeInput: "beforeinput",
|
|
80
|
-
onSubmit: "submit",
|
|
81
|
-
onReset: "reset",
|
|
82
|
-
onSelect: "select",
|
|
83
|
-
onInvalid: "invalid",
|
|
50
|
+
"Change Input BeforeInput Submit Reset Select Invalid " +
|
|
84
51
|
// Clipboard
|
|
85
|
-
|
|
86
|
-
onCut: "cut",
|
|
87
|
-
onPaste: "paste",
|
|
52
|
+
"Copy Cut Paste " +
|
|
88
53
|
// Composition (IME)
|
|
89
|
-
|
|
90
|
-
onCompositionUpdate: "compositionupdate",
|
|
91
|
-
onCompositionEnd: "compositionend",
|
|
54
|
+
"CompositionStart CompositionUpdate CompositionEnd " +
|
|
92
55
|
// Resource
|
|
93
|
-
|
|
94
|
-
onError: "error",
|
|
56
|
+
"Load Error " +
|
|
95
57
|
// Animation / Transition
|
|
96
|
-
|
|
97
|
-
onTransitionEnd: "transitionend",
|
|
58
|
+
"AnimationEnd TransitionEnd " +
|
|
98
59
|
// Element-specific (details, dialog, popover)
|
|
99
|
-
|
|
100
|
-
onBeforeToggle: "beforetoggle",
|
|
101
|
-
onClose: "close",
|
|
102
|
-
onCancel: "cancel",
|
|
60
|
+
"Toggle BeforeToggle Close Cancel " +
|
|
103
61
|
// Media
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
onEnded: "ended",
|
|
110
|
-
onLoadedData: "loadeddata",
|
|
111
|
-
onLoadedMetadata: "loadedmetadata",
|
|
112
|
-
onLoadStart: "loadstart",
|
|
113
|
-
onPause: "pause",
|
|
114
|
-
onPlay: "play",
|
|
115
|
-
onPlaying: "playing",
|
|
116
|
-
onProgress: "progress",
|
|
117
|
-
onRateChange: "ratechange",
|
|
118
|
-
onSeeked: "seeked",
|
|
119
|
-
onSeeking: "seeking",
|
|
120
|
-
onStalled: "stalled",
|
|
121
|
-
onSuspend: "suspend",
|
|
122
|
-
onTimeUpdate: "timeupdate",
|
|
123
|
-
onVolumeChange: "volumechange",
|
|
124
|
-
onWaiting: "waiting",
|
|
125
|
-
};
|
|
62
|
+
"Abort CanPlay CanPlayThrough DurationChange Emptied Ended LoadedData LoadedMetadata LoadStart Pause Play " +
|
|
63
|
+
"Playing Progress RateChange Seeked Seeking Stalled Suspend TimeUpdate VolumeChange Waiting");
|
|
64
|
+
function eventMap(names) {
|
|
65
|
+
return new Map(names.split(" ").map((name) => [`on${name}`, name.toLowerCase()]));
|
|
66
|
+
}
|
|
126
67
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/dom/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IAC9B,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,MAAM;IACN,UAAU;IACV,SAAS;IACT,SAAS;IACT,MAAM;IACN,GAAG;IACH,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO;IACP,gBAAgB;IAChB,gBAAgB;IAChB,MAAM;IACN,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,UAAU;IACV,eAAe;CAChB,CAAC,CAAC;AAEH,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/dom/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IAC9B,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,MAAM;IACN,UAAU;IACV,SAAS;IACT,SAAS;IACT,MAAM;IACN,GAAG;IACH,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO;IACP,gBAAgB;IAChB,gBAAgB;IAChB,MAAM;IACN,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,UAAU;IACV,eAAe;CAChB,CAAC,CAAC;AAEH,kGAAkG;AAClG,kGAAkG;AAClG,gFAAgF;AAChF,MAAM,CAAC,MAAM,SAAS,GAAgC,eAAe,CAAC,QAAQ;AAC5E,QAAQ;AACR,kGAAkG;IAClG,WAAW;IACX,yBAAyB;IACzB,QAAQ;IACR,aAAa;IACb,UAAU;IACV,mGAAmG;IACnG,uCAAuC;IACvC,QAAQ;IACR,gCAAgC;IAChC,OAAO;IACP,2DAA2D;IAC3D,iBAAiB;IACjB,yBAAyB;IACzB,OAAO;IACP,uDAAuD;IACvD,YAAY;IACZ,iBAAiB;IACjB,oBAAoB;IACpB,oDAAoD;IACpD,WAAW;IACX,aAAa;IACb,yBAAyB;IACzB,6BAA6B;IAC7B,8CAA8C;IAC9C,mCAAmC;IACnC,QAAQ;IACR,2GAA2G;IAC3G,4FAA4F,CAC7F,CAAC;AAEF,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;AACpF,CAAC"}
|
package/dist/dom/create.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function createElement(tag: string): HTMLElement | SVGElement;
|
|
1
|
+
export declare function createElement(tag: string, doc?: Document): HTMLElement | SVGElement;
|
|
2
2
|
//# sourceMappingURL=create.d.ts.map
|
package/dist/dom/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/dom/create.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/dom/create.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,QAAmB,GAAG,WAAW,GAAG,UAAU,CAI7F"}
|
package/dist/dom/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SVG_NAMESPACE, SVG_TAGS } from "./constants";
|
|
2
|
-
export function createElement(tag) {
|
|
2
|
+
export function createElement(tag, doc = document) {
|
|
3
3
|
return SVG_TAGS.has(tag)
|
|
4
|
-
? (
|
|
5
|
-
:
|
|
4
|
+
? (doc.createElementNS(SVG_NAMESPACE, tag))
|
|
5
|
+
: doc.createElement(tag);
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=create.js.map
|
package/dist/dom/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/dom/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,UAAU,aAAa,CAAC,GAAW;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/dom/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,MAAgB,QAAQ;IACjE,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QACtB,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/dom/events.d.ts
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
import type { Scope } from "../scope";
|
|
2
2
|
export declare function addEvent(el: Element, eventName: string, handler: EventListener | EventListenerObject | null | undefined, scope: Scope): void;
|
|
3
|
+
export interface DelegatedType {
|
|
4
|
+
/** The event prop (`onClick`), under which a hydration build pass records the handler. */
|
|
5
|
+
key: string;
|
|
6
|
+
type: string;
|
|
7
|
+
/** Holds an element's handler for this type. */
|
|
8
|
+
slot: symbol;
|
|
9
|
+
/** Set once the element's own listener for this type is attached. */
|
|
10
|
+
attached: symbol;
|
|
11
|
+
/** The capture listeners for this type are registered. */
|
|
12
|
+
watched: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The delegated event type an event prop binds, or null when `key` is not an event prop. */
|
|
15
|
+
export declare function delegatedProp(key: string): DelegatedType | null;
|
|
16
|
+
/**
|
|
17
|
+
* Registers a render container (or portal target) whose subtree gets delegated handlers even while
|
|
18
|
+
* it is not in the document. Returns the function that unregisters it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function addEventRoot(root: EventTarget): () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Binds `handler` for the event of `entry` (see delegatedProp) on `el` without attaching a
|
|
23
|
+
* listener now (see above). Falls back to addEvent when no render container is registered (an
|
|
24
|
+
* element mounted outside render()), when the element already has a delegated handler for this
|
|
25
|
+
* type, or when it was bound by another scope.
|
|
26
|
+
*/
|
|
27
|
+
export declare function addDelegatedEvent(el: Element, entry: DelegatedType, handler: unknown, scope: Scope & {
|
|
28
|
+
gen: number;
|
|
29
|
+
}): void;
|
|
30
|
+
export declare function removeListener(el: Element, eventName: string, handler: unknown): void;
|
|
3
31
|
//# sourceMappingURL=events.d.ts.map
|