@optiaxiom/proteus 0.0.0 → 0.1.0
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.
- package/LICENSE +201 -0
- package/dist/esm/assets/src/proteus-chart/ProteusChart.css.ts.vanilla-WpbWN23E.css +9 -0
- package/dist/esm/assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-sqWemcZm.css +9 -0
- package/dist/esm/assets/src/proteus-question/ProteusQuestionItem.css.ts.vanilla-Dns_NfIP.css +26 -0
- package/dist/esm/hooks/useEffectEvent.js +14 -0
- package/dist/esm/icons/IconAngleLeft.js +21 -0
- package/dist/esm/icons/IconCalendar.js +20 -0
- package/dist/esm/icons/withIcon.js +31 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/proteus-action/ProteusAction.js +41 -0
- package/dist/esm/proteus-action/ProteusCancelAction.js +41 -0
- package/dist/esm/proteus-chart/ProteusChart-css.js +6 -0
- package/dist/esm/proteus-chart/ProteusChart.js +71 -0
- package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +7 -0
- package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +45 -0
- package/dist/esm/proteus-data-table/ProteusDataTable.js +34 -0
- package/dist/esm/proteus-document/ProteusDocumentContext.js +6 -0
- package/dist/esm/proteus-document/ProteusDocumentPathContext.js +8 -0
- package/dist/esm/proteus-document/ProteusDocumentRenderer.js +39 -0
- package/dist/esm/proteus-document/ProteusDocumentShell.js +128 -0
- package/dist/esm/proteus-document/getProteusValue.js +49 -0
- package/dist/esm/proteus-document/resolveProteusProp.js +39 -0
- package/dist/esm/proteus-document/resolveProteusValue.js +18 -0
- package/dist/esm/proteus-document/schemas.js +48 -0
- package/dist/esm/proteus-document/useProteusValue.js +15 -0
- package/dist/esm/proteus-document/useResolvedProteusProps.js +19 -0
- package/dist/esm/proteus-element/ProteusElement.js +153 -0
- package/dist/esm/proteus-image/ProteusImage.js +91 -0
- package/dist/esm/proteus-image/downloadFile.js +12 -0
- package/dist/esm/proteus-input/ProteusInput.js +32 -0
- package/dist/esm/proteus-map/ProteusMap.js +35 -0
- package/dist/esm/proteus-question/ProteusQuestion.js +96 -0
- package/dist/esm/proteus-question/ProteusQuestionItem-css.js +9 -0
- package/dist/esm/proteus-question/ProteusQuestionItem.js +57 -0
- package/dist/esm/proteus-select/ProteusSelect.js +44 -0
- package/dist/esm/proteus-show/ProteusShow.js +70 -0
- package/dist/esm/proteus-textarea/ProteusTextarea.js +32 -0
- package/dist/esm/proteus-value/ProteusValue.js +9 -0
- package/dist/esm/schema/public-schema.json.js +7904 -0
- package/dist/esm/schema/runtime-schema.json.js +7851 -0
- package/dist/esm/spec.js +1 -0
- package/dist/index.d.ts +293 -0
- package/dist/spec.d.ts +8626 -0
- package/package.json +41 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { Group, Button, Text } from '@optiaxiom/react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { IconAngleLeft } from '../icons/IconAngleLeft.js';
|
|
6
|
+
import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
|
|
7
|
+
import { ProteusQuestionItem } from './ProteusQuestionItem.js';
|
|
8
|
+
|
|
9
|
+
function ProteusQuestion({ questions }) {
|
|
10
|
+
const { onEvent } = useProteusDocumentContext(
|
|
11
|
+
"@optiaxiom/proteus/ProteusQuestion"
|
|
12
|
+
);
|
|
13
|
+
const [answers, setAnswers] = useState([]);
|
|
14
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
15
|
+
if (currentIndex >= questions.length) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const current = questions[currentIndex];
|
|
19
|
+
const isLast = currentIndex === questions.length - 1;
|
|
20
|
+
const onComplete = () => onEvent({
|
|
21
|
+
message: answers.map(
|
|
22
|
+
(value, index) => `Q: ${questions[index].question}
|
|
23
|
+
A: ${value === null ? "[Not specified]" : value}`
|
|
24
|
+
).join("\n\n")
|
|
25
|
+
});
|
|
26
|
+
return /* @__PURE__ */ jsxs(Group, { flexDirection: "column", gap: "16", children: [
|
|
27
|
+
/* @__PURE__ */ jsx(
|
|
28
|
+
ProteusQuestionItem,
|
|
29
|
+
{
|
|
30
|
+
onValueChange: (value) => {
|
|
31
|
+
answers[currentIndex] = value;
|
|
32
|
+
setAnswers([...answers]);
|
|
33
|
+
},
|
|
34
|
+
options: current.options,
|
|
35
|
+
question: current.question,
|
|
36
|
+
type: current.type,
|
|
37
|
+
value: answers[currentIndex] ?? null
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
/* @__PURE__ */ jsxs(Group, { gap: "8", justifyContent: "end", children: [
|
|
41
|
+
questions.length > 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
42
|
+
/* @__PURE__ */ jsx(
|
|
43
|
+
Button,
|
|
44
|
+
{
|
|
45
|
+
"aria-label": "Previous",
|
|
46
|
+
disabled: currentIndex === 0,
|
|
47
|
+
icon: /* @__PURE__ */ jsx(IconAngleLeft, {}),
|
|
48
|
+
onClick: (event) => {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
setCurrentIndex((i) => i - 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ jsxs(Text, { color: "fg.tertiary", children: [
|
|
55
|
+
currentIndex + 1,
|
|
56
|
+
" of ",
|
|
57
|
+
questions.length
|
|
58
|
+
] })
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsx(
|
|
61
|
+
Button,
|
|
62
|
+
{
|
|
63
|
+
onClick: (event) => {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
answers[currentIndex] = null;
|
|
66
|
+
setAnswers([...answers]);
|
|
67
|
+
if (isLast) {
|
|
68
|
+
void onComplete();
|
|
69
|
+
} else {
|
|
70
|
+
setCurrentIndex((i) => i + 1);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
children: "Skip"
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
/* @__PURE__ */ jsx(
|
|
77
|
+
Button,
|
|
78
|
+
{
|
|
79
|
+
appearance: "primary",
|
|
80
|
+
onClick: (event) => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
if (isLast) {
|
|
83
|
+
void onComplete();
|
|
84
|
+
} else {
|
|
85
|
+
setCurrentIndex((i) => i + 1);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
children: isLast ? "Submit" : "Next"
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
] })
|
|
92
|
+
] });
|
|
93
|
+
}
|
|
94
|
+
ProteusQuestion.displayName = "@optiaxiom/proteus/ProteusQuestion";
|
|
95
|
+
|
|
96
|
+
export { ProteusQuestion };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './../assets/src/proteus-question/ProteusQuestionItem.css.ts.vanilla-Dns_NfIP.css';
|
|
2
|
+
import { recipe } from '@optiaxiom/react/css-runtime';
|
|
3
|
+
|
|
4
|
+
var addon = recipe({base:[{display:'grid',fontWeight:'500',placeItems:'center',rounded:'lg',size:'md',transition:'colors'},'ProteusQuestionItem__uar8vn3']});
|
|
5
|
+
var choice = recipe({base:[{border:'1',color:'fg.default',cursor:'pointer',flexDirection:'column',fontSize:'md',gap:'8',px:'16',py:'12',rounded:'lg',transition:'colors'},'ProteusQuestionItem__uar8vn2','ProteusQuestionItem__uar8vn0']});
|
|
6
|
+
var choiceGroup = recipe({base:{flexDirection:'column',gap:'8'}});
|
|
7
|
+
var input = recipe({base:'ProteusQuestionItem__uar8vn1'});
|
|
8
|
+
|
|
9
|
+
export { addon, choice, choiceGroup, input };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
import { Group, Text, Box, Checkbox } from '@optiaxiom/react';
|
|
5
|
+
import { VisuallyHidden } from '@optiaxiom/react/unstable';
|
|
6
|
+
import { choiceGroup, choice, input, addon } from './ProteusQuestionItem-css.js';
|
|
7
|
+
|
|
8
|
+
function ProteusQuestionItem({
|
|
9
|
+
onValueChange,
|
|
10
|
+
options,
|
|
11
|
+
question,
|
|
12
|
+
type,
|
|
13
|
+
value
|
|
14
|
+
}) {
|
|
15
|
+
return /* @__PURE__ */ jsxs(Group, { flexDirection: "column", gap: "16", children: [
|
|
16
|
+
/* @__PURE__ */ jsx(Text, { fontWeight: "500", children: question }),
|
|
17
|
+
/* @__PURE__ */ jsx(Group, { ...choiceGroup(), children: options.map((option, index) => {
|
|
18
|
+
const checked = type === "single_select" ? value?.[0] === option : Array.isArray(value) && value.includes(option);
|
|
19
|
+
return /* @__PURE__ */ createElement(Box, { asChild: true, ...choice(), key: option }, /* @__PURE__ */ jsxs("label", { children: [
|
|
20
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Box, { asChild: true, ...input(), children: /* @__PURE__ */ jsx(
|
|
21
|
+
"input",
|
|
22
|
+
{
|
|
23
|
+
checked,
|
|
24
|
+
name: type === "single_select" ? "question-item" : void 0,
|
|
25
|
+
onChange: () => {
|
|
26
|
+
if (type === "single_select") {
|
|
27
|
+
onValueChange([option]);
|
|
28
|
+
} else {
|
|
29
|
+
const current = Array.isArray(value) ? value : [];
|
|
30
|
+
onValueChange(
|
|
31
|
+
checked ? current.filter((v) => v !== option) : [...current, option]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
type: type === "single_select" ? "radio" : "checkbox",
|
|
36
|
+
value: option
|
|
37
|
+
}
|
|
38
|
+
) }) }),
|
|
39
|
+
/* @__PURE__ */ jsxs(Group, { gap: "12", children: [
|
|
40
|
+
/* @__PURE__ */ jsx(Box, { ...addon(), children: type === "single_select" ? index + 1 : /* @__PURE__ */ jsx(
|
|
41
|
+
Checkbox,
|
|
42
|
+
{
|
|
43
|
+
checked,
|
|
44
|
+
hidden: true,
|
|
45
|
+
pointerEvents: "none",
|
|
46
|
+
tabIndex: -1
|
|
47
|
+
}
|
|
48
|
+
) }),
|
|
49
|
+
/* @__PURE__ */ jsx(Group, { flex: "1", flexDirection: "column", gap: "2", children: /* @__PURE__ */ jsx(Text, { fontWeight: "500", children: option }) })
|
|
50
|
+
] })
|
|
51
|
+
] }));
|
|
52
|
+
}) })
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
ProteusQuestionItem.displayName = "@optiaxiom/proteus/ProteusQuestionItem";
|
|
56
|
+
|
|
57
|
+
export { ProteusQuestionItem };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Select } from '@optiaxiom/react';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
|
|
6
|
+
import { useProteusDocumentPathContext } from '../proteus-document/ProteusDocumentPathContext.js';
|
|
7
|
+
import { useProteusValue } from '../proteus-document/useProteusValue.js';
|
|
8
|
+
|
|
9
|
+
function ProteusSelect({
|
|
10
|
+
children,
|
|
11
|
+
options = [],
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
const { onDataChange, readOnly } = useProteusDocumentContext(
|
|
15
|
+
"@optiaxiom/proteus/ProteusSelect"
|
|
16
|
+
);
|
|
17
|
+
const { path: parentPath } = useProteusDocumentPathContext(
|
|
18
|
+
"@optiaxiom/proteus/ProteusSelect"
|
|
19
|
+
);
|
|
20
|
+
const optionsRef = useRef(options);
|
|
21
|
+
optionsRef.current = options;
|
|
22
|
+
const resolved = useProteusValue({ path: props.name ?? "" });
|
|
23
|
+
const value = props.name ? String(resolved ?? options[0]?.value ?? "") : options[0]?.value ?? "";
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
Select,
|
|
26
|
+
{
|
|
27
|
+
...props,
|
|
28
|
+
onValueChange: (value2) => {
|
|
29
|
+
if (readOnly) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (props.name) {
|
|
33
|
+
onDataChange?.(`${parentPath}/${props.name}`, value2);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
options,
|
|
37
|
+
value,
|
|
38
|
+
children
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
ProteusSelect.displayName = "@optiaxiom/proteus/ProteusSelect";
|
|
43
|
+
|
|
44
|
+
export { ProteusSelect };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
|
|
4
|
+
import { useProteusDocumentPathContext } from '../proteus-document/ProteusDocumentPathContext.js';
|
|
5
|
+
import { resolveProteusValue } from '../proteus-document/resolveProteusValue.js';
|
|
6
|
+
|
|
7
|
+
function ProteusShow({ children, when }) {
|
|
8
|
+
const { data } = useProteusDocumentContext("@optiaxiom/proteus/ProteusShow");
|
|
9
|
+
const { path: parentPath } = useProteusDocumentPathContext(
|
|
10
|
+
"@optiaxiom/proteus/ProteusShow"
|
|
11
|
+
);
|
|
12
|
+
const conditions = Array.isArray(when) ? when : [when];
|
|
13
|
+
const shouldShow = conditions.every(
|
|
14
|
+
(condition) => evaluateCondition(condition, data, parentPath)
|
|
15
|
+
);
|
|
16
|
+
if (!shouldShow) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
20
|
+
}
|
|
21
|
+
function evaluateCondition(condition, data, parentPath) {
|
|
22
|
+
if (!condition) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if ("and" in condition) {
|
|
26
|
+
return condition.and.every(
|
|
27
|
+
(cond) => evaluateCondition(cond, data, parentPath)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if ("or" in condition) {
|
|
31
|
+
return condition.or.some(
|
|
32
|
+
(cond) => evaluateCondition(cond, data, parentPath)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if ("!!" in condition) {
|
|
36
|
+
const value = resolveProteusValue(condition["!!"], data, parentPath);
|
|
37
|
+
return !!value;
|
|
38
|
+
}
|
|
39
|
+
if ("==" in condition) {
|
|
40
|
+
const [left, right] = condition["=="];
|
|
41
|
+
return resolveProteusValue(left, data, parentPath) === resolveProteusValue(right, data, parentPath);
|
|
42
|
+
} else if ("!=" in condition) {
|
|
43
|
+
const [left, right] = condition["!="];
|
|
44
|
+
return resolveProteusValue(left, data, parentPath) !== resolveProteusValue(right, data, parentPath);
|
|
45
|
+
} else if ("<" in condition) {
|
|
46
|
+
const [left, right] = condition["<"];
|
|
47
|
+
const leftVal = resolveProteusValue(left, data, parentPath);
|
|
48
|
+
const rightVal = resolveProteusValue(right, data, parentPath);
|
|
49
|
+
return typeof leftVal === "number" && typeof rightVal === "number" && leftVal < rightVal;
|
|
50
|
+
} else if ("<=" in condition) {
|
|
51
|
+
const [left, right] = condition["<="];
|
|
52
|
+
const leftVal = resolveProteusValue(left, data, parentPath);
|
|
53
|
+
const rightVal = resolveProteusValue(right, data, parentPath);
|
|
54
|
+
return typeof leftVal === "number" && typeof rightVal === "number" && leftVal <= rightVal;
|
|
55
|
+
} else if (">" in condition) {
|
|
56
|
+
const [left, right] = condition[">"];
|
|
57
|
+
const leftVal = resolveProteusValue(left, data, parentPath);
|
|
58
|
+
const rightVal = resolveProteusValue(right, data, parentPath);
|
|
59
|
+
return typeof leftVal === "number" && typeof rightVal === "number" && leftVal > rightVal;
|
|
60
|
+
} else if (">=" in condition) {
|
|
61
|
+
const [left, right] = condition[">="];
|
|
62
|
+
const leftVal = resolveProteusValue(left, data, parentPath);
|
|
63
|
+
const rightVal = resolveProteusValue(right, data, parentPath);
|
|
64
|
+
return typeof leftVal === "number" && typeof rightVal === "number" && leftVal >= rightVal;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
ProteusShow.displayName = "@optiaxiom/proteus/ProteusShow";
|
|
69
|
+
|
|
70
|
+
export { ProteusShow };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Textarea } from '@optiaxiom/react';
|
|
4
|
+
import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
|
|
5
|
+
import { useProteusDocumentPathContext } from '../proteus-document/ProteusDocumentPathContext.js';
|
|
6
|
+
import { useProteusValue } from '../proteus-document/useProteusValue.js';
|
|
7
|
+
|
|
8
|
+
function ProteusTextarea(props) {
|
|
9
|
+
const { onDataChange, readOnly } = useProteusDocumentContext(
|
|
10
|
+
"@optiaxiom/proteus/ProteusTextarea"
|
|
11
|
+
);
|
|
12
|
+
const { path: parentPath } = useProteusDocumentPathContext(
|
|
13
|
+
"@optiaxiom/proteus/ProteusTextarea"
|
|
14
|
+
);
|
|
15
|
+
const value = useProteusValue({ path: props.name ?? "" });
|
|
16
|
+
return /* @__PURE__ */ jsx(
|
|
17
|
+
Textarea,
|
|
18
|
+
{
|
|
19
|
+
...props,
|
|
20
|
+
onValueChange: (value2) => {
|
|
21
|
+
if (props.name) {
|
|
22
|
+
onDataChange?.(`${parentPath}/${props.name}`, value2);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
readOnly,
|
|
26
|
+
value: props.name ? String(value ?? "") : void 0
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
ProteusTextarea.displayName = "@optiaxiom/proteus/ProteusTextarea";
|
|
31
|
+
|
|
32
|
+
export { ProteusTextarea };
|