Sidebar-InstrumentComponent.js 2.52 KB

(function () {
	// Adds Atlassian shapes
	// instrument 仪表
	Sidebar.prototype.addThingsKitInstrumentPalette = function () {

		const gn = 'mxgraph.instrument';
		const dt = 'instrument';
		const label = mxResources.get('instrument')
		const width = 66;
		const height = 74;
		const prefix = `image;image=${window?.PROJECT_ENV.base}/webapp/images/thingskit/libs/`
		const defaultStyle = ';imageAspect=0;'
		this.setCurrentSearchEntryLibrary(dt);

		const { COMPONENT_KEY, CATEGORY } = window.CellAttributeKeyEnum

		function createUserObject(attribute) {
			attribute = Object.assign({ [COMPONENT_KEY]: '', [CATEGORY]: '' }, attribute || {})
			var xmlElement = mxUtils.createXmlDocument().createElement('UserObject');

			Object.keys(attribute).forEach(key => {
				xmlElement.setAttribute(key, attribute[key]);
			})
			return xmlElement
		}

		// 自定义属性
		const cellAttribute = {
			[COMPONENT_KEY]: 'Image',
			[CATEGORY]: 'DEFAULT'
		}

		const graphPathLib = [
			{ name: mxResources.get('instrument') + '1', path: 'instrument/仪表 1.svg' },
			{ name: mxResources.get('instrument') + '10', path: 'instrument/仪表 10.svg' },
			{ name: mxResources.get('instrument') + '11', path: 'instrument/仪表 11.svg' },
			{ name: mxResources.get('instrument') + '12', path: 'instrument/仪表 12.svg' },
			{ name: mxResources.get('instrument') + '2', path: 'instrument/仪表 2.svg' },
			{ name: mxResources.get('instrument') + '3', path: 'instrument/仪表 3.svg' },
			{ name: mxResources.get('instrument') + '4', path: 'instrument/仪表 4.svg' },
			{ name: mxResources.get('instrument') + '5', path: 'instrument/仪表 5.svg' },
			{ name: mxResources.get('instrument') + '6', path: 'instrument/仪表 6.svg' },
			{ name: mxResources.get('instrument') + '7', path: 'instrument/仪表 7.svg' },
			{ name: mxResources.get('instrument') + '8', path: 'instrument/仪表 8.svg' },
			{ name: mxResources.get('instrument') + '9', path: 'instrument/仪表 9.svg' },
		]



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

				return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, item.name);
			}));
		})


		this.setGalleryLib(dt, label, graphPathLib)

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

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