@praxisjs/runtime 0.7.0 → 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.
Files changed (138) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/children.d.ts.map +1 -1
  3. package/dist/children.js +2 -1
  4. package/dist/children.js.map +1 -1
  5. package/dist/component.d.ts +2 -3
  6. package/dist/component.d.ts.map +1 -1
  7. package/dist/component.js +133 -60
  8. package/dist/component.js.map +1 -1
  9. package/dist/context.d.ts +13 -0
  10. package/dist/context.d.ts.map +1 -1
  11. package/dist/context.js +24 -2
  12. package/dist/context.js.map +1 -1
  13. package/dist/dom/constants.d.ts +1 -1
  14. package/dist/dom/constants.d.ts.map +1 -1
  15. package/dist/dom/constants.js +24 -83
  16. package/dist/dom/constants.js.map +1 -1
  17. package/dist/dom/create.d.ts +1 -1
  18. package/dist/dom/create.d.ts.map +1 -1
  19. package/dist/dom/create.js +3 -3
  20. package/dist/dom/create.js.map +1 -1
  21. package/dist/dom/events.d.ts +29 -1
  22. package/dist/dom/events.d.ts.map +1 -1
  23. package/dist/dom/events.js +167 -17
  24. package/dist/dom/events.js.map +1 -1
  25. package/dist/dom/props.d.ts +4 -0
  26. package/dist/dom/props.d.ts.map +1 -1
  27. package/dist/dom/props.js +57 -8
  28. package/dist/dom/props.js.map +1 -1
  29. package/dist/dom/range.d.ts +4 -0
  30. package/dist/dom/range.d.ts.map +1 -0
  31. package/dist/dom/range.js +43 -0
  32. package/dist/dom/range.js.map +1 -0
  33. package/dist/dom/remove.d.ts.map +1 -1
  34. package/dist/dom/remove.js +2 -8
  35. package/dist/dom/remove.js.map +1 -1
  36. package/dist/element.d.ts.map +1 -1
  37. package/dist/element.js +7 -5
  38. package/dist/element.js.map +1 -1
  39. package/dist/hmr.d.ts +35 -0
  40. package/dist/hmr.d.ts.map +1 -0
  41. package/dist/hmr.js +85 -0
  42. package/dist/hmr.js.map +1 -0
  43. package/dist/hydration-context.d.ts +9 -1
  44. package/dist/hydration-context.d.ts.map +1 -1
  45. package/dist/hydration-context.js +34 -13
  46. package/dist/hydration-context.js.map +1 -1
  47. package/dist/hydration.d.ts.map +1 -1
  48. package/dist/hydration.js +4 -11
  49. package/dist/hydration.js.map +1 -1
  50. package/dist/index.d.ts +16 -5
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +31 -7
  53. package/dist/index.js.map +1 -1
  54. package/dist/list.d.ts +72 -0
  55. package/dist/list.d.ts.map +1 -0
  56. package/dist/list.js +786 -0
  57. package/dist/list.js.map +1 -0
  58. package/dist/portal.d.ts.map +1 -1
  59. package/dist/portal.js +3 -0
  60. package/dist/portal.js.map +1 -1
  61. package/dist/reactive.d.ts +2 -2
  62. package/dist/reactive.d.ts.map +1 -1
  63. package/dist/reactive.js +109 -34
  64. package/dist/reactive.js.map +1 -1
  65. package/dist/scope.d.ts +14 -4
  66. package/dist/scope.d.ts.map +1 -1
  67. package/dist/scope.js +55 -15
  68. package/dist/scope.js.map +1 -1
  69. package/dist/template.d.ts +48 -0
  70. package/dist/template.d.ts.map +1 -0
  71. package/dist/template.js +270 -0
  72. package/dist/template.js.map +1 -0
  73. package/package.json +15 -6
  74. package/src/children.ts +2 -1
  75. package/src/component.ts +135 -63
  76. package/src/context.ts +35 -4
  77. package/src/dom/constants.ts +25 -82
  78. package/src/dom/create.ts +3 -3
  79. package/src/dom/events.ts +188 -17
  80. package/src/dom/props.ts +66 -9
  81. package/src/dom/range.ts +45 -0
  82. package/src/dom/remove.ts +3 -7
  83. package/src/element.ts +8 -6
  84. package/src/hmr.ts +110 -0
  85. package/src/hydration-context.ts +34 -13
  86. package/src/hydration.ts +4 -9
  87. package/src/index.ts +54 -7
  88. package/src/list.ts +886 -0
  89. package/src/portal.ts +3 -0
  90. package/src/reactive.ts +147 -40
  91. package/src/scope.ts +63 -16
  92. package/src/template.ts +271 -0
  93. package/dist/__tests__/children.test.d.ts +0 -2
  94. package/dist/__tests__/children.test.d.ts.map +0 -1
  95. package/dist/__tests__/children.test.js +0 -241
  96. package/dist/__tests__/children.test.js.map +0 -1
  97. package/dist/__tests__/component.test.d.ts +0 -2
  98. package/dist/__tests__/component.test.d.ts.map +0 -1
  99. package/dist/__tests__/component.test.js +0 -331
  100. package/dist/__tests__/component.test.js.map +0 -1
  101. package/dist/__tests__/context.test.d.ts +0 -2
  102. package/dist/__tests__/context.test.d.ts.map +0 -1
  103. package/dist/__tests__/context.test.js +0 -111
  104. package/dist/__tests__/context.test.js.map +0 -1
  105. package/dist/__tests__/dom.test.d.ts +0 -2
  106. package/dist/__tests__/dom.test.d.ts.map +0 -1
  107. package/dist/__tests__/dom.test.js +0 -385
  108. package/dist/__tests__/dom.test.js.map +0 -1
  109. package/dist/__tests__/hydration.test.d.ts +0 -2
  110. package/dist/__tests__/hydration.test.d.ts.map +0 -1
  111. package/dist/__tests__/hydration.test.js +0 -299
  112. package/dist/__tests__/hydration.test.js.map +0 -1
  113. package/dist/__tests__/portal.test.d.ts +0 -2
  114. package/dist/__tests__/portal.test.d.ts.map +0 -1
  115. package/dist/__tests__/portal.test.js +0 -157
  116. package/dist/__tests__/portal.test.js.map +0 -1
  117. package/dist/__tests__/remove.test.d.ts +0 -2
  118. package/dist/__tests__/remove.test.d.ts.map +0 -1
  119. package/dist/__tests__/remove.test.js +0 -45
  120. package/dist/__tests__/remove.test.js.map +0 -1
  121. package/dist/__tests__/render.test.d.ts +0 -2
  122. package/dist/__tests__/render.test.d.ts.map +0 -1
  123. package/dist/__tests__/render.test.js +0 -97
  124. package/dist/__tests__/render.test.js.map +0 -1
  125. package/dist/__tests__/scope.test.d.ts +0 -2
  126. package/dist/__tests__/scope.test.d.ts.map +0 -1
  127. package/dist/__tests__/scope.test.js +0 -110
  128. package/dist/__tests__/scope.test.js.map +0 -1
  129. package/src/__tests__/children.test.ts +0 -276
  130. package/src/__tests__/component.test.ts +0 -363
  131. package/src/__tests__/context.test.ts +0 -128
  132. package/src/__tests__/dom.test.ts +0 -434
  133. package/src/__tests__/hydration.test.ts +0 -360
  134. package/src/__tests__/portal.test.ts +0 -177
  135. package/src/__tests__/remove.test.ts +0 -51
  136. package/src/__tests__/render.test.ts +0 -119
  137. package/src/__tests__/scope.test.ts +0 -120
  138. package/tsconfig.json +0 -8
