@dxos/react-list 0.1.23 → 0.1.45-next.45667d4

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 (47) hide show
  1. package/README.md +1 -22
  2. package/dist/lib/browser/index.mjs +147 -493
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/node/index.cjs +229 -0
  6. package/dist/lib/node/index.cjs.map +7 -0
  7. package/dist/lib/node/meta.json +1 -0
  8. package/dist/types/src/List.d.ts +42 -0
  9. package/dist/types/src/List.d.ts.map +1 -0
  10. package/dist/types/src/ListItem.d.ts +56 -0
  11. package/dist/types/src/ListItem.d.ts.map +1 -0
  12. package/dist/types/src/index.d.ts +2 -2
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/package.json +24 -18
  15. package/src/List.tsx +87 -0
  16. package/src/ListItem.tsx +228 -0
  17. package/src/index.ts +2 -2
  18. package/dist/types/src/components/List/List.d.ts +0 -8
  19. package/dist/types/src/components/List/List.d.ts.map +0 -1
  20. package/dist/types/src/components/List/List.stories.d.ts +0 -17
  21. package/dist/types/src/components/List/List.stories.d.ts.map +0 -1
  22. package/dist/types/src/components/List/index.d.ts +0 -2
  23. package/dist/types/src/components/List/index.d.ts.map +0 -1
  24. package/dist/types/src/components/ListPrimitive/ListPrimitive.d.ts +0 -55
  25. package/dist/types/src/components/ListPrimitive/ListPrimitive.d.ts.map +0 -1
  26. package/dist/types/src/components/ListPrimitive/ListPrimitive.stories.d.ts +0 -31
  27. package/dist/types/src/components/ListPrimitive/ListPrimitive.stories.d.ts.map +0 -1
  28. package/dist/types/src/components/ListPrimitive/index.d.ts +0 -2
  29. package/dist/types/src/components/ListPrimitive/index.d.ts.map +0 -1
  30. package/dist/types/src/components/index.d.ts +0 -2
  31. package/dist/types/src/components/index.d.ts.map +0 -1
  32. package/dist/types/src/hooks/index.d.ts +0 -2
  33. package/dist/types/src/hooks/index.d.ts.map +0 -1
  34. package/dist/types/src/hooks/usePropStatefully.d.ts +0 -6
  35. package/dist/types/src/hooks/usePropStatefully.d.ts.map +0 -1
  36. package/dist/types/src/model.d.ts +0 -3
  37. package/dist/types/src/model.d.ts.map +0 -1
  38. package/src/components/List/List.stories.tsx +0 -123
  39. package/src/components/List/List.tsx +0 -111
  40. package/src/components/List/index.ts +0 -5
  41. package/src/components/ListPrimitive/ListPrimitive.stories.tsx +0 -41
  42. package/src/components/ListPrimitive/ListPrimitive.tsx +0 -474
  43. package/src/components/ListPrimitive/index.ts +0 -5
  44. package/src/components/index.ts +0 -5
  45. package/src/hooks/index.ts +0 -5
  46. package/src/hooks/usePropStatefully.ts +0 -33
  47. package/src/model.ts +0 -6
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePropStatefully.d.ts","sourceRoot":"","sources":["../../../../src/hooks/usePropStatefully.ts"],"names":[],"mappings":"AAIA,OAAO,EAA+B,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAM9E;;GAEG;AACH,eAAO,MAAM,iBAAiB,4DAEU,OAAO,0DAiB9C,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const LIST_TYPE = "dxos:type/list";
2
- export declare const LIST_ITEM_TYPE = "dxos:type/list-item";
3
- //# sourceMappingURL=model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/model.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,mBAAmB,CAAC;AAC1C,eAAO,MAAM,cAAc,wBAAwB,CAAC"}
@@ -1,123 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import '@dxosTheme';
6
- import type { StoryFn } from '@storybook/react';
7
- import React, { useMemo, useState } from 'react';
8
-
9
- import { Trigger } from '@dxos/async';
10
- import { Client, Invitation, PublicKey } from '@dxos/client';
11
- import { TestBuilder } from '@dxos/client/testing';
12
- import { raise } from '@dxos/debug';
13
- import { ObjectModel } from '@dxos/object-model';
14
- import { useAsyncEffect } from '@dxos/react-async';
15
- import { ClientProvider, useSelection, useSpace } from '@dxos/react-client';
16
- import { Loading } from '@dxos/react-components';
17
-
18
- import { LIST_TYPE } from '../../model';
19
- import { List, ListProps } from './List';
20
-
21
- // TODO(wittjosiah): @dxos/log.
22
- const log = console.log;
23
-
24
- export default {
25
- component: List,
26
- argTypes: {}
27
- };
28
-
29
- export const Default = {
30
- render: (args: Omit<ListProps, 'itemId' | 'spaceKey'> & { spaceKey?: PublicKey; id?: number }) => {
31
- const space = useSpace(args.spaceKey);
32
- const [item] = useSelection(space?.database.select({ type: LIST_TYPE })) ?? [];
33
-
34
- useAsyncEffect(async () => {
35
- if (args.id === 0) {
36
- await space?.database.createItem({
37
- model: ObjectModel,
38
- type: LIST_TYPE
39
- });
40
- }
41
- }, [space]);
42
-
43
- return (
44
- <main className='max-is-lg mli-auto pli-7 mbs-7'>
45
- {item && space ? <List {...args} itemId={item.id} spaceKey={space?.key} /> : <Loading label='Loading…' />}
46
- </main>
47
- );
48
- },
49
- decorators: [
50
- // TODO(wittjosiah): Factor out.
51
- (Story: StoryFn) => {
52
- const n = 2;
53
- const clients = useMemo(() => {
54
- const testBuilder = new TestBuilder();
55
- return [...Array(n)].map(() => new Client({ services: testBuilder.createClientServicesHost() }));
56
- }, []);
57
-
58
- const [spaceKey, setSpaceKey] = useState<PublicKey>();
59
-
60
- useAsyncEffect(async () => {
61
- await Promise.all(clients.map((client) => client.initialize()));
62
- log('initialized');
63
-
64
- await Promise.all(clients.map((client) => client.halo.createProfile()));
65
- log('identity created');
66
-
67
- const space = await clients[0].echo.createSpace();
68
- log('space created', { space: space.key });
69
-
70
- await Promise.all(
71
- clients.slice(1).map(async (client) => {
72
- const success1 = new Trigger<Invitation>();
73
- const success2 = new Trigger<Invitation>();
74
-
75
- const observable1 = space.createInvitation({ type: Invitation.Type.INTERACTIVE_TESTING });
76
- log('invitation created');
77
- observable1.subscribe({
78
- onConnecting: (invitation) => {
79
- const observable2 = client.echo.acceptInvitation(invitation);
80
- log('invitation accepted');
81
-
82
- observable2.subscribe({
83
- onSuccess: (invitation: Invitation) => {
84
- success2.wake(invitation);
85
- log('invitation success2');
86
- },
87
- onError: (err: Error) => raise(err)
88
- });
89
- },
90
- onSuccess: (invitation) => {
91
- success1.wake(invitation);
92
- log('invitation success1');
93
- },
94
- onError: (err) => raise(err)
95
- });
96
-
97
- await Promise.all([success1.wait(), success2.wait()]);
98
- })
99
- );
100
-
101
- setSpaceKey(space.key);
102
-
103
- return () => {
104
- void Promise.all(clients.map((client) => client.destroy()));
105
- };
106
- }, clients);
107
-
108
- if (!spaceKey) {
109
- return <Loading label='Loading…' />;
110
- }
111
-
112
- return (
113
- <div className='flex'>
114
- {clients.map((client, index) => (
115
- <ClientProvider key={index} client={client} fallback={<Loading label='Loading…' />}>
116
- <Story args={{ spaceKey, id: index }} />
117
- </ClientProvider>
118
- ))}
119
- </div>
120
- );
121
- }
122
- ]
123
- };
@@ -1,111 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import React, { useCallback } from 'react';
6
-
7
- import { Item, PublicKey, Space } from '@dxos/client';
8
- import { ObjectModel } from '@dxos/object-model';
9
- import { useSelection, useSpace } from '@dxos/react-client';
10
- import { Loading, useTranslation } from '@dxos/react-components';
11
-
12
- import { LIST_ITEM_TYPE } from '../../model';
13
- import {
14
- ListPrimitive,
15
- ListAction,
16
- ListItems,
17
- isListItemChangedAction,
18
- isListItemDeletedAction,
19
- isListItemCreatedAction,
20
- ListItemProps,
21
- ListPrimitiveProps
22
- } from '../ListPrimitive';
23
-
24
- interface ListLoadedProps {
25
- space: Space;
26
- list: Item<ObjectModel>;
27
- listItems: Item<ObjectModel>[];
28
- }
29
-
30
- export interface ListProps {
31
- spaceKey: PublicKey;
32
- itemId: Item<ObjectModel>['id'];
33
- }
34
-
35
- const ListLoaded = ({ space, list, listItems: propsListItems }: ListLoadedProps) => {
36
- const listItems = useSelection(list?.select().children().filter({ type: LIST_ITEM_TYPE })) ?? propsListItems;
37
-
38
- const onAction = useCallback(
39
- async (action: ListAction) => {
40
- if (isListItemDeletedAction(action)) {
41
- const subject = space.database.getItem(action.deleted.id);
42
- // TODO(thure): use Echo’s native deletion
43
- return subject?.model.set('annotations.deleted', true);
44
- } else if (isListItemCreatedAction(action)) {
45
- // do nothing?
46
- } else if (isListItemChangedAction(action)) {
47
- const subject = space.database.getItem(action.listItemId);
48
- return Promise.all(
49
- (Object.keys(action.next) as (keyof ListItemProps)[]).map((prop) => {
50
- return subject?.model.set(prop, action.next[prop]);
51
- })
52
- );
53
- } else {
54
- return Promise.all(
55
- (Object.keys(action.next) as (keyof ListPrimitiveProps)[]).map((prop) => {
56
- return list?.model.set(prop, action.next[prop]);
57
- })
58
- );
59
- }
60
- },
61
- [list, listItems]
62
- );
63
-
64
- const createListItemId = useCallback(async () => {
65
- const listItem = await space?.database.createItem({
66
- model: ObjectModel,
67
- type: LIST_ITEM_TYPE,
68
- parent: list.id
69
- });
70
- return listItem.id;
71
- }, [space]);
72
-
73
- return (
74
- <ListPrimitive
75
- {...{
76
- id: list.id,
77
- title: list.model.get('title') ?? '',
78
- description: list.model.get('description') ?? '',
79
- items: (listItems ?? [])
80
- // TODO(thure): use Echo’s native deletion
81
- .filter((item) => !item.model.get('annotations.deleted'))
82
- .reduce((acc: ListItems, item) => {
83
- acc[item.id] = {
84
- title: item.model.get('title'),
85
- description: item.model.get('description'),
86
- annotations: item.model.get('annotations')
87
- };
88
- return acc;
89
- }, {}),
90
- onChangePeriod: 640,
91
- onAction,
92
- createListItemId
93
- }}
94
- />
95
- );
96
- };
97
-
98
- export const List = ({ spaceKey, itemId }: ListProps) => {
99
- const { t } = useTranslation('appkit');
100
-
101
- const space = useSpace(spaceKey);
102
- const list = (useSelection(space?.database.select({ id: itemId })) ?? [])[0];
103
- const listItems = useSelection(list?.select().children().filter({ type: LIST_ITEM_TYPE }));
104
-
105
- // TODO(thure): this should become `Suspense` when the above hooks support it
106
- return space && list && listItems ? (
107
- <ListLoaded {...{ space, list, listItems }} />
108
- ) : (
109
- <Loading label={t('generic loading label')} />
110
- );
111
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- export * from './List';
@@ -1,41 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import '@dxosTheme';
6
- import React from 'react';
7
-
8
- import { ListPrimitive, ListPrimitiveComponentProps } from './ListPrimitive';
9
-
10
- export default {
11
- component: ListPrimitive,
12
- argTypes: {}
13
- };
14
-
15
- export const Default = {
16
- render: (args: Omit<ListPrimitiveComponentProps, 'item'>) => {
17
- return (
18
- <main className='max-is-lg mli-auto pli-7 mbs-7'>
19
- <ListPrimitive {...args} />
20
- </main>
21
- );
22
- },
23
- args: {
24
- id: 'x123456',
25
- items: {
26
- x234567: {
27
- title: 'Apple'
28
- },
29
- x345678: {
30
- title: 'Grapes',
31
- annotations: { state: 'done' }
32
- },
33
- x456789: {
34
- title: 'Banana'
35
- },
36
- x567890: {
37
- title: 'Courgette'
38
- }
39
- }
40
- }
41
- };