@remote-dom/polyfill 1.3.0 → 1.4.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 (52) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/cjs/Attr.cjs +1 -2
  3. package/build/cjs/CustomElementRegistry.cjs +2 -2
  4. package/build/cjs/Document.cjs +6 -2
  5. package/build/cjs/DocumentFragment.cjs +2 -2
  6. package/build/cjs/Element.cjs +2 -2
  7. package/build/cjs/Event.cjs +5 -5
  8. package/build/cjs/Node.cjs +6 -8
  9. package/build/cjs/ParentNode.cjs +21 -6
  10. package/build/cjs/SVGElement.cjs +1 -1
  11. package/build/cjs/Text.cjs +1 -1
  12. package/build/cjs/Window.cjs +20 -20
  13. package/build/cjs/constants.cjs +2 -0
  14. package/build/cjs/shared.cjs +20 -0
  15. package/build/esm/Attr.mjs +1 -2
  16. package/build/esm/CustomElementRegistry.mjs +2 -2
  17. package/build/esm/Document.mjs +7 -3
  18. package/build/esm/DocumentFragment.mjs +2 -2
  19. package/build/esm/Element.mjs +2 -2
  20. package/build/esm/Event.mjs +5 -5
  21. package/build/esm/Node.mjs +8 -10
  22. package/build/esm/ParentNode.mjs +22 -7
  23. package/build/esm/SVGElement.mjs +1 -1
  24. package/build/esm/Text.mjs +1 -1
  25. package/build/esm/Window.mjs +20 -20
  26. package/build/esm/constants.mjs +2 -1
  27. package/build/esm/shared.mjs +20 -2
  28. package/build/esnext/Attr.esnext +0 -1
  29. package/build/esnext/Document.esnext +6 -2
  30. package/build/esnext/Node.esnext +7 -9
  31. package/build/esnext/ParentNode.esnext +20 -5
  32. package/build/esnext/constants.esnext +2 -1
  33. package/build/esnext/shared.esnext +20 -2
  34. package/build/tsconfig.tsbuildinfo +1 -1
  35. package/build/typescript/Attr.d.ts +0 -1
  36. package/build/typescript/Attr.d.ts.map +1 -1
  37. package/build/typescript/Document.d.ts +2 -1
  38. package/build/typescript/Document.d.ts.map +1 -1
  39. package/build/typescript/Node.d.ts +3 -1
  40. package/build/typescript/Node.d.ts.map +1 -1
  41. package/build/typescript/ParentNode.d.ts.map +1 -1
  42. package/build/typescript/constants.d.ts +1 -0
  43. package/build/typescript/constants.d.ts.map +1 -1
  44. package/build/typescript/shared.d.ts +2 -0
  45. package/build/typescript/shared.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/source/Attr.ts +0 -1
  48. package/source/Document.ts +6 -1
  49. package/source/Node.ts +10 -7
  50. package/source/ParentNode.ts +22 -4
  51. package/source/constants.ts +1 -0
  52. package/source/shared.ts +28 -1
package/source/Node.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  NamespaceURI,
9
9
  NodeType,
10
10
  HOOKS,
11
+ IS_CONNECTED,
11
12
  } from './constants.ts';
12
13
  import type {Document} from './Document.ts';
13
14
  import type {ParentNode} from './ParentNode.ts';
@@ -17,6 +18,7 @@ import {
17
18
  isParentNode,
18
19
  isTextNode,
19
20
  cloneNode,
21
+ descendants,
20
22
  } from './shared.ts';
21
23
 
