@sealcode/sealgen 0.8.52 → 0.8.53

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.
Files changed (90) hide show
  1. package/@types/forms/controls/array.d.ts +1 -1
  2. package/@types/forms/controls/checkbox-group.d.ts +1 -1
  3. package/@types/forms/controls/collapsible-field-group.d.ts +1 -1
  4. package/@types/forms/controls/derived-frame.d.ts +1 -0
  5. package/@types/forms/controls/dropdown.d.ts +2 -2
  6. package/@types/forms/controls/form-field-control.d.ts +1 -1
  7. package/@types/forms/controls/html.d.ts +1 -1
  8. package/@types/forms/controls/multiple-files.d.ts +1 -1
  9. package/@types/forms/controls/number.d.ts +1 -1
  10. package/@types/forms/controls/simple-input.d.ts +1 -1
  11. package/@types/forms/controls/tickable.d.ts +1 -1
  12. package/@types/forms/fields/field.d.ts +6 -6
  13. package/@types/forms/fields/file.d.ts +1 -1
  14. package/@types/forms/form.d.ts +7 -7
  15. package/@types/index.d.ts +1 -0
  16. package/@types/page/list.d.ts +13 -17
  17. package/@types/page/mountable-with-fields.d.ts +2 -2
  18. package/@types/page/props-parser.d.ts +1 -1
  19. package/@types/page/sealious-list.d.ts +18 -0
  20. package/@types/utils/utils.d.ts +3 -3
  21. package/lib/add-collection.js +7 -7
  22. package/lib/add-route.js +7 -7
  23. package/lib/add-route.test.js +4 -4
  24. package/lib/build.js +14 -10
  25. package/lib/components/components.js +5 -1
  26. package/lib/components/tabs.js +2 -2
  27. package/lib/components/toggle-modal.js +2 -2
  28. package/lib/find-scss-includes.js +3 -3
  29. package/lib/forms/controls/array.js +5 -5
  30. package/lib/forms/controls/big-radio-group.js +2 -2
  31. package/lib/forms/controls/checkboxed-list-input.js +3 -3
  32. package/lib/forms/controls/collapsible-field-group.js +1 -1
  33. package/lib/forms/controls/controls.js +5 -1
  34. package/lib/forms/controls/derived-frame.js +3 -3
  35. package/lib/forms/controls/derived.js +2 -2
  36. package/lib/forms/controls/dropdown.js +2 -2
  37. package/lib/forms/controls/editable-collection-subset.js +3 -3
  38. package/lib/forms/controls/field-group.js +1 -1
  39. package/lib/forms/controls/file.js +1 -1
  40. package/lib/forms/controls/hidden-input.js +1 -1
  41. package/lib/forms/controls/multiple-files.js +5 -5
  42. package/lib/forms/controls/multiple-photos.js +1 -1
  43. package/lib/forms/controls/photo.js +1 -1
  44. package/lib/forms/controls/simple-input.js +2 -2
  45. package/lib/forms/controls/tickable.js +3 -3
  46. package/lib/forms/fields/boolean.js +3 -3
  47. package/lib/forms/fields/checkboxed-list.js +3 -3
  48. package/lib/forms/fields/enum-multiple.js +3 -3
  49. package/lib/forms/fields/enum.js +2 -2
  50. package/lib/forms/fields/field.js +6 -2
  51. package/lib/forms/fields/file.js +6 -6
  52. package/lib/forms/fields/number.js +5 -5
  53. package/lib/forms/fields/pick-from-list.js +1 -1
  54. package/lib/forms/fields/regexp.js +2 -2
  55. package/lib/forms/fields/simple-form-field.js +4 -4
  56. package/lib/forms/form.js +9 -9
  57. package/lib/forms/form.test.js +12 -12
  58. package/lib/forms/multiform.js +5 -5
  59. package/lib/forms/multiform.test.js +26 -26
  60. package/lib/generate-collections.js +8 -4
  61. package/lib/generate-routes.js +12 -8
  62. package/lib/index.js +6 -1
  63. package/lib/make-env.js +1 -1
  64. package/lib/make-hidden-inputs.js +3 -3
  65. package/lib/page/list.js +66 -53
  66. package/lib/page/mountable-with-fields.js +2 -2
  67. package/lib/page/page.js +1 -1
  68. package/lib/page/sealious-list.js +53 -0
  69. package/lib/page/stateful-page.js +9 -9
  70. package/lib/templates/form.js +1 -1
  71. package/lib/templates/list.js +9 -8
  72. package/lib/templates/multiform.js +1 -1
  73. package/lib/templates/page.js +1 -1
  74. package/lib/templates/route-test.js +1 -1
  75. package/lib/templates/stateful-page.js +1 -1
  76. package/lib/test_utils/locator_is_visible.js +1 -1
  77. package/lib/utils/exec.js +1 -1
  78. package/lib/utils/import-path.js +2 -2
  79. package/lib/utils/input-wrapper.js +1 -1
  80. package/lib/utils/list-collections.js +2 -2
  81. package/lib/utils/prettier.js +6 -2
  82. package/lib/utils/question.js +1 -1
  83. package/lib/utils/render-attributes.js +1 -1
  84. package/lib/utils/utils.js +5 -1
  85. package/lib/utils/walk.js +1 -1
  86. package/package.json +2 -2
  87. package/src/index.ts +1 -0
  88. package/src/page/list.ts +70 -67
  89. package/src/page/sealious-list.ts +76 -0
  90. package/src/templates/list.ts +7 -6
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -9,7 +9,7 @@ const form_control_1 = require("./form-control");
9
9
  class DerivedFrame extends derived_1.Derived {
10
10
  constructor(frame_name, fields, generateFrameContent,
11
11
  // "a" is to make it a valid DOM id
12
- frame_id = "a" + make_slug_1.makeSlug(frame_name)) {
12
+ frame_id = "a" + (0, make_slug_1.makeSlug)(frame_name)) {
13
13
  super(fields, async (values, consts) => /* HTML */ `<turbo-frame
14
14
  id="${consts.frame_id}"
15
15
  src="./${consts.frame_id}?${Object.entries({
@@ -29,7 +29,7 @@ class DerivedFrame extends derived_1.Derived {
29
29
  this.frame_id = frame_id;
30
30
  }
31
31
  renderBackendResponseFrame(_ctx, content) {
32
- return tempstream_1.tempstream /* HTML */ `<turbo-frame
32
+ return (0, tempstream_1.tempstream /* HTML */) `<turbo-frame
33
33
  id="${this.frame_id}"
34
34
  target="_top"
35
35
  >
@@ -39,7 +39,7 @@ class DerivedFrame extends derived_1.Derived {
39
39
  mount(router) {
40
40
  router.get(this.frame_id, async (ctx) => {
41
41
  const query = ctx.query;
42
- if (!ts_predicates_1.hasShape({
42
+ if (!(0, ts_predicates_1.hasShape)({
43
43
  field_name_prefix: ts_predicates_1.predicates.string,
44
44
  form_id: ts_predicates_1.predicates.string,
45
45
  validate: ts_predicates_1.predicates.string,
@@ -19,11 +19,11 @@ class Derived extends form_control_1.FormControl {
19
19
  }
20
20
  async render(fctx) {
21
21
  // the A makes it always a valid id, as it cannot start with a number
22
- const id = "A" + crypto_1.randomUUID();
22
+ const id = "A" + (0, crypto_1.randomUUID)();
23
23
  const consts = this.getConsts(fctx);
24
24
  const frontend_side_refresh_code = (values_code = "getValues()") => `render(${values_code}, consts)
25
25
  .then(result=>document.querySelector("#${id}").innerHTML=result)`;
26
- return tempstream_1.tempstream /* HTML */ `<div>
26
+ return (0, tempstream_1.tempstream /* HTML */) `<div>
27
27
  <script>
28
28
  (function () {
29
29
  const consts = ${"{" +
@@ -37,10 +37,10 @@ class FreeformDropdown extends simple_input_1.SimpleInput {
37
37
  }
38
38
  async renderInput(ctx, attributes_str, data) {
39
39
  const { parsed: picked_value } = await this.field.getValue(ctx, data);
40
- return /* HTML */ tempstream_1.tempstream `<select ${attributes_str}>
40
+ return /* HTML */ (0, tempstream_1.tempstream) `<select ${attributes_str}>
41
41
  ${
42
42
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
43
- Promise.resolve(this.generateOptions(ctx)).then((options) => options.map(({ value, label }) => `<option value="${sanitize_1.attribute(value)}" ${(value || "") == picked_value ? "selected" : ""}>${label}</option>`))}
43
+ Promise.resolve(this.generateOptions(ctx)).then((options) => options.map(({ value, label }) => `<option value="${(0, sanitize_1.attribute)(value)}" ${(value || "") == picked_value ? "selected" : ""}>${label}</option>`))}
44
44
  </select>`;
45
45
  }
46
46
  }
@@ -22,7 +22,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
22
22
  }
