kempo 4.1.0 → 4.2.1
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/Split.js +1 -1
- package/dist/utils/watchWindowSize.js +1 -0
- package/docs/components/split.html +19 -0
- package/docs/kempo/components/Split.js +1 -1
- package/docs/kempo/utils/watchWindowSize.js +1 -0
- package/package.json +1 -1
- package/src/components/Split.js +38 -13
- package/src/utils/watchWindowSize.js +15 -0
package/dist/components/Split.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import drag from"../utils/drag.js";import{dispatchEvent}from"../utils/element.js";const dragStartWidth=Symbol(),dragStartCallback=Symbol(),dragEndCallback=Symbol(),dragCallback=Symbol(),dragCleanup=Symbol();export default class Split extends Component{constructor(t
|
|
1
|
+
import Component from"./Component.js";import drag from"../utils/drag.js";import{dispatchEvent}from"../utils/element.js";import{watchWindowSize,unwatchWindowSize}from"../utils/watchWindowSize.js";const dragStartWidth=Symbol(),dragStartCallback=Symbol(),dragEndCallback=Symbol(),dragCallback=Symbol(),dragCleanup=Symbol(),windowResizeHandler=Symbol();export default class Split extends Component{constructor({stackWidth:t=0}={}){super(),this[dragStartWidth]=0,this[dragStartCallback]=()=>{this.resizing=!0,this[dragStartWidth]=Math.round(this.shadowRoot.getElementById("left").getBoundingClientRect().width),dispatchEvent(this,"resizestart",{startSize:this[dragStartWidth]})},this[dragCallback]=({x:t})=>{const e=`${this[dragStartWidth]+t}px`;this.setSize(e),dispatchEvent(this,"resize",{size:e})},this[dragEndCallback]=({x:t})=>{this.resizing=!1;const e=`${this[dragStartWidth]+t}px`;this.setSize(e),dispatchEvent(this,"resizeend",{size:e})},this[dragCleanup]=()=>{},this[windowResizeHandler]=t=>{this.stacked=t<=this.stackWidth},this.registerAttributes({resizing:!1,stacked:!1,stackWidth:t})}disconnectedCallback(){super.disconnectedCallback(),this[dragCleanup]()}async render(t){return!!await super.render(t)&&(this[dragCleanup]=drag({element:this.shadowRoot.getElementById("divider-handle"),callback:this[dragCallback],startCallback:this[dragStartCallback],endCallback:this[dragEndCallback]}),this.stacked=watchWindowSize(this[windowResizeHandler])<=this.stackWidth,!0)}setSize(t){this.style.setProperty("--left_width",t)}get shadowTemplate(){return`\n <div\n id="left"\n class="pane"\n >\n ${super.shadowTemplate}\n </div>\n <div id="divider-handle">\n <div id="divider-border"></div>\n </div>\n <div\n id="right"\n class="pane"\n >\n <slot name="right"></slot>\n </div>\n `}get shadowStyles(){return`\n ${super.shadowStyles}\n :host {\n --left_width: calc( (100% - var(--handle_width)) / 2);\n --handle_width: 0.5rem;\n --min_pane_width: 6rem;\n\n height: 100%;\n display: flex;\n align-items: stretch;\n flex: 1 1 auto;\n overflow: hidden;\n }\n .pane, #divider-handle {\n display: inline-block;\n }\n .pane {\n min-width: var(--min_pane_width);\n max-width: calc(100% - var(--min_pane_width));\n max-height: 100%;\n overflow: hidden;\n }\n #left {\n flex: 0 0 var(--left_width);\n }\n #divider-handle {\n display: flex;\n justify-content: center;\n width: var(--handle_width);\n cursor: ew-resize;\n }\n :host([resizing]) #divider-handle {\n background-color: var(--tc_primary);\n }\n :host([resizing]) .pane {\n pointer-events: none;\n user-select: none;\n }\n #divider-border {\n width: 1px;\n height: 100%;\n border-left: 1px solid var(--c_border);\n }\n #right {\n flex: 1 1;\n }\n :host([stacked="true"]),\n :host([stacked="true"]) #left,\n :host([stacked="true"]) #right {\n display: block;\n }\n :host([stacked="true"]) #divider-handle {\n display: none;\n } \n `}}window.customElements.define("k-split",Split);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import debounce from"./debounce.js";const handlers=new Set;window.addEventListener("resize",debounce((()=>{const e=window.innerWidth;handlers.forEach((n=>n(e)))})));export const watchWindowSize=e=>(handlers.add(e),window.innerWidth);export const unwatchWindowSize=e=>{handlers.remove(e)};
|
|
@@ -79,6 +79,25 @@
|
|
|
79
79
|
</div>
|
|
80
80
|
</div>
|
|
81
81
|
|
|
82
|
+
<h3 id="stacking"><a href="#stacking" class="no-link">Stacking</a></h3>
|
|
83
|
+
<p>When the screen size is small (mobile) a split panel may not make sense, rather than changing the markup set the <code>stack-width</code> attribute to stack the contents (disable split view) when the window size is less than the provided size.</p>
|
|
84
|
+
<div class="row -mx">
|
|
85
|
+
<div class="col m-span-12 px">
|
|
86
|
+
<k-card label="HTML">
|
|
87
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-split</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"height: 10rem"</span> <span class="hljs-attr">stack-width</span>=<span class="hljs-string">"1080"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">div</span>></span>Left Pane Content<span class="hljs-tag"></<span class="hljs-name">div</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"right"</span>></span>Right Pane Content<span class="hljs-tag"></<span class="hljs-name">div</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">k-split</span>></span></code></pre>
|
|
88
|
+
</k-card>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="col m-span-12 px">
|
|
91
|
+
<k-card label="Output">
|
|
92
|
+
<k-split style="height: 10rem" stack-width="1080">
|
|
93
|
+
<div>Left Pane Content</div>
|
|
94
|
+
<div slot="right">Right Pane Content</div>
|
|
95
|
+
</k-split>
|
|
96
|
+
</k-card>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
|
|
82
101
|
<h2 id="jsRef">JavaScript Reference</h2>
|
|
83
102
|
|
|
84
103
|
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import drag from"../utils/drag.js";import{dispatchEvent}from"../utils/element.js";const dragStartWidth=Symbol(),dragStartCallback=Symbol(),dragEndCallback=Symbol(),dragCallback=Symbol(),dragCleanup=Symbol();export default class Split extends Component{constructor(t
|
|
1
|
+
import Component from"./Component.js";import drag from"../utils/drag.js";import{dispatchEvent}from"../utils/element.js";import{watchWindowSize,unwatchWindowSize}from"../utils/watchWindowSize.js";const dragStartWidth=Symbol(),dragStartCallback=Symbol(),dragEndCallback=Symbol(),dragCallback=Symbol(),dragCleanup=Symbol(),windowResizeHandler=Symbol();export default class Split extends Component{constructor({stackWidth:t=0}={}){super(),this[dragStartWidth]=0,this[dragStartCallback]=()=>{this.resizing=!0,this[dragStartWidth]=Math.round(this.shadowRoot.getElementById("left").getBoundingClientRect().width),dispatchEvent(this,"resizestart",{startSize:this[dragStartWidth]})},this[dragCallback]=({x:t})=>{const e=`${this[dragStartWidth]+t}px`;this.setSize(e),dispatchEvent(this,"resize",{size:e})},this[dragEndCallback]=({x:t})=>{this.resizing=!1;const e=`${this[dragStartWidth]+t}px`;this.setSize(e),dispatchEvent(this,"resizeend",{size:e})},this[dragCleanup]=()=>{},this[windowResizeHandler]=t=>{this.stacked=t<=this.stackWidth},this.registerAttributes({resizing:!1,stacked:!1,stackWidth:t})}disconnectedCallback(){super.disconnectedCallback(),this[dragCleanup]()}async render(t){return!!await super.render(t)&&(this[dragCleanup]=drag({element:this.shadowRoot.getElementById("divider-handle"),callback:this[dragCallback],startCallback:this[dragStartCallback],endCallback:this[dragEndCallback]}),this.stacked=watchWindowSize(this[windowResizeHandler])<=this.stackWidth,!0)}setSize(t){this.style.setProperty("--left_width",t)}get shadowTemplate(){return`\n <div\n id="left"\n class="pane"\n >\n ${super.shadowTemplate}\n </div>\n <div id="divider-handle">\n <div id="divider-border"></div>\n </div>\n <div\n id="right"\n class="pane"\n >\n <slot name="right"></slot>\n </div>\n `}get shadowStyles(){return`\n ${super.shadowStyles}\n :host {\n --left_width: calc( (100% - var(--handle_width)) / 2);\n --handle_width: 0.5rem;\n --min_pane_width: 6rem;\n\n height: 100%;\n display: flex;\n align-items: stretch;\n flex: 1 1 auto;\n overflow: hidden;\n }\n .pane, #divider-handle {\n display: inline-block;\n }\n .pane {\n min-width: var(--min_pane_width);\n max-width: calc(100% - var(--min_pane_width));\n max-height: 100%;\n overflow: hidden;\n }\n #left {\n flex: 0 0 var(--left_width);\n }\n #divider-handle {\n display: flex;\n justify-content: center;\n width: var(--handle_width);\n cursor: ew-resize;\n }\n :host([resizing]) #divider-handle {\n background-color: var(--tc_primary);\n }\n :host([resizing]) .pane {\n pointer-events: none;\n user-select: none;\n }\n #divider-border {\n width: 1px;\n height: 100%;\n border-left: 1px solid var(--c_border);\n }\n #right {\n flex: 1 1;\n }\n :host([stacked="true"]),\n :host([stacked="true"]) #left,\n :host([stacked="true"]) #right {\n display: block;\n }\n :host([stacked="true"]) #divider-handle {\n display: none;\n } \n `}}window.customElements.define("k-split",Split);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import debounce from"./debounce.js";const handlers=new Set;window.addEventListener("resize",debounce((()=>{const e=window.innerWidth;handlers.forEach((n=>n(e)))})));export const watchWindowSize=e=>(handlers.add(e),window.innerWidth);export const unwatchWindowSize=e=>{handlers.remove(e)};
|
package/package.json
CHANGED
package/src/components/Split.js
CHANGED
|
@@ -3,14 +3,21 @@ import drag from '../utils/drag.js';
|
|
|
3
3
|
import {
|
|
4
4
|
dispatchEvent
|
|
5
5
|
} from '../utils/element.js';
|
|
6
|
+
import {
|
|
7
|
+
watchWindowSize,
|
|
8
|
+
unwatchWindowSize
|
|
9
|
+
} from '../utils/watchWindowSize.js'
|
|
6
10
|
|
|
7
11
|
const dragStartWidth = Symbol(),
|
|
8
12
|
dragStartCallback = Symbol(),
|
|
9
13
|
dragEndCallback = Symbol(),
|
|
10
14
|
dragCallback = Symbol(),
|
|
11
|
-
dragCleanup = Symbol()
|
|
15
|
+
dragCleanup = Symbol(),
|
|
16
|
+
windowResizeHandler = Symbol();
|
|
12
17
|
export default class Split extends Component {
|
|
13
|
-
constructor(
|
|
18
|
+
constructor({
|
|
19
|
+
stackWidth = 0
|
|
20
|
+
} = {}){
|
|
14
21
|
super();
|
|
15
22
|
|
|
16
23
|
/* Private Members */
|
|
@@ -37,24 +44,35 @@ export default class Split extends Component {
|
|
|
37
44
|
dispatchEvent(this, 'resizeend', { size } );
|
|
38
45
|
}
|
|
39
46
|
this[dragCleanup] = () => {}
|
|
47
|
+
this[windowResizeHandler] = (width) => {
|
|
48
|
+
this.stacked = width <= this.stackWidth;
|
|
49
|
+
}
|
|
40
50
|
|
|
41
51
|
/* Init */
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
this.registerAttributes({
|
|
53
|
+
resizing: false,
|
|
54
|
+
stacked: false,
|
|
55
|
+
stackWidth
|
|
52
56
|
});
|
|
53
57
|
}
|
|
58
|
+
|
|
54
59
|
disconnectedCallback(){
|
|
55
60
|
super.disconnectedCallback();
|
|
56
61
|
this[dragCleanup]();
|
|
57
62
|
}
|
|
63
|
+
async render(force){
|
|
64
|
+
if(await super.render(force)){
|
|
65
|
+
this[dragCleanup] = drag({
|
|
66
|
+
element: this.shadowRoot.getElementById('divider-handle'),
|
|
67
|
+
callback: this[dragCallback],
|
|
68
|
+
startCallback: this[dragStartCallback],
|
|
69
|
+
endCallback: this[dragEndCallback]
|
|
70
|
+
});
|
|
71
|
+
this.stacked = watchWindowSize(this[windowResizeHandler]) <= this.stackWidth;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
58
76
|
|
|
59
77
|
setSize(size){
|
|
60
78
|
this.style.setProperty('--left_width', size);
|
|
@@ -126,7 +144,14 @@ export default class Split extends Component {
|
|
|
126
144
|
#right {
|
|
127
145
|
flex: 1 1;
|
|
128
146
|
}
|
|
129
|
-
|
|
147
|
+
:host([stacked="true"]),
|
|
148
|
+
:host([stacked="true"]) #left,
|
|
149
|
+
:host([stacked="true"]) #right {
|
|
150
|
+
display: block;
|
|
151
|
+
}
|
|
152
|
+
:host([stacked="true"]) #divider-handle {
|
|
153
|
+
display: none;
|
|
154
|
+
}
|
|
130
155
|
`;
|
|
131
156
|
}
|
|
132
157
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import debounce from './debounce.js';
|
|
2
|
+
|
|
3
|
+
const handlers = new Set();
|
|
4
|
+
window.addEventListener('resize', debounce(()=>{
|
|
5
|
+
const width = window.innerWidth;
|
|
6
|
+
handlers.forEach( (handler) => handler(width));
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
export const watchWindowSize = (handler) => {
|
|
10
|
+
handlers.add(handler);
|
|
11
|
+
return window.innerWidth;
|
|
12
|
+
}
|
|
13
|
+
export const unwatchWindowSize = (handler) => {
|
|
14
|
+
handlers.remove(handler);
|
|
15
|
+
}
|