1+ console . log ( "*** Hello World!" )
2+
3+ import React from 'react' ;
4+ import ReactDOM from 'react-dom' ;
5+ import { compose } from 'redux' ;
6+
7+ import { AppStateHOC } from 'scratch-gui' ;
8+ import GUI from 'scratch-gui' ;
9+ // import { HashParserHOC } from 'scratch-gui';
10+ // import log from '../lib/log.js';
11+
12+ const onClickLogo = ( ) => {
13+ window . location = 'https://scratch.mit.edu' ;
14+ } ;
15+
16+ // const handleTelemetryModalCancel = () => {
17+ // log('User canceled telemetry modal');
18+ // };
19+
20+ // const handleTelemetryModalOptIn = () => {
21+ // log('User opted into telemetry');
22+ // };
23+
24+ // const handleTelemetryModalOptOut = () => {
25+ // log('User opted out of telemetry');
26+ // };
27+
28+ const appTarget = document . createElement ( 'div' ) ;
29+ document . body . appendChild ( appTarget ) ;
30+
31+ /*
32+ * Render the GUI playground. This is a separate function because importing anything
33+ * that instantiates the VM causes unsupported browsers to crash
34+ * {object} appTarget - the DOM element to render to
35+ */
36+ // export default appTarget => {
37+ GUI . setAppElement ( appTarget ) ;
38+
39+ // note that redux's 'compose' function is just being used as a general utility to make
40+ // the hierarchy of HOC constructor calls clearer here; it has nothing to do with redux's
41+ // ability to compose reducers.
42+ const WrappedGui = compose (
43+ AppStateHOC ,
44+ // HashParserHOC
45+ ) ( GUI ) ;
46+
47+ // TODO a hack for testing the backpack, allow backpack host to be set by url param
48+ const backpackHostMatches = window . location . href . match ( / [ ? & ] b a c k p a c k _ h o s t = ( [ ^ & ] * ) & ? / ) ;
49+ const backpackHost = backpackHostMatches ? backpackHostMatches [ 1 ] : null ;
50+
51+ const scratchDesktopMatches = window . location . href . match ( / [ ? & ] i s S c r a t c h D e s k t o p = ( [ ^ & ] + ) / ) ;
52+ let simulateScratchDesktop ;
53+ if ( scratchDesktopMatches ) {
54+ try {
55+ // parse 'true' into `true`, 'false' into `false`, etc.
56+ simulateScratchDesktop = JSON . parse ( scratchDesktopMatches [ 1 ] ) ;
57+ } catch {
58+ // it's not JSON so just use the string
59+ // note that a typo like "falsy" will be treated as true
60+ simulateScratchDesktop = scratchDesktopMatches [ 1 ] ;
61+ }
62+ }
63+
64+ if ( process . env . NODE_ENV === 'production' && typeof window === 'object' ) {
65+ // Warn before navigating away
66+ window . onbeforeunload = ( ) => true ;
67+ }
68+
69+ ReactDOM . render (
70+ // important: this is checking whether `simulateScratchDesktop` is truthy, not just defined!
71+ simulateScratchDesktop ?
72+ < WrappedGui
73+ canEditTitle
74+ isScratchDesktop
75+ showTelemetryModal
76+ canSave = { false }
77+ onTelemetryModalCancel = { handleTelemetryModalCancel }
78+ onTelemetryModalOptIn = { handleTelemetryModalOptIn }
79+ onTelemetryModalOptOut = { handleTelemetryModalOptOut }
80+ /> :
81+ < WrappedGui
82+ canEditTitle
83+ backpackVisible
84+ showComingSoon
85+ backpackHost = { backpackHost }
86+ canSave = { false }
87+ onClickLogo = { onClickLogo }
88+ /> ,
89+ appTarget ) ;
90+ // };
0 commit comments