refactor: underscore-prefix all non-exported functions
This commit is contained in:
@@ -7,19 +7,19 @@ import { coerce, stressorToString } from '../util.js';
|
||||
|
||||
const H4 = { style: 'margin:0 0 0.5rem' };
|
||||
|
||||
function unknownPropFields(node) {
|
||||
function _unknownPropFields(node) {
|
||||
return Object.entries(node.unknownProps ?? {})
|
||||
.map(([key, value]) => ({ key, value: String(value), editable: false }));
|
||||
}
|
||||
|
||||
function parseStressor(str) {
|
||||
function _parseStressor(str) {
|
||||
const groups = str.split(';').map(seg =>
|
||||
seg.split(',').map(n => parseInt(n, 10)).filter(n => !isNaN(n))
|
||||
).filter(g => g.length > 0);
|
||||
return groups.length ? { type: 'stressor', groups } : null;
|
||||
}
|
||||
|
||||
function scoreInfoFields(info) {
|
||||
function _scoreInfoFields(info) {
|
||||
return [
|
||||
{ key: 'title', value: info?.title ?? '', editable: true },
|
||||
{ key: 'composer', value: info?.composer ?? '', editable: true },
|
||||
@@ -28,7 +28,7 @@ function scoreInfoFields(info) {
|
||||
];
|
||||
}
|
||||
|
||||
function instrFields(instr) {
|
||||
function _instrFields(instr) {
|
||||
return [
|
||||
{ key: 'name', value: instr.name, editable: false },
|
||||
{ key: 'linked', value: instr.isLinked, editable: false, type: 'boolean' },
|
||||
@@ -36,11 +36,11 @@ function instrFields(instr) {
|
||||
];
|
||||
}
|
||||
|
||||
function variationFields(v) {
|
||||
function _variationFields(v) {
|
||||
return [{ key: 'depends_on', value: v.dependsOn ?? '—', editable: true }];
|
||||
}
|
||||
|
||||
function shapeSection(label, shape, onChange) {
|
||||
function _shapeSection(label, shape, onChange) {
|
||||
if (!shape) return null;
|
||||
return h('div', { style: 'margin-top:0.5rem' }, [
|
||||
h('strong', null, label),
|
||||
@@ -101,7 +101,7 @@ export const PaneFO = {
|
||||
return h('div', { class: 'se-fo-pane' }, [
|
||||
h('h4', H4, 'Score'),
|
||||
h(ObjectExtended, {
|
||||
fields: scoreInfoFields(model.info),
|
||||
fields: _scoreInfoFields(model.info),
|
||||
onChange: ({ key, value }) => {
|
||||
if (!model.info) model.info = {};
|
||||
model.info[key] = value;
|
||||
@@ -114,7 +114,7 @@ export const PaneFO = {
|
||||
if (node.type === 'instrument') {
|
||||
children.push(
|
||||
h('h4', H4, `Instrument: ${node.name}`),
|
||||
h(ObjectExtended, { fields: instrFields(node), onChange: null }),
|
||||
h(ObjectExtended, { fields: _instrFields(node), onChange: null }),
|
||||
);
|
||||
} else if (node.type === 'variation') {
|
||||
const instr = props.store.scoreModel.instruments.find(
|
||||
@@ -125,7 +125,7 @@ export const PaneFO = {
|
||||
|
||||
children.push(
|
||||
h('h4', H4, 'Variation'),
|
||||
h(ObjectExtended, { fields: variationFields(node), onChange: ({ key, value }) => {
|
||||
h(ObjectExtended, { fields: _variationFields(node), onChange: ({ key, value }) => {
|
||||
if (key === 'depends_on') {
|
||||
const old = node.dependsOn;
|
||||
node.dependsOn = value;
|
||||
@@ -223,13 +223,13 @@ export const PaneFO = {
|
||||
onChange: ({ key, value }) => {
|
||||
if (key === 'id') { node.id = value; markBarDirty(); return; }
|
||||
if (key === 'beats_per_minute') node.tempoLevels = isNaN(value) ? null : value;
|
||||
if (key === 'stress_pattern') node.stressor = parseStressor(value);
|
||||
if (key === 'stress_pattern') node.stressor = _parseStressor(value);
|
||||
markBarDirty();
|
||||
},
|
||||
}),
|
||||
shapeSection('Upper stress bound', node.upperStressBound, markBarDirty),
|
||||
shapeSection('Lower stress bound', node.lowerStressBound, markBarDirty),
|
||||
shapeSection('Tempo shape', node.tempoShape, markBarDirty),
|
||||
_shapeSection('Upper stress bound', node.upperStressBound, markBarDirty),
|
||||
_shapeSection('Lower stress bound', node.lowerStressBound, markBarDirty),
|
||||
_shapeSection('Tempo shape', node.tempoShape, markBarDirty),
|
||||
);
|
||||
} else if (node.type === 'voice') {
|
||||
children.push(
|
||||
@@ -254,7 +254,7 @@ export const PaneFO = {
|
||||
node.motifRefs?.length
|
||||
? { key: 'motifRefs', value: node.motifRefs.map(m => m.chord ? `${m.label}(${m.chord})` : m.label).join(', '), editable: false }
|
||||
: null,
|
||||
...unknownPropFields(node),
|
||||
..._unknownPropFields(node),
|
||||
].filter(Boolean),
|
||||
onChange: null,
|
||||
}),
|
||||
@@ -269,7 +269,7 @@ export const PaneFO = {
|
||||
{ key: 'label', value: node.label, editable: false },
|
||||
{ key: 'static', value: node.isStatic, editable: false, type: 'boolean' },
|
||||
{ key: 'stem notes', value: node.stemNotes.map(pitchLabel).join(', ') || '—', editable: false },
|
||||
...unknownPropFields(node),
|
||||
..._unknownPropFields(node),
|
||||
],
|
||||
onChange: null,
|
||||
}),
|
||||
@@ -291,7 +291,7 @@ export const PaneFO = {
|
||||
{ key: 'adj_stress', value: node.adjStress != null ? String(node.adjStress) : '', editable: true, type: 'number' },
|
||||
{ key: 'chain', value: node.chainText, editable: true },
|
||||
{ key: 'clauses', value: String(node.clauses.length), editable: false },
|
||||
...unknownPropFields(node),
|
||||
..._unknownPropFields(node),
|
||||
],
|
||||
onChange: ({ key, value }) => {
|
||||
if (key === 'pitch') node.pitch = value;
|
||||
|
||||
@@ -4,13 +4,13 @@ import { getKindGroups } from '../subobject-kinds.js';
|
||||
|
||||
// Strip the final maximal run of same-class characters (all-digits or all-non-digits)
|
||||
// from the ID tail. Everything before that run is the group key.
|
||||
function barGroupKey(id) {
|
||||
function _barGroupKey(id) {
|
||||
const m = id.match(/(\d+|\D+)$/);
|
||||
return m ? id.slice(0, m.index) : id;
|
||||
}
|
||||
|
||||
// Increment the trailing numeric run of an ID, preserving zero-padding width.
|
||||
function incrementId(id) {
|
||||
function _incrementId(id) {
|
||||
const m = id.match(/(\d+)$/);
|
||||
if (!m) return id + '1';
|
||||
const num = parseInt(m[1], 10) + 1;
|
||||
@@ -70,10 +70,10 @@ export const PaneSubObjects = {
|
||||
if (!model) return;
|
||||
let newId;
|
||||
if (afterId) {
|
||||
newId = incrementId(afterId);
|
||||
newId = _incrementId(afterId);
|
||||
} else {
|
||||
const liveBars = (model.bars ?? []).filter(b => !b.deleted);
|
||||
newId = liveBars.length ? incrementId(liveBars[liveBars.length - 1].id) : 'bar001';
|
||||
newId = liveBars.length ? _incrementId(liveBars[liveBars.length - 1].id) : 'bar001';
|
||||
}
|
||||
const newBar = {
|
||||
type: 'bar', id: newId, isDirty: true, isNew: true,
|
||||
@@ -103,7 +103,7 @@ export const PaneSubObjects = {
|
||||
const barGroups = [];
|
||||
const seen = new Map();
|
||||
for (const item of visibleItems) {
|
||||
const key = barGroupKey(item.label);
|
||||
const key = _barGroupKey(item.label);
|
||||
if (!seen.has(key)) {
|
||||
const g = { key, items: [] };
|
||||
barGroups.push(g);
|
||||
|
||||
Reference in New Issue
Block a user