@@ -1,4 +1,9 @@
1
1
  import type { Scope } from "./scope";
2
+ /**
3
+ * True during a hydration build pass (see runInRecording). Exported as a live binding so the hot
4
+ * render paths read a variable instead of calling isRecording() for every binding.
5
+ */
6
+ export declare let recording: boolean;
2
7
  /**
3
8
  * Marks the synchronous "build" pass of a hydration attempt: `factory()` runs
4
9
  * completely normally (same create-mode code as a plain client render), but
@@ -14,8 +19,11 @@ interface PropRecord {
14
19
  scope: Scope;
15
20
  }
16
21
  export declare function recordProps(el: Element, props: Record<string, unknown>, scope: Scope): void;
22
+ /** Adds one prop to an element's record, for elements whose props are applied one at a time. */
23
+ export declare function recordProp(el: Element, key: string, value: unknown, scope: Scope): void;
17
24
  export declare function getRecordedProps(el: Element): PropRecord | undefined;
25
+ export declare function onHydrationReplace(node: Node, replace: (real: Node) => void): void;
26
+ export declare function getHydrationReplacer(node: Node): ((real: Node) => void) | undefined;
18
27
  export declare function registerReactiveNode(node: Node, owner: Node[]): void;
19
- export declare function getReactiveOwner(node: Node): Node[] | undefined;
20
28
  export {};
