strapi-plugin-magic-mark 4.0.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.
- package/CHANGELOG.md +7 -0
- package/README.md +5 -1
- package/dist/admin/{App-C9PsvW9C.mjs → App-BIc-2qv8.mjs} +1 -1
- package/dist/admin/{App-KJvUCwN1.js → App-DxALpMK_.js} +1 -1
- package/dist/admin/{PinnedBookmarksWidget-ClskVR1i.mjs → PinnedBookmarksWidget-BWiAKlnA.mjs} +1 -1
- package/dist/admin/{PinnedBookmarksWidget-DlD8lDhq.js → PinnedBookmarksWidget-VM6buexr.js} +1 -1
- package/dist/admin/{index-X8I03cOT.mjs → index-BJ8l6K7P.mjs} +124 -32
- package/dist/admin/{index-CLjQOzqv.js → index-C9FMo0F_.js} +124 -32
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.0.1](https://github.com/Schero94/Magicmark/compare/v4.0.0...v4.0.1) (2026-11-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* keep saved filters valid for Strapi 5.62 ([#6](https://github.com/Schero94/Magicmark/issues/6)) ([4e97c70](https://github.com/Schero94/Magicmark/commit/4e97c70daac8fd4eb8f99aed41e6dbcb69b57479))
|
|
7
|
+
|
|
1
8
|
# [4.0.0](https://github.com/Schero94/Magicmark/compare/v3.4.0...v4.0.0) (2026-11-11)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Schero94/Magicmark/main/docs/site/img/icon.svg" alt="Magic Mark icon" width="96" height="96" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# Magic Mark
|
|
2
6
|
|
|
3
7
|
**Saved views for the Strapi 5 Content Manager.** Filter a list once, save it as a bookmark and
|
|
@@ -311,7 +315,7 @@ restarts crashed workers).
|
|
|
311
315
|
|
|
312
316
|
| Magic Mark | Strapi | Node.js | Notes |
|
|
313
317
|
| ---------- | ------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
314
|
-
| 4.x | 5.57.0 or newer 5.x | 22.22.2 or newer 22.x, 24.15.0 or newer | Free. Acceptance host: Strapi 5.
|
|
318
|
+
| 4.x | 5.57.0 or newer 5.x | 22.22.2 or newer 22.x, 24.15.0 or newer | Free. Acceptance host: Strapi 5.62.0 on SQLite and Postgres 16. 3.x data and permissions migrate on the first start. |
|
|
315
319
|
| 3.x | 5.x | 22 | Contained the license system. No longer maintained. |
|
|
316
320
|
|
|
317
321
|
Install with npm, yarn 1 or pnpm. The plugin's peers match what a new Strapi 5 app already has:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useNotification, useClipboard, useIsDesktop, useIsMobile, useMediaQuery, useRBAC, useQueryParams, Page, Layouts, SearchInput, Pagination, ConfirmDialog } from "@strapi/strapi/admin";
|
|
3
3
|
import { useHref, NavLink, Routes, Route } from "react-router-dom";
|
|
4
|
-
import { m as msg, u as useBookmarksApi, a as useOpenBookmark, b as useContentTypeNames, A as ALL_PERMISSIONS, B as BookmarkFormModal, g as getIcon, c as bookmarkLocation, L as LINK_TARGET, d as countConditions, p as parseQuery, e as pluginId, P as PERMISSIONS } from "./index-
|
|
4
|
+
import { m as msg, u as useBookmarksApi, a as useOpenBookmark, b as useContentTypeNames, A as ALL_PERMISSIONS, B as BookmarkFormModal, g as getIcon, c as bookmarkLocation, L as LINK_TARGET, d as countConditions, p as parseQuery, e as pluginId, P as PERMISSIONS } from "./index-BJ8l6K7P.mjs";
|
|
5
5
|
import { Flex, IconButton, Menu, LinkButton, Box, SingleSelect, SingleSelectOption, Button, EmptyStateLayout, Badge, Typography, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Dialog, Link as Link$1 } from "@strapi/design-system";
|
|
6
6
|
import { Pin, More, ExternalLink, Pencil, Duplicate, Link, Trash, CaretDown, CaretUp, ArrowRight } from "@strapi/icons";
|
|
7
7
|
import { EmptyDocuments, EmptyPictures } from "@strapi/icons/symbols";
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const admin = require("@strapi/strapi/admin");
|
|
5
5
|
const reactRouterDom = require("react-router-dom");
|
|
6
|
-
const index = require("./index-
|
|
6
|
+
const index = require("./index-C9FMo0F_.js");
|
|
7
7
|
const designSystem = require("@strapi/design-system");
|
|
8
8
|
const icons = require("@strapi/icons");
|
|
9
9
|
const symbols = require("@strapi/icons/symbols");
|
package/dist/admin/{PinnedBookmarksWidget-ClskVR1i.mjs → PinnedBookmarksWidget-BWiAKlnA.mjs}
RENAMED
|
@@ -4,7 +4,7 @@ import { Widget } from "@strapi/strapi/admin";
|
|
|
4
4
|
import { useState, useEffect } from "react";
|
|
5
5
|
import { useIntl } from "react-intl";
|
|
6
6
|
import { NavLink } from "react-router-dom";
|
|
7
|
-
import { u as useBookmarksApi, a as useOpenBookmark, b as useContentTypeNames, m as msg, g as getIcon, c as bookmarkLocation, L as LINK_TARGET } from "./index-
|
|
7
|
+
import { u as useBookmarksApi, a as useOpenBookmark, b as useContentTypeNames, m as msg, g as getIcon, c as bookmarkLocation, L as LINK_TARGET } from "./index-BJ8l6K7P.mjs";
|
|
8
8
|
const PinnedBookmarksWidget = () => {
|
|
9
9
|
const { formatMessage } = useIntl();
|
|
10
10
|
const api = useBookmarksApi();
|
|
@@ -6,7 +6,7 @@ const admin = require("@strapi/strapi/admin");
|
|
|
6
6
|
const react = require("react");
|
|
7
7
|
const reactIntl = require("react-intl");
|
|
8
8
|
const reactRouterDom = require("react-router-dom");
|
|
9
|
-
const index = require("./index-
|
|
9
|
+
const index = require("./index-C9FMo0F_.js");
|
|
10
10
|
const PinnedBookmarksWidget = () => {
|
|
11
11
|
const { formatMessage } = reactIntl.useIntl();
|
|
12
12
|
const api = index.useBookmarksApi();
|
|
@@ -327,6 +327,20 @@ const operatorsForType = (type, isSubField = false) => {
|
|
|
327
327
|
}
|
|
328
328
|
return isSubField ? ops.filter((op) => !LIST_OPERATORS.includes(op) && !RANGE_OPERATORS.includes(op)) : ops;
|
|
329
329
|
};
|
|
330
|
+
const BOOLEAN_VALUES = ["true", "false"];
|
|
331
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
332
|
+
const isDateOnly = (value) => DATE_ONLY.test(value ?? "");
|
|
333
|
+
const datetimeToInput = (value) => {
|
|
334
|
+
const date = new Date(value);
|
|
335
|
+
if (!value.includes("T") || Number.isNaN(date.getTime())) return value;
|
|
336
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
337
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
338
|
+
};
|
|
339
|
+
const inputToDatetime = (value) => {
|
|
340
|
+
if (!value || isDateOnly(value)) return value;
|
|
341
|
+
const date = new Date(value);
|
|
342
|
+
return Number.isNaN(date.getTime()) ? value : date.toISOString();
|
|
343
|
+
};
|
|
330
344
|
const splitList = (value) => value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
331
345
|
const validateRow = (row, fields) => {
|
|
332
346
|
const field = fields.get(row.field);
|
|
@@ -335,6 +349,7 @@ const validateRow = (row, fields) => {
|
|
|
335
349
|
return "operator";
|
|
336
350
|
}
|
|
337
351
|
if (NO_VALUE_OPERATORS.includes(row.operator)) return null;
|
|
352
|
+
if (field.type === "boolean") return BOOLEAN_VALUES.includes(row.value) ? null : "value";
|
|
338
353
|
if (LIST_OPERATORS.includes(row.operator)) return splitList(row.value).length ? null : "value";
|
|
339
354
|
if (!row.value.trim()) return "value";
|
|
340
355
|
if (RANGE_OPERATORS.includes(row.operator) && !(row.valueTo ?? "").trim()) return "valueTo";
|
|
@@ -367,7 +382,7 @@ const filterDepth = (value) => {
|
|
|
367
382
|
return 0;
|
|
368
383
|
};
|
|
369
384
|
const fitsAdminQueryDepth = (filters) => filterDepth(filters) <= ADMIN_QUERY_DEPTH;
|
|
370
|
-
const isPlainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
385
|
+
const isPlainObject$1 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
371
386
|
const SAFE_KEY = /^[A-Za-z_][A-Za-z0-9_]{0,99}$/;
|
|
372
387
|
const OPERATOR = /^\$[A-Za-z]{1,20}$/;
|
|
373
388
|
let rowCounter = 0;
|
|
@@ -376,12 +391,12 @@ const nextRowId = () => {
|
|
|
376
391
|
return `row-${rowCounter}`;
|
|
377
392
|
};
|
|
378
393
|
const entryToRow = (entry) => {
|
|
379
|
-
if (!isPlainObject(entry)) return null;
|
|
394
|
+
if (!isPlainObject$1(entry)) return null;
|
|
380
395
|
const keys = Object.keys(entry);
|
|
381
396
|
if (keys.length !== 1 || !SAFE_KEY.test(keys[0])) return null;
|
|
382
397
|
const head = keys[0];
|
|
383
398
|
const inner = entry[head];
|
|
384
|
-
if (!isPlainObject(inner)) return null;
|
|
399
|
+
if (!isPlainObject$1(inner)) return null;
|
|
385
400
|
const innerKeys = Object.keys(inner);
|
|
386
401
|
if (innerKeys.length !== 1) return null;
|
|
387
402
|
let path = head;
|
|
@@ -389,7 +404,7 @@ const entryToRow = (entry) => {
|
|
|
389
404
|
if (!OPERATOR.test(innerKeys[0])) {
|
|
390
405
|
if (!SAFE_KEY.test(innerKeys[0])) return null;
|
|
391
406
|
const nested = inner[innerKeys[0]];
|
|
392
|
-
if (!isPlainObject(nested) || Object.keys(nested).length !== 1) return null;
|
|
407
|
+
if (!isPlainObject$1(nested) || Object.keys(nested).length !== 1) return null;
|
|
393
408
|
path = `${head}.${innerKeys[0]}`;
|
|
394
409
|
opObject = nested;
|
|
395
410
|
}
|
|
@@ -417,16 +432,16 @@ const parseFilters = (filters) => {
|
|
|
417
432
|
if (filters === void 0 || filters === null || filters === "") {
|
|
418
433
|
return { match: "all", rows: [], unsupported: false };
|
|
419
434
|
}
|
|
420
|
-
if (!isPlainObject(filters)) return { match: "all", rows: [], unsupported: true };
|
|
435
|
+
if (!isPlainObject$1(filters)) return { match: "all", rows: [], unsupported: true };
|
|
421
436
|
const keys = Object.keys(filters);
|
|
422
437
|
if (keys.length !== 1 || !["$and", "$or"].includes(keys[0])) {
|
|
423
438
|
return { match: "all", rows: [], unsupported: true };
|
|
424
439
|
}
|
|
425
440
|
const match = keys[0] === "$or" ? "any" : "all";
|
|
426
441
|
const list = filters[keys[0]];
|
|
427
|
-
const entries = Array.isArray(list) ? list : isPlainObject(list) ? Object.values(list) : [];
|
|
442
|
+
const entries = Array.isArray(list) ? list : isPlainObject$1(list) ? Object.values(list) : [];
|
|
428
443
|
const rows = [];
|
|
429
|
-
let unsupported = !Array.isArray(list) && !isPlainObject(list);
|
|
444
|
+
let unsupported = !Array.isArray(list) && !isPlainObject$1(list);
|
|
430
445
|
for (const entry of entries) {
|
|
431
446
|
const row = entryToRow(entry);
|
|
432
447
|
if (row) rows.push(row);
|
|
@@ -435,11 +450,11 @@ const parseFilters = (filters) => {
|
|
|
435
450
|
return { match, rows, unsupported };
|
|
436
451
|
};
|
|
437
452
|
const countConditions = (filters) => {
|
|
438
|
-
if (!isPlainObject(filters)) return 0;
|
|
453
|
+
if (!isPlainObject$1(filters)) return 0;
|
|
439
454
|
let count = 0;
|
|
440
455
|
for (const [key, value] of Object.entries(filters)) {
|
|
441
456
|
if (key === "$and" || key === "$or") {
|
|
442
|
-
count += Array.isArray(value) ? value.length : isPlainObject(value) ? Object.keys(value).length : 0;
|
|
457
|
+
count += Array.isArray(value) ? value.length : isPlainObject$1(value) ? Object.keys(value).length : 0;
|
|
443
458
|
} else {
|
|
444
459
|
count += 1;
|
|
445
460
|
}
|
|
@@ -501,16 +516,6 @@ const INPUT_TYPES = {
|
|
|
501
516
|
datetime: "datetime-local",
|
|
502
517
|
email: "text"
|
|
503
518
|
};
|
|
504
|
-
const isoToLocalInput = (value) => {
|
|
505
|
-
const date = new Date(value);
|
|
506
|
-
if (!value.includes("T") || Number.isNaN(date.getTime())) return value;
|
|
507
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
508
|
-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
509
|
-
};
|
|
510
|
-
const localInputToIso = (value) => {
|
|
511
|
-
const date = new Date(value);
|
|
512
|
-
return value && !Number.isNaN(date.getTime()) ? date.toISOString() : value;
|
|
513
|
-
};
|
|
514
519
|
const emptyRow = () => ({ id: nextRowId(), field: "", operator: "$eq", value: "" });
|
|
515
520
|
const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
516
521
|
const { formatMessage } = useIntl();
|
|
@@ -522,8 +527,8 @@ const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
|
522
527
|
const [rows, setRows] = useState(
|
|
523
528
|
() => initial.rows.length ? initial.rows.map((row) => ({
|
|
524
529
|
...row,
|
|
525
|
-
value:
|
|
526
|
-
valueTo: row.valueTo &&
|
|
530
|
+
value: datetimeToInput(row.value),
|
|
531
|
+
valueTo: row.valueTo && datetimeToInput(row.valueTo)
|
|
527
532
|
})) : [emptyRow()]
|
|
528
533
|
);
|
|
529
534
|
const [unsupported, setUnsupported] = useState(initial.unsupported);
|
|
@@ -538,8 +543,8 @@ const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
|
538
543
|
const prepared = activeRows.map(
|
|
539
544
|
(row) => fieldMap.get(row.field)?.type === "datetime" ? {
|
|
540
545
|
...row,
|
|
541
|
-
value:
|
|
542
|
-
valueTo: row.valueTo &&
|
|
546
|
+
value: inputToDatetime(row.value),
|
|
547
|
+
valueTo: row.valueTo && inputToDatetime(row.valueTo)
|
|
543
548
|
} : row
|
|
544
549
|
);
|
|
545
550
|
const filters = buildFilters(match, prepared);
|
|
@@ -786,7 +791,8 @@ const ValueInput = ({ row, field, onChange, errorText }) => {
|
|
|
786
791
|
/* @__PURE__ */ jsx(Field.Error, {})
|
|
787
792
|
] });
|
|
788
793
|
}
|
|
789
|
-
const
|
|
794
|
+
const keepsDay = type === "datetime" && !isRange && isDateOnly(row.value);
|
|
795
|
+
const inputType = isList ? "text" : keepsDay ? "date" : INPUT_TYPES[type] ?? "text";
|
|
790
796
|
if (isRange) {
|
|
791
797
|
return /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "flex-start", children: [
|
|
792
798
|
/* @__PURE__ */ jsxs(Field.Root, { name: `from-${row.id}`, error: errorText("value"), flex: 1, minWidth: 0, children: [
|
|
@@ -867,6 +873,76 @@ const useBookmarksApi = () => {
|
|
|
867
873
|
[get, post, put, del]
|
|
868
874
|
);
|
|
869
875
|
};
|
|
876
|
+
const TRUE_VALUES = /* @__PURE__ */ new Set(["true", "t", "1", "yes", "on"]);
|
|
877
|
+
const FALSE_VALUES = /* @__PURE__ */ new Set(["false", "f", "0", "no", "off"]);
|
|
878
|
+
const LOGICAL = /* @__PURE__ */ new Set(["$and", "$or", "$not"]);
|
|
879
|
+
const normalizeBooleanValue = (value) => {
|
|
880
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
881
|
+
if (typeof value === "number") return value === 1 ? "true" : value === 0 ? "false" : null;
|
|
882
|
+
if (typeof value !== "string") return null;
|
|
883
|
+
const text = value.trim().toLowerCase();
|
|
884
|
+
if (TRUE_VALUES.has(text)) return "true";
|
|
885
|
+
if (FALSE_VALUES.has(text)) return "false";
|
|
886
|
+
return null;
|
|
887
|
+
};
|
|
888
|
+
const createAttributeResolver = (init, uid) => {
|
|
889
|
+
const contentTypes = new Map(init.contentTypes.map((ct) => [ct.uid, ct.attributes]));
|
|
890
|
+
const components = new Map(init.components.map((c) => [c.uid, c.attributes]));
|
|
891
|
+
return (path) => {
|
|
892
|
+
let attributes = contentTypes.get(uid);
|
|
893
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
894
|
+
const attribute = attributes?.[path[i]];
|
|
895
|
+
if (!attribute) return void 0;
|
|
896
|
+
if (i === path.length - 1) return attribute;
|
|
897
|
+
if (attribute.type === "relation") {
|
|
898
|
+
attributes = contentTypes.get(attribute.targetModel ?? attribute.target ?? "");
|
|
899
|
+
} else if (attribute.type === "component" && attribute.component) {
|
|
900
|
+
attributes = components.get(attribute.component);
|
|
901
|
+
} else {
|
|
902
|
+
return void 0;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return void 0;
|
|
906
|
+
};
|
|
907
|
+
};
|
|
908
|
+
const isPlainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
909
|
+
const sanitizeBooleanFilters = (filters, resolve) => {
|
|
910
|
+
let normalized = 0;
|
|
911
|
+
let dropped = 0;
|
|
912
|
+
const fixValue = (value) => {
|
|
913
|
+
if (Array.isArray(value)) {
|
|
914
|
+
const list = value.map(fixValue).filter((item) => item !== void 0);
|
|
915
|
+
return list.length ? list : void 0;
|
|
916
|
+
}
|
|
917
|
+
const next = normalizeBooleanValue(value);
|
|
918
|
+
if (next === null) {
|
|
919
|
+
dropped += 1;
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
if (next !== value) normalized += 1;
|
|
923
|
+
return next;
|
|
924
|
+
};
|
|
925
|
+
const walk = (node, path) => {
|
|
926
|
+
if (Array.isArray(node)) {
|
|
927
|
+
const list = node.map((item) => walk(item, path)).filter((item) => item !== void 0);
|
|
928
|
+
return list.length || !node.length ? list : void 0;
|
|
929
|
+
}
|
|
930
|
+
const isBoolean = path.length > 0 && resolve(path)?.type === "boolean";
|
|
931
|
+
if (!isPlainObject(node)) {
|
|
932
|
+
return isBoolean ? fixValue(node) : node;
|
|
933
|
+
}
|
|
934
|
+
const out = {};
|
|
935
|
+
for (const [key, value] of Object.entries(node)) {
|
|
936
|
+
let next;
|
|
937
|
+
if (LOGICAL.has(key)) next = walk(value, path);
|
|
938
|
+
else if (key.startsWith("$")) next = isBoolean ? fixValue(value) : value;
|
|
939
|
+
else next = walk(value, [...path, key]);
|
|
940
|
+
if (next !== void 0) out[key] = next;
|
|
941
|
+
}
|
|
942
|
+
return Object.keys(out).length || !Object.keys(node).length ? out : void 0;
|
|
943
|
+
};
|
|
944
|
+
return { filters: walk(filters, []), normalized, dropped };
|
|
945
|
+
};
|
|
870
946
|
const QS_PARSE_OPTIONS = {
|
|
871
947
|
allowPrototypes: false,
|
|
872
948
|
plainObjects: true,
|
|
@@ -884,15 +960,24 @@ const bookmarkLocation = (bookmark) => {
|
|
|
884
960
|
if (!location) return null;
|
|
885
961
|
return { pathname: location.path, search: bookmark.query ? `?${bookmark.query}` : "" };
|
|
886
962
|
};
|
|
963
|
+
const normalizeSavedQuery = (query, init, uid) => {
|
|
964
|
+
if (query.filters === void 0) return query;
|
|
965
|
+
const result = sanitizeBooleanFilters(query.filters, createAttributeResolver(init, uid));
|
|
966
|
+
if (!result.normalized && !result.dropped) return query;
|
|
967
|
+
const next = { ...query };
|
|
968
|
+
if (result.filters === void 0) delete next.filters;
|
|
969
|
+
else next.filters = result.filters;
|
|
970
|
+
return next;
|
|
971
|
+
};
|
|
887
972
|
const useOpenBookmark = () => {
|
|
888
973
|
const navigate = useNavigate();
|
|
974
|
+
const { get } = useFetchClient();
|
|
889
975
|
const { toggleNotification } = useNotification();
|
|
890
976
|
const { formatMessage } = useIntl();
|
|
891
977
|
return useCallback(
|
|
892
|
-
(bookmark) => {
|
|
893
|
-
const target = bookmarkLocation(bookmark);
|
|
978
|
+
async (bookmark) => {
|
|
894
979
|
const location = parseListViewPath(bookmark.path);
|
|
895
|
-
if (!
|
|
980
|
+
if (!location) {
|
|
896
981
|
toggleNotification({
|
|
897
982
|
type: "danger",
|
|
898
983
|
message: formatMessage(
|
|
@@ -901,13 +986,20 @@ const useOpenBookmark = () => {
|
|
|
901
986
|
});
|
|
902
987
|
return;
|
|
903
988
|
}
|
|
989
|
+
const parsed = parseQuery(bookmark.query);
|
|
990
|
+
let saved = parsed;
|
|
991
|
+
try {
|
|
992
|
+
saved = normalizeSavedQuery(parsed, await loadInit(get), location.uid);
|
|
993
|
+
} catch {
|
|
994
|
+
}
|
|
995
|
+
const search = saved === parsed ? bookmark.query ?? "" : stringifyQuery(saved);
|
|
904
996
|
try {
|
|
905
|
-
syncPersistedListSettings(window.localStorage, location.uid,
|
|
997
|
+
syncPersistedListSettings(window.localStorage, location.uid, saved);
|
|
906
998
|
} catch {
|
|
907
999
|
}
|
|
908
|
-
navigate(
|
|
1000
|
+
navigate({ pathname: location.path, search: search ? `?${search}` : "" });
|
|
909
1001
|
},
|
|
910
|
-
[navigate, toggleNotification, formatMessage]
|
|
1002
|
+
[get, navigate, toggleNotification, formatMessage]
|
|
911
1003
|
);
|
|
912
1004
|
};
|
|
913
1005
|
const errorBody = (error) => error?.response?.data?.error;
|
|
@@ -1703,7 +1795,7 @@ const index = {
|
|
|
1703
1795
|
to: `plugins/${pluginId}`,
|
|
1704
1796
|
icon: PluginIcon,
|
|
1705
1797
|
intlLabel: { id: `${pluginId}.plugin.name`, defaultMessage: "Magic Mark" },
|
|
1706
|
-
Component: () => import("./App-
|
|
1798
|
+
Component: () => import("./App-BIc-2qv8.mjs"),
|
|
1707
1799
|
permissions: PERMISSIONS.read
|
|
1708
1800
|
});
|
|
1709
1801
|
app.registerPlugin({ id: pluginId, name: "Magic Mark" });
|
|
@@ -1718,7 +1810,7 @@ const index = {
|
|
|
1718
1810
|
label: { id: `${pluginId}.widget.link`, defaultMessage: "Manage bookmarks" },
|
|
1719
1811
|
href: `/plugins/${pluginId}`
|
|
1720
1812
|
},
|
|
1721
|
-
component: async () => (await import("./PinnedBookmarksWidget-
|
|
1813
|
+
component: async () => (await import("./PinnedBookmarksWidget-BWiAKlnA.mjs")).default,
|
|
1722
1814
|
permissions: PERMISSIONS.read
|
|
1723
1815
|
});
|
|
1724
1816
|
}
|
|
@@ -330,6 +330,20 @@ const operatorsForType = (type, isSubField = false) => {
|
|
|
330
330
|
}
|
|
331
331
|
return isSubField ? ops.filter((op) => !LIST_OPERATORS.includes(op) && !RANGE_OPERATORS.includes(op)) : ops;
|
|
332
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
|
+
};
|
|
333
347
|
const splitList = (value) => value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
334
348
|
const validateRow = (row, fields) => {
|
|
335
349
|
const field = fields.get(row.field);
|
|
@@ -338,6 +352,7 @@ const validateRow = (row, fields) => {
|
|
|
338
352
|
return "operator";
|
|
339
353
|
}
|
|
340
354
|
if (NO_VALUE_OPERATORS.includes(row.operator)) return null;
|
|
355
|
+
if (field.type === "boolean") return BOOLEAN_VALUES.includes(row.value) ? null : "value";
|
|
341
356
|
if (LIST_OPERATORS.includes(row.operator)) return splitList(row.value).length ? null : "value";
|
|
342
357
|
if (!row.value.trim()) return "value";
|
|
343
358
|
if (RANGE_OPERATORS.includes(row.operator) && !(row.valueTo ?? "").trim()) return "valueTo";
|
|
@@ -370,7 +385,7 @@ const filterDepth = (value) => {
|
|
|
370
385
|
return 0;
|
|
371
386
|
};
|
|
372
387
|
const fitsAdminQueryDepth = (filters) => filterDepth(filters) <= ADMIN_QUERY_DEPTH;
|
|
373
|
-
const isPlainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
388
|
+
const isPlainObject$1 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
374
389
|
const SAFE_KEY = /^[A-Za-z_][A-Za-z0-9_]{0,99}$/;
|
|
375
390
|
const OPERATOR = /^\$[A-Za-z]{1,20}$/;
|
|
376
391
|
let rowCounter = 0;
|
|
@@ -379,12 +394,12 @@ const nextRowId = () => {
|
|
|
379
394
|
return `row-${rowCounter}`;
|
|
380
395
|
};
|
|
381
396
|
const entryToRow = (entry) => {
|
|
382
|
-
if (!isPlainObject(entry)) return null;
|
|
397
|
+
if (!isPlainObject$1(entry)) return null;
|
|
383
398
|
const keys = Object.keys(entry);
|
|
384
399
|
if (keys.length !== 1 || !SAFE_KEY.test(keys[0])) return null;
|
|
385
400
|
const head = keys[0];
|
|
386
401
|
const inner = entry[head];
|
|
387
|
-
if (!isPlainObject(inner)) return null;
|
|
402
|
+
if (!isPlainObject$1(inner)) return null;
|
|
388
403
|
const innerKeys = Object.keys(inner);
|
|
389
404
|
if (innerKeys.length !== 1) return null;
|
|
390
405
|
let path = head;
|
|
@@ -392,7 +407,7 @@ const entryToRow = (entry) => {
|
|
|
392
407
|
if (!OPERATOR.test(innerKeys[0])) {
|
|
393
408
|
if (!SAFE_KEY.test(innerKeys[0])) return null;
|
|
394
409
|
const nested = inner[innerKeys[0]];
|
|
395
|
-
if (!isPlainObject(nested) || Object.keys(nested).length !== 1) return null;
|
|
410
|
+
if (!isPlainObject$1(nested) || Object.keys(nested).length !== 1) return null;
|
|
396
411
|
path = `${head}.${innerKeys[0]}`;
|
|
397
412
|
opObject = nested;
|
|
398
413
|
}
|
|
@@ -420,16 +435,16 @@ const parseFilters = (filters) => {
|
|
|
420
435
|
if (filters === void 0 || filters === null || filters === "") {
|
|
421
436
|
return { match: "all", rows: [], unsupported: false };
|
|
422
437
|
}
|
|
423
|
-
if (!isPlainObject(filters)) return { match: "all", rows: [], unsupported: true };
|
|
438
|
+
if (!isPlainObject$1(filters)) return { match: "all", rows: [], unsupported: true };
|
|
424
439
|
const keys = Object.keys(filters);
|
|
425
440
|
if (keys.length !== 1 || !["$and", "$or"].includes(keys[0])) {
|
|
426
441
|
return { match: "all", rows: [], unsupported: true };
|
|
427
442
|
}
|
|
428
443
|
const match = keys[0] === "$or" ? "any" : "all";
|
|
429
444
|
const list = filters[keys[0]];
|
|
430
|
-
const entries = Array.isArray(list) ? list : isPlainObject(list) ? Object.values(list) : [];
|
|
445
|
+
const entries = Array.isArray(list) ? list : isPlainObject$1(list) ? Object.values(list) : [];
|
|
431
446
|
const rows = [];
|
|
432
|
-
let unsupported = !Array.isArray(list) && !isPlainObject(list);
|
|
447
|
+
let unsupported = !Array.isArray(list) && !isPlainObject$1(list);
|
|
433
448
|
for (const entry of entries) {
|
|
434
449
|
const row = entryToRow(entry);
|
|
435
450
|
if (row) rows.push(row);
|
|
@@ -438,11 +453,11 @@ const parseFilters = (filters) => {
|
|
|
438
453
|
return { match, rows, unsupported };
|
|
439
454
|
};
|
|
440
455
|
const countConditions = (filters) => {
|
|
441
|
-
if (!isPlainObject(filters)) return 0;
|
|
456
|
+
if (!isPlainObject$1(filters)) return 0;
|
|
442
457
|
let count = 0;
|
|
443
458
|
for (const [key, value] of Object.entries(filters)) {
|
|
444
459
|
if (key === "$and" || key === "$or") {
|
|
445
|
-
count += Array.isArray(value) ? value.length : isPlainObject(value) ? Object.keys(value).length : 0;
|
|
460
|
+
count += Array.isArray(value) ? value.length : isPlainObject$1(value) ? Object.keys(value).length : 0;
|
|
446
461
|
} else {
|
|
447
462
|
count += 1;
|
|
448
463
|
}
|
|
@@ -504,16 +519,6 @@ const INPUT_TYPES = {
|
|
|
504
519
|
datetime: "datetime-local",
|
|
505
520
|
email: "text"
|
|
506
521
|
};
|
|
507
|
-
const isoToLocalInput = (value) => {
|
|
508
|
-
const date = new Date(value);
|
|
509
|
-
if (!value.includes("T") || Number.isNaN(date.getTime())) return value;
|
|
510
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
511
|
-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
512
|
-
};
|
|
513
|
-
const localInputToIso = (value) => {
|
|
514
|
-
const date = new Date(value);
|
|
515
|
-
return value && !Number.isNaN(date.getTime()) ? date.toISOString() : value;
|
|
516
|
-
};
|
|
517
522
|
const emptyRow = () => ({ id: nextRowId(), field: "", operator: "$eq", value: "" });
|
|
518
523
|
const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
519
524
|
const { formatMessage } = reactIntl.useIntl();
|
|
@@ -525,8 +530,8 @@ const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
|
525
530
|
const [rows, setRows] = react.useState(
|
|
526
531
|
() => initial.rows.length ? initial.rows.map((row) => ({
|
|
527
532
|
...row,
|
|
528
|
-
value:
|
|
529
|
-
valueTo: row.valueTo &&
|
|
533
|
+
value: datetimeToInput(row.value),
|
|
534
|
+
valueTo: row.valueTo && datetimeToInput(row.valueTo)
|
|
530
535
|
})) : [emptyRow()]
|
|
531
536
|
);
|
|
532
537
|
const [unsupported, setUnsupported] = react.useState(initial.unsupported);
|
|
@@ -541,8 +546,8 @@ const AdvancedFiltersModal = ({ open, onOpenChange, uid }) => {
|
|
|
541
546
|
const prepared = activeRows.map(
|
|
542
547
|
(row) => fieldMap.get(row.field)?.type === "datetime" ? {
|
|
543
548
|
...row,
|
|
544
|
-
value:
|
|
545
|
-
valueTo: row.valueTo &&
|
|
549
|
+
value: inputToDatetime(row.value),
|
|
550
|
+
valueTo: row.valueTo && inputToDatetime(row.valueTo)
|
|
546
551
|
} : row
|
|
547
552
|
);
|
|
548
553
|
const filters = buildFilters(match, prepared);
|
|
@@ -789,7 +794,8 @@ const ValueInput = ({ row, field, onChange, errorText }) => {
|
|
|
789
794
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
790
795
|
] });
|
|
791
796
|
}
|
|
792
|
-
const
|
|
797
|
+
const keepsDay = type === "datetime" && !isRange && isDateOnly(row.value);
|
|
798
|
+
const inputType = isList ? "text" : keepsDay ? "date" : INPUT_TYPES[type] ?? "text";
|
|
793
799
|
if (isRange) {
|
|
794
800
|
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "flex-start", children: [
|
|
795
801
|
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `from-${row.id}`, error: errorText("value"), flex: 1, minWidth: 0, children: [
|
|
@@ -870,6 +876,76 @@ const useBookmarksApi = () => {
|
|
|
870
876
|
[get, post, put, del]
|
|
871
877
|
);
|
|
872
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
|
+
};
|
|
873
949
|
const QS_PARSE_OPTIONS = {
|
|
874
950
|
allowPrototypes: false,
|
|
875
951
|
plainObjects: true,
|
|
@@ -887,15 +963,24 @@ const bookmarkLocation = (bookmark) => {
|
|
|
887
963
|
if (!location) return null;
|
|
888
964
|
return { pathname: location.path, search: bookmark.query ? `?${bookmark.query}` : "" };
|
|
889
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
|
+
};
|
|
890
975
|
const useOpenBookmark = () => {
|
|
891
976
|
const navigate = reactRouterDom.useNavigate();
|
|
977
|
+
const { get } = admin.useFetchClient();
|
|
892
978
|
const { toggleNotification } = admin.useNotification();
|
|
893
979
|
const { formatMessage } = reactIntl.useIntl();
|
|
894
980
|
return react.useCallback(
|
|
895
|
-
(bookmark) => {
|
|
896
|
-
const target = bookmarkLocation(bookmark);
|
|
981
|
+
async (bookmark) => {
|
|
897
982
|
const location = parseListViewPath(bookmark.path);
|
|
898
|
-
if (!
|
|
983
|
+
if (!location) {
|
|
899
984
|
toggleNotification({
|
|
900
985
|
type: "danger",
|
|
901
986
|
message: formatMessage(
|
|
@@ -904,13 +989,20 @@ const useOpenBookmark = () => {
|
|
|
904
989
|
});
|
|
905
990
|
return;
|
|
906
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);
|
|
907
999
|
try {
|
|
908
|
-
syncPersistedListSettings(window.localStorage, location.uid,
|
|
1000
|
+
syncPersistedListSettings(window.localStorage, location.uid, saved);
|
|
909
1001
|
} catch {
|
|
910
1002
|
}
|
|
911
|
-
navigate(
|
|
1003
|
+
navigate({ pathname: location.path, search: search ? `?${search}` : "" });
|
|
912
1004
|
},
|
|
913
|
-
[navigate, toggleNotification, formatMessage]
|
|
1005
|
+
[get, navigate, toggleNotification, formatMessage]
|
|
914
1006
|
);
|
|
915
1007
|
};
|
|
916
1008
|
const errorBody = (error) => error?.response?.data?.error;
|
|
@@ -1706,7 +1798,7 @@ const index = {
|
|
|
1706
1798
|
to: `plugins/${pluginId}`,
|
|
1707
1799
|
icon: PluginIcon,
|
|
1708
1800
|
intlLabel: { id: `${pluginId}.plugin.name`, defaultMessage: "Magic Mark" },
|
|
1709
|
-
Component: () => Promise.resolve().then(() => require("./App-
|
|
1801
|
+
Component: () => Promise.resolve().then(() => require("./App-DxALpMK_.js")),
|
|
1710
1802
|
permissions: PERMISSIONS.read
|
|
1711
1803
|
});
|
|
1712
1804
|
app.registerPlugin({ id: pluginId, name: "Magic Mark" });
|
|
@@ -1721,7 +1813,7 @@ const index = {
|
|
|
1721
1813
|
label: { id: `${pluginId}.widget.link`, defaultMessage: "Manage bookmarks" },
|
|
1722
1814
|
href: `/plugins/${pluginId}`
|
|
1723
1815
|
},
|
|
1724
|
-
component: async () => (await Promise.resolve().then(() => require("./PinnedBookmarksWidget-
|
|
1816
|
+
component: async () => (await Promise.resolve().then(() => require("./PinnedBookmarksWidget-VM6buexr.js"))).default,
|
|
1725
1817
|
permissions: PERMISSIONS.read
|
|
1726
1818
|
});
|
|
1727
1819
|
}
|
package/dist/admin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const index = require("./index-
|
|
3
|
+
const index = require("./index-C9FMo0F_.js");
|
|
4
4
|
require("@strapi/icons");
|
|
5
5
|
exports.default = index.index;
|
package/dist/admin/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-plugin-magic-mark",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Bookmarks for the Strapi 5 Content Manager: save list views with their filters, sort order, search and locale, pin them and share them with roles or admin users.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -78,11 +78,11 @@
|
|
|
78
78
|
"@semantic-release/github": "^12.0.10",
|
|
79
79
|
"@semantic-release/npm": "^13.2.0",
|
|
80
80
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
81
|
-
"@strapi/design-system": "^2.
|
|
82
|
-
"@strapi/icons": "^2.
|
|
81
|
+
"@strapi/design-system": "^2.3.1",
|
|
82
|
+
"@strapi/icons": "^2.3.1",
|
|
83
83
|
"@strapi/sdk-plugin": "^6.1.1",
|
|
84
|
-
"@strapi/strapi": "5.
|
|
85
|
-
"@strapi/typescript-utils": "5.
|
|
84
|
+
"@strapi/strapi": "^5.62.0",
|
|
85
|
+
"@strapi/typescript-utils": "^5.62.0",
|
|
86
86
|
"@types/qs": "^6.15.1",
|
|
87
87
|
"@types/react": "^18.3.31",
|
|
88
88
|
"@types/react-dom": "^18.3.7",
|