@dxos/plugin-stack 0.9.0 → 0.9.1-staging.ee54ba693a

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 (95) hide show
  1. package/dist/lib/neutral/StackArticle-DDKRSUE7.mjs +199 -0
  2. package/dist/lib/neutral/StackArticle-DDKRSUE7.mjs.map +7 -0
  3. package/dist/lib/neutral/StackPlugin.mjs +6 -4
  4. package/dist/lib/neutral/StackPlugin.mjs.map +4 -4
  5. package/dist/lib/neutral/capabilities/index.mjs +3 -1
  6. package/dist/lib/neutral/capabilities/index.mjs.map +1 -1
  7. package/dist/lib/neutral/chunk-FDNICBZZ.mjs +18 -0
  8. package/dist/lib/neutral/chunk-FDNICBZZ.mjs.map +7 -0
  9. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  10. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  11. package/dist/lib/neutral/chunk-ZOIZTRMG.mjs +44 -0
  12. package/dist/lib/neutral/chunk-ZOIZTRMG.mjs.map +7 -0
  13. package/dist/lib/neutral/components/index.mjs +191 -147
  14. package/dist/lib/neutral/components/index.mjs.map +4 -4
  15. package/dist/lib/neutral/containers/index.mjs +3 -1
  16. package/dist/lib/neutral/containers/index.mjs.map +1 -1
  17. package/dist/lib/neutral/index.mjs +5 -6
  18. package/dist/lib/neutral/meta.json +1 -1
  19. package/dist/lib/neutral/meta.mjs +2 -1
  20. package/dist/lib/neutral/plugin.mjs +2 -1
  21. package/dist/lib/neutral/plugin.mjs.map +1 -1
  22. package/dist/lib/neutral/{react-surface-MD3CVY2N.mjs → react-surface-IL4CW7ND.mjs} +3 -1
  23. package/dist/lib/neutral/{react-surface-MD3CVY2N.mjs.map → react-surface-IL4CW7ND.mjs.map} +1 -1
  24. package/dist/lib/neutral/translations.mjs +9 -7
  25. package/dist/lib/neutral/translations.mjs.map +3 -3
  26. package/dist/lib/neutral/types/index.mjs +4 -5
  27. package/dist/types/dx.config.d.ts +28 -0
  28. package/dist/types/dx.config.d.ts.map +1 -0
  29. package/dist/types/src/capabilities/index.d.ts +1 -1
  30. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  31. package/dist/types/src/capabilities/react-surface.d.ts +2 -2
  32. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  33. package/dist/types/src/components/Stack/Stack.d.ts +67 -0
  34. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -0
  35. package/dist/types/src/components/Stack/index.d.ts +2 -0
  36. package/dist/types/src/components/Stack/index.d.ts.map +1 -0
  37. package/dist/types/src/components/index.d.ts +1 -3
  38. package/dist/types/src/components/index.d.ts.map +1 -1
  39. package/dist/types/src/containers/StackArticle/StackArticle.d.ts +1 -2
  40. package/dist/types/src/containers/StackArticle/StackArticle.d.ts.map +1 -1
  41. package/dist/types/src/containers/StackArticle/StackArticle.stories.d.ts +7 -0
  42. package/dist/types/src/containers/StackArticle/StackArticle.stories.d.ts.map +1 -0
  43. package/dist/types/src/meta.d.ts +32 -2
  44. package/dist/types/src/meta.d.ts.map +1 -1
  45. package/dist/types/src/translations.d.ts +5 -16
  46. package/dist/types/src/translations.d.ts.map +1 -1
  47. package/dist/types/src/types/Stack.d.ts +6 -0
  48. package/dist/types/src/types/Stack.d.ts.map +1 -0
  49. package/dist/types/src/types/index.d.ts +1 -2
  50. package/dist/types/src/types/index.d.ts.map +1 -1
  51. package/dist/types/tsconfig.tsbuildinfo +1 -1
  52. package/dx.config.ts +32 -0
  53. package/package.json +34 -28
  54. package/src/StackPlugin.ts +3 -3
  55. package/src/components/Stack/Stack.tsx +319 -0
  56. package/src/components/{StackContext → Stack}/index.ts +1 -1
  57. package/src/components/index.ts +1 -3
  58. package/src/containers/StackArticle/StackArticle.stories.tsx +122 -0
  59. package/src/containers/StackArticle/StackArticle.tsx +181 -119
  60. package/src/meta.ts +3 -26
  61. package/src/translations.ts +6 -6
  62. package/src/types/Stack.ts +12 -0
  63. package/src/types/index.ts +1 -2
  64. package/dist/lib/neutral/StackArticle-R7IS6TYR.mjs +0 -124
  65. package/dist/lib/neutral/StackArticle-R7IS6TYR.mjs.map +0 -7
  66. package/dist/lib/neutral/chunk-RGJSGQGF.mjs +0 -36
  67. package/dist/lib/neutral/chunk-RGJSGQGF.mjs.map +0 -7
  68. package/dist/lib/neutral/chunk-T4NSFSPH.mjs +0 -24
  69. package/dist/lib/neutral/chunk-T4NSFSPH.mjs.map +0 -7
  70. package/dist/types/src/components/StackContext/StackContext.d.ts +0 -11
  71. package/dist/types/src/components/StackContext/StackContext.d.ts.map +0 -1
  72. package/dist/types/src/components/StackContext/index.d.ts +0 -2
  73. package/dist/types/src/components/StackContext/index.d.ts.map +0 -1
  74. package/dist/types/src/components/StackSection/CaretDownUp.d.ts +0 -3
  75. package/dist/types/src/components/StackSection/CaretDownUp.d.ts.map +0 -1
  76. package/dist/types/src/components/StackSection/StackSection.d.ts +0 -5
  77. package/dist/types/src/components/StackSection/StackSection.d.ts.map +0 -1
  78. package/dist/types/src/components/StackSection/index.d.ts +0 -2
  79. package/dist/types/src/components/StackSection/index.d.ts.map +0 -1
  80. package/dist/types/src/components/StackSettings/StackSettings.d.ts +0 -6
  81. package/dist/types/src/components/StackSettings/StackSettings.d.ts.map +0 -1
  82. package/dist/types/src/components/StackSettings/index.d.ts +0 -2
  83. package/dist/types/src/components/StackSettings/index.d.ts.map +0 -1
  84. package/dist/types/src/types/stack.d.ts +0 -18
  85. package/dist/types/src/types/stack.d.ts.map +0 -1
  86. package/dist/types/src/types/types.d.ts +0 -44
  87. package/dist/types/src/types/types.d.ts.map +0 -1
  88. package/src/components/StackContext/StackContext.tsx +0 -25
  89. package/src/components/StackSection/CaretDownUp.tsx +0 -30
  90. package/src/components/StackSection/StackSection.tsx +0 -123
  91. package/src/components/StackSection/index.ts +0 -5
  92. package/src/components/StackSettings/StackSettings.tsx +0 -28
  93. package/src/components/StackSettings/index.ts +0 -5
  94. package/src/types/stack.ts +0 -26
  95. package/src/types/types.ts +0 -46
