UNPKG

plot-plan-designer

Version:

Design Editor Tools with React.js + ant.design + fabric.js

103 lines (102 loc) 4.22 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const prop_types_1 = __importDefault(require("prop-types")); const react_ace_1 = __importDefault(require("react-ace")); const debounce_1 = __importDefault(require("lodash/debounce")); require("ace-builds/src-noconflict/mode-javascript"); require("ace-builds/src-noconflict/theme-github"); let InputScript = /** @class */ (() => { class InputScript extends react_1.Component { constructor() { super(...arguments); this.state = { text: this.props.value || '', }; this.onChange = (value, e) => { if (this.debouncedValidate) { this.debouncedValidate(); } this.setState({ text: value, }); }; this.onValidate = annotations => { if (annotations.length) { const errors = annotations .filter(annotation => annotation.type === 'error') .map(annotation => { return new Error(`${annotation.row}:${annotation.column} ${annotation.text} error`); }); this.debouncedValidate(errors); } }; } componentDidMount() { this.debouncedValidate = debounce_1.default(errors => { const { onValidate } = this.props; if (onValidate) { onValidate(errors); } const { onChange } = this.props; if (onChange) { onChange(this.state.text); } }, 200); } UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.value !== this.props.value) { this.setState({ text: nextProps.value, }); } } render() { const { defaultValue, width, height, dsiabled } = this.props; const { text } = this.state; return (react_1.default.createElement(react_ace_1.default, { ref: c => { this.aceRef = c; }, mode: "javascript", theme: "github", width: width, height: height, defaultValue: defaultValue || text, value: text, editorProps: { $blockScrolling: true, }, onChange: this.onChange, onValidate: this.onValidate, readOnly: dsiabled })); } } InputScript.propTypes = { defaultValue: prop_types_1.default.string, value: prop_types_1.default.string, width: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.number]), height: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.number]), onChange: prop_types_1.default.func, onValidate: prop_types_1.default.func, disabled: prop_types_1.default.bool, }; InputScript.defaultProps = { width: '100%', height: '200px', disabled: false, }; return InputScript; })(); exports.default = InputScript;