23
23
  async render(fctx) {
24
24
  const { parsed: values } = await this.field.getValue(fctx.ctx, fctx.data);
25
- return tempstream_1.tempstream /* HTML */ `<div>
25
+ return (0, tempstream_1.tempstream /* HTML */) `<div>
26
26
  <ul>
27
27
  ${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
28
28
  .filter(([value]) => (values || []).includes(value))
@@ -36,7 +36,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
36
36
  <input
37
37
  type="hidden"
38
38
  name="${this.field.name}"
39
- value="${sanitize_1.attribute(value)}"
39
+ value="${(0, sanitize_1.attribute)(value)}"
40
40
  />
41
41
  <input
42
42
  type="hidden"
@@ -57,7 +57,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
57
57
  <select name="${this.field.name}">
58
58
  ${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
59
59
  .filter(([value]) => !(values || []).includes(value))
60
- .map(([value, text]) => `<option value="${sanitize_1.attribute(value)}">${text}</option>`))}
60
+ .map(([value, text]) => `<option value="${(0, sanitize_1.attribute)(value)}">${text}</option>`))}
61
61
  </select>
62
62
  <input type="hidden" name="${this.actionname}" value="select" />
63
63
  <input
@@ -29,7 +29,7 @@ class FieldGroup extends form_field_control_1.FormFieldControl {
29
29
  }
