@finos/perspective-viewer
Version:
The `<perspective-viewer>` Custom Element, frontend for Perspective.js
1,525 lines (1,445 loc) • 147 kB
JavaScript
import { ClipboardItem } from './snippets/perspective-viewer-937ec4dd94bcc2fe/inline0.js';
import { IntersectionObserver } from './snippets/perspective-viewer-937ec4dd94bcc2fe/inline1.js';
import { ResizeObserver } from './snippets/perspective-viewer-937ec4dd94bcc2fe/inline2.js';
import { bootstrap } from './snippets/perspective-viewer-937ec4dd94bcc2fe/inline3.js';
import { psp } from './snippets/perspective-viewer-937ec4dd94bcc2fe/inline4.js';
let wasm;
const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
let WASM_VECTOR_LEN = 0;
let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
const encodeString = function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
};
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
let cachedDataViewMemory0 = null;
function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function handleError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
wasm.__wbindgen_export_2(addHeapObject(e));
}
}
function isLikeNone(x) {
return x === undefined || x === null;
}
function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function getArrayJsValueFromWasm0(ptr, len) {
ptr = ptr >>> 0;
const mem = getDataViewMemory0();
const result = [];
for (let i = ptr; i < ptr + 4 * len; i += 4) {
result.push(takeObject(mem.getUint32(i, true)));
}
return result;
}
function getArrayU8FromWasm0(ptr, len) {
ptr = ptr >>> 0;
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
}
const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(state => {
wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b)
});
function makeClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
// First up with a closure we increment the internal reference
// count. This ensures that the Rust closure environment won't
// be deallocated while we're invoking it.
state.cnt++;
try {
return f(state.a, state.b, ...args);
} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b);
state.a = 0;
CLOSURE_DTORS.unregister(state);
}
}
};
real.original = state;
CLOSURE_DTORS.register(real, state, state);
return real;
}
function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
// First up with a closure we increment the internal reference
// count. This ensures that the Rust closure environment won't
// be deallocated while we're invoking it.
state.cnt++;
const a = state.a;
state.a = 0;
try {
return f(a, state.b, ...args);
} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_4.get(state.dtor)(a, state.b);
CLOSURE_DTORS.unregister(state);
} else {
state.a = a;
}
}
};
real.original = state;
CLOSURE_DTORS.register(real, state, state);
return real;
}
function debugString(val) {
// primitive types
const type = typeof val;
if (type == 'number' || type == 'boolean' || val == null) {
return `${val}`;
}
if (type == 'string') {
return `"${val}"`;
}
if (type == 'symbol') {
const description = val.description;
if (description == null) {
return 'Symbol';
} else {
return `Symbol(${description})`;
}
}
if (type == 'function') {
const name = val.name;
if (typeof name == 'string' && name.length > 0) {
return `Function(${name})`;
} else {
return 'Function';
}
}
// objects
if (Array.isArray(val)) {
const length = val.length;
let debug = '[';
if (length > 0) {
debug += debugString(val[0]);
}
for(let i = 1; i < length; i++) {
debug += ', ' + debugString(val[i]);
}
debug += ']';
return debug;
}
// Test for built-in
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches && builtInMatches.length > 1) {
className = builtInMatches[1];
} else {
// Failed to match the standard '[object ClassName]'
return toString.call(val);
}
if (className == 'Object') {
// we're a user defined class or Object
// JSON.stringify avoids problems with cycles, and is generally much
// easier than looping through ownProperties of `val`.
try {
return 'Object(' + JSON.stringify(val) + ')';
} catch (_) {
return 'Object';
}
}
// errors
if (val instanceof Error) {
return `${val.name}: ${val.message}\n${val.stack}`;
}
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}
function _assertClass(instance, klass) {
if (!(instance instanceof klass)) {
throw new Error(`expected instance of ${klass.name}`);
}
}
function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
const mem = getDataViewMemory0();
for (let i = 0; i < array.length; i++) {
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
}
WASM_VECTOR_LEN = array.length;
return ptr;
}
/**
* Register a plugin globally.
* @param {string} name
*/
export function registerPlugin(name) {
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
const len0 = WASM_VECTOR_LEN;
wasm.registerPlugin(ptr0, len0);
}
/**
* Register this crate's Custom Elements in the browser's current session.
*
* This must occur before calling any public API methods on these Custom
* Elements from JavaScript, as the methods themselves won't be defined yet.
* By default, this crate does not register `PerspectiveViewerElement` (as to
* preserve backwards-compatible synchronous API).
*/
export function init() {
wasm.init();
}
let stack_pointer = 128;
function addBorrowedObject(obj) {
if (stack_pointer == 1) throw new Error('out of js stack');
heap[--stack_pointer] = obj;
return stack_pointer;
}
function __wbg_adapter_52(arg0, arg1, arg2) {
wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_57(arg0, arg1, arg2) {
wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_60(arg0, arg1) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.__wbindgen_export_7(retptr, arg0, arg1);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
function __wbg_adapter_65(arg0, arg1) {
const ret = wasm.__wbindgen_export_8(arg0, arg1);
return takeObject(ret);
}
function __wbg_adapter_68(arg0, arg1, arg2) {
try {
wasm.__wbindgen_export_9(arg0, arg1, addBorrowedObject(arg2));
} finally {
heap[stack_pointer++] = undefined;
}
}
function __wbg_adapter_71(arg0, arg1) {
wasm.__wbindgen_export_10(arg0, arg1);
}
function __wbg_adapter_74(arg0, arg1, arg2) {
wasm.__wbindgen_export_11(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_736(arg0, arg1, arg2, arg3) {
wasm.__wbindgen_export_12(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}
const __wbindgen_enum_ShadowRootMode = ["open", "closed"];
const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0, 1));
/**
* An instance of a [`Client`] is a connection to a single
* `perspective_server::Server`, whether locally in-memory or remote over some
* transport like a WebSocket.
*
* The browser and node.js libraries both support the `websocket(url)`
* constructor, which connects to a remote `perspective_server::Server`
* instance over a WebSocket transport.
*
* In the browser, the `worker()` constructor creates a new Web Worker
* `perspective_server::Server` and returns a [`Client`] connected to it.
*
* In node.js, a pre-instantied [`Client`] connected synhronously to a global
* singleton `perspective_server::Server` is the default module export.
*
* # JavaScript Examples
*
* Create a Web Worker `perspective_server::Server` in the browser and return a
* [`Client`] instance connected for it:
*
* ```javascript
* import perspective from "@finos/perspective";
* const client = await perspective.worker();
* ```
*
* Create a WebSocket connection to a remote `perspective_server::Server`:
*
* ```javascript
* import perspective from "@finos/perspective";
* const client = await perspective.websocket("ws://locahost:8080/ws");
* ```
*
* Access the synchronous client in node.js:
*
* ```javascript
* import { default as client } from "@finos/perspective";
* ```
*/
export class Client {
static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(Client.prototype);
obj.__wbg_ptr = ptr;
ClientFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ClientFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_client_free(ptr, 0);
}
/**
* @returns {string}
*/
__getClassname() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.client___getClassname(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
deferred1_0 = r0;
deferred1_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
}
}
/**
* @param {Function} send_request
* @param {Function | null} [close]
*/
constructor(send_request, close) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.client_new(retptr, addHeapObject(send_request), isLikeNone(close) ? 0 : addHeapObject(close));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
if (r2) {
throw takeObject(r1);
}
this.__wbg_ptr = r0 >>> 0;
ClientFinalization.register(this, this.__wbg_ptr, this);
return this;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {Function} on_response
* @returns {ProxySession}
*/
new_proxy_session(on_response) {
try {
const ret = wasm.client_new_proxy_session(this.__wbg_ptr, addBorrowedObject(on_response));
return ProxySession.__wrap(ret);
} finally {
heap[stack_pointer++] = undefined;
}
}
/**
* @returns {Promise<void>}
*/
init() {
const ret = wasm.client_init(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @param {any} value
* @returns {Promise<void>}
*/
handle_response(value) {
const ret = wasm.client_handle_response(this.__wbg_ptr, addHeapObject(value));
return takeObject(ret);
}
/**
* @param {string} error
* @param {Function | null} [reconnect]
* @returns {Promise<void>}
*/
handle_error(error, reconnect) {
const ptr0 = passStringToWasm0(error, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.client_handle_error(this.__wbg_ptr, ptr0, len0, isLikeNone(reconnect) ? 0 : addHeapObject(reconnect));
return takeObject(ret);
}
/**
* @param {Function} callback
* @returns {Promise<number>}
*/
on_error(callback) {
const ret = wasm.client_on_error(this.__wbg_ptr, addHeapObject(callback));
return takeObject(ret);
}
/**
* Creates a new [`Table`] from either a _schema_ or _data_.
*
* The [`Client::table`] factory function can be initialized with either a
* _schema_ (see [`Table::schema`]), or data in one of these formats:
*
* - Apache Arrow
* - CSV
* - JSON row-oriented
* - JSON column-oriented
* - NDJSON
*
* When instantiated with _data_, the schema is inferred from this data.
* While this is convenient, inferrence is sometimes imperfect e.g.
* when the input is empty, null or ambiguous. For these cases,
* [`Client::table`] can first be instantiated with a explicit schema.
*
* When instantiated with a _schema_, the resulting [`Table`] is empty but
* with known column names and column types. When subsqeuently
* populated with [`Table::update`], these columns will be _coerced_ to
* the schema's type. This behavior can be useful when
* [`Client::table`]'s column type inferences doesn't work.
*
* The resulting [`Table`] is _virtual_, and invoking its methods
* dispatches events to the `perspective_server::Server` this
* [`Client`] connects to, where the data is stored and all calculation
* occurs.
*
* # Arguments
*
* - `arg` - Either _schema_ or initialization _data_.
* - `options` - Optional configuration which provides one of:
* - `limit` - The max number of rows the resulting [`Table`] can
* store.
* - `index` - The column name to use as an _index_ column. If this
* `Table` is being instantiated by _data_, this column name must be
* present in the data.
* - `name` - The name of the table. This will be generated if it is
* not provided.
* - `format` - The explicit format of the input data, can be one of
* `"json"`, `"columns"`, `"csv"` or `"arrow"`. This overrides
* language-specific type dispatch behavior, which allows stringified
* and byte array alternative inputs.
*
* # JavaScript Examples
*
* Load a CSV from a `string`:
*
* ```javascript
* const table = await client.table("x,y\n1,2\n3,4");
* ```
*
* Load an Arrow from an `ArrayBuffer`:
*
* ```javascript
* import * as fs from "node:fs/promises";
* const table2 = await client.table(await fs.readFile("superstore.arrow"));
* ```
*
* Load a CSV from a `UInt8Array` (the default for this type is Arrow)
* using a format override:
*
* ```javascript
* const enc = new TextEncoder();
* const table = await client.table(enc.encode("x,y\n1,2\n3,4"), {
* format: "csv",
* });
* ```
*
* Create a table with an `index`:
*
* ```javascript
* const table = await client.table(data, { index: "Row ID" });
* ```
* @param {string | ArrayBuffer | Record<string, unknown[]> | Record<string, unknown>[]} value
* @param {TableInitOptions | null} [options]
* @returns {Promise<Table>}
*/
table(value, options) {
const ret = wasm.client_table(this.__wbg_ptr, addHeapObject(value), isLikeNone(options) ? 0 : addHeapObject(options));
return takeObject(ret);
}
/**
* Terminates this [`Client`], cleaning up any [`crate::View`] handles the
* [`Client`] has open as well as its callbacks.
* @returns {any}
*/
terminate() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.client_terminate(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Opens a [`Table`] that is hosted on the `perspective_server::Server`
* that is connected to this [`Client`].
*
* The `name` property of [`TableInitOptions`] is used to identify each
* [`Table`]. [`Table`] `name`s can be looked up for each [`Client`]
* via [`Client::get_hosted_table_names`].
*
* # JavaScript Examples
*
* Get a virtual [`Table`] named "table_one" from this [`Client`]
*
* ```javascript
* const tables = await client.open_table("table_one");
* ```
* @param {string} entity_id
* @returns {Promise<Table>}
*/
open_table(entity_id) {
const ptr0 = passStringToWasm0(entity_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.client_open_table(this.__wbg_ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Retrieves the names of all tables that this client has access to.
*
* `name` is a string identifier unique to the [`Table`] (per [`Client`]),
* which can be used in conjunction with [`Client::open_table`] to get
* a [`Table`] instance without the use of [`Client::table`]
* constructor directly (e.g., one created by another [`Client`]).
*
* # JavaScript Examples
*
* ```javascript
* const tables = await client.get_hosted_table_names();
* ```
* @returns {Promise<any>}
*/
get_hosted_table_names() {
const ret = wasm.client_get_hosted_table_names(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Register a callback which is invoked whenever [`Client::table`] (on this
* [`Client`]) or [`Table::delete`] (on a [`Table`] belinging to this
* [`Client`]) are called.
* @param {Function} on_update_js
* @returns {Promise<number>}
*/
on_hosted_tables_update(on_update_js) {
const ret = wasm.client_on_hosted_tables_update(this.__wbg_ptr, addHeapObject(on_update_js));
return takeObject(ret);
}
/**
* Remove a callback previously registered via
* `Client::on_hosted_tables_update`.
* @param {number} update_id
* @returns {Promise<void>}
*/
remove_hosted_tables_update(update_id) {
const ret = wasm.client_remove_hosted_tables_update(this.__wbg_ptr, update_id);
return takeObject(ret);
}
/**
* Provides the [`SystemInfo`] struct, implementation-specific metadata
* about the [`perspective_server::Server`] runtime such as Memory and
* CPU usage.
*
* For WebAssembly servers, this method includes the WebAssembly heap size.
*
* # JavaScript Examples
*
* ```javascript
* const info = await client.system_info();
* ```
* @returns {Promise<SystemInfo>}
*/
system_info() {
const ret = wasm.client_system_info(this.__wbg_ptr);
return takeObject(ret);
}
}
const ColumnDropDownElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_columndropdownelement_free(ptr >>> 0, 1));
export class ColumnDropDownElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ColumnDropDownElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_columndropdownelement_free(ptr, 0);
}
}
const CopyDropDownMenuElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_copydropdownmenuelement_free(ptr >>> 0, 1));
export class CopyDropDownMenuElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
CopyDropDownMenuElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_copydropdownmenuelement_free(ptr, 0);
}
/**
* @param {HTMLElement} elem
*/
constructor(elem) {
const ret = wasm.copydropdownmenuelement_new(addHeapObject(elem));
this.__wbg_ptr = ret >>> 0;
CopyDropDownMenuElementFinalization.register(this, this.__wbg_ptr, this);
return this;
}
/**
* @param {HTMLElement} target
*/
open(target) {
wasm.copydropdownmenuelement_open(this.__wbg_ptr, addHeapObject(target));
}
hide() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.copydropdownmenuelement_hide(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Internal Only.
*
* Set this custom element model's raw pointer.
* @param {PerspectiveViewerElement} parent
*/
set_model(parent) {
_assertClass(parent, PerspectiveViewerElement);
wasm.copydropdownmenuelement_set_model(this.__wbg_ptr, parent.__wbg_ptr);
}
connected_callback() {
wasm.copydropdownmenuelement_connected_callback(this.__wbg_ptr);
}
}
const ExportDropDownMenuElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_exportdropdownmenuelement_free(ptr >>> 0, 1));
export class ExportDropDownMenuElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ExportDropDownMenuElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_exportdropdownmenuelement_free(ptr, 0);
}
/**
* @param {HTMLElement} elem
*/
constructor(elem) {
const ret = wasm.copydropdownmenuelement_new(addHeapObject(elem));
this.__wbg_ptr = ret >>> 0;
ExportDropDownMenuElementFinalization.register(this, this.__wbg_ptr, this);
return this;
}
/**
* @param {HTMLElement} target
*/
open(target) {
wasm.exportdropdownmenuelement_open(this.__wbg_ptr, addHeapObject(target));
}
hide() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.exportdropdownmenuelement_hide(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Internal Only.
*
* Set this custom element model's raw pointer.
* @param {PerspectiveViewerElement} parent
*/
set_model(parent) {
_assertClass(parent, PerspectiveViewerElement);
wasm.exportdropdownmenuelement_set_model(this.__wbg_ptr, parent.__wbg_ptr);
}
connected_callback() {
wasm.copydropdownmenuelement_connected_callback(this.__wbg_ptr);
}
}
const FilterDropDownElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_filterdropdownelement_free(ptr >>> 0, 1));
export class FilterDropDownElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
FilterDropDownElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_filterdropdownelement_free(ptr, 0);
}
}
const FunctionDropDownElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_functiondropdownelement_free(ptr >>> 0, 1));
export class FunctionDropDownElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
FunctionDropDownElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_functiondropdownelement_free(ptr, 0);
}
}
const PerspectiveDebugPluginElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_perspectivedebugpluginelement_free(ptr >>> 0, 1));
/**
* The `<perspective-viewer-plugin>` element.
*
* The default perspective plugin which is registered and activated
* automcatically when a `<perspective-viewer>` is loaded without plugins.
* While you will not typically instantiate this class directly, it is simple
* enough to function as a good "default" plugin implementation which can be
* extended to create custom plugins.
*
* # Example
* ```javascript
* class MyPlugin extends customElements.get("perspective-viewer-plugin") {
* // Custom plugin overrides
* }
* ```
*/
export class PerspectiveDebugPluginElement {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
PerspectiveDebugPluginElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_perspectivedebugpluginelement_free(ptr, 0);
}
/**
* @param {HTMLElement} elem
*/
constructor(elem) {
const ret = wasm.perspectivedebugpluginelement_new(addHeapObject(elem));
this.__wbg_ptr = ret >>> 0;
PerspectiveDebugPluginElementFinalization.register(this, this.__wbg_ptr, this);
return this;
}
/**
* @returns {string}
*/
get name() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.perspectivedebugpluginelement_name(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
deferred1_0 = r0;
deferred1_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {string}
*/
get select_mode() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.perspectivedebugpluginelement_select_mode(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
deferred1_0 = r0;
deferred1_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {any}
*/
get min_config_columns() {
const ret = wasm.perspectivedebugpluginelement_config_column_names(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {any}
*/
get config_column_names() {
const ret = wasm.perspectivedebugpluginelement_config_column_names(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @param {View} view
* @returns {Promise<any>}
*/
update(view) {
_assertClass(view, View);
const ret = wasm.perspectivedebugpluginelement_draw(this.__wbg_ptr, view.__wbg_ptr);
return takeObject(ret);
}
/**
* # Notes
*
* When you pass a `wasm_bindgen` wrapped type _into_ Rust, it acts like a
* move. Ergo, if you replace the `&` in the `view` argument, the JS copy
* of the `View` will be invalid
* @param {View} view
* @returns {Promise<any>}
*/
draw(view) {
_assertClass(view, View);
const ret = wasm.perspectivedebugpluginelement_draw(this.__wbg_ptr, view.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
clear() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
resize() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
restyle() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
save() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
restore() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
delete() {
const ret = wasm.perspectivedebugpluginelement_clear(this.__wbg_ptr);
return takeObject(ret);
}
connectedCallback() {
wasm.perspectivedebugpluginelement_connectedCallback(this.__wbg_ptr);
}
}
const PerspectiveViewerElementFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_perspectiveviewerelement_free(ptr >>> 0, 1));
/**
* The `<perspective-viewer>` custom element.
*
* # JavaScript Examples
*
* Create a new `<perspective-viewer>`:
*
* ```javascript
* const viewer = document.createElement("perspective-viewer");
* window.body.appendChild(viewer);
* ```
*/
export class PerspectiveViewerElement {
static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(PerspectiveViewerElement.prototype);
obj.__wbg_ptr = ptr;
PerspectiveViewerElementFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
PerspectiveViewerElementFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_perspectiveviewerelement_free(ptr, 0);
}
/**
* @param {HTMLElement} elem
*/
constructor(elem) {
const ret = wasm.perspectiveviewerelement_new(addHeapObject(elem));
this.__wbg_ptr = ret >>> 0;
PerspectiveViewerElementFinalization.register(this, this.__wbg_ptr, this);
return this;
}
connectedCallback() {
wasm.perspectiveviewerelement_connectedCallback(this.__wbg_ptr);
}
/**
* Loads a [`Table`] (or rather, a Javascript `Promise` which returns a
* [`Table`]) in this viewer.
*
* When [`PerspectiveViewerElement::load`] resolves, the first frame of the
* UI + visualization is guaranteed to have been drawn. Awaiting the result
* of this method in a `try`/`catch` block will capture any errors
* thrown during the loading process, or from the [`Table`] `Promise`
* itself.
*
* A [`Table`] can be created using the
* [`@finos/perspective`](https://www.npmjs.com/package/@finos/perspective)
* library from NPM (see [`perspective_js`] documentation for details).
*
* # JavaScript Examples
*
* ```javascript
* import perspective from "@finos/perspective";
*
* const worker = await perspective.worker();
* viewer.load(worker.table("x,y\n1,2"));
* ```
* @param {any} table
* @returns {Promise<any>}
*/
load(table) {
const ret = wasm.perspectiveviewerelement_load(this.__wbg_ptr, addHeapObject(table));
return takeObject(ret);
}
/**
* Delete the internal [`View`] and all associated state, rendering this
* `<perspective-viewer>` unusable and freeing all associated resources.
* Does not delete the supplied [`Table`] (as this is constructed by the
* callee).
*
* Calling _any_ method on a `<perspective-viewer>` after [`Self::delete`]
* will throw.
*
* <div class="warning">
*
* Allowing a `<perspective-viewer>` to be garbage-collected
* without calling [`PerspectiveViewerElement::delete`] will leak WASM
* memory!
*
* </div>
*
* # JavaScript Examples
*
* ```javascript
* await viewer.delete();
* ```
* @returns {Promise<any>}
*/
delete() {
const ptr = this.__destroy_into_raw();
const ret = wasm.perspectiveviewerelement_delete(ptr);
return takeObject(ret);
}
/**
* Restart this `<perspective-viewer>` to its initial state, before
* `load()`.
*
* Use `Self::restart` if you plan to call `Self::load` on this viewer
* again, or alternatively `Self::delete` if this viewer is no longer
* needed.
* @returns {Promise<any>}
*/
eject() {
const ret = wasm.perspectiveviewerelement_eject(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Get the underlying [`View`] for this viewer.
*
* Use this method to get promgrammatic access to the [`View`] as currently
* configured by the user, for e.g. serializing as an
* [Apache Arrow](https://arrow.apache.org/) before passing to another
* library.
*
* The [`View`] returned by this method is owned by the
* [`PerspectiveViewerElement`] and may be _invalidated_ by
* [`View::delete`] at any time. Plugins which rely on this [`View`] for
* their [`HTMLPerspectiveViewerPluginElement::draw`] implementations
* should treat this condition as a _cancellation_ by silently aborting on
* "View already deleted" errors from method calls.
*
* # JavaScript Examples
*
* ```javascript
* const view = await viewer.getView();
* ```
* @returns {Promise<any>}
*/
getView() {
const ret = wasm.perspectiveviewerelement_getView(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Get the underlying [`Table`] for this viewer (as passed to
* [`PerspectiveViewerElement::load`]).
*
* # Arguments
*
* - `wait_for_table` - whether to wait for
* [`PerspectiveViewerElement::load`] to be called, or fail immediately
* if [`PerspectiveViewerElement::load`] has not yet been called.
*
* # JavaScript Examples
*
* ```javascript
* const table = await viewer.getTable();
* ```
* @param {boolean | null} [wait_for_table]
* @returns {Promise<any>}
*/
getTable(wait_for_table) {
const ret = wasm.perspectiveviewerelement_getTable(this.__wbg_ptr, isLikeNone(wait_for_table) ? 0xFFFFFF : wait_for_table ? 1 : 0);
return takeObject(ret);
}
/**
* Get render statistics. Some fields of the returned stats object are
* relative to the last time [`PerspectiveViewerElement::getRenderStats`]
* was called, ergo calling this method resets these fields.
*
* # JavaScript Examples
*
* ```javascript
* const {virtual_fps, actual_fps} = await viewer.getRenderStats();
* ```
* @returns {any}
*/
getRenderStats() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.perspectiveviewerelement_getRenderStats(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Flush any pending modifications to this `<perspective-viewer>`. Since
* `<perspective-viewer>`'s API is almost entirely `async`, it may take
* some milliseconds before any user-initiated changes to the [`View`]
* affects the rendered element. If you want to make sure all pending
* actions have been rendered, call and await [`Self::flush`].
*
* [`Self::flush`] will resolve immediately if there is no [`Table`] set.
*
* # JavaScript Examples
*
* In this example, [`Self::restore`] is called without `await`, but the
* eventual render which results from this call can still be awaited by
* immediately awaiting [`Self::flush`] instead.
*
* ```javascript
* viewer.restore(config);
* await viewer.flush();
* ```
* @returns {Promise<any>}
*/
flush() {
const ret = wasm.perspectiveviewerelement_flush(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Restores this element from a full/partial
* [`perspective_js::JsViewConfig`].
*
* One of the best ways to use [`Self::restore`] is by first configuring
* a `<perspective-viewer>` as you wish, then using either the `Debug`
* panel or "Copy" -> "config.json" from the toolbar menu to snapshot
* the [`Self::restore`] argument as JSON.
*
* # Arguments
*
* - `update` - The config to restore to, as returned by [`Self::save`] in
* either "json", "string" or "arraybuffer" format.
*
* # JavaScript Examples
*
* Apply a `group_by` to the current [`View`], without modifying/resetting
* other fields:
*
* ```javascript
* await viewer.restore({group_by: ["State"]});
* ```
* @param {any} update
* @returns {Promise<any>}
*/
restore(update) {
const ret = wasm.perspectiveviewerelement_restore(this.__wbg_ptr, addHeapObject(update));
return takeObject(ret);
}
/**
* @returns {Promise<any>}
*/
resetError() {
const ret = wasm.perspectiveviewerelement_resetError(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Save this element to serialized state object, one which can be restored
* via the [`Self::restore`] method.
*
* # Arguments
*
* - `format` - Supports "json" (default), "arraybuffer" or "string".
*
* # JavaScript Examples
*
* Get the current `group_by` setting:
*
* ```javascript
* const {group_by} = await viewer.restore();
* ```
*
* Reset workflow attached to an external button `myResetButton`:
*
* ```javascript
* const token = await viewer.save();
* myResetButton.addEventListener("clien", async () => {
* await viewer.restore(token);
* });
* ```
* @param {string | null} [format]
* @returns {Promise<any>}
*/
save(format) {
var ptr0 = isLikeNone(format) ? 0 : passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
var len0 = WASM_VECTOR_LEN;
const ret = wasm.perspectiveviewerelement_save(this.__wbg_ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Download this viewer's internal [`View`] data as a `.csv` file.
*
* # Arguments
*
* - `flat` - Whether to use the current [`perspective_js::JsViewConfig`]
* to generate this data, or use the default.
*
* # JavaScript Examples
*
* ```javascript
* myDownloadButton.addEventListener("click", async () => {
* await viewer.download();
* })
* ```
* @param {boolean | null} [flat]
* @returns {Promise<any>}
*/
download(flat) {
const ret = wasm.perspectiveviewerelement_download(this.__wbg_ptr, isLikeNone(flat) ? 0xFFFFFF : flat ? 1 : 0);
return takeObject(ret);
}
/**
* Copy this viewer's `View` or `Table` data as CSV to the system
* clipboard.
*
* # Arguments
*
* - `method` - The `ExportMethod` (serialized as a `String`) to use to
* render the data to the Clipboard.
*
* # JavaScript Examples
*
* ```javascript
* myDownloadButton.addEventListener("click", async () => {
* await viewer.copy();
* })
* ```
* @param {string | null} [method]
* @returns {Promise<any>}
*/
copy(method) {
const ret = wasm.perspectiveviewerelement_copy(this.__wbg_ptr, isLikeNone(method) ? 0 : addHeapObject(method));
return takeObject(ret);
}
/**
* Reset the viewer's `ViewerConfig` to the default.
*
* # Arguments
*
* - `reset_all` - If set, will clear expressions and column settings as
* well.
*
* # JavaScript Examples
*
* ```javascript
* await viewer.reset();
* ```
* @param {boolean | null} [reset_all]
* @returns {Promise<any>}
*/
reset(reset_all) {
const ret = wasm.perspectiveviewerelement_reset(this.__wbg_ptr, isLikeNone(reset_all) ? 0xFFFFFF : reset_all ? 1 : 0);
return takeObject(ret);
}
/**
* Recalculate the viewer's dimensions and redraw.
*
* Use this method to tell `<perspective-viewer>` its dimensions have
* changed when auto-size mode has been disabled via [`Self::setAutoSize`].
* [`Self::resize`] resolves when the resize-initiated redraw of this
* element has completed.
*
* # Arguments
*
* - `force` - If [`Self::resize`] is called with `false` or without an
* argument, and _auto-size_ mode is enabled via [`Self::setAutoSize`],
* [`Self::resize`] will log a warning and auto-disable auto-size mode.
*
* # JavaScript Examples
*
* ```javascript
* await viewer.resize(true)
* ```
* @param {boolean | null} [force]
* @returns {Promise<any>}
*/
resize(force) {
const ret = wasm.perspectiveviewerelement_resize(this.__wbg_ptr, isLikeNone(force) ? 0xFFFFFF : force ? 1 : 0);
return takeObject(ret);
}
/**
* Sets the auto-size behavior of this component.
*
* When `true`, this `<perspective-viewer>` will register a
* `ResizeObserver` on itself and call [`Self::resize`] whenever its own
* dimensions change. However, when embedded in a larger application
* context, you may want to call [`Self::resize`] manually to avoid
* over-rendering; in this case auto-sizing can be disabled via this
* method. Auto-size behavior is enabled by default.
*
* # Arguments
*
* - `autosize` - Whether to enable `auto-size` behavior or not.
*
* # JavaScript Examples
*
* Disable auto-size behavior:
*
* ```javascript
* viewer.setAutoSize(false);
* ```
* @param {boolean} autosize
*/
setAutoSize(autosize) {
wasm.perspectiveviewerelement_setAutoSize(this.__wbg_ptr, autosize);
}
/**
* Sets the auto-pause behavior of this component.
*
* When `true`, this `<perspective-viewer>` will register an
* `IntersectionObserver` on itself and subsequently skip rendering
* whenever its viewport visibility changes. Auto-pause is enabled by
* default.
*
* # Arguments
*
* - `autopause` Whether to enable `auto-pause` behavior or not.
*
* # JavaScript Examples
*
* Disable auto-size behavior:
*
* ```javascript
* viewer.setAutoPause(false);
* ```
* @param {boolean} autopause
*/
setAutoPause(autopause) {
wasm.perspectiveviewerelement_setAutoPause(this.__wbg_ptr, autopause);
}
/**
* Return a [`perspective_js::JsViewWindow`] for the currently selected
* region.
* @returns {ViewWindow | undefined}
*/
getSelection() {
const ret = wasm.perspectiveviewerelement_getSelection(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Set the selection [`perspective_js::JsViewWindow`] for this element.
* @param {ViewWindow | null} [window]
*/
setSelection(window) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.perspectiveviewerelement_setSelection(retptr, this.__wbg_ptr, isLikeNone(window) ? 0 : addHeapObject(window));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Get this viewer's edit port for the currently loaded [`Table`] (see
* [`Table::update`] for details on ports).
* @returns {number}
*/
getEditPort() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.perspectiveviewerelement_getEditPort(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
if (r3) {
throw takeObject(r2);
}
return r0;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Restyle all plugins from current document.
*
* <div class="warning">
*
* [`Self::restyleElement`] _must_ be called for many runtime changes to
* CSS properties to be reflected in an already-rendered
* `<perspective-viewer>`.
*
* </div>
*
* # JavaScript Examples
*
* ```javascript
* viewer.style = "--icon--color: red";
* await viewer.restyleElement();
* ```
* @returns {Promise<any>}
*/
restyleElement() {
const ret = wasm.perspectiveviewerelement_restyleElement(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Set the available theme names available in the status bar UI.
*
* Calling