@@ -3,121 +3,160 @@
3
3
  //
4
4
 
5
5
  import { Atom, useAtomValue } from '@effect-atom/atom-react';
6
- import * as Option from 'effect/Option';
7
- import React, { useCallback, useState } from 'react';
6
+ import React, { useCallback, useMemo, useState } from 'react';
8
7
 
9
8
  import { useOperationInvoker } from '@dxos/app-framework/ui';
10
- import { LayoutOperation } from '@dxos/app-toolkit';
11
- import { useAppGraph, type AppSurface } from '@dxos/app-toolkit/ui';
12
- import { type Collection, Obj, type Ref } from '@dxos/echo';
13
- import { Graph } from '@dxos/plugin-graph';
9
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
10
+ import { type Collection, Obj } from '@dxos/echo';
14
11
  import { SpaceOperation } from '@dxos/plugin-space';
15
- import { Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
16
- import { Stack, StackItem } from '@dxos/react-ui-stack';
17
- import { isNonNullable } from '@dxos/util';
12
+ import { Panel, Toolbar, useTranslation } from '@dxos/react-ui';
13
+ import { Menu, createMenuAction } from '@dxos/react-ui-menu';
14
+ import { Mosaic, type MosaicEventHandler } from '@dxos/react-ui-mosaic';
15
+ import { arrayMove, isNonNullable } from '@dxos/util';
18
16
 
19
- import { StackContext, StackSection } from '#components';
17
+ import { Stack, type StackSectionItem } from '#components';
20
18
  import { meta } from '#meta';
21
- import {
22
- type AddSectionPosition,
23
- type CollapsedSections,
24
- type StackSectionItem,
25
- type StackSectionMetadata,
26
- type StackSectionView,
27
- } from '#types';
28
-
29
- const collectionObjectsFamily = Atom.family((collection: Collection.Collection) =>
30
- Atom.make((get) => {
31
- const snapshot = get(Obj.atom(collection));
32
- return (
33
- snapshot.objects
34
- // TODO(wittjosiah): Why isn't this type inferred correctly?
35
- .map((ref: Ref.Ref<Obj.Unknown>) => get(Obj.atomReactive(ref)))
36
- .filter(isNonNullable)
37
- );
38
- }),
39
- );
40
19
 
41
- type StackArticleProps = AppSurface.ObjectArticleProps<Collection.Collection>;
20
+ export type StackArticleProps = AppSurface.ObjectArticleProps<Collection.Collection>;
42
21
 
43
22
  export const StackArticle = ({ attendableId, subject: collection }: StackArticleProps) => {
44
23
  const { invokePromise } = useOperationInvoker();
45
- const { graph } = useAppGraph();
46
- const { t } = useTranslation(meta.id);
47
- const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});
48
-
49
- // TODO(wittjosiah): Re-implement stack views with relations.
50
- // const defaultStack = useMemo(() => Obj.make(StackViewType, { sections: {} }), [collection]);
51
- // const stack = (collection.views[StackViewType.typename]?.target as StackViewType | undefined) ?? defaultStack;
52
- // useEffect(() => {
53
- // if (!collection.views[StackViewType.typename]) {
54
- // collection.views[StackViewType.typename] = Ref.make(stack);
55
- // }
56
- // }, [collection, stack]);
57
-
58
- const collectionObjects = useAtomValue(collectionObjectsFamily(collection));
59
- const items = collectionObjects.map((object: Obj.Unknown) => {
60
- const iconAnnotation = Obj.getIcon(object);
61
- const metadata: StackSectionMetadata = { icon: iconAnnotation?.icon };
62
- const view = {
63
- // ...stack.sections[object.id],
64
- collapsed: collapsedSections[Obj.getURI(object)],
65
- title:
66
- (object as any)?.title ??
67
- // TODO(wittjosiah): `getNode` is not reactive.
68
- toLocalizedString(Graph.getNode(graph, Obj.getURI(object)).pipe(Option.getOrNull)?.properties.label, t),
69
- } as StackSectionView;
70
- return { id: Obj.getURI(object), object, metadata, view } satisfies StackSectionItem;
71
- });
24
+ const { t } = useTranslation(meta.profile.key);
25
+ const [collapsedSections, setCollapsedSections] = useState<Record<string, boolean>>({});
72
26
 
