ingeniuscliq-core 0.4.30 → 0.5.0

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.
@@ -1,5 +1,6 @@
1
1
  export * from './use-mobile';
2
2
  export * from './useLanguage';
3
3
  export * from './useNotification';
4
+ export * from './useDocumentMeta';
4
5
  export * from '../modules/registry/hooks/index';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Hook to update document title and favicon based on store settings
3
+ */
4
+ export declare function useDocumentMeta(): void;
5
+ //# sourceMappingURL=useDocumentMeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDocumentMeta.d.ts","sourceRoot":"","sources":["../../src/hooks/useDocumentMeta.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,eAAe,SAmC9B"}
@@ -0,0 +1,32 @@
1
+ import { useEffect } from 'react';
2
+ import { useCustomizationStore } from '../stores/customizationStore.js';
3
+ import { useShallow } from '../node_modules/zustand/esm/react/shallow.js';
4
+
5
+ function useDocumentMeta() {
6
+ const { settings } = useCustomizationStore(
7
+ useShallow((state) => ({
8
+ settings: state.settings
9
+ }))
10
+ );
11
+ useEffect(() => {
12
+ if (!settings) return;
13
+ if (settings.store_name) {
14
+ document.title = settings.store_name;
15
+ }
16
+ if (settings.store_favicon) {
17
+ const existingFavicons = document.querySelectorAll('link[rel*="icon"]');
18
+ existingFavicons.forEach((favicon) => favicon.remove());
19
+ const link = document.createElement("link");
20
+ link.rel = "icon";
21
+ link.type = "image/x-icon";
22
+ link.href = settings.store_favicon;
23
+ document.head.appendChild(link);
24
+ const appleTouchIcon = document.createElement("link");
25
+ appleTouchIcon.rel = "apple-touch-icon";
26
+ appleTouchIcon.href = settings.store_favicon;
27
+ document.head.appendChild(appleTouchIcon);
28
+ }
29
+ }, [settings]);
30
+ }
31
+
32
+ export { useDocumentMeta };
package/dist/index.js CHANGED
@@ -76,6 +76,7 @@ export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './comp
76
76
  export { useIsMobile } from './hooks/use-mobile.js';
77
77
  export { useLanguage } from './hooks/useLanguage.js';
78
78
  export { useNotify } from './hooks/useNotification.js';
79
+ export { useDocumentMeta } from './hooks/useDocumentMeta.js';
79
80
  export { useAuth } from './modules/CoreAuth/hooks/useAuth.js';
80
81
  /* empty css */
81
82
  import './modules/CoreAuth/index.js';
@@ -0,0 +1,12 @@
1
+ import React__default from 'react';
2
+ import { shallow } from '../vanilla/shallow.js';
3
+
4
+ function useShallow(selector) {
5
+ const prev = React__default.useRef(void 0);
6
+ return (state) => {
7
+ const next = selector(state);
8
+ return shallow(prev.current, next) ? prev.current : prev.current = next;
9
+ };
10
+ }
11
+
12
+ export { useShallow };
@@ -0,0 +1,55 @@
1
+ const isIterable = (obj) => Symbol.iterator in obj;
2
+ const hasIterableEntries = (value) => (
3
+ // HACK: avoid checking entries type
4
+ "entries" in value
5
+ );
6
+ const compareEntries = (valueA, valueB) => {
7
+ const mapA = valueA instanceof Map ? valueA : new Map(valueA.entries());
8
+ const mapB = valueB instanceof Map ? valueB : new Map(valueB.entries());
9
+ if (mapA.size !== mapB.size) {
10
+ return false;
11
+ }
12
+ for (const [key, value] of mapA) {
13
+ if (!Object.is(value, mapB.get(key))) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ };
19
+ const compareIterables = (valueA, valueB) => {
20
+ const iteratorA = valueA[Symbol.iterator]();
21
+ const iteratorB = valueB[Symbol.iterator]();
22
+ let nextA = iteratorA.next();
23
+ let nextB = iteratorB.next();
24
+ while (!nextA.done && !nextB.done) {
25
+ if (!Object.is(nextA.value, nextB.value)) {
26
+ return false;
27
+ }
28
+ nextA = iteratorA.next();
29
+ nextB = iteratorB.next();
30
+ }
31
+ return !!nextA.done && !!nextB.done;
32
+ };
33
+ function shallow(valueA, valueB) {
34
+ if (Object.is(valueA, valueB)) {
35
+ return true;
36
+ }
37
+ if (typeof valueA !== "object" || valueA === null || typeof valueB !== "object" || valueB === null) {
38
+ return false;
39
+ }
40
+ if (Object.getPrototypeOf(valueA) !== Object.getPrototypeOf(valueB)) {
41
+ return false;
42
+ }
43
+ if (isIterable(valueA) && isIterable(valueB)) {
44
+ if (hasIterableEntries(valueA) && hasIterableEntries(valueB)) {
45
+ return compareEntries(valueA, valueB);
46
+ }
47
+ return compareIterables(valueA, valueB);
48
+ }
49
+ return compareEntries(
50
+ { entries: () => Object.entries(valueA) },
51
+ { entries: () => Object.entries(valueB) }
52
+ );
53
+ }
54
+
55
+ export { shallow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeniuscliq-core",
3
- "version": "0.4.30",
3
+ "version": "0.5.0",
4
4
  "description": "IngeniusCliq Core UI y lógica compartida",
5
5
  "license": "MIT",
6
6
  "type": "module",