katalyst-tables 3.5.5 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"tables.min.js","sources":["../../../javascript/tables/orderable/list_controller.js","../../../javascript/tables/selection/item_controller.js","../../../javascript/tables/query_input_controller.js","../../../javascript/tables/application.js","../../../javascript/tables/orderable/item_controller.js","../../../javascript/tables/orderable/form_controller.js","../../../javascript/tables/selection/form_controller.js","../../../javascript/tables/selection/table_controller.js","../../../javascript/tables/query_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableListController extends Controller {\n static outlets = [\"tables--orderable--item\", \"tables--orderable--form\"];\n\n //region State transitions\n\n startDragging(dragState) {\n this.dragState = dragState;\n\n document.addEventListener(\"mousemove\", this.mousemove);\n document.addEventListener(\"mouseup\", this.mouseup);\n window.addEventListener(\"scroll\", this.scroll, true);\n\n this.element.style.position = \"relative\";\n }\n\n stopDragging() {\n const dragState = this.dragState;\n delete this.dragState;\n\n document.removeEventListener(\"mousemove\", this.mousemove);\n document.removeEventListener(\"mouseup\", this.mouseup);\n window.removeEventListener(\"scroll\", this.scroll, true);\n\n this.element.removeAttribute(\"style\");\n this.tablesOrderableItemOutlets.forEach((item) => item.reset());\n\n return dragState;\n }\n\n drop() {\n // note: early returns guard against turbo updates that prevent us finding\n // the right item to drop on. In this situation it's better to discard the\n // drop than to drop in the wrong place.\n\n const dragItem = this.dragItem;\n\n if (!dragItem) return;\n\n const newIndex = dragItem.dragIndex;\n const targetItem = this.tablesOrderableItemOutlets[newIndex];\n\n if (!targetItem) return;\n\n // swap the dragged item into the correct position for its current offset\n if (newIndex < dragItem.index) {\n targetItem.row.insertAdjacentElement(\"beforebegin\", dragItem.row);\n } else if (newIndex > dragItem.index) {\n targetItem.row.insertAdjacentElement(\"afterend\", dragItem.row);\n }\n\n // reindex all items based on their new positions\n this.tablesOrderableItemOutlets.forEach((item, index) =>\n item.updateIndex(index),\n );\n\n // save the changes\n this.commitChanges();\n }\n\n commitChanges() {\n // clear any existing inputs to prevent duplicates\n this.tablesOrderableFormOutlet.clear();\n\n // insert any items that have changed position\n this.tablesOrderableItemOutlets.forEach((item) => {\n if (item.hasChanges) this.tablesOrderableFormOutlet.add(item);\n });\n\n this.tablesOrderableFormOutlet.submit();\n }\n\n //endregion\n\n //region Events\n\n mousedown(event) {\n if (this.isDragging) return;\n\n const target = this.#targetItem(event.target);\n\n if (!target) return;\n\n event.preventDefault(); // prevent built-in drag\n\n this.startDragging(new DragState(this.element, event, target.id));\n\n this.dragState.updateCursor(this.element, target.row, event, this.animate);\n }\n\n mousemove = (event) => {\n if (!this.isDragging) return;\n\n event.preventDefault(); // prevent build-in drag\n\n if (this.ticking) return;\n\n this.ticking = true;\n\n window.requestAnimationFrame(() => {\n this.ticking = false;\n this.dragState?.updateCursor(\n this.element,\n this.dragItem.row,\n event,\n this.animate,\n );\n });\n };\n\n scroll = (event) => {\n if (!this.isDragging || this.ticking) return;\n\n this.ticking = true;\n\n window.requestAnimationFrame(() => {\n this.ticking = false;\n this.dragState?.updateScroll(\n this.element,\n this.dragItem.row,\n this.animate,\n );\n });\n };\n\n mouseup = (event) => {\n if (!this.isDragging) return;\n\n this.drop();\n this.stopDragging();\n this.tablesOrderableFormOutlets.forEach((form) => delete form.dragState);\n };\n\n tablesOrderableFormOutletConnected(form, element) {\n if (form.dragState) {\n // restore the previous controller's state\n this.startDragging(form.dragState);\n }\n }\n\n tablesOrderableFormOutletDisconnected(form, element) {\n if (this.isDragging) {\n // cache drag state in the form\n form.dragState = this.stopDragging();\n }\n }\n\n beforeMorphAttribute(e) {\n switch (e.detail.attributeName) {\n case \"dragging\": // set to track the item being dragged\n e.preventDefault();\n break;\n case \"style\": // used to animate rows moving up and down\n if (e.target.tagName === \"TBODY\" || e.target.tagName === \"TR\") {\n e.preventDefault();\n }\n break;\n }\n }\n\n //endregion\n\n //region Helpers\n\n /**\n * Updates the position of the drag item with a relative offset. Updates\n * other items relative to the new position of the drag item, as required.\n *\n * @callback {OrderableListController~animate}\n * @param {number} offset\n */\n animate = (offset) => {\n const dragItem = this.dragItem;\n\n // Visually update the dragItem so it follows the cursor\n dragItem.dragUpdate(offset);\n\n // Visually updates the position of all items in the list relative to the\n // dragged item. No actual changes to orderings at this stage.\n this.#currentItems.forEach((item, index) => {\n if (item === dragItem) return;\n item.updateVisually(index);\n });\n };\n\n get isDragging() {\n return !!this.dragState;\n }\n\n get dragItem() {\n if (!this.isDragging) return null;\n\n return this.tablesOrderableItemOutlets.find(\n (item) => item.id === this.dragState.targetId,\n );\n }\n\n /**\n * Returns the current items in the list, sorted by their current index.\n * Current uses the drag index if the item is being dragged, if set.\n *\n * @returns {Array[OrderableRowController]}\n */\n get #currentItems() {\n return this.tablesOrderableItemOutlets.toSorted(\n (a, b) => a.comparisonIndex - b.comparisonIndex,\n );\n }\n\n /**\n * Returns the item outlet that was clicked on, if any.\n *\n * @param element {HTMLElement} the clicked ordinal cell\n * @returns {OrderableRowController}\n */\n #targetItem(element) {\n return this.tablesOrderableItemOutlets.find(\n (item) => item.element === element,\n );\n }\n\n //endregion\n}\n\n/**\n * During drag we want to be able to translate a document-relative coordinate\n * into a coordinate relative to the list element. This state object calculates\n * and stores internal state so that we can translate absolute page coordinates\n * from mouse events into relative offsets for the list items within the list\n * element.\n *\n * We also keep track of the drag target so that if the controller is attached\n * to a new element during the drag we can continue after the turbo update.\n */\nclass DragState {\n /**\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param event {MouseEvent} the initial event\n * @param id {String} the id of the element being dragged\n */\n constructor(list, event, id) {\n // cursor offset is the offset of the cursor relative to the drag item\n this.cursorOffset = event.offsetY;\n\n // initial offset is the offset position of the drag item at drag start\n this.initialPosition = event.target.offsetTop - list.offsetTop;\n\n // id of the item being dragged\n this.targetId = id;\n }\n\n /**\n * Calculates the offset of the drag item relative to its initial position.\n *\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param row {HTMLElement} the row being dragged\n * @param event {MouseEvent} the current event\n * @param callback {OrderableListController~animate} updates the drag item with a relative offset\n */\n updateCursor(list, row, event, callback) {\n // Calculate and store the list offset relative to the viewport\n // This value is cached so we can calculate the outcome of any scroll events\n this.listOffset = list.getBoundingClientRect().top;\n\n // Calculate the position of the cursor relative to the list.\n // Accounts for scroll offsets by using the item's bounding client rect.\n const cursorPosition = event.clientY - this.listOffset;\n\n // intended item position relative to the list, from cursor position\n let itemPosition = cursorPosition - this.cursorOffset;\n\n this.#updateItemPosition(list, row, itemPosition, callback);\n }\n\n /**\n * Animates the item's position as the list scrolls. Requires a previous call\n * to set the scroll offset.\n *\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param row {HTMLElement} the row being dragged\n * @param callback {OrderableListController~animate} updates the drag item with a relative offset\n */\n updateScroll(list, row, callback) {\n const previousScrollOffset = this.listOffset;\n\n // Calculate and store the list offset relative to the viewport\n // This value is cached so we can calculate the outcome of any scroll events\n this.listOffset = list.getBoundingClientRect().top;\n\n // Calculate the change in scroll offset since the last update\n const scrollDelta = previousScrollOffset - this.listOffset;\n\n // intended item position relative to the list, from cursor position\n const position = this.position + scrollDelta;\n\n this.#updateItemPosition(list, row, position, callback);\n }\n\n #updateItemPosition(list, row, position, callback) {\n // ensure itemPosition is within the bounds of the list (tbody)\n position = Math.max(position, 0);\n position = Math.min(position, list.offsetHeight - row.offsetHeight);\n\n // cache the item's position relative to the list for use in scroll events\n this.position = position;\n\n // Item has position: relative, so we want to calculate the amount to move\n // the item relative to it's DOM position to represent how much it has been\n // dragged by.\n const offset = position - this.initialPosition;\n\n // Convert itemPosition from offset relative to list to offset relative to\n // its position within the DOM (if it hadn't moved).\n callback(offset);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Couples an input element in a row to the selection form which is turbo-permanent and outside the table.\n * When the input is toggled, the form will create/destroy hidden inputs. The checkbox inside this cell will follow\n * the hidden inputs.\n *\n * Cell value may change when:\n * * cell connects, e.g. when the user paginates\n * * cell is re-used by turbo-morph, e.g. pagination\n * * cell is toggled\n * * select-all/de-select-all on table header\n */\nexport default class SelectionItemController extends Controller {\n static outlets = [\"tables--selection--form\"];\n static values = {\n params: Object,\n checked: Boolean,\n };\n\n tablesSelectionFormOutletConnected(form) {\n form.visible(this.id, true);\n this.checkedValue = form.isSelected(this.id);\n }\n\n disconnect() {\n // Remove from form's list of visible selections.\n // This should be an outlet disconnect, but those events are not reliable in turbo 8.0\n if (this.hasTablesSelectionFormOutlet) {\n this.tablesSelectionFormOutlet.visible(this.id, false);\n }\n }\n\n change(e) {\n e.preventDefault();\n\n this.checkedValue = this.tablesSelectionFormOutlet.toggle(this.id);\n }\n\n get id() {\n return this.paramsValue.id;\n }\n\n /**\n * Update checked to match match selection form. This occurs when the item is re-used by turbo-morph.\n */\n paramsValueChanged(params, previous) {\n if (!this.hasTablesSelectionFormOutlet) return;\n\n // if id is changing (e.g. morph) then let the form know that the previous id is now not visible\n if (previous.id !== params.id) {\n this.tablesSelectionFormOutlet.visible(previous.id, false);\n }\n\n // tell form that our id is now visible in the table\n this.tablesSelectionFormOutlet.visible(params.id, true);\n\n // id has changed, so update checked from form\n this.checkedValue = this.tablesSelectionFormOutlet.isSelected(params.id);\n\n // propagate changes\n this.update();\n }\n\n /**\n * Update input to match checked. This occurs when the item is toggled, connected, or morphed.\n */\n checkedValueChanged() {\n if (!this.hasTablesSelectionFormOutlet) return;\n\n // ensure that checked matches the form, i.e. if morphed\n this.checkedValue = this.tablesSelectionFormOutlet.isSelected(this.id);\n\n // propagate changes\n this.update();\n }\n\n /**\n * Notify table that id or value may have changed. Note that this may fire when nothing has changed.\n *\n * Debouncing to minimise dom updates.\n */\n async update() {\n this.updating ||= Promise.resolve().then(() => {\n this.#update();\n delete this.updating;\n });\n\n return this.updating;\n }\n\n #update() {\n this.element.querySelector(\"input\").checked = this.checkedValue;\n this.dispatch(\"select\", {\n detail: { id: this.id, selected: this.checkedValue },\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class QueryInputController extends Controller {\n static targets = [\"input\", \"highlight\"];\n static values = { query: String };\n\n connect() {\n this.queryValue = this.inputTarget.value;\n this.element.dataset.connected = \"\";\n }\n\n disconnect() {\n delete this.element.dataset.connected;\n }\n\n update() {\n this.queryValue = this.inputTarget.value;\n }\n\n queryValueChanged(query) {\n this.highlightTarget.innerHTML = \"\";\n\n new Parser().parse(query).tokens.forEach((token) => {\n this.highlightTarget.appendChild(token.render());\n });\n }\n}\n\nclass Parser {\n constructor() {\n this.tokens = [];\n this.values = null;\n }\n\n parse(input) {\n const query = new StringScanner(input);\n\n while (!query.isEos()) {\n this.push(this.skipWhitespace(query));\n\n const value = this.takeTagged(query) || this.takeUntagged(query);\n\n if (!this.push(value)) break;\n }\n\n return this;\n }\n\n push(token) {\n if (token) {\n this.values ? this.values.push(token) : this.tokens.push(token);\n }\n\n return !!token;\n }\n\n skipWhitespace(query) {\n if (!query.scan(/\\s+/)) return;\n\n return new Token(query.matched());\n }\n\n takeUntagged(query) {\n if (!query.scan(/\\S+/)) return;\n\n return new Untagged(query.matched());\n }\n\n takeTagged(query) {\n if (!query.scan(/(\\w+(?:\\.\\w+)?)(:\\s*)/)) return;\n\n const key = query.valueAt(1);\n const separator = query.valueAt(2);\n\n const value =\n this.takeArrayValue(query) || this.takeSingleValue(query) || new Token();\n\n return new Tagged(key, separator, value);\n }\n\n takeArrayValue(query) {\n if (!query.scan(/\\[\\s*/)) return;\n\n const start = new Token(query.matched());\n const values = (this.values = []);\n\n while (!query.isEos()) {\n if (!this.push(this.takeSingleValue(query))) break;\n if (!this.push(this.takeDelimiter(query))) break;\n }\n\n query.scan(/\\s*]/);\n const end = new Token(query.matched());\n\n this.values = null;\n\n return new Array(start, values, end);\n }\n\n takeDelimiter(query) {\n if (!query.scan(/\\s*,\\s*/)) return;\n\n return new Token(query.matched());\n }\n\n takeSingleValue(query) {\n return this.takeQuotedValue(query) || this.takeUnquotedValue(query);\n }\n\n takeQuotedValue(query) {\n if (!query.scan(/\"([^\"]*)\"/)) return;\n\n return new Value(query.matched());\n }\n\n takeUnquotedValue(query) {\n if (!query.scan(/[^ \\],]*/)) return;\n\n return new Value(query.matched());\n }\n}\n\nclass Token {\n constructor(value = \"\") {\n this.value = value;\n }\n\n render() {\n return document.createTextNode(this.value);\n }\n}\n\nclass Value extends Token {\n render() {\n const span = document.createElement(\"span\");\n span.className = \"value\";\n span.innerText = this.value;\n\n return span;\n }\n}\n\nclass Tagged extends Token {\n constructor(key, separator, value) {\n super();\n\n this.key = key;\n this.separator = separator;\n this.value = value;\n }\n\n render() {\n const span = document.createElement(\"span\");\n span.className = \"tag\";\n\n const key = document.createElement(\"span\");\n key.className = \"key\";\n key.innerText = this.key;\n\n span.appendChild(key);\n span.appendChild(document.createTextNode(this.separator));\n span.appendChild(this.value.render());\n\n return span;\n }\n}\n\nclass Untagged extends Token {\n render() {\n const span = document.createElement(\"span\");\n span.className = \"untagged\";\n span.innerText = this.value;\n return span;\n }\n}\n\nclass Array extends Token {\n constructor(start, values, end) {\n super();\n\n this.start = start;\n this.values = values;\n this.end = end;\n }\n\n render() {\n const array = document.createElement(\"span\");\n array.className = \"array-values\";\n array.appendChild(this.start.render());\n\n this.values.forEach((value) => {\n const span = document.createElement(\"span\");\n span.appendChild(value.render());\n array.appendChild(span);\n });\n\n array.appendChild(this.end.render());\n\n return array;\n }\n}\n\nclass StringScanner {\n constructor(input) {\n this.input = input;\n this.position = 0;\n this.last = null;\n }\n\n isEos() {\n return this.position >= this.input.length;\n }\n\n scan(regex) {\n const match = regex.exec(this.input.substring(this.position));\n if (match?.index === 0) {\n this.last = match;\n this.position += match[0].length;\n return true;\n } else {\n this.last = {};\n return false;\n }\n }\n\n matched() {\n return this.last && this.last[0];\n }\n\n valueAt(index) {\n return this.last && this.last[index];\n }\n}\n","import OrderableItemController from \"./orderable/item_controller\";\nimport OrderableListController from \"./orderable/list_controller\";\nimport OrderableFormController from \"./orderable/form_controller\";\nimport SelectionFormController from \"./selection/form_controller\";\nimport SelectionItemController from \"./selection/item_controller\";\nimport SelectionTableController from \"./selection/table_controller\";\nimport QueryController from \"./query_controller\";\nimport QueryInputController from \"./query_input_controller\";\n\nconst Definitions = [\n {\n identifier: \"tables--orderable--item\",\n controllerConstructor: OrderableItemController,\n },\n {\n identifier: \"tables--orderable--list\",\n controllerConstructor: OrderableListController,\n },\n {\n identifier: \"tables--orderable--form\",\n controllerConstructor: OrderableFormController,\n },\n {\n identifier: \"tables--selection--form\",\n controllerConstructor: SelectionFormController,\n },\n {\n identifier: \"tables--selection--item\",\n controllerConstructor: SelectionItemController,\n },\n {\n identifier: \"tables--selection--table\",\n controllerConstructor: SelectionTableController,\n },\n {\n identifier: \"tables--query\",\n controllerConstructor: QueryController,\n },\n {\n identifier: \"tables--query-input\",\n controllerConstructor: QueryInputController,\n },\n];\n\nexport { Definitions as default };\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableRowController extends Controller {\n static values = {\n params: Object,\n };\n\n connect() {\n // index from server may be inconsistent with the visual ordering,\n // especially if this is a new node. Use positional indexes instead,\n // as these are the values we will send on save.\n this.index = domIndex(this.row);\n }\n\n paramsValueChanged(params) {\n this.id = params.id_value;\n }\n\n dragUpdate(offset) {\n this.dragOffset = offset;\n this.row.style.position = \"relative\";\n this.row.style.top = offset + \"px\";\n this.row.style.zIndex = \"1\";\n this.row.toggleAttribute(\"dragging\", true);\n }\n\n /**\n * Called on items that are not the dragged item during drag. Updates the\n * visual position of the item relative to the dragged item.\n *\n * @param index {number} intended index of the item during drag\n */\n updateVisually(index) {\n this.row.style.position = \"relative\";\n this.row.style.top = `${\n this.row.offsetHeight * (index - this.dragIndex)\n }px`;\n }\n\n /**\n * Set the index value of the item. This is called on all items after a drop\n * event. If the index is different to the params index then this item has\n * changed.\n *\n * @param index {number} the new index value\n */\n updateIndex(index) {\n this.index = index;\n }\n\n /** Retrieve params for use in the form */\n params(scope) {\n const { id_name, id_value, index_name } = this.paramsValue;\n return [\n { name: `${scope}[${id_value}][${id_name}]`, value: this.id },\n { name: `${scope}[${id_value}][${index_name}]`, value: this.index },\n ];\n }\n\n /**\n * Restore any visual changes made during drag and remove the drag state.\n */\n reset() {\n delete this.dragOffset;\n this.row.removeAttribute(\"style\");\n this.row.removeAttribute(\"dragging\");\n }\n\n /**\n * @returns {boolean} true when the item has a change to its index value\n */\n get hasChanges() {\n return this.paramsValue.index_value !== this.index;\n }\n\n /**\n * Calculate the relative index of the item during drag. This is used to\n * sort items during drag as it takes into account any uncommitted changes\n * to index caused by the drag offset.\n *\n * @returns {number} index for the purposes of drag and drop ordering\n */\n get dragIndex() {\n if (this.dragOffset && this.dragOffset !== 0) {\n return this.index + Math.round(this.dragOffset / this.row.offsetHeight);\n } else {\n return this.index;\n }\n }\n\n /**\n * Index value for use in comparisons during drag. This is used to determine\n * whether the dragged item is above or below another item. If this item is\n * being dragged then we offset the index by 0.5 to ensure that it jumps up\n * or down when it reaches the midpoint of the item above or below it.\n *\n * @returns {number}\n */\n get comparisonIndex() {\n if (this.dragOffset) {\n return this.dragIndex + (this.dragOffset > 0 ? 0.5 : -0.5);\n } else {\n return this.index;\n }\n }\n\n /**\n * The containing row element.\n *\n * @returns {HTMLElement}\n */\n get row() {\n return this.element.parentElement;\n }\n}\n\nfunction domIndex(element) {\n return Array.from(element.parentElement.children).indexOf(element);\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableFormController extends Controller {\n static values = { scope: String };\n\n add(item) {\n item.params(this.scopeValue).forEach(({ name, value }) => {\n this.element.insertAdjacentHTML(\n \"beforeend\",\n `<input type=\"hidden\" name=\"${name}\" value=\"${value}\" data-generated>`,\n );\n });\n }\n\n submit() {\n if (this.inputs.length === 0) return;\n\n this.element.requestSubmit();\n }\n\n clear() {\n this.inputs.forEach((input) => input.remove());\n }\n\n get inputs() {\n return this.element.querySelectorAll(\"input[data-generated]\");\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class SelectionFormController extends Controller {\n static values = {\n count: Number,\n primaryKey: { type: String, default: \"id\" },\n };\n static targets = [\"count\", \"singular\", \"plural\"];\n\n connect() {\n this.countValue = this.inputs.length;\n }\n\n /**\n * @param id to toggle\n * @return {boolean} true if selected, false if unselected\n */\n toggle(id) {\n const input = this.input(id);\n\n if (input) {\n input.remove();\n } else {\n this.element.insertAdjacentHTML(\n \"beforeend\",\n `<input type=\"hidden\" name=\"${this.primaryKeyValue}[]\" value=\"${id}\">`,\n );\n }\n\n this.countValue = this.visibleInputs.length;\n\n return !input;\n }\n\n /**\n * @param id to toggle visibility\n * @return {boolean} true if visible, false if not visible\n */\n visible(id, visible) {\n const input = this.input(id);\n\n if (input) {\n input.disabled = !visible;\n }\n\n this.countValue = this.visibleInputs.length;\n\n return !input;\n }\n\n /**\n * @returns {boolean} true if the given id is currently selected\n */\n isSelected(id) {\n return !!this.input(id);\n }\n\n get inputs() {\n return this.element.querySelectorAll(\n `input[name=\"${this.primaryKeyValue}[]\"]`,\n );\n }\n\n get visibleInputs() {\n return Array.from(this.inputs).filter((i) => !i.disabled);\n }\n\n input(id) {\n return this.element.querySelector(\n `input[name=\"${this.primaryKeyValue}[]\"][value=\"${id}\"]`,\n );\n }\n\n countValueChanged(count) {\n this.element.toggleAttribute(\"hidden\", count === 0);\n this.countTarget.textContent = count;\n this.singularTarget.toggleAttribute(\"hidden\", count !== 1);\n this.pluralTarget.toggleAttribute(\"hidden\", count === 1);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class SelectionTableController extends Controller {\n static targets = [\"header\", \"item\"];\n static outlets = [\"tables--selection--form\"];\n\n itemTargetConnected(item) {\n this.update();\n }\n\n itemTargetDisconnected(item) {\n this.update();\n }\n\n toggleHeader(e) {\n this.items.forEach((item) => {\n if (item.checkedValue === e.target.checked) return;\n\n item.checkedValue = this.tablesSelectionFormOutlet.toggle(item.id);\n });\n }\n\n async update() {\n this.updating ||= Promise.resolve().then(() => {\n this.#update();\n delete this.updating;\n });\n\n return this.updating;\n }\n\n #update() {\n let present = 0;\n let checked = 0;\n\n this.items.forEach((item) => {\n present++;\n if (item.checkedValue) checked++;\n });\n\n this.headerInput.checked = present > 0 && checked === present;\n this.headerInput.indeterminate = checked > 0 && checked !== present;\n }\n\n get headerInput() {\n return this.headerTarget.querySelector(\"input\");\n }\n\n get items() {\n return this.itemTargets.map((el) => this.#itemOutlet(el)).filter((c) => c);\n }\n\n /**\n * Ideally we would be using outlets, but as of turbo 8.0.4 outlets do not fire disconnect events when morphing.\n *\n * Instead, we're using the targets to finds the controller.\n */\n #itemOutlet(el) {\n return this.application.getControllerForElementAndIdentifier(\n el,\n \"tables--selection--item\",\n );\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class QueryController extends Controller {\n static targets = [\"modal\"];\n\n disconnect() {\n delete this.pending;\n\n document.removeEventListener(\"selectionchange\", this.selection);\n }\n\n focus() {\n if (document.activeElement === this.query) return;\n\n this.query.addEventListener(\n \"focusin\",\n (e) => {\n e.target.setSelectionRange(-1, -1);\n },\n { once: true },\n );\n\n this.query.focus();\n }\n\n closeModal() {\n delete this.modalTarget.dataset.open;\n\n if (document.activeElement === this.query) document.activeElement.blur();\n\n document.removeEventListener(\"selectionchange\", this.selection);\n }\n\n openModal() {\n this.modalTarget.dataset.open = true;\n\n document.addEventListener(\"selectionchange\", this.selection);\n }\n\n /**\n * If the user presses escape once, clear the input.\n * If the user presses escape again, get them out of here.\n */\n clear() {\n if (this.query.value === \"\") {\n this.closeModal();\n } else {\n this.query.value = \"\";\n this.query.dispatchEvent(new Event(\"input\"));\n this.query.dispatchEvent(new Event(\"change\"));\n this.update();\n }\n }\n\n submit() {\n const hasFocus = this.isFocused;\n const position = hasFocus && this.query.selectionStart;\n\n if (this.pending) {\n clearTimeout(this.pending);\n delete this.pending;\n }\n\n // prevent an unnecessary `?q=` parameter from appearing in the URL\n if (this.query.value === \"\") {\n this.query.disabled = true;\n\n // restore input and focus after form submission\n setTimeout(() => {\n this.query.disabled = false;\n if (hasFocus) this.query.focus();\n }, 0);\n }\n\n // add/remove current cursor position\n if (hasFocus && position) {\n this.position.value = position;\n this.position.disabled = false;\n } else {\n this.position.value = \"\";\n this.position.disabled = true;\n }\n }\n\n update = () => {\n if (this.pending) clearTimeout(this.pending);\n this.pending = setTimeout(() => {\n this.element.requestSubmit();\n }, 300);\n };\n\n selection = () => {\n if (this.isFocused && this.query.value.length > 0) this.update();\n };\n\n beforeMorphAttribute(e) {\n switch (e.detail.attributeName) {\n case \"data-open\":\n e.preventDefault();\n break;\n }\n }\n\n get query() {\n return this.element.querySelector(\"[role=searchbox]\");\n }\n\n get position() {\n return this.element.querySelector(\"input[name=p]\");\n }\n\n get isFocused() {\n return this.query === document.activeElement;\n }\n}\n"],"names":["DragState","constructor","list","event","id","this","cursorOffset","offsetY","initialPosition","target","offsetTop","targetId","updateCursor","row","callback","listOffset","getBoundingClientRect","top","itemPosition","clientY","updateItemPosition","updateScroll","previousScrollOffset","scrollDelta","position","Math","max","min","offsetHeight","SelectionItemController","Controller","static","params","Object","checked","Boolean","tablesSelectionFormOutletConnected","form","visible","checkedValue","isSelected","disconnect","hasTablesSelectionFormOutlet","tablesSelectionFormOutlet","change","e","preventDefault","toggle","paramsValue","paramsValueChanged","previous","update","checkedValueChanged","updating","Promise","resolve","then","element","querySelector","dispatch","detail","selected","Parser","tokens","values","parse","input","query","StringScanner","isEos","push","skipWhitespace","value","takeTagged","takeUntagged","token","scan","Token","matched","Untagged","key","valueAt","separator","takeArrayValue","takeSingleValue","Tagged","start","takeDelimiter","end","Array","takeQuotedValue","takeUnquotedValue","Value","render","document","createTextNode","span","createElement","className","innerText","super","appendChild","array","forEach","last","length","regex","match","exec","substring","index","Definitions","identifier","controllerConstructor","connect","from","parentElement","children","indexOf","id_value","dragUpdate","offset","dragOffset","style","zIndex","toggleAttribute","updateVisually","dragIndex","updateIndex","scope","id_name","index_name","name","reset","removeAttribute","hasChanges","index_value","round","comparisonIndex","startDragging","dragState","addEventListener","mousemove","mouseup","window","scroll","stopDragging","removeEventListener","tablesOrderableItemOutlets","item","drop","dragItem","newIndex","targetItem","insertAdjacentElement","commitChanges","tablesOrderableFormOutlet","clear","add","submit","mousedown","isDragging","animate","ticking","requestAnimationFrame","tablesOrderableFormOutlets","tablesOrderableFormOutletConnected","tablesOrderableFormOutletDisconnected","beforeMorphAttribute","attributeName","tagName","currentItems","find","toSorted","a","b","String","scopeValue","insertAdjacentHTML","inputs","requestSubmit","remove","querySelectorAll","count","Number","primaryKey","type","default","countValue","primaryKeyValue","visibleInputs","disabled","filter","i","countValueChanged","countTarget","textContent","singularTarget","pluralTarget","itemTargetConnected","itemTargetDisconnected","toggleHeader","items","present","headerInput","indeterminate","headerTarget","itemTargets","map","el","itemOutlet","c","application","getControllerForElementAndIdentifier","pending","selection","focus","activeElement","setSelectionRange","once","closeModal","modalTarget","dataset","open","blur","openModal","dispatchEvent","Event","hasFocus","isFocused","selectionStart","clearTimeout","setTimeout","queryValue","inputTarget","connected","queryValueChanged","highlightTarget","innerHTML"],"mappings":"gDA2OA,MAAMA,EAMJ,WAAAC,CAAYC,EAAMC,EAAOC,GAEvBC,KAAKC,aAAeH,EAAMI,QAG1BF,KAAKG,gBAAkBL,EAAMM,OAAOC,UAAYR,EAAKQ,UAGrDL,KAAKM,SAAWP,CACjB,CAUD,YAAAQ,CAAaV,EAAMW,EAAKV,EAAOW,GAG7BT,KAAKU,WAAab,EAAKc,wBAAwBC,IAO/C,IAAIC,EAHmBf,EAAMgB,QAAUd,KAAKU,WAGRV,KAAKC,aAEzCD,MAAKe,EAAoBlB,EAAMW,EAAKK,EAAcJ,EACnD,CAUD,YAAAO,CAAanB,EAAMW,EAAKC,GACtB,MAAMQ,EAAuBjB,KAAKU,WAIlCV,KAAKU,WAAab,EAAKc,wBAAwBC,IAG/C,MAAMM,EAAcD,EAAuBjB,KAAKU,WAG1CS,EAAWnB,KAAKmB,SAAWD,EAEjClB,MAAKe,EAAoBlB,EAAMW,EAAKW,EAAUV,EAC/C,CAED,EAAAM,CAAoBlB,E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,CAAkBzK,GAChB9D,KAAKwO,gBAAgBC,UAAY,IAEjC,IAAIhL,GAASG,MAAME,GAAOJ,OAAOwC,SAAS5B,IACxCtE,KAAKwO,gBAAgBxI,YAAY1B,EAAMkB,SAAS,GAEnD"}
1
+ {"version":3,"file":"tables.min.js","sources":["../../../javascript/tables/orderable/list_controller.js","../../../javascript/tables/selection/item_controller.js","../../../javascript/tables/query_input_controller.js","../../../javascript/tables/application.js","../../../javascript/tables/orderable/item_controller.js","../../../javascript/tables/orderable/form_controller.js","../../../javascript/tables/selection/form_controller.js","../../../javascript/tables/selection/table_controller.js","../../../javascript/tables/query_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableListController extends Controller {\n static outlets = [\"tables--orderable--item\", \"tables--orderable--form\"];\n\n //region State transitions\n\n startDragging(dragState) {\n this.dragState = dragState;\n\n document.addEventListener(\"mousemove\", this.mousemove);\n document.addEventListener(\"mouseup\", this.mouseup);\n window.addEventListener(\"scroll\", this.scroll, true);\n\n this.element.style.position = \"relative\";\n }\n\n stopDragging() {\n const dragState = this.dragState;\n delete this.dragState;\n\n document.removeEventListener(\"mousemove\", this.mousemove);\n document.removeEventListener(\"mouseup\", this.mouseup);\n window.removeEventListener(\"scroll\", this.scroll, true);\n\n this.element.removeAttribute(\"style\");\n this.tablesOrderableItemOutlets.forEach((item) => item.reset());\n\n return dragState;\n }\n\n drop() {\n // note: early returns guard against turbo updates that prevent us finding\n // the right item to drop on. In this situation it's better to discard the\n // drop than to drop in the wrong place.\n\n const dragItem = this.dragItem;\n\n if (!dragItem) return;\n\n const newIndex = dragItem.dragIndex;\n const targetItem = this.tablesOrderableItemOutlets[newIndex];\n\n if (!targetItem) return;\n\n // swap the dragged item into the correct position for its current offset\n if (newIndex < dragItem.index) {\n targetItem.row.insertAdjacentElement(\"beforebegin\", dragItem.row);\n } else if (newIndex > dragItem.index) {\n targetItem.row.insertAdjacentElement(\"afterend\", dragItem.row);\n }\n\n // reindex all items based on their new positions\n this.tablesOrderableItemOutlets.forEach((item, index) =>\n item.updateIndex(index),\n );\n\n // save the changes\n this.commitChanges();\n }\n\n commitChanges() {\n // clear any existing inputs to prevent duplicates\n this.tablesOrderableFormOutlet.clear();\n\n // insert any items that have changed position\n this.tablesOrderableItemOutlets.forEach((item) => {\n if (item.hasChanges) this.tablesOrderableFormOutlet.add(item);\n });\n\n this.tablesOrderableFormOutlet.submit();\n }\n\n //endregion\n\n //region Events\n\n mousedown(event) {\n if (this.isDragging) return;\n\n const target = this.#targetItem(event.target);\n\n if (!target) return;\n\n event.preventDefault(); // prevent built-in drag\n\n this.startDragging(new DragState(this.element, event, target.id));\n\n this.dragState.updateCursor(this.element, target.row, event, this.animate);\n }\n\n mousemove = (event) => {\n if (!this.isDragging) return;\n\n event.preventDefault(); // prevent build-in drag\n\n if (this.ticking) return;\n\n this.ticking = true;\n\n window.requestAnimationFrame(() => {\n this.ticking = false;\n this.dragState?.updateCursor(\n this.element,\n this.dragItem.row,\n event,\n this.animate,\n );\n });\n };\n\n scroll = (event) => {\n if (!this.isDragging || this.ticking) return;\n\n this.ticking = true;\n\n window.requestAnimationFrame(() => {\n this.ticking = false;\n this.dragState?.updateScroll(\n this.element,\n this.dragItem.row,\n this.animate,\n );\n });\n };\n\n mouseup = (event) => {\n if (!this.isDragging) return;\n\n this.drop();\n this.stopDragging();\n this.tablesOrderableFormOutlets.forEach((form) => delete form.dragState);\n };\n\n tablesOrderableFormOutletConnected(form, element) {\n if (form.dragState) {\n // restore the previous controller's state\n this.startDragging(form.dragState);\n }\n }\n\n tablesOrderableFormOutletDisconnected(form, element) {\n if (this.isDragging) {\n // cache drag state in the form\n form.dragState = this.stopDragging();\n }\n }\n\n beforeMorphAttribute(e) {\n switch (e.detail.attributeName) {\n case \"dragging\": // set to track the item being dragged\n e.preventDefault();\n break;\n case \"style\": // used to animate rows moving up and down\n if (e.target.tagName === \"TBODY\" || e.target.tagName === \"TR\") {\n e.preventDefault();\n }\n break;\n }\n }\n\n //endregion\n\n //region Helpers\n\n /**\n * Updates the position of the drag item with a relative offset. Updates\n * other items relative to the new position of the drag item, as required.\n *\n * @callback {OrderableListController~animate}\n * @param {number} offset\n */\n animate = (offset) => {\n const dragItem = this.dragItem;\n\n // Visually update the dragItem so it follows the cursor\n dragItem.dragUpdate(offset);\n\n // Visually updates the position of all items in the list relative to the\n // dragged item. No actual changes to orderings at this stage.\n this.#currentItems.forEach((item, index) => {\n if (item === dragItem) return;\n item.updateVisually(index);\n });\n };\n\n get isDragging() {\n return !!this.dragState;\n }\n\n get dragItem() {\n if (!this.isDragging) return null;\n\n return this.tablesOrderableItemOutlets.find(\n (item) => item.id === this.dragState.targetId,\n );\n }\n\n /**\n * Returns the current items in the list, sorted by their current index.\n * Current uses the drag index if the item is being dragged, if set.\n *\n * @returns {Array[OrderableRowController]}\n */\n get #currentItems() {\n return this.tablesOrderableItemOutlets.toSorted(\n (a, b) => a.comparisonIndex - b.comparisonIndex,\n );\n }\n\n /**\n * Returns the item outlet that was clicked on, if any.\n *\n * @param element {HTMLElement} the clicked ordinal cell\n * @returns {OrderableRowController}\n */\n #targetItem(element) {\n return this.tablesOrderableItemOutlets.find(\n (item) => item.element === element,\n );\n }\n\n //endregion\n}\n\n/**\n * During drag we want to be able to translate a document-relative coordinate\n * into a coordinate relative to the list element. This state object calculates\n * and stores internal state so that we can translate absolute page coordinates\n * from mouse events into relative offsets for the list items within the list\n * element.\n *\n * We also keep track of the drag target so that if the controller is attached\n * to a new element during the drag we can continue after the turbo update.\n */\nclass DragState {\n /**\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param event {MouseEvent} the initial event\n * @param id {String} the id of the element being dragged\n */\n constructor(list, event, id) {\n // cursor offset is the offset of the cursor relative to the drag item\n this.cursorOffset = event.offsetY;\n\n // initial offset is the offset position of the drag item at drag start\n this.initialPosition = event.target.offsetTop - list.offsetTop;\n\n // id of the item being dragged\n this.targetId = id;\n }\n\n /**\n * Calculates the offset of the drag item relative to its initial position.\n *\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param row {HTMLElement} the row being dragged\n * @param event {MouseEvent} the current event\n * @param callback {OrderableListController~animate} updates the drag item with a relative offset\n */\n updateCursor(list, row, event, callback) {\n // Calculate and store the list offset relative to the viewport\n // This value is cached so we can calculate the outcome of any scroll events\n this.listOffset = list.getBoundingClientRect().top;\n\n // Calculate the position of the cursor relative to the list.\n // Accounts for scroll offsets by using the item's bounding client rect.\n const cursorPosition = event.clientY - this.listOffset;\n\n // intended item position relative to the list, from cursor position\n let itemPosition = cursorPosition - this.cursorOffset;\n\n this.#updateItemPosition(list, row, itemPosition, callback);\n }\n\n /**\n * Animates the item's position as the list scrolls. Requires a previous call\n * to set the scroll offset.\n *\n * @param list {HTMLElement} the list controller's element (tbody)\n * @param row {HTMLElement} the row being dragged\n * @param callback {OrderableListController~animate} updates the drag item with a relative offset\n */\n updateScroll(list, row, callback) {\n const previousScrollOffset = this.listOffset;\n\n // Calculate and store the list offset relative to the viewport\n // This value is cached so we can calculate the outcome of any scroll events\n this.listOffset = list.getBoundingClientRect().top;\n\n // Calculate the change in scroll offset since the last update\n const scrollDelta = previousScrollOffset - this.listOffset;\n\n // intended item position relative to the list, from cursor position\n const position = this.position + scrollDelta;\n\n this.#updateItemPosition(list, row, position, callback);\n }\n\n #updateItemPosition(list, row, position, callback) {\n // ensure itemPosition is within the bounds of the list (tbody)\n position = Math.max(position, 0);\n position = Math.min(position, list.offsetHeight - row.offsetHeight);\n\n // cache the item's position relative to the list for use in scroll events\n this.position = position;\n\n // Item has position: relative, so we want to calculate the amount to move\n // the item relative to it's DOM position to represent how much it has been\n // dragged by.\n const offset = position - this.initialPosition;\n\n // Convert itemPosition from offset relative to list to offset relative to\n // its position within the DOM (if it hadn't moved).\n callback(offset);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Couples an input element in a row to the selection form which is turbo-permanent and outside the table.\n * When the input is toggled, the form will create/destroy hidden inputs. The checkbox inside this cell will follow\n * the hidden inputs.\n *\n * Cell value may change when:\n * * cell connects, e.g. when the user paginates\n * * cell is re-used by turbo-morph, e.g. pagination\n * * cell is toggled\n * * select-all/de-select-all on table header\n */\nexport default class SelectionItemController extends Controller {\n static outlets = [\"tables--selection--form\"];\n static values = {\n params: Object,\n checked: Boolean,\n };\n\n tablesSelectionFormOutletConnected(form) {\n form.visible(this.id, true);\n this.checkedValue = form.isSelected(this.id);\n }\n\n disconnect() {\n // Remove from form's list of visible selections.\n // This should be an outlet disconnect, but those events are not reliable in turbo 8.0\n if (this.hasTablesSelectionFormOutlet) {\n this.tablesSelectionFormOutlet.visible(this.id, false);\n }\n }\n\n change(e) {\n e.preventDefault();\n\n this.checkedValue = this.tablesSelectionFormOutlet.toggle(this.id);\n }\n\n get id() {\n return this.paramsValue.id;\n }\n\n /**\n * Update checked to match match selection form. This occurs when the item is re-used by turbo-morph.\n */\n paramsValueChanged(params, previous) {\n if (!this.hasTablesSelectionFormOutlet) return;\n\n // if id is changing (e.g. morph) then let the form know that the previous id is now not visible\n if (previous.id !== params.id) {\n this.tablesSelectionFormOutlet.visible(previous.id, false);\n }\n\n // tell form that our id is now visible in the table\n this.tablesSelectionFormOutlet.visible(params.id, true);\n\n // id has changed, so update checked from form\n this.checkedValue = this.tablesSelectionFormOutlet.isSelected(params.id);\n\n // propagate changes\n this.update();\n }\n\n /**\n * Update input to match checked. This occurs when the item is toggled, connected, or morphed.\n */\n checkedValueChanged() {\n if (!this.hasTablesSelectionFormOutlet) return;\n\n // ensure that checked matches the form, i.e. if morphed\n this.checkedValue = this.tablesSelectionFormOutlet.isSelected(this.id);\n\n // propagate changes\n this.update();\n }\n\n /**\n * Notify table that id or value may have changed. Note that this may fire when nothing has changed.\n *\n * Debouncing to minimise dom updates.\n */\n async update() {\n this.updating ||= Promise.resolve().then(() => {\n this.#update();\n delete this.updating;\n });\n\n return this.updating;\n }\n\n #update() {\n this.element.querySelector(\"input\").checked = this.checkedValue;\n this.dispatch(\"select\", {\n detail: { id: this.id, selected: this.checkedValue },\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class QueryInputController extends Controller {\n static targets = [\"input\", \"highlight\"];\n static values = { query: String };\n\n connect() {\n this.queryValue = this.inputTarget.value;\n this.element.dataset.connected = \"\";\n }\n\n disconnect() {\n delete this.element.dataset.connected;\n }\n\n update() {\n this.queryValue = this.inputTarget.value;\n }\n\n queryValueChanged(query) {\n this.highlightTarget.innerHTML = \"\";\n\n new Parser().parse(query).tokens.forEach((token) => {\n this.highlightTarget.appendChild(token.render());\n });\n }\n\n replaceToken(e) {\n let tokenToAdd = e.detail.token.toString();\n\n // wrap in quotes if it contains a spaces or special characters\n if (/\\s/.exec(tokenToAdd)) {\n tokenToAdd = `\"${tokenToAdd}\"`;\n }\n\n const indexPosition = e.detail.position;\n let caretPosition = indexPosition + tokenToAdd.length;\n let sliceStart = indexPosition;\n let sliceEnd = indexPosition;\n\n // detect if position has a token already, if so, replace it\n const existingToken = new Parser()\n .parse(this.queryValue)\n .tokenAtPosition(indexPosition);\n if (existingToken) {\n // We don't want to include the trailing space as we are replacing an existing value\n tokenToAdd = tokenToAdd.trim();\n\n // Slice up to the beginning of the tokens value (not the initial caret position)\n sliceStart = existingToken.startOfValue();\n\n // Slice after the end of the tokens value\n sliceEnd = existingToken.endOfValue();\n\n // The end position of the newly added token\n caretPosition = sliceStart + tokenToAdd.length;\n }\n\n // Replace any text within sliceStart and sliceEnd with tokenToAdd\n this.inputTarget.value =\n this.queryValue.slice(0, sliceStart) +\n tokenToAdd +\n this.queryValue.slice(sliceEnd);\n\n // Re focus the input at the end of the newly added token\n this.update();\n this.inputTarget.focus();\n this.inputTarget.setSelectionRange(caretPosition, caretPosition);\n }\n}\n\nclass Parser {\n constructor() {\n this.tokens = [];\n this.values = null;\n }\n\n parse(input) {\n const query = new StringScanner(input);\n\n while (!query.isEos()) {\n this.push(this.skipWhitespace(query));\n\n const value = this.takeTagged(query) || this.takeUntagged(query);\n\n if (!this.push(value)) break;\n }\n\n return this;\n }\n\n push(token) {\n if (token) {\n this.values ? this.values.push(token) : this.tokens.push(token);\n }\n\n return !!token;\n }\n\n skipWhitespace(query) {\n if (!query.scan(/\\s+/)) return;\n\n return new Token(query.matched(), query.position);\n }\n\n takeUntagged(query) {\n if (!query.scan(/\\S+/)) return;\n\n return new Untagged(query.matched(), query.position);\n }\n\n takeTagged(query) {\n if (!query.scan(/(\\w+(?:\\.\\w+)?)(:\\s*)/)) return;\n\n const key = query.valueAt(1);\n const separator = query.valueAt(2);\n\n const value =\n this.takeArrayValue(query) || this.takeSingleValue(query) || new Token();\n\n return new Tagged(key, separator, value, query.position);\n }\n\n takeArrayValue(query) {\n if (!query.scan(/\\[\\s*/)) return;\n\n const start = new Token(query.matched(), query.position);\n const values = (this.values = []);\n\n while (!query.isEos()) {\n if (!this.push(this.takeSingleValue(query))) break;\n if (!this.push(this.takeDelimiter(query))) break;\n }\n\n query.scan(/\\s*]/);\n const end = new Token(query.matched(), query.position);\n\n this.values = null;\n\n return new ArrayToken(start, values, end);\n }\n\n takeDelimiter(query) {\n if (!query.scan(/\\s*,\\s*/)) return;\n\n return new Token(query.matched(), query.position);\n }\n\n takeSingleValue(query) {\n return this.takeQuotedValue(query) || this.takeUnquotedValue(query);\n }\n\n takeQuotedValue(query) {\n if (!query.scan(/\"([^\"]*)\"/)) return;\n\n return new Value(query.matched(), query.position);\n }\n\n takeUnquotedValue(query) {\n if (!query.scan(/[^ \\],]*/)) return;\n\n return new Value(query.matched(), query.position);\n }\n\n tokenAtPosition(position) {\n return this.tokens\n .filter((t) => t instanceof Tagged || t instanceof Untagged)\n .find((t) => t.range.includes(position));\n }\n}\n\nclass Token {\n constructor(value = \"\", position) {\n this.value = value;\n this.length = this.value.length;\n this.start = position - this.length;\n this.end = this.start + this.length;\n this.range = this.arrayRange(this.start, this.end);\n }\n\n render() {\n return document.createTextNode(this.value);\n }\n\n arrayRange(start, stop) {\n return Array.from(\n { length: stop - start + 1 },\n (value, index) => start + index,\n );\n }\n\n startOfValue() {\n return this.start;\n }\n\n endOfValue() {\n return this.end;\n }\n}\n\nclass Value extends Token {\n render() {\n const span = document.createElement(\"span\");\n span.className = \"value\";\n span.innerText = this.value;\n\n return span;\n }\n}\n\nclass Tagged extends Token {\n constructor(key, separator, value, position) {\n super();\n\n this.key = key;\n this.separator = separator;\n this.value = value;\n this.length = key.length + separator.length + value.value.length;\n this.start = position - this.length;\n this.end = this.start + this.length;\n this.range = this.arrayRange(this.start, this.end);\n }\n\n render() {\n const span = document.createElement(\"span\");\n span.className = \"tag\";\n\n const key = document.createElement(\"span\");\n key.className = \"key\";\n key.innerText = this.key;\n\n span.appendChild(key);\n span.appendChild(document.createTextNode(this.separator));\n span.appendChild(this.value.render());\n\n return span;\n }\n\n startOfValue() {\n return this.value.startOfValue();\n }\n\n endOfValue() {\n return this.value.endOfValue();\n }\n}\n\nclass Untagged extends Token {\n render() {\n const span = document.createElement(\"span\");\n span.className = \"untagged\";\n span.innerText = this.value;\n return span;\n }\n}\n\nclass ArrayToken extends Token {\n constructor(start, values, end) {\n super();\n\n this.start = start;\n this.values = values;\n this.end = end;\n this.range = this.arrayRange(start.start, end.range[end.length]);\n this.length =\n start.length +\n values.reduce((length, value) => length + value.length, 0) +\n end.length;\n }\n\n render() {\n const array = document.createElement(\"span\");\n array.className = \"array-values\";\n array.appendChild(this.start.render());\n\n this.values.forEach((value) => {\n const span = document.createElement(\"span\");\n span.appendChild(value.render());\n array.appendChild(span);\n });\n\n array.appendChild(this.end.render());\n\n return array;\n }\n\n startOfValue() {\n return this.start.start;\n }\n\n endOfValue() {\n return this.end.end;\n }\n}\n\nclass StringScanner {\n constructor(input) {\n this.input = input;\n this.position = 0;\n this.last = null;\n }\n\n isEos() {\n return this.position >= this.input.length;\n }\n\n scan(regex) {\n const match = regex.exec(this.input.substring(this.position));\n if (match?.index === 0) {\n this.last = match;\n this.position += match[0].length;\n return true;\n } else {\n this.last = {};\n return false;\n }\n }\n\n matched() {\n return this.last && this.last[0];\n }\n\n valueAt(index) {\n return this.last && this.last[index];\n }\n}\n","import OrderableItemController from \"./orderable/item_controller\";\nimport OrderableListController from \"./orderable/list_controller\";\nimport OrderableFormController from \"./orderable/form_controller\";\nimport SelectionFormController from \"./selection/form_controller\";\nimport SelectionItemController from \"./selection/item_controller\";\nimport SelectionTableController from \"./selection/table_controller\";\nimport QueryController from \"./query_controller\";\nimport QueryInputController from \"./query_input_controller\";\n\nconst Definitions = [\n {\n identifier: \"tables--orderable--item\",\n controllerConstructor: OrderableItemController,\n },\n {\n identifier: \"tables--orderable--list\",\n controllerConstructor: OrderableListController,\n },\n {\n identifier: \"tables--orderable--form\",\n controllerConstructor: OrderableFormController,\n },\n {\n identifier: \"tables--selection--form\",\n controllerConstructor: SelectionFormController,\n },\n {\n identifier: \"tables--selection--item\",\n controllerConstructor: SelectionItemController,\n },\n {\n identifier: \"tables--selection--table\",\n controllerConstructor: SelectionTableController,\n },\n {\n identifier: \"tables--query\",\n controllerConstructor: QueryController,\n },\n {\n identifier: \"tables--query-input\",\n controllerConstructor: QueryInputController,\n },\n];\n\nexport { Definitions as default };\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableRowController extends Controller {\n static values = {\n params: Object,\n };\n\n connect() {\n // index from server may be inconsistent with the visual ordering,\n // especially if this is a new node. Use positional indexes instead,\n // as these are the values we will send on save.\n this.index = domIndex(this.row);\n }\n\n paramsValueChanged(params) {\n this.id = params.id_value;\n }\n\n dragUpdate(offset) {\n this.dragOffset = offset;\n this.row.style.position = \"relative\";\n this.row.style.top = offset + \"px\";\n this.row.style.zIndex = \"1\";\n this.row.toggleAttribute(\"dragging\", true);\n }\n\n /**\n * Called on items that are not the dragged item during drag. Updates the\n * visual position of the item relative to the dragged item.\n *\n * @param index {number} intended index of the item during drag\n */\n updateVisually(index) {\n this.row.style.position = \"relative\";\n this.row.style.top = `${\n this.row.offsetHeight * (index - this.dragIndex)\n }px`;\n }\n\n /**\n * Set the index value of the item. This is called on all items after a drop\n * event. If the index is different to the params index then this item has\n * changed.\n *\n * @param index {number} the new index value\n */\n updateIndex(index) {\n this.index = index;\n }\n\n /** Retrieve params for use in the form */\n params(scope) {\n const { id_name, id_value, index_name } = this.paramsValue;\n return [\n { name: `${scope}[${id_value}][${id_name}]`, value: this.id },\n { name: `${scope}[${id_value}][${index_name}]`, value: this.index },\n ];\n }\n\n /**\n * Restore any visual changes made during drag and remove the drag state.\n */\n reset() {\n delete this.dragOffset;\n this.row.removeAttribute(\"style\");\n this.row.removeAttribute(\"dragging\");\n }\n\n /**\n * @returns {boolean} true when the item has a change to its index value\n */\n get hasChanges() {\n return this.paramsValue.index_value !== this.index;\n }\n\n /**\n * Calculate the relative index of the item during drag. This is used to\n * sort items during drag as it takes into account any uncommitted changes\n * to index caused by the drag offset.\n *\n * @returns {number} index for the purposes of drag and drop ordering\n */\n get dragIndex() {\n if (this.dragOffset && this.dragOffset !== 0) {\n return this.index + Math.round(this.dragOffset / this.row.offsetHeight);\n } else {\n return this.index;\n }\n }\n\n /**\n * Index value for use in comparisons during drag. This is used to determine\n * whether the dragged item is above or below another item. If this item is\n * being dragged then we offset the index by 0.5 to ensure that it jumps up\n * or down when it reaches the midpoint of the item above or below it.\n *\n * @returns {number}\n */\n get comparisonIndex() {\n if (this.dragOffset) {\n return this.dragIndex + (this.dragOffset > 0 ? 0.5 : -0.5);\n } else {\n return this.index;\n }\n }\n\n /**\n * The containing row element.\n *\n * @returns {HTMLElement}\n */\n get row() {\n return this.element.parentElement;\n }\n}\n\nfunction domIndex(element) {\n return Array.from(element.parentElement.children).indexOf(element);\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class OrderableFormController extends Controller {\n static values = { scope: String };\n\n add(item) {\n item.params(this.scopeValue).forEach(({ name, value }) => {\n this.element.insertAdjacentHTML(\n \"beforeend\",\n `<input type=\"hidden\" name=\"${name}\" value=\"${value}\" data-generated>`,\n );\n });\n }\n\n submit() {\n if (this.inputs.length === 0) return;\n\n this.element.requestSubmit();\n }\n\n clear() {\n this.inputs.forEach((input) => input.remove());\n }\n\n get inputs() {\n return this.element.querySelectorAll(\"input[data-generated]\");\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class SelectionFormController extends Controller {\n static values = {\n count: Number,\n primaryKey: { type: String, default: \"id\" },\n };\n static targets = [\"count\", \"singular\", \"plural\"];\n\n connect() {\n this.countValue = this.inputs.length;\n }\n\n /**\n * @param id to toggle\n * @return {boolean} true if selected, false if unselected\n */\n toggle(id) {\n const input = this.input(id);\n\n if (input) {\n input.remove();\n } else {\n this.element.insertAdjacentHTML(\n \"beforeend\",\n `<input type=\"hidden\" name=\"${this.primaryKeyValue}[]\" value=\"${id}\">`,\n );\n }\n\n this.countValue = this.visibleInputs.length;\n\n return !input;\n }\n\n /**\n * @param id to toggle visibility\n * @return {boolean} true if visible, false if not visible\n */\n visible(id, visible) {\n const input = this.input(id);\n\n if (input) {\n input.disabled = !visible;\n }\n\n this.countValue = this.visibleInputs.length;\n\n return !input;\n }\n\n /**\n * @returns {boolean} true if the given id is currently selected\n */\n isSelected(id) {\n return !!this.input(id);\n }\n\n get inputs() {\n return this.element.querySelectorAll(\n `input[name=\"${this.primaryKeyValue}[]\"]`,\n );\n }\n\n get visibleInputs() {\n return Array.from(this.inputs).filter((i) => !i.disabled);\n }\n\n input(id) {\n return this.element.querySelector(\n `input[name=\"${this.primaryKeyValue}[]\"][value=\"${id}\"]`,\n );\n }\n\n countValueChanged(count) {\n this.element.toggleAttribute(\"hidden\", count === 0);\n this.countTarget.textContent = count;\n this.singularTarget.toggleAttribute(\"hidden\", count !== 1);\n this.pluralTarget.toggleAttribute(\"hidden\", count === 1);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class SelectionTableController extends Controller {\n static targets = [\"header\", \"item\"];\n static outlets = [\"tables--selection--form\"];\n\n itemTargetConnected(item) {\n this.update();\n }\n\n itemTargetDisconnected(item) {\n this.update();\n }\n\n toggleHeader(e) {\n this.items.forEach((item) => {\n if (item.checkedValue === e.target.checked) return;\n\n item.checkedValue = this.tablesSelectionFormOutlet.toggle(item.id);\n });\n }\n\n async update() {\n this.updating ||= Promise.resolve().then(() => {\n this.#update();\n delete this.updating;\n });\n\n return this.updating;\n }\n\n #update() {\n let present = 0;\n let checked = 0;\n\n this.items.forEach((item) => {\n present++;\n if (item.checkedValue) checked++;\n });\n\n this.headerInput.checked = present > 0 && checked === present;\n this.headerInput.indeterminate = checked > 0 && checked !== present;\n }\n\n get headerInput() {\n return this.headerTarget.querySelector(\"input\");\n }\n\n get items() {\n return this.itemTargets.map((el) => this.#itemOutlet(el)).filter((c) => c);\n }\n\n /**\n * Ideally we would be using outlets, but as of turbo 8.0.4 outlets do not fire disconnect events when morphing.\n *\n * Instead, we're using the targets to finds the controller.\n */\n #itemOutlet(el) {\n return this.application.getControllerForElementAndIdentifier(\n el,\n \"tables--selection--item\",\n );\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nexport default class QueryController extends Controller {\n static targets = [\"modal\"];\n\n disconnect() {\n delete this.pending;\n\n document.removeEventListener(\"selectionchange\", this.selection);\n }\n\n focus() {\n if (document.activeElement === this.query) return;\n\n this.query.addEventListener(\n \"focusin\",\n (e) => {\n e.target.setSelectionRange(-1, -1);\n },\n { once: true },\n );\n\n this.query.focus();\n }\n\n closeModal() {\n delete this.modalTarget.dataset.open;\n this.query.setAttribute(\"aria-expanded\", false);\n\n if (document.activeElement === this.query) document.activeElement.blur();\n\n document.removeEventListener(\"selectionchange\", this.selection);\n }\n\n openModal() {\n this.modalTarget.dataset.open = true;\n this.query.setAttribute(\"aria-expanded\", true);\n\n document.addEventListener(\"selectionchange\", this.selection);\n }\n\n /**\n * If the user presses escape once, clear the input.\n * If the user presses escape again, get them out of here.\n */\n clear() {\n if (this.query.value === \"\") {\n this.closeModal();\n } else {\n this.query.value = \"\";\n this.query.dispatchEvent(new Event(\"input\"));\n this.query.dispatchEvent(new Event(\"change\"));\n this.update();\n }\n }\n\n submit() {\n const hasFocus = this.isFocused;\n const position = hasFocus && this.query.selectionStart;\n\n if (this.pending) {\n clearTimeout(this.pending);\n delete this.pending;\n }\n\n // add/remove current cursor position\n if (hasFocus && this.query.value !== \"\") {\n this.position.value = position;\n this.position.disabled = false;\n } else {\n this.position.value = \"\";\n this.position.disabled = true;\n }\n\n // prevent an unnecessary `?q=&p=0` parameter from appearing in the URL\n if (this.query.value === \"\") {\n this.query.disabled = true;\n\n // restore input and focus after form submission\n setTimeout(() => {\n this.query.disabled = false;\n this.position.disabled = false;\n if (hasFocus) this.query.focus();\n }, 0);\n }\n }\n\n update = () => {\n if (this.pending) clearTimeout(this.pending);\n this.pending = setTimeout(() => {\n this.element.requestSubmit();\n }, 300);\n };\n\n selection = () => {\n if (this.isFocused && this.query.value.length > 0) this.update();\n };\n\n beforeMorphAttribute(e) {\n switch (e.detail.attributeName) {\n case \"data-open\":\n e.preventDefault();\n break;\n }\n }\n\n moveToPreviousSuggestion() {\n const prev = this.previousSuggestion || this.lastSuggestion;\n\n if (prev) this.makeSuggestionActive(prev);\n }\n\n moveToNextSuggestion() {\n const next = this.nextSuggestion || this.firstSuggestion;\n\n if (next) this.makeSuggestionActive(next);\n }\n\n selectFirstSuggestion(e) {\n // This is caused by pressing the tab key. We don't want to move focus.\n // Ideally we don't want to always prevent the user from tabbing. We will address this later\n e.preventDefault();\n\n this.firstSuggestion?.dispatchEvent(new CustomEvent(\"query:select\"));\n }\n\n selectActiveSuggestion() {\n if (!this.activeSuggestion) {\n this.closeModal();\n return;\n }\n\n this.activeSuggestion.dispatchEvent(new CustomEvent(\"query:select\"));\n }\n\n selectSuggestion(e) {\n this.query.dispatchEvent(\n new CustomEvent(\"replaceToken\", {\n detail: { token: e.params.value, position: this.query.selectionStart },\n }),\n );\n\n this.clearActiveSuggestion();\n }\n\n makeSuggestionActive(node) {\n if (this.activeSuggestion) {\n this.activeSuggestion.setAttribute(\"aria-selected\", \"false\");\n }\n\n this.query.setAttribute(\"aria-activedescendant\", node.id);\n node.setAttribute(\"aria-selected\", \"true\");\n }\n\n clearActiveSuggestion() {\n if (this.activeSuggestion) {\n this.activeSuggestion.setAttribute(\"aria-selected\", \"false\");\n this.query.removeAttribute(\"aria-activedescendant\");\n }\n }\n\n get activeSuggestion() {\n return this.modalTarget.querySelector(\n `#${this.query.getAttribute(\"aria-activedescendant\")}`,\n );\n }\n\n get previousSuggestion() {\n return this.activeSuggestion?.previousElementSibling;\n }\n\n get nextSuggestion() {\n return this.activeSuggestion?.nextElementSibling;\n }\n\n get firstSuggestion() {\n return this.modalTarget.querySelector(\"#suggestions li:first-of-type\");\n }\n\n get lastSuggestion() {\n return this.modalTarget.querySelector(\"#suggestions li:last-of-type\");\n }\n\n get query() {\n return this.element.querySelector(\"[role=combobox]\");\n }\n\n get position() {\n return this.element.querySelector(\"input[name=p]\");\n }\n\n get isFocused() {\n return this.query === document.activeElement;\n }\n}\n"],"names":["DragState","constructor","list","event","id","this","cursorOffset","offsetY","initialPosition","target","offsetTop","targetId","updateCursor","row","callback","listOffset","getBoundingClientRect","top","itemPosition","clientY","updateItemPosition","updateScroll","previousScrollOffset","scrollDelta","position","Math","max","min","offsetHeight","SelectionItemController","Controller","static","params","Object","checked","Boolean","tablesSelectionFormOutletConnected","form","visible","checkedValue","isSelected","disconnect","hasTablesSelectionFormOutlet","tablesSelectionFormOutlet","change","e","preventDefault","toggle","paramsValue","paramsValueChanged","previous","update","checkedValueChanged","updating","Promise","resolve","then","element","querySelector","dispatch","detail","selected","Parser","tokens","values","parse","input","query","StringScanner","isEos","push","skipWhitespace","value","takeTagged","takeUntagged","token","scan","Token","matched","Untagged","key","valueAt","separator","takeArrayValue","takeSingleValue","Tagged","start","takeDelimiter","end","ArrayToken","takeQuotedValue","takeUnquotedValue","Value","tokenAtPosition","filter","t","find","range","includes","length","arrayRange","render","document","createTextNode","stop","Array","from","index","startOfValue","endOfValue","span","createElement","className","innerText","super","appendChild","reduce","array","forEach","last","regex","match","exec","substring","Definitions","identifier","controllerConstructor","connect","parentElement","children","indexOf","id_value","dragUpdate","offset","dragOffset","style","zIndex","toggleAttribute","updateVisually","dragIndex","updateIndex","scope","id_name","index_name","name","reset","removeAttribute","hasChanges","index_value","round","comparisonIndex","startDragging","dragState","addEventListener","mousemove","mouseup","window","scroll","stopDragging","removeEventListener","tablesOrderableItemOutlets","item","drop","dragItem","newIndex","targetItem","insertAdjacentElement","commitChanges","tablesOrderableFormOutlet","clear","add","submit","mousedown","isDragging","animate","ticking","requestAnimationFrame","tablesOrderableFormOutlets","tablesOrderableFormOutletConnected","tablesOrderableFormOutletDisconnected","beforeMorphAttribute","attributeName","tagName","currentItems","toSorted","a","b","String","scopeValue","insertAdjacentHTML","inputs","requestSubmit","remove","querySelectorAll","count","Number","primaryKey","type","default","countValue","primaryKeyValue","visibleInputs","disabled","i","countValueChanged","countTarget","textContent","singularTarget","pluralTarget","itemTargetConnected","itemTargetDisconnected","toggleHeader","items","present","headerInput","indeterminate","headerTarget","itemTargets","map","el","itemOutlet","c","application","getControllerForElementAndIdentifier","pending","selection","focus","activeElement","setSelectionRange","once","closeModal","modalTarget","dataset","open","setAttribute","blur","openModal","dispatchEvent","Event","hasFocus","isFocused","selectionStart","clearTimeout","setTimeout","moveToPreviousSuggestion","prev","previousSuggestion","lastSuggestion","makeSuggestionActive","moveToNextSuggestion","next","nextSuggestion","firstSuggestion","selectFirstSuggestion","CustomEvent","selectActiveSuggestion","activeSuggestion","selectSuggestion","clearActiveSuggestion","node","getAttribute","previousElementSibling","nextElementSibling","queryValue","inputTarget","connected","queryValueChanged","highlightTarget","innerHTML","replaceToken","tokenToAdd","toString","indexPosition","caretPosition","sliceStart","sliceEnd","existingToken","trim","slice"],"mappings":"gDA2OA,MAAMA,EAMJ,WAAAC,CAAYC,EAAMC,EAAOC,GAEvBC,KAAKC,aAAeH,EAAMI,QAG1BF,KAAKG,gBAAkBL,EAAMM,OAAOC,UAAYR,EAAKQ,UAGrDL,KAAKM,SAA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E,KAAKkQ,WAAWe,MAAM,EAAGJ,GACzBJ,EACAzQ,KAAKkQ,WAAWe,MAAMH,GAGxB9Q,KAAK8C,SACL9C,KAAKmQ,YAAYtC,QACjB7N,KAAKmQ,YAAYpC,kBAAkB6C,EAAeA,EACnD"}
@@ -7,14 +7,14 @@
7
7
  grid-template-areas: "input button";
