@crowdedkingdoms/crowdyjs 18.22.0-test.1 → 18.23.0-dev.1
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/README.md +38 -1
- package/dist/crowdy-dsh/bridge.d.ts +72 -3
- package/dist/crowdy-dsh/bridge.d.ts.map +1 -1
- package/dist/crowdy-dsh/bridge.js +243 -12
- package/dist/crowdy-dsh/game-paths.d.ts +8 -0
- package/dist/crowdy-dsh/game-paths.d.ts.map +1 -0
- package/dist/crowdy-dsh/game-paths.js +20 -0
- package/dist/crowdy-dsh/pane.d.ts +18 -1
- package/dist/crowdy-dsh/pane.d.ts.map +1 -1
- package/dist/crowdy-dsh/pane.js +86 -2
- package/dist/crowdy-dsh/protocol.d.ts +165 -2
- package/dist/crowdy-dsh/protocol.d.ts.map +1 -1
- package/dist/crowdy-dsh/protocol.js +24 -1
- package/dist/crowdy-studio/controller.d.ts +100 -0
- package/dist/crowdy-studio/controller.d.ts.map +1 -1
- package/dist/crowdy-studio/controller.js +363 -1
- package/dist/crowdy-studio/dom-shell.d.ts +11 -0
- package/dist/crowdy-studio/dom-shell.d.ts.map +1 -1
- package/dist/crowdy-studio/dom-shell.js +182 -0
- package/dist/crowdy-studio/draft/github-draft-store.d.ts +143 -0
- package/dist/crowdy-studio/draft/github-draft-store.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/github-draft-store.js +477 -0
- package/dist/crowdy-studio/draft/hash.d.ts +12 -0
- package/dist/crowdy-studio/draft/hash.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/hash.js +25 -0
- package/dist/crowdy-studio/draft/index.d.ts +6 -0
- package/dist/crowdy-studio/draft/index.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/index.js +5 -0
- package/dist/crowdy-studio/draft/overlay-storage.d.ts +48 -0
- package/dist/crowdy-studio/draft/overlay-storage.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/overlay-storage.js +94 -0
- package/dist/crowdy-studio/draft/paths.d.ts +20 -0
- package/dist/crowdy-studio/draft/paths.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/paths.js +54 -0
- package/dist/crowdy-studio/draft/types.d.ts +137 -0
- package/dist/crowdy-studio/draft/types.d.ts.map +1 -0
- package/dist/crowdy-studio/draft/types.js +29 -0
- package/dist/crowdy-studio/editor.d.ts +2 -0
- package/dist/crowdy-studio/editor.d.ts.map +1 -1
- package/dist/crowdy-studio/embed/panel.d.ts +8 -0
- package/dist/crowdy-studio/embed/panel.d.ts.map +1 -1
- package/dist/crowdy-studio/embed/panel.js +2 -0
- package/dist/crowdy-studio/github/index.d.ts +1 -1
- package/dist/crowdy-studio/github/index.d.ts.map +1 -1
- package/dist/crowdy-studio/github/transport.d.ts +59 -0
- package/dist/crowdy-studio/github/transport.d.ts.map +1 -1
- package/dist/crowdy-studio/github/transport.js +30 -1
- package/dist/crowdy-studio/index.d.ts +1 -0
- package/dist/crowdy-studio/index.d.ts.map +1 -1
- package/dist/crowdy-studio/index.js +1 -0
- package/dist/crowdy-studio/models.d.ts +1 -1
- package/dist/crowdy-studio/models.d.ts.map +1 -1
- package/dist/crowdy-studio/monaco-editor.d.ts.map +1 -1
- package/dist/crowdy-studio/monaco-editor.js +16 -0
- package/dist/crowdy-studio/mount.d.ts +2 -0
- package/dist/crowdy-studio/mount.d.ts.map +1 -1
- package/dist/crowdy-studio/mount.js +2 -0
- package/dist/crowdy-studio/repository-tree.d.ts +14 -0
- package/dist/crowdy-studio/repository-tree.d.ts.map +1 -0
- package/dist/crowdy-studio/repository-tree.js +45 -0
- package/dist/crowdy-studio/styles.d.ts +1 -1
- package/dist/crowdy-studio/styles.d.ts.map +1 -1
- package/dist/crowdy-studio/styles.js +1 -0
- package/dist/crowdy-studio/textarea-editor.d.ts.map +1 -1
- package/dist/crowdy-studio/textarea-editor.js +10 -4
- package/dist/default-origin.d.ts +6 -6
- package/dist/default-origin.d.ts.map +1 -1
- package/dist/default-origin.js +6 -6
- package/dist/generated/graphql-schema.d.ts +84 -2
- package/dist/generated/graphql-schema.d.ts.map +1 -1
- package/dist/generated/graphql-schema.js +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { CrowdyError, CrowdyGraphQLError } from '../errors.js';
|
|
|
3
3
|
import { digestCanonicalJson, sha256Digest, } from '../player-host/json-schema.js';
|
|
4
4
|
import { parseRustcDiagnostics } from './diagnostics.js';
|
|
5
5
|
import { githubNewRepositoryUrl, githubRepositorySlug } from './github/new-repo.js';
|
|
6
|
+
import { DraftError, normalizeRepoPath, } from './draft/index.js';
|
|
6
7
|
import { cloneCrowdyStudioProject, crowdyStudioFileKey, normalizeCrowdyStudioPath, projectTargets, CrowdyStudioOfflineError, CrowdyStudioRevisionConflictError, } from './models.js';
|
|
7
8
|
import { createCrowdyStudioStarterProject, } from './starter-projects.js';
|
|
8
9
|
/** As ck-exec's mod names. */
|
|
@@ -12,6 +13,8 @@ const CRATE_NAME = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
|
12
13
|
/** ck-exec's server log levels (`ExecLogLine.level`); a CLIENT half's are crowdy-client-sdk's. */
|
|
13
14
|
const LOG_LEVELS = ['error', 'warn', 'info', 'debug'];
|
|
14
15
|
const PREVIEW_LOG_LINES_KEPT = 100;
|
|
16
|
+
/** Editor keystrokes reach the game draft after this pause. */
|
|
17
|
+
const REPOSITORY_WRITE_DEBOUNCE_MS = 250;
|
|
15
18
|
class OperationCancelledError extends Error {
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
@@ -53,6 +56,16 @@ export class CrowdyStudioController {
|
|
|
53
56
|
this.conflictRemote = null;
|
|
54
57
|
this.broker = null;
|
|
55
58
|
this.operationGeneration = 0;
|
|
59
|
+
/** Game editor: the open Construct game's draft, or null in the mod editor. */
|
|
60
|
+
this.draft = null;
|
|
61
|
+
this.draftProjectId = null;
|
|
62
|
+
this.draftUnsubscribe = null;
|
|
63
|
+
/** Layout kind per `projectId@githubSha`; a commit's tree never changes. */
|
|
64
|
+
this.layoutKinds = new Map();
|
|
65
|
+
/** Debounced editor writes into the draft, by path. */
|
|
66
|
+
this.repositoryWrites = new Map();
|
|
67
|
+
this.editorKnown = false;
|
|
68
|
+
this.editorKnownWaiters = [];
|
|
56
69
|
this.agentOperationGeneration = 0;
|
|
57
70
|
this.visibleSurfaces = new Set();
|
|
58
71
|
this.surfaceTimers = new Map();
|
|
@@ -191,6 +204,8 @@ export class CrowdyStudioController {
|
|
|
191
204
|
const first = projects.find((project) => project.projectId === this.options.initialProjectId) ?? projects[0];
|
|
192
205
|
if (first)
|
|
193
206
|
await this.loadProject(first.projectId);
|
|
207
|
+
else
|
|
208
|
+
this.markEditorKnown();
|
|
194
209
|
}
|
|
195
210
|
async createProject(options) {
|
|
196
211
|
this.ensureAlive();
|
|
@@ -260,6 +275,7 @@ export class CrowdyStudioController {
|
|
|
260
275
|
projectId,
|
|
261
276
|
});
|
|
262
277
|
this.installProject(project);
|
|
278
|
+
await this.refreshRepositoryMode();
|
|
263
279
|
if (this.options.synchronizationProvider) {
|
|
264
280
|
await this.refreshCheckpoints();
|
|
265
281
|
}
|
|
@@ -305,7 +321,8 @@ export class CrowdyStudioController {
|
|
|
305
321
|
void this.refreshGitHubStatus();
|
|
306
322
|
}
|
|
307
323
|
openFile(ref) {
|
|
308
|
-
|
|
324
|
+
if (ref.source !== 'REPOSITORY')
|
|
325
|
+
this.requireFile(ref);
|
|
309
326
|
const exists = this.state.openFiles.some((entry) => sameFileRef(entry, ref));
|
|
310
327
|
this.update({
|
|
311
328
|
openFiles: exists ? this.state.openFiles : [...this.state.openFiles, ref],
|
|
@@ -320,8 +337,330 @@ export class CrowdyStudioController {
|
|
|
320
337
|
this.update({ openFiles, activeFile });
|
|
321
338
|
}
|
|
322
339
|
fileContent(ref) {
|
|
340
|
+
if (ref.source === 'REPOSITORY') {
|
|
341
|
+
return this.state.repositoryDocuments?.find((file) => file.path === ref.path)?.content ?? '';
|
|
342
|
+
}
|
|
323
343
|
return this.requireFile(ref).content;
|
|
324
344
|
}
|
|
345
|
+
// ----- game editor: the draft of a bound Construct game -------------------
|
|
346
|
+
/** The open project's draft in the game editor; null in the mod editor. */
|
|
347
|
+
get draftStore() {
|
|
348
|
+
return this.draft;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Resolves once the first project load decided between the mod editor and
|
|
352
|
+
* the game editor. Bounded, so a page that cannot reach the API still boots
|
|
353
|
+
* its agent (in the mod editor) instead of waiting forever.
|
|
354
|
+
*/
|
|
355
|
+
whenEditorKnown(timeoutMs = 15000) {
|
|
356
|
+
if (this.editorKnown)
|
|
357
|
+
return Promise.resolve();
|
|
358
|
+
return new Promise((resolve) => {
|
|
359
|
+
const timer = setTimeout(resolve, timeoutMs);
|
|
360
|
+
this.editorKnownWaiters.push(() => {
|
|
361
|
+
clearTimeout(timer);
|
|
362
|
+
resolve();
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Pick the editor for the open project. A GITHUB project the API classifies
|
|
368
|
+
* as CONSTRUCT_GAME gets the host's draft store; anything else, or a host
|
|
369
|
+
* without one, the mod editor. The kind is asked once per mirror commit.
|
|
370
|
+
*/
|
|
371
|
+
async refreshRepositoryMode() {
|
|
372
|
+
try {
|
|
373
|
+
const project = this.state.project;
|
|
374
|
+
const factory = this.options.draftStore;
|
|
375
|
+
const github = this.options.github;
|
|
376
|
+
const sha = project?.github?.sha ?? null;
|
|
377
|
+
if (!project || project.source !== 'GITHUB' || !sha || !github || !factory) {
|
|
378
|
+
this.closeDraft();
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const key = `${project.projectId}@${sha}`;
|
|
382
|
+
let kind = this.layoutKinds.get(key);
|
|
383
|
+
if (!kind) {
|
|
384
|
+
const layout = await github.layout({ appId: this.options.appId, projectId: project.projectId });
|
|
385
|
+
kind = layout.kind ?? 'STUDIO_CRATES';
|
|
386
|
+
this.layoutKinds.set(key, kind);
|
|
387
|
+
}
|
|
388
|
+
if (kind !== 'CONSTRUCT_GAME') {
|
|
389
|
+
this.closeDraft();
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
// The same game keeps its store: the store follows its own commits.
|
|
393
|
+
if (this.draft && this.draftProjectId === project.projectId)
|
|
394
|
+
return;
|
|
395
|
+
this.closeDraft();
|
|
396
|
+
const store = factory({ appId: this.options.appId, projectId: project.projectId, githubSha: sha });
|
|
397
|
+
if (!store)
|
|
398
|
+
return;
|
|
399
|
+
this.draft = store;
|
|
400
|
+
this.draftProjectId = project.projectId;
|
|
401
|
+
this.draftUnsubscribe = store.subscribe((event) => this.onDraftChange(event));
|
|
402
|
+
this.update({
|
|
403
|
+
repositoryMode: true,
|
|
404
|
+
repositoryStore: store.kind,
|
|
405
|
+
repositoryFiles: undefined,
|
|
406
|
+
repositoryDirectories: undefined,
|
|
407
|
+
repositoryDocuments: [],
|
|
408
|
+
repositoryMessage: undefined,
|
|
409
|
+
openFiles: this.state.openFiles.filter((ref) => ref.source !== 'PROJECT'),
|
|
410
|
+
activeFile: this.state.activeFile?.source === 'PROJECT' ? null : this.state.activeFile,
|
|
411
|
+
});
|
|
412
|
+
await this.reloadRepository();
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
this.update({ repositoryMessage: errorMessage(error) });
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
this.markEditorKnown();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/** Re-load the draft (base tree and stored edits) for the Files pane. */
|
|
422
|
+
async reloadRepository() {
|
|
423
|
+
const store = this.draft;
|
|
424
|
+
if (!store)
|
|
425
|
+
return;
|
|
426
|
+
this.update({ repositoryBusy: true });
|
|
427
|
+
try {
|
|
428
|
+
const snapshot = await store.load();
|
|
429
|
+
if (store !== this.draft)
|
|
430
|
+
return;
|
|
431
|
+
this.applyDraftSnapshot();
|
|
432
|
+
const open = (this.state.repositoryDocuments ?? []).map((doc) => doc.path);
|
|
433
|
+
if (open.length > 0)
|
|
434
|
+
await this.refreshRepositoryDocuments(open);
|
|
435
|
+
this.update({
|
|
436
|
+
repositoryMessage: snapshot.truncated
|
|
437
|
+
? 'The repository is larger than the editor lists; some files are hidden.'
|
|
438
|
+
: undefined,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
this.update({ repositoryMessage: errorMessage(error) });
|
|
443
|
+
}
|
|
444
|
+
finally {
|
|
445
|
+
this.update({ repositoryBusy: false });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/** Open one draft file in the editor. */
|
|
449
|
+
async openRepositoryFile(path) {
|
|
450
|
+
const store = this.requireDraft();
|
|
451
|
+
const normalized = normalizeRepoPath(path);
|
|
452
|
+
if (!normalized)
|
|
453
|
+
throw new Error(`${path} is not a file the game editor opens.`);
|
|
454
|
+
const read = await store.read([normalized]);
|
|
455
|
+
if (read.binary.includes(normalized)) {
|
|
456
|
+
this.update({ repositoryMessage: `${normalized} is a binary file; the editor opens text only.` });
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const file = read.files[0];
|
|
460
|
+
if (!file)
|
|
461
|
+
throw new Error(`${normalized} is not in the draft.`);
|
|
462
|
+
const ref = { source: 'REPOSITORY', path: normalized };
|
|
463
|
+
const exists = this.state.openFiles.some((entry) => sameFileRef(entry, ref));
|
|
464
|
+
this.update({
|
|
465
|
+
repositoryDocuments: upsertRepositoryDocument(this.state.repositoryDocuments ?? [], normalized, file.content, file.hash),
|
|
466
|
+
openFiles: exists ? this.state.openFiles : [...this.state.openFiles, ref],
|
|
467
|
+
activeFile: ref,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* A keystroke in a draft file. The text reaches the draft a moment later;
|
|
472
|
+
* the player's typing wins over a concurrent agent write (the agent writes
|
|
473
|
+
* under a hash precondition, so its next write re-reads). Never a commit.
|
|
474
|
+
*/
|
|
475
|
+
updateRepositoryFile(path, content) {
|
|
476
|
+
const current = this.state.repositoryDocuments?.find((file) => file.path === path);
|
|
477
|
+
if (current?.content === content)
|
|
478
|
+
return;
|
|
479
|
+
this.update({
|
|
480
|
+
repositoryDocuments: upsertRepositoryDocument(this.state.repositoryDocuments ?? [], path, content, current?.hash),
|
|
481
|
+
});
|
|
482
|
+
if (!this.draft)
|
|
483
|
+
return;
|
|
484
|
+
const pending = this.repositoryWrites.get(path);
|
|
485
|
+
if (pending)
|
|
486
|
+
clearTimeout(pending);
|
|
487
|
+
this.repositoryWrites.set(path, setTimeout(() => {
|
|
488
|
+
this.repositoryWrites.delete(path);
|
|
489
|
+
void this.writeRepositoryDocument(path);
|
|
490
|
+
}, REPOSITORY_WRITE_DEBOUNCE_MS));
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Publish the draft (or the named paths) as one commit on the bound branch.
|
|
494
|
+
* When the branch moved, the store rebases what does not collide and lists
|
|
495
|
+
* the rest in `repositoryConflicts` for {@link resolveRepositoryConflict}.
|
|
496
|
+
*/
|
|
497
|
+
async commitRepository(request) {
|
|
498
|
+
const store = this.requireDraft();
|
|
499
|
+
await this.flushRepositoryWrites();
|
|
500
|
+
this.update({ repositoryBusy: true, repositoryMessage: 'Committing…' });
|
|
501
|
+
try {
|
|
502
|
+
const result = await store.commit(request);
|
|
503
|
+
this.update({
|
|
504
|
+
repositoryMessage: `Committed ${result.committed.length} file${result.committed.length === 1 ? '' : 's'} as ${result.commitSha.slice(0, 7)}.`,
|
|
505
|
+
});
|
|
506
|
+
// The project's githubSha moved; the GitHub card and the mod tools read it.
|
|
507
|
+
if (this.state.saveState === 'SAVED')
|
|
508
|
+
void this.reloadProject().catch(() => undefined);
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
this.update({
|
|
513
|
+
repositoryConflicts: store.conflicts(),
|
|
514
|
+
repositoryMessage: errorMessage(error),
|
|
515
|
+
});
|
|
516
|
+
throw error;
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
this.update({ repositoryBusy: false });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/** Drop draft edits (every one when `paths` is omitted). */
|
|
523
|
+
async discardRepositoryFiles(paths) {
|
|
524
|
+
const store = this.requireDraft();
|
|
525
|
+
for (const path of paths ?? [...this.repositoryWrites.keys()]) {
|
|
526
|
+
const pending = this.repositoryWrites.get(path);
|
|
527
|
+
if (pending)
|
|
528
|
+
clearTimeout(pending);
|
|
529
|
+
this.repositoryWrites.delete(path);
|
|
530
|
+
}
|
|
531
|
+
await store.discard(paths);
|
|
532
|
+
}
|
|
533
|
+
/** `mine` commits the draft over the branch's change; `theirs` drops the draft edit. */
|
|
534
|
+
async resolveRepositoryConflict(path, keep) {
|
|
535
|
+
const store = this.requireDraft();
|
|
536
|
+
await store.resolveConflict(path, keep);
|
|
537
|
+
this.update({ repositoryConflicts: store.conflicts() });
|
|
538
|
+
if (keep === 'theirs')
|
|
539
|
+
await this.refreshRepositoryDocuments([path]);
|
|
540
|
+
}
|
|
541
|
+
requireDraft() {
|
|
542
|
+
if (!this.draft)
|
|
543
|
+
throw new DraftError('DRAFT_UNAVAILABLE', 'This project has no game draft.');
|
|
544
|
+
return this.draft;
|
|
545
|
+
}
|
|
546
|
+
markEditorKnown() {
|
|
547
|
+
if (this.editorKnown)
|
|
548
|
+
return;
|
|
549
|
+
this.editorKnown = true;
|
|
550
|
+
for (const wake of this.editorKnownWaiters.splice(0))
|
|
551
|
+
wake();
|
|
552
|
+
}
|
|
553
|
+
closeDraft() {
|
|
554
|
+
for (const timer of this.repositoryWrites.values())
|
|
555
|
+
clearTimeout(timer);
|
|
556
|
+
this.repositoryWrites.clear();
|
|
557
|
+
this.draftUnsubscribe?.();
|
|
558
|
+
this.draftUnsubscribe = null;
|
|
559
|
+
this.draft?.dispose();
|
|
560
|
+
const wasOn = this.state.repositoryMode === true;
|
|
561
|
+
this.draft = null;
|
|
562
|
+
this.draftProjectId = null;
|
|
563
|
+
if (!wasOn)
|
|
564
|
+
return;
|
|
565
|
+
this.update({
|
|
566
|
+
repositoryMode: false,
|
|
567
|
+
repositoryStore: undefined,
|
|
568
|
+
repositoryFiles: undefined,
|
|
569
|
+
repositoryDirectories: undefined,
|
|
570
|
+
repositoryDirty: undefined,
|
|
571
|
+
repositoryDeleted: undefined,
|
|
572
|
+
repositoryConflicts: undefined,
|
|
573
|
+
repositoryBaseCommitSha: undefined,
|
|
574
|
+
repositoryRevision: undefined,
|
|
575
|
+
repositoryDocuments: undefined,
|
|
576
|
+
repositoryMessage: undefined,
|
|
577
|
+
openFiles: this.state.openFiles.filter((ref) => ref.source !== 'REPOSITORY'),
|
|
578
|
+
activeFile: this.state.activeFile?.source === 'REPOSITORY' ? null : this.state.activeFile,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
applyDraftSnapshot() {
|
|
582
|
+
const store = this.draft;
|
|
583
|
+
if (!store)
|
|
584
|
+
return;
|
|
585
|
+
const snapshot = store.snapshot();
|
|
586
|
+
const files = snapshot.entries.map((entry) => entry.path);
|
|
587
|
+
this.update({
|
|
588
|
+
repositoryFiles: files,
|
|
589
|
+
repositoryDirectories: directoriesOf(files),
|
|
590
|
+
repositoryDirty: snapshot.entries.filter((entry) => entry.dirty).map((entry) => entry.path),
|
|
591
|
+
repositoryDeleted: snapshot.deleted,
|
|
592
|
+
repositoryConflicts: store.conflicts(),
|
|
593
|
+
repositoryBaseCommitSha: snapshot.baseCommitSha,
|
|
594
|
+
repositoryRevision: snapshot.revision,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
onDraftChange(event) {
|
|
598
|
+
if (!this.draft)
|
|
599
|
+
return;
|
|
600
|
+
this.applyDraftSnapshot();
|
|
601
|
+
// The editor already shows its own keystrokes.
|
|
602
|
+
if (event.source === 'player')
|
|
603
|
+
return;
|
|
604
|
+
const open = new Set((this.state.repositoryDocuments ?? []).map((doc) => doc.path));
|
|
605
|
+
const touched = event.source === 'agent' || event.source === 'commit'
|
|
606
|
+
? event.changes.map((change) => change.path).filter((path) => open.has(path))
|
|
607
|
+
: [...open];
|
|
608
|
+
if (touched.length > 0)
|
|
609
|
+
void this.refreshRepositoryDocuments(touched);
|
|
610
|
+
}
|
|
611
|
+
/** Re-read open documents from the draft; a document the player is still typing in is left alone. */
|
|
612
|
+
async refreshRepositoryDocuments(paths) {
|
|
613
|
+
const store = this.draft;
|
|
614
|
+
if (!store)
|
|
615
|
+
return;
|
|
616
|
+
const wanted = paths.filter((path) => !this.repositoryWrites.has(path));
|
|
617
|
+
if (wanted.length === 0)
|
|
618
|
+
return;
|
|
619
|
+
const read = await store.read(wanted);
|
|
620
|
+
if (store !== this.draft)
|
|
621
|
+
return;
|
|
622
|
+
let documents = [...(this.state.repositoryDocuments ?? [])];
|
|
623
|
+
for (const file of read.files) {
|
|
624
|
+
if (this.repositoryWrites.has(file.path))
|
|
625
|
+
continue;
|
|
626
|
+
documents = upsertRepositoryDocument(documents, file.path, file.content, file.hash);
|
|
627
|
+
}
|
|
628
|
+
const gone = new Set(read.missing);
|
|
629
|
+
documents = documents.filter((doc) => !gone.has(doc.path));
|
|
630
|
+
const openFiles = this.state.openFiles.filter((ref) => !(ref.source === 'REPOSITORY' && gone.has(ref.path)));
|
|
631
|
+
const activeGone = this.state.activeFile?.source === 'REPOSITORY' && gone.has(this.state.activeFile.path);
|
|
632
|
+
this.update({
|
|
633
|
+
repositoryDocuments: documents,
|
|
634
|
+
openFiles,
|
|
635
|
+
activeFile: activeGone ? (openFiles.at(-1) ?? null) : this.state.activeFile,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
async writeRepositoryDocument(path) {
|
|
639
|
+
const store = this.draft;
|
|
640
|
+
const doc = this.state.repositoryDocuments?.find((file) => file.path === path);
|
|
641
|
+
if (!store || !doc)
|
|
642
|
+
return;
|
|
643
|
+
try {
|
|
644
|
+
const result = await store.write(path, doc.content, { source: 'player' });
|
|
645
|
+
const latest = this.state.repositoryDocuments?.find((file) => file.path === path);
|
|
646
|
+
if (latest && latest.content === doc.content) {
|
|
647
|
+
this.update({
|
|
648
|
+
repositoryDocuments: upsertRepositoryDocument(this.state.repositoryDocuments ?? [], path, doc.content, result.hash),
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
this.update({ repositoryMessage: errorMessage(error) });
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async flushRepositoryWrites() {
|
|
657
|
+
const pending = [...this.repositoryWrites.keys()];
|
|
658
|
+
for (const path of pending) {
|
|
659
|
+
clearTimeout(this.repositoryWrites.get(path));
|
|
660
|
+
this.repositoryWrites.delete(path);
|
|
661
|
+
}
|
|
662
|
+
await Promise.all(pending.map((path) => this.writeRepositoryDocument(path)));
|
|
663
|
+
}
|
|
325
664
|
addFile(target, path, content = '') {
|
|
326
665
|
const project = this.requireProject();
|
|
327
666
|
this.assertProjectTarget(project, target);
|
|
@@ -1377,6 +1716,7 @@ export class CrowdyStudioController {
|
|
|
1377
1716
|
destroy() {
|
|
1378
1717
|
if (this.destroyed)
|
|
1379
1718
|
return;
|
|
1719
|
+
this.closeDraft();
|
|
1380
1720
|
this.destroyed = true;
|
|
1381
1721
|
++this.operationGeneration;
|
|
1382
1722
|
this.clearSaveTimers();
|
|
@@ -1793,7 +2133,29 @@ function upsertCheckpoint(checkpoints, checkpoint) {
|
|
|
1793
2133
|
...checkpoints.filter((entry) => entry.checkpointId !== checkpoint.checkpointId),
|
|
1794
2134
|
];
|
|
1795
2135
|
}
|
|
2136
|
+
function upsertRepositoryDocument(documents, path, content, hash) {
|
|
2137
|
+
const next = documents.filter((file) => file.path !== path);
|
|
2138
|
+
next.push(hash ? { path, content, hash } : { path, content });
|
|
2139
|
+
return next;
|
|
2140
|
+
}
|
|
2141
|
+
/** Every directory that holds one of `files`, excluding the root. */
|
|
2142
|
+
function directoriesOf(files) {
|
|
2143
|
+
const dirs = new Set();
|
|
2144
|
+
for (const file of files) {
|
|
2145
|
+
let slash = file.lastIndexOf('/');
|
|
2146
|
+
while (slash > 0) {
|
|
2147
|
+
const dir = file.slice(0, slash);
|
|
2148
|
+
if (dirs.has(dir))
|
|
2149
|
+
break;
|
|
2150
|
+
dirs.add(dir);
|
|
2151
|
+
slash = dir.lastIndexOf('/');
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
return [...dirs].sort();
|
|
2155
|
+
}
|
|
1796
2156
|
function fileRefExists(project, state, ref) {
|
|
2157
|
+
if (ref.source === 'REPOSITORY')
|
|
2158
|
+
return true;
|
|
1797
2159
|
if (ref.source === 'PROJECT') {
|
|
1798
2160
|
return project.files.some((file) => file.target === ref.target &&
|
|
1799
2161
|
file.path === normalizeCrowdyStudioPath(ref.path));
|
|
@@ -40,6 +40,7 @@ export declare class CrowdyStudioDomShell {
|
|
|
40
40
|
private readonly saveMessageText;
|
|
41
41
|
private readonly saveAction;
|
|
42
42
|
private readonly remoteAction;
|
|
43
|
+
private readonly runtimeTools;
|
|
43
44
|
private readonly testAction;
|
|
44
45
|
private readonly runMenu;
|
|
45
46
|
private readonly deployAction;
|
|
@@ -85,6 +86,10 @@ export declare class CrowdyStudioDomShell {
|
|
|
85
86
|
private readonly unsubscribeLayout;
|
|
86
87
|
private activePanel;
|
|
87
88
|
private explorerForm;
|
|
89
|
+
/** Repository directories the Files pane is showing the children of. */
|
|
90
|
+
private readonly repositoryExpanded;
|
|
91
|
+
/** The open commit form: its message and the paths it includes. */
|
|
92
|
+
private repositoryCommit;
|
|
88
93
|
private lastState;
|
|
89
94
|
private lastPhase;
|
|
90
95
|
private disposed;
|
|
@@ -111,6 +116,12 @@ export declare class CrowdyStudioDomShell {
|
|
|
111
116
|
private renderProjects;
|
|
112
117
|
private renderSaveState;
|
|
113
118
|
private renderExplorer;
|
|
119
|
+
private renderRepository;
|
|
120
|
+
private repositoryNodes;
|
|
121
|
+
/** The branch and the draft both changed `path`: the player keeps one. */
|
|
122
|
+
private conflictRow;
|
|
123
|
+
/** One commit: a message and the changed paths to include. */
|
|
124
|
+
private commitForm;
|
|
114
125
|
private projectSection;
|
|
115
126
|
private projectFileRow;
|
|
116
127
|
private projectFileFormRow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-shell.d.ts","sourceRoot":"","sources":["../../src/crowdy-studio/dom-shell.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACL,sBAAsB,EAIvB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"dom-shell.d.ts","sourceRoot":"","sources":["../../src/crowdy-studio/dom-shell.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACL,sBAAsB,EAIvB,MAAM,aAAa,CAAC;AAwCrB;;;;;;;GAOG;AACH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,kDAAkD;IAClD,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,0EAA0E;IAC1E,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,KAAK,cAAc,CAAC;IAClD,qEAAqE;IACrE,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAC5D;AAED,qBAAa,oBAAoB;IAqE7B,OAAO,CAAC,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