@burger-editor/frozen-patty 0.10.0 → 4.0.0-alpha.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/LICENSE +1 -1
- package/README.md +26 -27
- package/dist/field-name-parser.d.ts +8 -0
- package/dist/field-name-parser.js +18 -0
- package/{lib → dist}/frozen-patty.d.ts +4 -18
- package/dist/frozen-patty.js +43 -0
- package/dist/get-value.d.ts +10 -0
- package/dist/get-value.js +15 -0
- package/dist/get-values.d.ts +9 -0
- package/dist/get-values.js +158 -0
- package/dist/get.d.ts +9 -0
- package/dist/get.js +19 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/set-value.d.ts +21 -0
- package/{lib/setValue.js → dist/set-value.js} +249 -221
- package/dist/set.d.ts +9 -0
- package/dist/set.js +60 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +37 -0
- package/package.json +35 -39
- package/lib/frozen-patty.d.ts.map +0 -1
- package/lib/frozen-patty.js +0 -47
- package/lib/frozen-patty.js.map +0 -1
- package/lib/get.d.ts +0 -4
- package/lib/get.d.ts.map +0 -1
- package/lib/get.js +0 -20
- package/lib/get.js.map +0 -1
- package/lib/getValue.d.ts +0 -10
- package/lib/getValue.d.ts.map +0 -1
- package/lib/getValue.js +0 -142
- package/lib/getValue.js.map +0 -1
- package/lib/index.d.ts +0 -35
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/polyfill.d.ts +0 -1
- package/lib/polyfill.d.ts.map +0 -1
- package/lib/polyfill.js +0 -20
- package/lib/polyfill.js.map +0 -1
- package/lib/set.d.ts +0 -4
- package/lib/set.d.ts.map +0 -1
- package/lib/set.js +0 -56
- package/lib/set.js.map +0 -1
- package/lib/setValue.d.ts +0 -15
- package/lib/setValue.d.ts.map +0 -1
- package/lib/setValue.js.map +0 -1
- package/lib/util.d.ts +0 -8
- package/lib/util.d.ts.map +0 -1
- package/lib/util.js +0 -30
- package/lib/util.js.map +0 -1
|
@@ -1,64 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { fieldNameParser } from './field-name-parser.js';
|
|
2
|
+
import { kebabCase } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* Set value to an element
|
|
5
5
|
*
|
|
6
6
|
* ```html
|
|
7
7
|
* <div [target-attribute] data-[attr]="[name]:[target-attribute]"></div>
|
|
8
8
|
* ```
|
|
9
|
-
*
|
|
9
|
+
* @param el A target element
|
|
10
10
|
* @param name A label name
|
|
11
11
|
* @param datum A datum of value
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
12
|
+
* @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
|
|
13
|
+
* @param filter
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* 抽出した対象キー
|
|
22
|
-
*/
|
|
23
|
-
var key = void 0;
|
|
24
|
-
/**
|
|
25
|
-
* 対象属性
|
|
26
|
-
*
|
|
27
|
-
* `null`の場合は`innerHTML`が対象となる
|
|
28
|
-
* ただし要素がinput要素の場合は`value`に設定
|
|
29
|
-
*/
|
|
30
|
-
var targetAttr = void 0;
|
|
31
|
-
//
|
|
32
|
-
// 対象属性名の抽出
|
|
33
|
-
//
|
|
34
|
-
if (/^[a-z_-](?:[a-z0-9_-])*:[a-z_-](?:[a-z0-9_-])*(?:\([a-z-]+\))?/i.test(bindingFormat)) {
|
|
35
|
-
var splitKey = bindingFormat.split(':');
|
|
36
|
-
key = splitKey[0].trim();
|
|
37
|
-
targetAttr = splitKey[1].trim();
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
key = bindingFormat.trim();
|
|
41
|
-
targetAttr = null;
|
|
42
|
-
}
|
|
43
|
-
//
|
|
44
|
-
// 対象キーが一致しなければスキップする
|
|
45
|
-
//
|
|
46
|
-
if (name !== key) {
|
|
15
|
+
export function setValue(el, name, datum, attr = 'field', filter) {
|
|
16
|
+
const rawValue = el.getAttribute(`data-${attr}`);
|
|
17
|
+
const fieldList = rawValue?.split(/\s*,\s*/) ?? [];
|
|
18
|
+
for (const field of fieldList) {
|
|
19
|
+
const { fieldName, propName } = fieldNameParser(field);
|
|
20
|
+
if (name !== fieldName) {
|
|
47
21
|
continue;
|
|
48
22
|
}
|
|
49
23
|
if (filter) {
|
|
50
24
|
datum = filter(datum);
|
|
51
25
|
}
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// style属性
|
|
58
|
-
//
|
|
59
|
-
if (/^style\([a-z-]+\)$/i.test(targetAttr)) {
|
|
60
|
-
var cssPropertyName = targetAttr.replace(/^style\(([a-z-]+)\)$/i, '$1');
|
|
61
|
-
var cssValue = void 0;
|
|
26
|
+
// console.log({ name, field, fieldName, propName, datum, el: el.innerHTML });
|
|
27
|
+
if (propName) {
|
|
28
|
+
if (/^style\([a-z-]+\)$/i.test(propName)) {
|
|
29
|
+
const cssPropertyName = propName.replace(/^style\(([a-z-]+)\)$/i, '$1');
|
|
30
|
+
let cssValue;
|
|
62
31
|
switch (cssPropertyName) {
|
|
63
32
|
case 'background-image': {
|
|
64
33
|
//
|
|
@@ -69,74 +38,93 @@ function default_1(name, datum, el, attr, filter) {
|
|
|
69
38
|
// デモサーバーから本番サーバーへの移行ができなくなってしまうので避ける
|
|
70
39
|
// 単純な文字列を流し込む(setAttributeを利用)
|
|
71
40
|
// urlはマルチバイト文字や空白記号を含まないはずであるがエスケープする
|
|
72
|
-
|
|
73
|
-
cssValue =
|
|
41
|
+
const url = encodeURI(`${datum}`);
|
|
42
|
+
cssValue = `url(${url})`;
|
|
74
43
|
break;
|
|
75
44
|
}
|
|
76
45
|
//
|
|
77
46
|
// TODO: 他にもvalueに単位が必要なケースなどに対応したい
|
|
78
47
|
//
|
|
79
48
|
default: {
|
|
80
|
-
cssValue =
|
|
49
|
+
cssValue = `${datum}`;
|
|
81
50
|
}
|
|
82
51
|
}
|
|
83
|
-
el.setAttribute('style',
|
|
84
|
-
//
|
|
85
|
-
// 属性
|
|
86
|
-
//
|
|
52
|
+
el.setAttribute('style', `${cssPropertyName}: ${cssValue}`);
|
|
87
53
|
}
|
|
88
54
|
else if (el instanceof HTMLElement) {
|
|
89
|
-
|
|
55
|
+
// HTMLElement
|
|
56
|
+
set(el, attr, propName, datum);
|
|
90
57
|
}
|
|
91
58
|
else {
|
|
92
59
|
// SVGElement or more
|
|
93
|
-
el.setAttribute(
|
|
94
|
-
}
|
|
95
|
-
//
|
|
96
|
-
// 属性指定がない場合
|
|
97
|
-
//
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
if (el instanceof HTMLInputElement ||
|
|
101
|
-
el instanceof HTMLSelectElement ||
|
|
102
|
-
el instanceof HTMLTextAreaElement) {
|
|
103
|
-
el.value = "".concat(datum);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
el.innerHTML = "".concat(datum);
|
|
60
|
+
el.setAttribute(propName, `${datum}`);
|
|
107
61
|
}
|
|
62
|
+
return;
|
|
108
63
|
}
|
|
64
|
+
setContent(el, datum);
|
|
109
65
|
}
|
|
110
66
|
}
|
|
111
|
-
exports.default = default_1;
|
|
112
67
|
/**
|
|
113
|
-
* Set attribute
|
|
114
|
-
*
|
|
115
|
-
* @param el Target HTML element
|
|
116
|
-
* @param attr Attribute name
|
|
117
|
-
* @param datum Datum
|
|
118
68
|
*
|
|
69
|
+
* @param el
|
|
70
|
+
* @param prefix
|
|
71
|
+
* @param name
|
|
72
|
+
* @param datum
|
|
119
73
|
*/
|
|
120
|
-
|
|
121
|
-
function setAttribute(el, attr, datum) {
|
|
74
|
+
function set(el, prefix, name, datum) {
|
|
122
75
|
if (datum == null) {
|
|
123
|
-
el.removeAttribute(
|
|
76
|
+
el.removeAttribute(name);
|
|
124
77
|
return;
|
|
125
78
|
}
|
|
126
|
-
switch (
|
|
127
|
-
|
|
128
|
-
|
|
79
|
+
switch (name) {
|
|
80
|
+
case 'text': {
|
|
81
|
+
setContent(el, datum, false);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
case 'html': {
|
|
85
|
+
setContent(el, datum, true);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
case 'node': {
|
|
89
|
+
if (typeof datum !== 'string') {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const nodeName = el.localName ?? el.nodeName.toLowerCase();
|
|
93
|
+
if (nodeName === datum.toLowerCase()) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const node = (el.ownerDocument ?? document).createElement(`${datum}`);
|
|
97
|
+
for (const child of el.childNodes) {
|
|
98
|
+
node.append(child.cloneNode(true));
|
|
99
|
+
}
|
|
100
|
+
for (const { name, value } of el.attributes) {
|
|
101
|
+
node.setAttribute(name, value);
|
|
102
|
+
}
|
|
103
|
+
el.replaceWith(node);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!name.startsWith('data-') && !(name in el)) {
|
|
108
|
+
const dataAttr = `data-${prefix}-${kebabCase(name)}`;
|
|
109
|
+
if (el.hasAttribute(dataAttr)) {
|
|
110
|
+
el.setAttribute(dataAttr, `${datum}`);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
switch (name) {
|
|
115
|
+
case 'contenteditable': {
|
|
129
116
|
switch (datum) {
|
|
117
|
+
case true:
|
|
130
118
|
case 'true':
|
|
131
119
|
case '': {
|
|
132
120
|
el.contentEditable = 'true';
|
|
133
121
|
break;
|
|
134
122
|
}
|
|
135
123
|
default: {
|
|
136
|
-
el.removeAttribute(
|
|
124
|
+
el.removeAttribute(name);
|
|
137
125
|
}
|
|
138
126
|
}
|
|
139
|
-
|
|
127
|
+
return;
|
|
140
128
|
}
|
|
141
129
|
case 'dir': {
|
|
142
130
|
switch (datum) {
|
|
@@ -145,12 +133,12 @@ function setAttribute(el, attr, datum) {
|
|
|
145
133
|
el.dir = datum;
|
|
146
134
|
break;
|
|
147
135
|
}
|
|
148
|
-
case 'auto':
|
|
136
|
+
// case 'auto':
|
|
149
137
|
default: {
|
|
150
|
-
el.removeAttribute(
|
|
138
|
+
el.removeAttribute(name);
|
|
151
139
|
}
|
|
152
140
|
}
|
|
153
|
-
|
|
141
|
+
return;
|
|
154
142
|
}
|
|
155
143
|
case 'draggable': {
|
|
156
144
|
if (typeof datum === 'boolean') {
|
|
@@ -166,52 +154,57 @@ function setAttribute(el, attr, datum) {
|
|
|
166
154
|
el.draggable = false;
|
|
167
155
|
break;
|
|
168
156
|
}
|
|
169
|
-
case 'auto':
|
|
157
|
+
// case 'auto':
|
|
170
158
|
default: {
|
|
171
|
-
el.removeAttribute(
|
|
159
|
+
el.removeAttribute(name);
|
|
172
160
|
}
|
|
173
161
|
}
|
|
174
|
-
|
|
162
|
+
return;
|
|
175
163
|
}
|
|
176
164
|
case 'hidden': {
|
|
165
|
+
if (datum === 'until-found') {
|
|
166
|
+
el.setAttribute(name, datum);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
177
169
|
el.hidden = !!datum;
|
|
178
|
-
|
|
170
|
+
return;
|
|
179
171
|
}
|
|
180
172
|
case 'spellcheck': {
|
|
181
173
|
el.spellcheck = !!datum;
|
|
182
|
-
|
|
174
|
+
return;
|
|
183
175
|
}
|
|
184
176
|
case 'tabindex': {
|
|
185
|
-
|
|
177
|
+
let i;
|
|
186
178
|
if (typeof datum === 'boolean') {
|
|
187
179
|
i = datum ? 0 : -1;
|
|
188
180
|
}
|
|
189
181
|
else if (typeof datum === 'string') {
|
|
190
|
-
i = parseInt(datum, 10);
|
|
182
|
+
i = Number.parseInt(datum, 10);
|
|
191
183
|
}
|
|
192
184
|
else {
|
|
193
185
|
i = datum;
|
|
194
186
|
}
|
|
195
|
-
el.tabIndex = isNaN(i) ? -1 : Math.floor(i);
|
|
196
|
-
|
|
187
|
+
el.tabIndex = Number.isNaN(i) ? -1 : Math.floor(i);
|
|
188
|
+
return;
|
|
197
189
|
}
|
|
198
190
|
case 'async': {
|
|
199
191
|
if (el instanceof HTMLScriptElement) {
|
|
200
192
|
el.async = !!datum;
|
|
201
193
|
}
|
|
202
194
|
else {
|
|
203
|
-
el.setAttribute(
|
|
195
|
+
el.setAttribute(name, `${datum}`);
|
|
204
196
|
}
|
|
205
|
-
|
|
197
|
+
return;
|
|
206
198
|
}
|
|
207
199
|
case 'autocomplete': {
|
|
208
200
|
if (el instanceof HTMLInputElement || el instanceof HTMLFormElement) {
|
|
209
|
-
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
el.autocomplete = datum ? `${datum}` : 'off';
|
|
210
203
|
}
|
|
211
204
|
else {
|
|
212
|
-
el.setAttribute(
|
|
205
|
+
el.setAttribute(name, `${datum}`);
|
|
213
206
|
}
|
|
214
|
-
|
|
207
|
+
return;
|
|
215
208
|
}
|
|
216
209
|
case 'autofocus': {
|
|
217
210
|
if (el instanceof HTMLButtonElement ||
|
|
@@ -221,84 +214,84 @@ function setAttribute(el, attr, datum) {
|
|
|
221
214
|
el.autofocus = datum === '' ? true : !!datum;
|
|
222
215
|
}
|
|
223
216
|
else {
|
|
224
|
-
el.setAttribute(
|
|
217
|
+
el.setAttribute(name, `${datum}`);
|
|
225
218
|
}
|
|
226
|
-
|
|
219
|
+
return;
|
|
227
220
|
}
|
|
228
221
|
case 'autoplay': {
|
|
229
222
|
if (el instanceof HTMLAudioElement || el instanceof HTMLVideoElement) {
|
|
230
223
|
el.autoplay = datum === '' ? true : !!datum;
|
|
231
224
|
}
|
|
232
225
|
else {
|
|
233
|
-
el.setAttribute(
|
|
226
|
+
el.setAttribute(name, `${datum}`);
|
|
234
227
|
}
|
|
235
|
-
|
|
228
|
+
return;
|
|
236
229
|
}
|
|
237
230
|
case 'checked': {
|
|
238
231
|
if (el instanceof HTMLInputElement) {
|
|
239
232
|
el.checked = datum === '' ? true : !!datum;
|
|
240
233
|
}
|
|
241
234
|
else {
|
|
242
|
-
el.setAttribute(
|
|
235
|
+
el.setAttribute(name, `${datum}`);
|
|
243
236
|
}
|
|
244
|
-
|
|
237
|
+
return;
|
|
245
238
|
}
|
|
246
239
|
case 'cols': {
|
|
247
240
|
if (el instanceof HTMLTextAreaElement) {
|
|
248
|
-
|
|
249
|
-
if (isNaN(cols)) {
|
|
250
|
-
el.removeAttribute(
|
|
241
|
+
const cols = toInt(datum);
|
|
242
|
+
if (Number.isNaN(cols)) {
|
|
243
|
+
el.removeAttribute(name);
|
|
251
244
|
}
|
|
252
245
|
else {
|
|
253
246
|
el.cols = cols;
|
|
254
247
|
}
|
|
255
248
|
}
|
|
256
249
|
else {
|
|
257
|
-
el.setAttribute(
|
|
250
|
+
el.setAttribute(name, `${datum}`);
|
|
258
251
|
}
|
|
259
|
-
|
|
252
|
+
return;
|
|
260
253
|
}
|
|
261
254
|
case 'colspan': {
|
|
262
255
|
if (el instanceof HTMLTableCellElement) {
|
|
263
|
-
|
|
264
|
-
if (isNaN(colSpan)) {
|
|
265
|
-
el.removeAttribute(
|
|
256
|
+
const colSpan = toInt(datum);
|
|
257
|
+
if (Number.isNaN(colSpan)) {
|
|
258
|
+
el.removeAttribute(name);
|
|
266
259
|
}
|
|
267
260
|
else {
|
|
268
261
|
el.colSpan = colSpan;
|
|
269
262
|
}
|
|
270
263
|
}
|
|
271
264
|
else {
|
|
272
|
-
el.setAttribute(
|
|
265
|
+
el.setAttribute(name, `${datum}`);
|
|
273
266
|
}
|
|
274
|
-
|
|
267
|
+
return;
|
|
275
268
|
}
|
|
276
269
|
case 'controls': {
|
|
277
270
|
if (el instanceof HTMLAudioElement || el instanceof HTMLVideoElement) {
|
|
278
271
|
el.controls = datum === '' ? true : !!datum;
|
|
279
272
|
}
|
|
280
273
|
else {
|
|
281
|
-
el.setAttribute(
|
|
274
|
+
el.setAttribute(name, `${datum}`);
|
|
282
275
|
}
|
|
283
|
-
|
|
276
|
+
return;
|
|
284
277
|
}
|
|
285
278
|
case 'default': {
|
|
286
279
|
if (el instanceof HTMLTrackElement) {
|
|
287
280
|
el.default = datum === '' ? true : !!datum;
|
|
288
281
|
}
|
|
289
282
|
else {
|
|
290
|
-
el.setAttribute(
|
|
283
|
+
el.setAttribute(name, `${datum}`);
|
|
291
284
|
}
|
|
292
|
-
|
|
285
|
+
return;
|
|
293
286
|
}
|
|
294
287
|
case 'defer': {
|
|
295
288
|
if (el instanceof HTMLScriptElement) {
|
|
296
289
|
el.defer = !!datum;
|
|
297
290
|
}
|
|
298
291
|
else {
|
|
299
|
-
el.setAttribute(
|
|
292
|
+
el.setAttribute(name, `${datum}`);
|
|
300
293
|
}
|
|
301
|
-
|
|
294
|
+
return;
|
|
302
295
|
}
|
|
303
296
|
case 'disabled': {
|
|
304
297
|
if (el instanceof HTMLButtonElement ||
|
|
@@ -311,160 +304,160 @@ function setAttribute(el, attr, datum) {
|
|
|
311
304
|
el.disabled = datum === '' ? true : !!datum;
|
|
312
305
|
}
|
|
313
306
|
else {
|
|
314
|
-
el.setAttribute(
|
|
307
|
+
el.setAttribute(name, `${datum}`);
|
|
315
308
|
}
|
|
316
|
-
|
|
309
|
+
return;
|
|
317
310
|
}
|
|
318
311
|
case 'download': {
|
|
319
312
|
if (el instanceof HTMLAnchorElement) {
|
|
320
313
|
if (datum || datum === '') {
|
|
321
|
-
el.download =
|
|
314
|
+
el.download = `${datum}`;
|
|
322
315
|
}
|
|
323
316
|
else {
|
|
324
|
-
el.removeAttribute(
|
|
317
|
+
el.removeAttribute(name);
|
|
325
318
|
}
|
|
326
319
|
}
|
|
327
320
|
else {
|
|
328
|
-
el.setAttribute(
|
|
321
|
+
el.setAttribute(name, `${datum}`);
|
|
329
322
|
}
|
|
330
|
-
|
|
323
|
+
return;
|
|
331
324
|
}
|
|
332
325
|
case 'high': {
|
|
333
326
|
if (el instanceof HTMLMeterElement) {
|
|
334
|
-
|
|
335
|
-
if (isNaN(high)) {
|
|
336
|
-
el.removeAttribute(
|
|
327
|
+
const high = toInt(datum);
|
|
328
|
+
if (Number.isNaN(high)) {
|
|
329
|
+
el.removeAttribute(name);
|
|
337
330
|
}
|
|
338
331
|
else {
|
|
339
332
|
el.high = high;
|
|
340
333
|
}
|
|
341
334
|
}
|
|
342
335
|
else {
|
|
343
|
-
el.setAttribute(
|
|
336
|
+
el.setAttribute(name, `${datum}`);
|
|
344
337
|
}
|
|
345
|
-
|
|
338
|
+
return;
|
|
346
339
|
}
|
|
347
340
|
case 'ismap': {
|
|
348
341
|
if (el instanceof HTMLImageElement) {
|
|
349
342
|
el.isMap = datum === '' ? true : !!datum;
|
|
350
343
|
}
|
|
351
344
|
else {
|
|
352
|
-
el.setAttribute(
|
|
345
|
+
el.setAttribute(name, `${datum}`);
|
|
353
346
|
}
|
|
354
|
-
|
|
347
|
+
return;
|
|
355
348
|
}
|
|
356
349
|
case 'loop': {
|
|
357
350
|
if (el instanceof HTMLAudioElement || el instanceof HTMLVideoElement) {
|
|
358
351
|
el.loop = datum === '' ? true : !!datum;
|
|
359
352
|
}
|
|
360
353
|
else {
|
|
361
|
-
el.setAttribute(
|
|
354
|
+
el.setAttribute(name, `${datum}`);
|
|
362
355
|
}
|
|
363
|
-
|
|
356
|
+
return;
|
|
364
357
|
}
|
|
365
358
|
case 'low': {
|
|
366
359
|
if (el instanceof HTMLMeterElement) {
|
|
367
|
-
|
|
368
|
-
if (isNaN(low)) {
|
|
369
|
-
el.removeAttribute(
|
|
360
|
+
const low = toInt(datum);
|
|
361
|
+
if (Number.isNaN(low)) {
|
|
362
|
+
el.removeAttribute(name);
|
|
370
363
|
}
|
|
371
364
|
else {
|
|
372
365
|
el.low = low;
|
|
373
366
|
}
|
|
374
367
|
}
|
|
375
368
|
else {
|
|
376
|
-
el.setAttribute(
|
|
369
|
+
el.setAttribute(name, `${datum}`);
|
|
377
370
|
}
|
|
378
|
-
|
|
371
|
+
return;
|
|
379
372
|
}
|
|
380
373
|
case 'max': {
|
|
381
374
|
if (el instanceof HTMLInputElement ||
|
|
382
375
|
el instanceof HTMLMeterElement ||
|
|
383
376
|
el instanceof HTMLProgressElement) {
|
|
384
|
-
|
|
385
|
-
if (isNaN(max)) {
|
|
386
|
-
el.removeAttribute(
|
|
377
|
+
const max = toInt(datum);
|
|
378
|
+
if (Number.isNaN(max)) {
|
|
379
|
+
el.removeAttribute(name);
|
|
387
380
|
}
|
|
388
381
|
else {
|
|
389
382
|
el.max = max;
|
|
390
383
|
}
|
|
391
384
|
}
|
|
392
385
|
else {
|
|
393
|
-
el.setAttribute(
|
|
386
|
+
el.setAttribute(name, `${datum}`);
|
|
394
387
|
}
|
|
395
|
-
|
|
388
|
+
return;
|
|
396
389
|
}
|
|
397
390
|
case 'maxlength': {
|
|
398
391
|
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
399
|
-
|
|
400
|
-
if (isNaN(maxLength)) {
|
|
401
|
-
el.removeAttribute(
|
|
392
|
+
const maxLength = toInt(datum);
|
|
393
|
+
if (Number.isNaN(maxLength)) {
|
|
394
|
+
el.removeAttribute(name);
|
|
402
395
|
}
|
|
403
396
|
else {
|
|
404
397
|
el.maxLength = Math.floor(maxLength);
|
|
405
398
|
}
|
|
406
399
|
}
|
|
407
400
|
else {
|
|
408
|
-
el.setAttribute(
|
|
401
|
+
el.setAttribute(name, `${datum}`);
|
|
409
402
|
}
|
|
410
|
-
|
|
403
|
+
return;
|
|
411
404
|
}
|
|
412
405
|
case 'min': {
|
|
413
406
|
if (el instanceof HTMLInputElement || el instanceof HTMLMeterElement) {
|
|
414
|
-
|
|
415
|
-
if (isNaN(min)) {
|
|
416
|
-
el.removeAttribute(
|
|
407
|
+
const min = toInt(datum);
|
|
408
|
+
if (Number.isNaN(min)) {
|
|
409
|
+
el.removeAttribute(name);
|
|
417
410
|
}
|
|
418
411
|
else {
|
|
419
412
|
el.min = min;
|
|
420
413
|
}
|
|
421
414
|
}
|
|
422
415
|
else {
|
|
423
|
-
el.setAttribute(
|
|
416
|
+
el.setAttribute(name, `${datum}`);
|
|
424
417
|
}
|
|
425
|
-
|
|
418
|
+
return;
|
|
426
419
|
}
|
|
427
420
|
case 'multiple': {
|
|
428
421
|
if (el instanceof HTMLInputElement || el instanceof HTMLSelectElement) {
|
|
429
422
|
el.multiple = datum === '' ? true : !!datum;
|
|
430
423
|
}
|
|
431
424
|
else {
|
|
432
|
-
el.setAttribute(
|
|
425
|
+
el.setAttribute(name, `${datum}`);
|
|
433
426
|
}
|
|
434
|
-
|
|
427
|
+
return;
|
|
435
428
|
}
|
|
436
429
|
case 'novalidate': {
|
|
437
430
|
if (el instanceof HTMLFormElement) {
|
|
438
431
|
el.noValidate = datum === '' ? true : !!datum;
|
|
439
432
|
}
|
|
440
433
|
else {
|
|
441
|
-
el.setAttribute(
|
|
434
|
+
el.setAttribute(name, `${datum}`);
|
|
435
|
+
}
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
case 'open': {
|
|
439
|
+
if (el instanceof HTMLDetailsElement) {
|
|
440
|
+
el.open = datum === '' ? true : !!datum;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
el.setAttribute(name, `${datum}`);
|
|
442
444
|
}
|
|
443
445
|
break;
|
|
444
446
|
}
|
|
445
|
-
// ⚰️ Unsupported HTMLDetailsElement yet...
|
|
446
|
-
// case 'oepn': {
|
|
447
|
-
// if (el instanceof HTMLDetailsElement) {
|
|
448
|
-
// el.oepn = datum === '' ? true : !!datum;
|
|
449
|
-
// } else {
|
|
450
|
-
// el.setAttribute(attr, `${datum}`);
|
|
451
|
-
// }
|
|
452
|
-
// break;
|
|
453
|
-
// }
|
|
454
447
|
case 'optimum': {
|
|
455
448
|
if (el instanceof HTMLMeterElement) {
|
|
456
|
-
|
|
457
|
-
if (isNaN(optimum)) {
|
|
458
|
-
el.removeAttribute(
|
|
449
|
+
const optimum = toInt(datum);
|
|
450
|
+
if (Number.isNaN(optimum)) {
|
|
451
|
+
el.removeAttribute(name);
|
|
459
452
|
}
|
|
460
453
|
else {
|
|
461
454
|
el.optimum = Math.floor(optimum);
|
|
462
455
|
}
|
|
463
456
|
}
|
|
464
457
|
else {
|
|
465
|
-
el.setAttribute(
|
|
458
|
+
el.setAttribute(name, `${datum}`);
|
|
466
459
|
}
|
|
467
|
-
|
|
460
|
+
return;
|
|
468
461
|
}
|
|
469
462
|
case 'preload': {
|
|
470
463
|
if (el instanceof HTMLAudioElement || el instanceof HTMLVideoElement) {
|
|
@@ -481,18 +474,18 @@ function setAttribute(el, attr, datum) {
|
|
|
481
474
|
}
|
|
482
475
|
}
|
|
483
476
|
else {
|
|
484
|
-
el.setAttribute(
|
|
477
|
+
el.setAttribute(name, `${datum}`);
|
|
485
478
|
}
|
|
486
|
-
|
|
479
|
+
return;
|
|
487
480
|
}
|
|
488
481
|
case 'readonly': {
|
|
489
482
|
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
490
483
|
el.readOnly = datum === '' ? true : !!datum;
|
|
491
484
|
}
|
|
492
485
|
else {
|
|
493
|
-
el.setAttribute(
|
|
486
|
+
el.setAttribute(name, `${datum}`);
|
|
494
487
|
}
|
|
495
|
-
|
|
488
|
+
return;
|
|
496
489
|
}
|
|
497
490
|
case 'required': {
|
|
498
491
|
if (el instanceof HTMLInputElement ||
|
|
@@ -501,94 +494,93 @@ function setAttribute(el, attr, datum) {
|
|
|
501
494
|
el.required = datum === '' ? true : !!datum;
|
|
502
495
|
}
|
|
503
496
|
else {
|
|
504
|
-
el.setAttribute(
|
|
497
|
+
el.setAttribute(name, `${datum}`);
|
|
505
498
|
}
|
|
506
|
-
|
|
499
|
+
return;
|
|
507
500
|
}
|
|
508
501
|
case 'reversed': {
|
|
509
502
|
if (el instanceof HTMLOListElement) {
|
|
510
|
-
// tslint:disable-next-line:no-any
|
|
511
503
|
el.reversed = datum === '' ? true : !!datum;
|
|
512
504
|
}
|
|
513
505
|
else {
|
|
514
|
-
el.setAttribute(
|
|
506
|
+
el.setAttribute(name, `${datum}`);
|
|
515
507
|
}
|
|
516
|
-
|
|
508
|
+
return;
|
|
517
509
|
}
|
|
518
510
|
case 'rows': {
|
|
519
511
|
if (el instanceof HTMLTextAreaElement) {
|
|
520
|
-
|
|
521
|
-
if (isNaN(rows)) {
|
|
522
|
-
el.removeAttribute(
|
|
512
|
+
const rows = toInt(datum);
|
|
513
|
+
if (Number.isNaN(rows)) {
|
|
514
|
+
el.removeAttribute(name);
|
|
523
515
|
}
|
|
524
516
|
else {
|
|
525
517
|
el.rows = Math.floor(rows);
|
|
526
518
|
}
|
|
527
519
|
}
|
|
528
520
|
else {
|
|
529
|
-
el.setAttribute(
|
|
521
|
+
el.setAttribute(name, `${datum}`);
|
|
530
522
|
}
|
|
531
|
-
|
|
523
|
+
return;
|
|
532
524
|
}
|
|
533
525
|
case 'rowspan': {
|
|
534
526
|
if (el instanceof HTMLTableCellElement) {
|
|
535
|
-
|
|
536
|
-
if (isNaN(rowSpan)) {
|
|
537
|
-
el.removeAttribute(
|
|
527
|
+
const rowSpan = toInt(datum);
|
|
528
|
+
if (Number.isNaN(rowSpan)) {
|
|
529
|
+
el.removeAttribute(name);
|
|
538
530
|
}
|
|
539
531
|
else {
|
|
540
532
|
el.rowSpan = Math.floor(rowSpan);
|
|
541
533
|
}
|
|
542
534
|
}
|
|
543
535
|
else {
|
|
544
|
-
el.setAttribute(
|
|
536
|
+
el.setAttribute(name, `${datum}`);
|
|
545
537
|
}
|
|
546
|
-
|
|
538
|
+
return;
|
|
547
539
|
}
|
|
548
540
|
case 'size': {
|
|
549
541
|
if (el instanceof HTMLInputElement || el instanceof HTMLSelectElement) {
|
|
550
|
-
|
|
551
|
-
if (isNaN(size)) {
|
|
552
|
-
el.removeAttribute(
|
|
542
|
+
const size = toInt(datum);
|
|
543
|
+
if (Number.isNaN(size)) {
|
|
544
|
+
el.removeAttribute(name);
|
|
553
545
|
}
|
|
554
546
|
else {
|
|
555
547
|
el.size = size;
|
|
556
548
|
}
|
|
557
549
|
}
|
|
558
550
|
else {
|
|
559
|
-
el.setAttribute(
|
|
551
|
+
el.setAttribute(name, `${datum}`);
|
|
560
552
|
}
|
|
561
|
-
|
|
553
|
+
return;
|
|
562
554
|
}
|
|
563
555
|
case 'span': {
|
|
564
556
|
if (el instanceof HTMLTableColElement) {
|
|
565
|
-
|
|
566
|
-
if (isNaN(span)) {
|
|
567
|
-
el.removeAttribute(
|
|
557
|
+
const span = toInt(datum);
|
|
558
|
+
if (Number.isNaN(span)) {
|
|
559
|
+
el.removeAttribute(name);
|
|
568
560
|
}
|
|
569
561
|
else {
|
|
570
562
|
el.span = span;
|
|
571
563
|
}
|
|
572
564
|
}
|
|
573
565
|
else {
|
|
574
|
-
el.setAttribute(
|
|
566
|
+
el.setAttribute(name, `${datum}`);
|
|
575
567
|
}
|
|
576
|
-
|
|
568
|
+
return;
|
|
577
569
|
}
|
|
578
570
|
case 'start': {
|
|
579
571
|
if (el instanceof HTMLOListElement) {
|
|
580
|
-
|
|
581
|
-
if (isNaN(start)) {
|
|
582
|
-
el.removeAttribute(
|
|
572
|
+
const start = toInt(datum);
|
|
573
|
+
if (Number.isNaN(start)) {
|
|
574
|
+
el.removeAttribute(name);
|
|
583
575
|
}
|
|
584
576
|
else {
|
|
585
577
|
el.start = start;
|
|
586
578
|
}
|
|
587
579
|
}
|
|
588
580
|
else {
|
|
589
|
-
el.setAttribute(
|
|
581
|
+
el.setAttribute(name, `${datum}`);
|
|
590
582
|
}
|
|
591
|
-
|
|
583
|
+
return;
|
|
592
584
|
}
|
|
593
585
|
case 'step': {
|
|
594
586
|
if (el instanceof HTMLInputElement) {
|
|
@@ -596,34 +588,34 @@ function setAttribute(el, attr, datum) {
|
|
|
596
588
|
el.step = datum;
|
|
597
589
|
break;
|
|
598
590
|
}
|
|
599
|
-
|
|
600
|
-
if (isNaN(step)) {
|
|
601
|
-
el.removeAttribute(
|
|
591
|
+
const step = toNum(datum);
|
|
592
|
+
if (Number.isNaN(step)) {
|
|
593
|
+
el.removeAttribute(name);
|
|
602
594
|
}
|
|
603
595
|
else {
|
|
604
596
|
el.step = step.toString(10);
|
|
605
597
|
}
|
|
606
598
|
}
|
|
607
599
|
else {
|
|
608
|
-
el.setAttribute(
|
|
600
|
+
el.setAttribute(name, `${datum}`);
|
|
609
601
|
}
|
|
610
|
-
|
|
602
|
+
return;
|
|
611
603
|
}
|
|
612
604
|
case 'target': {
|
|
613
605
|
if (el instanceof HTMLAnchorElement ||
|
|
614
606
|
el instanceof HTMLAreaElement ||
|
|
615
607
|
el instanceof HTMLFormElement) {
|
|
616
608
|
if (datum) {
|
|
617
|
-
el.target =
|
|
609
|
+
el.target = `${datum}`;
|
|
618
610
|
}
|
|
619
611
|
else {
|
|
620
|
-
el.removeAttribute(
|
|
612
|
+
el.removeAttribute(name);
|
|
621
613
|
}
|
|
622
614
|
}
|
|
623
615
|
else {
|
|
624
|
-
el.setAttribute(
|
|
616
|
+
el.setAttribute(name, `${datum}`);
|
|
625
617
|
}
|
|
626
|
-
|
|
618
|
+
return;
|
|
627
619
|
}
|
|
628
620
|
// case 'accesskey':
|
|
629
621
|
// case 'class':
|
|
@@ -675,24 +667,60 @@ function setAttribute(el, attr, datum) {
|
|
|
675
667
|
// case 'wrap':
|
|
676
668
|
// and Data-* attributes
|
|
677
669
|
default: {
|
|
678
|
-
el.setAttribute(
|
|
670
|
+
el.setAttribute(name, `${datum}`);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
*
|
|
676
|
+
* @param el
|
|
677
|
+
* @param datum
|
|
678
|
+
* @param asHtml
|
|
679
|
+
*/
|
|
680
|
+
export function setContent(el, datum, asHtml = true) {
|
|
681
|
+
if (el instanceof HTMLInputElement ||
|
|
682
|
+
el instanceof HTMLSelectElement ||
|
|
683
|
+
el instanceof HTMLTextAreaElement ||
|
|
684
|
+
el instanceof HTMLOutputElement) {
|
|
685
|
+
if (el instanceof HTMLInputElement &&
|
|
686
|
+
(el.type === 'radio' || el.type === 'checkbox')) {
|
|
687
|
+
if (typeof datum === 'boolean') {
|
|
688
|
+
el.checked = datum;
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
el.checked = el.value === `${datum}`;
|
|
692
|
+
return;
|
|
679
693
|
}
|
|
694
|
+
el.value = `${datum}`;
|
|
695
|
+
return;
|
|
680
696
|
}
|
|
697
|
+
if (asHtml) {
|
|
698
|
+
el.innerHTML = datum == null ? '' : `${datum}`;
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
el.textContent = datum == null ? '' : `${datum}`;
|
|
681
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
*
|
|
705
|
+
* @param datum
|
|
706
|
+
*/
|
|
682
707
|
function toNum(datum) {
|
|
683
|
-
|
|
708
|
+
let i;
|
|
684
709
|
if (typeof datum === 'boolean') {
|
|
685
710
|
i = +datum;
|
|
686
711
|
}
|
|
687
712
|
else if (typeof datum === 'string') {
|
|
688
|
-
i = parseFloat(datum);
|
|
713
|
+
i = Number.parseFloat(datum);
|
|
689
714
|
}
|
|
690
715
|
else {
|
|
691
716
|
i = datum;
|
|
692
717
|
}
|
|
693
718
|
return i;
|
|
694
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
*
|
|
722
|
+
* @param datum
|
|
723
|
+
*/
|
|
695
724
|
function toInt(datum) {
|
|
696
725
|
return Math.floor(toNum(datum));
|
|
697
726
|
}
|
|
698
|
-
//# sourceMappingURL=setValue.js.map
|