73
- const handleDelete = useCallback(
74
- async (id: string) => {
75
- const index = collection.objects
76
- .map((object) => object.target)
77
- .filter(isNonNullable)
78
- .findIndex((section) => Obj.getURI(section) === id);
79
- const object = collection.objects[index].target;
80
- if (Obj.isObject(object)) {
81
- await invokePromise(SpaceOperation.RemoveObjects, {
82
- objects: [object],
83
- target: collection,
27
+ const collectionObjects = useAtomValue(createCollectionObjects(collection));
28
+ const items = useMemo<StackSectionItem[]>(
29
+ () => collectionObjects.map((object) => ({ id: Obj.getURI(object), object })),
30
+ [collectionObjects],
31
+ );
32
+
33
+ const collapsed = useMemo<ReadonlySet<string>>(
34
+ () => new Set(Object.keys(collapsedSections).filter((id) => collapsedSections[id])),
35
+ [collapsedSections],
36
+ );
37
+
38
+ // Index of a section within the collection by its object URI.
39
+ const findIndex = useCallback(
40
+ (id: string) => collection.objects.findIndex((ref) => ref.target != null && Obj.getURI(ref.target) === id),
41
+ [collection],
42
+ );
43
+
44
+ // Reorder sections in place. Placeholder/tile drop locations are 1-based with half-step placeholders
45
+ // between tiles, so the floor of the drop location is the destination array index (see Mosaic.Stack).
46
+ const eventHandler = useMemo<MosaicEventHandler<StackSectionItem>>(
47
+ () => ({
48
+ id: Obj.getURI(collection),
49
+ canDrop: ({ source }) =>
50
+ collection.objects.some((ref) => ref.target != null && Obj.getURI(ref.target) === source.id),
51
+ onDrop: ({ source, target }) => {
52
+ const to =
53
+ target?.type === 'tile' || target?.type === 'placeholder'
54
+ ? target.location
55
+ : target?.type === 'container'
56
+ ? collection.objects.length
57
+ : -1;
58
+ const insert = typeof to === 'number' && to >= 0 ? Math.floor(to) : -1;
59
+ if (insert < 0) {
60
+ return;
61
+ }
62
+
63
+ Obj.update(collection, (collection) => {
64
+ const from = findIndex(source.id);
65
+ if (from !== -1) {
66
+ arrayMove(collection.objects, from, insert);
67
+ }
84
68
  });
69
+ },
70
+ }),
71
+ [collection, findIndex],
72
+ );
85
73
 
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)];
74
+ const handleMoveUp = useCallback(
75
+ (id: string) => {
76
+ const index = findIndex(id);
77
+ if (index > 0) {
78
+ Obj.update(collection, (collection) => {
79
+ const [ref] = collection.objects.splice(index, 1);
80
+ collection.objects.splice(index - 1, 0, ref);
81
+ });
88
82
  }
89
83
  },
90
- [collection, invokePromise],
84
+ [collection, findIndex],
91
85
  );
92
86
 
93
- const handleAdd = useCallback(
94
- async (id: string, position: AddSectionPosition) => {
95
- // TODO(wittjosiah): Use object creation dialog.
96
- await invokePromise(LayoutOperation.UpdateDialog, {
97
- subject: `${meta.id}.AddSectionDialog`,
98
- blockAlign: 'start',
99
- props: {
100
- path: id,
101
- position,
102
- collection,
103
- },
104
- });
87
+ const handleMoveDown = useCallback(
88
+ (id: string) => {
89
+ const index = findIndex(id);
90
+ if (index >= 0 && index < collection.objects.length - 1) {
91
+ Obj.update(collection, (collection) => {
92
+ const [ref] = collection.objects.splice(index, 1);
93
+ collection.objects.splice(index + 1, 0, ref);
94
+ });
95
+ }
105
96
  },
106
- [collection, invokePromise],
97
+ [collection, findIndex],
107
98
  );
108
99
 
109
- const handleNavigate = useCallback(
110
- async (id: string) => {
111
- await invokePromise(LayoutOperation.Open, { subject: [id] });
100
+ const handleDelete = useCallback(
101
+ (id: string) => {
102
+ const index = findIndex(id);
103
+ if (index >= 0) {
104
+ Obj.update(collection, (collection) => {
105
+ collection.objects.splice(index, 1);
106
+ });
107
+ }
112
108
  },
113
- [invokePromise],
109
+ [collection, findIndex],
110
+ );
111
+
112
+ const handleAdd = useCallback(
113
+ (id: string) =>
114
+ invokePromise(SpaceOperation.OpenCreateObject, {
115
+ target: collection,
116
+ navigable: false,
117
+ // The created object is appended; move it to immediately after the originating section.
118
+ onCreateObject: (object: Obj.Unknown) => {
119
+ const from = findIndex(Obj.getURI(object));
120
+ const anchor = findIndex(id);
121
+ if (from >= 0 && anchor >= 0) {
122
+ Obj.update(collection, (collection) => {
123
+ const [ref] = collection.objects.splice(from, 1);
124
+ collection.objects.splice(anchor < from ? anchor + 1 : anchor, 0, ref);
125
+ });
126
+ }
127
+ },
128
+ }),
129
+ [collection, invokePromise, findIndex],
114
130
  );
115
131
 
116
132
  const handleCollapse = useCallback(
117
- (id: string, collapsed: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: collapsed })),
133
+ (id: string, value: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: value })),
118
134
  [],
119
135
  );
120
136
 
137
+ const handleCollapseAll = useCallback(
138
+ () => setCollapsedSections(Object.fromEntries(collectionObjects.map((object) => [Obj.getURI(object), true]))),
139
+ [collectionObjects],
140
+ );
141
+
142
+ const handleExpandAll = useCallback(() => setCollapsedSections({}), []);
143
+
144
+ const optionsMenu = useMemo(
145
+ () => [
146
+ createMenuAction('collapse-all', handleCollapseAll, {
147
+ label: ['collapse-all.label', { ns: meta.profile.key }],
148
+ icon: 'ph--arrows-in-line-vertical--regular',
149
+ testId: 'stack.collapse-all',
150
+ }),
151
+ createMenuAction('expand-all', handleExpandAll, {
152
+ label: ['expand-all.label', { ns: meta.profile.key }],
153
+ icon: 'ph--arrows-out-line-vertical--regular',
154
+ testId: 'stack.expand-all',
155
+ }),
156
+ ],
157
+ [handleCollapseAll, handleExpandAll],
158
+ );
159
+
121
160
  const handleAddSection = useCallback(
122
161
  () =>
123
162
  invokePromise(SpaceOperation.OpenCreateObject, {
@@ -128,37 +167,60 @@ export const StackArticle = ({ attendableId, subject: collection }: StackArticle
128
167
  );
129
168
 
130
169
  return (
131
- <StackItem.Content toolbar classNames='dx-document'>
132
- <Toolbar.Root>
133
- <Toolbar.IconButton
134
- icon='ph--plus--regular'
135
- iconOnly
136
- label='Add section'
137
- data-testid='stack.addSection'
138
- onClick={handleAddSection}
139
- />
140
- </Toolbar.Root>
141
- <StackContext.Provider
142
- value={{
143
- attendableId,
144
- onCollapse: handleCollapse,
145
- onNavigate: handleNavigate,
146
- onDelete: handleDelete,
147
- onAdd: handleAdd,
148
- }}
149
- >
150
- <Stack
151
- orientation='vertical'
152
- size='intrinsic'
170
+ <Panel.Root>
171
+ <Panel.Toolbar classNames='bg-toolbar-surface'>
172
+ <Toolbar.Root classNames='dx-document'>
173
+ <Toolbar.IconButton
174
+ square
175
+ icon='ph--plus--regular'
176
+ iconOnly
177
+ label={t('add-section.label')}
178
+ data-testid='stack.addSection'
179
+ onClick={handleAddSection}
180
+ />
181
+ <Toolbar.Separator />
182
+ <Menu.Root>
183
+ <Menu.Trigger asChild>
184
+ <Toolbar.IconButton
185
+ square
186
+ icon='ph--dots-three-vertical--regular'
187
+ iconOnly
188
+ label={t('options.label')}
189
+ data-testid='stack.options'
190
+ />
191
+ </Menu.Trigger>
192
+ <Menu.Content items={optionsMenu} />
193
+ </Menu.Root>
194
+ </Toolbar.Root>
195
+ </Panel.Toolbar>
196
+ <Panel.Content>
197
+ <Stack.Root
153
198
  id={Obj.getURI(collection)}
154
- data-testid='main.stack'
155
- classNames='overflow-y-auto'
199
+ attendableId={attendableId}
200
+ collapsed={collapsed}
201
+ eventHandler={eventHandler}
202
+ onCollapse={handleCollapse}
203
+ onAdd={handleAdd}
204
+ onMoveUp={handleMoveUp}
205
+ onMoveDown={handleMoveDown}
206
+ onDelete={handleDelete}
156
207
  >
157
- {items.map((item) => (
158
- <StackSection key={item.id} {...item} />
159
- ))}
160
- </Stack>
161
- </StackContext.Provider>
162
- </StackItem.Content>
208
+ <Stack.Content centered padding data-testid='main.stack'>
209
+ <Stack.Viewport>
210
+ <Mosaic.Stack classNames='dx-document' items={items} getId={getId} Tile={Stack.Section} />
211
+ </Stack.Viewport>
212
+ </Stack.Content>
213
+ </Stack.Root>
214
+ </Panel.Content>
215
+ </Panel.Root>
163
216
  );
164
217
  };
218
+
219
+ const getId = (item: StackSectionItem) => item.id;
220
+
221
+ const createCollectionObjects = Atom.family((collection: Collection.Collection) =>
222
+ Atom.make((get) => {
223
+ const snapshot = get(Obj.atom(collection));
224
+ return snapshot.objects.map((ref) => get(Obj.atomReactive(ref))).filter(isNonNullable);
225
+ }),
226
+ );
package/src/meta.ts CHANGED
@@ -4,32 +4,9 @@
4
4
 
5
5
  import { Plugin } from '@dxos/app-framework';
6
6
  import { DXN } from '@dxos/keys';
7
- import { trim } from '@dxos/util';
8
7
 
9
- export const SECTION_IDENTIFIER = DXN.make('org.dxos.type.stackSection');
10
-
11
- export const meta = Plugin.makeMeta({
12
- key: DXN.make('org.dxos.plugin.stack'),
13
- // TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
14
- // Conside renaming this to the collection plugin and trying to factor more collections logic from the space plugin.
15
- name: 'Collections',
16
- author: 'DXOS',
17
- spec: 'PLUGIN.mdl',
18
- description: trim`
19
- StackPlugin renders any Collection object as a vertically scrollable stack of collapsible sections in the
20
- Composer article surface. Each section wraps an arbitrary ECHO object and delegates its content rendering
21
- to the section surface role, enabling any other plugin to contribute its own section renderer.
8
+ import config from '../dx.config';
22
9
 
23
- Sections can be individually collapsed to show only their title, expanded to reveal full content, navigated
24
- to directly, or removed from the collection. New sections can be inserted before or after any existing
25
- section via a per-section dropdown menu, or appended via the toolbar Add button.
26
-
27
- The plugin registers StackViewType with the ECHO schema module so that per-section view metadata
28
- (height overrides, custom display data) can be stored and replicated alongside the collection.
10
+ export const SECTION_IDENTIFIER = DXN.make('org.dxos.type.stackSection');
29
11
 
30
- A settings panel exposes a separation toggle that controls whether visual dividers are rendered between
31
- sections.
32
- `,
33
- icon: 'ph--stack-simple--regular',
34
- source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-stack',
35
- });
12
+ export const meta = Plugin.getMetaFromConfig(config);
@@ -3,16 +3,14 @@
3
3
  //
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
- import { translations as stackTranslations } from '@dxos/react-ui-stack/translations';
7
6
 
8
7
  import { meta } from '#meta';
9
8
 
10
9
  export const translations = [
11
10
  {
12
11
  'en-US': {
13
- [meta.id]: {
12
+ [meta.profile.key]: {
14
13
  'plugin.name': 'Stacks',
15
- 'settings.title': 'Stack settings',
16
14
  'settings.separation.label': 'Separate sections',
17
15
  'settings.separation.description': 'Add visual dividers between sections in stacks.',
18
16
  'add-section-beforeAll-dialog.title': 'Add a section to the start',
@@ -26,14 +24,16 @@ export const translations = [
26
24
  'remove-section.label': 'Delete',
27
25
  'navigate-to-section.label': 'Navigate to object',
28
26
  'untitled-section.title': 'Untitled section',
29
- 'add-section-before.label': 'Add before',
30
- 'add-section-after.label': 'Add after',
27
+ 'move-up.label': 'Move up',
28
+ 'move-down.label': 'Move down',
31
29
  'expand.label': 'Expand',
32
30
  'collapse.label': 'Collapse',
31
+ 'collapse-all.label': 'Collapse all',
32
+ 'expand-all.label': 'Expand all',
33
+ 'options.label': 'Options',
33
34
  'open-chat-thread.label': 'Open chat thread',
34
35
  'drag-handle.label': 'Press space or enter to begin dragging this object.',
35
36
  },
36
37
  },
37
38
  },
38
- ...stackTranslations,
39
39
  ] as const satisfies Resource[];
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import * as Schema from 'effect/Schema';
8
+
9
+ import { DXN, Type } from '@dxos/echo';
10
+
11
+ // TODO(burdon): Placeholder.
12
+ export class Stack extends Type.makeObject<Stack>(DXN.make('org.dxos.type.stack', '0.1.0'))(Schema.Struct({})) {}
@@ -2,5 +2,4 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './stack';
6
- export type * from './types';
5
+ export * as Stack from './Stack';
@@ -1,124 +0,0 @@
1
- // src/containers/StackArticle/StackArticle.tsx
2
- import { Atom, useAtomValue } from "@effect-atom/atom-react";
3
- import * as Option from "effect/Option";
4
- import React, { useCallback, useState } from "react";
5
- import { useOperationInvoker } from "@dxos/app-framework/ui";
6
- import { LayoutOperation } from "@dxos/app-toolkit";
7
- import { useAppGraph } from "@dxos/app-toolkit/ui";
8
- import { Obj } from "@dxos/echo";
9
- import { Graph } from "@dxos/plugin-graph";
10
- import { SpaceOperation } from "@dxos/plugin-space";
11
- import { Toolbar, toLocalizedString, useTranslation } from "@dxos/react-ui";
12
- import { Stack, StackItem } from "@dxos/react-ui-stack";
13
- import { isNonNullable } from "@dxos/util";
14
- import { StackContext, StackSection } from "#components";
15
- import { meta } from "#meta";
16
- var collectionObjectsFamily = Atom.family((collection) => Atom.make((get) => {
17
- const snapshot = get(Obj.atom(collection));
18
- return snapshot.objects.map((ref) => get(Obj.atomReactive(ref))).filter(isNonNullable);
19
- }));
20
- var StackArticle = ({ attendableId, subject: collection }) => {
21
- const { invokePromise } = useOperationInvoker();
22
- const { graph } = useAppGraph();
23
- const { t } = useTranslation(meta.id);
24
- const [collapsedSections, setCollapsedSections] = useState({});
25
- const collectionObjects = useAtomValue(collectionObjectsFamily(collection));
26
- const items = collectionObjects.map((object) => {
27
- const iconAnnotation = Obj.getIcon(object);
28
- const metadata = {
29
- icon: iconAnnotation?.icon
30
- };
31
- const view = {
32
- // ...stack.sections[object.id],
33
- collapsed: collapsedSections[Obj.getURI(object)],
34
- title: object?.title ?? // TODO(wittjosiah): `getNode` is not reactive.
35
- toLocalizedString(Graph.getNode(graph, Obj.getURI(object)).pipe(Option.getOrNull)?.properties.label, t)
36
- };
37
- return {
38
- id: Obj.getURI(object),
39
- object,
40
- metadata,
41
- view
42
- };
43
- });
44
- const handleDelete = useCallback(async (id) => {
45
- const index = collection.objects.map((object2) => object2.target).filter(isNonNullable).findIndex((section) => Obj.getURI(section) === id);
46
- const object = collection.objects[index].target;
47
- if (Obj.isObject(object)) {
48
- await invokePromise(SpaceOperation.RemoveObjects, {
49
- objects: [
50
- object
51
- ],
52
- target: collection
53
- });
54
- }
55
- }, [
56
- collection,
57
- invokePromise
58
- ]);
59
- const handleAdd = useCallback(async (id, position) => {
60
- await invokePromise(LayoutOperation.UpdateDialog, {
61
- subject: `${meta.id}.AddSectionDialog`,
62
- blockAlign: "start",
63
- props: {
64
- path: id,
65
- position,
66
- collection
67
- }
68
- });
69
- }, [
70
- collection,
71
- invokePromise
72
- ]);
73
- const handleNavigate = useCallback(async (id) => {
74
- await invokePromise(LayoutOperation.Open, {
75
- subject: [
76
- id
77
- ]
78
- });
79
- }, [
80
- invokePromise
81
- ]);
82
- const handleCollapse = useCallback((id, collapsed) => setCollapsedSections((prev) => ({
83
- ...prev,
84
- [id]: collapsed
85
- })), []);
86
- const handleAddSection = useCallback(() => invokePromise(SpaceOperation.OpenCreateObject, {
87
- target: collection,
88
- navigable: false
89
- }), [
90
- collection,
91
- invokePromise
92
- ]);
93
- return /* @__PURE__ */ React.createElement(StackItem.Content, {
94
- toolbar: true,
95
- classNames: "dx-document"
96
- }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Toolbar.IconButton, {
97
- icon: "ph--plus--regular",
98
- iconOnly: true,
99
- label: "Add section",
100
- "data-testid": "stack.addSection",
101
- onClick: handleAddSection
102
- })), /* @__PURE__ */ React.createElement(StackContext.Provider, {
103
- value: {
104
- attendableId,
105
- onCollapse: handleCollapse,
106
- onNavigate: handleNavigate,
107
- onDelete: handleDelete,
108
- onAdd: handleAdd
109
- }
110
- }, /* @__PURE__ */ React.createElement(Stack, {
111
- orientation: "vertical",
112
- size: "intrinsic",
113
- id: Obj.getURI(collection),
114
- "data-testid": "main.stack",
115
- classNames: "overflow-y-auto"
116
- }, items.map((item) => /* @__PURE__ */ React.createElement(StackSection, {
117
- key: item.id,
118
- ...item
119
- })))));
120
- };
121
- export {
122
- StackArticle as default
123
- };
124
- //# sourceMappingURL=StackArticle-R7IS6TYR.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/containers/StackArticle/StackArticle.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Atom, useAtomValue } from '@effect-atom/atom-react';\nimport * as Option from 'effect/Option';\nimport React, { useCallback, useState } from 'react';\n\nimport { useOperationInvoker } from '@dxos/app-framework/ui';\nimport { LayoutOperation } from '@dxos/app-toolkit';\nimport { useAppGraph, type AppSurface } from '@dxos/app-toolkit/ui';\nimport { type Collection, Obj, type Ref } from '@dxos/echo';\nimport { Graph } from '@dxos/plugin-graph';\nimport { SpaceOperation } from '@dxos/plugin-space';\nimport { Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';\nimport { Stack, StackItem } from '@dxos/react-ui-stack';\nimport { isNonNullable } from '@dxos/util';\n\nimport { StackContext, StackSection } from '#components';\nimport { meta } from '#meta';\nimport {\n type AddSectionPosition,\n type CollapsedSections,\n type StackSectionItem,\n type StackSectionMetadata,\n type StackSectionView,\n} from '#types';\n\nconst collectionObjectsFamily = Atom.family((collection: Collection.Collection) =>\n Atom.make((get) => {\n const snapshot = get(Obj.atom(collection));\n return (\n snapshot.objects\n // TODO(wittjosiah): Why isn't this type inferred correctly?\n .map((ref: Ref.Ref<Obj.Unknown>) => get(Obj.atomReactive(ref)))\n .filter(isNonNullable)\n );\n }),\n);\n\ntype StackArticleProps = AppSurface.ObjectArticleProps<Collection.Collection>;\n\nexport const StackArticle = ({ attendableId, subject: collection }: StackArticleProps) => {\n const { invokePromise } = useOperationInvoker();\n const { graph } = useAppGraph();\n const { t } = useTranslation(meta.id);\n const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});\n\n // TODO(wittjosiah): Re-implement stack views with relations.\n // const defaultStack = useMemo(() => Obj.make(StackViewType, { sections: {} }), [collection]);\n // const stack = (collection.views[StackViewType.typename]?.target as StackViewType | undefined) ?? defaultStack;\n // useEffect(() => {\n // if (!collection.views[StackViewType.typename]) {\n // collection.views[StackViewType.typename] = Ref.make(stack);\n // }\n // }, [collection, stack]);\n\n const collectionObjects = useAtomValue(collectionObjectsFamily(collection));\n const items = collectionObjects.map((object: Obj.Unknown) => {\n const iconAnnotation = Obj.getIcon(object);\n const metadata: StackSectionMetadata = { icon: iconAnnotation?.icon };\n const view = {\n // ...stack.sections[object.id],\n collapsed: collapsedSections[Obj.getURI(object)],\n title:\n (object as any)?.title ??\n // TODO(wittjosiah): `getNode` is not reactive.\n toLocalizedString(Graph.getNode(graph, Obj.getURI(object)).pipe(Option.getOrNull)?.properties.label, t),\n } as StackSectionView;\n return { id: Obj.getURI(object), object, metadata, view } satisfies StackSectionItem;\n });\n\n const handleDelete = useCallback(\n async (id: string) => {\n const index = collection.objects\n .map((object) => object.target)\n .filter(isNonNullable)\n .findIndex((section) => Obj.getURI(section) === id);\n const object = collection.objects[index].target;\n if (Obj.isObject(object)) {\n await invokePromise(SpaceOperation.RemoveObjects, {\n objects: [object],\n target: collection,\n });\n\n // TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.\n // delete stack.sections[Path.last(path)];\n }\n },\n [collection, invokePromise],\n );\n\n const handleAdd = useCallback(\n async (id: string, position: AddSectionPosition) => {\n // TODO(wittjosiah): Use object creation dialog.\n await invokePromise(LayoutOperation.UpdateDialog, {\n subject: `${meta.id}.AddSectionDialog`,\n blockAlign: 'start',\n props: {\n path: id,\n position,\n collection,\n },\n });\n },\n [collection, invokePromise],\n );\n\n const handleNavigate = useCallback(\n async (id: string) => {\n await invokePromise(LayoutOperation.Open, { subject: [id] });\n },\n [invokePromise],\n );\n\n const handleCollapse = useCallback(\n (id: string, collapsed: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: collapsed })),\n [],\n );\n\n const handleAddSection = useCallback(\n () =>\n invokePromise(SpaceOperation.OpenCreateObject, {\n target: collection,\n navigable: false,\n }),\n [collection, invokePromise],\n );\n\n return (\n <StackItem.Content toolbar classNames='dx-document'>\n <Toolbar.Root>\n <Toolbar.IconButton\n icon='ph--plus--regular'\n iconOnly\n label='Add section'\n data-testid='stack.addSection'\n onClick={handleAddSection}\n />\n </Toolbar.Root>\n <StackContext.Provider\n value={{\n attendableId,\n onCollapse: handleCollapse,\n onNavigate: handleNavigate,\n onDelete: handleDelete,\n onAdd: handleAdd,\n }}\n >\n <Stack\n orientation='vertical'\n size='intrinsic'\n id={Obj.getURI(collection)}\n data-testid='main.stack'\n classNames='overflow-y-auto'\n >\n {items.map((item) => (\n <StackSection key={item.id} {...item} />\n ))}\n </Stack>\n </StackContext.Provider>\n </StackItem.Content>\n );\n};\n"],
5
- "mappings": ";AAIA,SAASA,MAAMC,oBAAoB;AACnC,YAAYC,YAAY;AACxB,OAAOC,SAASC,aAAaC,gBAAgB;AAE7C,SAASC,2BAA2B;AACpC,SAASC,uBAAuB;AAChC,SAASC,mBAAoC;AAC7C,SAA0BC,WAAqB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LmC,UAAAA;IACA1B,OAAM;IACN2B,eAAY;IACZC,SAASV;OAGb,sBAAA,cAACzD,aAAaoE,UAAQ;IACpBC,OAAO;MACLrD;MACAsD,YAAYf;MACZgB,YAAYlB;MACZmB,UAAUhC;MACViC,OAAO1B;IACT;KAEA,sBAAA,cAAClD,OAAAA;IACC6E,aAAY;IACZC,MAAK;IACLtD,IAAI9B,IAAI0C,OAAO5B,UAAAA;IACf6D,eAAY;IACZJ,YAAW;KAEVrC,MAAMd,IAAI,CAACiE,SACV,sBAAA,cAAC3E,cAAAA;IAAa4E,KAAKD,KAAKvD;IAAK,GAAGuD;;AAM5C;",
6
- "names": ["Atom", "useAtomValue", "Option", "React", "useCallback", "useState", "useOperationInvoker", "LayoutOperation", "useAppGraph", "Obj", "Graph", "SpaceOperation", "Toolbar", "toLocalizedString", "useTranslation", "Stack", "StackItem", "isNonNullable", "StackContext", "StackSection", "meta", "collectionObjectsFamily", "family", "collection", "make", "get", "snapshot", "atom", "objects", "map", "ref", "atomReactive", "filter", "StackArticle", "attendableId", "subject", "invokePromise", "graph", "t", "id", "collapsedSections", "setCollapsedSections", "collectionObjects", "items", "object", "iconAnnotation", "getIcon", "metadata", "icon", "view", "collapsed", "getURI", "title", "getNode", "pipe", "getOrNull", "properties", "label", "handleDelete", "index", "target", "findIndex", "section", "isObject", "RemoveObjects", "handleAdd", "position", "UpdateDialog", "blockAlign", "props", "path", "handleNavigate", "Open", "handleCollapse", "prev", "handleAddSection", "OpenCreateObject", "navigable", "Content", "toolbar", "classNames", "Root", "IconButton", "iconOnly", "data-testid", "onClick", "Provider", "value", "onCollapse", "onNavigate", "onDelete", "onAdd", "orientation", "size", "item", "key"]
7
- }
@@ -1,36 +0,0 @@
1
- // src/meta.ts
2
- import { Plugin } from "@dxos/app-framework";
3
- import { DXN } from "@dxos/keys";
4
- import { trim } from "@dxos/util";
5
- var SECTION_IDENTIFIER = DXN.make("org.dxos.type.stackSection");
6
- var meta = Plugin.makeMeta({
7
- key: DXN.make("org.dxos.plugin.stack"),
8
- // TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
9
- // Conside renaming this to the collection plugin and trying to factor more collections logic from the space plugin.
10
- name: "Collections",
11
- author: "DXOS",
12
- spec: "PLUGIN.mdl",
13
- description: trim`
14
- StackPlugin renders any Collection object as a vertically scrollable stack of collapsible sections in the
15
- Composer article surface. Each section wraps an arbitrary ECHO object and delegates its content rendering
16
- to the section surface role, enabling any other plugin to contribute its own section renderer.
17
-
18
- Sections can be individually collapsed to show only their title, expanded to reveal full content, navigated
19
- to directly, or removed from the collection. New sections can be inserted before or after any existing
20
- section via a per-section dropdown menu, or appended via the toolbar Add button.
21
-
22
- The plugin registers StackViewType with the ECHO schema module so that per-section view metadata
23
- (height overrides, custom display data) can be stored and replicated alongside the collection.
24
-
25
- A settings panel exposes a separation toggle that controls whether visual dividers are rendered between
26
- sections.
27
- `,
28
- icon: "ph--stack-simple--regular",
29
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-stack"
30
- });
31
-
32
- export {
33
- SECTION_IDENTIFIER,
34
- meta
35
- };
36
- //# sourceMappingURL=chunk-RGJSGQGF.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { DXN } from '@dxos/keys';\nimport { trim } from '@dxos/util';\n\nexport const SECTION_IDENTIFIER = DXN.make('org.dxos.type.stackSection');\n\nexport const meta = Plugin.makeMeta({\n key: DXN.make('org.dxos.plugin.stack'),\n // TODO(wittjosiah): Prevents \"stacks\" language from being exposed to users in settings panel.\n // Conside renaming this to the collection plugin and trying to factor more collections logic from the space plugin.\n name: 'Collections',\n author: 'DXOS',\n spec: 'PLUGIN.mdl',\n description: trim`\n StackPlugin renders any Collection object as a vertically scrollable stack of collapsible sections in the\n Composer article surface. Each section wraps an arbitrary ECHO object and delegates its content rendering\n to the section surface role, enabling any other plugin to contribute its own section renderer.\n\n Sections can be individually collapsed to show only their title, expanded to reveal full content, navigated\n to directly, or removed from the collection. New sections can be inserted before or after any existing\n section via a per-section dropdown menu, or appended via the toolbar Add button.\n\n The plugin registers StackViewType with the ECHO schema module so that per-section view metadata\n (height overrides, custom display data) can be stored and replicated alongside the collection.\n\n A settings panel exposes a separation toggle that controls whether visual dividers are rendered between\n sections.\n `,\n icon: 'ph--stack-simple--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-stack',\n});\n"],
5
- "mappings": ";AAIA,SAASA,cAAc;AACvB,SAASC,WAAW;AACpB,SAASC,YAAY;AAEd,IAAMC,qBAAqBF,IAAIG,KAAK,4BAAA;AAEpC,IAAMC,OAAOL,OAAOM,SAAS;EAClCC,KAAKN,IAAIG,KAAK,uBAAA;;;EAGdI,MAAM;EACNC,QAAQ;EACRC,MAAM;EACNC,aAAaT;;;;;;;;;;;;;;;EAebU,MAAM;EACNC,QAAQ;AACV,CAAA;",
6
- "names": ["Plugin", "DXN", "trim", "SECTION_IDENTIFIER", "make", "meta", "makeMeta", "key", "name", "author", "spec", "description", "icon", "source"]
7
- }