@teambit/compositions.ui.composition-compare 0.0.259 → 0.0.260
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/composition-compare.context.tsx +6 -6
- package/composition-compare.module.scss +126 -14
- package/composition-compare.tsx +608 -169
- package/composition-dropdown.module.scss +28 -0
- package/composition-dropdown.tsx +16 -4
- package/dist/composition-compare.context.d.ts +1 -1
- package/dist/composition-compare.d.ts +1 -1
- package/dist/composition-compare.js +439 -110
- package/dist/composition-compare.js.map +1 -1
- package/dist/composition-compare.module.scss +126 -14
- package/dist/composition-dropdown.d.ts +1 -0
- package/dist/composition-dropdown.js +23 -9
- package/dist/composition-dropdown.js.map +1 -1
- package/dist/composition-dropdown.module.scss +28 -0
- package/index.ts +1 -1
- package/package.json +18 -10
- /package/dist/{preview-1739094520607.js → preview-1772488540837.js} +0 -0
|
@@ -15,145 +15,474 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.CompositionCompare = CompositionCompare;
|
|
30
40
|
const react_1 = __importStar(require("react"));
|
|
41
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
31
42
|
const component_ui_component_compare_context_1 = require("@teambit/component.ui.component-compare.context");
|
|
32
43
|
const compositions_1 = require("@teambit/compositions");
|
|
33
44
|
const compositions_ui_hooks_use_composition_1 = require("@teambit/compositions.ui.hooks.use-composition");
|
|
34
45
|
const component_ui_component_compare_hooks_use_component_compare_url_1 = require("@teambit/component.ui.component-compare.hooks.use-component-compare-url");
|
|
35
46
|
const component_ui_component_compare_layouts_compare_split_layout_preset_1 = require("@teambit/component.ui.component-compare.layouts.compare-split-layout-preset");
|
|
36
47
|
const design_ui_round_loader_1 = require("@teambit/design.ui.round-loader");
|
|
48
|
+
const evangelist_elements_icon_1 = require("@teambit/evangelist.elements.icon");
|
|
49
|
+
const base_react_navigation_link_1 = require("@teambit/base-react.navigation.link");
|
|
50
|
+
const ui_foundation_ui_react_router_use_query_1 = require("@teambit/ui-foundation.ui.react-router.use-query");
|
|
37
51
|
const query_string_1 = __importDefault(require("query-string"));
|
|
38
52
|
const composition_dropdown_1 = require("./composition-dropdown");
|
|
39
53
|
const composition_compare_context_1 = require("./composition-compare.context");
|
|
40
54
|
const lodash_1 = require("lodash");
|
|
55
|
+
const semver = __importStar(require("semver"));
|
|
41
56
|
const composition_compare_module_scss_1 = __importDefault(require("./composition-compare.module.scss"));
|
|
57
|
+
const noop = () => { };
|
|
58
|
+
const LOCAL_VERSION = 'workspace';
|
|
59
|
+
function MissingComposition({ compositionId, version }) {
|
|
60
|
+
const message = compositionId
|
|
61
|
+
? `The selected composition "${compositionId}" does not exist for the ${version} version.`
|
|
62
|
+
: `The selected composition does not exist for the ${version} version.`;
|
|
63
|
+
return (react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.subView },
|
|
64
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.missingComposition },
|
|
65
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.missingCompositionTitle }, "Composition not available"),
|
|
66
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.missingCompositionSubtitle }, message))));
|
|
67
|
+
}
|
|
68
|
+
function getCompositionTag(hasInBase, hasInCompare) {
|
|
69
|
+
if (hasInBase && hasInCompare)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (hasInBase)
|
|
72
|
+
return 'Base only';
|
|
73
|
+
if (hasInCompare)
|
|
74
|
+
return 'Compare only';
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
function useResizePanel(initialHeight) {
|
|
78
|
+
const MIN_PANEL_HEIGHT = 80;
|
|
79
|
+
const MIN_COMPARE_HEIGHT = 150;
|
|
80
|
+
const DEFAULT_PANEL_RATIO = 0.34;
|
|
81
|
+
const [panelHeight, setPanelHeight] = (0, react_1.useState)(initialHeight);
|
|
82
|
+
const [isResizing, setIsResizing] = (0, react_1.useState)(false);
|
|
83
|
+
const panelRef = (0, react_1.useRef)(null);
|
|
84
|
+
const isDragging = (0, react_1.useRef)(false);
|
|
85
|
+
const panelHeightRef = (0, react_1.useRef)(initialHeight);
|
|
86
|
+
const removeListenersRef = (0, react_1.useRef)(null);
|
|
87
|
+
const rafRef = (0, react_1.useRef)(null);
|
|
88
|
+
const initializedRef = (0, react_1.useRef)(false);
|
|
89
|
+
const userResizedRef = (0, react_1.useRef)(false);
|
|
90
|
+
const getMaxPanelHeight = (0, react_1.useCallback)(() => {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const containerHeight = (_b = (_a = panelRef.current) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.clientHeight;
|
|
93
|
+
if (!containerHeight)
|
|
94
|
+
return Math.max(MIN_PANEL_HEIGHT, initialHeight);
|
|
95
|
+
return Math.max(MIN_PANEL_HEIGHT, containerHeight - MIN_COMPARE_HEIGHT);
|
|
96
|
+
}, [MIN_COMPARE_HEIGHT, MIN_PANEL_HEIGHT, initialHeight]);
|
|
97
|
+
const getDefaultPanelHeight = (0, react_1.useCallback)(() => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
const containerHeight = (_b = (_a = panelRef.current) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.clientHeight;
|
|
100
|
+
if (!containerHeight || containerHeight <= 0)
|
|
101
|
+
return initialHeight;
|
|
102
|
+
return Math.max(initialHeight, Math.round(containerHeight * DEFAULT_PANEL_RATIO));
|
|
103
|
+
}, [initialHeight, DEFAULT_PANEL_RATIO]);
|
|
104
|
+
const clampPanelHeight = (0, react_1.useCallback)((height) => {
|
|
105
|
+
const maxHeight = getMaxPanelHeight();
|
|
106
|
+
return Math.max(MIN_PANEL_HEIGHT, Math.min(maxHeight, height));
|
|
107
|
+
}, [MIN_PANEL_HEIGHT, getMaxPanelHeight]);
|
|
108
|
+
const applyPanelHeight = (0, react_1.useCallback)((height, commitToState = false) => {
|
|
109
|
+
const clamped = clampPanelHeight(height);
|
|
110
|
+
panelHeightRef.current = clamped;
|
|
111
|
+
if (panelRef.current)
|
|
112
|
+
panelRef.current.style.height = `${clamped}px`;
|
|
113
|
+
if (commitToState)
|
|
114
|
+
setPanelHeight(clamped);
|
|
115
|
+
return clamped;
|
|
116
|
+
}, [clampPanelHeight]);
|
|
117
|
+
const syncPanelHeight = (0, react_1.useCallback)(() => {
|
|
118
|
+
if (isDragging.current)
|
|
119
|
+
return;
|
|
120
|
+
const nextHeight = userResizedRef.current ? panelHeightRef.current : getDefaultPanelHeight();
|
|
121
|
+
applyPanelHeight(nextHeight, true);
|
|
122
|
+
}, [applyPanelHeight, getDefaultPanelHeight]);
|
|
123
|
+
(0, react_1.useEffect)(() => {
|
|
124
|
+
if (initializedRef.current)
|
|
125
|
+
return;
|
|
126
|
+
initializedRef.current = true;
|
|
127
|
+
syncPanelHeight();
|
|
128
|
+
}, [syncPanelHeight]);
|
|
129
|
+
(0, react_1.useEffect)(() => {
|
|
130
|
+
const handleWindowResize = () => {
|
|
131
|
+
syncPanelHeight();
|
|
132
|
+
};
|
|
133
|
+
handleWindowResize();
|
|
134
|
+
window.addEventListener('resize', handleWindowResize);
|
|
135
|
+
return () => window.removeEventListener('resize', handleWindowResize);
|
|
136
|
+
}, [syncPanelHeight]);
|
|
137
|
+
(0, react_1.useEffect)(() => {
|
|
138
|
+
var _a;
|
|
139
|
+
if (typeof ResizeObserver === 'undefined')
|
|
140
|
+
return;
|
|
141
|
+
const parent = (_a = panelRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
142
|
+
if (!parent)
|
|
143
|
+
return;
|
|
144
|
+
const observer = new ResizeObserver(() => {
|
|
145
|
+
syncPanelHeight();
|
|
146
|
+
});
|
|
147
|
+
observer.observe(parent);
|
|
148
|
+
return () => observer.disconnect();
|
|
149
|
+
}, [syncPanelHeight]);
|
|
150
|
+
const handleResizeStart = (0, react_1.useCallback)((e) => {
|
|
151
|
+
var _a;
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
isDragging.current = true;
|
|
155
|
+
setIsResizing(true);
|
|
156
|
+
const startY = e.clientY;
|
|
157
|
+
const startHeight = panelHeightRef.current;
|
|
158
|
+
const handleMouseMove = (moveEvent) => {
|
|
159
|
+
if (!isDragging.current)
|
|
160
|
+
return;
|
|
161
|
+
moveEvent.preventDefault();
|
|
162
|
+
const delta = startY - moveEvent.clientY;
|
|
163
|
+
const targetHeight = startHeight + delta;
|
|
164
|
+
if (rafRef.current !== null)
|
|
165
|
+
cancelAnimationFrame(rafRef.current);
|
|
166
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
167
|
+
applyPanelHeight(targetHeight);
|
|
168
|
+
rafRef.current = null;
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const handleMouseUp = () => {
|
|
172
|
+
if (rafRef.current !== null) {
|
|
173
|
+
cancelAnimationFrame(rafRef.current);
|
|
174
|
+
rafRef.current = null;
|
|
175
|
+
}
|
|
176
|
+
userResizedRef.current = true;
|
|
177
|
+
isDragging.current = false;
|
|
178
|
+
applyPanelHeight(panelHeightRef.current, true);
|
|
179
|
+
setIsResizing(false);
|
|
180
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
181
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
182
|
+
window.removeEventListener('blur', handleMouseUp);
|
|
183
|
+
document.body.style.cursor = '';
|
|
184
|
+
document.body.style.userSelect = '';
|
|
185
|
+
};
|
|
186
|
+
(_a = removeListenersRef.current) === null || _a === void 0 ? void 0 : _a.call(removeListenersRef);
|
|
187
|
+
document.body.style.cursor = 'ns-resize';
|
|
188
|
+
document.body.style.userSelect = 'none';
|
|
189
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
190
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
191
|
+
window.addEventListener('blur', handleMouseUp);
|
|
192
|
+
removeListenersRef.current = () => {
|
|
193
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
194
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
195
|
+
window.removeEventListener('blur', handleMouseUp);
|
|
196
|
+
};
|
|
197
|
+
}, [applyPanelHeight]);
|
|
198
|
+
(0, react_1.useEffect)(() => {
|
|
199
|
+
return () => {
|
|
200
|
+
var _a;
|
|
201
|
+
isDragging.current = false;
|
|
202
|
+
if (rafRef.current !== null) {
|
|
203
|
+
cancelAnimationFrame(rafRef.current);
|
|
204
|
+
rafRef.current = null;
|
|
205
|
+
}
|
|
206
|
+
(_a = removeListenersRef.current) === null || _a === void 0 ? void 0 : _a.call(removeListenersRef);
|
|
207
|
+
removeListenersRef.current = null;
|
|
208
|
+
document.body.style.cursor = '';
|
|
209
|
+
document.body.style.userSelect = '';
|
|
210
|
+
};
|
|
211
|
+
}, []);
|
|
212
|
+
return { panelRef, panelHeight, isResizing, handleResizeStart };
|
|
213
|
+
}
|
|
214
|
+
function findComposition(compositions, id) {
|
|
215
|
+
if (!id || !compositions)
|
|
216
|
+
return compositions === null || compositions === void 0 ? void 0 : compositions[0];
|
|
217
|
+
return compositions.find((c) => c.identifier === id) || undefined;
|
|
218
|
+
}
|
|
219
|
+
function useCompositionSelection() {
|
|
220
|
+
const selectedCompositionBaseFile = (0, component_ui_component_compare_hooks_use_component_compare_url_1.useCompareQueryParam)('compositionBaseFile');
|
|
221
|
+
const selectedCompositionCompareFile = (0, component_ui_component_compare_hooks_use_component_compare_url_1.useCompareQueryParam)('compositionCompareFile');
|
|
222
|
+
return { selectedCompositionBaseFile, selectedCompositionCompareFile };
|
|
223
|
+
}
|
|
224
|
+
function buildChannelKey(prefix, idStr, compId) {
|
|
225
|
+
if (!idStr || !compId)
|
|
226
|
+
return undefined;
|
|
227
|
+
return `${prefix}:${idStr}:${compId}`;
|
|
228
|
+
}
|
|
229
|
+
function buildQueryParams(channelKey) {
|
|
230
|
+
const params = Object.assign({ livecontrols: true }, (channelKey ? { lcchannel: channelKey } : {}));
|
|
231
|
+
return { params, queryString: query_string_1.default.stringify(params) };
|
|
232
|
+
}
|
|
233
|
+
function buildUpdatedUrlFromQuery(query, pathname, queryParams) {
|
|
234
|
+
const queryObj = Object.fromEntries(query.entries());
|
|
235
|
+
const updatedObj = Object.assign(Object.assign({}, queryObj), queryParams);
|
|
236
|
+
const updatedQueryString = new URLSearchParams(updatedObj).toString();
|
|
237
|
+
return `${pathname}?${updatedQueryString}`;
|
|
238
|
+
}
|
|
239
|
+
function resolveVersion(model) {
|
|
240
|
+
var _a, _b;
|
|
241
|
+
const id = model === null || model === void 0 ? void 0 : model.id;
|
|
242
|
+
const versionFromField = (_b = (_a = id === null || id === void 0 ? void 0 : id.version) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
243
|
+
const versionFromToString = typeof (id === null || id === void 0 ? void 0 : id.toString) === 'function' ? id.toString().split('@')[1] : undefined;
|
|
244
|
+
return versionFromField || versionFromToString;
|
|
245
|
+
}
|
|
246
|
+
function hasStableCompareData(contextLoading, base, compare) {
|
|
247
|
+
return !contextLoading && base !== undefined && compare !== undefined;
|
|
248
|
+
}
|
|
249
|
+
function resolveRequestedCompositionId({ selectedCompositionCompareFile, selectedCompositionBaseFile, compareStateId, baseStateId, compareCompositions, baseCompositions, }) {
|
|
250
|
+
var _a, _b;
|
|
251
|
+
const explicitId = selectedCompositionCompareFile || selectedCompositionBaseFile;
|
|
252
|
+
const stateId = compareStateId || baseStateId;
|
|
253
|
+
const defaultId = ((_a = compareCompositions === null || compareCompositions === void 0 ? void 0 : compareCompositions[0]) === null || _a === void 0 ? void 0 : _a.identifier) || ((_b = baseCompositions === null || baseCompositions === void 0 ? void 0 : baseCompositions[0]) === null || _b === void 0 ? void 0 : _b.identifier);
|
|
254
|
+
return explicitId || stateId || defaultId;
|
|
255
|
+
}
|
|
256
|
+
function resolveCompositionId(selectedComposition, requestedCompositionId) {
|
|
257
|
+
return (selectedComposition === null || selectedComposition === void 0 ? void 0 : selectedComposition.identifier) || requestedCompositionId;
|
|
258
|
+
}
|
|
259
|
+
function hasMissingComposition(requestedCompositionId, selectedComposition) {
|
|
260
|
+
return Boolean(requestedCompositionId && !selectedComposition);
|
|
261
|
+
}
|
|
262
|
+
function buildControlsResetKey(baseChannelKey, compareChannelKey) {
|
|
263
|
+
return `${baseChannelKey || ''}-${compareChannelKey || ''}`;
|
|
264
|
+
}
|
|
265
|
+
function formatVersionForLabel(version, opts) {
|
|
266
|
+
if (opts === null || opts === void 0 ? void 0 : opts.forceWorkspace)
|
|
267
|
+
return LOCAL_VERSION;
|
|
268
|
+
if (!version)
|
|
269
|
+
return undefined;
|
|
270
|
+
if (version === LOCAL_VERSION)
|
|
271
|
+
return LOCAL_VERSION;
|
|
272
|
+
return semver.valid(version) ? version : version.slice(0, 6);
|
|
273
|
+
}
|
|
274
|
+
function useStableControlLabels(baseModel, compareModel, compareHasLocalChanges) {
|
|
275
|
+
const baseVersion = (0, react_1.useMemo)(() => formatVersionForLabel(resolveVersion(baseModel)), [baseModel]);
|
|
276
|
+
const compareVersion = (0, react_1.useMemo)(() => formatVersionForLabel(resolveVersion(compareModel), { forceWorkspace: compareHasLocalChanges }), [compareModel, compareHasLocalChanges]);
|
|
277
|
+
const [stableVersions, setStableVersions] = (0, react_1.useState)({
|
|
278
|
+
base: baseVersion,
|
|
279
|
+
compare: compareVersion,
|
|
280
|
+
});
|
|
281
|
+
(0, react_1.useEffect)(() => {
|
|
282
|
+
setStableVersions((prev) => {
|
|
283
|
+
const nextBase = baseVersion !== null && baseVersion !== void 0 ? baseVersion : prev.base;
|
|
284
|
+
const nextCompare = compareVersion !== null && compareVersion !== void 0 ? compareVersion : prev.compare;
|
|
285
|
+
if (nextBase === prev.base && nextCompare === prev.compare)
|
|
286
|
+
return prev;
|
|
287
|
+
return { base: nextBase, compare: nextCompare };
|
|
288
|
+
});
|
|
289
|
+
}, [baseVersion, compareVersion]);
|
|
290
|
+
const effectiveBaseVersion = baseVersion !== null && baseVersion !== void 0 ? baseVersion : stableVersions.base;
|
|
291
|
+
const effectiveCompareVersion = compareVersion !== null && compareVersion !== void 0 ? compareVersion : stableVersions.compare;
|
|
292
|
+
return (0, react_1.useMemo)(() => ({
|
|
293
|
+
common: 'Common',
|
|
294
|
+
base: effectiveBaseVersion ? `Base version: ${effectiveBaseVersion}` : 'Base version',
|
|
295
|
+
compare: effectiveCompareVersion ? `Compare version: ${effectiveCompareVersion}` : 'Compare version',
|
|
296
|
+
}), [effectiveBaseVersion, effectiveCompareVersion]);
|
|
297
|
+
}
|
|
298
|
+
function CompositionLayout({ model, selected, queryParams, compositionParams, previewViewProps, emptyState, PreviewView, contextKey, isBase, isCompare, }) {
|
|
299
|
+
return (react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.subView },
|
|
300
|
+
react_1.default.createElement(composition_compare_context_1.CompositionCompareContext.Provider, { value: {
|
|
301
|
+
compositionProps: Object.assign(Object.assign({ forceHeight: undefined, innerBottomPadding: 50 }, previewViewProps), { emptyState, component: model, queryParams,
|
|
302
|
+
selected }),
|
|
303
|
+
isBase,
|
|
304
|
+
isCompare,
|
|
305
|
+
} },
|
|
306
|
+
react_1.default.createElement(compositions_ui_hooks_use_composition_1.CompositionContextProvider, { queryParams: compositionParams, setQueryParams: noop },
|
|
307
|
+
react_1.default.createElement(PreviewView, Object.assign({ key: contextKey, forceHeight: undefined, innerBottomPadding: 50 }, previewViewProps, { emptyState: emptyState, component: model, selected: selected, queryParams: queryParams }))))));
|
|
308
|
+
}
|
|
42
309
|
function CompositionCompare(props) {
|
|
43
310
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
44
|
-
const { emptyState, PreviewView = compositions_1.CompositionContent, Widgets, previewViewProps = {} } = props;
|
|
311
|
+
const { emptyState, PreviewView = compositions_1.CompositionContent, Widgets, previewViewProps = {}, } = props;
|
|
45
312
|
const componentCompareContext = (0, component_ui_component_compare_context_1.useComponentCompare)();
|
|
46
|
-
const
|
|
313
|
+
const query = (0, ui_foundation_ui_react_router_use_query_1.useQuery)();
|
|
314
|
+
const location = (0, base_react_navigation_link_1.useLocation)() || { pathname: '/' };
|
|
315
|
+
const { base, compare, baseContext, compareContext, loading: contextLoading } = componentCompareContext || {};
|
|
316
|
+
const [isControlsOpen, setControlsOpen] = (0, react_1.useState)(true);
|
|
317
|
+
const [controlsStatus, setControlsStatus] = (0, react_1.useState)('loading');
|
|
318
|
+
const [everHadControls, setEverHadControls] = (0, react_1.useState)(false);
|
|
319
|
+
const { panelRef, panelHeight, isResizing, handleResizeStart } = useResizePanel(240);
|
|
320
|
+
const isStableData = hasStableCompareData(contextLoading, base, compare);
|
|
47
321
|
const baseCompositions = base === null || base === void 0 ? void 0 : base.model.compositions;
|
|
48
322
|
const compareCompositions = compare === null || compare === void 0 ? void 0 : compare.model.compositions;
|
|
49
|
-
const selectedCompositionBaseFile = (
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
323
|
+
const { selectedCompositionBaseFile, selectedCompositionCompareFile } = useCompositionSelection();
|
|
324
|
+
const compareState = (_a = compareContext === null || compareContext === void 0 ? void 0 : compareContext.state) === null || _a === void 0 ? void 0 : _a.preview;
|
|
325
|
+
const baseHooks = (_b = baseContext === null || baseContext === void 0 ? void 0 : baseContext.hooks) === null || _b === void 0 ? void 0 : _b.preview;
|
|
326
|
+
const compareHooks = (_c = compareContext === null || compareContext === void 0 ? void 0 : compareContext.hooks) === null || _c === void 0 ? void 0 : _c.preview;
|
|
327
|
+
const requestedCompositionId = (0, react_1.useMemo)(() => {
|
|
328
|
+
var _a, _b;
|
|
329
|
+
return resolveRequestedCompositionId({
|
|
330
|
+
selectedCompositionCompareFile,
|
|
331
|
+
selectedCompositionBaseFile,
|
|
332
|
+
compareStateId: compareState === null || compareState === void 0 ? void 0 : compareState.id,
|
|
333
|
+
baseStateId: (_b = (_a = baseContext === null || baseContext === void 0 ? void 0 : baseContext.state) === null || _a === void 0 ? void 0 : _a.preview) === null || _b === void 0 ? void 0 : _b.id,
|
|
334
|
+
compareCompositions,
|
|
335
|
+
baseCompositions,
|
|
336
|
+
});
|
|
337
|
+
}, [
|
|
338
|
+
selectedCompositionCompareFile,
|
|
339
|
+
selectedCompositionBaseFile,
|
|
340
|
+
compareState === null || compareState === void 0 ? void 0 : compareState.id,
|
|
341
|
+
(_e = (_d = baseContext === null || baseContext === void 0 ? void 0 : baseContext.state) === null || _d === void 0 ? void 0 : _d.preview) === null || _e === void 0 ? void 0 : _e.id,
|
|
342
|
+
compareCompositions,
|
|
343
|
+
baseCompositions,
|
|
344
|
+
]);
|
|
345
|
+
const selectedBaseComp = findComposition(baseCompositions, requestedCompositionId);
|
|
346
|
+
const selectedCompareComp = findComposition(compareCompositions, requestedCompositionId);
|
|
347
|
+
const baseMissing = hasMissingComposition(requestedCompositionId, selectedBaseComp);
|
|
348
|
+
const compareMissing = hasMissingComposition(requestedCompositionId, selectedCompareComp);
|
|
349
|
+
const baseCompositionIds = (0, react_1.useMemo)(() => new Set((baseCompositions || []).map((c) => c.identifier)), [baseCompositions]);
|
|
350
|
+
const compareCompositionIds = (0, react_1.useMemo)(() => new Set((compareCompositions || []).map((c) => c.identifier)), [compareCompositions]);
|
|
351
|
+
const compositionsDropdownSource = (0, react_1.useMemo)(() => {
|
|
352
|
+
var _a;
|
|
353
|
+
return (_a = (0, lodash_1.uniqBy)((baseCompositions || []).concat(compareCompositions || []), 'identifier')) === null || _a === void 0 ? void 0 : _a.map((c) => {
|
|
354
|
+
const hasInBase = baseCompositionIds.has(c.identifier);
|
|
355
|
+
const hasInCompare = compareCompositionIds.has(c.identifier);
|
|
356
|
+
const tag = getCompositionTag(hasInBase, hasInCompare);
|
|
357
|
+
const href = !(compareState === null || compareState === void 0 ? void 0 : compareState.controlled)
|
|
358
|
+
? buildUpdatedUrlFromQuery(query, location.pathname, {
|
|
359
|
+
compositionBaseFile: c.identifier,
|
|
360
|
+
compositionCompareFile: c.identifier,
|
|
361
|
+
})
|
|
362
|
+
: buildUpdatedUrlFromQuery(query, location.pathname, {});
|
|
363
|
+
const onClick = (compareState === null || compareState === void 0 ? void 0 : compareState.controlled)
|
|
364
|
+
? (id, e) => {
|
|
365
|
+
var _a, _b;
|
|
366
|
+
(_a = compareHooks === null || compareHooks === void 0 ? void 0 : compareHooks.onClick) === null || _a === void 0 ? void 0 : _a.call(compareHooks, id, e);
|
|
367
|
+
(_b = baseHooks === null || baseHooks === void 0 ? void 0 : baseHooks.onClick) === null || _b === void 0 ? void 0 : _b.call(baseHooks, id, e);
|
|
368
|
+
}
|
|
369
|
+
: undefined;
|
|
370
|
+
return { id: c.identifier, label: c.displayName, href, onClick, tag };
|
|
371
|
+
});
|
|
372
|
+
}, [
|
|
373
|
+
baseCompositions,
|
|
374
|
+
compareCompositions,
|
|
375
|
+
baseCompositionIds,
|
|
376
|
+
compareCompositionIds,
|
|
377
|
+
compareState === null || compareState === void 0 ? void 0 : compareState.controlled,
|
|
378
|
+
compareHooks,
|
|
379
|
+
baseHooks,
|
|
380
|
+
query,
|
|
381
|
+
location.pathname,
|
|
382
|
+
]);
|
|
383
|
+
const selectedCompareDropdown = (0, react_1.useMemo)(() => {
|
|
384
|
+
const found = compositionsDropdownSource.find((item) => item.id === (selectedCompareComp === null || selectedCompareComp === void 0 ? void 0 : selectedCompareComp.identifier)) ||
|
|
385
|
+
compositionsDropdownSource.find((item) => item.id === (selectedBaseComp === null || selectedBaseComp === void 0 ? void 0 : selectedBaseComp.identifier));
|
|
386
|
+
if (found)
|
|
387
|
+
return found;
|
|
388
|
+
if (requestedCompositionId)
|
|
389
|
+
return { id: requestedCompositionId, label: requestedCompositionId, tag: 'Missing' };
|
|
390
|
+
return undefined;
|
|
391
|
+
}, [
|
|
392
|
+
compositionsDropdownSource,
|
|
393
|
+
selectedCompareComp === null || selectedCompareComp === void 0 ? void 0 : selectedCompareComp.identifier,
|
|
394
|
+
selectedBaseComp === null || selectedBaseComp === void 0 ? void 0 : selectedBaseComp.identifier,
|
|
395
|
+
requestedCompositionId,
|
|
396
|
+
]);
|
|
397
|
+
const baseIdStr = (_f = base === null || base === void 0 ? void 0 : base.model.id) === null || _f === void 0 ? void 0 : _f.toString();
|
|
398
|
+
const compareIdStr = (_g = compare === null || compare === void 0 ? void 0 : compare.model.id) === null || _g === void 0 ? void 0 : _g.toString();
|
|
399
|
+
(0, compositions_1.useDefaultControlsSchemaResponder)(baseIdStr, Boolean(baseIdStr));
|
|
400
|
+
(0, compositions_1.useDefaultControlsSchemaResponder)(compareIdStr, Boolean(compareIdStr));
|
|
401
|
+
const baseCompId = resolveCompositionId(selectedBaseComp, requestedCompositionId);
|
|
402
|
+
const compareCompId = resolveCompositionId(selectedCompareComp, requestedCompositionId);
|
|
403
|
+
const baseChannelKey = (0, react_1.useMemo)(() => buildChannelKey('base', baseIdStr, baseCompId), [baseIdStr, baseCompId]);
|
|
404
|
+
const compareChannelKey = (0, react_1.useMemo)(() => buildChannelKey('compare', compareIdStr, compareCompId), [compareIdStr, compareCompId]);
|
|
405
|
+
const baseQuery = (0, react_1.useMemo)(() => buildQueryParams(baseChannelKey), [baseChannelKey]);
|
|
406
|
+
const compareQuery = (0, react_1.useMemo)(() => buildQueryParams(compareChannelKey), [compareChannelKey]);
|
|
407
|
+
const controlsResetKey = buildControlsResetKey(baseChannelKey, compareChannelKey);
|
|
408
|
+
const hasControlChannels = Boolean(baseChannelKey && compareChannelKey);
|
|
409
|
+
(0, react_1.useEffect)(() => {
|
|
410
|
+
setEverHadControls(false);
|
|
411
|
+
setControlsStatus('loading');
|
|
412
|
+
}, [controlsResetKey]);
|
|
413
|
+
const handleControlsStatusChange = (0, react_1.useCallback)((status) => {
|
|
414
|
+
setControlsStatus(status);
|
|
415
|
+
if (status === 'available')
|
|
416
|
+
setEverHadControls(true);
|
|
417
|
+
}, []);
|
|
418
|
+
const showControlsPanel = controlsStatus === 'available' || everHadControls;
|
|
419
|
+
const baseModel = base === null || base === void 0 ? void 0 : base.model;
|
|
420
|
+
const compareModel = compare === null || compare === void 0 ? void 0 : compare.model;
|
|
421
|
+
const stableLabels = useStableControlLabels(baseModel, compareModel, compare === null || compare === void 0 ? void 0 : compare.hasLocalChanges);
|
|
119
422
|
const BaseLayout = (0, react_1.useMemo)(() => {
|
|
120
|
-
if (
|
|
423
|
+
if (!isStableData || !baseChannelKey || !baseModel)
|
|
121
424
|
return null;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
425
|
+
if (baseMissing)
|
|
426
|
+
return react_1.default.createElement(MissingComposition, { compositionId: requestedCompositionId, version: "base" });
|
|
427
|
+
return (react_1.default.createElement(CompositionLayout, { model: baseModel, selected: selectedBaseComp, queryParams: baseQuery.queryString, compositionParams: baseQuery.params, previewViewProps: previewViewProps, emptyState: emptyState, PreviewView: PreviewView, contextKey: `base-${baseIdStr}-${baseCompId}`, isBase: true }));
|
|
428
|
+
}, [
|
|
429
|
+
isStableData,
|
|
430
|
+
baseModel,
|
|
431
|
+
baseIdStr,
|
|
432
|
+
baseCompId,
|
|
433
|
+
baseChannelKey,
|
|
434
|
+
selectedBaseComp === null || selectedBaseComp === void 0 ? void 0 : selectedBaseComp.identifier,
|
|
435
|
+
baseQuery,
|
|
436
|
+
previewViewProps,
|
|
437
|
+
emptyState,
|
|
438
|
+
baseMissing,
|
|
439
|
+
requestedCompositionId,
|
|
440
|
+
]);
|
|
130
441
|
const CompareLayout = (0, react_1.useMemo)(() => {
|
|
131
|
-
if (
|
|
442
|
+
if (!isStableData || !compareChannelKey || !compareModel)
|
|
132
443
|
return null;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
444
|
+
if (compareMissing)
|
|
445
|
+
return react_1.default.createElement(MissingComposition, { compositionId: requestedCompositionId, version: "compare" });
|
|
446
|
+
return (react_1.default.createElement(CompositionLayout, { model: compareModel, selected: selectedCompareComp, queryParams: compareQuery.queryString, compositionParams: compareQuery.params, previewViewProps: previewViewProps, emptyState: emptyState, PreviewView: PreviewView, contextKey: `compare-${compareIdStr}-${compareCompId}`, isCompare: true }));
|
|
447
|
+
}, [
|
|
448
|
+
isStableData,
|
|
449
|
+
compareModel,
|
|
450
|
+
compareIdStr,
|
|
451
|
+
compareCompId,
|
|
452
|
+
compareChannelKey,
|
|
453
|
+
selectedCompareComp === null || selectedCompareComp === void 0 ? void 0 : selectedCompareComp.identifier,
|
|
454
|
+
compareQuery,
|
|
455
|
+
previewViewProps,
|
|
456
|
+
emptyState,
|
|
457
|
+
compareMissing,
|
|
458
|
+
requestedCompositionId,
|
|
459
|
+
]);
|
|
460
|
+
const toggleControls = (0, react_1.useCallback)(() => setControlsOpen((x) => !x), []);
|
|
461
|
+
const handleHeaderKeyDown = (0, react_1.useCallback)((e) => {
|
|
462
|
+
if (e.key === 'Enter' || e.key === ' ')
|
|
463
|
+
toggleControls();
|
|
464
|
+
}, [toggleControls]);
|
|
465
|
+
if (!base && !compare)
|
|
466
|
+
return null;
|
|
467
|
+
const key = `${base === null || base === void 0 ? void 0 : base.model.id.toString()}-${compare === null || compare === void 0 ? void 0 : compare.model.id.toString()}-composition-compare`;
|
|
468
|
+
return (react_1.default.createElement("div", { key: key, className: (0, classnames_1.default)(composition_compare_module_scss_1.default.container, { [composition_compare_module_scss_1.default.isResizing]: isResizing }) },
|
|
469
|
+
contextLoading && (react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.loader },
|
|
470
|
+
react_1.default.createElement(design_ui_round_loader_1.RoundLoader, null))),
|
|
471
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.toolbar },
|
|
146
472
|
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.left },
|
|
147
473
|
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.dropdown }, compositionsDropdownSource.length > 0 && (react_1.default.createElement(composition_dropdown_1.CompositionDropdown, { dropdownItems: compositionsDropdownSource, selected: selectedCompareDropdown }))),
|
|
148
474
|
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.widgets }, Widgets === null || Widgets === void 0 ? void 0 : Widgets.Left)),
|
|
149
475
|
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.right },
|
|
150
|
-
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.widgets }, Widgets === null || Widgets === void 0 ? void 0 : Widgets.Right)))
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
476
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.widgets }, Widgets === null || Widgets === void 0 ? void 0 : Widgets.Right))),
|
|
477
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.compareLayout },
|
|
478
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.compareMain },
|
|
479
|
+
react_1.default.createElement(component_ui_component_compare_layouts_compare_split_layout_preset_1.CompareSplitLayoutPreset, { base: BaseLayout, compare: CompareLayout })),
|
|
480
|
+
hasControlChannels && (react_1.default.createElement("div", { ref: panelRef, className: composition_compare_module_scss_1.default.controlsPanel, style: showControlsPanel ? (isControlsOpen ? { height: panelHeight } : undefined) : { display: 'none' } },
|
|
481
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.controlsResizeHandle, onMouseDown: handleResizeStart, role: "separator", "aria-orientation": "horizontal" }),
|
|
482
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.controlsPanelHeader, onClick: toggleControls, onKeyDown: handleHeaderKeyDown, role: "button", tabIndex: 0 },
|
|
483
|
+
react_1.default.createElement(evangelist_elements_icon_1.Icon, { of: isControlsOpen ? 'fat-arrow-down' : 'fat-arrow-up', className: composition_compare_module_scss_1.default.controlsArrow }),
|
|
484
|
+
react_1.default.createElement("span", { className: composition_compare_module_scss_1.default.controlsPanelTitle }, "Live controls")),
|
|
485
|
+
react_1.default.createElement("div", { className: composition_compare_module_scss_1.default.controlsPanelContent, style: { display: isControlsOpen ? undefined : 'none' } },
|
|
486
|
+
react_1.default.createElement(compositions_1.LiveControlsDiffPanel, { resetKey: controlsResetKey, baseChannel: baseChannelKey, compareChannel: compareChannelKey, commonLabel: stableLabels.common, baseLabel: stableLabels.base, compareLabel: stableLabels.compare, showEmptyState: false, onStatusChange: handleControlsStatusChange })))))));
|
|
158
487
|
}
|
|
159
488
|
//# sourceMappingURL=composition-compare.js.map
|