@ledvance/base 1.1.13 → 1.1.15

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 (65) hide show
  1. package/.prettierrc.js +0 -0
  2. package/package.json +1 -1
  3. package/src/api/native.d.ts +5 -0
  4. package/src/api/native.ts +193 -160
  5. package/src/api/nativeEventEmitter.ts +54 -54
  6. package/src/components/Card.tsx +25 -25
  7. package/src/components/Cell.tsx +32 -32
  8. package/src/components/ColorAdjustView.tsx +44 -44
  9. package/src/components/ColorTempAdjustView.tsx +37 -37
  10. package/src/components/ColorsLine.d.ts +7 -0
  11. package/src/components/ColorsLine.tsx +48 -0
  12. package/src/components/DeleteButton.d.ts +1 -1
  13. package/src/components/DeleteButton.tsx +27 -27
  14. package/src/components/Dialog.tsx +28 -28
  15. package/src/components/FanAdjustView.tsx +115 -105
  16. package/src/components/InfoText.tsx +29 -29
  17. package/src/components/LampAdjustView.tsx +52 -52
  18. package/src/components/LinearGradientLine.tsx +53 -53
  19. package/src/components/MoodColorsLine.d.ts +9 -0
  20. package/src/components/MoodColorsLine.tsx +38 -0
  21. package/src/components/Page.tsx +34 -34
  22. package/src/components/Popup.tsx +17 -17
  23. package/src/components/Segmented.d.ts +2 -2
  24. package/src/components/Segmented.tsx +66 -65
  25. package/src/components/Spacer.tsx +5 -5
  26. package/src/components/Tag.tsx +42 -42
  27. package/src/components/TextButton.d.ts +1 -1
  28. package/src/components/TextButton.tsx +23 -23
  29. package/src/components/TextField.tsx +58 -58
  30. package/src/components/connect.tsx +10 -10
  31. package/src/components/ldvColorBrightness.tsx +12 -12
  32. package/src/components/ldvColorSlider.tsx +109 -109
  33. package/src/components/ldvPickerView.tsx +70 -70
  34. package/src/components/ldvPresetView.tsx +68 -68
  35. package/src/components/ldvSaturation.tsx +14 -14
  36. package/src/components/ldvSlider.d.ts +3 -3
  37. package/src/components/ldvSlider.tsx +93 -93
  38. package/src/components/ldvSwitch.tsx +35 -35
  39. package/src/components/ldvTemperatureSlider.tsx +120 -120
  40. package/src/components/ldvTopBar.tsx +50 -50
  41. package/src/components/ldvTopName.tsx +44 -44
  42. package/src/components/segmentControl.tsx +59 -59
  43. package/src/components/weekSelect.tsx +76 -76
  44. package/src/composeLayout.tsx +165 -165
  45. package/src/i18n/index.ts +12 -12
  46. package/src/i18n/strings.ts +11004 -11004
  47. package/src/main.tsx +4 -4
  48. package/src/models/GlobalParams.ts +7 -7
  49. package/src/models/TuyaApi.d.ts +3 -3
  50. package/src/models/TuyaApi.ts +61 -61
  51. package/src/models/combine.ts +7 -7
  52. package/src/models/configureStore.ts +14 -14
  53. package/src/models/index.ts +4 -4
  54. package/src/models/modules/NativePropsSlice.tsx +170 -169
  55. package/src/models/modules/Result.ts +8 -8
  56. package/src/models/modules/common.ts +90 -90
  57. package/src/res/index.ts +35 -35
  58. package/src/utils/ColorParser.ts +150 -150
  59. package/src/utils/ColorUtils.tsx +414 -414
  60. package/src/utils/Support.d.ts +9 -0
  61. package/src/utils/Support.ts +85 -0
  62. package/src/utils/cctUtils.d.ts +1 -0
  63. package/src/utils/cctUtils.ts +111 -0
  64. package/src/utils/common.ts +186 -174
  65. package/src/utils/index.ts +123 -123
@@ -6,41 +6,41 @@ import {actions, store} from './models'
6
6
  import {addListener, removeListener} from 'api/nativeEventEmitter'
7
7
  import {NativeApi} from 'api/native'
