@hitkey-io/strapi-plugin-region 1.0.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.
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const index = require("../_chunks/index-C8USiGWk.js");
3
+ require("react");
4
+ module.exports = index.index;
@@ -0,0 +1,5 @@
1
+ import { i } from "../_chunks/index-Cpq91_9N.mjs";
2
+ import "react";
3
+ export {
4
+ i as default
5
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ const PLUGIN_ID = "strapi-plugin-region";
3
+ const index = {
4
+ register({ strapi }) {
5
+ strapi.customFields.register({
6
+ name: "region-select",
7
+ plugin: PLUGIN_ID,
8
+ type: "string"
9
+ });
10
+ },
11
+ bootstrap({ strapi }) {
12
+ const regionFields = /* @__PURE__ */ new Set();
13
+ for (const contentType of Object.values(strapi.contentTypes)) {
14
+ for (const [attrName, attr] of Object.entries(contentType.attributes)) {
15
+ if (attr.customField === "plugin::strapi-plugin-region.region-select") {
16
+ regionFields.add(attrName);
17
+ }
18
+ }
19
+ }
20
+ if (regionFields.size === 0) return;
21
+ const parseRegionFields = (item) => {
22
+ if (!item || typeof item !== "object") return;
23
+ for (const field of regionFields) {
24
+ if (typeof item[field] === "string") {
25
+ try {
26
+ item[field] = JSON.parse(item[field]);
27
+ } catch {
28
+ }
29
+ }
30
+ }
31
+ };
32
+ strapi.server.use(async (ctx, next) => {
33
+ await next();
34
+ if (!ctx.url.startsWith("/api/")) return;
35
+ const data = ctx.body?.data;
36
+ if (!data) return;
37
+ if (Array.isArray(data)) {
38
+ data.forEach(parseRegionFields);
39
+ } else {
40
+ parseRegionFields(data);
41
+ }
42
+ });
43
+ }
44
+ };
45
+ module.exports = index;
@@ -0,0 +1,46 @@
1
+ const PLUGIN_ID = "strapi-plugin-region";
2
+ const index = {
3
+ register({ strapi }) {
4
+ strapi.customFields.register({
5
+ name: "region-select",
6
+ plugin: PLUGIN_ID,
7
+ type: "string"
8
+ });
9
+ },
10
+ bootstrap({ strapi }) {
11
+ const regionFields = /* @__PURE__ */ new Set();
12
+ for (const contentType of Object.values(strapi.contentTypes)) {
13
+ for (const [attrName, attr] of Object.entries(contentType.attributes)) {
14
+ if (attr.customField === "plugin::strapi-plugin-region.region-select") {
15
+ regionFields.add(attrName);
16
+ }
17
+ }
18
+ }
19
+ if (regionFields.size === 0) return;
20
+ const parseRegionFields = (item) => {
21
+ if (!item || typeof item !== "object") return;
22
+ for (const field of regionFields) {
23
+ if (typeof item[field] === "string") {
24
+ try {
25
+ item[field] = JSON.parse(item[field]);
26
+ } catch {
27
+ }
28
+ }
29
+ }
30
+ };
31
+ strapi.server.use(async (ctx, next) => {
32
+ await next();
33
+ if (!ctx.url.startsWith("/api/")) return;
34
+ const data = ctx.body?.data;
35
+ if (!data) return;
36
+ if (Array.isArray(data)) {
37
+ data.forEach(parseRegionFields);
38
+ } else {
39
+ parseRegionFields(data);
40
+ }
41
+ });
42
+ }
43
+ };
44
+ export {
45
+ index as default
46
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@hitkey-io/strapi-plugin-region",
3
+ "version": "1.0.0",
4
+ "description": "Strapi 5 custom field for selecting country and region",
5
+ "license": "MIT",
6
+ "author": "Nikolay Larsen <nikolay@velkomb.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hitkey-io/strapi-plugin-region.git"
10
+ },
11
+ "homepage": "https://github.com/hitkey-io/strapi-plugin-region#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/hitkey-io/strapi-plugin-region/issues"
14
+ },
15
+ "keywords": [
16
+ "strapi",
17
+ "strapi-plugin",
18
+ "strapi5",
19
+ "custom-field",
20
+ "country",
21
+ "region",
22
+ "geo"
23
+ ],
24
+ "type": "commonjs",
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ "./strapi-admin": {
28
+ "source": "./admin/src/index.ts",
29
+ "import": "./dist/admin/index.mjs",
30
+ "require": "./dist/admin/index.js",
31
+ "default": "./dist/admin/index.js"
32
+ },
33
+ "./strapi-server": {
34
+ "source": "./server/src/index.ts",
35
+ "import": "./dist/server/index.mjs",
36
+ "require": "./dist/server/index.js",
37
+ "default": "./dist/server/index.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "strapi-admin.js",
43
+ "strapi-server.js"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "strapi": {
49
+ "kind": "plugin",
50
+ "name": "strapi-plugin-region",
51
+ "displayName": "Region Select"
52
+ },
53
+ "dependencies": {},
54
+ "devDependencies": {
55
+ "@strapi/sdk-plugin": "^5.3.2"
56
+ },
57
+ "peerDependencies": {
58
+ "@strapi/design-system": "^2.0.0 || ^2.0.0-rc",
59
+ "@strapi/icons": "^2.0.0 || ^2.0.0-rc",
60
+ "@radix-ui/react-tooltip": "^1.0.0",
61
+ "@strapi/strapi": "^5.0.0 || ^5.0.0-rc",
62
+ "react": "^18.0.0",
63
+ "react-dom": "^18.0.0",
64
+ "react-intl": "^6.0.0",
65
+ "styled-components": "^6.0.0"
66
+ }
67
+ }