UNPKG

devextreme-react

Version:

DevExtreme React UI and Visualization Components

435 lines (433 loc) • 14 kB
/*! * devextreme-react * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-react */ "use client"; import * as React from "react"; import { memo, forwardRef, useImperativeHandle, useRef, useMemo } from "react"; import dxDiagram from "devextreme/ui/diagram"; import { Component as BaseComponent } from "./core/component"; import NestedOption from "./core/nested-option"; const Diagram = memo(forwardRef((props, ref) => { const baseRef = useRef(null); useImperativeHandle(ref, () => ({ instance() { return baseRef.current?.getInstance(); } }), [baseRef.current]); const subscribableOptions = useMemo(() => (["gridSize", "gridSize.value", "pageSize", "pageSize.height", "pageSize.width", "zoomLevel", "zoomLevel.value"]), []); const independentEvents = useMemo(() => (["onContentReady", "onCustomCommand", "onDisposing", "onInitialized", "onItemClick", "onItemDblClick", "onRequestEditOperation", "onRequestLayoutUpdate"]), []); const defaults = useMemo(() => ({ defaultGridSize: "gridSize", defaultPageSize: "pageSize", defaultZoomLevel: "zoomLevel", }), []); const expectedChildren = useMemo(() => ({ contextMenu: { optionName: "contextMenu", isCollectionItem: false }, contextToolbox: { optionName: "contextToolbox", isCollectionItem: false }, customShape: { optionName: "customShapes", isCollectionItem: true }, defaultItemProperties: { optionName: "defaultItemProperties", isCollectionItem: false }, edges: { optionName: "edges", isCollectionItem: false }, editing: { optionName: "editing", isCollectionItem: false }, export: { optionName: "export", isCollectionItem: false }, gridSize: { optionName: "gridSize", isCollectionItem: false }, historyToolbar: { optionName: "historyToolbar", isCollectionItem: false }, mainToolbar: { optionName: "mainToolbar", isCollectionItem: false }, nodes: { optionName: "nodes", isCollectionItem: false }, pageSize: { optionName: "pageSize", isCollectionItem: false }, propertiesPanel: { optionName: "propertiesPanel", isCollectionItem: false }, toolbox: { optionName: "toolbox", isCollectionItem: false }, viewToolbar: { optionName: "viewToolbar", isCollectionItem: false }, zoomLevel: { optionName: "zoomLevel", isCollectionItem: false } }), []); const templateProps = useMemo(() => ([ { tmplOption: "customShapeTemplate", render: "customShapeRender", component: "customShapeComponent" }, { tmplOption: "customShapeToolboxTemplate", render: "customShapeToolboxRender", component: "customShapeToolboxComponent" }, ]), []); return (React.createElement((BaseComponent), { WidgetClass: dxDiagram, ref: baseRef, subscribableOptions, independentEvents, defaults, expectedChildren, templateProps, ...props, })); })); const _componentAutoLayout = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "autoLayout", }, }); }; const AutoLayout = Object.assign(_componentAutoLayout, { componentType: "option", }); const _componentCommand = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "commands", IsCollectionItem: true, ExpectedChildren: { item: { optionName: "items", isCollectionItem: true } }, }, }); }; const Command = Object.assign(_componentCommand, { componentType: "option", }); const _componentCommandItem = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "items", IsCollectionItem: true, }, }); }; const CommandItem = Object.assign(_componentCommandItem, { componentType: "option", }); const _componentConnectionPoint = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "connectionPoints", IsCollectionItem: true, }, }); }; const ConnectionPoint = Object.assign(_componentConnectionPoint, { componentType: "option", }); const _componentContextMenu = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "contextMenu", ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const ContextMenu = Object.assign(_componentContextMenu, { componentType: "option", }); const _componentContextToolbox = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "contextToolbox", }, }); }; const ContextToolbox = Object.assign(_componentContextToolbox, { componentType: "option", }); const _componentCustomShape = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "customShapes", IsCollectionItem: true, ExpectedChildren: { connectionPoint: { optionName: "connectionPoints", isCollectionItem: true } }, TemplateProps: [{ tmplOption: "template", render: "render", component: "component" }, { tmplOption: "toolboxTemplate", render: "toolboxRender", component: "toolboxComponent" }], }, }); }; const CustomShape = Object.assign(_componentCustomShape, { componentType: "option", }); const _componentDefaultItemProperties = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "defaultItemProperties", }, }); }; const DefaultItemProperties = Object.assign(_componentDefaultItemProperties, { componentType: "option", }); const _componentEdges = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "edges", }, }); }; const Edges = Object.assign(_componentEdges, { componentType: "option", }); const _componentEditing = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "editing", }, }); }; const Editing = Object.assign(_componentEditing, { componentType: "option", }); const _componentExport = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "export", }, }); }; const Export = Object.assign(_componentExport, { componentType: "option", }); const _componentGridSize = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "gridSize", DefaultsProps: { defaultValue: "value" }, }, }); }; const GridSize = Object.assign(_componentGridSize, { componentType: "option", }); const _componentGroup = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "groups", IsCollectionItem: true, ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const Group = Object.assign(_componentGroup, { componentType: "option", }); const _componentHistoryToolbar = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "historyToolbar", ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const HistoryToolbar = Object.assign(_componentHistoryToolbar, { componentType: "option", }); const _componentItem = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "items", IsCollectionItem: true, }, }); }; const Item = Object.assign(_componentItem, { componentType: "option", }); const _componentMainToolbar = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "mainToolbar", ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const MainToolbar = Object.assign(_componentMainToolbar, { componentType: "option", }); const _componentNodes = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "nodes", ExpectedChildren: { autoLayout: { optionName: "autoLayout", isCollectionItem: false } }, }, }); }; const Nodes = Object.assign(_componentNodes, { componentType: "option", }); const _componentPageSize = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "pageSize", DefaultsProps: { defaultHeight: "height", defaultWidth: "width" }, ExpectedChildren: { item: { optionName: "items", isCollectionItem: true }, pageSizeItem: { optionName: "items", isCollectionItem: true } }, }, }); }; const PageSize = Object.assign(_componentPageSize, { componentType: "option", }); const _componentPageSizeItem = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "items", IsCollectionItem: true, }, }); }; const PageSizeItem = Object.assign(_componentPageSizeItem, { componentType: "option", }); const _componentPropertiesPanel = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "propertiesPanel", ExpectedChildren: { tab: { optionName: "tabs", isCollectionItem: true } }, }, }); }; const PropertiesPanel = Object.assign(_componentPropertiesPanel, { componentType: "option", }); const _componentTab = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "tabs", IsCollectionItem: true, ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true }, group: { optionName: "groups", isCollectionItem: true }, tabGroup: { optionName: "groups", isCollectionItem: true } }, }, }); }; const Tab = Object.assign(_componentTab, { componentType: "option", }); const _componentTabGroup = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "groups", IsCollectionItem: true, ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const TabGroup = Object.assign(_componentTabGroup, { componentType: "option", }); const _componentToolbox = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "toolbox", ExpectedChildren: { group: { optionName: "groups", isCollectionItem: true }, toolboxGroup: { optionName: "groups", isCollectionItem: true } }, }, }); }; const Toolbox = Object.assign(_componentToolbox, { componentType: "option", }); const _componentToolboxGroup = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "groups", IsCollectionItem: true, }, }); }; const ToolboxGroup = Object.assign(_componentToolboxGroup, { componentType: "option", }); const _componentViewToolbar = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "viewToolbar", ExpectedChildren: { command: { optionName: "commands", isCollectionItem: true } }, }, }); }; const ViewToolbar = Object.assign(_componentViewToolbar, { componentType: "option", }); const _componentZoomLevel = (props) => { return React.createElement((NestedOption), { ...props, elementDescriptor: { OptionName: "zoomLevel", DefaultsProps: { defaultValue: "value" }, }, }); }; const ZoomLevel = Object.assign(_componentZoomLevel, { componentType: "option", }); export default Diagram; export { Diagram, AutoLayout, Command, CommandItem, ConnectionPoint, ContextMenu, ContextToolbox, CustomShape, DefaultItemProperties, Edges, Editing, Export, GridSize, Group, HistoryToolbar, Item, MainToolbar, Nodes, PageSize, PageSizeItem, PropertiesPanel, Tab, TabGroup, Toolbox, ToolboxGroup, ViewToolbar, ZoomLevel };