From 33ebfd68a035f66642fdec3f67b0a263d7d7ba94 Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Mon, 21 Nov 2022 14:01:06 +0000 Subject: [PATCH] [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) --- addons/web/static/src/core/utils/draggable_hook_builder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/core/utils/draggable_hook_builder.js b/addons/web/static/src/core/utils/draggable_hook_builder.js index 830f8be5787..8820b58666c 100644 --- a/addons/web/static/src/core/utils/draggable_hook_builder.js +++ b/addons/web/static/src/core/utils/draggable_hook_builder.js @@ -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`); } }