From 5fe7878889e0a2f46de54b617a8aaee4299e35d9 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Mon, 1 Apr 2019 17:57:30 -0400 Subject: [PATCH 01/26] convert js to ts --- dist/js/stacks.js | 457 --------------------- dist/js/stacks.min.js | 2 +- lib/js/controllers/s-expandable-control.js | 157 ------- lib/js/controllers/s-table.js | 203 --------- lib/js/finalize.js | 3 - lib/js/stacks.js | 78 ---- lib/ts/controllers/s-expandable-control.ts | 172 ++++++++ lib/ts/controllers/s-table.ts | 227 ++++++++++ lib/ts/finalize.ts | 3 + lib/ts/stacks.ts | 48 +++ tsconfig.json | 9 + 11 files changed, 460 insertions(+), 899 deletions(-) delete mode 100644 lib/js/controllers/s-expandable-control.js delete mode 100644 lib/js/controllers/s-table.js delete mode 100644 lib/js/finalize.js delete mode 100644 lib/js/stacks.js create mode 100644 lib/ts/controllers/s-expandable-control.ts create mode 100644 lib/ts/controllers/s-table.ts create mode 100644 lib/ts/finalize.ts create mode 100644 lib/ts/stacks.ts create mode 100644 tsconfig.json diff --git a/dist/js/stacks.js b/dist/js/stacks.js index e405123049..8854d06bcd 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -1752,460 +1752,3 @@ Copyright © 2019 Basecamp, LLC value: true }); }); - - -; - - -(function () { - window.Stacks = window.Stacks || Object.create(null); - Stacks._initializing = true; - var application = Stacks.stimulusApplication = Stimulus.Application.start(); - Stacks.controllers = Object.create(null); - - function StacksController () { - Stimulus.Controller.apply(this, arguments); - } - StacksController.prototype = Object.create(Stimulus.Controller.prototype, { - constructor: { value: StacksController, enumerable: false, writable: true } - }); - StacksController.prototype.getElementData = function(element, key) { - return element.getAttribute("data-" + this.identifier + "-" + key); - }; - StacksController.prototype.setElementData = function(element, key, value) { - element.setAttribute("data-" + this.identifier + "-" + key, value); - }; - StacksController.prototype.removeElementData = function(element, key) { - element.removeAttribute("data-" + this.identifier + "-" + key); - }; - StacksController.prototype.triggerEvent = function(eventName, detail, optionalElement) { - var event; - var namespacedName = this.identifier + ":" + eventName; - try { - event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); - } catch (ex) { - // Internet Explorer - event = document.createEvent("CustomEvent"); - event.initCustomEvent(namespacedName, true, true, detail); - } - (optionalElement || this.element).dispatchEvent(event); - }; - Object.setPrototypeOf(StacksController, Stimulus.Controller); - - function createController(name, data) { - var Controller = function () { - StacksController.apply(this, arguments); - }; - Controller.prototype = Object.create(StacksController.prototype, { - // This needs to be writable because Stimulus changes the constructor property - // on the controller. This shouldn't be a problem, mind you -- because right here - // were're defining the property on the *prototype*. But IE11 throws anyway. - constructor: { value: Controller, enumerable: false, writable: true } - }); - Object.setPrototypeOf(Controller, StacksController); - - var targets; - for (var prop in data) if (data.hasOwnProperty(prop)) { - if (prop === "targets") { - targets = data[prop]; - Object.defineProperty(Controller, "targets", { - get: function () { return targets; }, - enumerable: false - }); - } else { - Object.defineProperty(Controller.prototype, prop, Object.getOwnPropertyDescriptor(data, prop)); - } - } - return Controller; - } - - Stacks.addController = function addController(name, data) { - var hasPrefix = /^s-/.test(name); - if (Stacks._initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!Stacks._initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; - } - var Controller = createController(name, data); - application.register(name, Controller); - if (Stacks._initializing) { - Stacks.controllers[name] = Controller; - } - }; -})() - - -; - -(function () { - "use strict"; - - // Radio buttons only trigger a change event when they're *checked*, but not when - // they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in - // the document, we listen for change events on *all* radio buttons and find any - // other radio buttons in the same `name` group, triggering a custom event on all - // of them so the controller can re-evaluate. - // - // We're keeping a count of how many of these controllers are connected to the DOM, - // so only have this global listener when we actually need it. - - var RADIO_OFF_EVENT = "s-expandable-control:radio-off"; - - function globalChangeListener(e) { - if (e.target.nodeName !== "INPUT" || e.target.type !== "radio") { - return; - } - document.querySelectorAll('input[type="radio"][name="' + e.target.name + '"]') - .forEach(function (other) { - if (other === e.target) { - return; - } - var customEvent; - try { - customEvent = new Event(RADIO_OFF_EVENT); - } catch (ex) { - // Internet Explorer - customEvent = document.createEvent("Event"); - customEvent.initEvent(RADIO_OFF_EVENT, true, true); - } - other.dispatchEvent(customEvent); - }); - } - - var refCount = 0; - function globalChangeListenerRequired(required) { - if (required) { - refCount++; - if (refCount === 1) { - document.body.addEventListener("change", globalChangeListener); - } - } else { - refCount--; - if (refCount === 0) { - document.body.removeEventListener("change", globalChangeListener); - } - } - } - - - Stacks.addController("s-expandable-control", { - - initialize: function () { - if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf(this.element.type) >= 0) { - this.isCollapsed = this._isCollapsedForCheckable; - this.events = ["change", RADIO_OFF_EVENT]; - this.isCheckable = true; - this.isRadio = this.element.type === "radio"; - } else { - this.isCollapsed = this._isCollapsedForClickable; - this.events = ["click", "keydown"]; - } - this.listener = this.listener.bind(this); - }, - - // for non-checkable elements, the initial source of truth is the collapsed/expanded - // state of the controlled element (unless the element doesn't exist) - _isCollapsedForClickable: function () { - var cc = this.controlledCollapsible; - return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; - }, - - // for checkable elements, the initial source of truth is the checked state - _isCollapsedForCheckable: function () { - return !this.element.checked; - }, - - get controlledCollapsible() { - return document.getElementById(this.element.getAttribute("aria-controls")); - }, - - _dispatchShowHideEvent: function(isShow) { - this.triggerEvent(isShow ? "show" : "hide"); - }, - - _toggleClass: function(doAdd) { - if (!this.data.has("toggle-class")) { - return; - } - var cl = this.element.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { - cl.toggle(cls, !!doAdd); - }); - }, - - listener: function(e) { - var newCollapsed; - if (this.isCheckable) { - newCollapsed = !this.element.checked; - } else { - if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { - return; - } - if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { - return; - } - newCollapsed = this.element.getAttribute("aria-expanded") === "true"; - e.preventDefault(); - if (e.type === "click") { - this.element.blur(); - } - } - this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); - this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); - this._dispatchShowHideEvent(!newCollapsed); - this._toggleClass(!newCollapsed); - }, - - connect: function () { - this.events.forEach(function (e) { - this.element.addEventListener(e, this.listener); - }, this); - - if (this.isRadio) { - globalChangeListenerRequired(true); - } - - // synchronize state -- in all cases, this means setting the correct `aria-expanded` - // attribute; for checkable controls this also means setting the `is-collapsed` class - this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); - if (this.isCheckable) { - var cc = this.controlledCollapsible; - if (cc) { - var expected = !this.isCollapsed(); - var actual = cc.classList.contains("is-expanded"); - if (expected !== actual) { - cc.classList.toggle("is-expanded", expected); - this._dispatchShowHideEvent(expected); - this._toggleClass(expected); - } - } - } - }, - - disconnect: function () { - this.events.forEach(function (e) { - this.element.removeEventListener(e, this.listener); - }, this); - - if (this.isRadio) { - globalChangeListenerRequired(false); - } - } - - }); -})(); - - -; - -(function () { - "use strict"; - Stacks.addController("s-table", { - - targets: ["column"], - - setCurrentSort: function (headElem, direction) { - if (["asc", "desc", "none"].indexOf(direction) < 0) { - throw "direction must be one of asc, desc, or none" - } - var controller = this; - this.columnTargets.forEach(function (target) { - var isCurrrent = target === headElem; - - target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); - - target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { - var visible = isCurrrent ? direction : "none"; - icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); - }); - - if (!isCurrrent || direction === "none") { - controller.removeElementData(target, "sort-direction"); - } else { - controller.setElementData(target, "sort-direction", direction); - } - }); - }, - - sort: function (evt) { - var controller = this; - var colHead = evt.currentTarget; - var table = this.element; - var tbody = table.tBodies[0]; - - // the column slot number of the clicked header - var colno = getCellSlot(colHead); - - if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head - return; - } - - // an index of the , so we can find out for each row which element is - // in the same column slot as the header - var slotIndex = buildIndex(tbody); - - // the default behavior when clicking a header is to sort by this column in ascending - // direction, *unless* it is already sorted that way - var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; - - var rows = Array.from(table.tBodies[0].rows); - - // if this is still false after traversing the data, that means all values are integers (or empty) - // and thus we'll sort numerically. - var anyNonInt = false; - - // data will be a list of tuples [value, rowNum], where value is what we're sorting by - var data = []; - var firstBottomRow; - rows.forEach(function (row, index) { - var force = controller.getElementData(row, "sort-to"); - if (force === "top") { - return; // rows not added to the list will automatically end up at the top - } else if (force === "bottom") { - if (!firstBottomRow) { - firstBottomRow = row; - } - return; - } - var cell = slotIndex[index][colno]; - if (!cell) { - data.push(["", index]); - return; - } - - // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, - // the value we're using is the cell's text, trimmed of any whitespace - var explicit = controller.getElementData(cell, "sort-val"); - var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); - - if ((d !== "") && (parseInt(d, 10) + "" !== d)) { - anyNonInt = true; - } - data.push([d, index]); - }); - - // If all values were integers (or empty cells), sort numerically, with empty cells treated as - // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) - if (!anyNonInt) { - data.forEach(function (tuple) { - tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); - }); - } - - // We don't sort an array of , but instead an arrays of row *numbers*, because this way we - // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same - // order (the JS standard does not gurantee this for sort()). - data.sort(function (a, b) { - // first compare the values (a[0]) - if (a[0] > b[0]) { - return 1 * direction; - } else if (a[0] < b[0]) { - return -1 * direction; - } else { - // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting - // (note that this comparison is independent of the sorting direction) - return a[1] > b[1] ? 1 : -1; - } - }); - - // this is the actual reordering of the table rows - data.forEach(function (tup) { - var row = rows[tup[1]]; - row.parentElement.removeChild(row); - if (firstBottomRow) { - tbody.insertBefore(row, firstBottomRow); - } else { - tbody.appendChild(row); - } - }); - - // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click - // will cause sorting in descending direction - this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); - } - }); - - function buildIndex(section) { - return buildIndexOrGetCellSlot(section); - } - - function getCellSlot(cell) { - return buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); - } - - // Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* - // of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. - // Because we need to know which header cells and data cells belong together, we have to 1) find out - // which column number (or "slot" as we call it here) the header cell has, and 2) for each row find - // out which cell corresponds to this slot (because those are the rows we're sorting by). - // - // That's what the following function does. If the second argument is not given, it returns an index - // of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The - // indices of the sub-array correspond to column slots; the values are the actual table cell elements. - // For example index[4][3] is the or in row 4, column 3 of the table section ( or ). - // Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, - // it may also be in a previous . - // - // If the second argument is given, it's a or that we're trying to find, and the algorithm - // stops as soon as it has found it and the function returns its slot number. - function buildIndexOrGetCellSlot(section, findCell) { - var index = []; - var curRow = section.children[0]; - - // the elements of these two arrays are synchronized; the first array contains table cell elements, - // the second one contains a number that indicates for how many more rows this elements will - // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) - var growing = []; - var growingRowsLeft = []; - - // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done - while (curRow || growingRowsLeft.some(function (e) { return e; })) { - var curIndexRow = []; - index.push(curIndexRow); - - var curSlot = 0; - if (curRow) { - for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { - while (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; - curSlot++; - } - var cell = curRow.children[curCellInd]; - if (getComputedStyle(cell).display === "none") { - continue; - } - if (cell === findCell) { - return curSlot; - } - var nextFreeSlot = curSlot + cell.colSpan; - for (; curSlot < nextFreeSlot; curSlot++) { - growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything - growing[curSlot] = cell; - curIndexRow[curSlot] = cell; - } - } - } - while (curSlot < growing.length) { - if (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; - } - curSlot++; - } - if (curRow) { - curRow = curRow.nextElementSibling; - } - } - return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ - } - -})(); - - -; - -(function () { - delete Stacks._initializing; -})(); diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index 1c9349c6cf..d0399b2c62 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]t[0]?1*i:e[0]t[1]?1:-1}),h.forEach(function(e){var t=l[e[1]];t.parentElement.removeChild(t),a?o.insertBefore(t,a):o.appendChild(t)}),this.setCurrentSort(n,1===i?"asc":"desc")}}})}(),delete Stacks._initializing; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]= 0) { - this.isCollapsed = this._isCollapsedForCheckable; - this.events = ["change", RADIO_OFF_EVENT]; - this.isCheckable = true; - this.isRadio = this.element.type === "radio"; - } else { - this.isCollapsed = this._isCollapsedForClickable; - this.events = ["click", "keydown"]; - } - this.listener = this.listener.bind(this); - }, - - // for non-checkable elements, the initial source of truth is the collapsed/expanded - // state of the controlled element (unless the element doesn't exist) - _isCollapsedForClickable: function () { - var cc = this.controlledCollapsible; - return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; - }, - - // for checkable elements, the initial source of truth is the checked state - _isCollapsedForCheckable: function () { - return !this.element.checked; - }, - - get controlledCollapsible() { - return document.getElementById(this.element.getAttribute("aria-controls")); - }, - - _dispatchShowHideEvent: function(isShow) { - this.triggerEvent(isShow ? "show" : "hide"); - }, - - _toggleClass: function(doAdd) { - if (!this.data.has("toggle-class")) { - return; - } - var cl = this.element.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { - cl.toggle(cls, !!doAdd); - }); - }, - - listener: function(e) { - var newCollapsed; - if (this.isCheckable) { - newCollapsed = !this.element.checked; - } else { - if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { - return; - } - if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { - return; - } - newCollapsed = this.element.getAttribute("aria-expanded") === "true"; - e.preventDefault(); - if (e.type === "click") { - this.element.blur(); - } - } - this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); - this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); - this._dispatchShowHideEvent(!newCollapsed); - this._toggleClass(!newCollapsed); - }, - - connect: function () { - this.events.forEach(function (e) { - this.element.addEventListener(e, this.listener); - }, this); - - if (this.isRadio) { - globalChangeListenerRequired(true); - } - - // synchronize state -- in all cases, this means setting the correct `aria-expanded` - // attribute; for checkable controls this also means setting the `is-collapsed` class - this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); - if (this.isCheckable) { - var cc = this.controlledCollapsible; - if (cc) { - var expected = !this.isCollapsed(); - var actual = cc.classList.contains("is-expanded"); - if (expected !== actual) { - cc.classList.toggle("is-expanded", expected); - this._dispatchShowHideEvent(expected); - this._toggleClass(expected); - } - } - } - }, - - disconnect: function () { - this.events.forEach(function (e) { - this.element.removeEventListener(e, this.listener); - }, this); - - if (this.isRadio) { - globalChangeListenerRequired(false); - } - } - - }); -})(); diff --git a/lib/js/controllers/s-table.js b/lib/js/controllers/s-table.js deleted file mode 100644 index 0964af2f9b..0000000000 --- a/lib/js/controllers/s-table.js +++ /dev/null @@ -1,203 +0,0 @@ -(function () { - "use strict"; - Stacks.addController("s-table", { - - targets: ["column"], - - setCurrentSort: function (headElem, direction) { - if (["asc", "desc", "none"].indexOf(direction) < 0) { - throw "direction must be one of asc, desc, or none" - } - var controller = this; - this.columnTargets.forEach(function (target) { - var isCurrrent = target === headElem; - - target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); - - target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { - var visible = isCurrrent ? direction : "none"; - icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); - }); - - if (!isCurrrent || direction === "none") { - controller.removeElementData(target, "sort-direction"); - } else { - controller.setElementData(target, "sort-direction", direction); - } - }); - }, - - sort: function (evt) { - var controller = this; - var colHead = evt.currentTarget; - var table = this.element; - var tbody = table.tBodies[0]; - - // the column slot number of the clicked header - var colno = getCellSlot(colHead); - - if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head - return; - } - - // an index of the , so we can find out for each row which element is - // in the same column slot as the header - var slotIndex = buildIndex(tbody); - - // the default behavior when clicking a header is to sort by this column in ascending - // direction, *unless* it is already sorted that way - var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; - - var rows = Array.from(table.tBodies[0].rows); - - // if this is still false after traversing the data, that means all values are integers (or empty) - // and thus we'll sort numerically. - var anyNonInt = false; - - // data will be a list of tuples [value, rowNum], where value is what we're sorting by - var data = []; - var firstBottomRow; - rows.forEach(function (row, index) { - var force = controller.getElementData(row, "sort-to"); - if (force === "top") { - return; // rows not added to the list will automatically end up at the top - } else if (force === "bottom") { - if (!firstBottomRow) { - firstBottomRow = row; - } - return; - } - var cell = slotIndex[index][colno]; - if (!cell) { - data.push(["", index]); - return; - } - - // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, - // the value we're using is the cell's text, trimmed of any whitespace - var explicit = controller.getElementData(cell, "sort-val"); - var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); - - if ((d !== "") && (parseInt(d, 10) + "" !== d)) { - anyNonInt = true; - } - data.push([d, index]); - }); - - // If all values were integers (or empty cells), sort numerically, with empty cells treated as - // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) - if (!anyNonInt) { - data.forEach(function (tuple) { - tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); - }); - } - - // We don't sort an array of , but instead an arrays of row *numbers*, because this way we - // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same - // order (the JS standard does not gurantee this for sort()). - data.sort(function (a, b) { - // first compare the values (a[0]) - if (a[0] > b[0]) { - return 1 * direction; - } else if (a[0] < b[0]) { - return -1 * direction; - } else { - // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting - // (note that this comparison is independent of the sorting direction) - return a[1] > b[1] ? 1 : -1; - } - }); - - // this is the actual reordering of the table rows - data.forEach(function (tup) { - var row = rows[tup[1]]; - row.parentElement.removeChild(row); - if (firstBottomRow) { - tbody.insertBefore(row, firstBottomRow); - } else { - tbody.appendChild(row); - } - }); - - // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click - // will cause sorting in descending direction - this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); - } - }); - - function buildIndex(section) { - return buildIndexOrGetCellSlot(section); - } - - function getCellSlot(cell) { - return buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); - } - - // Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* - // of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. - // Because we need to know which header cells and data cells belong together, we have to 1) find out - // which column number (or "slot" as we call it here) the header cell has, and 2) for each row find - // out which cell corresponds to this slot (because those are the rows we're sorting by). - // - // That's what the following function does. If the second argument is not given, it returns an index - // of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The - // indices of the sub-array correspond to column slots; the values are the actual table cell elements. - // For example index[4][3] is the or in row 4, column 3 of the table section ( or ). - // Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, - // it may also be in a previous . - // - // If the second argument is given, it's a or that we're trying to find, and the algorithm - // stops as soon as it has found it and the function returns its slot number. - function buildIndexOrGetCellSlot(section, findCell) { - var index = []; - var curRow = section.children[0]; - - // the elements of these two arrays are synchronized; the first array contains table cell elements, - // the second one contains a number that indicates for how many more rows this elements will - // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) - var growing = []; - var growingRowsLeft = []; - - // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done - while (curRow || growingRowsLeft.some(function (e) { return e; })) { - var curIndexRow = []; - index.push(curIndexRow); - - var curSlot = 0; - if (curRow) { - for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { - while (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; - curSlot++; - } - var cell = curRow.children[curCellInd]; - if (getComputedStyle(cell).display === "none") { - continue; - } - if (cell === findCell) { - return curSlot; - } - var nextFreeSlot = curSlot + cell.colSpan; - for (; curSlot < nextFreeSlot; curSlot++) { - growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything - growing[curSlot] = cell; - curIndexRow[curSlot] = cell; - } - } - } - while (curSlot < growing.length) { - if (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; - } - curSlot++; - } - if (curRow) { - curRow = curRow.nextElementSibling; - } - } - return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ - } - -})(); diff --git a/lib/js/finalize.js b/lib/js/finalize.js deleted file mode 100644 index e193450b53..0000000000 --- a/lib/js/finalize.js +++ /dev/null @@ -1,3 +0,0 @@ -(function () { - delete Stacks._initializing; -})(); diff --git a/lib/js/stacks.js b/lib/js/stacks.js deleted file mode 100644 index 367d0c21d7..0000000000 --- a/lib/js/stacks.js +++ /dev/null @@ -1,78 +0,0 @@ - -(function () { - window.Stacks = window.Stacks || Object.create(null); - Stacks._initializing = true; - var application = Stacks.stimulusApplication = Stimulus.Application.start(); - Stacks.controllers = Object.create(null); - - function StacksController () { - Stimulus.Controller.apply(this, arguments); - } - StacksController.prototype = Object.create(Stimulus.Controller.prototype, { - constructor: { value: StacksController, enumerable: false, writable: true } - }); - StacksController.prototype.getElementData = function(element, key) { - return element.getAttribute("data-" + this.identifier + "-" + key); - }; - StacksController.prototype.setElementData = function(element, key, value) { - element.setAttribute("data-" + this.identifier + "-" + key, value); - }; - StacksController.prototype.removeElementData = function(element, key) { - element.removeAttribute("data-" + this.identifier + "-" + key); - }; - StacksController.prototype.triggerEvent = function(eventName, detail, optionalElement) { - var event; - var namespacedName = this.identifier + ":" + eventName; - try { - event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); - } catch (ex) { - // Internet Explorer - event = document.createEvent("CustomEvent"); - event.initCustomEvent(namespacedName, true, true, detail); - } - (optionalElement || this.element).dispatchEvent(event); - }; - Object.setPrototypeOf(StacksController, Stimulus.Controller); - - function createController(name, data) { - var Controller = function () { - StacksController.apply(this, arguments); - }; - Controller.prototype = Object.create(StacksController.prototype, { - // This needs to be writable because Stimulus changes the constructor property - // on the controller. This shouldn't be a problem, mind you -- because right here - // were're defining the property on the *prototype*. But IE11 throws anyway. - constructor: { value: Controller, enumerable: false, writable: true } - }); - Object.setPrototypeOf(Controller, StacksController); - - var targets; - for (var prop in data) if (data.hasOwnProperty(prop)) { - if (prop === "targets") { - targets = data[prop]; - Object.defineProperty(Controller, "targets", { - get: function () { return targets; }, - enumerable: false - }); - } else { - Object.defineProperty(Controller.prototype, prop, Object.getOwnPropertyDescriptor(data, prop)); - } - } - return Controller; - } - - Stacks.addController = function addController(name, data) { - var hasPrefix = /^s-/.test(name); - if (Stacks._initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!Stacks._initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; - } - var Controller = createController(name, data); - application.register(name, Controller); - if (Stacks._initializing) { - Stacks.controllers[name] = Controller; - } - }; -})() diff --git a/lib/ts/controllers/s-expandable-control.ts b/lib/ts/controllers/s-expandable-control.ts new file mode 100644 index 0000000000..8262f30ccd --- /dev/null +++ b/lib/ts/controllers/s-expandable-control.ts @@ -0,0 +1,172 @@ +import { StacksController, addController } from "../stacks"; + +// Radio buttons only trigger a change event when they're *checked*, but not when +// they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in +// the document, we listen for change events on *all* radio buttons and find any +// other radio buttons in the same `name` group, triggering a custom event on all +// of them so the controller can re-evaluate. +// +// We're keeping a count of how many of these controllers are connected to the DOM, +// so only have this global listener when we actually need it. + +const RADIO_OFF_EVENT = "s-expandable-control:radio-off"; + +function globalChangeListener(e: UIEvent) { + const target = e.target; + if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { + return; + } + document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') + .forEach(function (other) { + if (other === e.target) { + return; + } + var customEvent; + try { + customEvent = new Event(RADIO_OFF_EVENT); + } catch (ex) { + // Internet Explorer + customEvent = document.createEvent("Event"); + customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } + other.dispatchEvent(customEvent); + }); +} + +var refCount = 0; +function globalChangeListenerRequired(required: boolean) { + if (required) { + refCount++; + if (refCount === 1) { + document.body.addEventListener("change", globalChangeListener as EventListener); + } + } else { + refCount--; + if (refCount === 0) { + document.body.removeEventListener("change", globalChangeListener as EventListener); + } + } +} + +addController("s-expandable-control", class extends StacksController { + private isCollapsed!: () => boolean; + private events!: string[]; + private isCheckable!: boolean; + private isRadio!: boolean; + + initialize() { + if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf((this.element).type) >= 0) { + this.isCollapsed = this._isCollapsedForCheckable; + this.events = ["change", RADIO_OFF_EVENT]; + this.isCheckable = true; + this.isRadio = (this.element).type === "radio"; + } else { + this.isCollapsed = this._isCollapsedForClickable; + this.events = ["click", "keydown"]; + } + this.listener = this.listener.bind(this); + }; + + + // for non-checkable elements, the initial source of truth is the collapsed/expanded + // state of the controlled element (unless the element doesn't exist) + _isCollapsedForClickable() { + var cc = this.controlledCollapsible; + return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; + }; + + // for checkable elements, the initial source of truth is the checked state + _isCollapsedForCheckable() { + return !(this.element).checked; + }; + + + get controlledCollapsible() { + const attr = this.element.getAttribute("aria-controls"); + if (!attr) { + throw "couldn't find controls" + } + const result = document.getElementById(attr); + if (!result) { + throw "couldn't find controls" + } + return result; + }; + + _dispatchShowHideEvent(isShow: boolean) { + this.triggerEvent(isShow ? "show" : "hide"); + }; + + _toggleClass(doAdd: boolean) { + if (!this.data.has("toggle-class")) { + return; + } + var cl = this.element.classList; + var toggleClass = this.data.get("toggle-class"); + if (!toggleClass) { + throw "couldn't find toggle class" + } + toggleClass.split(/\s+/).forEach(function (cls) { + cl.toggle(cls, !!doAdd); + }); + }; + + listener(e: UIEvent) { + var newCollapsed; + if (this.isCheckable) { + newCollapsed = !(this.element).checked; + } else { + if (e.type == "keydown" && ((e).keyCode != 13 && (e).keyCode != 32)) { + return; + } + if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf((e.target).nodeName) >= 0) { + return; + } + newCollapsed = this.element.getAttribute("aria-expanded") === "true"; + e.preventDefault(); + if (e.type === "click") { + (this.element).blur(); + } + } + this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); + this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); + this._dispatchShowHideEvent(!newCollapsed); + this._toggleClass(!newCollapsed); + }; + + connect() { + this.events.forEach(e => { + this.element.addEventListener(e, this.listener as EventListener); + }, this); + + if (this.isRadio) { + globalChangeListenerRequired(true); + } + + // synchronize state -- in all cases, this means setting the correct `aria-expanded` + // attribute; for checkable controls this also means setting the `is-collapsed` class + this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); + if (this.isCheckable) { + var cc = this.controlledCollapsible; + if (cc) { + var expected = !this.isCollapsed(); + var actual = cc.classList.contains("is-expanded"); + if (expected !== actual) { + cc.classList.toggle("is-expanded", expected); + this._dispatchShowHideEvent(expected); + this._toggleClass(expected); + } + } + } + }; + + disconnect() { + this.events.forEach(e => { + this.element.removeEventListener(e, this.listener as EventListener); + }, this); + + if (this.isRadio) { + globalChangeListenerRequired(false); + } + }; +}); diff --git a/lib/ts/controllers/s-table.ts b/lib/ts/controllers/s-table.ts new file mode 100644 index 0000000000..a72572d27b --- /dev/null +++ b/lib/ts/controllers/s-table.ts @@ -0,0 +1,227 @@ +import { StacksController, addController } from "../stacks"; + + +addController("s-table", class extends StacksController { + static targets = ["column"]; + declare readonly columnTarget!: Element; + declare readonly columnTargets!: Element[]; + + setCurrentSort(headElem: Element, direction: "asc" | "desc" | "none") { + if (["asc", "desc", "none"].indexOf(direction) < 0) { + throw "direction must be one of asc, desc, or none" + } + var controller = this; + this.columnTargets.forEach(function (target) { + var isCurrrent = target === headElem; + + target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); + + target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { + var visible = isCurrrent ? direction : "none"; + icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); + }); + + if (!isCurrrent || direction === "none") { + controller.removeElementData(target, "sort-direction"); + } else { + controller.setElementData(target, "sort-direction", direction); + } + }); + }; + + sort(evt: Event) { + var controller = this; + var colHead = evt.currentTarget; + if (!(colHead instanceof HTMLTableCellElement)) { + throw "invalid event target"; + } + var table = this.element as HTMLTableElement; + var tbody = table.tBodies[0]; + + // the column slot number of the clicked header + var colno = getCellSlot(colHead); + + if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head + return; + } + + // an index of the , so we can find out for each row which element is + // in the same column slot as the header + var slotIndex = buildIndex(tbody); + + // the default behavior when clicking a header is to sort by this column in ascending + // direction, *unless* it is already sorted that way + var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; + + var rows = Array.from(table.tBodies[0].rows); + + // if this is still false after traversing the data, that means all values are integers (or empty) + // and thus we'll sort numerically. + var anyNonInt = false; + + // data will be a list of tuples [value, rowNum], where value is what we're sorting by + var data: [string | number, number][] = []; + var firstBottomRow: HTMLTableRowElement; + rows.forEach(function (row, index) { + var force = controller.getElementData(row, "sort-to"); + if (force === "top") { + return; // rows not added to the list will automatically end up at the top + } else if (force === "bottom") { + if (!firstBottomRow) { + firstBottomRow = row; + } + return; + } + var cell = slotIndex[index][colno]; + if (!cell) { + data.push(["", index]); + return; + } + + // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, + // the value we're using is the cell's text, trimmed of any whitespace + var explicit = controller.getElementData(cell, "sort-val"); + var d = typeof explicit === "string" ? explicit : cell.textContent!.trim(); + + if ((d !== "") && (parseInt(d, 10) + "" !== d)) { + anyNonInt = true; + } + data.push([d, index]); + }); + + // If all values were integers (or empty cells), sort numerically, with empty cells treated as + // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) + if (!anyNonInt) { + data.forEach(function (tuple) { + tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0] as string, 10); + }); + } + + // We don't sort an array of , but instead an arrays of row *numbers*, because this way we + // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same + // order (the JS standard does not gurantee this for sort()). + data.sort(function (a, b) { + // first compare the values (a[0]) + if (a[0] > b[0]) { + return 1 * direction; + } else if (a[0] < b[0]) { + return -1 * direction; + } else { + // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting + // (note that this comparison is independent of the sorting direction) + return a[1] > b[1] ? 1 : -1; + } + }); + + // this is the actual reordering of the table rows + data.forEach(function (tup) { + var row = rows[tup[1]]; + row.parentElement!.removeChild(row); + if (firstBottomRow) { + tbody.insertBefore(row, firstBottomRow); + } else { + tbody.appendChild(row); + } + }); + + // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click + // will cause sorting in descending direction + this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); + } + +}); + +function buildIndex(section: HTMLTableSectionElement): HTMLTableCellElement[][] { + const result = buildIndexOrGetCellSlot(section); + if (!(result instanceof Array)) { + throw "shouldn't happen" + } + return result; +} + +function getCellSlot(cell: HTMLTableCellElement): number { + if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { + throw "invalid table" + } + const result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (typeof result !== "number") { + throw "shouldn't happen" + } + return result +} + +// Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* +// of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. +// Because we need to know which header cells and data cells belong together, we have to 1) find out +// which column number (or "slot" as we call it here) the header cell has, and 2) for each row find +// out which cell corresponds to this slot (because those are the rows we're sorting by). +// +// That's what the following function does. If the second argument is not given, it returns an index +// of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The +// indices of the sub-array correspond to column slots; the values are the actual table cell elements. +// For example index[4][3] is the or in row 4, column 3 of the table section ( or ). +// Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, +// it may also be in a previous . +// +// If the second argument is given, it's a or that we're trying to find, and the algorithm +// stops as soon as it has found it and the function returns its slot number. +function buildIndexOrGetCellSlot(section: HTMLTableSectionElement, findCell?: HTMLTableCellElement) { + var index = []; + var curRow = section.children[0]; + + // the elements of these two arrays are synchronized; the first array contains table cell elements, + // the second one contains a number that indicates for how many more rows this elements will + // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) + var growing: HTMLTableCellElement[] = []; + var growingRowsLeft: number[] = []; + + // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done + while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { + var curIndexRow: HTMLTableCellElement[] = []; + index.push(curIndexRow); + + var curSlot = 0; + if (curRow) { + for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { + while (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + curSlot++; + } + var cell = curRow.children[curCellInd]; + if (!(cell instanceof HTMLTableCellElement)) { + throw "invalid table" + } + if (getComputedStyle(cell).display === "none") { + continue; + } + if (cell === findCell) { + return curSlot; + } + var nextFreeSlot = curSlot + cell.colSpan; + for (; curSlot < nextFreeSlot; curSlot++) { + growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything + growing[curSlot] = cell; + curIndexRow[curSlot] = cell; + } + } + } + while (curSlot < growing.length) { + if (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + } + curSlot++; + } + if (curRow && curRow.nextElementSibling) { + curRow = curRow.nextElementSibling; + } + } + return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ +} + +// addController("s-table", class extends StacksController { + + +// }); + diff --git a/lib/ts/finalize.ts b/lib/ts/finalize.ts new file mode 100644 index 0000000000..fd17ee8c6c --- /dev/null +++ b/lib/ts/finalize.ts @@ -0,0 +1,3 @@ +import { _internalData } from "./stacks" + +_internalData.initializing = false; diff --git a/lib/ts/stacks.ts b/lib/ts/stacks.ts new file mode 100644 index 0000000000..f76b2df2f1 --- /dev/null +++ b/lib/ts/stacks.ts @@ -0,0 +1,48 @@ +import { Application, Controller, ControllerConstructor } from "stimulus" + +export const stimulusApplication = Application.start(); +export var _internalData = { initializing: true }; + +export class StacksController extends Controller { + protected getElementData(element: Element, key: string) { + return element.getAttribute("data-" + this.identifier + "-" + key); + }; + protected setElementData(element: Element, key: string, value: string) { + element.setAttribute("data-" + this.identifier + "-" + key, value); + }; + protected removeElementData(element: Element, key: string) { + element.removeAttribute("data-" + this.identifier + "-" + key); + }; + protected triggerEvent(eventName: string, detail?: T, optionalElement?: Element) { + const namespacedName = this.identifier + ":" + eventName; + var event : CustomEvent; + try { + event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); + } catch (ex) { + // Internet Explorer + event = document.createEvent("CustomEvent"); + event.initCustomEvent(namespacedName, true, true, detail!); + } + (optionalElement || this.element).dispatchEvent(event); + }; +} + + +type ControllersDictionary = { [identifier: string]: ControllerConstructor }; +const _controllers : ControllersDictionary = {}; +export const controllers : Readonly = _controllers; + + +export function addController(name: string, controller: ControllerConstructor) { + var hasPrefix = /^s-/.test(name); + if (_internalData.initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!_internalData.initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + stimulusApplication.register(name, controller); + if (_internalData.initializing) { + _controllers[name] = controller; + } +}; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..18556d8f40 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "strict": true, + "typeRoots": ["node_modules/@types", "node_modules/@stimulus/core"], + "target": "es5", + "lib": ["dom", "es6", "dom.iterable", "scripthost"] // es6 stuff is polyfilled by stimulus + }, + "include": ["lib/ts/**/*.ts"] +} \ No newline at end of file From fdd0c79cd8f0531973ff0c447b9631488296f3f3 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Mon, 1 Apr 2019 19:32:56 -0400 Subject: [PATCH 02/26] convert to non-module based code. Required https://github.com/stimulusjs/stimulus/issues/238 --- lib/ts/controllers/s-expandable-control.ts | 4 +- lib/ts/controllers/s-table.ts | 5 +- lib/ts/finalize.ts | 4 +- lib/ts/stacks.ts | 90 +++++++++++----------- 4 files changed, 48 insertions(+), 55 deletions(-) diff --git a/lib/ts/controllers/s-expandable-control.ts b/lib/ts/controllers/s-expandable-control.ts index 8262f30ccd..270c94ec91 100644 --- a/lib/ts/controllers/s-expandable-control.ts +++ b/lib/ts/controllers/s-expandable-control.ts @@ -1,5 +1,3 @@ -import { StacksController, addController } from "../stacks"; - // Radio buttons only trigger a change event when they're *checked*, but not when // they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in // the document, we listen for change events on *all* radio buttons and find any @@ -48,7 +46,7 @@ function globalChangeListenerRequired(required: boolean) { } } -addController("s-expandable-control", class extends StacksController { +Stacks.addController("s-expandable-control", class extends Stacks.StacksController { private isCollapsed!: () => boolean; private events!: string[]; private isCheckable!: boolean; diff --git a/lib/ts/controllers/s-table.ts b/lib/ts/controllers/s-table.ts index a72572d27b..d641a4565c 100644 --- a/lib/ts/controllers/s-table.ts +++ b/lib/ts/controllers/s-table.ts @@ -1,7 +1,4 @@ -import { StacksController, addController } from "../stacks"; - - -addController("s-table", class extends StacksController { +Stacks.addController("s-table", class extends Stacks.StacksController { static targets = ["column"]; declare readonly columnTarget!: Element; declare readonly columnTargets!: Element[]; diff --git a/lib/ts/finalize.ts b/lib/ts/finalize.ts index fd17ee8c6c..b28b205bf7 100644 --- a/lib/ts/finalize.ts +++ b/lib/ts/finalize.ts @@ -1,3 +1 @@ -import { _internalData } from "./stacks" - -_internalData.initializing = false; +Stacks._initializing = false; diff --git a/lib/ts/stacks.ts b/lib/ts/stacks.ts index f76b2df2f1..a55bdb6b06 100644 --- a/lib/ts/stacks.ts +++ b/lib/ts/stacks.ts @@ -1,48 +1,48 @@ -import { Application, Controller, ControllerConstructor } from "stimulus" - -export const stimulusApplication = Application.start(); -export var _internalData = { initializing: true }; - -export class StacksController extends Controller { - protected getElementData(element: Element, key: string) { - return element.getAttribute("data-" + this.identifier + "-" + key); - }; - protected setElementData(element: Element, key: string, value: string) { - element.setAttribute("data-" + this.identifier + "-" + key, value); - }; - protected removeElementData(element: Element, key: string) { - element.removeAttribute("data-" + this.identifier + "-" + key); - }; - protected triggerEvent(eventName: string, detail?: T, optionalElement?: Element) { - const namespacedName = this.identifier + ":" + eventName; - var event : CustomEvent; - try { - event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); - } catch (ex) { - // Internet Explorer - event = document.createEvent("CustomEvent"); - event.initCustomEvent(namespacedName, true, true, detail!); +namespace Stacks { + export const application = Stimulus.Application.start(); + export var _initializing = true; + + export class StacksController extends Stimulus.Controller { + protected getElementData(element: Element, key: string) { + return element.getAttribute("data-" + this.identifier + "-" + key); + }; + protected setElementData(element: Element, key: string, value: string) { + element.setAttribute("data-" + this.identifier + "-" + key, value); + }; + protected removeElementData(element: Element, key: string) { + element.removeAttribute("data-" + this.identifier + "-" + key); + }; + protected triggerEvent(eventName: string, detail?: T, optionalElement?: Element) { + const namespacedName = this.identifier + ":" + eventName; + var event : CustomEvent; + try { + event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); + } catch (ex) { + // Internet Explorer + event = document.createEvent("CustomEvent"); + event.initCustomEvent(namespacedName, true, true, detail!); + } + (optionalElement || this.element).dispatchEvent(event); + }; + } + + + type ControllersDictionary = { [identifier: string]: Stimulus.ControllerConstructor }; + const _controllers : ControllersDictionary = {}; + export const controllers : Readonly = _controllers; + + + export function addController(name: string, controller: Stimulus.ControllerConstructor) { + var hasPrefix = /^s-/.test(name); + if (_initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!_initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + application.register(name, controller); + if (_initializing) { + _controllers[name] = controller; } - (optionalElement || this.element).dispatchEvent(event); }; } - - -type ControllersDictionary = { [identifier: string]: ControllerConstructor }; -const _controllers : ControllersDictionary = {}; -export const controllers : Readonly = _controllers; - - -export function addController(name: string, controller: ControllerConstructor) { - var hasPrefix = /^s-/.test(name); - if (_internalData.initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!_internalData.initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; - } - stimulusApplication.register(name, controller); - if (_internalData.initializing) { - _controllers[name] = controller; - } -}; From 5e624bc21fddcf7cb23f0f024a220e797b7924bc Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 12:06:43 -0400 Subject: [PATCH 03/26] add workaround for umd global issue --- lib/ts/stimulus.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/ts/stimulus.d.ts diff --git a/lib/ts/stimulus.d.ts b/lib/ts/stimulus.d.ts new file mode 100644 index 0000000000..092d009721 --- /dev/null +++ b/lib/ts/stimulus.d.ts @@ -0,0 +1,4 @@ +// allows stimulus to be used as a UMD global from TypeScript. +// You can delete this file after https://github.com/stimulusjs/stimulus/issues/238 has been fixed +export * from "stimulus"; +export as namespace Stimulus; From c2d4b09f14dfb12b3037e932ff854b2bd17c70e9 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 13:01:02 -0400 Subject: [PATCH 04/26] set up ts build system --- .gitignore | 2 + Gruntfile.js | 16 +- dist/js/stacks.js | 438 ++++++++++++++++++++++++ dist/js/stacks.min.js | 2 +- package-lock.json | 759 ++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- tsconfig.json | 4 +- 7 files changed, 1217 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c1bb609ebd..66fd3ca0f2 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,8 @@ node_modules /docs/assets/css/ /docs/assets/js/stacks.* /docs/assets/js/controllers.js +/build/ +.tscache # legacy compiled files -- these are no longer generated, but may still be lingering around /lib/css/*.css diff --git a/Gruntfile.js b/Gruntfile.js index 3a79b6c3eb..82607ab828 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -74,6 +74,11 @@ module.exports = function(grunt) { } }, // Minify and concatenate JS + ts: { + stacks_js: { + tsconfig: "tsconfig.json" + } + }, uglify: { stacks_js: { files: { @@ -94,9 +99,9 @@ module.exports = function(grunt) { files: { 'dist/js/stacks.js': [ 'node_modules/stimulus/dist/stimulus.umd.js', - 'lib/js/stacks.js', - 'lib/js/controllers/**/*.js', - 'lib/js/finalize.js' + 'build/ts/stacks.js', + 'build/ts/controllers/**/*.js', + 'build/ts/finalize.js' ] } }, @@ -132,7 +137,7 @@ module.exports = function(grunt) { }, stacks_js: { - files: ['lib/js/**/*.js'], // note: this doesn't watch any of the npm dependencies + files: ['lib/ts/**/*.ts'], // note: this doesn't watch any of the npm dependencies tasks: ['concurrent:compile_stacks_js', 'copy:js2docs'] }, @@ -162,7 +167,7 @@ module.exports = function(grunt) { // Stacks JS itself and the polyfills are independent of each other, so they can be compiled in parallel compile_stacks_js: [ - ['concat:stacks_js', 'uglify:stacks_js'], + ['ts:stacks_js', 'concat:stacks_js', 'uglify:stacks_js'], ['rollup:stacks_js_polyfills', 'uglify:stacks_js_polyfills'] ], @@ -222,6 +227,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-rollup'); + grunt.loadNpmTasks("grunt-ts"); grunt.registerTask('default', 'Compile all JS and LESS files and rebuild the documentation site, then continue running and re-compile as needed whenever files are changed.', diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 8854d06bcd..6918693591 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -1752,3 +1752,441 @@ Copyright © 2019 Basecamp, LLC value: true }); }); + + +; + +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Stacks; +(function (Stacks) { + Stacks.application = Stimulus.Application.start(); + Stacks._initializing = true; + var StacksController = (function (_super) { + __extends(StacksController, _super); + function StacksController() { + return _super !== null && _super.apply(this, arguments) || this; + } + StacksController.prototype.getElementData = function (element, key) { + return element.getAttribute("data-" + this.identifier + "-" + key); + }; + ; + StacksController.prototype.setElementData = function (element, key, value) { + element.setAttribute("data-" + this.identifier + "-" + key, value); + }; + ; + StacksController.prototype.removeElementData = function (element, key) { + element.removeAttribute("data-" + this.identifier + "-" + key); + }; + ; + StacksController.prototype.triggerEvent = function (eventName, detail, optionalElement) { + var namespacedName = this.identifier + ":" + eventName; + var event; + try { + event = new CustomEvent(namespacedName, { bubbles: true, detail: detail }); + } + catch (ex) { + event = document.createEvent("CustomEvent"); + event.initCustomEvent(namespacedName, true, true, detail); + } + (optionalElement || this.element).dispatchEvent(event); + }; + ; + return StacksController; + }(Stimulus.Controller)); + Stacks.StacksController = StacksController; + var _controllers = {}; + Stacks.controllers = _controllers; + function addController(name, controller) { + var hasPrefix = /^s-/.test(name); + if (Stacks._initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!Stacks._initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + Stacks.application.register(name, controller); + if (Stacks._initializing) { + _controllers[name] = controller; + } + } + Stacks.addController = addController; + ; +})(Stacks || (Stacks = {})); +//# sourceMappingURL=stacks.js.map + +; + +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var RADIO_OFF_EVENT = "s-expandable-control:radio-off"; +function globalChangeListener(e) { + var target = e.target; + if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { + return; + } + document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') + .forEach(function (other) { + if (other === e.target) { + return; + } + var customEvent; + try { + customEvent = new Event(RADIO_OFF_EVENT); + } + catch (ex) { + customEvent = document.createEvent("Event"); + customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } + other.dispatchEvent(customEvent); + }); +} +var refCount = 0; +function globalChangeListenerRequired(required) { + if (required) { + refCount++; + if (refCount === 1) { + document.body.addEventListener("change", globalChangeListener); + } + } + else { + refCount--; + if (refCount === 0) { + document.body.removeEventListener("change", globalChangeListener); + } + } +} +Stacks.addController("s-expandable-control", (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.initialize = function () { + if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf(this.element.type) >= 0) { + this.isCollapsed = this._isCollapsedForCheckable; + this.events = ["change", RADIO_OFF_EVENT]; + this.isCheckable = true; + this.isRadio = this.element.type === "radio"; + } + else { + this.isCollapsed = this._isCollapsedForClickable; + this.events = ["click", "keydown"]; + } + this.listener = this.listener.bind(this); + }; + ; + class_1.prototype._isCollapsedForClickable = function () { + var cc = this.controlledCollapsible; + return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; + }; + ; + class_1.prototype._isCollapsedForCheckable = function () { + return !this.element.checked; + }; + ; + Object.defineProperty(class_1.prototype, "controlledCollapsible", { + get: function () { + var attr = this.element.getAttribute("aria-controls"); + if (!attr) { + throw "couldn't find controls"; + } + var result = document.getElementById(attr); + if (!result) { + throw "couldn't find controls"; + } + return result; + }, + enumerable: true, + configurable: true + }); + ; + class_1.prototype._dispatchShowHideEvent = function (isShow) { + this.triggerEvent(isShow ? "show" : "hide"); + }; + ; + class_1.prototype._toggleClass = function (doAdd) { + if (!this.data.has("toggle-class")) { + return; + } + var cl = this.element.classList; + var toggleClass = this.data.get("toggle-class"); + if (!toggleClass) { + throw "couldn't find toggle class"; + } + toggleClass.split(/\s+/).forEach(function (cls) { + cl.toggle(cls, !!doAdd); + }); + }; + ; + class_1.prototype.listener = function (e) { + var newCollapsed; + if (this.isCheckable) { + newCollapsed = !this.element.checked; + } + else { + if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { + return; + } + if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { + return; + } + newCollapsed = this.element.getAttribute("aria-expanded") === "true"; + e.preventDefault(); + if (e.type === "click") { + this.element.blur(); + } + } + this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); + this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); + this._dispatchShowHideEvent(!newCollapsed); + this._toggleClass(!newCollapsed); + }; + ; + class_1.prototype.connect = function () { + var _this = this; + this.events.forEach(function (e) { + _this.element.addEventListener(e, _this.listener); + }, this); + if (this.isRadio) { + globalChangeListenerRequired(true); + } + this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); + if (this.isCheckable) { + var cc = this.controlledCollapsible; + if (cc) { + var expected = !this.isCollapsed(); + var actual = cc.classList.contains("is-expanded"); + if (expected !== actual) { + cc.classList.toggle("is-expanded", expected); + this._dispatchShowHideEvent(expected); + this._toggleClass(expected); + } + } + } + }; + ; + class_1.prototype.disconnect = function () { + var _this = this; + this.events.forEach(function (e) { + _this.element.removeEventListener(e, _this.listener); + }, this); + if (this.isRadio) { + globalChangeListenerRequired(false); + } + }; + ; + return class_1; +}(Stacks.StacksController))); +//# sourceMappingURL=s-expandable-control.js.map + +; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var _a; +"use strict"; +Stacks.addController("s-table", (_a = (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.setCurrentSort = function (headElem, direction) { + if (["asc", "desc", "none"].indexOf(direction) < 0) { + throw "direction must be one of asc, desc, or none"; + } + var controller = this; + this.columnTargets.forEach(function (target) { + var isCurrrent = target === headElem; + target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); + target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { + var visible = isCurrrent ? direction : "none"; + icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); + }); + if (!isCurrrent || direction === "none") { + controller.removeElementData(target, "sort-direction"); + } + else { + controller.setElementData(target, "sort-direction", direction); + } + }); + }; + ; + class_1.prototype.sort = function (evt) { + var controller = this; + var colHead = evt.currentTarget; + if (!(colHead instanceof HTMLTableCellElement)) { + throw "invalid event target"; + } + var table = this.element; + var tbody = table.tBodies[0]; + var colno = getCellSlot(colHead); + if (colno < 0) { + return; + } + var slotIndex = buildIndex(tbody); + var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; + var rows = Array.from(table.tBodies[0].rows); + var anyNonInt = false; + var data = []; + var firstBottomRow; + rows.forEach(function (row, index) { + var force = controller.getElementData(row, "sort-to"); + if (force === "top") { + return; + } + else if (force === "bottom") { + if (!firstBottomRow) { + firstBottomRow = row; + } + return; + } + var cell = slotIndex[index][colno]; + if (!cell) { + data.push(["", index]); + return; + } + var explicit = controller.getElementData(cell, "sort-val"); + var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); + if ((d !== "") && (parseInt(d, 10) + "" !== d)) { + anyNonInt = true; + } + data.push([d, index]); + }); + if (!anyNonInt) { + data.forEach(function (tuple) { + tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); + }); + } + data.sort(function (a, b) { + if (a[0] > b[0]) { + return 1 * direction; + } + else if (a[0] < b[0]) { + return -1 * direction; + } + else { + return a[1] > b[1] ? 1 : -1; + } + }); + data.forEach(function (tup) { + var row = rows[tup[1]]; + row.parentElement.removeChild(row); + if (firstBottomRow) { + tbody.insertBefore(row, firstBottomRow); + } + else { + tbody.appendChild(row); + } + }); + this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); + }; + return class_1; + }(Stacks.StacksController)), + _a.targets = ["column"], + _a)); +function buildIndex(section) { + var result = buildIndexOrGetCellSlot(section); + if (!(result instanceof Array)) { + throw "shouldn't happen"; + } + return result; +} +function getCellSlot(cell) { + if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { + throw "invalid table"; + } + var result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (typeof result !== "number") { + throw "shouldn't happen"; + } + return result; +} +function buildIndexOrGetCellSlot(section, findCell) { + var index = []; + var curRow = section.children[0]; + var growing = []; + var growingRowsLeft = []; + while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { + var curIndexRow = []; + index.push(curIndexRow); + var curSlot = 0; + if (curRow) { + for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { + while (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + curSlot++; + } + var cell = curRow.children[curCellInd]; + if (!(cell instanceof HTMLTableCellElement)) { + throw "invalid table"; + } + if (getComputedStyle(cell).display === "none") { + continue; + } + if (cell === findCell) { + return curSlot; + } + var nextFreeSlot = curSlot + cell.colSpan; + for (; curSlot < nextFreeSlot; curSlot++) { + growingRowsLeft[curSlot] = cell.rowSpan - 1; + growing[curSlot] = cell; + curIndexRow[curSlot] = cell; + } + } + } + while (curSlot < growing.length) { + if (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + } + curSlot++; + } + if (curRow && curRow.nextElementSibling) { + curRow = curRow.nextElementSibling; + } + } + return findCell ? -1 : index; +} +//# sourceMappingURL=s-table.js.map + +; + +"use strict"; +Stacks._initializing = false; +//# sourceMappingURL=finalize.js.map \ No newline at end of file diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index d0399b2c62..ab26dcc2f1 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1])?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]t[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),a?r.insertBefore(t,a):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],_a)),Stacks._initializing=!1; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 03af160a1f..6700190d00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -123,6 +123,27 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" }, + "anymatch": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", + "integrity": "sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw==", + "dev": true, + "requires": { + "micromatch": "^3.1.4", + "normalize-path": "^2.1.1" + }, + "dependencies": { + "normalize-path": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", + "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "dev": true, + "requires": { + "remove-trailing-separator": "^1.0.1" + } + } + } + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -226,6 +247,12 @@ "babel-polyfill": "^6.23.0" } }, + "async-each": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.2.tgz", + "integrity": "sha512-6xrbvN0MOBKSJDdonmSSz2OwFSgxRaVtBDes26mj9KIGtDo+g9xosFRSC+i1gQh2oAN/tQ62AI/pGZGQjVOiRg==", + "dev": true + }, "async-limiter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", @@ -384,6 +411,12 @@ "resolved": "http://registry.npmjs.org/bignumber.js/-/bignumber.js-2.4.0.tgz", "integrity": "sha1-g4qZLan51zfg9LLbC+YrsJ3Qxeg=" }, + "binary-extensions": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz", + "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", + "dev": true + }, "bmp-js": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.0.3.tgz", @@ -554,6 +587,37 @@ "supports-color": "^2.0.0" } }, + "chokidar": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.5.tgz", + "integrity": "sha512-i0TprVWp+Kj4WRPtInjexJ8Q+BqTE909VpH8xVhXrJkoc5QC8VO9TryGOqTr+2hljzc1sC62t22h5tZePodM/A==", + "dev": true, + "requires": { + "anymatch": "^2.0.0", + "async-each": "^1.0.1", + "braces": "^2.3.2", + "fsevents": "^1.2.7", + "glob-parent": "^3.1.0", + "inherits": "^2.0.3", + "is-binary-path": "^1.0.0", + "is-glob": "^4.0.0", + "normalize-path": "^3.0.0", + "path-is-absolute": "^1.0.0", + "readdirp": "^2.2.1", + "upath": "^1.1.1" + }, + "dependencies": { + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + } + } + }, "chrome-launcher": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/chrome-launcher/-/chrome-launcher-0.10.5.tgz", @@ -771,6 +835,26 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "csproj2ts": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/csproj2ts/-/csproj2ts-1.1.0.tgz", + "integrity": "sha512-sk0RTT51t4lUNQ7UfZrqjQx7q4g0m3iwNA6mvyh7gLsgQYvwKzfdyoAgicC9GqJvkoIkU0UmndV9c7VZ8pJ45Q==", + "dev": true, + "requires": { + "es6-promise": "^4.1.1", + "lodash": "^4.17.4", + "semver": "^5.4.1", + "xml2js": "^0.4.19" + }, + "dependencies": { + "es6-promise": { + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz", + "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==", + "dev": true + } + } + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -885,6 +969,21 @@ "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=", "dev": true }, + "detect-indent": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz", + "integrity": "sha1-920GQ1LN9Docts5hnE7jqUdd4gg=", + "dev": true, + "requires": { + "repeating": "^2.0.0" + } + }, + "detect-newline": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz", + "integrity": "sha1-9B8cEL5LAOh7XxPaaAdZ8sW/0+I=", + "dev": true + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -1470,6 +1569,554 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "fsevents": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.7.tgz", + "integrity": "sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw==", + "dev": true, + "optional": true, + "requires": { + "nan": "^2.9.2", + "node-pre-gyp": "^0.10.0" + }, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "chownr": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "debug": { + "version": "2.6.9", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "fs-minipass": { + "version": "1.2.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "^2.2.1" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "glob": { + "version": "7.1.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "iconv-lite": { + "version": "0.4.24", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "ignore-walk": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minimatch": "^3.0.4" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "ini": { + "version": "1.3.5", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true, + "optional": true + }, + "minipass": { + "version": "2.3.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "minizlib": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "^2.2.1" + } + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "needle": { + "version": "2.2.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "^2.1.2", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + } + }, + "node-pre-gyp": { + "version": "0.10.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "^1.0.2", + "mkdirp": "^0.5.1", + "needle": "^2.2.1", + "nopt": "^4.0.1", + "npm-packlist": "^1.1.6", + "npmlog": "^4.0.2", + "rc": "^1.2.7", + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^4" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + }, + "npm-bundled": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "npm-packlist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ignore-walk": "^3.0.1", + "npm-bundled": "^1.0.1" + } + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "wrappy": "1" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "rimraf": { + "version": "2.6.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "glob": "^7.1.3" + } + }, + "safe-buffer": { + "version": "5.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "safer-buffer": { + "version": "2.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sax": { + "version": "1.2.4", + "bundled": true, + "dev": true, + "optional": true + }, + "semver": { + "version": "5.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "4.4.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "chownr": "^1.1.1", + "fs-minipass": "^1.2.5", + "minipass": "^2.3.4", + "minizlib": "^1.1.1", + "mkdirp": "^0.5.0", + "safe-buffer": "^5.1.2", + "yallist": "^3.0.2" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "wide-align": { + "version": "1.1.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "yallist": { + "version": "3.0.3", + "bundled": true, + "dev": true, + "optional": true + } + } + }, "gaze": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/gaze/-/gaze-1.1.3.tgz", @@ -1518,6 +2165,16 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", + "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", + "dev": true, + "requires": { + "is-glob": "^3.1.0", + "path-dirname": "^1.0.0" + } + }, "global": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/global/-/global-4.3.2.tgz", @@ -2861,6 +3518,39 @@ } } }, + "grunt-ts": { + "version": "6.0.0-beta.22", + "resolved": "https://registry.npmjs.org/grunt-ts/-/grunt-ts-6.0.0-beta.22.tgz", + "integrity": "sha512-g9e+ZImQ7W38dfpwhp0+GUltXWidy3YGPfIA/IyGL5HMv6wmVmMMoSgscI5swhs2HSPf8yAvXAAJbwrouijoRg==", + "dev": true, + "requires": { + "chokidar": "^2.0.4", + "csproj2ts": "^1.1.0", + "detect-indent": "^4.0.0", + "detect-newline": "^2.1.0", + "es6-promise": "~0.1.1", + "jsmin2": "^1.2.1", + "lodash": "~4.17.10", + "ncp": "0.5.1", + "rimraf": "2.2.6", + "semver": "^5.3.0", + "strip-bom": "^2.0.0" + }, + "dependencies": { + "es6-promise": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-0.1.2.tgz", + "integrity": "sha1-8RLCn+paCZhTn8tqL9IUQ9KPBfc=", + "dev": true + }, + "rimraf": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.6.tgz", + "integrity": "sha1-xZWXVpsU2VatKcrMQr3d9fDqT0w=", + "dev": true + } + } + }, "gzip-size": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-3.0.0.tgz", @@ -3083,6 +3773,15 @@ "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "dev": true }, + "is-binary-path": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz", + "integrity": "sha1-dfFmQrSA8YenEcgUFh/TpKdlWJg=", + "dev": true, + "requires": { + "binary-extensions": "^1.0.0" + } + }, "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", @@ -3318,6 +4017,12 @@ "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "optional": true }, + "jsmin2": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/jsmin2/-/jsmin2-1.2.1.tgz", + "integrity": "sha1-iPvi+/dfCpH2YCD9mBzWk/S/5X4=", + "dev": true + }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -3706,6 +4411,13 @@ "integrity": "sha512-7qPFYrSTiyI95rSElQ7Vsfh4XyLnlf6qTnYpio+O3jr1u54ONW7uYWyECv1UBB537xMPKRRRUGcWAUFTlMtpgg==", "dev": true }, + "nan": { + "version": "2.13.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", + "integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==", + "dev": true, + "optional": true + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -3725,6 +4437,12 @@ "to-regex": "^3.0.1" } }, + "ncp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-0.5.1.tgz", + "integrity": "sha1-dDmFMW49tFkoG1hxaehFc1oFQ58=", + "dev": true + }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", @@ -3767,6 +4485,12 @@ "validate-npm-package-license": "^3.0.1" } }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true + }, "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -3996,6 +4720,12 @@ } } }, + "path-dirname": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", + "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=", + "dev": true + }, "path-exists": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", @@ -4300,6 +5030,17 @@ } } }, + "readdirp": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", + "integrity": "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.11", + "micromatch": "^3.1.10", + "readable-stream": "^2.0.2" + } + }, "rechoir": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", @@ -4334,6 +5075,12 @@ "safe-regex": "^1.1.0" } }, + "remove-trailing-separator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", + "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", + "dev": true + }, "repeat-element": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz", @@ -5039,6 +5786,12 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typescript": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.1.tgz", + "integrity": "sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q==", + "dev": true + }, "uglify-js": { "version": "3.4.7", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.7.tgz", @@ -5150,6 +5903,12 @@ } } }, + "upath": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/upath/-/upath-1.1.2.tgz", + "integrity": "sha512-kXpym8nmDmlCBr7nKdIx8P2jNBa+pBpIUFRnKJ4dr8htyYGJFokkr2ZvERRtUN+9SY+JqXouNgUPtv6JQva/2Q==", + "dev": true + }, "uri-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/uri-path/-/uri-path-1.0.0.tgz", diff --git a/package.json b/package.json index 4da0b665bf..339bd5b777 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,12 @@ "grunt-contrib-watch": "^1.1.0", "grunt-rollup": "^9.0.0", "grunt-shell": "^1.1.2", + "grunt-ts": "^6.0.0-beta.22", "mdn-polyfills": "^5.15.0", "rollup": "^0.67.4", "rollup-plugin-commonjs": "^8.4.1", - "rollup-plugin-node-resolve": "^3.4.0" + "rollup-plugin-node-resolve": "^3.4.0", + "typescript": "^3.4.1" }, "dependencies": { "@stackoverflow/stacks-icons": "^1.16.0", diff --git a/tsconfig.json b/tsconfig.json index 18556d8f40..981190f2df 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,9 @@ "strict": true, "typeRoots": ["node_modules/@types", "node_modules/@stimulus/core"], "target": "es5", - "lib": ["dom", "es6", "dom.iterable", "scripthost"] // es6 stuff is polyfilled by stimulus + "lib": ["dom", "es6", "dom.iterable", "scripthost"], // es6 stuff is polyfilled by stimulus + "outDir": "build/ts", + "rootDir": "lib/ts" }, "include": ["lib/ts/**/*.ts"] } \ No newline at end of file From b91d490b9f6f0eb9e4a5522df8e0a93086f8d9ba Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 13:15:00 -0400 Subject: [PATCH 05/26] move tsconfig down a level, to allow separate tsconfig in docs --- Gruntfile.js | 8 ++++---- tsconfig.json => lib/tsconfig.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename tsconfig.json => lib/tsconfig.json (52%) diff --git a/Gruntfile.js b/Gruntfile.js index 82607ab828..301d054365 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,7 +76,7 @@ module.exports = function(grunt) { // Minify and concatenate JS ts: { stacks_js: { - tsconfig: "tsconfig.json" + tsconfig: "lib/tsconfig.json" } }, uglify: { @@ -99,9 +99,9 @@ module.exports = function(grunt) { files: { 'dist/js/stacks.js': [ 'node_modules/stimulus/dist/stimulus.umd.js', - 'build/ts/stacks.js', - 'build/ts/controllers/**/*.js', - 'build/ts/finalize.js' + 'build/lib/ts/stacks.js', + 'build/lib/ts/controllers/**/*.js', + 'build/lib/ts/finalize.js' ] } }, diff --git a/tsconfig.json b/lib/tsconfig.json similarity index 52% rename from tsconfig.json rename to lib/tsconfig.json index 981190f2df..9bb9670faa 100644 --- a/tsconfig.json +++ b/lib/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { "strict": true, - "typeRoots": ["node_modules/@types", "node_modules/@stimulus/core"], + "typeRoots": ["../node_modules/@types", "../node_modules/@stimulus/core"], "target": "es5", "lib": ["dom", "es6", "dom.iterable", "scripthost"], // es6 stuff is polyfilled by stimulus - "outDir": "build/ts", - "rootDir": "lib/ts" + "outDir": "../build", + "rootDir": "." }, - "include": ["lib/ts/**/*.ts"] + "include": ["./ts/**/*.ts"] } \ No newline at end of file From 53629d4fbc76f75a235227e9acc1e09a39c61fb8 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 13:40:51 -0400 Subject: [PATCH 06/26] convert docs-resizer to ts; use stimulus directly (no need to depend on stacks); set up build for docs ts --- Gruntfile.js | 19 ++++------- .../{docs-resizer.js => docs-resizer.ts} | 33 +++++++++++++------ docs/assets/js/controllers/stimulus.d.ts | 4 +++ docs/assets/js/tsconfig.json | 10 ++++++ 4 files changed, 43 insertions(+), 23 deletions(-) rename docs/assets/js/controllers/{docs-resizer.js => docs-resizer.ts} (54%) create mode 100644 docs/assets/js/controllers/stimulus.d.ts create mode 100644 docs/assets/js/tsconfig.json diff --git a/Gruntfile.js b/Gruntfile.js index 301d054365..f9c944bb98 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -77,6 +77,9 @@ module.exports = function(grunt) { ts: { stacks_js: { tsconfig: "lib/tsconfig.json" + }, + docs_js: { + tsconfig: "docs/assets/js/tsconfig.json" } }, uglify: { @@ -104,17 +107,7 @@ module.exports = function(grunt) { 'build/lib/ts/finalize.js' ] } - }, - docs_js: { - options: { - separator: '\n\n;\n\n' - }, - files: { - 'docs/assets/js/controllers.js': [ - 'docs/assets/js/controllers/*.js' - ] - } - }, + } }, // Watch for files to change and run tasks when they do watch: { @@ -133,7 +126,7 @@ module.exports = function(grunt) { docs_js: { files: ['docs/assets/js/controllers/*.js'], - tasks: ['concat:docs_js'] + tasks: ['ts:docs_js'] }, stacks_js: { @@ -161,7 +154,7 @@ module.exports = function(grunt) { // CSS and JS compilation don't impact each other, thus can run in parallel compile: [ 'concurrent:compile_stacks_css', - 'concat:docs_js', + 'ts:docs_js', ['concurrent:compile_stacks_js', 'copy:js2docs'] ], diff --git a/docs/assets/js/controllers/docs-resizer.js b/docs/assets/js/controllers/docs-resizer.ts similarity index 54% rename from docs/assets/js/controllers/docs-resizer.js rename to docs/assets/js/controllers/docs-resizer.ts index 150cd675e4..21b5e13c81 100644 --- a/docs/assets/js/controllers/docs-resizer.js +++ b/docs/assets/js/controllers/docs-resizer.ts @@ -1,7 +1,17 @@ -Stacks.addController("docs-resizer", { - targets: ["resizable", "default"], +var application = Stimulus.Application.start(); +application.register("docs-resizer", class extends Stimulus.Controller { + static targets = ["resizable", "default"]; + declare resizableTarget!: Element; + declare resizableTargets!: Element[]; + declare hasResizableTarget!: boolean; + declare defaultTarget!: Element; + declare defaultTargets!: Element[]; + declare hasDefaultTarget!: boolean; - connect: function () { + private _selected!: Element | null; + private _sizeClass!: string | null; + + connect() { this._selected = null; this._sizeClass = null; if (this.hasDefaultTarget) { @@ -12,17 +22,20 @@ Stacks.addController("docs-resizer", { that.defaultTarget.dispatchEvent(evt); }, 0); } - }, + }; - small: function (e) { + small(e: Event) { this._handleSizeEvent(e, "w4"); - }, + }; - large: function (e) { + large(e: Event) { this._handleSizeEvent(e, "w100"); - }, + }; - _handleSizeEvent: function(evt, cls) { + _handleSizeEvent(evt: Event, cls: string) { + if (!(evt.currentTarget instanceof Element)) { + throw "unexpected event" + } if (this._sizeClass) { this.resizableTarget.classList.remove(this._sizeClass); } @@ -32,7 +45,7 @@ Stacks.addController("docs-resizer", { } this._sizeClass = cls; this.resizableTarget.classList.add(cls); - this._selected = evt.currentTarget; + this._selected = evt.currentTarget as Element; evt.currentTarget.classList.add("bg-black-100"); evt.currentTarget.classList.add("fc-black-600"); evt.preventDefault(); diff --git a/docs/assets/js/controllers/stimulus.d.ts b/docs/assets/js/controllers/stimulus.d.ts new file mode 100644 index 0000000000..092d009721 --- /dev/null +++ b/docs/assets/js/controllers/stimulus.d.ts @@ -0,0 +1,4 @@ +// allows stimulus to be used as a UMD global from TypeScript. +// You can delete this file after https://github.com/stimulusjs/stimulus/issues/238 has been fixed +export * from "stimulus"; +export as namespace Stimulus; diff --git a/docs/assets/js/tsconfig.json b/docs/assets/js/tsconfig.json new file mode 100644 index 0000000000..433f5e58f2 --- /dev/null +++ b/docs/assets/js/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "strict": true, + "typeRoots": ["../node_modules/@types", "../node_modules/@stimulus/core"], + "target": "es5", + "lib": ["dom", "es6", "dom.iterable", "scripthost"], // es6 stuff is polyfilled by stimulus + "outFile": "./controllers.js" + }, + "include": ["./controllers/*.ts", "./controllers/*.d.ts"] +} \ No newline at end of file From 63b5aeb25eb08e14d55e5b6c9636c06ce90fbef8 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 14:07:22 -0400 Subject: [PATCH 07/26] IIFE these controller files --- lib/ts/controllers/s-expandable-control.ts | 300 +++++++-------- lib/ts/controllers/s-table.ts | 408 ++++++++++----------- 2 files changed, 353 insertions(+), 355 deletions(-) diff --git a/lib/ts/controllers/s-expandable-control.ts b/lib/ts/controllers/s-expandable-control.ts index 270c94ec91..e09c4445d0 100644 --- a/lib/ts/controllers/s-expandable-control.ts +++ b/lib/ts/controllers/s-expandable-control.ts @@ -1,170 +1,172 @@ -// Radio buttons only trigger a change event when they're *checked*, but not when -// they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in -// the document, we listen for change events on *all* radio buttons and find any -// other radio buttons in the same `name` group, triggering a custom event on all -// of them so the controller can re-evaluate. -// -// We're keeping a count of how many of these controllers are connected to the DOM, -// so only have this global listener when we actually need it. - -const RADIO_OFF_EVENT = "s-expandable-control:radio-off"; - -function globalChangeListener(e: UIEvent) { - const target = e.target; - if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { - return; +(function(){ + // Radio buttons only trigger a change event when they're *checked*, but not when + // they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in + // the document, we listen for change events on *all* radio buttons and find any + // other radio buttons in the same `name` group, triggering a custom event on all + // of them so the controller can re-evaluate. + // + // We're keeping a count of how many of these controllers are connected to the DOM, + // so only have this global listener when we actually need it. + const RADIO_OFF_EVENT = "s-expandable-control:radio-off"; + + function globalChangeListener(e: UIEvent) { + const target = e.target; + if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { + return; + } + document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') + .forEach(function (other) { + if (other === e.target) { + return; + } + var customEvent; + try { + customEvent = new Event(RADIO_OFF_EVENT); + } catch (ex) { + // Internet Explorer + customEvent = document.createEvent("Event"); + customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } + other.dispatchEvent(customEvent); + }); } - document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') - .forEach(function (other) { - if (other === e.target) { - return; + + var refCount = 0; + function globalChangeListenerRequired(required: boolean) { + if (required) { + refCount++; + if (refCount === 1) { + document.body.addEventListener("change", globalChangeListener as EventListener); } - var customEvent; - try { - customEvent = new Event(RADIO_OFF_EVENT); - } catch (ex) { - // Internet Explorer - customEvent = document.createEvent("Event"); - customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } else { + refCount--; + if (refCount === 0) { + document.body.removeEventListener("change", globalChangeListener as EventListener); } - other.dispatchEvent(customEvent); - }); -} - -var refCount = 0; -function globalChangeListenerRequired(required: boolean) { - if (required) { - refCount++; - if (refCount === 1) { - document.body.addEventListener("change", globalChangeListener as EventListener); - } - } else { - refCount--; - if (refCount === 0) { - document.body.removeEventListener("change", globalChangeListener as EventListener); } } -} - -Stacks.addController("s-expandable-control", class extends Stacks.StacksController { - private isCollapsed!: () => boolean; - private events!: string[]; - private isCheckable!: boolean; - private isRadio!: boolean; - - initialize() { - if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf((this.element).type) >= 0) { - this.isCollapsed = this._isCollapsedForCheckable; - this.events = ["change", RADIO_OFF_EVENT]; - this.isCheckable = true; - this.isRadio = (this.element).type === "radio"; - } else { - this.isCollapsed = this._isCollapsedForClickable; - this.events = ["click", "keydown"]; - } - this.listener = this.listener.bind(this); - }; + Stacks.addController("s-expandable-control", class extends Stacks.StacksController { + private isCollapsed!: () => boolean; + private events!: string[]; + private isCheckable!: boolean; + private isRadio!: boolean; + + initialize() { + if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf((this.element).type) >= 0) { + this.isCollapsed = this._isCollapsedForCheckable; + this.events = ["change", RADIO_OFF_EVENT]; + this.isCheckable = true; + this.isRadio = (this.element).type === "radio"; + } else { + this.isCollapsed = this._isCollapsedForClickable; + this.events = ["click", "keydown"]; + } + this.listener = this.listener.bind(this); + }; - // for non-checkable elements, the initial source of truth is the collapsed/expanded - // state of the controlled element (unless the element doesn't exist) - _isCollapsedForClickable() { - var cc = this.controlledCollapsible; - return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; - }; - // for checkable elements, the initial source of truth is the checked state - _isCollapsedForCheckable() { - return !(this.element).checked; - }; + // for non-checkable elements, the initial source of truth is the collapsed/expanded + // state of the controlled element (unless the element doesn't exist) + _isCollapsedForClickable() { + var cc = this.controlledCollapsible; + return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; + }; + // for checkable elements, the initial source of truth is the checked state + _isCollapsedForCheckable() { + return !(this.element).checked; + }; - get controlledCollapsible() { - const attr = this.element.getAttribute("aria-controls"); - if (!attr) { - throw "couldn't find controls" - } - const result = document.getElementById(attr); - if (!result) { - throw "couldn't find controls" - } - return result; - }; - _dispatchShowHideEvent(isShow: boolean) { - this.triggerEvent(isShow ? "show" : "hide"); - }; + get controlledCollapsible() { + const attr = this.element.getAttribute("aria-controls"); + if (!attr) { + throw "couldn't find controls" + } + const result = document.getElementById(attr); + if (!result) { + throw "couldn't find controls" + } + return result; + }; - _toggleClass(doAdd: boolean) { - if (!this.data.has("toggle-class")) { - return; - } - var cl = this.element.classList; - var toggleClass = this.data.get("toggle-class"); - if (!toggleClass) { - throw "couldn't find toggle class" - } - toggleClass.split(/\s+/).forEach(function (cls) { - cl.toggle(cls, !!doAdd); - }); - }; - - listener(e: UIEvent) { - var newCollapsed; - if (this.isCheckable) { - newCollapsed = !(this.element).checked; - } else { - if (e.type == "keydown" && ((e).keyCode != 13 && (e).keyCode != 32)) { + _dispatchShowHideEvent(isShow: boolean) { + this.triggerEvent(isShow ? "show" : "hide"); + }; + + _toggleClass(doAdd: boolean) { + if (!this.data.has("toggle-class")) { return; } - if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf((e.target).nodeName) >= 0) { - return; + var cl = this.element.classList; + var toggleClass = this.data.get("toggle-class"); + if (!toggleClass) { + throw "couldn't find toggle class" + } + toggleClass.split(/\s+/).forEach(function (cls) { + cl.toggle(cls, !!doAdd); + }); + }; + + listener(e: UIEvent) { + var newCollapsed; + if (this.isCheckable) { + newCollapsed = !(this.element).checked; + } else { + if (e.type == "keydown" && ((e).keyCode != 13 && (e).keyCode != 32)) { + return; + } + if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf((e.target).nodeName) >= 0) { + return; + } + newCollapsed = this.element.getAttribute("aria-expanded") === "true"; + e.preventDefault(); + if (e.type === "click") { + (this.element).blur(); + } } - newCollapsed = this.element.getAttribute("aria-expanded") === "true"; - e.preventDefault(); - if (e.type === "click") { - (this.element).blur(); + this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); + this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); + this._dispatchShowHideEvent(!newCollapsed); + this._toggleClass(!newCollapsed); + }; + + connect() { + this.events.forEach(e => { + this.element.addEventListener(e, this.listener as EventListener); + }, this); + + if (this.isRadio) { + globalChangeListenerRequired(true); } - } - this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); - this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); - this._dispatchShowHideEvent(!newCollapsed); - this._toggleClass(!newCollapsed); - }; - - connect() { - this.events.forEach(e => { - this.element.addEventListener(e, this.listener as EventListener); - }, this); - - if (this.isRadio) { - globalChangeListenerRequired(true); - } - // synchronize state -- in all cases, this means setting the correct `aria-expanded` - // attribute; for checkable controls this also means setting the `is-collapsed` class - this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); - if (this.isCheckable) { - var cc = this.controlledCollapsible; - if (cc) { - var expected = !this.isCollapsed(); - var actual = cc.classList.contains("is-expanded"); - if (expected !== actual) { - cc.classList.toggle("is-expanded", expected); - this._dispatchShowHideEvent(expected); - this._toggleClass(expected); + // synchronize state -- in all cases, this means setting the correct `aria-expanded` + // attribute; for checkable controls this also means setting the `is-collapsed` class + this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); + if (this.isCheckable) { + var cc = this.controlledCollapsible; + if (cc) { + var expected = !this.isCollapsed(); + var actual = cc.classList.contains("is-expanded"); + if (expected !== actual) { + cc.classList.toggle("is-expanded", expected); + this._dispatchShowHideEvent(expected); + this._toggleClass(expected); + } } } - } - }; + }; - disconnect() { - this.events.forEach(e => { - this.element.removeEventListener(e, this.listener as EventListener); - }, this); + disconnect() { + this.events.forEach(e => { + this.element.removeEventListener(e, this.listener as EventListener); + }, this); - if (this.isRadio) { - globalChangeListenerRequired(false); - } - }; -}); + if (this.isRadio) { + globalChangeListenerRequired(false); + } + }; + }); + +})(); \ No newline at end of file diff --git a/lib/ts/controllers/s-table.ts b/lib/ts/controllers/s-table.ts index d641a4565c..ddde65f6f5 100644 --- a/lib/ts/controllers/s-table.ts +++ b/lib/ts/controllers/s-table.ts @@ -1,224 +1,220 @@ -Stacks.addController("s-table", class extends Stacks.StacksController { - static targets = ["column"]; - declare readonly columnTarget!: Element; - declare readonly columnTargets!: Element[]; - - setCurrentSort(headElem: Element, direction: "asc" | "desc" | "none") { - if (["asc", "desc", "none"].indexOf(direction) < 0) { - throw "direction must be one of asc, desc, or none" - } - var controller = this; - this.columnTargets.forEach(function (target) { - var isCurrrent = target === headElem; - - target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); - - target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { - var visible = isCurrrent ? direction : "none"; - icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); - }); - - if (!isCurrrent || direction === "none") { - controller.removeElementData(target, "sort-direction"); - } else { - controller.setElementData(target, "sort-direction", direction); +(function(){ + Stacks.addController("s-table", class extends Stacks.StacksController { + static targets = ["column"]; + declare readonly columnTarget!: Element; + declare readonly columnTargets!: Element[]; + + setCurrentSort(headElem: Element, direction: "asc" | "desc" | "none") { + if (["asc", "desc", "none"].indexOf(direction) < 0) { + throw "direction must be one of asc, desc, or none" } - }); - }; - - sort(evt: Event) { - var controller = this; - var colHead = evt.currentTarget; - if (!(colHead instanceof HTMLTableCellElement)) { - throw "invalid event target"; - } - var table = this.element as HTMLTableElement; - var tbody = table.tBodies[0]; - - // the column slot number of the clicked header - var colno = getCellSlot(colHead); - - if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head - return; - } - - // an index of the , so we can find out for each row which element is - // in the same column slot as the header - var slotIndex = buildIndex(tbody); - - // the default behavior when clicking a header is to sort by this column in ascending - // direction, *unless* it is already sorted that way - var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; - - var rows = Array.from(table.tBodies[0].rows); - - // if this is still false after traversing the data, that means all values are integers (or empty) - // and thus we'll sort numerically. - var anyNonInt = false; - - // data will be a list of tuples [value, rowNum], where value is what we're sorting by - var data: [string | number, number][] = []; - var firstBottomRow: HTMLTableRowElement; - rows.forEach(function (row, index) { - var force = controller.getElementData(row, "sort-to"); - if (force === "top") { - return; // rows not added to the list will automatically end up at the top - } else if (force === "bottom") { - if (!firstBottomRow) { - firstBottomRow = row; + var controller = this; + this.columnTargets.forEach(function (target) { + var isCurrrent = target === headElem; + + target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); + + target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { + var visible = isCurrrent ? direction : "none"; + icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); + }); + + if (!isCurrrent || direction === "none") { + controller.removeElementData(target, "sort-direction"); + } else { + controller.setElementData(target, "sort-direction", direction); } - return; + }); + }; + + sort(evt: Event) { + var controller = this; + var colHead = evt.currentTarget; + if (!(colHead instanceof HTMLTableCellElement)) { + throw "invalid event target"; } - var cell = slotIndex[index][colno]; - if (!cell) { - data.push(["", index]); + var table = this.element as HTMLTableElement; + var tbody = table.tBodies[0]; + + // the column slot number of the clicked header + var colno = getCellSlot(colHead); + + if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head return; } - - // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, - // the value we're using is the cell's text, trimmed of any whitespace - var explicit = controller.getElementData(cell, "sort-val"); - var d = typeof explicit === "string" ? explicit : cell.textContent!.trim(); - - if ((d !== "") && (parseInt(d, 10) + "" !== d)) { - anyNonInt = true; + + // an index of the , so we can find out for each row which element is + // in the same column slot as the header + var slotIndex = buildIndex(tbody); + + // the default behavior when clicking a header is to sort by this column in ascending + // direction, *unless* it is already sorted that way + var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; + + var rows = Array.from(table.tBodies[0].rows); + + // if this is still false after traversing the data, that means all values are integers (or empty) + // and thus we'll sort numerically. + var anyNonInt = false; + + // data will be a list of tuples [value, rowNum], where value is what we're sorting by + var data: [string | number, number][] = []; + var firstBottomRow: HTMLTableRowElement; + rows.forEach(function (row, index) { + var force = controller.getElementData(row, "sort-to"); + if (force === "top") { + return; // rows not added to the list will automatically end up at the top + } else if (force === "bottom") { + if (!firstBottomRow) { + firstBottomRow = row; + } + return; + } + var cell = slotIndex[index][colno]; + if (!cell) { + data.push(["", index]); + return; + } + + // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, + // the value we're using is the cell's text, trimmed of any whitespace + var explicit = controller.getElementData(cell, "sort-val"); + var d = typeof explicit === "string" ? explicit : cell.textContent!.trim(); + + if ((d !== "") && (parseInt(d, 10) + "" !== d)) { + anyNonInt = true; + } + data.push([d, index]); + }); + + // If all values were integers (or empty cells), sort numerically, with empty cells treated as + // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) + if (!anyNonInt) { + data.forEach(function (tuple) { + tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0] as string, 10); + }); } - data.push([d, index]); - }); - - // If all values were integers (or empty cells), sort numerically, with empty cells treated as - // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) - if (!anyNonInt) { - data.forEach(function (tuple) { - tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0] as string, 10); + + // We don't sort an array of , but instead an arrays of row *numbers*, because this way we + // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same + // order (the JS standard does not gurantee this for sort()). + data.sort(function (a, b) { + // first compare the values (a[0]) + if (a[0] > b[0]) { + return 1 * direction; + } else if (a[0] < b[0]) { + return -1 * direction; + } else { + // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting + // (note that this comparison is independent of the sorting direction) + return a[1] > b[1] ? 1 : -1; + } + }); + + // this is the actual reordering of the table rows + data.forEach(function (tup) { + var row = rows[tup[1]]; + row.parentElement!.removeChild(row); + if (firstBottomRow) { + tbody.insertBefore(row, firstBottomRow); + } else { + tbody.appendChild(row); + } }); + + // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click + // will cause sorting in descending direction + this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); } - - // We don't sort an array of , but instead an arrays of row *numbers*, because this way we - // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same - // order (the JS standard does not gurantee this for sort()). - data.sort(function (a, b) { - // first compare the values (a[0]) - if (a[0] > b[0]) { - return 1 * direction; - } else if (a[0] < b[0]) { - return -1 * direction; - } else { - // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting - // (note that this comparison is independent of the sorting direction) - return a[1] > b[1] ? 1 : -1; - } - }); - - // this is the actual reordering of the table rows - data.forEach(function (tup) { - var row = rows[tup[1]]; - row.parentElement!.removeChild(row); - if (firstBottomRow) { - tbody.insertBefore(row, firstBottomRow); - } else { - tbody.appendChild(row); - } - }); - - // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click - // will cause sorting in descending direction - this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); - } + + }); -}); - -function buildIndex(section: HTMLTableSectionElement): HTMLTableCellElement[][] { - const result = buildIndexOrGetCellSlot(section); - if (!(result instanceof Array)) { - throw "shouldn't happen" - } - return result; -} - -function getCellSlot(cell: HTMLTableCellElement): number { - if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { - throw "invalid table" + function buildIndex(section: HTMLTableSectionElement): HTMLTableCellElement[][] { + const result = buildIndexOrGetCellSlot(section); + if (!(result instanceof Array)) { + throw "shouldn't happen" + } + return result; } - const result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); - if (typeof result !== "number") { - throw "shouldn't happen" + + function getCellSlot(cell: HTMLTableCellElement): number { + if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { + throw "invalid table" + } + const result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (typeof result !== "number") { + throw "shouldn't happen" + } + return result } - return result -} - -// Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* -// of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. -// Because we need to know which header cells and data cells belong together, we have to 1) find out -// which column number (or "slot" as we call it here) the header cell has, and 2) for each row find -// out which cell corresponds to this slot (because those are the rows we're sorting by). -// -// That's what the following function does. If the second argument is not given, it returns an index -// of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The -// indices of the sub-array correspond to column slots; the values are the actual table cell elements. -// For example index[4][3] is the or in row 4, column 3 of the table section ( or ). -// Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, -// it may also be in a previous . -// -// If the second argument is given, it's a or that we're trying to find, and the algorithm -// stops as soon as it has found it and the function returns its slot number. -function buildIndexOrGetCellSlot(section: HTMLTableSectionElement, findCell?: HTMLTableCellElement) { - var index = []; - var curRow = section.children[0]; - - // the elements of these two arrays are synchronized; the first array contains table cell elements, - // the second one contains a number that indicates for how many more rows this elements will - // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) - var growing: HTMLTableCellElement[] = []; - var growingRowsLeft: number[] = []; - - // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done - while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { - var curIndexRow: HTMLTableCellElement[] = []; - index.push(curIndexRow); - - var curSlot = 0; - if (curRow) { - for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { - while (growingRowsLeft[curSlot]) { + + // Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* + // of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. + // Because we need to know which header cells and data cells belong together, we have to 1) find out + // which column number (or "slot" as we call it here) the header cell has, and 2) for each row find + // out which cell corresponds to this slot (because those are the rows we're sorting by). + // + // That's what the following function does. If the second argument is not given, it returns an index + // of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The + // indices of the sub-array correspond to column slots; the values are the actual table cell elements. + // For example index[4][3] is the or in row 4, column 3 of the table section ( or ). + // Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, + // it may also be in a previous . + // + // If the second argument is given, it's a or that we're trying to find, and the algorithm + // stops as soon as it has found it and the function returns its slot number. + function buildIndexOrGetCellSlot(section: HTMLTableSectionElement, findCell?: HTMLTableCellElement) { + var index = []; + var curRow = section.children[0]; + + // the elements of these two arrays are synchronized; the first array contains table cell elements, + // the second one contains a number that indicates for how many more rows this elements will + // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) + var growing: HTMLTableCellElement[] = []; + var growingRowsLeft: number[] = []; + + // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done + while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { + var curIndexRow: HTMLTableCellElement[] = []; + index.push(curIndexRow); + + var curSlot = 0; + if (curRow) { + for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { + while (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + curSlot++; + } + var cell = curRow.children[curCellInd]; + if (!(cell instanceof HTMLTableCellElement)) { + throw "invalid table" + } + if (getComputedStyle(cell).display === "none") { + continue; + } + if (cell === findCell) { + return curSlot; + } + var nextFreeSlot = curSlot + cell.colSpan; + for (; curSlot < nextFreeSlot; curSlot++) { + growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything + growing[curSlot] = cell; + curIndexRow[curSlot] = cell; + } + } + } + while (curSlot < growing.length) { + if (growingRowsLeft[curSlot]) { growingRowsLeft[curSlot]--; curIndexRow[curSlot] = growing[curSlot]; - curSlot++; - } - var cell = curRow.children[curCellInd]; - if (!(cell instanceof HTMLTableCellElement)) { - throw "invalid table" - } - if (getComputedStyle(cell).display === "none") { - continue; - } - if (cell === findCell) { - return curSlot; - } - var nextFreeSlot = curSlot + cell.colSpan; - for (; curSlot < nextFreeSlot; curSlot++) { - growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything - growing[curSlot] = cell; - curIndexRow[curSlot] = cell; } + curSlot++; } - } - while (curSlot < growing.length) { - if (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; + if (curRow && curRow.nextElementSibling) { + curRow = curRow.nextElementSibling; } - curSlot++; - } - if (curRow && curRow.nextElementSibling) { - curRow = curRow.nextElementSibling; } + return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ } - return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ -} - -// addController("s-table", class extends StacksController { - - -// }); - +})(); \ No newline at end of file From d674c53031a4ff4115b27cd2f70af9fe4be5feee Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Tue, 2 Apr 2019 14:31:20 -0400 Subject: [PATCH 08/26] IIFE docs resizer --- docs/assets/js/controllers/docs-resizer.ts | 106 +++++++++++---------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/docs/assets/js/controllers/docs-resizer.ts b/docs/assets/js/controllers/docs-resizer.ts index 21b5e13c81..655925ce5f 100644 --- a/docs/assets/js/controllers/docs-resizer.ts +++ b/docs/assets/js/controllers/docs-resizer.ts @@ -1,53 +1,55 @@ -var application = Stimulus.Application.start(); -application.register("docs-resizer", class extends Stimulus.Controller { - static targets = ["resizable", "default"]; - declare resizableTarget!: Element; - declare resizableTargets!: Element[]; - declare hasResizableTarget!: boolean; - declare defaultTarget!: Element; - declare defaultTargets!: Element[]; - declare hasDefaultTarget!: boolean; - - private _selected!: Element | null; - private _sizeClass!: string | null; - - connect() { - this._selected = null; - this._sizeClass = null; - if (this.hasDefaultTarget) { - var evt = document.createEvent('mouseevent'); - evt.initEvent('click', true, true); - var that = this; - setTimeout(function () { - that.defaultTarget.dispatchEvent(evt); - }, 0); +(function(){ + var application = Stimulus.Application.start(); + application.register("docs-resizer", class extends Stimulus.Controller { + static targets = ["resizable", "default"]; + declare resizableTarget!: Element; + declare resizableTargets!: Element[]; + declare hasResizableTarget!: boolean; + declare defaultTarget!: Element; + declare defaultTargets!: Element[]; + declare hasDefaultTarget!: boolean; + + private _selected!: Element | null; + private _sizeClass!: string | null; + + connect() { + this._selected = null; + this._sizeClass = null; + if (this.hasDefaultTarget) { + var evt = document.createEvent('mouseevent'); + evt.initEvent('click', true, true); + var that = this; + setTimeout(function () { + that.defaultTarget.dispatchEvent(evt); + }, 0); + } + }; + + small(e: Event) { + this._handleSizeEvent(e, "w4"); + }; + + large(e: Event) { + this._handleSizeEvent(e, "w100"); + }; + + _handleSizeEvent(evt: Event, cls: string) { + if (!(evt.currentTarget instanceof Element)) { + throw "unexpected event" + } + if (this._sizeClass) { + this.resizableTarget.classList.remove(this._sizeClass); + } + if (this._selected) { + this._selected.classList.remove("bg-black-100"); + this._selected.classList.remove("fc-black-600"); + } + this._sizeClass = cls; + this.resizableTarget.classList.add(cls); + this._selected = evt.currentTarget as Element; + evt.currentTarget.classList.add("bg-black-100"); + evt.currentTarget.classList.add("fc-black-600"); + evt.preventDefault(); } - }; - - small(e: Event) { - this._handleSizeEvent(e, "w4"); - }; - - large(e: Event) { - this._handleSizeEvent(e, "w100"); - }; - - _handleSizeEvent(evt: Event, cls: string) { - if (!(evt.currentTarget instanceof Element)) { - throw "unexpected event" - } - if (this._sizeClass) { - this.resizableTarget.classList.remove(this._sizeClass); - } - if (this._selected) { - this._selected.classList.remove("bg-black-100"); - this._selected.classList.remove("fc-black-600"); - } - this._sizeClass = cls; - this.resizableTarget.classList.add(cls); - this._selected = evt.currentTarget as Element; - evt.currentTarget.classList.add("bg-black-100"); - evt.currentTarget.classList.add("fc-black-600"); - evt.preventDefault(); - } -}); + }); +})(); \ No newline at end of file From 21b3b56f8c5659b86f57a15fc20f684a3114a76f Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Wed, 3 Apr 2019 19:21:20 -0400 Subject: [PATCH 09/26] remove controllers dictionary, it's available as application.controllers anyway --- lib/ts/stacks.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/ts/stacks.ts b/lib/ts/stacks.ts index a55bdb6b06..0dd288e8ab 100644 --- a/lib/ts/stacks.ts +++ b/lib/ts/stacks.ts @@ -26,12 +26,6 @@ namespace Stacks { }; } - - type ControllersDictionary = { [identifier: string]: Stimulus.ControllerConstructor }; - const _controllers : ControllersDictionary = {}; - export const controllers : Readonly = _controllers; - - export function addController(name: string, controller: Stimulus.ControllerConstructor) { var hasPrefix = /^s-/.test(name); if (_initializing && !hasPrefix) { @@ -41,8 +35,5 @@ namespace Stacks { throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; } application.register(name, controller); - if (_initializing) { - _controllers[name] = controller; - } }; } From 585e2400352833db4bd602bc5297b2097d9294bc Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Thu, 4 Apr 2019 13:38:26 -0400 Subject: [PATCH 10/26] reinstate old version of addController api for ES5 consumers. TS files use Stacks.application.register --- lib/ts/controllers/s-expandable-control.ts | 2 +- lib/ts/controllers/s-table.ts | 2 +- lib/ts/stacks.ts | 62 ++++++++++++++++++---- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/lib/ts/controllers/s-expandable-control.ts b/lib/ts/controllers/s-expandable-control.ts index e09c4445d0..9d7934d9dd 100644 --- a/lib/ts/controllers/s-expandable-control.ts +++ b/lib/ts/controllers/s-expandable-control.ts @@ -46,7 +46,7 @@ } } - Stacks.addController("s-expandable-control", class extends Stacks.StacksController { + Stacks.application.register("s-expandable-control", class extends Stacks.StacksController { private isCollapsed!: () => boolean; private events!: string[]; private isCheckable!: boolean; diff --git a/lib/ts/controllers/s-table.ts b/lib/ts/controllers/s-table.ts index ddde65f6f5..f68ce47f09 100644 --- a/lib/ts/controllers/s-table.ts +++ b/lib/ts/controllers/s-table.ts @@ -1,5 +1,5 @@ (function(){ - Stacks.addController("s-table", class extends Stacks.StacksController { + Stacks.application.register("s-table", class extends Stacks.StacksController { static targets = ["column"]; declare readonly columnTarget!: Element; declare readonly columnTargets!: Element[]; diff --git a/lib/ts/stacks.ts b/lib/ts/stacks.ts index 0dd288e8ab..bc128a9ff7 100644 --- a/lib/ts/stacks.ts +++ b/lib/ts/stacks.ts @@ -1,5 +1,31 @@ namespace Stacks { - export const application = Stimulus.Application.start(); + class StacksApplication extends Stimulus.Application { + load(...definitions: Stimulus.Definition[]): void + load(definitions: Stimulus.Definition[]): void + load(head: Stimulus.Definition | Stimulus.Definition[], ...rest: Stimulus.Definition[]) { + const definitions = Array.isArray(head) ? head : [head, ...rest]; + + for (const definition of definitions) { + var hasPrefix = /^s-/.test(definition.identifier); + if (_initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!_initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + } + + super.load(definitions); + } + + static start(element?: Element, schema?: Stimulus.Schema): StacksApplication { + const application = new StacksApplication(element, schema); + application.start(); + return application; + } + } + + export const application: Stimulus.Application = StacksApplication.start(); export var _initializing = true; export class StacksController extends Stimulus.Controller { @@ -25,15 +51,31 @@ namespace Stacks { (optionalElement || this.element).dispatchEvent(event); }; } - - export function addController(name: string, controller: Stimulus.ControllerConstructor) { - var hasPrefix = /^s-/.test(name); - if (_initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!_initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + + // ControllerDefinition/createController/addController is here to make + // it easier to consume Stimulus from ES5 files (without classes) + export interface ControllerDefinition { + [name: string]: any; + targets?: string[]; + } + export function createController(controllerDefinition: ControllerDefinition): typeof StacksController { + const Controller = controllerDefinition.hasOwnProperty("targets") + ? class Controller extends StacksController { static targets = controllerDefinition.targets! } + : class Controller extends StacksController {}; + + for (var prop in controllerDefinition) { + if (prop !== "targets" && controllerDefinition.hasOwnProperty(prop)) { + Object.defineProperty( + Controller.prototype, + prop, + Object.getOwnPropertyDescriptor(controllerDefinition, prop)! + ); + } } - application.register(name, controller); + + return Controller; + } + export function addController(name: string, controller: ControllerDefinition) { + application.register(name, createController(controller)); }; } From 1f6463651fea4980098153ab905397469dc83b15 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Thu, 4 Apr 2019 13:44:19 -0400 Subject: [PATCH 11/26] check in build outputs (ugh, will fix in future) and ignore map file. --- .gitignore | 1 + dist/js/stacks.js | 658 ++++++++++++++++++++++-------------------- dist/js/stacks.min.js | 2 +- 3 files changed, 355 insertions(+), 306 deletions(-) diff --git a/.gitignore b/.gitignore index 66fd3ca0f2..eb89fe89eb 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ node_modules /docs/assets/css/ /docs/assets/js/stacks.* /docs/assets/js/controllers.js +/docs/assets/js/controllers.js.map /build/ .tscache diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 6918693591..ef5fcd4d68 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -1772,7 +1772,37 @@ var __extends = (this && this.__extends) || (function () { })(); var Stacks; (function (Stacks) { - Stacks.application = Stimulus.Application.start(); + var StacksApplication = (function (_super) { + __extends(StacksApplication, _super); + function StacksApplication() { + return _super !== null && _super.apply(this, arguments) || this; + } + StacksApplication.prototype.load = function (head) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + var definitions = Array.isArray(head) ? head : [head].concat(rest); + for (var _a = 0, definitions_1 = definitions; _a < definitions_1.length; _a++) { + var definition = definitions_1[_a]; + var hasPrefix = /^s-/.test(definition.identifier); + if (Stacks._initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!Stacks._initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + } + _super.prototype.load.call(this, definitions); + }; + StacksApplication.start = function (element, schema) { + var application = new StacksApplication(element, schema); + application.start(); + return application; + }; + return StacksApplication; + }(Stimulus.Application)); + Stacks.application = StacksApplication.start(); Stacks._initializing = true; var StacksController = (function (_super) { __extends(StacksController, _super); @@ -1807,20 +1837,34 @@ var Stacks; return StacksController; }(Stimulus.Controller)); Stacks.StacksController = StacksController; - var _controllers = {}; - Stacks.controllers = _controllers; - function addController(name, controller) { - var hasPrefix = /^s-/.test(name); - if (Stacks._initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!Stacks._initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; - } - Stacks.application.register(name, controller); - if (Stacks._initializing) { - _controllers[name] = controller; + function createController(controllerDefinition) { + var _a; + var Controller = controllerDefinition.hasOwnProperty("targets") + ? (_a = (function (_super) { + __extends(Controller, _super); + function Controller() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Controller; + }(StacksController)), + _a.targets = controllerDefinition.targets, + _a) : (function (_super) { + __extends(Controller, _super); + function Controller() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Controller; + }(StacksController)); + for (var prop in controllerDefinition) { + if (prop !== "targets" && controllerDefinition.hasOwnProperty(prop)) { + Object.defineProperty(Controller.prototype, prop, Object.getOwnPropertyDescriptor(controllerDefinition, prop)); + } } + return Controller; + } + Stacks.createController = createController; + function addController(name, controller) { + Stacks.application.register(name, createController(controller)); } Stacks.addController = addController; ; @@ -1843,168 +1887,171 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var RADIO_OFF_EVENT = "s-expandable-control:radio-off"; -function globalChangeListener(e) { - var target = e.target; - if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { - return; - } - document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') - .forEach(function (other) { - if (other === e.target) { +(function () { + var RADIO_OFF_EVENT = "s-expandable-control:radio-off"; + function globalChangeListener(e) { + var target = e.target; + if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { return; } - var customEvent; - try { - customEvent = new Event(RADIO_OFF_EVENT); - } - catch (ex) { - customEvent = document.createEvent("Event"); - customEvent.initEvent(RADIO_OFF_EVENT, true, true); - } - other.dispatchEvent(customEvent); - }); -} -var refCount = 0; -function globalChangeListenerRequired(required) { - if (required) { - refCount++; - if (refCount === 1) { - document.body.addEventListener("change", globalChangeListener); - } - } - else { - refCount--; - if (refCount === 0) { - document.body.removeEventListener("change", globalChangeListener); - } - } -} -Stacks.addController("s-expandable-control", (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; + document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') + .forEach(function (other) { + if (other === e.target) { + return; + } + var customEvent; + try { + customEvent = new Event(RADIO_OFF_EVENT); + } + catch (ex) { + customEvent = document.createEvent("Event"); + customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } + other.dispatchEvent(customEvent); + }); } - class_1.prototype.initialize = function () { - if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf(this.element.type) >= 0) { - this.isCollapsed = this._isCollapsedForCheckable; - this.events = ["change", RADIO_OFF_EVENT]; - this.isCheckable = true; - this.isRadio = this.element.type === "radio"; + var refCount = 0; + function globalChangeListenerRequired(required) { + if (required) { + refCount++; + if (refCount === 1) { + document.body.addEventListener("change", globalChangeListener); + } } else { - this.isCollapsed = this._isCollapsedForClickable; - this.events = ["click", "keydown"]; - } - this.listener = this.listener.bind(this); - }; - ; - class_1.prototype._isCollapsedForClickable = function () { - var cc = this.controlledCollapsible; - return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; - }; - ; - class_1.prototype._isCollapsedForCheckable = function () { - return !this.element.checked; - }; - ; - Object.defineProperty(class_1.prototype, "controlledCollapsible", { - get: function () { - var attr = this.element.getAttribute("aria-controls"); - if (!attr) { - throw "couldn't find controls"; - } - var result = document.getElementById(attr); - if (!result) { - throw "couldn't find controls"; + refCount--; + if (refCount === 0) { + document.body.removeEventListener("change", globalChangeListener); } - return result; - }, - enumerable: true, - configurable: true - }); - ; - class_1.prototype._dispatchShowHideEvent = function (isShow) { - this.triggerEvent(isShow ? "show" : "hide"); - }; - ; - class_1.prototype._toggleClass = function (doAdd) { - if (!this.data.has("toggle-class")) { - return; } - var cl = this.element.classList; - var toggleClass = this.data.get("toggle-class"); - if (!toggleClass) { - throw "couldn't find toggle class"; + } + Stacks.application.register("s-expandable-control", (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; } - toggleClass.split(/\s+/).forEach(function (cls) { - cl.toggle(cls, !!doAdd); + class_1.prototype.initialize = function () { + if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf(this.element.type) >= 0) { + this.isCollapsed = this._isCollapsedForCheckable; + this.events = ["change", RADIO_OFF_EVENT]; + this.isCheckable = true; + this.isRadio = this.element.type === "radio"; + } + else { + this.isCollapsed = this._isCollapsedForClickable; + this.events = ["click", "keydown"]; + } + this.listener = this.listener.bind(this); + }; + ; + class_1.prototype._isCollapsedForClickable = function () { + var cc = this.controlledCollapsible; + return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; + }; + ; + class_1.prototype._isCollapsedForCheckable = function () { + return !this.element.checked; + }; + ; + Object.defineProperty(class_1.prototype, "controlledCollapsible", { + get: function () { + var attr = this.element.getAttribute("aria-controls"); + if (!attr) { + throw "couldn't find controls"; + } + var result = document.getElementById(attr); + if (!result) { + throw "couldn't find controls"; + } + return result; + }, + enumerable: true, + configurable: true }); - }; - ; - class_1.prototype.listener = function (e) { - var newCollapsed; - if (this.isCheckable) { - newCollapsed = !this.element.checked; - } - else { - if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { + ; + class_1.prototype._dispatchShowHideEvent = function (isShow) { + this.triggerEvent(isShow ? "show" : "hide"); + }; + ; + class_1.prototype._toggleClass = function (doAdd) { + if (!this.data.has("toggle-class")) { return; } - if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { - return; + var cl = this.element.classList; + var toggleClass = this.data.get("toggle-class"); + if (!toggleClass) { + throw "couldn't find toggle class"; } - newCollapsed = this.element.getAttribute("aria-expanded") === "true"; - e.preventDefault(); - if (e.type === "click") { - this.element.blur(); + toggleClass.split(/\s+/).forEach(function (cls) { + cl.toggle(cls, !!doAdd); + }); + }; + ; + class_1.prototype.listener = function (e) { + var newCollapsed; + if (this.isCheckable) { + newCollapsed = !this.element.checked; } - } - this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); - this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); - this._dispatchShowHideEvent(!newCollapsed); - this._toggleClass(!newCollapsed); - }; - ; - class_1.prototype.connect = function () { - var _this = this; - this.events.forEach(function (e) { - _this.element.addEventListener(e, _this.listener); - }, this); - if (this.isRadio) { - globalChangeListenerRequired(true); - } - this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); - if (this.isCheckable) { - var cc = this.controlledCollapsible; - if (cc) { - var expected = !this.isCollapsed(); - var actual = cc.classList.contains("is-expanded"); - if (expected !== actual) { - cc.classList.toggle("is-expanded", expected); - this._dispatchShowHideEvent(expected); - this._toggleClass(expected); + else { + if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { + return; + } + if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { + return; + } + newCollapsed = this.element.getAttribute("aria-expanded") === "true"; + e.preventDefault(); + if (e.type === "click") { + this.element.blur(); } } - } - }; - ; - class_1.prototype.disconnect = function () { - var _this = this; - this.events.forEach(function (e) { - _this.element.removeEventListener(e, _this.listener); - }, this); - if (this.isRadio) { - globalChangeListenerRequired(false); - } - }; - ; - return class_1; -}(Stacks.StacksController))); + this.element.setAttribute("aria-expanded", newCollapsed ? "false" : "true"); + this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); + this._dispatchShowHideEvent(!newCollapsed); + this._toggleClass(!newCollapsed); + }; + ; + class_1.prototype.connect = function () { + var _this = this; + this.events.forEach(function (e) { + _this.element.addEventListener(e, _this.listener); + }, this); + if (this.isRadio) { + globalChangeListenerRequired(true); + } + this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); + if (this.isCheckable) { + var cc = this.controlledCollapsible; + if (cc) { + var expected = !this.isCollapsed(); + var actual = cc.classList.contains("is-expanded"); + if (expected !== actual) { + cc.classList.toggle("is-expanded", expected); + this._dispatchShowHideEvent(expected); + this._toggleClass(expected); + } + } + } + }; + ; + class_1.prototype.disconnect = function () { + var _this = this; + this.events.forEach(function (e) { + _this.element.removeEventListener(e, _this.listener); + }, this); + if (this.isRadio) { + globalChangeListenerRequired(false); + } + }; + ; + return class_1; + }(Stacks.StacksController))); +})(); //# sourceMappingURL=s-expandable-control.js.map ; +"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -2018,171 +2065,172 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var _a; -"use strict"; -Stacks.addController("s-table", (_a = (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; - } - class_1.prototype.setCurrentSort = function (headElem, direction) { - if (["asc", "desc", "none"].indexOf(direction) < 0) { - throw "direction must be one of asc, desc, or none"; - } - var controller = this; - this.columnTargets.forEach(function (target) { - var isCurrrent = target === headElem; - target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); - target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { - var visible = isCurrrent ? direction : "none"; - icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); - }); - if (!isCurrrent || direction === "none") { - controller.removeElementData(target, "sort-direction"); - } - else { - controller.setElementData(target, "sort-direction", direction); - } - }); - }; - ; - class_1.prototype.sort = function (evt) { - var controller = this; - var colHead = evt.currentTarget; - if (!(colHead instanceof HTMLTableCellElement)) { - throw "invalid event target"; - } - var table = this.element; - var tbody = table.tBodies[0]; - var colno = getCellSlot(colHead); - if (colno < 0) { - return; +(function () { + var _a; + Stacks.application.register("s-table", (_a = (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; } - var slotIndex = buildIndex(tbody); - var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; - var rows = Array.from(table.tBodies[0].rows); - var anyNonInt = false; - var data = []; - var firstBottomRow; - rows.forEach(function (row, index) { - var force = controller.getElementData(row, "sort-to"); - if (force === "top") { - return; + class_1.prototype.setCurrentSort = function (headElem, direction) { + if (["asc", "desc", "none"].indexOf(direction) < 0) { + throw "direction must be one of asc, desc, or none"; } - else if (force === "bottom") { - if (!firstBottomRow) { - firstBottomRow = row; + var controller = this; + this.columnTargets.forEach(function (target) { + var isCurrrent = target === headElem; + target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); + target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { + var visible = isCurrrent ? direction : "none"; + icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); + }); + if (!isCurrrent || direction === "none") { + controller.removeElementData(target, "sort-direction"); } - return; + else { + controller.setElementData(target, "sort-direction", direction); + } + }); + }; + ; + class_1.prototype.sort = function (evt) { + var controller = this; + var colHead = evt.currentTarget; + if (!(colHead instanceof HTMLTableCellElement)) { + throw "invalid event target"; } - var cell = slotIndex[index][colno]; - if (!cell) { - data.push(["", index]); + var table = this.element; + var tbody = table.tBodies[0]; + var colno = getCellSlot(colHead); + if (colno < 0) { return; } - var explicit = controller.getElementData(cell, "sort-val"); - var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); - if ((d !== "") && (parseInt(d, 10) + "" !== d)) { - anyNonInt = true; - } - data.push([d, index]); - }); - if (!anyNonInt) { - data.forEach(function (tuple) { - tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); + var slotIndex = buildIndex(tbody); + var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; + var rows = Array.from(table.tBodies[0].rows); + var anyNonInt = false; + var data = []; + var firstBottomRow; + rows.forEach(function (row, index) { + var force = controller.getElementData(row, "sort-to"); + if (force === "top") { + return; + } + else if (force === "bottom") { + if (!firstBottomRow) { + firstBottomRow = row; + } + return; + } + var cell = slotIndex[index][colno]; + if (!cell) { + data.push(["", index]); + return; + } + var explicit = controller.getElementData(cell, "sort-val"); + var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); + if ((d !== "") && (parseInt(d, 10) + "" !== d)) { + anyNonInt = true; + } + data.push([d, index]); }); - } - data.sort(function (a, b) { - if (a[0] > b[0]) { - return 1 * direction; - } - else if (a[0] < b[0]) { - return -1 * direction; - } - else { - return a[1] > b[1] ? 1 : -1; - } - }); - data.forEach(function (tup) { - var row = rows[tup[1]]; - row.parentElement.removeChild(row); - if (firstBottomRow) { - tbody.insertBefore(row, firstBottomRow); + if (!anyNonInt) { + data.forEach(function (tuple) { + tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); + }); } - else { - tbody.appendChild(row); - } - }); - this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); - }; - return class_1; - }(Stacks.StacksController)), - _a.targets = ["column"], - _a)); -function buildIndex(section) { - var result = buildIndexOrGetCellSlot(section); - if (!(result instanceof Array)) { - throw "shouldn't happen"; - } - return result; -} -function getCellSlot(cell) { - if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { - throw "invalid table"; + data.sort(function (a, b) { + if (a[0] > b[0]) { + return 1 * direction; + } + else if (a[0] < b[0]) { + return -1 * direction; + } + else { + return a[1] > b[1] ? 1 : -1; + } + }); + data.forEach(function (tup) { + var row = rows[tup[1]]; + row.parentElement.removeChild(row); + if (firstBottomRow) { + tbody.insertBefore(row, firstBottomRow); + } + else { + tbody.appendChild(row); + } + }); + this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); + }; + return class_1; + }(Stacks.StacksController)), + _a.targets = ["column"], + _a)); + function buildIndex(section) { + var result = buildIndexOrGetCellSlot(section); + if (!(result instanceof Array)) { + throw "shouldn't happen"; + } + return result; } - var result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); - if (typeof result !== "number") { - throw "shouldn't happen"; + function getCellSlot(cell) { + if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { + throw "invalid table"; + } + var result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (typeof result !== "number") { + throw "shouldn't happen"; + } + return result; } - return result; -} -function buildIndexOrGetCellSlot(section, findCell) { - var index = []; - var curRow = section.children[0]; - var growing = []; - var growingRowsLeft = []; - while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { - var curIndexRow = []; - index.push(curIndexRow); - var curSlot = 0; - if (curRow) { - for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { - while (growingRowsLeft[curSlot]) { + function buildIndexOrGetCellSlot(section, findCell) { + var index = []; + var curRow = section.children[0]; + var growing = []; + var growingRowsLeft = []; + while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { + var curIndexRow = []; + index.push(curIndexRow); + var curSlot = 0; + if (curRow) { + for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { + while (growingRowsLeft[curSlot]) { + growingRowsLeft[curSlot]--; + curIndexRow[curSlot] = growing[curSlot]; + curSlot++; + } + var cell = curRow.children[curCellInd]; + if (!(cell instanceof HTMLTableCellElement)) { + throw "invalid table"; + } + if (getComputedStyle(cell).display === "none") { + continue; + } + if (cell === findCell) { + return curSlot; + } + var nextFreeSlot = curSlot + cell.colSpan; + for (; curSlot < nextFreeSlot; curSlot++) { + growingRowsLeft[curSlot] = cell.rowSpan - 1; + growing[curSlot] = cell; + curIndexRow[curSlot] = cell; + } + } + } + while (curSlot < growing.length) { + if (growingRowsLeft[curSlot]) { growingRowsLeft[curSlot]--; curIndexRow[curSlot] = growing[curSlot]; - curSlot++; - } - var cell = curRow.children[curCellInd]; - if (!(cell instanceof HTMLTableCellElement)) { - throw "invalid table"; - } - if (getComputedStyle(cell).display === "none") { - continue; - } - if (cell === findCell) { - return curSlot; - } - var nextFreeSlot = curSlot + cell.colSpan; - for (; curSlot < nextFreeSlot; curSlot++) { - growingRowsLeft[curSlot] = cell.rowSpan - 1; - growing[curSlot] = cell; - curIndexRow[curSlot] = cell; } + curSlot++; } - } - while (curSlot < growing.length) { - if (growingRowsLeft[curSlot]) { - growingRowsLeft[curSlot]--; - curIndexRow[curSlot] = growing[curSlot]; + if (curRow && curRow.nextElementSibling) { + curRow = curRow.nextElementSibling; } - curSlot++; - } - if (curRow && curRow.nextElementSibling) { - curRow = curRow.nextElementSibling; } + return findCell ? -1 : index; } - return findCell ? -1 : index; -} +})(); //# sourceMappingURL=s-table.js.map ; diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index ab26dcc2f1..6790c1e0b0 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]t[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),a?r.insertBefore(t,a):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],_a)),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||c("missing event name"),this.identifier=n.identifier||c("missing identifier"),this.methodName=n.methodName||c("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function c(e){throw new Error(e)}var a=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]t[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),a?r.insertBefore(t,a):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From 51c7f6d568fcbdc2ce6e1e428dddc1d0b05b281d Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 18 Jul 2019 15:17:11 -0400 Subject: [PATCH 12/26] rebuild files --- dist/js/stacks.js | 790 ++++++++++++++++++------------------------ dist/js/stacks.min.js | 2 +- 2 files changed, 330 insertions(+), 462 deletions(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 2c0480f69f..df7b8986e4 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4372,124 +4372,160 @@ return Popper; ; - -(function () { - window.Stacks = window.Stacks || Object.create(null); - Stacks._initializing = true; - var application = Stacks.stimulusApplication = Stimulus.Application.start(); - Stacks.controllers = Object.create(null); - - function StacksController () { - Stimulus.Controller.apply(this, arguments); - } - StacksController.prototype = Object.create(Stimulus.Controller.prototype, { - constructor: { value: StacksController, enumerable: false, writable: true } - }); - StacksController.prototype.getElementData = function(element, key) { - return element.getAttribute("data-" + this.identifier + "-" + key); +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - StacksController.prototype.setElementData = function(element, key, value) { - element.setAttribute("data-" + this.identifier + "-" + key, value); - }; - StacksController.prototype.removeElementData = function(element, key) { - element.removeAttribute("data-" + this.identifier + "-" + key); - }; - StacksController.prototype.triggerEvent = function(eventName, detail, optionalElement) { - var event; - var namespacedName = this.identifier + ":" + eventName; - try { - event = new CustomEvent(namespacedName, {bubbles: true, detail: detail}); - } catch (ex) { - // Internet Explorer - event = document.createEvent("CustomEvent"); - event.initCustomEvent(namespacedName, true, true, detail); +})(); +var Stacks; +(function (Stacks) { + var StacksApplication = (function (_super) { + __extends(StacksApplication, _super); + function StacksApplication() { + return _super !== null && _super.apply(this, arguments) || this; } - (optionalElement || this.element).dispatchEvent(event); - return event; - }; - Object.setPrototypeOf(StacksController, Stimulus.Controller); - - function createController(name, data) { - var Controller = function () { - StacksController.apply(this, arguments); + StacksApplication.prototype.load = function (head) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + var definitions = Array.isArray(head) ? head : [head].concat(rest); + for (var _a = 0, definitions_1 = definitions; _a < definitions_1.length; _a++) { + var definition = definitions_1[_a]; + var hasPrefix = /^s-/.test(definition.identifier); + if (Stacks._initializing && !hasPrefix) { + throw "Stacks-created Stimulus controller names must start with \"s-\"."; + } + if (!Stacks._initializing && hasPrefix) { + throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; + } + } + _super.prototype.load.call(this, definitions); }; - Controller.prototype = Object.create(StacksController.prototype, { - // This needs to be writable because Stimulus changes the constructor property - // on the controller. This shouldn't be a problem, mind you -- because right here - // were're defining the property on the *prototype*. But IE11 throws anyway. - constructor: { value: Controller, enumerable: false, writable: true } - }); - Object.setPrototypeOf(Controller, StacksController); - - var targets; - for (var prop in data) if (data.hasOwnProperty(prop)) { - if (prop === "targets") { - targets = data[prop]; - Object.defineProperty(Controller, "targets", { - get: function () { return targets; }, - enumerable: false - }); - } else { - Object.defineProperty(Controller.prototype, prop, Object.getOwnPropertyDescriptor(data, prop)); + StacksApplication.start = function (element, schema) { + var application = new StacksApplication(element, schema); + application.start(); + return application; + }; + return StacksApplication; + }(Stimulus.Application)); + Stacks.application = StacksApplication.start(); + Stacks._initializing = true; + var StacksController = (function (_super) { + __extends(StacksController, _super); + function StacksController() { + return _super !== null && _super.apply(this, arguments) || this; + } + StacksController.prototype.getElementData = function (element, key) { + return element.getAttribute("data-" + this.identifier + "-" + key); + }; + ; + StacksController.prototype.setElementData = function (element, key, value) { + element.setAttribute("data-" + this.identifier + "-" + key, value); + }; + ; + StacksController.prototype.removeElementData = function (element, key) { + element.removeAttribute("data-" + this.identifier + "-" + key); + }; + ; + StacksController.prototype.triggerEvent = function (eventName, detail, optionalElement) { + var namespacedName = this.identifier + ":" + eventName; + var event; + try { + event = new CustomEvent(namespacedName, { bubbles: true, detail: detail }); + } + catch (ex) { + event = document.createEvent("CustomEvent"); + event.initCustomEvent(namespacedName, true, true, detail); + } + (optionalElement || this.element).dispatchEvent(event); + }; + ; + return StacksController; + }(Stimulus.Controller)); + Stacks.StacksController = StacksController; + function createController(controllerDefinition) { + var _a; + var Controller = controllerDefinition.hasOwnProperty("targets") + ? (_a = (function (_super) { + __extends(Controller, _super); + function Controller() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Controller; + }(StacksController)), + _a.targets = controllerDefinition.targets, + _a) : (function (_super) { + __extends(Controller, _super); + function Controller() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Controller; + }(StacksController)); + for (var prop in controllerDefinition) { + if (prop !== "targets" && controllerDefinition.hasOwnProperty(prop)) { + Object.defineProperty(Controller.prototype, prop, Object.getOwnPropertyDescriptor(controllerDefinition, prop)); } } return Controller; } - - Stacks.addController = function addController(name, data) { - var hasPrefix = /^s-/.test(name); - if (Stacks._initializing && !hasPrefix) { - throw "Stacks-created Stimulus controller names must start with \"s-\"."; - } - if (!Stacks._initializing && hasPrefix) { - throw "The \"s-\" prefix on Stimulus controller names is reserved for Stacks-created controllers."; - } - var Controller = createController(name, data); - application.register(name, Controller); - if (Stacks._initializing) { - Stacks.controllers[name] = Controller; - } - }; -})() - + Stacks.createController = createController; + function addController(name, controller) { + Stacks.application.register(name, createController(controller)); + } + Stacks.addController = addController; + ; +})(Stacks || (Stacks = {})); +//# sourceMappingURL=stacks.js.map ; +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); (function () { - "use strict"; - - // Radio buttons only trigger a change event when they're *checked*, but not when - // they're *unchecked*. Therefore, if we have an active `s-collapsible-control` in - // the document, we listen for change events on *all* radio buttons and find any - // other radio buttons in the same `name` group, triggering a custom event on all - // of them so the controller can re-evaluate. - // - // We're keeping a count of how many of these controllers are connected to the DOM, - // so only have this global listener when we actually need it. - var RADIO_OFF_EVENT = "s-expandable-control:radio-off"; - function globalChangeListener(e) { - if (e.target.nodeName !== "INPUT" || e.target.type !== "radio") { + var target = e.target; + if (!(target instanceof HTMLInputElement) || target.nodeName !== "INPUT" || target.type !== "radio") { return; } - document.querySelectorAll('input[type="radio"][name="' + e.target.name + '"]') + document.querySelectorAll('input[type="radio"][name="' + target.name + '"]') .forEach(function (other) { - if (other === e.target) { - return; - } - var customEvent; - try { - customEvent = new Event(RADIO_OFF_EVENT); - } catch (ex) { - // Internet Explorer - customEvent = document.createEvent("Event"); - customEvent.initEvent(RADIO_OFF_EVENT, true, true); - } - other.dispatchEvent(customEvent); - }); + if (other === e.target) { + return; + } + var customEvent; + try { + customEvent = new Event(RADIO_OFF_EVENT); + } + catch (ex) { + customEvent = document.createEvent("Event"); + customEvent.initEvent(RADIO_OFF_EVENT, true, true); + } + other.dispatchEvent(customEvent); + }); } - var refCount = 0; function globalChangeListenerRequired(required) { if (required) { @@ -4497,65 +4533,82 @@ return Popper; if (refCount === 1) { document.body.addEventListener("change", globalChangeListener); } - } else { + } + else { refCount--; if (refCount === 0) { document.body.removeEventListener("change", globalChangeListener); } } } - - - Stacks.addController("s-expandable-control", { - - initialize: function () { + Stacks.application.register("s-expandable-control", (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.initialize = function () { if (this.element.nodeName === "INPUT" && ["radio", "checkbox"].indexOf(this.element.type) >= 0) { this.isCollapsed = this._isCollapsedForCheckable; this.events = ["change", RADIO_OFF_EVENT]; this.isCheckable = true; this.isRadio = this.element.type === "radio"; - } else { + } + else { this.isCollapsed = this._isCollapsedForClickable; this.events = ["click", "keydown"]; } this.listener = this.listener.bind(this); - }, - - // for non-checkable elements, the initial source of truth is the collapsed/expanded - // state of the controlled element (unless the element doesn't exist) - _isCollapsedForClickable: function () { + }; + ; + class_1.prototype._isCollapsedForClickable = function () { var cc = this.controlledCollapsible; return cc ? !cc.classList.contains("is-expanded") : this.element.getAttribute("aria-expanded") === "false"; - }, - - // for checkable elements, the initial source of truth is the checked state - _isCollapsedForCheckable: function () { + }; + ; + class_1.prototype._isCollapsedForCheckable = function () { return !this.element.checked; - }, - - get controlledCollapsible() { - return document.getElementById(this.element.getAttribute("aria-controls")); - }, - - _dispatchShowHideEvent: function(isShow) { + }; + ; + Object.defineProperty(class_1.prototype, "controlledCollapsible", { + get: function () { + var attr = this.element.getAttribute("aria-controls"); + if (!attr) { + throw "couldn't find controls"; + } + var result = document.getElementById(attr); + if (!result) { + throw "couldn't find controls"; + } + return result; + }, + enumerable: true, + configurable: true + }); + ; + class_1.prototype._dispatchShowHideEvent = function (isShow) { this.triggerEvent(isShow ? "show" : "hide"); - }, - - _toggleClass: function(doAdd) { + }; + ; + class_1.prototype._toggleClass = function (doAdd) { if (!this.data.has("toggle-class")) { return; } var cl = this.element.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { + var toggleClass = this.data.get("toggle-class"); + if (!toggleClass) { + throw "couldn't find toggle class"; + } + toggleClass.split(/\s+/).forEach(function (cls) { cl.toggle(cls, !!doAdd); }); - }, - - listener: function(e) { + }; + ; + class_1.prototype.listener = function (e) { var newCollapsed; if (this.isCheckable) { newCollapsed = !this.element.checked; - } else { + } + else { if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { return; } @@ -4572,19 +4625,16 @@ return Popper; this.controlledCollapsible.classList.toggle("is-expanded", !newCollapsed); this._dispatchShowHideEvent(!newCollapsed); this._toggleClass(!newCollapsed); - }, - - connect: function () { + }; + ; + class_1.prototype.connect = function () { + var _this = this; this.events.forEach(function (e) { - this.element.addEventListener(e, this.listener); + _this.element.addEventListener(e, _this.listener); }, this); - if (this.isRadio) { globalChangeListenerRequired(true); } - - // synchronize state -- in all cases, this means setting the correct `aria-expanded` - // attribute; for checkable controls this also means setting the `is-collapsed` class this.element.setAttribute("aria-expanded", this.isCollapsed() ? "false" : "true"); if (this.isCheckable) { var cc = this.controlledCollapsible; @@ -4598,349 +4648,165 @@ return Popper; } } } - }, - - disconnect: function () { + }; + ; + class_1.prototype.disconnect = function () { + var _this = this; this.events.forEach(function (e) { - this.element.removeEventListener(e, this.listener); + _this.element.removeEventListener(e, _this.listener); }, this); - if (this.isRadio) { globalChangeListenerRequired(false); } - } - - }); + }; + ; + return class_1; + }(Stacks.StacksController))); })(); - +//# sourceMappingURL=s-expandable-control.js.map ; -(function () { - "use strict"; - Stacks.addController("s-popover", { - targets: [], - - /** - * Initializes popper.js and document events on controller connect - */ - connect: function() { - var referenceSelector = this.data.get("reference-selector"); - - // if there is an alternative reference selector and that element exists, use it (otherwise use this element) - this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; - - var popoverId = this.referenceElement.getAttribute("aria-controls"); - - if (!popoverId) { - throw "[aria-controls=\"{POPOVER_ID}\"] required"; - } - - this.popoverElement = document.getElementById(popoverId); - - this.popper = new Popper(this.referenceElement, this.popoverElement, { - placement: this.data.get("placement") || "bottom", - }); - - // toggle classes based on if the popover is already visible - this._toggleOptionalClasses(this.popoverElement.classList.contains("is-visible")); - }, - - /** - * Cleans up popper.js elements and disconnects all added event listeners on controller disconnect - */ - disconnect: function() { - this.popper.destroy(); - this._unbindDocumentEvents(); - }, - - /** - * Toggles the visibility of the popover when called as a Stimulus action - * @param {Event} event - The event object from the Stimulus action call - */ - toggle: function(event) { - this._toggle(); - }, - - /** - * Shows the popover - */ - show: function() { - this._toggle(true); - }, - - /** - * Hides the popover - */ - hide: function() { - this._toggle(false); - }, - - /** - * Toggles the visibility of the popover element - * @param {boolean=} show - Optional parameter that force shows/hides the element or toggles it if left undefined - */ - _toggle: function(show) { - var toShow = show; - - // if we're letting the class toggle, we need to figure out if the popover is visible manually - if (typeof toShow === "undefined") { - toShow = !this.popoverElement.classList.contains("is-visible"); - } - - // show/hide events trigger before toggling the class - this.triggerEvent(toShow ? "show" : "hide"); - - this.popper.update(); - this.popoverElement.classList.toggle("is-visible", show); - this._toggleOptionalClasses(show); - - if (this.popoverElement.classList.contains("is-visible")) { - this._bindDocumentEvents(); - } - else { - this._unbindDocumentEvents(); - } - - // shown/hidden events trigger after toggling the class - this.triggerEvent(toShow ? "shown" : "hidden"); - }, - - /** - * Binds global events to the document for hiding popovers on user interaction - */ - _bindDocumentEvents: function() { - // in order for removeEventListener to remove the right event, this bound function needs a constant reference - this._boundClickFn = this._boundClickFn || this._hideOnOutsideClick.bind(this); - this._boundKeypressFn = this._boundKeypressFn || this._hideOnEscapePress.bind(this); - - document.addEventListener("click", this._boundClickFn); - document.addEventListener("keyup", this._boundKeypressFn); - }, - - /** - * Unbinds global events to the document for hiding popovers on user interaction - */ - _unbindDocumentEvents: function() { - document.removeEventListener("click", this._boundClickFn); - document.removeEventListener("keyup", this._boundKeypressFn); - }, - - /** - * Forces the popover to hide if a user clicks outside of it or its reference element - * @param {Event} e - The document click event - */ - _hideOnOutsideClick: function(e) { - // check if the document was clicked inside either the reference element or the popover itself - // note: .contains also returns true if the node itself matches the target element - if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { - this.hide(); - } - }, - - /** - * Forces the popover to hide if the user presses escape while it, one of its childen, or the reference element are focused - * @param {Event} e - The document keyup event - */ - _hideOnEscapePress: function(e) { - // if the ESC key (27) wasn't pressed or if no popovers are showing, return - if (e.which !== 27 || !this.popoverElement.classList.contains("is-visible")) { - return; - } - - // check if the target was inside the popover element and refocus the triggering element - // note: .contains also returns true if the node itself matches the target element - if (this.popoverElement.contains(e.target)) { - this.referenceElement.focus(); - } - - this.hide(); - }, - - /** - * Toggles all classes on the originating element based on the `class-toggle` data - * @param {boolean=} show - Optional parameter that force shows/hides the classes or toggles them if left undefined - */ - _toggleOptionalClasses: function(show) { - if (!this.data.has("toggle-class")) { - return; - } - var cl = this.referenceElement.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { - cl.toggle(cls, show); - }); - } - }); +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; })(); - - -; - (function () { - "use strict"; - Stacks.addController("s-table", { - - targets: ["column"], - - setCurrentSort: function (headElem, direction) { - if (["asc", "desc", "none"].indexOf(direction) < 0) { - throw "direction must be one of asc, desc, or none" + var _a; + Stacks.application.register("s-table", (_a = (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; } - var controller = this; - this.columnTargets.forEach(function (target) { - var isCurrrent = target === headElem; - - target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); - - target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { - var visible = isCurrrent ? direction : "none"; - icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); - }); - - if (!isCurrrent || direction === "none") { - controller.removeElementData(target, "sort-direction"); - } else { - controller.setElementData(target, "sort-direction", direction); + class_1.prototype.setCurrentSort = function (headElem, direction) { + if (["asc", "desc", "none"].indexOf(direction) < 0) { + throw "direction must be one of asc, desc, or none"; } - }); - }, - - sort: function (evt) { - var controller = this; - var colHead = evt.currentTarget; - var table = this.element; - var tbody = table.tBodies[0]; - - // the column slot number of the clicked header - var colno = getCellSlot(colHead); - - if (colno < 0) { // this shouldn't happen if the clicked element is actually a column head - return; - } - - // an index of the , so we can find out for each row which element is - // in the same column slot as the header - var slotIndex = buildIndex(tbody); - - // the default behavior when clicking a header is to sort by this column in ascending - // direction, *unless* it is already sorted that way - var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; - - var rows = Array.from(table.tBodies[0].rows); - - // if this is still false after traversing the data, that means all values are integers (or empty) - // and thus we'll sort numerically. - var anyNonInt = false; - - // data will be a list of tuples [value, rowNum], where value is what we're sorting by - var data = []; - var firstBottomRow; - rows.forEach(function (row, index) { - var force = controller.getElementData(row, "sort-to"); - if (force === "top") { - return; // rows not added to the list will automatically end up at the top - } else if (force === "bottom") { - if (!firstBottomRow) { - firstBottomRow = row; + var controller = this; + this.columnTargets.forEach(function (target) { + var isCurrrent = target === headElem; + target.classList.toggle("is-sorted", isCurrrent && direction !== "none"); + target.querySelectorAll(".js-sorting-indicator").forEach(function (icon) { + var visible = isCurrrent ? direction : "none"; + icon.classList.toggle("d-none", !icon.classList.contains("js-sorting-indicator-" + visible)); + }); + if (!isCurrrent || direction === "none") { + controller.removeElementData(target, "sort-direction"); } - return; + else { + controller.setElementData(target, "sort-direction", direction); + } + }); + }; + ; + class_1.prototype.sort = function (evt) { + var controller = this; + var colHead = evt.currentTarget; + if (!(colHead instanceof HTMLTableCellElement)) { + throw "invalid event target"; } - var cell = slotIndex[index][colno]; - if (!cell) { - data.push(["", index]); + var table = this.element; + var tbody = table.tBodies[0]; + var colno = getCellSlot(colHead); + if (colno < 0) { return; } - - // unless the to-be-sorted-by value is explicitly provided on the element via this attribute, - // the value we're using is the cell's text, trimmed of any whitespace - var explicit = controller.getElementData(cell, "sort-val"); - var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); - - if ((d !== "") && (parseInt(d, 10) + "" !== d)) { - anyNonInt = true; - } - data.push([d, index]); - }); - - // If all values were integers (or empty cells), sort numerically, with empty cells treated as - // having the lowest possible value (i.e. sorted to the top if ascending, bottom if descending) - if (!anyNonInt) { - data.forEach(function (tuple) { - tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); + var slotIndex = buildIndex(tbody); + var direction = this.getElementData(colHead, "sort-direction") === "asc" ? -1 : 1; + var rows = Array.from(table.tBodies[0].rows); + var anyNonInt = false; + var data = []; + var firstBottomRow; + rows.forEach(function (row, index) { + var force = controller.getElementData(row, "sort-to"); + if (force === "top") { + return; + } + else if (force === "bottom") { + if (!firstBottomRow) { + firstBottomRow = row; + } + return; + } + var cell = slotIndex[index][colno]; + if (!cell) { + data.push(["", index]); + return; + } + var explicit = controller.getElementData(cell, "sort-val"); + var d = typeof explicit === "string" ? explicit : cell.textContent.trim(); + if ((d !== "") && (parseInt(d, 10) + "" !== d)) { + anyNonInt = true; + } + data.push([d, index]); }); - } - - // We don't sort an array of , but instead an arrays of row *numbers*, because this way we - // can enforce stable sorting, i.e. rows that compare equal are guaranteed to remain in the same - // order (the JS standard does not gurantee this for sort()). - data.sort(function (a, b) { - // first compare the values (a[0]) - if (a[0] > b[0]) { - return 1 * direction; - } else if (a[0] < b[0]) { - return -1 * direction; - } else { - // if the values are equal, compare the row numbers (a[1]) to guarantee stable sorting - // (note that this comparison is independent of the sorting direction) - return a[1] > b[1] ? 1 : -1; + if (!anyNonInt) { + data.forEach(function (tuple) { + tuple[0] = tuple[0] === "" ? Number.MIN_VALUE : parseInt(tuple[0], 10); + }); } - }); - - // this is the actual reordering of the table rows - data.forEach(function (tup) { - var row = rows[tup[1]]; - row.parentElement.removeChild(row); - if (firstBottomRow) { - tbody.insertBefore(row, firstBottomRow); - } else { - tbody.appendChild(row); - } - }); - - // update the UI and set the `data-sort-direction` attribute if appropriate, so that the next click - // will cause sorting in descending direction - this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); - } - }); - + data.sort(function (a, b) { + if (a[0] > b[0]) { + return 1 * direction; + } + else if (a[0] < b[0]) { + return -1 * direction; + } + else { + return a[1] > b[1] ? 1 : -1; + } + }); + data.forEach(function (tup) { + var row = rows[tup[1]]; + row.parentElement.removeChild(row); + if (firstBottomRow) { + tbody.insertBefore(row, firstBottomRow); + } + else { + tbody.appendChild(row); + } + }); + this.setCurrentSort(colHead, direction === 1 ? "asc" : "desc"); + }; + return class_1; + }(Stacks.StacksController)), + _a.targets = ["column"], + _a)); function buildIndex(section) { - return buildIndexOrGetCellSlot(section); + var result = buildIndexOrGetCellSlot(section); + if (!(result instanceof Array)) { + throw "shouldn't happen"; + } + return result; } - function getCellSlot(cell) { - return buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (!(cell.parentElement && cell.parentElement.parentElement instanceof HTMLTableSectionElement)) { + throw "invalid table"; + } + var result = buildIndexOrGetCellSlot(cell.parentElement.parentElement, cell); + if (typeof result !== "number") { + throw "shouldn't happen"; + } + return result; } - - // Just because a is the 4th *child* of its doesn't mean it belongs to the 4th *column* - // of the table. Previous cells may have a colspan; cells in previous rows may have a rowspan. - // Because we need to know which header cells and data cells belong together, we have to 1) find out - // which column number (or "slot" as we call it here) the header cell has, and 2) for each row find - // out which cell corresponds to this slot (because those are the rows we're sorting by). - // - // That's what the following function does. If the second argument is not given, it returns an index - // of the table, which is an array of arrays. Each of the sub-arrays corresponds to a table row. The - // indices of the sub-array correspond to column slots; the values are the actual table cell elements. - // For example index[4][3] is the or in row 4, column 3 of the table section ( or ). - // Note that this element is not necessarily even in the 4th (zero-based) -- if it has a rowSpan > 1, - // it may also be in a previous . - // - // If the second argument is given, it's a or that we're trying to find, and the algorithm - // stops as soon as it has found it and the function returns its slot number. function buildIndexOrGetCellSlot(section, findCell) { var index = []; var curRow = section.children[0]; - - // the elements of these two arrays are synchronized; the first array contains table cell elements, - // the second one contains a number that indicates for how many more rows this elements will - // exist (i.e. the value is initially one less than the cell's rowspan, and will be decreased for each row) var growing = []; var growingRowsLeft = []; - - // continue while we have actual 's left *or* we still have rowspan'ed elements that aren't done - while (curRow || growingRowsLeft.some(function (e) { return e; })) { + while (curRow || growingRowsLeft.some(function (e) { return e !== 0; })) { var curIndexRow = []; index.push(curIndexRow); - var curSlot = 0; if (curRow) { for (var curCellInd = 0; curCellInd < curRow.children.length; curCellInd++) { @@ -4950,6 +4816,9 @@ return Popper; curSlot++; } var cell = curRow.children[curCellInd]; + if (!(cell instanceof HTMLTableCellElement)) { + throw "invalid table"; + } if (getComputedStyle(cell).display === "none") { continue; } @@ -4958,7 +4827,7 @@ return Popper; } var nextFreeSlot = curSlot + cell.colSpan; for (; curSlot < nextFreeSlot; curSlot++) { - growingRowsLeft[curSlot] = cell.rowSpan - 1; // if any of these is already growing, the table is broken -- no guarantees of anything + growingRowsLeft[curSlot] = cell.rowSpan - 1; growing[curSlot] = cell; curIndexRow[curSlot] = cell; } @@ -4971,18 +4840,17 @@ return Popper; } curSlot++; } - if (curRow) { + if (curRow && curRow.nextElementSibling) { curRow = curRow.nextElementSibling; } } - return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ + return findCell ? -1 : index; } - })(); - +//# sourceMappingURL=s-table.js.map ; -(function () { - delete Stacks._initializing; -})(); +"use strict"; +Stacks._initializing = false; +//# sourceMappingURL=finalize.js.map \ No newline at end of file diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index f70a0927bf..83af4e5aa6 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=N({},l,f[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!W(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",f=l.toLowerCase(),p=c?"left":"top",h=c?"bottom":"right",d=C(r)[u];a[h]-ds[h]&&(e.offsets.popper[f]+=a[f]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[f]+a[u]/2-d/2,g=E(e.instance.popper),y=parseFloat(g["margin"+l],10),b=parseFloat(g["border"+l+"Width"],10),v=m-e.offsets.popper[f]-y-b;return v=Math.max(Math.min(s[u]-d,v),0),e.arrowElement=r,e.offsets.arrow=(w(n={},f,Math.round(v)),w(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(g,y){if(T(g.instance.modifiers,"inner"))return g;if(g.flipped&&g.placement===g.originalPlacement)return g;var b=p(g.instance.popper,g.instance.reference,y.padding,y.boundariesElement,g.positionFixed),v=g.placement.split("-")[0],E=P(v),w=g.placement.split("-")[1]||"",O=[];switch(y.behavior){case q:O=[v,E];break;case Y:O=z(v);break;case G:O=z(v,!0);break;default:O=y.behavior}return O.forEach(function(e,t){if(v!==e||O.length===t+1)return g;v=g.placement.split("-")[0],E=P(v);var n,r=g.offsets.popper,o=g.offsets.reference,i=Math.floor,s="left"===v&&i(r.right)>i(o.left)||"right"===v&&i(r.left)i(o.top)||"bottom"===v&&i(r.top)i(b.right),u=i(r.top)i(b.bottom),f="left"===v&&a||"right"===v&&c||"top"===v&&u||"bottom"===v&&l,p=-1!==["top","bottom"].indexOf(v),h=!!y.flipVariations&&(p&&"start"===w&&a||p&&"end"===w&&c||!p&&"start"===w&&u||!p&&"end"===w&&l),d=!!y.flipVariationsByContent&&(p&&"start"===w&&c||p&&"end"===w&&a||!p&&"start"===w&&l||!p&&"end"===w&&u),m=h||d;(s||f||m)&&(g.flipped=!0,(s||f)&&(v=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),g.placement=v+(w?"-"+w:""),g.offsets.popper=N({},g.offsets.popper,B(g.instance.popper,g.offsets.reference,g.placement)),g=L(g.instance.modifiers,g,"flip"))}),g},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=P(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!W(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=_(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*i:e[0]t[1]?1:-1}),p.forEach(function(e){var t=l[e[1]];t.parentElement.removeChild(t),c?o.insertBefore(t,c):o.appendChild(t)}),this.setCurrentSort(n,1===i?"asc":"desc")}}})}(),delete Stacks._initializing; +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),f=0c[e]&&!r.escapeWithReference&&(n=Math.min(f[t],c[e]-("right"===e?f.width:f.height))),E({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";f=M({},f,l[t](e))}),e.offsets.popper=f,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",f=c?"Top":"Left",l=f.toLowerCase(),p=c?"left":"top",h=c?"bottom":"right",d=C(r)[u];a[h]-ds[h]&&(e.offsets.popper[l]+=a[l]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[l]+a[u]/2-d/2,y=w(e.instance.popper),g=parseFloat(y["margin"+f],10),b=parseFloat(y["border"+f+"Width"],10),v=m-e.offsets.popper[l]-g-b;return v=Math.max(Math.min(s[u]-d,v),0),e.arrowElement=r,e.offsets.arrow=(E(n={},l,Math.round(v)),E(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(j(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var b=p(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),v=y.placement.split("-")[0],w=P(v),E=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[v,w];break;case Y:O=z(v);break;case G:O=z(v,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(v!==e||O.length===t+1)return y;v=y.placement.split("-")[0],w=P(v);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===v&&i(r.right)>i(o.left)||"right"===v&&i(r.left)i(o.top)||"bottom"===v&&i(r.top)i(b.right),u=i(r.top)i(b.bottom),l="left"===v&&a||"right"===v&&c||"top"===v&&u||"bottom"===v&&f,p=-1!==["top","bottom"].indexOf(v),h=!!g.flipVariations&&(p&&"start"===E&&a||p&&"end"===E&&c||!p&&"start"===E&&u||!p&&"end"===E&&f),d=!!g.flipVariationsByContent&&(p&&"start"===E&&c||p&&"end"===E&&a||!p&&"start"===E&&f||!p&&"end"===E&&u),m=h||d;(s||l||m)&&(y.flipped=!0,(s||l)&&(v=O[t+1]),m&&(E="end"===(n=E)?"start":"start"===n?"end":n),y.placement=v+(E?"-"+E:""),y.offsets.popper=M({},y.offsets.popper,T(y.instance.popper,y.offsets.reference,y.placement)),y=B(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=P(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=_(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),l.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From 66daef4237c245e70afccc616c643722abf2942f Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 18 Jul 2019 15:37:42 -0400 Subject: [PATCH 13/26] ensure all js files migrated to ts are up to date --- lib/ts/stacks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ts/stacks.ts b/lib/ts/stacks.ts index bc128a9ff7..1fb59eb6ef 100644 --- a/lib/ts/stacks.ts +++ b/lib/ts/stacks.ts @@ -49,6 +49,7 @@ namespace Stacks { event.initCustomEvent(namespacedName, true, true, detail!); } (optionalElement || this.element).dispatchEvent(event); + return event; }; } From 9e84ae064ed5fbf64bafdc4f6c785403f22d36aa Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 18 Jul 2019 15:37:49 -0400 Subject: [PATCH 14/26] commit built files --- dist/js/stacks.js | 1 + dist/js/stacks.min.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index df7b8986e4..8f15bb0c1f 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4448,6 +4448,7 @@ var Stacks; event.initCustomEvent(namespacedName, true, true, detail); } (optionalElement || this.element).dispatchEvent(event); + return event; }; ; return StacksController; diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index 83af4e5aa6..a894a19aae 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),f=0c[e]&&!r.escapeWithReference&&(n=Math.min(f[t],c[e]-("right"===e?f.width:f.height))),E({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";f=M({},f,l[t](e))}),e.offsets.popper=f,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",f=c?"Top":"Left",l=f.toLowerCase(),p=c?"left":"top",h=c?"bottom":"right",d=C(r)[u];a[h]-ds[h]&&(e.offsets.popper[l]+=a[l]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[l]+a[u]/2-d/2,y=w(e.instance.popper),g=parseFloat(y["margin"+f],10),b=parseFloat(y["border"+f+"Width"],10),v=m-e.offsets.popper[l]-g-b;return v=Math.max(Math.min(s[u]-d,v),0),e.arrowElement=r,e.offsets.arrow=(E(n={},l,Math.round(v)),E(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(j(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var b=p(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),v=y.placement.split("-")[0],w=P(v),E=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[v,w];break;case Y:O=z(v);break;case G:O=z(v,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(v!==e||O.length===t+1)return y;v=y.placement.split("-")[0],w=P(v);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===v&&i(r.right)>i(o.left)||"right"===v&&i(r.left)i(o.top)||"bottom"===v&&i(r.top)i(b.right),u=i(r.top)i(b.bottom),l="left"===v&&a||"right"===v&&c||"top"===v&&u||"bottom"===v&&f,p=-1!==["top","bottom"].indexOf(v),h=!!g.flipVariations&&(p&&"start"===E&&a||p&&"end"===E&&c||!p&&"start"===E&&u||!p&&"end"===E&&f),d=!!g.flipVariationsByContent&&(p&&"start"===E&&c||p&&"end"===E&&a||!p&&"start"===E&&f||!p&&"end"===E&&u),m=h||d;(s||l||m)&&(y.flipped=!0,(s||l)&&(v=O[t+1]),m&&(E="end"===(n=E)?"start":"start"===n?"end":n),y.placement=v+(E?"-"+E:""),y.offsets.popper=M({},y.offsets.popper,T(y.instance.popper,y.offsets.reference,y.placement)),y=B(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=P(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=_(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),l.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),f=0c[e]&&!r.escapeWithReference&&(n=Math.min(f[t],c[e]-("right"===e?f.width:f.height))),E({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";f=M({},f,l[t](e))}),e.offsets.popper=f,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",f=c?"Top":"Left",l=f.toLowerCase(),p=c?"left":"top",h=c?"bottom":"right",d=C(r)[u];a[h]-ds[h]&&(e.offsets.popper[l]+=a[l]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[l]+a[u]/2-d/2,y=w(e.instance.popper),g=parseFloat(y["margin"+f],10),b=parseFloat(y["border"+f+"Width"],10),v=m-e.offsets.popper[l]-g-b;return v=Math.max(Math.min(s[u]-d,v),0),e.arrowElement=r,e.offsets.arrow=(E(n={},l,Math.round(v)),E(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(j(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var b=p(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),v=y.placement.split("-")[0],w=P(v),E=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[v,w];break;case Y:O=z(v);break;case G:O=z(v,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(v!==e||O.length===t+1)return y;v=y.placement.split("-")[0],w=P(v);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===v&&i(r.right)>i(o.left)||"right"===v&&i(r.left)i(o.top)||"bottom"===v&&i(r.top)i(b.right),u=i(r.top)i(b.bottom),l="left"===v&&a||"right"===v&&c||"top"===v&&u||"bottom"===v&&f,p=-1!==["top","bottom"].indexOf(v),h=!!g.flipVariations&&(p&&"start"===E&&a||p&&"end"===E&&c||!p&&"start"===E&&u||!p&&"end"===E&&f),d=!!g.flipVariationsByContent&&(p&&"start"===E&&c||p&&"end"===E&&a||!p&&"start"===E&&f||!p&&"end"===E&&u),m=h||d;(s||l||m)&&(y.flipped=!0,(s||l)&&(v=O[t+1]),m&&(E="end"===(n=E)?"start":"start"===n?"end":n),y.placement=v+(E?"-"+E:""),y.offsets.popper=M({},y.offsets.popper,T(y.instance.popper,y.offsets.reference,y.placement)),y=B(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=P(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=_(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),l.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From 9322977b603f378d7becf825f0e0ba18d965e687 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 18 Jul 2019 17:11:48 -0400 Subject: [PATCH 15/26] add s-popover.ts --- .../controllers/s-popover.ts} | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) rename lib/{js/controllers/s-popover.js => ts/controllers/s-popover.ts} (77%) diff --git a/lib/js/controllers/s-popover.js b/lib/ts/controllers/s-popover.ts similarity index 77% rename from lib/js/controllers/s-popover.js rename to lib/ts/controllers/s-popover.ts index 022f6691dd..ce877e1702 100644 --- a/lib/js/controllers/s-popover.js +++ b/lib/ts/controllers/s-popover.ts @@ -1,16 +1,26 @@ + + (function () { "use strict"; - Stacks.addController("s-popover", { - targets: [], - + Stacks.application.register("s-popover", class extends Stacks.StacksController { + static targets: []; + + private referenceElement!: HTMLElement; + private popoverElement!: HTMLElement; + // @ts-ignore + private popper!: Popper; + + private _boundClickFn!: any; + private _boundKeypressFn!: any; + /** * Initializes popper.js and document events on controller connect */ - connect: function() { + connect() { var referenceSelector = this.data.get("reference-selector"); // if there is an alternative reference selector and that element exists, use it (otherwise use this element) - this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; + this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; var popoverId = this.referenceElement.getAttribute("aria-controls"); @@ -18,51 +28,59 @@ throw "[aria-controls=\"{POPOVER_ID}\"] required"; } - this.popoverElement = document.getElementById(popoverId); + var element = document.getElementById(popoverId); + + if (!element) { + throw "element with popover id not found"; + } + + this.popoverElement = element; + // @ts-ignore this.popper = new Popper(this.referenceElement, this.popoverElement, { - placement: this.data.get("placement") || "bottom", + // @ts-ignore + placement: this.data.get("placement") as Popper.Placement || "bottom", }); // toggle classes based on if the popover is already visible this._toggleOptionalClasses(this.popoverElement.classList.contains("is-visible")); - }, + }; /** * Cleans up popper.js elements and disconnects all added event listeners on controller disconnect */ - disconnect: function() { + disconnect() { this.popper.destroy(); this._unbindDocumentEvents(); - }, + }; /** * Toggles the visibility of the popover when called as a Stimulus action * @param {Event} event - The event object from the Stimulus action call */ - toggle: function(event) { + toggle() { this._toggle(); - }, + }; /** * Shows the popover */ - show: function() { + show() { this._toggle(true); - }, + }; /** * Hides the popover */ - hide: function() { + hide() { this._toggle(false); - }, + }; /** * Toggles the visibility of the popover element * @param {boolean=} show - Optional parameter that force shows/hides the element or toggles it if left undefined */ - _toggle: function(show) { + _toggle(show?: boolean) { var toShow = show; // if we're letting the class toggle, we need to figure out if the popover is visible manually @@ -86,45 +104,45 @@ // shown/hidden events trigger after toggling the class this.triggerEvent(toShow ? "shown" : "hidden"); - }, + }; /** * Binds global events to the document for hiding popovers on user interaction */ - _bindDocumentEvents: function() { + _bindDocumentEvents() { // in order for removeEventListener to remove the right event, this bound function needs a constant reference this._boundClickFn = this._boundClickFn || this._hideOnOutsideClick.bind(this); this._boundKeypressFn = this._boundKeypressFn || this._hideOnEscapePress.bind(this); document.addEventListener("click", this._boundClickFn); document.addEventListener("keyup", this._boundKeypressFn); - }, + }; /** * Unbinds global events to the document for hiding popovers on user interaction */ - _unbindDocumentEvents: function() { + _unbindDocumentEvents() { document.removeEventListener("click", this._boundClickFn); document.removeEventListener("keyup", this._boundKeypressFn); - }, + }; /** * Forces the popover to hide if a user clicks outside of it or its reference element * @param {Event} e - The document click event */ - _hideOnOutsideClick: function(e) { + _hideOnOutsideClick(e: MouseEvent) { // check if the document was clicked inside either the reference element or the popover itself // note: .contains also returns true if the node itself matches the target element - if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { + if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { this.hide(); } - }, + }; /** * Forces the popover to hide if the user presses escape while it, one of its childen, or the reference element are focused * @param {Event} e - The document keyup event */ - _hideOnEscapePress: function(e) { + _hideOnEscapePress(e: KeyboardEvent) { // if the ESC key (27) wasn't pressed or if no popovers are showing, return if (e.which !== 27 || !this.popoverElement.classList.contains("is-visible")) { return; @@ -132,23 +150,23 @@ // check if the target was inside the popover element and refocus the triggering element // note: .contains also returns true if the node itself matches the target element - if (this.popoverElement.contains(e.target)) { + if (this.popoverElement.contains(e.target)) { this.referenceElement.focus(); } this.hide(); - }, + }; /** * Toggles all classes on the originating element based on the `class-toggle` data * @param {boolean=} show - Optional parameter that force shows/hides the classes or toggles them if left undefined */ - _toggleOptionalClasses: function(show) { + _toggleOptionalClasses(show?: boolean) { if (!this.data.has("toggle-class")) { return; } var cl = this.referenceElement.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { + this.data.get("toggle-class")!.split(/\s+/).forEach(function (cls: string) { cl.toggle(cls, show); }); } From d2e4775f60e1253b2cbd56b4a1d3c53d5ad415bb Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 18 Jul 2019 17:11:56 -0400 Subject: [PATCH 16/26] commit compiled files --- dist/js/stacks.js | 118 ++++++++++++++++++++++++++++++++++++++++++ dist/js/stacks.min.js | 2 +- 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 8f15bb0c1f..c920a21b14 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4668,6 +4668,124 @@ var __extends = (this && this.__extends) || (function () { ; +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +(function () { + "use strict"; + Stacks.application.register("s-popover", (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.connect = function () { + var referenceSelector = this.data.get("reference-selector"); + this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; + var popoverId = this.referenceElement.getAttribute("aria-controls"); + if (!popoverId) { + throw "[aria-controls=\"{POPOVER_ID}\"] required"; + } + var element = document.getElementById(popoverId); + if (!element) { + throw "element with popover id not found"; + } + this.popoverElement = element; + this.popper = new Popper(this.referenceElement, this.popoverElement, { + placement: this.data.get("placement") || "bottom", + }); + this._toggleOptionalClasses(this.popoverElement.classList.contains("is-visible")); + }; + ; + class_1.prototype.disconnect = function () { + this.popper.destroy(); + this._unbindDocumentEvents(); + }; + ; + class_1.prototype.toggle = function () { + this._toggle(); + }; + ; + class_1.prototype.show = function () { + this._toggle(true); + }; + ; + class_1.prototype.hide = function () { + this._toggle(false); + }; + ; + class_1.prototype._toggle = function (show) { + var toShow = show; + if (typeof toShow === "undefined") { + toShow = !this.popoverElement.classList.contains("is-visible"); + } + this.triggerEvent(toShow ? "show" : "hide"); + this.popper.update(); + this.popoverElement.classList.toggle("is-visible", show); + this._toggleOptionalClasses(show); + if (this.popoverElement.classList.contains("is-visible")) { + this._bindDocumentEvents(); + } + else { + this._unbindDocumentEvents(); + } + this.triggerEvent(toShow ? "shown" : "hidden"); + }; + ; + class_1.prototype._bindDocumentEvents = function () { + this._boundClickFn = this._boundClickFn || this._hideOnOutsideClick.bind(this); + this._boundKeypressFn = this._boundKeypressFn || this._hideOnEscapePress.bind(this); + document.addEventListener("click", this._boundClickFn); + document.addEventListener("keyup", this._boundKeypressFn); + }; + ; + class_1.prototype._unbindDocumentEvents = function () { + document.removeEventListener("click", this._boundClickFn); + document.removeEventListener("keyup", this._boundKeypressFn); + }; + ; + class_1.prototype._hideOnOutsideClick = function (e) { + if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { + this.hide(); + } + }; + ; + class_1.prototype._hideOnEscapePress = function (e) { + if (e.which !== 27 || !this.popoverElement.classList.contains("is-visible")) { + return; + } + if (this.popoverElement.contains(e.target)) { + this.referenceElement.focus(); + } + this.hide(); + }; + ; + class_1.prototype._toggleOptionalClasses = function (show) { + if (!this.data.has("toggle-class")) { + return; + } + var cl = this.referenceElement.classList; + this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { + cl.toggle(cls, show); + }); + }; + return class_1; + }(Stacks.StacksController))); +})(); +//# sourceMappingURL=s-popover.js.map + +; + "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index a894a19aae..3272ffa265 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),f=0c[e]&&!r.escapeWithReference&&(n=Math.min(f[t],c[e]-("right"===e?f.width:f.height))),E({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";f=M({},f,l[t](e))}),e.offsets.popper=f,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",f=c?"Top":"Left",l=f.toLowerCase(),p=c?"left":"top",h=c?"bottom":"right",d=C(r)[u];a[h]-ds[h]&&(e.offsets.popper[l]+=a[l]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[l]+a[u]/2-d/2,y=w(e.instance.popper),g=parseFloat(y["margin"+f],10),b=parseFloat(y["border"+f+"Width"],10),v=m-e.offsets.popper[l]-g-b;return v=Math.max(Math.min(s[u]-d,v),0),e.arrowElement=r,e.offsets.arrow=(E(n={},l,Math.round(v)),E(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(j(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var b=p(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),v=y.placement.split("-")[0],w=P(v),E=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[v,w];break;case Y:O=z(v);break;case G:O=z(v,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(v!==e||O.length===t+1)return y;v=y.placement.split("-")[0],w=P(v);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===v&&i(r.right)>i(o.left)||"right"===v&&i(r.left)i(o.top)||"bottom"===v&&i(r.top)i(b.right),u=i(r.top)i(b.bottom),l="left"===v&&a||"right"===v&&c||"top"===v&&u||"bottom"===v&&f,p=-1!==["top","bottom"].indexOf(v),h=!!g.flipVariations&&(p&&"start"===E&&a||p&&"end"===E&&c||!p&&"start"===E&&u||!p&&"end"===E&&f),d=!!g.flipVariationsByContent&&(p&&"start"===E&&c||p&&"end"===E&&a||!p&&"start"===E&&f||!p&&"end"===E&&u),m=h||d;(s||l||m)&&(y.flipped=!0,(s||l)&&(v=O[t+1]),m&&(E="end"===(n=E)?"start":"start"===n?"end":n),y.placement=v+(E?"-"+E:""),y.offsets.popper=M({},y.offsets.popper,T(y.instance.popper,y.offsets.reference,y.placement)),y=B(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=P(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=_(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),l.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=F({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=F({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From fd311b664fb53f09841d053460bbf44d5f49f263 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 23 Jul 2019 13:06:24 -0400 Subject: [PATCH 17/26] remove empty stacks.js --- lib/js/stacks.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/js/stacks.js diff --git a/lib/js/stacks.js b/lib/js/stacks.js deleted file mode 100644 index e69de29bb2..0000000000 From 41c67e0dc88a759f95d5907996ac706b7e3b4ae4 Mon Sep 17 00:00:00 2001 From: Benjamin Hodgson Date: Wed, 24 Jul 2019 11:26:41 +0100 Subject: [PATCH 18/26] Fix infinite loop in table sort code --- lib/ts/controllers/s-table.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ts/controllers/s-table.ts b/lib/ts/controllers/s-table.ts index f68ce47f09..c58c5b4662 100644 --- a/lib/ts/controllers/s-table.ts +++ b/lib/ts/controllers/s-table.ts @@ -211,10 +211,10 @@ } curSlot++; } - if (curRow && curRow.nextElementSibling) { - curRow = curRow.nextElementSibling; + if (curRow) { + curRow = curRow.nextElementSibling!; } } return findCell ? -1 : index; /* if findCell was given but we end up here, that means it isn't in this section */ } -})(); \ No newline at end of file +})(); From 04b9b7b4bea235c78cfd5dc9d54e803a4c72156b Mon Sep 17 00:00:00 2001 From: Aaron Shekey Date: Wed, 24 Jul 2019 14:05:16 -0500 Subject: [PATCH 19/26] Fix NPM vulnerabilities --- package-lock.json | 68 +++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1ac2c7717..0124bff411 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1055,7 +1055,7 @@ }, "es6-promise": { "version": "3.3.1", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", + "resolved": "http://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", "integrity": "sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM=" }, "es6-promisify": { @@ -4331,9 +4331,9 @@ "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -4990,7 +4990,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -5004,7 +5004,7 @@ "dependencies": { "string_decoder": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { "safe-buffer": "~5.1.0" @@ -5201,19 +5201,18 @@ } }, "rollup-pluginutils": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.4.1.tgz", - "integrity": "sha512-wesMQ9/172IJDIW/lYWm0vW0LiKe5Ekjws481R7z9WTRtmO59cqyM/2uUlxvf6yzm/fElFmHUobeQOYz46dZJw==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz", + "integrity": "sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==", "dev": true, "requires": { - "estree-walker": "^0.6.0", - "micromatch": "^3.1.10" + "estree-walker": "^0.6.1" }, "dependencies": { "estree-walker": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.0.tgz", - "integrity": "sha512-peq1RfVAVzr3PU/jL31RaOjUKLoZJpObQWJJ+LgfcxDUifyLZ1RjPQZTl0pzj2uJ45b7A7XpyppXvxdEqzo4rw==", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", "dev": true } } @@ -5301,9 +5300,9 @@ } }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -5654,7 +5653,7 @@ "dependencies": { "rimraf": { "version": "2.2.8", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", + "resolved": "http://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=" } } @@ -5806,38 +5805,15 @@ } }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "unpipe": { @@ -6047,7 +6023,7 @@ }, "xmlbuilder": { "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", + "resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" }, "xtend": { From b1c549cba7ad906ea0ad5b0787a4f6e9c96092cc Mon Sep 17 00:00:00 2001 From: Aaron Shekey Date: Wed, 24 Jul 2019 14:06:24 -0500 Subject: [PATCH 20/26] Commit compiled JS --- dist/js/stacks.js | 2 +- dist/js/stacks.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index c920a21b14..5ed85c89d2 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4959,7 +4959,7 @@ var __extends = (this && this.__extends) || (function () { } curSlot++; } - if (curRow && curRow.nextElementSibling) { + if (curRow) { curRow = curRow.nextElementSibling; } } diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index 3272ffa265..e989a2c319 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=F({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=F({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=S({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=S({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From 42a5825cb3501bb636c6671030faf9983dd89aea Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 6 Aug 2019 17:06:04 -0400 Subject: [PATCH 21/26] address PR comments --- lib/ts/controllers/s-expandable-control.ts | 8 ++++---- lib/ts/controllers/s-popover.ts | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ts/controllers/s-expandable-control.ts b/lib/ts/controllers/s-expandable-control.ts index 9d7934d9dd..b30fd7531f 100644 --- a/lib/ts/controllers/s-expandable-control.ts +++ b/lib/ts/controllers/s-expandable-control.ts @@ -109,12 +109,12 @@ }); }; - listener(e: UIEvent) { + listener(e: Event) { var newCollapsed; if (this.isCheckable) { newCollapsed = !(this.element).checked; } else { - if (e.type == "keydown" && ((e).keyCode != 13 && (e).keyCode != 32)) { + if (e.type == "keydown" && (e instanceof KeyboardEvent && e.keyCode != 13 && e.keyCode != 32)) { return; } if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf((e.target).nodeName) >= 0) { @@ -134,7 +134,7 @@ connect() { this.events.forEach(e => { - this.element.addEventListener(e, this.listener as EventListener); + this.element.addEventListener(e, this.listener); }, this); if (this.isRadio) { @@ -160,7 +160,7 @@ disconnect() { this.events.forEach(e => { - this.element.removeEventListener(e, this.listener as EventListener); + this.element.removeEventListener(e, this.listener); }, this); if (this.isRadio) { diff --git a/lib/ts/controllers/s-popover.ts b/lib/ts/controllers/s-popover.ts index ce877e1702..2308854279 100644 --- a/lib/ts/controllers/s-popover.ts +++ b/lib/ts/controllers/s-popover.ts @@ -131,9 +131,10 @@ * @param {Event} e - The document click event */ _hideOnOutsideClick(e: MouseEvent) { + const target = e.target; // check if the document was clicked inside either the reference element or the popover itself // note: .contains also returns true if the node itself matches the target element - if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { + if (!this.referenceElement.contains(target) && !this.popoverElement.contains(target)) { this.hide(); } }; From 96304de722ab2f18c5dac9fe7c027fa95502c392 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 6 Aug 2019 17:06:22 -0400 Subject: [PATCH 22/26] commit compiled files --- dist/js/stacks.js | 5 +++-- dist/js/stacks.min.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 5ed85c89d2..4e37890c1d 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4610,7 +4610,7 @@ var __extends = (this && this.__extends) || (function () { newCollapsed = !this.element.checked; } else { - if (e.type == "keydown" && (e.keyCode != 13 && e.keyCode != 32)) { + if (e.type == "keydown" && (e instanceof KeyboardEvent && e.keyCode != 13 && e.keyCode != 32)) { return; } if (e.target !== e.currentTarget && ["A", "BUTTON"].indexOf(e.target.nodeName) >= 0) { @@ -4755,7 +4755,8 @@ var __extends = (this && this.__extends) || (function () { }; ; class_1.prototype._hideOnOutsideClick = function (e) { - if (!this.referenceElement.contains(e.target) && !this.popoverElement.contains(e.target)) { + var target = e.target; + if (!this.referenceElement.contains(target) && !this.popoverElement.contains(target)) { this.hide(); } }; diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index e989a2c319..2207b3628c 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=S({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=S({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=S({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=S({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file From 26606d710949df31eef000695ccaa7df9c58cc0f Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 8 Aug 2019 13:45:06 -0400 Subject: [PATCH 23/26] add declaration support for compiled js files --- Gruntfile.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index fb2a6a7f6b..799bd497da 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -80,6 +80,9 @@ module.exports = function(grunt) { }, docs_js: { tsconfig: "docs/assets/js/tsconfig.json" + }, + options: { + declaration: true } }, uglify: { @@ -207,6 +210,12 @@ module.exports = function(grunt) { dest: 'docs/_data/product/', filter: 'isFile', }, + declarations: { + expand: true, + cwd: 'build/lib/ts', + src: 'stacks.d.ts', + dest: 'dist/js/' + } }, }); @@ -229,7 +238,7 @@ module.exports = function(grunt) { grunt.registerTask('build', 'Compile all JS and LESS files and rebuild the documentation site.', - ['concurrent:compile', 'shell:jekyllBuild']); + ['concurrent:compile', 'shell:jekyllBuild', 'copy:declarations']); grunt.registerTask('update-icons', ['clean:icons', 'copy:svgs', 'copy:data']); From 37841109ca70e8d22637f6a217759497758c4eb6 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 8 Aug 2019 13:46:25 -0400 Subject: [PATCH 24/26] add generated declaration files --- dist/js/stacks.d.ts | 16 ++++++++++++++++ docs/assets/js/controllers.d.ts | 0 2 files changed, 16 insertions(+) create mode 100644 dist/js/stacks.d.ts create mode 100644 docs/assets/js/controllers.d.ts diff --git a/dist/js/stacks.d.ts b/dist/js/stacks.d.ts new file mode 100644 index 0000000000..a6d892eafd --- /dev/null +++ b/dist/js/stacks.d.ts @@ -0,0 +1,16 @@ +declare namespace Stacks { + const application: Stimulus.Application; + var _initializing: boolean; + class StacksController extends Stimulus.Controller { + protected getElementData(element: Element, key: string): string | null; + protected setElementData(element: Element, key: string, value: string): void; + protected removeElementData(element: Element, key: string): void; + protected triggerEvent(eventName: string, detail?: T, optionalElement?: Element): CustomEvent; + } + interface ControllerDefinition { + [name: string]: any; + targets?: string[]; + } + function createController(controllerDefinition: ControllerDefinition): typeof StacksController; + function addController(name: string, controller: ControllerDefinition): void; +} diff --git a/docs/assets/js/controllers.d.ts b/docs/assets/js/controllers.d.ts new file mode 100644 index 0000000000..e69de29bb2 From 2c9d59e9ba44ca7b49f4881ceedc6b22730c45e0 Mon Sep 17 00:00:00 2001 From: b-kelly Date: Fri, 9 Aug 2019 13:55:50 -0400 Subject: [PATCH 25/26] Update lib/ts/controllers/s-popover.ts Co-Authored-By: Brian Nickel --- lib/ts/controllers/s-popover.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/controllers/s-popover.ts b/lib/ts/controllers/s-popover.ts index 2308854279..69b1dfd633 100644 --- a/lib/ts/controllers/s-popover.ts +++ b/lib/ts/controllers/s-popover.ts @@ -3,7 +3,7 @@ (function () { "use strict"; Stacks.application.register("s-popover", class extends Stacks.StacksController { - static targets: []; + static targets = []; private referenceElement!: HTMLElement; private popoverElement!: HTMLElement; From 39123147612f7bb9e08850d023690746c38e485f Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Fri, 9 Aug 2019 13:58:38 -0400 Subject: [PATCH 26/26] commit built files --- dist/js/stacks.js | 193 +++++++++++++++++++++--------------------- dist/js/stacks.min.js | 2 +- 2 files changed, 99 insertions(+), 96 deletions(-) diff --git a/dist/js/stacks.js b/dist/js/stacks.js index 4e37890c1d..116e51ab1c 100644 --- a/dist/js/stacks.js +++ b/dist/js/stacks.js @@ -4684,104 +4684,107 @@ var __extends = (this && this.__extends) || (function () { })(); (function () { "use strict"; - Stacks.application.register("s-popover", (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; - } - class_1.prototype.connect = function () { - var referenceSelector = this.data.get("reference-selector"); - this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; - var popoverId = this.referenceElement.getAttribute("aria-controls"); - if (!popoverId) { - throw "[aria-controls=\"{POPOVER_ID}\"] required"; - } - var element = document.getElementById(popoverId); - if (!element) { - throw "element with popover id not found"; - } - this.popoverElement = element; - this.popper = new Popper(this.referenceElement, this.popoverElement, { - placement: this.data.get("placement") || "bottom", - }); - this._toggleOptionalClasses(this.popoverElement.classList.contains("is-visible")); - }; - ; - class_1.prototype.disconnect = function () { - this.popper.destroy(); - this._unbindDocumentEvents(); - }; - ; - class_1.prototype.toggle = function () { - this._toggle(); - }; - ; - class_1.prototype.show = function () { - this._toggle(true); - }; - ; - class_1.prototype.hide = function () { - this._toggle(false); - }; - ; - class_1.prototype._toggle = function (show) { - var toShow = show; - if (typeof toShow === "undefined") { - toShow = !this.popoverElement.classList.contains("is-visible"); - } - this.triggerEvent(toShow ? "show" : "hide"); - this.popper.update(); - this.popoverElement.classList.toggle("is-visible", show); - this._toggleOptionalClasses(show); - if (this.popoverElement.classList.contains("is-visible")) { - this._bindDocumentEvents(); + var _a; + Stacks.application.register("s-popover", (_a = (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; } - else { + class_1.prototype.connect = function () { + var referenceSelector = this.data.get("reference-selector"); + this.referenceElement = referenceSelector && this.element.querySelector(referenceSelector) || this.element; + var popoverId = this.referenceElement.getAttribute("aria-controls"); + if (!popoverId) { + throw "[aria-controls=\"{POPOVER_ID}\"] required"; + } + var element = document.getElementById(popoverId); + if (!element) { + throw "element with popover id not found"; + } + this.popoverElement = element; + this.popper = new Popper(this.referenceElement, this.popoverElement, { + placement: this.data.get("placement") || "bottom", + }); + this._toggleOptionalClasses(this.popoverElement.classList.contains("is-visible")); + }; + ; + class_1.prototype.disconnect = function () { + this.popper.destroy(); this._unbindDocumentEvents(); - } - this.triggerEvent(toShow ? "shown" : "hidden"); - }; - ; - class_1.prototype._bindDocumentEvents = function () { - this._boundClickFn = this._boundClickFn || this._hideOnOutsideClick.bind(this); - this._boundKeypressFn = this._boundKeypressFn || this._hideOnEscapePress.bind(this); - document.addEventListener("click", this._boundClickFn); - document.addEventListener("keyup", this._boundKeypressFn); - }; - ; - class_1.prototype._unbindDocumentEvents = function () { - document.removeEventListener("click", this._boundClickFn); - document.removeEventListener("keyup", this._boundKeypressFn); - }; - ; - class_1.prototype._hideOnOutsideClick = function (e) { - var target = e.target; - if (!this.referenceElement.contains(target) && !this.popoverElement.contains(target)) { + }; + ; + class_1.prototype.toggle = function () { + this._toggle(); + }; + ; + class_1.prototype.show = function () { + this._toggle(true); + }; + ; + class_1.prototype.hide = function () { + this._toggle(false); + }; + ; + class_1.prototype._toggle = function (show) { + var toShow = show; + if (typeof toShow === "undefined") { + toShow = !this.popoverElement.classList.contains("is-visible"); + } + this.triggerEvent(toShow ? "show" : "hide"); + this.popper.update(); + this.popoverElement.classList.toggle("is-visible", show); + this._toggleOptionalClasses(show); + if (this.popoverElement.classList.contains("is-visible")) { + this._bindDocumentEvents(); + } + else { + this._unbindDocumentEvents(); + } + this.triggerEvent(toShow ? "shown" : "hidden"); + }; + ; + class_1.prototype._bindDocumentEvents = function () { + this._boundClickFn = this._boundClickFn || this._hideOnOutsideClick.bind(this); + this._boundKeypressFn = this._boundKeypressFn || this._hideOnEscapePress.bind(this); + document.addEventListener("click", this._boundClickFn); + document.addEventListener("keyup", this._boundKeypressFn); + }; + ; + class_1.prototype._unbindDocumentEvents = function () { + document.removeEventListener("click", this._boundClickFn); + document.removeEventListener("keyup", this._boundKeypressFn); + }; + ; + class_1.prototype._hideOnOutsideClick = function (e) { + var target = e.target; + if (!this.referenceElement.contains(target) && !this.popoverElement.contains(target)) { + this.hide(); + } + }; + ; + class_1.prototype._hideOnEscapePress = function (e) { + if (e.which !== 27 || !this.popoverElement.classList.contains("is-visible")) { + return; + } + if (this.popoverElement.contains(e.target)) { + this.referenceElement.focus(); + } this.hide(); - } - }; - ; - class_1.prototype._hideOnEscapePress = function (e) { - if (e.which !== 27 || !this.popoverElement.classList.contains("is-visible")) { - return; - } - if (this.popoverElement.contains(e.target)) { - this.referenceElement.focus(); - } - this.hide(); - }; - ; - class_1.prototype._toggleOptionalClasses = function (show) { - if (!this.data.has("toggle-class")) { - return; - } - var cl = this.referenceElement.classList; - this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { - cl.toggle(cls, show); - }); - }; - return class_1; - }(Stacks.StacksController))); + }; + ; + class_1.prototype._toggleOptionalClasses = function (show) { + if (!this.data.has("toggle-class")) { + return; + } + var cl = this.referenceElement.classList; + this.data.get("toggle-class").split(/\s+/).forEach(function (cls) { + cl.toggle(cls, show); + }); + }; + return class_1; + }(Stacks.StacksController)), + _a.targets = [], + _a)); })(); //# sourceMappingURL=s-popover.js.map diff --git a/dist/js/stacks.min.js b/dist/js/stacks.min.js index 2207b3628c..8baa0c24d9 100644 --- a/dist/js/stacks.min.js +++ b/dist/js/stacks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=S({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=S({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Stimulus={})}(this,function(e){"use strict";var r=function(){function e(e,t){this.eventTarget=e,this.eventName=t,this.unorderedBindings=new Set}return e.prototype.connect=function(){this.eventTarget.addEventListener(this.eventName,this,!1)},e.prototype.disconnect=function(){this.eventTarget.removeEventListener(this.eventName,this,!1)},e.prototype.bindingConnected=function(e){this.unorderedBindings.add(e)},e.prototype.bindingDisconnected=function(e){this.unorderedBindings.delete(e)},e.prototype.handleEvent=function(e){for(var t=function(e){{if("immediatePropagationStopped"in e)return e;var t=e.stopImmediatePropagation;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation:function(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e),n=0,r=this.bindings;n)?(.+?)(#(.+))?$/;function t(e){var t=e.trim().match(o)||[];return{eventTarget:function(e){{if("window"==e)return window;if("document"==e)return document}}(t[4]),eventName:t[2],identifier:t[5],methodName:t[7]}}var i=function(){function e(e,t,n){this.element=e,this.index=t,this.eventTarget=n.eventTarget||e,this.eventName=n.eventName||function(e){var t=e.tagName.toLowerCase();if(t in s)return s[t](e)}(e)||a("missing event name"),this.identifier=n.identifier||a("missing identifier"),this.methodName=n.methodName||a("missing method name")}return e.forToken=function(e){return new this(e.element,e.index,t(e.content))},e.prototype.toString=function(){var e=this.eventTargetName?"@"+this.eventTargetName:"";return""+this.eventName+e+"->"+this.identifier+"#"+this.methodName},Object.defineProperty(e.prototype,"eventTargetName",{get:function(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e},enumerable:!0,configurable:!0}),e}(),s={a:function(e){return"click"},button:function(e){return"click"},form:function(e){return"submit"},input:function(e){return"submit"==e.getAttribute("type")?"click":"change"},select:function(e){return"change"},textarea:function(e){return"change"}};function a(e){throw new Error(e)}var c=function(){function e(e,t){this.context=e,this.action=t}return Object.defineProperty(e.prototype,"index",{get:function(){return this.action.index},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTarget",{get:function(){return this.action.eventTarget},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return this.context.identifier},enumerable:!0,configurable:!0}),e.prototype.handleEvent=function(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)},Object.defineProperty(e.prototype,"eventName",{get:function(){return this.action.eventName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"method",{get:function(){var e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error('Action "'+this.action+'" references undefined method "'+this.methodName+'"')},enumerable:!0,configurable:!0}),e.prototype.invokeWithEvent=function(t){try{this.method.call(this.controller,t)}catch(e){var n=this,r={identifier:n.identifier,controller:n.controller,element:n.element,index:n.index,event:t};this.context.handleError(e,'invoking action "'+this.action+'"',r)}},e.prototype.willBeInvokedByEvent=function(e){var t=e.target;return this.element===t||(!(t instanceof Element&&this.element.contains(t))||this.scope.containsElement(t))},Object.defineProperty(e.prototype,"controller",{get:function(){return this.context.controller},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"methodName",{get:function(){return this.action.methodName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"element",{get:function(){return this.scope.element},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scope",{get:function(){return this.context.scope},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){var n=this;this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(function(e){return n.processMutations(e)})}return e.prototype.start=function(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,subtree:!0}),this.refresh())},e.prototype.stop=function(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)},e.prototype.refresh=function(){if(this.started){for(var e=new Set(this.matchElementsInTree()),t=0,n=Array.from(this.elements);ts[0]&&t[1]=r.clientWidth&&n>=r.clientHeight}),l=0c[e]&&!r.escapeWithReference&&(n=Math.min(l[t],c[e]-("right"===e?l.width:l.height))),w({},t,n)}};return u.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";l=S({},l,p[t](e))}),e.offsets.popper=l,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,r=t.reference,o=e.placement.split("-")[0],i=Math.floor,s=-1!==["top","bottom"].indexOf(o),a=s?"right":"bottom",c=s?"left":"top",u=s?"width":"height";return n[a]i(r[a])&&(e.offsets.popper[c]=i(r[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!U(e.instance.modifiers,"arrow","keepTogether"))return e;var r=t.element;if("string"==typeof r){if(!(r=e.instance.popper.querySelector(r)))return e}else if(!e.instance.popper.contains(r))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var o=e.placement.split("-")[0],i=e.offsets,s=i.popper,a=i.reference,c=-1!==["left","right"].indexOf(o),u=c?"height":"width",l=c?"Top":"Left",p=l.toLowerCase(),f=c?"left":"top",h=c?"bottom":"right",d=_(r)[u];a[h]-ds[h]&&(e.offsets.popper[p]+=a[p]+d-s[h]),e.offsets.popper=O(e.offsets.popper);var m=a[p]+a[u]/2-d/2,y=E(e.instance.popper),g=parseFloat(y["margin"+l],10),v=parseFloat(y["border"+l+"Width"],10),b=m-e.offsets.popper[p]-g-v;return b=Math.max(Math.min(s[u]-d,b),0),e.arrowElement=r,e.offsets.arrow=(w(n={},p,Math.round(b)),w(n,f,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(y,g){if(L(y.instance.modifiers,"inner"))return y;if(y.flipped&&y.placement===y.originalPlacement)return y;var v=f(y.instance.popper,y.instance.reference,g.padding,g.boundariesElement,y.positionFixed),b=y.placement.split("-")[0],E=C(b),w=y.placement.split("-")[1]||"",O=[];switch(g.behavior){case q:O=[b,E];break;case Y:O=z(b);break;case G:O=z(b,!0);break;default:O=g.behavior}return O.forEach(function(e,t){if(b!==e||O.length===t+1)return y;b=y.placement.split("-")[0],E=C(b);var n,r=y.offsets.popper,o=y.offsets.reference,i=Math.floor,s="left"===b&&i(r.right)>i(o.left)||"right"===b&&i(r.left)i(o.top)||"bottom"===b&&i(r.top)i(v.right),u=i(r.top)i(v.bottom),p="left"===b&&a||"right"===b&&c||"top"===b&&u||"bottom"===b&&l,f=-1!==["top","bottom"].indexOf(b),h=!!g.flipVariations&&(f&&"start"===w&&a||f&&"end"===w&&c||!f&&"start"===w&&u||!f&&"end"===w&&l),d=!!g.flipVariationsByContent&&(f&&"start"===w&&c||f&&"end"===w&&a||!f&&"start"===w&&l||!f&&"end"===w&&u),m=h||d;(s||p||m)&&(y.flipped=!0,(s||p)&&(b=O[t+1]),m&&(w="end"===(n=w)?"start":"start"===n?"end":n),y.placement=b+(w?"-"+w:""),y.offsets.popper=S({},y.offsets.popper,P(y.instance.popper,y.offsets.reference,y.placement)),y=T(y.instance.modifiers,y,"flip"))}),y},behavior:"flip",padding:5,boundariesElement:"viewport",flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],r=e.offsets,o=r.popper,i=r.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return o[s?"left":"top"]=i[n]-(a?o[s?"width":"height"]:0),e.placement=C(t),e.offsets.popper=O(o),e}},hide:{order:800,enabled:!0,fn:function(e){if(!U(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=M(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightt[0]?1*o:e[0]t[1]?1:-1}),p.forEach(function(e){var t=i[e[1]];t.parentElement.removeChild(t),c?r.insertBefore(t,c):r.appendChild(t)}),this.setCurrentSort(t,1===o?"asc":"desc")}},t}(Stacks.StacksController)).targets=["column"],e))}(),Stacks._initializing=!1; \ No newline at end of file