import React = require("react"); import { Workspace } from "@tandem/editor/browser"; import { DOMElements } from "@tandem/html-extension/collections"; import { HashInputComponent } from "@tandem/html-extension/editor/browser/components/common"; import { BaseApplicationComponent } from "@tandem/common"; import { SyntheticHTMLElement, SyntheticDOMAttribute, SyntheticDOMElementEdit } from "@tandem/synthetic-browser"; export class ElementAttributesPaneComponent extends BaseApplicationComponent<{ workspace: Workspace }, any> { addAttribute = () => { this.items.setAttribute("", ""); } setAttribute = (name: string, value: any, oldName?: string) => { if(name != null) this.items.setAttribute(name, value); if (oldName != null) { this.items.removeAttribute(oldName); } for (const item of this.items) { const edit = item.createEdit() as SyntheticDOMElementEdit; edit.setAttribute(name, value, oldName); this.props.workspace.applyFileMutations(edit.mutations); } } get items(): DOMElements { if (!this.props.workspace) return DOMElements.create() as DOMElements; const { selection } = this.props.workspace; return DOMElements.fromArray(selection); } render() { if (!this.props.workspace) return null; const items = this.items; if (!items.length) return null; return
Attributes
+
{ items.attributes.length ? : this.renderAddButton() }
; } renderAddButton() { return
; } }