@antv/x6
Version:
JavaScript diagramming library that uses SVG and HTML for rendering
94 lines • 2.72 kB
JavaScript
import { __decorate, __rest } from "tslib";
import { Basecoat, disposable } from '../../common';
import { ClipboardImpl } from './clipboard';
import './api';
export class Clipboard extends Basecoat {
get disabled() {
return this.options.enabled !== true;
}
get cells() {
return this.clipboardImpl.cells;
}
constructor(options = {}) {
super();
this.name = 'clipboard';
this.options = Object.assign({ enabled: true }, options);
}
init(graph) {
this.graph = graph;
this.clipboardImpl = new ClipboardImpl();
this.clipboardImpl.deserialize(this.options);
}
// #region api
isEnabled() {
return !this.disabled;
}
enable() {
if (this.disabled) {
this.options.enabled = true;
}
}
disable() {
if (!this.disabled) {
this.options.enabled = false;
}
}
toggleEnabled(enabled) {
// the enabled state is not specified.
if (enabled === undefined) {
enabled = !this.isEnabled();
}
enabled ? this.enable() : this.disable();
return this;
}
isEmpty(options = {}) {
return this.clipboardImpl.isEmpty(options);
}
getCellsInClipboard() {
return this.cells;
}
clean(force) {
if (!this.disabled || force) {
this.clipboardImpl.clean();
this.notify('clipboard:changed', { cells: [] });
}
return this;
}
copy(cells, options = {}) {
if (!this.disabled) {
this.clipboardImpl.copy(cells, this.graph, Object.assign(Object.assign({}, this.commonOptions), options));
this.notify('clipboard:changed', { cells });
}
return this;
}
cut(cells, options = {}) {
if (!this.disabled) {
this.clipboardImpl.cut(cells, this.graph, Object.assign(Object.assign({}, this.commonOptions), options));
this.notify('clipboard:changed', { cells });
}
return this;
}
paste(options = {}, graph = this.graph) {
if (!this.disabled) {
return this.clipboardImpl.paste(graph, Object.assign(Object.assign({}, this.commonOptions), options));
}
return [];
}
// #endregion
get commonOptions() {
const _a = this.options, { enabled } = _a, others = __rest(_a, ["enabled"]);
return others;
}
notify(name, args) {
this.trigger(name, args);
this.graph.trigger(name, args);
}
dispose() {
this.clean(true);
this.off();
}
}
__decorate([
disposable()
], Clipboard.prototype, "dispose", null);
//# sourceMappingURL=index.js.map