@dxos/plugin-space 0.7.1 → 0.7.2-staging.6d26b2a

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.
@@ -22,7 +22,7 @@ import { signal } from "@preact/signals-core";
22
22
  import React17 from "react";
23
23
  import { LayoutAction as LayoutAction2, NavigationAction as NavigationAction4, Surface, findPlugin, firstIdInPart, openIds, parseGraphPlugin, parseIntentPlugin as parseIntentPlugin2, parseLayoutPlugin, parseMetadataResolverPlugin, parseNavigationPlugin as parseNavigationPlugin2, resolvePlugin } from "@dxos/app-framework";
24
24
  import { EventSubscriptions } from "@dxos/async";
25
- import { isReactiveObject as isReactiveObject2 } from "@dxos/echo-schema";
25
+ import { isDeleted, isReactiveObject as isReactiveObject2 } from "@dxos/echo-schema";
26
26
  import { scheduledEffect } from "@dxos/echo-signals/core";
27
27
  import { invariant as invariant2 } from "@dxos/invariant";
28
28
  import { LocalStorageStore } from "@dxos/local-storage";
@@ -33,7 +33,7 @@ import { parseClientPlugin } from "@dxos/plugin-client";
33
33
  import { createExtension, memoize as memoize2, toSignal } from "@dxos/plugin-graph";
34
34
  import { ObservabilityAction as ObservabilityAction2 } from "@dxos/plugin-observability/meta";
35
35
  import { PublicKey as PublicKey2 } from "@dxos/react-client";
36
- import { Expando, Filter, SpaceState as SpaceState2, create as create2, fullyQualifiedId as fullyQualifiedId4, getSpace as getSpace4, getTypename as getTypename2, isEchoObject as isEchoObject2, isSpace as isSpace2, loadObjectReferences, parseId, FQ_ID_LENGTH } from "@dxos/react-client/echo";
36
+ import { Expando, Filter, SpaceState as SpaceState2, create as create2, fullyQualifiedId as fullyQualifiedId4, getSpace as getSpace4, getTypename as getTypename2, isEchoObject as isEchoObject2, isSpace as isSpace2, loadObjectReferences, parseId, FQ_ID_LENGTH, SPACE_ID_LENGTH, OBJECT_ID_LENGTH } from "@dxos/react-client/echo";
37
37
  import { osTranslations } from "@dxos/shell/react";
38
38
  import { ComplexMap as ComplexMap2, nonNullable, reduceGroupBy } from "@dxos/util";
39
39
 
