@sealcode/sealgen 0.12.0 → 0.12.3
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/notifier.js +1 -1
- package/package.json +2 -2
- package/src/notifier.ts +1 -1
- package/.madgerc +0 -7
- package/coverage/.tmp/coverage-15.json +0 -1
- package/coverage/.tmp/coverage-16.json +0 -1
- package/coverage/.tmp/coverage-17.json +0 -1
- package/coverage/.tmp/coverage-18.json +0 -1
- package/coverage/.tmp/coverage-19.json +0 -1
- package/coverage/.tmp/coverage-20.json +0 -1
- package/coverage/.tmp/coverage-21.json +0 -1
- package/coverage/.tmp/coverage-22.json +0 -1
- package/coverage/.tmp/coverage-23.json +0 -1
- package/coverage/.tmp/coverage-24.json +0 -1
- package/coverage/.tmp/coverage-25.json +0 -1
- package/coverage/.tmp/coverage-26.json +0 -1
- package/lib/add-collection.js +0 -24
- package/lib/add-jdd-component.js +0 -27
- package/lib/add-route.js +0 -65
- package/lib/add-route.test.js +0 -60
- package/lib/build.js +0 -187
- package/lib/cli.js +0 -35
- package/lib/components/components.js +0 -3
- package/lib/components/tabs.js +0 -88
- package/lib/components/toggle-modal.js +0 -46
- package/lib/example.test.js +0 -5
- package/lib/find-css-includes.js +0 -23
- package/lib/forms/controls/array.js +0 -140
- package/lib/forms/controls/autocomplete.js +0 -23
- package/lib/forms/controls/big-radio-group.js +0 -34
- package/lib/forms/controls/checkbox-group.js +0 -29
- package/lib/forms/controls/checkbox.js +0 -24
- package/lib/forms/controls/checkboxed-list-input.js +0 -35
- package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
- package/lib/forms/controls/collapsible-field-group.js +0 -78
- package/lib/forms/controls/controls.js +0 -31
- package/lib/forms/controls/derived-frame.js +0 -52
- package/lib/forms/controls/derived.js +0 -77
- package/lib/forms/controls/dropdown.js +0 -55
- package/lib/forms/controls/editable-collection-subset.js +0 -68
- package/lib/forms/controls/field-group.js +0 -53
- package/lib/forms/controls/file.js +0 -35
- package/lib/forms/controls/form-control.js +0 -14
- package/lib/forms/controls/form-field-control.js +0 -9
- package/lib/forms/controls/form-header.js +0 -14
- package/lib/forms/controls/form-paragraph.js +0 -12
- package/lib/forms/controls/frame.js +0 -25
- package/lib/forms/controls/hidden-input.js +0 -14
- package/lib/forms/controls/html.js +0 -23
- package/lib/forms/controls/multiple-files.js +0 -160
- package/lib/forms/controls/multiple-photos.js +0 -33
- package/lib/forms/controls/number.js +0 -25
- package/lib/forms/controls/photo.js +0 -57
- package/lib/forms/controls/radio.js +0 -25
- package/lib/forms/controls/reverse-single-reference.js +0 -47
- package/lib/forms/controls/simple-input.js +0 -78
- package/lib/forms/controls/textarea.js +0 -33
- package/lib/forms/controls/tickable.js +0 -75
- package/lib/forms/fields/boolean.js +0 -51
- package/lib/forms/fields/boolean.test.js +0 -32
- package/lib/forms/fields/checkboxed-list.js +0 -40
- package/lib/forms/fields/collection-field.js +0 -29
- package/lib/forms/fields/email.js +0 -11
- package/lib/forms/fields/email.test.js +0 -20
- package/lib/forms/fields/enum-multiple.js +0 -47
- package/lib/forms/fields/enum-multiple.test.js +0 -27
- package/lib/forms/fields/enum.js +0 -39
- package/lib/forms/fields/enum.test.js +0 -21
- package/lib/forms/fields/existing-sealious-value.js +0 -16
- package/lib/forms/fields/field.js +0 -81
- package/lib/forms/fields/file.js +0 -53
- package/lib/forms/fields/multiple-files.js +0 -15
- package/lib/forms/fields/number.js +0 -45
- package/lib/forms/fields/number.test.js +0 -30
- package/lib/forms/fields/pick-from-list.js +0 -31
- package/lib/forms/fields/pick-from-list.test.js +0 -17
- package/lib/forms/fields/proxy-field.js +0 -20
- package/lib/forms/fields/regexp.js +0 -40
- package/lib/forms/fields/regexp.test.js +0 -21
- package/lib/forms/fields/reverse-single-reference.js +0 -14
- package/lib/forms/fields/simple-form-field.js +0 -20
- package/lib/forms/fields/structured-array.js +0 -18
- package/lib/forms/form.js +0 -176
- package/lib/forms/form.test.js +0 -1
- package/lib/forms/multiform.js +0 -174
- package/lib/forms/multiform.test.js +0 -426
- package/lib/generate-collections.js +0 -52
- package/lib/generate-components.js +0 -33
- package/lib/generate-routes.js +0 -75
- package/lib/index.js +0 -17
- package/lib/make-env.js +0 -14
- package/lib/make-hidden-inputs.js +0 -14
- package/lib/mount.js +0 -70
- package/lib/notifier.js +0 -19
- package/lib/page/access-control.js +0 -16
- package/lib/page/default-list-filters.js +0 -40
- package/lib/page/list.js +0 -183
- package/lib/page/mountable-with-fields.js +0 -85
- package/lib/page/mountable.js +0 -5
- package/lib/page/page.js +0 -26
- package/lib/page/props-parser.js +0 -23
- package/lib/page/sealious-list.js +0 -59
- package/lib/page/stateful-page.js +0 -97
- package/lib/remove-named-imports.js +0 -47
- package/lib/run.js +0 -2
- package/lib/sanitize.js +0 -10
- package/lib/src/add-collection.js +0 -24
- package/lib/src/add-jdd-component.js +0 -27
- package/lib/src/add-route.js +0 -65
- package/lib/src/add-route.test.js +0 -72
- package/lib/src/build.js +0 -142
- package/lib/src/cli.js +0 -37
- package/lib/src/components/components.js +0 -3
- package/lib/src/components/tabs.js +0 -88
- package/lib/src/components/toggle-modal.js +0 -46
- package/lib/src/example.test.js +0 -5
- package/lib/src/find-css-includes.js +0 -23
- package/lib/src/forms/controls/array.js +0 -141
- package/lib/src/forms/controls/autocomplete.js +0 -23
- package/lib/src/forms/controls/big-radio-group.js +0 -34
- package/lib/src/forms/controls/checkbox-group.js +0 -30
- package/lib/src/forms/controls/checkbox.js +0 -24
- package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
- package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
- package/lib/src/forms/controls/collapsible-field-group.js +0 -78
- package/lib/src/forms/controls/controls.js +0 -31
- package/lib/src/forms/controls/derived-frame.js +0 -52
- package/lib/src/forms/controls/derived.js +0 -77
- package/lib/src/forms/controls/dropdown.js +0 -55
- package/lib/src/forms/controls/editable-collection-subset.js +0 -68
- package/lib/src/forms/controls/field-group.js +0 -53
- package/lib/src/forms/controls/file.js +0 -35
- package/lib/src/forms/controls/form-control.js +0 -14
- package/lib/src/forms/controls/form-field-control.js +0 -9
- package/lib/src/forms/controls/form-header.js +0 -14
- package/lib/src/forms/controls/form-paragraph.js +0 -12
- package/lib/src/forms/controls/frame.js +0 -25
- package/lib/src/forms/controls/hidden-input.js +0 -14
- package/lib/src/forms/controls/html.js +0 -23
- package/lib/src/forms/controls/multiple-files.js +0 -160
- package/lib/src/forms/controls/multiple-photos.js +0 -33
- package/lib/src/forms/controls/number.js +0 -25
- package/lib/src/forms/controls/photo.js +0 -57
- package/lib/src/forms/controls/radio.js +0 -25
- package/lib/src/forms/controls/reverse-single-reference.js +0 -47
- package/lib/src/forms/controls/simple-input.js +0 -78
- package/lib/src/forms/controls/textarea.js +0 -33
- package/lib/src/forms/controls/tickable.js +0 -75
- package/lib/src/forms/fields/boolean.js +0 -51
- package/lib/src/forms/fields/boolean.test.js +0 -33
- package/lib/src/forms/fields/checkboxed-list.js +0 -40
- package/lib/src/forms/fields/collection-field.js +0 -29
- package/lib/src/forms/fields/email.js +0 -11
- package/lib/src/forms/fields/email.test.js +0 -20
- package/lib/src/forms/fields/enum-multiple.js +0 -47
- package/lib/src/forms/fields/enum-multiple.test.js +0 -27
- package/lib/src/forms/fields/enum.js +0 -39
- package/lib/src/forms/fields/enum.test.js +0 -21
- package/lib/src/forms/fields/existing-sealious-value.js +0 -16
- package/lib/src/forms/fields/field.js +0 -66
- package/lib/src/forms/fields/fields.js +0 -16
- package/lib/src/forms/fields/file.js +0 -53
- package/lib/src/forms/fields/multiple-files.js +0 -15
- package/lib/src/forms/fields/number.js +0 -45
- package/lib/src/forms/fields/number.test.js +0 -31
- package/lib/src/forms/fields/pick-from-list.js +0 -31
- package/lib/src/forms/fields/pick-from-list.test.js +0 -17
- package/lib/src/forms/fields/proxy-field.js +0 -20
- package/lib/src/forms/fields/regexp.js +0 -40
- package/lib/src/forms/fields/regexp.test.js +0 -21
- package/lib/src/forms/fields/reverse-single-reference.js +0 -14
- package/lib/src/forms/fields/simple-form-field.js +0 -19
- package/lib/src/forms/fields/structured-array.js +0 -18
- package/lib/src/forms/form-types.js +0 -2
- package/lib/src/forms/form.js +0 -176
- package/lib/src/forms/form.test.js +0 -271
- package/lib/src/forms/multiform.js +0 -174
- package/lib/src/forms/multiform.test.js +0 -430
- package/lib/src/generate-collections.js +0 -52
- package/lib/src/generate-components.js +0 -33
- package/lib/src/generate-routes.js +0 -75
- package/lib/src/hehe.test.js +0 -7
- package/lib/src/index.js +0 -19
- package/lib/src/make-env.js +0 -14
- package/lib/src/make-hidden-inputs.js +0 -14
- package/lib/src/mount.js +0 -70
- package/lib/src/notifier.js +0 -19
- package/lib/src/page/access-control.js +0 -16
- package/lib/src/page/default-list-filters.js +0 -40
- package/lib/src/page/list.js +0 -184
- package/lib/src/page/mountable-with-fields.js +0 -85
- package/lib/src/page/mountable.js +0 -5
- package/lib/src/page/page.js +0 -26
- package/lib/src/page/props-parser.js +0 -23
- package/lib/src/page/sealious-list.js +0 -59
- package/lib/src/page/stateful-page.js +0 -97
- package/lib/src/run.js +0 -2
- package/lib/src/sample-index.js +0 -3
- package/lib/src/sample-lib.js +0 -6
- package/lib/src/sanitize.js +0 -10
- package/lib/src/templates/collection.js +0 -12
- package/lib/src/templates/form.js +0 -57
- package/lib/src/templates/jdd-component.js +0 -39
- package/lib/src/templates/list.js +0 -139
- package/lib/src/templates/long-running-process.js +0 -60
- package/lib/src/templates/multiform.js +0 -55
- package/lib/src/templates/page.js +0 -23
- package/lib/src/templates/post.js +0 -22
- package/lib/src/templates/redirect.js +0 -23
- package/lib/src/templates/route-test.js +0 -54
- package/lib/src/templates/stateful-page.js +0 -66
- package/lib/src/templates/templates.js +0 -21
- package/lib/src/test_utils/locator_is_visible.js +0 -11
- package/lib/src/utils/assert-throws.js +0 -17
- package/lib/src/utils/base64.js +0 -7
- package/lib/src/utils/browser-creator.js +0 -10
- package/lib/src/utils/escape-url-params.js +0 -14
- package/lib/src/utils/exec.js +0 -22
- package/lib/src/utils/extract-fields-from-collection.js +0 -26
- package/lib/src/utils/format-external-url.js +0 -11
- package/lib/src/utils/import-path.js +0 -16
- package/lib/src/utils/input-wrapper.js +0 -15
- package/lib/src/utils/list-collections.js +0 -13
- package/lib/src/utils/make-slug.js +0 -6
- package/lib/src/utils/natural-numbers.js +0 -6
- package/lib/src/utils/prettier.js +0 -10
- package/lib/src/utils/question.js +0 -19
- package/lib/src/utils/render-attributes.js +0 -19
- package/lib/src/utils/sleep.js +0 -4
- package/lib/src/utils/translate.js +0 -6
- package/lib/src/utils/url-with-new-params.js +0 -5
- package/lib/src/utils/utils.js +0 -16
- package/lib/src/utils/walk.js +0 -23
- package/lib/src/vitest.config.js +0 -20
- package/lib/templates/collection.js +0 -12
- package/lib/templates/form.js +0 -57
- package/lib/templates/jdd-component.js +0 -39
- package/lib/templates/list.js +0 -139
- package/lib/templates/long-running-process.js +0 -60
- package/lib/templates/multiform.js +0 -55
- package/lib/templates/page.js +0 -23
- package/lib/templates/post.js +0 -22
- package/lib/templates/redirect.js +0 -23
- package/lib/templates/route-test.js +0 -54
- package/lib/templates/stateful-page.js +0 -66
- package/lib/templates/templates.js +0 -21
- package/lib/test_utils/locator_is_visible.js +0 -11
- package/lib/utils/assert-throws.js +0 -17
- package/lib/utils/base64.js +0 -7
- package/lib/utils/browser-creator.js +0 -10
- package/lib/utils/escape-url-params.js +0 -14
- package/lib/utils/exec.js +0 -22
- package/lib/utils/extract-fields-from-collection.js +0 -26
- package/lib/utils/format-external-url.js +0 -11
- package/lib/utils/import-path.js +0 -16
- package/lib/utils/input-wrapper.js +0 -15
- package/lib/utils/list-collections.js +0 -13
- package/lib/utils/make-slug.js +0 -6
- package/lib/utils/natural-numbers.js +0 -6
- package/lib/utils/prettier.js +0 -10
- package/lib/utils/question.js +0 -19
- package/lib/utils/render-attributes.js +0 -19
- package/lib/utils/sleep.js +0 -4
- package/lib/utils/translate.js +0 -6
- package/lib/utils/url-with-new-params.js +0 -5
- package/lib/utils/utils.js +0 -16
- package/lib/utils/walk.js +0 -23
- package/lib/vitest.config.js +0 -22
package/lib/build.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { build, context } from "esbuild";
|
|
2
|
-
import { promises as fs } from "fs";
|
|
3
|
-
import { extname } from "path";
|
|
4
|
-
import * as chokidar from "chokidar";
|
|
5
|
-
import { default as glob } from "tiny-glob";
|
|
6
|
-
import { generate_css_includes } from "./find-css-includes.js";
|
|
7
|
-
import { sleep } from "./utils/sleep.js";
|
|
8
|
-
import { generateCollections } from "./generate-collections.js";
|
|
9
|
-
import { generateRoutes } from "./generate-routes.js";
|
|
10
|
-
import { generateComponents } from "./generate-components.js";
|
|
11
|
-
import { make_notifier } from "./notifier.js";
|
|
12
|
-
import getPort from "get-port";
|
|
13
|
-
import _locreq from "locreq";
|
|
14
|
-
const target_locreq = _locreq(process.cwd());
|
|
15
|
-
const generate_names = (function* generate_names() {
|
|
16
|
-
const base_name = "____unique_import_";
|
|
17
|
-
let count = 0;
|
|
18
|
-
while (true) {
|
|
19
|
-
yield `${base_name}${count}`;
|
|
20
|
-
count++;
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
async function get_notifier_port() {
|
|
24
|
-
return getPort({ port: 4000 });
|
|
25
|
-
}
|
|
26
|
-
async function write_notifier_config(watch, port) {
|
|
27
|
-
const config = { watch };
|
|
28
|
-
if (port) {
|
|
29
|
-
config.port = port;
|
|
30
|
-
}
|
|
31
|
-
await fs.writeFile(target_locreq.resolve("public/dist/notifier.json"), JSON.stringify(config));
|
|
32
|
-
}
|
|
33
|
-
async function build_ts() {
|
|
34
|
-
await Promise.all([
|
|
35
|
-
generateCollections(),
|
|
36
|
-
generateRoutes(),
|
|
37
|
-
generateComponents(),
|
|
38
|
-
]);
|
|
39
|
-
const entryPoints = (await glob("./src/back/**/*.{ts,tsx}")).filter((path) => !path.includes(".#"));
|
|
40
|
-
try {
|
|
41
|
-
await build({
|
|
42
|
-
entryPoints,
|
|
43
|
-
sourcemap: true,
|
|
44
|
-
bundle: false,
|
|
45
|
-
jsxFactory: "TempstreamJSX.createElement",
|
|
46
|
-
outdir: "./dist/back",
|
|
47
|
-
logLevel: "info",
|
|
48
|
-
platform: "node",
|
|
49
|
-
target: "es2022",
|
|
50
|
-
format: "esm",
|
|
51
|
-
plugins: [
|
|
52
|
-
{
|
|
53
|
-
name: "remove-named-imports",
|
|
54
|
-
setup(build) {
|
|
55
|
-
build.onLoad({ filter: /.*/ }, async ({ path }) => {
|
|
56
|
-
const named_and_default_regex = /^import\s+((\S+),\s+)?({\s*[^}]+})\s+from\s+("[^"]+");\s*$/gm;
|
|
57
|
-
const old_content = await fs.readFile(path, "utf-8");
|
|
58
|
-
const contents = old_content.replace(named_and_default_regex, (_, default_import_name, __, all_named, module_path) => {
|
|
59
|
-
/* eslint-disable */
|
|
60
|
-
const new_name = generate_names.next().value;
|
|
61
|
-
const result = `import * as ${new_name} from ${module_path}${default_import_name
|
|
62
|
-
? `; const ${default_import_name.replace(",", "")} = ${new_name}.default || ${new_name};`
|
|
63
|
-
: ""};` +
|
|
64
|
-
all_named
|
|
65
|
-
.match(/[a-zA-Z_$][^,}]+/g)
|
|
66
|
-
.map((importname) => {
|
|
67
|
-
if (importname.startsWith("default as")) {
|
|
68
|
-
return `const ${importname.replace("default as ", "")} = ${new_name}?.default || ${new_name};`;
|
|
69
|
-
}
|
|
70
|
-
if (importname.match(/([^{]*)\sas\s([^}]*)/)) {
|
|
71
|
-
// is "import {asdfas as somethong_else}
|
|
72
|
-
const [_, original, named] = importname.match(/([^{]*)\sas\s([^}]*)/);
|
|
73
|
-
return `const named = ${new_name}?.default.${original} || ${new_name}?.${original}`;
|
|
74
|
-
}
|
|
75
|
-
return `const ${importname} = ${new_name}?.default?.${importname} || ${new_name}?.${importname};`;
|
|
76
|
-
})
|
|
77
|
-
.join(" ");
|
|
78
|
-
return result;
|
|
79
|
-
/* eslint-enable */
|
|
80
|
-
});
|
|
81
|
-
return {
|
|
82
|
-
contents,
|
|
83
|
-
loader: extname(path) === ".tsx" ? "tsx" : "ts",
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
93
|
-
console.error(e.message);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function complex_build(watch) {
|
|
97
|
-
const loader = Object.fromEntries(["png", "svg", "jpg", "gif", "jpeg", "otf", "ttf"].map((ext) => ["." + ext, "file"]));
|
|
98
|
-
let css_build = await context({
|
|
99
|
-
entryPoints: ["./src/main.css"],
|
|
100
|
-
sourcemap: true,
|
|
101
|
-
bundle: true,
|
|
102
|
-
outdir: "./public/dist",
|
|
103
|
-
logLevel: "info",
|
|
104
|
-
// plugins: [sassPlugin()],
|
|
105
|
-
loader,
|
|
106
|
-
});
|
|
107
|
-
let ongoing_ts = false;
|
|
108
|
-
let ongoing_css = false;
|
|
109
|
-
let ongoing_ts_promise = null;
|
|
110
|
-
if (watch) {
|
|
111
|
-
const watcher = chokidar.watch("src", { ignoreInitial: true });
|
|
112
|
-
const port = await get_notifier_port();
|
|
113
|
-
const notifier = make_notifier(port);
|
|
114
|
-
await write_notifier_config(watch, port);
|
|
115
|
-
watcher.on("all", async (_, path) => {
|
|
116
|
-
if (!css_build)
|
|
117
|
-
return;
|
|
118
|
-
if (path.includes(".#"))
|
|
119
|
-
return;
|
|
120
|
-
if (path.endsWith(".css") && !path.endsWith("/includes.css")) {
|
|
121
|
-
if (ongoing_css) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
ongoing_css = true;
|
|
125
|
-
// refresh the list of all css files in includes.css
|
|
126
|
-
await generate_css_includes();
|
|
127
|
-
try {
|
|
128
|
-
await css_build?.rebuild?.();
|
|
129
|
-
console.log(`Built main.css [on ${path}]`);
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
133
|
-
console.error(e.message);
|
|
134
|
-
await sleep(200);
|
|
135
|
-
css_build
|
|
136
|
-
?.rebuild?.()
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
138
|
-
.catch((e) => console.error(e?.message));
|
|
139
|
-
}
|
|
140
|
-
if (ongoing_ts_promise) {
|
|
141
|
-
await ongoing_ts_promise;
|
|
142
|
-
}
|
|
143
|
-
notifier("css");
|
|
144
|
-
ongoing_css = false;
|
|
145
|
-
}
|
|
146
|
-
if ((path.endsWith(".ts") || path.endsWith(".tsx")) &&
|
|
147
|
-
!path.endsWith("src/back/collections/collections.ts") &&
|
|
148
|
-
!path.endsWith("src/back/routes/routes.ts") &&
|
|
149
|
-
!path.endsWith("src/back/routes/urls.ts")) {
|
|
150
|
-
if (ongoing_ts) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
ongoing_ts = true;
|
|
154
|
-
ongoing_ts_promise = build_ts();
|
|
155
|
-
await ongoing_ts_promise;
|
|
156
|
-
notifier("ts");
|
|
157
|
-
ongoing_ts_promise = null;
|
|
158
|
-
console.log(`Finished TS build [on ${path}]`);
|
|
159
|
-
ongoing_ts = false;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
await write_notifier_config(watch);
|
|
165
|
-
}
|
|
166
|
-
await generate_css_includes();
|
|
167
|
-
await Promise.all([css_build.rebuild(), build_ts()]);
|
|
168
|
-
watch && css_build?.rebuild?.();
|
|
169
|
-
}
|
|
170
|
-
export async function buildProject({ watch, }) {
|
|
171
|
-
try {
|
|
172
|
-
await build({
|
|
173
|
-
entryPoints: ["./src/front/index.ts"],
|
|
174
|
-
sourcemap: true,
|
|
175
|
-
outfile: "./public/dist/bundle.js",
|
|
176
|
-
logLevel: "info",
|
|
177
|
-
bundle: true,
|
|
178
|
-
});
|
|
179
|
-
await complex_build(watch);
|
|
180
|
-
}
|
|
181
|
-
catch (e) {
|
|
182
|
-
console.log("CAUGHT!");
|
|
183
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
184
|
-
console.error(e.message);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
//# sourceMappingURL=build.js.map
|
package/lib/cli.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { addCollection } from "./add-collection.js";
|
|
3
|
-
import { addJDDComponent } from "./add-jdd-component.js";
|
|
4
|
-
import { addRoute } from "./add-route.js";
|
|
5
|
-
import { buildProject } from "./build.js";
|
|
6
|
-
import { generate_css_includes } from "./find-css-includes.js";
|
|
7
|
-
import { generateCollections } from "./generate-collections.js";
|
|
8
|
-
import { generateComponents } from "./generate-components.js";
|
|
9
|
-
import { generateRoutes } from "./generate-routes.js";
|
|
10
|
-
import { makeEnv } from "./make-env.js";
|
|
11
|
-
import yargs from "yargs/yargs";
|
|
12
|
-
const actions = {
|
|
13
|
-
"add-collection": addCollection,
|
|
14
|
-
"add-route": addRoute,
|
|
15
|
-
"generate-collections": generateCollections,
|
|
16
|
-
"generate-components": generateComponents,
|
|
17
|
-
"generate-routes": generateRoutes,
|
|
18
|
-
"generate-css-includes": generate_css_includes,
|
|
19
|
-
build: buildProject,
|
|
20
|
-
default: async function () {
|
|
21
|
-
console.log("Usage: `sealscript <action>`");
|
|
22
|
-
console.log(`Available actions: ${Object.keys(actions)
|
|
23
|
-
.filter((e) => e != "default")
|
|
24
|
-
.join(", ")}`);
|
|
25
|
-
},
|
|
26
|
-
"make-env": makeEnv,
|
|
27
|
-
"add-component": addJDDComponent,
|
|
28
|
-
};
|
|
29
|
-
void (async function () {
|
|
30
|
-
const action = process.argv.at(2);
|
|
31
|
-
actions;
|
|
32
|
-
const fn = actions[action || "default"] || actions.default;
|
|
33
|
-
await fn(yargs().argv);
|
|
34
|
-
})();
|
|
35
|
-
//# sourceMappingURL=cli.js.map
|
package/lib/components/tabs.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
function name_to_id(str) {
|
|
3
|
-
return str.replace(/\W/g, "-");
|
|
4
|
-
}
|
|
5
|
-
const style = (hide_tabs_width) => /* HTML */ `<style>
|
|
6
|
-
.tab-label {
|
|
7
|
-
height: 45px;
|
|
8
|
-
line-height: 45px;
|
|
9
|
-
padding: 0 45px;
|
|
10
|
-
display: block;
|
|
11
|
-
float: left;
|
|
12
|
-
box-sizing: border-box;
|
|
13
|
-
border-bottom: 3px solid transparent;
|
|
14
|
-
cursor: pointer;
|
|
15
|
-
font-size: 18px;
|
|
16
|
-
-webkit-user-select: none;
|
|
17
|
-
user-select: none;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@media screen and (max-width: ${hide_tabs_width}px) {
|
|
21
|
-
.tab-label {
|
|
22
|
-
display: none;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.tab-label--mobile {
|
|
27
|
-
line-height: unset;
|
|
28
|
-
padding-top: 30px;
|
|
29
|
-
padding-left: 0;
|
|
30
|
-
pointer-events: none;
|
|
31
|
-
padding-bottom: 30px;
|
|
32
|
-
color: $font-graphite;
|
|
33
|
-
border-bottom: 2px solid $font-primary;
|
|
34
|
-
display: none;
|
|
35
|
-
@media screen and (max-width: ${hide_tabs_width}px) {
|
|
36
|
-
display: block;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.tab-content {
|
|
41
|
-
padding-top: 30px;
|
|
42
|
-
clear: both;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@media screen and (max-width: ${hide_tabs_width}px) {
|
|
46
|
-
.tab-content {
|
|
47
|
-
display: block !important;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
</style>`;
|
|
51
|
-
export function tabs(tabs, selected_tab_style = "font-weight: bold;", selected_index = 0, hide_tabs_width = 0) {
|
|
52
|
-
return /* HTML */ tempstream `${style(hide_tabs_width)}
|
|
53
|
-
${Object.keys(tabs)
|
|
54
|
-
.map((tab_title, index) => {
|
|
55
|
-
const id = name_to_id(tab_title);
|
|
56
|
-
return /* HTML */ `<input
|
|
57
|
-
type="radio"
|
|
58
|
-
name="tabs"
|
|
59
|
-
id="${id}"
|
|
60
|
-
class="tab-radio--${id}"
|
|
61
|
-
style="display: none"
|
|
62
|
-
${selected_index == index ? "checked" : ""}
|
|
63
|
-
/>
|
|
64
|
-
<label class="tab-label tab-label--${id}" for="${id}">
|
|
65
|
-
${tab_title}
|
|
66
|
-
</label>`;
|
|
67
|
-
})
|
|
68
|
-
.join("\n")}
|
|
69
|
-
${Object.entries(tabs).map(([title, content]) => {
|
|
70
|
-
const id = name_to_id(title);
|
|
71
|
-
return /* HTML */ tempstream `<div class="tab-label tab-label--mobile">
|
|
72
|
-
${title}
|
|
73
|
-
</div>
|
|
74
|
-
<div class="tab-content tab-content--${id}">${content}</div>
|
|
75
|
-
<style>
|
|
76
|
-
.tab-radio--${id} ~ .tab-content--${id} {
|
|
77
|
-
display:none;
|
|
78
|
-
}
|
|
79
|
-
.tab-radio--${id}:checked ~ .tab-content--${id} {
|
|
80
|
-
display:block;
|
|
81
|
-
}
|
|
82
|
-
.tab-radio--${id}:checked ~ label.tab-label--${id} {
|
|
83
|
-
${selected_tab_style}
|
|
84
|
-
}
|
|
85
|
-
</style>`;
|
|
86
|
-
})}`;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=tabs.js.map
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { makeSlug } from "../utils/utils.js";
|
|
3
|
-
export function toggleModal(options) {
|
|
4
|
-
const { contentWrapped, contentUnwrapped, name } = options;
|
|
5
|
-
const id = makeSlug(name);
|
|
6
|
-
return tempstream /* HTML */ `<style>
|
|
7
|
-
.toggle-modal__wrapped {
|
|
8
|
-
display: none;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@media (max-width: 960px) {
|
|
12
|
-
.toggle-modal__wrapped {
|
|
13
|
-
display: block;
|
|
14
|
-
}
|
|
15
|
-
.toggle-modal__unwrapped {
|
|
16
|
-
display: none;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#${id} {
|
|
20
|
-
display: none;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#${id}:checked ~ .toggle-modal__wrapped {
|
|
24
|
-
display: none;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
#${id}:checked ~ .toggle-modal__unwrapped {
|
|
28
|
-
display: block;
|
|
29
|
-
position: fixed;
|
|
30
|
-
height: 100vh;
|
|
31
|
-
width: 100vw;
|
|
32
|
-
top: 0;
|
|
33
|
-
left: 0;
|
|
34
|
-
background-color: white;
|
|
35
|
-
z-index: 99;
|
|
36
|
-
overflow-y: scroll;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
</style>
|
|
40
|
-
<div class="toggle-modal toggle-modal--${id}">
|
|
41
|
-
<input id="${id}" name="${id}" type="checkbox" autocomplete="off" />
|
|
42
|
-
<div class="toggle-modal__wrapped">${contentWrapped(id)}</div>
|
|
43
|
-
<div class="toggle-modal__unwrapped">${contentUnwrapped(id)}</div>
|
|
44
|
-
</div>`;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=toggle-modal.js.map
|
package/lib/example.test.js
DELETED
package/lib/find-css-includes.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
import _locreq from "locreq";
|
|
3
|
-
import { relative } from "path";
|
|
4
|
-
import { walkDir } from "./utils/walk.js";
|
|
5
|
-
const target_locreq = _locreq(process.cwd());
|
|
6
|
-
export async function generate_css_includes() {
|
|
7
|
-
const files = await Promise.all((await walkDir(target_locreq.resolve("src/")))
|
|
8
|
-
.filter((f) => f.endsWith(".css") &&
|
|
9
|
-
!f.endsWith("/main.css") &&
|
|
10
|
-
!f.endsWith("\\main.css") &&
|
|
11
|
-
!f.endsWith("/includes.css") &&
|
|
12
|
-
!f.endsWith("\\includes.css") &&
|
|
13
|
-
!f.includes(".#"))
|
|
14
|
-
.map((fullpath) => relative(target_locreq.resolve("src/"), fullpath)));
|
|
15
|
-
await fs.writeFile(target_locreq.resolve("src/includes.css"), `/* DO NOT EDIT! This file is generated automaticaly with npx sealgen generate-css-includes */
|
|
16
|
-
|
|
17
|
-
@import "../node_modules/@sealcode/sealgen/src/forms/forms.css";
|
|
18
|
-
${files.map((path) => `@import "${path.replaceAll("\\", "/")}";`).join("\n")}
|
|
19
|
-
`);
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log("Successfuly generated new src/includes.css file");
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=find-css-includes.js.map
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { hasShape, predicates } from "@sealcode/ts-predicates";
|
|
2
|
-
import qs from "qs";
|
|
3
|
-
import { tempstream } from "tempstream";
|
|
4
|
-
import { Controls, Fields } from "../../index.js";
|
|
5
|
-
import { FormFieldControl } from "./form-field-control.js";
|
|
6
|
-
export function UnboundControl(controlClass, arbitrary_field_name, params) {
|
|
7
|
-
return [controlClass, arbitrary_field_name, params];
|
|
8
|
-
}
|
|
9
|
-
export class StructuredArray extends FormFieldControl {
|
|
10
|
-
constructor(field, item_controls) {
|
|
11
|
-
super([field]);
|
|
12
|
-
this.field = field;
|
|
13
|
-
this.item_controls = item_controls;
|
|
14
|
-
}
|
|
15
|
-
getFrameID() {
|
|
16
|
-
return `array-frame-${this.field.name}`;
|
|
17
|
-
}
|
|
18
|
-
getInnerFormID() {
|
|
19
|
-
return this.getFrameID() + "-form";
|
|
20
|
-
}
|
|
21
|
-
getActionURL(form_id, action) {
|
|
22
|
-
return `${this.getFrameID()}${form_id || action ? "?" : ""}${qs.stringify({ form_id, action })}`;
|
|
23
|
-
}
|
|
24
|
-
async getDefaultItemBody() {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
makeSubfield(_field_name) {
|
|
28
|
-
const fields = this;
|
|
29
|
-
return new Fields.SimpleFormField(false);
|
|
30
|
-
}
|
|
31
|
-
async renderItemControl(ctx, form_id, control, item, index) {
|
|
32
|
-
const fctx = {
|
|
33
|
-
ctx,
|
|
34
|
-
data: {},
|
|
35
|
-
messages: [],
|
|
36
|
-
field_name_prefix: "",
|
|
37
|
-
form_id,
|
|
38
|
-
validate: false,
|
|
39
|
-
};
|
|
40
|
-
if (Array.isArray(control)) {
|
|
41
|
-
const [constructor, field_name, params] = control;
|
|
42
|
-
const field = this.makeSubfield(field_name);
|
|
43
|
-
if (!field) {
|
|
44
|
-
console.warn(`makeSubfield returned null for field ${field_name}`);
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
|
-
await field.init(`${this.field.name}[data][${index}][${field_name}]`);
|
|
48
|
-
const hidden_shadow = new Controls.Derived([field], async (values, { inner_form_id, field_name }) => /* HTML */ `<input
|
|
49
|
-
name="${field_name}"
|
|
50
|
-
type="hidden"
|
|
51
|
-
value="${values[field_name] || ""}"
|
|
52
|
-
form="${inner_form_id}"
|
|
53
|
-
/>`, async () => ({
|
|
54
|
-
inner_form_id: this.getInnerFormID(),
|
|
55
|
-
field_name: field.name,
|
|
56
|
-
}));
|
|
57
|
-
return tempstream `${new constructor(field, params).render({
|
|
58
|
-
...fctx,
|
|
59
|
-
data: { [field.name]: item[field_name] },
|
|
60
|
-
})}${hidden_shadow.render({
|
|
61
|
-
...fctx,
|
|
62
|
-
data: { [field.name]: item[field_name] },
|
|
63
|
-
form_id: this.getInnerFormID(),
|
|
64
|
-
})}`;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return control.render(fctx);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async renderItem(ctx, form_id, item, index) {
|
|
71
|
-
return tempstream /* HTML */ `<div>
|
|
72
|
-
${this.item_controls.map((control) => this.renderItemControl(ctx, form_id, control, item, index))}
|
|
73
|
-
<input
|
|
74
|
-
type="submit"
|
|
75
|
-
value="remove"
|
|
76
|
-
form="${this.getInnerFormID()}"
|
|
77
|
-
formaction="${this.getActionURL(form_id, {
|
|
78
|
-
remove: index,
|
|
79
|
-
})}"
|
|
80
|
-
/>
|
|
81
|
-
</div>`;
|
|
82
|
-
}
|
|
83
|
-
async getItems(ctx, raw_values) {
|
|
84
|
-
return (await this.field.getValue(ctx, raw_values)).parsed;
|
|
85
|
-
}
|
|
86
|
-
async _render(ctx, form_id, raw_values) {
|
|
87
|
-
const items = await this.getItems(ctx, raw_values);
|
|
88
|
-
return tempstream /* HTML */ `<turbo-frame id="${this.getFrameID()}">
|
|
89
|
-
Reverse Single Reference
|
|
90
|
-
${items.map((item, index) => this.renderItem(ctx, form_id, item, index))}
|
|
91
|
-
<form id="${this.getInnerFormID()}" method="POST"></form>
|
|
92
|
-
<input
|
|
93
|
-
type="submit"
|
|
94
|
-
value="add"
|
|
95
|
-
form="${this.getInnerFormID()}"
|
|
96
|
-
formaction="${this.getActionURL(form_id, {
|
|
97
|
-
insert: { index: items.length, value: {} },
|
|
98
|
-
})}"
|
|
99
|
-
/>
|
|
100
|
-
</turbo-frame>`;
|
|
101
|
-
}
|
|
102
|
-
render(fctx) {
|
|
103
|
-
return this._render(fctx.ctx, fctx.form_id, fctx.data);
|
|
104
|
-
}
|
|
105
|
-
async getTargetItemID(ctx) {
|
|
106
|
-
return ctx.params.id;
|
|
107
|
-
}
|
|
108
|
-
mount(router) {
|
|
109
|
-
console.log("mounting!", this.getActionURL());
|
|
110
|
-
router.post(this.getActionURL(), async (ctx) => {
|
|
111
|
-
let form_id = ctx.query.form_id;
|
|
112
|
-
if (typeof form_id != "string") {
|
|
113
|
-
throw new Error("Missing form_id query param");
|
|
114
|
-
}
|
|
115
|
-
const item = await this.field.sealious_field.collection.getByID(ctx.$context, await this.getTargetItemID(ctx));
|
|
116
|
-
if (!hasShape({ action: predicates.object }, ctx.$body)) {
|
|
117
|
-
throw new Error("Missing action param");
|
|
118
|
-
}
|
|
119
|
-
const field_data = ctx.$body[this.field.name] || { data: [] };
|
|
120
|
-
console.log({ action: field_data });
|
|
121
|
-
if (!hasShape({
|
|
122
|
-
data: predicates.array(this.field.sealious_field.value_predicate),
|
|
123
|
-
}, field_data)) {
|
|
124
|
-
throw new Error("missing data atribute in action description");
|
|
125
|
-
}
|
|
126
|
-
item.set(this.field.name, {
|
|
127
|
-
...ctx.$body.action,
|
|
128
|
-
data: field_data.data || [],
|
|
129
|
-
});
|
|
130
|
-
console.log("ACTION", {
|
|
131
|
-
...ctx.$body.action,
|
|
132
|
-
data: field_data.data || [],
|
|
133
|
-
});
|
|
134
|
-
await item.save(ctx.$context);
|
|
135
|
-
console.log(await item.getDecodedBody(ctx.$context, {}));
|
|
136
|
-
ctx.body = this._render(ctx, form_id, await item.getDecodedBody(ctx.$context, {}));
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
//# sourceMappingURL=array.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SimpleInput } from "./simple-input.js";
|
|
2
|
-
export class Autocomplete extends SimpleInput {
|
|
3
|
-
constructor(field, options) {
|
|
4
|
-
super(field);
|
|
5
|
-
this.field = field;
|
|
6
|
-
this.options = options;
|
|
7
|
-
}
|
|
8
|
-
getListID() {
|
|
9
|
-
return this.getID() + "_list";
|
|
10
|
-
}
|
|
11
|
-
async getInputAttributes(fctx) {
|
|
12
|
-
return {
|
|
13
|
-
...(await super.getInputAttributes(fctx)),
|
|
14
|
-
list: this.getListID(),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
async postInput(ctx) {
|
|
18
|
-
return /* HTML */ `<datalist id="${this.getListID()}">
|
|
19
|
-
${(await this.field.generateOptions(ctx)).map(({ value }) => /* HTML */ `<option>${value}</option>`)}
|
|
20
|
-
</datalist>`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { FormFieldControl } from "./form-field-control.js";
|
|
3
|
-
export class BigRadioGroup extends FormFieldControl {
|
|
4
|
-
constructor(field, options) {
|
|
5
|
-
super([field]);
|
|
6
|
-
this.field = field;
|
|
7
|
-
this.options = options;
|
|
8
|
-
}
|
|
9
|
-
async render(fctx) {
|
|
10
|
-
const { raw: current_value } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
11
|
-
return tempstream /* HTML */ `<div class="bigradios">
|
|
12
|
-
${Object.entries(this.options).map(([key, { description }]) => {
|
|
13
|
-
const id = `${this.field.name}-radio-${key}`;
|
|
14
|
-
return tempstream /* HTML */ `<input
|
|
15
|
-
type="radio"
|
|
16
|
-
name="${this.field.name}"
|
|
17
|
-
value="${key}"
|
|
18
|
-
id="${id}"
|
|
19
|
-
style="display: none"
|
|
20
|
-
${fctx.form_id ? `form=${fctx.form_id}` : ""}
|
|
21
|
-
${this.field.required ? "required" : ""}
|
|
22
|
-
${key == current_value ? "checked" : ""}
|
|
23
|
-
/>
|
|
24
|
-
<div class="bigradio">
|
|
25
|
-
${typeof description == "function"
|
|
26
|
-
? description(fctx)
|
|
27
|
-
: description}
|
|
28
|
-
<label class="bigradio__cta" for="${id}">Wybierz</label>
|
|
29
|
-
</div>`;
|
|
30
|
-
})}
|
|
31
|
-
</div>`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=big-radio-group.js.map
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ProxyFormField } from "../fields/proxy-field.js";
|
|
2
|
-
import { CheckboxWithValue } from "./checkbox.js";
|
|
3
|
-
import { FieldGroup, FormFieldControl } from "./controls.js";
|
|
4
|
-
export class CheckboxGroup extends FormFieldControl {
|
|
5
|
-
constructor(field, options = {}) {
|
|
6
|
-
super([field]);
|
|
7
|
-
this.field = field;
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
wrapGroup(fctx, checkboxes) {
|
|
11
|
-
return new FieldGroup(checkboxes, {
|
|
12
|
-
label: this.options.label,
|
|
13
|
-
classes: [
|
|
14
|
-
...(this.options.classes || []),
|
|
15
|
-
"field-group--checkboxes",
|
|
16
|
-
],
|
|
17
|
-
}).render(fctx);
|
|
18
|
-
}
|
|
19
|
-
async render(fctx) {
|
|
20
|
-
const { parsed: values } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
21
|
-
const checkboxes = this.field.options.map((option) => new CheckboxWithValue(new ProxyFormField(false, this.field.name, false, values.includes(option)), {
|
|
22
|
-
id: this.field.name + "__" + option,
|
|
23
|
-
label: (this.options.checkboxNameToLabel ||
|
|
24
|
-
((s) => s))(option),
|
|
25
|
-
}, option));
|
|
26
|
-
return this.wrapGroup(fctx, checkboxes);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=checkbox-group.js.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Tickable } from "./tickable.js";
|
|
2
|
-
export class Checkbox extends Tickable {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.type = "checkbox";
|
|
6
|
-
}
|
|
7
|
-
isChecked(_ctx, _data, value) {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
getValueAttribute() {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class CheckboxWithValue extends Checkbox {
|
|
15
|
-
constructor(field, options, value) {
|
|
16
|
-
super(field, options);
|
|
17
|
-
this.field = field;
|
|
18
|
-
this.value = value;
|
|
19
|
-
}
|
|
20
|
-
getValueAttribute() {
|
|
21
|
-
return this.value;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=checkbox.js.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { is, predicates } from "@sealcode/ts-predicates";
|
|
2
|
-
import { tempstream } from "tempstream";
|
|
3
|
-
import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper.js";
|
|
4
|
-
import { FormFieldControl } from "./controls.js";
|
|
5
|
-
export class CheckboxedListInput extends FormFieldControl {
|
|
6
|
-
constructor(field, options = { label: field.name }) {
|
|
7
|
-
super([field]);
|
|
8
|
-
this.field = field;
|
|
9
|
-
this.options = options;
|
|
10
|
-
}
|
|
11
|
-
async render(fctx) {
|
|
12
|
-
const { parsed: pickedValues } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
13
|
-
if (!is(pickedValues, predicates.array(predicates.string))) {
|
|
14
|
-
throw new Error("picked values is not an array of strings");
|
|
15
|
-
}
|
|
16
|
-
const [options, isVisible] = await Promise.all([
|
|
17
|
-
this.field.generateOptions(fctx.ctx),
|
|
18
|
-
this.field.isVisible(fctx.ctx),
|
|
19
|
-
]);
|
|
20
|
-
const { name, required } = this.field;
|
|
21
|
-
return tempstream /* HTML */ `${isVisible
|
|
22
|
-
? Object.entries(options).map(([value, text]) => inputWrapper([name, getRequiredClass(required)],
|
|
23
|
-
/* HTML */ `
|
|
24
|
-
<input
|
|
25
|
-
type="checkbox"
|
|
26
|
-
id="${name}.${value}"
|
|
27
|
-
name="${name}.${value}"
|
|
28
|
-
${pickedValues.includes(value) ? "checked" : ""}
|
|
29
|
-
/>
|
|
30
|
-
<label for="${name}.${value}">${text}</label>
|
|
31
|
-
`))
|
|
32
|
-
: ""}`;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=checkboxed-list-input.js.map
|