30
30
  async render(fctx) {
31
31
  const { label, classes } = this.options;
32
- return tempstream_1.tempstream /* HTML */ `
32
+ return (0, tempstream_1.tempstream /* HTML */) `
33
33
  <div
34
34
  class="field-group ${(classes || []).join(" ")}"
35
35
  ${this.options.containerID
@@ -12,7 +12,7 @@ class File extends simple_input_1.SimpleInput {
12
12
  }
13
13
  async preInput(ctx, data) {
14
14
  const { parsed } = await this.field.getValue(ctx, data);
15
- return tempstream_1.tempstream /* HTML */ `${this.renderFilePreview(ctx, parsed.old)}
15
+ return (0, tempstream_1.tempstream /* HTML */) `${this.renderFilePreview(ctx, parsed.old)}
16
16
  <input
17
17
  type="hidden"
18
18
  name="${this.field.name}[old][id]"
@@ -11,7 +11,7 @@ class HiddenInput extends form_field_control_1.FormFieldControl {
11
11
  }
12
12
  async render(fctx) {
13
13
  const { raw } = await this.field.getValue(fctx.ctx, fctx.data);
14
- return tempstream_1.tempstream `<input type="hidden" name="${this.field.name}" value="${sanitize_1.attribute((raw || "").toString())}" form="${fctx.form_id}">`;
14
+ return (0, tempstream_1.tempstream) `<input type="hidden" name="${this.field.name}" value="${(0, sanitize_1.attribute)((raw || "").toString())}" form="${fctx.form_id}">`;
15
15
  }
16
16
  }
17
17
  exports.HiddenInput = HiddenInput;
@@ -26,7 +26,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
26
26
  });
27
27
  router.post(this.getFrameRelativeURL() + "/add", async (ctx) => {
28
28
  let files = ctx.$body.files;
29
- if (!files || !ts_predicates_1.is(files, ts_predicates_1.predicates.object)) {
29
+ if (!files || !(0, ts_predicates_1.is)(files, ts_predicates_1.predicates.object)) {
30
30
  ctx.body = "Missing files";
31
31
  return;
32
32
  }
@@ -60,7 +60,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
60
60
  return `A${this.field.name}__multiple-fields-control`;
61
61
  }
62
62
  renderFrame(ctx, content) {
63
- return tempstream_1.tempstream /* HTML */ `<turbo-frame
63
+ return (0, tempstream_1.tempstream /* HTML */) `<turbo-frame
64
64
  ${content ? "" : `src="./${this.getFrameRelativeURL()}"`}
65
65
  id="${this.getFrameID()}"
66
66
  target="_top"
@@ -94,7 +94,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
94
94
  return file.filename || "no filename";
95
95
  }
96
96
  async renderFileItem(fileItem, file) {
97
- return tempstream_1.tempstream /* HTML */ `<li class="file-list-item">
97
+ return (0, tempstream_1.tempstream /* HTML */) `<li class="file-list-item">
98
98
  <a
99
99
  class="file-list-item__preview"
100
100
  href="${file.getURL()}"
@@ -139,7 +139,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
139
139
  item,
140
140
  await this.extractFileFromItem(item),
141
141
  ]))).filter(([_, f]) => f !== null);
