@mantine/store 7.0.0 → 7.0.1-alpha.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.
package/esm/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { createStore, useStore } from './store.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -36,4 +36,4 @@ function useStore(store) {
36
36
  }
37
37
 
38
38
  export { createStore, useStore };
39
- //# sourceMappingURL=store.js.map
39
+ //# sourceMappingURL=store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.mjs","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\ntype SetStateCallback<Value> = (value: Value) => Value;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value | SetStateCallback<Value>): void;\n updateState(value: Value | SetStateCallback<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 extends Record<string, any>>(\n initialState: Value\n): 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 updateState(value) {\n state = typeof value === 'function' ? value(state) : value;\n },\n\n setState(value) {\n this.updateState(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":";;AACO,SAAS,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Store, MantineStoreSubscriber, MantineStoreValue } from './store';
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@mantine/store",
3
- "version": "7.0.0",
3
+ "version": "7.0.1-alpha.0",
4
+ "main": "./cjs/index.js",
4
5
  "types": "./lib/index.d.ts",
5
- "module": "./esm/index.js",
6
+ "module": "./esm/index.mjs",
6
7
  "exports": {
7
8
  ".": {
8
- "import": "./esm/index.js",
9
- "require": "./cjs/index.js",
10
- "types": "./lib/index.d.ts"
9
+ "import": {
10
+ "types": "./lib/index.d.mts",
11
+ "default": "./esm/index.mjs"
12
+ },
13
+ "require": {
14
+ "types": "./lib/index.d.ts",
15
+ "default": "./cjs/index.js"
16
+ }
11
17
  }
12
18
  },
13
19
  "license": "MIT",
package/esm/index.js DELETED
@@ -1,3 +0,0 @@
1
- 'use client';
2
- export { createStore, useStore } from './store.js';
3
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/esm/store.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nexport type MantineStoreSubscriber<Value> = (value: Value) => void;\ntype SetStateCallback<Value> = (value: Value) => Value;\n\nexport interface MantineStore<Value> {\n getState(): Value;\n setState(value: Value | SetStateCallback<Value>): void;\n updateState(value: Value | SetStateCallback<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 extends Record<string, any>>(\n initialState: Value\n): 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 updateState(value) {\n state = typeof value === 'function' ? value(state) : value;\n },\n\n setState(value) {\n this.updateState(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":";;AACO,SAAS,WAAW,CAAC,YAAY,EAAE;AAC1C,EAAE,IAAI,KAAK,GAAG,YAAY,CAAC;AAC3B,EAAE,IAAI,WAAW,GAAG,KAAK,CAAC;AAC1B,EAAE,MAAM,SAAS,mBAAmB,IAAI,GAAG,EAAE,CAAC;AAC9C,EAAE,OAAO;AACT,IAAI,QAAQ,GAAG;AACf,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,IAAI,WAAW,CAAC,KAAK,EAAE;AACvB,MAAM,KAAK,GAAG,OAAO,KAAK,KAAK,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AACjE,KAAK;AACL,IAAI,QAAQ,CAAC,KAAK,EAAE;AACpB,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC9B,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,KAAK;AACL,IAAI,UAAU,CAAC,KAAK,EAAE;AACtB,MAAM,IAAI,CAAC,WAAW,EAAE;AACxB,QAAQ,KAAK,GAAG,KAAK,CAAC;AACtB,QAAQ,WAAW,GAAG,IAAI,CAAC;AAC3B,OAAO;AACP,KAAK;AACL,IAAI,SAAS,CAAC,QAAQ,EAAE;AACxB,MAAM,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,MAAM,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9C,KAAK;AACL,GAAG,CAAC;AACJ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