@dxos/plugin-stack 0.6.8-main.046e6cf
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 +8 -0
- package/README.md +15 -0
- package/dist/lib/browser/StackMain-MDOKSAYA.mjs +276 -0
- package/dist/lib/browser/StackMain-MDOKSAYA.mjs.map +7 -0
- package/dist/lib/browser/chunk-AYDYMPJK.mjs +19 -0
- package/dist/lib/browser/chunk-AYDYMPJK.mjs.map +7 -0
- package/dist/lib/browser/chunk-R5KXWF2W.mjs +21 -0
- package/dist/lib/browser/chunk-R5KXWF2W.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +285 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/meta.mjs +11 -0
- package/dist/lib/browser/meta.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +9 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node/StackMain-AXFLSTLI.cjs +295 -0
- package/dist/lib/node/StackMain-AXFLSTLI.cjs.map +7 -0
- package/dist/lib/node/chunk-EMD6A66G.cjs +44 -0
- package/dist/lib/node/chunk-EMD6A66G.cjs.map +7 -0
- package/dist/lib/node/chunk-I42JKRXR.cjs +53 -0
- package/dist/lib/node/chunk-I42JKRXR.cjs.map +7 -0
- package/dist/lib/node/index.cjs +298 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.cjs +32 -0
- package/dist/lib/node/meta.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node/types/index.cjs +31 -0
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/types/src/StackPlugin.d.ts +4 -0
- package/dist/types/src/StackPlugin.d.ts.map +1 -0
- package/dist/types/src/components/AddSection.d.ts +6 -0
- package/dist/types/src/components/AddSection.d.ts.map +1 -0
- package/dist/types/src/components/AddSectionDialog.d.ts +14 -0
- package/dist/types/src/components/AddSectionDialog.d.ts.map +1 -0
- package/dist/types/src/components/StackMain.d.ts +9 -0
- package/dist/types/src/components/StackMain.d.ts.map +1 -0
- package/dist/types/src/components/StackSettings.d.ts +6 -0
- package/dist/types/src/components/StackSettings.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +8 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +12 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +30 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/stack.d.ts +26 -0
- package/dist/types/src/types/stack.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +34 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/package.json +91 -0
- package/src/StackPlugin.tsx +101 -0
- package/src/components/AddSection.tsx +102 -0
- package/src/components/AddSectionDialog.tsx +130 -0
- package/src/components/StackMain.tsx +216 -0
- package/src/components/StackSettings.tsx +23 -0
- package/src/components/index.ts +11 -0
- package/src/index.ts +11 -0
- package/src/meta.tsx +17 -0
- package/src/translations.ts +26 -0
- package/src/types/index.ts +6 -0
- package/src/types/stack.ts +21 -0
- package/src/types/types.ts +47 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Plus } from '@phosphor-icons/react';
|
|
6
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
LayoutAction,
|
|
10
|
+
NavigationAction,
|
|
11
|
+
parseMetadataResolverPlugin,
|
|
12
|
+
Surface,
|
|
13
|
+
useIntentDispatcher,
|
|
14
|
+
useResolvePlugin,
|
|
15
|
+
} from '@dxos/app-framework';
|
|
16
|
+
import { create, getType, isReactiveObject } from '@dxos/echo-schema';
|
|
17
|
+
import { useGraph } from '@dxos/plugin-graph';
|
|
18
|
+
import { SpaceAction } from '@dxos/plugin-space';
|
|
19
|
+
import { type CollectionType } from '@dxos/plugin-space/types';
|
|
20
|
+
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
21
|
+
import { Button, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
22
|
+
import { type MosaicDataItem, type MosaicDropEvent, type MosaicMoveEvent, Path } from '@dxos/react-ui-mosaic';
|
|
23
|
+
import {
|
|
24
|
+
type AddSectionPosition,
|
|
25
|
+
type CollapsedSections,
|
|
26
|
+
Stack,
|
|
27
|
+
type StackProps,
|
|
28
|
+
type StackSectionItem,
|
|
29
|
+
} from '@dxos/react-ui-stack';
|
|
30
|
+
import { nonNullable } from '@dxos/util';
|
|
31
|
+
|
|
32
|
+
import { AddSection } from './AddSection';
|
|
33
|
+
import { SECTION_IDENTIFIER, STACK_PLUGIN } from '../meta';
|
|
34
|
+
import { StackViewType } from '../types';
|
|
35
|
+
|
|
36
|
+
const SectionContent: StackProps['SectionContent'] = ({ data }) => {
|
|
37
|
+
// TODO(wittjosiah): Better section placeholder.
|
|
38
|
+
return <Surface role='section' data={{ object: data }} limit={1} placeholder={<></>} />;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type StackMainProps = {
|
|
42
|
+
collection: CollectionType;
|
|
43
|
+
separation?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const StackMain = ({ collection, separation }: StackMainProps) => {
|
|
47
|
+
const dispatch = useIntentDispatcher();
|
|
48
|
+
const { graph } = useGraph();
|
|
49
|
+
const { t } = useTranslation(STACK_PLUGIN);
|
|
50
|
+
const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
|
|
51
|
+
const defaultStack = useMemo(() => create(StackViewType, { sections: {} }), [collection]);
|
|
52
|
+
const stack = (collection.views[StackViewType.typename] as StackViewType) ?? defaultStack;
|
|
53
|
+
const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!collection.views[StackViewType.typename]) {
|
|
57
|
+
collection.views[StackViewType.typename] = stack;
|
|
58
|
+
}
|
|
59
|
+
}, [collection, stack]);
|
|
60
|
+
|
|
61
|
+
const id = `stack-${collection.id}`;
|
|
62
|
+
const items =
|
|
63
|
+
collection.objects
|
|
64
|
+
// TODO(wittjosiah): Should the database handle this differently?
|
|
65
|
+
// TODO(wittjosiah): Render placeholders for missing objects so they can be removed from the stack?
|
|
66
|
+
.filter(nonNullable)
|
|
67
|
+
.map((object) => {
|
|
68
|
+
const metadata = metadataPlugin?.provides.metadata.resolver(
|
|
69
|
+
getType(object)?.objectId ?? 'never',
|
|
70
|
+
) as StackSectionItem['metadata'];
|
|
71
|
+
const view = {
|
|
72
|
+
...stack.sections[object.id],
|
|
73
|
+
collapsed: collapsedSections[fullyQualifiedId(object)],
|
|
74
|
+
title:
|
|
75
|
+
(object as any)?.title ?? toLocalizedString(graph.findNode(fullyQualifiedId(object))?.properties.label, t),
|
|
76
|
+
} as StackSectionItem['view'];
|
|
77
|
+
return { id: fullyQualifiedId(object), object, metadata, view };
|
|
78
|
+
}) ?? [];
|
|
79
|
+
|
|
80
|
+
const handleOver = ({ active, over }: MosaicMoveEvent<number>) => {
|
|
81
|
+
// TODO(thure): Eventually Stack should handle foreign draggables.
|
|
82
|
+
if (active.type !== SECTION_IDENTIFIER) {
|
|
83
|
+
return 'reject';
|
|
84
|
+
}
|
|
85
|
+
if (Path.parent(active.path) === Path.parent(over.path)) {
|
|
86
|
+
return 'rearrange';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
|
|
90
|
+
const data = parseData ? parseData(active.item, 'object') : active.item;
|
|
91
|
+
|
|
92
|
+
// TODO(wittjosiah): Prevent dropping items which don't have a section renderer?
|
|
93
|
+
// Perhaps stack plugin should just provide a fallback section renderer.
|
|
94
|
+
if (!isReactiveObject(data)) {
|
|
95
|
+
return 'reject';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const exists = items.findIndex(({ id }) => id === active.item.id) >= 0;
|
|
99
|
+
if (!exists) {
|
|
100
|
+
return 'transfer';
|
|
101
|
+
} else {
|
|
102
|
+
return 'reject';
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const handleDrop = ({ operation, active, over }: MosaicDropEvent<number>) => {
|
|
107
|
+
if (
|
|
108
|
+
(active.path === Path.create(id, active.item.id) || active.path === id) &&
|
|
109
|
+
(operation !== 'copy' || over.path === Path.create(id, over.item.id) || over.path === id)
|
|
110
|
+
) {
|
|
111
|
+
collection.objects.splice(active.position!, 1);
|
|
112
|
+
delete stack.sections[active.item.id];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
|
|
116
|
+
const object = parseData?.(active.item, 'object');
|
|
117
|
+
if (object && over.path === Path.create(id, over.item.id)) {
|
|
118
|
+
collection.objects.splice(over.position!, 0, object);
|
|
119
|
+
} else if (object && over.path === id) {
|
|
120
|
+
collection.objects.push(object);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!stack.sections[object.id]) {
|
|
124
|
+
stack.sections[object.id] = {};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const handleDelete = async (path: string) => {
|
|
129
|
+
const index = collection.objects
|
|
130
|
+
.filter(nonNullable)
|
|
131
|
+
.findIndex((section) => fullyQualifiedId(section) === Path.last(path));
|
|
132
|
+
if (index >= 0) {
|
|
133
|
+
await dispatch({
|
|
134
|
+
action: SpaceAction.REMOVE_OBJECT,
|
|
135
|
+
data: { object: collection.objects[index], collection },
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.
|
|
139
|
+
// delete stack.sections[Path.last(path)];
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// TODO(wittjosiah): Factor out.
|
|
144
|
+
|
|
145
|
+
const handleNavigate = async (object: MosaicDataItem) => {
|
|
146
|
+
const toId = fullyQualifiedId(object);
|
|
147
|
+
await dispatch([
|
|
148
|
+
{
|
|
149
|
+
action: NavigationAction.OPEN,
|
|
150
|
+
data: { activeParts: { main: [toId] } },
|
|
151
|
+
},
|
|
152
|
+
{ action: LayoutAction.SCROLL_INTO_VIEW, data: { id: toId } },
|
|
153
|
+
]);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleAddSection = (path: string, position: AddSectionPosition) => {
|
|
157
|
+
void dispatch?.({
|
|
158
|
+
action: LayoutAction.SET_LAYOUT,
|
|
159
|
+
data: {
|
|
160
|
+
element: 'dialog',
|
|
161
|
+
component: `${STACK_PLUGIN}/AddSectionDialog`,
|
|
162
|
+
subject: { path, position, collection },
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const handleCollapseSection = (id: string, collapsed: boolean) => {
|
|
168
|
+
setCollapsedSections((prev) => ({ ...prev, [id]: collapsed }));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<>
|
|
173
|
+
<Stack
|
|
174
|
+
id={id}
|
|
175
|
+
data-testid='main.stack'
|
|
176
|
+
SectionContent={SectionContent}
|
|
177
|
+
type={SECTION_IDENTIFIER}
|
|
178
|
+
items={items}
|
|
179
|
+
separation={separation}
|
|
180
|
+
emptyComponent={<span data-testid='stack.empty'></span>}
|
|
181
|
+
onDrop={handleDrop}
|
|
182
|
+
onOver={handleOver}
|
|
183
|
+
onDeleteSection={handleDelete}
|
|
184
|
+
onNavigateToSection={handleNavigate}
|
|
185
|
+
onAddSection={handleAddSection}
|
|
186
|
+
onCollapseSection={handleCollapseSection}
|
|
187
|
+
/>
|
|
188
|
+
|
|
189
|
+
{items.length === 0 ? (
|
|
190
|
+
<AddSection collection={collection} />
|
|
191
|
+
) : (
|
|
192
|
+
<div role='none' className='flex mlb-2 pli-2 justify-center'>
|
|
193
|
+
<Button
|
|
194
|
+
data-testid='stack.createSection'
|
|
195
|
+
classNames='gap-2'
|
|
196
|
+
onClick={() =>
|
|
197
|
+
dispatch?.({
|
|
198
|
+
action: LayoutAction.SET_LAYOUT,
|
|
199
|
+
data: {
|
|
200
|
+
element: 'dialog',
|
|
201
|
+
component: 'dxos.org/plugin/stack/AddSectionDialog',
|
|
202
|
+
subject: { position: 'afterAll', collection },
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
>
|
|
207
|
+
<Plus />
|
|
208
|
+
<span className='sr-only'>{t('add section label')}</span>
|
|
209
|
+
</Button>
|
|
210
|
+
</div>
|
|
211
|
+
)}
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export default StackMain;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { SettingsValue } from '@dxos/plugin-settings';
|
|
8
|
+
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
|
|
10
|
+
import { STACK_PLUGIN } from '../meta';
|
|
11
|
+
import { type StackSettingsProps } from '../types';
|
|
12
|
+
|
|
13
|
+
export const StackSettings = ({ settings }: { settings: StackSettingsProps }) => {
|
|
14
|
+
const { t } = useTranslation(STACK_PLUGIN);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<SettingsValue label={t('settings separation label')}>
|
|
19
|
+
<Input.Switch checked={settings.separation} onCheckedChange={(checked) => (settings.separation = !!checked)} />
|
|
20
|
+
</SettingsValue>
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
// Lazily load components for content surfaces.
|
|
8
|
+
export const StackMain = React.lazy(() => import('./StackMain'));
|
|
9
|
+
|
|
10
|
+
export * from './StackSettings';
|
|
11
|
+
export * from './AddSectionDialog';
|
package/src/index.ts
ADDED
package/src/meta.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type IconProps, StackSimple } from '@phosphor-icons/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
export const STACK_PLUGIN = 'dxos.org/plugin/stack';
|
|
9
|
+
export const SECTION_IDENTIFIER = 'dxos.org/type/StackSection';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
id: STACK_PLUGIN,
|
|
13
|
+
// TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
|
|
14
|
+
name: 'Collections',
|
|
15
|
+
iconComponent: (props: IconProps) => <StackSimple {...props} />,
|
|
16
|
+
iconSymbol: 'ph--stack-simple--regular',
|
|
17
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { translations as stackTranslations } from '@dxos/react-ui-stack';
|
|
6
|
+
|
|
7
|
+
import { STACK_PLUGIN } from './meta';
|
|
8
|
+
|
|
9
|
+
export default [
|
|
10
|
+
{
|
|
11
|
+
'en-US': {
|
|
12
|
+
[STACK_PLUGIN]: {
|
|
13
|
+
'plugin name': 'Stacks',
|
|
14
|
+
'settings separation label': 'Separate sections',
|
|
15
|
+
'add section beforeAll dialog title': 'Add a section to the start',
|
|
16
|
+
'add section afterAll dialog title': 'Add a section to the end',
|
|
17
|
+
'add section before dialog title': 'Add a section',
|
|
18
|
+
'add section after dialog title': 'Add a section',
|
|
19
|
+
'add section input placeholder': 'Find the type of section to add',
|
|
20
|
+
'upload file label': 'Add file',
|
|
21
|
+
'add section label': 'Add section',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
...stackTranslations,
|
|
26
|
+
];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { S, TypedObject } from '@dxos/echo-schema';
|
|
6
|
+
|
|
7
|
+
// All section metadata needs to be optional/have defaults.
|
|
8
|
+
// Any objects added to the collection will start with the section defaults.
|
|
9
|
+
// If an object is removed from the collection without removing the section metadata this is fine.
|
|
10
|
+
// Stack component should cleanup the superfluous data on future edits.
|
|
11
|
+
|
|
12
|
+
export const SectionSchema = S.Struct({
|
|
13
|
+
height: S.optional(S.Number),
|
|
14
|
+
// Space for data that isn't stack-specific but is specific to this view instance.
|
|
15
|
+
// e.g. cover/fill for an image
|
|
16
|
+
custom: S.optional(S.Record(S.String, S.Any)),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export class StackViewType extends TypedObject({ typename: 'dxos.org/type/StackView', version: '0.1.0' })({
|
|
20
|
+
sections: S.mutable(S.Record(S.String, SectionSchema)),
|
|
21
|
+
}) {}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type IconProps } from '@phosphor-icons/react';
|
|
6
|
+
import { type FC } from 'react';
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
Intent,
|
|
10
|
+
MetadataRecordsProvides,
|
|
11
|
+
SettingsProvides,
|
|
12
|
+
SurfaceProvides,
|
|
13
|
+
TranslationsProvides,
|
|
14
|
+
} from '@dxos/app-framework';
|
|
15
|
+
import { type SchemaProvides } from '@dxos/plugin-client';
|
|
16
|
+
|
|
17
|
+
// TODO(wittjosiah): Creators/choosers likely aren't stack-specific.
|
|
18
|
+
// Also distinct from graph actions though, output should be inserted into current view rather than navigated to.
|
|
19
|
+
type StackSectionAction = {
|
|
20
|
+
id: string;
|
|
21
|
+
testId: string;
|
|
22
|
+
type: string | [string, { ns: string }];
|
|
23
|
+
label: string | [string, { ns: string }];
|
|
24
|
+
icon: FC<IconProps>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type StackSectionCreator = StackSectionAction & {
|
|
28
|
+
intent: Intent | Intent[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type StackProvides = {
|
|
32
|
+
stack: {
|
|
33
|
+
creators?: StackSectionCreator[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type StackState = {
|
|
38
|
+
creators: StackSectionCreator[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type StackSettingsProps = { separation: boolean };
|
|
42
|
+
|
|
43
|
+
export type StackPluginProvides = SurfaceProvides &
|
|
44
|
+
MetadataRecordsProvides &
|
|
45
|
+
SettingsProvides<StackSettingsProps> &
|
|
46
|
+
TranslationsProvides &
|
|
47
|
+
SchemaProvides & { stack: StackState };
|