The newDragSource() function is not functioning properly within golden-layout version 2.6.0

We are currently in the process of migrating from golden-layout version 1.5.9 to version 2.6.0 within a large Angular 16 production application, albeit slowly and somewhat painfully.

Within our application, there exists a dropdown menu that displays the names of all available widgets that can be added to the page. Upon initialization, all HTML elements within this menu are set up as drag sources using the newDragSource method provided by the GoldenLayout object.

In the previous version (1.5.9), this functionality worked flawlessly - users could drag items from the menu onto the page and they would appear as golden-layout components with full functionality. Additionally, clicking on an item in the menu also added the component to the page successfully.

However, in the latest version (2.6.0) this feature is completely broken. The menu items are not draggable at all. Nonetheless, clicking on an item in the menu still results in adding the selected component to the layout, which functions as expected.

The code snippet used to create the drag sources is outlined below:

public createNewWidgetDragSource(element: HTMLElement, widgetModel: Widget): void {
  const gl = this.getGoldenLayoutInstance();
  const config = () => {
    const item: DragSource.ComponentItemConfig = {
      state: null,
      title: widgetModel.name,
      type: 'widget-golden-instance',
    };
    return item;
  };

  gl.newDragSource(element, config);
}

It's worth noting that this code closely resembles the one utilized in the golden-layout-ng-app reference application, where it operates seamlessly. However, the reference app employs golden-layout version 2.5.0.

The widget-golden-instance component type represents a generic golden-layout container component, serving as a host for many of our own widgets.

Upon inspecting the gl object in the aforementioned code, I can confirm that the _dragSources array within the object does contain the LI elements from the menu.

No errors are reported in either the editor or browser, aside from a deprecation warning related to ComponentItemConfig under the DragSource namespace. This warning was disregarded, with no impact on the behavior noted.

Despite everything appearing correct, the dragging capability simply does not work. Could it be an oversight on my part, or perhaps a bug within the system?

Edit:

I suspect this issue may relate to the fact that the list items designated as drag sources are located within a menu. When hard-coded elements outside of the menu are made draggable using the same function createNewWidgetDragSource, they work as intended.

Even after attempting delayed initialization of the menu elements as drag sources when the menu is visible, the problem persists. Furthermore, calling the createNewWidgetDragSource method without passing an HTML element triggers an error from the golden-layout source, despite confirming that the method is passed the list-item elements from the menu.

An attempt to update the reference app to utilize golden-layout version 2.6.0 instead of 2.5.0 resulted in successful dragging functionality, leaving me perplexed as to why the same logic fails in our implementation.

All aspects seem to align correctly, with the appropriate elements present at the expected times and absence of any noticeable errors. Yet, the feature remains unresponsive.

Answer №1

After some trial and error, I finally managed to solve this.

Despite setting the list items in the menu as dragSource items, the mouseDown event handler (automatically added by golden-layout when creating each dragSource) was actually being triggered on a label element within the list item rather than the list item itself. There is a specific logic within golden-layout that verifies if the mouseDown event target matches the dragSource element. In this case, it did not match, causing the logic to fail.

The solution was to designate the labels within the list items as the dragSources instead, which successfully resolved the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlocking the pathway to a multitude of stores through an array using the power of Svelte

I am currently utilizing svelte-forms and looking to create an array of fields The function field() provides a writable store and serves as a convenient way to generate a new form input, acting as your input controller. Consider the following scenario & ...

What is the best way to refresh or reload a child component in Angular?

I have a transaction.component.html file that displays the app-deal-partners component. Every time the delete function is triggered, I want to refresh and reload the child component, which is the app-deal-partners component. I need to reload <app-deal- ...

Oops! An issue occurred: Attempting to access 'handle' property of an undefined value

Within my application, I've developed two distinct components: the Selector Component and the Shifter Component. The Selector Component is responsible for selecting a list of items that require updating, and it triggers a method in the Shifter Compone ...

Tips for cycling through the backend API map reaction in Angular or Typescript

When I make a call to an API, it returns a response in the form of a map: {thomas: 3, test70: 2, tim: 2, elin: 2, sumeet12: 1} I tried iterating over this response in Angular, but encountered an error. Error Encountered: This expression is not callab ...

In order to work with Mongoose and Typescript, it is necessary for me to

