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