need to fix window message
This commit is contained in:
parent
6c9e0aaa1a
commit
2a2ddf205a
23 changed files with 126 additions and 161 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { loadFeaturedPatterns, loadPublicPatterns } from '@src/user_pattern_utils.mjs';
|
||||
import { MiniRepl } from '@src/docs/MiniRepl';
|
||||
import { PatternLabel } from '@src/repl/panel/PatternsTab';
|
||||
import { PatternLabel } from '@src/repl/components/panel/PatternsTab';
|
||||
|
||||
function PatternList({ patterns }) {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ import { useRef } from 'react';
|
|||
|
||||
export function UdelFrame({ onEvaluate, hash, instance }) {
|
||||
const ref = useRef();
|
||||
|
||||
console.info('frame')
|
||||
window.addEventListener('message', (message) => {
|
||||
console.info(message, 'message')
|
||||
const childWindow = ref?.current?.contentWindow;
|
||||
if (message == null || message.source !== childWindow) {
|
||||
return; // Skip message in this event listener
|
||||
|
|
|
|||
|
|
@ -4,36 +4,7 @@ import { UdelFrame } from './UdelFrame';
|
|||
import { useState } from 'react';
|
||||
import UdelsHeader from './UdelsHeader';
|
||||
|
||||
function NumberInput({ value, onChange, label = '', min, max }) {
|
||||
const [localState, setLocalState] = useState(value);
|
||||
const [isFocused, setIsFocused] = useState(false);
|
||||
|
||||
return (
|
||||
<label>
|
||||
{label}
|
||||
<input
|
||||
min={min}
|
||||
max={max}
|
||||
className="p-2 bg-background rounded-md text-foreground"
|
||||
type={'number'}
|
||||
value={(isFocused ? localState : value) ?? ''}
|
||||
onFocus={() => {
|
||||
setLocalState(value);
|
||||
setIsFocused(true);
|
||||
}}
|
||||
onBlur={() => {
|
||||
onChange(Math.max(localState, min));
|
||||
setIsFocused(false);
|
||||
}}
|
||||
onChange={(e) => {
|
||||
let val = e.target.value;
|
||||
val = val.length ? Math.min(parseFloat(e.target.value), max) : null;
|
||||
setLocalState(val);
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
const defaultHash = 'c3RhY2soCiAgCik%3D';
|
||||
|
||||
const getHashesFromUrl = () => {
|
||||
|
|
@ -60,6 +31,7 @@ export function Udels() {
|
|||
const onEvaluate = (key, code) => {
|
||||
const hashes = getHashesFromUrl();
|
||||
hashes[key] = code2hash(code);
|
||||
|
||||
updateURLHashes(hashes);
|
||||
};
|
||||
// useEffect(() => {
|
||||
|
|
@ -78,17 +50,6 @@ export function Udels() {
|
|||
}}
|
||||
>
|
||||
<UdelsHeader numWindows={numWindows} setNumWindows={numWindowsOnChange} />
|
||||
{/* <div
|
||||
style={{
|
||||
height: 40,
|
||||
width: '100',
|
||||
position: 'absolute',
|
||||
color: 'white',
|
||||
zIndex: 10,
|
||||
}}
|
||||
>
|
||||
<NumberInput min={1} max={8} value={numWindows} onChange={numWindowsOnChange} />
|
||||
</div> */}
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ReplContext } from '@src/repl/util.mjs';
|
||||
|
||||
import Loader from '@src/repl/Loader';
|
||||
import { Panel } from '@src/repl/panel/Panel';
|
||||
import Loader from '@src/repl/components/Loader';
|
||||
import { Panel } from '@src/repl/components/panel/Panel';
|
||||
import { Code } from '@src/repl/components/Code';
|
||||
import BigPlayButton from '@src/repl/components/BigPlayButton';
|
||||
import UserFacingErrorMessage from '@src/repl/components/UserFacingErrorMessage';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import NumberInput from '@src/repl/panel/NumberInput';
|
||||
import NumberInput from '@src/repl/components/NumberInput';
|
||||
|
||||
export default function UdelsHeader(Props) {
|
||||
const { numWindows, setNumWindows } = Props;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue