@dxos/plugin-stack 0.8.2-staging.7ac8446 → 0.8.3-main.672df60

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.
Files changed (66) hide show
  1. package/dist/lib/browser/StackMain-HZI5H2RA.mjs +315 -0
  2. package/dist/lib/browser/StackMain-HZI5H2RA.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-L34RFJ2L.mjs → chunk-XOUJQIK6.mjs} +10 -9
  4. package/dist/lib/browser/chunk-XOUJQIK6.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +10 -38
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/react-surface-FIWIAQRE.mjs +46 -0
  9. package/dist/lib/browser/react-surface-FIWIAQRE.mjs.map +7 -0
  10. package/dist/lib/browser/types/index.mjs +1 -1
  11. package/dist/lib/node/StackMain-NPXLFG5C.cjs +329 -0
  12. package/dist/lib/node/StackMain-NPXLFG5C.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-6IPBX635.cjs → chunk-5QWZH22T.cjs} +12 -11
  14. package/dist/lib/node/chunk-5QWZH22T.cjs.map +7 -0
  15. package/dist/lib/node/index.cjs +5 -29
  16. package/dist/lib/node/index.cjs.map +4 -4
  17. package/dist/lib/node/meta.json +1 -1
  18. package/dist/lib/node/react-surface-73G6PBCV.cjs +64 -0
  19. package/dist/lib/node/react-surface-73G6PBCV.cjs.map +7 -0
  20. package/dist/lib/node/types/index.cjs +3 -3
  21. package/dist/lib/node/types/index.cjs.map +1 -1
  22. package/dist/lib/node-esm/StackMain-QH6CGYPK.mjs +316 -0
  23. package/dist/lib/node-esm/StackMain-QH6CGYPK.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-3ZYHKSIS.mjs → chunk-3R62SZZT.mjs} +10 -9
  25. package/dist/lib/node-esm/chunk-3R62SZZT.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +10 -38
  27. package/dist/lib/node-esm/index.mjs.map +4 -4
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/react-surface-SCL5YFJ5.mjs +47 -0
  30. package/dist/lib/node-esm/react-surface-SCL5YFJ5.mjs.map +7 -0
  31. package/dist/lib/node-esm/types/index.mjs +1 -1
  32. package/dist/types/src/StackPlugin.d.ts.map +1 -1
  33. package/dist/types/src/capabilities/index.d.ts +2 -0
  34. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  35. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  36. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  37. package/dist/types/src/components/CaretDownUp.d.ts.map +1 -1
  38. package/dist/types/src/components/StackMain.d.ts.map +1 -1
  39. package/dist/types/src/components/StackSection.d.ts +2 -1
  40. package/dist/types/src/components/StackSection.d.ts.map +1 -1
  41. package/dist/types/src/components/StackSettings.d.ts.map +1 -1
  42. package/dist/types/src/translations.d.ts +1 -0
  43. package/dist/types/src/translations.d.ts.map +1 -1
  44. package/dist/types/src/types/stack.d.ts +11 -11
  45. package/dist/types/src/types/stack.d.ts.map +1 -1
  46. package/dist/types/src/types/types.d.ts +2 -2
  47. package/dist/types/src/types/types.d.ts.map +1 -1
  48. package/dist/types/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +27 -23
  50. package/src/StackPlugin.ts +53 -0
  51. package/src/capabilities/index.ts +7 -0
  52. package/src/capabilities/react-surface.tsx +33 -0
  53. package/src/components/StackMain.tsx +11 -9
  54. package/src/components/StackSection.tsx +8 -6
  55. package/src/types/stack.ts +7 -5
  56. package/src/types/types.ts +2 -2
  57. package/dist/lib/browser/StackMain-E42SHTS6.mjs +0 -295
  58. package/dist/lib/browser/StackMain-E42SHTS6.mjs.map +0 -7
  59. package/dist/lib/browser/chunk-L34RFJ2L.mjs.map +0 -7
  60. package/dist/lib/node/StackMain-4N6IFLMF.cjs +0 -309
  61. package/dist/lib/node/StackMain-4N6IFLMF.cjs.map +0 -7
  62. package/dist/lib/node/chunk-6IPBX635.cjs.map +0 -7
  63. package/dist/lib/node-esm/StackMain-QFKYWI2J.mjs +0 -296
  64. package/dist/lib/node-esm/StackMain-QFKYWI2J.mjs.map +0 -7
  65. package/dist/lib/node-esm/chunk-3ZYHKSIS.mjs.map +0 -7
  66. package/src/StackPlugin.tsx +0 -76
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-stack",
3
- "version": "0.8.2-staging.7ac8446",
3
+ "version": "0.8.3-main.672df60",
4
4
  "description": "DXOS Surface plugin for Stack entities",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -34,26 +34,29 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@fluentui/react-tabster": "^9.24.2",
