@dxos/plugin-preview 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0

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.
@@ -11,7 +11,7 @@ import { create } from '@dxos/echo-schema';
11
11
  import { faker } from '@dxos/random';
12
12
  import { makeRef } from '@dxos/react-client/echo';
13
13
  import { Icon, Popover } from '@dxos/react-ui';
14
- import { Contact, Organization, Project } from '@dxos/schema';
14
+ import { DataType } from '@dxos/schema';
15
15
  import { withTheme, withLayout } from '@dxos/storybook-utils';
16
16
 
17
17
  import { ContactCard, OrganizationCard, ProjectCard } from './components';
@@ -40,7 +40,7 @@ const meta: Meta<StoryProps> = {
40
40
  </Popover.Root>
41
41
  );
42
42
  },
43
- decorators: [withTheme, withLayout({ tooltips: true })],
43
+ decorators: [withTheme, withLayout()],
44
44
  parameters: {
45
45
  layout: 'centered',
46
46
  translations,
@@ -52,7 +52,7 @@ export default meta;
52
52
  const omitImage = ({ image, ...rest }: any) => rest;
53
53
 
54
54
  const data = (() => {
55
- const organization = create(Organization, {
55
+ const organization = create(DataType.Organization, {
56
56
  name: faker.company.name(),
57
57
  image:
58
58
  'https://plus.unsplash.com/premium_photo-1672116452571-896980a801c8?q=80&w=2671&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
@@ -60,7 +60,7 @@ const data = (() => {
60
60
  description: faker.lorem.paragraph(),
61
61
  });
62
62
 
63
- const contact = create(Contact, {
63
+ const contact = create(DataType.Person, {
64
64
  fullName: faker.person.fullName(),
65
65
  image:
66
66
  'https://plus.unsplash.com/premium_photo-1664536392779-049ba8fde933?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
@@ -81,7 +81,7 @@ const data = (() => {
81
81
  ],
82
82
  });
83
83
 
84
- const project = create(Project, {
84
+ const project = create(DataType.Project, {
85
85
  name: faker.person.fullName(),
86
86
  image: 'https://dxos.network/dxos-logotype-blue.png',
87
87
  description: faker.lorem.paragraph(),
@@ -95,6 +95,7 @@ export const ContactWithImage = {
95
95
  Component: ContactCard,
96
96
  icon: 'ph--user--regular',
97
97
  subject: data.contact,
98
+ role: 'popover',
98
99
  },
99
100
  };
100
101
 
@@ -103,6 +104,7 @@ export const ContactNoImage = {
103
104
  Component: ContactCard,
104
105
  icon: 'ph--user--regular',
105
106
  subject: omitImage(data.contact),
107
+ role: 'popover',
106
108
  },
107
109
  };
108
110
 
@@ -111,6 +113,7 @@ export const OrganizationWithImage = {
111
113
  Component: OrganizationCard,
112
114
  icon: 'ph--building-office--regular',
113
115
  subject: data.organization,
116
+ role: 'popover',
114
117
  },
115
118
  };
116
119
 
@@ -119,6 +122,7 @@ export const OrganizationNoImage = {
119
122
  Component: OrganizationCard,
120
123
  icon: 'ph--building-office--regular',
121
124
  subject: omitImage(data.organization),
125
+ role: 'popover',
122
126
  },
123
127
  };
124
128
 
@@ -127,6 +131,7 @@ export const ProjectWithImage = {
127
131
  Component: ProjectCard,
128
132
  icon: 'ph--building--regular',
129
133
  subject: data.project,
134
+ role: 'popover',
130
135
  },
131
136
  };
132
137
 
@@ -135,5 +140,6 @@ export const ProjectNoImage = {
135
140
  Component: ProjectCard,
136
141
  icon: 'ph--building--regular',
137
142
  subject: omitImage(data.project),
143
+ role: 'popover',
138
144
  },
139
145
  };
@@ -25,7 +25,7 @@ import {
25
25
  getSpace,
26
26
  isEchoObject,
27
27
  parseId,
28
- type ReactiveEchoObject,
28
+ type AnyLiveObject,
29
29
  type Space,
30
30
  } from '@dxos/client/echo';
31
31
  import { isInstanceOf } from '@dxos/echo-schema';
@@ -38,7 +38,7 @@ import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/react-ui-edit
38
38
  import { Form } from '@dxos/react-ui-form';
39
39
  import { TableType } from '@dxos/react-ui-table';
40
40
  import { descriptionMessage } from '@dxos/react-ui-theme';
41
- import { Contact, Organization, Project } from '@dxos/schema';
41
+ import { DataType } from '@dxos/schema';
42
42
 
43
43
  import { ContactCard, OrganizationCard, ProjectCard } from './components';
44
44
  import { meta, PREVIEW_PLUGIN } from './meta';
@@ -71,7 +71,7 @@ export const PreviewPlugin = () =>
71
71
  defineModule({
72
72
  id: `${meta.id}/module/schema`,
73
73
  activatesOn: ClientEvents.SetupSchema,
74
- activate: () => [contributes(ClientCapabilities.Schema, [Contact, Organization])],
74
+ activate: () => [contributes(ClientCapabilities.Schema, [DataType.Person, DataType.Organization])],
75
75
  }),
76
76
  defineModule({
77
77
  id: `${meta.id}/module/preview-popover`,
@@ -79,9 +79,9 @@ export const PreviewPlugin = () =>
79
79
  activate: (context) => {
80
80
  // TODO(wittjosiah): Factor out lookup handlers to other plugins to make not ECHO-specific.
81
81
  const handleDxRefTagActivate = async ({ ref, label, trigger }: DxRefTagActivate) => {
82
- const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
83
- const client = context.requestCapability(ClientCapabilities.Client);
84
- const [layout] = context.requestCapabilities(Capabilities.Layout);
82
+ const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
83
+ const client = context.getCapability(ClientCapabilities.Client);
84
+ const [layout] = context.getCapabilities(Capabilities.Layout);
85
85
  const { spaceId } = parseId(layout.workspace);
86
86
  const space = (spaceId && client.spaces.get(spaceId)) ?? client.spaces.default;
87
87
  const result = await handlePreviewLookup(client, space, { ref, label });
@@ -128,15 +128,15 @@ export const PreviewPlugin = () =>
128
128
  createSurface({
129
129
  id: `${PREVIEW_PLUGIN}/schema-popover`,
130
130
  role: ['popover', 'card--kanban'],
131
- filter: (data): data is { subject: Contact } => isInstanceOf(Contact, data.subject),
131
+ filter: (data): data is { subject: DataType.Person } => isInstanceOf(DataType.Person, data.subject),
132
132
  component: ({ data, role }) => {
133
133
  const { dispatchPromise: dispatch } = useIntentDispatcher();
134
134
  const handleOrgClick = useCallback(
135
- async (org: Organization) => {
135
+ async (org: DataType.Organization) => {
136
136
  const space = getSpace(org);
137
- const tablesQuery = await space?.db.query(Filter.schema(TableType)).run();
137
+ const tablesQuery = await space?.db.query(Filter.type(TableType)).run();
138
138
  const currentSpaceOrgTable = tablesQuery?.objects.find((table) => {
139
- return table.view?.target?.query?.typename === Organization.typename;
139
+ return table.view?.target?.query?.typename === DataType.Organization.typename;
140
140
  });
141
141
  await dispatch(
142
142
  createIntent(LayoutAction.UpdatePopover, {
@@ -169,7 +169,8 @@ export const PreviewPlugin = () =>
169
169
  createSurface({
170
170
  id: `${PREVIEW_PLUGIN}/schema-popover`,
171
171
  role: ['popover', 'card--kanban'],
172
- filter: (data): data is { subject: Organization } => isInstanceOf(Organization, data.subject),
172
+ filter: (data): data is { subject: DataType.Organization } =>
173
+ isInstanceOf(DataType.Organization, data.subject),
173
174
  component: ({ data, role }) => (
174
175
  <OrganizationCard subject={data.subject} role={role}>
175
176
  {role === 'popover' && <Surface role='related' data={data} />}
@@ -179,7 +180,7 @@ export const PreviewPlugin = () =>
179
180
  createSurface({
180
181
  id: `${PREVIEW_PLUGIN}/schema-popover`,
181
182
  role: ['popover', 'card--kanban'],
182
- filter: (data): data is { subject: Project } => isInstanceOf(Project, data.subject),
183
+ filter: (data): data is { subject: DataType.Project } => isInstanceOf(DataType.Project, data.subject),
183
184
  component: ({ data, role }) => <ProjectCard subject={data.subject} role={role} />,
184
185
  }),
185
186
 
@@ -190,7 +191,7 @@ export const PreviewPlugin = () =>
190
191
  id: `${PREVIEW_PLUGIN}/fallback-popover`,
191
192
  role: ['popover', 'card--kanban'],
192
193
  position: 'fallback',
193
- filter: (data): data is { subject: ReactiveEchoObject<any> } => isEchoObject(data.subject),
194
+ filter: (data): data is { subject: AnyLiveObject<any> } => isEchoObject(data.subject),
194
195
  component: ({ data, role }) => {
195
196
  const schema = getSchema(data.subject);
196
197
  const { t } = useTranslation(PREVIEW_PLUGIN);
@@ -202,7 +203,7 @@ export const PreviewPlugin = () =>
202
203
  <Form
203
204
  schema={schema}
204
205
  values={data.subject}
205
- readonly
206
+ readonly={role === 'popover'}
206
207
  {...(role === 'card--kanban' && { classNames: kanbanCardWithoutPoster })}
207
208
  />
208
209
  );
@@ -6,7 +6,7 @@ import React, { Fragment } from 'react';
6
6
 
7
7
  import { Icon, Avatar, Button } from '@dxos/react-ui';
8
8
  import { mx } from '@dxos/react-ui-theme';
9
- import { type Contact, type Organization } from '@dxos/schema';
9
+ import { type DataType } from '@dxos/schema';
10
10
 
11
11
  import { type PreviewProps, popoverCard, previewTitle, previewProse, previewChrome, defaultCard } from '../types';
12
12
 
@@ -16,7 +16,7 @@ export const ContactCard = ({
16
16
  role,
17
17
  subject: { fullName, image, organization, emails },
18
18
  onOrgClick,
19
- }: PreviewProps<Contact> & { onOrgClick?: (org: Organization) => void }) => {
19
+ }: PreviewProps<DataType.Person> & { onOrgClick?: (org: DataType.Organization) => void }) => {
20
20
  const organizationName = organization && typeof organization === 'object' ? organization.target?.name : organization;
21
21
  return (
22
22
  <div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
@@ -6,7 +6,7 @@ import React from 'react';
6
6
 
7
7
  import { Icon } from '@dxos/react-ui';
8
8
  import { mx } from '@dxos/react-ui-theme';
9
- import { type Organization } from '@dxos/schema';
9
+ import { type DataType } from '@dxos/schema';
10
10
 
11
11
  import { type PreviewProps, popoverCard, previewTitle, previewProse, previewChrome, defaultCard } from '../types';
12
12
 
@@ -15,7 +15,7 @@ export const OrganizationCard = ({
15
15
  classNames,
16
16
  subject: { name, image, description, website },
17
17
  role,
18
- }: PreviewProps<Organization>) => {
18
+ }: PreviewProps<DataType.Organization>) => {
19
19
  return (
20
20
  <div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
21
21
  {image ? (
@@ -5,11 +5,15 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { mx } from '@dxos/react-ui-theme';
8
- import { type Project } from '@dxos/schema';
8
+ import { type DataType } from '@dxos/schema';
9
9
 
10
10
  import { type PreviewProps, popoverCard, previewTitle, defaultCard } from '../types';
11
11
 
12
- export const ProjectCard = ({ classNames, role, subject: { name, image, description } }: PreviewProps<Project>) => {
12
+ export const ProjectCard = ({
13
+ classNames,
14
+ role,
15
+ subject: { name, image, description },
16
+ }: PreviewProps<DataType.Project>) => {
13
17
  return (
14
18
  <div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
15
19
  {image && <img className='is-full bs-auto' src={image} alt={name} />}