1472 lines
48KB

  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. var Events = function () {
  9. function Events() {
  10. _classCallCheck(this, Events);
  11. this._types = {};
  12. this._seq = 0;
  13. }
  14. _createClass(Events, [{
  15. key: "on",
  16. value: function on(eventType, listener) {
  17. var subs = this._types[eventType];
  18. if (!subs) {
  19. subs = this._types[eventType] = {};
  20. }
  21. var sub = "sub" + this._seq++;
  22. subs[sub] = listener;
  23. return sub;
  24. }
  25. // Returns false if no match, or string for sub name if matched
  26. }, {
  27. key: "off",
  28. value: function off(eventType, listener) {
  29. var subs = this._types[eventType];
  30. if (typeof listener === "function") {
  31. for (var key in subs) {
  32. if (subs.hasOwnProperty(key)) {
  33. if (subs[key] === listener) {
  34. delete subs[key];
  35. return key;
  36. }
  37. }
  38. }
  39. return false;
  40. } else if (typeof listener === "string") {
  41. if (subs && subs[listener]) {
  42. delete subs[listener];
  43. return listener;
  44. }
  45. return false;
  46. } else {
  47. throw new Error("Unexpected type for listener");
  48. }
  49. }
  50. }, {
  51. key: "trigger",
  52. value: function trigger(eventType, arg, thisObj) {
  53. var subs = this._types[eventType];
  54. for (var key in subs) {
  55. if (subs.hasOwnProperty(key)) {
  56. subs[key].call(thisObj, arg);
  57. }
  58. }
  59. }
  60. }]);
  61. return Events;
  62. }();
  63. exports.default = Events;
  64. },{}],2:[function(require,module,exports){
  65. "use strict";
  66. Object.defineProperty(exports, "__esModule", {
  67. value: true
  68. });
  69. exports.FilterHandle = undefined;
  70. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  71. var _events = require("./events");
  72. var _events2 = _interopRequireDefault(_events);
  73. var _filterset = require("./filterset");
  74. var _filterset2 = _interopRequireDefault(_filterset);
  75. var _group = require("./group");
  76. var _group2 = _interopRequireDefault(_group);
  77. var _util = require("./util");
  78. var util = _interopRequireWildcard(_util);
  79. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  80. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  81. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  82. function getFilterSet(group) {
  83. var fsVar = group.var("filterset");
  84. var result = fsVar.get();
  85. if (!result) {
  86. result = new _filterset2.default();
  87. fsVar.set(result);
  88. }
  89. return result;
  90. }
  91. var id = 1;
  92. function nextId() {
  93. return id++;
  94. }
  95. var FilterHandle = exports.FilterHandle = function () {
  96. /**
  97. * @classdesc
  98. * Use this class to contribute to, and listen for changes to, the filter set
  99. * for the given group of widgets. Filter input controls should create one
  100. * `FilterHandle` and only call {@link FilterHandle#set}. Output widgets that
  101. * wish to displayed filtered data should create one `FilterHandle` and use
  102. * the {@link FilterHandle#filteredKeys} property and listen for change
  103. * events.
  104. *
  105. * If two (or more) `FilterHandle` instances in the same webpage share the
  106. * same group name, they will contribute to a single "filter set". Each
  107. * `FilterHandle` starts out with a `null` value, which means they take
  108. * nothing away from the set of data that should be shown. To make a
  109. * `FilterHandle` actually remove data from the filter set, set its value to
  110. * an array of keys which should be displayed. Crosstalk will aggregate the
  111. * various key arrays by finding their intersection; only keys that are
  112. * present in all non-null filter handles are considered part of the filter
  113. * set.
  114. *
  115. * @param {string} [group] - The name of the Crosstalk group, or if none,
  116. * null or undefined (or any other falsy value). This can be changed later
  117. * via the @{link FilterHandle#setGroup} method.
  118. * @param {Object} [extraInfo] - An object whose properties will be copied to
  119. * the event object whenever an event is emitted.
  120. */
  121. function FilterHandle(group, extraInfo) {
  122. _classCallCheck(this, FilterHandle);
  123. this._eventRelay = new _events2.default();
  124. this._emitter = new util.SubscriptionTracker(this._eventRelay);
  125. // Name of the group we're currently tracking, if any. Can change over time.
  126. this._group = null;
  127. // The filterSet that we're tracking, if any. Can change over time.
  128. this._filterSet = null;
  129. // The Var we're currently tracking, if any. Can change over time.
  130. this._filterVar = null;
  131. // The event handler subscription we currently have on var.on("change").
  132. this._varOnChangeSub = null;
  133. this._extraInfo = util.extend({ sender: this }, extraInfo);
  134. this._id = "filter" + nextId();
  135. this.setGroup(group);
  136. }
  137. /**
  138. * Changes the Crosstalk group membership of this FilterHandle. If `set()` was
  139. * previously called on this handle, switching groups will clear those keys
  140. * from the old group's filter set. These keys will not be applied to the new
  141. * group's filter set either. In other words, `setGroup()` effectively calls
  142. * `clear()` before switching groups.
  143. *
  144. * @param {string} group - The name of the Crosstalk group, or null (or
  145. * undefined) to clear the group.
  146. */
  147. _createClass(FilterHandle, [{
  148. key: "setGroup",
  149. value: function setGroup(group) {
  150. var _this = this;
  151. // If group is unchanged, do nothing
  152. if (this._group === group) return;
  153. // Treat null, undefined, and other falsy values the same
  154. if (!this._group && !group) return;
  155. if (this._filterVar) {
  156. this._filterVar.off("change", this._varOnChangeSub);
  157. this.clear();
  158. this._varOnChangeSub = null;
  159. this._filterVar = null;
  160. this._filterSet = null;
  161. }
  162. this._group = group;
  163. if (group) {
  164. group = (0, _group2.default)(group);
  165. this._filterSet = getFilterSet(group);
  166. this._filterVar = (0, _group2.default)(group).var("filter");
  167. var sub = this._filterVar.on("change", function (e) {
  168. _this._eventRelay.trigger("change", e, _this);
  169. });
  170. this._varOnChangeSub = sub;
  171. }
  172. }
  173. /**
  174. * Combine the given `extraInfo` (if any) with the handle's default
  175. * `_extraInfo` (if any).
  176. * @private
  177. */
  178. }, {
  179. key: "_mergeExtraInfo",
  180. value: function _mergeExtraInfo(extraInfo) {
  181. return util.extend({}, this._extraInfo ? this._extraInfo : null, extraInfo ? extraInfo : null);
  182. }
  183. /**
  184. * Close the handle. This clears this handle's contribution to the filter set,
  185. * and unsubscribes all event listeners.
  186. */
  187. }, {
  188. key: "close",
  189. value: function close() {
  190. this._emitter.removeAllListeners();
  191. this.clear();
  192. this.setGroup(null);
  193. }
  194. /**
  195. * Clear this handle's contribution to the filter set.
  196. *
  197. * @param {Object} [extraInfo] - Extra properties to be included on the event
  198. * object that's passed to listeners (in addition to any options that were
  199. * passed into the `FilterHandle` constructor).
  200. */
  201. }, {
  202. key: "clear",
  203. value: function clear(extraInfo) {
  204. if (!this._filterSet) return;
  205. this._filterSet.clear(this._id);
  206. this._onChange(extraInfo);
  207. }
  208. /**
  209. * Set this handle's contribution to the filter set. This array should consist
  210. * of the keys of the rows that _should_ be displayed; any keys that are not
  211. * present in the array will be considered _filtered out_. Note that multiple
  212. * `FilterHandle` instances in the group may each contribute an array of keys,
  213. * and only those keys that appear in _all_ of the arrays make it through the
  214. * filter.
  215. *
  216. * @param {string[]} keys - Empty array, or array of keys. To clear the
  217. * filter, don't pass an empty array; instead, use the
  218. * {@link FilterHandle#clear} method.
  219. * @param {Object} [extraInfo] - Extra properties to be included on the event
  220. * object that's passed to listeners (in addition to any options that were
  221. * passed into the `FilterHandle` constructor).
  222. */
  223. }, {
  224. key: "set",
  225. value: function set(keys, extraInfo) {
  226. if (!this._filterSet) return;
  227. this._filterSet.update(this._id, keys);
  228. this._onChange(extraInfo);
  229. }
  230. /**
  231. * @return {string[]|null} - Either: 1) an array of keys that made it through
  232. * all of the `FilterHandle` instances, or, 2) `null`, which means no filter
  233. * is being applied (all data should be displayed).
  234. */
  235. }, {
  236. key: "on",
  237. /**
  238. * Subscribe to events on this `FilterHandle`.
  239. *
  240. * @param {string} eventType - Indicates the type of events to listen to.
  241. * Currently, only `"change"` is supported.
  242. * @param {FilterHandle~listener} listener - The callback function that
  243. * will be invoked when the event occurs.
  244. * @return {string} - A token to pass to {@link FilterHandle#off} to cancel
  245. * this subscription.
  246. */
  247. value: function on(eventType, listener) {
  248. return this._emitter.on(eventType, listener);
  249. }
  250. /**
  251. * Cancel event subscriptions created by {@link FilterHandle#on}.
  252. *
  253. * @param {string} eventType - The type of event to unsubscribe.
  254. * @param {string|FilterHandle~listener} listener - Either the callback
  255. * function previously passed into {@link FilterHandle#on}, or the
  256. * string that was returned from {@link FilterHandle#on}.
  257. */
  258. }, {
  259. key: "off",
  260. value: function off(eventType, listener) {
  261. return this._emitter.off(eventType, listener);
  262. }
  263. }, {
  264. key: "_onChange",
  265. value: function _onChange(extraInfo) {
  266. if (!this._filterSet) return;
  267. this._filterVar.set(this._filterSet.value, this._mergeExtraInfo(extraInfo));
  268. }
  269. /**
  270. * @callback FilterHandle~listener
  271. * @param {Object} event - An object containing details of the event. For
  272. * `"change"` events, this includes the properties `value` (the new
  273. * value of the filter set, or `null` if no filter set is active),
  274. * `oldValue` (the previous value of the filter set), and `sender` (the
  275. * `FilterHandle` instance that made the change).
  276. */
  277. /**
  278. * @event FilterHandle#change
  279. * @type {object}
  280. * @property {object} value - The new value of the filter set, or `null`
  281. * if no filter set is active.
  282. * @property {object} oldValue - The previous value of the filter set.
  283. * @property {FilterHandle} sender - The `FilterHandle` instance that
  284. * changed the value.
  285. */
  286. }, {
  287. key: "filteredKeys",
  288. get: function get() {
  289. return this._filterSet ? this._filterSet.value : null;
  290. }
  291. }]);
  292. return FilterHandle;
  293. }();
  294. },{"./events":1,"./filterset":3,"./group":4,"./util":11}],3:[function(require,module,exports){
  295. "use strict";
  296. Object.defineProperty(exports, "__esModule", {
  297. value: true
  298. });
  299. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  300. var _util = require("./util");
  301. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  302. function naturalComparator(a, b) {
  303. if (a === b) {
  304. return 0;
  305. } else if (a < b) {
  306. return -1;
  307. } else if (a > b) {
  308. return 1;
  309. }
  310. }
  311. /**
  312. * @private
  313. */
  314. var FilterSet = function () {
  315. function FilterSet() {
  316. _classCallCheck(this, FilterSet);
  317. this.reset();
  318. }
  319. _createClass(FilterSet, [{
  320. key: "reset",
  321. value: function reset() {
  322. // Key: handle ID, Value: array of selected keys, or null
  323. this._handles = {};
  324. // Key: key string, Value: count of handles that include it
  325. this._keys = {};
  326. this._value = null;
  327. this._activeHandles = 0;
  328. }
  329. }, {
  330. key: "update",
  331. value: function update(handleId, keys) {
  332. if (keys !== null) {
  333. keys = keys.slice(0); // clone before sorting
  334. keys.sort(naturalComparator);
  335. }
  336. var _diffSortedLists = (0, _util.diffSortedLists)(this._handles[handleId], keys),
  337. added = _diffSortedLists.added,
  338. removed = _diffSortedLists.removed;
  339. this._handles[handleId] = keys;
  340. for (var i = 0; i < added.length; i++) {
  341. this._keys[added[i]] = (this._keys[added[i]] || 0) + 1;
  342. }
  343. for (var _i = 0; _i < removed.length; _i++) {
  344. this._keys[removed[_i]]--;
  345. }
  346. this._updateValue(keys);
  347. }
  348. /**
  349. * @param {string[]} keys Sorted array of strings that indicate
  350. * a superset of possible keys.
  351. * @private
  352. */
  353. }, {
  354. key: "_updateValue",
  355. value: function _updateValue() {
  356. var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._allKeys;
  357. var handleCount = Object.keys(this._handles).length;
  358. if (handleCount === 0) {
  359. this._value = null;
  360. } else {
  361. this._value = [];
  362. for (var i = 0; i < keys.length; i++) {
  363. var count = this._keys[keys[i]];
  364. if (count === handleCount) {
  365. this._value.push(keys[i]);
  366. }
  367. }
  368. }
  369. }
  370. }, {
  371. key: "clear",
  372. value: function clear(handleId) {
  373. if (typeof this._handles[handleId] === "undefined") {
  374. return;
  375. }
  376. var keys = this._handles[handleId];
  377. if (!keys) {
  378. keys = [];
  379. }
  380. for (var i = 0; i < keys.length; i++) {
  381. this._keys[keys[i]]--;
  382. }
  383. delete this._handles[handleId];
  384. this._updateValue();
  385. }
  386. }, {
  387. key: "value",
  388. get: function get() {
  389. return this._value;
  390. }
  391. }, {
  392. key: "_allKeys",
  393. get: function get() {
  394. var allKeys = Object.keys(this._keys);
  395. allKeys.sort(naturalComparator);
  396. return allKeys;
  397. }
  398. }]);
  399. return FilterSet;
  400. }();
  401. exports.default = FilterSet;
  402. },{"./util":11}],4:[function(require,module,exports){
  403. (function (global){
  404. "use strict";
  405. Object.defineProperty(exports, "__esModule", {
  406. value: true
  407. });
  408. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  409. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  410. exports.default = group;
  411. var _var2 = require("./var");
  412. var _var3 = _interopRequireDefault(_var2);
  413. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  414. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  415. // Use a global so that multiple copies of crosstalk.js can be loaded and still
  416. // have groups behave as singletons across all copies.
  417. global.__crosstalk_groups = global.__crosstalk_groups || {};
  418. var groups = global.__crosstalk_groups;
  419. function group(groupName) {
  420. if (groupName && typeof groupName === "string") {
  421. if (!groups.hasOwnProperty(groupName)) {
  422. groups[groupName] = new Group(groupName);
  423. }
  424. return groups[groupName];
  425. } else if ((typeof groupName === "undefined" ? "undefined" : _typeof(groupName)) === "object" && groupName._vars && groupName.var) {
  426. // Appears to already be a group object
  427. return groupName;
  428. } else if (Array.isArray(groupName) && groupName.length == 1 && typeof groupName[0] === "string") {
  429. return group(groupName[0]);
  430. } else {
  431. throw new Error("Invalid groupName argument");
  432. }
  433. }
  434. var Group = function () {
  435. function Group(name) {
  436. _classCallCheck(this, Group);
  437. this.name = name;
  438. this._vars = {};
  439. }
  440. _createClass(Group, [{
  441. key: "var",
  442. value: function _var(name) {
  443. if (!name || typeof name !== "string") {
  444. throw new Error("Invalid var name");
  445. }
  446. if (!this._vars.hasOwnProperty(name)) this._vars[name] = new _var3.default(this, name);
  447. return this._vars[name];
  448. }
  449. }, {
  450. key: "has",
  451. value: function has(name) {
  452. if (!name || typeof name !== "string") {
  453. throw new Error("Invalid var name");
  454. }
  455. return this._vars.hasOwnProperty(name);
  456. }
  457. }]);
  458. return Group;
  459. }();
  460. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  461. },{"./var":12}],5:[function(require,module,exports){
  462. (function (global){
  463. "use strict";
  464. Object.defineProperty(exports, "__esModule", {
  465. value: true
  466. });
  467. var _group = require("./group");
  468. var _group2 = _interopRequireDefault(_group);
  469. var _selection = require("./selection");
  470. var _filter = require("./filter");
  471. require("./input");
  472. require("./input_selectize");
  473. require("./input_checkboxgroup");
  474. require("./input_slider");
  475. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  476. var defaultGroup = (0, _group2.default)("default");
  477. function var_(name) {
  478. return defaultGroup.var(name);
  479. }
  480. function has(name) {
  481. return defaultGroup.has(name);
  482. }
  483. if (global.Shiny) {
  484. global.Shiny.addCustomMessageHandler("update-client-value", function (message) {
  485. if (typeof message.group === "string") {
  486. (0, _group2.default)(message.group).var(message.name).set(message.value);
  487. } else {
  488. var_(message.name).set(message.value);
  489. }
  490. });
  491. }
  492. var crosstalk = {
  493. group: _group2.default,
  494. var: var_,
  495. has: has,
  496. SelectionHandle: _selection.SelectionHandle,
  497. FilterHandle: _filter.FilterHandle
  498. };
  499. /**
  500. * @namespace crosstalk
  501. */
  502. exports.default = crosstalk;
  503. global.crosstalk = crosstalk;
  504. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  505. },{"./filter":2,"./group":4,"./input":6,"./input_checkboxgroup":7,"./input_selectize":8,"./input_slider":9,"./selection":10}],6:[function(require,module,exports){
  506. (function (global){
  507. "use strict";
  508. Object.defineProperty(exports, "__esModule", {
  509. value: true
  510. });
  511. exports.register = register;
  512. var $ = global.jQuery;
  513. var bindings = {};
  514. function register(reg) {
  515. bindings[reg.className] = reg;
  516. if (global.document && global.document.readyState !== "complete") {
  517. $(function () {
  518. bind();
  519. });
  520. } else if (global.document) {
  521. setTimeout(bind, 100);
  522. }
  523. }
  524. function bind() {
  525. Object.keys(bindings).forEach(function (className) {
  526. var binding = bindings[className];
  527. $("." + binding.className).not(".crosstalk-input-bound").each(function (i, el) {
  528. bindInstance(binding, el);
  529. });
  530. });
  531. }
  532. // Escape jQuery identifier
  533. function $escape(val) {
  534. return val.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
  535. }
  536. function bindEl(el) {
  537. var $el = $(el);
  538. Object.keys(bindings).forEach(function (className) {
  539. if ($el.hasClass(className) && !$el.hasClass("crosstalk-input-bound")) {
  540. var binding = bindings[className];
  541. bindInstance(binding, el);
  542. }
  543. });
  544. }
  545. function bindInstance(binding, el) {
  546. var jsonEl = $(el).find("script[type='application/json'][data-for='" + $escape(el.id) + "']");
  547. var data = JSON.parse(jsonEl[0].innerText);
  548. var instance = binding.factory(el, data);
  549. $(el).data("crosstalk-instance", instance);
  550. $(el).addClass("crosstalk-input-bound");
  551. }
  552. if (global.Shiny) {
  553. (function () {
  554. var inputBinding = new global.Shiny.InputBinding();
  555. var $ = global.jQuery;
  556. $.extend(inputBinding, {
  557. find: function find(scope) {
  558. return $(scope).find(".crosstalk-input");
  559. },
  560. initialize: function initialize(el) {
  561. if (!$(el).hasClass("crosstalk-input-bound")) {
  562. bindEl(el);
  563. }
  564. },
  565. getId: function getId(el) {
  566. return el.id;
  567. },
  568. getValue: function getValue(el) {},
  569. setValue: function setValue(el, value) {},
  570. receiveMessage: function receiveMessage(el, data) {},
  571. subscribe: function subscribe(el, callback) {
  572. $(el).data("crosstalk-instance").resume();
  573. },
  574. unsubscribe: function unsubscribe(el) {
  575. $(el).data("crosstalk-instance").suspend();
  576. }
  577. });
  578. global.Shiny.inputBindings.register(inputBinding, "crosstalk.inputBinding");
  579. })();
  580. }
  581. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  582. },{}],7:[function(require,module,exports){
  583. (function (global){
  584. "use strict";
  585. var _input = require("./input");
  586. var input = _interopRequireWildcard(_input);
  587. var _filter = require("./filter");
  588. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  589. var $ = global.jQuery;
  590. input.register({
  591. className: "crosstalk-input-checkboxgroup",
  592. factory: function factory(el, data) {
  593. /*
  594. * map: {"groupA": ["keyA", "keyB", ...], ...}
  595. * group: "ct-groupname"
  596. */
  597. var ctHandle = new _filter.FilterHandle(data.group);
  598. var lastKnownKeys = void 0;
  599. var $el = $(el);
  600. $el.on("change", "input[type='checkbox']", function () {
  601. var checked = $el.find("input[type='checkbox']:checked");
  602. if (checked.length === 0) {
  603. lastKnownKeys = null;
  604. ctHandle.clear();
  605. } else {
  606. (function () {
  607. var keys = {};
  608. checked.each(function () {
  609. data.map[this.value].forEach(function (key) {
  610. keys[key] = true;
  611. });
  612. });
  613. var keyArray = Object.keys(keys);
  614. keyArray.sort();
  615. lastKnownKeys = keyArray;
  616. ctHandle.set(keyArray);
  617. })();
  618. }
  619. });
  620. return {
  621. suspend: function suspend() {
  622. ctHandle.clear();
  623. },
  624. resume: function resume() {
  625. if (lastKnownKeys) ctHandle.set(lastKnownKeys);
  626. }
  627. };
  628. }
  629. });
  630. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  631. },{"./filter":2,"./input":6}],8:[function(require,module,exports){
  632. (function (global){
  633. "use strict";
  634. var _input = require("./input");
  635. var input = _interopRequireWildcard(_input);
  636. var _util = require("./util");
  637. var util = _interopRequireWildcard(_util);
  638. var _filter = require("./filter");
  639. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  640. var $ = global.jQuery;
  641. input.register({
  642. className: "crosstalk-input-select",
  643. factory: function factory(el, data) {
  644. /*
  645. * items: {value: [...], label: [...]}
  646. * map: {"groupA": ["keyA", "keyB", ...], ...}
  647. * group: "ct-groupname"
  648. */
  649. var first = [{ value: "", label: "(All)" }];
  650. var items = util.dataframeToD3(data.items);
  651. var opts = {
  652. options: first.concat(items),
  653. valueField: "value",
  654. labelField: "label",
  655. searchField: "label"
  656. };
  657. var select = $(el).find("select")[0];
  658. var selectize = $(select).selectize(opts)[0].selectize;
  659. var ctHandle = new _filter.FilterHandle(data.group);
  660. var lastKnownKeys = void 0;
  661. selectize.on("change", function () {
  662. if (selectize.items.length === 0) {
  663. lastKnownKeys = null;
  664. ctHandle.clear();
  665. } else {
  666. (function () {
  667. var keys = {};
  668. selectize.items.forEach(function (group) {
  669. data.map[group].forEach(function (key) {
  670. keys[key] = true;
  671. });
  672. });
  673. var keyArray = Object.keys(keys);
  674. keyArray.sort();
  675. lastKnownKeys = keyArray;
  676. ctHandle.set(keyArray);
  677. })();
  678. }
  679. });
  680. return {
  681. suspend: function suspend() {
  682. ctHandle.clear();
  683. },
  684. resume: function resume() {
  685. if (lastKnownKeys) ctHandle.set(lastKnownKeys);
  686. }
  687. };
  688. }
  689. });
  690. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  691. },{"./filter":2,"./input":6,"./util":11}],9:[function(require,module,exports){
  692. (function (global){
  693. "use strict";
  694. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  695. var _input = require("./input");
  696. var input = _interopRequireWildcard(_input);
  697. var _filter = require("./filter");
  698. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  699. var $ = global.jQuery;
  700. var strftime = global.strftime;
  701. input.register({
  702. className: "crosstalk-input-slider",
  703. factory: function factory(el, data) {
  704. /*
  705. * map: {"groupA": ["keyA", "keyB", ...], ...}
  706. * group: "ct-groupname"
  707. */
  708. var ctHandle = new _filter.FilterHandle(data.group);
  709. var opts = {};
  710. var $el = $(el).find("input");
  711. var dataType = $el.data("data-type");
  712. var timeFormat = $el.data("time-format");
  713. var timeFormatter = void 0;
  714. // Set up formatting functions
  715. if (dataType === "date") {
  716. timeFormatter = strftime.utc();
  717. opts.prettify = function (num) {
  718. return timeFormatter(timeFormat, new Date(num));
  719. };
  720. } else if (dataType === "datetime") {
  721. var timezone = $el.data("timezone");
  722. if (timezone) timeFormatter = strftime.timezone(timezone);else timeFormatter = strftime;
  723. opts.prettify = function (num) {
  724. return timeFormatter(timeFormat, new Date(num));
  725. };
  726. }
  727. $el.ionRangeSlider(opts);
  728. function getValue() {
  729. var result = $el.data("ionRangeSlider").result;
  730. // Function for converting numeric value from slider to appropriate type.
  731. var convert = void 0;
  732. var dataType = $el.data("data-type");
  733. if (dataType === "date") {
  734. convert = function convert(val) {
  735. return formatDateUTC(new Date(+val));
  736. };
  737. } else if (dataType === "datetime") {
  738. convert = function convert(val) {
  739. // Convert ms to s
  740. return +val / 1000;
  741. };
  742. } else {
  743. convert = function convert(val) {
  744. return +val;
  745. };
  746. }
  747. if ($el.data("ionRangeSlider").options.type === "double") {
  748. return [convert(result.from), convert(result.to)];
  749. } else {
  750. return convert(result.from);
  751. }
  752. }
  753. var lastKnownKeys = null;
  754. $el.on("change.crosstalkSliderInput", function (event) {
  755. if (!$el.data("updating") && !$el.data("animating")) {
  756. var _getValue = getValue(),
  757. _getValue2 = _slicedToArray(_getValue, 2),
  758. from = _getValue2[0],
  759. to = _getValue2[1];
  760. var keys = [];
  761. for (var i = 0; i < data.values.length; i++) {
  762. var val = data.values[i];
  763. if (val >= from && val <= to) {
  764. keys.push(data.keys[i]);
  765. }
  766. }
  767. keys.sort();
  768. ctHandle.set(keys);
  769. lastKnownKeys = keys;
  770. }
  771. });
  772. // let $el = $(el);
  773. // $el.on("change", "input[type="checkbox"]", function() {
  774. // let checked = $el.find("input[type="checkbox"]:checked");
  775. // if (checked.length === 0) {
  776. // ctHandle.clear();
  777. // } else {
  778. // let keys = {};
  779. // checked.each(function() {
  780. // data.map[this.value].forEach(function(key) {
  781. // keys[key] = true;
  782. // });
  783. // });
  784. // let keyArray = Object.keys(keys);
  785. // keyArray.sort();
  786. // ctHandle.set(keyArray);
  787. // }
  788. // });
  789. return {
  790. suspend: function suspend() {
  791. ctHandle.clear();
  792. },
  793. resume: function resume() {
  794. if (lastKnownKeys) ctHandle.set(lastKnownKeys);
  795. }
  796. };
  797. }
  798. });
  799. // Convert a number to a string with leading zeros
  800. function padZeros(n, digits) {
  801. var str = n.toString();
  802. while (str.length < digits) {
  803. str = "0" + str;
  804. }return str;
  805. }
  806. // Given a Date object, return a string in yyyy-mm-dd format, using the
  807. // UTC date. This may be a day off from the date in the local time zone.
  808. function formatDateUTC(date) {
  809. if (date instanceof Date) {
  810. return date.getUTCFullYear() + "-" + padZeros(date.getUTCMonth() + 1, 2) + "-" + padZeros(date.getUTCDate(), 2);
  811. } else {
  812. return null;
  813. }
  814. }
  815. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  816. },{"./filter":2,"./input":6}],10:[function(require,module,exports){
  817. "use strict";
  818. Object.defineProperty(exports, "__esModule", {
  819. value: true
  820. });
  821. exports.SelectionHandle = undefined;
  822. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  823. var _events = require("./events");
  824. var _events2 = _interopRequireDefault(_events);
  825. var _group = require("./group");
  826. var _group2 = _interopRequireDefault(_group);
  827. var _util = require("./util");
  828. var util = _interopRequireWildcard(_util);
  829. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  830. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  831. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  832. var SelectionHandle = exports.SelectionHandle = function () {
  833. /**
  834. * @classdesc
  835. * Use this class to read and write (and listen for changes to) the selection
  836. * for a Crosstalk group. This is intended to be used for linked brushing.
  837. *
  838. * If two (or more) `SelectionHandle` instances in the same webpage share the
  839. * same group name, they will share the same state. Setting the selection using
  840. * one `SelectionHandle` instance will result in the `value` property instantly
  841. * changing across the others, and `"change"` event listeners on all instances
  842. * (including the one that initiated the sending) will fire.
  843. *
  844. * @param {string} [group] - The name of the Crosstalk group, or if none,
  845. * null or undefined (or any other falsy value). This can be changed later
  846. * via the [SelectionHandle#setGroup](#setGroup) method.
  847. * @param {Object} [extraInfo] - An object whose properties will be copied to
  848. * the event object whenever an event is emitted.
  849. */
  850. function SelectionHandle() {
  851. var group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  852. var extraInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  853. _classCallCheck(this, SelectionHandle);
  854. this._eventRelay = new _events2.default();
  855. this._emitter = new util.SubscriptionTracker(this._eventRelay);
  856. // Name of the group we're currently tracking, if any. Can change over time.
  857. this._group = null;
  858. // The Var we're currently tracking, if any. Can change over time.
  859. this._var = null;
  860. // The event handler subscription we currently have on var.on("change").
  861. this._varOnChangeSub = null;
  862. this._extraInfo = util.extend({ sender: this }, extraInfo);
  863. this.setGroup(group);
  864. }
  865. /**
  866. * Changes the Crosstalk group membership of this SelectionHandle. The group
  867. * being switched away from (if any) will not have its selection value
  868. * modified as a result of calling `setGroup`, even if this handle was the
  869. * most recent handle to set the selection of the group.
  870. *
  871. * The group being switched to (if any) will also not have its selection value
  872. * modified as a result of calling `setGroup`. If you want to set the
  873. * selection value of the new group, call `set` explicitly.
  874. *
  875. * @param {string} group - The name of the Crosstalk group, or null (or
  876. * undefined) to clear the group.
  877. */
  878. _createClass(SelectionHandle, [{
  879. key: "setGroup",
  880. value: function setGroup(group) {
  881. var _this = this;
  882. // If group is unchanged, do nothing
  883. if (this._group === group) return;
  884. // Treat null, undefined, and other falsy values the same
  885. if (!this._group && !group) return;
  886. if (this._var) {
  887. this._var.off("change", this._varOnChangeSub);
  888. this._var = null;
  889. this._varOnChangeSub = null;
  890. }
  891. this._group = group;
  892. if (group) {
  893. this._var = (0, _group2.default)(group).var("selection");
  894. var sub = this._var.on("change", function (e) {
  895. _this._eventRelay.trigger("change", e, _this);
  896. });
  897. this._varOnChangeSub = sub;
  898. }
  899. }
  900. /**
  901. * Retrieves the current selection for the group represented by this
  902. * `SelectionHandle`.
  903. *
  904. * - If no selection is active, then this value will be falsy.
  905. * - If a selection is active, but no data points are selected, then this
  906. * value will be an empty array.
  907. * - If a selection is active, and data points are selected, then the keys
  908. * of the selected data points will be present in the array.
  909. */
  910. }, {
  911. key: "_mergeExtraInfo",
  912. /**
  913. * Combines the given `extraInfo` (if any) with the handle's default
  914. * `_extraInfo` (if any).
  915. * @private
  916. */
  917. value: function _mergeExtraInfo(extraInfo) {
  918. // Important incidental effect: shallow clone is returned
  919. return util.extend({}, this._extraInfo ? this._extraInfo : null, extraInfo ? extraInfo : null);
  920. }
  921. /**
  922. * Overwrites the current selection for the group, and raises the `"change"`
  923. * event among all of the group's '`SelectionHandle` instances (including
  924. * this one).
  925. *
  926. * @fires SelectionHandle#change
  927. * @param {string[]} selectedKeys - Falsy, empty array, or array of keys (see
  928. * {@link SelectionHandle#value}).
  929. * @param {Object} [extraInfo] - Extra properties to be included on the event
  930. * object that's passed to listeners (in addition to any options that were
  931. * passed into the `SelectionHandle` constructor).
  932. */
  933. }, {
  934. key: "set",
  935. value: function set(selectedKeys, extraInfo) {
  936. if (this._var) this._var.set(selectedKeys, this._mergeExtraInfo(extraInfo));
  937. }
  938. /**
  939. * Overwrites the current selection for the group, and raises the `"change"`
  940. * event among all of the group's '`SelectionHandle` instances (including
  941. * this one).
  942. *
  943. * @fires SelectionHandle#change
  944. * @param {Object} [extraInfo] - Extra properties to be included on the event
  945. * object that's passed to listeners (in addition to any that were passed
  946. * into the `SelectionHandle` constructor).
  947. */
  948. }, {
  949. key: "clear",
  950. value: function clear(extraInfo) {
  951. if (this._var) this.set(void 0, this._mergeExtraInfo(extraInfo));
  952. }
  953. /**
  954. * Subscribes to events on this `SelectionHandle`.
  955. *
  956. * @param {string} eventType - Indicates the type of events to listen to.
  957. * Currently, only `"change"` is supported.
  958. * @param {SelectionHandle~listener} listener - The callback function that
  959. * will be invoked when the event occurs.
  960. * @return {string} - A token to pass to {@link SelectionHandle#off} to cancel
  961. * this subscription.
  962. */
  963. }, {
  964. key: "on",
  965. value: function on(eventType, listener) {
  966. return this._emitter.on(eventType, listener);
  967. }
  968. /**
  969. * Cancels event subscriptions created by {@link SelectionHandle#on}.
  970. *
  971. * @param {string} eventType - The type of event to unsubscribe.
  972. * @param {string|SelectionHandle~listener} listener - Either the callback
  973. * function previously passed into {@link SelectionHandle#on}, or the
  974. * string that was returned from {@link SelectionHandle#on}.
  975. */
  976. }, {
  977. key: "off",
  978. value: function off(eventType, listener) {
  979. return this._emitter.off(eventType, listener);
  980. }
  981. /**
  982. * Shuts down the `SelectionHandle` object.
  983. *
  984. * Removes all event listeners that were added through this handle.
  985. */
  986. }, {
  987. key: "close",
  988. value: function close() {
  989. this._emitter.removeAllListeners();
  990. this.setGroup(null);
  991. }
  992. /**
  993. * @callback SelectionHandle~listener
  994. * @param {Object} event - An object containing details of the event. For
  995. * `"change"` events, this includes the properties `value` (the new
  996. * value of the selection, or `undefined` if no selection is active),
  997. * `oldValue` (the previous value of the selection), and `sender` (the
  998. * `SelectionHandle` instance that made the change).
  999. */
  1000. /**
  1001. * @event SelectionHandle#change
  1002. * @type {object}
  1003. * @property {object} value - The new value of the selection, or `undefined`
  1004. * if no selection is active.
  1005. * @property {object} oldValue - The previous value of the selection.
  1006. * @property {SelectionHandle} sender - The `SelectionHandle` instance that
  1007. * changed the value.
  1008. */
  1009. }, {
  1010. key: "value",
  1011. get: function get() {
  1012. return this._var ? this._var.get() : null;
  1013. }
  1014. }]);
  1015. return SelectionHandle;
  1016. }();
  1017. },{"./events":1,"./group":4,"./util":11}],11:[function(require,module,exports){
  1018. "use strict";
  1019. Object.defineProperty(exports, "__esModule", {
  1020. value: true
  1021. });
  1022. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1023. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1024. exports.extend = extend;
  1025. exports.checkSorted = checkSorted;
  1026. exports.diffSortedLists = diffSortedLists;
  1027. exports.dataframeToD3 = dataframeToD3;
  1028. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1029. function extend(target) {
  1030. for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1031. sources[_key - 1] = arguments[_key];
  1032. }
  1033. for (var i = 0; i < sources.length; i++) {
  1034. var src = sources[i];
  1035. if (typeof src === "undefined" || src === null) continue;
  1036. for (var key in src) {
  1037. if (src.hasOwnProperty(key)) {
  1038. target[key] = src[key];
  1039. }
  1040. }
  1041. }
  1042. return target;
  1043. }
  1044. function checkSorted(list) {
  1045. for (var i = 1; i < list.length; i++) {
  1046. if (list[i] <= list[i - 1]) {
  1047. throw new Error("List is not sorted or contains duplicate");
  1048. }
  1049. }
  1050. }
  1051. function diffSortedLists(a, b) {
  1052. var i_a = 0;
  1053. var i_b = 0;
  1054. if (!a) a = [];
  1055. if (!b) b = [];
  1056. var a_only = [];
  1057. var b_only = [];
  1058. checkSorted(a);
  1059. checkSorted(b);
  1060. while (i_a < a.length && i_b < b.length) {
  1061. if (a[i_a] === b[i_b]) {
  1062. i_a++;
  1063. i_b++;
  1064. } else if (a[i_a] < b[i_b]) {
  1065. a_only.push(a[i_a++]);
  1066. } else {
  1067. b_only.push(b[i_b++]);
  1068. }
  1069. }
  1070. if (i_a < a.length) a_only = a_only.concat(a.slice(i_a));
  1071. if (i_b < b.length) b_only = b_only.concat(b.slice(i_b));
  1072. return {
  1073. removed: a_only,
  1074. added: b_only
  1075. };
  1076. }
  1077. // Convert from wide: { colA: [1,2,3], colB: [4,5,6], ... }
  1078. // to long: [ {colA: 1, colB: 4}, {colA: 2, colB: 5}, ... ]
  1079. function dataframeToD3(df) {
  1080. var names = [];
  1081. var length = void 0;
  1082. for (var name in df) {
  1083. if (df.hasOwnProperty(name)) names.push(name);
  1084. if (_typeof(df[name]) !== "object" || typeof df[name].length === "undefined") {
  1085. throw new Error("All fields must be arrays");
  1086. } else if (typeof length !== "undefined" && length !== df[name].length) {
  1087. throw new Error("All fields must be arrays of the same length");
  1088. }
  1089. length = df[name].length;
  1090. }
  1091. var results = [];
  1092. var item = void 0;
  1093. for (var row = 0; row < length; row++) {
  1094. item = {};
  1095. for (var col = 0; col < names.length; col++) {
  1096. item[names[col]] = df[names[col]][row];
  1097. }
  1098. results.push(item);
  1099. }
  1100. return results;
  1101. }
  1102. /**
  1103. * Keeps track of all event listener additions/removals and lets all active
  1104. * listeners be removed with a single operation.
  1105. *
  1106. * @private
  1107. */
  1108. var SubscriptionTracker = exports.SubscriptionTracker = function () {
  1109. function SubscriptionTracker(emitter) {
  1110. _classCallCheck(this, SubscriptionTracker);
  1111. this._emitter = emitter;
  1112. this._subs = {};
  1113. }
  1114. _createClass(SubscriptionTracker, [{
  1115. key: "on",
  1116. value: function on(eventType, listener) {
  1117. var sub = this._emitter.on(eventType, listener);
  1118. this._subs[sub] = eventType;
  1119. return sub;
  1120. }
  1121. }, {
  1122. key: "off",
  1123. value: function off(eventType, listener) {
  1124. var sub = this._emitter.off(eventType, listener);
  1125. if (sub) {
  1126. delete this._subs[sub];
  1127. }
  1128. return sub;
  1129. }
  1130. }, {
  1131. key: "removeAllListeners",
  1132. value: function removeAllListeners() {
  1133. var _this = this;
  1134. var current_subs = this._subs;
  1135. this._subs = {};
  1136. Object.keys(current_subs).forEach(function (sub) {
  1137. _this._emitter.off(current_subs[sub], sub);
  1138. });
  1139. }
  1140. }]);
  1141. return SubscriptionTracker;
  1142. }();
  1143. },{}],12:[function(require,module,exports){
  1144. (function (global){
  1145. "use strict";
  1146. Object.defineProperty(exports, "__esModule", {
  1147. value: true
  1148. });
  1149. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1150. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1151. var _events = require("./events");
  1152. var _events2 = _interopRequireDefault(_events);
  1153. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1154. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1155. var Var = function () {
  1156. function Var(group, name, /*optional*/value) {
  1157. _classCallCheck(this, Var);
  1158. this._group = group;
  1159. this._name = name;
  1160. this._value = value;
  1161. this._events = new _events2.default();
  1162. }
  1163. _createClass(Var, [{
  1164. key: "get",
  1165. value: function get() {
  1166. return this._value;
  1167. }
  1168. }, {
  1169. key: "set",
  1170. value: function set(value, /*optional*/event) {
  1171. if (this._value === value) {
  1172. // Do nothing; the value hasn't changed
  1173. return;
  1174. }
  1175. var oldValue = this._value;
  1176. this._value = value;
  1177. // Alert JavaScript listeners that the value has changed
  1178. var evt = {};
  1179. if (event && (typeof event === "undefined" ? "undefined" : _typeof(event)) === "object") {
  1180. for (var k in event) {
  1181. if (event.hasOwnProperty(k)) evt[k] = event[k];
  1182. }
  1183. }
  1184. evt.oldValue = oldValue;
  1185. evt.value = value;
  1186. this._events.trigger("change", evt, this);
  1187. // TODO: Make this extensible, to let arbitrary back-ends know that
  1188. // something has changed
  1189. if (global.Shiny && global.Shiny.onInputChange) {
  1190. global.Shiny.onInputChange(".clientValue-" + (this._group.name !== null ? this._group.name + "-" : "") + this._name, typeof value === "undefined" ? null : value);
  1191. }
  1192. }
  1193. }, {
  1194. key: "on",
  1195. value: function on(eventType, listener) {
  1196. return this._events.on(eventType, listener);
  1197. }
  1198. }, {
  1199. key: "off",
  1200. value: function off(eventType, listener) {
  1201. return this._events.off(eventType, listener);
  1202. }
  1203. }]);
  1204. return Var;
  1205. }();
  1206. exports.default = Var;
  1207. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1208. },{"./events":1}]},{},[5])
  1209. //# sourceMappingURL=crosstalk.js.map