@primershop/strapi-plugin-status-manager 0.0.16 → 0.0.18

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/package.json CHANGED
@@ -1,39 +1,37 @@
1
1
  {
2
2
  "name": "@primershop/strapi-plugin-status-manager",
3
- "version": "0.0.16",
4
- "description": "Enables more status variations for Strapi (v0.0.16)",
3
+ "version": "0.0.18",
4
+ "description": "Enables more status variations for Strapi (v0.0.18)",
5
+ "type": "commonjs",
5
6
  "exports": {
6
7
  "./strapi-admin": {
7
8
  "import": "./dist/admin/index.mjs",
8
9
  "require": "./dist/admin/index.js",
10
+ "source": "./admin/src/index.ts",
9
11
  "default": "./dist/admin/index.js"
10
12
  },
11
13
  "./strapi-server": {
12
14
  "import": "./dist/server/index.mjs",
15
+ "source": "./server/src/index.ts",
13
16
  "require": "./dist/server/index.js",
14
17
  "default": "./dist/server/index.js"
15
18
  },
16
19
  "./package.json": "./package.json"
17
20
  },
18
21
  "files": [
19
- "dist/"
22
+ "dist"
20
23
  ],
21
24
  "scripts": {
22
- "build": "npm-run-all clean --parallel build:code",
23
- "build:code": "rollup -c",
24
- "build:dev": "rollup -c rollup.config.dev.mjs",
25
- "build:types": "run-p build:types:server build:types:admin",
26
- "build:types:server": "tsc -p server/tsconfig.build.json ",
27
- "build:types:admin": "tsc -p admin/tsconfig.build.json ",
25
+ "build": "strapi-plugin build",
26
+ "watch": "strapi-plugin watch",
27
+ "watch:link": "strapi-plugin watch:link",
28
+ "verify": "strapi-plugin verify",
28
29
  "clean": "rimraf ./dist",
29
30
  "lint": "eslint .",
30
31
  "test:front": "cross-env IS_EE=true jest --config ./jest.config.front.js",
31
32
  "test:ts:front": "tsc -p admin/tsconfig.json",
32
33
  "test:unit": "jest",
33
34
  "test:unit:watch": "jest --watch",
34
- "watch": "rollup -c -w",
35
- "dev": "NODE_ENV=development DEBUG=true rollup -c rollup.config.dev.mjs -w",
36
- "test:debug": "NODE_ENV=development DEBUG=true node test-debug.js",
37
35
  "deploy": "node ../../scripts/plugin-deploy.js strapi-plugin-status-manager",
38
36
  "deploy:patch": "node ../../scripts/plugin-deploy.js strapi-plugin-status-manager patch",
39
37
  "deploy:minor": "node ../../scripts/plugin-deploy.js strapi-plugin-status-manager minor",
@@ -72,10 +70,11 @@
72
70
  "@rollup/plugin-swc": "^0.4.0",
73
71
  "@strapi/admin": "^5.29.0",
74
72
  "@strapi/content-manager": "^5.29.0",
73
+ "@strapi/sdk-plugin": "^5.4.0",
75
74
  "@strapi/types": "^5.29.0",
75
+ "@types/node": "^25.0.2",
76
76
  "@types/react": "^18.3.1",
77
77
  "@types/react-dom": "^18.3.1",
78
- "@types/node": "^25.0.2",
79
78
  "cross-env": "^10.0.0",
80
79
  "eslint": "9.39.2",
81
80
  "jest": "^30.2.0",
@@ -92,7 +91,7 @@
92
91
  "kind": "plugin",
93
92
  "name": "primershop-status-manager",
94
93
  "displayName": "Status Manager",
95
- "description": "Manages content statuses (v0.0.16)"
94
+ "description": "Manages content statuses (v0.0.18)"
96
95
  },
97
96
  "dependencies": {
98
97
  "@strapi/design-system": "^2.0.0-rc.27",
@@ -1,412 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var designSystem = require('@strapi/design-system');
5
- var admin = require('@strapi/strapi/admin');
6
- var React = require('react');
7
- var combine = require('@atlaskit/pragmatic-drag-and-drop/combine');
8
- var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
9
- var pointerOutsideOfPreview = require('@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview');
10
- var setCustomNativeDragPreview = require('@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview');
11
- var reorder = require('@atlaskit/pragmatic-drag-and-drop/reorder');
12
- var closestEdge = require('@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge');
13
- var icons = require('@strapi/icons');
14
- var index = require('./index-mATo7IeG.js');
15
-
16
- const StatusManager = ()=>{
17
- const [statuses, setStatuses] = React.useState([]);
18
- const [newStatus, setNewStatus] = React.useState("");
19
- const [statusToDelete, setStatusToDelete] = React.useState(null);
20
- const [replacementStatus, setReplacementStatus] = React.useState("");
21
- const { get, post, put } = admin.useFetchClient();
22
- const [instanceId] = React.useState(()=>Symbol("instance-id"));
23
- // Fetch statuses
24
- React.useEffect(()=>{
25
- const loadStatuses = async ()=>{
26
- const { data } = await get("primershop-status-manager/statuses");
27
- setStatuses(data);
28
- };
29
- loadStatuses();
30
- }, [
31
- get
32
- ]);
33
- // Validate input (Latin characters only)
34
- const validateInput = (value)=>/^[a-zA-Z\s]+$/.test(value);
35
- // Add new status
36
- const addStatus = async ()=>{
37
- if (!newStatus || !validateInput(newStatus)) return alert("Only Latin characters allowed!");
38
- try {
39
- const { data } = await post("primershop-status-manager/status", {
40
- name: newStatus,
41
- published: false
42
- });
43
- setStatuses([
44
- ...statuses,
45
- data
46
- ]);
47
- setNewStatus("");
48
- } catch (error) {
49
- console.error("Error creating status:", error);
50
- }
51
- };
52
- const reorderItem = React.useCallback(async ({ startIndex, indexOfTarget, closestEdgeOfTarget })=>{
53
- // Calculate the final index based on the target position and edge
54
- let finishIndex = indexOfTarget;
55
- if (closestEdgeOfTarget === "bottom") {
56
- finishIndex = indexOfTarget + 1;
57
- }
58
- // If moving an item down, we need to adjust for the removed item
59
- if (startIndex < finishIndex) {
60
- finishIndex--;
61
- }
62
- if (finishIndex === startIndex) {
63
- return;
64
- }
65
- const reordered = reorder.reorder({
66
- list: statuses,
67
- startIndex,
68
- finishIndex
69
- });
70
- // Send new order to API
71
- const orderedIds = reordered.map((status, index)=>({
72
- documentId: status.documentId,
73
- order: index
74
- }));
75
- await put("/primershop-status-manager/statuses/reorder", {
76
- statuses: orderedIds
77
- });
78
- setStatuses(reordered);
79
- }, [
80
- statuses,
81
- put
82
- ]);
83
- // Setup drag and drop
84
- React.useEffect(()=>{
85
- const statusElements = document.querySelectorAll("[data-status-id]");
86
- const cleanupFunctions = [];
87
- statusElements.forEach((element)=>{
88
- const statusId = element.getAttribute("data-status-id");
89
- const index = statuses.findIndex((s)=>s.documentId === statusId);
90
- const dragHandle = element.querySelector("[data-drag-handle]");
91
- if (!dragHandle) return;
92
- // Setup draggable
93
- const draggableCleanup = adapter.draggable({
94
- element: dragHandle,
95
- getInitialData: ()=>({
96
- statusId,
97
- index,
98
- instanceId
99
- }),
100
- onGenerateDragPreview ({ nativeSetDragImage }) {
101
- setCustomNativeDragPreview.setCustomNativeDragPreview({
102
- nativeSetDragImage,
103
- getOffset: pointerOutsideOfPreview.pointerOutsideOfPreview({
104
- x: "16px",
105
- y: "8px"
106
- }),
107
- render ({ container }) {
108
- const preview = document.createElement("div");
109
- preview.style.padding = "8px 16px";
110
- preview.style.backgroundColor = "#fff";
111
- preview.style.border = "1px solid #ccc";
112
- preview.style.borderRadius = "4px";
113
- preview.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)";
114
- const statusNameElement = element.querySelector("[data-status-name]");
115
- preview.textContent = statusNameElement?.textContent || "";
116
- container.appendChild(preview);
117
- return ()=>container.removeChild(preview);
118
- }
119
- });
120
- }
121
- });
122
- // Setup drop target
123
- const dropTargetCleanup = adapter.dropTargetForElements({
124
- element: element,
125
- canDrop: ({ source })=>source.data.instanceId === instanceId,
126
- getData ({ input }) {
127
- return closestEdge.attachClosestEdge({
128
- statusId,
129
- index,
130
- instanceId
131
- }, {
132
- element,
133
- input,
134
- allowedEdges: [
135
- "top",
136
- "bottom"
137
- ]
138
- });
139
- },
140
- onDrag ({ source, self }) {
141
- const isSource = source.element === dragHandle;
142
- if (isSource) return;
143
- const closestEdge$1 = closestEdge.extractClosestEdge(self.data);
144
- const sourceIndex = Number(source.data.index);
145
- const isItemBeforeSource = index === sourceIndex - 1;
146
- const isItemAfterSource = index === sourceIndex + 1;
147
- const isDropIndicatorHidden = isItemBeforeSource && closestEdge$1 === "bottom" || isItemAfterSource && closestEdge$1 === "top";
148
- if (isDropIndicatorHidden) return;
149
- // Add visual feedback for drop target
150
- element.style.background = `linear-gradient(${closestEdge$1 === "top" ? 180 : 0}deg, rgba(136,131,214,0.4) 0%, rgba(255,255,255,0) 50%)`;
151
- },
152
- onDragLeave () {
153
- element.style.background = "";
154
- },
155
- onDrop ({ source, self }) {
156
- element.style.background = "";
157
- const sourceData = source.data;
158
- const targetData = self.data;
159
- const indexOfTarget = statuses.findIndex((s)=>s.documentId === targetData.statusId);
160
- if (indexOfTarget < 0) return;
161
- const closestEdgeOfTarget = closestEdge.extractClosestEdge(targetData);
162
- reorderItem({
163
- startIndex: sourceData.index,
164
- indexOfTarget,
165
- closestEdgeOfTarget
166
- });
167
- }
168
- });
169
- // Combine cleanup functions
170
- const combinedCleanup = combine.combine(draggableCleanup, dropTargetCleanup);
171
- cleanupFunctions.push(combinedCleanup);
172
- });
173
- // Monitor for drops
174
- const monitorCleanup = adapter.monitorForElements({
175
- canMonitor: ({ source })=>source.data.instanceId === instanceId,
176
- onDrop ({ location, source }) {
177
- const target = location.current.dropTargets[0];
178
- if (!target) return;
179
- const sourceData = source.data;
180
- const targetData = target.data;
181
- const indexOfTarget = statuses.findIndex((s)=>s.documentId === targetData.statusId);
182
- if (indexOfTarget < 0) return;
183
- const closestEdgeOfTarget = closestEdge.extractClosestEdge(targetData);
184
- reorderItem({
185
- startIndex: sourceData.index,
186
- indexOfTarget,
187
- closestEdgeOfTarget
188
- });
189
- }
190
- });
191
- // Cleanup function
192
- return ()=>{
193
- cleanupFunctions.forEach((cleanup)=>cleanup());
194
- monitorCleanup();
195
- };
196
- }, [
197
- statuses,
198
- reorderItem,
199
- instanceId
200
- ]);
201
- // Open delete dialog
202
- const confirmDelete = (status)=>{
203
- setStatusToDelete(status);
204
- };
205
- // Delete status and replace with selected one
206
- const deleteStatus = async ()=>{
207
- if (!replacementStatus) return alert("Select a replacement status!");
208
- const replacementStatusObj = statuses.find((s)=>s.name === replacementStatus);
209
- if (!replacementStatusObj) return alert("Replacement status not found!");
210
- try {
211
- await put("/primershop-status-manager/statuses/delete", {
212
- statusId: statusToDelete?.documentId,
213
- replacementId: replacementStatusObj.documentId
214
- });
215
- // Remove the deleted status from the list
216
- setStatuses(statuses.filter((s)=>s.documentId !== statusToDelete?.documentId));
217
- setStatusToDelete(null);
218
- setReplacementStatus("");
219
- } catch (error) {
220
- console.error("Error deleting status:", error);
221
- }
222
- };
223
- // Toggle publish status
224
- const togglePublish = async (id, published)=>{
225
- try {
226
- await put(`/primershop-status-manager/statuses/${id}`, {
227
- published: !published
228
- });
229
- setStatuses(statuses.map((s)=>s.documentId === id ? {
230
- ...s,
231
- published: !published
232
- } : s));
233
- } catch (error) {
234
- console.error("Error toggling publish status:", error);
235
- }
236
- };
237
- return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
238
- padding: 4,
239
- children: [
240
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
241
- variant: "beta",
242
- children: "Status Manager"
243
- }),
244
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
245
- marginTop: 4,
246
- gap: 2,
247
- children: [
248
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
249
- placeholder: "Enter a status...",
250
- value: newStatus,
251
- onChange: (e)=>setNewStatus(e.target.value)
252
- }),
253
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
254
- onClick: addStatus,
255
- startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Plus, {}),
256
- children: "Add Status"
257
- })
258
- ]
259
- }),
260
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
261
- marginTop: 4,
262
- children: statuses.map((status)=>/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
263
- "data-status-id": status.documentId,
264
- alignItems: "center",
265
- gap: 2,
266
- marginBottom: 2,
267
- paddingBottom: 2,
268
- style: {
269
- borderBottom: `1px solid gray`,
270
- minWidth: 300,
271
- userSelect: "none",
272
- touchAction: "none"
273
- },
274
- children: [
275
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
276
- "data-drag-handle": true,
277
- style: {
278
- cursor: "grab",
279
- padding: "4px",
280
- display: "flex",
281
- alignItems: "center"
282
- },
283
- children: /*#__PURE__*/ jsxRuntime.jsx(icons.Drag, {})
284
- }, `dragHandle-${status.documentId}`),
285
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
286
- variant: "sigma",
287
- style: {
288
- display: "inline-block",
289
- marginRight: "auto"
290
- },
291
- "data-status-name": true,
292
- children: status.name
293
- }),
294
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
295
- variant: status.published ? "success-light" : "secondary",
296
- onClick: ()=>togglePublish(status.documentId, status.published),
297
- children: status.published ? "Published" : "Unpublished"
298
- }),
299
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Root, {
300
- onOpenChange: ()=>confirmDelete(status),
301
- children: [
302
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Trigger, {
303
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
304
- variant: "tertiary",
305
- startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Trash, {}),
306
- children: "Delete"
307
- })
308
- }),
309
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Content, {
310
- children: [
311
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Header, {
312
- children: "Delete status"
313
- }),
314
- statuses.length > 1 && statusToDelete && /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Body, {
315
- children: [
316
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
317
- children: "Choose a replacement status before deleting:"
318
- }),
319
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
320
- onChange: (value)=>setReplacementStatus(value),
321
- placeholder: "Select replacement",
322
- children: statuses.filter((s)=>s.documentId !== statusToDelete.documentId).map((s)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
323
- value: s.name,
324
- children: s.name
325
- }, `statusChoice-${s.documentId}`))
326
- }),
327
- replacementStatus && /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Typography, {
328
- children: [
329
- "Replacing ",
330
- statusToDelete.name,
331
- " with ",
332
- replacementStatus
333
- ]
334
- })
335
- ]
336
- }),
337
- /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Footer, {
338
- children: [
339
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Cancel, {
340
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
341
- fullWidth: true,
342
- variant: "tertiary",
343
- children: "Cancel"
344
- })
345
- }),
346
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Action, {
347
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
348
- fullWidth: true,
349
- variant: "danger-light",
350
- onClick: deleteStatus,
351
- children: "Yes, delete"
352
- })
353
- })
354
- ]
355
- })
356
- ]
357
- })
358
- ]
359
- })
360
- ]
361
- }, `status-${status.documentId}`))
362
- }, statuses.length)
363
- ]
364
- });
365
- };
366
-
367
- const HomePage = ()=>{
368
- return /*#__PURE__*/ jsxRuntime.jsxs(admin.Layouts.Root, {
369
- children: [
370
- /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Title, {
371
- children: "Status Manager"
372
- }),
373
- /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Main, {
374
- children: /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Protect, {
375
- permissions: index.pluginPermissions.accessStatusManager,
376
- children: /*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Content, {
377
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
378
- children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
379
- padding: 10,
380
- gap: {
381
- initial: 1,
382
- medium: 4,
383
- large: 8
384
- },
385
- direction: {
386
- initial: "column",
387
- medium: "row"
388
- },
389
- alignItems: {
390
- initial: "center",
391
- medium: "flex-start"
392
- },
393
- children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
394
- padding: 1,
395
- children: [
396
- /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
397
- variant: "alpha",
398
- children: "Status manager"
399
- }),
400
- /*#__PURE__*/ jsxRuntime.jsx(StatusManager, {})
401
- ]
402
- })
403
- })
404
- })
405
- })
406
- })
407
- })
408
- ]
409
- });
410
- };
411
-
412
- exports.HomePage = HomePage;