@dxos/plugin-stack 0.7.4 → 0.7.5-main.9d26e3a

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 (43) hide show
  1. package/dist/lib/browser/StackMain-HSYQ5B3Y.mjs +295 -0
  2. package/dist/lib/browser/StackMain-HSYQ5B3Y.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +28 -163
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/node/StackMain-AWN5MFZK.cjs +309 -0
  7. package/dist/lib/node/StackMain-AWN5MFZK.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +28 -161
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node-esm/StackMain-EFCZCMIJ.mjs +296 -0
  12. package/dist/lib/node-esm/StackMain-EFCZCMIJ.mjs.map +7 -0
  13. package/dist/lib/node-esm/index.mjs +28 -163
  14. package/dist/lib/node-esm/index.mjs.map +4 -4
  15. package/dist/lib/node-esm/meta.json +1 -1
  16. package/dist/types/src/StackPlugin.d.ts.map +1 -1
  17. package/dist/types/src/components/StackMain.d.ts.map +1 -1
  18. package/dist/types/src/components/StackSection.d.ts.map +1 -1
  19. package/dist/types/src/components/index.d.ts +0 -1
  20. package/dist/types/src/components/index.d.ts.map +1 -1
  21. package/dist/types/src/types/stack.d.ts +6 -12
  22. package/dist/types/src/types/stack.d.ts.map +1 -1
  23. package/dist/types/src/types/types.d.ts +4 -16
  24. package/dist/types/src/types/types.d.ts.map +1 -1
  25. package/dist/types/tsconfig.tsbuildinfo +1 -0
  26. package/package.json +23 -23
  27. package/src/StackPlugin.tsx +26 -47
  28. package/src/components/StackMain.tsx +60 -69
  29. package/src/components/StackSection.tsx +2 -4
  30. package/src/components/index.ts +0 -1
  31. package/src/types/types.ts +3 -19
  32. package/dist/lib/browser/StackMain-4D4J4IRK.mjs +0 -391
  33. package/dist/lib/browser/StackMain-4D4J4IRK.mjs.map +0 -7
  34. package/dist/lib/node/StackMain-V7C55NCF.cjs +0 -403
  35. package/dist/lib/node/StackMain-V7C55NCF.cjs.map +0 -7
  36. package/dist/lib/node-esm/StackMain-5I43UWGF.mjs +0 -392
  37. package/dist/lib/node-esm/StackMain-5I43UWGF.mjs.map +0 -7
  38. package/dist/types/src/components/AddSection.d.ts +0 -6
  39. package/dist/types/src/components/AddSection.d.ts.map +0 -1
  40. package/dist/types/src/components/AddSectionDialog.d.ts +0 -14
  41. package/dist/types/src/components/AddSectionDialog.d.ts.map +0 -1
  42. package/src/components/AddSection.tsx +0 -102
  43. package/src/components/AddSectionDialog.tsx +0 -128
@@ -3,16 +3,17 @@
3
3
  //
4
4
 
5
5
  import { Plus } from '@phosphor-icons/react';
6
- import React, { useEffect, useMemo, useState } from 'react';
6
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
7
 
8
8
  import {
9
+ createIntent,
9
10
  LayoutAction,
10
11
  NavigationAction,
11
12
  parseMetadataResolverPlugin,
12
13
  useIntentDispatcher,
13
14
  useResolvePlugin,
14
15
  } from '@dxos/app-framework';
15
- import { create, getType, fullyQualifiedId } from '@dxos/client/echo';
16
+ import { create, getType, fullyQualifiedId, isReactiveObject, makeRef } from '@dxos/client/echo';
16
17
  import { useGraph } from '@dxos/plugin-graph';
17
18
  import { SpaceAction } from '@dxos/plugin-space';
18
19
  import { type CollectionType } from '@dxos/plugin-space/types';
@@ -21,7 +22,6 @@ import { AttentionProvider } from '@dxos/react-ui-attention';
21
22
  import { Stack } from '@dxos/react-ui-stack';
