@gravitee/ui-components 3.25.3-typescript-50960c3 → 3.25.3-typescript-9d19b68
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/package.json +5 -13
- package/src/atoms/gv-autocomplete.js +422 -1
- package/src/atoms/gv-button.js +397 -1
- package/src/atoms/gv-checkbox.js +178 -1
- package/src/atoms/gv-date-picker-calendar.js +812 -1
- package/src/atoms/gv-date-picker-cell.js +174 -1
- package/src/atoms/gv-date-picker.js +638 -1
- package/src/atoms/gv-file-upload.js +348 -1
- package/src/atoms/gv-icon.js +93 -1
- package/src/atoms/gv-image.js +135 -1
- package/src/atoms/gv-input-message.js +78 -1
- package/src/atoms/gv-input.js +508 -1
- package/src/atoms/gv-link.js +204 -1
- package/src/atoms/gv-message.js +133 -1
- package/src/atoms/gv-metric.js +112 -1
- package/src/atoms/gv-relative-time.js +143 -1
- package/src/atoms/gv-select-native.js +363 -1
- package/src/atoms/gv-select.js +413 -1
- package/src/atoms/gv-spinner.js +54 -1
- package/src/atoms/gv-state.js +125 -1
- package/src/atoms/gv-switch.js +235 -1
- package/src/atoms/gv-tag.js +162 -1
- package/src/atoms/gv-text.js +160 -1
- package/src/charts/gv-chart-bar.js +101 -1
- package/src/charts/gv-chart-gauge.js +92 -1
- package/src/charts/gv-chart-histogram.js +78 -1
- package/src/charts/gv-chart-line.js +218 -1
- package/src/charts/gv-chart-map.js +111 -1
- package/src/charts/gv-chart-pie.js +89 -1
- package/src/index.js +77 -1
- package/src/lib/cron-expression.js +176 -1
- package/src/lib/date.js +43 -1
- package/src/lib/events.js +26 -1
- package/src/lib/http-client-schema-form.js +67 -1
- package/src/lib/http.js +237 -1
- package/src/lib/i18n.js +93 -1
- package/src/lib/item.js +110 -1
- package/src/lib/properties.js +171 -1
- package/src/lib/schema-form.js +39 -1
- package/src/lib/studio.js +144 -1
- package/src/lib/style.js +39 -1
- package/src/lib/text-format.js +65 -1
- package/src/lib/theme.js +60 -1
- package/src/lib/utils.js +106 -1
- package/src/mixins/chart-element.js +153 -1
- package/src/mixins/input-element.js +136 -1
- package/src/mixins/item-resource.js +102 -1
- package/src/mixins/keyboard-element.js +62 -1
- package/src/mixins/update-after-browser.js +30 -1
- package/src/mixins/with-resize-observer.js +62 -1
- package/src/mixins/with-skeleton-attribute.js +109 -1
- package/src/molecules/gv-card-full.js +209 -1
- package/src/molecules/gv-card-list.js +101 -1
- package/src/molecules/gv-card.js +130 -1
- package/src/molecules/gv-category-list.js +56 -1
- package/src/molecules/gv-category.js +163 -1
- package/src/molecules/gv-code.js +334 -1
- package/src/molecules/gv-confirm.js +175 -1
- package/src/molecules/gv-cron-editor.js +685 -1
- package/src/molecules/gv-dropdown-menu.js +108 -1
- package/src/molecules/gv-expandable.js +116 -1
- package/src/molecules/gv-expression-language.js +263 -1
- package/src/molecules/gv-identity-picture.js +139 -1
- package/src/molecules/gv-list.js +214 -1
- package/src/molecules/gv-metrics.js +147 -1
- package/src/molecules/gv-modal.js +203 -1
- package/src/molecules/gv-nav.js +180 -1
- package/src/molecules/gv-option.js +230 -1
- package/src/molecules/gv-plans.js +400 -1
- package/src/molecules/gv-popover.js +323 -1
- package/src/molecules/gv-promote.js +203 -1
- package/src/molecules/gv-rating-list.js +341 -1
- package/src/molecules/gv-rating.js +234 -1
- package/src/molecules/gv-row-expandable.js +42 -1
- package/src/molecules/gv-row.js +205 -1
- package/src/molecules/gv-stats.js +110 -1
- package/src/molecules/gv-stepper.js +274 -1
- package/src/molecules/gv-table.js +644 -1
- package/src/molecules/gv-tree.js +238 -1
- package/src/organisms/gv-documentation.js +205 -1
- package/src/organisms/gv-header.js +276 -1
- package/src/organisms/gv-http-client.js +258 -1
- package/src/organisms/gv-menu.js +258 -1
- package/src/organisms/gv-newsletter-subscription.js +258 -1
- package/src/organisms/gv-pagination.js +179 -1
- package/src/organisms/gv-properties.js +860 -1
- package/src/organisms/gv-resizable-views.js +371 -1
- package/src/organisms/gv-resources.js +496 -1
- package/src/organisms/gv-schema-form-array.js +237 -1
- package/src/organisms/gv-schema-form-control-object.js +141 -1
- package/src/organisms/gv-schema-form-control.js +419 -1
- package/src/organisms/gv-schema-form.js +700 -1
- package/src/organisms/gv-tabs.js +201 -1
- package/src/organisms/gv-user-menu.js +298 -1
- package/src/organisms/gv-vertical-menu.js +119 -1
- package/src/policy-studio/gv-flow-step.js +443 -1
- package/src/policy-studio/gv-flow.js +595 -1
- package/src/policy-studio/gv-policy-studio-menu.js +689 -1
- package/src/policy-studio/gv-policy-studio.js +1712 -1
- package/src/styles/empty.js +35 -1
- package/src/styles/input.js +262 -1
- package/src/styles/link.js +31 -1
- package/src/styles/shapes.js +17 -1
- package/src/styles/skeleton.js +52 -1
- package/src/styles/zoom.js +39 -1
- package/src/theme/gv-theme.js +197 -1
- package/wc/gv-autocomplete.js +1 -1
- package/wc/gv-button.js +1 -1
- package/wc/gv-card-full.js +1 -1
- package/wc/gv-card-list.js +1 -1
- package/wc/gv-card.js +1 -1
- package/wc/gv-category-list.js +1 -1
- package/wc/gv-category.js +1 -1
- package/wc/gv-chart-bar.js +1 -1
- package/wc/gv-chart-gauge.js +1 -1
- package/wc/gv-chart-histogram.js +1 -1
- package/wc/gv-chart-line.js +1 -1
- package/wc/gv-chart-map.js +1 -1
- package/wc/gv-chart-pie.js +1 -1
- package/wc/gv-checkbox.js +1 -1
- package/wc/gv-code.js +1 -1
- package/wc/gv-confirm.js +1 -1
- package/wc/gv-cron-editor.js +1 -1
- package/wc/gv-date-picker-calendar.js +1 -1
- package/wc/gv-date-picker-cell.js +1 -1
- package/wc/gv-date-picker.js +1 -1
- package/wc/gv-documentation.js +1 -1
- package/wc/gv-dropdown-menu.js +1 -1
- package/wc/gv-expandable.js +1 -1
- package/wc/gv-expression-language.js +1 -1
- package/wc/gv-file-upload.js +1 -1
- package/wc/gv-flow-step.js +1 -1
- package/wc/gv-flow.js +1 -1
- package/wc/gv-header.js +1 -1
- package/wc/gv-http-client.js +1 -1
- package/wc/gv-icon.js +1 -1
- package/wc/gv-identity-picture.js +1 -1
- package/wc/gv-image.js +1 -1
- package/wc/gv-input-message.js +1 -1
- package/wc/gv-input.js +1 -1
- package/wc/gv-link.js +1 -1
- package/wc/gv-list.js +1 -1
- package/wc/gv-menu.js +1 -1
- package/wc/gv-message.js +1 -1
- package/wc/gv-metric.js +1 -1
- package/wc/gv-metrics.js +1 -1
- package/wc/gv-modal.js +1 -1
- package/wc/gv-nav.js +1 -1
- package/wc/gv-newsletter-subscription.js +1 -1
- package/wc/gv-option.js +1 -1
- package/wc/gv-pagination.js +1 -1
- package/wc/gv-plans.js +1 -1
- package/wc/gv-policy-studio-menu.js +1 -1
- package/wc/gv-policy-studio.js +1 -1
- package/wc/gv-popover.js +1 -1
- package/wc/gv-promote.js +1 -1
- package/wc/gv-properties.js +1 -1
- package/wc/gv-rating-list.js +1 -1
- package/wc/gv-rating.js +1 -1
- package/wc/gv-relative-time.js +1 -1
- package/wc/gv-resizable-views.js +1 -1
- package/wc/gv-resources.js +1 -1
- package/wc/gv-row-expandable.js +1 -1
- package/wc/gv-row.js +1 -1
- package/wc/gv-schema-form-array.js +1 -1
- package/wc/gv-schema-form-control-object.js +1 -1
- package/wc/gv-schema-form-control.js +1 -1
- package/wc/gv-schema-form.js +1 -1
- package/wc/gv-select-native.js +1 -1
- package/wc/gv-select.js +1 -1
- package/wc/gv-spinner.js +1 -1
- package/wc/gv-state.js +1 -1
- package/wc/gv-stats.js +1 -1
- package/wc/gv-stepper.js +1 -1
- package/wc/gv-switch.js +1 -1
- package/wc/gv-table.js +1 -1
- package/wc/gv-tabs.js +1 -1
- package/wc/gv-tag.js +1 -1
- package/wc/gv-text.js +1 -1
- package/wc/gv-theme.js +1 -1
- package/wc/gv-tree.js +1 -1
- package/wc/gv-user-menu.js +1 -1
- package/wc/gv-vertical-menu.js +1 -1
|
@@ -1 +1,644 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvTable=void 0;const t=require("lit"),e=require("../styles/skeleton"),i=require("../styles/empty"),s=require("../styles/link"),r=require("lit/directives/class-map"),o=require("lit/directives/repeat"),n=require("../lib/events"),a=require("../lib/i18n"),l=require("lit/directives/until"),h=require("lit/directives/style-map"),d=require("../mixins/with-resize-observer"),g=require("lit/directives/if-defined");require("../atoms/gv-image"),require("../organisms/gv-pagination");const c=require("../lib/style");class p extends((0,d.withResizeObserver)(t.LitElement)){static get properties(){return{items:{type:Array},title:{type:String},order:{type:String},options:{type:Array},noheader:{type:Boolean},nosort:{type:Boolean},rowsheight:{type:String},rowheight:{type:String},emptymessage:{type:String},format:{type:Function},compareFn:{type:Function},selected:{type:Array,reflect:!0},total:{type:String},skeleton:{type:Boolean},_items:{type:Array,attribute:!1},_skeleton:{type:Boolean,attribute:!1},_error:{type:Boolean,attribute:!1},_empty:{type:Boolean,attribute:!1},_itemsProvider:{type:Array,attribute:!1},_page:{type:Number,attribute:!1}}}static get styles(){return[s.link,e.skeleton,i.empty,t.css`:host{--selected--bgc:var(--gv-table-selected--bgc, var(--gv-theme-color, #5a7684));--hover-bgc:var(--gv-table-hover--bgc, var(--gv-theme-neutral-color-lighter, #fafafa));--bgc:var(--gv-table--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));--bdc:var(--gv-table--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));display:block;height:100%;margin:.2rem;box-sizing:border-box}.table{background-color:var(--bgc);flex-direction:column;height:100%;display:flex;width:100%}.rows{-ms-overflow-style:none;scrollbar-width:none;overflow:var(--gv-table-rows--ov,auto);flex:1;height:100%;transition:height 250ms ease-in-out}.rows::-webkit-scrollbar{display:none}:host([w-lt-768]) .row{height:70px}:host([w-lt-580]) .row{height:60px}:host([w-lt-400]) .row{height:50px}.theader{background-color:var(--gv-theme-neutral-color-lighter);font-weight:700;padding:0 .2rem}.row,.theader{align-items:var(--gv-table-row--ai,center);align-content:var(--gv-table-row--ac,center);border-right:solid thick transparent;display:grid}div{box-sizing:border-box}.cell{height:100%;display:var(--gv-table-cell--d,flex);align-items:center}.row:not(:last-child){box-shadow:0 5px 3px -6px var(--bdc)}.row.selected,.row:hover{background-color:var(--hover-bgc)}.row.selected{border-color:var(--selected--bgc);box-sizing:border-box}.header{border-bottom:1px solid var(--bdc);padding:var(--gv-table-header--p,2rem 4rem)}.title{margin:0;text-transform:uppercase;font-size:var(--gv-table-header--fz,var(--gv-theme-font-size-l,20px));line-height:var(--gv-table-header--fz,var(--gv-theme-font-size-l,20px));opacity:.6}.title span{font-weight:600;font-size:var(--gv-theme-font-size-s);line-height:var(--gv-theme-font-size-s);margin-left:8px;opacity:.7}gv-identity-picture{height:35px;width:35px;--gv-image--of:contain;margin-left:20px}gv-icon{transform:rotate(0);--gv-icon--s:18px}gv-icon.desc{transform:rotate(180deg)}gv-pagination{align-self:flex-end}.cell>:not(gv-tag){margin:auto;width:100%}`]}constructor(){super(),this._id=(new Date).getTime(),this.breakpoints={width:[400,580,768]},this._empty=!1,this.order="",this._page=1,this._itemsProvider=[],this.selected=[],this.compareFn=(t,e,i)=>{const s=this._getDataFromField(t,i)&&this._getDataFromField(t,i).toLowerCase?this._getDataFromField(t,i).toLowerCase():"",r=this._getDataFromField(e,i)&&this._getDataFromField(e,i).toLowerCase?this._getDataFromField(e,i).toLowerCase():"";return this.order.startsWith("-")?r.localeCompare(s):s.localeCompare(r)},this.addEventListener("gv-pagination:paginate",(t=>{this._page=t.detail.page}))}set items(t){this._skeleton=!0,Promise.resolve(t).then((t=>{t&&(this._itemsProvider=t.map(((t,e)=>(t._id=null==t.id?e:t.id,t))),this._onSortChanged(),this._empty=0===this._itemsProvider.length,this._skeleton=!1)})).catch((t=>{console.error(t),this._error=!0,this._skeleton=!1,this._itemsProvider=[]}))}get items(){return this._itemsProvider}_onSortChanged(t,e){if(e&&e.preventDefault(),this._itemsProvider&&this.order){const e=this.order.startsWith("-"),i=e?this.order.substring(1):this.order,s=t||i;t&&(this.order=i===s?e?s:"-"+s:s),this._itemsProvider=this._itemsProvider.sort(((t,e)=>this.compareFn(t,e,s))),t&&(0,n.dispatchCustomEvent)(this,"sort",{order:this.order})}}get _items(){if(this._itemsProvider){if(this.options&&this.options.paging&&this.options.paging<this._itemsProvider.length){const t=(this._page-1)*this.options.paging;return[...this._itemsProvider].splice(t,this.options.paging)}return this._itemsProvider}return[]}_getItemId(t){return null==t.id?t._id:t.id}_onSelect(t,e){if(!this._skeleton&&!e.target.dataset.preventSelect)if(this.options.selectable){const e=this._getItemId(t);this._isSelected(t)?this.selected=this.selected.filter((t=>e!==t)):"multi"===this.options.selectable?this.selected=[...this.selected,e]:this.selected=[e],(0,n.dispatchCustomEvent)(this,"select",{items:this.selectedItems,options:this.options})}else(0,n.dispatchCustomEvent)(this,"select",{items:[t]})}get selectedItems(){return this.selected&&this._itemsProvider?this._itemsProvider.filter((t=>this.selected&&this.selected.includes(this._getItemId(t)))):[]}_onMouseEnter(t){this.selected&&this.selected.length>0||this._skeleton||(0,n.dispatchCustomEvent)(this,"mouseenter",{item:t})}_onMouseLeave(){this.selected&&this.selected.length>0||this._skeleton||(0,n.dispatchCustomEvent)(this,"mouseleave")}_renderHeader(e){if(this.noheader)return"";{const i={...e,height:this.rowheight,"grid-auto-rows":this.rowheight?null:"minmax(80px, auto)"};return t.html`<div class="${(0,r.classMap)({theader:!0})}" style="${(0,h.styleMap)(i)}">${this.options&&this.options.data&&this._items&&this._items.length?(0,o.repeat)(this.options.data,(t=>t),(e=>{const i=this.order&&this.order.startsWith("-")?this.order.substring(1):this.order,s=this.format&&e.label?this.format(e.label):e.label,o="function"==typeof e.headerStyle?e.headerStyle(s):e.headerStyle;return t.html`<div style="${o||""}">${this.order&&!this.nosort?t.html`<gv-button link @click="${this._onSortChanged.bind(this,e.field||e.tag)}">${(0,l.until)(s)}</gv-button>${i===e.tag||i===e.field&&"image"!==e.type?t.html`<gv-icon class="${(0,r.classMap)({desc:this.order.startsWith("-")})}" shape="design:triangle"></gv-icon>`:""}`:(0,l.until)(s)}</div>`})):""}</div>`}}_renderIcon(e,i,s){const r="function"==typeof s.icon?s.icon(e):s.icon,o="function"==typeof s.iconTitle?s.iconTitle(e):s.iconTitle;return r?t.html`<gv-icon shape="${r}" title="${o}"></gv-icon>`:""}_renderComponent(t,e,i,s,r){if(i.condition&&!i.condition(t))return"";const o=document.createElement(r);o.value=s,i.attributes&&Object.keys(i.attributes).forEach((e=>{if(e.startsWith("on")){const s=e.replace("on","").toLowerCase();"click"===s&&o.classList.add("link"),o.dataset.preventSelect=!0,o.addEventListener(s,(s=>{s.stopPropagation();null==("function"==typeof i.confirm?i.confirm(t):i.confirm)&&setTimeout((()=>{i.attributes[e](t,s,o,this)}),0)}))}else if("function"==typeof i.attributes[e]){const s=i.attributes[e](t);null!=s&&(o[e]=s)}else this.format&&"string"==typeof i.attributes[e]?this.format(i.attributes[e]).then((t=>{o[e]=t})):o[e]=i.attributes[e]})),o.addEventListener("input",(t=>{this._items[e][i.field]=t.target.value}));const n="function"==typeof i.confirm?i.confirm(t):i.confirm;if(n){const e=document.createElement("gv-confirm");return this.format?this.format(n.msg).then((t=>e.message=t)):e.message=n.msg,n.danger&&(e.danger=!0),e.addEventListener("click",(t=>t.stopPropagation())),e.addEventListener("gv-confirm:ok",(e=>{e.stopPropagation(),i.attributes.onClick(t,e,o)})),e.appendChild(o),e}return o}_renderCell(t,e,i,s){if(e.type){if("image"===e.type){let s="";return e.alt&&(s="function"==typeof e.alt?e.alt(i):this._getDataFromField(i,e.alt)),this._renderImage(t,s)}if("function"==typeof e.type)return this._renderComponent(i,s,e,t,e.type(i));if(e.type.startsWith("gv-"))return this._renderComponent(i,s,e,t,e.type)}return(0,l.until)(t)}_getFormattedCellValue(t,e){let i=t.field?this._getDataFromField(e,t.field):"";return i&&("date"===t.type?i=new Date(i).toLocaleDateString((0,a.getLanguage)()):"datetime"===t.type?i=new Date(i).toLocaleString((0,a.getLanguage)()):"time"===t.type&&(i=new Date(i).toLocaleTimeString((0,a.getLanguage)()))),t.format&&(i=t.format(i)),i}_isSelected(t){return this.selected&&this.selected.includes(this._getItemId(t))}_renderRows(e){return t.html`<div class="rows" style="${(0,h.styleMap)({height:this.rowsheight,"user-select":this.options.selectable?"none":""})}" @mouseleave="${this._onMouseLeave.bind(this)}">${this._items&&this._items.length?(0,o.repeat)(this._items,(t=>t),((i,s)=>t.html`<div class="${(0,r.classMap)({row:!0,skeleton:this._skeleton,selected:this._isSelected(i)})}" style="${(0,h.styleMap)({...e,height:this.rowheight,"grid-auto-rows":this.rowheight?null:"minmax(80px, auto)",cursor:this.options.selectable?"pointer":"","border-color":this.options.selectable&&this._isSelected(i)?"var(--selected--bgc)":"","column-gap":"var(--gv-table--colmg, 0.2rem)"})}" @click="${this._onSelect.bind(this,i)}" @mouseenter="${this._onMouseEnter.bind(this,i)}">${this.options&&this.options.data?(0,o.repeat)(this.options.data,(t=>t),(e=>{const r="function"==typeof e.style?e.style(i):e.style,o=this._getFormattedCellValue(e,i);return t.html`<div class="cell" style="${(0,g.ifDefined)(r)}" title="${o}">${this._renderCell(o,e,i,s)}${this._renderTag(e,i)}${e.icon?this._renderIcon(i,s,e):""}</div>`})):""}</div>`)):""}</div>`}_renderItems(){let e=this.options.data.map((t=>t.width?t.width:"image"===t.type?"80px":"icon"===t.type?"40px":null));const i=e.filter((t=>null!==t)),s=i.reduce(((t,e)=>t+parseInt(e.replace("px",""),10)),0);e=e.map((t=>{if(null==t){const t=(0,c.getCssVar)(this,"--gv-table--colmg","0.2rem");return`calc((100% - ( ${s}px + ${this.options.data.length-1} * ${t} ) ) / ${this.options.data.length-i.length})`}return t}));const r={"grid-template-columns":e.join(" ")};return t.html`${this._renderHeader(r)} ${this._renderRows(r)} ${this._renderPagination()}`}_renderPagination(){if(this.options&&this.options.paging&&this._itemsProvider){const e={first:1,last:this._itemsProvider.length/this.options.paging,total:this._itemsProvider.length,current_page:this._page,total_pages:this._itemsProvider.length/this.options.paging};return t.html`<gv-pagination .data="${e}" widget="true"></gv-pagination>`}}_getDataFromField(t,e){return"function"==typeof e?e(t):e.split(".").reduce(((t,e)=>t&&t[e]),t)}_renderTag(e,i){if(e.tag){let s;if(s="function"==typeof e.tag?e.tag(i):e.format?e.format(this._getDataFromField(i,e.tag)):this._getDataFromField(i,e.tag),s)return t.html`<gv-tag ?skeleton="${this._skeleton}">${s}</gv-tag>`}return""}_onImageLoaded(){this._skeleton=!1}_renderImage(e,i){return t.html`<gv-identity-picture .picture="${e}" .display_name="${i}"></gv-identity-picture>`}updated(t){this._onSortChanged()}render(){if(this._error)return t.html`<div class="error">${(0,a.i18n)("gv-table.error")}</div>`;const e={table:!0,skeleton:this._skeleton||this.skeleton},i={height:this.rowsheight?this.rowsheight:""};return t.html`<div class="${(0,r.classMap)(e)}" style="${(0,h.styleMap)({display:this.rowsheight?"block":"flex"})}">${this.title?t.html`<div class="header"><h3 class="title">${this.title} ${this._empty?"":t.html`<span>(${this.total||this._items&&this._items.length})</span>`}</h3></div>`:""} ${!this._empty&&this.options&&this.options.data?this._renderItems():t.html`<div class="empty" style="${(0,h.styleMap)(i)}">${this.emptymessage?this.emptymessage:(0,a.i18n)("gv-table.empty")}</div>`}</div>`}}exports.GvTable=p,window.customElements.define("gv-table",p);
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { css, LitElement, html } from 'lit';
|
|
17
|
+
import { skeleton } from '../styles/skeleton';
|
|
18
|
+
import { empty } from '../styles/empty';
|
|
19
|
+
import { link } from '../styles/link';
|
|
20
|
+
import { classMap } from 'lit/directives/class-map';
|
|
21
|
+
import { repeat } from 'lit/directives/repeat';
|
|
22
|
+
import { dispatchCustomEvent } from '../lib/events';
|
|
23
|
+
import { getLanguage, i18n } from '../lib/i18n';
|
|
24
|
+
import { until } from 'lit/directives/until';
|
|
25
|
+
import { styleMap } from 'lit/directives/style-map';
|
|
26
|
+
import { withResizeObserver } from '../mixins/with-resize-observer';
|
|
27
|
+
import { ifDefined } from 'lit/directives/if-defined';
|
|
28
|
+
import '../atoms/gv-image';
|
|
29
|
+
import '../organisms/gv-pagination';
|
|
30
|
+
import { getCssVar } from '../lib/style';
|
|
31
|
+
/**
|
|
32
|
+
* Table component
|
|
33
|
+
*
|
|
34
|
+
* ## Details
|
|
35
|
+
* * has @theme facet
|
|
36
|
+
*
|
|
37
|
+
* @fires gv-table:select - when table row is selected
|
|
38
|
+
* @fires gv-table:mouseenter - when the pointer is entering on a table row
|
|
39
|
+
* @fires gv-table:mouseleave - when the pointer is leaving a table row
|
|
40
|
+
* @fires gv-table:sort - when the order is changed
|
|
41
|
+
*
|
|
42
|
+
* @attr {Array<any>} items - A list of items to display
|
|
43
|
+
* @attr {String} title - A title to display
|
|
44
|
+
* @attr {String} order - If defined, the table will be ordered by the field. Start with '-' to sort in desc
|
|
45
|
+
* @attr {Array<any>} options - The list of options to display
|
|
46
|
+
* @attr {Boolean} noheader - Used to hide the table header
|
|
47
|
+
* @attr {Boolean} nosort - Used to disable the click on header to sort
|
|
48
|
+
* @attr {String} rowsheight - The height of the table rows
|
|
49
|
+
* @attr {String} rowheight - The height of the table single row
|
|
50
|
+
* @attr {String} emptymessage - The empty message to display
|
|
51
|
+
* @attr {Function} format - A function to format table headers and string cells
|
|
52
|
+
* @attr {Function} compareFn - A function to define how to sort. Default function will sort selected field ignoring case
|
|
53
|
+
* @attr {Array<any>} selected - A list of selected ids of the items displayed
|
|
54
|
+
* @attr {String} total - Total of data displayed on the table (useful with in case of pagination)
|
|
55
|
+
* @attr {Boolean} skeleton - Force gv-table to be in skeleton mode
|
|
56
|
+
*
|
|
57
|
+
* @cssprop {Color} [--gv-table-selected--bgc=var(--gv-theme-color, #5a7684)] - Selected background color
|
|
58
|
+
* @cssprop {Color} [--gv-table-hover--bgc=var(--gv-theme-neutral-color-lighter, #fafafa)] - Row background color on hover
|
|
59
|
+
* @cssprop {Color} [--gv-table--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
|
|
60
|
+
* @cssprop {Color} [--gv-table--bdc=var(--gv-theme-neutral-color-dark, #d9d9d9)] - Border color
|
|
61
|
+
* @cssprop {String} [--gv-table-header--fz=var(--gv-theme-font-size-l, 20px)] - Title font size
|
|
62
|
+
* @cssprop {Length} [--gv-table-header--p=2rem 4rem] - Title padding
|
|
63
|
+
* @cssprop {String} [--gv-table-rows--ov=auto] - Overflow on table
|
|
64
|
+
* @cssprop {Length} [--gv-table--colmg=0.2rem] - Column gap
|
|
65
|
+
* @cssprop {String} [--gv-table-row--ai=center] - Row align-items
|
|
66
|
+
* @cssprop {String} [--gv-table-row--ac=center] - Row align-content
|
|
67
|
+
* @cssprop {String} [--gv-table-cell--d=flex] - Cell display
|
|
68
|
+
*/
|
|
69
|
+
export class GvTable extends withResizeObserver(LitElement) {
|
|
70
|
+
static get properties() {
|
|
71
|
+
return {
|
|
72
|
+
items: { type: Array },
|
|
73
|
+
title: { type: String },
|
|
74
|
+
order: { type: String },
|
|
75
|
+
options: { type: Array },
|
|
76
|
+
noheader: { type: Boolean },
|
|
77
|
+
nosort: { type: Boolean },
|
|
78
|
+
rowsheight: { type: String },
|
|
79
|
+
rowheight: { type: String },
|
|
80
|
+
emptymessage: { type: String },
|
|
81
|
+
format: { type: Function },
|
|
82
|
+
compareFn: { type: Function },
|
|
83
|
+
selected: { type: Array, reflect: true },
|
|
84
|
+
total: { type: String },
|
|
85
|
+
skeleton: { type: Boolean },
|
|
86
|
+
_items: { type: Array, attribute: false },
|
|
87
|
+
_skeleton: { type: Boolean, attribute: false },
|
|
88
|
+
_error: { type: Boolean, attribute: false },
|
|
89
|
+
_empty: { type: Boolean, attribute: false },
|
|
90
|
+
_itemsProvider: { type: Array, attribute: false },
|
|
91
|
+
_page: { type: Number, attribute: false },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
static get styles() {
|
|
95
|
+
return [
|
|
96
|
+
link,
|
|
97
|
+
skeleton,
|
|
98
|
+
empty,
|
|
99
|
+
// language=CSS
|
|
100
|
+
css `
|
|
101
|
+
:host {
|
|
102
|
+
--selected--bgc: var(--gv-table-selected--bgc, var(--gv-theme-color, #5a7684));
|
|
103
|
+
--hover-bgc: var(--gv-table-hover--bgc, var(--gv-theme-neutral-color-lighter, #fafafa));
|
|
104
|
+
--bgc: var(--gv-table--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));
|
|
105
|
+
--bdc: var(--gv-table--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));
|
|
106
|
+
display: block;
|
|
107
|
+
height: 100%;
|
|
108
|
+
margin: 0.2rem;
|
|
109
|
+
box-sizing: border-box;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.table {
|
|
113
|
+
background-color: var(--bgc);
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
height: 100%;
|
|
116
|
+
display: flex;
|
|
117
|
+
width: 100%;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.rows {
|
|
121
|
+
-ms-overflow-style: none;
|
|
122
|
+
scrollbar-width: none;
|
|
123
|
+
overflow: var(--gv-table-rows--ov, auto);
|
|
124
|
+
flex: 1;
|
|
125
|
+
height: 100%;
|
|
126
|
+
transition: height 250ms ease-in-out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.rows::-webkit-scrollbar {
|
|
130
|
+
display: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
:host([w-lt-768]) .row {
|
|
134
|
+
height: 70px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
:host([w-lt-580]) .row {
|
|
138
|
+
height: 60px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
:host([w-lt-400]) .row {
|
|
142
|
+
height: 50px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.theader {
|
|
146
|
+
background-color: var(--gv-theme-neutral-color-lighter);
|
|
147
|
+
font-weight: bold;
|
|
148
|
+
padding: 0 0.2rem;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.row,
|
|
152
|
+
.theader {
|
|
153
|
+
align-items: var(--gv-table-row--ai, center);
|
|
154
|
+
align-content: var(--gv-table-row--ac, center);
|
|
155
|
+
border-right: solid thick transparent;
|
|
156
|
+
display: grid;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
div {
|
|
160
|
+
box-sizing: border-box;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.cell {
|
|
164
|
+
height: 100%;
|
|
165
|
+
display: var(--gv-table-cell--d, flex);
|
|
166
|
+
align-items: center;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.row:not(:last-child) {
|
|
170
|
+
box-shadow: 0 5px 3px -6px var(--bdc);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.row:hover,
|
|
174
|
+
.row.selected {
|
|
175
|
+
background-color: var(--hover-bgc);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.row.selected {
|
|
179
|
+
border-color: var(--selected--bgc);
|
|
180
|
+
box-sizing: border-box;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.header {
|
|
184
|
+
border-bottom: 1px solid var(--bdc);
|
|
185
|
+
padding: var(--gv-table-header--p, 2rem 4rem);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.title {
|
|
189
|
+
margin: 0;
|
|
190
|
+
text-transform: uppercase;
|
|
191
|
+
font-size: var(--gv-table-header--fz, var(--gv-theme-font-size-l, 20px));
|
|
192
|
+
line-height: var(--gv-table-header--fz, var(--gv-theme-font-size-l, 20px));
|
|
193
|
+
opacity: 0.6;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.title span {
|
|
197
|
+
font-weight: 600;
|
|
198
|
+
font-size: var(--gv-theme-font-size-s);
|
|
199
|
+
line-height: var(--gv-theme-font-size-s);
|
|
200
|
+
margin-left: 8px;
|
|
201
|
+
opacity: 0.7;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
gv-identity-picture {
|
|
205
|
+
height: 35px;
|
|
206
|
+
width: 35px;
|
|
207
|
+
--gv-image--of: contain;
|
|
208
|
+
margin-left: 20px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
gv-icon {
|
|
212
|
+
transform: rotate(0deg);
|
|
213
|
+
--gv-icon--s: 18px;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
gv-icon.desc {
|
|
217
|
+
transform: rotate(180deg);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
gv-pagination {
|
|
221
|
+
align-self: flex-end;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.cell > *:not(gv-tag) {
|
|
225
|
+
margin: auto;
|
|
226
|
+
width: 100%;
|
|
227
|
+
}
|
|
228
|
+
`,
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
constructor() {
|
|
232
|
+
super();
|
|
233
|
+
this._id = new Date().getTime();
|
|
234
|
+
this.breakpoints = {
|
|
235
|
+
width: [400, 580, 768],
|
|
236
|
+
};
|
|
237
|
+
this._empty = false;
|
|
238
|
+
this.order = '';
|
|
239
|
+
this._page = 1;
|
|
240
|
+
this._itemsProvider = [];
|
|
241
|
+
this.selected = [];
|
|
242
|
+
this.compareFn = (item, item2, value) => {
|
|
243
|
+
const itemData = this._getDataFromField(item, value) && this._getDataFromField(item, value).toLowerCase
|
|
244
|
+
? this._getDataFromField(item, value).toLowerCase()
|
|
245
|
+
: '';
|
|
246
|
+
const itemData2 = this._getDataFromField(item2, value) && this._getDataFromField(item2, value).toLowerCase
|
|
247
|
+
? this._getDataFromField(item2, value).toLowerCase()
|
|
248
|
+
: '';
|
|
249
|
+
if (this.order.startsWith('-')) {
|
|
250
|
+
return itemData2.localeCompare(itemData);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return itemData.localeCompare(itemData2);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
this.addEventListener('gv-pagination:paginate', (e) => {
|
|
257
|
+
this._page = e.detail.page;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
set items(items) {
|
|
261
|
+
this._skeleton = true;
|
|
262
|
+
Promise.resolve(items)
|
|
263
|
+
.then((items) => {
|
|
264
|
+
if (items) {
|
|
265
|
+
this._itemsProvider = items.map((item, index) => {
|
|
266
|
+
item._id = item.id == null ? index : item.id;
|
|
267
|
+
return item;
|
|
268
|
+
});
|
|
269
|
+
this._onSortChanged();
|
|
270
|
+
this._empty = this._itemsProvider.length === 0;
|
|
271
|
+
this._skeleton = false;
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
.catch((e) => {
|
|
275
|
+
console.error(e);
|
|
276
|
+
this._error = true;
|
|
277
|
+
this._skeleton = false;
|
|
278
|
+
this._itemsProvider = [];
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
get items() {
|
|
282
|
+
return this._itemsProvider;
|
|
283
|
+
}
|
|
284
|
+
_onSortChanged(field, e) {
|
|
285
|
+
if (e) {
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
}
|
|
288
|
+
if (this._itemsProvider && this.order) {
|
|
289
|
+
const desc = this.order.startsWith('-');
|
|
290
|
+
const previousOrder = desc ? this.order.substring(1) : this.order;
|
|
291
|
+
const value = field || previousOrder;
|
|
292
|
+
if (field) {
|
|
293
|
+
this.order = previousOrder === value ? (desc ? value : '-' + value) : value;
|
|
294
|
+
}
|
|
295
|
+
this._itemsProvider = this._itemsProvider.sort((item, item2) => this.compareFn(item, item2, value));
|
|
296
|
+
if (field) {
|
|
297
|
+
dispatchCustomEvent(this, 'sort', { order: this.order });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
get _items() {
|
|
302
|
+
if (this._itemsProvider) {
|
|
303
|
+
if (this.options && this.options.paging && this.options.paging < this._itemsProvider.length) {
|
|
304
|
+
const index = (this._page - 1) * this.options.paging;
|
|
305
|
+
return [...this._itemsProvider].splice(index, this.options.paging);
|
|
306
|
+
}
|
|
307
|
+
return this._itemsProvider;
|
|
308
|
+
}
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
_getItemId(item) {
|
|
312
|
+
return item.id == null ? item._id : item.id;
|
|
313
|
+
}
|
|
314
|
+
_onSelect(item, event) {
|
|
315
|
+
if (!this._skeleton && !event.target.dataset.preventSelect) {
|
|
316
|
+
if (this.options.selectable) {
|
|
317
|
+
const itemId = this._getItemId(item);
|
|
318
|
+
if (this._isSelected(item)) {
|
|
319
|
+
this.selected = this.selected.filter((id) => itemId !== id);
|
|
320
|
+
}
|
|
321
|
+
else if (this.options.selectable === 'multi') {
|
|
322
|
+
this.selected = [...this.selected, itemId];
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
this.selected = [itemId];
|
|
326
|
+
}
|
|
327
|
+
dispatchCustomEvent(this, 'select', { items: this.selectedItems, options: this.options });
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
dispatchCustomEvent(this, 'select', { items: [item] });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
get selectedItems() {
|
|
335
|
+
if (this.selected && this._itemsProvider) {
|
|
336
|
+
return this._itemsProvider.filter((item) => this.selected && this.selected.includes(this._getItemId(item)));
|
|
337
|
+
}
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
_onMouseEnter(item) {
|
|
341
|
+
if (!(this.selected && this.selected.length > 0) && !this._skeleton) {
|
|
342
|
+
dispatchCustomEvent(this, 'mouseenter', { item });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
_onMouseLeave() {
|
|
346
|
+
if (!(this.selected && this.selected.length > 0) && !this._skeleton) {
|
|
347
|
+
dispatchCustomEvent(this, 'mouseleave');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
_renderHeader(styleGridColumns) {
|
|
351
|
+
if (this.noheader) {
|
|
352
|
+
return '';
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
const style = {
|
|
356
|
+
...styleGridColumns,
|
|
357
|
+
...{
|
|
358
|
+
height: this.rowheight,
|
|
359
|
+
'grid-auto-rows': this.rowheight ? null : 'minmax(80px, auto)',
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
return html ` <div class=${classMap({ theader: true })} style=${styleMap(style)}>
|
|
363
|
+
${this.options && this.options.data && this._items && this._items.length
|
|
364
|
+
? repeat(this.options.data, (option) => option, (option) => {
|
|
365
|
+
const orderValue = this.order && this.order.startsWith('-') ? this.order.substring(1) : this.order;
|
|
366
|
+
const label = this.format && option.label ? this.format(option.label) : option.label;
|
|
367
|
+
const style = typeof option.headerStyle === 'function' ? option.headerStyle(label) : option.headerStyle;
|
|
368
|
+
return html ` <div style="${style || ''}">
|
|
369
|
+
${this.order && !this.nosort
|
|
370
|
+
? html `
|
|
371
|
+
<gv-button link @click="${this._onSortChanged.bind(this, option.field || option.tag)}">${until(label)}</gv-button>
|
|
372
|
+
${orderValue === option.tag || (orderValue === option.field && option.type !== 'image')
|
|
373
|
+
? html ` <gv-icon class=${classMap({ desc: this.order.startsWith('-') })} shape="design:triangle"></gv-icon>`
|
|
374
|
+
: ''}
|
|
375
|
+
</a>`
|
|
376
|
+
: until(label)}
|
|
377
|
+
</div>`;
|
|
378
|
+
})
|
|
379
|
+
: ''}
|
|
380
|
+
</div>`;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
_renderIcon(item, itemIndex, option) {
|
|
384
|
+
const icon = typeof option.icon === 'function' ? option.icon(item) : option.icon;
|
|
385
|
+
const iconTitle = typeof option.iconTitle === 'function' ? option.iconTitle(item) : option.iconTitle;
|
|
386
|
+
if (icon) {
|
|
387
|
+
return html ` <gv-icon shape="${icon}" title="${iconTitle}"></gv-icon>`;
|
|
388
|
+
}
|
|
389
|
+
return '';
|
|
390
|
+
}
|
|
391
|
+
_renderComponent(item, itemIndex, option, value, type) {
|
|
392
|
+
if (option.condition && !option.condition(item)) {
|
|
393
|
+
return '';
|
|
394
|
+
}
|
|
395
|
+
const element = document.createElement(type);
|
|
396
|
+
element.value = value;
|
|
397
|
+
if (option.attributes) {
|
|
398
|
+
Object.keys(option.attributes).forEach((attribute) => {
|
|
399
|
+
if (attribute.startsWith('on')) {
|
|
400
|
+
const event = attribute.replace('on', '').toLowerCase();
|
|
401
|
+
if (event === 'click') {
|
|
402
|
+
element.classList.add('link');
|
|
403
|
+
}
|
|
404
|
+
element.dataset.preventSelect = true;
|
|
405
|
+
element.addEventListener(event, (e) => {
|
|
406
|
+
e.stopPropagation();
|
|
407
|
+
const optionConfirm = typeof option.confirm === 'function' ? option.confirm(item) : option.confirm;
|
|
408
|
+
if (optionConfirm == null) {
|
|
409
|
+
setTimeout(() => {
|
|
410
|
+
option.attributes[attribute](item, e, element, this);
|
|
411
|
+
}, 0);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
else if (typeof option.attributes[attribute] === 'function') {
|
|
416
|
+
const value = option.attributes[attribute](item);
|
|
417
|
+
if (value != null) {
|
|
418
|
+
element[attribute] = value;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
if (this.format && typeof option.attributes[attribute] === 'string') {
|
|
423
|
+
this.format(option.attributes[attribute]).then((t) => {
|
|
424
|
+
element[attribute] = t;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
element[attribute] = option.attributes[attribute];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
element.addEventListener('input', (event) => {
|
|
434
|
+
this._items[itemIndex][option.field] = event.target.value;
|
|
435
|
+
});
|
|
436
|
+
const optionConfirm = typeof option.confirm === 'function' ? option.confirm(item) : option.confirm;
|
|
437
|
+
if (optionConfirm) {
|
|
438
|
+
const confirm = document.createElement('gv-confirm');
|
|
439
|
+
if (this.format) {
|
|
440
|
+
this.format(optionConfirm.msg).then((t) => (confirm.message = t));
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
confirm.message = optionConfirm.msg;
|
|
444
|
+
}
|
|
445
|
+
if (optionConfirm.danger) {
|
|
446
|
+
confirm.danger = true;
|
|
447
|
+
}
|
|
448
|
+
confirm.addEventListener('click', (e) => e.stopPropagation());
|
|
449
|
+
confirm.addEventListener('gv-confirm:ok', (e) => {
|
|
450
|
+
e.stopPropagation();
|
|
451
|
+
option.attributes.onClick(item, e, element);
|
|
452
|
+
});
|
|
453
|
+
confirm.appendChild(element);
|
|
454
|
+
return confirm;
|
|
455
|
+
}
|
|
456
|
+
return element;
|
|
457
|
+
}
|
|
458
|
+
_renderCell(formattedValue, option, item, itemIndex) {
|
|
459
|
+
if (option.type) {
|
|
460
|
+
if (option.type === 'image') {
|
|
461
|
+
let alt = '';
|
|
462
|
+
if (option.alt) {
|
|
463
|
+
if (typeof option.alt === 'function') {
|
|
464
|
+
alt = option.alt(item);
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
alt = this._getDataFromField(item, option.alt);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return this._renderImage(formattedValue, alt);
|
|
471
|
+
}
|
|
472
|
+
else if (typeof option.type === 'function') {
|
|
473
|
+
return this._renderComponent(item, itemIndex, option, formattedValue, option.type(item));
|
|
474
|
+
}
|
|
475
|
+
else if (option.type.startsWith('gv-')) {
|
|
476
|
+
return this._renderComponent(item, itemIndex, option, formattedValue, option.type);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return until(formattedValue);
|
|
480
|
+
}
|
|
481
|
+
_getFormattedCellValue(option, item) {
|
|
482
|
+
let value = option.field ? this._getDataFromField(item, option.field) : '';
|
|
483
|
+
if (value) {
|
|
484
|
+
if (option.type === 'date') {
|
|
485
|
+
value = new Date(value).toLocaleDateString(getLanguage());
|
|
486
|
+
}
|
|
487
|
+
else if (option.type === 'datetime') {
|
|
488
|
+
value = new Date(value).toLocaleString(getLanguage());
|
|
489
|
+
}
|
|
490
|
+
else if (option.type === 'time') {
|
|
491
|
+
value = new Date(value).toLocaleTimeString(getLanguage());
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (option.format) {
|
|
495
|
+
value = option.format(value);
|
|
496
|
+
}
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
_isSelected(item) {
|
|
500
|
+
return this.selected && this.selected.includes(this._getItemId(item));
|
|
501
|
+
}
|
|
502
|
+
_renderRows(styleGridColumns) {
|
|
503
|
+
return html ` <div
|
|
504
|
+
class="rows"
|
|
505
|
+
style=${styleMap({ height: this.rowsheight, 'user-select': this.options.selectable ? 'none' : '' })}
|
|
506
|
+
@mouseleave="${this._onMouseLeave.bind(this)}"
|
|
507
|
+
>
|
|
508
|
+
${this._items && this._items.length
|
|
509
|
+
? repeat(this._items, (item) => item, (item, itemIndex) => {
|
|
510
|
+
return html `
|
|
511
|
+
<div class=${classMap({
|
|
512
|
+
row: true,
|
|
513
|
+
skeleton: this._skeleton,
|
|
514
|
+
selected: this._isSelected(item),
|
|
515
|
+
})} style=${styleMap({
|
|
516
|
+
...styleGridColumns,
|
|
517
|
+
...{
|
|
518
|
+
height: this.rowheight,
|
|
519
|
+
'grid-auto-rows': this.rowheight ? null : 'minmax(80px, auto)',
|
|
520
|
+
cursor: this.options.selectable ? 'pointer' : '',
|
|
521
|
+
'border-color': this.options.selectable && this._isSelected(item) ? 'var(--selected--bgc)' : '',
|
|
522
|
+
'column-gap': 'var(--gv-table--colmg, 0.2rem)',
|
|
523
|
+
},
|
|
524
|
+
})}
|
|
525
|
+
@click="${this._onSelect.bind(this, item)}"
|
|
526
|
+
@mouseenter="${this._onMouseEnter.bind(this, item)}">
|
|
527
|
+
${this.options && this.options.data
|
|
528
|
+
? repeat(this.options.data, (option) => option, (option) => {
|
|
529
|
+
const style = typeof option.style === 'function' ? option.style(item) : option.style;
|
|
530
|
+
const formattedValue = this._getFormattedCellValue(option, item);
|
|
531
|
+
return html `<div class="cell" style="${ifDefined(style)}" title="${formattedValue}">
|
|
532
|
+
${this._renderCell(formattedValue, option, item, itemIndex)}${this._renderTag(option, item)}${option.icon
|
|
533
|
+
? this._renderIcon(item, itemIndex, option)
|
|
534
|
+
: ''}
|
|
535
|
+
</div> `;
|
|
536
|
+
})
|
|
537
|
+
: ''}
|
|
538
|
+
</div>
|
|
539
|
+
</div>`;
|
|
540
|
+
})
|
|
541
|
+
: ''}
|
|
542
|
+
</div>`;
|
|
543
|
+
}
|
|
544
|
+
_renderItems() {
|
|
545
|
+
let widthTemplate = this.options.data.map((o) => {
|
|
546
|
+
if (o.width) {
|
|
547
|
+
return o.width;
|
|
548
|
+
}
|
|
549
|
+
else if (o.type === 'image') {
|
|
550
|
+
return '80px';
|
|
551
|
+
}
|
|
552
|
+
else if (o.type === 'icon') {
|
|
553
|
+
return '40px';
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
556
|
+
});
|
|
557
|
+
const fixedData = widthTemplate.filter((width) => width !== null);
|
|
558
|
+
const fixedWidth = fixedData.reduce((acc, width) => {
|
|
559
|
+
return acc + parseInt(width.replace('px', ''), 10);
|
|
560
|
+
}, 0);
|
|
561
|
+
widthTemplate = widthTemplate.map((width) => {
|
|
562
|
+
if (width == null) {
|
|
563
|
+
const columnGap = getCssVar(this, '--gv-table--colmg', '0.2rem');
|
|
564
|
+
return `calc((100% - ( ${fixedWidth}px + ${this.options.data.length - 1} * ${columnGap} ) ) / ${this.options.data.length - fixedData.length})`;
|
|
565
|
+
}
|
|
566
|
+
return width;
|
|
567
|
+
});
|
|
568
|
+
const styleGridColumns = { 'grid-template-columns': widthTemplate.join(' ') };
|
|
569
|
+
return html ` ${this._renderHeader(styleGridColumns)} ${this._renderRows(styleGridColumns)} ${this._renderPagination()} `;
|
|
570
|
+
}
|
|
571
|
+
_renderPagination() {
|
|
572
|
+
if (this.options && this.options.paging && this._itemsProvider) {
|
|
573
|
+
const paginationData = {
|
|
574
|
+
first: 1,
|
|
575
|
+
last: this._itemsProvider.length / this.options.paging,
|
|
576
|
+
total: this._itemsProvider.length,
|
|
577
|
+
current_page: this._page,
|
|
578
|
+
total_pages: this._itemsProvider.length / this.options.paging,
|
|
579
|
+
};
|
|
580
|
+
return html `<gv-pagination .data="${paginationData}" widget="true"></gv-pagination>`;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
_getDataFromField(item, field) {
|
|
584
|
+
if (typeof field === 'function') {
|
|
585
|
+
return field(item);
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
return field.split('.').reduce((p, c) => p && p[c], item);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
_renderTag(option, item) {
|
|
592
|
+
if (option.tag) {
|
|
593
|
+
let tag;
|
|
594
|
+
if (typeof option.tag === 'function') {
|
|
595
|
+
tag = option.tag(item);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
tag = option.format ? option.format(this._getDataFromField(item, option.tag)) : this._getDataFromField(item, option.tag);
|
|
599
|
+
}
|
|
600
|
+
if (tag) {
|
|
601
|
+
return html ` <gv-tag ?skeleton="${this._skeleton}">${tag}</gv-tag>`;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return '';
|
|
605
|
+
}
|
|
606
|
+
_onImageLoaded() {
|
|
607
|
+
this._skeleton = false;
|
|
608
|
+
}
|
|
609
|
+
_renderImage(picture, alt) {
|
|
610
|
+
return html `<gv-identity-picture .picture="${picture}" .display_name="${alt}"></gv-identity-picture>`;
|
|
611
|
+
}
|
|
612
|
+
updated(props) {
|
|
613
|
+
this._onSortChanged();
|
|
614
|
+
}
|
|
615
|
+
render() {
|
|
616
|
+
if (this._error) {
|
|
617
|
+
return html `<div class="error">${i18n('gv-table.error')}</div>`;
|
|
618
|
+
}
|
|
619
|
+
const classes = {
|
|
620
|
+
table: true,
|
|
621
|
+
skeleton: this._skeleton || this.skeleton,
|
|
622
|
+
};
|
|
623
|
+
const emptyStyle = {
|
|
624
|
+
height: this.rowsheight ? this.rowsheight : '',
|
|
625
|
+
};
|
|
626
|
+
return html `
|
|
627
|
+
<div class=${classMap(classes)} style="${styleMap({ display: this.rowsheight ? 'block' : 'flex' })}">
|
|
628
|
+
${this.title
|
|
629
|
+
? html ` <div class="header">
|
|
630
|
+
<h3 class="title">
|
|
631
|
+
${this.title} ${!this._empty ? html `<span>(${this.total || (this._items && this._items.length)})</span>` : ''}
|
|
632
|
+
</h3>
|
|
633
|
+
</div>`
|
|
634
|
+
: ''}
|
|
635
|
+
${!this._empty && this.options && this.options.data
|
|
636
|
+
? this._renderItems()
|
|
637
|
+
: html ` <div class="empty" style="${styleMap(emptyStyle)}">
|
|
638
|
+
${this.emptymessage ? this.emptymessage : i18n('gv-table.empty')}
|
|
639
|
+
</div>`}
|
|
640
|
+
</div>
|
|
641
|
+
`;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
window.customElements.define('gv-table', GvTable);
|