@hubspot/ui-extensions 0.12.3 → 0.12.4

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 (64) hide show
  1. package/dist/__tests__/crm/utils/fetchAssociations.spec.js +2 -1
  2. package/dist/crm/hooks/useAssociations.d.ts +2 -10
  3. package/dist/crm/hooks/useAssociations.js +2 -1
  4. package/dist/crm/utils/fetchAssociations.d.ts +0 -8
  5. package/dist/crm/utils/fetchAssociations.js +0 -10
  6. package/dist/experimental/pages/components/index.d.ts +1 -0
  7. package/dist/experimental/pages/components/index.js +1 -0
  8. package/dist/experimental/pages/components/page-routes.d.ts +83 -0
  9. package/dist/experimental/pages/components/page-routes.js +66 -0
  10. package/dist/experimental/pages/create-page-router.d.ts +35 -0
  11. package/dist/experimental/pages/create-page-router.js +123 -0
  12. package/dist/experimental/pages/create-page-router.test.d.ts +1 -0
  13. package/dist/experimental/pages/create-page-router.test.js +296 -0
  14. package/dist/experimental/pages/hooks.d.ts +8 -0
  15. package/dist/experimental/pages/hooks.js +15 -0
  16. package/dist/experimental/pages/index.d.ts +5 -3
  17. package/dist/experimental/pages/index.js +4 -3
  18. package/dist/experimental/pages/internal/app-page-route-context.d.ts +16 -0
  19. package/dist/experimental/pages/internal/app-page-route-context.js +12 -0
  20. package/dist/experimental/pages/internal/convert-page-routes-react-elements.d.ts +9 -0
  21. package/dist/experimental/pages/internal/convert-page-routes-react-elements.js +138 -0
  22. package/dist/experimental/pages/internal/page-router-internal-types.d.ts +40 -0
  23. package/dist/experimental/pages/internal/page-router-internal-types.js +5 -0
  24. package/dist/experimental/pages/internal/trie-router.d.ts +31 -0
  25. package/dist/experimental/pages/internal/trie-router.js +141 -0
  26. package/dist/experimental/pages/internal/trie-router.test.d.ts +1 -0
  27. package/dist/experimental/pages/internal/trie-router.test.js +263 -0
  28. package/dist/experimental/pages/internal/useAppPageLocation.d.ts +1 -0
  29. package/dist/experimental/pages/internal/useAppPageLocation.js +13 -0
  30. package/dist/experimental/pages/types.d.ts +29 -0
  31. package/dist/experimental/pages/types.js +1 -0
  32. package/dist/internal/hook-utils.d.ts +7 -6
  33. package/dist/internal/hook-utils.js +8 -9
  34. package/dist/pages/index.d.ts +1 -0
  35. package/dist/pages/index.js +1 -0
  36. package/dist/shared/remoteComponents.d.ts +24 -0
  37. package/dist/shared/remoteComponents.js +28 -0
  38. package/dist/shared/types/components/button.d.ts +2 -2
  39. package/dist/shared/types/components/image.d.ts +2 -2
  40. package/dist/shared/types/components/inputs.d.ts +7 -1
  41. package/dist/shared/types/components/link.d.ts +2 -2
  42. package/dist/shared/types/pages/components/index.d.ts +3 -1
  43. package/dist/shared/types/pages/components/page-breadcrumbs.d.ts +34 -0
  44. package/dist/shared/types/pages/components/page-breadcrumbs.js +1 -0
  45. package/dist/shared/types/pages/components/page-header.d.ts +82 -0
  46. package/dist/shared/types/pages/components/page-header.js +1 -0
  47. package/dist/shared/types/pages/components/page-link.d.ts +4 -2
  48. package/dist/shared/types/pages/components/page-title.d.ts +12 -0
  49. package/dist/shared/types/pages/components/page-title.js +1 -0
  50. package/dist/shared/types/pages/index.d.ts +1 -0
  51. package/dist/shared/types/pages/index.js +1 -0
  52. package/dist/shared/types/pages.d.ts +1 -0
  53. package/dist/shared/types/pages.js +1 -0
  54. package/dist/shared/types/worker-globals.d.ts +3 -12
  55. package/dist/testing/internal/mocks/index.d.ts +14 -6
  56. package/dist/testing/internal/mocks/index.js +19 -5
  57. package/dist/testing/internal/mocks/mock-app-page-location.d.ts +7 -0
  58. package/dist/testing/internal/mocks/mock-app-page-location.js +35 -0
  59. package/dist/testing/internal/mocks/mock-hooks.js +12 -7
  60. package/dist/testing/render.js +7 -6
  61. package/dist/testing/types.d.ts +19 -3
  62. package/dist/utils/pagination.d.ts +17 -0
  63. package/dist/utils/pagination.js +10 -0
  64. package/package.json +1 -1
