@wordpress/list-reusable-blocks 5.57.0 → 6.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/build/components/import-dropdown/index.cjs +39 -51
- package/build/components/import-dropdown/index.cjs.map +1 -7
- package/build/components/import-form/index.cjs +96 -109
- package/build/components/import-form/index.cjs.map +1 -7
- package/build/index.cjs +46 -53
- package/build/index.cjs.map +1 -7
- package/build/utils/export.cjs +44 -52
- package/build/utils/export.cjs.map +1 -7
- package/build/utils/file.cjs +20 -35
- package/build/utils/file.cjs.map +1 -7
- package/build/utils/import.cjs +48 -53
- package/build/utils/import.cjs.map +1 -7
- package/build/utils/types.cjs +4 -18
- package/build-module/components/import-dropdown/index.mjs +17 -25
- package/build-module/components/import-dropdown/index.mjs.map +1 -7
- package/build-module/components/import-form/index.mjs +72 -81
- package/build-module/components/import-form/index.mjs.map +1 -7
- package/build-module/index.mjs +24 -35
- package/build-module/index.mjs.map +1 -7
- package/build-module/utils/export.mjs +23 -28
- package/build-module/utils/export.mjs.map +1 -7
- package/build-module/utils/file.mjs +16 -11
- package/build-module/utils/file.mjs.map +1 -7
- package/build-module/utils/import.mjs +29 -30
- package/build-module/utils/import.mjs.map +1 -7
- package/build-module/utils/types.mjs +0 -1
- package/package.json +12 -13
- package/CHANGELOG.md +0 -317
- package/build/utils/types.cjs.map +0 -7
- package/build-module/utils/types.mjs.map +0 -7
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/export.ts"],
|
|
4
|
-
"sourcesContent": ["import { paramCase as kebabCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport apiFetch from '@wordpress/api-fetch';\nimport { downloadBlob } from '@wordpress/blob';\nimport type { Post, PostType } from './types';\n\n/**\n * Export a reusable block as a JSON file.\n *\n * @param id - The ID of the reusable block to export\n */\nasync function exportReusableBlock( id: number ): Promise< void > {\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst post = await apiFetch< Post >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`,\n\t} );\n\n\tconst title = post.title.raw;\n\tconst content = post.content.raw;\n\tconst syncStatus = post.wp_pattern_sync_status;\n\n\tconst fileContent = JSON.stringify(\n\t\t{\n\t\t\t__file: 'wp_block',\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tsyncStatus,\n\t\t},\n\t\tnull,\n\t\t2\n\t);\n\n\tconst fileName = kebabCase( removeAccents( title ) ) + '.json';\n\n\tdownloadBlob( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuC;AACvC,4BAA0B;AAC1B,uBAAqB;AACrB,kBAA6B;AAQ7B,eAAe,oBAAqB,IAA8B;AACjE,QAAM,WAAW,UAAM,iBAAAA,SAAsB;AAAA,IAC5C,MAAM;AAAA,EACP,CAAE;AAEF,QAAM,OAAO,UAAM,iBAAAA,SAAkB;AAAA,IACpC,MAAM,UAAW,SAAS,SAAU,IAAK,EAAG;AAAA,EAC7C,CAAE;AAEF,QAAM,QAAQ,KAAK,MAAM;AACzB,QAAM,UAAU,KAAK,QAAQ;AAC7B,QAAM,aAAa,KAAK;AAExB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,eAAW,mBAAAC,eAAW,sBAAAC,SAAe,KAAM,CAAE,IAAI;AAEvD,gCAAc,UAAU,aAAa,kBAAmB;AACzD;AAEA,IAAO,iBAAQ;",
|
|
6
|
-
"names": ["apiFetch", "kebabCase", "removeAccents"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"export.cjs","names":["apiFetch","kebabCase","removeAccents"],"sources":["../../src/utils/export.ts"],"sourcesContent":["import { paramCase as kebabCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport apiFetch from '@wordpress/api-fetch';\nimport { downloadBlob } from '@wordpress/blob';\nimport type { Post, PostType } from './types';\n\n/**\n * Export a reusable block as a JSON file.\n *\n * @param id - The ID of the reusable block to export\n */\nasync function exportReusableBlock( id: number ): Promise< void > {\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst post = await apiFetch< Post >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`,\n\t} );\n\n\tconst title = post.title.raw;\n\tconst content = post.content.raw;\n\tconst syncStatus = post.wp_pattern_sync_status;\n\n\tconst fileContent = JSON.stringify(\n\t\t{\n\t\t\t__file: 'wp_block',\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tsyncStatus,\n\t\t},\n\t\tnull,\n\t\t2\n\t);\n\n\tconst fileName = kebabCase( removeAccents( title ) ) + '.json';\n\n\tdownloadBlob( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,eAAe,oBAAqB,IAA8B;CACjE,MAAM,WAAW,OAAA,GAAMA,qBAAAA,QAAAA,CAAsB,EAC5C,MAAM,wBACP,CAAE;CAEF,MAAM,OAAO,OAAA,GAAMA,qBAAAA,QAAAA,CAAkB,EACpC,MAAM,UAAW,SAAS,UAAW,GAAI,GAAI,eAC9C,CAAE;CAEF,MAAM,QAAQ,KAAK,MAAM;CACzB,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,aAAa,KAAK;CAExB,MAAM,cAAc,KAAK,UACxB;EACC,QAAQ;EACR;EACA;EACA;CACD,GACA,MACA,CACD;CAEA,MAAM,YAAA,GAAWC,YAAAA,UAAAA,EAAAA,GAAWC,eAAAA,QAAAA,CAAe,KAAM,CAAE,IAAI;CAEvD,CAAA,GAAA,gBAAA,aAAA,CAAc,UAAU,aAAa,kBAAmB;AACzD"}
|
package/build/utils/file.cjs
CHANGED
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/list-reusable-blocks/src/utils/file.ts
|
|
21
|
-
var file_exports = {};
|
|
22
|
-
__export(file_exports, {
|
|
23
|
-
readTextFile: () => readTextFile
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
6
|
+
// packages/list-reusable-blocks/src/utils/file.ts
|
|
7
|
+
/**
|
|
8
|
+
* Reads the textual content of the given file.
|
|
9
|
+
*
|
|
10
|
+
* @param file - File to read
|
|
11
|
+
* @return Promise that resolves to the content of the file
|
|
12
|
+
*/
|
|
26
13
|
function readTextFile(file) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
const reader = new window.FileReader();
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
reader.onload = () => {
|
|
17
|
+
resolve(reader.result);
|
|
18
|
+
};
|
|
19
|
+
reader.readAsText(file);
|
|
20
|
+
});
|
|
34
21
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=file.cjs.map
|
|
22
|
+
exports.readTextFile = readTextFile;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=file.cjs.map
|
package/build/utils/file.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/file.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Reads the textual content of the given file.\n *\n * @param file - File to read\n * @return Promise that resolves to the content of the file\n */\nexport function readTextFile( file: File ): Promise< string > {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result as string );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,aAAc,MAAgC;AAC7D,QAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAO,IAAI,QAAS,CAAE,YAAa;AAClC,WAAO,SAAS,MAAM;AACrB,cAAS,OAAO,MAAiB;AAAA,IAClC;AACA,WAAO,WAAY,IAAK;AAAA,EACzB,CAAE;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"file.cjs","names":[],"sources":["../../src/utils/file.ts"],"sourcesContent":["/**\n * Reads the textual content of the given file.\n *\n * @param file - File to read\n * @return Promise that resolves to the content of the file\n */\nexport function readTextFile( file: File ): Promise< string > {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result as string );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;AAMA,SAAgB,aAAc,MAAgC;CAC7D,MAAM,SAAS,IAAI,OAAO,WAAW;CACrC,OAAO,IAAI,SAAW,YAAa;EAClC,OAAO,eAAe;GACrB,QAAS,OAAO,MAAiB;EAClC;EACA,OAAO,WAAY,IAAK;CACzB,CAAE;AACH"}
|
package/build/utils/import.cjs
CHANGED
|
@@ -1,65 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_api_fetch = require("@wordpress/api-fetch");
|
|
28
|
+
_wordpress_api_fetch = __toESM(_wordpress_api_fetch);
|
|
29
|
+
let __file_ts = require("./file.cjs");
|
|
30
30
|
// packages/list-reusable-blocks/src/utils/import.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var import_file = require("./file.cjs");
|
|
31
|
+
/**
|
|
32
|
+
* Import a reusable block from a JSON file.
|
|
33
|
+
*
|
|
34
|
+
* @param file - File to import
|
|
35
|
+
* @return Promise returning the imported reusable block
|
|
36
|
+
*/
|
|
38
37
|
async function importReusableBlock(file) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
|
|
59
|
-
},
|
|
60
|
-
method: "POST"
|
|
61
|
-
});
|
|
62
|
-
return reusableBlock;
|
|
38
|
+
const fileContent = await (0, __file_ts.readTextFile)(file);
|
|
39
|
+
let parsedContent;
|
|
40
|
+
try {
|
|
41
|
+
parsedContent = JSON.parse(fileContent);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error("Invalid JSON file");
|
|
44
|
+
}
|
|
45
|
+
if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") throw new Error("Invalid pattern JSON file");
|
|
46
|
+
const postType = await (0, _wordpress_api_fetch.default)({ path: `/wp/v2/types/wp_block` });
|
|
47
|
+
return await (0, _wordpress_api_fetch.default)({
|
|
48
|
+
path: `/wp/v2/${postType.rest_base}`,
|
|
49
|
+
data: {
|
|
50
|
+
title: parsedContent.title,
|
|
51
|
+
content: parsedContent.content,
|
|
52
|
+
status: "publish",
|
|
53
|
+
meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
|
|
54
|
+
},
|
|
55
|
+
method: "POST"
|
|
56
|
+
});
|
|
63
57
|
}
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
exports.default = importReusableBlock;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=import.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/import.ts"],
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { readTextFile } from './file';\nimport type {\n\tParsedContent,\n\tPostType,\n\tReusableBlock,\n\tReusableBlockData,\n} from './types';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param file - File to import\n * @return Promise returning the imported reusable block\n */\nasync function importReusableBlock( file: File ): Promise< ReusableBlock > {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent: ParsedContent;\n\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t}\n\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst reusableBlock = await apiFetch< ReusableBlock >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t} satisfies ReusableBlockData,\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AACrB,kBAA6B;AAc7B,eAAe,oBAAqB,MAAuC;AAC1E,QAAM,cAAc,UAAM,0BAAc,IAAK;AAC7C,MAAI;AAEJ,MAAI;AACH,oBAAgB,KAAK,MAAO,WAAY;AAAA,EACzC,QAAQ;AACP,UAAM,IAAI,MAAO,mBAAoB;AAAA,EACtC;AAEA,MACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UACpC;AACD,UAAM,IAAI,MAAO,2BAA4B;AAAA,EAC9C;AAEA,QAAM,WAAW,UAAM,iBAAAA,SAAsB;AAAA,IAC5C,MAAM;AAAA,EACP,CAAE;AAEF,QAAM,gBAAgB,UAAM,iBAAAA,SAA2B;AAAA,IACtD,MAAM,UAAW,SAAS,SAAU;AAAA,IACpC,MAAM;AAAA,MACL,OAAO,cAAc;AAAA,MACrB,SAAS,cAAc;AAAA,MACvB,QAAQ;AAAA,MACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACT,CAAE;AAEF,SAAO;AACR;AAEA,IAAO,iBAAQ;",
|
|
6
|
-
"names": ["apiFetch"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"import.cjs","names":["readTextFile","apiFetch"],"sources":["../../src/utils/import.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { readTextFile } from './file';\nimport type {\n\tParsedContent,\n\tPostType,\n\tReusableBlock,\n\tReusableBlockData,\n} from './types';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param file - File to import\n * @return Promise returning the imported reusable block\n */\nasync function importReusableBlock( file: File ): Promise< ReusableBlock > {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent: ParsedContent;\n\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t}\n\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst reusableBlock = await apiFetch< ReusableBlock >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t} satisfies ReusableBlockData,\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,eAAe,oBAAqB,MAAuC;CAC1E,MAAM,cAAc,OAAA,GAAMA,UAAAA,aAAAA,CAAc,IAAK;CAC7C,IAAI;CAEJ,IAAI;EACH,gBAAgB,KAAK,MAAO,WAAY;CACzC,QAAQ;EACP,MAAM,IAAI,MAAO,mBAAoB;CACtC;CAEA,IACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UAErC,MAAM,IAAI,MAAO,2BAA4B;CAG9C,MAAM,WAAW,OAAA,GAAMC,qBAAAA,QAAAA,CAAsB,EAC5C,MAAM,wBACP,CAAE;CAgBF,OAAO,OAAA,GAdqBA,qBAAAA,QAAAA,CAA2B;EACtD,MAAM,UAAW,SAAS;EAC1B,MAAM;GACL,OAAO,cAAc;GACrB,SAAS,cAAc;GACvB,QAAQ;GACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD,KAAA;EACL;EACA,QAAQ;CACT,CAAE;AAGH"}
|
package/build/utils/types.cjs
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// packages/list-reusable-blocks/src/utils/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
19
|
-
//# sourceMappingURL=types.cjs.map
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
// packages/list-reusable-blocks/src/components/import-dropdown/index.tsx
|
|
2
1
|
import { Button, Dropdown } from "@wordpress/components";
|
|
3
2
|
import { pipe } from "@wordpress/compose";
|
|
4
3
|
import { __ } from "@wordpress/i18n";
|
|
5
4
|
import ImportForm from "../import-form/index.mjs";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// packages/list-reusable-blocks/src/components/import-dropdown/index.tsx
|
|
7
7
|
function ImportDropdown({ onUpload }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
children: __("Import from JSON")
|
|
22
|
-
}
|
|
23
|
-
),
|
|
24
|
-
renderContent: ({ onClose }) => /* @__PURE__ */ jsx(ImportForm, { onUpload: pipe(onClose, onUpload) })
|
|
25
|
-
}
|
|
26
|
-
);
|
|
8
|
+
return /* @__PURE__ */ jsx(Dropdown, {
|
|
9
|
+
popoverProps: { placement: "bottom-start" },
|
|
10
|
+
contentClassName: "list-reusable-blocks-import-dropdown__content",
|
|
11
|
+
renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ jsx(Button, {
|
|
12
|
+
size: "compact",
|
|
13
|
+
className: "list-reusable-blocks-import-dropdown__button",
|
|
14
|
+
"aria-expanded": isOpen,
|
|
15
|
+
onClick: onToggle,
|
|
16
|
+
variant: "primary",
|
|
17
|
+
children: __("Import from JSON")
|
|
18
|
+
}),
|
|
19
|
+
renderContent: ({ onClose }) => /* @__PURE__ */ jsx(ImportForm, { onUpload: pipe(onClose, onUpload) })
|
|
20
|
+
});
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=index.mjs.map
|
|
22
|
+
export { ImportDropdown as default };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/import-dropdown/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Dropdown } from '@wordpress/components';\nimport { pipe } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport type { ImportDropdownProps } from '../../utils/types';\nimport ImportForm from '../import-form';\n\nfunction ImportDropdown( { onUpload }: ImportDropdownProps ) {\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\tcontentClassName=\"list-reusable-blocks-import-dropdown__content\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-dropdown__button\"\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Import from JSON' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<ImportForm onUpload={ pipe( onClose, onUpload ) } />\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default ImportDropdown;\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,QAAQ,gBAAgB;AACjC,SAAS,YAAY;AACrB,SAAS,UAAU;AAEnB,OAAO,gBAAgB;AAQnB;AANJ,SAAS,eAAgB,EAAE,SAAS,GAAyB;AAC5D,SACC;AAAA,IAAC;AAAA;AAAA,MACA,cAAe,EAAE,WAAW,eAAe;AAAA,MAC3C,kBAAiB;AAAA,MACjB,cAAe,CAAE,EAAE,QAAQ,SAAS,MACnC;AAAA,QAAC;AAAA;AAAA,UACA,MAAK;AAAA,UACL,WAAU;AAAA,UACV,iBAAgB;AAAA,UAChB,SAAU;AAAA,UACV,SAAQ;AAAA,UAEN,aAAI,kBAAmB;AAAA;AAAA,MAC1B;AAAA,MAED,eAAgB,CAAE,EAAE,QAAQ,MAC3B,oBAAC,cAAW,UAAW,KAAM,SAAS,QAAS,GAAI;AAAA;AAAA,EAErD;AAEF;AAEA,IAAO,0BAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/import-dropdown/index.tsx"],"sourcesContent":["import { Button, Dropdown } from '@wordpress/components';\nimport { pipe } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport type { ImportDropdownProps } from '../../utils/types';\nimport ImportForm from '../import-form';\n\nfunction ImportDropdown( { onUpload }: ImportDropdownProps ) {\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\tcontentClassName=\"list-reusable-blocks-import-dropdown__content\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-dropdown__button\"\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Import from JSON' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<ImportForm onUpload={ pipe( onClose, onUpload ) } />\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default ImportDropdown;\n"],"mappings":";;;;;;AAMA,SAAS,eAAgB,EAAE,YAAkC;CAC5D,OACC,oBAAC,UAAD;EACC,cAAe,EAAE,WAAW,eAAe;EAC3C,kBAAiB;EACjB,eAAiB,EAAE,QAAQ,eAC1B,oBAAC,QAAD;GACC,MAAK;GACL,WAAU;GACV,iBAAgB;GAChB,SAAU;GACV,SAAQ;GAEN,UAAA,GAAI,kBAAmB;EAClB,CAAA;EAET,gBAAkB,EAAE,cACnB,oBAAC,YAAD,EAAY,UAAW,KAAM,SAAS,QAAS,EAAK,CAAA;CAErD,CAAA;AAEH"}
|
|
@@ -1,90 +1,81 @@
|
|
|
1
|
-
// packages/list-reusable-blocks/src/components/import-form/index.tsx
|
|
2
1
|
import { Button, Notice } from "@wordpress/components";
|
|
3
2
|
import { withInstanceId } from "@wordpress/compose";
|
|
4
3
|
import { useRef, useState } from "@wordpress/element";
|
|
5
4
|
import { __, _x } from "@wordpress/i18n";
|
|
6
5
|
import importReusableBlock from "../../utils/import.mjs";
|
|
7
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// packages/list-reusable-blocks/src/components/import-form/index.tsx
|
|
8
8
|
function ImportForm({ instanceId, onUpload }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
variant: "secondary",
|
|
78
|
-
className: "list-reusable-blocks-import-form__button",
|
|
79
|
-
children: _x("Import", "button label")
|
|
80
|
-
}
|
|
81
|
-
)
|
|
82
|
-
]
|
|
83
|
-
}
|
|
84
|
-
);
|
|
9
|
+
const inputId = "list-reusable-blocks-import-form-" + instanceId;
|
|
10
|
+
const formRef = useRef(null);
|
|
11
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
12
|
+
const [error, setError] = useState(null);
|
|
13
|
+
const [file, setFile] = useState(null);
|
|
14
|
+
const onChangeFile = (event) => {
|
|
15
|
+
setFile(event.target.files?.[0] || null);
|
|
16
|
+
setError(null);
|
|
17
|
+
};
|
|
18
|
+
const onSubmit = (event) => {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
if (!file) return;
|
|
21
|
+
setIsLoading(true);
|
|
22
|
+
importReusableBlock(file).then((reusableBlock) => {
|
|
23
|
+
if (!formRef.current) return;
|
|
24
|
+
setIsLoading(false);
|
|
25
|
+
onUpload(reusableBlock);
|
|
26
|
+
}).catch((errors) => {
|
|
27
|
+
if (!formRef.current) return;
|
|
28
|
+
let uiMessage;
|
|
29
|
+
switch (errors.message) {
|
|
30
|
+
case "Invalid JSON file":
|
|
31
|
+
uiMessage = __("Invalid JSON file");
|
|
32
|
+
break;
|
|
33
|
+
case "Invalid pattern JSON file":
|
|
34
|
+
uiMessage = __("Invalid pattern JSON file");
|
|
35
|
+
break;
|
|
36
|
+
default: uiMessage = __("Unknown error");
|
|
37
|
+
}
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
setError(uiMessage);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const onDismissError = () => {
|
|
43
|
+
setError(null);
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
46
|
+
className: "list-reusable-blocks-import-form",
|
|
47
|
+
onSubmit,
|
|
48
|
+
ref: formRef,
|
|
49
|
+
children: [
|
|
50
|
+
error && /* @__PURE__ */ jsx(Notice, {
|
|
51
|
+
status: "error",
|
|
52
|
+
onRemove: () => onDismissError(),
|
|
53
|
+
children: error
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ jsx("label", {
|
|
56
|
+
htmlFor: inputId,
|
|
57
|
+
className: "list-reusable-blocks-import-form__label",
|
|
58
|
+
children: __("File")
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx("input", {
|
|
61
|
+
id: inputId,
|
|
62
|
+
type: "file",
|
|
63
|
+
onChange: onChangeFile
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ jsx(Button, {
|
|
66
|
+
__next40pxDefaultSize: true,
|
|
67
|
+
type: "submit",
|
|
68
|
+
isBusy: isLoading,
|
|
69
|
+
accessibleWhenDisabled: true,
|
|
70
|
+
disabled: !file || isLoading,
|
|
71
|
+
variant: "secondary",
|
|
72
|
+
className: "list-reusable-blocks-import-form__button",
|
|
73
|
+
children: _x("Import", "button label")
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
85
77
|
}
|
|
86
78
|
var import_form_default = withInstanceId(ImportForm);
|
|
87
|
-
export {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
//# sourceMappingURL=index.mjs.map
|
|
79
|
+
export { import_form_default as default };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/import-form/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Notice } from '@wordpress/components';\nimport { withInstanceId } from '@wordpress/compose';\nimport { useRef, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport importReusableBlock from '../../utils/import';\nimport type { ImportFormProps, ReusableBlock } from '../../utils/types';\n\nfunction ImportForm( { instanceId, onUpload }: ImportFormProps ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef< HTMLFormElement >( null );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState< string | null >( null );\n\tconst [ file, setFile ] = useState< File | null >( null );\n\n\tconst onChangeFile = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetFile( event.target.files?.[ 0 ] || null );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event: React.FormEvent< HTMLFormElement > ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( true );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock: ReusableBlock ) => {\n\t\t\t\tif ( ! formRef.current ) {\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: Error ) => {\n\t\t\t\tif ( ! formRef.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage: string;\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 pattern JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid pattern 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\t__next40pxDefaultSize\n\t\t\t\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\n\t\t\t\taccessibleWhenDisabled\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"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,QAAQ,cAAc;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,QAAQ,gBAAgB;AACjC,SAAS,IAAI,UAAU;AACvB,OAAO,yBAAyB;AA0D9B,SAME,KANF;AAvDF,SAAS,WAAY,EAAE,YAAY,SAAS,GAAqB;AAChE,QAAM,UAAU,sCAAsC;AAEtD,QAAM,UAAU,OAA2B,IAAK;AAChD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,OAAO,QAAS,IAAI,SAA2B,IAAK;AAC5D,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAyB,IAAK;AAExD,QAAM,eAAe,CAAE,UAAkD;AACxE,YAAS,MAAM,OAAO,QAAS,CAAE,KAAK,IAAK;AAC3C,aAAU,IAAK;AAAA,EAChB;AAEA,QAAM,WAAW,CAAE,UAA+C;AACjE,UAAM,eAAe;AACrB,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,iBAAc,IAAK;AACnB,wBAAqB,IAAK,EACxB,KAAM,CAAE,kBAAkC;AAC1C,UAAK,CAAE,QAAQ,SAAU;AACxB;AAAA,MACD;AAEA,mBAAc,KAAM;AACpB,eAAU,aAAc;AAAA,IACzB,CAAE,EACD,MAAO,CAAE,WAAmB;AAC5B,UAAK,CAAE,QAAQ,SAAU;AACxB;AAAA,MACD;AAEA,UAAI;AACJ,cAAS,OAAO,SAAU;AAAA,QACzB,KAAK;AACJ,sBAAY,GAAI,mBAAoB;AACpC;AAAA,QACD,KAAK;AACJ,sBAAY,GAAI,2BAA4B;AAC5C;AAAA,QACD;AACC,sBAAY,GAAI,eAAgB;AAAA,MAClC;AAEA,mBAAc,KAAM;AACpB,eAAU,SAAU;AAAA,IACrB,CAAE;AAAA,EACJ;AAEA,QAAM,iBAAiB,MAAM;AAC5B,aAAU,IAAK;AAAA,EAChB;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV;AAAA,MACA,KAAM;AAAA,MAEJ;AAAA,iBACD,oBAAC,UAAO,QAAO,SAAQ,UAAW,MAAM,eAAe,GACpD,iBACH;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA,SAAU;AAAA,YACV,WAAU;AAAA,YAER,aAAI,MAAO;AAAA;AAAA,QACd;AAAA,QACA,oBAAC,WAAM,IAAK,SAAU,MAAK,QAAO,UAAW,cAAe;AAAA,QAC5D;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,MAAK;AAAA,YACL,QAAS;AAAA,YACT,wBAAsB;AAAA,YACtB,UAAW,CAAE,QAAQ;AAAA,YACrB,SAAQ;AAAA,YACR,WAAU;AAAA,YAER,aAAI,UAAU,cAAe;AAAA;AAAA,QAChC;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,sBAAQ,eAAgB,UAAW;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCNotice"],"sources":["../../../src/components/import-form/index.tsx"],"sourcesContent":["import { Button, Notice as WCNotice } from '@wordpress/components';\nimport { withInstanceId } from '@wordpress/compose';\nimport { useRef, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport importReusableBlock from '../../utils/import';\nimport type { ImportFormProps, ReusableBlock } from '../../utils/types';\n\nfunction ImportForm( { instanceId, onUpload }: ImportFormProps ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef< HTMLFormElement >( null );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState< string | null >( null );\n\tconst [ file, setFile ] = useState< File | null >( null );\n\n\tconst onChangeFile = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetFile( event.target.files?.[ 0 ] || null );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event: React.FormEvent< HTMLFormElement > ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( true );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock: ReusableBlock ) => {\n\t\t\t\tif ( ! formRef.current ) {\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: Error ) => {\n\t\t\t\tif ( ! formRef.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage: string;\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 pattern JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid pattern 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<WCNotice status=\"error\" onRemove={ () => onDismissError() }>\n\t\t\t\t\t{ error }\n\t\t\t\t</WCNotice>\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\t__next40pxDefaultSize\n\t\t\t\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\n\t\t\t\taccessibleWhenDisabled\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"],"mappings":";;;;;;;AAOA,SAAS,WAAY,EAAE,YAAY,YAA8B;CAChE,MAAM,UAAU,sCAAsC;CAEtD,MAAM,UAAU,OAA2B,IAAK;CAChD,MAAM,CAAE,WAAW,gBAAiB,SAAU,KAAM;CACpD,MAAM,CAAE,OAAO,YAAa,SAA2B,IAAK;CAC5D,MAAM,CAAE,MAAM,WAAY,SAAyB,IAAK;CAExD,MAAM,gBAAiB,UAAkD;EACxE,QAAS,MAAM,OAAO,QAAS,MAAO,IAAK;EAC3C,SAAU,IAAK;CAChB;CAEA,MAAM,YAAa,UAA+C;EACjE,MAAM,eAAe;EACrB,IAAK,CAAE,MACN;EAED,aAAc,IAAK;EACnB,oBAAqB,IAAK,CAAC,CACzB,MAAQ,kBAAkC;GAC1C,IAAK,CAAE,QAAQ,SACd;GAGD,aAAc,KAAM;GACpB,SAAU,aAAc;EACzB,CAAE,CAAC,CACF,OAAS,WAAmB;GAC5B,IAAK,CAAE,QAAQ,SACd;GAGD,IAAI;GACJ,QAAS,OAAO,SAAhB;IACC,KAAK;KACJ,YAAY,GAAI,mBAAoB;KACpC;IACD,KAAK;KACJ,YAAY,GAAI,2BAA4B;KAC5C;IACD,SACC,YAAY,GAAI,eAAgB;GAClC;GAEA,aAAc,KAAM;GACpB,SAAU,SAAU;EACrB,CAAE;CACJ;CAEA,MAAM,uBAAuB;EAC5B,SAAU,IAAK;CAChB;CAEA,OACC,qBAAC,QAAD;EACC,WAAU;EACC;EACX,KAAM;EAHP,UAAA;GAKG,SACD,oBAACA,QAAD;IAAU,QAAO;IAAQ,gBAAiB,eAAe;IACtD,UAAA;GACO,CAAA;GAEX,oBAAC,SAAD;IACC,SAAU;IACV,WAAU;IAER,UAAA,GAAI,MAAO;GACP,CAAA;GACP,oBAAC,SAAD;IAAO,IAAK;IAAU,MAAK;IAAO,UAAW;GAAgB,CAAA;GAC7D,oBAAC,QAAD;IACC,uBAAA;IACA,MAAK;IACL,QAAS;IACT,wBAAA;IACA,UAAW,CAAE,QAAQ;IACrB,SAAQ;IACR,WAAU;IAER,UAAA,GAAI,UAAU,cAAe;GACxB,CAAA;EACH;;AAER;AAEA,IAAA,sBAAe,eAAgB,UAAW"}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,43 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import { createRoot, StrictMode } from "@wordpress/element";
|
|
1
|
+
import { StrictMode, createRoot } from "@wordpress/element";
|
|
3
2
|
import { __ } from "@wordpress/i18n";
|
|
4
3
|
import ImportDropdown from "./components/import-dropdown/index.mjs";
|
|
5
4
|
import exportReusableBlock from "./utils/export.mjs";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// packages/list-reusable-blocks/src/index.tsx
|
|
7
7
|
document.body.addEventListener("click", (event) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const blockId = target.dataset.id;
|
|
14
|
-
if (blockId) {
|
|
15
|
-
exportReusableBlock(Number(blockId));
|
|
16
|
-
}
|
|
8
|
+
const target = event.target;
|
|
9
|
+
if (!target.classList.contains("wp-list-reusable-blocks__export")) return;
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
const blockId = target.dataset.id;
|
|
12
|
+
if (blockId) exportReusableBlock(Number(blockId));
|
|
17
13
|
});
|
|
18
14
|
document.addEventListener("DOMContentLoaded", () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
container.className = "list-reusable-blocks__container";
|
|
35
|
-
if (!button.parentNode) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
button.parentNode.insertBefore(container, button);
|
|
39
|
-
createRoot(container).render(
|
|
40
|
-
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(ImportDropdown, { onUpload: showNotice }) })
|
|
41
|
-
);
|
|
15
|
+
const button = document.querySelector(".page-title-action");
|
|
16
|
+
if (!button) return;
|
|
17
|
+
const showNotice = () => {
|
|
18
|
+
const notice = document.createElement("div");
|
|
19
|
+
notice.className = "notice notice-success is-dismissible";
|
|
20
|
+
notice.innerHTML = `<p>${__("Pattern imported successfully!")}</p>`;
|
|
21
|
+
const headerEnd = document.querySelector(".wp-header-end");
|
|
22
|
+
if (!headerEnd || !headerEnd.parentNode) return;
|
|
23
|
+
headerEnd.parentNode.insertBefore(notice, headerEnd);
|
|
24
|
+
};
|
|
25
|
+
const container = document.createElement("div");
|
|
26
|
+
container.className = "list-reusable-blocks__container";
|
|
27
|
+
if (!button.parentNode) return;
|
|
28
|
+
button.parentNode.insertBefore(container, button);
|
|
29
|
+
createRoot(container).render(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(ImportDropdown, { onUpload: showNotice }) }));
|
|
42
30
|
});
|
|
43
|
-
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createRoot, StrictMode } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ImportDropdown from './components/import-dropdown';\nimport exportReusableBlock from './utils/export';\n\n// Setup Export Links.\ndocument.body.addEventListener( 'click', ( event: MouseEvent ) => {\n\tconst target = event.target as HTMLElement;\n\n\tif ( ! target.classList.contains( 'wp-list-reusable-blocks__export' ) ) {\n\t\treturn;\n\t}\n\n\tevent.preventDefault();\n\n\tconst blockId = target.dataset.id;\n\tif ( blockId ) {\n\t\texportReusableBlock( Number( blockId ) );\n\t}\n} );\n\n// Setup Import Form.\ndocument.addEventListener( 'DOMContentLoaded', () => {\n\tconst button = document.querySelector( '.page-title-action' );\n\tif ( ! button ) {\n\t\treturn;\n\t}\n\n\tconst showNotice = () => {\n\t\tconst notice = document.createElement( 'div' );\n\t\tnotice.className = 'notice notice-success is-dismissible';\n\t\tnotice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;\n\n\t\tconst headerEnd = document.querySelector( '.wp-header-end' );\n\t\tif ( ! headerEnd || ! headerEnd.parentNode ) {\n\t\t\treturn;\n\t\t}\n\t\theaderEnd.parentNode.insertBefore( notice, headerEnd );\n\t};\n\n\tconst container = document.createElement( 'div' );\n\tcontainer.className = 'list-reusable-blocks__container';\n\n\tif ( ! button.parentNode ) {\n\t\treturn;\n\t}\n\n\tbutton.parentNode.insertBefore( container, button );\n\tcreateRoot( container ).render(\n\t\t<StrictMode>\n\t\t\t<ImportDropdown onUpload={ showNotice } />\n\t\t</StrictMode>\n\t);\n} );\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,UAAU;AACnB,OAAO,oBAAoB;AAC3B,OAAO,yBAAyB;AA+C7B;AA5CH,SAAS,KAAK,iBAAkB,SAAS,CAAE,UAAuB;AACjE,QAAM,SAAS,MAAM;AAErB,MAAK,CAAE,OAAO,UAAU,SAAU,iCAAkC,GAAI;AACvE;AAAA,EACD;AAEA,QAAM,eAAe;AAErB,QAAM,UAAU,OAAO,QAAQ;AAC/B,MAAK,SAAU;AACd,wBAAqB,OAAQ,OAAQ,CAAE;AAAA,EACxC;AACD,CAAE;AAGF,SAAS,iBAAkB,oBAAoB,MAAM;AACpD,QAAM,SAAS,SAAS,cAAe,oBAAqB;AAC5D,MAAK,CAAE,QAAS;AACf;AAAA,EACD;AAEA,QAAM,aAAa,MAAM;AACxB,UAAM,SAAS,SAAS,cAAe,KAAM;AAC7C,WAAO,YAAY;AACnB,WAAO,YAAY,MAAO,GAAI,gCAAiC,CAAE;AAEjE,UAAM,YAAY,SAAS,cAAe,gBAAiB;AAC3D,QAAK,CAAE,aAAa,CAAE,UAAU,YAAa;AAC5C;AAAA,IACD;AACA,cAAU,WAAW,aAAc,QAAQ,SAAU;AAAA,EACtD;AAEA,QAAM,YAAY,SAAS,cAAe,KAAM;AAChD,YAAU,YAAY;AAEtB,MAAK,CAAE,OAAO,YAAa;AAC1B;AAAA,EACD;AAEA,SAAO,WAAW,aAAc,WAAW,MAAO;AAClD,aAAY,SAAU,EAAE;AAAA,IACvB,oBAAC,cACA,8BAAC,kBAAe,UAAW,YAAa,GACzC;AAAA,EACD;AACD,CAAE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["import { createRoot, StrictMode } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ImportDropdown from './components/import-dropdown';\nimport exportReusableBlock from './utils/export';\n\n// Setup Export Links.\ndocument.body.addEventListener( 'click', ( event: MouseEvent ) => {\n\tconst target = event.target as HTMLElement;\n\n\tif ( ! target.classList.contains( 'wp-list-reusable-blocks__export' ) ) {\n\t\treturn;\n\t}\n\n\tevent.preventDefault();\n\n\tconst blockId = target.dataset.id;\n\tif ( blockId ) {\n\t\texportReusableBlock( Number( blockId ) );\n\t}\n} );\n\n// Setup Import Form.\ndocument.addEventListener( 'DOMContentLoaded', () => {\n\tconst button = document.querySelector( '.page-title-action' );\n\tif ( ! button ) {\n\t\treturn;\n\t}\n\n\tconst showNotice = () => {\n\t\tconst notice = document.createElement( 'div' );\n\t\tnotice.className = 'notice notice-success is-dismissible';\n\t\tnotice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;\n\n\t\tconst headerEnd = document.querySelector( '.wp-header-end' );\n\t\tif ( ! headerEnd || ! headerEnd.parentNode ) {\n\t\t\treturn;\n\t\t}\n\t\theaderEnd.parentNode.insertBefore( notice, headerEnd );\n\t};\n\n\tconst container = document.createElement( 'div' );\n\tcontainer.className = 'list-reusable-blocks__container';\n\n\tif ( ! button.parentNode ) {\n\t\treturn;\n\t}\n\n\tbutton.parentNode.insertBefore( container, button );\n\tcreateRoot( container ).render(\n\t\t<StrictMode>\n\t\t\t<ImportDropdown onUpload={ showNotice } />\n\t\t</StrictMode>\n\t);\n} );\n"],"mappings":";;;;;;AAMA,SAAS,KAAK,iBAAkB,UAAW,UAAuB;CACjE,MAAM,SAAS,MAAM;CAErB,IAAK,CAAE,OAAO,UAAU,SAAU,iCAAkC,GACnE;CAGD,MAAM,eAAe;CAErB,MAAM,UAAU,OAAO,QAAQ;CAC/B,IAAK,SACJ,oBAAqB,OAAQ,OAAQ,CAAE;AAEzC,CAAE;AAGF,SAAS,iBAAkB,0BAA0B;CACpD,MAAM,SAAS,SAAS,cAAe,oBAAqB;CAC5D,IAAK,CAAE,QACN;CAGD,MAAM,mBAAmB;EACxB,MAAM,SAAS,SAAS,cAAe,KAAM;EAC7C,OAAO,YAAY;EACnB,OAAO,YAAY,MAAO,GAAI,gCAAiC,EAAG;EAElE,MAAM,YAAY,SAAS,cAAe,gBAAiB;EAC3D,IAAK,CAAE,aAAa,CAAE,UAAU,YAC/B;EAED,UAAU,WAAW,aAAc,QAAQ,SAAU;CACtD;CAEA,MAAM,YAAY,SAAS,cAAe,KAAM;CAChD,UAAU,YAAY;CAEtB,IAAK,CAAE,OAAO,YACb;CAGD,OAAO,WAAW,aAAc,WAAW,MAAO;CAClD,WAAY,SAAU,CAAC,CAAC,OACvB,oBAAC,YAAD,EAAA,UACC,oBAAC,gBAAD,EAAgB,UAAW,WAAc,CAAA,EAC9B,CAAA,CACb;AACD,CAAE"}
|