@hubspot/ui-extensions 0.0.1-prealpha.3 → 0.0.1-prealpha.5

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.
@@ -0,0 +1,17 @@
1
+ /* eslint-disable hubspot-dev/no-confusing-browser-globals */
2
+ import { createRoot } from '@remote-ui/react';
3
+ import { isValidElement } from 'react';
4
+ export const hubspot = {
5
+ extend: render,
6
+ };
7
+ const extend = (...args) => self.extend(...args);
8
+ function render(renderCallback) {
9
+ return extend((root, api) => {
10
+ const renderCallbackResult = renderCallback(api);
11
+ if (!isValidElement(renderCallbackResult)) {
12
+ throw new Error(`[hubspot.extend]: Expected callback function to return a valid element, got: ${renderCallbackResult}`);
13
+ }
14
+ createRoot(root).render(renderCallbackResult);
15
+ root.mount();
16
+ });
17
+ }
@@ -0,0 +1,3 @@
1
+ export { Alert, Button, ButtonRow, Card, DescriptionList, DescriptionListItem, Divider, Form, Heading, Image, Input, LoadingSpinner, ProgressBar, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, Table, TableFooter, TableCell, TableRow, TableBody, TableHeader, TableHead, Tag, Text, Tile, } from './coreComponents';
2
+ export { hubspot } from './hubspot';
3
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Alert, Button, ButtonRow, Card, DescriptionList, DescriptionListItem, Divider, Form, Heading, Image, Input, LoadingSpinner, ProgressBar, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, Table, TableFooter, TableCell, TableRow, TableBody, TableHeader, TableHead, Tag, Text, Tile, } from './coreComponents';
2
+ export { hubspot } from './hubspot';
3
+ export * from './types';
@@ -0,0 +1,263 @@
1
+ import { ReactNode, ComponentType } from 'react';
2
+ export interface AlertProps {
3
+ title: string;
4
+ body?: string;
5
+ children?: ReactNode;
6
+ variant?: 'info' | 'warning' | 'success' | 'error' | 'danger';
7
+ }
8
+ export interface ButtonProps {
9
+ text: string;
10
+ onClick?: () => void;
11
+ href?: string;
12
+ disabled?: boolean;
13
+ variant?: 'primary' | 'secondary' | 'destructive';
14
+ type?: 'button' | 'reset' | 'submit';
15
+ }
16
+ export interface ButtonRowProps {
17
+ children: ReactNode;
18
+ disableDropdown?: boolean;
19
+ }
20
+ export interface CardProps {
21
+ children: ReactNode;
22
+ }
23
+ export interface DescriptionListItemProps {
24
+ children: ReactNode;
25
+ label: string;
26
+ }
27
+ export interface DescriptionListProps {
28
+ children: ReactNode;
29
+ direction?: 'row' | 'column';
30
+ }
31
+ export interface DividerProps {
32
+ distance?: 'flush' | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large';
33
+ }
34
+ export interface FormProps {
35
+ children: ReactNode;
36
+ onSubmit?: () => void;
37
+ preventDefault?: boolean;
38
+ }
39
+ export interface HeadingProps {
40
+ text: string;
41
+ format?: 'plaintext' | 'markdown';
42
+ }
43
+ export interface ImageProps {
44
+ alt?: string;
45
+ href?: string;
46
+ onClick?: () => void;
47
+ src: string;
48
+ width?: number;
49
+ }
50
+ export interface InputProps {
51
+ label: string;
52
+ name: string;
53
+ value?: string;
54
+ required?: boolean;
55
+ readonly?: boolean;
56
+ description?: string;
57
+ tooltip?: string;
58
+ placeholder?: string;
59
+ error?: boolean;
60
+ validationMessage?: string;
61
+ onChange: (value: string) => void;
62
+ onInput: (value: string) => void;
63
+ }
64
+ export interface ProgressBarProps {
65
+ title?: string;
66
+ showPercentage?: boolean;
67
+ value?: number;
68
+ valueMax?: number;
69
+ valueDescription?: string;
70
+ variant?: 'success' | 'danger' | 'warning';
71
+ }
72
+ export interface SelectProps {
73
+ label: string;
74
+ name: string;
75
+ value?: string | number | boolean;
76
+ required?: boolean;
77
+ readonly?: boolean;
78
+ description?: string;
79
+ tooltip?: string;
80
+ placeholder?: string;
81
+ error?: boolean;
82
+ validationMessage?: string;
83
+ onChange?: (value: SelectProps['value']) => void;
84
+ options: {
85
+ label: string;
86
+ value: string | number | boolean;
87
+ }[];
88
+ }
89
+ export interface TagProps {
90
+ text: string;
91
+ onClick?: () => void;
92
+ variant?: 'default' | 'warning' | 'success' | 'error';
93
+ }
94
+ export interface TextProps {
95
+ format?: 'plaintext' | 'markdown';
96
+ text: string;
97
+ variant?: 'bodytext' | 'microcopy';
98
+ }
99
+ export interface TileProps {
100
+ children: ReactNode;
101
+ flush?: boolean;
102
+ }
103
+ interface Team {
104
+ id: number;
105
+ name: string;
106
+ teammates: number[];
107
+ }
108
+ export interface UserContext {
109
+ id: number;
110
+ emails: string[];
111
+ email: string;
112
+ firstName: string;
113
+ lastName: string;
114
+ roles: string[];
115
+ teams: Team[];
116
+ locale?: string;
117
+ }
118
+ export interface PortalContext {
119
+ id: number;
120
+ timezone: string;
121
+ }
122
+ export interface Context {
123
+ user: UserContext;
124
+ portal: PortalContext;
125
+ }
126
+ type distanceOptions = 'flush' | 'small';
127
+ export interface StackProps {
128
+ distance?: distanceOptions;
129
+ children?: React.ReactNode;
130
+ }
131
+ export interface StatisticsTrendProps {
132
+ value: string;
133
+ direction: 'increase' | 'decrease';
134
+ }
135
+ export interface StatisticsItemProps {
136
+ id?: string;
137
+ label: string;
138
+ number: string;
139
+ children: ReactNode;
140
+ }
141
+ export interface StatisticsProps {
142
+ children: ReactNode;
143
+ }
144
+ export interface CrmPropertyListProps {
145
+ properties: string[];
146
+ direction?: string;
147
+ }
148
+ export interface ServerlessRunnerParams {
149
+ name: string;
150
+ payload: Record<string, unknown>;
151
+ onError?: () => void;
152
+ }
153
+ export type ServerlessFuncRunner = (params: ServerlessRunnerParams) => Promise<any>;
154
+ export interface ServerlessSuccessResponse {
155
+ logId: string;
156
+ response: {
157
+ message?: {
158
+ type: 'SUCCESS' | 'ERROR';
159
+ body: string;
160
+ } | string;
161
+ context?: Record<string, unknown>;
162
+ section?: Record<string, unknown>;
163
+ };
164
+ }
165
+ export interface ServerlessErrorResponse {
166
+ responseJSON?: {
167
+ message: string;
168
+ correlationId: string;
169
+ category: string;
170
+ subCategory?: string;
171
+ errors?: {
172
+ message: string;
173
+ subCategory: string;
174
+ }[];
175
+ };
176
+ status: number;
177
+ }
178
+ export interface ExtensionCardContextData {
179
+ cardId: string;
180
+ appId: number | string;
181
+ objectId: number | string;
182
+ objectTypeId: string;
183
+ location: keyof ExtensionPoints;
184
+ }
185
+ export type ExtensionPointAction = (...args: any[]) => Promise<any> | void;
186
+ export interface ExtensionPointContract {
187
+ actions?: {
188
+ [k: string]: ExtensionPointAction;
189
+ } | {};
190
+ customComponents: Record<string, ComponentType<any>>;
191
+ }
192
+ type AlertType = 'info' | 'warning' | 'success' | 'danger' | 'tip' | undefined;
193
+ export type AddAlertAction = (args: {
194
+ type?: AlertType;
195
+ message: string;
196
+ }) => void;
197
+ export type ReloadPageAction = () => void;
198
+ export type FetchCrmObjectPropertiesAction = (properties: string[]) => Promise<{
199
+ name: string;
200
+ value: string;
201
+ }[]>;
202
+ export type OpenIframeModalAction = (action: OpenIframeActionPayload) => void;
203
+ export interface CrmMiddleExtensionPoint extends ExtensionPointContract {
204
+ actions: {
205
+ addAlert: AddAlertAction;
206
+ reloadPage: ReloadPageAction;
207
+ fetchCrmObjectProperties: FetchCrmObjectPropertiesAction;
208
+ openIframeModal: OpenIframeModalAction;
209
+ };
210
+ customComponents: {
211
+ CrmPropertyList?: ComponentType<CrmPropertyListProps>;
212
+ };
213
+ }
214
+ interface CrmSidebarExtensionPoint extends ExtensionPointContract {
215
+ actions: {
216
+ reloadPage: ReloadPageAction;
217
+ };
218
+ }
219
+ interface RemotePlaygroundExtensionPoint extends ExtensionPointContract {
220
+ actions: {
221
+ warn: () => void;
222
+ };
223
+ customComponents: {
224
+ ExampleCrmComponent: ComponentType<ExampleCrmComponentProps>;
225
+ };
226
+ }
227
+ export interface ExtensionPoints {
228
+ 'uie.playground.middle': RemotePlaygroundExtensionPoint;
229
+ 'crm.record.tab': CrmMiddleExtensionPoint;
230
+ 'crm.record.sidebar': CrmSidebarExtensionPoint;
231
+ }
232
+ export interface ExampleCrmComponentProps {
233
+ name: string;
234
+ size: 'sm' | 'md' | 'lg';
235
+ count: number;
236
+ }
237
+ export interface ExtensionPointApi<ExtensionPointName extends keyof ExtensionPoints> {
238
+ context: Context;
239
+ runServerlessFunction: ServerlessFuncRunner;
240
+ actions: ExtensionPoints[ExtensionPointName]['actions'];
241
+ customComponents: string[];
242
+ }
243
+ interface OpenIframeActionPayload {
244
+ uri: string;
245
+ height: number;
246
+ width: number;
247
+ associatedObjectProperties?: string[];
248
+ }
249
+ export interface LoadingSpinnerProps {
250
+ label: string;
251
+ showLabel?: boolean;
252
+ size?: 'xs' | 'sm' | 'md';
253
+ layout?: 'inline' | 'centered';
254
+ grow?: boolean;
255
+ }
256
+ export interface TableElementProps {
257
+ children: React.ReactNode;
258
+ }
259
+ export interface TableProps extends TableElementProps {
260
+ flush?: boolean;
261
+ bordered?: boolean;
262
+ }
263
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { RemoteComponentType } from '@remote-ui/core';
2
+ import type { ReactComponentTypeFromRemoteComponentType } from '@remote-ui/react';
3
+ export declare function createExtensionComponent<ComponentType extends string, Props = Record<string, never>, AllowedChildren extends RemoteComponentType<string, any> | boolean = true>(componentType: ComponentType | RemoteComponentType<ComponentType, Props, AllowedChildren>): RemoteComponentType<ComponentType, Props, AllowedChildren> & ReactComponentTypeFromRemoteComponentType<RemoteComponentType<ComponentType, Props, AllowedChildren>>;
@@ -0,0 +1,4 @@
1
+ import { createRemoteReactComponent } from '@remote-ui/react';
2
+ export function createExtensionComponent(componentType) {
3
+ return createRemoteReactComponent(componentType);
4
+ }
package/package.json CHANGED
@@ -1,17 +1,51 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions",
3
- "version": "0.0.1-prealpha.3",
3
+ "version": "0.0.1-prealpha.5",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "index.ts",
7
- "scripts": {},
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "clean": "rm -rf dist/",
10
+ "prepare": "npm run clean && tsc",
11
+ "watch": "npm run clean && tsc --watch"
12
+ },
13
+ "files": [
14
+ "dist/**/*"
15
+ ],
8
16
  "publishConfig": {
9
17
  "access": "public"
10
18
  },
