glass-easel-devtools-agent 0.10.2 → 0.12.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.
@@ -140,6 +140,7 @@ export declare class MountPointsManager {
140
140
  private useInConsole;
141
141
  generateNodeId(): NodeId;
142
142
  private getNodeId;
143
+ private getActiveNodeId;
143
144
  private queryActiveNode;
144
145
  private getMaybeBackendNode;
145
146
  private startWatch;
@@ -21,7 +21,7 @@ export type AgentRequestKind = {
21
21
  getAttributes: GetAttributes;
22
22
  getGlassEaselAttributes: GetGlassEaselAttributes;
23
23
  useGlassEaselAttributeInConsole: UseGlassEaselAttributeInConsole;
24
- getGlassEaselComposedChildren: GetGlassEaselComposedChildren;
24
+ getGlassEaselNonInheritComposedChildren: GetGlassEaselNonInheritComposedChildren;
25
25
  requestChildNodes: RequestChildNodes;
26
26
  removeNode: RemoveNode;
27
27
  resolveNode: ResolveNode;
@@ -48,7 +48,8 @@ export declare const enum GlassEaselNodeType {
48
48
  TextNode = 257,
49
49
  NativeNode = 258,
50
50
  Component = 259,
51
- VirtualNode = 260
51
+ VirtualNode = 260,
52
+ InheritVirtualNode = 261
52
53
  }
53
54
  export declare const glassEaselNodeTypeToCDP: (t: GlassEaselNodeType) => CDPNodeType.ELEMENT_NODE | CDPNodeType.TEXT_NODE | CDPNodeType.DOCUMENT_NODE;
54
55
  /**
@@ -76,6 +77,8 @@ export type Node = BackendNode & {
76
77
  nodeId: NodeId;
77
78
  /** Node id of its parent (if any); for shadow-root, this is its host. */
78
79
  parentId?: NodeId;
80
+ /** The composed parent (if any). */
81
+ glassEaselNonInheritComposedParentId?: NodeId;
79
82
  /** The local name of the node (for components, it is the component name). */
80
83
  localName: string;
81
84
  /** The text content (if any). */
@@ -284,7 +287,7 @@ export interface UseGlassEaselAttributeInConsole {
284
287
  /**
285
288
  * Get the composed children of a node.
286
289
  */
287
- export interface GetGlassEaselComposedChildren extends RequestResponse {
290
+ export interface GetGlassEaselNonInheritComposedChildren extends RequestResponse {
288
291
  request: {
289
292
  nodeId: NodeId;
290
293
  };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "glass-easel-devtools-agent",
3
- "version": "0.10.2",
3
+ "version": "0.12.0",
4
4
  "main": "dist/index.js",
5
5
  "peerDependencies": {
6
- "glass-easel": "^0.10.2"
6
+ "glass-easel": ">=0.12.0"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@csstools/css-tokenizer": "^2.4.1",
10
10
  "@csstools/selector-specificity": "^3.1.1",
11
11
  "@types/node": "^20.16.5",
12
12
  "devtools-protocol": "^0.0.1319565",
13
- "glass-easel": "^0.10.2",
14
- "glass-easel-template-compiler": "^0.10.2",
13
+ "glass-easel": ">=0.12.0",
14
+ "glass-easel-template-compiler": ">=0.12.0",
15
15
  "postcss-selector-parser": "^6.1.2"
16
16
  },
17
17
  "scripts": {
@@ -29,7 +29,12 @@ export const enum StaticNodeName {
29
29
  const getNodeType = (node: glassEasel.Node): GlassEaselNodeType => {
30
30
  if (node.asTextNode()) return GlassEaselNodeType.TextNode
31
31
  if (node.asNativeNode()) return GlassEaselNodeType.NativeNode
32
- if (node.asVirtualNode()) return GlassEaselNodeType.VirtualNode
32
+ if (node.asVirtualNode()) {
33
+ if (node.asVirtualNode()!.isInheritSlots()) {
34
+ return GlassEaselNodeType.InheritVirtualNode
35
+ }
36
+ return GlassEaselNodeType.VirtualNode
37
+ }
33
38
  if (node.asGeneralComponent()) return GlassEaselNodeType.Component
34
39
  return GlassEaselNodeType.Unknown
35
40
  }
@@ -45,14 +50,21 @@ const getNodeName = (
45
50
  const comp = node.asGeneralComponent()!
46
51
  return local ? comp.is : comp.tagName
47
52
  }
48
- if (nodeType === GlassEaselNodeType.VirtualNode) return node.asVirtualNode()!.is
53
+ if (
54
+ nodeType === GlassEaselNodeType.VirtualNode ||
55
+ nodeType === GlassEaselNodeType.InheritVirtualNode
56
+ ) {
57
+ return node.asVirtualNode()!.is
58
+ }
49
59
  return StaticNodeName.Unknown
50
60
  }
51
61
 
52
62
  export class MountPointsManager {
53
63
  private conn: Connection
54
64
  private nodeIdMap = new WeakMap<glassEasel.Node, NodeId>()
65
+ // active nodes are the nodes that being display and watched
55
66
  private activeNodes = Object.create(null) as Record<NodeId, NodeMeta>
67
+ // backend nodes are the nodes that has being transmitted to the client in arguments but not display
56
68
  private activeBackendNodes = Object.create(null) as Record<NodeId, WeakRef<glassEasel.Node>>
57
69
  readonly documentNodeId = 1
58
70
  private nodeIdInc = 2
@@ -143,7 +155,11 @@ export class MountPointsManager {
143
155
  let glassEaselNodeType = GlassEaselNodeType.Unknown
144
156
  if (comp) glassEaselNodeType = GlassEaselNodeType.Component
145
157
  if (nativeNode) glassEaselNodeType = GlassEaselNodeType.NativeNode
146
- if (virtualNode) glassEaselNodeType = GlassEaselNodeType.VirtualNode
158
+ if (virtualNode) {
159
+ glassEaselNodeType = virtualNode.isInheritSlots()
160
+ ? GlassEaselNodeType.InheritVirtualNode
161
+ : GlassEaselNodeType.VirtualNode
162
+ }
147
163
 
148
164
  // collect basic attributes
149
165
  const virtual = elem.isVirtual()
@@ -325,17 +341,28 @@ export class MountPointsManager {
325
341
  },
326
342
  )
327
343
 
328
- this.conn.setRequestHandler('DOM.getGlassEaselComposedChildren', async ({ nodeId }) => {
329
- const { node } = this.queryActiveNode(nodeId)
330
- const elem = node.asElement()
331
- if (!elem) return { nodes: [] }
332
- const nodes: dom.Node[] = []
333
- elem.forEachComposedChild((child) => {
334
- const nodeMeta = this.activateNode(child)
335
- nodes.push(this.collectNodeDetails(nodeMeta, 0, false))
336
- })
337
- return { nodes }
338
- })
344
+ this.conn.setRequestHandler(
345
+ 'DOM.getGlassEaselNonInheritComposedChildren',
346
+ async ({ nodeId }) => {
347
+ const { node } = this.queryActiveNode(nodeId)
348
+ const elem = node.asElement()
349
+ if (!elem) return { nodes: [] }
350
+ const nodes: dom.Node[] = []
351
+ if (elem.isInheritSlots()) {
352
+ elem.childNodes.forEach((child) => {
353
+ const nodeMeta = this.activateNode(child)
354
+ nodes.push(this.collectNodeDetails(nodeMeta, 0, false))
355
+ })
356
+ } else {
357
+ elem.forEachComposedChild((child) => {
358
+ if (child.parentNode?.isInheritSlots()) return
359
+ const nodeMeta = this.activateNode(child)
360
+ nodes.push(this.collectNodeDetails(nodeMeta, 0, false))
361
+ })
362
+ }
363
+ return { nodes }
364
+ },
365
+ )
339
366
 
340
367
  this.conn.setRequestHandler(
341
368
  'DOM.pushNodesByBackendIdsToFrontend',
@@ -648,6 +675,14 @@ export class MountPointsManager {
648
675
  return newNodeId
649
676
  }
650
677
 
678
+ private getActiveNodeId(node: glassEasel.Node): NodeId | null {
679
+ const nodeId = this.nodeIdMap.get(node)
680
+ if (nodeId !== undefined) {
681
+ return this.activeNodes[nodeId] ? nodeId : null
682
+ }
683
+ return null
684
+ }
685
+
651
686
  private queryActiveNode(nodeId: NodeId): NodeMeta {
652
687
  const nodeMeta = this.activeNodes[nodeId]
653
688
  if (!nodeMeta) throw new Error(`no active node found for node id ${nodeId}`)
@@ -752,11 +787,32 @@ export class MountPointsManager {
752
787
  if (index < 0) return
753
788
  const previousNodeId = index === 0 ? 0 : this.getNodeId(parent.childNodes[index - 1])
754
789
  const childMeta = this.activateNode(child)
790
+ const node = this.collectNodeDetails(childMeta, 0, false)
755
791
  this.conn.sendEvent('DOM.childNodeInserted', {
756
792
  parentNodeId: nodeId,
757
793
  previousNodeId,
758
- node: this.collectNodeDetails(childMeta, 0, false),
794
+ node,
759
795
  })
796
+ const composedParent = child.getComposedParent()
797
+ if (!parent.isInheritSlots() && composedParent && composedParent !== parent) {
798
+ const composedParentId = this.getActiveNodeId(composedParent)
799
+ if (composedParentId) {
800
+ let prev: glassEasel.Node | null = null
801
+ const found = composedParent.forEachComposedChild((c) => {
802
+ if (c === child) return false
803
+ prev = c
804
+ return true
805
+ })
806
+ if (found) {
807
+ const previousNodeId = prev ? this.getNodeId(prev) : 0
808
+ this.conn.sendEvent('DOM.childNodeInserted', {
809
+ parentNodeId: composedParentId,
810
+ previousNodeId,
811
+ node,
812
+ })
813
+ }
814
+ }
815
+ }
760
816
  })
761
817
  ev.removedNodes?.forEach((child) => {
762
818
  this.deactivateNodeTree(child)
@@ -764,6 +820,16 @@ export class MountPointsManager {
764
820
  parentNodeId: nodeId,
765
821
  nodeId: this.getNodeId(child),
766
822
  })
823
+ const composedParent = child.getComposedParent()
824
+ if (!parent.isInheritSlots() && composedParent && composedParent !== parent) {
825
+ const composedParentId = this.getActiveNodeId(composedParent)
826
+ if (composedParentId) {
827
+ this.conn.sendEvent('DOM.childNodeRemoved', {
828
+ parentNodeId: composedParentId,
829
+ nodeId: this.getNodeId(child),
830
+ })
831
+ }
832
+ }
767
833
  })
768
834
  return
769
835
  }
@@ -886,6 +952,17 @@ export class MountPointsManager {
886
952
  else if (node.parentNode) parentId = this.getNodeId(node.parentNode)
887
953
  else if (node.asShadowRoot()) parentId = this.getNodeId(node.asShadowRoot()!.getHostNode())
888
954
  else parentId = undefined
955
+ let composedParentId: NodeId | undefined
956
+ if (isMountPoint) {
957
+ composedParentId = this.documentNodeId
958
+ } else if (node.parentNode?.isInheritSlots()) {
959
+ composedParentId = parentId
960
+ } else {
961
+ const composedParent = node.getComposedParent()
962
+ if (composedParent) {
963
+ composedParentId = this.addBackendNode(composedParent)
964
+ }
965
+ }
889
966
  const localName = getNodeName(node, ty, true)
890
967
  const nodeValue = node.asTextNode()?.textContent ?? ''
891
968
 
@@ -993,6 +1070,7 @@ export class MountPointsManager {
993
1070
  const elem = node.asElement()!
994
1071
  distributedNodes = []
995
1072
  elem.forEachComposedChild((child) => {
1073
+ if (child.parentNode?.isInheritSlots()) return
996
1074
  const nodeId = this.addBackendNode(child)
997
1075
  const n = this.collectNodeBasicInfomation(nodeId, child)
998
1076
  if (n) distributedNodes!.push(n)
@@ -1008,6 +1086,7 @@ export class MountPointsManager {
1008
1086
  inheritSlots,
1009
1087
  nodeId,
1010
1088
  parentId,
1089
+ glassEaselNonInheritComposedParentId: composedParentId,
1011
1090
  localName,
1012
1091
  nodeValue,
1013
1092
  attributes,
@@ -23,7 +23,7 @@ export type AgentRequestKind = {
23
23
  getAttributes: GetAttributes
24
24
  getGlassEaselAttributes: GetGlassEaselAttributes
25
25
  useGlassEaselAttributeInConsole: UseGlassEaselAttributeInConsole
26
- getGlassEaselComposedChildren: GetGlassEaselComposedChildren
26
+ getGlassEaselNonInheritComposedChildren: GetGlassEaselNonInheritComposedChildren
27
27
  requestChildNodes: RequestChildNodes
28
28
  removeNode: RemoveNode
29
29
  resolveNode: ResolveNode
@@ -54,6 +54,7 @@ export const enum GlassEaselNodeType {
54
54
  NativeNode,
55
55
  Component,
56
56
  VirtualNode,
57
+ InheritVirtualNode,
57
58
  }
58
59
 
59
60
  export const glassEaselNodeTypeToCDP = (t: GlassEaselNodeType) => {
@@ -61,6 +62,7 @@ export const glassEaselNodeTypeToCDP = (t: GlassEaselNodeType) => {
61
62
  if (t === GlassEaselNodeType.NativeNode) return CDPNodeType.ELEMENT_NODE
62
63
  if (t === GlassEaselNodeType.Component) return CDPNodeType.ELEMENT_NODE
63
64
  if (t === GlassEaselNodeType.VirtualNode) return CDPNodeType.ELEMENT_NODE
65
+ if (t === GlassEaselNodeType.InheritVirtualNode) return CDPNodeType.ELEMENT_NODE
64
66
  if (t === GlassEaselNodeType.Unknown) return CDPNodeType.DOCUMENT_NODE
65
67
  return CDPNodeType.DOCUMENT_NODE
66
68
  }
@@ -91,6 +93,8 @@ export type Node = BackendNode & {
91
93
  nodeId: NodeId
92
94
  /** Node id of its parent (if any); for shadow-root, this is its host. */
93
95
  parentId?: NodeId
96
+ /** The composed parent (if any). */
97
+ glassEaselNonInheritComposedParentId?: NodeId
94
98
  /** The local name of the node (for components, it is the component name). */
95
99
  localName: string
96
100
  /** The text content (if any). */
@@ -248,7 +252,7 @@ export interface UseGlassEaselAttributeInConsole {
248
252
  /**
249
253
  * Get the composed children of a node.
250
254
  */
251
- export interface GetGlassEaselComposedChildren extends RequestResponse {
255
+ export interface GetGlassEaselNonInheritComposedChildren extends RequestResponse {
252
256
  request: { nodeId: NodeId }
253
257
  response: { nodes: Node[] }
254
258
  }