refactor: extract shortView into node-views.js
This commit is contained in:
@@ -2,48 +2,9 @@ import { h, ref, watch, onMounted } from 'vue';
|
||||
import { fetchAstLog, fetchScoreText, putScoreText, fetchAudioWidget, URLS } from '../api.js';
|
||||
import { parseAstLog, buildModel } from '../ast-parser.js';
|
||||
import { patchScore } from '../exporter.js';
|
||||
import { shortView } from '../node-views.js';
|
||||
import { StatusPoller } from './StatusPoller.js';
|
||||
|
||||
// Short label + identifying meta for each node type.
|
||||
function shortView(node) {
|
||||
if (!node) return { typeTag: '?', label: '?', meta: [] };
|
||||
switch (node.type) {
|
||||
case 'score':
|
||||
return {
|
||||
typeTag: 'score',
|
||||
label: node.info?.title ?? '(untitled)',
|
||||
meta: node.info?.composer ? [{ key: 'composer', value: node.info.composer }] : [],
|
||||
};
|
||||
case 'instrument':
|
||||
return { typeTag: 'instrument', label: node.name, meta: [] };
|
||||
case 'variation': {
|
||||
const dep = node.dependsOn;
|
||||
const label = dep == null ? '(root variation)'
|
||||
: isNaN(Number(dep)) ? `ATTR: ${dep}`
|
||||
: String(dep);
|
||||
return { typeTag: 'variation', label, meta: [] };
|
||||
}
|
||||
case 'label_spec':
|
||||
return { typeTag: 'label', label: node.label ?? '(no label)', meta: [] };
|
||||
case 'bar':
|
||||
return { typeTag: 'bar', label: node.id, meta: [] };
|
||||
case 'voice':
|
||||
return { typeTag: 'voice', label: node.name, meta: [] };
|
||||
case 'offset':
|
||||
return { typeTag: 'tick', label: String(node.tick ?? '?'), meta: [] };
|
||||
case 'motif':
|
||||
return { typeTag: 'motif', label: node.label, meta: node.isStatic ? [{ key: 'static', value: '✓' }] : [] };
|
||||
case 'stem_note':
|
||||
return { typeTag: 'stem_note', label: String(node.pitch), meta: [] };
|
||||
case 'article': {
|
||||
const n = node.properties?.length ?? 0;
|
||||
return { typeTag: 'article', label: node.name, meta: n ? [{ key: 'props', value: n }] : [] };
|
||||
}
|
||||
default:
|
||||
return { typeTag: node.type, label: node.type, meta: [] };
|
||||
}
|
||||
}
|
||||
|
||||
export const PaneCP = {
|
||||
props: ['store', 'importOnLoad', 'onFocusFO'],
|
||||
setup(props) {
|
||||
|
||||
38
static/node-views.js
Normal file
38
static/node-views.js
Normal file
@@ -0,0 +1,38 @@
|
||||
export function shortView(node) {
|
||||
if (!node) return { typeTag: '?', label: '?', meta: [] };
|
||||
switch (node.type) {
|
||||
case 'score':
|
||||
return {
|
||||
typeTag: 'score',
|
||||
label: node.info?.title ?? '(untitled)',
|
||||
meta: node.info?.composer ? [{ key: 'composer', value: node.info.composer }] : [],
|
||||
};
|
||||
case 'instrument':
|
||||
return { typeTag: 'instrument', label: node.name, meta: [] };
|
||||
case 'variation': {
|
||||
const dep = node.dependsOn;
|
||||
const label = dep == null ? '(root variation)'
|
||||
: isNaN(Number(dep)) ? `ATTR: ${dep}`
|
||||
: String(dep);
|
||||
return { typeTag: 'variation', label, meta: [] };
|
||||
}
|
||||
case 'label_spec':
|
||||
return { typeTag: 'label', label: node.label ?? '(no label)', meta: [] };
|
||||
case 'bar':
|
||||
return { typeTag: 'bar', label: node.id, meta: [] };
|
||||
case 'voice':
|
||||
return { typeTag: 'voice', label: node.name, meta: [] };
|
||||
case 'offset':
|
||||
return { typeTag: 'tick', label: String(node.tick ?? '?'), meta: [] };
|
||||
case 'motif':
|
||||
return { typeTag: 'motif', label: node.label, meta: node.isStatic ? [{ key: 'static', value: '✓' }] : [] };
|
||||
case 'stem_note':
|
||||
return { typeTag: 'stem_note', label: String(node.pitch), meta: [] };
|
||||
case 'article': {
|
||||
const n = node.properties?.length ?? 0;
|
||||
return { typeTag: 'article', label: node.name, meta: n ? [{ key: 'props', value: n }] : [] };
|
||||
}
|
||||
default:
|
||||
return { typeTag: node.type, label: node.type, meta: [] };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user