@opentiny/next-sdk 0.2.9 → 0.2.10

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/next-sdk",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "homepage": "https://docs.opentiny.design/next-sdk/guide/",
6
6
  "repository": {
@@ -146,30 +146,33 @@ class FloatingBlock {
146
146
 
147
147
  /**
148
148
  * 合并菜单项配置。
149
- * - sessionId:使用默认菜单 + 用户配置(可定制每一项的 show/text/icon 等)
150
- * - sessionId:不渲染任何下拉菜单,仅保留点击浮标打开对话框的能力
149
+ * - 用户明确传入 menuItems:直接使用用户配置,不受 sessionId 限制;未传 icon 时自动补充默认图标
150
+ * - sessionId 且未传 menuItems:使用默认菜单
151
+ * - 无 sessionId 且未传 menuItems:不渲染任何下拉菜单,仅保留点击浮标打开对话框的能力
151
152
  */
152
153
  private mergeMenuItems(userMenuItems?: MenuItemConfig[]): MenuItemConfig[] {
153
- // sessionId:完全关闭下拉菜单(包括 ai-chat 项),只保留点击浮标触发 onShowAIChat
154
- if (!this.options.sessionId) {
155
- return []
154
+ // action 对应的默认图标映射
155
+ const defaultIcons: Partial<Record<ActionType, string>> = {
156
+ 'qr-code': qrCode,
157
+ 'ai-chat': chat,
158
+ 'remote-url': link,
159
+ 'remote-control': scan
156
160
  }
157
161
 
158
- if (!userMenuItems) {
159
- return getDefaultMenuItems(this.options)
162
+ // 用户明确传入了 menuItems,直接使用,并补充缺失的图标
163
+ if (userMenuItems) {
164
+ return userMenuItems.map((item) => ({
165
+ ...item,
166
+ icon: item.icon ?? defaultIcons[item.action]
167
+ }))
160
168
  }
161
169
 
162
- return getDefaultMenuItems(this.options).map((defaultItem) => {
163
- const userItem = userMenuItems.find((item) => item.action === defaultItem.action)
164
- if (userItem) {
165
- return {
166
- ...defaultItem,
167
- ...userItem,
168
- show: userItem.show !== undefined ? userItem.show : defaultItem.show
169
- }
170
- }
171
- return defaultItem
172
- })
170
+ // sessionId 且无用户菜单:完全关闭下拉菜单,只保留点击浮标触发 onShowAIChat
171
+ if (!this.options.sessionId) {
172
+ return []
173
+ }
174
+
175
+ return getDefaultMenuItems(this.options)
173
176
  }
174
177
 
175
178
  private init(): void {
@@ -220,7 +223,7 @@ class FloatingBlock {
220
223
  <div class="tiny-remoter-dropdown-item__content">
221
224
  <div title="${item.tip}">${item.text}</div>
222
225
  <div class="tiny-remoter-dropdown-item__desc-wrapper">
223
- <div class="tiny-remoter-dropdown-item__desc ${item.active ? 'tiny-remoter-dropdown-item__desc--active' : ''} ${item.know ? 'tiny-remoter-dropdown-item__desc--know' : ''}">${item.desc}</div>
226
+ <div class="tiny-remoter-dropdown-item__desc ${item.active ? 'tiny-remoter-dropdown-item__desc--active' : ''} ${item.know ? 'tiny-remoter-dropdown-item__desc--know' : ''}">${item.desc ?? ''}</div>
224
227
  <div>
225
228
  ${
226
229
  item.showCopyIcon
@@ -357,13 +360,31 @@ class FloatingBlock {
357
360
  }
358
361
 
359
362
  private copyRemoteControl(): void {
360
- if (!this.options.sessionId) return
361
- this.copyToClipboard(this.options.sessionId.slice(-6))
363
+ // 优先使用用户菜单项中的 desc/text(支持自定义识别码),回退到 sessionId 末 6 位
364
+ const menuItem = this.menuItems.find((item) => item.action === 'remote-control')
365
+ const codeToCopy =
366
+ menuItem?.desc || menuItem?.text || (this.options.sessionId ? this.options.sessionId.slice(-6) : '')
367
+ if (codeToCopy) {
368
+ this.copyToClipboard(codeToCopy)
369
+ }
362
370
  }
363
371
 
364
372
  private copyRemoteURL(): void {
365
- if (!this.options.sessionId) return
366
- this.copyToClipboard(this.options.remoteUrl + this.sessionPrefix + this.options.sessionId)
373
+ const menuItem = this.menuItems.find((item) => item.action === 'remote-url')
374
+
375
+ // 构造带 sessionId 的完整遥控链接(默认行为)
376
+ const sessionUrl = this.options.sessionId
377
+ ? this.options.remoteUrl + this.sessionPrefix + this.options.sessionId
378
+ : ''
379
+
380
+ // 仅当 desc 是用户真正自定义的值(不同于裸 remoteUrl)时才优先使用,
381
+ // 否则回退到带 sessionId 的完整链接,避免默认菜单场景复制裸域名
382
+ const customDesc = menuItem?.desc && menuItem.desc !== this.options.remoteUrl ? menuItem.desc : undefined
383
+ const urlToCopy = customDesc || sessionUrl || menuItem?.text || ''
384
+
385
+ if (urlToCopy) {
386
+ this.copyToClipboard(urlToCopy)
387
+ }
367
388
  }
368
389
 
369
390
  // 实现复制到剪贴板功能