A platform for community discussion. Free, open, simple.
UX: use core drag-and-drop on Boards (#43773)
Krisc967cf8fb1ae
diff --git a/plugins/boards/assets/javascripts/discourse/components/boards-board-viewer.gjs b/plugins/boards/assets/javascripts/discourse/components/boards-board-viewer.gjsindex 3d92d212d7b..ecf618f8beb 100644--- a/plugins/boards/assets/javascripts/discourse/components/boards-board-viewer.gjs+++ b/plugins/boards/assets/javascripts/discourse/components/boards-board-viewer.gjs@@ -29,11 +29,9 @@ import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";import dBoundCategoryLink from "discourse/ui-kit/helpers/d-bound-category-link";import dDiscourseTags from "discourse/ui-kit/helpers/d-discourse-tags";import dIcon from "discourse/ui-kit/helpers/d-icon";+import dDragAndDropAutoScroll from "discourse/ui-kit/modifiers/d-drag-and-drop-auto-scroll";import { i18n } from "discourse-i18n";-import {- autoScrollSpeedForPointer,- dragToScroll,-} from "../lib/boards-auto-scroll";+import { dragToScroll } from "../lib/boards-auto-scroll";import {isRecencyColumn,sortCardsForColumn,@@ -124,23 +122,7 @@ export default class BoardsBoardViewer extends Component {@tracked fullscreen = false;@tracked linkHighlightCardId = null;@tracked linkedCardId = null;-- horizontalAutoScrollFrame = null;- horizontalAutoScrollSpeed = 0;- horizontalAutoScrollContainer = null;- horizontalAutoScrollHasDocumentListeners = false;- stopHorizontalAutoScroll = () => this.#stopHorizontalAutoScroll();- updateHorizontalAutoScroll = (event) => {- if (!this.dragData || !this.horizontalAutoScrollContainer) {- this.#stopHorizontalAutoScroll();- return;- }-- this.#updateHorizontalAutoScroll(- this.horizontalAutoScrollContainer,- event.clientX- );- };+ @tracked pendingDropCardId = null;setupMessageBus = modifier((element) => {const channel = `/boards/${this.board.id}`;@@ -204,7 +186,6 @@ export default class BoardsBoardViewer extends Component {super.willDestroy(...arguments);this._clearDropHighlight();this._cleanupPromotion();- this.#stopHorizontalAutoScroll();}get boardTagNames() {@@ -297,153 +278,20 @@ export default class BoardsBoardViewer extends Component {});}- @action- dragOverBoardContainer(event) {- const dragData = this.dragData;- if (!dragData) {- this.#stopHorizontalAutoScroll();- return;- }-- event.preventDefault();- this.#updateHorizontalAutoScroll(event.currentTarget, event.clientX);- }-- @action- dragLeaveBoardContainer(event) {- if (!this.dragData && !event.currentTarget.contains(event.relatedTarget)) {- this.#stopHorizontalAutoScroll();- }- }-- @action- dropBoardContainer() {- this.#stopHorizontalAutoScroll();- }-@actionasync onDrop(cardId, toColumnId, afterCardId, fromColumnId) {- if (!this.board.canWrite || !fromColumnId) {- return;- }-- const fromColumn = this.columns.find((c) => c.id === fromColumnId);- const toColumn = this.columns.find((c) => c.id === toColumnId);- if (!fromColumn || !toColumn) {- return;- }-- const cardIndex = fromColumn.cards.findIndex((c) => c.id === cardId);- if (cardIndex === -1) {- return;- }-- const card = fromColumn.cards[cardIndex];- const isSameColumn = fromColumnId === toColumnId;- const targetIsRecency = isRecencyColumn(toColumn);- if (isSameColumn && targetIsRecency) {- this.dragData = null;- return;- }-- if (targetIsRecency) {- afterCardId = null;- }-- let constraintFix = null;-- if (!isSameColumn && card.topic) {- try {- constraintFix = await this.#resolveConstraintFix(- card.topic_id || card.topic.id,- card.topic,- toColumn- );- } catch (error) {- popupAjaxError(error);- return;- }-- if (constraintFix === false) {- return;- }- }-- if (!isSameColumn && !constraintFix && this.board.require_confirmation) {- const confirmed = await this._confirmMove(card, toColumn);- if (!confirmed) {- return;- }- }-- const snapshot = this.columns.map((col) =>- col.copy({ cards: col.cards.map((c) => c.copy()) })- );-- fromColumn.cards.splice(cardIndex, 1);-- let insertIndex = targetIsRecency ? 0 : toColumn.cards.length;- if (!targetIsRecency && afterCardId != null) {- const idx = toColumn.cards.findIndex((c) => c.id === afterCardId);- if (idx !== -1) {- insertIndex = idx + 1;- }- } else {- insertIndex = 0;- }- toColumn.cards.splice(insertIndex, 0, card);- card.column_id = toColumnId;-- this.columns = this.columns.map((col) => {- if (col.id === fromColumnId || col.id === toColumnId) {- return col.copy({ cards: [...col.cards] });- }- return col;- });- this.dragData = null;-- const data = {- client_id: this.messageBus.clientId,- card: {- column_id: toColumnId,- after_card_id: afterCardId,- },- };- if (constraintFix) {- data.constraint_fix = constraintFix;- }-+ // A move can wait on a server check or a confirmation. Until it settles,+ // keep the card hidden and the placeholder where it was dropped.+ this.pendingDropCardId = cardId;try {- const result = await ajax(- `/boards/api/boards/${this.board.id}/cards/${card.id}`,- { type: "PUT", data }+ await this.#moveDroppedCard(+ cardId,+ toColumnId,+ afterCardId,+ fromColumnId);- if (result?.card) {- const existingCard = this.columns- .flatMap((col) => col.cards)- .find((c) => c.id === result.card.id);- const mergedCard = existingCard- ? existingCard.copy(result.card)- : Card.create(result.card);- const withoutCard = this.columns.map((col) =>- col.copy({- cards: col.cards.filter((c) => c.id !== result.card.id),- })- );-- this.columns = withoutCard.map((col) => {- if (col.id === mergedCard.column_id) {- return col.copy({- cards: sortCardsForColumn(col, [...col.cards, mergedCard]),- });- }- return col;- });- }- this._highlightDroppedCard(card.id);- } catch (error) {- this.columns = snapshot;- popupAjaxError(error);+ } finally {+ this.#settlePendingDrop(cardId);}}@@ -964,100 +812,144 @@ export default class BoardsBoardViewer extends Component {}}- #updateHorizontalAutoScroll(container, clientX) {- const speed = autoScrollSpeedForPointer(- clientX,- container.getBoundingClientRect(),- "x"- );+ async #moveDroppedCard(cardId, toColumnId, afterCardId, fromColumnId) {+ if (!this.board.canWrite || !fromColumnId) {+ return;+ }- if (- (speed < 0 && container.scrollLeft <= 0) ||- (speed > 0 &&- container.scrollLeft + container.clientWidth >= container.scrollWidth)- ) {- this.#stopHorizontalAutoScroll();+ const fromColumn = this.columns.find((c) => c.id === fromColumnId);+ const toColumn = this.columns.find((c) => c.id === toColumnId);+ if (!fromColumn || !toColumn) {return;}- this.horizontalAutoScrollSpeed = speed;- this.horizontalAutoScrollContainer = container;- this.#ensureHorizontalAutoScrollDocumentListeners();+ const cardIndex = fromColumn.cards.findIndex((c) => c.id === cardId);+ if (cardIndex === -1) {+ return;+ }- if (speed === 0) {- this.#stopHorizontalAutoScroll();+ const card = fromColumn.cards[cardIndex];+ const isSameColumn = fromColumnId === toColumnId;+ const targetIsRecency = isRecencyColumn(toColumn);+ if (isSameColumn && targetIsRecency) {+ this.dragData = null;return;}- if (!this.horizontalAutoScrollFrame) {- this.#horizontalAutoScroll();+ if (targetIsRecency) {+ afterCardId = null;}- }- #horizontalAutoScroll() {- this.horizontalAutoScrollFrame = requestAnimationFrame(() => {- this.horizontalAutoScrollFrame = null;+ let constraintFix = null;- const container = this.horizontalAutoScrollContainer;- if (!container || this.horizontalAutoScrollSpeed === 0) {+ if (!isSameColumn && card.topic) {+ try {+ constraintFix = await this.#resolveConstraintFix(+ card.topic_id || card.topic.id,+ card.topic,+ toColumn+ );+ } catch (error) {+ popupAjaxError(error);return;}- const previousScrollLeft = container.scrollLeft;- container.scrollLeft += this.horizontalAutoScrollSpeed;+ if (constraintFix === false) {+ return;+ }+ }- if (container.scrollLeft === previousScrollLeft) {- this.#stopHorizontalAutoScroll();+ if (!isSameColumn && !constraintFix && this.board.require_confirmation) {+ const confirmed = await this._confirmMove(card, toColumn);+ if (!confirmed) {return;}+ }- this.#horizontalAutoScroll();- });- }+ const snapshot = this.columns.map((col) =>+ col.copy({ cards: col.cards.map((c) => c.copy()) })+ );- #ensureHorizontalAutoScrollDocumentListeners() {- if (this.horizontalAutoScrollHasDocumentListeners) {- return;+ fromColumn.cards.splice(cardIndex, 1);++ let insertIndex = targetIsRecency ? 0 : toColumn.cards.length;+ if (!targetIsRecency && afterCardId != null) {+ const idx = toColumn.cards.findIndex((c) => c.id === afterCardId);+ if (idx !== -1) {+ insertIndex = idx + 1;+ }+ } else {+ insertIndex = 0;}+ toColumn.cards.splice(insertIndex, 0, card);+ card.column_id = toColumnId;- document.addEventListener(- "dragover",- this.updateHorizontalAutoScroll,- true- );- document.addEventListener("dragend", this.stopHorizontalAutoScroll, true);- document.addEventListener("drop", this.stopHorizontalAutoScroll, true);- this.horizontalAutoScrollHasDocumentListeners = true;- }+ this.#settlePendingDrop(cardId);+ this.columns = this.columns.map((col) => {+ if (col.id === fromColumnId || col.id === toColumnId) {+ return col.copy({ cards: [...col.cards] });+ }+ return col;+ });+ this.dragData = null;- #removeHorizontalAutoScrollDocumentListeners() {- if (!this.horizontalAutoScrollHasDocumentListeners) {- return;+ const data = {+ client_id: this.messageBus.clientId,+ card: {+ column_id: toColumnId,+ after_card_id: afterCardId,+ },+ };+ if (constraintFix) {+ data.constraint_fix = constraintFix;}- document.removeEventListener(- "dragover",- this.updateHorizontalAutoScroll,- true- );- document.removeEventListener(- "dragend",- this.stopHorizontalAutoScroll,- true- );- document.removeEventListener("drop", this.stopHorizontalAutoScroll, true);- this.horizontalAutoScrollHasDocumentListeners = false;+ try {+ const result = await ajax(+ `/boards/api/boards/${this.board.id}/cards/${card.id}`,+ { type: "PUT", data }+ );+ if (result?.card) {+ const existingCard = this.columns+ .flatMap((col) => col.cards)+ .find((c) => c.id === result.card.id);+ const mergedCard = existingCard+ ? existingCard.copy(result.card)+ : Card.create(result.card);+ const withoutCard = this.columns.map((col) =>+ col.copy({+ cards: col.cards.filter((c) => c.id !== result.card.id),+ })+ );++ this.columns = withoutCard.map((col) => {+ if (col.id === mergedCard.column_id) {+ return col.copy({+ cards: sortCardsForColumn(col, [...col.cards, mergedCard]),+ });+ }+ return col;+ });+ }+ this._highlightDroppedCard(card.id);+ } catch (error) {+ this.columns = snapshot;+ popupAjaxError(error);+ }}- #stopHorizontalAutoScroll() {- if (this.horizontalAutoScrollFrame) {- cancelAnimationFrame(this.horizontalAutoScrollFrame);- this.horizontalAutoScrollFrame = null;+ #settlePendingDrop(cardId) {+ if (this.pendingDropCardId !== cardId) {+ return;}- this.horizontalAutoScrollSpeed = 0;- this.horizontalAutoScrollContainer = null;- this.#removeHorizontalAutoScrollDocumentListeners();+ this.pendingDropCardId = null;+ document+ .querySelectorAll(".discourse-boards-column__drop-indicator")+ .forEach((indicator) => indicator.remove());+ document+ .querySelectorAll(".discourse-boards-column__empty[hidden]")+ .forEach((emptyMessage) => (emptyMessage.hidden = false));}async #resolveConstraintFix(topicId, topic, column) {@@ -1530,9 +1422,7 @@ export default class BoardsBoardViewer extends Component {{{#if this.columns.length}}<divclass="discourse-boards-board-container"- {{on "dragover" this.dragOverBoardContainer}}- {{on "dragleave" this.dragLeaveBoardContainer}}- {{on "drop" this.dropBoardContainer}}+ {{dDragAndDropAutoScroll axis="horizontal" types="boards-card"}}{{dragToScroll}}>{{#each this.columns key="id" as |column|}}@@ -1557,6 +1447,7 @@ export default class BoardsBoardViewer extends Component {@onPromoteToTopic={{this.onPromoteToTopic}}@onRefreshBoard={{this.refreshBoard}}@onUpdateCard={{this.onUpdateCard}}+ @pendingDropCardId={{this.pendingDropCardId}}/>{{/each}}{{#if this.board.canManage}}diff --git a/plugins/boards/assets/javascripts/discourse/components/boards-card.gjs b/plugins/boards/assets/javascripts/discourse/components/boards-card.gjsindex 8280dd18bb2..b42c9c1dbc9 100644--- a/plugins/boards/assets/javascripts/discourse/components/boards-card.gjs+++ b/plugins/boards/assets/javascripts/discourse/components/boards-card.gjs@@ -1,19 +1,19 @@import Component from "@glimmer/component";import { tracked } from "@glimmer/tracking";-import { fn } from "@ember/helper";+import { fn, hash } from "@ember/helper";import { on } from "@ember/modifier";import { action } from "@ember/object";import { getOwner } from "@ember/owner";-import { cancel } from "@ember/runloop";import { service } from "@ember/service";import { trustHTML } from "@ember/template";+import { modifier } from "ember-modifier";import TopicStatus from "discourse/components/topic-status";import DMenu from "discourse/float-kit/components/d-menu";-import discourseLater from "discourse/lib/later";import renderTags from "discourse/lib/render-tags";import { emojiUnescape } from "discourse/lib/text";import DiscourseURL from "discourse/lib/url";import { escapeExpression } from "discourse/lib/utilities";+import { not, or } from "discourse/truth-helpers";import DAsyncContent from "discourse/ui-kit/d-async-content";import DButton from "discourse/ui-kit/d-button";import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";@@ -22,6 +22,7 @@ import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";import dFormatDate from "discourse/ui-kit/helpers/d-format-date";import dIcon from "discourse/ui-kit/helpers/d-icon";import { renderAvatar } from "discourse/ui-kit/helpers/d-user-avatar";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";import { i18n } from "discourse-i18n";import { loadCategory } from "../lib/boards-categories";import { boardsBoardUrl, boardsCardUrl } from "../lib/boards-urls";@@ -42,18 +43,34 @@ export default class BoardsCard extends Component {@service siteSettings;@tracked dragging = false;- dragHideTimer = null;- dragImageElement = null;++ /**+ * Links and images inside the card start their own native drag, which no+ * column accepts. Tags and badges are rendered HTML that can't bind+ * `draggable`, so it is switched off on whatever is pressed.+ */+ suppressNestedNativeDrag = modifier((element) => {+ const onPointerDown = (event) => {+ if (!element.hasAttribute("data-drag-source")) {+ return;+ }+ const nested = event.target.closest?.("a, img");+ if (nested && element.contains(nested)) {+ nested.draggable = false;+ }+ };++ element.addEventListener("pointerdown", onPointerDown, { capture: true });+ return () =>+ element.removeEventListener("pointerdown", onPointerDown, {+ capture: true,+ });+ });willDestroy() {super.willDestroy(...arguments);- const isActiveDragSource =- this.dragging || this.dragHideTimer || this.dragImageElement;- this.#clearDragHideTimer();- this.#cleanupDragImage();-- if (isActiveDragSource) {+ if (this.dragging) {this.#removeDropIndicators();}}@@ -376,35 +393,31 @@ export default class BoardsCard extends Component {}@action- dragStart(event) {- if (!this.args.board.canWrite) {- event.preventDefault();- return;- }-- const cardRect = event.currentTarget.getBoundingClientRect();- this.#setDragImage(event, event.currentTarget, cardRect);+ dragStart({ source }) {+ const cardElement = source.element;+ const cardHeight = cardElement.getBoundingClientRect().height;this.args.onDragStart({cardId: this.args.card.id,topicId: this.args.card.topic_id,fromColumnId: this.args.card.column_id,- cardHeight: cardRect.height,+ cardHeight,hasPlacedIndicator: false,});- event.dataTransfer.effectAllowed = "move";- event.stopPropagation();- this.#scheduleDragSourceHide(event.currentTarget, cardRect.height);+ if (shouldInsertSourceDropIndicator()) {+ this.#insertSourceDropIndicator(cardElement, cardHeight);+ }+ this.dragging = true;}@actiondragEnd() {this.args.onDragEnd?.(this.args.card.id);- this.#clearDragHideTimer();- this.#removeDropIndicators();+ if (!this.args.isPendingDrop) {+ this.#removeDropIndicators();+ }this.dragging = false;- this.#cleanupDragImage();}#openFloaterAssignModal() {@@ -422,59 +435,6 @@ export default class BoardsCard extends Component {});}- #scheduleDragSourceHide(cardElement, cardHeight) {- this.#clearDragHideTimer();-- this.dragHideTimer = discourseLater(this, () => {- this.dragHideTimer = null;-- if (!this.isDestroying) {- if (shouldInsertSourceDropIndicator()) {- this.#insertSourceDropIndicator(cardElement, cardHeight);- }- this.dragging = true;- }- });- }-- #clearDragHideTimer() {- if (this.dragHideTimer) {- cancel(this.dragHideTimer);- this.dragHideTimer = null;- }- }-- #setDragImage(event, cardElement, cardRect) {- if (!event.dataTransfer?.setDragImage) {- return;- }-- this.#cleanupDragImage();-- const dragImage = cardElement.cloneNode(true);- dragImage.classList.remove("discourse-boards-card--dragging");- dragImage.classList.add("discourse-boards-card--drag-image");- dragImage.style.width = `${cardRect.width}px`;- dragImage.style.height = `${cardRect.height}px`;- dragImage.setAttribute("aria-hidden", "true");-- document.body.append(dragImage);- this.dragImageElement = dragImage;-- // Fallback for programmatic or test drags where the pointer coordinates are 0.- const offsetX =- event.clientX > 0 ? Math.max(event.clientX - cardRect.left, 0) : 24;- const offsetY =- event.clientY > 0 ? Math.max(event.clientY - cardRect.top, 0) : 24;-- event.dataTransfer.setDragImage(dragImage, offsetX, offsetY);- }-- #cleanupDragImage() {- this.dragImageElement?.remove();- this.dragImageElement = null;- }-#insertSourceDropIndicator(cardElement, cardHeight) {const cardsContainer = cardElement.closest(".discourse-boards-column__cards"@@ -504,18 +464,23 @@ export default class BoardsCard extends Component {<divclass={{dConcatClass"discourse-boards-card"- (if this.dragging "discourse-boards-card--dragging")+ (if (or this.dragging @isPendingDrop) "discourse-boards-card--dragging")(unless this.isTopicCard "discourse-boards-card--floater")(if @isDropHighlighted "discourse-boards-card--drop-highlighted")(if @isLinkHighlighted "discourse-boards-card--link-highlighted")}}data-card-id={{@card.id}}data-topic-id={{@card.topic_id}}- draggable={{@board.canWrite}}role="button"tabindex="0"- {{on "dragstart" this.dragStart}}- {{on "dragend" this.dragEnd}}+ {{dDragAndDropSource+ type="boards-card"+ data=(hash [email protected] [email protected]_id)+ disabled=(not @board.canWrite)+ onDragEnd=this.dragEnd+ onDragStart=this.dragStart+ }}+ {{this.suppressNestedNativeDrag}}{{on "click" this.onCardClick}}{{on "keydown" this.onCardKeydown}}>diff --git a/plugins/boards/assets/javascripts/discourse/components/boards-column.gjs b/plugins/boards/assets/javascripts/discourse/components/boards-column.gjsindex 22b12c15bfa..76b8c9acc35 100644--- a/plugins/boards/assets/javascripts/discourse/components/boards-column.gjs+++ b/plugins/boards/assets/javascripts/discourse/components/boards-column.gjs@@ -9,8 +9,9 @@ import { eq } from "discourse/truth-helpers";import DButton from "discourse/ui-kit/d-button";import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";import dIcon from "discourse/ui-kit/helpers/d-icon";+import dDragAndDropAutoScroll from "discourse/ui-kit/modifiers/d-drag-and-drop-auto-scroll";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";import { i18n } from "discourse-i18n";-import { autoScrollSpeedForPointer } from "../lib/boards-auto-scroll";import { isRecencyColumn } from "../lib/boards-card-ordering";import {columnColorVariable,@@ -55,17 +56,6 @@ export default class BoardsColumn extends Component {@tracked showAllCards = false;- autoScrollFrame = null;- autoScrollSpeed = 0;- autoScrollContainer = null;- autoScrollHasDocumentListeners = false;- stopAutoScroll = () => this.#stopAutoScroll();-- willDestroy() {- super.willDestroy(...arguments);- this.#stopAutoScroll();- }-get cardCount() {return this.args.column.cards?.length || 0;}@@ -170,30 +160,30 @@ export default class BoardsColumn extends Component {}@action- dragOver(event) {- event.preventDefault();+ canDropCard({ source }) {+ // Recency columns sort themselves, so reordering within one is meaningless.+ return !(+ this.isRecencySorted && source.data.fromColumnId === this.args.column.id+ );+ }++ @action+ dragOver({ element, location }) {const dragData = this.args.dragData;if (!dragData) {- this.#stopAutoScroll();return;}- event.currentTarget.classList.add("discourse-boards-column--drag-target");+ element.classList.add("discourse-boards-column--drag-target");- const cardsContainer = event.currentTarget.querySelector(+ const cardsContainer = element.querySelector(".discourse-boards-column__cards");if (!cardsContainer) {- this.#stopAutoScroll();return;}- this.#updateAutoScroll(cardsContainer, event.clientY);-- if (this.isRecencySorted && dragData.fromColumnId === this.args.column.id) {- this.removeDropIndicator(event.currentTarget, { animate: true });- return;- }+ const { clientY } = location.current.input;let indicator = cardsContainer.querySelector(".discourse-boards-column__drop-indicator"@@ -223,7 +213,7 @@ export default class BoardsColumn extends Component {continue;}const rect = cardEl.getBoundingClientRect();- if (event.clientY <= rect.top + rect.height / 2) {+ if (clientY <= rect.top + rect.height / 2) {insertBefore = cardEl;break;}@@ -276,39 +266,25 @@ export default class BoardsColumn extends Component {}@action- dragLeave(event) {- event.preventDefault();- if (!event.currentTarget.contains(event.relatedTarget)) {- event.currentTarget.classList.remove(- "discourse-boards-column--drag-target"- );- this.removeDropIndicator(event.currentTarget, { animate: true });- this.#stopAutoScroll();- }+ dragLeave({ element }) {+ element.classList.remove("discourse-boards-column--drag-target");+ this.removeDropIndicator(element, { animate: true });}@action- drop(event) {- event.preventDefault();- event.currentTarget.classList.remove(- "discourse-boards-column--drag-target"- );- this.#stopAutoScroll();+ drop({ element, location }) {+ element.classList.remove("discourse-boards-column--drag-target");const dragData = this.args.dragData;if (!dragData) {- this.removeDropIndicator(event.currentTarget, { animate: false });+ this.removeDropIndicator(element, { animate: false });return;}- if (this.isRecencySorted && dragData.fromColumnId === this.args.column.id) {- this.removeDropIndicator(event.currentTarget, { animate: false });- return;- }-- const cardsContainer = event.currentTarget.querySelector(+ const cardsContainer = element.querySelector(".discourse-boards-column__cards");+ const { clientY } = location.current.input;let afterCardId = null;if (cardsContainer && !this.isRecencySorted) {@@ -321,14 +297,13 @@ export default class BoardsColumn extends Component {continue;}const rect = cardEl.getBoundingClientRect();- if (event.clientY > rect.top + rect.height / 2) {+ if (clientY > rect.top + rect.height / 2) {afterCardId = elCardId;}}}- this.removeDropIndicator(event.currentTarget, { animate: false });-+ // The board viewer removes the placeholder once the move settles.this.args.onDrop(dragData.cardId,this.args.column.id,@@ -374,88 +349,6 @@ export default class BoardsColumn extends Component {}}- #updateAutoScroll(cardsContainer, clientY) {- const speed = autoScrollSpeedForPointer(- clientY,- cardsContainer.getBoundingClientRect()- );-- if (- (speed < 0 && cardsContainer.scrollTop <= 0) ||- (speed > 0 &&- cardsContainer.scrollTop + cardsContainer.clientHeight >=- cardsContainer.scrollHeight)- ) {- this.#stopAutoScroll();- return;- }-- this.autoScrollSpeed = speed;- this.autoScrollContainer = cardsContainer;- this.#ensureAutoScrollDocumentListeners();-- if (speed === 0) {- this.#stopAutoScroll();- return;- }-- if (!this.autoScrollFrame) {- this.#autoScroll();- }- }-- #autoScroll() {- this.autoScrollFrame = requestAnimationFrame(() => {- this.autoScrollFrame = null;-- const container = this.autoScrollContainer;- if (!container || this.autoScrollSpeed === 0) {- return;- }-- const previousScrollTop = container.scrollTop;- container.scrollTop += this.autoScrollSpeed;-- if (container.scrollTop === previousScrollTop) {- this.#stopAutoScroll();- return;- }-- this.#autoScroll();- });- }-- #ensureAutoScrollDocumentListeners() {- if (this.autoScrollHasDocumentListeners) {- return;- }-- document.addEventListener("dragend", this.stopAutoScroll, true);- document.addEventListener("drop", this.stopAutoScroll, true);- this.autoScrollHasDocumentListeners = true;- }-- #removeAutoScrollDocumentListeners() {- if (!this.autoScrollHasDocumentListeners) {- return;- }-- document.removeEventListener("dragend", this.stopAutoScroll, true);- document.removeEventListener("drop", this.stopAutoScroll, true);- this.autoScrollHasDocumentListeners = false;- }-- #stopAutoScroll() {- if (this.autoScrollFrame) {- cancelAnimationFrame(this.autoScrollFrame);- this.autoScrollFrame = null;- }-- this.autoScrollSpeed = 0;- this.autoScrollContainer = null;- this.#removeAutoScrollDocumentListeners();- }-#indicatorMatchesPosition(cardsContainer, indicator, insertBefore) {if (indicator.parentElement !== cardsContainer) {return false;@@ -478,9 +371,15 @@ export default class BoardsColumn extends Component {data-column-id={{@column.id}}data-default-sort={{@column.default_sort}}style={{columnColorVariable @column.color}}- {{on "dragover" this.dragOver}}- {{on "dragleave" this.dragLeave}}- {{on "drop" this.drop}}+ {{dDragAndDropTarget+ accepts="boards-card"+ canDrop=this.canDropCard+ indicator=false+ onDrag=this.dragOver+ onDragEnter=this.dragOver+ onDragLeave=this.dragLeave+ onDrop=this.drop+ }}><div class="discourse-boards-column__header"><span class="discourse-boards-column__header-content">@@ -550,7 +449,10 @@ export default class BoardsColumn extends Component {{{/if}}</div>- <div class="discourse-boards-column__cards">+ <div+ class="discourse-boards-column__cards"+ {{dDragAndDropAutoScroll types="boards-card"}}+ >{{#if this.visibleCards.length}}{{#each this.visibleCards key="id" as |card|}}<BoardsCard@@ -563,6 +465,7 @@ export default class BoardsColumn extends Component {@columnTitle={{@column.fancyTitle}}@isDropHighlighted={{eq @dropHighlightCardId card.id}}@isLinkHighlighted={{eq @linkHighlightCardId card.id}}+ @isPendingDrop={{eq @pendingDropCardId card.id}}@onDeleteCard={{@onDeleteCard}}@onDragEnd={{@onDragEnd}}@onDragStart={{@onDragStart}}diff --git a/plugins/boards/assets/javascripts/discourse/lib/boards-auto-scroll.js b/plugins/boards/assets/javascripts/discourse/lib/boards-auto-scroll.jsindex e87a2deb4d1..c98cf6c5dd8 100644--- a/plugins/boards/assets/javascripts/discourse/lib/boards-auto-scroll.js+++ b/plugins/boards/assets/javascripts/discourse/lib/boards-auto-scroll.js@@ -1,37 +1,5 @@import { modifier } from "ember-modifier";-const AUTO_SCROLL_EDGE_SIZE = 72;-const AUTO_SCROLL_MAX_SPEED = 10;--export function autoScrollSpeedForPointer(pointerPosition, rect, axis = "y") {- if (!rect) {- return 0;- }-- const startEdge = axis === "x" ? rect.left : rect.top;- const endEdge = axis === "x" ? rect.right : rect.bottom;-- const startDistance = pointerPosition - startEdge;- if (startDistance < AUTO_SCROLL_EDGE_SIZE) {- return -Math.ceil(- ((AUTO_SCROLL_EDGE_SIZE - Math.max(startDistance, 0)) /- AUTO_SCROLL_EDGE_SIZE) *- AUTO_SCROLL_MAX_SPEED- );- }-- const endDistance = endEdge - pointerPosition;- if (endDistance < AUTO_SCROLL_EDGE_SIZE) {- return Math.ceil(- ((AUTO_SCROLL_EDGE_SIZE - Math.max(endDistance, 0)) /- AUTO_SCROLL_EDGE_SIZE) *- AUTO_SCROLL_MAX_SPEED- );- }-- return 0;-}-const DRAG_SCROLL_SKIP_SELECTOR =".discourse-boards-card, button, a, input, textarea, select, [contenteditable=''], [contenteditable='true']";diff --git a/plugins/boards/assets/stylesheets/boards-board.scss b/plugins/boards/assets/stylesheets/boards-board.scssindex 318ecee5a7a..0670ecaeeeb 100644--- a/plugins/boards/assets/stylesheets/boards-board.scss+++ b/plugins/boards/assets/stylesheets/boards-board.scss@@ -502,7 +502,13 @@ body.discourse-boards-fullscreen .fk-d-menu[data-identifier^="boards-"] {border-left: 2px solid var(--discourse-boards-column-color);}- &[draggable="false"] {+ // iOS turns a long press on text into a selection instead of a drag+ &[data-drag-source] {+ -webkit-touch-callout: none;+ user-select: none;+ }++ &:not([data-drag-source]) {cursor: not-allowed;}@@ -716,17 +722,6 @@ body.discourse-boards-fullscreen .fk-d-menu[data-identifier^="boards-"] {}}-.discourse-boards-card--drag-image {- position: fixed;- box-sizing: border-box;- top: -9999px;- left: -9999px;- margin: 0;- pointer-events: none;- box-shadow: var(--shadow-card);- cursor: grabbing;-}-@keyframes discourse-boards-card-drop-highlight {0% {border-color: var(--discourse-boards-column-color, var(--primary-500));diff --git a/plugins/boards/spec/system/boards_board_viewer_spec.rb b/plugins/boards/spec/system/boards_board_viewer_spec.rbindex 9706eb71390..2c2ba33c712 100644--- a/plugins/boards/spec/system/boards_board_viewer_spec.rb+++ b/plugins/boards/spec/system/boards_board_viewer_spec.rb@@ -252,7 +252,7 @@ describe "Boards Board Viewer" doboard_viewer.visit_board(board)expect(board_viewer).to have_card_in_column("To Do", "Read only topic")- expect(board_viewer.card_draggable?("Read only topic")).to eq(false)+ expect(board_viewer).to have_no_draggable_card("Read only topic")endend@@ -728,7 +728,7 @@ describe "Boards Board Viewer" do"/boards/archive-roundtrip-archived-#{Time.zone.today.strftime("%Y%m%d")}/#{board.id}",)expect(board_viewer).to have_no_add_card_button_in_column("To Do")- expect(page).to have_css("[data-card-id='#{card.id}'][draggable='false']")+ expect(page).to have_css("[data-card-id='#{card.id}']:not([data-drag-source])")board_viewer.open_controls_menuexpect(board_viewer).to have_no_board_settings_option@@ -741,7 +741,7 @@ describe "Boards Board Viewer" doexpect(page).to have_no_css(".discourse-boards-archive-modal")expect(page).to have_current_path("/boards/archive-roundtrip/#{board.id}")expect(board_viewer).to have_add_card_button_in_column("To Do")- expect(page).to have_css("[data-card-id='#{card.id}'][draggable='true']")+ expect(page).to have_css("[data-card-id='#{card.id}'][data-drag-source]")endenddiff --git a/plugins/boards/spec/system/page_objects/pages/boards_board_viewer.rb b/plugins/boards/spec/system/page_objects/pages/boards_board_viewer.rbindex 5c8aab7404d..7c471db7909 100644--- a/plugins/boards/spec/system/page_objects/pages/boards_board_viewer.rb+++ b/plugins/boards/spec/system/page_objects/pages/boards_board_viewer.rb@@ -40,10 +40,15 @@ module PageObjectsenddef drag_card_to_column(card_title, target_column_title)- find(".discourse-boards-card", text: card_title).drag_to(- find(".discourse-boards-column", text: /#{Regexp.escape(target_column_title)}/i),- html5: true,- delay: 0.4,+ card = find(".discourse-boards-card[data-drag-source]", text: card_title)+ column =+ find(+ ".discourse-boards-column[data-drop-target]",+ text: /#{Regexp.escape(target_column_title)}/i,+ )+ drag_and_drop(+ source: ".discourse-boards-card[data-card-id='#{card["data-card-id"]}']",+ target: ".discourse-boards-column[data-column-id='#{column["data-column-id"]}']",)selfend@@ -52,8 +57,12 @@ module PageObjectshas_css?(".discourse-boards-board-viewer__title", text: title)end- def card_draggable?(card_title)- find(".discourse-boards-card", text: card_title)["draggable"] == "true"+ def has_draggable_card?(card_title)+ has_css?(".discourse-boards-card[data-drag-source]", text: card_title)+ end++ def has_no_draggable_card?(card_title)+ has_css?(".discourse-boards-card:not([data-drag-source])", text: card_title)enddef has_tag_on_card?(card_title, tag_name)diff --git a/plugins/boards/test/javascripts/components/boards-board-viewer-test.gjs b/plugins/boards/test/javascripts/components/boards-board-viewer-test.gjsindex 44407928b94..cce31042adf 100644--- a/plugins/boards/test/javascripts/components/boards-board-viewer-test.gjs+++ b/plugins/boards/test/javascripts/components/boards-board-viewer-test.gjs@@ -8,6 +8,12 @@ import pretender, {parsePostData,response,} from "discourse/tests/helpers/create-pretender";+import {+ centerOf,+ dragEvent,+ dragOver,+ startDrag,+} from "discourse/tests/helpers/ui-kit/drag-and-drop-helper";import BoardsBoardViewer from "discourse/plugins/boards/discourse/components/boards-board-viewer";import BoardsFabricators from "discourse/plugins/boards/discourse/lib/fabricators";@@ -31,18 +37,6 @@ function recentISO(daysAgo) {return new Date(Date.now() - daysAgo * 24 * 60 * 60 * 1000).toISOString();}-function stubCardRect(cardId, { top = 0, height = 48 } = {}) {- const card = document.querySelector(cardSelector(cardId));- sinon.stub(card, "getBoundingClientRect").returns({- top,- bottom: top + height,- left: 0,- right: 200,- width: 200,- height,- });-}-module("Integration | Component | BoardsBoardViewer", function (hooks) {setupRenderingTest(hooks);@@ -97,20 +91,23 @@ module("Integration | Component | BoardsBoardViewer", function (hooks) {this.dragDataTransfer = null;this.dragCard = async (cardId) => {this.dragDataTransfer = new DataTransfer();- stubCardRect(cardId);-- await triggerEvent(cardSelector(cardId), "dragstart", {- clientX: 10,- clientY: 10,+ await startDrag(cardSelector(cardId), {dataTransfer: this.dragDataTransfer,});};- this.dropOnColumn = async (columnId, { clientY = 0 } = {}) => {- await triggerEvent(columnSelector(columnId), "drop", {- clientY,- dataTransfer: this.dragDataTransfer,+ this.dropOnColumn = async (columnId, { clientY } = {}) => {+ const target = columnSelector(columnId);+ const coordinates = clientY === undefined ? {} : { clientY };+ const dataTransfer = this.dragDataTransfer;++ await dragOver(target, { dataTransfer, coordinates });+ await dragEvent(target, "drop", {+ dataTransfer,+ ...centerOf(target),+ ...coordinates,});+ await settled();};});@@ -183,9 +180,12 @@ module("Integration | Component | BoardsBoardViewer", function (hooks) {});});- stubCardRect(102, { top: 0, height: 48 });await this.dragCard(101);- await this.dropOnColumn(20, { clientY: 30 });+ // Below the target card's midpoint, so the drop lands after it.+ const targetRect = document+ .querySelector(cardSelector(102))+ .getBoundingClientRect();+ await this.dropOnColumn(20, { clientY: targetRect.bottom - 2 });assert.strictEqual(requestData.card.column_id, "20");assert.strictEqual(requestData.card.after_card_id, "102");@@ -280,6 +280,15 @@ module("Integration | Component | BoardsBoardViewer", function (hooks) {boardTagNames: [],boardCategoryIds: [3],});+ assert+ .dom(`${columnSelector(10)} ${cardSelector(101)}`)+ .hasClass(+ "discourse-boards-card--dragging",+ "the card stays hidden in its old slot while the move is pending"+ );+ assert+ .dom(`${columnSelector(20)} .discourse-boards-column__drop-indicator`)+ .exists("the placeholder stays where the card was dropped");opts.model.onConfirm({ category_id: 3 });});@@ -313,6 +322,15 @@ module("Integration | Component | BoardsBoardViewer", function (hooks) {await this.dropOnColumn(20);assert.strictEqual(moveRequestData.constraint_fix.category_id, "3");+ assert+ .dom(`${columnSelector(20)} ${cardSelector(101)}`)+ .doesNotHaveClass(+ "discourse-boards-card--dragging",+ "the moved card is visible in its new column"+ );+ assert+ .dom(".discourse-boards-column__drop-indicator")+ .doesNotExist("the placeholder is cleared once the move lands");});test("renders and highlights an old linked card in a recency column", async function (assert) {@@ -721,7 +739,10 @@ module("Integration | Component | BoardsBoardViewer", function (hooks) {);assert.dom(cardSelector(101))- .hasAttribute("draggable", "false", "archived cards cannot be dragged");+ .doesNotHaveAttribute(+ "data-drag-source",+ "archived cards cannot be dragged"+ );assert.true(this.messageBus.subscribe.calledWith("/boards/1"),"archived boards stay subscribed to receive unarchive events"diff --git a/plugins/boards/test/javascripts/unit/components/boards-drop-test.js b/plugins/boards/test/javascripts/unit/components/boards-drop-test.jsindex 8093b5f0e33..d628897a7bf 100644--- a/plugins/boards/test/javascripts/unit/components/boards-drop-test.js+++ b/plugins/boards/test/javascripts/unit/components/boards-drop-test.js@@ -6,7 +6,6 @@ import {recencyDropIndicatorInsertBefore,shouldAnimateDropIndicatorPlacement,} from "discourse/plugins/boards/discourse/components/boards-column";-import { autoScrollSpeedForPointer } from "discourse/plugins/boards/discourse/lib/boards-auto-scroll";function createDropTarget() {const column = document.createElement("div");@@ -105,34 +104,6 @@ module("Boards | Unit | Components | boards drop", function (hooks) {);});- test("column drag auto-scroll speed follows pointer edge proximity", function (assert) {- const verticalRect = { top: 100, bottom: 500 };- const horizontalRect = { left: 100, right: 500 };-- assert.strictEqual(- autoScrollSpeedForPointer(300, verticalRect),- 0,- "it does not scroll away from the column edges"- );- assert.true(- autoScrollSpeedForPointer(110, verticalRect) < 0,- "it scrolls up near the top edge"- );- assert.true(- autoScrollSpeedForPointer(490, verticalRect) > 0,- "it scrolls down near the bottom edge"- );- assert.true(- Math.abs(autoScrollSpeedForPointer(100, verticalRect)) >- Math.abs(autoScrollSpeedForPointer(150, verticalRect)),- "it scrolls faster closer to the edge"- );- assert.true(- autoScrollSpeedForPointer(490, horizontalRect, "x") > 0,- "it supports horizontal scrolling near the right edge"- );- });-test("moved topic cards without existing topic data require a board refetch", function (assert) {assert.true(shouldRefetchMovedCardPayload(null, {