Fix PR comments:
- change the onChange handler to return onChange rather than onBlur - Change the vega component to a checkbox - Create new IDs + check whether it works with multiple editors - Multiple line squiggle editors (noticed this was an issue) - Remove ace imports that are not used
This commit is contained in:
		
							parent
							
								
									427c5d5615
								
							
						
					
					
						commit
						e1295e4f0f
					
				| 
						 | 
					@ -1,10 +1,9 @@
 | 
				
			||||||
 | 
					import _ from "lodash";
 | 
				
			||||||
import React, { FC } from "react";
 | 
					import React, { FC } from "react";
 | 
				
			||||||
import AceEditor from "react-ace";
 | 
					import AceEditor from "react-ace";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "ace-builds/src-noconflict/mode-golang";
 | 
					import "ace-builds/src-noconflict/mode-golang";
 | 
				
			||||||
import "ace-builds/src-noconflict/theme-github";
 | 
					import "ace-builds/src-noconflict/theme-github";
 | 
				
			||||||
import "ace-builds/src-noconflict/ext-language_tools";
 | 
					 | 
				
			||||||
import "ace-builds/src-noconflict/keybinding-vim";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface CodeEditorProps {
 | 
					interface CodeEditorProps {
 | 
				
			||||||
  value: string;
 | 
					  value: string;
 | 
				
			||||||
| 
						 | 
					@ -18,26 +17,30 @@ export let CodeEditor: FC<CodeEditorProps> = ({
 | 
				
			||||||
  onChange,
 | 
					  onChange,
 | 
				
			||||||
  oneLine = false,
 | 
					  oneLine = false,
 | 
				
			||||||
  width = 500,
 | 
					  width = 500,
 | 
				
			||||||
}: CodeEditorProps) => (
 | 
					}: CodeEditorProps) => {
 | 
				
			||||||
 | 
					  let lineCount = value.split("\n").length;
 | 
				
			||||||
 | 
					  let id = _.uniqueId();
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
    <AceEditor
 | 
					    <AceEditor
 | 
				
			||||||
      value={value}
 | 
					      value={value}
 | 
				
			||||||
      mode="golang"
 | 
					      mode="golang"
 | 
				
			||||||
      theme="github"
 | 
					      theme="github"
 | 
				
			||||||
      width={width + "px"}
 | 
					      width={width + "px"}
 | 
				
			||||||
    maxLines={oneLine ? 1 : 15}
 | 
					      minLines={oneLine ? lineCount : 15}
 | 
				
			||||||
    minLines={oneLine ? 1 : 15}
 | 
					      maxLines={oneLine ? lineCount : 15}
 | 
				
			||||||
      showGutter={false}
 | 
					      showGutter={false}
 | 
				
			||||||
      highlightActiveLine={false}
 | 
					      highlightActiveLine={false}
 | 
				
			||||||
      showPrintMargin={false}
 | 
					      showPrintMargin={false}
 | 
				
			||||||
      onChange={onChange}
 | 
					      onChange={onChange}
 | 
				
			||||||
    name="UNIQUE_ID_OF_DIV"
 | 
					      name={id}
 | 
				
			||||||
      editorProps={{
 | 
					      editorProps={{
 | 
				
			||||||
        $blockScrolling: true,
 | 
					        $blockScrolling: true,
 | 
				
			||||||
      }}
 | 
					      }}
 | 
				
			||||||
      setOptions={{
 | 
					      setOptions={{
 | 
				
			||||||
        enableBasicAutocompletion: false,
 | 
					        enableBasicAutocompletion: false,
 | 
				
			||||||
      enableLiveAutocompletion: true,
 | 
					        enableLiveAutocompletion: false,
 | 
				
			||||||
      }}
 | 
					      }}
 | 
				
			||||||
    />
 | 
					    />
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
export default CodeEditor;
 | 
					export default CodeEditor;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function renderSquiggleEditor(props: SquiggleEditorProps) {
 | 
					export function renderSquiggleEditorToDom(props: SquiggleEditorProps) {
 | 
				
			||||||
  let parent = document.createElement("div");
 | 
					  let parent = document.createElement("div");
 | 
				
			||||||
  ReactDOM.render(
 | 
					  ReactDOM.render(
 | 
				
			||||||
    <SquiggleEditor
 | 
					    <SquiggleEditor
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,8 +20,8 @@ function FieldFloat(Props: FieldFloatProps) {
 | 
				
			||||||
      <Input
 | 
					      <Input
 | 
				
			||||||
        value={contents}
 | 
					        value={contents}
 | 
				
			||||||
        className={Props.className ? Props.className : ""}
 | 
					        className={Props.className ? Props.className : ""}
 | 
				
			||||||
        onChange={(e) => setContents(e.target.value)}
 | 
					        onChange={(e) => {
 | 
				
			||||||
        onBlur={() => {
 | 
					          setContents(e.target.value);
 | 
				
			||||||
          let result = parseFloat(contents);
 | 
					          let result = parseFloat(contents);
 | 
				
			||||||
          if (_.isFinite(result)) {
 | 
					          if (_.isFinite(result)) {
 | 
				
			||||||
            Props.onChange(result);
 | 
					            Props.onChange(result);
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,7 @@ let SquigglePlayground: FC<Props> = (props) => {
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
export default SquigglePlayground;
 | 
					export default SquigglePlayground;
 | 
				
			||||||
export function renderSquigglePlayground(props: Props) {
 | 
					export function renderSquigglePlaygroundToDom(props: Props) {
 | 
				
			||||||
  let parent = document.createElement("div");
 | 
					  let parent = document.createElement("div");
 | 
				
			||||||
  ReactDOM.render(<SquigglePlayground {...props} />, parent);
 | 
					  ReactDOM.render(<SquigglePlayground {...props} />, parent);
 | 
				
			||||||
  return parent;
 | 
					  return parent;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
export { SquiggleChart } from "./SquiggleChart";
 | 
					export { SquiggleChart } from "./SquiggleChart";
 | 
				
			||||||
export { SquiggleEditor, renderSquiggleEditor } from "./SquiggleEditor";
 | 
					export { SquiggleEditor, renderSquiggleEditorToDom } from "./SquiggleEditor";
 | 
				
			||||||
import SquigglePlayground, {
 | 
					import SquigglePlayground, {
 | 
				
			||||||
  renderSquigglePlayground,
 | 
					  renderSquigglePlaygroundToDom,
 | 
				
			||||||
} from "./SquigglePlayground";
 | 
					} from "./SquigglePlayground";
 | 
				
			||||||
export { SquigglePlayground, renderSquigglePlayground };
 | 
					export { SquigglePlayground, renderSquigglePlaygroundToDom };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,21 +16,19 @@
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      "name": "xscale",
 | 
					      "name": "xscale",
 | 
				
			||||||
      "description": "The transform of the x scale",
 | 
					      "description": "The transform of the x scale",
 | 
				
			||||||
      "value": 1.0,
 | 
					      "value": false,
 | 
				
			||||||
      "bind": {
 | 
					      "bind": {
 | 
				
			||||||
        "input": "select",
 | 
					        "input": "checkbox",
 | 
				
			||||||
        "options": [0.1, 1],
 | 
					        "name": "log x scale"
 | 
				
			||||||
        "labels": ["log", "linear"]
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      "name": "yscale",
 | 
					      "name": "yscale",
 | 
				
			||||||
      "description": "The transform of the y scale",
 | 
					      "description": "The transform of the y scale",
 | 
				
			||||||
      "value": 1.0,
 | 
					      "value": false,
 | 
				
			||||||
      "bind": {
 | 
					      "bind": {
 | 
				
			||||||
        "input": "select",
 | 
					        "input": "checkbox",
 | 
				
			||||||
        "options": [0.1, 1],
 | 
					        "name": "log y scale"
 | 
				
			||||||
        "labels": ["log", "linear"]
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
| 
						 | 
					@ -39,7 +37,7 @@
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      "name": "xscale",
 | 
					      "name": "xscale",
 | 
				
			||||||
      "type": "pow",
 | 
					      "type": "pow",
 | 
				
			||||||
      "exponent": { "signal": "xscale" },
 | 
					      "exponent": { "signal": "xscale ? 0.1 : 1" },
 | 
				
			||||||
      "range": "width",
 | 
					      "range": "width",
 | 
				
			||||||
      "zero": false,
 | 
					      "zero": false,
 | 
				
			||||||
      "nice": false,
 | 
					      "nice": false,
 | 
				
			||||||
| 
						 | 
					@ -53,7 +51,7 @@
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      "name": "yscale",
 | 
					      "name": "yscale",
 | 
				
			||||||
      "type": "pow",
 | 
					      "type": "pow",
 | 
				
			||||||
      "exponent": { "signal": "yscale" },
 | 
					      "exponent": { "signal": "yscale ? 0.1 : 1" },
 | 
				
			||||||
      "range": "height",
 | 
					      "range": "height",
 | 
				
			||||||
      "nice": true,
 | 
					      "nice": true,
 | 
				
			||||||
      "zero": true,
 | 
					      "zero": true,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,3 +20,16 @@ the distribution.
 | 
				
			||||||
    {Template.bind({})}
 | 
					    {Template.bind({})}
 | 
				
			||||||
  </Story>
 | 
					  </Story>
 | 
				
			||||||
</Canvas>
 | 
					</Canvas>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can also name variables like so:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<Canvas>
 | 
				
			||||||
 | 
					  <Story
 | 
				
			||||||
 | 
					    name="Variables"
 | 
				
			||||||
 | 
					    args={{
 | 
				
			||||||
 | 
					      initialSquiggleString: "x = 2\nnormal(x,2)",
 | 
				
			||||||
 | 
					    }}
 | 
				
			||||||
 | 
					  >
 | 
				
			||||||
 | 
					    {Template.bind({})}
 | 
				
			||||||
 | 
					  </Story>
 | 
				
			||||||
 | 
					</Canvas>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user