37
- "@preact/signals-core": "^1.6.0",
37
+ "@preact-signals/safe-react": "^0.9.0",
38
+ "@preact/signals-core": "^1.9.0",
38
39
  "@radix-ui/react-collapsible": "1.1.3",
40
+ "effect": "3.14.21",
39
41
  "node-fetch": "^2.6.0",
40
42
  "react-is": "~18.2.0",
41
- "@dxos/async": "0.8.2-staging.7ac8446",
42
- "@dxos/client": "0.8.2-staging.7ac8446",
43
- "@dxos/app-framework": "0.8.2-staging.7ac8446",
44
- "@dxos/echo-schema": "0.8.2-staging.7ac8446",
45
- "@dxos/invariant": "0.8.2-staging.7ac8446",
46
- "@dxos/plugin-client": "0.8.2-staging.7ac8446",
47
- "@dxos/plugin-deck": "0.8.2-staging.7ac8446",
48
- "@dxos/local-storage": "0.8.2-staging.7ac8446",
49
- "@dxos/plugin-graph": "0.8.2-staging.7ac8446",
50
- "@dxos/plugin-space": "0.8.2-staging.7ac8446",
51
- "@dxos/react-client": "0.8.2-staging.7ac8446",
52
- "@dxos/react-ui-attention": "0.8.2-staging.7ac8446",
53
- "@dxos/react-ui-form": "0.8.2-staging.7ac8446",
54
- "@dxos/react-ui-searchlist": "0.8.2-staging.7ac8446",
55
- "@dxos/react-ui-stack": "0.8.2-staging.7ac8446",
56
- "@dxos/util": "0.8.2-staging.7ac8446"
43
+ "@dxos/app-framework": "0.8.3-main.672df60",
44
+ "@dxos/echo": "0.8.3-main.672df60",
45
+ "@dxos/client": "0.8.3-main.672df60",
46
+ "@dxos/echo-schema": "0.8.3-main.672df60",
47
+ "@dxos/invariant": "0.8.3-main.672df60",
48
+ "@dxos/local-storage": "0.8.3-main.672df60",
49
+ "@dxos/async": "0.8.3-main.672df60",
50
+ "@dxos/plugin-client": "0.8.3-main.672df60",
51
+ "@dxos/plugin-deck": "0.8.3-main.672df60",
52
+ "@dxos/plugin-graph": "0.8.3-main.672df60",
53
+ "@dxos/plugin-space": "0.8.3-main.672df60",
54
+ "@dxos/react-client": "0.8.3-main.672df60",
55
+ "@dxos/react-ui-attention": "0.8.3-main.672df60",
56
+ "@dxos/react-ui-form": "0.8.3-main.672df60",
57
+ "@dxos/react-ui-stack": "0.8.3-main.672df60",
58
+ "@dxos/util": "0.8.3-main.672df60",
59
+ "@dxos/react-ui-searchlist": "0.8.3-main.672df60"
57
60
  },
58
61
  "devDependencies": {
59
62
  "@babel/core": "^7.18.13",
@@ -63,16 +66,17 @@
63
66
  "react": "~18.2.0",
64
67
  "react-dom": "~18.2.0",
65
68
  "vite": "5.4.7",
66
- "@dxos/react-ui": "0.8.2-staging.7ac8446",
67
- "@dxos/react-ui-theme": "0.8.2-staging.7ac8446",
68
- "@dxos/storybook-utils": "0.8.2-staging.7ac8446"
69
+ "@dxos/react-ui": "0.8.3-main.672df60",
70
+ "@dxos/react-ui-theme": "0.8.3-main.672df60",
71
+ "@dxos/storybook-utils": "0.8.3-main.672df60"
69
72
  },
70
73
  "peerDependencies": {
71
74
  "@phosphor-icons/react": "^2.1.5",
75
+ "effect": "^3.13.3",
72
76
  "react": "~18.2.0",
73
77
  "react-dom": "~18.2.0",
74
- "@dxos/react-ui": "0.8.2-staging.7ac8446",
75
- "@dxos/react-ui-theme": "0.8.2-staging.7ac8446"
78
+ "@dxos/react-ui": "0.8.3-main.672df60",
79
+ "@dxos/react-ui-theme": "0.8.3-main.672df60"
76
80
  },
77
81
  "publishConfig": {
78
82
  "access": "public"
@@ -0,0 +1,53 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Capabilities, contributes, defineModule, definePlugin, Events } from '@dxos/app-framework';
6
+ import { type AnyLiveObject } from '@dxos/client/echo';
7
+ import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
8
+
9
+ import { ReactSurface } from './capabilities';
10
+ import { meta, SECTION_IDENTIFIER } from './meta';
11
+ import translations from './translations';
12
+ import { StackViewType } from './types';
13
+
14
+ export const StackPlugin = () =>
15
+ definePlugin(meta, [
16
+ defineModule({
17
+ id: `${meta.id}/module/translations`,
18
+ activatesOn: Events.SetupTranslations,
19
+ activate: () => contributes(Capabilities.Translations, translations),
20
+ }),
21
+ defineModule({
22
+ id: `${meta.id}/module/metadata`,
23
+ activatesOn: Events.SetupMetadata,
24
+ activate: () => [
25
+ contributes(Capabilities.Metadata, {
26
+ id: SECTION_IDENTIFIER,
27
+ metadata: {
28
+ parse: (section: { object: AnyLiveObject<any> }, type: string) => {
29
+ switch (type) {
30
+ case 'node':
31
+ // TODO(wittjosiah): Remove cast.
32
+ return { id: section.object.id, label: section.object.title, data: section.object };
33
+ case 'object':
34
+ return section.object;
35
+ case 'view-object':
36
+ return section;
37
+ }
38
+ },
39
+ },
40
+ }),
41
+ ],
42
+ }),
43
+ defineModule({
44
+ id: `${meta.id}/module/schema`,
45
+ activatesOn: ClientEvents.SetupSchema,
46
+ activate: () => contributes(ClientCapabilities.Schema, [StackViewType]),
47
+ }),
48
+ defineModule({
49
+ id: `${meta.id}/module/react-surface`,
50
+ activatesOn: Events.SetupReactSurface,
51
+ activate: ReactSurface,
52
+ }),
53
+ ]);
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { lazy } from '@dxos/app-framework';
6
+
7
+ export const ReactSurface = lazy(() => import('./react-surface'));
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
+ import { isInstanceOf } from '@dxos/echo-schema';
9
+ import { CollectionType } from '@dxos/plugin-space/types';
10
+ import { fullyQualifiedId } from '@dxos/react-client/echo';
11
+
12
+ import { StackMain } from '../components';
13
+ import { STACK_PLUGIN } from '../meta';
14
+
15
+ export default () =>
16
+ contributes(
17
+ Capabilities.ReactSurface,
18
+ createSurface({
19
+ id: `${STACK_PLUGIN}/article`,
20
+ role: 'article',
21
+ filter: (data): data is { id?: string; subject: CollectionType } => isInstanceOf(CollectionType, data.subject),
22
+ component: ({ data }) => {
23
+ // This allows the id to be overridden by the surface for situations where the id of the collection
24
+ // is not the same as the id of what is being represented (e.g., a space with a root collection).
25
+ const id = typeof data.id === 'string' ? data.id : undefined;
26
+ return (
27
+ <div role='none' className='overflow-auto' style={{ contain: 'layout' }}>
28
+ <StackMain id={id ?? fullyQualifiedId(data.subject)} collection={data.subject} />
29
+ </div>
30
+ );
31
+ },
32
+ }),
33
+ );
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Plus } from '@phosphor-icons/react';
6
+ import { Option } from 'effect';
6
7
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
8
 
