@dxos/react-ui-stack 0.7.1 → 0.7.2-main.f1adc9f

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.
@@ -1,121 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { create, type ReactiveObject, S } from '@dxos/echo-schema';
6
- import { faker } from '@dxos/random';
7
-
8
- // TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/react-ui/testing.
9
-
10
- // TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).
11
-
12
- // TODO(burdon): Util.
13
- export const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>
14
- Array.from({ length })
15
- .map((_, i) => fn(i))
16
- .filter(Boolean) as T[];
17
-
18
- // TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?
19
- export type TestItem = { id: string; type: string } & Record<string, any>;
20
-
21
- type ObjectDataGenerator = {
22
- createSchema?: () => S.Schema<any>;
23
- createData: () => any;
24
- };
25
-
26
- type ObjectFactory<T extends ReactiveObject<any>> = {
27
- schema?: S.Schema<any>; // TODO(burdon): Support both typed and expando schema.
28
- createObject: () => T;
29
- };
30
-
31
- type ObjectFactoryMap = { [type: string]: ObjectFactory<any> };
32
-
33
- const createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {
34
- const schema = createSchema?.();
35
- return {
36
- schema,
37
- createObject: () => (schema ? create(schema, createData()) : create(createData())),
38
- };
39
- };
40
-
41
- // TODO(burdon): Handle restricted values.
42
- export const Status = ['pending', 'active', 'done'];
43
- export const Priority = [1, 2, 3, 4, 5];
44
-
45
- export const defaultGenerators: { [type: string]: ObjectDataGenerator } = {
46
- document: {
47
- createData: () => ({
48
- title: faker.lorem.sentence(3),
49
- body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
50
- }),
51
- },
52
-
53
- image: {
54
- createData: () => ({
55
- title: faker.lorem.sentence(3),
56
- image: faker.helpers.arrayElement(data.images),
57
- body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,
58
- }),
59
- },
60
-
61
- project: {
62
- createSchema: () =>
63
- S.Struct({
64
- title: S.String,
65
- repo: S.String,
66
- status: S.String,
67
- priority: S.Number,
68
- }),
69
- createData: () => ({
70
- title: faker.commerce.productName(),
71
- repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
72
- status: faker.helpers.arrayElement(Status),
73
- priority: faker.helpers.arrayElement(Priority),
74
- }),
75
- },
76
- };
77
-
78
- /**
79
- * Typed object generator.
80
- * @deprecated
81
- */
82
- // TODO(wittjosiah): Remove.
83
- export class TestObjectGenerator {
84
- public readonly factories: ObjectFactoryMap;
85
-
86
- constructor({ types, factories }: { types?: string[]; factories?: ObjectFactoryMap } = {}) {
87
- this.factories =
88
- factories ??
89
- (types ?? Object.keys(defaultGenerators)).reduce<ObjectFactoryMap>((acc, type) => {
90
- acc[type] = createFactory(defaultGenerators[type]);
91
- return acc;
92
- }, {});
93
- }
94
-
95
- get schema(): S.Schema<any>[] {
96
- return Object.values(this.factories).map((f) => f.schema!);
97
- }
98
-
99
- createObject({ types }: { types?: string[] } = {}) {
100
- const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));
101
- const factory = this.factories[type];
102
- return factory?.createObject();
103
- }
104
-
105
- createObjects({ types, length }: { types?: string[]; length: number }) {
106
- return range(() => this.createObject({ types }), length);
107
- }
108
- }
109
-
110
- // https://unsplash.com
111
- // TODO(burdon): Use https://picsum.photos?
112
- const data = {
113
- images: [
114
- '/images/image-1.png',
115
- '/images/image-2.png',
116
- '/images/image-3.png',
117
- '/images/image-4.png',
118
- '/images/image-5.png',
119
- '/images/image-6.png',
120
- ],
121
- };