@saltcorn/markup 0.6.1-beta.2 → 0.6.2-beta.1
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/helpers.js +58 -10
- package/index.js +16 -0
- package/layout.js +10 -7
- package/package.json +4 -2
package/helpers.js
CHANGED
|
@@ -17,16 +17,16 @@ const {
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* checks if x is defined
|
|
20
|
-
* @param {*} x
|
|
20
|
+
* @param {*} x
|
|
21
21
|
* @returns {boolean}
|
|
22
22
|
*/
|
|
23
23
|
const isdef = (x) => typeof x !== "undefined";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @param {object|string} v
|
|
27
|
-
* @param {object} hdr
|
|
28
|
-
* @param {boolean} force_required
|
|
29
|
-
* @param {string} neutral_label
|
|
26
|
+
* @param {object|string} v
|
|
27
|
+
* @param {object} hdr
|
|
28
|
+
* @param {boolean} force_required
|
|
29
|
+
* @param {string} neutral_label
|
|
30
30
|
* @returns {string}
|
|
31
31
|
*/
|
|
32
32
|
const select_options = (v, hdr, force_required, neutral_label = "") => {
|
|
@@ -56,7 +56,7 @@ const select_options = (v, hdr, force_required, neutral_label = "") => {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
*
|
|
60
60
|
* @param {object} opts
|
|
61
61
|
* @param {string} opts.name
|
|
62
62
|
* @param {object} [opts.options]
|
|
@@ -66,7 +66,15 @@ const select_options = (v, hdr, force_required, neutral_label = "") => {
|
|
|
66
66
|
* @param {...*} opts.rest
|
|
67
67
|
* @returns {string}
|
|
68
68
|
*/
|
|
69
|
-
const radio_group = ({
|
|
69
|
+
const radio_group = ({
|
|
70
|
+
name,
|
|
71
|
+
options,
|
|
72
|
+
value,
|
|
73
|
+
inline,
|
|
74
|
+
form_name,
|
|
75
|
+
onChange,
|
|
76
|
+
...rest
|
|
77
|
+
}) =>
|
|
70
78
|
div(
|
|
71
79
|
(options || [])
|
|
72
80
|
.filter((o) => (typeof o === "string" ? o : o.value))
|
|
@@ -79,6 +87,7 @@ const radio_group = ({ name, options, value, inline, form_name, ...rest }) =>
|
|
|
79
87
|
class: ["form-check-input", rest.class],
|
|
80
88
|
type: "radio",
|
|
81
89
|
name,
|
|
90
|
+
onChange,
|
|
82
91
|
"data-fieldname": form_name,
|
|
83
92
|
id,
|
|
84
93
|
value: text_attr(myvalue),
|
|
@@ -93,6 +102,44 @@ const radio_group = ({ name, options, value, inline, form_name, ...rest }) =>
|
|
|
93
102
|
.join("")
|
|
94
103
|
);
|
|
95
104
|
|
|
105
|
+
const checkbox_group = ({
|
|
106
|
+
name,
|
|
107
|
+
options,
|
|
108
|
+
value,
|
|
109
|
+
inline,
|
|
110
|
+
form_name,
|
|
111
|
+
onChange,
|
|
112
|
+
...rest
|
|
113
|
+
}) =>
|
|
114
|
+
div(
|
|
115
|
+
(options || [])
|
|
116
|
+
.filter((o) => (typeof o === "string" ? o : o.value))
|
|
117
|
+
.map((o, ix) => {
|
|
118
|
+
const myvalue = typeof o === "string" ? o : o.value;
|
|
119
|
+
const id = `input${text_attr(name)}${ix}`;
|
|
120
|
+
return div(
|
|
121
|
+
{ class: ["form-check", inline && "form-check-inline"] },
|
|
122
|
+
input({
|
|
123
|
+
class: ["form-check-input", rest.class],
|
|
124
|
+
type: "checkbox",
|
|
125
|
+
name,
|
|
126
|
+
onChange: `check_state_field(this)`,
|
|
127
|
+
"data-fieldname": form_name,
|
|
128
|
+
id,
|
|
129
|
+
value: text_attr(myvalue),
|
|
130
|
+
checked: Array.isArray(value)
|
|
131
|
+
? value.includes(myvalue)
|
|
132
|
+
: myvalue === value,
|
|
133
|
+
}),
|
|
134
|
+
label(
|
|
135
|
+
{ class: "form-check-label", for: id },
|
|
136
|
+
typeof o === "string" ? o : o.label
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
})
|
|
140
|
+
.join("")
|
|
141
|
+
);
|
|
142
|
+
|
|
96
143
|
/**
|
|
97
144
|
* @param {object} opts
|
|
98
145
|
* @param {number} opts.current_page
|
|
@@ -143,9 +190,9 @@ const pagination = ({
|
|
|
143
190
|
};
|
|
144
191
|
|
|
145
192
|
/**
|
|
146
|
-
* @param {string} name
|
|
147
|
-
* @param {object} v
|
|
148
|
-
* @param {object} param2
|
|
193
|
+
* @param {string} name
|
|
194
|
+
* @param {object} v
|
|
195
|
+
* @param {object} param2
|
|
149
196
|
* @returns {string}
|
|
150
197
|
*/
|
|
151
198
|
const search_bar = (
|
|
@@ -217,4 +264,5 @@ module.exports = {
|
|
|
217
264
|
search_bar,
|
|
218
265
|
pagination,
|
|
219
266
|
radio_group,
|
|
267
|
+
checkbox_group,
|
|
220
268
|
};
|
package/index.js
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
* @category saltcorn-markup
|
|
3
3
|
* @module saltcorn-markup/index
|
|
4
4
|
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* All files in the saltcorn-markup package.
|
|
8
|
+
* @namespace saltcorn-markup_overview
|
|
9
|
+
* @property {module:builder} builder
|
|
10
|
+
* @property {module:emergency_layout} emergency_layout
|
|
11
|
+
* @property {module:form} from
|
|
12
|
+
* @property {module:helpers} helpers
|
|
13
|
+
* @property {module:layout_utils} layout_utils
|
|
14
|
+
* @property {module:layout} layout
|
|
15
|
+
* @property {module:mktag} mktag
|
|
16
|
+
* @property {module:table} table
|
|
17
|
+
* @property {module:tabs} tabs
|
|
18
|
+
* @category saltcorn-markup
|
|
19
|
+
*/
|
|
20
|
+
|
|
5
21
|
const renderForm = require("./form");
|
|
6
22
|
const renderBuilder = require("./builder");
|
|
7
23
|
const mkTable = require("./table");
|
package/layout.js
CHANGED
|
@@ -34,7 +34,7 @@ const { search_bar_form, search_bar } = require("./helpers");
|
|
|
34
34
|
const couldHaveAlerts = (alerts) => alerts || Array.isArray(alerts);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* @param {string|object} body
|
|
37
|
+
* @param {string|object} body
|
|
38
38
|
* @param {object[]} [alerts]
|
|
39
39
|
* @returns {object}
|
|
40
40
|
*/
|
|
@@ -62,9 +62,9 @@ const makeSegments = (body, alerts) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param {object} segment
|
|
67
|
-
* @param {string} inner
|
|
65
|
+
*
|
|
66
|
+
* @param {object} segment
|
|
67
|
+
* @param {string} inner
|
|
68
68
|
* @returns {div|span|string}
|
|
69
69
|
*/
|
|
70
70
|
const applyTextStyle = (segment, inner) => {
|
|
@@ -97,10 +97,13 @@ const applyTextStyle = (segment, inner) => {
|
|
|
97
97
|
* @param {string[]} opts.titles
|
|
98
98
|
* @param {string} opts.tabsStyle
|
|
99
99
|
* @param {*} opts.ntabs
|
|
100
|
-
* @param {function} go
|
|
100
|
+
* @param {function} go
|
|
101
101
|
* @returns {ul_div}
|
|
102
102
|
*/
|
|
103
|
-
const renderTabs = (
|
|
103
|
+
const renderTabs = (
|
|
104
|
+
{ contents, titles, tabsStyle, ntabs, independent },
|
|
105
|
+
go
|
|
106
|
+
) => {
|
|
104
107
|
const rndid = `tab${Math.floor(Math.random() * 16777215).toString(16)}`;
|
|
105
108
|
if (tabsStyle === "Accordion")
|
|
106
109
|
return div(
|
|
@@ -130,7 +133,7 @@ const renderTabs = ({ contents, titles, tabsStyle, ntabs }, go) => {
|
|
|
130
133
|
class: ["collapse", ix === 0 && "show"],
|
|
131
134
|
id: `${rndid}tab${ix}`,
|
|
132
135
|
"aria-labelledby": `${rndid}head${ix}`,
|
|
133
|
-
"data-parent": `#${rndid}top`,
|
|
136
|
+
"data-parent": independent ? undefined : `#${rndid}top`,
|
|
134
137
|
},
|
|
135
138
|
div({ class: "card-body" }, go(t, false, ix))
|
|
136
139
|
)
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/markup",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2-beta.1",
|
|
4
4
|
"description": "Markup for Saltcorn, open-source no-code platform",
|
|
5
5
|
"homepage": "https://saltcorn.com",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jest"
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"tsc": "echo \"Error: no TypeScript support yet\"",
|
|
10
|
+
"clean": "echo \"Error: no TypeScript support yet\""
|
|
9
11
|
},
|
|
10
12
|
"author": "Tom Nielsen",
|
|
11
13
|
"license": "MIT",
|