@mattisvensson/strapi-plugin-webatlas 0.8.0 → 0.8.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 (76) hide show
  1. package/dist/_chunks/FullLoader-Cmsf8xS6.js +12 -0
  2. package/dist/_chunks/FullLoader-Cmsf8xS6.js.map +1 -0
  3. package/dist/_chunks/FullLoader-CrPED_dY.mjs +1 -0
  4. package/dist/_chunks/FullLoader-CrPED_dY.mjs.map +1 -0
  5. package/dist/_chunks/PageWrapper-Bp9vGwpG.js +54 -0
  6. package/dist/_chunks/PageWrapper-BvOY7VCN.mjs +55 -0
  7. package/dist/_chunks/PageWrapper-BzDrMm2d.js +55 -0
  8. package/dist/_chunks/PageWrapper-BzDrMm2d.js.map +1 -0
  9. package/dist/_chunks/{PageWrapper-B6nLPFak.mjs → PageWrapper-oLhcg9BA.mjs} +2 -1
  10. package/dist/_chunks/PageWrapper-oLhcg9BA.mjs.map +1 -0
  11. package/dist/_chunks/de-CDBoUBzw.js +124 -0
  12. package/dist/_chunks/de-CDBoUBzw.js.map +1 -0
  13. package/dist/_chunks/{de-C1QgkRoj.mjs → de-Dt80IqMG.mjs} +2 -0
  14. package/dist/_chunks/de-Dt80IqMG.mjs.map +1 -0
  15. package/dist/_chunks/{en--8p5hbLP.mjs → en-BHxDiueo.mjs} +2 -0
  16. package/dist/_chunks/en-BHxDiueo.mjs.map +1 -0
  17. package/dist/_chunks/en-DfvURaup.js +124 -0
  18. package/dist/_chunks/en-DfvURaup.js.map +1 -0
  19. package/dist/_chunks/index--oj1eNcM.js +247 -0
  20. package/dist/_chunks/index--oj1eNcM.js.map +1 -0
  21. package/dist/_chunks/{index-VcxUbdMO.mjs → index-BBn1ZvsE.mjs} +2 -2
  22. package/dist/_chunks/index-BCPgfhBx.js +124 -0
  23. package/dist/_chunks/index-BCPgfhBx.js.map +1 -0
  24. package/dist/_chunks/index-BKdvSgDB.js +246 -0
  25. package/dist/_chunks/index-CAged_xE.mjs +247 -0
  26. package/dist/_chunks/index-CAged_xE.mjs.map +1 -0
  27. package/dist/_chunks/index-CHRBu9Xy.mjs +124 -0
  28. package/dist/_chunks/index-CHRBu9Xy.mjs.map +1 -0
  29. package/dist/_chunks/{index-DSPh-fHL.mjs → index-CTA8agp7.mjs} +7 -7
  30. package/dist/_chunks/{index-Z3qq1ab8.mjs → index-CUlRMqGG.mjs} +26 -29
  31. package/dist/_chunks/index-CbW6k4FH.js +4205 -0
  32. package/dist/_chunks/index-CbW6k4FH.js.map +1 -0
  33. package/dist/_chunks/index-CtFERXkl.js +253 -0
  34. package/dist/_chunks/index-CtFERXkl.js.map +1 -0
  35. package/dist/_chunks/index-D29zBs5w.mjs +12228 -0
  36. package/dist/_chunks/index-D29zBs5w.mjs.map +1 -0
  37. package/dist/_chunks/index-D72CZ5b7.js +123 -0
  38. package/dist/_chunks/{index-7rox7tGX.mjs → index-DJBXRNlE.mjs} +3 -2
  39. package/dist/_chunks/index-DJBXRNlE.mjs.map +1 -0
  40. package/dist/_chunks/index-DMpiX4hP.mjs +4189 -0
  41. package/dist/_chunks/index-DMpiX4hP.mjs.map +1 -0
  42. package/dist/_chunks/index-DTPDMxs_.js +12227 -0
  43. package/dist/_chunks/index-DUgh4AJb.js +252 -0
  44. package/dist/_chunks/index-Dxn0NT06.js +4204 -0
  45. package/dist/_chunks/index-Nx4IRYIK.mjs +252 -0
  46. package/dist/_chunks/{index-DGSjLYNl.mjs → index-Rfm9O167.mjs} +1 -1
  47. package/dist/_chunks/index-YzPuPn68.js +12228 -0
  48. package/dist/_chunks/index-YzPuPn68.js.map +1 -0
  49. package/dist/admin/index.js +5 -0
  50. package/dist/admin/index.js.map +1 -0
  51. package/dist/admin/index.mjs +2 -1
  52. package/dist/admin/index.mjs.map +1 -0
  53. package/dist/admin/src/components/modals/NavEdit.d.ts +1 -1
  54. package/dist/admin/src/components/modals/fields/Visibility.d.ts +5 -0
  55. package/dist/admin/src/components/modals/fields/index.d.ts +2 -0
  56. package/dist/server/index.js +12 -3
  57. package/dist/server/index.js.map +1 -0
  58. package/dist/server/index.mjs +12 -3
  59. package/dist/server/index.mjs.map +1 -0
  60. package/package.json +1 -1
  61. package/dist/_chunks/PageWrapper-BMzPDWn4.js +0 -0
  62. package/dist/_chunks/PageWrapper-BMzPDWn4.js.map +0 -0
  63. package/dist/_chunks/de-DYxCPOdb.js +0 -0
  64. package/dist/_chunks/de-DYxCPOdb.js.map +0 -0
  65. package/dist/_chunks/en-Be-athEA.js +0 -0
  66. package/dist/_chunks/en-Be-athEA.js.map +0 -0
  67. package/dist/_chunks/index-Bu-uQ9jA.js +0 -0
  68. package/dist/_chunks/index-Bu-uQ9jA.js.map +0 -0
  69. package/dist/_chunks/index-C53yDU_z.js +0 -0
  70. package/dist/_chunks/index-C53yDU_z.js.map +0 -0
  71. package/dist/_chunks/index-CAz59RSr.js +0 -0
  72. package/dist/_chunks/index-CAz59RSr.js.map +0 -0
  73. package/dist/_chunks/index-DKfUSLPc.js +0 -0
  74. package/dist/_chunks/index-DKfUSLPc.js.map +0 -0
  75. package/dist/_chunks/index-DPMhcaxW.js +0 -0
  76. package/dist/_chunks/index-DPMhcaxW.js.map +0 -0
@@ -0,0 +1,252 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useReducer, useState, useRef, useEffect } from "react";
3
+ import { Box, Accordion, Field, SingleSelect, SingleSelectOption, MultiSelect, MultiSelectOption } from "@strapi/design-system";
4
+ import { useNotification } from "@strapi/strapi/admin";
5
+ import { g as getTranslation, T as Tooltip, b as usePluginConfig, c as useAllContentTypes, t as transformToUrl } from "./index-CTA8agp7.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 } from "./PageWrapper-BvOY7VCN.mjs";
10
+ function ContentTypeAccordion({
11
+ contentType,
12
+ contentTypeSettings,
13
+ dispatch
14
+ }) {
15
+ const { formatMessage } = useIntl();
16
+ if (!contentType) return null;
17
+ return /* @__PURE__ */ jsx(
18
+ Box,
19
+ {
20
+ borderColor: !contentTypeSettings.default && "danger500",
21
+ children: /* @__PURE__ */ jsxs(Accordion.Item, { value: contentType.uid, size: "S", children: [
22
+ /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { children: contentType?.info.displayName }) }),
23
+ /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsxs(Box, { padding: 3, children: [
24
+ /* @__PURE__ */ jsxs(
25
+ Field.Root,
26
+ {
27
+ name: "selectedContentTypes",
28
+ hint: formatMessage({
29
+ id: getTranslation("settings.page.defaultField.hint"),
30
+ defaultMessage: 'The selected field from the content type will be used to generate the URL alias. 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.defaultField.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.defaultField"),
40
+ defaultMessage: "Default URL Alias field"
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: 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") return null;
51
+ return /* @__PURE__ */ jsx(SingleSelectOption, { value: key, children: key }, index);
52
+ })
53
+ }
54
+ ),
55
+ /* @__PURE__ */ jsx(Field.Hint, {})
56
+ ]
57
+ }
58
+ ),
59
+ /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(
60
+ Field.Root,
61
+ {
62
+ name: "urlAliasPattern",
63
+ hint: formatMessage({
64
+ id: getTranslation("settings.page.urlAliasPattern.hint"),
65
+ defaultMessage: 'The pattern to prepend to the generated URL alias. For example, if you enter "blog" and the value of default field is "My First Post", the generated URL alias will be "blog/my-first-post". Leave empty for no prefix.'
66
+ }),
67
+ children: [
68
+ /* @__PURE__ */ jsxs(Field.Label, { children: [
69
+ formatMessage({
70
+ id: getTranslation("settings.page.urlAliasPattern"),
71
+ defaultMessage: "URL Alias Pattern"
72
+ }),
73
+ /* @__PURE__ */ jsx(Tooltip, { description: formatMessage({
74
+ id: getTranslation("settings.page.urlAliasPattern.tooltip"),
75
+ defaultMessage: "Leading and trailing slashes will be removed. Spaces will be replaced with hyphens. Special characters will be encoded."
76
+ }) })
77
+ ] }),
78
+ /* @__PURE__ */ jsx(
79
+ Field.Input,
80
+ {
81
+ value: contentTypeSettings.pattern,
82
+ onChange: (e) => dispatch({ type: "SET_PATTERN", payload: { ctUid: contentType.uid, pattern: e.target.value } }),
83
+ disabled: !contentTypeSettings.default,
84
+ type: "text",
85
+ placeholder: formatMessage({
86
+ id: getTranslation("settings.page.urlAliasPattern.placeholder"),
87
+ defaultMessage: "e.g. blog"
88
+ })
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsx(Field.Hint, {})
92
+ ]
93
+ }
94
+ ) })
95
+ ] }) })
96
+ ] }, contentType.uid)
97
+ },
98
+ contentType.uid
99
+ );
100
+ }
101
+ function reducer(newConfig, action) {
102
+ let updatedContentTypes;
103
+ switch (action.type) {
104
+ case "SET_SELECTED_CONTENT_TYPES":
105
+ if (!newConfig) return null;
106
+ updatedContentTypes = action.payload.map((ct) => {
107
+ return newConfig?.selectedContentTypes.find((cta) => cta.uid === ct.uid) || ct;
108
+ });
109
+ return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
110
+ case "SET_DEFAULT_FIELD":
111
+ if (!newConfig) return null;
112
+ updatedContentTypes = newConfig?.selectedContentTypes.map(
113
+ (ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
114
+ );
115
+ return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
116
+ case "SET_PATTERN":
117
+ if (!newConfig) return null;
118
+ updatedContentTypes = newConfig?.selectedContentTypes.map(
119
+ (ct) => ct.uid === action.payload.ctUid ? { ...ct, pattern: transformToUrl(action.payload.pattern) } : ct
120
+ );
121
+ return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
122
+ case "SET_CONFIG":
123
+ return action.payload;
124
+ default:
125
+ throw new Error();
126
+ }
127
+ }
128
+ const Settings = () => {
129
+ const { config: fetchedConfig, setConfig, loading, fetchError } = usePluginConfig();
130
+ const [config, dispatch] = useReducer(reducer, fetchedConfig);
131
+ const { contentTypes: allContentTypesData } = useAllContentTypes();
132
+ const allContentTypes = allContentTypesData?.filter((ct) => ct.pluginOptions?.webatlas?.active === true);
133
+ const { toggleNotification } = useNotification();
134
+ const { formatMessage } = useIntl();
135
+ const [isSaving, setIsSaving] = useState(false);
136
+ const initialConfig = useRef(fetchedConfig);
137
+ useEffect(() => {
138
+ initialConfig.current = fetchedConfig;
139
+ if (fetchedConfig)
140
+ dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
141
+ }, [fetchedConfig]);
142
+ useEffect(() => {
143
+ if (fetchError) {
144
+ toggleNotification({
145
+ type: "danger",
146
+ message: formatMessage({
147
+ id: getTranslation("notification.error"),
148
+ defaultMessage: "An error occurred"
149
+ }) + ": " + fetchError
150
+ });
151
+ }
152
+ }, [fetchError, toggleNotification, formatMessage]);
153
+ async function save() {
154
+ if (!config || config.selectedContentTypes.find((cta) => !cta.default) !== void 0) return;
155
+ setIsSaving(true);
156
+ try {
157
+ await setConfig({ selectedContentTypes: config.selectedContentTypes });
158
+ initialConfig.current = config;
159
+ toggleNotification({
160
+ type: "success",
161
+ message: formatMessage({
162
+ id: getTranslation("notification.settings.saved"),
163
+ defaultMessage: "Settings saved successfully"
164
+ })
165
+ });
166
+ setIsSaving(false);
167
+ } catch (err) {
168
+ setIsSaving(false);
169
+ toggleNotification({
170
+ type: "danger",
171
+ message: formatMessage({
172
+ id: getTranslation("notification.error"),
173
+ defaultMessage: "An error occurred"
174
+ }) + ": " + err
175
+ });
176
+ console.error(err);
177
+ }
178
+ }
179
+ if (loading) {
180
+ return /* @__PURE__ */ jsx(
181
+ PageWrapper,
182
+ {
183
+ isSaving,
184
+ disabledCondition: true,
185
+ children: /* @__PURE__ */ jsx(FullLoader, { height: 200 })
186
+ }
187
+ );
188
+ }
189
+ return /* @__PURE__ */ jsxs(
190
+ PageWrapper,
191
+ {
192
+ save,
193
+ isSaving,
194
+ disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
195
+ children: [
196
+ /* @__PURE__ */ jsxs(
197
+ Field.Root,
198
+ {
199
+ name: "selectedContentTypes",
200
+ hint: formatMessage({
201
+ id: getTranslation("settings.page.enabledContentTypes.hint"),
202
+ defaultMessage: "Select the content types for which you want to enable URL aliases"
203
+ }),
204
+ children: [
205
+ /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
206
+ id: getTranslation("settings.page.enabledContentTypes"),
207
+ defaultMessage: "Enabled Content Types"
208
+ }) }),
209
+ /* @__PURE__ */ jsx(
210
+ MultiSelect,
211
+ {
212
+ placeholder: formatMessage({
213
+ id: getTranslation("settings.page.enabledContentTypes.placeholder"),
214
+ defaultMessage: "Select content types..."
215
+ }),
216
+ onClear: () => dispatch({ type: "SET_SELECTED_CONTENT_TYPES", payload: [] }),
217
+ value: [...config?.selectedContentTypes.map((ct) => ct.uid) || []],
218
+ onChange: (value) => dispatch({
219
+ type: "SET_SELECTED_CONTENT_TYPES",
220
+ payload: value.map((v) => ({
221
+ uid: v,
222
+ default: "",
223
+ pattern: ""
224
+ }))
225
+ }),
226
+ withTags: true,
227
+ children: allContentTypes && allContentTypes.map(
228
+ (item) => /* @__PURE__ */ jsx(MultiSelectOption, { value: item.uid, children: item.info.displayName }, item.uid)
229
+ )
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsx(Field.Hint, {})
233
+ ]
234
+ }
235
+ ),
236
+ config?.selectedContentTypes && config.selectedContentTypes.length > 0 && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
237
+ /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
238
+ id: getTranslation("settings.page.contentTypeSettings"),
239
+ defaultMessage: "Content Type settings"
240
+ }) }),
241
+ /* @__PURE__ */ jsx(Accordion.Root, { children: config.selectedContentTypes?.map((contentTypeSettings) => {
242
+ const ct = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid);
243
+ return /* @__PURE__ */ jsx(ContentTypeAccordion, { contentType: ct, contentTypeSettings, dispatch }, contentTypeSettings.uid);
244
+ }) })
245
+ ] }) })
246
+ ]
247
+ }
248
+ );
249
+ };
250
+ export {
251
+ Settings as default
252
+ };
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useState, useEffect, useMemo } from "react";
3
3
  import { Thead, Tr, Th, Typography, VisuallyHidden, Td, Flex, LinkButton, Grid, Box, Field, Table, Tbody, EmptyStateLayout } from "@strapi/design-system";
4
4
  import { ChevronDown, Pencil, Cross } from "@strapi/icons";
5
- import { g as getTranslation, u as useApi, d as debounce } from "./index-DSPh-fHL.mjs";
5
+ import { g as getTranslation, u as useApi, d as debounce } from "./index-CTA8agp7.mjs";
6
6
  import { Page, Layouts, useNotification } from "@strapi/strapi/admin";
7
7
  import "@strapi/icons/symbols";
8
8
  import { F as FullLoader } from "./FullLoader-CrPED_dY.mjs";