8
8
  import {
9
- DeviceInfo,
10
- NativeProps,
11
- setGroupNativeProps,
12
- setNativeProps,
13
- UAGroupInfo,
9
+ DeviceInfo,
10
+ NativeProps,
11
+ setGroupNativeProps,
12
+ setNativeProps,
13
+ UAGroupInfo,
14
14
  } from './models/modules/NativePropsSlice'
15
15
  import {DpSchema, GlobalParams} from './models/GlobalParams'
16
16
  import Connect from './components/connect'
17
17
 
18
18
  interface Props {
19
- devInfo: DevInfo
20
- preload?: boolean
21
- ldvDevInfo: LdvDevInfo
22
- uaGroupInfo: UAGroupInfoProps
19
+ devInfo: DevInfo
20
+ preload?: boolean
21
+ ldvDevInfo: LdvDevInfo
22
+ uaGroupInfo: UAGroupInfoProps
23
23
  }
24
24
 
25
25
  interface LdvDevInfo extends DeviceInfo {
26
- schema: any
27
- familyName: string
26
+ schema: any
27
+ familyName: string
28
28
  }
29
29
 
30
30
  interface UAGroupInfoProps extends UAGroupInfo {
31
- schema: any
32
- familyName: string
31
+ schema: any
32
+ familyName: string
33
33
  }
34
34
 
35
35
  const TYEvent = TYSdk.event
36
36
  const TYDevice = TYSdk.device
37
37
 
38
38
  const theme = {
39
- global: {
40
- background: '#fff',
41
- },
42
- ldvMainBgColor: '#f60',
43
- 'slider.trackRadius': 15,
39
+ global: {
40
+ background: '#fff',
41
+ },
42
+ ldvMainBgColor: '#f60',
43
+ 'slider.trackRadius': 15,
44
44
  }
45
45
 
46
46
  /**
@@ -48,160 +48,160 @@ const theme = {
48
48
  * @param {} component - 需要连接到redux store的组件,通常为即为main
49
49
  */
