@optiaxiom/proteus 0.1.5 → 0.1.6

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.
@@ -3,7 +3,7 @@ import { jsx } from 'react/jsx-runtime';
3
3
  import { Button } from '@optiaxiom/react';
4
4
  import { useState } from 'react';
5
5
  import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
6
- import { useResolvedProteusProps } from '../proteus-document/useResolvedProteusProps.js';
6
+ import { useResolveProteusValues } from '../proteus-document/useResolveProteusValues.js';
7
7
 
8
8
  function ProteusAction({
9
9
  children,
@@ -13,7 +13,7 @@ function ProteusAction({
13
13
  const { onEvent, valid } = useProteusDocumentContext(
14
14
  "@optiaxiom/proteus/ProteusAction"
15
15
  );
16
- const resolvedOnClick = useResolvedProteusProps(
16
+ const resolvedOnClick = useResolveProteusValues(
17
17
  onClick ?? {}
18
18
  );
19
19
  const [loading, setLoading] = useState(false);
@@ -61,6 +61,15 @@ function ProteusDocumentShell({
61
61
  } else if (event.action === "download") {
62
62
  if (typeof event.url === "string") {
63
63
  await downloadFile(event.url);
64
+ } else if (Array.isArray(event.url)) {
65
+ await Promise.all(
66
+ event.url.map((u) => {
67
+ if (typeof u !== "string") {
68
+ throw new Error("Invalid URL in download array");
69
+ }
70
+ return downloadFile(u);
71
+ })
72
+ );
64
73
  } else {
65
74
  throw new Error("Invalid URL for download action");
66
75
  }
@@ -131,7 +140,7 @@ function ProteusDocumentShell({
131
140
  ]
132
141
  }
133
142
  ),
134
- /* @__PURE__ */ jsx(Group, { asChild: true, flexDirection: "column", gap: "16", children: /* @__PURE__ */ jsx(
143
+ /* @__PURE__ */ jsx(Group, { asChild: true, flexDirection: "column", gap: "16", children: /* @__PURE__ */ jsxs(
135
144
  "form",
136
145
  {
137
146
  onChange: (event) => {
@@ -140,11 +149,16 @@ function ProteusDocumentShell({
140
149
  setValid(form.checkValidity());
141
150
  });
142
151
  },
152
+ onSubmit: (event) => {
153
+ event.preventDefault();
154
+ },
143
155
  ref: formRef,
144
- children: element.body
156
+ children: [
157
+ element.body,
158
+ element.actions && !readOnly && /* @__PURE__ */ jsx(Group, { gap: "16", justifyContent: "end", w: "full", children: element.actions })
159
+ ]
145
160
  }
146
- ) }),
147
- element.actions && !readOnly && /* @__PURE__ */ jsx(Group, { gap: "16", justifyContent: "end", w: "full", children: element.actions })
161
+ ) })
148
162
  ]
149
163
  }
150
164
  )
@@ -12,6 +12,20 @@ function resolveProteusValue(value, data, parentPath) {
12
12
  parentPath
13
13
  );
14
14
  }
15
+ if ("$type" in value && value.$type === "Map" && "path" in value && typeof value.path === "string" && "children" in value) {
16
+ const array = getProteusValue(
17
+ data,
18
+ { path: value.path },
19
+ parentPath
20
+ );
21
+ if (!Array.isArray(array)) {
22
+ return value;
23
+ }
24
+ const resolvedPath = value.path.startsWith("/") ? value.path : `${parentPath}/${value.path}`;
25
+ return array.map(
26
+ (_, index) => resolveProteusValue(value.children, data, `${resolvedPath}/${index}`)
27
+ );
28
+ }
15
29
  return value;
16
30
  }
17
31
 
@@ -2,7 +2,7 @@ import { useProteusDocumentContext } from './ProteusDocumentContext.js';
2
2
  import { useProteusDocumentPathContext } from './ProteusDocumentPathContext.js';
3
3
  import { resolveProteusValue } from './resolveProteusValue.js';
4
4
 
5
- function useResolvedProteusProps(props) {
5
+ function useResolveProteusValues(props) {
6
6
  const { data } = useProteusDocumentContext(
7
7
  "@optiaxiom/react/useResolvedProteusProps"
8
8
  );
@@ -16,4 +16,4 @@ function useResolvedProteusProps(props) {
16
16
  return resolved;
17
17
  }
18
18
 
19
- export { useResolvedProteusProps };
19
+ export { useResolveProteusValues };
@@ -2772,6 +2772,9 @@ var definitions = {
2772
2772
  },
2773
2773
  url: {
2774
2774
  anyOf: [
2775
+ {
2776
+ $ref: "#/definitions/ProteusMap"
2777
+ },
2775
2778
  {
2776
2779
  $ref: "#/definitions/ProteusValue"
2777
2780
  },
@@ -2779,7 +2782,7 @@ var definitions = {
2779
2782
  type: "string"
2780
2783
  }
2781
2784
  ],
2782
- description: "URL to download"
2785
+ description: "URL to download, or a Map expression resolving to multiple URLs"
2783
2786
  }
2784
2787
  },
2785
2788
  required: [
@@ -2758,6 +2758,9 @@ var definitions = {
2758
2758
  },
2759
2759
  url: {
2760
2760
  anyOf: [
2761
+ {
2762
+ $ref: "#/definitions/ProteusMap"
2763
+ },
2761
2764
  {
2762
2765
  $ref: "#/definitions/ProteusValue"
2763
2766
  },
@@ -2765,7 +2768,7 @@ var definitions = {
2765
2768
  type: "string"
2766
2769
  }
2767
2770
  ],
2768
- description: "URL to download"
2771
+ description: "URL to download, or a Map expression resolving to multiple URLs"
2769
2772
  }
2770
2773
  },
2771
2774
  required: [
package/dist/index.d.ts CHANGED
@@ -222,7 +222,7 @@ type ProteusEventHandler = {
222
222
  action: "download";
223
223
  url: (ProteusValueProps & {
224
224
  $type: "Value";
225
- }) | string;
225
+ }) | string | string[];
226
226
  } | {
227
227
  action: "message-from";
228
228
  path: string;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/optimizely-axiom/optiaxiom.git"
8
8
  },
9
9
  "type": "module",
10
- "version": "0.1.5",
10
+ "version": "0.1.6",
11
11
  "files": [
12
12
  "dist/**",
13
13
  "LICENSE"