@webiny/website-builder-sdk 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0

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 (362) hide show
  1. package/BindingsApi.js +29 -36
  2. package/BindingsApi.js.map +1 -1
  3. package/BindingsProcessor.js +34 -43
  4. package/BindingsProcessor.js.map +1 -1
  5. package/BindingsProcessor.test.js +82 -78
  6. package/BindingsProcessor.test.js.map +1 -1
  7. package/BindingsResolver.d.ts +4 -1
  8. package/BindingsResolver.js +92 -122
  9. package/BindingsResolver.js.map +1 -1
  10. package/BindingsResolver.test.js +399 -363
  11. package/BindingsResolver.test.js.map +1 -1
  12. package/ComponentInputTraverser.js +29 -49
  13. package/ComponentInputTraverser.js.map +1 -1
  14. package/ComponentManifestToAstConverter.d.ts +33 -1
  15. package/ComponentManifestToAstConverter.js +164 -21
  16. package/ComponentManifestToAstConverter.js.map +1 -1
  17. package/ComponentRegistry.d.ts +2 -1
  18. package/ComponentRegistry.js +40 -22
  19. package/ComponentRegistry.js.map +1 -1
  20. package/ComponentResolver.d.ts +6 -3
  21. package/ComponentResolver.js +30 -29
  22. package/ComponentResolver.js.map +1 -1
  23. package/ConstraintEvaluator.d.ts +41 -0
  24. package/ConstraintEvaluator.js +304 -0
  25. package/ConstraintEvaluator.js.map +1 -0
  26. package/ConstraintEvaluator.test.d.ts +1 -0
  27. package/ConstraintEvaluator.test.js +1771 -0
  28. package/ConstraintEvaluator.test.js.map +1 -0
  29. package/ContentSdk.d.ts +80 -4
  30. package/ContentSdk.js +190 -89
  31. package/ContentSdk.js.map +1 -1
  32. package/DocumentStore.d.ts +5 -0
  33. package/DocumentStore.js +49 -59
  34. package/DocumentStore.js.map +1 -1
  35. package/DocumentStore.test.d.ts +1 -0
  36. package/DocumentStore.test.js +126 -0
  37. package/DocumentStore.test.js.map +1 -0
  38. package/DocumentStoreManager.d.ts +9 -2
  39. package/DocumentStoreManager.js +36 -16
  40. package/DocumentStoreManager.js.map +1 -1
  41. package/EditingSdk.d.ts +19 -3
  42. package/EditingSdk.js +112 -121
  43. package/EditingSdk.js.map +1 -1
  44. package/ElementBindings.d.ts +28 -0
  45. package/ElementBindings.js +88 -0
  46. package/ElementBindings.js.map +1 -0
  47. package/ElementBindings.test.d.ts +1 -0
  48. package/ElementBindings.test.js +127 -0
  49. package/ElementBindings.test.js.map +1 -0
  50. package/ElementFactory.d.ts +13 -4
  51. package/ElementFactory.js +170 -164
  52. package/ElementFactory.js.map +1 -1
  53. package/ElementFactory.test.d.ts +1 -0
  54. package/ElementFactory.test.js +511 -0
  55. package/ElementFactory.test.js.map +1 -0
  56. package/ElementSelection.d.ts +20 -0
  57. package/ElementSelection.js +32 -0
  58. package/ElementSelection.js.map +1 -0
  59. package/ElementSelection.test.d.ts +1 -0
  60. package/ElementSelection.test.js +73 -0
  61. package/ElementSelection.test.js.map +1 -0
  62. package/Environment.d.ts +7 -0
  63. package/Environment.js +19 -19
  64. package/Environment.js.map +1 -1
  65. package/Environment.test.d.ts +1 -0
  66. package/Environment.test.js +39 -0
  67. package/Environment.test.js.map +1 -0
  68. package/FunctionConverter.js +8 -7
  69. package/FunctionConverter.js.map +1 -1
  70. package/GlobalComponentLanguage.d.ts +31 -0
  71. package/GlobalComponentLanguage.js +37 -0
  72. package/GlobalComponentLanguage.js.map +1 -0
  73. package/HashObject.js +11 -12
  74. package/HashObject.js.map +1 -1
  75. package/HotkeyManager.js +40 -47
  76. package/HotkeyManager.js.map +1 -1
  77. package/IBindingsUpdater.js +0 -3
  78. package/IRedirects.js +0 -3
  79. package/InheritanceProcessor.js +99 -139
  80. package/InheritanceProcessor.js.map +1 -1
  81. package/InheritanceProcessor.test.js +184 -177
  82. package/InheritanceProcessor.test.js.map +1 -1
  83. package/InheritedValueResolver.d.ts +6 -0
  84. package/InheritedValueResolver.js +22 -20
  85. package/InheritedValueResolver.js.map +1 -1
  86. package/InputBindingsProcessor.js +193 -289
  87. package/InputBindingsProcessor.js.map +1 -1
  88. package/InputRenderer.test.d.ts +1 -0
  89. package/InputRenderer.test.js +186 -0
  90. package/InputRenderer.test.js.map +1 -0
  91. package/InputsBindingsProcessor.test.js +464 -314
  92. package/InputsBindingsProcessor.test.js.map +1 -1
  93. package/InputsUpdater.d.ts +1 -1
  94. package/InputsUpdater.js +24 -26
  95. package/InputsUpdater.js.map +1 -1
  96. package/LayoutContentArea.d.ts +68 -0
  97. package/LayoutContentArea.js +78 -0
  98. package/LayoutContentArea.js.map +1 -0
  99. package/LayoutContentArea.test.d.ts +1 -0
  100. package/LayoutContentArea.test.js +111 -0
  101. package/LayoutContentArea.test.js.map +1 -0
  102. package/LiveSdk.d.ts +6 -3
  103. package/LiveSdk.js +16 -13
  104. package/LiveSdk.js.map +1 -1
  105. package/Logger.js +9 -8
  106. package/Logger.js.map +1 -1
  107. package/MouseTracker.js +77 -83
  108. package/MouseTracker.js.map +1 -1
  109. package/NullSdk.d.ts +5 -3
  110. package/NullSdk.js +25 -14
  111. package/NullSdk.js.map +1 -1
  112. package/PreviewDocument.d.ts +3 -1
  113. package/PreviewDocument.js +30 -30
  114. package/PreviewDocument.js.map +1 -1
  115. package/PreviewSdk.d.ts +7 -3
  116. package/PreviewSdk.js +23 -17
  117. package/PreviewSdk.js.map +1 -1
  118. package/PreviewViewport.d.ts +5 -0
  119. package/PreviewViewport.js +60 -63
  120. package/PreviewViewport.js.map +1 -1
  121. package/PreviewViewport.test.d.ts +1 -0
  122. package/PreviewViewport.test.js +27 -0
  123. package/PreviewViewport.test.js.map +1 -0
  124. package/RadioOptionInputs.test.d.ts +1 -0
  125. package/RadioOptionInputs.test.js +521 -0
  126. package/RadioOptionInputs.test.js.map +1 -0
  127. package/ResizeObserver.js +24 -31
  128. package/ResizeObserver.js.map +1 -1
  129. package/StylesBindingsProcessor.js +41 -79
  130. package/StylesBindingsProcessor.js.map +1 -1
  131. package/StylesUpdater.d.ts +1 -1
  132. package/StylesUpdater.js +23 -25
  133. package/StylesUpdater.js.map +1 -1
  134. package/Theme.js +30 -25
  135. package/Theme.js.map +1 -1
  136. package/ViewportManager.js +89 -101
  137. package/ViewportManager.js.map +1 -1
  138. package/asset/deliveryUrl.d.ts +41 -0
  139. package/asset/deliveryUrl.js +34 -0
  140. package/asset/deliveryUrl.js.map +1 -0
  141. package/asset/deliveryUrl.test.d.ts +1 -0
  142. package/asset/deliveryUrl.test.js +127 -0
  143. package/asset/deliveryUrl.test.js.map +1 -0
  144. package/asset/geometry.d.ts +7 -0
  145. package/asset/geometry.js +10 -0
  146. package/asset/geometry.js.map +1 -0
  147. package/asset/imageSrcSet.d.ts +63 -0
  148. package/asset/imageSrcSet.js +98 -0
  149. package/asset/imageSrcSet.js.map +1 -0
  150. package/asset/imageSrcSet.test.d.ts +1 -0
  151. package/asset/imageSrcSet.test.js +103 -0
  152. package/asset/imageSrcSet.test.js.map +1 -0
  153. package/asset/index.d.ts +5 -0
  154. package/asset/index.js +5 -0
  155. package/asset/normalize.d.ts +24 -0
  156. package/asset/normalize.js +106 -0
  157. package/asset/normalize.js.map +1 -0
  158. package/asset/normalize.test.d.ts +1 -0
  159. package/asset/normalize.test.js +263 -0
  160. package/asset/normalize.test.js.map +1 -0
  161. package/asset/types.d.ts +2 -0
  162. package/asset/types.js +0 -0
  163. package/componentLoader/ComponentLoader.d.ts +16 -0
  164. package/componentLoader/ComponentLoader.js +0 -0
  165. package/componentLoader/RegistryOnlyComponentLoader.d.ts +9 -0
  166. package/componentLoader/RegistryOnlyComponentLoader.js +8 -0
  167. package/componentLoader/RegistryOnlyComponentLoader.js.map +1 -0
  168. package/componentLoader/createComponentLoader.d.ts +7 -0
  169. package/componentLoader/createComponentLoader.js +10 -0
  170. package/componentLoader/createComponentLoader.js.map +1 -0
  171. package/componentLoader/defaultComponentLoader.d.ts +7 -0
  172. package/componentLoader/defaultComponentLoader.js +8 -0
  173. package/componentLoader/defaultComponentLoader.js.map +1 -0
  174. package/componentLoader/index.d.ts +3 -0
  175. package/componentLoader/index.js +3 -0
  176. package/constants.d.ts +1 -0
  177. package/constants.js +7 -5
  178. package/constants.js.map +1 -1
  179. package/contentClientState.test.d.ts +1 -0
  180. package/contentClientState.test.js +404 -0
  181. package/contentClientState.test.js.map +1 -0
  182. package/contentEntry/ContentEntryBindingsResolver.d.ts +33 -0
  183. package/contentEntry/ContentEntryBindingsResolver.js +52 -0
  184. package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
  185. package/contentEntry/ContentEntryCache.d.ts +49 -0
  186. package/contentEntry/ContentEntryCache.js +51 -0
  187. package/contentEntry/ContentEntryCache.js.map +1 -0
  188. package/contentEntry/resolveContentEntry.d.ts +74 -0
  189. package/contentEntry/resolveContentEntry.js +53 -0
  190. package/contentEntry/resolveContentEntry.js.map +1 -0
  191. package/contentEntry/resolveContentEntry.test.d.ts +1 -0
  192. package/contentEntry/resolveContentEntry.test.js +213 -0
  193. package/contentEntry/resolveContentEntry.test.js.map +1 -0
  194. package/createComponent.d.ts +5 -0
  195. package/createComponent.js +32 -0
  196. package/createComponent.js.map +1 -0
  197. package/createContentClient.d.ts +17 -0
  198. package/createContentClient.js +16 -0
  199. package/createContentClient.js.map +1 -0
  200. package/createContentClient.test.d.ts +1 -0
  201. package/createContentClient.test.js +165 -0
  202. package/createContentClient.test.js.map +1 -0
  203. package/createElement.js +5 -6
  204. package/createElement.js.map +1 -1
  205. package/createGlobalElementDocument.d.ts +6 -0
  206. package/createGlobalElementDocument.js +23 -0
  207. package/createGlobalElementDocument.js.map +1 -0
  208. package/createInput.d.ts +10 -2
  209. package/createInput.js +92 -143
  210. package/createInput.js.map +1 -1
  211. package/createTheme.js +2 -3
  212. package/createTheme.js.map +1 -1
  213. package/dataProviders/ApiClient.d.ts +13 -5
  214. package/dataProviders/ApiClient.js +58 -49
  215. package/dataProviders/ApiClient.js.map +1 -1
  216. package/dataProviders/ApiClient.test.d.ts +1 -0
  217. package/dataProviders/ApiClient.test.js +116 -0
  218. package/dataProviders/ApiClient.test.js.map +1 -0
  219. package/dataProviders/DefaultDataProvider.d.ts +7 -2
  220. package/dataProviders/DefaultDataProvider.js +103 -45
  221. package/dataProviders/DefaultDataProvider.js.map +1 -1
  222. package/dataProviders/DefaultDataProvider.test.d.ts +1 -0
  223. package/dataProviders/DefaultDataProvider.test.js +81 -0
  224. package/dataProviders/DefaultDataProvider.test.js.map +1 -0
  225. package/dataProviders/GET_EXPERIMENT_PAUSED.d.ts +1 -0
  226. package/dataProviders/GET_EXPERIMENT_PAUSED.js +17 -0
  227. package/dataProviders/GET_EXPERIMENT_PAUSED.js.map +1 -0
  228. package/dataProviders/GET_LAYOUT_BY_SLUG.d.ts +1 -0
  229. package/dataProviders/GET_LAYOUT_BY_SLUG.js +27 -0
  230. package/dataProviders/GET_LAYOUT_BY_SLUG.js.map +1 -0
  231. package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -1
  232. package/dataProviders/GET_PAGE_BY_ID.js +10 -1
  233. package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
  234. package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -1
  235. package/dataProviders/GET_PAGE_BY_PATH.js +10 -1
  236. package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
  237. package/dataProviders/GET_PAGE_EXPERIMENT.d.ts +1 -0
  238. package/dataProviders/GET_PAGE_EXPERIMENT.js +32 -0
  239. package/dataProviders/GET_PAGE_EXPERIMENT.js.map +1 -0
  240. package/dataProviders/GET_VARIANT_CONTENT.d.ts +1 -0
  241. package/dataProviders/GET_VARIANT_CONTENT.js +24 -0
  242. package/dataProviders/GET_VARIANT_CONTENT.js.map +1 -0
  243. package/dataProviders/LIST_PUBLISHED_PAGES.d.ts +1 -1
  244. package/dataProviders/LIST_PUBLISHED_PAGES.js +16 -5
  245. package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -1
  246. package/dataProviders/NullDataProvider.d.ts +17 -4
  247. package/dataProviders/NullDataProvider.js +33 -13
  248. package/dataProviders/NullDataProvider.js.map +1 -1
  249. package/dataProviders/RedirectsProvider.js +24 -27
  250. package/dataProviders/RedirectsProvider.js.map +1 -1
  251. package/dataProviders/queries.test.d.ts +1 -0
  252. package/dataProviders/queries.test.js +53 -0
  253. package/dataProviders/queries.test.js.map +1 -0
  254. package/defaultBreakpoints.js +43 -22
  255. package/defaultBreakpoints.js.map +1 -1
  256. package/documentOperations/$addElementReferenceToParent.d.ts +1 -1
  257. package/documentOperations/$addElementReferenceToParent.js +30 -26
  258. package/documentOperations/$addElementReferenceToParent.js.map +1 -1
  259. package/documentOperations/AddElement.js +8 -7
  260. package/documentOperations/AddElement.js.map +1 -1
  261. package/documentOperations/AddToParent.d.ts +2 -2
  262. package/documentOperations/AddToParent.js +14 -13
  263. package/documentOperations/AddToParent.js.map +1 -1
  264. package/documentOperations/IDocumentOperation.js +0 -3
  265. package/documentOperations/RemoveElement.js +10 -7
  266. package/documentOperations/RemoveElement.js.map +1 -1
  267. package/documentOperations/SetGlobalInputBinding.js +23 -22
  268. package/documentOperations/SetGlobalInputBinding.js.map +1 -1
  269. package/documentOperations/SetGlobalStyleBinding.js +23 -23
  270. package/documentOperations/SetGlobalStyleBinding.js.map +1 -1
  271. package/documentOperations/SetInputBindingOverride.js +30 -29
  272. package/documentOperations/SetInputBindingOverride.js.map +1 -1
  273. package/documentOperations/SetStyleBindingOverride.js +30 -31
  274. package/documentOperations/SetStyleBindingOverride.js.map +1 -1
  275. package/documentOperations/index.js +9 -8
  276. package/documentOperations/index.js.map +1 -1
  277. package/experiments/PostHogAnalyticsProvider.d.ts +31 -0
  278. package/experiments/PostHogAnalyticsProvider.js +28 -0
  279. package/experiments/PostHogAnalyticsProvider.js.map +1 -0
  280. package/experiments/analyticsProvider.d.ts +4 -0
  281. package/experiments/analyticsProvider.js +11 -0
  282. package/experiments/analyticsProvider.js.map +1 -0
  283. package/experiments/bucketing.d.ts +27 -0
  284. package/experiments/bucketing.js +91 -0
  285. package/experiments/bucketing.js.map +1 -0
  286. package/experiments/bucketing.test.d.ts +1 -0
  287. package/experiments/bucketing.test.js +183 -0
  288. package/experiments/bucketing.test.js.map +1 -0
  289. package/experiments/index.d.ts +5 -0
  290. package/experiments/index.js +5 -0
  291. package/experiments/render.d.ts +82 -0
  292. package/experiments/render.js +149 -0
  293. package/experiments/render.js.map +1 -0
  294. package/experiments/types.d.ts +108 -0
  295. package/experiments/types.js +4 -0
  296. package/experiments/types.js.map +1 -0
  297. package/findMatchingAstNode.js +11 -13
  298. package/findMatchingAstNode.js.map +1 -1
  299. package/generateElementId.js +2 -1
  300. package/generateElementId.js.map +1 -1
  301. package/globalElements.d.ts +43 -0
  302. package/globalElements.js +79 -0
  303. package/globalElements.js.map +1 -0
  304. package/globalElements.test.d.ts +1 -0
  305. package/globalElements.test.js +343 -0
  306. package/globalElements.test.js.map +1 -0
  307. package/headersProvider.d.ts +1 -2
  308. package/headersProvider.js +4 -3
  309. package/headersProvider.js.map +1 -1
  310. package/image/geometry.d.ts +54 -0
  311. package/image/geometry.js +112 -0
  312. package/image/geometry.js.map +1 -0
  313. package/image/geometry.test.d.ts +1 -0
  314. package/image/geometry.test.js +190 -0
  315. package/image/geometry.test.js.map +1 -0
  316. package/image/index.d.ts +3 -0
  317. package/image/index.js +3 -0
  318. package/image/presets.d.ts +6 -0
  319. package/image/presets.js +20 -0
  320. package/image/presets.js.map +1 -0
  321. package/image/types.d.ts +10 -0
  322. package/image/types.js +0 -0
  323. package/index.d.ts +21 -0
  324. package/index.js +21 -2
  325. package/jsonPatch.js +5 -9
  326. package/jsonPatch.js.map +1 -1
  327. package/listItemId.d.ts +17 -0
  328. package/listItemId.js +14 -0
  329. package/listItemId.js.map +1 -0
  330. package/listItemId.test.d.ts +1 -0
  331. package/listItemId.test.js +265 -0
  332. package/listItemId.test.js.map +1 -0
  333. package/messages.d.ts +3 -0
  334. package/messages.js +15 -11
  335. package/messages.js.map +1 -1
  336. package/messenger/MessageOrigin.js +12 -11
  337. package/messenger/MessageOrigin.js.map +1 -1
  338. package/messenger/Messenger.js +58 -71
  339. package/messenger/Messenger.js.map +1 -1
  340. package/messenger/index.js +0 -2
  341. package/package.json +17 -16
  342. package/radioOptionInputs.d.ts +24 -0
  343. package/radioOptionInputs.js +26 -0
  344. package/radioOptionInputs.js.map +1 -0
  345. package/registerComponentGroup.js +5 -6
  346. package/registerComponentGroup.js.map +1 -1
  347. package/types/ShorthandCssProperties.js +0 -3
  348. package/types/WebsiteBuilderTheme.d.ts +12 -0
  349. package/types/WebsiteBuilderTheme.js +0 -3
  350. package/types.d.ts +338 -18
  351. package/types.js +0 -3
  352. package/withGlobalElementDefaults.d.ts +8 -0
  353. package/withGlobalElementDefaults.js +60 -0
  354. package/withGlobalElementDefaults.js.map +1 -0
  355. package/IBindingsUpdater.js.map +0 -1
  356. package/IRedirects.js.map +0 -1
  357. package/documentOperations/IDocumentOperation.js.map +0 -1
  358. package/index.js.map +0 -1
  359. package/messenger/index.js.map +0 -1
  360. package/types/ShorthandCssProperties.js.map +0 -1
  361. package/types/WebsiteBuilderTheme.js.map +0 -1
  362. package/types.js.map +0 -1
