cogsbox-state 0.5.489 → 0.5.490

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/src/plugins.ts CHANGED
@@ -27,12 +27,14 @@ export type ChainMethodContext<TOptions = any, THookReturn = any> = {
27
27
  $update: (payload: any) => { synced: () => void };
28
28
  $applyOperation: (operation: any, metaData?: Record<string, any>) => void;
29
29
  getFieldMetaData: () => any;
30
- setFieldMetaData: (data: Record<string, any>) => void;
31
- removeFieldMetaData: () => void;
32
- getFieldRefs: () => RefObject<any>[];
33
- getFieldElements: () => HTMLElement[];
34
- setFieldDisabled: (disabled: boolean) => void;
35
- };
30
+ setFieldMetaData: (data: Record<string, any>) => void;
31
+ removeFieldMetaData: () => void;
32
+ watchPluginMeta: (scope?: string) => void;
33
+ notifyPluginMeta: (scope?: string) => void;
34
+ getFieldRefs: () => RefObject<any>[];
35
+ getFieldElements: () => HTMLElement[];
36
+ setFieldDisabled: (disabled: boolean) => void;
37
+ };
36
38
 
37
39
  export type ChainMethodHandler = (
38
40
  ctx: ChainMethodContext<any, any>,
package/src/store.ts CHANGED
@@ -4,7 +4,6 @@ import type { RefObject } from 'react';
4
4
  import type {
5
5
  OptionsType,
6
6
  ReactivityType,
7
- SyncInfo,
8
7
  UpdateTypeDetail,
9
8
  } from './CogsState.js';
10
9
 
@@ -134,18 +133,14 @@ export type ShadowMetadata = {
134
133
  value?: any;
135
134
  id?: string;
136
135
  typeInfo?: SchemaTypeInfo;
137
- stateSource?: 'default' | 'server' | 'localStorage';
138
- lastServerSync?: number;
139
- isDirty?: boolean;
140
136
  isRaw?: boolean;
141
- baseServerState?: any;
142
137
  arrayKeys?: string[];
143
138
  fields?: Record<string, any>;
144
139
  virtualizer?: {
145
140
  itemHeight?: number;
146
141
  domRef?: HTMLElement | null;
147
142
  };
148
- syncInfo?: { status: string };
143
+
149
144
  validation?: ValidationState;
150
145
  features?: {
151
146
  localStorageEnabled: boolean;
@@ -252,12 +247,6 @@ export type CogsGlobalState = {
252
247
  dependencyPath: string[],
253
248
  fullComponentId: string
254
249
  ) => void;
255
- markAsDirty: (
256
- key: string,
257
- path: string[],
258
- options: { bubble: boolean }
259
- ) => void;
260
-
261
250
  pathSubscribers: Map<string, Set<(newValue: any) => void>>;
262
251
  subscribeToPath: (
263
252
  path: string,
@@ -278,23 +267,8 @@ export type CogsGlobalState = {
278
267
  getInitialOptions: (key: string) => OptionsType | undefined;
279
268
  setInitialStateOptions: (key: string, value: OptionsType) => void;
280
269
 
281
- serverStateUpdates: Map<
282
- string,
283
- {
284
- data: any;
285
- status: 'loading' | 'success' | 'error';
286
- timestamp: number;
287
- }
288
- >;
289
-
290
- setServerStateUpdate: (key: string, serverState: any) => void;
291
-
292
270
  stateLog: Map<string, Map<string, UpdateTypeDetail>>;
293
- syncInfoStore: Map<string, SyncInfo>;
294
271
  addStateLog: (updates: UpdateTypeDetail[]) => void;
295
-
296
- setSyncInfo: (key: string, syncInfo: SyncInfo) => void;
297
- getSyncInfo: (key: string) => SyncInfo | null;
298
272
  };
299
273
  function getTypeFromZodSchema(
300
274
  schema: any,
@@ -787,9 +761,6 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
787
761
  const {
788
762
  components,
789
763
  features,
790
- lastServerSync,
791
- stateSource,
792
- baseServerState,
793
764
  pathComponents,
794
765
  signals,
795
766
  validation,
@@ -797,9 +768,6 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
797
768
 
798
769
  if (components) preservedMetadata.components = components;
799
770
  if (features) preservedMetadata.features = features;
800
- if (lastServerSync) preservedMetadata.lastServerSync = lastServerSync;
801
- if (stateSource) preservedMetadata.stateSource = stateSource;
802
- if (baseServerState) preservedMetadata.baseServerState = baseServerState;
803
771
  if (pathComponents) preservedMetadata.pathComponents = pathComponents;
804
772
  if (signals) preservedMetadata.signals = signals;
805
773
  if (validation) preservedMetadata.validation = validation;
@@ -962,15 +930,9 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
962
930
  const {
963
931
  components,
964
932
  features,
965
- lastServerSync,
966
- stateSource,
967
- baseServerState,
968
933
  } = existingRoot._meta;
969
934
  if (components) preservedMetadata.components = components;
970
935
  if (features) preservedMetadata.features = features;
971
- if (lastServerSync) preservedMetadata.lastServerSync = lastServerSync;
972
- if (stateSource) preservedMetadata.stateSource = stateSource;
973
- if (baseServerState) preservedMetadata.baseServerState = baseServerState;
974
936
  }
975
937
 
976
938
  shadowStateStore.delete(key);
@@ -1467,55 +1429,6 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
1467
1429
  }
1468
1430
  },
1469
1431
 
1470
- markAsDirty: (key, path, options = { bubble: true }) => {
1471
- // Start at the root node once.
1472
- let rootNode = get().getShadowNode(key, []);
1473
- if (!rootNode) return;
1474
-
1475
- // Navigate to the target node once.
1476
- let currentNode = rootNode;
1477
- for (const segment of path) {
1478
- currentNode = currentNode[segment];
1479
- if (!currentNode) return; // Path doesn't exist, nothing to mark.
1480
- }
1481
-
1482
- // Mark the target node as dirty.
1483
- if (!currentNode._meta) currentNode._meta = {};
1484
- currentNode._meta.isDirty = true;
1485
-
1486
- // If bubbling is disabled, we are done.
1487
- if (!options.bubble) return;
1488
-
1489
- // Efficiently bubble up using the path segments.
1490
- let parentNode = rootNode;
1491
- for (let i = 0; i < path.length; i++) {
1492
- // The current node in the loop is the parent of the next one.
1493
- if (parentNode._meta?.isDirty) {
1494
- // Optimization: If a parent is already dirty, all of its ancestors are too.
1495
- // We can stop bubbling immediately.
1496
- return;
1497
- }
1498
- if (!parentNode._meta) parentNode._meta = {};
1499
- parentNode._meta.isDirty = true;
1500
- parentNode = parentNode[path[i]!];
1501
- }
1502
- },
1503
-
1504
- // Keep these in Zustand as they need React reactivity
1505
- serverStateUpdates: new Map(),
1506
- setServerStateUpdate: (key, serverState) => {
1507
- set((state) => ({
1508
- serverStateUpdates: new Map(state.serverStateUpdates).set(
1509
- key,
1510
- serverState
1511
- ),
1512
- }));
1513
- get().notifyPathSubscribers(key, {
1514
- type: 'SERVER_STATE_UPDATE',
1515
- serverState,
1516
- });
1517
- },
1518
-
1519
1432
  pathSubscribers: new Map<string, Set<(newValue: any) => void>>(),
1520
1433
  subscribeToPath: (path, callback) => {
1521
1434
  const subscribers = get().pathSubscribers;
@@ -1654,14 +1567,7 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
1654
1567
  }));
1655
1568
  },
1656
1569
 
1657
- syncInfoStore: new Map<string, SyncInfo>(),
1658
- setSyncInfo: (key, syncInfo) =>
1659
- set((state) => {
1660
- const newMap = new Map(state.syncInfoStore);
1661
- newMap.set(key, syncInfo);
1662
- return { syncInfoStore: newMap };
1663
- }),
1664
- getSyncInfo: (key) => get().syncInfoStore.get(key) || null,
1570
+ // Removed: syncInfo is now owned by Shape Plugin
1665
1571
  }));
1666
1572
 
1667
1573
  export function getAllFieldElements(stateKey: string): HTMLElement[] {