@hubspot/ui-extensions 0.10.1 → 0.11.1

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 (149) hide show
  1. package/dist/{pages/home/components.d.ts → __synced__/appHomeRemoteComponents.synced.d.ts} +7 -7
  2. package/dist/{pages/home/components.js → __synced__/appHomeRemoteComponents.synced.js} +1 -0
  3. package/dist/{crm/components.d.ts → __synced__/crmRemoteComponents.synced.d.ts} +40 -41
  4. package/dist/__synced__/crmRemoteComponents.synced.js +15 -0
  5. package/dist/{experimental/types.d.ts → __synced__/experimental/types.synced.d.ts} +6 -1
  6. package/dist/__synced__/experimentalRemoteComponents.synced.d.ts +94 -0
  7. package/dist/__synced__/experimentalRemoteComponents.synced.js +56 -0
  8. package/dist/__synced__/remoteComponents.synced.d.ts +579 -0
  9. package/dist/{coreComponents.js → __synced__/remoteComponents.synced.js} +89 -69
  10. package/dist/__synced__/types/actions.synced.d.ts +57 -0
  11. package/dist/__synced__/types/actions.synced.js +1 -0
  12. package/dist/__synced__/types/components/accordion.synced.d.ts +48 -0
  13. package/dist/__synced__/types/components/accordion.synced.js +1 -0
  14. package/dist/__synced__/types/components/alert.synced.d.ts +24 -0
  15. package/dist/__synced__/types/components/alert.synced.js +1 -0
  16. package/dist/__synced__/types/components/app-home-header-actions.synced.d.ts +39 -0
  17. package/dist/__synced__/types/components/app-home-header-actions.synced.js +1 -0
  18. package/dist/__synced__/types/components/button-row.synced.d.ts +44 -0
  19. package/dist/__synced__/types/components/button-row.synced.js +1 -0
  20. package/dist/__synced__/types/components/button.synced.d.ts +89 -0
  21. package/dist/__synced__/types/components/button.synced.js +1 -0
  22. package/dist/__synced__/types/components/card.synced.d.ts +12 -0
  23. package/dist/__synced__/types/components/card.synced.js +1 -0
  24. package/dist/__synced__/types/components/chart.synced.d.ts +137 -0
  25. package/dist/__synced__/types/components/chart.synced.js +5 -0
  26. package/dist/__synced__/types/components/description-list.synced.d.ts +36 -0
  27. package/dist/__synced__/types/components/description-list.synced.js +1 -0
  28. package/dist/__synced__/types/components/divider.synced.d.ts +14 -0
  29. package/dist/__synced__/types/components/divider.synced.js +1 -0
  30. package/dist/__synced__/types/components/dropdown.synced.d.ts +84 -0
  31. package/dist/__synced__/types/components/dropdown.synced.js +1 -0
  32. package/dist/__synced__/types/components/empty-state.synced.d.ts +51 -0
  33. package/dist/__synced__/types/components/empty-state.synced.js +1 -0
  34. package/dist/__synced__/types/components/error-state.synced.d.ts +24 -0
  35. package/dist/__synced__/types/components/error-state.synced.js +1 -0
  36. package/dist/__synced__/types/components/form.synced.d.ts +29 -0
  37. package/dist/__synced__/types/components/form.synced.js +1 -0
  38. package/dist/__synced__/types/components/heading.synced.d.ts +19 -0
  39. package/dist/__synced__/types/components/heading.synced.js +1 -0
  40. package/dist/__synced__/types/components/icon.synced.d.ts +29 -0
  41. package/dist/__synced__/types/components/icon.synced.js +1 -0
  42. package/dist/__synced__/types/components/iframe.synced.d.ts +20 -0
  43. package/dist/__synced__/types/components/iframe.synced.js +1 -0
  44. package/dist/__synced__/types/components/illustration.synced.d.ts +53 -0
  45. package/dist/__synced__/types/components/illustration.synced.js +43 -0
  46. package/dist/__synced__/types/components/image.synced.d.ts +40 -0
  47. package/dist/__synced__/types/components/image.synced.js +1 -0
  48. package/dist/__synced__/types/components/index.synced.d.ts +38 -0
  49. package/dist/__synced__/types/components/index.synced.js +1 -0
  50. package/dist/__synced__/types/components/inputs.synced.d.ts +350 -0
  51. package/dist/__synced__/types/components/inputs.synced.js +1 -0
  52. package/dist/__synced__/types/components/layouts.synced.d.ts +172 -0
  53. package/dist/__synced__/types/components/layouts.synced.js +1 -0
  54. package/dist/__synced__/types/components/link.synced.d.ts +38 -0
  55. package/dist/__synced__/types/components/link.synced.js +1 -0
  56. package/dist/__synced__/types/components/list.synced.d.ts +18 -0
  57. package/dist/__synced__/types/components/list.synced.js +1 -0
  58. package/dist/__synced__/types/components/loading-spinner.synced.d.ts +31 -0
  59. package/dist/__synced__/types/components/loading-spinner.synced.js +1 -0
  60. package/dist/__synced__/types/components/modal.synced.d.ts +60 -0
  61. package/dist/__synced__/types/components/modal.synced.js +1 -0
  62. package/dist/__synced__/types/components/panel.synced.d.ts +73 -0
  63. package/dist/__synced__/types/components/panel.synced.js +1 -0
  64. package/dist/__synced__/types/components/progress-bar.synced.d.ts +48 -0
  65. package/dist/__synced__/types/components/progress-bar.synced.js +1 -0
  66. package/dist/__synced__/types/components/selects.synced.d.ts +130 -0
  67. package/dist/__synced__/types/components/selects.synced.js +1 -0
  68. package/dist/__synced__/types/components/statistics.synced.d.ts +56 -0
  69. package/dist/__synced__/types/components/statistics.synced.js +1 -0
  70. package/dist/__synced__/types/components/status-tag.synced.d.ts +42 -0
  71. package/dist/__synced__/types/components/status-tag.synced.js +1 -0
  72. package/dist/__synced__/types/components/step-indicator.synced.d.ts +44 -0
  73. package/dist/__synced__/types/components/step-indicator.synced.js +1 -0
  74. package/dist/__synced__/types/components/table.synced.d.ts +138 -0
  75. package/dist/__synced__/types/components/table.synced.js +1 -0
  76. package/dist/__synced__/types/components/tabs.synced.d.ts +55 -0
  77. package/dist/__synced__/types/components/tabs.synced.js +1 -0
  78. package/dist/__synced__/types/components/tag.synced.d.ts +32 -0
  79. package/dist/__synced__/types/components/tag.synced.js +1 -0
  80. package/dist/__synced__/types/components/text.synced.d.ts +93 -0
  81. package/dist/__synced__/types/components/text.synced.js +1 -0
  82. package/dist/__synced__/types/components/tile.synced.d.ts +24 -0
  83. package/dist/__synced__/types/components/tile.synced.js +1 -0
  84. package/dist/__synced__/types/components/toggle.synced.d.ts +60 -0
  85. package/dist/__synced__/types/components/toggle.synced.js +1 -0
  86. package/dist/__synced__/types/components/toggleInputs.synced.d.ts +191 -0
  87. package/dist/__synced__/types/components/toggleInputs.synced.js +1 -0
  88. package/dist/__synced__/types/components/tooltip.synced.d.ts +12 -0
  89. package/dist/__synced__/types/components/tooltip.synced.js +1 -0
  90. package/dist/__synced__/types/context.synced.d.ts +82 -0
  91. package/dist/__synced__/types/context.synced.js +1 -0
  92. package/dist/__synced__/types/crm.synced.d.ts +248 -0
  93. package/dist/__synced__/types/crm.synced.js +1 -0
  94. package/dist/__synced__/types/extension-points.synced.d.ts +122 -0
  95. package/dist/__synced__/types/extension-points.synced.js +9 -0
  96. package/dist/__synced__/types/http-requests.synced.d.ts +106 -0
  97. package/dist/__synced__/types/http-requests.synced.js +8 -0
  98. package/dist/__synced__/types/index.synced.d.ts +8 -0
  99. package/dist/__synced__/types/index.synced.js +1 -0
  100. package/dist/__synced__/types/reactions.synced.d.ts +12 -0
  101. package/dist/__synced__/types/reactions.synced.js +1 -0
  102. package/dist/__synced__/types/shared.synced.d.ts +196 -0
  103. package/dist/{types.js → __synced__/types/shared.synced.js} +0 -68
  104. package/dist/__synced__/utils/remote-component-registry.synced.d.ts +80 -0
  105. package/dist/__synced__/utils/remote-component-registry.synced.js +64 -0
  106. package/dist/crm/index.d.ts +2 -2
  107. package/dist/crm/index.js +1 -2
  108. package/dist/experimental/index.d.ts +2 -73
  109. package/dist/experimental/index.js +1 -34
  110. package/dist/experimental/testing/internal/constants.d.ts +2 -0
  111. package/dist/experimental/testing/internal/constants.js +1 -0
  112. package/dist/experimental/testing/internal/debug.d.ts +8 -0
  113. package/dist/experimental/testing/internal/debug.js +10 -0
  114. package/dist/experimental/testing/internal/element.d.ts +11 -0
  115. package/dist/experimental/testing/internal/element.js +67 -0
  116. package/dist/experimental/testing/internal/errors.d.ts +44 -0
  117. package/dist/experimental/testing/internal/errors.js +52 -0
  118. package/dist/experimental/testing/internal/fragment.d.ts +8 -0
  119. package/dist/experimental/testing/internal/fragment.js +44 -0
  120. package/dist/experimental/testing/internal/print.d.ts +6 -0
  121. package/dist/experimental/testing/internal/print.js +114 -0
  122. package/dist/experimental/testing/internal/query.d.ts +57 -0
  123. package/dist/experimental/testing/internal/query.js +231 -0
  124. package/dist/experimental/testing/internal/root.d.ts +8 -0
  125. package/dist/experimental/testing/internal/root.js +44 -0
  126. package/dist/experimental/testing/internal/text.d.ts +9 -0
  127. package/dist/experimental/testing/internal/text.js +16 -0
  128. package/dist/experimental/testing/internal/types-internal.d.ts +47 -0
  129. package/dist/experimental/testing/internal/types-internal.js +1 -0
  130. package/dist/experimental/testing/type-utils.d.ts +29 -0
  131. package/dist/experimental/testing/type-utils.js +37 -0
  132. package/dist/experimental/testing/types.d.ts +240 -0
  133. package/dist/experimental/testing/types.js +10 -0
  134. package/dist/hubspot.d.ts +1 -1
  135. package/dist/index.d.ts +2 -2
  136. package/dist/index.js +2 -2
  137. package/dist/pages/home/index.d.ts +1 -0
  138. package/dist/pages/home/index.js +1 -0
  139. package/package.json +12 -10
  140. package/dist/coreComponents.d.ts +0 -844
  141. package/dist/crm/components.js +0 -15
  142. package/dist/experimental/testing/index.d.ts +0 -14
  143. package/dist/experimental/testing/index.js +0 -33
  144. package/dist/experimental/testing/jest/matchers/index.d.ts +0 -6
  145. package/dist/experimental/testing/jest/matchers/index.js +0 -6
  146. package/dist/types.d.ts +0 -3167
  147. package/dist/utils/createExtensionComponent.d.ts +0 -3
  148. package/dist/utils/createExtensionComponent.js +0 -4
  149. /package/dist/{experimental/types.js → __synced__/experimental/types.synced.js} +0 -0
