import { LitElement, PropertyValueMap, html } from "lit"; import { customElement, property } from "lit/decorators.js"; // Syncmeta Widgets import "./partials/main.widget"; import "./partials/attribute.widget"; import "./partials/debug.widget"; import "./partials/palette.widget"; import "./partials/activity.widget"; import interact from "interactjs"; @customElement("widget-container") export class WidgetContainer extends LitElement { @property({ type: String }) yjsHost = "localhost"; @property({ type: Number }) yjsPort = 1234; @property({ type: String }) yjsProtocol = "ws"; @property({ type: String }) yjsSpaceTitle = window.spaceTitle; createRenderRoot() { return this; } constructor() { super(); } render() { return html`
`; } connectedCallback(): void { super.connectedCallback(); } protected firstUpdated( _changedProperties: PropertyValueMap | Map ): void { super.firstUpdated(_changedProperties); this.addWidgetButtons(); interact(".main-left").resizable({ // resize from all edges and corners edges: { right: true, // Resize if pointer target is the given Element }, listeners: { move(event) { const target = event.target; let x = parseFloat(target.getAttribute("data-x")) || 0; let y = parseFloat(target.getAttribute("data-y")) || 0; // update the element's style target.style.width = event.rect.width + "px"; target.style.height = event.rect.height + "px"; // translate when resizing from top or left edges x += event.deltaRect.left; y += event.deltaRect.top; target.style.webkitTransform = target.style.transform = "translate(" + x + "px," + y + "px)"; target.setAttribute("data-x", x); target.setAttribute("data-y", y); }, }, // Width and height can be adjusted independently. When `true`, width and // height are adjusted at a 1:1 ratio. square: false, // Width and height can be adjusted independently. When `true`, width and // height maintain the aspect ratio they had when resizing started. preserveAspectRatio: false, invert: "none", max: Infinity, modifiers: [ // Minimum size interact.modifiers.restrictSize({ min: { width: 100, height: 50 }, }), ], maxPerElement: 1, }); } /** * Adds the widget buttons to the main widget container. * One button for the export/import modal and one button for the user activities. */ addWidgetButtons() { setTimeout(() => { const rowContainer = document.querySelector( "#main-widget-utilities-container" ); if (!rowContainer?.firstElementChild) { console.error( `Could not find the first col of row container. ${document.querySelector( "#main-widget-utilities-container" )} This means that the debug widget button will not be added. Make sure that the following selector is correct: #main-widget-utilities-container. The first child will be used to append the button.` ); return; } const widgetButtons = `
`; // add buttons as the second child of the row container rowContainer.firstElementChild.appendChild( new DOMParser().parseFromString(widgetButtons, "text/html").body .firstChild as Node ); }, 1000); } }