@wordpress/list-reusable-blocks 3.0.19 → 3.1.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/CHANGELOG.md +2 -0
- package/LICENSE.md +1 -1
- package/build/components/import-form/index.js +52 -83
- package/build/components/import-form/index.js.map +1 -1
- package/build-module/components/import-form/index.js +53 -84
- package/build-module/components/import-form/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/import-form/index.js +52 -73
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
|
@@ -24,63 +24,47 @@ var _import = _interopRequireDefault(require("../../utils/import"));
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
onChangeFile(event) {
|
|
45
|
-
this.setState({
|
|
46
|
-
file: event.target.files[0],
|
|
47
|
-
error: null
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
onSubmit(event) {
|
|
27
|
+
function ImportForm(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
instanceId,
|
|
30
|
+
onUpload
|
|
31
|
+
} = _ref;
|
|
32
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
33
|
+
const formRef = (0, _element.useRef)();
|
|
34
|
+
const [isLoading, setIsLoading] = (0, _element.useState)(false);
|
|
35
|
+
const [error, setError] = (0, _element.useState)(null);
|
|
36
|
+
const [file, setFile] = (0, _element.useState)(null);
|
|
37
|
+
|
|
38
|
+
const onChangeFile = event => {
|
|
39
|
+
setFile(event.target.files[0]);
|
|
40
|
+
setError(null);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const onSubmit = event => {
|
|
52
44
|
event.preventDefault();
|
|
53
|
-
const {
|
|
54
|
-
file
|
|
55
|
-
} = this.state;
|
|
56
|
-
const {
|
|
57
|
-
onUpload
|
|
58
|
-
} = this.props;
|
|
59
45
|
|
|
60
46
|
if (!file) {
|
|
61
47
|
return;
|
|
62
48
|
}
|
|
63
49
|
|
|
64
|
-
|
|
50
|
+
setIsLoading({
|
|
65
51
|
isLoading: true
|
|
66
52
|
});
|
|
67
53
|
(0, _import.default)(file).then(reusableBlock => {
|
|
68
|
-
if (!
|
|
54
|
+
if (!formRef) {
|
|
69
55
|
return;
|
|
70
56
|
}
|
|
71
57
|
|
|
72
|
-
|
|
73
|
-
isLoading: false
|
|
74
|
-
});
|
|
58
|
+
setIsLoading(false);
|
|
75
59
|
onUpload(reusableBlock);
|
|
76
|
-
}).catch(
|
|
77
|
-
if (!
|
|
60
|
+
}).catch(errors => {
|
|
61
|
+
if (!formRef) {
|
|
78
62
|
return;
|
|
79
63
|
}
|
|
80
64
|
|
|
81
65
|
let uiMessage;
|
|
82
66
|
|
|
83
|
-
switch (
|
|
67
|
+
switch (errors.message) {
|
|
84
68
|
case 'Invalid JSON file':
|
|
85
69
|
uiMessage = (0, _i18n.__)('Invalid JSON file');
|
|
86
70
|
break;
|
|
@@ -93,51 +77,36 @@ class ImportForm extends _element.Component {
|
|
|
93
77
|
uiMessage = (0, _i18n.__)('Unknown error');
|
|
94
78
|
}
|
|
95
79
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
error: uiMessage
|
|
99
|
-
});
|
|
80
|
+
setIsLoading(false);
|
|
81
|
+
setError(uiMessage);
|
|
100
82
|
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
onDismissError() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}, (0, _i18n.__)('File')), (0, _element.createElement)("input", {
|
|
129
|
-
id: inputId,
|
|
130
|
-
type: "file",
|
|
131
|
-
onChange: this.onChangeFile
|
|
132
|
-
}), (0, _element.createElement)(_components.Button, {
|
|
133
|
-
type: "submit",
|
|
134
|
-
isBusy: isLoading,
|
|
135
|
-
disabled: !file || isLoading,
|
|
136
|
-
variant: "secondary",
|
|
137
|
-
className: "list-reusable-blocks-import-form__button"
|
|
138
|
-
}, (0, _i18n._x)('Import', 'button label')));
|
|
139
|
-
}
|
|
140
|
-
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const onDismissError = () => {
|
|
86
|
+
setError(null);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (0, _element.createElement)("form", {
|
|
90
|
+
className: "list-reusable-blocks-import-form",
|
|
91
|
+
onSubmit: onSubmit,
|
|
92
|
+
ref: formRef
|
|
93
|
+
}, error && (0, _element.createElement)(_components.Notice, {
|
|
94
|
+
status: "error",
|
|
95
|
+
onRemove: () => onDismissError()
|
|
96
|
+
}, error), (0, _element.createElement)("label", {
|
|
97
|
+
htmlFor: inputId,
|
|
98
|
+
className: "list-reusable-blocks-import-form__label"
|
|
99
|
+
}, (0, _i18n.__)('File')), (0, _element.createElement)("input", {
|
|
100
|
+
id: inputId,
|
|
101
|
+
type: "file",
|
|
102
|
+
onChange: onChangeFile
|
|
103
|
+
}), (0, _element.createElement)(_components.Button, {
|
|
104
|
+
type: "submit",
|
|
105
|
+
isBusy: isLoading,
|
|
106
|
+
disabled: !file || isLoading,
|
|
107
|
+
variant: "secondary",
|
|
108
|
+
className: "list-reusable-blocks-import-form__button"
|
|
109
|
+
}, (0, _i18n._x)('Import', 'button label')));
|
|
141
110
|
}
|
|
142
111
|
|
|
143
112
|
var _default = (0, _compose.withInstanceId)(ImportForm);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["ImportForm","
|
|
1
|
+
{"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["ImportForm","instanceId","onUpload","inputId","formRef","isLoading","setIsLoading","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","then","reusableBlock","catch","errors","uiMessage","message","onDismissError"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGA,SAASA,UAAT,OAAgD;AAAA,MAA3B;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAA2B;AAC/C,QAAMC,OAAO,GAAG,sCAAsCF,UAAtD;AAEA,QAAMG,OAAO,GAAG,sBAAhB;AACA,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,uBAAU,KAAV,CAApC;AACA,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,IAAV,CAA5B;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,uBAAU,IAAV,CAA1B;;AAEA,QAAMC,YAAY,GAAKC,KAAF,IAAa;AACjCF,IAAAA,OAAO,CAAEE,KAAK,CAACC,MAAN,CAAaC,KAAb,CAAoB,CAApB,CAAF,CAAP;AACAN,IAAAA,QAAQ,CAAE,IAAF,CAAR;AACA,GAHD;;AAKA,QAAMO,QAAQ,GAAKH,KAAF,IAAa;AAC7BA,IAAAA,KAAK,CAACI,cAAN;;AACA,QAAK,CAAEP,IAAP,EAAc;AACb;AACA;;AACDH,IAAAA,YAAY,CAAE;AAAED,MAAAA,SAAS,EAAE;AAAb,KAAF,CAAZ;AACA,yBAAqBI,IAArB,EACEQ,IADF,CACUC,aAAF,IAAqB;AAC3B,UAAK,CAAEd,OAAP,EAAiB;AAChB;AACA;;AAEDE,MA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C;AALX,KAOG,cAAI,QAAJ,EAAc,cAAd,CAPH,CAjBD,CADD;AA6BA;;eAEc,6BAAgBL,UAAhB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { withInstanceId } from '@wordpress/compose';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, Notice } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport importReusableBlock from '../../utils/import';\n\nfunction ImportForm( { instanceId, onUpload } ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState( null );\n\tconst [ file, setFile ] = useState( null );\n\n\tconst onChangeFile = ( event ) => {\n\t\tsetFile( event.target.files[ 0 ] );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( { isLoading: true } );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tonUpload( reusableBlock );\n\t\t\t} )\n\t\t\t.catch( ( errors ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage;\n\t\t\t\tswitch ( errors.message ) {\n\t\t\t\t\tcase 'Invalid JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'Invalid Reusable block JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid Reusable block JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tuiMessage = __( 'Unknown error' );\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetError( uiMessage );\n\t\t\t} );\n\t};\n\n\tconst onDismissError = () => {\n\t\tsetError( null );\n\t};\n\n\treturn (\n\t\t<form\n\t\t\tclassName=\"list-reusable-blocks-import-form\"\n\t\t\tonSubmit={ onSubmit }\n\t\t\tref={ formRef }\n\t\t>\n\t\t\t{ error && (\n\t\t\t\t<Notice status=\"error\" onRemove={ () => onDismissError() }>\n\t\t\t\t\t{ error }\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t\t<label\n\t\t\t\thtmlFor={ inputId }\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__label\"\n\t\t\t>\n\t\t\t\t{ __( 'File' ) }\n\t\t\t</label>\n\t\t\t<input id={ inputId } type=\"file\" onChange={ onChangeFile } />\n\t\t\t<Button\n\t\t\t\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\n\t\t\t\tdisabled={ ! file || isLoading }\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__button\"\n\t\t\t>\n\t\t\t\t{ _x( 'Import', 'button label' ) }\n\t\t\t</Button>\n\t\t</form>\n\t);\n}\n\nexport default withInstanceId( ImportForm );\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { useState, useRef } from '@wordpress/element';
|
|
7
7
|
import { withInstanceId } from '@wordpress/compose';
|
|
8
8
|
import { __, _x } from '@wordpress/i18n';
|
|
9
9
|
import { Button, Notice } from '@wordpress/components';
|
|
@@ -13,63 +13,47 @@ import { Button, Notice } from '@wordpress/components';
|
|
|
13
13
|
|
|
14
14
|
import importReusableBlock from '../../utils/import';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
onChangeFile(event) {
|
|
34
|
-
this.setState({
|
|
35
|
-
file: event.target.files[0],
|
|
36
|
-
error: null
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onSubmit(event) {
|
|
16
|
+
function ImportForm(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
instanceId,
|
|
19
|
+
onUpload
|
|
20
|
+
} = _ref;
|
|
21
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
22
|
+
const formRef = useRef();
|
|
23
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
24
|
+
const [error, setError] = useState(null);
|
|
25
|
+
const [file, setFile] = useState(null);
|
|
26
|
+
|
|
27
|
+
const onChangeFile = event => {
|
|
28
|
+
setFile(event.target.files[0]);
|
|
29
|
+
setError(null);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const onSubmit = event => {
|
|
41
33
|
event.preventDefault();
|
|
42
|
-
const {
|
|
43
|
-
file
|
|
44
|
-
} = this.state;
|
|
45
|
-
const {
|
|
46
|
-
onUpload
|
|
47
|
-
} = this.props;
|
|
48
34
|
|
|
49
35
|
if (!file) {
|
|
50
36
|
return;
|
|
51
37
|
}
|
|
52
38
|
|
|
53
|
-
|
|
39
|
+
setIsLoading({
|
|
54
40
|
isLoading: true
|
|
55
41
|
});
|
|
56
42
|
importReusableBlock(file).then(reusableBlock => {
|
|
57
|
-
if (!
|
|
43
|
+
if (!formRef) {
|
|
58
44
|
return;
|
|
59
45
|
}
|
|
60
46
|
|
|
61
|
-
|
|
62
|
-
isLoading: false
|
|
63
|
-
});
|
|
47
|
+
setIsLoading(false);
|
|
64
48
|
onUpload(reusableBlock);
|
|
65
|
-
}).catch(
|
|
66
|
-
if (!
|
|
49
|
+
}).catch(errors => {
|
|
50
|
+
if (!formRef) {
|
|
67
51
|
return;
|
|
68
52
|
}
|
|
69
53
|
|
|
70
54
|
let uiMessage;
|
|
71
55
|
|
|
72
|
-
switch (
|
|
56
|
+
switch (errors.message) {
|
|
73
57
|
case 'Invalid JSON file':
|
|
74
58
|
uiMessage = __('Invalid JSON file');
|
|
75
59
|
break;
|
|
@@ -82,51 +66,36 @@ class ImportForm extends Component {
|
|
|
82
66
|
uiMessage = __('Unknown error');
|
|
83
67
|
}
|
|
84
68
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
error: uiMessage
|
|
88
|
-
});
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
setError(uiMessage);
|
|
89
71
|
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
onDismissError() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}, __('File')), createElement("input", {
|
|
118
|
-
id: inputId,
|
|
119
|
-
type: "file",
|
|
120
|
-
onChange: this.onChangeFile
|
|
121
|
-
}), createElement(Button, {
|
|
122
|
-
type: "submit",
|
|
123
|
-
isBusy: isLoading,
|
|
124
|
-
disabled: !file || isLoading,
|
|
125
|
-
variant: "secondary",
|
|
126
|
-
className: "list-reusable-blocks-import-form__button"
|
|
127
|
-
}, _x('Import', 'button label')));
|
|
128
|
-
}
|
|
129
|
-
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const onDismissError = () => {
|
|
75
|
+
setError(null);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return createElement("form", {
|
|
79
|
+
className: "list-reusable-blocks-import-form",
|
|
80
|
+
onSubmit: onSubmit,
|
|
81
|
+
ref: formRef
|
|
82
|
+
}, error && createElement(Notice, {
|
|
83
|
+
status: "error",
|
|
84
|
+
onRemove: () => onDismissError()
|
|
85
|
+
}, error), createElement("label", {
|
|
86
|
+
htmlFor: inputId,
|
|
87
|
+
className: "list-reusable-blocks-import-form__label"
|
|
88
|
+
}, __('File')), createElement("input", {
|
|
89
|
+
id: inputId,
|
|
90
|
+
type: "file",
|
|
91
|
+
onChange: onChangeFile
|
|
92
|
+
}), createElement(Button, {
|
|
93
|
+
type: "submit",
|
|
94
|
+
isBusy: isLoading,
|
|
95
|
+
disabled: !file || isLoading,
|
|
96
|
+
variant: "secondary",
|
|
97
|
+
className: "list-reusable-blocks-import-form__button"
|
|
98
|
+
}, _x('Import', 'button label')));
|
|
130
99
|
}
|
|
131
100
|
|
|
132
101
|
export default withInstanceId(ImportForm);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["useState","useRef","withInstanceId","__","_x","Button","Notice","importReusableBlock","ImportForm","instanceId","onUpload","inputId","formRef","isLoading","setIsLoading","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","then","reusableBlock","catch","errors","uiMessage","message","onDismissError"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,QAAiC,oBAAjC;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,EAAT,EAAaC,EAAb,QAAuB,iBAAvB;AACA,SAASC,MAAT,EAAiBC,MAAjB,QAA+B,uBAA/B;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,oBAAhC;;AAEA,SAASC,UAAT,OAAgD;AAAA,MAA3B;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAA2B;AAC/C,QAAMC,OAAO,GAAG,sCAAsCF,UAAtD;AAEA,QAAMG,OAAO,GAA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AACA,KA5BF;AA6BA,GAnCD;;AAqCA,QAAME,cAAc,GAAG,MAAM;AAC5Bf,IAAAA,QAAQ,CAAE,IAAF,CAAR;AACA,GAFD;;AAIA,SACC;AACC,IAAA,SAAS,EAAC,kCADX;AAEC,IAAA,QAAQ,EAAGO,QAFZ;AAGC,IAAA,GAAG,EAAGX;AAHP,KAKGG,KAAK,IACN,cAAC,MAAD;AAAQ,IAAA,MAAM,EAAC,OAAf;AAAuB,IAAA,QAAQ,EAAG,MAAMgB,cAAc;AAAtD,KACGhB,KADH,CANF,EAUC;AACC,IAAA,OAAO,EAAGJ,OADX;AAEC,IAAA,SAAS,EAAC;AAFX,KAIGR,EAAE,CAAE,MAAF,CAJL,CAVD,EAgBC;AAAO,IAAA,EAAE,EAAGQ,OAAZ;AAAsB,IAAA,IAAI,EAAC,MAA3B;AAAkC,IAAA,QAAQ,EAAGQ;AAA7C,IAhBD,EAiBC,cAAC,MAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,MAAM,EAAGN,SAFV;AAGC,IAAA,QAAQ,EAAG,CAAEI,IAAF,IAAUJ,SAHtB;AAIC,IAAA,OAAO,EAAC,WAJT;AAKC,IAAA,SAAS,EAAC;AALX,KAOGT,EAAE,CAAE,QAAF,EAAY,cAAZ,CAPL,CAjBD,CADD;AA6BA;;AAED,eAAeF,cAAc,CAAEM,UAAF,CAA7B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { withInstanceId } from '@wordpress/compose';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, Notice } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport importReusableBlock from '../../utils/import';\n\nfunction ImportForm( { instanceId, onUpload } ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState( null );\n\tconst [ file, setFile ] = useState( null );\n\n\tconst onChangeFile = ( event ) => {\n\t\tsetFile( event.target.files[ 0 ] );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( { isLoading: true } );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tonUpload( reusableBlock );\n\t\t\t} )\n\t\t\t.catch( ( errors ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage;\n\t\t\t\tswitch ( errors.message ) {\n\t\t\t\t\tcase 'Invalid JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'Invalid Reusable block JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid Reusable block JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tuiMessage = __( 'Unknown error' );\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetError( uiMessage );\n\t\t\t} );\n\t};\n\n\tconst onDismissError = () => {\n\t\tsetError( null );\n\t};\n\n\treturn (\n\t\t<form\n\t\t\tclassName=\"list-reusable-blocks-import-form\"\n\t\t\tonSubmit={ onSubmit }\n\t\t\tref={ formRef }\n\t\t>\n\t\t\t{ error && (\n\t\t\t\t<Notice status=\"error\" onRemove={ () => onDismissError() }>\n\t\t\t\t\t{ error }\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t\t<label\n\t\t\t\thtmlFor={ inputId }\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__label\"\n\t\t\t>\n\t\t\t\t{ __( 'File' ) }\n\t\t\t</label>\n\t\t\t<input id={ inputId } type=\"file\" onChange={ onChangeFile } />\n\t\t\t<Button\n\t\t\t\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\n\t\t\t\tdisabled={ ! file || isLoading }\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__button\"\n\t\t\t>\n\t\t\t\t{ _x( 'Import', 'button label' ) }\n\t\t\t</Button>\n\t\t</form>\n\t);\n}\n\nexport default withInstanceId( ImportForm );\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/list-reusable-blocks",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Adding Export/Import support to the reusable blocks listing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"module": "build-module/index.js",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/api-fetch": "^
|
|
30
|
-
"@wordpress/components": "^19.
|
|
31
|
-
"@wordpress/compose": "^5.0
|
|
32
|
-
"@wordpress/element": "^4.0
|
|
33
|
-
"@wordpress/i18n": "^4.
|
|
29
|
+
"@wordpress/api-fetch": "^6.0.0",
|
|
30
|
+
"@wordpress/components": "^19.3.0",
|
|
31
|
+
"@wordpress/compose": "^5.1.0",
|
|
32
|
+
"@wordpress/element": "^4.1.0",
|
|
33
|
+
"@wordpress/i18n": "^4.3.0",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
40
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { useState, useRef } from '@wordpress/element';
|
|
5
5
|
import { withInstanceId } from '@wordpress/compose';
|
|
6
6
|
import { __, _x } from '@wordpress/i18n';
|
|
7
7
|
import { Button, Notice } from '@wordpress/components';
|
|
@@ -11,52 +11,41 @@ import { Button, Notice } from '@wordpress/components';
|
|
|
11
11
|
*/
|
|
12
12
|
import importReusableBlock from '../../utils/import';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
super( ...arguments );
|
|
17
|
-
this.state = {
|
|
18
|
-
isLoading: false,
|
|
19
|
-
error: null,
|
|
20
|
-
file: null,
|
|
21
|
-
};
|
|
14
|
+
function ImportForm( { instanceId, onUpload } ) {
|
|
15
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const formRef = useRef();
|
|
18
|
+
const [ isLoading, setIsLoading ] = useState( false );
|
|
19
|
+
const [ error, setError ] = useState( null );
|
|
20
|
+
const [ file, setFile ] = useState( null );
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
const onChangeFile = ( event ) => {
|
|
23
|
+
setFile( event.target.files[ 0 ] );
|
|
24
|
+
setError( null );
|
|
25
|
+
};
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
this.setState( { file: event.target.files[ 0 ], error: null } );
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
onSubmit( event ) {
|
|
27
|
+
const onSubmit = ( event ) => {
|
|
37
28
|
event.preventDefault();
|
|
38
|
-
const { file } = this.state;
|
|
39
|
-
const { onUpload } = this.props;
|
|
40
29
|
if ( ! file ) {
|
|
41
30
|
return;
|
|
42
31
|
}
|
|
43
|
-
|
|
32
|
+
setIsLoading( { isLoading: true } );
|
|
44
33
|
importReusableBlock( file )
|
|
45
34
|
.then( ( reusableBlock ) => {
|
|
46
|
-
if ( !
|
|
35
|
+
if ( ! formRef ) {
|
|
47
36
|
return;
|
|
48
37
|
}
|
|
49
38
|
|
|
50
|
-
|
|
39
|
+
setIsLoading( false );
|
|
51
40
|
onUpload( reusableBlock );
|
|
52
41
|
} )
|
|
53
|
-
.catch( (
|
|
54
|
-
if ( !
|
|
42
|
+
.catch( ( errors ) => {
|
|
43
|
+
if ( ! formRef ) {
|
|
55
44
|
return;
|
|
56
45
|
}
|
|
57
46
|
|
|
58
47
|
let uiMessage;
|
|
59
|
-
switch (
|
|
48
|
+
switch ( errors.message ) {
|
|
60
49
|
case 'Invalid JSON file':
|
|
61
50
|
uiMessage = __( 'Invalid JSON file' );
|
|
62
51
|
break;
|
|
@@ -67,54 +56,44 @@ class ImportForm extends Component {
|
|
|
67
56
|
uiMessage = __( 'Unknown error' );
|
|
68
57
|
}
|
|
69
58
|
|
|
70
|
-
|
|
59
|
+
setIsLoading( false );
|
|
60
|
+
setError( uiMessage );
|
|
71
61
|
} );
|
|
72
|
-
}
|
|
62
|
+
};
|
|
73
63
|
|
|
74
|
-
onDismissError() {
|
|
75
|
-
|
|
76
|
-
}
|
|
64
|
+
const onDismissError = () => {
|
|
65
|
+
setError( null );
|
|
66
|
+
};
|
|
77
67
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
return (
|
|
69
|
+
<form
|
|
70
|
+
className="list-reusable-blocks-import-form"
|
|
71
|
+
onSubmit={ onSubmit }
|
|
72
|
+
ref={ formRef }
|
|
73
|
+
>
|
|
74
|
+
{ error && (
|
|
75
|
+
<Notice status="error" onRemove={ () => onDismissError() }>
|
|
76
|
+
{ error }
|
|
77
|
+
</Notice>
|
|
78
|
+
) }
|
|
79
|
+
<label
|
|
80
|
+
htmlFor={ inputId }
|
|
81
|
+
className="list-reusable-blocks-import-form__label"
|
|
82
|
+
>
|
|
83
|
+
{ __( 'File' ) }
|
|
84
|
+
</label>
|
|
85
|
+
<input id={ inputId } type="file" onChange={ onChangeFile } />
|
|
86
|
+
<Button
|
|
87
|
+
type="submit"
|
|
88
|
+
isBusy={ isLoading }
|
|
89
|
+
disabled={ ! file || isLoading }
|
|
90
|
+
variant="secondary"
|
|
91
|
+
className="list-reusable-blocks-import-form__button"
|
|
86
92
|
>
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
>
|
|
92
|
-
{ error }
|
|
93
|
-
</Notice>
|
|
94
|
-
) }
|
|
95
|
-
<label
|
|
96
|
-
htmlFor={ inputId }
|
|
97
|
-
className="list-reusable-blocks-import-form__label"
|
|
98
|
-
>
|
|
99
|
-
{ __( 'File' ) }
|
|
100
|
-
</label>
|
|
101
|
-
<input
|
|
102
|
-
id={ inputId }
|
|
103
|
-
type="file"
|
|
104
|
-
onChange={ this.onChangeFile }
|
|
105
|
-
/>
|
|
106
|
-
<Button
|
|
107
|
-
type="submit"
|
|
108
|
-
isBusy={ isLoading }
|
|
109
|
-
disabled={ ! file || isLoading }
|
|
110
|
-
variant="secondary"
|
|
111
|
-
className="list-reusable-blocks-import-form__button"
|
|
112
|
-
>
|
|
113
|
-
{ _x( 'Import', 'button label' ) }
|
|
114
|
-
</Button>
|
|
115
|
-
</form>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
93
|
+
{ _x( 'Import', 'button label' ) }
|
|
94
|
+
</Button>
|
|
95
|
+
</form>
|
|
96
|
+
);
|
|
118
97
|
}
|
|
119
98
|
|
|
120
99
|
export default withInstanceId( ImportForm );
|