@dxos/plugin-stack 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/PLUGIN.mdl +326 -0
- package/README.md +1 -1
- package/dist/lib/neutral/StackArticle-R7IS6TYR.mjs +124 -0
- package/dist/lib/neutral/StackArticle-R7IS6TYR.mjs.map +7 -0
- package/dist/lib/neutral/StackPlugin.mjs +34 -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/neutral/chunk-RGJSGQGF.mjs +36 -0
- package/dist/lib/neutral/chunk-RGJSGQGF.mjs.map +7 -0
- package/dist/lib/{browser/chunk-NHMDZYOB.mjs → neutral/chunk-T4NSFSPH.mjs} +6 -10
- package/dist/lib/neutral/chunk-T4NSFSPH.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-MD3CVY2N.mjs +23 -0
- package/dist/lib/neutral/react-surface-MD3CVY2N.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 -7
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/StackArticle/StackArticle.d.ts +7 -0
- package/dist/types/src/containers/StackArticle/StackArticle.d.ts.map +1 -0
- package/dist/types/src/containers/StackArticle/index.d.ts +2 -0
- package/dist/types/src/containers/StackArticle/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 +4 -3
- 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 -31
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/stack.d.ts +12 -14
- package/dist/types/src/types/stack.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +2 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +87 -54
- package/src/StackPlugin.ts +19 -44
- package/src/capabilities/index.ts +2 -2
- package/src/capabilities/react-surface.tsx +20 -21
- 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} +28 -25
- 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/StackArticle/StackArticle.tsx +164 -0
- package/src/containers/StackArticle/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/index.ts +1 -1
- package/src/meta.ts +21 -7
- package/src/plugin.ts +9 -0
- package/src/translations.ts +23 -22
- package/src/types/stack.ts +6 -7
- package/src/types/types.ts +2 -3
- package/src/vite-env.d.ts +10 -0
- package/dist/lib/browser/StackContainer-DD3ZD5OE.mjs +0 -299
- package/dist/lib/browser/StackContainer-DD3ZD5OE.mjs.map +0 -7
- package/dist/lib/browser/chunk-NHMDZYOB.mjs.map +0 -7
- package/dist/lib/browser/chunk-UIKFKRFJ.mjs +0 -21
- package/dist/lib/browser/chunk-UIKFKRFJ.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -99
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-HVPK7YZQ.mjs +0 -39
- package/dist/lib/browser/react-surface-HVPK7YZQ.mjs.map +0 -7
- package/dist/lib/node-esm/StackContainer-JGWPXSUF.mjs +0 -300
- package/dist/lib/node-esm/StackContainer-JGWPXSUF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BGVQYUYP.mjs +0 -23
- package/dist/lib/node-esm/chunk-BGVQYUYP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZZFA7HIV.mjs +0 -30
- package/dist/lib/node-esm/chunk-ZZFA7HIV.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -100
- 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-HYSD7AC2.mjs +0 -40
- package/dist/lib/node-esm/react-surface-HYSD7AC2.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/StackContainer.d.ts +0 -9
- package/dist/types/src/components/StackContainer.d.ts.map +0 -1
- package/dist/types/src/components/StackContext.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/StackContainer.tsx +0 -172
- package/src/components/StackSettings.tsx +0 -30
- /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,164 @@
|
|
|
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 { type Collection, Obj, type Ref } from '@dxos/echo';
|
|
13
|
+
import { Graph } from '@dxos/plugin-graph';
|
|
14
|
+
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';
|
|
18
|
+
|
|
19
|
+
import { StackContext, StackSection } from '#components';
|
|
20
|
+
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
|
+
|
|
41
|
+
type StackArticleProps = AppSurface.ObjectArticleProps<Collection.Collection>;
|
|
42
|
+
|
|
43
|
+
export const StackArticle = ({ attendableId, subject: collection }: StackArticleProps) => {
|
|
44
|
+
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
|
+
});
|
|
72
|
+
|
|
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,
|
|
84
|
+
});
|
|
85
|
+
|
|
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, invokePromise],
|
|
91
|
+
);
|
|
92
|
+
|
|
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
|
+
});
|
|
105
|
+
},
|
|
106
|
+
[collection, invokePromise],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const handleNavigate = useCallback(
|
|
110
|
+
async (id: string) => {
|
|
111
|
+
await invokePromise(LayoutOperation.Open, { subject: [id] });
|
|
112
|
+
},
|
|
113
|
+
[invokePromise],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const handleCollapse = useCallback(
|
|
117
|
+
(id: string, collapsed: boolean) => setCollapsedSections((prev) => ({ ...prev, [id]: collapsed })),
|
|
118
|
+
[],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const handleAddSection = useCallback(
|
|
122
|
+
() =>
|
|
123
|
+
invokePromise(SpaceOperation.OpenCreateObject, {
|
|
124
|
+
target: collection,
|
|
125
|
+
navigable: false,
|
|
126
|
+
}),
|
|
127
|
+
[collection, invokePromise],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
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'
|
|
153
|
+
id={Obj.getURI(collection)}
|
|
154
|
+
data-testid='main.stack'
|
|
155
|
+
classNames='overflow-y-auto'
|
|
156
|
+
>
|
|
157
|
+
{items.map((item) => (
|
|
158
|
+
<StackSection key={item.id} {...item} />
|
|
159
|
+
))}
|
|
160
|
+
</Stack>
|
|
161
|
+
</StackContext.Provider>
|
|
162
|
+
</StackItem.Content>
|
|
163
|
+
);
|
|
164
|
+
};
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,20 +2,34 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { DXN } from '@dxos/keys';
|
|
6
7
|
import { trim } from '@dxos/util';
|
|
7
8
|
|
|
8
|
-
export const SECTION_IDENTIFIER = 'dxos.
|
|
9
|
+
export const SECTION_IDENTIFIER = DXN.make('org.dxos.type.stackSection');
|
|
9
10
|
|
|
10
|
-
export const meta
|
|
11
|
-
|
|
11
|
+
export const meta = Plugin.makeMeta({
|
|
12
|
+
key: DXN.make('org.dxos.plugin.stack'),
|
|
12
13
|
// TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
|
|
13
14
|
// Conside renaming this to the collection plugin and trying to factor more collections logic from the space plugin.
|
|
14
15
|
name: 'Collections',
|
|
16
|
+
author: 'DXOS',
|
|
17
|
+
spec: 'PLUGIN.mdl',
|
|
15
18
|
description: trim`
|
|
16
|
-
|
|
17
|
-
|
|
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.
|
|
22
|
+
|
|
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.
|
|
29
|
+
|
|
30
|
+
A settings panel exposes a separation toggle that controls whether visual dividers are rendered between
|
|
31
|
+
sections.
|
|
18
32
|
`,
|
|
19
33
|
icon: 'ph--stack-simple--regular',
|
|
20
34
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-stack',
|
|
21
|
-
};
|
|
35
|
+
});
|
package/src/plugin.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -3,34 +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
|
-
'settings
|
|
17
|
-
'
|
|
18
|
-
'add
|
|
19
|
-
'add
|
|
20
|
-
'add
|
|
21
|
-
'add
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'add
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
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.',
|
|
34
35
|
},
|
|
35
36
|
},
|
|
36
37
|
},
|
package/src/types/stack.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { DXN, 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,8 @@ 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(Type.makeObject(DXN.make('org.dxos.type.stackView', '0.1.0')));
|
|
25
|
+
|
|
26
|
+
export type StackViewType = Type.InstanceType<typeof StackViewType>;
|
package/src/types/types.ts
CHANGED
|
@@ -4,10 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { type FC } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type Obj } from '@dxos/echo';
|
|
7
|
+
import { type Collection, type Obj } from '@dxos/echo';
|
|
8
8
|
import { type Label } from '@dxos/react-ui';
|
|
9
9
|
import { type StackItemSize } from '@dxos/react-ui-stack';
|
|
10
|
-
import { type Collection } from '@dxos/schema';
|
|
11
10
|
|
|
12
11
|
export type AddSectionPosition = 'before' | 'after' | 'beforeAll' | 'afterAll';
|
|
13
12
|
|
|
@@ -39,7 +38,7 @@ export type StackSectionMetadata = {
|
|
|
39
38
|
|
|
40
39
|
export type StackSectionItem = {
|
|
41
40
|
id: string;
|
|
42
|
-
object: Obj.
|
|
41
|
+
object: Obj.Unknown;
|
|
43
42
|
view: StackSectionView;
|
|
44
43
|
metadata: StackSectionMetadata;
|
|
45
44
|
};
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
meta
|
|
3
|
-
} from "./chunk-UIKFKRFJ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/StackContainer.tsx
|
|
6
|
-
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
7
|
-
import * as Option from "effect/Option";
|
|
8
|
-
import React3, { useCallback, useState as useState2 } from "react";
|
|
9
|
-
import { Capabilities, LayoutAction, createIntent } from "@dxos/app-framework";
|
|
10
|
-
import { useAppGraph, useCapabilities, useIntentDispatcher } from "@dxos/app-framework/react";
|
|
11
|
-
import { isLiveObject } from "@dxos/client/echo";
|
|
12
|
-
import { Obj } from "@dxos/echo";
|
|
13
|
-
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
14
|
-
import { Toolbar, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
15
|
-
import { AttentionProvider } from "@dxos/react-ui-attention";
|
|
16
|
-
import { Stack, StackItem as StackItem2 } from "@dxos/react-ui-stack";
|
|
17
|
-
import { isNonNullable } from "@dxos/util";
|
|
18
|
-
|
|
19
|
-
// src/components/StackContext.tsx
|
|
20
|
-
import { createContext, useContext } from "react";
|
|
21
|
-
var StackContext = /* @__PURE__ */ createContext({
|
|
22
|
-
onCollapse: () => {
|
|
23
|
-
},
|
|
24
|
-
onNavigate: async () => {
|
|
25
|
-
},
|
|
26
|
-
onDelete: async () => {
|
|
27
|
-
},
|
|
28
|
-
onAdd: () => {
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
var useStack = () => useContext(StackContext);
|
|
32
|
-
|
|
33
|
-
// src/components/StackSection.tsx
|
|
34
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
35
|
-
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
36
|
-
import React2, { useMemo, useState } from "react";
|
|
37
|
-
import { Surface } from "@dxos/app-framework/react";
|
|
38
|
-
import { DropdownMenu, Icon, IconButton, useTranslation } from "@dxos/react-ui";
|
|
39
|
-
import { useAttentionAttributes } from "@dxos/react-ui-attention";
|
|
40
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
41
|
-
import { getSize, mx, textBlockWidth } from "@dxos/react-ui-theme";
|
|
42
|
-
|
|
43
|
-
// src/components/CaretDownUp.tsx
|
|
44
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
45
|
-
import React from "react";
|
|
46
|
-
var CaretDownUp = ({ children, ...props }) => {
|
|
47
|
-
var _effect = _useSignals();
|
|
48
|
-
try {
|
|
49
|
-
return /* @__PURE__ */ React.createElement("svg", {
|
|
50
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
51
|
-
viewBox: "0 0 256 256",
|
|
52
|
-
...props
|
|
53
|
-
}, /* @__PURE__ */ React.createElement("rect", {
|
|
54
|
-
width: "256",
|
|
55
|
-
height: "256",
|
|
56
|
-
fill: "none"
|
|
57
|
-
}), /* @__PURE__ */ React.createElement("polyline", {
|
|
58
|
-
points: "80 224 128 176 176 224",
|
|
59
|
-
fill: "none",
|
|
60
|
-
stroke: "currentColor",
|
|
61
|
-
strokeLinecap: "round",
|
|
62
|
-
strokeLinejoin: "round",
|
|
63
|
-
strokeWidth: "16"
|
|
64
|
-
}), /* @__PURE__ */ React.createElement("polyline", {
|
|
65
|
-
points: "80 32 128 80 176 32",
|
|
66
|
-
fill: "none",
|
|
67
|
-
stroke: "currentColor",
|
|
68
|
-
strokeLinecap: "round",
|
|
69
|
-
strokeLinejoin: "round",
|
|
70
|
-
strokeWidth: "16"
|
|
71
|
-
}), children);
|
|
72
|
-
} finally {
|
|
73
|
-
_effect.f();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/components/StackSection.tsx
|
|
78
|
-
var sectionActionDimensions = "p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
|
|
79
|
-
var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
|
|
80
|
-
var _effect = _useSignals2();
|
|
81
|
-
try {
|
|
82
|
-
const { t } = useTranslation(meta.id);
|
|
83
|
-
const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
|
|
84
|
-
const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
|
|
85
|
-
const attentionAttrs = useAttentionAttributes(id);
|
|
86
|
-
const stackItem = useMemo(() => ({
|
|
87
|
-
id
|
|
88
|
-
}), [
|
|
89
|
-
id
|
|
90
|
-
]);
|
|
91
|
-
return /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Root, {
|
|
92
|
-
asChild: true,
|
|
93
|
-
open: !view.collapsed,
|
|
94
|
-
onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
|
|
95
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.Root, {
|
|
96
|
-
item: stackItem,
|
|
97
|
-
role: "section",
|
|
98
|
-
...attentionAttrs
|
|
99
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.Heading, {
|
|
100
|
-
classNames: "attention-surface"
|
|
101
|
-
}, /* @__PURE__ */ React2.createElement("span", {
|
|
102
|
-
className: "sr-only"
|
|
103
|
-
}, view.title), /* @__PURE__ */ React2.createElement(StackItem.HeadingStickyContent, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Root, {
|
|
104
|
-
open: optionsMenuOpen,
|
|
105
|
-
onOpenChange: setOptionsMenuOpen
|
|
106
|
-
}, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
|
|
107
|
-
asChild: true
|
|
108
|
-
}, /* @__PURE__ */ React2.createElement(StackItem.SigilButton, null, /* @__PURE__ */ React2.createElement(Icon, {
|
|
109
|
-
icon,
|
|
110
|
-
size: 5,
|
|
111
|
-
classNames: "transition-opacity"
|
|
112
|
-
}))), /* @__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, {
|
|
113
|
-
onClick: () => onNavigate(id),
|
|
114
|
-
"data-testid": "section.navigate-to"
|
|
115
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
116
|
-
icon: "ph--arrow-right--regular",
|
|
117
|
-
size: 5
|
|
118
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
119
|
-
className: "mis-2 grow"
|
|
120
|
-
}, t("navigate to section label"))) : /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
|
|
121
|
-
asChild: true
|
|
122
|
-
}, /* @__PURE__ */ React2.createElement(DropdownMenu.Item, null, /* @__PURE__ */ React2.createElement(CaretDownUp, {
|
|
123
|
-
className: getSize(5)
|
|
124
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
125
|
-
className: "mis-2 grow"
|
|
126
|
-
}, t("collapse label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
127
|
-
onClick: () => onAdd(id, "before"),
|
|
128
|
-
"data-testid": "section.add-before"
|
|
129
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
130
|
-
icon: "ph--arrow-line-up--regular",
|
|
131
|
-
size: 5
|
|
132
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
133
|
-
className: "mis-2 grow"
|
|
134
|
-
}, t("add section before label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
135
|
-
onClick: () => onAdd(id, "after"),
|
|
136
|
-
"data-testid": "section.add-after"
|
|
137
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
138
|
-
icon: "ph--arrow-line-down--regular",
|
|
139
|
-
size: 5
|
|
140
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
141
|
-
className: "mis-2 grow"
|
|
142
|
-
}, t("add section after label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
|
|
143
|
-
onClick: () => onDelete(id),
|
|
144
|
-
"data-testid": "section.remove"
|
|
145
|
-
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
146
|
-
icon: "ph--trash--regular",
|
|
147
|
-
size: 5
|
|
148
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
149
|
-
className: "mis-2 grow"
|
|
150
|
-
}, t("remove section label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
|
|
151
|
-
asChild: true
|
|
152
|
-
}, /* @__PURE__ */ React2.createElement(IconButton, {
|
|
153
|
-
iconOnly: true,
|
|
154
|
-
variant: "ghost",
|
|
155
|
-
label: t("expand label"),
|
|
156
|
-
icon: "ph--caret-up-down--regular",
|
|
157
|
-
classNames: sectionActionDimensions
|
|
158
|
-
})) : /* @__PURE__ */ React2.createElement(IconButton, {
|
|
159
|
-
iconOnly: true,
|
|
160
|
-
variant: "ghost",
|
|
161
|
-
onClick: () => onNavigate(id),
|
|
162
|
-
label: t("navigate to section label"),
|
|
163
|
-
icon: "ph--arrow-right--regular",
|
|
164
|
-
"data-testid": "section.navigate-to",
|
|
165
|
-
classNames: sectionActionDimensions
|
|
166
|
-
}))), /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ React2.createElement(Surface, {
|
|
167
|
-
role: "section",
|
|
168
|
-
data: {
|
|
169
|
-
subject: object
|
|
170
|
-
},
|
|
171
|
-
limit: 1,
|
|
172
|
-
placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
|
|
173
|
-
})), view.collapsed && /* @__PURE__ */ React2.createElement(StackItem.Content, {
|
|
174
|
-
classNames: "attention-surface"
|
|
175
|
-
}, /* @__PURE__ */ React2.createElement("h2", {
|
|
176
|
-
className: mx("flex items-center p-4 font-medium", textBlockWidth)
|
|
177
|
-
}, view.title))));
|
|
178
|
-
} finally {
|
|
179
|
-
_effect.f();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// src/components/StackContainer.tsx
|
|
184
|
-
var StackContainer = ({ id, collection }) => {
|
|
185
|
-
var _effect = _useSignals3();
|
|
186
|
-
try {
|
|
187
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
188
|
-
const { graph } = useAppGraph();
|
|
189
|
-
const { t } = useTranslation2(meta.id);
|
|
190
|
-
const allMetadata = useCapabilities(Capabilities.Metadata);
|
|
191
|
-
const [collapsedSections, setCollapsedSections] = useState2({});
|
|
192
|
-
const items = collection.objects.map((object) => object.target).filter(isNonNullable).map((object) => {
|
|
193
|
-
const metadata = allMetadata.find((m) => m.id === (Obj.getTypename(object) ?? "never"))?.metadata;
|
|
194
|
-
const view = {
|
|
195
|
-
// ...stack.sections[object.id],
|
|
196
|
-
collapsed: collapsedSections[Obj.getDXN(object).toString()],
|
|
197
|
-
title: object?.title ?? // TODO(wittjosiah): `getNode` is not reactive.
|
|
198
|
-
toLocalizedString(graph.getNode(Obj.getDXN(object).toString()).pipe(Option.getOrNull)?.properties.label, t)
|
|
199
|
-
};
|
|
200
|
-
return {
|
|
201
|
-
id: Obj.getDXN(object).toString(),
|
|
202
|
-
object,
|
|
203
|
-
metadata,
|
|
204
|
-
view
|
|
205
|
-
};
|
|
206
|
-
}) ?? [];
|
|
207
|
-
const handleDelete = useCallback(async (id2) => {
|
|
208
|
-
const index = collection.objects.map((object2) => object2.target).filter(isNonNullable).findIndex((section) => Obj.getDXN(section).toString() === id2);
|
|
209
|
-
const object = collection.objects[index].target;
|
|
210
|
-
if (isLiveObject(object)) {
|
|
211
|
-
await dispatch(createIntent(SpaceAction.RemoveObjects, {
|
|
212
|
-
objects: [
|
|
213
|
-
object
|
|
214
|
-
],
|
|
215
|
-
target: collection
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
}, [
|
|
219
|
-
collection,
|
|
220
|
-
dispatch
|
|
221
|
-
]);
|
|
222
|
-
const handleAdd = useCallback(async (id2, position) => {
|
|
223
|
-
await dispatch?.(
|
|
224
|
-
// TODO(wittjosiah): Use object creation dialog.
|
|
225
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
226
|
-
part: "dialog",
|
|
227
|
-
subject: `${meta.id}/AddSectionDialog`,
|
|
228
|
-
options: {
|
|
229
|
-
blockAlign: "start",
|
|
230
|
-
props: {
|
|
231
|
-
path: id2,
|
|
232
|
-
position,
|
|
233
|
-
collection
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
);
|
|
238
|
-
}, [
|
|
239
|
-
collection,
|
|
240
|
-
dispatch
|
|
241
|
-
]);
|
|
242
|
-
const handleNavigate = useCallback(async (id2) => {
|
|
243
|
-
await dispatch(createIntent(LayoutAction.Open, {
|
|
244
|
-
part: "main",
|
|
245
|
-
subject: [
|
|
246
|
-
id2
|
|
247
|
-
]
|
|
248
|
-
}));
|
|
249
|
-
}, [
|
|
250
|
-
dispatch
|
|
251
|
-
]);
|
|
252
|
-
const handleCollapse = useCallback((id2, collapsed) => setCollapsedSections((prev) => ({
|
|
253
|
-
...prev,
|
|
254
|
-
[id2]: collapsed
|
|
255
|
-
})), []);
|
|
256
|
-
const handleAddSection = useCallback(() => dispatch?.(createIntent(SpaceAction.OpenCreateObject, {
|
|
257
|
-
target: collection,
|
|
258
|
-
navigable: false
|
|
259
|
-
})), [
|
|
260
|
-
collection,
|
|
261
|
-
dispatch
|
|
262
|
-
]);
|
|
263
|
-
return /* @__PURE__ */ React3.createElement(StackItem2.Content, {
|
|
264
|
-
toolbar: true,
|
|
265
|
-
classNames: "container-max-width overflow-hidden border-l border-r border-subduedSeparator"
|
|
266
|
-
}, /* @__PURE__ */ React3.createElement(Toolbar.Root, null, /* @__PURE__ */ React3.createElement(Toolbar.IconButton, {
|
|
267
|
-
icon: "ph--plus--regular",
|
|
268
|
-
iconOnly: true,
|
|
269
|
-
label: "Add section",
|
|
270
|
-
"data-testid": "stack.addSection",
|
|
271
|
-
onClick: handleAddSection
|
|
272
|
-
})), /* @__PURE__ */ React3.createElement(AttentionProvider, {
|
|
273
|
-
id
|
|
274
|
-
}, /* @__PURE__ */ React3.createElement(StackContext.Provider, {
|
|
275
|
-
value: {
|
|
276
|
-
onCollapse: handleCollapse,
|
|
277
|
-
onNavigate: handleNavigate,
|
|
278
|
-
onDelete: handleDelete,
|
|
279
|
-
onAdd: handleAdd
|
|
280
|
-
}
|
|
281
|
-
}, /* @__PURE__ */ React3.createElement(Stack, {
|
|
282
|
-
orientation: "vertical",
|
|
283
|
-
size: "intrinsic",
|
|
284
|
-
id,
|
|
285
|
-
"data-testid": "main.stack",
|
|
286
|
-
classNames: "overflow-y-auto"
|
|
287
|
-
}, items.map((item) => /* @__PURE__ */ React3.createElement(StackSection, {
|
|
288
|
-
key: item.id,
|
|
289
|
-
...item
|
|
290
|
-
}))))));
|
|
291
|
-
} finally {
|
|
292
|
-
_effect.f();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var StackContainer_default = StackContainer;
|
|
296
|
-
export {
|
|
297
|
-
StackContainer_default as default
|
|
298
|
-
};
|
|
299
|
-
//# sourceMappingURL=StackContainer-DD3ZD5OE.mjs.map
|