strapi-plugin-magic-mark 3.4.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +373 -0
  2. package/README.md +393 -618
  3. package/dist/admin/App-BIc-2qv8.mjs +580 -0
  4. package/dist/admin/App-DxALpMK_.js +580 -0
  5. package/dist/admin/PinnedBookmarksWidget-BWiAKlnA.mjs +55 -0
  6. package/dist/admin/PinnedBookmarksWidget-VM6buexr.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-BJ8l6K7P.mjs +1861 -0
  16. package/dist/admin/index-C9FMo0F_.js +1862 -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-DNyxeldt.js +0 -1451
  28. package/dist/_chunks/App-D_Vllkur.mjs +0 -1449
  29. package/dist/_chunks/UpgradePage-DuyIskve.mjs +0 -351
  30. package/dist/_chunks/UpgradePage-SzlmS6po.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-CBwb0AEf.js +0 -3618
  40. package/dist/_chunks/index-JirQF8zE.mjs +0 -328
  41. package/dist/_chunks/index-QkINaIgJ.mjs +0 -3614
  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
@@ -0,0 +1,1862 @@
1
+ "use strict";
2
+ const icons = require("@strapi/icons");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const designSystem = require("@strapi/design-system");
5
+ const admin = require("@strapi/strapi/admin");
6
+ const react = require("react");
7
+ const reactIntl = require("react-intl");
8
+ const reactRouterDom = require("react-router-dom");
9
+ const qs = require("qs");
10
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
11
+ const qs__default = /* @__PURE__ */ _interopDefault(qs);
12
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
13
+ const v = glob[path];
14
+ if (v) {
15
+ return typeof v === "function" ? v() : Promise.resolve(v);
16
+ }
17
+ return new Promise((_, reject) => {
18
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
19
+ reject.bind(
20
+ null,
21
+ new Error(
22
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
23
+ )
24
+ )
25
+ );
26
+ });
27
+ };
28
+ const action = (uid) => [{ action: `plugin::magic-mark.${uid}`, subject: null }];
29
+ const PERMISSIONS = {
30
+ read: action("bookmarks.read"),
31
+ create: action("bookmarks.create"),
32
+ update: action("bookmarks.update"),
33
+ delete: action("bookmarks.delete"),
34
+ share: action("bookmarks.share"),
35
+ manage: action("bookmarks.manage")
36
+ };
37
+ const ALL_PERMISSIONS = Object.values(PERMISSIONS).flat();
38
+ const LIST_VIEW_PATH = /^\/content-manager\/(collection-types|single-types)\/((?:api|plugin)::[a-z0-9_-]{1,80}\.[a-z0-9_-]{1,80})\/?$/;
39
+ const SAVED_QUERY_KEYS = ["filters", "sort", "pageSize", "_q", "plugins"];
40
+ const PERSISTED_KEYS = ["sort", "filters", "pageSize"];
41
+ const parseListViewPath = (pathname) => {
42
+ if (typeof pathname !== "string") return null;
43
+ const match = LIST_VIEW_PATH.exec(pathname);
44
+ if (!match) return null;
45
+ return {
46
+ kind: match[1],
47
+ uid: match[2],
48
+ path: `/content-manager/${match[1]}/${match[2]}`
49
+ };
50
+ };
51
+ const pickSavedQuery = (query) => {
52
+ const out = {};
53
+ for (const key of SAVED_QUERY_KEYS) {
54
+ const value = query[key];
55
+ if (value === void 0 || value === "") continue;
56
+ if (key === "plugins") {
57
+ const locale = value?.i18n?.locale;
58
+ if (typeof locale === "string") out.plugins = { i18n: { locale } };
59
+ continue;
60
+ }
61
+ out[key] = value;
62
+ }
63
+ return out;
64
+ };
65
+ const syncPersistedListSettings = (storage, uid, saved) => {
66
+ const prefix = `STRAPI_LIST_VIEW_SETTINGS:${uid}`;
67
+ const value = {};
68
+ for (const key of PERSISTED_KEYS) {
69
+ if (saved[key] !== void 0) value[key] = saved[key];
70
+ }
71
+ const keys = [];
72
+ for (let i = 0; i < storage.length; i += 1) {
73
+ const key = storage.key(i);
74
+ if (key && (key === prefix || key.startsWith(`${prefix}:`))) keys.push(key);
75
+ }
76
+ for (const key of keys) {
77
+ if (Object.keys(value).length) storage.setItem(key, JSON.stringify(value));
78
+ else storage.removeItem(key);
79
+ }
80
+ };
81
+ const pluginId = "magic-mark";
82
+ const msg = (key, defaultMessage) => ({
83
+ id: `${pluginId}.${key}`,
84
+ defaultMessage
85
+ });
86
+ const NATIVE_OPERATOR_LABELS = {
87
+ $eq: "is",
88
+ $ne: "is not",
89
+ $null: "is null",
90
+ $notNull: "is not null",
91
+ $eqi: "is (case insensitive)",
92
+ $nei: "is not (case insensitive)",
93
+ $contains: "contains",
94
+ $containsi: "contains (case insensitive)",
95
+ $notContains: "does not contain",
96
+ $notContainsi: "does not contain (case insensitive)",
97
+ $startsWith: "starts with",
98
+ $startsWithi: "starts with (case insensitive)",
99
+ $endsWith: "ends with",
100
+ $endsWithi: "ends with (case insensitive)",
101
+ $gt: "is greater than",
102
+ $gte: "is greater than or equal to",
103
+ $lt: "is lower than",
104
+ $lte: "is lower than or equal to"
105
+ };
106
+ const PLUGIN_OPERATOR_LABELS = {
107
+ $in: msg("operators.in", "is one of"),
108
+ $notIn: msg("operators.notIn", "is none of"),
109
+ $between: msg("operators.between", "is between")
110
+ };
111
+ const operatorLabel = (operator) => PLUGIN_OPERATOR_LABELS[operator] ?? {
112
+ id: `components.FilterOptions.FILTER_TYPES.${operator}`,
113
+ defaultMessage: NATIVE_OPERATOR_LABELS[operator] ?? operator
114
+ };
115
+ const NOT_FILTERABLE = /* @__PURE__ */ new Set([
116
+ "json",
117
+ "component",
118
+ "media",
119
+ "richtext",
120
+ "dynamiczone",
121
+ "password",
122
+ "blocks",
123
+ "relation"
124
+ ]);
125
+ const SCALAR_SUB_TYPES = /* @__PURE__ */ new Set([
126
+ "string",
127
+ "text",
128
+ "email",
129
+ "uid",
130
+ "integer",
131
+ "biginteger",
132
+ "float",
133
+ "decimal",
134
+ "date",
135
+ "datetime",
136
+ "time",
137
+ "boolean",
138
+ "enumeration"
139
+ ]);
140
+ const COMPONENT_INTERNAL_KEYS = /* @__PURE__ */ new Set(["id", "documentId"]);
141
+ const mainFieldName = (meta) => {
142
+ const main = meta?.list?.mainField ?? meta?.edit?.mainField;
143
+ return typeof main === "string" ? main : main?.name;
144
+ };
145
+ const buildFieldOptions = (uid, init, metadatas, readable) => {
146
+ const schema = init.contentTypes.find((ct) => ct.uid === uid);
147
+ if (!schema) return [];
148
+ const fields = [
149
+ { path: "id", label: "id", type: "integer" },
150
+ { path: "documentId", label: "documentId", type: "string" }
151
+ ];
152
+ const canRead = (name) => readable === null || readable.some((field) => field === name || field.startsWith(`${name}.`));
153
+ for (const [name, attribute] of Object.entries(schema.attributes)) {
154
+ if (!canRead(name) || attribute.private) continue;
155
+ const label = metadatas[name]?.list?.label || metadatas[name]?.edit?.label || name;
156
+ if (attribute.type === "relation") {
157
+ const target = attribute.targetModel ?? attribute.target;
158
+ if (!target || target === "admin::user") continue;
159
+ const targetSchema = init.contentTypes.find((ct) => ct.uid === target);
160
+ const main = mainFieldName(metadatas[name]);
161
+ const mainType = main ? targetSchema?.attributes?.[main]?.type : void 0;
162
+ if (main && mainType && SCALAR_SUB_TYPES.has(mainType)) {
163
+ fields.push({
164
+ path: `${name}.${main}`,
165
+ label: `${label} (${main})`,
166
+ type: mainType,
167
+ group: label
168
+ });
169
+ }
170
+ fields.push({ path: `${name}.id`, label: `${label} (id)`, type: "integer", group: label });
171
+ continue;
172
+ }
173
+ if (attribute.type === "component" && !attribute.repeatable && attribute.component) {
174
+ const component = init.components.find((c) => c.uid === attribute.component);
175
+ for (const [subName, sub] of Object.entries(component?.attributes ?? {})) {
176
+ if (COMPONENT_INTERNAL_KEYS.has(subName)) continue;
177
+ if (!SCALAR_SUB_TYPES.has(sub.type) || sub.private) continue;
178
+ fields.push({
179
+ path: `${name}.${subName}`,
180
+ label: `${label} (${subName})`,
181
+ type: sub.type,
182
+ enum: sub.enum,
183
+ group: label
184
+ });
185
+ }
186
+ continue;
187
+ }
188
+ if (NOT_FILTERABLE.has(attribute.type)) continue;
189
+ fields.push({ path: name, label, type: attribute.type, enum: attribute.enum });
190
+ }
191
+ for (const name of ["createdAt", "updatedAt"]) {
192
+ if (!fields.some((field) => field.path === name)) {
193
+ fields.push({ path: name, label: metadatas[name]?.list?.label || name, type: "datetime" });
194
+ }
195
+ }
196
+ return fields;
197
+ };
198
+ let initCache = null;
199
+ const configCache = /* @__PURE__ */ new Map();
200
+ const loadInit = (get) => {
201
+ if (!initCache) {
202
+ initCache = get("/content-manager/init").then(({ data }) => data.data).catch((error) => {
203
+ initCache = null;
204
+ throw error;
205
+ });
206
+ }
207
+ return initCache;
208
+ };
209
+ const loadMetadatas = (get, uid) => {
210
+ let promise = configCache.get(uid);
211
+ if (!promise) {
212
+ promise = get(
213
+ `/content-manager/content-types/${uid}/configuration`
214
+ ).then(({ data }) => data.data.contentType.metadatas ?? {}).catch((error) => {
215
+ configCache.delete(uid);
216
+ throw error;
217
+ });
218
+ configCache.set(uid, promise);
219
+ }
220
+ return promise;
221
+ };
222
+ const useContentTypeNames = () => {
223
+ const { get } = admin.useFetchClient();
224
+ const [state, setState] = react.useState({
225
+ names: /* @__PURE__ */ new Map(),
226
+ isLoading: true,
227
+ error: null
228
+ });
229
+ react.useEffect(() => {
230
+ let active = true;
231
+ loadInit(get).then((init) => {
232
+ if (!active) return;
233
+ setState({
234
+ names: new Map(init.contentTypes.map((ct) => [ct.uid, ct.info?.displayName ?? ct.uid])),
235
+ isLoading: false,
236
+ error: null
237
+ });
238
+ }).catch((error) => active && setState({ names: /* @__PURE__ */ new Map(), isLoading: false, error }));
239
+ return () => {
240
+ active = false;
241
+ };
242
+ }, [get]);
243
+ return state;
244
+ };
245
+ const useFilterFields = (uid) => {
246
+ const { get } = admin.useFetchClient();
247
+ const permissions = admin.useAuth("MagicMarkFilters", (state2) => state2.permissions);
248
+ const [attempt, setAttempt] = react.useState(0);
249
+ const [state, setState] = react.useState({
250
+ key: "",
251
+ fields: [],
252
+ error: null
253
+ });
254
+ const readable = react.useMemo(() => {
255
+ const permission = permissions.find(
256
+ (p) => p.action === "plugin::content-manager.explorer.read" && p.subject === uid
257
+ );
258
+ const fields = permission?.properties?.fields;
259
+ return Array.isArray(fields) ? fields : null;
260
+ }, [permissions, uid]);
261
+ const key = uid ? `${uid}:${attempt}` : "";
262
+ react.useEffect(() => {
263
+ if (!uid) return void 0;
264
+ let active = true;
265
+ Promise.all([loadInit(get), loadMetadatas(get, uid)]).then(([init, metadatas]) => {
266
+ if (active) {
267
+ setState({ key, fields: buildFieldOptions(uid, init, metadatas, readable), error: null });
268
+ }
269
+ }).catch((error) => active && setState({ key, fields: [], error }));
270
+ return () => {
271
+ active = false;
272
+ };
273
+ }, [get, uid, readable, key]);
274
+ const current = state.key === key;
275
+ return {
276
+ fields: current ? state.fields : [],
277
+ error: current ? state.error : null,
278
+ isLoading: !!uid && !current,
279
+ retry: () => setAttempt((n) => n + 1)
280
+ };
281
+ };
282
+ const ADMIN_QUERY_DEPTH = 5;
283
+ const NO_VALUE_OPERATORS = ["$null", "$notNull"];
284
+ const LIST_OPERATORS = ["$in", "$notIn"];
285
+ const RANGE_OPERATORS = ["$between"];
286
+ const BASE$1 = ["$eq", "$ne", "$null", "$notNull"];
287
+ const NUMERIC = ["$gt", "$gte", "$lt", "$lte"];
288
+ const SENSITIVE = ["$eqi", "$nei"];
289
+ const CONTAINS = ["$contains", "$containsi", "$notContains", "$notContainsi"];
290
+ const STRING_PARSE = ["$startsWith", "$startsWithi", "$endsWith", "$endsWithi"];
291
+ const ALL_OPERATORS = [
292
+ ...BASE$1,
293
+ ...SENSITIVE,
294
+ ...CONTAINS,
295
+ ...STRING_PARSE,
296
+ ...NUMERIC,
297
+ ...LIST_OPERATORS,
298
+ ...RANGE_OPERATORS
299
+ ];
300
+ const operatorsForType = (type, isSubField = false) => {
301
+ let ops;
302
+ switch (type) {
303
+ case "email":
304
+ case "string":
305
+ case "text":
306
+ case "uid":
307
+ ops = [...BASE$1, ...SENSITIVE, ...CONTAINS, ...STRING_PARSE, ...LIST_OPERATORS];
308
+ break;
309
+ case "float":
310
+ case "integer":
311
+ case "biginteger":
312
+ case "decimal":
313
+ ops = [...BASE$1, ...NUMERIC, ...LIST_OPERATORS, ...RANGE_OPERATORS];
314
+ break;
315
+ case "date":
316
+ case "time":
317
+ ops = [...BASE$1, ...NUMERIC, ...CONTAINS, ...RANGE_OPERATORS];
318
+ break;
319
+ case "datetime":
320
+ ops = [...BASE$1, ...NUMERIC, ...RANGE_OPERATORS];
321
+ break;
322
+ case "enumeration":
323
+ ops = [...BASE$1, ...LIST_OPERATORS];
324
+ break;
325
+ case "boolean":
326
+ ops = [...BASE$1];
327
+ break;
328
+ default:
329
+ ops = [...BASE$1, ...SENSITIVE];
330
+ }
331
+ return isSubField ? ops.filter((op) => !LIST_OPERATORS.includes(op) && !RANGE_OPERATORS.includes(op)) : ops;
332
+ };
333
+ const BOOLEAN_VALUES = ["true", "false"];
334
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
335
+ const isDateOnly = (value) => DATE_ONLY.test(value ?? "");
336
+ const datetimeToInput = (value) => {
337
+ const date = new Date(value);
338
+ if (!value.includes("T") || Number.isNaN(date.getTime())) return value;
339
+ const pad = (n) => String(n).padStart(2, "0");
340
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
341
+ };
342
+ const inputToDatetime = (value) => {
343
+ if (!value || isDateOnly(value)) return value;
344
+ const date = new Date(value);
345
+ return Number.isNaN(date.getTime()) ? value : date.toISOString();
346
+ };
347
+ const splitList = (value) => value.split(",").map((item) => item.trim()).filter(Boolean);
348
+ const validateRow = (row, fields) => {
349
+ const field = fields.get(row.field);
350
+ if (!field) return "field";
351
+ if (!operatorsForType(field.type, row.field.includes(".")).includes(row.operator)) {
352
+ return "operator";
353
+ }
354
+ if (NO_VALUE_OPERATORS.includes(row.operator)) return null;
355
+ if (field.type === "boolean") return BOOLEAN_VALUES.includes(row.value) ? null : "value";
356
+ if (LIST_OPERATORS.includes(row.operator)) return splitList(row.value).length ? null : "value";
357
+ if (!row.value.trim()) return "value";
358
+ if (RANGE_OPERATORS.includes(row.operator) && !(row.valueTo ?? "").trim()) return "valueTo";
359
+ return null;
360
+ };
361
+ const operatorValue = (row) => {
362
+ if (NO_VALUE_OPERATORS.includes(row.operator)) return { [row.operator]: "true" };
363
+ if (LIST_OPERATORS.includes(row.operator)) return { [row.operator]: splitList(row.value) };
364
+ if (RANGE_OPERATORS.includes(row.operator)) {
365
+ return { [row.operator]: [row.value.trim(), (row.valueTo ?? "").trim()] };
366
+ }
367
+ return { [row.operator]: row.value.trim() };
368
+ };
369
+ const rowToFilter = (row) => {
370
+ const [head, sub] = row.field.split(".");
371
+ return sub ? { [head]: { [sub]: operatorValue(row) } } : { [head]: operatorValue(row) };
372
+ };
373
+ const buildFilters = (match, rows) => {
374
+ if (!rows.length) return void 0;
375
+ return { [match === "any" ? "$or" : "$and"]: rows.map(rowToFilter) };
376
+ };
377
+ const filterDepth = (value) => {
378
+ if (Array.isArray(value)) {
379
+ return value.length ? 1 + Math.max(...value.map(filterDepth)) : 1;
380
+ }
381
+ if (value && typeof value === "object") {
382
+ const entries = Object.values(value);
383
+ return entries.length ? 1 + Math.max(...entries.map(filterDepth)) : 1;
384
+ }
385
+ return 0;
386
+ };
387
+ const fitsAdminQueryDepth = (filters) => filterDepth(filters) <= ADMIN_QUERY_DEPTH;
388
+ const isPlainObject$1 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
389
+ const SAFE_KEY = /^[A-Za-z_][A-Za-z0-9_]{0,99}$/;
390
+ const OPERATOR = /^\$[A-Za-z]{1,20}$/;
391
+ let rowCounter = 0;
392
+ const nextRowId = () => {
393
+ rowCounter += 1;
394
+ return `row-${rowCounter}`;
395
+ };
396
+ const entryToRow = (entry) => {
397
+ if (!isPlainObject$1(entry)) return null;
398
+ const keys = Object.keys(entry);
399
+ if (keys.length !== 1 || !SAFE_KEY.test(keys[0])) return null;
400
+ const head = keys[0];
401
+ const inner = entry[head];
402
+ if (!isPlainObject$1(inner)) return null;
403
+ const innerKeys = Object.keys(inner);
404
+ if (innerKeys.length !== 1) return null;
405
+ let path = head;
406
+ let opObject = inner;
407
+ if (!OPERATOR.test(innerKeys[0])) {
408
+ if (!SAFE_KEY.test(innerKeys[0])) return null;
409
+ const nested = inner[innerKeys[0]];
410
+ if (!isPlainObject$1(nested) || Object.keys(nested).length !== 1) return null;
411
+ path = `${head}.${innerKeys[0]}`;
412
+ opObject = nested;
413
+ }
414
+ const operator = Object.keys(opObject)[0];
415
+ if (!ALL_OPERATORS.includes(operator)) return null;
416
+ const raw = opObject[operator];
417
+ if (NO_VALUE_OPERATORS.includes(operator)) {
418
+ return { id: nextRowId(), field: path, operator, value: "" };
419
+ }
420
+ if (LIST_OPERATORS.includes(operator)) {
421
+ const list = Array.isArray(raw) ? raw : [raw];
422
+ if (!list.every((item) => typeof item === "string")) return null;
423
+ return { id: nextRowId(), field: path, operator, value: list.join(", ") };
424
+ }
425
+ if (RANGE_OPERATORS.includes(operator)) {
426
+ if (!Array.isArray(raw) || raw.length !== 2 || !raw.every((v) => typeof v === "string")) {
427
+ return null;
428
+ }
429
+ return { id: nextRowId(), field: path, operator, value: raw[0], valueTo: raw[1] };
430
+ }
431
+ if (typeof raw !== "string") return null;
432
+ return { id: nextRowId(), field: path, operator, value: raw };
433
+ };
434
+ const parseFilters = (filters) => {
435
+ if (filters === void 0 || filters === null || filters === "") {
436
+ return { match: "all", rows: [], unsupported: false };
437
+ }
438
+ if (!isPlainObject$1(filters)) return { match: "all", rows: [], unsupported: true };
439
+ const keys = Object.keys(filters);
440
+ if (keys.length !== 1 || !["$and", "$or"].includes(keys[0])) {
441
+ return { match: "all", rows: [], unsupported: true };
442
+ }
443
+ const match = keys[0] === "$or" ? "any" : "all";
444
+ const list = filters[keys[0]];
445
+ const entries = Array.isArray(list) ? list : isPlainObject$1(list) ? Object.values(list) : [];
446
+ const rows = [];
447
+ let unsupported = !Array.isArray(list) && !isPlainObject$1(list);
448
+ for (const entry of entries) {
449
+ const row = entryToRow(entry);
450
+ if (row) rows.push(row);
451
+ else unsupported = true;
452
+ }
453
+ return { match, rows, unsupported };
454
+ };
455
+ const countConditions = (filters) => {
456
+ if (!isPlainObject$1(filters)) return 0;
457
+ let count = 0;
458
+ for (const [key, value] of Object.entries(filters)) {
459
+ if (key === "$and" || key === "$or") {
460
+ count += Array.isArray(value) ? value.length : isPlainObject$1(value) ? Object.keys(value).length : 0;
461
+ } else {
462
+ count += 1;
463
+ }
464
+ }
465
+ return count;
466
+ };
467
+ const FOCUSABLE = [
468
+ "a[href]",
469
+ "button:not([disabled])",
470
+ 'input:not([disabled]):not([type="hidden"])',
471
+ "select:not([disabled])",
472
+ "textarea:not([disabled])",
473
+ '[tabindex]:not([tabindex="-1"])',
474
+ '[contenteditable="true"]'
475
+ ].join(",");
476
+ const loopTarget = (nodes, active, backwards) => {
477
+ if (!nodes.length) return null;
478
+ const first = nodes[0];
479
+ const last = nodes[nodes.length - 1];
480
+ const index2 = active === null ? -1 : nodes.indexOf(active);
481
+ if (index2 === -1) return backwards ? last : first;
482
+ if (!backwards && active === last) return first;
483
+ if (backwards && active === first) return last;
484
+ return null;
485
+ };
486
+ const keepFocusInside = (event) => {
487
+ if (event.key !== "Tab" || event.defaultPrevented) return;
488
+ const container = event.currentTarget;
489
+ const active = document.activeElement;
490
+ if (active && !container.contains(active)) return;
491
+ const nodes = Array.from(container.querySelectorAll(FOCUSABLE)).filter(
492
+ (node) => node.getClientRects().length > 0 && node.getAttribute("aria-hidden") !== "true"
493
+ );
494
+ const target = loopTarget(nodes, active, event.shiftKey);
495
+ if (target) {
496
+ event.preventDefault();
497
+ target.focus();
498
+ }
499
+ };
500
+ const LINK_TARGET = {
501
+ paddingTop: "0.6rem",
502
+ paddingBottom: "0.6rem",
503
+ marginTop: "-0.6rem",
504
+ marginBottom: "-0.6rem"
505
+ };
506
+ const TEXT_BUTTON_TARGET = {
507
+ paddingTop: "0.8rem",
508
+ paddingBottom: "0.8rem",
509
+ marginTop: "-0.8rem",
510
+ marginBottom: "-0.8rem"
511
+ };
512
+ const INPUT_TYPES = {
513
+ integer: "number",
514
+ biginteger: "text",
515
+ float: "number",
516
+ decimal: "number",
517
+ date: "date",
518
+ time: "time",
519
+ datetime: "datetime-local",
520
+ email: "text"
521
+ };
522
+ const emptyRow = () => ({ id: nextRowId(), field: "", operator: "$eq", value: "" });
523
+ const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
524
+ const { formatMessage } = reactIntl.useIntl();
525
+ const [{ query }, setQuery] = admin.useQueryParams();
526
+ const { fields, isLoading, error, retry } = useFilterFields(open ? uid : null);
527
+ const fieldMap = react.useMemo(() => new Map(fields.map((field) => [field.path, field])), [fields]);
528
+ const [initial] = react.useState(() => parseFilters(query.filters));
529
+ const [match, setMatch] = react.useState(initial.match);
530
+ const [rows, setRows] = react.useState(
531
+ () => initial.rows.length ? initial.rows.map((row) => ({
532
+ ...row,
533
+ value: datetimeToInput(row.value),
534
+ valueTo: row.valueTo && datetimeToInput(row.valueTo)
535
+ })) : [emptyRow()]
536
+ );
537
+ const [unsupported, setUnsupported] = react.useState(initial.unsupported);
538
+ const [showErrors, setShowErrors] = react.useState(false);
539
+ const updateRow = (id, patch) => setRows((prev) => prev.map((row) => row.id === id ? { ...row, ...patch } : row));
540
+ const activeRows = rows.filter((row) => row.field || row.value);
541
+ const rowErrors = new Map(activeRows.map((row) => [row.id, validateRow(row, fieldMap)]));
542
+ const hasErrors = [...rowErrors.values()].some(Boolean);
543
+ const apply = () => {
544
+ setShowErrors(true);
545
+ if (hasErrors) return;
546
+ const prepared = activeRows.map(
547
+ (row) => fieldMap.get(row.field)?.type === "datetime" ? {
548
+ ...row,
549
+ value: inputToDatetime(row.value),
550
+ valueTo: row.valueTo && inputToDatetime(row.valueTo)
551
+ } : row
552
+ );
553
+ const filters = buildFilters(match, prepared);
554
+ if (filters && !fitsAdminQueryDepth(filters)) return;
555
+ setQuery(
556
+ {
557
+ ...admin.withEncodedUserParams(query, { page: 1 }),
558
+ filters: filters ? admin.deepEncodeQueryValues(filters) : void 0
559
+ },
560
+ "push",
561
+ true
562
+ );
563
+ onOpenChange(false);
564
+ };
565
+ const clearAll = () => {
566
+ setQuery({ ...admin.withEncodedUserParams(query, { page: 1 }), filters: void 0 }, "push", true);
567
+ onOpenChange(false);
568
+ };
569
+ const errorText = (row, part) => {
570
+ if (!showErrors || rowErrors.get(row.id) !== part) return void 0;
571
+ if (part === "field") return formatMessage(msg("filters.errorField", "Choose a field."));
572
+ if (part === "operator")
573
+ return formatMessage(msg("filters.errorOperator", "Choose a condition."));
574
+ return formatMessage(msg("filters.errorValue", "Enter a value."));
575
+ };
576
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { onKeyDown: keepFocusInside, children: [
577
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { closeLabel: formatMessage(msg("form.close", "Close")), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: formatMessage(msg("filters.title", "Advanced filters")) }) }),
578
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 6, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: formatMessage(msg("state.loading", "Loading")) }) }) : error ? /* @__PURE__ */ jsxRuntime.jsx(
579
+ designSystem.Alert,
580
+ {
581
+ variant: "danger",
582
+ closeLabel: formatMessage(msg("form.close", "Close")),
583
+ title: formatMessage(msg("filters.loadErrorTitle", "Fields could not be loaded")),
584
+ action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", size: "S", onClick: retry, children: formatMessage(msg("state.retry", "Try again")) }),
585
+ children: formatMessage(
586
+ msg("filters.loadError", "The fields of this content type could not be loaded.")
587
+ )
588
+ }
589
+ ) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
590
+ unsupported ? /* @__PURE__ */ jsxRuntime.jsx(
591
+ designSystem.Alert,
592
+ {
593
+ variant: "warning",
594
+ closeLabel: formatMessage(msg("form.close", "Close")),
595
+ onClose: () => setUnsupported(false),
596
+ children: formatMessage(
597
+ msg(
598
+ "filters.unsupported",
599
+ "The list has filters this editor cannot show. Applying replaces them."
600
+ )
601
+ )
602
+ }
603
+ ) : null,
604
+ /* @__PURE__ */ jsxRuntime.jsxs(
605
+ designSystem.Field.Root,
606
+ {
607
+ name: "match",
608
+ hint: match === "any" ? formatMessage(
609
+ msg(
610
+ "filters.matchAnyHint",
611
+ "These conditions are not shown as filter tags above the list."
612
+ )
613
+ ) : void 0,
614
+ children: [
615
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("filters.match", "Show entries that match")) }),
616
+ /* @__PURE__ */ jsxRuntime.jsxs(
617
+ designSystem.SingleSelect,
618
+ {
619
+ value: match,
620
+ onChange: (value) => setMatch(value),
621
+ children: [
622
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "all", children: formatMessage(msg("filters.matchAll", "All conditions")) }),
623
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "any", children: formatMessage(msg("filters.matchAny", "Any condition")) })
624
+ ]
625
+ }
626
+ ),
627
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
628
+ ]
629
+ }
630
+ ),
631
+ /* @__PURE__ */ jsxRuntime.jsx(
632
+ designSystem.Flex,
633
+ {
634
+ direction: "column",
635
+ alignItems: "stretch",
636
+ gap: 4,
637
+ tag: "ol",
638
+ "aria-label": formatMessage(msg("filters.conditions", "Conditions")),
639
+ children: rows.map((row, index2) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "li", background: "neutral100", hasRadius: true, padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
640
+ FilterRowEditor,
641
+ {
642
+ row,
643
+ index: index2,
644
+ fields,
645
+ field: fieldMap.get(row.field),
646
+ onChange: (patch) => updateRow(row.id, patch),
647
+ onRemove: () => setRows((prev) => {
648
+ const next = prev.filter((r) => r.id !== row.id);
649
+ return next.length ? next : [emptyRow()];
650
+ }),
651
+ errorText: (part) => errorText(row, part)
652
+ }
653
+ ) }, row.id))
654
+ }
655
+ ),
656
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
657
+ designSystem.TextButton,
658
+ {
659
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
660
+ ...TEXT_BUTTON_TARGET,
661
+ onClick: () => setRows((prev) => [...prev, emptyRow()]),
662
+ children: formatMessage(msg("filters.add", "Add condition"))
663
+ }
664
+ ) })
665
+ ] }) }),
666
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
667
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", onClick: clearAll, disabled: !query.filters, children: formatMessage(msg("filters.clear", "Clear all")) }),
668
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
669
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage(msg("form.cancel", "Cancel")) }) }),
670
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: apply, disabled: isLoading || !!error, children: formatMessage(msg("filters.apply", "Apply")) })
671
+ ] })
672
+ ] })
673
+ ] }) });
674
+ };
675
+ const FilterRowEditor = ({
676
+ row,
677
+ index: index2,
678
+ fields,
679
+ field,
680
+ onChange,
681
+ onRemove,
682
+ errorText
683
+ }) => {
684
+ const { formatMessage } = reactIntl.useIntl();
685
+ const operators = field ? operatorsForType(field.type, row.field.includes(".")) : [];
686
+ const needsValue = !NO_VALUE_OPERATORS.includes(row.operator);
687
+ const position = { number: index2 + 1 };
688
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, children: [
689
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `field-${row.id}`, error: errorText("field"), children: [
690
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("filters.field", "Field")) }),
691
+ /* @__PURE__ */ jsxRuntime.jsx(
692
+ designSystem.Combobox,
693
+ {
694
+ value: row.field,
695
+ onChange: (value) => {
696
+ const next = fields.find((f) => f.path === value);
697
+ const ops = next ? operatorsForType(next.type, (value ?? "").includes(".")) : [];
698
+ onChange({
699
+ field: value ?? "",
700
+ operator: ops.includes(row.operator) ? row.operator : ops[0] ?? "$eq",
701
+ value: "",
702
+ valueTo: void 0
703
+ });
704
+ },
705
+ placeholder: formatMessage(msg("filters.fieldPlaceholder", "Choose a field")),
706
+ noOptionsMessage: () => formatMessage(msg("filters.noFields", "No matching fields")),
707
+ children: fields.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: option.path, children: option.label }, option.path))
708
+ }
709
+ ),
710
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
711
+ ] }) }),
712
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `operator-${row.id}`, error: errorText("operator"), children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("filters.operator", "Condition")) }),
714
+ /* @__PURE__ */ jsxRuntime.jsx(
715
+ designSystem.SingleSelect,
716
+ {
717
+ value: row.operator,
718
+ disabled: !field,
719
+ onChange: (value) => onChange({ operator: String(value) }),
720
+ children: operators.map((op) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: op, children: formatMessage(operatorLabel(op)) }, op))
721
+ }
722
+ ),
723
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
724
+ ] }) }),
725
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 10, xs: 10, direction: "column", alignItems: "stretch", children: needsValue ? /* @__PURE__ */ jsxRuntime.jsx(ValueInput, { row, field, onChange, errorText }) : null }),
726
+ /* @__PURE__ */ jsxRuntime.jsx(
727
+ designSystem.Grid.Item,
728
+ {
729
+ col: 1,
730
+ s: 2,
731
+ xs: 2,
732
+ direction: "column",
733
+ alignItems: "flex-end",
734
+ justifyContent: "flex-end",
735
+ children: /* @__PURE__ */ jsxRuntime.jsx(
736
+ designSystem.IconButton,
737
+ {
738
+ label: formatMessage(msg("filters.remove", "Remove condition {number}"), position),
739
+ variant: "ghost",
740
+ onClick: onRemove,
741
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
742
+ }
743
+ )
744
+ }
745
+ )
746
+ ] });
747
+ };
748
+ const ValueInput = ({ row, field, onChange, errorText }) => {
749
+ const { formatMessage } = reactIntl.useIntl();
750
+ const valueLabel = formatMessage(msg("filters.value", "Value"));
751
+ const isList = LIST_OPERATORS.includes(row.operator);
752
+ const isRange = RANGE_OPERATORS.includes(row.operator);
753
+ const type = field?.type ?? "string";
754
+ if (type === "boolean") {
755
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `value-${row.id}`, error: errorText("value"), children: [
756
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: valueLabel }),
757
+ /* @__PURE__ */ jsxRuntime.jsxs(
758
+ designSystem.SingleSelect,
759
+ {
760
+ value: row.value,
761
+ onChange: (value) => onChange({ value: String(value) }),
762
+ children: [
763
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "true", children: formatMessage(msg("filters.true", "true")) }),
764
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "false", children: formatMessage(msg("filters.false", "false")) })
765
+ ]
766
+ }
767
+ ),
768
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
769
+ ] });
770
+ }
771
+ if (type === "enumeration" && field?.enum) {
772
+ return isList ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `value-${row.id}`, error: errorText("value"), children: [
773
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: valueLabel }),
774
+ /* @__PURE__ */ jsxRuntime.jsx(
775
+ designSystem.MultiSelect,
776
+ {
777
+ withTags: true,
778
+ value: splitList(row.value),
779
+ onChange: (values) => onChange({ value: values.join(", ") }),
780
+ children: field.enum.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: option, children: option }, option))
781
+ }
782
+ ),
783
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
784
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `value-${row.id}`, error: errorText("value"), children: [
785
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: valueLabel }),
786
+ /* @__PURE__ */ jsxRuntime.jsx(
787
+ designSystem.SingleSelect,
788
+ {
789
+ value: row.value,
790
+ onChange: (value) => onChange({ value: String(value) }),
791
+ children: field.enum.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: option, children: option }, option))
792
+ }
793
+ ),
794
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
795
+ ] });
796
+ }
797
+ const keepsDay = type === "datetime" && !isRange && isDateOnly(row.value);
798
+ const inputType = isList ? "text" : keepsDay ? "date" : INPUT_TYPES[type] ?? "text";
799
+ if (isRange) {
800
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "flex-start", children: [
801
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `from-${row.id}`, error: errorText("value"), flex: 1, minWidth: 0, children: [
802
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("filters.from", "From")) }),
803
+ /* @__PURE__ */ jsxRuntime.jsx(
804
+ designSystem.TextInput,
805
+ {
806
+ type: inputType,
807
+ value: row.value,
808
+ onChange: (event) => onChange({ value: event.target.value })
809
+ }
810
+ ),
811
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
812
+ ] }),
813
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `to-${row.id}`, error: errorText("valueTo"), flex: 1, minWidth: 0, children: [
814
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("filters.to", "To")) }),
815
+ /* @__PURE__ */ jsxRuntime.jsx(
816
+ designSystem.TextInput,
817
+ {
818
+ type: inputType,
819
+ value: row.valueTo ?? "",
820
+ onChange: (event) => onChange({ valueTo: event.target.value })
821
+ }
822
+ ),
823
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
824
+ ] })
825
+ ] });
826
+ }
827
+ return /* @__PURE__ */ jsxRuntime.jsxs(
828
+ designSystem.Field.Root,
829
+ {
830
+ name: `value-${row.id}`,
831
+ error: errorText("value"),
832
+ hint: isList ? formatMessage(msg("filters.listHint", "Separate values with commas.")) : void 0,
833
+ children: [
834
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: valueLabel }),
835
+ /* @__PURE__ */ jsxRuntime.jsx(
836
+ designSystem.TextInput,
837
+ {
838
+ type: inputType,
839
+ value: row.value,
840
+ onChange: (event) => onChange({ value: event.target.value })
841
+ }
842
+ ),
843
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
844
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
845
+ ]
846
+ }
847
+ );
848
+ };
849
+ const BASE = "/magic-mark";
850
+ const useBookmarksApi = () => {
851
+ const { get, post, put, del } = admin.useFetchClient();
852
+ return react.useMemo(
853
+ () => ({
854
+ list: async (params, signal) => {
855
+ const clean = Object.fromEntries(
856
+ Object.entries(params).filter(([, value]) => value !== void 0 && value !== "")
857
+ );
858
+ const { data } = await get(`${BASE}/bookmarks`, { params: clean, signal });
859
+ return data;
860
+ },
861
+ get: async (id) => (await get(`${BASE}/bookmarks/${id}`)).data.data,
862
+ create: async (input) => (await post(`${BASE}/bookmarks`, input)).data.data,
863
+ update: async (id, input) => (await put(`${BASE}/bookmarks/${id}`, input)).data.data,
864
+ updateView: async (id, query) => (await put(`${BASE}/bookmarks/${id}/view`, { query })).data.data,
865
+ duplicate: async (id, name) => (await post(`${BASE}/bookmarks/${id}/duplicate`, name ? { name } : {})).data.data,
866
+ pin: async (id, pinned) => (await put(`${BASE}/bookmarks/${id}/pin`, { pinned })).data.data,
867
+ remove: async (id) => {
868
+ await del(`${BASE}/bookmarks/${id}`);
869
+ },
870
+ roles: async () => (await get(`${BASE}/sharing/roles`)).data.data,
871
+ users: async (q, page = 1, signal) => (await get(
872
+ `${BASE}/sharing/users`,
873
+ { params: q ? { q, page } : { page }, signal }
874
+ )).data
875
+ }),
876
+ [get, post, put, del]
877
+ );
878
+ };
879
+ const TRUE_VALUES = /* @__PURE__ */ new Set(["true", "t", "1", "yes", "on"]);
880
+ const FALSE_VALUES = /* @__PURE__ */ new Set(["false", "f", "0", "no", "off"]);
881
+ const LOGICAL = /* @__PURE__ */ new Set(["$and", "$or", "$not"]);
882
+ const normalizeBooleanValue = (value) => {
883
+ if (typeof value === "boolean") return value ? "true" : "false";
884
+ if (typeof value === "number") return value === 1 ? "true" : value === 0 ? "false" : null;
885
+ if (typeof value !== "string") return null;
886
+ const text = value.trim().toLowerCase();
887
+ if (TRUE_VALUES.has(text)) return "true";
888
+ if (FALSE_VALUES.has(text)) return "false";
889
+ return null;
890
+ };
891
+ const createAttributeResolver = (init, uid) => {
892
+ const contentTypes = new Map(init.contentTypes.map((ct) => [ct.uid, ct.attributes]));
893
+ const components = new Map(init.components.map((c) => [c.uid, c.attributes]));
894
+ return (path) => {
895
+ let attributes = contentTypes.get(uid);
896
+ for (let i = 0; i < path.length; i += 1) {
897
+ const attribute = attributes?.[path[i]];
898
+ if (!attribute) return void 0;
899
+ if (i === path.length - 1) return attribute;
900
+ if (attribute.type === "relation") {
901
+ attributes = contentTypes.get(attribute.targetModel ?? attribute.target ?? "");
902
+ } else if (attribute.type === "component" && attribute.component) {
903
+ attributes = components.get(attribute.component);
904
+ } else {
905
+ return void 0;
906
+ }
907
+ }
908
+ return void 0;
909
+ };
910
+ };
911
+ const isPlainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
912
+ const sanitizeBooleanFilters = (filters, resolve) => {
913
+ let normalized = 0;
914
+ let dropped = 0;
915
+ const fixValue = (value) => {
916
+ if (Array.isArray(value)) {
917
+ const list = value.map(fixValue).filter((item) => item !== void 0);
918
+ return list.length ? list : void 0;
919
+ }
920
+ const next = normalizeBooleanValue(value);
921
+ if (next === null) {
922
+ dropped += 1;
923
+ return void 0;
924
+ }
925
+ if (next !== value) normalized += 1;
926
+ return next;
927
+ };
928
+ const walk = (node, path) => {
929
+ if (Array.isArray(node)) {
930
+ const list = node.map((item) => walk(item, path)).filter((item) => item !== void 0);
931
+ return list.length || !node.length ? list : void 0;
932
+ }
933
+ const isBoolean = path.length > 0 && resolve(path)?.type === "boolean";
934
+ if (!isPlainObject(node)) {
935
+ return isBoolean ? fixValue(node) : node;
936
+ }
937
+ const out = {};
938
+ for (const [key, value] of Object.entries(node)) {
939
+ let next;
940
+ if (LOGICAL.has(key)) next = walk(value, path);
941
+ else if (key.startsWith("$")) next = isBoolean ? fixValue(value) : value;
942
+ else next = walk(value, [...path, key]);
943
+ if (next !== void 0) out[key] = next;
944
+ }
945
+ return Object.keys(out).length || !Object.keys(node).length ? out : void 0;
946
+ };
947
+ return { filters: walk(filters, []), normalized, dropped };
948
+ };
949
+ const QS_PARSE_OPTIONS = {
950
+ allowPrototypes: false,
951
+ plainObjects: true,
952
+ depth: 8,
953
+ parameterLimit: 500,
954
+ arrayLimit: 100
955
+ };
956
+ const parseQuery = (query) => {
957
+ if (!query) return {};
958
+ return qs__default.default.parse(query.startsWith("?") ? query.slice(1) : query, QS_PARSE_OPTIONS);
959
+ };
960
+ const stringifyQuery = (query) => qs__default.default.stringify(query, { encodeValuesOnly: true });
961
+ const bookmarkLocation = (bookmark) => {
962
+ const location = parseListViewPath(bookmark.path);
963
+ if (!location) return null;
964
+ return { pathname: location.path, search: bookmark.query ? `?${bookmark.query}` : "" };
965
+ };
966
+ const normalizeSavedQuery = (query, init, uid) => {
967
+ if (query.filters === void 0) return query;
968
+ const result = sanitizeBooleanFilters(query.filters, createAttributeResolver(init, uid));
969
+ if (!result.normalized && !result.dropped) return query;
970
+ const next = { ...query };
971
+ if (result.filters === void 0) delete next.filters;
972
+ else next.filters = result.filters;
973
+ return next;
974
+ };
975
+ const useOpenBookmark = () => {
976
+ const navigate = reactRouterDom.useNavigate();
977
+ const { get } = admin.useFetchClient();
978
+ const { toggleNotification } = admin.useNotification();
979
+ const { formatMessage } = reactIntl.useIntl();
980
+ return react.useCallback(
981
+ async (bookmark) => {
982
+ const location = parseListViewPath(bookmark.path);
983
+ if (!location) {
984
+ toggleNotification({
985
+ type: "danger",
986
+ message: formatMessage(
987
+ msg("notification.invalidPath", "This bookmark does not point to a list view.")
988
+ )
989
+ });
990
+ return;
991
+ }
992
+ const parsed = parseQuery(bookmark.query);
993
+ let saved = parsed;
994
+ try {
995
+ saved = normalizeSavedQuery(parsed, await loadInit(get), location.uid);
996
+ } catch {
997
+ }
998
+ const search = saved === parsed ? bookmark.query ?? "" : stringifyQuery(saved);
999
+ try {
1000
+ syncPersistedListSettings(window.localStorage, location.uid, saved);
1001
+ } catch {
1002
+ }
1003
+ navigate({ pathname: location.path, search: search ? `?${search}` : "" });
1004
+ },
1005
+ [get, navigate, toggleNotification, formatMessage]
1006
+ );
1007
+ };
1008
+ const errorBody = (error) => error?.response?.data?.error;
1009
+ const fieldErrors = (error) => {
1010
+ const fields = errorBody(error)?.details?.fieldErrors ?? {};
1011
+ return Object.fromEntries(
1012
+ Object.entries(fields).filter(([, messages]) => Array.isArray(messages) && messages.length).map(([field, messages]) => [field, messages[0]])
1013
+ );
1014
+ };
1015
+ const ICON_OPTIONS = [
1016
+ { key: "bookmark", Icon: icons.Book },
1017
+ { key: "star", Icon: icons.Star },
1018
+ { key: "heart", Icon: icons.Heart },
1019
+ { key: "bolt", Icon: icons.Lightning },
1020
+ { key: "rocket", Icon: icons.Rocket },
1021
+ { key: "sparkles", Icon: icons.Sparkle },
1022
+ { key: "pencil", Icon: icons.Pencil },
1023
+ { key: "document", Icon: icons.File },
1024
+ { key: "folder", Icon: icons.Folder },
1025
+ { key: "photo", Icon: icons.Image },
1026
+ { key: "link", Icon: icons.Link },
1027
+ { key: "tag", Icon: icons.PriceTag },
1028
+ { key: "filter", Icon: icons.Filter },
1029
+ { key: "search", Icon: icons.Search },
1030
+ { key: "calendar", Icon: icons.Calendar },
1031
+ { key: "clock", Icon: icons.Clock },
1032
+ { key: "bell", Icon: icons.Bell },
1033
+ { key: "check", Icon: icons.CheckCircle },
1034
+ { key: "mail", Icon: icons.Mail },
1035
+ { key: "user", Icon: icons.User },
1036
+ { key: "briefcase", Icon: icons.Briefcase },
1037
+ { key: "gift", Icon: icons.Gift },
1038
+ { key: "globe", Icon: icons.Globe },
1039
+ { key: "home", Icon: icons.House },
1040
+ { key: "flag", Icon: icons.Feather },
1041
+ { key: "fire", Icon: icons.TrendUp },
1042
+ { key: "cube", Icon: icons.Stack },
1043
+ { key: "cog", Icon: icons.Cog },
1044
+ { key: "wrench", Icon: icons.PuzzlePiece },
1045
+ { key: "terminal", Icon: icons.Code },
1046
+ { key: "chart", Icon: icons.ChartPie }
1047
+ ];
1048
+ const ALIASES = { book: "bookmark", users: "user" };
1049
+ const BY_KEY = new Map(ICON_OPTIONS.map((option) => [option.key, option.Icon]));
1050
+ const getIcon = (key) => BY_KEY.get(ALIASES[key ?? ""] ?? key ?? "") ?? icons.Book;
1051
+ const ICON_LABELS = {
1052
+ bookmark: msg("icons.bookmark", "Book"),
1053
+ star: msg("icons.star", "Star"),
1054
+ heart: msg("icons.heart", "Heart"),
1055
+ bolt: msg("icons.bolt", "Lightning"),
1056
+ rocket: msg("icons.rocket", "Rocket"),
1057
+ sparkles: msg("icons.sparkles", "Sparkle"),
1058
+ pencil: msg("icons.pencil", "Pencil"),
1059
+ document: msg("icons.document", "Document"),
1060
+ folder: msg("icons.folder", "Folder"),
1061
+ photo: msg("icons.photo", "Image"),
1062
+ link: msg("icons.link", "Link"),
1063
+ tag: msg("icons.tag", "Tag"),
1064
+ filter: msg("icons.filter", "Filter"),
1065
+ search: msg("icons.search", "Search"),
1066
+ calendar: msg("icons.calendar", "Calendar"),
1067
+ clock: msg("icons.clock", "Clock"),
1068
+ bell: msg("icons.bell", "Bell"),
1069
+ check: msg("icons.check", "Check mark"),
1070
+ mail: msg("icons.mail", "Mail"),
1071
+ user: msg("icons.user", "Person"),
1072
+ briefcase: msg("icons.briefcase", "Briefcase"),
1073
+ gift: msg("icons.gift", "Gift"),
1074
+ globe: msg("icons.globe", "Globe"),
1075
+ home: msg("icons.home", "House"),
1076
+ flag: msg("icons.flag", "Feather"),
1077
+ fire: msg("icons.fire", "Trend"),
1078
+ cube: msg("icons.cube", "Stack"),
1079
+ cog: msg("icons.cog", "Gear"),
1080
+ wrench: msg("icons.wrench", "Puzzle piece"),
1081
+ terminal: msg("icons.terminal", "Code"),
1082
+ chart: msg("icons.chart", "Chart")
1083
+ };
1084
+ const FilterSummary = ({ contentType, query }) => {
1085
+ const { formatMessage } = reactIntl.useIntl();
1086
+ const { fields } = useFilterFields(contentType);
1087
+ const parsed = parseQuery(query);
1088
+ const state = parseFilters(parsed.filters);
1089
+ const labels = new Map(fields.map((field) => [field.path, field.label]));
1090
+ const tags = state.rows.map((row) => {
1091
+ const field = labels.get(row.field) ?? row.field;
1092
+ const op = formatMessage(operatorLabel(row.operator));
1093
+ if (NO_VALUE_OPERATORS.includes(row.operator)) return `${field} ${op}`;
1094
+ if (RANGE_OPERATORS.includes(row.operator)) {
1095
+ return formatMessage(msg("summary.range", "{field} {operator} {from} and {to}"), {
1096
+ field,
1097
+ operator: op,
1098
+ from: row.value,
1099
+ to: row.valueTo ?? ""
1100
+ });
1101
+ }
1102
+ return `${field} ${op} ${row.value}`;
1103
+ });
1104
+ const sort = typeof parsed.sort === "string" ? parsed.sort.split(":") : null;
1105
+ const locale = parsed.plugins?.i18n?.locale;
1106
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
1107
+ tags.length === 0 && !state.unsupported ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(msg("summary.noFilters", "No filters. The bookmark opens the full list.")) }) : null,
1108
+ tags.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
1109
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(
1110
+ state.match === "any" ? msg("summary.matchAny", "Any of") : msg("summary.matchAll", "All of")
1111
+ ) }),
1112
+ tags.map((label, index2) => /* @__PURE__ */ jsxRuntime.jsx(
1113
+ designSystem.Box,
1114
+ {
1115
+ background: "primary100",
1116
+ borderColor: "primary200",
1117
+ hasRadius: true,
1118
+ paddingLeft: 2,
1119
+ paddingRight: 2,
1120
+ paddingTop: 1,
1121
+ paddingBottom: 1,
1122
+ minWidth: 0,
1123
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "primary600", children: label })
1124
+ },
1125
+ `${index2}-${label}`
1126
+ ))
1127
+ ] }) : null,
1128
+ state.unsupported ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(msg("summary.customFilters", "Includes filters set outside the editor.")) }) : null,
1129
+ sort || locale ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
1130
+ sort ? formatMessage(msg("summary.sort", "Sorted by {field}, {direction}"), {
1131
+ field: labels.get(sort[0]) ?? sort[0],
1132
+ direction: formatMessage(
1133
+ sort[1]?.toUpperCase() === "DESC" ? msg("summary.descending", "descending") : msg("summary.ascending", "ascending")
1134
+ )
1135
+ }) : null,
1136
+ locale ? formatMessage(msg("summary.locale", "Locale: {locale}"), { locale }) : null
1137
+ ].filter(Boolean).join(" · ") }) : null
1138
+ ] });
1139
+ };
1140
+ const SharingFields = ({ value, onChange, error }) => {
1141
+ const { formatMessage } = reactIntl.useIntl();
1142
+ const api = useBookmarksApi();
1143
+ const [roles, setRoles] = react.useState([]);
1144
+ const [rolesLoading, setRolesLoading] = react.useState(true);
1145
+ const [search, setSearch] = react.useState("");
1146
+ const [results, setResults] = react.useState([]);
1147
+ const [usersLoading, setUsersLoading] = react.useState(false);
1148
+ const [loadError, setLoadError] = react.useState(false);
1149
+ const timer = react.useRef(null);
1150
+ react.useEffect(() => {
1151
+ let active = true;
1152
+ api.roles().then((data) => active && setRoles(data)).catch(() => active && setLoadError(true)).finally(() => active && setRolesLoading(false));
1153
+ return () => {
1154
+ active = false;
1155
+ };
1156
+ }, [api]);
1157
+ react.useEffect(() => {
1158
+ if (value.visibility !== "shared") return void 0;
1159
+ const controller = new AbortController();
1160
+ if (timer.current) clearTimeout(timer.current);
1161
+ timer.current = setTimeout(() => {
1162
+ setUsersLoading(true);
1163
+ api.users(search.trim(), 1, controller.signal).then(({ data }) => setResults(data)).catch(() => {
1164
+ if (!controller.signal.aborted) setLoadError(true);
1165
+ }).finally(() => !controller.signal.aborted && setUsersLoading(false));
1166
+ }, 250);
1167
+ return () => {
1168
+ controller.abort();
1169
+ if (timer.current) clearTimeout(timer.current);
1170
+ };
1171
+ }, [api, search, value.visibility]);
1172
+ const userLabel = (user) => [
1173
+ user.name ?? formatMessage(msg("sharing.unnamedUser", "Unnamed user")),
1174
+ user.email ? `(${user.email})` : ""
1175
+ ].filter(Boolean).join(" ");
1176
+ const selectedIds = new Set(value.users.map((user) => user.documentId));
1177
+ const options = results.filter((user) => !selectedIds.has(user.documentId));
1178
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
1179
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "visibility", children: [
1180
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.visibility", "Who can see it")) }),
1181
+ /* @__PURE__ */ jsxRuntime.jsxs(
1182
+ designSystem.Radio.Group,
1183
+ {
1184
+ value: value.visibility,
1185
+ onValueChange: (next) => onChange({ ...value, visibility: next }),
1186
+ "aria-label": formatMessage(msg("form.visibility", "Who can see it")),
1187
+ children: [
1188
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { value: "private", children: formatMessage(msg("visibility.private", "Only me")) }),
1189
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { value: "shared", children: formatMessage(msg("visibility.sharedOption", "Specific roles and users")) }),
1190
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { value: "public", children: formatMessage(msg("visibility.publicOption", "All admin users")) })
1191
+ ]
1192
+ }
1193
+ )
1194
+ ] }),
1195
+ value.visibility === "shared" ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", hasRadius: true, padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
1196
+ loadError ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "danger600", children: formatMessage(
1197
+ msg(
1198
+ "sharing.loadError",
1199
+ "Roles and users could not be loaded. Close the dialog and try again."
1200
+ )
1201
+ ) }) : null,
1202
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "roles", error, children: [
1203
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.roles", "Roles")) }),
1204
+ /* @__PURE__ */ jsxRuntime.jsx(
1205
+ designSystem.MultiSelect,
1206
+ {
1207
+ loading: rolesLoading,
1208
+ value: value.roles,
1209
+ onChange: (next) => onChange({ ...value, roles: next }),
1210
+ placeholder: formatMessage(msg("form.rolesPlaceholder", "Choose roles")),
1211
+ children: roles.map((role) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: role.documentId, children: role.name }, role.documentId))
1212
+ }
1213
+ ),
1214
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
1215
+ ] }),
1216
+ /* @__PURE__ */ jsxRuntime.jsxs(
1217
+ designSystem.Field.Root,
1218
+ {
1219
+ name: "users",
1220
+ hint: formatMessage(msg("form.usersHint", "Type a name to search admin users.")),
1221
+ children: [
1222
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.users", "Users")) }),
1223
+ /* @__PURE__ */ jsxRuntime.jsx(
1224
+ designSystem.Combobox,
1225
+ {
1226
+ value: "",
1227
+ textValue: search,
1228
+ onTextValueChange: setSearch,
1229
+ loading: usersLoading,
1230
+ loadingMessage: formatMessage(msg("sharing.searching", "Searching users")),
1231
+ noOptionsMessage: () => formatMessage(msg("sharing.noUsers", "No matching users")),
1232
+ placeholder: formatMessage(msg("form.usersPlaceholder", "Search users")),
1233
+ onChange: (id) => {
1234
+ const user = options.find((option) => option.documentId === id);
1235
+ if (user) onChange({ ...value, users: [...value.users, user] });
1236
+ setSearch("");
1237
+ },
1238
+ children: options.map((user) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: user.documentId, children: userLabel(user) }, user.documentId))
1239
+ }
1240
+ ),
1241
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
1242
+ ]
1243
+ }
1244
+ ),
1245
+ value.users.length ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, wrap: "wrap", children: value.users.map((user) => /* @__PURE__ */ jsxRuntime.jsx(
1246
+ designSystem.Tag,
1247
+ {
1248
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}),
1249
+ label: formatMessage(msg("sharing.removeUser", "Remove {name}"), {
1250
+ name: userLabel(user)
1251
+ }),
1252
+ onClick: () => onChange({
1253
+ ...value,
1254
+ users: value.users.filter((u) => u.documentId !== user.documentId)
1255
+ }),
1256
+ children: userLabel(user)
1257
+ },
1258
+ user.documentId
1259
+ )) }) : null
1260
+ ] }) }) : null
1261
+ ] });
1262
+ };
1263
+ const NAME_MAX = 100;
1264
+ const snapshot = (name, description, icon, sharing) => JSON.stringify([
1265
+ name,
1266
+ description,
1267
+ icon,
1268
+ sharing.visibility,
1269
+ [...sharing.roles].sort(),
1270
+ sharing.users.map((user) => user.documentId).sort()
1271
+ ]);
1272
+ const DESCRIPTION_MAX = 500;
1273
+ const BookmarkFormModal = ({
1274
+ open,
1275
+ onOpenChange,
1276
+ view,
1277
+ bookmarkId,
1278
+ canShare,
1279
+ onSaved
1280
+ }) => {
1281
+ const { formatMessage } = reactIntl.useIntl();
1282
+ const { toggleNotification } = admin.useNotification();
1283
+ const api = useBookmarksApi();
1284
+ const { names } = useContentTypeNames();
1285
+ const isEdit = !!bookmarkId;
1286
+ const [name, setName] = react.useState("");
1287
+ const [description, setDescription] = react.useState("");
1288
+ const [icon, setIcon] = react.useState("bookmark");
1289
+ const [sharing, setSharing] = react.useState({
1290
+ visibility: "private",
1291
+ roles: [],
1292
+ users: []
1293
+ });
1294
+ const [loaded, setLoaded] = react.useState(null);
1295
+ const [loading, setLoading] = react.useState(!!bookmarkId);
1296
+ const [loadFailed, setLoadFailed] = react.useState(false);
1297
+ const [saving, setSaving] = react.useState(false);
1298
+ const [errors, setErrors] = react.useState({});
1299
+ const [queryRejected, setQueryRejected] = react.useState(false);
1300
+ const [initial, setInitial] = react.useState(
1301
+ () => snapshot("", "", "bookmark", { visibility: "private", roles: [], users: [] })
1302
+ );
1303
+ const [confirmDiscard, setConfirmDiscard] = react.useState(false);
1304
+ react.useEffect(() => {
1305
+ if (!bookmarkId) return void 0;
1306
+ let active = true;
1307
+ api.get(bookmarkId).then((bookmark) => {
1308
+ if (!active) return;
1309
+ const loadedSharing = {
1310
+ visibility: bookmark.visibility,
1311
+ roles: bookmark.sharing?.roles.map((role) => role.documentId) ?? [],
1312
+ users: bookmark.sharing?.users ?? []
1313
+ };
1314
+ setLoaded(bookmark);
1315
+ setName(bookmark.name);
1316
+ setDescription(bookmark.description ?? "");
1317
+ setIcon(bookmark.icon);
1318
+ setSharing(loadedSharing);
1319
+ setInitial(
1320
+ snapshot(bookmark.name, bookmark.description ?? "", bookmark.icon, loadedSharing)
1321
+ );
1322
+ }).catch(() => active && setLoadFailed(true)).finally(() => active && setLoading(false));
1323
+ return () => {
1324
+ active = false;
1325
+ };
1326
+ }, [bookmarkId, api]);
1327
+ const validate = () => {
1328
+ const next = {};
1329
+ if (!name.trim()) next.name = formatMessage(msg("form.nameRequired", "Enter a name."));
1330
+ else if (name.trim().length > NAME_MAX) {
1331
+ next.name = formatMessage(msg("form.nameTooLong", "Use at most {max} characters."), {
1332
+ max: NAME_MAX
1333
+ });
1334
+ }
1335
+ if (description.length > DESCRIPTION_MAX) {
1336
+ next.description = formatMessage(
1337
+ msg("form.descriptionTooLong", "Use at most {max} characters."),
1338
+ {
1339
+ max: DESCRIPTION_MAX
1340
+ }
1341
+ );
1342
+ }
1343
+ if (canShare && sharing.visibility === "shared" && !sharing.roles.length && !sharing.users.length) {
1344
+ next.roles = formatMessage(msg("form.targetsRequired", "Choose at least one role or user."));
1345
+ }
1346
+ setErrors(next);
1347
+ return Object.keys(next).length === 0;
1348
+ };
1349
+ const submit = async () => {
1350
+ if (!validate()) return;
1351
+ setSaving(true);
1352
+ const sharingInput = canShare ? {
1353
+ visibility: sharing.visibility,
1354
+ roles: sharing.visibility === "shared" ? sharing.roles : [],
1355
+ users: sharing.visibility === "shared" ? sharing.users.map((u) => u.documentId) : []
1356
+ } : {};
1357
+ try {
1358
+ const saved = isEdit ? await api.update(bookmarkId, {
1359
+ name: name.trim(),
1360
+ description: description.trim(),
1361
+ icon,
1362
+ ...sharingInput
1363
+ }) : await api.create({
1364
+ name: name.trim(),
1365
+ description: description.trim(),
1366
+ icon,
1367
+ path: view?.path,
1368
+ query: view?.query ?? "",
1369
+ ...sharingInput
1370
+ });
1371
+ toggleNotification({
1372
+ type: "success",
1373
+ message: formatMessage(
1374
+ isEdit ? msg("notification.updated", "Bookmark saved.") : msg("notification.created", "Bookmark created.")
1375
+ )
1376
+ });
1377
+ onSaved(saved);
1378
+ onOpenChange(false);
1379
+ } catch (error) {
1380
+ const fields = fieldErrors(error);
1381
+ setQueryRejected(!!fields.query);
1382
+ if (Object.keys(fields).length) {
1383
+ setErrors({
1384
+ ...fields.name ? { name: formatMessage(msg("form.nameInvalid", "Check the name.")) } : {},
1385
+ ...fields.roles || fields.users ? {
1386
+ roles: formatMessage(
1387
+ msg("form.targetsInvalid", "One of the roles or users no longer exists.")
1388
+ )
1389
+ } : {}
1390
+ });
1391
+ }
1392
+ if (fields.query) return;
1393
+ toggleNotification({
1394
+ type: "danger",
1395
+ message: formatMessage(
1396
+ msg(
1397
+ "notification.saveError",
1398
+ "The bookmark could not be saved. Your changes are still in the form."
1399
+ )
1400
+ )
1401
+ });
1402
+ } finally {
1403
+ setSaving(false);
1404
+ }
1405
+ };
1406
+ const isDirty = !loading && !loadFailed && snapshot(name, description, icon, sharing) !== initial;
1407
+ const handleOpenChange = (next) => {
1408
+ if (!next && isDirty && !saving) {
1409
+ setConfirmDiscard(true);
1410
+ return;
1411
+ }
1412
+ onOpenChange(next);
1413
+ };
1414
+ const title = isEdit ? formatMessage(msg("form.editTitle", "Edit bookmark")) : formatMessage(msg("form.createTitle", "Save view as bookmark"));
1415
+ const contentType = view?.contentType ?? loaded?.contentType ?? null;
1416
+ const query = view?.query ?? loaded?.query ?? "";
1417
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1418
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { onKeyDown: keepFocusInside, children: [
1419
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { closeLabel: formatMessage(msg("form.close", "Close")), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
1420
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 6, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: formatMessage(msg("state.loading", "Loading")) }) }) : loadFailed ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage(msg("form.loadError", "The bookmark could not be loaded.")) }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
1421
+ queryRejected ? /* @__PURE__ */ jsxRuntime.jsx(
1422
+ designSystem.Alert,
1423
+ {
1424
+ variant: "danger",
1425
+ closeLabel: formatMessage(msg("form.close", "Close")),
1426
+ onClose: () => setQueryRejected(false),
1427
+ children: formatMessage(
1428
+ msg(
1429
+ "form.queryTooLong",
1430
+ "This view cannot be saved: the search text or a filter value is too long. Shorten it in the list and try again."
1431
+ )
1432
+ )
1433
+ }
1434
+ ) : null,
1435
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", hasRadius: true, padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
1436
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: formatMessage(msg("form.savedView", "Saved view")) }),
1437
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", children: view?.contentTypeName ?? (contentType ? names.get(contentType) ?? contentType : "") }),
1438
+ /* @__PURE__ */ jsxRuntime.jsx(FilterSummary, { contentType, query })
1439
+ ] }) }),
1440
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "name", error: errors.name, required: true, children: [
1441
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.name", "Name")) }),
1442
+ /* @__PURE__ */ jsxRuntime.jsx(
1443
+ designSystem.TextInput,
1444
+ {
1445
+ value: name,
1446
+ maxLength: NAME_MAX,
1447
+ onChange: (event) => setName(event.target.value),
1448
+ placeholder: formatMessage(
1449
+ msg("form.namePlaceholder", "e.g. Drafts waiting for review")
1450
+ )
1451
+ }
1452
+ ),
1453
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
1454
+ ] }),
1455
+ /* @__PURE__ */ jsxRuntime.jsxs(
1456
+ designSystem.Field.Root,
1457
+ {
1458
+ name: "description",
1459
+ error: errors.description,
1460
+ hint: formatMessage(
1461
+ msg("form.descriptionHint", "Optional. Shown below the name.")
1462
+ ),
1463
+ children: [
1464
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.description", "Description")) }),
1465
+ /* @__PURE__ */ jsxRuntime.jsx(
1466
+ designSystem.Textarea,
1467
+ {
1468
+ value: description,
1469
+ onChange: (event) => setDescription(event.target.value)
1470
+ }
1471
+ ),
1472
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
1473
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
1474
+ ]
1475
+ }
1476
+ ),
1477
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "icon", children: [
1478
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage(msg("form.icon", "Icon")) }),
1479
+ /* @__PURE__ */ jsxRuntime.jsx(
1480
+ designSystem.SingleSelect,
1481
+ {
1482
+ value: icon,
1483
+ onChange: (value) => setIcon(String(value)),
1484
+ children: ICON_OPTIONS.map(({ key, Icon }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: key, startIcon: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true }), children: formatMessage(ICON_LABELS[key]) }, key))
1485
+ }
1486
+ )
1487
+ ] }),
1488
+ canShare ? /* @__PURE__ */ jsxRuntime.jsx(SharingFields, { value: sharing, onChange: setSharing, error: errors.roles }) : null
1489
+ ] }) }),
1490
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
1491
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage(msg("form.cancel", "Cancel")) }) }),
1492
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: submit, loading: saving, disabled: loading || loadFailed, children: formatMessage(msg("form.save", "Save")) })
1493
+ ] })
1494
+ ] }) }),
1495
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: confirmDiscard, onOpenChange: setConfirmDiscard, children: /* @__PURE__ */ jsxRuntime.jsx(
1496
+ admin.ConfirmDialog,
1497
+ {
1498
+ variant: "danger",
1499
+ onConfirm: () => {
1500
+ setConfirmDiscard(false);
1501
+ onOpenChange(false);
1502
+ },
1503
+ children: formatMessage(
1504
+ msg(
1505
+ "form.discardBody",
1506
+ "Close without saving? Your changes to this bookmark will be lost."
1507
+ )
1508
+ )
1509
+ }
1510
+ ) })
1511
+ ] });
1512
+ };
1513
+ const POPOVER_LIMIT = 100;
1514
+ const sortBookmarks = (list) => [...list].sort((a, b) => Number(b.isPinned) - Number(a.isPinned) || a.name.localeCompare(b.name));
1515
+ const BookmarksPopover = ({
1516
+ listView,
1517
+ canCreate,
1518
+ canUpdate,
1519
+ canShare
1520
+ }) => {
1521
+ const { formatMessage } = reactIntl.useIntl();
1522
+ const { toggleNotification } = admin.useNotification();
1523
+ const api = useBookmarksApi();
1524
+ const openBookmark = useOpenBookmark();
1525
+ const [{ query }] = admin.useQueryParams();
1526
+ const { names } = useContentTypeNames();
1527
+ const [open, setOpen] = react.useState(false);
1528
+ const [items, setItems] = react.useState([]);
1529
+ const [total, setTotal] = react.useState(0);
1530
+ const [status, setStatus] = react.useState("idle");
1531
+ const [busyId, setBusyId] = react.useState(null);
1532
+ const [captured, setCaptured] = react.useState(null);
1533
+ const load = react.useCallback(async () => {
1534
+ setStatus("loading");
1535
+ try {
1536
+ const base = {
1537
+ contentType: listView.uid,
1538
+ pageSize: POPOVER_LIMIT,
1539
+ sort: "name:asc"
1540
+ };
1541
+ const [pinned, all] = await Promise.all([
1542
+ api.list({ ...base, scope: "pinned" }),
1543
+ api.list(base)
1544
+ ]);
1545
+ const pinnedIds = new Set(pinned.data.map((b) => b.documentId));
1546
+ const rest = all.data.filter((b) => !pinnedIds.has(b.documentId));
1547
+ setItems(sortBookmarks([...pinned.data, ...rest]).slice(0, POPOVER_LIMIT));
1548
+ setTotal(all.meta.pagination.total);
1549
+ setStatus("ready");
1550
+ } catch {
1551
+ setStatus("error");
1552
+ }
1553
+ }, [api, listView.uid]);
1554
+ const handleOpenChange = (next) => {
1555
+ setOpen(next);
1556
+ if (next) load();
1557
+ };
1558
+ const currentQuery = stringifyQuery(pickSavedQuery(query));
1559
+ const contentTypeName = names.get(listView.uid) ?? listView.uid;
1560
+ const saveView = () => {
1561
+ setOpen(false);
1562
+ setCaptured({
1563
+ path: listView.path,
1564
+ query: currentQuery,
1565
+ contentType: listView.uid,
1566
+ contentTypeName
1567
+ });
1568
+ };
1569
+ const togglePin = async (bookmark) => {
1570
+ setBusyId(bookmark.documentId);
1571
+ try {
1572
+ await api.pin(bookmark.documentId, !bookmark.isPinned);
1573
+ setItems(
1574
+ (prev) => sortBookmarks(
1575
+ prev.map(
1576
+ (b) => b.documentId === bookmark.documentId ? { ...b, isPinned: !b.isPinned } : b
1577
+ )
1578
+ )
1579
+ );
1580
+ } catch {
1581
+ toggleNotification({
1582
+ type: "danger",
1583
+ message: formatMessage(msg("notification.pinError", "The bookmark could not be pinned."))
1584
+ });
1585
+ } finally {
1586
+ setBusyId(null);
1587
+ }
1588
+ };
1589
+ const updateView = async (bookmark) => {
1590
+ setBusyId(bookmark.documentId);
1591
+ try {
1592
+ const updated = await api.updateView(bookmark.documentId, currentQuery);
1593
+ setItems(
1594
+ (prev) => prev.map((b) => b.documentId === updated.documentId ? { ...b, ...updated } : b)
1595
+ );
1596
+ toggleNotification({
1597
+ type: "success",
1598
+ message: formatMessage(
1599
+ msg("notification.viewUpdated", '"{name}" now saves the current view.'),
1600
+ {
1601
+ name: bookmark.name
1602
+ }
1603
+ )
1604
+ });
1605
+ } catch (error) {
1606
+ toggleNotification({
1607
+ type: "danger",
1608
+ message: formatMessage(
1609
+ fieldErrors(error).query ? msg(
1610
+ "form.queryTooLong",
1611
+ "This view cannot be saved: the search text or a filter value is too long. Shorten it in the list and try again."
1612
+ ) : msg("notification.viewUpdateError", "The bookmark could not be updated.")
1613
+ )
1614
+ });
1615
+ } finally {
1616
+ setBusyId(null);
1617
+ }
1618
+ };
1619
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1620
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Popover.Root, { open, onOpenChange: handleOpenChange, children: [
1621
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.IconButton, { label: formatMessage(msg("popover.trigger", "Bookmarks")), children: /* @__PURE__ */ jsxRuntime.jsx(icons.Star, {}) }) }),
1622
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Content, { side: "bottom", align: "end", sideOffset: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
1623
+ designSystem.Box,
1624
+ {
1625
+ width: "32rem",
1626
+ maxWidth: "calc(100vw - 32px)",
1627
+ maxHeight: "var(--radix-popover-content-available-height)",
1628
+ overflow: "auto",
1629
+ padding: 3,
1630
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
1631
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 2, children: [
1632
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "h2", children: formatMessage(msg("popover.title", "Bookmarks for {name}"), {
1633
+ name: contentTypeName
1634
+ }) }),
1635
+ canCreate ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { size: "S", variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), onClick: saveView, children: formatMessage(msg("popover.save", "Save view")) }) : null
1636
+ ] }),
1637
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
1638
+ status === "loading" ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: formatMessage(msg("state.loading", "Loading")) }) }) : null,
1639
+ status === "error" ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
1640
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "danger600", children: formatMessage(msg("popover.error", "Bookmarks could not be loaded.")) }),
1641
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TextButton, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}), onClick: load, children: formatMessage(msg("state.retry", "Try again")) })
1642
+ ] }) : null,
1643
+ status === "ready" && items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: canCreate ? formatMessage(
1644
+ msg(
1645
+ "popover.empty",
1646
+ "No bookmarks for this content type yet. Filter the list, then choose Save view."
1647
+ )
1648
+ ) : formatMessage(
1649
+ msg("popover.emptyReadOnly", "No bookmarks for this content type yet.")
1650
+ ) }) : null,
1651
+ status === "ready" && items.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { maxHeight: "40rem", overflow: "auto", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, tag: "ul", children: items.map((bookmark) => {
1652
+ const Icon = getIcon(bookmark.icon);
1653
+ const target = bookmarkLocation(bookmark);
1654
+ const isCurrent = bookmark.query === currentQuery;
1655
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1656
+ designSystem.Flex,
1657
+ {
1658
+ tag: "li",
1659
+ gap: 2,
1660
+ alignItems: "center",
1661
+ paddingTop: 1,
1662
+ paddingBottom: 1,
1663
+ children: [
1664
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "flex-start", flex: 1, minWidth: 0, children: [
1665
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 1, color: "neutral600", children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true }) }),
1666
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", minWidth: 0, children: [
1667
+ target ? /* @__PURE__ */ jsxRuntime.jsx(
1668
+ designSystem.Link,
1669
+ {
1670
+ tag: reactRouterDom.NavLink,
1671
+ to: target,
1672
+ ...LINK_TARGET,
1673
+ onClick: (event) => {
1674
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0)
1675
+ return;
1676
+ event.preventDefault();
1677
+ setOpen(false);
1678
+ openBookmark(bookmark);
1679
+ },
1680
+ "aria-current": isCurrent ? "page" : void 0,
1681
+ children: bookmark.name
1682
+ }
1683
+ ) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: bookmark.name }),
1684
+ bookmark.description ? /* @__PURE__ */ jsxRuntime.jsx(
1685
+ designSystem.Typography,
1686
+ {
1687
+ variant: "pi",
1688
+ textColor: "neutral600",
1689
+ ellipsis: true,
1690
+ title: bookmark.description,
1691
+ children: bookmark.description
1692
+ }
1693
+ ) : null
1694
+ ] })
1695
+ ] }),
1696
+ canUpdate && bookmark.canEdit && !isCurrent ? /* @__PURE__ */ jsxRuntime.jsx(
1697
+ designSystem.IconButton,
1698
+ {
1699
+ label: formatMessage(
1700
+ msg("actions.updateViewNamed", "Save the current view in {name}"),
1701
+ {
1702
+ name: bookmark.name
1703
+ }
1704
+ ),
1705
+ variant: "ghost",
1706
+ disabled: busyId === bookmark.documentId,
1707
+ onClick: () => updateView(bookmark),
1708
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {})
1709
+ }
1710
+ ) : null,
1711
+ /* @__PURE__ */ jsxRuntime.jsx(
1712
+ designSystem.IconButton,
1713
+ {
1714
+ label: formatMessage(
1715
+ bookmark.isPinned ? msg("actions.unpinNamed", "Unpin {name}") : msg("actions.pinNamed", "Pin {name}"),
1716
+ { name: bookmark.name }
1717
+ ),
1718
+ variant: bookmark.isPinned ? "secondary" : "ghost",
1719
+ disabled: busyId === bookmark.documentId,
1720
+ onClick: () => togglePin(bookmark),
1721
+ "aria-pressed": bookmark.isPinned,
1722
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pin, {})
1723
+ }
1724
+ )
1725
+ ]
1726
+ },
1727
+ bookmark.documentId
1728
+ );
1729
+ }) }) }) : null,
1730
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
1731
+ status === "ready" && total > items.length ? /* @__PURE__ */ jsxRuntime.jsx(
1732
+ designSystem.Link,
1733
+ {
1734
+ tag: reactRouterDom.NavLink,
1735
+ to: `/plugins/${pluginId}?contentType=${encodeURIComponent(listView.uid)}`,
1736
+ ...LINK_TARGET,
1737
+ onClick: () => setOpen(false),
1738
+ children: formatMessage(msg("popover.showAll", "Show all {total} bookmarks"), { total })
1739
+ }
1740
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1741
+ designSystem.Link,
1742
+ {
1743
+ tag: reactRouterDom.NavLink,
1744
+ to: `/plugins/${pluginId}`,
1745
+ onClick: () => setOpen(false),
1746
+ ...LINK_TARGET,
1747
+ children: formatMessage(msg("popover.manage", "Manage bookmarks"))
1748
+ }
1749
+ )
1750
+ ] })
1751
+ }
1752
+ ) })
1753
+ ] }),
1754
+ captured ? /* @__PURE__ */ jsxRuntime.jsx(
1755
+ BookmarkFormModal,
1756
+ {
1757
+ open: !!captured,
1758
+ onOpenChange: (next) => !next && setCaptured(null),
1759
+ view: captured,
1760
+ canShare,
1761
+ onSaved: () => setCaptured(null)
1762
+ }
1763
+ ) : null
1764
+ ] });
1765
+ };
1766
+ const ListViewActions = () => {
1767
+ const { formatMessage } = reactIntl.useIntl();
1768
+ const { pathname } = reactRouterDom.useLocation();
1769
+ const listView = parseListViewPath(pathname);
1770
+ const { allowedActions, isLoading } = admin.useRBAC(ALL_PERMISSIONS);
1771
+ const [filtersOpen, setFiltersOpen] = react.useState(false);
1772
+ if (!listView || listView.kind !== "collection-types") return null;
1773
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1774
+ /* @__PURE__ */ jsxRuntime.jsx(
1775
+ designSystem.IconButton,
1776
+ {
1777
+ label: formatMessage(msg("filters.title", "Advanced filters")),
1778
+ onClick: () => setFiltersOpen(true),
1779
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.SlidersHorizontal, {})
1780
+ }
1781
+ ),
1782
+ filtersOpen ? /* @__PURE__ */ jsxRuntime.jsx(AdvancedFiltersModal, { open: filtersOpen, onOpenChange: setFiltersOpen, uid: listView.uid }) : null,
1783
+ !isLoading && allowedActions.canRead ? /* @__PURE__ */ jsxRuntime.jsx(
1784
+ BookmarksPopover,
1785
+ {
1786
+ listView,
1787
+ canCreate: !!allowedActions.canCreate,
1788
+ canUpdate: !!allowedActions.canUpdate,
1789
+ canShare: !!allowedActions.canShare
1790
+ }
1791
+ ) : null
1792
+ ] });
1793
+ };
1794
+ const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.Book, {});
1795
+ const index = {
1796
+ register(app) {
1797
+ app.addMenuLink({
1798
+ to: `plugins/${pluginId}`,
1799
+ icon: PluginIcon,
1800
+ intlLabel: { id: `${pluginId}.plugin.name`, defaultMessage: "Magic Mark" },
1801
+ Component: () => Promise.resolve().then(() => require("./App-DxALpMK_.js")),
1802
+ permissions: PERMISSIONS.read
1803
+ });
1804
+ app.registerPlugin({ id: pluginId, name: "Magic Mark" });
1805
+ const widgets = app.widgets;
1806
+ if (widgets && typeof widgets.register === "function") {
1807
+ widgets.register({
1808
+ id: "pinned-bookmarks",
1809
+ pluginId,
1810
+ icon: icons.Star,
1811
+ title: { id: `${pluginId}.widget.title`, defaultMessage: "Pinned bookmarks" },
1812
+ link: {
1813
+ label: { id: `${pluginId}.widget.link`, defaultMessage: "Manage bookmarks" },
1814
+ href: `/plugins/${pluginId}`
1815
+ },
1816
+ component: async () => (await Promise.resolve().then(() => require("./PinnedBookmarksWidget-VM6buexr.js"))).default,
1817
+ permissions: PERMISSIONS.read
1818
+ });
1819
+ }
1820
+ },
1821
+ bootstrap(app) {
1822
+ const contentManager = app.getPlugin("content-manager");
1823
+ contentManager?.injectComponent("listView", "actions", {
1824
+ name: `${pluginId}-list-view-actions`,
1825
+ Component: ListViewActions
1826
+ });
1827
+ },
1828
+ async registerTrads({ locales }) {
1829
+ return Promise.all(
1830
+ locales.map(async (locale) => {
1831
+ try {
1832
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-Cn90CcnC.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-GDfO_EfL.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-6o-_RABX.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-BOZS5mJT.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-D13SxuK2.js")) }), `./translations/${locale}.json`, 3);
1833
+ return {
1834
+ data: Object.fromEntries(
1835
+ Object.entries(data).map(([key, value]) => [
1836
+ `${pluginId}.${key}`,
1837
+ value
1838
+ ])
1839
+ ),
1840
+ locale
1841
+ };
1842
+ } catch {
1843
+ return { data: {}, locale };
1844
+ }
1845
+ })
1846
+ );
1847
+ }
1848
+ };
1849
+ exports.ALL_PERMISSIONS = ALL_PERMISSIONS;
1850
+ exports.BookmarkFormModal = BookmarkFormModal;
1851
+ exports.LINK_TARGET = LINK_TARGET;
1852
+ exports.PERMISSIONS = PERMISSIONS;
1853
+ exports.bookmarkLocation = bookmarkLocation;
1854
+ exports.countConditions = countConditions;
1855
+ exports.getIcon = getIcon;
1856
+ exports.index = index;
1857
+ exports.msg = msg;
1858
+ exports.parseQuery = parseQuery;
1859
+ exports.pluginId = pluginId;
1860
+ exports.useBookmarksApi = useBookmarksApi;
1861
+ exports.useContentTypeNames = useContentTypeNames;
1862
+ exports.useOpenBookmark = useOpenBookmark;