@remotion/studio
Version:
APIs for interacting with the Remotion Studio
102 lines (101 loc) • 5 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Editor = exports.BUFFER_STATE_DELAY_IN_MILLISECONDS = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const player_1 = require("@remotion/player");
const react_1 = __importStar(require("react"));
const remotion_1 = require("remotion");
const colors_1 = require("../helpers/colors");
const noop_1 = require("../helpers/noop");
const canvas_ref_1 = require("../state/canvas-ref");
const timeline_zoom_1 = require("../state/timeline-zoom");
const z_index_1 = require("../state/z-index");
const EditorContent_1 = require("./EditorContent");
const GlobalKeybindings_1 = require("./GlobalKeybindings");
const Modals_1 = require("./Modals");
const NotificationCenter_1 = require("./Notifications/NotificationCenter");
const TopPanel_1 = require("./TopPanel");
const background = {
backgroundColor: colors_1.BACKGROUND,
display: 'flex',
width: '100%',
height: '100%',
flexDirection: 'column',
position: 'absolute',
};
const DEFAULT_BUFFER_STATE_DELAY_IN_MILLISECONDS = 300;
exports.BUFFER_STATE_DELAY_IN_MILLISECONDS = typeof process.env.BUFFER_STATE_DELAY_IN_MILLISECONDS === 'undefined' ||
process.env.BUFFER_STATE_DELAY_IN_MILLISECONDS === null
? DEFAULT_BUFFER_STATE_DELAY_IN_MILLISECONDS
: Number(process.env.BUFFER_STATE_DELAY_IN_MILLISECONDS);
const Editor = ({ Root, readOnlyStudio }) => {
const size = player_1.PlayerInternals.useElementSize(canvas_ref_1.drawRef, {
triggerOnWindowResize: false,
shouldApplyCssTransforms: true,
});
(0, react_1.useEffect)(() => {
if (readOnlyStudio) {
return;
}
const listenToChanges = (e) => {
if (window.remotion_unsavedProps) {
e.returnValue = 'Are you sure you want to leave?';
}
};
window.addEventListener('beforeunload', listenToChanges);
return () => {
window.removeEventListener('beforeunload', listenToChanges);
};
}, [readOnlyStudio]);
const [canvasMounted, setCanvasMounted] = react_1.default.useState(false);
const onMounted = (0, react_1.useCallback)(() => {
setCanvasMounted(true);
}, []);
const value = (0, react_1.useMemo)(() => {
if (!size) {
return null;
}
return {
type: 'canvas-size',
canvasSize: size,
};
}, [size]);
const MemoRoot = (0, react_1.useMemo)(() => {
return react_1.default.memo(Root);
}, [Root]);
return ((0, jsx_runtime_1.jsx)(z_index_1.HigherZIndex, { onEscape: noop_1.noop, onOutsideClick: noop_1.noop, children: (0, jsx_runtime_1.jsxs)(timeline_zoom_1.TimelineZoomContext, { children: [(0, jsx_runtime_1.jsx)(remotion_1.Internals.CurrentScaleContext.Provider, { value: value, children: (0, jsx_runtime_1.jsxs)("div", { style: background, children: [canvasMounted ? (0, jsx_runtime_1.jsx)(MemoRoot, {}) : null, (0, jsx_runtime_1.jsxs)(remotion_1.Internals.CanUseRemotionHooksProvider, { children: [(0, jsx_runtime_1.jsx)(EditorContent_1.EditorContent, { readOnlyStudio: readOnlyStudio, children: (0, jsx_runtime_1.jsx)(TopPanel_1.TopPanel, { drawRef: canvas_ref_1.drawRef, bufferStateDelayInMilliseconds: exports.BUFFER_STATE_DELAY_IN_MILLISECONDS, onMounted: onMounted, readOnlyStudio: readOnlyStudio }) }), (0, jsx_runtime_1.jsx)(GlobalKeybindings_1.GlobalKeybindings, {})] })] }) }), (0, jsx_runtime_1.jsx)(Modals_1.Modals, { readOnlyStudio: readOnlyStudio }), (0, jsx_runtime_1.jsx)(NotificationCenter_1.NotificationCenter, {})] }) }));
};
exports.Editor = Editor;