8
8
  grid-template-columns: 1fr auto;
9
9
 
10
- [role="searchbox"] {
10
+ [role="combobox"] {
11
11
  grid-area: input;
12
12
  background: transparent;
13
13
  caret-color: black;
14
14
  resize: none;
15
15
  }
16
16
 
17
- &[data-connected] [role="searchbox"] {
17
+ &[data-connected] [role="combobox"] {
18
18
  color: transparent;
19
19
  }
20
20
 
@@ -47,6 +47,9 @@
47
47
  }
48
48
 
49
49
  .query-modal {
50
+ --suggestion-hover: rgba(0, 0, 0, 0.1);
51
+ --suggestion-selected: #888;
52
+
50
53
  position: absolute;
51
54
  top: 100%;
52
55
  left: 0;
@@ -76,14 +79,45 @@
76
79
 
77
80
  .content {
78
81
  grid-area: content;
82
+ padding-top: 0.5rem;
83
+ }
84
+
85
+ h4 {
79
86
  padding-inline: 1rem;
80
- padding-block: 0.5rem;
81
87
  }
82
88
 
83
89
  ul {
84
90
  margin-block: 0;
85
91
  padding-inline-start: 0;
86
92
  list-style: none;
93
+
94
+ li {
95
+ position: relative;
96
+ display: flex;
97
+ align-items: baseline;
98
+ padding-inline: 1rem;
99
+ padding-block: 0.125rem;
100
+
101
+ &[aria-selected="true"],
102
+ &:hover {
103
+ outline: none;
104
+ background: var(--suggestion-hover);
105
+ }
106
+
107
+ &[aria-selected="true"]::after {
108
+ content: "";
109
+ position: absolute;
110
+ left: 0;
111
+ top: 0;
112
+ bottom: 0;
113
+ width: 4px;
114
+ background: var(--suggestion-selected);
115
+ }
116
+
117
+ &:hover {
118
+ cursor: pointer;
119
+ }
120
+ }
87
121
  }
88
122
 
89
123
  .error {
@@ -2,7 +2,12 @@
2
2
  <%= form.label name, "Search", hidden: "" %>
3
3
  <%= form.text_area(
4
4
  name,
5
- role: "searchbox",
5
+ role: "combobox",
6
+ aria: {
7
+ controls: "suggestion-dialog",
8
+ expanded: false,
9
+ haspopup: "dialog",
10
+ },
6
11
  placeholder:,
7
12
  autocomplete: "off",
8
13
  rows: 1,
@@ -44,9 +44,13 @@ module Katalyst
44
44
  spellcheck: false,
45
45
  data: {
46
46
  action: %w[
47
+ replaceToken->tables--query-input#replaceToken
47
48
  tables--query-input#update
48
- keydown.enter->tables--query#closeModal:prevent
49
+ keydown.enter->tables--query#selectActiveSuggestion:prevent
49
50
  keydown.esc->tables--query#clear:prevent
51
+ keydown.up->tables--query#moveToPreviousSuggestion:prevent
52
+ keydown.down->tables--query#moveToNextSuggestion:prevent
53
+ keydown.alt+up->tables--query#clearActiveSuggestion:prevent
50
54
  ],
51
55
  tables__query_input_target: "input",
52
56
  },
@@ -8,8 +8,8 @@
8
8
  <% end %>
9
9
  <div class="content">
10
10
  <% if suggestions? %>
11
- <h4><%= t(".suggestions_title") %></h4>
12
- <ul>
11
+ <h4 id="suggestions-title"><%= t(".suggestions_title") %></h4>
12
+ <ul id="suggestions" role="listbox" aria-labelledby="suggestions-title">
13
13
  <% suggestions.each do |suggestion| %>
14
14
  <%= render suggestion %>
15
15
  <% end %>
@@ -19,8 +19,8 @@ module Katalyst
19
19
  end
20
20
 
21
21
  def before_render
22
- collection.suggestions.each do |suggestion|
23
- with_suggestion(suggestion:)
22
+ collection.suggestions.each_with_index do |suggestion, index|
23
+ with_suggestion(suggestion:, index:)
24
24
  end
25
25
  end
26
26
 
@@ -28,7 +28,12 @@ module Katalyst
28
28
 
29
29
  def default_html_attributes
30
30
  {
31
+ id: "suggestion-dialog",
31
32
  class: "query-modal",
33
+ role: "dialog",
34
+ aria: {
35
+ label: t(".suggestions_title"),
36
+ },
32
37
  data: {
33
38
  tables__query_target: "modal",
34
39
  action: ["turbo:before-morph-attribute->tables--query#beforeMorphAttribute"],
@@ -8,15 +8,29 @@ module Katalyst
8
8
 
9
9
  delegate :type, :value, to: :@suggestion
10
10
 
11
- def initialize(suggestion:, **)
11
+ def initialize(suggestion:, index:, **)
12
12
  super(**)
13
13
 
14
14
  @suggestion = suggestion
15
+ @index = index
16
+ end
17
+
18
+ def dom_id
19
+ "suggestion_#{@index}"
15
20
  end
16
21
 
17
22
  def default_html_attributes
18
23
  {
24
+ id: dom_id,
19
25
  class: ["suggestion", type.to_s],
26
+ role: "option",
27
+ data: {
28
+ action: %w[
29
+ click->tables--query#selectSuggestion
30
+ query:select->tables--query#selectSuggestion
31
+ ],
32
+ tables__query_value_param: value_param,
33
+ },
20
34
  }
21
35
  end
22
36
 
@@ -29,6 +43,12 @@ module Katalyst
29
43
  %("#{value}")
30
44
  end
31
45
  end
46
+
47
+ def value_param
48
+ return "#{@suggestion.value}:" if @suggestion.type == :attribute
49
+
50
+ @suggestion.value
51
+ end
32
52
  end
33
53
  end
34
54
  end
@@ -90,6 +90,7 @@ module Katalyst
90
90
  focusin->tables--query#openModal:stop
91
91
  submit->tables--query#submit
92
92
  input->tables--query#update
93
+ keydown.tab->tables--query#selectFirstSuggestion
93
94
  ],
94
95
  },
95
96
  }
@@ -25,6 +25,7 @@ export default class QueryController extends Controller {
25
25
 
26
26
  closeModal() {
27
27
  delete this.modalTarget.dataset.open;
28
+ this.query.setAttribute("aria-expanded", false);
28
29
 
29
30
  if (document.activeElement === this.query) document.activeElement.blur();
30
31
 
@@ -33,6 +34,7 @@ export default class QueryController extends Controller {
33
34
 
34
35
  openModal() {
35
36
  this.modalTarget.dataset.open = true;
37
+ this.query.setAttribute("aria-expanded", true);
36
38
 
37
39
  document.addEventListener("selectionchange", this.selection);
38
40
  }
@@ -61,25 +63,26 @@ export default class QueryController extends Controller {
61
63
  delete this.pending;
62
64
  }
63
65
 
64
- // prevent an unnecessary `?q=` parameter from appearing in the URL
66
+ // add/remove current cursor position
67
+ if (hasFocus && this.query.value !== "") {
68
+ this.position.value = position;
69
+ this.position.disabled = false;
70
+ } else {
71
+ this.position.value = "";
72
+ this.position.disabled = true;
73
+ }
74
+
75
+ // prevent an unnecessary `?q=&p=0` parameter from appearing in the URL
65
76
  if (this.query.value === "") {
66
77
  this.query.disabled = true;
67
78
 
68
79
  // restore input and focus after form submission
69
80
  setTimeout(() => {
70
81
  this.query.disabled = false;
82
+ this.position.disabled = false;
71
83
  if (hasFocus) this.query.focus();
72
84
  }, 0);
73
85
  }
74
-
75
- // add/remove current cursor position
76
- if (hasFocus && position) {
77
- this.position.value = position;
78
- this.position.disabled = false;
79
- } else {
80
- this.position.value = "";
81
- this.position.disabled = true;
82
- }
83
86
  }
84
87
 
85
88
  update = () => {
@@ -101,8 +104,85 @@ export default class QueryController extends Controller {
101
104
  }
102
105
  }
103
106
 
107
+ moveToPreviousSuggestion() {
108
+ const prev = this.previousSuggestion || this.lastSuggestion;
109
+
110
+ if (prev) this.makeSuggestionActive(prev);
111
+ }
112
+
113
+ moveToNextSuggestion() {
114
+ const next = this.nextSuggestion || this.firstSuggestion;
115
+
116
+ if (next) this.makeSuggestionActive(next);
117
+ }
118
+
119
+ selectFirstSuggestion(e) {
120
+ // This is caused by pressing the tab key. We don't want to move focus.
121
+ // Ideally we don't want to always prevent the user from tabbing. We will address this later
122
+ e.preventDefault();
123
+
124
+ this.firstSuggestion?.dispatchEvent(new CustomEvent("query:select"));
125
+ }
126
+
127
+ selectActiveSuggestion() {
128
+ if (!this.activeSuggestion) {
129
+ this.closeModal();
130
+ return;
131
+ }
132
+
133
+ this.activeSuggestion.dispatchEvent(new CustomEvent("query:select"));
134
+ }
135
+
136
+ selectSuggestion(e) {
137
+ this.query.dispatchEvent(
138
+ new CustomEvent("replaceToken", {
139
+ detail: { token: e.params.value, position: this.query.selectionStart },
140
+ }),
141
+ );
142
+
143
+ this.clearActiveSuggestion();
144
+ }
145
+
146
+ makeSuggestionActive(node) {
147
+ if (this.activeSuggestion) {
148
+ this.activeSuggestion.setAttribute("aria-selected", "false");
149
+ }
150
+
151
+ this.query.setAttribute("aria-activedescendant", node.id);
152
+ node.setAttribute("aria-selected", "true");
153
+ }
154
+
155
+ clearActiveSuggestion() {
156
+ if (this.activeSuggestion) {
157
+ this.activeSuggestion.setAttribute("aria-selected", "false");
158
+ this.query.removeAttribute("aria-activedescendant");
159
+ }
160
+ }
161
+
162
+ get activeSuggestion() {
163
+ return this.modalTarget.querySelector(
164
+ `#${this.query.getAttribute("aria-activedescendant")}`,
165
+ );
166
+ }
167
+
168
+ get previousSuggestion() {
169
+ return this.activeSuggestion?.previousElementSibling;
170
+ }
171
+
172
+ get nextSuggestion() {
173
+ return this.activeSuggestion?.nextElementSibling;
174
+ }
175
+
176
+ get firstSuggestion() {
177
+ return this.modalTarget.querySelector("#suggestions li:first-of-type");
178
+ }
179
+
180
+ get lastSuggestion() {
181
+ return this.modalTarget.querySelector("#suggestions li:last-of-type");
182
+ }
183
+
104
184
  get query() {
105
- return this.element.querySelector("[role=searchbox]");
185
+ return this.element.querySelector("[role=combobox]");
106
186
  }
107
187
 
108
188
  get position() {