@studiometa/js-toolkit 3.0.0-alpha.5 → 3.0.0-alpha.7
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/Base/Base.d.ts +5 -5
- package/Base/Base.js +52 -29
- package/Base/Base.js.map +2 -2
- package/Base/features.d.ts +5 -0
- package/Base/features.js +8 -0
- package/Base/features.js.map +2 -2
- package/Base/managers/ChildrenManager.d.ts +5 -5
- package/Base/managers/ChildrenManager.js +24 -17
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.d.ts +6 -28
- package/Base/managers/EventsManager.js +45 -55
- package/Base/managers/EventsManager.js.map +2 -2
- package/Base/managers/OptionsManager.d.ts +1 -1
- package/Base/managers/OptionsManager.js +25 -20
- package/Base/managers/OptionsManager.js.map +3 -3
- package/Base/managers/RefsManager.d.ts +1 -1
- package/Base/managers/RefsManager.js +15 -26
- package/Base/managers/RefsManager.js.map +3 -3
- package/Base/managers/ResponsiveOptionsManager.js +7 -4
- package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
- package/Base/utils.d.ts +1 -1
- package/Base/utils.js +11 -17
- package/Base/utils.js.map +2 -2
- package/decorators/withBreakpointManager.js +6 -4
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.d.ts +0 -1
- package/decorators/withBreakpointObserver.js +4 -2
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.js +2 -2
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.js +2 -2
- package/decorators/withMountWhenInView.js.map +2 -2
- package/helpers/createApp.js +9 -4
- package/helpers/createApp.js.map +2 -2
- package/package.json +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +2 -2
- package/utils/memo.d.ts +5 -0
- package/utils/memo.js +14 -0
- package/utils/memo.js.map +7 -0
- package/utils/string/changeCase.d.ts +24 -0
- package/utils/string/changeCase.js +47 -0
- package/utils/string/changeCase.js.map +7 -0
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/index.js.map +2 -2
- package/Base/managers/ActionManager.d.ts +0 -4
- package/Base/managers/ActionManager.js +0 -10
- package/Base/managers/ActionManager.js.map +0 -7
package/Base/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Base, BaseConfig, BaseConstructor } from './index.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Add a task to the main queue.
|
|
4
4
|
*/
|
|
5
|
-
export declare function addToQueue(fn: () => unknown):
|
|
5
|
+
export declare function addToQueue(fn: () => unknown): Promise<unknown>;
|
|
6
6
|
/**
|
|
7
7
|
* Get a list of elements based on the name of a component.
|
|
8
8
|
*
|
package/Base/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isDefined,
|
|
1
|
+
import { isArray, isDefined, SmartQueue } from "../utils/index.js";
|
|
2
2
|
import { features } from "./features.js";
|
|
3
3
|
let queue;
|
|
4
4
|
function addToQueue(fn) {
|
|
@@ -9,25 +9,27 @@ function addToQueue(fn) {
|
|
|
9
9
|
if (!queue) {
|
|
10
10
|
queue = new SmartQueue();
|
|
11
11
|
}
|
|
12
|
-
queue.add(fn);
|
|
12
|
+
return queue.add(fn);
|
|
13
13
|
}
|
|
14
14
|
const selectors = /* @__PURE__ */ new Map();
|
|
15
15
|
const separator = " ";
|
|
16
16
|
function getSelector(nameOrSelector) {
|
|
17
|
-
|
|
17
|
+
const { component } = features.get("attributes");
|
|
18
|
+
const key = component + nameOrSelector;
|
|
19
|
+
if (!selectors.has(key)) {
|
|
18
20
|
const parts = [
|
|
19
21
|
// Single selector
|
|
20
|
-
`[
|
|
22
|
+
`[${component}="${nameOrSelector}"]`,
|
|
21
23
|
// Selector in the middle of a list of selectors
|
|
22
|
-
`[
|
|
24
|
+
`[${component}*="${separator}${nameOrSelector}${separator}"]`,
|
|
23
25
|
// Selector at the end of a list of selectors
|
|
24
|
-
`[
|
|
26
|
+
`[${component}$="${separator}${nameOrSelector}"]`,
|
|
25
27
|
// Selector at the beginning of a list of selectors
|
|
26
|
-
`[
|
|
28
|
+
`[${component}^="${nameOrSelector}${separator}"]`
|
|
27
29
|
];
|
|
28
|
-
selectors.set(
|
|
30
|
+
selectors.set(key, parts.join(","));
|
|
29
31
|
}
|
|
30
|
-
return selectors.get(
|
|
32
|
+
return selectors.get(key);
|
|
31
33
|
}
|
|
32
34
|
function getComponentElements(nameOrSelector, element = document) {
|
|
33
35
|
const selector = getSelector(nameOrSelector);
|
|
@@ -54,14 +56,6 @@ function getEventTarget(instance, event, config) {
|
|
|
54
56
|
if (eventIsNative(event, instance.$el)) {
|
|
55
57
|
return instance.$el;
|
|
56
58
|
}
|
|
57
|
-
if (isDev) {
|
|
58
|
-
console.warn(
|
|
59
|
-
`[${config.name}]`,
|
|
60
|
-
`The "${event}" event is missing from the configuration and is not a native`,
|
|
61
|
-
`event for the root element of type \`${instance.$el.constructor.name}\`.`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return instance;
|
|
65
59
|
}
|
|
66
60
|
const instances = /* @__PURE__ */ new Set();
|
|
67
61
|
function getInstances(ctor) {
|
package/Base/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/Base/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { isArray, isDefined, isDev, SmartQueue } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown)
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,
|
|
4
|
+
"sourcesContent": ["import { isArray, isDefined, isDev, SmartQueue } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown) {\n if (features.get('blocking')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n return queue.add(fn);\n}\n\nconst selectors = new Map();\n\n// Separator used for multi-component declaration in `data-component` attributeS.\nconst separator = ' ';\n\n/**\n * Get the selector for a given component.\n */\nfunction getSelector(nameOrSelector: string): string {\n const { component } = features.get('attributes');\n const key = component + nameOrSelector;\n\n if (!selectors.has(key)) {\n const parts = [\n // Single selector\n `[${component}=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[${component}*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[${component}$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[${component}^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(key, parts.join(','));\n }\n\n return selectors.get(key);\n}\n\n/**\n * Get a list of elements based on the name of a component.\n *\n * @param {string} nameOrSelector\n * The name or selector to used for this component.\n * @param {HTMLElement|Document} element\n * The root element on which to query the selector, defaults to `document`.\n * @returns {Array<HTMLElement>}\n * A list of elements on which the component should be mounted.\n */\nexport function getComponentElements(\n nameOrSelector: string,\n element: HTMLElement | Document = document,\n): HTMLElement[] {\n const selector = getSelector(nameOrSelector);\n let elements = [];\n\n try {\n elements = Array.from(element.querySelectorAll(selector));\n // eslint-disable-next-line no-empty\n } catch {}\n\n // If no child component found with the default selector, and if the selector does not\n // start with an uppercase letter, matching a component's name, try a classic DOM selector.\n if (elements.length === 0 && nameOrSelector[0] === nameOrSelector[0].toLowerCase()) {\n elements = Array.from(element.querySelectorAll(nameOrSelector));\n }\n\n return elements;\n}\n\n/**\n * Test if an event is defined in the given config.\n */\nexport function eventIsDefinedInConfig(event: string, config: BaseConfig): boolean {\n return isArray(config.emits) && config.emits.includes(event);\n}\n\n/**\n * Test if an event can be used on the given element.\n */\nexport function eventIsNative(event: string, element: HTMLElement): boolean {\n return isDefined(element[`on${event}`]);\n}\n\n/**\n * Get the target of a given event.\n *\n * @todo Return false in v3 if event is not defined or not native to prevent adding a listener.\n */\nexport function getEventTarget(\n instance: Base,\n event: string,\n config: BaseConfig,\n): Base | Base['$el'] {\n if (eventIsDefinedInConfig(event, config)) {\n return instance;\n }\n\n if (eventIsNative(event, instance.$el)) {\n return instance.$el;\n }\n}\n\nconst instances = new Set<Base>();\n\n/**\n * Get all mounted instances or the ones from a given component.\n */\nexport function getInstances(): Set<Base>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor: T,\n): Set<InstanceType<T>>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor?: T,\n): Set<InstanceType<T>> | Set<Base> {\n if (isDefined(ctor)) {\n const filteredInstances = new Set<InstanceType<T>>();\n for (const instance of instances) {\n if (instance instanceof ctor) {\n filteredInstances.add(instance as InstanceType<T>);\n }\n }\n return filteredInstances;\n } else {\n return new Set(instances);\n }\n}\n\nexport function addInstance(instance: Base) {\n instances.add(instance);\n}\n\nexport function deleteInstance(instance: Base) {\n instances.delete(instance);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,WAAkB,kBAAkB;AAEtD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAmB;AAC5C,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,SAAO,MAAM,IAAI,EAAE;AACrB;AAEA,MAAM,YAAY,oBAAI,IAAI;AAG1B,MAAM,YAAY;AAKlB,SAAS,YAAY,gBAAgC;AACnD,QAAM,EAAE,UAAU,IAAI,SAAS,IAAI,YAAY;AAC/C,QAAM,MAAM,YAAY;AAExB,MAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACvB,UAAM,QAAQ;AAAA;AAAA,MAEZ,IAAI,SAAS,KAAK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AO;AAAA,EACT,OAAO;AACL,WAAO,IAAI,IAAI,SAAS;AAAA,EAC1B;AACF;AAEO,SAAS,YAAY,UAAgB;AAC1C,YAAU,IAAI,QAAQ;AACxB;AAEO,SAAS,eAAe,UAAgB;AAC7C,YAAU,OAAO,QAAQ;AAC3B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -55,20 +55,22 @@ function withBreakpointManager(BaseClass, breakpoints) {
|
|
|
55
55
|
* Override the default $mount method to prevent component's from being
|
|
56
56
|
* mounted when they should not.
|
|
57
57
|
*/
|
|
58
|
-
$mount() {
|
|
59
|
-
super.$mount();
|
|
58
|
+
async $mount() {
|
|
59
|
+
await super.$mount();
|
|
60
60
|
testBreakpoints(instances.get(this));
|
|
61
61
|
return this;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Destroy all instances when the main one is destroyed.
|
|
65
65
|
*/
|
|
66
|
-
$destroy() {
|
|
66
|
+
async $destroy() {
|
|
67
|
+
const promises = [];
|
|
67
68
|
if (isArray(instances.get(this))) {
|
|
68
69
|
for (const [, instance] of instances.get(this)) {
|
|
69
|
-
instance.$destroy();
|
|
70
|
+
promises.push(instance.$destroy());
|
|
70
71
|
}
|
|
71
72
|
}
|
|
73
|
+
await Promise.all(promises);
|
|
72
74
|
return super.$destroy();
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withBreakpointManager.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, isArray } from '../utils/index.js';\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n */\nfunction testBreakpoints(breakpoints: Array<[string[], Base]>) {\n const { breakpoint } = useResize().props();\n for (const [breakpointKeys, instance] of breakpoints) {\n if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {\n setTimeout(() => instance.$mount(), 0);\n } else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {\n instance.$destroy();\n }\n }\n}\n\n/**\n * Prepare the components.\n */\nfunction mountComponents(\n instance: Base,\n breakpoints: Array<[string, BaseConstructor]>,\n): Array<[string[], Base]> {\n return breakpoints.map(([bk, ComponentClass]) => {\n const child = new ComponentClass(instance.$el);\n Object.defineProperty(child, '$parent', { get: () => instance.$parent });\n return [bk.split(' '), child];\n });\n}\n\n/**\n * A cache object to hold each Base sub-instances.\n */\nconst instances: WeakMap<Base, Array<[string[], Base]>> = new WeakMap();\n\n/**\n * BreakpointManager class.\n */\nexport function withBreakpointManager<S extends Base>(\n BaseClass: typeof Base,\n breakpoints: Array<[string, BaseConstructor<Base>]>,\n): BaseDecorator<BaseInterface, S> {\n if (!isArray(breakpoints)) {\n if (isDev) {\n throw new Error('[withBreakpointManager] The `breakpoints` parameter must be an array.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n if (breakpoints.length < 2) {\n if (isDev) {\n throw new Error('[withBreakpointManager] You must define at least 2 breakpoints.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n const { add, props } = useResize();\n\n // Do nothing if no breakpoint has been defined.\n // @see https://js-toolkit.meta.fr/services/resize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error('The `BreakpointManager` class requires breakpoints to be defined.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n /**\n * Class.\n */\n class WithBreakpointManager<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (!instances.has(this)) {\n instances.set(this, mountComponents(this, breakpoints));\n }\n\n add(`BreakpointManager-${this.$id}`, () => {\n testBreakpoints(instances.get(this));\n });\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n $mount()
|
|
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C,UAAU,IAAI,IAAI,GAAG;AACxB,kBAAU,IAAI,MAAM,gBAAgB,MAAM,WAAW,CAAC;AAAA,MACxD;AAEA,UAAI,qBAAqB,KAAK,GAAG,IAAI,MAAM;AACzC,wBAAgB,UAAU,IAAI,IAAI,CAAC;AAAA,MACrC,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, isArray } from '../utils/index.js';\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n */\nfunction testBreakpoints(breakpoints: Array<[string[], Base]>) {\n const { breakpoint } = useResize().props();\n for (const [breakpointKeys, instance] of breakpoints) {\n if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {\n setTimeout(() => instance.$mount(), 0);\n } else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {\n instance.$destroy();\n }\n }\n}\n\n/**\n * Prepare the components.\n */\nfunction mountComponents(\n instance: Base,\n breakpoints: Array<[string, BaseConstructor]>,\n): Array<[string[], Base]> {\n return breakpoints.map(([bk, ComponentClass]) => {\n const child = new ComponentClass(instance.$el);\n Object.defineProperty(child, '$parent', { get: () => instance.$parent });\n return [bk.split(' '), child];\n });\n}\n\n/**\n * A cache object to hold each Base sub-instances.\n */\nconst instances: WeakMap<Base, Array<[string[], Base]>> = new WeakMap();\n\n/**\n * BreakpointManager class.\n */\nexport function withBreakpointManager<S extends Base>(\n BaseClass: typeof Base,\n breakpoints: Array<[string, BaseConstructor<Base>]>,\n): BaseDecorator<BaseInterface, S> {\n if (!isArray(breakpoints)) {\n if (isDev) {\n throw new Error('[withBreakpointManager] The `breakpoints` parameter must be an array.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n if (breakpoints.length < 2) {\n if (isDev) {\n throw new Error('[withBreakpointManager] You must define at least 2 breakpoints.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n const { add, props } = useResize();\n\n // Do nothing if no breakpoint has been defined.\n // @see https://js-toolkit.meta.fr/services/resize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error('The `BreakpointManager` class requires breakpoints to be defined.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n /**\n * Class.\n */\n class WithBreakpointManager<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (!instances.has(this)) {\n instances.set(this, mountComponents(this, breakpoints));\n }\n\n add(`BreakpointManager-${this.$id}`, () => {\n testBreakpoints(instances.get(this));\n });\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n await super.$mount();\n\n testBreakpoints(instances.get(this));\n\n return this;\n }\n\n /**\n * Destroy all instances when the main one is destroyed.\n */\n async $destroy() {\n const promises = [];\n if (isArray(instances.get(this))) {\n for (const [, instance] of instances.get(this)) {\n promises.push(instance.$destroy());\n }\n }\n\n await Promise.all(promises);\n\n return super.$destroy();\n }\n }\n\n // @ts-ignore\n return WithBreakpointManager;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,eAAe;AAK/B,SAAS,gBAAgB,aAAsC;AAC7D,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AACzC,aAAW,CAAC,gBAAgB,QAAQ,KAAK,aAAa;AACpD,QAAI,eAAe,SAAS,UAAU,KAAK,CAAC,SAAS,YAAY;AAC/D,iBAAW,MAAM,SAAS,OAAO,GAAG,CAAC;AAAA,IACvC,WAAW,CAAC,eAAe,SAAS,UAAU,KAAK,SAAS,YAAY;AACtE,eAAS,SAAS;AAAA,IACpB;AAAA,EACF;AACF;AAKA,SAAS,gBACP,UACA,aACyB;AACzB,SAAO,YAAY,IAAI,CAAC,CAAC,IAAI,cAAc,MAAM;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AAE,QAAQ,KAAK,UAAU,IAAI,IAAI,GAAG;AAC9C,mBAAS,KAAK,SAAS,SAAS,CAAC;AAAA,QACnC;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,QAAQ;AAE1B,aAAO,MAAM,SAAS;AAAA,IACxB;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useResize } from "../services/index.js";
|
|
2
2
|
import { isDev, startsWith } from "../utils/index.js";
|
|
3
|
+
import { features } from "../Base/features.js";
|
|
3
4
|
function testBreakpoints(instance, breakpoint = useResize().props().breakpoint) {
|
|
4
5
|
const { activeBreakpoints, inactiveBreakpoints } = instance.$options;
|
|
5
6
|
const isInActiveBreakpoint = activeBreakpoints && activeBreakpoints.split(" ").includes(breakpoint);
|
|
@@ -67,8 +68,9 @@ function withBreakpointObserver(BaseClass) {
|
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
const key = `BreakpointObserver-${this.$id}`;
|
|
71
|
+
const attributes = features.get("attributes");
|
|
70
72
|
const mutationObserver = new MutationObserver(([mutation]) => {
|
|
71
|
-
if (mutation.type === "attributes" &&
|
|
73
|
+
if (mutation.type === "attributes" && startsWith(mutation.attributeName, `${attributes.option}-`)) {
|
|
72
74
|
if (!hasBreakpointConfiguration(this)) {
|
|
73
75
|
this.$mount();
|
|
74
76
|
remove(key);
|
|
@@ -87,7 +89,7 @@ function withBreakpointObserver(BaseClass) {
|
|
|
87
89
|
* Override the default $mount method to prevent component's from being
|
|
88
90
|
* mounted when they should not.
|
|
89
91
|
*/
|
|
90
|
-
$mount() {
|
|
92
|
+
async $mount() {
|
|
91
93
|
if (!hasBreakpointConfiguration(this)) {
|
|
92
94
|
return super.$mount();
|
|
93
95
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withBreakpointObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\nimport { features } from '../Base/features.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {}\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n *\n * @param {Base<WithBreakpointObserverProps>} instance The component's instance.\n * @param {string} [breakpoint] The breakpoint to test.\n * @returns {string} The action to trigger.\n */\nfunction testBreakpoints(\n instance: Base<WithBreakpointObserverProps>,\n breakpoint: string = useResize().props().breakpoint,\n): string {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n const isInActiveBreakpoint =\n activeBreakpoints && activeBreakpoints.split(' ').includes(breakpoint);\n const isInInactiveBreakpoint =\n inactiveBreakpoints && inactiveBreakpoints.split(' ').includes(breakpoint);\n\n if (\n (activeBreakpoints && isInActiveBreakpoint) ||\n (inactiveBreakpoints && !isInInactiveBreakpoint)\n ) {\n return '$mount';\n }\n\n return '$destroy';\n}\n\n/**\n * Test if the given instance is configured for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {boolean} True if configured correctly, false otherwise.\n */\nfunction hasBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): boolean {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n return Boolean(activeBreakpoints || inactiveBreakpoints);\n}\n\n/**\n * Test if the given instance has a conflicting configuration for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {void}\n */\nfunction testConflictingBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): void {\n const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;\n if (activeBreakpoints && inactiveBreakpoints) {\n throw new Error(\n `[${name}] Incorrect configuration: the \\`activeBreakpoints\\` and \\`inactiveBreakpoints\\` are not compatible.`,\n );\n }\n}\n\n/**\n * Add the current instance to the resize service.\n *\n * @param {string} key The key for the resize service callback.\n * @param {Base} instance The instance to observe.\n */\nfunction addToResize(key, instance) {\n if (isDev) {\n testConflictingBreakpointConfiguration(instance);\n }\n\n const { add, has } = useResize();\n\n if (!has(key)) {\n add(key, ({ breakpoint }) => {\n const action = testBreakpoints(instance, breakpoint);\n\n // Always destroy before mounting\n if (action === '$destroy' && instance.$isMounted) {\n instance[action]();\n } else if (action === '$mount' && !instance.$isMounted) {\n setTimeout(() => instance[action](), 0);\n }\n });\n }\n}\n\n/**\n * BreakpointObserver class.\n */\nexport function withBreakpointObserver<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithBreakpointObserverInterface, S, WithBreakpointObserverProps> {\n /**\n * Class.\n */\n class WithBreakpointObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithBreakpointObserverProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithBreakpointObserver`,\n options: {\n ...BaseClass.config?.options,\n activeBreakpoints: String,\n inactiveBreakpoints: String,\n },\n };\n\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const { remove, props } = useResize();\n const { name } = this.$options;\n\n // Do nothing if no breakpoint has been defined.\n // @see https://js-toolkit.meta.fr/services/resize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error(\n `[${name}] The \\`BreakpointObserver\\` class requires breakpoints to be defined.`,\n );\n }\n return;\n }\n\n const key = `BreakpointObserver-${this.$id}`;\n const attributes = features.get('attributes');\n\n // Watch change on the `data-options` attribute to emit the `set:options` event.\n const mutationObserver = new MutationObserver(([mutation]) => {\n if (\n mutation.type === 'attributes' &&\n startsWith(mutation.attributeName, `${attributes.option}-`)\n ) {\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n this.$mount();\n remove(key);\n return;\n }\n\n addToResize(key, this);\n }\n });\n mutationObserver.observe(this.$el, { attributes: true });\n\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return;\n }\n\n addToResize(key, this);\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n // Execute normal behavior when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return super.$mount();\n }\n\n const action = testBreakpoints(this);\n if (action === '$mount') {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithBreakpointObserver;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,kBAAkB;AAClC,SAAS,gBAAgB;AAkBzB,SAAS,gBACP,UACA,aAAqB,UAAU,EAAE,MAAM,EAAE,YACjC;AACR,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,QAAM,uBACJ,qBAAqB,kBAAkB,MAAM,GAAG,EAAE,SAAS,UAAU;AACvE,QAAM,yBACJ,uBAAuB,oBAAoB,MAAM,GAAG,EAAE,SAAS,UAAU;AAE3E,MACG,qBAAqB,wBACrB,uBAAuB,CAAC,wBACzB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQA,SAAS,2BAA2B,UAAsD;AACxF,QAAM,EAAE,mBAAmB,oBAAoB,I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AAEA,YAAM,MAAM,sBAAsB,KAAK,GAAG;AAC1C,YAAM,aAAa,SAAS,IAAI,YAAY;AAG5C,YAAM,mBAAmB,IAAI,iBAAiB,CAAC,CAAC,QAAQ,MAAM;AAC5D,YACE,SAAS,SAAS,gBAClB,WAAW,SAAS,eAAe,GAAG,WAAW,MAAM,GAAG,GAC1D;AAEA,cAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,iBAAK,OAAO;AACZ,mBAAO,GAAG;AACV;AAAA,UACF;AAEA,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AACD,uBAAiB,QAAQ,KAAK,KAAK,EAAE,YAAY,KAAK,CAAC;AAGvD,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC;AAAA,MACF;AAEA,kBAAY,KAAK,IAAI;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,SAAS;AAEb,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,YAAM,SAAS,gBAAgB,IAAI;AACnC,UAAI,WAAW,UAAU;AACvB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountOnMediaQuery.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...BaseClass.config?.options,\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__matches) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,aAAa;AAmBf,SAAS,sBACd,WACA,OAC8E;AAAA,EAI9E,MAAM,8BAA+D,UAEnE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAG,UAAU,QAAQ;AAAA,QACrB,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOZ,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,SAAS,CAAC,KAAK,SAAS,SAAS,CAAC,OAAO;AAC3C,aAAK;AAAA,UACH;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB,OAAO,WAAW,KAAK,SAAS,SAAS,KAAK;AAGrE,WAAK,YAAY,eAAe;AAEhC,YAAM,gBAAgB,CAAC,UAA+B;AACpD,aAAK,YAAY,MAAM;AAEvB,YAAI,MAAM,WAAW,CAAC,KAAK,YAAY;AACrC,eAAK,OAAO;AAAA,QACd,WAAW,KAAK,YAAY;AAC1B,qBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,QAClC;AAAA,MACF;AAGA,qBAAe,iBAAiB,UAAU,aAAa;AAEvD,WAAK,IAAI,cAAc,MAAM;AAC3B,uBAAe,oBAAoB,UAAU,aAAa;AAAA,MAC5D,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...BaseClass.config?.options,\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__matches) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,aAAa;AAmBf,SAAS,sBACd,WACA,OAC8E;AAAA,EAI9E,MAAM,8BAA+D,UAEnE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAG,UAAU,QAAQ;AAAA,QACrB,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOZ,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,SAAS,CAAC,KAAK,SAAS,SAAS,CAAC,OAAO;AAC3C,aAAK;AAAA,UACH;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB,OAAO,WAAW,KAAK,SAAS,SAAS,KAAK;AAGrE,WAAK,YAAY,eAAe;AAEhC,YAAM,gBAAgB,CAAC,UAA+B;AACpD,aAAK,YAAY,MAAM;AAEvB,YAAI,MAAM,WAAW,CAAC,KAAK,YAAY;AACrC,eAAK,OAAO;AAAA,QACd,WAAW,KAAK,YAAY;AAC1B,qBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,QAClC;AAAA,MACF;AAGA,qBAAe,iBAAiB,UAAU,aAAa;AAEvD,WAAK,IAAI,cAAc,MAAM;AAC3B,uBAAe,oBAAoB,UAAU,aAAa;AAAA,MAC5D,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,SAAS;AACb,UAAI,KAAK,WAAW;AAClB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -55,9 +55,9 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
55
55
|
/**
|
|
56
56
|
* Override the mounting of the component.
|
|
57
57
|
*/
|
|
58
|
-
$mount() {
|
|
58
|
+
async $mount() {
|
|
59
59
|
if (this.__isVisible) {
|
|
60
|
-
super.$mount();
|
|
60
|
+
return super.$mount();
|
|
61
61
|
}
|
|
62
62
|
return this;
|
|
63
63
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountWhenInView.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...BaseClass.config?.options,\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
-
"mappings": "AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;AAAA,EAI1E,MAAM,4BAA6D,UAEjE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAG,UAAU,QAAQ;AAAA,QACrB,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,aAAa,IAAI;AAAA,QACpB,CAAC,YAAY;AACX,gBAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,UAAU,OAAO,MAAM,gBAAgB,KAAK;AACnF,cAAI,KAAK,gBAAgB,WAAW;AAClC,iBAAK,cAAc;AAEnB,gBAAI,WAAW;AACb,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,YAClC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SACN;AAAA,QACL;AAAA,MACF;AAEA,WAAK,WAAW,QAAQ,KAAK,GAAG;AAEhC,WAAK,IAAI,cAAc,MAAM;AAC3B,aAAK,WAAW,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...BaseClass.config?.options,\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__isVisible) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
+
"mappings": "AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;AAAA,EAI1E,MAAM,4BAA6D,UAEjE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAG,UAAU,QAAQ;AAAA,QACrB,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,aAAa,IAAI;AAAA,QACpB,CAAC,YAAY;AACX,gBAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,UAAU,OAAO,MAAM,gBAAgB,KAAK;AACnF,cAAI,KAAK,gBAAgB,WAAW;AAClC,iBAAK,cAAc;AAEnB,gBAAI,WAAW;AACb,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,YAClC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SACN;AAAA,QACL;AAAA,MACF;AAEA,WAAK,WAAW,QAAQ,KAAK,GAAG;AAEhC,WAAK,IAAI,cAAc,MAAM;AAC3B,aAAK,WAAW,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,SAAS;AACb,UAAI,KAAK,aAAa;AACpB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.js
CHANGED
|
@@ -5,7 +5,8 @@ function createApp(App, options = {}) {
|
|
|
5
5
|
const {
|
|
6
6
|
root = document.body,
|
|
7
7
|
breakpoints = null,
|
|
8
|
-
blocking = null
|
|
8
|
+
blocking = null,
|
|
9
|
+
attributes = null
|
|
9
10
|
} = options instanceof HTMLElement ? { root: options } : options;
|
|
10
11
|
if (isObject(breakpoints)) {
|
|
11
12
|
features.set("breakpoints", breakpoints);
|
|
@@ -13,13 +14,17 @@ function createApp(App, options = {}) {
|
|
|
13
14
|
if (isBoolean(blocking)) {
|
|
14
15
|
features.set("blocking", blocking);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
if (isObject(attributes)) {
|
|
18
|
+
features.set("attributes", attributes);
|
|
19
|
+
}
|
|
20
|
+
async function init() {
|
|
21
|
+
app = new App(root);
|
|
22
|
+
await app.$mount();
|
|
18
23
|
return app;
|
|
19
24
|
}
|
|
20
25
|
let p;
|
|
21
26
|
if (features.get("blocking")) {
|
|
22
|
-
p =
|
|
27
|
+
p = init();
|
|
23
28
|
} else {
|
|
24
29
|
p = new Promise((resolve) => {
|
|
25
30
|
if (document.readyState === "complete") {
|
package/helpers/createApp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isBoolean, isObject } from '../utils/index.js';\n\nexport type CreateAppOptions = Partial<Features> & {\n root?: HTMLElement;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n options: HTMLElement | CreateAppOptions = {},\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const {\n root = document.body,\n breakpoints = null,\n blocking = null,\n } = options instanceof HTMLElement ? { root: options } : options;\n\n if (isObject(breakpoints)) {\n features.set('breakpoints', breakpoints);\n }\n\n if (isBoolean(blocking)) {\n features.set('blocking', blocking);\n }\n\n function init() {\n app = (new App(root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('blocking')) {\n p =
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,WAAW,gBAAgB;AAUrB,SAAR,UACL,KACA,UAA0C,CAAC,GACf;AAC5B,MAAI;AACJ,QAAM;AAAA,IACJ,OAAO,SAAS;AAAA,IAChB,cAAc;AAAA,IACd,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isBoolean, isObject } from '../utils/index.js';\n\nexport type CreateAppOptions = Partial<Features> & {\n root?: HTMLElement;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n options: HTMLElement | CreateAppOptions = {},\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const {\n root = document.body,\n breakpoints = null,\n blocking = null,\n attributes = null,\n } = options instanceof HTMLElement ? { root: options } : options;\n\n if (isObject(breakpoints)) {\n features.set('breakpoints', breakpoints);\n }\n\n if (isBoolean(blocking)) {\n features.set('blocking', blocking);\n }\n\n if (isObject(attributes)) {\n features.set('attributes', attributes);\n }\n\n async function init() {\n app = (new App(root) as S & Base<T>)\n await app.$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('blocking')) {\n p = init();\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,WAAW,gBAAgB;AAUrB,SAAR,UACL,KACA,UAA0C,CAAC,GACf;AAC5B,MAAI;AACJ,QAAM;AAAA,IACJ,OAAO,SAAS;AAAA,IAChB,cAAc;AAAA,IACd,WAAW;AAAA,IACX,aAAa;AAAA,EACf,IAAI,mBAAmB,cAAc,EAAE,MAAM,QAAQ,IAAI;AAEzD,MAAI,SAAS,WAAW,GAAG;AACzB,aAAS,IAAI,eAAe,WAAW;AAAA,EACzC;AAEA,MAAI,UAAU,QAAQ,GAAG;AACvB,aAAS,IAAI,YAAY,QAAQ;AAAA,EACnC;AAEA,MAAI,SAAS,UAAU,GAAG;AACxB,aAAS,IAAI,cAAc,UAAU;AAAA,EACvC;AAEA,iBAAe,OAAO;AACpB,UAAO,IAAI,IAAI,IAAI;AACnB,UAAM,IAAI,OAAO;AACjB,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,QAAI,KAAK;AAAA,EACX,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
package/utils/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport * from './trapFocus.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { nextTick } from './nextTick.js';\nexport { nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { scrollTo } from './scrollTo.js';\nexport { default as getComponentResolver } from './getComponentResolver.js';\nexport * from './is.js';\nexport * from './has.js';\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport { SmartQueue } from './SmartQueue.js';\nexport * from './dom/index.js';\nexport * from './wait.js';\nexport * from './random.js';\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAoB,WAAXA,gBAA2B;AACpC,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAuC;AAChD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport * from './trapFocus.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { nextTick } from './nextTick.js';\nexport { nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { scrollTo } from './scrollTo.js';\nexport { default as getComponentResolver } from './getComponentResolver.js';\nexport * from './is.js';\nexport * from './has.js';\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport { SmartQueue } from './SmartQueue.js';\nexport * from './dom/index.js';\nexport * from './wait.js';\nexport * from './random.js';\nexport * from './memo.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAoB,WAAXA,gBAA2B;AACpC,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAuC;AAChD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/utils/memo.d.ts
ADDED
package/utils/memo.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function memo(fn) {
|
|
2
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3
|
+
return function cached(...args) {
|
|
4
|
+
const key = args.join("");
|
|
5
|
+
if (!cache.has(key)) {
|
|
6
|
+
cache.set(key, fn(...args));
|
|
7
|
+
}
|
|
8
|
+
return cache.get(key);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
memo
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/memo.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Memoize the result of a function with a single argument indefinitely.\n * This is a simpler implementation of the `memoize` function.\n */\nexport function memo<T extends (...args: unknown[]) => unknown>(fn: T): T {\n const cache = new Map<string, ReturnType<T>>();\n\n // @ts-ignore\n return function cached(...args) {\n const key = args.join('');\n if (!cache.has(key)) {\n cache.set(key, fn(...args) as ReturnType<T>);\n }\n return cache.get(key);\n };\n}\n"],
|
|
5
|
+
"mappings": "AAIO,SAAS,KAAgD,IAAU;AACxE,QAAM,QAAQ,oBAAI,IAA2B;AAG7C,SAAO,SAAS,UAAU,MAAM;AAC9B,UAAM,MAAM,KAAK,KAAK,EAAE;AACxB,QAAI,CAAC,MAAM,IAAI,GAAG,GAAG;AACnB,YAAM,IAAI,KAAK,GAAG,GAAG,IAAI,CAAkB;AAAA,IAC7C;AACA,WAAO,MAAM,IAAI,GAAG;AAAA,EACtB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a string to lowercase.
|
|
3
|
+
*/
|
|
4
|
+
export declare function lowerCase(string: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Convert a string to UPPERCASE.
|
|
7
|
+
*/
|
|
8
|
+
export declare function upperCase(string: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert a string to camelCase.
|
|
11
|
+
*/
|
|
12
|
+
export declare const camelCase: (string: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Convert a string to PascalCase.
|
|
15
|
+
*/
|
|
16
|
+
export declare const pascalCase: (string: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Convert a string to snake_case.
|
|
19
|
+
*/
|
|
20
|
+
export declare const snakeCase: (string: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Convert a string to dash-case.
|
|
23
|
+
*/
|
|
24
|
+
export declare const dashCase: (string: string) => string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { memo } from "../memo.js";
|
|
2
|
+
const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
3
|
+
const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
4
|
+
const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
5
|
+
const SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
6
|
+
function split(value) {
|
|
7
|
+
let result = value.trim();
|
|
8
|
+
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
9
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
10
|
+
let start = 0;
|
|
11
|
+
let end = result.length;
|
|
12
|
+
while (result.charAt(start) === "\0") start++;
|
|
13
|
+
if (start === end) return [];
|
|
14
|
+
while (result.charAt(end - 1) === "\0") end--;
|
|
15
|
+
return result.slice(start, end).split(/\0/g);
|
|
16
|
+
}
|
|
17
|
+
function delimitedCase(string, delimiter) {
|
|
18
|
+
return split(string).map((word) => lowerCase(word)).join(delimiter);
|
|
19
|
+
}
|
|
20
|
+
function lowerCase(string) {
|
|
21
|
+
return string.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
function upperCase(string) {
|
|
24
|
+
return string.toUpperCase();
|
|
25
|
+
}
|
|
26
|
+
const camelCase = memo(function camelCase2(string) {
|
|
27
|
+
const result = pascalCase(string);
|
|
28
|
+
return lowerCase(result[0]) + result.slice(1);
|
|
29
|
+
});
|
|
30
|
+
const pascalCase = memo(function pascalCase2(string) {
|
|
31
|
+
return split(string).map((word) => upperCase(word[0]) + lowerCase(word.slice(1))).join("");
|
|
32
|
+
});
|
|
33
|
+
const snakeCase = memo(function snakeCase2(string) {
|
|
34
|
+
return delimitedCase(string, "_");
|
|
35
|
+
});
|
|
36
|
+
const dashCase = memo(function dashCase2(string) {
|
|
37
|
+
return delimitedCase(string, "-");
|
|
38
|
+
});
|
|
39
|
+
export {
|
|
40
|
+
camelCase,
|
|
41
|
+
dashCase,
|
|
42
|
+
lowerCase,
|
|
43
|
+
pascalCase,
|
|
44
|
+
snakeCase,
|
|
45
|
+
upperCase
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=changeCase.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/string/changeCase.ts"],
|
|
4
|
+
"sourcesContent": ["import { memo } from '../memo.js';\n\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\nconst SPLIT_REPLACE_VALUE = '$1\\0$2';\n\n/**\n * Split function from the `change-case` package.\n * @see https://github.com/blakeembrey/change-case\n */\nfunction split(value: string) {\n let result = value.trim();\n\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n\n result = result.replace(DEFAULT_STRIP_REGEXP, '\\0');\n\n let start = 0;\n let end = result.length;\n\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === '\\0') start++;\n if (start === end) return [];\n while (result.charAt(end - 1) === '\\0') end--;\n\n return result.slice(start, end).split(/\\0/g);\n}\n\n/**\n * Convert a string to lowercase and join each word with the given delimiter.\n */\nfunction delimitedCase(string: string, delimiter: string): string {\n return split(string)\n .map((word) => lowerCase(word))\n .join(delimiter);\n}\n/**\n * Convert a string to lowercase.\n */\nexport function lowerCase(string: string): string {\n return string.toLowerCase();\n}\n\n/**\n * Convert a string to UPPERCASE.\n */\nexport function upperCase(string: string): string {\n return string.toUpperCase();\n}\n\n/**\n * Convert a string to camelCase.\n */\nexport const camelCase = memo(function camelCase(string: string): string {\n const result = pascalCase(string);\n return lowerCase(result[0]) + result.slice(1);\n});\n\n/**\n * Convert a string to PascalCase.\n */\nexport const pascalCase = memo(function pascalCase(string: string): string {\n return split(string)\n .map((word) => upperCase(word[0]) + lowerCase(word.slice(1)))\n .join('');\n});\n\n/**\n * Convert a string to snake_case.\n */\nexport const snakeCase = memo(function snakeCase(string: string): string {\n return delimitedCase(string, '_');\n});\n\n/**\n * Convert a string to dash-case.\n */\nexport const dashCase = memo(function dashCase(string: string): string {\n return delimitedCase(string, '-');\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY;AAErB,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AAM5B,SAAS,MAAM,OAAe;AAC5B,MAAI,SAAS,MAAM,KAAK;AAExB,WAAS,OACN,QAAQ,sBAAsB,mBAAmB,EACjD,QAAQ,sBAAsB,mBAAmB;AAEpD,WAAS,OAAO,QAAQ,sBAAsB,IAAI;AAElD,MAAI,QAAQ;AACZ,MAAI,MAAM,OAAO;AAGjB,SAAO,OAAO,OAAO,KAAK,MAAM,KAAM;AACtC,MAAI,UAAU,IAAK,QAAO,CAAC;AAC3B,SAAO,OAAO,OAAO,MAAM,CAAC,MAAM,KAAM;AAExC,SAAO,OAAO,MAAM,OAAO,GAAG,EAAE,MAAM,KAAK;AAC7C;AAKA,SAAS,cAAc,QAAgB,WAA2B;AAChE,SAAO,MAAM,MAAM,EAChB,IAAI,CAAC,SAAS,UAAU,IAAI,CAAC,EAC7B,KAAK,SAAS;AACnB;AAIO,SAAS,UAAU,QAAwB;AAChD,SAAO,OAAO,YAAY;AAC5B;AAKO,SAAS,UAAU,QAAwB;AAChD,SAAO,OAAO,YAAY;AAC5B;AAKO,MAAM,YAAY,KAAK,SAASA,WAAU,QAAwB;AACvE,QAAM,SAAS,WAAW,MAAM;AAChC,SAAO,UAAU,OAAO,CAAC,CAAC,IAAI,OAAO,MAAM,CAAC;AAC9C,CAAC;AAKM,MAAM,aAAa,KAAK,SAASC,YAAW,QAAwB;AACzE,SAAO,MAAM,MAAM,EAChB,IAAI,CAAC,SAAS,UAAU,KAAK,CAAC,CAAC,IAAI,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,EAC3D,KAAK,EAAE;AACZ,CAAC;AAKM,MAAM,YAAY,KAAK,SAASC,WAAU,QAAwB;AACvE,SAAO,cAAc,QAAQ,GAAG;AAClC,CAAC;AAKM,MAAM,WAAW,KAAK,SAASC,UAAS,QAAwB;AACrE,SAAO,cAAc,QAAQ,GAAG;AAClC,CAAC;",
|
|
6
|
+
"names": ["camelCase", "pascalCase", "snakeCase", "dashCase"]
|
|
7
|
+
}
|
package/utils/string/index.d.ts
CHANGED
package/utils/string/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { default as default10 } from "./withTrailingCharacters.js";
|
|
|
10
10
|
import { default as default11 } from "./withTrailingSlash.js";
|
|
11
11
|
export * from "./startsWith.js";
|
|
12
12
|
export * from "./endsWith.js";
|
|
13
|
+
export * from "./changeCase.js";
|
|
13
14
|
export {
|
|
14
15
|
default2 as withLeadingCharacters,
|
|
15
16
|
default3 as withLeadingSlash,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/string/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as withLeadingCharacters } from './withLeadingCharacters.js';\nexport { default as withLeadingSlash } from './withLeadingSlash.js';\nexport { default as withoutLeadingCharacters } from './withoutLeadingCharacters.js';\nexport { default as withoutLeadingCharactersRecursive } from './withoutLeadingCharactersRecursive.js';\nexport { default as withoutLeadingSlash } from './withoutLeadingSlash.js';\nexport { default as withoutTrailingCharacters } from './withoutTrailingCharacters.js';\nexport { default as withoutTrailingCharactersRecursive } from './withoutTrailingCharactersRecursive.js';\nexport { default as withoutTrailingSlash } from './withoutTrailingSlash.js';\nexport { default as withTrailingCharacters } from './withTrailingCharacters.js';\nexport { default as withTrailingSlash } from './withTrailingSlash.js';\nexport * from './startsWith.js';\nexport * from './endsWith.js';\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAAwC;AACjD,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAA2C;AACpD,SAAoB,WAAXA,gBAAoD;AAC7D,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAA4C;AACrD,SAAoB,WAAXA,gBAAqD;AAC9D,SAAoB,WAAXA,gBAAuC;AAChD,SAAoB,WAAXA,iBAAyC;AAClD,SAAoB,WAAXA,iBAAoC;AAC7C,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export { default as withLeadingCharacters } from './withLeadingCharacters.js';\nexport { default as withLeadingSlash } from './withLeadingSlash.js';\nexport { default as withoutLeadingCharacters } from './withoutLeadingCharacters.js';\nexport { default as withoutLeadingCharactersRecursive } from './withoutLeadingCharactersRecursive.js';\nexport { default as withoutLeadingSlash } from './withoutLeadingSlash.js';\nexport { default as withoutTrailingCharacters } from './withoutTrailingCharacters.js';\nexport { default as withoutTrailingCharactersRecursive } from './withoutTrailingCharactersRecursive.js';\nexport { default as withoutTrailingSlash } from './withoutTrailingSlash.js';\nexport { default as withTrailingCharacters } from './withTrailingCharacters.js';\nexport { default as withTrailingSlash } from './withTrailingSlash.js';\nexport * from './startsWith.js';\nexport * from './endsWith.js';\nexport * from './changeCase.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAAwC;AACjD,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAA2C;AACpD,SAAoB,WAAXA,gBAAoD;AAC7D,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAA4C;AACrD,SAAoB,WAAXA,gBAAqD;AAC9D,SAAoB,WAAXA,gBAAuC;AAChD,SAAoB,WAAXA,iBAAyC;AAClD,SAAoB,WAAXA,iBAAoC;AAC7C,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../packages/js-toolkit/Base/managers/ActionManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { AbstractManager } from './AbstractManager.js';\n\nexport class ActionManager extends AbstractManager {\n registerAll() {\n this.__element.querySelectorAll('[data-on]');\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAEzB,MAAM,sBAAsB,gBAAgB;AAAA,EACjD,cAAc;AACZ,SAAK,UAAU,iBAAiB,WAAW;AAAA,EAC7C;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|