swoop-common 2.2.174 → 2.2.176

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.
@@ -6,4 +6,5 @@ export type Trip = {
6
6
  alias?: string | null;
7
7
  publishState?: (PublishState | null);
8
8
  partner?: string | null;
9
+ websiteUrl?: string | null;
9
10
  };
@@ -7,4 +7,5 @@ export type Trip_jsonld = (HydraItemBaseSchema & {
7
7
  alias?: string | null;
8
8
  publishState?: (PublishState_jsonld | null);
9
9
  partner?: string | null;
10
+ websiteUrl?: string | null;
10
11
  });
@@ -6,6 +6,7 @@ import "../../renderers/Debug";
6
6
  import "../../renderers/Example";
7
7
  import "../../renderers/Image/ImageForm";
8
8
  import "../../renderers/Image/ImagePresentation";
9
+ import "../../renderers/NestedObjectArray";
9
10
  import "../../renderers/StagedText";
10
11
  import "../../renderers/Subset";
11
12
  import "../../renderers/TemplatePicker";
@@ -8,6 +8,7 @@ import "../../renderers/Debug";
8
8
  import "../../renderers/Example";
9
9
  import "../../renderers/Image/ImageForm";
10
10
  import "../../renderers/Image/ImagePresentation";
11
+ import "../../renderers/NestedObjectArray";
11
12
  import "../../renderers/StagedText";
12
13
  import "../../renderers/Subset";
13
14
  import "../../renderers/TemplatePicker";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import { resolveSchema } from "@jsonforms/core";
2
+ import { JsonForms } from "@jsonforms/react";
3
+ import { materialCells, materialRenderers } from "@jsonforms/material-renderers";
4
+ import React, { useState } from "react";
5
+ import { Accordion, AccordionDetails, AccordionSummary, Box, Button, IconButton, Typography } from "@mui/material";
6
+ import AddIcon from "@mui/icons-material/Add";
7
+ import DeleteIcon from "@mui/icons-material/Delete";
8
+ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
9
+ import { ComponentPool } from "../registry/types";
10
+ import { getComponents, registerComponent } from "../registry/components";
11
+ const hasNestedArray = (schema) => {
12
+ if (schema.type !== "array")
13
+ return false;
14
+ const items = schema.items;
15
+ if (!items || items.type !== "object")
16
+ return false;
17
+ const props = items.properties;
18
+ if (!props)
19
+ return false;
20
+ return Object.values(props).some((p) => p.type === "array");
21
+ };
22
+ // Rank 5 — beats materialArrayLayout (rank 4), only fires on arrays of objects
23
+ // that contain at least one nested array property.
24
+ const nestedObjectArrayTester = (uischema, schema) => {
25
+ const ui = uischema;
26
+ if (!ui.scope)
27
+ return -1;
28
+ const scoped = resolveSchema(schema, ui.scope, schema);
29
+ if (!scoped)
30
+ return -1;
31
+ if (!hasNestedArray(scoped))
32
+ return -1;
33
+ return 5;
34
+ };
35
+ const getItemLabel = (item, index) => (item === null || item === void 0 ? void 0 : item.title) ||
36
+ (item === null || item === void 0 ? void 0 : item.name) ||
37
+ (item === null || item === void 0 ? void 0 : item.label) ||
38
+ `Item ${index + 1}`;
39
+ const NestedObjectArrayRenderer = ({ data, handleChange, path, schema, label, enabled }) => {
40
+ const items = Array.isArray(data) ? data : [];
41
+ const itemSchema = schema.items;
42
+ const [expanded, setExpanded] = useState(false);
43
+ const renderers = [...materialRenderers, ...getComponents(ComponentPool.FORM)];
44
+ const handleItemChange = (index, newData) => {
45
+ const next = [...items];
46
+ next[index] = newData;
47
+ handleChange(path, next);
48
+ };
49
+ const addItem = () => {
50
+ handleChange(path, [...items, {}]);
51
+ setExpanded(items.length);
52
+ };
53
+ const removeItem = (e, index) => {
54
+ e.stopPropagation();
55
+ const next = items.filter((_, i) => i !== index);
56
+ handleChange(path, next);
57
+ setExpanded(false);
58
+ };
59
+ return (React.createElement(Box, null,
60
+ label && (React.createElement(Typography, { variant: "subtitle2", sx: { mb: 1 } }, label)),
61
+ items.map((item, index) => (React.createElement(Accordion, { key: index, expanded: expanded === index, onChange: (_, isExpanded) => setExpanded(isExpanded ? index : false), sx: { mb: 1 } },
62
+ React.createElement(AccordionSummary, { expandIcon: React.createElement(ExpandMoreIcon, null) },
63
+ React.createElement(Box, { sx: {
64
+ display: "flex",
65
+ alignItems: "center",
66
+ width: "100%",
67
+ gap: 1
68
+ } },
69
+ React.createElement(Typography, { sx: { flex: 1 } }, getItemLabel(item, index)),
70
+ enabled && (React.createElement(IconButton, { size: "small", color: "error", onClick: (e) => removeItem(e, index), "aria-label": "Remove item" },
71
+ React.createElement(DeleteIcon, { fontSize: "small" }))))),
72
+ React.createElement(AccordionDetails, null,
73
+ React.createElement(JsonForms, { schema: itemSchema, data: item, onChange: ({ data: newData }) => handleItemChange(index, newData), renderers: renderers, cells: materialCells, readonly: !enabled }))))),
74
+ enabled && (React.createElement(Button, { size: "small", variant: "outlined", startIcon: React.createElement(AddIcon, null), onClick: addItem, sx: { mt: 1 } },
75
+ "Add ", label !== null && label !== void 0 ? label : "Item"))));
76
+ };
77
+ registerComponent("nested-object-array", NestedObjectArrayRenderer, ComponentPool.FORM, nestedObjectArrayTester);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "2.2.174",
3
+ "version": "2.2.176",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {