@absolutejs/absolute 0.19.0-beta.336 → 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.
@@ -2,14 +2,18 @@ import { type StateCreator, type StoreApi } from 'zustand/vanilla';
2
2
  export type IslandStoreState = Record<string, unknown>;
3
3
  export type IslandStateSnapshot = Record<string, IslandStoreState>;
4
4
  type AnyIslandStore = StoreApi<IslandStoreState>;
5
+ type IslandStoreInstance = {
6
+ applyExternalSnapshot: (snapshot: IslandStoreState) => void;
7
+ store: AnyIslandStore;
8
+ };
5
9
  declare const ABSOLUTE_ISLAND_STATE = "__ABS_ISLAND_STATE__";
6
10
  declare const ABSOLUTE_ISLAND_STORES = "__ABS_ISLAND_STORES__";
7
11
  declare global {
8
12
  var __ABS_ISLAND_STATE__: IslandStateSnapshot | undefined;
9
- var __ABS_ISLAND_STORES__: Map<string, AnyIslandStore> | undefined;
13
+ var __ABS_ISLAND_STORES__: Map<string, Set<IslandStoreInstance>> | undefined;
10
14
  }
11
15
  export declare const initializeIslandStores: (state: IslandStateSnapshot) => void;
12
- export declare const createIslandStore: (storeId: string) => <T extends IslandStoreState>(createState: StateCreator<T, [], []>) => StoreApi<T>;
16
+ export declare const createIslandStore: <T extends IslandStoreState>(storeId: string, createState: StateCreator<T, [], []>) => StoreApi<T>;
13
17
  export declare const readIslandStore: <TState extends IslandStoreState, TSelected>(store: StoreApi<TState>, selector: (state: TState) => TSelected) => TSelected;
14
18
  export declare const subscribeIslandStore: <TState extends IslandStoreState, TSelected>(store: StoreApi<TState>, selector: (state: TState) => TSelected, listener: (value: TSelected) => void) => () => void;
15
19
  export declare const getIslandStoreServerSnapshot: <TState extends IslandStoreState, TSelected>(store: StoreApi<TState>, selector: (state: TState) => TSelected) => TSelected;
@@ -223,23 +223,45 @@ var initializeIslandStores = (state) => {
223
223
  };
224
224
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
225
225
  for (const [storeId, store] of getIslandStores()) {
226
- applySnapshot(store, nextSnapshot[storeId]);
226
+ for (const instance of store) {
227
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
228
+ }
227
229
  }
228
230
  };
229
- var createIslandStore = (storeId) => (createState) => {
231
+ var createIslandStore = (storeId, createState) => {
232
+ const store = createStore(createState);
230
233
  const stores = getIslandStores();
231
- const existingStore = stores.get(storeId);
232
- if (existingStore) {
233
- return existingStore;
234
- }
235
- const store = createStore()(createState);
234
+ const storeInstances = stores.get(storeId) ?? new Set;
236
235
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
237
236
  applySnapshot(store, initialSnapshot);
238
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
237
+ let isApplyingExternalSnapshot = false;
238
+ const applyExternalSnapshot = (snapshot) => {
239
+ isApplyingExternalSnapshot = true;
240
+ applySnapshot(store, snapshot);
241
+ };
242
+ const syncSnapshot = (state) => {
243
+ const nextSnapshot = toSerializableState(state);
244
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
245
+ for (const peerStore of storeInstances) {
246
+ if (peerStore.store === store) {
247
+ continue;
248
+ }
249
+ peerStore.applyExternalSnapshot(nextSnapshot);
250
+ }
251
+ };
252
+ storeInstances.add({
253
+ applyExternalSnapshot,
254
+ store
255
+ });
256
+ stores.set(storeId, storeInstances);
257
+ syncSnapshot(store.getState());
239
258
  store.subscribe((state) => {
240
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
259
+ if (isApplyingExternalSnapshot) {
260
+ isApplyingExternalSnapshot = false;
261
+ return;
262
+ }
263
+ syncSnapshot(state);
241
264
  });
242
- stores.set(storeId, store);
243
265
  return store;
244
266
  };
245
267
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -276,5 +298,5 @@ export {
276
298
  Island_default as Island
277
299
  };
278
300
 
279
- //# debugId=76A6696AFFC9BC4764756E2164756E21
301
+ //# debugId=9FC43098F735C99364756E2164756E21
280
302
  //# sourceMappingURL=browser.js.map
@@ -8,11 +8,11 @@
8
8
  "import type {\n\tIslandRegistry,\n\tIslandRegistryInput,\n\tTypedIslandRenderProps\n} from '../../types/island';\nimport {\n\tgetIslandMarkerAttributes,\n\tserializeIslandAttributes\n} from '../core/islandMarkupAttributes';\n\nexport const createTypedIsland = <T extends IslandRegistryInput>(\n\t_registry: IslandRegistry<T>\n) => {\n\treturn (props: TypedIslandRenderProps<T>) => {\n\t\tconst attributes = getIslandMarkerAttributes(props);\n\t\treturn `<div ${serializeIslandAttributes(attributes)}></div>`;\n\t};\n};\n",
9
9
  "import type { RuntimeIslandRenderProps } from '../../types/island';\nimport {\n\tgetIslandMarkerAttributes,\n\tserializeIslandAttributes\n} from '../core/islandMarkupAttributes';\n\nconst getIslandSnapshot = (slotId: string) => {\n\tif (typeof window === 'undefined') {\n\t\treturn null;\n\t}\n\n\tconst snapshot = window.__ABS_SVELTE_ISLAND_HTML__;\n\tif (!snapshot || typeof snapshot !== 'object') {\n\t\treturn null;\n\t}\n\n\tconst value = snapshot[slotId];\n\treturn typeof value === 'string' ? value : null;\n};\n\nconst buildFallbackMarkup = (props: RuntimeIslandRenderProps) =>\n\t`<div ${serializeIslandAttributes(getIslandMarkerAttributes(props))}></div>`;\n\nexport const resolveIslandHtml = (\n\tslotId: string,\n\tprops: RuntimeIslandRenderProps\n) => {\n\tconst snapshot = getIslandSnapshot(slotId);\n\tif (snapshot !== null) {\n\t\treturn snapshot;\n\t}\n\n\tif (typeof document === 'undefined') {\n\t\treturn buildFallbackMarkup(props);\n\t}\n\n\tconst slot = document.querySelector<HTMLElement>(\n\t\t`[data-absolute-island-slot=\"${slotId}\"]`\n\t);\n\n\treturn slot?.innerHTML ?? buildFallbackMarkup(props);\n};\n",
10
10
  "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",
11
- "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>;\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>(createState: StateCreator<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>()(createState);\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",
11
+ "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",
12
12
  "import type { StoreApi } from 'zustand/vanilla';\nimport {\n\treadIslandStore,\n\tsubscribeIslandStore,\n\ttype IslandStoreState\n} from '../client/islandStore';\n\nexport const useIslandStore = <\n\tTState extends IslandStoreState,\n\tTSelected\n>(\n\tstore: StoreApi<TState>,\n\tselector: (state: TState) => TSelected\n) => ({\n\tsubscribe(listener: (value: TSelected) => void) {\n\t\tlistener(readIslandStore(store, selector));\n\t\treturn subscribeIslandStore(store, selector, listener);\n\t}\n});\n",
13
13
  "export { default as Island } from './components/Island.svelte';\nexport { createTypedIsland } from './createIsland.browser';\nexport { resolveIslandHtml } from './resolveIslandHtml.browser';\nexport { useIslandStore } from './islandStore';\n\nexport const renderIsland = async () => {\n\tthrow new Error(\n\t\t'renderIsland is server-only. Use it during SSR, not in the browser.'\n\t);\n};\n"
14
14
  ],
15
- "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;AA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,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;;;ACpJ9B,IAAM,iBAAiB,CAI7B,OACA,cACK;AAAA,EACL,SAAS,CAAC,UAAsC;AAAA,IAC/C,SAAS,gBAAgB,OAAO,QAAQ,CAAC;AAAA,IACzC,OAAO,qBAAqB,OAAO,UAAU,QAAQ;AAAA;AAEvD;;;ACbO,IAAM,eAAe,YAAY;AAAA,EACvC,MAAM,IAAI,MACT,qEACD;AAAA;",
16
+ "debugId": "9FC43098F735C99364756E2164756E21",
17
17
  "names": []
18
18
  }
@@ -30719,23 +30719,45 @@ var initializeIslandStores = (state) => {
30719
30719
  };
30720
30720
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
30721
30721
  for (const [storeId, store] of getIslandStores()) {
30722
- applySnapshot(store, nextSnapshot[storeId]);
30722
+ for (const instance of store) {
30723
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
30724
+ }
30723
30725
  }
30724
30726
  };
30725
- var createIslandStore = (storeId) => (createState) => {
30727
+ var createIslandStore = (storeId, createState) => {
30728
+ const store = createStore(createState);
30726
30729
  const stores = getIslandStores();
30727
- const existingStore = stores.get(storeId);
30728
- if (existingStore) {
30729
- return existingStore;
30730
- }
30731
- const store = createStore()(createState);
30730
+ const storeInstances = stores.get(storeId) ?? new Set;
30732
30731
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
30733
30732
  applySnapshot(store, initialSnapshot);
30734
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
30733
+ let isApplyingExternalSnapshot = false;
30734
+ const applyExternalSnapshot = (snapshot) => {
30735
+ isApplyingExternalSnapshot = true;
30736
+ applySnapshot(store, snapshot);
30737
+ };
30738
+ const syncSnapshot = (state) => {
30739
+ const nextSnapshot = toSerializableState(state);
30740
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
30741
+ for (const peerStore of storeInstances) {
30742
+ if (peerStore.store === store) {
30743
+ continue;
30744
+ }
30745
+ peerStore.applyExternalSnapshot(nextSnapshot);
30746
+ }
30747
+ };
30748
+ storeInstances.add({
30749
+ applyExternalSnapshot,
30750
+ store
30751
+ });
30752
+ stores.set(storeId, storeInstances);
30753
+ syncSnapshot(store.getState());
30735
30754
  store.subscribe((state) => {
30736
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
30755
+ if (isApplyingExternalSnapshot) {
30756
+ isApplyingExternalSnapshot = false;
30757
+ return;
30758
+ }
30759
+ syncSnapshot(state);
30737
30760
  });
30738
- stores.set(storeId, store);
30739
30761
  return store;
30740
30762
  };
30741
30763
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30780,5 +30802,5 @@ export {
30780
30802
  Island_default as Island
30781
30803
  };
30782
30804
 
30783
- //# debugId=B394FD8C9FC7503F64756E2164756E21
30805
+ //# debugId=9CFC1F9433B3007E64756E2164756E21
30784
30806
  //# sourceMappingURL=index.js.map