@absolutejs/absolute 0.19.0-beta.337 → 0.19.0-beta.338

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.
@@ -178,31 +178,45 @@ var initializeIslandStores = (state) => {
178
178
  };
179
179
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
180
180
  for (const [storeId, store] of getIslandStores()) {
181
- applySnapshot(store, nextSnapshot[storeId]);
181
+ for (const instance of store) {
182
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
183
+ }
182
184
  }
183
185
  };
184
- var createIslandStore = (storeId) => (createState) => {
186
+ var createIslandStore = (storeId, createState) => {
187
+ const store = createStore(createState);
185
188
  const stores = getIslandStores();
186
- const existingStore = stores.get(storeId);
187
- if (existingStore) {
188
- return existingStore;
189
- }
190
- const store = createStore()((set, get, api) => createState((update) => {
191
- set((state) => {
192
- const nextPartial = typeof update === "function" ? update(state) : update;
193
- return {
194
- ...state,
195
- ...nextPartial
196
- };
197
- });
198
- }, get, api));
189
+ const storeInstances = stores.get(storeId) ?? new Set;
199
190
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
200
191
  applySnapshot(store, initialSnapshot);
201
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
192
+ let isApplyingExternalSnapshot = false;
193
+ const applyExternalSnapshot = (snapshot) => {
194
+ isApplyingExternalSnapshot = true;
195
+ applySnapshot(store, snapshot);
196
+ };
197
+ const syncSnapshot = (state) => {
198
+ const nextSnapshot = toSerializableState(state);
199
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
200
+ for (const peerStore of storeInstances) {
201
+ if (peerStore.store === store) {
202
+ continue;
203
+ }
204
+ peerStore.applyExternalSnapshot(nextSnapshot);
205
+ }
206
+ };
207
+ storeInstances.add({
208
+ applyExternalSnapshot,
209
+ store
210
+ });
211
+ stores.set(storeId, storeInstances);
212
+ syncSnapshot(store.getState());
202
213
  store.subscribe((state) => {
203
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
214
+ if (isApplyingExternalSnapshot) {
215
+ isApplyingExternalSnapshot = false;
216
+ return;
217
+ }
218
+ syncSnapshot(state);
204
219
  });
205
- stores.set(storeId, store);
206
220
  return store;
207
221
  };
208
222
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -229,5 +243,5 @@ export {
229
243
  createIslandStore
230
244
  };
231
245
 
232
- //# debugId=6F7231AAFF815DA364756E2164756E21
246
+ //# debugId=6FA47D4A1FC4F18F64756E2164756E21
233
247
  //# sourceMappingURL=browser.js.map
@@ -6,9 +6,9 @@
6
6
  "import type {\n\tIslandComponentDefinition,\n\tIslandRegistry,\n\tIslandRegistryInput\n} from '../../types/island';\n\nexport const defineIslandRegistry = <T extends IslandRegistryInput>(\n\tregistry: IslandRegistry<T>\n) => registry;\n\nexport const defineIslandComponent = <Component>(\n\tcomponent: Component,\n\toptions: {\n\t\texport?: string;\n\t\tsource: string;\n\t}\n): IslandComponentDefinition<Component> => ({\n\tcomponent,\n\texport: options.export,\n\tsource: options.source\n});\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null;\n\nexport const isIslandComponentDefinition = <Component>(\n\tvalue: Component | IslandComponentDefinition<Component>\n): value is IslandComponentDefinition<Component> =>\n\tisRecord(value) &&\n\t'component' in value &&\n\t'source' in value &&\n\ttypeof value.source === 'string';\n\nexport function getIslandComponent<Component>(component: Component): Component;\nexport function getIslandComponent<Component>(\n\tcomponent: IslandComponentDefinition<Component>\n): Component;\nexport function getIslandComponent<Component>(\n\tcomponent: Component | IslandComponentDefinition<Component>\n) {\n\tif (isIslandComponentDefinition(component)) {\n\t\treturn component.component;\n\t}\n\n\treturn component;\n}\n\nexport const getIslandBuildReference = <Component>(\n\tcomponent: Component | IslandComponentDefinition<Component>\n) => {\n\tif (!isIslandComponentDefinition(component)) return null;\n\n\treturn {\n\t\texport: component.export,\n\t\tsource: component.source\n\t};\n};\n\nexport const serializeIslandProps = (props: unknown) =>\n\tJSON.stringify(props ?? {});\n\nexport const parseIslandProps = (rawProps: string | null) => {\n\tif (!rawProps) return {};\n\n\treturn JSON.parse(rawProps);\n};\n\nexport {\n\tgetIslandManifestEntries,\n\tgetIslandManifestKey\n} from './islandManifest';\n",
7
7
  "export { defineIslandRegistry } from '../core/islands';\nexport { createIslandStore } from '../client/islandStore';\n\nexport const renderIslandMarkup = async () => {\n\tthrow new Error(\n\t\t'renderIslandMarkup is server-only. Import from \"@absolutejs/absolute/islands/server\" on the server.'\n\t);\n};\n",
8
8
  "const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const api = { setState, getState, getInitialState, subscribe };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);\n\nexport { createStore };\n",
9
- "import {\n\tcreateStore,\n\ttype StoreApi\n} from 'zustand/vanilla';\n\nexport type IslandStoreState = Record<string, unknown>;\nexport type IslandStateSnapshot = Record<string, IslandStoreState>;\nexport type IslandStoreSetState<T extends IslandStoreState> = (\n\tupdate:\n\t\t| Partial<T>\n\t\t| ((state: T) => Partial<T>)\n) => void;\nexport type IslandStoreInitializer<T extends IslandStoreState> = (\n\tset: IslandStoreSetState<T>,\n\tget: () => T,\n\tstore: StoreApi<T>\n) => T;\ntype AnyIslandStore = StoreApi<IslandStoreState>;\n\nconst ABSOLUTE_ISLAND_STATE = '__ABS_ISLAND_STATE__';\nconst ABSOLUTE_ISLAND_STORES = '__ABS_ISLAND_STORES__';\n\ndeclare global {\n\tvar __ABS_ISLAND_STATE__: IslandStateSnapshot | undefined;\n\tvar __ABS_ISLAND_STORES__: Map<string, AnyIslandStore> | undefined;\n}\n\nconst getIslandStoreSnapshot = () => {\n\tglobalThis.__ABS_ISLAND_STATE__ ??= {};\n\treturn globalThis.__ABS_ISLAND_STATE__;\n};\n\nconst getIslandStores = () => {\n\tglobalThis.__ABS_ISLAND_STORES__ ??= new Map();\n\treturn globalThis.__ABS_ISLAND_STORES__;\n};\n\nconst isSerializableValue = (value: unknown) =>\n\ttypeof value !== 'function' && value !== undefined;\n\nconst toSerializableState = <T extends IslandStoreState>(state: T) =>\n\tObject.fromEntries(\n\t\tObject.entries(state).filter(([, value]) => isSerializableValue(value))\n\t);\n\nconst applySnapshot = <T extends IslandStoreState>(\n\tstore: StoreApi<T>,\n\tsnapshot: IslandStoreState | undefined\n) => {\n\tif (!snapshot) {\n\t\treturn;\n\t}\n\n\tstore.setState({\n\t\t...store.getState(),\n\t\t...snapshot\n\t});\n};\n\nexport const initializeIslandStores = (state: IslandStateSnapshot) => {\n\tconst currentSnapshot = getIslandStoreSnapshot();\n\tconst nextSnapshot = {\n\t\t...state,\n\t\t...currentSnapshot\n\t};\n\n\tglobalThis.__ABS_ISLAND_STATE__ = nextSnapshot;\n\n\tfor (const [storeId, store] of getIslandStores()) {\n\t\tapplySnapshot(store, nextSnapshot[storeId]);\n\t}\n};\n\nexport const createIslandStore =\n\t(storeId: string) =>\n\t<T extends IslandStoreState>(\n\t\tcreateState: IslandStoreInitializer<T>\n\t) => {\n\t\tconst stores = getIslandStores();\n\t\tconst existingStore = stores.get(storeId);\n\t\tif (existingStore) {\n\t\t\treturn existingStore as StoreApi<T>;\n\t\t}\n\n\t\tconst store = createStore<T>()((set, get, api) =>\n\t\t\tcreateState(\n\t\t\t\t(update) => {\n\t\t\t\t\tset((state) => {\n\t\t\t\t\t\tconst nextPartial =\n\t\t\t\t\t\t\ttypeof update === 'function' ? update(state) : update;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t...nextPartial\n\t\t\t\t\t\t};\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tget,\n\t\t\t\tapi\n\t\t\t)\n\t\t);\n\t\tconst initialSnapshot = getIslandStoreSnapshot()[storeId];\n\t\tapplySnapshot(store, initialSnapshot);\n\n\t\tgetIslandStoreSnapshot()[storeId] = toSerializableState(\n\t\t\tstore.getState()\n\t\t);\n\t\tstore.subscribe((state) => {\n\t\t\tgetIslandStoreSnapshot()[storeId] = toSerializableState(state);\n\t\t});\n\n\t\tstores.set(storeId, store as AnyIslandStore);\n\t\treturn store;\n\t};\n\nexport const readIslandStore = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected\n) => selector(store.getState());\n\nexport const subscribeIslandStore = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected,\n\tlistener: (value: TSelected) => void\n) => {\n\tlet currentSelection = selector(store.getState());\n\n\treturn store.subscribe((state) => {\n\t\tconst nextSelection = selector(state);\n\t\tif (Object.is(nextSelection, currentSelection)) {\n\t\t\treturn;\n\t\t}\n\n\t\tcurrentSelection = nextSelection;\n\t\tlistener(nextSelection);\n\t});\n};\n\nexport const getIslandStoreServerSnapshot = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected\n) => selector(store.getInitialState());\n\nexport const resetIslandStoreForTesting = () => {\n\tdelete globalThis.__ABS_ISLAND_STATE__;\n\tdelete globalThis.__ABS_ISLAND_STORES__;\n};\n\nexport { ABSOLUTE_ISLAND_STATE, ABSOLUTE_ISLAND_STORES };\n"
9
+ "import {\n\tcreateStore,\n\ttype StateCreator,\n\ttype StoreApi\n} from 'zustand/vanilla';\n\nexport type IslandStoreState = Record<string, unknown>;\nexport type IslandStateSnapshot = Record<string, IslandStoreState>;\ntype AnyIslandStore = StoreApi<IslandStoreState>;\ntype IslandStoreInstance = {\n\tapplyExternalSnapshot: (snapshot: IslandStoreState) => void;\n\tstore: AnyIslandStore;\n};\n\nconst ABSOLUTE_ISLAND_STATE = '__ABS_ISLAND_STATE__';\nconst ABSOLUTE_ISLAND_STORES = '__ABS_ISLAND_STORES__';\n\ndeclare global {\n\tvar __ABS_ISLAND_STATE__: IslandStateSnapshot | undefined;\n\tvar __ABS_ISLAND_STORES__:\n\t\t| Map<string, Set<IslandStoreInstance>>\n\t\t| undefined;\n}\n\nconst getIslandStoreSnapshot = () => {\n\tglobalThis.__ABS_ISLAND_STATE__ ??= {};\n\treturn globalThis.__ABS_ISLAND_STATE__;\n};\n\nconst getIslandStores = () => {\n\tglobalThis.__ABS_ISLAND_STORES__ ??= new Map();\n\treturn globalThis.__ABS_ISLAND_STORES__;\n};\n\nconst isSerializableValue = (value: unknown) =>\n\ttypeof value !== 'function' && value !== undefined;\n\nconst toSerializableState = <T extends IslandStoreState>(state: T) =>\n\tObject.fromEntries(\n\t\tObject.entries(state).filter(([, value]) => isSerializableValue(value))\n\t);\n\nconst applySnapshot = <T extends IslandStoreState>(\n\tstore: StoreApi<T>,\n\tsnapshot: IslandStoreState | undefined\n) => {\n\tif (!snapshot) {\n\t\treturn;\n\t}\n\n\tstore.setState({\n\t\t...store.getState(),\n\t\t...snapshot\n\t});\n};\n\nexport const initializeIslandStores = (state: IslandStateSnapshot) => {\n\tconst currentSnapshot = getIslandStoreSnapshot();\n\tconst nextSnapshot = {\n\t\t...state,\n\t\t...currentSnapshot\n\t};\n\n\tglobalThis.__ABS_ISLAND_STATE__ = nextSnapshot;\n\n\tfor (const [storeId, store] of getIslandStores()) {\n\t\tfor (const instance of store) {\n\t\t\tinstance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});\n\t\t}\n\t}\n};\n\nexport const createIslandStore = <T extends IslandStoreState>(\n\tstoreId: string,\n\tcreateState: StateCreator<T, [], []>\n) => {\n\tconst store = createStore<T>(createState);\n\tconst stores = getIslandStores();\n\tconst storeInstances = stores.get(storeId) ?? new Set<IslandStoreInstance>();\n\tconst initialSnapshot = getIslandStoreSnapshot()[storeId];\n\tapplySnapshot(store, initialSnapshot);\n\tlet isApplyingExternalSnapshot = false;\n\n\tconst applyExternalSnapshot = (snapshot: IslandStoreState) => {\n\t\tisApplyingExternalSnapshot = true;\n\t\tapplySnapshot(store, snapshot);\n\t};\n\n\tconst syncSnapshot = (state: T) => {\n\t\tconst nextSnapshot = toSerializableState(state);\n\t\tgetIslandStoreSnapshot()[storeId] = nextSnapshot;\n\n\t\tfor (const peerStore of storeInstances) {\n\t\t\tif (peerStore.store === store) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tpeerStore.applyExternalSnapshot(nextSnapshot);\n\t\t}\n\t};\n\n\tstoreInstances.add({\n\t\tapplyExternalSnapshot,\n\t\tstore\n\t});\n\tstores.set(storeId, storeInstances);\n\n\tsyncSnapshot(store.getState());\n\tstore.subscribe((state) => {\n\t\tif (isApplyingExternalSnapshot) {\n\t\t\tisApplyingExternalSnapshot = false;\n\t\t\treturn;\n\t\t}\n\n\t\tsyncSnapshot(state);\n\t});\n\n\treturn store;\n};\n\nexport const readIslandStore = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected\n) => selector(store.getState());\n\nexport const subscribeIslandStore = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected,\n\tlistener: (value: TSelected) => void\n) => {\n\tlet currentSelection = selector(store.getState());\n\n\treturn store.subscribe((state) => {\n\t\tconst nextSelection = selector(state);\n\t\tif (Object.is(nextSelection, currentSelection)) {\n\t\t\treturn;\n\t\t}\n\n\t\tcurrentSelection = nextSelection;\n\t\tlistener(nextSelection);\n\t});\n};\n\nexport const getIslandStoreServerSnapshot = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected\n) => selector(store.getInitialState());\n\nexport const resetIslandStoreForTesting = () => {\n\tdelete globalThis.__ABS_ISLAND_STATE__;\n\tdelete globalThis.__ABS_ISLAND_STORES__;\n};\n\nexport { ABSOLUTE_ISLAND_STATE, ABSOLUTE_ISLAND_STORES };\n"
10
10
  ],
