@@ -4,7 +4,6 @@ import { action } from '@ember/object';
4
4
import type Owner from ' @ember/owner' ;
5
5
import { service } from ' @ember/service' ;
6
6
import Component from ' @glimmer/component' ;
7
- import { tracked } from ' @glimmer/tracking' ;
8
7
9
8
import Folder from ' @cardstack/boxel-icons/folder' ;
10
9
import { restartableTask , task } from ' ember-concurrency' ;
@@ -248,11 +247,13 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
248
247
{{/if }}
249
248
{{/if }}
250
249
</div >
251
- <FormatChooser
252
- class =' format-chooser'
253
- @ format ={{this .format }}
254
- @ setFormat ={{this .setFormat }}
255
- />
250
+ {{#if this . card }}
251
+ <FormatChooser
252
+ class =' format-chooser'
253
+ @ format ={{this .format }}
254
+ @ setFormat ={{this .setFormat }}
255
+ />
256
+ {{/if }}
256
257
</div >
257
258
<style scoped >
258
259
.playground-panel-content {
@@ -356,8 +357,10 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
356
357
@service private declare realm: RealmService ;
357
358
@service private declare realmServer: RealmServerService ;
358
359
@service declare recentFilesService: RecentFilesService ;
359
- @tracked private format: Format = ' isolated' ;
360
- private playgroundSelections: Record <string , string >;
360
+ private playgroundSelections: Record <
361
+ string , // moduleId
362
+ { cardId: string ; format: Format }
363
+ >; // TrackedObject
361
364
362
365
constructor (owner : Owner , args : PlaygroundContentSignature [' Args' ]) {
363
366
super (owner , args );
@@ -404,22 +407,27 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
404
407
};
405
408
}
406
409
407
- private cardResource = getCard (this , () =>
408
- this .playgroundSelections [this .args .moduleId ]?.replace (/ \. json$ / , ' ' ),
410
+ private cardResource = getCard (
411
+ this ,
412
+ () => this .playgroundSelections [this .args .moduleId ]?.cardId ,
409
413
);
410
414
411
415
private get card(): CardDef | undefined {
412
416
return this .cardResource .card ;
413
417
}
414
418
419
+ private get format(): Format {
420
+ return this .playgroundSelections [this .args .moduleId ]?.format ?? ' isolated' ;
421
+ }
422
+
415
423
private copyToClipboard = task (async (id : string ) => {
416
424
await navigator .clipboard .writeText (id );
417
425
});
418
426
419
- private openInInteractMode = task (async (id : string , format : Format ) => {
427
+ private openInInteractMode = task (async (id : string ) => {
420
428
await this .operatorModeStateService .openCardInInteractMode (
421
429
new URL (id ),
422
- format ,
430
+ this . format === ' edit ' ? ' edit ' : ' isolated ' ,
423
431
);
424
432
});
425
433
@@ -439,28 +447,31 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
439
447
icon: IconCode ,
440
448
}),
441
449
new MenuItem (' Open in Interact Mode' , ' action' , {
442
- action : () => this .openInInteractMode .perform (cardId , this . format ),
450
+ action : () => this .openInInteractMode .perform (cardId ),
443
451
icon: Eye ,
444
452
}),
445
453
];
446
454
return menuItems ;
447
455
}
448
456
449
- private persistSelections = (cardId : string ) => {
450
- this .playgroundSelections [this .args .moduleId ] = cardId ;
457
+ private persistSelections = (cardId : string , format = this . format ) => {
458
+ this .playgroundSelections [this .args .moduleId ] = { cardId , format } ;
451
459
window .localStorage .setItem (
452
460
' playground-selections' ,
453
461
JSON .stringify (this .playgroundSelections ),
454
462
);
455
463
};
456
464
457
465
@action private onSelect(card : PrerenderedCard ) {
458
- this .persistSelections (card .url );
466
+ this .persistSelections (card .url . replace ( / \. json $ / , ' ' ) );
459
467
}
460
468
461
469
@action
462
470
private setFormat(format : Format ) {
463
- this .format = format ;
471
+ if (! this .card ?.id ) {
472
+ return ;
473
+ }
474
+ this .persistSelections (this .card .id , format );
464
475
}
465
476
466
477
private chooseCard = restartableTask (async () => {
0 commit comments