21
29
  //# sourceMappingURL=hydration-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydration-context.d.ts","sourceRoot":"","sources":["../src/hydration-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIrC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQhD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,EAAE,K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AkB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI,CAGlF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,GAAG,SAAS,CAEnF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAKpE"}
@@ -1,4 +1,8 @@
1
- let _recording = false;
1
+ /**
2
+ * True during a hydration build pass (see runInRecording). Exported as a live binding so the hot
3
+ * render paths read a variable instead of calling isRecording() for every binding.
4
+ */
5
+ export let recording = false;
2
6
  /**
3
7
  * Marks the synchronous "build" pass of a hydration attempt: `factory()` runs
4
8
  * completely normally (same create-mode code as a plain client render), but
@@ -8,33 +12,50 @@ let _recording = false;
8
12
  * element instead of the fresh one. No-op / zero cost outside a build pass.
9
13
  */
10
14
  export function runInRecording(fn) {
11
- const prev = _recording;
12
- _recording = true;
15
+ const prev = recording;
16
+ recording = true;
13
17
  try {
14
18
  return fn();
15
19
  }
16
20
  finally {
17
- _recording = prev;
21
+ recording = prev;
18
22
  }
19
23
  }
20
24
  export function isRecording() {
21
- return _recording;
25
+ return recording;
22
26
  }
23
27
  const _propRecords = new WeakMap();
24
28
  export function recordProps(el, props, scope) {
25
29
  _propRecords.set(el, { props, scope });
26
30
  }
31
+ /** Adds one prop to an element's record, for elements whose props are applied one at a time. */
32
+ export function recordProp(el, key, value, scope) {
33
+ const record = _propRecords.get(el);
34
+ if (record === undefined)
35
+ _propRecords.set(el, { props: { [key]: value }, scope });
36
+ else
37
+ record.props[key] = value;
38
+ }
27
39
  export function getRecordedProps(el) {
28
40
  return _propRecords.get(el);
29
41
  }
