@mark1russell7/vex 0.3.0 → 0.4.0
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/build/index.d.ts +41 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +293 -79
- package/build/index.js.map +1 -1
- package/package.json +3 -2
- package/src/builder.ts +69 -16
- package/src/deps.ts +8 -5
- package/src/evaluate.ts +45 -10
- package/src/ir.ts +9 -4
- package/src/json.ts +162 -51
- package/src/sheet.ts +30 -5
- package/src/space.ts +10 -0
package/src/space.ts
CHANGED
|
@@ -225,6 +225,16 @@ export function applyMove(s: Space, at: Position, m: Move): Result<string> {
|
|
|
225
225
|
return ok(at.focus === a ? (b ?? at.focus) : (a ?? at.focus));
|
|
226
226
|
}
|
|
227
227
|
case "offset": {
|
|
228
|
+
// In a tree space, an offset with one number moves among the siblings in key order. The roots are siblings.
|
|
229
|
+
const parentOf = s.parentOf?.bind(s);
|
|
230
|
+
const childrenOf = s.childrenOf?.bind(s);
|
|
231
|
+
if (parentOf !== undefined && childrenOf !== undefined && m.d.length === 1) {
|
|
232
|
+
const p = parentOf(at.focus);
|
|
233
|
+
const group = p === undefined ? s.keys.filter((k) => parentOf(k) === undefined) : childrenOf(p);
|
|
234
|
+
const i = group.indexOf(at.focus);
|
|
235
|
+
const k = i < 0 ? undefined : group[i + (m.d[0] ?? 0)];
|
|
236
|
+
return k === undefined ? refError("out-of-bounds", `the offset [${m.d.join(",")}] from "${at.focus}" is outside its siblings`) : ok(k);
|
|
237
|
+
}
|
|
228
238
|
const c = s.coords(at.focus);
|
|
229
239
|
if (c === undefined || c.length !== m.d.length) {
|
|
230
240
|
return refError("no-offset", `an offset of length ${m.d.length} is not valid in a ${s.kind} space`);
|