@neovici/cosmoz-utils 6.22.0 → 6.22.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.
@@ -0,0 +1,17 @@
1
+ type UsePersistResult = {
2
+ value: string;
3
+ setValue: (value: string) => void;
4
+ revalidate: () => string;
5
+ };
6
+ /**
7
+ * Hook to persist a string property to localStorage with cross-tab sync.
8
+ * Uses useProperty internally to make the value reactive to parent prop changes.
9
+ * When key is undefined, acts like a regular useProperty.
10
+ *
11
+ * @param property - property name on the host element
12
+ * @param key - localStorage key (if undefined, persistence is disabled)
13
+ * @param defaultValue - fallback value when no stored value exists
14
+ * @returns { value, setValue, revalidate }
15
+ */
16
+ export declare const usePersist: (property: string, key: string | undefined, defaultValue: string) => UsePersistResult;
17
+ export {};
@@ -0,0 +1,62 @@
1
+ import { useCallback, useEffect, useProperty } from '@pionjs/pion';
2
+ /**
3
+ * Hook to persist a string property to localStorage with cross-tab sync.
4
+ * Uses useProperty internally to make the value reactive to parent prop changes.
5
+ * When key is undefined, acts like a regular useProperty.
6
+ *
7
+ * @param property - property name on the host element
8
+ * @param key - localStorage key (if undefined, persistence is disabled)
9
+ * @param defaultValue - fallback value when no stored value exists
10
+ * @returns { value, setValue, revalidate }
11
+ */
12
+ export const usePersist = (property, key, defaultValue) => {
13
+ const [value, setValue] = useProperty(property, () => {
14
+ if (!key)
15
+ return defaultValue;
16
+ try {
17
+ return localStorage.getItem(key) ?? defaultValue;
18
+ }
19
+ catch {
20
+ return defaultValue;
21
+ }
22
+ });
23
+ // Cross-tab sync via storage events (different browser windows)
24
+ useEffect(() => {
25
+ if (!key)
26
+ return;
27
+ const handleStorage = (e) => {
28
+ if (e.key === key && e.newValue) {
29
+ setValue(e.newValue);
30
+ }
31
+ };
32
+ window.addEventListener('storage', handleStorage);
33
+ return () => window.removeEventListener('storage', handleStorage);
34
+ }, [key]);
35
+ const setPersistedValue = useCallback((newValue) => {
36
+ setValue(newValue);
37
+ if (key) {
38
+ try {
39
+ localStorage.setItem(key, newValue);
40
+ }
41
+ catch {
42
+ // Silently fail
43
+ }
44
+ }
45
+ }, [key]);
46
+ const revalidate = useCallback(() => {
47
+ if (!key)
48
+ return value;
49
+ try {
50
+ const stored = localStorage.getItem(key);
51
+ if (stored != null && stored !== value) {
52
+ setValue(stored);
53
+ return stored;
54
+ }
55
+ }
56
+ catch {
57
+ // Ignore
58
+ }
59
+ return value;
60
+ }, [key, value]);
61
+ return { value, setValue: setPersistedValue, revalidate };
62
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "6.22.0",
3
+ "version": "6.22.1",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -30,18 +30,8 @@
30
30
  "start": "wds",
31
31
  "test": "wtr --coverage",
32
32
  "test:watch": "wtr --watch",
33
- "prepare": "husky install"
34
- },
35
- "release": {
36
- "plugins": [
37
- "@semantic-release/commit-analyzer",
38
- "@semantic-release/release-notes-generator",
39
- "@semantic-release/changelog",
40
- "@semantic-release/github",
41
- "@semantic-release/npm",
42
- "@semantic-release/git"
43
- ],
44
- "branch": "master"
33
+ "prepare": "husky install",
34
+ "changeset": "changeset"
45
35
  },
46
36
  "publishConfig": {
47
37
  "access": "public"
@@ -73,20 +63,18 @@
73
63
  "@pionjs/pion": "^2.7.1"
74
64
  },
75
65
  "devDependencies": {
66
+ "@changesets/cli": "^2.27.0",
76
67
  "@commitlint/cli": "^19.0.0",
77
68
  "@commitlint/config-conventional": "^19.0.0",
78
69
  "@neovici/cfg": "^2.13.0",
79
70
  "@open-wc/testing": "^4.0.0",
80
- "@playwright/test": "^1.60.0",
71
+ "@playwright/test": "1.60.0",
81
72
  "@polymer/polymer": "^3.3.1",
82
- "@semantic-release/changelog": "^6.0.0",
83
- "@semantic-release/git": "^10.0.0",
84
73
  "@types/mocha": "^10.0.3",
85
74
  "@web/test-runner-playwright": "^0.11.1",
86
75
  "husky": "^8.0.0",
87
76
  "lint-staged": "^16.2.7",
88
77
  "lit-html": "^2.0.0 || ^3.0.0",
89
- "semantic-release": "^25.0.2",
90
78
  "sinon": "^19.0.0"
91
79
  }
92
80
  }