@@ -1,36 +1,3 @@
1
- import { createRemoteReactComponent } from '@remote-ui/react';
2
1
  export { useCrmProperties } from '../crm/hooks/useCrmProperties';
3
2
  export { useAssociations } from '../crm/hooks/useAssociations';
4
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
5
- const Iframe = createRemoteReactComponent('Iframe');
6
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
7
- const MediaObject = createRemoteReactComponent('MediaObject', {
8
- fragmentProps: ['itemRight', 'itemLeft'],
9
- });
10
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
11
- const Stack2 = createRemoteReactComponent('Stack2');
12
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
13
- const Center = createRemoteReactComponent('Center');
14
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
15
- const Grid = createRemoteReactComponent('Grid');
16
- /** @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates. */
17
- const GridItem = createRemoteReactComponent('GridItem');
18
- const SettingsView = createRemoteReactComponent('SettingsView');
19
- /**
20
- * The `ExpandableText` component renders a text that can be expanded or collapsed based on a maximum height.
21
- *
22
- * **Links:**
23
- *
24
- * - {@link https://developers.hubspot.com/docs/reference/ui-components/standard-components/expandable-text ExpandableText Docs}
25
- */
26
- const ExpandableText = createRemoteReactComponent('ExpandableText');
27
- /**
28
- * The `Popover` component renders a popover overlay that can contain other components.
29
- *
30
- * **Links:**
31
- *
32
- * - {@link https://developers.hubspot.com/docs/reference/ui-components/standard-components/popover Popover Docs}
33
- */
34
- const Popover = createRemoteReactComponent('Popover');
35
- const FileInput = createRemoteReactComponent('FileInput');
36
- export { Iframe, MediaObject, Stack2, Center, GridItem, Grid, SettingsView, ExpandableText, Popover, FileInput, };
3
+ export { Iframe, MediaObject, Stack2, Center, GridItem, Grid, SettingsView, ExpandableText, Popover, FileInput, } from '../__synced__/experimentalRemoteComponents.synced';
@@ -0,0 +1,2 @@
1
+ import { type RenderedChildNode } from '../types';
2
+ export declare const EMPTY_CHILDREN: RenderedChildNode[];
@@ -0,0 +1 @@
1
+ export const EMPTY_CHILDREN = [];
@@ -0,0 +1,8 @@
1
+ import type { RenderedParentNode } from '../types';
2
+ /**
3
+ * Logs a rendered node tree to the console for debugging purposes.
4
+ *
5
+ * @param parentNode The node to log.
6
+ * @param label Optional label to display before the node tree.
7
+ */
8
+ export declare const debugLog: (parentNode: RenderedParentNode, label?: string) => never;
@@ -0,0 +1,10 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /**
3
+ * Logs a rendered node tree to the console for debugging purposes.
4
+ *
5
+ * @param parentNode The node to log.
6
+ * @param label Optional label to display before the node tree.
7
+ */
8
+ export const debugLog = (parentNode, label) => {
9
+ throw new Error('Not implemented');
10
+ };
@@ -0,0 +1,11 @@
1
+ import type { UnknownComponentProps } from '../../../__synced__/types/shared.synced';
2
+ import type { RenderedDocumentInternal, RenderedElementNodeInternal } from './types-internal';
3
+ /**
4
+ * Creates a rendered element node.
5
+ *
6
+ * @param document The document that the element belongs to.
7
+ * @param name The name of the element.
8
+ * @param props The props of the element.
9
+ * @returns A rendered element node.
10
+ */
11
+ export declare const createElementNode: (document: RenderedDocumentInternal, name: string, props: UnknownComponentProps) => RenderedElementNodeInternal;
@@ -0,0 +1,67 @@
1
+ import { RenderedNodeType } from '../types';
2
+ import { EMPTY_CHILDREN } from './constants';
3
+ import { debugLog } from './debug';
4
+ import { InvalidEventFunctionError, MissingEventFunctionError } from './errors';
5
+ import { printNode } from './print';
6
+ import { find, findAll, findAllChildren, findChild, maybeFind, maybeFindChild, } from './query';
7
+ /**
8
+ * Creates a rendered element node.
9
+ *
10
+ * @param document The document that the element belongs to.
11
+ * @param name The name of the element.
12
+ * @param props The props of the element.
13
+ * @returns A rendered element node.
14
+ */
15
+ export const createElementNode = (document, name, props) => {
16
+ const elementNode = {
17
+ nodeType: RenderedNodeType.Element,
18
+ name,
19
+ props,
20
+ text: null,
21
+ children: EMPTY_CHILDREN,
22
+ document,
23
+ debugLog: (label) => {
24
+ debugLog(elementNode, label);
25
+ },
26
+ find: (targetComponent, matcher) => {
27
+ return find(elementNode, targetComponent, matcher);
28
+ },
29
+ findAll: (targetComponent, matcher) => {
30
+ return findAll(elementNode, targetComponent, matcher);
31
+ },
32
+ findChild: (targetComponent, matcher) => {
33
+ return findChild(elementNode, targetComponent, matcher);
34
+ },
35
+ findAllChildren: (targetComponent, matcher) => {
36
+ return findAllChildren(elementNode, targetComponent, matcher);
37
+ },
38
+ maybeFind: (targetComponent, matcher) => {
39
+ return maybeFind(elementNode, targetComponent, matcher);
40
+ },
41
+ maybeFindChild: (targetComponent, matcher) => {
42
+ return maybeFindChild(elementNode, targetComponent, matcher);
43
+ },
44
+ toString: () => {
45
+ return printNode(elementNode);
46
+ },
47
+ trigger: (eventPropName, eventArg) => {
48
+ const eventFunction = elementNode.props[eventPropName];
49
+ if (!eventFunction) {
50
+ throw new MissingEventFunctionError({
51
+ componentName: name,
52
+ eventPropName,
53
+ });
54
+ }
55
+ if (typeof eventFunction !== 'function') {
56
+ throw new InvalidEventFunctionError({
57
+ componentName: name,
58
+ eventPropName,
59
+ });
60
+ }
61
+ document.batchUpdate(() => {
62
+ eventFunction(eventArg);
63
+ });
64
+ },
65
+ };
66
+ return elementNode;
67
+ };
@@ -0,0 +1,44 @@
1
+ import { RenderedParentNode } from '../types';
2
+ import { RenderedRootNodeInternal } from './types-internal';
3
+ /**
4
+ * Thrown when trying to trigger an event that has a handler prop that is not a function.
5
+ */
6
+ export declare class InvalidEventFunctionError extends Error {
7
+ constructor({ componentName, eventPropName, }: {
8
+ componentName: string;
9
+ eventPropName: string;
10
+ });
11
+ }
12
+ /**
13
+ * Thrown when trying to trigger an event that has no corresponding handler function in the props object.
14
+ */
15
+ export declare class MissingEventFunctionError extends Error {
16
+ constructor({ componentName, eventPropName, }: {
17
+ componentName: string;
18
+ eventPropName: string;
19
+ });
20
+ }
21
+ /**
22
+ * Thrown when a component is not found in the rendered output.
23
+ */
24
+ export declare class ComponentNotFoundError extends Error {
25
+ constructor({ findMethodName, parentNode, componentName, }: {
26
+ findMethodName: string;
27
+ parentNode: RenderedParentNode;
28
+ componentName: string;
29
+ });
30
+ }
31
+ /**
32
+ * Thrown when invalid components are detected in the rendered output.
33
+ */
34
+ export declare class InvalidComponentsError extends Error {
35
+ constructor(rootNode: RenderedRootNodeInternal);
36
+ }
37
+ /**
38
+ * Thrown when the target component passed to the find operation is not a valid HubSpot-provided React component.
39
+ */
40
+ export declare class FindInvalidComponentError extends Error {
41
+ constructor({ findMethodName }: {
42
+ findMethodName: string;
43
+ });
44
+ }
@@ -0,0 +1,52 @@
1
+ import { printNode } from './print';
2
+ /**
3
+ * Thrown when trying to trigger an event that has a handler prop that is not a function.
4
+ */
5
+ export class InvalidEventFunctionError extends Error {
6
+ constructor({ componentName, eventPropName, }) {
7
+ super(`trigger("${String(eventPropName)}", ...) failed. Event function for prop "${String(eventPropName)}" in component "${componentName}" props is not a function`);
8
+ this.name = 'InvalidEventFunctionError';
9
+ }
10
+ }
11
+ /**
12
+ * Thrown when trying to trigger an event that has no corresponding handler function in the props object.
13
+ */
14
+ export class MissingEventFunctionError extends Error {
15
+ constructor({ componentName, eventPropName, }) {
16
+ super(`trigger("${String(eventPropName)}", ...) failed. Event function for prop "${String(eventPropName)}" not found in component "${componentName}" props`);
17
+ this.name = 'MissingEventFunctionError';
18
+ }
19
+ }
20
+ /**
21
+ * Thrown when a component is not found in the rendered output.
22
+ */
23
+ export class ComponentNotFoundError extends Error {
24
+ constructor({ findMethodName, parentNode, componentName, }) {
25
+ super(`${findMethodName}() failed. <${componentName}> not found in rendered output: ${parentNode.toString()}`);
26
+ this.name = 'ComponentNotFoundError';
27
+ }
28
+ }
29
+ /**
30
+ * Thrown when invalid components are detected in the rendered output.
31
+ */
32
+ export class InvalidComponentsError extends Error {
33
+ constructor(rootNode) {
34
+ super(`Invalid rendered output. Found invalid components (${rootNode.document
35
+ .getInvalidComponentNames()
36
+ .map((name) => `"${name}"`)
37
+ .join(', ')}) in rendered output: ${printNode(rootNode, {
38
+ markInvalidComponents: true,
39
+ listInvalidComponents: true,
40
+ })}`);
41
+ this.name = 'InvalidComponentsError';
42
+ }
43
+ }
44
+ /**
45
+ * Thrown when the target component passed to the find operation is not a valid HubSpot-provided React component.
46
+ */
47
+ export class FindInvalidComponentError extends Error {
48
+ constructor({ findMethodName }) {
49
+ super(`${findMethodName}() failed. The provided target component is not a HubSpot-provided React component`);
50
+ this.name = 'FindInvalidComponentError';
51
+ }
52
+ }
@@ -0,0 +1,8 @@
1
+ import type { RenderedDocumentInternal, RenderedFragmentNodeInternal } from './types-internal';
2
+ /**
3
+ * Creates a rendered fragment node.
4
+ *
5
+ * @param document The document that the fragment belongs to.
6
+ * @returns A rendered fragment node.
7
+ */
8
+ export declare const createFragmentNode: (document: RenderedDocumentInternal) => RenderedFragmentNodeInternal;
@@ -0,0 +1,44 @@
1
+ import { RenderedNodeType } from '../types';
2
+ import { EMPTY_CHILDREN } from './constants';
3
+ import { debugLog } from './debug';
4
+ import { printNode } from './print';
5
+ import { find, findAll, findAllChildren, findChild, maybeFind, maybeFindChild, } from './query';
6
+ /**
7
+ * Creates a rendered fragment node.
8
+ *
9
+ * @param document The document that the fragment belongs to.
10
+ * @returns A rendered fragment node.
11
+ */
12
+ export const createFragmentNode = (document) => {
13
+ const fragmentNode = {
14
+ nodeType: RenderedNodeType.Fragment,
15
+ text: null,
16
+ children: EMPTY_CHILDREN,
17
+ document,
18
+ debugLog: (label) => {
19
+ debugLog(fragmentNode, label);
20
+ },
21
+ find: (targetComponent, matcher) => {
22
+ return find(fragmentNode, targetComponent, matcher);
23
+ },
24
+ findAll: (targetComponent, matcher) => {
25
+ return findAll(fragmentNode, targetComponent, matcher);
26
+ },
27
+ findChild: (targetComponent, matcher) => {
28
+ return findChild(fragmentNode, targetComponent, matcher);
29
+ },
30
+ findAllChildren: (targetComponent, matcher) => {
31
+ return findAllChildren(fragmentNode, targetComponent, matcher);
32
+ },
33
+ maybeFind: (targetComponent, matcher) => {
34
+ return maybeFind(fragmentNode, targetComponent, matcher);
35
+ },
36
+ maybeFindChild: (targetComponent, matcher) => {
37
+ return maybeFindChild(fragmentNode, targetComponent, matcher);
38
+ },
39
+ toString: () => {
40
+ return printNode(fragmentNode);
41
+ },
42
+ };
43
+ return fragmentNode;
44
+ };
@@ -0,0 +1,6 @@
1
+ import type { RenderedParentNode } from '../types';
2
+ export interface PrintOptions {
3
+ markInvalidComponents: boolean;
4
+ listInvalidComponents: boolean;
5
+ }
6
+ export declare const printNode: (rootNode: RenderedParentNode, options?: PrintOptions) => string;
@@ -0,0 +1,114 @@
1
+ import { __hubSpotComponentRegistry } from '../../../__synced__/remoteComponents.synced';
2
+ import { isRenderedElementNode, isRenderedFragmentNode, isRenderedRootNode, isRenderedTextNode, } from '../type-utils';
3
+ const INDENT_STRING = ' ';
4
+ const printTextNode = (node, indent, printContext) => {
5
+ printContext.append(`${indent}${JSON.stringify(node.text)}\n`);
6
+ };
7
+ const propValueToString = (value) => {
8
+ if (typeof value === 'function') {
9
+ return '={function}';
10
+ }
11
+ else if (typeof value === 'number') {
12
+ return `={${value}}`;
13
+ }
14
+ else if (typeof value === 'string') {
15
+ return `=${JSON.stringify(value)}`;
16
+ }
17
+ else if (typeof value === 'boolean') {
18
+ return value === true ? '' : '={false}';
19
+ }
20
+ return `={${JSON.stringify(value)}}`;
21
+ };
22
+ const printElementProps = (name, props, indent, printContext) => {
23
+ for (const [propName, propValue] of Object.entries(props)) {
24
+ if (__hubSpotComponentRegistry.isComponentFragmentProp(name, propName)) {
25
+ printContext.append(` ${propName}={`);
26
+ printFragmentNode(propValue, indent, printContext);
27
+ printContext.append(`}`);
28
+ }
29
+ else {
30
+ printContext.append(` ${propName}${propValueToString(propValue)}`);
31
+ }
32
+ }
33
+ };
34
+ const printElementStart = (node, indent, printContext) => {
35
+ const { name } = node;
36
+ printContext.append(indent);
37
+ printContext.append(`<${name}`);
38
+ if (!__hubSpotComponentRegistry.isAllowedComponentName(name)) {
39
+ printContext.foundInvalidComponents.add(name);
40
+ if (printContext.options.markInvalidComponents) {
41
+ printContext.append('⚠️');
42
+ }
43
+ }
44
+ };
45
+ const printElementNode = (node, indent, printContext) => {
46
+ const hasChildren = node.children.length > 0;
47
+ const { name, props } = node;
48
+ if (hasChildren) {
49
+ printElementStart(node, indent, printContext);
50
+ printElementProps(name, props, indent + INDENT_STRING, printContext);
51
+ printContext.append(`>\n`);
52
+ printChildren(node, indent + INDENT_STRING, printContext);
53
+ printContext.append(`${indent}</${name}>\n`);
54
+ }
55
+ else {
56
+ printElementStart(node, indent, printContext);
57
+ printElementProps(name, props, indent + INDENT_STRING, printContext);
58
+ printContext.append(`/>\n`);
59
+ }
60
+ };
61
+ const printChildren = (node, indent, printContext) => {
62
+ const { children } = node;
63
+ for (const child of children) {
64
+ if (isRenderedTextNode(child)) {
65
+ printTextNode(child, indent, printContext);
66
+ }
67
+ else if (isRenderedElementNode(child)) {
68
+ printElementNode(child, indent, printContext);
69
+ }
70
+ else {
71
+ throw new Error(`Illegal State. Invalid rendered node type: ${child.nodeType}`);
72
+ }
73
+ }
74
+ };
75
+ const DEFAULT_PRINT_OPTIONS = {
76
+ markInvalidComponents: true,
77
+ listInvalidComponents: false,
78
+ };
79
+ const printFragmentNode = (node, indent, printContext) => {
80
+ printContext.append(`<>\n`);
81
+ printChildren(node, indent + INDENT_STRING, printContext);
82
+ printContext.append(`${indent}</>`);
83
+ };
84
+ export const printNode = (rootNode, options = DEFAULT_PRINT_OPTIONS) => {
85
+ const { listInvalidComponents } = options;
86
+ let output = '';
87
+ const printContext = {
88
+ append: (str) => {
89
+ output += str;
90
+ },
91
+ options,
92
+ foundInvalidComponents: new Set(),
93
+ };
94
+ if (isRenderedRootNode(rootNode)) {
95
+ printContext.append(`<>\n`);
96
+ printChildren(rootNode, INDENT_STRING, printContext);
97
+ printContext.append(`</>`);
98
+ }
99
+ else if (isRenderedFragmentNode(rootNode)) {
100
+ printFragmentNode(rootNode, '', printContext);
101
+ }
102
+ else {
103
+ printElementNode(rootNode, '', printContext);
104
+ }
105
+ if (listInvalidComponents && printContext.foundInvalidComponents.size > 0) {
106
+ printContext.append(`\n⚠️ Invalid components:\n`);
107
+ const foundInvalidComponents = [...printContext.foundInvalidComponents];
108
+ foundInvalidComponents.sort();
109
+ for (const invalidComponentName of foundInvalidComponents) {
110
+ printContext.append(`- ${invalidComponentName}\n`);
111
+ }
112
+ }
113
+ return output.replace(/\n$/, '');
114
+ };
@@ -0,0 +1,57 @@
1
+ import type { HubSpotReactComponent, UnknownComponentProps } from '../../../__synced__/types/shared.synced';
2
+ import type { ElementMatcher, RenderedElementNode } from '../types';
3
+ import type { RenderedParentNodeInternal } from './types-internal';
4
+ /**
5
+ * Finds the first descendant element node that matches the given component.
6
+ *
7
+ * @param parentNode The parent node to search in.
8
+ * @param targetComponent The component to find.
9
+ * @param matcher An optional matcher to filter the elements.
10
+ * @returns The first element node that matches the given component or `null` if no match is found.
11
+ */
12
+ export declare const maybeFind: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps> | null;
13
+ /**
14
+ * Finds the first descendant element node that matches the given component.
15
+ *
16
+ * @param parentNode The parent node to search in.
17
+ * @param targetComponent The component to find.
18
+ * @param matcher An optional matcher to filter the elements.
19
+ * @returns The first element node that matches the given component.
20
+ */
21
+ export declare const find: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps>;
22
+ /**
23
+ * Finds all descendant element nodes that match the given component.
24
+ *
25
+ * @param parentNode The parent node to search in.
26
+ * @param targetComponent The component to find.
27
+ * @param matcher An optional matcher to filter the elements.
28
+ * @returns An array of element nodes that match the given component.
29
+ */
30
+ export declare const findAll: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps>[];
31
+ /**
32
+ * Finds the first direct child element node that matches the given component.
33
+ *
34
+ * @param parentNode The parent node to search in.
35
+ * @param targetComponent The component to find.
36
+ * @param matcher An optional matcher to filter the elements.
37
+ * @returns The first child element node that matches the given component.
38
+ */
39
+ export declare const findChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps>;
40
+ /**
41
+ * Finds the first direct child element node that matches the given component.
42
+ *
43
+ * @param parentNode The parent node to search in.
44
+ * @param targetComponent The component to find.
45
+ * @param matcher An optional matcher to filter the elements.
46
+ * @returns The first child element node that matches the given component.
47
+ */
48
+ export declare const maybeFindChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps> | null;
49
+ /**
50
+ * Finds all direct child element nodes that match the given component.
51
+ *
52
+ * @param parentNode The parent node to search in.
53
+ * @param targetComponent The component to find.
54
+ * @param matcher An optional matcher to filter the elements.
55
+ * @returns An array of child element nodes that match the given component.
56
+ */
57
+ export declare const findAllChildren: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps> | undefined) => RenderedElementNode<TProps>[];