swoop-common 2.2.100 → 2.2.102

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.
@@ -9,36 +9,90 @@ import { initialisedCheck } from "../../api/init";
9
9
  import ComponentContext from "../contexts/ComponentContext";
10
10
  export const StyledFormView = ({ initialData, schema, onChange, stage, pool, readonly, hideReadonlyFields, hintComponentId, overrideJsonSchema, overrideUiSchema, }) => {
11
11
  useEffect(initialisedCheck, []);
12
+ const wrapperRef = React.useRef(null);
12
13
  const json = overrideJsonSchema || generateJsonSchema(schema, stage, hideReadonlyFields);
13
14
  const ui = overrideUiSchema || generateUiSchema(schema, stage, hideReadonlyFields);
15
+ useEffect(() => {
16
+ const root = wrapperRef.current;
17
+ if (!root)
18
+ return;
19
+ const syncArrayColumnLabels = () => {
20
+ const tables = root.querySelectorAll(".MuiTable-root");
21
+ tables.forEach((table) => {
22
+ table.removeAttribute("data-jsonforms-two-col-array");
23
+ const existingLabels = table.querySelectorAll(":scope > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root[data-column-label]");
24
+ existingLabels.forEach((cell) => cell.removeAttribute("data-column-label"));
25
+ });
26
+ tables.forEach((table) => {
27
+ const hasToolbar = Boolean(table.querySelector(":scope > .MuiTableHead-root > .MuiToolbar-root"));
28
+ if (!hasToolbar)
29
+ return;
30
+ const headerCells = table.querySelectorAll(":scope > .MuiTableHead-root > .MuiTableRow-root:last-child > .MuiTableCell-root");
31
+ if (headerCells.length === 0)
32
+ return;
33
+ const labels = Array.from(headerCells)
34
+ .map((cell) => { var _a, _b; return (_b = (_a = cell.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ""; })
35
+ .filter((label) => label.length > 0);
36
+ if (labels.length === 0)
37
+ return;
38
+ table.setAttribute("data-jsonforms-two-col-array", "true");
39
+ const bodyRows = table.querySelectorAll(":scope > .MuiTableBody-root > .MuiTableRow-root");
40
+ bodyRows.forEach((row) => {
41
+ const bodyCells = row.querySelectorAll(":scope > .MuiTableCell-root");
42
+ bodyCells.forEach((cell, index) => {
43
+ if (index < labels.length) {
44
+ cell.setAttribute("data-column-label", labels[index]);
45
+ }
46
+ else {
47
+ cell.removeAttribute("data-column-label");
48
+ }
49
+ });
50
+ });
51
+ });
52
+ };
53
+ syncArrayColumnLabels();
54
+ const observer = new MutationObserver(syncArrayColumnLabels);
55
+ observer.observe(root, { childList: true, subtree: true });
56
+ return () => observer.disconnect();
57
+ }, [json, ui]);
14
58
  return (React.createElement(ComponentContext, { componentId: hintComponentId, stage: stage },
15
59
  React.createElement(GlobalStyles, { styles: {
16
- ".json-forms-wrapper .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root, .json-forms-wrapper .MuiTable-root > .MuiTableHead-root > .MuiTableRow-root:last-child": {
60
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableBody-root > .MuiTableRow-root": {
17
61
  display: "grid",
18
62
  gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
19
63
  columnGap: "24px",
20
64
  rowGap: "12px",
21
65
  alignItems: "start",
66
+ position: "relative",
67
+ paddingRight: "52px",
22
68
  },
23
- ".json-forms-wrapper .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root, .json-forms-wrapper .MuiTable-root > .MuiTableHead-root > .MuiTableRow-root:last-child > .MuiTableCell-root": {
69
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root": {
24
70
  minWidth: 0,
25
71
  width: "100%",
26
- paddingLeft: 0,
27
- paddingRight: 0,
72
+ padding: 0,
28
73
  },
29
- ".json-forms-wrapper .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root:only-child": {
74
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root[data-column-label]::before": {
75
+ content: "attr(data-column-label)",
76
+ display: "block",
77
+ marginBottom: "8px",
78
+ fontWeight: 600,
79
+ },
80
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root:only-child": {
30
81
  gridColumn: "1 / -1",
31
82
  },
32
- ".json-forms-wrapper .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root:last-child": {
33
- gridColumn: "2",
34
- justifySelf: "end",
35
- width: "fit-content",
83
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root:last-child": {
84
+ position: "absolute",
85
+ right: 0,
86
+ top: "50%",
87
+ transform: "translateY(-50%)",
88
+ width: "auto",
89
+ padding: 0,
36
90
  },
37
- ".json-forms-wrapper .MuiTable-root > .MuiTableHead-root > .MuiTableRow-root:last-child > .MuiTableCell-root:last-child": {
91
+ ".json-forms-wrapper .MuiTable-root[data-jsonforms-two-col-array='true'] > .MuiTableHead-root > .MuiTableRow-root:last-child": {
38
92
  display: "none",
39
93
  },
40
94
  } }),
41
- React.createElement("div", { className: "json-forms-wrapper" },
95
+ React.createElement("div", { className: "json-forms-wrapper", ref: wrapperRef },
42
96
  React.createElement(JsonForms, { onChange: onChange, data: initialData, schema: json, uischema: ui, renderers: [
43
97
  ...materialRenderers,
44
98
  ...((pool && getComponents(pool)) || []),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "2.2.100",
3
+ "version": "2.2.102",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {