Sidebar-Control-Components.js 1.76 KB

(function () {
	// Adds Atlassian shapes
	// Control Component 控制元件
	Sidebar.prototype.addControlComponentsPalette = function () {
		const { COMPONENT_TYPE } = this.enumCellBasicAttribute
		const { DEFAULT } = this.enumComponentType
		const gn = 'mxgraph.control';
		const dt = 'control';
		const label = '控制元件'
		const width = 66;
		const height = 74;
		const staticPath = '/thingskit-drawio/img/lib/thingskit/'
		const prefix = 'image;image=img/lib/thingskit/'
		const defaultStyle = ';imageAspect=0;'
		this.setCurrentSearchEntryLibrary(dt);

		// 自定义属性
		const cellAttribute = {
			[COMPONENT_TYPE]: DEFAULT
		}

		const graphPathLib = [
			{ name: '风机1.png', path: 'fan/风机1.png' },
			{ name: '风机2.png', path: 'fan/风机2.png' },
			{ name: '风机3.png', path: 'fan/风机3.png' },
			{ name: '风机4.png', path: 'fan/风机4.png' },
			{ name: '风机5.gif', path: 'fan/风机5.gif' },
			{ name: '风机6.gif', path: 'fan/风机6.gif' },
			{ name: '风机7.gif', path: 'fan/风机7.gif' },
			{ name: '风机8.png', path: 'fan/风机8.png' },
		]

		const lib = graphPathLib.map(item => {
			item.staticPath = staticPath + item.path
			return item
		})

		const fns = graphPathLib.map(item => {
			return this.addEntry(this.getTagsForStencil(gn, item.name, dt).join(' '), mxUtils.bind(this, function () {
				const cell = new mxCell('', new mxGeometry(0, 0, width, height), `${prefix}${item.path}${defaultStyle}`);
				cell.setVertex(true)
				this.setCellAttributes(cell, cellAttribute)
				return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, item.name);
			}));
		})

		this.setVariableImageLib(dt, label, lib)

		this.addPaletteFunctions(dt, label, false, fns);

		this.setCurrentSearchEntryLibrary();
	};
})();