@dxos/react-ui-form 0.8.4-main.937b3ca → 0.8.4-main.9735255

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.
@@ -167,12 +167,25 @@ var ControlFrameItem = ({ title, description, children }) => {
167
167
 
168
168
  // src/components/FieldEditor/FieldEditor.tsx
169
169
  import React18, { useCallback as useCallback14, useEffect as useEffect7, useMemo as useMemo7, useState as useState5 } from "react";
170
- import { Obj } from "@dxos/echo";
170
+ import { Obj as Obj3 } from "@dxos/echo";
171
171
  import { Format as Format4, FormatEnums, formatToType } from "@dxos/echo/internal";
172
172
  import { log as log2 } from "@dxos/log";
173
173
  import { useAsyncEffect, useTranslation as useTranslation9 } from "@dxos/react-ui";
174
174
  import { formatToAdditionalPropertyAttributes, getFormatSchema } from "@dxos/schema";
175
175
 
176
+ // src/util/echo.ts
177
+ import { Obj } from "@dxos/echo";
178
+ import { setValue as setValuePlain, splitJsonPath } from "@dxos/effect";
179
+ var setValueEchoAware = (obj, path, value3) => {
180
+ if (Obj.isObject(obj)) {
181
+ Obj.change(obj, (mutableObj) => {
182
+ Obj.setValue(mutableObj, splitJsonPath(path), value3);
183
+ });
184
+ return obj;
185
+ }
186
+ return setValuePlain(obj, path, value3);
187
+ };
188
+
176
189
  // src/util/field.ts
177
190
  import { Format, GeoLocation, TypeEnum } from "@dxos/echo/internal";
178
191
  var parseValue = ({ type, format, value: value3 }) => {
@@ -475,13 +488,14 @@ import { IconButton as IconButton2, useTranslation as useTranslation4 } from "@d
475
488
  import { createContext } from "@radix-ui/react-context";
476
489
  import * as Schema2 from "effect/Schema";
477
490
  import React5, { useEffect as useEffect3, useMemo as useMemo4, useRef } from "react";
478
- import { createJsonPath as createJsonPath3, getValue as getValue$2, setValue as setValue$2 } from "@dxos/effect";
491
+ import { createJsonPath as createJsonPath3, getValue as getValue$2 } from "@dxos/effect";
479
492
  import { IconButton, ScrollArea, useTranslation as useTranslation3 } from "@dxos/react-ui";
480
493
  import { mx as mx4 } from "@dxos/ui-theme";
481
494
 
482
495
  // src/hooks/useFormHandler.ts
483
496
  import { useControllableState } from "@radix-ui/react-use-controllable-state";
484
497
  import { useCallback, useEffect, useMemo, useState } from "react";
498
+ import { Obj as Obj2 } from "@dxos/echo";
485
499
  import { createJsonPath, fromEffectValidationPath, getValue as getValue$, setValue as setValue$ } from "@dxos/effect";
486
500
  import { log } from "@dxos/log";
487
501
  import { useDefaultValue } from "@dxos/react-ui";
@@ -515,7 +529,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
515
529
  errors: errors2
516
530
  }, {
517
531
  F: __dxlog_file,
518
- L: 157,
532
+ L: 160,
519
533
  S: void 0,
520
534
  C: (f, a) => f(...a)
521
535
  });
@@ -608,7 +622,7 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
608
622
  value: value3
609
623
  }, {
610
624
  F: __dxlog_file,
611
- L: 256,
625
+ L: 259,
612
626
  S: void 0,
613
627
  C: (f, a) => f(...a)
614
628
  });
