desy-html 8.13.1 → 9.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/config/tailwind.config.js +189 -189
- package/docs/_global.foot.njk +1 -0
- package/docs/_include.template-header.njk +5 -0
- package/docs/_macro.example-render.njk +4 -0
- package/docs/componentes.html +3 -0
- package/docs/ds/_ds.section.layout.njk +5 -0
- package/docs/examples-datepicker.html +8 -0
- package/docs/index.html +10 -0
- package/gulpfile.js +32 -36
- package/package.json +9 -2
- package/src/css/styles.css +1 -0
- package/src/js/cally.js +1114 -0
- package/src/js/desy-html.js +88 -0
- package/src/js/filters/filter-caller.js +2 -2
- package/src/js/filters/filter-slugify.js +2 -2
- package/src/js/filters/highlight.js +4 -4
- package/src/js/filters/index.js +6 -5
- package/src/js/globals/get-html-code-from-example.js +8 -6
- package/src/js/globals/get-html-code-from-file.js +7 -7
- package/src/js/globals/get-nunjucks-code-from-example.js +9 -10
- package/src/js/globals/get-nunjucks-code-from-file.js +6 -6
- package/src/js/globals/index.js +6 -6
- package/src/js/index.js +3 -1
- package/src/templates/components/datepicker/_examples.datepicker.njk +347 -0
- package/src/templates/components/datepicker/_macro.datepicker.njk +3 -0
- package/src/templates/components/datepicker/_styles.datepicker.css +85 -0
- package/src/templates/components/datepicker/_template.datepicker.njk +124 -0
- package/src/templates/components/datepicker/params.datepicker.yaml +105 -0
package/src/js/desy-html.js
CHANGED
|
@@ -435,3 +435,91 @@ export function NavComponent(aria) {
|
|
|
435
435
|
nav.init(null);
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
|
+
|
|
439
|
+
export function DatepickerComponent(aria) {
|
|
440
|
+
const modules = document.querySelectorAll('[data-module="c-datepicker"]');
|
|
441
|
+
[...modules].forEach((module) => {
|
|
442
|
+
const inputElement = module.getElementsByTagName('input')[0];
|
|
443
|
+
if (inputElement) {
|
|
444
|
+
const dropdownId = inputElement.getAttribute('id');
|
|
445
|
+
const datepickerDropdown = inputElement.parentNode.querySelector('[data-module="c-dropdown-button"]');
|
|
446
|
+
let datepickerCalendar = null;
|
|
447
|
+
let isOpen = false;
|
|
448
|
+
|
|
449
|
+
const focusCalendar = () => {
|
|
450
|
+
const inputInitialValue = inputElement.value;
|
|
451
|
+
requestAnimationFrame(() => {
|
|
452
|
+
const datepickerSelect = module.querySelector(':is(select)');
|
|
453
|
+
const datepickerCalendar = module.querySelector(':is(calendar-date, calendar-multi, calendar-range)');
|
|
454
|
+
const datepickerInitialValue = datepickerCalendar.value;
|
|
455
|
+
if (datepickerCalendar != undefined) {
|
|
456
|
+
datepickerCalendar.focus();
|
|
457
|
+
datepickerCalendar.addEventListener('change', (e) => {
|
|
458
|
+
inputElement.value = e.target.value;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if(datepickerSelect != undefined) {
|
|
462
|
+
datepickerSelect.addEventListener('change', function() {
|
|
463
|
+
const selectedValue = this.value;
|
|
464
|
+
datepickerCalendar.min = selectedValue + "-01-01";
|
|
465
|
+
datepickerCalendar.max = selectedValue + "-31-12";
|
|
466
|
+
datepickerCalendar.focusedDate = datepickerCalendar.min;
|
|
467
|
+
});
|
|
468
|
+
datepickerSelect.focus();
|
|
469
|
+
}
|
|
470
|
+
const datepickerCancel = module.querySelector('#' + dropdownId + '-cancel');
|
|
471
|
+
const datepickerSubmit = module.querySelector('#' + dropdownId + '-submit');
|
|
472
|
+
if (datepickerCancel != undefined) {
|
|
473
|
+
datepickerCancel.onclick = function() {
|
|
474
|
+
inputElement.value = inputInitialValue;
|
|
475
|
+
datepickerCalendar.tentative ="";
|
|
476
|
+
datepickerCalendar.value = datepickerInitialValue;
|
|
477
|
+
closeDropdown();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (datepickerSubmit != undefined) {
|
|
481
|
+
datepickerSubmit.onclick = function() {
|
|
482
|
+
closeDropdown();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const closeDropdown = () => {
|
|
489
|
+
setTimeout(() => {
|
|
490
|
+
isOpen = false;
|
|
491
|
+
inputElement.focus();
|
|
492
|
+
}, 300);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const observer = new MutationObserver((mutations) => {
|
|
496
|
+
mutations.forEach((mutation) => {
|
|
497
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'aria-expanded') {
|
|
498
|
+
const currentExpandedValue = mutation.target.getAttribute('aria-expanded');
|
|
499
|
+
if (currentExpandedValue !== isOpen) {
|
|
500
|
+
const datepickerTimeout = setTimeout(focusCalendar, 500);
|
|
501
|
+
isOpen = currentExpandedValue;
|
|
502
|
+
if(!isOpen) {
|
|
503
|
+
clearTimeout(datepickerTimeout);
|
|
504
|
+
closeDropdown();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
observer.observe(datepickerDropdown, { attributes: true, attributeFilter: ['aria-expanded'] });
|
|
512
|
+
} else {
|
|
513
|
+
const datepickerSelect = module.querySelector(':is(select)');
|
|
514
|
+
const datepickerCalendar = module.querySelector(':is(calendar-date, calendar-multi, calendar-range)');
|
|
515
|
+
if(datepickerSelect != undefined) {
|
|
516
|
+
datepickerSelect.addEventListener('change', function() {
|
|
517
|
+
const selectedValue = this.value;
|
|
518
|
+
datepickerCalendar.min = selectedValue + "-01-01";
|
|
519
|
+
datepickerCalendar.max = selectedValue + "-31-12";
|
|
520
|
+
datepickerCalendar.focusedDate = datepickerCalendar.min;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function filterslugify(str) {
|
|
2
2
|
// Replace spaces with hyphens
|
|
3
3
|
let slug = str.replace(/\s+/g, '-');
|
|
4
4
|
// Remove special characters
|
|
@@ -8,4 +8,4 @@ function filterSlugify(str) {
|
|
|
8
8
|
return slug;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export default filterslugify;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import hljs from 'highlight.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Format code with syntax highlighting
|
|
@@ -7,8 +7,8 @@ const hljs = require('highlight.js')
|
|
|
7
7
|
* @param {string} [language] - Code programming language
|
|
8
8
|
* @returns {string} Code with syntax highlighting
|
|
9
9
|
*/
|
|
10
|
-
function highlight
|
|
11
|
-
return hljs.highlight(code.trim(), { language: language || 'plaintext' }).value
|
|
10
|
+
function highlight(code, language) {
|
|
11
|
+
return hljs.highlight(code.trim(), { language: language || 'plaintext' }).value;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
export default highlight;
|
package/src/js/filters/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Nunjucks filters
|
|
3
3
|
*/
|
|
4
|
-
const highlight = require('./highlight')
|
|
5
|
-
const filtercaller = require('./filter-caller')
|
|
6
|
-
const filterslugify = require('./filter-slugify')
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
import highlight from './highlight.js';
|
|
6
|
+
import filtercaller from './filter-caller.js';
|
|
7
|
+
import filterslugify from './filter-slugify.js';
|
|
8
|
+
|
|
9
|
+
export const SOURCE_NUNJUCKS_FILTERS = {
|
|
9
10
|
highlight,
|
|
10
11
|
filtercaller,
|
|
11
12
|
filterslugify
|
|
12
|
-
}
|
|
13
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import beautify from 'js-beautify';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Component HTML code (formatted)
|
|
4
5
|
*
|
|
@@ -6,14 +7,15 @@ const beautify = require('js-beautify')
|
|
|
6
7
|
* @param {unknown} params - Component macro params
|
|
7
8
|
* @param {unknown} pathName - path name
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
function getHTMLCodeFromExample(componentName, params, pathName) {
|
|
10
12
|
const templatePath = `${pathName}s/${componentName}/_template.${componentName}.njk`;
|
|
11
13
|
|
|
12
14
|
// Render to HTML
|
|
13
|
-
const html = this.env.render(templatePath, { params }).trim()
|
|
15
|
+
const html = this.env.render(templatePath, { params }).trim();
|
|
14
16
|
|
|
15
17
|
// Default beautify options
|
|
16
|
-
const options = beautify.html.defaultOptions()
|
|
18
|
+
const options = beautify.html.defaultOptions();
|
|
17
19
|
|
|
18
20
|
return beautify.html(html, {
|
|
19
21
|
indent_size: 2,
|
|
@@ -23,7 +25,7 @@ function getHTMLCodeFromExample (componentName, params, pathName) {
|
|
|
23
25
|
max_preserve_newlines: 0,
|
|
24
26
|
// Ensure attribute wrapping in header SVG is preserved
|
|
25
27
|
wrap_attributes: 'preserve'
|
|
26
|
-
})
|
|
28
|
+
});
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
export default getHTMLCodeFromExample;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import beautify from 'js-beautify';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Component HTML code (formatted)
|
|
4
5
|
*
|
|
5
6
|
* @param {string} templatePath - Path to nunjucks file. Eg: `includes/_loremipsum-large.njk`;
|
|
6
7
|
*/
|
|
7
|
-
function getHTMLCodeFromFile
|
|
8
|
-
|
|
8
|
+
function getHTMLCodeFromFile(templatePath) {
|
|
9
9
|
// Render to HTML
|
|
10
|
-
const html = this.env.render(templatePath).trim()
|
|
10
|
+
const html = this.env.render(templatePath).trim();
|
|
11
11
|
|
|
12
12
|
// Default beautify options
|
|
13
|
-
const options = beautify.html.defaultOptions()
|
|
13
|
+
const options = beautify.html.defaultOptions();
|
|
14
14
|
|
|
15
15
|
return beautify.html(html, {
|
|
16
16
|
indent_size: 2,
|
|
@@ -20,7 +20,7 @@ function getHTMLCodeFromFile (templatePath) {
|
|
|
20
20
|
max_preserve_newlines: 0,
|
|
21
21
|
// Ensure attribute wrapping in header SVG is preserved
|
|
22
22
|
wrap_attributes: 'preserve'
|
|
23
|
-
})
|
|
23
|
+
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
export default getHTMLCodeFromFile;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { outdent } from 'outdent';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Component Nunjucks code (formatted)
|
|
@@ -8,25 +7,25 @@ const { outdent } = require('outdent')
|
|
|
8
7
|
* @param {unknown} params - Component macro params
|
|
9
8
|
* @returns {string} Nunjucks code
|
|
10
9
|
*/
|
|
11
|
-
function getNunjucksCodeFromExample
|
|
12
|
-
const macroName = kebabCaseToPascalCase(componentName)
|
|
10
|
+
function getNunjucksCodeFromExample(componentName, params, pathName) {
|
|
11
|
+
const macroName = kebabCaseToPascalCase(componentName);
|
|
13
12
|
|
|
14
13
|
return outdent`
|
|
15
14
|
{% from "${pathName}s/${componentName}/_macro.${componentName}.njk" import ${pathName}${macroName} %}
|
|
16
15
|
|
|
17
16
|
{{ ${pathName}${macroName}(${
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
JSON.stringify(params, undefined, 2)
|
|
18
|
+
}) }}
|
|
19
|
+
`;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
function kebabCaseToPascalCase
|
|
22
|
+
function kebabCaseToPascalCase(value) {
|
|
24
23
|
return value
|
|
25
24
|
.toLowerCase()
|
|
26
25
|
.split('-')
|
|
27
26
|
// capitalize each 'word'
|
|
28
27
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
29
|
-
.join('')
|
|
28
|
+
.join('');
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
export default getNunjucksCodeFromExample;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Component Nunjucks code (formatted)
|
|
@@ -6,9 +7,8 @@ const { outdent } = require('outdent')
|
|
|
6
7
|
* @param {string} templatePath - Path to nunjucks file. Eg: `includes/_loremipsum-large.njk`;
|
|
7
8
|
* @returns {string} Nunjucks code
|
|
8
9
|
*/
|
|
9
|
-
function getNunjucksCodeFromFile
|
|
10
|
-
|
|
11
|
-
let codeFromFile
|
|
10
|
+
function getNunjucksCodeFromFile(templatePath) {
|
|
11
|
+
let codeFromFile;
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
14
|
codeFromFile = fs.readFileSync(`src/templates/${templatePath}`, 'utf8');
|
|
@@ -18,7 +18,7 @@ function getNunjucksCodeFromFile (templatePath) {
|
|
|
18
18
|
|
|
19
19
|
return outdent`
|
|
20
20
|
${codeFromFile}
|
|
21
|
-
|
|
21
|
+
`;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
export default getNunjucksCodeFromFile;
|
package/src/js/globals/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Nunjucks globals
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import getHTMLCodeFromExample from './get-html-code-from-example.js';
|
|
5
|
+
import getNunjucksCodeFromExample from './get-nunjucks-code-from-example.js';
|
|
6
|
+
import getHTMLCodeFromFile from './get-html-code-from-file.js';
|
|
7
|
+
import getNunjucksCodeFromFile from './get-nunjucks-code-from-file.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export const SOURCE_NUNJUCKS_GLOBALS = {
|
|
10
10
|
getNunjucksCodeFromExample,
|
|
11
11
|
getHTMLCodeFromExample,
|
|
12
12
|
getNunjucksCodeFromFile,
|
|
13
13
|
getHTMLCodeFromFile
|
|
14
|
-
}
|
|
14
|
+
};
|
package/src/js/index.js
CHANGED
|
@@ -23,7 +23,8 @@ import {
|
|
|
23
23
|
MenuHorizontalComponent,
|
|
24
24
|
MenuNavigationComponent,
|
|
25
25
|
HeaderNavigationComponent,
|
|
26
|
-
NavComponent
|
|
26
|
+
NavComponent,
|
|
27
|
+
DatepickerComponent
|
|
27
28
|
} from './desy-html.js';
|
|
28
29
|
|
|
29
30
|
var aria = aria || {};
|
|
@@ -48,6 +49,7 @@ MenuHorizontalComponent(aria);
|
|
|
48
49
|
MenuNavigationComponent(aria);
|
|
49
50
|
HeaderNavigationComponent(aria);
|
|
50
51
|
NavComponent(aria);
|
|
52
|
+
DatepickerComponent(aria);
|
|
51
53
|
|
|
52
54
|
//Using the browser API to copy code to the clipboard
|
|
53
55
|
const copyButtons = document.querySelectorAll('[data-module = "c-button-copy"]');
|