@@ -0,0 +1,165 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { createContentClient } from "./createContentClient.js";
3
+ import { contentSdk } from "./ContentSdk.js";
4
+ const pageResponse = (path)=>({
5
+ data: {
6
+ websiteBuilder: {
7
+ getPageByPath: {
8
+ data: {
9
+ id: `page:${path}`,
10
+ properties: {
11
+ id: `page:${path}`,
12
+ path
13
+ }
14
+ },
15
+ error: null
16
+ }
17
+ }
18
+ }
19
+ });
20
+ describe("createContentClient", ()=>{
21
+ let requests;
22
+ let delays;
23
+ beforeEach(()=>{
24
+ requests = [];
25
+ delays = {};
26
+ const fetchMock = vi.fn(async (url, init)=>{
27
+ const headers = init.headers;
28
+ const body = JSON.parse(init.body);
29
+ const path = body.variables.path;
30
+ requests.push({
31
+ url,
32
+ tenant: headers["X-Tenant"],
33
+ authorization: headers["Authorization"],
34
+ path
35
+ });
36
+ const delay = delays[path] ?? 0;
37
+ await new Promise((resolve)=>setTimeout(resolve, delay));
38
+ return {
39
+ json: async ()=>pageResponse(path)
40
+ };
41
+ });
42
+ vi.stubGlobal("fetch", fetchMock);
43
+ });
44
+ afterEach(()=>{
45
+ vi.unstubAllGlobals();
46
+ });
47
+ it("sends each client's own tenant, host and key", async ()=>{
48
+ const clientA = createContentClient({
49
+ apiHost: "https://a.example.com",
50
+ apiKey: "key-a",
51
+ apiTenant: "tenant-a"
52
+ });
53
+ const clientB = createContentClient({
54
+ apiHost: "https://b.example.com",
55
+ apiKey: "key-b",
56
+ apiTenant: "tenant-b"
57
+ });
58
+ await clientA.getPage("/a");
59
+ await clientB.getPage("/b");
60
+ expect(requests).toEqual([
61
+ {
62
+ url: "https://a.example.com/graphql",
63
+ tenant: "tenant-a",
64
+ authorization: "Bearer key-a",
65
+ path: "/a"
66
+ },
67
+ {
68
+ url: "https://b.example.com/graphql",
69
+ tenant: "tenant-b",
70
+ authorization: "Bearer key-b",
71
+ path: "/b"
72
+ }
73
+ ]);
74
+ });
75
+ it("keeps clients isolated when their calls interleave", async ()=>{
76
+ const clientA = createContentClient({
77
+ apiHost: "https://a.example.com",
78
+ apiKey: "key-a",
79
+ apiTenant: "tenant-a"
80
+ });
81
+ const clientB = createContentClient({
82
+ apiHost: "https://b.example.com",
83
+ apiKey: "key-b",
84
+ apiTenant: "tenant-b"
85
+ });
86
+ delays["/a"] = 20;
87
+ delays["/b"] = 0;
88
+ const [pageA, pageB] = await Promise.all([
89
+ clientA.getPage("/a"),
90
+ clientB.getPage("/b")
91
+ ]);
92
+ expect(pageA?.properties.path).toBe("/a");
93
+ expect(pageB?.properties.path).toBe("/b");
94
+ const requestA = requests.find((request)=>"/a" === request.path);
95
+ const requestB = requests.find((request)=>"/b" === request.path);
96
+ expect(requestA).toMatchObject({
97
+ url: "https://a.example.com/graphql",
98
+ tenant: "tenant-a",
99
+ authorization: "Bearer key-a"
100
+ });
101
+ expect(requestB).toMatchObject({
102
+ url: "https://b.example.com/graphql",
103
+ tenant: "tenant-b",
104
+ authorization: "Bearer key-b"
105
+ });
106
+ });
107
+ it("does not change what the contentSdk singleton sends, and init() does not change a client", async ()=>{
108
+ contentSdk.init({
109
+ apiHost: "https://singleton.example.com",
110
+ apiKey: "key-singleton",
111
+ apiTenant: "root"
112
+ });
113
+ const client = createContentClient({
114
+ apiHost: "https://client.example.com",
115
+ apiKey: "key-client",
116
+ apiTenant: "tenant-client"
117
+ });
118
+ await contentSdk.getPage("/singleton");
119
+ contentSdk.init({
120
+ apiHost: "https://singleton-2.example.com",
121
+ apiKey: "key-singleton-2",
122
+ apiTenant: "root-2"
123
+ });
124
+ await client.getPage("/client");
125
+ await contentSdk.getPage("/singleton-2");
126
+ expect(requests).toEqual([
127
+ {
128
+ url: "https://singleton.example.com/graphql",
129
+ tenant: "root",
130
+ authorization: "Bearer key-singleton",
131
+ path: "/singleton"
132
+ },
133
+ {
134
+ url: "https://client.example.com/graphql",
135
+ tenant: "tenant-client",
136
+ authorization: "Bearer key-client",
137
+ path: "/client"
138
+ },
139
+ {
140
+ url: "https://singleton-2.example.com/graphql",
141
+ tenant: "root-2",
142
+ authorization: "Bearer key-singleton-2",
143
+ path: "/singleton-2"
144
+ }
145
+ ]);
146
+ });
147
+ it("keeps the preview flag per client", ()=>{
148
+ const live = createContentClient({
149
+ apiHost: "https://a.example.com",
150
+ apiKey: "key-a",
151
+ apiTenant: "tenant-a"
152
+ });
153
+ const preview = createContentClient({
154
+ apiHost: "https://a.example.com",
155
+ apiKey: "key-a",
156
+ apiTenant: "tenant-a",
157
+ preview: true,
158
+ previewParams: "wb.type=page&wb.path=/a&wb.id=page-1"
159
+ });
160
+ expect(live.isPreviewing()).toBe(false);
161
+ expect(preview.isPreviewing()).toBe(true);
162
+ });
163
+ });
164
+
165
+ //# sourceMappingURL=createContentClient.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContentClient.test.js","sources":["../src/createContentClient.test.ts"],"sourcesContent":["import { describe, it, expect, beforeEach, afterEach, vi } from \"vitest\";\nimport { createContentClient } from \"./createContentClient.js\";\nimport { contentSdk } from \"./ContentSdk.js\";\n\ninterface RecordedRequest {\n url: string;\n tenant: string;\n authorization: string;\n path: string;\n}\n\nconst pageResponse = (path: string) => {\n return {\n data: {\n websiteBuilder: {\n getPageByPath: {\n data: { id: `page:${path}`, properties: { id: `page:${path}`, path } },\n error: null\n }\n }\n }\n };\n};\n\ndescribe(\"createContentClient\", () => {\n let requests: RecordedRequest[];\n let delays: Record<string, number>;\n\n beforeEach(() => {\n requests = [];\n delays = {};\n\n const fetchMock = vi.fn(async (url: string, init: RequestInit) => {\n const headers = init.headers as Record<string, string>;\n const body = JSON.parse(init.body as string);\n const path: string = body.variables.path;\n requests.push({\n url,\n tenant: headers[\"X-Tenant\"],\n authorization: headers[\"Authorization\"],\n path\n });\n\n const delay = delays[path] ?? 0;\n await new Promise(resolve => setTimeout(resolve, delay));\n\n return { json: async () => pageResponse(path) };\n });\n\n vi.stubGlobal(\"fetch\", fetchMock);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n });\n\n it(\"sends each client's own tenant, host and key\", async () => {\n const clientA = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const clientB = createContentClient({\n apiHost: \"https://b.example.com\",\n apiKey: \"key-b\",\n apiTenant: \"tenant-b\"\n });\n\n await clientA.getPage(\"/a\");\n await clientB.getPage(\"/b\");\n\n expect(requests).toEqual([\n {\n url: \"https://a.example.com/graphql\",\n tenant: \"tenant-a\",\n authorization: \"Bearer key-a\",\n path: \"/a\"\n },\n {\n url: \"https://b.example.com/graphql\",\n tenant: \"tenant-b\",\n authorization: \"Bearer key-b\",\n path: \"/b\"\n }\n ]);\n });\n\n it(\"keeps clients isolated when their calls interleave\", async () => {\n const clientA = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const clientB = createContentClient({\n apiHost: \"https://b.example.com\",\n apiKey: \"key-b\",\n apiTenant: \"tenant-b\"\n });\n\n // The first request to start is the last to finish.\n delays[\"/a\"] = 20;\n delays[\"/b\"] = 0;\n\n const [pageA, pageB] = await Promise.all([clientA.getPage(\"/a\"), clientB.getPage(\"/b\")]);\n\n expect(pageA?.properties.path).toBe(\"/a\");\n expect(pageB?.properties.path).toBe(\"/b\");\n\n const requestA = requests.find(request => request.path === \"/a\");\n const requestB = requests.find(request => request.path === \"/b\");\n\n expect(requestA).toMatchObject({\n url: \"https://a.example.com/graphql\",\n tenant: \"tenant-a\",\n authorization: \"Bearer key-a\"\n });\n expect(requestB).toMatchObject({\n url: \"https://b.example.com/graphql\",\n tenant: \"tenant-b\",\n authorization: \"Bearer key-b\"\n });\n });\n\n it(\"does not change what the contentSdk singleton sends, and init() does not change a client\", async () => {\n contentSdk.init({\n apiHost: \"https://singleton.example.com\",\n apiKey: \"key-singleton\",\n apiTenant: \"root\"\n });\n\n const client = createContentClient({\n apiHost: \"https://client.example.com\",\n apiKey: \"key-client\",\n apiTenant: \"tenant-client\"\n });\n\n await contentSdk.getPage(\"/singleton\");\n\n contentSdk.init({\n apiHost: \"https://singleton-2.example.com\",\n apiKey: \"key-singleton-2\",\n apiTenant: \"root-2\"\n });\n\n await client.getPage(\"/client\");\n await contentSdk.getPage(\"/singleton-2\");\n\n expect(requests).toEqual([\n {\n url: \"https://singleton.example.com/graphql\",\n tenant: \"root\",\n authorization: \"Bearer key-singleton\",\n path: \"/singleton\"\n },\n {\n url: \"https://client.example.com/graphql\",\n tenant: \"tenant-client\",\n authorization: \"Bearer key-client\",\n path: \"/client\"\n },\n {\n url: \"https://singleton-2.example.com/graphql\",\n tenant: \"root-2\",\n authorization: \"Bearer key-singleton-2\",\n path: \"/singleton-2\"\n }\n ]);\n });\n\n it(\"keeps the preview flag per client\", () => {\n const live = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const preview = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\",\n preview: true,\n previewParams: \"wb.type=page&wb.path=/a&wb.id=page-1\"\n });\n\n expect(live.isPreviewing()).toBe(false);\n expect(preview.isPreviewing()).toBe(true);\n });\n});\n"],"names":["pageResponse","path","describe","requests","delays","beforeEach","fetchMock","vi","url","init","headers","body","JSON","delay","Promise","resolve","setTimeout","afterEach","it","clientA","createContentClient","clientB","expect","pageA","pageB","requestA","request","requestB","contentSdk","client","live","preview"],"mappings":";;;AAWA,MAAMA,eAAe,CAACC,OACX;QACH,MAAM;YACF,gBAAgB;gBACZ,eAAe;oBACX,MAAM;wBAAE,IAAI,CAAC,KAAK,EAAEA,MAAM;wBAAE,YAAY;4BAAE,IAAI,CAAC,KAAK,EAAEA,MAAM;4BAAEA;wBAAK;oBAAE;oBACrE,OAAO;gBACX;YACJ;QACJ;IACJ;AAGJC,SAAS,uBAAuB;IAC5B,IAAIC;IACJ,IAAIC;IAEJC,WAAW;QACPF,WAAW,EAAE;QACbC,SAAS,CAAC;QAEV,MAAME,YAAYC,GAAG,EAAE,CAAC,OAAOC,KAAaC;YACxC,MAAMC,UAAUD,KAAK,OAAO;YAC5B,MAAME,OAAOC,KAAK,KAAK,CAACH,KAAK,IAAI;YACjC,MAAMR,OAAeU,KAAK,SAAS,CAAC,IAAI;YACxCR,SAAS,IAAI,CAAC;gBACVK;gBACA,QAAQE,OAAO,CAAC,WAAW;gBAC3B,eAAeA,OAAO,CAAC,gBAAgB;gBACvCT;YACJ;YAEA,MAAMY,QAAQT,MAAM,CAACH,KAAK,IAAI;YAC9B,MAAM,IAAIa,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;YAEjD,OAAO;gBAAE,MAAM,UAAYb,aAAaC;YAAM;QAClD;QAEAM,GAAG,UAAU,CAAC,SAASD;IAC3B;IAEAW,UAAU;QACNV,GAAG,gBAAgB;IACvB;IAEAW,GAAG,gDAAgD;QAC/C,MAAMC,UAAUC,oBAAoB;YAChC,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACA,MAAMC,UAAUD,oBAAoB;YAChC,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAEA,MAAMD,QAAQ,OAAO,CAAC;QACtB,MAAME,QAAQ,OAAO,CAAC;QAEtBC,OAAOnB,UAAU,OAAO,CAAC;YACrB;gBACI,KAAK;gBACL,QAAQ;gBACR,eAAe;gBACf,MAAM;YACV;YACA;gBACI,KAAK;gBACL,QAAQ;gBACR,eAAe;gBACf,MAAM;YACV;SACH;IACL;IAEAe,GAAG,sDAAsD;QACrD,MAAMC,UAAUC,oBAAoB;YAChC,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACA,MAAMC,UAAUD,oBAAoB;YAChC,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAGAhB,MAAM,CAAC,KAAK,GAAG;QACfA,MAAM,CAAC,KAAK,GAAG;QAEf,MAAM,CAACmB,OAAOC,MAAM,GAAG,MAAMV,QAAQ,GAAG,CAAC;YAACK,QAAQ,OAAO,CAAC;YAAOE,QAAQ,OAAO,CAAC;SAAM;QAEvFC,OAAOC,OAAO,WAAW,MAAM,IAAI,CAAC;QACpCD,OAAOE,OAAO,WAAW,MAAM,IAAI,CAAC;QAEpC,MAAMC,WAAWtB,SAAS,IAAI,CAACuB,CAAAA,UAAWA,AAAiB,SAAjBA,QAAQ,IAAI;QACtD,MAAMC,WAAWxB,SAAS,IAAI,CAACuB,CAAAA,UAAWA,AAAiB,SAAjBA,QAAQ,IAAI;QAEtDJ,OAAOG,UAAU,aAAa,CAAC;YAC3B,KAAK;YACL,QAAQ;YACR,eAAe;QACnB;QACAH,OAAOK,UAAU,aAAa,CAAC;YAC3B,KAAK;YACL,QAAQ;YACR,eAAe;QACnB;IACJ;IAEAT,GAAG,4FAA4F;QAC3FU,WAAW,IAAI,CAAC;YACZ,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAEA,MAAMC,SAAST,oBAAoB;YAC/B,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAEA,MAAMQ,WAAW,OAAO,CAAC;QAEzBA,WAAW,IAAI,CAAC;YACZ,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAEA,MAAMC,OAAO,OAAO,CAAC;QACrB,MAAMD,WAAW,OAAO,CAAC;QAEzBN,OAAOnB,UAAU,OAAO,CAAC;YACrB;gBACI,KAAK;gBACL,QAAQ;gBACR,eAAe;gBACf,MAAM;YACV;YACA;gBACI,KAAK;gBACL,QAAQ;gBACR,eAAe;gBACf,MAAM;YACV;YACA;gBACI,KAAK;gBACL,QAAQ;gBACR,eAAe;gBACf,MAAM;YACV;SACH;IACL;IAEAe,GAAG,qCAAqC;QACpC,MAAMY,OAAOV,oBAAoB;YAC7B,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QACA,MAAMW,UAAUX,oBAAoB;YAChC,SAAS;YACT,QAAQ;YACR,WAAW;YACX,SAAS;YACT,eAAe;QACnB;QAEAE,OAAOQ,KAAK,YAAY,IAAI,IAAI,CAAC;QACjCR,OAAOS,QAAQ,YAAY,IAAI,IAAI,CAAC;IACxC;AACJ"}
package/createElement.js CHANGED
@@ -1,8 +1,7 @@
1
- export const createElement = params => {
2
- return {
3
- action: "CreateElement",
4
- params
5
- };
6
- };
1
+ const createElement = (params)=>({
2
+ action: "CreateElement",
3
+ params
4
+ });
5
+ export { createElement };
7
6
 