11
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEM,2BAA2B,CAAC,cACjC,UAAU,IAAI,YAAY,IAAI,UAAU,MAAM,CAAC,GAEnC,uBAAuB,CACnC,WACA,cACI,SAAS,yBAAyB,SAAS,IAAI,aAEvC,2BAA2B,CAAC,aAAqC;AAAA,EAC7E,MAAM,UACL,CAAC;AAAA,EACF,MAAM,aAAgC,CAAC,SAAS,UAAU,OAAO,SAAS;AAAA,EAE1E,WAAW,aAAa,YAAY;AAAA,IACnC,MAAM,SAAS,SAAS,yBAAyB,SAAS;AAAA,IAC1D,YAAY,KAAK,UAAU,OAAO,QAAQ,QAAQ,GAAG;AAAA,MACpD,IAAI,CAAC,IAAI,WAAW,MAAM;AAAA,QAAG;AAAA,MAE7B,MAAM,YAAY,IAAI,MAAM,OAAO,MAAM;AAAA,MACzC,IAAI,CAAC;AAAA,QAAW;AAAA,MAEhB,MAAM,mBAAmB,QAAQ,cAAc,CAAC;AAAA,MAChD,iBAAiB,aAAa;AAAA,MAC9B,QAAQ,aAAa;AAAA,IACtB;AAAA,EACD;AAAA,EAEA,OAAO;AAAA;;;ACQD,SAAS,kBAA6B,CAC5C,WACC;AAAA,EACD,IAAI,4BAA4B,SAAS,GAAG;AAAA,IAC3C,OAAO,UAAU;AAAA,EAClB;AAAA,EAEA,OAAO;AAAA;AAAA,IAtCK,uBAAuB,CACnC,aACI,UAEQ,wBAAwB,CACpC,WACA,aAI2C;AAAA,EAC3C;AAAA,EACA,QAAQ,QAAQ;AAAA,E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AAM,UAAU,CAAC,UAAU;AAAA,IAC1B,IAAI,4BAA4B;AAAA,MAC/B,6BAA6B;AAAA,MAC7B;AAAA,IACD;AAAA,IAEA,aAAa,KAAK;AAAA,GAClB;AAAA,EAED,OAAO;AAAA;AAGD,IAAM,kBAAkB,CAI9B,OACA,aACI,SAAS,MAAM,SAAS,CAAC;AAEvB,IAAM,uBAAuB,CAInC,OACA,UACA,aACI;AAAA,EACJ,IAAI,mBAAmB,SAAS,MAAM,SAAS,CAAC;AAAA,EAEhD,OAAO,MAAM,UAAU,CAAC,UAAU;AAAA,IACjC,MAAM,gBAAgB,SAAS,KAAK;AAAA,IACpC,IAAI,OAAO,GAAG,eAAe,gBAAgB,GAAG;AAAA,MAC/C;AAAA,IACD;AAAA,IAEA,mBAAmB;AAAA,IACnB,SAAS,aAAa;AAAA,GACtB;AAAA;AAGK,IAAM,+BAA+B,CAI3C,OACA,aACI,SAAS,MAAM,gBAAgB,CAAC;;;AFxJ9B,IAAM,qBAAqB,YAAY;AAAA,EAC7C,MAAM,IAAI,MACT,qGACD;AAAA;",
12
+ "debugId": "6FA47D4A1FC4F18F64756E2164756E21",
13
13
  "names": []
