@dxos/plugin-stack 0.7.4 → 0.7.5-main.9d26e3a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/StackMain-HSYQ5B3Y.mjs +295 -0
- package/dist/lib/browser/StackMain-HSYQ5B3Y.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +28 -163
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/StackMain-AWN5MFZK.cjs +309 -0
- package/dist/lib/node/StackMain-AWN5MFZK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +28 -161
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/StackMain-EFCZCMIJ.mjs +296 -0
- package/dist/lib/node-esm/StackMain-EFCZCMIJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +28 -163
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/StackPlugin.d.ts.map +1 -1
- package/dist/types/src/components/StackMain.d.ts.map +1 -1
- package/dist/types/src/components/StackSection.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/types/stack.d.ts +6 -12
- package/dist/types/src/types/stack.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -16
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +23 -23
- package/src/StackPlugin.tsx +26 -47
- package/src/components/StackMain.tsx +60 -69
- package/src/components/StackSection.tsx +2 -4
- package/src/components/index.ts +0 -1
- package/src/types/types.ts +3 -19
- package/dist/lib/browser/StackMain-4D4J4IRK.mjs +0 -391
- package/dist/lib/browser/StackMain-4D4J4IRK.mjs.map +0 -7
- package/dist/lib/node/StackMain-V7C55NCF.cjs +0 -403
- package/dist/lib/node/StackMain-V7C55NCF.cjs.map +0 -7
- package/dist/lib/node-esm/StackMain-5I43UWGF.mjs +0 -392
- package/dist/lib/node-esm/StackMain-5I43UWGF.mjs.map +0 -7
- package/dist/types/src/components/AddSection.d.ts +0 -6
- package/dist/types/src/components/AddSection.d.ts.map +0 -1
- package/dist/types/src/components/AddSectionDialog.d.ts +0 -14
- package/dist/types/src/components/AddSectionDialog.d.ts.map +0 -1
- package/src/components/AddSection.tsx +0 -102
- package/src/components/AddSectionDialog.tsx +0 -128
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { FilePlus } from '@phosphor-icons/react';
|
|
6
|
-
import React, { useCallback, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { usePlugin, useIntent, LayoutAction, useResolvePlugin, parseFileManagerPlugin } from '@dxos/app-framework';
|
|
9
|
-
import { type ReactiveEchoObject, create, getSpace } from '@dxos/client/echo';
|
|
10
|
-
import { FileType } from '@dxos/plugin-ipfs/types';
|
|
11
|
-
import { type CollectionType } from '@dxos/plugin-space/types';
|
|
12
|
-
import { Dialog, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
13
|
-
import { Path } from '@dxos/react-ui-mosaic';
|
|
14
|
-
import { SearchList } from '@dxos/react-ui-searchlist';
|
|
15
|
-
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
16
|
-
import { nonNullable } from '@dxos/util';
|
|
17
|
-
|
|
18
|
-
import { STACK_PLUGIN } from '../meta';
|
|
19
|
-
import { StackViewType, type StackPluginProvides, type AddSectionPosition } from '../types';
|
|
20
|
-
|
|
21
|
-
type AddSectionDialogProps = { path?: string; position: AddSectionPosition; collection: CollectionType };
|
|
22
|
-
|
|
23
|
-
export const dataHasAddSectionDialogProps = (data: any): data is { subject: AddSectionDialogProps } => {
|
|
24
|
-
return (
|
|
25
|
-
'subject' in data &&
|
|
26
|
-
typeof data.subject === 'object' &&
|
|
27
|
-
!!data.subject &&
|
|
28
|
-
'position' in data.subject &&
|
|
29
|
-
typeof data.subject.position === 'string' &&
|
|
30
|
-
'collection' in data.subject
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const AddSectionDialog = ({ path, position, collection }: AddSectionDialogProps) => {
|
|
35
|
-
const { t } = useTranslation(STACK_PLUGIN);
|
|
36
|
-
const stackPlugin = usePlugin<StackPluginProvides>(STACK_PLUGIN);
|
|
37
|
-
const fileManagerPlugin = useResolvePlugin(parseFileManagerPlugin);
|
|
38
|
-
const fileRef = useRef<HTMLInputElement | null>(null);
|
|
39
|
-
const { dispatch } = useIntent();
|
|
40
|
-
const space = getSpace(collection);
|
|
41
|
-
const [pending, setPending] = useState<boolean>(false);
|
|
42
|
-
const [uploadError, setUploadError] = useState<Error | undefined>();
|
|
43
|
-
|
|
44
|
-
const handleAdd = useCallback(
|
|
45
|
-
(sectionObject: ReactiveEchoObject<any>) => {
|
|
46
|
-
const index =
|
|
47
|
-
position === 'beforeAll'
|
|
48
|
-
? 0
|
|
49
|
-
: position === 'afterAll'
|
|
50
|
-
? collection.objects.length
|
|
51
|
-
: collection.objects.filter(nonNullable).findIndex((section) => section.id === Path.last(path!));
|
|
52
|
-
|
|
53
|
-
collection.objects.splice(index + (position === 'after' ? 1 : 0), 0, sectionObject);
|
|
54
|
-
const stack = collection.views[StackViewType.typename];
|
|
55
|
-
if (stack) {
|
|
56
|
-
stack.sections[sectionObject.id] = {};
|
|
57
|
-
}
|
|
58
|
-
setPending(false);
|
|
59
|
-
void dispatch?.({ action: LayoutAction.SET_LAYOUT, data: { element: 'dialog', state: false } });
|
|
60
|
-
},
|
|
61
|
-
[collection, path, position, dispatch],
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const handleFileUpload =
|
|
65
|
-
fileManagerPlugin?.provides.file.upload && space
|
|
66
|
-
? async (file: File) => {
|
|
67
|
-
const filename = file.name.split('.')[0];
|
|
68
|
-
try {
|
|
69
|
-
const info = await fileManagerPlugin.provides.file.upload?.(file, space);
|
|
70
|
-
if (info) {
|
|
71
|
-
const obj = create(FileType, { type: file.type, name: filename, filename, cid: info.cid });
|
|
72
|
-
handleAdd(obj);
|
|
73
|
-
}
|
|
74
|
-
} catch (err: any) {
|
|
75
|
-
setUploadError(err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
: undefined;
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<Dialog.Content>
|
|
82
|
-
<Dialog.Title>{t(`add section ${position} dialog title`)}</Dialog.Title>
|
|
83
|
-
<SearchList.Root label={t('add section input placeholder')}>
|
|
84
|
-
<SearchList.Input placeholder={t('add section input placeholder')} classNames='pli-3' disabled={pending} />
|
|
85
|
-
<SearchList.Content classNames='min-bs-24 bs-fit max-bs-64 overflow-auto' {...(pending && { inert: 'true' })}>
|
|
86
|
-
{stackPlugin?.provides?.stack.creators?.map(({ id, icon: Icon, label: propsLabel, testId, intent }) => {
|
|
87
|
-
const label = toLocalizedString(propsLabel, t);
|
|
88
|
-
return (
|
|
89
|
-
<SearchList.Item
|
|
90
|
-
value={label}
|
|
91
|
-
key={id}
|
|
92
|
-
onSelect={async () => {
|
|
93
|
-
setPending(true);
|
|
94
|
-
const { data: nextSection } = (await dispatch({ ...intent, data: { space } })) ?? {};
|
|
95
|
-
handleAdd(nextSection);
|
|
96
|
-
}}
|
|
97
|
-
classNames='flex items-center gap-2 pli-2'
|
|
98
|
-
data-testid={testId}
|
|
99
|
-
>
|
|
100
|
-
{Icon && <Icon className={mx(getSize(4), 'shrink-0')} />}
|
|
101
|
-
<span className='grow truncate'>{label}</span>
|
|
102
|
-
</SearchList.Item>
|
|
103
|
-
);
|
|
104
|
-
})}
|
|
105
|
-
{handleFileUpload && (
|
|
106
|
-
<SearchList.Item
|
|
107
|
-
value={t('upload file label')}
|
|
108
|
-
classNames='flex items-center gap-2 pli-2'
|
|
109
|
-
onSelect={() => fileRef.current?.click()}
|
|
110
|
-
>
|
|
111
|
-
<FilePlus />
|
|
112
|
-
<span className='grow truncate'>{t('upload file label')}</span>
|
|
113
|
-
</SearchList.Item>
|
|
114
|
-
)}
|
|
115
|
-
{uploadError && <div className='text-error-500'>{uploadError.message}</div>}
|
|
116
|
-
</SearchList.Content>
|
|
117
|
-
</SearchList.Root>
|
|
118
|
-
{handleFileUpload && (
|
|
119
|
-
<input
|
|
120
|
-
type='file'
|
|
121
|
-
className='sr-only'
|
|
122
|
-
ref={fileRef}
|
|
123
|
-
onChange={({ target: { files } }) => files && handleFileUpload(files[0])}
|
|
124
|
-
/>
|
|
125
|
-
)}
|
|
126
|
-
</Dialog.Content>
|
|
127
|
-
);
|
|
128
|
-
};
|