UNPKG

@finos/perspective-viewer

Version:

The `<perspective-viewer>` Custom Element, frontend for Perspective.js

3 lines (2 loc) 9.48 kB
var c=class extends HTMLElement{constructor(){super()}get name(){return"Debug"}get select_mode(){return"select"}get min_config_columns(){}get config_column_names(){}async update(t){return this.draw(t)}async draw(t){this.style.backgroundColor="#fff";let i=await t.to_csv(),r="margin:0;overflow:scroll;position:absolute;width:100%;height:100%";this.innerHTML=`<pre style='${r}'>${i}</pre>`}async clear(){this.innerHTML=""}async resize(){}async restyle(){}async save(){}async restore(){}async delete(){}};document.createElement("perspective-viewer-plugin").constructor===HTMLElement&&window.customElements.define("perspective-viewer-plugin",c);import{PerspectiveViewerElement as E,register_plugin as T}from"@finos/perspective-viewer/dist/pkg/perspective_viewer.js";import{Decompress as y}from"fflate";import b from"@finos/perspective-viewer/dist/pkg/perspective_viewer.js";import h from"@finos/perspective-viewer/dist/pkg/perspective_viewer_bg.wasm";window.addEventListener("unhandledrejection",e=>{e.reason?.message==="View method cancelled"&&e.preventDefault()});function u(e){return new Uint32Array(e.slice(0,4))[0]==559903}async function P(){let e=await h,t=[],i=0,r=new y(s=>{s&&(i+=s.byteLength,t.push(s))});if(e instanceof URL||typeof e=="string"){let l=(await fetch(e.toString())).body.getReader(),o=0;for(;;){let{value:m,done:g}=await l.read();if(g)break;o===0&&u(m.buffer)||o===1?(o=1,r.push(m,g)):(o=2,i+=m.byteLength,t.push(m))}}else if(e instanceof Uint8Array)u(e.buffer)?r.push(e,!0):(i=e.byteLength,t=[e]);else{let s=new Uint8Array(e);u(e)?r.push(s,!0):(i=s.byteLength,t=[s])}let n=0,a=new Uint8Array(i);for(let s of t)a.set(s,n),n+=s.byteLength;return await b(a)}var f=P();var p=class extends HTMLElement{constructor(){super();this.load_wasm()}async load_wasm(){await f,this.instance||(this.instance=new E(this))}async connectedCallback(){await this.load_wasm(),this.instance.connected_callback()}static async registerPlugin(t){await f,T(t)}async load(t){await this.load_wasm(),await this.instance.js_load(t)}async notifyResize(t=!1){await this.load_wasm(),await this.instance.js_resize(t)}async setAutoSize(t=!0){await this.load_wasm(),await this.instance.js_set_auto_size(t)}async getTable(t){return await this.load_wasm(),await this.instance.js_get_table(!!t)}async getView(){return await this.load_wasm(),await this.instance.js_get_view()}async restore(t){await this.load_wasm(),await this.instance.js_restore(t)}async save(t){return await this.load_wasm(),await this.instance.js_save(t)}async flush(){await this.load_wasm(),await this.instance.js_flush()}async reset(t=!1){await this.load_wasm(),await this.instance.js_reset(t)}async delete(){await this.load_wasm(),await this.instance.js_delete()}async download(t){await this.load_wasm(),await this.instance.js_download(t)}async copy(t){await this.load_wasm(),await this.instance.js_copy(t)}async restyleElement(){await this.load_wasm(),await this.instance.js_restyle_element()}async resetThemes(t){await this.load_wasm(),await this.instance.js_reset_themes(t)}async getEditPort(){return await this.load_wasm(),await this.instance.js_get_edit_port()}async setThrottle(t){await this.load_wasm(),await this.instance.js_set_throttle(t)}async toggleConfig(t){await this.load_wasm(),await this.instance.js_toggle_config(t)}async getPlugin(t){return await this.load_wasm(),await this.instance.js_get_plugin(t)}async getAllPlugins(){return await this.load_wasm(),await this.instance.js_get_all_plugins()}};document.createElement("perspective-viewer").constructor===HTMLElement&&window.customElements.define("perspective-viewer",p);function q(e,{warn:t=!0,replace_defaults:i=!1}={}){if(typeof e=="object"&&!(e instanceof ArrayBuffer)){let r=JSON.parse(JSON.stringify(e));return"viewers"in r&&"detail"in r?L(r,{warn:t,replace_defaults:i}):v(r,!1,{warn:t,replace_defaults:i})}else return e}function L(e,t){for(let i in e.viewers)e.viewers[i]=v(e.viewers[i],!0,t),"master"in e.viewers[i]||(e.viewers[i].master=!1,t.warn&&console.warn('Deprecated perspective missing attribute "master" set to default')),"linked"in e.viewers[i]||(e.viewers[i].linked=!1,t.warn&&console.warn('Deprecated perspective missing attribute "linked" set to default'));return e}function v(e,t,i){return M(e,[k,H,x,A,i.replace_defaults?V:!1,D,S,t?C:$].filter(r=>!!r),i)}function M(e,t,i){for(let r of t)e=r(e,i);return e}function V(e,t){for(let i of["group_by","split_by","filter","sort"])e[i]===null&&(e[i]=[],t.warn&&console.warn(`Deprecated perspective missing attribute "${i}" set to default"`)),"aggregates"in e&&e.aggregates===null&&(e.aggregates={},t.warn&&console.warn('Deprecated perspective missing attribute "aggregates" set to default"'));return e}function w(e,t){return function(i,r){let n=0;for(let a of t)if(a in i){if(n++>0)throw new Error(`Duplicate "${e}" fields`);i[e]=i[a],a!==e&&(delete i[a],r.warn&&console.warn(`Deprecated perspective attribute "${a}" renamed "${e}"`))}return i}}var k=w("group_by",["group_by","row_pivots","row-pivot","row-pivots","row_pivot"]),H=w("split_by",["split_by","column_pivots","column-pivot","column-pivots","column_pivot","col_pivots","col-pivot","col-pivots","col_pivot"]),x=w("filter",["filter","filters"]);function j(e,t,i,r,n){if(e.test(i)){let a=i.replace(e,t);n.warn&&console.warn(`Deprecated perspective "expression" attribute value "${i}" updated to "${a}"`);for(let s of["group_by","split_by"])if(s in r)for(let l in r[s])r[s][l]===i.replace(/"/g,"")&&(r[s][l]=a,n.warn&&console.warn(`Deprecated perspective expression in "${s}" attribute "${i}" replaced with "${a}"`));for(let s of r.filter||[])s[0]===i.replace(/"/g,"")&&(s[0]=a,n.warn&&console.warn(`Deprecated perspective expression in "filter" attribute "${i}" replaced with "${a}"`));for(let s of r.sort||[])s[0]===i.replace(/"/g,"")&&(s[0]=a,n.warn&&console.warn(`Deprecated perspective expression in "sort" attribute "${i}" replaced with "${a}"`));return a}else return i}function A(e,t){if(e["computed-columns"]){if("expressions"in e)throw new Error('Duplicate "expressions" and "computed-columns');e.expressions=e["computed-columns"],delete e["computed-columns"],t.warn&&console.warn('Deprecated perspective attribute "computed-columns" renamed "expressions"');let i=[[/^year_bucket\("(.+?)"\)/,`bucket("$1", 'y')`],[/^month_bucket\("(.+?)"\)/,`bucket("$1", 'M')`],[/^day_bucket\("(.+?)"\)/,`bucket("$1", 'd')`],[/^hour_bucket\("(.+?)"\)/,`bucket("$1", 'h')`],[/^minute_bucket\("(.+?)"\)/,`bucket("$1", 'm')`],[/^second_bucket\("(.+?)"\)/,`bucket("$1", 's')`]];for(let r in e.expressions){let n=e.expressions[r];for(let[a,s]of i)n=j(a,s,n,e,t);e.expressions[r]=n}}return e}function D(e,t){let i={datagrid:"Datagrid",Datagrid:"Datagrid",d3_y_area:"Y Area","Y Area":"Y Area",d3_y_line:"Y Line","Y Line":"Y Line",d3_xy_line:"X/Y Line","X/Y Line":"X/Y Line",d3_y_scatter:"Y Scatter","Y Scatter":"Y Scatter",d3_xy_scatter:"X/Y Scatter","X/Y Scatter":"X/Y Scatter",d3_x_bar:"X Bar","X Bar":"X Bar",d3_y_bar:"Y Bar","Y Bar":"Y Bar",d3_heatmap:"Heatmap",Heatmap:"Heatmap",d3_treemap:"Treemap",Treemap:"Treemap",d3_sunburst:"Sunburst",Sunburst:"Sunburst"};return"plugin"in e&&e.plugin!==i[e.plugin]&&(e.plugin=i[e.plugin],t.warn&&console.warn(`Deprecated perspective "plugin" attribute value "${e.plugin}" updated to "${i[e.plugin]}"`)),e}function S(e,t){if(e.plugin==="Datagrid"&&!!e.plugin_config&&!e.plugin_config.columns){t.warn&&console.warn('Deprecated perspective attribute "plugin_config" moved to "plugin_config.columns"');let i={};for(let r of Object.keys(e.plugin_config)){let n=e.plugin_config[r];delete e.plugin_config[r],typeof n.color_mode=="string"&&(n.number_color_mode=n.color_mode,delete n.color_mode,t.warn&&console.warn('Deprecated perspective attribute "color_mode" renamed "number_color_mode"')),i[r]=n}e.plugin_config.columns=i,t.replace_defaults&&(e.plugin_config.editable=!1,e.plugin_config.scroll_lock=!0)}return e}function $(e,t){let i=["editable","selectable","name","table","master","linked"];for(let r of i)r in e&&(delete e[r],t.warn&&console.warn(`Deprecated perspective attribute "${r}" removed`));return e}function C(e,t){let i=["editable","selectable","name","table","master","linked"];for(let r of i)r in e&&e[r]===null&&(delete e[r],t.warn&&console.warn(`Deprecated perspective attribute "${r}" removed`));return e}import{PerspectiveNumberColumnStyleElement as Y}from"@finos/perspective-viewer/dist/pkg/perspective_viewer.js";var d=class extends HTMLElement{constructor(){super()}async open(t,i,r){this.instance?this.instance.reset(i,r):this.instance=new Y(this,i,r),this.instance.open(t)}destroy(){this.instance.destroy()}};document.createElement("perspective-number-column-style").constructor===HTMLElement&&window.customElements.define("perspective-number-column-style",d);import{PerspectiveStringColumnStyleElement as B}from"@finos/perspective-viewer/dist/pkg/perspective_viewer.js";var _=class extends HTMLElement{constructor(){super()}async open(t,i,r){this.instance?this.instance.reset(i):this.instance=new B(this,i,r),this.instance.open(t)}destroy(){this.instance.destroy()}};document.createElement("perspective-string-column-style").constructor===HTMLElement&&window.customElements.define("perspective-string-column-style",_);import"mobile-drag-drop-shadow-dom";var ne={HTMLPerspectiveViewerElement:p,HTMLPerspectiveViewerPluginElement:c};export{p as HTMLPerspectiveViewerElement,c as HTMLPerspectiveViewerPluginElement,q as convert,ne as default}; //# sourceMappingURL=perspective-viewer.js.map