@open-pioneer/test-utils 2.4.0-dev.20241120092632 → 3.0.0-dev.20250221111321

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.
package/CHANGELOG.md CHANGED
@@ -1,171 +1,191 @@
1
1
  # @open-pioneer/test-utils
2
2
 
3
- ## 2.4.0-dev.20241120092632
3
+ ## 3.0.0-dev.20250221111321
4
+
5
+ ### Major Changes
6
+
7
+ - 9477e54: Update dependencies
8
+
9
+ - React 19
10
+ - Vite 6
11
+ - FormatJS 3
12
+ - Open Pioneer Build Tools
13
+ - ...
14
+
15
+ For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [9477e54]
20
+ - @open-pioneer/chakra-integration@3.0.0-dev.20250221111321
21
+ - @open-pioneer/runtime-react-support@3.0.0-dev.20250221111321
22
+
23
+ ## 2.4.0
4
24
 
5
25
  ### Patch Changes
6
26
 
7
- - 1b63ebe: Update dependencies
8
- - Updated dependencies [1b63ebe]
9
- - @open-pioneer/chakra-integration@2.4.0-dev.20241120092632
10
- - @open-pioneer/runtime-react-support@2.4.0-dev.20241120092632
27
+ - 1b63ebe: Update dependencies
28
+ - Updated dependencies [1b63ebe]
29
+ - @open-pioneer/chakra-integration@2.4.0
30
+ - @open-pioneer/runtime-react-support@2.4.0
11
31
 
12
32
  ## 2.3.0
13
33
 
14
34
  ### Minor Changes
15
35
 
16
- - 2fbaaa0: Use normal `dependencies` instead of `peerDependencies`. Peer dependencies have some usability issues (and bugs) when used at scale.
36
+ - 2fbaaa0: Use normal `dependencies` instead of `peerDependencies`. Peer dependencies have some usability issues (and bugs) when used at scale.
17
37
 
18
38
  ### Patch Changes
19
39
 
20
- - Updated dependencies [2fbaaa0]
21
- - @open-pioneer/runtime-react-support@2.3.0
22
- - @open-pioneer/chakra-integration@2.3.0
40
+ - Updated dependencies [2fbaaa0]
41
+ - @open-pioneer/runtime-react-support@2.3.0
42
+ - @open-pioneer/chakra-integration@2.3.0
23
43
 
24
44
  ## 2.2.0
25
45
 
26
46
  ### Patch Changes
27
47
 
28
- - 39dad46: Switch to a new versioning strategy.
29
- From now on, packages released by this repository share a common version number.
30
- - Updated dependencies [39dad46]
31
- - @open-pioneer/chakra-integration@2.2.0
32
- - @open-pioneer/runtime-react-support@2.2.0
48
+ - 39dad46: Switch to a new versioning strategy.
49
+ From now on, packages released by this repository share a common version number.
50
+ - Updated dependencies [39dad46]
51
+ - @open-pioneer/chakra-integration@2.2.0
52
+ - @open-pioneer/runtime-react-support@2.2.0
33
53
 
34
54
  ## 1.1.4
35
55
 
36
56
  ### Patch Changes
37
57
 
38
- - e0b2fae: Update dependencies
39
- - Updated dependencies [5c62522]
40
- - Updated dependencies [e0b2fae]
41
- - @open-pioneer/chakra-integration@1.1.4
42
- - @open-pioneer/runtime-react-support@1.0.2
58
+ - e0b2fae: Update dependencies
59
+ - Updated dependencies [5c62522]
60
+ - Updated dependencies [e0b2fae]
61
+ - @open-pioneer/chakra-integration@1.1.4
62
+ - @open-pioneer/runtime-react-support@1.0.2
43
63
 
44
64
  ## 1.1.3
45
65
 
46
66
  ### Patch Changes
47
67
 
48
- - 64645aa: Update to react 18.3
49
- - b3c60f2: Harmonize naming of Open Pioneer Trails in READMEs and package.json files.
50
- - Updated dependencies [64645aa]
51
- - Updated dependencies [64645aa]
52
- - Updated dependencies [b3c60f2]
53
- - @open-pioneer/runtime-react-support@1.0.2
54
- - @open-pioneer/chakra-integration@1.1.3
68
+ - 64645aa: Update to react 18.3
69
+ - b3c60f2: Harmonize naming of Open Pioneer Trails in READMEs and package.json files.
70
+ - Updated dependencies [64645aa]
71
+ - Updated dependencies [64645aa]
72
+ - Updated dependencies [b3c60f2]
73
+ - @open-pioneer/runtime-react-support@1.0.2
74
+ - @open-pioneer/chakra-integration@1.1.3
55
75
 
56
76
  ## 1.1.2
57
77
 
58
78
  ### Patch Changes
59
79
 
60
- - 5ff8f30: Update package.json metadata.
61
- - Updated dependencies [5ff8f30]
62
- - @open-pioneer/runtime-react-support@1.0.1
63
- - @open-pioneer/chakra-integration@1.1.2
80
+ - 5ff8f30: Update package.json metadata.
81
+ - Updated dependencies [5ff8f30]
82
+ - @open-pioneer/runtime-react-support@1.0.1
83
+ - @open-pioneer/chakra-integration@1.1.2
64
84
 
65
85
  ## 1.1.1
66
86
 
67
87
  ### Patch Changes
68
88
 
69
- - b617e3b: Fix typo in readme
89
+ - b617e3b: Fix typo in readme
70
90
 
71
91
  ## 1.1.0
72
92
 
73
93
  ### Minor Changes
74
94
 
75
- - 2d5a94a: Provide `createIntl` from `@open-pioneer/test-utils/vanilla` to make creation of a `PackageIntl` instance easier.
95
+ - 2d5a94a: Provide `createIntl` from `@open-pioneer/test-utils/vanilla` to make creation of a `PackageIntl` instance easier.
76
96
 
77
97
  ### Patch Changes
78
98
 
79
- - @open-pioneer/runtime-react-support@1.0.0
99
+ - @open-pioneer/runtime-react-support@1.0.0
80
100
 
81
101
  ## 1.0.2
82
102
 
83
103
  ### Patch Changes
84
104
 
