@embeddables/cli 0.7.13 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prompts/custom/build-funnel.md +1 -1
- package/.prompts/embeddables-cli.md +9 -2
- package/package.json +1 -1
- package/dist/auth/index.d.ts +0 -43
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -102
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -174
- package/dist/commands/branch.d.ts +0 -4
- package/dist/commands/branch.d.ts.map +0 -1
- package/dist/commands/branch.js +0 -68
- package/dist/commands/build-workbench.d.ts +0 -5
- package/dist/commands/build-workbench.d.ts.map +0 -1
- package/dist/commands/build-workbench.js +0 -128
- package/dist/commands/build.d.ts +0 -8
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -55
- package/dist/commands/dev.d.ts +0 -12
- package/dist/commands/dev.d.ts.map +0 -1
- package/dist/commands/dev.js +0 -221
- package/dist/commands/experiments-connect.d.ts +0 -6
- package/dist/commands/experiments-connect.d.ts.map +0 -1
- package/dist/commands/experiments-connect.js +0 -140
- package/dist/commands/init.d.ts +0 -5
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -327
- package/dist/commands/login.d.ts +0 -2
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js +0 -122
- package/dist/commands/logout.d.ts +0 -2
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js +0 -22
- package/dist/commands/pull.d.ts +0 -14
- package/dist/commands/pull.d.ts.map +0 -1
- package/dist/commands/pull.js +0 -383
- package/dist/commands/save.d.ts +0 -30
- package/dist/commands/save.d.ts.map +0 -1
- package/dist/commands/save.js +0 -591
- package/dist/commands/upgrade.d.ts +0 -2
- package/dist/commands/upgrade.d.ts.map +0 -1
- package/dist/commands/upgrade.js +0 -51
- package/dist/compiler/errors.d.ts +0 -20
- package/dist/compiler/errors.d.ts.map +0 -1
- package/dist/compiler/errors.js +0 -35
- package/dist/compiler/evalStatic.d.ts +0 -3
- package/dist/compiler/evalStatic.d.ts.map +0 -1
- package/dist/compiler/evalStatic.js +0 -57
- package/dist/compiler/flatten.js +0 -1
- package/dist/compiler/helpers/duplicateIds.d.ts +0 -9
- package/dist/compiler/helpers/duplicateIds.d.ts.map +0 -1
- package/dist/compiler/helpers/duplicateIds.js +0 -71
- package/dist/compiler/helpers/numericLeadingKeys.d.ts +0 -8
- package/dist/compiler/helpers/numericLeadingKeys.d.ts.map +0 -1
- package/dist/compiler/helpers/numericLeadingKeys.js +0 -17
- package/dist/compiler/index.d.ts +0 -18
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/index.js +0 -1245
- package/dist/compiler/parsePage.d.ts +0 -15
- package/dist/compiler/parsePage.d.ts.map +0 -1
- package/dist/compiler/parsePage.js +0 -631
- package/dist/compiler/registry.d.ts +0 -4
- package/dist/compiler/registry.d.ts.map +0 -1
- package/dist/compiler/registry.js +0 -44
- package/dist/compiler/reverse.d.ts +0 -23
- package/dist/compiler/reverse.d.ts.map +0 -1
- package/dist/compiler/reverse.js +0 -1875
- package/dist/compiler/types.d.ts +0 -21
- package/dist/compiler/types.d.ts.map +0 -1
- package/dist/compiler/types.js +0 -1
- package/dist/components/index.d.ts +0 -21
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -21
- package/dist/components/primitives/BaseComponent.d.ts +0 -32
- package/dist/components/primitives/BaseComponent.d.ts.map +0 -1
- package/dist/components/primitives/BaseComponent.js +0 -26
- package/dist/components/primitives/BookMeeting.d.ts +0 -18
- package/dist/components/primitives/BookMeeting.d.ts.map +0 -1
- package/dist/components/primitives/BookMeeting.js +0 -5
- package/dist/components/primitives/Chart.d.ts +0 -41
- package/dist/components/primitives/Chart.d.ts.map +0 -1
- package/dist/components/primitives/Chart.js +0 -5
- package/dist/components/primitives/Container.d.ts +0 -8
- package/dist/components/primitives/Container.d.ts.map +0 -1
- package/dist/components/primitives/Container.js +0 -5
- package/dist/components/primitives/CustomButton.d.ts +0 -37
- package/dist/components/primitives/CustomButton.d.ts.map +0 -1
- package/dist/components/primitives/CustomButton.js +0 -10
- package/dist/components/primitives/CustomHTML.d.ts +0 -8
- package/dist/components/primitives/CustomHTML.d.ts.map +0 -1
- package/dist/components/primitives/CustomHTML.js +0 -5
- package/dist/components/primitives/FileUpload.d.ts +0 -18
- package/dist/components/primitives/FileUpload.d.ts.map +0 -1
- package/dist/components/primitives/FileUpload.js +0 -16
- package/dist/components/primitives/InputBox.d.ts +0 -34
- package/dist/components/primitives/InputBox.d.ts.map +0 -1
- package/dist/components/primitives/InputBox.js +0 -25
- package/dist/components/primitives/Lottie.d.ts +0 -11
- package/dist/components/primitives/Lottie.d.ts.map +0 -1
- package/dist/components/primitives/Lottie.js +0 -5
- package/dist/components/primitives/MediaEmbed.d.ts +0 -13
- package/dist/components/primitives/MediaEmbed.d.ts.map +0 -1
- package/dist/components/primitives/MediaEmbed.js +0 -6
- package/dist/components/primitives/MediaImage.d.ts +0 -8
- package/dist/components/primitives/MediaImage.d.ts.map +0 -1
- package/dist/components/primitives/MediaImage.js +0 -5
- package/dist/components/primitives/OptionSelector.d.ts +0 -35
- package/dist/components/primitives/OptionSelector.d.ts.map +0 -1
- package/dist/components/primitives/OptionSelector.js +0 -8
- package/dist/components/primitives/PaypalCheckout.d.ts +0 -25
- package/dist/components/primitives/PaypalCheckout.d.ts.map +0 -1
- package/dist/components/primitives/PaypalCheckout.js +0 -5
- package/dist/components/primitives/PlainText.d.ts +0 -6
- package/dist/components/primitives/PlainText.d.ts.map +0 -1
- package/dist/components/primitives/PlainText.js +0 -5
- package/dist/components/primitives/ProgressBar.d.ts +0 -15
- package/dist/components/primitives/ProgressBar.d.ts.map +0 -1
- package/dist/components/primitives/ProgressBar.js +0 -5
- package/dist/components/primitives/RichText.d.ts +0 -6
- package/dist/components/primitives/RichText.d.ts.map +0 -1
- package/dist/components/primitives/RichText.js +0 -5
- package/dist/components/primitives/RichTextMarkdown.d.ts +0 -6
- package/dist/components/primitives/RichTextMarkdown.d.ts.map +0 -1
- package/dist/components/primitives/RichTextMarkdown.js +0 -5
- package/dist/components/primitives/Rive.d.ts +0 -16
- package/dist/components/primitives/Rive.d.ts.map +0 -1
- package/dist/components/primitives/Rive.js +0 -8
- package/dist/components/primitives/StripeCheckout.d.ts +0 -52
- package/dist/components/primitives/StripeCheckout.d.ts.map +0 -1
- package/dist/components/primitives/StripeCheckout.js +0 -5
- package/dist/components/primitives/StripeCheckout2.d.ts +0 -30
- package/dist/components/primitives/StripeCheckout2.d.ts.map +0 -1
- package/dist/components/primitives/StripeCheckout2.js +0 -7
- package/dist/config/index.d.ts +0 -23
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -42
- package/dist/constants.d.ts +0 -9
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -9
- package/dist/helpers/TEMP helpers file.d.ts +0 -1
- package/dist/helpers/TEMP helpers file.d.ts.map +0 -1
- package/dist/helpers/TEMP helpers file.js +0 -1
- package/dist/helpers/dates.d.ts +0 -5
- package/dist/helpers/dates.d.ts.map +0 -1
- package/dist/helpers/dates.js +0 -7
- package/dist/helpers/json.d.ts +0 -47
- package/dist/helpers/json.d.ts.map +0 -1
- package/dist/helpers/json.js +0 -622
- package/dist/helpers/utils.d.ts +0 -13
- package/dist/helpers/utils.d.ts.map +0 -1
- package/dist/helpers/utils.js +0 -28
- package/dist/logger.d.ts +0 -11
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -21
- package/dist/prompts/branches.d.ts +0 -20
- package/dist/prompts/branches.d.ts.map +0 -1
- package/dist/prompts/branches.js +0 -90
- package/dist/prompts/embeddables.d.ts +0 -43
- package/dist/prompts/embeddables.d.ts.map +0 -1
- package/dist/prompts/embeddables.js +0 -198
- package/dist/prompts/experiments.d.ts +0 -28
- package/dist/prompts/experiments.d.ts.map +0 -1
- package/dist/prompts/experiments.js +0 -87
- package/dist/prompts/index.d.ts +0 -11
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js +0 -6
- package/dist/prompts/projects.d.ts +0 -22
- package/dist/prompts/projects.d.ts.map +0 -1
- package/dist/prompts/projects.js +0 -86
- package/dist/prompts/versions.d.ts +0 -18
- package/dist/prompts/versions.d.ts.map +0 -1
- package/dist/prompts/versions.js +0 -99
- package/dist/proxy/injectApiInterceptor.d.ts +0 -6
- package/dist/proxy/injectApiInterceptor.d.ts.map +0 -1
- package/dist/proxy/injectApiInterceptor.js +0 -66
- package/dist/proxy/injectReload.d.ts +0 -2
- package/dist/proxy/injectReload.d.ts.map +0 -1
- package/dist/proxy/injectReload.js +0 -14
- package/dist/proxy/injectWorkbench.d.ts +0 -5
- package/dist/proxy/injectWorkbench.d.ts.map +0 -1
- package/dist/proxy/injectWorkbench.js +0 -22
- package/dist/proxy/server.d.ts +0 -11
- package/dist/proxy/server.d.ts.map +0 -1
- package/dist/proxy/server.js +0 -316
- package/dist/proxy/sse.d.ts +0 -5
- package/dist/proxy/sse.d.ts.map +0 -1
- package/dist/proxy/sse.js +0 -17
- package/dist/sentry-context.d.ts +0 -48
- package/dist/sentry-context.d.ts.map +0 -1
- package/dist/sentry-context.js +0 -156
- package/dist/stdout.d.ts +0 -17
- package/dist/stdout.d.ts.map +0 -1
- package/dist/stdout.js +0 -23
- package/dist/types-builder.d.ts +0 -800
- package/dist/types-builder.d.ts.map +0 -1
- package/dist/types-builder.js +0 -20
- package/dist/workbench/ActionsPanel.d.ts +0 -6
- package/dist/workbench/ActionsPanel.d.ts.map +0 -1
- package/dist/workbench/ActionsPanel.js +0 -47
- package/dist/workbench/AutofillPanel.d.ts +0 -6
- package/dist/workbench/AutofillPanel.d.ts.map +0 -1
- package/dist/workbench/AutofillPanel.js +0 -543
- package/dist/workbench/ComputedFieldsPanel.d.ts +0 -6
- package/dist/workbench/ComputedFieldsPanel.d.ts.map +0 -1
- package/dist/workbench/ComputedFieldsPanel.js +0 -31
- package/dist/workbench/ExperimentsPanel.d.ts +0 -6
- package/dist/workbench/ExperimentsPanel.d.ts.map +0 -1
- package/dist/workbench/ExperimentsPanel.js +0 -182
- package/dist/workbench/FieldEditorPanel.d.ts +0 -9
- package/dist/workbench/FieldEditorPanel.d.ts.map +0 -1
- package/dist/workbench/FieldEditorPanel.js +0 -650
- package/dist/workbench/InspectorPanel.d.ts +0 -6
- package/dist/workbench/InspectorPanel.d.ts.map +0 -1
- package/dist/workbench/InspectorPanel.js +0 -341
- package/dist/workbench/PageNavigator.d.ts +0 -6
- package/dist/workbench/PageNavigator.d.ts.map +0 -1
- package/dist/workbench/PageNavigator.js +0 -123
- package/dist/workbench/SchemaPanel.d.ts +0 -6
- package/dist/workbench/SchemaPanel.d.ts.map +0 -1
- package/dist/workbench/SchemaPanel.js +0 -222
- package/dist/workbench/UserDataPanel.d.ts +0 -6
- package/dist/workbench/UserDataPanel.d.ts.map +0 -1
- package/dist/workbench/UserDataPanel.js +0 -350
- package/dist/workbench/WorkbenchApp.d.ts +0 -7
- package/dist/workbench/WorkbenchApp.d.ts.map +0 -1
- package/dist/workbench/WorkbenchApp.js +0 -193
- package/dist/workbench/cloudflare-worker/README.md +0 -31
- package/dist/workbench/cloudflare-worker/public/workbench.css +0 -1614
- package/dist/workbench/cloudflare-worker/public/workbench.js +0 -77
- package/dist/workbench/cloudflare-worker/worker.js +0 -40
- package/dist/workbench/cloudflare-worker/wrangler.toml +0 -10
- package/dist/workbench/index.d.ts +0 -10
- package/dist/workbench/index.d.ts.map +0 -1
- package/dist/workbench/index.js +0 -44
- package/dist/workbench/workbench.css +0 -1614
- package/dist/workbench/workbench.js +0 -77
package/dist/helpers/json.js
DELETED
|
@@ -1,622 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/helpers/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/helpers/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAIxC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,IAAI;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAc7F"}
|
package/dist/helpers/utils.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
export function generateId(prefix) {
|
|
3
|
-
const randomString = Math.random().toString(20).slice(2) + Math.random().toString(20).slice(2);
|
|
4
|
-
return prefix ? `${prefix}_${randomString}` : `_${randomString}`;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* If the current working directory is inside embeddables/<id>/ (or a subfolder),
|
|
8
|
-
* returns that embeddable id and the project root (the directory containing the
|
|
9
|
-
* embeddables/ folder). Otherwise returns null.
|
|
10
|
-
* When using the inferred id, callers should chdir(projectRoot) so relative
|
|
11
|
-
* paths like embeddables/<id>/... resolve correctly.
|
|
12
|
-
*/
|
|
13
|
-
export function inferEmbeddableFromCwd() {
|
|
14
|
-
let current = path.resolve(process.cwd());
|
|
15
|
-
for (;;) {
|
|
16
|
-
const parent = path.dirname(current);
|
|
17
|
-
if (parent === current)
|
|
18
|
-
break;
|
|
19
|
-
if (path.basename(parent) === 'embeddables') {
|
|
20
|
-
return {
|
|
21
|
-
embeddableId: path.basename(current),
|
|
22
|
-
projectRoot: path.dirname(parent),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
current = parent;
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
package/dist/logger.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type LogContext = Record<string, string | number | boolean | null | undefined>;
|
|
2
|
-
export interface Logger {
|
|
3
|
-
info(message: string, ctx?: LogContext): void;
|
|
4
|
-
warn(message: string, ctx?: LogContext): void;
|
|
5
|
-
error(message: string, ctx?: LogContext): void;
|
|
6
|
-
}
|
|
7
|
-
export declare function createLogger(fn: string): Logger;
|
|
8
|
-
export declare function captureException(error: unknown): void;
|
|
9
|
-
export declare function exit(code: number): Promise<never>;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;AAE9E,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC7C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;CAC/C;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAY/C;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAErD;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAGvD"}
|