19
+ "exports": {
20
+ ".": "./dist/index.js",
21
+ "./crm": "./dist/crm/index.js"
22
+ },
11
23
  "license": "MIT",
12
24
  "dependencies": {
13
25
  "@remote-ui/react": "^5.0.0",
14
26
  "react": "^18.2.0"
15
27
  },
16
- "gitHead": "74dbffa7fe6e4ad7d5029897801c11dc5d5edae1"
28
+ "engines": {
29
+ "node": ">=16"
30
+ },
31
+ "peerDependencies": {
32
+ "@remote-ui/react": "^5.0.0",
33
+ "react": "^18.2.0",
34
+ "typescript": "^5.0.4"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "react": {
38
+ "optional": false
39
+ },
40
+ "@remote-ui/react": {
41
+ "optional": false
42
+ },
43
+ "typescript": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "typescript": "5.0.4"
49
+ },
50
+ "gitHead": "a4652eb58cbde813dbebc8b7127c36102b9b6ed6"
17
51
  }
@@ -1,11 +0,0 @@
1
- /* Hello! To create your first component, uncomment the code below and replace
2
- * the entry with your props and component name
3
- * import { createExtensionComponent } from '../utils/createExtensionComponent';
4
- * import type { ExampleCrmComponentProps } from '../types';
5
-
6
- * const ExampleCrmComponent = createExtensionComponent<
7
- * 'ExampleCrmComponent',
8
- * ExampleCrmComponentProps
9
- * >('ExampleCrmComponent');
10
- */
11
- export {};
package/coreComponents.ts DELETED
@@ -1,94 +0,0 @@
1
- import { createRemoteReactComponent } from '@remote-ui/react';
2
-
3
- import type {
4
- AlertProps,
5
- ButtonProps,
6
- ButtonRowProps,
7
- CardProps,
8
- DescriptionListProps,
9
- DescriptionListItemProps,
10
- FormProps,
11
- HeadingProps,
12
- ImageProps,
13
- InputProps,
14
- LoadingSpinnerProps,
15
- ProgressBarProps,
16
- SelectProps,
17
- TagProps,
18
- TextProps,
19
- TileProps,
20
- StackProps,
21
- StatisticsProps,
22
- StatisticsItemProps,
23
- StatisticsTrendProps,
24
- } from './types';
25
-
26
- const Alert = createRemoteReactComponent<'Alert', AlertProps>('Alert');
27
- const Button = createRemoteReactComponent<'Button', ButtonProps>('Button');
28
- const ButtonRow = createRemoteReactComponent<'ButtonRow', ButtonRowProps>(
29
- 'ButtonRow'
30
- );
31
- const Card = createRemoteReactComponent<'Card', CardProps>('Card');
32
- const DescriptionList = createRemoteReactComponent<
33
- 'DescriptionList',
34
- DescriptionListProps
35
- >('DescriptionList');
36
- const DescriptionListItem = createRemoteReactComponent<
37
- 'DescriptionListItem',
38
- DescriptionListItemProps
39
- >('DescriptionListItem');
40
- const Divider = createRemoteReactComponent<'Divider', {}>('Divider');
41
- const Form = createRemoteReactComponent<'Form', FormProps>('Form');
42
- const Heading = createRemoteReactComponent<'Heading', HeadingProps>('Heading');
43
- const Image = createRemoteReactComponent<'Image', ImageProps>('Image');
44
- const Input = createRemoteReactComponent<'Input', InputProps>('Input');
45
- const LoadingSpinner = createRemoteReactComponent<
46
- 'LoadingSpinner',
47
- LoadingSpinnerProps
48
- >('LoadingSpinner');
49
- const ProgressBar = createRemoteReactComponent<'ProgressBar', ProgressBarProps>(
50
- 'ProgressBar'
51
- );
52
- const Select = createRemoteReactComponent<'Select', SelectProps>('Select');
53
- const Tag = createRemoteReactComponent<'Tag', TagProps>('Tag');
54
- const Text = createRemoteReactComponent<'Text', TextProps>('Text');
55
- const Tile = createRemoteReactComponent<'Tile', TileProps>('Tile');
56
- const Stack = createRemoteReactComponent<'Stack', StackProps>('Stack');
57
-
58
- const StatisticsItem = createRemoteReactComponent<
59
- 'StatisticsItem',
60
- StatisticsItemProps
61
- >('StatisticsItem');
62
-
63
- const Statistics = createRemoteReactComponent<'Statistics', StatisticsProps>(
64
- 'Statistics'
65
- );
66
-
67
- const StatisticsTrend = createRemoteReactComponent<
68
- 'StatisticsTrend',
69
- StatisticsTrendProps
70
- >('StatisticsTrend');
71
-
72
- export {
73
- Alert,
74
- Button,
75
- ButtonRow,
76
- Card,
77
- DescriptionList,
78
- DescriptionListItem,
79
- Divider,
80
- Form,
81
- Heading,
82
- Image,
83
- Input,
84
- LoadingSpinner,
85
- ProgressBar,
86
- Select,
87
- Stack,
88
- Statistics,
89
- StatisticsItem,
90
- StatisticsTrend,
91
- Tag,
92
- Text,
93
- Tile,
94
- };
package/hubspot.ts DELETED
@@ -1,32 +0,0 @@
1
- /* eslint-disable hubspot-dev/no-confusing-browser-globals */
2
-
3
- import { createRoot, RemoteRoot } from '@remote-ui/react';
4
- import { ReactElement, isValidElement } from 'react';
5
- import { ExtensionPoints, ExtensionPointApi } from './types';
6
-
7
- export const hubspot = {
8
- extend: render,
9
- };
10
-
11
- const extend = (...args) => (self as any).extend(...args);
12
-
13
- function render<ExtensionPointName extends keyof ExtensionPoints>(
14
- renderCallback: (
15
- api: ExtensionPointApi<ExtensionPointName>
16
- ) => ReactElement<any>
17
- ) {
18
- return extend(
19
- (root: RemoteRoot, api: ExtensionPointApi<ExtensionPointName>) => {
20
- const renderCallbackResult = renderCallback(api);
21
-
22
- if (!isValidElement(renderCallbackResult)) {
23
- throw new Error(
24
- `[hubspot.extend]: Expected callback function to return a valid element, got: ${renderCallbackResult}`
25
- );
26
- }
27
-
28
- createRoot(root).render(renderCallbackResult);
29
- root.mount();
30
- }
31
- );
32
- }
package/index.ts DELETED
@@ -1,25 +0,0 @@
1
- export {
2
- Alert,
3
- Button,
4
- ButtonRow,
5
- Card,
6
- DescriptionList,
7
- DescriptionListItem,
8
- Divider,
9
- Form,
10
- Heading,
11
- Image,
12
- Input,
13
- LoadingSpinner,
14
- ProgressBar,
15
- Select,
16
- Stack,
17
- Statistics,
18
- StatisticsItem,
19
- StatisticsTrend,
20
- Tag,
21
- Text,
22
- Tile,
23
- } from './coreComponents';
24
-
25
- export { hubspot } from './hubspot';