@lazhus/kg-ui 0.10.9 → 0.10.10
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/custom-elements.json
CHANGED
|
@@ -1571,6 +1571,10 @@
|
|
|
1571
1571
|
}
|
|
1572
1572
|
]
|
|
1573
1573
|
},
|
|
1574
|
+
{
|
|
1575
|
+
"kind": "method",
|
|
1576
|
+
"name": "_getNormalizedPageSizeOptions"
|
|
1577
|
+
},
|
|
1574
1578
|
{
|
|
1575
1579
|
"kind": "method",
|
|
1576
1580
|
"name": "_getProcessedData"
|
|
@@ -1814,11 +1818,23 @@
|
|
|
1814
1818
|
"text": "CustomEvent"
|
|
1815
1819
|
}
|
|
1816
1820
|
},
|
|
1821
|
+
{
|
|
1822
|
+
"name": "kg-page-change",
|
|
1823
|
+
"type": {
|
|
1824
|
+
"text": "CustomEvent"
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1817
1827
|
{
|
|
1818
1828
|
"name": "page-size-change",
|
|
1819
1829
|
"type": {
|
|
1820
1830
|
"text": "CustomEvent"
|
|
1821
1831
|
}
|
|
1832
|
+
},
|
|
1833
|
+
{
|
|
1834
|
+
"name": "kg-page-size-change",
|
|
1835
|
+
"type": {
|
|
1836
|
+
"text": "CustomEvent"
|
|
1837
|
+
}
|
|
1822
1838
|
}
|
|
1823
1839
|
],
|
|
1824
1840
|
"superclass": {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r)(t,"symbol"!=typeof i?i+"":i,r);import{LitElement as i,css as r,html as a}from"lit";import"lit/directives/class-map.js";import"./kg-checkbox.js";import"./kg-radio.js";import{unsafeHTML as s}from"lit/directives/unsafe-html.js";import"./kg-button.js";import"./kg-skeleton.js";class o extends i{constructor(){super(),this.columns=[],this.data=[],this.loading=!1,this.striped=!1,this.bordered=!1,this.hover=!0,this.selectable=!1,this.selectionMode="multiple",this.selectedRows=[],this.sortable=!1,this.pagination=!1,this.pageSize=10,this.pageSizeOptions=[10,20,50,100],this.total=0,this.serverSide=!1,this.currentPage=1,this._sortColumn=null,this._sortDirection=null}_handleSelectAll(e){if(!this.selectable||"single"===this.selectionMode)return;const t=e.detail.checked;this.selectedRows=t?[...this.data]:[],this._emitSelectionChange()}_handleRowSelect(e,t){if(this.selectable)if(t.stopPropagation(),"single"===this.selectionMode)this._isSelected(e)||(this.selectedRows=[e],this._emitSelectionChange());else{let i;i="change"===t.type&&void 0!==t.detail&&void 0!==t.detail.checked?t.detail.checked:!this._isSelected(e),this.selectedRows=i?[...this.selectedRows,e]:this.selectedRows.filter(t=>t!==e),this._emitSelectionChange()}}_isSelected(e){return this.selectedRows.includes(e)}_emitSelectionChange(){this.dispatchEvent(new CustomEvent("selection-change",{detail:{selectedRows:this.selectedRows},bubbles:!0,composed:!0}))}_handleSort(e){(e.sortable||this.sortable)&&(this._sortColumn===e.field?this._sortDirection="asc"===this._sortDirection?"desc":"asc":(this._sortColumn=e.field,this._sortDirection="asc"),this.dispatchEvent(new CustomEvent("sort",{detail:{column:this._sortColumn,direction:this._sortDirection},bubbles:!0,composed:!0})))}_getProcessedData(){if(this.serverSide)return{data:this.data,total:this.total||this.data.length};let e=[...this.data];if(this._sortColumn&&e.sort((e,t)=>{const i=e[this._sortColumn],r=t[this._sortColumn];return i<r?"asc"===this._sortDirection?-1:1:i>r?"asc"===this._sortDirection?1:-1:0}),this.pagination){const t=(this.currentPage-1)*
|
|
1
|
+
var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r)(t,"symbol"!=typeof i?i+"":i,r);import{LitElement as i,css as r,html as a}from"lit";import"lit/directives/class-map.js";import"./kg-checkbox.js";import"./kg-radio.js";import{unsafeHTML as s}from"lit/directives/unsafe-html.js";import"./kg-button.js";import"./kg-skeleton.js";class o extends i{constructor(){super(),this.columns=[],this.data=[],this.loading=!1,this.striped=!1,this.bordered=!1,this.hover=!0,this.selectable=!1,this.selectionMode="multiple",this.selectedRows=[],this.sortable=!1,this.pagination=!1,this.pageSize=10,this.pageSizeOptions=[10,20,50,100],this.total=0,this.serverSide=!1,this.currentPage=1,this._sortColumn=null,this._sortDirection=null}_handleSelectAll(e){if(!this.selectable||"single"===this.selectionMode)return;const t=e.detail.checked;this.selectedRows=t?[...this.data]:[],this._emitSelectionChange()}_handleRowSelect(e,t){if(this.selectable)if(t.stopPropagation(),"single"===this.selectionMode)this._isSelected(e)||(this.selectedRows=[e],this._emitSelectionChange());else{let i;i="change"===t.type&&void 0!==t.detail&&void 0!==t.detail.checked?t.detail.checked:!this._isSelected(e),this.selectedRows=i?[...this.selectedRows,e]:this.selectedRows.filter(t=>t!==e),this._emitSelectionChange()}}_isSelected(e){return this.selectedRows.includes(e)}_emitSelectionChange(){this.dispatchEvent(new CustomEvent("selection-change",{detail:{selectedRows:this.selectedRows},bubbles:!0,composed:!0}))}_handleSort(e){(e.sortable||this.sortable)&&(this._sortColumn===e.field?this._sortDirection="asc"===this._sortDirection?"desc":"asc":(this._sortColumn=e.field,this._sortDirection="asc"),this.dispatchEvent(new CustomEvent("sort",{detail:{column:this._sortColumn,direction:this._sortDirection},bubbles:!0,composed:!0})))}_getNormalizedPageSizeOptions(){let e=this.pageSizeOptions;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e=e.split(",").map(e=>Number(e.trim()))}return Array.isArray(e)&&0!==e.length||(e=[10,20,50,100]),e.map(e=>Number(e))}_getProcessedData(){if(this.serverSide)return{data:this.data||[],total:Number(this.total)||(this.data?this.data.length:0)};let e=[...this.data||[]];if(this._sortColumn&&e.sort((e,t)=>{const i=e[this._sortColumn],r=t[this._sortColumn];return i<r?"asc"===this._sortDirection?-1:1:i>r?"asc"===this._sortDirection?1:-1:0}),this.pagination){const t=Number(this.pageSize)||10,i=((Number(this.currentPage)||1)-1)*t,r=i+t;return{data:e.slice(i,r),total:e.length}}return{data:e,total:e.length}}_changePage(e){const t=Number(e);if(t<1)return;const i=Number(this.pageSize)||10,r=this.serverSide&&Number(this.total)||(this.data?this.data.length:0);if(t>Math.max(1,Math.ceil(r/i)))return;this.currentPage=t;const a={page:t,pageSize:i};this.dispatchEvent(new CustomEvent("page-change",{detail:a,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("kg-page-change",{detail:a,bubbles:!0,composed:!0}))}_handlePageSizeChange(e){const t=parseInt(e.target.value,10)||10;this.pageSize=t,this.currentPage=1,this.requestUpdate();const i={pageSize:t,page:1},r={page:1,pageSize:t};this.dispatchEvent(new CustomEvent("page-size-change",{detail:i,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("kg-page-size-change",{detail:i,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("page-change",{detail:r,bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("kg-page-change",{detail:r,bubbles:!0,composed:!0}))}_renderCellContent(e,t){if(!e.render)return t[e.field];const i=e.render(t);return"string"==typeof i?s(i):i}_renderHeaderContent(e){if(e.headerRender){const t=e.headerRender(e);return"string"==typeof t?s(t):t}return e.label}_getMaxDepth(e){if(!e||0===e.length)return 1;let t=0;const i=(e,r)=>{t=Math.max(t,r),e.forEach(e=>{e.children&&e.children.length>0&&i(e.children,r+1)})};return i(e,1),t}_getLeafCount(e){return e.children&&0!==e.children.length?e.children.reduce((e,t)=>e+this._getLeafCount(t),0):1}_getLeafColumns(e=this.columns){if(!e)return[];const t=[],i=e=>{e.forEach(e=>{e.children&&e.children.length>0?i(e.children):t.push(e)})};return i(e),t}_getHeaderRows(){const e=this._getMaxDepth(this.columns),t=Array.from({length:e},()=>[]),i=(r,a)=>{r.forEach(r=>{const s=!r.children||0===r.children.length,o=this._getLeafCount(r),n=s?e-a:1;t[a].push({...r,colspan:o,rowspan:n}),r.children&&i(r.children,a+1)})};return i(this.columns,0),t}render(){const{data:e,total:t}=this._getProcessedData(),i=Number(this.pageSize)||10,r=Number(this.currentPage)||1,s=Number(t)||0,o=this.pagination?Math.max(1,Math.ceil(s/i)):1,n=this._getNormalizedPageSizeOptions(),l=this.data&&this.data.length>0&&this.selectedRows.length===this.data.length,d="single"===this.selectionMode,c=this._getHeaderRows(),h=c.length,g=this._getLeafColumns(),p=(()=>{const e=[],t=r-2,i=r+2+1;for(let r=1;r<=o;r++)(1===r||r===o||r>=t&&r<i)&&e.push(r);return e})();return a`
|
|
2
2
|
<div class="wrapper">
|
|
3
3
|
<div class="table-container">
|
|
4
4
|
<table>
|
|
5
5
|
<thead>
|
|
6
|
-
${
|
|
6
|
+
${c.map((e,t)=>a`
|
|
7
7
|
<tr>
|
|
8
8
|
${0===t&&this.selectable?a`
|
|
9
|
-
<th class="checkbox-cell" rowspan="${
|
|
10
|
-
${
|
|
9
|
+
<th class="checkbox-cell" rowspan="${h}">
|
|
10
|
+
${d?"":a`
|
|
11
11
|
<kg-checkbox
|
|
12
|
-
.checked="${
|
|
12
|
+
.checked="${l}"
|
|
13
13
|
@change="${this._handleSelectAll}"
|
|
14
14
|
></kg-checkbox>
|
|
15
15
|
`}
|
|
@@ -44,7 +44,7 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
44
44
|
<kg-skeleton variant="rect" width="16px" height="16px" style="border-radius: 4px; display: inline-block;"></kg-skeleton>
|
|
45
45
|
</td>
|
|
46
46
|
`:""}
|
|
47
|
-
${
|
|
47
|
+
${g.map(()=>a`
|
|
48
48
|
<td>
|
|
49
49
|
<kg-skeleton variant="text" width="${Math.floor(50*Math.random()+40)}%" height="1rem"></kg-skeleton>
|
|
50
50
|
</td>
|
|
@@ -53,7 +53,7 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
53
53
|
`)}
|
|
54
54
|
`:0===e.length?a`
|
|
55
55
|
<tr>
|
|
56
|
-
<td colspan="${
|
|
56
|
+
<td colspan="${g.length+(this.selectable?1:0)}" class="empty-state">
|
|
57
57
|
Veri bulunamadı.
|
|
58
58
|
</td>
|
|
59
59
|
</tr>
|
|
@@ -64,7 +64,7 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
64
64
|
>
|
|
65
65
|
${this.selectable?a`
|
|
66
66
|
<td class="checkbox-cell">
|
|
67
|
-
${
|
|
67
|
+
${d?a`
|
|
68
68
|
<kg-radio
|
|
69
69
|
.checked="${this._isSelected(e)}"
|
|
70
70
|
style="pointer-events: none;"
|
|
@@ -79,7 +79,7 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
79
79
|
</td>
|
|
80
80
|
`:""}
|
|
81
81
|
|
|
82
|
-
${
|
|
82
|
+
${g.map(t=>a`
|
|
83
83
|
<td class="${t.align?`align-${t.align}`:""}">
|
|
84
84
|
${this._renderCellContent(t,e)}
|
|
85
85
|
</td>
|
|
@@ -90,18 +90,18 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
90
90
|
</table>
|
|
91
91
|
</div>
|
|
92
92
|
|
|
93
|
-
${this.pagination&&
|
|
93
|
+
${this.pagination&&s>0?a`
|
|
94
94
|
<div class="pagination-footer">
|
|
95
95
|
<div style="display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;">
|
|
96
96
|
<div class="pagination-info">
|
|
97
|
-
Toplam <strong>${
|
|
97
|
+
Toplam <strong>${s}</strong> kayıttan <strong>${(r-1)*i+1} - ${Math.min(r*i,s)}</strong> arası gösteriliyor
|
|
98
98
|
</div>
|
|
99
99
|
|
|
100
100
|
<div class="page-size-selector">
|
|
101
101
|
<span>Sayfa başına:</span>
|
|
102
|
-
<select class="page-size-select" @change="${this._handlePageSizeChange}">
|
|
103
|
-
${
|
|
104
|
-
<option value="${e}" ?selected="${
|
|
102
|
+
<select class="page-size-select" .value="${String(i)}" @change="${this._handlePageSizeChange}">
|
|
103
|
+
${n.map(e=>a`
|
|
104
|
+
<option value="${e}" ?selected="${i===e}">${e}</option>
|
|
105
105
|
`)}
|
|
106
106
|
</select>
|
|
107
107
|
</div>
|
|
@@ -133,8 +133,8 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
133
133
|
</kg-button>
|
|
134
134
|
|
|
135
135
|
<!-- Page Numbers -->
|
|
136
|
-
${
|
|
137
|
-
${t>0&&e-
|
|
136
|
+
${p.map((e,t)=>a`
|
|
137
|
+
${t>0&&e-p[t-1]>1?a`<span class="pagination-info">...</span>`:""}
|
|
138
138
|
<kg-button
|
|
139
139
|
@click="${()=>this._changePage(e)}"
|
|
140
140
|
color="${this.currentPage===e?"primary":"secondary"}"
|
|
@@ -148,7 +148,7 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
148
148
|
|
|
149
149
|
<!-- Next Page -->
|
|
150
150
|
<kg-button
|
|
151
|
-
?disabled="${this.currentPage===
|
|
151
|
+
?disabled="${this.currentPage===o}"
|
|
152
152
|
@click="${()=>this._changePage(this.currentPage+1)}"
|
|
153
153
|
text
|
|
154
154
|
color="secondary"
|
|
@@ -160,8 +160,8 @@ var e=Object.defineProperty,t=(t,i,r)=>((t,i,r)=>i in t?e(t,i,{enumerable:!0,con
|
|
|
160
160
|
|
|
161
161
|
<!-- Last Page -->
|
|
162
162
|
<kg-button
|
|
163
|
-
?disabled="${this.currentPage===
|
|
164
|
-
@click="${()=>this._changePage(
|
|
163
|
+
?disabled="${this.currentPage===o}"
|
|
164
|
+
@click="${()=>this._changePage(o)}"
|
|
165
165
|
text
|
|
166
166
|
color="secondary"
|
|
167
167
|
size="medium"
|
package/dist/react/KgDataGrid.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useState as t,useRef as
|
|
1
|
+
import e,{useState as t,useRef as n,useMemo as r,useEffect as a}from"react";import{createPortal as o}from"react-dom";import{o as c}from"../chunks/create-component-jQ1kjF1Z.js";import{kgdatagrid as s}from"../components/kg-datagrid.js";"undefined"==typeof customElements||customElements.get("kg-datagrid")||customElements.define("kg-datagrid",s);const l=c({tagName:"kg-datagrid",elementClass:s,react:e,events:{onSelectionChange:"selection-change",onKgSelectionChange:"selection-change",onPageChange:"page-change",onKgPageChange:"page-change",onPageSizeChange:"page-size-change",onKgPageSizeChange:"page-size-change",onSort:"sort",onKgSort:"sort"}}),i=({columns:c,...s})=>{const[i,d]=t(/* @__PURE__ */new Map),g=n(null),m=n(/* @__PURE__ */new WeakMap),u=n(/* @__PURE__ */new WeakMap),h=r(()=>{if(!c)return[];const t=n=>n.map(n=>{const r={...n};return n.render&&(r.render=t=>{const r=n.render(t);if(!e.isValidElement(r))return r;let a=m.current.get(t);a||(a=/* @__PURE__ */new Map,m.current.set(t,a));let o=a.get(n.field);return o||(o=document.createElement("div"),o.className="kg-react-cell-portal",o.style.display="contents",o.dataset.reactCellId=Math.random().toString(36).substr(2,9),a.set(n.field,o)),o._reactContent=r,o}),n.headerRender&&(r.headerRender=t=>{const r=n.headerRender(t);if(!e.isValidElement(r))return r;let a=u.current.get(n);return a||(a=document.createElement("div"),a.className="kg-react-cell-portal",a.style.display="contents",a.dataset.reactCellId="h-"+Math.random().toString(36).substr(2,9),u.current.set(n,a)),a._reactContent=r,a}),n.children&&n.children.length>0&&(r.children=t(n.children)),r});return t(c)},[c]);return a(()=>{const e=g.current;if(!e)return;const t=e.shadowRoot||e,n=()=>{const e=t.querySelectorAll(".kg-react-cell-portal"),n=/* @__PURE__ */new Map;e.forEach(e=>{e._reactContent&&n.set(e,e._reactContent)}),d(e=>{if(e.size!==n.size)return n;for(const[t,r]of n)if(e.get(t)!==r)return n;return e})},r=new MutationObserver(()=>{n()});return r.observe(t,{childList:!0,subtree:!0,attributes:!1,characterData:!1}),n(),()=>r.disconnect()},[h,s.data]),e.createElement(e.Fragment,null,e.createElement(l,{ref:g,columns:h,...s}),Array.from(i.entries()).map(([e,t])=>o(t,e,e.dataset.reactCellId)))};export{i as KgDataGrid};
|
package/package.json
CHANGED
|
@@ -63,7 +63,9 @@ declare global {
|
|
|
63
63
|
onSelectionChange?: (e: any) => void;
|
|
64
64
|
onSort?: (e: any) => void;
|
|
65
65
|
onPageChange?: (e: any) => void;
|
|
66
|
+
onKgPageChange?: (e: any) => void;
|
|
66
67
|
onPageSizeChange?: (e: any) => void;
|
|
68
|
+
onKgPageSizeChange?: (e: any) => void;
|
|
67
69
|
[key: string]: any;
|
|
68
70
|
};
|
|
69
71
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -209,7 +209,9 @@ declare global {
|
|
|
209
209
|
onSelectionChange?: (e: any) => void;
|
|
210
210
|
onSort?: (e: any) => void;
|
|
211
211
|
onPageChange?: (e: any) => void;
|
|
212
|
+
onKgPageChange?: (e: any) => void;
|
|
212
213
|
onPageSizeChange?: (e: any) => void;
|
|
214
|
+
onKgPageSizeChange?: (e: any) => void;
|
|
213
215
|
[key: string]: any;
|
|
214
216
|
};
|
|
215
217
|
'kg-datepicker': {
|