14
14
  }
@@ -30266,31 +30266,45 @@ var initializeIslandStores = (state) => {
30266
30266
  };
30267
30267
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
30268
30268
  for (const [storeId, store] of getIslandStores()) {
30269
- applySnapshot(store, nextSnapshot[storeId]);
30269
+ for (const instance of store) {
30270
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
30271
+ }
30270
30272
  }
30271
30273
  };
30272
- var createIslandStore = (storeId) => (createState) => {
30274
+ var createIslandStore = (storeId, createState) => {
30275
+ const store = createStore(createState);
30273
30276
  const stores = getIslandStores();
30274
- const existingStore = stores.get(storeId);
30275
- if (existingStore) {
30276
- return existingStore;
30277
- }
30278
- const store = createStore()((set, get, api) => createState((update) => {
30279
- set((state) => {
30280
- const nextPartial = typeof update === "function" ? update(state) : update;
30281
- return {
30282
- ...state,
30283
- ...nextPartial
30284
- };
30285
- });
30286
- }, get, api));
30277
+ const storeInstances = stores.get(storeId) ?? new Set;
30287
30278
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
30288
30279
  applySnapshot(store, initialSnapshot);
30289
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
30280
+ let isApplyingExternalSnapshot = false;
30281
+ const applyExternalSnapshot = (snapshot) => {
30282
+ isApplyingExternalSnapshot = true;
30283
+ applySnapshot(store, snapshot);
30284
+ };
30285
+ const syncSnapshot = (state) => {
30286
+ const nextSnapshot = toSerializableState(state);
30287
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
30288
+ for (const peerStore of storeInstances) {
30289
+ if (peerStore.store === store) {
30290
+ continue;
30291
+ }
30292
+ peerStore.applyExternalSnapshot(nextSnapshot);
30293
+ }
30294
+ };
30295
+ storeInstances.add({
30296
+ applyExternalSnapshot,
30297
+ store
30298
+ });
30299
+ stores.set(storeId, storeInstances);
30300
+ syncSnapshot(store.getState());
30290
30301
  store.subscribe((state) => {
30291
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
30302
+ if (isApplyingExternalSnapshot) {
30303
+ isApplyingExternalSnapshot = false;
30304
+ return;
30305
+ }
30306
+ syncSnapshot(state);
30292
30307
  });
30293
- stores.set(storeId, store);
30294
30308
  return store;
30295
30309
  };
30296
30310
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30312,5 +30326,5 @@ export {
30312
30326
  createIslandStore
30313
30327
  };
30314
30328
 
30315
- //# debugId=AD17117A97C6F88564756E2164756E21
30329
+ //# debugId=D3E89C1C7CFE1AE664756E2164756E21
30316
30330
  //# sourceMappingURL=index.js.map