@abtnode/ux 1.16.16 → 1.16.17-beta-8cacb9b3

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.
@@ -26,7 +26,7 @@ import Button from '@arcblock/ux/lib/Button';
26
26
  import Alert from '@arcblock/ux/lib/Alert';
27
27
  import AnimationWaiter from '@arcblock/ux/lib/AnimationWaiter';
28
28
  import ResultMessage from '@blocklet/launcher-layout/lib/launch-result-message';
29
- import { getDisplayName, isComponentBlocklet, isFreeBlocklet, getSharedConfigObj, hasStartEngine } from '@blocklet/meta/lib/util';
29
+ import { getDisplayName, isFreeBlocklet, getSharedConfigObj, hasStartEngine } from '@blocklet/meta/lib/util';
30
30
  import urlPathFriendly from '@blocklet/meta/lib/url-path-friendly';
31
31
  import Toast from '@arcblock/ux/lib/Toast';
32
32
  import { useNodeContext } from '../../contexts/node';
@@ -714,9 +714,6 @@ export default function AddComponent({
714
714
  extraFilter: allBlocklets => {
715
715
  // only use blocklets that are component
716
716
  return allBlocklets?.filter(x => {
717
- if (!isComponentBlocklet(x)) {
718
- return false;
719
- }
720
717
  if ((blocklet.children || []).some(y => y.meta.did === x.did)) {
721
718
  return false;
722
719
  }
@@ -0,0 +1,188 @@
1
+ import { useState } from 'react';
2
+ import { Link, useNavigate } from 'react-router-dom';
3
+ import MenuItem from '@mui/material/MenuItem';
4
+ import TextField from '@mui/material/TextField';
5
+ import Typography from '@mui/material/Typography';
6
+ import Breadcrumbs from '@mui/material/Breadcrumbs';
7
+ import styled from '@emotion/styled';
8
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
9
+ import Box from '@mui/material/Box';
10
+ import Button from '@arcblock/ux/lib/Button';
11
+ import DidConnect from '@arcblock/did-connect/lib/Connect';
12
+ import Toast from '@arcblock/ux/lib/Toast';
13
+ import DidAddress from '../../did-address';
14
+ import { useNodeContext } from '../../contexts/node';
15
+ import { useBlockletContext } from '../../contexts/blocklet';
16
+ import { useSessionContext } from '../../contexts/session';
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ const Types = [{
20
+ label: {
21
+ en: 'Resource',
22
+ zh: '资源'
23
+ },
24
+ value: 'resource'
25
+ }, {
26
+ label: {
27
+ en: 'Application',
28
+ zh: '应用'
29
+ },
30
+ value: 'pack',
31
+ disabled: true
32
+ }];
33
+ export default function CreateProject({
34
+ ...rest
35
+ }) {
36
+ const navigate = useNavigate();
37
+ const {
38
+ t,
39
+ locale
40
+ } = useLocaleContext();
41
+ const {
42
+ blocklet
43
+ } = useBlockletContext();
44
+ const [blockletTitle, setBlockletTitle] = useState('');
45
+ const [loading, setLoading] = useState(false);
46
+ const [type, setType] = useState('resource'); // resource, pack
47
+ const {
48
+ api: sessionApi
49
+ } = useSessionContext();
50
+ const {
51
+ api
52
+ } = useNodeContext();
53
+ const [blockletDid, setBlockletDid] = useState();
54
+ const [openConnect, setOpenConnect] = useState(false);
55
+ const handleCreateBlockletDidError = err => {
56
+ Toast.error(err.message);
57
+ setOpenConnect(false);
58
+ };
59
+ const handleCreateBlockletDidSuccess = result => {
60
+ const did = result?.blockletWallet?.address;
61
+ if (!did) {
62
+ Toast.error('Empty Blocklet DID');
63
+ } else {
64
+ setBlockletDid(did);
65
+ }
66
+ setOpenConnect(false);
67
+ };
68
+ const onCreate = () => {
69
+ setLoading(true);
70
+ api.createProject({
71
+ input: {
72
+ did: blocklet.meta.did,
73
+ blockletTitle: blockletTitle || '',
74
+ blockletDid,
75
+ type
76
+ }
77
+ }).then(() => {
78
+ setLoading(false);
79
+ navigate('../', {
80
+ replace: true
81
+ });
82
+ }).catch(err => {
83
+ setLoading(false);
84
+ Toast.error(err.message);
85
+ });
86
+ };
87
+ return /*#__PURE__*/_jsxs(Main, {
88
+ ...rest,
89
+ children: [/*#__PURE__*/_jsxs(Breadcrumbs, {
90
+ className: "breadcrumbs",
91
+ "aria-label": "breadcrumb",
92
+ children: [/*#__PURE__*/_jsx(Link, {
93
+ to: "..",
94
+ children: t('common.publish')
95
+ }), /*#__PURE__*/_jsxs(Typography, {
96
+ color: "text.primary",
97
+ children: [t('common.create'), " Blocklet"]
98
+ })]
99
+ }), /*#__PURE__*/_jsxs(Box, {
100
+ style: {
101
+ maxWidth: 500
102
+ },
103
+ children: [/*#__PURE__*/_jsxs(Box, {
104
+ sx: {
105
+ mb: 3
106
+ },
107
+ display: "flex",
108
+ alignItems: "center",
109
+ children: [/*#__PURE__*/_jsxs(Typography, {
110
+ variant: "h6",
111
+ sx: {
112
+ mr: 3
113
+ },
114
+ children: ["Blocklet DID:", ' ']
115
+ }), blockletDid ? /*#__PURE__*/_jsx(DidAddress, {
116
+ size: 14,
117
+ responsive: true,
118
+ did: blockletDid
119
+ }) : /*#__PURE__*/_jsx(Button, {
120
+ onClick: () => setOpenConnect(true),
121
+ children: t('blocklet.publish.createBlockletDid')
122
+ })]
123
+ }), openConnect && /*#__PURE__*/_jsx(DidConnect, {
124
+ open: true,
125
+ popup: true,
126
+ onClose: () => setOpenConnect(false),
127
+ action: "gen-blocklet-key-pair",
128
+ locale: locale,
129
+ checkFn: sessionApi.get,
130
+ saveConnect: false,
131
+ forceConnected: false,
132
+ checkTimeout: 5 * 60 * 1000,
133
+ onSuccess: handleCreateBlockletDidSuccess,
134
+ onError: handleCreateBlockletDidError,
135
+ extraParams: {
136
+ did: blocklet.meta.did
137
+ },
138
+ messages: {
139
+ title: t('blocklet.publish.connect.title'),
140
+ scan: t('blocklet.publish.connect.scan'),
141
+ confirm: t('blocklet.publish.connect.confirm'),
142
+ success: t('blocklet.publish.connect.success')
143
+ }
144
+ }), /*#__PURE__*/_jsx(TextField, {
145
+ label: `Blocklet ${t('common.title')}`,
146
+ autoComplete: "off",
147
+ variant: "outlined",
148
+ inputProps: {
149
+ 'data-cy': 'export-blocklet-title'
150
+ },
151
+ fullWidth: true,
152
+ helperText: "",
153
+ value: blockletTitle || '',
154
+ onChange: e => {
155
+ setBlockletTitle(e.target.value);
156
+ }
157
+ }), /*#__PURE__*/_jsx(TextField, {
158
+ sx: {
159
+ my: 4
160
+ },
161
+ id: "blocklet-type",
162
+ select: true,
163
+ label: `Blocklet ${t('common.type')}`,
164
+ helperText: "",
165
+ fullWidth: true,
166
+ value: type,
167
+ onChange: e => setType(e.target.value),
168
+ children: Types.map(x => /*#__PURE__*/_jsx(MenuItem, {
169
+ value: x.value,
170
+ disabled: x.disabled,
171
+ children: x.label[locale] || x.label.en
172
+ }, x.value))
173
+ })]
174
+ }), /*#__PURE__*/_jsx(Button, {
175
+ variant: "contained",
176
+ disabled: loading || !blockletDid || !blockletTitle,
177
+ onClick: onCreate,
178
+ children: t('common.create')
179
+ })]
180
+ });
181
+ }
182
+ CreateProject.propTypes = {};
183
+ CreateProject.defaultProps = {};
184
+ const Main = styled.div`
185
+ .breadcrumbs {
186
+ margin-bottom: 24px;
187
+ }
188
+ `;