@dxos/react-ui-form 0.8.4-main.66e292d → 0.8.4-main.69d29f4
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/dist/lib/browser/index.mjs +2212 -2284
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2212 -2284
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +2 -2
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +7 -4
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +6 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +9 -3
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form-old.stories.d.ts +131 -0
- package/dist/types/src/components/Form/Form-old.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/Form.d.ts +81 -27
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +53 -92
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +37 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +78 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts +19 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts +14 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
- package/dist/types/src/components/Form/{custom/SelectOptionsInput.stories.d.ts → fields/SelectOptionField.stories.d.ts} +6 -3
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/index.d.ts +12 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +2 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +14 -9
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +5 -2
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +6 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +5 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +0 -2
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -3
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +6 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/echo.d.ts +6 -0
- package/dist/types/src/util/echo.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +7 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +1 -2
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -44
- package/src/components/ControlSection/ControlSection.tsx +8 -8
- package/src/components/FieldEditor/FieldEditor.stories.tsx +42 -21
- package/src/components/FieldEditor/FieldEditor.tsx +72 -75
- package/src/components/Form/Form-old.stories.tsx +314 -0
- package/src/components/Form/Form.stories.tsx +146 -246
- package/src/components/Form/Form.tsx +320 -110
- package/src/components/Form/FormField.tsx +286 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +174 -0
- package/src/components/Form/FormFieldSet.tsx +125 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +151 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/GeoPointField.tsx +120 -0
- package/src/components/Form/fields/MarkdownField.tsx +78 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +181 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +17 -14
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +20 -14
- package/src/components/Form/fields/TextAreaField.tsx +38 -0
- package/src/components/Form/fields/TextField.tsx +38 -0
- package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +15 -8
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +15 -8
- package/src/components/ObjectPicker/ObjectPicker.tsx +76 -62
- package/src/components/ViewEditor/ViewEditor.stories.tsx +29 -25
- package/src/components/ViewEditor/ViewEditor.test.tsx +6 -2
- package/src/components/ViewEditor/ViewEditor.tsx +223 -154
- package/src/components/testing.tsx +9 -7
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +362 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/translations.ts +8 -6
- package/src/util/echo.ts +25 -0
- package/src/util/index.ts +2 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +7 -13
- package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/Defaults.d.ts +0 -14
- package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -9
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -63
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -23
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/Input.d.ts +0 -29
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -22
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -4
- package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/factory.d.ts +0 -8
- package/dist/types/src/components/Form/factory.d.ts.map +0 -1
- package/dist/types/src/hooks/useForm.d.ts +0 -67
- package/dist/types/src/hooks/useForm.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/Form/ArrayField.tsx +0 -127
- package/src/components/Form/Defaults.tsx +0 -205
- package/src/components/Form/FormActions.tsx +0 -59
- package/src/components/Form/FormContent.tsx +0 -362
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -54
- package/src/components/Form/RefField.tsx +0 -283
- package/src/components/Form/custom/GeoPointInput.tsx +0 -80
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -34
- package/src/hooks/useForm.ts +0 -296
- package/src/hooks/useQueryRefOptions.ts +0 -62
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/translations.ts
|
|
2
|
-
var translationKey = "react-ui-form";
|
|
2
|
+
var translationKey = "@dxos/react-ui-form";
|
|
3
3
|
var translations = [
|
|
4
4
|
{
|
|
5
5
|
"en-US": {
|
|
@@ -24,7 +24,9 @@ var translations = [
|
|
|
24
24
|
"ref field combobox input placeholder": "Search\u2026",
|
|
25
25
|
"ref field placeholder_one": "Select\u2026",
|
|
26
26
|
"ref field placeholder_other": "Select items\u2026",
|
|
27
|
-
|
|
27
|
+
"example placeholder": "Example",
|
|
28
|
+
"latitude placeholder": "Latitude (e.g., 40.7128)",
|
|
29
|
+
"longitude placeholder": "Longitude (e.g., -74.0060)",
|
|
28
30
|
"cancel button label": "Cancel",
|
|
29
31
|
"save button label": "Save",
|
|
30
32
|
// FormatEnum
|
|
@@ -56,10 +58,10 @@ var translations = [
|
|
|
56
58
|
"format uri": "URI",
|
|
57
59
|
"format url": "URL",
|
|
58
60
|
"format uuid": "UUID",
|
|
59
|
-
//
|
|
61
|
+
// GeoPointField.
|
|
60
62
|
"latitude label": "Latitude",
|
|
61
63
|
"longitude label": "Longitude",
|
|
62
|
-
//
|
|
64
|
+
// SelectOptionsField.
|
|
63
65
|
"select option label": "Label",
|
|
64
66
|
"select option label placeholder": "Option label",
|
|
65
67
|
"select option color": "Color",
|
|
@@ -67,93 +69,58 @@ var translations = [
|
|
|
67
69
|
"select option add": "Add option",
|
|
68
70
|
// System schema message.
|
|
69
71
|
"system schema title": "System type",
|
|
70
|
-
"system schema description": "
|
|
72
|
+
"system schema description": "System type: cannot add or remove fields."
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
];
|
|
75
77
|
|
|
76
78
|
// src/components/ControlSection/ControlSection.tsx
|
|
77
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
78
79
|
import React from "react";
|
|
79
80
|
import { Button, Input, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
80
|
-
import {
|
|
81
|
-
import { mx } from "@dxos/
|
|
81
|
+
import { Layout } from "@dxos/react-ui-mosaic";
|
|
82
|
+
import { mx } from "@dxos/ui-theme";
|
|
82
83
|
var ControlPage = ({ children, classNames, ...props }) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...props
|
|
92
|
-
}, children));
|
|
93
|
-
} finally {
|
|
94
|
-
_effect.f();
|
|
95
|
-
}
|
|
84
|
+
return /* @__PURE__ */ React.createElement(Layout.Container, {
|
|
85
|
+
scrollable: true,
|
|
86
|
+
classNames: "[--control-spacing:var(--dx-trimMd)]"
|
|
87
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
88
|
+
role: "none",
|
|
89
|
+
className: mx("pli-cardSpacingInline pbe-trimMd", classNames),
|
|
90
|
+
...props
|
|
91
|
+
}, children));
|
|
96
92
|
};
|
|
97
93
|
var ControlSection = ({ title, description, children }) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
description
|
|
103
|
-
}), children);
|
|
104
|
-
} finally {
|
|
105
|
-
_effect.f();
|
|
106
|
-
}
|
|
94
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ControlSectionHeading, {
|
|
95
|
+
title,
|
|
96
|
+
description
|
|
97
|
+
}), children);
|
|
107
98
|
};
|
|
108
99
|
var ControlSectionHeading = ({ title, description }) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
className: "pli-trimMd mlb-trimMd container-max-width text-description"
|
|
116
|
-
}, toLocalizedString(description, t)));
|
|
117
|
-
} finally {
|
|
118
|
-
_effect.f();
|
|
119
|
-
}
|
|
100
|
+
const { t } = useTranslation(translationKey);
|
|
101
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h2", {
|
|
102
|
+
className: "pli-trimMd container-max-width text-xl mbs-trimMd mbe-trimMd"
|
|
103
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
104
|
+
className: "pli-trimMd mlb-trimMd container-max-width text-description"
|
|
105
|
+
}, toLocalizedString(description, t)));
|
|
120
106
|
};
|
|
121
107
|
var ControlGroupButton = ({ classNames, ...props }) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
classNames
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
]
|
|
130
|
-
});
|
|
131
|
-
} finally {
|
|
132
|
-
_effect.f();
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
var ControlGroup = ({ children, classNames }) => {
|
|
136
|
-
var _effect = _useSignals();
|
|
137
|
-
try {
|
|
138
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
139
|
-
role: "none",
|
|
140
|
-
className: mx("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd", "[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end", classNames)
|
|
141
|
-
}, children);
|
|
142
|
-
} finally {
|
|
143
|
-
_effect.f();
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
var ControlFrame = ({ children }) => {
|
|
147
|
-
var _effect = _useSignals();
|
|
148
|
-
try {
|
|
149
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
150
|
-
role: "none",
|
|
151
|
-
className: mx("container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd", "border border-separator rounded-md")
|
|
152
|
-
}, children);
|
|
153
|
-
} finally {
|
|
154
|
-
_effect.f();
|
|
155
|
-
}
|
|
108
|
+
return /* @__PURE__ */ React.createElement(Button, {
|
|
109
|
+
...props,
|
|
110
|
+
classNames: [
|
|
111
|
+
"md:col-span-2",
|
|
112
|
+
classNames
|
|
113
|
+
]
|
|
114
|
+
});
|
|
156
115
|
};
|
|
116
|
+
var ControlGroup = ({ children, classNames }) => /* @__PURE__ */ React.createElement("div", {
|
|
117
|
+
role: "none",
|
|
118
|
+
className: mx("group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd", "[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end", classNames)
|
|
119
|
+
}, children);
|
|
120
|
+
var ControlFrame = ({ children }) => /* @__PURE__ */ React.createElement("div", {
|
|
121
|
+
role: "none",
|
|
122
|
+
className: mx("container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd", "border border-separator rounded-md")
|
|
123
|
+
}, children);
|
|
157
124
|
var controlItemClasses = mx([
|
|
158
125
|
"container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center",
|
|
159
126
|
// TODO(burdon): Use grid gap consistently or apply margins consistently?
|
|
@@ -163,657 +130,453 @@ var controlItemClasses = mx([
|
|
|
163
130
|
var controlItemTitleClasses = "mbe-0 text-lg text-baseText font-normal";
|
|
164
131
|
var controlItemDescriptionClasses = "mlb-trimSm md:mbe-0 text-base text-description";
|
|
165
132
|
var ControlItem = ({ title, description, children }) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
className: controlItemDescriptionClasses
|
|
177
|
-
}, toLocalizedString(description, t))), children);
|
|
178
|
-
} finally {
|
|
179
|
-
_effect.f();
|
|
180
|
-
}
|
|
133
|
+
const { t } = useTranslation(translationKey);
|
|
134
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
135
|
+
className: controlItemClasses
|
|
136
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
137
|
+
role: "none"
|
|
138
|
+
}, /* @__PURE__ */ React.createElement("h3", {
|
|
139
|
+
className: controlItemTitleClasses
|
|
140
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
141
|
+
className: controlItemDescriptionClasses
|
|
142
|
+
}, toLocalizedString(description, t))), children);
|
|
181
143
|
};
|
|
182
144
|
var ControlItemInput = ({ title, description, children }) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
classNames: controlItemDescriptionClasses
|
|
194
|
-
}, toLocalizedString(description, t)))), children));
|
|
195
|
-
} finally {
|
|
196
|
-
_effect.f();
|
|
197
|
-
}
|
|
145
|
+
const { t } = useTranslation(translationKey);
|
|
146
|
+
return /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
|
|
147
|
+
className: controlItemClasses
|
|
148
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
149
|
+
role: "none"
|
|
150
|
+
}, /* @__PURE__ */ React.createElement(Input.Label, {
|
|
151
|
+
classNames: controlItemTitleClasses
|
|
152
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement(Input.DescriptionAndValidation, null, /* @__PURE__ */ React.createElement(Input.Description, {
|
|
153
|
+
classNames: controlItemDescriptionClasses
|
|
154
|
+
}, toLocalizedString(description, t)))), children));
|
|
198
155
|
};
|
|
199
156
|
var ControlFrameItem = ({ title, description, children }) => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
className: "mlb-trimSm md:mbe-0 text-description"
|
|
210
|
-
}, toLocalizedString(description, t)), children);
|
|
211
|
-
} finally {
|
|
212
|
-
_effect.f();
|
|
213
|
-
}
|
|
157
|
+
const { t } = useTranslation(translationKey);
|
|
158
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
159
|
+
role: "group",
|
|
160
|
+
className: "min-is-0"
|
|
161
|
+
}, /* @__PURE__ */ React.createElement("h3", {
|
|
162
|
+
className: "text-lg mbe-2"
|
|
163
|
+
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React.createElement("p", {
|
|
164
|
+
className: "mlb-trimSm md:mbe-0 text-description"
|
|
165
|
+
}, toLocalizedString(description, t)), children);
|
|
214
166
|
};
|
|
215
167
|
|
|
216
168
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
217
|
-
import {
|
|
218
|
-
import
|
|
219
|
-
import { Format as
|
|
220
|
-
import { log as
|
|
169
|
+
import React18, { useCallback as useCallback14, useEffect as useEffect7, useMemo as useMemo7, useState as useState5 } from "react";
|
|
170
|
+
import { Obj as Obj3 } from "@dxos/echo";
|
|
171
|
+
import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
|
|
172
|
+
import { log as log2 } from "@dxos/log";
|
|
221
173
|
import { useAsyncEffect, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
222
|
-
import { formatToAdditionalPropertyAttributes, getFormatSchema
|
|
174
|
+
import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
|
|
223
175
|
|
|
224
|
-
// src/
|
|
225
|
-
import {
|
|
226
|
-
import
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
import React2 from "react";
|
|
234
|
-
import { Icon, Input as Input2, Tooltip } from "@dxos/react-ui";
|
|
235
|
-
import { labelSpacing } from "@dxos/react-ui-stack";
|
|
236
|
-
import { errorText, mx as mx2 } from "@dxos/react-ui-theme";
|
|
237
|
-
var InputHeader = ({ error, label, readonly }) => {
|
|
238
|
-
var _effect = _useSignals2();
|
|
239
|
-
try {
|
|
240
|
-
const Label = readonly ? "span" : Input2.Label;
|
|
241
|
-
const labelProps = readonly ? {} : {
|
|
242
|
-
classNames: "!mlb-0"
|
|
243
|
-
};
|
|
244
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
245
|
-
role: "none",
|
|
246
|
-
className: mx2("flex justify-between items-center", labelSpacing)
|
|
247
|
-
}, /* @__PURE__ */ React2.createElement(Label, labelProps, label), error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
248
|
-
asChild: true,
|
|
249
|
-
content: error,
|
|
250
|
-
side: "bottom"
|
|
251
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
252
|
-
icon: "ph--warning--regular",
|
|
253
|
-
size: 4,
|
|
254
|
-
classNames: errorText
|
|
255
|
-
})));
|
|
256
|
-
} finally {
|
|
257
|
-
_effect.f();
|
|
176
|
+
// src/util/echo.ts
|
|
177
|
+
import { Obj } from "@dxos/echo";
|
|
178
|
+
import { setValue as setValuePlain, splitJsonPath } from "@dxos/effect";
|
|
179
|
+
var setValueEchoAware = (obj, path, value3) => {
|
|
180
|
+
if (Obj.isObject(obj)) {
|
|
181
|
+
Obj.change(obj, (mutableObj) => {
|
|
182
|
+
Obj.setValue(mutableObj, splitJsonPath(path), value3);
|
|
183
|
+
});
|
|
184
|
+
return obj;
|
|
258
185
|
}
|
|
186
|
+
return setValuePlain(obj, path, value3);
|
|
259
187
|
};
|
|
260
188
|
|
|
261
|
-
// src/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const [latitudeText, setLatitudeText] = useState(geoLocation.latitude?.toString());
|
|
278
|
-
useEffect(() => {
|
|
279
|
-
const location = GeoLocation.fromGeoPoint(geoPoint);
|
|
280
|
-
setLongitudeText(location.longitude.toString());
|
|
281
|
-
setLatitudeText(location.latitude.toString());
|
|
282
|
-
}, [
|
|
283
|
-
geoPoint
|
|
284
|
-
]);
|
|
285
|
-
const handleCoordinateChange = useCallback((coordinateType, setText) => (event) => {
|
|
286
|
-
const inputText = event.target.value;
|
|
287
|
-
setText(inputText);
|
|
288
|
-
if (inputText !== "" && inputText !== "-") {
|
|
289
|
-
const coord = safeParseFloat(inputText);
|
|
290
|
-
if (coord !== void 0 && !isNaN(coord)) {
|
|
291
|
-
const currentLocation = GeoLocation.fromGeoPoint(getValue3() ?? [
|
|
292
|
-
0,
|
|
293
|
-
0
|
|
294
|
-
]);
|
|
295
|
-
const newLocation = {
|
|
296
|
-
...currentLocation,
|
|
297
|
-
[coordinateType]: coord
|
|
298
|
-
};
|
|
299
|
-
const newValue = GeoLocation.toGeoPoint(newLocation);
|
|
300
|
-
onValueChange(type, newValue);
|
|
189
|
+
// src/util/field.ts
|
|
190
|
+
import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
|
|
191
|
+
var parseValue = ({ type, format, value: value3 }) => {
|
|
192
|
+
if (value3 === void 0 || value3 === null || value3 === "") {
|
|
193
|
+
return void 0;
|
|
194
|
+
}
|
|
195
|
+
const parseScalar = (type2) => {
|
|
196
|
+
switch (type2) {
|
|
197
|
+
case TypeEnum.Boolean: {
|
|
198
|
+
if (typeof value3 === "string") {
|
|
199
|
+
const lowercaseValue = value3.toLowerCase();
|
|
200
|
+
if (lowercaseValue === "0" || lowercaseValue === "false") {
|
|
201
|
+
return false;
|
|
202
|
+
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
301
205
|
}
|
|
206
|
+
return Boolean(value3);
|
|
302
207
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
]);
|
|
308
|
-
return /* @__PURE__ */ React3.createElement(Input3.Root, {
|
|
309
|
-
validationValence: status
|
|
310
|
-
}, /* @__PURE__ */ React3.createElement(InputHeader, {
|
|
311
|
-
error,
|
|
312
|
-
label
|
|
313
|
-
}), /* @__PURE__ */ React3.createElement("div", {
|
|
314
|
-
role: "none",
|
|
315
|
-
className: "grid grid-cols-2 gap-2"
|
|
316
|
-
}, /* @__PURE__ */ React3.createElement("div", {
|
|
317
|
-
role: "none"
|
|
318
|
-
}, /* @__PURE__ */ React3.createElement(Input3.Label, null, t("latitude label")), /* @__PURE__ */ React3.createElement(Input3.TextInput, {
|
|
319
|
-
type: "number",
|
|
320
|
-
step: "0.00001",
|
|
321
|
-
min: "-90",
|
|
322
|
-
max: "90",
|
|
323
|
-
disabled: !!readonly,
|
|
324
|
-
value: latitudeText,
|
|
325
|
-
onChange: handleCoordinateChange("latitude", setLatitudeText),
|
|
326
|
-
onBlur
|
|
327
|
-
})), /* @__PURE__ */ React3.createElement("div", {
|
|
328
|
-
role: "none"
|
|
329
|
-
}, /* @__PURE__ */ React3.createElement(Input3.Label, null, t("longitude label")), /* @__PURE__ */ React3.createElement(Input3.TextInput, {
|
|
330
|
-
type: "number",
|
|
331
|
-
step: "0.00001",
|
|
332
|
-
min: "-180",
|
|
333
|
-
max: "180",
|
|
334
|
-
disabled: !!readonly,
|
|
335
|
-
value: longitudeText,
|
|
336
|
-
onChange: handleCoordinateChange("longitude", setLongitudeText),
|
|
337
|
-
onBlur
|
|
338
|
-
}))));
|
|
339
|
-
} finally {
|
|
340
|
-
_effect.f();
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// src/components/Form/custom/SelectOptionsInput.tsx
|
|
345
|
-
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
346
|
-
import React4, { useCallback as useCallback2, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
347
|
-
import { PublicKey } from "@dxos/keys";
|
|
348
|
-
import { IconButton, Input as Input4, Tag, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
349
|
-
import { List } from "@dxos/react-ui-list";
|
|
350
|
-
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
351
|
-
import { hues, subtleHover } from "@dxos/react-ui-theme";
|
|
352
|
-
var SelectOptionInput = ({ type, label, readonly, getStatus, getValue: getValue3, onValueChange }) => {
|
|
353
|
-
var _effect = _useSignals4();
|
|
354
|
-
try {
|
|
355
|
-
const [selected, setSelectedId] = useState2(null);
|
|
356
|
-
const [isNewOption, setIsNewOption] = useState2(false);
|
|
357
|
-
const inputRef = useRef(null);
|
|
358
|
-
const { t } = useTranslation3(translationKey);
|
|
359
|
-
const { status, error } = getStatus();
|
|
360
|
-
const options = getValue3();
|
|
361
|
-
useEffect2(() => {
|
|
362
|
-
if (options === void 0) {
|
|
363
|
-
onValueChange(type, []);
|
|
208
|
+
case TypeEnum.Number: {
|
|
209
|
+
const cleaned = typeof value3 === "string" ? value3.replace(/[^0-9.-]+/g, "") : value3;
|
|
210
|
+
const num = Number(cleaned);
|
|
211
|
+
return Number.isNaN(num) ? null : num;
|
|
364
212
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const randomHue = () => {
|
|
371
|
-
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
372
|
-
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
373
|
-
if (unusedHues.length > 0) {
|
|
374
|
-
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
213
|
+
case TypeEnum.String:
|
|
214
|
+
case TypeEnum.Ref:
|
|
215
|
+
return String(value3);
|
|
216
|
+
default: {
|
|
217
|
+
return value3;
|
|
375
218
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
if (!format) {
|
|
222
|
+
return parseScalar(type);
|
|
223
|
+
}
|
|
224
|
+
switch (format) {
|
|
225
|
+
case Format.TypeFormat.Boolean:
|
|
226
|
+
return parseScalar(TypeEnum.Boolean);
|
|
227
|
+
case Format.TypeFormat.Number:
|
|
228
|
+
case Format.TypeFormat.Percent:
|
|
229
|
+
case Format.TypeFormat.Currency:
|
|
230
|
+
return parseScalar(TypeEnum.Number);
|
|
231
|
+
case Format.TypeFormat.String:
|
|
232
|
+
case Format.TypeFormat.Markdown: {
|
|
233
|
+
return parseScalar(TypeEnum.String);
|
|
234
|
+
}
|
|
235
|
+
case Format.TypeFormat.Ref:
|
|
236
|
+
throw new Error(`unexpected format: ${Format.TypeFormat.Ref}`);
|
|
237
|
+
case Format.TypeFormat.DateTime:
|
|
238
|
+
case Format.TypeFormat.Date:
|
|
239
|
+
case Format.TypeFormat.Time:
|
|
240
|
+
case Format.TypeFormat.Timestamp: {
|
|
241
|
+
const date = new Date(value3);
|
|
242
|
+
return isNaN(date.getTime()) ? null : date;
|
|
243
|
+
}
|
|
244
|
+
case Format.TypeFormat.GeoPoint: {
|
|
245
|
+
if (typeof value3 === "string") {
|
|
246
|
+
const cleaned = value3.replace(/[^0-9.,-]+/g, "");
|
|
247
|
+
const parts = cleaned.split(",");
|
|
248
|
+
if (parts.length === 2) {
|
|
249
|
+
const lat = parseFloat(parts[0]);
|
|
250
|
+
const long = parseFloat(parts[1]);
|
|
251
|
+
if (!isNaN(lat) && !isNaN(long)) {
|
|
252
|
+
return GeoLocation.toGeoPoint({
|
|
253
|
+
latitude: lat,
|
|
254
|
+
longitude: long
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
410
258
|
}
|
|
411
|
-
|
|
412
|
-
|
|
259
|
+
return [
|
|
260
|
+
0,
|
|
261
|
+
0
|
|
413
262
|
];
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
options,
|
|
419
|
-
type,
|
|
420
|
-
onValueChange
|
|
421
|
-
]);
|
|
422
|
-
const handleClick = useCallback2((id) => {
|
|
423
|
-
setSelectedId((current) => current === id ? null : id);
|
|
424
|
-
}, []);
|
|
425
|
-
const handleTitleChange = useCallback2((id) => (e) => {
|
|
426
|
-
const newOptions = options?.map((o) => o.id === id ? {
|
|
427
|
-
...o,
|
|
428
|
-
title: e.target.value
|
|
429
|
-
} : o);
|
|
430
|
-
onValueChange(type, newOptions ?? []);
|
|
431
|
-
}, [
|
|
432
|
-
options,
|
|
433
|
-
type,
|
|
434
|
-
onValueChange
|
|
435
|
-
]);
|
|
436
|
-
const handleKeyDown = useCallback2((e) => {
|
|
437
|
-
if (e.key === "Enter") {
|
|
438
|
-
setSelectedId(null);
|
|
439
|
-
}
|
|
440
|
-
}, []);
|
|
441
|
-
const handleColorChange = useCallback2((id) => (hue) => {
|
|
442
|
-
const newOptions = options?.map((o) => o.id === id ? {
|
|
443
|
-
...o,
|
|
444
|
-
color: hue
|
|
445
|
-
} : o);
|
|
446
|
-
onValueChange(type, newOptions ?? []);
|
|
447
|
-
}, [
|
|
448
|
-
options,
|
|
449
|
-
type,
|
|
450
|
-
onValueChange
|
|
451
|
-
]);
|
|
452
|
-
useEffect2(() => {
|
|
453
|
-
if (selected && isNewOption && inputRef.current) {
|
|
454
|
-
inputRef.current.focus();
|
|
455
|
-
setIsNewOption(false);
|
|
456
|
-
}
|
|
457
|
-
}, [
|
|
458
|
-
selected,
|
|
459
|
-
isNewOption
|
|
460
|
-
]);
|
|
461
|
-
return /* @__PURE__ */ React4.createElement(Input4.Root, {
|
|
462
|
-
validationValence: status
|
|
463
|
-
}, /* @__PURE__ */ React4.createElement(InputHeader, {
|
|
464
|
-
error,
|
|
465
|
-
label
|
|
466
|
-
}), /* @__PURE__ */ React4.createElement("div", {
|
|
467
|
-
role: "none"
|
|
468
|
-
}, options && /* @__PURE__ */ React4.createElement(List.Root, {
|
|
469
|
-
items: options,
|
|
470
|
-
isItem: (item) => true,
|
|
471
|
-
onMove: readonly ? void 0 : handleMove,
|
|
472
|
-
readonly: !!readonly
|
|
473
|
-
}, ({ items }) => /* @__PURE__ */ React4.createElement("div", {
|
|
474
|
-
role: "list",
|
|
475
|
-
className: "is-full overflow-auto"
|
|
476
|
-
}, items?.map((item) => /* @__PURE__ */ React4.createElement("div", {
|
|
477
|
-
key: item.id
|
|
478
|
-
}, /* @__PURE__ */ React4.createElement(List.Item, {
|
|
479
|
-
role: "button",
|
|
480
|
-
item,
|
|
481
|
-
classNames: [
|
|
482
|
-
subtleHover,
|
|
483
|
-
"flex flex-col cursor-pointer rounded-sm"
|
|
484
|
-
],
|
|
485
|
-
"aria-expanded": selected === item.id
|
|
486
|
-
}, /* @__PURE__ */ React4.createElement("div", {
|
|
487
|
-
className: "flex items-center"
|
|
488
|
-
}, /* @__PURE__ */ React4.createElement(List.ItemDragHandle, {
|
|
489
|
-
disabled: !!readonly
|
|
490
|
-
}), /* @__PURE__ */ React4.createElement(List.ItemTitle, {
|
|
491
|
-
onClick: () => handleClick(item.id),
|
|
492
|
-
classNames: "flex-1"
|
|
493
|
-
}, /* @__PURE__ */ React4.createElement(Tag, {
|
|
494
|
-
palette: item.color
|
|
495
|
-
}, item.title || "\u200B")), /* @__PURE__ */ React4.createElement(IconButton, {
|
|
496
|
-
iconOnly: true,
|
|
497
|
-
variant: "ghost",
|
|
498
|
-
label: t(selected === item.id ? "collapse label" : "expand label", {
|
|
499
|
-
ns: "os"
|
|
500
|
-
}),
|
|
501
|
-
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
502
|
-
onClick: () => handleClick(item.id)
|
|
503
|
-
})), selected === item.id && /* @__PURE__ */ React4.createElement("div", {
|
|
504
|
-
className: "pli-cardSpacingInline plb-cardSpacingBlock flex flex-col gap-1 density-fine"
|
|
505
|
-
}, /* @__PURE__ */ React4.createElement(Input4.Label, {
|
|
506
|
-
classNames: "text-xs"
|
|
507
|
-
}, t("select option label")), /* @__PURE__ */ React4.createElement("div", {
|
|
508
|
-
className: "grid grid-cols-[1fr_min-content_min-content] gap-1"
|
|
509
|
-
}, /* @__PURE__ */ React4.createElement(Input4.TextInput, {
|
|
510
|
-
disabled: !!readonly,
|
|
511
|
-
placeholder: t("select option label placeholder"),
|
|
512
|
-
ref: selected === item.id ? inputRef : void 0,
|
|
513
|
-
value: item.title,
|
|
514
|
-
onChange: handleTitleChange(item.id),
|
|
515
|
-
onKeyDown: handleKeyDown,
|
|
516
|
-
classNames: "flex-1",
|
|
517
|
-
"data-no-submit": true
|
|
518
|
-
}), /* @__PURE__ */ React4.createElement(HuePicker, {
|
|
519
|
-
disabled: !!readonly,
|
|
520
|
-
value: item.color,
|
|
521
|
-
onChange: handleColorChange(item.id)
|
|
522
|
-
}), /* @__PURE__ */ React4.createElement(IconButton, {
|
|
523
|
-
disabled: !!readonly,
|
|
524
|
-
icon: "ph--trash--fill",
|
|
525
|
-
iconOnly: true,
|
|
526
|
-
label: t("select option delete"),
|
|
527
|
-
onClick: () => handleDelete(item.id)
|
|
528
|
-
})))))), /* @__PURE__ */ React4.createElement(IconButton, {
|
|
529
|
-
variant: "ghost",
|
|
530
|
-
icon: "ph--plus--regular",
|
|
531
|
-
label: t("select option add"),
|
|
532
|
-
onClick: handleAdd,
|
|
533
|
-
disabled: !!readonly,
|
|
534
|
-
classNames: "is-full"
|
|
535
|
-
})))));
|
|
536
|
-
} finally {
|
|
537
|
-
_effect.f();
|
|
263
|
+
}
|
|
264
|
+
default: {
|
|
265
|
+
return value3;
|
|
266
|
+
}
|
|
538
267
|
}
|
|
539
268
|
};
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
];
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
onBlur
|
|
575
|
-
}))));
|
|
576
|
-
} finally {
|
|
577
|
-
_effect.f();
|
|
269
|
+
var cellClassesForFieldType = ({ type, format }) => {
|
|
270
|
+
switch (format || type) {
|
|
271
|
+
case Format.TypeFormat.Markdown:
|
|
272
|
+
return void 0;
|
|
273
|
+
case Format.TypeFormat.Time:
|
|
274
|
+
case Format.TypeFormat.Timestamp:
|
|
275
|
+
case Format.TypeFormat.DateTime:
|
|
276
|
+
case Format.TypeFormat.Date:
|
|
277
|
+
case Format.TypeFormat.Duration:
|
|
278
|
+
return [
|
|
279
|
+
"font-mono",
|
|
280
|
+
"text-right"
|
|
281
|
+
];
|
|
282
|
+
case Format.TypeFormat.Currency:
|
|
283
|
+
return [
|
|
284
|
+
"text-right"
|
|
285
|
+
];
|
|
286
|
+
case Format.TypeFormat.JSON:
|
|
287
|
+
case Format.TypeFormat.DID:
|
|
288
|
+
return [
|
|
289
|
+
"font-mono"
|
|
290
|
+
];
|
|
291
|
+
case TypeEnum.Number:
|
|
292
|
+
case TypeEnum.Boolean:
|
|
293
|
+
return [
|
|
294
|
+
"text-right",
|
|
295
|
+
"font-mono"
|
|
296
|
+
];
|
|
297
|
+
case TypeEnum.String:
|
|
298
|
+
return void 0;
|
|
299
|
+
case TypeEnum.Ref:
|
|
300
|
+
return void 0;
|
|
301
|
+
default:
|
|
302
|
+
return void 0;
|
|
578
303
|
}
|
|
579
304
|
};
|
|
305
|
+
var pathNotUniqueError = (path) => ({
|
|
306
|
+
path: "path",
|
|
307
|
+
message: `'${path}' is already present`
|
|
308
|
+
});
|
|
580
309
|
|
|
581
|
-
// src/
|
|
582
|
-
import {
|
|
583
|
-
import
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
placeholder,
|
|
597
|
-
value: getValue3() ?? "",
|
|
598
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
599
|
-
onBlur
|
|
600
|
-
}), inputOnly && /* @__PURE__ */ React6.createElement(Input6.Validation, null, error));
|
|
601
|
-
} finally {
|
|
602
|
-
_effect.f();
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
var NumberInput = ({ type, label, inputOnly, readonly, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
606
|
-
var _effect = _useSignals6();
|
|
607
|
-
try {
|
|
608
|
-
const { status, error } = getStatus();
|
|
609
|
-
return readonly && !getValue3() ? null : readonly === "static" && inputOnly ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.Root, {
|
|
610
|
-
validationValence: status
|
|
611
|
-
}, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
612
|
-
error,
|
|
613
|
-
label
|
|
614
|
-
}), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.TextInput, {
|
|
615
|
-
type: "number",
|
|
616
|
-
disabled: !!readonly,
|
|
617
|
-
placeholder,
|
|
618
|
-
value: getValue3(),
|
|
619
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
620
|
-
onBlur
|
|
621
|
-
}), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
|
|
622
|
-
} finally {
|
|
623
|
-
_effect.f();
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
var BooleanInput = ({ type, label, inputOnly, getStatus, getValue: getValue3, onValueChange, readonly }) => {
|
|
627
|
-
var _effect = _useSignals6();
|
|
628
|
-
try {
|
|
629
|
-
const { status, error } = getStatus();
|
|
630
|
-
const checked = Boolean(getValue3());
|
|
631
|
-
const { t } = useTranslation4(translationKey);
|
|
632
|
-
return /* @__PURE__ */ React6.createElement(Input6.Root, {
|
|
633
|
-
validationValence: status
|
|
634
|
-
}, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
635
|
-
error,
|
|
636
|
-
label
|
|
637
|
-
}), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, t(checked ? "boolean input true value" : "boolean input false value")) : /* @__PURE__ */ React6.createElement(Input6.Switch, {
|
|
638
|
-
disabled: !!readonly,
|
|
639
|
-
checked,
|
|
640
|
-
onCheckedChange: (value2) => onValueChange(type, value2)
|
|
641
|
-
}), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
|
|
642
|
-
} finally {
|
|
643
|
-
_effect.f();
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
var SelectInput = ({ type, label, inputOnly, readonly, placeholder, options, getStatus, getValue: getValue3, onValueChange }) => {
|
|
647
|
-
var _effect = _useSignals6();
|
|
648
|
-
try {
|
|
649
|
-
const { status, error } = getStatus();
|
|
650
|
-
const value2 = getValue3();
|
|
651
|
-
const handleValueChange = useCallback3((value3) => onValueChange(type, value3), [
|
|
652
|
-
type,
|
|
653
|
-
onValueChange
|
|
654
|
-
]);
|
|
655
|
-
return readonly && !value2 ? null : /* @__PURE__ */ React6.createElement(Input6.Root, {
|
|
656
|
-
validationValence: status
|
|
657
|
-
}, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
658
|
-
error,
|
|
659
|
-
label
|
|
660
|
-
}), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value2)?.label ?? String(value2)) : /* @__PURE__ */ React6.createElement(Select.Root, {
|
|
661
|
-
value: value2,
|
|
662
|
-
onValueChange: handleValueChange
|
|
663
|
-
}, /* @__PURE__ */ React6.createElement(Select.TriggerButton, {
|
|
664
|
-
classNames: "is-full",
|
|
665
|
-
disabled: !!readonly,
|
|
666
|
-
placeholder
|
|
667
|
-
}), /* @__PURE__ */ React6.createElement(Select.Portal, null, /* @__PURE__ */ React6.createElement(Select.Content, null, /* @__PURE__ */ React6.createElement(Select.Viewport, null, options?.map(({ value: value3, label: label2 }) => (
|
|
668
|
-
// NOTE: Numeric values are converted to and from strings.
|
|
669
|
-
/* @__PURE__ */ React6.createElement(Select.Option, {
|
|
670
|
-
key: String(value3),
|
|
671
|
-
value: String(value3)
|
|
672
|
-
}, label2 ?? String(value3))
|
|
673
|
-
))), /* @__PURE__ */ React6.createElement(Select.Arrow, null)))), inputOnly && /* @__PURE__ */ React6.createElement(Input6.DescriptionAndValidation, null, error));
|
|
674
|
-
} finally {
|
|
675
|
-
_effect.f();
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
var MarkdownInput = ({ type, label, inputOnly, readonly, placeholder, getStatus, getValue: getValue3, onValueChange, onBlur }) => {
|
|
679
|
-
var _effect = _useSignals6();
|
|
680
|
-
try {
|
|
681
|
-
const { status, error } = getStatus();
|
|
682
|
-
const textareaRef = useRef2(null);
|
|
683
|
-
const adjustHeight = useCallback3(() => {
|
|
684
|
-
const textarea = textareaRef.current;
|
|
685
|
-
if (textarea) {
|
|
686
|
-
textarea.style.blockSize = "auto";
|
|
687
|
-
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
310
|
+
// src/util/formatting.ts
|
|
311
|
+
import { format as formatDate } from "date-fns/format";
|
|
312
|
+
import { Format as Format2, GeoLocation as GeoLocation2, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
|
|
313
|
+
var formatForDisplay = ({ type, format, value: value3, locale = void 0 }) => {
|
|
314
|
+
const formatScalar = (type2) => {
|
|
315
|
+
switch (type2) {
|
|
316
|
+
case TypeEnum2.Boolean:
|
|
317
|
+
return value3.toLocaleString().toUpperCase();
|
|
318
|
+
case TypeEnum2.Number:
|
|
319
|
+
return value3.toLocaleString(locale);
|
|
320
|
+
case TypeEnum2.String:
|
|
321
|
+
case TypeEnum2.Ref:
|
|
322
|
+
return String(value3);
|
|
323
|
+
default: {
|
|
324
|
+
return String(value3);
|
|
688
325
|
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
adjustHeight
|
|
694
|
-
]);
|
|
695
|
-
useEffect3(() => {
|
|
696
|
-
adjustHeight();
|
|
697
|
-
}, [
|
|
698
|
-
getValue3(),
|
|
699
|
-
adjustHeight
|
|
700
|
-
]);
|
|
701
|
-
return /* @__PURE__ */ React6.createElement(Input6.Root, {
|
|
702
|
-
validationValence: status
|
|
703
|
-
}, !inputOnly && /* @__PURE__ */ React6.createElement(InputHeader, {
|
|
704
|
-
error,
|
|
705
|
-
label
|
|
706
|
-
}), readonly === "static" ? /* @__PURE__ */ React6.createElement("p", null, getValue3() ?? "") : /* @__PURE__ */ React6.createElement(Input6.TextArea, {
|
|
707
|
-
ref: textareaRef,
|
|
708
|
-
disabled: !!readonly,
|
|
709
|
-
placeholder,
|
|
710
|
-
value: getValue3() ?? "",
|
|
711
|
-
classNames: "min-bs-auto max-bs-40 overflow-auto",
|
|
712
|
-
onChange: (event) => onValueChange(type, event.target.value),
|
|
713
|
-
onBlur,
|
|
714
|
-
style: {
|
|
715
|
-
resize: "none"
|
|
716
|
-
},
|
|
717
|
-
spellCheck: false
|
|
718
|
-
}), inputOnly && /* @__PURE__ */ React6.createElement(Input6.Validation, null, error));
|
|
719
|
-
} finally {
|
|
720
|
-
_effect.f();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
if (!format) {
|
|
329
|
+
return formatScalar(type);
|
|
721
330
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
|
|
726
|
-
import { useFocusFinders } from "@fluentui/react-tabster";
|
|
727
|
-
import React13, { useCallback as useCallback11, useEffect as useEffect7, useRef as useRef3 } from "react";
|
|
728
|
-
import { cardDialogOverflow, cardSpacing as cardSpacing2 } from "@dxos/react-ui-stack";
|
|
729
|
-
|
|
730
|
-
// src/components/Form/FormActions.tsx
|
|
731
|
-
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
732
|
-
import React8 from "react";
|
|
733
|
-
import { IconButton as IconButton2, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
734
|
-
import { cardSpacing } from "@dxos/react-ui-stack";
|
|
735
|
-
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
736
|
-
|
|
737
|
-
// src/components/Form/FormContext.tsx
|
|
738
|
-
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
739
|
-
import React7, { createContext, useCallback as useCallback7, useContext, useEffect as useEffect6, useMemo as useMemo3 } from "react";
|
|
740
|
-
import { raise } from "@dxos/debug";
|
|
741
|
-
import { getValue as getValue2 } from "@dxos/echo/internal";
|
|
742
|
-
import { createJsonPath as createJsonPath2 } from "@dxos/effect";
|
|
743
|
-
|
|
744
|
-
// src/hooks/useForm.ts
|
|
745
|
-
import * as SchemaAST from "effect/SchemaAST";
|
|
746
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
|
|
747
|
-
import { getValue, setValue } from "@dxos/echo/internal";
|
|
748
|
-
import { createJsonPath, fromEffectValidationPath } from "@dxos/effect";
|
|
749
|
-
import { invariant } from "@dxos/invariant";
|
|
750
|
-
import { log } from "@dxos/log";
|
|
751
|
-
import { validateSchema } from "@dxos/schema";
|
|
752
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useForm.ts";
|
|
753
|
-
var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, onSave }) => {
|
|
754
|
-
invariant(SchemaAST.isTypeLiteral(schema.ast), void 0, {
|
|
755
|
-
F: __dxlog_file,
|
|
756
|
-
L: 96,
|
|
757
|
-
S: void 0,
|
|
758
|
-
A: [
|
|
759
|
-
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
760
|
-
""
|
|
761
|
-
]
|
|
762
|
-
});
|
|
763
|
-
const [values, setValues] = useState3(initialValues);
|
|
764
|
-
useEffect4(() => {
|
|
765
|
-
setValues(initialValues);
|
|
766
|
-
}, [
|
|
767
|
-
initialValues
|
|
768
|
-
]);
|
|
769
|
-
const [touched, setTouched] = useState3(createKeySet(initialValues, false));
|
|
770
|
-
const [changed, setChanged] = useState3(createKeySet(initialValues, false));
|
|
771
|
-
const [errors, setErrors] = useState3({});
|
|
772
|
-
const [saving, setSaving] = useState3(false);
|
|
773
|
-
const validate = useCallback4((values2) => {
|
|
774
|
-
let errors2 = validateSchema(schema, values2) ?? [];
|
|
775
|
-
if (errors2.length === 0 && onValidate) {
|
|
776
|
-
const validatedValues = values2;
|
|
777
|
-
errors2 = onValidate(validatedValues) ?? [];
|
|
331
|
+
switch (format) {
|
|
332
|
+
case Format2.TypeFormat.Boolean: {
|
|
333
|
+
return formatScalar(TypeEnum2.Boolean);
|
|
778
334
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
return valid;
|
|
782
|
-
}, [
|
|
783
|
-
schema,
|
|
784
|
-
onValidate
|
|
785
|
-
]);
|
|
786
|
-
const [schemaDirty, setSchemaDirty] = useState3(false);
|
|
787
|
-
useEffect4(() => setSchemaDirty(true), [
|
|
788
|
-
schema
|
|
789
|
-
]);
|
|
790
|
-
useEffect4(() => {
|
|
791
|
-
if (schemaDirty) {
|
|
792
|
-
validate(values);
|
|
793
|
-
setSchemaDirty(false);
|
|
335
|
+
case Format2.TypeFormat.Number: {
|
|
336
|
+
return formatScalar(TypeEnum2.Number);
|
|
794
337
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
338
|
+
case Format2.TypeFormat.String:
|
|
339
|
+
case Format2.TypeFormat.Ref: {
|
|
340
|
+
return formatScalar(TypeEnum2.String);
|
|
341
|
+
}
|
|
342
|
+
case Format2.TypeFormat.Percent: {
|
|
343
|
+
return `${value3 * 100}%`;
|
|
344
|
+
}
|
|
345
|
+
case Format2.TypeFormat.Currency: {
|
|
346
|
+
return value3.toLocaleString(locale, {
|
|
347
|
+
style: "currency",
|
|
348
|
+
currency: "USD",
|
|
349
|
+
minimumFractionDigits: 2,
|
|
350
|
+
maximumFractionDigits: 2
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
case Format2.TypeFormat.Date: {
|
|
354
|
+
try {
|
|
355
|
+
return formatDate(new Date(value3), "yyyy-MM-dd");
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return "Invalid Date";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
case Format2.TypeFormat.Time: {
|
|
361
|
+
try {
|
|
362
|
+
return formatDate(new Date(value3), "HH:mm:ss");
|
|
363
|
+
} catch (error) {
|
|
364
|
+
return "Invalid Time";
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
case Format2.TypeFormat.DateTime: {
|
|
368
|
+
try {
|
|
369
|
+
return formatDate(new Date(value3), "yyyy-MM-dd HH:mm:ss");
|
|
370
|
+
} catch (error) {
|
|
371
|
+
return "Invalid DateTime";
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
case Format2.TypeFormat.GeoPoint: {
|
|
375
|
+
if (value3 === null || value3 === void 0) {
|
|
376
|
+
return "";
|
|
377
|
+
}
|
|
378
|
+
if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
|
|
379
|
+
const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
|
|
380
|
+
return `${latitude},${longitude}`;
|
|
381
|
+
}
|
|
382
|
+
return String(value3);
|
|
383
|
+
}
|
|
384
|
+
default: {
|
|
385
|
+
if (value3 === null || value3 === "undefined") {
|
|
386
|
+
return "";
|
|
387
|
+
}
|
|
388
|
+
return String(value3);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
var formatForEditing = ({ type, format, value: value3, locale = void 0 }) => {
|
|
393
|
+
const formatScalar = (type2) => {
|
|
394
|
+
switch (type2) {
|
|
395
|
+
case TypeEnum2.Boolean:
|
|
396
|
+
case TypeEnum2.Number:
|
|
397
|
+
case TypeEnum2.String:
|
|
398
|
+
case TypeEnum2.Ref:
|
|
399
|
+
return String(value3);
|
|
400
|
+
default:
|
|
401
|
+
return String(value3);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
if (!format) {
|
|
405
|
+
return formatScalar(type);
|
|
406
|
+
}
|
|
407
|
+
switch (format) {
|
|
408
|
+
case Format2.TypeFormat.Boolean:
|
|
409
|
+
case Format2.TypeFormat.Number:
|
|
410
|
+
case Format2.TypeFormat.String:
|
|
411
|
+
case Format2.TypeFormat.Ref: {
|
|
412
|
+
return formatScalar(type);
|
|
413
|
+
}
|
|
414
|
+
case Format2.TypeFormat.Percent: {
|
|
415
|
+
return String(value3 * 100);
|
|
416
|
+
}
|
|
417
|
+
case Format2.TypeFormat.Currency: {
|
|
418
|
+
return String(value3);
|
|
419
|
+
}
|
|
420
|
+
case Format2.TypeFormat.DateTime: {
|
|
421
|
+
const date = new Date(value3);
|
|
422
|
+
return date.toISOString();
|
|
423
|
+
}
|
|
424
|
+
case Format2.TypeFormat.Date: {
|
|
425
|
+
const date = new Date(value3);
|
|
426
|
+
return date.toISOString().split("T")[0];
|
|
427
|
+
}
|
|
428
|
+
case Format2.TypeFormat.Time: {
|
|
429
|
+
const date = new Date(value3);
|
|
430
|
+
return date.toISOString().split("T")[1].split(".")[0];
|
|
431
|
+
}
|
|
432
|
+
case Format2.TypeFormat.GeoPoint: {
|
|
433
|
+
if (value3 === null || value3 === void 0) {
|
|
434
|
+
return "";
|
|
435
|
+
}
|
|
436
|
+
if (Array.isArray(value3) && value3.length >= 2 && value3.every(Number.isFinite)) {
|
|
437
|
+
const { latitude, longitude } = GeoLocation2.fromGeoPoint(value3);
|
|
438
|
+
return `${latitude},${longitude}`;
|
|
439
|
+
}
|
|
440
|
+
return String(value3);
|
|
441
|
+
}
|
|
442
|
+
default: {
|
|
443
|
+
return String(value3);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/util/properties.ts
|
|
449
|
+
import * as Option from "effect/Option";
|
|
450
|
+
import { Annotation } from "@dxos/echo";
|
|
451
|
+
import { getProperties } from "@dxos/effect";
|
|
452
|
+
var getFormProperties = (ast) => {
|
|
453
|
+
return getProperties(ast).filter((prop) => Annotation.FormInputAnnotation.getFromAst(prop.type).pipe(Option.getOrElse(() => true)));
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
// src/util/refs.ts
|
|
457
|
+
import { Ref } from "@dxos/echo";
|
|
458
|
+
import { getArrayElementType, isArrayType } from "@dxos/effect";
|
|
459
|
+
var getRefProps = (ast) => {
|
|
460
|
+
if (isArrayType(ast)) {
|
|
461
|
+
const elementType = getArrayElementType(ast);
|
|
462
|
+
if (elementType) {
|
|
463
|
+
if (Ref.isRefType(elementType)) {
|
|
464
|
+
return {
|
|
465
|
+
ast: elementType,
|
|
466
|
+
isArray: true
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (Ref.isRefType(ast)) {
|
|
472
|
+
return {
|
|
473
|
+
ast,
|
|
474
|
+
isArray: false
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
return void 0;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// src/components/Form/fields/ArrayField.tsx
|
|
481
|
+
import * as Option3 from "effect/Option";
|
|
482
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
483
|
+
import React6, { useCallback as useCallback3 } from "react";
|
|
484
|
+
import { findNode as findNode2, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
|
|
485
|
+
import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
486
|
+
|
|
487
|
+
// src/components/Form/Form.tsx
|
|
488
|
+
import { createContext } from "@radix-ui/react-context";
|
|
489
|
+
import * as Schema2 from "effect/Schema";
|
|
490
|
+
import React5, { useEffect as useEffect3, useMemo as useMemo4, useRef } from "react";
|
|
491
|
+
import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
|
|
492
|
+
import { IconButton, ScrollArea, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
493
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
494
|
+
|
|
495
|
+
// src/hooks/useFormHandler.ts
|
|
496
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
497
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
498
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
499
|
+
import { createJsonPath, fromEffectValidationPath, getValue as getValue$, setValue as setValue$ } from "@dxos/effect";
|
|
500
|
+
import { log } from "@dxos/log";
|
|
501
|
+
import { useDefaultValue } from "@dxos/react-ui";
|
|
502
|
+
import { validateSchema } from "@dxos/schema";
|
|
503
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useFormHandler.ts";
|
|
504
|
+
var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: defaultValuesProp, onValuesChanged, onValidate, onSave, onCancel, ...props }) => {
|
|
505
|
+
const [changed, setChanged] = useState({});
|
|
506
|
+
const [touched, setTouched] = useState({});
|
|
507
|
+
const [errors, setErrors] = useState({});
|
|
508
|
+
const [saving, setSaving] = useState(false);
|
|
509
|
+
const defaultValues = useDefaultValue(defaultValuesProp, () => ({}));
|
|
510
|
+
const [values$, setValues] = useControllableState({
|
|
511
|
+
prop: valuesProp,
|
|
512
|
+
defaultProp: defaultValues,
|
|
513
|
+
onChange: () => {
|
|
514
|
+
setValues(valuesProp ?? defaultValues);
|
|
515
|
+
setChanged({});
|
|
516
|
+
setTouched({});
|
|
517
|
+
setErrors({});
|
|
518
|
+
setSaving(false);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
const values = values$;
|
|
522
|
+
const validate = useCallback((values2) => {
|
|
523
|
+
if (!schema) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
let errors2 = validateSchema(schema, values2) ?? [];
|
|
527
|
+
log("validate", {
|
|
528
|
+
values: values2,
|
|
529
|
+
errors: errors2
|
|
530
|
+
}, {
|
|
531
|
+
F: __dxlog_file,
|
|
532
|
+
L: 160,
|
|
533
|
+
S: void 0,
|
|
534
|
+
C: (f, a) => f(...a)
|
|
535
|
+
});
|
|
536
|
+
if (errors2.length === 0 && onValidate) {
|
|
537
|
+
const validatedValues = values2;
|
|
538
|
+
errors2 = onValidate(validatedValues) ?? [];
|
|
539
|
+
}
|
|
540
|
+
setErrors(flatMap(errors2));
|
|
541
|
+
const valid = errors2.length === 0;
|
|
542
|
+
return valid;
|
|
543
|
+
}, [
|
|
544
|
+
schema,
|
|
545
|
+
onValidate
|
|
546
|
+
]);
|
|
547
|
+
const [schemaChanged, setSchemaChanged] = useState(false);
|
|
548
|
+
useEffect(() => setSchemaChanged(true), [
|
|
549
|
+
schema
|
|
550
|
+
]);
|
|
551
|
+
useEffect(() => {
|
|
552
|
+
if (schemaChanged) {
|
|
553
|
+
validate(values);
|
|
554
|
+
setSchemaChanged(false);
|
|
555
|
+
}
|
|
556
|
+
}, [
|
|
557
|
+
validate,
|
|
558
|
+
values,
|
|
559
|
+
schemaChanged
|
|
560
|
+
]);
|
|
561
|
+
const isValid = useMemo(() => {
|
|
562
|
+
return Object.keys(errors).length === 0;
|
|
563
|
+
}, [
|
|
564
|
+
errors
|
|
565
|
+
]);
|
|
566
|
+
const canSave = useMemo(() => !saving && // Check if any error paths that are touched have errors.
|
|
567
|
+
!Object.entries(touched).some(([path, isTouched]) => isTouched && Object.keys(errors).some((errorPath) => errorPath === path || errorPath.startsWith(`${path}.`) || errorPath.startsWith(`${path}[`))), [
|
|
568
|
+
touched,
|
|
569
|
+
errors,
|
|
570
|
+
saving
|
|
571
|
+
]);
|
|
572
|
+
const handleSave = useCallback(async () => {
|
|
573
|
+
if (validate(values)) {
|
|
574
|
+
setSaving(true);
|
|
575
|
+
try {
|
|
576
|
+
await onSave?.(values, {
|
|
577
|
+
changed,
|
|
578
|
+
isValid
|
|
579
|
+
});
|
|
817
580
|
} finally {
|
|
818
581
|
setSaving(false);
|
|
819
582
|
}
|
|
@@ -822,11 +585,17 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
822
585
|
values,
|
|
823
586
|
validate,
|
|
824
587
|
onSave,
|
|
825
|
-
changed
|
|
588
|
+
changed,
|
|
589
|
+
isValid
|
|
590
|
+
]);
|
|
591
|
+
const handleCancel = useCallback(() => {
|
|
592
|
+
onCancel?.();
|
|
593
|
+
}, [
|
|
594
|
+
onCancel
|
|
826
595
|
]);
|
|
827
|
-
const getStatus =
|
|
596
|
+
const getStatus = useCallback((path) => {
|
|
828
597
|
const jsonPath = Array.isArray(path) ? createJsonPath(path) : path;
|
|
829
|
-
const
|
|
598
|
+
const [_, error] = Object.entries(errors).find(([errorPath]) => errorPath === jsonPath || errorPath.startsWith(`${jsonPath}.`) || errorPath.startsWith(`${jsonPath}[`)) ?? [];
|
|
830
599
|
const isTouched = touched[jsonPath];
|
|
831
600
|
if (!isTouched) {
|
|
832
601
|
return {
|
|
@@ -835,112 +604,120 @@ var useForm = ({ schema, initialValues, onValuesChanged, onValidate, onValid, on
|
|
|
835
604
|
};
|
|
836
605
|
}
|
|
837
606
|
return {
|
|
838
|
-
status:
|
|
839
|
-
error:
|
|
607
|
+
status: error ? "error" : void 0,
|
|
608
|
+
error: error ? error ?? void 0 : void 0
|
|
840
609
|
};
|
|
841
610
|
}, [
|
|
842
611
|
errors,
|
|
843
612
|
touched
|
|
844
613
|
]);
|
|
845
|
-
const
|
|
846
|
-
return getValue(values, createJsonPath(path));
|
|
614
|
+
const getValue = useCallback((path) => {
|
|
615
|
+
return getValue$(values, createJsonPath(path));
|
|
847
616
|
}, [
|
|
848
617
|
values
|
|
849
618
|
]);
|
|
850
|
-
const onValueChange =
|
|
619
|
+
const onValueChange = useCallback((path, type, value3) => {
|
|
620
|
+
log("onValueChange", {
|
|
621
|
+
path,
|
|
622
|
+
value: value3
|
|
623
|
+
}, {
|
|
624
|
+
F: __dxlog_file,
|
|
625
|
+
L: 259,
|
|
626
|
+
S: void 0,
|
|
627
|
+
C: (f, a) => f(...a)
|
|
628
|
+
});
|
|
851
629
|
const jsonPath = createJsonPath(path);
|
|
852
|
-
let parsedValue =
|
|
630
|
+
let parsedValue = value3;
|
|
853
631
|
try {
|
|
854
|
-
if (type === "
|
|
855
|
-
parsedValue = parseFloat(
|
|
632
|
+
if (type._tag === "NumberKeyword") {
|
|
633
|
+
parsedValue = parseFloat(value3) || 0;
|
|
856
634
|
}
|
|
857
635
|
} catch (err) {
|
|
858
636
|
log.catch(err, void 0, {
|
|
859
637
|
F: __dxlog_file,
|
|
860
|
-
L:
|
|
638
|
+
L: 268,
|
|
861
639
|
S: void 0,
|
|
862
640
|
C: (f, a) => f(...a)
|
|
863
641
|
});
|
|
864
642
|
parsedValue = void 0;
|
|
865
643
|
}
|
|
866
|
-
const newValues = {
|
|
867
|
-
...setValue(values, jsonPath, parsedValue)
|
|
644
|
+
const newValues = Obj2.isObject(values) ? (setValueEchoAware(values, jsonPath, parsedValue), values) : {
|
|
645
|
+
...setValue$(values, jsonPath, parsedValue)
|
|
868
646
|
};
|
|
869
647
|
setValues(newValues);
|
|
870
648
|
const newChanged = {
|
|
871
|
-
...changed,
|
|
872
649
|
[jsonPath]: true
|
|
873
650
|
};
|
|
874
|
-
setChanged(
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
651
|
+
setChanged({
|
|
652
|
+
...changed,
|
|
653
|
+
...newChanged
|
|
654
|
+
});
|
|
655
|
+
const isValid2 = validate(newValues);
|
|
656
|
+
onValuesChanged?.(newValues, {
|
|
657
|
+
isValid: isValid2,
|
|
658
|
+
changed: newChanged
|
|
659
|
+
});
|
|
882
660
|
}, [
|
|
883
661
|
values,
|
|
884
|
-
|
|
662
|
+
changed,
|
|
885
663
|
validate,
|
|
886
|
-
|
|
887
|
-
changed
|
|
664
|
+
onValuesChanged
|
|
888
665
|
]);
|
|
889
|
-
const
|
|
666
|
+
const onBlur = useCallback(async (path) => {
|
|
890
667
|
const jsonPath = createJsonPath(path);
|
|
891
668
|
setTouched((touched2) => ({
|
|
892
669
|
...touched2,
|
|
893
670
|
[jsonPath]: true
|
|
894
671
|
}));
|
|
895
|
-
validate(values);
|
|
672
|
+
const isValid2 = validate(values);
|
|
673
|
+
if (Object.keys(changed).length > 0 && isValid2 && autoSave) {
|
|
674
|
+
await onSave?.(values, {
|
|
675
|
+
changed,
|
|
676
|
+
isValid: isValid2
|
|
677
|
+
});
|
|
678
|
+
}
|
|
896
679
|
}, [
|
|
897
680
|
validate,
|
|
898
|
-
values
|
|
681
|
+
values,
|
|
682
|
+
changed,
|
|
683
|
+
autoSave,
|
|
684
|
+
onSave
|
|
899
685
|
]);
|
|
900
|
-
return
|
|
686
|
+
return useMemo(() => ({
|
|
901
687
|
// State.
|
|
688
|
+
schema,
|
|
902
689
|
values,
|
|
903
690
|
errors,
|
|
904
691
|
touched,
|
|
905
692
|
changed,
|
|
693
|
+
isValid,
|
|
906
694
|
canSave,
|
|
907
|
-
|
|
695
|
+
autoSave,
|
|
908
696
|
// Actions.
|
|
909
|
-
handleSave,
|
|
697
|
+
onSave: handleSave,
|
|
698
|
+
onCancel: handleCancel,
|
|
910
699
|
// Field utils.
|
|
911
700
|
getStatus,
|
|
912
|
-
getValue
|
|
701
|
+
getValue,
|
|
702
|
+
onBlur,
|
|
913
703
|
onValueChange,
|
|
914
|
-
|
|
704
|
+
...props
|
|
915
705
|
}), [
|
|
706
|
+
schema,
|
|
916
707
|
values,
|
|
917
708
|
errors,
|
|
918
709
|
touched,
|
|
919
710
|
changed,
|
|
920
711
|
canSave,
|
|
921
|
-
|
|
922
|
-
handleSave,
|
|
712
|
+
isValid,
|
|
923
713
|
getStatus,
|
|
924
|
-
|
|
714
|
+
getValue,
|
|
715
|
+
onBlur,
|
|
925
716
|
onValueChange,
|
|
926
|
-
|
|
717
|
+
onSave,
|
|
718
|
+
onCancel
|
|
927
719
|
]);
|
|
928
720
|
};
|
|
929
|
-
var createKeySet = (obj, value2) => {
|
|
930
|
-
invariant(obj, void 0, {
|
|
931
|
-
F: __dxlog_file,
|
|
932
|
-
L: 280,
|
|
933
|
-
S: void 0,
|
|
934
|
-
A: [
|
|
935
|
-
"obj",
|
|
936
|
-
""
|
|
937
|
-
]
|
|
938
|
-
});
|
|
939
|
-
return Object.keys(obj).reduce((acc, key) => ({
|
|
940
|
-
...acc,
|
|
941
|
-
[key]: value2
|
|
942
|
-
}), {});
|
|
943
|
-
};
|
|
944
721
|
var flatMap = (errors) => {
|
|
945
722
|
return errors.reduce((result, { path, message }) => {
|
|
946
723
|
const jsonPath = fromEffectValidationPath(path);
|
|
@@ -951,1641 +728,1786 @@ var flatMap = (errors) => {
|
|
|
951
728
|
}, {});
|
|
952
729
|
};
|
|
953
730
|
|
|
954
|
-
// src/hooks/
|
|
955
|
-
import { useCallback as
|
|
956
|
-
import {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
const { objects } = await query.run();
|
|
966
|
-
return objects.map((object) => {
|
|
967
|
-
const dxn = Obj.getDXN(object);
|
|
968
|
-
if (!dxn) {
|
|
969
|
-
return void 0;
|
|
731
|
+
// src/hooks/useKeyHandler.tsx
|
|
732
|
+
import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
733
|
+
import { addEventListener } from "@dxos/async";
|
|
734
|
+
var useKeyHandler = (formElement, form) => {
|
|
735
|
+
const handleKeyDown = useCallback2((event) => {
|
|
736
|
+
switch (event.key) {
|
|
737
|
+
case "Enter": {
|
|
738
|
+
if (event.metaKey && form.canSave) {
|
|
739
|
+
form.onSave();
|
|
740
|
+
}
|
|
741
|
+
break;
|
|
970
742
|
}
|
|
971
|
-
|
|
972
|
-
dxn,
|
|
973
|
-
label: Obj.getLabel(object) ?? object?.id ?? ""
|
|
974
|
-
};
|
|
975
|
-
return item;
|
|
976
|
-
}).filter(isNonNullable);
|
|
743
|
+
}
|
|
977
744
|
}, [
|
|
978
|
-
|
|
745
|
+
form.isValid,
|
|
746
|
+
form.canSave,
|
|
747
|
+
form.onSave,
|
|
748
|
+
form.autoSave
|
|
979
749
|
]);
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
// src/hooks/useQueryRefOptions.ts
|
|
983
|
-
import { useCallback as useCallback6, useEffect as useEffect5, useState as useState4 } from "react";
|
|
984
|
-
import { log as log2 } from "@dxos/log";
|
|
985
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/hooks/useQueryRefOptions.ts";
|
|
986
|
-
var useQueryRefOptions = ({ refTypeInfo, onQueryRefOptions }) => {
|
|
987
|
-
const [options, setOptions] = useState4([]);
|
|
988
|
-
const [loading, setLoading] = useState4(false);
|
|
989
|
-
const [state, setState] = useState4({});
|
|
990
|
-
const update = useCallback6(() => setState({}), []);
|
|
991
|
-
useEffect5(() => {
|
|
992
|
-
if (!refTypeInfo || !onQueryRefOptions) {
|
|
750
|
+
useEffect2(() => {
|
|
751
|
+
if (!formElement) {
|
|
993
752
|
return;
|
|
994
753
|
}
|
|
995
|
-
|
|
996
|
-
setLoading(true);
|
|
997
|
-
try {
|
|
998
|
-
const fetchedOptions = await onQueryRefOptions(refTypeInfo);
|
|
999
|
-
setOptions(fetchedOptions.map((option) => {
|
|
1000
|
-
const dxn = option.dxn.toString();
|
|
1001
|
-
return {
|
|
1002
|
-
id: dxn,
|
|
1003
|
-
label: option.label ?? dxn,
|
|
1004
|
-
hue: "neutral"
|
|
1005
|
-
};
|
|
1006
|
-
}));
|
|
1007
|
-
} catch (error) {
|
|
1008
|
-
log2.error("Failed to fetch ref options:", error, {
|
|
1009
|
-
F: __dxlog_file2,
|
|
1010
|
-
L: 51,
|
|
1011
|
-
S: void 0,
|
|
1012
|
-
C: (f, a) => f(...a)
|
|
1013
|
-
});
|
|
1014
|
-
setOptions([]);
|
|
1015
|
-
} finally {
|
|
1016
|
-
setLoading(false);
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
void fetchOptions();
|
|
754
|
+
return addEventListener(formElement, "keydown", handleKeyDown);
|
|
1020
755
|
}, [
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
state
|
|
756
|
+
formElement,
|
|
757
|
+
handleKeyDown
|
|
1024
758
|
]);
|
|
1025
|
-
return {
|
|
1026
|
-
options,
|
|
1027
|
-
update,
|
|
1028
|
-
loading
|
|
1029
|
-
};
|
|
1030
759
|
};
|
|
1031
760
|
|
|
1032
|
-
// src/components/Form/
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
var
|
|
1038
|
-
const
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
onTouched,
|
|
1057
|
-
stablePath
|
|
1058
|
-
]);
|
|
761
|
+
// src/components/Form/FormFieldComponent.tsx
|
|
762
|
+
import React2, { Component } from "react";
|
|
763
|
+
import { Icon, Input as Input2, Tooltip } from "@dxos/react-ui";
|
|
764
|
+
import { errorText, mx as mx2 } from "@dxos/ui-theme";
|
|
765
|
+
var labelSpacing = "mbs-inputSpacingBlock mbe-labelSpacingBlock";
|
|
766
|
+
var FormFieldLabel = ({ label, error, readonly, asChild }) => {
|
|
767
|
+
const Label = readonly || asChild ? "span" : Input2.Label;
|
|
768
|
+
const labelProps = readonly || asChild ? {
|
|
769
|
+
className: "text-description text-sm"
|
|
770
|
+
} : {
|
|
771
|
+
classNames: "!mlb-0 text-sm"
|
|
772
|
+
};
|
|
773
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
774
|
+
role: "none",
|
|
775
|
+
className: mx2("flex justify-between items-center", labelSpacing)
|
|
776
|
+
}, /* @__PURE__ */ React2.createElement(Label, labelProps, label), error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
777
|
+
asChild: true,
|
|
778
|
+
content: error,
|
|
779
|
+
side: "bottom"
|
|
780
|
+
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
781
|
+
icon: "ph--warning--regular",
|
|
782
|
+
size: 4,
|
|
783
|
+
classNames: errorText
|
|
784
|
+
})));
|
|
1059
785
|
};
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
const inputIsTextarea = event.target.tagName.toLowerCase() === "textarea";
|
|
1068
|
-
const inputOptOut = event.target.hasAttribute("data-no-submit") || event.target.closest("[data-no-submit]") !== null;
|
|
1069
|
-
const shouldSubmitRegularInput = !inputIsTextarea && keyIsEnter && !modifierUsed;
|
|
1070
|
-
const shouldSubmitTextarea = inputIsTextarea && keyIsEnter && event.metaKey;
|
|
1071
|
-
if ((shouldSubmitRegularInput || shouldSubmitTextarea) && !inputOptOut) {
|
|
1072
|
-
if (!autoSave && form.canSave) {
|
|
1073
|
-
form.handleSave();
|
|
1074
|
-
}
|
|
1075
|
-
if (autoSave && form.formIsValid) {
|
|
1076
|
-
event.target.blur();
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}, [
|
|
1080
|
-
form.canSave,
|
|
1081
|
-
form.formIsValid,
|
|
1082
|
-
form.handleSave,
|
|
1083
|
-
autoSave
|
|
1084
|
-
]);
|
|
1085
|
-
useEffect6(() => {
|
|
1086
|
-
if (!formRef?.current) {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
const formElement = formRef.current;
|
|
1090
|
-
formElement.addEventListener("keydown", handleKeyDown);
|
|
1091
|
-
return () => formElement.removeEventListener("keydown", handleKeyDown);
|
|
1092
|
-
}, [
|
|
1093
|
-
formRef,
|
|
1094
|
-
form.canSave,
|
|
1095
|
-
form.formIsValid,
|
|
1096
|
-
form.handleSave,
|
|
1097
|
-
autoSave
|
|
1098
|
-
]);
|
|
1099
|
-
return /* @__PURE__ */ React7.createElement(FormContext.Provider, {
|
|
1100
|
-
value: form
|
|
1101
|
-
}, children);
|
|
1102
|
-
} finally {
|
|
1103
|
-
_effect.f();
|
|
786
|
+
FormFieldLabel.displayName = "Form.FieldLabel";
|
|
787
|
+
var FormFieldWrapper = (props) => {
|
|
788
|
+
const { children, readonly, layout, label, getStatus, getValue } = props;
|
|
789
|
+
const { status, error } = getStatus();
|
|
790
|
+
const value3 = getValue();
|
|
791
|
+
if (layout === "static" && value3 == null) {
|
|
792
|
+
return null;
|
|
1104
793
|
}
|
|
794
|
+
const str = String(value3 ?? "");
|
|
795
|
+
return /* @__PURE__ */ React2.createElement(Input2.Root, {
|
|
796
|
+
validationValence: status
|
|
797
|
+
}, layout !== "inline" && /* @__PURE__ */ React2.createElement(FormFieldLabel, {
|
|
798
|
+
error,
|
|
799
|
+
readonly,
|
|
800
|
+
label
|
|
801
|
+
}), layout === "static" ? /* @__PURE__ */ React2.createElement("p", null, str) : children ? children({
|
|
802
|
+
value: value3
|
|
803
|
+
}) : null, layout === "full" && /* @__PURE__ */ React2.createElement(Input2.DescriptionAndValidation, null, /* @__PURE__ */ React2.createElement(Input2.Validation, null, error)));
|
|
1105
804
|
};
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1130
|
-
|
|
805
|
+
var FormFieldErrorBoundary = class extends Component {
|
|
806
|
+
static getDerivedStateFromError(error) {
|
|
807
|
+
return {
|
|
808
|
+
error
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
state = {
|
|
812
|
+
error: void 0
|
|
813
|
+
};
|
|
814
|
+
componentDidUpdate(prevProps) {
|
|
815
|
+
if (prevProps.path !== this.props.path) {
|
|
816
|
+
this.resetError();
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
render() {
|
|
820
|
+
if (this.state.error) {
|
|
821
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
822
|
+
className: "flex gap-2 border border-roseFill font-mono text-sm"
|
|
823
|
+
}, /* @__PURE__ */ React2.createElement("span", {
|
|
824
|
+
className: "bg-roseFill text-surfaceText pli-1 font-thin"
|
|
825
|
+
}, "ERROR"), String(this.props.path?.join(".")));
|
|
826
|
+
}
|
|
827
|
+
return this.props.children;
|
|
828
|
+
}
|
|
829
|
+
resetError() {
|
|
830
|
+
this.setState({
|
|
831
|
+
error: void 0
|
|
832
|
+
});
|
|
1131
833
|
}
|
|
1132
834
|
};
|
|
1133
835
|
|
|
1134
|
-
// src/components/Form/
|
|
1135
|
-
import {
|
|
1136
|
-
import
|
|
1137
|
-
import * as Schema from "effect/Schema";
|
|
1138
|
-
import * as SchemaAST4 from "effect/SchemaAST";
|
|
1139
|
-
import * as StringEffect from "effect/String";
|
|
1140
|
-
import React12, { Component, forwardRef as forwardRef2, useMemo as useMemo6 } from "react";
|
|
1141
|
-
import { createJsonPath as createJsonPath3, findNode as findNode3, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2 } from "@dxos/effect";
|
|
1142
|
-
import { mx as mx6 } from "@dxos/react-ui-theme";
|
|
1143
|
-
import { getSchemaProperties as getSchemaProperties2 } from "@dxos/schema";
|
|
836
|
+
// src/components/Form/FormFieldSet.tsx
|
|
837
|
+
import React4, { forwardRef, useMemo as useMemo3 } from "react";
|
|
838
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
1144
839
|
import { isTruthy } from "@dxos/util";
|
|
1145
840
|
|
|
1146
|
-
// src/
|
|
1147
|
-
import
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
841
|
+
// src/components/Form/FormField.tsx
|
|
842
|
+
import * as Match from "effect/Match";
|
|
843
|
+
import * as Option2 from "effect/Option";
|
|
844
|
+
import * as Schema from "effect/Schema";
|
|
845
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
846
|
+
import * as String2 from "effect/String";
|
|
847
|
+
import React3, { useMemo as useMemo2 } from "react";
|
|
848
|
+
import { Format as Format3 } from "@dxos/echo";
|
|
849
|
+
import { createJsonPath as createJsonPath2, findNode, getAnnotation, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion, isNestedType } from "@dxos/effect";
|
|
850
|
+
import { useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
851
|
+
var FormField = (props) => {
|
|
852
|
+
const {
|
|
853
|
+
type,
|
|
854
|
+
name,
|
|
855
|
+
path,
|
|
856
|
+
projection,
|
|
857
|
+
fieldMap,
|
|
858
|
+
fieldProvider,
|
|
859
|
+
readonly,
|
|
860
|
+
layout,
|
|
861
|
+
// RefFieldProps
|
|
862
|
+
createOptionLabel,
|
|
863
|
+
createOptionIcon,
|
|
864
|
+
createInitialValuePath,
|
|
865
|
+
db,
|
|
866
|
+
schemaHook,
|
|
867
|
+
getOptions: getRefOptions,
|
|
868
|
+
onCreate
|
|
869
|
+
} = props;
|
|
870
|
+
const { t } = useTranslation2(translationKey);
|
|
871
|
+
const title = getAnnotation(SchemaAST.TitleAnnotationId)(type);
|
|
872
|
+
const description = getAnnotation(SchemaAST.DescriptionAnnotationId)(type);
|
|
873
|
+
const examples = getAnnotation(SchemaAST.ExamplesAnnotationId)(type);
|
|
874
|
+
const label = useMemo2(() => title ?? String2.capitalize(name), [
|
|
875
|
+
title,
|
|
876
|
+
name
|
|
877
|
+
]);
|
|
878
|
+
const placeholder = useMemo2(() => examples?.length ? `${t("example placeholder")}: ${examples[0]}` : description ?? label, [
|
|
879
|
+
examples,
|
|
880
|
+
description,
|
|
881
|
+
label
|
|
882
|
+
]);
|
|
883
|
+
const fieldState = useFormFieldState(FormField.displayName, path);
|
|
884
|
+
const fieldProps = {
|
|
885
|
+
type,
|
|
886
|
+
format: Format3.FormatAnnotation.getFromAst(type).pipe((annotation) => Option2.getOrUndefined(annotation)),
|
|
887
|
+
readonly,
|
|
888
|
+
label,
|
|
889
|
+
placeholder,
|
|
890
|
+
layout,
|
|
891
|
+
...fieldState
|
|
892
|
+
};
|
|
893
|
+
const jsonPath = createJsonPath2(path ?? []);
|
|
894
|
+
const CustomField = fieldMap?.[jsonPath];
|
|
895
|
+
if (CustomField) {
|
|
896
|
+
return /* @__PURE__ */ React3.createElement(CustomField, fieldProps);
|
|
1151
897
|
}
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
} else if (lowercaseValue === "1" || lowercaseValue === "true") {
|
|
1160
|
-
return true;
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
return Boolean(value2);
|
|
1164
|
-
}
|
|
1165
|
-
case TypeEnum.Number: {
|
|
1166
|
-
const cleaned = typeof value2 === "string" ? value2.replace(/[^0-9.-]+/g, "") : value2;
|
|
1167
|
-
const num = Number(cleaned);
|
|
1168
|
-
return Number.isNaN(num) ? null : num;
|
|
1169
|
-
}
|
|
1170
|
-
case TypeEnum.String:
|
|
1171
|
-
case TypeEnum.Ref:
|
|
1172
|
-
return String(value2);
|
|
1173
|
-
default: {
|
|
1174
|
-
return value2;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
if (!format) {
|
|
1179
|
-
return parseScalar(type);
|
|
898
|
+
const component = fieldProvider?.({
|
|
899
|
+
schema: Schema.make(type),
|
|
900
|
+
prop: name,
|
|
901
|
+
fieldProps
|
|
902
|
+
});
|
|
903
|
+
if (component) {
|
|
904
|
+
return component;
|
|
1180
905
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
906
|
+
if (isArrayType2(type)) {
|
|
907
|
+
return /* @__PURE__ */ React3.createElement(ArrayField, {
|
|
908
|
+
fieldProps: fieldState,
|
|
909
|
+
label,
|
|
910
|
+
...props
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
const Field = getFormField(fieldProps);
|
|
914
|
+
if (Field) {
|
|
915
|
+
return /* @__PURE__ */ React3.createElement(Field, fieldProps);
|
|
916
|
+
}
|
|
917
|
+
const options = getOptions(type);
|
|
918
|
+
if (options) {
|
|
919
|
+
return /* @__PURE__ */ React3.createElement(SelectField, {
|
|
920
|
+
...fieldProps,
|
|
921
|
+
options: options.map((option) => ({
|
|
922
|
+
value: option,
|
|
923
|
+
label: option.toString()
|
|
924
|
+
}))
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
const refProps = getRefProps(type);
|
|
928
|
+
if (refProps) {
|
|
929
|
+
return /* @__PURE__ */ React3.createElement(RefField, {
|
|
930
|
+
...fieldProps,
|
|
931
|
+
...refProps,
|
|
932
|
+
createOptionLabel,
|
|
933
|
+
createOptionIcon,
|
|
934
|
+
createInitialValuePath,
|
|
935
|
+
db,
|
|
936
|
+
schemaHook,
|
|
937
|
+
getOptions: getRefOptions,
|
|
938
|
+
onCreate
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
if (isNestedType(type)) {
|
|
942
|
+
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
943
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST.isTypeLiteral);
|
|
944
|
+
if (typeLiteral) {
|
|
945
|
+
const schema = Schema.make(typeLiteral);
|
|
946
|
+
return /* @__PURE__ */ React3.createElement(FormFieldSet, {
|
|
947
|
+
schema,
|
|
948
|
+
path,
|
|
949
|
+
readonly,
|
|
950
|
+
layout,
|
|
951
|
+
label,
|
|
952
|
+
projection,
|
|
953
|
+
fieldMap,
|
|
954
|
+
fieldProvider,
|
|
955
|
+
createOptionLabel,
|
|
956
|
+
createOptionIcon,
|
|
957
|
+
createInitialValuePath,
|
|
958
|
+
db,
|
|
959
|
+
schemaHook,
|
|
960
|
+
getOptions: getRefOptions,
|
|
961
|
+
onCreate
|
|
962
|
+
});
|
|
1223
963
|
}
|
|
1224
964
|
}
|
|
965
|
+
return null;
|
|
1225
966
|
};
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
case
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
case
|
|
1240
|
-
return
|
|
1241
|
-
"text-right"
|
|
1242
|
-
];
|
|
1243
|
-
case Format.TypeFormat.JSON:
|
|
1244
|
-
case Format.TypeFormat.DID:
|
|
1245
|
-
return [
|
|
1246
|
-
"font-mono"
|
|
1247
|
-
];
|
|
1248
|
-
case TypeEnum.Number:
|
|
1249
|
-
case TypeEnum.Boolean:
|
|
1250
|
-
return [
|
|
1251
|
-
"text-right",
|
|
1252
|
-
"font-mono"
|
|
1253
|
-
];
|
|
1254
|
-
case TypeEnum.String:
|
|
1255
|
-
return void 0;
|
|
1256
|
-
case TypeEnum.Ref:
|
|
1257
|
-
return void 0;
|
|
1258
|
-
default:
|
|
1259
|
-
return void 0;
|
|
967
|
+
FormField.displayName = "Form.FormField";
|
|
968
|
+
var getFormField = ({ type, format }) => {
|
|
969
|
+
const formatField = Match.value(format).pipe(Match.withReturnType(), Match.when(Format3.TypeFormat.GeoPoint, () => GeoPointField), Match.when(Format3.TypeFormat.Markdown, () => MarkdownField), Match.when(Format3.TypeFormat.Text, () => TextAreaField), Match.orElse(() => void 0));
|
|
970
|
+
if (formatField) {
|
|
971
|
+
return formatField;
|
|
972
|
+
}
|
|
973
|
+
switch (type._tag) {
|
|
974
|
+
// TODO(wittjosiah): Schema.Any is currently used to represent template inputs.
|
|
975
|
+
case "AnyKeyword":
|
|
976
|
+
case "StringKeyword":
|
|
977
|
+
return TextField;
|
|
978
|
+
case "NumberKeyword":
|
|
979
|
+
return NumberField;
|
|
980
|
+
case "BooleanKeyword":
|
|
981
|
+
return BooleanField;
|
|
1260
982
|
}
|
|
1261
983
|
};
|
|
1262
|
-
var
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
});
|
|
1266
|
-
|
|
1267
|
-
// src/util/formatting.ts
|
|
1268
|
-
import { format as formatDate } from "date-fns/format";
|
|
1269
|
-
import { Format as Format2, GeoLocation as GeoLocation3, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
|
|
1270
|
-
var formatForDisplay = ({ type, format, value: value2, locale = void 0 }) => {
|
|
1271
|
-
const formatScalar = (type2) => {
|
|
1272
|
-
switch (type2) {
|
|
1273
|
-
case TypeEnum2.Boolean:
|
|
1274
|
-
return value2.toLocaleString().toUpperCase();
|
|
1275
|
-
case TypeEnum2.Number:
|
|
1276
|
-
return value2.toLocaleString(locale);
|
|
1277
|
-
case TypeEnum2.String:
|
|
1278
|
-
case TypeEnum2.Ref:
|
|
1279
|
-
return String(value2);
|
|
1280
|
-
default: {
|
|
1281
|
-
return String(value2);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
if (!format) {
|
|
1286
|
-
return formatScalar(type);
|
|
984
|
+
var getOptions = (ast) => {
|
|
985
|
+
if (isLiteralUnion(ast)) {
|
|
986
|
+
return ast.types.map((type) => type.literal).filter((v) => v !== null);
|
|
1287
987
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
return formatScalar(TypeEnum2.String);
|
|
1298
|
-
}
|
|
1299
|
-
case Format2.TypeFormat.Percent: {
|
|
1300
|
-
return `${value2 * 100}%`;
|
|
1301
|
-
}
|
|
1302
|
-
case Format2.TypeFormat.Currency: {
|
|
1303
|
-
return value2.toLocaleString(locale, {
|
|
1304
|
-
style: "currency",
|
|
1305
|
-
currency: "USD",
|
|
1306
|
-
minimumFractionDigits: 2,
|
|
1307
|
-
maximumFractionDigits: 2
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
case Format2.TypeFormat.Date: {
|
|
1311
|
-
try {
|
|
1312
|
-
return formatDate(new Date(value2), "yyyy-MM-dd");
|
|
1313
|
-
} catch (error) {
|
|
1314
|
-
return "Invalid Date";
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
case Format2.TypeFormat.Time: {
|
|
1318
|
-
try {
|
|
1319
|
-
return formatDate(new Date(value2), "HH:mm:ss");
|
|
1320
|
-
} catch (error) {
|
|
1321
|
-
return "Invalid Time";
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
case Format2.TypeFormat.DateTime: {
|
|
1325
|
-
try {
|
|
1326
|
-
return formatDate(new Date(value2), "yyyy-MM-dd HH:mm:ss");
|
|
1327
|
-
} catch (error) {
|
|
1328
|
-
return "Invalid DateTime";
|
|
1329
|
-
}
|
|
988
|
+
return Format3.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option2.getOrUndefined(annotation));
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
// src/components/Form/FormFieldSet.tsx
|
|
992
|
+
var FormFieldSet = /* @__PURE__ */ forwardRef(({ classNames, label, schema, readonly, path, exclude, sort, projection, layout, ...props }, forwardRef4) => {
|
|
993
|
+
const values = useFormValues(FormFieldSet.displayName, path);
|
|
994
|
+
const properties = useMemo3(() => {
|
|
995
|
+
if (!schema) {
|
|
996
|
+
return [];
|
|
1330
997
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
998
|
+
const props2 = getFormProperties(schema.ast);
|
|
999
|
+
if (projection) {
|
|
1000
|
+
const fieldProjections = projection.getFieldProjections();
|
|
1001
|
+
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
1002
|
+
const visibleProps = props2.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
1003
|
+
const orderedProps = [];
|
|
1004
|
+
for (const fieldProjection of fieldProjections) {
|
|
1005
|
+
const fieldPath = String(fieldProjection.field.path);
|
|
1006
|
+
const prop = visibleProps.find((p) => p.name === fieldPath);
|
|
1007
|
+
if (prop) {
|
|
1008
|
+
orderedProps.push(prop);
|
|
1009
|
+
}
|
|
1338
1010
|
}
|
|
1339
|
-
|
|
1011
|
+
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
1012
|
+
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
1013
|
+
orderedProps.push(...remainingProps);
|
|
1014
|
+
return orderedProps;
|
|
1340
1015
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1016
|
+
const filtered = exclude ? exclude(props2) : props2;
|
|
1017
|
+
return sort ? filtered.sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filtered;
|
|
1018
|
+
}, [
|
|
1019
|
+
schema,
|
|
1020
|
+
values,
|
|
1021
|
+
exclude,
|
|
1022
|
+
sort,
|
|
1023
|
+
projection?.fields
|
|
1024
|
+
]);
|
|
1025
|
+
if ((readonly || layout === "static") && values == null) {
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1029
|
+
role: "form",
|
|
1030
|
+
className: mx3("is-full", layout === "inline" && "flex flex-col gap-2", classNames),
|
|
1031
|
+
ref: forwardRef4
|
|
1032
|
+
}, layout !== "inline" && label && /* @__PURE__ */ React4.createElement(FormFieldLabel, {
|
|
1033
|
+
label,
|
|
1034
|
+
asChild: true
|
|
1035
|
+
}), properties.map((property) => {
|
|
1036
|
+
const name = property.name.toString();
|
|
1037
|
+
return /* @__PURE__ */ React4.createElement(FormFieldErrorBoundary, {
|
|
1038
|
+
key: name,
|
|
1039
|
+
path: [
|
|
1040
|
+
...path ?? [],
|
|
1041
|
+
name
|
|
1042
|
+
]
|
|
1043
|
+
}, /* @__PURE__ */ React4.createElement(FormField, {
|
|
1044
|
+
type: property.type,
|
|
1045
|
+
name,
|
|
1046
|
+
path: [
|
|
1047
|
+
...path ?? [],
|
|
1048
|
+
name
|
|
1049
|
+
],
|
|
1050
|
+
readonly,
|
|
1051
|
+
layout,
|
|
1052
|
+
projection,
|
|
1053
|
+
...props
|
|
1054
|
+
}));
|
|
1055
|
+
}).filter(isTruthy));
|
|
1056
|
+
});
|
|
1057
|
+
FormFieldSet.displayName = "Form.Fields";
|
|
1058
|
+
|
|
1059
|
+
// src/components/Form/Form.tsx
|
|
1060
|
+
var omitId = (schema) => schema.pipe(Schema2.omit("id"));
|
|
1061
|
+
var [FormContextProvider, useFormContext] = createContext("Form");
|
|
1062
|
+
var useFormValues = (componentName, path = [], defaultValue) => {
|
|
1063
|
+
const jsonPath = createJsonPath3(path);
|
|
1064
|
+
const { form: { values } } = useFormContext(componentName);
|
|
1065
|
+
const value3 = getValue$2(values, jsonPath);
|
|
1066
|
+
useEffect3(() => {
|
|
1067
|
+
if (!value3 && defaultValue) {
|
|
1068
|
+
setValueEchoAware(values, jsonPath, defaultValue());
|
|
1346
1069
|
}
|
|
1070
|
+
}, [
|
|
1071
|
+
value3,
|
|
1072
|
+
defaultValue
|
|
1073
|
+
]);
|
|
1074
|
+
return value3;
|
|
1075
|
+
};
|
|
1076
|
+
var useFormFieldState = (componentName, path = []) => {
|
|
1077
|
+
const stablePath = useMemo4(() => path, [
|
|
1078
|
+
Array.isArray(path) ? path.join(".") : path
|
|
1079
|
+
]);
|
|
1080
|
+
const { form: { getStatus, getValue, onBlur, onValueChange } } = useFormContext(componentName);
|
|
1081
|
+
return useMemo4(() => ({
|
|
1082
|
+
getStatus: () => getStatus(stablePath),
|
|
1083
|
+
getValue: () => getValue(stablePath),
|
|
1084
|
+
onBlur: () => onBlur(stablePath),
|
|
1085
|
+
onValueChange: (ast, value3) => onValueChange(stablePath, ast, value3)
|
|
1086
|
+
}), [
|
|
1087
|
+
getStatus,
|
|
1088
|
+
getValue,
|
|
1089
|
+
onBlur,
|
|
1090
|
+
onValueChange,
|
|
1091
|
+
stablePath
|
|
1092
|
+
]);
|
|
1093
|
+
};
|
|
1094
|
+
var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
|
|
1095
|
+
const form = useFormHandler({
|
|
1096
|
+
schema,
|
|
1097
|
+
values,
|
|
1098
|
+
onSave,
|
|
1099
|
+
onCancel,
|
|
1100
|
+
...props
|
|
1101
|
+
});
|
|
1102
|
+
return /* @__PURE__ */ React5.createElement(FormContextProvider, {
|
|
1103
|
+
form,
|
|
1104
|
+
...props
|
|
1105
|
+
}, children);
|
|
1106
|
+
};
|
|
1107
|
+
FormRoot.displayName = "Form.Root";
|
|
1108
|
+
var FormViewport = ({ classNames, children }) => {
|
|
1109
|
+
return /* @__PURE__ */ React5.createElement(ScrollArea.Root, null, /* @__PURE__ */ React5.createElement(ScrollArea.Viewport, {
|
|
1110
|
+
classNames: [
|
|
1111
|
+
"plb-cardSpacingBlock",
|
|
1112
|
+
classNames
|
|
1113
|
+
]
|
|
1114
|
+
}, children), /* @__PURE__ */ React5.createElement(ScrollArea.Scrollbar, {
|
|
1115
|
+
orientation: "vertical"
|
|
1116
|
+
}, /* @__PURE__ */ React5.createElement(ScrollArea.Thumb, null)));
|
|
1117
|
+
};
|
|
1118
|
+
FormViewport.displayName = "Form.Viewport";
|
|
1119
|
+
var FormContent = ({ classNames, children }) => {
|
|
1120
|
+
const { form, testId } = useFormContext(FormContent.displayName);
|
|
1121
|
+
const ref = useRef(null);
|
|
1122
|
+
useKeyHandler(ref.current, form);
|
|
1123
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1124
|
+
ref,
|
|
1125
|
+
role: "form",
|
|
1126
|
+
className: mx4("flex flex-col is-full pli-cardSpacingInline density-fine", classNames),
|
|
1127
|
+
"data-testid": testId
|
|
1128
|
+
}, children);
|
|
1129
|
+
};
|
|
1130
|
+
FormContent.displayName = "Form.Content";
|
|
1131
|
+
var FormFieldSet2 = ({ classNames }) => {
|
|
1132
|
+
const { form, ...props } = useFormContext(FormFieldSet2.displayName);
|
|
1133
|
+
return /* @__PURE__ */ React5.createElement(FormFieldSet, {
|
|
1134
|
+
classNames,
|
|
1135
|
+
schema: form.schema,
|
|
1136
|
+
...props
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1139
|
+
FormFieldSet2.displayName = "Form.FieldSet";
|
|
1140
|
+
var FormActions = ({ classNames }) => {
|
|
1141
|
+
const { t } = useTranslation3(translationKey);
|
|
1142
|
+
const { form: { canSave, onSave, onCancel }, readonly, layout } = useFormContext(FormActions.displayName);
|
|
1143
|
+
if (readonly || layout === "static") {
|
|
1144
|
+
return null;
|
|
1347
1145
|
}
|
|
1146
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1147
|
+
role: "none",
|
|
1148
|
+
className: mx4("grid grid-flow-col auto-cols-fr gap-2 pbs-cardSpacingBlock", classNames)
|
|
1149
|
+
}, onCancel && /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1150
|
+
icon: "ph--x--regular",
|
|
1151
|
+
iconEnd: true,
|
|
1152
|
+
label: t("cancel button label"),
|
|
1153
|
+
onClick: onCancel,
|
|
1154
|
+
"data-testid": "cancel-button"
|
|
1155
|
+
}), onSave && /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1156
|
+
type: "submit",
|
|
1157
|
+
variant: "primary",
|
|
1158
|
+
disabled: !canSave,
|
|
1159
|
+
icon: "ph--check--regular",
|
|
1160
|
+
iconEnd: true,
|
|
1161
|
+
label: t("save button label"),
|
|
1162
|
+
onClick: onSave,
|
|
1163
|
+
"data-testid": "save-button"
|
|
1164
|
+
}));
|
|
1348
1165
|
};
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1166
|
+
FormActions.displayName = "Form.Actions";
|
|
1167
|
+
var FormSubmit = ({ classNames, label, icon }) => {
|
|
1168
|
+
const { t } = useTranslation3(translationKey);
|
|
1169
|
+
const { form: { canSave, onSave }, readonly, layout } = useFormContext(FormSubmit.displayName);
|
|
1170
|
+
if (readonly || layout === "static") {
|
|
1171
|
+
return null;
|
|
1172
|
+
}
|
|
1173
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
1174
|
+
role: "none",
|
|
1175
|
+
className: mx4("flex is-full pbs-cardSpacingBlock", classNames)
|
|
1176
|
+
}, /* @__PURE__ */ React5.createElement(IconButton, {
|
|
1177
|
+
classNames: "is-full",
|
|
1178
|
+
type: "submit",
|
|
1179
|
+
variant: "primary",
|
|
1180
|
+
disabled: !canSave,
|
|
1181
|
+
icon: icon ?? "ph--check--regular",
|
|
1182
|
+
label: label ?? t("save button label"),
|
|
1183
|
+
onClick: onSave,
|
|
1184
|
+
"data-testid": "save-button"
|
|
1185
|
+
}));
|
|
1186
|
+
};
|
|
1187
|
+
FormSubmit.displayName = "Form.Submit";
|
|
1188
|
+
var Form = {
|
|
1189
|
+
Root: FormRoot,
|
|
1190
|
+
Viewport: FormViewport,
|
|
1191
|
+
Content: FormContent,
|
|
1192
|
+
FieldSet: FormFieldSet2,
|
|
1193
|
+
Actions: FormActions,
|
|
1194
|
+
Submit: FormSubmit,
|
|
1195
|
+
Label: FormFieldLabel
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
// src/components/Form/fields/ArrayField.tsx
|
|
1199
|
+
var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps, ...props }) => {
|
|
1200
|
+
const { t } = useTranslation4(translationKey);
|
|
1201
|
+
const elementType = getArrayElementType2(type);
|
|
1202
|
+
const { onValueChange } = inputProps;
|
|
1203
|
+
const values = useFormValues(ArrayField.displayName, path, () => []);
|
|
1204
|
+
const getDefaultObjectValue = (typeNode) => {
|
|
1205
|
+
const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
|
|
1206
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST2.isTypeLiteral);
|
|
1207
|
+
if (!typeLiteral) {
|
|
1208
|
+
return {};
|
|
1359
1209
|
}
|
|
1210
|
+
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1211
|
+
const defaultValue = SchemaAST2.getDefaultAnnotation(prop.type).pipe((annotation) => Option3.getOrUndefined(annotation));
|
|
1212
|
+
return [
|
|
1213
|
+
prop.name,
|
|
1214
|
+
defaultValue
|
|
1215
|
+
];
|
|
1216
|
+
}));
|
|
1360
1217
|
};
|
|
1361
|
-
|
|
1362
|
-
|
|
1218
|
+
const handleAdd = useCallback3(() => {
|
|
1219
|
+
const defaultValue = isNestedType2(type) && elementType ? getDefaultObjectValue(elementType) : getDefaultValue(elementType);
|
|
1220
|
+
values && onValueChange(type, [
|
|
1221
|
+
...values,
|
|
1222
|
+
defaultValue
|
|
1223
|
+
]);
|
|
1224
|
+
}, [
|
|
1225
|
+
onValueChange,
|
|
1226
|
+
type,
|
|
1227
|
+
elementType,
|
|
1228
|
+
values
|
|
1229
|
+
]);
|
|
1230
|
+
const handleDelete = useCallback3((idx) => {
|
|
1231
|
+
onValueChange(type, values?.filter((_, i) => i !== idx));
|
|
1232
|
+
}, [
|
|
1233
|
+
onValueChange,
|
|
1234
|
+
type,
|
|
1235
|
+
values
|
|
1236
|
+
]);
|
|
1237
|
+
if (!elementType || (readonly || layout === "static") && values && values.length < 1) {
|
|
1238
|
+
return null;
|
|
1363
1239
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1240
|
+
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, (layout !== "static" || values && values.length > 0) && /* @__PURE__ */ React6.createElement(FormFieldLabel, {
|
|
1241
|
+
readonly,
|
|
1242
|
+
label,
|
|
1243
|
+
asChild: true
|
|
1244
|
+
}), /* @__PURE__ */ React6.createElement("div", {
|
|
1245
|
+
role: "none",
|
|
1246
|
+
className: "flex flex-col gap-2"
|
|
1247
|
+
}, values?.map((_, index) => {
|
|
1248
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
1249
|
+
role: "none",
|
|
1250
|
+
key: index,
|
|
1251
|
+
className: "grid grid-cols-[1fr_min-content] gap-2 last:mb-3"
|
|
1252
|
+
}, /* @__PURE__ */ React6.createElement(FormField, {
|
|
1253
|
+
autoFocus: index === values.length - 1,
|
|
1254
|
+
type: elementType,
|
|
1255
|
+
path: [
|
|
1256
|
+
...path ?? [],
|
|
1257
|
+
index
|
|
1258
|
+
],
|
|
1259
|
+
readonly: readonly || layout === "static",
|
|
1260
|
+
layout: "inline",
|
|
1261
|
+
...props
|
|
1262
|
+
}), !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement("div", {
|
|
1263
|
+
role: "none",
|
|
1264
|
+
className: "flex flex-col bs-full justify-end"
|
|
1265
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
1266
|
+
role: "none",
|
|
1267
|
+
className: "flex items-center bs-[var(--line-height)]"
|
|
1268
|
+
}, /* @__PURE__ */ React6.createElement(IconButton2, {
|
|
1269
|
+
icon: "ph--x--regular",
|
|
1270
|
+
iconOnly: true,
|
|
1271
|
+
label: t("button remove"),
|
|
1272
|
+
onClick: () => handleDelete(index),
|
|
1273
|
+
classNames: "self-center"
|
|
1274
|
+
}))));
|
|
1275
|
+
})), !readonly && layout !== "static" && /* @__PURE__ */ React6.createElement(IconButton2, {
|
|
1276
|
+
classNames: "flex is-full _mlb-cardSpacingBlock",
|
|
1277
|
+
icon: "ph--plus--regular",
|
|
1278
|
+
label: t("add field"),
|
|
1279
|
+
onClick: handleAdd
|
|
1280
|
+
}));
|
|
1281
|
+
};
|
|
1282
|
+
ArrayField.displayName = "Form.ArrayField";
|
|
1283
|
+
var getDefaultValue = (ast) => {
|
|
1284
|
+
switch (ast?._tag) {
|
|
1285
|
+
case "StringKeyword": {
|
|
1286
|
+
return "";
|
|
1384
1287
|
}
|
|
1385
|
-
case
|
|
1386
|
-
|
|
1387
|
-
return date.toISOString().split("T")[1].split(".")[0];
|
|
1288
|
+
case "NumberKeyword": {
|
|
1289
|
+
return 0;
|
|
1388
1290
|
}
|
|
1389
|
-
case
|
|
1390
|
-
|
|
1391
|
-
return "";
|
|
1392
|
-
}
|
|
1393
|
-
if (Array.isArray(value2) && value2.length >= 2 && value2.every(Number.isFinite)) {
|
|
1394
|
-
const { latitude, longitude } = GeoLocation3.fromGeoPoint(value2);
|
|
1395
|
-
return `${latitude},${longitude}`;
|
|
1396
|
-
}
|
|
1397
|
-
return String(value2);
|
|
1291
|
+
case "BooleanKeyword": {
|
|
1292
|
+
return false;
|
|
1398
1293
|
}
|
|
1399
1294
|
default: {
|
|
1400
|
-
|
|
1295
|
+
if (ast && isNestedType2(ast)) {
|
|
1296
|
+
return {};
|
|
1297
|
+
} else {
|
|
1298
|
+
throw new Error(`Unsupported type: ${ast?._tag}`);
|
|
1299
|
+
}
|
|
1401
1300
|
}
|
|
1402
1301
|
}
|
|
1403
1302
|
};
|
|
1404
1303
|
|
|
1405
|
-
// src/
|
|
1406
|
-
import {
|
|
1407
|
-
import {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1304
|
+
// src/components/Form/fields/BooleanField.tsx
|
|
1305
|
+
import React7, { useCallback as useCallback4 } from "react";
|
|
1306
|
+
import { Input as Input3 } from "@dxos/react-ui";
|
|
1307
|
+
var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
|
|
1308
|
+
const handleChange = useCallback4((value3) => onValueChange?.(type, value3), [
|
|
1309
|
+
type,
|
|
1310
|
+
onValueChange
|
|
1311
|
+
]);
|
|
1312
|
+
return /* @__PURE__ */ React7.createElement(FormFieldWrapper, {
|
|
1313
|
+
readonly,
|
|
1314
|
+
...props
|
|
1315
|
+
}, ({ value: value3 }) => /* @__PURE__ */ React7.createElement(Input3.Switch, {
|
|
1316
|
+
disabled: !!readonly,
|
|
1317
|
+
checked: value3,
|
|
1318
|
+
onCheckedChange: handleChange
|
|
1319
|
+
}));
|
|
1415
1320
|
};
|
|
1416
1321
|
|
|
1417
|
-
// src/
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1322
|
+
// src/components/Form/fields/GeoPointField.tsx
|
|
1323
|
+
import React8, { useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo5, useState as useState2 } from "react";
|
|
1324
|
+
import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
|
|
1325
|
+
import { Input as Input4, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1326
|
+
import { safeParseFloat } from "@dxos/util";
|
|
1327
|
+
var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1328
|
+
const { t } = useTranslation5(translationKey);
|
|
1329
|
+
const { status, error } = getStatus();
|
|
1330
|
+
const geoPoint = useMemo5(() => getValue() ?? [
|
|
1331
|
+
0,
|
|
1332
|
+
0
|
|
1333
|
+
], [
|
|
1334
|
+
getValue
|
|
1335
|
+
]);
|
|
1336
|
+
const value3 = useMemo5(() => GeoLocation3.fromGeoPoint(geoPoint), [
|
|
1337
|
+
geoPoint
|
|
1338
|
+
]);
|
|
1339
|
+
const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
|
|
1340
|
+
const [latitudeText, setLatitudeText] = useState2(value3.latitude?.toString());
|
|
1341
|
+
useEffect4(() => {
|
|
1342
|
+
const location = GeoLocation3.fromGeoPoint(geoPoint);
|
|
1343
|
+
setLongitudeText(location.longitude?.toString());
|
|
1344
|
+
setLatitudeText(location.latitude?.toString());
|
|
1345
|
+
}, [
|
|
1346
|
+
geoPoint
|
|
1347
|
+
]);
|
|
1348
|
+
const handleChange = useCallback5((coordinateType, setText) => (event) => {
|
|
1349
|
+
const inputText = event.target.value;
|
|
1350
|
+
setText(inputText);
|
|
1351
|
+
if (inputText !== "" && inputText !== "-") {
|
|
1352
|
+
const coord = safeParseFloat(inputText);
|
|
1353
|
+
if (coord !== void 0 && !isNaN(coord)) {
|
|
1354
|
+
const currentLocation = GeoLocation3.fromGeoPoint(getValue() ?? [
|
|
1355
|
+
0,
|
|
1356
|
+
0
|
|
1357
|
+
]);
|
|
1358
|
+
const newLocation = {
|
|
1359
|
+
...currentLocation,
|
|
1360
|
+
[coordinateType]: coord
|
|
1428
1361
|
};
|
|
1362
|
+
const newValue = GeoLocation3.toGeoPoint(newLocation);
|
|
1363
|
+
onValueChange(type, newValue);
|
|
1429
1364
|
}
|
|
1430
1365
|
}
|
|
1366
|
+
}, [
|
|
1367
|
+
type,
|
|
1368
|
+
getValue,
|
|
1369
|
+
onValueChange
|
|
1370
|
+
]);
|
|
1371
|
+
if ((readonly || layout === "static") && !value3?.latitude && !value3?.longitude) {
|
|
1372
|
+
return null;
|
|
1431
1373
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1374
|
+
return /* @__PURE__ */ React8.createElement(Input4.Root, {
|
|
1375
|
+
validationValence: status
|
|
1376
|
+
}, layout !== "inline" && /* @__PURE__ */ React8.createElement(FormFieldLabel, {
|
|
1377
|
+
error,
|
|
1378
|
+
readonly,
|
|
1379
|
+
label,
|
|
1380
|
+
asChild: true
|
|
1381
|
+
}), layout === "static" ? /* @__PURE__ */ React8.createElement(LatLng, value3) : /* @__PURE__ */ React8.createElement("div", {
|
|
1382
|
+
role: "none",
|
|
1383
|
+
className: "grid grid-cols-2 gap-2"
|
|
1384
|
+
}, /* @__PURE__ */ React8.createElement("div", null, /* @__PURE__ */ React8.createElement(Input4.Root, null, layout !== "inline" && /* @__PURE__ */ React8.createElement(Input4.Label, null, t("latitude label")), /* @__PURE__ */ React8.createElement(Input4.TextInput, {
|
|
1385
|
+
type: "number",
|
|
1386
|
+
step: "0.00001",
|
|
1387
|
+
min: "-90",
|
|
1388
|
+
max: "90",
|
|
1389
|
+
disabled: !!readonly,
|
|
1390
|
+
placeholder: t("latitude placeholder"),
|
|
1391
|
+
value: latitudeText ?? "",
|
|
1392
|
+
onChange: handleChange("latitude", setLatitudeText),
|
|
1393
|
+
onBlur
|
|
1394
|
+
}))), /* @__PURE__ */ React8.createElement("div", null, /* @__PURE__ */ React8.createElement(Input4.Root, null, layout !== "inline" && /* @__PURE__ */ React8.createElement(Input4.Label, null, t("longitude label")), /* @__PURE__ */ React8.createElement(Input4.TextInput, {
|
|
1395
|
+
type: "number",
|
|
1396
|
+
step: "0.00001",
|
|
1397
|
+
min: "-180",
|
|
1398
|
+
max: "180",
|
|
1399
|
+
disabled: !!readonly,
|
|
1400
|
+
placeholder: t("longitude placeholder"),
|
|
1401
|
+
value: longitudeText ?? "",
|
|
1402
|
+
onChange: handleChange("longitude", setLongitudeText),
|
|
1403
|
+
onBlur
|
|
1404
|
+
})))));
|
|
1405
|
+
};
|
|
1406
|
+
var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
1407
|
+
const latHem = latitude >= 0 ? "N" : "S";
|
|
1408
|
+
const lngHem = longitude >= 0 ? "E" : "W";
|
|
1409
|
+
return /* @__PURE__ */ React8.createElement("span", {
|
|
1410
|
+
className: "inline-flex items-center gap-1"
|
|
1411
|
+
}, /* @__PURE__ */ React8.createElement("span", null, /* @__PURE__ */ React8.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React8.createElement("span", {
|
|
1412
|
+
className: "text-subdued"
|
|
1413
|
+
}, "\xB0", latHem)), /* @__PURE__ */ React8.createElement("span", null, /* @__PURE__ */ React8.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React8.createElement("span", {
|
|
1414
|
+
className: "text-subdued"
|
|
1415
|
+
}, "\xB0", lngHem)));
|
|
1439
1416
|
};
|
|
1440
1417
|
|
|
1441
|
-
// src/components/Form/
|
|
1442
|
-
import {
|
|
1443
|
-
import
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
var ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }) => {
|
|
1453
|
-
var _effect = _useSignals9();
|
|
1454
|
-
try {
|
|
1455
|
-
const { t } = useTranslation6(translationKey);
|
|
1456
|
-
const { ast, name, type, title } = property;
|
|
1457
|
-
const values = useFormValues(path ?? []) ?? [];
|
|
1458
|
-
invariant2(Array.isArray(values), `Values at path ${path?.join(".")} must be an array.`, {
|
|
1459
|
-
F: __dxlog_file3,
|
|
1460
|
-
L: 37,
|
|
1461
|
-
S: void 0,
|
|
1462
|
-
A: [
|
|
1463
|
-
"Array.isArray(values)",
|
|
1464
|
-
"`Values at path ${path?.join('.')} must be an array.`"
|
|
1465
|
-
]
|
|
1466
|
-
});
|
|
1467
|
-
const label = title ?? Function.pipe(name, String2.capitalize);
|
|
1468
|
-
const elementType = findArrayElementType(ast);
|
|
1469
|
-
const getDefaultObjectValue = (typeNode) => {
|
|
1470
|
-
const baseNode = findNode2(typeNode, isDiscriminatedUnion);
|
|
1471
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode2(typeNode, SchemaAST3.isTypeLiteral);
|
|
1472
|
-
if (!typeLiteral) {
|
|
1473
|
-
return {};
|
|
1474
|
-
}
|
|
1475
|
-
return Object.fromEntries(getSchemaProperties(typeLiteral, {}, {
|
|
1476
|
-
form: true
|
|
1477
|
-
}).map((prop) => [
|
|
1478
|
-
prop.name,
|
|
1479
|
-
prop.defaultValue
|
|
1480
|
-
]));
|
|
1481
|
-
};
|
|
1482
|
-
const getDefaultValue = () => type === "object" && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
|
|
1483
|
-
const handleAdd = useCallback8(() => {
|
|
1484
|
-
inputProps.onValueChange(type, [
|
|
1485
|
-
...values,
|
|
1486
|
-
getDefaultValue()
|
|
1487
|
-
]);
|
|
1488
|
-
}, [
|
|
1489
|
-
type,
|
|
1490
|
-
elementType,
|
|
1491
|
-
inputProps,
|
|
1492
|
-
values
|
|
1493
|
-
]);
|
|
1494
|
-
const handleRemove = useCallback8((index) => {
|
|
1495
|
-
const newValues = values.filter((_, i) => i !== index);
|
|
1496
|
-
inputProps.onValueChange(type, newValues);
|
|
1497
|
-
}, [
|
|
1498
|
-
type,
|
|
1499
|
-
inputProps,
|
|
1500
|
-
values
|
|
1501
|
-
]);
|
|
1502
|
-
if (!elementType) {
|
|
1503
|
-
return null;
|
|
1418
|
+
// src/components/Form/fields/MarkdownField.tsx
|
|
1419
|
+
import React9, { useCallback as useCallback6, useEffect as useEffect5, useRef as useRef2 } from "react";
|
|
1420
|
+
import { Input as Input5 } from "@dxos/react-ui";
|
|
1421
|
+
var MarkdownField = ({ type, readonly, label, placeholder, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1422
|
+
const { status, error } = getStatus();
|
|
1423
|
+
const textareaRef = useRef2(null);
|
|
1424
|
+
const adjustHeight = useCallback6(() => {
|
|
1425
|
+
const textarea = textareaRef.current;
|
|
1426
|
+
if (textarea) {
|
|
1427
|
+
textarea.style.blockSize = "auto";
|
|
1428
|
+
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
1504
1429
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
Custom,
|
|
1525
|
-
lookupComponent
|
|
1526
|
-
});
|
|
1527
|
-
return readonly ? field : /* @__PURE__ */ React9.createElement(Fragment, {
|
|
1528
|
-
key: index
|
|
1529
|
-
}, /* @__PURE__ */ React9.createElement("div", {
|
|
1530
|
-
role: "none"
|
|
1531
|
-
}, field), /* @__PURE__ */ React9.createElement(IconButton3, {
|
|
1532
|
-
icon: "ph--trash--regular",
|
|
1533
|
-
iconOnly: true,
|
|
1534
|
-
label: t("button remove"),
|
|
1535
|
-
onClick: () => handleRemove(index),
|
|
1536
|
-
classNames: "self-center"
|
|
1537
|
-
}));
|
|
1538
|
-
})), !readonly && /* @__PURE__ */ React9.createElement(IconButton3, {
|
|
1539
|
-
classNames: "is-full mlb-cardSpacingBlock flex",
|
|
1540
|
-
icon: "ph--plus--regular",
|
|
1541
|
-
label: t("add field"),
|
|
1542
|
-
onClick: handleAdd
|
|
1543
|
-
}));
|
|
1544
|
-
} finally {
|
|
1545
|
-
_effect.f();
|
|
1430
|
+
}, []);
|
|
1431
|
+
useEffect5(() => {
|
|
1432
|
+
adjustHeight();
|
|
1433
|
+
}, [
|
|
1434
|
+
adjustHeight
|
|
1435
|
+
]);
|
|
1436
|
+
useEffect5(() => {
|
|
1437
|
+
adjustHeight();
|
|
1438
|
+
}, [
|
|
1439
|
+
getValue(),
|
|
1440
|
+
adjustHeight
|
|
1441
|
+
]);
|
|
1442
|
+
const handleChange = useCallback6((event) => onValueChange(type, event.target.value), [
|
|
1443
|
+
type,
|
|
1444
|
+
onValueChange
|
|
1445
|
+
]);
|
|
1446
|
+
const value3 = getValue();
|
|
1447
|
+
if ((readonly || layout === "static") && !value3) {
|
|
1448
|
+
return null;
|
|
1546
1449
|
}
|
|
1450
|
+
return /* @__PURE__ */ React9.createElement(Input5.Root, {
|
|
1451
|
+
validationValence: status
|
|
1452
|
+
}, layout !== "inline" && /* @__PURE__ */ React9.createElement(FormFieldLabel, {
|
|
1453
|
+
error,
|
|
1454
|
+
readonly,
|
|
1455
|
+
label
|
|
1456
|
+
}), layout === "static" ? /* @__PURE__ */ React9.createElement("p", null, value3) : /* @__PURE__ */ React9.createElement(Input5.TextArea, {
|
|
1457
|
+
ref: textareaRef,
|
|
1458
|
+
disabled: !!readonly,
|
|
1459
|
+
placeholder,
|
|
1460
|
+
value: value3 ?? "",
|
|
1461
|
+
classNames: "min-bs-auto max-bs-40 overflow-auto",
|
|
1462
|
+
onChange: handleChange,
|
|
1463
|
+
onBlur,
|
|
1464
|
+
style: {
|
|
1465
|
+
resize: "none"
|
|
1466
|
+
},
|
|
1467
|
+
spellCheck: false
|
|
1468
|
+
}), layout === "full" && /* @__PURE__ */ React9.createElement(Input5.Validation, null, error));
|
|
1547
1469
|
};
|
|
1548
1470
|
|
|
1549
|
-
// src/components/Form/
|
|
1550
|
-
import {
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1471
|
+
// src/components/Form/fields/NumberField.tsx
|
|
1472
|
+
import React10, { useCallback as useCallback7 } from "react";
|
|
1473
|
+
import { Input as Input6 } from "@dxos/react-ui";
|
|
1474
|
+
import { safeParseFloat as safeParseFloat2 } from "@dxos/util";
|
|
1475
|
+
var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1476
|
+
const handleChange = useCallback7((event) => onValueChange(type, safeParseFloat2(event.target.value) || 0), [
|
|
1477
|
+
type,
|
|
1478
|
+
onValueChange
|
|
1479
|
+
]);
|
|
1480
|
+
return /* @__PURE__ */ React10.createElement(FormFieldWrapper, {
|
|
1481
|
+
readonly,
|
|
1482
|
+
...props
|
|
1483
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React10.createElement(Input6.TextInput, {
|
|
1484
|
+
type: "number",
|
|
1485
|
+
disabled: !!readonly,
|
|
1486
|
+
placeholder,
|
|
1487
|
+
value: value3,
|
|
1488
|
+
onChange: handleChange,
|
|
1489
|
+
onBlur
|
|
1490
|
+
}));
|
|
1566
1491
|
};
|
|
1567
1492
|
|
|
1568
|
-
// src/components/Form/RefField.tsx
|
|
1569
|
-
import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
|
|
1493
|
+
// src/components/Form/fields/RefField.tsx
|
|
1570
1494
|
import "@dxos/lit-ui/dx-tag-picker.pcss";
|
|
1571
|
-
import
|
|
1572
|
-
import {
|
|
1573
|
-
import {
|
|
1495
|
+
import React12, { useCallback as useCallback9, useMemo as useMemo6 } from "react";
|
|
1496
|
+
import { Entity, Filter, Ref as Ref2 } from "@dxos/echo";
|
|
1497
|
+
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
1498
|
+
import { useQuery, useSchema as useSchema$ } from "@dxos/echo-react";
|
|
1499
|
+
import { findAnnotation } from "@dxos/effect";
|
|
1574
1500
|
import { DXN } from "@dxos/keys";
|
|
1575
|
-
import { DxAnchor
|
|
1576
|
-
import { Button as Button2, Icon as
|
|
1577
|
-
import { descriptionText, mx as mx5 } from "@dxos/
|
|
1578
|
-
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1501
|
+
import { DxAnchor } from "@dxos/lit-ui/react";
|
|
1502
|
+
import { Button as Button2, Icon as Icon2, Input as Input7, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1503
|
+
import { descriptionText, mx as mx5 } from "@dxos/ui-theme";
|
|
1579
1504
|
|
|
1580
1505
|
// src/components/ObjectPicker/ObjectPicker.tsx
|
|
1581
|
-
import {
|
|
1582
|
-
import
|
|
1583
|
-
import {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
const [showForm, setShowForm] = useState5(false);
|
|
1591
|
-
const handleFormSave = useCallback9((values) => {
|
|
1592
|
-
onCreate?.(values);
|
|
1593
|
-
setShowForm(false);
|
|
1594
|
-
setSearchString("");
|
|
1595
|
-
}, [
|
|
1596
|
-
onCreate
|
|
1597
|
-
]);
|
|
1598
|
-
const handleFormCancel = useCallback9(() => {
|
|
1599
|
-
setShowForm(false);
|
|
1600
|
-
setSearchString("");
|
|
1601
|
-
}, []);
|
|
1602
|
-
const handleClick = useCallback9((event) => {
|
|
1603
|
-
if (createSchema && event.target.closest('[data-value="__create__"]')) {
|
|
1604
|
-
event.stopPropagation();
|
|
1605
|
-
event.preventDefault();
|
|
1606
|
-
setShowForm(true);
|
|
1607
|
-
}
|
|
1608
|
-
}, [
|
|
1609
|
-
createSchema
|
|
1610
|
-
]);
|
|
1611
|
-
const handleKeyDown = useCallback9((event) => {
|
|
1612
|
-
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1613
|
-
event.stopPropagation();
|
|
1614
|
-
event.preventDefault();
|
|
1615
|
-
setShowForm(true);
|
|
1616
|
-
}
|
|
1617
|
-
}, [
|
|
1618
|
-
createSchema
|
|
1619
|
-
]);
|
|
1620
|
-
const labelById = useMemo4(() => options.reduce((acc, option) => {
|
|
1621
|
-
acc[option.id.toLowerCase()] = option.label.toLowerCase();
|
|
1622
|
-
return acc;
|
|
1623
|
-
}, {}), [
|
|
1624
|
-
options
|
|
1625
|
-
]);
|
|
1626
|
-
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1627
|
-
...props,
|
|
1628
|
-
ref,
|
|
1629
|
-
filter: (value2, search) => value2 === "__create__" || labelById[value2]?.includes(search.toLowerCase()) ? 1 : 0,
|
|
1630
|
-
onClickCapture: handleClick,
|
|
1631
|
-
onKeyDownCapture: handleKeyDown
|
|
1632
|
-
}, showForm && createSchema ? /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form, {
|
|
1633
|
-
schema: createSchema,
|
|
1634
|
-
values: createInitialValuePath ? {
|
|
1635
|
-
[createInitialValuePath]: searchString
|
|
1636
|
-
} : {},
|
|
1637
|
-
onSave: handleFormSave,
|
|
1638
|
-
onCancel: handleFormCancel,
|
|
1639
|
-
testId: "create-referenced-object-form"
|
|
1640
|
-
})) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(Combobox.Input, {
|
|
1641
|
-
placeholder: t("ref field combobox input placeholder"),
|
|
1642
|
-
value: searchString,
|
|
1643
|
-
onValueChange: setSearchString,
|
|
1644
|
-
autoFocus: true
|
|
1645
|
-
}), /* @__PURE__ */ React10.createElement(Combobox.List, null, options.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1646
|
-
key: option.id,
|
|
1647
|
-
value: option.id,
|
|
1648
|
-
onSelect: () => onSelect(option.id),
|
|
1649
|
-
classNames: "flex items-center gap-2"
|
|
1650
|
-
}, /* @__PURE__ */ React10.createElement("span", {
|
|
1651
|
-
className: "grow"
|
|
1652
|
-
}, option.label), selectedIds?.includes(option.id) && /* @__PURE__ */ React10.createElement(Icon2, {
|
|
1653
|
-
icon: "ph--check--regular"
|
|
1654
|
-
}))), searchString.length > 0 && createOptionLabel && createOptionIcon && createSchema && onCreate && /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1655
|
-
value: "__create__",
|
|
1656
|
-
classNames: "flex items-center gap-2"
|
|
1657
|
-
}, /* @__PURE__ */ React10.createElement(Icon2, {
|
|
1658
|
-
icon: createOptionIcon
|
|
1659
|
-
}), t(createOptionLabel[0], {
|
|
1506
|
+
import React11, { forwardRef as forwardRef2, useCallback as useCallback8, useState as useState3 } from "react";
|
|
1507
|
+
import { Popover, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1508
|
+
import { Combobox, useSearchListInput, useSearchListResults } from "@dxos/react-ui-searchlist";
|
|
1509
|
+
var CreateItem = ({ createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
|
|
1510
|
+
const { t } = useTranslation6(translationKey);
|
|
1511
|
+
const { query } = useSearchListInput();
|
|
1512
|
+
return /* @__PURE__ */ React11.createElement(Combobox.Item, {
|
|
1513
|
+
value: "__create__",
|
|
1514
|
+
label: t(createOptionLabel[0], {
|
|
1660
1515
|
ns: createOptionLabel[1].ns,
|
|
1661
|
-
text:
|
|
1662
|
-
})
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1516
|
+
text: query
|
|
1517
|
+
}),
|
|
1518
|
+
icon: createOptionIcon,
|
|
1519
|
+
classNames: "flex items-center gap-2",
|
|
1520
|
+
closeOnSelect: false,
|
|
1521
|
+
onSelect: () => {
|
|
1522
|
+
onCreateItemSelect(query);
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
};
|
|
1526
|
+
var ObjectPickerContent = /* @__PURE__ */ forwardRef2(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, onSelect, onCreate, ...props }, ref) => {
|
|
1527
|
+
const { t } = useTranslation6(translationKey);
|
|
1528
|
+
const [showForm, setShowForm] = useState3(false);
|
|
1529
|
+
const [formInitialValue, setFormInitialValue] = useState3("");
|
|
1530
|
+
const { results, handleSearch } = useSearchListResults({
|
|
1531
|
+
items: options
|
|
1532
|
+
});
|
|
1533
|
+
const handleFormSave = useCallback8((values) => {
|
|
1534
|
+
onCreate?.(values);
|
|
1535
|
+
setShowForm(false);
|
|
1536
|
+
setFormInitialValue("");
|
|
1537
|
+
}, [
|
|
1538
|
+
onCreate
|
|
1539
|
+
]);
|
|
1540
|
+
const handleFormCancel = useCallback8(() => {
|
|
1541
|
+
setShowForm(false);
|
|
1542
|
+
setFormInitialValue("");
|
|
1543
|
+
}, []);
|
|
1544
|
+
const handleKeyDown = useCallback8((event) => {
|
|
1545
|
+
if (event.key === "Enter" && createSchema && event.currentTarget.querySelector('[role="option"][aria-selected="true"][data-value="__create__"]')) {
|
|
1546
|
+
event.stopPropagation();
|
|
1547
|
+
event.preventDefault();
|
|
1548
|
+
const input = event.currentTarget.querySelector('input[type="text"]');
|
|
1549
|
+
const currentQuery = input?.value || "";
|
|
1550
|
+
setFormInitialValue(currentQuery);
|
|
1551
|
+
setShowForm(true);
|
|
1552
|
+
}
|
|
1553
|
+
}, [
|
|
1554
|
+
createSchema
|
|
1555
|
+
]);
|
|
1556
|
+
return /* @__PURE__ */ React11.createElement(Combobox.Content, {
|
|
1557
|
+
...props,
|
|
1558
|
+
ref,
|
|
1559
|
+
onSearch: handleSearch,
|
|
1560
|
+
onKeyDownCapture: handleKeyDown
|
|
1561
|
+
}, showForm && createSchema ? /* @__PURE__ */ React11.createElement(Popover.Viewport, null, /* @__PURE__ */ React11.createElement(Form.Root, {
|
|
1562
|
+
testId: "create-referenced-object-form",
|
|
1563
|
+
schema: createSchema,
|
|
1564
|
+
values: createInitialValuePath ? {
|
|
1565
|
+
[createInitialValuePath]: formInitialValue
|
|
1566
|
+
} : {},
|
|
1567
|
+
onSave: handleFormSave,
|
|
1568
|
+
onCancel: handleFormCancel
|
|
1569
|
+
}, /* @__PURE__ */ React11.createElement(Form.Viewport, null, /* @__PURE__ */ React11.createElement(Form.Content, null, /* @__PURE__ */ React11.createElement(Form.FieldSet, null), /* @__PURE__ */ React11.createElement(Form.Actions, null))))) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Combobox.Input, {
|
|
1570
|
+
placeholder: t("ref field combobox input placeholder"),
|
|
1571
|
+
autoFocus: true
|
|
1572
|
+
}), /* @__PURE__ */ React11.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React11.createElement(Combobox.Item, {
|
|
1573
|
+
key: option.id,
|
|
1574
|
+
value: option.id,
|
|
1575
|
+
label: option.label,
|
|
1576
|
+
checked: selectedIds?.includes(option.id),
|
|
1577
|
+
onSelect: () => onSelect(option.id),
|
|
1578
|
+
classNames: "flex items-center gap-2"
|
|
1579
|
+
})), createOptionLabel && createOptionIcon && createSchema && onCreate && /* @__PURE__ */ React11.createElement(CreateItem, {
|
|
1580
|
+
createOptionLabel,
|
|
1581
|
+
createOptionIcon,
|
|
1582
|
+
onCreateItemSelect: (query) => {
|
|
1583
|
+
setFormInitialValue(query);
|
|
1584
|
+
setShowForm(true);
|
|
1585
|
+
}
|
|
1586
|
+
}))), /* @__PURE__ */ React11.createElement(Combobox.Arrow, null));
|
|
1666
1587
|
});
|
|
1667
1588
|
ObjectPickerContent.displayName = "ObjectPickerContent";
|
|
1668
1589
|
var ObjectPicker = {
|
|
1669
1590
|
Root: Combobox.Root,
|
|
1591
|
+
Portal: Combobox.Portal,
|
|
1670
1592
|
Trigger: Combobox.Trigger,
|
|
1671
1593
|
VirtualTrigger: Combobox.VirtualTrigger,
|
|
1672
1594
|
Content: ObjectPickerContent
|
|
1673
1595
|
};
|
|
1674
1596
|
|
|
1675
|
-
// src/components/Form/RefField.tsx
|
|
1676
|
-
var
|
|
1597
|
+
// src/components/Form/fields/RefField.tsx
|
|
1598
|
+
var isRefSnapshot = (val) => {
|
|
1677
1599
|
return typeof val === "object" && typeof val?.["/"] === "string";
|
|
1678
1600
|
};
|
|
1679
|
-
var
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
const
|
|
1707
|
-
if (
|
|
1708
|
-
|
|
1709
|
-
const matchingOption = availableOptions.find((option2) => option2.id === dxnString);
|
|
1710
|
-
if (matchingOption) {
|
|
1711
|
-
return matchingOption;
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
return void 0;
|
|
1715
|
-
};
|
|
1716
|
-
if (array && Array.isArray(formValue)) {
|
|
1717
|
-
return formValue.map(unknownToRefOption).filter(isNonNullable2) ?? [];
|
|
1718
|
-
}
|
|
1719
|
-
const option = unknownToRefOption(formValue);
|
|
1720
|
-
if (option) {
|
|
1721
|
-
return [
|
|
1722
|
-
option
|
|
1723
|
-
];
|
|
1724
|
-
}
|
|
1725
|
-
return [];
|
|
1726
|
-
}, [
|
|
1727
|
-
getValue3,
|
|
1728
|
-
availableOptions,
|
|
1729
|
-
array
|
|
1730
|
-
]);
|
|
1731
|
-
const handleUpdate = useCallback10((ids) => {
|
|
1732
|
-
if (ids.length === 0) {
|
|
1733
|
-
onValueChange("object", void 0);
|
|
1734
|
-
return;
|
|
1735
|
-
}
|
|
1736
|
-
const refs = ids.map((id) => {
|
|
1737
|
-
const item = availableOptions.find((option) => option.id === id);
|
|
1738
|
-
if (item) {
|
|
1739
|
-
const dxn = DXN.parse(item.id);
|
|
1740
|
-
return Ref.fromDXN(dxn);
|
|
1741
|
-
}
|
|
1742
|
-
return null;
|
|
1743
|
-
}).filter(isNonNullable2);
|
|
1744
|
-
if (array) {
|
|
1745
|
-
onValueChange("object", refs);
|
|
1746
|
-
} else {
|
|
1747
|
-
onValueChange("object", refs[0]);
|
|
1748
|
-
}
|
|
1749
|
-
}, [
|
|
1750
|
-
availableOptions,
|
|
1751
|
-
array,
|
|
1752
|
-
onValueChange
|
|
1753
|
-
]);
|
|
1754
|
-
const handleCreate = useCallback10((values) => {
|
|
1755
|
-
onCreate?.(values);
|
|
1756
|
-
updateOptions();
|
|
1757
|
-
}, [
|
|
1758
|
-
onCreate,
|
|
1759
|
-
updateOptions
|
|
1760
|
-
]);
|
|
1761
|
-
if (!refTypeInfo) {
|
|
1762
|
-
return null;
|
|
1763
|
-
}
|
|
1764
|
-
const { status, error } = restInputProps.getStatus();
|
|
1765
|
-
const items = handleGetValue();
|
|
1766
|
-
const selectedIds = useMemo5(() => items.map((i) => i.id), [
|
|
1767
|
-
items
|
|
1768
|
-
]);
|
|
1769
|
-
const toggleSelect = useCallback10((id) => {
|
|
1770
|
-
if (array) {
|
|
1771
|
-
const nextIds = selectedIds.includes(id) ? selectedIds.filter((x) => x !== id) : [
|
|
1772
|
-
...selectedIds,
|
|
1773
|
-
id
|
|
1774
|
-
];
|
|
1775
|
-
handleUpdate(nextIds);
|
|
1776
|
-
} else {
|
|
1777
|
-
if (selectedIds[0] === id) {
|
|
1778
|
-
handleUpdate([]);
|
|
1779
|
-
} else {
|
|
1780
|
-
handleUpdate([
|
|
1781
|
-
id
|
|
1782
|
-
]);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
}, [
|
|
1786
|
-
array,
|
|
1787
|
-
selectedIds,
|
|
1788
|
-
handleUpdate
|
|
1789
|
-
]);
|
|
1790
|
-
return readonly && items.length < 1 ? null : /* @__PURE__ */ React11.createElement(Input7.Root, {
|
|
1791
|
-
validationValence: status
|
|
1792
|
-
}, !inputOnly && /* @__PURE__ */ React11.createElement(InputHeader, {
|
|
1793
|
-
error,
|
|
1794
|
-
label
|
|
1795
|
-
}), /* @__PURE__ */ React11.createElement("div", {
|
|
1796
|
-
"data-no-submit": true
|
|
1797
|
-
}, readonly ? items.length < 1 ? /* @__PURE__ */ React11.createElement("p", {
|
|
1798
|
-
className: mx5(descriptionText, "mbe-2")
|
|
1799
|
-
}, t("empty readonly ref field label")) : items.map((item) => /* @__PURE__ */ React11.createElement(DxAnchor, {
|
|
1800
|
-
key: item.id,
|
|
1801
|
-
refid: item.id,
|
|
1802
|
-
rootclassname: "mie-1"
|
|
1803
|
-
}, item.label)) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
|
|
1804
|
-
asChild: true
|
|
1805
|
-
}, /* @__PURE__ */ React11.createElement(Button2, {
|
|
1806
|
-
variant: "ghost",
|
|
1807
|
-
classNames: "is-full text-start gap-2"
|
|
1808
|
-
}, /* @__PURE__ */ React11.createElement("div", {
|
|
1809
|
-
role: "none",
|
|
1810
|
-
className: "grow"
|
|
1811
|
-
}, items?.length ? items?.map((item) => /* @__PURE__ */ React11.createElement(DxTagPickerItem, {
|
|
1812
|
-
key: item.id,
|
|
1813
|
-
itemId: item.id,
|
|
1814
|
-
label: item.label,
|
|
1815
|
-
...item.hue ? {
|
|
1816
|
-
hue: item.hue
|
|
1817
|
-
} : {},
|
|
1818
|
-
removeLabel: t("remove item label"),
|
|
1819
|
-
onItemClick: (event) => {
|
|
1820
|
-
if (event.action === "remove") {
|
|
1821
|
-
toggleSelect(item.id);
|
|
1601
|
+
var defaultGetOptions = (results) => results.map((result) => {
|
|
1602
|
+
const id = Entity.getDXN(result).toString();
|
|
1603
|
+
const label = Entity.getLabel(result);
|
|
1604
|
+
return {
|
|
1605
|
+
id,
|
|
1606
|
+
label: label ?? id
|
|
1607
|
+
};
|
|
1608
|
+
});
|
|
1609
|
+
var defaultResultsHook = (db, typename) => useQuery(db, typename ? Filter.typename(typename) : Filter.nothing());
|
|
1610
|
+
var RefField = (props) => {
|
|
1611
|
+
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, db, resultsHook: useResults = defaultResultsHook, schemaHook: useSchema = useSchema$, getOptions: getOptions2 = defaultGetOptions, onCreate, onValueChange } = props;
|
|
1612
|
+
const { t } = useTranslation7(translationKey);
|
|
1613
|
+
const { status, error } = getStatus();
|
|
1614
|
+
const typename = useMemo6(() => type ? findAnnotation(type, ReferenceAnnotationId)?.typename : void 0, [
|
|
1615
|
+
type
|
|
1616
|
+
]);
|
|
1617
|
+
const results = useResults(db, typename);
|
|
1618
|
+
const options = useMemo6(() => getOptions2(results), [
|
|
1619
|
+
results,
|
|
1620
|
+
getOptions2
|
|
1621
|
+
]);
|
|
1622
|
+
const handleGetValue = useCallback9(() => {
|
|
1623
|
+
const formValue = getValue();
|
|
1624
|
+
const unknownToRefOption = (value3) => {
|
|
1625
|
+
const isRef = Ref2.isRef(value3);
|
|
1626
|
+
if (isRef || isRefSnapshot(value3)) {
|
|
1627
|
+
const dxnString = isRef ? value3.dxn.toString() : value3["/"];
|
|
1628
|
+
const matchingOption = options.find((option) => option.id === dxnString);
|
|
1629
|
+
if (matchingOption) {
|
|
1630
|
+
return matchingOption;
|
|
1822
1631
|
}
|
|
1823
1632
|
}
|
|
1824
|
-
})) : /* @__PURE__ */ React11.createElement("span", {
|
|
1825
|
-
className: "text-description"
|
|
1826
|
-
}, placeholder ?? t("ref field placeholder", {
|
|
1827
|
-
count: array ? 99 : 1
|
|
1828
|
-
}))), /* @__PURE__ */ React11.createElement(Icon3, {
|
|
1829
|
-
size: 3,
|
|
1830
|
-
icon: "ph--caret-down--bold"
|
|
1831
|
-
}))), /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
|
|
1832
|
-
options: availableOptions,
|
|
1833
|
-
selectedIds,
|
|
1834
|
-
onSelect: toggleSelect,
|
|
1835
|
-
createSchema,
|
|
1836
|
-
createOptionLabel,
|
|
1837
|
-
createOptionIcon,
|
|
1838
|
-
createInitialValuePath,
|
|
1839
|
-
onCreate: handleCreate
|
|
1840
|
-
}))), inputOnly && /* @__PURE__ */ React11.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1841
|
-
} finally {
|
|
1842
|
-
_effect.f();
|
|
1843
|
-
}
|
|
1844
|
-
};
|
|
1845
|
-
var RefFieldFallback = ({ type, label, readonly, placeholder, inputOnly, getValue: getValue3, onValueChange, ...restInputProps }) => {
|
|
1846
|
-
var _effect = _useSignals11();
|
|
1847
|
-
try {
|
|
1848
|
-
const handleOnValueChange = (_type, dxnString) => {
|
|
1849
|
-
const dxn = DXN.tryParse(dxnString);
|
|
1850
|
-
if (dxn) {
|
|
1851
|
-
onValueChange?.("object", Ref.fromDXN(dxn));
|
|
1852
|
-
} else if (dxnString === "") {
|
|
1853
|
-
onValueChange?.("object", void 0);
|
|
1854
|
-
} else {
|
|
1855
|
-
onValueChange?.("string", dxnString);
|
|
1856
|
-
}
|
|
1857
|
-
};
|
|
1858
|
-
const handleGetValue = () => {
|
|
1859
|
-
const formValue = getValue3();
|
|
1860
|
-
if (typeof formValue === "string") {
|
|
1861
|
-
return formValue;
|
|
1862
|
-
}
|
|
1863
|
-
if (Ref.isRef(formValue)) {
|
|
1864
|
-
return formValue.dxn.toString();
|
|
1865
|
-
}
|
|
1866
1633
|
return void 0;
|
|
1867
1634
|
};
|
|
1868
|
-
return
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
]);
|
|
1893
|
-
const placeholder = useMemo6(() => examples?.length ? `Example: "${examples[0]}"` : description, [
|
|
1894
|
-
examples,
|
|
1895
|
-
description
|
|
1896
|
-
]);
|
|
1897
|
-
const FoundComponent = lookupComponent?.({
|
|
1898
|
-
prop: name,
|
|
1899
|
-
schema: Schema.make(ast),
|
|
1900
|
-
inputProps: {
|
|
1901
|
-
type,
|
|
1902
|
-
format,
|
|
1903
|
-
label,
|
|
1904
|
-
readonly,
|
|
1905
|
-
placeholder,
|
|
1906
|
-
...inputProps
|
|
1907
|
-
}
|
|
1908
|
-
});
|
|
1909
|
-
if (FoundComponent) {
|
|
1910
|
-
return FoundComponent;
|
|
1911
|
-
}
|
|
1912
|
-
const jsonPath = createJsonPath3(path ?? []);
|
|
1913
|
-
const CustomComponent = Custom?.[jsonPath];
|
|
1914
|
-
if (CustomComponent) {
|
|
1915
|
-
return /* @__PURE__ */ React12.createElement(CustomComponent, {
|
|
1916
|
-
type,
|
|
1917
|
-
format,
|
|
1918
|
-
label,
|
|
1919
|
-
inputOnly: inline,
|
|
1920
|
-
placeholder,
|
|
1921
|
-
readonly,
|
|
1922
|
-
...inputProps
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
const refProps = getRefProps(property);
|
|
1926
|
-
if (refProps) {
|
|
1927
|
-
return /* @__PURE__ */ React12.createElement(RefField, {
|
|
1928
|
-
ast: refProps.ast,
|
|
1929
|
-
array: refProps.isArray,
|
|
1930
|
-
type,
|
|
1931
|
-
format,
|
|
1932
|
-
label,
|
|
1933
|
-
placeholder,
|
|
1934
|
-
readonly,
|
|
1935
|
-
inputOnly: inline,
|
|
1936
|
-
onQueryRefOptions,
|
|
1937
|
-
createOptionLabel,
|
|
1938
|
-
createOptionIcon,
|
|
1939
|
-
onCreate,
|
|
1940
|
-
createSchema,
|
|
1941
|
-
createInitialValuePath,
|
|
1942
|
-
...inputProps
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
|
-
if (array) {
|
|
1946
|
-
return /* @__PURE__ */ React12.createElement(ArrayField, {
|
|
1947
|
-
property,
|
|
1948
|
-
path,
|
|
1949
|
-
inputProps,
|
|
1950
|
-
readonly,
|
|
1951
|
-
Custom
|
|
1952
|
-
});
|
|
1953
|
-
}
|
|
1954
|
-
const InputComponent = getInputComponent(type, format);
|
|
1955
|
-
if (InputComponent) {
|
|
1956
|
-
return /* @__PURE__ */ React12.createElement(InputComponent, {
|
|
1957
|
-
type,
|
|
1958
|
-
format,
|
|
1959
|
-
label,
|
|
1960
|
-
inputOnly: inline,
|
|
1961
|
-
placeholder,
|
|
1962
|
-
readonly,
|
|
1963
|
-
...inputProps
|
|
1964
|
-
});
|
|
1965
|
-
}
|
|
1966
|
-
if (options) {
|
|
1967
|
-
return /* @__PURE__ */ React12.createElement(SelectInput, {
|
|
1968
|
-
type,
|
|
1969
|
-
format,
|
|
1970
|
-
readonly,
|
|
1971
|
-
inputOnly: inline,
|
|
1972
|
-
label,
|
|
1973
|
-
options: options.map((option) => ({
|
|
1974
|
-
value: option,
|
|
1975
|
-
label: String(option)
|
|
1976
|
-
})),
|
|
1977
|
-
placeholder,
|
|
1978
|
-
...inputProps
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
if (type === "object") {
|
|
1982
|
-
const baseNode = findNode3(ast, isDiscriminatedUnion2);
|
|
1983
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, inputProps.getValue()) : findNode3(ast, SchemaAST4.isTypeLiteral);
|
|
1984
|
-
if (typeLiteral) {
|
|
1985
|
-
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, !inline && /* @__PURE__ */ React12.createElement("h3", {
|
|
1986
|
-
className: mx6("text-lg mlb-inputSpacingBlock first:mbs-0")
|
|
1987
|
-
}, label), /* @__PURE__ */ React12.createElement(FormFields, {
|
|
1988
|
-
schema: Schema.make(typeLiteral),
|
|
1989
|
-
path,
|
|
1990
|
-
readonly,
|
|
1991
|
-
projection,
|
|
1992
|
-
onQueryRefOptions,
|
|
1993
|
-
createOptionLabel,
|
|
1994
|
-
createOptionIcon,
|
|
1995
|
-
onCreate,
|
|
1996
|
-
Custom,
|
|
1997
|
-
lookupComponent
|
|
1998
|
-
}));
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
return null;
|
|
2002
|
-
} finally {
|
|
2003
|
-
_effect.f();
|
|
2004
|
-
}
|
|
2005
|
-
};
|
|
2006
|
-
var FormFields = /* @__PURE__ */ forwardRef2(({ classNames, schema, path, filter, sort, projection, readonly, lookupComponent, Custom, onQueryRefOptions, ...props }, forwardRef4) => {
|
|
2007
|
-
var _effect = _useSignals12();
|
|
2008
|
-
try {
|
|
2009
|
-
const values = useFormValues(path);
|
|
2010
|
-
const properties = useMemo6(() => {
|
|
2011
|
-
const props2 = getSchemaProperties2(schema.ast, values, {
|
|
2012
|
-
form: true
|
|
2013
|
-
});
|
|
2014
|
-
if (projection) {
|
|
2015
|
-
const fieldProjections = projection.getFieldProjections();
|
|
2016
|
-
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
2017
|
-
const visibleProps = props2.filter((prop) => !hiddenProperties.has(prop.name));
|
|
2018
|
-
const orderedProps = [];
|
|
2019
|
-
for (const fieldProjection of fieldProjections) {
|
|
2020
|
-
const fieldPath = String(fieldProjection.field.path);
|
|
2021
|
-
const prop = visibleProps.find((p) => p.name === fieldPath);
|
|
2022
|
-
if (prop) {
|
|
2023
|
-
orderedProps.push(prop);
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
const projectionPaths = new Set(fieldProjections.map((fp) => String(fp.field.path)));
|
|
2027
|
-
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name));
|
|
2028
|
-
orderedProps.push(...remainingProps);
|
|
2029
|
-
return orderedProps;
|
|
2030
|
-
}
|
|
2031
|
-
const filtered = filter ? filter(props2) : props2;
|
|
2032
|
-
return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
|
|
2033
|
-
}, [
|
|
2034
|
-
schema,
|
|
2035
|
-
values,
|
|
2036
|
-
filter,
|
|
2037
|
-
sort,
|
|
2038
|
-
projection?.fields
|
|
2039
|
-
]);
|
|
2040
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
2041
|
-
role: "form",
|
|
2042
|
-
className: mx6("is-full", classNames),
|
|
2043
|
-
ref: forwardRef4
|
|
2044
|
-
}, properties.map((property) => {
|
|
2045
|
-
return /* @__PURE__ */ React12.createElement(ErrorBoundary, {
|
|
2046
|
-
key: property.name,
|
|
2047
|
-
path: [
|
|
2048
|
-
...path ?? [],
|
|
2049
|
-
property.name
|
|
2050
|
-
]
|
|
2051
|
-
}, /* @__PURE__ */ React12.createElement(FormField, {
|
|
2052
|
-
property,
|
|
2053
|
-
path: [
|
|
2054
|
-
...path ?? [],
|
|
2055
|
-
property.name
|
|
2056
|
-
],
|
|
2057
|
-
readonly,
|
|
2058
|
-
projection,
|
|
2059
|
-
onQueryRefOptions,
|
|
2060
|
-
lookupComponent,
|
|
2061
|
-
Custom,
|
|
2062
|
-
...props
|
|
2063
|
-
}));
|
|
2064
|
-
}).filter(isTruthy));
|
|
2065
|
-
} finally {
|
|
2066
|
-
_effect.f();
|
|
2067
|
-
}
|
|
2068
|
-
});
|
|
2069
|
-
var ErrorBoundary = class extends Component {
|
|
2070
|
-
static getDerivedStateFromError(error) {
|
|
2071
|
-
return {
|
|
2072
|
-
error
|
|
2073
|
-
};
|
|
2074
|
-
}
|
|
2075
|
-
state = {
|
|
2076
|
-
error: void 0
|
|
2077
|
-
};
|
|
2078
|
-
componentDidUpdate(prevProps) {
|
|
2079
|
-
if (prevProps.path !== this.props.path) {
|
|
2080
|
-
this.resetError();
|
|
1635
|
+
return unknownToRefOption(formValue);
|
|
1636
|
+
}, [
|
|
1637
|
+
options,
|
|
1638
|
+
getValue
|
|
1639
|
+
]);
|
|
1640
|
+
const handleUpdate = useCallback9((id) => {
|
|
1641
|
+
const item2 = options.find((option) => option.id === id);
|
|
1642
|
+
const ref = item2 ? Ref2.fromDXN(DXN.parse(item2.id)) : void 0;
|
|
1643
|
+
onValueChange(type, ref);
|
|
1644
|
+
}, [
|
|
1645
|
+
options,
|
|
1646
|
+
type,
|
|
1647
|
+
onValueChange
|
|
1648
|
+
]);
|
|
1649
|
+
const item = handleGetValue();
|
|
1650
|
+
const selectedIds = useMemo6(() => item ? [
|
|
1651
|
+
item.id
|
|
1652
|
+
] : [], [
|
|
1653
|
+
item
|
|
1654
|
+
]);
|
|
1655
|
+
const createSchema = useSchema(db, typename);
|
|
1656
|
+
const handleCreate = useCallback9((values) => {
|
|
1657
|
+
if (createSchema && onCreate) {
|
|
1658
|
+
onCreate(createSchema, values);
|
|
2081
1659
|
}
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
1660
|
+
}, [
|
|
1661
|
+
createSchema,
|
|
1662
|
+
onCreate
|
|
1663
|
+
]);
|
|
1664
|
+
const handleSelect = useCallback9((id) => {
|
|
1665
|
+
if (item?.id === id) {
|
|
1666
|
+
handleUpdate(void 0);
|
|
1667
|
+
} else {
|
|
1668
|
+
handleUpdate(id);
|
|
2090
1669
|
}
|
|
2091
|
-
|
|
1670
|
+
}, [
|
|
1671
|
+
item,
|
|
1672
|
+
handleUpdate
|
|
1673
|
+
]);
|
|
1674
|
+
if (!typename || (readonly || layout === "static") && !item) {
|
|
1675
|
+
return null;
|
|
2092
1676
|
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
1677
|
+
return /* @__PURE__ */ React12.createElement(Input7.Root, {
|
|
1678
|
+
validationValence: status
|
|
1679
|
+
}, layout !== "inline" && /* @__PURE__ */ React12.createElement(FormFieldLabel, {
|
|
1680
|
+
error,
|
|
1681
|
+
readonly,
|
|
1682
|
+
label
|
|
1683
|
+
}), /* @__PURE__ */ React12.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React12.createElement("p", {
|
|
1684
|
+
className: mx5(descriptionText, "mbe-2")
|
|
1685
|
+
}, t("empty readonly ref field label")) : /* @__PURE__ */ React12.createElement(DxAnchor, {
|
|
1686
|
+
key: item.id,
|
|
1687
|
+
refid: item.id,
|
|
1688
|
+
rootclassname: "mie-1"
|
|
1689
|
+
}, item.label) : /* @__PURE__ */ React12.createElement(ObjectPicker.Root, null, /* @__PURE__ */ React12.createElement(ObjectPicker.Trigger, {
|
|
1690
|
+
asChild: true,
|
|
1691
|
+
classNames: "p-0"
|
|
1692
|
+
}, item ? /* @__PURE__ */ React12.createElement("div", {
|
|
1693
|
+
className: "flex gap-2 is-full"
|
|
1694
|
+
}, /* @__PURE__ */ React12.createElement(Input7.Root, {
|
|
1695
|
+
key: item.id
|
|
1696
|
+
}, /* @__PURE__ */ React12.createElement(Input7.TextInput, {
|
|
1697
|
+
value: item.label,
|
|
1698
|
+
readOnly: true,
|
|
1699
|
+
classNames: "is-full"
|
|
1700
|
+
}))) : /* @__PURE__ */ React12.createElement(Button2, {
|
|
1701
|
+
classNames: "is-full text-start gap-2"
|
|
1702
|
+
}, /* @__PURE__ */ React12.createElement("div", {
|
|
1703
|
+
role: "none",
|
|
1704
|
+
className: "grow overflow-hidden"
|
|
1705
|
+
}, /* @__PURE__ */ React12.createElement("span", {
|
|
1706
|
+
className: "flex truncate text-description"
|
|
1707
|
+
}, placeholder ?? t("ref field placeholder"))), /* @__PURE__ */ React12.createElement(Icon2, {
|
|
1708
|
+
size: 3,
|
|
1709
|
+
icon: "ph--caret-down--bold"
|
|
1710
|
+
}))), /* @__PURE__ */ React12.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React12.createElement(ObjectPicker.Content, {
|
|
1711
|
+
classNames: "popover-card-width",
|
|
1712
|
+
options,
|
|
1713
|
+
selectedIds,
|
|
1714
|
+
createSchema: createSchema && omitId(createSchema),
|
|
1715
|
+
createOptionLabel,
|
|
1716
|
+
createOptionIcon,
|
|
1717
|
+
createInitialValuePath,
|
|
1718
|
+
onCreate: handleCreate,
|
|
1719
|
+
onSelect: handleSelect
|
|
1720
|
+
})))), layout === "full" && /* @__PURE__ */ React12.createElement(Input7.DescriptionAndValidation, null, error));
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
// src/components/Form/fields/SelectField.tsx
|
|
1724
|
+
import React13, { useCallback as useCallback10 } from "react";
|
|
1725
|
+
import { Input as Input8, Select } from "@dxos/react-ui";
|
|
1726
|
+
var SelectField = ({ type, readonly, label, layout, placeholder, options, getStatus, getValue, onValueChange }) => {
|
|
1727
|
+
const { status, error } = getStatus();
|
|
1728
|
+
const value3 = getValue();
|
|
1729
|
+
const handleValueChange = useCallback10((value4) => onValueChange(type, value4), [
|
|
1730
|
+
type,
|
|
1731
|
+
onValueChange
|
|
1732
|
+
]);
|
|
1733
|
+
if ((readonly || layout === "static") && value3 == null) {
|
|
1734
|
+
return null;
|
|
2097
1735
|
}
|
|
1736
|
+
return /* @__PURE__ */ React13.createElement(Input8.Root, {
|
|
1737
|
+
validationValence: status
|
|
1738
|
+
}, layout !== "inline" && /* @__PURE__ */ React13.createElement(FormFieldLabel, {
|
|
1739
|
+
error,
|
|
1740
|
+
readonly,
|
|
1741
|
+
label
|
|
1742
|
+
}), layout === "static" ? /* @__PURE__ */ React13.createElement("p", null, options?.find(({ value: optionValue }) => optionValue === value3)?.label ?? String(value3)) : /* @__PURE__ */ React13.createElement(Select.Root, {
|
|
1743
|
+
value: value3,
|
|
1744
|
+
onValueChange: handleValueChange
|
|
1745
|
+
}, /* @__PURE__ */ React13.createElement(Select.TriggerButton, {
|
|
1746
|
+
classNames: "is-full",
|
|
1747
|
+
disabled: !!readonly,
|
|
1748
|
+
placeholder
|
|
1749
|
+
}), /* @__PURE__ */ React13.createElement(Select.Portal, null, /* @__PURE__ */ React13.createElement(Select.Content, null, /* @__PURE__ */ React13.createElement(Select.Viewport, null, options?.map(({ value: value4, label: label2 }) => (
|
|
1750
|
+
// NOTE: Numeric values are converted to and from strings.
|
|
1751
|
+
/* @__PURE__ */ React13.createElement(Select.Option, {
|
|
1752
|
+
key: String(value4),
|
|
1753
|
+
value: String(value4)
|
|
1754
|
+
}, label2 ?? String(value4))
|
|
1755
|
+
))), /* @__PURE__ */ React13.createElement(Select.Arrow, null)))), layout === "full" && /* @__PURE__ */ React13.createElement(Input8.DescriptionAndValidation, null, error));
|
|
2098
1756
|
};
|
|
2099
1757
|
|
|
2100
|
-
// src/components/Form/
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
1758
|
+
// src/components/Form/fields/SelectOptionField.tsx
|
|
1759
|
+
import React14, { useCallback as useCallback11, useEffect as useEffect6, useRef as useRef3, useState as useState4 } from "react";
|
|
1760
|
+
import { PublicKey } from "@dxos/keys";
|
|
1761
|
+
import { IconButton as IconButton3, Input as Input9, Tag, useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
1762
|
+
import { List } from "@dxos/react-ui-list";
|
|
1763
|
+
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
1764
|
+
import { hues, osTranslations, subtleHover } from "@dxos/ui-theme";
|
|
1765
|
+
var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
|
|
1766
|
+
const { t } = useTranslation8(translationKey);
|
|
1767
|
+
const { status, error } = getStatus();
|
|
1768
|
+
const [selected, setSelectedId] = useState4(null);
|
|
1769
|
+
const [isNewOption, setIsNewOption] = useState4(false);
|
|
1770
|
+
const inputRef = useRef3(null);
|
|
1771
|
+
const options = getValue();
|
|
1772
|
+
useEffect6(() => {
|
|
1773
|
+
if (options === void 0) {
|
|
1774
|
+
onValueChange(type, []);
|
|
1775
|
+
}
|
|
1776
|
+
}, [
|
|
1777
|
+
options,
|
|
1778
|
+
type,
|
|
1779
|
+
onValueChange
|
|
1780
|
+
]);
|
|
1781
|
+
const randomHue = () => {
|
|
1782
|
+
const usedHues = new Set(options?.map((option) => option.color) ?? []);
|
|
1783
|
+
const unusedHues = hues.filter((hue) => !usedHues.has(hue));
|
|
1784
|
+
if (unusedHues.length > 0) {
|
|
1785
|
+
return unusedHues[Math.floor(Math.random() * unusedHues.length)];
|
|
1786
|
+
}
|
|
1787
|
+
const lastThree = new Set(options?.slice(-3).map((option) => option.color) ?? []);
|
|
1788
|
+
const availableHues = hues.filter((hue) => !lastThree.has(hue));
|
|
1789
|
+
return availableHues[Math.floor(Math.random() * availableHues.length)] ?? hues[Math.floor(Math.random() * hues.length)];
|
|
1790
|
+
};
|
|
1791
|
+
const handleAdd = useCallback11(() => {
|
|
1792
|
+
const newId = PublicKey.random().truncate();
|
|
1793
|
+
const newOption = {
|
|
1794
|
+
id: newId,
|
|
1795
|
+
title: "",
|
|
1796
|
+
color: randomHue()
|
|
1797
|
+
};
|
|
1798
|
+
onValueChange(type, [
|
|
1799
|
+
...options ?? [],
|
|
1800
|
+
newOption
|
|
2123
1801
|
]);
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
}
|
|
1802
|
+
setSelectedId(newId);
|
|
1803
|
+
setIsNewOption(true);
|
|
1804
|
+
}, [
|
|
1805
|
+
options,
|
|
1806
|
+
type,
|
|
1807
|
+
onValueChange
|
|
1808
|
+
]);
|
|
1809
|
+
const handleDelete = useCallback11((id) => {
|
|
1810
|
+
const newOptions = options?.filter((option) => option.id !== id) ?? [];
|
|
1811
|
+
onValueChange(type, newOptions);
|
|
1812
|
+
setSelectedId(null);
|
|
1813
|
+
}, [
|
|
1814
|
+
options,
|
|
1815
|
+
type,
|
|
1816
|
+
onValueChange
|
|
1817
|
+
]);
|
|
1818
|
+
const handleMove = useCallback11((from, to) => {
|
|
1819
|
+
if (!options) {
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1822
|
+
const newOptions = [
|
|
1823
|
+
...options
|
|
1824
|
+
];
|
|
1825
|
+
const [removed] = newOptions.splice(from, 1);
|
|
1826
|
+
newOptions.splice(to, 0, removed);
|
|
1827
|
+
onValueChange(type, newOptions);
|
|
1828
|
+
}, [
|
|
1829
|
+
options,
|
|
1830
|
+
type,
|
|
1831
|
+
onValueChange
|
|
1832
|
+
]);
|
|
1833
|
+
const handleClick = useCallback11((id) => {
|
|
1834
|
+
setSelectedId((current) => current === id ? null : id);
|
|
1835
|
+
}, []);
|
|
1836
|
+
const handleTitleChange = useCallback11((id) => (e) => {
|
|
1837
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1838
|
+
...o,
|
|
1839
|
+
title: e.target.value
|
|
1840
|
+
} : o);
|
|
1841
|
+
onValueChange(type, newOptions ?? []);
|
|
1842
|
+
}, [
|
|
1843
|
+
options,
|
|
1844
|
+
type,
|
|
1845
|
+
onValueChange
|
|
1846
|
+
]);
|
|
1847
|
+
const handleKeyDown = useCallback11((ev) => {
|
|
1848
|
+
if (ev.key === "Enter") {
|
|
1849
|
+
setSelectedId(null);
|
|
1850
|
+
}
|
|
1851
|
+
}, []);
|
|
1852
|
+
const handleColorChange = useCallback11((id) => (hue) => {
|
|
1853
|
+
const newOptions = options?.map((o) => o.id === id ? {
|
|
1854
|
+
...o,
|
|
1855
|
+
color: hue
|
|
1856
|
+
} : o);
|
|
1857
|
+
onValueChange(type, newOptions ?? []);
|
|
1858
|
+
}, [
|
|
1859
|
+
options,
|
|
1860
|
+
type,
|
|
1861
|
+
onValueChange
|
|
1862
|
+
]);
|
|
1863
|
+
useEffect6(() => {
|
|
1864
|
+
if (selected && isNewOption && inputRef.current) {
|
|
1865
|
+
inputRef.current.focus();
|
|
1866
|
+
setIsNewOption(false);
|
|
1867
|
+
}
|
|
1868
|
+
}, [
|
|
1869
|
+
selected,
|
|
1870
|
+
isNewOption
|
|
1871
|
+
]);
|
|
1872
|
+
return /* @__PURE__ */ React14.createElement(Input9.Root, {
|
|
1873
|
+
validationValence: status
|
|
1874
|
+
}, /* @__PURE__ */ React14.createElement(FormFieldLabel, {
|
|
1875
|
+
error,
|
|
1876
|
+
readonly,
|
|
1877
|
+
label
|
|
1878
|
+
}), /* @__PURE__ */ React14.createElement("div", {
|
|
1879
|
+
role: "none"
|
|
1880
|
+
}, options && /* @__PURE__ */ React14.createElement(List.Root, {
|
|
1881
|
+
items: options,
|
|
1882
|
+
isItem: (_item) => true,
|
|
1883
|
+
onMove: readonly ? void 0 : handleMove,
|
|
1884
|
+
readonly: !!readonly
|
|
1885
|
+
}, ({ items }) => /* @__PURE__ */ React14.createElement("div", {
|
|
1886
|
+
role: "list",
|
|
1887
|
+
className: "is-full overflow-auto"
|
|
1888
|
+
}, items?.map((item) => /* @__PURE__ */ React14.createElement("div", {
|
|
1889
|
+
key: item.id
|
|
1890
|
+
}, /* @__PURE__ */ React14.createElement(List.Item, {
|
|
1891
|
+
role: "button",
|
|
1892
|
+
item,
|
|
1893
|
+
classNames: [
|
|
1894
|
+
subtleHover,
|
|
1895
|
+
"flex flex-col cursor-pointer rounded-sm"
|
|
1896
|
+
],
|
|
1897
|
+
"aria-expanded": selected === item.id
|
|
1898
|
+
}, /* @__PURE__ */ React14.createElement("div", {
|
|
1899
|
+
className: "flex items-center"
|
|
1900
|
+
}, /* @__PURE__ */ React14.createElement(List.ItemDragHandle, {
|
|
1901
|
+
disabled: !!readonly
|
|
1902
|
+
}), /* @__PURE__ */ React14.createElement(List.ItemTitle, {
|
|
1903
|
+
onClick: () => handleClick(item.id),
|
|
1904
|
+
classNames: "flex-1"
|
|
1905
|
+
}, /* @__PURE__ */ React14.createElement(Tag, {
|
|
1906
|
+
palette: item.color
|
|
1907
|
+
}, item.title || "\u200B")), /* @__PURE__ */ React14.createElement(IconButton3, {
|
|
1908
|
+
iconOnly: true,
|
|
1909
|
+
variant: "ghost",
|
|
1910
|
+
label: t(selected === item.id ? "collapse label" : "expand label", {
|
|
1911
|
+
ns: osTranslations
|
|
1912
|
+
}),
|
|
1913
|
+
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
1914
|
+
onClick: () => handleClick(item.id)
|
|
1915
|
+
})), selected === item.id && /* @__PURE__ */ React14.createElement("div", {
|
|
1916
|
+
className: "pli-cardSpacingInline plb-cardSpacingBlock flex flex-col gap-1 density-fine"
|
|
1917
|
+
}, /* @__PURE__ */ React14.createElement(Input9.Label, {
|
|
1918
|
+
classNames: "text-xs"
|
|
1919
|
+
}, t("select option label")), /* @__PURE__ */ React14.createElement("div", {
|
|
1920
|
+
className: "grid grid-cols-[1fr_min-content_min-content] gap-1"
|
|
1921
|
+
}, /* @__PURE__ */ React14.createElement(Input9.TextInput, {
|
|
1922
|
+
disabled: !!readonly,
|
|
1923
|
+
placeholder: t("select option label placeholder"),
|
|
1924
|
+
ref: selected === item.id ? inputRef : void 0,
|
|
1925
|
+
value: item.title,
|
|
1926
|
+
onChange: handleTitleChange(item.id),
|
|
1927
|
+
onKeyDown: handleKeyDown,
|
|
1928
|
+
classNames: "flex-1"
|
|
1929
|
+
}), /* @__PURE__ */ React14.createElement(HuePicker, {
|
|
1930
|
+
disabled: !!readonly,
|
|
1931
|
+
value: item.color,
|
|
1932
|
+
onChange: handleColorChange(item.id)
|
|
1933
|
+
}), /* @__PURE__ */ React14.createElement(IconButton3, {
|
|
1934
|
+
disabled: !!readonly,
|
|
1935
|
+
icon: "ph--trash--fill",
|
|
1936
|
+
iconOnly: true,
|
|
1937
|
+
label: t("select option delete"),
|
|
1938
|
+
onClick: () => handleDelete(item.id)
|
|
1939
|
+
})))))), /* @__PURE__ */ React14.createElement(IconButton3, {
|
|
1940
|
+
variant: "ghost",
|
|
1941
|
+
icon: "ph--plus--regular",
|
|
1942
|
+
label: t("select option add"),
|
|
1943
|
+
onClick: handleAdd,
|
|
1944
|
+
disabled: !!readonly,
|
|
1945
|
+
classNames: "is-full"
|
|
1946
|
+
})))));
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
// src/components/Form/fields/TextField.tsx
|
|
1950
|
+
import React15, { useCallback as useCallback12 } from "react";
|
|
1951
|
+
import { Input as Input10 } from "@dxos/react-ui";
|
|
1952
|
+
var TextField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1953
|
+
const handleChange = useCallback12((event) => onValueChange(type, event.target.value), [
|
|
1954
|
+
type,
|
|
1955
|
+
onValueChange
|
|
1956
|
+
]);
|
|
1957
|
+
return /* @__PURE__ */ React15.createElement(FormFieldWrapper, {
|
|
1958
|
+
readonly,
|
|
1959
|
+
...props
|
|
1960
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React15.createElement(Input10.TextInput, {
|
|
1961
|
+
noAutoFill: true,
|
|
1962
|
+
disabled: !!readonly,
|
|
1963
|
+
placeholder,
|
|
1964
|
+
value: value3,
|
|
1965
|
+
onChange: handleChange,
|
|
1966
|
+
onBlur
|
|
1967
|
+
}));
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
// src/components/Form/fields/TextAreaField.tsx
|
|
1971
|
+
import React16, { useCallback as useCallback13 } from "react";
|
|
1972
|
+
import { Input as Input11 } from "@dxos/react-ui";
|
|
1973
|
+
var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props }) => {
|
|
1974
|
+
const handleChange = useCallback13((event) => onValueChange(type, event.target.value), [
|
|
1975
|
+
type,
|
|
1976
|
+
onValueChange
|
|
1977
|
+
]);
|
|
1978
|
+
return /* @__PURE__ */ React16.createElement(FormFieldWrapper, {
|
|
1979
|
+
readonly,
|
|
1980
|
+
...props
|
|
1981
|
+
}, ({ value: value3 = "" }) => /* @__PURE__ */ React16.createElement(Input11.TextArea, {
|
|
1982
|
+
rows: 3,
|
|
1983
|
+
disabled: !!readonly,
|
|
1984
|
+
placeholder,
|
|
1985
|
+
value: value3,
|
|
1986
|
+
onChange: handleChange,
|
|
1987
|
+
onBlur
|
|
1988
|
+
}));
|
|
1989
|
+
};
|
|
1990
|
+
|
|
1991
|
+
// src/components/Form/fields/TupleField.tsx
|
|
1992
|
+
import React17 from "react";
|
|
1993
|
+
import { Input as Input12 } from "@dxos/react-ui";
|
|
1994
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
1995
|
+
import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
|
|
1996
|
+
var gridCols = [
|
|
1997
|
+
"grid-cols-1",
|
|
1998
|
+
"grid-cols-2",
|
|
1999
|
+
"grid-cols-3",
|
|
2000
|
+
"grid-cols-4"
|
|
2001
|
+
];
|
|
2002
|
+
var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValueChange, onBlur }) => {
|
|
2003
|
+
const { status, error } = getStatus();
|
|
2004
|
+
const values = getValue() ?? {};
|
|
2005
|
+
return /* @__PURE__ */ React17.createElement(Input12.Root, {
|
|
2006
|
+
validationValence: status
|
|
2007
|
+
}, /* @__PURE__ */ React17.createElement(FormFieldLabel, {
|
|
2008
|
+
error,
|
|
2009
|
+
readonly,
|
|
2010
|
+
label
|
|
2011
|
+
}), /* @__PURE__ */ React17.createElement("div", {
|
|
2012
|
+
className: mx6("grid gap-2", gridCols[binding.length - 1])
|
|
2013
|
+
}, binding.map((prop) => /* @__PURE__ */ React17.createElement(Input12.TextInput, {
|
|
2014
|
+
key: prop,
|
|
2015
|
+
type: "number",
|
|
2016
|
+
disabled: !!readonly,
|
|
2017
|
+
value: values[prop],
|
|
2018
|
+
onChange: (event) => {
|
|
2019
|
+
onValueChange(type, {
|
|
2020
|
+
...values,
|
|
2021
|
+
[prop]: safeParseFloat3(event.target.value, 0)
|
|
2022
|
+
});
|
|
2023
|
+
},
|
|
2024
|
+
onBlur
|
|
2025
|
+
}))));
|
|
2158
2026
|
};
|
|
2159
2027
|
|
|
2160
2028
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
2161
|
-
var
|
|
2162
|
-
var FieldEditor = ({ readonly, projection, field, registry, onSave, onCancel
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2029
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
2030
|
+
var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
|
|
2031
|
+
const { t } = useTranslation9(translationKey);
|
|
2032
|
+
const [props, setProps] = useState5(projection.getFieldProjection(field.id).props);
|
|
2033
|
+
useEffect7(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
2034
|
+
field,
|
|
2035
|
+
projection
|
|
2036
|
+
]);
|
|
2037
|
+
const [schemas, setSchemas] = useState5([]);
|
|
2038
|
+
useAsyncEffect(async () => {
|
|
2039
|
+
if (!registry) {
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
const subscription = registry.query().subscribe((query) => setSchemas(query.results), {
|
|
2043
|
+
fire: true
|
|
2044
|
+
});
|
|
2045
|
+
const schemas2 = await registry.query().run();
|
|
2046
|
+
setSchemas(schemas2);
|
|
2047
|
+
return () => subscription?.();
|
|
2048
|
+
}, [
|
|
2049
|
+
registry
|
|
2050
|
+
]);
|
|
2051
|
+
const [referenceSchema, setReferenceSchema] = useState5();
|
|
2052
|
+
useEffect7(() => {
|
|
2053
|
+
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2054
|
+
}, [
|
|
2055
|
+
schemas,
|
|
2056
|
+
props?.referenceSchema
|
|
2057
|
+
]);
|
|
2058
|
+
const [{ fieldSchema }, setFieldSchema] = useState5({
|
|
2059
|
+
fieldSchema: getFormatSchema(props?.format)
|
|
2060
|
+
});
|
|
2061
|
+
const fieldMap = useMemo7(() => ({
|
|
2062
|
+
["format"]: (props2) => /* @__PURE__ */ React18.createElement(SelectField, {
|
|
2063
|
+
...props2,
|
|
2064
|
+
options: FormatEnums.filter((value3) => value3 !== Format4.TypeFormat.None).map((value3) => ({
|
|
2065
|
+
value: value3,
|
|
2066
|
+
label: t(`format ${value3}`)
|
|
2067
|
+
}))
|
|
2068
|
+
}),
|
|
2069
|
+
["referenceSchema"]: (props2) => /* @__PURE__ */ React18.createElement(SelectField, {
|
|
2070
|
+
...props2,
|
|
2071
|
+
options: schemas.map((schema) => ({
|
|
2072
|
+
value: schema.typename
|
|
2073
|
+
}))
|
|
2074
|
+
}),
|
|
2075
|
+
["referencePath"]: (props2) => /* @__PURE__ */ React18.createElement(SelectField, {
|
|
2076
|
+
...props2,
|
|
2077
|
+
options: referenceSchema ? getFormProperties(referenceSchema.ast).sort((a, b) => a.name.toString().localeCompare(b.name.toString())).map((p) => ({
|
|
2078
|
+
value: p.name.toString()
|
|
2079
|
+
})) : []
|
|
2080
|
+
}),
|
|
2081
|
+
["options"]: (props2) => /* @__PURE__ */ React18.createElement(SelectOptionField, props2)
|
|
2082
|
+
}), [
|
|
2083
|
+
t,
|
|
2084
|
+
schemas,
|
|
2085
|
+
referenceSchema
|
|
2086
|
+
]);
|
|
2087
|
+
const propIsNotType = useCallback14((props2) => props2.filter((prop) => prop.name !== "type"), []);
|
|
2088
|
+
const handleValuesChanged = useCallback14((_props) => {
|
|
2089
|
+
setFieldSchema((prev) => {
|
|
2090
|
+
const fieldSchema2 = getFormatSchema(_props.format);
|
|
2091
|
+
if (prev.fieldSchema === fieldSchema2) {
|
|
2092
|
+
return prev;
|
|
2175
2093
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
}
|
|
2179
|
-
const schemas2 = await registry.query().run();
|
|
2180
|
-
setSchemas(schemas2);
|
|
2181
|
-
return () => subscription?.();
|
|
2182
|
-
}, [
|
|
2183
|
-
registry
|
|
2184
|
-
]);
|
|
2185
|
-
const [referenceSchema, setReferenceSchema] = useState6();
|
|
2186
|
-
useEffect8(() => {
|
|
2187
|
-
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2188
|
-
}, [
|
|
2189
|
-
schemas,
|
|
2190
|
-
props?.referenceSchema
|
|
2191
|
-
]);
|
|
2192
|
-
const [{ fieldSchema }, setFieldSchema] = useState6({
|
|
2193
|
-
fieldSchema: getFormatSchema(props?.format)
|
|
2094
|
+
return {
|
|
2095
|
+
fieldSchema: fieldSchema2
|
|
2096
|
+
};
|
|
2194
2097
|
});
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
const
|
|
2198
|
-
if (
|
|
2199
|
-
return
|
|
2098
|
+
setReferenceSchema((prev) => {
|
|
2099
|
+
if (_props.referenceSchema !== prev?.typename) {
|
|
2100
|
+
const newSchema = schemas.find((schema) => schema.typename === _props.referenceSchema);
|
|
2101
|
+
if (newSchema) {
|
|
2102
|
+
return newSchema;
|
|
2200
2103
|
}
|
|
2104
|
+
}
|
|
2105
|
+
return prev;
|
|
2106
|
+
});
|
|
2107
|
+
setProps((props2) => {
|
|
2108
|
+
const type = formatToType[_props.format];
|
|
2109
|
+
const additionalProps = formatToAdditionalPropertyAttributes[_props.format];
|
|
2110
|
+
if (props2.type !== type) {
|
|
2201
2111
|
return {
|
|
2202
|
-
|
|
2112
|
+
...props2,
|
|
2113
|
+
..._props,
|
|
2114
|
+
...additionalProps,
|
|
2115
|
+
type
|
|
2203
2116
|
};
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
return {
|
|
2219
|
-
...props2,
|
|
2220
|
-
..._props,
|
|
2221
|
-
...additionalProps,
|
|
2222
|
-
type
|
|
2223
|
-
};
|
|
2117
|
+
}
|
|
2118
|
+
return _props;
|
|
2119
|
+
});
|
|
2120
|
+
}, [
|
|
2121
|
+
schemas,
|
|
2122
|
+
props.format,
|
|
2123
|
+
props.referenceSchema
|
|
2124
|
+
]);
|
|
2125
|
+
const handleValidate = useCallback14(({ property }) => {
|
|
2126
|
+
if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
|
|
2127
|
+
return [
|
|
2128
|
+
{
|
|
2129
|
+
path: "property",
|
|
2130
|
+
message: `property is not unique: '${property}'`
|
|
2224
2131
|
}
|
|
2225
|
-
|
|
2132
|
+
];
|
|
2133
|
+
}
|
|
2134
|
+
}, [
|
|
2135
|
+
projection.getFields(),
|
|
2136
|
+
field
|
|
2137
|
+
]);
|
|
2138
|
+
const handleSave = useCallback14((props2) => {
|
|
2139
|
+
if (view) {
|
|
2140
|
+
Obj3.change(view, () => {
|
|
2141
|
+
projection.setFieldProjection({
|
|
2142
|
+
field,
|
|
2143
|
+
props: props2
|
|
2144
|
+
});
|
|
2226
2145
|
});
|
|
2227
|
-
}
|
|
2228
|
-
schemas,
|
|
2229
|
-
props.format,
|
|
2230
|
-
props.referenceSchema
|
|
2231
|
-
]);
|
|
2232
|
-
const handleValidate = useCallback12(({ property }) => {
|
|
2233
|
-
if (property && projection.fields.find((f) => f.path === property && f.path !== field.path)) {
|
|
2234
|
-
return [
|
|
2235
|
-
{
|
|
2236
|
-
path: "property",
|
|
2237
|
-
message: `property is not unique: '${property}'`
|
|
2238
|
-
}
|
|
2239
|
-
];
|
|
2240
|
-
}
|
|
2241
|
-
}, [
|
|
2242
|
-
projection.fields,
|
|
2243
|
-
field
|
|
2244
|
-
]);
|
|
2245
|
-
const handleSave = useCallback12((props2) => {
|
|
2146
|
+
} else {
|
|
2246
2147
|
projection.setFieldProjection({
|
|
2247
2148
|
field,
|
|
2248
2149
|
props: props2
|
|
2249
2150
|
});
|
|
2250
|
-
onSave();
|
|
2251
|
-
}, [
|
|
2252
|
-
projection,
|
|
2253
|
-
field,
|
|
2254
|
-
onSave
|
|
2255
|
-
]);
|
|
2256
|
-
const handleCancel = useCallback12(() => {
|
|
2257
|
-
requestAnimationFrame(() => onCancel?.());
|
|
2258
|
-
onSave();
|
|
2259
|
-
}, [
|
|
2260
|
-
onSave
|
|
2261
|
-
]);
|
|
2262
|
-
const custom = useMemo7(() => ({
|
|
2263
|
-
["format"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2264
|
-
...props2,
|
|
2265
|
-
options: FormatEnums.filter((value2) => value2 !== Format5.TypeFormat.None).map((value2) => ({
|
|
2266
|
-
value: value2,
|
|
2267
|
-
label: t(`format ${value2}`)
|
|
2268
|
-
}))
|
|
2269
|
-
}),
|
|
2270
|
-
["referenceSchema"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2271
|
-
...props2,
|
|
2272
|
-
options: schemas.map((schema) => ({
|
|
2273
|
-
value: schema.typename
|
|
2274
|
-
}))
|
|
2275
|
-
}),
|
|
2276
|
-
["referencePath"]: (props2) => /* @__PURE__ */ React14.createElement(SelectInput, {
|
|
2277
|
-
...props2,
|
|
2278
|
-
options: referenceSchema ? getSchemaProperties3(referenceSchema.ast, {}, {
|
|
2279
|
-
form: true
|
|
2280
|
-
}).sort(sortProperties).map((p) => ({
|
|
2281
|
-
value: p.name
|
|
2282
|
-
})) : []
|
|
2283
|
-
}),
|
|
2284
|
-
["options"]: (props2) => /* @__PURE__ */ React14.createElement(SelectOptionInput, props2)
|
|
2285
|
-
}), [
|
|
2286
|
-
t,
|
|
2287
|
-
schemas,
|
|
2288
|
-
referenceSchema
|
|
2289
|
-
]);
|
|
2290
|
-
const propIsNotType = useCallback12((props2) => props2.filter((p) => p.name !== "type"), []);
|
|
2291
|
-
if (!fieldSchema) {
|
|
2292
|
-
log3.warn("invalid format", {
|
|
2293
|
-
props
|
|
2294
|
-
}, {
|
|
2295
|
-
F: __dxlog_file4,
|
|
2296
|
-
L: 180,
|
|
2297
|
-
S: void 0,
|
|
2298
|
-
C: (f, a) => f(...a)
|
|
2299
|
-
});
|
|
2300
|
-
return null;
|
|
2301
2151
|
}
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2152
|
+
onSave();
|
|
2153
|
+
}, [
|
|
2154
|
+
projection,
|
|
2155
|
+
field,
|
|
2156
|
+
view,
|
|
2157
|
+
onSave
|
|
2158
|
+
]);
|
|
2159
|
+
const handleCancel = useCallback14(() => {
|
|
2160
|
+
onSave();
|
|
2161
|
+
requestAnimationFrame(() => onCancel?.());
|
|
2162
|
+
}, [
|
|
2163
|
+
onSave
|
|
2164
|
+
]);
|
|
2165
|
+
if (!fieldSchema) {
|
|
2166
|
+
log2.warn("invalid format", {
|
|
2167
|
+
props
|
|
2168
|
+
}, {
|
|
2169
|
+
F: __dxlog_file2,
|
|
2170
|
+
L: 173,
|
|
2171
|
+
S: void 0,
|
|
2172
|
+
C: (f, a) => f(...a)
|
|
2319
2173
|
});
|
|
2320
|
-
|
|
2321
|
-
_effect.f();
|
|
2174
|
+
return null;
|
|
2322
2175
|
}
|
|
2176
|
+
return /* @__PURE__ */ React18.createElement(Form.Root, {
|
|
2177
|
+
key: field.id,
|
|
2178
|
+
fieldMap,
|
|
2179
|
+
autoFocus: true,
|
|
2180
|
+
readonly,
|
|
2181
|
+
schema: fieldSchema,
|
|
2182
|
+
values: props,
|
|
2183
|
+
exclude: propIsNotType,
|
|
2184
|
+
sort: [
|
|
2185
|
+
"property",
|
|
2186
|
+
"format"
|
|
2187
|
+
],
|
|
2188
|
+
onValuesChanged: handleValuesChanged,
|
|
2189
|
+
onValidate: handleValidate,
|
|
2190
|
+
onSave: handleSave,
|
|
2191
|
+
onCancel: handleCancel
|
|
2192
|
+
}, /* @__PURE__ */ React18.createElement(Form.Content, null, /* @__PURE__ */ React18.createElement(Form.FieldSet, null), /* @__PURE__ */ React18.createElement(Form.Actions, null)));
|
|
2323
2193
|
};
|
|
2324
2194
|
|
|
2325
2195
|
// src/components/ViewEditor/ViewEditor.tsx
|
|
2326
|
-
import {
|
|
2196
|
+
import { RegistryContext } from "@effect-atom/atom-react";
|
|
2327
2197
|
import * as Array2 from "effect/Array";
|
|
2328
|
-
import * as
|
|
2329
|
-
import * as
|
|
2330
|
-
import * as
|
|
2331
|
-
import
|
|
2332
|
-
import { QueryAST } from "@dxos/echo";
|
|
2333
|
-
import { EchoSchema,
|
|
2334
|
-
import {
|
|
2335
|
-
import {
|
|
2336
|
-
import { Callout, IconButton as IconButton4, Input as
|
|
2198
|
+
import * as Match2 from "effect/Match";
|
|
2199
|
+
import * as Option4 from "effect/Option";
|
|
2200
|
+
import * as Schema3 from "effect/Schema";
|
|
2201
|
+
import React19, { forwardRef as forwardRef3, useCallback as useCallback15, useContext, useImperativeHandle, useMemo as useMemo8, useState as useState6 } from "react";
|
|
2202
|
+
import { Filter as Filter2, Format as Format5, Obj as Obj4, Query, QueryAST } from "@dxos/echo";
|
|
2203
|
+
import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
|
|
2204
|
+
import { invariant } from "@dxos/invariant";
|
|
2205
|
+
import { useObject } from "@dxos/react-client/echo";
|
|
2206
|
+
import { Callout, IconButton as IconButton4, Input as Input13, useTranslation as useTranslation10 } from "@dxos/react-ui";
|
|
2337
2207
|
import { QueryForm } from "@dxos/react-ui-components";
|
|
2338
2208
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
2339
|
-
import {
|
|
2340
|
-
import {
|
|
2341
|
-
|
|
2342
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2209
|
+
import { FieldSchema, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
|
|
2210
|
+
import { mx as mx7, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
|
|
2211
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2343
2212
|
var listGrid = "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]";
|
|
2344
2213
|
var listItemGrid = "grid grid-cols-subgrid col-span-5";
|
|
2345
|
-
var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode = "schema", registry, readonly, showHeading = false, types, tags, onQueryChanged, onDelete
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
schema,
|
|
2355
|
-
JSON.stringify(view.projection)
|
|
2356
|
-
]);
|
|
2357
|
-
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
2358
|
-
projectionModel
|
|
2359
|
-
]);
|
|
2360
|
-
const [expandedField, setExpandedField] = useState7();
|
|
2361
|
-
const queueTarget = Match.value(view.query.ast).pipe(Match.when({
|
|
2362
|
-
type: "options"
|
|
2363
|
-
}, ({ options }) => {
|
|
2364
|
-
return Option.fromNullable(options.queues).pipe(Option.flatMap((queues) => Array2.head(queues)), Option.getOrUndefined);
|
|
2365
|
-
}), Match.orElse(() => void 0));
|
|
2366
|
-
const viewSchema = useMemo8(() => {
|
|
2367
|
-
const base = Schema2.Struct({
|
|
2368
|
-
query: mode === "schema" ? Format6.URL.annotations({
|
|
2369
|
-
title: "Record type"
|
|
2370
|
-
}) : QueryAST.Query.annotations({
|
|
2371
|
-
title: "Query"
|
|
2372
|
-
})
|
|
2373
|
-
});
|
|
2374
|
-
if (mode === "tag") {
|
|
2375
|
-
return Schema2.Struct({
|
|
2376
|
-
...base.fields,
|
|
2377
|
-
target: Schema2.optional(Schema2.String.annotations({
|
|
2378
|
-
title: "Target Queue"
|
|
2379
|
-
}))
|
|
2380
|
-
}).pipe(Schema2.mutable);
|
|
2381
|
-
}
|
|
2382
|
-
return base.pipe(Schema2.mutable);
|
|
2383
|
-
}, [
|
|
2384
|
-
mode
|
|
2385
|
-
]);
|
|
2386
|
-
const viewValues = useMemo8(() => ({
|
|
2387
|
-
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2388
|
-
target: queueTarget
|
|
2389
|
-
}), [
|
|
2390
|
-
mode,
|
|
2391
|
-
view.query.ast,
|
|
2392
|
-
queueTarget
|
|
2393
|
-
]);
|
|
2394
|
-
const handleToggleField = useCallback13((field) => {
|
|
2395
|
-
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2396
|
-
}, [
|
|
2397
|
-
readonly
|
|
2398
|
-
]);
|
|
2399
|
-
const handleAdd = useCallback13(() => {
|
|
2400
|
-
invariant3(!readonly, void 0, {
|
|
2401
|
-
F: __dxlog_file5,
|
|
2402
|
-
L: 129,
|
|
2403
|
-
S: void 0,
|
|
2404
|
-
A: [
|
|
2405
|
-
"!readonly",
|
|
2406
|
-
""
|
|
2407
|
-
]
|
|
2408
|
-
});
|
|
2409
|
-
const field = projectionModel.createFieldProjection();
|
|
2410
|
-
setExpandedField(field.id);
|
|
2411
|
-
}, [
|
|
2412
|
-
schema,
|
|
2413
|
-
projectionModel,
|
|
2414
|
-
readonly
|
|
2415
|
-
]);
|
|
2416
|
-
const handleUpdate = useCallback13((values) => {
|
|
2417
|
-
requestAnimationFrame(() => {
|
|
2418
|
-
const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : values.query;
|
|
2419
|
-
onQueryChanged?.(query, values.target);
|
|
2420
|
-
});
|
|
2421
|
-
}, [
|
|
2422
|
-
onQueryChanged,
|
|
2214
|
+
var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode = "schema", registry, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
|
|
2215
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2216
|
+
const schemaReadonly = !isMutable(schema);
|
|
2217
|
+
const { t } = useTranslation10(translationKey);
|
|
2218
|
+
const projectionModel = useMemo8(() => {
|
|
2219
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2220
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2221
|
+
const model = new ProjectionModel({
|
|
2222
|
+
registry: atomRegistry,
|
|
2423
2223
|
view,
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2224
|
+
baseSchema: jsonSchema,
|
|
2225
|
+
change
|
|
2226
|
+
});
|
|
2227
|
+
return model;
|
|
2228
|
+
}, [
|
|
2229
|
+
atomRegistry,
|
|
2230
|
+
schema,
|
|
2231
|
+
view
|
|
2232
|
+
]);
|
|
2233
|
+
useImperativeHandle(forwardedRef, () => projectionModel, [
|
|
2234
|
+
projectionModel
|
|
2235
|
+
]);
|
|
2236
|
+
const [expandedField, setExpandedField] = useState6();
|
|
2237
|
+
const queueTarget = Match2.value(view.query.ast).pipe(Match2.when({
|
|
2238
|
+
type: "options"
|
|
2239
|
+
}, ({ options }) => {
|
|
2240
|
+
return Option4.fromNullable(options.queues).pipe(Option4.flatMap((queues) => Array2.head(queues)), Option4.getOrUndefined);
|
|
2241
|
+
}), Match2.orElse(() => void 0));
|
|
2242
|
+
const viewSchema = useMemo8(() => {
|
|
2243
|
+
const base = Schema3.Struct({
|
|
2244
|
+
query: mode === "schema" ? Format5.URL.annotations({
|
|
2245
|
+
title: "Record type"
|
|
2246
|
+
}) : QueryAST.Query.annotations({
|
|
2247
|
+
title: "Query"
|
|
2248
|
+
})
|
|
2249
|
+
});
|
|
2250
|
+
if (mode === "tag") {
|
|
2251
|
+
return Schema3.Struct({
|
|
2252
|
+
...base.fields,
|
|
2253
|
+
target: Schema3.optional(Schema3.String.annotations({
|
|
2254
|
+
title: "Target Queue"
|
|
2255
|
+
}))
|
|
2256
|
+
}).pipe(Schema3.mutable);
|
|
2257
|
+
}
|
|
2258
|
+
return base.pipe(Schema3.mutable);
|
|
2259
|
+
}, [
|
|
2260
|
+
mode
|
|
2261
|
+
]);
|
|
2262
|
+
const viewValues = useMemo8(() => ({
|
|
2263
|
+
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2264
|
+
target: queueTarget
|
|
2265
|
+
}), [
|
|
2266
|
+
mode,
|
|
2267
|
+
view.query.ast,
|
|
2268
|
+
queueTarget
|
|
2269
|
+
]);
|
|
2270
|
+
const fieldMap = useMemo8(() => mode === "tag" ? customFields({
|
|
2271
|
+
types,
|
|
2272
|
+
tags
|
|
2273
|
+
}) : void 0, [
|
|
2274
|
+
mode,
|
|
2275
|
+
types,
|
|
2276
|
+
tags
|
|
2277
|
+
]);
|
|
2278
|
+
const handleAdd = useCallback15(() => {
|
|
2279
|
+
invariant(!readonly, void 0, {
|
|
2280
|
+
F: __dxlog_file3,
|
|
2281
|
+
L: 146,
|
|
2282
|
+
S: void 0,
|
|
2283
|
+
A: [
|
|
2284
|
+
"!readonly",
|
|
2285
|
+
""
|
|
2286
|
+
]
|
|
2287
|
+
});
|
|
2288
|
+
const field = projectionModel.createFieldProjection();
|
|
2289
|
+
setExpandedField(field.id);
|
|
2290
|
+
}, [
|
|
2291
|
+
projectionModel,
|
|
2292
|
+
readonly
|
|
2293
|
+
]);
|
|
2294
|
+
const handleUpdate = useCallback15((values) => {
|
|
2295
|
+
requestAnimationFrame(() => {
|
|
2296
|
+
const query = mode === "schema" ? Query.select(Filter2.typename(values.query)).ast : values.query;
|
|
2297
|
+
onQueryChanged?.(query, values.target);
|
|
2298
|
+
});
|
|
2299
|
+
}, [
|
|
2300
|
+
onQueryChanged,
|
|
2301
|
+
view,
|
|
2302
|
+
queueTarget,
|
|
2303
|
+
mode
|
|
2304
|
+
]);
|
|
2305
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2306
|
+
invariant(!readonly, void 0, {
|
|
2307
|
+
F: __dxlog_file3,
|
|
2308
|
+
L: 163,
|
|
2309
|
+
S: void 0,
|
|
2310
|
+
A: [
|
|
2311
|
+
"!readonly",
|
|
2312
|
+
""
|
|
2313
|
+
]
|
|
2314
|
+
});
|
|
2315
|
+
if (fieldId === expandedField) {
|
|
2316
|
+
setExpandedField(void 0);
|
|
2317
|
+
}
|
|
2318
|
+
onDelete?.(fieldId);
|
|
2319
|
+
}, [
|
|
2320
|
+
expandedField,
|
|
2321
|
+
onDelete,
|
|
2322
|
+
readonly
|
|
2323
|
+
]);
|
|
2324
|
+
return /* @__PURE__ */ React19.createElement("div", {
|
|
2325
|
+
role: "none",
|
|
2326
|
+
className: mx7(classNames)
|
|
2327
|
+
}, schemaReadonly && !readonly && /* @__PURE__ */ React19.createElement(Callout.Root, {
|
|
2328
|
+
valence: "info",
|
|
2329
|
+
classNames: "mlb-cardSpacingBlock"
|
|
2330
|
+
}, /* @__PURE__ */ React19.createElement(Callout.Title, null, t("system schema description"))), /* @__PURE__ */ React19.createElement(Form.Root, {
|
|
2331
|
+
schema: viewSchema,
|
|
2332
|
+
values: viewValues,
|
|
2333
|
+
fieldMap,
|
|
2334
|
+
autoSave: true,
|
|
2335
|
+
onSave: handleUpdate
|
|
2336
|
+
}, /* @__PURE__ */ React19.createElement(Form.FieldSet, null), /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2337
|
+
label: t("fields label"),
|
|
2338
|
+
asChild: true
|
|
2339
|
+
}), /* @__PURE__ */ React19.createElement(FieldList, {
|
|
2340
|
+
schema,
|
|
2341
|
+
view,
|
|
2342
|
+
registry,
|
|
2343
|
+
readonly,
|
|
2344
|
+
showHeading,
|
|
2345
|
+
onDelete: handleDelete
|
|
2346
|
+
})), !readonly && !expandedField && /* @__PURE__ */ React19.createElement("div", {
|
|
2347
|
+
role: "none",
|
|
2348
|
+
className: "mlb-cardSpacingBlock"
|
|
2349
|
+
}, /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2350
|
+
icon: "ph--plus--regular",
|
|
2351
|
+
label: t("add property button label"),
|
|
2352
|
+
onClick: readonly ? void 0 : handleAdd,
|
|
2353
|
+
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
2354
|
+
disabled: view.projection.fields.length >= VIEW_FIELD_LIMIT,
|
|
2355
|
+
classNames: "is-full"
|
|
2356
|
+
})));
|
|
2357
|
+
});
|
|
2358
|
+
var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
2359
|
+
const atomRegistry = useContext(RegistryContext);
|
|
2360
|
+
const schemaReadonly = !isMutable(schema);
|
|
2361
|
+
const { t } = useTranslation10(translationKey);
|
|
2362
|
+
const [viewSnapshot] = useObject(view);
|
|
2363
|
+
const projectionModel = useMemo8(() => {
|
|
2364
|
+
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2365
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2366
|
+
const model = new ProjectionModel({
|
|
2367
|
+
registry: atomRegistry,
|
|
2368
|
+
view,
|
|
2369
|
+
baseSchema: jsonSchema,
|
|
2370
|
+
change
|
|
2371
|
+
});
|
|
2372
|
+
return model;
|
|
2373
|
+
}, [
|
|
2374
|
+
atomRegistry,
|
|
2375
|
+
schema,
|
|
2376
|
+
view
|
|
2377
|
+
]);
|
|
2378
|
+
const [expandedField, setExpandedField] = useState6();
|
|
2379
|
+
const handleToggleField = useCallback15((field) => {
|
|
2380
|
+
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2381
|
+
}, [
|
|
2382
|
+
readonly
|
|
2383
|
+
]);
|
|
2384
|
+
const handleDelete = useCallback15((fieldId) => {
|
|
2385
|
+
invariant(!readonly, void 0, {
|
|
2386
|
+
F: __dxlog_file3,
|
|
2387
|
+
L: 253,
|
|
2388
|
+
S: void 0,
|
|
2389
|
+
A: [
|
|
2390
|
+
"!readonly",
|
|
2391
|
+
""
|
|
2392
|
+
]
|
|
2393
|
+
});
|
|
2394
|
+
if (fieldId === expandedField) {
|
|
2395
|
+
setExpandedField(void 0);
|
|
2396
|
+
}
|
|
2397
|
+
onDelete?.(fieldId);
|
|
2398
|
+
}, [
|
|
2399
|
+
expandedField,
|
|
2400
|
+
onDelete,
|
|
2401
|
+
readonly
|
|
2402
|
+
]);
|
|
2403
|
+
const handleMove = useCallback15((fromIndex, toIndex) => {
|
|
2404
|
+
invariant(!readonly, void 0, {
|
|
2405
|
+
F: __dxlog_file3,
|
|
2406
|
+
L: 265,
|
|
2407
|
+
S: void 0,
|
|
2408
|
+
A: [
|
|
2409
|
+
"!readonly",
|
|
2410
|
+
""
|
|
2411
|
+
]
|
|
2412
|
+
});
|
|
2413
|
+
Obj4.change(view, (v) => {
|
|
2456
2414
|
const fields = [
|
|
2457
|
-
...
|
|
2415
|
+
...v.projection.fields
|
|
2458
2416
|
];
|
|
2459
2417
|
const [moved] = fields.splice(fromIndex, 1);
|
|
2460
2418
|
fields.splice(toIndex, 0, moved);
|
|
2461
|
-
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
Custom: custom
|
|
2503
|
-
}), /* @__PURE__ */ React15.createElement("div", {
|
|
2419
|
+
v.projection.fields = fields;
|
|
2420
|
+
});
|
|
2421
|
+
}, [
|
|
2422
|
+
view,
|
|
2423
|
+
readonly
|
|
2424
|
+
]);
|
|
2425
|
+
const handleClose = useCallback15(() => setExpandedField(void 0), []);
|
|
2426
|
+
const handleHide = useCallback15((fieldId) => {
|
|
2427
|
+
setExpandedField(void 0);
|
|
2428
|
+
projectionModel.hideFieldProjection(fieldId);
|
|
2429
|
+
}, [
|
|
2430
|
+
projectionModel
|
|
2431
|
+
]);
|
|
2432
|
+
const handleShow = useCallback15((property) => {
|
|
2433
|
+
setExpandedField(void 0);
|
|
2434
|
+
projectionModel.showFieldProjection(property);
|
|
2435
|
+
}, [
|
|
2436
|
+
projectionModel
|
|
2437
|
+
]);
|
|
2438
|
+
if (!viewSnapshot) {
|
|
2439
|
+
return null;
|
|
2440
|
+
}
|
|
2441
|
+
return /* @__PURE__ */ React19.createElement(List2.Root, {
|
|
2442
|
+
items: viewSnapshot.projection.fields,
|
|
2443
|
+
isItem: Schema3.is(FieldSchema),
|
|
2444
|
+
getId: (field) => field.id,
|
|
2445
|
+
onMove: readonly ? void 0 : handleMove,
|
|
2446
|
+
readonly
|
|
2447
|
+
}, ({ items: fields }) => /* @__PURE__ */ React19.createElement(React19.Fragment, null, showHeading && /* @__PURE__ */ React19.createElement("h3", {
|
|
2448
|
+
className: "text-sm"
|
|
2449
|
+
}, t("field path label")), /* @__PURE__ */ React19.createElement("div", {
|
|
2450
|
+
role: "list",
|
|
2451
|
+
className: listGrid
|
|
2452
|
+
}, fields?.map((field) => {
|
|
2453
|
+
const hidden = field.visible === false;
|
|
2454
|
+
return /* @__PURE__ */ React19.createElement(List2.Item, {
|
|
2455
|
+
key: field.id,
|
|
2456
|
+
item: field,
|
|
2457
|
+
classNames: listItemGrid,
|
|
2458
|
+
"aria-expanded": expandedField === field.id
|
|
2459
|
+
}, /* @__PURE__ */ React19.createElement("div", {
|
|
2504
2460
|
role: "none",
|
|
2505
|
-
className:
|
|
2506
|
-
}, /* @__PURE__ */
|
|
2507
|
-
|
|
2508
|
-
}
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
},
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
}, field.path), /* @__PURE__ */ React15.createElement(List2.ItemButton, {
|
|
2535
|
-
label: t(hidden ? "show field label" : "hide field label"),
|
|
2536
|
-
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2537
|
-
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2538
|
-
autoHide: false,
|
|
2539
|
-
disabled: readonly || !hidden && projectionModel.fields.length <= 1,
|
|
2540
|
-
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2541
|
-
}), !readonly && /* @__PURE__ */ React15.createElement(React15.Fragment, null, /* @__PURE__ */ React15.createElement(List2.ItemDeleteButton, {
|
|
2542
|
-
label: t("delete field label"),
|
|
2543
|
-
autoHide: false,
|
|
2544
|
-
disabled: readonly || schemaReadonly || view.projection.fields.length <= 1,
|
|
2545
|
-
onClick: () => handleDelete(field.id),
|
|
2546
|
-
"data-testid": "field.delete"
|
|
2547
|
-
}), /* @__PURE__ */ React15.createElement(IconButton4, {
|
|
2548
|
-
iconOnly: true,
|
|
2549
|
-
variant: "ghost",
|
|
2550
|
-
label: t("toggle expand label", {
|
|
2551
|
-
ns: "os"
|
|
2552
|
-
}),
|
|
2553
|
-
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2554
|
-
onClick: () => handleToggleField(field)
|
|
2555
|
-
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React15.createElement("div", {
|
|
2556
|
-
role: "none",
|
|
2557
|
-
className: "col-span-5 mbs-1 mbe-1 border border-separator rounded-md"
|
|
2558
|
-
}, /* @__PURE__ */ React15.createElement(FieldEditor, {
|
|
2559
|
-
readonly: readonly || schemaReadonly ? "disabled-input" : false,
|
|
2560
|
-
projection: projectionModel,
|
|
2561
|
-
field,
|
|
2562
|
-
registry,
|
|
2563
|
-
onSave: handleClose
|
|
2564
|
-
})));
|
|
2565
|
-
}))))), !readonly && !expandedField && /* @__PURE__ */ React15.createElement("div", {
|
|
2461
|
+
className: mx7(subtleHover2, listItemGrid, "rounded-sm cursor-pointer min-bs-10")
|
|
2462
|
+
}, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
|
|
2463
|
+
disabled: readonly || schemaReadonly
|
|
2464
|
+
}), /* @__PURE__ */ React19.createElement(List2.ItemTitle, {
|
|
2465
|
+
classNames: hidden && "text-subdued",
|
|
2466
|
+
onClick: () => handleToggleField(field)
|
|
2467
|
+
}, field.path), /* @__PURE__ */ React19.createElement(List2.ItemButton, {
|
|
2468
|
+
label: t(hidden ? "show field label" : "hide field label"),
|
|
2469
|
+
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2470
|
+
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2471
|
+
autoHide: false,
|
|
2472
|
+
disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
|
|
2473
|
+
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2474
|
+
}), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
|
|
2475
|
+
label: t("delete field label"),
|
|
2476
|
+
autoHide: false,
|
|
2477
|
+
disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
|
|
2478
|
+
onClick: () => handleDelete(field.id),
|
|
2479
|
+
"data-testid": "field.delete"
|
|
2480
|
+
}), /* @__PURE__ */ React19.createElement(IconButton4, {
|
|
2481
|
+
iconOnly: true,
|
|
2482
|
+
variant: "ghost",
|
|
2483
|
+
label: t("toggle expand label", {
|
|
2484
|
+
ns: osTranslations2
|
|
2485
|
+
}),
|
|
2486
|
+
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2487
|
+
onClick: () => handleToggleField(field),
|
|
2488
|
+
"data-testid": "field.toggle"
|
|
2489
|
+
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React19.createElement("div", {
|
|
2566
2490
|
role: "none",
|
|
2567
|
-
className:
|
|
2568
|
-
}, /* @__PURE__ */
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
classNames: "is-full"
|
|
2491
|
+
className: "col-span-5 mbs-1 mbe-1 border border-separator rounded-md"
|
|
2492
|
+
}, /* @__PURE__ */ React19.createElement(FieldEditor, {
|
|
2493
|
+
readonly: readonly || schemaReadonly,
|
|
2494
|
+
registry,
|
|
2495
|
+
projection: projectionModel,
|
|
2496
|
+
field,
|
|
2497
|
+
onSave: handleClose
|
|
2575
2498
|
})));
|
|
2576
|
-
}
|
|
2577
|
-
|
|
2578
|
-
}
|
|
2579
|
-
});
|
|
2499
|
+
}))));
|
|
2500
|
+
};
|
|
2580
2501
|
var customFields = ({ types, tags }) => ({
|
|
2581
|
-
query: (
|
|
2582
|
-
const handleChange =
|
|
2583
|
-
|
|
2502
|
+
query: ({ type, readonly, label, getValue, onValueChange }) => {
|
|
2503
|
+
const handleChange = useCallback15((query) => onValueChange(type, query.ast), [
|
|
2504
|
+
onValueChange
|
|
2584
2505
|
]);
|
|
2585
|
-
return /* @__PURE__ */
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2506
|
+
return /* @__PURE__ */ React19.createElement(Input13.Root, null, /* @__PURE__ */ React19.createElement(FormFieldLabel, {
|
|
2507
|
+
readonly,
|
|
2508
|
+
label
|
|
2509
|
+
}), /* @__PURE__ */ React19.createElement(QueryForm, {
|
|
2510
|
+
initialQuery: getValue(),
|
|
2589
2511
|
types,
|
|
2590
2512
|
tags,
|
|
2591
2513
|
onChange: handleChange
|
|
@@ -2593,7 +2515,8 @@ var customFields = ({ types, tags }) => ({
|
|
|
2593
2515
|
}
|
|
2594
2516
|
});
|
|
2595
2517
|
export {
|
|
2596
|
-
|
|
2518
|
+
ArrayField,
|
|
2519
|
+
BooleanField,
|
|
2597
2520
|
ControlFrame,
|
|
2598
2521
|
ControlFrameItem,
|
|
2599
2522
|
ControlGroup,
|
|
@@ -2605,31 +2528,36 @@ export {
|
|
|
2605
2528
|
ControlSectionHeading,
|
|
2606
2529
|
FieldEditor,
|
|
2607
2530
|
Form,
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2531
|
+
FormFieldErrorBoundary,
|
|
2532
|
+
FormFieldLabel,
|
|
2533
|
+
FormFieldWrapper,
|
|
2534
|
+
GeoPointField,
|
|
2535
|
+
MarkdownField,
|
|
2536
|
+
NumberField,
|
|
2613
2537
|
ObjectPicker,
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2538
|
+
RefField,
|
|
2539
|
+
SelectField,
|
|
2540
|
+
SelectOptionField,
|
|
2541
|
+
TextAreaField,
|
|
2542
|
+
TextField,
|
|
2543
|
+
TupleField,
|
|
2618
2544
|
ViewEditor,
|
|
2619
2545
|
cellClassesForFieldType,
|
|
2620
2546
|
controlItemClasses,
|
|
2621
|
-
findArrayElementType,
|
|
2622
2547
|
formatForDisplay,
|
|
2623
2548
|
formatForEditing,
|
|
2549
|
+
getDefaultValue,
|
|
2550
|
+
getFormProperties,
|
|
2624
2551
|
getRefProps,
|
|
2552
|
+
omitId,
|
|
2625
2553
|
parseValue,
|
|
2626
2554
|
pathNotUniqueError,
|
|
2555
|
+
setValueEchoAware,
|
|
2627
2556
|
translations,
|
|
2628
|
-
useForm,
|
|
2629
2557
|
useFormContext,
|
|
2558
|
+
useFormFieldState,
|
|
2559
|
+
useFormHandler,
|
|
2630
2560
|
useFormValues,
|
|
2631
|
-
|
|
2632
|
-
useQueryRefOptions,
|
|
2633
|
-
useRefQueryLookupHandler
|
|
2561
|
+
useKeyHandler
|
|
2634
2562
|
};
|
|
2635
2563
|
//# sourceMappingURL=index.mjs.map
|