@massimo-cassandro/minimo 1.7.0 → 1.7.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/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  export { betterText } from './src/utilities/better-text.js';
4
4
  export { classnames, classnamesNull } from './src/utilities/classnames.js';
5
5
  export { createId } from './src/utilities/create-id.js';
6
+ export { disableBtnsOnSubmit } from './src/utilities/disable-btns-on-submit.js';
6
7
  export { domBuilder } from './src/utilities/dom-builder/dom-builder.js';
7
8
  export { enableSubmitBtns } from './src/utilities/enable-submit-btns.js';
8
9
  export { escapeHTML, unescapeHTML } from './src/utilities/escape-html.js';
9
10
  export { getCookie, setCookie } from './src/utilities/cookies.js';
10
11
  export { linkedDates } from './src/utilities/linked-dates.js';
12
+ export { randomId } from './src/utilities/random-id.js';
11
13
  export { relativeDate } from './src/utilities/relative-date.js';
12
14
  export { sentenceCase } from './src/utilities/sentence-case.js';
13
15
  export { stripTags } from './src/utilities/strip-tags.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Disables all `[type=submit]` and `[type=button]` buttons on form submit.
3
+ *
4
+ * Applies to all `<form>` elements in the document except those with
5
+ * `data-disable-submit="false"`.
6
+ *
7
+ * @returns {void}
8
+ */
9
+ export function disableBtnsOnSubmit() {
10
+ document.querySelectorAll('form:not([data-disable-submit=false])').forEach( el => {
11
+ el.addEventListener('submit', () => {
12
+ /** @type {NodeListOf<HTMLButtonElement|HTMLInputElement>} */
13
+ const btns = el.querySelectorAll('[type=submit], [type=button]');
14
+ btns.forEach(btn => {
15
+ btn.disabled = true;
16
+ });
17
+ });
18
+ });
19
+ }
@@ -0,0 +1,13 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * Generates a random ID string.
5
+ * @returns {string} Base64-encoded random string
6
+ */
7
+ export function randomId() {
8
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
9
+ const bytes = crypto.getRandomValues(new Uint8Array(12));
10
+ return chars[bytes[0] % 52] // first item is from first 52 chars (A-Za-z)
11
+ + Array.from(bytes.slice(1), b => chars[b % 63]).join('');
12
+ }
13
+