Skip to content

feat: allow using editor in embedded mode #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/scratch-gui/src/exported-reducers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ScratchPaintReducer} from 'scratch-paint';
import LocalesReducer, {localesInitialState, initLocale} from './reducers/locales.js';
import GuiReducer, {buildInitialState, guiMiddleware, initEmbedded, initFullScreen, initPlayer} from './reducers/gui';
import {setFullScreen, setPlayer} from './reducers/mode.js';
import {setFullScreen, setPlayer, setEmbedded} from './reducers/mode.js';
import {activateDeck} from './reducers/cards.js';
import {
LoadingStates,
Expand Down Expand Up @@ -48,5 +48,6 @@ export {
localesInitialState,
setFullScreen,
setPlayer,
setEmbedded,
activateDeck
};
6 changes: 4 additions & 2 deletions packages/scratch-gui/src/lib/app-state-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const AppStateHOC = function (WrappedComponent, localesOnly, configFactory) {
localesOnly,
isFullScreen: props.isFullScreen,
isPlayerOnly: props.isPlayerOnly,
showTelemetryModal: props.showTelemetryModal
showTelemetryModal: props.showTelemetryModal,
isEmbedded: props.isEmbedded
}, configFactory);
}

Expand All @@ -45,7 +46,8 @@ const AppStateHOC = function (WrappedComponent, localesOnly, configFactory) {
isFullScreen: PropTypes.bool,
isPlayerOnly: PropTypes.bool,
isTelemetryEnabled: PropTypes.bool,
showTelemetryModal: PropTypes.bool
showTelemetryModal: PropTypes.bool,
isEmbedded: PropTypes.bool
};
return AppStateWrapper;
};
Expand Down
9 changes: 7 additions & 2 deletions packages/scratch-gui/src/lib/app-state-provider-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Provider} from 'react-redux';
import PropTypes from 'prop-types';

import {EditorState} from './editor-state';
import {setPlayer, setFullScreen} from '../reducers/mode.js';
import {setPlayer, setFullScreen, setEmbedded} from '../reducers/mode.js';
import ConnectedIntlProvider from './connected-intl-provider.jsx';

/**
Expand All @@ -23,6 +23,9 @@ export const AppStateProviderHOC = function (WrappedComponent) {
if (prevProps.isFullScreen !== this.props.isFullScreen) {
this.props.appState.store.dispatch(setFullScreen(this.props.isFullScreen));
}
if (prevProps.isEmbedded !== this.props.isEmbedded) {
this.props.appState.store.dispatch(setEmbedded(this.props.isEmbedded));
}
}

render () {
Expand All @@ -31,6 +34,7 @@ export const AppStateProviderHOC = function (WrappedComponent) {
isFullScreen, // eslint-disable-line no-unused-vars
isPlayerOnly, // eslint-disable-line no-unused-vars
showTelemetryModal, // eslint-disable-line no-unused-vars
isEmbedded, // eslint-disable-line no-unused-vars
...componentProps
} = this.props;
return (
Expand All @@ -50,7 +54,8 @@ export const AppStateProviderHOC = function (WrappedComponent) {
isFullScreen: PropTypes.bool,
isPlayerOnly: PropTypes.bool,
isTelemetryEnabled: PropTypes.bool,
showTelemetryModal: PropTypes.bool
showTelemetryModal: PropTypes.bool,
isEmbedded: PropTypes.bool
};
return AppStateWrapper;
};
9 changes: 7 additions & 2 deletions packages/scratch-gui/src/lib/editor-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface EditorStateParams {
isFullScreen?: boolean;
isPlayerOnly?: boolean;
showTelemetryModal?: boolean;
isEmbedded?: boolean;
}

/**
Expand Down Expand Up @@ -59,7 +60,8 @@ export class EditorState {
guiMiddleware,
initFullScreen,
initPlayer,
initTelemetryModal
initTelemetryModal,
initEmbedded
} = guiRedux;
const {ScratchPaintReducer} = require('scratch-paint');

Expand All @@ -68,13 +70,16 @@ export class EditorState {
require('../legacy-config').legacyConfig;

let initializedGui = buildInitialState(configOrLegacy);
if (params.isFullScreen || params.isPlayerOnly) {
if (params.isFullScreen || params.isPlayerOnly || params.isEmbedded) {
if (params.isFullScreen) {
initializedGui = initFullScreen(initializedGui);
}
if (params.isPlayerOnly) {
initializedGui = initPlayer(initializedGui);
}
if (params.isEmbedded) {
initializedGui = initEmbedded(initializedGui);
}
} else if (params.showTelemetryModal) {
initializedGui = initTelemetryModal(initializedGui);
}
Expand Down
20 changes: 19 additions & 1 deletion packages/scratch-gui/src/reducers/mode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const SET_FULL_SCREEN = 'scratch-gui/mode/SET_FULL_SCREEN';
const SET_PLAYER = 'scratch-gui/mode/SET_PLAYER';
const SET_EMBEDDED = 'scratch-gui/mode/SET_EMBEDDED';

const initialState = {
showBranding: false,
Expand All @@ -20,6 +21,16 @@ const reducer = function (state, action) {
isPlayerOnly: action.isPlayerOnly,
hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly
});
case SET_EMBEDDED:
if (action.isEmbedded) {
return Object.assign({}, state, {
showBranding: true,
isFullScreen: true,
isPlayerOnly: true,
hasEverEnteredEditor: false
});
}
return state;
default:
return state;
}
Expand All @@ -37,10 +48,17 @@ const setPlayer = function (isPlayerOnly) {
isPlayerOnly: isPlayerOnly
};
};
const setEmbedded = function (isEmbedded) {
return {
type: SET_EMBEDDED,
isEmbedded: isEmbedded
};
};

export {
reducer as default,
initialState as modeInitialState,
setFullScreen,
setPlayer
setPlayer,
setEmbedded
};