@blocklet/ui-react 3.4.14 → 3.5.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.
Files changed (256) hide show
  1. package/lib/common/org-switch/use-org.d.ts +4 -4
  2. package/lib/common/ws.d.ts +22 -1
  3. package/package.json +10 -7
  4. package/.aigne/doc-smith/.local/afs-storage.sqlite3 +0 -0
  5. package/.aigne/doc-smith/config.yaml +0 -78
  6. package/.aigne/doc-smith/history.yaml +0 -14
  7. package/.aigne/doc-smith/media-description.yaml +0 -11
  8. package/.aigne/doc-smith/output/structure-plan.json +0 -255
  9. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  10. package/.aigne/doc-smith/upload-cache.yaml +0 -528
  11. package/build.config.ts +0 -24
  12. package/docs/_sidebar.md +0 -19
  13. package/docs/assets/diagram/component-installer-diagram-0.ja.jpg +0 -0
  14. package/docs/assets/diagram/component-installer-diagram-0.jpg +0 -0
  15. package/docs/assets/diagram/component-installer-diagram-0.zh-TW.jpg +0 -0
  16. package/docs/assets/diagram/component-installer-diagram-0.zh.jpg +0 -0
  17. package/docs/assets/diagram/component-management-diagram-0.ja.jpg +0 -0
  18. package/docs/assets/diagram/component-management-diagram-0.jpg +0 -0
  19. package/docs/assets/diagram/component-management-diagram-0.zh-TW.jpg +0 -0
  20. package/docs/assets/diagram/component-management-diagram-0.zh.jpg +0 -0
  21. package/docs/assets/diagram/core-concepts-diagram-0.ja.jpg +0 -0
  22. package/docs/assets/diagram/core-concepts-diagram-0.jpg +0 -0
  23. package/docs/assets/diagram/core-concepts-diagram-0.zh-TW.jpg +0 -0
  24. package/docs/assets/diagram/core-concepts-diagram-0.zh.jpg +0 -0
  25. package/docs/assets/diagram/dashboard-diagram-0.ja.jpg +0 -0
  26. package/docs/assets/diagram/dashboard-diagram-0.jpg +0 -0
  27. package/docs/assets/diagram/dashboard-diagram-0.zh-TW.jpg +0 -0
  28. package/docs/assets/diagram/dashboard-diagram-0.zh.jpg +0 -0
  29. package/docs/assets/diagram/header-diagram-0.ja.jpg +0 -0
  30. package/docs/assets/diagram/header-diagram-0.jpg +0 -0
  31. package/docs/assets/diagram/header-diagram-0.zh-TW.jpg +0 -0
  32. package/docs/assets/diagram/header-diagram-0.zh.jpg +0 -0
  33. package/docs/assets/diagram/layout-diagram-0.ja.jpg +0 -0
  34. package/docs/assets/diagram/layout-diagram-0.jpg +0 -0
  35. package/docs/assets/diagram/layout-diagram-0.zh-TW.jpg +0 -0
  36. package/docs/assets/diagram/layout-diagram-0.zh.jpg +0 -0
  37. package/docs/assets/diagram/notifications-diagram-0.ja.jpg +0 -0
  38. package/docs/assets/diagram/notifications-diagram-0.jpg +0 -0
  39. package/docs/assets/diagram/notifications-diagram-0.zh-TW.jpg +0 -0
  40. package/docs/assets/diagram/notifications-diagram-0.zh.jpg +0 -0
  41. package/docs/assets/diagram/overview-diagram-0.ja.jpg +0 -0
  42. package/docs/assets/diagram/overview-diagram-0.jpg +0 -0
  43. package/docs/assets/diagram/overview-diagram-0.zh-TW.jpg +0 -0
  44. package/docs/assets/diagram/overview-diagram-0.zh.jpg +0 -0
  45. package/docs/assets/diagram/user-center-diagram-0.ja.jpg +0 -0
  46. package/docs/assets/diagram/user-center-diagram-0.jpg +0 -0
  47. package/docs/assets/diagram/user-center-diagram-0.zh-TW.jpg +0 -0
  48. package/docs/assets/diagram/user-center-diagram-0.zh.jpg +0 -0
  49. package/docs/assets/diagram/user-management-diagram-0.ja.jpg +0 -0
  50. package/docs/assets/diagram/user-management-diagram-0.jpg +0 -0
  51. package/docs/assets/diagram/user-management-diagram-0.zh-TW.jpg +0 -0
  52. package/docs/assets/diagram/user-management-diagram-0.zh.jpg +0 -0
  53. package/docs/assets/diagram/user-sessions-diagram-0.ja.jpg +0 -0
  54. package/docs/assets/diagram/user-sessions-diagram-0.jpg +0 -0
  55. package/docs/assets/diagram/user-sessions-diagram-0.zh-TW.jpg +0 -0
  56. package/docs/assets/diagram/user-sessions-diagram-0.zh.jpg +0 -0
  57. package/docs/components-component-management-blocklet-studio.ja.md +0 -194
  58. package/docs/components-component-management-blocklet-studio.md +0 -194
  59. package/docs/components-component-management-blocklet-studio.zh-TW.md +0 -194
  60. package/docs/components-component-management-blocklet-studio.zh.md +0 -194
  61. package/docs/components-component-management-component-installer.ja.md +0 -182
  62. package/docs/components-component-management-component-installer.md +0 -182
  63. package/docs/components-component-management-component-installer.zh-TW.md +0 -182
  64. package/docs/components-component-management-component-installer.zh.md +0 -182
  65. package/docs/components-component-management.ja.md +0 -30
  66. package/docs/components-component-management.md +0 -30
  67. package/docs/components-component-management.zh-TW.md +0 -30
  68. package/docs/components-component-management.zh.md +0 -30
  69. package/docs/components-layout-dashboard.ja.md +0 -185
  70. package/docs/components-layout-dashboard.md +0 -187
  71. package/docs/components-layout-dashboard.zh-TW.md +0 -185
  72. package/docs/components-layout-dashboard.zh.md +0 -185
  73. package/docs/components-layout-footer.ja.md +0 -165
  74. package/docs/components-layout-footer.md +0 -165
  75. package/docs/components-layout-footer.zh-TW.md +0 -165
  76. package/docs/components-layout-footer.zh.md +0 -165
  77. package/docs/components-layout-header.ja.md +0 -183
  78. package/docs/components-layout-header.md +0 -183
  79. package/docs/components-layout-header.zh-TW.md +0 -183
  80. package/docs/components-layout-header.zh.md +0 -183
  81. package/docs/components-layout.ja.md +0 -31
  82. package/docs/components-layout.md +0 -31
  83. package/docs/components-layout.zh-TW.md +0 -31
  84. package/docs/components-layout.zh.md +0 -31
  85. package/docs/components-notifications.ja.md +0 -125
  86. package/docs/components-notifications.md +0 -125
  87. package/docs/components-notifications.zh-TW.md +0 -125
  88. package/docs/components-notifications.zh.md +0 -125
  89. package/docs/components-user-management-user-center.ja.md +0 -148
  90. package/docs/components-user-management-user-center.md +0 -147
  91. package/docs/components-user-management-user-center.zh-TW.md +0 -148
  92. package/docs/components-user-management-user-center.zh.md +0 -148
  93. package/docs/components-user-management-user-sessions.ja.md +0 -121
  94. package/docs/components-user-management-user-sessions.md +0 -123
  95. package/docs/components-user-management-user-sessions.zh-TW.md +0 -121
  96. package/docs/components-user-management-user-sessions.zh.md +0 -121
  97. package/docs/components-user-management.ja.md +0 -49
  98. package/docs/components-user-management.md +0 -51
  99. package/docs/components-user-management.zh-TW.md +0 -49
  100. package/docs/components-user-management.zh.md +0 -49
  101. package/docs/components-utilities-icon.ja.md +0 -106
  102. package/docs/components-utilities-icon.md +0 -106
  103. package/docs/components-utilities-icon.zh-TW.md +0 -106
  104. package/docs/components-utilities-icon.zh.md +0 -106
  105. package/docs/components-utilities.ja.md +0 -136
  106. package/docs/components-utilities.md +0 -136
  107. package/docs/components-utilities.zh-TW.md +0 -136
  108. package/docs/components-utilities.zh.md +0 -136
  109. package/docs/components.ja.md +0 -27
  110. package/docs/components.md +0 -27
  111. package/docs/components.zh-TW.md +0 -27
  112. package/docs/components.zh.md +0 -27
  113. package/docs/core-concepts.ja.md +0 -134
  114. package/docs/core-concepts.md +0 -135
  115. package/docs/core-concepts.zh-TW.md +0 -134
  116. package/docs/core-concepts.zh.md +0 -134
  117. package/docs/getting-started.ja.md +0 -132
  118. package/docs/getting-started.md +0 -132
  119. package/docs/getting-started.zh-TW.md +0 -132
  120. package/docs/getting-started.zh.md +0 -132
  121. package/docs/hooks-api.ja.md +0 -214
  122. package/docs/hooks-api.md +0 -214
  123. package/docs/hooks-api.zh-TW.md +0 -214
  124. package/docs/hooks-api.zh.md +0 -214
  125. package/docs/how-to-guides.ja.md +0 -413
  126. package/docs/how-to-guides.md +0 -413
  127. package/docs/how-to-guides.zh-TW.md +0 -413
  128. package/docs/how-to-guides.zh.md +0 -413
  129. package/docs/overview.ja.md +0 -51
  130. package/docs/overview.md +0 -51
  131. package/docs/overview.zh-TW.md +0 -51
  132. package/docs/overview.zh.md +0 -51
  133. package/glossary.md +0 -12
  134. package/src/@types/index.ts +0 -230
  135. package/src/@types/shims.d.ts +0 -18
  136. package/src/BlockletStudio/README.md +0 -116
  137. package/src/BlockletStudio/index.tsx +0 -145
  138. package/src/ComponentInstaller/ComponentInstaller.stories.jsx +0 -16
  139. package/src/ComponentInstaller/index.jsx +0 -207
  140. package/src/ComponentInstaller/installer-item.jsx +0 -129
  141. package/src/ComponentInstaller/locales.js +0 -22
  142. package/src/ComponentInstaller/use-component-installed.js +0 -88
  143. package/src/ComponentManager/components/add-component.tsx +0 -136
  144. package/src/ComponentManager/components/check-component.tsx +0 -3
  145. package/src/ComponentManager/components/publish-component.tsx +0 -90
  146. package/src/ComponentManager/components/resource-dialog.tsx +0 -91
  147. package/src/ComponentManager/index.tsx +0 -3
  148. package/src/ComponentManager/libs/locales.ts +0 -15
  149. package/src/Dashboard/Dashboard.stories.jsx +0 -20
  150. package/src/Dashboard/app-shell/app-badge.stories.tsx +0 -64
  151. package/src/Dashboard/app-shell/app-badge.tsx +0 -94
  152. package/src/Dashboard/app-shell/app-header.tsx +0 -104
  153. package/src/Dashboard/app-shell/app-info-context.tsx +0 -182
  154. package/src/Dashboard/app-shell/badges/app-badge-default.tsx +0 -130
  155. package/src/Dashboard/app-shell/badges/app-badge-did.tsx +0 -28
  156. package/src/Dashboard/app-shell/badges/app-badge-state.tsx +0 -40
  157. package/src/Dashboard/app-shell/badges/app-badge-switch.tsx +0 -72
  158. package/src/Dashboard/app-shell/badges/app-badge-version.tsx +0 -60
  159. package/src/Dashboard/app-shell/index.ts +0 -5
  160. package/src/Dashboard/index.jsx +0 -184
  161. package/src/Footer/Footer.stories.jsx +0 -33
  162. package/src/Footer/brand.jsx +0 -81
  163. package/src/Footer/copyright.jsx +0 -22
  164. package/src/Footer/index.jsx +0 -111
  165. package/src/Footer/internal-footer.jsx +0 -139
  166. package/src/Footer/layout/plain.jsx +0 -55
  167. package/src/Footer/layout/row.jsx +0 -43
  168. package/src/Footer/layout/standard.jsx +0 -114
  169. package/src/Footer/links.jsx +0 -321
  170. package/src/Footer/social-media.jsx +0 -55
  171. package/src/Header/Header.stories.jsx +0 -30
  172. package/src/Header/index.tsx +0 -259
  173. package/src/Icon/Icon.stories.jsx +0 -12
  174. package/src/Icon/index.tsx +0 -87
  175. package/src/Notifications/Snackbar.tsx +0 -261
  176. package/src/Notifications/hooks/use-title.tsx +0 -254
  177. package/src/Notifications/hooks/use-width.tsx +0 -16
  178. package/src/Notifications/utils.ts +0 -246
  179. package/src/UserCenter/assets/banner.png +0 -0
  180. package/src/UserCenter/components/config-inviter.tsx +0 -48
  181. package/src/UserCenter/components/config-profile.tsx +0 -99
  182. package/src/UserCenter/components/danger-zone.tsx +0 -82
  183. package/src/UserCenter/components/editable-field.tsx +0 -273
  184. package/src/UserCenter/components/fallback.tsx +0 -57
  185. package/src/UserCenter/components/nft-preview.tsx +0 -84
  186. package/src/UserCenter/components/nft.tsx +0 -279
  187. package/src/UserCenter/components/notification.tsx +0 -319
  188. package/src/UserCenter/components/passport.tsx +0 -107
  189. package/src/UserCenter/components/privacy.tsx +0 -120
  190. package/src/UserCenter/components/settings.tsx +0 -170
  191. package/src/UserCenter/components/status-dialog/date-picker.tsx +0 -77
  192. package/src/UserCenter/components/status-dialog/index.tsx +0 -293
  193. package/src/UserCenter/components/status-selector/duration-menu.tsx +0 -90
  194. package/src/UserCenter/components/status-selector/index.tsx +0 -58
  195. package/src/UserCenter/components/status-selector/menu-item.tsx +0 -56
  196. package/src/UserCenter/components/storage/action.tsx +0 -49
  197. package/src/UserCenter/components/storage/connected.tsx +0 -61
  198. package/src/UserCenter/components/storage/delete.tsx +0 -72
  199. package/src/UserCenter/components/storage/disconnect.tsx +0 -40
  200. package/src/UserCenter/components/storage/icons/empty-spaces-nft.svg +0 -1
  201. package/src/UserCenter/components/storage/icons/long-arrow.svg +0 -5
  202. package/src/UserCenter/components/storage/icons/space-connected.svg +0 -3
  203. package/src/UserCenter/components/storage/icons/space-disconnect.svg +0 -3
  204. package/src/UserCenter/components/storage/index.tsx +0 -41
  205. package/src/UserCenter/components/storage/preview-nft.tsx +0 -72
  206. package/src/UserCenter/components/third-party-login/index.tsx +0 -199
  207. package/src/UserCenter/components/third-party-login/third-party-item.tsx +0 -296
  208. package/src/UserCenter/components/user-center.tsx +0 -787
  209. package/src/UserCenter/components/user-info/address.tsx +0 -143
  210. package/src/UserCenter/components/user-info/index.tsx +0 -4
  211. package/src/UserCenter/components/user-info/link-preview-input.tsx +0 -274
  212. package/src/UserCenter/components/user-info/metadata.tsx +0 -658
  213. package/src/UserCenter/components/user-info/social-actions/chat.tsx +0 -43
  214. package/src/UserCenter/components/user-info/social-actions/follow.tsx +0 -23
  215. package/src/UserCenter/components/user-info/social-actions/index.tsx +0 -17
  216. package/src/UserCenter/components/user-info/switch-role.tsx +0 -42
  217. package/src/UserCenter/components/user-info/timezone-select.tsx +0 -119
  218. package/src/UserCenter/components/user-info/user-basic-info.tsx +0 -292
  219. package/src/UserCenter/components/user-info/user-info-item.tsx +0 -54
  220. package/src/UserCenter/components/user-info/user-info.tsx +0 -91
  221. package/src/UserCenter/components/user-info/user-status.tsx +0 -234
  222. package/src/UserCenter/components/user-info/utils.ts +0 -320
  223. package/src/UserCenter/components/webhook-item.tsx +0 -248
  224. package/src/UserCenter/index.tsx +0 -1
  225. package/src/UserCenter/libs/locales.ts +0 -378
  226. package/src/UserCenter/libs/utils.ts +0 -30
  227. package/src/UserSessions/components/user-session-info.tsx +0 -78
  228. package/src/UserSessions/components/user-sessions.tsx +0 -545
  229. package/src/UserSessions/index.tsx +0 -1
  230. package/src/UserSessions/libs/locales.ts +0 -60
  231. package/src/UserSessions/libs/utils.ts +0 -82
  232. package/src/blocklets.js +0 -195
  233. package/src/common/domain-warning.jsx +0 -178
  234. package/src/common/header-addons.jsx +0 -119
  235. package/src/common/link-blocker.jsx +0 -20
  236. package/src/common/notification-addon.jsx +0 -135
  237. package/src/common/org-switch/avatar-uploader.jsx +0 -271
  238. package/src/common/org-switch/create.jsx +0 -267
  239. package/src/common/org-switch/index.jsx +0 -407
  240. package/src/common/org-switch/locales.js +0 -52
  241. package/src/common/org-switch/use-org.jsx +0 -79
  242. package/src/common/overridable-theme-provider.jsx +0 -17
  243. package/src/common/wallet-hidden-topbar.js +0 -14
  244. package/src/common/wizard-modal.jsx +0 -200
  245. package/src/common/ws.js +0 -68
  246. package/src/contexts/config-user-space.tsx +0 -88
  247. package/src/contexts/user-followers.tsx +0 -54
  248. package/src/hooks/use-follow.tsx +0 -75
  249. package/src/hooks/use-mobile.tsx +0 -6
  250. package/src/index.ts +0 -16
  251. package/src/libs/constant.ts +0 -1
  252. package/src/libs/spaces.tsx +0 -18
  253. package/src/libs/with-hide-when-embed.tsx +0 -24
  254. package/src/types.js +0 -45
  255. package/src/utils.js +0 -161
  256. package/vite.config.mjs +0 -34
@@ -1,413 +0,0 @@
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
- ```