142
- return input_wrapper_1.inputWrapper(["multiple-files", this.field.name, ...this.getClassModifiers()], tempstream_1.tempstream /* HTML */ `
142
+ return (0, input_wrapper_1.inputWrapper)(["multiple-files", this.field.name, ...this.getClassModifiers()], (0, tempstream_1.tempstream /* HTML */) `
143
143
  <label>${this.options.label || this.field.name}</label>
144
144
  <ul class="multiple-files__list">
145
145
  ${files.map(([item, file]) => this.renderFileItem(item, file))}
@@ -150,7 +150,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
150
150
  enctype="multipart/form-data"
151
151
  data-turbo-frame="${this.getFrameID()}"
152
152
  >
153
- <input ${render_attributes_1.renderAttributes(this.getInputAttributes())} />
153
+ <input ${(0, render_attributes_1.renderAttributes)(this.getInputAttributes())} />
154
154
  <input
155
155
  type="submit"
156
156
  value="${this.options.uploadLabel || "Upload"}"
@@ -20,7 +20,7 @@ class MultiplePhotos extends multiple_files_1.MultipleFiles {
20
20
  if (!path) {
21
21
  return "missing file";
22
22
  }
23
- return tempstream_1.tempstream /* HTML */ `<li>
23
+ return (0, tempstream_1.tempstream /* HTML */) `<li>
24
24
  <a href="${file.getURL()}" data-turbo="false">
25
25
  ${this.imageRouter.image({
26
26
  path,
@@ -24,7 +24,7 @@ class Photo extends file_1.File {
24
24
  return empty_container;
25
25
  }
26
26
  const file = await sealious_1.File.fromID(ctx.$app, id);
27
- return tempstream_1.tempstream /* HTML */ `<div class="${class_name}">
27
+ return (0, tempstream_1.tempstream /* HTML */) `<div class="${class_name}">
28
28
  ${this.imageRouter.image({
29
29
  resolutions: [100],
30
30
  sizes_attr: "100px",
@@ -67,10 +67,10 @@ class SimpleInput extends controls_1.FormFieldControl {
67
67
  const label = this.getLabel();
68
68
  const type = this.getType();
69
69
  const { valid, message } = await this.field.getValue(fctx.ctx, fctx.data);
70
- return input_wrapper_1.inputWrapper([id, type, input_wrapper_1.getRequiredClass(this.field.required)], tempstream_1.tempstream /* HTML */ `
70
+ return (0, input_wrapper_1.inputWrapper)([id, type, (0, input_wrapper_1.getRequiredClass)(this.field.required)], (0, tempstream_1.tempstream /* HTML */) `
71
71
  ${label ? `<label for="${id}">${label}</label>` : ""}
72
72
  ${await this.preInput(fctx.ctx, fctx.data)}
73
- ${this.renderInput(fctx.ctx, render_attributes_1.renderAttributes(await this.getInputAttributes(fctx)), fctx.data)}
73
+ ${this.renderInput(fctx.ctx, (0, render_attributes_1.renderAttributes)(await this.getInputAttributes(fctx)), fctx.data)}
74
74
  ${this.postInput(fctx.ctx)}
75
75
  ${~valid && !this.options.hide_errors && fctx.validate
76
76
  ? `<div class="input__error">${message}</div>`
@@ -20,7 +20,7 @@ class Tickable extends controls_1.FormFieldControl {
20
20
  this.makeInputID(ctx, data, value),
21
21
  this.type,
22
22
  this.field.name.replaceAll(/\W/g, "-"),
23
- input_wrapper_1.getRequiredClass(this.field.required),
23
+ (0, input_wrapper_1.getRequiredClass)(this.field.required),
24
24
  ...(this.isChecked(ctx, data, value) ? ["checked"] : []),
25
25
  ];
26
26
  }
@@ -35,14 +35,14 @@ class Tickable extends controls_1.FormFieldControl {
35
35
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
36
36
  const readonly = this.options.readonly || false;
37
37
  const required = this.field.required;
38
- return input_wrapper_1.inputWrapper(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
38
+ return (0, input_wrapper_1.inputWrapper)(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
39
39
  /* HTML */ `
40
40
  <input
41
41
  id="${id}"
42
42
  type="${this.type}"
43
43
  name="${fctx.field_name_prefix}${this.options.name ||
44
44
  this.field.name}"
45
- ${value ? `value="${sanitize_1.attribute(value)}"` : ""}
45
+ ${value ? `value="${(0, sanitize_1.attribute)(value)}"` : ""}
46
46
  ${fctx.form_id ? `form="${fctx.form_id}"` : ""}
47
47
  ${this.isChecked(fctx.ctx, fctx.data, parsed)
48
48
  ? "checked"
@@ -18,10 +18,10 @@ class Boolean extends field_1.FormField {
18
18
  return { valid: true, message: "" };
19
19
  }
20
20
  async parse(_, value) {
21
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.boolean)) {
21
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.boolean)) {
22
22
  return { parsable: true, parsed_value: value, error: null };
23
23
  }
24
- else if (ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
24
+ else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
25
25
  [...truthy, ...falsy].includes(value)) {
26
26
  return {
27
27
  parsable: true,
@@ -29,7 +29,7 @@ class Boolean extends field_1.FormField {
29
29
  error: null,
30
30
  };
31
31
  }
32
- else if (ts_predicates_1.is(value, ts_predicates_1.predicates.undefined)) {
32
+ else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.undefined)) {
33
33
  return {
34
34
  parsable: true,
35
35
  parsed_value: false,
@@ -12,16 +12,16 @@ class ChekboxedListField extends field_1.FormField {
12
12
  this.predicate = ts_predicates_1.predicates.array(ts_predicates_1.predicates.string); // TODO: this is probably wrong
13
13
  }
14
14
  async isValueValid(_, value) {
15
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
15
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
16
16
  return { valid: false, message: "you need an array" };
17
17
  }
18
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.null)) {
18
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.null)) {
19
19
  return { valid: false, message: "you need an array" };
20
20
  }
21
21
  return { valid: true, message: "" };
22
22
  }
23
23
  async parse(_, raw_value) {
24
- if (ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object)) {
24
+ if ((0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object)) {
25
25
  return {
26
26
  parsable: true,
27
27
  parsed_value: Object.fromEntries(Object.entries(raw_value).filter(([, value]) => value === "on")),
@@ -12,7 +12,7 @@ class EnumMultipleField extends field_1.FormField {
12
12
  }
13
13
  async isValueValid(_, values) {
14
14
  for (const value of values) {
15
- if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
15
+ if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
16
16
  return { valid: false, message: "expected a string" };
17
17
  }
18
18
  if (!this.options.includes(value)) {
@@ -22,10 +22,10 @@ class EnumMultipleField extends field_1.FormField {
22
22
  return { valid: true, message: "" };
23
23
  }
24
24
  async parse(_, value) {
25
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
25
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
26
26
  return { parsable: true, parsed_value: [value], error: null };
27
27
  }
28
- else if (ts_predicates_1.is(value, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
28
+ else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
29
29
  return {
30
30
  parsable: true,
31
31
  parsed_value: value,
@@ -11,7 +11,7 @@ class EnumField extends field_1.FormField {
11
11
  this.predicate = ts_predicates_1.predicates.enum(this.options);
12
12
  }
13
13
  async isValueValid(_, value) {
14
- if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
14
+ if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
15
15
  return { valid: false, message: "expected a string" };
16
16
  }
17
17
  if (this.options.includes(value)) {
@@ -20,7 +20,7 @@ class EnumField extends field_1.FormField {
20
20
  return { valid: false, message: this.error_message(this.options) };
21
21
  }
22
22
  async parse(_, value) {
23
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
23
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
24
24
  return {
25
25
  parsable: true,
26
26
  parsed_value: value,
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -31,7 +35,7 @@ class FormField {
31
35
  (value === "" || value === null || value === undefined)) {
32
36
  return {
33
37
  valid: false,
34
- message: translate_1.t(ctx, "field_is_required", [], "This field is required"),
38
+ message: (0, translate_1.t)(ctx, "field_is_required", [], "This field is required"),
35
39
  };
36
40
  }
37
41
  return this.isValueValid(ctx, value);
@@ -8,8 +8,8 @@ class File extends field_1.FormField {
8
8
  async parse(ctx, raw_value) {
9
9
  let result;
10
10
  if (raw_value instanceof sealious_1.File ||
11
- (ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object) &&
12
- ts_predicates_1.hasShape({
11
+ ((0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object) &&
12
+ (0, ts_predicates_1.hasShape)({
13
13
  filename: ts_predicates_1.predicates.string,
14
14
  id: ts_predicates_1.predicates.string,
15
15
  }, raw_value) &&
@@ -21,7 +21,7 @@ class File extends field_1.FormField {
21
21
  parsable: true,
22
22
  };
23
23
  }
24
- else if (!ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object)) {
24
+ else if (!(0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object)) {
25
25
  result = {
26
26
  parsed_value: null,
27
27
  error: "Expected a field with old.id:string, old.filename:string and new?:File",
@@ -29,12 +29,12 @@ class File extends field_1.FormField {
29
29
  };
30
30
  }
31
31
  else {
32
- const old_file = ts_predicates_1.hasFieldOfType(raw_value, "old", ts_predicates_1.predicates.object) &&
33
- ts_predicates_1.hasShape({ id: ts_predicates_1.predicates.string, filename: ts_predicates_1.predicates.string }, raw_value.old) &&
32
+ const old_file = (0, ts_predicates_1.hasFieldOfType)(raw_value, "old", ts_predicates_1.predicates.object) &&
33
+ (0, ts_predicates_1.hasShape)({ id: ts_predicates_1.predicates.string, filename: ts_predicates_1.predicates.string }, raw_value.old) &&
34
34
  raw_value.old.id
35
35
  ? await sealious_1.File.fromID(ctx.$app, raw_value.old.id)
36
36
  : null;
37
- const new_file = ts_predicates_1.hasFieldOfType(raw_value, "new", ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)) && raw_value.new[0] instanceof sealious_1.File
37
+ const new_file = (0, ts_predicates_1.hasFieldOfType)(raw_value, "new", ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)) && raw_value.new[0] instanceof sealious_1.File
38
38
  ? raw_value.new[0]
39
39
  : null;
40
40
  result = {
@@ -11,20 +11,20 @@ class NumberField extends field_1.FormField {
11
11
  this.predicate = ts_predicates_1.predicates.number;
12
12
  }
13
13
  async isValueValid(_, value) {
14
- if ((ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
14
+ if (((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
15
15
  !isNaN(parseFloat(value)) &&
16
16
  parseFloat(value).toString() == value.trim()) ||
17
- ts_predicates_1.is(value, ts_predicates_1.predicates.number) ||
18
- ((ts_predicates_1.is(value, ts_predicates_1.predicates.undefined) || value == "") && !this.required)) {
17
+ (0, ts_predicates_1.is)(value, ts_predicates_1.predicates.number) ||
18
+ (((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.undefined) || value == "") && !this.required)) {
19
19
  return { valid: true, message: "" };
20
20
  }
21
21
  return { valid: false, message: "Proszę wprowadzić liczbę" };
22
22
  }
23
23
  async parse(_, value) {
24
- if ((ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
24
+ if (((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
25
25
  !isNaN(parseFloat(value)) &&
26
26
  parseFloat(value).toString() == value.trim()) ||
27
- ts_predicates_1.is(value, ts_predicates_1.predicates.number)) {
27
+ (0, ts_predicates_1.is)(value, ts_predicates_1.predicates.number)) {
28
28
  return {
29
29
  parsable: true,
30
30
  parsed_value: this.options.decimalDigits
@@ -16,7 +16,7 @@ class PickFromListField extends simple_form_field_1.SimpleFormField {
16
16
  }
17
17
  async valueInList(ctx, value) {
18
18
  const options = await this.generateOptions(ctx);
19
- if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
19
+ if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
20
20
  return { valid: false, message: "not a string" };
21
21
  }
22
22
  if (this.required && !options.map((o) => o.value).includes(value)) {
@@ -12,7 +12,7 @@ class RegExpField extends field_1.FormField {
12
12
  this.predicate = ts_predicates_1.predicates.string;
13
13
  }
14
14
  async isValueValid(_, value) {
15
- if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
15
+ if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
16
16
  return { valid: false, message: "expected a string" };
17
17
  }
18
18
  if (this.regexp.exec(value)) {
@@ -21,7 +21,7 @@ class RegExpField extends field_1.FormField {
21
21
  return { valid: false, message: this.error_message };
22
22
  }
23
23
  async parse(_, value) {
24
- if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
24
+ if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
25
25
  return {
26
26
  parsable: true,
27
27
  parsed_value: value,
@@ -4,10 +4,6 @@ exports.SimpleFormField = void 0;
4
4
  const field_1 = require("./field");
5
5
  const ts_predicates_1 = require("@sealcode/ts-predicates");
6
6
  class SimpleFormField extends field_1.FormField {
7
- constructor(required) {
8
- super(required);
9
- this.predicate = ts_predicates_1.predicates.string;
10
- }
11
7
  async parse(_, raw_value) {
12
8
  return {
13
9
  parsed_value: (raw_value || "").toString(),
@@ -18,6 +14,10 @@ class SimpleFormField extends field_1.FormField {
18
14
  getEmptyValue() {
19
15
  return "";
20
16
  }
17
+ constructor(required) {
18
+ super(required);
19
+ this.predicate = ts_predicates_1.predicates.string;
20
+ }
21
21
  }
22
22
  exports.SimpleFormField = SimpleFormField;
23
23
  //# sourceMappingURL=simple-form-field.js.map
package/lib/forms/form.js CHANGED
@@ -16,7 +16,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
16
16
  this.submitButtonText = "Wyślij";
17
17
  this.action = "./";
18
18
  this.useTurbo = true;
19
- this.form_id = crypto_1.randomUUID();
19
+ this.form_id = (0, crypto_1.randomUUID)();
20
20
  }
21
21
  async canAccess(
22
22
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -24,7 +24,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
24
24
  return { canAccess: true, message: "" };
25
25
  }
26
26
  async renderError(_, error) {
27
- return tempstream_1.tempstream /* HTML */ `<div>${error.message}</div>`;
27
+ return (0, tempstream_1.tempstream /* HTML */) `<div>${error.message}</div>`;
28
28
  }
29
29
  makeSubmitButton() {
30
30
  return /* HTML */ `<input
@@ -35,7 +35,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
35
35
  />`;
36
36
  }
37
37
  async render(ctx, data, show_field_errors) {
38
- return tempstream_1.tempstream /* HTML */ `<div class="form-container">
38
+ return (0, tempstream_1.tempstream /* HTML */) `<div class="form-container">
39
39
  ${this.makeOpenFormTag(ctx)}
40
40
  ${!this.controls.some((control) => control.role == "messages")
41
41
  ? this.renderMessages(ctx, data)
@@ -52,7 +52,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
52
52
  return [];
53
53
  }
54
54
  makeOpenFormTag(ctx) {
55
- return tempstream_1.tempstream `<form enctype="multipart/form-data" method="POST" id="${this.form_id}" action="${this.action}" class="${this.makeFormClasses(ctx).then((classes) => classes.join(" "))}" ${this.useTurbo ? "" : `data-turbo="false"`}></form><div class="form">`;
55
+ return (0, tempstream_1.tempstream) `<form enctype="multipart/form-data" method="POST" id="${this.form_id}" action="${this.action}" class="${this.makeFormClasses(ctx).then((classes) => classes.join(" "))}" ${this.useTurbo ? "" : `data-turbo="false"`}></form><div class="form">`;
56
56
  }
57
57
  makeCloseFormTag() {
58
58
  return `</div>`;
@@ -72,8 +72,8 @@ class Form extends mountable_with_fields_1.MountableWithFields {
72
72
  }
73
73
  async onError(ctx, data, error) {
74
74
  let error_message = "Unknown error has occured";
75
- if (ts_predicates_1.is(error, ts_predicates_1.predicates.object) &&
76
- ts_predicates_1.hasShape({ message: ts_predicates_1.predicates.string }, error)) {
75
+ if ((0, ts_predicates_1.is)(error, ts_predicates_1.predicates.object) &&
76
+ (0, ts_predicates_1.hasShape)({ message: ts_predicates_1.predicates.string }, error)) {
77
77
  error_message = error.message;
78
78
  }
79
79
  const messages = [{ type: "error", text: error_message }];
@@ -121,10 +121,10 @@ class Form extends mountable_with_fields_1.MountableWithFields {
121
121
  catch (e) {
122
122
  // eslint-disable-next-line no-console
123
123
  console.dir(e, { depth: 5 });
124
- const message = ts_predicates_1.is(e, ts_predicates_1.predicates.object) &&
125
- ts_predicates_1.hasFieldOfType(e, "message", ts_predicates_1.predicates.string)
124
+ const message = (0, ts_predicates_1.is)(e, ts_predicates_1.predicates.object) &&
125
+ (0, ts_predicates_1.hasFieldOfType)(e, "message", ts_predicates_1.predicates.string)
126
126
  ? e?.message
127
- : ts_predicates_1.is(e, ts_predicates_1.predicates.string)
127
+ : (0, ts_predicates_1.is)(e, ts_predicates_1.predicates.string)
128
128
  ? e
129
129
  : "Wystąpił błąd";
130
130
  return this.onError(ctx, {
@@ -40,7 +40,7 @@ exports.form_factory = form_factory;
40
40
  describe("form test", () => {
41
41
  let page;
42
42
  before(async () => {
43
- const browser = await browser_creator_1.getBrowser();
43
+ const browser = await (0, browser_creator_1.getBrowser)();
44
44
  const context = await browser.newContext();
45
45
  page = await context.newPage();
46
46
  });
@@ -49,7 +49,7 @@ describe("form test", () => {
49
49
  before(async () => {
50
50
  const app = new koa_1.default();
51
51
  const router = new router_1.default();
52
- mount_1.mount(router, "/", form_factory(), true);
52
+ (0, mount_1.mount)(router, "/", form_factory(), true);
53
53
  app.use(router.routes()).use(router.allowedMethods());
54
54
  server = app.listen(8080);
55
55
  await page.goto("http://localhost:8080");
@@ -59,7 +59,7 @@ describe("form test", () => {
59
59
  });
60
60
  it("does not allow to submit an empty form when there's a required field", async () => {
61
61
  await page.getByRole("button", { name: "Submit", exact: true }).click();
62
- await utils_1.assertThrowsAsync(async () => {
62
+ await (0, utils_1.assertThrowsAsync)(async () => {
63
63
  return page.getByText("Done").click({ timeout: 500 });
64
64
  });
65
65
  });
@@ -92,7 +92,7 @@ describe("form test", () => {
92
92
  it("allows visit when configured when canAccess returns true", async () => {
93
93
  const app = new koa_1.default();
94
94
  const router = new router_1.default();
95
- mount_1.mount(router, "/", form_factory(async (ctx) => {
95
+ (0, mount_1.mount)(router, "/", form_factory(async (ctx) => {
96
96
  return { canAccess: true, message: "" };
97
97
  }), true);
98
98
  app.use(router.routes()).use(router.allowedMethods());
@@ -106,7 +106,7 @@ describe("form test", () => {
106
106
  const app = new koa_1.default();
107
107
  const router = new router_1.default();
108
108
  before(async () => {
109
- mount_1.mount(router, "/", form_factory(async (ctx) => {
109
+ (0, mount_1.mount)(router, "/", form_factory(async (ctx) => {
110
110
  return { canAccess: false, message: "" };
111
111
  }), true);
112
112
  app.use(router.routes()).use(router.allowedMethods());
@@ -135,7 +135,7 @@ describe("form test", () => {
135
135
  it("passes the context to canAccess (false case)", async () => {
136
136
  const app = new koa_1.default();
137
137
  const router = new router_1.default();
138
- mount_1.mount(router, "/", form_factory(async (ctx) => {
138
+ (0, mount_1.mount)(router, "/", form_factory(async (ctx) => {
139
139
  return ctx.$context && ctx.$context.user_id
140
140
  ? { canAccess: true, message: "" }
141
141
  : { canAccess: false, message: "" };
@@ -156,7 +156,7 @@ describe("form test", () => {
156
156
  };
157
157
  await next();
158
158
  });
159
- mount_1.mount(router, "/", form_factory(async (ctx) => {
159
+ (0, mount_1.mount)(router, "/", form_factory(async (ctx) => {
160
160
  return ctx.$context && ctx.$context.user_id
161
161
  ? { canAccess: true, message: "" }
162
162
  : { canAccess: false, message: "" };
@@ -175,7 +175,7 @@ describe("form test", () => {
175
175
  before(async () => {
176
176
  const app = new koa_1.default();
177
177
  const router = new router_1.default();
178
- mount_1.mount(router, "/", new (class extends index_1.Form {
178
+ (0, mount_1.mount)(router, "/", new (class extends index_1.Form {
179
179
  constructor() {
180
180
  super(...arguments);
181
181
  this.fields = fields;
@@ -210,14 +210,14 @@ describe("form test", () => {
210
210
  await page.getByPlaceholder("password").click();
211
211
  await page.getByPlaceholder("password").fill("incorrect");
212
212
  await page.getByRole("button", { name: "Submit" }).click();
213
- if (!(await locator_is_visible_1.locator_is_visible(page.getByText("Incorrect input"))))
213
+ if (!(await (0, locator_is_visible_1.locator_is_visible)(page.getByText("Incorrect input"))))
214
214
  throw new Error("validation message doens't show up when input is incorrect");
215
215
  });
216
216
  it("doesn't show when correct input is given", async () => {
217
217
  await page.getByPlaceholder("password").click();
218
218
  await page.getByPlaceholder("password").fill("correct");
219
219
  await page.getByRole("button", { name: "Submit" }).click();
220
- await utils_1.assertThrowsAsync(async () => {
220
+ await (0, utils_1.assertThrowsAsync)(async () => {
221
221
  return page.getByText("Incorrect input").click({ timeout: 500 });
222
222
  });
223
223
  });
@@ -230,7 +230,7 @@ describe("form test", () => {
230
230
  const fields = {
231
231
  text: new index_1.Fields.EmailField(true),
232
232
  };
233
- mount_1.mount(router, "/", new (class extends index_1.Form {
233
+ (0, mount_1.mount)(router, "/", new (class extends index_1.Form {
234
234
  constructor() {
235
235
  super(...arguments);
236
236
  this.fields = fields;
@@ -263,7 +263,7 @@ describe("form test", () => {
263
263
  await page.getByPlaceholder("text").click();
264
264
  await page.getByPlaceholder("text").fill("yes@an.email");
265
265
  await page.getByRole("button", { name: "Submit" }).click();
266
- utils_1.assertThrowsAsync(async () => {
266
+ (0, utils_1.assertThrowsAsync)(async () => {
267
267
  return page
268
268
  .getByText("Please enter a proper email address")
269
269
  .click({ timeout: 500 });