kempo 2.7.2 → 2.7.4
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/dist/components/Table.js +1 -1
- package/dist/components/ThemeSwitcher.js +1 -1
- package/docs/components/table.html +15 -3
- package/docs/icons/arrow-back.svg +1 -0
- package/docs/icons/arrow-forward.svg +1 -0
- package/docs/icons/cards.svg +1 -0
- package/docs/icons/chevron-left.svg +1 -0
- package/docs/icons/chevron-right.svg +1 -0
- package/docs/icons/drawing2.svg +124 -0
- package/docs/icons/file-text.svg +1 -0
- package/docs/icons/file.svg +1 -0
- package/docs/icons/folder-clear.svg +1 -0
- package/docs/icons/folder-create.svg +1 -0
- package/docs/icons/folder-open.svg +1 -0
- package/docs/icons/folder.svg +1 -0
- package/docs/icons/image.svg +1 -0
- package/docs/icons/label-add.svg +1 -0
- package/docs/icons/label.svg +1 -0
- package/docs/icons/mode-auto.svg +1 -0
- package/docs/icons/tag.svg +1 -0
- package/docs/icons/tools.svg +1 -0
- package/docs/kempo/components/Table.js +1 -1
- package/docs/kempo/components/ThemeSwitcher.js +1 -1
- package/package.json +1 -1
- package/scripts/build.js +14 -0
- package/src/components/Table.js +39 -8
- package/src/components/ThemeSwitcher.js +1 -1
- /package/docs/icons/{dark-mode.svg → mode-dark.svg} +0 -0
- /package/docs/icons/{light-mode.svg → mode-light.svg} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M200-200h560v-367L567-760H200v560Zm0 80q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h400l240 240v400q0 33-23.5 56.5T760-120H200Zm80-160h400v-80H280v80Zm0-160h400v-80H280v80Zm0-160h280v-80H280v80Zm-80 400v-560 560Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-280q66 0 113-47t47-113q0-66-47-113t-113-47q-66 0-113 47t-47 113q0 66 47 113t113 47Zm-46-248q11-5 22-8.5t24-3.5q42 0 71 29t29 71q0 13-3.5 24t-8.5 22L434-528Zm46 188q-42 0-71-29t-29-71q0-13 3.5-24t8.5-22l134 134q-11 5-22 8.5t-24 3.5ZM160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640v400q0 33-23.5 56.5T800-160H160Zm0-80h640v-400H447l-80-80H160v480Zm0 0v-480 480Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M560-320h80v-80h80v-80h-80v-80h-80v80h-80v80h80v80ZM160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640v400q0 33-23.5 56.5T800-160H160Zm0-80h640v-400H447l-80-80H160v480Zm0 0v-480 480Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640v400q0 33-23.5 56.5T800-160H160Zm0-80h640v-400H447l-80-80H160v480Zm0 0v-480 480Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M200-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-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-160v-80h120l180-240-180-240H160v200H80v-200q0-33 23.5-56.5T160-800h440q19 0 36 8.5t28 23.5l216 288-216 288q-11 15-28 23.5t-36 8.5H480Zm-10-320ZM200-120v-120H80v-80h120v-120h80v120h120v80H280v120h-80Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h440q19 0 36 8.5t28 23.5l216 288-216 288q-11 15-28 23.5t-36 8.5H160Zm0-80h440l180-240-180-240H160v480Zm220-240Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M 440 -920 L 440 -760 L 520 -760 L 520 -920 L 440 -920 z M 818.67969 -885.5332 L 583.66602 -651.38281 C 553.04363 -670.31258 518.55019 -680 480 -680 C 424.66678 -680 377.49992 -660.49992 338.5 -621.5 C 299.50008 -582.50008 280 -535.33322 280 -480 C 280 -441.71314 289.5643 -407.43184 308.23633 -376.96484 L 97.058594 -166.5625 L 168.59375 -92.332031 L 263.80078 -187.18945 C 267.09506 -183.63709 270.46257 -180.11555 273.9375 -176.64062 C 343.93736 -106.64077 428.9377 -71.640625 528.9375 -71.640625 C 628.9373 -71.640625 713.93764 -106.64077 783.9375 -176.64062 C 853.93736 -246.64049 888.9375 -331.64082 888.9375 -431.64062 C 888.9375 -440.97395 888.60417 -450.14064 887.9375 -459.14062 C 887.27083 -468.14062 886.27083 -476.97398 884.9375 -485.64062 C 865.60421 -458.30735 840.60411 -436.47393 809.9375 -420.14062 C 779.27089 -403.80733 745.60409 -395.64062 708.9375 -395.64062 C 648.93762 -395.64062 597.93742 -416.64072 555.9375 -458.64062 C 552.62172 -461.95641 549.47084 -465.3433 546.42188 -468.77344 L 890.21484 -811.30273 L 818.67969 -885.5332 z M 212 -806 L 155 -747 L 256 -650 L 308 -706 L 212 -806 z M 480 -600 C 495.83397 -600 510.50253 -597.28065 524.08008 -592.01562 L 367.83594 -436.34375 C 362.67843 -449.80488 360 -464.32853 360 -480 C 360 -513.33327 371.66671 -541.66671 395 -565 C 418.33329 -588.33329 446.66673 -600 480 -600 z M 40 -520 L 40 -440 L 200 -440 L 200 -520 L 40 -520 z M 489.73047 -412.28906 C 492.87534 -408.86757 496.09809 -405.48004 499.4375 -402.14062 C 557.10405 -344.47408 626.93766 -315.64062 708.9375 -315.64062 C 722.27081 -315.64062 735.60419 -316.64064 748.9375 -318.64062 C 762.27081 -320.64062 775.60419 -323.3073 788.9375 -326.64062 C 767.60421 -274.64074 733.60407 -232.4739 686.9375 -200.14062 C 640.27093 -167.80736 587.60405 -151.64062 528.9375 -151.64062 C 451.60432 -151.64062 385.60406 -178.97407 330.9375 -233.64062 C 327.48999 -237.08813 324.17746 -240.59082 320.95312 -244.13086 L 489.73047 -412.28906 z " /></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="m240-160 40-160H120l20-80h160l40-160H180l20-80h160l40-160h80l-40 160h160l40-160h80l-40 160h160l-20 80H660l-40 160h160l-20 80H600l-40 160h-80l40-160H360l-40 160h-80Zm140-240h160l40-160H420l-40 160Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M756-120 537-339l84-84 219 219-84 84Zm-552 0-84-84 276-276-68-68-28 28-51-51v82l-28 28-121-121 28-28h82l-50-50 142-142q20-20 43-29t47-9q24 0 47 9t43 29l-92 92 50 50-28 28 68 68 90-90q-4-11-6.5-23t-2.5-24q0-59 40.5-99.5T701-841q15 0 28.5 3t27.5 9l-99 99 72 72 99-99q7 14 9.5 27.5T841-701q0 59-40.5 99.5T701-561q-12 0-24-2t-23-7L204-120Z"/></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import Icon from"./Icon.js";import{toTitleCase}from"../utils/string.js";export default class Table extends Component{constructor(e=!1,t=!1,
|
|
1
|
+
import Component from"./Component.js";import Icon from"./Icon.js";import{toTitleCase}from"../utils/string.js";export default class Table extends Component{constructor(e=!1,t=!1,o={before:[],after:[],top:[],bottom:[]}){super(),this.registerProps({fields:[],records:[],controls:{before:[],after:[],top:[],bottom:[]}}),e&&this.setData(e,t,o)}async render(e){return!!await super.render(e)&&(this.renderControls(this.controls.top,"top"),this.renderFields(),this.renderRecords(),this.renderControls(this.controls.bottom,"bottom"),!0)}renderFields(){const e=this.controls?.before?.length?"<th></th>":"",t=this.controls?.after?.length?"<th></th>":"";this.shadowRoot.getElementById("fields").innerHTML=`${e}${this.fields.map((({label:e})=>`<th>${e}</th>`)).join("")}${t}`}renderRecords(){const e=this.shadowRoot.getElementById("records");e.innerHTML="",this.records.forEach((t=>{const o=document.createElement("tr");this.controls?.before?.length&&o.appendChild(this.renderRowControls(this.controls.before,t)),this.fields.forEach((({name:e})=>{const n=document.createElement("td");let r=t[e]||"";Array.isArray(r)&&(r=r.join(", ")),n.innerHTML=r,o.appendChild(n)})),this.controls?.after?.length&&o.appendChild(this.renderRowControls(this.controls.after,t)),e.appendChild(o)}))}renderRowControls(e=[],t){const o=document.createElement("td");return e.forEach((({html:e,icon:n,action:r,render:s})=>{if(e)o.appendChild(document.createRange().createContextualFragment(e));else if(s&&"function"==typeof s){const e=s(this,t);e instanceof HTMLElement?o.appendChild(e):"string"==typeof e&&o.appendChild(document.createRange().createContextualFragment(e))}else if(n){const e=document.createElement("button");e.appendChild(new Icon(n)),r&&e.addEventListener("click",(()=>r(this,t))),o.appendChild(e)}})),o}renderControls(e=[],t){const o=document.createElement("div");e.forEach((({html:e,icon:t,action:n,render:r})=>{if(e)o.appendChild(document.createRange().createContextualFragment(e));else if(r&&"function"==typeof r){const e=r(this);e instanceof HTMLElement?o.appendChild(e):"string"==typeof e&&o.appendChild(document.createRange().createContextualFragment(e))}else if(t){const e=document.createElement("button");e.appendChild(new Icon(t)),n&&e.addEventListener("click",(()=>n(this))),o.appendChild(e)}})),this.shadowRoot.getElementById(t).innerHTML="",this.shadowRoot.getElementById(t).appendChild(o)}setData(e,t=!1,o={before:[],after:[],top:[],bottom:[]}){this.records=e,this.fields=t||Table.extractFieldsFromRecords(this.records),this.controls=o,this.renderControls(this.controls.top,"top"),this.renderFields(),this.renderRecords(),this.renderControls(this.controls.bottom,"bottom")}get shadowTemplate(){return`\n ${super.shadowTemplate}\n <div class="responsive-table">\n <div id="top"></div>\n <table>\n <thead id="fields"></thead>\n <tbody id="records"></tbody>\n </table>\n <div id="bottom"></div>\n </div>\n `}get shadowStyles(){return`\n ${super.shadowStyles}\n :host {\n display: block;\n margin-bottom: var(--spacer);\n }\n `}static extractFieldsFromRecords(e,t=100){const o=new Set;return e.slice(0,t).forEach((e=>{Object.keys(e).forEach((e=>o.add(e)))})),[...o].map((e=>({name:e,label:toTitleCase(e)})))}}window.customElements.define("k-table",Table);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import{onEvent,dispatchEvent}from"../utils/element.js";import"./Icon.js";const storageWatcher=Symbol("storageWatcher"),clickHandler=Symbol("clickHandler");export default class ThemeSwitcher extends Component{constructor(){super(),this[storageWatcher]=()=>{this.currentTheme=ThemeSwitcher.getCurrentTheme()},this[clickHandler]=()=>{const e=ThemeSwitcher.getCurrentTheme();"auto"===e&&ThemeSwitcher.setTheme("light"),"light"===e&&ThemeSwitcher.setTheme("dark"),"dark"===e&&ThemeSwitcher.setTheme("auto")},this.registerAttribute("currentTheme",ThemeSwitcher.getCurrentTheme())}async render(e){return!!await super.render(e)&&(onEvent(window,"storage",this[storageWatcher]),onEvent(this.shadowRoot.getElementById("toggle"),"click",this[clickHandler]),!0)}disconnectedCallback(){super.disconnectedCallback(),offEvent(this.shadowRoot.getElementById("toggle"),"click",this[clickHandler])}get shadowTemplate(){return'\n <button\n id="toggle"\n class="no-btn"\n >\n <k-icon\n id="autoMode"\n name="mode-auto"\n class="mode"\n ></k-icon>\n <k-icon\n id="lightMode"\n name="mode-light"\n class="mode"\n ></k-icon>\n <k-icon\n id="darkMode"\n name="mode-dark"\n class="mode"\n ></k-icon>\n </button>\n '}get shadowStyles(){return'\n :host {\n --padding: var(--spacer);\n\n display: flex;\n }\n #toggle {\n padding: var(--padding);\n }\n .mode {\n display: none;\n }\n :host([current-theme="auto"]) #autoMode,\n :host([current-theme="light"]) #lightMode,\n :host([current-theme="dark"]) #darkMode {\n display: block;\n }\n '}static setTheme(e){localStorage.setItem("theme",e),document.documentElement.setAttribute("theme",e),dispatchEvent(window,"storage",{theme:e})}static getCurrentTheme(){let e=document.documentElement.getAttribute("theme");return e||(e=localStorage.getItem("theme")),e}}const colorSchemeQuery=window.matchMedia("(prefers-color-scheme: dark)"),colorSchemeChangeHandler=e=>document.documentElement.setAttribute("auto-theme",e.matches?"dark":"light");colorSchemeQuery.addEventListener("change",colorSchemeChangeHandler),colorSchemeChangeHandler(colorSchemeQuery),ThemeSwitcher.setTheme(ThemeSwitcher.getCurrentTheme()),window.customElements.define("k-theme-switcher",ThemeSwitcher);
|
|
1
|
+
import Component from"./Component.js";import{onEvent,dispatchEvent}from"../utils/element.js";import"./Icon.js";const storageWatcher=Symbol("storageWatcher"),clickHandler=Symbol("clickHandler");export default class ThemeSwitcher extends Component{constructor(){super(),this[storageWatcher]=()=>{this.currentTheme=ThemeSwitcher.getCurrentTheme()},this[clickHandler]=()=>{const e=ThemeSwitcher.getCurrentTheme();"auto"===e&&ThemeSwitcher.setTheme("light"),"light"===e&&ThemeSwitcher.setTheme("dark"),"dark"===e&&ThemeSwitcher.setTheme("auto")},this.registerAttribute("currentTheme",ThemeSwitcher.getCurrentTheme())}async render(e){return!!await super.render(e)&&(onEvent(window,"storage",this[storageWatcher]),onEvent(this.shadowRoot.getElementById("toggle"),"click",this[clickHandler]),!0)}disconnectedCallback(){super.disconnectedCallback(),offEvent(this.shadowRoot.getElementById("toggle"),"click",this[clickHandler])}get shadowTemplate(){return'\n <button\n id="toggle"\n class="no-btn"\n >\n <k-icon\n id="autoMode"\n name="mode-auto"\n class="mode"\n ></k-icon>\n <k-icon\n id="lightMode"\n name="mode-light"\n class="mode"\n ></k-icon>\n <k-icon\n id="darkMode"\n name="mode-dark"\n class="mode"\n ></k-icon>\n </button>\n '}get shadowStyles(){return'\n :host {\n --padding: var(--spacer);\n\n display: flex;\n }\n #toggle {\n padding: var(--padding);\n }\n .mode {\n display: none;\n }\n :host([current-theme="auto"]) #autoMode,\n :host([current-theme="light"]) #lightMode,\n :host([current-theme="dark"]) #darkMode {\n display: block;\n }\n '}static setTheme(e){localStorage.setItem("theme",e),document.documentElement.setAttribute("theme",e),dispatchEvent(window,"storage",{theme:e})}static getCurrentTheme(){let e=document.documentElement.getAttribute("theme");return e||(e=localStorage.getItem("theme")),e||"auto"}}const colorSchemeQuery=window.matchMedia("(prefers-color-scheme: dark)"),colorSchemeChangeHandler=e=>document.documentElement.setAttribute("auto-theme",e.matches?"dark":"light");colorSchemeQuery.addEventListener("change",colorSchemeChangeHandler),colorSchemeChangeHandler(colorSchemeQuery),ThemeSwitcher.setTheme(ThemeSwitcher.getCurrentTheme()),window.customElements.define("k-theme-switcher",ThemeSwitcher);
|
package/package.json
CHANGED
package/scripts/build.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import fse from 'fs-extra';
|
|
3
3
|
import { minify } from 'terser';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
4
9
|
|
|
5
10
|
console.log('Loading utils');
|
|
6
11
|
const components = (await fs.readdir('./src/components/')).map(f=>f.substring(0,f.length-3));
|
|
@@ -118,4 +123,13 @@ console.log('Copying dist/ to docs/');
|
|
|
118
123
|
await fse.ensureDir('./docs/'); // will also ensure docs/kempo
|
|
119
124
|
await fse.copy('./dist', './docs/kempo')
|
|
120
125
|
|
|
126
|
+
const iconsSrcDir = path.join(__dirname, '../icons');
|
|
127
|
+
const iconsDestDir = path.join(__dirname, '../docs/icons');
|
|
128
|
+
|
|
129
|
+
console.log('Deleting svg icons currently in docs/icons');
|
|
130
|
+
await fse.ensureDir(iconsDestDir);
|
|
131
|
+
await fse.emptyDir(iconsDestDir);
|
|
132
|
+
console.log('Copying all files from icons to docs/icons');
|
|
133
|
+
await fse.copy(iconsSrcDir, iconsDestDir);
|
|
134
|
+
|
|
121
135
|
console.log('Build Complete');
|
package/src/components/Table.js
CHANGED
|
@@ -3,13 +3,13 @@ import Icon from './Icon.js'; // Import Icon component
|
|
|
3
3
|
import { toTitleCase } from '../utils/string.js';
|
|
4
4
|
|
|
5
5
|
export default class Table extends Component {
|
|
6
|
-
constructor(data = false, fields = false, controls = { before: [], after: [] }){
|
|
6
|
+
constructor(data = false, fields = false, controls = { before: [], after: [], top: [], bottom: [] }){
|
|
7
7
|
super();
|
|
8
8
|
|
|
9
9
|
this.registerProps({
|
|
10
10
|
fields: [],
|
|
11
11
|
records: [],
|
|
12
|
-
controls: { before: [], after: [] }
|
|
12
|
+
controls: { before: [], after: [], top: [], bottom: [] }
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
/* Init */
|
|
@@ -19,8 +19,10 @@ export default class Table extends Component {
|
|
|
19
19
|
}
|
|
20
20
|
async render(force){
|
|
21
21
|
if(await super.render(force)){
|
|
22
|
+
this.renderControls(this.controls.top, 'top');
|
|
22
23
|
this.renderFields();
|
|
23
24
|
this.renderRecords();
|
|
25
|
+
this.renderControls(this.controls.bottom, 'bottom');
|
|
24
26
|
return true;
|
|
25
27
|
}
|
|
26
28
|
return false;
|
|
@@ -36,7 +38,7 @@ export default class Table extends Component {
|
|
|
36
38
|
this.records.forEach((record) => {
|
|
37
39
|
const $tr = document.createElement('tr');
|
|
38
40
|
if(this.controls?.before?.length){
|
|
39
|
-
$tr.appendChild(this.
|
|
41
|
+
$tr.appendChild(this.renderRowControls(this.controls.before, record));
|
|
40
42
|
}
|
|
41
43
|
this.fields.forEach(({name}) => {
|
|
42
44
|
const $td = document.createElement('td');
|
|
@@ -48,19 +50,19 @@ export default class Table extends Component {
|
|
|
48
50
|
$tr.appendChild($td);
|
|
49
51
|
});
|
|
50
52
|
if(this.controls?.after?.length){
|
|
51
|
-
$tr.appendChild(this.
|
|
53
|
+
$tr.appendChild(this.renderRowControls(this.controls.after, record));
|
|
52
54
|
}
|
|
53
55
|
$records.appendChild($tr);
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
renderRowControls(controls = [], record) {
|
|
58
60
|
const $td = document.createElement('td');
|
|
59
61
|
controls.forEach(({ html, icon, action, render }) => {
|
|
60
62
|
if(html){
|
|
61
63
|
$td.appendChild(document.createRange().createContextualFragment(html));
|
|
62
64
|
} else if(render && typeof(render) === 'function'){
|
|
63
|
-
const rendered = render(
|
|
65
|
+
const rendered = render(this, record);
|
|
64
66
|
if(rendered instanceof HTMLElement){
|
|
65
67
|
$td.appendChild(rendered);
|
|
66
68
|
} else if(typeof(rendered) === 'string'){
|
|
@@ -70,7 +72,7 @@ export default class Table extends Component {
|
|
|
70
72
|
const $button = document.createElement('button');
|
|
71
73
|
$button.appendChild(new Icon(icon));
|
|
72
74
|
if (action) {
|
|
73
|
-
$button.addEventListener('click', () => action(
|
|
75
|
+
$button.addEventListener('click', () => action(this, record));
|
|
74
76
|
}
|
|
75
77
|
$td.appendChild($button);
|
|
76
78
|
}
|
|
@@ -78,22 +80,51 @@ export default class Table extends Component {
|
|
|
78
80
|
return $td;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
renderControls(controls = [], position) {
|
|
84
|
+
const $container = document.createElement('div');
|
|
85
|
+
controls.forEach(({ html, icon, action, render }) => {
|
|
86
|
+
if(html){
|
|
87
|
+
$container.appendChild(document.createRange().createContextualFragment(html));
|
|
88
|
+
} else if(render && typeof(render) === 'function'){
|
|
89
|
+
const rendered = render(this);
|
|
90
|
+
if(rendered instanceof HTMLElement){
|
|
91
|
+
$container.appendChild(rendered);
|
|
92
|
+
} else if(typeof(rendered) === 'string'){
|
|
93
|
+
$container.appendChild(document.createRange().createContextualFragment(rendered));
|
|
94
|
+
}
|
|
95
|
+
} else if(icon){
|
|
96
|
+
const $button = document.createElement('button');
|
|
97
|
+
$button.appendChild(new Icon(icon));
|
|
98
|
+
if (action) {
|
|
99
|
+
$button.addEventListener('click', () => action(this));
|
|
100
|
+
}
|
|
101
|
+
$container.appendChild($button);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
this.shadowRoot.getElementById(position).innerHTML = '';
|
|
105
|
+
this.shadowRoot.getElementById(position).appendChild($container);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setData(records, fields = false, controls = { before: [], after: [], top: [], bottom: [] }){
|
|
82
109
|
this.records = records;
|
|
83
110
|
this.fields = fields || Table.extractFieldsFromRecords(this.records);
|
|
84
111
|
this.controls = controls;
|
|
112
|
+
this.renderControls(this.controls.top, 'top');
|
|
85
113
|
this.renderFields();
|
|
86
114
|
this.renderRecords();
|
|
115
|
+
this.renderControls(this.controls.bottom, 'bottom');
|
|
87
116
|
}
|
|
88
117
|
|
|
89
118
|
get shadowTemplate(){
|
|
90
119
|
return /*html*/`
|
|
91
120
|
${super.shadowTemplate}
|
|
92
121
|
<div class="responsive-table">
|
|
122
|
+
<div id="top"></div>
|
|
93
123
|
<table>
|
|
94
124
|
<thead id="fields"></thead>
|
|
95
125
|
<tbody id="records"></tbody>
|
|
96
126
|
</table>
|
|
127
|
+
<div id="bottom"></div>
|
|
97
128
|
</div>
|
|
98
129
|
`;
|
|
99
130
|
}
|
|
@@ -88,7 +88,7 @@ export default class ThemeSwitcher extends Component {
|
|
|
88
88
|
static getCurrentTheme(){
|
|
89
89
|
let theme = document.documentElement.getAttribute('theme');
|
|
90
90
|
if(!theme) theme = localStorage.getItem('theme');
|
|
91
|
-
return theme;
|
|
91
|
+
return theme || 'auto';
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
const colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
File without changes
|
|
File without changes
|