@geekron/strapi 0.2.3 → 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.
@@ -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
- const maxDepth = getMaxDepth(previousItem);
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
  }
@@ -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
- const maxDepth = getMaxDepth(previousItem);
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
  }
@@ -86,6 +86,16 @@ var schema_default = {
86
86
  localized: true
87
87
  }
88
88
  }
89
+ },
90
+ socials: {
91
+ type: "component",
92
+ pluginOptions: {
93
+ i18n: {
94
+ localized: true
95
+ }
96
+ },
97
+ component: "site.social",
98
+ repeatable: true
89
99
  }
90
100
  }
91
101
  };
@@ -710,90 +720,9 @@ var destroy = ({ strapi: strapi2 }) => {
710
720
  strapi2.log.info("dashboard server plugin: bootstrap");
711
721
  };
712
722
  var destroy_default = destroy;
713
- // server/src/components/schema/banner.json
714
- var banner_default = {
715
- collectionName: "components_website_banners",
716
- info: {
717
- displayName: "Banner",
718
- icon: "landscape"
719
- },
720
- options: {},
721
- attributes: {
722
- title: {
723
- type: "string"
724
- },
725
- subtitle: {
726
- type: "string"
727
- },
728
- description: {
729
- type: "string"
730
- },
731
- image: {
732
- type: "component",
733
- component: "base.image",
734
- repeatable: false
735
- }
736
- }
737
- };
738
- // server/src/components/schema/social.json
739
- var social_default = {
740
- collectionName: "components_website_socials",
741
- info: {
742
- displayName: "Social",
743
- icon: "paperPlane"
744
- },
745
- options: {},
746
- attributes: {
747
- type: {
748
- type: "enumeration",
749
- enum: [
750
- "url",
751
- "qrcode"
752
- ]
753
- },
754
- url: {
755
- type: "string",
756
- conditions: {
757
- visible: {
758
- "==": [
759
- {
760
- var: "type"
761
- },
762
- "url"
763
- ]
764
- }
765
- }
766
- },
767
- icon: {
768
- type: "customField",
769
- customField: "plugin::website.iconPicker"
770
- },
771
- color: {
772
- type: "customField",
773
- customField: "plugin::website.colorPicker"
774
- },
775
- qrcode: {
776
- type: "media",
777
- conditions: {
778
- visible: {
779
- "==": [
780
- {
781
- var: "type"
782
- },
783
- "qrcode"
784
- ]
785
- }
786
- },
787
- multiple: false,
788
- allowedTypes: [
789
- "images"
790
- ]
791
- }
792
- }
793
- };
794
723
 
795
724
  // server/src/components/index.ts
796
- var schemas = { banner: banner_default, social: social_default };
725
+ var schemas = {};
797
726
  var createComponent = (strapi2, { name, displayName, icon, attributes }) => {
798
727
  const category = "website";
799
728
  if (strapi2.components[`${category}.${name}`])
@@ -51,6 +51,16 @@ var schema_default = {
51
51
  localized: true
52
52
  }
53
53
  }
54
+ },
55
+ socials: {
56
+ type: "component",
57
+ pluginOptions: {
58
+ i18n: {
59
+ localized: true
60
+ }
61
+ },
62
+ component: "site.social",
63
+ repeatable: true
54
64
  }
55
65
  }
56
66
  };
@@ -675,90 +685,9 @@ var destroy = ({ strapi: strapi2 }) => {
675
685
  strapi2.log.info("dashboard server plugin: bootstrap");
676
686
  };
677
687
  var destroy_default = destroy;
678
- // server/src/components/schema/banner.json
679
- var banner_default = {
680
- collectionName: "components_website_banners",
681
- info: {
682
- displayName: "Banner",
683
- icon: "landscape"
684
- },
685
- options: {},
686
- attributes: {
687
- title: {
688
- type: "string"
689
- },
690
- subtitle: {
691
- type: "string"
692
- },
693
- description: {
694
- type: "string"
695
- },
696
- image: {
697
- type: "component",
698
- component: "base.image",
699
- repeatable: false
700
- }
701
- }
702
- };
703
- // server/src/components/schema/social.json
704
- var social_default = {
705
- collectionName: "components_website_socials",
706
- info: {
707
- displayName: "Social",
708
- icon: "paperPlane"
709
- },
710
- options: {},
711
- attributes: {
712
- type: {
713
- type: "enumeration",
714
- enum: [
715
- "url",
716
- "qrcode"
717
- ]
718
- },
719
- url: {
720
- type: "string",
721
- conditions: {
722
- visible: {
723
- "==": [
724
- {
725
- var: "type"
726
- },
727
- "url"
728
- ]
729
- }
730
- }
731
- },
732
- icon: {
733
- type: "customField",
734
- customField: "plugin::website.iconPicker"
735
- },
736
- color: {
737
- type: "customField",
738
- customField: "plugin::website.colorPicker"
739
- },
740
- qrcode: {
741
- type: "media",
742
- conditions: {
743
- visible: {
744
- "==": [
745
- {
746
- var: "type"
747
- },
748
- "qrcode"
749
- ]
750
- }
751
- },
752
- multiple: false,
753
- allowedTypes: [
754
- "images"
755
- ]
756
- }
757
- }
758
- };
759
688
 
760
689
  // server/src/components/index.ts
761
- var schemas = { banner: banner_default, social: social_default };
690
+ var schemas = {};
762
691
  var createComponent = (strapi2, { name, displayName, icon, attributes }) => {
763
692
  const category = "website";
764
693
  if (strapi2.components[`${category}.${name}`])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekron/strapi",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "极客领航网站管理插件",
5
5
  "type": "commonjs",
6
6
  "author": "Geekron",