@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
@@ -0,0 +1,231 @@
1
+ import { __hubSpotComponentRegistry } from '../../../__synced__/remoteComponents.synced';
2
+ import { isRenderedElementNode, isRenderedFragmentNode } from '../type-utils';
3
+ import { ComponentNotFoundError, FindInvalidComponentError, InvalidComponentsError, } from './errors';
4
+ /**
5
+ * Checks if the element matches the matcher.
6
+ *
7
+ * @param element The element to check.
8
+ * @param matcher An optional matcher to filter the elements.
9
+ * @returns `true` if the element matches the matcher, `false` otherwise.
10
+ */
11
+ const checkElementMatches = (element, matcher) => {
12
+ // If no matcher is provided, the element matches
13
+ if (!matcher) {
14
+ return true;
15
+ }
16
+ // Check if the matcher is a predicate function
17
+ if (typeof matcher === 'function') {
18
+ return matcher(element);
19
+ }
20
+ // Check if all the props in the matcher match the props in the element
21
+ return Object.keys(matcher).every((key) => element.props[key] === matcher[key]);
22
+ };
23
+ const addMatchToFindResult = (findResult, match, options) => {
24
+ if (options.findFirstOnly) {
25
+ findResult.match = match;
26
+ }
27
+ else {
28
+ findResult.allMatches.push(match);
29
+ }
30
+ };
31
+ /**
32
+ * Recursive helper for finding elements in the rendered tree.
33
+ * NOTE: The input `findResult` is mutated in place.
34
+ *
35
+ * @param parentNode The parent node to search in.
36
+ * @param options The options for the find operation.
37
+ * @param findResult The find result to mutate.
38
+ */
39
+ const findInternalHelper = (parentNode, options, findResult) => {
40
+ const { children } = parentNode;
41
+ const { targetComponent, matcher, findFirstOnly, findDirectChildrenOnly } = options;
42
+ const targetComponentName = __hubSpotComponentRegistry.getComponentName(targetComponent);
43
+ for (const child of children) {
44
+ if (!isRenderedElementNode(child)) {
45
+ // Skip over non-element child nodes (just text nodes)
46
+ continue;
47
+ }
48
+ if (child.name === targetComponentName &&
49
+ checkElementMatches(child, matcher)) {
50
+ // We found a match, so add it to the find result
51
+ addMatchToFindResult(findResult, child, options);
52
+ if (findFirstOnly) {
53
+ return;
54
+ }
55
+ }
56
+ // We only search in nested children and fragment props if we're not only looking for children
57
+ if (!findDirectChildrenOnly) {
58
+ // Search for the component in the fragment props
59
+ const { props } = child;
60
+ const fragmentProps = __hubSpotComponentRegistry.getComponentFragmentPropNames(child.name);
61
+ for (const fragmentPropName of fragmentProps) {
62
+ const maybeFragment = props[fragmentPropName];
63
+ // NOTE: As part of the conversion process of converting remote nodes to rendered nodes, we
64
+ // create a RenderedFragmentNode for each fragment prop and put that into the props object.
65
+ if (isRenderedFragmentNode(maybeFragment)) {
66
+ findInternalHelper(maybeFragment, options, findResult);
67
+ if (findFirstOnly && findResult.match) {
68
+ return;
69
+ }
70
+ }
71
+ }
72
+ // Search for the component in the child
73
+ findInternalHelper(child, options, findResult);
74
+ if (findFirstOnly && findResult.match) {
75
+ return;
76
+ }
77
+ }
78
+ }
79
+ return;
80
+ };
81
+ /**
82
+ * Internal utility that centralizes finding elements in the rendered tree (including error handling).
83
+ *
84
+ * @param parentNode The parent node to search in.
85
+ * @param options The options for the find operation.
86
+ * @returns The find result.
87
+ */
88
+ const findInternal = (parentNode, options) => {
89
+ const { document } = parentNode;
90
+ const { targetComponent, findMethodName, shouldThrowErrorIfNotFound } = options;
91
+ const targetComponentName = __hubSpotComponentRegistry.getComponentName(targetComponent);
92
+ if (!targetComponentName) {
93
+ throw new FindInvalidComponentError({
94
+ findMethodName,
95
+ });
96
+ }
97
+ // We always validate the document before running the find operation since the document may
98
+ // have been updated asynchronously in the background.
99
+ if (document.hasInvalidComponentNames()) {
100
+ throw new InvalidComponentsError(document.rootNode);
101
+ }
102
+ // Initialize the find result that will be mutated in place
103
+ const findResult = {
104
+ match: null,
105
+ allMatches: [],
106
+ };
107
+ // Run the internal find helper to recursively search the rendered tree
108
+ findInternalHelper(parentNode, options, findResult);
109
+ if (findResult.match === null && shouldThrowErrorIfNotFound) {
110
+ throw new ComponentNotFoundError({
111
+ findMethodName: options.findMethodName,
112
+ parentNode,
113
+ componentName: targetComponentName,
114
+ });
115
+ }
116
+ return findResult;
117
+ };
118
+ /**
119
+ * Finds the first descendant element node that matches the given component.
120
+ *
121
+ * @param parentNode The parent node to search in.
122
+ * @param targetComponent The component to find.
123
+ * @param matcher An optional matcher to filter the elements.
124
+ * @returns The first element node that matches the given component or `null` if no match is found.
125
+ */
126
+ export const maybeFind = (parentNode, targetComponent, matcher) => {
127
+ const { match } = findInternal(parentNode, {
128
+ targetComponent,
129
+ matcher,
130
+ findFirstOnly: true,
131
+ findDirectChildrenOnly: false,
132
+ findMethodName: 'maybeFind',
133
+ shouldThrowErrorIfNotFound: false,
134
+ });
135
+ return match;
136
+ };
137
+ /**
138
+ * Finds the first descendant element node that matches the given component.
139
+ *
140
+ * @param parentNode The parent node to search in.
141
+ * @param targetComponent The component to find.
142
+ * @param matcher An optional matcher to filter the elements.
143
+ * @returns The first element node that matches the given component.
144
+ */
145
+ export const find = (parentNode, targetComponent, matcher) => {
146
+ const { match } = findInternal(parentNode, {
147
+ targetComponent,
148
+ matcher,
149
+ findFirstOnly: true,
150
+ findDirectChildrenOnly: false,
151
+ findMethodName: 'find',
152
+ shouldThrowErrorIfNotFound: true,
153
+ });
154
+ return match;
155
+ };
156
+ /**
157
+ * Finds all descendant element nodes that match the given component.
158
+ *
159
+ * @param parentNode The parent node to search in.
160
+ * @param targetComponent The component to find.
161
+ * @param matcher An optional matcher to filter the elements.
162
+ * @returns An array of element nodes that match the given component.
163
+ */
164
+ export const findAll = (parentNode, targetComponent, matcher) => {
165
+ const { allMatches } = findInternal(parentNode, {
166
+ targetComponent,
167
+ matcher,
168
+ findFirstOnly: false,
169
+ findDirectChildrenOnly: false,
170
+ findMethodName: 'findAll',
171
+ shouldThrowErrorIfNotFound: false,
172
+ });
173
+ return allMatches;
174
+ };
175
+ /**
176
+ * Finds the first direct child element node that matches the given component.
177
+ *
178
+ * @param parentNode The parent node to search in.
179
+ * @param targetComponent The component to find.
180
+ * @param matcher An optional matcher to filter the elements.
181
+ * @returns The first child element node that matches the given component.
182
+ */
183
+ export const findChild = (parentNode, targetComponent, matcher) => {
184
+ const { match } = findInternal(parentNode, {
185
+ targetComponent,
186
+ matcher,
187
+ findFirstOnly: true,
188
+ findDirectChildrenOnly: true,
189
+ findMethodName: 'findChild',
190
+ shouldThrowErrorIfNotFound: true,
191
+ });
192
+ return match;
193
+ };
194
+ /**
195
+ * Finds the first direct child element node that matches the given component.
196
+ *
197
+ * @param parentNode The parent node to search in.
198
+ * @param targetComponent The component to find.
199
+ * @param matcher An optional matcher to filter the elements.
200
+ * @returns The first child element node that matches the given component.
201
+ */
202
+ export const maybeFindChild = (parentNode, targetComponent, matcher) => {
203
+ const { match } = findInternal(parentNode, {
204
+ targetComponent,
205
+ matcher,
206
+ findFirstOnly: true,
207
+ findDirectChildrenOnly: true,
208
+ findMethodName: 'maybeFindChild',
209
+ shouldThrowErrorIfNotFound: false,
210
+ });
211
+ return match;
212
+ };
213
+ /**
214
+ * Finds all direct child element nodes that match the given component.
215
+ *
216
+ * @param parentNode The parent node to search in.
217
+ * @param targetComponent The component to find.
218
+ * @param matcher An optional matcher to filter the elements.
219
+ * @returns An array of child element nodes that match the given component.
220
+ */
221
+ export const findAllChildren = (parentNode, targetComponent, matcher) => {
222
+ const { allMatches } = findInternal(parentNode, {
223
+ targetComponent,
224
+ matcher,
225
+ findFirstOnly: false,
226
+ findDirectChildrenOnly: true,
227
+ findMethodName: 'findAllChildren',
228
+ shouldThrowErrorIfNotFound: false,
229
+ });
230
+ return allMatches;
231
+ };
@@ -0,0 +1,8 @@
1
+ import type { RenderedDocumentInternal, RenderedRootNodeInternal } from './types-internal';
2
+ /**
3
+ * Creates a rendered root node.
4
+ *
5
+ * @param document The document that the root belongs to.
6
+ * @returns A rendered root node.
7
+ */
8
+ export declare const createRootNode: (document: RenderedDocumentInternal) => RenderedRootNodeInternal;
@@ -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 root node.
8
+ *
9
+ * @param document The document that the root belongs to.
10
+ * @returns A rendered root node.
11
+ */
12
+ export const createRootNode = (document) => {
13
+ const rootNode = {
14
+ nodeType: RenderedNodeType.Root,
15
+ text: null,
16
+ children: EMPTY_CHILDREN,
17
+ document,
18
+ debugLog: (label) => {
19
+ debugLog(rootNode, label);
20
+ },
21
+ find: (targetComponent, matcher) => {
22
+ return find(rootNode, targetComponent, matcher);
23
+ },
24
+ findAll: (targetComponent, matcher) => {
25
+ return findAll(rootNode, targetComponent, matcher);
26
+ },
27
+ findChild: (targetComponent, matcher) => {
28
+ return findChild(rootNode, targetComponent, matcher);
29
+ },
30
+ findAllChildren: (targetComponent, matcher) => {
31
+ return findAllChildren(rootNode, targetComponent, matcher);
32
+ },
33
+ maybeFind: (targetComponent, matcher) => {
34
+ return maybeFind(rootNode, targetComponent, matcher);
35
+ },
36
+ maybeFindChild: (targetComponent, matcher) => {
37
+ return maybeFindChild(rootNode, targetComponent, matcher);
38
+ },
39
+ toString: () => {
40
+ return printNode(rootNode);
41
+ },
42
+ };
43
+ return rootNode;
44
+ };
@@ -0,0 +1,9 @@
1
+ import { type RemoteRoot, type RemoteText } from '@remote-ui/core';
2
+ import { type RenderedTextNode } from '../types';
3
+ /**
4
+ * Creates a rendered text node.
5
+ *
6
+ * @param remoteText The remote text node or string to create a text node from.
7
+ * @returns A rendered text node.
8
+ */
9
+ export declare const createTextNode: (remoteText: RemoteText<RemoteRoot> | string) => RenderedTextNode;
@@ -0,0 +1,16 @@
1
+ import { RenderedNodeType } from '../types';
2
+ /**
3
+ * Creates a rendered text node.
4
+ *
5
+ * @param remoteText The remote text node or string to create a text node from.
6
+ * @returns A rendered text node.
7
+ */
8
+ export const createTextNode = (remoteText) => {
9
+ const text = typeof remoteText === 'string' ? remoteText : remoteText.text;
10
+ const textNode = {
11
+ nodeType: RenderedNodeType.Text,
12
+ text,
13
+ toString: () => text,
14
+ };
15
+ return textNode;
16
+ };
@@ -0,0 +1,47 @@
1
+ import type { RemoteComponent, RemoteFragment, RemoteRoot, RemoteText } from '@remote-ui/core';
2
+ import type { RenderedElementNode, RenderedFragmentNode, RenderedNode, RenderedParentNode, RenderedRootNode, RenderedTextNode } from '../types';
3
+ export type RemoteChildNode = RemoteComponent<any, RemoteRoot> | RemoteText<RemoteRoot>;
4
+ export type RemoteParentNode = RemoteRoot | RemoteComponent<any, RemoteRoot> | RemoteFragment;
5
+ /**
6
+ * Represents a rendered document.
7
+ */
8
+ export interface RenderedDocumentInternal {
9
+ /**
10
+ * The root node of the document.
11
+ */
12
+ rootNode: RenderedRootNodeInternal | null;
13
+ /**
14
+ * Adds the name of an invalid component to the document.
15
+ *
16
+ * @param name The name of the invalid component.
17
+ */
18
+ addInvalidComponentName: (name: string) => void;
19
+ /**
20
+ * @returns the names of the invalid components.
21
+ */
22
+ getInvalidComponentNames: () => string[];
23
+ /**
24
+ * @returns Returns `true` if the document has invalid component types. `false` otherwise.
25
+ */
26
+ hasInvalidComponentNames: () => boolean;
27
+ /**
28
+ * Used to wrap the execution of a function that updates the rendered DOM.
29
+ * This is used to validate the rendered DOM after the function has been executed.
30
+ *
31
+ * @param run The function to execute.
32
+ */
33
+ batchUpdate: (run: () => void) => void;
34
+ }
35
+ /**
36
+ * Adds the `document` property to the rendered node. We do not include this in the public types because it is not
37
+ * part of the public API, but we need it for internal use.
38
+ */
39
+ type MakeRenderedNodeInternal<TRenderedNode extends RenderedNode> = TRenderedNode & {
40
+ document: RenderedDocumentInternal;
41
+ };
42
+ export type RenderedElementNodeInternal = MakeRenderedNodeInternal<RenderedElementNode>;
43
+ export type RenderedTextNodeInternal = MakeRenderedNodeInternal<RenderedTextNode>;
44
+ export type RenderedRootNodeInternal = MakeRenderedNodeInternal<RenderedRootNode>;
45
+ export type RenderedFragmentNodeInternal = MakeRenderedNodeInternal<RenderedFragmentNode>;
46
+ export type RenderedParentNodeInternal = MakeRenderedNodeInternal<RenderedParentNode>;
47
+ export {};
@@ -0,0 +1,29 @@
1
+ import { type RenderedElementNode, type RenderedFragmentNode, type RenderedNode, type RenderedRootNode, type RenderedTextNode } from './types';
2
+ /**
3
+ * Type guard to check if a node is a rendered element node.
4
+ *
5
+ * @param node The node to check.
6
+ * @returns `true` if the node is a rendered element node.
7
+ */
8
+ export declare const isRenderedElementNode: (node: RenderedNode | null | undefined) => node is RenderedElementNode<import("../..").UnknownComponentProps>;
9
+ /**
10
+ * Type guard to check if a node is a rendered text node.
11
+ *
12
+ * @param node The node to check.
13
+ * @returns `true` if the node is a rendered text node.
14
+ */
15
+ export declare const isRenderedTextNode: (node: RenderedNode | null | undefined) => node is RenderedTextNode;
16
+ /**
17
+ * Type guard to check if a node is a rendered root node.
18
+ *
19
+ * @param node The node to check.
20
+ * @returns `true` if the node is a rendered root node.
21
+ */
22
+ export declare const isRenderedRootNode: (node: RenderedNode | null | undefined) => node is RenderedRootNode;
23
+ /**
24
+ * Type guard to check if a node is a rendered fragment node.
25
+ *
26
+ * @param node The node to check.
27
+ * @returns `true` if the node is a rendered fragment node.
28
+ */
29
+ export declare const isRenderedFragmentNode: (node: RenderedNode | null | undefined) => node is RenderedFragmentNode;
@@ -0,0 +1,37 @@
1
+ import { RenderedNodeType, } from './types';
2
+ /**
3
+ * Type guard to check if a node is a rendered element node.
4
+ *
5
+ * @param node The node to check.
6
+ * @returns `true` if the node is a rendered element node.
7
+ */
8
+ export const isRenderedElementNode = (node) => {
9
+ return node?.nodeType === RenderedNodeType.Element;
10
+ };
11
+ /**
12
+ * Type guard to check if a node is a rendered text node.
13
+ *
14
+ * @param node The node to check.
15
+ * @returns `true` if the node is a rendered text node.
16
+ */
17
+ export const isRenderedTextNode = (node) => {
18
+ return node?.nodeType === RenderedNodeType.Text;
19
+ };
20
+ /**
21
+ * Type guard to check if a node is a rendered root node.
22
+ *
23
+ * @param node The node to check.
24
+ * @returns `true` if the node is a rendered root node.
25
+ */
26
+ export const isRenderedRootNode = (node) => {
27
+ return node?.nodeType === RenderedNodeType.Root;
28
+ };
29
+ /**
30
+ * Type guard to check if a node is a rendered fragment node.
31
+ *
32
+ * @param node The node to check.
33
+ * @returns `true` if the node is a rendered fragment node.
34
+ */
35
+ export const isRenderedFragmentNode = (node) => {
36
+ return node?.nodeType === RenderedNodeType.Fragment;
37
+ };
@@ -0,0 +1,240 @@
1
+ import { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../../__synced__/types/shared.synced';
2
+ /**
3
+ * The type of a rendered node.
4
+ */
5
+ export declare enum RenderedNodeType {
6
+ Root = "root",
7
+ Fragment = "fragment",
8
+ Element = "element",
9
+ Text = "text"
10
+ }
11
+ /**
12
+ * Extracts event property names from a props type, filtering for properties that are functions
13
+ */
14
+ type EventNamesForProps<TProps extends UnknownComponentProps> = {
15
+ [K in keyof Required<TProps>]: Required<TProps>[K] extends Function ? K : never;
16
+ }[keyof TProps];
17
+ interface CommonQueryMethods {
18
+ /**
19
+ * Finds the first descendant element node that matches the given component.
20
+ *
21
+ * @param component The component to find.
22
+ * @param matcher An optional matcher to filter the elements.
23
+ * @returns The first element node that matches the given component or `null` if no match is found.
24
+ */
25
+ maybeFind<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps> | null;
26
+ /**
27
+ * Finds the first descendant element node that matches the given component. If no match is found, an error will be thrown.
28
+ *
29
+ * @param component The component to find.
30
+ * @param matcher An optional matcher to filter the elements.
31
+ * @returns The first element node that matches the given component.
32
+ */
33
+ find<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps>;
34
+ /**
35
+ * Finds all descendant element nodes that match the given component.
36
+ *
37
+ * @param component The component to find.
38
+ * @param matcher An optional matcher to filter the elements.
39
+ * @returns An array of element nodes that match the given component.
40
+ */
41
+ findAll<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps>[];
42
+ /**
43
+ * Finds the first direct child element node that matches the given component.
44
+ *
45
+ * @param component The component to find.
46
+ * @param matcher An optional matcher to filter the elements.
47
+ * @returns The first child element node that matches the given component.
48
+ */
49
+ findChild<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps>;
50
+ /**
51
+ * Finds the first direct child element node that matches the given component.
52
+ *
53
+ * @param component The component to find.
54
+ * @param matcher An optional matcher to filter the elements.
55
+ * @returns The first child element node that matches the given component or `null` if no match is found.
56
+ */
57
+ maybeFindChild<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps> | null;
58
+ /**
59
+ * Finds all direct child element nodes that match the given component.
60
+ *
61
+ * @param component The component to find.
62
+ * @param matcher An optional matcher to filter the elements.
63
+ * @returns An array of child element nodes that match the given component.
64
+ */
65
+ findAllChildren<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps>[];
66
+ }
67
+ interface BaseRenderedParentNode {
68
+ /**
69
+ * The child nodes
70
+ */
71
+ children: RenderedChildNode[];
72
+ }
73
+ /**
74
+ * Represents a root node of a rendered component.
75
+ *
76
+ * NOTE: Rendered root nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
77
+ */
78
+ export interface RenderedRootNode extends BaseRenderedParentNode, CommonQueryMethods {
79
+ /**
80
+ * The type of the node (always `RenderedNodeType.Root` for a root node).
81
+ */
82
+ nodeType: RenderedNodeType.Root;
83
+ /**
84
+ * The text content of the root node or `null` if the root node does not have any text content.
85
+ */
86
+ text: string | null;
87
+ /**
88
+ * Logs a string representation of the root node as a console log.
89
+ */
90
+ debugLog: (label?: string) => void;
91
+ /**
92
+ * Returns a string representation of the root node.
93
+ *
94
+ * @returns A string representation of the root node.
95
+ */
96
+ toString: () => string;
97
+ }
98
+ /**
99
+ * Represents a fragment node passed as a prop to a rendered component.
100
+ *
101
+ * NOTE: Rendered fragment nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
102
+ */
103
+ export interface RenderedFragmentNode extends BaseRenderedParentNode, CommonQueryMethods {
104
+ /**
105
+ * The type of the node (always `RenderedNodeType.Fragment` for a fragment node).
106
+ */
107
+ nodeType: RenderedNodeType.Fragment;
108
+ /**
109
+ * The text content of the fragment node or `null` if the fragment node does not have any text content.
110
+ */
111
+ text: string | null;
112
+ /**
113
+ * Logs a string representation of the fragment node as a console log.
114
+ */
115
+ debugLog: (label?: string) => void;
116
+ /**
117
+ * Returns a string representation of the fragment node.
118
+ */
119
+ toString: () => string;
120
+ }
121
+ type RenderPropsFromComponentProps<TProps extends UnknownComponentProps> = {
122
+ [K in keyof TProps]: HubSpotReactFragmentProp extends TProps[K] ? RenderedFragmentNode : TProps[K];
123
+ };
124
+ /**
125
+ * Represents an element node of a rendered component.
126
+ *
127
+ * NOTE: Rendered elements are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
128
+ */
129
+ export interface RenderedElementNode<TProps extends UnknownComponentProps = UnknownComponentProps> extends BaseRenderedParentNode, CommonQueryMethods {
130
+ /**
131
+ * The type of the node (always `RenderedNodeType.Element` for an element node).
132
+ */
133
+ nodeType: RenderedNodeType.Element;
134
+ /**
135
+ * The name of the element node.
136
+ */
137
+ name: string;
138
+ /**
139
+ * The props passed to the element node.
140
+ */
141
+ props: RenderPropsFromComponentProps<TProps>;
142
+ /**
143
+ * The text content of the element node or `null` if the element node does not have any text content.
144
+ */
145
+ text: string | null;
146
+ /**
147
+ * Logs a string representation of the element node as a console log.
148
+ *
149
+ * @param label The label to log.
150
+ */
151
+ debugLog: (label?: string) => void;
152
+ /**
153
+ * Returns a string representation of the element node.
154
+ */
155
+ toString: () => string;
156
+ /**
157
+ * Triggers an event function on the element node.
158
+ *
159
+ * @param eventPropName The name of the event to trigger.
160
+ * @param eventArg The argument to pass to the event.
161
+ */
162
+ trigger<TEventPropName extends EventNamesForProps<TProps>>(eventPropName: TEventPropName, eventArg?: TProps[TEventPropName]): void;
163
+ }
164
+ /**
165
+ * Represents a text node of a rendered component.
166
+ *
167
+ * NOTE: Rendered text nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
168
+ */
169
+ export interface RenderedTextNode {
170
+ /**
171
+ * The type of the node (always `RenderedNodeType.Text` for a text node).
172
+ */
173
+ nodeType: RenderedNodeType.Text;
174
+ /**
175
+ * The text content of the text node.
176
+ */
177
+ text: string;
178
+ /**
179
+ * Returns a string representation of the text node.
180
+ */
181
+ toString: () => string;
182
+ }
183
+ /**
184
+ * Represents a child node of a parent node.
185
+ *
186
+ * NOTE: Rendered child nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
187
+ */
188
+ export type RenderedChildNode = RenderedElementNode<UnknownComponentProps> | RenderedTextNode;
189
+ /**
190
+ * Represents a parent node of a rendered component.
191
+ *
192
+ * NOTE: Rendered parent nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
193
+ */
194
+ export type RenderedParentNode = RenderedElementNode<UnknownComponentProps> | RenderedRootNode | RenderedFragmentNode;
195
+ /**
196
+ * A predicate that matches an element node.
197
+ *
198
+ * @param node The node to match.
199
+ * @returns Whether the node matches the predicate.
200
+ */
201
+ export type ElementMatcherPredicate<TProps extends UnknownComponentProps> = (node: RenderedElementNode<TProps>) => boolean;
202
+ /**
203
+ * A matcher that matches an element node based on either a predicate or a partial set of properties.
204
+ */
205
+ export type ElementMatcher<TProps extends UnknownComponentProps> = ElementMatcherPredicate<TProps> | Partial<TProps>;
206
+ /**
207
+ * Options for the waitFor function.
208
+ */
209
+ export interface WaitForOptions {
210
+ /**
211
+ * The timeout in milliseconds. Defaults to 1000.
212
+ */
213
+ timeoutInMs?: number;
214
+ }
215
+ /**
216
+ * A result of a render operation.
217
+ */
218
+ export interface RenderResult extends CommonQueryMethods {
219
+ /**
220
+ * Waits for the given check to pass. If the check does not pass within the allowed amount of time, an error will be thrown.
221
+ *
222
+ * @param check The check to wait for.
223
+ * @returns A promise that resolves when the check passes.
224
+ */
225
+ waitFor: (check: () => void, options?: WaitForOptions) => Promise<void>;
226
+ /**
227
+ * Logs a string representation of the rendered output as a console log.
228
+ *
229
+ * @param label The label to log.
230
+ */
231
+ debugLog: (label?: string) => void;
232
+ /**
233
+ * Returns the root node.
234
+ *
235
+ * @returns The root node.
236
+ */
237
+ getRootNode: () => RenderedRootNode;
238
+ }
239
+ export type RenderedNode = RenderedElementNode<any> | RenderedRootNode | RenderedFragmentNode | RenderedTextNode;
240
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The type of a rendered node.
3
+ */
4
+ export var RenderedNodeType;
5
+ (function (RenderedNodeType) {
6
+ RenderedNodeType["Root"] = "root";
7
+ RenderedNodeType["Fragment"] = "fragment";
8
+ RenderedNodeType["Element"] = "element";
9
+ RenderedNodeType["Text"] = "text";
10
+ })(RenderedNodeType || (RenderedNodeType = {}));