@sealcode/sealgen 0.17.19 → 0.17.21
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/@types/src/templates/jdd-editor.d.ts +1 -0
- package/@types/src/templates/shared/item-delete.d.ts +1 -1
- package/@types/src/templates/templates.d.ts +2 -0
- package/lib/add-crud.js +1 -1
- package/lib/add-route.js +6 -3
- package/lib/add-verbose-crud.js +6 -18
- package/lib/templates/jdd-editor.js +81 -0
- package/lib/templates/shared/item-delete.js +2 -4
- package/lib/templates/templates.js +3 -1
- package/package.json +1 -1
- package/src/add-crud.ts +2 -1
- package/src/add-route.ts +5 -2
- package/src/add-verbose-crud.ts +6 -21
- package/src/templates/jdd-editor.ts +89 -0
- package/src/templates/shared/item-delete.ts +3 -4
- package/src/templates/templates.ts +2 -0
- package/lib/templates/shared/confirm-item-delete.js +0 -74
- package/src/templates/shared/confirm-item-delete.ts +0 -78
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jddEditorTemplate(actionName: string): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string,
|
|
1
|
+
export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string, list_action_name: string, importPath: (path: string) => string): Promise<string>;
|
|
@@ -6,6 +6,7 @@ import { pageTemplate } from "./page.js";
|
|
|
6
6
|
import { postTemplate } from "./post.js";
|
|
7
7
|
import { redirectTemplate } from "./redirect.js";
|
|
8
8
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
9
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
9
10
|
export declare const Templates: {
|
|
10
11
|
page: typeof pageTemplate;
|
|
11
12
|
form: typeof formTemplate;
|
|
@@ -16,4 +17,5 @@ export declare const Templates: {
|
|
|
16
17
|
sreact: typeof statefulPageTemplate;
|
|
17
18
|
lpr: typeof LongRunningProcessTemplate;
|
|
18
19
|
jdd: typeof jddComponentTemplate;
|
|
20
|
+
"jdd-editor": typeof jddEditorTemplate;
|
|
19
21
|
};
|
package/lib/add-crud.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
3
2
|
import prompts from "prompts";
|
|
3
|
+
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
4
4
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
5
5
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
6
|
import {
|
package/lib/add-route.js
CHANGED
|
@@ -41,12 +41,15 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
41
41
|
{ title: "multiform", value: "multiform" },
|
|
42
42
|
{ title: "redirect", value: "redirect" },
|
|
43
43
|
{ title: "raw POST", value: "post" },
|
|
44
|
-
{ title: "Long Running Process status page", value: "lpr" }
|
|
44
|
+
{ title: "Long Running Process status page", value: "lpr" },
|
|
45
|
+
{ title: "JDD content editor", value: "jdd-editor" }
|
|
45
46
|
]
|
|
46
47
|
}
|
|
47
48
|
]);
|
|
48
49
|
const { action, url, mode } = response;
|
|
49
|
-
const extension = ["list", "lpr", "page", "sreact"].includes(
|
|
50
|
+
const extension = ["list", "lpr", "page", "sreact", "jdd-editor"].includes(
|
|
51
|
+
mode
|
|
52
|
+
) ? "tsx" : "ts";
|
|
50
53
|
const base_file_name = escape_url_params(url) || "index";
|
|
51
54
|
const file_path = target_locreq.resolve(
|
|
52
55
|
`src/back/routes/${base_file_name}.${mode}.${extension}`
|
|
@@ -64,7 +67,7 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
64
67
|
}
|
|
65
68
|
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
66
69
|
await fs.writeFile(file_path, await template(action, file_path));
|
|
67
|
-
if (mode !== "lpr") {
|
|
70
|
+
if (mode !== "lpr" && mode !== "jdd-editor") {
|
|
68
71
|
await fs.writeFile(
|
|
69
72
|
test_file_path,
|
|
70
73
|
await testTemplate(action, file_path)
|
package/lib/add-verbose-crud.js
CHANGED
|
@@ -5,12 +5,11 @@ import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
|
5
5
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
6
|
import { collectionListTemplate } from "./templates/shared/collection-list.js";
|
|
7
7
|
import { writeFile } from "./utils/write-file.js";
|
|
8
|
-
import { importPath } from "./utils/import-path.js";
|
|
8
|
+
import { curryImportPath, importPath } from "./utils/import-path.js";
|
|
9
9
|
import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
|
|
10
10
|
import { generateRoutes } from "./generate-routes.js";
|
|
11
11
|
import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
|
|
12
12
|
import { editItemFormTemplate } from "./templates/shared/collection-edit-form.js";
|
|
13
|
-
import { askItemDeleteTemplate } from "./templates/shared/confirm-item-delete.js";
|
|
14
13
|
import { itemDeleteTemplate } from "./templates/shared/item-delete.js";
|
|
15
14
|
async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
16
15
|
const target_locreq = _locreq(app_directory);
|
|
@@ -40,7 +39,6 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
40
39
|
const list_action_name = toPascalCase(collection_name) + "CRUDList";
|
|
41
40
|
const create_action_name = toPascalCase(collection_name) + "CRUDCreate";
|
|
42
41
|
const edit_action_name = toPascalCase(collection_name) + "CRUDEdit";
|
|
43
|
-
const delete_ask_action_name = toPascalCase(collection_name) + "CRUDDeleteAsk";
|
|
44
42
|
const delete_action_name = toPascalCase(collection_name) + "CRUDDelete";
|
|
45
43
|
const list_path = target_locreq.resolve(
|
|
46
44
|
`src/back/routes/${escape_url_params(url)}/index.list.tsx`
|
|
@@ -50,7 +48,7 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
50
48
|
list_action_name,
|
|
51
49
|
list_path,
|
|
52
50
|
{
|
|
53
|
-
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${
|
|
51
|
+
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
|
|
54
52
|
list_path,
|
|
55
53
|
"src/back/routes/urls.ts"
|
|
56
54
|
)}";`,
|
|
@@ -66,7 +64,7 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
66
64
|
})}
|
|
67
65
|
<td><div class="sealious-list__actions">
|
|
68
66
|
<a href={${edit_action_name}URL(item.id)}>Edit</a>
|
|
69
|
-
<a href={${
|
|
67
|
+
<a data-turbo-method="POST" data-turbo-confirm="Delete item?" href={${delete_action_name}URL(item.id)}>Delete</a>
|
|
70
68
|
</div>
|
|
71
69
|
</td>
|
|
72
70
|
</tr>;
|
|
@@ -102,25 +100,15 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
102
100
|
list_action_name
|
|
103
101
|
);
|
|
104
102
|
await writeFile(edit_path, edit_content);
|
|
105
|
-
const delete_ask_path = target_locreq.resolve(
|
|
106
|
-
`src/back/routes/${escape_url_params(url)}/[id]/delete-ask.page.tsx`
|
|
107
|
-
);
|
|
108
|
-
const delete_ask_content = await askItemDeleteTemplate(
|
|
109
|
-
delete_ask_action_name,
|
|
110
|
-
collection_name,
|
|
111
|
-
delete_ask_path,
|
|
112
|
-
list_action_name,
|
|
113
|
-
delete_action_name
|
|
114
|
-
);
|
|
115
|
-
await writeFile(delete_ask_path, delete_ask_content);
|
|
116
103
|
const delete_path = target_locreq.resolve(
|
|
117
104
|
`src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
|
|
118
105
|
);
|
|
106
|
+
const base_import_path = curryImportPath(delete_path);
|
|
119
107
|
const delete_content = await itemDeleteTemplate(
|
|
120
108
|
delete_action_name,
|
|
121
109
|
collection_name,
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
list_action_name,
|
|
111
|
+
base_import_path
|
|
124
112
|
);
|
|
125
113
|
await writeFile(delete_path, delete_content);
|
|
126
114
|
await generateRoutes();
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { toPascalCase } from "js-convert-case";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
4
|
+
import { listCollections } from "../utils/list-collections.js";
|
|
5
|
+
async function jddEditorTemplate(actionName) {
|
|
6
|
+
const response = await prompts([
|
|
7
|
+
{
|
|
8
|
+
type: "autocomplete",
|
|
9
|
+
name: "collection",
|
|
10
|
+
message: "Which sealious collection do you like to add CRUD forms for?",
|
|
11
|
+
choices: (await listCollections()).map((collection) => ({
|
|
12
|
+
title: collection,
|
|
13
|
+
value: collection
|
|
14
|
+
}))
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
const collection_name = response.collection;
|
|
18
|
+
const jdd_fields = (await extract_fields_from_collection(collection_name)).filter((e) => e.type == "jdd");
|
|
19
|
+
let field_name = "";
|
|
20
|
+
if (jdd_fields.length == 1) {
|
|
21
|
+
field_name = jdd_fields[0].name;
|
|
22
|
+
console.log(
|
|
23
|
+
`Only one field of type JDD found: ${field_name}, so skipping the question...`
|
|
24
|
+
);
|
|
25
|
+
} else if (jdd_fields.length > 1) {
|
|
26
|
+
const response2 = await prompts([
|
|
27
|
+
{
|
|
28
|
+
type: "autocomplete",
|
|
29
|
+
name: "field_name",
|
|
30
|
+
message: `Which jdd field from the ${collection_name} do you want to setup the jdd-editor for?`,
|
|
31
|
+
choices: jdd_fields.map((field) => ({
|
|
32
|
+
title: field.name,
|
|
33
|
+
value: field.name
|
|
34
|
+
}))
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
field_name = response2.field_name;
|
|
38
|
+
} else {
|
|
39
|
+
console.error(
|
|
40
|
+
`Collection ${collection_name} does not have any fields of type JDD. Add such a field and try again.`
|
|
41
|
+
);
|
|
42
|
+
process.exit(13);
|
|
43
|
+
}
|
|
44
|
+
const collectionClassName = toPascalCase(collection_name);
|
|
45
|
+
return `import type { Context } from "koa";
|
|
46
|
+
import type { FieldNames } from "sealious";
|
|
47
|
+
import { TempstreamJSX } from "tempstream";
|
|
48
|
+
import type ${collectionClassName} from "src/back/collections/${collection_name}.js";
|
|
49
|
+
import { EditJDDField } from "@sealcode/jdd-editor";
|
|
50
|
+
import html from "src/back/html.js";
|
|
51
|
+
import { registry } from "src/back/jdd-components/registry.js";
|
|
52
|
+
import { makeJDDContext } from "src/back/jdd-context.js";
|
|
53
|
+
import { defaultHead } from "src/back/defaultHead.js";
|
|
54
|
+
|
|
55
|
+
export const actionName = "${actionName}";
|
|
56
|
+
|
|
57
|
+
export default new (class JDDCreatePreviewPage extends EditJDDField<${collectionClassName}> {
|
|
58
|
+
getCollection(ctx: Context) {
|
|
59
|
+
return ctx.$app.collections["${collection_name}"];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getJDDFieldName(): FieldNames<${collectionClassName}["fields"]> {
|
|
63
|
+
return "${field_name}";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async renderPreParameterButtons(ctx: Context) {
|
|
67
|
+
const item = await this.getItem(ctx);
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<h1>Edit ${collection_name}: {item.id}</h1>{" "}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
})({ html, registry, makeJDDContext, defaultHead });
|
|
75
|
+
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
jddEditorTemplate
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=jdd-editor.js.map
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
2
|
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
function itemDeleteTemplate(delete_action_name, collection_name,
|
|
5
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
3
|
+
function itemDeleteTemplate(delete_action_name, collection_name, list_action_name, importPath) {
|
|
6
4
|
const result = `import type { Context } from "koa";
|
|
7
5
|
import { Mountable } from "@sealcode/sealgen";
|
|
8
6
|
import type Router from "@koa/router";
|
|
@@ -25,7 +23,7 @@ export default new (class ${delete_action_name}Redirect extends Mountable {
|
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
mount(router: Router, path: string) {
|
|
28
|
-
router.
|
|
26
|
+
router.post(path, async (ctx) => {
|
|
29
27
|
await ctx.$app.collections["${toKebabCase(
|
|
30
28
|
collection_name
|
|
31
29
|
)}"].removeByID(ctx.$context, ctx.params.id!);
|
|
@@ -7,6 +7,7 @@ import { pageTemplate } from "./page.js";
|
|
|
7
7
|
import { postTemplate } from "./post.js";
|
|
8
8
|
import { redirectTemplate } from "./redirect.js";
|
|
9
9
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
10
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
10
11
|
const Templates = {
|
|
11
12
|
page: pageTemplate,
|
|
12
13
|
form: formTemplate,
|
|
@@ -16,7 +17,8 @@ const Templates = {
|
|
|
16
17
|
post: postTemplate,
|
|
17
18
|
sreact: statefulPageTemplate,
|
|
18
19
|
lpr: LongRunningProcessTemplate,
|
|
19
|
-
jdd: jddComponentTemplate
|
|
20
|
+
jdd: jddComponentTemplate,
|
|
21
|
+
"jdd-editor": jddEditorTemplate
|
|
20
22
|
};
|
|
21
23
|
export {
|
|
22
24
|
Templates
|
package/package.json
CHANGED
package/src/add-crud.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
3
2
|
import prompts from "prompts";
|
|
3
|
+
|
|
4
|
+
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
4
5
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
5
6
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
7
|
import {
|
package/src/add-route.ts
CHANGED
|
@@ -49,12 +49,15 @@ export async function addRoute(
|
|
|
49
49
|
{ title: "redirect", value: "redirect" },
|
|
50
50
|
{ title: "raw POST", value: "post" },
|
|
51
51
|
{ title: "Long Running Process status page", value: "lpr" },
|
|
52
|
+
{ title: "JDD content editor", value: "jdd-editor" },
|
|
52
53
|
],
|
|
53
54
|
},
|
|
54
55
|
]);
|
|
55
56
|
|
|
56
57
|
const { action, url, mode } = response as Record<string, string>;
|
|
57
|
-
const extension = ["list", "lpr", "page", "sreact"].includes(
|
|
58
|
+
const extension = ["list", "lpr", "page", "sreact", "jdd-editor"].includes(
|
|
59
|
+
mode
|
|
60
|
+
)
|
|
58
61
|
? "tsx"
|
|
59
62
|
: "ts";
|
|
60
63
|
|
|
@@ -78,7 +81,7 @@ export async function addRoute(
|
|
|
78
81
|
}
|
|
79
82
|
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
80
83
|
await fs.writeFile(file_path, await template(action, file_path));
|
|
81
|
-
if (mode !== "lpr") {
|
|
84
|
+
if (mode !== "lpr" && mode !== "jdd-editor") {
|
|
82
85
|
await fs.writeFile(
|
|
83
86
|
test_file_path,
|
|
84
87
|
await testTemplate(action, file_path)
|
package/src/add-verbose-crud.ts
CHANGED
|
@@ -5,12 +5,11 @@ import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
|
5
5
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
6
|
import { collectionListTemplate } from "./templates/shared/collection-list.js";
|
|
7
7
|
import { writeFile } from "./utils/write-file.js";
|
|
8
|
-
import { importPath } from "./utils/import-path.js";
|
|
8
|
+
import { curryImportPath, importPath } from "./utils/import-path.js";
|
|
9
9
|
import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
|
|
10
10
|
import { generateRoutes } from "./generate-routes.js";
|
|
11
11
|
import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
|
|
12
12
|
import { editItemFormTemplate } from "./templates/shared/collection-edit-form.js";
|
|
13
|
-
import { askItemDeleteTemplate } from "./templates/shared/confirm-item-delete.js";
|
|
14
13
|
import { itemDeleteTemplate } from "./templates/shared/item-delete.js";
|
|
15
14
|
|
|
16
15
|
export async function addVerboseCRUD(
|
|
@@ -50,8 +49,6 @@ export async function addVerboseCRUD(
|
|
|
50
49
|
const list_action_name = toPascalCase(collection_name) + "CRUDList";
|
|
51
50
|
const create_action_name = toPascalCase(collection_name) + "CRUDCreate";
|
|
52
51
|
const edit_action_name = toPascalCase(collection_name) + "CRUDEdit";
|
|
53
|
-
const delete_ask_action_name =
|
|
54
|
-
toPascalCase(collection_name) + "CRUDDeleteAsk";
|
|
55
52
|
const delete_action_name = toPascalCase(collection_name) + "CRUDDelete";
|
|
56
53
|
|
|
57
54
|
/* create the list endpoint */
|
|
@@ -63,7 +60,7 @@ export async function addVerboseCRUD(
|
|
|
63
60
|
list_action_name,
|
|
64
61
|
list_path,
|
|
65
62
|
{
|
|
66
|
-
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${
|
|
63
|
+
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
|
|
67
64
|
list_path,
|
|
68
65
|
"src/back/routes/urls.ts"
|
|
69
66
|
)}";`,
|
|
@@ -81,7 +78,7 @@ export async function addVerboseCRUD(
|
|
|
81
78
|
})}
|
|
82
79
|
<td><div class="sealious-list__actions">
|
|
83
80
|
<a href={${edit_action_name}URL(item.id)}>Edit</a>
|
|
84
|
-
<a href={${
|
|
81
|
+
<a data-turbo-method="POST" data-turbo-confirm="Delete item?" href={${delete_action_name}URL(item.id)}>Delete</a>
|
|
85
82
|
</div>
|
|
86
83
|
</td>
|
|
87
84
|
</tr>;
|
|
@@ -124,28 +121,16 @@ export async function addVerboseCRUD(
|
|
|
124
121
|
);
|
|
125
122
|
await writeFile(edit_path, edit_content);
|
|
126
123
|
|
|
127
|
-
/* create the confirm delete endpoint */
|
|
128
|
-
const delete_ask_path = target_locreq.resolve(
|
|
129
|
-
`src/back/routes/${escape_url_params(url)}/[id]/delete-ask.page.tsx`
|
|
130
|
-
);
|
|
131
|
-
const delete_ask_content = await askItemDeleteTemplate(
|
|
132
|
-
delete_ask_action_name,
|
|
133
|
-
collection_name,
|
|
134
|
-
delete_ask_path,
|
|
135
|
-
list_action_name,
|
|
136
|
-
delete_action_name
|
|
137
|
-
);
|
|
138
|
-
await writeFile(delete_ask_path, delete_ask_content);
|
|
139
|
-
|
|
140
124
|
/* create the actual delete endpoint */
|
|
141
125
|
const delete_path = target_locreq.resolve(
|
|
142
126
|
`src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
|
|
143
127
|
);
|
|
128
|
+
const base_import_path = curryImportPath(delete_path);
|
|
144
129
|
const delete_content = await itemDeleteTemplate(
|
|
145
130
|
delete_action_name,
|
|
146
131
|
collection_name,
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
list_action_name,
|
|
133
|
+
base_import_path
|
|
149
134
|
);
|
|
150
135
|
await writeFile(delete_path, delete_content);
|
|
151
136
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toPascalCase } from "js-convert-case";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
4
|
+
|
|
5
|
+
import { listCollections } from "../utils/list-collections.js";
|
|
6
|
+
|
|
7
|
+
export async function jddEditorTemplate(actionName: string) {
|
|
8
|
+
const response = await prompts([
|
|
9
|
+
{
|
|
10
|
+
type: "autocomplete",
|
|
11
|
+
name: "collection",
|
|
12
|
+
message:
|
|
13
|
+
"Which sealious collection do you like to add CRUD forms for?",
|
|
14
|
+
choices: (
|
|
15
|
+
await listCollections()
|
|
16
|
+
).map((collection) => ({
|
|
17
|
+
title: collection,
|
|
18
|
+
value: collection,
|
|
19
|
+
})),
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const collection_name = response.collection as string;
|
|
24
|
+
|
|
25
|
+
const jdd_fields = (
|
|
26
|
+
await extract_fields_from_collection(collection_name)
|
|
27
|
+
).filter((e) => e.type == "jdd");
|
|
28
|
+
|
|
29
|
+
let field_name = "";
|
|
30
|
+
if (jdd_fields.length == 1) {
|
|
31
|
+
field_name = jdd_fields[0].name;
|
|
32
|
+
console.log(
|
|
33
|
+
`Only one field of type JDD found: ${field_name}, so skipping the question...`
|
|
34
|
+
);
|
|
35
|
+
} else if (jdd_fields.length > 1) {
|
|
36
|
+
const response = await prompts([
|
|
37
|
+
{
|
|
38
|
+
type: "autocomplete",
|
|
39
|
+
name: "field_name",
|
|
40
|
+
message: `Which jdd field from the ${collection_name} do you want to setup the jdd-editor for?`,
|
|
41
|
+
choices: jdd_fields.map((field) => ({
|
|
42
|
+
title: field.name,
|
|
43
|
+
value: field.name,
|
|
44
|
+
})),
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
field_name = response.field_name as string;
|
|
48
|
+
} else {
|
|
49
|
+
console.error(
|
|
50
|
+
`Collection ${collection_name} does not have any fields of type JDD. Add such a field and try again.`
|
|
51
|
+
);
|
|
52
|
+
process.exit(13);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const collectionClassName = toPascalCase(collection_name);
|
|
56
|
+
|
|
57
|
+
return `import type { Context } from "koa";
|
|
58
|
+
import type { FieldNames } from "sealious";
|
|
59
|
+
import { TempstreamJSX } from "tempstream";
|
|
60
|
+
import type ${collectionClassName} from "src/back/collections/${collection_name}.js";
|
|
61
|
+
import { EditJDDField } from "@sealcode/jdd-editor";
|
|
62
|
+
import html from "src/back/html.js";
|
|
63
|
+
import { registry } from "src/back/jdd-components/registry.js";
|
|
64
|
+
import { makeJDDContext } from "src/back/jdd-context.js";
|
|
65
|
+
import { defaultHead } from "src/back/defaultHead.js";
|
|
66
|
+
|
|
67
|
+
export const actionName = "${actionName}";
|
|
68
|
+
|
|
69
|
+
export default new (class JDDCreatePreviewPage extends EditJDDField<${collectionClassName}> {
|
|
70
|
+
getCollection(ctx: Context) {
|
|
71
|
+
return ctx.$app.collections["${collection_name}"];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getJDDFieldName(): FieldNames<${collectionClassName}["fields"]> {
|
|
75
|
+
return "${field_name}";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async renderPreParameterButtons(ctx: Context) {
|
|
79
|
+
const item = await this.getItem(ctx);
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<h1>Edit ${collection_name}: {item.id}</h1>{" "}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
})({ html, registry, makeJDDContext, defaultHead });
|
|
87
|
+
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
@@ -5,10 +5,9 @@ import { formatWithPrettier } from "../../utils/prettier.js";
|
|
|
5
5
|
export function itemDeleteTemplate(
|
|
6
6
|
delete_action_name: string,
|
|
7
7
|
collection_name: string,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
list_action_name: string,
|
|
9
|
+
importPath: (path: string) => string
|
|
10
10
|
): Promise<string> {
|
|
11
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
12
11
|
const result = `import type { Context } from "koa";
|
|
13
12
|
import { Mountable } from "@sealcode/sealgen";
|
|
14
13
|
import type Router from "@koa/router";
|
|
@@ -31,7 +30,7 @@ export default new (class ${delete_action_name}Redirect extends Mountable {
|
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
mount(router: Router, path: string) {
|
|
34
|
-
router.
|
|
33
|
+
router.post(path, async (ctx) => {
|
|
35
34
|
await ctx.$app.collections["${toKebabCase(
|
|
36
35
|
collection_name
|
|
37
36
|
)}"].removeByID(ctx.$context, ctx.params.id!);
|
|
@@ -7,6 +7,7 @@ import { pageTemplate } from "./page.js";
|
|
|
7
7
|
import { postTemplate } from "./post.js";
|
|
8
8
|
import { redirectTemplate } from "./redirect.js";
|
|
9
9
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
10
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
10
11
|
|
|
11
12
|
export const Templates = {
|
|
12
13
|
page: pageTemplate,
|
|
@@ -18,4 +19,5 @@ export const Templates = {
|
|
|
18
19
|
sreact: statefulPageTemplate,
|
|
19
20
|
lpr: LongRunningProcessTemplate,
|
|
20
21
|
jdd: jddComponentTemplate,
|
|
22
|
+
"jdd-editor": jddEditorTemplate,
|
|
21
23
|
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
|
-
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
async function askItemDeleteTemplate(ask_delete_action_name, collection_name, newfilefullpath, list_action_name, delete_action_name) {
|
|
5
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
6
|
-
const result = `import type { Context } from "koa";
|
|
7
|
-
import { Page } from "@sealcode/sealgen";
|
|
8
|
-
import type { CollectionItem } from "sealious";
|
|
9
|
-
import { TempstreamJSX } from "tempstream";
|
|
10
|
-
import { ${delete_action_name}URL } from "${importPath(
|
|
11
|
-
"src/back/routes/urls.js"
|
|
12
|
-
)}";
|
|
13
|
-
import html from "${importPath("src/back/html.ts")}";
|
|
14
|
-
import { ${toPascalCase(collection_name)} as ${toPascalCase(
|
|
15
|
-
collection_name
|
|
16
|
-
)}Collection } from "${importPath("src/back/collections/collections.js")}";
|
|
17
|
-
|
|
18
|
-
export const actionName = "${ask_delete_action_name}";
|
|
19
|
-
|
|
20
|
-
export default new (class ${ask_delete_action_name}Page extends Page {
|
|
21
|
-
canAccess = async (ctx: Context) => {
|
|
22
|
-
const policy = ${toPascalCase(
|
|
23
|
-
collection_name
|
|
24
|
-
)}Collection.getPolicy("edit");
|
|
25
|
-
const response = await policy.check(ctx.$context);
|
|
26
|
-
return { canAccess: response?.allowed || false, message: response?.reason || "" };
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
getItemTitle(_ctx: Context, item: CollectionItem<typeof ${toPascalCase(
|
|
30
|
-
collection_name
|
|
31
|
-
)}Collection>){
|
|
32
|
-
return item.get("name")
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async render(ctx: Context) {
|
|
36
|
-
const id = ctx.params.id
|
|
37
|
-
if(!id){throw new Error("Could not read the id param from the URL")}
|
|
38
|
-
const { items: [item] } =
|
|
39
|
-
await ctx.$app.collections["${toKebabCase(
|
|
40
|
-
collection_name
|
|
41
|
-
)}"].list(ctx.$context).ids([id]).fetch();
|
|
42
|
-
|
|
43
|
-
if (!item) {
|
|
44
|
-
throw new Error("Item with given id not found");
|
|
45
|
-
}
|
|
46
|
-
return html(
|
|
47
|
-
ctx,
|
|
48
|
-
"Delete?",
|
|
49
|
-
<div>
|
|
50
|
-
<div class="confirm-delete-page confirm-delete-page--${toKebabCase(
|
|
51
|
-
collection_name
|
|
52
|
-
)}">
|
|
53
|
-
<span>
|
|
54
|
-
Are you sure you want to remove: {" "}
|
|
55
|
-
<b>{this.getItemTitle(ctx, item)}</b>
|
|
56
|
-
</span>
|
|
57
|
-
<form action={${delete_action_name}URL(item.id)}>
|
|
58
|
-
<button type="submit">
|
|
59
|
-
remove
|
|
60
|
-
</button>
|
|
61
|
-
<input type="hidden" name="id" value={item?.id} />
|
|
62
|
-
</form>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
})();
|
|
68
|
-
`;
|
|
69
|
-
return await formatWithPrettier(result);
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
askItemDeleteTemplate
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=confirm-item-delete.js.map
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
|
-
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
|
|
5
|
-
export async function askItemDeleteTemplate(
|
|
6
|
-
ask_delete_action_name: string,
|
|
7
|
-
collection_name: string,
|
|
8
|
-
newfilefullpath: string,
|
|
9
|
-
list_action_name: string,
|
|
10
|
-
delete_action_name: string
|
|
11
|
-
): Promise<string> {
|
|
12
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
13
|
-
const result = `import type { Context } from "koa";
|
|
14
|
-
import { Page } from "@sealcode/sealgen";
|
|
15
|
-
import type { CollectionItem } from "sealious";
|
|
16
|
-
import { TempstreamJSX } from "tempstream";
|
|
17
|
-
import { ${delete_action_name}URL } from "${importPath(
|
|
18
|
-
"src/back/routes/urls.js"
|
|
19
|
-
)}";
|
|
20
|
-
import html from "${importPath("src/back/html.ts")}";
|
|
21
|
-
import { ${toPascalCase(collection_name)} as ${toPascalCase(
|
|
22
|
-
collection_name
|
|
23
|
-
)}Collection } from "${importPath("src/back/collections/collections.js")}";
|
|
24
|
-
|
|
25
|
-
export const actionName = "${ask_delete_action_name}";
|
|
26
|
-
|
|
27
|
-
export default new (class ${ask_delete_action_name}Page extends Page {
|
|
28
|
-
canAccess = async (ctx: Context) => {
|
|
29
|
-
const policy = ${toPascalCase(
|
|
30
|
-
collection_name
|
|
31
|
-
)}Collection.getPolicy("edit");
|
|
32
|
-
const response = await policy.check(ctx.$context);
|
|
33
|
-
return { canAccess: response?.allowed || false, message: response?.reason || "" };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
getItemTitle(_ctx: Context, item: CollectionItem<typeof ${toPascalCase(
|
|
37
|
-
collection_name
|
|
38
|
-
)}Collection>){
|
|
39
|
-
return item.get("name")
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async render(ctx: Context) {
|
|
43
|
-
const id = ctx.params.id
|
|
44
|
-
if(!id){throw new Error("Could not read the id param from the URL")}
|
|
45
|
-
const { items: [item] } =
|
|
46
|
-
await ctx.$app.collections["${toKebabCase(
|
|
47
|
-
collection_name
|
|
48
|
-
)}"].list(ctx.$context).ids([id]).fetch();
|
|
49
|
-
|
|
50
|
-
if (!item) {
|
|
51
|
-
throw new Error("Item with given id not found");
|
|
52
|
-
}
|
|
53
|
-
return html(
|
|
54
|
-
ctx,
|
|
55
|
-
"Delete?",
|
|
56
|
-
<div>
|
|
57
|
-
<div class="confirm-delete-page confirm-delete-page--${toKebabCase(
|
|
58
|
-
collection_name
|
|
59
|
-
)}">
|
|
60
|
-
<span>
|
|
61
|
-
Are you sure you want to remove: {" "}
|
|
62
|
-
<b>{this.getItemTitle(ctx, item)}</b>
|
|
63
|
-
</span>
|
|
64
|
-
<form action={${delete_action_name}URL(item.id)}>
|
|
65
|
-
<button type="submit">
|
|
66
|
-
remove
|
|
67
|
-
</button>
|
|
68
|
-
<input type="hidden" name="id" value={item?.id} />
|
|
69
|
-
</form>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
})();
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
return await formatWithPrettier(result);
|
|
78
|
-
}
|