@teambit/compositions 1.0.893 → 1.0.895
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.section.tsx +1 -0
- package/compositions.tsx +30 -5
- package/dist/composition.section.js +2 -1
- package/dist/composition.section.js.map +1 -1
- package/dist/compositions.d.ts +2 -1
- package/dist/compositions.js +36 -2
- package/dist/compositions.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -1
- package/dist/{preview-1772220644928.js → preview-1772488540837.js} +2 -2
- package/dist/ui/compositions-panel/compositions-panel.js +20 -66
- package/dist/ui/compositions-panel/compositions-panel.js.map +1 -1
- package/dist/ui/compositions-panel/compositions-panel.module.scss +33 -0
- package/dist/ui/compositions-panel/live-control-input.d.ts +1 -0
- package/dist/ui/compositions-panel/live-control-input.js +142 -23
- package/dist/ui/compositions-panel/live-control-input.js.map +1 -1
- package/dist/ui/compositions-panel/live-control-input.module.scss +94 -1
- package/dist/ui/compositions-panel/live-control-panel.d.ts +3 -1
- package/dist/ui/compositions-panel/live-control-panel.js +4 -2
- package/dist/ui/compositions-panel/live-control-panel.js.map +1 -1
- package/dist/ui/compositions-panel/live-controls-diff-panel.d.ts +13 -0
- package/dist/ui/compositions-panel/live-controls-diff-panel.js +220 -0
- package/dist/ui/compositions-panel/live-controls-diff-panel.js.map +1 -0
- package/dist/ui/compositions-panel/live-controls-diff-panel.module.scss +185 -0
- package/dist/ui/compositions-panel/live-controls-renderer.d.ts +1 -0
- package/dist/ui/compositions-panel/live-controls-renderer.js +53 -0
- package/dist/ui/compositions-panel/live-controls-renderer.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +39 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/use-default-controls-schema-responder.d.ts +1 -0
- package/dist/use-default-controls-schema-responder.js +89 -0
- package/dist/use-default-controls-schema-responder.js.map +1 -0
- package/package.json +22 -20
- package/ui/compositions-panel/compositions-panel.module.scss +33 -0
- package/ui/compositions-panel/compositions-panel.tsx +21 -74
- package/ui/compositions-panel/live-control-input.module.scss +94 -1
- package/ui/compositions-panel/live-control-input.tsx +133 -30
- package/ui/compositions-panel/live-control-panel.tsx +4 -1
- package/ui/compositions-panel/live-controls-diff-panel.module.scss +185 -0
- package/ui/compositions-panel/live-controls-diff-panel.tsx +206 -0
- package/ui/compositions-panel/live-controls-renderer.tsx +15 -0
- package/ui/index.ts +4 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDefaultControlsSchemaResponder = useDefaultControlsSchemaResponder;
|
|
7
|
+
function _react() {
|
|
8
|
+
const data = require("react");
|
|
9
|
+
_react = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _apiReferenceHooks() {
|
|
15
|
+
const data = require("@teambit/api-reference.hooks.use-api");
|
|
16
|
+
_apiReferenceHooks = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
const DEFAULT_CONTROLS_REQUEST = 'composition-live-controls:request-default-controls';
|
|
22
|
+
const DEFAULT_CONTROLS_RESPONSE = 'composition-live-controls:default-controls';
|
|
23
|
+
function useDefaultControlsSchemaResponder(componentId, enabled = true) {
|
|
24
|
+
const pendingRequestsRef = (0, _react().useRef)([]);
|
|
25
|
+
const apiComponentId = enabled && componentId ? componentId : undefined;
|
|
26
|
+
const {
|
|
27
|
+
apiModel
|
|
28
|
+
} = (0, _apiReferenceHooks().useAPI)(apiComponentId, [], {
|
|
29
|
+
skipInternals: false
|
|
30
|
+
});
|
|
31
|
+
const schemaObject = (0, _react().useMemo)(() => apiModel?._api?.toObject(), [apiModel]);
|
|
32
|
+
const respondWithSchema = (0, _react().useCallback)(request => {
|
|
33
|
+
if (!schemaObject) return false;
|
|
34
|
+
try {
|
|
35
|
+
request.source.postMessage({
|
|
36
|
+
type: DEFAULT_CONTROLS_RESPONSE,
|
|
37
|
+
payload: {
|
|
38
|
+
id: request.id,
|
|
39
|
+
name: request.name,
|
|
40
|
+
schema: schemaObject
|
|
41
|
+
}
|
|
42
|
+
}, request.origin || '*');
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}, [schemaObject]);
|
|
48
|
+
const onDefaultControlsRequest = (0, _react().useCallback)(event => {
|
|
49
|
+
if (!enabled || !componentId) return;
|
|
50
|
+
const {
|
|
51
|
+
data
|
|
52
|
+
} = event;
|
|
53
|
+
if (!data || data.type !== DEFAULT_CONTROLS_REQUEST) return;
|
|
54
|
+
const payload = data.payload;
|
|
55
|
+
if (!payload?.id || !payload?.name) return;
|
|
56
|
+
if (payload.id !== componentId) return;
|
|
57
|
+
const source = event.source;
|
|
58
|
+
if (!source || source === window) return;
|
|
59
|
+
const request = {
|
|
60
|
+
id: payload.id,
|
|
61
|
+
name: payload.name,
|
|
62
|
+
source,
|
|
63
|
+
origin: event.origin || '*'
|
|
64
|
+
};
|
|
65
|
+
if (!schemaObject) {
|
|
66
|
+
pendingRequestsRef.current.push(request);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
respondWithSchema(request);
|
|
70
|
+
}, [componentId, enabled, respondWithSchema, schemaObject]);
|
|
71
|
+
(0, _react().useEffect)(() => {
|
|
72
|
+
if (!enabled || !componentId) {
|
|
73
|
+
pendingRequestsRef.current = [];
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
window.addEventListener('message', onDefaultControlsRequest);
|
|
77
|
+
return () => {
|
|
78
|
+
window.removeEventListener('message', onDefaultControlsRequest);
|
|
79
|
+
};
|
|
80
|
+
}, [componentId, enabled, onDefaultControlsRequest]);
|
|
81
|
+
(0, _react().useEffect)(() => {
|
|
82
|
+
if (!schemaObject || pendingRequestsRef.current.length === 0) return;
|
|
83
|
+
const pending = pendingRequestsRef.current;
|
|
84
|
+
pendingRequestsRef.current = [];
|
|
85
|
+
pending.forEach(respondWithSchema);
|
|
86
|
+
}, [schemaObject, respondWithSchema]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=use-default-controls-schema-responder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","data","require","_apiReferenceHooks","DEFAULT_CONTROLS_REQUEST","DEFAULT_CONTROLS_RESPONSE","useDefaultControlsSchemaResponder","componentId","enabled","pendingRequestsRef","useRef","apiComponentId","undefined","apiModel","useAPI","skipInternals","schemaObject","useMemo","_api","toObject","respondWithSchema","useCallback","request","source","postMessage","type","payload","id","name","schema","origin","onDefaultControlsRequest","event","window","current","push","useEffect","addEventListener","removeEventListener","length","pending","forEach"],"sources":["use-default-controls-schema-responder.ts"],"sourcesContent":["import { useMemo, useRef, useCallback, useEffect } from 'react';\nimport { useAPI } from '@teambit/api-reference.hooks.use-api';\n\nconst DEFAULT_CONTROLS_REQUEST = 'composition-live-controls:request-default-controls';\nconst DEFAULT_CONTROLS_RESPONSE = 'composition-live-controls:default-controls';\n\ntype DefaultControlsRequestPayload = {\n id: string;\n name: string;\n};\n\ntype PendingDefaultControlsRequest = {\n id: string;\n name: string;\n source: Window;\n origin: string;\n};\n\nexport function useDefaultControlsSchemaResponder(componentId: string | undefined, enabled = true) {\n const pendingRequestsRef = useRef<PendingDefaultControlsRequest[]>([]);\n const apiComponentId = enabled && componentId ? componentId : undefined;\n\n const { apiModel } = useAPI(apiComponentId, [], { skipInternals: false });\n const schemaObject = useMemo(() => apiModel?._api?.toObject(), [apiModel]);\n\n const respondWithSchema = useCallback(\n (request: PendingDefaultControlsRequest) => {\n if (!schemaObject) return false;\n try {\n request.source.postMessage(\n {\n type: DEFAULT_CONTROLS_RESPONSE,\n payload: { id: request.id, name: request.name, schema: schemaObject },\n },\n request.origin || '*'\n );\n return true;\n } catch {\n return false;\n }\n },\n [schemaObject]\n );\n\n const onDefaultControlsRequest = useCallback(\n (event: MessageEvent) => {\n if (!enabled || !componentId) return;\n const { data } = event;\n if (!data || data.type !== DEFAULT_CONTROLS_REQUEST) return;\n const payload = data.payload as DefaultControlsRequestPayload | undefined;\n if (!payload?.id || !payload?.name) return;\n if (payload.id !== componentId) return;\n const source = event.source as Window | null;\n if (!source || source === window) return;\n\n const request: PendingDefaultControlsRequest = {\n id: payload.id,\n name: payload.name,\n source,\n origin: event.origin || '*',\n };\n\n if (!schemaObject) {\n pendingRequestsRef.current.push(request);\n return;\n }\n\n respondWithSchema(request);\n },\n [componentId, enabled, respondWithSchema, schemaObject]\n );\n\n useEffect(() => {\n if (!enabled || !componentId) {\n pendingRequestsRef.current = [];\n return;\n }\n window.addEventListener('message', onDefaultControlsRequest);\n return () => {\n window.removeEventListener('message', onDefaultControlsRequest);\n };\n }, [componentId, enabled, onDefaultControlsRequest]);\n\n useEffect(() => {\n if (!schemaObject || pendingRequestsRef.current.length === 0) return;\n const pending = pendingRequestsRef.current;\n pendingRequestsRef.current = [];\n pending.forEach(respondWithSchema);\n }, [schemaObject, respondWithSchema]);\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,mBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,MAAMG,wBAAwB,GAAG,oDAAoD;AACrF,MAAMC,yBAAyB,GAAG,4CAA4C;AAcvE,SAASC,iCAAiCA,CAACC,WAA+B,EAAEC,OAAO,GAAG,IAAI,EAAE;EACjG,MAAMC,kBAAkB,GAAG,IAAAC,eAAM,EAAkC,EAAE,C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|
"name": "@teambit/compositions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.895",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/compositions/compositions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.compositions",
|
|
8
8
|
"name": "compositions",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.895"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"graphql-tag": "2.12.1",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"classnames": "^2.5.1",
|
|
17
17
|
"@teambit/compositions.model.composition-id": "0.0.506",
|
|
18
18
|
"@teambit/harmony": "0.4.7",
|
|
19
|
-
"@teambit/cli": "0.0.
|
|
20
|
-
"@teambit/component.sources": "0.0.
|
|
21
|
-
"@teambit/legacy.consumer-component": "0.0.
|
|
22
|
-
"@teambit/toolbox.path.match-patterns": "0.0.
|
|
19
|
+
"@teambit/cli": "0.0.1302",
|
|
20
|
+
"@teambit/component.sources": "0.0.152",
|
|
21
|
+
"@teambit/legacy.consumer-component": "0.0.101",
|
|
22
|
+
"@teambit/toolbox.path.match-patterns": "0.0.27",
|
|
23
23
|
"@teambit/ui-foundation.ui.constants.z-indexes": "0.0.504",
|
|
24
24
|
"@teambit/base-ui.surfaces.split-pane.hover-splitter": "1.0.0",
|
|
25
25
|
"@teambit/base-ui.surfaces.split-pane.split-pane": "1.0.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@teambit/documenter.theme.theme-context": "4.0.7",
|
|
33
33
|
"@teambit/documenter.ui.heading": "4.1.8",
|
|
34
34
|
"@teambit/documenter.ui.property-table": "4.1.11",
|
|
35
|
-
"@teambit/panels": "0.0.
|
|
35
|
+
"@teambit/panels": "0.0.1304",
|
|
36
36
|
"@teambit/preview.ui.component-preview": "1.0.31",
|
|
37
37
|
"@teambit/ui-foundation.ui.buttons.collapser": "0.0.233",
|
|
38
38
|
"@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.200",
|
|
@@ -40,10 +40,9 @@
|
|
|
40
40
|
"@teambit/design.ui.empty-box": "0.0.364",
|
|
41
41
|
"@teambit/design.ui.surfaces.status-message-card": "0.0.18",
|
|
42
42
|
"@teambit/mdx.ui.mdx-layout": "1.0.12",
|
|
43
|
-
"@teambit/
|
|
44
|
-
"@teambit/compositions.ui.composition-compare": "0.0.258",
|
|
43
|
+
"@teambit/api-reference.hooks.use-api": "0.0.57",
|
|
45
44
|
"@teambit/workspace.ui.use-workspace-mode": "0.0.2",
|
|
46
|
-
"@teambit/compositions.ui.composition-live-controls": "0.0.
|
|
45
|
+
"@teambit/compositions.ui.composition-live-controls": "0.0.6",
|
|
47
46
|
"@teambit/evangelist.elements.icon": "1.0.5",
|
|
48
47
|
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.502",
|
|
49
48
|
"@teambit/ui-foundation.ui.tree.drawer": "1.0.0",
|
|
@@ -54,16 +53,19 @@
|
|
|
54
53
|
"@teambit/design.inputs.input-text": "1.1.4",
|
|
55
54
|
"@teambit/design.inputs.text-area": "0.0.20",
|
|
56
55
|
"@teambit/design.ui.input.color-picker": "0.0.56",
|
|
57
|
-
"@teambit/
|
|
58
|
-
"@teambit/
|
|
59
|
-
"@teambit/
|
|
60
|
-
"@teambit/
|
|
61
|
-
"@teambit/
|
|
62
|
-
"@teambit/
|
|
63
|
-
"@teambit/
|
|
64
|
-
"@teambit/
|
|
65
|
-
"@teambit/
|
|
66
|
-
"@teambit/
|
|
56
|
+
"@teambit/base-ui.loaders.skeleton": "1.0.1",
|
|
57
|
+
"@teambit/component": "1.0.895",
|
|
58
|
+
"@teambit/graphql": "1.0.895",
|
|
59
|
+
"@teambit/dev-files": "1.0.895",
|
|
60
|
+
"@teambit/envs": "1.0.895",
|
|
61
|
+
"@teambit/preview": "1.0.895",
|
|
62
|
+
"@teambit/schema": "1.0.895",
|
|
63
|
+
"@teambit/scope": "1.0.895",
|
|
64
|
+
"@teambit/workspace": "1.0.895",
|
|
65
|
+
"@teambit/component-compare": "1.0.895",
|
|
66
|
+
"@teambit/compositions.ui.composition-compare-section": "0.0.103",
|
|
67
|
+
"@teambit/compositions.ui.composition-compare": "0.0.260",
|
|
68
|
+
"@teambit/ui": "1.0.895"
|
|
67
69
|
},
|
|
68
70
|
"devDependencies": {
|
|
69
71
|
"@types/lodash": "4.14.165",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
border: none;
|
|
14
14
|
border-bottom: 1px solid var(--bit-border-color-lightest, #ededed);
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
> div:last-child {
|
|
17
18
|
border-bottom: 1px solid var(--bit-border-color-lightest, #ededed);
|
|
18
19
|
}
|
|
@@ -179,3 +180,35 @@
|
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
183
|
+
|
|
184
|
+
.liveControlsSkeleton {
|
|
185
|
+
padding: 12px 16px;
|
|
186
|
+
display: flex;
|
|
187
|
+
flex-direction: column;
|
|
188
|
+
gap: 8px;
|
|
189
|
+
opacity: 1;
|
|
190
|
+
transition:
|
|
191
|
+
opacity 160ms ease-out,
|
|
192
|
+
transform 160ms ease-out;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.liveControlsSkeleton--hidden {
|
|
196
|
+
opacity: 0;
|
|
197
|
+
transform: translateY(2px);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.liveControlsContent {
|
|
201
|
+
opacity: 1;
|
|
202
|
+
transition:
|
|
203
|
+
opacity 160ms ease-out,
|
|
204
|
+
transform 160ms ease-out;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.liveControlsContent--hidden {
|
|
208
|
+
opacity: 0;
|
|
209
|
+
transform: translateY(2px);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.loader {
|
|
213
|
+
color: var(--skeleton-color, #e0e0e0);
|
|
214
|
+
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Icon } from '@teambit/evangelist.elements.icon';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import { useSearchParams } from 'react-router-dom';
|
|
4
|
-
import React, { useCallback,
|
|
4
|
+
import React, { useCallback, useState } from 'react';
|
|
5
5
|
import { DrawerUI } from '@teambit/ui-foundation.ui.tree.drawer';
|
|
6
6
|
import { MenuWidgetIcon } from '@teambit/ui-foundation.ui.menu-widget-icon';
|
|
7
7
|
import { Tooltip } from '@teambit/design.ui.tooltip';
|
|
8
8
|
import { useNavigate, useLocation } from '@teambit/base-react.navigation.link';
|
|
9
|
-
import {
|
|
10
|
-
type LiveControlReadyEventData,
|
|
11
|
-
getReadyListener,
|
|
12
|
-
broadcastUpdate,
|
|
13
|
-
} from '@teambit/compositions.ui.composition-live-controls';
|
|
14
|
-
|
|
9
|
+
import { useLiveControls } from '@teambit/compositions.ui.composition-live-controls';
|
|
15
10
|
import styles from './compositions-panel.module.scss';
|
|
16
11
|
import type { Composition } from '../../composition';
|
|
17
12
|
import { LiveControls } from './live-control-panel';
|
|
@@ -54,10 +49,8 @@ export function CompositionsPanel({
|
|
|
54
49
|
className,
|
|
55
50
|
...rest
|
|
56
51
|
}: CompositionsPanelProps) {
|
|
57
|
-
// setup drawer state
|
|
58
|
-
// TODO: only for alpha versions of live controls. remove when stable.
|
|
59
|
-
const [hasLiveControls, setHasLiveControls] = useState(false);
|
|
60
52
|
const [openDrawerList, onToggleDrawer] = useState(['COMPOSITIONS', 'LIVE_CONTROLS']);
|
|
53
|
+
const { hasLiveControls, ready, defs, values, onChange, setTimestamp } = useLiveControls();
|
|
61
54
|
const handleDrawerToggle = (id: string) => {
|
|
62
55
|
const isDrawerOpen = openDrawerList.includes(id);
|
|
63
56
|
if (isDrawerOpen) {
|
|
@@ -76,25 +69,19 @@ export function CompositionsPanel({
|
|
|
76
69
|
const versionFromQueryParams = searchParams.get('version');
|
|
77
70
|
const navigate = useNavigate();
|
|
78
71
|
|
|
79
|
-
// live control state
|
|
80
|
-
const [controlsTimestamp, setControlsTimestamp] = useState(0);
|
|
81
|
-
const [controlsDefs, setControlsDefs] = useState<any>(null);
|
|
82
|
-
const [controlsValues, setControlsValues] = useState<any>({});
|
|
83
|
-
const [mounter, setMounter] = useState<Window>();
|
|
84
|
-
|
|
85
72
|
// composition navigation action
|
|
86
73
|
const handleSelect = useCallback(
|
|
87
74
|
(selected: Composition) => {
|
|
88
75
|
onSelect && onSelect(selected);
|
|
89
76
|
if (selected === active) return;
|
|
90
|
-
|
|
77
|
+
setTimestamp(0);
|
|
91
78
|
},
|
|
92
|
-
[onSelect]
|
|
79
|
+
[onSelect, active, setTimestamp]
|
|
93
80
|
);
|
|
94
81
|
const onCompositionCodeClicked = useCallback(
|
|
95
82
|
(composition: Composition) => (e: React.MouseEvent<HTMLDivElement>) => {
|
|
96
83
|
e.preventDefault();
|
|
97
|
-
|
|
84
|
+
setTimestamp(0);
|
|
98
85
|
const queryParams = new URLSearchParams();
|
|
99
86
|
if (versionFromQueryParams) {
|
|
100
87
|
queryParams.set('version', versionFromQueryParams);
|
|
@@ -102,45 +89,7 @@ export function CompositionsPanel({
|
|
|
102
89
|
const basePath = location?.pathname.split('/~compositions')[0];
|
|
103
90
|
navigate(`${basePath}/~code/${composition.filepath}?${queryParams.toString()}#search=${composition.identifier}`);
|
|
104
91
|
},
|
|
105
|
-
[location?.pathname, versionFromQueryParams]
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// listen to the mounter for live control updates
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
// TODO: remove when stable.
|
|
111
|
-
window.addEventListener('message', (e: MessageEvent) => {
|
|
112
|
-
if (e.data.type === 'composition-live-controls:activate') {
|
|
113
|
-
setHasLiveControls(true);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
function onLiveControlsSetup(e: MessageEvent<LiveControlReadyEventData>) {
|
|
118
|
-
getReadyListener(e, ({ controls, values, timestamp }) => {
|
|
119
|
-
const iframeWindow = e.source;
|
|
120
|
-
setMounter(iframeWindow as Window);
|
|
121
|
-
setControlsDefs(controls);
|
|
122
|
-
setControlsValues(values);
|
|
123
|
-
setControlsTimestamp(timestamp);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
window.addEventListener('message', onLiveControlsSetup);
|
|
127
|
-
return () => {
|
|
128
|
-
window.removeEventListener('message', onLiveControlsSetup);
|
|
129
|
-
};
|
|
130
|
-
}, []);
|
|
131
|
-
|
|
132
|
-
// sync live control updates back to the mounter
|
|
133
|
-
const onLiveControlsUpdate = useCallback(
|
|
134
|
-
(key: string, value: any) => {
|
|
135
|
-
if (mounter) {
|
|
136
|
-
broadcastUpdate(mounter, controlsTimestamp, {
|
|
137
|
-
key,
|
|
138
|
-
value,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
setControlsValues((prev: any) => ({ ...prev, [key]: value }));
|
|
142
|
-
},
|
|
143
|
-
[mounter, controlsValues, controlsTimestamp]
|
|
92
|
+
[location?.pathname, navigate, setTimestamp, versionFromQueryParams]
|
|
144
93
|
);
|
|
145
94
|
|
|
146
95
|
return (
|
|
@@ -182,22 +131,20 @@ export function CompositionsPanel({
|
|
|
182
131
|
})}
|
|
183
132
|
</ul>
|
|
184
133
|
</DrawerUI>
|
|
185
|
-
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
) : null
|
|
200
|
-
}
|
|
134
|
+
{hasLiveControls ? (
|
|
135
|
+
<DrawerUI
|
|
136
|
+
name="LIVE CONTROLS"
|
|
137
|
+
className={classNames(styles.tab, className)}
|
|
138
|
+
isOpen={openDrawerList.includes('LIVE_CONTROLS')}
|
|
139
|
+
onToggle={() => handleDrawerToggle('LIVE_CONTROLS')}
|
|
140
|
+
>
|
|
141
|
+
{ready ? (
|
|
142
|
+
<LiveControls defs={defs} values={values} onChange={onChange} />
|
|
143
|
+
) : (
|
|
144
|
+
<div className={styles.noLiveControls}>No live controls available for this composition</div>
|
|
145
|
+
)}
|
|
146
|
+
</DrawerUI>
|
|
147
|
+
) : null}
|
|
201
148
|
</div>
|
|
202
149
|
);
|
|
203
150
|
}
|
|
@@ -1,7 +1,96 @@
|
|
|
1
1
|
@import '@teambit/ui-foundation.ui.constants.z-indexes/z-indexes.module.scss';
|
|
2
2
|
|
|
3
3
|
.wrapper {
|
|
4
|
-
|
|
4
|
+
display: block;
|
|
5
|
+
width: 100%;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
margin: 0;
|
|
8
|
+
padding: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.wrapper > * {
|
|
12
|
+
width: 100%;
|
|
13
|
+
min-width: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.fullWidthControl {
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.dropdownField {
|
|
21
|
+
display: block;
|
|
22
|
+
width: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dropdownField :global([class*='dropdownPlaceholder']) {
|
|
26
|
+
width: 100%;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.wrapper :global(textarea) {
|
|
31
|
+
min-height: 78px;
|
|
32
|
+
resize: vertical;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.toggleWrapper {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: flex-start;
|
|
39
|
+
min-height: 36px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.toggleControl {
|
|
43
|
+
width: 42px;
|
|
44
|
+
max-width: 42px;
|
|
45
|
+
min-width: 42px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.toggleControl > * {
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.rangeWrapper {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
gap: 6px;
|
|
56
|
+
padding-top: 4px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.rangeInput {
|
|
60
|
+
width: 100%;
|
|
61
|
+
margin: 0;
|
|
62
|
+
accent-color: var(--primary-color, #6a57fd);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.rangeValue {
|
|
66
|
+
font-size: var(--bit-p-xs, 13px);
|
|
67
|
+
line-height: 1.2;
|
|
68
|
+
color: var(--on-background-color, #222222);
|
|
69
|
+
opacity: 0.85;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.multiSelect {
|
|
73
|
+
width: 100%;
|
|
74
|
+
min-height: 112px;
|
|
75
|
+
padding: 6px 8px;
|
|
76
|
+
border: 1px solid var(--border-medium-color, rgba(0, 0, 0, 0.16));
|
|
77
|
+
border-radius: 8px;
|
|
78
|
+
background: var(--surface-neutral-color, #ffffff);
|
|
79
|
+
color: var(--on-background-color, #222222);
|
|
80
|
+
font: inherit;
|
|
81
|
+
line-height: 1.35;
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
scrollbar-gutter: stable;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.multiSelect:focus {
|
|
87
|
+
outline: none;
|
|
88
|
+
border-color: var(--primary-color, #6a57fd);
|
|
89
|
+
box-shadow: 0 0 0 2px rgba(106, 87, 253, 0.18);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.multiSelect option {
|
|
93
|
+
padding: 4px 6px;
|
|
5
94
|
}
|
|
6
95
|
|
|
7
96
|
.portalMenu {
|
|
@@ -19,3 +108,7 @@
|
|
|
19
108
|
cursor: pointer;
|
|
20
109
|
font-family: 'CircularPro', 'Gill Sans', 'Gill Sans MT', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
21
110
|
}
|
|
111
|
+
|
|
112
|
+
.inputText {
|
|
113
|
+
padding-top: 0px !important;
|
|
114
|
+
}
|