[IMP] web: adapt draggable_hook_builder for new sortableList hook

Purpose:
--------
Knowledge's sidebar revamp introduces a new draggable hook "SortableList"
that is meant to replace the usage of jQuery's sortable widget and of the
NestedSortable library previously used for the sidebar.

To be able to build this hook using the `draggable_hook_builder`, some
changes have been introduced:

- Do not remove the height of the dragged element when computing its max
allowed height (so that the dragged element is below the cursor even when
the cursor is at the max allowed height, instead of being on top of the
lasts elements, obstructing the view)

- Allow to define mandatory params in the built hook's default params, so
that one does not have to define this mandatory param for each instance of
the hook (eg. SortableList is intended to only work with `li` elements)

Task-3074123

closes odoo/odoo#107490

Related: odoo/enterprise#34788
Related: odoo/upgrade#4118
Signed-off-by: David Beguin (dbe) <dbe@odoo.com>
This commit is contained in:
Adrien Schoffeniels
2023-06-08 17:40:13 +02:00
parent 8369ae63c5
commit 33ebfd68a0
@@ -669,13 +669,13 @@ export function makeDraggableHook(hookParams) {
*/
const updateElementPosition = () => {
const { containerRect, element, elementRect, offset } = ctx.current;
const { width: ew, height: eh } = elementRect;
const { width: ew } = elementRect;
const { x: cx, y: cy, width: cw, height: ch } = containerRect;
// Updates the position of the dragged element.
dom.addStyle(element, {
left: `${clamp(ctx.mouse.x - offset.x, cx, cx + cw - ew)}px`,
top: `${clamp(ctx.mouse.y - offset.y, cy, cy + ch - eh)}px`,
top: `${clamp(ctx.mouse.y - offset.y, cy, cy + ch)}px`,
});
};
@@ -770,7 +770,7 @@ export function makeDraggableHook(hookParams) {
)} } and got ${type}`
);
}
} else if (MANDATORY_PARAMS.includes(prop)) {
} else if (MANDATORY_PARAMS.includes(prop) && !defaultParams[prop]) {
throw makeError(`missing required property "${prop}" in parameters`);
}
}