@dxos/react-list 0.1.5
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/LICENSE +8 -0
- package/dist/src/components/List/List.d.ts +8 -0
- package/dist/src/components/List/List.d.ts.map +1 -0
- package/dist/src/components/List/List.js +98 -0
- package/dist/src/components/List/List.js.map +1 -0
- package/dist/src/components/List/List.stories.d.ts +14 -0
- package/dist/src/components/List/List.stories.d.ts.map +1 -0
- package/dist/src/components/List/List.stories.js +116 -0
- package/dist/src/components/List/List.stories.js.map +1 -0
- package/dist/src/components/List/index.d.ts +2 -0
- package/dist/src/components/List/index.d.ts.map +1 -0
- package/dist/src/components/List/index.js +21 -0
- package/dist/src/components/List/index.js.map +1 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.d.ts +52 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.d.ts.map +1 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.js +184 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.js.map +1 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.stories.d.ts +10 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.stories.d.ts.map +1 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.stories.js +42 -0
- package/dist/src/components/ListPrimitive/ListPrimitive.stories.js.map +1 -0
- package/dist/src/components/ListPrimitive/index.d.ts +2 -0
- package/dist/src/components/ListPrimitive/index.d.ts.map +1 -0
- package/dist/src/components/ListPrimitive/index.js +21 -0
- package/dist/src/components/ListPrimitive/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +21 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/hooks/index.d.ts +2 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +21 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/usePropStatefully.d.ts +6 -0
- package/dist/src/hooks/usePropStatefully.d.ts.map +1 -0
- package/dist/src/hooks/usePropStatefully.js +30 -0
- package/dist/src/hooks/usePropStatefully.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/model.d.ts +3 -0
- package/dist/src/model.d.ts.map +1 -0
- package/dist/src/model.js +9 -0
- package/dist/src/model.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +21 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/templateForComponent.d.ts +4 -0
- package/dist/src/testing/templateForComponent.d.ts.map +1 -0
- package/dist/src/testing/templateForComponent.js +18 -0
- package/dist/src/testing/templateForComponent.js.map +1 -0
- package/package.json +42 -0
- package/src/components/List/List.stories.tsx +123 -0
- package/src/components/List/List.tsx +111 -0
- package/src/components/List/index.ts +5 -0
- package/src/components/ListPrimitive/ListPrimitive.stories.tsx +43 -0
- package/src/components/ListPrimitive/ListPrimitive.tsx +376 -0
- package/src/components/ListPrimitive/index.ts +5 -0
- package/src/components/index.ts +5 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/usePropStatefully.ts +33 -0
- package/src/index.ts +6 -0
- package/src/model.ts +6 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/templateForComponent.tsx +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListPrimitive.stories.js","sourceRoot":"","sources":["../../../../src/components/ListPrimitive/ListPrimitive.stories.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,sBAAoB;AACpB,kDAA0B;AAE1B,2CAAqD;AACrD,mDAA6E;AAE7E,kBAAe;IACb,KAAK,EAAE,0BAA0B;IACjC,SAAS,EAAE,6BAAa;IACxB,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,IAA+C,EAAE,EAAE;IACnE,OAAO,CACL,wCAAM,SAAS,EAAC,gCAAgC;QAC9C,8BAAC,6BAAa,OAAK,IAAI,GAAI,CACtB,CACR,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,OAAO,GAAG,IAAA,8BAAoB,EAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;AAC7E,eAAO,CAAC,IAAI,GAAG;IACb,EAAE,EAAE,SAAS;IACb,KAAK,EAAE;QACL,OAAO,EAAE;YACP,KAAK,EAAE,OAAO;SACf;QACD,OAAO,EAAE;YACP,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;SAC/B;QACD,OAAO,EAAE;YACP,KAAK,EAAE,QAAQ;SAChB;QACD,OAAO,EAAE;YACP,KAAK,EAAE,WAAW;SACnB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ListPrimitive/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./ListPrimitive"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ListPrimitive/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,kDAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./List"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,yCAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./usePropStatefully"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,sDAAoC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
*/
|
|
5
|
+
export declare const usePropStatefully: <T>(propsValue: T, equivalentPredicate?: ((a: T, b: T) => boolean) | undefined) => [T, Dispatch<SetStateAction<T>>, string];
|
|
6
|
+
//# sourceMappingURL=usePropStatefully.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePropStatefully.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePropStatefully.ts"],"names":[],"mappings":"AAIA,OAAO,EAA+B,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAM9E;;GAEG;AACH,eAAO,MAAM,iBAAiB,4DAEU,OAAO,0DAiB9C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.usePropStatefully = void 0;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_uikit_1 = require("@dxos/react-uikit");
|
|
9
|
+
const isEqual = (a, b) => a === b;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
const usePropStatefully = (propsValue, equivalentPredicate) => {
|
|
14
|
+
const [value, setValue] = (0, react_1.useState)(propsValue);
|
|
15
|
+
const [valueSession, setValueSession] = (0, react_1.useState)((0, react_uikit_1.randomString)());
|
|
16
|
+
const mounted = (0, react_1.useRef)(false);
|
|
17
|
+
const predicate = equivalentPredicate !== null && equivalentPredicate !== void 0 ? equivalentPredicate : (isEqual);
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
if (mounted.current && !predicate(propsValue, value)) {
|
|
20
|
+
setValue(propsValue);
|
|
21
|
+
setValueSession((0, react_uikit_1.randomString)());
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
mounted.current = true;
|
|
25
|
+
}
|
|
26
|
+
}, [propsValue]);
|
|
27
|
+
return [value, setValue, valueSession];
|
|
28
|
+
};
|
|
29
|
+
exports.usePropStatefully = usePropStatefully;
|
|
30
|
+
//# sourceMappingURL=usePropStatefully.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePropStatefully.js","sourceRoot":"","sources":["../../../src/hooks/usePropStatefully.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,iCAA8E;AAE9E,mDAAiD;AAEjD,MAAM,OAAO,GAAG,CAAI,CAAI,EAAE,CAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAE3C;;GAEG;AACI,MAAM,iBAAiB,GAAG,CAC/B,UAAa,EACb,mBAA6C,EACH,EAAE;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAI,UAAU,CAAC,CAAC;IAClD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAA,0BAAY,GAAE,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,IAAI,OAAU,CAAA,CAAC;IAEpD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;YACpD,QAAQ,CAAC,UAAU,CAAC,CAAC;YACrB,eAAe,CAAC,IAAA,0BAAY,GAAE,CAAC,CAAC;SACjC;aAAM;YACL,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;SACxB;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AACzC,CAAC,CAAC;AAnBW,QAAA,iBAAiB,qBAmB5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./components"), exports);
|
|
21
|
+
__exportStar(require("./model"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,+CAA6B;AAC7B,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,mBAAmB,CAAC;AAC1C,eAAO,MAAM,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LIST_ITEM_TYPE = exports.LIST_TYPE = void 0;
|
|
7
|
+
exports.LIST_TYPE = 'dxos:type/list';
|
|
8
|
+
exports.LIST_ITEM_TYPE = 'dxos:type/list-item';
|
|
9
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEW,QAAA,SAAS,GAAG,gBAAgB,CAAC;AAC7B,QAAA,cAAc,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./templateForComponent"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,yDAAuC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateForComponent.d.ts","sourceRoot":"","sources":["../../../src/testing/templateForComponent.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAElC,eAAO,MAAM,oBAAoB,kEAQ9B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.templateForComponent = void 0;
|
|
10
|
+
const react_1 = __importDefault(require("react"));
|
|
11
|
+
const templateForComponent = (Component) => (props) => {
|
|
12
|
+
const template = (args) => react_1.default.createElement(Component, { ...args });
|
|
13
|
+
const story = template.bind({});
|
|
14
|
+
story.args = props;
|
|
15
|
+
return story;
|
|
16
|
+
};
|
|
17
|
+
exports.templateForComponent = templateForComponent;
|
|
18
|
+
//# sourceMappingURL=templateForComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateForComponent.js","sourceRoot":"","sources":["../../../src/testing/templateForComponent.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAGF,kDAAkC;AAE3B,MAAM,oBAAoB,GAC/B,CAAe,SAAgB,EAAE,EAAE,CACnC,CAAC,KAAQ,EAAY,EAAE;IACrB,MAAM,QAAQ,GAAqC,CAAC,IAAI,EAAE,EAAE,CAAC,8BAAC,SAAS,OAAK,IAAI,GAAI,CAAC;IAErF,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AARS,QAAA,oBAAoB,wBAQ7B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/react-list",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "A list editing experience component for DXOS.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"main": "dist/src/index.js",
|
|
10
|
+
"types": "dist/src/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@dxos/client": "0.1.6",
|
|
17
|
+
"@dxos/config": "0.1.6",
|
|
18
|
+
"@dxos/object-model": "0.1.6",
|
|
19
|
+
"@dxos/react-appkit": "0.1.6",
|
|
20
|
+
"@dxos/react-async": "0.1.6",
|
|
21
|
+
"@dxos/react-client": "0.1.6",
|
|
22
|
+
"@dxos/react-ui": "0.1.6",
|
|
23
|
+
"@dxos/react-uikit": "0.1.6",
|
|
24
|
+
"classnames": "^2.3.2",
|
|
25
|
+
"react": "^18.2.0",
|
|
26
|
+
"react-dom": "^18.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@dxos/async": "0.1.6",
|
|
30
|
+
"@dxos/debug": "0.1.6",
|
|
31
|
+
"@dxos/vite-plugin": "0.1.6",
|
|
32
|
+
"@types/react": "^18.0.21",
|
|
33
|
+
"@types/react-dom": "^18.0.6",
|
|
34
|
+
"phosphor-react": "^1.4.1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"phosphor-react": "^1.4.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxosTheme';
|
|
6
|
+
import React, { useMemo, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Trigger } from '@dxos/async';
|
|
9
|
+
import { Client, Invitation, PublicKey, TestClientBuilder } from '@dxos/client';
|
|
10
|
+
import { raise } from '@dxos/debug';
|
|
11
|
+
import { ObjectModel } from '@dxos/object-model';
|
|
12
|
+
import { useAsyncEffect } from '@dxos/react-async';
|
|
13
|
+
import { ClientProvider, useSelection, useSpace } from '@dxos/react-client';
|
|
14
|
+
import { Loading } from '@dxos/react-uikit';
|
|
15
|
+
|
|
16
|
+
import { LIST_TYPE } from '../../model';
|
|
17
|
+
import { templateForComponent } from '../../testing';
|
|
18
|
+
import { List, ListProps } from './List';
|
|
19
|
+
|
|
20
|
+
// TODO(wittjosiah): @dxos/log.
|
|
21
|
+
const log = console.log;
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
title: 'react-list/List',
|
|
25
|
+
component: List,
|
|
26
|
+
argTypes: {}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const Template = (args: Omit<ListProps, 'itemId' | 'spaceKey'> & { spaceKey?: PublicKey; id?: number }) => {
|
|
30
|
+
const space = useSpace(args.spaceKey);
|
|
31
|
+
const [item] = useSelection(space?.database.select({ type: LIST_TYPE })) ?? [];
|
|
32
|
+
|
|
33
|
+
useAsyncEffect(async () => {
|
|
34
|
+
if (args.id === 0) {
|
|
35
|
+
await space?.database.createItem({
|
|
36
|
+
model: ObjectModel,
|
|
37
|
+
type: LIST_TYPE
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [space]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<main className='max-is-lg mli-auto pli-7 mbs-7'>
|
|
44
|
+
{item && space ? <List {...args} itemId={item.id} spaceKey={space?.key} /> : <Loading label='Loading…' />}
|
|
45
|
+
</main>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Default = templateForComponent(Template)({});
|
|
50
|
+
Default.args = {};
|
|
51
|
+
Default.decorators = [
|
|
52
|
+
// TODO(wittjosiah): Factor out.
|
|
53
|
+
(Story) => {
|
|
54
|
+
const n = 2;
|
|
55
|
+
const clients = useMemo(() => {
|
|
56
|
+
const testBuilder = new TestClientBuilder();
|
|
57
|
+
return [...Array(n)].map(() => new Client({ services: testBuilder.createClientServicesHost() }));
|
|
58
|
+
}, []);
|
|
59
|
+
const [spaceKey, setSpaceKey] = useState<PublicKey>();
|
|
60
|
+
|
|
61
|
+
useAsyncEffect(async () => {
|
|
62
|
+
await Promise.all(clients.map((client) => client.initialize()));
|
|
63
|
+
log('initialized');
|
|
64
|
+
|
|
65
|
+
await Promise.all(clients.map((client) => client.halo.createProfile()));
|
|
66
|
+
log('identity created');
|
|
67
|
+
|
|
68
|
+
const space = await clients[0].echo.createSpace();
|
|
69
|
+
log('space created');
|
|
70
|
+
|
|
71
|
+
await Promise.all(
|
|
72
|
+
clients.slice(1).map(async (client) => {
|
|
73
|
+
const success1 = new Trigger<Invitation>();
|
|
74
|
+
const success2 = new Trigger<Invitation>();
|
|
75
|
+
|
|
76
|
+
const observable1 = await space.createInvitation({ type: Invitation.Type.INTERACTIVE_TESTING });
|
|
77
|
+
log('invitation created');
|
|
78
|
+
|
|
79
|
+
const observable2 = await client.echo.acceptInvitation(observable1.invitation!);
|
|
80
|
+
log('invitation accepted');
|
|
81
|
+
|
|
82
|
+
observable1.subscribe({
|
|
83
|
+
onSuccess: (invitation) => {
|
|
84
|
+
success1.wake(invitation);
|
|
85
|
+
log('invitation success1');
|
|
86
|
+
},
|
|
87
|
+
onError: (err) => raise(err)
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
observable2.subscribe({
|
|
91
|
+
onSuccess: (invitation: Invitation) => {
|
|
92
|
+
success2.wake(invitation);
|
|
93
|
+
log('invitation success2');
|
|
94
|
+
},
|
|
95
|
+
onError: (err: Error) => raise(err)
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await Promise.all([success1.wait(), success2.wait()]);
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
setSpaceKey(space.key);
|
|
103
|
+
|
|
104
|
+
return () => {
|
|
105
|
+
void Promise.all(clients.map((client) => client.destroy()));
|
|
106
|
+
};
|
|
107
|
+
}, clients);
|
|
108
|
+
|
|
109
|
+
if (!spaceKey) {
|
|
110
|
+
return <Loading label='Loading…' />;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div className='flex'>
|
|
115
|
+
{clients.map((client, index) => (
|
|
116
|
+
<ClientProvider key={index} client={client} fallback={<Loading label='Loading…' />}>
|
|
117
|
+
<Story args={{ spaceKey, id: index }} />
|
|
118
|
+
</ClientProvider>
|
|
119
|
+
))}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Item, PublicKey, Space } from '@dxos/client';
|
|
8
|
+
import { ObjectModel } from '@dxos/object-model';
|
|
9
|
+
import { useSelection, useSpace } from '@dxos/react-client';
|
|
10
|
+
import { Loading } from '@dxos/react-ui';
|
|
11
|
+
import { useTranslation } from '@dxos/react-uikit';
|
|
12
|
+
|
|
13
|
+
import { LIST_ITEM_TYPE } from '../../model';
|
|
14
|
+
import {
|
|
15
|
+
ListPrimitive,
|
|
16
|
+
ListAction,
|
|
17
|
+
ListItems,
|
|
18
|
+
isListItemChangedAction,
|
|
19
|
+
isListItemDeletedAction,
|
|
20
|
+
isListItemCreatedAction,
|
|
21
|
+
ListItemProps,
|
|
22
|
+
ListPrimitiveProps
|
|
23
|
+
} from '../ListPrimitive';
|
|
24
|
+
|
|
25
|
+
interface ListLoadedProps {
|
|
26
|
+
space: Space;
|
|
27
|
+
list: Item<ObjectModel>;
|
|
28
|
+
listItems: Item<ObjectModel>[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ListProps {
|
|
32
|
+
spaceKey: PublicKey;
|
|
33
|
+
itemId: Item<ObjectModel>['id'];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ListLoaded = ({ space, list, listItems: propsListItems }: ListLoadedProps) => {
|
|
37
|
+
const listItems = useSelection(list?.select().children().filter({ type: LIST_ITEM_TYPE })) ?? propsListItems;
|
|
38
|
+
|
|
39
|
+
const onAction = useCallback(
|
|
40
|
+
async (action: ListAction) => {
|
|
41
|
+
if (isListItemDeletedAction(action)) {
|
|
42
|
+
const subject = space.database.getItem(action.deleted.id);
|
|
43
|
+
// TODO(thure): use Echo’s native deletion
|
|
44
|
+
return subject?.model.set('annotations.deleted', true);
|
|
45
|
+
} else if (isListItemCreatedAction(action)) {
|
|
46
|
+
// do nothing?
|
|
47
|
+
} else if (isListItemChangedAction(action)) {
|
|
48
|
+
const subject = space.database.getItem(action.listItemId);
|
|
49
|
+
return Promise.all(
|
|
50
|
+
(Object.keys(action.next) as (keyof ListItemProps)[]).map((prop) => {
|
|
51
|
+
return subject?.model.set(prop, action.next[prop]);
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
} else {
|
|
55
|
+
return Promise.all(
|
|
56
|
+
(Object.keys(action.next) as (keyof ListPrimitiveProps)[]).map((prop) => {
|
|
57
|
+
return list?.model.set(prop, action.next[prop]);
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
[list, listItems]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const createListItemId = useCallback(async () => {
|
|
66
|
+
const listItem = await space?.database.createItem({
|
|
67
|
+
model: ObjectModel,
|
|
68
|
+
type: LIST_ITEM_TYPE,
|
|
69
|
+
parent: list.id
|
|
70
|
+
});
|
|
71
|
+
return listItem.id;
|
|
72
|
+
}, [space]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<ListPrimitive
|
|
76
|
+
{...{
|
|
77
|
+
id: list.id,
|
|
78
|
+
title: list.model.get('title') ?? '',
|
|
79
|
+
description: list.model.get('description') ?? '',
|
|
80
|
+
items: (listItems ?? [])
|
|
81
|
+
// TODO(thure): use Echo’s native deletion
|
|
82
|
+
.filter((item) => !item.model.get('annotations.deleted'))
|
|
83
|
+
.reduce((acc: ListItems, item) => {
|
|
84
|
+
acc[item.id] = {
|
|
85
|
+
title: item.model.get('title'),
|
|
86
|
+
description: item.model.get('description'),
|
|
87
|
+
annotations: item.model.get('annotations')
|
|
88
|
+
};
|
|
89
|
+
return acc;
|
|
90
|
+
}, {}),
|
|
91
|
+
onAction,
|
|
92
|
+
createListItemId
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const List = ({ spaceKey, itemId }: ListProps) => {
|
|
99
|
+
const { t } = useTranslation('uikit');
|
|
100
|
+
|
|
101
|
+
const space = useSpace(spaceKey);
|
|
102
|
+
const list = (useSelection(space?.database.select({ id: itemId })) ?? [])[0];
|
|
103
|
+
const listItems = useSelection(list?.select().children().filter({ type: LIST_ITEM_TYPE }));
|
|
104
|
+
|
|
105
|
+
// TODO(thure): this should become `Suspense` when the above hooks support it
|
|
106
|
+
return space && list && listItems ? (
|
|
107
|
+
<ListLoaded {...{ space, list, listItems }} />
|
|
108
|
+
) : (
|
|
109
|
+
<Loading label={t('generic loading label')} />
|
|
110
|
+
);
|
|
111
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxosTheme';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { templateForComponent } from '../../testing';
|
|
9
|
+
import { ListPrimitive, ListPrimitiveComponentProps } from './ListPrimitive';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'react-list/ListPrimitive',
|
|
13
|
+
component: ListPrimitive,
|
|
14
|
+
argTypes: {}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const Template = (args: Omit<ListPrimitiveComponentProps, 'item'>) => {
|
|
18
|
+
return (
|
|
19
|
+
<main className='max-is-lg mli-auto pli-7 mbs-7'>
|
|
20
|
+
<ListPrimitive {...args} />
|
|
21
|
+
</main>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Default = templateForComponent(Template)({ id: '', items: {} });
|
|
26
|
+
Default.args = {
|
|
27
|
+
id: 'x123456',
|
|
28
|
+
items: {
|
|
29
|
+
x234567: {
|
|
30
|
+
title: 'Apple'
|
|
31
|
+
},
|
|
32
|
+
x345678: {
|
|
33
|
+
title: 'Grapes',
|
|
34
|
+
annotations: { state: 'done' }
|
|
35
|
+
},
|
|
36
|
+
x456789: {
|
|
37
|
+
title: 'Banana'
|
|
38
|
+
},
|
|
39
|
+
x567890: {
|
|
40
|
+
title: 'Courgette'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|