A platform for community discussion. Free, open, simple.
DEV: Document and demonstrate gesture primitives (#42601)
Sérgio Saquetimcec79c60b354
diff --git a/docs/developer-guides/docs/03-code-internals/29-drag-and-gesture-primitives.md b/docs/developer-guides/docs/03-code-internals/29-drag-and-gesture-primitives.mdnew file mode 100644index 00000000000..1993132706b--- /dev/null+++ b/docs/developer-guides/docs/03-code-internals/29-drag-and-gesture-primitives.md@@ -0,0 +1,503 @@+---+title: Drag, resize, and gesture primitives+short_title: Gesture primitives+id: drag-and-gesture-primitives+---++<div data-theme-toc="true"> </div>++`ui-kit` ships the input-driven gesture primitives: dragging a payload onto a+target, resizing a region, and reading a swipe or a pointer drag. This page is+the usage reference. Each primitive's own TSDoc carries the fine print for every+argument; what follows is how to put them together.++# Basic usage++A drag needs a source that carries a payload and a target that accepts its type.++```gjs+import { hash } from "@ember/helper";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";++<template>+ <div {{dDragAndDropSource type="card" data=(hash [email protected])}}>+ {{@card.title}}+ </div>++ <div {{dDragAndDropTarget accepts="card" onDrop=@onDrop}}>+ Drop a card here+ </div>+</template>+```++```js+@action+onDrop({ source, position }) {+ // source.data is what the source attached; position is "before" or "after"+ this.file(source.data.id, position);+}+```++The `type` string is the whole matching vocabulary. A target engages only for+sources whose `type` is in its `accepts`, and everything else drags straight+over it.++# Picking a primitive++| I want to… | Use |+| -------------------------------------------------------------- | ------------------------------------------- |+| Move something onto a target and transfer a payload | `dDragAndDropSource` + `dDragAndDropTarget` |+| Take page content the browser started dragging, with no source | `dDragAndDropTarget` with `adopts` |+| Take files, HTML, URLs, or text from outside the window | `dDragAndDropExternalTarget` |+| Upload the files somebody dropped | the upload pipeline, not the modifier above |+| React to a drag without becoming a drop target | `dDragAndDropMonitor` |+| Scroll a container while a drag hovers near its edge | `dDragAndDropAutoScroll` |+| Render from the in-flight drag | the `dragAndDrop` service |+| Press, move, and track a value continuously | `dPointerDrag` |+| Put an accessible handle between two regions | `DResizeSeparator` |+| Resize on one axis with your own element and semantics | `dResizeEdge` |+| Resize a box from its edges and corners | `DResizeHandles` |+| Detect a directional flick | `dSwipe` |+| Know that an element changed size | `dOnResize`, which is not a gesture |++# dDragAndDropSource++Marks an element draggable and attaches the payload.++## Arguments++| Argument | Type | Purpose |+| ------------------- | ------------------------------- | -------------------------------------------------------------------------- |+| `type` | `string`, required | The discriminator targets filter on. Overwrites any `type` in the payload. |+| `data` | `object` | Static payload, read back as `source.data`. |+| `getInitialData` | `() => object` | Dynamic payload, called once just before `dragstart`. |+| `dragPreview` | `Element` or render function | What the drag image shows. Defaults to the source element. |+| `dragPreviewOffset` | `{x: string, y: string}` | CSS lengths pushing a rendered preview clear of the pointer. |+| `effectAllowed` | `DataTransfer["effectAllowed"]` | What the drag permits. Defaults to `"move"`. |+| `dragHandle` | `Element` | An element inside this one that a drag must start from. |+| `disabled` | `boolean` | Detaches the registration. A drag in flight still finishes. |+| `canDrag` | `(feedback) => boolean` | Returning `false` blocks the drag from starting. |+| `onDragStart` | `(event) => void` | Fires once the drag is confirmed. |+| `onDragEnd` | `(event) => void` | Fires at the end of every drag, landed or abandoned. |+| `onDrop` | `(event) => void` | Fires only for a drag that ended on a target. |++The element carries `data-drag-source` while registered and `--dragging` for the+duration of the drag. Style and assert against those, never against+`draggable`: that attribute sits on whichever element was registered, which is+the handle when there is one.++## Dragging by a handle++Without a handle the whole element starts a drag, so text inside it cannot be+selected and a touch press meant to scroll starts a drag instead. Pass the+handle element itself, captured with a modifier, not a selector.++```gjs+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { modifier } from "ember-modifier";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";++export default class Row extends Component {+ @tracked gripElement;++ captureGrip = modifier((element) => {+ this.gripElement = element;+ return () => (this.gripElement = undefined);+ });++ <template>+ <li {{dDragAndDropSource type="row" dragHandle=this.gripElement}}>+ <span {{this.captureGrip}} aria-hidden="true"></span>+ {{@item.label}}+ </li>+ </template>+}+```++The row stays the drag body: it keeps `data-drag-source`, it is what a target+reports as `source.element`, and it is what the default preview photographs.++## Custom previews++An `Element` preview is photographed in place. A render function mounts a fresh+preview into an isolated offscreen container, so nothing around the source+bleeds into the drag image, and may return a cleanup function.++```js+dragPreview = ({ container, element }) => {+ const node = element.cloneNode(true);+ container.append(node);+ return () => node.remove();+};+```++# dDragAndDropTarget++Accepts element drags and reports where the drop would land.++## Arguments++| Argument | Type | Purpose |+| --------------- | -------------------------------------------- | ------------------------------------------------------------- |+| `accepts` | `string \| string[]` | Which source types engage the target. Omit to accept any. |+| `adopts` | `NativeDragAdoption \| NativeDragAdoption[]` | Also take browser-started page content. See below. |+| `acceptsSelf` | `boolean` | `false` refuses a drop whose dragged element is this element. |+| `position` | `"before" \| "after" \| "inside"` | A fixed position, which wins over midpoint math. |+| `axis` | `"vertical" \| "horizontal"` | Which midpoint is measured. Defaults to `"vertical"`. |+| `indicator` | `boolean` | `false` suppresses the indicator class. |+| `canDrop` | `(feedback) => boolean` | Gate asked while hovering. `false` defers to an ancestor. |+| `getDropEffect` | `(feedback) => DropEffect` | The cursor feedback the browser shows. |+| `getData` | `() => object` | Metadata attached to the drag's record of this target. |+| `getIsSticky` | `() => boolean` | Whether the target stays current after the pointer leaves. |+| `onDragEnter` | `(event) => void` | This target became the deepest accepted target. |+| `onDrag` | `(event) => void` | Throttled, while it stays the deepest accepted target. |+| `onDragLeave` | `(event) => void` | It stopped being the deepest accepted target. |+| `onDrop` | `(event) => void` | The drag was released here. |++A registered target carries `data-drop-target`.++## Positions and indicator classes++A target resolves `before`, `after` or `inside` and paints one class while a+compatible drag is over it:++| Position | Vertical axis | Horizontal axis |+| -------- | --------------- | --------------- |+| `before` | `--drag-above` | `--drag-left` |+| `after` | `--drag-below` | `--drag-right` |+| `inside` | `--drag-inside` | `--drag-inside` |++Positions are logical, not physical. In a right-to-left row, `before` still+means the reading-order start, and the class flips to `--drag-right` so the+indicator stays under the pointer. Consumers need no special case.++## Nesting++Only the deepest accepted target receives lifecycle callbacks, so nested targets+never handle one drop twice. The cost is that an ancestor stops indicating the+moment a descendant claims the drag. When a container has to stay highlighted+while its descendants activate in turn, render from the service instead and+leave drop handling to the descendants.++A descendant that answers `false` from `canDrop` is not accepted, so the drop+falls through to the nearest ancestor that does accept it. That is how a target+hands back a region it does not own, such as an edge band that belongs to the+enclosing container. Eligibility is sampled while the drag hovers and is not+asked again at the release, so the answer a target last gave is the one that+counts.++## Adopting browser-started drags++The browser starts drags on ordinary page content, such as a link or an image,+which registers no source and could not. An adoption lets a target take those+too. It names the kind of drag and supplies a predicate:++```js+export const WEB_LINK = {+ type: "web-link",+ match: ({ element }) => Boolean(element.closest("a[href]")),+};+```++```gjs+<div {{dDragAndDropTarget adopts=WEB_LINK onDrop=this.addLink}}></div>+```++From there it is an ordinary drag: the same callbacks, the same positions, the+same indicator. The adoption's `type` becomes `source.type`, so a monitor or+auto-scroll filters on it like any other type, and the native payload arrives on+`source.native` with the same reader API an external target hands you. Its+`items` list is always empty, because the handles go inert when `dragstart` ends.++Three rules are not guessable from the signature:++- **Adoption is resolved once for the page, not per target.** At `dragstart` the+ first live adoption whose predicate matches names the drag, and every target+ listing that name accepts it. Two adoptions sharing a name must therefore share+ a predicate. Declare one as a module constant and offer it from each target.+- **`adopts` without `accepts` refuses every registered source.** A target that+ named what it wants through `adopts` is not also asking for everything else on+ the page.+- **It covers only what the browser started on this page.** To take the same+ content dragged in from outside the window, pair the target with+ `dDragAndDropExternalTarget` on the same element.++Adoption deliberately leaves several drags alone: a registered source keeps its+own lifecycle, an element somebody else made draggable keeps its own drag, files+go to an external target, and a text selection is never adopted, including one+held inside an `input` or `textarea`. A predicate that throws is reported and+refuses, rather than deciding for the adoptions after it.++# dDragAndDropExternalTarget++Accepts payloads dragged in from another window or another application. It never+sees a drag that began on this page.++## Arguments++| Argument | Type | Purpose |+| ---------- | ------------------------------------------------ | -------------------------------------------------- |+| `accepts` | `"files" \| "html" \| "text" \| "urls"` or array | Which kinds engage the target. Omit to accept any. |+| `position` | `"before" \| "after" \| "inside"` | Opts into resolving a position at all. |+| `axis` | `"vertical" \| "horizontal"` | Same, from the pointer against the midpoint. |++It shares every kernel argument with the element target: `canDrop`,+`getDropEffect`, `getData`, `getIsSticky`, `indicator`, and the four lifecycle+callbacks.++Without `position` or `axis` the target is one destination rather than a slot:+callbacks receive `position: null` and the indicator is the single+`--drag-over-external` class. A registered external target carries+`data-drop-target-external`.++```gjs+<div+ {{dDragAndDropExternalTarget+ accepts=(array "urls" "text")+ onDrop=this.acceptLink+ }}+></div>+```++The payload exposes `types`, `containsFiles()`, `getFiles()`, `containsHTML()`,+`getHTML()`, `containsText()`, `getText()`, `containsURLs()` and `getURLs()`.+`items` and `getFiles()` are only populated at the drop.++**This is not the upload path.** A file dropped here does not enter upload+validation, progress, retries, or the upload record. Reach for it only when the+consumer genuinely wants the raw payload.++# dDragAndDropMonitor++Reacts to an element drag happening anywhere, without becoming a drop target.++| Argument | Type | Purpose |+| ------------- | -------------------- | --------------------------------------------- |+| `types` | `string \| string[]` | Which drag types to watch. Omit to watch all. |+| `onDragStart` | `(event) => void` | A watched drag began. |+| `onDrag` | `(event) => void` | Throttled, while it is in flight. |+| `onDrop` | `(event) => void` | It was released. |++The element only anchors the modifier's lifecycle; a monitor is global.++# dDragAndDropAutoScroll++Scrolls a container while a drag hovers near its edge.++| Argument | Type | Purpose |+| --------- | ------------------------------------------------ | ---------------------------------- |+| `types` | `string \| string[]` | Element drag types that engage it. |+| `accepts` | `"files" \| "html" \| "text" \| "urls"` or array | External kinds that engage it. |+| `axis` | `"vertical" \| "horizontal" \| "all"` | Which direction to scroll. |+| `target` | `"element" \| "window"` | Scroll this element or the window. |++Element drags and external drags arrive through different adapters, so a surface+that takes both names both: `types` for the element side, `accepts` for the+external side.++# The dragAndDrop service++The service holds the in-flight drag as tracked state, so a surface can render+from it without wiring a callback.++| Member | Purpose |+| ------------------------ | ------------------------------------------------- |+| `currentDrag` | The in-flight element drag, or `null`. |+| `currentExternalDrag` | The in-flight external drag, or `null`. |+| `isDragging` | Whether either is in flight. |+| `accepts(types)` | Whether the element drag's type is in `types`. |+| `acceptsExternal(kinds)` | Whether the external drag carries one of `kinds`. |++`currentDrag` carries `type`, `data`, `element`, and `native` for an adopted+drag.++```gjs+<div class={{if (this.dragAndDrop.accepts "row") "is-drop-zone"}}></div>+```++Use the service to read and the monitor to respond. Rendering from monitor+callbacks means keeping state the service already owns.++Note that `accepts()` and `acceptsExternal()` treat an empty or missing filter+as matching nothing, because a caller that has not decided should not light up+for every drag. A target's `accepts` reads the other way: omitting it accepts+everything.++# dPointerDrag++Press, move, and release on one element, for a value that tracks the pointer.+It transfers nothing and has no targets.++| Argument | Type | Purpose |+| ----------------- | ---------------------------------- | ------------------------------------------------ |+| `onDragStart` | `(event, info) => boolean \| void` | The gesture began. Returning `false` refuses it. |+| `onDrag` | `(event, info) => void` | The pointer moved. |+| `onDragEnd` | `(event, info) => void` | The gesture finished. |+| `onDragCancel` | `(event, info) => void` | It was interrupted rather than finished. |+| `threshold` | `number` | Pixels of movement before the gesture starts. |+| `draggingClass` | `string` | Class applied to the element while dragging. |+| `bodyClass` | `string` | Class applied to `document.body` while dragging. |+| `cancelCommits` | `boolean` | Whether a cancel commits the last value. |+| `stopPropagation` | `boolean` | Whether to stop the pointer events propagating. |+| `touchAction` | `TouchActionToken` | The `touch-action` to apply for the gesture. |++Always handle `onDragCancel`. A gesture interrupted by the browser otherwise+leaves whatever `onDragStart` opened still open.++# DResizeSeparator++The default for resizing between two regions. `dResizeEdge` underneath keeps the+value math, the bounds and the keyboard operation; the separator adds the+accessibility contract on top: `role="separator"`, one tab stop, an+`aria-orientation`, and live `aria-valuenow` updates.++| Argument | Type | Purpose |+| --------------- | ------------------------------------- | ------------------------------------------------------------------------- |+| `label` | `string`, required | What the separator is called, already translated. |+| `axis` | `"vertical" \| "horizontal"` | `"vertical"` resizes height. Defaults to `"vertical"`. |+| `side` | `"start" \| "end"` | The edge the handle sits on, naming the edge opposite the one that moves. |+| `measure` | `Element` or `(separator) => Element` | The box being resized. Given this, it measures itself. |+| `value` | `number` or `() => number` | The current size, when it is not the measured extent. |+| `min` / `max` | `number` or `() => number` | Bounds. Override the measurement. |+| `onResizeStart` | `() => void` | The gesture began. |+| `onResize` | `(size) => void` | Throughout the gesture. Preview here. |+| `onResizeEnd` | `(size) => void` | Once at the end. Commit here. |++`label` is required because a focusable `role="separator"` with no accessible+name is announced as a bare "splitter", which says nothing about what it+resizes.++```gjs+<DResizeSeparator+ @label={{i18n "sidebar.resize"}}+ @measure={{this.panelElement}}+ @onResizeEnd={{this.persistWidth}}+ @axis="horizontal"+/>+```++`onResizeEnd` also fires if the separator is destroyed mid-gesture, so anything+opened at the start still gets closed.++# dResizeEdge++The modifier underneath `DResizeSeparator`. Use it directly only when the+element and its separator semantics are already yours to provide.++| Argument | Type | Purpose |+| --------------- | ---------------------------------------- | ------------------------------------------------ |+| `value` | `number \| null` or a function, required | The current size. |+| `min` / `max` | `number` or a function, required | Bounds. |+| `axis` | `"vertical" \| "horizontal"` | Which dimension is resized. |+| `side` | `"start" \| "end"` | Which edge the handle sits on. |+| `bodyClass` | `string` | Class applied to `document.body` while resizing. |+| `onResizeStart` | `() => void` | The gesture began. |+| `onResize` | `(size, meta) => void` | Throughout the gesture. |+| `onResizeEnd` | `(size, meta) => void` | Once at the end. |++# DResizeHandles++Renders the edges and corners of a two-dimensional box resize and reports+pointer geometry for the consumer to interpret.++| Argument | Type | Purpose |+| --------------------------------------------------------------- | ----------------------------- | -------------------------------------------------------------- |+| `directions` | `BoxDirection[]` | Which of `n`, `ne`, `e`, `se`, `s`, `sw`, `w`, `nw` to render. |+| `handles` | `DResizeHandleDescriptor[]` | Explicit handle descriptors with their payloads. |+| `handleClass` / `draggingClass` | `string` | Classes for the handles and the active gesture. |+| `measure` | `MeasureTarget` | The box the geometry is measured against. |+| `threshold` | `number` | Pixels of movement before a gesture starts. |+| `cancelCommits` | `boolean` | Whether a cancel commits the last value. |+| `stopPropagation` | `boolean` | Whether to stop the pointer events propagating. |+| `onResizeStart` / `onResize` / `onResizeEnd` / `onResizeCancel` | `(payload, dragInfo) => void` | The gesture lifecycle. |++```js+@action+onResize(direction, { delta }) {+ if (direction.includes("e")) {+ this.width = Math.max(MIN, this.startWidth + delta.x);+ }+ if (direction.includes("s")) {+ this.height = Math.max(MIN, this.startHeight + delta.y);+ }+}+```++Do not give a two-dimensional box resize `role="separator"`. It has no single+`aria-valuenow` to report, so the role would describe a control that does not+exist.++# dSwipe++Reports a discrete directional flick with velocity, for touch surfaces that open+or dismiss something.++| Argument | Type | Purpose |+| ------------------ | ------------------------ | ----------------------------------------- |+| `onDidStartSwipe` | `(state, event) => void` | The gesture began. |+| `onDidSwipe` | `(state) => void` | It progressed. |+| `onDidEndSwipe` | `(state) => void` | It completed. |+| `onDidCancelSwipe` | `(detail) => void` | It was interrupted. |+| `enabled` | `boolean` | Whether the gesture is active. |+| `lockBody` | `boolean` | Whether to lock body scrolling during it. |++Use `dPointerDrag` instead when a value must track the pointer continuously.+`dSwipe` answers "which way did they flick", not "where is the pointer now".++# dOnResize is not a gesture++`dOnResize` wraps `ResizeObserver`: it reports that an element's size changed,+and nobody resizes anything with it. The similar name is the trap. To let+someone change a size, use one of the resize primitives above.++# Accessibility++**A drag is not a keyboard interaction.** Every reorder surface has to pair the+drag with a keyboard path, and every resize between regions should use the+keyboard support already in `DResizeSeparator` or `dResizeEdge`.++**Announce the outcome, not the movement.** A completed reorder reports the+item's new visible position once through `a11y.announce()`. A no-op announces+nothing, and moving the pointer across drop indicators announces nothing.++**Do not add `aria-dropeffect` or `aria-grabbed`.** Both are deprecated and+neither makes a drag operable.++**A drag handle is decorative and stays outside the tab order,** because a+keyboard cannot operate it. The operable controls are the keyboard path beside+it.++**Keep the two paths' scopes honest.** They may legitimately differ: arrows may+move within one labeled list while a drag crosses between lists. The keyboard+path should follow the list the user is stepping through rather than silently+crossing a semantic boundary.++# Testing++Synthetic mouse events do not drive a native drag; they stall. Use the helpers.++In JavaScript tests, from+`discourse/tests/helpers/ui-kit/drag-and-drop-helper`:++| Helper | Drives |+| --------------------------------------------- | -------------------------------------------- |+| `simulateDrag(source, target, opts)` | A registered source onto a target. |+| `simulateUnsourcedDrag(source, target, opts)` | Browser-started page content onto a target. |+| `simulateExternalDrag(target, opts)` | A payload from outside the window. |+| `externalDragOver` / `dragOver` / `startDrag` | A drag left hovering, without dropping. |+| `dragEvent` / `dragEventNow` | One event, with or without a frame after it. |+| `centerOf` / `textTransfer` / `fileTransfer` | Coordinates and payloads. |++Every synthetic drag event must carry finite `clientX` and `clientY`, which is+what `centerOf` is for.++In system specs, use `SystemHelpers#drag_and_drop`.++# dDraggable is deprecated++`dDraggable` raises `discourse.ui-kit.d-draggable` when instantiated. Use+`dPointerDrag`. It is not a drop-in: rename `didStartDrag`, `dragMove` and+`didEndDrag` to `onDragStart`, `onDrag` and `onDragEnd`, and add `onDragCancel`+so an interrupted gesture still finishes.diff --git a/frontend/discourse/app/ui-kit/modifiers/d-swipe.ts b/frontend/discourse/app/ui-kit/modifiers/d-swipe.tsindex 99101e0bca2..79bb2b4e9cb 100644--- a/frontend/discourse/app/ui-kit/modifiers/d-swipe.ts+++ b/frontend/discourse/app/ui-kit/modifiers/d-swipe.ts@@ -110,6 +110,12 @@ interface DSwipeSignature {* Swipe here* </div>* ```+ *+ * Guide to choosing between the gesture primitives:+ * `docs/developer-guides/docs/03-code-internals/29-drag-and-gesture-primitives.md`+ *+ * @see The `dPointerDrag` modifier for a value that tracks the pointer continuously. This+ * reports a discrete directional flick, not a continuous transform.*/export default class DSwipeModifier extends Modifier<DSwipeSignature> {@service declare site: Site;diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/axis.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/axis.gjsnew file mode 100644index 00000000000..c3ef0918e9c--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/axis.gjs@@ -0,0 +1,50 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++const COLUMNS = ["one", "two", "three"];++export default class AxisExample extends Component {+ @tracked position;++ @action+ onDrop({ position }) {+ this.position = position;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div class="styleguide-drag-and-drop__columns">+ {{#each COLUMNS key="@index" as |column|}}+ <div+ class="styleguide-drag-and-drop__column"+ {{dDragAndDropTarget+ accepts="card"+ axis="horizontal"+ onDrop=this.onDrop+ }}+ >{{column}}</div>+ {{/each}}+ </div>++ <p class="styleguide-example__result">+ {{#if this.position}}+ {{i18n+ "styleguide.sections.drag_and_drop.reported_position"+ position=this.position+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/fixed-position.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/fixed-position.gjsnew file mode 100644index 00000000000..df19efbf9fb--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/fixed-position.gjs@@ -0,0 +1,44 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class FixedPositionExample extends Component {+ @tracked position;++ @action+ onDrop({ position }) {+ this.position = position;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ accepts="card"+ position="before"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.always_before"}}</div>++ <p class="styleguide-example__result">+ {{#if this.position}}+ {{i18n+ "styleguide.sections.drag_and_drop.reported_position"+ position=this.position+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/positions.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/positions.gjsnew file mode 100644index 00000000000..ce54e3825dc--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/positions.gjs@@ -0,0 +1,32 @@+import { concat } from "@ember/helper";+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";+import { i18n } from "discourse-i18n";++/** Every indicator class a target can paint, shown without needing a drag. */+const POSITIONS = [+ { state: "--drag-above", label: "above" },+ { state: "--drag-below", label: "below" },+ { state: "--drag-left", label: "left" },+ { state: "--drag-right", label: "right" },+ { state: "--drag-inside", label: "inside" },+];++export default <template>+ <div class="styleguide-drag-and-drop__swatches">+ {{#each POSITIONS key="state" as |position|}}+ <div class="styleguide-drag-and-drop__swatch">+ <div+ data-drop-target+ class={{dConcatClass "styleguide-drag-and-drop__box" position.state}}+ >+ {{i18n+ (concat+ "styleguide.sections.drag_and_drop.positions." position.label+ )+ }}+ </div>+ <code>{{position.state}}</code>+ </div>+ {{/each}}+ </div>+</template>diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/types.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/types.gjsnew file mode 100644index 00000000000..5b61155dce2--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/basics/types.gjs@@ -0,0 +1,55 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { hash } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class TypesExample extends Component {+ @tracked landed;++ @action+ onDrop({ source }) {+ this.landed = source.data.label;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div class="styleguide-drag-and-drop__chips">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource+ type="card"+ data=(hash label=(i18n "styleguide.sections.drag_and_drop.a_card"))+ }}+ >{{i18n "styleguide.sections.drag_and_drop.a_card"}}</div>++ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource+ type="note"+ data=(hash label=(i18n "styleguide.sections.drag_and_drop.a_note"))+ }}+ >{{i18n "styleguide.sections.drag_and_drop.a_note"}}</div>+ </div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.cards_only"}}</div>++ <p class="styleguide-example__result">+ {{#if this.landed}}+ {{i18n "styleguide.sections.drag_and_drop.landed" label=this.landed}}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/pointer-drag.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/pointer-drag.gjsnew file mode 100644index 00000000000..76d6976bb05--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/pointer-drag.gjs@@ -0,0 +1,47 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { trustHTML } from "@ember/template";+import dPointerDrag from "discourse/ui-kit/modifiers/d-pointer-drag";+import { i18n } from "discourse-i18n";++export default class PointerDragExample extends Component {+ @tracked offset = 0;++ #start = 0;++ get knobStyle() {+ return trustHTML(`transform: translateX(${this.offset}px);`);+ }++ /** Restores what the gesture was previewing; an interrupted drag must not commit. */+ @action+ onDragCancel() {+ this.offset = this.#start;+ }++ @action+ onDrag(event, info) {+ this.offset = Math.min(240, Math.max(0, this.#start + info.delta.x));+ }++ @action+ onDragStart() {+ this.#start = this.offset;+ }++ <template>+ <div class="styleguide-drag-and-drop__track">+ <div+ class="styleguide-drag-and-drop__knob"+ style={{this.knobStyle}}+ {{dPointerDrag+ onDragStart=this.onDragStart+ onDrag=this.onDrag+ onDragCancel=this.onDragCancel+ draggingClass="--dragging"+ }}+ >{{i18n "styleguide.sections.drag_and_drop.knob"}}</div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/swipe.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/swipe.gjsnew file mode 100644index 00000000000..44ca223f8c0--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/gestures/swipe.gjs@@ -0,0 +1,34 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dSwipe from "discourse/ui-kit/modifiers/d-swipe";+import { i18n } from "discourse-i18n";++export default class SwipeExample extends Component {+ @tracked direction;++ @action+ onDidEndSwipe(state) {+ this.direction = state.direction;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__swipe"+ {{dSwipe onDidEndSwipe=this.onDidEndSwipe}}+ >{{i18n "styleguide.sections.drag_and_drop.swipe_here"}}</div>++ <p class="styleguide-example__result">+ {{#if this.direction}}+ {{i18n+ "styleguide.sections.drag_and_drop.swiped"+ direction=this.direction+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/adoption.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/adoption.gjsnew file mode 100644index 00000000000..9dd0fc41a00--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/adoption.gjs@@ -0,0 +1,50 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++/**+ * One adoption, declared once. Adoption is resolved for the whole page, so two+ * targets naming the same kind must share the predicate that decides it.+ */+const WEB_LINK = {+ type: "web-link",+ match: ({ element }) => Boolean(element.closest("a[href]")),+};++export default class AdoptionExample extends Component {+ @tracked url;++ @action+ onDrop({ source }) {+ this.url = source.native.getURLs()[0];+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <p>+ <a href="https://www.discourse.org">{{i18n+ "styleguide.sections.drag_and_drop.a_link"+ }}</a>+ </p>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ adopts=WEB_LINK+ position="inside"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.drop_a_link"}}</div>++ <p class="styleguide-example__result">+ {{#if this.url}}+ {{this.url}}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external-axis.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external-axis.gjsnew file mode 100644index 00000000000..89fcbe4af37--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external-axis.gjs@@ -0,0 +1,39 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { array } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropExternalTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-external-target";+import { i18n } from "discourse-i18n";++export default class ExternalAxisExample extends Component {+ @tracked position;++ @action+ onDrop({ position }) {+ this.position = position;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropExternalTarget+ accepts=(array "urls" "text")+ axis="vertical"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.a_slot"}}</div>++ <p class="styleguide-example__result">+ {{#if this.position}}+ {{i18n+ "styleguide.sections.drag_and_drop.reported_position"+ position=this.position+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external.gjsnew file mode 100644index 00000000000..23244405e4c--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/outside/external.gjs@@ -0,0 +1,40 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { array } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropExternalTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-external-target";+import { i18n } from "discourse-i18n";++export default class ExternalExample extends Component {+ @tracked summary;++ @action+ onDrop({ source }) {+ this.summary = source.containsFiles()+ ? source+ .getFiles()+ .map((file) => file.name)+ .join(", ")+ : (source.getURLs()[0] ?? source.getText());+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropExternalTarget+ accepts=(array "urls" "text" "files")+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.from_outside"}}</div>++ <p class="styleguide-example__result">+ {{#if this.summary}}+ {{this.summary}}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/auto-scroll.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/auto-scroll.gjsnew file mode 100644index 00000000000..e799a14bc98--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/auto-scroll.gjs@@ -0,0 +1,27 @@+import dDragAndDropAutoScroll from "discourse/ui-kit/modifiers/d-drag-and-drop-auto-scroll";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++const ROWS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];++export default <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div+ class="styleguide-drag-and-drop__scroller"+ {{dDragAndDropAutoScroll types="card"}}+ >+ {{#each ROWS key="@index" as |row|}}+ <div+ class="styleguide-drag-and-drop__scroller-row"+ {{dDragAndDropTarget accepts="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.row" number=row}}</div>+ {{/each}}+ </div>+ </div>+</template>diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/monitor.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/monitor.gjsnew file mode 100644index 00000000000..080dee82b82--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/monitor.gjs@@ -0,0 +1,52 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dDragAndDropMonitor from "discourse/ui-kit/modifiers/d-drag-and-drop-monitor";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class MonitorExample extends Component {+ @tracked entries = [];++ @action+ logDrop() {+ this.#log("onDrop");+ }++ @action+ logStart() {+ this.#log("onDragStart");+ }++ #log(name) {+ this.entries = [...this.entries, name].slice(-6);+ }++ <template>+ <div+ class="styleguide-drag-and-drop"+ {{dDragAndDropMonitor+ types="card"+ onDragStart=this.logStart+ onDrop=this.logDrop+ }}+ >+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget accepts="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drop_here"}}</div>++ <ol class="styleguide-drag-and-drop__log styleguide-example__result">+ {{#each this.entries key="@index" as |entry|}}+ <li>{{entry}}</li>+ {{/each}}+ </ol>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/service.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/service.gjsnew file mode 100644index 00000000000..18ebd8114cf--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/reacting/service.gjs@@ -0,0 +1,39 @@+import Component from "@glimmer/component";+import { service } from "@ember/service";+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import { i18n } from "discourse-i18n";++export default class ServiceExample extends Component {+ @service dragAndDrop;++ // Read through a getter rather than calling the service method from the+ // template: it is an ordinary method, so a template call would invoke it+ // detached from the service.+ get isArmed() {+ return this.dragAndDrop.accepts("card");+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ {{! No callbacks: the panel renders straight from tracked state. }}+ <div+ class={{dConcatClass+ "styleguide-drag-and-drop__panel"+ (if this.isArmed "--armed")+ }}+ >+ {{#if this.isArmed}}+ {{i18n "styleguide.sections.drag_and_drop.armed"}}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.idle"}}+ {{/if}}+ </div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/edge.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/edge.gjsnew file mode 100644index 00000000000..39fd27754f5--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/edge.gjs@@ -0,0 +1,55 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { trustHTML } from "@ember/template";+import dResizeEdge from "discourse/ui-kit/modifiers/d-resize-edge";+import { i18n } from "discourse-i18n";++const MAX = 320;+const MIN = 80;++export default class EdgeExample extends Component {+ @tracked width = 160;++ get paneStyle() {+ return trustHTML(`width: ${this.width}px;`);+ }++ @action+ onResize(size) {+ this.width = size;+ }++ <template>+ <div class="styleguide-drag-and-drop__panes">+ <div class="styleguide-drag-and-drop__pane" style={{this.paneStyle}}>+ {{i18n "styleguide.sections.drag_and_drop.left_pane"}}+ </div>++ {{! Everything the separator component would have supplied is spelled out+ here, because the modifier owns the interaction and nothing else. }}+ <div+ class="styleguide-drag-and-drop__divider"+ role="separator"+ tabindex="0"+ aria-orientation="vertical"+ aria-label={{i18n "styleguide.sections.drag_and_drop.edge_label"}}+ aria-valuenow={{this.width}}+ aria-valuemin={{MIN}}+ aria-valuemax={{MAX}}+ {{dResizeEdge+ value=this.width+ min=MIN+ max=MAX+ axis="horizontal"+ bodyClass="d-resizing-ew"+ onResize=this.onResize+ }}+ ></div>++ <div class="styleguide-drag-and-drop__pane --grow">+ {{i18n "styleguide.sections.drag_and_drop.right_pane"}}+ </div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/handles.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/handles.gjsnew file mode 100644index 00000000000..bbfd5730d73--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/handles.gjs@@ -0,0 +1,88 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { trustHTML } from "@ember/template";+import { modifier } from "ember-modifier";+import DResizeHandles from "discourse/ui-kit/d-resize-handles";++/** Smallest dimension the example permits. */+const MIN_SIZE = 60;++export default class HandlesExample extends Component {+ @tracked height = 120;+ @tracked width = 220;+ @tracked x = 16;+ @tracked y = 16;++ /** The area the box may occupy; every bound below is measured from it. */+ captureStage = modifier((element) => {+ this.stageElement = element;+ return () => (this.stageElement = undefined);+ });++ stageElement;+ #start = {};++ get boxStyle() {+ return trustHTML(+ `width: ${this.width}px; height: ${this.height}px; ` ++ `transform: translate(${this.x}px, ${this.y}px);`+ );+ }++ get readout() {+ return `${Math.round(this.width)} × ${Math.round(this.height)}`;+ }++ /**+ * A west or north handle moves the box's origin as well as its size, so the+ * opposite edge stays put. Every result is clamped inside the stage.+ */+ @action+ onResize(direction, { delta }) {+ const { x, y, width, height } = this.#start;+ const { clientWidth: maxX, clientHeight: maxY } = this.stageElement;++ if (direction.includes("e")) {+ this.width = this.#clamp(width + delta.x, MIN_SIZE, maxX - x);+ }+ if (direction.includes("w")) {+ this.x = this.#clamp(x + delta.x, 0, x + width - MIN_SIZE);+ this.width = x + width - this.x;+ }+ if (direction.includes("s")) {+ this.height = this.#clamp(height + delta.y, MIN_SIZE, maxY - y);+ }+ if (direction.includes("n")) {+ this.y = this.#clamp(y + delta.y, 0, y + height - MIN_SIZE);+ this.height = y + height - this.y;+ }+ }++ @action+ onResizeStart() {+ this.#start = {+ height: this.height,+ width: this.width,+ x: this.x,+ y: this.y,+ };+ }++ #clamp(value, min, max) {+ return Math.min(Math.max(value, min), max);+ }++ <template>+ <div class="styleguide-drag-and-drop__stage" {{this.captureStage}}>+ <div class="styleguide-drag-and-drop__resizable" style={{this.boxStyle}}>+ {{this.readout}}+ <DResizeHandles+ @handleClass="styleguide-drag-and-drop__handle"+ @onResizeStart={{this.onResizeStart}}+ @onResize={{this.onResize}}+ />+ </div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/separator.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/separator.gjsnew file mode 100644index 00000000000..580d7d09622--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/resize/separator.gjs@@ -0,0 +1,44 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { trustHTML } from "@ember/template";+import DResizeSeparator from "discourse/ui-kit/d-resize-separator";+import { i18n } from "discourse-i18n";++const MIN = 80;+const MAX = 320;++export default class SeparatorExample extends Component {+ @tracked width = 160;++ get paneStyle() {+ return trustHTML(`width: ${this.width}px;`);+ }++ @action+ onResize(size) {+ this.width = size;+ }++ <template>+ <div class="styleguide-drag-and-drop__panes">+ <div class="styleguide-drag-and-drop__pane" style={{this.paneStyle}}>+ {{i18n "styleguide.sections.drag_and_drop.left_pane"}}+ </div>++ <DResizeSeparator+ class="styleguide-drag-and-drop__divider"+ @axis="horizontal"+ @label={{i18n "styleguide.sections.drag_and_drop.separator_label"}}+ @value={{this.width}}+ @min={{MIN}}+ @max={{MAX}}+ @onResize={{this.onResize}}+ />++ <div class="styleguide-drag-and-drop__pane --grow">+ {{i18n "styleguide.sections.drag_and_drop.right_pane"}}+ </div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/disabled.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/disabled.gjsnew file mode 100644index 00000000000..50ea7df21fd--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/disabled.gjs@@ -0,0 +1,49 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import DToggleSwitch from "discourse/ui-kit/d-toggle-switch";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class DisabledExample extends Component {+ @tracked draggable = true;++ // The switch reads as the state it is in, so it is held positively here and+ // inverted for the modifier rather than the other way round.+ get disabled() {+ return !this.draggable;+ }++ @action+ toggle() {+ this.draggable = !this.draggable;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ {{! The control sits beside the source it governs, not after the target:+ it is the first thing the instruction asks the reader to touch. }}+ <div class="styleguide-drag-and-drop__controls">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card" disabled=this.disabled}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <DToggleSwitch+ @state={{this.draggable}}+ @translatedLabel={{i18n+ "styleguide.sections.drag_and_drop.draggable"+ }}+ {{on "click" this.toggle}}+ />+ </div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget accepts="card" position="inside"}}+ >{{i18n "styleguide.sections.drag_and_drop.drop_here"}}</div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/effect.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/effect.gjsnew file mode 100644index 00000000000..ce5b6231867--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/effect.gjs@@ -0,0 +1,63 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++const copyEffect = () => "copy";+const moveEffect = () => "move";++export default class EffectExample extends Component {+ @tracked effect;++ /** The effect a target asked for is recorded on the drag's own record of it. */+ @action+ onDrop({ location }) {+ this.effect = location.current.dropTargets[0]?.dropEffect;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource+ type="card"+ effectAllowed="copyMove"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div class="styleguide-drag-and-drop__chips">+ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ getDropEffect=copyEffect+ }}+ >{{i18n "styleguide.sections.drag_and_drop.asks_for_copy"}}</div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ getDropEffect=moveEffect+ }}+ >{{i18n "styleguide.sections.drag_and_drop.asks_for_move"}}</div>+ </div>++ <p class="styleguide-example__result">+ {{#if this.effect}}+ {{i18n+ "styleguide.sections.drag_and_drop.recorded_effect"+ effect=this.effect+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/handle.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/handle.gjsnew file mode 100644index 00000000000..73fa8893b9d--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/handle.gjs@@ -0,0 +1,57 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import { modifier } from "ember-modifier";+import dIcon from "discourse/ui-kit/helpers/d-icon";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class HandleExample extends Component {+ @tracked gripElement;+ @tracked landed = false;++ /** The grip element itself; `dragHandle` takes the element, never a selector. */+ captureGrip = modifier((element) => {+ this.gripElement = element;+ return () => (this.gripElement = undefined);+ });++ @action+ onDrop() {+ this.landed = true;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip --with-grip"+ {{dDragAndDropSource type="card" dragHandle=this.gripElement}}+ >+ <span+ {{this.captureGrip}}+ class="styleguide-drag-and-drop__grip"+ aria-hidden="true"+ >{{dIcon "grip-vertical"}}</span>+ {{i18n "styleguide.sections.drag_and_drop.selectable_text"}}+ </div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.drop_here"}}</div>++ <p class="styleguide-example__result">+ {{#if this.landed}}+ {{i18n "styleguide.sections.drag_and_drop.handle_landed"}}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/preview.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/preview.gjsnew file mode 100644index 00000000000..77805514364--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/sources/preview.gjs@@ -0,0 +1,39 @@+import Component from "@glimmer/component";+import { hash } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class PreviewExample extends Component {+ /**+ * Mounts a preview into the offscreen container the modifier supplies, so+ * nothing around the source bleeds into the drag image.+ */+ @action+ renderPreview({ container }) {+ const badge = document.createElement("div");+ badge.className = "styleguide-drag-and-drop__preview";+ badge.textContent = i18n("styleguide.sections.drag_and_drop.preview_badge");+ container.append(badge);+ return () => badge.remove();+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource+ type="card"+ dragPreview=this.renderPreview+ dragPreviewOffset=(hash x="0.75rem" y="0.75rem")+ }}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget accepts="card" position="inside"}}+ >{{i18n "styleguide.sections.drag_and_drop.drop_here"}}</div>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/accepts-self.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/accepts-self.gjsnew file mode 100644index 00000000000..db2dffa0869--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/accepts-self.gjs@@ -0,0 +1,55 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { hash } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class AcceptsSelfExample extends Component {+ @tracked landed;++ @action+ onDrop({ source }) {+ this.landed = source.data.name;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div class="styleguide-drag-and-drop__chips">+ <div+ class="styleguide-drag-and-drop__chip --dual"+ {{dDragAndDropSource type="card" data=(hash name="A")}}+ {{dDragAndDropTarget+ accepts="card"+ axis="horizontal"+ acceptsSelf=false+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.card_a"}}</div>++ <div+ class="styleguide-drag-and-drop__chip --dual"+ {{dDragAndDropSource type="card" data=(hash name="B")}}+ {{dDragAndDropTarget+ accepts="card"+ axis="horizontal"+ acceptsSelf=false+ onDrop=this.onDrop+ }}+ >{{i18n "styleguide.sections.drag_and_drop.card_b"}}</div>+ </div>++ <p class="styleguide-example__result">+ {{#if this.landed}}+ {{i18n+ "styleguide.sections.drag_and_drop.dropped_card"+ name=this.landed+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/can-drop.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/can-drop.gjsnew file mode 100644index 00000000000..a613cbea14e--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/can-drop.gjs@@ -0,0 +1,28 @@+import { hash } from "@ember/helper";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++/** Runs on every dragover, so it stays a cheap synchronous read. */+const isUnlocked = ({ source }) => !source.data.locked;++export default <template>+ <div class="styleguide-drag-and-drop">+ <div class="styleguide-drag-and-drop__chips">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card" data=(hash locked=false)}}+ >{{i18n "styleguide.sections.drag_and_drop.unlocked"}}</div>++ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card" data=(hash locked=true)}}+ >{{i18n "styleguide.sections.drag_and_drop.locked"}}</div>+ </div>++ <div+ class="styleguide-drag-and-drop__zone"+ {{dDragAndDropTarget accepts="card" position="inside" canDrop=isUnlocked}}+ >{{i18n "styleguide.sections.drag_and_drop.unlocked_only"}}</div>+ </div>+</template>diff --git a/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/nesting.gjs b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/nesting.gjsnew file mode 100644index 00000000000..4bfad2f9337--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/examples/molecules/drag-and-drop/targets/nesting.gjs@@ -0,0 +1,55 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { fn } from "@ember/helper";+import { action } from "@ember/object";+import dDragAndDropSource from "discourse/ui-kit/modifiers/d-drag-and-drop-source";+import dDragAndDropTarget from "discourse/ui-kit/modifiers/d-drag-and-drop-target";+import { i18n } from "discourse-i18n";++export default class NestingExample extends Component {+ @tracked landedOn;++ @action+ record(name) {+ this.landedOn = name;+ }++ <template>+ <div class="styleguide-drag-and-drop">+ <div+ class="styleguide-drag-and-drop__chip"+ {{dDragAndDropSource type="card"}}+ >{{i18n "styleguide.sections.drag_and_drop.drag_me"}}</div>++ <div+ class="styleguide-drag-and-drop__zone --outer"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ onDrop=(fn this.record "outer")+ }}+ >+ {{i18n "styleguide.sections.drag_and_drop.outer"}}+ <div+ class="styleguide-drag-and-drop__zone --inner"+ {{dDragAndDropTarget+ accepts="card"+ position="inside"+ onDrop=(fn this.record "inner")+ }}+ >{{i18n "styleguide.sections.drag_and_drop.inner"}}</div>+ </div>++ <p class="styleguide-example__result">+ {{#if this.landedOn}}+ {{i18n+ "styleguide.sections.drag_and_drop.received_by"+ name=this.landedOn+ }}+ {{else}}+ {{i18n "styleguide.sections.drag_and_drop.nothing_yet"}}+ {{/if}}+ </p>+ </div>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/drag-and-drop.gjs b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/drag-and-drop.gjsnew file mode 100644index 00000000000..e9e46f5b710--- /dev/null+++ b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/drag-and-drop.gjs@@ -0,0 +1,385 @@+import Component from "@glimmer/component";+import { i18n } from "discourse-i18n";+import AxisExample from "../../examples/molecules/drag-and-drop/basics/axis";+import axisSource from "../../examples/molecules/drag-and-drop/basics/axis?source=file";+import FixedPositionExample from "../../examples/molecules/drag-and-drop/basics/fixed-position";+import fixedpositionSource from "../../examples/molecules/drag-and-drop/basics/fixed-position?source=file";+import PositionsExample from "../../examples/molecules/drag-and-drop/basics/positions";+import positionsSource from "../../examples/molecules/drag-and-drop/basics/positions?source=file";+import TypesExample from "../../examples/molecules/drag-and-drop/basics/types";+import typesSource from "../../examples/molecules/drag-and-drop/basics/types?source=file";+import PointerDragExample from "../../examples/molecules/drag-and-drop/gestures/pointer-drag";+import pointerdragSource from "../../examples/molecules/drag-and-drop/gestures/pointer-drag?source=file";+import SwipeExample from "../../examples/molecules/drag-and-drop/gestures/swipe";+import swipeSource from "../../examples/molecules/drag-and-drop/gestures/swipe?source=file";+import AdoptionExample from "../../examples/molecules/drag-and-drop/outside/adoption";+import adoptionSource from "../../examples/molecules/drag-and-drop/outside/adoption?source=file";+import ExternalExample from "../../examples/molecules/drag-and-drop/outside/external";+import externalSource from "../../examples/molecules/drag-and-drop/outside/external?source=file";+import ExternalAxisExample from "../../examples/molecules/drag-and-drop/outside/external-axis";+import externalaxisSource from "../../examples/molecules/drag-and-drop/outside/external-axis?source=file";+import AutoScrollExample from "../../examples/molecules/drag-and-drop/reacting/auto-scroll";+import autoscrollSource from "../../examples/molecules/drag-and-drop/reacting/auto-scroll?source=file";+import MonitorExample from "../../examples/molecules/drag-and-drop/reacting/monitor";+import monitorSource from "../../examples/molecules/drag-and-drop/reacting/monitor?source=file";+import ServiceExample from "../../examples/molecules/drag-and-drop/reacting/service";+import serviceSource from "../../examples/molecules/drag-and-drop/reacting/service?source=file";+import EdgeExample from "../../examples/molecules/drag-and-drop/resize/edge";+import edgeSource from "../../examples/molecules/drag-and-drop/resize/edge?source=file";+import HandlesExample from "../../examples/molecules/drag-and-drop/resize/handles";+import handlesSource from "../../examples/molecules/drag-and-drop/resize/handles?source=file";+import SeparatorExample from "../../examples/molecules/drag-and-drop/resize/separator";+import separatorSource from "../../examples/molecules/drag-and-drop/resize/separator?source=file";+import DisabledExample from "../../examples/molecules/drag-and-drop/sources/disabled";+import disabledSource from "../../examples/molecules/drag-and-drop/sources/disabled?source=file";+import EffectExample from "../../examples/molecules/drag-and-drop/sources/effect";+import effectSource from "../../examples/molecules/drag-and-drop/sources/effect?source=file";+import HandleExample from "../../examples/molecules/drag-and-drop/sources/handle";+import handleSource from "../../examples/molecules/drag-and-drop/sources/handle?source=file";+import PreviewExample from "../../examples/molecules/drag-and-drop/sources/preview";+import previewSource from "../../examples/molecules/drag-and-drop/sources/preview?source=file";+import AcceptsSelfExample from "../../examples/molecules/drag-and-drop/targets/accepts-self";+import acceptsselfSource from "../../examples/molecules/drag-and-drop/targets/accepts-self?source=file";+import CanDropExample from "../../examples/molecules/drag-and-drop/targets/can-drop";+import candropSource from "../../examples/molecules/drag-and-drop/targets/can-drop?source=file";+import NestingExample from "../../examples/molecules/drag-and-drop/targets/nesting";+import nestingSource from "../../examples/molecules/drag-and-drop/targets/nesting?source=file";+import StyleguideGroups from "../../styleguide-groups";++const GROUPS = [+ "basics",+ "sources",+ "targets",+ "outside",+ "reacting",+ "resize",+ "gestures",+];++export default class DragAndDrop extends Component {+ get groups() {+ return GROUPS.map((id) => ({+ id,+ title: i18n(`styleguide.sections.drag_and_drop.groups.${id}.title`),+ description: i18n(+ `styleguide.sections.drag_and_drop.groups.${id}.description`+ ),+ }));+ }++ <template>+ <p class="section-description">+ {{i18n "styleguide.sections.drag_and_drop.description"}}+ </p>++ <StyleguideGroups+ @groups={{this.groups}}+ @section={{@section}}+ @active={{@group}}+ @ariaLabel={{i18n "styleguide.sections.drag_and_drop.groups.aria_label"}}+ as |Group|+ >+ <Group @id="basics" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.types_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.types_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.types_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.types_note"}}+ @code={{typesSource}}+ >+ <TypesExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.positions_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.positions_description"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.positions_note"}}+ @code={{positionsSource}}+ >+ <PositionsExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.axis_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.axis_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.axis_try_this"}}+ @code={{axisSource}}+ >+ <AxisExample />+ </Example>+ <Example+ @title={{i18n+ "styleguide.sections.drag_and_drop.fixed_position_title"+ }}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.fixed_position_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.fixed_position_try_this"+ }}+ @code={{fixedpositionSource}}+ >+ <FixedPositionExample />+ </Example>+ </Group>++ <Group @id="sources" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.handle_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.handle_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.handle_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.handle_note"}}+ @code={{handleSource}}+ >+ <HandleExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.preview_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.preview_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.preview_try_this"}}+ @code={{previewSource}}+ >+ <PreviewExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.disabled_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.disabled_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.disabled_try_this"+ }}+ @code={{disabledSource}}+ >+ <DisabledExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.effect_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.effect_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.effect_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.effect_note"}}+ @code={{effectSource}}+ >+ <EffectExample />+ </Example>+ </Group>++ <Group @id="targets" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.nesting_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.nesting_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.nesting_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.nesting_note"}}+ @code={{nestingSource}}+ >+ <NestingExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.accepts_self_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.accepts_self_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.accepts_self_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.accepts_self_note"}}+ @code={{acceptsselfSource}}+ >+ <AcceptsSelfExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.can_drop_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.can_drop_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.can_drop_try_this"+ }}+ @code={{candropSource}}+ >+ <CanDropExample />+ </Example>+ </Group>++ <Group @id="outside" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.adoption_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.adoption_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.adoption_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.adoption_note"}}+ @code={{adoptionSource}}+ >+ <AdoptionExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.external_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.external_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.external_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.external_note"}}+ @code={{externalSource}}+ >+ <ExternalExample />+ </Example>+ <Example+ @title={{i18n+ "styleguide.sections.drag_and_drop.external_axis_title"+ }}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.external_axis_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.external_axis_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.external_axis_note"}}+ @code={{externalaxisSource}}+ >+ <ExternalAxisExample />+ </Example>+ </Group>++ <Group @id="reacting" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.monitor_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.monitor_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.monitor_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.monitor_note"}}+ @code={{monitorSource}}+ >+ <MonitorExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.service_title"}}+ @kind="service"+ @description={{i18n+ "styleguide.sections.drag_and_drop.service_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.service_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.service_note"}}+ @code={{serviceSource}}+ >+ <ServiceExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.auto_scroll_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.auto_scroll_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.auto_scroll_try_this"+ }}+ @code={{autoscrollSource}}+ >+ <AutoScrollExample />+ </Example>+ </Group>++ <Group @id="resize" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.separator_title"}}+ @kind="component"+ @description={{i18n+ "styleguide.sections.drag_and_drop.separator_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.separator_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.separator_note"}}+ @code={{separatorSource}}+ >+ <SeparatorExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.edge_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.edge_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.edge_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.edge_note"}}+ @code={{edgeSource}}+ >+ <EdgeExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.handles_title"}}+ @kind="component"+ @description={{i18n+ "styleguide.sections.drag_and_drop.handles_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.handles_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.handles_note"}}+ @code={{handlesSource}}+ >+ <HandlesExample />+ </Example>+ </Group>++ <Group @id="gestures" as |Example|>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.pointer_drag_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.pointer_drag_description"+ }}+ @tryThis={{i18n+ "styleguide.sections.drag_and_drop.pointer_drag_try_this"+ }}+ @note={{i18n "styleguide.sections.drag_and_drop.pointer_drag_note"}}+ @code={{pointerdragSource}}+ >+ <PointerDragExample />+ </Example>+ <Example+ @title={{i18n "styleguide.sections.drag_and_drop.swipe_title"}}+ @kind="modifier"+ @description={{i18n+ "styleguide.sections.drag_and_drop.swipe_description"+ }}+ @tryThis={{i18n "styleguide.sections.drag_and_drop.swipe_try_this"}}+ @note={{i18n "styleguide.sections.drag_and_drop.swipe_note"}}+ @code={{swipeSource}}+ >+ <SwipeExample />+ </Example>+ </Group>+ </StyleguideGroups>+ </template>+}diff --git a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-example.gjs b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-example.gjsindex deee5072f89..b3f3327c5f1 100644--- a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-example.gjs+++ b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-example.gjs@@ -1,5 +1,6 @@import Component from "@glimmer/component";import { tracked } from "@glimmer/tracking";+import { warn } from "@ember/debug";import { action } from "@ember/object";import { eq, or } from "discourse/truth-helpers";import DButton from "discourse/ui-kit/d-button";@@ -11,6 +12,9 @@ import inlineCode from "discourse/plugins/styleguide/discourse/lib/inline-code";// plugin bundle, and importing it fails the whole bundle at load rather than at use.let exampleId = 0;+/** What an example demonstrates, when the page is documenting named APIs. */+const KINDS = ["component", "modifier", "service"];+/*** One demonstrated capability: a heading, the prose that says what it proves, the live* component, and an optional source snippet.@@ -34,6 +38,10 @@ let exampleId = 0;* Also accepts a block, for a short list; give a list in that block the class* `styleguide-example__note-list` so it picks up the card's list spacing.* @param {string} [code] - the imported source of the example module, revealed by a toggle.+ * @param {string} [kind] - what the example demonstrates: `component`, `modifier` or `service`.+ * Shown as a label beside the title. For a page documenting named APIs, where a card's title+ * alone leaves the reader guessing which kind of thing they are looking at. Omit it on a page+ * that demonstrates appearance rather than an API.** Two opt-in classes an example may apply to its own yielded markup:* `styleguide-example__result`, for an element the demo writes its output into, inside the@@ -55,6 +63,23 @@ export default class StyleguideExample extends Component {return this.args.headingLevel ?? 2;}+ get kindLabel() {+ const kind = this.args.kind;+ if (!kind) {+ return;+ }++ warn(+ `<StyleguideExample> was given @kind="${kind}", which is not one of ${KINDS.join(", ")}.`,+ KINDS.includes(kind),+ { id: "styleguide.example-unknown-kind" }+ );++ return KINDS.includes(kind)+ ? i18n(`styleguide.example.kind.${kind}`)+ : null;+ }+@actiontoggleCode() {this.showCode = !this.showCode;@@ -75,6 +100,10 @@ export default class StyleguideExample extends Component {</h2>{{/if}}+ {{#if this.kindLabel}}+ <span class="styleguide-example__kind">{{this.kindLabel}}</span>+ {{/if}}+{{#if @code}}{{! Icon-only, so the tooltip and the accessible name are set separately. DButtonbuilds its aria-label from the ariaLabel argument alone and never from the titlediff --git a/plugins/styleguide/assets/javascripts/discourse/lib/styleguide.js b/plugins/styleguide/assets/javascripts/discourse/lib/styleguide.jsindex d7d418cc94c..0744eeafc47 100644--- a/plugins/styleguide/assets/javascripts/discourse/lib/styleguide.js+++ b/plugins/styleguide/assets/javascripts/discourse/lib/styleguide.js@@ -14,6 +14,7 @@ import categories from "../components/sections/molecules/categories";import charCounter from "../components/sections/molecules/char-counter";import comboButton from "../components/sections/molecules/combo-button";import dialog from "../components/sections/molecules/dialog";+import dragAndDrop from "../components/sections/molecules/drag-and-drop";import emptyState from "../components/sections/molecules/empty-state";import menus from "../components/sections/molecules/menus";import multiselect from "../components/sections/molecules/multi-select";@@ -87,6 +88,7 @@ const SECTIONS = [{ component: multiselect, category: "molecules", id: "multi-select" },{ component: toasts, category: "molecules", id: "toasts" },{ component: dialog, category: "molecules", id: "dialog" },+ { component: dragAndDrop, category: "molecules", id: "drag-and-drop" },{ component: signupCta, category: "molecules", id: "signup-cta" },{ component: topicListItem, category: "molecules", id: "topic-list-item" },{diff --git a/plugins/styleguide/assets/stylesheets/styleguide.scss b/plugins/styleguide/assets/stylesheets/styleguide.scssindex 0563860efa8..585337d11c7 100644--- a/plugins/styleguide/assets/stylesheets/styleguide.scss+++ b/plugins/styleguide/assets/stylesheets/styleguide.scss@@ -167,6 +167,19 @@margin: 0;}+ // The auto margin, not the header's `space-between`, is what keeps the badge+ // beside the title and the code toggle at the far end.+ &__kind {+ margin-inline-end: auto;+ padding: 0 var(--space-2);+ border: 1px solid var(--content-border-color);+ border-radius: var(--d-border-radius);+ color: var(--primary-medium);+ font-size: var(--font-down-2);+ text-transform: lowercase;+ white-space: nowrap;+ }+&__description code,&__try-this code,&__note code {@@ -442,3 +455,278 @@flex-grow: 1;}}++.styleguide-drag-and-drop {+ display: flex;+ flex-direction: column;+ gap: var(--space-3);+ width: 100%;++ &__chips {+ display: flex;+ flex-wrap: wrap;+ gap: var(--space-2);+ }++ &__controls {+ display: flex;+ flex-wrap: wrap;+ align-items: center;+ gap: var(--space-3);+ }++ &__chip {+ display: inline-flex;+ align-items: center;+ gap: var(--space-2);+ padding: var(--space-2) var(--space-3);+ background: var(--token-color-surface-hovered);+ cursor: grab;++ &.--dual {+ min-width: 7rem;+ }++ &.--with-grip {+ cursor: auto;+ }+ }++ &__grip {+ cursor: grab;+ }++ &__zone {+ display: flex;+ align-items: center;+ justify-content: center;+ min-height: 4rem;+ padding: var(--space-3);+ border: 1px dashed var(--primary-medium);++ &.--outer {+ flex-direction: column;+ gap: var(--space-3);+ min-height: 9rem;+ }++ &.--inner {+ width: 70%;+ min-height: 3.5rem;+ }+ }++ &__columns {+ display: flex;+ gap: var(--space-2);+ }++ &__column {+ flex: 1;+ padding: var(--space-4) var(--space-2);+ background: var(--token-color-surface-hovered);+ text-align: center;+ }++ &__panel {+ padding: var(--space-3);+ background: var(--token-color-surface-hovered);++ &.--armed {+ background: var(--tertiary-very-low);+ }+ }++ &__log {+ @include unstyled-list;+ font-family: var(--font-family-monospace);+ }++ &__scroller {+ display: flex;+ flex-direction: column;+ gap: var(--space-1);+ max-height: 9rem;+ overflow-y: auto;+ }++ &__scroller-row {+ padding: var(--space-2) var(--space-3);+ background: var(--token-color-surface-hovered);+ }++ &__panes {+ display: flex;+ align-items: stretch;+ min-height: 6rem;+ }++ // Core ships the separator's cursor only. The visible divider is the+ // consumer's, drawn through the class it passes rather than the component's+ // own, which is how the composer does it too.+ &__divider {+ flex: 0 0 auto;+ width: 0.375rem;+ background: var(--primary-medium);+ }++ &__pane {+ display: flex;+ align-items: center;+ justify-content: center;+ background: var(--token-color-surface-hovered);++ &.--grow {+ flex: 1;+ }+ }++ &__track {+ position: relative;+ padding: var(--space-2);+ background: var(--token-color-surface-hovered);+ }++ &__knob {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 4rem;+ padding: var(--space-2);+ background: var(--tertiary-low);+ cursor: grab;+ user-select: none;+ }++ &__swipe {+ display: flex;+ align-items: center;+ justify-content: center;+ min-height: 5rem;+ background: var(--token-color-surface-hovered);+ touch-action: pan-y;+ }++ &__swatches {+ display: flex;+ flex-wrap: wrap;+ gap: var(--space-6);+ }++ &__swatch {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: var(--space-2);+ }++ &__box {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 5.625rem;+ min-height: 3.75rem;+ background: var(--token-color-surface-hovered);+ }++ // A fixed area the box floats inside, so a resize moves the box rather than+ // reflowing the card, and every bound is measured from something stable.+ &__stage {+ position: relative;+ height: 15rem;+ overflow: hidden;+ background: var(--primary-very-low);+ }++ &__resizable {+ position: absolute;+ top: 0;+ left: 0;+ display: flex;+ align-items: center;+ justify-content: center;+ background: var(--token-color-surface-hovered);+ }++ &__preview {+ padding: var(--space-2) var(--space-3);+ background: var(--tertiary);+ color: var(--secondary);+ }++ &__handle {+ position: absolute;+ width: 0.75rem;+ height: 0.75rem;+ background: var(--tertiary);++ // Compass directions follow physical pointer axes and must not flip in RTL.+ &.--n,+ &.--s {+ /*! rtl:ignore */+ left: 0.75rem;++ /*! rtl:ignore */+ right: 0.75rem;+ width: auto;+ cursor: ns-resize;+ }++ &.--e,+ &.--w {+ top: 0.75rem;+ bottom: 0.75rem;+ height: auto;+ cursor: ew-resize;+ }++ &.--n {+ top: -0.375rem;+ }++ &.--s {+ bottom: -0.375rem;+ }++ &.--e {+ /*! rtl:ignore */+ right: -0.375rem;+ }++ &.--w {+ /*! rtl:ignore */+ left: -0.375rem;+ }++ &.--ne {+ top: -0.375rem;++ /*! rtl:ignore */+ right: -0.375rem;+ cursor: nesw-resize;+ }++ &.--se {+ /*! rtl:ignore */+ right: -0.375rem;+ bottom: -0.375rem;+ cursor: nwse-resize;+ }++ &.--sw {+ bottom: -0.375rem;++ /*! rtl:ignore */+ left: -0.375rem;+ cursor: nesw-resize;+ }++ &.--nw {+ top: -0.375rem;++ /*! rtl:ignore */+ left: -0.375rem;+ cursor: nwse-resize;+ }+ }+}diff --git a/plugins/styleguide/config/locales/client.en.yml b/plugins/styleguide/config/locales/client.en.ymlindex 260ce3bc964..987be76b48d 100644--- a/plugins/styleguide/config/locales/client.en.yml+++ b/plugins/styleguide/config/locales/client.en.yml@@ -13,6 +13,10 @@ en:toggle_code: "Toggle code sample"try_this: "Try this:"code_region: "Source snippet: %{title}"+ kind:+ component: "Component"+ modifier: "Modifier"+ service: "Service"categories:syntax: Syntax@@ -41,6 +45,158 @@ en:title: "Colors"dialog:title: "Dialog"+ drag_and_drop:+ title: "Drag and drop"+ description: "The shared drag, drop, resize and gesture primitives, one capability per card."+ groups:+ aria_label: "Drag and drop groups"+ basics:+ title: "Basics"+ description: "The matching vocabulary, and the positions a target reports."+ sources:+ title: "Sources"+ description: "What a draggable element attaches, shows, and permits."+ targets:+ title: "Targets"+ description: "How a target decides whether a drop belongs to it."+ outside:+ title: "From outside"+ description: "Content the browser started dragging, from this page or another window."+ reacting:+ title: "Reacting"+ description: "Responding to a drag without owning the drop."+ resize:+ title: "Resizing"+ description: "Letting someone change a size, by keyboard as well as pointer."+ gestures:+ title: "Other gestures"+ description: "Pointer and touch gestures that transfer nothing."+ nothing_yet: "Nothing yet."+ drag_me: "Drag me"+ drop_here: "Drop here"+ a_card: "A card"+ a_note: "A note"+ cards_only: "Accepts cards only"+ landed: "Dropped: %{label}"+ reported_position: "Reported position: %{position}"+ positions:+ above: "Above"+ below: "Below"+ left: "Left"+ right: "Right"+ inside: "Inside"+ types_title: "Matching by type"+ types_description: "`dDragAndDropSource` names a type and `dDragAndDropTarget` filters on it. A target engages only for the types in its accepts list; everything else drags straight over it."+ types_try_this: "Drag each chip onto the zone. Only the card is taken."+ types_note: "Omitting accepts accepts every registered source, which is rarely what a real surface wants."+ positions_title: "Drop positions"+ positions_description: "`dDragAndDropTarget` paints exactly one of these classes while a compatible drag is over it: four sibling positions plus one container position."+ positions_note: "Positions are logical. In a right-to-left row, before still means the reading-order start and the class flips to --drag-right, so the indicator stays under the pointer."+ axis_title: "Measuring across"+ axis_description: "`dDragAndDropTarget` takes an axis, which chooses the midpoint that decides before from after. A row of columns measures horizontally."+ axis_try_this: "Drop on the left and right halves of one column and compare the reported position."+ fixed_position_title: "A fixed position"+ fixed_position_description: "`dDragAndDropTarget` given a position skips the midpoint entirely and always reports that one."+ fixed_position_try_this: "Drop on the bottom edge. It still reports before."+ always_before: "Always reports before"+ handle_title: "Dragging by a handle"+ handle_description: "`dDragAndDropSource` takes a dragHandle, which confines where a drag may begin so the rest of the element stays selectable and a touch press meant to scroll still scrolls."+ handle_try_this: "Select the text with the pointer, then drag the grip."+ handle_note: "The row stays the drag body: it keeps data-drag-source, it is the target's source.element, and it is what the preview photographs. Style and assert on data-drag-source, never on draggable."+ handle_landed: "The row landed, not the grip."+ selectable_text: "Selectable text"+ preview_title: "A custom preview"+ preview_description: "`dDragAndDropSource` takes a dragPreview render function, which mounts a preview into an isolated offscreen container so nothing around the source bleeds into the drag image."+ preview_try_this: "Drag the chip and watch what follows the pointer."+ preview_badge: "Custom preview"+ disabled_title: "Detaching a source"+ disabled_description: "`dDragAndDropSource` takes disabled, which detaches the registration. This, not a handle, is how to stop an element being dragged."+ disabled_try_this: "Switch it off, try to drag, then switch it back on."+ draggable: "Draggable"+ effect_title: "Declaring the effect"+ effect_description: "`dDragAndDropTarget` names the operation it would perform through getDropEffect, and the drag carries that effect on its record of the target."+ effect_try_this: "Drop on each zone and compare the recorded effect."+ effect_note: "The source's effectAllowed declares what it permits, but nothing here enforces the pair: a target may ask for an effect the source never permitted and no refusal follows. Keep the two consistent yourself."+ asks_for_copy: "Asks for copy"+ asks_for_move: "Asks for move"+ recorded_effect: "Recorded effect: %{effect}"+ nesting_title: "Nested targets"+ nesting_description: "`dDragAndDropTarget` hands the callbacks to the deepest accepted target under the pointer, so one drop is never handled twice."+ nesting_try_this: "Drop on the inner zone, then on the outer one around it."+ nesting_note: "The cost is that an ancestor stops indicating as soon as a descendant claims the drag. A container that must stay lit should render from the service instead."+ outer: "Outer"+ inner: "Inner"+ received_by: "Received by: %{name}"+ accepts_self_title: "Refusing itself"+ accepts_self_description: "`dDragAndDropTarget` takes acceptsSelf. An element that is both a source and a target accepts its own drop by default, since that is often meaningful."+ accepts_self_try_this: "Drop a card onto itself, then onto the other one."+ accepts_self_note: "The comparison is against the drag body, so a row dragged by a handle is still recognised as itself."+ card_a: "Card A"+ card_b: "Card B"+ dropped_card: "Dropped card %{name}"+ can_drop_title: "Refusing by payload"+ can_drop_description: "`dDragAndDropTarget` takes canDrop, a synchronous gate that inspects the payload and refuses the drop before it lands."+ can_drop_try_this: "Drag each chip over the zone. The locked one is never accepted."+ unlocked: "Unlocked"+ locked: "Locked"+ unlocked_only: "Unlocked only"+ adoption_title: "Adopting page content"+ adoption_description: "`dDragAndDropTarget` takes adopts. The browser starts drags on ordinary content such as a link, which registers no source, and an adoption lets a target take those too."+ adoption_try_this: "Drag the link above into the zone."+ adoption_note: "Adoption is resolved once for the page, not per target: the first live adoption whose predicate matches names the drag. Two adoptions sharing a name must share a predicate."+ a_link: "A link on this page"+ drop_a_link: "Drop a link here"+ external_title: "A drop from outside"+ external_description: "`dDragAndDropExternalTarget` takes payloads dragged in from another window or application. It never sees a drag that began on this page."+ external_try_this: "Drag a link from another tab, or a file from your desktop, into the zone."+ external_note: "This is not the upload path. A file dropped here does not enter upload validation, progress, or the upload record."+ from_outside: "Drop from outside the window"+ external_axis_title: "An external slot"+ external_axis_description: "`dDragAndDropExternalTarget` given an axis resolves a position from the pointer, just as an element target does."+ external_axis_try_this: "Drop something near the top edge, then near the bottom."+ external_axis_note: "Without a position or an axis the target is one destination rather than a slot: callbacks receive a null position and the indicator is the single --drag-over-external class."+ a_slot: "A slot, not a destination"+ monitor_title: "Watching every drag"+ monitor_description: "`dDragAndDropMonitor` reacts to a drag happening anywhere, without becoming a drop target itself."+ monitor_try_this: "Drag the chip and watch the log, whether or not you drop it on the zone."+ monitor_note: "The element only anchors the modifier's lifecycle. A monitor is global."+ service_title: "Rendering from state"+ service_description: "The `dragAndDrop` service exposes the in-flight drag as tracked state, so a surface can arm itself without wiring a single callback."+ service_try_this: "Start dragging the chip and watch the panel, without dropping."+ service_note: "The service reads the other way from a target: an empty or missing filter matches nothing, because a caller that has not decided should not light up for every drag."+ armed: "A card is in flight"+ idle: "Idle"+ auto_scroll_title: "Scrolling while dragging"+ auto_scroll_description: "`dDragAndDropAutoScroll` scrolls a container while a drag hovers near its edge, so a row below the fold stays reachable."+ auto_scroll_try_this: "Drag the chip to the bottom edge of the list and hold it there."+ row: "Row %{number}"+ separator_title: "Resizing between regions"+ separator_description: "`DResizeSeparator` is the component to reach for first. It wraps the `dResizeEdge` modifier and adds the separator contract: the role, one tab stop, and live announced values."+ separator_try_this: "Drag the divider, then focus it and use the arrow keys."+ separator_note: "A label is required: a focusable separator with no accessible name is announced as a bare splitter, which says nothing about what it resizes."+ separator_label: "Resize the panes"+ left_pane: "Left"+ right_pane: "Right"+ edge_title: "Resizing with your own element"+ edge_description: "`dResizeEdge` is the modifier underneath `DResizeSeparator`. It owns the interaction and nothing else, so the role, the tab stop and the announced values are yours to supply."+ edge_try_this: "Drag the divider, then focus it and use the arrow keys. It behaves the same; the difference is what the markup owes."+ edge_note: "Reach for it only when the element and its semantics are already yours to provide. Everything spelled out in this example is what the component would have given you."+ edge_label: "Resize the panes"+ handles_title: "Resizing a box"+ handles_description: "`DResizeHandles` is a component that renders the edges and corners of a box and reports pointer geometry for the consumer to turn into a size."+ handles_try_this: "Drag any edge or corner."+ handles_note: "Do not give a two-dimensional resize the separator role. It has no single value to announce, so the role would describe a control that does not exist."+ pointer_drag_title: "Tracking the pointer"+ pointer_drag_description: "`dPointerDrag` presses, moves and releases on one element. It transfers nothing and has no targets."+ pointer_drag_try_this: "Drag the knob along the track."+ pointer_drag_note: "Always handle the cancel callback. A gesture the browser interrupts otherwise leaves whatever the start opened still open."+ knob: "Knob"+ swipe_title: "Detecting a flick"+ swipe_description: "`dSwipe` reports one discrete direction with velocity, rather than a value that follows the pointer."+ swipe_try_this: "Swipe across the panel on a touch screen."+ swipe_note: "Reach for a pointer drag instead when a value must track the pointer continuously."+ swipe_here: "Swipe across me"+ swiped: "Swiped %{direction}"icons:title: "Icons"full_list: "See the full list of Font Awesome Icons"diff --git a/plugins/styleguide/spec/system/smoke_test_spec.rb b/plugins/styleguide/spec/system/smoke_test_spec.rbindex 9841dda75fb..6c98122c3c5 100644--- a/plugins/styleguide/spec/system/smoke_test_spec.rb+++ b/plugins/styleguide/spec/system/smoke_test_spec.rb@@ -1,6 +1,8 @@# frozen_string_literal: trueRSpec.describe "Styleguide Smoke Test" do+ include ThemeScreenshotMarker+fab!(:admin)let(:styleguide) { PageObjects::Pages::Styleguide.new }@@ -36,6 +38,7 @@ RSpec.describe "Styleguide Smoke Test" do{ href: "/molecules/multi-select", title: "Multi select" },{ href: "/molecules/toasts", title: "Toasts" },{ href: "/molecules/dialog", title: "Dialog" },+ { href: "/molecules/drag-and-drop", title: "Drag and drop" },{ href: "/molecules/tooltips", title: "Tooltips" },{ href: "/molecules/topic-list-item", title: "Topic List Item" },{ href: "/molecules/topic-notifications", title: "Topic Notifications" },@@ -123,6 +126,43 @@ RSpec.describe "Styleguide Smoke Test" doexpect(styleguide).to have_breadcrumb("Buttons")end+ it "renders the drag and drop examples" do+ visit "/styleguide/molecules/drag-and-drop"++ expect(styleguide).to have_heading("Drag and drop")+ # The first group renders by default; the rest are behind the group subnav.+ expect(page).to have_css("[data-test-styleguide-group='basics']")+ expect(page).to have_css(".styleguide-drag-and-drop__zone")+ screenshot_marker(label: "styleguide-drag-and-drop")+ end++ # Asserting on each group's own markup, not just its wrapper: the wrapper+ # renders before a broken example inside it throws, so a wrapper-only check+ # passes for a group whose examples never mounted.+ it "renders each drag and drop group's examples" do+ {+ "basics" => ".styleguide-drag-and-drop__swatches",+ "sources" => ".styleguide-drag-and-drop__grip",+ "targets" => ".styleguide-drag-and-drop__zone.--inner",+ "outside" => ".styleguide-drag-and-drop__zone",+ "reacting" => ".styleguide-drag-and-drop__panel",+ "resize" => ".styleguide-drag-and-drop__resizable",+ "gestures" => ".styleguide-drag-and-drop__knob",+ }.each do |group, selector|+ visit "/styleguide/molecules/drag-and-drop?group=#{group}"++ expect(page).to have_css("[data-test-styleguide-group='#{group}']")+ expect(page).to have_css(selector)+ end+ end++ it "labels each drag and drop example with what it demonstrates" do+ visit "/styleguide/molecules/drag-and-drop?group=resize"++ # The separator and the handles are components; the raw edge is a modifier.+ expect(page).to have_css(".styleguide-example__kind", count: 3)+ end+it "renders the index page correctly on a site with no default color schemes" doSiteSetting.default_theme_id = Fabricate(:theme).idvisit "/styleguide"