@embeddables/cli 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/dist/auth/index.d.ts +43 -0
  2. package/dist/auth/index.d.ts.map +1 -0
  3. package/dist/auth/index.js +102 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +210 -0
  7. package/dist/command-history.d.ts +13 -0
  8. package/dist/command-history.d.ts.map +1 -0
  9. package/dist/command-history.js +34 -0
  10. package/dist/commands/branch.d.ts +4 -0
  11. package/dist/commands/branch.d.ts.map +1 -0
  12. package/dist/commands/branch.js +67 -0
  13. package/dist/commands/build-workbench.d.ts +5 -0
  14. package/dist/commands/build-workbench.d.ts.map +1 -0
  15. package/dist/commands/build-workbench.js +116 -0
  16. package/dist/commands/build.d.ts +8 -0
  17. package/dist/commands/build.d.ts.map +1 -0
  18. package/dist/commands/build.js +60 -0
  19. package/dist/commands/builder-open.d.ts +4 -0
  20. package/dist/commands/builder-open.d.ts.map +1 -0
  21. package/dist/commands/builder-open.js +74 -0
  22. package/dist/commands/dev.d.ts +12 -0
  23. package/dist/commands/dev.d.ts.map +1 -0
  24. package/dist/commands/dev.js +226 -0
  25. package/dist/commands/diff.d.ts +76 -0
  26. package/dist/commands/diff.d.ts.map +1 -0
  27. package/dist/commands/diff.js +653 -0
  28. package/dist/commands/experiments-connect.d.ts +6 -0
  29. package/dist/commands/experiments-connect.d.ts.map +1 -0
  30. package/dist/commands/experiments-connect.js +140 -0
  31. package/dist/commands/feedback.d.ts +29 -0
  32. package/dist/commands/feedback.d.ts.map +1 -0
  33. package/dist/commands/feedback.js +267 -0
  34. package/dist/commands/init.d.ts +5 -0
  35. package/dist/commands/init.d.ts.map +1 -0
  36. package/dist/commands/init.js +384 -0
  37. package/dist/commands/inspect.d.ts +9 -0
  38. package/dist/commands/inspect.d.ts.map +1 -0
  39. package/dist/commands/inspect.js +293 -0
  40. package/dist/commands/login.d.ts +2 -0
  41. package/dist/commands/login.d.ts.map +1 -0
  42. package/dist/commands/login.js +117 -0
  43. package/dist/commands/logout.d.ts +2 -0
  44. package/dist/commands/logout.d.ts.map +1 -0
  45. package/dist/commands/logout.js +19 -0
  46. package/dist/commands/pull.d.ts +16 -0
  47. package/dist/commands/pull.d.ts.map +1 -0
  48. package/dist/commands/pull.js +395 -0
  49. package/dist/commands/save.d.ts +30 -0
  50. package/dist/commands/save.d.ts.map +1 -0
  51. package/dist/commands/save.js +597 -0
  52. package/dist/commands/upgrade.d.ts +2 -0
  53. package/dist/commands/upgrade.d.ts.map +1 -0
  54. package/dist/commands/upgrade.js +50 -0
  55. package/dist/compiler/errors.d.ts +20 -0
  56. package/dist/compiler/errors.d.ts.map +1 -0
  57. package/dist/compiler/errors.js +35 -0
  58. package/dist/compiler/evalStatic.d.ts +3 -0
  59. package/dist/compiler/evalStatic.d.ts.map +1 -0
  60. package/dist/compiler/evalStatic.js +57 -0
  61. package/dist/compiler/flatten.js +1 -0
  62. package/dist/compiler/helpers/duplicateIds.d.ts +9 -0
  63. package/dist/compiler/helpers/duplicateIds.d.ts.map +1 -0
  64. package/dist/compiler/helpers/duplicateIds.js +71 -0
  65. package/dist/compiler/helpers/numericLeadingKeys.d.ts +8 -0
  66. package/dist/compiler/helpers/numericLeadingKeys.d.ts.map +1 -0
  67. package/dist/compiler/helpers/numericLeadingKeys.js +17 -0
  68. package/dist/compiler/index.d.ts +18 -0
  69. package/dist/compiler/index.d.ts.map +1 -0
  70. package/dist/compiler/index.js +1272 -0
  71. package/dist/compiler/parsePage.d.ts +15 -0
  72. package/dist/compiler/parsePage.d.ts.map +1 -0
  73. package/dist/compiler/parsePage.js +654 -0
  74. package/dist/compiler/registry.d.ts +4 -0
  75. package/dist/compiler/registry.d.ts.map +1 -0
  76. package/dist/compiler/registry.js +44 -0
  77. package/dist/compiler/reverse.d.ts +23 -0
  78. package/dist/compiler/reverse.d.ts.map +1 -0
  79. package/dist/compiler/reverse.js +1920 -0
  80. package/dist/compiler/types.d.ts +21 -0
  81. package/dist/compiler/types.d.ts.map +1 -0
  82. package/dist/compiler/types.js +1 -0
  83. package/dist/components/index.d.ts +21 -0
  84. package/dist/components/index.d.ts.map +1 -0
  85. package/dist/components/index.js +21 -0
  86. package/dist/components/primitives/BaseComponent.d.ts +33 -0
  87. package/dist/components/primitives/BaseComponent.d.ts.map +1 -0
  88. package/dist/components/primitives/BaseComponent.js +26 -0
  89. package/dist/components/primitives/BookMeeting.d.ts +18 -0
  90. package/dist/components/primitives/BookMeeting.d.ts.map +1 -0
  91. package/dist/components/primitives/BookMeeting.js +5 -0
  92. package/dist/components/primitives/Chart.d.ts +41 -0
  93. package/dist/components/primitives/Chart.d.ts.map +1 -0
  94. package/dist/components/primitives/Chart.js +5 -0
  95. package/dist/components/primitives/Container.d.ts +8 -0
  96. package/dist/components/primitives/Container.d.ts.map +1 -0
  97. package/dist/components/primitives/Container.js +5 -0
  98. package/dist/components/primitives/CustomButton.d.ts +37 -0
  99. package/dist/components/primitives/CustomButton.d.ts.map +1 -0
  100. package/dist/components/primitives/CustomButton.js +10 -0
  101. package/dist/components/primitives/CustomHTML.d.ts +8 -0
  102. package/dist/components/primitives/CustomHTML.d.ts.map +1 -0
  103. package/dist/components/primitives/CustomHTML.js +5 -0
  104. package/dist/components/primitives/FileUpload.d.ts +18 -0
  105. package/dist/components/primitives/FileUpload.d.ts.map +1 -0
  106. package/dist/components/primitives/FileUpload.js +16 -0
  107. package/dist/components/primitives/InputBox.d.ts +34 -0
  108. package/dist/components/primitives/InputBox.d.ts.map +1 -0
  109. package/dist/components/primitives/InputBox.js +25 -0
  110. package/dist/components/primitives/Lottie.d.ts +11 -0
  111. package/dist/components/primitives/Lottie.d.ts.map +1 -0
  112. package/dist/components/primitives/Lottie.js +5 -0
  113. package/dist/components/primitives/MediaEmbed.d.ts +13 -0
  114. package/dist/components/primitives/MediaEmbed.d.ts.map +1 -0
  115. package/dist/components/primitives/MediaEmbed.js +6 -0
  116. package/dist/components/primitives/MediaImage.d.ts +8 -0
  117. package/dist/components/primitives/MediaImage.d.ts.map +1 -0
  118. package/dist/components/primitives/MediaImage.js +5 -0
  119. package/dist/components/primitives/OptionSelector.d.ts +38 -0
  120. package/dist/components/primitives/OptionSelector.d.ts.map +1 -0
  121. package/dist/components/primitives/OptionSelector.js +8 -0
  122. package/dist/components/primitives/PaypalCheckout.d.ts +25 -0
  123. package/dist/components/primitives/PaypalCheckout.d.ts.map +1 -0
  124. package/dist/components/primitives/PaypalCheckout.js +5 -0
  125. package/dist/components/primitives/PlainText.d.ts +6 -0
  126. package/dist/components/primitives/PlainText.d.ts.map +1 -0
  127. package/dist/components/primitives/PlainText.js +5 -0
  128. package/dist/components/primitives/ProgressBar.d.ts +15 -0
  129. package/dist/components/primitives/ProgressBar.d.ts.map +1 -0
  130. package/dist/components/primitives/ProgressBar.js +5 -0
  131. package/dist/components/primitives/RichText.d.ts +6 -0
  132. package/dist/components/primitives/RichText.d.ts.map +1 -0
  133. package/dist/components/primitives/RichText.js +5 -0
  134. package/dist/components/primitives/RichTextMarkdown.d.ts +6 -0
  135. package/dist/components/primitives/RichTextMarkdown.d.ts.map +1 -0
  136. package/dist/components/primitives/RichTextMarkdown.js +5 -0
  137. package/dist/components/primitives/Rive.d.ts +16 -0
  138. package/dist/components/primitives/Rive.d.ts.map +1 -0
  139. package/dist/components/primitives/Rive.js +8 -0
  140. package/dist/components/primitives/StripeCheckout.d.ts +52 -0
  141. package/dist/components/primitives/StripeCheckout.d.ts.map +1 -0
  142. package/dist/components/primitives/StripeCheckout.js +5 -0
  143. package/dist/components/primitives/StripeCheckout2.d.ts +30 -0
  144. package/dist/components/primitives/StripeCheckout2.d.ts.map +1 -0
  145. package/dist/components/primitives/StripeCheckout2.js +7 -0
  146. package/dist/config/index.d.ts +23 -0
  147. package/dist/config/index.d.ts.map +1 -0
  148. package/dist/config/index.js +42 -0
  149. package/dist/constants.d.ts +9 -0
  150. package/dist/constants.d.ts.map +1 -0
  151. package/dist/constants.js +9 -0
  152. package/dist/helpers/TEMP helpers file.d.ts +1 -0
  153. package/dist/helpers/TEMP helpers file.d.ts.map +1 -0
  154. package/dist/helpers/TEMP helpers file.js +1 -0
  155. package/dist/helpers/dates.d.ts +5 -0
  156. package/dist/helpers/dates.d.ts.map +1 -0
  157. package/dist/helpers/dates.js +7 -0
  158. package/dist/helpers/json.d.ts +47 -0
  159. package/dist/helpers/json.d.ts.map +1 -0
  160. package/dist/helpers/json.js +622 -0
  161. package/dist/helpers/prompt.d.ts +15 -0
  162. package/dist/helpers/prompt.d.ts.map +1 -0
  163. package/dist/helpers/prompt.js +35 -0
  164. package/dist/helpers/utils.d.ts +13 -0
  165. package/dist/helpers/utils.d.ts.map +1 -0
  166. package/dist/helpers/utils.js +28 -0
  167. package/dist/logger.d.ts +11 -0
  168. package/dist/logger.d.ts.map +1 -0
  169. package/dist/logger.js +21 -0
  170. package/dist/patches/prompts-escape.d.ts +14 -0
  171. package/dist/patches/prompts-escape.d.ts.map +1 -0
  172. package/dist/patches/prompts-escape.js +23 -0
  173. package/dist/prompts/branches.d.ts +20 -0
  174. package/dist/prompts/branches.d.ts.map +1 -0
  175. package/dist/prompts/branches.js +86 -0
  176. package/dist/prompts/embeddables.d.ts +43 -0
  177. package/dist/prompts/embeddables.d.ts.map +1 -0
  178. package/dist/prompts/embeddables.js +200 -0
  179. package/dist/prompts/experiments.d.ts +28 -0
  180. package/dist/prompts/experiments.d.ts.map +1 -0
  181. package/dist/prompts/experiments.js +89 -0
  182. package/dist/prompts/index.d.ts +11 -0
  183. package/dist/prompts/index.d.ts.map +1 -0
  184. package/dist/prompts/index.js +6 -0
  185. package/dist/prompts/projects.d.ts +22 -0
  186. package/dist/prompts/projects.d.ts.map +1 -0
  187. package/dist/prompts/projects.js +92 -0
  188. package/dist/prompts/versions.d.ts +18 -0
  189. package/dist/prompts/versions.d.ts.map +1 -0
  190. package/dist/prompts/versions.js +95 -0
  191. package/dist/proxy/injectApiInterceptor.d.ts +6 -0
  192. package/dist/proxy/injectApiInterceptor.d.ts.map +1 -0
  193. package/dist/proxy/injectApiInterceptor.js +66 -0
  194. package/dist/proxy/injectReload.d.ts +2 -0
  195. package/dist/proxy/injectReload.d.ts.map +1 -0
  196. package/dist/proxy/injectReload.js +14 -0
  197. package/dist/proxy/injectWorkbench.d.ts +5 -0
  198. package/dist/proxy/injectWorkbench.d.ts.map +1 -0
  199. package/dist/proxy/injectWorkbench.js +22 -0
  200. package/dist/proxy/server.d.ts +11 -0
  201. package/dist/proxy/server.d.ts.map +1 -0
  202. package/dist/proxy/server.js +304 -0
  203. package/dist/proxy/sse.d.ts +5 -0
  204. package/dist/proxy/sse.d.ts.map +1 -0
  205. package/dist/proxy/sse.js +17 -0
  206. package/dist/sentry-context.d.ts +48 -0
  207. package/dist/sentry-context.d.ts.map +1 -0
  208. package/dist/sentry-context.js +156 -0
  209. package/dist/stdout.d.ts +61 -0
  210. package/dist/stdout.d.ts.map +1 -0
  211. package/dist/stdout.js +163 -0
  212. package/dist/types-builder.d.ts +800 -0
  213. package/dist/types-builder.d.ts.map +1 -0
  214. package/dist/types-builder.js +20 -0
  215. package/dist/workbench/ActionsPanel.d.ts +6 -0
  216. package/dist/workbench/ActionsPanel.d.ts.map +1 -0
  217. package/dist/workbench/ActionsPanel.js +47 -0
  218. package/dist/workbench/AutofillPanel.d.ts +6 -0
  219. package/dist/workbench/AutofillPanel.d.ts.map +1 -0
  220. package/dist/workbench/AutofillPanel.js +543 -0
  221. package/dist/workbench/ComputedFieldsPanel.d.ts +6 -0
  222. package/dist/workbench/ComputedFieldsPanel.d.ts.map +1 -0
  223. package/dist/workbench/ComputedFieldsPanel.js +31 -0
  224. package/dist/workbench/ExperimentsPanel.d.ts +6 -0
  225. package/dist/workbench/ExperimentsPanel.d.ts.map +1 -0
  226. package/dist/workbench/ExperimentsPanel.js +182 -0
  227. package/dist/workbench/FieldEditorPanel.d.ts +9 -0
  228. package/dist/workbench/FieldEditorPanel.d.ts.map +1 -0
  229. package/dist/workbench/FieldEditorPanel.js +650 -0
  230. package/dist/workbench/InspectorPanel.d.ts +6 -0
  231. package/dist/workbench/InspectorPanel.d.ts.map +1 -0
  232. package/dist/workbench/InspectorPanel.js +341 -0
  233. package/dist/workbench/PageNavigator.d.ts +6 -0
  234. package/dist/workbench/PageNavigator.d.ts.map +1 -0
  235. package/dist/workbench/PageNavigator.js +123 -0
  236. package/dist/workbench/SchemaPanel.d.ts +6 -0
  237. package/dist/workbench/SchemaPanel.d.ts.map +1 -0
  238. package/dist/workbench/SchemaPanel.js +222 -0
  239. package/dist/workbench/UserDataPanel.d.ts +6 -0
  240. package/dist/workbench/UserDataPanel.d.ts.map +1 -0
  241. package/dist/workbench/UserDataPanel.js +350 -0
  242. package/dist/workbench/WorkbenchApp.d.ts +7 -0
  243. package/dist/workbench/WorkbenchApp.d.ts.map +1 -0
  244. package/dist/workbench/WorkbenchApp.js +193 -0
  245. package/dist/workbench/cloudflare-worker/README.md +31 -0
  246. package/dist/workbench/cloudflare-worker/public/workbench.css +1614 -0
  247. package/dist/workbench/cloudflare-worker/public/workbench.js +77 -0
  248. package/dist/workbench/cloudflare-worker/worker.js +40 -0
  249. package/dist/workbench/cloudflare-worker/wrangler.toml +10 -0
  250. package/dist/workbench/index.d.ts +10 -0
  251. package/dist/workbench/index.d.ts.map +1 -0
  252. package/dist/workbench/index.js +44 -0
  253. package/dist/workbench/workbench.css +1614 -0
  254. package/dist/workbench/workbench.js +77 -0
  255. package/package.json +1 -1
