@dfosco/storyboard-react 1.24.0 → 2.0.0-beta.0

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,9 +1,9 @@
1
1
  {
2
2
  "name": "@dfosco/storyboard-react",
3
- "version": "1.24.0",
3
+ "version": "2.0.0-beta.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "@dfosco/storyboard-core": "*",
6
+ "@dfosco/storyboard-core": "2.0.0-beta.0",
7
7
  "glob": "^11.0.0",
8
8
  "jsonc-parser": "^3.3.1"
9
9
  },
@@ -0,0 +1,43 @@
1
+ import { useCallback, useSyncExternalStore } from 'react'
2
+ import {
3
+ getCurrentMode,
4
+ getRegisteredModes,
5
+ activateMode,
6
+ subscribeToMode,
7
+ getModeSnapshot,
8
+ } from '@dfosco/storyboard-core'
9
+
10
+ /**
11
+ * React hook for the design-mode system.
12
+ *
13
+ * Uses useSyncExternalStore so the component re-renders whenever
14
+ * the active mode or the set of registered modes changes.
15
+ *
16
+ * @returns {{
17
+ * mode: string,
18
+ * modes: Array<{ name: string, label: string, icon?: string }>,
19
+ * switchMode: (name: string, options?: object) => void,
20
+ * currentModeConfig: object | undefined,
21
+ * }}
22
+ */
23
+ export function useMode() {
24
+ const snapshot = useSyncExternalStore(subscribeToMode, getModeSnapshot)
25
+
26
+ // snapshot is "modeName|registeredNames" — we only use it to trigger re-renders
27
+ void snapshot
28
+
29
+ const mode = getCurrentMode()
30
+ const modes = getRegisteredModes()
31
+ const currentModeConfig = modes.find((m) => m.name === mode)
32
+
33
+ const switchMode = useCallback((name, options) => {
34
+ activateMode(name, options)
35
+ }, [])
36
+
37
+ return {
38
+ mode,
39
+ modes,
40
+ switchMode,
41
+ currentModeConfig,
42
+ }
43
+ }
package/src/index.js CHANGED
@@ -20,6 +20,7 @@ export { useLocalStorage } from './hooks/useLocalStorage.js'
20
20
  export { useHideMode } from './hooks/useHideMode.js'
21
21
  export { useUndoRedo } from './hooks/useUndoRedo.js'
22
22
  export { useFeatureFlag } from './hooks/useFeatureFlag.js'
23
+ export { useMode } from './hooks/useMode.js'
23
24
 
24
25
  // React Router integration
25
26
  export { installHashPreserver } from './hashPreserver.js'
@@ -27,5 +28,8 @@ export { installHashPreserver } from './hashPreserver.js'
27
28
  // Form context (for design system packages to use)
28
29
  export { FormContext } from './context/FormContext.js'
29
30
 
31
+ // Design mode hook (keep — React apps may still read mode state)
32
+ // ModeSwitch and ToolbarShell UI moved to @dfosco/storyboard-svelte-ui
33
+
30
34
  // Viewfinder dashboard
31
35
  export { default as Viewfinder } from './Viewfinder.jsx'
@@ -108,6 +108,12 @@ function generateModule(index, root) {
108
108
  initCalls.push(`initPlugins(${JSON.stringify(config.plugins)})`)
109
109
  }
110
110
 
111
+ // Modes configuration from storyboard.config.json
112
+ if (config?.modes) {
113
+ imports.push(`import { initModesConfig } from '@dfosco/storyboard-core'`)
114
+ initCalls.push(`initModesConfig(${JSON.stringify(config.modes)})`)
115
+ }
116
+
111
117
  return [
112
118
  imports.join('\n'),
113
119
  '',