I am currently following the guidelines outlined in the Mongoose documentation to incorporate TypeScript support into my project: https://mongoosejs.com/docs/typescript.html. Within the documentation, there is an example provided as follows: import { Sche ...

Establishing the placement of map markers in Angular

Currently, I am in the process of developing a simple web application. The main functionality involves retrieving latitude and longitude data from my MongoDB database and displaying markers on a map, which is functioning correctly. However, the issue I&apo ...

Can you explain the key distinction between the backtick (`) and the ampersand-hash-39

I am completely new to TypeScript, JavaScript, and Angular. As I follow some tutorials, I often encounter code snippets like the one below: class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return `(${this.x}, ${th ...

Tips for sorting data based on duplicate dates within a single array element

Here is the existing Object Array structure: [ { "date":"12-09-2019 12:00 PM", "id":"1", "name":"hello1" }, { "date":"12-09-2019 03:00 PM", "id":"2", "name":"hello2" }, { "date":"12- ...

A feature that retrieves specific attributes from a type based on user-defined criteria

I am dealing with a group of types/interfaces that share common properties, but some cases do not utilize all of these properties. I would like to develop a function where only the names of the properties are passed to it. Here are the shared properties: ...

Strange Typescript Issue: Dependency Imports Not Recognized as Top-Level Module

Attempting to move a custom token from one account to another by following this detailed tutorial. Facing an issue with four errors showing up for all imports from the @solana/spl-token package. Tried removing the node-modules folder and reinstalling npm ...

What is the most effective way to perform unit testing on the "present" function of an Ionic alert controller?

I decided to write a unit test for the alert present function that gets triggered after creating an alert. This is what my code looks like. it('should call attempt To call alert present', async () => { const alert = { header: 'P ...

Using Typescript to add an element to a specific index in an array

Currently, I am engaged in a project using Angular2 and Firebase. My goal is to consolidate all query results under a single key called this.guestPush. Within my project, there is a multiple select element with different user levels - specifically 4, 6, ...

Struggling with the Transition from Google Sign-In

Having difficulty transitioning from Google Sign-In. "{error: 'idpiframe_initialization_failed', details: 'You have created a new client application that use…i/web/guides/gis-migration) for more information.'}" How do I u ...

Is TypeScript necessary, or can I simply stick with ES6?

As a client developer using AngularJS in my daily job, we are considering transitioning to TypeScript. After researching TypeScript, I discovered that most JavaScript packages I require need definition type files. This can be inconvenient, especially whe ...

The Angular Library encountered an error stating that the export 'X' imported as 'X' could not be found in 'my-pkg/my-lib'. It is possible that the library's exports include MyLibComponent, MyLibModule, and MyLibService

I have been attempting to bundle a group of classes into an Angular Library. I diligently followed the instructions provided at: https://angular.io/guide/creating-libraries: ng new my-pkg --no-create-application cd my-pkg ng generate library my-lib Subseq ...

Typescript error when using fill or justify prop in React-bootstrap with Typescript

Code import { useCallback, useState, useEffect } from 'react'; import { Tabs, Tab, Spinner, Alert } from 'react-bootstrap'; import { Categories } from '../../models/ICategory'; import IMovie from '../../models/IMovie&apo ...

What is the location for adjusting the angular strictness flags that determine the level of strictness for strictTemplates?

Currently in the process of transitioning our application to strictTemplates, we are encountering a multitude of errors, some more significant than others. As a result, I decided to adjust the strictness of the angular type checker and came across these s ...

Leveraging TypeScript alongside body-parser to access properties within req.body

I'm currently developing a web application using TypeScript and integrating the body-parser middleware to handle JSON request bodies. I've encountered type errors while attempting to access properties on the Request.body object. For instance, wh ...

Incorporating a new method into the Object prototype to provide universal access across all modules

I've been delving into Typescript experimentation and I'm attempting to enhance the Object prototype by adding a property that can be accessed by all objects within my modules. Here's what I've developed so far: In a Common.ts file O ...

Utilizing the backtick operator for string interpolation allows for dynamic value insertion

Greetings! Currently, I am delving into the world of Angular 2 and have stumbled upon some interesting discoveries. To enhance my knowledge of TypeScript, I decided to utilize the ScratchJS extension on the Chrome browser. During this exploration, I experi ...