dn-react-router-toolkit 0.8.0 → 0.9.0
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/api/index.js +13 -4
- package/dist/api/index.mjs +14 -5
- package/dist/api/item_api_handler.d.mts +4 -2
- package/dist/api/item_api_handler.d.ts +4 -2
- package/dist/api/item_api_handler.js +13 -4
- package/dist/api/item_api_handler.mjs +14 -5
- package/dist/crud/index.d.mts +0 -20
- package/dist/crud/index.d.ts +0 -20
- package/dist/crud/index.js +12 -8508
- package/dist/crud/index.mjs +0 -8516
- package/dist/post/index.js +67 -7705
- package/dist/post/index.mjs +54 -7717
- package/dist/post/post_form_page.js +67 -7705
- package/dist/post/post_form_page.mjs +54 -7717
- package/dist/table/index.d.mts +1 -3
- package/dist/table/index.d.ts +1 -3
- package/dist/table/index.js +83 -76
- package/dist/table/index.mjs +84 -74
- package/dist/table/load_table.d.mts +8 -2
- package/dist/table/load_table.d.ts +8 -2
- package/dist/table/load_table.js +23 -3
- package/dist/table/load_table.mjs +24 -3
- package/dist/table/loader.d.mts +3 -0
- package/dist/table/loader.d.ts +3 -0
- package/dist/table/loader.js +23 -3
- package/dist/table/loader.mjs +24 -3
- package/dist/table/repository.d.mts +6 -4
- package/dist/table/repository.d.ts +6 -4
- package/dist/table/repository.js +4 -0
- package/dist/table/repository.mjs +4 -0
- package/dist/table/table.d.mts +5 -2
- package/dist/table/table.d.ts +5 -2
- package/dist/table/table.js +38 -6
- package/dist/table/table.mjs +38 -6
- package/dist/table/table_form.d.mts +2 -2
- package/dist/table/table_form.d.ts +2 -2
- package/dist/table/table_form.js +52 -19
- package/dist/table/table_form.mjs +52 -19
- package/dist/table/use_table.d.mts +3 -3
- package/dist/table/use_table.d.ts +3 -3
- package/dist/table/use_table.js +1 -10
- package/dist/table/use_table.mjs +1 -10
- package/package.json +1 -1
- package/dist/crud/crud_loader.d.mts +0 -26
- package/dist/crud/crud_loader.d.ts +0 -26
- package/dist/crud/crud_loader.js +0 -322
- package/dist/crud/crud_loader.mjs +0 -307
- package/dist/crud/crud_page.d.mts +0 -32
- package/dist/crud/crud_page.d.ts +0 -32
- package/dist/crud/crud_page.js +0 -726
- package/dist/crud/crud_page.mjs +0 -708
- package/dist/crud/generate_handlers.d.mts +0 -16
- package/dist/crud/generate_handlers.d.ts +0 -16
- package/dist/crud/generate_handlers.js +0 -39
- package/dist/crud/generate_handlers.mjs +0 -14
- package/dist/crud/generate_pages.d.mts +0 -19
- package/dist/crud/generate_pages.d.ts +0 -19
- package/dist/crud/generate_pages.js +0 -55
- package/dist/crud/generate_pages.mjs +0 -30
- package/dist/crud/generate_routes.d.mts +0 -5
- package/dist/crud/generate_routes.d.ts +0 -5
- package/dist/crud/generate_routes.js +0 -7639
- package/dist/crud/generate_routes.mjs +0 -7627
- package/dist/table/item_loader.d.mts +0 -14
- package/dist/table/item_loader.d.ts +0 -14
- package/dist/table/item_loader.js +0 -43
- package/dist/table/item_loader.mjs +0 -18
- package/dist/table/page.d.mts +0 -16
- package/dist/table/page.d.ts +0 -16
- package/dist/table/page.js +0 -325
- package/dist/table/page.mjs +0 -300
package/dist/table/load_table.js
CHANGED
|
@@ -32,16 +32,27 @@ async function loadTable({
|
|
|
32
32
|
const searchParams = new URL(request.url).searchParams;
|
|
33
33
|
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
34
34
|
const query = searchParams.get("query") ?? void 0;
|
|
35
|
-
const limit = Number(searchParams.get("limit") ?? "
|
|
35
|
+
const limit = Number(searchParams.get("limit") ?? "10");
|
|
36
36
|
const offset = Number(searchParams.get("offset") ?? "0");
|
|
37
37
|
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
38
38
|
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
39
|
+
const filterWhere = Object.entries(options.filters ?? {}).map(([key, value]) => {
|
|
40
|
+
const param = searchParams.get(key);
|
|
41
|
+
if (param) {
|
|
42
|
+
return (0, import_drizzle_orm.eq)(
|
|
43
|
+
repository.schema[key],
|
|
44
|
+
decodeURIComponent(param)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}).filter(Boolean);
|
|
39
49
|
const whereClauses = (0, import_drizzle_orm.and)(
|
|
40
50
|
searchKey && query ? (0, import_drizzle_orm.ilike)(
|
|
41
51
|
repository.schema[searchKey],
|
|
42
52
|
`%${query}%`
|
|
43
53
|
) : void 0,
|
|
44
|
-
...
|
|
54
|
+
...filterWhere,
|
|
55
|
+
where
|
|
45
56
|
);
|
|
46
57
|
const total = await repository.countTotal({ where: whereClauses });
|
|
47
58
|
const items = await repository.findAll({
|
|
@@ -51,6 +62,14 @@ async function loadTable({
|
|
|
51
62
|
offset,
|
|
52
63
|
where: whereClauses
|
|
53
64
|
});
|
|
65
|
+
const filters = Object.fromEntries(
|
|
66
|
+
await Promise.all(
|
|
67
|
+
Object.keys(options.filters ?? {}).map(async (key) => {
|
|
68
|
+
const values = await repository.select(key);
|
|
69
|
+
return [key, values.filter(Boolean)];
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
);
|
|
54
73
|
return {
|
|
55
74
|
items,
|
|
56
75
|
total,
|
|
@@ -58,7 +77,8 @@ async function loadTable({
|
|
|
58
77
|
offset,
|
|
59
78
|
orderBy,
|
|
60
79
|
direction,
|
|
61
|
-
searchKey
|
|
80
|
+
searchKey,
|
|
81
|
+
filters
|
|
62
82
|
};
|
|
63
83
|
}
|
|
64
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/table/load_table.tsx
|
|
2
2
|
import {
|
|
3
3
|
and,
|
|
4
|
+
eq,
|
|
4
5
|
ilike
|
|
5
6
|
} from "drizzle-orm";
|
|
6
7
|
async function loadTable({
|
|
@@ -11,16 +12,27 @@ async function loadTable({
|
|
|
11
12
|
const searchParams = new URL(request.url).searchParams;
|
|
12
13
|
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
13
14
|
const query = searchParams.get("query") ?? void 0;
|
|
14
|
-
const limit = Number(searchParams.get("limit") ?? "
|
|
15
|
+
const limit = Number(searchParams.get("limit") ?? "10");
|
|
15
16
|
const offset = Number(searchParams.get("offset") ?? "0");
|
|
16
17
|
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
17
18
|
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
19
|
+
const filterWhere = Object.entries(options.filters ?? {}).map(([key, value]) => {
|
|
20
|
+
const param = searchParams.get(key);
|
|
21
|
+
if (param) {
|
|
22
|
+
return eq(
|
|
23
|
+
repository.schema[key],
|
|
24
|
+
decodeURIComponent(param)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}).filter(Boolean);
|
|
18
29
|
const whereClauses = and(
|
|
19
30
|
searchKey && query ? ilike(
|
|
20
31
|
repository.schema[searchKey],
|
|
21
32
|
`%${query}%`
|
|
22
33
|
) : void 0,
|
|
23
|
-
...
|
|
34
|
+
...filterWhere,
|
|
35
|
+
where
|
|
24
36
|
);
|
|
25
37
|
const total = await repository.countTotal({ where: whereClauses });
|
|
26
38
|
const items = await repository.findAll({
|
|
@@ -30,6 +42,14 @@ async function loadTable({
|
|
|
30
42
|
offset,
|
|
31
43
|
where: whereClauses
|
|
32
44
|
});
|
|
45
|
+
const filters = Object.fromEntries(
|
|
46
|
+
await Promise.all(
|
|
47
|
+
Object.keys(options.filters ?? {}).map(async (key) => {
|
|
48
|
+
const values = await repository.select(key);
|
|
49
|
+
return [key, values.filter(Boolean)];
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
);
|
|
33
53
|
return {
|
|
34
54
|
items,
|
|
35
55
|
total,
|
|
@@ -37,7 +57,8 @@ async function loadTable({
|
|
|
37
57
|
offset,
|
|
38
58
|
orderBy,
|
|
39
59
|
direction,
|
|
40
|
-
searchKey
|
|
60
|
+
searchKey,
|
|
61
|
+
filters
|
|
41
62
|
};
|
|
42
63
|
}
|
|
43
64
|
export {
|
package/dist/table/loader.d.mts
CHANGED
|
@@ -14,6 +14,9 @@ declare function tableLoader<T extends PgTableWithColumns<any>, TSelect>({ repos
|
|
|
14
14
|
orderBy: keyof T["_"]["columns"] & string;
|
|
15
15
|
direction: "asc" | "desc";
|
|
16
16
|
searchKey: ColumnOf<T> | undefined;
|
|
17
|
+
filters: {
|
|
18
|
+
[k: string]: unknown[];
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
}>;
|
|
19
22
|
|
package/dist/table/loader.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ declare function tableLoader<T extends PgTableWithColumns<any>, TSelect>({ repos
|
|
|
14
14
|
orderBy: keyof T["_"]["columns"] & string;
|
|
15
15
|
direction: "asc" | "desc";
|
|
16
16
|
searchKey: ColumnOf<T> | undefined;
|
|
17
|
+
filters: {
|
|
18
|
+
[k: string]: unknown[];
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
}>;
|
|
19
22
|
|
package/dist/table/loader.js
CHANGED
|
@@ -34,16 +34,27 @@ async function loadTable({
|
|
|
34
34
|
const searchParams = new URL(request.url).searchParams;
|
|
35
35
|
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
36
36
|
const query = searchParams.get("query") ?? void 0;
|
|
37
|
-
const limit = Number(searchParams.get("limit") ?? "
|
|
37
|
+
const limit = Number(searchParams.get("limit") ?? "10");
|
|
38
38
|
const offset = Number(searchParams.get("offset") ?? "0");
|
|
39
39
|
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
40
40
|
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
41
|
+
const filterWhere = Object.entries(options.filters ?? {}).map(([key, value]) => {
|
|
42
|
+
const param = searchParams.get(key);
|
|
43
|
+
if (param) {
|
|
44
|
+
return (0, import_drizzle_orm.eq)(
|
|
45
|
+
repository.schema[key],
|
|
46
|
+
decodeURIComponent(param)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return void 0;
|
|
50
|
+
}).filter(Boolean);
|
|
41
51
|
const whereClauses = (0, import_drizzle_orm.and)(
|
|
42
52
|
searchKey && query ? (0, import_drizzle_orm.ilike)(
|
|
43
53
|
repository.schema[searchKey],
|
|
44
54
|
`%${query}%`
|
|
45
55
|
) : void 0,
|
|
46
|
-
...
|
|
56
|
+
...filterWhere,
|
|
57
|
+
where
|
|
47
58
|
);
|
|
48
59
|
const total = await repository.countTotal({ where: whereClauses });
|
|
49
60
|
const items = await repository.findAll({
|
|
@@ -53,6 +64,14 @@ async function loadTable({
|
|
|
53
64
|
offset,
|
|
54
65
|
where: whereClauses
|
|
55
66
|
});
|
|
67
|
+
const filters = Object.fromEntries(
|
|
68
|
+
await Promise.all(
|
|
69
|
+
Object.keys(options.filters ?? {}).map(async (key) => {
|
|
70
|
+
const values = await repository.select(key);
|
|
71
|
+
return [key, values.filter(Boolean)];
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
);
|
|
56
75
|
return {
|
|
57
76
|
items,
|
|
58
77
|
total,
|
|
@@ -60,7 +79,8 @@ async function loadTable({
|
|
|
60
79
|
offset,
|
|
61
80
|
orderBy,
|
|
62
81
|
direction,
|
|
63
|
-
searchKey
|
|
82
|
+
searchKey,
|
|
83
|
+
filters
|
|
64
84
|
};
|
|
65
85
|
}
|
|
66
86
|
|
package/dist/table/loader.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/table/load_table.tsx
|
|
2
2
|
import {
|
|
3
3
|
and,
|
|
4
|
+
eq,
|
|
4
5
|
ilike
|
|
5
6
|
} from "drizzle-orm";
|
|
6
7
|
async function loadTable({
|
|
@@ -11,16 +12,27 @@ async function loadTable({
|
|
|
11
12
|
const searchParams = new URL(request.url).searchParams;
|
|
12
13
|
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
13
14
|
const query = searchParams.get("query") ?? void 0;
|
|
14
|
-
const limit = Number(searchParams.get("limit") ?? "
|
|
15
|
+
const limit = Number(searchParams.get("limit") ?? "10");
|
|
15
16
|
const offset = Number(searchParams.get("offset") ?? "0");
|
|
16
17
|
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
17
18
|
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
19
|
+
const filterWhere = Object.entries(options.filters ?? {}).map(([key, value]) => {
|
|
20
|
+
const param = searchParams.get(key);
|
|
21
|
+
if (param) {
|
|
22
|
+
return eq(
|
|
23
|
+
repository.schema[key],
|
|
24
|
+
decodeURIComponent(param)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}).filter(Boolean);
|
|
18
29
|
const whereClauses = and(
|
|
19
30
|
searchKey && query ? ilike(
|
|
20
31
|
repository.schema[searchKey],
|
|
21
32
|
`%${query}%`
|
|
22
33
|
) : void 0,
|
|
23
|
-
...
|
|
34
|
+
...filterWhere,
|
|
35
|
+
where
|
|
24
36
|
);
|
|
25
37
|
const total = await repository.countTotal({ where: whereClauses });
|
|
26
38
|
const items = await repository.findAll({
|
|
@@ -30,6 +42,14 @@ async function loadTable({
|
|
|
30
42
|
offset,
|
|
31
43
|
where: whereClauses
|
|
32
44
|
});
|
|
45
|
+
const filters = Object.fromEntries(
|
|
46
|
+
await Promise.all(
|
|
47
|
+
Object.keys(options.filters ?? {}).map(async (key) => {
|
|
48
|
+
const values = await repository.select(key);
|
|
49
|
+
return [key, values.filter(Boolean)];
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
);
|
|
33
53
|
return {
|
|
34
54
|
items,
|
|
35
55
|
total,
|
|
@@ -37,7 +57,8 @@ async function loadTable({
|
|
|
37
57
|
offset,
|
|
38
58
|
orderBy,
|
|
39
59
|
direction,
|
|
40
|
-
searchKey
|
|
60
|
+
searchKey,
|
|
61
|
+
filters
|
|
41
62
|
};
|
|
42
63
|
}
|
|
43
64
|
|
|
@@ -21,20 +21,22 @@ interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSele
|
|
|
21
21
|
findAll: (options: FindAllOptions<T>) => Promise<TSelect[]>;
|
|
22
22
|
save: (values: InferInsertModel<T>) => Promise<TSelect>;
|
|
23
23
|
delete: (id: string) => Promise<void>;
|
|
24
|
+
select(key: keyof InferSelectModel<T>): Promise<InferSelectModel<T>[typeof key][]>;
|
|
24
25
|
}
|
|
25
26
|
type SchemaOf<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"]> = TDatabase["_"]["fullSchema"][TSchemaKey];
|
|
26
|
-
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"],
|
|
27
|
+
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey>> {
|
|
27
28
|
db: TDatabase;
|
|
28
29
|
schema: SchemaOf<TDatabase, TSchemaKey>;
|
|
29
30
|
pk: TPrimaryKey;
|
|
30
31
|
constructor(db: TDatabase, schema: TSchemaKey, pk?: TPrimaryKey);
|
|
31
|
-
find(id: string): Promise<
|
|
32
|
+
find(id: string): Promise<TSelect | undefined>;
|
|
32
33
|
countTotal({ where }: {
|
|
33
34
|
where?: SQL<unknown>;
|
|
34
35
|
}): Promise<number>;
|
|
35
|
-
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<
|
|
36
|
-
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<
|
|
36
|
+
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect[]>;
|
|
37
|
+
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect>;
|
|
37
38
|
delete(pk: string): Promise<void>;
|
|
39
|
+
select(key: keyof InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>[typeof key][]>;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export { BaseTableRepository, type ColumnOf, type FindAllOptions, type InsertModelOf, type SchemaOf, type SelectModelOf, type TableRepository };
|
|
@@ -21,20 +21,22 @@ interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSele
|
|
|
21
21
|
findAll: (options: FindAllOptions<T>) => Promise<TSelect[]>;
|
|
22
22
|
save: (values: InferInsertModel<T>) => Promise<TSelect>;
|
|
23
23
|
delete: (id: string) => Promise<void>;
|
|
24
|
+
select(key: keyof InferSelectModel<T>): Promise<InferSelectModel<T>[typeof key][]>;
|
|
24
25
|
}
|
|
25
26
|
type SchemaOf<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"]> = TDatabase["_"]["fullSchema"][TSchemaKey];
|
|
26
|
-
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"],
|
|
27
|
+
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey>> {
|
|
27
28
|
db: TDatabase;
|
|
28
29
|
schema: SchemaOf<TDatabase, TSchemaKey>;
|
|
29
30
|
pk: TPrimaryKey;
|
|
30
31
|
constructor(db: TDatabase, schema: TSchemaKey, pk?: TPrimaryKey);
|
|
31
|
-
find(id: string): Promise<
|
|
32
|
+
find(id: string): Promise<TSelect | undefined>;
|
|
32
33
|
countTotal({ where }: {
|
|
33
34
|
where?: SQL<unknown>;
|
|
34
35
|
}): Promise<number>;
|
|
35
|
-
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<
|
|
36
|
-
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<
|
|
36
|
+
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect[]>;
|
|
37
|
+
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect>;
|
|
37
38
|
delete(pk: string): Promise<void>;
|
|
39
|
+
select(key: keyof InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>[typeof key][]>;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export { BaseTableRepository, type ColumnOf, type FindAllOptions, type InsertModelOf, type SchemaOf, type SelectModelOf, type TableRepository };
|
package/dist/table/repository.js
CHANGED
|
@@ -69,6 +69,10 @@ var BaseTableRepository = class {
|
|
|
69
69
|
async delete(pk) {
|
|
70
70
|
await this.db.delete(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk));
|
|
71
71
|
}
|
|
72
|
+
async select(key) {
|
|
73
|
+
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
74
|
+
return rows.map((row) => row.value);
|
|
75
|
+
}
|
|
72
76
|
};
|
|
73
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
78
|
0 && (module.exports = {
|
|
@@ -50,6 +50,10 @@ var BaseTableRepository = class {
|
|
|
50
50
|
async delete(pk) {
|
|
51
51
|
await this.db.delete(this.schema).where(eq(this.schema[this.pk], pk));
|
|
52
52
|
}
|
|
53
|
+
async select(key) {
|
|
54
|
+
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
55
|
+
return rows.map((row) => row.value);
|
|
56
|
+
}
|
|
53
57
|
};
|
|
54
58
|
export {
|
|
55
59
|
BaseTableRepository
|
package/dist/table/table.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { DetailedHTMLProps, TableHTMLAttributes, ReactNode, FC } from 'react';
|
|
3
3
|
|
|
4
4
|
type TableColumnProps<T> = ReactNode | {
|
|
5
5
|
label: ReactNode;
|
|
@@ -22,7 +22,10 @@ type OrderedTableProps<T> = DetailedHTMLProps<TableHTMLAttributes<HTMLTableEleme
|
|
|
22
22
|
offset?: number;
|
|
23
23
|
orderBy?: string;
|
|
24
24
|
direction?: string;
|
|
25
|
+
filters?: {
|
|
26
|
+
[key: string]: unknown[];
|
|
27
|
+
};
|
|
25
28
|
};
|
|
26
|
-
declare function Table<T>({ className, data, columns, mapper: Mapper, getLink, limit, offset, orderBy, direction, }: OrderedTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
29
|
+
declare function Table<T>({ className, data, columns, mapper: Mapper, getLink, limit, offset, orderBy, direction, filters, }: OrderedTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
27
30
|
|
|
28
31
|
export { type OrderedTableProps, Table, type TableColumnOptions, type TableColumnProps };
|
package/dist/table/table.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { DetailedHTMLProps, TableHTMLAttributes, ReactNode, FC } from 'react';
|
|
3
3
|
|
|
4
4
|
type TableColumnProps<T> = ReactNode | {
|
|
5
5
|
label: ReactNode;
|
|
@@ -22,7 +22,10 @@ type OrderedTableProps<T> = DetailedHTMLProps<TableHTMLAttributes<HTMLTableEleme
|
|
|
22
22
|
offset?: number;
|
|
23
23
|
orderBy?: string;
|
|
24
24
|
direction?: string;
|
|
25
|
+
filters?: {
|
|
26
|
+
[key: string]: unknown[];
|
|
27
|
+
};
|
|
25
28
|
};
|
|
26
|
-
declare function Table<T>({ className, data, columns, mapper: Mapper, getLink, limit, offset, orderBy, direction, }: OrderedTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
29
|
+
declare function Table<T>({ className, data, columns, mapper: Mapper, getLink, limit, offset, orderBy, direction, filters, }: OrderedTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
27
30
|
|
|
28
31
|
export { type OrderedTableProps, Table, type TableColumnOptions, type TableColumnProps };
|
package/dist/table/table.js
CHANGED
|
@@ -36,7 +36,8 @@ function Table({
|
|
|
36
36
|
limit,
|
|
37
37
|
offset,
|
|
38
38
|
orderBy,
|
|
39
|
-
direction
|
|
39
|
+
direction,
|
|
40
|
+
filters
|
|
40
41
|
}) {
|
|
41
42
|
const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
|
|
42
43
|
const sortedArray = [...data];
|
|
@@ -61,8 +62,8 @@ function Table({
|
|
|
61
62
|
"button",
|
|
62
63
|
{
|
|
63
64
|
className: (0, import_utils.cn)(
|
|
64
|
-
orderBy === key ? "text-
|
|
65
|
-
"px-4
|
|
65
|
+
orderBy === key ? "text-gray-900 font-medium" : "text-gray-500 font-medium",
|
|
66
|
+
"px-4 flex items-center w-full"
|
|
66
67
|
),
|
|
67
68
|
onClick: () => {
|
|
68
69
|
let newDirection = "asc";
|
|
@@ -83,14 +84,45 @@ function Table({
|
|
|
83
84
|
}
|
|
84
85
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: reactNode });
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
+
const filter = filters?.[key];
|
|
88
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
89
|
+
"th",
|
|
90
|
+
{
|
|
91
|
+
className: (0, import_utils.cn)("py-4 border-y font-normal align-top"),
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Head, {}),
|
|
94
|
+
filter && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-3 mt-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
95
|
+
"select",
|
|
96
|
+
{
|
|
97
|
+
className: "w-full h-10 px-1.5 border rounded-full outline-none",
|
|
98
|
+
onChange: (e) => {
|
|
99
|
+
const value2 = e.target.value;
|
|
100
|
+
setSearchParams((prev) => {
|
|
101
|
+
if (value2) {
|
|
102
|
+
prev.set(key, encodeURIComponent(value2));
|
|
103
|
+
} else {
|
|
104
|
+
prev.delete(key);
|
|
105
|
+
}
|
|
106
|
+
return prev;
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
children: [
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "\uC804\uCCB4" }),
|
|
111
|
+
filter.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: option, children: option }, option))
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
) })
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
key
|
|
118
|
+
);
|
|
87
119
|
}) }) }),
|
|
88
120
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tbody", { children: [
|
|
89
121
|
sortedArray.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
90
122
|
"td",
|
|
91
123
|
{
|
|
92
124
|
colSpan: keys.length,
|
|
93
|
-
className: "px-4 h-
|
|
125
|
+
className: "px-4 h-20 text-gray-400 text-center",
|
|
94
126
|
children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
95
127
|
}
|
|
96
128
|
) }),
|
|
@@ -115,7 +147,7 @@ function Table({
|
|
|
115
147
|
className: "block content-center px-4 w-full h-full",
|
|
116
148
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {})
|
|
117
149
|
}
|
|
118
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {});
|
|
150
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {}) });
|
|
119
151
|
const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
|
|
120
152
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
|
|
121
153
|
}) }, i))
|
package/dist/table/table.mjs
CHANGED
|
@@ -12,7 +12,8 @@ function Table({
|
|
|
12
12
|
limit,
|
|
13
13
|
offset,
|
|
14
14
|
orderBy,
|
|
15
|
-
direction
|
|
15
|
+
direction,
|
|
16
|
+
filters
|
|
16
17
|
}) {
|
|
17
18
|
const keys = Object.entries(columns).filter((entry) => entry[1]).map(([key]) => key);
|
|
18
19
|
const sortedArray = [...data];
|
|
@@ -37,8 +38,8 @@ function Table({
|
|
|
37
38
|
"button",
|
|
38
39
|
{
|
|
39
40
|
className: cn(
|
|
40
|
-
orderBy === key ? "text-
|
|
41
|
-
"px-4
|
|
41
|
+
orderBy === key ? "text-gray-900 font-medium" : "text-gray-500 font-medium",
|
|
42
|
+
"px-4 flex items-center w-full"
|
|
42
43
|
),
|
|
43
44
|
onClick: () => {
|
|
44
45
|
let newDirection = "asc";
|
|
@@ -59,14 +60,45 @@ function Table({
|
|
|
59
60
|
}
|
|
60
61
|
return /* @__PURE__ */ jsx(Fragment, { children: reactNode });
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
const filter = filters?.[key];
|
|
64
|
+
return /* @__PURE__ */ jsxs(
|
|
65
|
+
"th",
|
|
66
|
+
{
|
|
67
|
+
className: cn("py-4 border-y font-normal align-top"),
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsx(Head, {}),
|
|
70
|
+
filter && /* @__PURE__ */ jsx("div", { className: "px-3 mt-4", children: /* @__PURE__ */ jsxs(
|
|
71
|
+
"select",
|
|
72
|
+
{
|
|
73
|
+
className: "w-full h-10 px-1.5 border rounded-full outline-none",
|
|
74
|
+
onChange: (e) => {
|
|
75
|
+
const value2 = e.target.value;
|
|
76
|
+
setSearchParams((prev) => {
|
|
77
|
+
if (value2) {
|
|
78
|
+
prev.set(key, encodeURIComponent(value2));
|
|
79
|
+
} else {
|
|
80
|
+
prev.delete(key);
|
|
81
|
+
}
|
|
82
|
+
return prev;
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "\uC804\uCCB4" }),
|
|
87
|
+
filter.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: option }, option))
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
) })
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
key
|
|
94
|
+
);
|
|
63
95
|
}) }) }),
|
|
64
96
|
/* @__PURE__ */ jsxs("tbody", { children: [
|
|
65
97
|
sortedArray.length === 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
|
|
66
98
|
"td",
|
|
67
99
|
{
|
|
68
100
|
colSpan: keys.length,
|
|
69
|
-
className: "px-4 h-
|
|
101
|
+
className: "px-4 h-20 text-gray-400 text-center",
|
|
70
102
|
children: "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
71
103
|
}
|
|
72
104
|
) }),
|
|
@@ -91,7 +123,7 @@ function Table({
|
|
|
91
123
|
className: "block content-center px-4 w-full h-full",
|
|
92
124
|
children: /* @__PURE__ */ jsx(Content, {})
|
|
93
125
|
}
|
|
94
|
-
) : /* @__PURE__ */ jsx(Content, {});
|
|
126
|
+
) : /* @__PURE__ */ jsx("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ jsx(Content, {}) });
|
|
95
127
|
const cell = Mapper ? /* @__PURE__ */ jsx(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
|
|
96
128
|
return /* @__PURE__ */ jsx("td", { className: "px-0 h-14 border-b", children: cell }, key);
|
|
97
129
|
}) }, i))
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { TableColumnOptions } from './table.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { TableLoaderData } from './use_table.mjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
type TablePageOptions<TModel> = {
|
|
7
7
|
columns: TableColumnOptions<TModel>;
|
|
8
8
|
primaryKey?: keyof TModel;
|
|
9
9
|
};
|
|
10
|
-
type LoadedModel<T extends (...args: any) => any> =
|
|
10
|
+
type LoadedModel<T extends (...args: any) => any> = TableLoaderData<T>["items"][number];
|
|
11
11
|
declare function TableForm<T extends (...args: any) => any>({ columns, primaryKey, }: TablePageOptions<LoadedModel<T>>): react_jsx_runtime.JSX.Element;
|
|
12
12
|
|
|
13
13
|
export { type LoadedModel, TableForm, type TablePageOptions };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { TableColumnOptions } from './table.js';
|
|
3
|
-
import {
|
|
3
|
+
import { TableLoaderData } from './use_table.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
type TablePageOptions<TModel> = {
|
|
7
7
|
columns: TableColumnOptions<TModel>;
|
|
8
8
|
primaryKey?: keyof TModel;
|
|
9
9
|
};
|
|
10
|
-
type LoadedModel<T extends (...args: any) => any> =
|
|
10
|
+
type LoadedModel<T extends (...args: any) => any> = TableLoaderData<T>["items"][number];
|
|
11
11
|
declare function TableForm<T extends (...args: any) => any>({ columns, primaryKey, }: TablePageOptions<LoadedModel<T>>): react_jsx_runtime.JSX.Element;
|
|
12
12
|
|
|
13
13
|
export { type LoadedModel, TableForm, type TablePageOptions };
|