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