kempo-ui 0.0.76 → 0.0.78
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/.github/skills/get-icon/SKILL.md +144 -0
- package/.github/skills/highlight-code/SKILL.md +57 -0
- package/README.md +83 -1
- package/bin/get_icon.js +106 -0
- package/bin/highlight_code.js +39 -0
- package/bin/icon.js +131 -0
- package/bin/list_icons.js +70 -0
- package/dist/components/Resize.js +1 -0
- package/dist/components/Table.js +88 -78
- package/dist/components/Tree.js +1 -1
- package/docs/components/icon.html +28 -6
- package/docs/components/photo-viewer.html +7 -7
- package/docs/components/tree.html +26 -6
- package/docs/icons/account-circle.svg +1 -1
- package/docs/icons/add.svg +1 -1
- package/docs/icons/arrow-circle.svg +1 -1
- package/docs/icons/arrow-line.svg +1 -1
- package/docs/icons/arrow.svg +1 -1
- package/docs/icons/arrow_drop_down.svg +1 -1
- package/docs/icons/cards.svg +1 -1
- package/docs/icons/check.svg +1 -1
- package/docs/icons/chevron-double.svg +1 -1
- package/docs/icons/chevron-line.svg +1 -1
- package/docs/icons/chevron.svg +1 -1
- package/docs/icons/close.svg +1 -1
- package/docs/icons/code.svg +1 -1
- package/docs/icons/code_blocks.svg +1 -1
- package/docs/icons/copy.svg +1 -1
- package/docs/icons/delete.svg +1 -1
- package/docs/icons/drag-handle.svg +1 -1
- package/docs/icons/edit.svg +1 -1
- package/docs/icons/error.svg +1 -1
- package/docs/icons/export-file.svg +1 -1
- package/docs/icons/file-text.svg +1 -1
- package/docs/icons/file.svg +1 -1
- package/docs/icons/filter.svg +1 -1
- package/docs/icons/folder-open.svg +1 -1
- package/docs/icons/folder.svg +1 -1
- package/docs/icons/format_align_center.svg +1 -1
- package/docs/icons/format_align_justify.svg +1 -1
- package/docs/icons/format_align_left.svg +1 -1
- package/docs/icons/format_align_right.svg +1 -1
- package/docs/icons/format_bold.svg +1 -1
- package/docs/icons/format_clear.svg +1 -1
- package/docs/icons/format_color_fill.svg +1 -1
- package/docs/icons/format_color_text.svg +1 -1
- package/docs/icons/format_h1.svg +1 -1
- package/docs/icons/format_h2.svg +1 -1
- package/docs/icons/format_h3.svg +1 -1
- package/docs/icons/format_h4.svg +1 -1
- package/docs/icons/format_h5.svg +1 -1
- package/docs/icons/format_h6.svg +1 -1
- package/docs/icons/format_italic.svg +1 -1
- package/docs/icons/format_list_bulleted.svg +1 -1
- package/docs/icons/format_list_numbered.svg +1 -1
- package/docs/icons/format_paragraph.svg +1 -1
- package/docs/icons/format_underlined.svg +1 -1
- package/docs/icons/github-mark.svg +1 -1
- package/docs/icons/help.svg +1 -1
- package/docs/icons/hide.svg +1 -1
- package/docs/icons/image.svg +1 -1
- package/docs/icons/label.svg +1 -1
- package/docs/icons/license.svg +1 -1
- package/docs/icons/link.svg +1 -1
- package/docs/icons/menu.svg +1 -1
- package/docs/icons/mode-auto.svg +1 -1
- package/docs/icons/mode-dark.svg +1 -1
- package/docs/icons/mode-light.svg +1 -1
- package/docs/icons/more_vert.svg +1 -1
- package/docs/icons/settings.svg +1 -1
- package/docs/icons/show.svg +1 -1
- package/docs/icons/strikethrough_s.svg +1 -1
- package/docs/icons/table-visibility.svg +1 -1
- package/docs/icons/table.svg +1 -1
- package/docs/icons/warning.svg +1 -1
- package/docs/icons/wysiwyg.svg +1 -1
- package/docs/src/components/Resize.js +1 -0
- package/docs/src/components/Table.js +88 -78
- package/docs/src/components/Tree.js +1 -1
- package/icons/account-circle.svg +1 -1
- package/icons/add.svg +1 -1
- package/icons/arrow-circle.svg +1 -1
- package/icons/arrow-line.svg +1 -1
- package/icons/arrow.svg +1 -1
- package/icons/arrow_drop_down.svg +1 -1
- package/icons/cards.svg +1 -1
- package/icons/check.svg +1 -1
- package/icons/chevron-double.svg +1 -1
- package/icons/chevron-line.svg +1 -1
- package/icons/chevron.svg +1 -1
- package/icons/close.svg +1 -1
- package/icons/code.svg +1 -1
- package/icons/code_blocks.svg +1 -1
- package/icons/copy.svg +1 -1
- package/icons/delete.svg +1 -1
- package/icons/drag-handle.svg +1 -1
- package/icons/edit.svg +1 -1
- package/icons/error.svg +1 -1
- package/icons/export-file.svg +1 -1
- package/icons/file-text.svg +1 -1
- package/icons/file.svg +1 -1
- package/icons/filter.svg +1 -1
- package/icons/folder-open.svg +1 -1
- package/icons/folder.svg +1 -1
- package/icons/format_align_center.svg +1 -1
- package/icons/format_align_justify.svg +1 -1
- package/icons/format_align_left.svg +1 -1
- package/icons/format_align_right.svg +1 -1
- package/icons/format_bold.svg +1 -1
- package/icons/format_clear.svg +1 -1
- package/icons/format_color_fill.svg +1 -1
- package/icons/format_color_text.svg +1 -1
- package/icons/format_h1.svg +1 -1
- package/icons/format_h2.svg +1 -1
- package/icons/format_h3.svg +1 -1
- package/icons/format_h4.svg +1 -1
- package/icons/format_h5.svg +1 -1
- package/icons/format_h6.svg +1 -1
- package/icons/format_italic.svg +1 -1
- package/icons/format_list_bulleted.svg +1 -1
- package/icons/format_list_numbered.svg +1 -1
- package/icons/format_paragraph.svg +1 -1
- package/icons/format_underlined.svg +1 -1
- package/icons/github-mark.svg +1 -1
- package/icons/help.svg +1 -1
- package/icons/hide.svg +1 -1
- package/icons/image.svg +1 -1
- package/icons/label.svg +1 -1
- package/icons/license.svg +1 -1
- package/icons/link.svg +1 -1
- package/icons/menu.svg +1 -1
- package/icons/mode-auto.svg +1 -1
- package/icons/mode-dark.svg +1 -1
- package/icons/mode-light.svg +1 -1
- package/icons/more_vert.svg +1 -1
- package/icons/settings.svg +1 -1
- package/icons/show.svg +1 -1
- package/icons/strikethrough_s.svg +1 -1
- package/icons/table-visibility.svg +1 -1
- package/icons/table.svg +1 -1
- package/icons/warning.svg +1 -1
- package/icons/wysiwyg.svg +1 -1
- package/package.json +13 -4
- package/src/components/Resize.js +1 -0
- package/src/components/Table.js +136 -186
- package/src/components/Tree.js +4 -5
- package/icons/circle.svg +0 -1
- package/icons/compare.svg +0 -1
- package/icons/drawing2.svg +0 -124
- package/icons/filter-off.svg +0 -1
- package/icons/first.svg +0 -1
- package/icons/folder-clear.svg +0 -1
- package/icons/folder-create.svg +0 -1
- package/icons/key.svg +0 -1
- package/icons/label-add.svg +0 -1
- package/icons/last.svg +0 -1
- package/icons/login.svg +0 -1
- package/icons/logout.svg +0 -1
- package/icons/open-in-browser.svg +0 -1
- package/icons/pause.svg +0 -1
- package/icons/play.svg +0 -1
- package/icons/refresh.svg +0 -1
- package/icons/remove.svg +0 -1
- package/icons/save.svg +0 -1
- package/icons/search.svg +0 -1
- package/icons/storage.svg +0 -1
- package/icons/tag.svg +0 -1
- package/icons/tools.svg +0 -1
- package/icons/trash-x.svg +0 -1
- package/scripts/getIcon.js +0 -52
package/dist/components/Table.js
CHANGED
|
@@ -1,65 +1,64 @@
|
|
|
1
|
-
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1)}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.allOnPageSelected())}
|
|
2
|
-
<
|
|
3
|
-
<input
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`),this.hasBeforeControls()&&e.push(html`
|
|
10
|
-
<div class="field cell field-before-controls" style="width: ${this.columnSizes.beforeControls}px"></div>
|
|
11
|
-
`),this.fields.forEach(({name:t,label:s,hidden:i})=>{if(i)return;const r=this.sort.find(e=>e.name===t),o=this.sort.length>0&&this.sort[this.sort.length-1].name===t,l=r?r.asc?"sort-asc":"sort-desc":"";e.push(html`
|
|
12
|
-
<div
|
|
13
|
-
class="field cell ${l}"
|
|
14
|
-
style="width: ${this.columnSizes[t]}px; ${this.enableSorting?"cursor: pointer;":""}"
|
|
1
|
+
import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";import{toTitleCase}from"../utils/string.js";import{boolExists}from"../utils/propConverters.js";const selected=Symbol("selected"),hidden=Symbol("hidden"),index=Symbol("index"),editing=Symbol("editing");export default class Table extends ShadowComponent{static properties={enablePages:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-pages"},pageSize:{type:Number,reflect:!0,attribute:"page-size"},currentPage:{type:Number,reflect:!0,attribute:"current-page"},pageSizeOptions:{type:Array,attribute:"page-size-options"},enableSelection:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-selection"},enableSorting:{type:Boolean,reflect:!0,converter:boolExists,attribute:"enable-sorting"},caseSensitiveFilters:{type:Boolean,reflect:!0,converter:boolExists,attribute:"case-sensitive-filters"},fields:{type:Array},records:{type:Array},filters:{type:Array},sort:{type:Array},columnSizes:{type:Object},fetchPending:{type:Boolean}};constructor(e={}){super(),void 0===this.pageSize&&(this.pageSize=50),void 0===this.currentPage&&(this.currentPage=1),void 0===this.pageSizeOptions&&(this.pageSizeOptions=[10,25,50,100,500]),void 0===this.records&&(this.records=e.records||[]),void 0===this.fields&&(this.fields=e.fields||[]),void 0===this.filters&&(this.filters=e.filters||[]),void 0===this.sort&&(this.sort=[]),void 0===this.columnSizes&&(this.columnSizes={}),void 0===this.fetchPending&&(this.fetchPending=!1)}handleSelectAllChange=e=>{e.target.checked?this.selectAllOnPage():this.deselectAllOnPage()};handleFieldClick=e=>{const t=this.sort.find(t=>t.name===e),s=!t||!t.asc;this.sortBy(e,s)};handleRecordSelectionChange=(e,t)=>{e[selected]=!!t.target.checked,this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))};firstUpdated(){this.setData({records:this.records,fields:this.fields,filters:this.filters})}childrenUpdated(){this.requestUpdate()}updated(e){if(super.updated(e),this.enableSelection){const e=this.shadowRoot.getElementById("select-all");e&&(e.checked=this.allOnPageSelected())}}renderColgroupTemplate(){const e=[];return this.enableSelection&&e.push(html`<col style="width: 40px" />`),this.hasBeforeControls()&&e.push(html`<col style="width: ${this.columnSizes.beforeControls}px" />`),this.fields.forEach(({size:t,hidden:s})=>{s||e.push(t?html`<col style="width: ${t}px" />`:html`<col />`)}),this.hasAfterControls()&&e.push(html`<col style="width: ${this.columnSizes.afterControls}px" />`),e}getColumnCount(){let e=0;return this.enableSelection&&e++,this.hasBeforeControls()&&e++,this.fields.forEach(({hidden:t})=>{t||e++}),this.hasAfterControls()&&e++,e}renderFieldsTemplate(){const e=[];return this.enableSelection&&e.push(html`
|
|
2
|
+
<th class="controls field-select">
|
|
3
|
+
<input type="checkbox" id="select-all" @change=${this.handleSelectAllChange} />
|
|
4
|
+
</th>
|
|
5
|
+
`),this.hasBeforeControls()&&e.push(html`<th class="controls field-before-controls"></th>`),this.fields.forEach(({name:t,label:s,hidden:i})=>{if(i)return;const r=this.sort.find(e=>e.name===t),o=this.sort.length>0&&this.sort[this.sort.length-1].name===t,n=r?r.asc?"sort-asc":"sort-desc":"";e.push(html`
|
|
6
|
+
<th
|
|
7
|
+
class="${n}"
|
|
8
|
+
style="${this.enableSorting?"cursor: pointer;":""}"
|
|
15
9
|
@click=${this.enableSorting?()=>this.handleFieldClick(t):null}
|
|
16
10
|
>
|
|
17
11
|
${s}
|
|
18
12
|
${o?html`<k-icon name="arrow" direction="${r.asc?"down":"up"}" class="icon-sort"></k-icon>`:""}
|
|
19
|
-
</
|
|
20
|
-
`)}),this.hasAfterControls()&&e.push(html`
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<input
|
|
25
|
-
type="checkbox"
|
|
13
|
+
</th>
|
|
14
|
+
`)}),this.hasAfterControls()&&e.push(html`<th class="controls field-after-controls"></th>`),e}renderRecordsTemplate(){let e=this.getDisplayedRecords(),t=0,s=this.pageSize;this.enablePages&&(t=(this.currentPage-1)*this.pageSize,s=t+this.pageSize,e=e.slice(t,s));let i=null,r=0;const o=e.map((e,s)=>null!==e?this.renderRecordTemplate(e):(null===i&&(i=t+s),r++,html`<tr class="record fetching"><td class="cell" colspan="${this.getColumnCount()}">Loading...</td></tr>`));return null===i||this.fetchPending||setTimeout(()=>{this.fetchPending||this.dispatchEvent(new CustomEvent("fetchRecords",{detail:{start:i,count:r},bubbles:!0}))},0),o}renderRecordTemplate(e){const t=[];return this.enableSelection&&t.push(html`
|
|
15
|
+
<td class="cell selection controls">
|
|
16
|
+
<input
|
|
17
|
+
type="checkbox"
|
|
26
18
|
.checked=${e[selected]}
|
|
27
19
|
@change=${t=>this.handleRecordSelectionChange(e,t)}
|
|
28
20
|
/>
|
|
29
|
-
</
|
|
30
|
-
`),this.hasBeforeControls()&&t.push(this.renderBeforeControlsTemplate()),this.fields.forEach(({name:s,formatter:i,calculator:r,type:o,editor:
|
|
31
|
-
<
|
|
32
|
-
${e[editing]?this.renderEditingCell(e,s,a,r,
|
|
33
|
-
</
|
|
21
|
+
</td>
|
|
22
|
+
`),this.hasBeforeControls()&&t.push(this.renderBeforeControlsTemplate()),this.fields.forEach(({name:s,formatter:i,calculator:r,type:o,editor:n,hidden:l})=>{if(l)return;let a=e[s]||"";t.push(html`
|
|
23
|
+
<td class="cell" data-field=${s}>
|
|
24
|
+
${e[editing]?this.renderEditingCell(e,s,a,r,n,o):this.renderDisplayCell(e,s,a,r,i)}
|
|
25
|
+
</td>
|
|
34
26
|
`)}),this.hasAfterControls()&&t.push(this.renderAfterControlsTemplate()),html`
|
|
35
|
-
<
|
|
27
|
+
<tr class="record ${e[editing]?"editing":""}" data-index=${e[index]}>
|
|
36
28
|
${t}
|
|
37
|
-
</
|
|
29
|
+
</tr>
|
|
38
30
|
`}renderEditingCell(e,t,s,i,r,o){if(i)return html`<input disabled .value=${i(e,this)} />`;if(r){const e=r(s);return html`${e}`}switch(o||typeof s){case"number":return html`<input type="number" .value=${s} />`;case"date":return html`<input type="date" .value=${s} />`;case"boolean":return html`
|
|
39
31
|
<select .value=${s}>
|
|
40
32
|
<option value="true" ?selected=${s}>True</option>
|
|
41
33
|
<option value="false" ?selected=${!s}>False</option>
|
|
42
34
|
</select>
|
|
43
35
|
`;default:return html`<input type="text" .value=${s} />`}}renderDisplayCell(e,t,s,i,r){return i?i(e,this):r?r(s):s}renderBeforeControlsTemplate(){const e=[];return this.querySelectorAll('[slot="before"]').forEach(t=>{const s=t.tagName.toLowerCase(),i=document.createElement(s);Array.from(t.attributes).forEach(e=>{"slot"!==e.name&&i.setAttribute(e.name,e.value)}),t.innerHTML&&(i.innerHTML=t.innerHTML),e.push(i)}),html`
|
|
44
|
-
<
|
|
36
|
+
<td class="cell controls controls-before">
|
|
45
37
|
${e}
|
|
46
|
-
</
|
|
38
|
+
</td>
|
|
47
39
|
`}renderAfterControlsTemplate(){const e=[];return this.querySelectorAll('[slot="after"]').forEach(t=>{const s=t.tagName.toLowerCase(),i=document.createElement(s);Array.from(t.attributes).forEach(e=>{"slot"!==e.name&&i.setAttribute(e.name,e.value)}),t.innerHTML&&(i.innerHTML=t.innerHTML),e.push(i)}),html`
|
|
48
|
-
<
|
|
40
|
+
<td class="cell controls controls-after">
|
|
49
41
|
${e}
|
|
50
|
-
</
|
|
51
|
-
`}hasBeforeControls(){return!!this.querySelector('[slot="before"]')}hasAfterControls(){return!!this.querySelector('[slot="after"]')}hasTopControls(){return!!this.querySelector('[slot="top"]')}hasBottomControls(){return!!this.querySelector(":scope > :not([slot])")}editRecord(e){e[editing]=!0;const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.classList.add("editing"),t.setAttribute("editing","true"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";if(t.innerHTML="",i.calculator){const s=document.createElement("input");s.disabled=!0,s.value=i.calculator(e,this),t.appendChild(s)}else if(i.editor)t.appendChild(i.editor(r));else{const e=i.type||typeof r,s=Table.editors[e]||Table.editors.string;t.appendChild(s(r))}}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!0},bubbles:!0}))}saveEditedRecord(e){const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i&&!i.calculator){const i=t.querySelector("input, select");i&&(e[s]=i.value)}}),e[editing]=!1,t.classList.remove("editing"),t.removeAttribute("editing"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";i.calculator?t.textContent=i.calculator(e,this):i.formatter?t.innerHTML=i.formatter(r):t.textContent=r}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!1},bubbles:!0}))}cancelEditedRecord(e){e[editing]=!1;const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.classList.remove("editing"),t.removeAttribute("editing"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";i.calculator?t.textContent=i.calculator(e,this):i.formatter?t.innerHTML=i.formatter(r):t.textContent=r}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!1},bubbles:!0}))}recordIsEditing(e){return e[editing]}getCurrentPage(){return this.currentPage}getTotalPages(){return Math.ceil(this.getDisplayedRecords().length/this.pageSize)}setPage(e){e<1||e>this.getTotalPages()||(this.currentPage=e,this.requestUpdate(),this.dispatchEvent(new CustomEvent("pageChange",{bubbles:!0})))}firstPage(){1!==this.currentPage&&this.setPage(1)}nextPage(){this.currentPage<this.getTotalPages()&&this.setPage(this.currentPage+1)}prevPage(){this.currentPage>1&&this.setPage(this.currentPage-1)}lastPage(){this.currentPage!==this.getTotalPages()&&this.setPage(this.getTotalPages())}setPageSize(e){this.pageSize=e,this.currentPage=1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("pageSizeChange",{bubbles:!0}))}getPageSize(){return this.pageSize}getPageSizeOptions(){return this.pageSizeOptions}getFieldLabel(e){const t=this.fields.find(t=>t.name===e);return t?t.label:toTitleCase(e)}setPageSizeOptions(e){this.pageSizeOptions=e,this.requestUpdate()}setData({records:e=!1,fields:t=!1,pageSize:s=!1,pageSizeOptions:i=!1,currentPage:r=!1,enableSelection:o}={}){let l=!1,n=this.getTotalPages(),a=this.currentPage;e&&(this.records=e.map(e=>({...e})),this.records.forEach((e,t)=>{e[index]=t,e[selected]=!1,e[hidden]=!1,e[editing]=!1}),this.fields=t||Table.extractFieldsFromRecords(this.records),l=!0),s&&(this.pageSize=s,l=!0),i&&(this.pageSizeOptions=i),r&&(this.currentPage=r,l=!0),void 0!==o&&(this.enableSelection=o,l=!0),l&&this.requestUpdate();const d=this.getTotalPages();d!==n&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:this.getTotalPages()},bubbles:!0})),a>d&&this.setPage(d)}setRecords(e,t){let s=this.getTotalPages(),i=this.currentPage;this.records=e.map(e=>({...e})),this.records.forEach((e,t)=>{e[index]=t,e[selected]=!1,e[hidden]=!1,e[editing]=!1}),this.fields=t||Table.extractFieldsFromRecords(this.records),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordsSet",{detail:{records:e},bubbles:!0}));const r=this.getTotalPages();r!==s&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:this.getTotalPages()},bubbles:!0})),i>r&&this.setPage(r)}setupFetchRecords(e,t){const s=this.records.length,i=this.getTotalPages();if(s<e){this.records.length=e,this.records.fill(null,s),this.requestUpdate();const t=this.getTotalPages();t!==i&&setTimeout(()=>{this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:t},bubbles:!0}))},0)}this.addEventListener("fetchRecords",async e=>{if(this.fetchPending)return;this.fetchPending=!0;const{start:s,count:i}=e.detail,r=await t(s,i);r.forEach((e,t)=>{e[index]=s+t,void 0===e[selected]&&(e[selected]=!1),void 0===e[hidden]&&(e[hidden]=!1),void 0===e[editing]&&(e[editing]=!1)}),this.records.splice(s,r.length,...r),this.fetchPending=!1,this.requestUpdate()})}addRecord(e){e[selected]=!1,e[hidden]=!1,e[index]=this.records.length,this.records.push(e),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordAdded",{detail:{record:e},bubbles:!0}))}updateRecord(e,t){let s=!1,i=this.records.find(t=>t===e);if(i||void 0===e[index]||(i=this.records[e[index]]),Object.keys(t).forEach(e=>{i.hasOwnProperty(e)&&(i[e]=t[e],s=!0)}),s){const e=(this.currentPage-1)*this.pageSize,t=e+this.pageSize;(!this.enablePages||i[index]>=e&&i[index]<t)&&this.requestUpdate()}}deleteRecord(e){let t=this.records.find(t=>t===e),s=this.getTotalPages();if(t||void 0===e[index]||(t=this.records[e[index]]),t){const e=this.records.indexOf(t);this.records.splice(e,1),this.records.forEach((e,t)=>{e[index]=t}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0})),this.dispatchEvent(new CustomEvent("recordDeleted",{detail:{index:e},bubbles:!0}));const i=this.getTotalPages();this.currentPage>i&&this.setPage(i),i!==s&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:i},bubbles:!0}))}}deleteSelected(){let e=this.getTotalPages();this.getSelectedRecords().forEach(e=>{let t=this.records.find(t=>t===e);if(t||void 0===e[index]||(t=this.records[e[index]]),t){const e=this.records.indexOf(t);this.records.splice(e,1)}}),this.records.forEach((e,t)=>{e[index]=t}),this.requestUpdate();const t=this.getTotalPages();this.currentPage>t&&this.setPage(t),t!==e&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:t},bubbles:!0})),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))}getSelectedRecords(){return this.records.filter(e=>e[selected])}selectAllOnPage(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)this.records[s][selected]=!0;this.requestUpdate(),setTimeout(()=>{this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))},0)}deselectAllOnPage(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)this.records[s][selected]=!1;this.requestUpdate(),setTimeout(()=>{this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))},0)}allOnPageSelected(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)if(!this.records[s][selected])return!1;return!0}sortBy(e,t=!0){this.sort=this.sort.filter(t=>t.name!==e),this.sort.push({name:e,asc:t}),this.requestUpdate()}hideRecord(e){let t=this.records.find(t=>t===e);t||void 0===e[index]||(t=this.records[e[index]]),t&&(t[hidden]=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordHidden",{bubbles:!0})))}showRecord(e){let t=this.records.find(t=>t===e);t||void 0===e[index]||(t=this.records[e[index]]),t&&(t[hidden]=!1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordShown",{bubbles:!0})))}showAllRecords(){this.records.forEach(e=>{e[hidden]=!1}),this.filters.length&&(this.filters=[],this.dispatchEvent(new CustomEvent("filterRemoved",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0}))),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordShown",{bubbles:!0})),this.dispatchEvent(new CustomEvent("allRecordsShown",{bubbles:!0}))}addFilter(e,t,s){this.filters.push({field:e,condition:t,value:s}),this.dispatchEvent(new CustomEvent("filterAdded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0})),this.requestUpdate()}removeFilter(e,t,s,i=!0){const r=this.filters.findIndex(i=>i.field===e&&i.condition===t&&i.value===s);-1!==r&&(this.records.forEach(i=>{this.testFilter(i,e,t,s)||(i[hidden]=!1)}),this.filters.splice(r,1),this.dispatchEvent(new CustomEvent("filterRemoved",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0})),i&&this.requestUpdate())}testFilter(e,t,s,i){let r=e[t],o=i;switch(this.caseSensitiveFilters||"string"!=typeof r||"string"!=typeof i||(r=r.toLowerCase(),o=i.toLowerCase()),s){case"equals":return r===o;case"not-equals":return r!==o;case"contains":return r.includes(o);case"not-contains":return!r.includes(o);case"greater-than":return r>o;case"less-than":return r<o;case"greater-than-or-equal":return r>=o;case"less-than-or-equal":return r<=o;default:return!0}}removeAllFilters(){this.filters.length&&([...this.filters].forEach(({field:e,condition:t,value:s})=>{this.removeFilter(e,t,s,!1)}),this.requestUpdate())}search(e){const t=e.trim().toLowerCase();let s=!1;this.records.forEach(e=>{if(e[hidden])return;let i=!1;this.fields.forEach(({name:s})=>{(e[s]?.toString().toLowerCase()||"").includes(t)&&(i=!0)}),e[hidden]!==!i&&(e[hidden]=!i,s=!0)}),s&&(this.dispatchEvent(new CustomEvent("recordHidden",{bubbles:!0})),this.requestUpdate()),this.dispatchEvent(new CustomEvent("search",{detail:{term:e},bubbles:!0}))}getDisplayedRecords(){this.filters.forEach(({field:e,condition:t,value:s})=>{this.records.forEach(i=>{null!==i&&(this.testFilter(i,e,t,s)||(i[hidden]=!0))})});let e=this.records.filter(e=>null===e||!e[hidden]);return this.sort.forEach(({name:t,asc:s})=>{e.sort((e,i)=>null===e||null===i?0:e[t]<i[t]?s?-1:1:e[t]>i[t]?s?1:-1:0)}),e}getHiddenRecords(){return this.records.filter(e=>e[hidden])}calculateColumnSizes(){const e={total:0};this.enableSelection&&(e.total+=40);const t=Array.from(this.querySelectorAll('[slot="before"]')),s=Array.from(this.querySelectorAll('[slot="after"]'));e.beforeControls=t.reduce((e,t)=>e+(t.maxWidth||40),0),e.afterControls=s.reduce((e,t)=>e+(t.maxWidth||40),0),this.hasBeforeControls()&&(e.total+=e.beforeControls),this.hasAfterControls()&&(e.total+=e.afterControls),this.fields.forEach(t=>{if(t.size)e[t.name]=t.size,e.total+=t.size;else{let s=0;this.records.slice(0,100).forEach(e=>{if(null===e)return;let i=e[t.name];t.calculator&&(i=t.calculator(e,this)),t.formatter&&(i=t.formatter(i)),i&&i.toString().length>s&&(s=i.toString().length)}),e[t.name]=Math.max(10*s+32,128),t.hidden||(e.total+=e[t.name])}});const i=[...t,...s].some(e=>void 0===e.maxWidth);return JSON.stringify(this.columnSizes)!==JSON.stringify(e)&&(this.columnSizes=e),i&&setTimeout(()=>this.calculateColumnSizes(),0),this.columnSizes}setFieldHiddenState(e,t){const s=this.fields.find(t=>t.name===e);s&&(s.hidden=t,this.calculateColumnSizes(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("fieldVisibilityChanged",{detail:{field:s},bubbles:!0})),this.dispatchEvent(new CustomEvent(t?"fieldHidden":"fieldShown",{detail:{field:s},bubbles:!0})))}hideField(e){this.setFieldHiddenState(e,!0)}showField(e){this.setFieldHiddenState(e,!1)}reorderFields(e){const t=[];e.forEach(e=>{const s=this.fields.find(t=>t.name===e);s&&t.push(s)}),this.fields=t,this.requestUpdate()}render(){return this.records&&this.fields?(this.calculateColumnSizes(),this.hasTopControls()?this.setAttribute("top-controls","true"):this.removeAttribute("top-controls"),this.hasBottomControls()?this.setAttribute("bottom-controls","true"):this.removeAttribute("bottom-controls"),html`
|
|
42
|
+
</td>
|
|
43
|
+
`}hasBeforeControls(){return!!this.querySelector('[slot="before"]')}hasAfterControls(){return!!this.querySelector('[slot="after"]')}hasTopControls(){return!!this.querySelector('[slot="top"]')}hasBottomControls(){return!!this.querySelector(":scope > :not([slot])")}editRecord(e){e[editing]=!0;const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.classList.add("editing"),t.setAttribute("editing","true"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";if(t.innerHTML="",i.calculator){const s=document.createElement("input");s.disabled=!0,s.value=i.calculator(e,this),t.appendChild(s)}else if(i.editor)t.appendChild(i.editor(r));else{const e=i.type||typeof r,s=Table.editors[e]||Table.editors.string;t.appendChild(s(r))}}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!0},bubbles:!0}))}saveEditedRecord(e){const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i&&!i.calculator){const i=t.querySelector("input, select");i&&(e[s]=i.value)}}),e[editing]=!1,t.classList.remove("editing"),t.removeAttribute("editing"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";i.calculator?t.textContent=i.calculator(e,this):i.formatter?t.innerHTML=i.formatter(r):t.textContent=r}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!1},bubbles:!0}))}cancelEditedRecord(e){e[editing]=!1;const t=this.shadowRoot.querySelector(`.record[data-index="${e[index]}"]`);t&&(t.classList.remove("editing"),t.removeAttribute("editing"),t.querySelectorAll(".cell[data-field]").forEach(t=>{const s=t.dataset.field,i=this.fields.find(e=>e.name===s);if(i){const r=e[s]||"";i.calculator?t.textContent=i.calculator(e,this):i.formatter?t.innerHTML=i.formatter(r):t.textContent=r}})),this.dispatchEvent(new CustomEvent("editingChange",{detail:{record:e,editing:!1},bubbles:!0}))}recordIsEditing(e){return e[editing]}getCurrentPage(){return this.currentPage}getTotalPages(){return Math.ceil(this.getDisplayedRecords().length/this.pageSize)}setPage(e){e<1||e>this.getTotalPages()||(this.currentPage=e,this.requestUpdate(),this.dispatchEvent(new CustomEvent("pageChange",{bubbles:!0})))}firstPage(){1!==this.currentPage&&this.setPage(1)}nextPage(){this.currentPage<this.getTotalPages()&&this.setPage(this.currentPage+1)}prevPage(){this.currentPage>1&&this.setPage(this.currentPage-1)}lastPage(){this.currentPage!==this.getTotalPages()&&this.setPage(this.getTotalPages())}setPageSize(e){this.pageSize=e,this.currentPage=1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("pageSizeChange",{bubbles:!0}))}getPageSize(){return this.pageSize}getPageSizeOptions(){return this.pageSizeOptions}getFieldLabel(e){const t=this.fields.find(t=>t.name===e);return t?t.label:toTitleCase(e)}setPageSizeOptions(e){this.pageSizeOptions=e,this.requestUpdate()}setData({records:e=!1,fields:t=!1,pageSize:s=!1,pageSizeOptions:i=!1,currentPage:r=!1,enableSelection:o}={}){let n=!1,l=this.getTotalPages(),a=this.currentPage;e&&(this.records=e.map(e=>({...e})),this.records.forEach((e,t)=>{e[index]=t,e[selected]=!1,e[hidden]=!1,e[editing]=!1}),this.fields=t||Table.extractFieldsFromRecords(this.records),n=!0),s&&(this.pageSize=s,n=!0),i&&(this.pageSizeOptions=i),r&&(this.currentPage=r,n=!0),void 0!==o&&(this.enableSelection=o,n=!0),n&&this.requestUpdate();const d=this.getTotalPages();d!==l&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:this.getTotalPages()},bubbles:!0})),a>d&&this.setPage(d)}setRecords(e,t){let s=this.getTotalPages(),i=this.currentPage;this.records=e.map(e=>({...e})),this.records.forEach((e,t)=>{e[index]=t,e[selected]=!1,e[hidden]=!1,e[editing]=!1}),this.fields=t||Table.extractFieldsFromRecords(this.records),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordsSet",{detail:{records:e},bubbles:!0}));const r=this.getTotalPages();r!==s&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:this.getTotalPages()},bubbles:!0})),i>r&&this.setPage(r)}setupFetchRecords(e,t){const s=this.records.length,i=this.getTotalPages();if(s<e){this.records.length=e,this.records.fill(null,s),this.requestUpdate();const t=this.getTotalPages();t!==i&&setTimeout(()=>{this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:t},bubbles:!0}))},0)}this.addEventListener("fetchRecords",async e=>{if(this.fetchPending)return;this.fetchPending=!0;const{start:s,count:i}=e.detail,r=await t(s,i);r.forEach((e,t)=>{e[index]=s+t,void 0===e[selected]&&(e[selected]=!1),void 0===e[hidden]&&(e[hidden]=!1),void 0===e[editing]&&(e[editing]=!1)}),this.records.splice(s,r.length,...r),this.fetchPending=!1,this.requestUpdate()})}addRecord(e){e[selected]=!1,e[hidden]=!1,e[index]=this.records.length,this.records.push(e),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordAdded",{detail:{record:e},bubbles:!0}))}updateRecord(e,t){let s=!1,i=this.records.find(t=>t===e);if(i||void 0===e[index]||(i=this.records[e[index]]),Object.keys(t).forEach(e=>{i.hasOwnProperty(e)&&(i[e]=t[e],s=!0)}),s){const e=(this.currentPage-1)*this.pageSize,t=e+this.pageSize;(!this.enablePages||i[index]>=e&&i[index]<t)&&this.requestUpdate()}}deleteRecord(e){let t=this.records.find(t=>t===e),s=this.getTotalPages();if(t||void 0===e[index]||(t=this.records[e[index]]),t){const e=this.records.indexOf(t);this.records.splice(e,1),this.records.forEach((e,t)=>{e[index]=t}),this.requestUpdate(),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0})),this.dispatchEvent(new CustomEvent("recordDeleted",{detail:{index:e},bubbles:!0}));const i=this.getTotalPages();this.currentPage>i&&this.setPage(i),i!==s&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:i},bubbles:!0}))}}deleteSelected(){let e=this.getTotalPages();this.getSelectedRecords().forEach(e=>{let t=this.records.find(t=>t===e);if(t||void 0===e[index]||(t=this.records[e[index]]),t){const e=this.records.indexOf(t);this.records.splice(e,1)}}),this.records.forEach((e,t)=>{e[index]=t}),this.requestUpdate();const t=this.getTotalPages();this.currentPage>t&&this.setPage(t),t!==e&&this.dispatchEvent(new CustomEvent("pageCountChanged",{detail:{totalPages:t},bubbles:!0})),this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))}getSelectedRecords(){return this.records.filter(e=>e[selected])}selectAllOnPage(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)this.records[s][selected]=!0;this.requestUpdate(),setTimeout(()=>{this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))},0)}deselectAllOnPage(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)this.records[s][selected]=!1;this.requestUpdate(),setTimeout(()=>{this.dispatchEvent(new CustomEvent("selectionChange",{bubbles:!0}))},0)}allOnPageSelected(){const e=(this.currentPage-1)*this.pageSize,t=Math.min(e+this.pageSize,this.records.length);for(let s=e;s<t;s++)if(!this.records[s][selected])return!1;return!0}sortBy(e,t=!0){this.sort=this.sort.filter(t=>t.name!==e),this.sort.push({name:e,asc:t}),this.requestUpdate()}hideRecord(e){let t=this.records.find(t=>t===e);t||void 0===e[index]||(t=this.records[e[index]]),t&&(t[hidden]=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordHidden",{bubbles:!0})))}showRecord(e){let t=this.records.find(t=>t===e);t||void 0===e[index]||(t=this.records[e[index]]),t&&(t[hidden]=!1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordShown",{bubbles:!0})))}showAllRecords(){this.records.forEach(e=>{e[hidden]=!1}),this.filters.length&&(this.filters=[],this.dispatchEvent(new CustomEvent("filterRemoved",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0}))),this.requestUpdate(),this.dispatchEvent(new CustomEvent("recordShown",{bubbles:!0})),this.dispatchEvent(new CustomEvent("allRecordsShown",{bubbles:!0}))}addFilter(e,t,s){this.filters.push({field:e,condition:t,value:s}),this.dispatchEvent(new CustomEvent("filterAdded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0})),this.requestUpdate()}removeFilter(e,t,s,i=!0){const r=this.filters.findIndex(i=>i.field===e&&i.condition===t&&i.value===s);-1!==r&&(this.records.forEach(i=>{this.testFilter(i,e,t,s)||(i[hidden]=!1)}),this.filters.splice(r,1),this.dispatchEvent(new CustomEvent("filterRemoved",{bubbles:!0})),this.dispatchEvent(new CustomEvent("filterChange",{bubbles:!0})),i&&this.requestUpdate())}testFilter(e,t,s,i){let r=e[t],o=i;switch(this.caseSensitiveFilters||"string"!=typeof r||"string"!=typeof i||(r=r.toLowerCase(),o=i.toLowerCase()),s){case"equals":return r===o;case"not-equals":return r!==o;case"contains":return r.includes(o);case"not-contains":return!r.includes(o);case"greater-than":return r>o;case"less-than":return r<o;case"greater-than-or-equal":return r>=o;case"less-than-or-equal":return r<=o;default:return!0}}removeAllFilters(){this.filters.length&&([...this.filters].forEach(({field:e,condition:t,value:s})=>{this.removeFilter(e,t,s,!1)}),this.requestUpdate())}search(e){const t=e.trim().toLowerCase();let s=!1;this.records.forEach(e=>{if(e[hidden])return;let i=!1;this.fields.forEach(({name:s})=>{(e[s]?.toString().toLowerCase()||"").includes(t)&&(i=!0)}),e[hidden]!==!i&&(e[hidden]=!i,s=!0)}),s&&(this.dispatchEvent(new CustomEvent("recordHidden",{bubbles:!0})),this.requestUpdate()),this.dispatchEvent(new CustomEvent("search",{detail:{term:e},bubbles:!0}))}getDisplayedRecords(){this.filters.forEach(({field:e,condition:t,value:s})=>{this.records.forEach(i=>{null!==i&&(this.testFilter(i,e,t,s)||(i[hidden]=!0))})});let e=this.records.filter(e=>null===e||!e[hidden]);return this.sort.forEach(({name:t,asc:s})=>{e.sort((e,i)=>null===e||null===i?0:e[t]<i[t]?s?-1:1:e[t]>i[t]?s?1:-1:0)}),e}getHiddenRecords(){return this.records.filter(e=>e[hidden])}calculateColumnSizes(){const e=Array.from(this.querySelectorAll('[slot="before"]')),t=Array.from(this.querySelectorAll('[slot="after"]')),s={beforeControls:e.reduce((e,t)=>e+(t.maxWidth||40),0),afterControls:t.reduce((e,t)=>e+(t.maxWidth||40),0)},i=[...e,...t].some(e=>void 0===e.maxWidth);return JSON.stringify(this.columnSizes)!==JSON.stringify(s)&&(this.columnSizes=s),i&&setTimeout(()=>this.calculateColumnSizes(),0),this.columnSizes}setFieldHiddenState(e,t){const s=this.fields.find(t=>t.name===e);s&&(s.hidden=t,this.calculateColumnSizes(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("fieldVisibilityChanged",{detail:{field:s},bubbles:!0})),this.dispatchEvent(new CustomEvent(t?"fieldHidden":"fieldShown",{detail:{field:s},bubbles:!0})))}hideField(e){this.setFieldHiddenState(e,!0)}showField(e){this.setFieldHiddenState(e,!1)}reorderFields(e){const t=[];e.forEach(e=>{const s=this.fields.find(t=>t.name===e);s&&t.push(s)}),this.fields=t,this.requestUpdate()}render(){return this.records&&this.fields?(this.calculateColumnSizes(),this.hasTopControls()?this.setAttribute("top-controls","true"):this.removeAttribute("top-controls"),this.hasBottomControls()?this.setAttribute("bottom-controls","true"):this.removeAttribute("bottom-controls"),html`
|
|
52
44
|
<div id="wrapper">
|
|
53
|
-
<div id="top"
|
|
54
|
-
<div id="table">
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
<div id="top"><slot name="top"></slot></div>
|
|
46
|
+
<div id="table-container">
|
|
47
|
+
<table>
|
|
48
|
+
<colgroup>
|
|
49
|
+
${this.renderColgroupTemplate()}
|
|
50
|
+
</colgroup>
|
|
51
|
+
<thead>
|
|
52
|
+
<tr>
|
|
53
|
+
${this.renderFieldsTemplate()}
|
|
54
|
+
</tr>
|
|
55
|
+
</thead>
|
|
56
|
+
<tbody>
|
|
57
|
+
${this.renderRecordsTemplate()}
|
|
58
|
+
</tbody>
|
|
59
|
+
</table>
|
|
61
60
|
</div>
|
|
62
|
-
<div id="bottom"
|
|
61
|
+
<div id="bottom"><slot></slot></div>
|
|
63
62
|
</div>
|
|
64
63
|
<div style="display: none">
|
|
65
64
|
<slot name="before"></slot>
|
|
@@ -68,9 +67,8 @@ import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowCompon
|
|
|
68
67
|
`):html`
|
|
69
68
|
<div id="wrapper">
|
|
70
69
|
<div id="top"><slot name="top"></slot></div>
|
|
71
|
-
<div id="table">
|
|
72
|
-
<
|
|
73
|
-
<div id="records"></div>
|
|
70
|
+
<div id="table-container">
|
|
71
|
+
<table><thead><tr></tr></thead><tbody></tbody></table>
|
|
74
72
|
</div>
|
|
75
73
|
<div id="bottom"><slot></slot></div>
|
|
76
74
|
</div>
|
|
@@ -81,40 +79,67 @@ import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowCompon
|
|
|
81
79
|
`}static styles=css`
|
|
82
80
|
:host {
|
|
83
81
|
display: block;
|
|
84
|
-
width: 100%;
|
|
85
|
-
overflow: auto;
|
|
86
82
|
margin-bottom: var(--spacer);
|
|
87
83
|
}
|
|
88
84
|
#wrapper {
|
|
89
|
-
width: min-content;
|
|
90
85
|
border: 1px solid var(--c_border);
|
|
91
86
|
border-radius: var(--radius);
|
|
87
|
+
overflow: hidden;
|
|
92
88
|
}
|
|
93
|
-
#table {
|
|
94
|
-
|
|
89
|
+
#table-container {
|
|
90
|
+
overflow-x: auto;
|
|
95
91
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
table {
|
|
93
|
+
width: 100%;
|
|
94
|
+
border-collapse: collapse;
|
|
99
95
|
}
|
|
100
|
-
|
|
96
|
+
thead tr {
|
|
101
97
|
background-color: var(--c_bg__alt);
|
|
102
|
-
border-bottom: 1px solid var(--c_border);
|
|
103
98
|
}
|
|
104
|
-
|
|
105
|
-
#fields .cell:not(.controls) {
|
|
99
|
+
th, td {
|
|
106
100
|
padding: calc(0.5 * var(--spacer)) var(--spacer);
|
|
101
|
+
vertical-align: middle;
|
|
107
102
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
th:not(:last-child),
|
|
104
|
+
td:not(:last-child) {
|
|
105
|
+
border-right: 1px solid var(--c_border);
|
|
111
106
|
}
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
th:first-child,
|
|
108
|
+
td:first-child {
|
|
109
|
+
border-left: none;
|
|
110
|
+
}
|
|
111
|
+
th:last-child,
|
|
112
|
+
td:last-child {
|
|
113
|
+
border-right: none;
|
|
114
|
+
}
|
|
115
|
+
thead tr th {
|
|
116
|
+
border-top: none;
|
|
117
|
+
border-bottom: 1px solid var(--c_border);
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
tbody tr:not(:last-child) td {
|
|
116
120
|
border-bottom: 1px solid var(--c_border);
|
|
117
121
|
}
|
|
122
|
+
tbody tr:last-child td {
|
|
123
|
+
border-bottom: none;
|
|
124
|
+
}
|
|
125
|
+
th.controls,
|
|
126
|
+
td.controls {
|
|
127
|
+
padding: 0;
|
|
128
|
+
}
|
|
129
|
+
.field-select,
|
|
130
|
+
.selection {
|
|
131
|
+
width: 40px;
|
|
132
|
+
text-align: center;
|
|
133
|
+
}
|
|
134
|
+
.field-select input,
|
|
135
|
+
.selection input {
|
|
136
|
+
width: 1.25rem;
|
|
137
|
+
height: 1.25rem;
|
|
138
|
+
}
|
|
139
|
+
.icon-sort {
|
|
140
|
+
float: right;
|
|
141
|
+
opacity: 0.5;
|
|
142
|
+
}
|
|
118
143
|
#top, #bottom {
|
|
119
144
|
display: flex;
|
|
120
145
|
width: 100%;
|
|
@@ -133,19 +158,4 @@ import{html,css,unsafeStatic,literal}from"../lit-all.min.js";import ShadowCompon
|
|
|
133
158
|
:host(:not([bottom-controls])) #bottom {
|
|
134
159
|
display: none;
|
|
135
160
|
}
|
|
136
|
-
.field-select,
|
|
137
|
-
.selection {
|
|
138
|
-
display: flex;
|
|
139
|
-
justify-content: center;
|
|
140
|
-
align-items: center;
|
|
141
|
-
}
|
|
142
|
-
.field-select input,
|
|
143
|
-
.selection input {
|
|
144
|
-
width: 1.25rem;
|
|
145
|
-
height: 1.25rem;
|
|
146
|
-
}
|
|
147
|
-
.icon-sort {
|
|
148
|
-
float: right;
|
|
149
|
-
opacity: 0.5;
|
|
150
|
-
}
|
|
151
161
|
`;static extractFieldsFromRecords(e,t=100){const s=new Set;return e.slice(0,t).forEach(e=>{Object.keys(e).forEach(e=>s.add(e))}),[...s].map(e=>({name:e,label:toTitleCase(e)}))}static format(e){return(Array.isArray(e)?Table.formatters.array:Table.formatters[typeof e])(e)}static formatters={string:e=>e,number:e=>`${e}`,date:e=>e.toLocaleDateString(),boolean:e=>e?"True":"False",array:e=>e.map(e=>Table.format(e)).join(", "),undefined:e=>"",null:e=>"<code>null</code>"};static editors={string:e=>{const t=document.createElement("input");return t.value=e,t},number:e=>{const t=document.createElement("input");return t.type="number",t.value=e,t},date:e=>{const t=document.createElement("input");return t.type="date",t.value=e,t},boolean:e=>{const t=document.createElement("select");return t.innerHTML=`\n <option value="true" ${e?"selected":""}>True</option>\n <option value="false" ${e?"":"selected"}>False</option>\n `,t.value=e,t},calculated:e=>{const t=document.createElement("input");return t.disabled=!0,t.value=e,t}}}window.customElements.define("k-table",Table);
|
package/dist/components/Tree.js
CHANGED
|
@@ -6,7 +6,7 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-al
|
|
|
6
6
|
<div class="tree-root">
|
|
7
7
|
${e?e.map(([e,t])=>Tree.renderValue(t,e,1,this.depth)):Tree.renderValue(this.data,null,0,this.depth)}
|
|
8
8
|
</div>
|
|
9
|
-
`}static nodes=[];static addNode=(...e)=>{[...e].reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(e,"nodeTag")||(e.nodeTag="k-tree-node-"+nodeTagCounter++,window.customElements.define(e.nodeTag,e)),Tree.nodes.unshift(e)})};static renderValue(e,t=null,s=0,n=0){const r=Tree.nodes.find(t=>t.detect(e));if(r){const s=
|
|
9
|
+
`}static nodes=[];static addNode=(...e)=>{[...e].reverse().forEach(e=>{Object.prototype.hasOwnProperty.call(e,"nodeTag")||(e.nodeTag="k-tree-node-"+nodeTagCounter++,window.customElements.define(e.nodeTag,e)),Tree.nodes.unshift(e)})};static renderValue(e,t=null,s=0,n=0){const r=Tree.nodes.find(t=>t.detect(e));if(r&&r.prototype.getChildren===TreeNode.prototype.getChildren){const s=null!==t?html`<span class="${"number"==typeof t?"tc-muted":""}">${t}: </span>`:"";return html`<span class="d-b">${s}${new r(e).renderLabel()}</span>`}const o=document.createElement((r??TreeNode).nodeTag);return o.value=e,o.key=t,o.depth=s,o.maxDepth=n,o}}window.customElements.define("k-tree",Tree);export class TreeNode extends ShadowComponent{static nodeTag="k-tree-node";static properties={value:{type:Object},key:{attribute:!1},depth:{type:Number},maxDepth:{type:Number},opened:{type:Boolean,converter:boolExists,reflect:!0},icon:{type:String}};constructor(e){super(),this.value=void 0!==e?e:null,this.key=null,this.depth=0,this.maxDepth=0,this.opened=!1,this.icon=null}connectedCallback(){super.connectedCallback(),this.depth<=this.maxDepth&&(this.opened=!0)}get tree(){return this.closest("k-tree")}toggle=()=>{this.opened=!this.opened};renderLabel(){return"object"==typeof this.value&&null!==this.value?html`${Array.isArray(this.value)?"Array":"Object"}`:html`${this.value}`}getChildren(){return"object"!=typeof this.value||null===this.value?null:Array.isArray(this.value)?this.value.map((e,t)=>[t,e]):Object.entries(this.value)}renderIcon(){return this.icon?html`<k-icon name="${this.icon}"></k-icon>`:html`<k-icon name="chevron" class="toggle-icon" direction="${this.opened?"down":"right"}"></k-icon>`}render(){const e=this.getChildren(),t=null!==this.key?html`<span class="${"number"==typeof this.key?"tc-muted":""}">${this.key}: </span>`:"";return e?html`
|
|
10
10
|
<div>
|
|
11
11
|
<button class="branch-label no-btn" @click=${this.toggle} aria-expanded="${this.opened}">
|
|
12
12
|
${this.renderIcon()}
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
<a href="#explicitSource">Explicitly Set the Source</a><br />
|
|
29
29
|
<a href="#fallbackIcon">Fallback Icon</a><br />
|
|
30
30
|
<a href="#changingIconDirectory">Changing the Icon Directory Location</a><br />
|
|
31
|
-
<a href="#
|
|
31
|
+
<a href="#cliTool">Adding Icons with the CLI</a><br />
|
|
32
|
+
<a href="#addingIcons">Adding Icons Manually</a><br />
|
|
32
33
|
|
|
33
34
|
<h6 class="mt"><a href="#jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
34
35
|
<a href="#constructor">Constructor</a><br />
|
|
@@ -145,10 +146,31 @@
|
|
|
145
146
|
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><br /> window.kempo = {<br /> fallbackIcon: <span class="hljs-string">`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-79q-16 0-30.5-6T423-102L102-423q-11-12-17-26.5T79-480q0-16 6-31t17-26l321-321q12-12 26.5-17.5T480-881q16 0 31 5.5t26 17.5l321 321q12 11 17.5 26t5.5 31q0 16-5.5 30.5T858-423L537-102q-11 11-26 17t-31 6Zm0-80 321-321-321-321-321 321 321 321Zm-40-281h80v-240h-80v240Zm40 120q17 0 28.5-11.5T520-360q0-17-11.5-28.5T480-400q-17 0-28.5 11.5T440-360q0 17 11.5 28.5T480-320Zm0-160Z"/></svg>`</span><br /> };<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
146
147
|
|
|
147
148
|
<h3 id="changingIconDirectory"><a href="#changingIconDirectory" class="no-link">Changing the Icon Directory Location</a></h3>
|
|
148
|
-
<p>To change the location of the directory holding the icons, set the global <code>kempo.
|
|
149
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><br /> window.kempo = {<br />
|
|
149
|
+
<p>To change the location of the directory holding the icons, set the global <code>kempo.pathsToIcons</code> config before any components are loaded (for example in the head of the document). An array of paths is accepted — directories are checked in order and the first match is used, allowing you to override built-in icons or add your own alongside them.</p>
|
|
150
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><br /> window.kempo = {<br /> pathsToIcons: [<span class="hljs-string">'./my-icons'</span>, <span class="hljs-string">'./node_modules/kempo-ui/icons'</span>]<br /> };<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
150
151
|
|
|
151
|
-
<h3 id="
|
|
152
|
+
<h3 id="cliTool"><a href="#cliTool" class="no-link">Adding Icons with the CLI</a></h3>
|
|
153
|
+
<p>kempo-ui ships CLI tools for searching and downloading icons from the <a href="https://fonts.google.com/icons" target="_blank">Google Material Symbols</a> library. They are available via <code>npx</code> after installing kempo-ui.</p>
|
|
154
|
+
<p>Use the interactive picker to search and download in one step — type to filter, arrow keys to navigate, Enter to select:</p>
|
|
155
|
+
<pre><code class="hljs bash">npx kempo-icon</code></pre>
|
|
156
|
+
<p>Or use the individual commands for scripting:</p>
|
|
157
|
+
<pre><code class="hljs bash"># Search by name or tag
|
|
158
|
+
npx kempo-listicons chevron
|
|
159
|
+
|
|
160
|
+
# Download by name (saves to icons/ by default)
|
|
161
|
+
npx kempo-geticon chevron_right
|
|
162
|
+
|
|
163
|
+
# Download with a custom name
|
|
164
|
+
npx kempo-geticon content_copy copy
|
|
165
|
+
|
|
166
|
+
# Save to a custom directory
|
|
167
|
+
npx kempo-geticon format_bold --dir src/assets/icons
|
|
168
|
+
|
|
169
|
+
# Auto-accept directional icon prompt
|
|
170
|
+
npx kempo-geticon chevron_left -y</code></pre>
|
|
171
|
+
<p>Directional icons (those with <code>_left</code>, <code>_up</code>, <code>_down</code> etc. variants) are handled automatically — the CLI downloads the right-facing version and names it without the direction suffix. Use the <code>direction</code> attribute on <code><k-icon></code> to rotate it.</p>
|
|
172
|
+
|
|
173
|
+
<h3 id="addingIcons"><a href="#addingIcons" class="no-link">Adding Icons Manually</a></h3>
|
|
152
174
|
<p>Add your SVGs to the directory, remove the <code>height</code> and <code>width</code> attributes from the <code>svg</code> tag (if you do not, the Icon component will attempt to do it for you). The height and width will be managed by CSS to match the font-size. Give all objects (path, rect, circle) a fill of <code>currentColor</code>, this will allow the icon to adapt to the font color where it is rendered.</p>
|
|
153
175
|
<div class="row -mx mb">
|
|
154
176
|
<div class="col d-span-6 m-span-12 px">
|
|
@@ -192,8 +214,8 @@
|
|
|
192
214
|
<p>Semantic direction for icon rotation. Options: "down" (90°), "left" (180°), "up" (270°). Syncs with the <code>direction</code> attribute. Do not use with <code>rotation</code>.</p>
|
|
193
215
|
<h5><code>animation<i>: string</i></code></h5>
|
|
194
216
|
<p>Built-in animation to apply. Options: "spin" (continuous rotation), "blink" (fade in/out), "pulse" (scale up/down). Syncs with the <code>animation</code> attribute.</p>
|
|
195
|
-
<h5><code>
|
|
196
|
-
<p>An array of paths to directories containing icons. This is configured via the global <code>window.kempo.
|
|
217
|
+
<h5><code>pathsToIcons<i>: Array</i></code></h5>
|
|
218
|
+
<p>An array of paths to directories containing icons. This is configured via the global <code>window.kempo.pathsToIcons</code> config object. Directories are checked in order — the first match wins.</p>
|
|
197
219
|
|
|
198
220
|
</main>
|
|
199
221
|
<div style="height:33vh"></div>
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
<div class="row -mx mb">
|
|
127
127
|
<div class="col d-span-6 m-span-12 px">
|
|
128
128
|
<k-card label="HTML">
|
|
129
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-photo-viewer</span><br /> <span class="hljs-attr">src</span>=<span class="hljs-string">"../media/nsx.jpg"</span><br /> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Honda NSX"</span><br /> <span class="hljs-attr">keyboard-controls</span>=<span class="hljs-string">"false"</span><br />></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"close"</span>></span
|
|
129
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-photo-viewer</span><br /> <span class="hljs-attr">src</span>=<span class="hljs-string">"../media/nsx.jpg"</span><br /> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Honda NSX"</span><br /> <span class="hljs-attr">keyboard-controls</span>=<span class="hljs-string">"false"</span><br />></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"close"</span>></span>✕<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"prev"</span>></span>◀<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"next"</span>></span>▶<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">h6</span>></span>Honda NSX<span class="hljs-tag"></<span class="hljs-name">h6</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">p</span>></span>Custom controls, keyboard disabled<span class="hljs-tag"></<span class="hljs-name">p</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">k-photo-viewer</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">k-photo-viewer</span><br /> <span class="hljs-attr">src</span>=<span class="hljs-string">"../media/evo.jpg"</span><br /> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Mitsubishi Lancer Evolution"</span><br /> <span class="hljs-attr">keyboard-controls</span>=<span class="hljs-string">"false"</span><br />></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"close"</span>></span>✕<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"prev"</span>></span>◀<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"next"</span>></span>▶<span class="hljs-tag"></<span class="hljs-name">span</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">h6</span>></span>Mitsubishi Lancer Evolution<span class="hljs-tag"></<span class="hljs-name">h6</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">p</span>></span>Custom controls, keyboard disabled<span class="hljs-tag"></<span class="hljs-name">p</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">k-photo-viewer</span>></span></code></pre>
|
|
130
130
|
</k-card>
|
|
131
131
|
</div>
|
|
132
132
|
<div class="col d-span-6 m-span-12 px">
|
|
@@ -137,9 +137,9 @@
|
|
|
137
137
|
alt="Honda NSX"
|
|
138
138
|
keyboard-controls="false"
|
|
139
139
|
>
|
|
140
|
-
<span slot="close"
|
|
141
|
-
<span slot="prev"
|
|
142
|
-
<span slot="next"
|
|
140
|
+
<span slot="close">✕</span>
|
|
141
|
+
<span slot="prev">◀</span>
|
|
142
|
+
<span slot="next">▶</span>
|
|
143
143
|
<h6 class="m0">Honda NSX</h6>
|
|
144
144
|
<p class="m0">Custom controls, keyboard disabled</p>
|
|
145
145
|
</k-photo-viewer>
|
|
@@ -148,9 +148,9 @@
|
|
|
148
148
|
alt="Mitsubishi Lancer Evolution"
|
|
149
149
|
keyboard-controls="false"
|
|
150
150
|
>
|
|
151
|
-
<span slot="close"
|
|
152
|
-
<span slot="prev"
|
|
153
|
-
<span slot="next"
|
|
151
|
+
<span slot="close">✕</span>
|
|
152
|
+
<span slot="prev">◀</span>
|
|
153
|
+
<span slot="next">▶</span>
|
|
154
154
|
<h6 class="m0">Mitsubishi Lancer Evolution</h6>
|
|
155
155
|
<p class="m0">Custom controls, keyboard disabled</p>
|
|
156
156
|
</k-photo-viewer>
|
|
@@ -209,11 +209,11 @@
|
|
|
209
209
|
<span class="hljs-keyword">import</span> { html } <span class="hljs-keyword">from</span> <span class="hljs-string">'/src/lit-all.min.js'</span>;
|
|
210
210
|
|
|
211
211
|
<span class="hljs-keyword">class</span> <span class="hljs-title class_">FileHandleNode</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">TreeNode</span> {
|
|
212
|
-
<span class="hljs-title function_">
|
|
212
|
+
<span class="hljs-title function_">render</span>(<span class="hljs-params"></span>){
|
|
213
213
|
<span class="hljs-keyword">const</span> ext = <span class="hljs-variable language_">this</span>.<span class="hljs-property">value</span>.<span class="hljs-property">name</span>.<span class="hljs-title function_">split</span>(<span class="hljs-string">'.'</span>).<span class="hljs-title function_">pop</span>().<span class="hljs-title function_">toLowerCase</span>();
|
|
214
214
|
<span class="hljs-keyword">const</span> iconName = { <span class="hljs-attr">js</span>: <span class="hljs-string">'code'</span>, <span class="hljs-attr">html</span>: <span class="hljs-string">'code_blocks'</span>, <span class="hljs-attr">css</span>: <span class="hljs-string">'code'</span>,
|
|
215
215
|
<span class="hljs-attr">json</span>: <span class="hljs-string">'file-text'</span>, <span class="hljs-attr">md</span>: <span class="hljs-string">'file-text'</span> }[ext] ?? <span class="hljs-string">'file'</span>;
|
|
216
|
-
<span class="hljs-keyword">return</span> html`<span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">k-icon</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"</span></span></span><span class="hljs-subst">${iconName}</span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-icon</span>></span>`</span>;
|
|
216
|
+
<span class="hljs-keyword">return</span> html`<span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"d-b"</span>></span><span class="hljs-tag"><<span class="hljs-name">k-icon</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"</span></span></span><span class="hljs-subst">${iconName}</span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-icon</span>></span> </span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.value.name}</span><span class="language-xml"><span class="hljs-tag"></<span class="hljs-name">span</span>></span>`</span>;
|
|
217
217
|
}
|
|
218
218
|
<span class="hljs-title function_">getChildren</span>(<span class="hljs-params"></span>){ <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>; }
|
|
219
219
|
<span class="hljs-keyword">static</span> detect = <span class="hljs-function"><span class="hljs-params">v</span> =></span> v <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">FileSystemFileHandle</span>;
|
|
@@ -233,10 +233,20 @@
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
<span class="hljs-title function_">getChildren</span>(<span class="hljs-params"></span>){ <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">entries</span> ?? []; }
|
|
236
|
-
<span class="hljs-title function_">renderLabel</span>(<span class="hljs-params"></span>){ <span class="hljs-keyword">return</span> <span class="hljs-string">''</span>; }
|
|
237
236
|
<span class="hljs-title function_">renderIcon</span>(<span class="hljs-params"></span>){
|
|
238
237
|
<span class="hljs-keyword">return</span> html`<span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">k-icon</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"</span></span></span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.opened ? <span class="hljs-string">'folder-open'</span> : <span class="hljs-string">'folder'</span>}</span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-icon</span>></span>`</span>;
|
|
239
238
|
}
|
|
239
|
+
<span class="hljs-title function_">render</span>(<span class="hljs-params"></span>){
|
|
240
|
+
<span class="hljs-keyword">const</span> children = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">getChildren</span>();
|
|
241
|
+
<span class="hljs-keyword">return</span> html`<span class="language-xml">
|
|
242
|
+
<span class="hljs-tag"><<span class="hljs-name">div</span>></span>
|
|
243
|
+
<span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"branch-label no-btn"</span> @<span class="hljs-attr">click</span>=</span></span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.toggle}</span><span class="language-xml"><span class="hljs-tag"> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"</span></span></span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.opened}</span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">"</span>></span>
|
|
244
|
+
</span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.renderIcon()}</span><span class="language-xml"> </span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.value.name}</span><span class="language-xml">
|
|
245
|
+
<span class="hljs-tag"></<span class="hljs-name">button</span>></span>
|
|
246
|
+
</span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.opened ? html`<span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"pl"</span>></span></span><span class="hljs-subst">${children.map(([k, v]) => Tree.renderValue(v, k, <span class="hljs-variable language_">this</span>.depth + <span class="hljs-number">1</span>, <span class="hljs-variable language_">this</span>.maxDepth))}</span><span class="language-xml"><span class="hljs-tag"></<span class="hljs-name">div</span>></span>`</span> : <span class="hljs-string">''</span>}</span><span class="language-xml">
|
|
247
|
+
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
|
|
248
|
+
`</span>;
|
|
249
|
+
}
|
|
240
250
|
<span class="hljs-keyword">static</span> detect = <span class="hljs-function"><span class="hljs-params">v</span> =></span> v <span class="hljs-keyword">instanceof</span> <span class="hljs-title class_">FileSystemDirectoryHandle</span>;
|
|
241
251
|
}
|
|
242
252
|
|
|
@@ -256,11 +266,11 @@
|
|
|
256
266
|
import { html } from '../src/lit-all.min.js';
|
|
257
267
|
|
|
258
268
|
class FileHandleNode extends TreeNode {
|
|
259
|
-
|
|
269
|
+
render(){
|
|
260
270
|
const ext = this.value.name.split('.').pop().toLowerCase();
|
|
261
271
|
const iconName = { js: 'code', html: 'code_blocks', css: 'code',
|
|
262
272
|
json: 'file-text', md: 'file-text' }[ext] ?? 'file';
|
|
263
|
-
return html`<k-icon name="${iconName}"></k-icon>`;
|
|
273
|
+
return html`<span class="d-b"><k-icon name="${iconName}"></k-icon> ${this.value.name}</span>`;
|
|
264
274
|
}
|
|
265
275
|
getChildren(){ return null; }
|
|
266
276
|
static detect = v => v instanceof FileSystemFileHandle;
|
|
@@ -280,10 +290,20 @@
|
|
|
280
290
|
}
|
|
281
291
|
|
|
282
292
|
getChildren(){ return this.entries ?? []; }
|
|
283
|
-
renderLabel(){ return ''; }
|
|
284
293
|
renderIcon(){
|
|
285
294
|
return html`<k-icon name="${this.opened ? 'folder-open' : 'folder'}"></k-icon>`;
|
|
286
295
|
}
|
|
296
|
+
render(){
|
|
297
|
+
const children = this.getChildren();
|
|
298
|
+
return html`
|
|
299
|
+
<div>
|
|
300
|
+
<button class="branch-label no-btn" @click=${this.toggle} aria-expanded="${this.opened}">
|
|
301
|
+
${this.renderIcon()} ${this.value.name}
|
|
302
|
+
</button>
|
|
303
|
+
${this.opened ? html`<div class="pl">${children.map(([k, v]) => Tree.renderValue(v, k, this.depth + 1, this.maxDepth))}</div>` : ''}
|
|
304
|
+
</div>
|
|
305
|
+
`;
|
|
306
|
+
}
|
|
287
307
|
static detect = v => v instanceof FileSystemDirectoryHandle;
|
|
288
308
|
}
|
|
289
309
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>
|
package/docs/icons/add.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m480-320 160-160-160-160-56 56 64 64H320v80h168l-64 64 56 56Zm0 240q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m480-320 160-160-160-160-56 56 64 64H320v80h168l-64 64 56 56Zm0 240q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M800-240v-480h80v480h-80Zm-320 0-57-56 144-144H80v-80h487L424-664l56-56 240 240-240 240Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M800-240v-480h80v480h-80Zm-320 0-57-56 144-144H80v-80h487L424-664l56-56 240 240-240 240Z"/></svg>
|
package/docs/icons/arrow.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-360 280-560h400L480-360Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-360 280-560h400L480-360Z"/></svg>
|
package/docs/icons/cards.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M240-500v-220h220v220H240Zm0 260v-220h220v220H240Zm260-260v-220h220v220H500Zm0 260v-220h220v220H500ZM320-580h60v-60h-60v60Zm260 0h60v-60h-60v60ZM320-320h60v-60h-60v60Zm260 0h60v-60h-60v60ZM380-580Zm200 0Zm0 200Zm-200 0ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M240-500v-220h220v220H240Zm0 260v-220h220v220H240Zm260-260v-220h220v220H500Zm0 260v-220h220v220H500ZM320-580h60v-60h-60v60Zm260 0h60v-60h-60v60ZM320-320h60v-60h-60v60Zm260 0h60v-60h-60v60ZM380-580Zm200 0Zm0 200Zm-200 0ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Z"/></svg>
|
package/docs/icons/check.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M383-480 200-664l56-56 240 240-240 240-56-56 183-184Zm264 0L464-664l56-56 240 240-240 240-56-56 183-184Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M383-480 200-664l56-56 240 240-240 240-56-56 183-184Zm264 0L464-664l56-56 240 240-240 240-56-56 183-184Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m280-240-56-56 184-184-184-184 56-56 240 240-240 240Zm360 0v-480h80v480h-80Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m280-240-56-56 184-184-184-184 56-56 240 240-240 240Zm360 0v-480h80v480h-80Z"/></svg>
|
package/docs/icons/chevron.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>
|
package/docs/icons/close.svg
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>
|
package/docs/icons/code.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M320-240 80-480l240-240 57 57-184 184 183 183-56 56Zm320 0-57-57 184-184-183-183 56-56 240 240-240 240Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M320-240 80-480l240-240 57 57-184 184 183 183-56 56Zm320 0-57-57 184-184-183-183 56-56 240 240-240 240Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m384-336 56-57-87-87 87-87-56-57-144 144 144 144Zm192 0 144-144-144-144-56 57 87 87-87 87 56 57ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m384-336 56-57-87-87 87-87-56-57-144 144 144 144Zm192 0 144-144-144-144-56 57 87 87-87 87 56 57ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>
|