@wordpress/list-reusable-blocks 3.0.16-next.33ec3857e2.0 → 3.0.16
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/build/components/import-form/index.js +83 -52
- package/build/components/import-form/index.js.map +1 -1
- package/build-module/components/import-form/index.js +84 -53
- package/build-module/components/import-form/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/import-form/index.js +73 -52
|
@@ -24,47 +24,63 @@ 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
|
-
|
|
27
|
+
class ImportForm extends _element.Component {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.state = {
|
|
31
|
+
isLoading: false,
|
|
32
|
+
error: null,
|
|
33
|
+
file: null
|
|
34
|
+
};
|
|
35
|
+
this.isStillMounted = true;
|
|
36
|
+
this.onChangeFile = this.onChangeFile.bind(this);
|
|
37
|
+
this.onSubmit = this.onSubmit.bind(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
componentWillUnmount() {
|
|
41
|
+
this.isStillMounted = false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onChangeFile(event) {
|
|
45
|
+
this.setState({
|
|
46
|
+
file: event.target.files[0],
|
|
47
|
+
error: null
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onSubmit(event) {
|
|
44
52
|
event.preventDefault();
|
|
53
|
+
const {
|
|
54
|
+
file
|
|
55
|
+
} = this.state;
|
|
56
|
+
const {
|
|
57
|
+
onUpload
|
|
58
|
+
} = this.props;
|
|
45
59
|
|
|
46
60
|
if (!file) {
|
|
47
61
|
return;
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
|
|
64
|
+
this.setState({
|
|
51
65
|
isLoading: true
|
|
52
66
|
});
|
|
53
67
|
(0, _import.default)(file).then(reusableBlock => {
|
|
54
|
-
if (!
|
|
68
|
+
if (!this.isStillMounted) {
|
|
55
69
|
return;
|
|
56
70
|
}
|
|
57
71
|
|
|
58
|
-
|
|
72
|
+
this.setState({
|
|
73
|
+
isLoading: false
|
|
74
|
+
});
|
|
59
75
|
onUpload(reusableBlock);
|
|
60
|
-
}).catch(
|
|
61
|
-
if (!
|
|
76
|
+
}).catch(error => {
|
|
77
|
+
if (!this.isStillMounted) {
|
|
62
78
|
return;
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
let uiMessage;
|
|
66
82
|
|
|
67
|
-
switch (
|
|
83
|
+
switch (error.message) {
|
|
68
84
|
case 'Invalid JSON file':
|
|
69
85
|
uiMessage = (0, _i18n.__)('Invalid JSON file');
|
|
70
86
|
break;
|
|
@@ -77,36 +93,51 @@ function ImportForm(_ref) {
|
|
|
77
93
|
uiMessage = (0, _i18n.__)('Unknown error');
|
|
78
94
|
}
|
|
79
95
|
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
this.setState({
|
|
97
|
+
isLoading: false,
|
|
98
|
+
error: uiMessage
|
|
99
|
+
});
|
|
82
100
|
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
onDismissError() {
|
|
104
|
+
this.setState({
|
|
105
|
+
error: null
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
render() {
|
|
110
|
+
const {
|
|
111
|
+
instanceId
|
|
112
|
+
} = this.props;
|
|
113
|
+
const {
|
|
114
|
+
file,
|
|
115
|
+
isLoading,
|
|
116
|
+
error
|
|
117
|
+
} = this.state;
|
|
118
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
119
|
+
return (0, _element.createElement)("form", {
|
|
120
|
+
className: "list-reusable-blocks-import-form",
|
|
121
|
+
onSubmit: this.onSubmit
|
|
122
|
+
}, error && (0, _element.createElement)(_components.Notice, {
|
|
123
|
+
status: "error",
|
|
124
|
+
onRemove: () => this.onDismissError()
|
|
125
|
+
}, error), (0, _element.createElement)("label", {
|
|
126
|
+
htmlFor: inputId,
|
|
127
|
+
className: "list-reusable-blocks-import-form__label"
|
|
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
|
+
|
|
110
141
|
}
|
|
111
142
|
|
|
112
143
|
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","Component","constructor","arguments","state","isLoading","error","file","isStillMounted","onChangeFile","bind","onSubmit","componentWillUnmount","event","setState","target","files","preventDefault","onUpload","props","then","reusableBlock","catch","uiMessage","message","onDismissError","render","instanceId","inputId"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGA,MAAMA,UAAN,SAAyBC,kBAAzB,CAAmC;AAClCC,EAAAA,WAAW,GAAG;AACb,UAAO,GAAGC,SAAV;AACA,SAAKC,KAAL,GAAa;AACZC,MAAAA,SAAS,EAAE,KADC;AAEZC,MAAAA,KAAK,EAAE,IAFK;AAGZC,MAAAA,IAAI,EAAE;AAHM,KAAb;AAMA,SAAKC,cAAL,GAAsB,IAAtB;AACA,SAAKC,YAAL,GAAoB,KAAKA,YAAL,CAAkBC,IAAlB,CAAwB,IAAxB,CAApB;AACA,SAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcD,IAAd,CAAoB,IAApB,CAAhB;AACA;;AAEDE,EAAAA,oBAAoB,GAAG;AACtB,SAAKJ,cAAL,GAAsB,KAAtB;AACA;;AAEDC,EAAAA,YAAY,CAAEI,KAAF,EAAU;AACrB,SAAKC,QAAL,CAAe;AAAEP,MAAAA,IAAI,EAAEM,KAAK,CAACE,MAAN,CAAaC,KAAb,CAAoB,CAApB,CAAR;AAAiCV,MAAAA,KAAK,EAAE;AAAxC,KAAf;AACA;;AAEDK,EAAAA,QAAQ,CAAEE,KAAF,EAAU;AACjBA,IAAAA,KAAK,CAACI,cAAN;AACA,UAAM;AAAEV,MAAAA;AAAF,QAAW,KAAKH,KAAtB;AACA,UAAM;AAAEc,MAAAA;AAAF,QAAe,KAAKC,KAA1B;;AACA,QAAK,CAAEZ,IAAP,EAAc;AACb;AACA;;AACD,SAAKO,QAAL,CAAe;AAAET,MAAAA,SAAS,EAAE;AAAb,KAAf;AACA,yBAAqBE,IAArB,EACEa,IADF,CACUC,aAAF,IAAqB;AAC3B,UAAK,CAAE,KAAKb,cAAZ,EAA6B;AAC5B;AACA;;AAED,WAAKM,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AAC,MAFN;AAGC,MAAA,QAAQ,EAAG,KAAKnB;AAHjB,MAlBD,EAuBC,4BAAC,kBAAD;AACC,MAAA,IAAI,EAAC,QADN;AAEC,MAAA,MAAM,EAAGJ,SAFV;AAGC,MAAA,QAAQ,EAAG,CAAEE,IAAF,IAAUF,SAHtB;AAIC,MAAA,OAAO,EAAC,WAJT;AAKC,MAAA,SAAS,EAAC;AALX,OAOG,cAAI,QAAJ,EAAc,cAAd,CAPH,CAvBD,CADD;AAmCA;;AAvGiC;;eA0GpB,6BAAgBL,UAAhB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } 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\nclass ImportForm extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.state = {\n\t\t\tisLoading: false,\n\t\t\terror: null,\n\t\t\tfile: null,\n\t\t};\n\n\t\tthis.isStillMounted = true;\n\t\tthis.onChangeFile = this.onChangeFile.bind( this );\n\t\tthis.onSubmit = this.onSubmit.bind( this );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.isStillMounted = false;\n\t}\n\n\tonChangeFile( event ) {\n\t\tthis.setState( { file: event.target.files[ 0 ], error: null } );\n\t}\n\n\tonSubmit( event ) {\n\t\tevent.preventDefault();\n\t\tconst { file } = this.state;\n\t\tconst { onUpload } = this.props;\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tthis.setState( { isLoading: true } );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock ) => {\n\t\t\t\tif ( ! this.isStillMounted ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( { isLoading: false } );\n\t\t\t\tonUpload( reusableBlock );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif ( ! this.isStillMounted ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage;\n\t\t\t\tswitch ( error.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\tthis.setState( { isLoading: false, error: uiMessage } );\n\t\t\t} );\n\t}\n\n\tonDismissError() {\n\t\tthis.setState( { error: null } );\n\t}\n\n\trender() {\n\t\tconst { instanceId } = this.props;\n\t\tconst { file, isLoading, error } = this.state;\n\t\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\t\treturn (\n\t\t\t<form\n\t\t\t\tclassName=\"list-reusable-blocks-import-form\"\n\t\t\t\tonSubmit={ this.onSubmit }\n\t\t\t>\n\t\t\t\t{ error && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\tonRemove={ () => this.onDismissError() }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ error }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t<label\n\t\t\t\t\thtmlFor={ inputId }\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-form__label\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'File' ) }\n\t\t\t\t</label>\n\t\t\t\t<input\n\t\t\t\t\tid={ inputId }\n\t\t\t\t\ttype=\"file\"\n\t\t\t\t\tonChange={ this.onChangeFile }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\tisBusy={ isLoading }\n\t\t\t\t\tdisabled={ ! file || isLoading }\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-form__button\"\n\t\t\t\t>\n\t\t\t\t\t{ _x( 'Import', 'button label' ) }\n\t\t\t\t</Button>\n\t\t\t</form>\n\t\t);\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 { Component } 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,47 +13,63 @@ 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
|
-
|
|
16
|
+
class ImportForm extends Component {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.state = {
|
|
20
|
+
isLoading: false,
|
|
21
|
+
error: null,
|
|
22
|
+
file: null
|
|
23
|
+
};
|
|
24
|
+
this.isStillMounted = true;
|
|
25
|
+
this.onChangeFile = this.onChangeFile.bind(this);
|
|
26
|
+
this.onSubmit = this.onSubmit.bind(this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
componentWillUnmount() {
|
|
30
|
+
this.isStillMounted = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
onChangeFile(event) {
|
|
34
|
+
this.setState({
|
|
35
|
+
file: event.target.files[0],
|
|
36
|
+
error: null
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onSubmit(event) {
|
|
33
41
|
event.preventDefault();
|
|
42
|
+
const {
|
|
43
|
+
file
|
|
44
|
+
} = this.state;
|
|
45
|
+
const {
|
|
46
|
+
onUpload
|
|
47
|
+
} = this.props;
|
|
34
48
|
|
|
35
49
|
if (!file) {
|
|
36
50
|
return;
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
this.setState({
|
|
40
54
|
isLoading: true
|
|
41
55
|
});
|
|
42
56
|
importReusableBlock(file).then(reusableBlock => {
|
|
43
|
-
if (!
|
|
57
|
+
if (!this.isStillMounted) {
|
|
44
58
|
return;
|
|
45
59
|
}
|
|
46
60
|
|
|
47
|
-
|
|
61
|
+
this.setState({
|
|
62
|
+
isLoading: false
|
|
63
|
+
});
|
|
48
64
|
onUpload(reusableBlock);
|
|
49
|
-
}).catch(
|
|
50
|
-
if (!
|
|
65
|
+
}).catch(error => {
|
|
66
|
+
if (!this.isStillMounted) {
|
|
51
67
|
return;
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
let uiMessage;
|
|
55
71
|
|
|
56
|
-
switch (
|
|
72
|
+
switch (error.message) {
|
|
57
73
|
case 'Invalid JSON file':
|
|
58
74
|
uiMessage = __('Invalid JSON file');
|
|
59
75
|
break;
|
|
@@ -66,36 +82,51 @@ function ImportForm(_ref) {
|
|
|
66
82
|
uiMessage = __('Unknown error');
|
|
67
83
|
}
|
|
68
84
|
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
this.setState({
|
|
86
|
+
isLoading: false,
|
|
87
|
+
error: uiMessage
|
|
88
|
+
});
|
|
71
89
|
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
onDismissError() {
|
|
93
|
+
this.setState({
|
|
94
|
+
error: null
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
render() {
|
|
99
|
+
const {
|
|
100
|
+
instanceId
|
|
101
|
+
} = this.props;
|
|
102
|
+
const {
|
|
103
|
+
file,
|
|
104
|
+
isLoading,
|
|
105
|
+
error
|
|
106
|
+
} = this.state;
|
|
107
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
108
|
+
return createElement("form", {
|
|
109
|
+
className: "list-reusable-blocks-import-form",
|
|
110
|
+
onSubmit: this.onSubmit
|
|
111
|
+
}, error && createElement(Notice, {
|
|
112
|
+
status: "error",
|
|
113
|
+
onRemove: () => this.onDismissError()
|
|
114
|
+
}, error), createElement("label", {
|
|
115
|
+
htmlFor: inputId,
|
|
116
|
+
className: "list-reusable-blocks-import-form__label"
|
|
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
|
+
|
|
99
130
|
}
|
|
100
131
|
|
|
101
132
|
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":["Component","withInstanceId","__","_x","Button","Notice","importReusableBlock","ImportForm","constructor","arguments","state","isLoading","error","file","isStillMounted","onChangeFile","bind","onSubmit","componentWillUnmount","event","setState","target","files","preventDefault","onUpload","props","then","reusableBlock","catch","uiMessage","message","onDismissError","render","instanceId","inputId"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;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,MAAMC,UAAN,SAAyBP,SAAzB,CAAmC;AAClCQ,EAAAA,WAAW,GAAG;AACb,UAAO,GAAGC,SAAV;AACA,SAAKC,KAAL,GAAa;AACZC,MAAAA,SAAS,EAAE,KADC;AAEZC,MAAAA,KAAK,EAAE,IAFK;AAGZC,MAAAA,IAAI,EAAE;AAHM,KAAb;AAMA,SAAKC,cAAL,GAAsB,IAAtB;AACA,SAAKC,YAAL,GAAoB,KAAKA,YAAL,CAAkBC,IAAlB,CAAwB,IAAxB,CAApB;AACA,SAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcD,IAAd,CAAoB,IAApB,CAAhB;AACA;;AAEDE,EAAAA,oBAAoB,GAAG;AACtB,SAAKJ,cAAL,GAAsB,KAAtB;AACA;;AAEDC,EAAAA,YAAY,CAAEI,KAAF,EAAU;AACrB,SAAKC,QAAL,CAAe;AAAEP,MAAAA,IAAI,EAAEM,KAAK,CAACE,MAAN,CAAaC,KAAb,CAAoB,CAApB,CAAR;AAAiCV,MAAAA,KAAK,EAAE;AAAxC,KAAf;AACA;;AAEDK,EAAAA,QAAQ,CAAEE,KAAF,EAAU;AACjBA,IAAAA,KAAK,CAACI,cAAN;AACA,UAAM;AAAEV,MAAAA;AAAF,QAAW,KAAKH,KAAtB;AACA,UAAM;AAAEc,MAAAA;AAAF,QAAe,KAAKC,KAA1B;;AACA,QAAK,CAA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AAA,MAAM,EAAC,OADR;AAEC,MAAA,QAAQ,EAAG,MAAM,KAAKmB,cAAL;AAFlB,OAIGnB,KAJH,CALF,EAYC;AACC,MAAA,OAAO,EAAGsB,OADX;AAEC,MAAA,SAAS,EAAC;AAFX,OAIGhC,EAAE,CAAE,MAAF,CAJL,CAZD,EAkBC;AACC,MAAA,EAAE,EAAGgC,OADN;AAEC,MAAA,IAAI,EAAC,MAFN;AAGC,MAAA,QAAQ,EAAG,KAAKnB;AAHjB,MAlBD,EAuBC,cAAC,MAAD;AACC,MAAA,IAAI,EAAC,QADN;AAEC,MAAA,MAAM,EAAGJ,SAFV;AAGC,MAAA,QAAQ,EAAG,CAAEE,IAAF,IAAUF,SAHtB;AAIC,MAAA,OAAO,EAAC,WAJT;AAKC,MAAA,SAAS,EAAC;AALX,OAOGR,EAAE,CAAE,QAAF,EAAY,cAAZ,CAPL,CAvBD,CADD;AAmCA;;AAvGiC;;AA0GnC,eAAeF,cAAc,CAAEM,UAAF,CAA7B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } 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\nclass ImportForm extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.state = {\n\t\t\tisLoading: false,\n\t\t\terror: null,\n\t\t\tfile: null,\n\t\t};\n\n\t\tthis.isStillMounted = true;\n\t\tthis.onChangeFile = this.onChangeFile.bind( this );\n\t\tthis.onSubmit = this.onSubmit.bind( this );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.isStillMounted = false;\n\t}\n\n\tonChangeFile( event ) {\n\t\tthis.setState( { file: event.target.files[ 0 ], error: null } );\n\t}\n\n\tonSubmit( event ) {\n\t\tevent.preventDefault();\n\t\tconst { file } = this.state;\n\t\tconst { onUpload } = this.props;\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tthis.setState( { isLoading: true } );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock ) => {\n\t\t\t\tif ( ! this.isStillMounted ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( { isLoading: false } );\n\t\t\t\tonUpload( reusableBlock );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif ( ! this.isStillMounted ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage;\n\t\t\t\tswitch ( error.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\tthis.setState( { isLoading: false, error: uiMessage } );\n\t\t\t} );\n\t}\n\n\tonDismissError() {\n\t\tthis.setState( { error: null } );\n\t}\n\n\trender() {\n\t\tconst { instanceId } = this.props;\n\t\tconst { file, isLoading, error } = this.state;\n\t\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\t\treturn (\n\t\t\t<form\n\t\t\t\tclassName=\"list-reusable-blocks-import-form\"\n\t\t\t\tonSubmit={ this.onSubmit }\n\t\t\t>\n\t\t\t\t{ error && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\tonRemove={ () => this.onDismissError() }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ error }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t<label\n\t\t\t\t\thtmlFor={ inputId }\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-form__label\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'File' ) }\n\t\t\t\t</label>\n\t\t\t\t<input\n\t\t\t\t\tid={ inputId }\n\t\t\t\t\ttype=\"file\"\n\t\t\t\t\tonChange={ this.onChangeFile }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\tisBusy={ isLoading }\n\t\t\t\t\tdisabled={ ! file || isLoading }\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-form__button\"\n\t\t\t\t>\n\t\t\t\t\t{ _x( 'Import', 'button label' ) }\n\t\t\t\t</Button>\n\t\t\t</form>\n\t\t);\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.16
|
|
3
|
+
"version": "3.0.16",
|
|
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": "^5.2.
|
|
30
|
-
"@wordpress/components": "^19.
|
|
31
|
-
"@wordpress/compose": "^5.0.7
|
|
32
|
-
"@wordpress/element": "^4.0.
|
|
33
|
-
"@wordpress/i18n": "^4.2.
|
|
29
|
+
"@wordpress/api-fetch": "^5.2.6",
|
|
30
|
+
"@wordpress/components": "^19.1.6",
|
|
31
|
+
"@wordpress/compose": "^5.0.7",
|
|
32
|
+
"@wordpress/element": "^4.0.4",
|
|
33
|
+
"@wordpress/i18n": "^4.2.4",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "1081a28b2368fcebd9a14554fbd0e25eb33fbcb6"
|
|
40
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Component } 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,41 +11,52 @@ import { Button, Notice } from '@wordpress/components';
|
|
|
11
11
|
*/
|
|
12
12
|
import importReusableBlock from '../../utils/import';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
class ImportForm extends Component {
|
|
15
|
+
constructor() {
|
|
16
|
+
super( ...arguments );
|
|
17
|
+
this.state = {
|
|
18
|
+
isLoading: false,
|
|
19
|
+
error: null,
|
|
20
|
+
file: null,
|
|
21
|
+
};
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
this.isStillMounted = true;
|
|
24
|
+
this.onChangeFile = this.onChangeFile.bind( this );
|
|
25
|
+
this.onSubmit = this.onSubmit.bind( this );
|
|
26
|
+
}
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
28
|
+
componentWillUnmount() {
|
|
29
|
+
this.isStillMounted = false;
|
|
30
|
+
}
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
onChangeFile( event ) {
|
|
33
|
+
this.setState( { file: event.target.files[ 0 ], error: null } );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
onSubmit( event ) {
|
|
28
37
|
event.preventDefault();
|
|
38
|
+
const { file } = this.state;
|
|
39
|
+
const { onUpload } = this.props;
|
|
29
40
|
if ( ! file ) {
|
|
30
41
|
return;
|
|
31
42
|
}
|
|
32
|
-
|
|
43
|
+
this.setState( { isLoading: true } );
|
|
33
44
|
importReusableBlock( file )
|
|
34
45
|
.then( ( reusableBlock ) => {
|
|
35
|
-
if ( !
|
|
46
|
+
if ( ! this.isStillMounted ) {
|
|
36
47
|
return;
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
this.setState( { isLoading: false } );
|
|
40
51
|
onUpload( reusableBlock );
|
|
41
52
|
} )
|
|
42
|
-
.catch( (
|
|
43
|
-
if ( !
|
|
53
|
+
.catch( ( error ) => {
|
|
54
|
+
if ( ! this.isStillMounted ) {
|
|
44
55
|
return;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
let uiMessage;
|
|
48
|
-
switch (
|
|
59
|
+
switch ( error.message ) {
|
|
49
60
|
case 'Invalid JSON file':
|
|
50
61
|
uiMessage = __( 'Invalid JSON file' );
|
|
51
62
|
break;
|
|
@@ -56,44 +67,54 @@ function ImportForm( { instanceId, onUpload } ) {
|
|
|
56
67
|
uiMessage = __( 'Unknown error' );
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
setError( uiMessage );
|
|
70
|
+
this.setState( { isLoading: false, error: uiMessage } );
|
|
61
71
|
} );
|
|
62
|
-
}
|
|
72
|
+
}
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
74
|
+
onDismissError() {
|
|
75
|
+
this.setState( { error: null } );
|
|
76
|
+
}
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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"
|
|
78
|
+
render() {
|
|
79
|
+
const { instanceId } = this.props;
|
|
80
|
+
const { file, isLoading, error } = this.state;
|
|
81
|
+
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
82
|
+
return (
|
|
83
|
+
<form
|
|
84
|
+
className="list-reusable-blocks-import-form"
|
|
85
|
+
onSubmit={ this.onSubmit }
|
|
92
86
|
>
|
|
93
|
-
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
{ error && (
|
|
88
|
+
<Notice
|
|
89
|
+
status="error"
|
|
90
|
+
onRemove={ () => this.onDismissError() }
|
|
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
|
+
}
|
|
97
118
|
}
|
|
98
119
|
|
|
99
120
|
export default withInstanceId( ImportForm );
|