@blocklet/ui-react 3.1.48 → 3.1.50

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 (98) hide show
  1. package/.aigne/doc-smith/config.yaml +76 -0
  2. package/.aigne/doc-smith/history.yaml +9 -0
  3. package/.aigne/doc-smith/output/structure-plan.json +249 -0
  4. package/.aigne/doc-smith/upload-cache.yaml +528 -0
  5. package/docs/_sidebar.md +19 -0
  6. package/docs/components-component-management-blocklet-studio.ja.md +194 -0
  7. package/docs/components-component-management-blocklet-studio.md +194 -0
  8. package/docs/components-component-management-blocklet-studio.zh-TW.md +194 -0
  9. package/docs/components-component-management-blocklet-studio.zh.md +194 -0
  10. package/docs/components-component-management-component-installer.ja.md +256 -0
  11. package/docs/components-component-management-component-installer.md +256 -0
  12. package/docs/components-component-management-component-installer.zh-TW.md +256 -0
  13. package/docs/components-component-management-component-installer.zh.md +256 -0
  14. package/docs/components-component-management.ja.md +59 -0
  15. package/docs/components-component-management.md +59 -0
  16. package/docs/components-component-management.zh-TW.md +59 -0
  17. package/docs/components-component-management.zh.md +59 -0
  18. package/docs/components-layout-dashboard.ja.md +231 -0
  19. package/docs/components-layout-dashboard.md +231 -0
  20. package/docs/components-layout-dashboard.zh-TW.md +231 -0
  21. package/docs/components-layout-dashboard.zh.md +231 -0
  22. package/docs/components-layout-footer.ja.md +165 -0
  23. package/docs/components-layout-footer.md +165 -0
  24. package/docs/components-layout-footer.zh-TW.md +165 -0
  25. package/docs/components-layout-footer.zh.md +165 -0
  26. package/docs/components-layout-header.ja.md +233 -0
  27. package/docs/components-layout-header.md +233 -0
  28. package/docs/components-layout-header.zh-TW.md +233 -0
  29. package/docs/components-layout-header.zh.md +233 -0
  30. package/docs/components-layout.ja.md +50 -0
  31. package/docs/components-layout.md +50 -0
  32. package/docs/components-layout.zh-TW.md +50 -0
  33. package/docs/components-layout.zh.md +50 -0
  34. package/docs/components-notifications.ja.md +173 -0
  35. package/docs/components-notifications.md +173 -0
  36. package/docs/components-notifications.zh-TW.md +174 -0
  37. package/docs/components-notifications.zh.md +173 -0
  38. package/docs/components-user-management-user-center.ja.md +183 -0
  39. package/docs/components-user-management-user-center.md +183 -0
  40. package/docs/components-user-management-user-center.zh-TW.md +183 -0
  41. package/docs/components-user-management-user-center.zh.md +183 -0
  42. package/docs/components-user-management-user-sessions.ja.md +164 -0
  43. package/docs/components-user-management-user-sessions.md +164 -0
  44. package/docs/components-user-management-user-sessions.zh-TW.md +164 -0
  45. package/docs/components-user-management-user-sessions.zh.md +164 -0
  46. package/docs/components-user-management.ja.md +76 -0
  47. package/docs/components-user-management.md +76 -0
  48. package/docs/components-user-management.zh-TW.md +76 -0
  49. package/docs/components-user-management.zh.md +76 -0
  50. package/docs/components-utilities-icon.ja.md +106 -0
  51. package/docs/components-utilities-icon.md +106 -0
  52. package/docs/components-utilities-icon.zh-TW.md +106 -0
  53. package/docs/components-utilities-icon.zh.md +106 -0
  54. package/docs/components-utilities.ja.md +136 -0
  55. package/docs/components-utilities.md +136 -0
  56. package/docs/components-utilities.zh-TW.md +136 -0
  57. package/docs/components-utilities.zh.md +136 -0
  58. package/docs/components.ja.md +27 -0
  59. package/docs/components.md +27 -0
  60. package/docs/components.zh-TW.md +27 -0
  61. package/docs/components.zh.md +27 -0
  62. package/docs/core-concepts.ja.md +164 -0
  63. package/docs/core-concepts.md +164 -0
  64. package/docs/core-concepts.zh-TW.md +164 -0
  65. package/docs/core-concepts.zh.md +164 -0
  66. package/docs/getting-started.ja.md +132 -0
  67. package/docs/getting-started.md +132 -0
  68. package/docs/getting-started.zh-TW.md +132 -0
  69. package/docs/getting-started.zh.md +132 -0
  70. package/docs/hooks-api.ja.md +214 -0
  71. package/docs/hooks-api.md +214 -0
  72. package/docs/hooks-api.zh-TW.md +214 -0
  73. package/docs/hooks-api.zh.md +214 -0
  74. package/docs/how-to-guides.ja.md +413 -0
  75. package/docs/how-to-guides.md +413 -0
  76. package/docs/how-to-guides.zh-TW.md +413 -0
  77. package/docs/how-to-guides.zh.md +413 -0
  78. package/docs/overview.ja.md +91 -0
  79. package/docs/overview.md +91 -0
  80. package/docs/overview.zh-TW.md +91 -0
  81. package/docs/overview.zh.md +91 -0
  82. package/glossary.md +12 -0
  83. package/lib/Dashboard/index.js +46 -42
  84. package/lib/Footer/index.js +51 -36
  85. package/lib/Header/index.js +48 -44
  86. package/lib/UserCenter/components/settings.js +1 -0
  87. package/lib/UserCenter/components/user-center.js +133 -133
  88. package/lib/blocklets.d.ts +13 -2
  89. package/lib/blocklets.js +40 -40
  90. package/lib/common/header-addons.js +37 -33
  91. package/package.json +7 -7
  92. package/src/Dashboard/index.jsx +8 -3
  93. package/src/Footer/index.jsx +22 -4
  94. package/src/Header/index.tsx +7 -2
  95. package/src/UserCenter/components/settings.tsx +1 -0
  96. package/src/UserCenter/components/user-center.tsx +6 -6
  97. package/src/blocklets.js +18 -9
  98. package/src/common/header-addons.jsx +7 -2
