mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(ui): render the Scene panel's shot list and scene options as components
SceneShotList and SceneOptions render the project from a gev-scenes store instead of scenePresentation building rows with createElement. SceneControls stays the owner: it publishes the director's state and attaches the row actions, and a late destroy cannot detach a newer owner. Rows keep their identity across selection; a rename keeps its typed text across republishing and ends with its row. The select still changes its choice only when its options are rendered. Vue keeps whitespace in every component, so Prettier formats single-file components with strict whitespace sensitivity, and the test loader parses templates with the same options as the browser build. The i18n check reads view text without its interpolations, whose t() calls are scanned with the sources.
This commit is contained in:
1 parent
6802c9c8b0
commit
d9fdcfc641
13 files changed
+518
-306
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { markRaw, shallowRef } from 'vue';
|
||||
|
||||
/**
|
||||
* @typedef {object} SceneRowHandlers
|
||||
* @property {(shotId: string) => void} select
|
||||
* @property {(sceneId: string, shotId: string, title: string) => void} rename
|
||||
* @property {(sceneId: string, shotId: string) => void} load
|
||||
* @property {(sceneId: string, shotId: string) => void} remove
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Scene panel's project list as the panel views render it. SceneControls
|
||||
* owns the project presentation: it publishes here and attaches the row
|
||||
* actions; the views only render and forward clicks.
|
||||
*/
|
||||
export const useSceneStore = defineStore('gev-scenes', () => {
|
||||
// Scenes arrive as fresh read-only copies; only replacing them re-renders.
|
||||
const scenes = shallowRef(markRaw([]));
|
||||
const selectedSceneId = shallowRef(null);
|
||||
const selectedShotId = shallowRef(null);
|
||||
// The select's choice, updated only when its options are rendered.
|
||||
const listedSceneId = shallowRef(null);
|
||||
/** Whether an owner presents the project; until then the list is empty. */
|
||||
const attached = shallowRef(false);
|
||||
/** @type {{handlers: SceneRowHandlers}|null} */
|
||||
let owner = null;
|
||||
|
||||
/**
|
||||
* Present the project for an owner, replacing any earlier owner.
|
||||
* @param {SceneRowHandlers} handlers
|
||||
* @returns {object} Token for detach().
|
||||
*/
|
||||
function attach(handlers) {
|
||||
owner = { handlers };
|
||||
attached.value = true;
|
||||
return owner;
|
||||
}
|
||||
|
||||
/** Publish the shot list; `scenes` is copied so every publish re-renders. */
|
||||
function publish(state) {
|
||||
scenes.value = markRaw([...(state.scenes ?? [])]);
|
||||
selectedSceneId.value = state.selectedSceneId ?? null;
|
||||
selectedShotId.value = state.selectedShotId ?? null;
|
||||
}
|
||||
|
||||
/** Publish the project and the select's choice. */
|
||||
function publishOptions(state) {
|
||||
publish(state);
|
||||
listedSceneId.value = state.selectedSceneId ?? null;
|
||||
}
|
||||
|
||||
/** @param {string|null} id */
|
||||
function selectShot(id) {
|
||||
selectedShotId.value = id ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop presenting for the owner holding `token`: the list empties and row
|
||||
* clicks do nothing. A later owner's presentation is left alone.
|
||||
*/
|
||||
function detach(token) {
|
||||
if (token !== owner) return;
|
||||
owner = null;
|
||||
attached.value = false;
|
||||
publishOptions({});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward a row action to the owner, if one is attached.
|
||||
* @param {keyof SceneRowHandlers} name
|
||||
*/
|
||||
function act(name, ...args) {
|
||||
owner?.handlers[name]?.(...args);
|
||||
}
|
||||
|
||||
return {
|
||||
scenes,
|
||||
selectedSceneId,
|
||||
selectedShotId,
|
||||
listedSceneId,
|
||||
attached,
|
||||
attach,
|
||||
publish,
|
||||
publishOptions,
|
||||
selectShot,
|
||||
detach,
|
||||
act,
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user