@quicktvui/web-renderer 1.0.6 → 1.0.7
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.
package/package.json
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* QtBaseComponent - Base class for all QuickTV UI components
|
|
3
|
-
* Provides common property handling (visible, visibility, etc.)
|
|
3
|
+
* Provides common property handling (visible, visibility, showOnState, etc.)
|
|
4
4
|
*/
|
|
5
5
|
import { HippyWebView } from '@hippy/web-renderer'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Visibility enum values
|
|
9
|
-
* @typedef {'visible' | 'invisible' | 'gone'} QTVisibility
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
7
|
export class QtBaseComponent extends HippyWebView {
|
|
13
8
|
constructor(context, id, pId) {
|
|
14
9
|
super(context, id, pId)
|
|
15
|
-
// Store original display value for visibility toggle
|
|
16
10
|
this._originalDisplay = undefined
|
|
11
|
+
this._showOnState = null
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
/**
|
|
20
|
-
* Override updateProperty to handle common properties first
|
|
21
|
-
* Subclasses should call super.updateProperty(key, value) for unhandled properties
|
|
22
|
-
*/
|
|
23
14
|
updateProperty(key, value) {
|
|
24
15
|
if (key === 'type' && this.dom) {
|
|
25
16
|
if (value !== null && value !== undefined && value !== '') {
|
|
@@ -37,12 +28,6 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
37
28
|
super.updateProperty(key, value)
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
/**
|
|
41
|
-
* Handle common properties
|
|
42
|
-
* @param {string} key - Property name
|
|
43
|
-
* @param {*} value - Property value
|
|
44
|
-
* @returns {boolean} - True if handled
|
|
45
|
-
*/
|
|
46
31
|
_handleCommonProperty(key, value) {
|
|
47
32
|
switch (key) {
|
|
48
33
|
case 'visible':
|
|
@@ -54,7 +39,6 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
54
39
|
return true
|
|
55
40
|
|
|
56
41
|
case 'autofocus':
|
|
57
|
-
// 将 autofocus 属性设置到 DOM 元素上,供 TVFocusManager 识别
|
|
58
42
|
if (value === true || value === 'true' || value === 1 || value === '1') {
|
|
59
43
|
this.dom.setAttribute('autofocus', 'true')
|
|
60
44
|
} else {
|
|
@@ -63,7 +47,6 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
63
47
|
return true
|
|
64
48
|
|
|
65
49
|
case 'name':
|
|
66
|
-
// 存储 name 属性到组件实例和 DOM 上,用于子组件查找
|
|
67
50
|
this.props = this.props || {}
|
|
68
51
|
this.props.name = value
|
|
69
52
|
if (value) {
|
|
@@ -73,39 +56,26 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
73
56
|
}
|
|
74
57
|
return true
|
|
75
58
|
|
|
59
|
+
case 'showOnState':
|
|
60
|
+
this._setShowOnState(value)
|
|
61
|
+
return true
|
|
62
|
+
|
|
76
63
|
default:
|
|
77
64
|
return false
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
67
|
|
|
81
|
-
/**
|
|
82
|
-
* Set component visibility via boolean
|
|
83
|
-
* @param {boolean} visible - true to show, false to hide
|
|
84
|
-
*/
|
|
85
68
|
_setVisible(visible) {
|
|
86
69
|
if (visible === true) {
|
|
87
|
-
// Restore original display value if saved
|
|
88
70
|
if (this._originalDisplay !== undefined) {
|
|
89
71
|
this.dom.style.display = this._originalDisplay
|
|
90
72
|
} else {
|
|
91
|
-
// In Hippy, all elements default to flex layout
|
|
92
|
-
// Check if the element has flex properties and set display: flex accordingly
|
|
93
73
|
const style = this.dom.style
|
|
94
|
-
const hasFlexProperties =
|
|
95
|
-
style.flexDirection ||
|
|
96
|
-
style.justifyContent ||
|
|
97
|
-
style.alignItems ||
|
|
98
|
-
style.flexWrap ||
|
|
99
|
-
style.flexGrow ||
|
|
100
|
-
style.flexShrink
|
|
101
|
-
|
|
102
|
-
// Default to 'flex' for Hippy compatibility, unless display is already set
|
|
103
74
|
if (!style.display || style.display === 'none') {
|
|
104
|
-
style.display =
|
|
75
|
+
style.display = 'flex'
|
|
105
76
|
}
|
|
106
77
|
}
|
|
107
78
|
} else {
|
|
108
|
-
// Save current display value before hiding
|
|
109
79
|
if (this._originalDisplay === undefined) {
|
|
110
80
|
const currentDisplay = this.dom.style.display
|
|
111
81
|
if (currentDisplay && currentDisplay !== 'none') {
|
|
@@ -116,19 +86,12 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
116
86
|
}
|
|
117
87
|
}
|
|
118
88
|
|
|
119
|
-
/**
|
|
120
|
-
* Set component visibility via enum
|
|
121
|
-
* @param {QTVisibility} visibility - 'visible' | 'invisible' | 'gone'
|
|
122
|
-
*/
|
|
123
89
|
_setVisibility(visibility) {
|
|
124
90
|
switch (visibility) {
|
|
125
91
|
case 'visible':
|
|
126
|
-
// Restore display and ensure visibility
|
|
127
92
|
if (this._originalDisplay !== undefined) {
|
|
128
93
|
this.dom.style.display = this._originalDisplay
|
|
129
94
|
} else {
|
|
130
|
-
// In Hippy, all elements default to flex layout
|
|
131
|
-
// Default to 'flex' for Hippy compatibility
|
|
132
95
|
const style = this.dom.style
|
|
133
96
|
if (!style.display || style.display === 'none') {
|
|
134
97
|
style.display = 'flex'
|
|
@@ -138,12 +101,10 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
138
101
|
break
|
|
139
102
|
|
|
140
103
|
case 'invisible':
|
|
141
|
-
// Hidden but takes space
|
|
142
104
|
this.dom.style.visibility = 'hidden'
|
|
143
105
|
break
|
|
144
106
|
|
|
145
107
|
case 'gone':
|
|
146
|
-
// Completely hidden, doesn't take space
|
|
147
108
|
if (this._originalDisplay === undefined) {
|
|
148
109
|
const currentDisplay = this.dom.style.display
|
|
149
110
|
if (currentDisplay && currentDisplay !== 'none') {
|
|
@@ -158,19 +119,91 @@ export class QtBaseComponent extends HippyWebView {
|
|
|
158
119
|
}
|
|
159
120
|
}
|
|
160
121
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
122
|
+
_setShowOnState(value) {
|
|
123
|
+
if (value === null || value === undefined) {
|
|
124
|
+
this._showOnState = null
|
|
125
|
+
this.dom.removeAttribute('showOnState')
|
|
126
|
+
this.dom.style.display = ''
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this._showOnState = value
|
|
131
|
+
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
this.dom.setAttribute('showOnState', JSON.stringify(value))
|
|
134
|
+
} else {
|
|
135
|
+
this.dom.setAttribute('showOnState', String(value))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this._initShowOnStateVisibility()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_initShowOnStateVisibility() {
|
|
142
|
+
if (!this._showOnState) return
|
|
143
|
+
|
|
144
|
+
const focusedParent = this.dom.closest('.focused')
|
|
145
|
+
const selectedParent = this.dom.closest('[selected="true"], [selected=""]')
|
|
146
|
+
|
|
147
|
+
let currentState = 'normal'
|
|
148
|
+
if (focusedParent) {
|
|
149
|
+
currentState = 'focused'
|
|
150
|
+
} else if (selectedParent) {
|
|
151
|
+
currentState = 'selected'
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this._applyShowOnState(currentState)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_applyShowOnState(state) {
|
|
158
|
+
if (!this._showOnState) return
|
|
159
|
+
|
|
160
|
+
const states = this._parseShowOnState(this._showOnState)
|
|
161
|
+
const shouldShow = states.includes(state.toLowerCase())
|
|
162
|
+
|
|
163
|
+
if (shouldShow) {
|
|
164
|
+
if (this._originalDisplay !== undefined) {
|
|
165
|
+
this.dom.style.display = this._originalDisplay
|
|
166
|
+
} else {
|
|
167
|
+
this.dom.style.display = ''
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
if (this._originalDisplay === undefined) {
|
|
171
|
+
const currentDisplay = this.dom.style.display
|
|
172
|
+
if (currentDisplay && currentDisplay !== 'none') {
|
|
173
|
+
this._originalDisplay = currentDisplay
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
this.dom.style.display = 'none'
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_parseShowOnState(value) {
|
|
181
|
+
if (Array.isArray(value)) {
|
|
182
|
+
return value.map((s) => String(s).toLowerCase())
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (typeof value === 'string') {
|
|
186
|
+
try {
|
|
187
|
+
const parsed = JSON.parse(value)
|
|
188
|
+
if (Array.isArray(parsed)) {
|
|
189
|
+
return parsed.map((s) => String(s).toLowerCase())
|
|
190
|
+
}
|
|
191
|
+
} catch (e) {}
|
|
192
|
+
return [value.toLowerCase()]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return []
|
|
196
|
+
}
|
|
197
|
+
|
|
165
198
|
setVisible(visible) {
|
|
166
199
|
this._setVisible(visible)
|
|
167
200
|
}
|
|
168
201
|
|
|
169
|
-
/**
|
|
170
|
-
* Public method to set visibility via enum
|
|
171
|
-
* @param {QTVisibility} visibility - 'visible' | 'invisible' | 'gone'
|
|
172
|
-
*/
|
|
173
202
|
setVisibility(visibility) {
|
|
174
203
|
this._setVisibility(visibility)
|
|
175
204
|
}
|
|
205
|
+
|
|
206
|
+
setShowOnState(value) {
|
|
207
|
+
this._setShowOnState(value)
|
|
208
|
+
}
|
|
176
209
|
}
|