Sidebar-PlantComponent.js 5.45 KB

(function () {
	// Adds Atlassian shapes
	// plant label
	Sidebar.prototype.addThingsKitPlantPalette = function () {

		const gn = 'mxgraph.plant';
		const dt = 'plant';
		const label = mxResources.get('plant')
		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('plant') + '1  ', path: 'plant/植物 1.svg' },
			{ name: mxResources.get('plant') + '10', path: 'plant/植物 10.svg' },
			{ name: mxResources.get('plant') + '11', path: 'plant/植物 11.svg' },
			{ name: mxResources.get('plant') + '12', path: 'plant/植物 12.svg' },
			{ name: mxResources.get('plant') + '13', path: 'plant/植物 13.svg' },
			{ name: mxResources.get('plant') + '14', path: 'plant/植物 14.svg' },
			{ name: mxResources.get('plant') + '15', path: 'plant/植物 15.svg' },
			{ name: mxResources.get('plant') + '16', path: 'plant/植物 16.svg' },
			{ name: mxResources.get('plant') + '17', path: 'plant/植物 17.svg' },
			{ name: mxResources.get('plant') + '18', path: 'plant/植物 18.svg' },
			{ name: mxResources.get('plant') + '19', path: 'plant/植物 19.svg' },
			{ name: mxResources.get('plant') + '2', path: 'plant/植物 2.svg' },
			{ name: mxResources.get('plant') + '20', path: 'plant/植物 20.svg' },
			{ name: mxResources.get('plant') + '21', path: 'plant/植物 21.svg' },
			{ name: mxResources.get('plant') + '22', path: 'plant/植物 22.svg' },
			{ name: mxResources.get('plant') + '23', path: 'plant/植物 23.svg' },
			{ name: mxResources.get('plant') + '24', path: 'plant/植物 24.svg' },
			{ name: mxResources.get('plant') + '25', path: 'plant/植物 25.svg' },
			{ name: mxResources.get('plant') + '26', path: 'plant/植物 26.svg' },
			{ name: mxResources.get('plant') + '27', path: 'plant/植物 27.svg' },
			{ name: mxResources.get('plant') + '28', path: 'plant/植物 28.svg' },
			{ name: mxResources.get('plant') + '29', path: 'plant/植物 29.svg' },
			{ name: mxResources.get('plant') + '3', path: 'plant/植物 3.svg' },
			{ name: mxResources.get('plant') + '30', path: 'plant/植物 30.svg' },
			{ name: mxResources.get('plant') + '31', path: 'plant/植物 31.svg' },
			{ name: mxResources.get('plant') + '32', path: 'plant/植物 32.svg' },
			{ name: mxResources.get('plant') + '33', path: 'plant/植物 33.svg' },
			{ name: mxResources.get('plant') + '34', path: 'plant/植物 34.svg' },
			{ name: mxResources.get('plant') + '35', path: 'plant/植物 35.svg' },
			{ name: mxResources.get('plant') + '36', path: 'plant/植物 36.svg' },
			{ name: mxResources.get('plant') + '37', path: 'plant/植物 37.svg' },
			{ name: mxResources.get('plant') + '38', path: 'plant/植物 38.svg' },
			{ name: mxResources.get('plant') + '39', path: 'plant/植物 39.svg' },
			{ name: mxResources.get('plant') + '4', path: 'plant/植物 4.svg' },
			{ name: mxResources.get('plant') + '40', path: 'plant/植物 40.svg' },
			{ name: mxResources.get('plant') + '41', path: 'plant/植物 41.svg' },
			{ name: mxResources.get('plant') + '42', path: 'plant/植物 42.svg' },
			{ name: mxResources.get('plant') + '43', path: 'plant/植物 43.svg' },
			{ name: mxResources.get('plant') + '44', path: 'plant/植物 44.svg' },
			{ name: mxResources.get('plant') + '45', path: 'plant/植物 45.svg' },
			{ name: mxResources.get('plant') + '46', path: 'plant/植物 46.svg' },
			{ name: mxResources.get('plant') + '47', path: 'plant/植物 47.svg' },
			{ name: mxResources.get('plant') + '48', path: 'plant/植物 48.svg' },
			{ name: mxResources.get('plant') + '49', path: 'plant/植物 49.svg' },
			{ name: mxResources.get('plant') + '5', path: 'plant/植物 5.svg' },
			{ name: mxResources.get('plant') + '50', path: 'plant/植物 50.svg' },
			{ name: mxResources.get('plant') + '51', path: 'plant/植物 51.svg' },
			{ name: mxResources.get('plant') + '52', path: 'plant/植物 52.svg' },
			{ name: mxResources.get('plant') + '53', path: 'plant/植物 53.svg' },
			{ name: mxResources.get('plant') + '54', path: 'plant/植物 54.svg' },
			{ name: mxResources.get('plant') + '6', path: 'plant/植物 6.svg' },
			{ name: mxResources.get('plant') + '7', path: 'plant/植物 7.svg' },
			{ name: mxResources.get('plant') + '8', path: 'plant/植物 8.svg' },
			{ name: mxResources.get('plant') + '9', path: 'plant/植物 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();
	};
})();