glass-easel-devtools-panel 0.10.1 → 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.
@@ -11,7 +11,7 @@ import {
11
11
  } from '../../events'
12
12
  import { sendRequest } from '../../message_channel'
13
13
  import { error, warn } from '../../utils'
14
- import { store } from '../store'
14
+ import { store, type UserConfig } from '../store'
15
15
 
16
16
  type AttributeMeta = { name: string; value: string; isProperty: boolean; updateAniTs: number }
17
17
 
@@ -19,6 +19,7 @@ const enum DisplayKind {
19
19
  Text = 0,
20
20
  Tag = 1,
21
21
  VirtualTag = 2,
22
+ InheritVirtualTag = 3,
22
23
  }
23
24
 
24
25
  export const compDef = Component()
@@ -27,6 +28,7 @@ export const compDef = Component()
27
28
  propertyPassingDeepCopy: DeepCopyKind.None,
28
29
  propertyEarlyInit: true,
29
30
  })
31
+ .property('isShadowRoot', Boolean)
30
32
  .property('nodeInfo', {
31
33
  type: Object,
32
34
  value: null as protocol.dom.Node | null,
@@ -44,6 +46,7 @@ export const compDef = Component()
44
46
  children: [] as protocol.dom.Node[],
45
47
  tagVarName: '',
46
48
  tagUpdateHighlight: false,
49
+ hideSelf: false,
47
50
  }))
48
51
  .init((ctx) => {
49
52
  // eslint-disable-next-line @typescript-eslint/unbound-method
@@ -60,7 +63,7 @@ export const compDef = Component()
60
63
  // store bindings
61
64
  initStoreBindings(ctx, {
62
65
  store,
63
- fields: ['selectedNodeId', 'highlightNodeId'],
66
+ fields: ['selectedNodeId', 'highlightNodeId', 'userConfig'],
64
67
  })
65
68
 
66
69
  // child nodes listeners
@@ -206,8 +209,9 @@ export const compDef = Component()
206
209
  } else {
207
210
  let tagName = nodeInfo?.nodeName ?? ''
208
211
  if (nodeType === protocol.dom.GlassEaselNodeType.Unknown) tagName = 'unknown'
212
+ const isInherit = nodeType === protocol.dom.GlassEaselNodeType.InheritVirtualNode
209
213
  setData({
210
- kind: DisplayKind.VirtualTag,
214
+ kind: isInherit ? DisplayKind.InheritVirtualTag : DisplayKind.VirtualTag,
211
215
  tagName,
212
216
  })
213
217
  }
@@ -228,11 +232,42 @@ export const compDef = Component()
228
232
  }
229
233
  })
230
234
 
235
+ // hide self node mode for virtual nodes
236
+ observer(
237
+ ['kind', 'isShadowRoot', 'userConfig'] as any,
238
+ (kind: DisplayKind, isShadowRoot: boolean, userConfig: UserConfig) => {
239
+ let hideSelf = false
240
+ if (userConfig) {
241
+ if (
242
+ userConfig.showComposed &&
243
+ (kind === DisplayKind.InheritVirtualTag || kind === DisplayKind.VirtualTag)
244
+ ) {
245
+ hideSelf = true
246
+ } else if (!isShadowRoot) {
247
+ if (userConfig.hideVirtual) {
248
+ if (kind === DisplayKind.InheritVirtualTag || kind === DisplayKind.VirtualTag) {
249
+ hideSelf = true
250
+ }
251
+ } else if (userConfig.hideInherit) {
252
+ if (kind === DisplayKind.InheritVirtualTag) hideSelf = true
253
+ }
254
+ }
255
+ }
256
+ if (!data.hideSelf && hideSelf) {
257
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises, promise/catch-or-return
258
+ Promise.resolve().then(updateChildren)
259
+ }
260
+ setData({ hideSelf })
261
+ },
262
+ )
263
+
231
264
  // toggle children events