@@ -361,6 +361,11 @@ var constructSpaceNode = ({ space, navigable = false, personal, namesCache, reso
361
361
  return {
362
362
  id: space.id,
363
363
  type: SPACE_TYPE,
364
+ cacheable: [
365
+ "label",
366
+ "icon",
367
+ "role"
368
+ ],
364
369
  data: space,
365
370
  properties: {
366
371
  ...partials,
@@ -640,6 +645,11 @@ var createObjectNode = ({ object, space, navigable = false, resolve }) => {
640
645
  return {
641
646
  id: fullyQualifiedId2(object),
642
647
  type,
648
+ cacheable: [
649
+ "label",
650
+ "icon",
651
+ "role"
652
+ ],
643
653
  data: object,
644
654
  properties: {
645
655
  ...partials,
@@ -833,7 +843,7 @@ var cloneObject = async (object, resolve, newSpace) => {
833
843
  const serializer = metadata.serializer;
834
844
  invariant(serializer, `No serializer for type: ${typename}`, {
835
845
  F: __dxlog_file,
836
- L: 632,
846
+ L: 634,
837
847
  S: void 0,
838
848
  A: [
839
849
  "serializer",
@@ -1941,7 +1951,7 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
1941
1951
  err: err.message
1942
1952
  }, {
1943
1953
  F: __dxlog_file6,
1944
- L: 292,
1954
+ L: 294,
1945
1955
  S: void 0,
1946
1956
  C: (f, a) => f(...a)
1947
1957
  });
@@ -2228,6 +2238,10 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2228
2238
  {
2229
2239
  id: SPACES,
2230
2240
  type: SPACES,
2241
+ cacheable: [
2242
+ "label",
2243
+ "role"
2244
+ ],
2231
2245
  properties: {
2232
2246
  label: [
2233
2247
  "spaces label",
@@ -2249,7 +2263,7 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2249
2263
  } else {
2250
2264
  log3.warn("spaces order object not found", void 0, {
2251
2265
  F: __dxlog_file6,
2252
- L: 596,
2266
+ L: 599,
2253
2267
  S: void 0,
2254
2268
  C: (f, a) => f(...a)
2255
2269
  });
@@ -2334,37 +2348,31 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2334
2348
  }));
2335
2349
  } catch {
2336
2350
  }
2337
- }
2338
- }),
2339
- // Find an object by its fully qualified id.
2340
- createExtension({
2341
- id: `${SPACE_PLUGIN}/objects`,
2351
+ },
2342
2352
  resolver: ({ id }) => {
2343
- const [spaceId, objectId] = id.split(":");
2344
- const space = client.spaces.get().find((space2) => space2.id === spaceId);
2345
- if (!space) {
2353
+ if (id.length !== SPACE_ID_LENGTH) {
2346
2354
  return;
2347
2355
  }
2348
- const spaceState = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2349
- if (spaceState !== SpaceState2.SPACE_READY) {
2356
+ const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
2357
+ const isReady = toSignal((onChange) => client.spaces.isReady.subscribe(() => onChange()).unsubscribe, () => client.spaces.isReady.get());
2358
+ if (!spaces || !isReady) {
2350
2359
  return;
2351
2360
  }
2352
- const store = memoize2(() => signal(space.db.getObjectById(objectId)), id);
2353
- memoize2(() => {
2354
- if (!store.value) {
2355
- void space.db.loadObjectById(objectId).then((o) => store.value = o);
2356
- }
2357
- }, id);
2358
- const object = store.value;
2359
- if (!object) {
2361
+ const space = spaces.find((space2) => space2.id === id);
2362
+ if (!space) {
2360
2363
  return;
2361
2364
  }
2362
- return createObjectNode({
2363
- object,
2364
- space,
2365
- resolve,
2366
- navigable: state.values.navigableCollections
2367
- });
2365
+ if (space.state.get() === SpaceState2.SPACE_INACTIVE) {
2366
+ return false;
2367
+ } else {
2368
+ return constructSpaceNode({
2369
+ space,
2370
+ navigable: state.values.navigableCollections,
2371
+ personal: space === client.spaces.default,
2372
+ namesCache: state.values.spaceNames,
2373
+ resolve
2374
+ });
2375
+ }
2368
2376
  }
2369
2377
  }),
2370
2378
  // Create space actions and action groups.
@@ -2408,23 +2416,9 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2408
2416
  })).filter(nonNullable);
2409
2417
  }
2410
2418
  }),
2411
- // Create collection actions and action groups.
2412
- createExtension({
2413
- id: `${SPACE_PLUGIN}/object-actions`,
2414
- filter: (node) => isEchoObject2(node.data),
2415
- actionGroups: ({ node }) => constructObjectActionGroups({
2416
- object: node.data,
2417
- dispatch,
2418
- navigable: state.values.navigableCollections
2419
- }),
2420
- actions: ({ node }) => constructObjectActions({
2421
- node,
2422
- dispatch
2423
- })
2424
- }),
2425
- // Create nodes for objects in collections.
2419
+ // Create nodes for objects in a collection or by its fully qualified id.
2426
2420
  createExtension({
2427
- id: `${SPACE_PLUGIN}/collection-objects`,
2421
+ id: `${SPACE_PLUGIN}/objects`,
2428
2422
  filter: (node) => node.data instanceof CollectionType,
2429
2423
  connector: ({ node }) => {
2430
2424
  const collection = node.data;
@@ -2438,8 +2432,61 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2438
2432
  resolve,
2439
2433
  navigable: state.values.navigableCollections
2440
2434
  })).filter(nonNullable);
2435
+ },
2436
+ resolver: ({ id }) => {
2437
+ if (id.length !== FQ_ID_LENGTH) {
2438
+ return;
2439
+ }
2440
+ const [spaceId, objectId] = id.split(":");
2441
+ if (spaceId.length !== SPACE_ID_LENGTH && objectId.length !== OBJECT_ID_LENGTH) {
2442
+ return;
2443
+ }
2444
+ const space = client.spaces.get().find((space2) => space2.id === spaceId);
2445
+ if (!space) {
2446
+ return;
2447
+ }
2448
+ const spaceState = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2449
+ if (spaceState !== SpaceState2.SPACE_READY) {
2450
+ return;
2451
+ }
2452
+ const store = memoize2(() => signal(space.db.getObjectById(objectId)), id);
2453
+ memoize2(() => {
2454
+ if (!store.value) {
2455
+ void space.db.query({
2456
+ id: objectId
2457
+ }).first().then((o) => store.value = o);
2458
+ }
2459
+ }, id);
2460
+ const object = store.value;
2461
+ if (!object) {
2462
+ return;
2463
+ }
2464
+ if (isDeleted(object)) {
2465
+ return false;
2466
+ } else {
2467
+ return createObjectNode({
2468
+ object,
2469
+ space,
2470
+ resolve,
2471
+ navigable: state.values.navigableCollections
2472
+ });
2473
+ }
2441
2474
  }
