diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index 504615c..e575502 100755 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -451,9 +451,9 @@ class FastSelectionModel { /** * @typedef {import("../Blueprint").default} Blueprint - * @typedef {import("../entity/IEntity").IEntity} IEntity - * @typedef {import("../input/Context").default} Context - * @typedef {import("../template/Template").default} Template + * @typedef {import("../entity/IEntity").default} IEntity + * @typedef {import("../input/IContext").default} IContext + * @typedef {import("../template/ITemplate").default} ITemplate */ class IElement extends HTMLElement { @@ -461,7 +461,7 @@ class IElement extends HTMLElement { /** * * @param {IEntity} entity The entity containing blueprint related data for this graph element - * @param {Template} template The template to render this node + * @param {ITemplate} template The template to render this node */ constructor(entity, template) { super(); @@ -469,9 +469,9 @@ class IElement extends HTMLElement { this.blueprint = null; /** @type {IEntity} */ this.entity = entity; - /** @type {Template} */ + /** @type {ITemplate} */ this.template = template; - /** @type {Context[]} */ + /** @type {IContext[]} */ this.inputObjects = []; } @@ -497,7 +497,7 @@ class IElement extends HTMLElement { /** * @typedef {import("../element/IElement").default} IElement */ -class Template { +class ITemplate { /** * Computes the html content of the target element. @@ -521,7 +521,7 @@ class Template { /** * @typedef {import("../element/SelectorElement").default} SelectorElement */ -class SelectorTemplate extends Template { +class SelectorTemplate extends ITemplate { /** * Applies the style to the element. @@ -603,7 +603,7 @@ class SelectorElement extends IElement { customElements.define(SelectorElement.tagName, SelectorElement); /** @typedef {import("../Blueprint").default} Blueprint */ -class BlueprintTemplate extends Template { +class BlueprintTemplate extends ITemplate { header(element) { return html`
@@ -724,7 +724,7 @@ class BlueprintTemplate extends Template { } } -class Context { +class IContext { constructor(target, blueprint, options) { /** @type {HTMLElement} */ @@ -1362,7 +1362,7 @@ class SerializerFactory { } } -class Serializer { +class ISerializer { static grammar = Parsimmon.createLanguage(new Grammar()) @@ -1435,7 +1435,7 @@ class Serializer { } } -class ObjectSerializer extends Serializer { +class ObjectSerializer extends ISerializer { constructor() { super(ObjectEntity, " ", "\n", false); @@ -1453,7 +1453,7 @@ class ObjectSerializer extends Serializer { } read(value) { - const parseResult = Serializer.grammar.Object.parse(value); + const parseResult = ISerializer.grammar.Object.parse(value); if (!parseResult.status) { console.error("Error when trying to parse the object."); return parseResult @@ -1467,7 +1467,7 @@ class ObjectSerializer extends Serializer { * @returns {ObjectEntity[]} */ readMultiple(value) { - const parseResult = Serializer.grammar.MultipleObject.parse(value); + const parseResult = ISerializer.grammar.MultipleObject.parse(value); if (!parseResult.status) { console.error("Error when trying to parse the object."); return parseResult @@ -1491,7 +1491,7 @@ End Object`; } } -class Copy extends Context { +class Copy extends IContext { #copyHandler @@ -1521,7 +1521,7 @@ class Copy extends Context { * @typedef {import("../element/LinkElement").default} LinkElement * @typedef {import("../element/LinkMessageElement").default} LinkMessageElement */ -class LinkTemplate extends Template { +class LinkTemplate extends ITemplate { static pixelToUnit(pixels, pixelFullSize) { return pixels * 100 / pixelFullSize @@ -1796,7 +1796,7 @@ customElements.define(LinkElement.tagName, LinkElement); /** * @typedef {import("../element/PinElement").default} PinElement */ -class PinTemplate extends Template { +class PinTemplate extends ITemplate { /** * Computes the html content of the pin. @@ -1844,7 +1844,7 @@ class PinTemplate extends Template { /** * @typedef {import("../element/LinkMessageElement").default} LinkMessageElement */ -class LinkMessageTemplate extends Template { +class LinkMessageTemplate extends ITemplate { /** * Computes the html content of the target element. @@ -1929,7 +1929,7 @@ class LinkMessageElement extends IElement { customElements.define(LinkMessageElement.tagName, LinkMessageElement); -class Pointing extends Context { +class IPointing extends IContext { constructor(target, blueprint, options) { super(target, blueprint, options); @@ -1952,7 +1952,7 @@ class Pointing extends Context { /** * This class manages the ui gesture of mouse click and drag. Tha actual operations are implemented by the subclasses. */ -class MouseClickDrag extends Pointing { +class IMouseClickDrag extends IPointing { /** @type {(e: MouseEvent) => void} */ #mouseDownHandler @@ -2087,7 +2087,7 @@ class MouseClickDrag extends Pointing { } /** @typedef {import("../../element/PinElement").default} PinElement */ -class MouseCreateLink extends MouseClickDrag { +class MouseCreateLink extends IMouseClickDrag { /** @type {NodeListOf} */ #listenedPins @@ -2229,7 +2229,7 @@ customElements.define(PinElement.tagName, PinElement); /** * @typedef {import("../element/ISelectableDraggableElement").default} ISelectableDraggableElement */ -class SelectableDraggableTemplate extends Template { +class SelectableDraggableTemplate extends ITemplate { /** * Returns the html elements rendered from this template. @@ -2304,9 +2304,9 @@ class NodeTemplate extends SelectableDraggableTemplate { } /** - * @typedef {import("../../element/ISelectableDraggableElement").ISelectableDraggableElement} ISelectableDraggableElement + * @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement */ -class MouseMoveNodes extends MouseClickDrag { +class MouseMoveNodes extends IMouseClickDrag { /** * @@ -2515,7 +2515,7 @@ class KeyGrammar { .trim(P.optWhitespace) } -class KeyboardShortcut extends Context { +class IKeyboardShortcut extends IContext { static keyGrammar = P.createLanguage(new KeyGrammar()) @@ -2555,7 +2555,7 @@ class KeyboardShortcut extends Context { static keyOptionsParse(options, keyString) { options = { ...options, - ...KeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value + ...IKeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value }; return options } @@ -2572,7 +2572,7 @@ class KeyboardShortcut extends Context { } } -class KeyvoardCanc extends KeyboardShortcut { +class KeyvoardCanc extends IKeyboardShortcut { /** * @@ -2581,7 +2581,7 @@ class KeyvoardCanc extends KeyboardShortcut { * @param {OBject} options */ constructor(target, blueprint, options = {}) { - options = KeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey); + options = IKeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey); super(target, blueprint, options); } @@ -2590,7 +2590,7 @@ class KeyvoardCanc extends KeyboardShortcut { } } -class KeyboardSelectAll extends KeyboardShortcut { +class KeyboardSelectAll extends IKeyboardShortcut { /** * @@ -2599,7 +2599,7 @@ class KeyboardSelectAll extends KeyboardShortcut { * @param {Object} options */ constructor(target, blueprint, options = {}) { - options = KeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey); + options = IKeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey); super(target, blueprint, options); } @@ -2608,7 +2608,7 @@ class KeyboardSelectAll extends KeyboardShortcut { } } -class MouseScrollGraph extends MouseClickDrag { +class MouseScrollGraph extends IMouseClickDrag { startDrag() { this.blueprint.template.applyStartDragScrolling(this.blueprint); @@ -2623,9 +2623,9 @@ class MouseScrollGraph extends MouseClickDrag { } } -class MouseTracking extends Pointing { +class MouseTracking extends IPointing { - /** @type {Pointing} */ + /** @type {IPointing} */ #mouseTracker = null /** @type {(e: MouseEvent) => void} */ @@ -2685,7 +2685,7 @@ class MouseTracking extends Pointing { } } -class Paste extends Context { +class Paste extends IContext { #pasteHandle @@ -2736,7 +2736,7 @@ class Paste extends Context { } } -class Select extends MouseClickDrag { +class Select extends IMouseClickDrag { constructor(target, blueprint, options) { super(target, blueprint, options); @@ -2760,7 +2760,7 @@ class Select extends MouseClickDrag { } } -class Unfocus extends Context { +class Unfocus extends IContext { /** @type {(e: WheelEvent) => void} */ #clickHandler @@ -2796,7 +2796,7 @@ class Unfocus extends Context { } } -class MouseWheel extends Pointing { +class IMouseWheel extends IPointing { /** @type {(e: WheelEvent) => void} */ #mouseWheelHandler @@ -2843,7 +2843,7 @@ class MouseWheel extends Pointing { } } -class Zoom extends MouseWheel { +class Zoom extends IMouseWheel { wheel(variation, location) { let zoomLevel = this.blueprint.getZoom(); @@ -3216,7 +3216,7 @@ class Blueprint extends IElement { customElements.define(Blueprint.tagName, Blueprint); -class GeneralSerializer extends Serializer { +class GeneralSerializer extends ISerializer { constructor(wrap, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) { wrap = wrap ?? (v => `(${v})`); @@ -3225,7 +3225,7 @@ class GeneralSerializer extends Serializer { } read(value) { - let grammar = Grammar.getGrammarForType(Serializer.grammar, this.entityType); + let grammar = Grammar.getGrammarForType(ISerializer.grammar, this.entityType); const parseResult = grammar.parse(value); if (!parseResult.status) { console.error("Error when trying to parse the entity " + this.entityType.prototype.constructor.name); diff --git a/js/element/IElement.js b/js/element/IElement.js index 820ec13..18d67fa 100644 --- a/js/element/IElement.js +++ b/js/element/IElement.js @@ -1,8 +1,8 @@ /** * @typedef {import("../Blueprint").default} Blueprint - * @typedef {import("../entity/IEntity").IEntity} IEntity - * @typedef {import("../input/Context").default} Context - * @typedef {import("../template/Template").default} Template + * @typedef {import("../entity/IEntity").default} IEntity + * @typedef {import("../input/IContext").default} IContext + * @typedef {import("../template/ITemplate").default} ITemplate */ export default class IElement extends HTMLElement { @@ -10,7 +10,7 @@ export default class IElement extends HTMLElement { /** * * @param {IEntity} entity The entity containing blueprint related data for this graph element - * @param {Template} template The template to render this node + * @param {ITemplate} template The template to render this node */ constructor(entity, template) { super() @@ -18,9 +18,9 @@ export default class IElement extends HTMLElement { this.blueprint = null /** @type {IEntity} */ this.entity = entity - /** @type {Template} */ + /** @type {ITemplate} */ this.template = template - /** @type {Context[]} */ + /** @type {IContext[]} */ this.inputObjects = [] } diff --git a/js/entity/KeyBinding.js b/js/entity/KeyBindingEntity.js old mode 100755 new mode 100644 similarity index 68% rename from js/entity/KeyBinding.js rename to js/entity/KeyBindingEntity.js index 395591e..a7855ad --- a/js/entity/KeyBinding.js +++ b/js/entity/KeyBindingEntity.js @@ -1,16 +1,16 @@ -import IEntity from "./IEntity" - -export default class KeyBinding extends IEntity { - - static attributes = { - bCtrlDown: false, - bAltDown: false, - bShiftDown: false, - Key: String, - CommandName: String, - } - - getAttributes() { - return KeyBinding.attributes - } -} +import IEntity from "./IEntity" + +export default class KeyBindingEntity extends IEntity { + + static attributes = { + bCtrlDown: false, + bAltDown: false, + bShiftDown: false, + Key: String, + CommandName: String, + } + + getAttributes() { + return KeyBindingEntity.attributes + } +} diff --git a/js/input/Context.js b/js/input/IContext.js old mode 100755 new mode 100644 similarity index 94% rename from js/input/Context.js rename to js/input/IContext.js index 0960c27..7ba61a8 --- a/js/input/Context.js +++ b/js/input/IContext.js @@ -1,30 +1,30 @@ -export default class Context { - - constructor(target, blueprint, options) { - /** @type {HTMLElement} */ - this.target = target - /** @type {import("../Blueprint").default}" */ - this.blueprint = blueprint - this.options = options - let self = this - this.blueprintFocusHandler = _ => self.listenEvents() - this.blueprintUnfocusHandler = _ => self.unlistenEvents() - if (options?.wantsFocusCallback ?? false) { - this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler) - this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler) - } - } - - unlistenDOMElement() { - this.unlistenEvents() - this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler) - this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler) - } - - /* Subclasses will probabily override the following methods */ - listenEvents() { - } - - unlistenEvents() { - } -} +export default class IContext { + + constructor(target, blueprint, options) { + /** @type {HTMLElement} */ + this.target = target + /** @type {import("../Blueprint").default}" */ + this.blueprint = blueprint + this.options = options + let self = this + this.blueprintFocusHandler = _ => self.listenEvents() + this.blueprintUnfocusHandler = _ => self.unlistenEvents() + if (options?.wantsFocusCallback ?? false) { + this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler) + this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler) + } + } + + unlistenDOMElement() { + this.unlistenEvents() + this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler) + this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler) + } + + /* Subclasses will probabily override the following methods */ + listenEvents() { + } + + unlistenEvents() { + } +} diff --git a/js/input/common/Copy.js b/js/input/common/Copy.js index 162ddfa..c4910d5 100755 --- a/js/input/common/Copy.js +++ b/js/input/common/Copy.js @@ -1,7 +1,7 @@ -import Context from "../Context" +import IContext from "../IContext" import ObjectSerializer from "../../serialization/ObjectSerializer" -export default class Copy extends Context { +export default class Copy extends IContext { #copyHandler diff --git a/js/input/common/Paste.js b/js/input/common/Paste.js index 08b798c..fb68ecc 100755 --- a/js/input/common/Paste.js +++ b/js/input/common/Paste.js @@ -1,8 +1,8 @@ import NodeElement from "../../element/NodeElement" import ObjectSerializer from "../../serialization/ObjectSerializer" -import Context from "../Context" +import IContext from "../IContext" -export default class Paste extends Context { +export default class Paste extends IContext { #pasteHandle diff --git a/js/input/keybaord/KeyboardShortcut.js b/js/input/keybaord/IKeyboardShortcut.js old mode 100755 new mode 100644 similarity index 91% rename from js/input/keybaord/KeyboardShortcut.js rename to js/input/keybaord/IKeyboardShortcut.js index 1ea1e43..44cffc6 --- a/js/input/keybaord/KeyboardShortcut.js +++ b/js/input/keybaord/IKeyboardShortcut.js @@ -1,87 +1,87 @@ -import Configuration from "../../Configuration" -import Context from "../Context" -import Parsimmon from "parsimmon" - -let P = Parsimmon - -class KeyGrammar { - - // Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use - ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i))) - Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v]) - KeyboardShortcut = r => P.alt( - P.seqMap( - P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v) - .atLeast(1) - .map(v => v.reduce((acc, cur) => acc | cur)), - P.optWhitespace, - r.Key, - (modifierKeysFlag, _, key) => ({ - key: key, - ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))), - shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))), - altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))), - metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta"))) - }) - ), - r.Key.map(v => ({ key: v })) - ) - .trim(P.optWhitespace) -} - -export default class KeyboardShortcut extends Context { - - static keyGrammar = P.createLanguage(new KeyGrammar()) - - constructor(target, blueprint, options = {}) { - options.wantsFocusCallback = true - super(target, blueprint, options) - - /** @type {String[]} */ - this.key = this.options.key - this.ctrlKey = options.ctrlKey ?? false - this.shiftKey = options.shiftKey ?? false - this.altKey = options.altKey ?? false - this.metaKey = options.metaKey ?? false - - let self = this - this.keyDownHandler = e => { - if ( - e.code == self.key - && e.ctrlKey === self.ctrlKey - && e.shiftKey === self.shiftKey - && e.altKey === self.altKey - && e.metaKey === self.metaKey - ) { - self.fire() - e.preventDefault() - return true - } - return false - } - } - - /** - * - * @param {String} keyString - * @returns {Object} - */ - static keyOptionsParse(options, keyString) { - options = { - ...options, - ...KeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value - } - return options - } - - listenEvents() { - document.addEventListener("keydown", this.keyDownHandler) - } - - unlistenEvents() { - document.removeEventListener("keydown", this.keyDownHandler) - } - - fire() { - } -} +import Configuration from "../../Configuration" +import IContext from "../IContext" +import Parsimmon from "parsimmon" + +let P = Parsimmon + +class KeyGrammar { + + // Creates a grammar where each alternative is the string from ModifierKey mapped to a number for bit or use + ModifierKey = r => P.alt(...Configuration.ModifierKeys.map((v, i) => P.string(v).map(_ => 1 << i))) + Key = r => P.alt(...Object.keys(Configuration.Keys).map(v => P.string(v))).map(v => Configuration.Keys[v]) + KeyboardShortcut = r => P.alt( + P.seqMap( + P.seqMap(r.ModifierKey, P.optWhitespace, P.string(Configuration.keysSeparator), (v, _, __) => v) + .atLeast(1) + .map(v => v.reduce((acc, cur) => acc | cur)), + P.optWhitespace, + r.Key, + (modifierKeysFlag, _, key) => ({ + key: key, + ctrlKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Ctrl"))), + shiftKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Shift"))), + altKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Alt"))), + metaKey: Boolean(modifierKeysFlag & (1 << Configuration.ModifierKeys.indexOf("Meta"))) + }) + ), + r.Key.map(v => ({ key: v })) + ) + .trim(P.optWhitespace) +} + +export default class IKeyboardShortcut extends IContext { + + static keyGrammar = P.createLanguage(new KeyGrammar()) + + constructor(target, blueprint, options = {}) { + options.wantsFocusCallback = true + super(target, blueprint, options) + + /** @type {String[]} */ + this.key = this.options.key + this.ctrlKey = options.ctrlKey ?? false + this.shiftKey = options.shiftKey ?? false + this.altKey = options.altKey ?? false + this.metaKey = options.metaKey ?? false + + let self = this + this.keyDownHandler = e => { + if ( + e.code == self.key + && e.ctrlKey === self.ctrlKey + && e.shiftKey === self.shiftKey + && e.altKey === self.altKey + && e.metaKey === self.metaKey + ) { + self.fire() + e.preventDefault() + return true + } + return false + } + } + + /** + * + * @param {String} keyString + * @returns {Object} + */ + static keyOptionsParse(options, keyString) { + options = { + ...options, + ...IKeyboardShortcut.keyGrammar.KeyboardShortcut.parse(keyString).value + } + return options + } + + listenEvents() { + document.addEventListener("keydown", this.keyDownHandler) + } + + unlistenEvents() { + document.removeEventListener("keydown", this.keyDownHandler) + } + + fire() { + } +} diff --git a/js/input/keybaord/KeyboardCanc.js b/js/input/keybaord/KeyboardCanc.js index a329062..f926061 100755 --- a/js/input/keybaord/KeyboardCanc.js +++ b/js/input/keybaord/KeyboardCanc.js @@ -1,7 +1,7 @@ -import KeyboardShortcut from "./KeyboardShortcut" +import IKeyboardShortcut from "./IKeyboardShortcut" import Configuration from "../../Configuration" -export default class KeyvoardCanc extends KeyboardShortcut { +export default class KeyvoardCanc extends IKeyboardShortcut { /** * @@ -10,7 +10,7 @@ export default class KeyvoardCanc extends KeyboardShortcut { * @param {OBject} options */ constructor(target, blueprint, options = {}) { - options = KeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey) + options = IKeyboardShortcut.keyOptionsParse(options, Configuration.deleteNodesKeyboardKey) super(target, blueprint, options) } diff --git a/js/input/keybaord/KeyboardSelectAll.js b/js/input/keybaord/KeyboardSelectAll.js index 15bee2d..0a793ec 100755 --- a/js/input/keybaord/KeyboardSelectAll.js +++ b/js/input/keybaord/KeyboardSelectAll.js @@ -1,7 +1,7 @@ -import KeyboardShortcut from "./KeyboardShortcut" +import IKeyboardShortcut from "./IKeyboardShortcut" import Configuration from "../../Configuration" -export default class KeyboardSelectAll extends KeyboardShortcut { +export default class KeyboardSelectAll extends IKeyboardShortcut { /** * @@ -10,7 +10,7 @@ export default class KeyboardSelectAll extends KeyboardShortcut { * @param {Object} options */ constructor(target, blueprint, options = {}) { - options = KeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey) + options = IKeyboardShortcut.keyOptionsParse(options, Configuration.selectAllKeyboardKey) super(target, blueprint, options) } diff --git a/js/input/mouse/MouseClickDrag.js b/js/input/mouse/IMouseClickDrag.js old mode 100755 new mode 100644 similarity index 95% rename from js/input/mouse/MouseClickDrag.js rename to js/input/mouse/IMouseClickDrag.js index c4ba113..4f70409 --- a/js/input/mouse/MouseClickDrag.js +++ b/js/input/mouse/IMouseClickDrag.js @@ -1,139 +1,139 @@ -import Configuration from "../../Configuration" -import Pointing from "./Pointing" - -/** - * This class manages the ui gesture of mouse click and drag. Tha actual operations are implemented by the subclasses. - */ -export default class MouseClickDrag extends Pointing { - - /** @type {(e: MouseEvent) => void} */ - #mouseDownHandler - - /** @type {(e: MouseEvent) => void} */ - #mouseStartedMovingHandler - - /** @type {(e: MouseEvent) => void} */ - #mouseMoveHandler - - /** @type {(e: MouseEvent) => void} */ - #mouseUpHandler - - /** @type {Boolean} */ - #trackingMouse = false - - constructor(target, blueprint, options) { - super(target, blueprint, options) - this.clickButton = options?.clickButton ?? 0 - this.exitAnyButton = options?.exitAnyButton ?? true - this.moveEverywhere = options?.moveEverywhere ?? false - this.looseTarget = options?.looseTarget ?? false - this.consumeClickEvent = options?.consumeClickEvent ?? true - this.started = false - this.clickedPosition = [0, 0] - - const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace - let self = this - - this.#mouseDownHandler = e => { - this.blueprint.setFocused(true) - switch (e.button) { - case self.clickButton: - // Either doesn't matter or consider the click only when clicking on the parent, not descandants - if (self.looseTarget || e.target == e.currentTarget) { - e.preventDefault() - if (this.consumeClickEvent) { - e.stopImmediatePropagation() // Captured, don't call anyone else - } - self.started = false - // Attach the listeners - movementListenedElement.addEventListener("mousemove", self.#mouseStartedMovingHandler) - document.addEventListener("mouseup", self.#mouseUpHandler) - self.clickedPosition = self.locationFromEvent(e) - self.clicked(self.clickedPosition) - } - break - default: - if (!self.exitAnyButton) { - self.#mouseUpHandler(e) - } - break - } - } - - this.#mouseStartedMovingHandler = e => { - e.preventDefault() - // Delegate from now on to self.#mouseMoveHandler - movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler) - movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler) - - // Do actual actions - self.startDrag() - self.started = true - const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin) - // Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false - self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false - } - - this.#mouseMoveHandler = e => { - e.preventDefault() - const location = self.locationFromEvent(e) - const movement = [e.movementX, e.movementY] - self.dragTo(location, movement) - if (self.#trackingMouse) { - self.blueprint.entity.mousePosition = self.locationFromEvent(e) - } - } - - this.#mouseUpHandler = e => { - if (!self.exitAnyButton || e.button == self.clickButton) { - e.preventDefault() - // Remove the handlers of "mousemove" and "mouseup" - movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler) - movementListenedElement.removeEventListener("mousemove", self.#mouseMoveHandler) - document.removeEventListener("mouseup", self.#mouseUpHandler) - self.endDrag() - if (self.#trackingMouse) { - const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end) - this.target.dispatchEvent(dragEvent) - self.#trackingMouse = false - } - } - } - - this.target.addEventListener("mousedown", this.#mouseDownHandler) - if (this.clickButton == 2) { - this.target.addEventListener("contextmenu", e => e.preventDefault()) - } - } - - getEvent(eventName) { - return new CustomEvent(eventName, { - detail: { - tracker: this - }, - bubbles: true, - cancelable: true - }) - } - - unlistenDOMElement() { - super.unlistenDOMElement() - this.target.removeEventListener("mousedown", this.#mouseDownHandler) - if (this.clickButton == 2) { - this.target.removeEventListener("contextmenu", e => e.preventDefault()) - } - } - - /* Subclasses will override the following methods */ - clicked(location) { - } - - startDrag() { - } - - dragTo(location, movement) { - } - - endDrag() { - } -} +import Configuration from "../../Configuration" +import IPointing from "./IPointing" + +/** + * This class manages the ui gesture of mouse click and drag. Tha actual operations are implemented by the subclasses. + */ +export default class IMouseClickDrag extends IPointing { + + /** @type {(e: MouseEvent) => void} */ + #mouseDownHandler + + /** @type {(e: MouseEvent) => void} */ + #mouseStartedMovingHandler + + /** @type {(e: MouseEvent) => void} */ + #mouseMoveHandler + + /** @type {(e: MouseEvent) => void} */ + #mouseUpHandler + + /** @type {Boolean} */ + #trackingMouse = false + + constructor(target, blueprint, options) { + super(target, blueprint, options) + this.clickButton = options?.clickButton ?? 0 + this.exitAnyButton = options?.exitAnyButton ?? true + this.moveEverywhere = options?.moveEverywhere ?? false + this.looseTarget = options?.looseTarget ?? false + this.consumeClickEvent = options?.consumeClickEvent ?? true + this.started = false + this.clickedPosition = [0, 0] + + const movementListenedElement = this.moveEverywhere ? document.documentElement : this.movementSpace + let self = this + + this.#mouseDownHandler = e => { + this.blueprint.setFocused(true) + switch (e.button) { + case self.clickButton: + // Either doesn't matter or consider the click only when clicking on the parent, not descandants + if (self.looseTarget || e.target == e.currentTarget) { + e.preventDefault() + if (this.consumeClickEvent) { + e.stopImmediatePropagation() // Captured, don't call anyone else + } + self.started = false + // Attach the listeners + movementListenedElement.addEventListener("mousemove", self.#mouseStartedMovingHandler) + document.addEventListener("mouseup", self.#mouseUpHandler) + self.clickedPosition = self.locationFromEvent(e) + self.clicked(self.clickedPosition) + } + break + default: + if (!self.exitAnyButton) { + self.#mouseUpHandler(e) + } + break + } + } + + this.#mouseStartedMovingHandler = e => { + e.preventDefault() + // Delegate from now on to self.#mouseMoveHandler + movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler) + movementListenedElement.addEventListener("mousemove", self.#mouseMoveHandler) + + // Do actual actions + self.startDrag() + self.started = true + const dragEvent = self.getEvent(Configuration.trackingMouseEventName.begin) + // Handler calls e.preventDefault() when it receives the event, this means dispatchEvent returns false + self.#trackingMouse = this.target.dispatchEvent(dragEvent) == false + } + + this.#mouseMoveHandler = e => { + e.preventDefault() + const location = self.locationFromEvent(e) + const movement = [e.movementX, e.movementY] + self.dragTo(location, movement) + if (self.#trackingMouse) { + self.blueprint.entity.mousePosition = self.locationFromEvent(e) + } + } + + this.#mouseUpHandler = e => { + if (!self.exitAnyButton || e.button == self.clickButton) { + e.preventDefault() + // Remove the handlers of "mousemove" and "mouseup" + movementListenedElement.removeEventListener("mousemove", self.#mouseStartedMovingHandler) + movementListenedElement.removeEventListener("mousemove", self.#mouseMoveHandler) + document.removeEventListener("mouseup", self.#mouseUpHandler) + self.endDrag() + if (self.#trackingMouse) { + const dragEvent = self.getEvent(Configuration.trackingMouseEventName.end) + this.target.dispatchEvent(dragEvent) + self.#trackingMouse = false + } + } + } + + this.target.addEventListener("mousedown", this.#mouseDownHandler) + if (this.clickButton == 2) { + this.target.addEventListener("contextmenu", e => e.preventDefault()) + } + } + + getEvent(eventName) { + return new CustomEvent(eventName, { + detail: { + tracker: this + }, + bubbles: true, + cancelable: true + }) + } + + unlistenDOMElement() { + super.unlistenDOMElement() + this.target.removeEventListener("mousedown", this.#mouseDownHandler) + if (this.clickButton == 2) { + this.target.removeEventListener("contextmenu", e => e.preventDefault()) + } + } + + /* Subclasses will override the following methods */ + clicked(location) { + } + + startDrag() { + } + + dragTo(location, movement) { + } + + endDrag() { + } +} diff --git a/js/input/mouse/MouseWheel.js b/js/input/mouse/IMouseWheel.js old mode 100755 new mode 100644 similarity index 91% rename from js/input/mouse/MouseWheel.js rename to js/input/mouse/IMouseWheel.js index 2f8a4c8..f2b3cc1 --- a/js/input/mouse/MouseWheel.js +++ b/js/input/mouse/IMouseWheel.js @@ -1,48 +1,48 @@ -import Pointing from "./Pointing" - -export default class MouseWheel extends Pointing { - - /** @type {(e: WheelEvent) => void} */ - #mouseWheelHandler - - /** @type {(e: WheelEvent) => void} */ - #mouseParentWheelHandler - - /** - * - * @param {HTMLElement} target - * @param {import("../../Blueprint").default} blueprint - * @param {Object} options - */ - constructor(target, blueprint, options) { - options.wantsFocusCallback = true - super(target, blueprint, options) - this.looseTarget = options?.looseTarget ?? true - let self = this - - this.#mouseWheelHandler = e => { - e.preventDefault() - const location = self.locationFromEvent(e) - self.wheel(Math.sign(e.deltaY), location) - } - this.#mouseParentWheelHandler = e => e.preventDefault() - - if (this.blueprint.focused) { - this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false) - } - } - - listenEvents() { - this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false) - this.movementSpace.parentElement?.addEventListener("wheel", this.#mouseParentWheelHandler) - } - - unlistenEvents() { - this.movementSpace.removeEventListener("wheel", this.#mouseWheelHandler, false) - this.movementSpace.parentElement?.removeEventListener("wheel", this.#mouseParentWheelHandler) - } - - /* Subclasses will override the following method */ - wheel(variation, location) { - } -} +import IPointing from "./IPointing" + +export default class IMouseWheel extends IPointing { + + /** @type {(e: WheelEvent) => void} */ + #mouseWheelHandler + + /** @type {(e: WheelEvent) => void} */ + #mouseParentWheelHandler + + /** + * + * @param {HTMLElement} target + * @param {import("../../Blueprint").default} blueprint + * @param {Object} options + */ + constructor(target, blueprint, options) { + options.wantsFocusCallback = true + super(target, blueprint, options) + this.looseTarget = options?.looseTarget ?? true + let self = this + + this.#mouseWheelHandler = e => { + e.preventDefault() + const location = self.locationFromEvent(e) + self.wheel(Math.sign(e.deltaY), location) + } + this.#mouseParentWheelHandler = e => e.preventDefault() + + if (this.blueprint.focused) { + this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false) + } + } + + listenEvents() { + this.movementSpace.addEventListener("wheel", this.#mouseWheelHandler, false) + this.movementSpace.parentElement?.addEventListener("wheel", this.#mouseParentWheelHandler) + } + + unlistenEvents() { + this.movementSpace.removeEventListener("wheel", this.#mouseWheelHandler, false) + this.movementSpace.parentElement?.removeEventListener("wheel", this.#mouseParentWheelHandler) + } + + /* Subclasses will override the following method */ + wheel(variation, location) { + } +} diff --git a/js/input/mouse/Pointing.js b/js/input/mouse/IPointing.js old mode 100755 new mode 100644 similarity index 83% rename from js/input/mouse/Pointing.js rename to js/input/mouse/IPointing.js index 616c1c4..5ec1151 --- a/js/input/mouse/Pointing.js +++ b/js/input/mouse/IPointing.js @@ -1,22 +1,22 @@ -import Context from "../Context" -import Utility from "../../Utility" - -export default class Pointing extends Context { - - constructor(target, blueprint, options) { - super(target, blueprint, options) - this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement - } - - /** - * - * @param {MouseEvent} mouseEvent - * @returns - */ - locationFromEvent(mouseEvent) { - return this.blueprint.compensateTranslation( - Utility.convertLocation( - [mouseEvent.clientX, mouseEvent.clientY], - this.movementSpace)) - } -} +import IContext from "../IContext" +import Utility from "../../Utility" + +export default class IPointing extends IContext { + + constructor(target, blueprint, options) { + super(target, blueprint, options) + this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement + } + + /** + * + * @param {MouseEvent} mouseEvent + * @returns + */ + locationFromEvent(mouseEvent) { + return this.blueprint.compensateTranslation( + Utility.convertLocation( + [mouseEvent.clientX, mouseEvent.clientY], + this.movementSpace)) + } +} diff --git a/js/input/mouse/MouseCreateLink.js b/js/input/mouse/MouseCreateLink.js index 4aee9dd..fca8401 100755 --- a/js/input/mouse/MouseCreateLink.js +++ b/js/input/mouse/MouseCreateLink.js @@ -1,9 +1,9 @@ import LinkElement from "../../element/LinkElement" import LinkMessageElement from "../../element/LinkMessageElement" -import MouseClickDrag from "./MouseClickDrag" +import IMouseClickDrag from "./IMouseClickDrag" /** @typedef {import("../../element/PinElement").default} PinElement */ -export default class MouseCreateLink extends MouseClickDrag { +export default class MouseCreateLink extends IMouseClickDrag { /** @type {NodeListOf} */ #listenedPins diff --git a/js/input/mouse/MouseMoveNodes.js b/js/input/mouse/MouseMoveNodes.js index c40e92a..3814738 100755 --- a/js/input/mouse/MouseMoveNodes.js +++ b/js/input/mouse/MouseMoveNodes.js @@ -1,10 +1,10 @@ -import MouseClickDrag from "./MouseClickDrag" +import IMouseClickDrag from "./IMouseClickDrag" import Utility from "../../Utility" /** - * @typedef {import("../../element/ISelectableDraggableElement").ISelectableDraggableElement} ISelectableDraggableElement + * @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement */ -export default class MouseMoveNodes extends MouseClickDrag { +export default class MouseMoveNodes extends IMouseClickDrag { /** * diff --git a/js/input/mouse/MouseScrollGraph.js b/js/input/mouse/MouseScrollGraph.js index 90ded72..8a7320b 100755 --- a/js/input/mouse/MouseScrollGraph.js +++ b/js/input/mouse/MouseScrollGraph.js @@ -1,6 +1,6 @@ -import MouseClickDrag from "./MouseClickDrag" +import IMouseClickDrag from "./IMouseClickDrag" -export default class MouseScrollGraph extends MouseClickDrag { +export default class MouseScrollGraph extends IMouseClickDrag { startDrag() { this.blueprint.template.applyStartDragScrolling(this.blueprint) diff --git a/js/input/mouse/MouseTracking.js b/js/input/mouse/MouseTracking.js index 268142b..35a546a 100755 --- a/js/input/mouse/MouseTracking.js +++ b/js/input/mouse/MouseTracking.js @@ -1,9 +1,9 @@ import Configuration from "../../Configuration" -import Pointing from "./Pointing" +import IPointing from "./IPointing" -export default class MouseTracking extends Pointing { +export default class MouseTracking extends IPointing { - /** @type {Pointing} */ + /** @type {IPointing} */ #mouseTracker = null /** @type {(e: MouseEvent) => void} */ diff --git a/js/input/mouse/Select.js b/js/input/mouse/Select.js index 11be013..7fc7f6c 100755 --- a/js/input/mouse/Select.js +++ b/js/input/mouse/Select.js @@ -1,6 +1,6 @@ -import MouseClickDrag from "./MouseClickDrag" +import IMouseClickDrag from "./IMouseClickDrag" -export default class Select extends MouseClickDrag { +export default class Select extends IMouseClickDrag { constructor(target, blueprint, options) { super(target, blueprint, options) diff --git a/js/input/mouse/Unfocus.js b/js/input/mouse/Unfocus.js index 468ec3d..e4a19a0 100755 --- a/js/input/mouse/Unfocus.js +++ b/js/input/mouse/Unfocus.js @@ -1,6 +1,6 @@ -import Context from "../Context" +import IContext from "../IContext" -export default class Unfocus extends Context { +export default class Unfocus extends IContext { /** @type {(e: WheelEvent) => void} */ #clickHandler diff --git a/js/input/mouse/Zoom.js b/js/input/mouse/Zoom.js index 2d62460..c30236b 100755 --- a/js/input/mouse/Zoom.js +++ b/js/input/mouse/Zoom.js @@ -1,6 +1,6 @@ -import MouseWheel from "./MouseWheel" +import IMouseWheel from "./IMouseWheel" -export default class Zoom extends MouseWheel { +export default class Zoom extends IMouseWheel { wheel(variation, location) { let zoomLevel = this.blueprint.getZoom() diff --git a/js/serialization/GeneralSerializer.js b/js/serialization/GeneralSerializer.js index 97dd85e..7cd0b0a 100755 --- a/js/serialization/GeneralSerializer.js +++ b/js/serialization/GeneralSerializer.js @@ -1,7 +1,7 @@ import Grammar from "./Grammar" -import Serializer from "./Serializer" +import ISerializer from "./ISerializer" -export default class GeneralSerializer extends Serializer { +export default class GeneralSerializer extends ISerializer { constructor(wrap, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) { wrap = wrap ?? (v => `(${v})`) @@ -10,7 +10,7 @@ export default class GeneralSerializer extends Serializer { } read(value) { - let grammar = Grammar.getGrammarForType(Serializer.grammar, this.entityType) + let grammar = Grammar.getGrammarForType(ISerializer.grammar, this.entityType) const parseResult = grammar.parse(value) if (!parseResult.status) { console.error("Error when trying to parse the entity " + this.entityType.prototype.constructor.name) diff --git a/js/serialization/Serializer.js b/js/serialization/ISerializer.js old mode 100755 new mode 100644 similarity index 96% rename from js/serialization/Serializer.js rename to js/serialization/ISerializer.js index b463357..ce9c74f --- a/js/serialization/Serializer.js +++ b/js/serialization/ISerializer.js @@ -1,79 +1,79 @@ -import IEntity from "../entity/IEntity" -import Grammar from "./Grammar" -import Parsimmon from "parsimmon" -import SerializerFactory from "./SerializerFactory" -import TypeInitialization from "../entity/TypeInitialization" -import Utility from "../Utility" - -export default class Serializer { - - static grammar = Parsimmon.createLanguage(new Grammar()) - - constructor(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) { - this.entityType = entityType - this.prefix = prefix ?? "" - this.separator = separator ?? "," - this.trailingSeparator = trailingSeparator ?? false - this.attributeValueConjunctionSign = attributeValueConjunctionSign ?? "=" - this.attributeKeyPrinter = attributeKeyPrinter ?? (k => k.join(".")) - } - - writeValue(value) { - if (value === null) { - return "()" - } - const serialize = v => SerializerFactory.getSerializer(Utility.getType(v)).write(v) - // This is an exact match (and not instanceof) to hit also primitive types (by accessing value.constructor they are converted to objects automatically) - switch (value?.constructor) { - case Function: - return this.writeValue(value()) - case Boolean: - return Utility.FirstCapital(value.toString()) - case Number: - return value.toString() - case String: - return `"${value}"` - } - if (value instanceof Array) { - return `(${value.map(v => serialize(v) + ",")})` - } - if (value instanceof IEntity) { - return serialize(value) - } - } - - subWrite(key, object) { - let result = "" - let fullKey = key.concat("") - const last = fullKey.length - 1 - for (const property in object) { - fullKey[last] = property - const value = object[property] - if (object[property]?.constructor === Object) { - // Recursive call when finding an object - result += (result.length ? this.separator : "") - + this.subWrite(fullKey, value) - } else if (this.showProperty(fullKey, value)) { - result += (result.length ? this.separator : "") - + this.prefix - + this.attributeKeyPrinter(fullKey) - + this.attributeValueConjunctionSign - + this.writeValue(value) - } - } - if (this.trailingSeparator && result.length && fullKey.length === 0) { - // append separator at the end if asked and there was printed content - result += this.separator - } - return result - } - - showProperty(attributeKey, attributeValue) { - const attributes = this.entityType.attributes - const attribute = Utility.objectGet(attributes, attributeKey) - if (attribute instanceof TypeInitialization) { - return !Utility.equals(attribute.value, attributeValue) || attribute.showDefault - } - return true - } -} +import IEntity from "../entity/IEntity" +import Grammar from "./Grammar" +import Parsimmon from "parsimmon" +import SerializerFactory from "./SerializerFactory" +import TypeInitialization from "../entity/TypeInitialization" +import Utility from "../Utility" + +export default class ISerializer { + + static grammar = Parsimmon.createLanguage(new Grammar()) + + constructor(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) { + this.entityType = entityType + this.prefix = prefix ?? "" + this.separator = separator ?? "," + this.trailingSeparator = trailingSeparator ?? false + this.attributeValueConjunctionSign = attributeValueConjunctionSign ?? "=" + this.attributeKeyPrinter = attributeKeyPrinter ?? (k => k.join(".")) + } + + writeValue(value) { + if (value === null) { + return "()" + } + const serialize = v => SerializerFactory.getSerializer(Utility.getType(v)).write(v) + // This is an exact match (and not instanceof) to hit also primitive types (by accessing value.constructor they are converted to objects automatically) + switch (value?.constructor) { + case Function: + return this.writeValue(value()) + case Boolean: + return Utility.FirstCapital(value.toString()) + case Number: + return value.toString() + case String: + return `"${value}"` + } + if (value instanceof Array) { + return `(${value.map(v => serialize(v) + ",")})` + } + if (value instanceof IEntity) { + return serialize(value) + } + } + + subWrite(key, object) { + let result = "" + let fullKey = key.concat("") + const last = fullKey.length - 1 + for (const property in object) { + fullKey[last] = property + const value = object[property] + if (object[property]?.constructor === Object) { + // Recursive call when finding an object + result += (result.length ? this.separator : "") + + this.subWrite(fullKey, value) + } else if (this.showProperty(fullKey, value)) { + result += (result.length ? this.separator : "") + + this.prefix + + this.attributeKeyPrinter(fullKey) + + this.attributeValueConjunctionSign + + this.writeValue(value) + } + } + if (this.trailingSeparator && result.length && fullKey.length === 0) { + // append separator at the end if asked and there was printed content + result += this.separator + } + return result + } + + showProperty(attributeKey, attributeValue) { + const attributes = this.entityType.attributes + const attribute = Utility.objectGet(attributes, attributeKey) + if (attribute instanceof TypeInitialization) { + return !Utility.equals(attribute.value, attributeValue) || attribute.showDefault + } + return true + } +} diff --git a/js/serialization/ObjectSerializer.js b/js/serialization/ObjectSerializer.js index db32b52..05e979a 100755 --- a/js/serialization/ObjectSerializer.js +++ b/js/serialization/ObjectSerializer.js @@ -1,9 +1,9 @@ import ObjectEntity from "../entity/ObjectEntity" import PinEntity from "../entity/PinEntity" -import Serializer from "./Serializer" +import ISerializer from "./ISerializer" import SerializerFactory from "./SerializerFactory" -export default class ObjectSerializer extends Serializer { +export default class ObjectSerializer extends ISerializer { constructor() { super(ObjectEntity, " ", "\n", false) @@ -21,7 +21,7 @@ export default class ObjectSerializer extends Serializer { } read(value) { - const parseResult = Serializer.grammar.Object.parse(value) + const parseResult = ISerializer.grammar.Object.parse(value) if (!parseResult.status) { console.error("Error when trying to parse the object.") return parseResult @@ -35,7 +35,7 @@ export default class ObjectSerializer extends Serializer { * @returns {ObjectEntity[]} */ readMultiple(value) { - const parseResult = Serializer.grammar.MultipleObject.parse(value) + const parseResult = ISerializer.grammar.MultipleObject.parse(value) if (!parseResult.status) { console.error("Error when trying to parse the object.") return parseResult diff --git a/js/template/BlueprintTemplate.js b/js/template/BlueprintTemplate.js index 867ba3c..88752ea 100755 --- a/js/template/BlueprintTemplate.js +++ b/js/template/BlueprintTemplate.js @@ -2,10 +2,10 @@ import Configuration from "../Configuration" import html from "./html" import sanitizeText from "./sanitizeText" import SelectorElement from "../element/SelectorElement" -import Template from "./Template" +import ITemplate from "./ITemplate" /** @typedef {import("../Blueprint").default} Blueprint */ -export default class BlueprintTemplate extends Template { +export default class BlueprintTemplate extends ITemplate { header(element) { return html`
diff --git a/js/template/Template.js b/js/template/ITemplate.js old mode 100755 new mode 100644 similarity index 90% rename from js/template/Template.js rename to js/template/ITemplate.js index 05e8c23..4e3d2cb --- a/js/template/Template.js +++ b/js/template/ITemplate.js @@ -1,23 +1,23 @@ -/** - * @typedef {import("../element/IElement").default} IElement - */ -export default class Template { - - /** - * Computes the html content of the target element. - * @param {IElement} entity Element of the graph - * @returns The result html - */ - render(entity) { - return "" - } - - /** - * Applies the style to the element. - * @param {IElement} element Element of the graph - */ - apply(element) { - // TODO replace with the safer element.setHTML(...) when it will be available - element.innerHTML = this.render(element) - } -} +/** + * @typedef {import("../element/IElement").default} IElement + */ +export default class ITemplate { + + /** + * Computes the html content of the target element. + * @param {IElement} entity Element of the graph + * @returns The result html + */ + render(entity) { + return "" + } + + /** + * Applies the style to the element. + * @param {IElement} element Element of the graph + */ + apply(element) { + // TODO replace with the safer element.setHTML(...) when it will be available + element.innerHTML = this.render(element) + } +} diff --git a/js/template/LinkMessageTemplate.js b/js/template/LinkMessageTemplate.js index be88ad4..8e88318 100644 --- a/js/template/LinkMessageTemplate.js +++ b/js/template/LinkMessageTemplate.js @@ -1,11 +1,11 @@ import LinkElement from "../element/LinkElement" import html from "./html" -import Template from "./Template" +import ITemplate from "./ITemplate" /** * @typedef {import("../element/LinkMessageElement").default} LinkMessageElement */ -export default class LinkMessageTemplate extends Template { +export default class LinkMessageTemplate extends ITemplate { /** * Computes the html content of the target element. diff --git a/js/template/LinkTemplate.js b/js/template/LinkTemplate.js index 1245927..2715cd5 100755 --- a/js/template/LinkTemplate.js +++ b/js/template/LinkTemplate.js @@ -1,13 +1,13 @@ import html from "./html" import sanitizeText from "./sanitizeText" -import Template from "./Template" +import ITemplate from "./ITemplate" import Configuration from "../Configuration" /** * @typedef {import("../element/LinkElement").default} LinkElement * @typedef {import("../element/LinkMessageElement").default} LinkMessageElement */ -export default class LinkTemplate extends Template { +export default class LinkTemplate extends ITemplate { static pixelToUnit(pixels, pixelFullSize) { return pixels * 100 / pixelFullSize diff --git a/js/template/PinTemplate.js b/js/template/PinTemplate.js index c735319..ba1dd64 100755 --- a/js/template/PinTemplate.js +++ b/js/template/PinTemplate.js @@ -1,12 +1,12 @@ import Utility from "../Utility" import html from "./html" import sanitizeText from "./sanitizeText" -import Template from "./Template" +import ITemplate from "./ITemplate" /** * @typedef {import("../element/PinElement").default} PinElement */ -export default class PinTemplate extends Template { +export default class PinTemplate extends ITemplate { /** * Computes the html content of the pin. diff --git a/js/template/SelectableDraggableTemplate.js b/js/template/SelectableDraggableTemplate.js index a69f268..9179fd4 100755 --- a/js/template/SelectableDraggableTemplate.js +++ b/js/template/SelectableDraggableTemplate.js @@ -1,10 +1,10 @@ import sanitizeText from "./sanitizeText" -import Template from "./Template" +import ITemplate from "./ITemplate" /** * @typedef {import("../element/ISelectableDraggableElement").default} ISelectableDraggableElement */ -export default class SelectableDraggableTemplate extends Template { +export default class SelectableDraggableTemplate extends ITemplate { /** * Returns the html elements rendered from this template. diff --git a/js/template/SelectorTemplate.js b/js/template/SelectorTemplate.js index 163b676..d0440f0 100755 --- a/js/template/SelectorTemplate.js +++ b/js/template/SelectorTemplate.js @@ -1,10 +1,10 @@ import sanitizeText from "./sanitizeText" -import Template from "./Template" +import ITemplate from "./ITemplate" /** * @typedef {import("../element/SelectorElement").default} SelectorElement */ -export default class SelectorTemplate extends Template { +export default class SelectorTemplate extends ITemplate { /** * Applies the style to the element.