@opendaw/lib-box 0.0.14 → 0.0.15
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/dist/indexed-box.d.ts +1 -0
- package/dist/indexed-box.d.ts.map +1 -1
- package/dist/indexed-box.js +21 -0
- package/package.json +6 -6
package/dist/indexed-box.d.ts
CHANGED
@@ -9,6 +9,7 @@ export type IndexedBox = Box & Record<"index", Int32Field>;
|
|
9
9
|
export declare namespace IndexedBox {
|
10
10
|
const insertOrder: (field: Field, insertIndex?: int) => int;
|
11
11
|
const removeOrder: (field: Field, removeIndex: int) => void;
|
12
|
+
const moveIndex: (field: Field, startIndex: int, delta: int) => void;
|
12
13
|
const isIndexedBox: (box: Box) => box is IndexedBox;
|
13
14
|
const collectIndexedBoxes: <B extends IndexedBox>(field: Field, type?: Class<B>) => ReadonlyArray<B>;
|
14
15
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"indexed-box.d.ts","sourceRoot":"","sources":["../src/indexed-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAQ,KAAK,EAAE,GAAG,EAAQ,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AAEzB;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;AAE1D,yBAAiB,UAAU,CAAC;IACjB,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,cAAa,GAA6B,KAAG,GAStF,CAAA;IAEM,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,aAAa,GAAG,KAAG,IAO5D,CAAA;IAEM,MAAM,YAAY,GAAI,KAAK,GAAG,KAAG,GAAG,IAAI,UAA+D,CAAA;IAEvG,MAAM,mBAAmB,GAAI,CAAC,SAAS,UAAU,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAG,aAAa,CAAC,CAAC,CAKzC,CAAA;CACnE"}
|
1
|
+
{"version":3,"file":"indexed-box.d.ts","sourceRoot":"","sources":["../src/indexed-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAQ,KAAK,EAAE,GAAG,EAAQ,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAA;AAEzB;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;AAE1D,yBAAiB,UAAU,CAAC;IACjB,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,cAAa,GAA6B,KAAG,GAStF,CAAA;IAEM,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,aAAa,GAAG,KAAG,IAO5D,CAAA;IAEM,MAAM,SAAS,GAAI,OAAO,KAAK,EAAE,YAAY,GAAG,EAAE,OAAO,GAAG,KAAG,IAkBrE,CAAA;IAEM,MAAM,YAAY,GAAI,KAAK,GAAG,KAAG,GAAG,IAAI,UAA+D,CAAA;IAEvG,MAAM,mBAAmB,GAAI,CAAC,SAAS,UAAU,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAG,aAAa,CAAC,CAAC,CAKzC,CAAA;CACnE"}
|
package/dist/indexed-box.js
CHANGED
@@ -20,6 +20,27 @@ export var IndexedBox;
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
};
|
23
|
+
IndexedBox.moveIndex = (field, startIndex, delta) => {
|
24
|
+
const boxes = IndexedBox.collectIndexedBoxes(field);
|
25
|
+
const movingBox = boxes[startIndex];
|
26
|
+
if (delta < 0) {
|
27
|
+
const newIndex = clamp(startIndex + delta, 0, boxes.length - 1);
|
28
|
+
for (let index = newIndex; index < startIndex; index++) {
|
29
|
+
boxes[index].index.setValue(index + 1);
|
30
|
+
}
|
31
|
+
movingBox.index.setValue(newIndex);
|
32
|
+
}
|
33
|
+
else if (delta > 1) {
|
34
|
+
const newIndex = clamp(startIndex + (delta - 1), 0, boxes.length - 1);
|
35
|
+
for (let index = startIndex; index < newIndex; index++) {
|
36
|
+
boxes[index + 1].index.setValue(index);
|
37
|
+
}
|
38
|
+
movingBox.index.setValue(newIndex);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
console.warn(`moveIndex had no effect: startIndex: ${startIndex}, delta: ${delta}`);
|
42
|
+
}
|
43
|
+
};
|
23
44
|
IndexedBox.isIndexedBox = (box) => "index" in box && box.index instanceof Int32Field;
|
24
45
|
IndexedBox.collectIndexedBoxes = (field, type) => field.pointerHub.incoming()
|
25
46
|
.map(({ box }) => IndexedBox.isIndexedBox(box) && (type === undefined || box instanceof type)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opendaw/lib-box",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.15",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"license": "LGPL-3.0-or-later",
|
@@ -22,12 +22,12 @@
|
|
22
22
|
"test": "vitest run"
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@opendaw/lib-runtime": "^0.0.
|
26
|
-
"@opendaw/lib-std": "^0.0.
|
25
|
+
"@opendaw/lib-runtime": "^0.0.15",
|
26
|
+
"@opendaw/lib-std": "^0.0.15"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
|
-
"@opendaw/eslint-config": "^0.0.
|
30
|
-
"@opendaw/typescript-config": "^0.0.
|
29
|
+
"@opendaw/eslint-config": "^0.0.15",
|
30
|
+
"@opendaw/typescript-config": "^0.0.15"
|
31
31
|
},
|
32
|
-
"gitHead": "
|
32
|
+
"gitHead": "76b361985c1e34e609619835960e58ae7fbfd7d2"
|
33
33
|
}
|