Skip to content

Commit d6bc520

Browse files
author
Michael Jordan
committed
Merge branch 'main' into Issue-4967-useNumberField-input-masking
2 parents 49c33f6 + 99c3106 commit d6bc520

File tree

119 files changed

+3009
-1911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+3009
-1911
lines changed

.github/workflows/pr-comment.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"nyc": "^10.2.0",
159159
"p-queue": "^6.2.1",
160160
"parcel": "2.0.0-dev.1599",
161-
"parcel-resolver-storybook": "https://gitpkg.now.sh/mischnic/storybook-parcel/packages/parcel-resolver-storybook?master",
161+
"parcel-resolver-storybook": "https://gitpkg.vercel.app/mischnic/storybook-parcel/packages/parcel-resolver-storybook?master",
162162
"patch-package": "^6.2.0",
163163
"plop": "^2.4.0",
164164
"postcss": "^8.4.24",
@@ -178,9 +178,9 @@
178178
"sharp": "^0.31.2",
179179
"sinon": "^7.3.1",
180180
"storybook": "^7.6.19",
181-
"storybook-builder-parcel": "https://gitpkg.now.sh/mischnic/storybook-parcel/packages/storybook-builder-parcel?master",
181+
"storybook-builder-parcel": "https://gitpkg.vercel.app/mischnic/storybook-parcel/packages/storybook-builder-parcel?master",
182182
"storybook-dark-mode": "^3.0.3",
183-
"storybook-react-parcel": "https://gitpkg.now.sh/mischnic/storybook-parcel/packages/storybook-react-parcel?master",
183+
"storybook-react-parcel": "https://gitpkg.vercel.app/mischnic/storybook-parcel/packages/storybook-react-parcel?master",
184184
"tailwind-variants": "^0.1.18",
185185
"tailwindcss": "^3.4.0",
186186
"tailwindcss-animate": "^1.0.7",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @react-aria/collections
2+
3+
This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
export * from './src';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@react-aria/collections",
3+
"version": "3.0.0-alpha.1",
4+
"description": "Spectrum UI components in React",
5+
"license": "Apache-2.0",
6+
"main": "dist/main.js",
7+
"module": "dist/module.js",
8+
"types": "dist/types.d.ts",
9+
"exports": {
10+
"types": "./dist/types.d.ts",
11+
"import": "./dist/import.mjs",
12+
"require": "./dist/main.js"
13+
},
14+
"source": "src/index.ts",
15+
"files": [
16+
"dist",
17+
"src"
18+
],
19+
"sideEffects": false,
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/adobe/react-spectrum"
23+
},
24+
"dependencies": {
25+
"@react-aria/ssr": "^3.9.4",
26+
"@react-aria/utils": "^3.24.1",
27+
"@react-types/shared": "^3.23.1",
28+
"@swc/helpers": "^0.5.0",
29+
"use-sync-external-store": "^1.2.0"
30+
},
31+
"peerDependencies": {
32+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
33+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
34+
},
35+
"publishConfig": {
36+
"access": "public"
37+
}
38+
}
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Collection as ICollection, Key, Node} from '@react-types/shared';
14+
import {ReactElement, ReactNode} from 'react';
15+
16+
export type Mutable<T> = {
17+
-readonly[P in keyof T]: T[P]
18+
}
19+
20+
/** An immutable object representing a Node in a Collection. */
21+
export class NodeValue<T> implements Node<T> {
22+
readonly type: string;
23+
readonly key: Key;
24+
readonly value: T | null = null;
25+
readonly level: number = 0;
26+
readonly hasChildNodes: boolean = false;
27+
readonly rendered: ReactNode = null;
28+
readonly textValue: string = '';
29+
readonly 'aria-label'?: string = undefined;
30+
readonly index: number = 0;
31+
readonly parentKey: Key | null = null;
32+
readonly prevKey: Key | null = null;
33+
readonly nextKey: Key | null = null;
34+
readonly firstChildKey: Key | null = null;
35+
readonly lastChildKey: Key | null = null;
36+
readonly props: any = {};
37+
readonly render?: (node: Node<any>) => ReactElement;
38+
39+
constructor(type: string, key: Key) {
40+
this.type = type;
41+
this.key = key;
42+
}
43+
44+
get childNodes(): Iterable<Node<T>> {
45+
throw new Error('childNodes is not supported');
46+
}
47+
48+
clone(): NodeValue<T> {
49+
let node: Mutable<NodeValue<T>> = new NodeValue(this.type, this.key);
50+
node.value = this.value;
51+
node.level = this.level;
52+
node.hasChildNodes = this.hasChildNodes;
53+
node.rendered = this.rendered;
54+
node.textValue = this.textValue;
55+
node['aria-label'] = this['aria-label'];
56+
node.index = this.index;
57+
node.parentKey = this.parentKey;
58+
node.prevKey = this.prevKey;
59+
node.nextKey = this.nextKey;
60+
node.firstChildKey = this.firstChildKey;
61+
node.lastChildKey = this.lastChildKey;
62+
node.props = this.props;
63+
node.render = this.render;
64+
return node;
65+
}
66+
}
67+
68+
/**
69+
* An immutable Collection implementation. Updates are only allowed
70+
* when it is not marked as frozen. This can be subclassed to implement
71+
* custom collection behaviors.
72+
*/
73+
export class BaseCollection<T> implements ICollection<Node<T>> {
74+
private keyMap: Map<Key, NodeValue<T>> = new Map();
75+
private firstKey: Key | null = null;
76+
private lastKey: Key | null = null;
77+
private frozen = false;
78+
79+
get size() {
80+
return this.keyMap.size;
81+
}
82+
83+
getKeys() {
84+
return this.keyMap.keys();
85+
}
86+
87+
*[Symbol.iterator]() {
88+
let node: Node<T> | undefined = this.firstKey != null ? this.keyMap.get(this.firstKey) : undefined;
89+
while (node) {
90+
yield node;
91+
node = node.nextKey != null ? this.keyMap.get(node.nextKey) : undefined;
92+
}
93+
}
94+
95+
getChildren(key: Key): Iterable<Node<T>> {
96+
let keyMap = this.keyMap;
97+
return {
98+
*[Symbol.iterator]() {
99+
let parent = keyMap.get(key);
100+
let node = parent?.firstChildKey != null ? keyMap.get(parent.firstChildKey) : null;
101+
while (node) {
102+
yield node as Node<T>;
103+
node = node.nextKey != null ? keyMap.get(node.nextKey) : undefined;
104+
}
105+
}
106+
};
107+
}
108+
109+
getKeyBefore(key: Key) {
110+
let node = this.keyMap.get(key);
111+
if (!node) {
112+
return null;
113+
}
114+
115+
if (node.prevKey != null) {
116+
node = this.keyMap.get(node.prevKey);
117+
118+
while (node && node.type !== 'item' && node.lastChildKey != null) {
119+
node = this.keyMap.get(node.lastChildKey);
120+
}
121+
122+
return node?.key ?? null;
123+
}
124+
125+
return node.parentKey;
126+
}
127+
128+
getKeyAfter(key: Key) {
129+
let node = this.keyMap.get(key);
130+
if (!node) {
131+
return null;
132+
}
133+
134+
if (node.type !== 'item' && node.firstChildKey != null) {
135+
return node.firstChildKey;
136+
}
137+
138+
while (node) {
139+
if (node.nextKey != null) {
140+
return node.nextKey;
141+
}
142+
143+
if (node.parentKey != null) {
144+
node = this.keyMap.get(node.parentKey);
145+
} else {
146+
return null;
147+
}
148+
}
149+
150+
return null;
151+
}
152+
153+
getFirstKey() {
154+
return this.firstKey;
155+
}
156+
157+
getLastKey() {
158+
let node = this.lastKey != null ? this.keyMap.get(this.lastKey) : null;
159+
while (node?.lastChildKey != null) {
160+
node = this.keyMap.get(node.lastChildKey);
161+
}
162+
163+
return node?.key ?? null;
164+
}
165+
166+
getItem(key: Key): Node<T> | null {
167+
return this.keyMap.get(key) ?? null;
168+
}
169+
170+
at(): Node<T> {
171+
throw new Error('Not implemented');
172+
}
173+
174+
clone(): this {
175+
// We need to clone using this.constructor so that subclasses have the right prototype.
176+
// TypeScript isn't happy about this yet.
177+
// https://github.com/microsoft/TypeScript/issues/3841
178+
let Constructor: any = this.constructor;
179+
let collection: this = new Constructor();
180+
collection.keyMap = new Map(this.keyMap);
181+
collection.firstKey = this.firstKey;
182+
collection.lastKey = this.lastKey;
183+
return collection;
184+
}
185+
186+
addNode(node: NodeValue<T>) {
187+
if (this.frozen) {
188+
throw new Error('Cannot add a node to a frozen collection');
189+
}
190+
191+
this.keyMap.set(node.key, node);
192+
}
193+
194+
removeNode(key: Key) {
195+
if (this.frozen) {
196+
throw new Error('Cannot remove a node to a frozen collection');
197+
}
198+
199+
this.keyMap.delete(key);
200+
}
201+
202+
commit(firstKey: Key | null, lastKey: Key | null, isSSR = false) {
203+
if (this.frozen) {
204+
throw new Error('Cannot commit a frozen collection');
205+
}
206+
207+
this.firstKey = firstKey;
208+
this.lastKey = lastKey;
209+
this.frozen = !isSSR;
210+
}
211+
}

0 commit comments

Comments
 (0)