UNPKG

plot-plan-designer

Version:

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

132 lines (131 loc) 6.01 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __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 antd_1 = require("antd"); const i18next_1 = __importDefault(require("i18next")); const Canvas_1 = __importDefault(require("../../canvas/Canvas")); const AnimationProperty_1 = __importDefault(require("../properties/AnimationProperty")); const AnimationModal = (0, react_1.forwardRef)(({ visible, animation, onOk, onCancel, validateTitle, onChange }) => { const [form] = antd_1.Form.useForm(); const containerRef = (0, react_1.useRef)(null); const canvasRef = (0, react_1.useRef)(null); const [dimensions, setDimensions] = (0, react_1.useState)({ width: 150, height: 150 }); (0, react_1.useEffect)(() => { if (!visible && canvasRef.current) { canvasRef.current.handler.animationHandler.stop('animations'); } form.resetFields(); }, [visible, animation, form]); (0, react_1.useEffect)(() => { const waitForContainerRender = (container) => { if (!container) { setTimeout(() => waitForContainerRender(containerRef.current), 5); return; } const width = container.clientWidth; const height = container.clientHeight; setDimensions({ width, height }); const option = { type: 'i-text', text: '\uf3c5', fontFamily: 'Font Awesome 5 Free', fontWeight: 900, fontSize: 60, width: 30, height: 30, editable: false, name: 'New marker', tooltip: { enabled: false, }, left: 200, top: 50, id: 'animations', fill: 'rgba(0, 0, 0, 1)', stroke: 'rgba(255, 255, 255, 0)', }; if (canvasRef.current) { canvasRef.current.handler.add(option); } }; if (visible) { waitForContainerRender(containerRef.current); } }, [visible]); (0, react_1.useEffect)(() => { const waitForCanvasRender = (canvas, anim) => { if (!canvas) { setTimeout(() => waitForCanvasRender(canvasRef.current, anim), 5); return; } canvas.handler.setById('animations', 'animation', anim); }; if (visible) { waitForCanvasRender(canvasRef.current, animation); } }, [animation, visible]); return (react_1.default.createElement(antd_1.Modal, { open: visible, onOk: onOk, onCancel: onCancel, title: i18next_1.default.t('common.title') }, react_1.default.createElement(antd_1.Form, { form: form, layout: "vertical" }, react_1.default.createElement(antd_1.Form.Item, { label: i18next_1.default.t('common.title'), required: true, hasFeedback: true, help: validateTitle.help, validateStatus: validateTitle.validateStatus }, react_1.default.createElement(antd_1.Input, { value: animation === null || animation === void 0 ? void 0 : animation.title, onChange: (e) => { const updatedTitle = e.target.value; onChange === null || onChange === void 0 ? void 0 : onChange(null, { animation: { title: updatedTitle } }, { animation: Object.assign(Object.assign({}, animation), { title: updatedTitle }) }); } })), AnimationProperty_1.default.render(canvasRef.current, form, { animation, id: 'animations', })), react_1.default.createElement("div", { ref: containerRef }, react_1.default.createElement(Canvas_1.default, { ref: canvasRef, editable: false, canvasOption: { width: dimensions.width, height: dimensions.height, backgroundColor: '#f3f3f3', }, workareaOption: { backgroundColor: 'transparent' } })))); }); AnimationModal.displayName = 'AnimationModal'; AnimationModal.propTypes = { visible: prop_types_1.default.bool, animation: prop_types_1.default.object, onOk: prop_types_1.default.func, onCancel: prop_types_1.default.func, validateTitle: prop_types_1.default.object, onChange: prop_types_1.default.func, }; exports.default = AnimationModal;