kempo 1.0.0
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/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/components/Card.js +1 -0
- package/dist/components/CodeEditor.js +1 -0
- package/dist/components/Component.js +1 -0
- package/dist/components/Dialog.js +1 -0
- package/dist/components/FocusCapture.js +1 -0
- package/dist/components/Icon.js +1 -0
- package/dist/components/Import.js +1 -0
- package/dist/components/LazyComponent.js +1 -0
- package/dist/components/ReactiveComponent.js +1 -0
- package/dist/components/ReactiveLazyComponent.js +1 -0
- package/dist/components/Resize.js +1 -0
- package/dist/components/Search.js +1 -0
- package/dist/components/ShowMore.js +1 -0
- package/dist/components/SideMenu.js +1 -0
- package/dist/components/Split.js +1 -0
- package/dist/components/Tabs.js +1 -0
- package/dist/components/ThemeSwitcher.js +1 -0
- package/dist/components/Timestamp.js +1 -0
- package/dist/components/WebSnippetEditor.js +1 -0
- package/dist/index.js +1 -0
- package/dist/kempo-hljs.css +1 -0
- package/dist/kempo-styles.css +1 -0
- package/dist/kempo-vars.css +1 -0
- package/dist/kempo.css +1 -0
- package/dist/kempo.js +1 -0
- package/dist/utils/cli.js +1 -0
- package/dist/utils/cookie.js +1 -0
- package/dist/utils/debounce.js +1 -0
- package/dist/utils/drag.js +1 -0
- package/dist/utils/element.js +1 -0
- package/dist/utils/formatTimestamp.js +1 -0
- package/dist/utils/fuzzyMatch.js +1 -0
- package/dist/utils/getPreferredTheme.js +1 -0
- package/dist/utils/loadCss.js +1 -0
- package/dist/utils/loadScript.js +1 -0
- package/dist/utils/object.js +1 -0
- package/dist/utils/string.js +1 -0
- package/dist/utils/toFunction.js +1 -0
- package/dist/utils/type.js +1 -0
- package/dist/utils/waitFrames.js +1 -0
- package/docs/components/_template.html +22 -0
- package/docs/components/card.html +35 -0
- package/docs/components/codeeditor.html +29 -0
- package/docs/components/component.html +88 -0
- package/docs/components/dialog.html +89 -0
- package/docs/components/icon.html +73 -0
- package/docs/components/import.html +34 -0
- package/docs/components/lazycomponent.html +50 -0
- package/docs/components/resize.html +107 -0
- package/docs/components/show-more.html +92 -0
- package/docs/components/sidemenu.html +97 -0
- package/docs/components/split.html +70 -0
- package/docs/components/tabs.html +33 -0
- package/docs/components/websnippeteditor.html +42 -0
- package/docs/index.html +17 -0
- package/docs/kempo/components/Card.js +1 -0
- package/docs/kempo/components/CodeEditor.js +1 -0
- package/docs/kempo/components/Collapse.js +1 -0
- package/docs/kempo/components/Component.js +1 -0
- package/docs/kempo/components/Dialog.js +1 -0
- package/docs/kempo/components/FocusCapture.js +1 -0
- package/docs/kempo/components/Icon.js +1 -0
- package/docs/kempo/components/Import.js +1 -0
- package/docs/kempo/components/LazyComponent.js +1 -0
- package/docs/kempo/components/ReactiveComponent.js +1 -0
- package/docs/kempo/components/ReactiveLazyComponent.js +1 -0
- package/docs/kempo/components/Resize.js +1 -0
- package/docs/kempo/components/Search.js +1 -0
- package/docs/kempo/components/ShowMore.js +1 -0
- package/docs/kempo/components/SideMenu.js +1 -0
- package/docs/kempo/components/Split.js +1 -0
- package/docs/kempo/components/Tabs.js +1 -0
- package/docs/kempo/components/ThemeSwitcher.js +1 -0
- package/docs/kempo/components/Timestamp.js +1 -0
- package/docs/kempo/components/WebSnippetEditor.js +1 -0
- package/docs/kempo/icons/arrow-down-double.svg +1 -0
- package/docs/kempo/icons/arrow-up-double.svg +1 -0
- package/docs/kempo/icons/close.svg +2 -0
- package/docs/kempo/icons/compare.svg +1 -0
- package/docs/kempo/icons/dark-mode.svg +1 -0
- package/docs/kempo/icons/delete.svg +1 -0
- package/docs/kempo/icons/filter-off.svg +1 -0
- package/docs/kempo/icons/filter.svg +1 -0
- package/docs/kempo/icons/light-mode.svg +1 -0
- package/docs/kempo/icons/menu.svg +1 -0
- package/docs/kempo/icons/pause.svg +1 -0
- package/docs/kempo/icons/play.svg +1 -0
- package/docs/kempo/icons/search.svg +1 -0
- package/docs/kempo/icons/settings.svg +1 -0
- package/docs/kempo/icons/storage.svg +1 -0
- package/docs/kempo/icons/trash-x.svg +1 -0
- package/docs/kempo/index.js +1 -0
- package/docs/kempo/kempo-hljs.css +1 -0
- package/docs/kempo/kempo-styles.css +1 -0
- package/docs/kempo/kempo-vars.css +1 -0
- package/docs/kempo/kempo.css +1 -0
- package/docs/kempo/kempo.js +1 -0
- package/docs/kempo/utils/cli.js +1 -0
- package/docs/kempo/utils/cookie.js +1 -0
- package/docs/kempo/utils/debounce.js +1 -0
- package/docs/kempo/utils/drag.js +1 -0
- package/docs/kempo/utils/element.js +1 -0
- package/docs/kempo/utils/formatTimestamp.js +1 -0
- package/docs/kempo/utils/fuzzyMatch.js +1 -0
- package/docs/kempo/utils/getPreferredTheme.js +1 -0
- package/docs/kempo/utils/loadCss.js +1 -0
- package/docs/kempo/utils/loadScript.js +1 -0
- package/docs/kempo/utils/object.js +1 -0
- package/docs/kempo/utils/string.js +1 -0
- package/docs/kempo/utils/toFunction.js +1 -0
- package/docs/kempo/utils/type.js +1 -0
- package/docs/kempo/utils/waitFrames.js +1 -0
- package/docs/nav-1.inc.html +66 -0
- package/docs/nav.inc.html +66 -0
- package/docs/search.json +94 -0
- package/docs/styles/_template.html +22 -0
- package/docs/styles/borders-spacing.html +193 -0
- package/docs/styles/buttons.html +113 -0
- package/docs/styles/colors.html +65 -0
- package/docs/styles/displays-layouts.html +156 -0
- package/docs/styles/embed-1.html +35 -0
- package/docs/styles/inputs.html +89 -0
- package/docs/styles/tables.html +143 -0
- package/docs/styles/typography.html +116 -0
- package/icons/arrow-down-double.svg +1 -0
- package/icons/arrow-up-double.svg +1 -0
- package/icons/close.svg +2 -0
- package/icons/compare.svg +1 -0
- package/icons/dark-mode.svg +1 -0
- package/icons/delete.svg +1 -0
- package/icons/filter-off.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/light-mode.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/storage.svg +1 -0
- package/icons/trash-x.svg +1 -0
- package/kempo/components/Card.js +65 -0
- package/kempo/components/CodeEditor.js +141 -0
- package/kempo/components/Component.js +109 -0
- package/kempo/components/Dialog.js +277 -0
- package/kempo/components/FocusCapture.js +30 -0
- package/kempo/components/Icon.js +60 -0
- package/kempo/components/Import.js +40 -0
- package/kempo/components/LazyComponent.js +40 -0
- package/kempo/components/ReactiveComponent.js +11 -0
- package/kempo/components/ReactiveLazyComponent.js +11 -0
- package/kempo/components/Resize.js +168 -0
- package/kempo/components/Search.js +136 -0
- package/kempo/components/ShowMore.js +82 -0
- package/kempo/components/SideMenu.js +156 -0
- package/kempo/components/Split.js +133 -0
- package/kempo/components/Tabs.js +254 -0
- package/kempo/components/ThemeSwitcher.js +77 -0
- package/kempo/components/Timestamp.js +25 -0
- package/kempo/components/WebSnippetEditor.js +159 -0
- package/kempo/kempo-hljs.css +145 -0
- package/kempo/kempo-styles.css +893 -0
- package/kempo/kempo-vars.css +154 -0
- package/kempo/kempo.js +48 -0
- package/kempo/utils/cli.js +54 -0
- package/kempo/utils/cookie.js +16 -0
- package/kempo/utils/debounce.js +9 -0
- package/kempo/utils/drag.js +74 -0
- package/kempo/utils/element.js +69 -0
- package/kempo/utils/formatTimestamp.js +11 -0
- package/kempo/utils/fuzzyMatch.js +55 -0
- package/kempo/utils/getPreferredTheme.js +1 -0
- package/kempo/utils/loadCss.js +10 -0
- package/kempo/utils/loadScript.js +10 -0
- package/kempo/utils/object.js +177 -0
- package/kempo/utils/string.js +54 -0
- package/kempo/utils/toFunction.js +24 -0
- package/kempo/utils/type.js +8 -0
- package/kempo/utils/waitFrames.js +17 -0
- package/package.json +33 -0
- package/scripts/build.js +131 -0
- package/scripts/docs.js +14 -0
- package/test/components/SuiteList.js +26 -0
- package/test/components/Test.js +357 -0
- package/test/index.html +49 -0
- package/test/index.js +25 -0
- package/test/suite.html +45 -0
- package/test/suites.inc.html +4 -0
- package/test/tests/components/Component.test.js +138 -0
- package/test/tests/utils/cli.test.js +113 -0
- package/test/tests/utils/cookie.test.js +87 -0
- package/test/tests/utils/debounce.test.js +71 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
import debounce from '../utils/debounce.js';
|
|
3
|
+
|
|
4
|
+
const inputHandler = Symbol('inputHandler'),
|
|
5
|
+
focusHandler = Symbol('focusHandler'),
|
|
6
|
+
blurHandler = Symbol('blurHandler');
|
|
7
|
+
export default class Search extends Component {
|
|
8
|
+
constructor(){
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this[inputHandler] = debounce(() => {
|
|
12
|
+
this.search(this.shadowRoot.getElementById('input').value);
|
|
13
|
+
});
|
|
14
|
+
this[focusHandler] = () => {
|
|
15
|
+
this.opened = true;
|
|
16
|
+
}
|
|
17
|
+
this[blurHandler] = () => {
|
|
18
|
+
setTimeout(()=>{
|
|
19
|
+
this.opened = false;
|
|
20
|
+
}, 100);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.registerAttribute('opened', false);
|
|
24
|
+
this.registerProp('pages', {});
|
|
25
|
+
}
|
|
26
|
+
async render(force){
|
|
27
|
+
if(await super.render(force)){
|
|
28
|
+
this.pages = await (await fetch('/search.json')).json();
|
|
29
|
+
const $input = this.shadowRoot.getElementById('input')
|
|
30
|
+
$input.addEventListener('input', this[inputHandler]);
|
|
31
|
+
$input.addEventListener('focus', this[focusHandler]);
|
|
32
|
+
$input.addEventListener('blur', this[blurHandler]);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
search(term){
|
|
38
|
+
const $results = this.shadowRoot.getElementById('results');
|
|
39
|
+
if(term === ''){
|
|
40
|
+
$results.innerHTML = '';
|
|
41
|
+
} else {
|
|
42
|
+
const t = term.trim().toLowerCase();
|
|
43
|
+
Object.keys(this.pages).forEach( path => {
|
|
44
|
+
const page = this.pages[path];
|
|
45
|
+
page.score = 0;
|
|
46
|
+
if(page.name.toLowerCase().startsWith(t)){
|
|
47
|
+
page.score += 5;
|
|
48
|
+
} else if(page.name.toLowerCase().includes(t)){
|
|
49
|
+
page.score += 3;
|
|
50
|
+
}
|
|
51
|
+
if(page.terms.includes(t)){
|
|
52
|
+
page.score += 3;
|
|
53
|
+
}
|
|
54
|
+
page.terms.forEach( term => {
|
|
55
|
+
if(term.startsWith(t)){
|
|
56
|
+
page.score += 2;
|
|
57
|
+
} else if(term.includes(t)){
|
|
58
|
+
page.score += 1;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const results = Object.keys(this.pages)
|
|
63
|
+
.map( path => {
|
|
64
|
+
return {
|
|
65
|
+
path: path,
|
|
66
|
+
...(this.pages[path])
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.filter(({score})=>score)
|
|
70
|
+
.sort(({score: a}, {score: b})=>b-a)
|
|
71
|
+
.slice(0, 4);
|
|
72
|
+
if(results.length){
|
|
73
|
+
$results.innerHTML = results.map(({
|
|
74
|
+
path,
|
|
75
|
+
name
|
|
76
|
+
}) => `<a href="${path}">${name}</a>`).join('');
|
|
77
|
+
} else {
|
|
78
|
+
$results.innerHTML = `<a>No Results</a>`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
get shadowTemplate(){
|
|
85
|
+
return /*html*/`
|
|
86
|
+
<div id="wrapper">
|
|
87
|
+
<input
|
|
88
|
+
id="input"
|
|
89
|
+
placeholder="Search"
|
|
90
|
+
type="search"
|
|
91
|
+
/>
|
|
92
|
+
<div id="results"></div>
|
|
93
|
+
</div>
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
get shadowStyles(){
|
|
97
|
+
return /*css*/`
|
|
98
|
+
:host {
|
|
99
|
+
display: inline-block;
|
|
100
|
+
align-self: center;
|
|
101
|
+
}
|
|
102
|
+
#wrapper {
|
|
103
|
+
position: relative;
|
|
104
|
+
}
|
|
105
|
+
#input {
|
|
106
|
+
width: 100%;
|
|
107
|
+
margin: 0;
|
|
108
|
+
}
|
|
109
|
+
#results {
|
|
110
|
+
display: none;
|
|
111
|
+
position: absolute;
|
|
112
|
+
top: 100%;
|
|
113
|
+
left: 0;
|
|
114
|
+
width: 100%;
|
|
115
|
+
max-height: 20rem;
|
|
116
|
+
background-color: var(--c_bg);
|
|
117
|
+
color: var(--tc);
|
|
118
|
+
box-shadow: var(--drop_shadow);
|
|
119
|
+
}
|
|
120
|
+
:host([opened="true"]) #results {
|
|
121
|
+
display: block;
|
|
122
|
+
}
|
|
123
|
+
#results a {
|
|
124
|
+
display: block;
|
|
125
|
+
padding: var(--spacer_h);
|
|
126
|
+
text-decoration: none;
|
|
127
|
+
border-bottom: 1px solid var(--c_border);
|
|
128
|
+
border-radius: 0;
|
|
129
|
+
}
|
|
130
|
+
#results a:last-child {
|
|
131
|
+
border-bottom: 0;
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
window.customElements.define('k-search', Search);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import LazyComponent from './LazyComponent.js';
|
|
2
|
+
import './Icon.js';
|
|
3
|
+
import {
|
|
4
|
+
onEvent,
|
|
5
|
+
offEvent,
|
|
6
|
+
dispatchEvent
|
|
7
|
+
} from '../utils/element.js';
|
|
8
|
+
|
|
9
|
+
export default class ShowMore extends LazyComponent {
|
|
10
|
+
constructor(){
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
this.registerAttribute('opened', false);
|
|
14
|
+
this.registerProp('_toggleClickHandler', () => this.toggle());
|
|
15
|
+
}
|
|
16
|
+
async render(force){
|
|
17
|
+
await super.render(force);
|
|
18
|
+
onEvent(this.shadowRoot.getElementById('toggle'), 'click', this._toggleClickHandler);
|
|
19
|
+
}
|
|
20
|
+
more(){
|
|
21
|
+
this.opened = true;
|
|
22
|
+
}
|
|
23
|
+
less(){
|
|
24
|
+
this.opened = false;
|
|
25
|
+
}
|
|
26
|
+
toggle(){
|
|
27
|
+
this.opened?this.less():this.more();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get shadowTemplate(){
|
|
31
|
+
return /*html*/`
|
|
32
|
+
<div id="wrapper">
|
|
33
|
+
<div id="content">
|
|
34
|
+
${super.shadowTemplate}
|
|
35
|
+
</div>
|
|
36
|
+
<button
|
|
37
|
+
id="toggle"
|
|
38
|
+
class="no-btn"
|
|
39
|
+
>
|
|
40
|
+
<span id="more">
|
|
41
|
+
<slot name="more">Show More <k-icon name="arrow-down-double"></k-icon></slot>
|
|
42
|
+
</span>
|
|
43
|
+
<span id="less">
|
|
44
|
+
<slot name="less">Show Less <k-icon name="arrow-up-double"></k-icon></slot>
|
|
45
|
+
</span>
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
get shadowStyles(){
|
|
51
|
+
return /*css*/`
|
|
52
|
+
${super.shadowStyles}
|
|
53
|
+
:host {
|
|
54
|
+
--closed_height: 7rem;
|
|
55
|
+
|
|
56
|
+
display: block;
|
|
57
|
+
}
|
|
58
|
+
:host(:not([opened])) #content{
|
|
59
|
+
height: var(--closed_height);
|
|
60
|
+
overflow-y: hidden;
|
|
61
|
+
}
|
|
62
|
+
:host(:not([opened])) #content {
|
|
63
|
+
margin-bottom: calc(var(--closed_height) * -0.9);
|
|
64
|
+
}
|
|
65
|
+
:host(:not([opened])) #toggle {
|
|
66
|
+
padding-top: calc(var(--closed_height) - 2rem);
|
|
67
|
+
background: linear-gradient(to bottom, transparent 0%, var(--c_bg) 95%);
|
|
68
|
+
}
|
|
69
|
+
#toggle {
|
|
70
|
+
width: 100%;
|
|
71
|
+
padding: var(--spacer_h);
|
|
72
|
+
text-align: center;
|
|
73
|
+
background: var(--c_bg);
|
|
74
|
+
}
|
|
75
|
+
:host([opened]) #more,
|
|
76
|
+
:host(:not([opened])) #less {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
window.customElements.define('k-show-more', ShowMore);
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import LazyComponent from './LazyComponent.js';
|
|
2
|
+
import './Icon.js';
|
|
3
|
+
import './FocusCapture.js';
|
|
4
|
+
import {
|
|
5
|
+
onEvent,
|
|
6
|
+
offEvent,
|
|
7
|
+
dispatchEvent
|
|
8
|
+
} from '../utils/element.js';
|
|
9
|
+
|
|
10
|
+
export class SideMenu extends LazyComponent {
|
|
11
|
+
constructor(){
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
this.registerAttribute('opened', false);
|
|
15
|
+
this.registerAttribute('overlayClose', true);
|
|
16
|
+
this.registerProps({
|
|
17
|
+
_overlayClick: () => {
|
|
18
|
+
if(this.overlayClose) this.close();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
disconnectedCallback(){
|
|
23
|
+
super.disconnectedCallback();
|
|
24
|
+
offEvent(this.shadowRoot.getElementById('overlay'), 'click', this._overlayClick);
|
|
25
|
+
}
|
|
26
|
+
attributeChangedCallback(n, oV, nV){
|
|
27
|
+
super.attributeChangedCallback(n, oV, nV);
|
|
28
|
+
if(n === 'opened'){
|
|
29
|
+
if(nV === 'true'){
|
|
30
|
+
dispatchEvent(this, 'change open');
|
|
31
|
+
} else {
|
|
32
|
+
dispatchEvent(this, 'change close');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
render(force){
|
|
37
|
+
super.render(force);
|
|
38
|
+
onEvent(this.shadowRoot.getElementById('overlay'), 'click', this._overlayClick);
|
|
39
|
+
}
|
|
40
|
+
open(){
|
|
41
|
+
this.opened = true;
|
|
42
|
+
}
|
|
43
|
+
close(){
|
|
44
|
+
this.opened = false;
|
|
45
|
+
}
|
|
46
|
+
toggle(){
|
|
47
|
+
this.opened?this.close():this.open();
|
|
48
|
+
dispatchEvent(this, 'toggle');
|
|
49
|
+
}
|
|
50
|
+
get shadowTemplate(){
|
|
51
|
+
return /*html*/`
|
|
52
|
+
<k-focus-capture>
|
|
53
|
+
<div id="container">
|
|
54
|
+
<button id="overlay" class="no-btn">
|
|
55
|
+
<k-icon id="overlay-x" name="close"></k-icon>
|
|
56
|
+
</button>
|
|
57
|
+
<div id="menu">
|
|
58
|
+
${super.shadowTemplate}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</k-focus-capture>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
get shadowStyles(){
|
|
65
|
+
return /*css*/`
|
|
66
|
+
${super.shadowStyles}
|
|
67
|
+
:host {
|
|
68
|
+
--bg: var(--c_bg);
|
|
69
|
+
--width: 20rem;
|
|
70
|
+
|
|
71
|
+
position: fixed;
|
|
72
|
+
top: 0;
|
|
73
|
+
left: 0;
|
|
74
|
+
width: 100vw;
|
|
75
|
+
max-width: 100%;
|
|
76
|
+
height: 100vh;
|
|
77
|
+
z-index: 100;
|
|
78
|
+
pointer-events: none;
|
|
79
|
+
}
|
|
80
|
+
:host([opened]) {
|
|
81
|
+
pointer-events: auto;
|
|
82
|
+
}
|
|
83
|
+
k-focus-capture {
|
|
84
|
+
width: 100%;
|
|
85
|
+
height: 100%;
|
|
86
|
+
}
|
|
87
|
+
#container {
|
|
88
|
+
position: relative;
|
|
89
|
+
width: 100%;
|
|
90
|
+
height: 100%;
|
|
91
|
+
opacity: 0;
|
|
92
|
+
transition: opacity var(--animation_ms, 256ms);
|
|
93
|
+
}
|
|
94
|
+
:host([opened]) #container {
|
|
95
|
+
opacity: 1;
|
|
96
|
+
}
|
|
97
|
+
#overlay {
|
|
98
|
+
position: absolute;
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 100%;
|
|
101
|
+
left: 0;
|
|
102
|
+
top: 0;
|
|
103
|
+
background: var(--overlay, rgba(0, 0, 0, 0.5));
|
|
104
|
+
}
|
|
105
|
+
#overlay-x {
|
|
106
|
+
position: absolute;
|
|
107
|
+
top: var(--spacer_h);
|
|
108
|
+
right: var(--spacer_h);
|
|
109
|
+
font-size: 1.75rem;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
color: var(--tc_light);
|
|
112
|
+
}
|
|
113
|
+
:host([overlay-close="false"]) #overlay-x {
|
|
114
|
+
display: none;
|
|
115
|
+
}
|
|
116
|
+
:host([overlay-close="false"]) #overlay {
|
|
117
|
+
cursor: default;
|
|
118
|
+
}
|
|
119
|
+
#menu {
|
|
120
|
+
position: absolute;
|
|
121
|
+
width: var(--width);
|
|
122
|
+
max-width: calc(100vw - 6rem);
|
|
123
|
+
height: 100vh;
|
|
124
|
+
overflow-y: auto;
|
|
125
|
+
left: calc(var(--width) * -1);
|
|
126
|
+
top: 0;
|
|
127
|
+
background: var(--bg);
|
|
128
|
+
transition: left var(--animation_ms, 256ms);
|
|
129
|
+
padding: var(--menu_padding, var(--spacer))
|
|
130
|
+
}
|
|
131
|
+
:host([opened]) #menu {
|
|
132
|
+
left: 0;
|
|
133
|
+
}
|
|
134
|
+
:host([side="right"]) #menu {
|
|
135
|
+
left: auto;
|
|
136
|
+
transition: right var(--animation_ms, 256ms);
|
|
137
|
+
right: calc(var(--width) * -1);
|
|
138
|
+
}
|
|
139
|
+
:host([opened][side="right"]) #menu {
|
|
140
|
+
right: 0;
|
|
141
|
+
}
|
|
142
|
+
:host([side="right"]) #overlay-x {
|
|
143
|
+
right: auto;
|
|
144
|
+
left: var(--spacer_h);
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static get observedAttributes(){
|
|
150
|
+
return [
|
|
151
|
+
'opened',
|
|
152
|
+
...super.observedAttributes
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
window.customElements.define('k-side-menu', SideMenu);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
import drag from '../utils/drag.js';
|
|
3
|
+
import {
|
|
4
|
+
dispatchEvent
|
|
5
|
+
} from '../utils/element.js';
|
|
6
|
+
|
|
7
|
+
const dragStartWidth = Symbol(),
|
|
8
|
+
dragStartCallback = Symbol(),
|
|
9
|
+
dragEndCallback = Symbol(),
|
|
10
|
+
dragCallback = Symbol(),
|
|
11
|
+
dragCleanup = Symbol();
|
|
12
|
+
export default class Split extends Component {
|
|
13
|
+
constructor(_saveWidth, _loadWidth){
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
/* Private Members */
|
|
17
|
+
this[dragStartWidth] = 0;
|
|
18
|
+
|
|
19
|
+
/* Private Methods */
|
|
20
|
+
this[dragStartCallback] = () => {
|
|
21
|
+
this.resizing = true;
|
|
22
|
+
this[dragStartWidth] = Math.round(this.shadowRoot.getElementById('left').getBoundingClientRect().width);
|
|
23
|
+
dispatchEvent(this, 'resizestart', {
|
|
24
|
+
startSize: this[dragStartWidth]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
this[dragCallback] = ({x}) => {
|
|
28
|
+
const size = `${this[dragStartWidth] + x}px`;
|
|
29
|
+
this.setSize(size);
|
|
30
|
+
dispatchEvent(this, 'resize', { size } );
|
|
31
|
+
}
|
|
32
|
+
this[dragEndCallback] = ({x}) => {
|
|
33
|
+
this.resizing = false;
|
|
34
|
+
const width = this[dragStartWidth] + x;
|
|
35
|
+
const size = `${width}px`;
|
|
36
|
+
this.setSize(size);
|
|
37
|
+
dispatchEvent(this, 'resizeend', { size } );
|
|
38
|
+
}
|
|
39
|
+
this[dragCleanup] = () => {}
|
|
40
|
+
|
|
41
|
+
/* Init */
|
|
42
|
+
this.registerAttribute('resizing', false);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async connectedCallback(){
|
|
46
|
+
super.connectedCallback();
|
|
47
|
+
this[dragCleanup] = drag({
|
|
48
|
+
element: this.shadowRoot.getElementById('divider-handle'),
|
|
49
|
+
callback: this[dragCallback],
|
|
50
|
+
startCallback: this[dragStartCallback],
|
|
51
|
+
endCallback: this[dragEndCallback]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
disconnectedCallback(){
|
|
55
|
+
super.disconnectedCallback();
|
|
56
|
+
this[dragCleanup]();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setSize(size){
|
|
60
|
+
this.style.setProperty('--left_width', size);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get shadowTemplate(){
|
|
64
|
+
return /*html*/`
|
|
65
|
+
<div
|
|
66
|
+
id="left"
|
|
67
|
+
class="pane"
|
|
68
|
+
>
|
|
69
|
+
${super.shadowTemplate}
|
|
70
|
+
</div>
|
|
71
|
+
<div id="divider-handle">
|
|
72
|
+
<div id="divider-border"></div>
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
id="right"
|
|
76
|
+
class="pane"
|
|
77
|
+
>
|
|
78
|
+
<slot name="right"></slot>
|
|
79
|
+
</div>
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
get shadowStyles(){
|
|
83
|
+
return /*css*/`
|
|
84
|
+
${super.shadowStyles}
|
|
85
|
+
:host {
|
|
86
|
+
--left_width: calc( (100% - var(--handle_width)) / 2);
|
|
87
|
+
--handle_width: 0.5rem;
|
|
88
|
+
--min_pane_width: 6rem;
|
|
89
|
+
|
|
90
|
+
height: 100%;
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: stretch;
|
|
93
|
+
flex: 1 1 auto;
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
}
|
|
96
|
+
.pane, #divider-handle {
|
|
97
|
+
display: inline-block;
|
|
98
|
+
}
|
|
99
|
+
.pane {
|
|
100
|
+
min-width: var(--min_pane_width);
|
|
101
|
+
max-width: calc(100% - var(--min_pane_width));
|
|
102
|
+
max-height: 100%;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
}
|
|
105
|
+
#left {
|
|
106
|
+
flex: 0 0 var(--left_width);
|
|
107
|
+
}
|
|
108
|
+
#divider-handle {
|
|
109
|
+
display: flex;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
width: var(--handle_width);
|
|
112
|
+
cursor: ew-resize;
|
|
113
|
+
}
|
|
114
|
+
:host([resizing]) #divider-handle {
|
|
115
|
+
background-color: var(--tc_primary);
|
|
116
|
+
}
|
|
117
|
+
:host([resizing]) .pane {
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
user-select: none;
|
|
120
|
+
}
|
|
121
|
+
#divider-border {
|
|
122
|
+
width: 1px;
|
|
123
|
+
height: 100%;
|
|
124
|
+
border-left: 1px solid var(--c_border);
|
|
125
|
+
}
|
|
126
|
+
#right {
|
|
127
|
+
flex: 1 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
window.customElements.define('k-split', Split);
|