@esportsplus/template 0.17.0 → 0.19.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 (53) hide show
  1. package/build/attributes.js +4 -4
  2. package/build/constants.d.ts +2 -9
  3. package/build/constants.js +3 -10
  4. package/build/event.js +47 -45
  5. package/build/html/index.d.ts +3 -2106
  6. package/build/html/index.js +34 -8
  7. package/build/html/{cache.d.ts → parser.d.ts} +1 -1
  8. package/build/html/{cache.js → parser.js} +13 -7
  9. package/build/index.d.ts +1 -1
  10. package/build/render.js +3 -2
  11. package/build/slot/cleanup.js +2 -1
  12. package/build/slot/effect.js +22 -17
  13. package/build/slot/index.js +4 -9
  14. package/build/slot/reactive.d.ts +1 -1
  15. package/build/slot/reactive.js +26 -16
  16. package/build/slot/render.d.ts +2 -2
  17. package/build/slot/render.js +24 -45
  18. package/build/types.d.ts +5 -13
  19. package/build/utilities/element.d.ts +11 -0
  20. package/build/utilities/element.js +9 -0
  21. package/build/utilities/fragment.d.ts +3 -0
  22. package/build/utilities/fragment.js +11 -0
  23. package/build/utilities/node.d.ts +9 -0
  24. package/build/utilities/node.js +10 -0
  25. package/build/utilities/queue.d.ts +3 -0
  26. package/build/utilities/queue.js +4 -0
  27. package/build/utilities/text.d.ts +2 -0
  28. package/build/utilities/text.js +9 -0
  29. package/package.json +2 -2
  30. package/src/attributes.ts +23 -26
  31. package/src/constants.ts +3 -20
  32. package/src/event.ts +55 -52
  33. package/src/html/index.ts +50 -11
  34. package/src/html/{cache.ts → parser.ts} +15 -7
  35. package/src/index.ts +1 -1
  36. package/src/render.ts +3 -3
  37. package/src/slot/cleanup.ts +3 -4
  38. package/src/slot/effect.ts +33 -35
  39. package/src/slot/index.ts +6 -16
  40. package/src/slot/reactive.ts +33 -23
  41. package/src/slot/render.ts +28 -59
  42. package/src/types.ts +6 -19
  43. package/src/utilities/element.ts +28 -0
  44. package/src/utilities/fragment.ts +21 -0
  45. package/src/utilities/node.ts +29 -0
  46. package/src/utilities/queue.ts +9 -0
  47. package/src/utilities/text.ts +15 -0
  48. package/build/html/hydrate.d.ts +0 -3
  49. package/build/html/hydrate.js +0 -34
  50. package/build/utilities.d.ts +0 -28
  51. package/build/utilities.js +0 -37
  52. package/src/html/hydrate.ts +0 -53
  53. package/src/utilities.ts +0 -89
@@ -1,12 +1,38 @@
1
- import { RENDERABLE, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY } from '../constants.js';
2
- import hydrate from './hydrate.js';
3
- import cache from './cache.js';
1
+ import { RENDERABLE, RENDERABLE_HTML_REACTIVE_ARRAY } from '../constants.js';
2
+ import { cloneNode } from '../utilities/node.js';
3
+ import parser from './parser.js';
4
4
  const html = (literals, ...values) => {
5
- return {
6
- [RENDERABLE]: RENDERABLE_HTML_FRAGMENT,
7
- fragment: hydrate(cache.get(literals), values),
8
- literals
9
- };
5
+ let { fragment, slots } = parser.parse(literals);
6
+ fragment = cloneNode.call(fragment, true);
7
+ if (slots !== null) {
8
+ let node, nodePath, parent, parentPath;
9
+ for (let i = 0, n = slots.length; i < n; i++) {
10
+ let { fn, path, slot } = slots[i], pp = path.parent, pr = path.relative;
11
+ if (pp !== parentPath) {
12
+ if (pp === nodePath) {
13
+ parent = node;
14
+ parentPath = nodePath;
15
+ nodePath = undefined;
16
+ }
17
+ else {
18
+ parent = fragment;
19
+ parentPath = pp;
20
+ for (let i = 0, n = pp.length; i < n; i++) {
21
+ parent = pp[i].call(parent);
22
+ }
23
+ }
24
+ }
25
+ if (pr !== nodePath) {
26
+ node = parent;
27
+ nodePath = path.absolute;
28
+ for (let i = 0, n = pr.length; i < n; i++) {
29
+ node = pr[i].call(node);
30
+ }
31
+ }
32
+ fn(node, values[slot]);
33
+ }
34
+ }
35
+ return fragment;
10
36
  };
