@ai-matrx/design-system 0.18.2 → 0.18.3

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.
@@ -2378,6 +2378,10 @@ function materialIdentity(material) {
2378
2378
  }
2379
2379
  return `payload:${id}`;
2380
2380
  }
2381
+ function snapshotContent(snapshot) {
2382
+ const { sourceId, label, payload, coverage, unsavedChanges, omissions, sections, limits } = snapshot;
2383
+ return JSON.stringify({ sourceId, label, payload, coverage, unsavedChanges, omissions, sections, limits });
2384
+ }
2381
2385
  function useFence() {
2382
2386
  const mounted = React12.useRef(true);
2383
2387
  const nextId = React12.useRef(0);
@@ -2480,7 +2484,7 @@ function ContentTransferMenuSession({ source, surface, label, projection, sectio
2480
2484
  const captured = await material.capture(signal);
2481
2485
  sourceMaterial = { id: captured.snapshot.sourceId, label: captured.snapshot.label, capture: async () => captured };
2482
2486
  } else if ("kind" in material) {
2483
- sourceMaterial = applyMenuProjection ? { id: "direct", label: sourceLabel, capture: async () => (0, import_content_transfer.directSource)(material, { label: sourceLabel, ...projection ? { projection } : {}, ...sections ? { sections } : {} }) } : material;
2487
+ sourceMaterial = { id: materialIdentity(material), label: sourceLabel, capture: async () => (0, import_content_transfer.directSource)(material, { sourceId: materialIdentity(material), label: sourceLabel, ...applyMenuProjection && projection ? { projection } : {}, ...applyMenuProjection && sections ? { sections } : {} }) };
2484
2488
  } else if (applyMenuProjection && (projection || sections)) {
2485
2489
  sourceMaterial = {
2486
2490
  id: material.id,
@@ -2497,7 +2501,7 @@ function ContentTransferMenuSession({ source, surface, label, projection, sectio
2497
2501
  } else {
2498
2502
  sourceMaterial = material;
2499
2503
  }
2500
- const raw = "kind" in sourceMaterial ? (0, import_content_transfer.directSource)(sourceMaterial) : await sourceMaterial.capture({ scope, signal });
2504
+ const raw = await sourceMaterial.capture({ scope, signal });
2501
2505
  const constrained = (0, import_content_transfer.resolveTransferPreferences)(providerPreferences, preferences, raw.snapshot.limits);
2502
2506
  const result = await (0, import_content_transfer.capture)({ id: raw.snapshot.sourceId, label: raw.snapshot.label, capture: async () => ({ ...raw, snapshot: { ...raw.snapshot, limits: constrained.limits } }) }, signal, scope);
2503
2507
  if (scope !== "all-matching" || !collectPages) return result;
@@ -2557,31 +2561,117 @@ function ContentTransferMenuSession({ source, surface, label, projection, sectio
2557
2561
  fence.finish(controller);
2558
2562
  }
2559
2563
  }, [captureOne, capturePrimary, fence, formatSources, initialScope, preferences, providerPreferences, report, transport]);
2560
- const openWorkspace = React12.useCallback(async (key = primaryWorkspaceKey, variant) => {
2561
- const variantMaterial = variant && "kind" in variant.source ? { id: `variant:${key}`, label: variant.label, capture: async () => (0, import_content_transfer.directSource)(variant.source, { label: variant.label }) } : variant?.source;
2562
- const captureWorkspace = variantMaterial ? (scope, signal) => captureOne(variantMaterial, scope, signal, true) : capturePrimary;
2563
- workspaceCaptures.current.set(key, captureWorkspace);
2564
- if (workspaces[key]) {
2565
- setWorkspaceKey(key);
2566
- setWorkspaceOpen(true);
2567
- return;
2568
- }
2569
- const { controller, id } = fence.begin();
2570
- try {
2571
- const result = await captureWorkspace(initialScope, controller.signal);
2572
- if (!fence.valid(id, controller)) return;
2573
- const resolved = (0, import_content_transfer.resolveTransferPreferences)(providerPreferences, preferences, result.snapshot.limits);
2574
- const original = (0, import_content_transfer.createDraft)(result.snapshot);
2575
- const base = { ...result, key, original, draft: original, scope: initialScope, preferences: resolved, ...result.collectionError ? { error: result.collectionError } : {} };
2576
- setWorkspaces((current) => ({ ...current, [key]: { ...base, draft: rebuild(base, initialControls(base)) } }));
2577
- setWorkspaceKey(key);
2578
- setWorkspaceOpen(true);
2579
- } catch (error) {
2580
- if (fence.valid(id, controller)) setNotice(errorMessage(error, "Could not capture content"));
2581
- } finally {
2582
- fence.finish(controller);
2583
- }
2584
- }, [captureOne, capturePrimary, fence, initialScope, preferences, primaryWorkspaceKey, providerPreferences, workspaces]);
2564
+ const openWorkspace = React12.useCallback(
2565
+ async (key = primaryWorkspaceKey, variant) => {
2566
+ const variantMaterial = variant && "kind" in variant.source ? {
2567
+ id: `variant:${key}`,
2568
+ label: variant.label,
2569
+ capture: async () => (0, import_content_transfer.directSource)(variant.source, {
2570
+ sourceId: `variant:${key}`,
2571
+ label: variant.label
2572
+ })
2573
+ } : variant?.source;
2574
+ const captureWorkspace = (scope, signal, collectPages = true) => captureOne(variantMaterial ?? primary, scope, signal, true, collectPages);
2575
+ workspaceCaptures.current.set(key, captureWorkspace);
2576
+ const existing = workspaces[key];
2577
+ const { controller, id } = fence.begin();
2578
+ if (existing) {
2579
+ try {
2580
+ const allMatching = existing.scope === "all-matching";
2581
+ const fresh = await captureWorkspace(
2582
+ existing.scope,
2583
+ controller.signal,
2584
+ !allMatching
2585
+ );
2586
+ if (!fence.valid(id, controller) || !workspaceCaptures.current.has(key))
2587
+ return;
2588
+ if (allMatching && (!existing.allMatching || !fresh.allMatching))
2589
+ throw new Error(
2590
+ "This source can no longer provide an all-matching snapshot."
2591
+ );
2592
+ const collectionIdentity = (value) => value && {
2593
+ query: value.source.query,
2594
+ projection: value.projection,
2595
+ columns: value.columns,
2596
+ limits: value.limits
2597
+ };
2598
+ const changed = allMatching ? JSON.stringify(collectionIdentity(existing.allMatching)) !== JSON.stringify(collectionIdentity(fresh.allMatching)) : snapshotContent(existing.snapshot) !== snapshotContent(fresh.snapshot);
2599
+ setWorkspaces((current) => {
2600
+ const retained = current[key];
2601
+ if (!retained) return current;
2602
+ return {
2603
+ ...current,
2604
+ [key]: {
2605
+ ...retained,
2606
+ error: fresh.collectionError,
2607
+ ...allMatching ? { sourceStale: changed } : changed ? { pending: { ...fresh, scope: retained.scope } } : { pending: void 0 }
2608
+ }
2609
+ };
2610
+ });
2611
+ setWorkspaceKey(key);
2612
+ setWorkspaceOpen(true);
2613
+ } catch (error) {
2614
+ if (fence.valid(id, controller) && workspaceCaptures.current.has(key)) {
2615
+ setWorkspaces(
2616
+ (current) => current[key] ? {
2617
+ ...current,
2618
+ [key]: {
2619
+ ...current[key],
2620
+ error: errorMessage(error, "Could not refresh source")
2621
+ }
2622
+ } : current
2623
+ );
2624
+ setWorkspaceKey(key);
2625
+ setWorkspaceOpen(true);
2626
+ }
2627
+ } finally {
2628
+ fence.finish(controller);
2629
+ }
2630
+ return;
2631
+ }
2632
+ try {
2633
+ const result = await captureWorkspace(initialScope, controller.signal);
2634
+ if (!fence.valid(id, controller)) return;
2635
+ const resolved = (0, import_content_transfer.resolveTransferPreferences)(
2636
+ providerPreferences,
2637
+ preferences,
2638
+ result.snapshot.limits
2639
+ );
2640
+ const original = (0, import_content_transfer.createDraft)(result.snapshot);
2641
+ const base = {
2642
+ ...result,
2643
+ key,
2644
+ original,
2645
+ draft: original,
2646
+ scope: initialScope,
2647
+ preferences: resolved,
2648
+ ...result.collectionError ? { error: result.collectionError } : {}
2649
+ };
2650
+ setWorkspaces((current) => ({
2651
+ ...current,
2652
+ [key]: { ...base, draft: rebuild(base, initialControls(base)) }
2653
+ }));
2654
+ setWorkspaceKey(key);
2655
+ setWorkspaceOpen(true);
2656
+ } catch (error) {
2657
+ if (fence.valid(id, controller))
2658
+ setNotice(errorMessage(error, "Could not capture content"));
2659
+ } finally {
2660
+ fence.finish(controller);
2661
+ }
2662
+ },
2663
+ [
2664
+ captureOne,
2665
+ capturePrimary,
2666
+ fence,
2667
+ initialScope,
2668
+ preferences,
2669
+ primaryWorkspaceKey,
2670
+ primary,
2671
+ providerPreferences,
2672
+ workspaces
2673
+ ]
2674
+ );
2585
2675
  React12.useImperativeHandle(controllerRef, () => ({
2586
2676
  focusTrigger: () => triggerRef.current?.focus(),
2587
2677
  prepare: async (requestedSource, options) => {
@@ -2804,7 +2894,7 @@ function PreparationWorkspace({ restoreFocus, open, state, scopes, onClose, onCh
2804
2894
  setBusy("capture");
2805
2895
  try {
2806
2896
  const result = await captureScope(scope, controller.signal);
2807
- if (fence.valid(id, controller) && latest.current.draft.revision === revision) onChange({ ...latest.current, pending: { ...result, scope }, error: result.collectionError });
2897
+ if (fence.valid(id, controller) && latest.current.draft.revision === revision) onChange({ ...latest.current, pending: { ...result, scope }, sourceStale: false, error: result.collectionError });
2808
2898
  } catch (error) {
2809
2899
  if (fence.valid(id, controller)) onChange({ ...latest.current, error: errorMessage(error, "Refresh failed") });
2810
2900
  } finally {
@@ -3047,6 +3137,7 @@ function PreparationWorkspace({ restoreFocus, open, state, scopes, onClose, onCh
3047
3137
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { type: "button", variant: "outline", onClick: () => setPendingControls(null), children: "Keep edited draft" }),
3048
3138
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { type: "button", onClick: applyPendingControls, children: "Rebuild from source" })
3049
3139
  ] }) : null,
3140
+ state.sourceStale ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { role: "alert", className: "matrx-alchemy-decision", children: "The source changed since this draft. Use Refresh source to review the latest data." }) : null,
3050
3141
  state.pending ? /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "matrx-alchemy-decision", role: "alert", children: [
3051
3142
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { children: "A fresh source snapshot is ready." }),
3052
3143
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button, { type: "button", variant: "outline", onClick: () => resolveCapture("keep"), children: "Keep current snapshot and draft" }),