@dxos/plugin-stack 0.8.4-main.3f58842 → 0.8.4-main.3fbcb4aa9b
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.
- package/dist/lib/neutral/StackContainer-KZ5Q5YKJ.mjs +126 -0
- package/dist/lib/neutral/StackContainer-KZ5Q5YKJ.mjs.map +7 -0
- package/dist/lib/neutral/StackPlugin.mjs +22 -0
- package/dist/lib/neutral/StackPlugin.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +7 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-UN5PA7TK.mjs → neutral/chunk-3ISQZKGO.mjs} +8 -8
- package/dist/lib/neutral/chunk-3ISQZKGO.mjs.map +7 -0
- package/dist/lib/{browser/chunk-IRTROCUQ.mjs → neutral/chunk-IPU3C6TT.mjs} +10 -11
- package/dist/lib/neutral/chunk-IPU3C6TT.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +182 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +7 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +15 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +9 -0
- package/dist/lib/neutral/plugin.mjs +11 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-4ZA44TMR.mjs +23 -0
- package/dist/lib/neutral/react-surface-4ZA44TMR.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +37 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/types/index.mjs +1 -1
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/StackPlugin.d.ts +3 -1
- package/dist/types/src/StackPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +2 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/{StackContext.d.ts → StackContext/StackContext.d.ts} +2 -1
- package/dist/types/src/components/StackContext/StackContext.d.ts.map +1 -0
- package/dist/types/src/components/StackContext/index.d.ts +2 -0
- package/dist/types/src/components/StackContext/index.d.ts.map +1 -0
- package/dist/types/src/components/{CaretDownUp.d.ts → StackSection/CaretDownUp.d.ts} +1 -1
- package/dist/types/src/components/StackSection/CaretDownUp.d.ts.map +1 -0
- package/dist/types/src/components/{StackSection.d.ts → StackSection/StackSection.d.ts} +1 -1
- package/dist/types/src/components/StackSection/StackSection.d.ts.map +1 -0
- package/dist/types/src/components/StackSection/index.d.ts +2 -0
- package/dist/types/src/components/StackSection/index.d.ts.map +1 -0
- package/dist/types/src/components/{StackSettings.d.ts → StackSettings/StackSettings.d.ts} +1 -1
- package/dist/types/src/components/StackSettings/StackSettings.d.ts.map +1 -0
- package/dist/types/src/components/StackSettings/index.d.ts +2 -0
- package/dist/types/src/components/StackSettings/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/StackContainer/StackContainer.d.ts +7 -0
- package/dist/types/src/containers/StackContainer/StackContainer.d.ts.map +1 -0
- package/dist/types/src/containers/StackContainer/index.d.ts +2 -0
- package/dist/types/src/containers/StackContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +3 -4
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +31 -30
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/stack.d.ts +13 -14
- package/dist/types/src/types/stack.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +3 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +92 -50
- package/src/StackPlugin.ts +14 -46
- package/src/capabilities/index.ts +2 -2
- package/src/capabilities/react-surface.tsx +20 -26
- package/src/components/{StackContext.tsx → StackContext/StackContext.tsx} +3 -1
- package/src/components/StackContext/index.ts +5 -0
- package/src/components/{StackSection.tsx → StackSection/StackSection.tsx} +30 -26
- package/src/components/StackSection/index.ts +5 -0
- package/src/components/StackSettings/StackSettings.tsx +28 -0
- package/src/components/StackSettings/index.ts +5 -0
- package/src/components/index.ts +2 -4
- package/src/containers/StackContainer/StackContainer.tsx +170 -0
- package/src/containers/StackContainer/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/index.ts +1 -1
- package/src/meta.ts +9 -6
- package/src/plugin.ts +9 -0
- package/src/translations.ts +23 -21
- package/src/types/stack.ts +12 -8
- package/src/types/types.ts +3 -3
- package/dist/lib/browser/StackMain-ET24BQFZ.mjs +0 -299
- package/dist/lib/browser/StackMain-ET24BQFZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-FVB7LGW7.mjs +0 -19
- package/dist/lib/browser/chunk-FVB7LGW7.mjs.map +0 -7
- package/dist/lib/browser/chunk-IRTROCUQ.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -100
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-KODSQDIY.mjs +0 -46
- package/dist/lib/browser/react-surface-KODSQDIY.mjs.map +0 -7
- package/dist/lib/node-esm/StackMain-LCMLZ4MS.mjs +0 -300
- package/dist/lib/node-esm/StackMain-LCMLZ4MS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LRAZXJ65.mjs +0 -30
- package/dist/lib/node-esm/chunk-LRAZXJ65.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UN5PA7TK.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -101
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-SWMUVIYU.mjs +0 -47
- package/dist/lib/node-esm/react-surface-SWMUVIYU.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -10
- package/dist/types/src/components/CaretDownUp.d.ts.map +0 -1
- package/dist/types/src/components/StackContext.d.ts.map +0 -1
- package/dist/types/src/components/StackMain.d.ts +0 -9
- package/dist/types/src/components/StackMain.d.ts.map +0 -1
- package/dist/types/src/components/StackSection.d.ts.map +0 -1
- package/dist/types/src/components/StackSettings.d.ts.map +0 -1
- package/src/components/StackMain.tsx +0 -159
- package/src/components/StackSettings.tsx +0 -23
- /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
- /package/dist/lib/{node-esm/types/index.mjs.map → neutral/meta.mjs.map} +0 -0
- /package/src/components/{CaretDownUp.tsx → StackSection/CaretDownUp.tsx} +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import React, { useCallback, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
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 { Annotation, Obj, type Ref } from '@dxos/echo';
|
|
13
|
+
import { type Collection } from '@dxos/echo';
|
|
14
|
+
import { AtomObj } from '@dxos/echo-atom';
|
|
15
|
+
import { Graph } from '@dxos/plugin-graph';
|
|
16
|
+
import { SpaceOperation } from '@dxos/plugin-space';
|
|
17
|
+
import { Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
18
|
+
import { Stack, StackItem } from '@dxos/react-ui-stack';
|
|
19
|
+
import { isNonNullable } from '@dxos/util';
|
|
20
|
+
|
|
21
|
+
import { StackContext, StackSection } from '#components';
|
|
22
|
+
import { meta } from '#meta';
|
|
23
|
+
import {
|
|
24
|
+
type AddSectionPosition,
|
|
25
|
+
type CollapsedSections,
|
|
26
|
+
type StackSectionItem,
|
|
27
|
+
type StackSectionMetadata,
|
|
28
|
+
type StackSectionView,
|
|
29
|
+
} from '#types';
|
|
30
|
+
|
|
31
|
+
const collectionObjectsFamily = Atom.family((collection: Collection.Collection) =>
|
|
32
|
+
Atom.make((get) => {
|
|
33
|
+
const snapshot = get(AtomObj.make(collection));
|
|
34
|
+
return (
|
|
35
|
+
snapshot.objects
|
|
36
|
+
// TODO(wittjosiah): Why isn't this type inferred correctly?
|
|
37
|
+
.map((ref: Ref.Ref<Obj.Unknown>) => get(AtomObj.makeWithReactive(ref)))
|
|
38
|
+
.filter(isNonNullable)
|
|
39
|
+
);
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
type StackContainerProps = AppSurface.ObjectArticleProps<Collection.Collection>;
|
|
44
|
+
|
|
45
|
+
export const StackContainer = ({ attendableId, subject: collection }: StackContainerProps) => {
|
|
46
|
+
const { invokePromise } = useOperationInvoker();
|
|
47
|
+
const { graph } = useAppGraph();
|
|
48
|
+
const { t } = useTranslation(meta.id);
|
|
49
|
+
const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});
|
|
50
|
+
|
|
51
|
+
// TODO(wittjosiah): Re-implement stack views with relations.
|
|
52
|
+
// const defaultStack = useMemo(() => Obj.make(StackViewType, { sections: {} }), [collection]);
|
|
53
|
+
// const stack = (collection.views[StackViewType.typename]?.target as StackViewType | undefined) ?? defaultStack;
|
|
54
|
+
// useEffect(() => {
|
|
55
|
+
// if (!collection.views[StackViewType.typename]) {
|
|
56
|
+
// collection.views[StackViewType.typename] = Ref.make(stack);
|
|
57
|
+
// }
|
|
58
|
+
// }, [collection, stack]);
|
|
59
|
+
|
|
60
|
+
const collectionObjects = useAtomValue(collectionObjectsFamily(collection));
|
|
61
|
+
const items = collectionObjects.map((object: Obj.Unknown) => {
|
|
62
|
+
const schema = Obj.getSchema(object);
|
|
63
|
+
const iconAnnotation = schema ? Option.getOrUndefined(Annotation.IconAnnotation.get(schema)) : undefined;
|
|
64
|
+
const metadata: StackSectionMetadata = { icon: iconAnnotation?.icon };
|
|
65
|
+
const view = {
|
|
66
|
+
// ...stack.sections[object.id],
|
|
67
|
+
collapsed: collapsedSections[Obj.getDXN(object).toString()],
|
|
68
|
+
title:
|
|
69
|
+
(object as any)?.title ??
|
|
70
|
+
// TODO(wittjosiah): `getNode` is not reactive.
|
|
71
|
+
toLocalizedString(
|
|
72
|
+
Graph.getNode(graph, Obj.getDXN(object).toString()).pipe(Option.getOrNull)?.properties.label,
|
|
73
|
+
t,
|
|
74
|
+
),
|
|
75
|
+
} as StackSectionView;
|
|
76
|
+
return { id: Obj.getDXN(object).toString(), object, metadata, view } satisfies StackSectionItem;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const handleDelete = useCallback(
|
|
80
|
+
async (id: string) => {
|
|
81
|
+
const index = collection.objects
|
|
82
|
+
.map((object) => object.target)
|
|
83
|
+
.filter(isNonNullable)
|
|
84
|
+
.findIndex((section) => Obj.getDXN(section).toString() === id);
|
|
85
|
+
const object = collection.objects[index].target;
|
|
86
|
+
if (Obj.isObject(object)) {
|
|
87
|
+
await invokePromise(SpaceOperation.RemoveObjects, {
|
|
88
|
+
objects: [object],
|
|
89
|
+
target: collection,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.
|
|
93
|
+
// delete stack.sections[Path.last(path)];
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
[collection, invokePromise],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const handleAdd = useCallback(
|
|
100
|
+
async (id: string, position: AddSectionPosition) => {
|
|
101
|
+
// TODO(wittjosiah): Use object creation dialog.
|
|
102
|
+
await invokePromise(LayoutOperation.UpdateDialog, {
|
|
103
|
+
subject: `${meta.id}.AddSectionDialog`,
|
|
104
|
+
blockAlign: 'start',
|
|
105
|
+
props: {
|
|
106
|
+
path: id,
|
|
107
|
+
position,
|
|
108
|
+
collection,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
[collection, invokePromise],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const handleNavigate = useCallback(
|
|
116
|
+
async (id: string) => {
|
|
117
|
+
await invokePromise(LayoutOperation.Open, { subject: [id] });
|
|
118
|
+
},
|
|
119
|
+
[invokePromise],
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const handleCollapse = useCallback(
|
|
123
|
+
(id: string, collapsed: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: collapsed })),
|
|
124
|
+
[],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const handleAddSection = useCallback(
|
|
128
|
+
() =>
|
|
129
|
+
invokePromise(SpaceOperation.OpenCreateObject, {
|
|
130
|
+
target: collection,
|
|
131
|
+
navigable: false,
|
|
132
|
+
}),
|
|
133
|
+
[collection, invokePromise],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<StackItem.Content toolbar classNames='dx-document'>
|
|
138
|
+
<Toolbar.Root>
|
|
139
|
+
<Toolbar.IconButton
|
|
140
|
+
icon='ph--plus--regular'
|
|
141
|
+
iconOnly
|
|
142
|
+
label='Add section'
|
|
143
|
+
data-testid='stack.addSection'
|
|
144
|
+
onClick={handleAddSection}
|
|
145
|
+
/>
|
|
146
|
+
</Toolbar.Root>
|
|
147
|
+
<StackContext.Provider
|
|
148
|
+
value={{
|
|
149
|
+
attendableId,
|
|
150
|
+
onCollapse: handleCollapse,
|
|
151
|
+
onNavigate: handleNavigate,
|
|
152
|
+
onDelete: handleDelete,
|
|
153
|
+
onAdd: handleAdd,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<Stack
|
|
157
|
+
orientation='vertical'
|
|
158
|
+
size='intrinsic'
|
|
159
|
+
id={Obj.getDXN(collection).toString()}
|
|
160
|
+
data-testid='main.stack'
|
|
161
|
+
classNames='overflow-y-auto'
|
|
162
|
+
>
|
|
163
|
+
{items.map((item) => (
|
|
164
|
+
<StackSection key={item.id} {...item} />
|
|
165
|
+
))}
|
|
166
|
+
</Stack>
|
|
167
|
+
</StackContext.Provider>
|
|
168
|
+
</StackItem.Content>
|
|
169
|
+
);
|
|
170
|
+
};
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const
|
|
8
|
-
export const SECTION_IDENTIFIER = 'dxos.org/type/StackSection';
|
|
8
|
+
export const SECTION_IDENTIFIER = 'org.dxos.type.stackSection';
|
|
9
9
|
|
|
10
|
-
export const meta:
|
|
11
|
-
id:
|
|
10
|
+
export const meta: Plugin.Meta = {
|
|
11
|
+
id: 'org.dxos.plugin.stack',
|
|
12
12
|
// TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
|
|
13
13
|
// Conside renaming this to the collection plugin and trying to factor more collections logic from the space plugin.
|
|
14
14
|
name: 'Collections',
|
|
15
|
-
description:
|
|
15
|
+
description: trim`
|
|
16
|
+
Organize and view curated collections of workspace objects in customizable layouts.
|
|
17
|
+
Group related items together and manage collections with sections and filtering.
|
|
18
|
+
`,
|
|
16
19
|
icon: 'ph--stack-simple--regular',
|
|
17
20
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-stack',
|
|
18
21
|
};
|
package/src/plugin.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -3,33 +3,35 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
|
-
import { translations as stackTranslations } from '@dxos/react-ui-stack';
|
|
6
|
+
import { translations as stackTranslations } from '@dxos/react-ui-stack/translations';
|
|
7
7
|
|
|
8
|
-
import { meta } from '
|
|
8
|
+
import { meta } from '#meta';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
13
|
[meta.id]: {
|
|
14
|
-
'plugin
|
|
15
|
-
'settings
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'add
|
|
19
|
-
'add
|
|
20
|
-
'add
|
|
21
|
-
'
|
|
22
|
-
'add
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
14
|
+
'plugin.name': 'Stacks',
|
|
15
|
+
'settings.title': 'Stack settings',
|
|
16
|
+
'settings.separation.label': 'Separate sections',
|
|
17
|
+
'settings.separation.description': 'Add visual dividers between sections in stacks.',
|
|
18
|
+
'add-section-beforeAll-dialog.title': 'Add a section to the start',
|
|
19
|
+
'add-section-afterAll-dialog.title': 'Add a section to the end',
|
|
20
|
+
'add-section-before-dialog.title': 'Add a section',
|
|
21
|
+
'add-section-after-dialog.title': 'Add a section',
|
|
22
|
+
'add-section-input.placeholder': 'Find the type of section to add',
|
|
23
|
+
'upload-file.label': 'Add file',
|
|
24
|
+
'add-section.label': 'Add section',
|
|
25
|
+
'empty-stack.message': 'Drag objects into the stack.',
|
|
26
|
+
'remove-section.label': 'Delete',
|
|
27
|
+
'navigate-to-section.label': 'Navigate to object',
|
|
28
|
+
'untitled-section.title': 'Untitled section',
|
|
29
|
+
'add-section-before.label': 'Add before',
|
|
30
|
+
'add-section-after.label': 'Add after',
|
|
31
|
+
'expand.label': 'Expand',
|
|
32
|
+
'collapse.label': 'Collapse',
|
|
33
|
+
'open-chat-thread.label': 'Open chat thread',
|
|
34
|
+
'drag-handle.label': 'Press space or enter to begin dragging this object.',
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
},
|
package/src/types/stack.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Type } from '@dxos/echo';
|
|
8
8
|
|
|
9
9
|
// All section metadata needs to be optional/have defaults.
|
|
10
10
|
// Any objects added to the collection will start with the section defaults.
|
|
@@ -19,9 +19,13 @@ export const SectionSchema = Schema.Struct({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// TODO(wittjosiah): This needs a relation to be connected to a stack.
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
export const StackViewType = Schema.Struct({
|
|
23
|
+
sections: Schema.Record({ key: Schema.String, value: SectionSchema }),
|
|
24
|
+
}).pipe(
|
|
25
|
+
Type.object({
|
|
26
|
+
typename: 'org.dxos.type.stackView',
|
|
27
|
+
version: '0.1.0',
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export interface StackViewType extends Schema.Schema.Type<typeof StackViewType> {}
|
package/src/types/types.ts
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
import { type FC } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type Obj } from '@dxos/echo';
|
|
8
|
+
import { type Collection } from '@dxos/echo';
|
|
8
9
|
import { type Label } from '@dxos/react-ui';
|
|
9
10
|
import { type StackItemSize } from '@dxos/react-ui-stack';
|
|
10
|
-
import { type DataType } from '@dxos/schema';
|
|
11
11
|
|
|
12
12
|
export type AddSectionPosition = 'before' | 'after' | 'beforeAll' | 'afterAll';
|
|
13
13
|
|
|
14
14
|
export type CollapsedSections = Record<string, boolean>;
|
|
15
15
|
|
|
16
|
-
export type CollectionItem =
|
|
16
|
+
export type CollectionItem = Collection.Collection['objects'][number];
|
|
17
17
|
|
|
18
18
|
export type StackSectionView = {
|
|
19
19
|
title?: string;
|
|
@@ -39,7 +39,7 @@ export type StackSectionMetadata = {
|
|
|
39
39
|
|
|
40
40
|
export type StackSectionItem = {
|
|
41
41
|
id: string;
|
|
42
|
-
object: Obj.
|
|
42
|
+
object: Obj.Unknown;
|
|
43
43
|
view: StackSectionView;
|
|
44
44
|
metadata: StackSectionMetadata;
|
|
45
45
|
};
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
STACK_PLUGIN
|
|
3
|
-
} from "./chunk-FVB7LGW7.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/StackMain.tsx
|
|
6
|
-
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
7
|
-
import { Option } from "effect";
|
|
8
|
-
import React3, { useCallback, useState as useState2 } from "react";
|
|
9
|
-
import { Capabilities, LayoutAction, createIntent, useAppGraph, useCapabilities, useIntentDispatcher } from "@dxos/app-framework";
|
|
10
|
-
import { fullyQualifiedId, isLiveObject } from "@dxos/client/echo";
|
|
11
|
-
import { Obj } from "@dxos/echo";
|
|
12
|
-
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
13
|
-
import { Icon as Icon2, Button, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
14
|
-
import { AttentionProvider } from "@dxos/react-ui-attention";
|
|
15
|
-
import { Stack } from "@dxos/react-ui-stack";
|
|
16
|
-
import { isNonNullable } from "@dxos/util";
|
|
17
|
-
|
|
18
|
-
// src/components/StackContext.tsx
|
|
19
|
-
import { createContext, useContext } from "react";
|
|
20
|
-
var StackContext = /* @__PURE__ */ createContext({
|
|
21
|
-
onCollapse: () => {
|
|
22
|
-
},
|
|
23
|
-
onNavigate: async () => {
|
|
24
|
-
},
|
|
25
|
-
onDelete: async () => {
|
|
26
|
-
},
|
|
27
|
-
onAdd: () => {
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
var useStack = () => useContext(StackContext);
|
|
31
|
-
|
|
32
|
-
// src/components/StackSection.tsx
|
|
33
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
34
|
-
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
35
|
-
import React2, { useMemo, useState } from "react";
|
|
36
|
-
import { Surface } from "@dxos/app-framework";
|
|
37
|
-
import { DropdownMenu, Icon, useTranslation, IconButton } from "@dxos/react-ui";
|
|
38
|
-
import { useAttentionAttributes } 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
|
-
// src/components/CaretDownUp.tsx
|
|
43
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
44
|
-
import React from "react";
|
|
45
|
-
var CaretDownUp = ({ children, ...props }) => {
|
|
46
|
-
var _effect = _useSignals();
|
|
47
|
-
try {
|
|
48
|
-
return /* @__PURE__ */ React.createElement("svg", {
|
|
49
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
50
|
-
viewBox: "0 0 256 256",
|
|
51
|
-
...props
|
|
52
|
-
}, /* @__PURE__ */ React.createElement("rect", {
|
|
53
|
-
width: "256",
|
|
54
|
-
height: "256",
|
|
55
|
-
fill: "none"
|
|
56
|
-
}), /* @__PURE__ */ React.createElement("polyline", {
|
|
57
|
-
points: "80 224 128 176 176 224",
|
|
58
|
-
fill: "none",
|
|
59
|
-
stroke: "currentColor",
|
|
60
|
-
strokeLinecap: "round",
|
|
61
|
-
strokeLinejoin: "round",
|
|
62
|
-
strokeWidth: "16"
|
|
63
|
-
}), /* @__PURE__ */ React.createElement("polyline", {
|
|
64
|
-
points: "80 32 128 80 176 32",
|
|
65
|
-
fill: "none",
|
|
66
|
-
stroke: "currentColor",
|
|
67
|
-
strokeLinecap: "round",
|
|
68
|
-
strokeLinejoin: "round",
|
|
69
|
-
strokeWidth: "16"
|
|
70
|
-
}), children);
|
|
71
|
-
} finally {
|
|
72
|
-
_effect.f();
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// src/components/StackSection.tsx
|
|
77
|
-
var sectionActionDimensions = "p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
|
|
78
|
-
var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
|
|
79
|
-
var _effect = _useSignals2();
|
|
80
|
-
try {
|
|
81
|
-
const { t } = useTranslation(STACK_PLUGIN);
|
|
82
|
-
const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
|
|
83
|
-
const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
|
|
84
|
-
const attentionAttrs = useAttentionAttributes(id);
|
|
85
|
-
const stackItem = useMemo(() => ({
|
|
86
|
-
id
|
|
87
|
-
}), [
|
|
88
|
-
id
|
|
89
|
-
]);
|
|
90
|
-
return /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Root, {
|
|
91
|
-
asChild: true,
|
|
92
|
-
open: !view.collapsed,
|
|
93
|
-
onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
|
|
94
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.Root, {
|
|
95
|
-
item: stackItem,
|
|
96
|
-
role: "section",
|
|
97
|
-
...attentionAttrs
|
|
98
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.Heading, {
|
|
99
|
-
classNames: "attention-surface"
|
|
100
|
-
}, /* @__PURE__ */ React2.createElement("span", {
|
|
101
|
-
className: "sr-only"
|
|
102
|
-
}, view.title), /* @__PURE__ */ React2.createElement(StackItem.HeadingStickyContent, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Root, {
|
|
103
|
-
open: optionsMenuOpen,
|
|
104
|
-
onOpenChange: setOptionsMenuOpen
|
|
105
|
-
}, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
|
|
106
|
-
asChild: true
|
|
107
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.SigilButton, null, /* @__PURE__ */ React2.createElement(Icon, {
|
|
108
|
-
icon,
|
|
109
|
-
size: 5,
|
|
110
|
-
classNames: "transition-opacity"
|
|
111
|
-
}))), /* @__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, {
|
|
112
|
-
onClick: () => onNavigate(id),
|
|
113
|
-
"data-testid": "section.navigate-to"
|
|
114
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
115
|
-
icon: "ph--arrow-right--regular",
|
|
116
|
-
size: 5
|
|
117
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
118
|
-
className: "mis-2 grow"
|
|
119
|
-
}, t("navigate to section label"))) : /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
|
|
120
|
-
asChild: true
|
|
121
|
-
}, /* @__PURE__ */ React2.createElement(DropdownMenu.Item, null, /* @__PURE__ */ React2.createElement(CaretDownUp, {
|
|
122
|
-
className: getSize(5)
|
|
123
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
124
|
-
className: "mis-2 grow"
|
|
125
|
-
}, t("collapse label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
126
|
-
onClick: () => onAdd(id, "before"),
|
|
127
|
-
"data-testid": "section.add-before"
|
|
128
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
129
|
-
icon: "ph--arrow-line-up--regular",
|
|
130
|
-
size: 5
|
|
131
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
132
|
-
className: "mis-2 grow"
|
|
133
|
-
}, t("add section before label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
134
|
-
onClick: () => onAdd(id, "after"),
|
|
135
|
-
"data-testid": "section.add-after"
|
|
136
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
137
|
-
icon: "ph--arrow-line-down--regular",
|
|
138
|
-
size: 5
|
|
139
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
140
|
-
className: "mis-2 grow"
|
|
141
|
-
}, t("add section after label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
142
|
-
onClick: () => onDelete(id),
|
|
143
|
-
"data-testid": "section.remove"
|
|
144
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
145
|
-
icon: "ph--trash--regular",
|
|
146
|
-
size: 5
|
|
147
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
148
|
-
className: "mis-2 grow"
|
|
149
|
-
}, t("remove section label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
|
|
150
|
-
asChild: true
|
|
151
|
-
}, /* @__PURE__ */ React2.createElement(IconButton, {
|
|
152
|
-
iconOnly: true,
|
|
153
|
-
variant: "ghost",
|
|
154
|
-
label: t("expand label"),
|
|
155
|
-
icon: "ph--caret-up-down--regular",
|
|
156
|
-
classNames: sectionActionDimensions
|
|
157
|
-
})) : /* @__PURE__ */ React2.createElement(IconButton, {
|
|
158
|
-
iconOnly: true,
|
|
159
|
-
variant: "ghost",
|
|
160
|
-
onClick: () => onNavigate(id),
|
|
161
|
-
label: t("navigate to section label"),
|
|
162
|
-
icon: "ph--arrow-right--regular",
|
|
163
|
-
"data-testid": "section.navigate-to",
|
|
164
|
-
classNames: sectionActionDimensions
|
|
165
|
-
}))), /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ React2.createElement(Surface, {
|
|
166
|
-
role: "section",
|
|
167
|
-
data: {
|
|
168
|
-
subject: object
|
|
169
|
-
},
|
|
170
|
-
limit: 1,
|
|
171
|
-
placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
|
|
172
|
-
})), view.collapsed && /* @__PURE__ */ React2.createElement(StackItem.Content, {
|
|
173
|
-
classNames: "attention-surface"
|
|
174
|
-
}, /* @__PURE__ */ React2.createElement("h2", {
|
|
175
|
-
className: mx("flex items-center p-4 font-medium", textBlockWidth)
|
|
176
|
-
}, view.title))));
|
|
177
|
-
} finally {
|
|
178
|
-
_effect.f();
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// src/components/StackMain.tsx
|
|
183
|
-
var StackMain = ({ id, collection }) => {
|
|
184
|
-
var _effect = _useSignals3();
|
|
185
|
-
try {
|
|
186
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
187
|
-
const { graph } = useAppGraph();
|
|
188
|
-
const { t } = useTranslation2(STACK_PLUGIN);
|
|
189
|
-
const allMetadata = useCapabilities(Capabilities.Metadata);
|
|
190
|
-
const [collapsedSections, setCollapsedSections] = useState2({});
|
|
191
|
-
const items = collection.objects.map((object) => object.target).filter(isNonNullable).map((object) => {
|
|
192
|
-
const metadata = allMetadata.find((m) => m.id === (Obj.getTypename(object) ?? "never"))?.metadata;
|
|
193
|
-
const view = {
|
|
194
|
-
// ...stack.sections[object.id],
|
|
195
|
-
collapsed: collapsedSections[fullyQualifiedId(object)],
|
|
196
|
-
title: object?.title ?? // TODO(wittjosiah): `getNode` is not reactive.
|
|
197
|
-
toLocalizedString(graph.getNode(fullyQualifiedId(object)).pipe(Option.getOrNull)?.properties.label, t)
|
|
198
|
-
};
|
|
199
|
-
return {
|
|
200
|
-
id: fullyQualifiedId(object),
|
|
201
|
-
object,
|
|
202
|
-
metadata,
|
|
203
|
-
view
|
|
204
|
-
};
|
|
205
|
-
}) ?? [];
|
|
206
|
-
const handleDelete = useCallback(async (id2) => {
|
|
207
|
-
const index = collection.objects.map((object2) => object2.target).filter(isNonNullable).findIndex((section) => fullyQualifiedId(section) === id2);
|
|
208
|
-
const object = collection.objects[index].target;
|
|
209
|
-
if (isLiveObject(object)) {
|
|
210
|
-
await dispatch(createIntent(SpaceAction.RemoveObjects, {
|
|
211
|
-
objects: [
|
|
212
|
-
object
|
|
213
|
-
],
|
|
214
|
-
target: collection
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
217
|
-
}, [
|
|
218
|
-
collection,
|
|
219
|
-
dispatch
|
|
220
|
-
]);
|
|
221
|
-
const handleAdd = useCallback(async (id2, position) => {
|
|
222
|
-
await dispatch?.(
|
|
223
|
-
// TODO(wittjosiah): Use object creation dialog.
|
|
224
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
225
|
-
part: "dialog",
|
|
226
|
-
subject: `${STACK_PLUGIN}/AddSectionDialog`,
|
|
227
|
-
options: {
|
|
228
|
-
blockAlign: "start",
|
|
229
|
-
props: {
|
|
230
|
-
path: id2,
|
|
231
|
-
position,
|
|
232
|
-
collection
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
);
|
|
237
|
-
}, [
|
|
238
|
-
collection,
|
|
239
|
-
dispatch
|
|
240
|
-
]);
|
|
241
|
-
const handleNavigate = useCallback(async (id2) => {
|
|
242
|
-
await dispatch(createIntent(LayoutAction.Open, {
|
|
243
|
-
part: "main",
|
|
244
|
-
subject: [
|
|
245
|
-
id2
|
|
246
|
-
]
|
|
247
|
-
}));
|
|
248
|
-
}, [
|
|
249
|
-
dispatch
|
|
250
|
-
]);
|
|
251
|
-
const handleCollapse = useCallback((id2, collapsed) => setCollapsedSections((prev) => ({
|
|
252
|
-
...prev,
|
|
253
|
-
[id2]: collapsed
|
|
254
|
-
})), []);
|
|
255
|
-
const handleAddSection = useCallback(() => dispatch?.(createIntent(SpaceAction.OpenCreateObject, {
|
|
256
|
-
target: collection,
|
|
257
|
-
navigable: false
|
|
258
|
-
})), [
|
|
259
|
-
collection,
|
|
260
|
-
dispatch
|
|
261
|
-
]);
|
|
262
|
-
return /* @__PURE__ */ React3.createElement(AttentionProvider, {
|
|
263
|
-
id
|
|
264
|
-
}, /* @__PURE__ */ React3.createElement(StackContext.Provider, {
|
|
265
|
-
value: {
|
|
266
|
-
onCollapse: handleCollapse,
|
|
267
|
-
onNavigate: handleNavigate,
|
|
268
|
-
onDelete: handleDelete,
|
|
269
|
-
onAdd: handleAdd
|
|
270
|
-
}
|
|
271
|
-
}, /* @__PURE__ */ React3.createElement(Stack, {
|
|
272
|
-
orientation: "vertical",
|
|
273
|
-
size: "intrinsic",
|
|
274
|
-
id,
|
|
275
|
-
"data-testid": "main.stack"
|
|
276
|
-
}, items.map((item) => /* @__PURE__ */ React3.createElement(StackSection, {
|
|
277
|
-
key: item.id,
|
|
278
|
-
...item
|
|
279
|
-
}))), /* @__PURE__ */ React3.createElement("div", {
|
|
280
|
-
role: "none",
|
|
281
|
-
className: "flex mlb-2 pli-2 justify-center"
|
|
282
|
-
}, /* @__PURE__ */ React3.createElement(Button, {
|
|
283
|
-
"data-testid": "stack.createSection",
|
|
284
|
-
classNames: "gap-2",
|
|
285
|
-
onClick: handleAddSection
|
|
286
|
-
}, /* @__PURE__ */ React3.createElement(Icon2, {
|
|
287
|
-
icon: "ph--plus"
|
|
288
|
-
}), /* @__PURE__ */ React3.createElement("span", {
|
|
289
|
-
className: "sr-only"
|
|
290
|
-
}, t("add section label"))))));
|
|
291
|
-
} finally {
|
|
292
|
-
_effect.f();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var StackMain_default = StackMain;
|
|
296
|
-
export {
|
|
297
|
-
StackMain_default as default
|
|
298
|
-
};
|
|
299
|
-
//# sourceMappingURL=StackMain-ET24BQFZ.mjs.map
|