Sidebar-AirComponent.js 1.96 KB

(function () {
	// Adds Atlassian shapes
	// Air label
	Sidebar.prototype.addThingsKitAirPalette = function () {

		const gn = 'mxgraph.air';
		const dt = 'air';
		const label = mxResources.get('air')
		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('top'), path: 'Air/上.gif' },
			{ name: mxResources.get('top'), path: 'Air/上.png' },
			{ name: mxResources.get('bottom'), path: 'Air/下.gif' },
			{ name: mxResources.get('bottom'), path: 'Air/下.png' },
			{ name: mxResources.get('right'), path: 'Air/右.gif' },
			{ name: mxResources.get('right'), path: 'Air/右.png' },
			{ name: mxResources.get('left'), path: 'Air/左.gif' },
			{ name: mxResources.get('left'), path: 'Air/左.png' },
		]

		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();
	};
})();