kempo 2.0.0 → 2.0.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/Dialog.js +1 -1
- package/docs/components/show-more.html +1 -14
- package/docs/kempo/components/Dialog.js +1 -1
- package/docs/search.json +0 -24
- package/package.json +1 -1
- package/src/components/Dialog.js +3 -1
- package/docs/components/codeeditor.html +0 -25
- package/docs/components/websnippeteditor.html +0 -38
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import"./FocusCapture.js";import"./Icon.js";import{firstFocusable,onEvent,offEvent,dispatchEvent}from"../utils/element.js";export default class Dialog extends Component{constructor({opened:e=!1,closeBtn:n=!0,overlayClose:t=!0,confirmText:o="",confirmClasses:i="success ml",confirmAction:s=(()=>{}),cancelText:
|
|
1
|
+
import Component from"./Component.js";import"./FocusCapture.js";import"./Icon.js";import{firstFocusable,onEvent,offEvent,dispatchEvent}from"../utils/element.js";export default class Dialog extends Component{constructor({opened:e=!1,closeBtn:n=!0,overlayClose:t=!0,confirmText:o="",confirmClasses:i="success ml",confirmAction:s=(()=>{}),cancelText:l="",cancelClasses:c="",cancelAction:a=(()=>{}),closeCallback:r=(()=>{})}={}){super(),this.registerAttributes({opened:e,closeBtn:n,overlayClose:t,confirmText:o,confirmClasses:i,cancelText:l,cancelClasses:c}),this.registerProps({confirmAction:s,cancelAction:a,closeCallback:r,previousFocus:null,_clickHandler:e=>{const{target:{id:n}}=e;"overlay"==n&&this.overlayClose||"close"==n?this.close():"cancel"==n?(this.cancelAction(e),e.defaultPrevented||this.close()):"confirm"==n&&(this.confirmAction(e),e.defaultPrevented||this.close())},_keydownHandler:({keyCode:e})=>{27===e&&this.close()},_hasTitle:()=>!!this.querySelector('[slot="title"]')})}connectedCallback(){super.connectedCallback(),onEvent(this.shadowRoot,"click",this._clickHandler)}disconnectedCallback(){super.connectedCallback(),offEvent(this.shadowRoot,"click",this._clickHandler),offEvent(window,"keydown",this._keydownHandler)}attributeChangedCallback(e,n,t){super.attributeChangedCallback(e,n,t),"opened"===name&&dispatchEvent(this,t?"opened":"close")}open(){this.opened=!0;const e=this.shadowRoot.querySelector("[autofocus]")||firstFocusable(this.shadowRoot);e&&e.focus(),onEvent(window,"keydown",this._keydownHandler)}close(){this.opened=!1,this.blur(),this.closeCallback(),offEvent(window,"keydown",this._keydownHandler)}toggle(){this.opened?this.close():this.open()}focus(){const e=firstFocusable(this.shadowRoot);e&&(this.previousFocus=document.activeElement,e.focus())}blur(){this.previousFocus&&this.previousFocus.focus()}get shadowTemplate(){return`\n <k-focus-capture>\n <button id="overlay" aria-label="Close the Dialog"></button>\n <div id="wrapper">\n <div\n id="dialog"\n role="dialog"\n aria-modal="true"\n aria-labelledby="title"\n >\n <div\n id="header"\n class="${this._hasTitle()?"has-title":""}"\n >\n <div\n id="title"\n ><slot name="title"></slot></div>\n ${this.renderIf(this.closeBtn,'\n <button\n id="close"\n >\n <k-icon name="close"></k-icon>\n </button>\n ')}\n </div>\n <div id="body">\n ${super.shadowTemplate}\n </div>\n ${this.renderIf(this.cancelText||this.confirmText,`\n <div id="footer">\n ${this.renderIf(this.cancelText,`\n <button id="cancel" class="${this.cancelClasses}">\n ${this.cancelText}\n </button>\n `)}\n ${this.renderIf(this.confirmText,`\n <button id="confirm" class="${this.confirmClasses}">\n ${this.confirmText}\n </button>\n `)}\n </div>\n `)}\n </div>\n </div>\n </k-focus-capture>\n `}get shadowStyles(){return`\n ${super.shadowStyles}\n :host {\n display: inline;\n height: 1px;\n width: 1px;\n position: fixed; /* The browser seems to sometimes lazy load this if its out of view, this seems to fix it*/\n top: 0;\n left: 0;\n z-index: 100;\n }\n :host(:not([opened])){\n display: none;\n }\n #overlay {\n position: fixed;\n width: 100vw;\n height: 100vh;\n top: 0;\n left: 0;\n background-color: var(--c_overlay);\n z-index: 100;\n border: 0px solid transparent;\n box-shadow: 0 0 0 transparent;\n }\n #wrapper {\n display: flex;\n justify-content: center;\n align-items: center;\n position: fixed;\n width: 100vw;\n height: 100vh;\n top: 0;\n left: 0;\n z-index: 101;\n pointer-events: none;\n }\n #dialog {\n display: flex;\n flex-direction: column;\n min-width: var(--min_width, 20rem);\n width: var(--width, fit-content);\n max-width: var(--max_width, calc(100vw - 2rem));\n min-height: var(--min_height, 12rem);\n height: var(--height, fit-content);\n max-height: var(--max_height, calc(100vh - 2rem));\n background-color: var(--c_bg);\n box-shadow: var(--drop_shadow);\n border-radius: var(--radius);\n pointer-events: all;\n }\n #header {\n display: flex;\n align-items: center;\n }\n #header.has-title {\n border-bottom: 1px solid var(--c_border);\n }\n #title {\n flex: 1 1 auto;\n }\n #close {\n border: 0px;\n background: transparent;\n box-shadow: 0 0 0 transparent;\n color: var(--tc);\n }\n #close k-icon {\n pointer-events: none;\n }\n #body {\n flex: 1 1 auto;\n }\n #footer {\n display: flex;\n justify-content: flex-end;\n padding: var(--spacer_h);\n }\n `}static renderOnChange=["opened","closeBtn","overlayClose","title","confirmText","cancelText"];static create(e="",n={}){!1!==n.closeExisting&&document.querySelectorAll("k-dialog").forEach((e=>e.close()));const t=new Dialog({opened:!0,...n});onEvent(t,"close",t.remove),e instanceof HTMLElement||e instanceof DocumentFragment?t.appendChild(e):e instanceof NodeList?e.forEach((e=>t.appendChild(e))):t.innerHTML=e,document.body.prepend(t),t.open()}static confirm(e,n,t={title:"Confirm"}){Dialog.create(`\n <h5 slot="title" class="pyh px m0">${t.title}</h5>\n <p class="p">${e}</p>\n `,{...t,closeBtn:!1,overlayClose:!1,confirmText:"Yes",confirmClasses:"success ml",confirmAction:()=>n(!0),cancelText:"No",cancelClasses:"danger",cancelAction:()=>n(!1)})}static error(e,n,t={title:"Error"}){Dialog.create(`\n <h5 slot="title" class="pyh px m0 tc-danger">${t.title}</h5>\n <p class="p">${e}</p>\n `,{...t,cancelText:"Ok"})}}window.customElements.define("k-dialog",Dialog);
|
|
@@ -64,20 +64,7 @@
|
|
|
64
64
|
</k-card>
|
|
65
65
|
</div>
|
|
66
66
|
</div>
|
|
67
|
-
|
|
68
|
-
<h3>Try It Yourself</h3>
|
|
69
|
-
<k-web-snippet-editor
|
|
70
|
-
show-css="false"
|
|
71
|
-
show-js="false"
|
|
72
|
-
use-kempo="true"
|
|
73
|
-
scripts="../kempo/components/ShowMore.js"
|
|
74
|
-
>
|
|
75
|
-
<pre for="html"><k-show-more style="--closed_height: 10rem">
|
|
76
|
-
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatibus eum pariatur voluptas aspernatur ad laborum nostrum deserunt quo consequuntur, molestias id quos rem cum, distinctio quam obcaecati recusandae ut quod non vel ipsam architecto fuga. Tempore placeat quidem aperiam consectetur optio beatae assumenda dolor corrupti saepe eum, natus doloremque reprehenderit sequi laboriosam suscipit eos esse dolore facilis alias. Pariatur beatae ex suscipit nulla voluptate nobis quisquam alias. Nesciunt unde asperiores iste, praesentium quod cumque. Quos numquam sunt quisquam enim explicabo nobis fugiat, distinctio illum et corporis necessitatibus, ab ullam nesciunt tempora quas totam odio autem. Similique maiores facilis saepe exercitationem dolores, quisquam consequuntur atque in molestiae sint voluptatem. Eveniet vel recusandae sit. Doloribus eum magni cumque animi tempore error dicta dignissimos repellat porro, recusandae iusto quas? Soluta explicabo vitae cupiditate repellat magnam blanditiis, quam animi nihil, totam similique est eum, magni impedit deleniti! Laboriosam explicabo libero laudantium reiciendis autem officia obcaecati eius incidunt earum quibusdam, cumque quasi aspernatur quod at, placeat dolorum, vel illum commodi odit non. Iure adipisci, unde assumenda laboriosam quaerat beatae optio, aliquid tenetur ex nemo velit earum tempore nulla, animi neque nam ipsam quia accusantium enim et quis reprehenderit quas? Labore modi maiores in suscipit laboriosam.</p>
|
|
77
|
-
<span slot="more">Show me all the text</span>
|
|
78
|
-
<span slot="less">Whoa, that's too much text, hide some</span>
|
|
79
|
-
</k-show-more></pre>
|
|
80
|
-
</k-web-snippet-editor>
|
|
67
|
+
|
|
81
68
|
</main>
|
|
82
69
|
<div style="height:33vh"></div>
|
|
83
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Component from"./Component.js";import"./FocusCapture.js";import"./Icon.js";import{firstFocusable,onEvent,offEvent,dispatchEvent}from"../utils/element.js";export default class Dialog extends Component{constructor({opened:e=!1,closeBtn:n=!0,overlayClose:t=!0,confirmText:o="",confirmClasses:i="success ml",confirmAction:s=(()=>{}),cancelText:
|
|
1
|
+
import Component from"./Component.js";import"./FocusCapture.js";import"./Icon.js";import{firstFocusable,onEvent,offEvent,dispatchEvent}from"../utils/element.js";export default class Dialog extends Component{constructor({opened:e=!1,closeBtn:n=!0,overlayClose:t=!0,confirmText:o="",confirmClasses:i="success ml",confirmAction:s=(()=>{}),cancelText:l="",cancelClasses:c="",cancelAction:a=(()=>{}),closeCallback:r=(()=>{})}={}){super(),this.registerAttributes({opened:e,closeBtn:n,overlayClose:t,confirmText:o,confirmClasses:i,cancelText:l,cancelClasses:c}),this.registerProps({confirmAction:s,cancelAction:a,closeCallback:r,previousFocus:null,_clickHandler:e=>{const{target:{id:n}}=e;"overlay"==n&&this.overlayClose||"close"==n?this.close():"cancel"==n?(this.cancelAction(e),e.defaultPrevented||this.close()):"confirm"==n&&(this.confirmAction(e),e.defaultPrevented||this.close())},_keydownHandler:({keyCode:e})=>{27===e&&this.close()},_hasTitle:()=>!!this.querySelector('[slot="title"]')})}connectedCallback(){super.connectedCallback(),onEvent(this.shadowRoot,"click",this._clickHandler)}disconnectedCallback(){super.connectedCallback(),offEvent(this.shadowRoot,"click",this._clickHandler),offEvent(window,"keydown",this._keydownHandler)}attributeChangedCallback(e,n,t){super.attributeChangedCallback(e,n,t),"opened"===name&&dispatchEvent(this,t?"opened":"close")}open(){this.opened=!0;const e=this.shadowRoot.querySelector("[autofocus]")||firstFocusable(this.shadowRoot);e&&e.focus(),onEvent(window,"keydown",this._keydownHandler)}close(){this.opened=!1,this.blur(),this.closeCallback(),offEvent(window,"keydown",this._keydownHandler)}toggle(){this.opened?this.close():this.open()}focus(){const e=firstFocusable(this.shadowRoot);e&&(this.previousFocus=document.activeElement,e.focus())}blur(){this.previousFocus&&this.previousFocus.focus()}get shadowTemplate(){return`\n <k-focus-capture>\n <button id="overlay" aria-label="Close the Dialog"></button>\n <div id="wrapper">\n <div\n id="dialog"\n role="dialog"\n aria-modal="true"\n aria-labelledby="title"\n >\n <div\n id="header"\n class="${this._hasTitle()?"has-title":""}"\n >\n <div\n id="title"\n ><slot name="title"></slot></div>\n ${this.renderIf(this.closeBtn,'\n <button\n id="close"\n >\n <k-icon name="close"></k-icon>\n </button>\n ')}\n </div>\n <div id="body">\n ${super.shadowTemplate}\n </div>\n ${this.renderIf(this.cancelText||this.confirmText,`\n <div id="footer">\n ${this.renderIf(this.cancelText,`\n <button id="cancel" class="${this.cancelClasses}">\n ${this.cancelText}\n </button>\n `)}\n ${this.renderIf(this.confirmText,`\n <button id="confirm" class="${this.confirmClasses}">\n ${this.confirmText}\n </button>\n `)}\n </div>\n `)}\n </div>\n </div>\n </k-focus-capture>\n `}get shadowStyles(){return`\n ${super.shadowStyles}\n :host {\n display: inline;\n height: 1px;\n width: 1px;\n position: fixed; /* The browser seems to sometimes lazy load this if its out of view, this seems to fix it*/\n top: 0;\n left: 0;\n z-index: 100;\n }\n :host(:not([opened])){\n display: none;\n }\n #overlay {\n position: fixed;\n width: 100vw;\n height: 100vh;\n top: 0;\n left: 0;\n background-color: var(--c_overlay);\n z-index: 100;\n border: 0px solid transparent;\n box-shadow: 0 0 0 transparent;\n }\n #wrapper {\n display: flex;\n justify-content: center;\n align-items: center;\n position: fixed;\n width: 100vw;\n height: 100vh;\n top: 0;\n left: 0;\n z-index: 101;\n pointer-events: none;\n }\n #dialog {\n display: flex;\n flex-direction: column;\n min-width: var(--min_width, 20rem);\n width: var(--width, fit-content);\n max-width: var(--max_width, calc(100vw - 2rem));\n min-height: var(--min_height, 12rem);\n height: var(--height, fit-content);\n max-height: var(--max_height, calc(100vh - 2rem));\n background-color: var(--c_bg);\n box-shadow: var(--drop_shadow);\n border-radius: var(--radius);\n pointer-events: all;\n }\n #header {\n display: flex;\n align-items: center;\n }\n #header.has-title {\n border-bottom: 1px solid var(--c_border);\n }\n #title {\n flex: 1 1 auto;\n }\n #close {\n border: 0px;\n background: transparent;\n box-shadow: 0 0 0 transparent;\n color: var(--tc);\n }\n #close k-icon {\n pointer-events: none;\n }\n #body {\n flex: 1 1 auto;\n }\n #footer {\n display: flex;\n justify-content: flex-end;\n padding: var(--spacer_h);\n }\n `}static renderOnChange=["opened","closeBtn","overlayClose","title","confirmText","cancelText"];static create(e="",n={}){!1!==n.closeExisting&&document.querySelectorAll("k-dialog").forEach((e=>e.close()));const t=new Dialog({opened:!0,...n});onEvent(t,"close",t.remove),e instanceof HTMLElement||e instanceof DocumentFragment?t.appendChild(e):e instanceof NodeList?e.forEach((e=>t.appendChild(e))):t.innerHTML=e,document.body.prepend(t),t.open()}static confirm(e,n,t={title:"Confirm"}){Dialog.create(`\n <h5 slot="title" class="pyh px m0">${t.title}</h5>\n <p class="p">${e}</p>\n `,{...t,closeBtn:!1,overlayClose:!1,confirmText:"Yes",confirmClasses:"success ml",confirmAction:()=>n(!0),cancelText:"No",cancelClasses:"danger",cancelAction:()=>n(!1)})}static error(e,n,t={title:"Error"}){Dialog.create(`\n <h5 slot="title" class="pyh px m0 tc-danger">${t.title}</h5>\n <p class="p">${e}</p>\n `,{...t,cancelText:"Ok"})}}window.customElements.define("k-dialog",Dialog);
|
package/docs/search.json
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"/components/codeeditor.html": {
|
|
3
|
-
"name": "Components > Code Editor",
|
|
4
|
-
"terms": [
|
|
5
|
-
"component",
|
|
6
|
-
"code",
|
|
7
|
-
"editor",
|
|
8
|
-
"html",
|
|
9
|
-
"css",
|
|
10
|
-
"js"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
2
|
"/components/resize.html": {
|
|
14
3
|
"name": "Components > Resize",
|
|
15
4
|
"terms": [
|
|
@@ -48,19 +37,6 @@
|
|
|
48
37
|
"content"
|
|
49
38
|
]
|
|
50
39
|
},
|
|
51
|
-
"/components/websnippeteditor.html": {
|
|
52
|
-
"name": "Components > Web Snippet Editor",
|
|
53
|
-
"terms": [
|
|
54
|
-
"component",
|
|
55
|
-
"web",
|
|
56
|
-
"snippet",
|
|
57
|
-
"editor",
|
|
58
|
-
"code",
|
|
59
|
-
"html",
|
|
60
|
-
"css",
|
|
61
|
-
"js"
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
40
|
"/styles/borders-spacing.html": {
|
|
65
41
|
"name": "Styles > Borders and Spacing",
|
|
66
42
|
"terms": [
|
package/package.json
CHANGED
package/src/components/Dialog.js
CHANGED
|
@@ -72,7 +72,7 @@ export default class Dialog extends Component {
|
|
|
72
72
|
attributeChangedCallback(n, oV, nV){
|
|
73
73
|
super.attributeChangedCallback(n, oV, nV);
|
|
74
74
|
if(name === 'opened'){
|
|
75
|
-
dispatchEvent(this, nV?'opened':'
|
|
75
|
+
dispatchEvent(this, nV?'opened':'close');
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
open(){
|
|
@@ -161,6 +161,7 @@ export default class Dialog extends Component {
|
|
|
161
161
|
position: fixed; /* The browser seems to sometimes lazy load this if its out of view, this seems to fix it*/
|
|
162
162
|
top: 0;
|
|
163
163
|
left: 0;
|
|
164
|
+
z-index: 100;
|
|
164
165
|
}
|
|
165
166
|
:host(:not([opened])){
|
|
166
167
|
display: none;
|
|
@@ -242,6 +243,7 @@ export default class Dialog extends Component {
|
|
|
242
243
|
];
|
|
243
244
|
|
|
244
245
|
static create(contents = '', options = {}){
|
|
246
|
+
if(options.closeExisting!==false)document.querySelectorAll('k-dialog').forEach(d=>d.close());
|
|
245
247
|
const $dialog = new Dialog({
|
|
246
248
|
opened: true,
|
|
247
249
|
...options
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Code Editor - Components - Kempo Docs - A Web Components Solution</title>
|
|
7
|
-
<link rel="stylesheet" href="../kempo/kempo-vars.css" /><link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
8
|
-
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<k-import src="../nav-1.inc.html"></k-import>
|
|
12
|
-
<h1 class="ta-center">Code Editor</h1>
|
|
13
|
-
<main>
|
|
14
|
-
<p>Use the <code><k-code-editor></code> to create a code text editor. Put your initial code within the the tag, for HTML you should escape the open tags (<code><</code> should be <code>&lt;</code>) so the code is not treated as real HTML.</p>
|
|
15
|
-
<p>This is a very simple code editor, it is not intended to be full featured, just the basics, it's like a textarea with line numbers and highlighting. If you want a full featured editor please use <a href="https://ace.c9.io/" target="_blank">Ace Editor</a>, <a href="https://codemirror.net/" target="_blank">Code Mirror</a>, or <a href="https://microsoft.github.io/monaco-editor/" target="_blank">Monaco</a></p>
|
|
16
|
-
<k-code-editor>
|
|
17
|
-
<k-code-editor>
|
|
18
|
-
<!-- Init Code Here !-->
|
|
19
|
-
</k-code-editor>
|
|
20
|
-
</k-code-editor>
|
|
21
|
-
</main>
|
|
22
|
-
<script type="module" src="../kempo/components/Import.js"></script>
|
|
23
|
-
<script type="module" src="../kempo/components/CodeEditor.js"></script>
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Web Snippet Editor - Components - Kempo Docs - A Web Components Solution</title>
|
|
7
|
-
<link rel="stylesheet" href="../kempo/kempo-vars.css" /><link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
8
|
-
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<k-import src="../nav-1.inc.html"></k-import>
|
|
12
|
-
<h1 class="ta-center">Web Snippet Editor</h1>
|
|
13
|
-
<main>
|
|
14
|
-
<k-web-snippet-editor
|
|
15
|
-
use-kempo="false"
|
|
16
|
-
>
|
|
17
|
-
<pre for="html">
|
|
18
|
-
<button id="hello">
|
|
19
|
-
Click Me
|
|
20
|
-
</button>
|
|
21
|
-
</pre>
|
|
22
|
-
<pre for="css">
|
|
23
|
-
#hello {
|
|
24
|
-
color: blue;
|
|
25
|
-
}
|
|
26
|
-
</pre>
|
|
27
|
-
<pre for="js">
|
|
28
|
-
document.getElementById('hello').addEventListener('click', () => {
|
|
29
|
-
alert('Hello World');
|
|
30
|
-
});
|
|
31
|
-
</pre>
|
|
32
|
-
</k-web-snippet-editor>
|
|
33
|
-
</main>
|
|
34
|
-
<div style="height:33vh"></div>
|
|
35
|
-
<script type="module" src="../kempo/components/Import.js"></script>
|
|
36
|
-
<script type="module" src="../kempo/components/WebSnippetEditor.js"></script>
|
|
37
|
-
</body>
|
|
38
|
-
</html>
|