@@ -621,13 +635,13 @@ var useFormHandler = ({ schema, autoSave, values: valuesProp, defaultValues: def
621
635
  } catch (err) {
622
636
  log.catch(err, void 0, {
623
637
  F: __dxlog_file,
624
- L: 265,
638
+ L: 268,
625
639
  S: void 0,
626
640
  C: (f, a) => f(...a)
627
641
  });
628
642
  parsedValue = void 0;
629
643
  }
630
- const newValues = {
644
+ const newValues = Obj2.isObject(values) ? (setValueEchoAware(values, jsonPath, parsedValue), values) : {
631
645
  ...setValue$(values, jsonPath, parsedValue)
632
646
  };
633
647
  setValues(newValues);
@@ -1051,7 +1065,7 @@ var useFormValues = (componentName, path = [], defaultValue) => {
1051
1065
  const value3 = getValue$2(values, jsonPath);
1052
1066
  useEffect3(() => {
1053
1067
  if (!value3 && defaultValue) {
1054
- setValue$2(values, jsonPath, defaultValue());
1068
+ setValueEchoAware(values, jsonPath, defaultValue());
1055
1069
  }
1056
1070
  }, [
1057
1071
  value3,
@@ -2123,7 +2137,7 @@ var FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCanc
2123
2137
  ]);
2124
2138
  const handleSave = useCallback14((props2) => {
2125
2139
  if (view) {
2126
- Obj.change(view, () => {
2140
+ Obj3.change(view, () => {
2127
2141
  projection.setFieldProjection({
2128
2142
  field,
2129
2143
  props: props2
@@ -2185,13 +2199,14 @@ import * as Match2 from "effect/Match";
2185
2199
  import * as Option4 from "effect/Option";
2186
2200
  import * as Schema3 from "effect/Schema";
2187
2201
  import React19, { forwardRef as forwardRef3, useCallback as useCallback15, useContext, useImperativeHandle, useMemo as useMemo8, useState as useState6 } from "react";
2188
- import { Filter as Filter2, Format as Format5, Obj as Obj2, Query, QueryAST } from "@dxos/echo";
2202
+ import { Filter as Filter2, Format as Format5, Obj as Obj4, Query, QueryAST } from "@dxos/echo";
2189
2203
  import { EchoSchema, isMutable, toJsonSchema } from "@dxos/echo/internal";
2190
2204
  import { invariant } from "@dxos/invariant";
2205
+ import { useObject } from "@dxos/react-client/echo";
2191
2206
  import { Callout, IconButton as IconButton4, Input as Input13, useTranslation as useTranslation10 } from "@dxos/react-ui";
2192
2207
  import { QueryForm } from "@dxos/react-ui-components";
2193
2208
  import { List as List2 } from "@dxos/react-ui-list";
2194
- import { FieldSchema, ProjectionModel, VIEW_FIELD_LIMIT, createDirectChangeCallback, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
2209
+ import { FieldSchema, ProjectionModel, VIEW_FIELD_LIMIT, createEchoChangeCallback, getTypenameFromQuery } from "@dxos/schema";
2195
2210
  import { mx as mx7, osTranslations as osTranslations2, subtleHover as subtleHover2 } from "@dxos/ui-theme";
2196
2211
  var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-form/src/components/ViewEditor/ViewEditor.tsx";
2197
2212
  var listGrid = "grid grid-cols-[min-content_1fr_min-content_min-content_min-content]";
@@ -2202,7 +2217,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
2202
2217
  const { t } = useTranslation10(translationKey);
2203
2218
  const projectionModel = useMemo8(() => {
2204
2219
  const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
2205
- const change = schema instanceof EchoSchema ? createEchoChangeCallback(view, schema) : createDirectChangeCallback(view.projection, jsonSchema);
2220
+ const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
2206
2221
  const model = new ProjectionModel({
2207
2222
  registry: atomRegistry,
2208
2223
  view,
@@ -2263,7 +2278,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
2263
2278
  const handleAdd = useCallback15(() => {
2264
2279
  invariant(!readonly, void 0, {
2265
2280
  F: __dxlog_file3,
2266
- L: 148,
2281
+ L: 146,
2267
2282
  S: void 0,
2268
2283
  A: [
2269
2284
  "!readonly",
@@ -2290,7 +2305,7 @@ var ViewEditor = /* @__PURE__ */ forwardRef3(({ classNames, schema, view, mode =
2290
2305
  const handleDelete = useCallback15((fieldId) => {
2291
2306
  invariant(!readonly, void 0, {
2292
2307
  F: __dxlog_file3,
2293
- L: 165,
2308
+ L: 163,
2294
2309
  S: void 0,
2295
2310
  A: [
2296
2311
  "!readonly",
@@ -2344,9 +2359,10 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
2344
2359
  const atomRegistry = useContext(RegistryContext);
2345
2360
  const schemaReadonly = !isMutable(schema);
2346
2361
  const { t } = useTranslation10(translationKey);
2362
+ const [viewSnapshot] = useObject(view);
2347
2363
  const projectionModel = useMemo8(() => {
2348
2364
  const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
2349
- const change = schema instanceof EchoSchema ? createEchoChangeCallback(view, schema) : createDirectChangeCallback(view.projection, jsonSchema);
2365
+ const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : void 0);
2350
2366
  const model = new ProjectionModel({
2351
2367
  registry: atomRegistry,
2352
2368
  view,
@@ -2368,7 +2384,7 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
2368
2384
  const handleDelete = useCallback15((fieldId) => {
2369
2385
  invariant(!readonly, void 0, {
2370
2386
  F: __dxlog_file3,
2371
- L: 254,
2387
+ L: 253,
2372
2388
  S: void 0,
2373
2389
  A: [
2374
2390
  "!readonly",
@@ -2387,23 +2403,23 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
2387
2403
  const handleMove = useCallback15((fromIndex, toIndex) => {
2388
2404
  invariant(!readonly, void 0, {
2389
2405
  F: __dxlog_file3,
2390
- L: 266,
2406
+ L: 265,
2391
2407
  S: void 0,
2392
2408
  A: [
2393
2409
  "!readonly",
2394
2410
  ""
2395
2411
  ]
2396
2412
  });
2397
- const fields = [
2398
- ...view.projection.fields
2399
- ];
2400
- const [moved] = fields.splice(fromIndex, 1);
2401
- fields.splice(toIndex, 0, moved);
2402
- Obj2.change(view, (v) => {
2413
+ Obj4.change(view, (v) => {
2414
+ const fields = [
2415
+ ...v.projection.fields
2416
+ ];
2417
+ const [moved] = fields.splice(fromIndex, 1);
2418
+ fields.splice(toIndex, 0, moved);
2403
2419
  v.projection.fields = fields;
2404
2420
  });
2405
2421
  }, [
2406
- view.projection.fields,
2422
+ view,
2407
2423
  readonly
2408
2424
  ]);
2409
2425
  const handleClose = useCallback15(() => setExpandedField(void 0), []);
@@ -2419,8 +2435,11 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
2419
2435
  }, [
2420
2436
  projectionModel
2421
2437
  ]);
2438
+ if (!viewSnapshot) {
2439
+ return null;
2440
+ }
2422
2441
  return /* @__PURE__ */ React19.createElement(List2.Root, {
2423
- items: view.projection.fields,
2442
+ items: viewSnapshot.projection.fields,
2424
2443
  isItem: Schema3.is(FieldSchema),
2425
2444
  getId: (field) => field.id,
2426
2445
  onMove: readonly ? void 0 : handleMove,
@@ -2455,7 +2474,7 @@ var FieldList = ({ schema, view, registry, readonly, showHeading = false, onDele
2455
2474
  }), !readonly && /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(List2.ItemDeleteButton, {
2456
2475
  label: t("delete field label"),
2457
2476
  autoHide: false,
2458
- disabled: readonly || schemaReadonly || view.projection.fields.length <= 1,
2477
+ disabled: readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1,
2459
2478
  onClick: () => handleDelete(field.id),
2460
2479
  "data-testid": "field.delete"
2461
2480
  }), /* @__PURE__ */ React19.createElement(IconButton4, {
@@ -2533,6 +2552,7 @@ export {
2533
2552
  omitId,
2534
2553
  parseValue,
2535
2554
  pathNotUniqueError,
2555
+ setValueEchoAware,
2536
2556
  translations,
2537
2557
  useFormContext,
2538
2558
  useFormFieldState,