11
37
  html.reactive = (array, template) => {
12
38
  return {
@@ -1,5 +1,5 @@
1
1
  import { Template } from '../types.js';
2
2
  declare const _default: {
3
- get: (literals: TemplateStringsArray) => Template;
3
+ parse: (literals: TemplateStringsArray) => Template;
4
4
  };
5
5
  export default _default;
@@ -1,6 +1,8 @@
1
1
  import { NODE_CLOSING, NODE_ELEMENT, NODE_SLOT, NODE_VOID, NODE_WHITELIST, REGEX_EMPTY_TEXT_NODES, REGEX_SLOT_NODES, SLOT_HTML, SLOT_MARKER, SLOT_MARKER_LENGTH } from '../constants.js';
2
- import { firstChild, firstElementChild, fragment, nextElementSibling, nextSibling } from '../utilities.js';
2
+ import { firstElementChild, nextElementSibling } from '../utilities/element.js';
3
+ import { firstChild, nextSibling } from '../utilities/node.js';
3
4
  import { spread } from '../attributes.js';
5
+ import { fragment } from '../utilities/fragment.js';
4
6
  import s from '../slot/index.js';
5
7
  let cache = new WeakMap();
6
8
  function build(literals) {
@@ -85,16 +87,20 @@ function methods(children, copy, first, next) {
85
87
  return methods;
86
88
  }
87
89
  function set(literals, html, slots = null) {
88
- let template = {
90
+ let value = {
89
91
  fragment: fragment(html),
90
92
  html,
91
93
  literals,
92
94
  slots
93
95
  };
94
- cache.set(literals, template);
95
- return template;
96
+ cache.set(literals, value);
97
+ return value;
96
98
  }
97
- const get = (literals) => {
98
- return cache.get(literals) || build(literals);
99
+ const parse = (literals) => {
100
+ let result = cache.get(literals);
101
+ if (result === undefined) {
102
+ result = build(literals);
103
+ }
104
+ return result;
99
105
  };
100
- export default { get };
106
+ export default { parse };
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { default as html } from './html/index.js';
2
2
  export { default as render } from './render.js';
3
3
  export { default as svg } from './svg.js';
4
- export type { Attributes, Element, Elements, Renderable, RenderableValue } from './types.js';
4
+ export type { Attributes, Element, Renderable, RenderableValue } from './types.js';
package/build/render.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { SLOT_HTML } from './constants.js';
2
- import { firstChild, fragment, nodeValue } from './utilities.js';
2
+ import { fragment } from './utilities/fragment.js';
3
+ import { firstChild, nodeValue } from './utilities/node.js';
3
4
  import slot from './slot/index.js';
4
5
  let anchor, marker = firstChild.call(fragment(SLOT_HTML));
5
6
  export default (parent, renderable) => {
6
7
  nodeValue.call(parent, '');
7
8
  parent.append(anchor = marker.cloneNode());
8
- return slot(anchor, renderable);
9
+ slot(anchor, renderable);
9
10
  };
@@ -1,6 +1,7 @@
1
1
  import queue from '@esportsplus/queue';
2
2
  import { CLEANUP } from '../constants.js';
3
- import { microtask, previousSibling } from '../utilities.js';
3
+ import { microtask } from '../utilities/queue.js';
4
+ import { previousSibling } from '../utilities/node.js';
4
5
  let cleanup = queue(64), scheduled = false;
5
6
  function schedule() {
6
7
  if (!cleanup.length || scheduled) {
@@ -1,16 +1,19 @@
1
1
  import { effect } from '@esportsplus/reactivity';
2
- import { EMPTY_FRAGMENT, STATE_HYDRATING, STATE_NONE } from '../constants.js';
3
- import { cloneNode, firstChild, lastChild, nodeValue, raf, text } from '../utilities.js';
4
- import { ondisconnect } from '../slot/cleanup.js';
2
+ import { STATE_HYDRATING, STATE_NONE } from '../constants.js';
3
+ import { firstChild, lastChild, nodeValue } from '../utilities/node.js';
4
+ import { raf } from '../utilities/queue.js';
5
5
  import { remove } from './cleanup.js';
6
+ import text from '../utilities/text.js';
6
7
  import render from './render.js';
7
- function update(anchor, fragment, value) {
8
- let type = typeof value;
8
+ function update(anchor, value) {
9
9
  if (this.group) {
10
10
  remove([this.group]);
11
11
  this.group = undefined;
12
12
  }
13
- if (value == null || type !== 'object') {
13
+ if (value == null || value === false) {
14
+ value = '';
15
+ }
16
+ if (typeof value !== 'object') {
14
17
  let textnode = this.textnode;
15
18
  if (textnode) {
16
19
  nodeValue.call(textnode, String(value));
@@ -23,29 +26,31 @@ function update(anchor, fragment, value) {
23
26
  }
24
27
  }
25
28
  else {
26
- render(anchor, fragment, value);
27
- this.group = {
28
- head: firstChild.call(fragment),
29
- tail: lastChild.call(fragment)
30
- };
31
- anchor.after(fragment);
29
+ let fragment = render(anchor, value), head = firstChild.call(fragment);
30
+ if (head) {
31
+ this.group = {
32
+ head,
33
+ tail: lastChild.call(fragment)
34
+ };
35
+ anchor.after(fragment);
36
+ }
32
37
  }
33
38
  }
34
39
  export default (anchor, fn) => {
35
40
  let context = {
36
41
  group: undefined,
37
42
  textnode: undefined
38
- }, fragment = cloneNode.call(EMPTY_FRAGMENT), state = STATE_HYDRATING;
39
- ondisconnect(anchor, effect(() => {
43
+ }, state = STATE_HYDRATING;
44
+ effect(() => {
40
45
  let value = fn();
41
46
  if (state === STATE_HYDRATING) {
42
- update.call(context, anchor, fragment, value);
47
+ update.call(context, anchor, value);
43
48
  state = STATE_NONE;
44
49
  }
45
50
  else if (state === STATE_NONE) {
46
51
  raf.add(() => {
47
- update.call(context, anchor, fragment, value);
52
+ update.call(context, anchor, value);
48
53
  });
49
54
  }
50
- }));
55
+ });
51
56
  };
@@ -1,15 +1,10 @@
1
- import { EMPTY_FRAGMENT } from '../constants.js';
2
- import { cloneNode } from '../utilities.js';
3
1
  import effect from './effect.js';
4
2
  import render from './render.js';
5
- function slot(anchor, input) {
6
- let fragment = cloneNode.call(EMPTY_FRAGMENT);
7
- render(anchor, fragment, input);
8
- anchor.after(fragment);
9
- }
10
3
  export default (anchor, value) => {
11
4
  if (typeof value === 'function') {
12
- return effect(anchor, value);
5
+ effect(anchor, value);
6
+ }
7
+ else {
8
+ anchor.after(render(anchor, value));
13
9
  }
14
- return slot(anchor, value);
15
10
  };
@@ -1,3 +1,3 @@
1
1
  import { RenderableReactive } from '../types.js';
2
- declare const _default: (anchor: Element, renderable: RenderableReactive) => void;
2
+ declare const _default: (anchor: Element, renderable: RenderableReactive) => Node;
3
3
  export default _default;
@@ -1,45 +1,48 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { EMPTY_FRAGMENT } from '../constants.js';
3
- import { append, cloneNode, firstChild, lastChild } from '../utilities.js';
4
- import { remove } from './cleanup.js';
3
+ import { append } from '../utilities/fragment.js';
4
+ import { cloneNode, firstChild, lastChild } from '../utilities/node.js';
5
+ import { ondisconnect, remove } from './cleanup.js';
5
6
  class ReactiveArraySlot {
6
7
  array;
7
- fragment = cloneNode.call(EMPTY_FRAGMENT);
8
+ fragment;
8
9
  marker;
9
10
  nodes = [];
10
11
  template;
11
12
  constructor(anchor, array, template) {
12
- let fragment = this.fragment;
13
+ let fragment = this.fragment = cloneNode.call(EMPTY_FRAGMENT);
13
14
  this.array = array;
14
15
  this.marker = anchor;
15
16
  this.template = function (data, i) {
16
- let frag = template.call(this, data, i).fragment, group = {
17
+ let dispose, frag = root((d) => {
18
+ dispose = d;
19
+ return template.call(this, data, i);
20
+ }), group = {
17
21
  head: firstChild.call(frag),
18
22
  tail: lastChild.call(frag)
19
23
  };
20
24
  append.call(fragment, frag);
25
+ ondisconnect(group.head, dispose);
21
26
  return group;
22
27
  };
23
- let render = () => {
24
- root(() => this.render());
25
- };
26
28
  array.on('clear', () => this.clear());
27
- array.on('reverse', render);
29
+ array.on('reverse', () => {
30
+ root(() => this.render());
31
+ });
28
32
  array.on('pop', () => this.pop());
29
33
  array.on('push', ({ items }) => {
30
34
  root(() => this.push(items));
31
35
  });
32
36
  array.on('shift', () => this.shift());
33
- array.on('sort', render);
37
+ array.on('sort', () => {
38
+ root(() => this.render());
39
+ });
34
40
  array.on('splice', ({ deleteCount, items, start }) => {
35
41
  root(() => this.splice(start, deleteCount, ...items));
36
42
  });
37
43
  array.on('unshift', ({ items }) => {
38
44
  root(() => this.unshift(items));
39
45
  });
40
- if (array.length) {
41
- render();
42
- }
43
46
  }
44
47
  get length() {
45
48
  return this.nodes.length;
@@ -72,9 +75,10 @@ class ReactiveArraySlot {
72
75
  }
73
76
  }
74
77
  push(items) {
75
- let anchor = this.anchor(), array = this.array;
78
+ let anchor = this.anchor(), array = this.array, length = this.nodes.length;
79
+ this.nodes.length = length + items.length;
76
80
  for (let i = 0, n = items.length; i < n; i++) {
77
- this.nodes.push(this.template.call(array, items[i], i));
81
+ this.nodes[i + length] = this.template.call(array, items[i], i);
78
82
  }
79
83
  anchor.after(this.fragment);
80
84
  }
@@ -113,5 +117,11 @@ class ReactiveArraySlot {
113
117
  }
114
118
  }
115
119
  export default (anchor, renderable) => {
116
- new ReactiveArraySlot(anchor, renderable.array, renderable.template);
120
+ let { array, template } = renderable, slot = new ReactiveArraySlot(anchor, array, template);
121
+ if (array.length) {
122
+ root(() => {
123
+ slot.nodes = array.map(slot.template);
124
+ });
125
+ }
126
+ return slot.fragment;
117
127
  };
@@ -1,2 +1,2 @@
1
- import { Element, Fragment } from '../types.js';
2
- export default function render(anchor: Element, fragment: Fragment, input: unknown): void;
1
+ import { Element } from '../types.js';
2
+ export default function render(anchor: Element, input: unknown): Node;
@@ -1,58 +1,37 @@
1
1
  import { isArray } from '@esportsplus/utilities';
2
- import { RENDERABLE, RENDERABLE_ARRAY, RENDERABLE_FRAGMENT, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY, RENDERABLE_NODE, RENDERABLE_NODE_LIST, RENDERABLE_TEXT, RENDERABLE_VOID } from '../constants.js';
3
- import { append, text } from '../utilities.js';
2
+ import { EMPTY_FRAGMENT, RENDERABLE } from '../constants.js';
3
+ import { cloneNode, lastChild } from '../utilities/node.js';
4
+ import { append } from '../utilities/fragment.js';
5
+ import text from '../utilities/text.js';
4
6
  import reactive from './reactive.js';
5
- function type(input) {
6
- if (input === false || input == null || input === '') {
7
- return RENDERABLE_VOID;
7
+ export default function render(anchor, input) {
8
+ if (input == null || input === false || input === '') {
9
+ return EMPTY_FRAGMENT;
8
10
  }
9
11
  if (typeof input !== 'object') {
10
- return RENDERABLE_TEXT;
12
+ return text(input);
13
+ }
14
+ if ('nodeType' in input) {
15
+ return input;
11
16
  }
12
17
  if (RENDERABLE in input) {
13
- return input[RENDERABLE];
18
+ return reactive(anchor, input);
14
19
  }
15
20
  if (isArray(input)) {
16
- return RENDERABLE_ARRAY;
17
- }
18
- let nodeType = input.nodeType;
19
- if (nodeType === 11) {
20
- return RENDERABLE_FRAGMENT;
21
- }
22
- if (nodeType !== undefined) {
23
- return RENDERABLE_NODE;
21
+ let fragment = cloneNode.call(EMPTY_FRAGMENT);
22
+ for (let i = 0, n = input.length; i < n; i++) {
23
+ append.call(fragment, render(anchor, input[i]));
24
+ anchor = lastChild.call(fragment);
25
+ }
26
+ return fragment;
24
27
  }
25
28
  if (input instanceof NodeList) {
26
- return RENDERABLE_NODE_LIST;
27
- }
28
- }
29
- export default function render(anchor, fragment, input) {
30
- let t = type(input);
31
- switch (t) {
32
- case RENDERABLE_VOID:
33
- return;
34
- case RENDERABLE_TEXT:
35
- append.call(fragment, text(String(input)));
36
- return;
37
- case RENDERABLE_HTML_FRAGMENT:
38
- append.call(fragment, input.fragment);
39
- return;
40
- case RENDERABLE_HTML_REACTIVE_ARRAY:
41
- return reactive(anchor, input);
42
- case RENDERABLE_ARRAY:
43
- for (let i = 0, n = input.length; i < n; i++) {
44
- render(anchor, fragment, input[i]);
45
- }
46
- return;
47
- case RENDERABLE_FRAGMENT:
48
- append.call(fragment, input);
49
- return;
50
- case RENDERABLE_NODE:
51
- append.call(fragment, input);
52
- return;
53
- case RENDERABLE_NODE_LIST:
54
- append.call(fragment, ...input);
55
- return;
29
+ let fragment = cloneNode.call(EMPTY_FRAGMENT), nodes = Array.from(input);
30
+ for (let i = 0, n = nodes.length; i < n; i++) {
31
+ append.call(fragment, nodes[i]);
32
+ }
33
+ return fragment;
56
34
  }
35
+ return text(input);
57
36
  }
58
37
  ;
package/build/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactiveArray } from '@esportsplus/reactivity';
2
- import { RENDERABLE, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY } from './constants.js';
3
- import { firstChild } from './utilities.js';
2
+ import { RENDERABLE, RENDERABLE_HTML_REACTIVE_ARRAY } from './constants.js';
3
+ import { firstChild } from './utilities/node.js';
4
4
  import attributes from './attributes.js';
5
5
  import slot from './slot/index.js';
6
6
  import html from './html/index.js';
@@ -20,22 +20,14 @@ type Attributes = {
20
20
  type Effect<T> = () => EffectResponse<T>;
21
21
  type EffectResponse<T> = T extends [] ? (Primitive | Renderable)[] : Primitive | Renderable;
22
22
  type Element = HTMLElement & Attributes & Record<PropertyKey, unknown>;
23
- type Elements = Element[];
24
- type Fragment = (DocumentFragment | Node) & Record<PropertyKey, unknown>;
25
23
  type Primitive = bigint | boolean | null | number | string | undefined;
26
- type Renderable = Fragment | RenderableReactive;
24
+ type Renderable = DocumentFragment | Node | NodeList | Primitive | RenderableReactive | Renderable[];
27
25
  type RenderableReactive = Readonly<{
28
26
  [RENDERABLE]: typeof RENDERABLE_HTML_REACTIVE_ARRAY;
29
27
  array: ReactiveArray<unknown[]>;
30
28
  template: (this: ReactiveArray<unknown[]>, ...args: Parameters<Parameters<ReactiveArray<unknown[]>['map']>[0]>) => ReturnType<typeof html>;
31
29
  }>;
32
- type RenderableTemplate = {
33
- [RENDERABLE]: typeof RENDERABLE_HTML_FRAGMENT;
34
- fragment: Fragment;
35
- literals: TemplateStringsArray;
36
- };
37
- type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Fragment | Primitive | RenderableReactive;
38
- type RenderableValues = RenderableValue | RenderableValue[];
30
+ type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Primitive | RenderableReactive;
39
31
  type SlotGroup = {
40
32
  head: Element;
41
33
  tail: Element;
@@ -54,4 +46,4 @@ type Template = {
54
46
  slot: number;
55
47
  }[] | null;
56
48
  };
57
- export type { Attributes, Effect, Element, Elements, Fragment, Renderable, RenderableReactive, RenderableTemplate, RenderableValue, RenderableValues, SlotGroup, Template };
49
+ export type { Attributes, Effect, Element, Renderable, RenderableReactive, RenderableValue, SlotGroup, Template };
@@ -0,0 +1,11 @@
1
+ declare const addEventListener: {
2
+ <K extends keyof ElementEventMap>(type: K, listener: (this: Element, ev: ElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
3
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
4
+ };
5
+ declare const className: (v: any) => void;
6
+ declare const innerHTML: (v: any) => void;
7
+ declare const firstElementChild: () => any;
8
+ declare const nextElementSibling: () => any;
9
+ declare const removeAttribute: (qualifiedName: string) => void;
10
+ declare const setAttribute: (qualifiedName: string, value: string) => void;
11
+ export { addEventListener, className, innerHTML, firstElementChild, nextElementSibling, removeAttribute, setAttribute };
@@ -0,0 +1,9 @@
1
+ let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, prototype = Element.prototype;
2
+ const addEventListener = prototype.addEventListener;
3
+ const className = getOwnPropertyDescriptor(prototype, 'className').set;
4
+ const innerHTML = getOwnPropertyDescriptor(prototype, 'innerHTML').set;
5
+ const firstElementChild = getOwnPropertyDescriptor(prototype, 'firstElementChild').get;
6
+ const nextElementSibling = getOwnPropertyDescriptor(prototype, 'nextElementSibling').get;
7
+ const removeAttribute = prototype.removeAttribute;
8
+ const setAttribute = prototype.setAttribute;
9
+ export { addEventListener, className, innerHTML, firstElementChild, nextElementSibling, removeAttribute, setAttribute };
@@ -0,0 +1,3 @@
1
+ declare const append: (...nodes: (Node | string)[]) => void;
2
+ declare const fragment: (html: string) => DocumentFragment;
3
+ export { append, fragment };
@@ -0,0 +1,11 @@
1
+ import { innerHTML } from './element.js';
2
+ import { cloneNode } from './node.js';
3
+ let scratchpad = document.createElement('template');
4
+ const append = DocumentFragment.prototype.append;
5
+ const fragment = (html) => {
6
+ innerHTML.call(scratchpad, html);
7
+ let content = scratchpad.content;
8
+ scratchpad = cloneNode.call(scratchpad);
9
+ return content;
10
+ };
11
+ export { append, fragment };
@@ -0,0 +1,9 @@
1
+ declare const appendChild: <T extends Node>(node: T) => T;
2
+ declare const cloneNode: (subtree?: boolean) => Node;
3
+ declare const firstChild: () => any;
4
+ declare const lastChild: () => any;
5
+ declare const nextSibling: () => any;
6
+ declare const nodeValue: (v: any) => void;
7
+ declare const parentElement: () => any;
8
+ declare const previousSibling: () => any;
9
+ export { appendChild, cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
@@ -0,0 +1,10 @@
1
+ let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, prototype = Node.prototype;
2
+ const appendChild = prototype.appendChild;
3
+ const cloneNode = prototype.cloneNode;
4
+ const firstChild = getOwnPropertyDescriptor(prototype, 'firstChild').get;
5
+ const lastChild = getOwnPropertyDescriptor(prototype, 'lastChild').get;
6
+ const nextSibling = getOwnPropertyDescriptor(prototype, 'nextSibling').get;
7
+ const nodeValue = getOwnPropertyDescriptor(prototype, 'nodeValue').set;
8
+ const parentElement = getOwnPropertyDescriptor(prototype, 'parentElement').get;
9
+ const previousSibling = getOwnPropertyDescriptor(prototype, 'previousSibling').get;
10
+ export { appendChild, cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
@@ -0,0 +1,3 @@
1
+ declare const microtask: import("@esportsplus/tasks/build/factory").Scheduler;
2
+ declare const raf: import("@esportsplus/tasks/build/factory").Scheduler;
3
+ export { microtask, raf };
@@ -0,0 +1,4 @@
1
+ import { micro as m, raf as r } from '@esportsplus/tasks';
2
+ const microtask = m();
3
+ const raf = r();
4
+ export { microtask, raf };
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: string) => Node;
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { cloneNode, nodeValue } from './node.js';
2
+ let text = document.createTextNode('');
3
+ export default (value) => {
4
+ let element = cloneNode.call(text);
5
+ if (value !== '') {
6
+ nodeValue.call(element, value);
7
+ }
8
+ return element;
9
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
4
  "@esportsplus/queue": "^0.1.0",
5
- "@esportsplus/reactivity": "^0.15.0",
5
+ "@esportsplus/reactivity": "^0.16.1",
6
6
  "@esportsplus/tasks": "^0.2.1",
7
7
  "@esportsplus/utilities": "^0.22.1"
8
8
  },
@@ -14,7 +14,7 @@
14
14
  "private": false,
15
15
  "type": "module",
16
16
  "types": "./build/index.d.ts",
17
- "version": "0.17.0",
17
+ "version": "0.19.0",
18
18
  "scripts": {
19
19
  "build": "tsc && tsc-alias",
20
20
  "-": "-"
package/src/attributes.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { effect } from '@esportsplus/reactivity';
2
2
  import { isArray, isObject, isString } from '@esportsplus/utilities';
3
- import { ondisconnect } from './slot/cleanup';
4
3
  import { STATE_HYDRATING, STATE_NONE, STATE_WAITING } from './constants';
5
4
  import { Attributes, Element } from './types';
6
- import { className, raf, removeAttribute, setAttribute } from './utilities';
5
+ import { className, removeAttribute, setAttribute } from './utilities/element';
6
+ import { raf } from './utilities/queue';
7
7
  import q from '@esportsplus/queue';
8
8
  import event from './event';
9
9
 
@@ -73,31 +73,28 @@ function set(context: Context, name: string, value: unknown, state: State) {
73
73
 
74
74
  let id = (context.store[EFFECT] as number)++;
75
75
 
76
- ondisconnect(
77
- context.element,
78
- effect(() => {
79
- let v = (value as Function)(context.element);
80
-
81
- if (isArray(v)) {
82
- let last = v.length - 1;
83
-
84
- for (let i = 0, n = v.length; i < n; i++) {
85
- update(
86
- context,
87
- id,
88
- name,
89
- v[i],
90
- state === STATE_HYDRATING
91
- ? state
92
- : i !== last ? STATE_WAITING : state
93
- );
94
- }
76
+ effect(() => {
77
+ let v = (value as Function)(context.element);
78
+
79
+ if (isArray(v)) {
80
+ let last = v.length - 1;
81
+
82
+ for (let i = 0, n = v.length; i < n; i++) {
83
+ update(
84
+ context,
85
+ id,
86
+ name,
87
+ v[i],
88
+ state === STATE_HYDRATING
89
+ ? state
90
+ : i !== last ? STATE_WAITING : state
91
+ );
95
92
  }
96
- else {
97
- update(context, id, name, v, state);
98
- }
99
- })
100
- );
93
+ }
94
+ else {
95
+ update(context, id, name, v, state);
96
+ }
97
+ });
101
98
 
102
99
  state = STATE_NONE;
103
100
  }
package/src/constants.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { fragment } from './utilities';
1
+ import { fragment } from './utilities/fragment';
2
2
 
3
3
 
4
4
  const CLEANUP = Symbol();
@@ -47,21 +47,7 @@ const REGEX_SLOT_NODES = /<([\w-]+|[\/!])(?:([^><]*{{\$}}[^><]*)|(?:[^><]*))?>|{
47
47
 
48
48
  const RENDERABLE = Symbol();
49
49
 
50
- const RENDERABLE_ARRAY = 0;
51
-
52
- const RENDERABLE_FRAGMENT = 1;
53
-
54
- const RENDERABLE_HTML_FRAGMENT = 2;
55
-
56
- const RENDERABLE_HTML_REACTIVE_ARRAY = 3;
57
-
58
- const RENDERABLE_NODE = 4;
59
-
60
- const RENDERABLE_NODE_LIST = 5;
61
-
62
- const RENDERABLE_TEXT = 6;
63
-
64
- const RENDERABLE_VOID = 7;
50
+ const RENDERABLE_HTML_REACTIVE_ARRAY = 1;
65
51
 
66
52
 
67
53
  const SLOT_HTML = '<!--$-->';
@@ -83,10 +69,7 @@ export {
83
69
  EMPTY_FRAGMENT,
84
70
  NODE_CLOSING, NODE_ELEMENT, NODE_SLOT, NODE_VOID, NODE_WHITELIST,
85
71
  REGEX_EMPTY_TEXT_NODES, REGEX_SLOT_NODES,
86
- RENDERABLE, RENDERABLE_ARRAY, RENDERABLE_FRAGMENT,
87
- RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY,
88
- RENDERABLE_NODE, RENDERABLE_NODE_LIST, RENDERABLE_TEXT,
89
- RENDERABLE_VOID,
72
+ RENDERABLE, RENDERABLE_HTML_REACTIVE_ARRAY,
90
73
  SLOT_HTML, SLOT_MARKER, SLOT_MARKER_LENGTH,
91
74
  STATE_HYDRATING, STATE_NONE, STATE_WAITING
92
75
  };