8
7
  //# sourceMappingURL=createElement.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createElement","params","action"],"sources":["createElement.ts"],"sourcesContent":["import type { ResponsiveStyles } from \"~/types.js\";\n\nexport interface CreateElementParams {\n component: string;\n inputs?: Record<string, any>;\n styles?: ResponsiveStyles;\n}\n\nexport const createElement = (params: CreateElementParams) => {\n return {\n action: \"CreateElement\",\n params\n };\n};\n"],"mappings":"AAQA,OAAO,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EAC1D,OAAO;IACHC,MAAM,EAAE,eAAe;IACvBD;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"createElement.js","sources":["../src/createElement.ts"],"sourcesContent":["import type { ResponsiveStyles } from \"~/types.js\";\n\nexport interface CreateElementParams {\n component: string;\n inputs?: Record<string, any>;\n styles?: ResponsiveStyles;\n}\n\nexport const createElement = (params: CreateElementParams) => {\n return {\n action: \"CreateElement\",\n params\n };\n};\n"],"names":["createElement","params"],"mappings":"AAQO,MAAMA,gBAAgB,CAACC,SACnB;QACH,QAAQ;QACRA;IACJ"}
@@ -0,0 +1,6 @@
1
+ import type { ComponentManifest, GlobalDocument } from "./types.js";
2
+ /**
3
+ * Build the default instance of a global component (element + bindings) from its manifest defaults.
4
+ * Used when a global exists in code but has no stored instance yet.
5
+ */
6
+ export declare const createGlobalElementDocument: (componentName: string, components: Record<string, ComponentManifest>) => GlobalDocument;
@@ -0,0 +1,23 @@
1
+ import { ElementFactory } from "./ElementFactory.js";
2
+ const createDefaultIdGenerator = (componentName)=>{
3
+ const name = componentName.replace(/[^a-zA-Z0-9]/gu, (char)=>`_${char.codePointAt(0).toString(16)}_`);
4
+ const prefix = `global-${name}`;
5
+ let counter = 0;
6
+ return ()=>`${prefix}-${++counter}`;
7
+ };
8
+ const createGlobalElementDocument = (componentName, components)=>{
9
+ const factory = new ElementFactory(components, createDefaultIdGenerator(componentName), createDefaultIdGenerator(`${componentName}/item`));
10
+ const { operations } = factory.createGlobalElement(componentName);
11
+ const document = {
12
+ elements: {},
13
+ bindings: {}
14
+ };
15
+ operations.forEach((operation)=>operation.apply(document));
16
+ return {
17
+ elements: document.elements,
18
+ bindings: document.bindings
19
+ };
20
+ };
21
+ export { createGlobalElementDocument };
22
+
23
+ //# sourceMappingURL=createGlobalElementDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGlobalElementDocument.js","sources":["../src/createGlobalElementDocument.ts"],"sourcesContent":["import type { ComponentManifest, Document, GlobalDocument } from \"./types.js\";\nimport { ElementFactory } from \"./ElementFactory.js\";\n\n/**\n * Ids for the elements and bindings of a default global instance. They are derived from the component\n * name, so every build of the same defaults yields the same ids: the server render and the client\n * hydration agree, and re-renders don't remount the global's children. The hyphens keep them apart\n * from generated ids, which use only lowercase letters and digits.\n * Every other character of the name is escaped as `_<hex code point>_`, so two different names never\n * share a prefix (`Demo/Header` and `Demo-Header` would both collapse to `Demo-Header` otherwise).\n */\nconst createDefaultIdGenerator = (componentName: string) => {\n const name = componentName.replace(/[^a-zA-Z0-9]/gu, char => {\n return `_${char.codePointAt(0)!.toString(16)}_`;\n });\n const prefix = `global-${name}`;\n let counter = 0;\n return () => `${prefix}-${++counter}`;\n};\n\n/**\n * Build the default instance of a global component (element + bindings) from its manifest defaults.\n * Used when a global exists in code but has no stored instance yet.\n */\nexport const createGlobalElementDocument = (\n componentName: string,\n components: Record<string, ComponentManifest>\n): GlobalDocument => {\n const factory = new ElementFactory(\n components,\n createDefaultIdGenerator(componentName),\n createDefaultIdGenerator(`${componentName}/item`)\n );\n const { operations } = factory.createGlobalElement(componentName);\n\n const document = { elements: {}, bindings: {} } as Document;\n operations.forEach(operation => operation.apply(document));\n\n return { elements: document.elements, bindings: document.bindings };\n};\n"],"names":["createDefaultIdGenerator","componentName","name","char","prefix","counter","createGlobalElementDocument","components","factory","ElementFactory","operations","document","operation"],"mappings":";AAWA,MAAMA,2BAA2B,CAACC;IAC9B,MAAMC,OAAOD,cAAc,OAAO,CAAC,kBAAkBE,CAAAA,OAC1C,CAAC,CAAC,EAAEA,KAAK,WAAW,CAAC,GAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEnD,MAAMC,SAAS,CAAC,OAAO,EAAEF,MAAM;IAC/B,IAAIG,UAAU;IACd,OAAO,IAAM,GAAGD,OAAO,CAAC,EAAE,EAAEC,SAAS;AACzC;AAMO,MAAMC,8BAA8B,CACvCL,eACAM;IAEA,MAAMC,UAAU,IAAIC,eAChBF,YACAP,yBAAyBC,gBACzBD,yBAAyB,GAAGC,cAAc,KAAK,CAAC;IAEpD,MAAM,EAAES,UAAU,EAAE,GAAGF,QAAQ,mBAAmB,CAACP;IAEnD,MAAMU,WAAW;QAAE,UAAU,CAAC;QAAG,UAAU,CAAC;IAAE;IAC9CD,WAAW,OAAO,CAACE,CAAAA,YAAaA,UAAU,KAAK,CAACD;IAEhD,OAAO;QAAE,UAAUA,SAAS,QAAQ;QAAE,UAAUA,SAAS,QAAQ;IAAC;AACtE"}
package/createInput.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { TextInput, LongTextInput, NumberInput, BooleanInput, ColorInput, FileInput, LexicalInput, SelectInput, RadioInput, ObjectInput, DateTimeInput, ComponentInput, TagsInput, SlotInput } from "./types.js";
2
- export type InputFactory<Name extends string> = ReturnType<typeof createTextInput<Name>> | ReturnType<typeof createLongTextInput<Name>> | ReturnType<typeof createNumberInput<Name>> | ReturnType<typeof createBooleanInput<Name>> | ReturnType<typeof createColorInput<Name>> | ReturnType<typeof createFileInput<Name>> | ReturnType<typeof createDateInput<Name>> | ReturnType<typeof createLexicalInput<Name>> | ReturnType<typeof createSelectInput<Name>> | ReturnType<typeof createRadioInput<Name>> | ReturnType<typeof createObjectInput<Name>> | ReturnType<typeof createTagsInput<Name>> | ReturnType<typeof createSlotInput<Name>>;
1
+ import type { TextInput, LongTextInput, NumberInput, BooleanInput, ColorInput, FileInput, LexicalInput, SelectInput, RadioInput, ObjectInput, DateTimeInput, ComponentInput, TagsInput, SlotInput, ContentEntryInput } from "./types.js";
2
+ export type InputFactory<Name extends string> = ReturnType<typeof createTextInput<Name>> | ReturnType<typeof createLongTextInput<Name>> | ReturnType<typeof createNumberInput<Name>> | ReturnType<typeof createBooleanInput<Name>> | ReturnType<typeof createColorInput<Name>> | ReturnType<typeof createFileInput<Name>> | ReturnType<typeof createDateInput<Name>> | ReturnType<typeof createLexicalInput<Name>> | ReturnType<typeof createSelectInput<Name>> | ReturnType<typeof createRadioInput<Name>> | ReturnType<typeof createObjectInput<Name>> | ReturnType<typeof createTagsInput<Name>> | ReturnType<typeof createSlotInput<Name>> | ReturnType<typeof createContentEntryInput<Name>>;
3
3
  /**
4
4
  * TypeScript Overload Resolution and Input Factory Design
5
5
  *
@@ -122,4 +122,12 @@ export declare function createSlotInput<TName extends string>(input: {
122
122
  export declare function createSlotInput<TName extends string>(input: Omit<SlotInput, "type" | "name">): SlotInput & {
123
123
  name: TName;
124
124
  };
125
+ export declare function createContentEntryInput<TName extends string>(input: {
126
+ name: TName;
127
+ } & Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
128
+ name: TName;
129
+ };
130
+ export declare function createContentEntryInput<TName extends string>(input: Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
131
+ name: TName;
132
+ };
125
133
  export declare function createInput(input: ComponentInput): ComponentInput;
package/createInput.js CHANGED
@@ -1,160 +1,109 @@
1
1
  import { functionConverter } from "./FunctionConverter.js";
2
-
3
- /**
4
- * TypeScript Overload Resolution and Input Factory Design
5
- *
6
- * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:
7
- * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).
8
- * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).
9
- *
10
- * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.
11
- * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.
12
- *
13
- * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.
14
- * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)
15
- * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context
16
- * to resolve the correct type for `TName` even when `name` is omitted from the input.
17
- *
18
- * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,
19
- * so consumers of these factories do not need to worry about the presence of the `name` property in the result.
20
- */
21
- // Text
22
-
23
- export function createTextInput(input) {
24
- return createInput({
25
- type: "text",
26
- renderer: "Webiny/Input",
27
- ...input
28
- });
2
+ function createTextInput(input) {
3
+ return createInput({
4
+ type: "text",
5
+ renderer: "Webiny/Input",
6
+ ...input
7
+ });
29
8
  }
30
-
31
- // Long Text
32
-
33
- export function createLongTextInput(input) {
34
- return createInput({
35
- type: "longText",
36
- renderer: "Webiny/Textarea",
37
- ...input
38
- });
9
+ function createLongTextInput(input) {
10
+ return createInput({
11
+ type: "longText",
12
+ renderer: "Webiny/Textarea",
13
+ ...input
14
+ });
39
15
  }
40
-
41
- // Number
42
-
43
- export function createNumberInput(input) {
44
- return createInput({
45
- type: "number",
46
- renderer: "Webiny/Number",
47
- ...input
48
- });
16
+ function createNumberInput(input) {
17
+ return createInput({
18
+ type: "number",
19
+ renderer: "Webiny/Number",
20
+ ...input
21
+ });
49
22
  }
50
-
51
- // Boolean
52
-
53
- export function createBooleanInput(input) {
54
- return createInput({
55
- type: "boolean",
56
- renderer: "Webiny/Switch",
57
- ...input
58
- });
23
+ function createBooleanInput(input) {
24
+ return createInput({
25
+ type: "boolean",
26
+ renderer: "Webiny/Switch",
27
+ ...input
28
+ });
59
29
  }
60
-
61
- // Color
62
-
63
- export function createColorInput(input) {
64
- return createInput({
65
- type: "color",
66
- renderer: "Webiny/ColorPicker",
67
- ...input
68
- });
30
+ function createColorInput(input) {
31
+ return createInput({
32
+ type: "color",
33
+ renderer: "Webiny/ColorPicker",
34
+ ...input
35
+ });
69
36
  }
70
-
71
- // File
72
-
73
- export function createFileInput(input) {
74
- return createInput({
75
- type: "file",
76
- renderer: "Webiny/FileManager",
77
- ...input
78
- });
37
+ function createFileInput(input) {
38
+ return createInput({
39
+ type: "file",
40
+ renderer: "Webiny/FileManager",
41
+ ...input
42
+ });
79
43
  }
80
-
81
- // Date
82
-
83
- export function createDateInput(input) {
84
- return createInput({
85
- type: "datetime",
86
- renderer: "Webiny/DateTime",
87
- ...input
88
- });
44
+ function createDateInput(input) {
45
+ return createInput({
46
+ type: "datetime",
47
+ renderer: "Webiny/DateTime",
48
+ ...input
49
+ });
89
50
  }
90
-
91
- // Rich Text
92
-
93
- export function createLexicalInput(input) {
94
- return createInput({
95
- type: "lexical",
96
- renderer: "Webiny/Lexical",
97
- ...input
98
- });
51
+ function createLexicalInput(input) {
52
+ return createInput({
53
+ type: "lexical",
54
+ renderer: "Webiny/Lexical",
55
+ ...input
56
+ });
99
57
  }
100
-
101
- // Select
102
-
103
- export function createSelectInput(input) {
104
- return createInput({
105
- type: "select",
106
- renderer: "Webiny/Select",
107
- ...input
108
- });
58
+ function createSelectInput(input) {
59
+ return createInput({
60
+ type: "select",
61
+ renderer: "Webiny/Select",
62
+ ...input
63
+ });
109
64
  }
110
-
111
- // Radio
112
-
113
- export function createRadioInput(input) {
114
- return createInput({
115
- type: "radio",
116
- renderer: "Webiny/RadioGroup",
117
- ...input
118
- });
65
+ function createRadioInput(input) {
66
+ return createInput({
67
+ type: "radio",
68
+ renderer: "Webiny/RadioGroup",
69
+ ...input
70
+ });
119
71
  }
120
-
121
- // Object
122
-
123
- export function createObjectInput(input) {
124
- return createInput({
125
- type: "object",
126
- renderer: "Webiny/Object",
127
- ...input
128
- });
72
+ function createObjectInput(input) {
73
+ return createInput({
74
+ type: "object",
75
+ renderer: "Webiny/Object",
76
+ ...input
77
+ });
129
78
  }
130
-
131
- // Tags
132
-
133
- export function createTagsInput(input) {
134
- return createInput({
135
- type: "text",
136
- list: true,
137
- renderer: "Webiny/Tags",
138
- ...input
139
- });
79
+ function createTagsInput(input) {
80
+ return createInput({
81
+ type: "text",
82
+ list: true,
83
+ renderer: "Webiny/Tags",
84
+ ...input
85
+ });
140
86
  }
141
- export function createSlotInput(input) {
142
- return createInput({
143
- type: "slot",
144
- list: true,
145
- renderer: "Webiny/Slot",
146
- defaultValue: [],
147
- ...input
148
- });
87
+ function createSlotInput(input) {
88
+ return createInput({
89
+ type: "slot",
90
+ list: true,
91
+ renderer: "Webiny/Slot",
92
+ defaultValue: [],
93
+ ...input
94
+ });
149
95
  }
150
-
151
- // Implementation
152
- export function createInput(input) {
153
- if (input.onChange) {
154
- // @ts-expect-error We don't use this function on the frontend, so this is ok.
155
- input.onChange = functionConverter.serialize(input.onChange);
156
- }
157
- return input;
96
+ function createContentEntryInput(input) {
97
+ return createInput({
98
+ type: "contentEntry",
99
+ renderer: "Webiny/ContentEntry",
100
+ ...input
101
+ });
102
+ }
103
+ function createInput(input) {
104
+ if (input.onChange) input.onChange = functionConverter.serialize(input.onChange);
105
+ return input;
158
106
  }
107
+ export { createBooleanInput, createColorInput, createContentEntryInput, createDateInput, createFileInput, createInput, createLexicalInput, createLongTextInput, createNumberInput, createObjectInput, createRadioInput, createSelectInput, createSlotInput, createTagsInput, createTextInput };
159
108
 
160
109
  //# sourceMappingURL=createInput.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["functionConverter","createTextInput","input","createInput","type","renderer","createLongTextInput","createNumberInput","createBooleanInput","createColorInput","createFileInput","createDateInput","createLexicalInput","createSelectInput","createRadioInput","createObjectInput","createTagsInput","list","createSlotInput","defaultValue","onChange","serialize"],"sources":["createInput.ts"],"sourcesContent":["import type {\n TextInput,\n LongTextInput,\n NumberInput,\n BooleanInput,\n ColorInput,\n FileInput,\n LexicalInput,\n SelectInput,\n RadioInput,\n ObjectInput,\n DateTimeInput,\n ComponentInput,\n TagsInput,\n SlotInput\n} from \"./types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\nexport type InputFactory<Name extends string> =\n | ReturnType<typeof createTextInput<Name>>\n | ReturnType<typeof createLongTextInput<Name>>\n | ReturnType<typeof createNumberInput<Name>>\n | ReturnType<typeof createBooleanInput<Name>>\n | ReturnType<typeof createColorInput<Name>>\n | ReturnType<typeof createFileInput<Name>>\n | ReturnType<typeof createDateInput<Name>>\n | ReturnType<typeof createLexicalInput<Name>>\n | ReturnType<typeof createSelectInput<Name>>\n | ReturnType<typeof createRadioInput<Name>>\n | ReturnType<typeof createObjectInput<Name>>\n | ReturnType<typeof createTagsInput<Name>>\n | ReturnType<typeof createSlotInput<Name>>;\n\n/**\n * TypeScript Overload Resolution and Input Factory Design\n *\n * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:\n * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).\n * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).\n *\n * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.\n * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.\n *\n * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.\n * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)\n * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context\n * to resolve the correct type for `TName` even when `name` is omitted from the input.\n *\n * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,\n * so consumers of these factories do not need to worry about the presence of the `name` property in the result.\n */\n// Text\nexport function createTextInput<TName extends string>(\n input: { name: TName } & Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(\n input: Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(input: any): TextInput & { name: TName } {\n return createInput({\n type: \"text\",\n renderer: \"Webiny/Input\",\n ...input\n }) as TextInput & { name: TName };\n}\n\n// Long Text\nexport function createLongTextInput<TName extends string>(\n input: { name: TName } & Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: any\n): LongTextInput & { name: TName } {\n return createInput({\n type: \"longText\",\n renderer: \"Webiny/Textarea\",\n ...input\n }) as LongTextInput & { name: TName };\n}\n\n// Number\nexport function createNumberInput<TName extends string>(\n input: { name: TName } & Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(\n input: Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(input: any): NumberInput & { name: TName } {\n return createInput({\n type: \"number\",\n renderer: \"Webiny/Number\",\n ...input\n }) as NumberInput & { name: TName };\n}\n\n// Boolean\nexport function createBooleanInput<TName extends string>(\n input: { name: TName } & Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: any\n): BooleanInput & { name: TName } {\n return createInput({\n type: \"boolean\",\n renderer: \"Webiny/Switch\",\n ...input\n }) as BooleanInput & { name: TName };\n}\n\n// Color\nexport function createColorInput<TName extends string>(\n input: { name: TName } & Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(\n input: Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(input: any): ColorInput & { name: TName } {\n return createInput({\n type: \"color\",\n renderer: \"Webiny/ColorPicker\",\n ...input\n }) as ColorInput & { name: TName };\n}\n\n// File\nexport function createFileInput<TName extends string>(\n input: { name: TName } & Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(\n input: Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(input: any): FileInput & { name: TName } {\n return createInput({\n type: \"file\",\n renderer: \"Webiny/FileManager\",\n ...input\n }) as FileInput & { name: TName };\n}\n\n// Date\nexport function createDateInput<TName extends string>(\n input: { name: TName } & Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(\n input: Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(input: any): DateTimeInput & { name: TName } {\n return createInput({\n type: \"datetime\",\n renderer: \"Webiny/DateTime\",\n ...input\n }) as DateTimeInput & { name: TName };\n}\n\n// Rich Text\nexport function createLexicalInput<TName extends string>(\n input: { name: TName } & Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: any\n): LexicalInput & { name: TName } {\n return createInput({\n type: \"lexical\",\n renderer: \"Webiny/Lexical\",\n ...input\n }) as LexicalInput & { name: TName };\n}\n\n// Select\nexport function createSelectInput<TName extends string>(\n input: { name: TName } & Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(\n input: Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(input: any): SelectInput & { name: TName } {\n return createInput({\n type: \"select\",\n renderer: \"Webiny/Select\",\n ...input\n }) as SelectInput & { name: TName };\n}\n\n// Radio\nexport function createRadioInput<TName extends string>(\n input: { name: TName } & Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(\n input: Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(input: any): RadioInput & { name: TName } {\n return createInput({\n type: \"radio\",\n renderer: \"Webiny/RadioGroup\",\n ...input\n }) as RadioInput & { name: TName };\n}\n\n// Object\nexport function createObjectInput<TName extends string>(\n input: { name: TName } & Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(\n input: Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(input: any): ObjectInput & { name: TName } {\n return createInput({\n type: \"object\",\n renderer: \"Webiny/Object\",\n ...input\n }) as ObjectInput & { name: TName };\n}\n\n// Tags\nexport function createTagsInput<TName extends string>(\n input: { name: TName } & Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(\n input: Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(input: any): TagsInput & { name: TName } {\n return createInput({\n type: \"text\",\n list: true,\n renderer: \"Webiny/Tags\",\n ...input\n }) as TagsInput & { name: TName };\n}\n\nexport function createSlotInput<TName extends string>(\n input: { name: TName } & Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(\n input: Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(input: any): SlotInput & { name: TName } {\n return createInput({\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n defaultValue: [],\n ...input\n }) as SlotInput & { name: TName };\n}\n\n// Implementation\nexport function createInput(input: ComponentInput): ComponentInput {\n if (input.onChange) {\n // @ts-expect-error We don't use this function on the frontend, so this is ok.\n input.onChange = functionConverter.serialize(input.onChange!);\n }\n return input;\n}\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"createInput.js","sources":["../src/createInput.ts"],"sourcesContent":["import type {\n TextInput,\n LongTextInput,\n NumberInput,\n BooleanInput,\n ColorInput,\n FileInput,\n LexicalInput,\n SelectInput,\n RadioInput,\n ObjectInput,\n DateTimeInput,\n ComponentInput,\n TagsInput,\n SlotInput,\n ContentEntryInput\n} from \"./types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\nexport type InputFactory<Name extends string> =\n | ReturnType<typeof createTextInput<Name>>\n | ReturnType<typeof createLongTextInput<Name>>\n | ReturnType<typeof createNumberInput<Name>>\n | ReturnType<typeof createBooleanInput<Name>>\n | ReturnType<typeof createColorInput<Name>>\n | ReturnType<typeof createFileInput<Name>>\n | ReturnType<typeof createDateInput<Name>>\n | ReturnType<typeof createLexicalInput<Name>>\n | ReturnType<typeof createSelectInput<Name>>\n | ReturnType<typeof createRadioInput<Name>>\n | ReturnType<typeof createObjectInput<Name>>\n | ReturnType<typeof createTagsInput<Name>>\n | ReturnType<typeof createSlotInput<Name>>\n | ReturnType<typeof createContentEntryInput<Name>>;\n\n/**\n * TypeScript Overload Resolution and Input Factory Design\n *\n * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:\n * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).\n * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).\n *\n * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.\n * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.\n *\n * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.\n * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)\n * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context\n * to resolve the correct type for `TName` even when `name` is omitted from the input.\n *\n * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,\n * so consumers of these factories do not need to worry about the presence of the `name` property in the result.\n */\n// Text\nexport function createTextInput<TName extends string>(\n input: { name: TName } & Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(\n input: Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(input: any): TextInput & { name: TName } {\n return createInput({\n type: \"text\",\n renderer: \"Webiny/Input\",\n ...input\n }) as TextInput & { name: TName };\n}\n\n// Long Text\nexport function createLongTextInput<TName extends string>(\n input: { name: TName } & Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: any\n): LongTextInput & { name: TName } {\n return createInput({\n type: \"longText\",\n renderer: \"Webiny/Textarea\",\n ...input\n }) as LongTextInput & { name: TName };\n}\n\n// Number\nexport function createNumberInput<TName extends string>(\n input: { name: TName } & Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(\n input: Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(input: any): NumberInput & { name: TName } {\n return createInput({\n type: \"number\",\n renderer: \"Webiny/Number\",\n ...input\n }) as NumberInput & { name: TName };\n}\n\n// Boolean\nexport function createBooleanInput<TName extends string>(\n input: { name: TName } & Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: any\n): BooleanInput & { name: TName } {\n return createInput({\n type: \"boolean\",\n renderer: \"Webiny/Switch\",\n ...input\n }) as BooleanInput & { name: TName };\n}\n\n// Color\nexport function createColorInput<TName extends string>(\n input: { name: TName } & Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(\n input: Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(input: any): ColorInput & { name: TName } {\n return createInput({\n type: \"color\",\n renderer: \"Webiny/ColorPicker\",\n ...input\n }) as ColorInput & { name: TName };\n}\n\n// File\nexport function createFileInput<TName extends string>(\n input: { name: TName } & Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(\n input: Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(input: any): FileInput & { name: TName } {\n return createInput({\n type: \"file\",\n renderer: \"Webiny/FileManager\",\n ...input\n }) as FileInput & { name: TName };\n}\n\n// Date\nexport function createDateInput<TName extends string>(\n input: { name: TName } & Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(\n input: Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(input: any): DateTimeInput & { name: TName } {\n return createInput({\n type: \"datetime\",\n renderer: \"Webiny/DateTime\",\n ...input\n }) as DateTimeInput & { name: TName };\n}\n\n// Rich Text\nexport function createLexicalInput<TName extends string>(\n input: { name: TName } & Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: any\n): LexicalInput & { name: TName } {\n return createInput({\n type: \"lexical\",\n renderer: \"Webiny/Lexical\",\n ...input\n }) as LexicalInput & { name: TName };\n}\n\n// Select\nexport function createSelectInput<TName extends string>(\n input: { name: TName } & Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(\n input: Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(input: any): SelectInput & { name: TName } {\n return createInput({\n type: \"select\",\n renderer: \"Webiny/Select\",\n ...input\n }) as SelectInput & { name: TName };\n}\n\n// Radio\nexport function createRadioInput<TName extends string>(\n input: { name: TName } & Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(\n input: Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(input: any): RadioInput & { name: TName } {\n return createInput({\n type: \"radio\",\n renderer: \"Webiny/RadioGroup\",\n ...input\n }) as RadioInput & { name: TName };\n}\n\n// Object\nexport function createObjectInput<TName extends string>(\n input: { name: TName } & Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(\n input: Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(input: any): ObjectInput & { name: TName } {\n return createInput({\n type: \"object\",\n renderer: \"Webiny/Object\",\n ...input\n }) as ObjectInput & { name: TName };\n}\n\n// Tags\nexport function createTagsInput<TName extends string>(\n input: { name: TName } & Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(\n input: Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(input: any): TagsInput & { name: TName } {\n return createInput({\n type: \"text\",\n list: true,\n renderer: \"Webiny/Tags\",\n ...input\n }) as TagsInput & { name: TName };\n}\n\nexport function createSlotInput<TName extends string>(\n input: { name: TName } & Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(\n input: Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(input: any): SlotInput & { name: TName } {\n return createInput({\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n defaultValue: [],\n ...input\n }) as SlotInput & { name: TName };\n}\n\n// Content Entry\nexport function createContentEntryInput<TName extends string>(\n input: { name: TName } & Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: any\n): ContentEntryInput & { name: TName } {\n return createInput({\n type: \"contentEntry\",\n renderer: \"Webiny/ContentEntry\",\n ...input\n }) as ContentEntryInput & { name: TName };\n}\n\n// Implementation\nexport function createInput(input: ComponentInput): ComponentInput {\n if (input.onChange) {\n // @ts-expect-error We don't use this function on the frontend, so this is ok.\n input.onChange = functionConverter.serialize(input.onChange!);\n }\n return input;\n}\n"],"names":["createTextInput","input","createInput","createLongTextInput","createNumberInput","createBooleanInput","createColorInput","createFileInput","createDateInput","createLexicalInput","createSelectInput","createRadioInput","createObjectInput","createTagsInput","createSlotInput","createContentEntryInput","functionConverter"],"mappings":";AA4DO,SAASA,gBAAsCC,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASE,oBACZF,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASG,kBAAwCH,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASI,mBACZJ,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASK,iBAAuCL,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASM,gBAAsCN,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASO,gBAAsCP,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASQ,mBACZR,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASS,kBAAwCT,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASU,iBAAuCV,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASW,kBAAwCX,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASY,gBAAsCZ,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAQO,SAASa,gBAAsCb,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,cAAc,EAAE;QAChB,GAAGD,KAAK;IACZ;AACJ;AASO,SAASc,wBACZd,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAGO,SAASC,YAAYD,KAAqB;IAC7C,IAAIA,MAAM,QAAQ,EAEdA,MAAM,QAAQ,GAAGe,kBAAkB,SAAS,CAACf,MAAM,QAAQ;IAE/D,OAAOA;AACX"}
package/createTheme.js CHANGED
@@ -1,5 +1,4 @@
1
- export const createTheme = theme => {
2
- return theme;
3
- };
1
+ const createTheme = (theme)=>theme;
2
+ export { createTheme };
4
3
 
5
4
  //# sourceMappingURL=createTheme.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createTheme","theme"],"sources":["createTheme.ts"],"sourcesContent":["import type { WebsiteBuilderThemeInput } from \"~/types/WebsiteBuilderTheme.js\";\n\nexport type { WebsiteBuilderThemeInput };\n\nexport const createTheme = (theme: WebsiteBuilderThemeInput) => {\n return theme;\n};\n"],"mappings":"AAIA,OAAO,MAAMA,WAAW,GAAIC,KAA+B,IAAK;EAC5D,OAAOA,KAAK;AAChB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"createTheme.js","sources":["../src/createTheme.ts"],"sourcesContent":["import type { WebsiteBuilderThemeInput } from \"~/types/WebsiteBuilderTheme.js\";\n\nexport type { WebsiteBuilderThemeInput };\n\nexport const createTheme = (theme: WebsiteBuilderThemeInput) => {\n return theme;\n};\n"],"names":["createTheme","theme"],"mappings":"AAIO,MAAMA,cAAc,CAACC,QACjBA"}
@@ -1,6 +1,14 @@
1
+ import { type HeadersConfig } from "@webiny/sdk";
1
2
  interface QueryParams {
2
3
  query: string;
3
4
  variables: Record<string, any>;
5
+ }
6
+ export interface ApiClientConfig {
7
+ apiHost: string;
8
+ apiKey: string;
9
+ apiTenant: string;
10
+ /** Extra headers sent with every request; a function is called before each request. */
11
+ headers?: HeadersConfig;
4
12
  preview?: boolean;
5
13
  }
6
14
  type WithPath<T> = T & {
@@ -8,11 +16,11 @@ type WithPath<T> = T & {
8
16
  next?: Record<string, any>;
9
17
  };
10
18
  export declare class ApiClient {
11
- private readonly apiHost;
12
- private readonly apiKey;
13
- private readonly apiTenant;
14
- constructor(apiHost: string, apiKey: string, apiTenant: string);
19
+ private readonly config;
20
+ constructor(config: ApiClientConfig);
15
21
  fetch({ headers, path, ...params }: WithPath<RequestInit>): Promise<any>;
16
- query({ query, variables, preview }: QueryParams): Promise<any>;
22
+ query({ query, variables }: QueryParams, options?: {
23
+ noStore?: boolean;
24
+ }): Promise<any>;
17
25
  }
18
26
  export {};