@liveblocks/zustand 1.11.2 → 1.12.0-lexical2

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/dist/index.d.mts CHANGED
@@ -2,7 +2,15 @@ import { JsonObject, LsonObject, BaseUserMeta, Json, Room, User, Status, Client
2
2
  import { LegacyConnectionStatus } from '@liveblocks/core';
3
3
  import { StoreMutatorIdentifier, StateCreator } from 'zustand';
4
4
 
5
- declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
5
+ /** DP = Default Presence type */
6
+ declare type DP = JsonObject;
7
+ /** DS = Default Storage type */
8
+ declare type DS = LsonObject;
9
+ /** DU = Default UserMeta type */
10
+ declare type DU = BaseUserMeta;
11
+ /** DE = Default (Room)Event type */
12
+ declare type DE = Json;
13
+ declare type LiveblocksContext<P extends JsonObject, S extends LsonObject, U extends BaseUserMeta, E extends Json> = {
6
14
  /**
7
15
  * Enters a room and starts sync it with zustand state
8
16
  * @param roomId The id of the room
@@ -16,11 +24,11 @@ declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends Ls
16
24
  /**
17
25
  * The room currently synced to your zustand state.
18
26
  */
19
- readonly room: Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
27
+ readonly room: Room<P, S, U, E> | null;
20
28
  /**
21
29
  * Other users in the room. Empty no room is currently synced
22
30
  */
23
- readonly others: readonly User<TPresence, TUserMeta>[];
31
+ readonly others: readonly User<P, U>[];
24
32
  /**
25
33
  * Whether or not the room storage is currently loading
26
34
  */
@@ -50,12 +58,12 @@ declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends Ls
50
58
  /**
51
59
  * @deprecated Renamed to WithLiveblocks<...>
52
60
  */
53
- declare type LiveblocksState<TState, TPresence extends JsonObject = JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = Json> = WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>;
61
+ declare type LiveblocksState<TState, P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE> = WithLiveblocks<TState, P, S, U, E>;
54
62
  /**
55
63
  * Adds the `liveblocks` property to your custom Zustand state.
56
64
  */
57
- declare type WithLiveblocks<TState, TPresence extends JsonObject = JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = Json> = TState & {
58
- readonly liveblocks: LiveblocksContext<TPresence, TStorage, TUserMeta, TRoomEvent>;
65
+ declare type WithLiveblocks<TState, P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE> = TState & {
66
+ readonly liveblocks: LiveblocksContext<P, S, U, E>;
59
67
  };
60
68
  declare type Mapping<T> = {
61
69
  [K in keyof T]?: boolean;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,15 @@ import { JsonObject, LsonObject, BaseUserMeta, Json, Room, User, Status, Client
2
2
  import { LegacyConnectionStatus } from '@liveblocks/core';
3
3
  import { StoreMutatorIdentifier, StateCreator } from 'zustand';
4
4
 
5
- declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
5
+ /** DP = Default Presence type */
6
+ declare type DP = JsonObject;
7
+ /** DS = Default Storage type */
8
+ declare type DS = LsonObject;
9
+ /** DU = Default UserMeta type */
10
+ declare type DU = BaseUserMeta;
11
+ /** DE = Default (Room)Event type */
12
+ declare type DE = Json;
13
+ declare type LiveblocksContext<P extends JsonObject, S extends LsonObject, U extends BaseUserMeta, E extends Json> = {
6
14
  /**
7
15
  * Enters a room and starts sync it with zustand state
8
16
  * @param roomId The id of the room
@@ -16,11 +24,11 @@ declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends Ls
16
24
  /**
17
25
  * The room currently synced to your zustand state.
18
26
  */
19
- readonly room: Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
27
+ readonly room: Room<P, S, U, E> | null;
20
28
  /**
21
29
  * Other users in the room. Empty no room is currently synced
22
30
  */
23
- readonly others: readonly User<TPresence, TUserMeta>[];
31
+ readonly others: readonly User<P, U>[];
24
32
  /**
25
33
  * Whether or not the room storage is currently loading
26
34
  */
@@ -50,12 +58,12 @@ declare type LiveblocksContext<TPresence extends JsonObject, TStorage extends Ls
50
58
  /**
51
59
  * @deprecated Renamed to WithLiveblocks<...>
52
60
  */
53
- declare type LiveblocksState<TState, TPresence extends JsonObject = JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = Json> = WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>;
61
+ declare type LiveblocksState<TState, P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE> = WithLiveblocks<TState, P, S, U, E>;
54
62
  /**
55
63
  * Adds the `liveblocks` property to your custom Zustand state.
56
64
  */
57
- declare type WithLiveblocks<TState, TPresence extends JsonObject = JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = Json> = TState & {
58
- readonly liveblocks: LiveblocksContext<TPresence, TStorage, TUserMeta, TRoomEvent>;
65
+ declare type WithLiveblocks<TState, P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE> = TState & {
66
+ readonly liveblocks: LiveblocksContext<P, S, U, E>;
59
67
  };
60
68
  declare type Mapping<T> = {
61
69
  [K in keyof T]?: boolean;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var _core = require('@liveblocks/core');
9
9
 
10
10
  // src/version.ts
11
11
  var PKG_NAME = "@liveblocks/zustand";
12
- var PKG_VERSION = "1.11.2";
12
+ var PKG_VERSION = "1.12.0-lexical2";
13
13
  var PKG_FORMAT = "cjs";
14
14
 
15
15
  // src/index.ts
package/dist/index.js.map CHANGED
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B,GAAG,YAAY,IAAI,WAAW,IAAI,GAAG;AAAA,IACvC;AAEA,QAAI,QAAQ,GAAG,MAAM,MAAM;AACzB,aAAO,GAAG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,gBAAwB,SAI/B;AACA,QAAM,SAAS,QAAQ;AACvB,UAAQ,CAAC,QAAQ,GAAG,YAAY,oBAAoB;AAEpD,QAAM,iBAAiB;AAAA,IACrB,QAAQ,kBAAkB,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,QAAM,kBAAkB;AAAA,IACtB,QAAQ,mBAAmB,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,4BAAwB,gBAAgB,eAAe;AAAA,EACzD;AAEA,SAAO,EAAE,QAAQ,gBAAgB,gBAAgB;AACnD","sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus, StorageUpdate } from \"@liveblocks/core\";\nimport {\n detectDupes,\n errorIf,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"zustand\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nconst ERROR_PREFIX = \"Invalid @liveblocks/zustand middleware config.\";\n\nfunction mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n\nexport type LiveblocksContext<\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n> = {\n /**\n * Enters a room and starts sync it with zustand state\n * @param roomId The id of the room\n */\n readonly enterRoom: (roomId: string) => () => void;\n /**\n * Leaves the currently entered room and stops sync it with zustand state, if\n * any. If enterRoom was not called before, this is a no-op.\n */\n readonly leaveRoom: () => void;\n /**\n * The room currently synced to your zustand state.\n */\n readonly room: Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Renamed to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject = JsonObject,\n TStorage extends LsonObject = LsonObject,\n TUserMeta extends BaseUserMeta = BaseUserMeta,\n TRoomEvent extends Json = Json,\n> = WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>;\n\n/**\n * Adds the `liveblocks` property to your custom Zustand state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject = JsonObject,\n TStorage extends LsonObject = LsonObject,\n TUserMeta extends BaseUserMeta = BaseUserMeta,\n TRoomEvent extends Json = Json,\n> = TState & {\n readonly liveblocks: LiveblocksContext<\n TPresence,\n TStorage,\n TUserMeta,\n TRoomEvent\n >;\n};\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\ntype Options<T> = {\n /**\n * Liveblocks client created by @liveblocks/client createClient\n */\n client: Client;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room storage.\n */\n storageMapping?: Mapping<T>;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room presence.\n */\n presenceMapping?: Mapping<T>;\n};\n\ntype OuterLiveblocksMiddleware = <\n TState,\n Mps extends [StoreMutatorIdentifier, unknown][] = [],\n Mcs extends [StoreMutatorIdentifier, unknown][] = [],\n>(\n config: StateCreator<TState, Mps, Mcs, Omit<TState, \"liveblocks\">>,\n options: Options<Omit<TState, \"liveblocks\">>\n) => StateCreator<TState, Mps, Mcs, TState>;\n\ntype InnerLiveblocksMiddleware = <\n TState extends {\n readonly liveblocks: LiveblocksContext<\n JsonObject,\n LsonObject,\n BaseUserMeta,\n Json\n >;\n },\n>(\n config: StateCreator<TState, [], []>,\n options: Options<TState>\n) => StateCreator<TState, [], []>;\n\ntype ExtractPresence<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<infer P, any, any, any> ? P : never;\n\ntype ExtractStorage<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<any, infer S, any, any> ? S : never;\n\nconst middlewareImpl: InnerLiveblocksMiddleware = (config, options) => {\n type TState = ReturnType<typeof config>;\n type TLiveblocksContext = TState[\"liveblocks\"];\n type TRoom = NonNullable<TLiveblocksContext[\"room\"]>;\n type TPresence = ExtractPresence<TRoom>;\n type TStorage = ExtractStorage<TRoom>;\n\n const { client, presenceMapping, storageMapping } = validateOptions(options);\n return (set, get, api) => {\n let maybeRoom: TRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<TStorage> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n get(),\n presenceMapping\n ) as unknown as TPresence;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n }) as unknown as { room: TRoom; leave: () => void };\n maybeRoom = room;\n\n updateLiveblocksContext(set, { isStorageLoading: true, room });\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n updateLiveblocksContext(set, { others });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.status.subscribe((status) => {\n updateLiveblocksContext(set, {\n status,\n connection: room.getConnectionState(), // For backward-compatibility\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n set(\n selectFields(\n room.getPresence(),\n presenceMapping\n ) as Partial<TState>\n );\n }\n })\n );\n\n void room.getStorage().then(({ root }) => {\n const updates = {} as Partial<TState>;\n\n room.batch(() => {\n for (const key in storageMapping) {\n const liveblocksStatePart = root.get(key);\n if (liveblocksStatePart === undefined) {\n updates[key] = get()[key];\n patchLiveObjectKey(root, key, undefined, get()[key]);\n } else {\n updates[key] = lsonToJson(\n liveblocksStatePart\n ) as unknown as TState[Extract<keyof TState, string>];\n }\n }\n });\n\n set(updates);\n\n storageRoot = root as LiveObject<TStorage>;\n unsubscribeCallbacks.push(\n room.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n set(patchState(get(), updates, storageMapping));\n }\n },\n { isDeep: true }\n )\n );\n\n // set isLoading storage to false once storage is loaded\n updateLiveblocksContext(set, {\n isStorageLoading: false,\n });\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n\n updateLiveblocksContext(set, {\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n room: null,\n });\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n const store = config(\n (args) => {\n const { liveblocks: _, ...oldState } = get();\n set(args);\n const { liveblocks: __, ...newState } = get();\n\n if (maybeRoom) {\n const room = maybeRoom;\n isPatching = true;\n updatePresence(room, oldState, newState, presenceMapping);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n oldState,\n newState,\n storageMapping\n );\n }\n });\n\n isPatching = false;\n }\n },\n get,\n api\n );\n\n return {\n ...store,\n liveblocks: {\n enterRoom,\n leaveRoom,\n room: null,\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n },\n };\n };\n};\n\nexport const liveblocks =\n middlewareImpl as unknown as OuterLiveblocksMiddleware;\n\n/**\n * @deprecated Renamed to `liveblocks`.\n */\nexport const middleware = liveblocks;\n\nfunction patchState<T>(\n state: T,\n updates: StorageUpdate[],\n mapping: Mapping<T>\n) {\n const partialState: Partial<T> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<T> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction updateLiveblocksContext<\n TState,\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n>(\n set: (\n callbackOrPartial: (\n current: WithLiveblocks<\n TState,\n TPresence,\n TStorage,\n TUserMeta,\n TRoomEvent\n >\n ) =>\n | WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>\n | Partial<any>\n ) => void,\n partial: Partial<\n LiveblocksContext<TPresence, TStorage, TUserMeta, TRoomEvent>\n >\n) {\n set((state) => ({ liveblocks: { ...state.liveblocks, ...partial } }));\n}\n\nfunction updatePresence<\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n>(\n room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const val = newState?.[key];\n const patch = {} as Partial<TPresence>;\n patch[key] = val;\n room.updatePresence(patch);\n }\n }\n}\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal, newVal);\n }\n }\n}\n\nfunction isObject(value: unknown): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<T>(\n storageMapping: Mapping<T>,\n presenceMapping: Mapping<T>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on both presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n }\n }\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<T>(\n mapping: Mapping<T>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<T> {\n errorIf(\n !isObject(mapping),\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n\n const result: Mapping<T> = {};\n for (const key in mapping) {\n errorIf(\n typeof mapping[key] !== \"boolean\",\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n\nfunction validateOptions<TState>(options: Options<TState>): {\n client: Client;\n presenceMapping: Mapping<TState>;\n storageMapping: Mapping<TState>;\n} {\n const client = options.client;\n errorIf(!client, `${ERROR_PREFIX} client is missing`);\n\n const storageMapping = validateMapping(\n options.storageMapping ?? {},\n \"storageMapping\"\n );\n\n const presenceMapping = validateMapping(\n options.presenceMapping ?? {},\n \"presenceMapping\"\n );\n\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(storageMapping, presenceMapping);\n }\n\n return { client, storageMapping, presenceMapping };\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/zustand\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/version.ts"],"names":["updates"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACfA,IAAM,WAAW;AACjB,IAAM,cAAiD;AACvD,IAAM,aAAgD;;;ADkB7D,YAAY,UAAU,aAAa,UAAU;AAiB7C,IAAM,eAAe;AAErB,SAAS,8BAA8B,KAAoB;AACzD,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,YAAY,GAAG;AAAA,EAChC;AACF;AA+HA,IAAM,iBAA4C,CAAC,QAAQ,YAAY;AAOrE,QAAM,EAAE,QAAQ,iBAAiB,eAAe,IAAI,gBAAgB,OAAO;AAC3E,SAAO,CAAC,KAAK,KAAK,QAAQ;AACxB,QAAI,YAA0B;AAC9B,QAAI,aAAsB;AAC1B,QAAI,cAAoC;AACxC,QAAI,uBAA0C,CAAC;AAC/C,QAAI,aAA4B;AAChC,QAAI,cAAmC;AAEvC,aAAS,UAAU,WAAyB;AAC1C,UAAI,eAAe,WAAW;AAC5B;AAAA,MACF;AAEA,mBAAa;AACb,UAAI,gBAAgB,MAAM;AAExB,oBAAY;AAAA,MACd;AAEA,YAAM,kBAAkB;AAAA,QACtB,IAAI;AAAA,QACJ;AAAA,MACF;AAEA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AK,MAAM;AACnD;AAEA,SAAS,wBACP,gBACA,iBACA;AACA,aAAW,OAAO,gBAAgB;AAChC,QAAI,gBAAgB,GAAG,MAAM,QAAW;AACtC,YAAM,IAAI;AAAA,QACR,GAAG,YAAY,KAAK,GAAG;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;AAKA,SAAS,gBACP,SACA,aACY;AACZ;AAAA,IACE,CAAC,SAAS,OAAO;AAAA,IACjB,GAAG,YAAY,IAAI,WAAW;AAAA,EAChC;AAEA,QAAM,SAAqB,CAAC;AAC5B,aAAW,OAAO,SAAS;AACzB;AAAA,MACE,OAAO,QAAQ,GAAG,MAAM;AAAA,MACxB,GAAG,YAAY,IAAI,WAAW,IAAI,GAAG;AAAA,IACvC;AAEA,QAAI,QAAQ,GAAG,MAAM,MAAM;AACzB,aAAO,GAAG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,gBAAwB,SAI/B;AACA,QAAM,SAAS,QAAQ;AACvB,UAAQ,CAAC,QAAQ,GAAG,YAAY,oBAAoB;AAEpD,QAAM,iBAAiB;AAAA,IACrB,QAAQ,kBAAkB,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,QAAM,kBAAkB;AAAA,IACtB,QAAQ,mBAAmB,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,4BAAwB,gBAAgB,eAAe;AAAA,EACzD;AAEA,SAAO,EAAE,QAAQ,gBAAgB,gBAAgB;AACnD","sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus, StorageUpdate } from \"@liveblocks/core\";\nimport {\n detectDupes,\n errorIf,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"zustand\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\n//\n// Default concrete types for each of the user-provided type placeholders.\n//\n\n/** DP = Default Presence type */\ntype DP = JsonObject;\n/** DS = Default Storage type */\ntype DS = LsonObject;\n/** DU = Default UserMeta type */\ntype DU = BaseUserMeta;\n/** DE = Default (Room)Event type */\ntype DE = Json;\n/** DM = Default Thread Metadata type */\n// type DM = BaseMetadata;\n\nconst ERROR_PREFIX = \"Invalid @liveblocks/zustand middleware config.\";\n\nfunction mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n\nexport type LiveblocksContext<\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n> = {\n /**\n * Enters a room and starts sync it with zustand state\n * @param roomId The id of the room\n */\n readonly enterRoom: (roomId: string) => () => void;\n /**\n * Leaves the currently entered room and stops sync it with zustand state, if\n * any. If enterRoom was not called before, this is a no-op.\n */\n readonly leaveRoom: () => void;\n /**\n * The room currently synced to your zustand state.\n */\n readonly room: Room<P, S, U, E> | null;\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<P, U>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Renamed to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n P extends JsonObject = DP,\n S extends LsonObject = DS,\n U extends BaseUserMeta = DU,\n E extends Json = DE,\n> = WithLiveblocks<TState, P, S, U, E>;\n\n/**\n * Adds the `liveblocks` property to your custom Zustand state.\n */\nexport type WithLiveblocks<\n TState,\n P extends JsonObject = DP,\n S extends LsonObject = DS,\n U extends BaseUserMeta = DU,\n E extends Json = DE,\n> = TState & {\n readonly liveblocks: LiveblocksContext<P, S, U, E>;\n};\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\ntype Options<T> = {\n /**\n * Liveblocks client created by @liveblocks/client createClient\n */\n client: Client;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room storage.\n */\n storageMapping?: Mapping<T>;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room presence.\n */\n presenceMapping?: Mapping<T>;\n};\n\ntype OuterLiveblocksMiddleware = <\n TState,\n Mps extends [StoreMutatorIdentifier, unknown][] = [],\n Mcs extends [StoreMutatorIdentifier, unknown][] = [],\n>(\n config: StateCreator<TState, Mps, Mcs, Omit<TState, \"liveblocks\">>,\n options: Options<Omit<TState, \"liveblocks\">>\n) => StateCreator<TState, Mps, Mcs, TState>;\n\ntype InnerLiveblocksMiddleware = <\n TState extends {\n readonly liveblocks: LiveblocksContext<\n JsonObject,\n LsonObject,\n BaseUserMeta,\n Json\n >;\n },\n>(\n config: StateCreator<TState, [], []>,\n options: Options<TState>\n) => StateCreator<TState, [], []>;\n\ntype ExtractPresence<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<infer P, any, any, any> ? P : never;\n\ntype ExtractStorage<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<any, infer S, any, any> ? S : never;\n\nconst middlewareImpl: InnerLiveblocksMiddleware = (config, options) => {\n type TState = ReturnType<typeof config>;\n type TLiveblocksContext = TState[\"liveblocks\"];\n type TRoom = NonNullable<TLiveblocksContext[\"room\"]>;\n type P = ExtractPresence<TRoom>;\n type S = ExtractStorage<TRoom>;\n\n const { client, presenceMapping, storageMapping } = validateOptions(options);\n return (set, get, api) => {\n let maybeRoom: TRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<S> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n get(),\n presenceMapping\n ) as unknown as P;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n }) as unknown as { room: TRoom; leave: () => void };\n maybeRoom = room;\n\n updateLiveblocksContext(set, { isStorageLoading: true, room });\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n updateLiveblocksContext(set, { others });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.status.subscribe((status) => {\n updateLiveblocksContext(set, {\n status,\n connection: room.getConnectionState(), // For backward-compatibility\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n set(\n selectFields(\n room.getPresence(),\n presenceMapping\n ) as Partial<TState>\n );\n }\n })\n );\n\n void room.getStorage().then(({ root }) => {\n const updates = {} as Partial<TState>;\n\n room.batch(() => {\n for (const key in storageMapping) {\n const liveblocksStatePart = root.get(key);\n if (liveblocksStatePart === undefined) {\n updates[key] = get()[key];\n patchLiveObjectKey(root, key, undefined, get()[key]);\n } else {\n updates[key] = lsonToJson(\n liveblocksStatePart\n ) as unknown as TState[Extract<keyof TState, string>];\n }\n }\n });\n\n set(updates);\n\n storageRoot = root as LiveObject<S>;\n unsubscribeCallbacks.push(\n room.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n set(patchState(get(), updates, storageMapping));\n }\n },\n { isDeep: true }\n )\n );\n\n // set isLoading storage to false once storage is loaded\n updateLiveblocksContext(set, {\n isStorageLoading: false,\n });\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n\n updateLiveblocksContext(set, {\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n room: null,\n });\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n const store = config(\n (args) => {\n const { liveblocks: _, ...oldState } = get();\n set(args);\n const { liveblocks: __, ...newState } = get();\n\n if (maybeRoom) {\n const room = maybeRoom;\n isPatching = true;\n updatePresence(room, oldState, newState, presenceMapping);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n oldState,\n newState,\n storageMapping\n );\n }\n });\n\n isPatching = false;\n }\n },\n get,\n api\n );\n\n return {\n ...store,\n liveblocks: {\n enterRoom,\n leaveRoom,\n room: null,\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n },\n };\n };\n};\n\nexport const liveblocks =\n middlewareImpl as unknown as OuterLiveblocksMiddleware;\n\n/**\n * @deprecated Renamed to `liveblocks`.\n */\nexport const middleware = liveblocks;\n\nfunction patchState<T>(\n state: T,\n updates: StorageUpdate[],\n mapping: Mapping<T>\n) {\n const partialState: Partial<T> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<T> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction updateLiveblocksContext<\n TState,\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n>(\n set: (\n callbackOrPartial: (\n current: WithLiveblocks<TState, P, S, U, E>\n ) => WithLiveblocks<TState, P, S, U, E> | Partial<any>\n ) => void,\n partial: Partial<LiveblocksContext<P, S, U, E>>\n) {\n set((state) => ({ liveblocks: { ...state.liveblocks, ...partial } }));\n}\n\nfunction updatePresence<\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n>(\n room: Room<P, S, U, E>,\n oldState: P,\n newState: P,\n presenceMapping: Mapping<P>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const val = newState?.[key];\n const patch = {} as Partial<P>;\n patch[key] = val;\n room.updatePresence(patch);\n }\n }\n}\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal, newVal);\n }\n }\n}\n\nfunction isObject(value: unknown): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<T>(\n storageMapping: Mapping<T>,\n presenceMapping: Mapping<T>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on both presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n }\n }\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<T>(\n mapping: Mapping<T>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<T> {\n errorIf(\n !isObject(mapping),\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n\n const result: Mapping<T> = {};\n for (const key in mapping) {\n errorIf(\n typeof mapping[key] !== \"boolean\",\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n\nfunction validateOptions<TState>(options: Options<TState>): {\n client: Client;\n presenceMapping: Mapping<TState>;\n storageMapping: Mapping<TState>;\n} {\n const client = options.client;\n errorIf(!client, `${ERROR_PREFIX} client is missing`);\n\n const storageMapping = validateMapping(\n options.storageMapping ?? {},\n \"storageMapping\"\n );\n\n const presenceMapping = validateMapping(\n options.presenceMapping ?? {},\n \"presenceMapping\"\n );\n\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(storageMapping, presenceMapping);\n }\n\n return { client, storageMapping, presenceMapping };\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/zustand\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"]}
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  // src/version.ts
11
11
  var PKG_NAME = "@liveblocks/zustand";
12
- var PKG_VERSION = "1.11.2";
12
+ var PKG_VERSION = "1.12.0-lexical2";
13
13
  var PKG_FORMAT = "esm";
14
14
 
15
15
  // src/index.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/version.ts"],"sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus, StorageUpdate } from \"@liveblocks/core\";\nimport {\n detectDupes,\n errorIf,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"zustand\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nconst ERROR_PREFIX = \"Invalid @liveblocks/zustand middleware config.\";\n\nfunction mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n\nexport type LiveblocksContext<\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n> = {\n /**\n * Enters a room and starts sync it with zustand state\n * @param roomId The id of the room\n */\n readonly enterRoom: (roomId: string) => () => void;\n /**\n * Leaves the currently entered room and stops sync it with zustand state, if\n * any. If enterRoom was not called before, this is a no-op.\n */\n readonly leaveRoom: () => void;\n /**\n * The room currently synced to your zustand state.\n */\n readonly room: Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<TPresence, TUserMeta>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Renamed to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n TPresence extends JsonObject = JsonObject,\n TStorage extends LsonObject = LsonObject,\n TUserMeta extends BaseUserMeta = BaseUserMeta,\n TRoomEvent extends Json = Json,\n> = WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>;\n\n/**\n * Adds the `liveblocks` property to your custom Zustand state.\n */\nexport type WithLiveblocks<\n TState,\n TPresence extends JsonObject = JsonObject,\n TStorage extends LsonObject = LsonObject,\n TUserMeta extends BaseUserMeta = BaseUserMeta,\n TRoomEvent extends Json = Json,\n> = TState & {\n readonly liveblocks: LiveblocksContext<\n TPresence,\n TStorage,\n TUserMeta,\n TRoomEvent\n >;\n};\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\ntype Options<T> = {\n /**\n * Liveblocks client created by @liveblocks/client createClient\n */\n client: Client;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room storage.\n */\n storageMapping?: Mapping<T>;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room presence.\n */\n presenceMapping?: Mapping<T>;\n};\n\ntype OuterLiveblocksMiddleware = <\n TState,\n Mps extends [StoreMutatorIdentifier, unknown][] = [],\n Mcs extends [StoreMutatorIdentifier, unknown][] = [],\n>(\n config: StateCreator<TState, Mps, Mcs, Omit<TState, \"liveblocks\">>,\n options: Options<Omit<TState, \"liveblocks\">>\n) => StateCreator<TState, Mps, Mcs, TState>;\n\ntype InnerLiveblocksMiddleware = <\n TState extends {\n readonly liveblocks: LiveblocksContext<\n JsonObject,\n LsonObject,\n BaseUserMeta,\n Json\n >;\n },\n>(\n config: StateCreator<TState, [], []>,\n options: Options<TState>\n) => StateCreator<TState, [], []>;\n\ntype ExtractPresence<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<infer P, any, any, any> ? P : never;\n\ntype ExtractStorage<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<any, infer S, any, any> ? S : never;\n\nconst middlewareImpl: InnerLiveblocksMiddleware = (config, options) => {\n type TState = ReturnType<typeof config>;\n type TLiveblocksContext = TState[\"liveblocks\"];\n type TRoom = NonNullable<TLiveblocksContext[\"room\"]>;\n type TPresence = ExtractPresence<TRoom>;\n type TStorage = ExtractStorage<TRoom>;\n\n const { client, presenceMapping, storageMapping } = validateOptions(options);\n return (set, get, api) => {\n let maybeRoom: TRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<TStorage> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n get(),\n presenceMapping\n ) as unknown as TPresence;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n }) as unknown as { room: TRoom; leave: () => void };\n maybeRoom = room;\n\n updateLiveblocksContext(set, { isStorageLoading: true, room });\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n updateLiveblocksContext(set, { others });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.status.subscribe((status) => {\n updateLiveblocksContext(set, {\n status,\n connection: room.getConnectionState(), // For backward-compatibility\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n set(\n selectFields(\n room.getPresence(),\n presenceMapping\n ) as Partial<TState>\n );\n }\n })\n );\n\n void room.getStorage().then(({ root }) => {\n const updates = {} as Partial<TState>;\n\n room.batch(() => {\n for (const key in storageMapping) {\n const liveblocksStatePart = root.get(key);\n if (liveblocksStatePart === undefined) {\n updates[key] = get()[key];\n patchLiveObjectKey(root, key, undefined, get()[key]);\n } else {\n updates[key] = lsonToJson(\n liveblocksStatePart\n ) as unknown as TState[Extract<keyof TState, string>];\n }\n }\n });\n\n set(updates);\n\n storageRoot = root as LiveObject<TStorage>;\n unsubscribeCallbacks.push(\n room.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n set(patchState(get(), updates, storageMapping));\n }\n },\n { isDeep: true }\n )\n );\n\n // set isLoading storage to false once storage is loaded\n updateLiveblocksContext(set, {\n isStorageLoading: false,\n });\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n\n updateLiveblocksContext(set, {\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n room: null,\n });\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n const store = config(\n (args) => {\n const { liveblocks: _, ...oldState } = get();\n set(args);\n const { liveblocks: __, ...newState } = get();\n\n if (maybeRoom) {\n const room = maybeRoom;\n isPatching = true;\n updatePresence(room, oldState, newState, presenceMapping);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n oldState,\n newState,\n storageMapping\n );\n }\n });\n\n isPatching = false;\n }\n },\n get,\n api\n );\n\n return {\n ...store,\n liveblocks: {\n enterRoom,\n leaveRoom,\n room: null,\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n },\n };\n };\n};\n\nexport const liveblocks =\n middlewareImpl as unknown as OuterLiveblocksMiddleware;\n\n/**\n * @deprecated Renamed to `liveblocks`.\n */\nexport const middleware = liveblocks;\n\nfunction patchState<T>(\n state: T,\n updates: StorageUpdate[],\n mapping: Mapping<T>\n) {\n const partialState: Partial<T> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<T> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction updateLiveblocksContext<\n TState,\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n>(\n set: (\n callbackOrPartial: (\n current: WithLiveblocks<\n TState,\n TPresence,\n TStorage,\n TUserMeta,\n TRoomEvent\n >\n ) =>\n | WithLiveblocks<TState, TPresence, TStorage, TUserMeta, TRoomEvent>\n | Partial<any>\n ) => void,\n partial: Partial<\n LiveblocksContext<TPresence, TStorage, TUserMeta, TRoomEvent>\n >\n) {\n set((state) => ({ liveblocks: { ...state.liveblocks, ...partial } }));\n}\n\nfunction updatePresence<\n TPresence extends JsonObject,\n TStorage extends LsonObject,\n TUserMeta extends BaseUserMeta,\n TRoomEvent extends Json,\n>(\n room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>,\n oldState: TPresence,\n newState: TPresence,\n presenceMapping: Mapping<TPresence>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const val = newState?.[key];\n const patch = {} as Partial<TPresence>;\n patch[key] = val;\n room.updatePresence(patch);\n }\n }\n}\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal, newVal);\n }\n }\n}\n\nfunction isObject(value: unknown): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<T>(\n storageMapping: Mapping<T>,\n presenceMapping: Mapping<T>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on both presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n }\n }\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<T>(\n mapping: Mapping<T>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<T> {\n errorIf(\n !isObject(mapping),\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n\n const result: Mapping<T> = {};\n for (const key in mapping) {\n errorIf(\n typeof mapping[key] !== \"boolean\",\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n\nfunction validateOptions<TState>(options: Options<TState>): {\n client: Client;\n presenceMapping: Mapping<TState>;\n storageMapping: Mapping<TState>;\n} {\n const client = options.client;\n errorIf(!client, `${ERROR_PREFIX} client is missing`);\n\n const storageMapping = validateMapping(\n options.storageMapping ?? {},\n \"storageMapping\"\n );\n\n const presenceMapping = validateMapping(\n options.presenceMapping ?? {},\n \"presenceMapping\"\n );\n\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(storageMapping, presenceMapping);\n }\n\n return { client, storageMapping, presenceMapping };\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/zustand\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACfA,IAAM,WAAW;AACjB,IAAM,cAAiD;AACvD,IAAM,aAAgD;;;ADkB7D,YAAY,UAAU,aAAa,UAAU;AAE7C,IAAM,eAAe;AAErB,SAAS,8BAA8B,KAAoB;AACzD,SAAO,IAAI;AAAA,IACT,GAAG,YAAY,YAAY,GAAG;AAAA,EAChC;AACF;AAoIA,IAAM,iBAA4C,CAAC,QAAQ,YAAY;AAOrE,QAAM,EAAE,QAAQ,iBAAiB,eAAe,IAAI,gBA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c;AACzC,4BAAwB,gBAAgB,eAAe;AAAA,EACzD;AAEA,SAAO,EAAE,QAAQ,gBAAgB,gBAAgB;AACnD;","names":["updates"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/version.ts"],"sourcesContent":["import type {\n BaseUserMeta,\n Client,\n Json,\n JsonObject,\n LiveObject,\n LsonObject,\n Room,\n Status,\n User,\n} from \"@liveblocks/client\";\nimport type { LegacyConnectionStatus, StorageUpdate } from \"@liveblocks/core\";\nimport {\n detectDupes,\n errorIf,\n legacy_patchImmutableObject,\n lsonToJson,\n patchLiveObjectKey,\n} from \"@liveblocks/core\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"zustand\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\n//\n// Default concrete types for each of the user-provided type placeholders.\n//\n\n/** DP = Default Presence type */\ntype DP = JsonObject;\n/** DS = Default Storage type */\ntype DS = LsonObject;\n/** DU = Default UserMeta type */\ntype DU = BaseUserMeta;\n/** DE = Default (Room)Event type */\ntype DE = Json;\n/** DM = Default Thread Metadata type */\n// type DM = BaseMetadata;\n\nconst ERROR_PREFIX = \"Invalid @liveblocks/zustand middleware config.\";\n\nfunction mappingToFunctionIsNotAllowed(key: string): Error {\n return new Error(\n `${ERROR_PREFIX} mapping.${key} is invalid. Mapping to a function is not allowed.`\n );\n}\n\nexport type LiveblocksContext<\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n> = {\n /**\n * Enters a room and starts sync it with zustand state\n * @param roomId The id of the room\n */\n readonly enterRoom: (roomId: string) => () => void;\n /**\n * Leaves the currently entered room and stops sync it with zustand state, if\n * any. If enterRoom was not called before, this is a no-op.\n */\n readonly leaveRoom: () => void;\n /**\n * The room currently synced to your zustand state.\n */\n readonly room: Room<P, S, U, E> | null;\n /**\n * Other users in the room. Empty no room is currently synced\n */\n readonly others: readonly User<P, U>[];\n /**\n * Whether or not the room storage is currently loading\n */\n readonly isStorageLoading: boolean;\n /**\n * Legacy connection status of the room.\n *\n * @deprecated This API will be removed in a future version of Liveblocks.\n * Prefer using the newer `.status` property.\n *\n * We recommend making the following changes if you use these APIs:\n *\n * OLD STATUSES NEW STATUSES\n * closed --> initial\n * authenticating --> connecting\n * connecting --> connecting\n * open --> connected\n * unavailable --> reconnecting\n * failed --> disconnected\n */\n readonly connection: LegacyConnectionStatus;\n /**\n * Connection status of the room.\n */\n readonly status: Status;\n};\n\n/**\n * @deprecated Renamed to WithLiveblocks<...>\n */\nexport type LiveblocksState<\n TState,\n P extends JsonObject = DP,\n S extends LsonObject = DS,\n U extends BaseUserMeta = DU,\n E extends Json = DE,\n> = WithLiveblocks<TState, P, S, U, E>;\n\n/**\n * Adds the `liveblocks` property to your custom Zustand state.\n */\nexport type WithLiveblocks<\n TState,\n P extends JsonObject = DP,\n S extends LsonObject = DS,\n U extends BaseUserMeta = DU,\n E extends Json = DE,\n> = TState & {\n readonly liveblocks: LiveblocksContext<P, S, U, E>;\n};\n\nexport type Mapping<T> = {\n [K in keyof T]?: boolean;\n};\n\ntype Options<T> = {\n /**\n * Liveblocks client created by @liveblocks/client createClient\n */\n client: Client;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room storage.\n */\n storageMapping?: Mapping<T>;\n /**\n * Mapping used to synchronize a part of your zustand state with one Liveblocks Room presence.\n */\n presenceMapping?: Mapping<T>;\n};\n\ntype OuterLiveblocksMiddleware = <\n TState,\n Mps extends [StoreMutatorIdentifier, unknown][] = [],\n Mcs extends [StoreMutatorIdentifier, unknown][] = [],\n>(\n config: StateCreator<TState, Mps, Mcs, Omit<TState, \"liveblocks\">>,\n options: Options<Omit<TState, \"liveblocks\">>\n) => StateCreator<TState, Mps, Mcs, TState>;\n\ntype InnerLiveblocksMiddleware = <\n TState extends {\n readonly liveblocks: LiveblocksContext<\n JsonObject,\n LsonObject,\n BaseUserMeta,\n Json\n >;\n },\n>(\n config: StateCreator<TState, [], []>,\n options: Options<TState>\n) => StateCreator<TState, [], []>;\n\ntype ExtractPresence<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<infer P, any, any, any> ? P : never;\n\ntype ExtractStorage<\n TRoom extends Room<JsonObject, LsonObject, BaseUserMeta, Json>,\n> = TRoom extends Room<any, infer S, any, any> ? S : never;\n\nconst middlewareImpl: InnerLiveblocksMiddleware = (config, options) => {\n type TState = ReturnType<typeof config>;\n type TLiveblocksContext = TState[\"liveblocks\"];\n type TRoom = NonNullable<TLiveblocksContext[\"room\"]>;\n type P = ExtractPresence<TRoom>;\n type S = ExtractStorage<TRoom>;\n\n const { client, presenceMapping, storageMapping } = validateOptions(options);\n return (set, get, api) => {\n let maybeRoom: TRoom | null = null;\n let isPatching: boolean = false;\n let storageRoot: LiveObject<S> | null = null;\n let unsubscribeCallbacks: Array<() => void> = [];\n let lastRoomId: string | null = null;\n let lastLeaveFn: (() => void) | null = null;\n\n function enterRoom(newRoomId: string): void {\n if (lastRoomId === newRoomId) {\n return;\n }\n\n lastRoomId = newRoomId;\n if (lastLeaveFn !== null) {\n // First leave the old room before entering a potential new one\n lastLeaveFn();\n }\n\n const initialPresence = selectFields(\n get(),\n presenceMapping\n ) as unknown as P;\n\n const { room, leave } = client.enterRoom(newRoomId, {\n initialPresence,\n }) as unknown as { room: TRoom; leave: () => void };\n maybeRoom = room;\n\n updateLiveblocksContext(set, { isStorageLoading: true, room });\n\n unsubscribeCallbacks.push(\n room.events.others.subscribe(({ others }) => {\n updateLiveblocksContext(set, { others });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.status.subscribe((status) => {\n updateLiveblocksContext(set, {\n status,\n connection: room.getConnectionState(), // For backward-compatibility\n });\n })\n );\n\n unsubscribeCallbacks.push(\n room.events.myPresence.subscribe(() => {\n if (isPatching === false) {\n set(\n selectFields(\n room.getPresence(),\n presenceMapping\n ) as Partial<TState>\n );\n }\n })\n );\n\n void room.getStorage().then(({ root }) => {\n const updates = {} as Partial<TState>;\n\n room.batch(() => {\n for (const key in storageMapping) {\n const liveblocksStatePart = root.get(key);\n if (liveblocksStatePart === undefined) {\n updates[key] = get()[key];\n patchLiveObjectKey(root, key, undefined, get()[key]);\n } else {\n updates[key] = lsonToJson(\n liveblocksStatePart\n ) as unknown as TState[Extract<keyof TState, string>];\n }\n }\n });\n\n set(updates);\n\n storageRoot = root as LiveObject<S>;\n unsubscribeCallbacks.push(\n room.subscribe(\n root,\n (updates) => {\n if (isPatching === false) {\n set(patchState(get(), updates, storageMapping));\n }\n },\n { isDeep: true }\n )\n );\n\n // set isLoading storage to false once storage is loaded\n updateLiveblocksContext(set, {\n isStorageLoading: false,\n });\n });\n\n lastLeaveFn = () => {\n for (const unsubscribe of unsubscribeCallbacks) {\n unsubscribe();\n }\n unsubscribeCallbacks = [];\n\n storageRoot = null;\n maybeRoom = null;\n isPatching = false;\n\n lastRoomId = null;\n lastLeaveFn = null;\n leave();\n\n updateLiveblocksContext(set, {\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n room: null,\n });\n };\n }\n\n function leaveRoom() {\n lastLeaveFn?.();\n }\n\n const store = config(\n (args) => {\n const { liveblocks: _, ...oldState } = get();\n set(args);\n const { liveblocks: __, ...newState } = get();\n\n if (maybeRoom) {\n const room = maybeRoom;\n isPatching = true;\n updatePresence(room, oldState, newState, presenceMapping);\n\n room.batch(() => {\n if (storageRoot) {\n patchLiveblocksStorage(\n storageRoot,\n oldState,\n newState,\n storageMapping\n );\n }\n });\n\n isPatching = false;\n }\n },\n get,\n api\n );\n\n return {\n ...store,\n liveblocks: {\n enterRoom,\n leaveRoom,\n room: null,\n others: [],\n connection: \"closed\",\n isStorageLoading: false,\n },\n };\n };\n};\n\nexport const liveblocks =\n middlewareImpl as unknown as OuterLiveblocksMiddleware;\n\n/**\n * @deprecated Renamed to `liveblocks`.\n */\nexport const middleware = liveblocks;\n\nfunction patchState<T>(\n state: T,\n updates: StorageUpdate[],\n mapping: Mapping<T>\n) {\n const partialState: Partial<T> = {};\n\n for (const key in mapping) {\n partialState[key] = state[key];\n }\n\n const patched = legacy_patchImmutableObject(partialState, updates);\n\n const result: Partial<T> = {};\n\n for (const key in mapping) {\n result[key] = patched[key];\n }\n\n return result;\n}\n\nfunction selectFields<TState>(\n presence: TState,\n mapping: Mapping<TState>\n): /* TODO: Actually, Pick<TState, keyof Mapping<TState>> ? */\nPartial<TState> {\n const partialState = {} as Partial<TState>;\n for (const key in mapping) {\n partialState[key] = presence[key];\n }\n return partialState;\n}\n\nfunction updateLiveblocksContext<\n TState,\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n>(\n set: (\n callbackOrPartial: (\n current: WithLiveblocks<TState, P, S, U, E>\n ) => WithLiveblocks<TState, P, S, U, E> | Partial<any>\n ) => void,\n partial: Partial<LiveblocksContext<P, S, U, E>>\n) {\n set((state) => ({ liveblocks: { ...state.liveblocks, ...partial } }));\n}\n\nfunction updatePresence<\n P extends JsonObject,\n S extends LsonObject,\n U extends BaseUserMeta,\n E extends Json,\n>(\n room: Room<P, S, U, E>,\n oldState: P,\n newState: P,\n presenceMapping: Mapping<P>\n) {\n for (const key in presenceMapping) {\n if (typeof newState[key] === \"function\") {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const val = newState?.[key];\n const patch = {} as Partial<P>;\n patch[key] = val;\n room.updatePresence(patch);\n }\n }\n}\n\nfunction patchLiveblocksStorage<O extends LsonObject, TState>(\n root: LiveObject<O>,\n oldState: TState,\n newState: TState,\n mapping: Mapping<TState>\n) {\n for (const key in mapping) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n typeof newState[key] === \"function\"\n ) {\n throw mappingToFunctionIsNotAllowed(key);\n }\n\n if (oldState[key] !== newState[key]) {\n const oldVal = oldState[key];\n const newVal = newState[key];\n patchLiveObjectKey(root, key, oldVal, newVal);\n }\n }\n}\n\nfunction isObject(value: unknown): value is object {\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\nfunction validateNoDuplicateKeys<T>(\n storageMapping: Mapping<T>,\n presenceMapping: Mapping<T>\n) {\n for (const key in storageMapping) {\n if (presenceMapping[key] !== undefined) {\n throw new Error(\n `${ERROR_PREFIX} \"${key}\" is mapped on both presenceMapping and storageMapping. A key shouldn't exist on both mapping.`\n );\n }\n }\n}\n\n/**\n * Remove false keys from mapping and generate to a new object to avoid potential mutation from outside the middleware\n */\nfunction validateMapping<T>(\n mapping: Mapping<T>,\n mappingType: \"storageMapping\" | \"presenceMapping\"\n): Mapping<T> {\n errorIf(\n !isObject(mapping),\n `${ERROR_PREFIX} ${mappingType} should be an object where the values are boolean.`\n );\n\n const result: Mapping<T> = {};\n for (const key in mapping) {\n errorIf(\n typeof mapping[key] !== \"boolean\",\n `${ERROR_PREFIX} ${mappingType}.${key} value should be a boolean`\n );\n\n if (mapping[key] === true) {\n result[key] = true;\n }\n }\n return result;\n}\n\nfunction validateOptions<TState>(options: Options<TState>): {\n client: Client;\n presenceMapping: Mapping<TState>;\n storageMapping: Mapping<TState>;\n} {\n const client = options.client;\n errorIf(!client, `${ERROR_PREFIX} client is missing`);\n\n const storageMapping = validateMapping(\n options.storageMapping ?? {},\n \"storageMapping\"\n );\n\n const presenceMapping = validateMapping(\n options.presenceMapping ?? {},\n \"presenceMapping\"\n );\n\n if (process.env.NODE_ENV !== \"production\") {\n validateNoDuplicateKeys(storageMapping, presenceMapping);\n }\n\n return { client, storageMapping, presenceMapping };\n}\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/zustand\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACfA,IAAM,WAAW;AACjB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AwB,SAI/B;AACA,QAAM,SAAS,QAAQ;AACvB,UAAQ,CAAC,QAAQ,GAAG,YAAY,oBAAoB;AAEpD,QAAM,iBAAiB;AAAA,IACrB,QAAQ,kBAAkB,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,QAAM,kBAAkB;AAAA,IACtB,QAAQ,mBAAmB,CAAC;AAAA,IAC5B;AAAA,EACF;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,4BAAwB,gBAAgB,eAAe;AAAA,EACzD;AAEA,SAAO,EAAE,QAAQ,gBAAgB,gBAAgB;AACnD;","names":["updates"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/zustand",
3
- "version": "1.11.2",
3
+ "version": "1.12.0-lexical2",
4
4
  "description": "A middleware to integrate Liveblocks into Zustand stores. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "test:watch": "jest --silent --verbose --color=always --watch"
34
34
  },
35
35
  "dependencies": {
36
- "@liveblocks/client": "1.11.2",
37
- "@liveblocks/core": "1.11.2"
36
+ "@liveblocks/client": "1.12.0-lexical2",
37
+ "@liveblocks/core": "1.12.0-lexical2"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "zustand": "^4.1.3"