@nestjs-dash/core 0.0.1 → 0.1.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/LICENSE +21 -0
- package/README.md +23 -23
- package/dist/actions/handlers.d.ts +1 -1
- package/dist/actions/index.d.ts +25 -25
- package/dist/actions/index.js +93 -93
- package/dist/charts/index.d.ts +6 -6
- package/dist/charts/index.js +15 -15
- package/dist/forms/index.d.ts +24 -24
- package/dist/forms/index.js +76 -76
- package/dist/forms/json-fields.d.ts +1 -1
- package/dist/forms/json-fields.js +15 -15
- package/dist/forms/validation.d.ts +2 -2
- package/dist/forms/validation.js +2 -2
- package/dist/index.d.ts +29 -29
- package/dist/index.js +51 -51
- package/dist/schemas/index.d.ts +10 -10
- package/dist/schemas/index.js +22 -22
- package/dist/tables/index.d.ts +12 -12
- package/dist/tables/index.js +15 -15
- package/dist/tables/list-query-config.d.ts +3 -3
- package/dist/tables/list-query-config.js +4 -4
- package/package.json +21 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsonTextareaFieldKey } from
|
|
2
|
-
const JSON_ARRAY_FIELD_KINDS = new Set([
|
|
1
|
+
import { jsonTextareaFieldKey } from "@nestjs-dash/support";
|
|
2
|
+
const JSON_ARRAY_FIELD_KINDS = new Set(["tags-input", "repeater"]);
|
|
3
3
|
export function collectJsonArrayFields(node) {
|
|
4
4
|
if (!node)
|
|
5
5
|
return [];
|
|
@@ -15,7 +15,7 @@ export function collectJsonArrayFields(node) {
|
|
|
15
15
|
function parseJsonArray(raw) {
|
|
16
16
|
if (Array.isArray(raw))
|
|
17
17
|
return raw;
|
|
18
|
-
if (typeof raw !==
|
|
18
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
19
19
|
return [];
|
|
20
20
|
try {
|
|
21
21
|
const parsed = JSON.parse(raw);
|
|
@@ -31,14 +31,14 @@ export function parseJsonArrayFields(body, form) {
|
|
|
31
31
|
return body;
|
|
32
32
|
const payload = { ...body };
|
|
33
33
|
for (const field of fields) {
|
|
34
|
-
const name = String(field.name ?? field.props.name ??
|
|
34
|
+
const name = String(field.name ?? field.props.name ?? "");
|
|
35
35
|
if (!name || !(name in payload))
|
|
36
36
|
continue;
|
|
37
37
|
payload[name] = parseJsonArray(payload[name]);
|
|
38
38
|
}
|
|
39
39
|
return payload;
|
|
40
40
|
}
|
|
41
|
-
const JSON_PROJECTABLE_FIELD_KINDS = new Set([
|
|
41
|
+
const JSON_PROJECTABLE_FIELD_KINDS = new Set(["textarea", "rich-box"]);
|
|
42
42
|
export function collectJsonTextareaFields(node) {
|
|
43
43
|
if (!node)
|
|
44
44
|
return [];
|
|
@@ -52,14 +52,14 @@ export function collectJsonTextareaFields(node) {
|
|
|
52
52
|
return out;
|
|
53
53
|
}
|
|
54
54
|
function isPlainObject(value) {
|
|
55
|
-
return typeof value ===
|
|
55
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56
56
|
}
|
|
57
57
|
function parseJsonValue(raw) {
|
|
58
58
|
if (raw == null)
|
|
59
59
|
return null;
|
|
60
|
-
if (typeof raw !==
|
|
60
|
+
if (typeof raw !== "string")
|
|
61
61
|
return raw;
|
|
62
|
-
if (raw.trim() ===
|
|
62
|
+
if (raw.trim() === "")
|
|
63
63
|
return null;
|
|
64
64
|
try {
|
|
65
65
|
return JSON.parse(raw);
|
|
@@ -75,10 +75,10 @@ export function parseJsonTextareaFields(body, form, existingRecord) {
|
|
|
75
75
|
const payload = { ...body };
|
|
76
76
|
const merged = new Map();
|
|
77
77
|
for (const field of fields) {
|
|
78
|
-
const name = String(field.name ?? field.props.name ??
|
|
78
|
+
const name = String(field.name ?? field.props.name ?? "");
|
|
79
79
|
if (!name)
|
|
80
80
|
continue;
|
|
81
|
-
const property = typeof field.props.jsonProperty ===
|
|
81
|
+
const property = typeof field.props.jsonProperty === "string" ? field.props.jsonProperty : undefined;
|
|
82
82
|
const inputKey = jsonTextareaFieldKey(name, property);
|
|
83
83
|
if (!(inputKey in payload))
|
|
84
84
|
continue;
|
|
@@ -105,18 +105,18 @@ export function stringifyJsonTextareaFields(values, form) {
|
|
|
105
105
|
return values;
|
|
106
106
|
const result = { ...values };
|
|
107
107
|
for (const field of fields) {
|
|
108
|
-
const name = String(field.name ?? field.props.name ??
|
|
108
|
+
const name = String(field.name ?? field.props.name ?? "");
|
|
109
109
|
if (!name || !(name in values))
|
|
110
110
|
continue;
|
|
111
|
-
const property = typeof field.props.jsonProperty ===
|
|
111
|
+
const property = typeof field.props.jsonProperty === "string" ? field.props.jsonProperty : undefined;
|
|
112
112
|
const original = values[name];
|
|
113
113
|
if (property) {
|
|
114
114
|
const source = isPlainObject(original) ? original[property] : undefined;
|
|
115
115
|
result[jsonTextareaFieldKey(name, property)] =
|
|
116
|
-
source == null ?
|
|
116
|
+
source == null ? "" : typeof source === "string" ? source : JSON.stringify(source);
|
|
117
117
|
}
|
|
118
|
-
else if (typeof original !==
|
|
119
|
-
result[name] = original == null ?
|
|
118
|
+
else if (typeof original !== "string") {
|
|
119
|
+
result[name] = original == null ? "" : JSON.stringify(original, null, 2);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
return result;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SchemaNode } from
|
|
2
|
-
import type { ZodType } from
|
|
1
|
+
import type { SchemaNode } from "@nestjs-dash/support";
|
|
2
|
+
import type { ZodType } from "zod";
|
|
3
3
|
export declare function registerFieldValidation(schema: ZodType): string;
|
|
4
4
|
export declare function resolveFieldValidation(key: string): ZodType | undefined;
|
|
5
5
|
export declare function collectFieldValidations(node: SchemaNode | undefined | null): Array<{
|
package/dist/forms/validation.js
CHANGED
|
@@ -14,9 +14,9 @@ export function collectFieldValidations(node) {
|
|
|
14
14
|
return [];
|
|
15
15
|
const out = [];
|
|
16
16
|
const key = node.props.validationKey;
|
|
17
|
-
if (typeof key ===
|
|
17
|
+
if (typeof key === "string") {
|
|
18
18
|
const schema = resolveFieldValidation(key);
|
|
19
|
-
const name = String(node.name ?? node.props.name ??
|
|
19
|
+
const name = String(node.name ?? node.props.name ?? "");
|
|
20
20
|
if (schema && name) {
|
|
21
21
|
out.push({ name, schema });
|
|
22
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { type DatabaseAdapter, type ListQueryConfig, type RecordData, type RelationDefinition, type RelationType, type ResourceAdapter } from
|
|
2
|
-
import type { ChartSpec, SchemaNode } from
|
|
3
|
-
import { Schema } from
|
|
4
|
-
import { Table, type TableSchema } from
|
|
5
|
-
import type { PanelThemeColors, PanelThemeOverrides } from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export type ResourceApiMethod =
|
|
1
|
+
import { type DatabaseAdapter, type ListQueryConfig, type RecordData, type RelationDefinition, type RelationType, type ResourceAdapter } from "@nestjs-dash/adapter";
|
|
2
|
+
import type { ChartSpec, SchemaNode } from "@nestjs-dash/support";
|
|
3
|
+
import { Schema } from "./schemas/index.js";
|
|
4
|
+
import { Table, type TableSchema } from "./tables/index.js";
|
|
5
|
+
import type { PanelThemeColors, PanelThemeOverrides } from "./theme/index.js";
|
|
6
|
+
export * from "@nestjs-dash/adapter";
|
|
7
|
+
export * from "./actions/index.js";
|
|
8
|
+
export * from "./charts/index.js";
|
|
9
|
+
export * from "./forms/index.js";
|
|
10
|
+
export * from "./schemas/index.js";
|
|
11
|
+
export * from "./tables/index.js";
|
|
12
|
+
export * from "./theme/index.js";
|
|
13
|
+
export * from "@nestjs-dash/support";
|
|
14
|
+
export type ResourceApiMethod = "list" | "get" | "create" | "update" | "delete";
|
|
15
15
|
export interface ResourceApiFieldConfig {
|
|
16
|
-
create?: string[] |
|
|
17
|
-
update?: string[] |
|
|
18
|
-
response?: string[] |
|
|
16
|
+
create?: string[] | "*";
|
|
17
|
+
update?: string[] | "*";
|
|
18
|
+
response?: string[] | "*";
|
|
19
19
|
}
|
|
20
20
|
export interface ResourceApiConfig {
|
|
21
21
|
enabled?: boolean;
|
|
@@ -106,16 +106,16 @@ export type ResourcePanelClass = {
|
|
|
106
106
|
new (...args: never[]): ResourcePanelInstance;
|
|
107
107
|
};
|
|
108
108
|
export interface DashboardWidget {
|
|
109
|
-
slot?:
|
|
109
|
+
slot?: "main" | "side";
|
|
110
110
|
render?(ctx: PageRenderContext): string | Promise<string>;
|
|
111
111
|
chart?(ctx: PageRenderContext): ChartSpec | Promise<ChartSpec>;
|
|
112
112
|
canAccess?(ctx: AdminPolicyContext): boolean | Promise<boolean>;
|
|
113
113
|
}
|
|
114
114
|
export type DashboardWidgetPayload = {
|
|
115
|
-
type:
|
|
115
|
+
type: "html";
|
|
116
116
|
html: string;
|
|
117
117
|
} | {
|
|
118
|
-
type:
|
|
118
|
+
type: "chart";
|
|
119
119
|
chart: ChartSpec;
|
|
120
120
|
};
|
|
121
121
|
export type DashboardWidgets = {
|
|
@@ -132,7 +132,7 @@ export interface AdminPolicyContext {
|
|
|
132
132
|
request: unknown;
|
|
133
133
|
action?: string;
|
|
134
134
|
}
|
|
135
|
-
export type NavigationItemType =
|
|
135
|
+
export type NavigationItemType = "resource" | "page" | "link";
|
|
136
136
|
export interface NavigationItem {
|
|
137
137
|
label: string;
|
|
138
138
|
slug: string;
|
|
@@ -171,9 +171,9 @@ export interface SerializedResourceApi {
|
|
|
171
171
|
enabled: boolean;
|
|
172
172
|
methods: readonly ResourceApiMethod[];
|
|
173
173
|
fields: {
|
|
174
|
-
create: string[] |
|
|
175
|
-
update: string[] |
|
|
176
|
-
response: string[] |
|
|
174
|
+
create: string[] | "*";
|
|
175
|
+
update: string[] | "*";
|
|
176
|
+
response: string[] | "*";
|
|
177
177
|
};
|
|
178
178
|
strict: boolean;
|
|
179
179
|
}
|
|
@@ -279,8 +279,8 @@ export declare function resolveResourceSlug(resource: ResourceClass): string;
|
|
|
279
279
|
export declare function resolveResourceLabel(resource: ResourceClass): string;
|
|
280
280
|
export declare function extractFormFieldNames(form: SchemaNode | null): string[];
|
|
281
281
|
export declare function resolveResourceApi(resource: ResourceClass, form: SchemaNode | null): SerializedResourceApi;
|
|
282
|
-
export declare function pickFields(data: Record<string, unknown>, allowed: string[] |
|
|
283
|
-
export declare function assertAllowedFields(data: Record<string, unknown>, allowed: string[] |
|
|
282
|
+
export declare function pickFields(data: Record<string, unknown>, allowed: string[] | "*"): Record<string, unknown>;
|
|
283
|
+
export declare function assertAllowedFields(data: Record<string, unknown>, allowed: string[] | "*", strict: boolean): {
|
|
284
284
|
data: Record<string, unknown>;
|
|
285
285
|
rejected: string[];
|
|
286
286
|
};
|
|
@@ -306,7 +306,7 @@ export declare class Panel {
|
|
|
306
306
|
path(value: string): this;
|
|
307
307
|
apiPath(value: string): this;
|
|
308
308
|
brandName(value: string): this;
|
|
309
|
-
theme(value:
|
|
309
|
+
theme(value: "light" | "dark" | "system"): this;
|
|
310
310
|
stylesheetUrl(value: string): this;
|
|
311
311
|
colors(value: PanelThemeColors): this;
|
|
312
312
|
darkColors(value: PanelThemeColors): this;
|
|
@@ -330,7 +330,7 @@ export declare class Panel {
|
|
|
330
330
|
getPath(): string;
|
|
331
331
|
getApiPath(): string;
|
|
332
332
|
getBrandName(): string;
|
|
333
|
-
getTheme():
|
|
333
|
+
getTheme(): "light" | "dark" | "system";
|
|
334
334
|
getStylesheetUrl(): string | null;
|
|
335
335
|
getThemeOverrides(): PanelThemeOverrides;
|
|
336
336
|
getResources(): ResourceClass[];
|
|
@@ -349,5 +349,5 @@ export declare class Panel {
|
|
|
349
349
|
}
|
|
350
350
|
export declare function resolvePageSlug(page: PageClass): string;
|
|
351
351
|
export declare function groupNavigationItems(items: NavigationItem[]): NavigationGroup[];
|
|
352
|
-
export type { RelationDefinition, RelationType } from
|
|
352
|
+
export type { RelationDefinition, RelationType } from "@nestjs-dash/adapter";
|
|
353
353
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { isSoftDeleteCapable, } from
|
|
2
|
-
import { Schema } from
|
|
3
|
-
import { Table } from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
1
|
+
import { isSoftDeleteCapable, } from "@nestjs-dash/adapter";
|
|
2
|
+
import { Schema } from "./schemas/index.js";
|
|
3
|
+
import { Table } from "./tables/index.js";
|
|
4
|
+
export * from "@nestjs-dash/adapter";
|
|
5
|
+
export * from "./actions/index.js";
|
|
6
|
+
export * from "./charts/index.js";
|
|
7
|
+
export * from "./forms/index.js";
|
|
8
|
+
export * from "./schemas/index.js";
|
|
9
|
+
export * from "./tables/index.js";
|
|
10
|
+
export * from "./theme/index.js";
|
|
11
|
+
export * from "@nestjs-dash/support";
|
|
12
12
|
export class NavigationLink {
|
|
13
13
|
data;
|
|
14
14
|
constructor(label) {
|
|
15
|
-
this.data = { label, url:
|
|
15
|
+
this.data = { label, url: "#" };
|
|
16
16
|
}
|
|
17
17
|
static make(label) {
|
|
18
18
|
return new NavigationLink(label);
|
|
@@ -42,9 +42,9 @@ export class NavigationLink {
|
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
44
|
toNavigationItem(panelPath) {
|
|
45
|
-
const href = this.data.url.startsWith(
|
|
45
|
+
const href = this.data.url.startsWith("http")
|
|
46
46
|
? this.data.url
|
|
47
|
-
: this.data.url.startsWith(
|
|
47
|
+
: this.data.url.startsWith("/")
|
|
48
48
|
? this.data.url
|
|
49
49
|
: `${panelPath}/${this.data.url}`;
|
|
50
50
|
return {
|
|
@@ -52,10 +52,10 @@ export class NavigationLink {
|
|
|
52
52
|
slug: this.data.slug ??
|
|
53
53
|
this.data.label
|
|
54
54
|
.toLowerCase()
|
|
55
|
-
.replace(/[^a-z0-9]+/g,
|
|
56
|
-
.replace(/^-|-$/g,
|
|
55
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
56
|
+
.replace(/^-|-$/g, ""),
|
|
57
57
|
href,
|
|
58
|
-
type:
|
|
58
|
+
type: "link",
|
|
59
59
|
group: this.data.group ?? null,
|
|
60
60
|
sort: this.data.sort ?? 100,
|
|
61
61
|
icon: this.data.icon,
|
|
@@ -90,8 +90,8 @@ export class Page {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
export class RelationManager {
|
|
93
|
-
static relationship =
|
|
94
|
-
static type =
|
|
93
|
+
static relationship = "";
|
|
94
|
+
static type = "has-many";
|
|
95
95
|
static title;
|
|
96
96
|
static icon;
|
|
97
97
|
static relatedResource;
|
|
@@ -106,9 +106,9 @@ export class RelationManager {
|
|
|
106
106
|
}
|
|
107
107
|
function humanize(value) {
|
|
108
108
|
return value
|
|
109
|
-
.replace(/([a-z])([A-Z])/g,
|
|
110
|
-
.replace(/[-_]/g,
|
|
111
|
-
.replace(/\s+resource$/i,
|
|
109
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
110
|
+
.replace(/[-_]/g, " ")
|
|
111
|
+
.replace(/\s+resource$/i, "")
|
|
112
112
|
.trim();
|
|
113
113
|
}
|
|
114
114
|
export function resolveResourceSlug(resource) {
|
|
@@ -116,8 +116,8 @@ export function resolveResourceSlug(resource) {
|
|
|
116
116
|
return resource.slug;
|
|
117
117
|
}
|
|
118
118
|
return resource.name
|
|
119
|
-
.replace(/Resource$/i,
|
|
120
|
-
.replace(/([a-z])([A-Z])/g,
|
|
119
|
+
.replace(/Resource$/i, "")
|
|
120
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
121
121
|
.toLowerCase();
|
|
122
122
|
}
|
|
123
123
|
export function resolveResourceLabel(resource) {
|
|
@@ -130,7 +130,7 @@ export function extractFormFieldNames(form) {
|
|
|
130
130
|
const names = [];
|
|
131
131
|
const walk = (nodes) => {
|
|
132
132
|
for (const node of nodes) {
|
|
133
|
-
if (node.kind ===
|
|
133
|
+
if (node.kind === "html") {
|
|
134
134
|
continue;
|
|
135
135
|
}
|
|
136
136
|
if (node.children?.length) {
|
|
@@ -138,7 +138,7 @@ export function extractFormFieldNames(form) {
|
|
|
138
138
|
continue;
|
|
139
139
|
}
|
|
140
140
|
const name = node.name ?? node.props.name;
|
|
141
|
-
if (typeof name ===
|
|
141
|
+
if (typeof name === "string" && name.length > 0) {
|
|
142
142
|
names.push(name);
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -146,7 +146,7 @@ export function extractFormFieldNames(form) {
|
|
|
146
146
|
walk(form.children);
|
|
147
147
|
return names;
|
|
148
148
|
}
|
|
149
|
-
const ALL_API_METHODS = [
|
|
149
|
+
const ALL_API_METHODS = ["list", "get", "create", "update", "delete"];
|
|
150
150
|
export function resolveResourceApi(resource, form) {
|
|
151
151
|
const formFields = extractFormFieldNames(form);
|
|
152
152
|
const config = resource.api ?? {};
|
|
@@ -154,15 +154,15 @@ export function resolveResourceApi(resource, form) {
|
|
|
154
154
|
enabled: config.enabled !== false,
|
|
155
155
|
methods: config.methods?.length ? config.methods : [...ALL_API_METHODS],
|
|
156
156
|
fields: {
|
|
157
|
-
create: config.fields?.create ?? (formFields.length ? formFields :
|
|
158
|
-
update: config.fields?.update ?? (formFields.length ? formFields :
|
|
159
|
-
response: config.fields?.response ??
|
|
157
|
+
create: config.fields?.create ?? (formFields.length ? formFields : "*"),
|
|
158
|
+
update: config.fields?.update ?? (formFields.length ? formFields : "*"),
|
|
159
|
+
response: config.fields?.response ?? "*",
|
|
160
160
|
},
|
|
161
161
|
strict: config.strict !== false,
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
export function pickFields(data, allowed) {
|
|
165
|
-
if (allowed ===
|
|
165
|
+
if (allowed === "*") {
|
|
166
166
|
return { ...data };
|
|
167
167
|
}
|
|
168
168
|
const result = {};
|
|
@@ -174,7 +174,7 @@ export function pickFields(data, allowed) {
|
|
|
174
174
|
return result;
|
|
175
175
|
}
|
|
176
176
|
export function assertAllowedFields(data, allowed, strict) {
|
|
177
|
-
if (allowed ===
|
|
177
|
+
if (allowed === "*") {
|
|
178
178
|
return { data: { ...data }, rejected: [] };
|
|
179
179
|
}
|
|
180
180
|
const allowedSet = new Set(allowed);
|
|
@@ -193,16 +193,16 @@ export function serializeRelationManager(manager) {
|
|
|
193
193
|
let tableSchema = null;
|
|
194
194
|
let listQueryConfig = null;
|
|
195
195
|
let formSchema = null;
|
|
196
|
-
if (typeof manager.table ===
|
|
196
|
+
if (typeof manager.table === "function") {
|
|
197
197
|
const table = manager.table(Table.make());
|
|
198
198
|
tableSchema = table.toSchema();
|
|
199
199
|
listQueryConfig = table.toListQueryConfig();
|
|
200
200
|
}
|
|
201
|
-
if (typeof manager.form ===
|
|
201
|
+
if (typeof manager.form === "function") {
|
|
202
202
|
formSchema = manager.form(Schema.make()).toSchema();
|
|
203
203
|
}
|
|
204
204
|
const relatedResource = manager.relatedResource ?? relationship;
|
|
205
|
-
const ownerKey = manager.ownerKey ??
|
|
205
|
+
const ownerKey = manager.ownerKey ?? "id";
|
|
206
206
|
const pivotFields = manager.pivotFields ?? [];
|
|
207
207
|
const definition = {
|
|
208
208
|
name: relationship,
|
|
@@ -242,17 +242,17 @@ export function relationsFromResource(resource) {
|
|
|
242
242
|
return (resource.relationManagers ?? []).map((manager) => serializeRelationManager(manager).definition);
|
|
243
243
|
}
|
|
244
244
|
export class Panel {
|
|
245
|
-
panelId =
|
|
246
|
-
panelPath =
|
|
247
|
-
panelApiPath =
|
|
248
|
-
panelBrand =
|
|
245
|
+
panelId = "admin";
|
|
246
|
+
panelPath = "/admin";
|
|
247
|
+
panelApiPath = "/api";
|
|
248
|
+
panelBrand = "Nestjs-Dash";
|
|
249
249
|
resourceClasses = [];
|
|
250
250
|
pageClasses = [];
|
|
251
251
|
panelWidgets = [];
|
|
252
252
|
customNavLinks = [];
|
|
253
253
|
panelPlugins = [];
|
|
254
254
|
adapters = [];
|
|
255
|
-
panelTheme =
|
|
255
|
+
panelTheme = "system";
|
|
256
256
|
panelStylesheetUrl = null;
|
|
257
257
|
panelThemeOverrides = {};
|
|
258
258
|
panelNavigationOverrides = {};
|
|
@@ -264,11 +264,11 @@ export class Panel {
|
|
|
264
264
|
return this;
|
|
265
265
|
}
|
|
266
266
|
path(value) {
|
|
267
|
-
this.panelPath = value.startsWith(
|
|
267
|
+
this.panelPath = value.startsWith("/") ? value : `/${value}`;
|
|
268
268
|
return this;
|
|
269
269
|
}
|
|
270
270
|
apiPath(value) {
|
|
271
|
-
this.panelApiPath = value.startsWith(
|
|
271
|
+
this.panelApiPath = value.startsWith("/") ? value : `/${value}`;
|
|
272
272
|
return this;
|
|
273
273
|
}
|
|
274
274
|
brandName(value) {
|
|
@@ -473,7 +473,7 @@ export class Panel {
|
|
|
473
473
|
label: resourceClass.navigationLabel ?? serialized.label,
|
|
474
474
|
slug,
|
|
475
475
|
href: `${this.panelPath}/${slug}`,
|
|
476
|
-
type:
|
|
476
|
+
type: "resource",
|
|
477
477
|
group: resourceClass.navigationGroup ?? null,
|
|
478
478
|
sort: resourceClass.navigationSort ?? 0,
|
|
479
479
|
icon: resourceClass.navigationIcon,
|
|
@@ -488,7 +488,7 @@ export class Panel {
|
|
|
488
488
|
label: page.navigationLabel,
|
|
489
489
|
slug: page.slug,
|
|
490
490
|
href: `${this.panelPath}/pages/${page.slug}`,
|
|
491
|
-
type:
|
|
491
|
+
type: "page",
|
|
492
492
|
group: page.navigationGroup ?? null,
|
|
493
493
|
sort: page.navigationSort ?? 50,
|
|
494
494
|
icon: page.navigationIcon,
|
|
@@ -531,12 +531,12 @@ export class Panel {
|
|
|
531
531
|
let tableSchema = null;
|
|
532
532
|
let listQueryConfig = null;
|
|
533
533
|
let formSchema = null;
|
|
534
|
-
if (typeof resource.table ===
|
|
534
|
+
if (typeof resource.table === "function") {
|
|
535
535
|
const table = resource.table(Table.make());
|
|
536
536
|
tableSchema = table.toSchema();
|
|
537
537
|
listQueryConfig = table.toListQueryConfig();
|
|
538
538
|
}
|
|
539
|
-
if (typeof resource.form ===
|
|
539
|
+
if (typeof resource.form === "function") {
|
|
540
540
|
formSchema = resource.form(Schema.make()).toSchema();
|
|
541
541
|
}
|
|
542
542
|
const relationManagers = (resource.relationManagers ?? []).map((manager) => serializeRelationManager(manager));
|
|
@@ -562,16 +562,16 @@ export function resolvePageSlug(page) {
|
|
|
562
562
|
if (page.slug) {
|
|
563
563
|
return page.slug;
|
|
564
564
|
}
|
|
565
|
-
return (page.name ??
|
|
566
|
-
.replace(/Page$/i,
|
|
567
|
-
.replace(/([a-z])([A-Z])/g,
|
|
565
|
+
return (page.name ?? "page")
|
|
566
|
+
.replace(/Page$/i, "")
|
|
567
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
568
568
|
.toLowerCase();
|
|
569
569
|
}
|
|
570
570
|
export function groupNavigationItems(items) {
|
|
571
571
|
const order = [];
|
|
572
572
|
const buckets = new Map();
|
|
573
573
|
for (const item of items) {
|
|
574
|
-
const key = item.group?.trim() ||
|
|
574
|
+
const key = item.group?.trim() || "";
|
|
575
575
|
if (!buckets.has(key)) {
|
|
576
576
|
buckets.set(key, []);
|
|
577
577
|
order.push(key);
|
|
@@ -579,7 +579,7 @@ export function groupNavigationItems(items) {
|
|
|
579
579
|
buckets.get(key).push(item);
|
|
580
580
|
}
|
|
581
581
|
return order.map((key) => ({
|
|
582
|
-
label: key ||
|
|
582
|
+
label: key || "Main",
|
|
583
583
|
items: buckets.get(key) ?? [],
|
|
584
584
|
collapsible: key.length > 0,
|
|
585
585
|
collapsed: false,
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { JsonObject, SchemaNode } from
|
|
1
|
+
import type { JsonObject, SchemaNode } from "@nestjs-dash/support";
|
|
2
2
|
export declare abstract class ComponentBuilder {
|
|
3
|
-
abstract readonly kind: SchemaNode[
|
|
3
|
+
abstract readonly kind: SchemaNode["kind"];
|
|
4
4
|
protected props: JsonObject;
|
|
5
5
|
protected children: SchemaNode[];
|
|
6
6
|
protected setProp(key: string, value: unknown): this;
|
|
7
7
|
toSchema(): SchemaNode;
|
|
8
8
|
}
|
|
9
9
|
export declare class Schema extends ComponentBuilder {
|
|
10
|
-
readonly kind:
|
|
10
|
+
readonly kind: "schema";
|
|
11
11
|
static make(): Schema;
|
|
12
12
|
components(components: ComponentBuilder[]): this;
|
|
13
13
|
}
|
|
14
14
|
export declare class Section extends ComponentBuilder {
|
|
15
|
-
readonly kind:
|
|
15
|
+
readonly kind: "section";
|
|
16
16
|
static make(heading?: string): Section;
|
|
17
17
|
components(components: ComponentBuilder[]): this;
|
|
18
18
|
collapsible(value?: boolean): this;
|
|
19
19
|
}
|
|
20
20
|
export declare class Grid extends ComponentBuilder {
|
|
21
|
-
readonly kind:
|
|
21
|
+
readonly kind: "grid";
|
|
22
22
|
static make(columns?: number): Grid;
|
|
23
23
|
components(components: ComponentBuilder[]): this;
|
|
24
24
|
}
|
|
25
25
|
export declare class Tab extends ComponentBuilder {
|
|
26
|
-
readonly kind:
|
|
26
|
+
readonly kind: "tab";
|
|
27
27
|
static make(label: string): Tab;
|
|
28
28
|
id(value: string): this;
|
|
29
29
|
icon(value: string): this;
|
|
30
30
|
components(components: ComponentBuilder[]): this;
|
|
31
31
|
}
|
|
32
32
|
export declare class Tabs extends ComponentBuilder {
|
|
33
|
-
readonly kind:
|
|
33
|
+
readonly kind: "tabs";
|
|
34
34
|
static make(): Tabs;
|
|
35
35
|
tabs(items: Tab[]): this;
|
|
36
36
|
}
|
|
@@ -41,14 +41,14 @@ export interface HtmlRenderContext {
|
|
|
41
41
|
label: string;
|
|
42
42
|
};
|
|
43
43
|
path: string;
|
|
44
|
-
mode:
|
|
44
|
+
mode: "create" | "edit";
|
|
45
45
|
}
|
|
46
46
|
export type HtmlContentFn = (ctx: HtmlRenderContext) => string;
|
|
47
47
|
export declare function resolveHtmlContent(key: string): HtmlContentFn | undefined;
|
|
48
48
|
export declare class Html extends ComponentBuilder {
|
|
49
|
-
readonly kind:
|
|
49
|
+
readonly kind: "html";
|
|
50
50
|
static make(content: string | HtmlContentFn): Html;
|
|
51
51
|
key(value: string): this;
|
|
52
52
|
}
|
|
53
|
-
export { type SchemaNode } from
|
|
53
|
+
export { type SchemaNode } from "@nestjs-dash/support";
|
|
54
54
|
//# sourceMappingURL=index.d.ts.map
|