232
265
  const updateChildren = async () => {
233
266
  const distributedNodes = data.nodeInfo?.distributedNodes
234
267
  if (distributedNodes) {
235
- const { nodes } = await sendRequest('DOM.getGlassEaselComposedChildren', { nodeId })
268
+ const { nodes } = await sendRequest('DOM.getGlassEaselNonInheritComposedChildren', {
269
+ nodeId,
270
+ })
236
271
  setData({ children: nodes })
237
272
  } else {
238
273
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -248,7 +283,8 @@ export const compDef = Component()
248
283
  Promise.resolve().then(updateChildren)
249
284
  }
250
285
  })
251
- const visitChildNodePath = method(async (nodePath: protocol.dom.Node[]) => {
286
+ const visitChildNodePath = method(async (nodePath: protocol.dom.Node[], composed: boolean) => {
287
+ console.info('!!!', nodePath)
252
288
  const [node, ...childPath] = nodePath
253
289
  if (childPath.length === 0) {
254
290
  setData({ children: node.children })
@@ -259,9 +295,12 @@ export const compDef = Component()
259
295
  showChildNodes: true,
260
296
  children: node.children,
261
297
  })
298
+ if (composed && data.nodeInfo?.distributedNodes) {
299
+ await updateChildren()
300
+ }
262
301
  const childComp = self.selectComponent(`#child-${childPath[0].nodeId}`, compDef)
263
302
  if (childComp) {
264
- await childComp.visitChildNodePath(childPath)
303
+ await childComp.visitChildNodePath(childPath, composed)
265
304
  } else {
266
305
  error(`cannot find child node id ${childPath[0].nodeId}`)
267
306
  }
@@ -1,44 +1,52 @@
1
- <view wx:if="{{ kind === 1 || kind === 2 }}" class="tag {{ tagUpdateHighlight ? 'updated' : '' }}">
2
- <view class="fold-arrow">
3
- <view wx:if="{{ hasChildNodes || hasSlotContent || hasShadowRoot }}" class="fold-arrow-icon {{ showChildNodes ? 'fold-arrow-icon_open' : '' }}" catch:tap="toggleChildren">▶</view>
4
- </view>
1
+ <view wx:if="{{ kind === 1 || kind === 2 || kind === 3 || kind === 4 }}" class="tag {{ tagUpdateHighlight ? 'updated' : '' }}">
2
+ <block wx:if="{{ hideSelf }}"></block>
3
+ <block wx:else>
4
+ <view class="fold-arrow">
5
+ <view wx:if="{{ hasChildNodes || hasSlotContent || hasShadowRoot }}" class="fold-arrow-icon {{ showChildNodes ? 'fold-arrow-icon_open' : '' }}" catch:tap="toggleChildren">▶</view>
6
+ </view>
5
7
 
6
- <view
7
- class="tag-body {{ selectedNodeId === nodeInfo.nodeId ? 'tag-body_selected' : '' }} {{ highlightNodeId === nodeInfo.nodeId ? 'tag-body_highlight' : '' }}"
8
- hover-class="tag-body_hover"
9
- catch:tap="selectTag"
10
- bind:mouseenter="startHoverTag"
11
- bind:mouseleave="endHoverTag"
12
- >
13
- <block wx:if="{{ kind === 1 }}">
14
- <view class="tag-text">&lt;</view>
15
- <view class="tag-name">{{ tagName }}</view>
16
- <block wx:for="{{ attributes }}">
17
- <view class="attribute">
18
- <block>{{ ' ' }}</block>
19
- <view class="attribute-name {{ item.isProperty ? 'attribute-name_property' : '' }}">{{ item.name }}</view>
20
- <block>{{ '="' }}</block>
21
- <view class="attribute-value {{ item.updateAniTs ? 'updated' : '' }}">{{ item.value }}</view>
22
- <block>{{ '"' }}</block>
23
- </view>
8
+ <view
9
+ class="tag-body {{ selectedNodeId === nodeInfo.nodeId ? 'tag-body_selected' : '' }} {{ highlightNodeId === nodeInfo.nodeId ? 'tag-body_highlight' : '' }}"
10
+ hover-class="tag-body_hover"
11
+ catch:tap="selectTag"
12
+ bind:mouseenter="startHoverTag"
13
+ bind:mouseleave="endHoverTag"
14
+ >
15
+ <block wx:if="{{ kind === 1 }}">
16
+ <view class="tag-text">&lt;</view>
17
+ <view class="tag-name">{{ tagName }}</view>
18
+ <block wx:for="{{ attributes }}">
19
+ <view class="attribute">
20
+ <block>{{ ' ' }}</block>
21
+ <view class="attribute-name {{ item.isProperty ? 'attribute-name_property' : '' }}">{{ item.name }}</view>
22
+ <block>{{ '="' }}</block>
23
+ <view class="attribute-value {{ item.updateAniTs ? 'updated' : '' }}">{{ item.value }}</view>
24
+ <block>{{ '"' }}</block>
25
+ </view>
26
+ </block>
27
+ <view class="tag-text">&gt;</view>
24
28
  </block>
25
- <view class="tag-text">&gt;</view>
26
- </block>
27
- <block wx:else>
28
- <view class="virtual-tag-name">{{ tagName }}</view>
29
- </block>
30
- </view>
29
+ <block wx:else>
30
+ <view class="virtual-tag-name">{{ tagName }}</view>
31
+ </block>
32
+ </view>
31
33
 
32
- <view class="tag-var-name-wrapper" hidden="{{ selectedNodeId !== nodeInfo.nodeId }}">
33
- <view wx:if="{{ tagVarName }}" class="tag-var-name">={{ tagVarName }}</view>
34
- <view wx:else class="tag-var-name" hover-class="tag-var-name_hover" catch:tap="useElementInConsole">↖</view>
35
- </view>
34
+ <view class="tag-var-name-wrapper" hidden="{{ selectedNodeId !== nodeInfo.nodeId }}">
35
+ <view wx:if="{{ tagVarName }}" class="tag-var-name">={{ tagVarName }}</view>
36
+ <view wx:else class="tag-var-name" hover-class="tag-var-name_hover" catch:tap="useElementInConsole">↖</view>
37
+ </view>
38
+ </block>
36
39
 
37
- <view hidden="{{ !showChildNodes }}" class="children">
40
+ <view
41
+ hidden="{{ !showChildNodes && !hideSelf }}"
42
+ class="children {{ hideSelf ? '' : 'children_indent' }}"
43
+ >
38
44
  <view wx:if="{{ hasShadowRoot }}" class="shadow-roots">
39
- <element wx:for="{{ shadowRoots }}" wx:key="nodeId" id="child-{{ item.nodeId }}" node-info="{{ item }}" />
45
+ <element is-shadow-root wx:for="{{ shadowRoots }}" wx:key="nodeId" id="child-{{ item.nodeId }}" node-info="{{ item }}" />
40
46
  </view>
41
- <element wx:for="{{ children }}" wx:key="nodeId" id="child-{{ item.nodeId }}" node-info="{{ item }}" />
47
+ <block wx:if="{{ !userConfig.showComposed || isShadowRoot || !hasShadowRoot || nodeInfo.distributedNodes != undefined }}">
48
+ <element wx:for="{{ children }}" wx:key="nodeId" id="child-{{ item.nodeId }}" node-info="{{ item }}" />
49
+ </block>
42
50
  </view>
43
51
  </view>
44
52
 
@@ -31,6 +31,7 @@
31
31
  line-height: 1em;
32
32
  color: #444;
33
33
  text-align: center;
34
+ user-select: none;
34
35
  }
35
36
  .fold-arrow-icon {
36
37
  width: 1em;
@@ -94,7 +95,7 @@
94
95
  .color-mode(color, @attribute-value);
95
96
  }
96
97
 
97
- .children {
98
+ .children_indent {
98
99
  margin-left: 1em;
99
100
  }
100
101
 
@@ -1,6 +1,11 @@
1
- import type { PageConstructor, ComponentConstructor } from 'glass-easel-miniprogram-adapter'
1
+ import type {
2
+ PageConstructor,
3
+ ComponentConstructor,
4
+ BehaviorConstructor,
5
+ } from 'glass-easel-miniprogram-adapter'
2
6
 
3
7
  declare global {
4
8
  const Page: PageConstructor
5
9
  const Component: ComponentConstructor
10
+ const Behavior: BehaviorConstructor
6
11
  }