30
- // mountReactive() keeps a `currentNodes` array (by reference) for diffing its
31
- // *next* update. If reconcile() replaces one of those fresh nodes with a real
32
- // one, it needs to overwrite that array in place so the closure sees the swap.
33
- const _reactiveOwners = new WeakMap();
34
- export function registerReactiveNode(node, owner) {
35
- _reactiveOwners.set(node, owner);
42
+ // Code that keeps references to fresh nodes for its *next* update (mountReactive's
43
+ // `currentNodes`, a list row's boundaries) registers how to repoint them, so reconcile()
44
+ // can tell it when it keeps a real element in place of a fresh one. One node can have several
45
+ // owners (a list row's element is also part of the nodes an enclosing reactive child returned).
46
+ const _replacers = new WeakMap();
47
+ export function onHydrationReplace(node, replace) {
48
+ const prev = _replacers.get(node);
49
+ _replacers.set(node, prev === undefined ? replace : (real) => { prev(real); replace(real); });
50
+ }
51
+ export function getHydrationReplacer(node) {
52
+ return _replacers.get(node);
36
53
  }
37
- export function getReactiveOwner(node) {
38
- return _reactiveOwners.get(node);
54
+ export function registerReactiveNode(node, owner) {
55
+ onHydrationReplace(node, (real) => {
56
+ const idx = owner.indexOf(node);
57
+ if (idx !== -1)
58
+ owner[idx] = real;
59
+ });
39
60
  }
40
61
  //# sourceMappingURL=hydration-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydration-context.js","sourceRoot":"","sources":["../src/hydration-context.ts"],"names":[],"mappings":"AAEA,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAI,EAAW;IAC3C,MAAM,IAAI,GAAG,UAAU,CAAC;IACxB,UAAU,GAAG,IAAI,CAAC;IAClB,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,CAAC;AACpB,CAAC;AAOD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAuB,CAAC;AAExD,MAAM,UAAU,WAAW,CAAC,EAAW,EAAE,KAA8B,EAAE,KAAY;IACnF,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,C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+1 @@
1
- {"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../src/hydration.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,CA8BvE"}
1
+ {"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../src/hydration.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,CA8BvE"}
package/dist/hydration.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { applyProp } from "./dom/props";
2
- import { getReactiveOwner, getRecordedProps } from "./hydration-context";
2
+ import { getHydrationReplacer, getRecordedProps } from "./hydration-context";
3
3
  function replayProps(real, fresh) {
4
4
  const record = getRecordedProps(fresh);
5
5
  if (!record)
@@ -10,17 +10,10 @@ function replayProps(real, fresh) {
10
10
  applyProp(real, key, record.props[key], record.scope);
11
11
  }
12
12
  }
13
- // mountReactive()'s `currentNodes` array holds fresh node references for its
14
- // *next* diff. If we're keeping `real` instead of `fresh` here, that array
15
- // needs to see the swap too — it's registered by reference, so this mutation
16
- // is visible to whichever effect closure owns it.
13
+ // mountReactive()'s `currentNodes` and list rows keep fresh node references for their
14
+ // *next* update. If we're keeping `real` instead of `fresh` here, they need to see the swap.
17
15
  function notifyReplacement(fresh, real) {
18
- const owner = getReactiveOwner(fresh);
19
- if (!owner)
20
- return;
21
- const idx = owner.indexOf(fresh);
22
- if (idx !== -1)
23
- owner[idx] = real;
16
+ getHydrationReplacer(fresh)?.(real);
24
17
  }
25
18
  /**
26
19
  * Walks `freshChildren` (the complete, correctly-nested output of a normal
@@ -1 +1 @@
1
- {"version":3,"file":"hydration.js","sourceRoot":"","sources":["../src/hydration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM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at the start of
3
+ * the client bundle, so apps it builds need nothing more; a page prerendered another way calls it
4
+ * once before render(). Without it, a container carrying the hydration marker is cleared and
5
+ * mounted fresh.
6
+ */
7
+ export declare function enableHydration(): void;
1
8
  /**
2
9
  * Renders a component tree into a container element.
3
10
  *
4
11
  * The factory function is called once inside the root scope,
5
12
  * so `jsx()` can access the current scope via `getCurrentScope()`.
6
13
  *
7
- * If `container` carries the marker `@praxisjs/ssg` stamps onto prerendered
8
- * HTML, the tree is built normally into a detached scratch node and then
9
- * reconciled against the existing DOM (real elements are kept and have their
10
- * props/listeners replayed onto them; text/comments and any mismatched nodes
11
- * are recreated) instead of clearing the container and mounting fresh.
14
+ * Once hydration is enabled (see `enableHydration()`), a `container` carrying the marker
15
+ * `@praxisjs/ssg` stamps onto prerendered HTML has its tree built normally into a detached
16
+ * scratch node and then reconciled against the existing DOM (real elements are kept and have their
17
+ * props/listeners replayed onto them; text/comments and any mismatched nodes are recreated)
18
+ * instead of being cleared and mounted fresh.
12
19
  *
13
20
  * @example
14
21
  * render(() => <App />, document.getElementById('app'));
@@ -17,6 +24,10 @@ export declare function render(factory: () => Node | Node[] | null, container: H
17
24
  export { Scope } from "./scope";
18
25
  export { runInScope, getCurrentScope } from "./context";
19
26
  export { mountElement } from "./element";
27
+ export { mountChildren } from "./children";
28
+ export { template as _$template, html as _$html, element as _$element, prop as _$prop, reactive as _$reactive, insert as _$insert, reactiveOnly as _$reactiveOnly, insertOnly as _$insertOnly, on as _$on, event as _$event, onEvent as _$onEvent, className as _$className, scope as _$scope, } from "./template";
20
29
  export { mountComponent } from "./component";
30
+ export { registerHot as _$hmrRegister, acceptsHotUpdate as _$hmrAccepts } from "./hmr";
21
31
  export { Portal, type PortalProps } from "./portal";
32
+ export { For, Index, type ForProps, type IndexProps, type ListSource, type ListTransition, } from "./list";
22
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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AAI,OAAO,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,IAAI,aAAa,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EACL,GAAG,EACH,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -1,23 +1,29 @@
1
1
  import { mountChildren } from "./children";
2
2
  import { runInScope } from "./context";
3
+ import { addEventRoot } from "./dom/events";
3
4
  import { reconcile } from "./hydration";
4
5
  import { runInRecording } from "./hydration-context";
5
6
  import { Scope } from "./scope";
7
+ import { syncTemplateDocument } from "./template";
6
8
  /** Written by `@praxisjs/ssg` onto the mount container in its prerendered HTML. */
7
9
  const SSG_MARKER = "data-praxis-ssg";
8
10
  function mountCreate(factory, container) {
11
+ syncTemplateDocument();
9
12
  const rootScope = new Scope();
10
13
  container.innerHTML = "";
14
+ const removeEventRoot = addEventRoot(container);
11
15
  runInScope(rootScope, () => {
12
16
  const result = factory();
13
17
  mountChildren(container, result, rootScope);
14
18
  });
15
19
  return () => {
16
20
  rootScope.dispose();
21
+ removeEventRoot();
17
22
  container.innerHTML = "";
18
23
  };
19
24
  }
20
25
  function hydrate(factory, container) {
26
+ syncTemplateDocument();
21
27
  const rootScope = new Scope();
22
28
  const scratch = document.createDocumentFragment();
23
29
  // Build normally — same code as mountCreate, just into a detached scratch
@@ -31,35 +37,53 @@ function hydrate(factory, container) {
31
37
  });
32
38
  });
