@deephaven/js-plugin-simple-pivot
Version:
Simple Pivot plugin for Deephaven
1,334 lines • 158 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const plugin = require("@deephaven/plugin");
const icons = require("@deephaven/icons");
const React = require("react");
const irisGrid = require("@deephaven/iris-grid");
const jsapiBootstrap = require("@deephaven/jsapi-bootstrap");
const components = require("@deephaven/components");
const Log = require("@deephaven/log");
var jsxRuntimeExports = {};
var jsxRuntime = {
get exports() {
return jsxRuntimeExports;
},
set exports(v) {
jsxRuntimeExports = v;
}
};
var reactJsxRuntime_production_min = {};
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === void 0) {
throw new TypeError("Object.assign cannot be called with null or undefined");
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
var test1 = new String("abc");
test1[5] = "de";
if (Object.getOwnPropertyNames(test1)[0] === "5") {
return false;
}
var test2 = {};
for (var i = 0; i < 10; i++) {
test2["_" + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function(n2) {
return test2[n2];
});
if (order2.join("") !== "0123456789") {
return false;
}
var test3 = {};
"abcdefghijklmnopqrst".split("").forEach(function(letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") {
return false;
}
return true;
} catch (err) {
return false;
}
}
shouldUseNative() ? Object.assign : function(target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
/** @license React v17.0.2
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var f = React, g = 60103;
reactJsxRuntime_production_min.Fragment = 60107;
if ("function" === typeof Symbol && Symbol.for) {
var h = Symbol.for;
g = h("react.element");
reactJsxRuntime_production_min.Fragment = h("react.fragment");
}
var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty, p = { key: true, ref: true, __self: true, __source: true };
function q(c, a, k) {
var b, d = {}, e = null, l = null;
void 0 !== k && (e = "" + k);
void 0 !== a.key && (e = "" + a.key);
void 0 !== a.ref && (l = a.ref);
for (b in a)
n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
if (c && c.defaultProps)
for (b in a = c.defaultProps, a)
void 0 === d[b] && (d[b] = a[b]);
return { $$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current };
}
reactJsxRuntime_production_min.jsx = q;
reactJsxRuntime_production_min.jsxs = q;
(function(module2) {
{
module2.exports = reactJsxRuntime_production_min;
}
})(jsxRuntime);
function removeNullAndUndefined() {
for (var _len = arguments.length, maybeDefined = new Array(_len), _key = 0; _key < _len; _key++) {
maybeDefined[_key] = arguments[_key];
}
return maybeDefined.filter((m2) => m2 != null);
}
function _defineProperty$b(obj, key, value) {
key = _toPropertyKey$b(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$b(arg) {
var key = _toPrimitive$b(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$b(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
class CanceledPromiseError extends Error {
constructor() {
super(...arguments);
_defineProperty$b(this, "isCanceled", true);
}
}
const CanceledPromiseError$1 = CanceledPromiseError;
function bindAllMethods(instance) {
var traversePrototypeChain = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
var methodNames = getAllMethodNames(instance, traversePrototypeChain);
methodNames.forEach((methodName) => {
instance[methodName] = instance[methodName].bind(instance);
});
}
function getAllMethodNames(instance, traversePrototypeChain) {
var methodNames = /* @__PURE__ */ new Set();
var current = instance;
var level = 0;
while (current != null && current !== Object.prototype && (level <= 1 || traversePrototypeChain)) {
for (var name of Object.getOwnPropertyNames(current)) {
var _Object$getOwnPropert;
if (name !== "constructor" && // Ensure this is a method and not a getter
typeof ((_Object$getOwnPropert = Object.getOwnPropertyDescriptor(current, name)) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.value) === "function") {
methodNames.add(name);
}
}
current = Object.getPrototypeOf(current);
level += 1;
}
return [...methodNames.keys()];
}
class EventShimCustomEvent extends CustomEvent {
// The fields declared are so TS plays nicely w/ event-target-shim and the browser CustomEvent
// They don't actually do anything other than tell TS to not complain that they aren't set in the constructor
// If declare is removed, then the properties are initialized to undefined which breaks this class
// This will be the default for tsc and babel at some point
// https://github.com/babel/babel/issues/12128#issuecomment-702119272
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(typeArg, eventInitDict) {
super(typeArg, eventInitDict);
}
}
function _defineProperty$a(obj, key, value) {
key = _toPropertyKey$a(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$a(arg) {
var key = _toPrimitive$a(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$a(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
class TimeoutError extends Error {
constructor() {
super(...arguments);
_defineProperty$a(this, "isTimeout", true);
}
}
const TimeoutError$1 = TimeoutError;
class PromiseUtils {
/**
* Creates a promise that can be canceled by calling the `cancel` function
* Pass an optional `cleanupFunc` to perform actions on the resolved item after promise is cancelled.
* @param promise The item to resolve
* @param cleanup Function to cleanup the resolved item after cancelation. Called after both this promise is cancelled and the wrapped item was resolved (order does not matter).
*/
static makeCancelable(promise, cleanup) {
var hasCanceled = false;
var resolved;
var rejectFn;
var wrappedPromise = new Promise((resolve, reject) => {
rejectFn = reject;
Promise.resolve(promise).then((val) => {
if (hasCanceled) {
if (cleanup) {
cleanup(val);
}
} else {
resolved = val;
resolve(val);
}
}).catch((error) => reject(error));
});
wrappedPromise.cancel = () => {
hasCanceled = true;
rejectFn(new CanceledPromiseError$1());
if (resolved != null && cleanup) {
cleanup(resolved);
}
};
return wrappedPromise;
}
static isCanceled(error) {
return error instanceof CanceledPromiseError$1;
}
static isTimedOut(error) {
return error instanceof TimeoutError$1;
}
/**
* Wrap a callback call in a Promise + setTimeout.
* @param timeoutMs
* @param callback
*/
static withTimeout(timeoutMs, callback) {
return new Promise((resolve, reject) => {
setTimeout(() => {
try {
resolve(callback());
} catch (err) {
reject(err);
}
}, timeoutMs);
});
}
}
function assertInstanceOf(instance, type) {
if (!(instance instanceof type)) {
throw new Error("Expected instance of ".concat(type.name));
}
}
function assertNotNull(value) {
var message = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "Value is null or undefined";
if (value == null)
throw new Error(message);
}
function getErrorMessage(error) {
var errorObj = error;
if (error instanceof CustomEvent) {
errorObj = error.detail;
}
var message = "";
if (errorObj instanceof Error) {
message = errorObj.message;
} else if (errorObj != null) {
message = "".concat(errorObj);
}
message = message.trim();
if (message.length > 0) {
return message;
}
return void 0;
}
class TextUtils {
/**
* Joins a list of strings with a comma, keeping the oxford comma and adding "and" as appropriate.
* Eg.
* One
* One and Two
* One, Two, and Three
* @param items The items to join in a list
* @param conjunction Conjunction to use between the last two items
*/
static join(items) {
var conjunction = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "and";
if (items == null || items.length === 0) {
return "";
}
if (items.length === 1) {
return items[0];
}
if (items.length === 2) {
return "".concat(items[0], " ").concat(conjunction, " ").concat(items[1]);
}
var itemText = items.slice(0, items.length - 1).join(", ");
var lastItem = items[items.length - 1];
return "".concat(itemText, ", ").concat(conjunction, " ").concat(lastItem);
}
/**
* Converts text to lower case, handling null if necessary and returning an empty string
* @param text The text to convert to lower case
* @param isNullAllowed True if a null string should return an empty string from this function. If false an error is thrown if null is passed in.
*/
static toLower(text) {
var isNullAllowed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
if (text == null) {
if (isNullAllowed) {
return "";
}
throw new Error("Null string passed in to TextUtils.toLower");
}
return text.toLowerCase();
}
/**
*
* @param a The string to sort
* @param b Second string to sort
* @param isAscending Whether to sort ascending or descending
*/
static sort(a, b) {
var isAscending = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
if (a < b) {
return isAscending ? -1 : 1;
}
if (a > b) {
return isAscending ? 1 : -1;
}
return 0;
}
}
var safeIsNaN = Number.isNaN || function ponyfill(value) {
return typeof value === "number" && value !== value;
};
function isEqual(first, second) {
if (first === second) {
return true;
}
if (safeIsNaN(first) && safeIsNaN(second)) {
return true;
}
return false;
}
function areInputsEqual(newInputs, lastInputs) {
if (newInputs.length !== lastInputs.length) {
return false;
}
for (var i = 0; i < newInputs.length; i++) {
if (!isEqual(newInputs[i], lastInputs[i])) {
return false;
}
}
return true;
}
function memoizeOne(resultFn, isEqual2) {
if (isEqual2 === void 0) {
isEqual2 = areInputsEqual;
}
var lastThis;
var lastArgs = [];
var lastResult;
var calledOnce = false;
function memoized() {
var newArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
newArgs[_i] = arguments[_i];
}
if (calledOnce && lastThis === this && isEqual2(newArgs, lastArgs)) {
return lastResult;
}
lastResult = resultFn.apply(this, newArgs);
calledOnce = true;
lastThis = this;
lastArgs = newArgs;
return lastResult;
}
return memoized;
}
function _defineProperty$9(obj, key, value) {
key = _toPropertyKey$9(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$9(arg) {
var key = _toPrimitive$9(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$9(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
class TableColumnFormatter {
/**
* Validates format object
* @param dh JSAPI instance
* @param format Format object
* @returns true for valid object
*/
static isValid(dh, format) {
return true;
}
/**
* Check if the given formats match
* @param formatA format object to check
* @param formatB format object to check
* @returns True if the formats match
*/
static isSameFormat(formatA, formatB) {
throw new Error("isSameFormat not implemented");
}
/**
* Create and return a Format object
* @param label The label of the format object
* @param formatString Format string to use for the format
* @param type The type of column to use for this format
* @returns A format object
*/
static makeFormat(label, formatString, type) {
return {
label,
formatString,
type
};
}
/**
* @param value The value to format
* @param format Optional format object with value transformation options
* @returns String the formatted text string of the value passed in.
*/
format(value, format) {
return "";
}
}
_defineProperty$9(TableColumnFormatter, "TYPE_GLOBAL", "type-global");
_defineProperty$9(TableColumnFormatter, "TYPE_CONTEXT_PRESET", "type-context-preset");
_defineProperty$9(TableColumnFormatter, "TYPE_CONTEXT_CUSTOM", "type-context-custom");
const TableColumnFormatter$1 = TableColumnFormatter;
class BooleanColumnFormatter extends TableColumnFormatter$1 {
format(value) {
switch (value) {
case 1:
case true:
return "true";
case 0:
case false:
return "false";
default:
return "";
}
}
}
const BooleanColumnFormatter$1 = BooleanColumnFormatter;
class CharColumnFormatter extends TableColumnFormatter$1 {
format(value) {
return String.fromCharCode(value);
}
}
const CharColumnFormatter$1 = CharColumnFormatter;
function _defineProperty$8(obj, key, value) {
key = _toPropertyKey$8(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$8(arg) {
var key = _toPrimitive$8(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$8(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
var log$4 = Log.module("DateTimeColumnFormatter");
class DateTimeColumnFormatter extends TableColumnFormatter$1 {
/**
* Validates format object
* @param dh JSAPI instance
* @param format Format object
* @returns true for valid object
*/
static isValid(dh, format) {
if (format.formatString == null) {
return false;
}
try {
dh.i18n.DateTimeFormat.format(format.formatString, new Date());
return true;
} catch (e) {
return false;
}
}
static makeFormat(label, formatString) {
var type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : TableColumnFormatter$1.TYPE_CONTEXT_PRESET;
return {
label,
formatString,
type
};
}
/**
* Check if the given formats match
* @param formatA format object to check
* @param formatB format object to check
* @returns True if the formats match
*/
static isSameFormat(formatA, formatB) {
return formatA === formatB || formatA !== null && formatB !== null && formatA.type === formatB.type && formatA.formatString === formatB.formatString;
}
static makeGlobalFormatStringMap(showTimeZone, showTSeparator) {
var separator = showTSeparator ? "'T'" : " ";
var tz = showTimeZone ? " z" : "";
return /* @__PURE__ */ new Map([["yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd".concat(separator, "HH:mm:ss").concat(tz)], ["yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd".concat(separator, "HH:mm:ss.SSS").concat(tz)], ["yyyy-MM-dd HH:mm:ss.SSSSSSSSS", "yyyy-MM-dd".concat(separator, "HH:mm:ss.SSSSSSSSS").concat(tz)]]);
}
static getGlobalFormats(showTimeZone, showTSeparator) {
var formatStringMap = DateTimeColumnFormatter.makeGlobalFormatStringMap(showTimeZone, showTSeparator);
return [...formatStringMap.keys()];
}
static makeFormatStringMap(showTimeZone, showTSeparator) {
var separator = showTSeparator !== void 0 && showTSeparator ? "'T'" : " ";
var tz = showTimeZone !== void 0 && showTimeZone ? " z" : "";
return /* @__PURE__ */ new Map([["yyyy-MM-dd", "yyyy-MM-dd".concat(tz)], ["MM-dd-yyyy", "MM-dd-yyyy".concat(tz)], ["HH:mm:ss", "HH:mm:ss".concat(tz)], ["HH:mm:ss.SSS", "HH:mm:ss.SSS".concat(tz)], ["HH:mm:ss.SSSSSSSSS", "HH:mm:ss.SSSSSSSSS".concat(tz)], ["yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd".concat(separator, "HH:mm:ss").concat(tz)], ["yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd".concat(separator, "HH:mm:ss.SSS").concat(tz)], ["yyyy-MM-dd HH:mm:ss.SSSSSSSSS", "yyyy-MM-dd".concat(separator, "HH:mm:ss.SSSSSSSSS").concat(tz)]]);
}
static getFormats(showTimeZone, showTSeparator) {
var formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(showTimeZone, showTSeparator);
return [...formatStringMap.keys()];
}
constructor(dh) {
var {
timeZone: timeZoneParam = "",
showTimeZone = true,
showTSeparator = false,
defaultDateTimeFormatString = DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
super();
_defineProperty$8(this, "dh", void 0);
_defineProperty$8(this, "dhTimeZone", void 0);
_defineProperty$8(this, "defaultDateTimeFormatString", void 0);
_defineProperty$8(this, "showTimeZone", void 0);
_defineProperty$8(this, "showTSeparator", void 0);
_defineProperty$8(this, "formatStringMap", void 0);
var timeZone = timeZoneParam || DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID;
try {
this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(timeZone);
} catch (e) {
log$4.error("Unsupported time zone id", timeZone);
this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID);
}
this.dh = dh;
this.defaultDateTimeFormatString = defaultDateTimeFormatString;
this.showTimeZone = showTimeZone;
this.showTSeparator = showTSeparator;
this.formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(showTimeZone, showTSeparator);
}
getEffectiveFormatString(baseFormatString) {
var _this$formatStringMap;
return (_this$formatStringMap = this.formatStringMap.get(baseFormatString)) !== null && _this$formatStringMap !== void 0 ? _this$formatStringMap : baseFormatString;
}
format(value) {
var format = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var baseFormatString = format.formatString != null && format.formatString !== "" ? format.formatString : this.defaultDateTimeFormatString;
var formatString = this.getEffectiveFormatString(baseFormatString);
try {
return this.dh.i18n.DateTimeFormat.format(formatString, value, this.dhTimeZone);
} catch (e) {
log$4.error("Invalid format arguments");
}
return "";
}
}
_defineProperty$8(DateTimeColumnFormatter, "DEFAULT_DATETIME_FORMAT_STRING", "yyyy-MM-dd HH:mm:ss.SSS");
_defineProperty$8(DateTimeColumnFormatter, "DEFAULT_TIME_ZONE_ID", "America/New_York");
function _defineProperty$7(obj, key, value) {
key = _toPropertyKey$7(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$7(arg) {
var key = _toPrimitive$7(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$7(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
var log$3 = Log.module("DecimalColumnFormatter");
class DecimalColumnFormatter extends TableColumnFormatter$1 {
/**
* Validates format object
* @param dh JSAPI instance
* @param format Format object
* @returns true for valid object
*/
static isValid(dh, format) {
if (format.formatString == null) {
return false;
}
try {
dh.i18n.NumberFormat.format(format.formatString, 0);
return true;
} catch (e) {
return false;
}
}
/**
* Create a DecimalColumnFormat object with the parameters specified
* @param label Label for the format
* @param formatString Format string for the format
* @param multiplier Optional multiplier for the formatter
* @param type Type of format created
* @returns DecimalColumnFormat object
*/
static makeFormat(label, formatString) {
var type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : TableColumnFormatter$1.TYPE_CONTEXT_PRESET;
var multiplier = arguments.length > 3 ? arguments[3] : void 0;
return {
label,
type,
formatString,
multiplier
};
}
/**
* Convenient function to create a DecimalFormatObject with Preset type set
* @param label Label for this format object
* @param formatString Format string to use
* @param multiplier Multiplier to use
* @returns DecimalColumnFormat object
*/
static makePresetFormat(label) {
var formatString = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
var multiplier = arguments.length > 2 ? arguments[2] : void 0;
return DecimalColumnFormatter.makeFormat(label, formatString, TableColumnFormatter$1.TYPE_CONTEXT_PRESET, multiplier);
}
/**
* Convenient function to create a DecimalFormatObject with a default 'Custom Format' label and Custom type
* @param formatString Format string to use
* @param multiplier Multiplier to use
* @returns DecimalColumnFormat object
*/
static makeCustomFormat() {
var formatString = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
var multiplier = arguments.length > 1 ? arguments[1] : void 0;
return DecimalColumnFormatter.makeFormat("Custom Format", formatString, TableColumnFormatter$1.TYPE_CONTEXT_CUSTOM, multiplier);
}
/**
* Check if the given formats match
* @param formatA format object to check
* @param formatB format object to check
* @returns True if the formats match
*/
static isSameFormat(formatA, formatB) {
return formatA === formatB || formatA != null && formatB != null && formatA.type === formatB.type && formatA.formatString === formatB.formatString && formatA.multiplier === formatB.multiplier;
}
constructor(dh) {
var {
defaultFormatString = DecimalColumnFormatter.DEFAULT_FORMAT_STRING
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
super();
_defineProperty$7(this, "defaultFormatString", void 0);
_defineProperty$7(this, "dh", void 0);
this.dh = dh;
this.defaultFormatString = defaultFormatString;
}
/**
* Format a value with the provided format object
* @param valueParam Value to format
* @param format Format object
* @returns Formatted string
*/
format(valueParam) {
var format = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var formatString = format.formatString != null && format.formatString !== "" ? format.formatString : this.defaultFormatString;
var value = format.multiplier != null && format.multiplier !== 0 ? valueParam * format.multiplier : valueParam;
try {
return this.dh.i18n.NumberFormat.format(formatString, value);
} catch (e) {
log$3.error("Invalid format arguments");
}
return "";
}
}
_defineProperty$7(DecimalColumnFormatter, "DEFAULT_FORMAT_STRING", "###,##0.0000");
_defineProperty$7(DecimalColumnFormatter, "FORMAT_PERCENT", DecimalColumnFormatter.makePresetFormat("Percent", "##0.00%"));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_BASIS_POINTS", DecimalColumnFormatter.makePresetFormat("Basis Points", "###,##0 bp", 1e4));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_THOUSANDS", DecimalColumnFormatter.makePresetFormat("Thousands", "##0.000 k", 1e-3));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_MILLIONS", DecimalColumnFormatter.makePresetFormat("Millions", "###,##0.000 mm", 1e-6));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_SCIENTIFIC_NOTATION", DecimalColumnFormatter.makePresetFormat("Scientific Notation", "0.0000E0"));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_ROUND", DecimalColumnFormatter.makePresetFormat("Round", "###,##0"));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_ROUND_TWO_DECIMALS", DecimalColumnFormatter.makePresetFormat("0.00", "###,##0.00"));
_defineProperty$7(DecimalColumnFormatter, "FORMAT_ROUND_FOUR_DECIMALS", DecimalColumnFormatter.makePresetFormat("0.0000", "###,##0.0000"));
class DefaultColumnFormatter extends TableColumnFormatter$1 {
format(value) {
return "".concat(value);
}
}
const DefaultColumnFormatter$1 = DefaultColumnFormatter;
function _defineProperty$6(obj, key, value) {
key = _toPropertyKey$6(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$6(arg) {
var key = _toPrimitive$6(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$6(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
var log$2 = Log.module("IntegerColumnFormatter");
class IntegerColumnFormatter extends TableColumnFormatter$1 {
/**
* Validates format object
* @param dh JSAPI instance
* @param format Format object
* @returns true for valid object
*/
static isValid(dh, format) {
if (format.formatString == null) {
return false;
}
try {
dh.i18n.NumberFormat.format(format.formatString, 0);
return true;
} catch (e) {
return false;
}
}
/**
* Create an IntegerColumnFormat object with the parameters specified
* @param label Label for the format
* @param formatString Format string for the format
* @param multiplier Optional multiplier for the formatter
* @param type Type of format created
* @returns IntegerColumnFormat object
*/
static makeFormat(label, formatString) {
var type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : TableColumnFormatter$1.TYPE_CONTEXT_PRESET;
var multiplier = arguments.length > 3 ? arguments[3] : void 0;
return {
label,
type,
formatString,
multiplier
};
}
/**
* Convenient function to create a IntegerFormatObject with Preset type set
* @param label Label for this format object
* @param formatString Format string to use
* @param multiplier Multiplier to use
* @returns IntegerColumnFormat object
*/
static makePresetFormat(label) {
var formatString = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
var multiplier = arguments.length > 2 ? arguments[2] : void 0;
return IntegerColumnFormatter.makeFormat(label, formatString, TableColumnFormatter$1.TYPE_CONTEXT_PRESET, multiplier);
}
/**
* Convenient function to create a IntegerFormatObject with a default 'Custom Format' label and Custom type
* @param formatString Format string to use
* @param multiplier Multiplier to use
* @returns IntegerColumnFormat object
*/
static makeCustomFormat() {
var formatString = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
var multiplier = arguments.length > 1 ? arguments[1] : void 0;
return IntegerColumnFormatter.makeFormat("Custom Format", formatString, TableColumnFormatter$1.TYPE_CONTEXT_CUSTOM, multiplier);
}
/**
* Check if the given formats match
* @param formatA format object to check
* @param formatB format object to check
* @returns True if the formats match
*/
static isSameFormat(formatA, formatB) {
return formatA === formatB || formatA != null && formatB != null && formatA.type === formatB.type && formatA.formatString === formatB.formatString && formatA.multiplier === formatB.multiplier;
}
constructor(dh) {
var {
defaultFormatString = IntegerColumnFormatter.DEFAULT_FORMAT_STRING
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
super();
_defineProperty$6(this, "dh", void 0);
_defineProperty$6(this, "defaultFormatString", void 0);
this.dh = dh;
this.defaultFormatString = defaultFormatString;
}
/**
* Format a value with the provided format object
* @param valueParam Value to format
* @param format Format object
* @returns Formatted string
*/
format(valueParam) {
var format = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var formatString = format.formatString != null && format.formatString !== "" ? format.formatString : this.defaultFormatString;
var value = format.multiplier != null && format.multiplier !== 0 ? valueParam * format.multiplier : valueParam;
try {
return this.dh.i18n.NumberFormat.format(formatString, value);
} catch (e) {
log$2.error("Invalid format arguments");
}
return "";
}
}
_defineProperty$6(IntegerColumnFormatter, "DEFAULT_FORMAT_STRING", "###,##0");
_defineProperty$6(IntegerColumnFormatter, "FORMAT_THOUSANDS", IntegerColumnFormatter.makePresetFormat("Thousands", "##0.000 k", 1e-3));
_defineProperty$6(IntegerColumnFormatter, "FORMAT_MILLIONS", IntegerColumnFormatter.makePresetFormat("Millions", "###,##0.000 mm", 1e-6));
_defineProperty$6(IntegerColumnFormatter, "FORMAT_SCIENTIFIC_NOTATION", IntegerColumnFormatter.makePresetFormat("Scientific Notation", "0.0000E0"));
class StringColumnFormatter extends TableColumnFormatter$1 {
format(value) {
return value;
}
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
_defineProperty$5(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _defineProperty$5(obj, key, value) {
key = _toPropertyKey$5(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$5(arg) {
var key = _toPrimitive$5(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$5(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
var DATE_TIME_REGEX = /\s*(\d{4})([-./](\d{1,2}|[a-z]+))?([-./](\d{1,2}))?([tT\s](\d{2})([:](\d{2}))?([:](\d{2}))?([.](\d{1,9}))?)?(.*)/;
class DateUtils {
/**
*
* @param timeZone The time zone to parse this time in. E.g. America/New_York
* @param year The year for the date
* @param month The month, starting at 0
* @param day The day, starting at 1
* @param hour The hours
* @param minute The minutes
* @param second The seconds
* @param ns The nanoseconds
*/
static makeDateWrapper(dh, timeZone, year) {
var month = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
var day = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 1;
var hour = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 0;
var minute = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : 0;
var second = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : 0;
var ns = arguments.length > 8 && arguments[8] !== void 0 ? arguments[8] : 0;
if (!timeZone) {
throw new Error("No timezone provided");
}
var yearString = "".concat(year).padStart(4, "0");
var monthString = "".concat(month + 1).padStart(2, "0");
var dayString = "".concat(day).padStart(2, "0");
var hourString = "".concat(hour).padStart(2, "0");
var minuteString = "".concat(minute).padStart(2, "0");
var secondString = "".concat(second).padStart(2, "0");
var nanoString = "".concat(ns).padStart(9, "0");
var dateString = "".concat(yearString, "-").concat(monthString, "-").concat(dayString, " ").concat(hourString, ":").concat(minuteString, ":").concat(secondString, ".").concat(nanoString);
return dh.i18n.DateTimeFormat.parse(DateUtils.FULL_DATE_FORMAT, dateString, dh.i18n.TimeZone.getTimeZone(timeZone));
}
/**
* Takes the string the user entered and returns the next nanos value
* @param nanoString The nano string to get the next one of
* @returns The value of the next nanos
*/
static getNextNanos(nanoString) {
var sigNanos = parseInt(nanoString, 10);
var zeros = "0".repeat(9 - nanoString.length);
var nextNanoString = "".concat(sigNanos + 1).concat(zeros);
return parseInt(nextNanoString, 10);
}
/**
* @param components The string components that were parsed from the original string
* @param values The values that were parsed from the components
* @param timeZone The time zone to parse the date in. E.g. America/New_York
* @returns Returns the DateWrapper for the next date, or null if a full date was passed in
*/
static getNextDate(dh, components2, values, timeZone) {
var {
year,
month,
date,
hours,
minutes,
seconds,
nanos
} = values;
if (components2.nanos != null) {
if (components2.nanos.length === 9) {
return null;
}
nanos = DateUtils.getNextNanos(components2.nanos);
if (nanos > 999999999) {
seconds += 1;
nanos = 0;
}
} else if (components2.seconds != null) {
seconds += 1;
} else if (components2.minutes != null) {
minutes += 1;
} else if (components2.hours != null) {
hours += 1;
} else if (components2.date != null) {
date += 1;
} else if (components2.month != null) {
month += 1;
} else {
year += 1;
}
var jsDate = new Date(year, month, date, hours, minutes, seconds);
return DateUtils.makeDateWrapper(dh, timeZone, jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate(), jsDate.getHours(), jsDate.getMinutes(), jsDate.getSeconds(), nanos);
}
/**
* Get the JS month value for the provided string.
* Matches digits or a month name (eg. '1', '01', 'jan', 'january' should all work)
* @param monthString The string to parse to a JS month value
* @returns number The JS month value, which starts at 0 for january, or NaN if nothing could be parsed
*/
static parseMonth(monthString) {
var month = parseInt(monthString, 10);
if (!Number.isNaN(month)) {
if (month >= 1 && month <= 12) {
return month - 1;
}
return NaN;
}
var cleanMonthString = monthString.trim().toLowerCase();
if (cleanMonthString.length >= 3) {
for (var i = 0; i < DateUtils.months.length; i += 1) {
if (DateUtils.months[i].startsWith(cleanMonthString)) {
return i;
}
}
}
return NaN;
}
/**
* Parse a date object out of the provided string segments.
* Also using `parseMonth` to get month names like Aug/August rather than
* simply doing `parseInt`.
* @param yearString The year part of the string
* @param monthString The month part of the string
* @param dayString The day part of the string
* @param hourString The hour part of the string
* @param minuteString The minute part of the string
* @param secondString The second part of the string
* @param nanoString The milli part of the string
*/
static parseDateValues(yearString, monthString, dayString, hourString, minuteString, secondString, nanoString) {
var year = parseInt(yearString, 10);
var month = monthString != null ? this.parseMonth(monthString) : 0;
var date = dayString != null ? parseInt(dayString, 10) : 1;
var hours = hourString != null ? parseInt(hourString, 10) : 0;
var minutes = minuteString != null ? parseInt(minuteString, 10) : 0;
var seconds = secondString != null ? parseInt(secondString, 10) : 0;
var nanos = nanoString != null ? parseInt(nanoString.padEnd(9, "0"), 10) : 0;
if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(date) || Number.isNaN(hours) || Number.isNaN(minutes) || Number.isNaN(seconds) || Number.isNaN(nanos)) {
return null;
}
return {
year,
month,
date,
hours,
minutes,
seconds,
nanos
};
}
/**
* Parse out a date time string into it's string components.
* Anything that is not captured in the string will be undefined.
*
* @param dateTimeString The date time string to parse
* @param allowOverflow If true, will allow overflow characters after the date
* string
* @returns Containing the date time components
*/
static parseDateTimeString(dateTimeString) {
var allowOverflow = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
var result = DATE_TIME_REGEX.exec(dateTimeString);
if (result == null) {
throw new Error("Unexpected date string: ".concat(dateTimeString));
}
var [, year, , month, , date, , hours, , minutes, , seconds, , nanos, overflow] = result;
if (!allowOverflow && overflow != null && overflow.length > 0) {
throw new Error("Unexpected characters after date string '".concat(dateTimeString, "': ").concat(overflow));
}
var dateParts = {
year,
month,
date,
hours,
minutes,
seconds,
nanos
};
return allowOverflow ? _objectSpread(_objectSpread({}, dateParts), {}, {
overflow
}) : dateParts;
}
/**
* Parses the date range provided from a string of text.
* @param text The string to parse the date from. Can be a keyword like "today", or in the format "2018-08-04"
* @param timeZone The time zone to parse this range in. E.g. America/New_York
* @returns A tuple with the start and end value/null for that date range, or both null
*/
static parseDateRange(dh, text, timeZone) {
var cleanText = text.trim().toLowerCase();
if (cleanText.length === 0) {
throw new Error("Cannot parse date range from empty string");
}
if (cleanText === "null") {
return [null, null];
}
if (cleanText === "today") {
var now = new Date(Date.now());
var _startDate = DateUtils.makeDateWrapper(dh, timeZone, now.getFullYear(), now.getMonth(), now.getDate());
var tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
var _endDate = DateUtils.makeDateWrapper(dh, timeZone, tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate());
return [_startDate, _endDate];
}
if (cleanText === "yesterday") {
var _now = new Date(Date.now());
var yesterday = new Date(_now.getFullYear(), _now.getMonth(), _now.getDate() - 1);
var _startDate2 = DateUtils.makeDateWrapper(dh, timeZone, yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate());
var _endDate2 = DateUtils.makeDateWrapper(dh, timeZone, _now.getFullYear(), _now.getMonth(), _now.getDate());
return [_startDate2, _endDate2];
}
if (cleanText === "now") {
var _now2 = new Date(Date.now());
var date = dh.DateWrapper.ofJsDate(_now2);
return [date, null];
}
var components2 = DateUtils.parseDateTimeString(cleanText);
if (components2.year == null && components2.month == null && components2.date == null) {
throw new Error("Unable to extract year, month, or day ".concat(cleanText));
}
var values = DateUtils.parseDateValues(components2.year, components2.month, components2.date, components2.hours, components2.minutes, components2.seconds, components2.nanos);
if (values == null) {
throw new Error("Unable to extract date values from ".concat(components2));
}
var startDate = DateUtils.makeDateWrapper(dh, timeZone, values.year, values.month, values.date, values.hours, values.minutes, values.seconds, values.nanos);
var endDate = DateUtils.getNextDate(dh, components2, values, timeZone);
return [startDate, endDate];
}
/**
* Gets the Js Date object from the provided DateWrapper.
* In unit test, DateWrapper is just a number provided in millis, so handles that case.
* @param dateWrapper The DateWrapper object, or time in millis
*/
static getJsDate(dateWrapper) {
if (typeof dateWrapper === "number") {
return new Date(dateWrapper);
}
return dateWrapper.asDate();
}
/**
* Trim overflow (usually timezone) from a date time string.
* @param dateTimeString The date time string to trim
* @returns The date time string without overflow
*/
static trimDateTimeStringTimeZone(dateTimeString) {
var {
overflow = ""
} = DateUtils.parseDateTimeString(dateTimeString, true);
if (overflow === "") {
return dateTimeString;
}
if (!/^\s[A-Za-z]+/.test(overflow)) {
throw new Error("Unexpected timezone format in overflow: '".concat(dateTimeString, "'"));
}
return dateTimeString.slice(0, -overflow.length);
}
}
_defineProperty$5(DateUtils, "FULL_DATE_FORMAT", "yyyy-MM-dd HH:mm:ss.SSSSSSSSS");
_defineProperty$5(DateUtils, "months", ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]);
const DateUtils$1 = DateUtils;
function createFilterConditionFactory(columnNames, createColumnCondition) {
var conditionOperator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "or";
return function filterConditionFactory(maybeTable) {
var maybeColumns = maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.findColumns(typeof columnNames === "string" ? [columnNames] : columnNames);
if (maybeColumns == null || maybeColumns.length === 0) {
return null;
}
var filterConditions = maybeColumns.map(createColumnCondition);
return filterConditions.reduce((current, next) => current[conditionOperator](next));
};
}
function createValueFilter(tableUtils, columnNames, value, operator) {
return createFilterConditionFactory(columnNames, (col) => col.filter()[operator](tableUtils.makeFilterValue(col.type, value)), "or");
}
function _defineProperty$4(obj, key, value) {
key = _toPropertyKey$4(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$4(arg) {
var key = _toPrimitive$4(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$4(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
class Operator {
}
_defineProperty$4(Operator, "not", "not");
_defineProperty$4(Operator, "and", "and");
_defineProperty$4(Operator, "or", "or");
function _defineProperty$3(obj, key, value) {
key = _toPropertyKey$3(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _toPropertyKey$3(arg) {
var key = _toPrimitive$3(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive$3(input, hint) {
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
class Type {
}
_defineProperty$3(Type, "eq", "eq");
_defineProperty$3(Type, "eqIgnoreCase", "eqIgnoreCase");
_defineProperty$3(Type, "notEq", "notEq");
_defineProperty$3(Type, "notEqIgnoreCase", "notEqIgnoreCase");
_defineProperty$3(Type, "greaterThan", "greaterThan");
_defineProperty$3(Type, "greaterThanOrEqualTo", "greaterThanOrEqualTo");
_defineProperty$3(Type, "lessThan", "lessThan");
_defineProperty$3(Type, "lessThanOrEqualTo", "lessThanOrEqualTo");
_defineProperty$3(Type, "in", "in");
_defineProperty$3(Type, "inIgnoreCase", "inIgnoreCase");
_defineProperty$3(Type, "notIn", "notIn");
_defineProperty$3(Type, "notInIgnoreCase", "notInIgnoreCase");
_defineProperty$3(Type, "isTrue", "isTrue");
_defineProperty$3(Type, "isFalse", "isFalse");
_defineProperty$3(Type, "isNull", "isNull");
_defineProperty$3(Type, "invoke", "invoke");
_defineProperty$3(Type, "contains", "contains");
_defineProperty$3(Type, "notContains", "notContains");
_defineProperty$3(Type, "containsIgnoreCase", "containsIgnoreCase");
_defineProperty$3(Type, "startsWith", "startsWith");
_defineProperty$3(Type, "endsWith", "endsWith");
_defineProperty$3(Type, "containsAny", "containsAny");
Log.module("ViewportDataUtils");
function getSize(table) {
return table == null || isClosed(table) ? 0 : table.size;
}
function isClosed(table) {
if ("isClosed" in table) {
return table.isClosed;
}
return false;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(void 0);
});
};
}
function _defineProperty$2(obj, key, value) {
key = _toPropertyKey$2(key)