@sneat/core 0.5.0 → 0.5.2

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,44 @@
1
+ const CURRENT_SPACE_STORAGE_KEY = 'sneat.currentSpace';
2
+ /** Persists the user's current space so it can be restored after login. */
3
+ export function writeCurrentSpace(space) {
4
+ if (!space.id || !space.type) {
5
+ return;
6
+ }
7
+ try {
8
+ localStorage.setItem(CURRENT_SPACE_STORAGE_KEY, JSON.stringify({ id: space.id, type: space.type }));
9
+ }
10
+ catch {
11
+ // Ignore storage errors (e.g. disabled/full storage in private mode).
12
+ }
13
+ }
14
+ /** Clears the persisted current space (e.g. when the user leaves all spaces). */
15
+ export function clearCurrentSpace() {
16
+ try {
17
+ localStorage.removeItem(CURRENT_SPACE_STORAGE_KEY);
18
+ }
19
+ catch {
20
+ // Ignore storage errors (e.g. disabled storage in private mode).
21
+ }
22
+ }
23
+ /** Reads the persisted current space, or undefined when none/invalid. */
24
+ export function readCurrentSpace() {
25
+ try {
26
+ const value = localStorage.getItem(CURRENT_SPACE_STORAGE_KEY);
27
+ if (!value) {
28
+ return undefined;
29
+ }
30
+ const parsed = JSON.parse(value);
31
+ return parsed.id && parsed.type
32
+ ? { id: parsed.id, type: parsed.type }
33
+ : undefined;
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ }
39
+ /** Router path for the persisted current space, or undefined when none. */
40
+ export function currentSpacePath() {
41
+ const space = readCurrentSpace();
42
+ return space ? `/space/${space.type}/${space.id}` : undefined;
43
+ }
44
+ //# sourceMappingURL=current-space-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-space-storage.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/current-space-storage.ts"],"names":[],"mappings":"AAGA,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AAEvD,2EAA2E;AAC3E,MAAM,UAAU,iBAAiB,CAAC,KAAgB;IAChD,IAAI,CAAC,KAAK,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ChE,CAAC","sourcesContent":["import { ISpaceRef } from './interfaces';\nimport { SpaceType } from './team-type';\n\nconst CURRENT_SPACE_STORAGE_KEY = 'sneat.currentSpace';\n\n/** Persists the user's current space so it can be restored after login. */\nexport function writeCurrentSpace(space: ISpaceRef): void {\n if (!space.id || !space.type) {\n return;\n }\n try {\n localStorage.setItem(\n CURRENT_SPACE_STORAGE_KEY,\n JSON.stringify({ id: space.id, type: space.type }),\n );\n } catch {\n // Ignore storage errors (e.g. disabled/full storage in private mode).\n }\n}\n\n/** Clears the persisted current space (e.g. when the user leaves all spaces). */\nexport function clearCurrentSpace(): void {\n try {\n localStorage.removeItem(CURRENT_SPACE_STORAGE_KEY);\n } catch {\n // Ignore storage errors (e.g. disabled storage in private mode).\n }\n}\n\n/** Reads the persisted current space, or undefined when none/invalid. */\nexport function readCurrentSpace(): ISpaceRef | undefined {\n try {\n const value = localStorage.getItem(CURRENT_SPACE_STORAGE_KEY);\n if (!value) {\n return undefined;\n }\n const parsed = JSON.parse(value) as Partial<ISpaceRef>;\n return parsed.id && parsed.type\n ? { id: parsed.id, type: parsed.type as SpaceType }\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Router path for the persisted current space, or undefined when none. */\nexport function currentSpacePath(): string | undefined {\n const space = readCurrentSpace();\n return space ? `/space/${space.type}/${space.id}` : undefined;\n}\n"]}
@@ -15,6 +15,7 @@ export * from './form-field';
15
15
  export * from './team-type';
16
16
  export * from './location-href';
17
17
  export * from './interfaces';
18
+ export * from './current-space-storage';
18
19
  export * from './directives';
19
20
  export * from './environment-config';
20
21
  export * from './logging/interfaces';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './animations';\nexport * from './app.service';\nexport * from './core-models';\nexport * from './nav';\nexport * from './store';\nexport * from './sneat-enum-keys';\nexport * from './services';\nexport * from './exclude-undefined';\nexport * from './logging';\nexport * from './utils';\nexport * from './eq';\nexport * from './types';\nexport * from './sneat-extensions';\nexport * from './form-field';\nexport * from './team-type';\nexport * from './location-href';\nexport * from './interfaces';\nexport * from './directives';\nexport * from './environment-config';\nexport * from './logging/interfaces';\nexport * from './analytics.interface';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './animations';\nexport * from './app.service';\nexport * from './core-models';\nexport * from './nav';\nexport * from './store';\nexport * from './sneat-enum-keys';\nexport * from './services';\nexport * from './exclude-undefined';\nexport * from './logging';\nexport * from './utils';\nexport * from './eq';\nexport * from './types';\nexport * from './sneat-extensions';\nexport * from './form-field';\nexport * from './team-type';\nexport * from './location-href';\nexport * from './interfaces';\nexport * from './current-space-storage';\nexport * from './directives';\nexport * from './environment-config';\nexport * from './logging/interfaces';\nexport * from './analytics.interface';\n"]}
@@ -0,0 +1,9 @@
1
+ import { ISpaceRef } from './interfaces';
2
+ /** Persists the user's current space so it can be restored after login. */
3
+ export declare function writeCurrentSpace(space: ISpaceRef): void;
4
+ /** Clears the persisted current space (e.g. when the user leaves all spaces). */
5
+ export declare function clearCurrentSpace(): void;
6
+ /** Reads the persisted current space, or undefined when none/invalid. */
7
+ export declare function readCurrentSpace(): ISpaceRef | undefined;
8
+ /** Router path for the persisted current space, or undefined when none. */
9
+ export declare function currentSpacePath(): string | undefined;
package/lib/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './form-field';
15
15
  export * from './team-type';
16
16
  export * from './location-href';
17
17
  export * from './interfaces';
18
+ export * from './current-space-storage';
18
19
  export * from './directives';
19
20
  export * from './environment-config';
20
21
  export * from './logging/interfaces';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },