strapi-plugin-magic-mark 3.3.2 → 4.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +366 -0
  2. package/README.md +390 -619
  3. package/dist/admin/App-C9PsvW9C.mjs +580 -0
  4. package/dist/admin/App-KJvUCwN1.js +580 -0
  5. package/dist/admin/PinnedBookmarksWidget-ClskVR1i.mjs +55 -0
  6. package/dist/admin/PinnedBookmarksWidget-DlD8lDhq.js +55 -0
  7. package/dist/admin/de-BF0nCjGF.mjs +183 -0
  8. package/dist/admin/de-Cn90CcnC.js +183 -0
  9. package/dist/admin/en-D-EGHodf.mjs +183 -0
  10. package/dist/admin/en-GDfO_EfL.js +183 -0
  11. package/dist/admin/es-6o-_RABX.js +183 -0
  12. package/dist/admin/es-C33BufuB.mjs +183 -0
  13. package/dist/admin/fr-BOZS5mJT.js +183 -0
  14. package/dist/admin/fr-DJHTjkmb.mjs +183 -0
  15. package/dist/admin/index-CLjQOzqv.js +1770 -0
  16. package/dist/admin/index-X8I03cOT.mjs +1769 -0
  17. package/dist/admin/index.js +4 -2
  18. package/dist/admin/index.mjs +2 -1
  19. package/dist/admin/pt-D13SxuK2.js +183 -0
  20. package/dist/admin/pt-yoB1jrsq.mjs +183 -0
  21. package/dist/server/index.js +1129 -1542
  22. package/dist/server/index.mjs +1126 -1539
  23. package/package.json +90 -54
  24. package/strapi-admin.js +5 -0
  25. package/strapi-server.js +2 -1
  26. package/COPYRIGHT_NOTICE.txt +0 -20
  27. package/dist/_chunks/App-CozIqdTt.mjs +0 -1509
  28. package/dist/_chunks/App-DFDDcq8K.js +0 -1511
  29. package/dist/_chunks/UpgradePage-9godO_5E.mjs +0 -351
  30. package/dist/_chunks/UpgradePage-CwYDN8bT.js +0 -353
  31. package/dist/_chunks/de-Cs9dd3Mr.js +0 -138
  32. package/dist/_chunks/de-DOVki5VS.mjs +0 -138
  33. package/dist/_chunks/en-CE3r46Y2.js +0 -138
  34. package/dist/_chunks/en-Cf5-O03L.mjs +0 -138
  35. package/dist/_chunks/es-Ba6JcPIm.mjs +0 -138
  36. package/dist/_chunks/es-D4AOyJYJ.js +0 -138
  37. package/dist/_chunks/fr-CWSfoA8i.js +0 -138
  38. package/dist/_chunks/fr-CrMBXR3c.mjs +0 -138
  39. package/dist/_chunks/index-DCsuhvUc.js +0 -2698
  40. package/dist/_chunks/index-DNoxLWi0.mjs +0 -2694
  41. package/dist/_chunks/index-JirQF8zE.mjs +0 -328
  42. package/dist/_chunks/index-uUErgmi9.js +0 -330
  43. package/dist/_chunks/pt-BXxZ1Zym.mjs +0 -138
  44. package/dist/_chunks/pt-DW_6r_mP.js +0 -138
  45. package/pics/advancedFilters.png +0 -0
  46. package/pics/dashboard.png +0 -0
  47. package/pics/quickaccesinContentmanager.png +0 -0
  48. package/pics/saveAsMagicMark.png +0 -0
@@ -1,2698 +0,0 @@
1
- "use strict";
2
- const React = require("react");
3
- const admin = require("@strapi/strapi/admin");
4
- const jsxRuntime = require("react/jsx-runtime");
5
- const icons = require("@strapi/icons");
6
- const outline = require("@heroicons/react/24/outline");
7
- const reactIntl = require("react-intl");
8
- const reactRouterDom = require("react-router-dom");
9
- const styled = require("styled-components");
10
- const designSystem = require("@strapi/design-system");
11
- const ReactDOM = require("react-dom");
12
- const qs = require("qs");
13
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
- const React__default = /* @__PURE__ */ _interopDefault(React);
15
- const styled__default = /* @__PURE__ */ _interopDefault(styled);
16
- const ReactDOM__default = /* @__PURE__ */ _interopDefault(ReactDOM);
17
- const qs__default = /* @__PURE__ */ _interopDefault(qs);
18
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
19
- const v = glob[path];
20
- if (v) {
21
- return typeof v === "function" ? v() : Promise.resolve(v);
22
- }
23
- return new Promise((_, reject) => {
24
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
25
- reject.bind(
26
- null,
27
- new Error(
28
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
29
- )
30
- )
31
- );
32
- });
33
- };
34
- const strapi = {
35
- name: "magic-mark"
36
- };
37
- const pluginPkg = {
38
- strapi
39
- };
40
- const pluginId = "magic-mark";
41
- const Initializer = ({ setPlugin }) => {
42
- const ref = React.useRef(setPlugin);
43
- const { get } = admin.useFetchClient();
44
- React.useEffect(() => {
45
- ref.current(pluginId);
46
- }, []);
47
- React.useEffect(() => {
48
- const HEARTBEAT_INTERVAL = 4 * 60 * 1e3;
49
- const heartbeat = async () => {
50
- try {
51
- await get(`/${pluginId}/license/status`);
52
- } catch (error) {
53
- }
54
- };
55
- const initialTimeout = setTimeout(heartbeat, 60 * 1e3);
56
- const interval = setInterval(heartbeat, HEARTBEAT_INTERVAL);
57
- return () => {
58
- clearTimeout(initialTimeout);
59
- clearInterval(interval);
60
- };
61
- }, [get]);
62
- return null;
63
- };
64
- const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.Book, {});
65
- const parseQueryString = (queryString) => {
66
- const result = {
67
- filters: [],
68
- sort: [],
69
- populate: []
70
- };
71
- if (!queryString) return result;
72
- const params = new URLSearchParams(queryString);
73
- params.forEach((value, key) => {
74
- console.log("[QueryParser] Parsing:", key, "=", value);
75
- if (key.startsWith("filters[")) {
76
- const filter = parseFilterKey(key, value);
77
- if (filter) {
78
- result.filters.push(filter);
79
- }
80
- } else if (key === "sort") {
81
- result.sort = value.split(",").map((s) => s.trim());
82
- } else if (key.startsWith("populate")) {
83
- const populateField = extractPopulateField(key);
84
- if (populateField && !result.populate.includes(populateField)) {
85
- result.populate.push(populateField);
86
- }
87
- } else if (key === "page") {
88
- result.page = parseInt(value);
89
- } else if (key === "pageSize") {
90
- result.pageSize = parseInt(value);
91
- }
92
- });
93
- return result;
94
- };
95
- const parseFilterKey = (key, value) => {
96
- try {
97
- let logic;
98
- if (key.includes("[$and]")) {
99
- logic = "AND";
100
- } else if (key.includes("[$or]")) {
101
- logic = "OR";
102
- }
103
- const fieldMatch = key.match(/\[([^\]$]+)\](?=\[\$)/);
104
- const field = fieldMatch ? fieldMatch[1] : null;
105
- const operatorMatch = key.match(/\[\$(\w+)\]/);
106
- const operator = operatorMatch ? operatorMatch[1] : "eq";
107
- if (!field) {
108
- console.warn("[QueryParser] Could not extract field from:", key);
109
- return null;
110
- }
111
- return {
112
- field: formatFieldName(field),
113
- operator: formatOperator(operator),
114
- value,
115
- logic
116
- };
117
- } catch (error) {
118
- console.error("[QueryParser] Error parsing filter:", key, error);
119
- return null;
120
- }
121
- };
122
- const extractPopulateField = (key) => {
123
- const match = key.match(/populate\[([^\]]+)\]/);
124
- return match ? match[1] : null;
125
- };
126
- const formatFieldName = (field) => {
127
- const formatted = field.replace(/([A-Z])/g, " $1");
128
- return formatted.charAt(0).toUpperCase() + formatted.slice(1);
129
- };
130
- const formatOperator = (operator) => {
131
- const operatorMap = {
132
- "eq": "=",
133
- "ne": "≠",
134
- "lt": "<",
135
- "lte": "≤",
136
- "gt": ">",
137
- "gte": "≥",
138
- "in": "in",
139
- "notIn": "not in",
140
- "contains": "contains",
141
- "notContains": "not contains",
142
- "containsi": "contains (case insensitive)",
143
- "notContainsi": "not contains (case insensitive)",
144
- "startsWith": "starts with",
145
- "endsWith": "ends with",
146
- "null": "is null",
147
- "notNull": "is not null"
148
- };
149
- return operatorMap[operator] || operator;
150
- };
151
- const FilterChip = styled__default.default.div`
152
- display: inline-flex;
153
- align-items: center;
154
- padding: 4px 12px;
155
- border-radius: 4px;
156
- background: ${(props) => props.logic === "OR" ? props.theme.colors.warning100 : props.theme.colors.primary100};
157
- border: 1px solid ${(props) => props.logic === "OR" ? props.theme.colors.warning500 : props.theme.colors.primary500};
158
- font-size: 12px;
159
- margin: 4px;
160
- gap: 4px;
161
- color: ${(props) => props.theme.colors.neutral800};
162
- `;
163
- const LogicBadge = styled__default.default.span`
164
- font-weight: bold;
165
- color: ${(props) => props.logic === "OR" ? props.theme.colors.warning700 : props.theme.colors.primary700};
166
- font-size: 10px;
167
- text-transform: uppercase;
168
- `;
169
- const PopulateChip = styled__default.default.div`
170
- display: inline-flex;
171
- align-items: center;
172
- padding: 4px 12px;
173
- border-radius: 4px;
174
- background: ${(props) => props.theme.colors.success100};
175
- border: 1px solid ${(props) => props.theme.colors.success500};
176
- font-size: 12px;
177
- margin: 4px;
178
- color: ${(props) => props.theme.colors.neutral800};
179
- `;
180
- const SortChip = styled__default.default.div`
181
- display: inline-flex;
182
- align-items: center;
183
- padding: 4px 12px;
184
- border-radius: 4px;
185
- background: ${(props) => props.theme.colors.warning100};
186
- border: 1px solid ${(props) => props.theme.colors.warning500};
187
- font-size: 12px;
188
- margin: 4px;
189
- color: ${(props) => props.theme.colors.neutral800};
190
- `;
191
- const FilterPreview = ({ query }) => {
192
- const parsed = parseQueryString(query);
193
- if (!query || parsed.filters.length === 0 && parsed.sort.length === 0 && parsed.populate.length === 0) {
194
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "neutral100", borderRadius: "4px", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "No filters applied" }) });
195
- }
196
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 3, background: "neutral100", borderRadius: "4px", children: [
197
- parsed.filters.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 2, children: [
198
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", style: { marginBottom: "8px", display: "block" }, children: "Filters:" }),
199
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { wrap: "wrap", gap: 1, children: parsed.filters.map((filter, idx) => /* @__PURE__ */ jsxRuntime.jsxs(FilterChip, { logic: filter.logic, children: [
200
- filter.logic && /* @__PURE__ */ jsxRuntime.jsx(LogicBadge, { logic: filter.logic, children: filter.logic }),
201
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
202
- filter.field,
203
- " ",
204
- filter.operator,
205
- " ",
206
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: filter.value })
207
- ] })
208
- ] }, idx)) })
209
- ] }),
210
- parsed.sort.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 2, children: [
211
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", style: { marginBottom: "8px", display: "block" }, children: "Sorting:" }),
212
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { wrap: "wrap", gap: 1, children: parsed.sort.map((sort, idx) => /* @__PURE__ */ jsxRuntime.jsxs(SortChip, { children: [
213
- /* @__PURE__ */ jsxRuntime.jsx(icons.Filter, { width: "12px", height: "12px", style: { marginRight: "4px" } }),
214
- " ",
215
- sort
216
- ] }, idx)) })
217
- ] }),
218
- parsed.populate.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
219
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", style: { marginBottom: "8px", display: "block" }, children: "Relations:" }),
220
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { wrap: "wrap", gap: 1, children: parsed.populate.map((field, idx) => /* @__PURE__ */ jsxRuntime.jsxs(PopulateChip, { children: [
221
- /* @__PURE__ */ jsxRuntime.jsx(icons.Link, { width: "12px", height: "12px", style: { marginRight: "4px" } }),
222
- " ",
223
- field
224
- ] }, idx)) })
225
- ] })
226
- ] });
227
- };
228
- const theme = {
229
- colors: {
230
- primary: { 500: "#4945FF", 600: "#3B38E0", 100: "#EEF0FF", 200: "#D9D8FF" },
231
- secondary: { 100: "#F0F0FF" },
232
- danger: { 500: "#D02B20", 100: "#FCECEA" },
233
- neutral: { 200: "#DCDCE4", 400: "#A5A5BA", 600: "#666687" }
234
- },
235
- shadows: {
236
- md: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
237
- xl: "0 20px 25px -5px rgba(0, 0, 0, 0.15)"
238
- },
239
- gradients: {
240
- header: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)"
241
- }
242
- };
243
- const BOOKMARK_ICONS = [
244
- { id: "bookmark", icon: outline.BookmarkIcon, label: "Bookmark" },
245
- { id: "book", icon: outline.BookOpenIcon, label: "Book" },
246
- { id: "star", icon: outline.StarIcon, label: "Star" },
247
- { id: "heart", icon: outline.HeartIcon, label: "Heart" },
248
- { id: "bolt", icon: outline.BoltIcon, label: "Lightning" },
249
- { id: "rocket", icon: outline.RocketLaunchIcon, label: "Rocket" },
250
- { id: "pencil", icon: outline.PencilIcon, label: "Pencil" },
251
- { id: "link", icon: outline.LinkIcon, label: "Link" },
252
- { id: "sparkles", icon: outline.SparklesIcon, label: "Sparkles" },
253
- { id: "briefcase", icon: outline.BriefcaseIcon, label: "Briefcase" },
254
- { id: "photo", icon: outline.PhotoIcon, label: "Photo" },
255
- { id: "document", icon: outline.DocumentIcon, label: "Document" },
256
- { id: "bell", icon: outline.BellIcon, label: "Bell" },
257
- { id: "check", icon: outline.CheckCircleIcon, label: "Check" },
258
- { id: "gift", icon: outline.GiftIcon, label: "Gift" },
259
- { id: "user", icon: outline.UserIcon, label: "User" },
260
- { id: "users", icon: outline.UserGroupIcon, label: "Users" },
261
- { id: "mail", icon: outline.EnvelopeIcon, label: "Mail" },
262
- { id: "calendar", icon: outline.CalendarIcon, label: "Calendar" },
263
- { id: "clock", icon: outline.ClockIcon, label: "Clock" },
264
- { id: "folder", icon: outline.FolderIcon, label: "Folder" },
265
- { id: "search", icon: outline.MagnifyingGlassIcon, label: "Search" },
266
- { id: "filter", icon: outline.FunnelIcon, label: "Filter" },
267
- { id: "globe", icon: outline.GlobeAltIcon, label: "Globe" },
268
- { id: "tag", icon: outline.TagIcon, label: "Tag" },
269
- { id: "flag", icon: outline.FlagIcon, label: "Flag" },
270
- { id: "fire", icon: outline.FireIcon, label: "Fire" },
271
- { id: "cube", icon: outline.CubeIcon, label: "Cube" },
272
- { id: "home", icon: outline.HomeIcon, label: "Home" },
273
- { id: "cog", icon: outline.CogIcon, label: "Settings" },
274
- { id: "wrench", icon: outline.WrenchIcon, label: "Wrench" },
275
- { id: "terminal", icon: outline.CommandLineIcon, label: "Terminal" },
276
- { id: "chart", icon: outline.ChartBarIcon, label: "Chart" }
277
- ];
278
- const getIconById = (iconId) => {
279
- const found = BOOKMARK_ICONS.find((i) => i.id === iconId);
280
- return found ? found.icon : outline.BookmarkIcon;
281
- };
282
- const fadeIn$1 = styled.keyframes`
283
- from { opacity: 0; transform: scale(0.95); }
284
- to { opacity: 1; transform: scale(1); }
285
- `;
286
- styled.keyframes`
287
- from { opacity: 0; max-height: 0; }
288
- to { opacity: 1; max-height: 500px; }
289
- `;
290
- const Overlay = styled__default.default.div`
291
- position: fixed;
292
- top: 0;
293
- left: 0;
294
- right: 0;
295
- bottom: 0;
296
- background: rgba(0, 0, 0, 0.6);
297
- backdrop-filter: blur(4px);
298
- display: flex;
299
- align-items: center;
300
- justify-content: center;
301
- z-index: 999;
302
- `;
303
- const ModalContainer = styled__default.default.div`
304
- background: ${(p) => p.theme.colors.neutral0};
305
- border-radius: 16px;
306
- max-height: 90vh;
307
- overflow: hidden;
308
- max-width: 580px;
309
- width: 95%;
310
- box-shadow: ${theme.shadows.xl};
311
- animation: ${fadeIn$1} 0.2s ease-out;
312
- display: flex;
313
- flex-direction: column;
314
- `;
315
- const ModalHeader = styled__default.default.div`
316
- background: ${theme.gradients.header};
317
- padding: 24px 28px;
318
- display: flex;
319
- justify-content: space-between;
320
- align-items: center;
321
- `;
322
- const HeaderTitle = styled__default.default.h2`
323
- color: white;
324
- font-size: 1.25rem;
325
- font-weight: 600;
326
- margin: 0;
327
- display: flex;
328
- align-items: center;
329
- gap: 10px;
330
-
331
- svg {
332
- width: 24px;
333
- height: 24px;
334
- }
335
- `;
336
- const CloseButton = styled__default.default.button`
337
- background: rgba(255, 255, 255, 0.2);
338
- border: none;
339
- border-radius: 8px;
340
- padding: 8px;
341
- cursor: pointer;
342
- display: flex;
343
- align-items: center;
344
- justify-content: center;
345
- transition: all 0.15s ease;
346
-
347
- svg {
348
- width: 20px;
349
- height: 20px;
350
- color: white;
351
- }
352
-
353
- &:hover {
354
- background: rgba(255, 255, 255, 0.3);
355
- transform: scale(1.05);
356
- }
357
- `;
358
- const ModalBody = styled__default.default.div`
359
- padding: 24px 28px;
360
- overflow-y: auto;
361
- flex: 1;
362
- `;
363
- const ModalFooter = styled__default.default.div`
364
- padding: 16px 28px;
365
- background: ${(p) => p.theme.colors.neutral100};
366
- border-top: 1px solid rgba(128, 128, 128, 0.25);
367
- display: flex;
368
- justify-content: flex-end;
369
- gap: 12px;
370
- `;
371
- const Section = styled__default.default.div`
372
- margin-bottom: 20px;
373
- border: 1px solid rgba(128, 128, 128, 0.25);
374
- border-radius: 12px;
375
- overflow: hidden;
376
- background: ${(p) => p.theme.colors.neutral0};
377
- transition: all 0.2s ease;
378
-
379
- &:hover {
380
- border-color: ${theme.colors.primary[200]};
381
- }
382
- `;
383
- const SectionHeader = styled__default.default.button`
384
- width: 100%;
385
- padding: 14px 16px;
386
- background: ${(p) => p.theme.colors.neutral100};
387
- border: none;
388
- cursor: pointer;
389
- display: flex;
390
- align-items: center;
391
- justify-content: space-between;
392
- transition: all 0.15s ease;
393
-
394
- &:hover {
395
- background: ${(p) => p.theme.colors.neutral200};
396
- }
397
- `;
398
- const SectionTitle = styled__default.default.div`
399
- display: flex;
400
- align-items: center;
401
- gap: 10px;
402
- font-weight: 600;
403
- font-size: 0.875rem;
404
- color: ${(p) => p.theme.colors.neutral800};
405
-
406
- svg {
407
- width: 18px;
408
- height: 18px;
409
- color: ${theme.colors.primary[500]};
410
- }
411
- `;
412
- const SectionContent = styled__default.default.div`
413
- padding: ${(props) => props.$collapsed ? "0" : "16px"};
414
- max-height: ${(props) => props.$collapsed ? "0" : "500px"};
415
- opacity: ${(props) => props.$collapsed ? "0" : "1"};
416
- overflow: hidden;
417
- transition: all 0.25s ease;
418
- `;
419
- const ChevronIcon = styled__default.default.div`
420
- transform: rotate(${(props) => props.$collapsed ? "0" : "180deg"});
421
- transition: transform 0.2s ease;
422
-
423
- svg {
424
- width: 18px;
425
- height: 18px;
426
- color: ${(p) => p.theme.colors.neutral600};
427
- }
428
- `;
429
- const IconPicker = styled__default.default.div`
430
- display: grid;
431
- grid-template-columns: repeat(8, 1fr);
432
- gap: 8px;
433
- padding: 12px;
434
- background: ${(p) => p.theme.colors.neutral100};
435
- border-radius: 8px;
436
- max-height: 180px;
437
- overflow-y: auto;
438
-
439
- &::-webkit-scrollbar {
440
- width: 6px;
441
- }
442
-
443
- &::-webkit-scrollbar-track {
444
- background: transparent;
445
- }
446
-
447
- &::-webkit-scrollbar-thumb {
448
- background: ${theme.colors.neutral[400]};
449
- border-radius: 3px;
450
- }
451
- `;
452
- const IconButton = styled__default.default.button`
453
- display: flex;
454
- align-items: center;
455
- justify-content: center;
456
- padding: 10px;
457
- border: 2px solid ${(props) => props.$isSelected ? theme.colors.primary[500] : "transparent"};
458
- background: ${(props) => props.$isSelected ? theme.colors.primary[100] : props.theme.colors.neutral0};
459
- border-radius: 8px;
460
- cursor: pointer;
461
- transition: all 0.15s ease;
462
-
463
- svg {
464
- width: 20px;
465
- height: 20px;
466
- color: ${(props) => props.$isSelected ? theme.colors.primary[500] : props.theme.colors.neutral600};
467
- }
468
-
469
- &:hover {
470
- border-color: ${theme.colors.primary[500]};
471
- background: ${theme.colors.primary[100]};
472
- transform: scale(1.08);
473
-
474
- svg {
475
- color: ${theme.colors.primary[500]};
476
- }
477
- }
478
- `;
479
- const SelectedIconDisplay = styled__default.default.div`
480
- display: flex;
481
- align-items: center;
482
- gap: 16px;
483
- padding: 12px 16px;
484
- background: linear-gradient(135deg, ${theme.colors.primary[100]} 0%, ${theme.colors.secondary[100]} 100%);
485
- border-radius: 10px;
486
- margin-bottom: 12px;
487
- `;
488
- const SelectedIconCircle = styled__default.default.div`
489
- width: 52px;
490
- height: 52px;
491
- border-radius: 12px;
492
- background: ${(p) => p.theme.colors.neutral0};
493
- border: 2px solid ${theme.colors.primary[500]};
494
- display: flex;
495
- align-items: center;
496
- justify-content: center;
497
- box-shadow: ${theme.shadows.md};
498
-
499
- svg {
500
- width: 26px;
501
- height: 26px;
502
- color: ${theme.colors.primary[500]};
503
- }
504
- `;
505
- const PublicToggleContainer = styled__default.default.div`
506
- display: flex;
507
- align-items: center;
508
- justify-content: space-between;
509
- padding: 14px 16px;
510
- background: ${(p) => p.theme.colors.neutral100};
511
- border-radius: 10px;
512
- margin-bottom: 16px;
513
- `;
514
- const PublicToggleInfo = styled__default.default.div`
515
- display: flex;
516
- align-items: center;
517
- gap: 12px;
518
-
519
- svg {
520
- width: 20px;
521
- height: 20px;
522
- color: ${theme.colors.primary[500]};
523
- }
524
- `;
525
- const SwitchContainer = styled__default.default.label`
526
- position: relative;
527
- display: inline-flex;
528
- align-items: center;
529
- cursor: pointer;
530
- `;
531
- const SwitchInput = styled__default.default.input`
532
- opacity: 0;
533
- width: 0;
534
- height: 0;
535
- position: absolute;
536
- `;
537
- const SwitchSlider = styled__default.default.span`
538
- position: relative;
539
- width: 44px;
540
- height: 24px;
541
- background: ${(props) => props.$checked ? theme.colors.primary[500] : theme.colors.neutral[300]};
542
- border-radius: 24px;
543
- transition: all 0.2s ease;
544
-
545
- &::before {
546
- content: '';
547
- position: absolute;
548
- width: 18px;
549
- height: 18px;
550
- left: ${(props) => props.$checked ? "23px" : "3px"};
551
- top: 3px;
552
- background: white;
553
- border-radius: 50%;
554
- transition: all 0.2s ease;
555
- box-shadow: 0 1px 3px rgba(0,0,0,0.2);
556
- }
557
-
558
- &:hover {
559
- background: ${(props) => props.$checked ? theme.colors.primary[600] : theme.colors.neutral[400]};
560
- }
561
- `;
562
- const SelectionList = styled__default.default.div`
563
- max-height: 140px;
564
- overflow-y: auto;
565
- border: 1px solid rgba(128, 128, 128, 0.25);
566
- border-radius: 8px;
567
- background: ${(props) => props.$disabled ? props.theme.colors.neutral100 : props.theme.colors.neutral0};
568
- opacity: ${(props) => props.$disabled ? 0.6 : 1};
569
- pointer-events: ${(props) => props.$disabled ? "none" : "auto"};
570
-
571
- &::-webkit-scrollbar {
572
- width: 6px;
573
- }
574
-
575
- &::-webkit-scrollbar-track {
576
- background: transparent;
577
- }
578
-
579
- &::-webkit-scrollbar-thumb {
580
- background: ${theme.colors.neutral[400]};
581
- border-radius: 3px;
582
- }
583
- `;
584
- const SelectionItem = styled__default.default.label`
585
- display: flex;
586
- align-items: center;
587
- gap: 12px;
588
- padding: 10px 14px;
589
- cursor: pointer;
590
- border-bottom: 1px solid rgba(128, 128, 128, 0.25);
591
- background: ${(props) => props.$selected ? theme.colors.primary[100] : "transparent"};
592
- transition: all 0.15s ease;
593
-
594
- &:last-child {
595
- border-bottom: none;
596
- }
597
-
598
- &:hover {
599
- background: ${(props) => props.$selected ? theme.colors.primary[100] : props.theme.colors.neutral100};
600
- }
601
- `;
602
- const CustomCheckbox = styled__default.default.div`
603
- width: 20px;
604
- height: 20px;
605
- border-radius: 4px;
606
- border: 2px solid ${(props) => props.$checked ? theme.colors.primary[500] : props.theme.colors.neutral400};
607
- background: ${(props) => props.$checked ? theme.colors.primary[500] : "transparent"};
608
- display: flex;
609
- align-items: center;
610
- justify-content: center;
611
- transition: all 0.15s ease;
612
- flex-shrink: 0;
613
-
614
- svg {
615
- width: 14px;
616
- height: 14px;
617
- color: white;
618
- opacity: ${(props) => props.$checked ? 1 : 0};
619
- }
620
- `;
621
- const ItemLabel = styled__default.default.span`
622
- font-size: 0.875rem;
623
- color: ${(props) => props.$selected ? theme.colors.primary[600] : props.theme.colors.neutral800};
624
- font-weight: ${(props) => props.$selected ? 600 : 400};
625
- `;
626
- const ItemBadge = styled__default.default.span`
627
- font-size: 0.7rem;
628
- padding: 2px 6px;
629
- border-radius: 4px;
630
- background: ${(props) => props.$type === "custom" ? "#F3E8FF" : theme.colors.neutral[200]};
631
- color: ${(props) => props.$type === "custom" ? "#8B5CF6" : theme.colors.neutral[600]};
632
- font-weight: 500;
633
- `;
634
- const FormField = styled__default.default.div`
635
- margin-bottom: 16px;
636
-
637
- &:last-child {
638
- margin-bottom: 0;
639
- }
640
- `;
641
- const Label = styled__default.default.label`
642
- display: block;
643
- font-size: 0.875rem;
644
- font-weight: 600;
645
- color: ${(p) => p.theme.colors.neutral800};
646
- margin-bottom: 8px;
647
- `;
648
- const HintText = styled__default.default.p`
649
- font-size: 0.75rem;
650
- color: ${(p) => p.theme.colors.neutral600};
651
- margin-top: 6px;
652
- display: flex;
653
- align-items: center;
654
- gap: 6px;
655
-
656
- svg {
657
- width: 14px;
658
- height: 14px;
659
- flex-shrink: 0;
660
- }
661
- `;
662
- const PathDisplay = styled__default.default.div`
663
- padding: 12px 14px;
664
- background: ${(p) => p.theme.colors.neutral100};
665
- border: 1px solid rgba(128, 128, 128, 0.25);
666
- border-radius: 8px;
667
- font-family: 'Monaco', 'Menlo', monospace;
668
- font-size: 0.8rem;
669
- color: ${(p) => p.theme.colors.neutral600};
670
- word-break: break-all;
671
- `;
672
- const ErrorBox = styled__default.default.div`
673
- padding: 12px 16px;
674
- background: ${theme.colors.danger[100]};
675
- border: 1px solid ${theme.colors.danger[500]};
676
- border-radius: 8px;
677
- margin-bottom: 16px;
678
-
679
- p {
680
- color: ${theme.colors.danger[500]};
681
- font-size: 0.875rem;
682
- margin: 0;
683
- }
684
- `;
685
- const SectionLabel = styled__default.default.div`
686
- font-size: 0.75rem;
687
- font-weight: 600;
688
- color: ${(p) => p.theme.colors.neutral600};
689
- text-transform: uppercase;
690
- letter-spacing: 0.5px;
691
- margin-bottom: 8px;
692
- margin-top: 12px;
693
-
694
- &:first-child {
695
- margin-top: 0;
696
- }
697
- `;
698
- const StyledTextInput = styled__default.default(designSystem.TextInput)`
699
- input {
700
- border-radius: 8px;
701
- border: 1px solid rgba(128, 128, 128, 0.25);
702
-
703
- &:focus {
704
- border-color: ${theme.colors.primary[500]};
705
- box-shadow: 0 0 0 3px ${theme.colors.primary[100]};
706
- }
707
- }
708
- `;
709
- const StyledTextarea = styled__default.default(designSystem.Textarea)`
710
- textarea {
711
- border-radius: 8px;
712
- border: 1px solid rgba(128, 128, 128, 0.25);
713
- min-height: 80px;
714
-
715
- &:focus {
716
- border-color: ${theme.colors.primary[500]};
717
- box-shadow: 0 0 0 3px ${theme.colors.primary[100]};
718
- }
719
- }
720
- `;
721
- const CreateEditModal = ({
722
- bookmark,
723
- onClose,
724
- onSuccess,
725
- pluginId: pluginId2,
726
- currentPath,
727
- currentQuery
728
- }) => {
729
- const { formatMessage } = reactIntl.useIntl();
730
- const { post, put, get } = admin.useFetchClient();
731
- const [name2, setName] = React.useState("");
732
- const [path, setPath] = React.useState(currentPath || "");
733
- const [query, setQuery] = React.useState(currentQuery || "");
734
- const [icon, setIcon] = React.useState("bookmark");
735
- const [description, setDescription] = React.useState("");
736
- const [isSubmitting, setIsSubmitting] = React.useState(false);
737
- const [error, setError] = React.useState("");
738
- const [isPublic, setIsPublic] = React.useState(false);
739
- const [sharedWithRoles, setSharedWithRoles] = React.useState([]);
740
- const [sharedWithUsers, setSharedWithUsers] = React.useState([]);
741
- const [availableRoles, setAvailableRoles] = React.useState([]);
742
- const [availableUsers, setAvailableUsers] = React.useState([]);
743
- const [loadingRoles, setLoadingRoles] = React.useState(false);
744
- const [loadingUsers, setLoadingUsers] = React.useState(false);
745
- const [iconSectionOpen, setIconSectionOpen] = React.useState(true);
746
- const [sharingSectionOpen, setSharingSectionOpen] = React.useState(false);
747
- const [filtersSectionOpen, setFiltersSectionOpen] = React.useState(false);
748
- React.useEffect(() => {
749
- if (bookmark) {
750
- setName(bookmark.name);
751
- setPath(bookmark.path);
752
- setQuery(bookmark.query || "");
753
- setIcon(bookmark.icon || bookmark.emoji || "bookmark");
754
- setDescription(bookmark.description || "");
755
- setIsPublic(bookmark.isPublic || false);
756
- setSharedWithRoles(bookmark.sharedWithRoles || []);
757
- setSharedWithUsers(bookmark.sharedWithUsers || []);
758
- }
759
- fetchRoles();
760
- fetchUsers();
761
- }, [bookmark]);
762
- const fetchRoles = async () => {
763
- setLoadingRoles(true);
764
- try {
765
- const response = await get(`/${pluginId2}/roles`);
766
- const roles = response.data?.data?.data || response.data?.data || response.data || [];
767
- setAvailableRoles(roles);
768
- } catch (error2) {
769
- console.error("[Magic-Mark] Error fetching roles:", error2);
770
- } finally {
771
- setLoadingRoles(false);
772
- }
773
- };
774
- const fetchUsers = async () => {
775
- setLoadingUsers(true);
776
- try {
777
- const meResponse = await get("/admin/users/me");
778
- const currentUser = meResponse.data?.data || meResponse.data || meResponse;
779
- const currentUserId = currentUser?.id;
780
- const currentUserEmail = currentUser?.email;
781
- const response = await get("/admin/users?pageSize=100&page=1&sort=firstname");
782
- const allUsers = response.data?.data?.results || response.data?.results || [];
783
- const users = Array.isArray(allUsers) ? allUsers.filter((u) => {
784
- const matchById = u.id === currentUserId || u.id === Number(currentUserId) || String(u.id) === String(currentUserId);
785
- const matchByEmail = u.email?.toLowerCase() === currentUserEmail?.toLowerCase();
786
- return !(matchById || matchByEmail);
787
- }) : [];
788
- setAvailableUsers(users);
789
- } catch (error2) {
790
- console.error("[Magic-Mark] Error fetching users:", error2);
791
- try {
792
- const response = await get(`/${pluginId2}/users`);
793
- const users = response.data?.data?.data || response.data?.data || response.data || [];
794
- setAvailableUsers(users);
795
- } catch (fallbackError) {
796
- setAvailableUsers([]);
797
- }
798
- } finally {
799
- setLoadingUsers(false);
800
- }
801
- };
802
- const validateForm = () => {
803
- setError("");
804
- if (!name2.trim()) {
805
- setError(formatMessage({ id: `${pluginId2}.error.nameRequired`, defaultMessage: "Name is required" }));
806
- return false;
807
- }
808
- if (!path.trim()) {
809
- setError(formatMessage({ id: `${pluginId2}.error.pathRequired`, defaultMessage: "Path is required" }));
810
- return false;
811
- }
812
- return true;
813
- };
814
- const handleSubmit = async () => {
815
- if (!validateForm()) return;
816
- setIsSubmitting(true);
817
- try {
818
- const bookmarkId = bookmark?.documentId || bookmark?.id;
819
- const endpoint = bookmark ? `/${pluginId2}/bookmarks/${bookmarkId}` : `/${pluginId2}/bookmarks`;
820
- const body = {
821
- name: name2,
822
- path,
823
- query,
824
- icon,
825
- emoji: icon,
826
- description,
827
- isPublic,
828
- sharedWithRoles,
829
- sharedWithUsers
830
- };
831
- if (bookmark) {
832
- await put(endpoint, body);
833
- } else {
834
- await post(endpoint, body);
835
- }
836
- onSuccess();
837
- } catch (error2) {
838
- console.error("[Magic-Mark] Error saving bookmark:", error2);
839
- setError(formatMessage({ id: `${pluginId2}.error.save`, defaultMessage: "Failed to save bookmark" }));
840
- } finally {
841
- setIsSubmitting(false);
842
- }
843
- };
844
- const toggleRole = (roleId) => {
845
- setSharedWithRoles(
846
- (prev) => prev.includes(roleId) ? prev.filter((id) => id !== roleId) : [...prev, roleId]
847
- );
848
- };
849
- const toggleUser = (userId) => {
850
- setSharedWithUsers(
851
- (prev) => prev.includes(userId) ? prev.filter((id) => id !== userId) : [...prev, userId]
852
- );
853
- };
854
- const isEditing = !!bookmark;
855
- const SelectedIcon = getIconById(icon);
856
- return /* @__PURE__ */ jsxRuntime.jsx(Overlay, { onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContainer, { onClick: (e) => e.stopPropagation(), children: [
857
- /* @__PURE__ */ jsxRuntime.jsxs(ModalHeader, { children: [
858
- /* @__PURE__ */ jsxRuntime.jsxs(HeaderTitle, { children: [
859
- /* @__PURE__ */ jsxRuntime.jsx(outline.BookmarkIcon, {}),
860
- isEditing ? formatMessage({ id: `${pluginId2}.modal.edit`, defaultMessage: "Edit Bookmark" }) : formatMessage({ id: `${pluginId2}.modal.create`, defaultMessage: "Save as Bookmark" })
861
- ] }),
862
- /* @__PURE__ */ jsxRuntime.jsx(CloseButton, { onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}) })
863
- ] }),
864
- /* @__PURE__ */ jsxRuntime.jsxs(ModalBody, { children: [
865
- error && /* @__PURE__ */ jsxRuntime.jsx(ErrorBox, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: error }) }),
866
- /* @__PURE__ */ jsxRuntime.jsxs(FormField, { children: [
867
- /* @__PURE__ */ jsxRuntime.jsxs(Label, { children: [
868
- formatMessage({ id: `${pluginId2}.form.name`, defaultMessage: "Bookmark Name" }),
869
- " *"
870
- ] }),
871
- /* @__PURE__ */ jsxRuntime.jsx(
872
- StyledTextInput,
873
- {
874
- type: "text",
875
- placeholder: formatMessage({ id: `${pluginId2}.form.namePlaceholder`, defaultMessage: "e.g., Published Articles" }),
876
- value: name2,
877
- onChange: (e) => setName(e.target.value)
878
- }
879
- )
880
- ] }),
881
- /* @__PURE__ */ jsxRuntime.jsxs(Section, { children: [
882
- /* @__PURE__ */ jsxRuntime.jsxs(SectionHeader, { onClick: () => setIconSectionOpen(!iconSectionOpen), children: [
883
- /* @__PURE__ */ jsxRuntime.jsxs(SectionTitle, { children: [
884
- /* @__PURE__ */ jsxRuntime.jsx(outline.SwatchIcon, {}),
885
- formatMessage({ id: `${pluginId2}.form.icon`, defaultMessage: "Choose Icon" })
886
- ] }),
887
- /* @__PURE__ */ jsxRuntime.jsx(ChevronIcon, { $collapsed: !iconSectionOpen, children: /* @__PURE__ */ jsxRuntime.jsx(outline.ChevronDownIcon, {}) })
888
- ] }),
889
- /* @__PURE__ */ jsxRuntime.jsxs(SectionContent, { $collapsed: !iconSectionOpen, children: [
890
- /* @__PURE__ */ jsxRuntime.jsxs(SelectedIconDisplay, { children: [
891
- /* @__PURE__ */ jsxRuntime.jsx(SelectedIconCircle, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectedIcon, {}) }),
892
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
893
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "semiBold", style: { color: "var(--colors-neutral800, #32324D)", display: "block" }, children: BOOKMARK_ICONS.find((i) => i.id === icon)?.label || "Bookmark" }),
894
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { fontSize: "0.75rem", display: "block" }, children: "Click below to change" })
895
- ] })
896
- ] }),
897
- /* @__PURE__ */ jsxRuntime.jsx(IconPicker, { children: BOOKMARK_ICONS.map((item) => {
898
- const IconComp = item.icon;
899
- return /* @__PURE__ */ jsxRuntime.jsx(
900
- IconButton,
901
- {
902
- $isSelected: icon === item.id,
903
- onClick: () => setIcon(item.id),
904
- type: "button",
905
- title: item.label,
906
- children: /* @__PURE__ */ jsxRuntime.jsx(IconComp, {})
907
- },
908
- item.id
909
- );
910
- }) })
911
- ] })
912
- ] }),
913
- /* @__PURE__ */ jsxRuntime.jsxs(Section, { children: [
914
- /* @__PURE__ */ jsxRuntime.jsxs(SectionHeader, { onClick: () => setSharingSectionOpen(!sharingSectionOpen), children: [
915
- /* @__PURE__ */ jsxRuntime.jsxs(SectionTitle, { children: [
916
- /* @__PURE__ */ jsxRuntime.jsx(outline.ShareIcon, {}),
917
- formatMessage({ id: `${pluginId2}.form.sharing`, defaultMessage: "Sharing Options" }),
918
- (isPublic || sharedWithRoles.length > 0 || sharedWithUsers.length > 0) && /* @__PURE__ */ jsxRuntime.jsx(ItemBadge, { children: isPublic ? "Public" : `${sharedWithRoles.length + sharedWithUsers.length} shared` })
919
- ] }),
920
- /* @__PURE__ */ jsxRuntime.jsx(ChevronIcon, { $collapsed: !sharingSectionOpen, children: /* @__PURE__ */ jsxRuntime.jsx(outline.ChevronDownIcon, {}) })
921
- ] }),
922
- /* @__PURE__ */ jsxRuntime.jsxs(SectionContent, { $collapsed: !sharingSectionOpen, children: [
923
- /* @__PURE__ */ jsxRuntime.jsxs(PublicToggleContainer, { children: [
924
- /* @__PURE__ */ jsxRuntime.jsxs(PublicToggleInfo, { children: [
925
- /* @__PURE__ */ jsxRuntime.jsx(outline.GlobeAltIcon, {}),
926
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
927
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "semiBold", style: { color: "var(--colors-neutral800, #32324D)", display: "block" }, children: "Public Bookmark" }),
928
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", style: { fontSize: "0.75rem", color: "var(--colors-neutral600, #666687)", display: "block" }, children: "All admin users can see this" })
929
- ] })
930
- ] }),
931
- /* @__PURE__ */ jsxRuntime.jsxs(SwitchContainer, { children: [
932
- /* @__PURE__ */ jsxRuntime.jsx(
933
- SwitchInput,
934
- {
935
- type: "checkbox",
936
- checked: isPublic,
937
- onChange: () => setIsPublic(!isPublic)
938
- }
939
- ),
940
- /* @__PURE__ */ jsxRuntime.jsx(SwitchSlider, { $checked: isPublic })
941
- ] })
942
- ] }),
943
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Share with Roles" }),
944
- /* @__PURE__ */ jsxRuntime.jsx(SelectionList, { $disabled: isPublic, children: loadingRoles ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "16px", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Loading..." }) }) : availableRoles.length > 0 ? availableRoles.map((role) => /* @__PURE__ */ jsxRuntime.jsxs(
945
- SelectionItem,
946
- {
947
- $selected: sharedWithRoles.includes(role.id),
948
- onClick: () => !isPublic && toggleRole(role.id),
949
- children: [
950
- /* @__PURE__ */ jsxRuntime.jsx(CustomCheckbox, { $checked: sharedWithRoles.includes(role.id), children: /* @__PURE__ */ jsxRuntime.jsx(outline.CheckCircleIcon, {}) }),
951
- /* @__PURE__ */ jsxRuntime.jsx(ItemLabel, { $selected: sharedWithRoles.includes(role.id), children: role.name || role.code }),
952
- role.isCustom && /* @__PURE__ */ jsxRuntime.jsx(ItemBadge, { $type: "custom", children: "Custom" }),
953
- role.userCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs(ItemBadge, { $type: "count", children: [
954
- role.userCount,
955
- " users"
956
- ] })
957
- ]
958
- },
959
- role.id
960
- )) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "16px", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "No roles available" }) }) }),
961
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Share with Users" }),
962
- /* @__PURE__ */ jsxRuntime.jsx(SelectionList, { $disabled: isPublic, children: loadingUsers ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "16px", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Loading..." }) }) : availableUsers.length > 0 ? availableUsers.map((user) => /* @__PURE__ */ jsxRuntime.jsxs(
963
- SelectionItem,
964
- {
965
- $selected: sharedWithUsers.includes(user.id),
966
- onClick: () => !isPublic && toggleUser(user.id),
967
- children: [
968
- /* @__PURE__ */ jsxRuntime.jsx(CustomCheckbox, { $checked: sharedWithUsers.includes(user.id), children: /* @__PURE__ */ jsxRuntime.jsx(outline.CheckCircleIcon, {}) }),
969
- /* @__PURE__ */ jsxRuntime.jsxs(ItemLabel, { $selected: sharedWithUsers.includes(user.id), children: [
970
- user.firstname || "",
971
- " ",
972
- user.lastname || ""
973
- ] }),
974
- /* @__PURE__ */ jsxRuntime.jsx(ItemBadge, { children: user.email })
975
- ]
976
- },
977
- user.id
978
- )) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "16px", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "No other users" }) }) })
979
- ] })
980
- ] }),
981
- /* @__PURE__ */ jsxRuntime.jsxs(Section, { children: [
982
- /* @__PURE__ */ jsxRuntime.jsxs(SectionHeader, { onClick: () => setFiltersSectionOpen(!filtersSectionOpen), children: [
983
- /* @__PURE__ */ jsxRuntime.jsxs(SectionTitle, { children: [
984
- /* @__PURE__ */ jsxRuntime.jsx(outline.FunnelIcon, {}),
985
- formatMessage({ id: `${pluginId2}.form.filterPreview`, defaultMessage: "Captured Filters" })
986
- ] }),
987
- /* @__PURE__ */ jsxRuntime.jsx(ChevronIcon, { $collapsed: !filtersSectionOpen, children: /* @__PURE__ */ jsxRuntime.jsx(outline.ChevronDownIcon, {}) })
988
- ] }),
989
- /* @__PURE__ */ jsxRuntime.jsxs(SectionContent, { $collapsed: !filtersSectionOpen, children: [
990
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Content Manager Path" }),
991
- /* @__PURE__ */ jsxRuntime.jsx(PathDisplay, { children: path || "No path captured" }),
992
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "Active Filters" }),
993
- /* @__PURE__ */ jsxRuntime.jsx(FilterPreview, { query }),
994
- /* @__PURE__ */ jsxRuntime.jsxs(HintText, { children: [
995
- /* @__PURE__ */ jsxRuntime.jsx(outline.LightBulbIcon, {}),
996
- "These filters will be restored when you click this bookmark"
997
- ] })
998
- ] })
999
- ] }),
1000
- /* @__PURE__ */ jsxRuntime.jsxs(FormField, { children: [
1001
- /* @__PURE__ */ jsxRuntime.jsxs(Label, { children: [
1002
- formatMessage({ id: `${pluginId2}.form.description`, defaultMessage: "Description" }),
1003
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 400, color: "var(--colors-neutral600, #666687)" }, children: " (Optional)" })
1004
- ] }),
1005
- /* @__PURE__ */ jsxRuntime.jsx(
1006
- StyledTextarea,
1007
- {
1008
- placeholder: formatMessage({ id: `${pluginId2}.form.descriptionPlaceholder`, defaultMessage: "Add a description..." }),
1009
- value: description,
1010
- onChange: (e) => setDescription(e.target.value)
1011
- }
1012
- )
1013
- ] })
1014
- ] }),
1015
- /* @__PURE__ */ jsxRuntime.jsxs(ModalFooter, { children: [
1016
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: onClose, variant: "tertiary", children: formatMessage({ id: `${pluginId2}.button.cancel`, defaultMessage: "Cancel" }) }),
1017
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleSubmit, loading: isSubmitting, children: isEditing ? formatMessage({ id: `${pluginId2}.button.update`, defaultMessage: "Update" }) : formatMessage({ id: `${pluginId2}.button.save`, defaultMessage: "Save Bookmark" }) })
1018
- ] })
1019
- ] }) });
1020
- };
1021
- const fadeIn = styled.keyframes`
1022
- from { opacity: 0; transform: translateY(-8px); }
1023
- to { opacity: 1; transform: translateY(0); }
1024
- `;
1025
- const PopoverContainer = styled__default.default.div`
1026
- position: absolute;
1027
- top: calc(100% + 8px);
1028
- right: 0;
1029
- min-width: 280px;
1030
- max-width: 360px;
1031
- max-height: 400px;
1032
- background: ${(p) => p.theme.colors.neutral0};
1033
- border: 1px solid rgba(128, 128, 128, 0.25);
1034
- border-radius: 8px;
1035
- box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
1036
- z-index: 1000;
1037
- animation: ${fadeIn} 0.2s ease-out;
1038
- overflow: hidden;
1039
- `;
1040
- const PopoverHeader = styled__default.default.div`
1041
- padding: 12px 16px;
1042
- background: linear-gradient(135deg, #4945FF 0%, #7B79FF 100%);
1043
- border-bottom: 1px solid rgba(128, 128, 128, 0.25);
1044
- display: flex;
1045
- align-items: center;
1046
- gap: 8px;
1047
-
1048
- svg {
1049
- width: 16px;
1050
- height: 16px;
1051
- color: white;
1052
- }
1053
- `;
1054
- const PopoverTitle = styled__default.default.span`
1055
- font-size: 13px;
1056
- font-weight: 600;
1057
- color: white;
1058
- `;
1059
- const PopoverCount = styled__default.default.span`
1060
- font-size: 11px;
1061
- color: rgba(255, 255, 255, 0.8);
1062
- margin-left: auto;
1063
- `;
1064
- const BookmarksList = styled__default.default.div`
1065
- max-height: 300px;
1066
- overflow-y: auto;
1067
- padding: 8px;
1068
-
1069
- &::-webkit-scrollbar {
1070
- width: 6px;
1071
- }
1072
-
1073
- &::-webkit-scrollbar-track {
1074
- background: rgba(128, 128, 128, 0.12);
1075
- border-radius: 3px;
1076
- }
1077
-
1078
- &::-webkit-scrollbar-thumb {
1079
- background: #c0c0cf;
1080
- border-radius: 3px;
1081
- }
1082
- `;
1083
- const BookmarkItem = styled__default.default.button`
1084
- width: 100%;
1085
- display: flex;
1086
- align-items: center;
1087
- gap: 10px;
1088
- padding: 10px 12px;
1089
- border: none;
1090
- border-radius: 6px;
1091
- background: ${(props) => props.$isPinned ? "#fffbeb" : "transparent"};
1092
- cursor: pointer;
1093
- transition: all 0.15s ease;
1094
- text-align: left;
1095
-
1096
- &:hover {
1097
- background: ${(props) => props.$isPinned ? "#fef3c7" : "#f6f6f9"};
1098
-
1099
- .arrow-icon {
1100
- opacity: 1;
1101
- transform: translateX(0);
1102
- }
1103
- }
1104
-
1105
- &:active {
1106
- transform: scale(0.98);
1107
- }
1108
- `;
1109
- const BookmarkIconWrapper = styled__default.default.div`
1110
- display: flex;
1111
- align-items: center;
1112
- justify-content: center;
1113
- width: 32px;
1114
- height: 32px;
1115
- background: linear-gradient(135deg, #EEF0FF 0%, #E0E7FF 100%);
1116
- border-radius: 6px;
1117
- flex-shrink: 0;
1118
-
1119
- svg {
1120
- width: 16px;
1121
- height: 16px;
1122
- color: #4945FF;
1123
- }
1124
- `;
1125
- const BookmarkContent = styled__default.default.div`
1126
- flex: 1;
1127
- min-width: 0;
1128
- `;
1129
- const BookmarkName = styled__default.default.div`
1130
- font-size: 13px;
1131
- font-weight: 500;
1132
- color: ${(p) => p.theme.colors.neutral800};
1133
- white-space: nowrap;
1134
- overflow: hidden;
1135
- text-overflow: ellipsis;
1136
- `;
1137
- const BookmarkDescription = styled__default.default.div`
1138
- font-size: 11px;
1139
- color: ${(p) => p.theme.colors.neutral500};
1140
- white-space: nowrap;
1141
- overflow: hidden;
1142
- text-overflow: ellipsis;
1143
- margin-top: 2px;
1144
- `;
1145
- const ArrowIcon = styled__default.default.div`
1146
- opacity: 0;
1147
- transform: translateX(-4px);
1148
- transition: all 0.15s ease;
1149
- color: #4945FF;
1150
-
1151
- svg {
1152
- width: 14px;
1153
- height: 14px;
1154
- }
1155
- `;
1156
- const PinIcon = styled__default.default.div`
1157
- color: #f59e0b;
1158
- flex-shrink: 0;
1159
-
1160
- svg {
1161
- width: 12px;
1162
- height: 12px;
1163
- }
1164
- `;
1165
- const EmptyState = styled__default.default.div`
1166
- padding: 24px 16px;
1167
- text-align: center;
1168
- `;
1169
- const EmptyIcon = styled__default.default.div`
1170
- width: 48px;
1171
- height: 48px;
1172
- margin: 0 auto 12px;
1173
- background: ${(p) => p.theme.colors.neutral100};
1174
- border-radius: 50%;
1175
- display: flex;
1176
- align-items: center;
1177
- justify-content: center;
1178
-
1179
- svg {
1180
- width: 24px;
1181
- height: 24px;
1182
- color: ${(p) => p.theme.colors.neutral500};
1183
- }
1184
- `;
1185
- const PopoverFooter = styled__default.default.div`
1186
- padding: 10px 16px;
1187
- border-top: 1px solid rgba(128, 128, 128, 0.2);
1188
- background: ${(p) => p.theme.colors.neutral100};
1189
- `;
1190
- const ViewAllLink = styled__default.default.button`
1191
- width: 100%;
1192
- display: flex;
1193
- align-items: center;
1194
- justify-content: center;
1195
- gap: 6px;
1196
- padding: 8px;
1197
- border: none;
1198
- border-radius: 4px;
1199
- background: transparent;
1200
- color: #4945FF;
1201
- font-size: 13px;
1202
- font-weight: 500;
1203
- cursor: pointer;
1204
- transition: all 0.15s ease;
1205
-
1206
- &:hover {
1207
- background: rgba(73, 69, 255, 0.08);
1208
- }
1209
-
1210
- svg {
1211
- width: 14px;
1212
- height: 14px;
1213
- }
1214
- `;
1215
- const ViewsListPopover = ({
1216
- views,
1217
- onViewClick,
1218
- isLoading = false
1219
- }) => {
1220
- const { formatMessage } = reactIntl.useIntl();
1221
- const navigate = reactRouterDom.useNavigate();
1222
- const sortedViews = [...views].sort((a, b) => {
1223
- if (a.isPinned && !b.isPinned) return -1;
1224
- if (!a.isPinned && b.isPinned) return 1;
1225
- return a.name.localeCompare(b.name);
1226
- });
1227
- return /* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { children: [
1228
- /* @__PURE__ */ jsxRuntime.jsxs(PopoverHeader, { children: [
1229
- /* @__PURE__ */ jsxRuntime.jsx(outline.BookmarkIcon, {}),
1230
- /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: "Your Bookmarks" }),
1231
- /* @__PURE__ */ jsxRuntime.jsxs(PopoverCount, { children: [
1232
- views.length,
1233
- " saved"
1234
- ] })
1235
- ] }),
1236
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx(EmptyState, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: "Loading..." }) }) : views && views.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1237
- /* @__PURE__ */ jsxRuntime.jsx(BookmarksList, { children: sortedViews.map((view) => {
1238
- const IconComponent = getIconById(view.icon || view.emoji || "bookmark");
1239
- return /* @__PURE__ */ jsxRuntime.jsxs(
1240
- BookmarkItem,
1241
- {
1242
- $isPinned: view.isPinned,
1243
- onClick: () => onViewClick(view),
1244
- children: [
1245
- /* @__PURE__ */ jsxRuntime.jsx(BookmarkIconWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(IconComponent, {}) }),
1246
- /* @__PURE__ */ jsxRuntime.jsxs(BookmarkContent, { children: [
1247
- /* @__PURE__ */ jsxRuntime.jsx(BookmarkName, { children: view.name }),
1248
- view.description && /* @__PURE__ */ jsxRuntime.jsx(BookmarkDescription, { children: view.description })
1249
- ] }),
1250
- view.isPinned && /* @__PURE__ */ jsxRuntime.jsx(PinIcon, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pin, {}) }),
1251
- /* @__PURE__ */ jsxRuntime.jsx(ArrowIcon, { className: "arrow-icon", children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRight, {}) })
1252
- ]
1253
- },
1254
- view.id
1255
- );
1256
- }) }),
1257
- /* @__PURE__ */ jsxRuntime.jsx(PopoverFooter, { children: /* @__PURE__ */ jsxRuntime.jsxs(ViewAllLink, { onClick: () => navigate(`/plugins/${pluginId}`), children: [
1258
- /* @__PURE__ */ jsxRuntime.jsx(outline.BookmarkIcon, {}),
1259
- "Manage all bookmarks"
1260
- ] }) })
1261
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(EmptyState, { children: [
1262
- /* @__PURE__ */ jsxRuntime.jsx(EmptyIcon, { children: /* @__PURE__ */ jsxRuntime.jsx(outline.BookmarkIcon, {}) }),
1263
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({
1264
- id: `${pluginId}.ViewsWidget.ViewsPopover.emptyList`,
1265
- defaultMessage: "No bookmarks yet. Save your first view!"
1266
- }) })
1267
- ] })
1268
- ] });
1269
- };
1270
- const WidgetContainer = styled__default.default.div`
1271
- display: flex;
1272
- align-items: center;
1273
- gap: 8px;
1274
- margin-right: 8px;
1275
- `;
1276
- const ActionButton = styled__default.default.button`
1277
- display: inline-flex;
1278
- align-items: center;
1279
- justify-content: center;
1280
- gap: 6px;
1281
- height: 36px;
1282
- padding: 0 14px;
1283
- font-size: 13px;
1284
- font-weight: 500;
1285
- border: 1px solid rgba(128, 128, 128, 0.25);
1286
- border-radius: 4px;
1287
- background: ${(p) => p.theme.colors.neutral0};
1288
- color: ${(p) => p.theme.colors.neutral800};
1289
- cursor: pointer;
1290
- transition: all 0.15s ease;
1291
- white-space: nowrap;
1292
-
1293
- &:hover {
1294
- background: ${(p) => p.theme.colors.neutral100};
1295
- border-color: rgba(128, 128, 128, 0.3);
1296
- }
1297
-
1298
- &:active {
1299
- transform: scale(0.98);
1300
- }
1301
-
1302
- svg {
1303
- width: 16px;
1304
- height: 16px;
1305
- flex-shrink: 0;
1306
- }
1307
- `;
1308
- const MagicMarkButton = styled__default.default.button`
1309
- display: inline-flex;
1310
- align-items: center;
1311
- justify-content: center;
1312
- width: 32px;
1313
- height: 32px;
1314
- border: 1px solid rgba(128, 128, 128, 0.25);
1315
- border-radius: 4px;
1316
- background: ${(p) => p.theme.colors.neutral0};
1317
- color: ${(p) => p.theme.colors.neutral800};
1318
- cursor: pointer;
1319
- transition: all 0.15s ease;
1320
- position: relative;
1321
-
1322
- &:hover {
1323
- background: ${(p) => p.theme.colors.neutral100};
1324
- border-color: rgba(128, 128, 128, 0.3);
1325
- }
1326
-
1327
- &:active {
1328
- transform: scale(0.98);
1329
- }
1330
-
1331
- svg {
1332
- width: 18px;
1333
- height: 18px;
1334
- flex-shrink: 0;
1335
- color: ${(p) => p.theme.colors.neutral600};
1336
- }
1337
- `;
1338
- const MagicMarkWrapper = styled__default.default.div`
1339
- position: relative;
1340
- `;
1341
- const Badge = styled__default.default.span`
1342
- position: absolute;
1343
- top: -6px;
1344
- right: -6px;
1345
- display: inline-flex;
1346
- align-items: center;
1347
- justify-content: center;
1348
- min-width: 18px;
1349
- height: 18px;
1350
- padding: 0 5px;
1351
- font-size: 10px;
1352
- font-weight: 700;
1353
- background: #4945FF;
1354
- color: #ffffff;
1355
- border-radius: 9px;
1356
- border: 2px solid #ffffff;
1357
- box-shadow: 0 1px 3px rgba(0,0,0,0.15);
1358
- `;
1359
- const ViewsWidget = () => {
1360
- const { formatMessage } = reactIntl.useIntl();
1361
- const navigate = reactRouterDom.useNavigate();
1362
- const { get } = admin.useFetchClient();
1363
- const viewsButtonRef = React.useRef(null);
1364
- const [showCreateModal, setShowCreateModal] = React__default.default.useState(false);
1365
- const [viewsPopoverVisible, setViewsPopoverVisible] = React__default.default.useState(false);
1366
- const [bookmarks, setBookmarks] = React__default.default.useState([]);
1367
- const [isLoadingViews, setIsLoadingViews] = React__default.default.useState(false);
1368
- const [currentPath, setCurrentPath] = React__default.default.useState("");
1369
- const [currentQuery, setCurrentQuery] = React__default.default.useState("");
1370
- const getBookmarks = async () => {
1371
- setIsLoadingViews(true);
1372
- const url = `/magic-mark/bookmarks`;
1373
- try {
1374
- const { data } = await get(url);
1375
- setBookmarks(data.data || []);
1376
- } catch (error) {
1377
- console.error("[Magic-Mark] Error fetching bookmarks:", error);
1378
- setBookmarks([]);
1379
- } finally {
1380
- setIsLoadingViews(false);
1381
- }
1382
- };
1383
- const handleOpenModal = () => {
1384
- let path = window.location.pathname;
1385
- if (path.startsWith("/admin/")) {
1386
- path = path.substring(6);
1387
- }
1388
- const query = window.location.search.substring(1);
1389
- setCurrentPath(path);
1390
- setCurrentQuery(query);
1391
- setShowCreateModal(true);
1392
- };
1393
- React__default.default.useEffect(() => {
1394
- getBookmarks();
1395
- }, [showCreateModal]);
1396
- const handleBookmarkClick = (bookmark) => {
1397
- if (bookmark.path && bookmark.query) {
1398
- navigate(`${bookmark.path}?${bookmark.query}`);
1399
- } else if (bookmark.path) {
1400
- navigate(bookmark.path);
1401
- }
1402
- setViewsPopoverVisible(false);
1403
- };
1404
- return /* @__PURE__ */ jsxRuntime.jsxs(WidgetContainer, { children: [
1405
- /* @__PURE__ */ jsxRuntime.jsxs(
1406
- ActionButton,
1407
- {
1408
- onClick: handleOpenModal,
1409
- title: formatMessage({
1410
- id: `${pluginId}.ViewsWidget.actions.create`,
1411
- defaultMessage: "Save current view as bookmark"
1412
- }),
1413
- children: [
1414
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
1415
- "Save"
1416
- ]
1417
- }
1418
- ),
1419
- /* @__PURE__ */ jsxRuntime.jsxs(MagicMarkWrapper, { children: [
1420
- /* @__PURE__ */ jsxRuntime.jsx(
1421
- MagicMarkButton,
1422
- {
1423
- ref: viewsButtonRef,
1424
- onClick: () => setViewsPopoverVisible((s) => !s),
1425
- title: "MagicMark Bookmarks",
1426
- children: /* @__PURE__ */ jsxRuntime.jsx(outline.BookmarkIcon, {})
1427
- }
1428
- ),
1429
- bookmarks.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(Badge, { children: bookmarks.length }),
1430
- viewsPopoverVisible && viewsButtonRef.current && /* @__PURE__ */ jsxRuntime.jsx(
1431
- ViewsListPopover,
1432
- {
1433
- views: bookmarks,
1434
- onViewClick: handleBookmarkClick,
1435
- isLoading: isLoadingViews,
1436
- buttonElement: viewsButtonRef.current
1437
- }
1438
- )
1439
- ] }),
1440
- showCreateModal && /* @__PURE__ */ jsxRuntime.jsx(
1441
- CreateEditModal,
1442
- {
1443
- bookmark: null,
1444
- pluginId,
1445
- onClose: () => setShowCreateModal(false),
1446
- onSuccess: () => {
1447
- setShowCreateModal(false);
1448
- getBookmarks();
1449
- },
1450
- currentPath,
1451
- currentQuery
1452
- }
1453
- )
1454
- ] });
1455
- };
1456
- const SelectContainer = styled__default.default.div`
1457
- position: relative;
1458
- width: 100%;
1459
- `;
1460
- const SelectButton = styled__default.default.button`
1461
- width: 100%;
1462
- padding: 10px 36px 10px 12px;
1463
- border: 1px solid ${(props) => props.$isOpen ? "#4945ff" : "rgba(128, 128, 128, 0.25)"};
1464
- border-radius: 4px;
1465
- background: ${(p) => p.theme.colors.neutral0};
1466
- font-size: 14px;
1467
- text-align: left;
1468
- cursor: pointer;
1469
- display: flex;
1470
- align-items: center;
1471
- justify-content: space-between;
1472
- transition: all 0.2s ease;
1473
-
1474
- &:hover {
1475
- border-color: #4945ff;
1476
- }
1477
-
1478
- &:focus {
1479
- outline: none;
1480
- border-color: #4945ff;
1481
- box-shadow: 0 0 0 2px rgba(73, 69, 255, 0.1);
1482
- }
1483
-
1484
- @media (max-width: 768px) {
1485
- padding: 8px 32px 8px 10px;
1486
- font-size: 13px;
1487
- }
1488
- `;
1489
- const SelectText = styled__default.default.span`
1490
- color: ${(props) => props.$isPlaceholder ? "#8e8ea9" : "#212134"};
1491
- overflow: hidden;
1492
- text-overflow: ellipsis;
1493
- white-space: nowrap;
1494
- `;
1495
- const IconWrapper = styled__default.default.span`
1496
- position: absolute;
1497
- right: 12px;
1498
- top: 50%;
1499
- transform: translateY(-50%) ${(props) => props.$isOpen ? "rotate(180deg)" : "rotate(0deg)"};
1500
- transition: transform 0.2s ease;
1501
- display: flex;
1502
- align-items: center;
1503
- pointer-events: none;
1504
- color: ${(p) => p.theme.colors.neutral500};
1505
- `;
1506
- const DropdownList = styled__default.default.div`
1507
- position: fixed;
1508
- top: ${(props) => props.top}px;
1509
- left: ${(props) => props.left}px;
1510
- width: ${(props) => props.width}px;
1511
- max-height: 300px;
1512
- overflow-y: auto;
1513
- background: ${(p) => p.theme.colors.neutral0};
1514
- border: 1px solid rgba(128, 128, 128, 0.25);
1515
- border-radius: 4px;
1516
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
1517
- z-index: 10000;
1518
- display: ${(props) => props.$isOpen ? "block" : "none"};
1519
-
1520
- @media (max-width: 768px) {
1521
- max-height: 250px;
1522
- }
1523
- `;
1524
- const DropdownItem = styled__default.default.button`
1525
- width: 100%;
1526
- padding: 10px 12px;
1527
- border: none;
1528
- background: ${(props) => props.$isSelected ? "#f0f0ff" : props.theme.colors.neutral0};
1529
- text-align: left;
1530
- cursor: pointer;
1531
- font-size: 14px;
1532
- color: ${(props) => props.$isSelected ? "#4945ff" : props.theme.colors.neutral800};
1533
- transition: background 0.15s ease;
1534
-
1535
- &:hover {
1536
- background: ${(p) => p.theme.colors.neutral100};
1537
- }
1538
-
1539
- &:focus {
1540
- outline: none;
1541
- background: rgba(73, 69, 255, 0.06);
1542
- }
1543
-
1544
- @media (max-width: 768px) {
1545
- padding: 12px;
1546
- font-size: 13px;
1547
- }
1548
- `;
1549
- const SearchInput = styled__default.default.input`
1550
- width: 100%;
1551
- padding: 10px 12px;
1552
- border: none;
1553
- border-bottom: 1px solid rgba(128, 128, 128, 0.25);
1554
- font-size: 14px;
1555
-
1556
- &:focus {
1557
- outline: none;
1558
- border-bottom-color: #4945ff;
1559
- }
1560
-
1561
- @media (max-width: 768px) {
1562
- padding: 12px;
1563
- font-size: 13px;
1564
- }
1565
- `;
1566
- const CustomSelect = ({
1567
- value,
1568
- onChange,
1569
- options,
1570
- placeholder = "Select...",
1571
- searchable = true
1572
- }) => {
1573
- const [isOpen, setIsOpen] = React.useState(false);
1574
- const [searchTerm, setSearchTerm] = React.useState("");
1575
- const [dropdownPos, setDropdownPos] = React.useState({ top: 0, left: 0, width: 0 });
1576
- const containerRef = React.useRef(null);
1577
- const buttonRef = React.useRef(null);
1578
- const searchInputRef = React.useRef(null);
1579
- const updatePosition = () => {
1580
- if (buttonRef.current) {
1581
- const rect = buttonRef.current.getBoundingClientRect();
1582
- setDropdownPos({
1583
- top: rect.bottom + 4,
1584
- left: rect.left,
1585
- width: rect.width
1586
- });
1587
- }
1588
- };
1589
- React.useEffect(() => {
1590
- if (isOpen) {
1591
- updatePosition();
1592
- window.addEventListener("scroll", updatePosition, true);
1593
- window.addEventListener("resize", updatePosition);
1594
- return () => {
1595
- window.removeEventListener("scroll", updatePosition, true);
1596
- window.removeEventListener("resize", updatePosition);
1597
- };
1598
- }
1599
- }, [isOpen]);
1600
- React.useEffect(() => {
1601
- const handleClickOutside = (event) => {
1602
- const target = event.target;
1603
- if (containerRef.current && !containerRef.current.contains(target) && !target.closest("[data-dropdown-portal]")) {
1604
- setIsOpen(false);
1605
- setSearchTerm("");
1606
- }
1607
- };
1608
- if (isOpen) {
1609
- document.addEventListener("mousedown", handleClickOutside);
1610
- return () => document.removeEventListener("mousedown", handleClickOutside);
1611
- }
1612
- }, [isOpen]);
1613
- React.useEffect(() => {
1614
- if (isOpen && searchable && searchInputRef.current) {
1615
- searchInputRef.current.focus();
1616
- }
1617
- }, [isOpen, searchable]);
1618
- const filteredOptions = searchable && searchTerm ? options.filter(
1619
- (opt) => opt.label.toLowerCase().includes(searchTerm.toLowerCase())
1620
- ) : options;
1621
- const selectedOption = options.find((opt) => opt.value === value);
1622
- const handleSelect = (optionValue) => {
1623
- console.log("[CustomSelect] Selected:", optionValue);
1624
- onChange(optionValue);
1625
- setIsOpen(false);
1626
- setSearchTerm("");
1627
- };
1628
- const dropdownContent = /* @__PURE__ */ jsxRuntime.jsxs(
1629
- DropdownList,
1630
- {
1631
- $isOpen: isOpen,
1632
- top: dropdownPos.top,
1633
- left: dropdownPos.left,
1634
- width: dropdownPos.width,
1635
- "data-dropdown-portal": "true",
1636
- children: [
1637
- searchable && /* @__PURE__ */ jsxRuntime.jsx(
1638
- SearchInput,
1639
- {
1640
- ref: searchInputRef,
1641
- type: "text",
1642
- placeholder: "Search...",
1643
- value: searchTerm,
1644
- onChange: (e) => setSearchTerm(e.target.value),
1645
- onClick: (e) => e.stopPropagation()
1646
- }
1647
- ),
1648
- filteredOptions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "No options found" }) }) : filteredOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
1649
- DropdownItem,
1650
- {
1651
- type: "button",
1652
- $isSelected: option.value === value,
1653
- onClick: () => handleSelect(option.value),
1654
- children: option.label
1655
- },
1656
- option.value
1657
- ))
1658
- ]
1659
- }
1660
- );
1661
- return /* @__PURE__ */ jsxRuntime.jsxs(SelectContainer, { ref: containerRef, children: [
1662
- /* @__PURE__ */ jsxRuntime.jsxs(
1663
- SelectButton,
1664
- {
1665
- ref: buttonRef,
1666
- type: "button",
1667
- onClick: () => setIsOpen(!isOpen),
1668
- $isOpen: isOpen,
1669
- children: [
1670
- /* @__PURE__ */ jsxRuntime.jsx(SelectText, { $isPlaceholder: !value, children: selectedOption?.label || placeholder }),
1671
- /* @__PURE__ */ jsxRuntime.jsx(IconWrapper, { $isOpen: isOpen, children: "▼" })
1672
- ]
1673
- }
1674
- ),
1675
- isOpen && ReactDOM__default.default.createPortal(dropdownContent, document.body)
1676
- ] });
1677
- };
1678
- const useRelationSchema = () => {
1679
- const { get } = admin.useFetchClient();
1680
- const [loading, setLoading] = React.useState({});
1681
- const [errors, setErrors] = React.useState({});
1682
- const cacheRef = React.useRef({});
1683
- const CACHE_TTL = 5 * 60 * 1e3;
1684
- const fetchSchema = React.useCallback(async (uid) => {
1685
- const cached = cacheRef.current[uid];
1686
- if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
1687
- console.log("[RelationSchema] Using cached schema for:", uid);
1688
- return cached.attributes;
1689
- }
1690
- setLoading((prev) => ({ ...prev, [uid]: true }));
1691
- setErrors((prev) => ({ ...prev, [uid]: "" }));
1692
- try {
1693
- console.log("[RelationSchema] Fetching schema for:", uid);
1694
- const response = await get(`/content-type-builder/content-types/${uid}`);
1695
- const schemaInfo = response.data?.data?.schema || response.data?.schema || {};
1696
- const attributes = schemaInfo.attributes || {};
1697
- cacheRef.current[uid] = {
1698
- attributes,
1699
- timestamp: Date.now()
1700
- };
1701
- console.log("[RelationSchema] Fetched attributes for", uid, ":", Object.keys(attributes));
1702
- setLoading((prev) => ({ ...prev, [uid]: false }));
1703
- return attributes;
1704
- } catch (error) {
1705
- console.error("[RelationSchema] Error fetching schema for", uid, ":", error);
1706
- const errorMessage = error.message || "Failed to fetch schema";
1707
- setErrors((prev) => ({ ...prev, [uid]: errorMessage }));
1708
- setLoading((prev) => ({ ...prev, [uid]: false }));
1709
- return null;
1710
- }
1711
- }, [get]);
1712
- const getFilterableFields = React.useCallback(async (uid) => {
1713
- const attributes = await fetchSchema(uid);
1714
- if (!attributes) return [];
1715
- const fields = [];
1716
- const skipFields = ["createdBy", "updatedBy", "localizations", "locale"];
1717
- Object.entries(attributes).forEach(([name2, attr]) => {
1718
- if (skipFields.includes(name2)) return;
1719
- if (["media", "component", "dynamiczone"].includes(attr.type)) return;
1720
- const isRelation = attr.type === "relation";
1721
- fields.push({
1722
- name: name2,
1723
- type: attr.type,
1724
- isRelation,
1725
- target: isRelation ? attr.target : void 0
1726
- });
1727
- });
1728
- const defaultFields = [
1729
- { name: "id", type: "integer", isRelation: false },
1730
- { name: "documentId", type: "string", isRelation: false },
1731
- { name: "createdAt", type: "datetime", isRelation: false },
1732
- { name: "updatedAt", type: "datetime", isRelation: false }
1733
- ];
1734
- const existingNames = new Set(fields.map((f) => f.name));
1735
- defaultFields.forEach((df) => {
1736
- if (!existingNames.has(df.name)) {
1737
- fields.unshift(df);
1738
- }
1739
- });
1740
- return fields;
1741
- }, [fetchSchema]);
1742
- const getRelationFields = React.useCallback(async (relationTarget) => {
1743
- return getFilterableFields(relationTarget);
1744
- }, [getFilterableFields]);
1745
- const clearCache = React.useCallback(() => {
1746
- cacheRef.current = {};
1747
- console.log("[RelationSchema] Cache cleared");
1748
- }, []);
1749
- const getCachedSchema = React.useCallback((uid) => {
1750
- const cached = cacheRef.current[uid];
1751
- if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
1752
- return cached.attributes;
1753
- }
1754
- return null;
1755
- }, []);
1756
- return {
1757
- fetchSchema,
1758
- getFilterableFields,
1759
- getRelationFields,
1760
- clearCache,
1761
- getCachedSchema,
1762
- loading,
1763
- errors
1764
- };
1765
- };
1766
- const buildFilterFromPath = (fieldPath, operator, value) => {
1767
- const parts = fieldPath.split(".").filter(Boolean);
1768
- if (parts.length === 0) return {};
1769
- const opKey = operator.startsWith("$") ? operator : `$${operator}`;
1770
- const filterValue = ["null", "notNull"].includes(operator) ? true : value;
1771
- if (parts.length === 1) {
1772
- return { [parts[0]]: { [opKey]: filterValue } };
1773
- }
1774
- const [first, ...rest] = parts;
1775
- return {
1776
- [first]: buildFilterFromPath(rest.join("."), operator, value)
1777
- };
1778
- };
1779
- const extractRelationFromField = (field) => {
1780
- if (!field || !field.includes(".")) return null;
1781
- return field.split(".")[0];
1782
- };
1783
- const rowsToFilterStructure = (rows, connectors) => {
1784
- const validRows = rows.filter((r) => {
1785
- if (!r.field) return false;
1786
- const needsValue = !["null", "notNull"].includes(r.operator);
1787
- return !needsValue || r.value && r.value.trim() !== "";
1788
- });
1789
- if (validRows.length === 0) return void 0;
1790
- if (validRows.length === 1) {
1791
- return buildFilterFromPath(validRows[0].field, validRows[0].operator, validRows[0].value);
1792
- }
1793
- const groups = [];
1794
- let currentAndGroup = [];
1795
- validRows.forEach((row, i) => {
1796
- const filter = buildFilterFromPath(row.field, row.operator, row.value);
1797
- currentAndGroup.push(filter);
1798
- const nextConnector = connectors[i];
1799
- if (nextConnector?.logic === "OR" || !nextConnector) {
1800
- if (currentAndGroup.length === 1) {
1801
- groups.push(currentAndGroup[0]);
1802
- } else {
1803
- groups.push({ $and: currentAndGroup });
1804
- }
1805
- currentAndGroup = [];
1806
- }
1807
- });
1808
- if (currentAndGroup.length > 0) {
1809
- if (currentAndGroup.length === 1) {
1810
- groups.push(currentAndGroup[0]);
1811
- } else {
1812
- groups.push({ $and: currentAndGroup });
1813
- }
1814
- }
1815
- if (groups.length === 1) return groups[0];
1816
- return { $or: groups };
1817
- };
1818
- const generateFromRows = (rows, connectors) => {
1819
- const queryObject = {};
1820
- const filterStructure = rowsToFilterStructure(rows, connectors);
1821
- if (filterStructure) {
1822
- queryObject.filters = filterStructure;
1823
- }
1824
- const relations = /* @__PURE__ */ new Set();
1825
- rows.forEach((r) => {
1826
- const rel = extractRelationFromField(r.field);
1827
- if (rel) relations.add(rel);
1828
- });
1829
- if (relations.size > 0) {
1830
- const populate = {};
1831
- relations.forEach((rel) => {
1832
- populate[rel] = true;
1833
- });
1834
- queryObject.populate = populate;
1835
- }
1836
- return qs__default.default.stringify(queryObject, { encodeValuesOnly: true });
1837
- };
1838
- const extractFieldPathAndOperator = (parts) => {
1839
- let operatorIndex = -1;
1840
- for (let i = parts.length - 1; i >= 0; i--) {
1841
- if (parts[i].startsWith("$")) {
1842
- operatorIndex = i;
1843
- break;
1844
- }
1845
- }
1846
- if (operatorIndex === -1) return null;
1847
- const operator = parts[operatorIndex].substring(1);
1848
- const fieldPath = parts.slice(0, operatorIndex);
1849
- if (fieldPath.length === 0) return null;
1850
- return { fieldPath, operator };
1851
- };
1852
- const parseQueryToStructure = (queryString) => {
1853
- const params = new URLSearchParams(queryString);
1854
- const filterTree = {};
1855
- params.forEach((value, key) => {
1856
- if (key.startsWith("filters[")) {
1857
- const parts = key.match(/\[([^\]]+)\]/g)?.map((p) => p.slice(1, -1)) || [];
1858
- console.log("[QueryParser] Parsing key:", key, "parts:", parts);
1859
- if (parts.length < 2) return;
1860
- if (parts[0].startsWith("$")) {
1861
- const logic = parts[0].substring(1);
1862
- const index2 = parseInt(parts[1]);
1863
- if (isNaN(index2)) return;
1864
- if (parts[2].startsWith("$")) {
1865
- const nestedLogic = parts[2].substring(1);
1866
- const nestedIndex = parseInt(parts[3]);
1867
- if (isNaN(nestedIndex)) return;
1868
- const remainingParts = parts.slice(4);
1869
- const extracted = extractFieldPathAndOperator(remainingParts);
1870
- if (!extracted) return;
1871
- if (!filterTree[logic]) filterTree[logic] = {};
1872
- if (!filterTree[logic][index2]) filterTree[logic][index2] = { nested: nestedLogic, items: {} };
1873
- filterTree[logic][index2].items[nestedIndex] = {
1874
- fieldPath: extracted.fieldPath,
1875
- field: extracted.fieldPath[extracted.fieldPath.length - 1],
1876
- // Last element for backward compat
1877
- operator: extracted.operator,
1878
- value
1879
- };
1880
- } else {
1881
- const remainingParts = parts.slice(2);
1882
- const extracted = extractFieldPathAndOperator(remainingParts);
1883
- if (!extracted) return;
1884
- if (!filterTree[logic]) filterTree[logic] = {};
1885
- filterTree[logic][index2] = {
1886
- fieldPath: extracted.fieldPath,
1887
- field: extracted.fieldPath[extracted.fieldPath.length - 1],
1888
- // Last element for backward compat
1889
- operator: extracted.operator,
1890
- value
1891
- };
1892
- }
1893
- } else {
1894
- console.log("[QueryParser] Parsing simple filter without logic operator");
1895
- const extracted = extractFieldPathAndOperator(parts);
1896
- if (!extracted) return;
1897
- if (!filterTree["and"]) filterTree["and"] = {};
1898
- filterTree["and"][0] = {
1899
- fieldPath: extracted.fieldPath,
1900
- field: extracted.fieldPath[extracted.fieldPath.length - 1],
1901
- operator: extracted.operator,
1902
- value
1903
- };
1904
- }
1905
- }
1906
- });
1907
- console.log("[QueryParser] Filter tree:", filterTree);
1908
- const rootLogic = Object.keys(filterTree)[0] || "and";
1909
- const rootGroup = {
1910
- id: "root",
1911
- logic: rootLogic.toUpperCase(),
1912
- conditions: []
1913
- };
1914
- let conditionId = 1;
1915
- const rootItems = filterTree[rootLogic] || {};
1916
- Object.keys(rootItems).sort((a, b) => parseInt(a) - parseInt(b)).forEach((index2) => {
1917
- const item = rootItems[index2];
1918
- if (item.nested) {
1919
- const subGroup = {
1920
- id: `group_${conditionId++}`,
1921
- logic: item.nested.toUpperCase(),
1922
- conditions: [],
1923
- isGroup: true
1924
- };
1925
- Object.keys(item.items).sort((a, b) => parseInt(a) - parseInt(b)).forEach((subIndex) => {
1926
- const subItem = item.items[subIndex];
1927
- subGroup.conditions.push({
1928
- id: `condition_${conditionId++}`,
1929
- field: subItem.field,
1930
- fieldPath: subItem.fieldPath,
1931
- operator: subItem.operator,
1932
- value: decodeURIComponent(subItem.value)
1933
- });
1934
- });
1935
- rootGroup.conditions.push(subGroup);
1936
- } else {
1937
- rootGroup.conditions.push({
1938
- id: `condition_${conditionId++}`,
1939
- field: item.field,
1940
- fieldPath: item.fieldPath,
1941
- operator: item.operator,
1942
- value: decodeURIComponent(item.value)
1943
- });
1944
- }
1945
- });
1946
- if (rootGroup.conditions.length === 0) {
1947
- rootGroup.conditions.push({
1948
- id: "condition_1",
1949
- field: "",
1950
- fieldPath: [],
1951
- operator: "eq",
1952
- value: ""
1953
- });
1954
- }
1955
- console.log("[QueryParser] Built structure:", rootGroup);
1956
- return rootGroup;
1957
- };
1958
- const flattenGroup = (group) => {
1959
- const result = [];
1960
- const logic = group.logic;
1961
- group.conditions.forEach((item, i) => {
1962
- const connectorBefore = i === 0 ? null : logic;
1963
- if ("isGroup" in item && item.isGroup) {
1964
- const sub = flattenGroup(item);
1965
- sub.forEach((s, j) => {
1966
- result.push({
1967
- condition: s.condition,
1968
- connectorBefore: j === 0 ? connectorBefore : s.connectorBefore
1969
- });
1970
- });
1971
- } else {
1972
- result.push({ condition: item, connectorBefore });
1973
- }
1974
- });
1975
- return result;
1976
- };
1977
- const parseQueryToRows = (queryString) => {
1978
- const structure = parseQueryToStructure(queryString);
1979
- const flattened = flattenGroup(structure);
1980
- const rows = [];
1981
- const connectors = [];
1982
- flattened.forEach((item, i) => {
1983
- const cond = item.condition;
1984
- const field = cond.fieldPath && cond.fieldPath.length > 0 ? cond.fieldPath.join(".") : cond.field || "";
1985
- const needsValue = !["null", "notNull"].includes(cond.operator);
1986
- if (!field && needsValue) return;
1987
- rows.push({
1988
- id: cond.id || `row_${i + 1}`,
1989
- field,
1990
- operator: cond.operator,
1991
- value: cond.value || ""
1992
- });
1993
- if (item.connectorBefore && i > 0) {
1994
- connectors.push({ logic: item.connectorBefore });
1995
- }
1996
- });
1997
- for (let i = connectors.length; i < Math.max(0, rows.length - 1); i++) {
1998
- connectors.push({ logic: "AND" });
1999
- }
2000
- return { rows, connectors };
2001
- };
2002
- const ModalOverlay = styled__default.default.div`
2003
- position: fixed;
2004
- top: 0;
2005
- left: 0;
2006
- right: 0;
2007
- bottom: 0;
2008
- background-color: rgba(0, 0, 0, 0.5);
2009
- display: flex;
2010
- align-items: center;
2011
- justify-content: center;
2012
- z-index: 999;
2013
- padding: 20px;
2014
- @media (max-width: 768px) {
2015
- padding: 10px;
2016
- }
2017
- `;
2018
- const ModalContent = styled__default.default(designSystem.Box)`
2019
- background: ${(p) => p.theme.colors.neutral0};
2020
- border-radius: 8px;
2021
- max-height: 90vh;
2022
- overflow-y: auto;
2023
- max-width: 560px;
2024
- width: 100%;
2025
- box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
2026
- @media (max-width: 768px) {
2027
- max-width: 100%;
2028
- max-height: 95vh;
2029
- }
2030
- `;
2031
- const RowWrapper = styled__default.default.div`
2032
- display: flex;
2033
- flex-direction: column;
2034
- gap: 8px;
2035
- margin-bottom: 8px;
2036
- `;
2037
- const FilterRowContainer = styled__default.default.div`
2038
- display: flex;
2039
- align-items: center;
2040
- gap: 8px;
2041
- flex-wrap: wrap;
2042
- `;
2043
- const ValueInput = styled__default.default.input`
2044
- flex: 1;
2045
- min-width: 120px;
2046
- padding: 8px 12px;
2047
- border: 1px solid rgba(128, 128, 128, 0.25);
2048
- border-radius: 4px;
2049
- font-size: 14px;
2050
- &:focus {
2051
- outline: none;
2052
- border-color: #4945ff;
2053
- box-shadow: 0 0 0 2px rgba(73, 69, 255, 0.1);
2054
- }
2055
- `;
2056
- const ConnectorRow = styled__default.default.div`
2057
- display: flex;
2058
- align-items: center;
2059
- justify-content: center;
2060
- padding: 4px 0;
2061
- `;
2062
- const ConnectorButton = styled__default.default.button`
2063
- padding: 4px 12px;
2064
- font-size: 12px;
2065
- font-weight: 500;
2066
- border: 1px solid ${(props) => props.$active ? "#4945ff" : "rgba(128, 128, 128, 0.25)"};
2067
- border-radius: 4px;
2068
- background: ${(props) => props.$active ? "#EEF0FF" : "transparent"};
2069
- color: ${(props) => props.$active ? "#4945ff" : "#32324d"};
2070
- cursor: pointer;
2071
- transition: all 0.15s ease;
2072
- &:hover {
2073
- border-color: #4945ff;
2074
- background: ${(p) => p.theme.colors.neutral100};
2075
- }
2076
- `;
2077
- const DeleteButton = styled__default.default.button`
2078
- display: flex;
2079
- align-items: center;
2080
- justify-content: center;
2081
- width: 32px;
2082
- height: 32px;
2083
- border: none;
2084
- background: rgba(239, 68, 68, 0.06);
2085
- color: #dc2626;
2086
- border-radius: 4px;
2087
- cursor: pointer;
2088
- flex-shrink: 0;
2089
- &:hover {
2090
- background: rgba(239, 68, 68, 0.12);
2091
- }
2092
- svg {
2093
- width: 14px;
2094
- height: 14px;
2095
- }
2096
- `;
2097
- const AddButton = styled__default.default.button`
2098
- display: flex;
2099
- align-items: center;
2100
- gap: 6px;
2101
- padding: 8px 14px;
2102
- font-size: 13px;
2103
- font-weight: 500;
2104
- border: 1px dashed rgba(128, 128, 128, 0.25);
2105
- border-radius: 4px;
2106
- background: ${(p) => p.theme.colors.neutral100};
2107
- color: #4945ff;
2108
- cursor: pointer;
2109
- transition: all 0.15s ease;
2110
- &:hover {
2111
- border-color: #4945ff;
2112
- background: rgba(73, 69, 255, 0.06);
2113
- }
2114
- `;
2115
- const InfoText = styled__default.default.div`
2116
- font-size: 12px;
2117
- color: ${(p) => p.theme.colors.neutral600};
2118
- margin-top: 8px;
2119
- font-style: italic;
2120
- `;
2121
- const OPERATORS = [
2122
- { value: "eq", label: "is" },
2123
- { value: "ne", label: "is not" },
2124
- { value: "contains", label: "contains" },
2125
- { value: "notContains", label: "not contains" },
2126
- { value: "startsWith", label: "starts with" },
2127
- { value: "endsWith", label: "ends with" },
2128
- { value: "gt", label: "is greater than" },
2129
- { value: "lt", label: "is less than" },
2130
- { value: "null", label: "is null" },
2131
- { value: "notNull", label: "is not null" }
2132
- ];
2133
- const StrapiStyleFilterModal = ({
2134
- onClose,
2135
- onApply,
2136
- availableFields,
2137
- availableRelations = [],
2138
- currentQuery = ""
2139
- }) => {
2140
- const { getRelationFields } = useRelationSchema();
2141
- const [fieldOptions, setFieldOptions] = React.useState([]);
2142
- const [rows, setRows] = React.useState([]);
2143
- const [connectors, setConnectors] = React.useState([]);
2144
- const buildFieldOptions = React.useCallback(async () => {
2145
- const direct = availableFields.map((f) => ({
2146
- value: f.name,
2147
- label: f.name,
2148
- group: "Fields"
2149
- }));
2150
- const relationOptions = [];
2151
- for (const rel of availableRelations) {
2152
- if (!rel.target) continue;
2153
- try {
2154
- const nestedFields = await getRelationFields(rel.target);
2155
- if (nestedFields) {
2156
- nestedFields.filter((f) => !f.isRelation).forEach((f) => {
2157
- relationOptions.push({
2158
- value: `${rel.name}.${f.name}`,
2159
- label: `${rel.name} > ${f.name}`,
2160
- group: "Relations"
2161
- });
2162
- });
2163
- }
2164
- } catch (e) {
2165
- console.warn("[StrapiStyleFilter] Failed to load relation fields:", rel.name, e);
2166
- }
2167
- }
2168
- setFieldOptions([...direct, ...relationOptions]);
2169
- }, [availableFields, availableRelations, getRelationFields]);
2170
- React.useEffect(() => {
2171
- buildFieldOptions();
2172
- }, [buildFieldOptions]);
2173
- React.useEffect(() => {
2174
- if (currentQuery) {
2175
- const { rows: parsedRows, connectors: parsedConnectors } = parseQueryToRows(currentQuery);
2176
- if (parsedRows.length > 0) {
2177
- setRows(parsedRows);
2178
- setConnectors(parsedConnectors);
2179
- return;
2180
- }
2181
- }
2182
- setRows([{
2183
- id: `row_${Date.now()}`,
2184
- field: "",
2185
- operator: "eq",
2186
- value: ""
2187
- }]);
2188
- setConnectors([]);
2189
- }, [currentQuery]);
2190
- const relationsInUse = new Set(
2191
- rows.map((r) => r.field.includes(".") ? r.field.split(".")[0] : null).filter(Boolean)
2192
- );
2193
- const updateRow = (index2, updates) => {
2194
- setRows((prev) => prev.map((r, i) => i === index2 ? { ...r, ...updates } : r));
2195
- };
2196
- const updateConnector = (index2, logic) => {
2197
- setConnectors((prev) => {
2198
- const next = [...prev];
2199
- next[index2] = { logic };
2200
- return next;
2201
- });
2202
- };
2203
- const addRow = () => {
2204
- const newRow = {
2205
- id: `row_${Date.now()}`,
2206
- field: "",
2207
- operator: "eq",
2208
- value: ""
2209
- };
2210
- setRows((prev) => [...prev, newRow]);
2211
- setConnectors((prev) => [...prev, { logic: "AND" }]);
2212
- };
2213
- const removeRow = (index2) => {
2214
- setRows((prev) => prev.filter((_, i) => i !== index2));
2215
- setConnectors((prev) => {
2216
- const connectorIndex = index2 > 0 ? index2 - 1 : 0;
2217
- return prev.filter((_, i) => i !== connectorIndex);
2218
- });
2219
- };
2220
- const handleApply = () => {
2221
- const validRows = rows.filter((r) => r.field && (["null", "notNull"].includes(r.operator) || r.value.trim()));
2222
- if (validRows.length === 0) {
2223
- onApply("");
2224
- onClose();
2225
- return;
2226
- }
2227
- const queryString = generateFromRows(validRows, connectors.slice(0, validRows.length - 1));
2228
- onApply(queryString);
2229
- onClose();
2230
- };
2231
- const handleClearAll = () => {
2232
- setRows([{
2233
- id: `row_${Date.now()}`,
2234
- field: "",
2235
- operator: "eq",
2236
- value: ""
2237
- }]);
2238
- setConnectors([]);
2239
- };
2240
- const operatorOptions = OPERATORS.map((o) => ({ value: o.value, label: o.label }));
2241
- return /* @__PURE__ */ jsxRuntime.jsx(ModalOverlay, { onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { padding: 6, onClick: (e) => e.stopPropagation(), children: [
2242
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
2243
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { as: "h2", variant: "beta", children: "Filters" }),
2244
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: onClose, variant: "ghost", type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}) })
2245
- ] }),
2246
- /* @__PURE__ */ jsxRuntime.jsx(RowWrapper, { children: rows.map((row, i) => /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
2247
- i > 0 && /* @__PURE__ */ jsxRuntime.jsxs(ConnectorRow, { children: [
2248
- /* @__PURE__ */ jsxRuntime.jsx(
2249
- ConnectorButton,
2250
- {
2251
- type: "button",
2252
- $active: connectors[i - 1]?.logic === "AND",
2253
- onClick: () => updateConnector(i - 1, "AND"),
2254
- children: "and"
2255
- }
2256
- ),
2257
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { margin: "0 8px", color: "var(--colors-neutral500, #8e8ea9)" }, children: "|" }),
2258
- /* @__PURE__ */ jsxRuntime.jsx(
2259
- ConnectorButton,
2260
- {
2261
- type: "button",
2262
- $active: connectors[i - 1]?.logic === "OR",
2263
- onClick: () => updateConnector(i - 1, "OR"),
2264
- children: "or"
2265
- }
2266
- )
2267
- ] }),
2268
- /* @__PURE__ */ jsxRuntime.jsxs(FilterRowContainer, { children: [
2269
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: "1 1 140px", minWidth: "120px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2270
- CustomSelect,
2271
- {
2272
- value: row.field,
2273
- onChange: (v) => updateRow(i, { field: v }),
2274
- options: [
2275
- { value: "", label: "Select field..." },
2276
- ...fieldOptions
2277
- ],
2278
- placeholder: "Select field",
2279
- searchable: true
2280
- }
2281
- ) }),
2282
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: "1 1 130px", minWidth: "100px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2283
- CustomSelect,
2284
- {
2285
- value: row.operator,
2286
- onChange: (v) => updateRow(i, { operator: v }),
2287
- options: [
2288
- { value: "eq", label: "is" },
2289
- ...operatorOptions.filter((o) => o.value !== "eq")
2290
- ],
2291
- placeholder: "Operator",
2292
- searchable: false
2293
- }
2294
- ) }),
2295
- !["null", "notNull"].includes(row.operator) && /* @__PURE__ */ jsxRuntime.jsx(
2296
- ValueInput,
2297
- {
2298
- type: "text",
2299
- value: row.value,
2300
- onChange: (e) => updateRow(i, { value: e.target.value }),
2301
- placeholder: "Value"
2302
- }
2303
- ),
2304
- /* @__PURE__ */ jsxRuntime.jsx(
2305
- DeleteButton,
2306
- {
2307
- type: "button",
2308
- onClick: () => removeRow(i),
2309
- title: "Remove filter",
2310
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {})
2311
- }
2312
- )
2313
- ] })
2314
- ] }, row.id)) }),
2315
- /* @__PURE__ */ jsxRuntime.jsx(AddButton, { type: "button", onClick: addRow, children: "+ Add filter" }),
2316
- relationsInUse.size > 0 && /* @__PURE__ */ jsxRuntime.jsxs(InfoText, { children: [
2317
- Array.from(relationsInUse).join(", "),
2318
- " will be loaded automatically"
2319
- ] }),
2320
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", marginTop: 5, gap: 2, children: [
2321
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleClearAll, variant: "tertiary", children: "Clear All" }),
2322
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleApply, variant: "default", children: "Apply Filters" })
2323
- ] })
2324
- ] }) });
2325
- };
2326
- const FilterButtonGroup = styled__default.default.div`
2327
- display: flex;
2328
- align-items: center;
2329
- gap: 6px;
2330
- `;
2331
- const FilterButton = styled__default.default.button`
2332
- display: inline-flex;
2333
- align-items: center;
2334
- justify-content: center;
2335
- gap: 6px;
2336
- height: 36px;
2337
- padding: 0 14px;
2338
- font-size: 13px;
2339
- font-weight: 500;
2340
- border: 1px solid ${(props) => props.$isActive ? "#4945FF" : "rgba(128, 128, 128, 0.25)"};
2341
- border-radius: 4px;
2342
- background: ${(props) => props.$isActive ? "rgba(73, 69, 255, 0.08)" : props.theme.colors.neutral0};
2343
- color: ${(props) => props.$isActive ? "#4945FF" : props.theme.colors.neutral800};
2344
- cursor: pointer;
2345
- transition: all 0.15s ease;
2346
- white-space: nowrap;
2347
-
2348
- &:hover {
2349
- background: ${(props) => props.$isActive ? "rgba(73, 69, 255, 0.12)" : props.theme.colors.neutral100};
2350
- border-color: ${(props) => props.$isActive ? "#4945FF" : "rgba(128, 128, 128, 0.3)"};
2351
- }
2352
-
2353
- &:active {
2354
- transform: scale(0.98);
2355
- }
2356
-
2357
- svg {
2358
- width: 16px;
2359
- height: 16px;
2360
- flex-shrink: 0;
2361
- }
2362
- `;
2363
- const ClearButton = styled__default.default.button`
2364
- display: inline-flex;
2365
- align-items: center;
2366
- justify-content: center;
2367
- width: 36px;
2368
- height: 36px;
2369
- padding: 0;
2370
- border: 1px solid rgba(239, 68, 68, 0.3);
2371
- border-radius: 4px;
2372
- background: rgba(239, 68, 68, 0.06);
2373
- color: #dc2626;
2374
- cursor: pointer;
2375
- transition: all 0.15s ease;
2376
-
2377
- &:hover {
2378
- background: rgba(239, 68, 68, 0.12);
2379
- border-color: rgba(239, 68, 68, 0.4);
2380
- }
2381
-
2382
- &:active {
2383
- transform: scale(0.98);
2384
- }
2385
-
2386
- svg {
2387
- width: 16px;
2388
- height: 16px;
2389
- }
2390
- `;
2391
- const ActiveDot = styled__default.default.span`
2392
- width: 6px;
2393
- height: 6px;
2394
- background: #22c55e;
2395
- border-radius: 50%;
2396
- margin-left: 2px;
2397
- `;
2398
- const AdvancedFilterButton = () => {
2399
- const [showModal, setShowModal] = React.useState(false);
2400
- const navigate = reactRouterDom.useNavigate();
2401
- const location = reactRouterDom.useLocation();
2402
- const { get } = admin.useFetchClient();
2403
- const [availableFields, setAvailableFields] = React.useState([]);
2404
- const [availableRelations, setAvailableRelations] = React.useState([]);
2405
- const [hasActiveFilters, setHasActiveFilters] = React.useState(false);
2406
- React.useEffect(() => {
2407
- const params = new URLSearchParams(location.search);
2408
- let hasFilters = false;
2409
- params.forEach((value, key) => {
2410
- if (key.startsWith("filters[")) {
2411
- hasFilters = true;
2412
- }
2413
- });
2414
- setHasActiveFilters(hasFilters);
2415
- }, [location.search]);
2416
- const extractContentTypeUid = () => {
2417
- const match = location.pathname.match(/collection-types\/([^/?]+)/);
2418
- return match ? match[1] : null;
2419
- };
2420
- React.useEffect(() => {
2421
- const fetchSchema = async () => {
2422
- const uid = extractContentTypeUid();
2423
- if (!uid) {
2424
- console.log("[AdvancedFilter] No content type UID found in URL");
2425
- return;
2426
- }
2427
- try {
2428
- console.log("[AdvancedFilter] Fetching schema for:", uid);
2429
- let realAttributes = {};
2430
- try {
2431
- const schemaResponse = await get(`/content-type-builder/content-types/${uid}`);
2432
- const schemaInfo = schemaResponse.data?.data?.schema || schemaResponse.data?.schema || {};
2433
- realAttributes = schemaInfo.attributes || {};
2434
- console.log("[AdvancedFilter] Real schema attributes:", realAttributes);
2435
- } catch (e) {
2436
- console.log("[AdvancedFilter] Content-type-builder endpoint failed:", e);
2437
- }
2438
- let metadatas = {};
2439
- try {
2440
- const configResponse = await get(`/content-manager/content-types/${uid}/configuration`);
2441
- const contentTypeData = configResponse.data?.data?.contentType || configResponse.data?.contentType || {};
2442
- metadatas = contentTypeData.metadatas || {};
2443
- console.log("[AdvancedFilter] Configuration metadatas:", metadatas);
2444
- } catch (e) {
2445
- console.log("[AdvancedFilter] Configuration endpoint failed:", e);
2446
- }
2447
- const fields = [];
2448
- const relations = [];
2449
- const fieldNames = /* @__PURE__ */ new Set();
2450
- Object.keys(realAttributes).forEach((key) => {
2451
- const attr = realAttributes[key];
2452
- const attrType = attr.type;
2453
- if (["createdBy", "updatedBy", "localizations", "locale"].includes(key)) {
2454
- return;
2455
- }
2456
- if (attrType === "relation") {
2457
- relations.push({ name: key, target: attr.target });
2458
- console.log("[AdvancedFilter] Found relation:", key, "-> target:", attr.target);
2459
- } else if (attrType === "component" || attrType === "dynamiczone") {
2460
- console.log("[AdvancedFilter] Skipping component/dynamiczone:", key);
2461
- } else if (attrType === "media") {
2462
- console.log("[AdvancedFilter] Skipping media:", key);
2463
- } else if (!fieldNames.has(key)) {
2464
- fieldNames.add(key);
2465
- fields.push({
2466
- name: key,
2467
- type: attrType || "string"
2468
- });
2469
- }
2470
- });
2471
- ["id", "documentId", "createdAt", "updatedAt"].forEach((defaultField) => {
2472
- if (!fieldNames.has(defaultField)) {
2473
- let type = "string";
2474
- if (defaultField === "id") type = "integer";
2475
- if (defaultField === "createdAt" || defaultField === "updatedAt") type = "datetime";
2476
- fields.unshift({ name: defaultField, type });
2477
- }
2478
- });
2479
- setAvailableFields(fields);
2480
- setAvailableRelations(relations);
2481
- console.log("[AdvancedFilter] Final fields:", fields);
2482
- console.log("[AdvancedFilter] Final relations:", relations);
2483
- } catch (error) {
2484
- console.error("[AdvancedFilter] Error fetching schema:", error);
2485
- setAvailableFields([
2486
- { name: "id", type: "integer" },
2487
- { name: "documentId", type: "string" },
2488
- { name: "createdAt", type: "datetime" },
2489
- { name: "updatedAt", type: "datetime" }
2490
- ]);
2491
- }
2492
- };
2493
- fetchSchema();
2494
- }, [location.pathname]);
2495
- const handleApplyFilters = (queryString) => {
2496
- console.log("[AdvancedFilter] Applying filters:", queryString);
2497
- const currentPath = location.pathname;
2498
- const currentParams = new URLSearchParams(location.search);
2499
- const newParams = new URLSearchParams(queryString);
2500
- const cleanParams = new URLSearchParams();
2501
- currentParams.forEach((value, key) => {
2502
- if (!key.startsWith("filters[") && !key.startsWith("populate[")) {
2503
- cleanParams.set(key, value);
2504
- }
2505
- });
2506
- newParams.forEach((value, key) => {
2507
- cleanParams.set(key, value);
2508
- });
2509
- cleanParams.set("page", "1");
2510
- const finalUrl = `${currentPath}?${cleanParams.toString()}`;
2511
- console.log("[AdvancedFilter] Final URL:", finalUrl);
2512
- navigate(finalUrl);
2513
- setTimeout(() => {
2514
- window.location.reload();
2515
- }, 100);
2516
- };
2517
- const handleClearFilters = () => {
2518
- const currentPath = location.pathname;
2519
- const currentParams = new URLSearchParams(location.search);
2520
- const cleanParams = new URLSearchParams();
2521
- currentParams.forEach((value, key) => {
2522
- if (!key.startsWith("filters[") && !key.startsWith("populate[")) {
2523
- cleanParams.set(key, value);
2524
- }
2525
- });
2526
- const finalUrl = `${currentPath}${cleanParams.toString() ? "?" + cleanParams.toString() : ""}`;
2527
- navigate(finalUrl);
2528
- setTimeout(() => {
2529
- window.location.reload();
2530
- }, 100);
2531
- };
2532
- const getCurrentFilters = () => {
2533
- const params = new URLSearchParams(location.search);
2534
- const currentQuery = params.toString();
2535
- console.log("[AdvancedFilter] Current query from URL:", currentQuery);
2536
- return currentQuery;
2537
- };
2538
- return /* @__PURE__ */ jsxRuntime.jsxs(FilterButtonGroup, { children: [
2539
- /* @__PURE__ */ jsxRuntime.jsxs(
2540
- FilterButton,
2541
- {
2542
- $isActive: hasActiveFilters,
2543
- onClick: () => setShowModal(true),
2544
- title: "Open advanced filter builder",
2545
- children: [
2546
- /* @__PURE__ */ jsxRuntime.jsx(icons.Filter, {}),
2547
- "Filters",
2548
- hasActiveFilters && /* @__PURE__ */ jsxRuntime.jsx(ActiveDot, {})
2549
- ]
2550
- }
2551
- ),
2552
- hasActiveFilters && /* @__PURE__ */ jsxRuntime.jsx(
2553
- ClearButton,
2554
- {
2555
- onClick: handleClearFilters,
2556
- title: "Clear all filters",
2557
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {})
2558
- }
2559
- ),
2560
- showModal && /* @__PURE__ */ jsxRuntime.jsx(
2561
- StrapiStyleFilterModal,
2562
- {
2563
- onClose: () => setShowModal(false),
2564
- onApply: handleApplyFilters,
2565
- availableFields,
2566
- availableRelations,
2567
- currentQuery: getCurrentFilters()
2568
- }
2569
- )
2570
- ] });
2571
- };
2572
- const name = pluginPkg.strapi.name;
2573
- const prefixPluginTranslations = (data, pluginId2) => {
2574
- const prefixed = {};
2575
- Object.keys(data).forEach((key) => {
2576
- prefixed[`${pluginId2}.${key}`] = data[key];
2577
- });
2578
- return prefixed;
2579
- };
2580
- const index = {
2581
- register(app) {
2582
- console.log(`[${pluginId}] Registering plugin...`);
2583
- app.addMenuLink({
2584
- to: `plugins/${pluginId}`,
2585
- icon: PluginIcon,
2586
- intlLabel: {
2587
- id: `${pluginId}.Admin.MainMenu.PluginName`,
2588
- defaultMessage: name
2589
- },
2590
- Component: () => Promise.resolve().then(() => require("./App-DFDDcq8K.js")),
2591
- permissions: []
2592
- });
2593
- app.createSettingSection(
2594
- {
2595
- id: pluginId,
2596
- intlLabel: {
2597
- id: `${pluginId}.settings.title`,
2598
- defaultMessage: "MagicMark"
2599
- }
2600
- },
2601
- [
2602
- {
2603
- intlLabel: {
2604
- id: `${pluginId}.settings.upgrade`,
2605
- defaultMessage: "Upgrade"
2606
- },
2607
- id: "magic-mark-upgrade",
2608
- to: `${pluginId}/upgrade`,
2609
- Component: () => Promise.resolve().then(() => require(
2610
- /* webpackChunkName: "magic-mark-upgrade" */
2611
- "./UpgradePage-CwYDN8bT.js"
2612
- )),
2613
- permissions: []
2614
- },
2615
- {
2616
- intlLabel: {
2617
- id: `${pluginId}.settings.license`,
2618
- defaultMessage: "License"
2619
- },
2620
- id: "magic-mark-license",
2621
- to: `${pluginId}/license`,
2622
- Component: () => Promise.resolve().then(() => require(
2623
- /* webpackChunkName: "magic-mark-license" */
2624
- "./index-uUErgmi9.js"
2625
- )),
2626
- permissions: []
2627
- }
2628
- ]
2629
- );
2630
- app.registerPlugin({
2631
- id: pluginId,
2632
- initializer: Initializer,
2633
- isReady: true,
2634
- name
2635
- });
2636
- },
2637
- async bootstrap(app) {
2638
- console.log(`[${pluginId}] Bootstrapping plugin...`);
2639
- try {
2640
- const contentManagerPlugin = app.getPlugin("content-manager");
2641
- if (contentManagerPlugin) {
2642
- console.log(`[${pluginId}] Injecting content manager components...`);
2643
- contentManagerPlugin.injectComponent("listView", "actions", {
2644
- name: "magic-mark-advanced-filter",
2645
- Component: AdvancedFilterButton
2646
- });
2647
- contentManagerPlugin.injectComponent("listView", "actions", {
2648
- name: "magic-mark-views-widget",
2649
- Component: ViewsWidget
2650
- });
2651
- console.log(`[${pluginId}] Successfully injected content manager components`);
2652
- }
2653
- } catch (error) {
2654
- console.error(`[${pluginId}] Error injecting content manager components:`, error);
2655
- }
2656
- const env = typeof process === "undefined" ? {} : process.env;
2657
- if (env.STRAPI_ADMIN_FAVORITE_VIEWS_INJECT_TO) {
2658
- for (const entry of env.STRAPI_ADMIN_FAVORITE_VIEWS_INJECT_TO.split(",")) {
2659
- const parts = entry.split("::");
2660
- if (parts.length < 2) continue;
2661
- const [, pluginAndPath] = parts;
2662
- const [pluginName, container, block] = pluginAndPath.split(".");
2663
- const plugin = app.getPlugin(pluginName);
2664
- if (!plugin) continue;
2665
- try {
2666
- plugin.injectComponent(container, block, {
2667
- name: "favorite-views-widget",
2668
- Component: ViewsWidget
2669
- });
2670
- } catch (error) {
2671
- console.error(`[${pluginId}] Error injecting component to ${pluginName}:`, error);
2672
- }
2673
- }
2674
- }
2675
- },
2676
- async registerTrads({ locales }) {
2677
- const importedTrads = await Promise.all(
2678
- locales.map((locale) => {
2679
- return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-Cs9dd3Mr.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-CE3r46Y2.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-D4AOyJYJ.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-CWSfoA8i.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-DW_6r_mP.js")) }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
2680
- return {
2681
- data: prefixPluginTranslations(data, pluginId),
2682
- locale
2683
- };
2684
- }).catch(() => {
2685
- return {
2686
- data: {},
2687
- locale
2688
- };
2689
- });
2690
- })
2691
- );
2692
- return Promise.resolve(importedTrads);
2693
- }
2694
- };
2695
- exports.CreateEditModal = CreateEditModal;
2696
- exports.getIconById = getIconById;
2697
- exports.index = index;
2698
- exports.pluginId = pluginId;