8
9
  import {
@@ -13,9 +14,8 @@ import {
13
14
  useCapabilities,
14
15
  useIntentDispatcher,
15
16
  } from '@dxos/app-framework';
16
- import { create, getType, fullyQualifiedId, isReactiveObject, makeRef } from '@dxos/client/echo';
17
- import { SpaceAction } from '@dxos/plugin-space/types';
18
- import { type CollectionType } from '@dxos/plugin-space/types';
17
+ import { fullyQualifiedId, getTypename, isLiveObject, live, makeRef } from '@dxos/client/echo';
18
+ import { SpaceAction, type CollectionType } from '@dxos/plugin-space/types';
19
19
  import { Button, toLocalizedString, useTranslation } from '@dxos/react-ui';
20
20
  import { AttentionProvider } from '@dxos/react-ui-attention';
21
21
  import { Stack } from '@dxos/react-ui-stack';
@@ -26,11 +26,11 @@ import { StackSection } from './StackSection';
26
26
  import { STACK_PLUGIN } from '../meta';
27
27
  import {
28
28
  StackViewType,
29
+ type AddSectionPosition,
29
30
  type CollapsedSections,
31
+ type StackSectionItem,
30
32
  type StackSectionMetadata,
31
33
  type StackSectionView,
32
- type StackSectionItem,
33
- type AddSectionPosition,
34
34
  } from '../types';
35
35
 
36
36
  type StackMainProps = {
@@ -43,7 +43,7 @@ const StackMain = ({ id, collection }: StackMainProps) => {
43
43
  const { graph } = useAppGraph();
44
44
  const { t } = useTranslation(STACK_PLUGIN);
45
45
  const allMetadata = useCapabilities(Capabilities.Metadata);
46
- const defaultStack = useMemo(() => create(StackViewType, { sections: {} }), [collection]);
46
+ const defaultStack = useMemo(() => live(StackViewType, { sections: {} }), [collection]);
47
47
  const stack = (collection.views[StackViewType.typename]?.target as StackViewType | undefined) ?? defaultStack;
48
48
  const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});
49
49
 
@@ -60,13 +60,15 @@ const StackMain = ({ id, collection }: StackMainProps) => {
60
60
  .map((object) => object.target)
61
61
  .filter(isNonNullable)
62
62
  .map((object) => {
63
- const metadata = allMetadata.find((m) => m.id === (getType(object)?.objectId ?? 'never'))
63
+ const metadata = allMetadata.find((m) => m.id === (getTypename(object) ?? 'never'))
64
64
  ?.metadata as StackSectionMetadata;
65
65
  const view = {
66
66
  ...stack.sections[object.id],
67
67
  collapsed: collapsedSections[fullyQualifiedId(object)],
68
68
  title:
69
- (object as any)?.title ?? toLocalizedString(graph.findNode(fullyQualifiedId(object))?.properties.label, t),
69
+ (object as any)?.title ??
70
+ // TODO(wittjosiah): `getNode` is not reactive.
71
+ toLocalizedString(graph.getNode(fullyQualifiedId(object)).pipe(Option.getOrNull)?.properties.label, t),
70
72
  } as StackSectionView;
71
73
  return { id: fullyQualifiedId(object), object, metadata, view } satisfies StackSectionItem;
72
74
  }) ?? [];
@@ -78,7 +80,7 @@ const StackMain = ({ id, collection }: StackMainProps) => {
78
80
  .filter(isNonNullable)
79
81
  .findIndex((section) => fullyQualifiedId(section) === id);
80
82
  const object = collection.objects[index].target;
81
- if (isReactiveObject(object)) {
83
+ if (isLiveObject(object)) {
82
84
  await dispatch(createIntent(SpaceAction.RemoveObjects, { objects: [object], target: collection }));
83
85
 
84
86
  // TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.
@@ -7,7 +7,7 @@ import React, { useState } from 'react';
7
7
 
8
8
  import { Surface } from '@dxos/app-framework';
9
9
  import { DropdownMenu, Icon, useTranslation, IconButton } from '@dxos/react-ui';
10
- import { useAttendableAttributes } from '@dxos/react-ui-attention';
10
+ import { useAttentionAttributes } from '@dxos/react-ui-attention';
11
11
  import { StackItem } from '@dxos/react-ui-stack';
12
12
  import { mx, getSize, textBlockWidth } from '@dxos/react-ui-theme';
13
13
 
@@ -18,20 +18,22 @@ import { type StackSectionItem } from '../types';
18
18
 
19
19
  const sectionActionDimensions = 'p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min';
20
20
 
21
+ export type StackSectionProps = StackSectionItem;
22
+
21
23
  export const StackSection = ({
22
24
  id,
23
25
  view,
24
26
  object,
25
27
  metadata: { icon = 'ph--placeholder--regular' },
26
- }: StackSectionItem) => {
28
+ }: StackSectionProps) => {
27
29
  const { t } = useTranslation(STACK_PLUGIN);
28
30
  const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
29
31
  const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
30
- const attendableAttrs = useAttendableAttributes(id);
32
+ const attentionAttrs = useAttentionAttributes(id);
31
33
 
32
34
  return (
33
35
  <CollapsiblePrimitive.Root asChild open={!view.collapsed} onOpenChange={(nextOpen) => onCollapse?.(id, !nextOpen)}>
34
- <StackItem.Root item={{ id }} role='section' {...attendableAttrs} classNames='border-be border-separator'>
36
+ <StackItem.Root item={{ id }} role='section' {...attentionAttrs} classNames='border-be border-separator'>
35
37
  <StackItem.Heading classNames='attention-surface border-ie !border-separator'>
36
38
  <span className='sr-only'>{view.title}</span>
37
39
  <div role='none' className='sticky -block-start-px bg-[--sticky-bg] p-1 is-full'>
@@ -51,7 +53,7 @@ export const StackSection = ({
51
53
  <DropdownMenu.Viewport>
52
54
  {view.collapsed ? (
53
55
  <DropdownMenu.Item onClick={() => onNavigate(id)} data-testid='section.navigate-to'>
54
- <Icon icon='ph--arrow-square-out--regular' size={5} />
56
+ <Icon icon='ph--arrow-right--regular' size={5} />
55
57
  <span className='mis-2 grow'>{t('navigate to section label')}</span>
56
58
  </DropdownMenu.Item>
57
59
  ) : (
@@ -95,7 +97,7 @@ export const StackSection = ({
95
97
  variant='ghost'
96
98
  onClick={() => onNavigate(id)}
97
99
  label={t('navigate to section label')}
98
- icon='ph--arrow-square-out--regular'
100
+ icon='ph--arrow-right--regular'
99
101
  data-testid='section.navigate-to'
100
102
  classNames={sectionActionDimensions}
101
103
  />
@@ -2,21 +2,23 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { S, TypedObject } from '@dxos/echo-schema';
5
+ import { Schema } from 'effect';
6
+
7
+ import { TypedObject } from '@dxos/echo-schema';
6
8
 
7
9
  // All section metadata needs to be optional/have defaults.
8
10
  // Any objects added to the collection will start with the section defaults.
9
11
  // If an object is removed from the collection without removing the section metadata this is fine.
10
12
  // Stack components should clean-up the superfluous data on future edits.
11
13
 
12
- export const SectionSchema = S.Struct({
13
- height: S.optional(S.Number),
14
+ export const SectionSchema = Schema.Struct({
15
+ height: Schema.optional(Schema.Number),
14
16
  // Space for data that isn't stack-specific but is specific to this view instance.
15
17
  // e.g. cover/fill for an image
16
- custom: S.optional(S.Record({ key: S.String, value: S.Any })),
18
+ custom: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
17
19
  });
18
20
 
19
21
  // TODO(burdon): Should be just type/Stack?
20
22
  export class StackViewType extends TypedObject({ typename: 'dxos.org/type/StackView', version: '0.1.0' })({
21
- sections: S.mutable(S.Record({ key: S.String, value: SectionSchema })),
23
+ sections: Schema.mutable(Schema.Record({ key: Schema.String, value: SectionSchema })),
22
24
  }) {}
@@ -6,7 +6,7 @@ import { type IconProps } from '@phosphor-icons/react';
6
6
  import { type FC } from 'react';
7
7
 
8
8
  import { type CollectionType } from '@dxos/plugin-space/types';
9
- import { type ReactiveEchoObject } from '@dxos/react-client/echo';
9
+ import { type AnyLiveObject } from '@dxos/react-client/echo';
10
10
  import { type Label } from '@dxos/react-ui';
11
11
  import { type StackItemSize } from '@dxos/react-ui-stack';
12
12
 
@@ -40,7 +40,7 @@ export type StackSectionMetadata = {
40
40
 
41
41
  export type StackSectionItem = {
42
42
  id: string;
43
- object: ReactiveEchoObject<any>;
43
+ object: AnyLiveObject<any>;
44
44
  view: StackSectionView;
45
45
  metadata: StackSectionMetadata;
46
46
  };
@@ -1,295 +0,0 @@
1
- import {
2
- STACK_PLUGIN
3
- } from "./chunk-XHZTILS3.mjs";
4
- import {
5
- StackViewType
6
- } from "./chunk-L34RFJ2L.mjs";
7
-
8
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
9
- import { Plus } from "@phosphor-icons/react";
10
- import React3, { useCallback, useEffect, useMemo, useState as useState2 } from "react";
11
- import { Capabilities, createIntent, LayoutAction, useAppGraph, useCapabilities, useIntentDispatcher } from "@dxos/app-framework";
12
- import { create, getType, fullyQualifiedId, isReactiveObject, makeRef } from "@dxos/client/echo";
13
- import { SpaceAction } from "@dxos/plugin-space/types";
14
- import { Button, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
15
- import { AttentionProvider } from "@dxos/react-ui-attention";
16
- import { Stack } from "@dxos/react-ui-stack";
17
- import { isNonNullable } from "@dxos/util";
18
-
19
- // packages/plugins/plugin-stack/src/components/StackContext.tsx
20
- import { createContext, useContext } from "react";
21
- var StackContext = /* @__PURE__ */ createContext({
22
- onCollapse: () => {
23
- },
24
- onNavigate: async () => {
25
- },
26
- onDelete: async () => {
27
- },
28
- onAdd: () => {
29
- }
30
- });
31
- var useStack = () => useContext(StackContext);
32
-
33
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
34
- import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
35
- import React2, { useState } from "react";
36
- import { Surface } from "@dxos/app-framework";
37
- import { DropdownMenu, Icon, useTranslation, IconButton } from "@dxos/react-ui";
38
- import { useAttendableAttributes } from "@dxos/react-ui-attention";
39
- import { StackItem } from "@dxos/react-ui-stack";
40
- import { mx, getSize, textBlockWidth } from "@dxos/react-ui-theme";
41
-
42
- // packages/plugins/plugin-stack/src/components/CaretDownUp.tsx
43
- import React from "react";
44
- var CaretDownUp = ({ children, ...props }) => {
45
- return /* @__PURE__ */ React.createElement("svg", {
46
- xmlns: "http://www.w3.org/2000/svg",
47
- viewBox: "0 0 256 256",
48
- ...props
49
- }, /* @__PURE__ */ React.createElement("rect", {
50
- width: "256",
51
- height: "256",
52
- fill: "none"
53
- }), /* @__PURE__ */ React.createElement("polyline", {
54
- points: "80 224 128 176 176 224",
55
- fill: "none",
56
- stroke: "currentColor",
57
- strokeLinecap: "round",
58
- strokeLinejoin: "round",
59
- strokeWidth: "16"
60
- }), /* @__PURE__ */ React.createElement("polyline", {
61
- points: "80 32 128 80 176 32",
62
- fill: "none",
63
- stroke: "currentColor",
64
- strokeLinecap: "round",
65
- strokeLinejoin: "round",
66
- strokeWidth: "16"
67
- }), children);
68
- };
69
-
70
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
71
- var sectionActionDimensions = "p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
72
- var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
73
- const { t } = useTranslation(STACK_PLUGIN);
74
- const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
75
- const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
76
- const attendableAttrs = useAttendableAttributes(id);
77
- return /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Root, {
78
- asChild: true,
79
- open: !view.collapsed,
80
- onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
81
- }, /* @__PURE__ */ React2.createElement(StackItem.Root, {
82
- item: {
83
- id
84
- },
85
- role: "section",
86
- ...attendableAttrs,
87
- classNames: "border-be border-separator"
88
- }, /* @__PURE__ */ React2.createElement(StackItem.Heading, {
89
- classNames: "attention-surface border-ie !border-separator"
90
- }, /* @__PURE__ */ React2.createElement("span", {
91
- className: "sr-only"
92
- }, view.title), /* @__PURE__ */ React2.createElement("div", {
93
- role: "none",
94
- className: "sticky -block-start-px bg-[--sticky-bg] p-1 is-full"
95
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Root, {
96
- open: optionsMenuOpen,
97
- onOpenChange: setOptionsMenuOpen
98
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
99
- asChild: true
100
- }, /* @__PURE__ */ React2.createElement(StackItem.SigilButton, null, /* @__PURE__ */ React2.createElement(Icon, {
101
- icon,
102
- size: 5,
103
- classNames: "transition-opacity"
104
- }))), /* @__PURE__ */ React2.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Viewport, null, view.collapsed ? /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
105
- onClick: () => onNavigate(id),
106
- "data-testid": "section.navigate-to"
107
- }, /* @__PURE__ */ React2.createElement(Icon, {
108
- icon: "ph--arrow-square-out--regular",
109
- size: 5
110
- }), /* @__PURE__ */ React2.createElement("span", {
111
- className: "mis-2 grow"
112
- }, t("navigate to section label"))) : /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
113
- asChild: true
114
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Item, null, /* @__PURE__ */ React2.createElement(CaretDownUp, {
115
- className: getSize(5)
116
- }), /* @__PURE__ */ React2.createElement("span", {
117
- className: "mis-2 grow"
118
- }, t("collapse label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
119
- onClick: () => onAdd(id, "before"),
120
- "data-testid": "section.add-before"
121
- }, /* @__PURE__ */ React2.createElement(Icon, {
122
- icon: "ph--arrow-line-up--regular",
123
- size: 5
124
- }), /* @__PURE__ */ React2.createElement("span", {
125
- className: "mis-2 grow"
126
- }, t("add section before label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
127
- onClick: () => onAdd(id, "after"),
128
- "data-testid": "section.add-after"
129
- }, /* @__PURE__ */ React2.createElement(Icon, {
130
- icon: "ph--arrow-line-down--regular",
131
- size: 5
132
- }), /* @__PURE__ */ React2.createElement("span", {
133
- className: "mis-2 grow"
134
- }, t("add section after label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
135
- onClick: () => onDelete(id),
136
- "data-testid": "section.remove"
137
- }, /* @__PURE__ */ React2.createElement(Icon, {
138
- icon: "ph--trash--regular",
139
- size: 5
140
- }), /* @__PURE__ */ React2.createElement("span", {
141
- className: "mis-2 grow"
142
- }, t("remove section label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
143
- asChild: true
144
- }, /* @__PURE__ */ React2.createElement(IconButton, {
145
- iconOnly: true,
146
- variant: "ghost",
147
- label: t("expand label"),
148
- icon: "ph--caret-up-down--regular",
149
- classNames: sectionActionDimensions
150
- })) : /* @__PURE__ */ React2.createElement(IconButton, {
151
- iconOnly: true,
152
- variant: "ghost",
153
- onClick: () => onNavigate(id),
154
- label: t("navigate to section label"),
155
- icon: "ph--arrow-square-out--regular",
156
- "data-testid": "section.navigate-to",
157
- classNames: sectionActionDimensions
158
- }))), /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ React2.createElement(Surface, {
159
- role: "section",
160
- data: {
161
- subject: object
162
- },
163
- limit: 1,
164
- placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
165
- })), view.collapsed && /* @__PURE__ */ React2.createElement(StackItem.Content, {
166
- classNames: "attention-surface"
167
- }, /* @__PURE__ */ React2.createElement("h2", {
168
- className: mx("flex items-center p-4 font-medium", textBlockWidth)
169
- }, view.title))));
170
- };
171
-
172
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
173
- var StackMain = ({ id, collection }) => {
174
- const { dispatchPromise: dispatch } = useIntentDispatcher();
175
- const { graph } = useAppGraph();
176
- const { t } = useTranslation2(STACK_PLUGIN);
177
- const allMetadata = useCapabilities(Capabilities.Metadata);
178
- const defaultStack = useMemo(() => create(StackViewType, {
179
- sections: {}
180
- }), [
181
- collection
182
- ]);
183
- const stack = collection.views[StackViewType.typename]?.target ?? defaultStack;
184
- const [collapsedSections, setCollapsedSections] = useState2({});
185
- useEffect(() => {
186
- if (!collection.views[StackViewType.typename]) {
187
- collection.views[StackViewType.typename] = makeRef(stack);
188
- }
189
- }, [
190
- collection,
191
- stack
192
- ]);
193
- const items = collection.objects.map((object) => object.target).filter(isNonNullable).map((object) => {
194
- const metadata = allMetadata.find((m) => m.id === (getType(object)?.objectId ?? "never"))?.metadata;
195
- const view = {
196
- ...stack.sections[object.id],
197
- collapsed: collapsedSections[fullyQualifiedId(object)],
198
- title: object?.title ?? toLocalizedString(graph.findNode(fullyQualifiedId(object))?.properties.label, t)
199
- };
200
- return {
201
- id: fullyQualifiedId(object),
202
- object,
203
- metadata,
204
- view
205
- };
206
- }) ?? [];
207
- const handleDelete = useCallback(async (id2) => {
208
- const index = collection.objects.map((object2) => object2.target).filter(isNonNullable).findIndex((section) => fullyQualifiedId(section) === id2);
209
- const object = collection.objects[index].target;
210
- if (isReactiveObject(object)) {
211
- await dispatch(createIntent(SpaceAction.RemoveObjects, {
212
- objects: [
213
- object
214
- ],
215
- target: collection
216
- }));
217
- }
218
- }, [
219
- collection,
220
- dispatch
221
- ]);
222
- const handleAdd = useCallback(async (id2, position) => {
223
- await dispatch?.(
224
- // TODO(wittjosiah): Use object creation dialog.
225
- createIntent(LayoutAction.UpdateDialog, {
226
- part: "dialog",
227
- subject: `${STACK_PLUGIN}/AddSectionDialog`,
228
- options: {
229
- blockAlign: "start",
230
- props: {
231
- path: id2,
232
- position,
233
- collection
234
- }
235
- }
236
- })
237
- );
238
- }, [
239
- collection,
240
- dispatch
241
- ]);
242
- const handleNavigate = useCallback(async (id2) => {
243
- await dispatch(createIntent(LayoutAction.Open, {
244
- part: "main",
245
- subject: [
246
- id2
247
- ]
248
- }));
249
- }, [
250
- dispatch
251
- ]);
252
- const handleCollapse = useCallback((id2, collapsed) => setCollapsedSections((prev) => ({
253
- ...prev,
254
- [id2]: collapsed
255
- })), []);
256
- const handleAddSection = useCallback(() => dispatch?.(createIntent(SpaceAction.OpenCreateObject, {
257
- target: collection,
258
- navigable: false
259
- })), [
260
- collection,
261
- dispatch
262
- ]);
263
- return /* @__PURE__ */ React3.createElement(AttentionProvider, {
264
- id
265
- }, /* @__PURE__ */ React3.createElement(StackContext.Provider, {
266
- value: {
267
- onCollapse: handleCollapse,
268
- onNavigate: handleNavigate,
269
- onDelete: handleDelete,
270
- onAdd: handleAdd
271
- }
272
- }, /* @__PURE__ */ React3.createElement(Stack, {
273
- orientation: "vertical",
274
- size: "intrinsic",
275
- id,
276
- "data-testid": "main.stack"
277
- }, items.map((item) => /* @__PURE__ */ React3.createElement(StackSection, {
278
- key: item.id,
279
- ...item
280
- }))), /* @__PURE__ */ React3.createElement("div", {
281
- role: "none",
282
- className: "flex mlb-2 pli-2 justify-center"
283
- }, /* @__PURE__ */ React3.createElement(Button, {
284
- "data-testid": "stack.createSection",
285
- classNames: "gap-2",
286
- onClick: handleAddSection
287
- }, /* @__PURE__ */ React3.createElement(Plus, null), /* @__PURE__ */ React3.createElement("span", {
288
- className: "sr-only"
289
- }, t("add section label"))))));
290
- };
291
- var StackMain_default = StackMain;
292
- export {
293
- StackMain_default as default
294
- };
295
- //# sourceMappingURL=StackMain-E42SHTS6.mjs.map