@mattisvensson/strapi-plugin-webatlas 0.10.1 → 0.11.1

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.
Files changed (50) hide show
  1. package/README.md +16 -9
  2. package/dist/admin/{FullLoader-CrPED_dY.mjs → FullLoader-Btjb2W2p.mjs} +5 -1
  3. package/dist/admin/FullLoader-Btjb2W2p.mjs.map +1 -0
  4. package/dist/admin/{FullLoader-Cmsf8xS6.js → FullLoader-Da2n70bJ.js} +5 -1
  5. package/dist/admin/FullLoader-Da2n70bJ.js.map +1 -0
  6. package/dist/admin/{SettingTitle-uw1S5OmC.js → SettingTitle-B0quw3f8.js} +6 -2
  7. package/dist/admin/SettingTitle-B0quw3f8.js.map +1 -0
  8. package/dist/admin/{SettingTitle-DbsxB1V9.mjs → SettingTitle-HMfQOJnK.mjs} +6 -2
  9. package/dist/admin/SettingTitle-HMfQOJnK.mjs.map +1 -0
  10. package/dist/admin/de-B5pRvs13.mjs +1 -0
  11. package/dist/admin/de-B5pRvs13.mjs.map +1 -0
  12. package/dist/admin/de-CqU1FU8C.js +1 -0
  13. package/dist/admin/de-CqU1FU8C.js.map +1 -0
  14. package/dist/admin/en-BE-zzIv8.mjs +1 -0
  15. package/dist/admin/en-BE-zzIv8.mjs.map +1 -0
  16. package/dist/admin/en-C7I90FwV.js +1 -0
  17. package/dist/admin/en-C7I90FwV.js.map +1 -0
  18. package/dist/admin/{index-BKWY9Ta-.mjs → index-9_HhKDUC.mjs} +32 -58
  19. package/dist/admin/index-9_HhKDUC.mjs.map +1 -0
  20. package/dist/admin/{index-CIr8o1RP.mjs → index-B79ELMEC.mjs} +300 -282
  21. package/dist/admin/index-B79ELMEC.mjs.map +1 -0
  22. package/dist/admin/{index-DkqiqVx2.js → index-BEVoxEAm.js} +32 -58
  23. package/dist/admin/index-BEVoxEAm.js.map +1 -0
  24. package/dist/admin/index-Bmg-ERct.mjs +244 -0
  25. package/dist/admin/index-Bmg-ERct.mjs.map +1 -0
  26. package/dist/admin/{index-BXt-QjKo.js → index-C8YjuuOx.js} +497 -353
  27. package/dist/admin/index-C8YjuuOx.js.map +1 -0
  28. package/dist/admin/{index-DC5WwNdi.js → index-Cx_mktdk.js} +300 -282
  29. package/dist/admin/index-Cx_mktdk.js.map +1 -0
  30. package/dist/admin/{index-CUaBX_v-.mjs → index-Cz_k_jjp.mjs} +42 -30
  31. package/dist/admin/index-Cz_k_jjp.mjs.map +1 -0
  32. package/dist/admin/{index-BYlmJycd.js → index-D2hB1vTw.js} +42 -30
  33. package/dist/admin/index-D2hB1vTw.js.map +1 -0
  34. package/dist/admin/index-YdWxpvOH.js +244 -0
  35. package/dist/admin/index-YdWxpvOH.js.map +1 -0
  36. package/dist/admin/{index-tPrfjOIn.mjs → index-oEJT_mvw.mjs} +497 -353
  37. package/dist/admin/index-oEJT_mvw.mjs.map +1 -0
  38. package/dist/admin/index.js +2 -1
  39. package/dist/admin/index.js.map +1 -0
  40. package/dist/admin/index.mjs +2 -1
  41. package/dist/admin/index.mjs.map +1 -0
  42. package/dist/server/index.js +578 -394
  43. package/dist/server/index.js.map +1 -0
  44. package/dist/server/index.mjs +578 -394
  45. package/dist/server/index.mjs.map +1 -0
  46. package/package.json +108 -108
  47. package/dist/admin/index-B07KlG03.mjs +0 -218
  48. package/dist/admin/index-CGsC8P9P.js +0 -218
  49. package/dist/admin/src/index.d.ts +0 -12
  50. package/dist/server/src/index.d.ts +0 -301
package/package.json CHANGED
@@ -1,110 +1,110 @@
1
1
  {
2
- "version": "0.10.1",
3
- "keywords": [],
4
- "type": "commonjs",
5
- "exports": {
6
- "./package.json": "./package.json",
7
- "./strapi-admin": {
8
- "types": "./dist/admin/src/index.d.ts",
9
- "source": "./admin/src/index.tsx",
10
- "import": "./dist/admin/index.mjs",
11
- "require": "./dist/admin/index.js",
12
- "default": "./dist/admin/index.js"
13
- },
14
- "./strapi-server": {
15
- "types": "./dist/server/src/index.d.ts",
16
- "source": "./server/src/index.ts",
17
- "import": "./dist/server/index.mjs",
18
- "require": "./dist/server/index.js",
19
- "default": "./dist/server/index.js"
20
- }
21
- },
22
- "files": [
23
- "dist"
24
- ],
25
- "scripts": {
26
- "build": "strapi-plugin build && yalc push --publish",
27
- "watch": "strapi-plugin watch",
28
- "watch:link": "strapi-plugin watch:link",
29
- "verify": "strapi-plugin verify",
30
- "test:ts:front": "tsc -p admin/tsconfig.json",
31
- "test:ts:back": "tsc -p server/tsconfig.json",
32
- "test:jest": "ENV_PATH=./playground/.env jest --verbose --runInBand --forceExit",
33
- "test:cypress": "cypress run",
34
- "test:cypress:open": "cypress open",
35
- "preversion": "yarn build",
36
- "postversion": "git push && git push --tags"
37
- },
38
- "dependencies": {
39
- "@dnd-kit/core": "^6.3.1",
40
- "@dnd-kit/sortable": "^10.0.0",
41
- "@dnd-kit/utilities": "^3.2.2"
42
- },
43
- "devDependencies": {
44
- "@strapi/admin": "^5.0.0",
45
- "@strapi/pack-up": "^5.0.0",
46
- "@strapi/utils": "^5.0.0",
47
- "@strapi/content-manager": "^5.0.0",
48
- "@strapi/design-system": "^2.0.0",
49
- "@strapi/icons": "^2.0.0",
50
- "@strapi/sdk-plugin": "^6.0.0",
51
- "@strapi/strapi": "^5.0.0",
52
- "@strapi/typescript-utils": "^5.0.0",
53
- "@types/react": "^19.0.0",
54
- "@types/react-dom": "^19.0.0",
55
- "@types/lodash": "^4",
56
- "eslint": "^8.57.1",
57
- "cypress": "^13.9.0",
58
- "cypress-terminal-report": "^6.0.2",
59
- "jest": "^29.7.0",
60
- "prettier": "^3.4.2",
61
- "react": "^18.0.0",
62
- "react-intl": "^6.0.0",
63
- "react-dom": "^18.0.0",
64
- "react-router-dom": "^6.0.0",
65
- "supertest": "^7.0.0",
66
- "typescript": "^5.7.2"
67
- },
68
- "peerDependencies": {
69
- "@strapi/admin": "^5.0.0",
70
- "@strapi/utils": "^5.0.0",
71
- "@strapi/strapi": "^5.0.0",
72
- "@strapi/design-system": "^2.0.0",
73
- "@strapi/icons": "^2.0.0",
74
- "react-intl": "^6.0.0",
75
- "react": "^17.0.0 || ^18.0.0",
76
- "react-dom": "^17.0.0 || ^18.0.0",
77
- "react-router-dom": "^6.0.0",
78
- "styled-components": "^6.0.0"
79
- },
80
- "description": "A strapi plugin to manage URL routes and navigations.",
81
- "strapi": {
82
- "name": "webatlas",
83
- "displayName": "Webatlas",
84
- "description": "A strapi plugin to manage URL routes and navigations.",
85
- "kind": "plugin"
86
- },
87
- "name": "@mattisvensson/strapi-plugin-webatlas",
88
- "license": "MIT",
89
- "repository": {
90
- "type": "git",
91
- "url": "git+ssh://git@github.com:mattisvensson/strapi-plugin-webatlas.git"
92
- },
93
- "bugs": {
94
- "url": "https://github.com/mattisvensson/strapi-plugin-webatlas/issues"
95
- },
96
- "homepage": "https://github.com/mattisvensson/strapi-plugin-webatlas#readme",
97
- "author": {
98
- "name": "Matti Svensson",
99
- "email": "mattisvensson@web.de",
100
- "url": "https://mattisvensson.dev"
101
- },
102
- "maintainers": [
103
- {
104
- "name": "Matti Svensson",
105
- "email": "mattisvensson@web.de",
106
- "url": "https://mattisvensson.dev"
107
- }
108
- ],
109
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2
+ "version": "0.11.1",
3
+ "keywords": [],
4
+ "type": "commonjs",
5
+ "exports": {
6
+ "./package.json": "./package.json",
7
+ "./strapi-admin": {
8
+ "types": "./dist/admin/src/index.d.ts",
9
+ "source": "./admin/src/index.tsx",
10
+ "import": "./dist/admin/index.mjs",
11
+ "require": "./dist/admin/index.js",
12
+ "default": "./dist/admin/index.js"
13
+ },
14
+ "./strapi-server": {
15
+ "types": "./dist/server/src/index.d.ts",
16
+ "source": "./server/src/index.ts",
17
+ "import": "./dist/server/index.mjs",
18
+ "require": "./dist/server/index.js",
19
+ "default": "./dist/server/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "strapi-plugin build && yalc push --publish",
27
+ "watch": "strapi-plugin watch",
28
+ "watch:link": "strapi-plugin watch:link",
29
+ "verify": "strapi-plugin verify",
30
+ "test:ts:front": "tsc -p admin/tsconfig.json",
31
+ "test:ts:back": "tsc -p server/tsconfig.json",
32
+ "test:jest": "ENV_PATH=./playground/.env jest --verbose --runInBand --forceExit",
33
+ "test:cypress": "cypress run",
34
+ "test:cypress:open": "cypress open",
35
+ "preversion": "yarn build",
36
+ "postversion": "git push && git push --tags"
37
+ },
38
+ "dependencies": {
39
+ "@dnd-kit/core": "^6.3.1",
40
+ "@dnd-kit/sortable": "^10.0.0",
41
+ "@dnd-kit/utilities": "^3.2.2"
42
+ },
43
+ "devDependencies": {
44
+ "@strapi/admin": "^5.0.0",
45
+ "@strapi/pack-up": "^5.0.0",
46
+ "@strapi/utils": "^5.0.0",
47
+ "@strapi/content-manager": "^5.0.0",
48
+ "@strapi/design-system": "^2.0.0",
49
+ "@strapi/icons": "^2.0.0",
50
+ "@strapi/sdk-plugin": "^6.0.0",
51
+ "@strapi/strapi": "^5.0.0",
52
+ "@strapi/typescript-utils": "^5.0.0",
53
+ "@types/react": "^19.0.0",
54
+ "@types/react-dom": "^19.0.0",
55
+ "@types/lodash": "^4",
56
+ "eslint": "^8.57.1",
57
+ "cypress": "^13.9.0",
58
+ "cypress-terminal-report": "^6.0.2",
59
+ "jest": "^29.7.0",
60
+ "prettier": "^3.4.2",
61
+ "react": "^18.0.0",
62
+ "react-intl": "^6.0.0",
63
+ "react-dom": "^18.0.0",
64
+ "react-router-dom": "^6.0.0",
65
+ "supertest": "^7.0.0",
66
+ "typescript": "^5.7.2"
67
+ },
68
+ "peerDependencies": {
69
+ "@strapi/admin": "^5.0.0",
70
+ "@strapi/utils": "^5.0.0",
71
+ "@strapi/strapi": "^5.0.0",
72
+ "@strapi/design-system": "^2.0.0",
73
+ "@strapi/icons": "^2.0.0",
74
+ "react-intl": "^6.0.0",
75
+ "react": "^17.0.0 || ^18.0.0",
76
+ "react-dom": "^17.0.0 || ^18.0.0",
77
+ "react-router-dom": "^6.0.0",
78
+ "styled-components": "^6.0.0"
79
+ },
80
+ "description": "A strapi plugin to manage URL routes and navigations.",
81
+ "strapi": {
82
+ "name": "webatlas",
83
+ "displayName": "Webatlas",
84
+ "description": "A strapi plugin to manage URL routes and navigations.",
85
+ "kind": "plugin"
86
+ },
87
+ "name": "@mattisvensson/strapi-plugin-webatlas",
88
+ "license": "MIT",
89
+ "repository": {
90
+ "type": "git",
91
+ "url": "git+ssh://git@github.com:mattisvensson/strapi-plugin-webatlas.git"
92
+ },
93
+ "bugs": {
94
+ "url": "https://github.com/mattisvensson/strapi-plugin-webatlas/issues"
95
+ },
96
+ "homepage": "https://github.com/mattisvensson/strapi-plugin-webatlas#readme",
97
+ "author": {
98
+ "name": "Matti Svensson",
99
+ "email": "mattisvensson@web.de",
100
+ "url": "https://mattisvensson.dev"
101
+ },
102
+ "maintainers": [
103
+ {
104
+ "name": "Matti Svensson",
105
+ "email": "mattisvensson@web.de",
106
+ "url": "https://mattisvensson.dev"
107
+ }
108
+ ],
109
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
110
110
  }
@@ -1,218 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useReducer, useState, useRef, useEffect } from "react";
3
- import { Box, Accordion, Field, SingleSelect, SingleSelectOption, Typography, Link } from "@strapi/design-system";
4
- import { useNotification, Page } from "@strapi/strapi/admin";
5
- import { g as getTranslation, c as usePluginConfig, e as useAllContentTypes, p as pluginPermissions, f as PLUGIN_NAME, h as PLUGIN_VERSION } from "./index-CIr8o1RP.mjs";
6
- import { useIntl } from "react-intl";
7
- import "@strapi/icons/symbols";
8
- import { F as FullLoader } from "./FullLoader-CrPED_dY.mjs";
9
- import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-DbsxB1V9.mjs";
10
- import { ExternalLink } from "@strapi/icons";
11
- function ContentTypeAccordion({
12
- contentType,
13
- contentTypeSettings,
14
- dispatch
15
- }) {
16
- const { formatMessage } = useIntl();
17
- if (!contentType) return null;
18
- return /* @__PURE__ */ jsx(
19
- Box,
20
- {
21
- borderColor: !contentTypeSettings.default ? "danger500" : void 0,
22
- children: /* @__PURE__ */ jsxs(Accordion.Item, { value: contentType.uid, children: [
23
- /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { children: contentType?.info.displayName }) }),
24
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 3, children: /* @__PURE__ */ jsxs(
25
- Field.Root,
26
- {
27
- name: "selectedContentTypes",
28
- hint: formatMessage({
29
- id: getTranslation("settings.page.generate.hint"),
30
- defaultMessage: 'The selected field from the content type will be used to generate the path. Use a field that is unique and descriptive, such as a "title" or "name".'
31
- }),
32
- error: !contentTypeSettings.default && formatMessage({
33
- id: getTranslation("settings.page.generate.error"),
34
- defaultMessage: "Please select a default field"
35
- }),
36
- required: true,
37
- children: [
38
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
39
- id: getTranslation("settings.page.generate"),
40
- defaultMessage: "Generate paths from"
41
- }) }),
42
- /* @__PURE__ */ jsx(
43
- SingleSelect,
44
- {
45
- name: `defaultField-${contentType.uid}`,
46
- onClear: () => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: "" } }),
47
- value: contentTypeSettings?.default || "",
48
- onChange: (value) => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: String(value) } }),
49
- children: Object.entries(contentType.attributes).map(([key], index) => {
50
- if (key === "id" || key === "documentId" || key === "createdAt" || key === "updatedAt" || key === "createdBy" || key === "updatedBy" || key === "webatlas_path" || key === "webatlas_override" || key === "webatlas_parent") return null;
51
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: key, children: key }, index);
52
- })
53
- }
54
- ),
55
- /* @__PURE__ */ jsx(Field.Hint, {})
56
- ]
57
- }
58
- ) }) })
59
- ] }, contentType.uid)
60
- },
61
- contentType.uid
62
- );
63
- }
64
- function reducer(newConfig, action) {
65
- let updatedContentTypes;
66
- switch (action.type) {
67
- case "SET_DEFAULT_FIELD":
68
- if (!newConfig) return null;
69
- updatedContentTypes = newConfig?.selectedContentTypes.map(
70
- (ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
71
- );
72
- return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
73
- case "SET_CONFIG":
74
- return action.payload;
75
- default:
76
- throw new Error();
77
- }
78
- }
79
- const Settings = () => {
80
- const { config: fetchedConfig, setConfig, loading, fetchError } = usePluginConfig();
81
- const [config, dispatch] = useReducer(reducer, fetchedConfig);
82
- const { contentTypes: allContentTypesData } = useAllContentTypes();
83
- const allContentTypes = allContentTypesData?.filter((ct) => ct.pluginOptions?.webatlas?.enabled === true);
84
- const { toggleNotification } = useNotification();
85
- const { formatMessage } = useIntl();
86
- const [isSaving, setIsSaving] = useState(false);
87
- const initialConfig = useRef(fetchedConfig);
88
- useEffect(() => {
89
- initialConfig.current = fetchedConfig;
90
- if (fetchedConfig)
91
- dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
92
- }, [fetchedConfig]);
93
- useEffect(() => {
94
- if (fetchError) {
95
- toggleNotification({
96
- type: "danger",
97
- message: formatMessage({
98
- id: getTranslation("notification.error"),
99
- defaultMessage: "An error occurred"
100
- }) + ": " + fetchError
101
- });
102
- }
103
- }, [fetchError, toggleNotification, formatMessage]);
104
- async function save() {
105
- if (!config || config.selectedContentTypes.find((cta) => !cta.default) !== void 0) return;
106
- setIsSaving(true);
107
- try {
108
- await setConfig({ selectedContentTypes: config.selectedContentTypes });
109
- initialConfig.current = config;
110
- toggleNotification({
111
- type: "success",
112
- message: formatMessage({
113
- id: getTranslation("notification.settings.saved"),
114
- defaultMessage: "Settings saved successfully"
115
- })
116
- });
117
- setIsSaving(false);
118
- } catch (err) {
119
- setIsSaving(false);
120
- toggleNotification({
121
- type: "danger",
122
- message: formatMessage({
123
- id: getTranslation("notification.error"),
124
- defaultMessage: "An error occurred"
125
- }) + ": " + err
126
- });
127
- strapi.log.error(err);
128
- }
129
- }
130
- if (loading) {
131
- return /* @__PURE__ */ jsx(
132
- PageWrapper,
133
- {
134
- isSaving,
135
- subtitle: formatMessage({
136
- id: getTranslation("loading"),
137
- defaultMessage: "Loading..."
138
- }),
139
- disabledCondition: true,
140
- children: /* @__PURE__ */ jsx(FullLoader, { height: 200 })
141
- }
142
- );
143
- }
144
- return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions["settings.general"], children: /* @__PURE__ */ jsxs(
145
- PageWrapper,
146
- {
147
- save,
148
- isSaving,
149
- subtitle: formatMessage({
150
- id: getTranslation("settings.page.general.subtitle"),
151
- defaultMessage: "Configure general settings"
152
- }),
153
- disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
154
- children: [
155
- /* @__PURE__ */ jsx(ContentBox, { title: formatMessage({
156
- id: getTranslation("settings.page.general.contentTypes"),
157
- defaultMessage: "Content Types"
158
- }), children: config?.selectedContentTypes && config.selectedContentTypes.length > 0 ? /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
159
- /* @__PURE__ */ jsx(Field.Label, { children: /* @__PURE__ */ jsx(SettingTitle, { children: formatMessage({
160
- id: getTranslation("settings.page.contentTypeSettings"),
161
- defaultMessage: "Content Type settings"
162
- }) }) }),
163
- /* @__PURE__ */ jsx(Accordion.Root, { children: config.selectedContentTypes?.map((contentTypeSettings) => {
164
- const ct = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid);
165
- return /* @__PURE__ */ jsx(ContentTypeAccordion, { contentType: ct, contentTypeSettings, dispatch }, contentTypeSettings.uid);
166
- }) })
167
- ] }) : /* @__PURE__ */ jsxs(Typography, { children: [
168
- formatMessage({
169
- id: getTranslation("settings.page.general.noContentTypesEnabled"),
170
- defaultMessage: "No content types are enabled for Webatlas. Please enable at least one content type to use this plugin."
171
- }),
172
- /* @__PURE__ */ jsx(
173
- Link,
174
- {
175
- href: "https://github.com/mattisvensson/strapi-plugin-webatlas?tab=readme-ov-file#-configuration",
176
- isExternal: true,
177
- style: { marginLeft: 4 },
178
- children: formatMessage({
179
- id: getTranslation("settings.page.general.noContentTypesEnabled.moreInfo"),
180
- defaultMessage: "More info"
181
- })
182
- }
183
- )
184
- ] }) }),
185
- /* @__PURE__ */ jsx(ContentBox, { title: formatMessage({
186
- id: getTranslation("settings.page.general.details"),
187
- defaultMessage: "Details"
188
- }), children: /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
189
- /* @__PURE__ */ jsx(Field.Label, { children: /* @__PURE__ */ jsxs(SettingTitle, { children: [
190
- PLUGIN_NAME,
191
- " ",
192
- formatMessage({
193
- id: getTranslation("version"),
194
- defaultMessage: "Version"
195
- })
196
- ] }) }),
197
- /* @__PURE__ */ jsxs(Typography, { children: [
198
- "v",
199
- PLUGIN_VERSION,
200
- /* @__PURE__ */ jsx(
201
- Link,
202
- {
203
- href: `https://github.com/mattisvensson/strapi-plugin-webatlas/releases/tag/v${PLUGIN_VERSION}`,
204
- target: "_blank",
205
- rel: "noopener noreferrer",
206
- style: { marginLeft: 4 },
207
- children: /* @__PURE__ */ jsx(ExternalLink, {})
208
- }
209
- )
210
- ] })
211
- ] }) })
212
- ]
213
- }
214
- ) });
215
- };
216
- export {
217
- Settings as default
218
- };
@@ -1,218 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
- const designSystem = require("@strapi/design-system");
6
- const admin = require("@strapi/strapi/admin");
7
- const index = require("./index-DC5WwNdi.js");
8
- const reactIntl = require("react-intl");
9
- require("@strapi/icons/symbols");
10
- const FullLoader = require("./FullLoader-Cmsf8xS6.js");
11
- const SettingTitle = require("./SettingTitle-uw1S5OmC.js");
12
- const icons = require("@strapi/icons");
13
- function ContentTypeAccordion({
14
- contentType,
15
- contentTypeSettings,
16
- dispatch
17
- }) {
18
- const { formatMessage } = reactIntl.useIntl();
19
- if (!contentType) return null;
20
- return /* @__PURE__ */ jsxRuntime.jsx(
21
- designSystem.Box,
22
- {
23
- borderColor: !contentTypeSettings.default ? "danger500" : void 0,
24
- children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: contentType.uid, children: [
25
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { children: contentType?.info.displayName }) }),
26
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsxs(
27
- designSystem.Field.Root,
28
- {
29
- name: "selectedContentTypes",
30
- hint: formatMessage({
31
- id: index.getTranslation("settings.page.generate.hint"),
32
- defaultMessage: 'The selected field from the content type will be used to generate the path. Use a field that is unique and descriptive, such as a "title" or "name".'
33
- }),
34
- error: !contentTypeSettings.default && formatMessage({
35
- id: index.getTranslation("settings.page.generate.error"),
36
- defaultMessage: "Please select a default field"
37
- }),
38
- required: true,
39
- children: [
40
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
41
- id: index.getTranslation("settings.page.generate"),
42
- defaultMessage: "Generate paths from"
43
- }) }),
44
- /* @__PURE__ */ jsxRuntime.jsx(
45
- designSystem.SingleSelect,
46
- {
47
- name: `defaultField-${contentType.uid}`,
48
- onClear: () => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: "" } }),
49
- value: contentTypeSettings?.default || "",
50
- onChange: (value) => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: String(value) } }),
51
- children: Object.entries(contentType.attributes).map(([key], index2) => {
52
- if (key === "id" || key === "documentId" || key === "createdAt" || key === "updatedAt" || key === "createdBy" || key === "updatedBy" || key === "webatlas_path" || key === "webatlas_override" || key === "webatlas_parent") return null;
53
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: key, children: key }, index2);
54
- })
55
- }
56
- ),
57
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
58
- ]
59
- }
60
- ) }) })
61
- ] }, contentType.uid)
62
- },
63
- contentType.uid
64
- );
65
- }
66
- function reducer(newConfig, action) {
67
- let updatedContentTypes;
68
- switch (action.type) {
69
- case "SET_DEFAULT_FIELD":
70
- if (!newConfig) return null;
71
- updatedContentTypes = newConfig?.selectedContentTypes.map(
72
- (ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
73
- );
74
- return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
75
- case "SET_CONFIG":
76
- return action.payload;
77
- default:
78
- throw new Error();
79
- }
80
- }
81
- const Settings = () => {
82
- const { config: fetchedConfig, setConfig, loading, fetchError } = index.usePluginConfig();
83
- const [config, dispatch] = React.useReducer(reducer, fetchedConfig);
84
- const { contentTypes: allContentTypesData } = index.useAllContentTypes();
85
- const allContentTypes = allContentTypesData?.filter((ct) => ct.pluginOptions?.webatlas?.enabled === true);
86
- const { toggleNotification } = admin.useNotification();
87
- const { formatMessage } = reactIntl.useIntl();
88
- const [isSaving, setIsSaving] = React.useState(false);
89
- const initialConfig = React.useRef(fetchedConfig);
90
- React.useEffect(() => {
91
- initialConfig.current = fetchedConfig;
92
- if (fetchedConfig)
93
- dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
94
- }, [fetchedConfig]);
95
- React.useEffect(() => {
96
- if (fetchError) {
97
- toggleNotification({
98
- type: "danger",
99
- message: formatMessage({
100
- id: index.getTranslation("notification.error"),
101
- defaultMessage: "An error occurred"
102
- }) + ": " + fetchError
103
- });
104
- }
105
- }, [fetchError, toggleNotification, formatMessage]);
106
- async function save() {
107
- if (!config || config.selectedContentTypes.find((cta) => !cta.default) !== void 0) return;
108
- setIsSaving(true);
109
- try {
110
- await setConfig({ selectedContentTypes: config.selectedContentTypes });
111
- initialConfig.current = config;
112
- toggleNotification({
113
- type: "success",
114
- message: formatMessage({
115
- id: index.getTranslation("notification.settings.saved"),
116
- defaultMessage: "Settings saved successfully"
117
- })
118
- });
119
- setIsSaving(false);
120
- } catch (err) {
121
- setIsSaving(false);
122
- toggleNotification({
123
- type: "danger",
124
- message: formatMessage({
125
- id: index.getTranslation("notification.error"),
126
- defaultMessage: "An error occurred"
127
- }) + ": " + err
128
- });
129
- strapi.log.error(err);
130
- }
131
- }
132
- if (loading) {
133
- return /* @__PURE__ */ jsxRuntime.jsx(
134
- SettingTitle.PageWrapper,
135
- {
136
- isSaving,
137
- subtitle: formatMessage({
138
- id: index.getTranslation("loading"),
139
- defaultMessage: "Loading..."
140
- }),
141
- disabledCondition: true,
142
- children: /* @__PURE__ */ jsxRuntime.jsx(FullLoader.FullLoader, { height: 200 })
143
- }
144
- );
145
- }
146
- return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.pluginPermissions["settings.general"], children: /* @__PURE__ */ jsxRuntime.jsxs(
147
- SettingTitle.PageWrapper,
148
- {
149
- save,
150
- isSaving,
151
- subtitle: formatMessage({
152
- id: index.getTranslation("settings.page.general.subtitle"),
153
- defaultMessage: "Configure general settings"
154
- }),
155
- disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
156
- children: [
157
- /* @__PURE__ */ jsxRuntime.jsx(SettingTitle.ContentBox, { title: formatMessage({
158
- id: index.getTranslation("settings.page.general.contentTypes"),
159
- defaultMessage: "Content Types"
160
- }), children: config?.selectedContentTypes && config.selectedContentTypes.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "selectedContentTypesAccordion", children: [
161
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: /* @__PURE__ */ jsxRuntime.jsx(SettingTitle.SettingTitle, { children: formatMessage({
162
- id: index.getTranslation("settings.page.contentTypeSettings"),
163
- defaultMessage: "Content Type settings"
164
- }) }) }),
165
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Root, { children: config.selectedContentTypes?.map((contentTypeSettings) => {
166
- const ct = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid);
167
- return /* @__PURE__ */ jsxRuntime.jsx(ContentTypeAccordion, { contentType: ct, contentTypeSettings, dispatch }, contentTypeSettings.uid);
168
- }) })
169
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { children: [
170
- formatMessage({
171
- id: index.getTranslation("settings.page.general.noContentTypesEnabled"),
172
- defaultMessage: "No content types are enabled for Webatlas. Please enable at least one content type to use this plugin."
173
- }),
174
- /* @__PURE__ */ jsxRuntime.jsx(
175
- designSystem.Link,
176
- {
177
- href: "https://github.com/mattisvensson/strapi-plugin-webatlas?tab=readme-ov-file#-configuration",
178
- isExternal: true,
179
- style: { marginLeft: 4 },
180
- children: formatMessage({
181
- id: index.getTranslation("settings.page.general.noContentTypesEnabled.moreInfo"),
182
- defaultMessage: "More info"
183
- })
184
- }
185
- )
186
- ] }) }),
187
- /* @__PURE__ */ jsxRuntime.jsx(SettingTitle.ContentBox, { title: formatMessage({
188
- id: index.getTranslation("settings.page.general.details"),
189
- defaultMessage: "Details"
190
- }), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "selectedContentTypesAccordion", children: [
191
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: /* @__PURE__ */ jsxRuntime.jsxs(SettingTitle.SettingTitle, { children: [
192
- index.PLUGIN_NAME,
193
- " ",
194
- formatMessage({
195
- id: index.getTranslation("version"),
196
- defaultMessage: "Version"
197
- })
198
- ] }) }),
199
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { children: [
200
- "v",
201
- index.PLUGIN_VERSION,
202
- /* @__PURE__ */ jsxRuntime.jsx(
203
- designSystem.Link,
204
- {
205
- href: `https://github.com/mattisvensson/strapi-plugin-webatlas/releases/tag/v${index.PLUGIN_VERSION}`,
206
- target: "_blank",
207
- rel: "noopener noreferrer",
208
- style: { marginLeft: 4 },
209
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {})
210
- }
211
- )
212
- ] })
213
- ] }) })
214
- ]
215
- }
216
- ) });
217
- };
218
- exports.default = Settings;