feat(helpers): add uuid method
This commit is contained in:
parent
05e17d69e5
commit
8674ebd47f
12 changed files with 24 additions and 27 deletions
|
|
@ -36,7 +36,8 @@
|
||||||
"lion-accordion.js"
|
"lion-accordion.js"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.22.0"
|
"@lion/core": "^0.22.0",
|
||||||
|
"@lion/helpers": "^0.11.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"accordion",
|
"accordion",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable class-methods-use-this */
|
/* eslint-disable class-methods-use-this */
|
||||||
import { LitElement, css, html } from '@lion/core';
|
import { LitElement, css, html } from '@lion/core';
|
||||||
|
import { uuid } from '@lion/helpers';
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} StoreEntry
|
* @typedef {Object} StoreEntry
|
||||||
* @property {string} uid Unique ID for the entry
|
* @property {string} uid Unique ID for the entry
|
||||||
|
|
@ -11,8 +11,6 @@ import { LitElement, css, html } from '@lion/core';
|
||||||
* @property {(event: Event) => unknown} keydownHandler executed on keydown event
|
* @property {(event: Event) => unknown} keydownHandler executed on keydown event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uuid = () => Math.random().toString(36).substr(2, 10);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # <lion-accordion> webcomponent
|
* # <lion-accordion> webcomponent
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@
|
||||||
"demo/custom-collapsible.js"
|
"demo/custom-collapsible.js"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.22.0"
|
"@lion/core": "^0.22.0",
|
||||||
|
"@lion/helpers": "^0.11.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"collapsible",
|
"collapsible",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import { LitElement, html, css } from '@lion/core';
|
import { LitElement, html, css } from '@lion/core';
|
||||||
/**
|
import { uuid } from '@lion/helpers';
|
||||||
* Generate random UUID
|
|
||||||
*/
|
|
||||||
const uuid = () => Math.random().toString(36).substr(2, 10);
|
|
||||||
/**
|
/**
|
||||||
* `LionCollapsible` is a class for custom collapsible element (`<lion-collapsible>` web component).
|
* `LionCollapsible` is a class for custom collapsible element (`<lion-collapsible>` web component).
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.22.0",
|
"@lion/core": "^0.22.0",
|
||||||
|
"@lion/helpers": "^0.11.0",
|
||||||
"@lion/localize": "^0.24.0"
|
"@lion/localize": "^0.24.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { css, dedupeMixin, html, nothing, SlotMixin, DisabledMixin } from '@lion/core';
|
import { css, dedupeMixin, html, nothing, SlotMixin, DisabledMixin } from '@lion/core';
|
||||||
|
import { uuid } from '@lion/helpers';
|
||||||
import { getAriaElementsInRightDomOrder } from './utils/getAriaElementsInRightDomOrder.js';
|
import { getAriaElementsInRightDomOrder } from './utils/getAriaElementsInRightDomOrder.js';
|
||||||
import { Unparseable } from './validate/Unparseable.js';
|
import { Unparseable } from './validate/Unparseable.js';
|
||||||
import { FormRegisteringMixin } from './registration/FormRegisteringMixin.js';
|
import { FormRegisteringMixin } from './registration/FormRegisteringMixin.js';
|
||||||
|
|
@ -16,14 +17,6 @@ import { FormRegisteringMixin } from './registration/FormRegisteringMixin.js';
|
||||||
* @typedef {import('../types/FormControlMixinTypes.js').ModelValueEventDetails} ModelValueEventDetails
|
* @typedef {import('../types/FormControlMixinTypes.js').ModelValueEventDetails} ModelValueEventDetails
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates random unique identifier (for dom elements)
|
|
||||||
* @param {string} prefix
|
|
||||||
*/
|
|
||||||
function uuid(prefix) {
|
|
||||||
return `${prefix}-${Math.random().toString(36).substr(2, 10)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #FormControlMixin :
|
* #FormControlMixin :
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Utilities
|
// Utilities
|
||||||
export { renderLitAsNode } from './renderLitAsNode/src/renderLitAsNode.js';
|
export { renderLitAsNode } from './renderLitAsNode/src/renderLitAsNode.js';
|
||||||
export { sortEachDepth } from './sortEachDepth/src/sortEachDepth.js';
|
export { sortEachDepth } from './sortEachDepth/src/sortEachDepth.js';
|
||||||
|
export { uuid } from './uuid/uuid.js';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
export { SbActionLogger } from './sb-action-logger/src/SbActionLogger.js';
|
export { SbActionLogger } from './sb-action-logger/src/SbActionLogger.js';
|
||||||
|
|
|
||||||
9
packages/helpers/uuid/uuid.js
Normal file
9
packages/helpers/uuid/uuid.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Generates random unique identifier (for dom elements)
|
||||||
|
* @param {string} prefix
|
||||||
|
* @return {string} unique id
|
||||||
|
*/
|
||||||
|
export function uuid(prefix = '') {
|
||||||
|
const elementName = prefix.length > 1 ? `${prefix}-` : '';
|
||||||
|
return `${elementName}${Math.random().toString(36).substr(2, 10)}`;
|
||||||
|
}
|
||||||
|
|
@ -40,7 +40,8 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.22.0",
|
"@lion/core": "^0.22.0",
|
||||||
"@lion/form-core": "^0.17.1"
|
"@lion/form-core": "^0.17.1",
|
||||||
|
"@lion/helpers": "^0.11.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"form",
|
"form",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { css, dedupeMixin, html, ScopedElementsMixin, SlotMixin } from '@lion/core';
|
import { css, dedupeMixin, html, ScopedElementsMixin, SlotMixin } from '@lion/core';
|
||||||
import { ChoiceGroupMixin, FormControlMixin, FormRegistrarMixin } from '@lion/form-core';
|
import { ChoiceGroupMixin, FormControlMixin, FormRegistrarMixin } from '@lion/form-core';
|
||||||
|
import { uuid } from '@lion/helpers';
|
||||||
import { LionOptions } from './LionOptions.js';
|
import { LionOptions } from './LionOptions.js';
|
||||||
|
|
||||||
// TODO: extract ListNavigationWithActiveDescendantMixin that can be reused in [role="menu"]
|
// TODO: extract ListNavigationWithActiveDescendantMixin that can be reused in [role="menu"]
|
||||||
|
|
@ -51,10 +52,6 @@ function moveDefaultSlottablesToTarget(source, target) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function uuid() {
|
|
||||||
return Math.random().toString(36).substr(2, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ListboxMixin}
|
* @type {ListboxMixin}
|
||||||
* @param {import('@open-wc/dedupe-mixin').Constructor<import('@lion/core').LitElement>} superclass
|
* @param {import('@open-wc/dedupe-mixin').Constructor<import('@lion/core').LitElement>} superclass
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@
|
||||||
"lion-tabs.js"
|
"lion-tabs.js"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.22.0"
|
"@lion/core": "^0.22.0",
|
||||||
|
"@lion/helpers": "^0.11.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"lion",
|
"lion",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { css, html, LitElement } from '@lion/core';
|
import { css, html, LitElement } from '@lion/core';
|
||||||
|
import { uuid } from '@lion/helpers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} StoreEntry
|
* @typedef {Object} StoreEntry
|
||||||
|
|
@ -11,10 +12,6 @@ import { css, html, LitElement } from '@lion/core';
|
||||||
* @property {(event: Event) => unknown} keyupHandler executed on keyup event
|
* @property {(event: Event) => unknown} keyupHandler executed on keyup event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function uuid() {
|
|
||||||
return Math.random().toString(36).substr(2, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {StoreEntry} options
|
* @param {StoreEntry} options
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue