ts-dom-utils 2.0.0 → 2.2.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/CHANGELOG.md +9 -0
- package/README.md +8 -5
- package/dist/chunk-X7YTDZOL.js +1 -0
- package/dist/createElement.cjs +1 -1
- package/dist/createElement.d.cts +10 -5
- package/dist/createElement.d.ts +10 -5
- package/dist/createElement.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +8 -5
- package/dist/chunk-AR3IDUAF.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# ts-dom-utils
|
|
2
|
+
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3f66d1e: - Simplified `createElement` to handle all object properties, including style.
|
|
8
|
+
- Fixed issue with styles not applying correctly.
|
|
9
|
+
- Updated style type in `SpecialAttributes` to `Partial<CSSStyleDeclaration>` for editor hints and flexibility.
|
package/README.md
CHANGED
|
@@ -45,6 +45,9 @@ const button = createElement('button', {
|
|
|
45
45
|
id: 'my-button',
|
|
46
46
|
class: ['btn', 'btn-primary'],
|
|
47
47
|
text: 'Click me',
|
|
48
|
+
onclick: (event) => {
|
|
49
|
+
console.log('clicked!', event)
|
|
50
|
+
},
|
|
48
51
|
dataset: {
|
|
49
52
|
action: 'open-menu',
|
|
50
53
|
},
|
|
@@ -55,11 +58,11 @@ document.body.appendChild(button);
|
|
|
55
58
|
// <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expandended="false">Click me</button>
|
|
56
59
|
```
|
|
57
60
|
|
|
58
|
-
| Param | Default | Description
|
|
59
|
-
|
|
60
|
-
| tagName | undefined | The tag name of the element type to create.
|
|
61
|
-
| options | {} | The options to use when creating the element. Options can include any attributes that can be passed to `setAttribute`, with `class`,
|
|
62
|
-
| target | document | The Document in which to create the element.
|
|
61
|
+
| Param | Default | Description |
|
|
62
|
+
|---------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
63
|
+
| tagName | undefined | The tag name of the element type to create. |
|
|
64
|
+
| options | {} | The options to use when creating the element. Options can include any attributes that can be passed to `setAttribute`, with `class`, and `text` as special options for enhancement. |
|
|
65
|
+
| target | document | The Document in which to create the element. |
|
|
63
66
|
---
|
|
64
67
|
|
|
65
68
|
## `DOMisReady`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function l(s,i={},r=document){let e=r.createElement(s);return Object.entries(i).forEach(([n,t])=>{t!=null&&(n==="class"?Array.isArray(t)?e.classList.add(...t):typeof t=="string"&&e.classList.add(t):n==="text"?e.textContent=t:n in e?typeof t=="object"&&!Array.isArray(t)?Object.entries(t).forEach(([a,c])=>{e[n][a]=c}):e[n]=t:e.setAttribute(n,t))}),e}export{l as a};
|
package/dist/createElement.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var y=(i,n)=>{for(var r in n)a(i,r,{get:n[r],enumerable:!0})},d=(i,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of m(n))!p.call(i,t)&&t!==r&&a(i,t,{get:()=>n[t],enumerable:!(s=o(n,t))||s.enumerable});return i};var E=i=>d(a({},"__esModule",{value:!0}),i);var g={};y(g,{default:()=>c});module.exports=E(g);function c(i,n={},r=document){let s=r.createElement(i);return Object.entries(n).forEach(([t,e])=>{e!=null&&(t==="class"?Array.isArray(e)?s.classList.add(...e):typeof e=="string"&&s.classList.add(e):t==="text"?s.textContent=e:t in s?typeof e=="object"&&!Array.isArray(e)?Object.entries(e).forEach(([l,f])=>{s[t][l]=f}):s[t]=e:s.setAttribute(t,e))}),s}
|
package/dist/createElement.d.cts
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* id: 'my-button',
|
|
12
12
|
* class: ['btn', 'btn-primary'],
|
|
13
13
|
* text: 'Click me',
|
|
14
|
+
* onclick: (event) => {
|
|
15
|
+
* console.log('clicked!', event)
|
|
16
|
+
* },
|
|
14
17
|
* dataset: {
|
|
15
18
|
* action: 'open-menu',
|
|
16
19
|
* },
|
|
@@ -20,12 +23,14 @@
|
|
|
20
23
|
* document.body.appendChild(button);
|
|
21
24
|
* // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expandended="false">Click me</button>
|
|
22
25
|
*/
|
|
23
|
-
declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions
|
|
24
|
-
type
|
|
25
|
-
[key: string]: any;
|
|
26
|
+
declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
|
|
27
|
+
type SpecialAttributes = {
|
|
26
28
|
class?: string | string[];
|
|
27
|
-
dataset?: Record<string, string>;
|
|
28
29
|
text?: string;
|
|
30
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
31
|
+
};
|
|
32
|
+
type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
|
|
33
|
+
[key: string]: any;
|
|
29
34
|
};
|
|
30
35
|
|
|
31
|
-
export { CreateElementOptions, createElement as default };
|
|
36
|
+
export { type CreateElementOptions, createElement as default };
|
package/dist/createElement.d.ts
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* id: 'my-button',
|
|
12
12
|
* class: ['btn', 'btn-primary'],
|
|
13
13
|
* text: 'Click me',
|
|
14
|
+
* onclick: (event) => {
|
|
15
|
+
* console.log('clicked!', event)
|
|
16
|
+
* },
|
|
14
17
|
* dataset: {
|
|
15
18
|
* action: 'open-menu',
|
|
16
19
|
* },
|
|
@@ -20,12 +23,14 @@
|
|
|
20
23
|
* document.body.appendChild(button);
|
|
21
24
|
* // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expandended="false">Click me</button>
|
|
22
25
|
*/
|
|
23
|
-
declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions
|
|
24
|
-
type
|
|
25
|
-
[key: string]: any;
|
|
26
|
+
declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
|
|
27
|
+
type SpecialAttributes = {
|
|
26
28
|
class?: string | string[];
|
|
27
|
-
dataset?: Record<string, string>;
|
|
28
29
|
text?: string;
|
|
30
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
31
|
+
};
|
|
32
|
+
type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
|
|
33
|
+
[key: string]: any;
|
|
29
34
|
};
|
|
30
35
|
|
|
31
|
-
export { CreateElementOptions, createElement as default };
|
|
36
|
+
export { type CreateElementOptions, createElement as default };
|
package/dist/createElement.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-X7YTDZOL.js";export{a as default};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},x=(t,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!E.call(t,r)&&r!==s&&i(t,r,{get:()=>e[r],enumerable:!(a=p(e,r))||a.enumerable});return t};var g=t=>x(i({},"__esModule",{value:!0}),t);var M={};y(M,{DOMisReady:()=>d,createElement:()=>o,qs:()=>f,qsa:()=>l});module.exports=g(M);function o(t,e={},s=document){let a=s.createElement(t);return Object.entries(e).forEach(([r,n])=>{n!=null&&(r==="class"?Array.isArray(n)?a.classList.add(...n):typeof n=="string"&&a.classList.add(n):r==="text"?a.textContent=n:r in a?typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([m,c])=>{a[r][m]=c}):a[r]=n:a.setAttribute(r,n))}),a}function d(t=document){return new Promise(e=>{if(t.readyState!=="loading")return e();t.addEventListener("DOMContentLoaded",()=>e())})}function f(t,e=document){return e.querySelector(t)}function l(t,e=document){return e.querySelectorAll(t)}0&&(module.exports={DOMisReady,createElement,qs,qsa});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-QYTVIVCC.js";import{a}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-QYTVIVCC.js";import{a}from"./chunk-X7YTDZOL.js";import{a as t}from"./chunk-YC4DGQBN.js";import{a as r}from"./chunk-22TR3O4D.js";export{e as DOMisReady,a as createElement,t as qs,r as qsa};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-dom-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A simple utility library for DOM manipulation. Provides TypeScript typings for enhanced development experience in TS environments.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsup --dts",
|
|
12
|
-
"lint": "tsc"
|
|
12
|
+
"lint": "tsc",
|
|
13
|
+
"format": "prettier --write ./src",
|
|
14
|
+
"release": "npm run build && changeset publish"
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
15
17
|
"type": "git",
|
|
@@ -28,8 +30,9 @@
|
|
|
28
30
|
"homepage": "https://github.com/rafaucau/ts-dom-utils#readme",
|
|
29
31
|
"funding": "https://github.com/rafaucau/ts-dom-utils?sponsor=1",
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
33
|
+
"@changesets/cli": "^2.26.2",
|
|
34
|
+
"prettier": "^3.1.0",
|
|
35
|
+
"tsup": "^8.0.1",
|
|
36
|
+
"typescript": "^5.3.2"
|
|
34
37
|
}
|
|
35
38
|
}
|
package/dist/chunk-AR3IDUAF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function o(r,n={},a=document){let e=a.createElement(r);return Object.entries(n).forEach(([s,t])=>{if(s==="class"){Array.isArray(t)?e.classList.add(...t):e.classList.add(t);return}if(s==="dataset"&&typeof t=="object"&&t!==null){Object.entries(t).forEach(([i,c])=>{e.dataset[i]=c});return}if(s==="text"){e.textContent=t;return}e.setAttribute(s,t)}),e}export{o as a};
|