dsh-cad-studio 0.2.1 → 0.2.3

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 (2) hide show
  1. package/client.js +115 -18
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -100,7 +100,13 @@ window.__ModuleLoader__.load({
100
100
  background: 'transparent', color: skin.color, fontSize: 12, lineHeight: 1,
101
101
  cursor: 'pointer',
102
102
  }),
103
- tabs: { display: 'flex', alignItems: 'center', gap: 3, flex: '1 1 auto', minWidth: 0, overflow: 'hidden', '--cad-tab-basis': 'calc((100% - 50px - 26px - 18px) / 5)' },
103
+ tabs: { position: 'relative', display: 'flex', alignItems: 'center', gap: 3, flex: '1 1 auto', minWidth: 0, overflow: 'visible', '--cad-tab-basis': 'calc((100% - 50px - 26px - 18px) / 5)' },
104
+ // Anchor the "+" menu to the strip's right edge: because "+" is the
105
+ // last thing in the row, this keeps the menu hanging off that button
106
+ // as tabs open and close.
107
+ addMenu: { position: 'absolute', top: 'calc(100% + 4px)', zIndex: 40, width: 224, maxHeight: 300, overflowY: 'auto', display: 'flex', flexDirection: 'column', padding: 3, borderRadius: 8, border: '1px solid', boxShadow: '0 10px 26px rgba(0,0,0,.32)' },
108
+ addRow: (active) => ({ display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0, padding: '5px 7px', borderRadius: 6, border: 'none', background: active ? 'rgba(77,107,254,.16)' : 'transparent', textAlign: 'left', cursor: 'pointer', font: 'inherit' }),
109
+ addHint: { padding: '6px 8px', fontSize: 10.5, opacity: 0.6 },
104
110
  // A model tab is laid out at the width it would have with five tabs open
105
111
  // (--cad-tab-basis on the strip), so adding the first one does not stretch
106
112
  // it across the whole strip and the row never reflows as tabs come and go.
@@ -1191,6 +1197,14 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1191
1197
  const activityRef = useRef(null)
1192
1198
  const [fresh, setFresh] = useState(false)
1193
1199
  const seenRef = useRef('')
1200
+ // "+" owns its own dropdown (it is anchored to the button); the rail's
1201
+ // folder opens the models panel, where a click switches the model shown
1202
+ // by the current view instead of opening another tab.
1203
+ const [addOpen, setAddOpen] = useState(false)
1204
+ const [addAlign, setAddAlign] = useState('left')
1205
+ const addBtnRef = useRef(null)
1206
+ const [activityPin, setActivityPin] = useState(null)
1207
+ const activityPinRef = useRef(null)
1194
1208
  const [picked, setPicked] = useState('')
1195
1209
  const revealedRef = useRef('')
1196
1210
  const [payload, setPayload] = useState(null)
@@ -1296,6 +1310,35 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1296
1310
  showScene(scene, { tabKey })
1297
1311
  }
1298
1312
 
1313
+ /**
1314
+ * The folder's click: change what the current view shows, in place.
1315
+ * A focused model tab is retargeted to the picked model (same tab, no
1316
+ * new one); on the live tab the pick is pinned there until the session
1317
+ * publishes something new, at which point the live view takes over
1318
+ * again.
1319
+ */
1320
+ const switchModel = async (id) => {
1321
+ if (!id) return
1322
+ const scene = await loadScene(id)
1323
+ if (!scene) return
1324
+ const meta = scenes.find((sc) => sc.id === id) || { id, title: scene.title || id }
1325
+ const title = shortName(meta) || id
1326
+ rememberView(activeRef.current, payloadRef.current)
1327
+ const tab = openTabsRef.current.find((t) => t.key === activeRef.current)
1328
+ if (tab) {
1329
+ const next = openTabsRef.current.map((t) => (t.key === tab.key ? { ...t, id, title } : t))
1330
+ openTabsRef.current = next
1331
+ setOpenTabs(next)
1332
+ showScene(scene, { tabKey: tab.key })
1333
+ return
1334
+ }
1335
+ const pin = { id, title }
1336
+ activityPinRef.current = pin
1337
+ setActivityPin(pin)
1338
+ setFresh(false)
1339
+ showScene(scene, { tabKey: 'activity' })
1340
+ }
1341
+
1299
1342
  const focusTab = async (key) => {
1300
1343
  if (key === activeRef.current) return
1301
1344
  rememberView(activeRef.current, payloadRef.current)
@@ -1352,6 +1395,25 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1352
1395
  }
1353
1396
  }, [payload])
1354
1397
 
1398
+ // The "+" dropdown is a transient popover: Esc or a click anywhere else
1399
+ // dismisses it (the folder panel behind it is the one that stays put).
1400
+ useEffect(() => {
1401
+ if (!addOpen) return undefined
1402
+ const onDown = (event) => {
1403
+ const el = event.target
1404
+ if (!el || typeof el.closest !== 'function') return
1405
+ if (el.closest('[data-cad-addmenu]') || el.closest('[data-cad-tab-add]')) return
1406
+ setAddOpen(false)
1407
+ }
1408
+ const onKey = (event) => { if (event.key === 'Escape') setAddOpen(false) }
1409
+ document.addEventListener('mousedown', onDown, true)
1410
+ document.addEventListener('keydown', onKey, true)
1411
+ return () => {
1412
+ document.removeEventListener('mousedown', onDown, true)
1413
+ document.removeEventListener('keydown', onKey, true)
1414
+ }
1415
+ }, [addOpen])
1416
+
1355
1417
  useEffect(() => {
1356
1418
  let alive = true
1357
1419
  const tick = async () => {
@@ -1390,6 +1452,12 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
1390
1452
  // pair so driving a joint refreshes the viewport instead of being
1391
1453
  // mistaken for "nothing changed".
1392
1454
  const stamp = `${actId}@${(act && act.at) || ''}`
1455
+ // Something new was published by this session: the pinned model on
1456
+ // the live tab goes back to following the session.
1457
+ if (activityPinRef.current && activityPinRef.current.id !== actId) {
1458
+ activityPinRef.current = null
1459
+ setActivityPin(null)
1460
+ }
1393
1461
  if (stamp !== seenRef.current) {
1394
1462
  const had = Boolean(seenRef.current)
1395
1463
  seenRef.current = stamp
@@ -2152,8 +2220,8 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2152
2220
  type: 'button',
2153
2221
  'data-cad-scene': sc.id,
2154
2222
  style: styles.modelRow(sc.id === activeModel),
2155
- title: `${shortName(sc)}(${sc.instances || 0} 实例 · ${sc.parts || 0} 零件)`,
2156
- onClick: () => { openModel(sc.id) },
2223
+ title: `切换到 ${shortName(sc)}(替换当前视图里的模型,不新开页签)`,
2224
+ onClick: () => { switchModel(sc.id) },
2157
2225
  }, [
2158
2226
  h('span', { key: 'n', style: { ...styles.modelName, fontWeight: sc.id === activeModel ? 600 : 400 } }, shortName(sc)),
2159
2227
  h('span', { key: 'm', style: styles.modelMeta }, `${(sc.at ? new Date(sc.at).toLocaleTimeString('zh-CN', { hour12: false }) : '')} · ${sc.instances || 0} 实例 · ${sc.parts || 0} 零件`),
@@ -2228,20 +2296,49 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2228
2296
  }, '×')
2229
2297
  : null,
2230
2298
  ])),