@@ -155,6 +155,12 @@ export interface NumberInputProps extends BaseInputForNumber {
155
155
  formatStyle?: 'decimal' | 'percentage';
156
156
  /** @deprecated use onChange instead. It doesn't guarantee valid format */
157
157
  onInput?: (value: number) => void;
158
+ /**
159
+ * Sets the horizontal alignment of the text in the input.
160
+ *
161
+ * @defaultValue `"left"`
162
+ */
163
+ textAlign?: 'left' | 'right';
158
164
  }
159
165
  /**
160
166
  * The props type for [CurrencyInput](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/standard-components/currency-input).
@@ -185,7 +191,7 @@ export interface CurrencyInputProps extends BaseInputForNumber {
185
191
  *
186
192
  * @category Component Props
187
193
  */
188
- export interface StepperInputProps extends Omit<NumberInputProps, 'onInput'> {
194
+ export interface StepperInputProps extends Omit<NumberInputProps, 'onInput' | 'textAlign'> {
189
195
  /** The amount that the current value will increase or decrease by. Default is `1`.
190
196
  * @defaultValue `1`
191
197
  */
@@ -13,9 +13,9 @@ export interface LinkProps extends OverlayComponentProps, BaseComponentProps {
13
13
  */
14
14
  children: ReactNode;
15
15
  /**
16
- * Sets the link's URL and open behavior. Contains the following fields:
16
+ * Sets the link's URL and open behavior. Can be set to a URL string or an object with the following fields:
17
17
  * - `url` (string): the URL that will open on click.
18
- * - `external` (boolean): set to `true` to open the URL in a new tab and display an external link icon. By default:
18
+ * - `external` (boolean, optional): set to `true` to open the URL in a new tab and display an external link icon. By default:
19
19
  * - Links to HubSpot app pages will open in the same tab and will not include an icon.
20
20
  * - Links to non-HubSpot app pages will open in a new tab and include the icon.
21
21
  */
@@ -1,2 +1,4 @@
1
+ export type * from './page-breadcrumbs.ts';
2
+ export type * from './page-header.ts';
1
3
  export type * from './page-link.ts';
2
- export type * from './page-routes.ts';
4
+ export type * from './page-title.ts';
@@ -0,0 +1,34 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { BaseComponentProps } from '../../shared.ts';
3
+ /**
4
+ * The props type for [PageBreadcrumbs](https://developers.hubspot.com/docs/reference/ui-components/app-page-components/page-breadcrumbs)
5
+ */
6
+ export interface PageBreadcrumbsProps extends BaseComponentProps {
7
+ /**
8
+ * The links and text to render as breadcrumbs.
9
+ * Use `PageBreadcrumbs.PageLink` for navigable crumbs and `PageBreadcrumbs.Current` for the current page.
10
+ */
11
+ children: ReactNode;
12
+ }
13
+ export interface PageBreadcrumbsPageLinkProps extends BaseComponentProps {
14
+ /**
15
+ * The path to navigate to when the link is clicked. Supports path parameters (e.g. `/view-contact/:contactId`).
16
+ */
17
+ to: string;
18
+ /**
19
+ * Values for path parameters and query string entries.
20
+ * Parameters matching `:paramName` tokens in `to` are substituted into the path.
21
+ * Any remaining parameters are appended as query string entries.
22
+ */
23
+ params?: Record<string, string>;
24
+ /**
25
+ * The visible text of the breadcrumb link.
26
+ */
27
+ children: ReactNode;
28
+ }
29
+ export interface PageBreadcrumbsCurrentProps extends BaseComponentProps {
30
+ /**
31
+ * Label for the current location.
32
+ */
33
+ children: ReactNode;
34
+ }
@@ -0,0 +1,82 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import type { ReactionsHandler } from '../../reactions.ts';
3
+ import type { BaseComponentProps, ExtensionEvent } from '../../shared.ts';
4
+ /**
5
+ * The props type for [PageHeader](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header).
6
+ *
7
+ * @category Component Props
8
+ */
9
+ export interface PageHeaderProps extends BaseComponentProps {
10
+ /**
11
+ * Sets the content that will render inside the component. Can contain only <code>PageHeader.PrimaryAction</code> and/or <code>PageHeader.SecondaryActions</code> components.
12
+ */
13
+ children: ReactElement<PageHeaderPrimaryActionProps> | ReactElement<PageHeaderSecondaryActionsProps>;
14
+ }
15
+ /**
16
+ * The props type for [PageHeader.PrimaryAction](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-primaryaction).
17
+ *
18
+ * @category Component Props
19
+ */
20
+ export interface PageHeaderPrimaryActionProps extends BaseComponentProps {
21
+ /**
22
+ * Must be a <code>PageHeader.PageLink</code> component (for internal app pages) or a <code>PageHeader.Link</code> component (for URLs outside your app). No other component types are supported.
23
+ */
24
+ children: ReactNode;
25
+ }
26
+ /**
27
+ * The props type for [PageHeader.SecondaryActions](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-secondaryactions).
28
+ *
29
+ * @category Component Props
30
+ */
31
+ export interface PageHeaderSecondaryActionsProps extends BaseComponentProps {
32
+ /**
33
+ * Must contain one or more <code>PageHeader.PageLink</code> component (for internal app pages) or a <code>PageHeader.Link</code> component (for URLs outside your app). No other component types are supported.
34
+ */
35
+ children: ReactNode;
36
+ }
37
+ /**
38
+ * The props type for [PageHeader.Link](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-link).
39
+ *
40
+ * @category Component Props
41
+ */
42
+ export interface PageHeaderLinkProps extends BaseComponentProps {
43
+ /**
44
+ * A URL that will be opened when the button is clicked. If the value is a URL external to `hubspot.com` it will be opened in a new tab.
45
+ */
46
+ href?: string;
47
+ /**
48
+ * A function that will be invoked when the button is clicked. Do not use this function for submitting a form; use Form's `onSubmit` function instead.
49
+ *
50
+ * @event
51
+ */
52
+ onClick?: ReactionsHandler<ExtensionEvent>;
53
+ /**
54
+ * Determines whether or not the button should be disabled.
55
+ */
56
+ disabled?: boolean;
57
+ /**
58
+ * The visible label of the link button. This prop is passed implicitly by providing sub-components.
59
+ */
60
+ children: ReactNode;
61
+ }
62
+ /**
63
+ * The props type for [PageHeader.PageLink](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-pagelink).
64
+ *
65
+ * @category Component Props
66
+ */
67
+ export interface PageHeaderPageLinkProps extends BaseComponentProps {
68
+ /**
69
+ * The path to navigate to when the link is clicked. Supports path parameters (e.g. `/view-contact/:contactId`).
70
+ */
71
+ to: string;
72
+ /**
73
+ * Values for path parameters and query string entries.
74
+ * Parameters matching `:paramName` tokens in `to` are substituted into the path.
75
+ * Any remaining parameters are appended as query string entries.
76
+ */
77
+ params?: Record<string, string>;
78
+ /**
79
+ * The visible label of the link button. This prop is passed implicitly by providing sub-components.
80
+ */
81
+ children: ReactNode;
82
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -7,7 +7,9 @@ import type { BaseComponentProps } from '../../shared.ts';
7
7
  */
8
8
  export interface PageLinkProps extends BaseComponentProps {
9
9
  /**
10
- * The path to navigate to when the link is clicked. Supports path parameters (e.g. `/view-contact/:contactId`).
10
+ * The path to navigate to. Can be a simple path (e.g., <code>"/docs"</code>) or a path with parameters
11
+ * (e.g., <code>"/view-contact/:contactId"</code>). When using path parameters, provide the parameter
12
+ * values in the <code>params</code> prop.
11
13
  */
12
14
  to: string;
13
15
  /**
@@ -17,7 +19,7 @@ export interface PageLinkProps extends BaseComponentProps {
17
19
  */
18
20
  params?: Record<string, string>;
19
21
  /**
20
- * The content to render inside the link.
22
+ * The content to display inside the link.
21
23
  */
22
24
  children: ReactNode;
23
25
  }
@@ -0,0 +1,12 @@
1
+ import type { BaseComponentProps } from '../../shared.ts';
2
+ /**
3
+ * The props type for [PageTitle](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-title).
4
+ *
5
+ * @category Component Props
6
+ */
7
+ export interface PageTitleProps extends BaseComponentProps {
8
+ /**
9
+ * The text to display as the page heading. Also sets the browser tab title.
10
+ */
11
+ children: string;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type * from './components/index.ts';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type * from './pages/index.ts';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
1
  import type { HubspotExtendFunction } from './extend.ts';
2
2
  import type { ExtensionPointApiActions, ExtensionPointApiContext, ExtensionPointFullApi, ExtensionPoints } from './extension-points.ts';
3
3
  import type { Logger } from './logger.ts';
4
- import type { CreatePageRouterFunction, UsePageRouteHook } from './pages/app-pages-types.ts';
5
- import type { PageRoutesComponent } from './pages/components/page-routes.ts';
4
+ import type { AppPageLocation } from './shared.ts';
6
5
  export interface WorkersApi {
7
6
  /**
8
7
  * Hook added to worker globals so customer code can access extension context at runtime.
@@ -17,17 +16,9 @@ export interface WorkersApi {
17
16
  */
18
17
  useExtensionApi: <ExtensionPoint extends keyof ExtensionPoints>() => ExtensionPointFullApi<ExtensionPoint>;
19
18
  /**
20
- * The PageRoutes component.
19
+ * Hook added to worker globals so page router can access the current app page location at runtime.
21
20
  */
22
- PageRoutes: PageRoutesComponent;
23
- /**
24
- * Hook added to worker globals so customer code can access the current page route at runtime.
25
- */
26
- usePageRoute: UsePageRouteHook;
27
- /**
28
- * Function added to worker globals so customer code can create a page router at runtime.
29
- */
30
- createPageRouter: CreatePageRouterFunction;
21
+ useAppPageLocation: () => AppPageLocation;
31
22
  }
32
23
  export interface WorkerGlobalsInternal {
33
24
  /**
@@ -1,12 +1,20 @@
1
+ import { type useAppPageLocation } from '../../../experimental/pages/internal/useAppPageLocation.tsx';
1
2
  import type { ExtensionPointLocation } from '../../../shared/types/extension-points.ts';
2
- import type { RendererSpies } from '../../types.ts';
3
- import type { RendererMocksInternal } from '../types-internal.ts';
3
+ import type { RendererMocks } from '../../types.ts';
4
+ import { type MocksAppPageLocationStore } from './mock-app-page-location.tsx';
4
5
  /**
5
6
  * An object containing the mocks and spies.
6
7
  */
7
- export interface MocksWithSpies<TExtensionPointLocation extends ExtensionPointLocation> {
8
- mocks: RendererMocksInternal<TExtensionPointLocation>;
9
- spies: RendererSpies<TExtensionPointLocation>;
8
+ export interface RendererMocksContext {
9
+ /**
10
+ * The mocks object provided by the testing utilities.
11
+ */
12
+ mocks: RendererMocks<ExtensionPointLocation>;
13
+ /**
14
+ * The app page location store.
15
+ */
16
+ appPageLocationStore: MocksAppPageLocationStore;
17
+ useAppPageLocation: typeof useAppPageLocation;
10
18
  }
11
19
  /**
12
20
  * Creates a set of mocks and spies for the various functions such as the `useCrmProperties` and `useAssociations`
@@ -14,4 +22,4 @@ export interface MocksWithSpies<TExtensionPointLocation extends ExtensionPointLo
14
22
  *
15
23
  * @returns An object containing the mocks and spies.
16
24
  */
17
- export declare const createMocksWithSpies: <TExtensionPointLocation extends ExtensionPointLocation>(extensionPointLocation: TExtensionPointLocation) => MocksWithSpies<TExtensionPointLocation>;
25
+ export declare const createRendererMocksContext: <TExtensionPointLocation extends ExtensionPointLocation>(extensionPointLocation: TExtensionPointLocation) => RendererMocksContext;
@@ -1,4 +1,6 @@
1
+ import { act as reactAct, useSyncExternalStore } from 'react';
1
2
  import { spyOn } from 'tinyspy';
3
+ import { createMocksAppPageLocationStore, } from "./mock-app-page-location.js";
2
4
  import { createMockExtensionPointApi } from "./mock-extension-point-api.js";
3
5
  import { createMockHooks } from "./mock-hooks.js";
4
6
  /**
@@ -29,7 +31,7 @@ const spyOnAllFunctionsRecursive = (object) => {
29
31
  *
30
32
  * @returns An object containing the mocks and spies.
31
33
  */
32
- export const createMocksWithSpies = (extensionPointLocation) => {
34
+ export const createRendererMocksContext = (extensionPointLocation) => {
33
35
  const mockExtensionPointApi = createMockExtensionPointApi(extensionPointLocation);
34
36
  // Build a mocks object with the default mock functions.
35
37
  // NOTE: The mock implementations can be overridden by tests using the spies that are provided in the returned `spies` object.
@@ -37,10 +39,22 @@ export const createMocksWithSpies = (extensionPointLocation) => {
37
39
  ...createMockHooks(),
38
40
  ...mockExtensionPointApi,
39
41
  };
40
- // Spy on each of the mocks and build the object with all of the spies.
41
- const spies = spyOnAllFunctionsRecursive(mocks);
42
+ // Recursively create spies for all functions in the mocks object.
43
+ const mocksWithSpies = spyOnAllFunctionsRecursive(mocks);
44
+ const appPageLocationStore = createMocksAppPageLocationStore();
42
45
  return {
43
- mocks,
44
- spies: spies,
46
+ mocks: {
47
+ // NOTE: These mocks are exposed as part of our public API.
48
+ ...mocksWithSpies,
49
+ setPageLocation: (location) => {
50
+ reactAct(() => {
51
+ appPageLocationStore.setPageLocation(location);
52
+ });
53
+ },
54
+ },
55
+ appPageLocationStore,
56
+ useAppPageLocation: () => {
57
+ return useSyncExternalStore(appPageLocationStore.subscribe, appPageLocationStore.getSnapshot);
58
+ },
45
59
  };
46
60
  };
@@ -0,0 +1,7 @@
1
+ import type { AppPageLocation } from '../../../shared/types/shared.ts';
2
+ export interface MocksAppPageLocationStore {
3
+ getSnapshot: () => AppPageLocation;
4
+ setPageLocation: (location: AppPageLocation) => void;
5
+ subscribe: (listener: () => void) => () => void;
6
+ }
7
+ export declare const createMocksAppPageLocationStore: (initialLocation?: AppPageLocation) => MocksAppPageLocationStore;
@@ -0,0 +1,35 @@
1
+ const DEFAULT_PAGE_LOCATION = { path: '/', params: {} };
2
+ const areParamsEqual = (a, b) => {
3
+ const keysA = Object.keys(a);
4
+ const keysB = Object.keys(b);
5
+ if (keysA.length !== keysB.length)
6
+ return false;
7
+ for (const key of keysA) {
8
+ if (a[key] !== b[key])
9
+ return false;
10
+ }
11
+ return true;
12
+ };
13
+ const areAppPageLocationsEqual = (a, b) => a.path === b.path && areParamsEqual(a.params, b.params);
14
+ export const createMocksAppPageLocationStore = (initialLocation = DEFAULT_PAGE_LOCATION) => {
15
+ let currentLocation = initialLocation;
16
+ let listeners = [];
17
+ return {
18
+ getSnapshot: () => currentLocation,
19
+ setPageLocation: (location) => {
20
+ if (areAppPageLocationsEqual(location, currentLocation)) {
21
+ return;
22
+ }
23
+ currentLocation = location;
24
+ for (const listener of listeners) {
25
+ listener();
26
+ }
27
+ },
28
+ subscribe: (listener) => {
29
+ listeners = [...listeners, listener];
30
+ return () => {
31
+ listeners = listeners.filter((l) => l !== listener);
32
+ };
33
+ },
34
+ };
35
+ };
@@ -15,6 +15,13 @@ const createFakeProperties = (propertyNames) => {
15
15
  }, {});
16
16
  };
17
17
  export const createMockHooks = () => {
18
+ const useRequiredMocksContext = () => {
19
+ const mocksContext = useMocksContext();
20
+ if (!mocksContext) {
21
+ throw new Error('Illegal State: Mocks context not found.');
22
+ }
23
+ return mocksContext;
24
+ };
18
25
  // Build a mocks object with the default mock functions.
19
26
  // NOTE: The mock implementations can be overridden by tests using the spies that are provided in the returned `spies` object.
20
27
  return {
@@ -61,20 +68,18 @@ export const createMockHooks = () => {
61
68
  };
62
69
  },
63
70
  useExtensionContext: () => {
64
- const mocks = useMocksContext();
71
+ const { mocks } = useRequiredMocksContext();
65
72
  return mocks.context;
66
73
  },
67
74
  useExtensionActions: () => {
68
- const mocks = useMocksContext();
69
- return mocks
70
- .actions;
75
+ const { mocks } = useRequiredMocksContext();
76
+ return mocks.actions;
71
77
  },
72
78
  useExtensionApi: () => {
73
- const mocks = useMocksContext();
79
+ const { mocks } = useRequiredMocksContext();
74
80
  return {
75
81
  context: mocks.context,
76
- actions: mocks
77
- .actions,
82
+ actions: mocks.actions,
78
83
  runServerlessFunction: mocks.runServerlessFunction,
79
84
  };
80
85
  },
@@ -6,7 +6,7 @@ import { EXTENSION_POINT_LOCATIONS } from "../shared/types/extension-points.js";
6
6
  import { convertRemoteRoot } from "./internal/convert.js";
7
7
  import { createDocument } from "./internal/document.js";
8
8
  import { InvalidComponentsError, InvalidExtensionPointLocationError, WaitForTimeoutError, } from "./internal/errors.js";
9
- import { createMocksWithSpies } from "./internal/mocks/index.js";
9
+ import { createRendererMocksContext, } from "./internal/mocks/index.js";
10
10
  import { find, findAll, findAllChildren, findByTestId, findChild, maybeFind, maybeFindByTestId, maybeFindChild, } from "./internal/query.js";
11
11
  import { createRootNode } from "./internal/root.js";
12
12
  import { asRenderedRootNode } from "./internal/type-utils-internal.js";
@@ -21,7 +21,7 @@ const DEFAULT_WAIT_FOR_OPTIONS = {
21
21
  * @param node The React node to render.
22
22
  * @returns A render result object
23
23
  */
24
- const render = (node, mocksWithSpies) => {
24
+ const render = (node, mocksContext) => {
25
25
  let dirty = true;
26
26
  let waitForChecksQueued = false;
27
27
  let waitForList = [];
@@ -74,7 +74,7 @@ const render = (node, mocksWithSpies) => {
74
74
  };
75
75
  const remoteRoot = createRemoteRoot(remoteChannel);
76
76
  const reactRoot = createReactRoot(remoteRoot);
77
- reactRoot.render(_jsx(MocksContextProvider, { value: mocksWithSpies, children: node }));
77
+ reactRoot.render(_jsx(MocksContextProvider, { value: mocksContext, children: node }));
78
78
  remoteRoot.mount();
79
79
  let maybeRenderedRootNode;
80
80
  /**
@@ -174,13 +174,14 @@ export const createRenderer = (extensionPointLocation) => {
174
174
  return renderResult;
175
175
  };
176
176
  const getLatestRootNode = () => getRenderResult().getLatestRootNode();
177
- const { spies: mocksWithSpies } = createMocksWithSpies(extensionPointLocation);
177
+ const mocksContext = createRendererMocksContext(extensionPointLocation);
178
+ const { mocks } = mocksContext;
178
179
  return {
179
180
  render: (node) => {
180
- renderResult = render(node, mocksWithSpies);
181
+ renderResult = render(node, mocksContext);
181
182
  return asRenderedRootNode(renderResult.getLatestRootNode());
182
183
  },
183
- mocks: mocksWithSpies,
184
+ mocks: mocks,
184
185
  find: (component, matcher) => {
185
186
  return find(getLatestRootNode(), component, matcher);
186
187
  },
@@ -1,11 +1,12 @@
1
1
  import type { SpyImpl } from 'tinyspy';
2
2
  import type { useAssociations, useCrmProperties } from '../crm/index.ts';
3
+ import type { useAppPageLocation } from '../experimental/pages/internal/useAppPageLocation.tsx';
3
4
  import type { useExtensionActions } from '../hooks/useExtensionActions.tsx';
4
5
  import type { useExtensionApi } from '../hooks/useExtensionApi.tsx';
5
6
  import type { useExtensionContext } from '../hooks/useExtensionContext.tsx';
6
7
  import type { ExtensionPointApi, ExtensionPointApiActions, ExtensionPointLocation } from '../shared/types/extension-points.ts';
7
8
  import type { ServerlessFuncRunner } from '../shared/types/http-requests.ts';
8
- import type { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../shared/types/shared.ts';
9
+ import type { AppPageLocation, HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../shared/types/shared.ts';
9
10
  import type { AnyFunction } from './internal/types-internal.ts';
10
11
  /**
11
12
  * The type of a rendered node.
@@ -261,7 +262,7 @@ export type ExtensionPointApiActionSpies<TExtensionPointLocation extends Extensi
261
262
  /**
262
263
  * An object containing the spies for the various functions.
263
264
  */
264
- export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLocation = ExtensionPointLocation> {
265
+ export interface RendererMocks<TExtensionPointLocation extends ExtensionPointLocation = ExtensionPointLocation> {
265
266
  /**
266
267
  * A spy for the `useCrmProperties` hook function.
267
268
  * The spy can be used to track the calls to the hook function and also control the
@@ -307,6 +308,15 @@ export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLoc
307
308
  * information about spies and the supported API.
308
309
  */
309
310
  useExtensionApi: FunctionSpy<typeof useExtensionApi>;
311
+ /**
312
+ * A spy for the `useAppPageLocation` hook function.
313
+ * The spy can be used to track the calls to the hook function and also control the
314
+ * return result of the hook function.
315
+ *
316
+ * See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
317
+ * information about spies and the supported API.
318
+ */
319
+ useAppPageLocation: FunctionSpy<typeof useAppPageLocation>;
310
320
  /**
311
321
  * Mock context object that contains fake context data for the extension point API.
312
322
  */
@@ -329,6 +339,12 @@ export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLoc
329
339
  * information about spies and the supported API.
330
340
  */
331
341
  runServerlessFunction: FunctionSpy<ServerlessFuncRunner>;
342
+ /**
343
+ * Sets the current app page location for testing page routing.
344
+ *
345
+ * @param location The app page location to set.
346
+ */
347
+ setPageLocation: (location: AppPageLocation) => void;
332
348
  }
333
349
  /**
334
350
  * A result of a render operation.
@@ -363,7 +379,7 @@ export interface Renderer<TExtensionPointLocation extends ExtensionPointLocation
363
379
  /**
364
380
  * The mocks that can be used to control the behavior of the various functions.
365
381
  */
366
- mocks: RendererSpies<TExtensionPointLocation>;
382
+ mocks: RendererMocks<TExtensionPointLocation>;
367
383
  /**
368
384
  * Finds the first descendant element node that matches the given component and test ID.
369
385
  *
@@ -0,0 +1,17 @@
1
+ export interface PaginationResult {
2
+ hasNextPage: boolean;
3
+ hasPreviousPage: boolean;
4
+ currentPage: number;
5
+ pageSize: number;
6
+ nextPage: () => void;
7
+ previousPage: () => void;
8
+ reset: () => void;
9
+ }
10
+ export declare const DEFAULT_PAGE_SIZE = 10;
11
+ /**
12
+ * Calculate pagination flags based on current page and API hasMore flag
13
+ */
14
+ export declare function calculatePaginationFlags(currentPage: number, hasMore: boolean): {
15
+ hasNextPage: boolean;
16
+ hasPreviousPage: boolean;
17
+ };
@@ -0,0 +1,10 @@
1
+ export const DEFAULT_PAGE_SIZE = 10;
2
+ /**
3
+ * Calculate pagination flags based on current page and API hasMore flag
4
+ */
5
+ export function calculatePaginationFlags(currentPage, hasMore) {
6
+ return {
7
+ hasNextPage: hasMore,
8
+ hasPreviousPage: currentPage > 1,
9
+ };
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions",
3
- "version": "0.12.3",
3
+ "version": "0.12.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",