@ktjs/shortcuts 0.7.3 → 0.19.0
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 +5 -1
- package/dist/index.d.ts +2 -73
- package/dist/index.iife.js +55 -106
- package/dist/index.legacy.js +1 -82
- package/dist/index.mjs +2 -52
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
<img src="https://raw.githubusercontent.com/baendlorel/kt.js/dev/.assets/ktjs-0.0.1.svg" alt="KT.js Logo" width="150"/>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@ktjs/shortcuts)
|
|
6
|
+
|
|
7
|
+
> 📦 Part of [KT.js](https://github.com/baendlorel/kt.js) - A simple and easy-to-use web framework that never re-renders.
|
|
6
8
|
|
|
7
9
|
Convenient shortcut functions for common DOM operations in KT.js.
|
|
8
10
|
|
|
11
|
+
**Current Version:** 0.7.3
|
|
12
|
+
|
|
9
13
|
## Overview
|
|
10
14
|
|
|
11
15
|
`@ktjs/shortcuts` provides convenient shorthand functions and utilities to make working with KT.js even more productive. It includes shortcuts for all HTML elements, form helpers, layout utilities, and the powerful `withDefaults` function for creating element factories with predefined properties.
|
package/dist/index.d.ts
CHANGED
|
@@ -24,78 +24,7 @@ declare const tbody: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawCon
|
|
|
24
24
|
declare const tr: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) => HTMLTableRowElement;
|
|
25
25
|
declare const th: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) => HTMLTableCellElement;
|
|
26
26
|
declare const td: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) => HTMLTableCellElement;
|
|
27
|
-
declare const a: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) =>
|
|
27
|
+
declare const a: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) => SVGAElement;
|
|
28
28
|
declare const img: (attr?: _ktjs_core.KTRawAttr, content?: _ktjs_core.KTRawContent) => HTMLImageElement;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Used to create enhanced HTML elements
|
|
34
|
-
*/
|
|
35
|
-
interface KTBaseAttribute {
|
|
36
|
-
[k: string]: any;
|
|
37
|
-
|
|
38
|
-
id?: string;
|
|
39
|
-
class?: string;
|
|
40
|
-
style?: string | Partial<CSSStyleDeclaration>;
|
|
41
|
-
|
|
42
|
-
type?:
|
|
43
|
-
| 'text'
|
|
44
|
-
| 'password'
|
|
45
|
-
| 'email'
|
|
46
|
-
| 'number'
|
|
47
|
-
| 'tel'
|
|
48
|
-
| 'url'
|
|
49
|
-
| 'search'
|
|
50
|
-
| 'date'
|
|
51
|
-
| 'datetime-local'
|
|
52
|
-
| 'time'
|
|
53
|
-
| 'month'
|
|
54
|
-
| 'week'
|
|
55
|
-
| 'color'
|
|
56
|
-
| 'range'
|
|
57
|
-
| 'file'
|
|
58
|
-
| 'checkbox'
|
|
59
|
-
| 'radio'
|
|
60
|
-
| 'hidden'
|
|
61
|
-
| 'submit'
|
|
62
|
-
| 'reset'
|
|
63
|
-
| 'button'
|
|
64
|
-
| 'image'
|
|
65
|
-
| otherstring;
|
|
66
|
-
for?: string;
|
|
67
|
-
|
|
68
|
-
name?: string;
|
|
69
|
-
value?: string;
|
|
70
|
-
valueAsDate?: Date;
|
|
71
|
-
valueAsNumber?: number;
|
|
72
|
-
label?: string;
|
|
73
|
-
disabled?: boolean;
|
|
74
|
-
|
|
75
|
-
min?: string | number;
|
|
76
|
-
max?: string | number;
|
|
77
|
-
step?: string | number;
|
|
78
|
-
|
|
79
|
-
selected?: boolean;
|
|
80
|
-
checked?: boolean;
|
|
81
|
-
|
|
82
|
-
action?: string;
|
|
83
|
-
method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
type KTPrefixedEventHandlers = {
|
|
87
|
-
[EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Wrap `h`(or its shortcuts) with default attributes.
|
|
94
|
-
* - `defaultAttr.class` will be merged with the provided `class` attribute.
|
|
95
|
-
* @param func `h` or its shortcuts.
|
|
96
|
-
* @param defaultAttr default KTAttribute, must be an object.
|
|
97
|
-
* @returns new h function with default attributes.
|
|
98
|
-
*/
|
|
99
|
-
declare const withDefaults: <F extends (...args: any) => any>(func: F, defaultAttr: KTAttribute) => F;
|
|
100
|
-
|
|
101
|
-
export { a, btn, div, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul, withDefaults };
|
|
30
|
+
export { a, btn, div, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul };
|
package/dist/index.iife.js
CHANGED
|
@@ -1,113 +1,62 @@
|
|
|
1
1
|
var __ktjs_shortcuts__ = (function (exports, core) {
|
|
2
|
-
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const newFunc = (attr, content) => {
|
|
6
|
-
return core.h(tag, attr, content);
|
|
7
|
-
};
|
|
8
|
-
window.__ktjs__.mark(newFunc, tag);
|
|
9
|
-
return newFunc;
|
|
10
|
-
};
|
|
4
|
+
const aliasH = (tag) => (attr, content) => core.h(tag, attr, content);
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
const div = aliasH('div');
|
|
7
|
+
const span = aliasH('span');
|
|
8
|
+
const label = aliasH('label');
|
|
9
|
+
const p = aliasH('p');
|
|
10
|
+
const h1 = aliasH('h1');
|
|
11
|
+
const h2 = aliasH('h2');
|
|
12
|
+
const h3 = aliasH('h3');
|
|
13
|
+
const h4 = aliasH('h4');
|
|
14
|
+
const h5 = aliasH('h5');
|
|
15
|
+
const h6 = aliasH('h6');
|
|
16
|
+
const ul = aliasH('ul');
|
|
17
|
+
const ol = aliasH('ol');
|
|
18
|
+
const li = aliasH('li');
|
|
19
|
+
const btn = aliasH('button');
|
|
20
|
+
const form = aliasH('form');
|
|
21
|
+
const input = aliasH('input');
|
|
22
|
+
const select = aliasH('select');
|
|
23
|
+
const option = aliasH('option');
|
|
24
|
+
const table = aliasH('table');
|
|
25
|
+
const thead = aliasH('thead');
|
|
26
|
+
const tbody = aliasH('tbody');
|
|
27
|
+
const tr = aliasH('tr');
|
|
28
|
+
const th = aliasH('th');
|
|
29
|
+
const td = aliasH('td');
|
|
30
|
+
const a = aliasH('a');
|
|
31
|
+
const img = aliasH('img');
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
: (attr) => {
|
|
68
|
-
if (typeof attr === 'string') {
|
|
69
|
-
return { ...defaultAttr, class: attr };
|
|
70
|
-
}
|
|
71
|
-
else if (attr && typeof attr === 'object') {
|
|
72
|
-
return { ...defaultAttr, ...attr };
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
if (func.__ktjs_h__ === 'h') {
|
|
76
|
-
return ((tag, attr, content) => func(tag, merge(attr), content));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return ((attr, content) => func(merge(attr), content));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
33
|
+
exports.a = a;
|
|
34
|
+
exports.btn = btn;
|
|
35
|
+
exports.div = div;
|
|
36
|
+
exports.form = form;
|
|
37
|
+
exports.h1 = h1;
|
|
38
|
+
exports.h2 = h2;
|
|
39
|
+
exports.h3 = h3;
|
|
40
|
+
exports.h4 = h4;
|
|
41
|
+
exports.h5 = h5;
|
|
42
|
+
exports.h6 = h6;
|
|
43
|
+
exports.img = img;
|
|
44
|
+
exports.input = input;
|
|
45
|
+
exports.label = label;
|
|
46
|
+
exports.li = li;
|
|
47
|
+
exports.ol = ol;
|
|
48
|
+
exports.option = option;
|
|
49
|
+
exports.p = p;
|
|
50
|
+
exports.select = select;
|
|
51
|
+
exports.span = span;
|
|
52
|
+
exports.table = table;
|
|
53
|
+
exports.tbody = tbody;
|
|
54
|
+
exports.td = td;
|
|
55
|
+
exports.th = th;
|
|
56
|
+
exports.thead = thead;
|
|
57
|
+
exports.tr = tr;
|
|
58
|
+
exports.ul = ul;
|
|
82
59
|
|
|
83
|
-
|
|
84
|
-
exports.btn = btn;
|
|
85
|
-
exports.div = div;
|
|
86
|
-
exports.form = form;
|
|
87
|
-
exports.h1 = h1;
|
|
88
|
-
exports.h2 = h2;
|
|
89
|
-
exports.h3 = h3;
|
|
90
|
-
exports.h4 = h4;
|
|
91
|
-
exports.h5 = h5;
|
|
92
|
-
exports.h6 = h6;
|
|
93
|
-
exports.img = img;
|
|
94
|
-
exports.input = input;
|
|
95
|
-
exports.label = label;
|
|
96
|
-
exports.li = li;
|
|
97
|
-
exports.ol = ol;
|
|
98
|
-
exports.option = option;
|
|
99
|
-
exports.p = p;
|
|
100
|
-
exports.select = select;
|
|
101
|
-
exports.span = span;
|
|
102
|
-
exports.table = table;
|
|
103
|
-
exports.tbody = tbody;
|
|
104
|
-
exports.td = td;
|
|
105
|
-
exports.th = th;
|
|
106
|
-
exports.thead = thead;
|
|
107
|
-
exports.tr = tr;
|
|
108
|
-
exports.ul = ul;
|
|
109
|
-
exports.withDefaults = withDefaults;
|
|
110
|
-
|
|
111
|
-
return exports;
|
|
60
|
+
return exports;
|
|
112
61
|
|
|
113
62
|
})({}, __ktjs_core__);
|
package/dist/index.legacy.js
CHANGED
|
@@ -2,11 +2,9 @@ var __ktjs_shortcuts__ = (function (exports, core) {
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var aliasH = function (tag) {
|
|
5
|
-
|
|
5
|
+
return function (attr, content) {
|
|
6
6
|
return core.h(tag, attr, content);
|
|
7
7
|
};
|
|
8
|
-
window.__ktjs__.mark(newFunc, tag);
|
|
9
|
-
return newFunc;
|
|
10
8
|
};
|
|
11
9
|
|
|
12
10
|
var div = aliasH('div');
|
|
@@ -36,84 +34,6 @@ var __ktjs_shortcuts__ = (function (exports, core) {
|
|
|
36
34
|
var a = aliasH('a');
|
|
37
35
|
var img = aliasH('img');
|
|
38
36
|
|
|
39
|
-
/******************************************************************************
|
|
40
|
-
Copyright (c) Microsoft Corporation.
|
|
41
|
-
|
|
42
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
43
|
-
purpose with or without fee is hereby granted.
|
|
44
|
-
|
|
45
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
46
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
47
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
48
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
49
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
50
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
51
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
52
|
-
***************************************************************************** */
|
|
53
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var __assign = function() {
|
|
57
|
-
__assign = Object.assign || function __assign(t) {
|
|
58
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
59
|
-
s = arguments[i];
|
|
60
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
63
|
-
};
|
|
64
|
-
return __assign.apply(this, arguments);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
68
|
-
var e = new Error(message);
|
|
69
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Wrap `h`(or its shortcuts) with default attributes.
|
|
74
|
-
* - `defaultAttr.class` will be merged with the provided `class` attribute.
|
|
75
|
-
* @param func `h` or its shortcuts.
|
|
76
|
-
* @param defaultAttr default KTAttribute, must be an object.
|
|
77
|
-
* @returns new h function with default attributes.
|
|
78
|
-
*/
|
|
79
|
-
var withDefaults = function (func, defaultAttr) {
|
|
80
|
-
if ('__ktjs_h__' in func === false) {
|
|
81
|
-
window.__ktjs__.throws('withDefaults can only be used with h function or its alias');
|
|
82
|
-
}
|
|
83
|
-
if (defaultAttr === null || typeof defaultAttr !== 'object') {
|
|
84
|
-
window.__ktjs__.throws('defaultAttr must be an object');
|
|
85
|
-
}
|
|
86
|
-
// create different merger for defaultAttr with class and not
|
|
87
|
-
var merge = typeof defaultAttr.class === 'string'
|
|
88
|
-
? function (attr) {
|
|
89
|
-
var _a;
|
|
90
|
-
if (typeof attr === 'string') {
|
|
91
|
-
var newAttr = __assign({}, defaultAttr);
|
|
92
|
-
newAttr.class = attr + ' ' + defaultAttr.class;
|
|
93
|
-
return newAttr;
|
|
94
|
-
}
|
|
95
|
-
else if (attr && typeof attr === 'object') {
|
|
96
|
-
var newAttr = __assign(__assign({}, defaultAttr), attr);
|
|
97
|
-
newAttr.class = ((_a = attr.class) !== null && _a !== void 0 ? _a : '') + ' ' + defaultAttr.class;
|
|
98
|
-
return newAttr;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
: function (attr) {
|
|
102
|
-
if (typeof attr === 'string') {
|
|
103
|
-
return __assign(__assign({}, defaultAttr), { class: attr });
|
|
104
|
-
}
|
|
105
|
-
else if (attr && typeof attr === 'object') {
|
|
106
|
-
return __assign(__assign({}, defaultAttr), attr);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
if (func.__ktjs_h__ === 'h') {
|
|
110
|
-
return (function (tag, attr, content) { return func(tag, merge(attr), content); });
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return (function (attr, content) { return func(merge(attr), content); });
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
37
|
exports.a = a;
|
|
118
38
|
exports.btn = btn;
|
|
119
39
|
exports.div = div;
|
|
@@ -140,7 +60,6 @@ var __ktjs_shortcuts__ = (function (exports, core) {
|
|
|
140
60
|
exports.thead = thead;
|
|
141
61
|
exports.tr = tr;
|
|
142
62
|
exports.ul = ul;
|
|
143
|
-
exports.withDefaults = withDefaults;
|
|
144
63
|
|
|
145
64
|
return exports;
|
|
146
65
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { h } from '@ktjs/core';
|
|
2
2
|
|
|
3
|
-
const aliasH = (tag) =>
|
|
4
|
-
const newFunc = (attr, content) => {
|
|
5
|
-
return h(tag, attr, content);
|
|
6
|
-
};
|
|
7
|
-
window.__ktjs__.mark(newFunc, tag);
|
|
8
|
-
return newFunc;
|
|
9
|
-
};
|
|
3
|
+
const aliasH = (tag) => (attr, content) => h(tag, attr, content);
|
|
10
4
|
|
|
11
5
|
const div = aliasH('div');
|
|
12
6
|
const span = aliasH('span');
|
|
@@ -35,48 +29,4 @@ const td = aliasH('td');
|
|
|
35
29
|
const a = aliasH('a');
|
|
36
30
|
const img = aliasH('img');
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
* Wrap `h`(or its shortcuts) with default attributes.
|
|
40
|
-
* - `defaultAttr.class` will be merged with the provided `class` attribute.
|
|
41
|
-
* @param func `h` or its shortcuts.
|
|
42
|
-
* @param defaultAttr default KTAttribute, must be an object.
|
|
43
|
-
* @returns new h function with default attributes.
|
|
44
|
-
*/
|
|
45
|
-
const withDefaults = (func, defaultAttr) => {
|
|
46
|
-
if ('__ktjs_h__' in func === false) {
|
|
47
|
-
window.__ktjs__.throws('withDefaults can only be used with h function or its alias');
|
|
48
|
-
}
|
|
49
|
-
if (defaultAttr === null || typeof defaultAttr !== 'object') {
|
|
50
|
-
window.__ktjs__.throws('defaultAttr must be an object');
|
|
51
|
-
}
|
|
52
|
-
// create different merger for defaultAttr with class and not
|
|
53
|
-
const merge = typeof defaultAttr.class === 'string'
|
|
54
|
-
? (attr) => {
|
|
55
|
-
if (typeof attr === 'string') {
|
|
56
|
-
const newAttr = { ...defaultAttr };
|
|
57
|
-
newAttr.class = attr + ' ' + defaultAttr.class;
|
|
58
|
-
return newAttr;
|
|
59
|
-
}
|
|
60
|
-
else if (attr && typeof attr === 'object') {
|
|
61
|
-
const newAttr = { ...defaultAttr, ...attr };
|
|
62
|
-
newAttr.class = (attr.class ?? '') + ' ' + defaultAttr.class;
|
|
63
|
-
return newAttr;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
: (attr) => {
|
|
67
|
-
if (typeof attr === 'string') {
|
|
68
|
-
return { ...defaultAttr, class: attr };
|
|
69
|
-
}
|
|
70
|
-
else if (attr && typeof attr === 'object') {
|
|
71
|
-
return { ...defaultAttr, ...attr };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
if (func.__ktjs_h__ === 'h') {
|
|
75
|
-
return ((tag, attr, content) => func(tag, merge(attr), content));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return ((attr, content) => func(merge(attr), content));
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export { a, btn, div, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul, withDefaults };
|
|
32
|
+
export { a, btn, div, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ktjs/shortcuts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Shortcut functions for kt.js - common DOM operations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"directory": "packages/shortcuts"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ktjs/core": "0.
|
|
33
|
+
"@ktjs/core": "0.19.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "rollup -c rollup.config.mjs",
|