2442
2475
  }),
2476
+ // Create collection actions and action groups.
2477
+ createExtension({
2478
+ id: `${SPACE_PLUGIN}/object-actions`,
2479
+ filter: (node) => isEchoObject2(node.data),
2480
+ actionGroups: ({ node }) => constructObjectActionGroups({
2481
+ object: node.data,
2482
+ dispatch,
2483
+ navigable: state.values.navigableCollections
2484
+ }),
2485
+ actions: ({ node }) => constructObjectActions({
2486
+ node,
2487
+ dispatch
2488
+ })
2489
+ }),
2443
2490
  // Create nodes for object settings.
2444
2491
  createExtension({
2445
2492
  id: `${SPACE_PLUGIN}/settings-for-subject`,
@@ -2451,7 +2498,8 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2451
2498
  const icon = "ph--gear--regular";
2452
2499
  const [subjectId] = id.split("~");
2453
2500
  const { spaceId, objectId } = parseId(subjectId);
2454
- const space = client.spaces.get().find((space2) => space2.id === spaceId);
2501
+ const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
2502
+ const space = spaces?.find((space2) => space2.id === spaceId && space2.state.get() === SpaceState2.SPACE_READY);
2455
2503
  if (!objectId) {
2456
2504
  const label2 = space ? space.properties.name || [
2457
2505
  "unnamed space label",
@@ -2479,7 +2527,9 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2479
2527
  }
2480
2528
  const object = toSignal((onChange) => {
2481
2529
  const timeout = setTimeout(async () => {
2482
- await space?.db.loadObjectById(objectId);
2530
+ await space?.db.query({
2531
+ id: objectId
2532
+ }).first();
2483
2533
  onChange();
2484
2534
  });
2485
2535
  return () => clearTimeout(timeout);
@@ -2946,7 +2996,7 @@ var SpacePlugin = ({ invitationUrl = window.location.origin, invitationParam = "
2946
2996
  const objects = intent.data?.objects ?? intent.data?.result;
2947
2997
  invariant2(Array.isArray(objects), void 0, {
2948
2998
  F: __dxlog_file6,
2949
- L: 1291,
2999
+ L: 1346,
2950
3000
  S: void 0,
2951
3001
  A: [
2952
3002
  "Array.isArray(objects)",