@@ -0,0 +1,622 @@
1
+ export function translateJsonDiffToEditCommands({ previousObject = {}, currentObject = {}, path = [], objectMatchKeys = {}, basePath = [], forceObjectKeyInFirstLevelIteration, extraAlternativePathObjectMatchKeys = [], }) {
2
+ const commands = [];
3
+ //* Find which key to identify objects an array by. Default is 'id', but can be overridden by objectMatchKeys
4
+ const defaultObjectMatchKeys = {
5
+ load_tags: 'url',
6
+ content_sources: 'key',
7
+ };
8
+ objectMatchKeys = { ...defaultObjectMatchKeys, ...objectMatchKeys };
9
+ let objectMatchKey = undefined; //* default value
10
+ //* Find the latest occurrence of a key in the path that matches objectMatchKeys
11
+ for (let i = path.length - 1; i >= 0; i--) {
12
+ const pathSegment = path[i];
13
+ if (objectMatchKeys[pathSegment]) {
14
+ objectMatchKey = objectMatchKeys[pathSegment];
15
+ break;
16
+ }
17
+ }
18
+ if (forceObjectKeyInFirstLevelIteration)
19
+ objectMatchKey = forceObjectKeyInFirstLevelIteration;
20
+ if (!previousObject && !currentObject)
21
+ return commands;
22
+ if (Array.isArray(previousObject) && Array.isArray(currentObject)) {
23
+ const arrayCommands = translateArrayJsonDiffToEditCommands({
24
+ path,
25
+ previousArray: previousObject,
26
+ currentArray: currentObject,
27
+ objectMatchKeys,
28
+ basePath,
29
+ extraAlternativePathObjectMatchKeys,
30
+ });
31
+ commands.push(...arrayCommands);
32
+ return commands;
33
+ }
34
+ //* Get all unique keys from both objects
35
+ const previousKeys = new Set(Object.keys(previousObject || {}));
36
+ const currentKeys = new Set(Object.keys(currentObject || {}));
37
+ const allKeys = new Set(Array.from(previousKeys).concat(Array.from(currentKeys)));
38
+ allKeys.forEach((key) => {
39
+ const currentPath = [...path, key];
40
+ const previousValue = previousObject?.[key];
41
+ const currentValue = currentObject?.[key];
42
+ //* Property was removed
43
+ if (previousKeys.has(key) && !currentKeys.has(key)) {
44
+ if (currentPath[currentPath.length - 1] === key) {
45
+ commands.push({
46
+ type: 'remove',
47
+ data: {
48
+ path: [...basePath, ...currentPath.slice(0, -1)],
49
+ propertyToRemove: key,
50
+ objectMatchKey,
51
+ alternativePathObjectMatchKeys: objectMatchKey
52
+ ? [...extraAlternativePathObjectMatchKeys, objectMatchKey]
53
+ : !!extraAlternativePathObjectMatchKeys.length
54
+ ? extraAlternativePathObjectMatchKeys
55
+ : undefined,
56
+ },
57
+ });
58
+ }
59
+ else {
60
+ commands.push({
61
+ type: 'remove',
62
+ data: {
63
+ path: [...basePath, ...currentPath],
64
+ propertyToRemove: key,
65
+ objectMatchKey,
66
+ alternativePathObjectMatchKeys: objectMatchKey
67
+ ? [...extraAlternativePathObjectMatchKeys, objectMatchKey]
68
+ : !!extraAlternativePathObjectMatchKeys.length
69
+ ? extraAlternativePathObjectMatchKeys
70
+ : undefined,
71
+ },
72
+ });
73
+ }
74
+ return;
75
+ }
76
+ //* Property was added
77
+ if (!previousKeys.has(key) && currentKeys.has(key)) {
78
+ commands.push({
79
+ type: 'set',
80
+ data: {
81
+ path: [...basePath, ...currentPath],
82
+ value: currentValue,
83
+ objectMatchKey,
84
+ alternativePathObjectMatchKeys: objectMatchKey
85
+ ? [...extraAlternativePathObjectMatchKeys, objectMatchKey]
86
+ : !!extraAlternativePathObjectMatchKeys.length
87
+ ? extraAlternativePathObjectMatchKeys
88
+ : undefined,
89
+ },
90
+ });
91
+ return;
92
+ }
93
+ //* Property exists in both - check for changes
94
+ if (previousKeys.has(key) && currentKeys.has(key)) {
95
+ //* If both values are arrays, handle array comparison
96
+ if (Array.isArray(previousValue) && Array.isArray(currentValue)) {
97
+ const arrayCommands = translateArrayJsonDiffToEditCommands({
98
+ path: currentPath,
99
+ previousArray: previousValue,
100
+ currentArray: currentValue,
101
+ objectMatchKeys,
102
+ basePath,
103
+ extraAlternativePathObjectMatchKeys,
104
+ });
105
+ commands.push(...arrayCommands);
106
+ }
107
+ //* If both values are objects (but not arrays), recurse
108
+ else if (previousValue &&
109
+ currentValue &&
110
+ typeof previousValue === 'object' &&
111
+ typeof currentValue === 'object' &&
112
+ !Array.isArray(previousValue) &&
113
+ !Array.isArray(currentValue)) {
114
+ const nestedCommands = translateJsonDiffToEditCommands({
115
+ path: currentPath,
116
+ previousObject: previousValue,
117
+ currentObject: currentValue,
118
+ objectMatchKeys,
119
+ basePath,
120
+ extraAlternativePathObjectMatchKeys,
121
+ });
122
+ commands.push(...nestedCommands);
123
+ }
124
+ //* Primitive value comparison
125
+ else if (!deepEqual(previousValue, currentValue)) {
126
+ commands.push({
127
+ type: 'set',
128
+ data: {
129
+ path: [...basePath, ...currentPath],
130
+ value: currentValue,
131
+ objectMatchKey,
132
+ alternativePathObjectMatchKeys: objectMatchKey
133
+ ? [...extraAlternativePathObjectMatchKeys, objectMatchKey]
134
+ : !!extraAlternativePathObjectMatchKeys.length
135
+ ? extraAlternativePathObjectMatchKeys
136
+ : undefined,
137
+ },
138
+ });
139
+ }
140
+ }
141
+ });
142
+ return commands;
143
+ }
144
+ export function translateArrayJsonDiffToEditCommands({ previousArray = [], currentArray = [], path = [], objectMatchKeys = {}, basePath = [], extraAlternativePathObjectMatchKeys = [], }) {
145
+ const commands = [];
146
+ //* Find which key to identify objects an array by. Default is 'id', but can be overridden by objectMatchKeys
147
+ const defaultObjectMatchKeys = {
148
+ load_tags: 'url',
149
+ content_sources: 'key',
150
+ };
151
+ objectMatchKeys = { ...defaultObjectMatchKeys, ...objectMatchKeys };
152
+ const lastPathSegment = path[path.length - 1] ?? '';
153
+ const objectMatchKey = objectMatchKeys[lastPathSegment] ?? 'id';
154
+ //* Create maps for objects with 'id' field for efficient lookup
155
+ const previousItemsById = new Map();
156
+ const currentItemsById = new Map();
157
+ //* Separate items with and without 'id' field
158
+ const previousWithoutId = [];
159
+ const currentWithoutId = [];
160
+ previousArray.forEach((item, index) => {
161
+ if (item && typeof item === 'object' && item[objectMatchKey]) {
162
+ previousItemsById.set(item[objectMatchKey], { item, index });
163
+ }
164
+ else {
165
+ previousWithoutId.push(item);
166
+ }
167
+ });
168
+ currentArray.forEach((item, index) => {
169
+ if (item && typeof item === 'object' && item[objectMatchKey]) {
170
+ currentItemsById.set(item[objectMatchKey], { item, index });
171
+ }
172
+ else {
173
+ currentWithoutId.push(item);
174
+ }
175
+ });
176
+ //* Handle items with primary key field
177
+ //* Check for removed items
178
+ previousItemsById.forEach(({ item }, id) => {
179
+ if (!currentItemsById.has(id)) {
180
+ commands.push({
181
+ type: 'remove',
182
+ data: {
183
+ path: [...basePath, ...path, id],
184
+ objectMatchKey,
185
+ alternativePathObjectMatchKeys: [...extraAlternativePathObjectMatchKeys, objectMatchKey],
186
+ },
187
+ });
188
+ }
189
+ });
190
+ //* Check for added and modified items
191
+ currentItemsById.forEach(({ item: currentItem, index }, id) => {
192
+ if (!previousItemsById.has(id)) {
193
+ let position;
194
+ //* Check if the item is a component
195
+ if (currentItem.type && currentItem.id && currentItem.key) {
196
+ //* Components have a type property
197
+ const component = currentItem;
198
+ position = getInsertPositionForComponent({
199
+ afterComponentId: index > 0 ? currentArray[index - 1][objectMatchKey] : undefined,
200
+ beforeComponentId: index < currentArray.length - 1 ? currentArray[index + 1][objectMatchKey] : undefined,
201
+ parentComponentId: component.parent_id || undefined,
202
+ globalLocation: component._location || undefined,
203
+ components: currentArray,
204
+ });
205
+ }
206
+ else {
207
+ //* For non-components, use the original position logic
208
+ position = {
209
+ after: index > 0 ? currentArray[index - 1][objectMatchKey] : undefined,
210
+ before: index < currentArray.length - 1 ? currentArray[index + 1][objectMatchKey] : undefined,
211
+ };
212
+ }
213
+ //* Item was added
214
+ commands.push({
215
+ type: 'add',
216
+ data: {
217
+ path: [...basePath, ...path],
218
+ value: currentItem,
219
+ position,
220
+ objectMatchKey,
221
+ alternativePathObjectMatchKeys: [...extraAlternativePathObjectMatchKeys, objectMatchKey],
222
+ },
223
+ });
224
+ }
225
+ else {
226
+ //* Item exists, check for modifications
227
+ const previousItem = previousItemsById.get(id).item;
228
+ if (!deepEqual(previousItem, currentItem)) {
229
+ //* If it's an object, recurse to find specific changes
230
+ if (typeof currentItem === 'object' && typeof previousItem === 'object') {
231
+ const itemPath = [...path, id];
232
+ const nestedCommands = translateJsonDiffToEditCommands({
233
+ path: itemPath,
234
+ previousObject: previousItem,
235
+ currentObject: currentItem,
236
+ objectMatchKeys,
237
+ basePath,
238
+ extraAlternativePathObjectMatchKeys,
239
+ });
240
+ commands.push(...nestedCommands);
241
+ }
242
+ else {
243
+ const nestedCommands = translateJsonDiffToEditCommands({
244
+ path: [...path, id],
245
+ previousObject: previousItem,
246
+ currentObject: currentItem,
247
+ objectMatchKeys,
248
+ basePath,
249
+ extraAlternativePathObjectMatchKeys,
250
+ });
251
+ commands.push(...nestedCommands);
252
+ }
253
+ }
254
+ }
255
+ });
256
+ //* Handle items without 'id' field (primitives or objects without id)
257
+ //* If it's an array of primitives, remove all items present in previousArray that are not in currentArray and vice versa.
258
+ const isArrayOfPrimitives = previousWithoutId.every((item) => ['string', 'number', 'boolean'].includes(typeof item)) &&
259
+ currentWithoutId.every((item) => ['string', 'number', 'boolean'].includes(typeof item));
260
+ if (isArrayOfPrimitives) {
261
+ const prevPrimitives = new Set(previousWithoutId);
262
+ const currPrimitives = new Set(currentWithoutId);
263
+ //* Find removed primitives
264
+ prevPrimitives.forEach((item) => {
265
+ if (!currPrimitives.has(item)) {
266
+ commands.push({
267
+ type: 'remove',
268
+ data: {
269
+ alternativePathObjectMatchKeys: [...extraAlternativePathObjectMatchKeys],
270
+ path: [...basePath, ...path, item],
271
+ isStringMatch: typeof item === 'string',
272
+ },
273
+ });
274
+ }
275
+ });
276
+ //* Find added primitives
277
+ currPrimitives.forEach((item) => {
278
+ if (!prevPrimitives.has(item)) {
279
+ commands.push({
280
+ type: 'add',
281
+ data: {
282
+ alternativePathObjectMatchKeys: [...extraAlternativePathObjectMatchKeys],
283
+ path: [...basePath, ...path],
284
+ value: item,
285
+ },
286
+ });
287
+ }
288
+ });
289
+ }
290
+ else {
291
+ //* Handle array of objects without a primary key
292
+ //* Find a unique key in both previous and current arrays to identify items.
293
+ const previousUniqueKeys = findUniqueKey(previousWithoutId);
294
+ const currentUniqueKeys = findUniqueKey(currentWithoutId);
295
+ //* Find the intersection of the two arrays of keys to get common unique keys.
296
+ const commonUniqueKeys = previousUniqueKeys.filter((key) => currentUniqueKeys.includes(key));
297
+ const uniqueKey = commonUniqueKeys[0];
298
+ if (uniqueKey) {
299
+ //* Prevent infinite recursion: if both arrays without ID have only one element,
300
+ //* compare them directly instead of using recursion
301
+ if (previousWithoutId.length === 1 && currentWithoutId.length === 1) {
302
+ if (!deepEqual(previousWithoutId[0], currentWithoutId[0])) {
303
+ commands.push({
304
+ type: 'set',
305
+ data: { path: [...basePath, ...path], value: currentArray },
306
+ });
307
+ }
308
+ }
309
+ else {
310
+ //* We can identify items in the array by a unique key, so we compare them
311
+ commands.push(...translateArrayJsonDiffToEditCommands({
312
+ previousArray,
313
+ currentArray,
314
+ path,
315
+ objectMatchKeys: { ...objectMatchKeys, [lastPathSegment]: uniqueKey },
316
+ basePath,
317
+ extraAlternativePathObjectMatchKeys,
318
+ }));
319
+ }
320
+ }
321
+ else {
322
+ //* We cannot identify items in the array, as a fallback we treat it as a set of items and update the entire array if it has changed
323
+ if (!deepEqual(previousArray, currentArray)) {
324
+ commands.push({
325
+ type: 'set',
326
+ data: { path: [...basePath, ...path], value: currentArray },
327
+ });
328
+ }
329
+ }
330
+ }
331
+ return commands;
332
+ }
333
+ //* Find ancestors of a component (containers only, from root to direct parent)
334
+ export function findAncestorsOfComponent({ components, componentId, }) {
335
+ const ancestors = [];
336
+ const currentComponent = components.find((c) => c.id === componentId);
337
+ if (!currentComponent)
338
+ return ancestors;
339
+ const parentId = currentComponent.parent_id;
340
+ if (parentId) {
341
+ const parentComponent = components.find((c) => c.id === parentId);
342
+ if (parentComponent && parentComponent.type === 'Container') {
343
+ const parentAncestors = findAncestorsOfComponent({
344
+ components,
345
+ componentId: parentComponent.id,
346
+ });
347
+ ancestors.push(...parentAncestors);
348
+ ancestors.push(parentComponent);
349
+ }
350
+ }
351
+ return ancestors;
352
+ }
353
+ //* Find next sibling component
354
+ function getNextSiblingComponent({ components, currentComponentId, parentId, globalLocation, isGlobalComponents, }) {
355
+ const siblings = components.filter((c) => parentId ? c.parent_id === parentId : isGlobalComponents ? c._location === globalLocation : !c.parent_id);
356
+ const currentIndex = siblings.findIndex((c) => c.id === currentComponentId);
357
+ if (currentIndex >= 0 && currentIndex < siblings.length - 1) {
358
+ return siblings[currentIndex + 1];
359
+ }
360
+ return null;
361
+ }
362
+ //* Find previous sibling component
363
+ function getPreviousSiblingComponent({ components, currentComponentId, parentId, globalLocation, isGlobalComponents, }) {
364
+ const siblings = components.filter((c) => parentId ? c.parent_id === parentId : isGlobalComponents ? c._location === globalLocation : !c.parent_id);
365
+ const currentIndex = siblings.findIndex((c) => c.id === currentComponentId);
366
+ if (currentIndex > 0)
367
+ return siblings[currentIndex - 1];
368
+ return null;
369
+ }
370
+ export function getInsertPositionForComponent({ afterComponentId, beforeComponentId, parentComponentId, globalLocation, components, isGlobalComponents, }) {
371
+ //* Case 1: I get the afterComponentId
372
+ if (afterComponentId) {
373
+ //* Find the afterElement
374
+ const afterComponent = components.find((c) => c.id === afterComponentId);
375
+ if (afterComponent) {
376
+ //* Find the before compoentn (next sibling of after)
377
+ const beforeElement = getNextSiblingComponent({
378
+ components,
379
+ currentComponentId: afterComponentId,
380
+ parentId: afterComponent.parent_id,
381
+ globalLocation: afterComponent._location,
382
+ isGlobalComponents,
383
+ });
384
+ //* Get ancestors using our new function
385
+ const ancestors = findAncestorsOfComponent({ components, componentId: afterComponentId });
386
+ //* Check if it's global by looking at the last ancestor's _location
387
+ let isGlobal = false;
388
+ let detectedGlobalLocation;
389
+ if (ancestors.length > 0) {
390
+ //* Get the topmost ancestor (last in the array)
391
+ const topmostAncestor = ancestors[ancestors.length - 1];
392
+ if (topmostAncestor._location) {
393
+ isGlobal = true;
394
+ detectedGlobalLocation = topmostAncestor._location;
395
+ }
396
+ }
397
+ else if (afterComponent._location) {
398
+ //* If no ancestors but the component itself has _location
399
+ isGlobal = true;
400
+ detectedGlobalLocation = afterComponent._location;
401
+ }
402
+ //* Build the position
403
+ const position = { after: afterComponentId };
404
+ if (beforeElement)
405
+ position.before = beforeElement.id;
406
+ if (ancestors.length > 0)
407
+ position.inside = ancestors.map((ancestor) => ancestor.id);
408
+ if (isGlobal && detectedGlobalLocation)
409
+ position.globalLocation = detectedGlobalLocation;
410
+ return position;
411
+ }
412
+ }
413
+ //* Case 2: I get the beforeComponentId, but no afterComponentId
414
+ if (beforeComponentId) {
415
+ const beforeComponent = components.find((c) => c.id === beforeComponentId);
416
+ if (beforeComponent) {
417
+ //* Try to find an after component
418
+ const afterComponent = getPreviousSiblingComponent({
419
+ components,
420
+ currentComponentId: beforeComponentId,
421
+ parentId: beforeComponent.parent_id,
422
+ globalLocation: beforeComponent._location,
423
+ isGlobalComponents,
424
+ });
425
+ //* Get ancestors using our new function
426
+ const ancestors = findAncestorsOfComponent({ components, componentId: beforeComponentId });
427
+ //* Check if it's global by looking at the last ancestor's _location
428
+ let isGlobal = false;
429
+ let detectedGlobalLocation;
430
+ if (ancestors.length > 0) {
431
+ //* Get the topmost ancestor (last in the array)
432
+ const topmostAncestor = ancestors[ancestors.length - 1];
433
+ if (topmostAncestor._location) {
434
+ isGlobal = true;
435
+ detectedGlobalLocation = topmostAncestor._location;
436
+ }
437
+ }
438
+ else if (beforeComponent._location) {
439
+ //* If no ancestors but the component itself has _location
440
+ isGlobal = true;
441
+ detectedGlobalLocation = beforeComponent._location;
442
+ }
443
+ //* Build the position for first position
444
+ const position = { before: beforeComponentId };
445
+ if (afterComponent)
446
+ position.after = afterComponent.id;
447
+ if (ancestors.length > 0)
448
+ position.inside = ancestors.map((ancestor) => ancestor.id);
449
+ if (isGlobal && detectedGlobalLocation)
450
+ position.globalLocation = detectedGlobalLocation;
451
+ return position;
452
+ }
453
+ }
454
+ //* Case 3: I get the parentComponentId
455
+ if (parentComponentId) {
456
+ const parentComponent = components.find((c) => c.id === parentComponentId);
457
+ if (parentComponent) {
458
+ //* Get ancestors of the parent to construct inside and define globalLocation
459
+ const ancestors = findAncestorsOfComponent({ components, componentId: parentComponentId });
460
+ //* Check if it's global by looking at the last ancestor's _location
461
+ let isGlobal = false;
462
+ let detectedGlobalLocation;
463
+ if (ancestors.length > 0) {
464
+ //* Get the topmost ancestor (last in the array)
465
+ const topmostAncestor = ancestors[ancestors.length - 1];
466
+ if (topmostAncestor._location) {
467
+ isGlobal = true;
468
+ detectedGlobalLocation = topmostAncestor._location;
469
+ }
470
+ }
471
+ else if (parentComponent._location) {
472
+ //* If no ancestors but the parent itself has _location
473
+ isGlobal = true;
474
+ detectedGlobalLocation = parentComponent._location;
475
+ }
476
+ //* Build the position for insertion inside parent
477
+ const position = {
478
+ inside: [...ancestors.map((ancestor) => ancestor.id), parentComponentId],
479
+ };
480
+ if (isGlobal && detectedGlobalLocation)
481
+ position.globalLocation = detectedGlobalLocation;
482
+ return position;
483
+ }
484
+ }
485
+ //* Case 4: globalLocation provided
486
+ if (globalLocation)
487
+ return { globalLocation: globalLocation };
488
+ return undefined;
489
+ }
490
+ //* -------------------OBJECT FUNCTIONS ------------------- *//
491
+ //* Deep comparison function to check if two objects are equal
492
+ export function deepEqual(obj1, obj2) {
493
+ if (obj1 === obj2)
494
+ return true;
495
+ if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
496
+ return false;
497
+ }
498
+ const keys1 = Object.keys(obj1);
499
+ const keys2 = Object.keys(obj2);
500
+ if (keys1.length !== keys2.length)
501
+ return false;
502
+ for (let key of keys1) {
503
+ if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
504
+ return false;
505
+ }
506
+ }
507
+ return true;
508
+ }
509
+ export function findUniqueKey(arr) {
510
+ const uniqueKeys = [];
511
+ if (!arr.length || typeof arr[0] !== 'object' || arr[0] === null)
512
+ return uniqueKeys;
513
+ const keys = Object.keys(arr[0]);
514
+ for (const key of keys) {
515
+ const values = new Set();
516
+ let allHaveKeyAndArePrimitive = true;
517
+ for (const item of arr) {
518
+ if (item &&
519
+ typeof item === 'object' &&
520
+ key in item &&
521
+ ['string', 'number', 'boolean'].includes(typeof item[key])) {
522
+ values.add(item[key]);
523
+ }
524
+ else {
525
+ allHaveKeyAndArePrimitive = false;
526
+ break;
527
+ }
528
+ }
529
+ if (allHaveKeyAndArePrimitive && values.size === arr.length)
530
+ uniqueKeys.push(key);
531
+ }
532
+ return uniqueKeys;
533
+ }
534
+ //* Find the different paths between two objects
535
+ export function findDifferentPaths(obj1, obj2) {
536
+ const result = {};
537
+ //* Helper function to add a path to results
538
+ function addPath(path) {
539
+ const topLevel = path.split('.')[0];
540
+ if (!result[topLevel]) {
541
+ result[topLevel] = [];
542
+ }
543
+ if (!result[topLevel].includes(path)) {
544
+ result[topLevel].push(path);
545
+ }
546
+ }
547
+ //* Deep compare function to find all differences
548
+ function deepCompare(a, b, currentPath = '') {
549
+ //* If objects are strictly equal, no need to check further
550
+ if (a === b)
551
+ return;
552
+ //* Handle case when either value is not an object or is null
553
+ if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
554
+ addPath(currentPath);
555
+ return;
556
+ }
557
+ //* Get all keys from both objects
558
+ const allKeys = Array.from(new Set([...Object.keys(a), ...Object.keys(b)]));
559
+ for (const key of allKeys) {
560
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
561
+ //* If key exists only in one object
562
+ if (!(key in a) || !(key in b)) {
563
+ addPath(newPath);
564
+ //* If the key is in b but not a, and it's an object, add all nested paths
565
+ if (!(key in a) && typeof b[key] === 'object' && b[key] !== null) {
566
+ addNestedPaths(b[key], newPath);
567
+ }
568
+ //* If the key is in a but not b, and it's an object, add all nested paths
569
+ else if (!(key in b) && typeof a[key] === 'object' && a[key] !== null) {
570
+ addNestedPaths(a[key], newPath);
571
+ }
572
+ continue;
573
+ }
574
+ //* Recursively check nested properties
575
+ deepCompare(a[key], b[key], newPath);
576
+ }
577
+ }
578
+ //* Helper function to add all paths in a nested object
579
+ function addNestedPaths(obj, basePath) {
580
+ if (typeof obj !== 'object' || obj === null)
581
+ return;
582
+ addPath(basePath);
583
+ for (const key in obj) {
584
+ const newPath = `${basePath}.${key}`;
585
+ addPath(newPath);
586
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
587
+ addNestedPaths(obj[key], newPath);
588
+ }
589
+ }
590
+ }
591
+ deepCompare(obj1, obj2);
592
+ return result;
593
+ }
594
+ //* Get the value of an object by a path
595
+ export function getValueByPath(obj, path) {
596
+ let current = obj;
597
+ for (const key of path) {
598
+ if (current === undefined || current === null) {
599
+ return undefined;
600
+ }
601
+ current = current[key];
602
+ }
603
+ return current;
604
+ }
605
+ export function getBreakLineStringFromArray(input) {
606
+ if (Array.isArray(input))
607
+ return input.join('\n');
608
+ return input;
609
+ }
610
+ const DEFAULT_CONTENT_LANGUAGE_KEY = 'en';
611
+ //* Builds a language-prefixed key for multilanguage properties
612
+ //* For default language, returns the base key; for others, returns `lang--{languageKey}--{attributeKey}`
613
+ export function getMultilanguageKey({ attributeKey, languageKey, }) {
614
+ return languageKey === DEFAULT_CONTENT_LANGUAGE_KEY
615
+ ? attributeKey
616
+ : `lang--${languageKey}--${attributeKey}`;
617
+ }
618
+ export function getArrayFromBreakLineString(input) {
619
+ if (typeof input === 'string')
620
+ return input.split('\n');
621
+ return input;
622
+ }
@@ -0,0 +1,15 @@
1
+ import prompts from 'prompts';
2
+ /**
3
+ * Wrapper around `prompts` that properly handles ESC on all prompt types.
4
+ *
5
+ * The `prompts` library has a bug in AutocompletePrompt: pressing ESC triggers
6
+ * `exit()` which resolves the promise with the currently highlighted value
7
+ * (acting like a submit), rather than aborting. This wrapper detects the
8
+ * `exited` state via `onState` and calls `process.exit(0)` so ESC consistently
9
+ * quits the CLI command.
10
+ *
11
+ * For prompt types that already handle ESC correctly (select, confirm, text),
12
+ * the `onCancel` handler fires normally via the abort path.
13
+ */
14
+ export declare function prompt(question: prompts.PromptObject<string>, exitCode?: number): Promise<prompts.Answers<string>>;
15
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/helpers/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,EACtC,QAAQ,GAAE,MAAU,GACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CA4BlC"}
@@ -0,0 +1,35 @@
1
+ import prompts from 'prompts';
2
+ /**
3
+ * Wrapper around `prompts` that properly handles ESC on all prompt types.
4
+ *
5
+ * The `prompts` library has a bug in AutocompletePrompt: pressing ESC triggers
6
+ * `exit()` which resolves the promise with the currently highlighted value
7
+ * (acting like a submit), rather than aborting. This wrapper detects the
8
+ * `exited` state via `onState` and calls `process.exit(0)` so ESC consistently
9
+ * quits the CLI command.
10
+ *
11
+ * For prompt types that already handle ESC correctly (select, confirm, text),
12
+ * the `onCancel` handler fires normally via the abort path.
13
+ */
14
+ export async function prompt(question, exitCode = 0) {
15
+ let exited = false;
16
+ const originalOnState = question.onState;
17
+ const questionWithState = {
18
+ ...question,
19
+ onState: (state) => {
20
+ if (state.exited) {
21
+ exited = true;
22
+ }
23
+ originalOnState?.(state);
24
+ },
25
+ };
26
+ const response = await prompts(questionWithState, {
27
+ onCancel: () => {
28
+ process.exit(exitCode);
29
+ },
30
+ });
31
+ if (exited) {
32
+ process.exit(exitCode);
33
+ }
34
+ return response;
35
+ }
@@ -0,0 +1,13 @@
1
+ export declare function generateId(prefix: string): string;
2
+ /**
3
+ * If the current working directory is inside embeddables/<id>/ (or a subfolder),
4
+ * returns that embeddable id and the project root (the directory containing the
5
+ * embeddables/ folder). Otherwise returns null.
6
+ * When using the inferred id, callers should chdir(projectRoot) so relative
7
+ * paths like embeddables/<id>/... resolve correctly.
8
+ */
9
+ export declare function inferEmbeddableFromCwd(): {
10
+ embeddableId: string;
11
+ projectRoot: string;
12
+ } | null;
13
+ //# sourceMappingURL=utils.d.ts.map