@dxos/react-ui-form 0.8.4-main.d05673bc65 → 0.8.4-main.dfabb4ec29
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 +1004 -612
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +82 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1004 -612
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +84 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +63 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +40 -12
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +76 -74
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +11 -5
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +8 -7
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +5 -9
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +4 -4
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +8 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +84 -0
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +12 -6
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +63 -61
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +9 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
- package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +26 -4
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +63 -61
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +127 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +28 -33
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts +64 -61
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +2 -2
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +65 -63
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -4
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +63 -61
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field-type.d.ts +19 -0
- package/dist/types/src/util/field-type.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +1 -0
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -40
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
- package/src/components/FieldEditor/FieldEditor.tsx +4 -3
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +23 -36
- package/src/components/Form/Form.tsx +77 -48
- package/src/components/Form/FormField.tsx +27 -15
- package/src/components/Form/FormFieldComponent.tsx +5 -3
- package/src/components/Form/FormFieldSet.tsx +98 -77
- package/src/components/Form/fields/ArrayField.tsx +14 -8
- package/src/components/Form/fields/GeoPointField.tsx +8 -7
- package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
- package/src/components/Form/fields/MarkdownField.tsx +135 -45
- package/src/components/Form/fields/RefField.tsx +70 -35
- package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
- package/src/components/Form/fields/SelectOptionField.tsx +10 -10
- package/src/components/Form/fields/TextField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectForm/ObjectForm.tsx +114 -0
- package/src/components/ObjectForm/index.ts +5 -0
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +9 -7
- package/src/components/ObjectPicker/ObjectPicker.tsx +92 -65
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +362 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +101 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +141 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/Settings/AUDIT.md +52 -0
- package/src/components/Settings/Settings.stories.tsx +69 -21
- package/src/components/Settings/Settings.tsx +33 -183
- package/src/components/Settings/SettingsFieldSet.tsx +257 -0
- package/src/components/Settings/SettingsItem.tsx +58 -0
- package/src/components/Settings/SettingsSelectField.tsx +59 -0
- package/src/components/Settings/index.ts +2 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +10 -10
- package/src/components/ViewEditor/ViewEditor.test.tsx +0 -1
- package/src/components/ViewEditor/ViewEditor.tsx +15 -15
- package/src/components/index.ts +2 -0
- package/src/components/testing.tsx +19 -11
- package/src/hooks/useKeyHandler.tsx +7 -7
- package/src/index.ts +0 -4
- package/src/translations.ts +66 -63
- package/src/util/field-type.ts +60 -0
- package/src/util/index.ts +1 -0
- package/src/util/refs.ts +7 -3
|
@@ -1,89 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
-
// src/translations.ts
|
|
4
|
-
var translationKey = "@dxos/react-ui-form";
|
|
5
|
-
var translations = [
|
|
6
|
-
{
|
|
7
|
-
"en-US": {
|
|
8
|
-
[translationKey]: {
|
|
9
|
-
"fields label": "Fields",
|
|
10
|
-
"hidden fields label": "Hidden Fields",
|
|
11
|
-
"empty readonly ref field label": "(none)",
|
|
12
|
-
// TODO(burdon): Standardize field/property.
|
|
13
|
-
"add property button label": "Add property",
|
|
14
|
-
"field property label": "Property",
|
|
15
|
-
"field property placeholder": "Property name",
|
|
16
|
-
"field format label": "Type",
|
|
17
|
-
"field path label": "Field path",
|
|
18
|
-
"add field": "Add field",
|
|
19
|
-
"delete field": "Delete field",
|
|
20
|
-
"field limit reached": "Maximum number of fields reached",
|
|
21
|
-
"boolean input true value": "Yes",
|
|
22
|
-
"boolean input false value": "No",
|
|
23
|
-
"show field label": "Show field",
|
|
24
|
-
"hide field label": "Hide field",
|
|
25
|
-
"delete field label": "Delete field",
|
|
26
|
-
"ref field combobox input placeholder": "Search\u2026",
|
|
27
|
-
"ref field placeholder_one": "Select\u2026",
|
|
28
|
-
"ref field placeholder_other": "Select items\u2026",
|
|
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",
|
|
34
|
-
// FormatEnum
|
|
35
|
-
"format boolean": "Boolean",
|
|
36
|
-
"format currency": "Currency",
|
|
37
|
-
"format date": "Date",
|
|
38
|
-
"format date-time": "DateTime",
|
|
39
|
-
"format did": "DID",
|
|
40
|
-
"format duration": "Duration",
|
|
41
|
-
"format dxn": "DXN",
|
|
42
|
-
"format email": "Email",
|
|
43
|
-
"format formula": "Formula",
|
|
44
|
-
"format hostname": "Hostname",
|
|
45
|
-
"format integer": "Integer",
|
|
46
|
-
"format json": "JSON",
|
|
47
|
-
"format lnglat": "Geopoint",
|
|
48
|
-
"format markdown": "Markdown",
|
|
49
|
-
"format percent": "Percent",
|
|
50
|
-
"format ref": "Reference",
|
|
51
|
-
"format regex": "RegExp",
|
|
52
|
-
"format string": "String",
|
|
53
|
-
"format single-select": "Select",
|
|
54
|
-
"format multi-select": "Multi-select",
|
|
55
|
-
"format text": "Long text",
|
|
56
|
-
"format time": "Time",
|
|
57
|
-
"format timestamp": "Timestamp",
|
|
58
|
-
"format user": "User",
|
|
59
|
-
"format number": "Number",
|
|
60
|
-
"format uri": "URI",
|
|
61
|
-
"format url": "URL",
|
|
62
|
-
"format uuid": "UUID",
|
|
63
|
-
// GeoPointField.
|
|
64
|
-
"latitude label": "Latitude",
|
|
65
|
-
"longitude label": "Longitude",
|
|
66
|
-
// SelectOptionsField.
|
|
67
|
-
"select option label": "Label",
|
|
68
|
-
"select option label placeholder": "Option label",
|
|
69
|
-
"select option color": "Color",
|
|
70
|
-
"select option delete": "Delete",
|
|
71
|
-
"select option add": "Add option",
|
|
72
|
-
// System schema message.
|
|
73
|
-
"system schema title": "System type",
|
|
74
|
-
"system schema description": "System type: cannot add or remove fields."
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
];
|
|
79
|
-
|
|
80
3
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
81
|
-
import React17, { useCallback as useCallback14, useEffect as
|
|
82
|
-
import { Obj as
|
|
4
|
+
import React17, { useCallback as useCallback14, useEffect as useEffect5, useMemo as useMemo8, useState as useState6 } from "react";
|
|
5
|
+
import { Obj as Obj3 } from "@dxos/echo";
|
|
83
6
|
import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
|
|
84
7
|
import { log as log2 } from "@dxos/log";
|
|
85
|
-
import { useAsyncEffect, useTranslation as
|
|
8
|
+
import { useAsyncEffect, useTranslation as useTranslation9 } from "@dxos/react-ui";
|
|
86
9
|
import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
|
|
10
|
+
import { translationKey as translationKey9 } from "#translations";
|
|
87
11
|
|
|
88
12
|
// src/util/field.ts
|
|
89
13
|
import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
|
|
@@ -206,6 +130,46 @@ var pathNotUniqueError = (path) => ({
|
|
|
206
130
|
message: `'${path}' is already present`
|
|
207
131
|
});
|
|
208
132
|
|
|
133
|
+
// src/util/field-type.ts
|
|
134
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
135
|
+
import { getAnnotation, isLiteralUnion } from "@dxos/effect";
|
|
136
|
+
var detectFieldType = (ast) => {
|
|
137
|
+
if (isLiteralUnion(ast)) {
|
|
138
|
+
return "select";
|
|
139
|
+
}
|
|
140
|
+
if (SchemaAST.isTypeLiteral(ast)) {
|
|
141
|
+
return "struct";
|
|
142
|
+
}
|
|
143
|
+
switch (ast._tag) {
|
|
144
|
+
case "BooleanKeyword":
|
|
145
|
+
return "boolean";
|
|
146
|
+
case "StringKeyword":
|
|
147
|
+
return "string";
|
|
148
|
+
case "NumberKeyword":
|
|
149
|
+
return "number";
|
|
150
|
+
}
|
|
151
|
+
return void 0;
|
|
152
|
+
};
|
|
153
|
+
var getSelectOptionsFromAst = (ast) => {
|
|
154
|
+
if (!isLiteralUnion(ast)) {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
return ast.types.flatMap((literalNode) => {
|
|
158
|
+
const value3 = literalNode.literal;
|
|
159
|
+
if (typeof value3 !== "string" && typeof value3 !== "number") {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const title = getAnnotation(SchemaAST.TitleAnnotationId, false)(literalNode);
|
|
163
|
+
const label = title ?? (typeof value3 === "string" ? value3.charAt(0).toUpperCase() + value3.slice(1) : String(value3));
|
|
164
|
+
return [
|
|
165
|
+
{
|
|
166
|
+
value: value3,
|
|
167
|
+
label
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
|
|
209
173
|
// src/util/formatting.ts
|
|
210
174
|
import { format as formatDate } from "date-fns/format";
|
|
211
175
|
import { Format as Format2, GeoLocation as GeoLocation2, TypeEnum as TypeEnum2 } from "@dxos/echo/internal";
|
|
@@ -354,43 +318,52 @@ var getFormProperties = (ast) => {
|
|
|
354
318
|
|
|
355
319
|
// src/util/refs.ts
|
|
356
320
|
import { Ref } from "@dxos/echo";
|
|
357
|
-
import {
|
|
321
|
+
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
322
|
+
import { findAnnotation, getArrayElementType, isArrayType } from "@dxos/effect";
|
|
358
323
|
var getRefProps = (ast) => {
|
|
359
324
|
if (isArrayType(ast)) {
|
|
360
325
|
const elementType = getArrayElementType(ast);
|
|
361
326
|
if (elementType) {
|
|
362
327
|
if (Ref.isRefType(elementType)) {
|
|
328
|
+
const typename = findAnnotation(elementType, ReferenceAnnotationId)?.typename;
|
|
363
329
|
return {
|
|
364
330
|
ast: elementType,
|
|
365
|
-
isArray: true
|
|
331
|
+
isArray: true,
|
|
332
|
+
typename
|
|
366
333
|
};
|
|
367
334
|
}
|
|
368
335
|
}
|
|
369
336
|
}
|
|
370
337
|
if (Ref.isRefType(ast)) {
|
|
338
|
+
const typename = findAnnotation(ast, ReferenceAnnotationId)?.typename;
|
|
371
339
|
return {
|
|
372
340
|
ast,
|
|
373
|
-
isArray: false
|
|
341
|
+
isArray: false,
|
|
342
|
+
typename
|
|
374
343
|
};
|
|
375
344
|
}
|
|
376
345
|
return void 0;
|
|
377
346
|
};
|
|
378
347
|
|
|
379
348
|
// src/components/Form/fields/ArrayField.tsx
|
|
380
|
-
import * as
|
|
381
|
-
import * as
|
|
349
|
+
import * as Option4 from "effect/Option";
|
|
350
|
+
import * as SchemaAST4 from "effect/SchemaAST";
|
|
382
351
|
import React5, { useCallback as useCallback3 } from "react";
|
|
383
352
|
import { findNode as findNode2, getArrayElementType as getArrayElementType2, getDiscriminatedType as getDiscriminatedType2, isDiscriminatedUnion as isDiscriminatedUnion2, isNestedType as isNestedType2 } from "@dxos/effect";
|
|
384
353
|
import { IconButton as IconButton2, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
354
|
+
import { translationKey as translationKey3 } from "#translations";
|
|
385
355
|
|
|
386
356
|
// src/components/Form/Form.tsx
|
|
387
357
|
import { createContext } from "@radix-ui/react-context";
|
|
358
|
+
import * as Option3 from "effect/Option";
|
|
388
359
|
import * as Schema2 from "effect/Schema";
|
|
389
|
-
import * as
|
|
390
|
-
import React4, { useEffect as
|
|
360
|
+
import * as SchemaAST3 from "effect/SchemaAST";
|
|
361
|
+
import React4, { useEffect as useEffect2, useMemo as useMemo4, useRef } from "react";
|
|
362
|
+
import { Annotation as EchoAnnotation } from "@dxos/echo";
|
|
391
363
|
import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
|
|
392
|
-
import { IconButton, ScrollArea, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
393
|
-
import { mx
|
|
364
|
+
import { IconButton, ScrollArea, useMergeRefs, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
365
|
+
import { composable, composableProps, mx, withColumn } from "@dxos/ui-theme";
|
|
366
|
+
import { translationKey as translationKey2 } from "#translations";
|
|
394
367
|
|
|
395
368
|
// src/hooks/useFormHandler.ts
|
|
396
369
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
@@ -428,12 +401,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
428
401
|
log("validate", {
|
|
429
402
|
values: values2,
|
|
430
403
|
errors: errors2
|
|
431
|
-
}, {
|
|
432
|
-
F: __dxlog_file,
|
|
433
|
-
L: 155,
|
|
434
|
-
S: void 0,
|
|
435
|
-
C: (f, a) => f(...a)
|
|
436
|
-
});
|
|
404
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 42, S: void 0 });
|
|
437
405
|
if (errors2.length === 0 && onValidate) {
|
|
438
406
|
const validatedValues = values2;
|
|
439
407
|
errors2 = onValidate(validatedValues) ?? [];
|
|
@@ -521,12 +489,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
521
489
|
log("onValueChange", {
|
|
522
490
|
path,
|
|
523
491
|
value: value3
|
|
524
|
-
}, {
|
|
525
|
-
F: __dxlog_file,
|
|
526
|
-
L: 254,
|
|
527
|
-
S: void 0,
|
|
528
|
-
C: (f, a) => f(...a)
|
|
529
|
-
});
|
|
492
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 138, S: void 0 });
|
|
530
493
|
const jsonPath = createJsonPath(path);
|
|
531
494
|
const pathArray = path;
|
|
532
495
|
let parsedValue = value3;
|
|
@@ -535,12 +498,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
|
|
|
535
498
|
parsedValue = parseFloat(value3) || 0;
|
|
536
499
|
}
|
|
537
500
|
} catch (err) {
|
|
538
|
-
log.catch(err, void 0, {
|
|
539
|
-
F: __dxlog_file,
|
|
540
|
-
L: 264,
|
|
541
|
-
S: void 0,
|
|
542
|
-
C: (f, a) => f(...a)
|
|
543
|
-
});
|
|
501
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 150, S: void 0 });
|
|
544
502
|
parsedValue = void 0;
|
|
545
503
|
}
|
|
546
504
|
const newValues = mergeAtPath(values, pathArray, parsedValue);
|
|
@@ -649,9 +607,9 @@ var flatMap = (errors) => {
|
|
|
649
607
|
};
|
|
650
608
|
|
|
651
609
|
// src/hooks/useKeyHandler.tsx
|
|
652
|
-
import { useCallback as useCallback2,
|
|
610
|
+
import { useCallback as useCallback2, useLayoutEffect } from "react";
|
|
653
611
|
import { addEventListener } from "@dxos/async";
|
|
654
|
-
var useKeyHandler = (
|
|
612
|
+
var useKeyHandler = (elRef, form) => {
|
|
655
613
|
const handleKeyDown = useCallback2((event) => {
|
|
656
614
|
switch (event.key) {
|
|
657
615
|
case "Enter": {
|
|
@@ -667,13 +625,14 @@ var useKeyHandler = (formElement, form) => {
|
|
|
667
625
|
form.onSave,
|
|
668
626
|
form.autoSave
|
|
669
627
|
]);
|
|
670
|
-
|
|
671
|
-
|
|
628
|
+
useLayoutEffect(() => {
|
|
629
|
+
const el = elRef.current;
|
|
630
|
+
if (!el) {
|
|
672
631
|
return;
|
|
673
632
|
}
|
|
674
|
-
return addEventListener(
|
|
633
|
+
return addEventListener(el, "keydown", handleKeyDown);
|
|
675
634
|
}, [
|
|
676
|
-
|
|
635
|
+
elRef,
|
|
677
636
|
handleKeyDown
|
|
678
637
|
]);
|
|
679
638
|
};
|
|
@@ -685,7 +644,6 @@ import { inputTextLabel } from "@dxos/ui-theme";
|
|
|
685
644
|
var FormFieldLabel = ({ label, error, readonly, asChild }) => {
|
|
686
645
|
const Label = readonly || asChild ? "span" : Input.Label;
|
|
687
646
|
return /* @__PURE__ */ React.createElement("div", {
|
|
688
|
-
role: "none",
|
|
689
647
|
className: "flex items-center justify-between"
|
|
690
648
|
}, /* @__PURE__ */ React.createElement(Label, {
|
|
691
649
|
className: inputTextLabel
|
|
@@ -709,7 +667,6 @@ var FormFieldWrapper = (props) => {
|
|
|
709
667
|
}
|
|
710
668
|
const str = String(value3 ?? "");
|
|
711
669
|
return /* @__PURE__ */ React.createElement("div", {
|
|
712
|
-
role: "none",
|
|
713
670
|
className: "contents"
|
|
714
671
|
}, /* @__PURE__ */ React.createElement(Input.Root, {
|
|
715
672
|
validationValence: status
|
|
@@ -753,20 +710,19 @@ var FormFieldErrorBoundary = class extends Component {
|
|
|
753
710
|
};
|
|
754
711
|
|
|
755
712
|
// src/components/Form/FormFieldSet.tsx
|
|
756
|
-
import React3, {
|
|
757
|
-
import { mx } from "@dxos/ui-theme";
|
|
758
|
-
import { isTruthy } from "@dxos/util";
|
|
713
|
+
import React3, { useMemo as useMemo3 } from "react";
|
|
759
714
|
|
|
760
715
|
// src/components/Form/FormField.tsx
|
|
761
716
|
import * as Match from "effect/Match";
|
|
762
717
|
import * as Option2 from "effect/Option";
|
|
763
718
|
import * as Schema from "effect/Schema";
|
|
764
|
-
import * as
|
|
719
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
765
720
|
import * as String2 from "effect/String";
|
|
766
721
|
import React2, { useMemo as useMemo2 } from "react";
|
|
767
722
|
import { Format as Format3 } from "@dxos/echo";
|
|
768
|
-
import { createJsonPath as createJsonPath2, findNode, getAnnotation, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion, isNestedType } from "@dxos/effect";
|
|
723
|
+
import { createJsonPath as createJsonPath2, findNode, getAnnotation as getAnnotation2, getDiscriminatedType, isArrayType as isArrayType2, isDiscriminatedUnion, isLiteralUnion as isLiteralUnion2, isNestedType } from "@dxos/effect";
|
|
769
724
|
import { useTranslation } from "@dxos/react-ui";
|
|
725
|
+
import { translationKey } from "#translations";
|
|
770
726
|
var FormField = (props) => {
|
|
771
727
|
const {
|
|
772
728
|
type,
|
|
@@ -778,23 +734,25 @@ var FormField = (props) => {
|
|
|
778
734
|
readonly,
|
|
779
735
|
layout,
|
|
780
736
|
// RefFieldProps
|
|
737
|
+
createTypename,
|
|
781
738
|
createOptionLabel,
|
|
782
739
|
createOptionIcon,
|
|
783
740
|
createInitialValuePath,
|
|
741
|
+
createFieldMap: createFieldMap3,
|
|
784
742
|
db,
|
|
785
|
-
schemaHook,
|
|
786
|
-
getOptions
|
|
743
|
+
useSchema: schemaHook,
|
|
744
|
+
getOptions,
|
|
787
745
|
onCreate
|
|
788
746
|
} = props;
|
|
789
747
|
const { t } = useTranslation(translationKey);
|
|
790
|
-
const title =
|
|
791
|
-
const description =
|
|
792
|
-
const examples =
|
|
748
|
+
const title = getAnnotation2(SchemaAST2.TitleAnnotationId)(type);
|
|
749
|
+
const description = getAnnotation2(SchemaAST2.DescriptionAnnotationId)(type);
|
|
750
|
+
const examples = getAnnotation2(SchemaAST2.ExamplesAnnotationId)(type);
|
|
793
751
|
const label = useMemo2(() => title ?? String2.capitalize(name), [
|
|
794
752
|
title,
|
|
795
753
|
name
|
|
796
754
|
]);
|
|
797
|
-
const placeholder = useMemo2(() => examples?.length ? `${t("example
|
|
755
|
+
const placeholder = useMemo2(() => examples?.length ? `${t("example.placeholder")}: ${examples[0]}` : description ?? label, [
|
|
798
756
|
examples,
|
|
799
757
|
description,
|
|
800
758
|
label
|
|
@@ -807,6 +765,7 @@ var FormField = (props) => {
|
|
|
807
765
|
label,
|
|
808
766
|
placeholder,
|
|
809
767
|
layout,
|
|
768
|
+
db,
|
|
810
769
|
...fieldState
|
|
811
770
|
};
|
|
812
771
|
const jsonPath = createJsonPath2(path ?? []);
|
|
@@ -833,7 +792,7 @@ var FormField = (props) => {
|
|
|
833
792
|
if (Field) {
|
|
834
793
|
return /* @__PURE__ */ React2.createElement(Field, fieldProps);
|
|
835
794
|
}
|
|
836
|
-
const options =
|
|
795
|
+
const options = getSelectOptions(type);
|
|
837
796
|
if (options) {
|
|
838
797
|
const fieldProjections = projection?.getFieldProjections();
|
|
839
798
|
const fieldProjection = fieldProjections?.find((fp) => fp.field.path === name);
|
|
@@ -851,21 +810,23 @@ var FormField = (props) => {
|
|
|
851
810
|
}
|
|
852
811
|
const refProps = getRefProps(type);
|
|
853
812
|
if (refProps) {
|
|
813
|
+
const isCreateTarget = !createTypename || refProps.typename === createTypename;
|
|
854
814
|
return /* @__PURE__ */ React2.createElement(RefField, {
|
|
855
815
|
...fieldProps,
|
|
856
816
|
...refProps,
|
|
857
|
-
createOptionLabel,
|
|
858
|
-
createOptionIcon,
|
|
859
|
-
createInitialValuePath,
|
|
817
|
+
createOptionLabel: isCreateTarget ? createOptionLabel : void 0,
|
|
818
|
+
createOptionIcon: isCreateTarget ? createOptionIcon : void 0,
|
|
819
|
+
createInitialValuePath: isCreateTarget ? createInitialValuePath : void 0,
|
|
820
|
+
createFieldMap: isCreateTarget ? createFieldMap3 : void 0,
|
|
860
821
|
db,
|
|
861
|
-
schemaHook,
|
|
862
|
-
getOptions
|
|
822
|
+
useSchema: schemaHook,
|
|
823
|
+
getOptions,
|
|
863
824
|
onCreate
|
|
864
825
|
});
|
|
865
826
|
}
|
|
866
827
|
if (isNestedType(type)) {
|
|
867
828
|
const baseNode = findNode(type, isDiscriminatedUnion);
|
|
868
|
-
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type,
|
|
829
|
+
const typeLiteral = baseNode ? getDiscriminatedType(baseNode, fieldState.getValue()) : findNode(type, SchemaAST2.isTypeLiteral);
|
|
869
830
|
if (typeLiteral) {
|
|
870
831
|
const schema = Schema.make(typeLiteral);
|
|
871
832
|
return /* @__PURE__ */ React2.createElement(FormFieldSet, {
|
|
@@ -881,8 +842,8 @@ var FormField = (props) => {
|
|
|
881
842
|
createOptionIcon,
|
|
882
843
|
createInitialValuePath,
|
|
883
844
|
db,
|
|
884
|
-
schemaHook,
|
|
885
|
-
getOptions
|
|
845
|
+
useSchema: schemaHook,
|
|
846
|
+
getOptions,
|
|
886
847
|
onCreate
|
|
887
848
|
});
|
|
888
849
|
}
|
|
@@ -906,8 +867,8 @@ var getFormField = ({ type, format }) => {
|
|
|
906
867
|
return BooleanField;
|
|
907
868
|
}
|
|
908
869
|
};
|
|
909
|
-
var
|
|
910
|
-
if (
|
|
870
|
+
var getSelectOptions = (ast) => {
|
|
871
|
+
if (isLiteralUnion2(ast)) {
|
|
911
872
|
return ast.types.map((type) => type.literal).filter((v) => v !== null);
|
|
912
873
|
}
|
|
913
874
|
return Format3.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option2.getOrUndefined(annotation));
|
|
@@ -915,47 +876,19 @@ var getOptions = (ast) => {
|
|
|
915
876
|
|
|
916
877
|
// src/components/Form/FormFieldSet.tsx
|
|
917
878
|
var FORM_FIELDSET_NAME = "Form.FieldSet";
|
|
918
|
-
var FormFieldSet =
|
|
879
|
+
var FormFieldSet = ({ label, schema, readonly, path, sort, exclude, projection, layout, ...props }) => {
|
|
919
880
|
const values = useFormValues(FORM_FIELDSET_NAME, path);
|
|
920
|
-
const properties =
|
|
921
|
-
if (!schema) {
|
|
922
|
-
return [];
|
|
923
|
-
}
|
|
924
|
-
const props2 = getFormProperties(schema.ast);
|
|
925
|
-
if (projection) {
|
|
926
|
-
const fieldProjections = projection.getFieldProjections();
|
|
927
|
-
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
928
|
-
const visibleProps = props2.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
929
|
-
const orderedProps = [];
|
|
930
|
-
for (const fieldProjection of fieldProjections) {
|
|
931
|
-
const fieldPath = String(fieldProjection.field.path);
|
|
932
|
-
const prop = visibleProps.find((p) => p.name === fieldPath);
|
|
933
|
-
if (prop) {
|
|
934
|
-
orderedProps.push(prop);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
938
|
-
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
939
|
-
orderedProps.push(...remainingProps);
|
|
940
|
-
return orderedProps;
|
|
941
|
-
}
|
|
942
|
-
const filtered = exclude ? exclude(props2) : props2;
|
|
943
|
-
return sort ? filtered.sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filtered;
|
|
944
|
-
}, [
|
|
881
|
+
const properties = useFormFieldSetProperties({
|
|
945
882
|
schema,
|
|
946
883
|
values,
|
|
947
884
|
exclude,
|
|
948
885
|
sort,
|
|
949
|
-
projection
|
|
950
|
-
|
|
886
|
+
projection
|
|
887
|
+
});
|
|
951
888
|
if ((readonly || layout === "static") && values == null) {
|
|
952
889
|
return null;
|
|
953
890
|
}
|
|
954
|
-
return /* @__PURE__ */ React3.createElement("
|
|
955
|
-
role: "form",
|
|
956
|
-
className: mx("w-full", layout === "inline" && "flex flex-col gap-2"),
|
|
957
|
-
ref: forwardRef4
|
|
958
|
-
}, layout !== "inline" && label && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
|
|
891
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, layout !== "inline" && label && /* @__PURE__ */ React3.createElement(FormFieldLabel, {
|
|
959
892
|
label,
|
|
960
893
|
asChild: true
|
|
961
894
|
}), properties.map((property) => {
|
|
@@ -978,12 +911,52 @@ var FormFieldSet = /* @__PURE__ */ forwardRef(({ label, schema, readonly, path,
|
|
|
978
911
|
projection,
|
|
979
912
|
...props
|
|
980
913
|
}));
|
|
981
|
-
})
|
|
982
|
-
}
|
|
914
|
+
}));
|
|
915
|
+
};
|
|
983
916
|
FormFieldSet.displayName = FORM_FIELDSET_NAME;
|
|
917
|
+
var useFormFieldSetProperties = ({ schema, exclude, projection, values, sort }) => {
|
|
918
|
+
return useMemo3(() => {
|
|
919
|
+
if (!schema) {
|
|
920
|
+
return [];
|
|
921
|
+
}
|
|
922
|
+
const schemaProps = getFormProperties(schema.ast);
|
|
923
|
+
const filteredProps = exclude ? exclude(schemaProps) : schemaProps;
|
|
924
|
+
if (projection) {
|
|
925
|
+
const fieldProjections = projection.getFieldProjections();
|
|
926
|
+
const hiddenProperties = new Set(projection.getHiddenProperties());
|
|
927
|
+
const visibleProps = filteredProps.filter((prop) => !hiddenProperties.has(prop.name.toString()));
|
|
928
|
+
const orderedProps = [];
|
|
929
|
+
for (const fieldProjection of fieldProjections) {
|
|
930
|
+
const fieldPath = String(fieldProjection.field.path);
|
|
931
|
+
const prop = visibleProps.find((prop2) => prop2.name === fieldPath);
|
|
932
|
+
if (prop) {
|
|
933
|
+
orderedProps.push(prop);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const projectionPaths = new Set(fieldProjections.map((projection2) => String(projection2.field.path)));
|
|
937
|
+
const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name.toString()));
|
|
938
|
+
orderedProps.push(...remainingProps);
|
|
939
|
+
return orderedProps;
|
|
940
|
+
}
|
|
941
|
+
return sort ? [
|
|
942
|
+
...filteredProps
|
|
943
|
+
].sort(({ name: a }, { name: b }) => sort.indexOf(a.toString()) - sort.indexOf(b.toString())) : filteredProps;
|
|
944
|
+
}, [
|
|
945
|
+
schema,
|
|
946
|
+
values,
|
|
947
|
+
exclude,
|
|
948
|
+
sort,
|
|
949
|
+
projection
|
|
950
|
+
]);
|
|
951
|
+
};
|
|
984
952
|
|
|
985
953
|
// src/components/Form/Form.tsx
|
|
986
954
|
var omitId = (schema) => schema.pipe(Schema2.omit("id"));
|
|
955
|
+
var omitHiddenFormFields = (schema) => {
|
|
956
|
+
const properties = SchemaAST3.getPropertySignatures(schema.ast);
|
|
957
|
+
const hidden = properties.filter((prop) => Option3.getOrElse(EchoAnnotation.FormInputAnnotation.getFromAst(prop.type), () => true) === false).map((prop) => prop.name);
|
|
958
|
+
return hidden.length === 0 ? schema : schema.pipe(Schema2.omit(...hidden));
|
|
959
|
+
};
|
|
987
960
|
var [FormContextProvider, useFormContext] = createContext("Form");
|
|
988
961
|
var useFormValues = (componentName, path, defaultValue) => {
|
|
989
962
|
const stablePath = useMemo4(() => path ?? [], [
|
|
@@ -993,10 +966,10 @@ var useFormValues = (componentName, path, defaultValue) => {
|
|
|
993
966
|
const { form: { values, onValueChange } } = useFormContext(componentName);
|
|
994
967
|
const value3 = getValue$2(values, jsonPath);
|
|
995
968
|
const lastAppliedPathRef = useRef(null);
|
|
996
|
-
|
|
969
|
+
useEffect2(() => {
|
|
997
970
|
if (value3 == null && defaultValue && lastAppliedPathRef.current !== jsonPath) {
|
|
998
971
|
lastAppliedPathRef.current = jsonPath;
|
|
999
|
-
onValueChange(stablePath,
|
|
972
|
+
onValueChange(stablePath, SchemaAST3.stringKeyword, defaultValue());
|
|
1000
973
|
}
|
|
1001
974
|
}, [
|
|
1002
975
|
value3,
|
|
@@ -1040,29 +1013,35 @@ var FormRoot = ({ children, schema, values, onSave, onCancel, ...props }) => {
|
|
|
1040
1013
|
};
|
|
1041
1014
|
FormRoot.displayName = "Form.Root";
|
|
1042
1015
|
var FORM_VIEWPORT_NAME = "Form.Viewport";
|
|
1043
|
-
var FormViewport = ({ children,
|
|
1016
|
+
var FormViewport = composable(({ children, ...props }, forwardedRef) => {
|
|
1044
1017
|
return /* @__PURE__ */ React4.createElement(ScrollArea.Root, {
|
|
1018
|
+
...composableProps(props),
|
|
1045
1019
|
orientation: "vertical",
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
...props
|
|
1020
|
+
centered: true,
|
|
1021
|
+
padding: true,
|
|
1022
|
+
thin: true,
|
|
1023
|
+
ref: forwardedRef
|
|
1051
1024
|
}, /* @__PURE__ */ React4.createElement(ScrollArea.Viewport, null, children));
|
|
1052
|
-
};
|
|
1025
|
+
});
|
|
1053
1026
|
FormViewport.displayName = FORM_VIEWPORT_NAME;
|
|
1054
1027
|
var FORM_CONTENT_NAME = "Form.Content";
|
|
1055
|
-
var FormContent = ({
|
|
1028
|
+
var FormContent = composable(({ children, ...props }, forwardedRef) => {
|
|
1056
1029
|
const { form, testId } = useFormContext(FORM_CONTENT_NAME);
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1030
|
+
const localRef = useRef(null);
|
|
1031
|
+
const mergedRef = useMergeRefs([
|
|
1032
|
+
forwardedRef,
|
|
1033
|
+
localRef
|
|
1034
|
+
]);
|
|
1035
|
+
useKeyHandler(localRef, form);
|
|
1059
1036
|
return /* @__PURE__ */ React4.createElement("div", {
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1037
|
+
...composableProps(props, {
|
|
1038
|
+
role: "form",
|
|
1039
|
+
classNames: mx(withColumn.center(), "flex flex-col w-full pb-form-gap")
|
|
1040
|
+
}),
|
|
1041
|
+
"data-testid": testId,
|
|
1042
|
+
ref: mergedRef
|
|
1064
1043
|
}, children);
|
|
1065
|
-
};
|
|
1044
|
+
});
|
|
1066
1045
|
FormContent.displayName = FORM_CONTENT_NAME;
|
|
1067
1046
|
var FORM_FIELDSET_NAME2 = "Form.FieldSet";
|
|
1068
1047
|
var FormFieldSet2 = (props) => {
|
|
@@ -1076,18 +1055,17 @@ var FormFieldSet2 = (props) => {
|
|
|
1076
1055
|
FormFieldSet2.displayName = FORM_FIELDSET_NAME2;
|
|
1077
1056
|
var FORM_ACTIONS_NAME = "Form.Actions";
|
|
1078
1057
|
var FormActions = ({ classNames }) => {
|
|
1079
|
-
const { t } = useTranslation2(
|
|
1058
|
+
const { t } = useTranslation2(translationKey2);
|
|
1080
1059
|
const { form: { canSave, onSave, onCancel }, readonly, layout } = useFormContext(FORM_ACTIONS_NAME);
|
|
1081
1060
|
if (readonly || layout === "static") {
|
|
1082
1061
|
return null;
|
|
1083
1062
|
}
|
|
1084
1063
|
return /* @__PURE__ */ React4.createElement("div", {
|
|
1085
|
-
|
|
1086
|
-
className: mx2("grid grid-flow-col gap-2 auto-cols-fr py-form-padding", classNames)
|
|
1064
|
+
className: mx(withColumn.center(), "grid grid-flow-col gap-form-gap auto-cols-fr py-form-padding", classNames)
|
|
1087
1065
|
}, onCancel && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1088
1066
|
icon: "ph--x--regular",
|
|
1089
1067
|
iconEnd: true,
|
|
1090
|
-
label: t("cancel
|
|
1068
|
+
label: t("cancel-button.label"),
|
|
1091
1069
|
onClick: onCancel,
|
|
1092
1070
|
"data-testid": "cancel-button"
|
|
1093
1071
|
}), onSave && /* @__PURE__ */ React4.createElement(IconButton, {
|
|
@@ -1096,29 +1074,42 @@ var FormActions = ({ classNames }) => {
|
|
|
1096
1074
|
disabled: !canSave,
|
|
1097
1075
|
icon: "ph--check--regular",
|
|
1098
1076
|
iconEnd: true,
|
|
1099
|
-
label: t("save
|
|
1077
|
+
label: t("save-button.label"),
|
|
1100
1078
|
onClick: onSave,
|
|
1101
1079
|
"data-testid": "save-button"
|
|
1102
1080
|
}));
|
|
1103
1081
|
};
|
|
1104
1082
|
FormActions.displayName = FORM_ACTIONS_NAME;
|
|
1083
|
+
var FORM_SECTION_NAME = "Form.Section";
|
|
1084
|
+
var FormSection = composable(({ children, label, description, ...props }, forwardedRef) => {
|
|
1085
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1086
|
+
...composableProps(props, {
|
|
1087
|
+
classNames: "flex flex-col pt-form-section-gap first:pt-0"
|
|
1088
|
+
}),
|
|
1089
|
+
ref: forwardedRef
|
|
1090
|
+
}, /* @__PURE__ */ React4.createElement("h2", {
|
|
1091
|
+
className: "text-lg"
|
|
1092
|
+
}, label), description && /* @__PURE__ */ React4.createElement("p", {
|
|
1093
|
+
className: "text-description"
|
|
1094
|
+
}, description), children);
|
|
1095
|
+
});
|
|
1096
|
+
FormSection.displayName = FORM_SECTION_NAME;
|
|
1105
1097
|
var FORM_SUBMIT_NAME = "Form.Submit";
|
|
1106
1098
|
var FormSubmit = ({ classNames, label, icon, disabled }) => {
|
|
1107
|
-
const { t } = useTranslation2(
|
|
1099
|
+
const { t } = useTranslation2(translationKey2);
|
|
1108
1100
|
const { form: { canSave, onSave }, readonly, layout } = useFormContext(FORM_SUBMIT_NAME);
|
|
1109
1101
|
if (readonly || layout === "static") {
|
|
1110
1102
|
return null;
|
|
1111
1103
|
}
|
|
1112
1104
|
return /* @__PURE__ */ React4.createElement("div", {
|
|
1113
|
-
|
|
1114
|
-
className: mx2("flex w-full pt-form-padding", classNames)
|
|
1105
|
+
className: mx("flex w-full pt-form-padding", classNames)
|
|
1115
1106
|
}, /* @__PURE__ */ React4.createElement(IconButton, {
|
|
1116
1107
|
classNames: "w-full",
|
|
1117
1108
|
type: "submit",
|
|
1118
1109
|
variant: "primary",
|
|
1119
1110
|
disabled: disabled ?? !canSave,
|
|
1120
1111
|
icon: icon ?? "ph--check--regular",
|
|
1121
|
-
label: label ?? t("save
|
|
1112
|
+
label: label ?? t("save-button.label"),
|
|
1122
1113
|
onClick: onSave,
|
|
1123
1114
|
"data-testid": "save-button"
|
|
1124
1115
|
}));
|
|
@@ -1128,6 +1119,7 @@ var Form = {
|
|
|
1128
1119
|
Root: FormRoot,
|
|
1129
1120
|
Viewport: FormViewport,
|
|
1130
1121
|
Content: FormContent,
|
|
1122
|
+
Section: FormSection,
|
|
1131
1123
|
FieldSet: FormFieldSet2,
|
|
1132
1124
|
Label: FormFieldLabel,
|
|
1133
1125
|
Actions: FormActions,
|
|
@@ -1136,18 +1128,18 @@ var Form = {
|
|
|
1136
1128
|
|
|
1137
1129
|
// src/components/Form/fields/ArrayField.tsx
|
|
1138
1130
|
var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps, ...props }) => {
|
|
1139
|
-
const { t } = useTranslation3(
|
|
1131
|
+
const { t } = useTranslation3(translationKey3);
|
|
1140
1132
|
const elementType = getArrayElementType2(type);
|
|
1141
1133
|
const { onValueChange } = inputProps;
|
|
1142
1134
|
const values = useFormValues(ArrayField.displayName, path, () => []);
|
|
1143
1135
|
const getDefaultObjectValue = (typeNode) => {
|
|
1144
1136
|
const baseNode = findNode2(typeNode, isDiscriminatedUnion2);
|
|
1145
|
-
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode,
|
|
1137
|
+
const typeLiteral = baseNode ? getDiscriminatedType2(baseNode, {}) : findNode2(typeNode, SchemaAST4.isTypeLiteral);
|
|
1146
1138
|
if (!typeLiteral) {
|
|
1147
1139
|
return {};
|
|
1148
1140
|
}
|
|
1149
1141
|
return Object.fromEntries(getFormProperties(typeLiteral).map((prop) => {
|
|
1150
|
-
const defaultValue =
|
|
1142
|
+
const defaultValue = SchemaAST4.getDefaultAnnotation(prop.type).pipe((annotation) => Option4.getOrUndefined(annotation));
|
|
1151
1143
|
return [
|
|
1152
1144
|
prop.name,
|
|
1153
1145
|
defaultValue
|
|
@@ -1181,13 +1173,11 @@ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps,
|
|
|
1181
1173
|
label,
|
|
1182
1174
|
asChild: true
|
|
1183
1175
|
}), /* @__PURE__ */ React5.createElement("div", {
|
|
1184
|
-
|
|
1185
|
-
className: "flex flex-col gap-2"
|
|
1176
|
+
className: "flex flex-col gap-form-gap"
|
|
1186
1177
|
}, values?.map((_, index) => {
|
|
1187
1178
|
return /* @__PURE__ */ React5.createElement("div", {
|
|
1188
|
-
role: "none",
|
|
1189
1179
|
key: index,
|
|
1190
|
-
className: "grid grid-cols-[1fr_min-content] gap-
|
|
1180
|
+
className: "grid grid-cols-[1fr_min-content] gap-form-gap last:mb-form-gap items-center"
|
|
1191
1181
|
}, /* @__PURE__ */ React5.createElement(FormField, {
|
|
1192
1182
|
autoFocus: index === values.length - 1,
|
|
1193
1183
|
type: elementType,
|
|
@@ -1199,22 +1189,20 @@ var ArrayField = ({ type, path, label, readonly, layout, fieldProps: inputProps,
|
|
|
1199
1189
|
layout: "inline",
|
|
1200
1190
|
...props
|
|
1201
1191
|
}), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement("div", {
|
|
1202
|
-
role: "none",
|
|
1203
1192
|
className: "flex flex-col h-full justify-end"
|
|
1204
1193
|
}, /* @__PURE__ */ React5.createElement("div", {
|
|
1205
|
-
role: "none",
|
|
1206
1194
|
className: "flex items-center h-[2rem]"
|
|
1207
1195
|
}, /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1208
1196
|
icon: "ph--x--regular",
|
|
1209
1197
|
iconOnly: true,
|
|
1210
|
-
label: t("button
|
|
1198
|
+
label: t("remove.button"),
|
|
1211
1199
|
onClick: () => handleDelete(index),
|
|
1212
1200
|
classNames: "self-center"
|
|
1213
1201
|
}))));
|
|
1214
1202
|
})), !readonly && layout !== "static" && /* @__PURE__ */ React5.createElement(IconButton2, {
|
|
1215
1203
|
classNames: "flex w-full",
|
|
1216
1204
|
icon: "ph--plus--regular",
|
|
1217
|
-
label: t("add
|
|
1205
|
+
label: t("add-item.button"),
|
|
1218
1206
|
onClick: handleAdd
|
|
1219
1207
|
}));
|
|
1220
1208
|
};
|
|
@@ -1262,12 +1250,13 @@ var BooleanField = ({ type, readonly, onValueChange, ...props }) => {
|
|
|
1262
1250
|
};
|
|
1263
1251
|
|
|
1264
1252
|
// src/components/Form/fields/GeoPointField.tsx
|
|
1265
|
-
import React7, { useCallback as useCallback5, useEffect as
|
|
1253
|
+
import React7, { useCallback as useCallback5, useEffect as useEffect3, useMemo as useMemo5, useState as useState2 } from "react";
|
|
1266
1254
|
import { GeoLocation as GeoLocation3 } from "@dxos/echo/internal";
|
|
1267
1255
|
import { Input as Input3, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
1268
1256
|
import { safeParseFloat } from "@dxos/util";
|
|
1257
|
+
import { translationKey as translationKey4 } from "#translations";
|
|
1269
1258
|
var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onValueChange, onBlur }) => {
|
|
1270
|
-
const { t } = useTranslation4(
|
|
1259
|
+
const { t } = useTranslation4(translationKey4);
|
|
1271
1260
|
const { status, error } = getStatus();
|
|
1272
1261
|
const geoPoint = useMemo5(() => getValue() ?? [
|
|
1273
1262
|
0,
|
|
@@ -1280,7 +1269,7 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1280
1269
|
]);
|
|
1281
1270
|
const [longitudeText, setLongitudeText] = useState2(value3.longitude?.toString());
|
|
1282
1271
|
const [latitudeText, setLatitudeText] = useState2(value3.latitude?.toString());
|
|
1283
|
-
|
|
1272
|
+
useEffect3(() => {
|
|
1284
1273
|
const location = GeoLocation3.fromGeoPoint(geoPoint);
|
|
1285
1274
|
setLongitudeText(location.longitude?.toString());
|
|
1286
1275
|
setLatitudeText(location.latitude?.toString());
|
|
@@ -1321,25 +1310,24 @@ var GeoPointField = ({ type, label, readonly, layout, getStatus, getValue, onVal
|
|
|
1321
1310
|
label,
|
|
1322
1311
|
asChild: true
|
|
1323
1312
|
}), layout === "static" ? /* @__PURE__ */ React7.createElement(LatLng, value3) : /* @__PURE__ */ React7.createElement("div", {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("latitude label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1313
|
+
className: "grid grid-cols-2 gap-form-gap"
|
|
1314
|
+
}, /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("latitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1327
1315
|
type: "number",
|
|
1328
1316
|
step: "0.00001",
|
|
1329
1317
|
min: "-90",
|
|
1330
1318
|
max: "90",
|
|
1331
1319
|
disabled: !!readonly,
|
|
1332
|
-
placeholder: t("latitude
|
|
1320
|
+
placeholder: t("latitude.placeholder"),
|
|
1333
1321
|
value: latitudeText ?? "",
|
|
1334
1322
|
onChange: handleChange("latitude", setLatitudeText),
|
|
1335
1323
|
onBlur
|
|
1336
|
-
}))), /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("longitude
|
|
1324
|
+
}))), /* @__PURE__ */ React7.createElement("div", null, /* @__PURE__ */ React7.createElement(Input3.Root, null, layout !== "inline" && /* @__PURE__ */ React7.createElement(Input3.Label, null, t("longitude.label")), /* @__PURE__ */ React7.createElement(Input3.TextInput, {
|
|
1337
1325
|
type: "number",
|
|
1338
1326
|
step: "0.00001",
|
|
1339
1327
|
min: "-180",
|
|
1340
1328
|
max: "180",
|
|
1341
1329
|
disabled: !!readonly,
|
|
1342
|
-
placeholder: t("longitude
|
|
1330
|
+
placeholder: t("longitude.placeholder"),
|
|
1343
1331
|
value: longitudeText ?? "",
|
|
1344
1332
|
onChange: handleChange("longitude", setLongitudeText),
|
|
1345
1333
|
onBlur
|
|
@@ -1349,7 +1337,7 @@ var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
|
1349
1337
|
const latHem = latitude >= 0 ? "N" : "S";
|
|
1350
1338
|
const lngHem = longitude >= 0 ? "E" : "W";
|
|
1351
1339
|
return /* @__PURE__ */ React7.createElement("span", {
|
|
1352
|
-
className: "inline-flex items-center gap-
|
|
1340
|
+
className: "inline-flex items-center gap-form-gap"
|
|
1353
1341
|
}, /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(latitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
1354
1342
|
className: "text-subdued"
|
|
1355
1343
|
}, "\xB0", latHem)), /* @__PURE__ */ React7.createElement("span", null, /* @__PURE__ */ React7.createElement("span", null, Math.abs(longitude).toFixed(5)), /* @__PURE__ */ React7.createElement("span", {
|
|
@@ -1358,56 +1346,141 @@ var LatLng = ({ latitude = 0, longitude = 0 }) => {
|
|
|
1358
1346
|
};
|
|
1359
1347
|
|
|
1360
1348
|
// src/components/Form/fields/MarkdownField.tsx
|
|
1361
|
-
import
|
|
1362
|
-
import {
|
|
1363
|
-
|
|
1349
|
+
import { useAtomValue } from "@effect-atom/atom-react";
|
|
1350
|
+
import React8, { useCallback as useCallback6, useMemo as useMemo6 } from "react";
|
|
1351
|
+
import { Obj, Ref as Ref2 } from "@dxos/echo";
|
|
1352
|
+
import { AtomRef } from "@dxos/echo-atom";
|
|
1353
|
+
import { createDocAccessor } from "@dxos/echo-db";
|
|
1354
|
+
import { Button, Icon as Icon2, Input as Input4, useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1355
|
+
import { Editor, useBasicMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
1356
|
+
import { Text } from "@dxos/schema";
|
|
1357
|
+
import { createDataExtensions } from "@dxos/ui-editor";
|
|
1358
|
+
import { translationKey as translationKey5 } from "#translations";
|
|
1359
|
+
var editorClassNames = "transition-colors bg-input-surface focus-within:bg-focus-surface border border-separator rounded-xs p-1 px-2";
|
|
1360
|
+
var MarkdownField = ({ type, readonly, label, placeholder, layout, db, getStatus, getValue, onValueChange }) => {
|
|
1364
1361
|
const { status, error } = getStatus();
|
|
1365
|
-
const
|
|
1366
|
-
const adjustHeight = useCallback6(() => {
|
|
1367
|
-
const textarea = textareaRef.current;
|
|
1368
|
-
if (textarea) {
|
|
1369
|
-
textarea.style.blockSize = "auto";
|
|
1370
|
-
textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
|
|
1371
|
-
}
|
|
1372
|
-
}, []);
|
|
1373
|
-
useEffect5(() => {
|
|
1374
|
-
adjustHeight();
|
|
1375
|
-
}, [
|
|
1376
|
-
adjustHeight
|
|
1377
|
-
]);
|
|
1378
|
-
useEffect5(() => {
|
|
1379
|
-
adjustHeight();
|
|
1380
|
-
}, [
|
|
1381
|
-
getValue(),
|
|
1382
|
-
adjustHeight
|
|
1383
|
-
]);
|
|
1384
|
-
const handleChange = useCallback6((event) => onValueChange(type, event.target.value), [
|
|
1385
|
-
type,
|
|
1386
|
-
onValueChange
|
|
1387
|
-
]);
|
|
1362
|
+
const isRef = Ref2.isRefType(type);
|
|
1388
1363
|
const value3 = getValue();
|
|
1389
|
-
if ((readonly || layout === "static") &&
|
|
1364
|
+
if ((readonly || layout === "static") && value3 == null) {
|
|
1390
1365
|
return null;
|
|
1391
1366
|
}
|
|
1367
|
+
const renderEditor = () => {
|
|
1368
|
+
if (isRef) {
|
|
1369
|
+
const reference = value3;
|
|
1370
|
+
if (reference) {
|
|
1371
|
+
return /* @__PURE__ */ React8.createElement(RefMarkdownEditor, {
|
|
1372
|
+
reference,
|
|
1373
|
+
placeholder
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
if (readonly) {
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
return /* @__PURE__ */ React8.createElement(CreateTextButton, {
|
|
1380
|
+
db,
|
|
1381
|
+
disabled: !db,
|
|
1382
|
+
onCreate: (ref) => onValueChange(type, ref)
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
return /* @__PURE__ */ React8.createElement(StringMarkdownEditor, {
|
|
1386
|
+
value: value3 ?? "",
|
|
1387
|
+
placeholder,
|
|
1388
|
+
readonly: !!readonly,
|
|
1389
|
+
onChange: (next) => onValueChange(type, next)
|
|
1390
|
+
});
|
|
1391
|
+
};
|
|
1392
|
+
const renderStatic = () => {
|
|
1393
|
+
if (isRef) {
|
|
1394
|
+
const reference = value3;
|
|
1395
|
+
return reference ? /* @__PURE__ */ React8.createElement(RefStaticText, {
|
|
1396
|
+
reference
|
|
1397
|
+
}) : null;
|
|
1398
|
+
}
|
|
1399
|
+
return /* @__PURE__ */ React8.createElement("p", {
|
|
1400
|
+
className: "whitespace-pre-wrap"
|
|
1401
|
+
}, value3 ?? "");
|
|
1402
|
+
};
|
|
1392
1403
|
return /* @__PURE__ */ React8.createElement(Input4.Root, {
|
|
1393
1404
|
validationValence: status
|
|
1394
1405
|
}, layout !== "inline" && /* @__PURE__ */ React8.createElement(FormFieldLabel, {
|
|
1395
1406
|
error,
|
|
1396
1407
|
readonly,
|
|
1397
1408
|
label
|
|
1398
|
-
}), layout === "static" ?
|
|
1399
|
-
|
|
1400
|
-
|
|
1409
|
+
}), layout === "static" ? renderStatic() : renderEditor(), layout === "full" && /* @__PURE__ */ React8.createElement(Input4.Validation, null, error));
|
|
1410
|
+
};
|
|
1411
|
+
var RefStaticText = ({ reference }) => {
|
|
1412
|
+
const text = useAtomValue(useMemo6(() => AtomRef.make(reference), [
|
|
1413
|
+
reference
|
|
1414
|
+
]));
|
|
1415
|
+
if (!text?.content) {
|
|
1416
|
+
return null;
|
|
1417
|
+
}
|
|
1418
|
+
return /* @__PURE__ */ React8.createElement("p", {
|
|
1419
|
+
className: "whitespace-pre-wrap"
|
|
1420
|
+
}, text.content);
|
|
1421
|
+
};
|
|
1422
|
+
var RefMarkdownEditor = ({ reference, placeholder }) => {
|
|
1423
|
+
const text = useAtomValue(useMemo6(() => AtomRef.make(reference), [
|
|
1424
|
+
reference
|
|
1425
|
+
]));
|
|
1426
|
+
const dataExtensions = useMemo6(() => text ? [
|
|
1427
|
+
createDataExtensions({
|
|
1428
|
+
id: reference.dxn.toString(),
|
|
1429
|
+
text: createDocAccessor(text, [
|
|
1430
|
+
"content"
|
|
1431
|
+
])
|
|
1432
|
+
})
|
|
1433
|
+
] : [], [
|
|
1434
|
+
text,
|
|
1435
|
+
reference
|
|
1436
|
+
]);
|
|
1437
|
+
const extensions = useBasicMarkdownExtensions({
|
|
1401
1438
|
placeholder,
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
})
|
|
1439
|
+
extensions: dataExtensions
|
|
1440
|
+
});
|
|
1441
|
+
if (!text) {
|
|
1442
|
+
return null;
|
|
1443
|
+
}
|
|
1444
|
+
return /* @__PURE__ */ React8.createElement(Editor.Root, null, /* @__PURE__ */ React8.createElement(Editor.View, {
|
|
1445
|
+
classNames: editorClassNames,
|
|
1446
|
+
extensions
|
|
1447
|
+
}));
|
|
1448
|
+
};
|
|
1449
|
+
var StringMarkdownEditor = ({ value: value3, placeholder, readonly, onChange }) => {
|
|
1450
|
+
const extensions = useBasicMarkdownExtensions({
|
|
1451
|
+
placeholder
|
|
1452
|
+
});
|
|
1453
|
+
const handleChange = useCallback6((next) => onChange(next), [
|
|
1454
|
+
onChange
|
|
1455
|
+
]);
|
|
1456
|
+
return /* @__PURE__ */ React8.createElement(Editor.Root, null, /* @__PURE__ */ React8.createElement(Editor.View, {
|
|
1457
|
+
classNames: editorClassNames,
|
|
1458
|
+
extensions,
|
|
1459
|
+
value: value3,
|
|
1460
|
+
onChange: readonly ? void 0 : handleChange
|
|
1461
|
+
}));
|
|
1462
|
+
};
|
|
1463
|
+
var CreateTextButton = ({ db, disabled, onCreate }) => {
|
|
1464
|
+
const { t } = useTranslation5(translationKey5);
|
|
1465
|
+
const handleClick = useCallback6(() => {
|
|
1466
|
+
if (!db) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
const text = db.add(Obj.make(Text.Text, {
|
|
1470
|
+
content: ""
|
|
1471
|
+
}));
|
|
1472
|
+
onCreate(Ref2.make(text));
|
|
1473
|
+
}, [
|
|
1474
|
+
db,
|
|
1475
|
+
onCreate
|
|
1476
|
+
]);
|
|
1477
|
+
return /* @__PURE__ */ React8.createElement(Button, {
|
|
1478
|
+
onClick: handleClick,
|
|
1479
|
+
disabled
|
|
1480
|
+
}, /* @__PURE__ */ React8.createElement(Icon2, {
|
|
1481
|
+
icon: "ph--plus--regular",
|
|
1482
|
+
size: 4
|
|
1483
|
+
}), /* @__PURE__ */ React8.createElement("span", null, t("create-text.label")));
|
|
1411
1484
|
};
|
|
1412
1485
|
|
|
1413
1486
|
// src/components/Form/fields/NumberField.tsx
|
|
@@ -1433,48 +1506,33 @@ var NumberField = ({ type, readonly, placeholder, onValueChange, onBlur, ...prop
|
|
|
1433
1506
|
};
|
|
1434
1507
|
|
|
1435
1508
|
// src/components/Form/fields/RefField.tsx
|
|
1509
|
+
import React11, { useCallback as useCallback9, useMemo as useMemo7, useState as useState4 } from "react";
|
|
1436
1510
|
import "@dxos/lit-ui/dx-tag-picker.pcss";
|
|
1437
|
-
import
|
|
1438
|
-
import {
|
|
1439
|
-
import { ReferenceAnnotationId } from "@dxos/echo/internal";
|
|
1440
|
-
import {
|
|
1441
|
-
import { findAnnotation } from "@dxos/effect";
|
|
1511
|
+
import { Entity, Filter, Obj as Obj2, Ref as Ref3, Type } from "@dxos/echo";
|
|
1512
|
+
import { useQuery, useSchema as defaultUseSchema } from "@dxos/echo-react";
|
|
1513
|
+
import { ReferenceAnnotationId as ReferenceAnnotationId2 } from "@dxos/echo/internal";
|
|
1514
|
+
import { findAnnotation as findAnnotation2 } from "@dxos/effect";
|
|
1442
1515
|
import { DXN } from "@dxos/keys";
|
|
1443
1516
|
import { DxAnchor } from "@dxos/lit-ui/react";
|
|
1444
|
-
import { Button, Icon as
|
|
1517
|
+
import { Button as Button2, Icon as Icon3, Input as Input6, useTranslation as useTranslation7 } from "@dxos/react-ui";
|
|
1445
1518
|
import { ParentLabelAnnotationId } from "@dxos/schema";
|
|
1446
|
-
import {
|
|
1519
|
+
import { translationKey as translationKey7 } from "#translations";
|
|
1447
1520
|
|
|
1448
1521
|
// src/components/ObjectPicker/ObjectPicker.tsx
|
|
1449
|
-
import React10, { forwardRef
|
|
1450
|
-
import { Popover, useTranslation as
|
|
1451
|
-
import { Combobox
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
value: "__create__",
|
|
1457
|
-
label: t(createOptionLabel[0], {
|
|
1458
|
-
ns: createOptionLabel[1].ns,
|
|
1459
|
-
text: query
|
|
1460
|
-
}),
|
|
1461
|
-
icon: createOptionIcon,
|
|
1462
|
-
classNames: "flex items-center gap-2",
|
|
1463
|
-
closeOnSelect: false,
|
|
1464
|
-
onSelect: () => {
|
|
1465
|
-
onCreateItemSelect(query);
|
|
1466
|
-
}
|
|
1467
|
-
});
|
|
1468
|
-
};
|
|
1469
|
-
var ObjectPickerContent = /* @__PURE__ */ forwardRef2(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, onSelect, onCreate, ...props }, ref) => {
|
|
1470
|
-
const { t } = useTranslation5(translationKey);
|
|
1522
|
+
import React10, { forwardRef, useCallback as useCallback8, useState as useState3 } from "react";
|
|
1523
|
+
import { Popover, useTranslation as useTranslation6 } from "@dxos/react-ui";
|
|
1524
|
+
import { Combobox } from "@dxos/react-ui-list";
|
|
1525
|
+
import { useSearchListResults } from "@dxos/react-ui-search";
|
|
1526
|
+
import { translationKey as translationKey6 } from "#translations";
|
|
1527
|
+
var ObjectPickerContent = /* @__PURE__ */ forwardRef(({ options, selectedIds, createSchema, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap: createFieldMap3, onSelect, onCreate, ...props }, forwardedRef) => {
|
|
1528
|
+
const { t } = useTranslation6(translationKey6);
|
|
1471
1529
|
const [showForm, setShowForm] = useState3(false);
|
|
1472
1530
|
const [formInitialValue, setFormInitialValue] = useState3("");
|
|
1473
|
-
const { results, handleSearch } = useSearchListResults({
|
|
1531
|
+
const { results, query, handleSearch } = useSearchListResults({
|
|
1474
1532
|
items: options
|
|
1475
1533
|
});
|
|
1476
|
-
const handleFormSave = useCallback8((values) => {
|
|
1477
|
-
onCreate?.(values);
|
|
1534
|
+
const handleFormSave = useCallback8(async (values) => {
|
|
1535
|
+
await onCreate?.(values);
|
|
1478
1536
|
setShowForm(false);
|
|
1479
1537
|
setFormInitialValue("");
|
|
1480
1538
|
}, [
|
|
@@ -1496,22 +1554,31 @@ var ObjectPickerContent = /* @__PURE__ */ forwardRef2(({ options, selectedIds, c
|
|
|
1496
1554
|
}, [
|
|
1497
1555
|
createSchema
|
|
1498
1556
|
]);
|
|
1557
|
+
if (showForm && createSchema) {
|
|
1558
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1559
|
+
...props,
|
|
1560
|
+
onKeyDownCapture: handleKeyDown,
|
|
1561
|
+
ref: forwardedRef
|
|
1562
|
+
}, /* @__PURE__ */ React10.createElement(Popover.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Root, {
|
|
1563
|
+
testId: "create-referenced-object-form",
|
|
1564
|
+
schema: createSchema,
|
|
1565
|
+
defaultValues: createInitialValuePath ? {
|
|
1566
|
+
[createInitialValuePath]: formInitialValue
|
|
1567
|
+
} : {},
|
|
1568
|
+
fieldMap: createFieldMap3,
|
|
1569
|
+
onSave: handleFormSave,
|
|
1570
|
+
onCancel: handleFormCancel
|
|
1571
|
+
}, /* @__PURE__ */ React10.createElement(Form.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, null), /* @__PURE__ */ React10.createElement(Form.Actions, null))))), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
|
|
1572
|
+
}
|
|
1499
1573
|
return /* @__PURE__ */ React10.createElement(Combobox.Content, {
|
|
1500
1574
|
...props,
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
[createInitialValuePath]: formInitialValue
|
|
1509
|
-
} : {},
|
|
1510
|
-
onSave: handleFormSave,
|
|
1511
|
-
onCancel: handleFormCancel
|
|
1512
|
-
}, /* @__PURE__ */ React10.createElement(Form.Viewport, null, /* @__PURE__ */ React10.createElement(Form.Content, null, /* @__PURE__ */ React10.createElement(Form.FieldSet, null), /* @__PURE__ */ React10.createElement(Form.Actions, null))))) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(Combobox.Input, {
|
|
1513
|
-
placeholder: t("ref field combobox input placeholder"),
|
|
1514
|
-
autoFocus: true
|
|
1575
|
+
onKeyDownCapture: handleKeyDown,
|
|
1576
|
+
ref: forwardedRef
|
|
1577
|
+
}, /* @__PURE__ */ React10.createElement(Combobox.Input, {
|
|
1578
|
+
placeholder: t("ref-field-combobox-input.placeholder"),
|
|
1579
|
+
autoFocus: true,
|
|
1580
|
+
value: query,
|
|
1581
|
+
onValueChange: handleSearch
|
|
1515
1582
|
}), /* @__PURE__ */ React10.createElement(Combobox.List, null, results.map((option) => /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1516
1583
|
key: option.id,
|
|
1517
1584
|
value: option.id,
|
|
@@ -1519,16 +1586,34 @@ var ObjectPickerContent = /* @__PURE__ */ forwardRef2(({ options, selectedIds, c
|
|
|
1519
1586
|
checked: selectedIds?.includes(option.id),
|
|
1520
1587
|
onSelect: () => onSelect(option.id),
|
|
1521
1588
|
classNames: "flex items-center gap-2"
|
|
1522
|
-
})),
|
|
1589
|
+
})), createSchema && onCreate && /* @__PURE__ */ React10.createElement(CreateItem, {
|
|
1590
|
+
query,
|
|
1523
1591
|
createOptionLabel,
|
|
1524
|
-
createOptionIcon,
|
|
1525
|
-
onCreateItemSelect: (
|
|
1526
|
-
setFormInitialValue(
|
|
1592
|
+
createOptionIcon: createOptionIcon ?? "ph--plus--regular",
|
|
1593
|
+
onCreateItemSelect: (currentQuery) => {
|
|
1594
|
+
setFormInitialValue(currentQuery);
|
|
1527
1595
|
setShowForm(true);
|
|
1528
1596
|
}
|
|
1529
|
-
}))
|
|
1597
|
+
})), /* @__PURE__ */ React10.createElement(Combobox.Arrow, null));
|
|
1530
1598
|
});
|
|
1531
|
-
|
|
1599
|
+
var CreateItem = ({ query, createOptionLabel, createOptionIcon, onCreateItemSelect }) => {
|
|
1600
|
+
const { t } = useTranslation6(translationKey6);
|
|
1601
|
+
const label = createOptionLabel ? t(createOptionLabel[0], {
|
|
1602
|
+
ns: createOptionLabel[1].ns,
|
|
1603
|
+
text: query
|
|
1604
|
+
}) : t("create-option.label");
|
|
1605
|
+
return /* @__PURE__ */ React10.createElement(Combobox.Item, {
|
|
1606
|
+
value: "__create__",
|
|
1607
|
+
label,
|
|
1608
|
+
icon: createOptionIcon,
|
|
1609
|
+
classNames: "flex items-center gap-2",
|
|
1610
|
+
closeOnSelect: false,
|
|
1611
|
+
onSelect: () => {
|
|
1612
|
+
onCreateItemSelect(query);
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
};
|
|
1616
|
+
ObjectPickerContent.displayName = "ObjectPicker.Content";
|
|
1532
1617
|
var ObjectPicker = {
|
|
1533
1618
|
Root: Combobox.Root,
|
|
1534
1619
|
Portal: Combobox.Portal,
|
|
@@ -1543,39 +1628,41 @@ var isRefSnapshot = (val) => {
|
|
|
1543
1628
|
};
|
|
1544
1629
|
var defaultGetOptions = (results, { parentLabel } = {}) => results.map((result) => {
|
|
1545
1630
|
const id = Entity.getDXN(result).toString();
|
|
1546
|
-
const parent = parentLabel ?
|
|
1631
|
+
const parent = parentLabel ? Obj2.getParent(result) : void 0;
|
|
1547
1632
|
const label = parent ? Entity.getLabel(parent) : Entity.getLabel(result);
|
|
1548
1633
|
return {
|
|
1549
1634
|
id,
|
|
1550
1635
|
label: label ?? id
|
|
1551
1636
|
};
|
|
1552
1637
|
});
|
|
1553
|
-
var
|
|
1638
|
+
var defaultUseResults = (db, typename) => useQuery(db, typename ? typename === Type.getTypename(Obj2.Unknown) ? Filter.everything() : Filter.typename(typename) : Filter.nothing());
|
|
1554
1639
|
var RefField = (props) => {
|
|
1555
|
-
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, db,
|
|
1556
|
-
const { t } =
|
|
1640
|
+
const { type, readonly, label, placeholder, layout, getStatus, getValue, createOptionLabel, createOptionIcon, createInitialValuePath, createFieldMap: createFieldMap3, db, useSchema = defaultUseSchema, useResults = defaultUseResults, getOptions = defaultGetOptions, onCreate, onValueChange } = props;
|
|
1641
|
+
const { t } = useTranslation7(translationKey7);
|
|
1557
1642
|
const { status, error } = getStatus();
|
|
1558
|
-
const typename =
|
|
1643
|
+
const typename = useMemo7(() => type ? findAnnotation2(type, ReferenceAnnotationId2)?.typename : void 0, [
|
|
1559
1644
|
type
|
|
1560
1645
|
]);
|
|
1561
1646
|
const results = useResults(db, typename);
|
|
1562
|
-
const options =
|
|
1563
|
-
const parentLabel = type ?
|
|
1564
|
-
return
|
|
1647
|
+
const options = useMemo7(() => {
|
|
1648
|
+
const parentLabel = type ? findAnnotation2(type, ParentLabelAnnotationId) === true : false;
|
|
1649
|
+
return getOptions(results, {
|
|
1565
1650
|
parentLabel
|
|
1566
1651
|
});
|
|
1567
1652
|
}, [
|
|
1568
1653
|
results,
|
|
1569
|
-
|
|
1654
|
+
getOptions,
|
|
1570
1655
|
type
|
|
1571
1656
|
]);
|
|
1572
1657
|
const handleGetValue = useCallback9(() => {
|
|
1573
1658
|
const formValue = getValue();
|
|
1659
|
+
const dxnToObjectId = (dxn) => dxn.split(":").pop() ?? dxn;
|
|
1574
1660
|
const unknownToRefOption = (value3) => {
|
|
1575
|
-
const isRef =
|
|
1661
|
+
const isRef = Ref3.isRef(value3);
|
|
1576
1662
|
if (isRef || isRefSnapshot(value3)) {
|
|
1577
1663
|
const dxnString = isRef ? value3.dxn.toString() : value3["/"];
|
|
1578
|
-
const
|
|
1664
|
+
const objectId = dxnToObjectId(dxnString);
|
|
1665
|
+
const matchingOption = options.find((option) => dxnToObjectId(option.id) === objectId);
|
|
1579
1666
|
if (matchingOption) {
|
|
1580
1667
|
return matchingOption;
|
|
1581
1668
|
}
|
|
@@ -1587,29 +1674,37 @@ var RefField = (props) => {
|
|
|
1587
1674
|
options,
|
|
1588
1675
|
getValue
|
|
1589
1676
|
]);
|
|
1590
|
-
const handleUpdate = useCallback9((id) => {
|
|
1591
|
-
const item2 = options.find((option) => option.id === id);
|
|
1592
|
-
const ref = item2 ? Ref2.fromDXN(DXN.parse(item2.id)) : void 0;
|
|
1593
|
-
onValueChange(type, ref);
|
|
1594
|
-
}, [
|
|
1595
|
-
options,
|
|
1596
|
-
type,
|
|
1597
|
-
onValueChange
|
|
1598
|
-
]);
|
|
1599
1677
|
const item = handleGetValue();
|
|
1600
|
-
const selectedIds =
|
|
1678
|
+
const selectedIds = useMemo7(() => item ? [
|
|
1601
1679
|
item.id
|
|
1602
1680
|
] : [], [
|
|
1603
1681
|
item
|
|
1604
1682
|
]);
|
|
1605
1683
|
const createSchema = useSchema(db, typename);
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1684
|
+
const [open, setOpen] = useState4(false);
|
|
1685
|
+
const handleCreate = useCallback9(async (values) => {
|
|
1686
|
+
if (!createSchema || !onCreate) {
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
const newObject = await onCreate(createSchema, values);
|
|
1690
|
+
if (newObject) {
|
|
1691
|
+
onValueChange(type, Ref3.make(newObject));
|
|
1609
1692
|
}
|
|
1693
|
+
setOpen(false);
|
|
1610
1694
|
}, [
|
|
1611
1695
|
createSchema,
|
|
1612
|
-
onCreate
|
|
1696
|
+
onCreate,
|
|
1697
|
+
type,
|
|
1698
|
+
onValueChange
|
|
1699
|
+
]);
|
|
1700
|
+
const handleUpdate = useCallback9((id) => {
|
|
1701
|
+
const item2 = options.find((option) => option.id === id);
|
|
1702
|
+
const ref = item2 ? Ref3.fromDXN(DXN.parse(item2.id)) : void 0;
|
|
1703
|
+
onValueChange(type, ref);
|
|
1704
|
+
}, [
|
|
1705
|
+
options,
|
|
1706
|
+
type,
|
|
1707
|
+
onValueChange
|
|
1613
1708
|
]);
|
|
1614
1709
|
const handleSelect = useCallback9((id) => {
|
|
1615
1710
|
if (item?.id === id) {
|
|
@@ -1631,40 +1726,46 @@ var RefField = (props) => {
|
|
|
1631
1726
|
readonly,
|
|
1632
1727
|
label
|
|
1633
1728
|
}), /* @__PURE__ */ React11.createElement("div", null, readonly ? !item ? /* @__PURE__ */ React11.createElement("p", {
|
|
1634
|
-
className:
|
|
1635
|
-
}, t("empty
|
|
1729
|
+
className: "text-description mb-2"
|
|
1730
|
+
}, t("empty-readonly-ref-field.label")) : /* @__PURE__ */ React11.createElement(DxAnchor, {
|
|
1636
1731
|
key: item.id,
|
|
1637
1732
|
dxn: item.id,
|
|
1638
1733
|
rootclassname: "me-1"
|
|
1639
|
-
}, item.label) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root,
|
|
1734
|
+
}, item.label) : /* @__PURE__ */ React11.createElement(ObjectPicker.Root, {
|
|
1735
|
+
open,
|
|
1736
|
+
onOpenChange: setOpen
|
|
1737
|
+
}, /* @__PURE__ */ React11.createElement(ObjectPicker.Trigger, {
|
|
1640
1738
|
asChild: true,
|
|
1641
1739
|
classNames: "p-0"
|
|
1642
1740
|
}, item ? /* @__PURE__ */ React11.createElement("div", {
|
|
1643
|
-
className: "flex gap-
|
|
1741
|
+
className: "flex gap-form-gap w-full"
|
|
1644
1742
|
}, /* @__PURE__ */ React11.createElement(Input6.Root, {
|
|
1645
1743
|
key: item.id
|
|
1646
1744
|
}, /* @__PURE__ */ React11.createElement(Input6.TextInput, {
|
|
1647
1745
|
value: item.label,
|
|
1648
1746
|
readOnly: true,
|
|
1649
1747
|
classNames: "w-full"
|
|
1650
|
-
}))) : /* @__PURE__ */ React11.createElement(
|
|
1651
|
-
classNames: "w-full text-start gap-
|
|
1748
|
+
}))) : /* @__PURE__ */ React11.createElement(Button2, {
|
|
1749
|
+
classNames: "w-full text-start gap-form-gap"
|
|
1652
1750
|
}, /* @__PURE__ */ React11.createElement("div", {
|
|
1653
|
-
role: "none",
|
|
1654
1751
|
className: "grow overflow-hidden"
|
|
1655
1752
|
}, /* @__PURE__ */ React11.createElement("span", {
|
|
1656
|
-
className: "
|
|
1657
|
-
}, placeholder ?? t("ref
|
|
1753
|
+
className: "truncate text-description"
|
|
1754
|
+
}, placeholder ?? t("ref-field.placeholder"))), /* @__PURE__ */ React11.createElement(Icon3, {
|
|
1658
1755
|
size: 3,
|
|
1659
1756
|
icon: "ph--caret-down--bold"
|
|
1660
1757
|
}))), /* @__PURE__ */ React11.createElement(ObjectPicker.Portal, null, /* @__PURE__ */ React11.createElement(ObjectPicker.Content, {
|
|
1661
1758
|
classNames: "dx-card-popover-width",
|
|
1662
1759
|
options,
|
|
1663
1760
|
selectedIds,
|
|
1664
|
-
|
|
1761
|
+
// Strip hidden (`FormInputAnnotation.set(false)`) fields so the
|
|
1762
|
+
// form's validator doesn't reject required-but-hidden fields
|
|
1763
|
+
// such as backing-object refs supplied by a `FactoryAnnotation`.
|
|
1764
|
+
createSchema: createSchema && omitHiddenFormFields(omitId(createSchema)),
|
|
1665
1765
|
createOptionLabel,
|
|
1666
1766
|
createOptionIcon,
|
|
1667
1767
|
createInitialValuePath,
|
|
1768
|
+
createFieldMap: createFieldMap3,
|
|
1668
1769
|
onCreate: handleCreate,
|
|
1669
1770
|
onSelect: handleSelect
|
|
1670
1771
|
})))), layout === "full" && /* @__PURE__ */ React11.createElement(Input6.DescriptionAndValidation, null, error));
|
|
@@ -1706,20 +1807,21 @@ var SelectField = ({ type, readonly, label, layout, placeholder, options, getSta
|
|
|
1706
1807
|
};
|
|
1707
1808
|
|
|
1708
1809
|
// src/components/Form/fields/SelectOptionField.tsx
|
|
1709
|
-
import React13, { useCallback as useCallback11, useEffect as
|
|
1810
|
+
import React13, { useCallback as useCallback11, useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
|
|
1710
1811
|
import { PublicKey } from "@dxos/keys";
|
|
1711
|
-
import { IconButton as IconButton3, Input as Input8, Tag, useTranslation as
|
|
1812
|
+
import { IconButton as IconButton3, Input as Input8, Tag, useTranslation as useTranslation8 } from "@dxos/react-ui";
|
|
1712
1813
|
import { List } from "@dxos/react-ui-list";
|
|
1713
1814
|
import { HuePicker } from "@dxos/react-ui-pickers";
|
|
1714
1815
|
import { hues, osTranslations, subtleHover } from "@dxos/ui-theme";
|
|
1816
|
+
import { translationKey as translationKey8 } from "#translations";
|
|
1715
1817
|
var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueChange }) => {
|
|
1716
|
-
const { t } =
|
|
1818
|
+
const { t } = useTranslation8(translationKey8);
|
|
1717
1819
|
const { status, error } = getStatus();
|
|
1718
|
-
const [selected, setSelectedId] =
|
|
1719
|
-
const [isNewOption, setIsNewOption] =
|
|
1720
|
-
const inputRef =
|
|
1820
|
+
const [selected, setSelectedId] = useState5(null);
|
|
1821
|
+
const [isNewOption, setIsNewOption] = useState5(false);
|
|
1822
|
+
const inputRef = useRef2(null);
|
|
1721
1823
|
const options = getValue();
|
|
1722
|
-
|
|
1824
|
+
useEffect4(() => {
|
|
1723
1825
|
if (options === void 0) {
|
|
1724
1826
|
onValueChange(type, []);
|
|
1725
1827
|
}
|
|
@@ -1810,7 +1912,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1810
1912
|
type,
|
|
1811
1913
|
onValueChange
|
|
1812
1914
|
]);
|
|
1813
|
-
|
|
1915
|
+
useEffect4(() => {
|
|
1814
1916
|
if (selected && isNewOption && inputRef.current) {
|
|
1815
1917
|
inputRef.current.focus();
|
|
1816
1918
|
setIsNewOption(false);
|
|
@@ -1825,9 +1927,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1825
1927
|
error,
|
|
1826
1928
|
readonly,
|
|
1827
1929
|
label
|
|
1828
|
-
}), /* @__PURE__ */ React13.createElement("div", {
|
|
1829
|
-
role: "none"
|
|
1830
|
-
}, options && /* @__PURE__ */ React13.createElement(List.Root, {
|
|
1930
|
+
}), /* @__PURE__ */ React13.createElement("div", null, options && /* @__PURE__ */ React13.createElement(List.Root, {
|
|
1831
1931
|
items: options,
|
|
1832
1932
|
isItem: (_item) => true,
|
|
1833
1933
|
onMove: readonly ? void 0 : handleMove,
|
|
@@ -1857,20 +1957,20 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1857
1957
|
}, item.title || "\u200B")), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1858
1958
|
iconOnly: true,
|
|
1859
1959
|
variant: "ghost",
|
|
1860
|
-
label: t(selected === item.id ? "collapse
|
|
1960
|
+
label: t(selected === item.id ? "collapse.label" : "expand.label", {
|
|
1861
1961
|
ns: osTranslations
|
|
1862
1962
|
}),
|
|
1863
1963
|
icon: selected === item.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
1864
1964
|
onClick: () => handleClick(item.id)
|
|
1865
1965
|
})), selected === item.id && /* @__PURE__ */ React13.createElement("div", {
|
|
1866
|
-
className: "flex flex-col p-form-padding gap-
|
|
1966
|
+
className: "flex flex-col p-form-padding gap-form-gap dx-density-fine"
|
|
1867
1967
|
}, /* @__PURE__ */ React13.createElement(Input8.Label, {
|
|
1868
1968
|
classNames: "text-xs"
|
|
1869
|
-
}, t("select
|
|
1870
|
-
className: "grid grid-cols-[1fr_min-content_min-content] gap-
|
|
1969
|
+
}, t("select-option.label")), /* @__PURE__ */ React13.createElement("div", {
|
|
1970
|
+
className: "grid grid-cols-[1fr_min-content_min-content] gap-form-gap"
|
|
1871
1971
|
}, /* @__PURE__ */ React13.createElement(Input8.TextInput, {
|
|
1872
1972
|
disabled: !!readonly,
|
|
1873
|
-
placeholder: t("select
|
|
1973
|
+
placeholder: t("select-option-label.placeholder"),
|
|
1874
1974
|
ref: selected === item.id ? inputRef : void 0,
|
|
1875
1975
|
value: item.title,
|
|
1876
1976
|
onChange: handleTitleChange(item.id),
|
|
@@ -1884,12 +1984,12 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1884
1984
|
disabled: !!readonly,
|
|
1885
1985
|
icon: "ph--trash--fill",
|
|
1886
1986
|
iconOnly: true,
|
|
1887
|
-
label: t("select
|
|
1987
|
+
label: t("select-option-delete.button"),
|
|
1888
1988
|
onClick: () => handleDelete(item.id)
|
|
1889
1989
|
})))))), /* @__PURE__ */ React13.createElement(IconButton3, {
|
|
1890
1990
|
variant: "ghost",
|
|
1891
1991
|
icon: "ph--plus--regular",
|
|
1892
|
-
label: t("select
|
|
1992
|
+
label: t("select-option-add.button"),
|
|
1893
1993
|
onClick: handleAdd,
|
|
1894
1994
|
disabled: !!readonly,
|
|
1895
1995
|
classNames: "w-full"
|
|
@@ -1899,7 +1999,7 @@ var SelectOptionField = ({ type, readonly, label, getStatus, getValue, onValueCh
|
|
|
1899
1999
|
// src/components/Form/fields/TextField.tsx
|
|
1900
2000
|
import React14, { useCallback as useCallback12 } from "react";
|
|
1901
2001
|
import { Input as Input9 } from "@dxos/react-ui";
|
|
1902
|
-
var TextField = ({ type, readonly, placeholder,
|
|
2002
|
+
var TextField = ({ type, readonly, placeholder, onBlur, onValueChange, ...props }) => {
|
|
1903
2003
|
const handleChange = useCallback12((event) => onValueChange(type, event.target.value), [
|
|
1904
2004
|
type,
|
|
1905
2005
|
onValueChange
|
|
@@ -1912,8 +2012,8 @@ var TextField = ({ type, readonly, placeholder, onValueChange, onBlur, ...props
|
|
|
1912
2012
|
disabled: !!readonly,
|
|
1913
2013
|
placeholder,
|
|
1914
2014
|
value: value3,
|
|
1915
|
-
|
|
1916
|
-
|
|
2015
|
+
onBlur,
|
|
2016
|
+
onChange: handleChange
|
|
1917
2017
|
}));
|
|
1918
2018
|
};
|
|
1919
2019
|
|
|
@@ -1941,7 +2041,7 @@ var TextAreaField = ({ type, readonly, placeholder, onValueChange, onBlur, ...pr
|
|
|
1941
2041
|
// src/components/Form/fields/TupleField.tsx
|
|
1942
2042
|
import React16 from "react";
|
|
1943
2043
|
import { Input as Input11 } from "@dxos/react-ui";
|
|
1944
|
-
import { mx as
|
|
2044
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1945
2045
|
import { safeParseFloat as safeParseFloat3 } from "@dxos/util";
|
|
1946
2046
|
var gridCols = [
|
|
1947
2047
|
"grid-cols-1",
|
|
@@ -1959,7 +2059,7 @@ var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValue
|
|
|
1959
2059
|
readonly,
|
|
1960
2060
|
label
|
|
1961
2061
|
}), /* @__PURE__ */ React16.createElement("div", {
|
|
1962
|
-
className:
|
|
2062
|
+
className: mx2("grid gap-form-gap", gridCols[binding.length - 1])
|
|
1963
2063
|
}, binding.map((prop) => /* @__PURE__ */ React16.createElement(Input11.TextInput, {
|
|
1964
2064
|
key: prop,
|
|
1965
2065
|
type: "number",
|
|
@@ -1978,13 +2078,13 @@ var TupleField = ({ binding, type, readonly, label, getStatus, getValue, onValue
|
|
|
1978
2078
|
// src/components/FieldEditor/FieldEditor.tsx
|
|
1979
2079
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/FieldEditor/FieldEditor.tsx";
|
|
1980
2080
|
var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }) => {
|
|
1981
|
-
const { t } =
|
|
1982
|
-
const [props, setProps] =
|
|
1983
|
-
|
|
2081
|
+
const { t } = useTranslation9(translationKey9);
|
|
2082
|
+
const [props, setProps] = useState6(projection.getFieldProjection(field.id).props);
|
|
2083
|
+
useEffect5(() => setProps(projection.getFieldProjection(field.id).props), [
|
|
1984
2084
|
field,
|
|
1985
2085
|
projection
|
|
1986
2086
|
]);
|
|
1987
|
-
const [schemas, setSchemas] =
|
|
2087
|
+
const [schemas, setSchemas] = useState6([]);
|
|
1988
2088
|
useAsyncEffect(async () => {
|
|
1989
2089
|
if (!registry) {
|
|
1990
2090
|
return;
|
|
@@ -1998,22 +2098,22 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
1998
2098
|
}, [
|
|
1999
2099
|
registry
|
|
2000
2100
|
]);
|
|
2001
|
-
const [referenceSchema, setReferenceSchema] =
|
|
2002
|
-
|
|
2101
|
+
const [referenceSchema, setReferenceSchema] = useState6();
|
|
2102
|
+
useEffect5(() => {
|
|
2003
2103
|
setReferenceSchema(schemas.find((schema) => schema.typename === props?.referenceSchema));
|
|
2004
2104
|
}, [
|
|
2005
2105
|
schemas,
|
|
2006
2106
|
props?.referenceSchema
|
|
2007
2107
|
]);
|
|
2008
|
-
const [{ fieldSchema }, setFieldSchema] =
|
|
2108
|
+
const [{ fieldSchema }, setFieldSchema] = useState6({
|
|
2009
2109
|
fieldSchema: getFormatSchema(props?.format)
|
|
2010
2110
|
});
|
|
2011
|
-
const fieldMap =
|
|
2111
|
+
const fieldMap = useMemo8(() => ({
|
|
2012
2112
|
["format"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
2013
2113
|
...props2,
|
|
2014
2114
|
options: FormatEnums.filter((value3) => value3 !== Format4.TypeFormat.None).map((value3) => ({
|
|
2015
2115
|
value: value3,
|
|
2016
|
-
label: t(`format
|
|
2116
|
+
label: t(`format.${value3}.label`)
|
|
2017
2117
|
}))
|
|
2018
2118
|
}),
|
|
2019
2119
|
["referenceSchema"]: (props2) => /* @__PURE__ */ React17.createElement(SelectField, {
|
|
@@ -2087,7 +2187,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2087
2187
|
]);
|
|
2088
2188
|
const handleSave = useCallback14((props2) => {
|
|
2089
2189
|
if (view) {
|
|
2090
|
-
|
|
2190
|
+
Obj3.update(view, () => {
|
|
2091
2191
|
projection.setFieldProjection({
|
|
2092
2192
|
field,
|
|
2093
2193
|
props: props2
|
|
@@ -2115,12 +2215,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2115
2215
|
if (!fieldSchema) {
|
|
2116
2216
|
log2.warn("invalid format", {
|
|
2117
2217
|
props
|
|
2118
|
-
}, {
|
|
2119
|
-
F: __dxlog_file2,
|
|
2120
|
-
L: 172,
|
|
2121
|
-
S: void 0,
|
|
2122
|
-
C: (f, a) => f(...a)
|
|
2123
|
-
});
|
|
2218
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 156, S: void 0 });
|
|
2124
2219
|
return null;
|
|
2125
2220
|
}
|
|
2126
2221
|
return /* @__PURE__ */ React17.createElement(Form.Root, {
|
|
@@ -2142,160 +2237,488 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
|
|
|
2142
2237
|
}, /* @__PURE__ */ React17.createElement(Form.Content, null, /* @__PURE__ */ React17.createElement(Form.FieldSet, null), /* @__PURE__ */ React17.createElement(Form.Actions, null)));
|
|
2143
2238
|
};
|
|
2144
2239
|
|
|
2145
|
-
// src/components/
|
|
2146
|
-
import
|
|
2147
|
-
import
|
|
2148
|
-
import {
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
var
|
|
2155
|
-
var
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
};
|
|
2172
|
-
|
|
2173
|
-
var SettingsSection = ({ title, description, children }) => {
|
|
2174
|
-
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(SettingsSectionHeading, {
|
|
2175
|
-
title,
|
|
2176
|
-
description
|
|
2177
|
-
}), /* @__PURE__ */ React18.createElement("div", {
|
|
2178
|
-
className: "w-full pt-trim-md space-y-trim-md"
|
|
2179
|
-
}, children));
|
|
2180
|
-
};
|
|
2181
|
-
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
2182
|
-
var SettingsSectionHeading = ({ title, description }) => {
|
|
2183
|
-
const { t } = useTranslation9(translationKey);
|
|
2184
|
-
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement("h2", {
|
|
2185
|
-
className: "px-trim-md mt-trim-md mb-trim-md text-xl"
|
|
2186
|
-
}, toLocalizedString(title, t)), description && /* @__PURE__ */ React18.createElement("p", {
|
|
2187
|
-
className: "px-trim-md my-trim-md text-description"
|
|
2188
|
-
}, toLocalizedString(description, t)));
|
|
2240
|
+
// src/components/ObjectForm/ObjectForm.tsx
|
|
2241
|
+
import * as Schema3 from "effect/Schema";
|
|
2242
|
+
import React18, { useCallback as useCallback15, useMemo as useMemo9 } from "react";
|
|
2243
|
+
import { DXN as DXN2, Obj as Obj4, Ref as Ref4, Tag as Tag2, Type as Type2 } from "@dxos/echo";
|
|
2244
|
+
import { splitJsonPath } from "@dxos/echo/internal";
|
|
2245
|
+
import { invariant } from "@dxos/invariant";
|
|
2246
|
+
import { HuePicker as HuePicker2 } from "@dxos/react-ui-pickers";
|
|
2247
|
+
import { isNonNullable } from "@dxos/util";
|
|
2248
|
+
import { translationKey as translationKey10 } from "#translations";
|
|
2249
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ObjectForm/ObjectForm.tsx";
|
|
2250
|
+
var createFieldMap = {
|
|
2251
|
+
hue: ({ type, label, layout, getValue, onValueChange }) => {
|
|
2252
|
+
const handleChange = useCallback15((nextHue) => onValueChange(type, nextHue), [
|
|
2253
|
+
onValueChange,
|
|
2254
|
+
type
|
|
2255
|
+
]);
|
|
2256
|
+
const handleReset = useCallback15(() => onValueChange(type, void 0), [
|
|
2257
|
+
onValueChange,
|
|
2258
|
+
type
|
|
2259
|
+
]);
|
|
2260
|
+
return /* @__PURE__ */ React18.createElement(React18.Fragment, null, layout !== "inline" && /* @__PURE__ */ React18.createElement(Form.Label, {
|
|
2261
|
+
label
|
|
2262
|
+
}), /* @__PURE__ */ React18.createElement(HuePicker2, {
|
|
2263
|
+
value: getValue(),
|
|
2264
|
+
onChange: handleChange,
|
|
2265
|
+
onReset: handleReset
|
|
2266
|
+
}));
|
|
2267
|
+
}
|
|
2189
2268
|
};
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2269
|
+
var ObjectForm = ({ object, schema }) => {
|
|
2270
|
+
const db = Obj4.getDatabase(object);
|
|
2271
|
+
const meta = Obj4.getMeta(object);
|
|
2272
|
+
const tags = (meta.tags ?? []).map((tag) => db?.makeRef(DXN2.parse(tag))).filter(isNonNullable);
|
|
2273
|
+
const values = useMemo9(() => ({
|
|
2274
|
+
tags,
|
|
2275
|
+
...object
|
|
2276
|
+
}), [
|
|
2277
|
+
object,
|
|
2278
|
+
tags
|
|
2279
|
+
]);
|
|
2280
|
+
const formSchema = useMemo9(() => omitId(Schema3.Struct({
|
|
2281
|
+
tags: Schema3.Array(Ref4.Ref(Tag2.Tag)).pipe(Schema3.optional)
|
|
2282
|
+
}).pipe(Schema3.extend(schema))), [
|
|
2283
|
+
schema
|
|
2284
|
+
]);
|
|
2285
|
+
const handleCreate = useCallback15((schema2, values2) => {
|
|
2286
|
+
invariant(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 49, S: void 0, A: ["db", ""] });
|
|
2287
|
+
invariant(Type2.isObjectSchema(schema2), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 50, S: void 0, A: ["Type.isObjectSchema(schema)", ""] });
|
|
2288
|
+
const newObject = db.add(Obj4.make(schema2, values2));
|
|
2289
|
+
if (Obj4.instanceOf(Tag2.Tag, newObject)) {
|
|
2290
|
+
Obj4.update(object, (object2) => {
|
|
2291
|
+
Obj4.getMeta(object2).tags = [
|
|
2292
|
+
...Obj4.getMeta(object2).tags ?? [],
|
|
2293
|
+
Obj4.getDXN(newObject).toString()
|
|
2294
|
+
];
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
}, []);
|
|
2298
|
+
const handleChange = useCallback15(({ tags: tags2, ...values2 }, { isValid, changed }) => {
|
|
2299
|
+
if (!isValid) {
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
const changedPaths = Object.keys(changed).filter((path) => changed[path]);
|
|
2303
|
+
const hasTagsChange = changedPaths.some((path) => splitJsonPath(path)[0] === "tags");
|
|
2304
|
+
if (hasTagsChange) {
|
|
2305
|
+
Obj4.update(object, (object2) => {
|
|
2306
|
+
Obj4.getMeta(object2).tags = tags2?.map((tag) => tag.dxn.toString()) ?? [];
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
const nonTagPaths = changedPaths.filter((path) => splitJsonPath(path)[0] !== "tags");
|
|
2310
|
+
if (nonTagPaths.length > 0) {
|
|
2311
|
+
Obj4.update(object, () => {
|
|
2312
|
+
for (const path of nonTagPaths) {
|
|
2313
|
+
const parts = splitJsonPath(path);
|
|
2314
|
+
const value3 = Obj4.getValue(values2, parts);
|
|
2315
|
+
Obj4.setValue(object, parts, value3);
|
|
2316
|
+
}
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
}, [
|
|
2320
|
+
object
|
|
2321
|
+
]);
|
|
2322
|
+
return /* @__PURE__ */ React18.createElement(Form.Root, {
|
|
2323
|
+
schema: formSchema,
|
|
2324
|
+
defaultValues: values,
|
|
2325
|
+
createTypename: Type2.getTypename(Tag2.Tag),
|
|
2326
|
+
createOptionIcon: "ph--plus--regular",
|
|
2327
|
+
createOptionLabel: [
|
|
2328
|
+
"add-tag.label",
|
|
2329
|
+
{
|
|
2330
|
+
ns: translationKey10
|
|
2331
|
+
}
|
|
2332
|
+
],
|
|
2333
|
+
createInitialValuePath: "label",
|
|
2334
|
+
createFieldMap,
|
|
2335
|
+
db,
|
|
2336
|
+
onValuesChanged: handleChange,
|
|
2337
|
+
onCreate: handleCreate
|
|
2338
|
+
}, /* @__PURE__ */ React18.createElement(Form.Viewport, null, /* @__PURE__ */ React18.createElement(Form.Content, null, /* @__PURE__ */ React18.createElement(Form.FieldSet, null))));
|
|
2199
2339
|
};
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2340
|
+
|
|
2341
|
+
// src/components/ObjectProperties/ObjectProperties.tsx
|
|
2342
|
+
import * as Function from "effect/Function";
|
|
2343
|
+
import * as Option5 from "effect/Option";
|
|
2344
|
+
import * as Schema4 from "effect/Schema";
|
|
2345
|
+
import React19, { useCallback as useCallback16, useMemo as useMemo10 } from "react";
|
|
2346
|
+
import { DXN as DXN3, Obj as Obj5, Ref as Ref5, Tag as Tag3, Type as Type3 } from "@dxos/echo";
|
|
2347
|
+
import { splitJsonPath as splitJsonPath2 } from "@dxos/echo/internal";
|
|
2348
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2349
|
+
import { HuePicker as HuePicker3 } from "@dxos/react-ui-pickers";
|
|
2350
|
+
import { FactoryAnnotation } from "@dxos/schema";
|
|
2351
|
+
import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
|
|
2352
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2353
|
+
import { translationKey as translationKey11 } from "#translations";
|
|
2354
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ObjectProperties/ObjectProperties.tsx";
|
|
2355
|
+
var ObjectProperties = composable2(({ children, object, ...props }, forwardedRef) => {
|
|
2356
|
+
const db = Obj5.getDatabase(object);
|
|
2357
|
+
const meta = Obj5.getMeta(object);
|
|
2358
|
+
const tags = (meta.tags ?? []).map((tag) => db?.makeRef(DXN3.parse(tag))).filter(isNonNullable2);
|
|
2359
|
+
const values = useMemo10(() => ({
|
|
2360
|
+
tags,
|
|
2361
|
+
...object
|
|
2362
|
+
}), [
|
|
2363
|
+
object,
|
|
2364
|
+
tags
|
|
2365
|
+
]);
|
|
2366
|
+
const formSchema = useMemo10(() => {
|
|
2367
|
+
return Function.pipe(Obj5.getSchema(object), Option5.fromNullable, Option5.map((schema) => omitId(BaseSchema.pipe(Schema4.extend(schema)))), Option5.getOrUndefined);
|
|
2368
|
+
}, [
|
|
2369
|
+
object
|
|
2370
|
+
]);
|
|
2371
|
+
const handleCreate = useCallback16((schema, values2) => {
|
|
2372
|
+
invariant2(db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 45, S: void 0, A: ["db", ""] });
|
|
2373
|
+
invariant2(Type3.isObjectSchema(schema), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 46, S: void 0, A: ["Type.isObjectSchema(schema)", ""] });
|
|
2374
|
+
const factory = Option5.getOrUndefined(FactoryAnnotation.get(schema));
|
|
2375
|
+
const newObject = factory ? factory(values2) : Obj5.make(schema, values2);
|
|
2376
|
+
return db.add(newObject);
|
|
2377
|
+
}, [
|
|
2378
|
+
db
|
|
2379
|
+
]);
|
|
2380
|
+
const handleChange = useCallback16(({ tags: tags2, ...values2 }, { isValid, changed }) => {
|
|
2381
|
+
if (!isValid) {
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
const changedPaths = Object.keys(changed).filter((path) => changed[path]);
|
|
2385
|
+
const hasTagsChange = changedPaths.some((path) => splitJsonPath2(path)[0] === "tags");
|
|
2386
|
+
if (hasTagsChange) {
|
|
2387
|
+
Obj5.update(object, (object2) => {
|
|
2388
|
+
Obj5.getMeta(object2).tags = tags2?.map((tag) => tag.dxn.toString()) ?? [];
|
|
2389
|
+
});
|
|
2390
|
+
}
|
|
2391
|
+
const nonTagPaths = changedPaths.filter((path) => splitJsonPath2(path)[0] !== "tags");
|
|
2392
|
+
if (nonTagPaths.length > 0) {
|
|
2393
|
+
Obj5.update(object, () => {
|
|
2394
|
+
for (const path of nonTagPaths) {
|
|
2395
|
+
const parts = splitJsonPath2(path);
|
|
2396
|
+
const value3 = Obj5.getValue(values2, parts);
|
|
2397
|
+
Obj5.setValue(object, parts, value3);
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
}, [
|
|
2402
|
+
object
|
|
2403
|
+
]);
|
|
2404
|
+
if (!formSchema) {
|
|
2405
|
+
return null;
|
|
2406
|
+
}
|
|
2407
|
+
return /* @__PURE__ */ React19.createElement(Form.Root, {
|
|
2408
|
+
schema: formSchema,
|
|
2409
|
+
defaultValues: values,
|
|
2410
|
+
createTypename: Type3.getTypename(Tag3.Tag),
|
|
2411
|
+
createOptionIcon: "ph--plus--regular",
|
|
2412
|
+
createOptionLabel: [
|
|
2413
|
+
"add-tag.label",
|
|
2414
|
+
{
|
|
2415
|
+
ns: translationKey11
|
|
2416
|
+
}
|
|
2417
|
+
],
|
|
2418
|
+
createInitialValuePath: "label",
|
|
2419
|
+
createFieldMap: createFieldMap2,
|
|
2420
|
+
db,
|
|
2421
|
+
onValuesChanged: handleChange,
|
|
2422
|
+
onCreate: handleCreate
|
|
2423
|
+
}, /* @__PURE__ */ React19.createElement(Form.Viewport, {
|
|
2424
|
+
...composableProps2(props),
|
|
2425
|
+
ref: forwardedRef
|
|
2426
|
+
}, /* @__PURE__ */ React19.createElement(Form.Content, null, /* @__PURE__ */ React19.createElement(Form.FieldSet, null), children)));
|
|
2427
|
+
});
|
|
2428
|
+
var createFieldMap2 = {
|
|
2429
|
+
hue: ({ type, label, layout, getValue, onValueChange }) => {
|
|
2430
|
+
const handleChange = useCallback16((nextHue) => onValueChange(type, nextHue), [
|
|
2431
|
+
onValueChange,
|
|
2432
|
+
type
|
|
2433
|
+
]);
|
|
2434
|
+
const handleReset = useCallback16(() => onValueChange(type, void 0), [
|
|
2435
|
+
onValueChange,
|
|
2436
|
+
type
|
|
2437
|
+
]);
|
|
2438
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, layout !== "inline" && /* @__PURE__ */ React19.createElement(Form.Label, {
|
|
2439
|
+
label
|
|
2440
|
+
}), /* @__PURE__ */ React19.createElement(HuePicker3, {
|
|
2441
|
+
value: getValue(),
|
|
2442
|
+
onChange: handleChange,
|
|
2443
|
+
onReset: handleReset
|
|
2444
|
+
}));
|
|
2445
|
+
}
|
|
2221
2446
|
};
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2447
|
+
var BaseSchema = Schema4.Struct({
|
|
2448
|
+
tags: Schema4.Array(Ref5.Ref(Tag3.Tag)).pipe(Schema4.optional)
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
// src/components/Settings/Settings.tsx
|
|
2452
|
+
import React22 from "react";
|
|
2453
|
+
import { ScrollArea as ScrollArea2, toLocalizedString as toLocalizedString2, useTranslation as useTranslation11 } from "@dxos/react-ui";
|
|
2454
|
+
import { composable as composable3, composableProps as composableProps3, mx as mx4 } from "@dxos/ui-theme";
|
|
2455
|
+
import { translationKey as translationKey13 } from "#translations";
|
|
2456
|
+
|
|
2457
|
+
// src/components/Settings/SettingsFieldSet.tsx
|
|
2458
|
+
import * as SchemaAST5 from "effect/SchemaAST";
|
|
2459
|
+
import * as String3 from "effect/String";
|
|
2460
|
+
import React21, { useCallback as useCallback17, useMemo as useMemo11 } from "react";
|
|
2461
|
+
import { getAnnotation as getAnnotation3 } from "@dxos/effect";
|
|
2462
|
+
import { Input as Input13, Select as Select2 } from "@dxos/react-ui";
|
|
2463
|
+
|
|
2464
|
+
// src/components/Settings/SettingsItem.tsx
|
|
2465
|
+
import React20 from "react";
|
|
2466
|
+
import { Input as Input12, toLocalizedString, useTranslation as useTranslation10 } from "@dxos/react-ui";
|
|
2467
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2468
|
+
import { translationKey as translationKey12 } from "#translations";
|
|
2469
|
+
var SETTINGS_PANEL_NAME = "Settings.Panel";
|
|
2470
|
+
var SETTINGS_ITEM_NAME = "Settings.Item";
|
|
2471
|
+
var SettingsPanel = ({ classNames, children }) => {
|
|
2472
|
+
return /* @__PURE__ */ React20.createElement("div", {
|
|
2473
|
+
className: mx3("flex flex-col gap-3 p-trim-md border border-separator rounded-sm", classNames)
|
|
2232
2474
|
}, children);
|
|
2233
2475
|
};
|
|
2234
|
-
|
|
2476
|
+
SettingsPanel.displayName = SETTINGS_PANEL_NAME;
|
|
2235
2477
|
var SettingsItem = ({ title, description = "", children }) => {
|
|
2236
|
-
const { t } =
|
|
2237
|
-
return /* @__PURE__ */
|
|
2238
|
-
classNames:
|
|
2239
|
-
}, /* @__PURE__ */
|
|
2240
|
-
|
|
2241
|
-
}, toLocalizedString(title, t)), /* @__PURE__ */
|
|
2242
|
-
|
|
2243
|
-
}, toLocalizedString(description, t)), /* @__PURE__ */
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
}, children));
|
|
2478
|
+
const { t } = useTranslation10(translationKey12);
|
|
2479
|
+
return /* @__PURE__ */ React20.createElement(Input12.Root, null, /* @__PURE__ */ React20.createElement(SettingsPanel, {
|
|
2480
|
+
classNames: "grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0"
|
|
2481
|
+
}, /* @__PURE__ */ React20.createElement(Input12.Label, {
|
|
2482
|
+
classNames: "pb-trim-md text-base-surface-text text-lg md:col-span-2"
|
|
2483
|
+
}, toLocalizedString(title, t)), /* @__PURE__ */ React20.createElement(Input12.DescriptionAndValidation, null, /* @__PURE__ */ React20.createElement(Input12.Description, {
|
|
2484
|
+
classNames: "text-base text-description"
|
|
2485
|
+
}, toLocalizedString(description, t))), /* @__PURE__ */ React20.createElement("div", {
|
|
2486
|
+
className: "text-end py-1"
|
|
2487
|
+
}, children)));
|
|
2247
2488
|
};
|
|
2248
2489
|
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2490
|
+
|
|
2491
|
+
// src/components/Settings/SettingsFieldSet.tsx
|
|
2492
|
+
var SettingsFieldSet = ({ schema, values, onValuesChanged, readonly, fieldMap, visible, sort, pathPrefix = "" }) => {
|
|
2493
|
+
const properties = useMemo11(() => {
|
|
2494
|
+
const props = getFormProperties(schema.ast);
|
|
2495
|
+
if (!sort) {
|
|
2496
|
+
return props;
|
|
2497
|
+
}
|
|
2498
|
+
const rank = (name) => {
|
|
2499
|
+
const idx = sort.indexOf(name);
|
|
2500
|
+
return idx === -1 ? Number.POSITIVE_INFINITY : idx;
|
|
2501
|
+
};
|
|
2502
|
+
return [
|
|
2503
|
+
...props
|
|
2504
|
+
].sort(({ name: a }, { name: b }) => rank(a.toString()) - rank(b.toString()));
|
|
2505
|
+
}, [
|
|
2506
|
+
schema,
|
|
2507
|
+
sort
|
|
2508
|
+
]);
|
|
2509
|
+
const handleChange = useCallback17((name, value3) => {
|
|
2510
|
+
onValuesChanged?.({
|
|
2511
|
+
...values,
|
|
2512
|
+
[name]: value3
|
|
2513
|
+
});
|
|
2514
|
+
}, [
|
|
2515
|
+
values,
|
|
2516
|
+
onValuesChanged
|
|
2517
|
+
]);
|
|
2518
|
+
return /* @__PURE__ */ React21.createElement(React21.Fragment, null, properties.map((property) => {
|
|
2519
|
+
const name = property.name.toString();
|
|
2520
|
+
const path = pathPrefix ? `${pathPrefix}.${name}` : name;
|
|
2521
|
+
if (visible && !visible(path, values)) {
|
|
2522
|
+
return null;
|
|
2523
|
+
}
|
|
2524
|
+
const entry = fieldMap?.[name];
|
|
2525
|
+
return /* @__PURE__ */ React21.createElement(SettingsFieldItem, {
|
|
2526
|
+
key: name,
|
|
2527
|
+
path,
|
|
2528
|
+
property,
|
|
2529
|
+
value: values[name],
|
|
2530
|
+
onChange: (value3) => handleChange(name, value3),
|
|
2531
|
+
readonly,
|
|
2532
|
+
customField: typeof entry === "function" ? entry : void 0,
|
|
2533
|
+
nestedFieldMap: typeof entry === "object" ? entry : void 0,
|
|
2534
|
+
visible,
|
|
2535
|
+
sort
|
|
2536
|
+
});
|
|
2537
|
+
}));
|
|
2538
|
+
};
|
|
2539
|
+
SettingsFieldSet.displayName = "Settings.FieldSet";
|
|
2540
|
+
var SettingsFieldItem = ({ property, path, value: value3, onChange, readonly, customField, nestedFieldMap, visible, sort }) => {
|
|
2541
|
+
const { type } = property;
|
|
2542
|
+
const name = property.name.toString();
|
|
2543
|
+
const title = getAnnotation3(SchemaAST5.TitleAnnotationId)(type) ?? String3.capitalize(name);
|
|
2544
|
+
const description = getAnnotation3(SchemaAST5.DescriptionAnnotationId)(type);
|
|
2545
|
+
if (customField) {
|
|
2546
|
+
const CustomField = customField;
|
|
2547
|
+
return /* @__PURE__ */ React21.createElement(SettingsItem, {
|
|
2548
|
+
title,
|
|
2549
|
+
description
|
|
2550
|
+
}, /* @__PURE__ */ React21.createElement(CustomField, {
|
|
2551
|
+
value: value3,
|
|
2552
|
+
onChange,
|
|
2553
|
+
readonly
|
|
2554
|
+
}));
|
|
2555
|
+
}
|
|
2556
|
+
const fieldType = detectFieldType(type);
|
|
2557
|
+
switch (fieldType) {
|
|
2558
|
+
case "struct":
|
|
2559
|
+
return /* @__PURE__ */ React21.createElement(SettingsFieldSet, {
|
|
2560
|
+
schema: {
|
|
2561
|
+
ast: type
|
|
2562
|
+
},
|
|
2563
|
+
values: value3 ?? {},
|
|
2564
|
+
onValuesChanged: onChange,
|
|
2565
|
+
readonly,
|
|
2566
|
+
fieldMap: nestedFieldMap,
|
|
2567
|
+
visible,
|
|
2568
|
+
sort,
|
|
2569
|
+
pathPrefix: path
|
|
2570
|
+
});
|
|
2571
|
+
case "boolean":
|
|
2572
|
+
return /* @__PURE__ */ React21.createElement(SettingsItem, {
|
|
2573
|
+
title,
|
|
2574
|
+
description
|
|
2575
|
+
}, /* @__PURE__ */ React21.createElement(Input13.Switch, {
|
|
2576
|
+
disabled: readonly,
|
|
2577
|
+
checked: !!value3,
|
|
2578
|
+
onCheckedChange: (checked) => onChange(!!checked)
|
|
2579
|
+
}));
|
|
2580
|
+
case "select": {
|
|
2581
|
+
const options = getSelectOptionsFromAst(type) ?? [];
|
|
2582
|
+
return /* @__PURE__ */ React21.createElement(SettingsItem, {
|
|
2583
|
+
title,
|
|
2584
|
+
description
|
|
2585
|
+
}, /* @__PURE__ */ React21.createElement(Select2.Root, {
|
|
2586
|
+
disabled: readonly,
|
|
2587
|
+
value: value3 == null ? "" : globalThis.String(value3),
|
|
2588
|
+
onValueChange: (selected) => {
|
|
2589
|
+
const matched = options.find((option) => globalThis.String(option.value) === selected);
|
|
2590
|
+
onChange(matched?.value ?? selected);
|
|
2591
|
+
}
|
|
2592
|
+
}, /* @__PURE__ */ React21.createElement(Select2.TriggerButton, {
|
|
2593
|
+
disabled: readonly
|
|
2594
|
+
}), /* @__PURE__ */ React21.createElement(Select2.Portal, null, /* @__PURE__ */ React21.createElement(Select2.Content, null, /* @__PURE__ */ React21.createElement(Select2.Viewport, null, options.map((option) => /* @__PURE__ */ React21.createElement(Select2.Option, {
|
|
2595
|
+
key: globalThis.String(option.value),
|
|
2596
|
+
value: globalThis.String(option.value)
|
|
2597
|
+
}, option.label ?? globalThis.String(option.value)))), /* @__PURE__ */ React21.createElement(Select2.Arrow, null)))));
|
|
2598
|
+
}
|
|
2599
|
+
case "string":
|
|
2600
|
+
return /* @__PURE__ */ React21.createElement(SettingsItem, {
|
|
2601
|
+
title,
|
|
2602
|
+
description
|
|
2603
|
+
}, /* @__PURE__ */ React21.createElement(Input13.TextInput, {
|
|
2604
|
+
disabled: readonly,
|
|
2605
|
+
value: value3 ?? "",
|
|
2606
|
+
onChange: (event) => onChange(event.target.value)
|
|
2607
|
+
}));
|
|
2608
|
+
case "number":
|
|
2609
|
+
return /* @__PURE__ */ React21.createElement(SettingsItem, {
|
|
2610
|
+
title,
|
|
2611
|
+
description
|
|
2612
|
+
}, /* @__PURE__ */ React21.createElement(Input13.TextInput, {
|
|
2613
|
+
disabled: readonly,
|
|
2614
|
+
type: "number",
|
|
2615
|
+
value: value3 ?? "",
|
|
2616
|
+
onChange: (event) => {
|
|
2617
|
+
if (event.target.value === "") {
|
|
2618
|
+
onChange(void 0);
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
const parsed = Number(event.target.value);
|
|
2622
|
+
onChange(Number.isNaN(parsed) ? void 0 : parsed);
|
|
2623
|
+
}
|
|
2624
|
+
}));
|
|
2625
|
+
default:
|
|
2626
|
+
return null;
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
|
|
2630
|
+
// src/components/Settings/Settings.tsx
|
|
2631
|
+
var SETTINGS_ROOT_NAME = "Settings.Root";
|
|
2632
|
+
var SETTINGS_VIEWPORT_NAME = "Settings.Viewport";
|
|
2633
|
+
var SETTINGS_SECTION_NAME = "Settings.Section";
|
|
2634
|
+
var SettingsRoot = ({ children, classNames }) => {
|
|
2635
|
+
return /* @__PURE__ */ React22.createElement("div", {
|
|
2636
|
+
className: mx4("flex flex-col gap-2", classNames)
|
|
2637
|
+
}, children);
|
|
2638
|
+
};
|
|
2639
|
+
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
2640
|
+
var SettingsViewport = composable3(({ children, ...props }, forwardedRef) => {
|
|
2641
|
+
return /* @__PURE__ */ React22.createElement(ScrollArea2.Root, {
|
|
2642
|
+
...composableProps3(props),
|
|
2643
|
+
orientation: "vertical",
|
|
2644
|
+
centered: true,
|
|
2645
|
+
thin: true,
|
|
2646
|
+
ref: forwardedRef
|
|
2647
|
+
}, /* @__PURE__ */ React22.createElement(ScrollArea2.Viewport, {
|
|
2648
|
+
classNames: "px-4 pointer-coarse:px-2"
|
|
2649
|
+
}, /* @__PURE__ */ React22.createElement("div", {
|
|
2650
|
+
className: "dx-document flex flex-col gap-2 py-4"
|
|
2260
2651
|
}, children)));
|
|
2652
|
+
});
|
|
2653
|
+
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
2654
|
+
var SettingsSection = ({ title, description, children }) => {
|
|
2655
|
+
const { t } = useTranslation11(translationKey13);
|
|
2656
|
+
return /* @__PURE__ */ React22.createElement(React22.Fragment, null, /* @__PURE__ */ React22.createElement("h2", {
|
|
2657
|
+
className: "px-trim-md mt-trim-md text-xl"
|
|
2658
|
+
}, toLocalizedString2(title, t)), description && /* @__PURE__ */ React22.createElement("p", {
|
|
2659
|
+
className: "px-trim-md text-description"
|
|
2660
|
+
}, toLocalizedString2(description, t)), /* @__PURE__ */ React22.createElement("div", {
|
|
2661
|
+
className: "w-full pt-trim-md space-y-trim-md"
|
|
2662
|
+
}, children));
|
|
2261
2663
|
};
|
|
2262
|
-
|
|
2664
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
2263
2665
|
var Settings = {
|
|
2264
2666
|
Root: SettingsRoot,
|
|
2667
|
+
Viewport: SettingsViewport,
|
|
2265
2668
|
Section: SettingsSection,
|
|
2266
|
-
|
|
2267
|
-
Group: SettingsGroup,
|
|
2268
|
-
GroupButton: SettingsGroupButton,
|
|
2269
|
-
Container: SettingsContainer,
|
|
2270
|
-
Frame: SettingsFrame,
|
|
2271
|
-
FrameItem: SettingsFrameItem,
|
|
2669
|
+
Panel: SettingsPanel,
|
|
2272
2670
|
Item: SettingsItem,
|
|
2273
|
-
|
|
2671
|
+
FieldSet: SettingsFieldSet
|
|
2672
|
+
};
|
|
2673
|
+
|
|
2674
|
+
// src/components/Settings/SettingsSelectField.tsx
|
|
2675
|
+
import React23 from "react";
|
|
2676
|
+
import { Select as Select3 } from "@dxos/react-ui";
|
|
2677
|
+
var createSelectField = ({ options, defaultLabel = "Default" }) => {
|
|
2678
|
+
const normalized = options.map((option) => typeof option === "string" ? {
|
|
2679
|
+
value: option,
|
|
2680
|
+
label: option
|
|
2681
|
+
} : option);
|
|
2682
|
+
const hasDefault = defaultLabel !== null;
|
|
2683
|
+
const sentinel = hasDefault ? `__default__${Math.random().toString(36).slice(2)}` : "";
|
|
2684
|
+
return ({ value: value3, onChange, readonly }) => /* @__PURE__ */ React23.createElement(Select3.Root, {
|
|
2685
|
+
disabled: readonly,
|
|
2686
|
+
value: value3 ?? sentinel,
|
|
2687
|
+
onValueChange: (next) => onChange(hasDefault && next === sentinel ? void 0 : next)
|
|
2688
|
+
}, /* @__PURE__ */ React23.createElement(Select3.TriggerButton, {
|
|
2689
|
+
disabled: readonly
|
|
2690
|
+
}), /* @__PURE__ */ React23.createElement(Select3.Portal, null, /* @__PURE__ */ React23.createElement(Select3.Content, null, /* @__PURE__ */ React23.createElement(Select3.Viewport, null, hasDefault && /* @__PURE__ */ React23.createElement(Select3.Option, {
|
|
2691
|
+
value: sentinel
|
|
2692
|
+
}, defaultLabel), normalized.map((option) => /* @__PURE__ */ React23.createElement(Select3.Option, {
|
|
2693
|
+
key: option.value,
|
|
2694
|
+
value: option.value
|
|
2695
|
+
}, option.label ?? option.value))), /* @__PURE__ */ React23.createElement(Select3.Arrow, null))));
|
|
2274
2696
|
};
|
|
2275
2697
|
|
|
2276
2698
|
// src/components/ViewEditor/ViewEditor.tsx
|
|
2277
2699
|
import { RegistryContext } from "@effect-atom/atom-react";
|
|
2278
|
-
import * as
|
|
2700
|
+
import * as Array4 from "effect/Array";
|
|
2279
2701
|
import * as Match2 from "effect/Match";
|
|
2280
|
-
import * as
|
|
2281
|
-
import * as
|
|
2282
|
-
import
|
|
2283
|
-
import { Entity as Entity2, Feed, Filter as Filter2, Format as Format5, Obj as
|
|
2702
|
+
import * as Option6 from "effect/Option";
|
|
2703
|
+
import * as Schema5 from "effect/Schema";
|
|
2704
|
+
import React24, { forwardRef as forwardRef2, useCallback as useCallback18, useContext, useImperativeHandle, useMemo as useMemo12, useState as useState7 } from "react";
|
|
2705
|
+
import { Entity as Entity2, Feed, Filter as Filter2, Format as Format5, Obj as Obj6, Query, QueryAST, Ref as Ref6 } from "@dxos/echo";
|
|
2284
2706
|
import { View } from "@dxos/echo";
|
|
2285
2707
|
import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
|
|
2286
|
-
import { invariant } from "@dxos/invariant";
|
|
2708
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2287
2709
|
import { useObject, useQuery as useQuery2 } from "@dxos/react-client/echo";
|
|
2288
|
-
import { IconButton as IconButton4, Input as
|
|
2710
|
+
import { IconButton as IconButton4, Input as Input14, Message, useTranslation as useTranslation12 } from "@dxos/react-ui";
|
|
2289
2711
|
import { QueryForm } from "@dxos/react-ui-components";
|
|
2290
2712
|
import { List as List2 } from "@dxos/react-ui-list";
|
|
2291
2713
|
import { ParentLabelAnnotation, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
|
|
2292
|
-
import { mx as
|
|
2293
|
-
|
|
2294
|
-
var
|
|
2714
|
+
import { mx as mx5, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
|
|
2715
|
+
import { translationKey as translationKey14 } from "#translations";
|
|
2716
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
|
|
2717
|
+
var ViewEditor = /* @__PURE__ */ forwardRef2(({ classNames, schema, view, mode = "schema", registry, db, readonly, showHeading = false, types, tags, onQueryChanged, onDelete }, forwardedRef) => {
|
|
2295
2718
|
const atomRegistry = useContext(RegistryContext);
|
|
2296
2719
|
const schemaReadonly = !isMutable(schema);
|
|
2297
|
-
const { t } =
|
|
2298
|
-
const projectionModel =
|
|
2720
|
+
const { t } = useTranslation12(translationKey14);
|
|
2721
|
+
const projectionModel = useMemo12(() => {
|
|
2299
2722
|
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2300
2723
|
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2301
2724
|
const model = new ProjectionModel({
|
|
@@ -2319,21 +2742,21 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2319
2742
|
if (from._tag !== "scope") {
|
|
2320
2743
|
return void 0;
|
|
2321
2744
|
}
|
|
2322
|
-
return
|
|
2745
|
+
return Option6.fromNullable(from.scope.queues).pipe(Option6.flatMap((queues) => Array4.head(queues)), Option6.map(String), Option6.getOrUndefined);
|
|
2323
2746
|
}), Match2.orElse(() => void 0));
|
|
2324
2747
|
const feeds = useQuery2(db, Filter2.type(Feed.Feed));
|
|
2325
|
-
const targetRef =
|
|
2748
|
+
const targetRef = useMemo12(() => {
|
|
2326
2749
|
if (!queueTarget) {
|
|
2327
2750
|
return void 0;
|
|
2328
2751
|
}
|
|
2329
2752
|
const feed = feeds.find((feed2) => Feed.getQueueDxn(feed2)?.toString() === queueTarget);
|
|
2330
|
-
return feed ?
|
|
2753
|
+
return feed ? Ref6.fromDXN(Entity2.getDXN(feed)) : void 0;
|
|
2331
2754
|
}, [
|
|
2332
2755
|
queueTarget,
|
|
2333
2756
|
feeds
|
|
2334
2757
|
]);
|
|
2335
|
-
const viewSchema =
|
|
2336
|
-
const base =
|
|
2758
|
+
const viewSchema = useMemo12(() => {
|
|
2759
|
+
const base = Schema5.Struct({
|
|
2337
2760
|
query: mode === "schema" ? Format5.URL.annotations({
|
|
2338
2761
|
title: "Record type"
|
|
2339
2762
|
}) : QueryAST.Query.annotations({
|
|
@@ -2341,19 +2764,19 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2341
2764
|
})
|
|
2342
2765
|
});
|
|
2343
2766
|
if (mode === "tag") {
|
|
2344
|
-
return
|
|
2767
|
+
return Schema5.Struct({
|
|
2345
2768
|
...base.fields,
|
|
2346
2769
|
// TODO(wittjosiah): Replace Type.Feed with Dataset.Dataset when Ref.Ref supports unions.
|
|
2347
|
-
target:
|
|
2770
|
+
target: Ref6.Ref(Feed.Feed).pipe(Schema5.annotations({
|
|
2348
2771
|
title: "Target Feed"
|
|
2349
|
-
}), ParentLabelAnnotation.set(true),
|
|
2350
|
-
}).pipe(
|
|
2772
|
+
}), ParentLabelAnnotation.set(true), Schema5.optional)
|
|
2773
|
+
}).pipe(Schema5.mutable);
|
|
2351
2774
|
}
|
|
2352
|
-
return base.pipe(
|
|
2775
|
+
return base.pipe(Schema5.mutable);
|
|
2353
2776
|
}, [
|
|
2354
2777
|
mode
|
|
2355
2778
|
]);
|
|
2356
|
-
const viewValues =
|
|
2779
|
+
const viewValues = useMemo12(() => ({
|
|
2357
2780
|
query: mode === "schema" ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
2358
2781
|
target: targetRef
|
|
2359
2782
|
}), [
|
|
@@ -2361,7 +2784,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2361
2784
|
view.query.ast,
|
|
2362
2785
|
targetRef
|
|
2363
2786
|
]);
|
|
2364
|
-
const fieldMap =
|
|
2787
|
+
const fieldMap = useMemo12(() => mode === "tag" ? customFields({
|
|
2365
2788
|
types,
|
|
2366
2789
|
tags
|
|
2367
2790
|
}) : void 0, [
|
|
@@ -2369,12 +2792,12 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2369
2792
|
types,
|
|
2370
2793
|
tags
|
|
2371
2794
|
]);
|
|
2372
|
-
const handleUpdate =
|
|
2795
|
+
const handleUpdate = useCallback18((values) => {
|
|
2373
2796
|
const targetValue = values.target;
|
|
2374
2797
|
let queueDxn;
|
|
2375
|
-
if (
|
|
2798
|
+
if (Ref6.isRef(targetValue)) {
|
|
2376
2799
|
const feedDxn = targetValue.dxn.toString();
|
|
2377
|
-
const feed = feeds.find((feed2) =>
|
|
2800
|
+
const feed = feeds.find((feed2) => Obj6.getDXN(feed2).toString() === feedDxn);
|
|
2378
2801
|
if (feed) {
|
|
2379
2802
|
queueDxn = Feed.getQueueDxn(feed)?.toString();
|
|
2380
2803
|
}
|
|
@@ -2386,37 +2809,28 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2386
2809
|
mode,
|
|
2387
2810
|
feeds
|
|
2388
2811
|
]);
|
|
2389
|
-
const handleDelete =
|
|
2390
|
-
|
|
2391
|
-
F: __dxlog_file3,
|
|
2392
|
-
L: 185,
|
|
2393
|
-
S: void 0,
|
|
2394
|
-
A: [
|
|
2395
|
-
"!readonly",
|
|
2396
|
-
""
|
|
2397
|
-
]
|
|
2398
|
-
});
|
|
2812
|
+
const handleDelete = useCallback18((fieldId) => {
|
|
2813
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 127, S: void 0, A: ["!readonly", ""] });
|
|
2399
2814
|
onDelete?.(fieldId);
|
|
2400
2815
|
}, [
|
|
2401
2816
|
onDelete,
|
|
2402
2817
|
readonly
|
|
2403
2818
|
]);
|
|
2404
|
-
return /* @__PURE__ */
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
}, schemaReadonly && !readonly && /* @__PURE__ */ React19.createElement(Message.Root, {
|
|
2819
|
+
return /* @__PURE__ */ React24.createElement("div", {
|
|
2820
|
+
className: mx5(classNames)
|
|
2821
|
+
}, schemaReadonly && !readonly && /* @__PURE__ */ React24.createElement(Message.Root, {
|
|
2408
2822
|
valence: "info",
|
|
2409
2823
|
classNames: "my-form-padding"
|
|
2410
|
-
}, /* @__PURE__ */
|
|
2824
|
+
}, /* @__PURE__ */ React24.createElement(Message.Title, null, t("system-schema.description"))), /* @__PURE__ */ React24.createElement(Form.Root, {
|
|
2411
2825
|
schema: viewSchema,
|
|
2412
2826
|
values: viewValues,
|
|
2413
2827
|
fieldMap,
|
|
2414
2828
|
db,
|
|
2415
2829
|
onValuesChanged: handleUpdate
|
|
2416
|
-
}, /* @__PURE__ */
|
|
2417
|
-
label: t("fields
|
|
2830
|
+
}, /* @__PURE__ */ React24.createElement(Form.FieldSet, null), /* @__PURE__ */ React24.createElement(FormFieldLabel, {
|
|
2831
|
+
label: t("fields.label"),
|
|
2418
2832
|
asChild: true
|
|
2419
|
-
}), /* @__PURE__ */
|
|
2833
|
+
}), /* @__PURE__ */ React24.createElement(FieldList, {
|
|
2420
2834
|
schema,
|
|
2421
2835
|
view,
|
|
2422
2836
|
registry,
|
|
@@ -2428,9 +2842,9 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
|
|
|
2428
2842
|
var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }) => {
|
|
2429
2843
|
const atomRegistry = useContext(RegistryContext);
|
|
2430
2844
|
const schemaReadonly = !isMutable(schema);
|
|
2431
|
-
const { t } =
|
|
2845
|
+
const { t } = useTranslation12(translationKey14);
|
|
2432
2846
|
const [viewSnapshot] = useObject(view);
|
|
2433
|
-
const projectionModel =
|
|
2847
|
+
const projectionModel = useMemo12(() => {
|
|
2434
2848
|
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
2435
2849
|
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
|
|
2436
2850
|
const model = new ProjectionModel({
|
|
@@ -2445,38 +2859,22 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2445
2859
|
schema,
|
|
2446
2860
|
view
|
|
2447
2861
|
]);
|
|
2448
|
-
const [expandedField, setExpandedField] =
|
|
2449
|
-
const handleAdd =
|
|
2450
|
-
|
|
2451
|
-
F: __dxlog_file3,
|
|
2452
|
-
L: 250,
|
|
2453
|
-
S: void 0,
|
|
2454
|
-
A: [
|
|
2455
|
-
"!readonly",
|
|
2456
|
-
""
|
|
2457
|
-
]
|
|
2458
|
-
});
|
|
2862
|
+
const [expandedField, setExpandedField] = useState7();
|
|
2863
|
+
const handleAdd = useCallback18(() => {
|
|
2864
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 182, S: void 0, A: ["!readonly", ""] });
|
|
2459
2865
|
const field = projectionModel.createFieldProjection();
|
|
2460
2866
|
setExpandedField(field.id);
|
|
2461
2867
|
}, [
|
|
2462
2868
|
projectionModel,
|
|
2463
2869
|
readonly
|
|
2464
2870
|
]);
|
|
2465
|
-
const handleToggleField =
|
|
2871
|
+
const handleToggleField = useCallback18((field) => {
|
|
2466
2872
|
setExpandedField((prevExpandedFieldId) => prevExpandedFieldId === field.id ? void 0 : field.id);
|
|
2467
2873
|
}, [
|
|
2468
2874
|
readonly
|
|
2469
2875
|
]);
|
|
2470
|
-
const handleDelete =
|
|
2471
|
-
|
|
2472
|
-
F: __dxlog_file3,
|
|
2473
|
-
L: 264,
|
|
2474
|
-
S: void 0,
|
|
2475
|
-
A: [
|
|
2476
|
-
"!readonly",
|
|
2477
|
-
""
|
|
2478
|
-
]
|
|
2479
|
-
});
|
|
2876
|
+
const handleDelete = useCallback18((fieldId) => {
|
|
2877
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 195, S: void 0, A: ["!readonly", ""] });
|
|
2480
2878
|
if (fieldId === expandedField) {
|
|
2481
2879
|
setExpandedField(void 0);
|
|
2482
2880
|
}
|
|
@@ -2486,36 +2884,28 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2486
2884
|
onDelete,
|
|
2487
2885
|
readonly
|
|
2488
2886
|
]);
|
|
2489
|
-
const handleMove =
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
L: 276,
|
|
2493
|
-
S: void 0,
|
|
2494
|
-
A: [
|
|
2495
|
-
"!readonly",
|
|
2496
|
-
""
|
|
2497
|
-
]
|
|
2498
|
-
});
|
|
2499
|
-
Obj3.change(view, (v) => {
|
|
2887
|
+
const handleMove = useCallback18((fromIndex, toIndex) => {
|
|
2888
|
+
invariant3(!readonly, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 206, S: void 0, A: ["!readonly", ""] });
|
|
2889
|
+
Obj6.update(view, (view2) => {
|
|
2500
2890
|
const fields = [
|
|
2501
|
-
...
|
|
2891
|
+
...view2.projection.fields
|
|
2502
2892
|
];
|
|
2503
2893
|
const [moved] = fields.splice(fromIndex, 1);
|
|
2504
2894
|
fields.splice(toIndex, 0, moved);
|
|
2505
|
-
|
|
2895
|
+
view2.projection.fields = fields;
|
|
2506
2896
|
});
|
|
2507
2897
|
}, [
|
|
2508
2898
|
view,
|
|
2509
2899
|
readonly
|
|
2510
2900
|
]);
|
|
2511
|
-
const handleClose =
|
|
2512
|
-
const handleHide =
|
|
2901
|
+
const handleClose = useCallback18(() => setExpandedField(void 0), []);
|
|
2902
|
+
const handleHide = useCallback18((fieldId) => {
|
|
2513
2903
|
setExpandedField(void 0);
|
|
2514
2904
|
projectionModel.hideFieldProjection(fieldId);
|
|
2515
2905
|
}, [
|
|
2516
2906
|
projectionModel
|
|
2517
2907
|
]);
|
|
2518
|
-
const handleShow =
|
|
2908
|
+
const handleShow = useCallback18((property) => {
|
|
2519
2909
|
setExpandedField(void 0);
|
|
2520
2910
|
projectionModel.showFieldProjection(property);
|
|
2521
2911
|
}, [
|
|
@@ -2524,70 +2914,67 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2524
2914
|
if (!viewSnapshot) {
|
|
2525
2915
|
return null;
|
|
2526
2916
|
}
|
|
2527
|
-
return /* @__PURE__ */
|
|
2917
|
+
return /* @__PURE__ */ React24.createElement(List2.Root, {
|
|
2528
2918
|
items: viewSnapshot.projection.fields,
|
|
2529
|
-
isItem:
|
|
2919
|
+
isItem: Schema5.is(View.FieldSchema),
|
|
2530
2920
|
getId: (field) => field.id,
|
|
2531
2921
|
onMove: readonly ? void 0 : handleMove,
|
|
2532
2922
|
readonly
|
|
2533
|
-
}, ({ items: fields }) => /* @__PURE__ */
|
|
2923
|
+
}, ({ items: fields }) => /* @__PURE__ */ React24.createElement(React24.Fragment, null, showHeading && /* @__PURE__ */ React24.createElement("h3", {
|
|
2534
2924
|
className: "text-sm"
|
|
2535
|
-
}, t("field
|
|
2925
|
+
}, t("field-path.label")), /* @__PURE__ */ React24.createElement("div", {
|
|
2536
2926
|
role: "list",
|
|
2537
2927
|
className: "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]"
|
|
2538
2928
|
}, fields?.map((field) => {
|
|
2539
2929
|
const hidden = field.visible === false;
|
|
2540
|
-
return /* @__PURE__ */
|
|
2930
|
+
return /* @__PURE__ */ React24.createElement(List2.Item, {
|
|
2541
2931
|
key: field.id,
|
|
2542
2932
|
item: field,
|
|
2543
2933
|
classNames: "grid grid-cols-subgrid col-span-5",
|
|
2544
2934
|
"aria-expanded": expandedField === field.id
|
|
2545
|
-
}, /* @__PURE__ */
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
}, /* @__PURE__ */ React19.createElement(List2.ItemDragHandle, {
|
|
2935
|
+
}, /* @__PURE__ */ React24.createElement("div", {
|
|
2936
|
+
className: mx5(subtleHover2, "grid grid-cols-subgrid col-span-5", "rounded-xs cursor-pointer min-h-10")
|
|
2937
|
+
}, /* @__PURE__ */ React24.createElement(List2.ItemDragHandle, {
|
|
2549
2938
|
disabled: readonly || schemaReadonly
|
|
2550
|
-
}), /* @__PURE__ */
|
|
2939
|
+
}), /* @__PURE__ */ React24.createElement(List2.ItemTitle, {
|
|
2551
2940
|
classNames: hidden && "text-subdued",
|
|
2552
2941
|
onClick: () => handleToggleField(field)
|
|
2553
|
-
}, field.path), /* @__PURE__ */
|
|
2554
|
-
label: t(hidden ? "show
|
|
2942
|
+
}, field.path), /* @__PURE__ */ React24.createElement(List2.ItemIconButton, {
|
|
2943
|
+
label: t(hidden ? "show-field.label" : "hide-field.label"),
|
|
2555
2944
|
"data-testid": hidden ? "show-field-button" : "hide-field-button",
|
|
2556
2945
|
icon: hidden ? "ph--eye-closed--regular" : "ph--eye--regular",
|
|
2557
2946
|
autoHide: false,
|
|
2558
2947
|
disabled: readonly || !hidden && projectionModel.getFields().length <= 1,
|
|
2559
2948
|
onClick: () => hidden ? handleShow(field.path) : handleHide(field.id)
|
|
2560
|
-
}), !readonly && /* @__PURE__ */
|
|
2561
|
-
label: t("delete
|
|
2949
|
+
}), !readonly && /* @__PURE__ */ React24.createElement(React24.Fragment, null, /* @__PURE__ */ React24.createElement(List2.ItemDeleteButton, {
|
|
2950
|
+
label: t("delete-field.label"),
|
|
2562
2951
|
autoHide: false,
|
|
2563
2952
|
disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
|
|
2564
2953
|
onClick: () => handleDelete(field.id),
|
|
2565
2954
|
"data-testid": "field.delete"
|
|
2566
|
-
}), /* @__PURE__ */
|
|
2955
|
+
}), /* @__PURE__ */ React24.createElement(List2.ItemIconButton, {
|
|
2567
2956
|
iconOnly: true,
|
|
2568
2957
|
variant: "ghost",
|
|
2569
|
-
label: t("toggle
|
|
2958
|
+
label: t("toggle-expand.label", {
|
|
2570
2959
|
ns: osTranslations2
|
|
2571
2960
|
}),
|
|
2572
2961
|
icon: expandedField === field.id ? "ph--caret-down--regular" : "ph--caret-right--regular",
|
|
2573
2962
|
onClick: () => handleToggleField(field),
|
|
2574
2963
|
"data-testid": "field.toggle"
|
|
2575
|
-
}))), expandedField === field.id && !readonly && /* @__PURE__ */
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
}, /* @__PURE__ */ React19.createElement(FieldEditor, {
|
|
2964
|
+
}))), expandedField === field.id && !readonly && /* @__PURE__ */ React24.createElement("div", {
|
|
2965
|
+
className: "col-span-full mt-1 mb-1 border border-separator rounded-md"
|
|
2966
|
+
}, /* @__PURE__ */ React24.createElement(FieldEditor, {
|
|
2579
2967
|
readonly: readonly || schemaReadonly,
|
|
2580
2968
|
registry,
|
|
2581
2969
|
projection: projectionModel,
|
|
2582
2970
|
field,
|
|
2583
2971
|
onSave: handleClose
|
|
2584
2972
|
})));
|
|
2585
|
-
})), !readonly && !expandedField && /* @__PURE__ */
|
|
2586
|
-
role: "none",
|
|
2973
|
+
})), !readonly && !expandedField && /* @__PURE__ */ React24.createElement("div", {
|
|
2587
2974
|
className: "my-form-padding"
|
|
2588
|
-
}, /* @__PURE__ */
|
|
2975
|
+
}, /* @__PURE__ */ React24.createElement(IconButton4, {
|
|
2589
2976
|
icon: "ph--plus--regular",
|
|
2590
|
-
label: t("add
|
|
2977
|
+
label: t("add-property-button.label"),
|
|
2591
2978
|
onClick: handleAdd,
|
|
2592
2979
|
disabled: viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT,
|
|
2593
2980
|
classNames: "w-full"
|
|
@@ -2595,13 +2982,13 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
|
|
|
2595
2982
|
};
|
|
2596
2983
|
var customFields = ({ types, tags }) => ({
|
|
2597
2984
|
query: ({ type, readonly, label, getValue, onValueChange }) => {
|
|
2598
|
-
const handleChange =
|
|
2985
|
+
const handleChange = useCallback18((query) => onValueChange(type, query.ast), [
|
|
2599
2986
|
onValueChange
|
|
2600
2987
|
]);
|
|
2601
|
-
return /* @__PURE__ */
|
|
2988
|
+
return /* @__PURE__ */ React24.createElement(Input14.Root, null, /* @__PURE__ */ React24.createElement(FormFieldLabel, {
|
|
2602
2989
|
readonly,
|
|
2603
2990
|
label
|
|
2604
|
-
}), /* @__PURE__ */
|
|
2991
|
+
}), /* @__PURE__ */ React24.createElement(QueryForm, {
|
|
2605
2992
|
initialQuery: getValue(),
|
|
2606
2993
|
types,
|
|
2607
2994
|
tags,
|
|
@@ -2620,7 +3007,9 @@ export {
|
|
|
2620
3007
|
GeoPointField,
|
|
2621
3008
|
MarkdownField,
|
|
2622
3009
|
NumberField,
|
|
3010
|
+
ObjectForm,
|
|
2623
3011
|
ObjectPicker,
|
|
3012
|
+
ObjectProperties,
|
|
2624
3013
|
RefField,
|
|
2625
3014
|
SelectField,
|
|
2626
3015
|
SelectOptionField,
|
|
@@ -2630,15 +3019,18 @@ export {
|
|
|
2630
3019
|
TupleField,
|
|
2631
3020
|
ViewEditor,
|
|
2632
3021
|
cellClassesForFieldType,
|
|
3022
|
+
createSelectField,
|
|
3023
|
+
detectFieldType,
|
|
2633
3024
|
formatForDisplay,
|
|
2634
3025
|
formatForEditing,
|
|
2635
3026
|
getDefaultValue,
|
|
2636
3027
|
getFormProperties,
|
|
2637
3028
|
getRefProps,
|
|
3029
|
+
getSelectOptionsFromAst,
|
|
3030
|
+
omitHiddenFormFields,
|
|
2638
3031
|
omitId,
|
|
2639
3032
|
parseValue,
|
|
2640
3033
|
pathNotUniqueError,
|
|
2641
|
-
translations,
|
|
2642
3034
|
useFormContext,
|
|
2643
3035
|
useFormFieldState,
|
|
2644
3036
|
useFormHandler,
|