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