@mantine/store 7.0.0-alpha.12

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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Mantine Store
2
+
3
+ [![npm](https://img.shields.io/npm/dm/@mantine/store)](https://www.npmjs.com/package/@mantine/store)
4
+
5
+ Global state manager for `@mantine/notifications`, `@mantine/nprogress`, `@mantine/spotlight` and other Mantine packages.
6
+
7
+ [View documentation](https://mantine.dev/)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ # With yarn
13
+ yarn add @mantine/store
14
+
15
+ # With npm
16
+ npm install @mantine/store
17
+ ```
18
+
19
+ ## License
20
+
21
+ MIT
package/cjs/index.js ADDED
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var store = require('./store.js');
7
+
8
+
9
+
10
+ exports.createStore = store.createStore;
11
+ exports.useStore = store.useStore;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
package/cjs/store.js ADDED
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ function createStore(initialState) {
8
+ let state = initialState;
9
+ let initialized = false;
10
+ const listeners = new Set();
11
+ return {
12
+ getState() {
13
+ return state;
14
+ },
15
+ setState(value) {
16
+ state = value;
17
+ listeners.forEach((listener) => listener(state));
18
+ },
19
+ initialize(value) {
20
+ if (!initialized) {
21
+ state = value;
22
+ initialized = true;
23
+ }
24
+ },
25
+ subscribe(callback) {
26
+ listeners.add(callback);
27
+ return () => listeners.delete(callback);
28
+ },
29
+ };
30
+ }
31
+ function useStore(store) {
32
+ return react.useSyncExternalStore(store.subscribe, () => store.getState(), () => store.getState());
33
+ }
34
+
35
+ exports.createStore = createStore;
36
+ exports.useStore = useStore;
37
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":["useSyncExternalStore"],"mappings":";;;;;;SAagB,WAAW,CAAQ,YAAmB;IACpD,IAAI,KAAK,GAAG,YAAY,CAAC;IACzB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IAE3D,OAAO;QACL,QAAQ;YACN,OAAO,KAAK,CAAC;SACd;QAED,QAAQ,CAAC,KAAK;YACZ,KAAK,GAAG,KAAK,CAAC;YACd,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;SAClD;QAED,UAAU,CAAC,KAAK;YACd,IAAI,CAAC,WAAW,EAAE;gBAChB,KAAK,GAAG,KAAK,CAAC;gBACd,WAAW,GAAG,IAAI,CAAC;aACpB;SACF;QAED,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SACzC;KACF,CAAC;AACJ,CAAC;SAEe,QAAQ,CAAkC,KAAY;IACpE,OAAOA,0BAAoB,CACzB,KAAK,CAAC,SAAS,EACf,MAAM,KAAK,CAAC,QAAQ,EAAE,EACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CACvB,CAAC;AACJ;;;;;"}
package/esm/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use client';
2
+ export { createStore, useStore } from './store.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/esm/store.js ADDED
@@ -0,0 +1,32 @@
1
+ import { useSyncExternalStore } from 'react';
2
+
3
+ function createStore(initialState) {
4
+ let state = initialState;
5
+ let initialized = false;
6
+ const listeners = new Set();
7
+ return {
8
+ getState() {
9
+ return state;
10
+ },
11
+ setState(value) {
12
+ state = value;
13
+ listeners.forEach((listener) => listener(state));
14
+ },
15
+ initialize(value) {
16
+ if (!initialized) {
17
+ state = value;
18
+ initialized = true;
19
+ }
20
+ },
21
+ subscribe(callback) {
22
+ listeners.add(callback);
23
+ return () => listeners.delete(callback);
24
+ },
25
+ };
26
+ }
27
+ function useStore(store) {
28
+ return useSyncExternalStore(store.subscribe, () => store.getState(), () => store.getState());
29
+ }
30
+
31
+ export { createStore, useStore };
32
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value): void;\n initialize(value: Value): void;\n subscribe(callback: MantineStoreSubscriber<Value>): () => void;\n}\n\nexport type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;\n\nexport function createStore<Value>(initialState: Value): MantineStore<Value> {\n let state = initialState;\n let initialized = false;\n const listeners = new Set<MantineStoreSubscriber<Value>>();\n\n return {\n getState() {\n return state;\n },\n\n setState(value) {\n state = value;\n listeners.forEach((listener) => listener(state));\n },\n\n initialize(value) {\n if (!initialized) {\n state = value;\n initialized = true;\n }\n },\n\n subscribe(callback) {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n}\n\nexport function useStore<Store extends MantineStore<any>>(store: Store) {\n return useSyncExternalStore<MantineStoreValue<Store>>(\n store.subscribe,\n () => store.getState(),\n () => store.getState()\n );\n}\n"],"names":[],"mappings":";;SAagB,WAAW,CAAQ,YAAmB;IACpD,IAAI,KAAK,GAAG,YAAY,CAAC;IACzB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IAE3D,OAAO;QACL,QAAQ;YACN,OAAO,KAAK,CAAC;SACd;QAED,QAAQ,CAAC,KAAK;YACZ,KAAK,GAAG,KAAK,CAAC;YACd,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;SAClD;QAED,UAAU,CAAC,KAAK;YACd,IAAI,CAAC,WAAW,EAAE;gBAChB,KAAK,GAAG,KAAK,CAAC;gBACd,WAAW,GAAG,IAAI,CAAC;aACpB;SACF;QAED,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SACzC;KACF,CAAC;AACJ,CAAC;SAEe,QAAQ,CAAkC,KAAY;IACpE,OAAO,oBAAoB,CACzB,KAAK,CAAC,SAAS,EACf,MAAM,KAAK,CAAC,QAAQ,EAAE,EACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CACvB,CAAC;AACJ;;;;"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { useStore, createStore } from './store';
2
+ export type { MantineStore, MantineStoreSubscriber, MantineStoreValue } from './store';
package/lib/store.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export type MantineStoreSubscriber<Value> = (value: Value) => void;
2
+ export interface MantineStore<Value> {
3
+ getState(): Value;
4
+ setState(value: Value): void;
5
+ initialize(value: Value): void;
6
+ subscribe(callback: MantineStoreSubscriber<Value>): () => void;
7
+ }
8
+ export type MantineStoreValue<Store extends MantineStore<any>> = ReturnType<Store['getState']>;
9
+ export declare function createStore<Value>(initialState: Value): MantineStore<Value>;
10
+ export declare function useStore<Store extends MantineStore<any>>(store: Store): ReturnType<Store["getState"]>;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@mantine/store",
3
+ "version": "7.0.0-alpha.12",
4
+ "types": "./lib/index.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./esm/index.js",
8
+ "require": "./cjs/index.js",
9
+ "types": "./lib/index.d.ts"
10
+ }
11
+ },
12
+ "license": "MIT",
13
+ "author": "Vitaly Rtishchev <rtivital@gmail.com>",
14
+ "sideEffects": false,
15
+ "homepage": "https://mantine.dev",
16
+ "repository": {
17
+ "url": "https://github.com/mantinedev/mantine.git",
18
+ "type": "git",
19
+ "directory": "src/mantine-store"
20
+ },
21
+ "keywords": [
22
+ "react",
23
+ "next",
24
+ "nextjs",
25
+ "library",
26
+ "frontend",
27
+ "react-hooks",
28
+ "hooks",
29
+ "state"
30
+ ],
31
+ "peerDependencies": {
32
+ "react": ">=16.8.0"
33
+ },
34
+ "dependencies": {
35
+ "tslib": "^2.5.2"
36
+ },
37
+ "devDependencies": {}
38
+ }