22
23
  import { nonNullable } from '@dxos/util';
23
24
 
24
- import { AddSection } from './AddSection';
25
25
  import { StackContext } from './StackContext';
26
26
  import { StackSection } from './StackSection';
27
27
  import { STACK_PLUGIN } from '../meta';
@@ -40,17 +40,17 @@ type StackMainProps = {
40
40
  };
41
41
 
42
42
  const StackMain = ({ id, collection }: StackMainProps) => {
43
- const dispatch = useIntentDispatcher();
43
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
44
44
  const { graph } = useGraph();
45
45
  const { t } = useTranslation(STACK_PLUGIN);
46
46
  const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
47
47
  const defaultStack = useMemo(() => create(StackViewType, { sections: {} }), [collection]);
48
- const stack = (collection.views[StackViewType.typename] as StackViewType) ?? defaultStack;
48
+ const stack = (collection.views[StackViewType.typename]?.target as StackViewType | undefined) ?? defaultStack;
49
49
  const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});
50
50
 
51
51
  useEffect(() => {
52
52
  if (!collection.views[StackViewType.typename]) {
53
- collection.views[StackViewType.typename] = stack;
53
+ collection.views[StackViewType.typename] = makeRef(stack);
54
54
  }
55
55
  }, [collection, stack]);
56
56
 
@@ -58,6 +58,7 @@ const StackMain = ({ id, collection }: StackMainProps) => {
58
58
  collection.objects
59
59
  // TODO(wittjosiah): Should the database handle this differently?
60
60
  // TODO(wittjosiah): Render placeholders for missing objects so they can be removed from the stack?
61
+ .map((object) => object.target)
61
62
  .filter(nonNullable)
62
63
  .map((object) => {
63
64
  const metadata = metadataPlugin?.provides.metadata.resolver(
@@ -72,46 +73,53 @@ const StackMain = ({ id, collection }: StackMainProps) => {
72
73
  return { id: fullyQualifiedId(object), object, metadata, view } satisfies StackSectionItem;
73
74
  }) ?? [];
74
75
 
75
- const handleDelete = async (id: string) => {
76
- const index = collection.objects.filter(nonNullable).findIndex((section) => fullyQualifiedId(section) === id);
77
- if (index >= 0) {
78
- await dispatch({
79
- action: SpaceAction.REMOVE_OBJECTS,
80
- data: { objects: [collection.objects[index]], collection },
81
- });
76
+ const handleDelete = useCallback(
77
+ async (id: string) => {
78
+ const index = collection.objects
79
+ .map((object) => object.target)
80
+ .filter(nonNullable)
81
+ .findIndex((section) => fullyQualifiedId(section) === id);
82
+ const object = collection.objects[index].target;
83
+ if (isReactiveObject(object)) {
84
+ await dispatch(createIntent(SpaceAction.RemoveObjects, { objects: [object], target: collection }));
82
85
 
83
- // TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.
84
- // delete stack.sections[Path.last(path)];
85
- }
86
- };
87
-
88
- const handleAdd = (id: string, position: AddSectionPosition) => {
89
- void dispatch?.({
90
- action: LayoutAction.SET_LAYOUT,
91
- data: {
92
- element: 'dialog',
93
- component: `${STACK_PLUGIN}/AddSectionDialog`,
94
- subject: { path: id, position, collection },
95
- },
96
- });
97
- };
98
-
99
- const handleNavigate = async (id: string) => {
100
- await dispatch([
101
- {
102
- action: NavigationAction.OPEN,
103
- data: { activeParts: { main: [id] } },
104
- },
105
- {
106
- action: LayoutAction.SCROLL_INTO_VIEW,
107
- data: { id },
108
- },
109
- ]);
110
- };
111
-
112
- const handleCollapse = (id: string, collapsed: boolean) => {
113
- setCollapsedSections((prev) => ({ ...prev, [id]: collapsed }));
114
- };
86
+ // TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.
87
+ // delete stack.sections[Path.last(path)];
88
+ }
89
+ },
90
+ [collection, dispatch],
91
+ );
92
+
93
+ const handleAdd = useCallback(
94
+ async (id: string, position: AddSectionPosition) => {
95
+ await dispatch?.(
96
+ createIntent(LayoutAction.SetLayout, {
97
+ element: 'dialog',
98
+ component: `${STACK_PLUGIN}/AddSectionDialog`,
99
+ subject: { path: id, position, collection },
100
+ }),
101
+ );
102
+ },
103
+ [collection, dispatch],
104
+ );
105
+
106
+ const handleNavigate = useCallback(
107
+ async (id: string) => {
108
+ await dispatch(createIntent(NavigationAction.Open, { activeParts: { main: [id] } }));
109
+ await dispatch(createIntent(LayoutAction.ScrollIntoView, { id }));
110
+ },
111
+ [dispatch],
112
+ );
113
+
114
+ const handleCollapse = useCallback(
115
+ (id: string, collapsed: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: collapsed })),
116
+ [],
117
+ );
118
+
119
+ const handleAddSection = useCallback(
120
+ () => dispatch?.(createIntent(SpaceAction.OpenCreateObject, { target: collection, navigable: false })),
121
+ [collection, dispatch],
122
+ );
115
123
 
116
124
  return (
117
125
  <AttentionProvider id={id}>
@@ -123,35 +131,18 @@ const StackMain = ({ id, collection }: StackMainProps) => {
123
131
  onAdd: handleAdd,
124
132
  }}
125
133
  >
126
- <Stack orientation='vertical' size='intrinsic' separators={false} id={id} data-testid='main.stack'>
134
+ <Stack orientation='vertical' size='intrinsic' id={id} data-testid='main.stack'>
127
135
  {items.map((item) => (
128
136
  <StackSection key={item.id} {...item} />
129
137
  ))}
130
138
  </Stack>
131
139
 
132
- {items.length === 0 ? (
133
- <AddSection collection={collection} />
134
- ) : (
135
- <div role='none' className='flex mlb-2 pli-2 justify-center'>
136
- <Button
137
- data-testid='stack.createSection'
138
- classNames='gap-2'
139
- onClick={() =>
140
- dispatch?.({
141
- action: LayoutAction.SET_LAYOUT,
142
- data: {
143
- element: 'dialog',
144
- component: 'dxos.org/plugin/stack/AddSectionDialog',
145
- subject: { position: 'afterAll', collection },
146
- },
147
- })
148
- }
149
- >
150
- <Plus />
151
- <span className='sr-only'>{t('add section label')}</span>
152
- </Button>
153
- </div>
154
- )}
140
+ <div role='none' className='flex mlb-2 pli-2 justify-center'>
141
+ <Button data-testid='stack.createSection' classNames='gap-2' onClick={handleAddSection}>
142
+ <Plus />
143
+ <span className='sr-only'>{t('add section label')}</span>
144
+ </Button>
145
+ </div>
155
146
  </StackContext.Provider>
156
147
  </AttentionProvider>
157
148
  );
