@octanejs/radix 0.1.48 → 0.1.50
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/README.md +7 -0
- package/dist/cjs/collection-order.cjs +44 -0
- package/dist/cjs/collection.cjs +5 -4
- package/package.json +4 -4
- package/src/collection-order.ts +24 -0
- package/src/collection.ts +5 -4
package/README.md
CHANGED
|
@@ -7,6 +7,13 @@ primitives) on octane's hooks. It mirrors the unified `radix-ui` package's shape
|
|
|
7
7
|
low-level composition utilities are exported directly, and each component is a namespace
|
|
8
8
|
(`Separator.Root`, `Label.Root`).
|
|
9
9
|
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @octanejs/radix
|
|
14
|
+
pnpm add @octanejs/radix
|
|
15
|
+
```
|
|
16
|
+
|
|
10
17
|
```tsx
|
|
11
18
|
import { Separator, Label } from '@octanejs/radix';
|
|
12
19
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var collection_order_exports = {};
|
|
20
|
+
__export(collection_order_exports, {
|
|
21
|
+
COLLECTION_ORDER_INDEX_THRESHOLD: () => COLLECTION_ORDER_INDEX_THRESHOLD,
|
|
22
|
+
sortCollectionItemsByDomOrder: () => sortCollectionItemsByDomOrder
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(collection_order_exports);
|
|
25
|
+
const COLLECTION_ORDER_INDEX_THRESHOLD = 256;
|
|
26
|
+
function sortCollectionItemsByDomOrder(orderedNodes, items) {
|
|
27
|
+
if (items.length >= COLLECTION_ORDER_INDEX_THRESHOLD) {
|
|
28
|
+
const nodeIndexes = /* @__PURE__ */ new Map();
|
|
29
|
+
for (let index = 0; index < orderedNodes.length; index++) {
|
|
30
|
+
nodeIndexes.set(orderedNodes[index], index);
|
|
31
|
+
}
|
|
32
|
+
return items.sort(
|
|
33
|
+
(a, b) => (nodeIndexes.get(a.ref.current) ?? -1) - (nodeIndexes.get(b.ref.current) ?? -1)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return items.sort(
|
|
37
|
+
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
COLLECTION_ORDER_INDEX_THRESHOLD,
|
|
43
|
+
sortCollectionItemsByDomOrder
|
|
44
|
+
});
|
package/dist/cjs/collection.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __export(collection_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(collection_exports);
|
|
24
24
|
var import_octane = require("octane");
|
|
25
|
+
var import_collection_order = require("./collection-order.cjs");
|
|
25
26
|
var import_compose_refs = require("./compose-refs.cjs");
|
|
26
27
|
var import_context = require("./context.cjs");
|
|
27
28
|
var import_internal = require("./internal.cjs");
|
|
@@ -76,11 +77,11 @@ function createCollection(name) {
|
|
|
76
77
|
return () => {
|
|
77
78
|
const collectionNode = context.collectionRef.current;
|
|
78
79
|
if (!collectionNode) return [];
|
|
79
|
-
const orderedNodes = Array.from(
|
|
80
|
-
|
|
81
|
-
return items.sort(
|
|
82
|
-
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
80
|
+
const orderedNodes = Array.from(
|
|
81
|
+
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
83
82
|
);
|
|
83
|
+
const items = Array.from(context.itemMap.values());
|
|
84
|
+
return (0, import_collection_order.sortCollectionItemsByDomOrder)(orderedNodes, items);
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/radix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"aria-hidden": "^1.2.6",
|
|
50
|
-
"@octanejs/floating-ui": "0.1.
|
|
50
|
+
"@octanejs/floating-ui": "0.1.50"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"octane": "0.1.
|
|
53
|
+
"octane": "0.1.51"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@tsrx/react": "^0.2.61",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"react": "^19.2.7",
|
|
60
60
|
"react-dom": "^19.2.7",
|
|
61
61
|
"vitest": "^4.1.10",
|
|
62
|
-
"octane": "0.1.
|
|
62
|
+
"octane": "0.1.51"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build:cjs": "node ../../scripts/build-package-commonjs.mjs",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface CollectionItem<TNode> {
|
|
2
|
+
ref: { current: TNode | null };
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const COLLECTION_ORDER_INDEX_THRESHOLD = 256;
|
|
6
|
+
|
|
7
|
+
export function sortCollectionItemsByDomOrder<TNode, TItem extends CollectionItem<TNode>>(
|
|
8
|
+
orderedNodes: readonly TNode[],
|
|
9
|
+
items: TItem[],
|
|
10
|
+
): TItem[] {
|
|
11
|
+
if (items.length >= COLLECTION_ORDER_INDEX_THRESHOLD) {
|
|
12
|
+
const nodeIndexes = new Map<TNode, number>();
|
|
13
|
+
for (let index = 0; index < orderedNodes.length; index++) {
|
|
14
|
+
nodeIndexes.set(orderedNodes[index], index);
|
|
15
|
+
}
|
|
16
|
+
return items.sort(
|
|
17
|
+
(a, b) => (nodeIndexes.get(a.ref.current!) ?? -1) - (nodeIndexes.get(b.ref.current!) ?? -1),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return items.sort(
|
|
22
|
+
(a, b) => orderedNodes.indexOf(a.ref.current!) - orderedNodes.indexOf(b.ref.current!),
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/collection.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// octane ref-as-prop + our `Slot`.
|
|
7
7
|
import { createElement, useEffect, useRef } from 'octane';
|
|
8
8
|
|
|
9
|
+
import { sortCollectionItemsByDomOrder } from './collection-order';
|
|
9
10
|
import { useComposedRefs } from './compose-refs';
|
|
10
11
|
import { createContextScope } from './context';
|
|
11
12
|
import { S, splitSlot, subSlot } from './internal';
|
|
@@ -81,11 +82,11 @@ export function createCollection(name: string): [
|
|
|
81
82
|
return () => {
|
|
82
83
|
const collectionNode = context.collectionRef.current;
|
|
83
84
|
if (!collectionNode) return [];
|
|
84
|
-
const orderedNodes = Array.from(
|
|
85
|
-
|
|
86
|
-
return items.sort(
|
|
87
|
-
(a, b) => orderedNodes.indexOf(a.ref.current!) - orderedNodes.indexOf(b.ref.current!),
|
|
85
|
+
const orderedNodes = Array.from(
|
|
86
|
+
collectionNode.querySelectorAll<HTMLElement>(`[${ITEM_DATA_ATTR}]`),
|
|
88
87
|
);
|
|
88
|
+
const items = Array.from(context.itemMap.values());
|
|
89
|
+
return sortCollectionItemsByDomOrder(orderedNodes, items);
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
|