@optiaxiom/proteus 0.2.6 → 0.2.7

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.
@@ -1,5 +1,5 @@
1
- @layer optiaxiom._10u9e24;
2
- @layer optiaxiom._10u9e24 {
1
+ @layer optiaxiom._1fgw1dd;
2
+ @layer optiaxiom._1fgw1dd {
3
3
  .ProteusChart__jmlqij1 {
4
4
  border-radius: 16px;
5
5
  }
@@ -1,5 +1,5 @@
1
- @layer optiaxiom._10u9e24;
2
- @layer optiaxiom._10u9e24 {
1
+ @layer optiaxiom._1fgw1dd;
2
+ @layer optiaxiom._1fgw1dd {
3
3
  .ProteusChartTooltipContent__1gsvq810 {
4
4
  min-width: 128px;
5
5
  position: absolute;
@@ -1,5 +1,5 @@
1
- @layer optiaxiom._10u9e24;
2
- @layer optiaxiom._10u9e24 {
1
+ @layer optiaxiom._1fgw1dd;
2
+ @layer optiaxiom._1fgw1dd {
3
3
  .ProteusDocumentShell__vpuvfj1 {
4
4
  margin: -4px;
5
5
  }
@@ -1,5 +1,5 @@
1
- @layer optiaxiom._10u9e24;
2
- @layer optiaxiom._10u9e24 {
1
+ @layer optiaxiom._1fgw1dd;
2
+ @layer optiaxiom._1fgw1dd {
3
3
  .ProteusImageCarousel__1t6qej70 {
4
4
  outline: none;
5
5
  user-select: none;
@@ -1,5 +1,5 @@
1
- @layer optiaxiom._10u9e24;
2
- @layer optiaxiom._10u9e24 {
1
+ @layer optiaxiom._1fgw1dd;
2
+ @layer optiaxiom._1fgw1dd {
3
3
  .ProteusQuestion__8f590p0 {
4
4
  outline: none;
5
5
  }
@@ -0,0 +1,33 @@
1
+ import { useEffect } from 'react';
2
+
3
+ const useObserveValue = (inputRef, setValue) => {
4
+ useEffect(() => {
5
+ const input = inputRef.current;
6
+ if (!input) {
7
+ return;
8
+ }
9
+ const descriptor = Object.getOwnPropertyDescriptor(
10
+ input.constructor.prototype,
11
+ "value"
12
+ );
13
+ Object.defineProperty(input, "value", {
14
+ configurable: true,
15
+ enumerable: true,
16
+ get: function() {
17
+ return descriptor?.get?.call(input);
18
+ },
19
+ set: function(value) {
20
+ descriptor?.set?.call(input, value);
21
+ }
22
+ });
23
+ }, [inputRef, setValue]);
24
+ return (value) => {
25
+ if (!inputRef.current) {
26
+ return;
27
+ }
28
+ inputRef.current.value = value;
29
+ inputRef.current.dispatchEvent(new Event("change", { bubbles: true }));
30
+ };
31
+ };
32
+
33
+ export { useObserveValue };
@@ -1,4 +1,4 @@
1
- import './../assets/src/proteus-chart/ProteusChart.css.ts.vanilla-UlV5bM-e.css';
1
+ import './../assets/src/proteus-chart/ProteusChart.css.ts.vanilla-BO0-TwP_.css';
2
2
  import { recipe } from '@optiaxiom/react/css-runtime';
3
3
 
4
4
  var chart = recipe({base:[{border:'1',borderColor:'border.tertiary',fontSize:'sm',p:'16'},'ProteusChart__jmlqij1','ProteusChart__jmlqij0']});
@@ -1,4 +1,4 @@
1
- import './../assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-DFvGuq6I.css';
1
+ import './../assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-ETMXhILd.css';
2
2
  import { recipe } from '@optiaxiom/react/css-runtime';
3
3
 
4
4
  var tooltip = recipe({base:[{bg:'bg.default',border:'1',borderColor:'border.secondary',display:'grid',fontSize:'sm',gap:'6',pointerEvents:'none',px:'8',py:'10',rounded:'lg',shadow:'lg',transition:'all',z:'popover'},'ProteusChartTooltipContent__1gsvq810']});
@@ -1,4 +1,4 @@
1
- import './../assets/src/proteus-document/ProteusDocumentShell.css.ts.vanilla-C3__yEhR.css';
1
+ import './../assets/src/proteus-document/ProteusDocumentShell.css.ts.vanilla-CDxANCyw.css';
2
2
  import { recipe } from '@optiaxiom/react/css-runtime';
3
3
 
4
4
  var body = recipe({base:[{flexDirection:'column',gap:'16'},'ProteusDocumentShell__vpuvfj0'],variants:{truncate:{false:{},true:[{maxH:'sm',overflow:'auto',p:'4'},'ProteusDocumentShell__vpuvfj1']}}});
@@ -1,19 +1,26 @@
1
1
  "use client";
2
- import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { Flex } from '@optiaxiom/react';
4
- import { FileUpload, FileUploadList, FileUploadDropzone, FileUploadTrigger } from '@optiaxiom/react/unstable';
5
- import { useState, useCallback } from 'react';
4
+ import { FileUpload, VisuallyHidden, FileUploadList, FileUploadDropzone, FileUploadTrigger } from '@optiaxiom/react/unstable';
5
+ import { useRef, useState, useCallback } from 'react';
6
+ import { useObserveValue } from '../hooks/useObserveValue.js';
6
7
  import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
7
8
  import { useProteusDocumentPathContext } from '../proteus-document/ProteusDocumentPathContext.js';
8
9
 
9
- function ProteusFileUpload({ accept, name }) {
10
+ function ProteusFileUpload({
11
+ accept,
12
+ name,
13
+ required
14
+ }) {
10
15
  const { onDataChange, onUpload, readOnly } = useProteusDocumentContext(
11
16
  "@optiaxiom/proteus/ProteusFileUpload"
12
17
  );
13
18
  const { path: parentPath } = useProteusDocumentPathContext(
14
19
  "@optiaxiom/proteus/ProteusFileUpload"
15
20
  );
21
+ const inputRef = useRef(null);
16
22
  const [item, setItem] = useState(null);
23
+ const forceValueChange = useObserveValue(inputRef);
17
24
  const writeUrl = useCallback(
18
25
  (url) => {
19
26
  if (!name)
@@ -30,34 +37,55 @@ function ProteusFileUpload({ accept, name }) {
30
37
  const file = incoming[0];
31
38
  setItem({ file, status: "uploading" });
32
39
  writeUrl(null);
40
+ if (inputRef.current) {
41
+ forceValueChange("");
42
+ }
33
43
  try {
34
44
  const url = await onUpload(file);
35
45
  setItem(
36
46
  (curr) => curr?.file === file ? { file, status: "complete" } : curr
37
47
  );
38
48
  writeUrl(url);
49
+ if (inputRef.current) {
50
+ forceValueChange("1");
51
+ }
39
52
  } catch {
40
53
  setItem(
41
54
  (curr) => curr?.file === file ? { file, status: "error" } : curr
42
55
  );
43
56
  }
44
57
  },
45
- [onUpload, readOnly, writeUrl]
58
+ [forceValueChange, onUpload, readOnly, writeUrl]
46
59
  );
47
60
  const handleRemove = useCallback(() => {
48
61
  setItem(null);
49
62
  writeUrl(null);
50
- }, [writeUrl]);
51
- return /* @__PURE__ */ jsx(
63
+ if (inputRef.current) {
64
+ forceValueChange("");
65
+ }
66
+ }, [forceValueChange, writeUrl]);
67
+ return /* @__PURE__ */ jsxs(
52
68
  FileUpload,
53
69
  {
54
70
  accept,
55
71
  disabled: !onUpload || readOnly,
56
72
  onFilesDrop: handleFilesDrop,
57
- children: item ? /* @__PURE__ */ jsxs(Flex, { flexDirection: "column", gap: "8", children: [
58
- /* @__PURE__ */ jsx(FileUploadList, { items: [item], onRemove: handleRemove }),
59
- /* @__PURE__ */ jsx(FileUploadDropzone, { overlay: true })
60
- ] }) : /* @__PURE__ */ jsx(FileUploadDropzone, { children: /* @__PURE__ */ jsx(FileUploadTrigger, {}) })
73
+ children: [
74
+ /* @__PURE__ */ jsx(VisuallyHidden, { asChild: true, children: /* @__PURE__ */ jsx(
75
+ "input",
76
+ {
77
+ "aria-hidden": true,
78
+ name,
79
+ ref: inputRef,
80
+ required,
81
+ tabIndex: -1
82
+ }
83
+ ) }),
84
+ item ? /* @__PURE__ */ jsxs(Flex, { flexDirection: "column", gap: "8", children: [
85
+ /* @__PURE__ */ jsx(FileUploadList, { items: [item], onRemove: handleRemove }),
86
+ /* @__PURE__ */ jsx(FileUploadDropzone, { overlay: true })
87
+ ] }) : /* @__PURE__ */ jsx(FileUploadDropzone, { children: /* @__PURE__ */ jsx(FileUploadTrigger, {}) })
88
+ ]
61
89
  }
62
90
  );
63
91
  }
@@ -1,4 +1,4 @@
1
- import './../assets/src/proteus-image-carousel/ProteusImageCarousel.css.ts.vanilla-bCVJ5JAJ.css';
1
+ import './../assets/src/proteus-image-carousel/ProteusImageCarousel.css.ts.vanilla-CVLALefb.css';
2
2
  import { recipe } from '@optiaxiom/react/css-runtime';
3
3
 
4
4
  var carousel = recipe({base:[{flexDirection:'column',gap:'12'},'ProteusImageCarousel__1t6qej70']});
@@ -1,4 +1,4 @@
1
- import './../assets/src/proteus-question/ProteusQuestion.css.ts.vanilla-usVGixHc.css';
1
+ import './../assets/src/proteus-question/ProteusQuestion.css.ts.vanilla-DKDk8HIF.css';
2
2
  import { recipe } from '@optiaxiom/react/css-runtime';
3
3
 
4
4
  var addon = recipe({base:[{display:'grid',fontWeight:'500',placeItems:'center',rounded:'lg',size:'md',transition:'colors'},'ProteusQuestion__8f590p3'],variants:{cursor:{pointer:{cursor:'pointer'}}}});
package/dist/index.d.ts CHANGED
@@ -94,7 +94,7 @@ type ProteusFileUploadProps = {
94
94
  */
95
95
  required?: boolean;
96
96
  };
97
- declare function ProteusFileUpload({ accept, name }: ProteusFileUploadProps): react_jsx_runtime.JSX.Element;
97
+ declare function ProteusFileUpload({ accept, name, required, }: ProteusFileUploadProps): react_jsx_runtime.JSX.Element;
98
98
  declare namespace ProteusFileUpload {
99
99
  var displayName: string;
100
100
  }
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.2.6",
10
+ "version": "0.2.7",
11
11
  "files": [
12
12
  "dist/**",
13
13
  "LICENSE"
@@ -18,6 +18,7 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "import": "./dist/esm/index.js"
20
20
  },
21
+ "./package.json": "./package.json",
21
22
  "./spec": {
22
23
  "types": "./dist/spec.d.ts",
23
24
  "import": "./dist/esm/spec.js"
@@ -38,8 +39,8 @@
38
39
  "embla-carousel-react": "^8.6.0",
39
40
  "jsonpointer": "^5.0.1",
40
41
  "recharts": "^3.8.1",
41
- "@optiaxiom/icons": "^1.1.1",
42
- "@optiaxiom/react": "^1.9.31"
42
+ "@optiaxiom/icons": "^1.1.2",
43
+ "@optiaxiom/react": "^1.9.32"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@emotion/hash": "^0.9.2",