2231
- // "+" adds a tab (it opens the model list; every pick becomes its
2232
- // own tab). Hidden once the cap is reached — there is nothing left
2233
- // to add until a tab is closed.
2234
- openTabs.length < MAX_TABS
2235
- ? h('button', {
2236
- key: 'add',
2237
- type: 'button',
2238
- 'data-cad-tab-add': '1',
2239
- 'aria-label': '新增模型页签',
2240
- style: { ...styles.barBtn(panelSkin), marginLeft: 2 },
2241
- title: `新开一个模型页签(每次选一个模型就加一个,最多 ${MAX_TABS} 个)`,
2242
- onClick: () => setPanel((p) => (p === 'models' ? '' : 'models')),
2243
- }, '+')
2244
- : null,
2299
+ // "+" is its own control with its own dropdown, anchored to the
2300
+ // button: the rail's folder switches the current model in place and
2301
+ // stays open, "+" always makes a new tab and closes itself.
2302
+ h('span', { key: 'addwrap', style: { position: 'relative', display: 'inline-flex', flex: '0 0 auto' } }, [
2303
+ openTabs.length < MAX_TABS
2304
+ ? h('button', {
2305
+ key: 'add',
2306
+ type: 'button',
2307
+ 'data-cad-tab-add': '1',
2308
+ 'aria-label': '新增模型页签',
2309
+ 'aria-expanded': addOpen ? 'true' : 'false',
2310
+ style: { ...styles.barBtn(panelSkin), marginLeft: 2 },
2311
+ title: `新开一个模型页签(每次选一个模型就加一个,最多 ${MAX_TABS} 个)`,
2312
+ ref: addBtnRef,
2313
+ onClick: () => {
2314
+ // Open toward whichever side has room, so the menu never
2315
+ // lands under the page content beside the pane.
2316
+ const rect = addBtnRef.current ? addBtnRef.current.getBoundingClientRect() : null
2317
+ setAddAlign(rect && rect.right + 232 > window.innerWidth ? 'right' : 'left')
2318
+ setAddOpen((open) => !open)
2319
+ },
2320
+ }, '+')
2321
+ : null,
2322
+ addOpen
2323
+ ? h('div', {
2324
+ key: 'addmenu',
2325
+ 'data-cad-addmenu': '1',
2326
+ style: { ...styles.addMenu, ...(addAlign === 'right' ? { right: 0, left: 'auto' } : { left: 0, right: 'auto' }), background: panelSkin.background, borderColor: panelSkin.borderColor, color: panelSkin.color },
2327
+ }, scenes.length
2328
+ ? scenes.map((sc) => h('button', {
2329
+ key: sc.id,
2330
+ type: 'button',
2331
+ 'data-cad-add-scene': sc.id,
2332
+ style: styles.addRow(sc.id === activeModel),
2333
+ title: `${shortName(sc)}(${sc.instances || 0} 实例 · ${sc.parts || 0} 零件)`,
2334
+ onClick: () => { setAddOpen(false); openModel(sc.id) },
2335
+ }, [
2336
+ h('span', { key: 'n', style: { ...styles.modelName, fontWeight: sc.id === activeModel ? 600 : 400 } }, shortName(sc)),
2337
+ h('span', { key: 'm', style: styles.modelMeta }, `${sc.instances || 0} 实例 · ${sc.parts || 0} 零件`),
2338
+ ]))
2339
+ : h('div', { key: 'none', style: styles.addHint }, '还没有别的模型'))
2340
+ : null,
2341
+ ]),
2245
2342
  ]),
2246
2343
  ]),
2247
2344
  error ? h('div', { key: 'err', style: styles.warn }, error) : null,
@@ -2258,7 +2355,7 @@ const FILE_EXTS = ['step', 'stp', 'iges', 'igs', 'brep', 'stl']
2258
2355
  'data-cad-rail': item.id,
2259
2356
  'aria-pressed': panel === item.id ? 'true' : 'false',
2260
2357
  title: item.label,
2261
- onClick: () => setPanel((p) => (p === item.id ? '' : item.id)),
2358
+ onClick: () => { setAddOpen(false); setPanel((p) => (p === item.id ? '' : item.id)) },
2262
2359
  }, h(RailIcon, { name: item.id })))),
2263
2360
  h('div', { key: 'main', style: { flex: '1 1 auto', minWidth: 0, position: 'relative', display: 'flex', flexDirection: 'column' } }, [
2264
2361
  payload
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {