feat(ui): render the scene sharing dialogs and bar from a store

createSceneDialog keeps its builder but publishes the dialog's lines,
fields, buttons and status to a scene sharing store; SceneDialog.vue,
teleported to the body from the scene panels view, draws the same modal
with the same styles and opens it with Cancel focused. The EDIT DETAILS /
SHARE SCENE bar is drawn by that view while sharing offers it. The status
directive is shared with Provider Settings, and the two QA scripts that
drove the old DOM read the new dialog.
This commit is contained in:
Sameh Khamis committed 2026-10-31 18:37:14 -07:00
1 parent fe963a1219
commit 9d9eb267c5
15 files changed
+842 -355

No files matched your search

+147 -186
View File
@@ -1,210 +1,171 @@
import { t, tn } from '../i18n/index.js';
import { createActionButton } from './actionButton.js';
import { t } from '../i18n/index.js';
import { useSceneSharingStore } from './stores/sceneSharing.js';
import { applicationPinia } from './vueRuntime.js';
/** Small owned modal for scene authoring and import review; text never becomes markup. */
export function createSceneDialog(title, onClose) {
const dialog = document.createElement('dialog');
dialog.dataset.directorDialog = '';
dialog.className = 'director-sharing-dialog';
dialog.setAttribute('aria-label', title);
Object.assign(dialog.style, {
background: '#08141e',
color: '#e3faff',
border: '1px solid #397080',
borderRadius: '6px',
padding: '20px',
width: 'min(720px,calc(100vw - 32px))',
boxSizing: 'border-box',
position: 'fixed',
inset: '0',
margin: 'auto',
maxHeight: 'calc(100vh - 32px)',
overflow: 'auto',
font: '14px/1.5 sans-serif',
});
const heading = document.createElement('h2');
heading.textContent = title;
heading.style.marginBottom = '12px';
dialog.append(heading);
const body = document.createElement('div'),
footer = document.createElement('div'),
status = document.createElement('p');
status.setAttribute('role', 'status');
dialog.append(body, status, footer);
const listeners = [];
function listen(node, type, fn) {
node.addEventListener(type, fn);
listeners.push(() => node.removeEventListener(type, fn));
}
function text(value, parent = body) {
const p = document.createElement('p');
p.textContent = value;
p.style.margin = '8px 0';
parent.append(p);
return p;
}
function button(label, fn, parent = footer) {
const b = document.createElement('button');
b.type = 'button';
b.textContent = label;
Object.assign(b.style, {
background: '#10242e',
color: '#e3faff',
border: '1px solid #397080',
borderRadius: '3px',
padding: '7px 11px',
margin: '6px 6px 6px 0',
cursor: 'pointer',
font: 'inherit',
let dialogCount = 0;
/**
* Small owned modal for scene authoring and import review; text never becomes
* markup. The dialog is presented through the scene sharing store and drawn
* by SceneDialog.vue; the returned builder adds its lines, fields and buttons
* in order. Body content comes first, then the status line, then the footer
* row, which starts with Cancel.
* @param {string} title
* @param {() => void} onClose Cancel, Escape.
*/
export function createSceneDialog(
title,
onClose,
store = useSceneSharingStore(applicationPinia()),
) {
const id = ++dialogCount;
const items = [];
const actions = new Map();
let status = '',
statusSeq = 0,
nextItem = 0,
disposed = false;
const controls = {
click(itemId) {
const item = items.find((entry) => entry.id === itemId);
if (!disposed && !item?.disabled) actions.get(itemId)?.();
},
setValue(itemId, value) {
const item = items.find((entry) => entry.id === itemId);
if (item) item.value = value;
},
setFiles(itemId, files) {
const item = items.find((entry) => entry.id === itemId);
if (!item) return;
item.files = [...files];
publish();
},
cancel() {
if (!disposed) onClose();
},
};
function publish() {
if (disposed || store.controls !== controls) return;
store.publishDialog({
id,
title,
items: items.map((item) => ({ ...item })),
status,
statusSeq,
});
listen(b, 'click', fn);
parent.append(b);
return b;
}
function input(label, value, { type = 'text', multiline = false } = {}) {
const wrapper = document.createElement('label');
wrapper.style.display = 'block';
wrapper.textContent = label;
const node = document.createElement(multiline ? 'textarea' : 'input');
if (!multiline) node.type = type;
node.value = value;
node.setAttribute('aria-label', label);
Object.assign(node.style, {
display: 'block',
boxSizing: 'border-box',
width: '100%',
padding: '7px',
margin: '6px 0 14px',
color: '#e3faff',
background: '#10242e',
border: '1px solid #397080',
font: multiline ? '12px monospace' : 'inherit',
});
if (multiline) node.rows = 9;
wrapper.append(node);
if (type === 'file') fileChooser(wrapper, node);
body.append(wrapper);
return node;
function add(item) {
items.push({ id: nextItem++, ...item });
publish();
return items.at(-1);
}
function text(value) {
add({ kind: 'text', place: 'body', value });
}
/**
* The browser draws a file input's button and "no file" text in its own
* language. Stretch the native input, transparent, over the whole row (so
* click, focus and drops stay native) and draw translated text under it.
* @param {string} label
* @param {() => void} fn
* @param {object} [options]
* @param {'body'|'footer'} [options.place]
* @param {string} [options.hook] A data attribute name, e.g.
* 'data-director-apply-import', for automation to find the button by.
* @returns {{disabled: boolean}}
*/
function fileChooser(wrapper, node) {
wrapper.style.position = 'relative';
Object.assign(node.style, {
position: 'absolute',
inset: '0',
width: '100%',
height: '100%',
margin: '0',
padding: '0',
border: '0',
opacity: '0',
cursor: 'pointer',
zIndex: '1',
function button(label, fn, { place = 'footer', hook, autofocus } = {}) {
const item = add({
kind: 'button',
place,
label,
disabled: false,
hook,
autofocus,
});
const row = document.createElement('span');
row.setAttribute('aria-hidden', 'true');
Object.assign(row.style, {
display: 'flex',
alignItems: 'center',
gap: '10px',
margin: '6px 0 14px',
padding: '7px',
background: '#10242e',
border: '1px solid #397080',
});
const chooser = document.createElement('span');
chooser.textContent = t('Choose files');
Object.assign(chooser.style, {
padding: '3px 9px',
border: '1px solid #397080',
borderRadius: '3px',
background: '#08141e',
cursor: 'pointer',
});
const chosen = document.createElement('span');
const showChosen = () => {
const count = node.files?.length || 0;
// One file shows its name, like the browser's own picker did.
chosen.textContent =
count === 1
? node.files[0].name
: count
? tn(count, '{count} file selected', '{count} files selected')
: t('No file chosen');
actions.set(item.id, fn);
return {
get disabled() {
return item.disabled;
},
set disabled(value) {
item.disabled = Boolean(value);
publish();
},
};
showChosen();
row.append(chooser, chosen);
wrapper.append(row);
listen(node, 'change', showChosen);
listen(node, 'focus', () => {
chooser.style.outline = '2px solid #e3faff';
});
listen(node, 'blur', () => {
chooser.style.outline = '';
});
}
button(t('Cancel'), onClose);
listen(dialog, 'cancel', (event) => {
event.preventDefault();
onClose();
});
document.body.append(dialog);
dialog.showModal();
/**
* @param {string} label
* @param {string} value
* @param {object} [options]
* @param {string} [options.type]
* @param {boolean} [options.multiline]
* @param {boolean} [options.multiple] File inputs: several files.
* @param {boolean} [options.directory] File inputs: a whole folder.
* @returns {{value: string, readonly files: File[]}}
*/
function input(
label,
value,
{ type = 'text', multiline = false, multiple, directory } = {},
) {
const item = add({
kind: 'input',
place: 'body',
label,
value,
type: multiline ? null : type,
multiline,
multiple: Boolean(multiple),
directory: Boolean(directory),
files: [],
});
return {
get value() {
return item.value;
},
set value(next) {
item.value = next;
publish();
},
get files() {
return item.files;
},
};
}
function setStatus(value) {
status = value;
statusSeq++;
publish();
}
store.connect(controls);
// Cancel takes the opening focus, as the first control drawn.
button(t('Cancel'), onClose, { autofocus: true });
return {
body,
footer,
status,
text,
button,
input,
listen,
element: dialog,
setStatus,
dispose() {
for (const remove of listeners.splice(0)) remove();
dialog.close();
dialog.remove();
if (disposed) return;
if (store.controls === controls) {
store.connect(null);
store.publishDialog(null);
}
disposed = true;
},
};
}
/** Add controls only when their owner is present; dispose removes every listener and element. */
/**
* Offer the EDIT DETAILS / SHARE SCENE bar beside the scene panel's file
* controls; the returned function withdraws it, unless another owner has
* offered its own since.
*/
export function mountSceneSharing(
{ edit, share },
panel = document.getElementById('scene-panel'),
store = useSceneSharingStore(applicationPinia()),
) {
if (!panel) return () => {};
const bar = document.createElement('div');
bar.dataset.directorAuthoring = '';
bar.className = 'scene-controls';
const entries = [
[t('EDIT DETAILS'), t('Edit anchors, data packs and shot details'), edit],
[
t('SHARE SCENE'),
t('Download this scene as JSON or an asset bundle'),
share,
],
];
const removers = [];
for (const [text, title, fn] of entries) {
const b = createActionButton({
label: text,
title,
className: 'scene-btn',
});
b.addEventListener('click', fn);
removers.push(() => b.removeEventListener('click', fn));
bar.append(b);
}
// Beside EXPORT / IMPORT, under SAVE & SHARE.
const fileRow = panel.querySelector?.('.scene-file-controls');
if (fileRow) fileRow.after(bar);
else (panel.querySelector?.('.scene-panel-inner') || panel).appendChild(bar);
const actions = { edit, share };
store.offerToolbar(actions);
return () => {
for (const remove of removers) remove();
bar.remove();
if (store.toolbar === actions) store.offerToolbar(null);
};
}