@@ -6415,13 +6415,54 @@ export function DataPillar({
64156415 // that does not parse must not be saveable, let alone publishable as the live
64166416 // field definition (objectui#4306).
64176417 //
6418- // The count is STAMPED with the selection it came from, so it expires by
6419- // construction when the selection changes or the panel closes: an unmounted
6420- // inspector can never retract its last verdict, and a host that waited for
6421- // one would leave Save wedged shut with nothing on screen to fix.
6418+ // The report is STAMPED with the selection it came from: it is the open
6419+ // inspector's live verdict, and never reads as another selection's.
64226420 const [ blockingReport , setBlockingReport ] = React . useState ( { key : '' , count : 0 } ) ;
64236421 const fieldSelKey = fieldSel ? `${ current ?. name ?? '' } :${ fieldSel . kind } :${ fieldSel . id } ` : '' ;
6424- const inspectorBlocking = blockingReport . key === fieldSelKey ? blockingReport . count : 0 ;
6422+ // objectstack#27485 — the verdict belongs to the draft, not to the selection.
6423+ // Expiring it with the selection released the hold the moment the inspector
6424+ // closed (Escape, Close, another field, another tab) while the broken text
6425+ // stayed in the draft, and the autosave sent it. So each field's last live
6426+ // verdict is kept with the stamp of what it judged (`fieldCelStamp`, taken
6427+ // while the inspector is open on it) and holds, with the inspector closed,
6428+ // while the draft still carries that stamp: an edit to the text, the field's
6429+ // removal or the object's next load ends it. Nothing is left shut with
6430+ // nothing to fix: the held line names the field and its "Show me" opens it,
6431+ // and the open inspector's live verdict always wins.
6432+ const [ celVerdicts , setCelVerdicts ] = React . useState < Record < string , { field : string ; count : number ; stamp : string | null } > > ( { } ) ;
6433+ const liveFieldReport = fieldSel ?. kind === 'field' && blockingReport . key === fieldSelKey ;
6434+ const openFieldStamp = fieldSel ?. kind === 'field' ? fieldCelStamp ( objDraft , fieldSel . id ) : null ;
6435+ React . useEffect ( ( ) => {
6436+ if ( ! liveFieldReport || fieldSel === null ) return ;
6437+ const kept = { field : fieldSel . id , count : blockingReport . count , stamp : openFieldStamp } ;
6438+ setCelVerdicts ( ( prev ) => {
6439+ const was = prev [ fieldSelKey ] ;
6440+ if ( was && was . count === kept . count && was . stamp === kept . stamp ) return prev ;
6441+ return { ...prev , [ fieldSelKey ] : kept } ;
6442+ } ) ;
6443+ } , [ liveFieldReport , fieldSel , fieldSelKey , blockingReport . count , openFieldStamp ] ) ;
6444+ // The open object's fields whose verdict holds, and their summed count.
6445+ const celHeldFields : string [ ] = [ ] ;
6446+ let inspectorBlocking = 0 ;
6447+ const celFieldPrefix = `${ current ?. name ?? '' } :field:` ;
6448+ for ( const [ key , kept ] of Object . entries ( celVerdicts ) ) {
6449+ if ( ! key . startsWith ( celFieldPrefix ) || key === fieldSelKey ) continue ;
6450+ if ( kept . count > 0 && kept . stamp === fieldCelStamp ( objDraft , kept . field ) ) {
6451+ celHeldFields . push ( kept . field ) ;
6452+ inspectorBlocking += kept . count ;
6453+ }
6454+ }
6455+ if ( blockingReport . key === fieldSelKey && blockingReport . count > 0 ) {
6456+ if ( fieldSel ?. kind === 'field' ) celHeldFields . push ( fieldSel . id ) ;
6457+ inspectorBlocking += blockingReport . count ;
6458+ } else if ( fieldSelKey !== '' && ! liveFieldReport ) {
6459+ // Opened, and its inspector has not reported yet: its kept verdict stands.
6460+ const kept = celVerdicts [ fieldSelKey ] ;
6461+ if ( kept && kept . count > 0 && kept . stamp === openFieldStamp ) {
6462+ celHeldFields . push ( kept . field ) ;
6463+ inspectorBlocking += kept . count ;
6464+ }
6465+ }
64256466 // The pillar's PANEL family reports separately (objectui#4527): the
64266467 // validations, actions and settings panels all write through this same draft
64276468 // and own no Save of their own, so their CEL faults have to reach this
@@ -6691,6 +6732,8 @@ export function DataPillar({
66916732 setLoading ( true ) ;
66926733 setError ( null ) ;
66936734 setFieldSel ( null ) ;
6735+ // objectstack#27485 — kept CEL verdicts judged the buffer this load replaces.
6736+ setCelVerdicts ( { } ) ;
66946737 setDirty ( false ) ;
66956738 ( async ( ) => {
66966739 try {
@@ -6958,7 +7001,7 @@ export function DataPillar({
69587001
69597002 // objectui#5813 — auto-save replaces the Save draft button; the blocked guard
69607003 // is the button's old disabled-condition verbatim, plus the hold above.
6961- const { sending : sendingObjDraft , loaded : objLoaded } = useDraftAutoSave ( {
7004+ const { flush : flushObjSave , sending : sendingObjDraft , loaded : objLoaded } = useDraftAutoSave ( {
69627005 // objectui#11232 — the object `doSave` addresses.
69637006 target : `object:${ current ?. name ?? '' } ` ,
69647007 loadedFor : objDraftFor ,
@@ -6967,8 +7010,27 @@ export function DataPillar({
69677010 snapshot : objDraft ,
69687011 save : doSave ,
69697012 } ) ;
7013+ // objectstack#27485 — an unsent edit the CEL verdict holds is named like an
7014+ // incomplete one: the held line, the surface's Publish and the rail's
7015+ // question all read it, so it outlives the inspector without going unseen.
7016+ const celHeldField = celHeldFields [ 0 ] ?? null ;
7017+ const celHeldLabel = React . useMemo ( ( ) => {
7018+ if ( celHeldField === null ) return null ;
7019+ const label = readFields ( objDraft . fields ) . entries . find ( ( e ) => e . name === celHeldField ) ?. def . label ;
7020+ return typeof label === 'string' && label . trim ( ) !== '' ? label . trim ( ) : celHeldField ;
7021+ } , [ celHeldField , objDraft . fields ] ) ;
7022+ const objCelHeld = React . useMemo < StudioHeld | null > (
7023+ ( ) =>
7024+ dirty && celHeldField !== null && celHeldLabel !== null
7025+ ? {
7026+ clause : tFormat ( 'engine.studio.held.celInvalid' , locale , { field : celHeldLabel } ) ,
7027+ target : { kind : 'field' , id : celHeldField } ,
7028+ }
7029+ : null ,
7030+ [ dirty , celHeldField , celHeldLabel , locale ] ,
7031+ ) ;
69707032 // Only the open object's own buffer is held (objectui#11272).
6971- const objHeld = objLoaded ? objIncomplete : null ;
7033+ const objHeld = objLoaded ? ( objIncomplete ?? objCelHeld ) : null ;
69727034 // objectstack#26917 — the refusal's way out: the object holding the
69737035 // identifier is on this rail, so it opens instead of a second one being
69747036 // made. The New button already asked about a held edit (objectstack#26845).
@@ -6985,19 +7047,56 @@ export function DataPillar({
69857047 const fieldAgentMark =
69867048 objLoaded && fieldSel ?. kind === 'field' ? agentDraftMarkOf ( objDraftChanges , [ 'fields' , fieldSel . id ] ) : null ;
69877049 useHeldEditReport ( onHeldEditChange , objHeld ?. clause ?? null ) ;
7050+ // objectstack#27511 — opening another object replaces the one buffer the
7051+ // open object's edits live in, and the autosave's timer sends nothing once
7052+ // the open object has changed (objectui#11232). So an edit still inside the
7053+ // debounce was dropped by the switch with nothing on screen. The switch now
7054+ // sends it first with the autosave's own `flush` and opens the object once
7055+ // the buffer is clean, as the Interfaces nav's "Done" closes (objectui#11189);
7056+ // a save already in flight is waited out the same way. An edit that cannot
7057+ // be sent (held, or its save refused with the refusal on screen) is the
7058+ // author's to drop: the switch asks (objectstack#26705).
7059+ const [ switchTo , setSwitchTo ] = React . useState < Surface | null > ( null ) ;
7060+ const openObject = React . useCallback (
7061+ ( next : Surface ) : boolean => {
7062+ if ( next . name === current ?. name ) {
7063+ setSwitchTo ( null ) ;
7064+ setCurrent ( next ) ;
7065+ return true ;
7066+ }
7067+ if ( saving || ( dirty && objHeld === null && flushObjSave ( ) ) ) {
7068+ setSwitchTo ( next ) ;
7069+ return true ;
7070+ }
7071+ if ( ! confirmDropUnsavedWork ( dirty , locale ) ) return false ;
7072+ setSwitchTo ( null ) ;
7073+ setCurrent ( next ) ;
7074+ return true ;
7075+ } ,
7076+ [ current , saving , dirty , objHeld , flushObjSave , locale ] ,
7077+ ) ;
7078+ React . useEffect ( ( ) => {
7079+ if ( ! switchTo || saving ) return ;
7080+ if ( dirty && objHeld === null && flushObjSave ( ) ) return ;
7081+ setSwitchTo ( null ) ;
7082+ // Still dirty: the save was refused (on screen) or an edit taken meanwhile
7083+ // is held. The author stays; the next switch asks.
7084+ if ( dirty ) return ;
7085+ setCurrent ( switchTo ) ;
7086+ } , [ switchTo , saving , dirty , objHeld , flushObjSave ] ) ;
69887087 // The live request's apply (see `requestedSurface` above). objectstack#26845
69897088 // — another object's load replaces the buffer a held edit lives in, so it
6990- // asks first, as the rail does; declined, the request is spent and the held
7089+ // goes through the rail's own switch (`openObject`): an unsent edit is sent
7090+ // first, or the author is asked; declined, the request is spent and the
69917091 // edit stays. A request for the open object drops nothing and asks nothing.
69927092 React . useEffect ( ( ) => {
69937093 if ( ! requestedSurface || ! objectsLoaded ) return ;
69947094 if ( requestedSurface . id === appliedRequestRef . current ) return ;
69957095 appliedRequestRef . current = requestedSurface . id ;
69967096 const match = resolveSurfaceDeepLink ( objects , requestedSurface . target , 'object' ) ;
69977097 if ( ! match ) return ;
6998- if ( match . name !== current ?. name && ! confirmDropUnsavedWork ( objHeld !== null , locale ) ) return ;
6999- setCurrent ( match ) ;
7000- } , [ requestedSurface , objects , objectsLoaded , current , objHeld , locale ] ) ;
7098+ openObject ( match ) ;
7099+ } , [ requestedSurface , objects , objectsLoaded , openObject ] ) ;
70017100 // objectstack#26845 — a created object opens at once, and its load replaces
70027101 // the buffer a held edit lives in: asked before the dialog opens, so Cancel
70037102 // costs nothing and the create itself asks nothing.
@@ -7283,11 +7382,10 @@ export function DataPillar({
72837382 key = { o . name }
72847383 active = { current ?. name === o . name }
72857384 onClick = { ( ) => {
7286- // objectstack#26705 — another object's load replaces the
7287- // buffer the held edit lives in; the open one keeps it.
7288- if ( current ?. name !== o . name && ! confirmDropUnsavedWork ( objHeld !== null , locale ) ) return ;
7289- setCurrent ( o ) ;
7290- if ( isMobile ) setRailOpen ( false ) ;
7385+ // objectstack#26705, objectstack#27511 — another object's load
7386+ // replaces the buffer the open one's edits live in: they are
7387+ // sent first, or the author is asked (`openObject`).
7388+ if ( openObject ( o ) && isMobile ) setRailOpen ( false ) ;
72917389 } }
72927390 icon = { < Icon className = "h-4 w-4 shrink-0" /> }
72937391 >
0 commit comments