33
39
  reconcile(container, Array.from(scratch.childNodes));
40
+ const removeEventRoot = addEventRoot(container);
34
41
  return () => {
35
42
  rootScope.dispose();
43
+ removeEventRoot();
36
44
  container.innerHTML = "";
37
45
  };
38
46
  }
47
+ // Reached only through enableHydration(), so an app that never calls it leaves the reconciliation
48
+ // and every recording branch of the render paths out of its bundle.
49
+ let hydrateRoot = null;
50
+ /**
51
+ * Lets render() hydrate the HTML `@praxisjs/ssg` prerendered. `ssgPlugin()` calls it at the start of
52
+ * the client bundle, so apps it builds need nothing more; a page prerendered another way calls it
53
+ * once before render(). Without it, a container carrying the hydration marker is cleared and
54
+ * mounted fresh.
55
+ */
56
+ export function enableHydration() {
57
+ hydrateRoot = hydrate;
58
+ }
39
59
  /**
40
60
  * Renders a component tree into a container element.
41
61
  *
42
62
  * The factory function is called once inside the root scope,
43
63
  * so `jsx()` can access the current scope via `getCurrentScope()`.
44
64
  *
45
- * If `container` carries the marker `@praxisjs/ssg` stamps onto prerendered
46
- * HTML, the tree is built normally into a detached scratch node and then
47
- * reconciled against the existing DOM (real elements are kept and have their
48
- * props/listeners replayed onto them; text/comments and any mismatched nodes
49
- * are recreated) instead of clearing the container and mounting fresh.
65
+ * Once hydration is enabled (see `enableHydration()`), a `container` carrying the marker
66
+ * `@praxisjs/ssg` stamps onto prerendered HTML has its tree built normally into a detached
67
+ * scratch node and then reconciled against the existing DOM (real elements are kept and have their
68
+ * props/listeners replayed onto them; text/comments and any mismatched nodes are recreated)
69
+ * instead of being cleared and mounted fresh.
50
70
  *
51
71
  * @example
52
72
  * render(() => <App />, document.getElementById('app'));
53
73
  */