22
24
  export class Node extends EventTarget {
@@ -28,6 +30,7 @@ export class Node extends EventTarget {
28
30
  [CHILD]: Node | null = null;
29
31
  [PREV]: Node | null = null;
30
32
  [NEXT]: Node | null = null;
33
+ [IS_CONNECTED] = false;
31
34
 
32
35
  protected get [HOOKS]() {
33
36
  return this[OWNER_DOCUMENT].defaultView[HOOKS];
@@ -45,6 +48,10 @@ export class Node extends EventTarget {
45
48
  return this[OWNER_DOCUMENT];
46
49
  }
47
50
 
51
+ get isConnected() {
52
+ return this[IS_CONNECTED];
53
+ }
54
+
48
55
  isDefaultNamespace(namespace: string) {
49
56
  return namespace === NamespaceURI.XHTML;
50
57
  }
@@ -113,17 +120,13 @@ export class Node extends EventTarget {
113
120
  get textContent(): string | null {
114
121
  if (isCharacterData(this)) return this.data;
115
122
  let text = '';
116
- function walk(node: Node) {
123
+
124
+ for (const node of descendants(this)) {
117
125
  if (isTextNode(node)) {
118
126
  text += node.data;
119
127
  }
120
- const child = node[CHILD];
121
- if (child) walk(child);
122
- const sibling = node[NEXT];
123
- if (sibling) walk(sibling);
124
128
  }
125
- const child = this[CHILD];
126
- if (child) walk(child);
129
+
127
130
  return text;
128
131
  }
129
132
 
@@ -6,11 +6,13 @@ import {
6
6
  OWNER_DOCUMENT,
7
7
  NodeType,
8
8
  HOOKS,
9
+ IS_CONNECTED,
9
10
  } from './constants.ts';
10
11
  import type {Node} from './Node.ts';
11
12
  import {ChildNode, toNode} from './ChildNode.ts';
12
13
  import {NodeList} from './NodeList.ts';
13
14
  import {querySelectorAll, querySelector} from './selectors.ts';
15
+ import {selfAndDescendants} from './shared.ts';
14
16
 
15
17
  export class ParentNode extends ChildNode {
16
18
  readonly childNodes = new NodeList();
@@ -66,8 +68,16 @@ export class ParentNode extends ChildNode {
66
68
  children.splice(children.indexOf(child), 1);
67
69
  }
68
70
 
69
- (child as any).disconnectedCallback?.();
70
- this[HOOKS].removeChild?.(this as any, child as any, childNodesIndex);
71
+ if (this[IS_CONNECTED]) {
72
+ for (const node of selfAndDescendants(child)) {
73
+ node[IS_CONNECTED] = false;
74
+ (node as any).disconnectedCallback?.();
75
+ }
76
+ }
77
+
78
+ if (this.nodeType === NodeType.ELEMENT_NODE) {
79
+ this[HOOKS].removeChild?.(this as any, child as any, childNodesIndex);
80
+ }
71
81
  }
72
82
 
73
83
  replaceChild(newChild: Node, oldChild: Node) {
@@ -154,7 +164,15 @@ export class ParentNode extends ChildNode {
154
164
  if (isElement) this.children.push(child);
155
165
  }
156
166
 
157
- (child as any).connectedCallback?.();
158
- this[HOOKS].insertChild?.(this as any, child as any, insertIndex);
167
+ if (this[IS_CONNECTED]) {
168
+ for (const node of selfAndDescendants(child)) {
169
+ node[IS_CONNECTED] = true;
170
+ (node as any).connectedCallback?.();
171
+ }
172
+ }
173
+
174
+ if (this.nodeType === NodeType.ELEMENT_NODE) {
175
+ this[HOOKS].insertChild?.(this as any, child as any, insertIndex);
176
+ }
159
177
  }
160
178
  }
@@ -16,6 +16,7 @@ export const PATH = Symbol('path');
16
16
  export const STOP_IMMEDIATE_PROPAGATION = Symbol('stop_immediate_propagation');
17
17
  export const CONTENT = Symbol('content');
18
18
  export const HOOKS = Symbol('hooks');
19
+ export const IS_CONNECTED = Symbol('is_connected');
19
20
 
20
21
  // @TODO remove explicit values
21
22
  export const enum NodeType {
package/source/shared.ts CHANGED
@@ -1,4 +1,11 @@
1
- import {DATA, OWNER_DOCUMENT, ATTRIBUTES, NodeType} from './constants.ts';
1
+ import {
2
+ DATA,
3
+ OWNER_DOCUMENT,
4
+ ATTRIBUTES,
5
+ NodeType,
6
+ CHILD,
7
+ NEXT,
8
+ } from './constants.ts';
2
9
  import type {Document} from './Document.ts';
3
10
  import type {DocumentFragment} from './DocumentFragment.ts';
4
11
  import type {Node} from './Node.ts';
@@ -78,3 +85,23 @@ export function cloneNode(
78
85
  return cloned;
79
86
  }
80
87
  }
88
+
89
+ export function descendants(node: Node) {
90
+ const nodes: Node[] = [];
91
+ const walk = (node: Node) => {
92
+ nodes.push(node);
93
+ const child = node[CHILD];
94
+ if (child) walk(child);
95
+ const sibling = node[NEXT];
96
+ if (sibling) walk(sibling);
97
+ };
98
+ const child = node[CHILD];
99
+ if (child) walk(child);
100
+ return nodes;
101
+ }
102
+
103
+ export function selfAndDescendants(node: Node) {
104
+ const nodes = descendants(node);
105
+ nodes.unshift(node);
106
+ return nodes;
107
+ }