@@ -47,7 +47,7 @@ export const StackSection = ({
47
47
  </StackItem.SigilButton>
48
48
  </DropdownMenu.Trigger>
49
49
  <DropdownMenu.Portal>
50
- <DropdownMenu.Content style={{ zIndex: 70 }}>
50
+ <DropdownMenu.Content>
51
51
  <DropdownMenu.Viewport>
52
52
  {view.collapsed ? (
53
53
  <DropdownMenu.Item onClick={() => onNavigate(id)} data-testid='section.navigate-to'>
@@ -83,7 +83,6 @@ export const StackSection = ({
83
83
  <CollapsiblePrimitive.Trigger asChild>
84
84
  <IconButton
85
85
  iconOnly
86
- tooltipZIndex='70'
87
86
  variant='ghost'
88
87
  label={t('expand label')}
89
88
  icon='ph--caret-up-down--regular'
@@ -93,7 +92,6 @@ export const StackSection = ({
93
92
  ) : (
94
93
  <IconButton
95
94
  iconOnly
96
- tooltipZIndex='70'
97
95
  variant='ghost'
98
96
  onClick={() => onNavigate(id)}
99
97
  label={t('navigate to section label')}
@@ -105,7 +103,7 @@ export const StackSection = ({
105
103
  </div>
106
104
  </StackItem.Heading>
107
105
  <CollapsiblePrimitive.Content>
108
- <Surface role='section' data={{ object }} limit={1} placeholder={<></>} />
106
+ <Surface role='section' data={{ subject: object }} limit={1} placeholder={<></>} />
109
107
  </CollapsiblePrimitive.Content>
110
108
  {view.collapsed && (
111
109
  <StackItem.Content toolbar={false} classNames='attention-surface'>
@@ -7,4 +7,3 @@ import { lazy } from 'react';
7
7
  export const StackMain = lazy(() => import('./StackMain'));
8
8
 
9
9
  export * from './StackSettings';
10
- export * from './AddSectionDialog';
@@ -6,7 +6,6 @@ import { type IconProps } from '@phosphor-icons/react';
6
6
  import { type FC } from 'react';
7
7
 
8
8
  import type {
9
- Intent,
10
9
  MetadataRecordsProvides,
11
10
  SettingsProvides,
12
11
  SurfaceProvides,
@@ -14,6 +13,7 @@ import type {
14
13
  } from '@dxos/app-framework';
15
14
  import { type SchemaProvides } from '@dxos/plugin-space';
16
15
  import { type CollectionType } from '@dxos/plugin-space/types';
16
+ import { type ReactiveEchoObject } from '@dxos/react-client/echo';
17
17
  import { type Label } from '@dxos/react-ui';
18
18
  import { type StackItemSize } from '@dxos/react-ui-stack';
19
19
 
@@ -31,8 +31,6 @@ export type StackSectionView = {
31
31
  custom?: Record<string, any>;
32
32
  };
33
33
 
34
- // TODO(wittjosiah): Creators/choosers likely aren't stack-specific.
35
- // Also distinct from graph actions though, output should be inserted into current view rather than navigated to.
36
34
  type StackSectionAction = {
37
35
  id: string;
38
36
  testId: string;
@@ -49,29 +47,15 @@ export type StackSectionMetadata = {
49
47
 
50
48
  export type StackSectionItem = {
51
49
  id: string;
52
- object: CollectionType['objects'][number];
50
+ object: ReactiveEchoObject<any>;
53
51
  view: StackSectionView;
54
52
  metadata: StackSectionMetadata;
55
53
  };
56
54
 
57
- export type StackSectionCreator = StackSectionAction & {
58
- intent: Intent | Intent[];
59
- };
60
-
61
- export type StackProvides = {
62
- stack: {
63
- creators?: StackSectionCreator[];
64
- };
65
- };
66
-
67
- export type StackState = {
68
- creators: StackSectionCreator[];
69
- };
70
-
71
55
  export type StackSettingsProps = { separation: boolean };
72
56
 
73
57
  export type StackPluginProvides = SurfaceProvides &
74
58
  MetadataRecordsProvides &
75
59
  SettingsProvides<StackSettingsProps> &
76
60
  TranslationsProvides &
77
- SchemaProvides & { stack: StackState };
61
+ SchemaProvides;
@@ -1,391 +0,0 @@
1
- import {
2
- STACK_PLUGIN
3
- } from "./chunk-DS5KGEJG.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 React4, { useEffect, useMemo, useState as useState2 } from "react";
11
- import { LayoutAction, NavigationAction, parseMetadataResolverPlugin, useIntentDispatcher as useIntentDispatcher2, useResolvePlugin } from "@dxos/app-framework";
12
- import { create, getType, fullyQualifiedId } from "@dxos/client/echo";
13
- import { useGraph } from "@dxos/plugin-graph";
14
- import { SpaceAction } from "@dxos/plugin-space";
15
- import { Button, toLocalizedString as toLocalizedString2, useTranslation as useTranslation3 } from "@dxos/react-ui";
16
- import { AttentionProvider } from "@dxos/react-ui-attention";
17
- import { Stack } from "@dxos/react-ui-stack";
18
- import { nonNullable } from "@dxos/util";
19
-
20
- // packages/plugins/plugin-stack/src/components/AddSection.tsx
21
- import { useArrowNavigationGroup } from "@fluentui/react-tabster";
22
- import React, { useCallback } from "react";
23
- import { usePlugin, useIntentDispatcher } from "@dxos/app-framework";
24
- import { toLocalizedString, useTranslation } from "@dxos/react-ui";
25
- import { getSize, mx } from "@dxos/react-ui-theme";
26
- var CreatorTile = ({ Icon: Icon2, label, testId, handleAdd }) => {
27
- const onClick = useCallback((_) => handleAdd(), [
28
- handleAdd
29
- ]);
30
- const onKeyDown = useCallback((event) => {
31
- if (event.key === "Enter" || event.key === " ") {
32
- event.preventDefault();
33
- handleAdd();
34
- }
35
- }, [
36
- handleAdd
37
- ]);
38
- return /* @__PURE__ */ React.createElement("div", {
39
- role: "button",
40
- "aria-label": label,
41
- tabIndex: 0,
42
- className: mx("flex items-center w-[10rem] h-16 overflow-hidden", "border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer"),
43
- onClick,
44
- onKeyDown,
45
- "data-testid": testId
46
- }, /* @__PURE__ */ React.createElement("div", {
47
- className: "flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator"
48
- }, /* @__PURE__ */ React.createElement(Icon2, {
49
- weight: "thin",
50
- className: getSize(6)
51
- })), /* @__PURE__ */ React.createElement("div", {
52
- className: "overflow-hidden items-center p-2 px-3"
53
- }, /* @__PURE__ */ React.createElement("span", {
54
- className: "capitalize"
55
- }, label)));
56
- };
57
- var AddSection = ({ collection }) => {
58
- const domAttributes = useArrowNavigationGroup({
59
- axis: "grid"
60
- });
61
- const dispatch = useIntentDispatcher();
62
- const { t } = useTranslation(STACK_PLUGIN);
63
- const stackPlugin = usePlugin(STACK_PLUGIN);
64
- const stackCreators = stackPlugin?.provides?.stack.creators ?? [];
65
- const handleAdd = useCallback(async (creator) => {
66
- const { data: section } = await dispatch(creator.intent) ?? {};
67
- collection.objects = [
68
- section
69
- ];
70
- const stack = collection.views[StackViewType.typename];
71
- if (stack) {
72
- stack.sections[section.id] = {};
73
- }
74
- }, [
75
- collection,
76
- dispatch
77
- ]);
78
- if (stackCreators.length === 0) {
79
- return null;
80
- }
81
- return /* @__PURE__ */ React.createElement("div", {
82
- ...domAttributes,
83
- role: "none",
84
- className: "flex flex-wrap items-center p-8 gap-4"
85
- }, stackCreators.map((creator) => {
86
- const { id, type, icon, testId } = creator;
87
- return /* @__PURE__ */ React.createElement(CreatorTile, {
88
- key: id,
89
- label: toLocalizedString(type, t),
90
- testId,
91
- Icon: icon,
92
- handleAdd: () => handleAdd(creator)
93
- });
94
- }));
95
- };
96
-
97
- // packages/plugins/plugin-stack/src/components/StackContext.tsx
98
- import { createContext, useContext } from "react";
99
- var StackContext = /* @__PURE__ */ createContext({
100
- onCollapse: () => {
101
- },
102
- onNavigate: async () => {
103
- },
104
- onDelete: async () => {
105
- },
106
- onAdd: () => {
107
- }
108
- });
109
- var useStack = () => useContext(StackContext);
110
-
111
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
112
- import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
113
- import React3, { useState } from "react";
114
- import { Surface } from "@dxos/app-framework";
115
- import { DropdownMenu, Icon, useTranslation as useTranslation2, IconButton } from "@dxos/react-ui";
116
- import { useAttendableAttributes } from "@dxos/react-ui-attention";
117
- import { StackItem } from "@dxos/react-ui-stack";
118
- import { mx as mx2, getSize as getSize2, textBlockWidth } from "@dxos/react-ui-theme";
119
-
120
- // packages/plugins/plugin-stack/src/components/CaretDownUp.tsx
121
- import React2 from "react";
122
- var CaretDownUp = ({ children, ...props }) => {
123
- return /* @__PURE__ */ React2.createElement("svg", {
124
- xmlns: "http://www.w3.org/2000/svg",
125
- viewBox: "0 0 256 256",
126
- ...props
127
- }, /* @__PURE__ */ React2.createElement("rect", {
128
- width: "256",
129
- height: "256",
130
- fill: "none"
131
- }), /* @__PURE__ */ React2.createElement("polyline", {
132
- points: "80 224 128 176 176 224",
133
- fill: "none",
134
- stroke: "currentColor",
135
- strokeLinecap: "round",
136
- strokeLinejoin: "round",
137
- strokeWidth: "16"
138
- }), /* @__PURE__ */ React2.createElement("polyline", {
139
- points: "80 32 128 80 176 32",
140
- fill: "none",
141
- stroke: "currentColor",
142
- strokeLinecap: "round",
143
- strokeLinejoin: "round",
144
- strokeWidth: "16"
145
- }), children);
146
- };
147
-
148
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
149
- var sectionActionDimensions = "m-1 p-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
150
- var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
151
- const { t } = useTranslation2(STACK_PLUGIN);
152
- const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
153
- const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
154
- const attendableAttrs = useAttendableAttributes(id);
155
- return /* @__PURE__ */ React3.createElement(CollapsiblePrimitive.Root, {
156
- asChild: true,
157
- open: !view.collapsed,
158
- onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
159
- }, /* @__PURE__ */ React3.createElement(StackItem.Root, {
160
- item: {
161
- id
162
- },
163
- role: "section",
164
- ...attendableAttrs,
165
- classNames: "border-be border-separator"
166
- }, /* @__PURE__ */ React3.createElement(StackItem.Heading, {
167
- classNames: "attention-surface border-ie !border-separator"
168
- }, /* @__PURE__ */ React3.createElement("span", {
169
- className: "sr-only"
170
- }, view.title), /* @__PURE__ */ React3.createElement("div", {
171
- role: "none",
172
- className: "sticky -block-start-px bg-[--sticky-bg]"
173
- }, /* @__PURE__ */ React3.createElement(DropdownMenu.Root, {
174
- open: optionsMenuOpen,
175
- onOpenChange: setOptionsMenuOpen
176
- }, /* @__PURE__ */ React3.createElement(DropdownMenu.Trigger, {
177
- asChild: true
178
- }, /* @__PURE__ */ React3.createElement(StackItem.SigilButton, null, /* @__PURE__ */ React3.createElement(Icon, {
179
- icon,
180
- size: 5,
181
- classNames: "transition-opacity"
182
- }))), /* @__PURE__ */ React3.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Content, {
183
- style: {
184
- zIndex: 70
185
- }
186
- }, /* @__PURE__ */ React3.createElement(DropdownMenu.Viewport, null, view.collapsed ? /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
187
- onClick: () => onNavigate(id),
188
- "data-testid": "section.navigate-to"
189
- }, /* @__PURE__ */ React3.createElement(Icon, {
190
- icon: "ph--arrow-square-out--regular",
191
- size: 5
192
- }), /* @__PURE__ */ React3.createElement("span", {
193
- className: "mis-2 grow"
194
- }, t("navigate to section label"))) : /* @__PURE__ */ React3.createElement(CollapsiblePrimitive.Trigger, {
195
- asChild: true
196
- }, /* @__PURE__ */ React3.createElement(DropdownMenu.Item, null, /* @__PURE__ */ React3.createElement(CaretDownUp, {
197
- className: getSize2(5)
198
- }), /* @__PURE__ */ React3.createElement("span", {
199
- className: "mis-2 grow"
200
- }, t("collapse label")))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
201
- onClick: () => onAdd(id, "before"),
202
- "data-testid": "section.add-before"
203
- }, /* @__PURE__ */ React3.createElement(Icon, {
204
- icon: "ph--arrow-line-up--regular",
205
- size: 5
206
- }), /* @__PURE__ */ React3.createElement("span", {
207
- className: "mis-2 grow"
208
- }, t("add section before label"))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
209
- onClick: () => onAdd(id, "after"),
210
- "data-testid": "section.add-after"
211
- }, /* @__PURE__ */ React3.createElement(Icon, {
212
- icon: "ph--arrow-line-down--regular",
213
- size: 5
214
- }), /* @__PURE__ */ React3.createElement("span", {
215
- className: "mis-2 grow"
216
- }, t("add section after label"))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
217
- onClick: () => onDelete(id),
218
- "data-testid": "section.remove"
219
- }, /* @__PURE__ */ React3.createElement(Icon, {
220
- icon: "ph--trash--regular",
221
- size: 5
222
- }), /* @__PURE__ */ React3.createElement("span", {
223
- className: "mis-2 grow"
224
- }, t("remove section label")))), /* @__PURE__ */ React3.createElement(DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ React3.createElement(CollapsiblePrimitive.Trigger, {
225
- asChild: true
226
- }, /* @__PURE__ */ React3.createElement(IconButton, {
227
- iconOnly: true,
228
- tooltipZIndex: "70",
229
- variant: "ghost",
230
- label: t("expand label"),
231
- icon: "ph--caret-up-down--regular",
232
- classNames: sectionActionDimensions
233
- })) : /* @__PURE__ */ React3.createElement(IconButton, {
234
- iconOnly: true,
235
- tooltipZIndex: "70",
236
- variant: "ghost",
237
- onClick: () => onNavigate(id),
238
- label: t("navigate to section label"),
239
- icon: "ph--arrow-square-out--regular",
240
- "data-testid": "section.navigate-to",
241
- classNames: sectionActionDimensions
242
- }))), /* @__PURE__ */ React3.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ React3.createElement(Surface, {
243
- role: "section",
244
- data: {
245
- object
246
- },
247
- limit: 1,
248
- placeholder: /* @__PURE__ */ React3.createElement(React3.Fragment, null)
249
- })), view.collapsed && /* @__PURE__ */ React3.createElement(StackItem.Content, {
250
- toolbar: false,
251
- classNames: "attention-surface"
252
- }, /* @__PURE__ */ React3.createElement("h2", {
253
- className: mx2("flex items-center p-4 font-medium is-full", textBlockWidth)
254
- }, view.title))));
255
- };
256
-
257
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
258
- var StackMain = ({ id, collection }) => {
259
- const dispatch = useIntentDispatcher2();
260
- const { graph } = useGraph();
261
- const { t } = useTranslation3(STACK_PLUGIN);
262
- const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
263
- const defaultStack = useMemo(() => create(StackViewType, {
264
- sections: {}
265
- }), [
266
- collection
267
- ]);
268
- const stack = collection.views[StackViewType.typename] ?? defaultStack;
269
- const [collapsedSections, setCollapsedSections] = useState2({});
270
- useEffect(() => {
271
- if (!collection.views[StackViewType.typename]) {
272
- collection.views[StackViewType.typename] = stack;
273
- }
274
- }, [
275
- collection,
276
- stack
277
- ]);
278
- const items = collection.objects.filter(nonNullable).map((object) => {
279
- const metadata = metadataPlugin?.provides.metadata.resolver(getType(object)?.objectId ?? "never");
280
- const view = {
281
- ...stack.sections[object.id],
282
- collapsed: collapsedSections[fullyQualifiedId(object)],
283
- title: object?.title ?? toLocalizedString2(graph.findNode(fullyQualifiedId(object))?.properties.label, t)
284
- };
285
- return {
286
- id: fullyQualifiedId(object),
287
- object,
288
- metadata,
289
- view
290
- };
291
- }) ?? [];
292
- const handleDelete = async (id2) => {
293
- const index = collection.objects.filter(nonNullable).findIndex((section) => fullyQualifiedId(section) === id2);
294
- if (index >= 0) {
295
- await dispatch({
296
- action: SpaceAction.REMOVE_OBJECTS,
297
- data: {
298
- objects: [
299
- collection.objects[index]
300
- ],
301
- collection
302
- }
303
- });
304
- }
305
- };
306
- const handleAdd = (id2, position) => {
307
- void dispatch?.({
308
- action: LayoutAction.SET_LAYOUT,
309
- data: {
310
- element: "dialog",
311
- component: `${STACK_PLUGIN}/AddSectionDialog`,
312
- subject: {
313
- path: id2,
314
- position,
315
- collection
316
- }
317
- }
318
- });
319
- };
320
- const handleNavigate = async (id2) => {
321
- await dispatch([
322
- {
323
- action: NavigationAction.OPEN,
324
- data: {
325
- activeParts: {
326
- main: [
327
- id2
328
- ]
329
- }
330
- }
331
- },
332
- {
333
- action: LayoutAction.SCROLL_INTO_VIEW,
334
- data: {
335
- id: id2
336
- }
337
- }
338
- ]);
339
- };
340
- const handleCollapse = (id2, collapsed) => {
341
- setCollapsedSections((prev) => ({
342
- ...prev,
343
- [id2]: collapsed
344
- }));
345
- };
346
- return /* @__PURE__ */ React4.createElement(AttentionProvider, {
347
- id
348
- }, /* @__PURE__ */ React4.createElement(StackContext.Provider, {
349
- value: {
350
- onCollapse: handleCollapse,
351
- onNavigate: handleNavigate,
352
- onDelete: handleDelete,
353
- onAdd: handleAdd
354
- }
355
- }, /* @__PURE__ */ React4.createElement(Stack, {
356
- orientation: "vertical",
357
- size: "intrinsic",
358
- separators: false,
359
- id,
360
- "data-testid": "main.stack"
361
- }, items.map((item) => /* @__PURE__ */ React4.createElement(StackSection, {
362
- key: item.id,
363
- ...item
364
- }))), items.length === 0 ? /* @__PURE__ */ React4.createElement(AddSection, {
365
- collection
366
- }) : /* @__PURE__ */ React4.createElement("div", {
367
- role: "none",
368
- className: "flex mlb-2 pli-2 justify-center"
369
- }, /* @__PURE__ */ React4.createElement(Button, {
370
- "data-testid": "stack.createSection",
371
- classNames: "gap-2",
372
- onClick: () => dispatch?.({
373
- action: LayoutAction.SET_LAYOUT,
374
- data: {
375
- element: "dialog",
376
- component: "dxos.org/plugin/stack/AddSectionDialog",
377
- subject: {
378
- position: "afterAll",
379
- collection
380
- }
381
- }
382
- })
383
- }, /* @__PURE__ */ React4.createElement(Plus, null), /* @__PURE__ */ React4.createElement("span", {
384
- className: "sr-only"
385
- }, t("add section label"))))));
386
- };
387
- var StackMain_default = StackMain;
388
- export {
389
- StackMain_default as default
390
- };
391
- //# sourceMappingURL=StackMain-4D4J4IRK.mjs.map