tablevu 0.2.22 → 0.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -109
- package/dist/array.d.ts +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/odata.d.ts +40 -0
- package/dist/table.d.ts +173 -0
- package/dist/tablevu-index.esm.js +1076 -0
- package/dist/tablevu-index.umd.cjs.js +1087 -0
- package/dist/tablevu-odata.esm.js +508 -0
- package/dist/tablevu-odata.umd.cjs.js +519 -0
- package/dist/tablevu-table.esm.js +551 -0
- package/dist/tablevu-table.umd.cjs.js +560 -0
- package/dist/tablevu-webapi.esm.js +19 -0
- package/dist/tablevu-webapi.umd.cjs.js +29 -0
- package/dist/webapi.d.ts +15 -0
- package/package.json +43 -24
- package/LICENSE +0 -21
- package/dist/array.js +0 -1
- package/dist/get.js +0 -1
- package/dist/odata.js +0 -1
- package/dist/table.js +0 -1
- package/dist/webapi.js +0 -1
- package/index.js +0 -5
- package/src/array.js +0 -78
- package/src/get.js +0 -28
- package/src/odata.js +0 -179
- package/src/table.js +0 -609
- package/src/webapi.js +0 -33
package/package.json
CHANGED
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tablevu",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.3.0-beta.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vue 3 data table component",
|
|
6
|
+
"main": "dist/tablevu-index.umd.cjs.js",
|
|
7
|
+
"module": "dist/tablevu-index.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/tablevu-index.esm.js",
|
|
12
|
+
"require": "./dist/tablevu-index.umd.cjs.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./table": {
|
|
16
|
+
"import": "./dist/tablevu-table.esm.js",
|
|
17
|
+
"require": "./dist/tablevu-table.umd.cjs.js",
|
|
18
|
+
"types": "./dist/table.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./odata": {
|
|
21
|
+
"import": "./dist/tablevu-odata.esm.js",
|
|
22
|
+
"require": "./dist/tablevu-odata.umd.cjs.js",
|
|
23
|
+
"types": "./dist/odata.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./webapi": {
|
|
26
|
+
"import": "./dist/tablevu-webapi.esm.js",
|
|
27
|
+
"require": "./dist/tablevu-webapi.umd.cjs.js",
|
|
28
|
+
"types": "./dist/webapi.d.ts"
|
|
29
|
+
}
|
|
8
30
|
},
|
|
31
|
+
"files": ["dist"],
|
|
9
32
|
"scripts": {
|
|
10
|
-
"build": "
|
|
33
|
+
"build": "rollup -c",
|
|
11
34
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
35
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"url": "git+https://github.com/endb/tablevu.git"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"table",
|
|
19
|
-
"datatable",
|
|
20
|
-
"vue3 table",
|
|
21
|
-
"vue3 datatable",
|
|
22
|
-
"vue 3 table",
|
|
23
|
-
"vue 3 datatable"
|
|
24
|
-
],
|
|
25
|
-
"author": "endb <ender.boz@gmail.com>",
|
|
36
|
+
"keywords": ["table", "datatable", "vue3 table", "vue3 datatable", "vue 3 table", "vue 3 datatable"],
|
|
37
|
+
"author": "Ender Boz <ender.boz@gmail.com>",
|
|
26
38
|
"license": "MIT",
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
},
|
|
39
|
+
"repository": { "type": "git", "url": "git+https://github.com/endb/tablevu.git" },
|
|
40
|
+
"bugs": { "url": "https://github.com/endb/tablevu/issues" },
|
|
30
41
|
"homepage": "https://github.com/endb/tablevu#readme",
|
|
42
|
+
"dependencies": { "vue": ">=3.0.0" },
|
|
31
43
|
"devDependencies": {
|
|
32
|
-
"
|
|
44
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
45
|
+
"@types/node": "^20.14.2",
|
|
46
|
+
"@vitejs/plugin-vue": "^6.0.9",
|
|
47
|
+
"rollup": "^4.20.0",
|
|
48
|
+
"rollup-plugin-visualizer": "^5.12.0",
|
|
49
|
+
"rollup-plugin-vue": "^6.0.0",
|
|
50
|
+
"tslib": "^2.8.1",
|
|
51
|
+
"typescript": "^5.5.0"
|
|
33
52
|
}
|
|
34
|
-
}
|
|
53
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Ender Boz
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/array.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function(props,data){let d=[];if(Array.isArray(data))d=data;return new Promise((resolve,reject)=>{if(props.pageSize){d=d.slice((props.currPage-1)*props.pageSize,props.currPage*props.pageSize)}if(props.sort&&props.sort.length>0){for(let i=props.sort.length-1;i>=0;i--){let f=null;if(props.sort[i].index>-1)f=props.cols[props.sort[i].index].name;else f=props.sort[i].name;if(props.sort[i].dir=="desc")d.sort((a,b)=>a[f]<b[f]?1:b[f]<a[f]?-1:0);else d.sort((a,b)=>a[f]>b[f]?1:b[f]>a[f]?-1:0)}}resolve({rows:d,count:d.length})})}
|
package/dist/get.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function get(req){return new Promise((resolve,reject)=>{fetch(req).then(res=>res.json()).then(res=>{let r;let c=0;if(res){if(res.hasOwnProperty("value"))r=res.value;else r=res;if(res.hasOwnProperty("@odata.count")){c=parseInt(res["@odata.count"])}else if(res.hasOwnProperty("count"))c=parseInt(res["count"]);else c=0;resolve({rows:r,count:c})}else resolve({rows:null,count:null})}).catch(err=>{console.error(err);reject(err)})})}
|
package/dist/odata.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import get from"./get.js";function filter(q){function fuval(q){if(q===null){return"null"}else if(typeof q==="string"){if(q.length==10&&q[4]=="-"&&q[7]=="-"&&Date.parse(q)){return q}else return"'"+q+"'"}else{if(typeof q==="number"||typeof q==="boolean")return q.toString();else{if(q.getMonth&&typeof q.getMonth==="function")return q.toISOString();else return q.func+"("+q.params.join(",")+")"}}}let s="";if(q&&q.filters)for(let i=0;i<q.filters.length;i++){if(i>0)s=s+` ${q.type||"and"} `;if(q.filters[i].child){if(q.filters[i].operator=="any"||q.filters[i].operator=="all"){s=s+q.filters[i].child+"/"+q.filters[i].operator+"(i:"+filter(q.filters[i],"i")+")"}}else if(q.filters[i].column){if(q.filters[i].operator=="in")s=s+fuval(q.filters[i].value)+" "+q.filters[i].operator+" "+q.filters[i].column;else s=s+q.filters[i].column+" "+q.filters[i].operator+" "+fuval(q.filters[i].value)}else{if(q.filters[i].func)s=s+q.filters[i].func+"("+q.filters[i].params.map(m=>fuval(m)).join(",")+")";else if(q.filters[i])s=s+"("+filter(q.filters[i])+")"}}return s}function sefs(url,query,seperator){let r="";if(query.select&&query.select.length>0){if(seperator)r+="$select="+query.select.join(",");else url.searchParams.append("$select",query.select.join(","))}if(query.expand&&query.expand.length>0){let a=[];query.expand.forEach(e=>{let q=sefs(null,e,";");if(q)a.push(e.name+"("+q+")");else a.push(e.name)});if(seperator)r+=(r.length>0?seperator:"")+"$expand="+a.join(",");else url.searchParams.append("$expand",a.join(","))}if(query.orderby){if(seperator)r+="$orderby="+query.orderby;else url.searchParams.append("$orderby",query.orderby)}if(query.top&&parseInt(query.top)>=0){if(seperator)r+="$top="+query.top;else url.searchParams.append("$top",query.top)}if(query.skip&&parseInt(query.skip)>=0){if(seperator)r+="$skip="+query.skip;else url.searchParams.append("$skip",query.skip)}if(query.count){if(seperator)r+="$count=true";else url.searchParams.append("$count",true)}return r}export default class odata{constructor(req,features){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("$skip",props.pageSize*(props.currPage-1));u.searchParams.append("$top",props.pageSize)}sefs(u,features);let f=[];if(features.filter){if(typeof features.filter=="string")f.push(features.filter);else if(Object.prototype.hasOwnProperty.call(features.filter,"filters")){let l=filter(features.filter);if(l)f.push(l)}}if(props.filter){if(typeof props.filter=="string")f.push(props.filter);else if(props.filter&&Object.prototype.hasOwnProperty.call(props.filter,"filters")){let l=filter(props.filter);if(l)f.push(l)}}if(props.search){let l=props.cols.filter(q=>q.searchable==undefined||q.searchable==true).map(q=>"contains("+q.name.replaceAll(".","/")+",'"+props.search+"')").join(" or ");if(l)f.push("("+l+")")}if(f&&f.length>0)u.searchParams.append("$filter",f.join(" and "));if(props.sort&&props.sort.length>0)u.searchParams.append("$orderby",props.sort.map(m=>{let n={index:-1,name:"",dir:null};if(Object.prototype.hasOwnProperty.call(m,"index")){n.index=m.index}else{n.name=m.name}n.dir=m.dir;return n}).map(m=>{return(m.index>-1?props.cols[m.index].name:m.name).replaceAll(".","/")+(m.dir?" "+m.dir:"")}).join(","));let r=null;if(features&&features.onfetch&&typeof features.onfetch=="function")r=features.onfetch(new Request(u,req));else r=new Request(u,req);return get(r)}}}
|
package/dist/table.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1};const tablevu={props:{settings:{type:Object,default:null},data:{type:[Array,Function]},group:{type:[String,Object]},search:{type:String},filter:{type:[Array,Object]},command:{type:Array,default:[]},rowid:{type:String},onRowClick:{type:Function},onRowDblClick:{type:Function},class:{type:String,default:"table"},style:{type:String,default:null}},emits:["onRowClick","onRowDblClick"],setup(props,{attrs,slots,emit,expose}){let rows=[];let rowg=[];let grps=[];let adapter=null;let timer=null;const spec=reactive({caption:null,group:{value:props.settings&&props.settings.group?props.settings.group.value:props.group?props.group:null,content:props.settings&&props.settings.group?props.settings.group.content:null,expandAll:true,class:"table-light"},page:{count:0,size:props.settings&&props.settings.page?props.settings.page.size:0,current:0,type:null},sort:props.settings&&props.settings.sort?props.settings.sort:[],columns:props.settings&&props.settings.columns?props.settings.columns:[],footer:{button:{class:"btn"}}});if(props.data){if(Array.isArray(props.data)){adapter=adaptarr}else{adapter=props.data}}if(props.search)spec.search=props.search;watch(()=>props.search,(n,o)=>{const x=parseInt(props.settings.searchMinChar)||3;if(timer){clearTimeout(timer);timer=null}if(n&&n.length>x){spec.search=n;timer=setTimeout(()=>{refresh();timer=null},444)}else if(o&&o.length>x&&(n==undefined||n==null||n.length<=x)){spec.search=null;timer=setTimeout(()=>{refresh();timer=null},444)}});if(props.filter)spec.filter=props.filter;watch(()=>props.filter,()=>{if(props.filter)spec.filter=props.filter;else spec.filter=null;refresh()},{deep:true});watch(()=>props.command,(n,o)=>{if(n&&n.length>0){const c=props.command[n.length-1];if(c&&c.name){if(c.name.toLowerCase()=="refresh")refresh();else if(c.name.toLowerCase()=="first")first();else if(c.name.toLowerCase()=="prior")prior();else if(c.name.toLowerCase()=="next")next();else if(c.name.toLowerCase()=="last")last();else console.log("Unknown command")}props.command.length=0}},{deep:true});function prepareGroup(g,r){grps=[];rowg=[];for(let i=0;i<r.length;i++){let v=null;let c=null;const o=r[i];if(g.value){if(typeof g.value=="function")v=g.value(o);else v=o[g.value]}else if(typeof g=="function")v=g(o);else{if(typeof g=="bigint"||typeof g=="number"){const l=parseFloat(g);if(l)v=o[l]}else if(typeof g=="string")v=o[g]}if(g.content){if(typeof g.content=="function")c=g.content(o);else c=o[g.content]}let n=grps.findIndex(f=>f.group==v);if(n==-1){n=grps.push({group:v,content:c,expand:spec.group.expandAll})-1}rowg.push(n)}}function first(){page(1)}function prior(){if(spec.page.current>1){page(spec.page.current-1)}else{page(spec.page.current)}}function next(){page(spec.page.current+1)}function last(){page(spec.page.count)}function go(){let p;let g=spec.page.current;do{p=prompt(undefined,spec.page.current);g=parseInt(p)}while(p&&isNaN(g));if(g&&g>0&&g!=spec.page.current)page(g)}function refresh(){page(spec.page.current)}function orderby(ind,dir){if(spec.sort&&spec.sort.length>0){let l=spec.sort.findIndex(f=>f.index==ind);if(l<0){let n=spec.columns[ind].name;l=spec.sort.findIndex(f=>f.name==n)}if(l==0){spec.sort[l].dir=dir?dir:spec.sort[0].dir?null:"desc"}else if(l>0){spec.sort.splice(l,1)}if(l!=0){spec.sort.unshift({index:ind,dir:dir?dir:null})}if(spec.sort.length>2){spec.sort.pop()}}else{spec.sort.push({index:ind,dir:dir?dir:null})}page(spec.page.current)}function page(currentPage){let dat=null;if(props.data){if(Array.isArray(props.data))dat=props.data}else return;spec.status=tablevuStatuses.Loading;if(adapter){adapter({pageSize:spec.page.size,currPage:currentPage,sort:spec.sort,cols:spec.columns,filter:spec.filter,search:spec.search},dat).then(ada=>{if(spec.onData)rows=spec.onData(ada.rows);else rows=ada.rows;if(spec.group&&(typeof spec.group=="string"||typeof spec.group=="bigint"||typeof spec.group=="object"&&spec.group.value))prepareGroup(spec.group,rows);spec.page.count=ada.count>0&&spec.page.size>0?Math.ceil(ada.count/spec.page.size):0;spec.page.current=currentPage;spec.status=tablevuStatuses.Ready;spec.time=Date.now()})}}function renderValue(col,val){if(val){let v;if(col.type=="datetime"||col.type=="date"||col.type=="time"){let t=new Date(val);if(col.type=="date")v=t.toLocaleDateString();else if(col.type=="time")v=t.toLocaleTimeString();else v=t.toLocaleString()}else{if(col.type=="numeric"){v=parseFloat(val)}else{if(col.type=="integer"){v=parseInt(val)}else v=val}}return v}else return""}function renderCell(col,val){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}const v=renderValue(col,val);return h("td",o,v)}function renderCustomCell(col,row){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}let f=col.render(row);return h("td",o,f)}function renderGroup(grp){const b=h("button",{title:grp.expand,onClick:event=>{grp.expand=grp.expand?false:true;event.currentTarget.value=grp.expand?"▼":"►";spec.time=Date.now();event.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},grp.expand?"▼":"►");const v=grp.content||grp.group;return h("tr",{},h("td",{colspan:spec.columns.length,class:spec.group.class},[b,v]))}function renderRow(index,row){const o={};const r=[];o.key=index;o.index=index;if(props.rowid){o.rowid=row[props.rowid]}for(let i=0;i<spec.columns.length;i+=1){let v;const c=spec.columns[i];if(c.render){v=renderCustomCell(c,row);r.push(v)}else{if(c.depth){v=row;for(let j=0;j<c.depth.length;j+=1){if(v)v=v[c.depth[j]]}}else{v=row[c.name]}r.push(renderCell(c,v))}}o.ondblclick=event=>{const r=rows[event.currentTarget.attributes.index.value];emit("onRowDblClick",event,r)};if(props.onRowClick){o.onClick=event=>{const r=rows[event.currentTarget.attributes.index.value];props.onRowClick(event,r)}}return h("tr",o,r)}function renderHeader(){let ar=[];let sp=1;for(let i=0;i<spec.columns.length;i+=1){if(sp>1){sp--;continue}const cl=[];if(spec.columns[i].label){cl.push(h("span",spec.columns[i].label))}else{cl.push(h("span",spec.columns[i].name))}if(spec.sort&&spec.sort.length>0&&spec.sort[0].index==i){if(spec.sort[0].dir=="desc")cl.push(h("span",{style:{float:"right"}},"▼"));else cl.push(h("span",{style:{float:"right"}},"▲"))}let ch={position:"relative"};if(spec.columns[i].width){ch.width=spec.columns[i].width;ch.minWidth=spec.columns[i].width;ch.maxWidth=spec.columns[i].width}let cy={display:"block","font-weight":500,textDecoration:"none",textAlign:"center"};if(spec.columns[i].header){if(spec.columns[i].header.colspan)sp=parseInt(spec.columns[i].header.colspan)||1;if(spec.columns[i].header.style)ch.style=spec.columns[i].header.style;if(spec.columns[i].header.align)ch.textAlign=spec.columns[i].header.align}let a;let f;if(spec.columns[i].popup){const r=ref(null);let c=[h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(event){orderby(i,"desc");event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];a=h("a",{href:"#",onClick(event){if(r.value&&r.value.style&&r.value.style.display&&r.value.style.display=="block")r.value.style.display="none";else r.value.style.display="block";event.preventDefault()},style:cy},cl);f=h("div",{ref:r,style:{position:"absolute",display:"none",width:spec.columns[i].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},c)}else a=h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:cy},cl);if(spec.columns[i].filter){}ar.push(h("th",{colspan:sp>1?sp:null,style:ch},[a,f]))}const tr=h("tr",{},ar);return[tr]}function renderBody(){const dr=[];if(rows&&rows.length>0){if(grps&&grps.length>0){let r=[];for(let g=0;g<grps.length;g++)r.push({index:g,childs:[]});for(let i=0;i<rows.length;i++){const x=rowg[i];r[x].childs.push(renderRow(i,rows[i]))}for(let g=0;g<grps.length;g++){dr.push(renderGroup(grps[g]));if(grps[g].expand)dr.push(r[g].childs)}}else{for(let i=0;i<rows.length;i++){dr.push(renderRow(i,rows[i]))}}}return dr}function renderFooter(){const fr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:first,disabled:spec.page.current==1},"◀◀");const ls=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:last,disabled:spec.page.count==0||spec.page.current==spec.page.count},"▶▶");const pg=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:go},spec.page.current+(spec.page.count>0?" / "+spec.page.count:""));const pr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:prior,disabled:spec.page.current==1},"◀");const nx=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:next,disabled:spec.page.count>0&&spec.page.current==spec.page.count},"▶");const td=h("td",{colspan:spec.columns.length,align:"center"},[fr,pr,pg,nx,ls]);const tr=h("tr",{},[td]);return[tr]}function renderCaption(){return null}if(spec.columns.length==0){alert("Columns not defined !")}for(let i=0;i<spec.columns.length;i++)if(spec.columns[i].name&&spec.columns[i].name.indexOf(".")>-1){spec.columns[i].depth=spec.columns[i].name.split(".")}page(1);onMounted(()=>{});return{spec:spec,renderHeader:renderHeader,renderBody:renderBody,renderFooter:renderFooter,renderCaption:renderCaption}},render(props){let prps={class:"tablevu"};if(props.class)prps.class="tablevu "+props.class;if(props.style)prps.style=props.style;let cntn=[];cntn.push(h("thead",{},this.renderHeader()));if(this.spec.status==tablevuStatuses.Ready)cntn.push(h("tbody",{"data-time":this.spec.time},this.renderBody()));if(this.spec.caption)cntn.push(h("caption",{},this.renderCaption()));if(this.spec.status==tablevuStatuses.Ready)if(this.spec.page.size>0)cntn.push(h("tfoot",{},this.renderFooter()));return h("table",prps,cntn)}};export default tablevu;
|
package/dist/webapi.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import get from"./get.js";export default class webapi{constructor(req,data,events){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("skip",props.pageSize*(props.currPage-1));u.searchParams.append("top",props.pageSize)}if(props.search)u.searchParams.append("search",props.search);if(props.sort&&props.sort.length>0){u.searchParams.append("orderby",props.sort.map(m=>{let n={index:-1,name:""};if(Object.prototype.hasOwnProperty.call(m,"index")){n.index=m.index}else{n.name=m.name}return n}).map(m=>{return m.index>-1?props.cols[m.index].name:m.name}))}let r=null;if(events&&events.onfetch&&typeof events.onfetch=="function")r=events.onfetch(new Request(u,req));else r=new Request(u,req);return get(r)}}}
|
package/index.js
DELETED
package/src/array.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export default function (props, data) {
|
|
2
|
-
let d = [];
|
|
3
|
-
|
|
4
|
-
if (Array.isArray(data))
|
|
5
|
-
d = data;
|
|
6
|
-
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
// Paging //
|
|
9
|
-
if (props.pageSize) {
|
|
10
|
-
d = d.slice((props.currPage - 1) * props.pageSize, props.currPage * props.pageSize);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Sort //
|
|
14
|
-
if (props.sort && props.sort.length > 0) {
|
|
15
|
-
for (let i = props.sort.length - 1; i >= 0; i--) {
|
|
16
|
-
let f = null;
|
|
17
|
-
|
|
18
|
-
if (props.sort[i].index > -1)
|
|
19
|
-
f = props.cols[props.sort[i].index].name;
|
|
20
|
-
else
|
|
21
|
-
f = props.sort[i].name;
|
|
22
|
-
|
|
23
|
-
if (props.sort[i].dir == 'desc')
|
|
24
|
-
d.sort((a,b) => (a[f] < b[f]) ? 1 : ((b[f] < a[f]) ? -1 : 0));
|
|
25
|
-
else
|
|
26
|
-
d.sort((a,b) => (a[f] > b[f]) ? 1 : ((b[f] > a[f]) ? -1 : 0));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
resolve({ rows: d, count: d.length })
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
/*
|
|
35
|
-
export default function adapter(params, data) {
|
|
36
|
-
debugger;
|
|
37
|
-
const rsl = data;
|
|
38
|
-
|
|
39
|
-
// Filter & Search //
|
|
40
|
-
if (params.filter || params.search) {
|
|
41
|
-
const cls = params.cols.map((m,i) => ({ index: i, searchable: q.searchable == undefined || q.searchable == true})).filter(q => q.searchable == true).map(m => m.index);
|
|
42
|
-
|
|
43
|
-
if (cls.length > 0 && (params.filter || params.search)) {
|
|
44
|
-
if (params.filter) {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (params.search) {
|
|
49
|
-
rsl = rsl.filter(f => {
|
|
50
|
-
return Object.values(f).filter((l,x) => cls.indexOf(x) > -1).some(s => s.indexOf(params.search) > -1)
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Sort //
|
|
57
|
-
if (params.sort && params.sort.length > 0) {
|
|
58
|
-
for (let i = params.sort.length - 1; i >= 0; i--) {
|
|
59
|
-
let s = params.sort[i];
|
|
60
|
-
if (s.dir == 'desc')
|
|
61
|
-
rsl.sort((a,b) => (a[s.name] < b[s.name]) ? 1 : ((b[s.name] < a[s.name]) ? -1 : 0));
|
|
62
|
-
else
|
|
63
|
-
rsl.sort((a,b) => (a[s.name] > b[s.name]) ? 1 : ((b[s.name] > a[s.name]) ? -1 : 0));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Paging //
|
|
68
|
-
if (params.pageSize && rsl.length > params.pageSize) {
|
|
69
|
-
rsl = rsl.filter((v,i,s) => i >= params.pageSize * (params.currPage - 1) && i < params.pageSize * params.currPage);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Select - None //
|
|
73
|
-
|
|
74
|
-
// Expand - None //
|
|
75
|
-
|
|
76
|
-
return { rows: rsl, count: data.length };
|
|
77
|
-
}
|
|
78
|
-
*/
|
package/src/get.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export default function get(req) {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
fetch(req).then(res => res.json()).then(res => {
|
|
4
|
-
let r;
|
|
5
|
-
let c = 0;
|
|
6
|
-
|
|
7
|
-
if (res) {
|
|
8
|
-
if (res.hasOwnProperty('value'))
|
|
9
|
-
r = res.value;
|
|
10
|
-
else
|
|
11
|
-
r = res;
|
|
12
|
-
|
|
13
|
-
if (res.hasOwnProperty('@odata.count')) {
|
|
14
|
-
c = parseInt(res['@odata.count']);
|
|
15
|
-
} else if (res.hasOwnProperty('count'))
|
|
16
|
-
c = parseInt(res['count']);
|
|
17
|
-
else
|
|
18
|
-
c = 0;
|
|
19
|
-
|
|
20
|
-
resolve({ rows: r, count: c })
|
|
21
|
-
} else
|
|
22
|
-
resolve({ rows: null, count: null })
|
|
23
|
-
}).catch(err => {
|
|
24
|
-
console.error(err);
|
|
25
|
-
reject(err);
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
}
|
package/src/odata.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import get from './get.js';
|
|
2
|
-
|
|
3
|
-
function filter(q) {
|
|
4
|
-
|
|
5
|
-
function fuval(q) {
|
|
6
|
-
if (q === null) {
|
|
7
|
-
return 'null'
|
|
8
|
-
} else if (typeof(q) === 'string') {
|
|
9
|
-
if (q.length == 10 && q[4] == '-' && q[7] == '-' && Date.parse(q)) { // input date return iso string
|
|
10
|
-
return q;
|
|
11
|
-
} else
|
|
12
|
-
return '\'' + q + '\'';
|
|
13
|
-
} else {
|
|
14
|
-
if (typeof(q) === 'number' || typeof(q) === 'boolean')
|
|
15
|
-
return q.toString();
|
|
16
|
-
else {
|
|
17
|
-
if (q.getMonth && typeof q.getMonth === "function")
|
|
18
|
-
return q.toISOString()
|
|
19
|
-
else
|
|
20
|
-
return q.func + '(' + q.params.join(',') + ')';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let s = '';
|
|
26
|
-
|
|
27
|
-
if (q && q.filters)
|
|
28
|
-
for (let i = 0; i < q.filters.length; i++) {
|
|
29
|
-
if (i > 0)
|
|
30
|
-
s = s + ` ${q.type || 'and'} `;
|
|
31
|
-
|
|
32
|
-
if (q.filters[i].child) {
|
|
33
|
-
if (q.filters[i].operator == 'any' || q.filters[i].operator == 'all') {
|
|
34
|
-
s = s + q.filters[i].child + '/' + q.filters[i].operator + '(i:' + filter(q.filters[i], 'i') + ')';
|
|
35
|
-
}
|
|
36
|
-
} else
|
|
37
|
-
if (q.filters[i].column) {
|
|
38
|
-
if (q.filters[i].operator == 'in')
|
|
39
|
-
s = s + fuval(q.filters[i].value) + ' ' + q.filters[i].operator + ' ' + q.filters[i].column;
|
|
40
|
-
else
|
|
41
|
-
s = s + q.filters[i].column + ' ' + q.filters[i].operator + ' ' + fuval(q.filters[i].value);
|
|
42
|
-
} else {
|
|
43
|
-
if (q.filters[i].func)
|
|
44
|
-
s = s + q.filters[i].func + '(' + q.filters[i].params.map(m => fuval(m)).join(',') + ')';
|
|
45
|
-
else
|
|
46
|
-
if (q.filters[i])
|
|
47
|
-
s = s + '(' + filter(q.filters[i]) + ')';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return s;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function sefs(url, query, seperator) {
|
|
55
|
-
let r = '';
|
|
56
|
-
|
|
57
|
-
if (query.select && query.select.length > 0) {
|
|
58
|
-
if (seperator)
|
|
59
|
-
r += '$select=' + query.select.join(',');
|
|
60
|
-
else
|
|
61
|
-
url.searchParams.append('$select', query.select.join(','));
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
if (query.expand && query.expand.length > 0) {
|
|
65
|
-
let a = [];
|
|
66
|
-
|
|
67
|
-
query.expand.forEach(e => {
|
|
68
|
-
let q = sefs(null, e, ';');
|
|
69
|
-
|
|
70
|
-
if (q)
|
|
71
|
-
a.push(e.name + '(' + q + ')');
|
|
72
|
-
else
|
|
73
|
-
a.push(e.name);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (seperator)
|
|
77
|
-
r += (r.length > 0 ? seperator: '') + '$expand=' + a.join(',');
|
|
78
|
-
else
|
|
79
|
-
url.searchParams.append('$expand', a.join(','));
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
if (query.orderby) {
|
|
83
|
-
if (seperator)
|
|
84
|
-
r += '$orderby=' + query.orderby;
|
|
85
|
-
else
|
|
86
|
-
url.searchParams.append('$orderby', query.orderby);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
if (query.top && parseInt(query.top) >= 0) {
|
|
90
|
-
if (seperator)
|
|
91
|
-
r += '$top=' + query.top;
|
|
92
|
-
else
|
|
93
|
-
url.searchParams.append('$top', query.top);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (query.skip && parseInt(query.skip) >= 0) {
|
|
97
|
-
if (seperator)
|
|
98
|
-
r += '$skip=' + query.skip;
|
|
99
|
-
else
|
|
100
|
-
url.searchParams.append('$skip', query.skip);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
if (query.count) {
|
|
104
|
-
if (seperator)
|
|
105
|
-
r += '$count=true';
|
|
106
|
-
else
|
|
107
|
-
url.searchParams.append('$count', true);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
return r;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export default class odata {
|
|
114
|
-
constructor(req, features) {
|
|
115
|
-
this.adapter = (props) => {
|
|
116
|
-
const u = new URL(req.url);
|
|
117
|
-
|
|
118
|
-
// Paging //
|
|
119
|
-
if (props.pageSize) {
|
|
120
|
-
u.searchParams.append('$skip', props.pageSize * (props.currPage - 1));
|
|
121
|
-
u.searchParams.append('$top', props.pageSize);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
sefs(u, features);
|
|
125
|
-
|
|
126
|
-
// Filter //
|
|
127
|
-
let f = [];
|
|
128
|
-
|
|
129
|
-
// Static filter //
|
|
130
|
-
if (features.filter) {
|
|
131
|
-
if (typeof(features.filter) == 'string')
|
|
132
|
-
f.push(features.filter);
|
|
133
|
-
else
|
|
134
|
-
if (Object.prototype.hasOwnProperty.call(features.filter, 'filters')) {
|
|
135
|
-
let l = filter(features.filter);
|
|
136
|
-
|
|
137
|
-
if (l)
|
|
138
|
-
f.push(l);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Dynamic filter //
|
|
143
|
-
if (props.filter) {
|
|
144
|
-
if (typeof(props.filter) == 'string')
|
|
145
|
-
f.push(props.filter);
|
|
146
|
-
else
|
|
147
|
-
if (props.filter && Object.prototype.hasOwnProperty.call(props.filter, 'filters')) {
|
|
148
|
-
let l = filter(props.filter);
|
|
149
|
-
|
|
150
|
-
if (l)
|
|
151
|
-
f.push(l);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Search //
|
|
156
|
-
if (props.search) {
|
|
157
|
-
let l = props.cols.filter(q => q.searchable == undefined || q.searchable == true).map(q => "contains(" + q.name.replaceAll('.', '/') + ",'" + props.search + "')").join(" or ");
|
|
158
|
-
|
|
159
|
-
if (l)
|
|
160
|
-
f.push('(' + l + ')');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (f && f.length > 0)
|
|
164
|
-
u.searchParams.append('$filter', f.join(' and '));
|
|
165
|
-
|
|
166
|
-
// Sort //
|
|
167
|
-
if (props.sort && props.sort.length > 0)
|
|
168
|
-
u.searchParams.append('$orderby', props.sort.map(m => { let n = { index: -1, name: '', dir: null }; if (Object.prototype.hasOwnProperty.call(m, 'index')) { n.index = m.index } else { n.name = m.name }; n.dir = m.dir; return n; }).map(m => { return (m.index > -1 ? props.cols[m.index].name : m.name).replaceAll('.', '/') + (m.dir ? (' ' + m.dir): '') }).join(','));
|
|
169
|
-
|
|
170
|
-
let r = null;
|
|
171
|
-
if (features && features.onfetch && typeof features.onfetch == 'function')
|
|
172
|
-
r = features.onfetch(new Request(u, req))
|
|
173
|
-
else
|
|
174
|
-
r = new Request(u, req);
|
|
175
|
-
|
|
176
|
-
return get(r);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|