123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- import {
- import_css
- } from "./chunk-PGYCW7PW.js";
- import {
- attr,
- classes,
- delegate,
- domify$1,
- event,
- query
- } from "./chunk-XZ2PVW7M.js";
- import {
- assign,
- every,
- forEach,
- isArray,
- isDefined,
- isFunction,
- some
- } from "./chunk-4AK4GF4H.js";
- import "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/diagram-js@11.9.1/node_modules/diagram-js/lib/util/Elements.js
- function getBBox(elements, stopRecursion) {
- stopRecursion = !!stopRecursion;
- if (!isArray(elements)) {
- elements = [elements];
- }
- var minX, minY, maxX, maxY;
- forEach(elements, function(element) {
- var bbox = element;
- if (element.waypoints && !stopRecursion) {
- bbox = getBBox(element.waypoints, true);
- }
- var x = bbox.x, y = bbox.y, height = bbox.height || 0, width = bbox.width || 0;
- if (x < minX || minX === void 0) {
- minX = x;
- }
- if (y < minY || minY === void 0) {
- minY = y;
- }
- if (x + width > maxX || maxX === void 0) {
- maxX = x + width;
- }
- if (y + height > maxY || maxY === void 0) {
- maxY = y + height;
- }
- });
- return {
- x: minX,
- y: minY,
- height: maxY - minY,
- width: maxX - minX
- };
- }
- // node_modules/.pnpm/diagram-js@11.9.1/node_modules/diagram-js/lib/features/context-pad/ContextPad.js
- var entrySelector = ".entry";
- var DEFAULT_PRIORITY = 1e3;
- var CONTEXT_PAD_PADDING = 12;
- function ContextPad(canvas, config, eventBus, overlays) {
- this._canvas = canvas;
- this._eventBus = eventBus;
- this._overlays = overlays;
- var scale = isDefined(config && config.scale) ? config.scale : {
- min: 1,
- max: 1.5
- };
- this._overlaysConfig = {
- scale
- };
- this._current = null;
- this._init();
- }
- ContextPad.$inject = [
- "canvas",
- "config.contextPad",
- "eventBus",
- "overlays"
- ];
- ContextPad.prototype._init = function() {
- var self = this;
- this._eventBus.on("selection.changed", function(event2) {
- var selection = event2.newSelection;
- var target = selection.length ? selection.length === 1 ? selection[0] : selection : null;
- if (target) {
- self.open(target, true);
- } else {
- self.close();
- }
- });
- this._eventBus.on("elements.changed", function(event2) {
- var elements = event2.elements, current = self._current;
- if (!current) {
- return;
- }
- var currentTarget = current.target;
- var currentChanged = some(
- isArray(currentTarget) ? currentTarget : [currentTarget],
- function(element) {
- return includes(elements, element);
- }
- );
- if (currentChanged) {
- self.open(currentTarget, true);
- }
- });
- };
- ContextPad.prototype.registerProvider = function(priority, provider) {
- if (!provider) {
- provider = priority;
- priority = DEFAULT_PRIORITY;
- }
- this._eventBus.on("contextPad.getProviders", priority, function(event2) {
- event2.providers.push(provider);
- });
- };
- ContextPad.prototype.getEntries = function(target) {
- var providers = this._getProviders();
- var provideFn = isArray(target) ? "getMultiElementContextPadEntries" : "getContextPadEntries";
- var entries = {};
- forEach(providers, function(provider) {
- if (!isFunction(provider[provideFn])) {
- return;
- }
- var entriesOrUpdater = provider[provideFn](target);
- if (isFunction(entriesOrUpdater)) {
- entries = entriesOrUpdater(entries);
- } else {
- forEach(entriesOrUpdater, function(entry, id) {
- entries[id] = entry;
- });
- }
- });
- return entries;
- };
- ContextPad.prototype.trigger = function(action, event2, autoActivate) {
- var entry, originalEvent, button = event2.delegateTarget || event2.target;
- if (!button) {
- return event2.preventDefault();
- }
- entry = attr(button, "data-action");
- originalEvent = event2.originalEvent || event2;
- return this.triggerEntry(entry, action, originalEvent, autoActivate);
- };
- ContextPad.prototype.triggerEntry = function(entryId, action, event2, autoActivate) {
- if (!this.isShown()) {
- return;
- }
- var target = this._current.target, entries = this._current.entries;
- var entry = entries[entryId];
- if (!entry) {
- return;
- }
- var handler = entry.action;
- if (isFunction(handler)) {
- if (action === "click") {
- return handler(event2, target, autoActivate);
- }
- } else {
- if (handler[action]) {
- return handler[action](event2, target, autoActivate);
- }
- }
- event2.preventDefault();
- };
- ContextPad.prototype.open = function(target, force) {
- if (!force && this.isOpen(target)) {
- return;
- }
- this.close();
- this._updateAndOpen(target);
- };
- ContextPad.prototype._getProviders = function() {
- var event2 = this._eventBus.createEvent({
- type: "contextPad.getProviders",
- providers: []
- });
- this._eventBus.fire(event2);
- return event2.providers;
- };
- ContextPad.prototype._updateAndOpen = function(target) {
- var entries = this.getEntries(target), pad = this.getPad(target), html = pad.html, image;
- forEach(entries, function(entry, id) {
- var grouping = entry.group || "default", control = domify$1(entry.html || '<div class="entry" draggable="true"></div>'), container;
- attr(control, "data-action", id);
- container = query("[data-group=" + (0, import_css.default)(grouping) + "]", html);
- if (!container) {
- container = domify$1('<div class="group"></div>');
- attr(container, "data-group", grouping);
- html.appendChild(container);
- }
- container.appendChild(control);
- if (entry.className) {
- addClasses(control, entry.className);
- }
- if (entry.title) {
- attr(control, "title", entry.title);
- }
- if (entry.imageUrl) {
- image = domify$1("<img>");
- attr(image, "src", entry.imageUrl);
- image.style.width = "100%";
- image.style.height = "100%";
- control.appendChild(image);
- }
- });
- classes(html).add("open");
- this._current = {
- target,
- entries,
- pad
- };
- this._eventBus.fire("contextPad.open", { current: this._current });
- };
- ContextPad.prototype.getPad = function(target) {
- if (this.isOpen()) {
- return this._current.pad;
- }
- var self = this;
- var overlays = this._overlays;
- var html = domify$1('<div class="djs-context-pad"></div>');
- var position = this._getPosition(target);
- var overlaysConfig = assign({
- html
- }, this._overlaysConfig, position);
- delegate.bind(html, entrySelector, "click", function(event2) {
- self.trigger("click", event2);
- });
- delegate.bind(html, entrySelector, "dragstart", function(event2) {
- self.trigger("dragstart", event2);
- });
- event.bind(html, "mousedown", function(event2) {
- event2.stopPropagation();
- });
- var activeRootElement = this._canvas.getRootElement();
- this._overlayId = overlays.add(activeRootElement, "context-pad", overlaysConfig);
- var pad = overlays.get(this._overlayId);
- this._eventBus.fire("contextPad.create", {
- target,
- pad
- });
- return pad;
- };
- ContextPad.prototype.close = function() {
- if (!this.isOpen()) {
- return;
- }
- this._overlays.remove(this._overlayId);
- this._overlayId = null;
- this._eventBus.fire("contextPad.close", { current: this._current });
- this._current = null;
- };
- ContextPad.prototype.isOpen = function(target) {
- var current = this._current;
- if (!current) {
- return false;
- }
- if (!target) {
- return true;
- }
- var currentTarget = current.target;
- if (isArray(target) !== isArray(currentTarget)) {
- return false;
- }
- if (isArray(target)) {
- return target.length === currentTarget.length && every(target, function(element) {
- return includes(currentTarget, element);
- });
- } else {
- return currentTarget === target;
- }
- };
- ContextPad.prototype.isShown = function() {
- return this.isOpen() && this._overlays.isShown();
- };
- ContextPad.prototype._getPosition = function(target) {
- var elements = isArray(target) ? target : [target];
- var bBox = getBBox(elements);
- return {
- position: {
- left: bBox.x + bBox.width + CONTEXT_PAD_PADDING,
- top: bBox.y - CONTEXT_PAD_PADDING / 2
- }
- };
- };
- function addClasses(element, classNames) {
- var classes2 = classes(element);
- classNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
- classNames.forEach(function(cls) {
- classes2.add(cls);
- });
- }
- function includes(array, item) {
- return array.indexOf(item) !== -1;
- }
- export {
- ContextPad as default
- };
- //# sourceMappingURL=diagram-js_lib_features_context-pad_ContextPad.js.map
|