@massimo-cassandro/minimo 0.1.12 → 0.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/package.json +8 -4
- package/src/{js → components}/dialog-content.js +1 -1
- package/src/{css → components/inner-nav}/inner-nav.css +2 -2
- package/src/{js → components/inner-nav}/inner-nav.js +8 -0
- package/src/components/modal-content/modal-content.js +1 -1
- package/src/components/modal-content/modal-content.module.css +4 -4
- package/src/components/recaptcha/recaptcha.css +4 -5
- package/src/components/recaptcha/recaptcha.minimo.tokens.jsonc +24 -0
- package/src/{css/spinners → components/spinner}/TODO spinner-circle.css +1 -1
- package/src/components/spinner/readme.md +1 -0
- package/src/{css/spinners → components/spinner}/spinner-circle-basic.css +3 -2
- package/src/{css/spinners → components/spinner}/spinner-wrapper.css +1 -1
- package/src/components/spinner/spinner.minimo.tokens.jsonc +22 -0
- package/src/components/toast/toast.js +77 -0
- package/src/components/toast/toast.minimo.tokens.jsonc +29 -0
- package/src/components/toast/toast.module.css +59 -0
- package/src/css/alerts.css +23 -23
- package/src/css/anchors.css +17 -16
- package/src/css/buttons/btn-close.css +8 -7
- package/src/css/buttons/buttons.css +101 -94
- package/src/css/buttons/status-buttons.css +43 -43
- package/src/css/container.css +3 -12
- package/src/css/details.css +1 -1
- package/src/css/dialog-content.css +2 -2
- package/src/css/flex.css +9 -0
- package/src/css/forms/fieldset.css +75 -0
- package/src/css/forms/form-group.css +18 -0
- package/src/css/forms/form-utilities.css +32 -0
- package/src/css/forms/forms.css +37 -202
- package/src/css/forms/input-group.css +49 -0
- package/src/css/forms/validation.css +25 -0
- package/src/css/grid.css +25 -18
- package/src/css/headings.css +10 -9
- package/src/css/icons.css +1 -40
- package/src/css/layout-base.css +3 -3
- package/src/css/overlay.css +1 -2
- package/src/css/table.css +26 -19
- package/src/css/text.css +8 -7
- package/src/css/utilities.css +90 -29
- package/src/custom-media-default.css +20 -8
- package/src/custom-properties-default.css +212 -317
- package/src/design-tokens/TODO.md +2 -0
- package/src/design-tokens/alerts.minimo.tokens.jsonc +23 -0
- package/src/design-tokens/basic.minimo.tokens.jsonc +52 -0
- package/src/design-tokens/btn-close.minimo.tokens.jsonc +95 -0
- package/src/design-tokens/btn-primary.minimo.tokens.jsonc +100 -0
- package/src/design-tokens/btn-secondary.minimo.tokens.jsonc +33 -0
- package/src/design-tokens/btn.minimo.tokens.jsonc +200 -0
- package/src/design-tokens/color-accent.minimo.tokens.jsonc +13 -0
- package/src/design-tokens/color-neutral.minimo.tokens.jsonc +12 -0
- package/src/design-tokens/color-primary.minimo.tokens.jsonc +12 -0
- package/src/design-tokens/color-secondary.minimo.tokens.jsonc +12 -0
- package/src/design-tokens/flex-grid.minimo.tokens.jsonc +18 -0
- package/src/design-tokens/form.minimo.tokens.jsonc +295 -0
- package/src/design-tokens/gradients-shadowes.minimo.tokens.jsonc +4 -0
- package/src/design-tokens/headings.minimo.tokens.jsonc +57 -0
- package/src/design-tokens/link.minimo.tokens.jsonc +41 -0
- package/src/design-tokens/radius.minimo.tokens.jsonc +45 -0
- package/src/design-tokens/size.minimo.tokens.jsonc +101 -0
- package/src/design-tokens/status.minimo.tokens.jsonc +69 -0
- package/src/design-tokens/table.minimo.tokens.jsonc +66 -0
- package/src/design-tokens/typography.minimo.tokens.jsonc +120 -0
- package/src/design-tokens/utility.minimo.tokens.jsonc +8 -0
- package/src/design-tokens/z-index.minimo.tokens.jsonc +8 -0
- package/src/design-tokens-utilities/build-tokens.mjs +501 -0
- package/src/design-tokens-utilities/check-unresolved-custom-props.mjs +131 -0
- package/src/design-tokens-utilities/config-templates/tokens-config.mjs +34 -0
- package/src/design-tokens-utilities/readme.md +16 -0
- package/src/fonts-template.css +7 -0
- package/src/index-template.css +5 -10
- package/src/index.js +1 -0
- package/src/utilities/classnames.js +3 -0
- package/src/web-components/simple-datatable/icons/arrow-down.svg +1 -0
- package/src/web-components/simple-datatable/icons/arrow-up.svg +2 -0
- package/src/web-components/simple-datatable/icons/arrows-down-up.svg +1 -0
- package/src/web-components/simple-datatable/icons/caret-left.svg +1 -0
- package/src/web-components/simple-datatable/icons/caret-right.svg +1 -0
- package/src/web-components/simple-datatable/icons/check-bold.svg +1 -0
- package/src/web-components/simple-datatable/icons/x-bold.svg +1 -0
- package/src/web-components/simple-datatable/simple-datatable.js +219 -0
- package/src/web-components/simple-datatable/simple-datatable.minimo.tokens.jsonc +50 -0
- package/src/web-components/simple-datatable/simple-datatable.module.css +214 -0
- package/src/web-components/simple-datatable/src/parse-cols.js +117 -0
- package/src/components/init.js +0 -7
- package/src/css/forms/form-edit-info.css +0 -17
- /package/src/{js → components}/alert-autoclose.js +0 -0
- /package/src/{js → components}/create-blurhash-canvas.js +0 -0
- /package/src/{js → components}/dismiss-alerts.js +0 -0
- /package/src/{js → components}/forms.js +0 -0
- /package/src/{js → components}/img-viewer-dom-builder.js +0 -0
- /package/src/{js → components}/overlay.js +0 -0
- /package/src/{js → components}/print-icon.js +0 -0
- /package/src/{css/spinners → components/spinner}/TODO spinner-three-dots.css +0 -0
- /package/src/{css/spinners → components/spinner}/spinner-trailing-dots.css +0 -0
- /package/src/{js → components/spinner}/spinner.js +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
|
|
5
|
+
// rivela eventuale custom props css nei file della dir data non presenti nel file css di definizione
|
|
6
|
+
// uso: node check-unresolved-custom-props.mjs --config ./path/to-config.mjs
|
|
7
|
+
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
11
|
+
import { dirname } from 'path';
|
|
12
|
+
import { glob } from 'node:fs/promises';
|
|
13
|
+
import { styleText, parseArgs } from 'node:util';
|
|
14
|
+
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
|
|
18
|
+
// 1. Configurazione e parsing dei flag
|
|
19
|
+
const options = {
|
|
20
|
+
config: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
short: 'c',
|
|
23
|
+
},
|
|
24
|
+
// Qui in futuro potrai aggiungere altri flag, es:
|
|
25
|
+
// verbose: { type: 'boolean', short: 'v' }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const { values } = parseArgs({ options });
|
|
29
|
+
|
|
30
|
+
if (!values.config) {
|
|
31
|
+
console.error(styleText(['red'], 'Errore: Devi fornire il percorso del config con il flag --config o -c'));
|
|
32
|
+
console.log('Esempio: node check-unresolved-custom-props.mjs --config ./config.mjs');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const absoluteConfigPath = path.resolve(process.cwd(), values.config);
|
|
37
|
+
const configDir = path.dirname(absoluteConfigPath);
|
|
38
|
+
|
|
39
|
+
async function run() {
|
|
40
|
+
try {
|
|
41
|
+
|
|
42
|
+
const { default: config } = await import(pathToFileURL(absoluteConfigPath).href);
|
|
43
|
+
console.log(config);
|
|
44
|
+
const custom_prop_file_path = path.resolve(configDir, path.join(config.buildPath, config.destFile));
|
|
45
|
+
const custom_prop_filename = path.basename(custom_prop_file_path);
|
|
46
|
+
const checkdir = path.resolve(configDir, config.dir_to_check);
|
|
47
|
+
const exclude = config.exclude_pattern;
|
|
48
|
+
|
|
49
|
+
const files = [];
|
|
50
|
+
for await (const entry of glob(path.join(checkdir, '/**/*.css'))) {
|
|
51
|
+
if (!entry.endsWith(custom_prop_filename)) {
|
|
52
|
+
files.push(entry);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(custom_prop_file_path)) {
|
|
57
|
+
throw new Error(`File delle proprietà non trovato: ${custom_prop_file_path}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// lista custom props definiti
|
|
61
|
+
const cssContent = fs.readFileSync(custom_prop_file_path, 'utf-8');
|
|
62
|
+
const regex = /--([a-z0-9-]+)(?=\s*:)/g;
|
|
63
|
+
const propertyNamesList = [...cssContent.matchAll(regex)].map(match => `--${match[1]}`);
|
|
64
|
+
// extra_custom_props_files
|
|
65
|
+
|
|
66
|
+
(config.extra_custom_props_files??[]).forEach(extraCustomePropsFile => {
|
|
67
|
+
|
|
68
|
+
const extraCustomPropsContent = fs.readFileSync(
|
|
69
|
+
path.resolve(configDir, extraCustomePropsFile),
|
|
70
|
+
'utf-8');
|
|
71
|
+
|
|
72
|
+
const extraMatches = [...extraCustomPropsContent.matchAll(regex)].map(match => `--${match[1]}`);
|
|
73
|
+
propertyNamesList.push(...extraMatches);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// rilevamento custom props nei vari file css
|
|
79
|
+
const regex2 = /var\(\s*(--[a-z0-9-]+)\s*(,.*?)?\)/g;
|
|
80
|
+
const unresolved_props = [];
|
|
81
|
+
const check = []; // per controllo aggiuntivo esecuzione
|
|
82
|
+
|
|
83
|
+
files.forEach(file => {
|
|
84
|
+
const fileContent = fs.readFileSync(file, 'utf-8');
|
|
85
|
+
// const filename = path.relative(checkdir, file);
|
|
86
|
+
const filename = path.relative(configDir, file);
|
|
87
|
+
const matches = [...fileContent.matchAll(regex2)];
|
|
88
|
+
|
|
89
|
+
matches.forEach(match => {
|
|
90
|
+
const cprop = match[1];
|
|
91
|
+
const isExcluded = exclude.some(exRegex => exRegex.test(cprop));
|
|
92
|
+
const isDefined = propertyNamesList.includes(cprop);
|
|
93
|
+
|
|
94
|
+
const lineNumber = fileContent.substring(0, match.index).split('\n').length;
|
|
95
|
+
if (!isExcluded && !isDefined) {
|
|
96
|
+
// unresolved_props.push(`${filename}:${lineNumber} -> var(${cprop})`);
|
|
97
|
+
unresolved_props.push({file: filename, line: lineNumber, prop: cprop});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
check.push(`${filename}:${lineNumber} - ${cprop} - unresolved: ${(!isExcluded && !isDefined) ? 'Y' : 'N'}`);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
unresolved_props.sort((a,b) => a.file.localeCompare(b.file));
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const result_file = path.resolve(configDir, 'unresolved-props.md');
|
|
108
|
+
|
|
109
|
+
console.log(styleText(['green'],
|
|
110
|
+
`${unresolved_props.length} custom properties non impostate ` +
|
|
111
|
+
`-> ${path.relative(process.cwd(), result_file)}`)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Output
|
|
115
|
+
fs.writeFileSync(result_file, unresolved_props
|
|
116
|
+
.map(item => `* [${path.basename(item.file)} :: ${item.line}](${item.file}#L${item.line}) -> var(${item.prop})`)
|
|
117
|
+
.join('\n'), 'utf-8');
|
|
118
|
+
|
|
119
|
+
// fs.writeFileSync(path.resolve(configDir, 'full-result.txt'), check.join('\n'), 'utf-8');
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
console.log(styleText(['green'], '**** FINE ****'));
|
|
123
|
+
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.log(styleText(['redBright'], err.stack));
|
|
126
|
+
// console.error(styleText(['red'], `Errore: ${err.message}`));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
run();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
// TODO spostare percorsi minimo su node modules
|
|
6
|
+
const minimo_path = path.resolve(homedir(), 'Sites/minimo/src');
|
|
7
|
+
|
|
8
|
+
// path relativi a questo file
|
|
9
|
+
|
|
10
|
+
const config = {
|
|
11
|
+
// build tokens
|
|
12
|
+
stylelintConfigPath: '../../stylelint.config.mjs',
|
|
13
|
+
buildPath: '../src/css', // dir in cui salvare il file generato da style dictionary
|
|
14
|
+
destFile: 'custom-properties.css', // nome del file generato da style dictionary
|
|
15
|
+
// tokens files
|
|
16
|
+
source: [
|
|
17
|
+
// '../../node_modules/open-props/open-props.style-dictionary-tokens.json',
|
|
18
|
+
path.join(minimo_path, 'design-tokens/*.jsonc'),
|
|
19
|
+
path.join(minimo_path, 'components/**/*.tokens.jsonc'),
|
|
20
|
+
path.join(minimo_path, 'web-components/**/*.tokens.jsonc'),
|
|
21
|
+
'./figma-tokens-OK/*.jsonc',
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
// eventuali file aggiuntivi con custim props utilizzate nel progetto
|
|
25
|
+
extra_custom_props_files: [
|
|
26
|
+
// '../../node_modules/open-props/open-props.min.css'
|
|
27
|
+
],
|
|
28
|
+
dir_to_check: '../../src', // percorso della dir che include i css da analizzare
|
|
29
|
+
exclude_pattern: [ // patterns per l'esclusione dal controllo di alcune custom props
|
|
30
|
+
/^--_/,
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default config;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
```json
|
|
2
|
+
{
|
|
3
|
+
"build tokens": "node ~/Sites/minimo/utilities/build-tokens.mjs --config ./path/to/tokens-config.mjs",
|
|
4
|
+
"check unresolved props": "node ~/Sites/minimo/utilities/check-unresolved-custom-props.mjs --config ./path/to/tokens-config.mjs"
|
|
5
|
+
}
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
ln -s ~/Sites/minimo/src dest/_minimo-alias
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## TODO
|
|
13
|
+
|
|
14
|
+
* <https://github.com/georgeadamson/postcss-merge-selectors>
|
|
15
|
+
* <https://medium.com/@ashusingh584/chokidar-11290855e2cb>
|
|
16
|
+
* <https://github.com/xtivia/style-dictionary-watcher>
|
package/src/index-template.css
CHANGED
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
@import '@minimo/css/container.css';
|
|
16
16
|
|
|
17
17
|
/* @import '@minimo/css/forms/forms.css'; */
|
|
18
|
-
/* @import '@minimo/css/forms/
|
|
18
|
+
/* @import '@minimo/css/forms/fieldset.css'; */
|
|
19
|
+
/* @import '@minimo/css/forms/form-group.css'; */
|
|
20
|
+
/* @import '@minimo/css/forms/input-group.css'; */
|
|
21
|
+
/* @import '@minimo/css/forms/validation.css'; */
|
|
22
|
+
/* @import '@minimo/css/forms/form-utilities.css'; */
|
|
19
23
|
@import '@minimo/css/buttons/buttons.css';
|
|
20
24
|
/* @import '@minimo/css/buttons/status-buttons.css'; */
|
|
21
25
|
/* @import '@minimo/css/buttons/btn-close.css'; */
|
|
@@ -26,19 +30,10 @@
|
|
|
26
30
|
/* @import '@minimo/css/icons.css'; */
|
|
27
31
|
@import '@minimo/css/svg.css';
|
|
28
32
|
@import '@minimo/css/overlay.css';
|
|
29
|
-
/* @import '@minimo/css/inner-nav.css'; */
|
|
30
33
|
/* @import '@minimo/css/table.css'; */
|
|
31
34
|
/* @import '@minimo/css/flex.css'; */
|
|
32
35
|
/* @import '@minimo/css/grid.css'; */
|
|
33
36
|
/* @import '@minimo/css/details.css'; */
|
|
34
|
-
|
|
35
|
-
/* spinner attivarne uno solo + spinner-wrapper */
|
|
36
|
-
@import '@minimo/css/spinners/spinner-wrapper.css';
|
|
37
|
-
/* @import '@minimo/css/spinners/spinner-trailing-dots.css'; */
|
|
38
|
-
/* @import '@minimo/css/spinners/spinner-three-dots.css'; */
|
|
39
|
-
/* @import '@minimo/css/spinners/spinner-circle.css'; */
|
|
40
|
-
@import '@minimo/css/spinners/spinner-circle-basic.css';
|
|
41
|
-
|
|
42
37
|
/* @import '@minimo/css/utilities.css'; */
|
|
43
38
|
|
|
44
39
|
|
package/src/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { classnames } from './utilities/classnames.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path d="M205.66 149.66l-72 72a8 8 0 0 1-11.32 0l-72-72a8 8 0 0 1 11.32-11.32L120 196.69V40a8 8 0 0 1 16 0v156.69l58.34-58.35a8 8 0 0 1 11.32 11.32z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><path d="M117.66 170.34a8 8 0 0 1 0 11.32l-32 32a8 8 0 0 1-11.32 0l-32-32a8 8 0 0 1 11.32-11.32L72 188.69V48a8 8 0 0 1 16 0v140.69l18.34-18.35a8 8 0 0 1 11.32 0zm96-96l-32-32a8 8 0 0 0-11.32 0l-32 32a8 8 0 0 0 11.32 11.32L168 67.31V208a8 8 0 0 0 16 0V67.31l18.34 18.35a8 8 0 0 0 11.32-11.32z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M165.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L91.31,128Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M232.49,80.49l-128,128a12,12,0,0,1-17,0l-56-56a12,12,0,1,1,17-17L96,183,215.51,63.51a12,12,0,0,1,17,17Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"></path></svg>
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
|
|
2
|
+
import { DataTable } from 'simple-datatables';
|
|
3
|
+
// import { classnames } from '@massimo-cassandro/js-utilities/index.js';
|
|
4
|
+
|
|
5
|
+
import { parseCols } from './src/parse-cols.js';
|
|
6
|
+
|
|
7
|
+
import * as styles from './simple-datatable.module.css';
|
|
8
|
+
|
|
9
|
+
import caretLeftIcon from './icons/caret-left.svg?inline';
|
|
10
|
+
import caretRightIcon from './icons/caret-right.svg?inline';
|
|
11
|
+
|
|
12
|
+
// TODO possibilità di definizione cols anche da js. In questo caso, in presenza ANCHE dell'attributo, deve prevalere quest'ultimo
|
|
13
|
+
|
|
14
|
+
// https://fiduswriter.github.io/simple-datatables/documentation/
|
|
15
|
+
|
|
16
|
+
class SimpleDatatable extends HTMLElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
// this.attachShadow({ mode: 'open' }); // commentare per light dom
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// implementare se necessario modificare gli attributi nel runtime
|
|
24
|
+
/*
|
|
25
|
+
static get observedAttributes() {
|
|
26
|
+
return ['icon', 'variant', 'size', 'url'];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
attributeChangedCallback() {}
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async connectedCallback() {
|
|
34
|
+
this.innerHTML = '<div class="spinner"><span class="visually-hidden">Caricamento dati...</span></div>';
|
|
35
|
+
|
|
36
|
+
const jsonUrl = this.getAttribute('json') || null,
|
|
37
|
+
cols = JSON.parse(this.getAttribute('cols')?? {});
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(jsonUrl),
|
|
41
|
+
json_data = await response.json();
|
|
42
|
+
|
|
43
|
+
this.headings = cols.map(item => item._title? `<abbr title="${item._title}">${item._heading}</abbr>` : item._heading);
|
|
44
|
+
|
|
45
|
+
this.data = json_data.data.map((row, idx) => {
|
|
46
|
+
|
|
47
|
+
// riga datatable
|
|
48
|
+
return {
|
|
49
|
+
attributes: {'data-jidx': idx}, // indice della riga dati nel json originale
|
|
50
|
+
|
|
51
|
+
cells: cols.map((col_item, col_idx) => {
|
|
52
|
+
|
|
53
|
+
let value = row[col_item._field];
|
|
54
|
+
// let order = null;
|
|
55
|
+
|
|
56
|
+
// ------------------
|
|
57
|
+
// elaborazione _renderTpl -> aggiunta id e/o altri riferimenti a campi della riga.
|
|
58
|
+
// necessario farlo così, perché simple-datatable non permette l'accesso ai dati di riga
|
|
59
|
+
// durante il render delle celle, i riferimenti vanno quindi risolti al momento di elaborare i dati
|
|
60
|
+
if(col_item._renderTpl) {
|
|
61
|
+
const this_value = decodeURIComponent(col_item._renderTpl).replace(/\[\[(.*?)\]\]/g, (match, key) => {
|
|
62
|
+
|
|
63
|
+
if(row[key] == null) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.error(`[s-datatable] Chiave “${key}” non trovata (colonna ${col_idx})`);
|
|
66
|
+
}
|
|
67
|
+
return row[key]?? '{{' + key + '}}';
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
value = this_value;
|
|
71
|
+
// order = row[col_item._field];
|
|
72
|
+
}
|
|
73
|
+
// ------------------
|
|
74
|
+
|
|
75
|
+
// conversione date symfony in ISO8601
|
|
76
|
+
else if(col_item._renderMode === 'sf_datetime' && value != null) {
|
|
77
|
+
value = value.date.replace(' ', 'T') +
|
|
78
|
+
(value.timezone === 'UTC'? 'Z' : '');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return value; //{text: value, ...(order? {order: order} : {})};
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.columns = cols.map((col_settings, idx ) => {
|
|
87
|
+
|
|
88
|
+
// pre-elaborazione tipi predefiniti
|
|
89
|
+
col_settings = parseCols(col_settings);
|
|
90
|
+
|
|
91
|
+
const col_obj = {
|
|
92
|
+
...(Object.fromEntries(
|
|
93
|
+
Object.entries(col_settings).filter(([key]) => !key.startsWith('_'))
|
|
94
|
+
)),
|
|
95
|
+
select: idx,
|
|
96
|
+
type: col_settings.type?? 'string',
|
|
97
|
+
searchable: col_settings.searchable?? true,
|
|
98
|
+
sortable: col_settings.sortable?? true,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return col_obj;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// console.log('json_data', json_data);
|
|
105
|
+
// console.log('cols', cols);
|
|
106
|
+
// console.log('columns', this.columns);
|
|
107
|
+
// console.log('data', this.data);
|
|
108
|
+
|
|
109
|
+
} catch(err) {
|
|
110
|
+
/* eslint-disable no-console */
|
|
111
|
+
console.error(jsonUrl);
|
|
112
|
+
console.error(err);
|
|
113
|
+
/* eslint-enable no-console */
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.render();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// approccio per eventuale modifica degli attributi nel runtime
|
|
120
|
+
// set variant(val) {this.setAttribute('variant', val);} get variant(val) {return this.getAttribute('variant')}
|
|
121
|
+
|
|
122
|
+
render() {
|
|
123
|
+
this.innerHTML = '';
|
|
124
|
+
const table = document.createElement('table');
|
|
125
|
+
this.appendChild(table);
|
|
126
|
+
|
|
127
|
+
// https://fiduswriter.github.io/simple-datatables/documentation/Options
|
|
128
|
+
const dt = new DataTable(table, {
|
|
129
|
+
locale: 'it',
|
|
130
|
+
searchable: true,
|
|
131
|
+
sortable: true,
|
|
132
|
+
fixedHeight: false,
|
|
133
|
+
fixedColumns: false,
|
|
134
|
+
paging: true,
|
|
135
|
+
perPage: +this.getAttribute('perPage') || 25,
|
|
136
|
+
pagerDelta: 2,
|
|
137
|
+
perPageSelect: false,
|
|
138
|
+
|
|
139
|
+
labels: {
|
|
140
|
+
placeholder: 'Cerca...',
|
|
141
|
+
searchTitle: 'Cerca nella tabella',
|
|
142
|
+
pageTitle: 'Pagina {page}',
|
|
143
|
+
perPage: 'Righe per pagina',
|
|
144
|
+
noRows: 'Nessun record trovato',
|
|
145
|
+
info: 'Stai visualizzando le righe da {start} a {end}, su un totale di {rows}',
|
|
146
|
+
noResults: 'Nessun risultato per la ricerca',
|
|
147
|
+
},
|
|
148
|
+
classes: {
|
|
149
|
+
wrapper : styles.datatableWrapper,
|
|
150
|
+
container : 'table-responsive',
|
|
151
|
+
loading : 'datatable-loading', // ??
|
|
152
|
+
|
|
153
|
+
// barra superiore
|
|
154
|
+
top : styles.topArea,
|
|
155
|
+
search : styles.searchWrapper,
|
|
156
|
+
input : 'form-control form-control-sm',
|
|
157
|
+
// dropdown : 'datatable-dropdown', // selettore righe per pagina, disattivato
|
|
158
|
+
|
|
159
|
+
empty : styles.empty,
|
|
160
|
+
|
|
161
|
+
// table
|
|
162
|
+
table : `table table-bordered ${styles.table}`,
|
|
163
|
+
// buttons in thead per il sort
|
|
164
|
+
sorter : `btn-reset ${styles.sortBtn}`,
|
|
165
|
+
ascending : styles.sortAscending,
|
|
166
|
+
descending : styles.sortDescending,
|
|
167
|
+
|
|
168
|
+
// area inferiore
|
|
169
|
+
bottom : styles.bottomArea,
|
|
170
|
+
// info text
|
|
171
|
+
info : styles.info,
|
|
172
|
+
|
|
173
|
+
// pagination
|
|
174
|
+
// pagination : styles.paginationNav,
|
|
175
|
+
paginationList : styles.paginationList,
|
|
176
|
+
paginationListItem : styles.paginationListItem,
|
|
177
|
+
paginationListItemLink : styles.paginationListItemBtn,
|
|
178
|
+
// hidden : 'datatable-hidden',
|
|
179
|
+
disabled : styles.paginationDisabled,
|
|
180
|
+
active : styles.paginationActive,
|
|
181
|
+
|
|
182
|
+
// cursor: 'datatable-cursor',
|
|
183
|
+
// dropdown: 'datatable-dropdown',
|
|
184
|
+
// ellipsis: 'datatable-ellipsis',
|
|
185
|
+
// filter: 'datatable-filter',
|
|
186
|
+
// filterActive: 'datatable-filter-active',
|
|
187
|
+
// headercontainer: 'datatable-headercontainer',
|
|
188
|
+
// selector: 'datatable-selector',
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
columns: this.columns,
|
|
192
|
+
data: {
|
|
193
|
+
headings: this.headings,
|
|
194
|
+
data: this.data
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
dt.on('datatable.init', () => {
|
|
199
|
+
const pagination = this.querySelector(`.${styles.paginationList}`);
|
|
200
|
+
|
|
201
|
+
if(pagination.querySelectorAll(`.${styles.paginationListItem}`).length) {
|
|
202
|
+
|
|
203
|
+
pagination.querySelector(`.${styles.paginationListItem}:first-child .${styles.paginationListItemBtn}`)
|
|
204
|
+
.innerHTML = caretLeftIcon;
|
|
205
|
+
|
|
206
|
+
pagination.querySelector(`.${styles.paginationListItem}:last-child .${styles.paginationListItemBtn}`)
|
|
207
|
+
.innerHTML = caretRightIcon;
|
|
208
|
+
|
|
209
|
+
pagination.querySelectorAll(`.${styles.paginationListItemBtn}:has(svg)`)
|
|
210
|
+
.forEach(btn => btn.classList.add(styles.hasSvg));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
} // end render
|
|
215
|
+
} // end component
|
|
216
|
+
|
|
217
|
+
if (!customElements.get('s-datatable')) {
|
|
218
|
+
customElements.define('s-datatable', SimpleDatatable);
|
|
219
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sdt": {
|
|
3
|
+
|
|
4
|
+
"thead": {
|
|
5
|
+
"hover": {
|
|
6
|
+
"background": {
|
|
7
|
+
"color": {
|
|
8
|
+
"$value": "color-mix(in srgb, {table.thead.background.color} 90%, {accent.base})",
|
|
9
|
+
"$type": "color"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
"pagination": {
|
|
16
|
+
"border": {
|
|
17
|
+
"$type": "border",
|
|
18
|
+
"$value": {
|
|
19
|
+
"color": "{neutral.base}",
|
|
20
|
+
"width": "{btn.border.width}",
|
|
21
|
+
// "style": "solid"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"padding": {
|
|
25
|
+
"block": {
|
|
26
|
+
"$value": "{size.xxs}",
|
|
27
|
+
"$type": "dimension"
|
|
28
|
+
},
|
|
29
|
+
"inline": {
|
|
30
|
+
"$value": "{size.xs}",
|
|
31
|
+
"$type": "dimension"
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"hover": {
|
|
36
|
+
"background": {
|
|
37
|
+
"color": {
|
|
38
|
+
"$value": "{btn.primary.background.color}",
|
|
39
|
+
"$type": "color"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"color": {
|
|
43
|
+
"$value": "{btn.primary.color}",
|
|
44
|
+
"$type": "color"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|