@sealcode/sealgen 0.15.36 → 0.15.37

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.
@@ -6,35 +6,27 @@ import { FormField } from "../fields/field.js";
6
6
  import { Table as TableField } from "../fields/table.js";
7
7
  import { Form } from "../form.js";
8
8
  import { FormControl, FormControlContext } from "./form-control.js";
9
+ export type TableControlOptions<F extends Record<string, FormField>> = {
10
+ render_fields: {
11
+ [field_name in keyof F]: (fctx: FormControlContext, name: string, value: string) => string;
12
+ };
13
+ allow_removing?: boolean;
14
+ label_add?: string;
15
+ label: string;
16
+ label_remove?: string;
17
+ } & ({
18
+ allow_adding: false;
19
+ } | {
20
+ allow_adding: true;
21
+ make_new_row: (ctx: Context) => Promise<{
22
+ [field_name in keyof F]: unknown;
23
+ }>;
24
+ });
9
25
  export declare class Table<F extends Record<string, FormField>> extends FormControl {
10
26
  table_field: TableField<F>;
11
- options: {
12
- render_fields: {
13
- [field_name in keyof F]: (fctx: FormControlContext, name: string, value: string) => string;
14
- };
15
- allow_adding?: boolean;
16
- allow_removing?: boolean;
17
- make_new_row: (ctx: Context) => Promise<{
18
- [field_name in keyof F]: unknown;
19
- }>;
20
- label_add?: string;
21
- label: string;
22
- label_remove?: string;
23
- };
27
+ options: TableControlOptions<F>;
24
28
  role: "input";
25
- constructor(table_field: TableField<F>, options: {
26
- render_fields: {
27
- [field_name in keyof F]: (fctx: FormControlContext, name: string, value: string) => string;
28
- };
29
- allow_adding?: boolean;
30
- allow_removing?: boolean;
31
- make_new_row: (ctx: Context) => Promise<{
32
- [field_name in keyof F]: unknown;
33
- }>;
34
- label_add?: string;
35
- label: string;
36
- label_remove?: string;
37
- });
29
+ constructor(table_field: TableField<F>, options: TableControlOptions<F>);
38
30
  render(fctx: FormControlContext): Promise<FlatTemplatable>;
39
31
  getFrameID(): string;
40
32
  getActionURL(field_name: string, action: Record<string, unknown>): string;
@@ -105,7 +105,7 @@ class Table extends FormControl {
105
105
  await next();
106
106
  return;
107
107
  }
108
- if (hasShape(
108
+ if (this.options.allow_adding && hasShape(
109
109
  {
110
110
  insert: predicates.shape({ index: predicates.string })
111
111
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.15.36",
3
+ "version": "0.15.37",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -12,27 +12,33 @@ import { FormReaction } from "../form-types.js";
12
12
  import { Form } from "../form.js";
13
13
  import { FormControl, FormControlContext } from "./form-control.js";
14
14
 
15
+ export type TableControlOptions<F extends Record<string, FormField>> = {
16
+ render_fields: {
17
+ [field_name in keyof F]: (
18
+ fctx: FormControlContext,
19
+ name: string,
20
+ value: string
21
+ ) => string;
22
+ };
23
+ allow_removing?: boolean;
24
+ label_add?: string;
25
+ label: string;
26
+ label_remove?: string;
27
+ } & (
28
+ | { allow_adding: false }
29
+ | {
30
+ allow_adding: true;
31
+ make_new_row: (
32
+ ctx: Context
33
+ ) => Promise<{ [field_name in keyof F]: unknown }>;
34
+ }
35
+ );
36
+
15
37
  export class Table<F extends Record<string, FormField>> extends FormControl {
16
38
  role = <const>"input";
17
39
  constructor(
18
40
  public table_field: TableField<F>,
19
- public options: {
20
- render_fields: {
21
- [field_name in keyof F]: (
22
- fctx: FormControlContext,
23
- name: string,
24
- value: string
25
- ) => string;
26
- };
27
- allow_adding?: boolean;
28
- allow_removing?: boolean;
29
- make_new_row: (
30
- ctx: Context
31
- ) => Promise<{ [field_name in keyof F]: unknown }>;
32
- label_add?: string;
33
- label: string;
34
- label_remove?: string;
35
- }
41
+ public options: TableControlOptions<F>
36
42
  ) {
37
43
  super();
38
44
  }
@@ -149,6 +155,7 @@ export class Table<F extends Record<string, FormField>> extends FormControl {
149
155
  return;
150
156
  }
151
157
  if (
158
+ this.options.allow_adding &&
152
159
  hasShape(
153
160
  {
154
161
  insert: predicates.shape({ index: predicates.string }),