@geekron/strapi 0.2.4 → 0.2.5
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/dist/admin/index.js +46 -7
- package/dist/admin/index.mjs +46 -7
- package/dist/server/index.js +10 -0
- package/dist/server/index.mjs +10 -0
- package/package.json +1 -1
package/dist/admin/index.js
CHANGED
|
@@ -46738,7 +46738,7 @@ function getMinDepth(nextItem) {
|
|
|
46738
46738
|
}
|
|
46739
46739
|
return 0;
|
|
46740
46740
|
}
|
|
46741
|
-
function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
46741
|
+
function getProjection(items, activeId, overId, dragOffset, indentationWidth, configMaxDepth) {
|
|
46742
46742
|
const overItemIndex = items.findIndex(({ id }) => id === overId);
|
|
46743
46743
|
const activeItemIndex = items.findIndex(({ id }) => id === activeId);
|
|
46744
46744
|
const activeItem = items[activeItemIndex];
|
|
@@ -46750,8 +46750,11 @@ function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
|
46750
46750
|
const nextItem = newItems[overItemIndex + 1];
|
|
46751
46751
|
const dragDepth = getDragDepth(dragOffset, indentationWidth);
|
|
46752
46752
|
const projectedDepth = activeItem.depth + dragDepth;
|
|
46753
|
-
|
|
46753
|
+
let maxDepth = getMaxDepth(previousItem);
|
|
46754
46754
|
const minDepth = getMinDepth(nextItem);
|
|
46755
|
+
if (configMaxDepth !== undefined && maxDepth >= configMaxDepth) {
|
|
46756
|
+
maxDepth = configMaxDepth - 1;
|
|
46757
|
+
}
|
|
46755
46758
|
let depth = projectedDepth;
|
|
46756
46759
|
if (projectedDepth >= maxDepth) {
|
|
46757
46760
|
depth = maxDepth;
|
|
@@ -47214,7 +47217,7 @@ var adjustTranslate = ({ transform }) => {
|
|
|
47214
47217
|
};
|
|
47215
47218
|
// admin/src/fields/DataNested/hooks/useTreeItems.ts
|
|
47216
47219
|
var import_react7 = require("react");
|
|
47217
|
-
function useTreeItems(defaultItems) {
|
|
47220
|
+
function useTreeItems(defaultItems, maxDepth) {
|
|
47218
47221
|
const [items, setItems] = import_react7.useState(() => defaultItems);
|
|
47219
47222
|
const [modalState, setModalState] = import_react7.useState({
|
|
47220
47223
|
isOpen: false,
|
|
@@ -47245,6 +47248,12 @@ function useTreeItems(defaultItems) {
|
|
|
47245
47248
|
});
|
|
47246
47249
|
};
|
|
47247
47250
|
const handleAddChild = (id) => {
|
|
47251
|
+
if (maxDepth !== undefined) {
|
|
47252
|
+
const itemDepth = getItemDepth(items, id);
|
|
47253
|
+
if (itemDepth >= maxDepth - 1) {
|
|
47254
|
+
return;
|
|
47255
|
+
}
|
|
47256
|
+
}
|
|
47248
47257
|
setModalState({
|
|
47249
47258
|
isOpen: true,
|
|
47250
47259
|
mode: "add",
|
|
@@ -47327,6 +47336,21 @@ function findItemDeep2(items, itemId) {
|
|
|
47327
47336
|
}
|
|
47328
47337
|
return;
|
|
47329
47338
|
}
|
|
47339
|
+
function getItemDepth(items, itemId, depth = 0) {
|
|
47340
|
+
for (const item of items) {
|
|
47341
|
+
const { id, children } = item;
|
|
47342
|
+
if (id === itemId) {
|
|
47343
|
+
return depth;
|
|
47344
|
+
}
|
|
47345
|
+
if (children.length) {
|
|
47346
|
+
const childDepth = getItemDepth(children, itemId, depth + 1);
|
|
47347
|
+
if (childDepth !== -1) {
|
|
47348
|
+
return childDepth;
|
|
47349
|
+
}
|
|
47350
|
+
}
|
|
47351
|
+
}
|
|
47352
|
+
return -1;
|
|
47353
|
+
}
|
|
47330
47354
|
// admin/src/fields/DataNested/keyboardCoordinates.ts
|
|
47331
47355
|
var import_core = __toESM(require_dist3(), 1);
|
|
47332
47356
|
|
|
@@ -47499,6 +47523,7 @@ function SortableTree({
|
|
|
47499
47523
|
indicator = false,
|
|
47500
47524
|
indentationWidth = DEFAULT_INDENTATION_WIDTH,
|
|
47501
47525
|
removable,
|
|
47526
|
+
maxDepth,
|
|
47502
47527
|
onChange
|
|
47503
47528
|
}) {
|
|
47504
47529
|
const {
|
|
@@ -47514,7 +47539,7 @@ function SortableTree({
|
|
|
47514
47539
|
handleModalClose,
|
|
47515
47540
|
handleModalSubmit,
|
|
47516
47541
|
getInitialData
|
|
47517
|
-
} = useTreeItems(defaultItems);
|
|
47542
|
+
} = useTreeItems(defaultItems, maxDepth);
|
|
47518
47543
|
const [activeId, setActiveId] = import_react8.useState(null);
|
|
47519
47544
|
const flattenedItems = import_react8.useMemo(() => {
|
|
47520
47545
|
const flattenedTree = flattenTree(items);
|
|
@@ -47534,7 +47559,7 @@ function SortableTree({
|
|
|
47534
47559
|
handleDragOver,
|
|
47535
47560
|
handleDragCancel
|
|
47536
47561
|
} = useDragState(flattenedItems, setActiveId);
|
|
47537
|
-
const projected = activeId && overId ? getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth) : null;
|
|
47562
|
+
const projected = activeId && overId ? getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth, maxDepth) : null;
|
|
47538
47563
|
const sensorContext = import_react8.useRef({
|
|
47539
47564
|
items: flattenedItems,
|
|
47540
47565
|
offset: offsetLeft
|
|
@@ -47614,7 +47639,7 @@ function SortableTree({
|
|
|
47614
47639
|
collapsed: Boolean(collapsed && children.length),
|
|
47615
47640
|
onCollapse: collapsible && children.length ? () => handleCollapse(id) : undefined,
|
|
47616
47641
|
onAddSibling: () => handleAddSibling(id),
|
|
47617
|
-
onAddChild: () => handleAddChild(id),
|
|
47642
|
+
onAddChild: maxDepth !== undefined && depth >= maxDepth - 1 ? undefined : () => handleAddChild(id),
|
|
47618
47643
|
onEdit: () => handleEdit(id),
|
|
47619
47644
|
onRemove: removable ? () => handleRemove(id) : undefined
|
|
47620
47645
|
}, id, false, undefined, this)),
|
|
@@ -47650,7 +47675,8 @@ var DataNested = ({
|
|
|
47650
47675
|
name,
|
|
47651
47676
|
label,
|
|
47652
47677
|
hint,
|
|
47653
|
-
required
|
|
47678
|
+
required,
|
|
47679
|
+
attribute
|
|
47654
47680
|
}) => {
|
|
47655
47681
|
const field = import_admin3.useField(name);
|
|
47656
47682
|
const handleChange = (value) => {
|
|
@@ -47671,6 +47697,7 @@ var DataNested = ({
|
|
|
47671
47697
|
indicator: true,
|
|
47672
47698
|
removable: true,
|
|
47673
47699
|
defaultItems: field.value || [],
|
|
47700
|
+
maxDepth: attribute.options?.depth,
|
|
47674
47701
|
onChange: handleChange
|
|
47675
47702
|
}, undefined, false, undefined, this),
|
|
47676
47703
|
/* @__PURE__ */ jsx_dev_runtime23.jsxDEV(import_design_system5.Field.Hint, {}, undefined, false, undefined, this),
|
|
@@ -47708,6 +47735,18 @@ var registerDataNested = (app) => {
|
|
|
47708
47735
|
id: "form.attribute.item.requiredField.description",
|
|
47709
47736
|
defaultMessage: "Cannot create entry if empty"
|
|
47710
47737
|
}
|
|
47738
|
+
},
|
|
47739
|
+
{
|
|
47740
|
+
name: "options.depth",
|
|
47741
|
+
type: "number",
|
|
47742
|
+
intlLabel: {
|
|
47743
|
+
id: `${pluginId}.fields.dataNested.options.depthField.label`,
|
|
47744
|
+
defaultMessage: "Nested max depth"
|
|
47745
|
+
},
|
|
47746
|
+
description: {
|
|
47747
|
+
id: `${pluginId}.fields.dataNested.options.depthField.description`,
|
|
47748
|
+
defaultMessage: "Maximum depth of nested items"
|
|
47749
|
+
}
|
|
47711
47750
|
}
|
|
47712
47751
|
]
|
|
47713
47752
|
}
|
package/dist/admin/index.mjs
CHANGED
|
@@ -46783,7 +46783,7 @@ function getMinDepth(nextItem) {
|
|
|
46783
46783
|
}
|
|
46784
46784
|
return 0;
|
|
46785
46785
|
}
|
|
46786
|
-
function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
46786
|
+
function getProjection(items, activeId, overId, dragOffset, indentationWidth, configMaxDepth) {
|
|
46787
46787
|
const overItemIndex = items.findIndex(({ id }) => id === overId);
|
|
46788
46788
|
const activeItemIndex = items.findIndex(({ id }) => id === activeId);
|
|
46789
46789
|
const activeItem = items[activeItemIndex];
|
|
@@ -46795,8 +46795,11 @@ function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
|
46795
46795
|
const nextItem = newItems[overItemIndex + 1];
|
|
46796
46796
|
const dragDepth = getDragDepth(dragOffset, indentationWidth);
|
|
46797
46797
|
const projectedDepth = activeItem.depth + dragDepth;
|
|
46798
|
-
|
|
46798
|
+
let maxDepth = getMaxDepth(previousItem);
|
|
46799
46799
|
const minDepth = getMinDepth(nextItem);
|
|
46800
|
+
if (configMaxDepth !== undefined && maxDepth >= configMaxDepth) {
|
|
46801
|
+
maxDepth = configMaxDepth - 1;
|
|
46802
|
+
}
|
|
46800
46803
|
let depth = projectedDepth;
|
|
46801
46804
|
if (projectedDepth >= maxDepth) {
|
|
46802
46805
|
depth = maxDepth;
|
|
@@ -47259,7 +47262,7 @@ var adjustTranslate = ({ transform }) => {
|
|
|
47259
47262
|
};
|
|
47260
47263
|
// admin/src/fields/DataNested/hooks/useTreeItems.ts
|
|
47261
47264
|
import { useState as useState6 } from "react";
|
|
47262
|
-
function useTreeItems(defaultItems) {
|
|
47265
|
+
function useTreeItems(defaultItems, maxDepth) {
|
|
47263
47266
|
const [items, setItems] = useState6(() => defaultItems);
|
|
47264
47267
|
const [modalState, setModalState] = useState6({
|
|
47265
47268
|
isOpen: false,
|
|
@@ -47290,6 +47293,12 @@ function useTreeItems(defaultItems) {
|
|
|
47290
47293
|
});
|
|
47291
47294
|
};
|
|
47292
47295
|
const handleAddChild = (id) => {
|
|
47296
|
+
if (maxDepth !== undefined) {
|
|
47297
|
+
const itemDepth = getItemDepth(items, id);
|
|
47298
|
+
if (itemDepth >= maxDepth - 1) {
|
|
47299
|
+
return;
|
|
47300
|
+
}
|
|
47301
|
+
}
|
|
47293
47302
|
setModalState({
|
|
47294
47303
|
isOpen: true,
|
|
47295
47304
|
mode: "add",
|
|
@@ -47372,6 +47381,21 @@ function findItemDeep2(items, itemId) {
|
|
|
47372
47381
|
}
|
|
47373
47382
|
return;
|
|
47374
47383
|
}
|
|
47384
|
+
function getItemDepth(items, itemId, depth = 0) {
|
|
47385
|
+
for (const item of items) {
|
|
47386
|
+
const { id, children } = item;
|
|
47387
|
+
if (id === itemId) {
|
|
47388
|
+
return depth;
|
|
47389
|
+
}
|
|
47390
|
+
if (children.length) {
|
|
47391
|
+
const childDepth = getItemDepth(children, itemId, depth + 1);
|
|
47392
|
+
if (childDepth !== -1) {
|
|
47393
|
+
return childDepth;
|
|
47394
|
+
}
|
|
47395
|
+
}
|
|
47396
|
+
}
|
|
47397
|
+
return -1;
|
|
47398
|
+
}
|
|
47375
47399
|
// admin/src/fields/DataNested/keyboardCoordinates.ts
|
|
47376
47400
|
var import_core = __toESM(require_dist3(), 1);
|
|
47377
47401
|
|
|
@@ -47544,6 +47568,7 @@ function SortableTree({
|
|
|
47544
47568
|
indicator = false,
|
|
47545
47569
|
indentationWidth = DEFAULT_INDENTATION_WIDTH,
|
|
47546
47570
|
removable,
|
|
47571
|
+
maxDepth,
|
|
47547
47572
|
onChange
|
|
47548
47573
|
}) {
|
|
47549
47574
|
const {
|
|
@@ -47559,7 +47584,7 @@ function SortableTree({
|
|
|
47559
47584
|
handleModalClose,
|
|
47560
47585
|
handleModalSubmit,
|
|
47561
47586
|
getInitialData
|
|
47562
|
-
} = useTreeItems(defaultItems);
|
|
47587
|
+
} = useTreeItems(defaultItems, maxDepth);
|
|
47563
47588
|
const [activeId, setActiveId] = useState7(null);
|
|
47564
47589
|
const flattenedItems = useMemo3(() => {
|
|
47565
47590
|
const flattenedTree = flattenTree(items);
|
|
@@ -47579,7 +47604,7 @@ function SortableTree({
|
|
|
47579
47604
|
handleDragOver,
|
|
47580
47605
|
handleDragCancel
|
|
47581
47606
|
} = useDragState(flattenedItems, setActiveId);
|
|
47582
|
-
const projected = activeId && overId ? getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth) : null;
|
|
47607
|
+
const projected = activeId && overId ? getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth, maxDepth) : null;
|
|
47583
47608
|
const sensorContext = useRef2({
|
|
47584
47609
|
items: flattenedItems,
|
|
47585
47610
|
offset: offsetLeft
|
|
@@ -47659,7 +47684,7 @@ function SortableTree({
|
|
|
47659
47684
|
collapsed: Boolean(collapsed && children.length),
|
|
47660
47685
|
onCollapse: collapsible && children.length ? () => handleCollapse(id) : undefined,
|
|
47661
47686
|
onAddSibling: () => handleAddSibling(id),
|
|
47662
|
-
onAddChild: () => handleAddChild(id),
|
|
47687
|
+
onAddChild: maxDepth !== undefined && depth >= maxDepth - 1 ? undefined : () => handleAddChild(id),
|
|
47663
47688
|
onEdit: () => handleEdit(id),
|
|
47664
47689
|
onRemove: removable ? () => handleRemove(id) : undefined
|
|
47665
47690
|
}, id, false, undefined, this)),
|
|
@@ -47695,7 +47720,8 @@ var DataNested = ({
|
|
|
47695
47720
|
name,
|
|
47696
47721
|
label,
|
|
47697
47722
|
hint,
|
|
47698
|
-
required
|
|
47723
|
+
required,
|
|
47724
|
+
attribute
|
|
47699
47725
|
}) => {
|
|
47700
47726
|
const field = useField2(name);
|
|
47701
47727
|
const handleChange = (value) => {
|
|
@@ -47716,6 +47742,7 @@ var DataNested = ({
|
|
|
47716
47742
|
indicator: true,
|
|
47717
47743
|
removable: true,
|
|
47718
47744
|
defaultItems: field.value || [],
|
|
47745
|
+
maxDepth: attribute.options?.depth,
|
|
47719
47746
|
onChange: handleChange
|
|
47720
47747
|
}, undefined, false, undefined, this),
|
|
47721
47748
|
/* @__PURE__ */ jsxDEV23(Field2.Hint, {}, undefined, false, undefined, this),
|
|
@@ -47753,6 +47780,18 @@ var registerDataNested = (app) => {
|
|
|
47753
47780
|
id: "form.attribute.item.requiredField.description",
|
|
47754
47781
|
defaultMessage: "Cannot create entry if empty"
|
|
47755
47782
|
}
|
|
47783
|
+
},
|
|
47784
|
+
{
|
|
47785
|
+
name: "options.depth",
|
|
47786
|
+
type: "number",
|
|
47787
|
+
intlLabel: {
|
|
47788
|
+
id: `${pluginId}.fields.dataNested.options.depthField.label`,
|
|
47789
|
+
defaultMessage: "Nested max depth"
|
|
47790
|
+
},
|
|
47791
|
+
description: {
|
|
47792
|
+
id: `${pluginId}.fields.dataNested.options.depthField.description`,
|
|
47793
|
+
defaultMessage: "Maximum depth of nested items"
|
|
47794
|
+
}
|
|
47756
47795
|
}
|
|
47757
47796
|
]
|
|
47758
47797
|
}
|
package/dist/server/index.js
CHANGED
package/dist/server/index.mjs
CHANGED