50
50
  const composeLayout = (component: React.ComponentType) => {
51
- const NavigatorLayout = component
52
- const {dispatch} = store
51
+ const NavigatorLayout = component
52
+ const {dispatch} = store
53
+
54
+ addListener(store)
55
+
56
+ /**
57
+ * 此处监听了`设备数据变更`事件,
58
+ * 每当dp点数据变更时,会将变更的dp点状态同步更新到`redux`中去。
59
+ * 同理当设备信息变更时,也会将变更的设备信息值同步更新到`redux`中去。
60
+ */
61
+ TYEvent.on('deviceDataChange', data => {
62
+ switch (data.type) {
63
+ case 'dpData':
64
+ dispatch(actions.common.responseUpdateDp(data.payload as Record<string, DpValue>))
65
+ break
66
+ case 'deviceOnline':
67
+ console.log('设备在线状态', data.payload)
68
+ break
69
+ default:
70
+ dispatch(actions.common.deviceChange(data.payload as DevInfo))
71
+ break
72
+ }
73
+ })
53
74
 
54
- addListener(store)
75
+ /**
76
+ * 此处监听了`网络状态变更事件`事件,
77
+ * 每当设备信息变更时,会将变更的设备信息值同步更新到`redux`中去。
78
+ */
79
+ TYSdk.event.on('networkStateChange', data => {
80
+ dispatch(actions.common.deviceChange(data as any))
81
+ })
55
82
 
83
+ class PanelComponent extends Component<Props> {
56
84
  /**
57
- * 此处监听了`设备数据变更`事件,
58
- * 每当dp点数据变更时,会将变更的dp点状态同步更新到`redux`中去。
59
- * 同理当设备信息变更时,也会将变更的设备信息值同步更新到`redux`中去。
85
+ * 如果面板进入时,`devInfo`已经存在(通常都会存在的)
86
+ * 这里会调用 setDeviceInfo 将原始的devInfo处理一下,并置入`redux`
87
+ *
88
+ * 如果面板进入时,`devInfo`不存在,
89
+ * 那么会调用 getDeviceInfo 异步获取处理好的`devInfo`,并置入`redux`
60
90
  */
61
- TYEvent.on('deviceDataChange', data => {
62
- switch (data.type) {
63
- case 'dpData':
64
- dispatch(actions.common.responseUpdateDp(data.payload as Record<string, DpValue>))
65
- break
66
- case 'deviceOnline':
67
- console.log('设备在线状态', data.payload)
68
- break
69
- default:
70
- dispatch(actions.common.deviceChange(data.payload as DevInfo))
71
- break
72
- }
73
- })
91
+ constructor(props: Props) {
92
+ super(props)
93
+ if (props && props.devInfo && props.devInfo.devId) {
94
+ TYDevice.setDeviceInfo(props.devInfo)
95
+ TYDevice.getDeviceInfo()
96
+ .then(data => {
97
+ dispatch(actions.common.devInfoChange(data))
98
+ return Promise.all([TYDevice.getDeviceState(), data])
99
+ })
100
+ .then(([dpState, devInfo]) => {
101
+ const isEqual = _.isEqual(dpState, devInfo.state)
102
+ if (isEqual) return
103
+ dispatch(actions.common.responseUpdateDp(dpState))
104
+ })
105
+ } else if (props.preload) {
106
+ // do something
107
+ } else {
108
+ TYDevice.getDeviceInfo().then(data => dispatch(actions.common.devInfoChange(data)))
109
+ }
110
+
111
+ if (!!props.ldvDevInfo) {
112
+ this.initReduxDeviceNativeProps(props.ldvDevInfo)
113
+ } else {
114
+ this.initReduxGroupNativeProps(props.uaGroupInfo)
115
+ }
116
+ }
74
117
 
75
- /**
76
- * 此处监听了`网络状态变更事件`事件,
77
- * 每当设备信息变更时,会将变更的设备信息值同步更新到`redux`中去。
78
- */
79
- TYSdk.event.on('networkStateChange', data => {
80
- dispatch(actions.common.deviceChange(data as any))
81
- })
82
-
83
- class PanelComponent extends Component<Props> {
84
- /**
85
- * 如果面板进入时,`devInfo`已经存在(通常都会存在的)
86
- * 这里会调用 setDeviceInfo 将原始的devInfo处理一下,并置入`redux`
87
- *
88
- * 如果面板进入时,`devInfo`不存在,
89
- * 那么会调用 getDeviceInfo 异步获取处理好的`devInfo`,并置入`redux`
90
- */
91
- constructor(props: Props) {
92
- super(props)
93
- if (props && props.devInfo && props.devInfo.devId) {
94
- TYDevice.setDeviceInfo(props.devInfo)
95
- TYDevice.getDeviceInfo()
96
- .then(data => {
97
- dispatch(actions.common.devInfoChange(data))
98
- return Promise.all([TYDevice.getDeviceState(), data])
99
- })
100
- .then(([dpState, devInfo]) => {
101
- const isEqual = _.isEqual(dpState, devInfo.state)
102
- if (isEqual) return
103
- dispatch(actions.common.responseUpdateDp(dpState))
104
- })
105
- } else if (props.preload) {
106
- // do something
107
- } else {
108
- TYDevice.getDeviceInfo().then(data => dispatch(actions.common.devInfoChange(data)))
109
- }
110
-
111
- if (!!props.ldvDevInfo) {
112
- this.initReduxDeviceNativeProps(props.ldvDevInfo)
113
- } else {
114
- this.initReduxGroupNativeProps(props.uaGroupInfo)
115
- }
116
- }
117
-
118
- initReduxDeviceNativeProps(ldvDevInfo: LdvDevInfo) {
119
- console.log('原生数据:', JSON.stringify(ldvDevInfo))
120
- NativeApi.log('原生数据: ' + JSON.stringify(ldvDevInfo))
121
- const dps = this.setDpSchemaMap(ldvDevInfo.schema)
122
- const nativeProps: NativeProps = {
123
- deviceInfo: {
124
- devId: ldvDevInfo.devId,
125
- dps: {...dps, ...JSON.parse(ldvDevInfo.dps)},
126
- pId: ldvDevInfo.pId,
127
- },
128
- uaGroupInfo: {
129
- tyGroupId: -1,
130
- dps: {},
131
- pId: '',
132
- config: {},
133
- },
134
- familyName: ldvDevInfo.familyName,
135
- }
136
- NativeApi.showObj(nativeProps)
137
- console.log('Redux 初始数据:', JSON.stringify(nativeProps))
138
- NativeApi.log('Redux 初始数据:' + JSON.stringify(nativeProps))
139
- dispatch(setNativeProps(nativeProps))
140
- }
141
-
142
- initReduxGroupNativeProps(uaGroupInfo: UAGroupInfoProps) {
143
- console.log('原生数据:', JSON.stringify(uaGroupInfo))
144
- NativeApi.log('原生数据: ' + JSON.stringify(uaGroupInfo))
145
- const dps = this.setDpSchemaMap(uaGroupInfo.schema)
146
- const nativeProps: NativeProps = {
147
- deviceInfo: {
148
- devId: '',
149
- dps: {},
150
- pId: '',
151
- },
152
- uaGroupInfo: {
153
- tyGroupId: uaGroupInfo.tyGroupId,
154
- dps: {...dps, ...JSON.parse(uaGroupInfo.dps)},
155
- pId: uaGroupInfo.pId,
156
- config: JSON.parse(uaGroupInfo.config || '{}'),
157
- },
158
- familyName: uaGroupInfo.familyName,
159
- }
160
- NativeApi.showObj(nativeProps)
161
- console.log('Redux 初始数据:', JSON.stringify(nativeProps))
162
- NativeApi.log('Redux 初始数据:' + JSON.stringify(nativeProps))
163
- dispatch(setGroupNativeProps(nativeProps))
164
- }
165
-
166
- setDpSchemaMap(schema: string): any {
167
- // 处理物模型协议和dps
168
- const dpSchemaMap: Record<string, DpSchema> = {}
169
- const dps = {}
170
- JSON.parse(schema || '[]')
171
- .forEach(schemaItem => {
172
- dpSchemaMap[schemaItem.code] = {
173
- name: schemaItem.name,
174
- dp: schemaItem.id,
175
- type: schemaItem.type,
176
- mode: schemaItem.mode,
177
- property: schemaItem.property,
178
- }
179
- dps[schemaItem.id] = null
180
- })
181
- GlobalParams.dpSchemaMap = dpSchemaMap
182
- return dps
183
- }
184
-
185
- render() {
186
- return (
187
- <Provider store={store}>
188
- <Theme theme={theme}>
189
- <Connect mapStateToProps={_.identity}>
190
- {({mapStateToProps, ...props}: { mapStateToProps: any; [_: string]: any }) => {
191
- return <NavigatorLayout {...props} />
192
- }}
193
- </Connect>
194
- </Theme>
195
- </Provider>
196
- )
197
- }
198
-
199
- componentWillUnmount() {
200
- removeListener()
201
- }
118
+ initReduxDeviceNativeProps(ldvDevInfo: LdvDevInfo) {
119
+ console.log('原生数据:', JSON.stringify(ldvDevInfo))
120
+ NativeApi.log('原生数据: ' + JSON.stringify(ldvDevInfo))
121
+ const dps = this.setDpSchemaMap(ldvDevInfo.schema)
122
+ const nativeProps: NativeProps = {
123
+ deviceInfo: {
124
+ devId: ldvDevInfo.devId,
125
+ dps: {...dps, ...JSON.parse(ldvDevInfo.dps)},
126
+ pId: ldvDevInfo.pId,
127
+ },
128
+ uaGroupInfo: {
129
+ tyGroupId: -1,
130
+ dps: {},
131
+ pId: '',
132
+ config: {},
133
+ },
134
+ familyName: ldvDevInfo.familyName,
135
+ }
136
+ NativeApi.showObj(nativeProps)
137
+ console.log('Redux 初始数据:', JSON.stringify(nativeProps))
138
+ NativeApi.log('Redux 初始数据:' + JSON.stringify(nativeProps))
139
+ dispatch(setNativeProps(nativeProps))
140
+ }
141
+
142
+ initReduxGroupNativeProps(uaGroupInfo: UAGroupInfoProps) {
143
+ console.log('原生数据:', JSON.stringify(uaGroupInfo))
144
+ NativeApi.log('原生数据: ' + JSON.stringify(uaGroupInfo))
145
+ const dps = this.setDpSchemaMap(uaGroupInfo.schema)
146
+ const nativeProps: NativeProps = {
147
+ deviceInfo: {
148
+ devId: '',
149
+ dps: {},
150
+ pId: '',
151
+ },
152
+ uaGroupInfo: {
153
+ tyGroupId: uaGroupInfo.tyGroupId,
154
+ dps: {...dps, ...JSON.parse(uaGroupInfo.dps)},
155
+ pId: uaGroupInfo.pId,
156
+ config: JSON.parse(uaGroupInfo.config || '{}'),
157
+ },
158
+ familyName: uaGroupInfo.familyName,
159
+ }
160
+ NativeApi.showObj(nativeProps)
161
+ console.log('Redux 初始数据:', JSON.stringify(nativeProps))
162
+ NativeApi.log('Redux 初始数据:' + JSON.stringify(nativeProps))
163
+ dispatch(setGroupNativeProps(nativeProps))
164
+ }
165
+
166
+ setDpSchemaMap(schema: string): any {
167
+ // 处理物模型协议和dps
168
+ const dpSchemaMap: Record<string, DpSchema> = {}
169
+ const dps = {}
170
+ JSON.parse(schema || '[]')
171
+ .forEach((schemaItem: any) => {
172
+ dpSchemaMap[schemaItem.code] = {
173
+ name: schemaItem.name,
174
+ dp: schemaItem.id,
175
+ type: schemaItem.type,
176
+ mode: schemaItem.mode,
177
+ property: schemaItem.property,
178
+ }
179
+ dps[schemaItem.id] = null
180
+ })
181
+ GlobalParams.dpSchemaMap = dpSchemaMap
182
+ return dps
183
+ }
184
+
185
+ render() {
186
+ return (
187
+ <Provider store={store}>
188
+ <Theme theme={theme}>
189
+ <Connect mapStateToProps={_.identity}>
190
+ {({mapStateToProps, ...props}: { mapStateToProps: any; [_: string]: any }) => {
191
+ return <NavigatorLayout {...props} />
192
+ }}
193
+ </Connect>
194
+ </Theme>
195
+ </Provider>
196
+ )
197
+ }
198
+
199
+ componentWillUnmount() {
200
+ removeListener()
202
201
  }
202
+ }
203
203
 
204
- return PanelComponent
204
+ return PanelComponent
205
205
  }
206
206
 
207
207
 
package/src/i18n/index.ts CHANGED
@@ -4,33 +4,33 @@ import Strings from './strings'
4
4
  type Key = keyof typeof Strings.en
5
5
 
6
6
  function getLang(key: Key, defaultString?: string): string {
7
- // @ts-ignore
8
- return new I18N(Strings).getLang(key, defaultString)
7
+ // @ts-ignore
8
+ return new I18N(Strings).getLang(key, defaultString)
9
9
  }
10
10
 
11
11
  function getDpLang(code: string, value?: DpValue): string {
12
- return new I18N(Strings).getDpLang(code, value)
12
+ return new I18N(Strings).getDpLang(code, value)
13
13
  }
14
14
 
15
15
  function formatString(key: string, values: string[]): string {
16
- return new I18N(Strings).formatString(key, ...values)
16
+ return new I18N(Strings).formatString(key, ...values)
17
17
  }
18
18
 
19
19
  function formatValue(key: Key, ...values: string[]): string {
20
- // @ts-ignore
21
- return new I18N(Strings).formatValue(key, ...values)
20
+ // @ts-ignore
21
+ return new I18N(Strings).formatValue(key, ...values)
22
22
  }
23
23
 
24
24
  function getDpName(code: string, defaultName?: string): string {
25
- return new I18N(Strings).getDpName(code, defaultName)
25
+ return new I18N(Strings).getDpName(code, defaultName)
26
26
  }
27
27
 
28
28
  const I18n = {
29
- getLang,
30
- getDpLang,
31
- formatString,
32
- formatValue,
33
- getDpName,
29
+ getLang,
30
+ getDpLang,
31
+ formatString,
32
+ formatValue,
33
+ getDpName,
34
34
  }
35
35
 
36
36
  export default I18n