mcard-studio 0.0.1 → 0.0.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 (212) hide show
  1. package/README.md +3 -0
  2. package/astro.config.mjs +46 -2
  3. package/bin/mcard-studio.mjs +1 -1
  4. package/cli/lib/runtimeContext.mjs +6 -3
  5. package/dist/client/_astro/{ChartAnalyticsViewlet.Cevj0EOs.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
  6. package/dist/client/_astro/ClmPcardViewlet.cvKsR2ng.js +3 -0
  7. package/dist/client/_astro/D3GraphViewlet.8YEIrCGL.js +2 -0
  8. package/dist/client/_astro/DockviewSpatialWorkbench.BTd66LPl.js +12 -0
  9. package/dist/client/_astro/DocumentViewlets.KY1HcNka.js +2 -0
  10. package/dist/client/_astro/DxfViewlet.B3N5zpZR.js +1 -0
  11. package/dist/client/_astro/ExcalidrawWhiteboardViewlet.CMJGCQN4.js +1 -0
  12. package/dist/client/_astro/{FaroVCardSpanInstrumenter.BIk2NhJY.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
  13. package/dist/client/_astro/{FontSpecimenViewlet.CpONhJh0.js → FontSpecimenViewlet.ChIyr0B8.js} +1 -1
  14. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.D3FSc061.js +1 -0
  15. package/dist/client/_astro/{ImageViewlet.CHeNvX6L.js → ImageViewlet.Cs-u7-wt.js} +1 -1
  16. package/dist/client/_astro/{KatexFormulaViewlet.Cy_InWOK.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
  17. package/dist/client/_astro/KoishiChatViewlet.DLsMmwdb.js +16 -0
  18. package/dist/client/_astro/MCardLibraryHarness.WBT9W10S.js +2 -0
  19. package/dist/client/_astro/{MarkdownViewlet.qoPlM-TZ.js → MarkdownViewlet.BIolkNXf.js} +25 -25
  20. package/dist/client/_astro/{MermaidDiagramViewlet.RnwDfQl6.js → MermaidDiagramViewlet.CkRk7QsS.js} +1 -1
  21. package/dist/client/_astro/PCardRendererBridge.DhaRSprd.js +1 -0
  22. package/dist/client/_astro/RendererPCardRegistry.brM2KiQs.js +1 -0
  23. package/dist/client/_astro/{SchemaYamlViewlet.D6HVdmrq.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
  24. package/dist/client/_astro/{ShellContainer.astro_astro_type_script_index_0_lang.2oi8fhQo.js → ShellContainer.astro_astro_type_script_index_0_lang.5q1gCLvf.js} +1 -1
  25. package/dist/client/_astro/{Spatial3dViewlet.CCYBSSib.js → Spatial3dViewlet.C-jjhr0A.js} +1 -1
  26. package/dist/client/_astro/{StudioLayout.CBgiVbeb.css → StudioLayout.CX8XGtZV.css} +1 -1
  27. package/dist/client/_astro/StudioWorkbench.B1QwGHWM.js +7 -0
  28. package/dist/client/_astro/{SvgViewlet.BxlWQ-JX.js → SvgViewlet.uGxvb06H.js} +1 -1
  29. package/dist/client/_astro/{TerminalView.DWZR-hUa.js → TerminalView.DP7G7E1m.js} +4 -4
  30. package/dist/client/_astro/{ThemeSettingsViewlet.Cb1r8fWw.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
  31. package/dist/client/_astro/{TikzDiagramViewlet.CqY7VTeP.js → TikzDiagramViewlet.O8MJyXfT.js} +1 -1
  32. package/dist/client/_astro/VideoPlayerViewlet.-ycmo3kY.js +1 -0
  33. package/dist/client/_astro/WebappZenViewlet.PNce4u2T.js +1 -0
  34. package/dist/client/_astro/{WelcomeViewport.LwKTA6h7.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
  35. package/dist/client/_astro/{agentIdentityCredentialService.BtKVsl2C.js → agentIdentityCredentialService.BEtZzBlO.js} +5 -5
  36. package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
  37. package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
  38. package/dist/client/_astro/{markdownService.D-tM2RYx.js → markdownService.CpuKl0vp.js} +1 -1
  39. package/dist/client/_astro/{mcardStore.BiAvqM-D.js → mcardStore.nSWnzeLg.js} +2 -2
  40. package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
  41. package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
  42. package/dist/client/_astro/polyfills.Bi7kO8cu.js +1 -0
  43. package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
  44. package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
  45. package/dist/client/_astro/{tikzCompiler.DFojjdxR.js → tikzCompiler.-fXMNQpz.js} +1 -1
  46. package/dist/client/_astro/{useMCardHydration.Co47OH3D.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
  47. package/dist/client/_astro/vendor-ai.D6NcJ6lu.js +69 -0
  48. package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
  49. package/dist/client/_astro/vfsHandles.D4Pq18pW.js +1 -0
  50. package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
  51. package/dist/client/_astro/vfsTransactions.DBNtFuRz.js +1 -0
  52. package/dist/client/_astro/{workspaceStore.CXakha4Y.js → workspaceStore.DUHW2YBc.js} +1 -1
  53. package/dist/client/js/buffer-polyfill.js +14 -0
  54. package/dist/server/chunks/{StudioLayout_D163irJ0.mjs → StudioLayout_taayQJ5b.mjs} +2 -2
  55. package/dist/server/chunks/{_.._ZXsz792-.mjs → _.._CoQKwo62.mjs} +137 -91
  56. package/dist/server/chunks/{_handle__D_cIJYrU.mjs → _handle__D8dKQPUS.mjs} +3 -3
  57. package/dist/server/chunks/{cardTypeDetector_CyW1Xnmy.mjs → cardTypeDetector_C55M_HWS.mjs} +9 -0
  58. package/dist/server/chunks/{cards_B89BvF6W.mjs → cards_rVOc8K6H.mjs} +2 -2
  59. package/dist/server/chunks/cas_DTxlZ4Le.mjs +68 -0
  60. package/dist/server/chunks/{dispatch_DOwSKukU.mjs → dispatch_BTW4E_BJ.mjs} +8 -7
  61. package/dist/server/chunks/{dispatch_CxWKiHpn.mjs → dispatch_MbkljUxD.mjs} +8 -8
  62. package/dist/server/chunks/{export_DRouradA.mjs → export_DkEwDE2T.mjs} +3 -3
  63. package/dist/server/chunks/{health_Dfa5I0-X.mjs → health_cRt0M0yu.mjs} +1 -1
  64. package/dist/server/chunks/{mcard-library_DvPPUs9_.mjs → mcard-library_CLHvyslV.mjs} +1 -1
  65. package/dist/server/chunks/{mcardVfs_CeezzRvt.mjs → mcardVfs_DvNburKb.mjs} +5 -30
  66. package/dist/server/chunks/{move__RFvIDkq.mjs → move_DYcaXBLV.mjs} +6 -6
  67. package/dist/server/chunks/{pathsConfig_CgNYYLVm.mjs → pathsConfig_Dack-p2f.mjs} +13 -3
  68. package/dist/server/chunks/{proxy_CrWJQIBe.mjs → proxy_CMbbdBPW.mjs} +2 -2
  69. package/dist/server/chunks/{raw_DzNDaDVP.mjs → raw_C97sJWhg.mjs} +59 -26
  70. package/dist/server/chunks/{serverBootstrap_XKo2s6Ha.mjs → serverBootstrap_BDdSRIu5.mjs} +2 -2
  71. package/dist/server/chunks/tree_BwmO-pTe.mjs +186 -0
  72. package/dist/server/chunks/vfsCore_DIKpk-pk.mjs +98 -0
  73. package/dist/server/chunks/{vfsTreeScan_CKp7kMt9.mjs → vfsTreeScan_CRoCluPB.mjs} +18 -10
  74. package/dist/server/chunks/workspaceRoot_CRx3taID.mjs +157 -0
  75. package/dist/server/chunks/{write_popiFsO7.mjs → write_BLsmsTIx.mjs} +6 -5
  76. package/dist/server/chunks/{ws-server-init_CkcgcI5V.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
  77. package/dist/server/entry.mjs +8 -4
  78. package/dist/server/entry2.mjs +67 -28
  79. package/dist/server/virtual_astro_middleware.mjs +2 -2
  80. package/package.json +2 -2
  81. package/public/js/buffer-polyfill.js +14 -0
  82. package/src/components/studio/views/cardViewlets/ClmRegistryComponentViewlet.tsx +133 -0
  83. package/src/components/studio/views/cardViewlets/DxfViewlet.tsx +230 -0
  84. package/src/components/studio/views/cardViewlets/VideoPlayerViewlet.tsx +4 -4
  85. package/src/components/studio/views/cardViewlets/coreViewletDefs.ts +2 -2
  86. package/src/components/studio/views/cardViewlets/documents/AudioPlayerViewlet.tsx +15 -3
  87. package/src/components/studio/views/cardViewlets/documents/PdfViewlet.tsx +25 -7
  88. package/src/components/studio/views/cardViewlets/markdown/stages/wikilinkStage.ts +2 -1
  89. package/src/components/studio/views/cardViewlets/mediaViewletDefs.ts +21 -1
  90. package/src/components/studio/views/cardViewlets/webapp/WebappCanvas.tsx +40 -15
  91. package/src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx +108 -0
  92. package/src/components/studio/views/cardViewlets/webapp/WebappZenViewlet.tsx +23 -30
  93. package/src/components/studio/views/fileTree/MCardFileTree.tsx +71 -54
  94. package/src/components/studio/views/fileTree/hooks/useFileTreeSync.ts +0 -1
  95. package/src/components/studio/views/fileTree/hooks/usePartitionedTrees.ts +68 -23
  96. package/src/components/studio/views/fileTree/hooks/useSectionAccordion.ts +21 -11
  97. package/src/components/studio/views/functions/UnifiedFunctionExplorerViewlet.tsx +168 -0
  98. package/src/components/studio/views/history/HistoryPanel.tsx +110 -0
  99. package/src/components/studio/views/lineage/LineagePanel.tsx +152 -0
  100. package/src/components/studio/views/navigation/HandleLineageDrawer.tsx +89 -0
  101. package/src/components/studio/views/navigation/MultiCardCollectionBrowser.tsx +154 -0
  102. package/src/components/studio/views/pills/HashPill.tsx +101 -0
  103. package/src/components/studio/views/residency/ResidencyIndicator.tsx +82 -0
  104. package/src/config/app_config.json +3 -3
  105. package/src/core/projection/catalog.ts +105 -0
  106. package/src/core/projection/collection.ts +148 -0
  107. package/src/core/projection/handleSubscription.ts +132 -0
  108. package/src/core/projection/index.ts +4 -0
  109. package/src/core/projection/selectors.ts +29 -0
  110. package/src/core/projection/views.ts +242 -0
  111. package/src/core/refinement/designMetrics.ts +104 -0
  112. package/src/core/refinement/fibrationProjector.ts +142 -0
  113. package/src/core/refinement/lagrangianEngine.ts +137 -0
  114. package/src/core/refinement/refinementCommands.ts +82 -0
  115. package/src/core/viewport/deviceArchetypeRegistry.ts +177 -0
  116. package/src/core/viewport/viewportAudit.ts +150 -0
  117. package/src/edge/storeFilter.d.ts +4 -0
  118. package/src/edge/storeFilter.js +54 -0
  119. package/src/edge/storeFilter.ts +52 -0
  120. package/src/layouts/StudioLayout.astro +1 -0
  121. package/src/lib/cryptoPolyfill.js +77 -1
  122. package/src/lib/fsPolyfill.js +65 -0
  123. package/src/lib/urlPolyfill.js +21 -0
  124. package/src/lib/zlibPolyfill.js +35 -0
  125. package/src/packages/mcard-studio/package.json +2 -2
  126. package/src/packages/mcard-studio/type/legacyMapping.ts +5 -0
  127. package/src/packages/mcard-studio/viewlets/manifests.ts +2 -0
  128. package/src/packages/mcard-studio/viewlets/moduleMap.ts +12 -0
  129. package/src/packages/mcard-studio/viewlets/refinementManifests.ts +114 -0
  130. package/src/pages/api/dispatch.ts +3 -2
  131. package/src/pages/api/vfs/cas.ts +114 -0
  132. package/src/pages/api/vfs/move.ts +5 -5
  133. package/src/pages/api/vfs/raw.ts +72 -27
  134. package/src/pages/api/vfs/tree.ts +130 -11
  135. package/src/pages/api/vfs/write.ts +5 -4
  136. package/src/pages/index.astro +75 -0
  137. package/src/server/api/kernelDispatch.ts +8 -8
  138. package/src/server/artifactCollectionService.ts +4 -7
  139. package/src/server/artifactRepository.ts +4 -3
  140. package/src/server/clmRunner.mjs +1 -1
  141. package/src/server/collectionOwner.mjs +5 -5
  142. package/src/server/effects/executionPersistenceService.mjs +11 -11
  143. package/src/server/effects/resultSealingService.mjs +2 -2
  144. package/src/server/fileIngestService.mjs +21 -9
  145. package/src/server/fileWatcherService.mjs +4 -1
  146. package/src/server/handlers/fileChangeHandler.mjs +18 -10
  147. package/src/server/handlers/saveExecutionLogHandler.mjs +6 -6
  148. package/src/server/notificationService.mjs +14 -1
  149. package/src/server/scripts/buildSeedingMemory.mjs +3 -3
  150. package/src/server/serverMemoryRepository.ts +41 -59
  151. package/src/server/vfsTreeScan.ts +16 -10
  152. package/src/server/workspaceRoot.ts +143 -5
  153. package/src/services/cardTypeDetector.ts +4 -0
  154. package/src/services/databaseSyncService.ts +30 -46
  155. package/src/services/inBrowserLlm/engines/litertEngine.ts +1 -1
  156. package/src/services/namespaceProtocolClient.ts +221 -0
  157. package/src/services/renderers/pcard/RendererPCardRegistry.ts +4 -66
  158. package/src/services/renderers/pcard/modalitySpecs.ts +125 -0
  159. package/src/services/renderers/pcard/types.ts +7 -1
  160. package/src/services/renderers/rendererEventBus.ts +5 -3
  161. package/src/services/unifiedFunctionExecutionService.ts +145 -0
  162. package/src/services/vfs/vfsCore.ts +12 -1
  163. package/src/services/vfs/vfsMigration.ts +95 -0
  164. package/src/services/vfs/vfsMutations.ts +17 -35
  165. package/src/services/vfs/vfsPersistence.ts +19 -24
  166. package/src/services/vfs/vfsSync.ts +55 -17
  167. package/src/services/vfs/vfsVersions.ts +23 -34
  168. package/src/services/workbenchExecutionPolicy.ts +183 -0
  169. package/src/stores/mcardCollectionStore.ts +2 -0
  170. package/src/styles/dockview.css +34 -0
  171. package/src/ui/viewlets/FibrationRefinementViewlet.tsx +155 -0
  172. package/src/ui/viewlets/PetriConformanceViewlet.tsx +166 -0
  173. package/src/ui/viewlets/ResponsiveViewportLabViewlet.tsx +175 -0
  174. package/src/ui/viewlets/SprintGovernanceViewlet.tsx +176 -0
  175. package/src/ui/viewlets/viewletFocus.ts +35 -0
  176. package/src/ui/viewlets/viewportLabParts.tsx +190 -0
  177. package/dist/client/_astro/ClmPcardViewlet.DW5Yft0E.js +0 -3
  178. package/dist/client/_astro/D3GraphViewlet.DAjPz1DP.js +0 -2
  179. package/dist/client/_astro/DockviewSpatialWorkbench.DyQjSoHd.js +0 -12
  180. package/dist/client/_astro/DocumentViewlets.Dm_GL3AL.js +0 -2
  181. package/dist/client/_astro/ExcalidrawWhiteboardViewlet.DrlW7B6G.js +0 -1
  182. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.DGXU-3Lu.js +0 -1
  183. package/dist/client/_astro/KoishiChatViewlet.B0eDEMnT.js +0 -16
  184. package/dist/client/_astro/MCardLibraryHarness.CUJLJFBt.js +0 -2
  185. package/dist/client/_astro/PCardRendererBridge.BnyaE05I.js +0 -1
  186. package/dist/client/_astro/RendererPCardRegistry.CLr4j1Ub.js +0 -1
  187. package/dist/client/_astro/StudioWorkbench.CF0SOYwy.js +0 -7
  188. package/dist/client/_astro/VideoPlayerViewlet.DoSYmmoQ.js +0 -1
  189. package/dist/client/_astro/WebappZenViewlet.CQW50OhX.js +0 -1
  190. package/dist/client/_astro/cardTypeDetector.C9kGObMh.js +0 -1
  191. package/dist/client/_astro/disposable.66apX1Q2.js +0 -1
  192. package/dist/client/_astro/empty.DOwCrGXH.js +0 -1
  193. package/dist/client/_astro/mcardVfs.Bj-RA0p7.js +0 -2
  194. package/dist/client/_astro/path.CR60mj9W.js +0 -1
  195. package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
  196. package/dist/client/_astro/polyfills.DcBkS56X.js +0 -1
  197. package/dist/client/_astro/rendererEventBus.CyFnSRLk.js +0 -1
  198. package/dist/client/_astro/themeStore.zUMFLo3Q.js +0 -1
  199. package/dist/client/_astro/vendor-ai.CZe7UVVK.js +0 -69
  200. package/dist/client/_astro/vfsHandles.B-nczBRy.js +0 -1
  201. package/dist/client/_astro/vfsPersistence.D6zRzVML.js +0 -1
  202. package/dist/client/_astro/vfsTransactions.04mkEHxD.js +0 -1
  203. package/dist/server/chunks/cryptoPolyfill_99rxUwYC.mjs +0 -180
  204. package/dist/server/chunks/kernelHash_DRaj51hY.mjs +0 -5
  205. package/dist/server/chunks/tree_CE2BhvyJ.mjs +0 -76
  206. package/dist/server/chunks/vfsCore_B6nCiBl5.mjs +0 -21
  207. package/dist/server/chunks/workspaceRoot_DVSUbYkd.mjs +0 -71
  208. package/src/server/kernelHash.ts +0 -22
  209. package/src/server/storage/cardCollection.ts +0 -94
  210. package/src/server/storage/index.ts +0 -3
  211. package/src/server/storage/mcard.ts +0 -99
  212. package/src/server/storage/sqliteNodeEngine.ts +0 -121
@@ -8,6 +8,35 @@ import type { ProbeResult } from './hooks/useWebappSecurityProbe';
8
8
  import { IframeSecurityShield } from '../IframeSecurityShield';
9
9
  import { WebappForbiddenView } from '../WebappForbiddenView';
10
10
 
11
+ export type WebappTrustMode = 'untrusted-external' | 'trusted-same-origin';
12
+ export const UNTRUSTED_EXTERNAL_SANDBOX = 'allow-scripts allow-forms allow-popups allow-downloads';
13
+ export const TRUSTED_SAME_ORIGIN_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups allow-downloads';
14
+ export const WEBAPP_TELEMETRY_SCHEMA = 'mcard-portal-telemetry/v1';
15
+ export const WEBAPP_TELEMETRY_TYPES = Object.freeze(['portal:ready', 'portal:resize', 'portal:metric', 'portal:error']);
16
+
17
+ export function resolveWebappSandbox(trustMode: WebappTrustMode = 'untrusted-external'): string {
18
+ return trustMode === 'trusted-same-origin' ? TRUSTED_SAME_ORIGIN_SANDBOX : UNTRUSTED_EXTERNAL_SANDBOX;
19
+ }
20
+
21
+ export function validateWebappTelemetryMessage(
22
+ event: { source?: unknown; origin?: string; data?: unknown } | null | undefined,
23
+ options: { expectedSource: unknown; expectedNonce: string | null | undefined },
24
+ ): { ok: boolean; reason?: string; message?: { schema: string; type: string; nonce: string; payload: Record<string, unknown> } } {
25
+ if (!event || typeof event !== 'object') return { ok: false, reason: 'invalid_event' };
26
+ if (!options.expectedSource || event.source !== options.expectedSource) return { ok: false, reason: 'source_mismatch' };
27
+ if (!options.expectedNonce || typeof options.expectedNonce !== 'string') return { ok: false, reason: 'nonce_unconfigured' };
28
+ const data = event.data as Record<string, unknown> | null | undefined;
29
+ if (!data || typeof data !== 'object' || Array.isArray(data)) return { ok: false, reason: 'malformed_payload' };
30
+ if (data.schema !== WEBAPP_TELEMETRY_SCHEMA) return { ok: false, reason: 'unsupported_schema_version' };
31
+ if (typeof data.nonce !== 'string' || data.nonce !== options.expectedNonce) return { ok: false, reason: 'nonce_mismatch' };
32
+ if (typeof data.type !== 'string' || !(WEBAPP_TELEMETRY_TYPES as readonly string[]).includes(data.type)) {
33
+ return { ok: false, reason: 'unsupported_message_type' };
34
+ }
35
+ const payload = data.payload ?? {};
36
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return { ok: false, reason: 'invalid_payload_object' };
37
+ return { ok: true, message: { schema: data.schema, type: data.type, nonce: data.nonce, payload: payload as Record<string, unknown> } };
38
+ }
39
+
11
40
  export interface WebappCanvasProps {
12
41
  appName?: string;
13
42
  viewportStyles: React.CSSProperties;
@@ -23,23 +52,15 @@ export interface WebappCanvasProps {
23
52
  hasShieldError: boolean;
24
53
  setHasShieldError: (has: boolean) => void;
25
54
  iframeKey: number;
55
+ trustMode?: WebappTrustMode;
56
+ mountNonce?: string;
26
57
  }
27
58
 
28
59
  export const WebappCanvas: React.FC<WebappCanvasProps> = ({
29
- appName,
30
- viewportStyles,
31
- probeData,
32
- forceDirectEmbed,
33
- setForceDirectEmbed,
34
- targetUrl,
35
- activeSrc,
36
- useProxy,
37
- setUseProxy,
38
- isLoading,
39
- setIsLoading,
40
- hasShieldError,
41
- setHasShieldError,
42
- iframeKey,
60
+ appName, viewportStyles, probeData, forceDirectEmbed, setForceDirectEmbed,
61
+ targetUrl, activeSrc, useProxy, setUseProxy, isLoading, setIsLoading,
62
+ hasShieldError, setHasShieldError, iframeKey,
63
+ trustMode = 'untrusted-external', mountNonce = 'default-mount-nonce',
43
64
  }) => {
44
65
  return (
45
66
  <div
@@ -120,7 +141,11 @@ export const WebappCanvas: React.FC<WebappCanvasProps> = ({
120
141
  key={iframeKey}
121
142
  src={activeSrc}
122
143
  title={appName || 'WebApp MCard'}
123
- sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-downloads"
144
+ sandbox={resolveWebappSandbox(trustMode)}
145
+ referrerPolicy="no-referrer"
146
+ data-role="webapp-iframe"
147
+ data-trust-mode={trustMode}
148
+ data-mount-nonce={mountNonce}
124
149
  onLoad={() => setIsLoading(false)}
125
150
  onError={() => {
126
151
  setIsLoading(false);
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Device-Archetype Preset Bar & Viewport Style Resolver (SMR-12 · DoD-SMR-12-03)
3
+ * Canonical Path: src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx
4
+ *
5
+ * Extracted from WebappZenViewlet.tsx to preserve INV-304-11 (<=150 LOC thin membrane).
6
+ */
7
+
8
+ import React from 'react';
9
+ import type { ViewportMode } from './types';
10
+ import {
11
+ DEVICE_CLASSES,
12
+ DEVICE_PRESETS,
13
+ getPreset,
14
+ } from '../../../../../core/viewport/deviceArchetypeRegistry';
15
+
16
+ const FRAMED_SHADOW = '0 0 24px rgba(0, 0, 0, 0.6)';
17
+ const MOBILE_SHADOW = '0 0 28px rgba(0, 0, 0, 0.7)';
18
+ const FRAMED_BORDER = '1px solid #3c3c3c';
19
+
20
+ export function resolveWebappViewportStyles(
21
+ presetId: string | null,
22
+ viewportMode: ViewportMode,
23
+ ): React.CSSProperties {
24
+ const preset = presetId ? getPreset(presetId) : undefined;
25
+ if (preset) {
26
+ if (preset.deviceClass === 'desktop') {
27
+ return { width: '100%', height: '100%' };
28
+ }
29
+ return {
30
+ width: `${preset.width}px`,
31
+ maxWidth: '100%',
32
+ height: '100%',
33
+ margin: '0 auto',
34
+ boxShadow: FRAMED_SHADOW,
35
+ borderLeft: FRAMED_BORDER,
36
+ borderRight: FRAMED_BORDER,
37
+ };
38
+ }
39
+ switch (viewportMode) {
40
+ case 'tablet':
41
+ return {
42
+ width: '768px',
43
+ maxWidth: '100%',
44
+ height: '100%',
45
+ margin: '0 auto',
46
+ boxShadow: FRAMED_SHADOW,
47
+ borderLeft: FRAMED_BORDER,
48
+ borderRight: FRAMED_BORDER,
49
+ };
50
+ case 'mobile':
51
+ return {
52
+ width: '375px',
53
+ maxWidth: '100%',
54
+ height: '100%',
55
+ margin: '0 auto',
56
+ boxShadow: MOBILE_SHADOW,
57
+ borderLeft: FRAMED_BORDER,
58
+ borderRight: FRAMED_BORDER,
59
+ };
60
+ case 'desktop':
61
+ default:
62
+ return { width: '100%', height: '100%' };
63
+ }
64
+ }
65
+
66
+ export interface WebappDevicePresetBarProps {
67
+ presetId: string | null;
68
+ setPresetId: (presetId: string | null) => void;
69
+ targetUrl: string;
70
+ useProxy: boolean;
71
+ }
72
+
73
+ export const WebappDevicePresetBar: React.FC<WebappDevicePresetBarProps> = ({
74
+ presetId,
75
+ setPresetId,
76
+ targetUrl,
77
+ useProxy,
78
+ }) => {
79
+ const openResponsiveLab = () => {
80
+ window.dispatchEvent(
81
+ new CustomEvent('clm:open-responsive-lab', {
82
+ detail: { url: targetUrl, presetId, useProxy },
83
+ }),
84
+ );
85
+ };
86
+
87
+ return (
88
+ <div className="webapp-viewport-presets" data-role="viewport-presets">
89
+ <label htmlFor="webapp-device-preset">Device</label>
90
+ <select
91
+ id="webapp-device-preset"
92
+ data-role="device-preset"
93
+ value={presetId ?? ''}
94
+ onChange={(e) => setPresetId(e.target.value || null)}
95
+ >
96
+ <option value="">Address-bar mode</option>
97
+ {DEVICE_PRESETS.map((p) => (
98
+ <option key={p.id} value={p.id}>
99
+ {DEVICE_CLASSES[p.deviceClass].label} · {p.label} {p.width}×{p.height}
100
+ </option>
101
+ ))}
102
+ </select>
103
+ <button type="button" data-role="open-responsive-lab" onClick={openResponsiveLab}>
104
+ Open in Responsive Lab
105
+ </button>
106
+ </div>
107
+ );
108
+ };
@@ -16,12 +16,14 @@ import { FullscreenIframeModal } from '../FullscreenIframeModal';
16
16
  import { WebappAddressBar } from './WebappAddressBar';
17
17
  import { ProxyAdvisoryBanner } from './ProxyAdvisoryBanner';
18
18
  import { WebappCanvas } from './WebappCanvas';
19
+ import { WebappDevicePresetBar, resolveWebappViewportStyles } from './WebappDevicePresetBar';
19
20
  import { useWebappSecurityProbe } from './hooks/useWebappSecurityProbe';
20
21
  import { useZenAudioTeardown } from './hooks/useZenAudioTeardown';
21
22
 
22
23
  export const WebappZenViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
23
24
  const [isZenOpen, setIsZenOpen] = useState(false);
24
25
  const [viewportMode, setViewportMode] = useState<ViewportMode>('desktop');
26
+ const [presetId, setPresetId] = useState<string | null>(null);
25
27
  const [isLoading, setIsLoading] = useState(true);
26
28
  const [iframeKey, setIframeKey] = useState(0);
27
29
  const [copied, setCopied] = useState(false);
@@ -29,35 +31,24 @@ export const WebappZenViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
29
31
  // Cordis Rule 3: Clean WebAudio and animation loop teardown on unmount
30
32
  useZenAudioTeardown();
31
33
 
32
- const targetUrl = useMemo(() => {
33
- return extractWebappUrl(mcard.content, mcard.path, mcard.name);
34
- }, [mcard.content, mcard.path, mcard.name]);
34
+ const targetUrl = useMemo(
35
+ () => extractWebappUrl(mcard.content, mcard.path, mcard.name),
36
+ [mcard.content, mcard.path, mcard.name],
37
+ );
35
38
 
36
39
  const {
37
- probeData,
38
- useProxy,
39
- setUseProxy,
40
- hasShieldError,
41
- setHasShieldError,
42
- isAdvisoryDismissed,
43
- setIsAdvisoryDismissed,
44
- forceDirectEmbed,
45
- setForceDirectEmbed,
46
- activeSrc,
40
+ probeData, useProxy, setUseProxy, hasShieldError, setHasShieldError,
41
+ isAdvisoryDismissed, setIsAdvisoryDismissed, forceDirectEmbed, setForceDirectEmbed, activeSrc,
47
42
  } = useWebappSecurityProbe(targetUrl);
48
43
 
49
44
  // SV-08: Auto-enable proxy shield on fullscreen split request
50
45
  React.useEffect(() => {
51
46
  const handleSplitReq = (e: Event) => {
52
47
  const detail = (e as CustomEvent<{ targetUrl?: string; useProxy?: boolean }>).detail;
53
- if (detail?.useProxy || probeData?.shouldBlockEmbed) {
54
- setUseProxy(true);
55
- }
48
+ if (detail?.useProxy || probeData?.shouldBlockEmbed) setUseProxy(true);
56
49
  };
57
50
  window.addEventListener('clm:fullscreen-split-requested', handleSplitReq);
58
- return () => {
59
- window.removeEventListener('clm:fullscreen-split-requested', handleSplitReq);
60
- };
51
+ return () => window.removeEventListener('clm:fullscreen-split-requested', handleSplitReq);
61
52
  }, [probeData?.shouldBlockEmbed, setUseProxy]);
62
53
 
63
54
  const handleCopyUrl = async () => {
@@ -75,17 +66,12 @@ export const WebappZenViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
75
66
  setIframeKey((k) => k + 1);
76
67
  };
77
68
 
78
- const viewportStyles = useMemo<React.CSSProperties>(() => {
79
- switch (viewportMode) {
80
- case 'tablet':
81
- return { width: '768px', maxWidth: '100%', height: '100%', margin: '0 auto', boxShadow: '0 0 24px rgba(0, 0, 0, 0.6)', borderLeft: '1px solid #3c3c3c', borderRight: '1px solid #3c3c3c' };
82
- case 'mobile':
83
- return { width: '375px', maxWidth: '100%', height: '100%', margin: '0 auto', boxShadow: '0 0 28px rgba(0, 0, 0, 0.7)', borderLeft: '1px solid #3c3c3c', borderRight: '1px solid #3c3c3c' };
84
- case 'desktop':
85
- default:
86
- return { width: '100%', height: '100%' };
87
- }
88
- }, [viewportMode]);
69
+ // SMR-12: an explicit device-archetype preset takes precedence over the coarse
70
+ // address-bar mode; the address bar keeps working when no preset is chosen.
71
+ const viewportStyles = useMemo<React.CSSProperties>(
72
+ () => resolveWebappViewportStyles(presetId, viewportMode),
73
+ [presetId, viewportMode],
74
+ );
89
75
 
90
76
  return (
91
77
  <div className="webapp-zen-viewlet" style={{ display: 'flex', flexDirection: 'column', height: '100%', width: '100%', backgroundColor: '#181818', color: '#cccccc', position: 'relative', overflow: 'hidden' }}>
@@ -115,6 +101,13 @@ export const WebappZenViewlet: React.FC<CardViewletProps> = ({ mcard }) => {
115
101
  targetUrl={targetUrl}
116
102
  />
117
103
 
104
+ <WebappDevicePresetBar
105
+ presetId={presetId}
106
+ setPresetId={setPresetId}
107
+ targetUrl={targetUrl}
108
+ useProxy={useProxy}
109
+ />
110
+
118
111
  <WebappCanvas
119
112
  appName={mcard.name}
120
113
  viewportStyles={viewportStyles}
@@ -34,8 +34,8 @@ export const MCardFileTree: React.FC = () => {
34
34
  const { draggedItem, dragOverPath, setDraggedItem, setDragOverPath, handleDrop, handleDragOver, handleDragLeave } = useDragAndDrop();
35
35
  const { handleUploadFile, handleForkDirectory } = useFileTreeTransactions({ onRefresh: handleRefresh });
36
36
 
37
- const { filteredTrees, matchCounts, itemCounts, totalMatches, autoExpandedDirs, isFiltering } = usePartitionedTrees(treeMap, query);
38
- const { sections, expanded, toggleSection } = useSectionAccordion(activeMCard?.handle || activeMCard?.path || null, isFiltering, matchCounts);
37
+ const { sections: dynamicSections, filteredTrees, matchCounts, itemCounts, totalMatches, autoExpandedDirs, isFiltering } = usePartitionedTrees(treeMap, query);
38
+ const { sections, expanded, toggleSection } = useSectionAccordion(activeMCard?.handle || activeMCard?.path || null, isFiltering, matchCounts, dynamicSections);
39
39
 
40
40
  const toggleCollapse = useCallback((dirPath: string) => {
41
41
  setCollapsedDirs((prev) => ({ ...prev, [dirPath]: !prev[dirPath] }));
@@ -48,63 +48,80 @@ export const MCardFileTree: React.FC = () => {
48
48
  return copy;
49
49
  }, [collapsedDirs, autoExpandedDirs, isFiltering]);
50
50
 
51
+ const rwSections = useMemo(() => sections.filter((s) => s.mode === 'read-write'), [sections]);
52
+ const roSections = useMemo(() => sections.filter((s) => s.mode === 'read-only'), [sections]);
53
+
54
+ const renderSection = (sec: (typeof sections)[number]) => (
55
+ <ExplorerSection
56
+ key={sec.id}
57
+ id={sec.id}
58
+ title={sec.title}
59
+ mode={sec.mode}
60
+ icon={sec.mode === 'read-only' ? <LockIcon size={12} /> : undefined}
61
+ isExpanded={expanded[sec.id] ?? false}
62
+ itemCount={itemCounts[sec.id] || 0}
63
+ matchCount={isFiltering ? matchCounts[sec.id] : undefined}
64
+ onToggle={() => toggleSection(sec.id)}
65
+ actions={
66
+ sec.mode === 'read-write' ? (
67
+ <>
68
+ <button type="button" data-testid="section-new-card-btn" title="New Card" onClick={() => startCardInsertion(resolveTargetFolder())} className="explorer-section-action-btn">+</button>
69
+ <button type="button" data-testid="section-new-folder-btn" title="New Folder" onClick={() => startFolderInsertion(resolveTargetFolder())} className="explorer-section-action-btn">📁</button>
70
+ <button type="button" data-testid="section-refresh-btn" title="Refresh" onClick={handleRefresh} className="explorer-section-action-btn">🔄</button>
71
+ </>
72
+ ) : (
73
+ <button type="button" data-testid={`section-${sec.id}-fork-btn`} title="Fork to Workspace" onClick={handleForkDirectory} className="explorer-section-action-btn-fork">Fork</button>
74
+ )
75
+ }
76
+ >
77
+ <div
78
+ data-testid={`section-${sec.id}-drop-zone`}
79
+ onDragOver={(e) => sec.mode === 'read-write' && handleDragOver(e, '__root__')}
80
+ onDragLeave={(e) => sec.mode === 'read-write' && handleDragLeave(e, '__root__')}
81
+ onDrop={(e) => sec.mode === 'read-write' && handleDrop(e, '')}
82
+ className={`explorer-section-drop-zone ${dragOverPath === '__root__' && sec.mode === 'read-write' ? 'drag-active' : ''}`}
83
+ >
84
+ <FileTreeNode
85
+ nodes={filteredTrees[sec.id] || {}}
86
+ collapsedDirs={effectiveCollapsedDirs}
87
+ toggleCollapse={toggleCollapse}
88
+ activeMCard={activeMCard}
89
+ editingPath={editingPath}
90
+ editingValue={editingValue}
91
+ setEditingValue={setEditingValue}
92
+ startRename={startRename}
93
+ cancelRename={cancelRename}
94
+ commitRename={commitRename}
95
+ draggedItem={draggedItem}
96
+ dragOverPath={dragOverPath}
97
+ setDraggedItem={setDraggedItem}
98
+ setDragOverPath={setDragOverPath}
99
+ onDropItem={handleDrop}
100
+ onSelectDir={setSelectedDirPath}
101
+ />
102
+ </div>
103
+ </ExplorerSection>
104
+ );
105
+
51
106
  return (
52
107
  <div className="mcard-file-tree">
53
108
  <ExplorerSearchField totalMatches={isFiltering ? totalMatches : undefined} />
54
109
  <ExplorerActionBar onUploadFile={handleUploadFile} />
55
- <div className="mcard-file-tree-scroll">
56
- {sections.map((sec) => (
57
- <ExplorerSection
58
- key={sec.id}
59
- id={sec.id}
60
- title={sec.title}
61
- mode={sec.mode}
62
- icon={sec.mode === 'read-only' ? <LockIcon size={12} /> : undefined}
63
- isExpanded={expanded[sec.id] ?? false}
64
- itemCount={itemCounts[sec.id] || 0}
65
- matchCount={isFiltering ? matchCounts[sec.id] : undefined}
66
- onToggle={() => toggleSection(sec.id)}
67
- actions={
68
- sec.id === WS_DIR ? (
69
- <>
70
- <button type="button" data-testid="section-new-card-btn" title="New Card" onClick={() => startCardInsertion(resolveTargetFolder())} className="explorer-section-action-btn">+</button>
71
- <button type="button" data-testid="section-new-folder-btn" title="New Folder" onClick={() => startFolderInsertion(resolveTargetFolder())} className="explorer-section-action-btn">📁</button>
72
- <button type="button" data-testid="section-refresh-btn" title="Refresh" onClick={handleRefresh} className="explorer-section-action-btn">🔄</button>
73
- </>
74
- ) : (
75
- <button type="button" data-testid={`section-${sec.id}-fork-btn`} title="Fork to Workspace" onClick={handleForkDirectory} className="explorer-section-action-btn-fork">Fork</button>
76
- )
77
- }
78
- >
79
- <div
80
- data-testid={`section-${sec.id}-drop-zone`}
81
- onDragOver={(e) => sec.id === WS_DIR && handleDragOver(e, '__root__')}
82
- onDragLeave={(e) => sec.id === WS_DIR && handleDragLeave(e, '__root__')}
83
- onDrop={(e) => sec.id === WS_DIR && handleDrop(e, '')}
84
- className={`explorer-section-drop-zone ${dragOverPath === '__root__' && sec.id === WS_DIR ? 'drag-active' : ''}`}
85
- >
86
- <FileTreeNode
87
- nodes={filteredTrees[sec.id] || {}}
88
- collapsedDirs={effectiveCollapsedDirs}
89
- toggleCollapse={toggleCollapse}
90
- activeMCard={activeMCard}
91
- editingPath={editingPath}
92
- editingValue={editingValue}
93
- setEditingValue={setEditingValue}
94
- startRename={startRename}
95
- cancelRename={cancelRename}
96
- commitRename={commitRename}
97
- draggedItem={draggedItem}
98
- dragOverPath={dragOverPath}
99
- setDraggedItem={setDraggedItem}
100
- setDragOverPath={setDragOverPath}
101
- onDropItem={handleDrop}
102
- onSelectDir={setSelectedDirPath}
103
- />
104
- </div>
105
- </ExplorerSection>
106
- ))}
110
+ <div className="mcard-file-tree-scroll mcard-file-tree-rw-scroll">
111
+ {rwSections.map(renderSection)}
107
112
  </div>
113
+ {roSections.length > 0 && (
114
+ <>
115
+ <div className="mcard-file-tree-gap-divider" data-testid="explorer-sections-gap">
116
+ <div className="mcard-file-tree-gap-line" />
117
+ <span className="mcard-file-tree-gap-label">Read-Only Projections</span>
118
+ <div className="mcard-file-tree-gap-line" />
119
+ </div>
120
+ <div className="mcard-file-tree-ro-scroll">
121
+ {roSections.map(renderSection)}
122
+ </div>
123
+ </>
124
+ )}
108
125
  </div>
109
126
  );
110
127
  };
@@ -77,7 +77,6 @@ export function useFileTreeSync(options: UseFileTreeSyncOptions = {}) {
77
77
 
78
78
  const interval = setInterval(() => {
79
79
  if ($syncMode.get() === 'server') {
80
- syncMCardVfsWithServer();
81
80
  federateAllScopesIntoTree();
82
81
  }
83
82
  }, 5000);
@@ -8,7 +8,7 @@ import { useMemo } from 'react';
8
8
  import type { MCardFileNode } from '@/types/mcard';
9
9
  import type { TreeNode } from '../FileTreeNode';
10
10
  import { filterSectionTree } from './useTreeSearchFilter';
11
- import { EXPLORER_SECTIONS, WS_DIR, ASSETS_DIR, CK_DIR, PUBLIC_DIR } from './useSectionAccordion';
11
+ import { EXPLORER_SECTIONS, WS_DIR, ASSETS_DIR, CK_DIR, PUBLIC_DIR, type SectionConfig } from './useSectionAccordion';
12
12
 
13
13
  function buildSectionTree(files: { relPath: string; file: MCardFileNode }[]): Record<string, TreeNode> {
14
14
  const tree: Record<string, TreeNode> = {};
@@ -37,29 +37,73 @@ function buildSectionTree(files: { relPath: string; file: MCardFileNode }[]): Re
37
37
 
38
38
  export function usePartitionedTrees(treeMap: Record<string, MCardFileNode>, query: string) {
39
39
  return useMemo(() => {
40
- const partitionedFiles: Record<string, { relPath: string; file: MCardFileNode }[]> = {
41
- [WS_DIR]: [],
42
- [ASSETS_DIR]: [],
43
- [CK_DIR]: [],
44
- [PUBLIC_DIR]: [],
45
- };
40
+ const files = Object.values(treeMap);
41
+ const isStandard = files.some((f) =>
42
+ f.path.startsWith(`${ASSETS_DIR}/`) ||
43
+ f.path.startsWith(`${CK_DIR}/`) ||
44
+ f.path.startsWith(`${PUBLIC_DIR}/`)
45
+ );
46
46
 
47
- const assetsPrefix = `${ASSETS_DIR}/`;
48
- const ckPrefix = `${CK_DIR}/`;
49
- const pubPrefix = `${PUBLIC_DIR}/`;
50
- const wsPrefix = `${WS_DIR}/`;
47
+ let sections: SectionConfig[];
48
+ const partitionedFiles: Record<string, { relPath: string; file: MCardFileNode }[]> = {};
51
49
 
52
- for (const file of Object.values(treeMap)) {
53
- const p = file.path;
54
- if (p.startsWith(assetsPrefix)) {
55
- partitionedFiles[ASSETS_DIR].push({ relPath: p.slice(assetsPrefix.length), file });
56
- } else if (p.startsWith(ckPrefix)) {
57
- partitionedFiles[CK_DIR].push({ relPath: p.slice(ckPrefix.length), file });
58
- } else if (p.startsWith(pubPrefix)) {
59
- partitionedFiles[PUBLIC_DIR].push({ relPath: p.slice(pubPrefix.length), file });
60
- } else {
61
- const rel = p.startsWith(wsPrefix) ? p.slice(wsPrefix.length) : p;
62
- partitionedFiles[WS_DIR].push({ relPath: rel, file });
50
+ if (isStandard || files.length === 0) {
51
+ sections = EXPLORER_SECTIONS;
52
+ for (const s of sections) partitionedFiles[s.id] = [];
53
+ const assetsPrefix = `${ASSETS_DIR}/`;
54
+ const ckPrefix = `${CK_DIR}/`;
55
+ const pubPrefix = `${PUBLIC_DIR}/`;
56
+ const wsPrefix = `${WS_DIR}/`;
57
+ for (const file of files) {
58
+ const p = file.path;
59
+ if (p.startsWith(assetsPrefix)) {
60
+ partitionedFiles[ASSETS_DIR].push({ relPath: p.slice(assetsPrefix.length), file });
61
+ } else if (p.startsWith(ckPrefix)) {
62
+ partitionedFiles[CK_DIR].push({ relPath: p.slice(ckPrefix.length), file });
63
+ } else if (p.startsWith(pubPrefix)) {
64
+ partitionedFiles[PUBLIC_DIR].push({ relPath: p.slice(pubPrefix.length), file });
65
+ } else {
66
+ const rel = p.startsWith(wsPrefix) ? p.slice(wsPrefix.length) : p;
67
+ partitionedFiles[WS_DIR].push({ relPath: rel, file });
68
+ }
69
+ }
70
+ } else {
71
+ const topDirs = new Set<string>();
72
+ let hasRootFiles = false;
73
+ for (const file of files) {
74
+ const slashIdx = file.path.indexOf('/');
75
+ if (slashIdx > 0) {
76
+ topDirs.add(file.path.slice(0, slashIdx));
77
+ } else {
78
+ hasRootFiles = true;
79
+ }
80
+ }
81
+ const sortedDirs = Array.from(topDirs).sort();
82
+ sections = sortedDirs.map((dir) => ({
83
+ id: dir,
84
+ title: dir,
85
+ mode: 'read-write' as const,
86
+ prefix: `${dir}/`,
87
+ }));
88
+ if (hasRootFiles) {
89
+ sections.push({
90
+ id: '__root__',
91
+ title: 'Files',
92
+ mode: 'read-write' as const,
93
+ prefix: '',
94
+ });
95
+ }
96
+ for (const s of sections) partitionedFiles[s.id] = [];
97
+ for (const file of files) {
98
+ const slashIdx = file.path.indexOf('/');
99
+ if (slashIdx > 0) {
100
+ const dir = file.path.slice(0, slashIdx);
101
+ if (partitionedFiles[dir]) {
102
+ partitionedFiles[dir].push({ relPath: file.path.slice(slashIdx + 1), file });
103
+ }
104
+ } else if (partitionedFiles['__root__']) {
105
+ partitionedFiles['__root__'].push({ relPath: file.path, file });
106
+ }
63
107
  }
64
108
  }
65
109
 
@@ -70,7 +114,7 @@ export function usePartitionedTrees(treeMap: Record<string, MCardFileNode>, quer
70
114
  const autoExpandedDirs = new Set<string>();
71
115
  let totalMatches = 0;
72
116
 
73
- for (const sec of EXPLORER_SECTIONS) {
117
+ for (const sec of sections) {
74
118
  const list = partitionedFiles[sec.id] || [];
75
119
  itemCounts[sec.id] = list.length;
76
120
  const tree = buildSectionTree(list);
@@ -84,6 +128,7 @@ export function usePartitionedTrees(treeMap: Record<string, MCardFileNode>, quer
84
128
  }
85
129
 
86
130
  return {
131
+ sections,
87
132
  rawTrees,
88
133
  filteredTrees,
89
134
  matchCounts,
@@ -28,20 +28,30 @@ export const EXPLORER_SECTIONS: SectionConfig[] = [
28
28
  { id: PUBLIC_DIR, title: 'READ-ONLY: Public Assets', mode: 'read-only', prefix: PUBLIC_DIR },
29
29
  ];
30
30
 
31
- function getInitialState(): Record<string, boolean> {
31
+ function getInitialState(secList: SectionConfig[]): Record<string, boolean> {
32
+ const defaults: Record<string, boolean> = {};
33
+ const isCustom = secList !== EXPLORER_SECTIONS;
34
+ for (let i = 0; i < secList.length; i++) {
35
+ defaults[secList[i].id] = isCustom ? true : i === 0;
36
+ }
32
37
  try {
33
38
  const raw = typeof localStorage !== 'undefined' ? localStorage.getItem(STORAGE_KEY) : null;
34
- if (raw) return JSON.parse(raw);
39
+ if (raw) return { ...defaults, ...JSON.parse(raw) };
35
40
  } catch {}
36
- return { [WS_DIR]: true, [ASSETS_DIR]: false, [CK_DIR]: false, [PUBLIC_DIR]: false };
41
+ return defaults;
37
42
  }
38
43
 
39
44
  export function useSectionAccordion(
40
45
  activeHandle: string | null | undefined,
41
46
  isFiltering: boolean,
42
- matchCounts: Record<string, number>
47
+ matchCounts: Record<string, number>,
48
+ customSections?: SectionConfig[]
43
49
  ) {
44
- const [expanded, setExpanded] = useState<Record<string, boolean>>(getInitialState);
50
+ const sections = useMemo(
51
+ () => (customSections && customSections.length > 0 ? customSections : EXPLORER_SECTIONS),
52
+ [customSections]
53
+ );
54
+ const [expanded, setExpanded] = useState<Record<string, boolean>>(() => getInitialState(sections));
45
55
 
46
56
  const toggleSection = useCallback((id: string) => {
47
57
  setExpanded((prev) => {
@@ -64,22 +74,22 @@ export function useSectionAccordion(
64
74
  : '';
65
75
  if (!handleStr || typeof handleStr.toLowerCase !== 'function') return;
66
76
  const lower = handleStr.toLowerCase();
67
- for (const sec of EXPLORER_SECTIONS) {
68
- if (lower.startsWith(sec.prefix)) {
77
+ for (const sec of sections) {
78
+ if (sec.prefix && lower.startsWith(sec.prefix.toLowerCase())) {
69
79
  setExpanded((prev) => (prev[sec.id] ? prev : { ...prev, [sec.id]: true }));
70
80
  break;
71
81
  }
72
82
  }
73
- }, [activeHandle]);
83
+ }, [activeHandle, sections]);
74
84
 
75
85
  const effectiveExpanded = useMemo(() => {
76
86
  if (!isFiltering) return expanded;
77
87
  const copy = { ...expanded };
78
- for (const sec of EXPLORER_SECTIONS) {
88
+ for (const sec of sections) {
79
89
  if ((matchCounts[sec.id] || 0) > 0) copy[sec.id] = true;
80
90
  }
81
91
  return copy;
82
- }, [expanded, isFiltering, matchCounts]);
92
+ }, [expanded, isFiltering, matchCounts, sections]);
83
93
 
84
- return { sections: EXPLORER_SECTIONS, expanded: effectiveExpanded, toggleSection };
94
+ return { sections, expanded: effectiveExpanded, toggleSection };
85
95
  }