@sealcode/sealgen 0.5.15 → 0.5.16
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/forms/controls/controls.d.ts +1 -0
- package/@types/forms/controls/textarea.d.ts +19 -0
- package/@types/index.d.ts +1 -0
- package/@types/sanitize.d.ts +1 -0
- package/lib/forms/controls/controls.js +3 -1
- package/lib/forms/controls/controls.js.map +1 -1
- package/lib/forms/controls/dropdown.js +2 -1
- package/lib/forms/controls/dropdown.js.map +1 -1
- package/lib/forms/controls/editable-collection-subset.js +3 -2
- package/lib/forms/controls/editable-collection-subset.js.map +1 -1
- package/lib/forms/controls/hidden-input.js +2 -1
- package/lib/forms/controls/hidden-input.js.map +1 -1
- package/lib/forms/controls/simple-input.js +3 -2
- package/lib/forms/controls/simple-input.js.map +1 -1
- package/lib/forms/controls/textarea.js +33 -0
- package/lib/forms/controls/textarea.js.map +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/make-hidden-inputs.js +2 -1
- package/lib/make-hidden-inputs.js.map +1 -1
- package/lib/sanitize.js +11 -0
- package/lib/sanitize.js.map +1 -0
- package/package.json +1 -1
- package/src/forms/controls/controls.ts +1 -0
- package/src/forms/controls/dropdown.ts +2 -1
- package/src/forms/controls/editable-collection-subset.ts +5 -2
- package/src/forms/controls/hidden-input.ts +2 -1
- package/src/forms/controls/simple-input.ts +9 -6
- package/src/forms/controls/textarea.ts +37 -0
- package/src/index.ts +1 -0
- package/src/make-hidden-inputs.ts +2 -1
- package/src/sanitize.ts +6 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
|
+
import { FormFieldControl } from "./form-field-control";
|
|
6
|
+
export declare class Textarea extends FormFieldControl {
|
|
7
|
+
field: FormField;
|
|
8
|
+
options: {
|
|
9
|
+
label?: string;
|
|
10
|
+
rows?: number;
|
|
11
|
+
cols?: number;
|
|
12
|
+
};
|
|
13
|
+
constructor(field: FormField, options?: {
|
|
14
|
+
label?: string;
|
|
15
|
+
rows?: number;
|
|
16
|
+
cols?: number;
|
|
17
|
+
});
|
|
18
|
+
render(ctx: Context, data: Record<string, FormDataValue>): Promise<FlatTemplatable>;
|
|
19
|
+
}
|
package/@types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function attribute(raw: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HiddenInput = exports.HTML = exports.FormParagraph = exports.FormHeader = exports.SimpleInput = exports.Dropdown = exports.CheckboxedListInput = exports.Frame = exports.EditableCollectionSubset = exports.FormFieldControl = exports.FormControl = void 0;
|
|
3
|
+
exports.Textarea = exports.HiddenInput = exports.HTML = exports.FormParagraph = exports.FormHeader = exports.SimpleInput = exports.Dropdown = exports.CheckboxedListInput = exports.Frame = exports.EditableCollectionSubset = exports.FormFieldControl = exports.FormControl = void 0;
|
|
4
4
|
var form_control_1 = require("./form-control");
|
|
5
5
|
Object.defineProperty(exports, "FormControl", { enumerable: true, get: function () { return form_control_1.FormControl; } });
|
|
6
6
|
var form_field_control_1 = require("./form-field-control");
|
|
@@ -23,4 +23,6 @@ var html_1 = require("./html");
|
|
|
23
23
|
Object.defineProperty(exports, "HTML", { enumerable: true, get: function () { return html_1.HTML; } });
|
|
24
24
|
var hidden_input_1 = require("./hidden-input");
|
|
25
25
|
Object.defineProperty(exports, "HiddenInput", { enumerable: true, get: function () { return hidden_input_1.HiddenInput; } });
|
|
26
|
+
var textarea_1 = require("./textarea");
|
|
27
|
+
Object.defineProperty(exports, "Textarea", { enumerable: true, get: function () { return textarea_1.Textarea; } });
|
|
26
28
|
//# sourceMappingURL=controls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../../../src/forms/controls/controls.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
|
|
1
|
+
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../../../src/forms/controls/controls.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Dropdown = void 0;
|
|
4
4
|
const tempstream_1 = require("tempstream");
|
|
5
|
+
const sanitize_1 = require("../../sanitize");
|
|
5
6
|
const controls_1 = require("./controls");
|
|
6
7
|
class Dropdown extends controls_1.FormFieldControl {
|
|
7
8
|
constructor(field, options = {
|
|
@@ -26,7 +27,7 @@ class Dropdown extends controls_1.FormFieldControl {
|
|
|
26
27
|
: ""}
|
|
27
28
|
${!this.options.autocomplete ? `autocomplete="off"` : ""}
|
|
28
29
|
>
|
|
29
|
-
${Promise.resolve(this.field.generateOptions(ctx)).then((options) => Object.entries(options).map(([value, text]) => `<option value="${value}" ${(value || "") == picked_value
|
|
30
|
+
${Promise.resolve(this.field.generateOptions(ctx)).then((options) => Object.entries(options).map(([value, text]) => `<option value="${sanitize_1.attribute(value)}" ${(value || "") == picked_value
|
|
30
31
|
? "selected"
|
|
31
32
|
: ""}>${text}</option>`))}
|
|
32
33
|
</select>`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../../src/forms/controls/dropdown.ts"],"names":[],"mappings":";;;AACA,2CAAwC;
|
|
1
|
+
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../../src/forms/controls/dropdown.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AACxC,6CAA2C;AAG3C,yCAA8C;AAE9C,MAAa,QAAS,SAAQ,2BAAgB;IAC7C,YACQ,KAAwB,EACxB,UAIH;QACH,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KAClB;QAED,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAXR,UAAK,GAAL,KAAK,CAAmB;QACxB,YAAO,GAAP,OAAO,CAQb;IAGF,CAAC;IAED,KAAK,CAAC,MAAM,CACX,GAAY,EACZ,IAAmC;QAEnC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAC3B,OAAO,uBAAU,CAAA,UAAU,CAAC,eAAe,EAAE;OACxC,IAAI,CAAC,OAAO,CAAC,KAAK;;YAEb,IAAI,CAAC,KAAK,CAAC,IAAI;UACjB,EAAE;MACN,IAAI,CAAC,OAAO,CAAC,UAAU;YACxB,CAAC,CAAC,+BAA+B;YACjC,CAAC,CAAC,EAAE;MACH,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE;;MAEtD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CACtD,CAAC,OAAO,EAAE,EAAE,CACX,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAC1B,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CACjB,kBAAkB,oBAAS,CAAC,KAAK,CAAC,KACjC,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,YAAY;YAC5B,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,EACJ,IAAI,IAAI,WAAW,CACpB,CACF;aACQ,CAAC;IACb,CAAC;CACD;AA7CD,4BA6CC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EditableCollectionSubset = void 0;
|
|
4
4
|
const tempstream_1 = require("tempstream");
|
|
5
|
+
const sanitize_1 = require("../../sanitize");
|
|
5
6
|
const controls_1 = require("./controls");
|
|
6
7
|
/**
|
|
7
8
|
* This control has own forms in it so if you want to use it you
|
|
@@ -35,7 +36,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
|
|
|
35
36
|
<input
|
|
36
37
|
type="hidden"
|
|
37
38
|
name="${this.field.name}"
|
|
38
|
-
value="${value}"
|
|
39
|
+
value="${sanitize_1.attribute(value)}"
|
|
39
40
|
/>
|
|
40
41
|
<input
|
|
41
42
|
type="hidden"
|
|
@@ -56,7 +57,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
|
|
|
56
57
|
<select name="${this.field.name}">
|
|
57
58
|
${Promise.resolve(this.field.generateOptions(ctx)).then((options) => Object.entries(options)
|
|
58
59
|
.filter(([value]) => !(values || []).includes(value))
|
|
59
|
-
.map(([value, text]) => `<option value="${value}">${text}</option>`))}
|
|
60
|
+
.map(([value, text]) => `<option value="${sanitize_1.attribute(value)}">${text}</option>`))}
|
|
60
61
|
</select>
|
|
61
62
|
<input type="hidden" name="${this.actionname}" value="select" />
|
|
62
63
|
<input
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editable-collection-subset.js","sourceRoot":"","sources":["../../../src/forms/controls/editable-collection-subset.ts"],"names":[],"mappings":";;;AACA,2CAAyD;
|
|
1
|
+
{"version":3,"file":"editable-collection-subset.js","sourceRoot":"","sources":["../../../src/forms/controls/editable-collection-subset.ts"],"names":[],"mappings":";;;AACA,2CAAyD;AACzD,6CAA2C;AAG3C,yCAA8C;AAE9C;;;;;;GAMG;AACH,MAAa,wBAAyB,SAAQ,2BAAgB;IAC7D,YACQ,KAAwB,EACxB,UAAkB,EAClB,SAAkB,EAClB,WAAoB;QAE3B,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QALR,UAAK,GAAL,KAAK,CAAmB;QACxB,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAS;QAClB,gBAAW,GAAX,WAAW,CAAS;QA4E5B,SAAI,GAAU,OAAO,CAAC;IAzEtB,CAAC;IAED,KAAK,CAAC,MAAM,CACX,GAAY,EACZ,IAAmC;QAEnC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEhE,OAAO,uBA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AC,UAAU,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE;;;SAGnD,CAAC;IACT,CAAC;CAED;AAlFD,4DAkFC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HiddenInput = void 0;
|
|
4
4
|
const tempstream_1 = require("tempstream");
|
|
5
|
+
const sanitize_1 = require("../../sanitize");
|
|
5
6
|
const form_field_control_1 = require("./form-field-control");
|
|
6
7
|
class HiddenInput extends form_field_control_1.FormFieldControl {
|
|
7
8
|
constructor(field) {
|
|
@@ -10,7 +11,7 @@ class HiddenInput extends form_field_control_1.FormFieldControl {
|
|
|
10
11
|
}
|
|
11
12
|
async render(ctx, data) {
|
|
12
13
|
const { raw } = await this.field.getValue(ctx, data);
|
|
13
|
-
return tempstream_1.tempstream `<input type="hidden" name="${this.field.name}" value="${(raw || "").toString()}">`;
|
|
14
|
+
return tempstream_1.tempstream `<input type="hidden" name="${this.field.name}" value="${sanitize_1.attribute((raw || "").toString())}">`;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
exports.HiddenInput = HiddenInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hidden-input.js","sourceRoot":"","sources":["../../../src/forms/controls/hidden-input.ts"],"names":[],"mappings":";;;AACA,2CAAyD;
|
|
1
|
+
{"version":3,"file":"hidden-input.js","sourceRoot":"","sources":["../../../src/forms/controls/hidden-input.ts"],"names":[],"mappings":";;;AACA,2CAAyD;AACzD,6CAA2C;AAG3C,6DAAwD;AAExD,MAAa,WAAY,SAAQ,qCAAgB;IAChD,YAAmB,KAAgB;QAClC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QADG,UAAK,GAAL,KAAK,CAAW;IAEnC,CAAC;IAED,KAAK,CAAC,MAAM,CACX,GAAY,EACZ,IAAmC;QAEnC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACrD,OAAO,uBAAU,CAAA,8BAChB,IAAI,CAAC,KAAK,CAAC,IACZ,YAAY,oBAAS,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC;IACnD,CAAC;CACD;AAdD,kCAcC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimpleInput = void 0;
|
|
4
|
+
const sanitize_1 = require("../../sanitize");
|
|
4
5
|
const controls_1 = require("./controls");
|
|
5
6
|
class SimpleInput extends controls_1.FormFieldControl {
|
|
6
7
|
constructor(field, options = {}) {
|
|
@@ -28,12 +29,12 @@ class SimpleInput extends controls_1.FormFieldControl {
|
|
|
28
29
|
id="${id}"
|
|
29
30
|
type="${type}"
|
|
30
31
|
name="${this.field.name}"
|
|
31
|
-
value="${!valid && raw
|
|
32
|
+
value="${sanitize_1.attribute(!valid && raw
|
|
32
33
|
? raw.toString()
|
|
33
34
|
: parsed !== undefined && parsed !== null
|
|
34
35
|
? // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
35
36
|
parsed?.toString() || ""
|
|
36
|
-
: ""}"
|
|
37
|
+
: "")}"
|
|
37
38
|
placeholder="${placeholder}"
|
|
38
39
|
${readonly ? "readonly" : ""}
|
|
39
40
|
${required ? "required" : ""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-input.js","sourceRoot":"","sources":["../../../src/forms/controls/simple-input.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"simple-input.js","sourceRoot":"","sources":["../../../src/forms/controls/simple-input.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAG3C,yCAA8C;AAE9C,MAAa,WAAY,SA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c,EAAE,QAAQ,EAAa,IAAI,EAAE;gBAC/C,CAAC,CAAC,EAAE,CACL;mBACc,WAAW;MACxB,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;MAC1B,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;MAC1B,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE;MACtD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE;;KAEvD,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW;YACpC,CAAC,CAAC,6BAA6B,OAAO,QAAQ;YAC9C,CAAC,CAAC,EAAE;SACC,CAAC;IACT,CAAC;CACD;AA7ED,kCA6EC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Textarea = void 0;
|
|
4
|
+
const tempstream_1 = require("tempstream");
|
|
5
|
+
const sanitize_1 = require("../../sanitize");
|
|
6
|
+
const form_field_control_1 = require("./form-field-control");
|
|
7
|
+
class Textarea extends form_field_control_1.FormFieldControl {
|
|
8
|
+
constructor(field, options = {}) {
|
|
9
|
+
super([field]);
|
|
10
|
+
this.field = field;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
async render(ctx, data) {
|
|
14
|
+
const { raw } = await this.field.getValue(ctx, data);
|
|
15
|
+
return tempstream_1.tempstream /* HTML */ `<div
|
|
16
|
+
class="form-input form-input__wrapper"
|
|
17
|
+
>
|
|
18
|
+
<label for="${this.field.name}"
|
|
19
|
+
>${this.options.label || this.field.name}</label
|
|
20
|
+
>
|
|
21
|
+
<textarea
|
|
22
|
+
name="${this.field.name}"
|
|
23
|
+
id="${this.field.name}"
|
|
24
|
+
rows="${this.options.rows || 5}"
|
|
25
|
+
cols="${this.options.cols || 33}"
|
|
26
|
+
>
|
|
27
|
+
${sanitize_1.attribute((raw || "").toString())}</textarea
|
|
28
|
+
>
|
|
29
|
+
</div>`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Textarea = Textarea;
|
|
33
|
+
//# sourceMappingURL=textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../../src/forms/controls/textarea.ts"],"names":[],"mappings":";;;AACA,2CAAyD;AACzD,6CAA2C;AAG3C,6DAAwD;AAExD,MAAa,QAAS,SAAQ,qCAAgB;IAC7C,YACQ,KAAgB,EAChB,UAA4D,EAAE;QAErE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAHR,UAAK,GAAL,KAAK,CAAW;QAChB,YAAO,GAAP,OAAO,CAAuD;IAGtE,CAAC;IAED,KAAK,CAAC,MAAM,CACX,GAAY,EACZ,IAAmC;QAEnC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACrD,OAAO,uBAAU,CAAA,UAAU,CAAC;;;iBAGb,IAAI,CAAC,KAAK,CAAC,IAAI;OACzB,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI;;;YAGhC,IAAI,CAAC,KAAK,CAAC,IAAI;UACjB,IAAI,CAAC,KAAK,CAAC,IAAI;YACb,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE;;EAEjC,oBAAS,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;;SAE1B,CAAC;IACT,CAAC;CACD;AA7BD,4BA6BC"}
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Fields = exports.Controls = void 0;
|
|
25
|
+
exports.sanitize = exports.Fields = exports.Controls = void 0;
|
|
26
26
|
exports.Controls = __importStar(require("./forms/controls/controls"));
|
|
27
27
|
exports.Fields = __importStar(require("./forms/fields/field"));
|
|
28
28
|
__exportStar(require("./page/mountable"), exports);
|
|
@@ -32,4 +32,5 @@ __exportStar(require("./page/props-parser"), exports);
|
|
|
32
32
|
__exportStar(require("./utils/utils"), exports);
|
|
33
33
|
__exportStar(require("./page/list"), exports);
|
|
34
34
|
__exportStar(require("./utils/translate"), exports);
|
|
35
|
+
exports.sanitize = __importStar(require("./sanitize"));
|
|
35
36
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,sEAAsD;AACtD,+DAA+C;AAC/C,mDAAiC;AACjC,8CAA4B;AAC5B,+CAA6B;AAC7B,sDAAoC;AACpC,gDAA8B;AAC9B,8CAA4B;AAC5B,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,sEAAsD;AACtD,+DAA+C;AAC/C,mDAAiC;AACjC,8CAA4B;AAC5B,+CAA6B;AAC7B,sDAAoC;AACpC,gDAA8B;AAC9B,8CAA4B;AAC5B,oDAAkC;AAClC,uDAAuC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeHiddenInputs = void 0;
|
|
4
4
|
const tempstream_1 = require("tempstream");
|
|
5
|
+
const sanitize_1 = require("./sanitize");
|
|
5
6
|
function makeHiddenInputs(ctx, fields, values, fields_to_skip) {
|
|
6
7
|
return tempstream_1.tempstream `${Object.entries(fields)
|
|
7
8
|
.filter(([key]) => !fields_to_skip.includes(key))
|
|
@@ -10,7 +11,7 @@ function makeHiddenInputs(ctx, fields, values, fields_to_skip) {
|
|
|
10
11
|
name="${key}"
|
|
11
12
|
value="${field
|
|
12
13
|
.getValue(ctx, values)
|
|
13
|
-
.then((r) => JSON.stringify(r.raw))}"
|
|
14
|
+
.then((r) => sanitize_1.attribute(JSON.stringify(r.raw)))}"
|
|
14
15
|
/>`)}`;
|
|
15
16
|
}
|
|
16
17
|
exports.makeHiddenInputs = makeHiddenInputs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-hidden-inputs.js","sourceRoot":"","sources":["../src/make-hidden-inputs.ts"],"names":[],"mappings":";;;AACA,2CAAyD;
|
|
1
|
+
{"version":3,"file":"make-hidden-inputs.js","sourceRoot":"","sources":["../src/make-hidden-inputs.ts"],"names":[],"mappings":";;;AACA,2CAAyD;AAGzD,yCAAuC;AAEvC,SAAgB,gBAAgB,CAC/B,GAAY,EACZ,MAAiC,EACjC,MAAqC,EACrC,cAAwB;IAExB,OAAO,uBAAU,CAAA,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SACxC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAChD,GAAG,CACH,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,uBAAU,CAAA,UAAU,CAAC;;YAE9B,GAAG;aACF,KAAK;SACZ,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;SACrB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;MAC7C,CACH,EAAE,CAAC;AACN,CAAC;AAjBD,4CAiBC"}
|
package/lib/sanitize.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attribute = void 0;
|
|
4
|
+
function attribute(raw) {
|
|
5
|
+
return raw
|
|
6
|
+
.replaceAll("<", "<")
|
|
7
|
+
.replace('"', """)
|
|
8
|
+
.replaceAll("'", "'");
|
|
9
|
+
}
|
|
10
|
+
exports.attribute = attribute;
|
|
11
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAC,GAAW;IACpC,OAAO,GAAG;SACR,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;SACtB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AALD,8BAKC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { tempstream } from "tempstream";
|
|
3
|
+
import { attribute } from "../../sanitize";
|
|
3
4
|
import { FormField, PickFromListField } from "../fields/field";
|
|
4
5
|
import { FormDataValue } from "../form";
|
|
5
6
|
import { FormFieldControl } from "./controls";
|
|
@@ -40,7 +41,7 @@ export class Dropdown extends FormFieldControl {
|
|
|
40
41
|
(options) =>
|
|
41
42
|
Object.entries(options).map(
|
|
42
43
|
([value, text]) =>
|
|
43
|
-
`<option value="${value}" ${
|
|
44
|
+
`<option value="${attribute(value)}" ${
|
|
44
45
|
(value || "") == picked_value
|
|
45
46
|
? "selected"
|
|
46
47
|
: ""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
|
+
import { attribute } from "../../sanitize";
|
|
3
4
|
import { PickFromListField } from "../fields/field";
|
|
4
5
|
import { FormDataValue } from "../form";
|
|
5
6
|
import { FormFieldControl } from "./controls";
|
|
@@ -46,7 +47,7 @@ export class EditableCollectionSubset extends FormFieldControl {
|
|
|
46
47
|
<input
|
|
47
48
|
type="hidden"
|
|
48
49
|
name="${this.field.name}"
|
|
49
|
-
value="${value}"
|
|
50
|
+
value="${attribute(value)}"
|
|
50
51
|
/>
|
|
51
52
|
<input
|
|
52
53
|
type="hidden"
|
|
@@ -78,7 +79,9 @@ export class EditableCollectionSubset extends FormFieldControl {
|
|
|
78
79
|
)
|
|
79
80
|
.map(
|
|
80
81
|
([value, text]) =>
|
|
81
|
-
`<option value="${
|
|
82
|
+
`<option value="${attribute(
|
|
83
|
+
value
|
|
84
|
+
)}">${text}</option>`
|
|
82
85
|
)
|
|
83
86
|
)}
|
|
84
87
|
</select>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
|
+
import { attribute } from "../../sanitize";
|
|
3
4
|
import { FormField } from "../fields/field";
|
|
4
5
|
import { FormDataValue } from "../form";
|
|
5
6
|
import { FormFieldControl } from "./form-field-control";
|
|
@@ -16,6 +17,6 @@ export class HiddenInput extends FormFieldControl {
|
|
|
16
17
|
const { raw } = await this.field.getValue(ctx, data);
|
|
17
18
|
return tempstream`<input type="hidden" name="${
|
|
18
19
|
this.field.name
|
|
19
|
-
}" value="${(raw || "").toString()}">`;
|
|
20
|
+
}" value="${attribute((raw || "").toString())}">`;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
|
+
import { attribute } from "../../sanitize";
|
|
2
3
|
import { FormField } from "../fields/field";
|
|
3
4
|
import { FormDataValue } from "../form";
|
|
4
5
|
import { FormFieldControl } from "./controls";
|
|
@@ -61,12 +62,14 @@ export class SimpleInput extends FormFieldControl {
|
|
|
61
62
|
id="${id}"
|
|
62
63
|
type="${type}"
|
|
63
64
|
name="${this.field.name}"
|
|
64
|
-
value="${
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
value="${attribute(
|
|
66
|
+
!valid && raw
|
|
67
|
+
? raw.toString()
|
|
68
|
+
: parsed !== undefined && parsed !== null
|
|
69
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
70
|
+
((parsed as any)?.toString() as string) || ""
|
|
71
|
+
: ""
|
|
72
|
+
)}"
|
|
70
73
|
placeholder="${placeholder}"
|
|
71
74
|
${readonly ? "readonly" : ""}
|
|
72
75
|
${required ? "required" : ""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
|
+
import { attribute } from "../../sanitize";
|
|
4
|
+
import { FormField } from "../fields/field";
|
|
5
|
+
import { FormDataValue } from "../form";
|
|
6
|
+
import { FormFieldControl } from "./form-field-control";
|
|
7
|
+
|
|
8
|
+
export class Textarea extends FormFieldControl {
|
|
9
|
+
constructor(
|
|
10
|
+
public field: FormField,
|
|
11
|
+
public options: { label?: string; rows?: number; cols?: number } = {}
|
|
12
|
+
) {
|
|
13
|
+
super([field]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async render(
|
|
17
|
+
ctx: Context,
|
|
18
|
+
data: Record<string, FormDataValue>
|
|
19
|
+
): Promise<FlatTemplatable> {
|
|
20
|
+
const { raw } = await this.field.getValue(ctx, data);
|
|
21
|
+
return tempstream/* HTML */ `<div
|
|
22
|
+
class="form-input form-input__wrapper"
|
|
23
|
+
>
|
|
24
|
+
<label for="${this.field.name}"
|
|
25
|
+
>${this.options.label || this.field.name}</label
|
|
26
|
+
>
|
|
27
|
+
<textarea
|
|
28
|
+
name="${this.field.name}"
|
|
29
|
+
id="${this.field.name}"
|
|
30
|
+
rows="${this.options.rows || 5}"
|
|
31
|
+
cols="${this.options.cols || 33}"
|
|
32
|
+
>
|
|
33
|
+
${attribute((raw || "").toString())}</textarea
|
|
34
|
+
>
|
|
35
|
+
</div>`;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Context } from "koa";
|
|
|
2
2
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
3
|
import { FormDataValue } from ".";
|
|
4
4
|
import { FormField } from "./forms/fields/field";
|
|
5
|
+
import { attribute } from "./sanitize";
|
|
5
6
|
|
|
6
7
|
export function makeHiddenInputs(
|
|
7
8
|
ctx: Context,
|
|
@@ -17,7 +18,7 @@ export function makeHiddenInputs(
|
|
|
17
18
|
name="${key}"
|
|
18
19
|
value="${field
|
|
19
20
|
.getValue(ctx, values)
|
|
20
|
-
.then((r) => JSON.stringify(r.raw))}"
|
|
21
|
+
.then((r) => attribute(JSON.stringify(r.raw)))}"
|
|
21
22
|
/>`
|
|
22
23
|
)}`;
|
|
23
24
|
}
|