Browse Source

fix: improve drag event handling by ensuring target and event are correctly set for move command

carlos/645-absolute-mode-enhancements
Carlos 10 months ago
parent
commit
53fdee374c
  1. 11
      packages/core/src/commands/index.ts
  2. 13
      packages/core/src/dom_components/model/Component.ts

11
packages/core/src/commands/index.ts

@ -164,17 +164,6 @@ export default class CommandsModule extends Module<CommandsConfig & { pStylePref
const onEnd = getOnComponentDragEnd(em, targets, { altMode });
if (altMode) {
// Create the event if none is provided
// TODO: Check why this logic is needed with the toolbar move button in absolute mode (in not absolute mode it isn't needed)
if (!event) {
const rect = target.view?.el.getBoundingClientRect();
const clientX = rect ? rect.left + rect.width / 2 : 0;
const clientY = rect ? rect.top + rect.height / 2 : 0;
event = { type: 'manual', clientX, clientY };
}
dragger = ed.runCommand('core:component-drag', {
guidesInfo: 1,
mode,

13
packages/core/src/dom_components/model/Component.ts

@ -1146,7 +1146,18 @@ export default class Component extends StyleableModel<ComponentProperties> {
tb.push({
attributes: { class: `${ppfx}no-touch-actions`, draggable: true },
label: em.getIcon('move'),
command: 'tlb-move',
command: (ed) => {
// tld-move event needs to be called with a target and a drag event
const target = ed.getSelected();
const rect = target?.view?.el.getBoundingClientRect();
const clientX = rect ? rect.left + rect.width / 2 : 0;
const clientY = rect ? rect.top + rect.height / 2 : 0;
ed.runCommand('tlb-move', {
target,
event: new DragEvent('dragstart', { clientX, clientY }),
});
},
});
model.get('copyable') &&
tb.push({

Loading…
Cancel
Save