@dxos/plugin-stack 0.7.4 → 0.7.5-feature-compute.4d9d99a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/lib/browser/StackMain-VH3YESQL.mjs +295 -0
  2. package/dist/lib/browser/StackMain-VH3YESQL.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-DS5KGEJG.mjs → chunk-WTGFKPPQ.mjs} +3 -3
  4. package/dist/lib/browser/chunk-WTGFKPPQ.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +78 -235
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node/StackMain-USQVAFKL.cjs +309 -0
  9. package/dist/lib/node/StackMain-USQVAFKL.cjs.map +7 -0
  10. package/dist/lib/node/{chunk-PA5PRDM6.cjs → chunk-CZCFFT2J.cjs} +7 -7
  11. package/dist/lib/node/chunk-CZCFFT2J.cjs.map +7 -0
  12. package/dist/lib/node/index.cjs +80 -231
  13. package/dist/lib/node/index.cjs.map +4 -4
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node-esm/StackMain-DW27O56R.mjs +296 -0
  16. package/dist/lib/node-esm/StackMain-DW27O56R.mjs.map +7 -0
  17. package/dist/lib/node-esm/{chunk-JEQMG2E2.mjs → chunk-SJU6TPRI.mjs} +3 -3
  18. package/dist/lib/node-esm/chunk-SJU6TPRI.mjs.map +7 -0
  19. package/dist/lib/node-esm/index.mjs +78 -235
  20. package/dist/lib/node-esm/index.mjs.map +4 -4
  21. package/dist/lib/node-esm/meta.json +1 -1
  22. package/dist/types/src/StackPlugin.d.ts +1 -3
  23. package/dist/types/src/StackPlugin.d.ts.map +1 -1
  24. package/dist/types/src/components/StackMain.d.ts.map +1 -1
  25. package/dist/types/src/components/StackSection.d.ts.map +1 -1
  26. package/dist/types/src/components/index.d.ts +1 -2
  27. package/dist/types/src/components/index.d.ts.map +1 -1
  28. package/dist/types/src/index.d.ts +1 -3
  29. package/dist/types/src/index.d.ts.map +1 -1
  30. package/dist/types/src/meta.d.ts +1 -2
  31. package/dist/types/src/meta.d.ts.map +1 -1
  32. package/dist/types/src/types/stack.d.ts +6 -12
  33. package/dist/types/src/types/stack.d.ts.map +1 -1
  34. package/dist/types/src/types/types.d.ts +2 -17
  35. package/dist/types/src/types/types.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -0
  37. package/package.json +22 -31
  38. package/src/StackPlugin.tsx +61 -73
  39. package/src/components/StackMain.tsx +66 -76
  40. package/src/components/StackSection.tsx +2 -4
  41. package/src/components/index.ts +0 -1
  42. package/src/index.ts +1 -6
  43. package/src/meta.ts +1 -1
  44. package/src/types/types.ts +2 -31
  45. package/dist/lib/browser/StackMain-4D4J4IRK.mjs +0 -391
  46. package/dist/lib/browser/StackMain-4D4J4IRK.mjs.map +0 -7
  47. package/dist/lib/browser/chunk-DS5KGEJG.mjs.map +0 -7
  48. package/dist/lib/browser/meta.mjs +0 -11
  49. package/dist/lib/browser/meta.mjs.map +0 -7
  50. package/dist/lib/node/StackMain-V7C55NCF.cjs +0 -403
  51. package/dist/lib/node/StackMain-V7C55NCF.cjs.map +0 -7
  52. package/dist/lib/node/chunk-PA5PRDM6.cjs.map +0 -7
  53. package/dist/lib/node/meta.cjs +0 -32
  54. package/dist/lib/node/meta.cjs.map +0 -7
  55. package/dist/lib/node-esm/StackMain-5I43UWGF.mjs +0 -392
  56. package/dist/lib/node-esm/StackMain-5I43UWGF.mjs.map +0 -7
  57. package/dist/lib/node-esm/chunk-JEQMG2E2.mjs.map +0 -7
  58. package/dist/lib/node-esm/meta.mjs +0 -12
  59. package/dist/lib/node-esm/meta.mjs.map +0 -7
  60. package/dist/types/src/components/AddSection.d.ts +0 -6
  61. package/dist/types/src/components/AddSection.d.ts.map +0 -1
  62. package/dist/types/src/components/AddSectionDialog.d.ts +0 -14
  63. package/dist/types/src/components/AddSectionDialog.d.ts.map +0 -1
  64. package/src/components/AddSection.tsx +0 -102
  65. 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
- };