ywana-core8 0.2.3 → 0.2.5
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/dist/index.css +279 -0
- package/dist/index.js +423 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +423 -4
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +423 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/desktop/AppManager.js +270 -0
- package/src/desktop/ApplicationMenu.css +279 -0
- package/src/desktop/ApplicationMenu.js +214 -0
- package/src/desktop/Desktop.stories.jsx +262 -5
- package/src/desktop/desktop.js +124 -43
- package/src/desktop/index.js +5 -1
- package/src/examples/ApplicationMenuExample.js +361 -0
package/src/desktop/desktop.js
CHANGED
@@ -1,8 +1,56 @@
|
|
1
|
-
import React, { useRef, useEffect } from 'react'
|
1
|
+
import React, { useRef, useEffect, useState, createContext, useContext } from 'react'
|
2
2
|
import { WindowProvider, useWindows } from './WindowContext'
|
3
3
|
import { Window } from './window'
|
4
|
+
import { ApplicationMenu } from './ApplicationMenu'
|
5
|
+
import { defaultAppManager } from './AppManager'
|
4
6
|
import './desktop.css'
|
5
7
|
|
8
|
+
/**
|
9
|
+
* Context for Application state
|
10
|
+
*/
|
11
|
+
const AppContext = createContext()
|
12
|
+
|
13
|
+
export const useApplicationMenu = () => {
|
14
|
+
const context = useContext(AppContext)
|
15
|
+
if (!context) {
|
16
|
+
throw new Error('useApplicationMenu must be used within AppProvider')
|
17
|
+
}
|
18
|
+
return context.applicationMenu
|
19
|
+
}
|
20
|
+
|
21
|
+
export const useAppManager = () => {
|
22
|
+
const context = useContext(AppContext)
|
23
|
+
if (!context) {
|
24
|
+
throw new Error('useAppManager must be used within AppProvider')
|
25
|
+
}
|
26
|
+
return context.appManager
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* AppProvider - Provides Application state and AppManager to React components
|
31
|
+
*/
|
32
|
+
export const AppProvider = ({ children, appManager = defaultAppManager }) => {
|
33
|
+
const [isApplicationMenuOpen, setIsApplicationMenuOpen] = useState(false)
|
34
|
+
|
35
|
+
const value = {
|
36
|
+
// Application Menu state
|
37
|
+
applicationMenu: {
|
38
|
+
isOpen: isApplicationMenuOpen,
|
39
|
+
open: () => setIsApplicationMenuOpen(true),
|
40
|
+
close: () => setIsApplicationMenuOpen(false),
|
41
|
+
toggle: () => setIsApplicationMenuOpen(!isApplicationMenuOpen)
|
42
|
+
},
|
43
|
+
// App Manager instance
|
44
|
+
appManager: appManager
|
45
|
+
}
|
46
|
+
|
47
|
+
return (
|
48
|
+
<AppContext.Provider value={value}>
|
49
|
+
{children}
|
50
|
+
</AppContext.Provider>
|
51
|
+
)
|
52
|
+
}
|
53
|
+
|
6
54
|
/**
|
7
55
|
* Desktop layout component - manages overall desktop structure and sizing
|
8
56
|
*/
|
@@ -90,18 +138,7 @@ export const Workspace = ({ children }) => {
|
|
90
138
|
statusBar={window.statusBar}
|
91
139
|
>
|
92
140
|
<div style={{ padding: '16px' }}>
|
93
|
-
|
94
|
-
<p><strong>ID:</strong> {window.id}</p>
|
95
|
-
<p><strong>Position:</strong> {window.position.x}, {window.position.y}</p>
|
96
|
-
<p><strong>Size:</strong> {window.size.width} × {window.size.height}</p>
|
97
|
-
<p><strong>Z-Index:</strong> {window.zIndex}</p>
|
98
|
-
<p><strong>Status:</strong> {window.minimized ? 'Minimized' : window.maximized ? 'Maximized' : 'Normal'}</p>
|
99
|
-
|
100
|
-
<div style={{ marginTop: '16px', padding: '12px', background: '#f8f9fa', borderRadius: '4px' }}>
|
101
|
-
<p><strong>Window Content Area</strong></p>
|
102
|
-
<p>This is where your application content would go.</p>
|
103
|
-
<p>The window is fully draggable and has working minimize, maximize, and close buttons.</p>
|
104
|
-
</div>
|
141
|
+
{window.content}
|
105
142
|
</div>
|
106
143
|
</Window>
|
107
144
|
))}
|
@@ -123,6 +160,8 @@ export const DesktopTaskbar = () => {
|
|
123
160
|
closeWindow
|
124
161
|
} = useWindows()
|
125
162
|
|
163
|
+
const { open: openApplicationMenu } = useApplicationMenu()
|
164
|
+
|
126
165
|
const handleCreateWindow = () => {
|
127
166
|
const windowTypes = [
|
128
167
|
{ title: 'File Explorer', icon: '📁', size: { width: 600, height: 400 } },
|
@@ -182,34 +221,57 @@ export const DesktopTaskbar = () => {
|
|
182
221
|
|
183
222
|
return (
|
184
223
|
<div style={{
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
224
|
+
position: 'absolute',
|
225
|
+
bottom: 0,
|
226
|
+
left: 0,
|
227
|
+
right: 0,
|
228
|
+
height: '50px',
|
229
|
+
background: 'rgba(0,0,0,0.8)',
|
230
|
+
display: 'flex',
|
231
|
+
alignItems: 'center',
|
232
|
+
padding: '0 16px',
|
233
|
+
gap: '8px'
|
234
|
+
}}>
|
235
|
+
{/* Start button */}
|
236
|
+
<button
|
237
|
+
onClick={openApplicationMenu}
|
238
|
+
style={{
|
239
|
+
padding: '8px 16px',
|
240
|
+
background: '#1976d2',
|
241
|
+
color: 'white',
|
242
|
+
border: 'none',
|
243
|
+
borderRadius: '4px',
|
244
|
+
cursor: 'pointer',
|
245
|
+
fontSize: '14px',
|
246
|
+
fontWeight: 'bold',
|
247
|
+
flexShrink: 0,
|
248
|
+
display: 'flex',
|
249
|
+
alignItems: 'center',
|
250
|
+
gap: '6px'
|
251
|
+
}}
|
252
|
+
title="Open application menu"
|
253
|
+
>
|
254
|
+
<span style={{ fontSize: '16px' }}>🚀</span>
|
255
|
+
Start
|
256
|
+
</button>
|
257
|
+
|
258
|
+
{/* Create window button (for testing) */}
|
259
|
+
<button
|
260
|
+
onClick={handleCreateWindow}
|
261
|
+
style={{
|
262
|
+
padding: '8px 12px',
|
263
|
+
background: '#666',
|
264
|
+
color: 'white',
|
265
|
+
border: 'none',
|
266
|
+
borderRadius: '4px',
|
267
|
+
cursor: 'pointer',
|
268
|
+
fontSize: '12px',
|
269
|
+
flexShrink: 0
|
270
|
+
}}
|
271
|
+
title="Create random window (for testing)"
|
272
|
+
>
|
273
|
+
+
|
274
|
+
</button>
|
213
275
|
|
214
276
|
{/* Separator */}
|
215
277
|
<div style={{
|
@@ -303,9 +365,11 @@ export const DesktopTaskbar = () => {
|
|
303
365
|
}
|
304
366
|
|
305
367
|
/**
|
306
|
-
*
|
368
|
+
* Internal Desktop component that uses the contexts
|
307
369
|
*/
|
308
|
-
|
370
|
+
const DesktopInternal = ({ desktopSize, children, ...props }) => {
|
371
|
+
const { isOpen, close } = useApplicationMenu()
|
372
|
+
|
309
373
|
return (
|
310
374
|
<WindowProvider desktopSize={desktopSize}>
|
311
375
|
<DesktopLayout {...props}>
|
@@ -313,7 +377,24 @@ export const Desktop = ({ desktopSize, children, ...props }) => {
|
|
313
377
|
{children}
|
314
378
|
</Workspace>
|
315
379
|
<DesktopTaskbar />
|
380
|
+
<ApplicationMenu
|
381
|
+
isOpen={isOpen}
|
382
|
+
onClose={close}
|
383
|
+
/>
|
316
384
|
</DesktopLayout>
|
317
385
|
</WindowProvider>
|
318
386
|
)
|
319
387
|
}
|
388
|
+
|
389
|
+
/**
|
390
|
+
* Main Desktop component with AppProvider wrapper
|
391
|
+
*/
|
392
|
+
export const Desktop = ({ desktopSize, children, ...props }) => {
|
393
|
+
return (
|
394
|
+
<AppProvider>
|
395
|
+
<DesktopInternal desktopSize={desktopSize} {...props}>
|
396
|
+
{children}
|
397
|
+
</DesktopInternal>
|
398
|
+
</AppProvider>
|
399
|
+
)
|
400
|
+
}
|
package/src/desktop/index.js
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
// Desktop Components - Window management system for web applications
|
2
|
-
export { Desktop, Workspace, DesktopTaskbar } from './desktop'
|
2
|
+
export { Desktop, Workspace, DesktopTaskbar, AppProvider, useApplicationMenu, useAppManager } from './desktop'
|
3
3
|
export { Window } from './window'
|
4
|
+
export { ApplicationMenu } from './ApplicationMenu'
|
5
|
+
|
6
|
+
// Application Management
|
7
|
+
export { AppManager, defaultAppManager } from './AppManager'
|
4
8
|
|
5
9
|
// Window Management
|
6
10
|
export { WindowManager } from './WindowManager'
|
@@ -0,0 +1,361 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Desktop, AppProvider, AppManager, defaultAppManager, useApplicationMenu, useAppManager } from '../desktop'
|
3
|
+
|
4
|
+
// Example custom components for applications
|
5
|
+
const TextEditorComponent = () => (
|
6
|
+
<div style={{ padding: '20px', height: '100%', display: 'flex', flexDirection: 'column' }}>
|
7
|
+
<div style={{ marginBottom: '10px', display: 'flex', gap: '10px' }}>
|
8
|
+
<button style={{ padding: '5px 10px', fontSize: '12px' }}>New</button>
|
9
|
+
<button style={{ padding: '5px 10px', fontSize: '12px' }}>Open</button>
|
10
|
+
<button style={{ padding: '5px 10px', fontSize: '12px' }}>Save</button>
|
11
|
+
</div>
|
12
|
+
<textarea
|
13
|
+
style={{
|
14
|
+
flex: 1,
|
15
|
+
border: '1px solid #ccc',
|
16
|
+
padding: '10px',
|
17
|
+
fontFamily: 'monospace',
|
18
|
+
fontSize: '14px',
|
19
|
+
resize: 'none'
|
20
|
+
}}
|
21
|
+
placeholder="Start typing your text here..."
|
22
|
+
defaultValue="Welcome to the Text Editor!\n\nThis is a simple text editor application launched from the Application Menu."
|
23
|
+
/>
|
24
|
+
</div>
|
25
|
+
)
|
26
|
+
|
27
|
+
const CalculatorComponent = () => {
|
28
|
+
const [display, setDisplay] = React.useState('0')
|
29
|
+
const [previousValue, setPreviousValue] = React.useState(null)
|
30
|
+
const [operation, setOperation] = React.useState(null)
|
31
|
+
const [waitingForOperand, setWaitingForOperand] = React.useState(false)
|
32
|
+
|
33
|
+
const inputNumber = (num) => {
|
34
|
+
if (waitingForOperand) {
|
35
|
+
setDisplay(String(num))
|
36
|
+
setWaitingForOperand(false)
|
37
|
+
} else {
|
38
|
+
setDisplay(display === '0' ? String(num) : display + num)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
const inputOperation = (nextOperation) => {
|
43
|
+
const inputValue = parseFloat(display)
|
44
|
+
|
45
|
+
if (previousValue === null) {
|
46
|
+
setPreviousValue(inputValue)
|
47
|
+
} else if (operation) {
|
48
|
+
const currentValue = previousValue || 0
|
49
|
+
const newValue = calculate(currentValue, inputValue, operation)
|
50
|
+
|
51
|
+
setDisplay(String(newValue))
|
52
|
+
setPreviousValue(newValue)
|
53
|
+
}
|
54
|
+
|
55
|
+
setWaitingForOperand(true)
|
56
|
+
setOperation(nextOperation)
|
57
|
+
}
|
58
|
+
|
59
|
+
const calculate = (firstValue, secondValue, operation) => {
|
60
|
+
switch (operation) {
|
61
|
+
case '+': return firstValue + secondValue
|
62
|
+
case '-': return firstValue - secondValue
|
63
|
+
case '×': return firstValue * secondValue
|
64
|
+
case '÷': return firstValue / secondValue
|
65
|
+
case '=': return secondValue
|
66
|
+
default: return secondValue
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
const performCalculation = () => {
|
71
|
+
const inputValue = parseFloat(display)
|
72
|
+
|
73
|
+
if (previousValue !== null && operation) {
|
74
|
+
const newValue = calculate(previousValue, inputValue, operation)
|
75
|
+
setDisplay(String(newValue))
|
76
|
+
setPreviousValue(null)
|
77
|
+
setOperation(null)
|
78
|
+
setWaitingForOperand(true)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
const clear = () => {
|
83
|
+
setDisplay('0')
|
84
|
+
setPreviousValue(null)
|
85
|
+
setOperation(null)
|
86
|
+
setWaitingForOperand(false)
|
87
|
+
}
|
88
|
+
|
89
|
+
const buttonStyle = {
|
90
|
+
padding: '15px',
|
91
|
+
margin: '2px',
|
92
|
+
border: 'none',
|
93
|
+
borderRadius: '4px',
|
94
|
+
cursor: 'pointer',
|
95
|
+
fontSize: '16px',
|
96
|
+
fontWeight: 'bold'
|
97
|
+
}
|
98
|
+
|
99
|
+
return (
|
100
|
+
<div style={{ padding: '20px', maxWidth: '250px' }}>
|
101
|
+
<div style={{
|
102
|
+
background: '#000',
|
103
|
+
color: '#fff',
|
104
|
+
padding: '15px',
|
105
|
+
textAlign: 'right',
|
106
|
+
fontSize: '24px',
|
107
|
+
marginBottom: '10px',
|
108
|
+
borderRadius: '4px',
|
109
|
+
minHeight: '40px',
|
110
|
+
display: 'flex',
|
111
|
+
alignItems: 'center',
|
112
|
+
justifyContent: 'flex-end'
|
113
|
+
}}>
|
114
|
+
{display}
|
115
|
+
</div>
|
116
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: '2px' }}>
|
117
|
+
<button style={{...buttonStyle, background: '#f0f0f0'}} onClick={clear}>C</button>
|
118
|
+
<button style={{...buttonStyle, background: '#f0f0f0'}} onClick={() => {}}>±</button>
|
119
|
+
<button style={{...buttonStyle, background: '#f0f0f0'}} onClick={() => {}}>%</button>
|
120
|
+
<button style={{...buttonStyle, background: '#ff9500', color: 'white'}} onClick={() => inputOperation('÷')}>÷</button>
|
121
|
+
|
122
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(7)}>7</button>
|
123
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(8)}>8</button>
|
124
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(9)}>9</button>
|
125
|
+
<button style={{...buttonStyle, background: '#ff9500', color: 'white'}} onClick={() => inputOperation('×')}>×</button>
|
126
|
+
|
127
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(4)}>4</button>
|
128
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(5)}>5</button>
|
129
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(6)}>6</button>
|
130
|
+
<button style={{...buttonStyle, background: '#ff9500', color: 'white'}} onClick={() => inputOperation('-')}>-</button>
|
131
|
+
|
132
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(1)}>1</button>
|
133
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(2)}>2</button>
|
134
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => inputNumber(3)}>3</button>
|
135
|
+
<button style={{...buttonStyle, background: '#ff9500', color: 'white'}} onClick={() => inputOperation('+')}>+</button>
|
136
|
+
|
137
|
+
<button style={{...buttonStyle, background: '#333', color: 'white', gridColumn: 'span 2'}} onClick={() => inputNumber(0)}>0</button>
|
138
|
+
<button style={{...buttonStyle, background: '#333', color: 'white'}} onClick={() => {}}>.</button>
|
139
|
+
<button style={{...buttonStyle, background: '#ff9500', color: 'white'}} onClick={performCalculation}>=</button>
|
140
|
+
</div>
|
141
|
+
</div>
|
142
|
+
)
|
143
|
+
}
|
144
|
+
|
145
|
+
// Register custom applications with components
|
146
|
+
const setupCustomApps = () => {
|
147
|
+
// Register Text Editor with actual component
|
148
|
+
defaultAppManager.registerApp({
|
149
|
+
id: 'text-editor-custom',
|
150
|
+
name: 'Advanced Text Editor',
|
151
|
+
description: 'Full-featured text editor with toolbar',
|
152
|
+
icon: '📝',
|
153
|
+
category: 'Productivity',
|
154
|
+
component: <TextEditorComponent />,
|
155
|
+
size: { width: 600, height: 400 }
|
156
|
+
})
|
157
|
+
|
158
|
+
// Register Calculator with actual component
|
159
|
+
defaultAppManager.registerApp({
|
160
|
+
id: 'calculator-custom',
|
161
|
+
name: 'Calculator Pro',
|
162
|
+
description: 'Advanced calculator with full functionality',
|
163
|
+
icon: '🧮',
|
164
|
+
category: 'Utilities',
|
165
|
+
component: <CalculatorComponent />,
|
166
|
+
size: { width: 300, height: 450 }
|
167
|
+
})
|
168
|
+
|
169
|
+
// Register a custom dashboard app
|
170
|
+
defaultAppManager.registerApp({
|
171
|
+
id: 'dashboard',
|
172
|
+
name: 'Dashboard',
|
173
|
+
description: 'System monitoring dashboard',
|
174
|
+
icon: '📊',
|
175
|
+
category: 'System',
|
176
|
+
component: (
|
177
|
+
<div style={{ padding: '20px' }}>
|
178
|
+
<h2>System Dashboard</h2>
|
179
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px', marginTop: '20px' }}>
|
180
|
+
<div style={{ padding: '15px', background: '#e3f2fd', borderRadius: '8px' }}>
|
181
|
+
<h4>CPU Usage</h4>
|
182
|
+
<div style={{ fontSize: '24px', fontWeight: 'bold', color: '#1976d2' }}>45%</div>
|
183
|
+
</div>
|
184
|
+
<div style={{ padding: '15px', background: '#e8f5e8', borderRadius: '8px' }}>
|
185
|
+
<h4>Memory</h4>
|
186
|
+
<div style={{ fontSize: '24px', fontWeight: 'bold', color: '#388e3c' }}>2.1GB</div>
|
187
|
+
</div>
|
188
|
+
<div style={{ padding: '15px', background: '#fff3e0', borderRadius: '8px' }}>
|
189
|
+
<h4>Disk Space</h4>
|
190
|
+
<div style={{ fontSize: '24px', fontWeight: 'bold', color: '#f57c00' }}>78%</div>
|
191
|
+
</div>
|
192
|
+
<div style={{ padding: '15px', background: '#fce4ec', borderRadius: '8px' }}>
|
193
|
+
<h4>Network</h4>
|
194
|
+
<div style={{ fontSize: '24px', fontWeight: 'bold', color: '#c2185b' }}>125 MB/s</div>
|
195
|
+
</div>
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
),
|
199
|
+
size: { width: 500, height: 400 }
|
200
|
+
})
|
201
|
+
}
|
202
|
+
|
203
|
+
// Component that demonstrates using both AppProvider hooks
|
204
|
+
const DemoControls = () => {
|
205
|
+
const { isOpen, open, close, toggle } = useApplicationMenu()
|
206
|
+
const appManager = useAppManager()
|
207
|
+
const [appCount, setAppCount] = React.useState(0)
|
208
|
+
|
209
|
+
React.useEffect(() => {
|
210
|
+
const updateCount = () => setAppCount(appManager.getAllApps().length)
|
211
|
+
updateCount()
|
212
|
+
appManager.addListener(updateCount)
|
213
|
+
return () => appManager.removeListener(updateCount)
|
214
|
+
}, [appManager])
|
215
|
+
|
216
|
+
const addCustomApp = () => {
|
217
|
+
const randomId = `custom-app-${Date.now()}`
|
218
|
+
appManager.registerApp({
|
219
|
+
id: randomId,
|
220
|
+
name: `Custom App ${Math.floor(Math.random() * 100)}`,
|
221
|
+
description: 'Dynamically added application',
|
222
|
+
icon: ['🎨', '🎯', '🎪', '🎭', '🎨'][Math.floor(Math.random() * 5)],
|
223
|
+
category: 'Custom',
|
224
|
+
component: (
|
225
|
+
<div style={{ padding: '20px', textAlign: 'center' }}>
|
226
|
+
<h2>Dynamic App</h2>
|
227
|
+
<p>This app was added dynamically using AppManager!</p>
|
228
|
+
<p>ID: {randomId}</p>
|
229
|
+
</div>
|
230
|
+
),
|
231
|
+
size: { width: 400, height: 300 }
|
232
|
+
})
|
233
|
+
}
|
234
|
+
|
235
|
+
return (
|
236
|
+
<div style={{
|
237
|
+
position: 'absolute',
|
238
|
+
top: '20px',
|
239
|
+
right: '20px',
|
240
|
+
background: 'rgba(255,255,255,0.9)',
|
241
|
+
padding: '20px',
|
242
|
+
borderRadius: '8px',
|
243
|
+
boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
|
244
|
+
maxWidth: '300px'
|
245
|
+
}}>
|
246
|
+
<h4 style={{ margin: '0 0 15px 0' }}>🎮 App Controls</h4>
|
247
|
+
<p style={{ margin: '0 0 10px 0', fontSize: '14px', color: '#666' }}>
|
248
|
+
Menu: <strong>{isOpen ? 'Open' : 'Closed'}</strong><br/>
|
249
|
+
Apps: <strong>{appCount}</strong>
|
250
|
+
</p>
|
251
|
+
|
252
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
253
|
+
<button
|
254
|
+
onClick={open}
|
255
|
+
style={{
|
256
|
+
padding: '8px 12px',
|
257
|
+
background: '#4caf50',
|
258
|
+
color: 'white',
|
259
|
+
border: 'none',
|
260
|
+
borderRadius: '4px',
|
261
|
+
cursor: 'pointer',
|
262
|
+
fontSize: '12px'
|
263
|
+
}}
|
264
|
+
>
|
265
|
+
Open Menu
|
266
|
+
</button>
|
267
|
+
<button
|
268
|
+
onClick={close}
|
269
|
+
style={{
|
270
|
+
padding: '8px 12px',
|
271
|
+
background: '#f44336',
|
272
|
+
color: 'white',
|
273
|
+
border: 'none',
|
274
|
+
borderRadius: '4px',
|
275
|
+
cursor: 'pointer',
|
276
|
+
fontSize: '12px'
|
277
|
+
}}
|
278
|
+
>
|
279
|
+
Close Menu
|
280
|
+
</button>
|
281
|
+
<button
|
282
|
+
onClick={toggle}
|
283
|
+
style={{
|
284
|
+
padding: '8px 12px',
|
285
|
+
background: '#2196f3',
|
286
|
+
color: 'white',
|
287
|
+
border: 'none',
|
288
|
+
borderRadius: '4px',
|
289
|
+
cursor: 'pointer',
|
290
|
+
fontSize: '12px'
|
291
|
+
}}
|
292
|
+
>
|
293
|
+
Toggle Menu
|
294
|
+
</button>
|
295
|
+
<hr style={{ margin: '10px 0', border: 'none', borderTop: '1px solid #eee' }} />
|
296
|
+
<button
|
297
|
+
onClick={addCustomApp}
|
298
|
+
style={{
|
299
|
+
padding: '8px 12px',
|
300
|
+
background: '#ff9800',
|
301
|
+
color: 'white',
|
302
|
+
border: 'none',
|
303
|
+
borderRadius: '4px',
|
304
|
+
cursor: 'pointer',
|
305
|
+
fontSize: '12px'
|
306
|
+
}}
|
307
|
+
>
|
308
|
+
Add Custom App
|
309
|
+
</button>
|
310
|
+
</div>
|
311
|
+
</div>
|
312
|
+
)
|
313
|
+
}
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Example component demonstrating the ApplicationMenu system
|
317
|
+
*/
|
318
|
+
export const ApplicationMenuExample = () => {
|
319
|
+
React.useEffect(() => {
|
320
|
+
setupCustomApps()
|
321
|
+
}, [])
|
322
|
+
|
323
|
+
return (
|
324
|
+
<div style={{ height: '100vh', position: 'relative', backgroundColor: '#f0f0f0' }}>
|
325
|
+
<Desktop desktopSize={{ width: 1200, height: 800 }}>
|
326
|
+
{/* Desktop background content */}
|
327
|
+
<div style={{
|
328
|
+
position: 'absolute',
|
329
|
+
top: '20px',
|
330
|
+
left: '20px',
|
331
|
+
background: 'rgba(255,255,255,0.9)',
|
332
|
+
padding: '20px',
|
333
|
+
borderRadius: '8px',
|
334
|
+
boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
|
335
|
+
maxWidth: '400px'
|
336
|
+
}}>
|
337
|
+
<h3 style={{ margin: '0 0 15px 0' }}>🚀 AppProvider + AppManager Demo</h3>
|
338
|
+
<p style={{ margin: '0 0 15px 0', lineHeight: '1.5' }}>
|
339
|
+
AppProvider and AppManager now collaborate seamlessly. The ApplicationMenu gets apps
|
340
|
+
from AppManager through the context. Try adding custom apps dynamically!
|
341
|
+
</p>
|
342
|
+
<div style={{ fontSize: '14px', color: '#666' }}>
|
343
|
+
<p><strong>Collaboration Features:</strong></p>
|
344
|
+
<ul style={{ margin: '5px 0', paddingLeft: '20px' }}>
|
345
|
+
<li>AppProvider provides AppManager via context</li>
|
346
|
+
<li>ApplicationMenu uses useAppManager() hook</li>
|
347
|
+
<li>Dynamic app registration and updates</li>
|
348
|
+
<li>Real-time app count updates</li>
|
349
|
+
<li>Clean separation of concerns</li>
|
350
|
+
</ul>
|
351
|
+
</div>
|
352
|
+
</div>
|
353
|
+
|
354
|
+
{/* Demo controls using the hook */}
|
355
|
+
<DemoControls />
|
356
|
+
</Desktop>
|
357
|
+
</div>
|
358
|
+
)
|
359
|
+
}
|
360
|
+
|
361
|
+
export default ApplicationMenuExample
|