@@ -0,0 +1,413 @@
1
+ # How-to Guides
2
+
3
+ This section provides practical, step-by-step guides for completing common tasks and implementing specific workflows using the library's components. Each guide is designed to be a self-contained set of instructions to help you achieve a specific outcome efficiently.
4
+
5
+ <x-cards data-columns="2">
6
+ <x-card data-title="Add Custom Elements to the Header" data-icon="lucide:layout-template" data-href="#how-to-add-custom-elements-to-the-header">
7
+ Learn how to use the `addons` render prop to extend the `Header` component with custom buttons, navigation, or other interactive elements.
8
+ </x-card>
9
+ <x-card data-title="Handle Optional Component Dependencies" data-icon="lucide:puzzle" data-href="#how-to-handle-optional-component-dependencies">
10
+ Implement a workflow that prompts administrators to install required components on-demand, ensuring your blocklet's features run smoothly.
11
+ </x-card>
12
+ <x-card data-title="Implement Real-time User Notifications" data-icon="lucide:bell-ring" data-href="#how-to-implement-real-time-user-notifications">
13
+ Set up a real-time notification system using WebSockets to keep users informed of important events within your application.
14
+ </x-card>
15
+ <x-card data-title="Publish Resources with BlockletStudio" data-icon="lucide:rocket" data-href="#how-to-publish-resources-with-blockletstudio">
16
+ Integrate the `BlockletStudio` component to provide a user interface for publishing and managing resources and dependent components.
17
+ </x-card>
18
+ </x-cards>
19
+
20
+ ---
21
+
22
+ ## How to Add Custom Elements to the Header
23
+
24
+ The `Header` component is designed to be extensible. You can add custom buttons, search bars, or other React components directly into the header by leveraging the `addons` prop.
25
+
26
+ ### Goal
27
+
28
+ To add a custom "Chat" button, a search input, and additional action icons to the main application header.
29
+
30
+ ### Prerequisites
31
+
32
+ - A functional React application with the `@arcblock/ux` library installed.
33
+ - An existing `<Header>` component instance. For more information, see the [Header component documentation](./components-layout-header.md).
34
+
35
+ ### Steps
36
+
37
+ The `addons` prop accepts a render function. This function receives the default addons (like the session manager) as its first argument, allowing you to decide where to place your custom elements relative to the defaults.
38
+
39
+ 1. **Define the `addons` Render Prop**
40
+
41
+ In your `Header` component, pass a function to the `addons` prop. This function should return the JSX you want to render.
42
+
43
+ ```jsx
44
+ <Header
45
+ meta={meta}
46
+ addons={(defaultAddons, { navigation }) => {
47
+ // Your custom components will go here
48
+ return (
49
+ <>
50
+ {/* Render your custom components */}
51
+ {defaultAddons}
52
+ </>
53
+ );
54
+ }}
55
+ />
56
+ ```
57
+
58
+ 2. **Add Custom Components**
59
+
60
+ Inside the render function, you can add any components you need. In this example, we'll add a standard Material-UI `Button`, a few `AddonButton` components for icons, and a `Divider`.
61
+
62
+ 3. **Combine with Default Addons**
63
+
64
+ It is standard practice to render the `defaultAddons` that are passed into the function. This ensures that essential elements like the locale switcher and session manager are still displayed. You can place your custom components before or after the `defaultAddons`.
65
+
66
+ ### Complete Example
67
+
68
+ Here is a complete example demonstrating how to add several custom elements to the header. This includes navigation, buttons, and icons, rendered alongside the default session manager.
69
+
70
+ ```javascript How to Add Custom Elements to the Header icon=logos:react
71
+ import { Box, Divider, Button } from '@mui/material';
72
+ import { SessionContext } from '@arcblock/did-connect-react/lib/Session';
73
+ import { AddonButton } from '@arcblock/ux/lib/Header/addon-button';
74
+ import NavMenu from '@arcblock/ux/lib/NavMenu';
75
+ import SessionManager from '@arcblock/ux/lib/SessionManager';
76
+ import Header from '@arcblock/ux/lib/Header';
77
+ import { Icon } from '@iconify/react';
78
+
79
+ // Mock data for demonstration purposes
80
+ const mockBlockletMeta = {
81
+ title: 'My App',
82
+ description: 'A great application',
83
+ logoUrl: 'https://www.arcblock.io/image-bin/uploads/eb1cf5d60cd85c42362920c49e3768cb.svg'
84
+ };
85
+
86
+ const mockSessionContextValue = {
87
+ session: {
88
+ user: {
89
+ fullName: 'Demo User',
90
+ did: 'z1ex...',
91
+ role: 'admin',
92
+ },
93
+ // ... other session properties
94
+ },
95
+ };
96
+
97
+ export default function CustomHeaderGuide() {
98
+ const meta = {
99
+ ...mockBlockletMeta,
100
+ enableConnect: true,
101
+ enableLocale: true,
102
+ };
103
+
104
+ return (
105
+ <SessionContext.Provider value={mockSessionContextValue}>
106
+ <Header
107
+ meta={meta}
108
+ homeLink="https://www.arcblock.io"
109
+ addons={(defaultAddons, { navigation }) => (
110
+ <>
111
+ {/* 1. Add custom navigation */}
112
+ {navigation.navItems?.length > 0 && (
113
+ <NavMenu
114
+ activeId={navigation.activeId}
115
+ items={navigation.navItems}
116
+ className="header-nav"
117
+ />
118
+ )}
119
+ {/* 2. Add a custom button */}
120
+ <Button variant="contained" color="primary" size="small">
121
+ Button
122
+ </Button>
123
+ {/* 3. Add custom icon buttons */}
124
+ <AddonButton icon={<Icon icon="tabler:message-circle" />}>Chat</AddonButton>
125
+ <AddonButton icon={<Icon icon="tabler:bell" />} />
126
+ <Divider orientation="vertical" flexItem sx={{ height: 12, alignSelf: 'center' }} />
127
+ {/* 4. Render the default addons (includes session manager) */}
128
+ {defaultAddons}
129
+ </>
130
+ )}
131
+ />
132
+ </SessionContext.Provider>
133
+ );
134
+ }
135
+ ```
136
+
137
+ ---
138
+
139
+ ## How to Handle Optional Component Dependencies
140
+
141
+ Many blocklets rely on other components to provide specific features. The `ComponentInstaller` allows you to build features that depend on optional components, and if they are not installed, it provides a user-friendly way for an administrator to install them.
142
+
143
+ ### Goal
144
+
145
+ To protect a feature that requires another blocklet component to be installed. If the component is missing, an administrator will be shown an interface to install it, while other users will see nothing.
146
+
147
+ ### Prerequisites
148
+
149
+ - A feature in your application that depends on another component (e.g., a "Media Manager" that requires the "Media Kit" blocklet).
150
+ - The DID of the component dependency.
151
+ - Familiarity with user roles (`owner`, `admin`).
152
+
153
+ ### Steps
154
+
155
+ 1. **Import `ComponentInstaller`**
156
+
157
+ First, import the component from the library.
158
+
159
+ ```javascript
160
+ import ComponentInstaller from '@arcblock/ux/lib/ComponentInstaller';
161
+ ```
162
+
163
+ 2. **Wrap Your Feature**
164
+
165
+ Wrap the component or feature that has the dependency with the `ComponentInstaller`.
166
+
167
+ 3. **Provide the Component DID**
168
+
169
+ Pass the DID of the required component to the `did` prop. This can be a single string or an array of strings if there are multiple dependencies.
170
+
171
+ 4. **Configure Behavior for Non-Admins**
172
+
173
+ Use the `noPermissionMute` prop. When set to `true`, users who do not have permission to install components (i.e., non-admins) will not see the installation prompt. You can provide a `fallback` component to show them instead.
174
+
175
+ ### Complete Example
176
+
177
+ In this scenario, we have a `MyFeatureButton` that should only be rendered if the component with DID `z8ia...` is installed.
178
+
179
+ ```javascript How to Handle Optional Component Dependencies icon=logos:react
180
+ import ComponentInstaller from '@arcblock/ux/lib/ComponentInstaller';
181
+ import { Button } from '@mui/material';
182
+
183
+ const REQUIRED_COMPONENT_DID = 'z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9'; // Example DID
184
+
185
+ // This is the component that requires the dependency
186
+ function MyFeatureButton() {
187
+ return <Button variant="contained">Use Awesome Feature</Button>;
188
+ }
189
+
190
+ export default function OptionalComponentGuide() {
191
+ return (
192
+ <ComponentInstaller
193
+ // The DID of the component to check for
194
+ did={REQUIRED_COMPONENT_DID}
195
+ // A list of roles that are allowed to see the installer UI
196
+ roles={['owner', 'admin']}
197
+ // If true, non-admins will not see the installer UI
198
+ noPermissionMute
199
+ // Optional: What to show non-admins if the component is not installed
200
+ fallback={<div>This feature is not available.</div>}
201
+ // A callback that fires after a successful installation
202
+ onInstalled={() => console.log('Component was installed successfully!')}
203
+ >
204
+ {/* This child will only be rendered if the component is already installed */}
205
+ <MyFeatureButton />
206
+ </ComponentInstaller>
207
+ );
208
+ }
209
+ ```
210
+
211
+ When an admin visits this page and the component is not installed, they will see a pop-up allowing them to install it. A regular user will see the fallback message. Once installed, all users will see the `MyFeatureButton`.
212
+
213
+ ---
214
+
215
+ ## How to Implement Real-time User Notifications
216
+
217
+ You can provide users with real-time feedback and notifications by listening to WebSocket events from the Blocklet Server. The `NotificationAddon` component is a ready-to-use solution for displaying an unread notification count in the header.
218
+
219
+ ### Goal
220
+
221
+ To add a notification bell icon to the application header that displays a badge with the count of unread notifications and updates in real-time.
222
+
223
+ ### Prerequisites
224
+
225
+ - Your blocklet must be running on a Blocklet Server version that supports the notification service (`1.16.42` or higher).
226
+ - A `<Header>` component where the notification icon will be placed.
227
+ - A session context providing user information.
228
+
229
+ ### Key Concepts
230
+
231
+ - **WebSocket Events**: The Blocklet Server broadcasts events when notifications are created or read.
232
+ - **`useListenWsClient`**: A hook to get a WebSocket client instance for a specific channel (e.g., 'user').
233
+ - **Event Naming**: Events are scoped to the user and blocklet. The format for new notifications is `${blocklet.did}/${user.did}/notification:blocklet:create`.
234
+
235
+ ### Steps
236
+
237
+ The `NotificationAddon` component encapsulates all the required logic for listening to WebSocket events and displaying the unread count.
238
+
239
+ 1. **Import `NotificationAddon`**
240
+
241
+ ```javascript
242
+ import NotificationAddon from '@arcblock/ux/lib/common/notification-addon';
243
+ ```
244
+
245
+ 2. **Add to Header `addons`**
246
+
247
+ The simplest way to use this is to add it inside the `Header`'s `addons` render prop.
248
+
249
+ 3. **Pass the Session Object**
250
+
251
+ The `NotificationAddon` component requires the `session` object to identify the current user and manage the unread count state.
252
+
253
+ ### Complete Example
254
+
255
+ This example shows how to integrate the `NotificationAddon` into the `Header`. It will automatically connect to the WebSocket, listen for events, and update the badge count.
256
+
257
+ ```javascript How to Implement Real-time User Notifications icon=logos:react
258
+ import { SessionContext } from '@arcblock/did-connect-react/lib/Session';
259
+ import Header from '@arcblock/ux/lib/Header';
260
+ import NotificationAddon from '@arcblock/ux/lib/common/notification-addon';
261
+
262
+ // Mock data for demonstration purposes
263
+ const mockBlockletMeta = {
264
+ title: 'My App',
265
+ description: 'A great application',
266
+ logoUrl: 'https://www.arcblock.io/image-bin/uploads/eb1cf5d60cd85c42362920c49e3768cb.svg'
267
+ };
268
+
269
+ const mockSessionContextValue = {
270
+ session: {
271
+ user: {
272
+ fullName: 'Demo User',
273
+ did: 'z1ex...',
274
+ role: 'admin',
275
+ },
276
+ unReadCount: 3, // Initial unread count
277
+ setUnReadCount: () => {}, // State setter function
278
+ // ... other session properties
279
+ },
280
+ };
281
+
282
+ export default function NotificationGuide() {
283
+ const meta = { ...mockBlockletMeta, enableConnect: true };
284
+
285
+ return (
286
+ <SessionContext.Provider value={mockSessionContextValue}>
287
+ <Header
288
+ meta={meta}
289
+ addons={(defaultAddons) => (
290
+ <>
291
+ {/* The NotificationAddon will handle real-time updates */}
292
+ <NotificationAddon session={mockSessionContextValue.session} />
293
+ {defaultAddons}
294
+ </>
295
+ )}
296
+ />
297
+ </SessionContext.Provider>
298
+ );
299
+ }
300
+ ```
301
+
302
+ When a new notification for the logged-in user is created, the badge count on the bell icon will automatically increment. Clicking the icon will navigate the user to their notifications page.
303
+
304
+ ---
305
+
306
+ ## How to Publish Resources with BlockletStudio
307
+
308
+ The `BlockletStudio` component provides a complete, embeddable UI for publishing resources and components. It handles user connection, resource selection, and the release process, simplifying a complex workflow into a single component.
309
+
310
+ ### Goal
311
+
312
+ To add a button that opens a dialog, allowing users to select and publish files and dependent components from the blocklet.
313
+
314
+ ### Prerequisites
315
+
316
+ - An API endpoint in your blocklet that returns a list of available resources.
317
+ - The DID of the component that provides the publishing UI (the "studio" component).
318
+
319
+ ### Steps
320
+
321
+ 1. **Import `BlockletStudio` and Manage State**
322
+
323
+ You'll need to manage the visibility of the studio dialog using component state.
324
+
325
+ ```javascript
326
+ import { useState } from 'react';
327
+ import { BlockletStudio } from '@arcblock/ux/lib/BlockletStudio';
328
+ import { Button, CircularProgress } from '@mui/material';
329
+ ```
330
+
331
+ 2. **Render the Component**
332
+
333
+ Place the `<BlockletStudio />` component in your app and control its visibility with the `open` and `setOpen` props.
334
+
335
+ 3. **Configure Essential Props**
336
+
337
+ - `componentDid`: The DID of the studio blocklet that provides the publishing service.
338
+ - `title`, `description`: Metadata for the item being published.
339
+ - `resourcesParams`: An object passed as query parameters to your resource-fetching API.
340
+ - `components`: An array of components to be pre-selected or required.
341
+ - `resources`: An object specifying which resources to pre-select.
342
+
343
+ 4. **Handle Lifecycle Events**
344
+
345
+ Use the `onOpened`, `onUploaded`, and `onReleased` callbacks to respond to events in the publishing lifecycle, such as hiding a loading spinner or showing a success message.
346
+
347
+ ### Complete Example
348
+
349
+ This example shows a button that, when clicked, opens the `BlockletStudio` dialog. It also demonstrates managing a loading state for a better user experience.
350
+
351
+ ```javascript How to Publish Resources with BlockletStudio icon=logos:react
352
+ import { useState } from 'react';
353
+ import { Button, CircularProgress } from '@mui/material';
354
+ import { BlockletStudio } from '@arcblock/ux/lib/BlockletStudio';
355
+
356
+ // The DID of the blocklet that provides the studio/publishing UI
357
+ const AI_STUDIO_COMPONENT_DID = 'z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9'; // Example DID
358
+
359
+ export default function PublisherGuide() {
360
+ const [isStudioOpen, setStudioOpen] = useState(false);
361
+ const [isOpening, setOpening] = useState(false);
362
+
363
+ const handleShowDialog = () => {
364
+ setOpening(true);
365
+ setStudioOpen(true);
366
+ };
367
+
368
+ return (
369
+ <>
370
+ <Button
371
+ variant="contained"
372
+ onClick={handleShowDialog}
373
+ disabled={isOpening}
374
+ startIcon={isOpening ? <CircularProgress size={16} /> : null}>
375
+ Publish to Studio
376
+ </Button>
377
+
378
+ <BlockletStudio
379
+ // Controls the dialog's visibility
380
+ open={isStudioOpen}
381
+ setOpen={setStudioOpen}
382
+ // Basic information for the published item
383
+ title="My Demo Project"
384
+ description="This is a project published from my blocklet."
385
+ // The DID of the studio service component
386
+ componentDid={AI_STUDIO_COMPONENT_DID}
387
+ // Parameters sent to your blocklet's resource API
388
+ resourcesParams={{ projectId: 'test-project-123' }}
389
+ // Pre-selected components
390
+ components={[
391
+ { did: 'z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ', included: true, required: true },
392
+ { did: 'z2qZyjnsRffFtn2PDnDwDHTRbAu53RpKqDtFZ', included: true, required: false },
393
+ ]}
394
+ // Pre-selected resources
395
+ resources={{
396
+ // The key is the DID of the resource provider blocklet
397
+ z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB: [
398
+ 'template-448698592710885376',
399
+ 'example-448698592710885376',
400
+ ],
401
+ }}
402
+ // Event handlers
403
+ onOpened={() => setOpening(false)}
404
+ onUploaded={() => alert('Upload complete!')}
405
+ onReleased={() => {
406
+ alert('Successfully released!');
407
+ setStudioOpen(false);
408
+ }}
409
+ />
410
+ </>
411
+ );
412
+ }
413
+ ```