@dile/lib 0.0.1 → 0.0.2
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/LICENSE +9 -0
- package/index.js +23 -0
- package/package.json +16 -6
- package/src/components/DileAppFeedback.js +60 -0
- package/src/components/DileAppLoading.js +34 -0
- package/src/components/DileAuthGuard.js +64 -0
- package/src/lib/DileAppNavigate.js +13 -0
- package/src/lib/DileAppRouter.js +39 -0
- package/src/lib/{feedback-mixin.js → DileFeedback.js} +2 -3
- package/src/lib/{state-mixin.js → DileState.js} +2 -4
- package/src/redux/{app-slice.js → feedback-slice.js} +7 -7
- package/.vscode/settings.json +0 -22
- package/src/redux/store.js +0 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 EscuelaIT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/index.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export {
|
|
2
|
+
feedbackSlice,
|
|
3
|
+
negativeFeedback,
|
|
4
|
+
positiveFeedback,
|
|
5
|
+
neutralFeedback,
|
|
6
|
+
startLoading,
|
|
7
|
+
stopLoading
|
|
8
|
+
} from './src/redux/feedback-slice.js';
|
|
9
|
+
export {
|
|
10
|
+
userSlice,
|
|
11
|
+
storeUser,
|
|
12
|
+
removeUser,
|
|
13
|
+
storeToken,
|
|
14
|
+
setInitialized
|
|
15
|
+
} from './src/redux/user-slice.js';
|
|
16
|
+
export { DileFeedback } from './src/lib/DileFeedback.js';
|
|
17
|
+
export { DileState } from './src/lib/DileState.js';
|
|
18
|
+
export { DileAppRouter } from './src/lib/DileAppRouter.js';
|
|
19
|
+
export { DileAppNavigate } from './src/lib/DileAppNavigate.js';
|
|
20
|
+
|
|
21
|
+
export { DileAppFeedback } from './src/components/DileAppFeedback.js';
|
|
22
|
+
export { DileAppLoading } from './src/components/DileAppLoading.js';
|
|
23
|
+
export { DileAuthGuard } from './src/components/DileAuthGuard.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/lib",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "App libraries and helpers",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Common App libraries, mixins and helpers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "test"
|
|
@@ -11,11 +11,21 @@
|
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"lib",
|
|
14
|
-
"app"
|
|
14
|
+
"app",
|
|
15
|
+
"mixins"
|
|
15
16
|
],
|
|
16
|
-
"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/Polydile/dile-components.git"
|
|
20
|
+
},
|
|
21
|
+
"author": "Miguel Angel Alvarez",
|
|
22
|
+
"homepage": "https://dile-components.com/",
|
|
17
23
|
"license": "MIT",
|
|
18
24
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
|
|
25
|
+
"@dile/ui": "^2.5.6",
|
|
26
|
+
"@lit-labs/router": "^0.1.4",
|
|
27
|
+
"@reduxjs/toolkit": "^2.5.1",
|
|
28
|
+
"lit": "^2.7.0 || ^3.0.0"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "0ca8a028f7d8e60a7e1b83ad5a6a90dfc97ddac4"
|
|
21
31
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { DileState } from '../lib/DileState.js';
|
|
3
|
+
import '@dile/ui/components/toast/toast';
|
|
4
|
+
|
|
5
|
+
export const DileAppFeedback = (store) => class extends DileState(store)(LitElement) {
|
|
6
|
+
static styles = [
|
|
7
|
+
css`
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
position: fixed;
|
|
11
|
+
z-index: 999999;
|
|
12
|
+
}
|
|
13
|
+
@media(min-width: 500px) {
|
|
14
|
+
dile-toast {
|
|
15
|
+
--dile-toast-width: var(--dile-app-feedback-big-toast-width, 450px);
|
|
16
|
+
--dile-toast-padding: var(--dile-app-feedback-big-toast-padding, 15px 20px);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
static get properties() {
|
|
23
|
+
return {
|
|
24
|
+
time: { type: Number },
|
|
25
|
+
incomingMsg: { type: Object },
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.time = 5000;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
firstUpdated() {
|
|
35
|
+
this.toast = this.shadowRoot.getElementById('toast');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stateChanged(state) {
|
|
39
|
+
console.log('state', state)
|
|
40
|
+
this.incomingMsg = state.feedback.message;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
updated(changedProperties) {
|
|
44
|
+
if (changedProperties.has('incomingMsg')) {
|
|
45
|
+
this.changeIncomingMsg(this.incomingMsg);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
changeIncomingMsg(feedbackMsg) {
|
|
50
|
+
if (feedbackMsg && feedbackMsg.msg && feedbackMsg.status) {
|
|
51
|
+
this.toast.open(feedbackMsg.msg, feedbackMsg.status);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
render() {
|
|
56
|
+
return html`
|
|
57
|
+
<dile-toast id="toast" duration=${this.time}></dile-toast>
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { DileState } from '../lib/DileState.js';
|
|
3
|
+
import '@dile/ui/components/spinner/spinner-modal';
|
|
4
|
+
|
|
5
|
+
export const DileAppLoading = (store) => class extends DileState(store)(LitElement) {
|
|
6
|
+
static get styles() {
|
|
7
|
+
return css`
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get properties() {
|
|
15
|
+
return {
|
|
16
|
+
loading: { type: Boolean }
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.loading = false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
return html`
|
|
27
|
+
<dile-spinner-modal ?active=${this.loading}></dile-spinner-modal>
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
stateChanged(state) {
|
|
32
|
+
this.loading = state.feedback.loading;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { DileAppNavigate } from '../lib/DileAppNavigate';
|
|
3
|
+
import { DileState } from '../lib/DileState.js';
|
|
4
|
+
import '@dile/ui/components/spinner/spinner-block.js';
|
|
5
|
+
|
|
6
|
+
export const DileAuthGuard = (store) => class extends DileAppNavigate(DileState(store)(LitElement)) {
|
|
7
|
+
static styles = [
|
|
8
|
+
css`
|
|
9
|
+
:host {
|
|
10
|
+
display: block;
|
|
11
|
+
}
|
|
12
|
+
`
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
static get properties() {
|
|
16
|
+
return {
|
|
17
|
+
loaded: { type: Boolean },
|
|
18
|
+
pageTitle: { type: String },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.pageTitle = '';
|
|
25
|
+
console.log('soy auth guard');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
createRenderRoot() {
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
return html`
|
|
34
|
+
eeste es el auth guard
|
|
35
|
+
${this.loaded
|
|
36
|
+
? html`<slot></slot>`
|
|
37
|
+
: this.loadingTemplate
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
firstUpdated() {
|
|
44
|
+
const currentState = this.getState();
|
|
45
|
+
this.stateChanged(currentState);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
stateChanged(state) {
|
|
49
|
+
if(!state) return;
|
|
50
|
+
if (state.user.isInitialized) {
|
|
51
|
+
if(state.user.isLoggedIn && state.user.userData.is_admin === true) {
|
|
52
|
+
this.loaded = true;
|
|
53
|
+
} else {
|
|
54
|
+
this.goToUrl('/', this.pageTitle);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get loadingTemplate() {
|
|
60
|
+
return html`
|
|
61
|
+
<dile-spinner-block></dile-spinner-block>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const DileAppNavigate = (superclass) => class extends superclass {
|
|
2
|
+
goToUrl(url, title = '') {
|
|
3
|
+
console.log('app navigate', url, title)
|
|
4
|
+
document.dispatchEvent(new CustomEvent('dile-lib-navigate', {
|
|
5
|
+
bubbles: true,
|
|
6
|
+
composed: true,
|
|
7
|
+
detail: {
|
|
8
|
+
url,
|
|
9
|
+
title,
|
|
10
|
+
}
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Routes, Router } from '@lit-labs/router';
|
|
2
|
+
|
|
3
|
+
export const DileAppRouter = (superclass) => class extends superclass {
|
|
4
|
+
|
|
5
|
+
static get properties() {
|
|
6
|
+
return {
|
|
7
|
+
_routes: { type: Object },
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.navigateHandler = this.programaticNavigation.bind(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
programaticNavigation(e) {
|
|
17
|
+
history.pushState(
|
|
18
|
+
null,
|
|
19
|
+
e.detail.url || 'App',
|
|
20
|
+
e.detail.url);
|
|
21
|
+
setTimeout(() => this._routes.goto(e.detail.url), 100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
super.connectedCallback();
|
|
26
|
+
document.addEventListener('dile-lib-navigate', this.navigateHandler);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
disconnectedCallback() {
|
|
30
|
+
super.disconnectedCallback();
|
|
31
|
+
document.removeEventListener('dile-lib-navigate', this.navigateHandler);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
createRoutes(routes) {
|
|
35
|
+
new Router(this, []);
|
|
36
|
+
|
|
37
|
+
this._routes = new Routes(this, routes);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { positiveFeedback, negativeFeedback, neutralFeedback, startLoading, stopLoading } from '../redux/app-slice';
|
|
1
|
+
import { positiveFeedback, negativeFeedback, neutralFeedback, startLoading, stopLoading } from '../redux/feedback-slice';
|
|
3
2
|
|
|
4
|
-
export const
|
|
3
|
+
export const DileFeedback = (store) => (Superclass) => class extends Superclass {
|
|
5
4
|
positiveFeedback(msg) {
|
|
6
5
|
store.dispatch(positiveFeedback(msg));
|
|
7
6
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const StateMixin = (superclass) => class extends superclass {
|
|
1
|
+
export const DileState = (store) => (superclass) => class extends superclass {
|
|
4
2
|
|
|
5
3
|
connectedCallback() {
|
|
6
4
|
super.connectedCallback();
|
|
@@ -17,7 +15,7 @@ export const StateMixin = (superclass) => class extends superclass {
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
stateChanged(state) {
|
|
20
|
-
//
|
|
18
|
+
// Override this method to get the state needed by the component
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
getState() {
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
name: '
|
|
3
|
+
export const feedbackSlice = createSlice({
|
|
4
|
+
name: 'feedback',
|
|
5
5
|
initialState: {
|
|
6
|
-
|
|
6
|
+
message: null,
|
|
7
7
|
loading: false,
|
|
8
8
|
},
|
|
9
9
|
reducers: {
|
|
10
10
|
positiveFeedback(state, action) {
|
|
11
|
-
state.
|
|
11
|
+
state.message = {
|
|
12
12
|
status: 'success',
|
|
13
13
|
msg: action.payload,
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
negativeFeedback(state, action) {
|
|
17
|
-
state.
|
|
17
|
+
state.message = {
|
|
18
18
|
status: 'error',
|
|
19
19
|
msg: action.payload,
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
neutralFeedback(state, action) {
|
|
23
|
-
state.
|
|
23
|
+
state.message = {
|
|
24
24
|
status: 'neutral',
|
|
25
25
|
msg: action.payload,
|
|
26
26
|
}
|
|
@@ -40,4 +40,4 @@ export const {
|
|
|
40
40
|
neutralFeedback,
|
|
41
41
|
startLoading,
|
|
42
42
|
stopLoading,
|
|
43
|
-
} =
|
|
43
|
+
} = feedbackSlice.actions;
|
package/.vscode/settings.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"workbench.colorCustomizations": {
|
|
3
|
-
"activityBar.activeBackground": "#fbed80",
|
|
4
|
-
"activityBar.background": "#fbed80",
|
|
5
|
-
"activityBar.foreground": "#15202b",
|
|
6
|
-
"activityBar.inactiveForeground": "#15202b99",
|
|
7
|
-
"activityBarBadge.background": "#06b9a5",
|
|
8
|
-
"activityBarBadge.foreground": "#15202b",
|
|
9
|
-
"commandCenter.border": "#15202b99",
|
|
10
|
-
"sash.hoverBorder": "#fbed80",
|
|
11
|
-
"statusBar.background": "#f9e64f",
|
|
12
|
-
"statusBar.foreground": "#15202b",
|
|
13
|
-
"statusBarItem.hoverBackground": "#f7df1e",
|
|
14
|
-
"statusBarItem.remoteBackground": "#f9e64f",
|
|
15
|
-
"statusBarItem.remoteForeground": "#15202b",
|
|
16
|
-
"titleBar.activeBackground": "#f9e64f",
|
|
17
|
-
"titleBar.activeForeground": "#15202b",
|
|
18
|
-
"titleBar.inactiveBackground": "#f9e64f99",
|
|
19
|
-
"titleBar.inactiveForeground": "#15202b99"
|
|
20
|
-
},
|
|
21
|
-
"peacock.color": "#f9e64f"
|
|
22
|
-
}
|
package/src/redux/store.js
DELETED