85
- - f5c0e31: Bump @formatjs/intl version
86
- - f5c0e31: Bump @testing-library/\* dependencies
87
- - Updated dependencies [f5c0e31]
88
- - @open-pioneer/chakra-integration@1.1.1
89
- - @open-pioneer/runtime-react-support@1.0.0
105
+ - f5c0e31: Bump @formatjs/intl version
106
+ - f5c0e31: Bump @testing-library/\* dependencies
107
+ - Updated dependencies [f5c0e31]
108
+ - @open-pioneer/chakra-integration@1.1.1
109
+ - @open-pioneer/runtime-react-support@1.0.0
90
110
 
91
111
  ## 1.0.1
92
112
 
93
113
  ### Patch Changes
94
114
 
95
- - Updated dependencies [6632892]
96
- - @open-pioneer/chakra-integration@1.1.0
97
- - @open-pioneer/runtime-react-support@1.0.0
115
+ - Updated dependencies [6632892]
116
+ - @open-pioneer/chakra-integration@1.1.0
117
+ - @open-pioneer/runtime-react-support@1.0.0
98
118
 
99
119
  ## 1.0.0
100
120
 
101
121
  ### Major Changes
102
122
 
103
- - 22ff68a: Initial release
123
+ - 22ff68a: Initial release
104
124
 
105
125
  ### Patch Changes
106
126
 
107
- - Updated dependencies [22ff68a]
108
- - @open-pioneer/chakra-integration@1.0.0
109
- - @open-pioneer/runtime-react-support@1.0.0
127
+ - Updated dependencies [22ff68a]
128
+ - @open-pioneer/chakra-integration@1.0.0
129
+ - @open-pioneer/runtime-react-support@1.0.0
110
130
 
111
131
  ## 0.1.6
112
132
 
113
133
  ### Patch Changes
114
134
 
115
- - 9eac5c9: Use peer dependencies for (most) dependencies
116
- - Updated dependencies [9eac5c9]
117
- - @open-pioneer/runtime-react-support@0.1.2
118
- - @open-pioneer/chakra-integration@0.1.4
135
+ - 9eac5c9: Use peer dependencies for (most) dependencies
136
+ - Updated dependencies [9eac5c9]
137
+ - @open-pioneer/runtime-react-support@0.1.2
138
+ - @open-pioneer/chakra-integration@0.1.4
119
139
 
120
140
  ## 0.1.5
121
141
 
122
142
  ### Patch Changes
123
143
 
124
- - 5e08907: Don't show MISSING_TRANSLATION errors when testing components or services.
144
+ - 5e08907: Don't show MISSING_TRANSLATION errors when testing components or services.
125
145
 
126
146
  ## 0.1.4
127
147
 
128
148
  ### Patch Changes
129
149
 
130
- - 49ba4e1: Use build-package CLI to build.
131
- - Updated dependencies [49ba4e1]
132
- - @open-pioneer/chakra-integration@0.1.3
133
- - @open-pioneer/runtime-react-support@0.1.1
150
+ - 49ba4e1: Use build-package CLI to build.
151
+ - Updated dependencies [49ba4e1]
152
+ - @open-pioneer/chakra-integration@0.1.3
153
+ - @open-pioneer/runtime-react-support@0.1.1
134
154
 
135
155
  ## 0.1.3
136
156
 
137
157
  ### Patch Changes
138
158
 
139
- - e752d49: Use new runtime-react-support package
140
- - Updated dependencies [e752d49]
141
- - @open-pioneer/runtime-react-support@0.1.0
159
+ - e752d49: Use new runtime-react-support package
160
+ - Updated dependencies [e752d49]
161
+ - @open-pioneer/runtime-react-support@0.1.0
142
162
 
143
163
  ## 0.1.2
144
164
 
145
165
  ### Patch Changes
146
166
 
147
- - a40f12d: Update build-package tool. TypeScript declaration files should now be available.
148
- - Updated dependencies [a40f12d]
149
- - @open-pioneer/chakra-integration@0.1.2
150
- - @open-pioneer/runtime@0.1.2
167
+ - a40f12d: Update build-package tool. TypeScript declaration files should now be available.
168
+ - Updated dependencies [a40f12d]
169
+ - @open-pioneer/chakra-integration@0.1.2
170
+ - @open-pioneer/runtime@0.1.2
151
171
 
152
172
  ## 0.1.1
153
173
 
154
174
  ### Patch Changes
155
175
 
156
- - e1c7295: Compiled with build-package 0.5.2
157
- - Updated dependencies [e1c7295]
158
- - @open-pioneer/chakra-integration@0.1.1
159
- - @open-pioneer/runtime@0.1.1
176
+ - e1c7295: Compiled with build-package 0.5.2
177
+ - Updated dependencies [e1c7295]
178
+ - @open-pioneer/chakra-integration@0.1.1
179
+ - @open-pioneer/runtime@0.1.1
160
180
 
161
181
  ## 0.1.0
162
182
 
163
183
  ### Minor Changes
164
184
 
165
- - 77f7d5c: Initial test release
185
+ - 77f7d5c: Initial test release
166
186
 
167
187
  ### Patch Changes
168
188
 
169
- - Updated dependencies [77f7d5c]
170
- - @open-pioneer/chakra-integration@0.1.0
171
- - @open-pioneer/runtime@0.1.0
189
+ - Updated dependencies [77f7d5c]
190
+ - @open-pioneer/chakra-integration@0.1.0
191
+ - @open-pioneer/runtime@0.1.0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/test-utils",
4
- "version": "2.4.0-dev.20241120092632",
4
+ "version": "3.0.0-dev.20250221111321",
5
5
  "description": "Contains test utilities that make it easier to test parts of an Open Pioneer Trails application.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -14,13 +14,13 @@
14
14
  "directory": "src/packages/test-utils"
15
15
  },