54
74
  export function render(factory, container) {
55
- if (container.hasAttribute(SSG_MARKER)) {
56
- return hydrate(factory, container);
75
+ if (hydrateRoot !== null && container.hasAttribute(SSG_MARKER)) {
76
+ return hydrateRoot(factory, container);
57
77
  }
58
78
  return mountCreate(factory, container);
59
79
  }
60
80
  export { Scope } from "./scope";
61
81
  export { runInScope, getCurrentScope } from "./context";
62
82
  export { mountElement } from "./element";
83
+ export { mountChildren } from "./children";
84
+ export { template as _$template, html as _$html, element as _$element, prop as _$prop, reactive as _$reactive, insert as _$insert, reactiveOnly as _$reactiveOnly, insertOnly as _$insertOnly, on as _$on, event as _$event, onEvent as _$onEvent, className as _$className, scope as _$scope, } from "./template";
63
85
  export { mountComponent } from "./component";
86
+ export { registerHot as _$hmrRegister, acceptsHotUpdate as _$hmrAccepts } from "./hmr";
64
87
  export { Portal } from "./portal";
88
+ export { For, Index, } from "./list";
65
89
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,mFAAmF;AACnF,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,SAAS,WAAW,CAClB,OAAmC,EACnC,SAAsB;IAEtB,MAAM,SAAS,GAAG,IAAI,KAAK,EAAE,CAAC;IAC9B,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;IAEzB,UAAU,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,OAAO,EAAE,CAAC;QACzB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE;QACV,SAAS,CAAC,OAAO,EAAE,CAAC;QACpB,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CACd,OAAmC,EACnC,SAAsB;IAEtB,MAAM,SAAS,GAAG,IAAI,KAAK,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;IAElD,0EAA0E;IAC1E,sEAAsE;IACtE,wEAAwE;IACxE,0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B,KAAK,IAAI,OAAO,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,IAAI,aAAa,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,MAAM,EAAoB,MAAM,UAAU,CAAC;AACpD,OAAO,EACL,GAAG,EACH,KAAK,GAKN,MAAM,QAAQ,CAAC"}
package/dist/list.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { RootComponent } from "@praxisjs/core/internal";
2
+ import type { Children } from "@praxisjs/shared";
3
+ /** Anything with Promise-based `enter`/`leave` hooks, such as `createTransition()` from `@praxisjs/motion`. */
4
+ export interface ListTransition {
5
+ enter?(el: HTMLElement): Promise<void>;
6
+ leave?(el: HTMLElement): Promise<void>;
7
+ }
8
+ export type ListSource<T> = readonly T[] | Iterable<T> | null | undefined | (() => readonly T[] | Iterable<T> | null | undefined);
9
+ export interface ForProps<T> {
10
+ /** The items, or a function returning them. Only this function is tracked by the list. */
11
+ each: ListSource<T>;
12
+ /**
13
+ * Identifies an item across updates: a function of the item (and its index), or the name of a
14
+ * property holding the key. Defaults to the item itself.
15
+ */
16
+ by?: ((item: T, index: number) => unknown) | keyof T;
17
+ /** Rendered while the list is empty. A function is mounted (and disposed) each time it shows. */
18
+ fallback?: Children;
19
+ /** Runs `enter` on the elements of added rows and keeps removed rows until `leave` resolves. */
20
+ transition?: ListTransition;
21
+ /** Also run `transition.enter` for the rows of the first render. */
22
+ appear?: boolean;
23
+ /**
24
+ * Renders one row, once per key. `item()` returns the current item for that key and is reactive
25
+ * when read inside a binding; `index()` returns the row's current position.
26
+ */
27
+ children: (item: () => T, index: () => number) => Children;
28
+ }
29
+ export interface IndexProps<T> {
30
+ each: ListSource<T>;
31
+ fallback?: Children;
32
+ transition?: ListTransition;
33
+ appear?: boolean;
34
+ /** Renders the row at one position. `item()` is reactive and follows whatever sits at `index`. */
35
+ children: (item: () => T, index: number) => Children;
36
+ }
37
+ /**
38
+ * Longest increasing subsequence of `sources`, ignoring zeros (rows without a previous position).
39
+ * Returns the positions in `sources` that belong to it, in increasing order. O(n log n).
40
+ */
41
+ export declare function longestIncreasingSubsequence(sources: Int32Array): Int32Array;
42
+ /**
43
+ * Keyed list. Rows are created once per key and kept (with their DOM, state and effects) while the
44
+ * key stays in the list; reorders move the existing nodes with the minimum number of moves.
45
+ *
46
+ * @example
47
+ * <For each={() => this.todos} by={(todo) => todo.id} fallback={<p>Nothing to do</p>}>
48
+ * {(todo, index) => <li>{() => `${index() + 1}. ${todo().title}`}</li>}
49
+ * </For>
50
+ */
51
+ export declare class For<T> extends RootComponent<ForProps<T>> {
52
+ static readonly __isComponent: true;
53
+ static readonly __isStateless = true;
54
+ static readonly __jsxRawProps: true;
55
+ render(): Node | null;
56
+ }
57
+ /**
58
+ * Positional list, for primitives and lists without stable identity. Row `i` is created once and
59
+ * kept; when the value at `i` changes only the bindings reading `item()` update.
60
+ *
61
+ * @example
62
+ * <Index each={() => this.tags}>
63
+ * {(tag, i) => <input value={() => tag()} onInput={(e) => { this.rename(i, e) }} />}
64
+ * </Index>
65
+ */
66
+ export declare class Index<T> extends RootComponent<IndexProps<T>> {
67
+ static readonly __isComponent: true;
68
+ static readonly __isStateless = true;
69
+ static readonly __jsxRawProps: true;
70
+ render(): Node | null;
71
+ }
72
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAOd,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAU,MAAM,kBAAkB,CAAC;AAUzD,+GAA+G;AAC/G,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,CAAC,CAAC,EAAE,EA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