16
16
  "dependencies": {
17
- "@testing-library/react": "^16.0.1",
18
- "react": "^18.3.1",
19
- "react-dom": "^18.3.1",
17
+ "@testing-library/react": "^16.2.0",
18
+ "react": "^19.0.0",
19
+ "react-dom": "^19.0.0",
20
20
  "@testing-library/dom": "^10.4.0",
21
- "@formatjs/intl": "^2.10.8",
22
- "@open-pioneer/runtime-react-support": "^2.4.0-dev.20241120092632",
23
- "@open-pioneer/chakra-integration": "^2.4.0-dev.20241120092632"
21
+ "@formatjs/intl": "^3.1.4",
22
+ "@open-pioneer/runtime-react-support": "^3.0.0-dev.20250221111321",
23
+ "@open-pioneer/chakra-integration": "^3.0.0-dev.20250221111321"
24
24
  },
25
25
  "exports": {
26
26
  "./package.json": "./package.json",
package/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","sources":["react.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { CustomChakraProvider } from \"@open-pioneer/chakra-integration\";\nimport type { PackageIntl, Service } from \"@open-pioneer/runtime\";\nimport {\n PackageContext as InternalPackageContext,\n PackageContextMethods\n} from \"@open-pioneer/runtime-react-support\";\nimport { FC, ReactNode, useMemo } from \"react\";\nimport { createIntl } from \"./vanilla\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyService = Service<any>;\n\nexport interface PackageContextProviderProps {\n /** Interface implementations, keyed by interface name. */\n services?: {\n [interfaceName: string]: AnyService;\n };\n\n /** Interface implementations, keyed by interface name and then by qualifier. */\n qualifiedServices?: {\n [interfaceName: string]: {\n [qualifier: string]: AnyService;\n };\n };\n\n /** Package properties (keyed by package name). */\n properties?: {\n [packageName: string]: Record<string, unknown>;\n };\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * I18n messages for packages\n */\n messages?: {\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n [packageName: string]: Record<string, string>;\n };\n\n /** Children to render */\n children?: ReactNode;\n}\n\n/**\n * Injects services and properties into the component tree.\n * React components using Open Pioneer Trails hooks like `useService` and `useProperties`\n * will receive the mocked properties here instead.\n * Currently also wrapped with the CustomChakraProvider to support chakra-ui elements\n */\nexport const PackageContextProvider: FC<PackageContextProviderProps> = (props) => {\n const { children, ...rest } = props;\n const contextMethods = useMemo(() => createPackageContextMethods(rest), [rest]);\n return (\n <CustomChakraProvider container={document.body}>\n <InternalPackageContext.Provider value={contextMethods}>\n {children}\n </InternalPackageContext.Provider>\n </CustomChakraProvider>\n );\n};\n\nfunction createPackageContextMethods(\n options: Omit<PackageContextProviderProps, \"children\">\n): PackageContextMethods {\n const services = options?.services ?? {};\n const qualifiedServices = options?.qualifiedServices ?? {};\n const properties = options?.properties ?? {};\n const locale = options?.locale ?? \"en\";\n const messages = options?.messages ?? {};\n const cachedIntl: Record<string, PackageIntl> = {};\n return {\n getService(packageName, interfaceName, options) {\n if (!options.qualifier) {\n const service = services[interfaceName];\n if (service) {\n return service;\n }\n const qualified = qualifiedServices[interfaceName];\n if (qualified) {\n for (const value of Object.values(qualified)) {\n return value; // Return any implementation\n }\n }\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}'. Update the configuration of PackageContextProvider.`\n );\n }\n\n const qualifiedService = qualifiedServices[interfaceName]?.[options.qualifier];\n if (!qualifiedService) {\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}' (qualifier '${options.qualifier}'). Update the configuration of PackageContextProvider.`\n );\n }\n return qualifiedService;\n },\n getServices(packageName, interfaceName) {\n const unqualified = services[interfaceName];\n const results = Object.values(qualifiedServices[interfaceName] ?? {});\n if (unqualified) {\n results.push(unqualified);\n }\n return results;\n },\n getProperties(packageName) {\n const packageProperties = properties[packageName];\n if (!packageProperties) {\n throw new Error(\n `No properties for package '${packageName}' bound for testing. Update the configuration of PackageContextProvider.`\n );\n }\n return packageProperties;\n },\n getIntl(packageName) {\n const initIntl = () => {\n const packageMessages = messages[packageName];\n return createIntl({\n locale,\n messages: packageMessages\n });\n };\n return (cachedIntl[packageName] ??= initIntl());\n }\n };\n}\n"],"names":["InternalPackageContext","options"],"mapp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C,QAAA,OAAO,UAAW,CAAA;AAAA,UACd,MAAA;AAAA,UACA,QAAU,EAAA,eAAA;AAAA,SACb,CAAA,CAAA;AAAA,OACL,CAAA;AACA,MAAQ,OAAA,UAAA,CAAW,WAAW,CAAA,KAAM,QAAS,EAAA,CAAA;AAAA,KACjD;AAAA,GACJ,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"react.js","sources":["react.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { CustomChakraProvider } from \"@open-pioneer/chakra-integration\";\nimport type { PackageIntl, Service } from \"@open-pioneer/runtime\";\nimport {\n PackageContext as InternalPackageContext,\n PackageContextMethods\n} from \"@open-pioneer/runtime-react-support\";\nimport { FC, ReactNode, useMemo } from \"react\";\nimport { createIntl } from \"./vanilla\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyService = Service<any>;\n\nexport interface PackageContextProviderProps {\n /** Interface implementations, keyed by interface name. */\n services?: {\n [interfaceName: string]: AnyService;\n };\n\n /** Interface implementations, keyed by interface name and then by qualifier. */\n qualifiedServices?: {\n [interfaceName: string]: {\n [qualifier: string]: AnyService;\n };\n };\n\n /** Package properties (keyed by package name). */\n properties?: {\n [packageName: string]: Record<string, unknown>;\n };\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * I18n messages for packages\n */\n messages?: {\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n [packageName: string]: Record<string, string>;\n };\n\n /** Children to render */\n children?: ReactNode;\n}\n\n/**\n * Injects services and properties into the component tree.\n * React components using Open Pioneer Trails hooks like `useService` and `useProperties`\n * will receive the mocked properties here instead.\n * Currently also wrapped with the CustomChakraProvider to support chakra-ui elements\n */\nexport const PackageContextProvider: FC<PackageContextProviderProps> = (props) => {\n const { children, ...rest } = props;\n const contextMethods = useMemo(() => createPackageContextMethods(rest), [rest]);\n return (\n <CustomChakraProvider container={document.body}>\n <InternalPackageContext.Provider value={contextMethods}>\n {children}\n </InternalPackageContext.Provider>\n </CustomChakraProvider>\n );\n};\n\nfunction createPackageContextMethods(\n options: Omit<PackageContextProviderProps, \"children\">\n): PackageContextMethods {\n const services = options?.services ?? {};\n const qualifiedServices = options?.qualifiedServices ?? {};\n const properties = options?.properties ?? {};\n const locale = options?.locale ?? \"en\";\n const messages = options?.messages ?? {};\n const cachedIntl: Record<string, PackageIntl> = {};\n return {\n getService(packageName, interfaceName, options) {\n if (!options.qualifier) {\n const service = services[interfaceName];\n if (service) {\n return service;\n }\n const qualified = qualifiedServices[interfaceName];\n if (qualified) {\n for (const value of Object.values(qualified)) {\n return value; // Return any implementation\n }\n }\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}'. Update the configuration of PackageContextProvider.`\n );\n }\n\n const qualifiedService = qualifiedServices[interfaceName]?.[options.qualifier];\n if (!qualifiedService) {\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}' (qualifier '${options.qualifier}'). Update the configuration of PackageContextProvider.`\n );\n }\n return qualifiedService;\n },\n getServices(packageName, interfaceName) {\n const unqualified = services[interfaceName];\n const results = Object.values(qualifiedServices[interfaceName] ?? {});\n if (unqualified) {\n results.push(unqualified);\n }\n return results;\n },\n getProperties(packageName) {\n const packageProperties = properties[packageName];\n if (!packageProperties) {\n throw new Error(\n `No properties for package '${packageName}' bound for testing. Update the configuration of PackageContextProvider.`\n );\n }\n return packageProperties;\n },\n getIntl(packageName) {\n const initIntl = () => {\n const packageMessages = messages[packageName];\n return createIntl({\n locale,\n messages: packageMessages\n });\n };\n return (cachedIntl[packageName] ??= initIntl());\n }\n };\n}\n"],"names":["InternalPackageContext","options"],"mappings":";;;;;;AA6Da,MAAA,sBAAA,GAA0D,CAAC,KAAU,KAAA;AAC9E,EAAA,MAAM,EAAE,QAAA,EAAU,GAAG,IAAA,EAAS,GAAA,KAAA;AAC9B,EAAM,MAAA,cAAA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SAAS,CAAA;AAC7E,MAAA,IAAI,CAAC,gBAAkB,EAAA;AACnB,QAAA,MAAM,IAAI,KAAA;AAAA,UACN,CAA0C,uCAAA,EAAA,aAAa,CAAiBA,cAAAA,EAAAA,QAAAA,CAAQ,SAAS,CAAA,uDAAA;AAAA,SAC7F;AAAA;AAEJ,MAAO,OAAA,gBAAA;AAAA,KACX;AAAA,IACA,WAAA,CAAY,aAAa,aAAe,EAAA;AACpC,MAAM,MAAA,WAAA,GAAc,SAAS,aAAa,CAAA;AAC1C,MAAA,MAAM,UAAU,MAAO,CAAA,MAAA,CAAO,kBAAkB,aAAa,CAAA,IAAK,EAAE,CAAA;AACpE,MAAA,IAAI,WAAa,EAAA;AACb,QAAA,OAAA,CAAQ,KAAK,WAAW,CAAA;AAAA;AAE5B,MAAO,OAAA,OAAA;AAAA,KACX;AAAA,IACA,cAAc,WAAa,EAAA;AACvB,MAAM,MAAA,iBAAA,GAAoB,WAAW,WAAW,CAAA;AAChD,MAAA,IAAI,CAAC,iBAAmB,EAAA;AACpB,QAAA,MAAM,IAAI,KAAA;AAAA,UACN,8BAA8B,WAAW,CAAA,wEAAA;AAAA,SAC7C;AAAA;AAEJ,MAAO,OAAA,iBAAA;AAAA,KACX;AAAA,IACA,QAAQ,WAAa,EAAA;AACjB,MAAA,MAAM,WAAW,MAAM;AACnB,QAAM,MAAA,eAAA,GAAkB,SAAS,WAAW,CAAA;AAC5C,QAAA,OAAO,UAAW,CAAA;AAAA,UACd,MAAA;AAAA,UACA,QAAU,EAAA;AAAA,SACb,CAAA;AAAA,OACL;AACA,MAAQ,OAAA,UAAA,CAAW,WAAW,CAAA,KAAM,QAAS,EAAA;AAAA;AACjD,GACJ;AACJ;;;;"}
package/services.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReferenceMeta, Service, ServiceConstructor } from \"@open-pioneer/runtime\";\nimport { createIntl } from \"./vanilla\";\n\n/**\n * Options for the {@link createService} function.\n */\nexport interface CreateServiceOptions<References> {\n /**\n * References provided to the service constructor.\n *\n * @default {}\n */\n references?: PartialServiceReferences<References>;\n\n /**\n * Properties provided to the service constructor.\n *\n * @default {}\n */\n properties?: Record<string, unknown>;\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\ntype PartialServiceReferences<References> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]?: References[referenceName] extends any[]\n ? Partial<References[referenceName][number]>[]\n : Partial<References[referenceName]>;\n};\n\n/**\n * Creates a new service instance of `clazz`.\n *\n * The options passed into the constructor of `clazz` are taking from the `options` parameter.\n *\n * This function allows the user to define mock- or test objects as service references.\n *\n * Most type-checking features are disabled for convenience, but by default this function's types\n * enforce that a value provided for a reference must match the partial interface of the actually required type.\n *\n * For example, if a service depends on `{ ctx: ApplicationContext }`, this function ensures\n * that the test value for `ctx` implements `Partial<ApplicationContext>`.\n * This can of course be disabled by casting the value explicitly.\n *\n * @param clazz a service class\n * @param options options passed to the service constructor\n * @returns a new instance of the given service class\n */\nexport async function createService<References extends {}, Interface extends {}>(\n clazz: ServiceConstructor<References, Interface>,\n options?: CreateServiceOptions<References>\n): Promise<Service<Interface>> {\n const references = options?.references ?? {};\n const referencesMeta = Object.fromEntries(\n Object.entries(references).map(([referenceName, reference]) => [\n referenceName,\n referenceMeta(referenceName, reference)\n ])\n );\n\n const intl = createIntl(options);\n return new clazz({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n references: references as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n referencesMeta: referencesMeta as any,\n properties: options?.properties ?? {},\n intl\n });\n}\n\nfunction referenceMeta(referenceName: string, reference: unknown): ReferenceMeta | ReferenceMeta[] {\n if (Array.isArray(reference)) {\n return reference.map<ReferenceMeta>((_, index) => ({\n serviceId: `test-utils::${referenceName}-${index}`\n }));\n }\n return {\n serviceId: `test-utils::${referenceName}`\n };\n}\n"],"names":[],"mappings":";;AAwEsB,eAAA,aAAA,CAClB,OACA,OAC2B,EAAA;AAC3B,EAAM,MAAA,UAAA,GAAa,OAAS,EAAA,UAAA,IAAc,EAAC,CAAA;AAC3C,EAAA,MAAM,iBAAiB,MAAO,CAAA,WAAA;AAAA,IAC1B,MAAA,CAAO,QAAQ,UAAU,CAAA,CAAE,IAAI,CAAC,CAAC,aAAe,EAAA,SAAS,CAAM,KAAA;AAAA,MAC3D,aAAA;AAAA,MACA,aAAA,CAAc,eAAe,SAAS,CAAA;AAAA,KACzC,CAAA;AAAA,GACL,CAAA;AAEA,EAAM,MAAA,IAAA,GAAO,WAAW,OAAO,CAAA,CAAA;AAC/B,EAAA,OAAO,IAAI,KAAM,CAAA;AAAA;AAAA,IAEb,UAAA;AAAA;AAAA,IAEA,cAAA;AAAA,IACA,UAAA,EAAY,OAAS,EAAA,UAAA,IAAc,EAAC;AAAA,IACpC,IAAA;AAAA,GACH,CAAA,CAAA;AACL,CAAA;AAEA,SAAS,aAAA,CAAc,eAAuB,SAAqD,EAAA;AAC/F,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,SAAS,CAAG,EAAA;AAC1B,IAAA,OAAO,SAAU,CAAA,GAAA,CAAmB,CAAC,CAAA,EAAG,KAAW,MAAA;AAAA,MAC/C,SAAW,EAAA,CAAA,YAAA,EAAe,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAAA,KAClD,CAAA,CAAA,CAAA;AAAA,GACN;AACA,EAAO,OAAA;AAAA,IACH,SAAA,EAAW,eAAe,aAAa,CAAA,CAAA;AAAA,GAC3C,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReferenceMeta, Service, ServiceConstructor } from \"@open-pioneer/runtime\";\nimport { createIntl } from \"./vanilla\";\n\n/**\n * Options for the {@link createService} function.\n */\nexport interface CreateServiceOptions<References> {\n /**\n * References provided to the service constructor.\n *\n * @default {}\n */\n references?: PartialServiceReferences<References>;\n\n /**\n * Properties provided to the service constructor.\n *\n * @default {}\n */\n properties?: Record<string, unknown>;\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\ntype PartialServiceReferences<References> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]?: References[referenceName] extends any[]\n ? Partial<References[referenceName][number]>[]\n : Partial<References[referenceName]>;\n};\n\n/**\n * Creates a new service instance of `clazz`.\n *\n * The options passed into the constructor of `clazz` are taking from the `options` parameter.\n *\n * This function allows the user to define mock- or test objects as service references.\n *\n * Most type-checking features are disabled for convenience, but by default this function's types\n * enforce that a value provided for a reference must match the partial interface of the actually required type.\n *\n * For example, if a service depends on `{ ctx: ApplicationContext }`, this function ensures\n * that the test value for `ctx` implements `Partial<ApplicationContext>`.\n * This can of course be disabled by casting the value explicitly.\n *\n * @param clazz a service class\n * @param options options passed to the service constructor\n * @returns a new instance of the given service class\n */\nexport async function createService<References extends {}, Interface extends {}>(\n clazz: ServiceConstructor<References, Interface>,\n options?: CreateServiceOptions<References>\n): Promise<Service<Interface>> {\n const references = options?.references ?? {};\n const referencesMeta = Object.fromEntries(\n Object.entries(references).map(([referenceName, reference]) => [\n referenceName,\n referenceMeta(referenceName, reference)\n ])\n );\n\n const intl = createIntl(options);\n return new clazz({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n references: references as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n referencesMeta: referencesMeta as any,\n properties: options?.properties ?? {},\n intl\n });\n}\n\nfunction referenceMeta(referenceName: string, reference: unknown): ReferenceMeta | ReferenceMeta[] {\n if (Array.isArray(reference)) {\n return reference.map<ReferenceMeta>((_, index) => ({\n serviceId: `test-utils::${referenceName}-${index}`\n }));\n }\n return {\n serviceId: `test-utils::${referenceName}`\n };\n}\n"],"names":[],"mappings":";;AAwEsB,eAAA,aAAA,CAClB,OACA,OAC2B,EAAA;AAC3B,EAAM,MAAA,UAAA,GAAa,OAAS,EAAA,UAAA,IAAc,EAAC;AAC3C,EAAA,MAAM,iBAAiB,MAAO,CAAA,WAAA;AAAA,IAC1B,MAAA,CAAO,QAAQ,UAAU,CAAA,CAAE,IAAI,CAAC,CAAC,aAAe,EAAA,SAAS,CAAM,KAAA;AAAA,MAC3D,aAAA;AAAA,MACA,aAAA,CAAc,eAAe,SAAS;AAAA,KACzC;AAAA,GACL;AAEA,EAAM,MAAA,IAAA,GAAO,WAAW,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,KAAM,CAAA;AAAA;AAAA,IAEb,UAAA;AAAA;AAAA,IAEA,cAAA;AAAA,IACA,UAAA,EAAY,OAAS,EAAA,UAAA,IAAc,EAAC;AAAA,IACpC;AAAA,GACH,CAAA;AACL;AAEA,SAAS,aAAA,CAAc,eAAuB,SAAqD,EAAA;AAC/F,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,SAAS,CAAG,EAAA;AAC1B,IAAA,OAAO,SAAU,CAAA,GAAA,CAAmB,CAAC,CAAA,EAAG,KAAW,MAAA;AAAA,MAC/C,SAAW,EAAA,CAAA,YAAA,EAAe,aAAa,CAAA,CAAA,EAAI,KAAK,CAAA;AAAA,KAClD,CAAA,CAAA;AAAA;AAEN,EAAO,OAAA;AAAA,IACH,SAAA,EAAW,eAAe,aAAa,CAAA;AAAA,GAC3C;AACJ;;;;"}
package/vanilla.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vanilla.js","sources":["vanilla.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n createIntlCache,\n createIntl as createFormatJsIntl,\n IntlErrorCode,\n OnErrorFn\n} from \"@formatjs/intl\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\n\n/** Options for `createIntl`. */\nexport interface I18nOptions {\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages (e.g. `defaultMessage` property in `intl.formatMessage(...)`).\n * It is usually not necessary to specify this option.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\n/**\n * Creates an `intl` instance that can be used for testing.\n *\n * Other than the default implementation provided by `@formatjs/intl`, this\n * `intl` object will not warn if a message is not defined.\n * Instead, it will simply render the fallback message.\n * This behavior makes testing easier.\n *\n * Note that messages can still be defined by using the `messages` parameter.\n */\nexport function createIntl(options?: I18nOptions): PackageIntl {\n const messages = options?.messages ?? {};\n const locale = options?.locale ?? \"en\";\n const defaultMessageLocale = options?.defaultMessageLocale ?? \"en\";\n const cache = createIntlCache();\n const intl = createFormatJsIntl(\n {\n locale,\n defaultLocale: defaultMessageLocale,\n messages,\n onError: INTL_ERROR_HANDLER\n },\n cache\n );\n return intl;\n}\n\n/** Hides missing translation errors during tests */\nconst INTL_ERROR_HANDLER: OnErrorFn = (err) => {\n if (err.code === IntlErrorCode.MISSING_TRANSLATION) {\n return;\n }\n\n console.error(err);\n};\n"],"names":["createFormatJsIntl"],"mappings":";;AA+CO,SAAS,WAAW,OAAoC,EAAA;AAC3D,EAAM,MAAA,QAAA,GAAW,OAAS,EAAA,QAAA,IAAY,EAAC,CAAA;AACvC,EAAM,MAAA,MAAA,GAAS,SAAS,MAAU,IAAA,IAAA,CAAA;AAClC,EAAM,MAAA,oBAAA,GAAuB,SAAS,oBAAwB,IAAA,IAAA,CAAA;AAC9D,EAAA,MAAM,QAAQ,eAAgB,EAAA,CAAA;AAC9B,EAAA,MAAM,IAAO,GAAAA,YAAA;AAAA,IACT;AAAA,MACI,MAAA;AAAA,MACA,aAAe,EAAA,oBAAA;AAAA,MACf,QAAA;AAAA,MACA,OAAS,EAAA,kBAAA;AAAA,KACb;AAAA,IACA,KAAA;AAAA,GACJ,CAAA;AACA,EAAO,OAAA,IAAA,CAAA;AACX,CAAA;AAGA,MAAM,kBAAA,GAAgC,CAAC,GAAQ,KAAA;AAC3C,EAAI,IAAA,GAAA,CAAI,IAAS,KAAA,aAAA,CAAc,mBAAqB,EAAA;AAChD,IAAA,OAAA;AAAA,GACJ;AAEA,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA,CAAA;AACrB,CAAA;;;;"}
1
+ {"version":3,"file":"vanilla.js","sources":["vanilla.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n createIntlCache,\n createIntl as createFormatJsIntl,\n IntlErrorCode,\n OnErrorFn\n} from \"@formatjs/intl\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\n\n/** Options for `createIntl`. */\nexport interface I18nOptions {\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The locale for embedded default messages (e.g. `defaultMessage` property in `intl.formatMessage(...)`).\n * It is usually not necessary to specify this option.\n *\n * See also https://formatjs.io/docs/intl#message-descriptor\n *\n * @default \"en\"\n */\n defaultMessageLocale?: string;\n\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n messages?: Record<string, string>;\n}\n\n/**\n * Creates an `intl` instance that can be used for testing.\n *\n * Other than the default implementation provided by `@formatjs/intl`, this\n * `intl` object will not warn if a message is not defined.\n * Instead, it will simply render the fallback message.\n * This behavior makes testing easier.\n *\n * Note that messages can still be defined by using the `messages` parameter.\n */\nexport function createIntl(options?: I18nOptions): PackageIntl {\n const messages = options?.messages ?? {};\n const locale = options?.locale ?? \"en\";\n const defaultMessageLocale = options?.defaultMessageLocale ?? \"en\";\n const cache = createIntlCache();\n const intl = createFormatJsIntl(\n {\n locale,\n defaultLocale: defaultMessageLocale,\n messages,\n onError: INTL_ERROR_HANDLER\n },\n cache\n );\n return intl;\n}\n\n/** Hides missing translation errors during tests */\nconst INTL_ERROR_HANDLER: OnErrorFn = (err) => {\n if (err.code === IntlErrorCode.MISSING_TRANSLATION) {\n return;\n }\n\n console.error(err);\n};\n"],"names":["createFormatJsIntl"],"mappings":";;AA+CO,SAAS,WAAW,OAAoC,EAAA;AAC3D,EAAM,MAAA,QAAA,GAAW,OAAS,EAAA,QAAA,IAAY,EAAC;AACvC,EAAM,MAAA,MAAA,GAAS,SAAS,MAAU,IAAA,IAAA;AAClC,EAAM,MAAA,oBAAA,GAAuB,SAAS,oBAAwB,IAAA,IAAA;AAC9D,EAAA,MAAM,QAAQ,eAAgB,EAAA;AAC9B,EAAA,MAAM,IAAO,GAAAA,YAAA;AAAA,IACT;AAAA,MACI,MAAA;AAAA,MACA,aAAe,EAAA,oBAAA;AAAA,MACf,QAAA;AAAA,MACA,OAAS,EAAA;AAAA,KACb;AAAA,IACA;AAAA,GACJ;AACA,EAAO,OAAA,IAAA;AACX;AAGA,MAAM,kBAAA,GAAgC,CAAC,GAAQ,KAAA;AAC3C,EAAI,IAAA,GAAA,CAAI,IAAS,KAAA,aAAA,CAAc,mBAAqB,EAAA;AAChD,IAAA;AAAA;AAGJ,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACrB,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"web-components.js","sources":["web-components.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { waitFor, within } from \"@testing-library/dom\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst GLOBAL = global as any;\n\nfunction nextId(): number {\n GLOBAL[\"__WEB_COMPONENT_COUNT__\"] ??= 0;\n const id = (GLOBAL[\"__WEB_COMPONENT_COUNT__\"] += 1);\n return id;\n}\n\n/**\n * Renders the given component into the DOM and returns the new node.\n */\nexport async function renderComponent(\n component: CustomElementConstructor | string,\n options?: {\n container?: HTMLElement;\n attributes?: Record<string, string>;\n }\n) {\n const tag = typeof component === \"string\" ? component : defineComponent(component);\n const container = options?.container ?? document.body;\n const node = container.ownerDocument.createElement(tag);\n for (const [key, value] of Object.entries(options?.attributes ?? {})) {\n node.setAttribute(key, value);\n }\n container.innerHTML = \"\";\n container.appendChild(node);\n return {\n node\n };\n}\n\n/**\n * Renders the given component into the DOM (via {@link renderComponent}) and works on its shadow root.\n * In order to use this function, the shadow root should be attached as `open` from inside the component class.\n *\n * After the shadow root has been accessed, the function searches (and waits) for an inner root container (by default `.pioneer-root`)\n * where all other searches should be executed.\n *\n * Returns the shadow root, the inner container, and a bound queries object that automatically searches in the inner container\n * instead of the whole document.\n */\nexport async function renderComponentShadowDOM(\n component: CustomElementConstructor | string,\n options?: {\n container?: HTMLElement;\n attributes?: Record<string, string>;\n innerContainerSelector?: string;\n }\n) {\n const { node } = await renderComponent(component, options);\n const selector = options?.innerContainerSelector ?? \".pioneer-root\";\n const { shadowRoot, innerContainer } = await waitFor(() => {\n const shadowRoot = node.shadowRoot;\n if (!shadowRoot) {\n throw new Error(\"Shadow root not attached.\");\n }\n const innerContainer = shadowRoot.querySelector<HTMLElement>(selector);\n if (!innerContainer) {\n throw new Error(\"Inner container not ready.\");\n }\n return { shadowRoot, innerContainer };\n });\n\n const queries = within(innerContainer);\n return {\n node,\n shadowRoot,\n innerContainer,\n queries\n };\n}\n\n/**\n * Defines the given component and returns the unique tag name.\n * This helper is necessary because tag names must not collide in the global elements registry (and\n * un-registration is not possible).\n */\nexport function defineComponent(\n component: CustomElementConstructor,\n options?: {\n nameHint?: string;\n }\n) {\n const nameHint = options?.nameHint ?? \"test-component\";\n const tag = `${nameHint}-${nextId()}`;\n customElements.define(tag, component);\n return tag;\n}\n"],"names":["shadowRoot","innerContainer"],"mappings":";;AAKA,MAAM,MAAS,GAAA,MAAA,CAAA;AAEf,SAAS,MAAiB,GAAA;AACtB,EAAA,MAAA,CAAO,yBAAyB,CAAM,KAAA,CAAA,CAAA;AACtC,EAAM,MAAA,EAAA,GAAM,MAAO,CAAA,yBAAyB,CAAK,IAAA,CAAA,CAAA;AACjD,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAKsB,eAAA,eAAA,CAClB,WACA,OAIF,EAAA;AACE,EAAA,MAAM,MAAM,OAAO,SAAA,KAAc,QAAW,GAAA,SAAA,GAAY,gBAAgB,SAAS,CAAA,CAAA;AACjF,EAAM,MAAA,SAAA,GAAY,OAAS,EAAA,SAAA,IAAa,QAAS,CAAA,IAAA,CAAA;AACjD,EAAA,MAAM,IAAO,GAAA,SAAA,CAAU,aAAc,CAAA,aAAA,CAAc,GAAG,CAAA,CAAA;AACtD,EAAW,KAAA,MAAA,CAAC,GAAK,EAAA,KAAK,CAAK,IAAA,MAAA,CAAO,QAAQ,OAAS,EAAA,UAAA,IAAc,EAAE,CAAG,EAAA;AAClE,IAAK,IAAA,CAAA,YAAA,CAAa,KAAK,KAAK,CAAA,CAAA;AAAA,GAChC;AACA,EAAA,SAAA,CAAU,SAAY,GAAA,EAAA,CAAA;AACtB,EAAA,SAAA,CAAU,YAAY,IAAI,CAAA,CAAA;AAC1B,EAAO,OAAA;AAAA,IACH,IAAA;AAAA,GACJ,CAAA;AACJ,CAAA;AAYsB,eAAA,wBAAA,CAClB,WACA,OAKF,EAAA;AACE,EAAA,MAAM,EAAE,IAAK,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,OAAO,CAAA,CAAA;AACzD,EAAM,MAAA,QAAA,GAAW,SAAS,sBAA0B,IAAA,eAAA,CAAA;AACpD,EAAA,MAAM,EAAE,UAAY,EAAA,cAAA,EAAmB,GAAA,MAAM,QAAQ,MAAM;AACvD,IAAA,MAAMA,cAAa,IAAK,CAAA,UAAA,CAAA;AACxB,IAAA,IAAI,CAACA,WAAY,EAAA;AACb,MAAM,MAAA,IAAI,MAAM,2BAA2B,CAAA,CAAA;AAAA,KAC/C;AACA,IAAMC,MAAAA,eAAAA,GAAiBD,WAAW,CAAA,aAAA,CAA2B,QAAQ,CAAA,CAAA;AACrE,IAAA,IAAI,CAACC,eAAgB,EAAA;AACjB,MAAM,MAAA,IAAI,MAAM,4BAA4B,CAAA,CAAA;AAAA,KAChD;AACA,IAAA,OAAO,EAAE,UAAA,EAAAD,WAAY,EAAA,cAAA,EAAAC,eAAe,EAAA,CAAA;AAAA,GACvC,CAAA,CAAA;AAED,EAAM,MAAA,OAAA,GAAU,OAAO,cAAc,CAAA,CAAA;AACrC,EAAO,OAAA;AAAA,IACH,IAAA;AAAA,IACA,UAAA;AAAA,IACA,cAAA;AAAA,IACA,OAAA;AAAA,GACJ,CAAA;AACJ,CAAA;AAOgB,SAAA,eAAA,CACZ,WACA,OAGF,EAAA;AACE,EAAM,MAAA,QAAA,GAAW,SAAS,QAAY,IAAA,gBAAA,CAAA;AACtC,EAAA,MAAM,GAAM,GAAA,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,CAAA;AACnC,EAAe,cAAA,CAAA,MAAA,CAAO,KAAK,SAAS,CAAA,CAAA;AACpC,EAAO,OAAA,GAAA,CAAA;AACX;;;;"}
1
+ {"version":3,"file":"web-components.js","sources":["web-components.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { waitFor, within } from \"@testing-library/dom\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst GLOBAL = global as any;\n\nfunction nextId(): number {\n GLOBAL[\"__WEB_COMPONENT_COUNT__\"] ??= 0;\n const id = (GLOBAL[\"__WEB_COMPONENT_COUNT__\"] += 1);\n return id;\n}\n\n/**\n * Renders the given component into the DOM and returns the new node.\n */\nexport async function renderComponent(\n component: CustomElementConstructor | string,\n options?: {\n container?: HTMLElement;\n attributes?: Record<string, string>;\n }\n) {\n const tag = typeof component === \"string\" ? component : defineComponent(component);\n const container = options?.container ?? document.body;\n const node = container.ownerDocument.createElement(tag);\n for (const [key, value] of Object.entries(options?.attributes ?? {})) {\n node.setAttribute(key, value);\n }\n container.innerHTML = \"\";\n container.appendChild(node);\n return {\n node\n };\n}\n\n/**\n * Renders the given component into the DOM (via {@link renderComponent}) and works on its shadow root.\n * In order to use this function, the shadow root should be attached as `open` from inside the component class.\n *\n * After the shadow root has been accessed, the function searches (and waits) for an inner root container (by default `.pioneer-root`)\n * where all other searches should be executed.\n *\n * Returns the shadow root, the inner container, and a bound queries object that automatically searches in the inner container\n * instead of the whole document.\n */\nexport async function renderComponentShadowDOM(\n component: CustomElementConstructor | string,\n options?: {\n container?: HTMLElement;\n attributes?: Record<string, string>;\n innerContainerSelector?: string;\n }\n) {\n const { node } = await renderComponent(component, options);\n const selector = options?.innerContainerSelector ?? \".pioneer-root\";\n const { shadowRoot, innerContainer } = await waitFor(() => {\n const shadowRoot = node.shadowRoot;\n if (!shadowRoot) {\n throw new Error(\"Shadow root not attached.\");\n }\n const innerContainer = shadowRoot.querySelector<HTMLElement>(selector);\n if (!innerContainer) {\n throw new Error(\"Inner container not ready.\");\n }\n return { shadowRoot, innerContainer };\n });\n\n const queries = within(innerContainer);\n return {\n node,\n shadowRoot,\n innerContainer,\n queries\n };\n}\n\n/**\n * Defines the given component and returns the unique tag name.\n * This helper is necessary because tag names must not collide in the global elements registry (and\n * un-registration is not possible).\n */\nexport function defineComponent(\n component: CustomElementConstructor,\n options?: {\n nameHint?: string;\n }\n) {\n const nameHint = options?.nameHint ?? \"test-component\";\n const tag = `${nameHint}-${nextId()}`;\n customElements.define(tag, component);\n return tag;\n}\n"],"names":["shadowRoot","innerContainer"],"mappings":";;AAKA,MAAM,MAAS,GAAA,MAAA;AAEf,SAAS,MAAiB,GAAA;AACtB,EAAA,MAAA,CAAO,yBAAyB,CAAM,KAAA,CAAA;AACtC,EAAM,MAAA,EAAA,GAAM,MAAO,CAAA,yBAAyB,CAAK,IAAA,CAAA;AACjD,EAAO,OAAA,EAAA;AACX;AAKsB,eAAA,eAAA,CAClB,WACA,OAIF,EAAA;AACE,EAAA,MAAM,MAAM,OAAO,SAAA,KAAc,QAAW,GAAA,SAAA,GAAY,gBAAgB,SAAS,CAAA;AACjF,EAAM,MAAA,SAAA,GAAY,OAAS,EAAA,SAAA,IAAa,QAAS,CAAA,IAAA;AACjD,EAAA,MAAM,IAAO,GAAA,SAAA,CAAU,aAAc,CAAA,aAAA,CAAc,GAAG,CAAA;AACtD,EAAW,KAAA,MAAA,CAAC,GAAK,EAAA,KAAK,CAAK,IAAA,MAAA,CAAO,QAAQ,OAAS,EAAA,UAAA,IAAc,EAAE,CAAG,EAAA;AAClE,IAAK,IAAA,CAAA,YAAA,CAAa,KAAK,KAAK,CAAA;AAAA;AAEhC,EAAA,SAAA,CAAU,SAAY,GAAA,EAAA;AACtB,EAAA,SAAA,CAAU,YAAY,IAAI,CAAA;AAC1B,EAAO,OAAA;AAAA,IACH;AAAA,GACJ;AACJ;AAYsB,eAAA,wBAAA,CAClB,WACA,OAKF,EAAA;AACE,EAAA,MAAM,EAAE,IAAK,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,OAAO,CAAA;AACzD,EAAM,MAAA,QAAA,GAAW,SAAS,sBAA0B,IAAA,eAAA;AACpD,EAAA,MAAM,EAAE,UAAY,EAAA,cAAA,EAAmB,GAAA,MAAM,QAAQ,MAAM;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