@ktjs/jsx 0.6.3 → 0.6.5

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@ktjs/core");function e(e,r,...n){const o="string"==typeof r?{class:r}:r;return t.h(e,o,n)}const r=e,n=e;Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return t.h}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return t.h}}),exports.Fragment=function(e){const{children:r}=e||{};if(!r)return t.ktnull;if(!Array.isArray(r))return r;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),r.forEach(e=>{e&&e!==t.ktnull&&("string"==typeof e?n.appendChild(document.createTextNode(e)):e instanceof HTMLElement&&n.appendChild(e))}),n},exports.jsx=e,exports.jsxDEV=r,exports.jsxs=n;
1
+ "use strict";var e=require("@ktjs/core");function t(t,n,...r){const o="string"==typeof n?{class:n}:n;if(null==o)return e.h(t);const s=o.children;return delete o.children,e.h(t,o,s)}const n=t,r=t;Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return e.h}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return e.h}}),exports.Fragment=function(e){window.__ktjs__.throws("kt.js doesn't have a Fragment concept")},exports.jsx=t,exports.jsxDEV=n,exports.jsxs=r;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,12 @@
1
- import { HTMLTag, KTRawAttr, KTRawContents, KTRawContent, ktnull, KTAttribute } from '@ktjs/core';
1
+ import { HTMLTag, KTRawAttr, KTRawContent, ktnull, KTAttribute } from '@ktjs/core';
2
2
  export { h as createElement, h } from '@ktjs/core';
3
3
 
4
- declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ...children: KTRawContents): HTMLElementTagNameMap[T];
4
+ /**
5
+ * @param tag html tag
6
+ * @param props properties/attributes
7
+ * @param _metadata metadata is ignored
8
+ */
9
+ declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ..._metadata: any[]): HTMLElementTagNameMap[T];
5
10
  /**
6
11
  * Fragment support - returns an array of children
7
12
  * Note: kt.js doesn't have a real Fragment concept,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{h as t,ktnull as r}from"@ktjs/core";export{h as createElement,h}from"@ktjs/core";function e(r,e,...n){return t(r,"string"==typeof e?{class:e}:e,n)}function n(t){const{children:e}=t||{};if(!e)return r;if(!Array.isArray(e))return e;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),e.forEach(t=>{t&&t!==r&&("string"==typeof t?n.appendChild(document.createTextNode(t)):t instanceof HTMLElement&&n.appendChild(t))}),n}const o=e,c=e;export{n as Fragment,e as jsx,o as jsxDEV,c as jsxs};
1
+ import{h as t}from"@ktjs/core";export{h as createElement,h}from"@ktjs/core";function e(e,n,...o){const r="string"==typeof n?{class:n}:n;if(null==r)return t(e);const c=r.children;return delete r.children,t(e,r,c)}function n(t){window.__ktjs__.throws("kt.js doesn't have a Fragment concept")}const o=e,r=e;export{n as Fragment,e as jsx,o as jsxDEV,r as jsxs};
@@ -2,9 +2,18 @@
2
2
 
3
3
  var core = require('@ktjs/core');
4
4
 
5
- function jsx(tag, props, ...children) {
5
+ /**
6
+ * @param tag html tag
7
+ * @param props properties/attributes
8
+ * @param _metadata metadata is ignored
9
+ */
10
+ function jsx(tag, props, ..._metadata) {
6
11
  const propObj = typeof props === 'string' ? { class: props } : props;
7
- console.log('jsx tag', tag, 'props', props, 'rest children', children);
12
+ if (propObj === undefined || propObj === null) {
13
+ return core.h(tag);
14
+ }
15
+ const children = propObj.children;
16
+ delete propObj.children;
8
17
  return core.h(tag, propObj, children);
9
18
  }
10
19
  /**
@@ -12,31 +21,30 @@ function jsx(tag, props, ...children) {
12
21
  * Note: kt.js doesn't have a real Fragment concept,
13
22
  * so we return ktnull for empty fragments or flatten children
14
23
  */
15
- // todo 实在不需要也可以在此函数内直接报错说自己不支持
16
24
  function Fragment(props) {
17
- const { children } = props || {};
18
- if (!children) {
19
- return core.ktnull;
20
- }
21
- // If single child, return it directly
22
- if (!Array.isArray(children)) {
23
- return children;
24
- }
25
- // For multiple children, create a document fragment wrapper
26
- // This is a limitation - JSX fragments must be wrapped in kt.js
27
- const wrapper = document.createElement('div');
28
- wrapper.setAttribute('data-kt-fragment', 'true');
29
- children.forEach((child) => {
30
- if (child && child !== core.ktnull) {
31
- if (typeof child === 'string') {
32
- wrapper.appendChild(document.createTextNode(child));
33
- }
34
- else if (child instanceof HTMLElement) {
35
- wrapper.appendChild(child);
36
- }
37
- }
38
- });
39
- return wrapper;
25
+ window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
26
+ // const { children } = props || {};
27
+ // if (!children) {
28
+ // return ktnull;
29
+ // }
30
+ // // If single child, return it directly
31
+ // if (!Array.isArray(children)) {
32
+ // return children as HTMLElement;
33
+ // }
34
+ // // For multiple children, create a document fragment wrapper
35
+ // // This is a limitation - JSX fragments must be wrapped in kt.js
36
+ // const wrapper = document.createElement('div');
37
+ // wrapper.setAttribute('data-kt-fragment', 'true');
38
+ // children.forEach((child) => {
39
+ // if (child && child !== ktnull) {
40
+ // if (typeof child === 'string') {
41
+ // wrapper.appendChild(document.createTextNode(child));
42
+ // } else if (child instanceof HTMLElement) {
43
+ // wrapper.appendChild(child);
44
+ // }
45
+ // }
46
+ // });
47
+ // return wrapper;
40
48
  }
41
49
  /**
42
50
  * JSX Development runtime - same as jsx but with additional dev checks
@@ -1,7 +1,12 @@
1
- import { HTMLTag, KTRawAttr, KTRawContents, KTRawContent, ktnull } from '@ktjs/core';
1
+ import { HTMLTag, KTRawAttr, KTRawContent, ktnull } from '@ktjs/core';
2
2
  export { h as createElement, h } from '@ktjs/core';
3
3
 
4
- declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ...children: KTRawContents): HTMLElementTagNameMap[T];
4
+ /**
5
+ * @param tag html tag
6
+ * @param props properties/attributes
7
+ * @param _metadata metadata is ignored
8
+ */
9
+ declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ..._metadata: any[]): HTMLElementTagNameMap[T];
5
10
  /**
6
11
  * Fragment support - returns an array of children
7
12
  * Note: kt.js doesn't have a real Fragment concept,
@@ -1,9 +1,18 @@
1
- import { h, ktnull } from '@ktjs/core';
1
+ import { h } from '@ktjs/core';
2
2
  export { h as createElement, h } from '@ktjs/core';
3
3
 
4
- function jsx(tag, props, ...children) {
4
+ /**
5
+ * @param tag html tag
6
+ * @param props properties/attributes
7
+ * @param _metadata metadata is ignored
8
+ */
9
+ function jsx(tag, props, ..._metadata) {
5
10
  const propObj = typeof props === 'string' ? { class: props } : props;
6
- console.log('jsx tag', tag, 'props', props, 'rest children', children);
11
+ if (propObj === undefined || propObj === null) {
12
+ return h(tag);
13
+ }
14
+ const children = propObj.children;
15
+ delete propObj.children;
7
16
  return h(tag, propObj, children);
8
17
  }
9
18
  /**
@@ -11,31 +20,30 @@ function jsx(tag, props, ...children) {
11
20
  * Note: kt.js doesn't have a real Fragment concept,
12
21
  * so we return ktnull for empty fragments or flatten children
13
22
  */
14
- // todo 实在不需要也可以在此函数内直接报错说自己不支持
15
23
  function Fragment(props) {
16
- const { children } = props || {};
17
- if (!children) {
18
- return ktnull;
19
- }
20
- // If single child, return it directly
21
- if (!Array.isArray(children)) {
22
- return children;
23
- }
24
- // For multiple children, create a document fragment wrapper
25
- // This is a limitation - JSX fragments must be wrapped in kt.js
26
- const wrapper = document.createElement('div');
27
- wrapper.setAttribute('data-kt-fragment', 'true');
28
- children.forEach((child) => {
29
- if (child && child !== ktnull) {
30
- if (typeof child === 'string') {
31
- wrapper.appendChild(document.createTextNode(child));
32
- }
33
- else if (child instanceof HTMLElement) {
34
- wrapper.appendChild(child);
35
- }
36
- }
37
- });
38
- return wrapper;
24
+ window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
25
+ // const { children } = props || {};
26
+ // if (!children) {
27
+ // return ktnull;
28
+ // }
29
+ // // If single child, return it directly
30
+ // if (!Array.isArray(children)) {
31
+ // return children as HTMLElement;
32
+ // }
33
+ // // For multiple children, create a document fragment wrapper
34
+ // // This is a limitation - JSX fragments must be wrapped in kt.js
35
+ // const wrapper = document.createElement('div');
36
+ // wrapper.setAttribute('data-kt-fragment', 'true');
37
+ // children.forEach((child) => {
38
+ // if (child && child !== ktnull) {
39
+ // if (typeof child === 'string') {
40
+ // wrapper.appendChild(document.createTextNode(child));
41
+ // } else if (child instanceof HTMLElement) {
42
+ // wrapper.appendChild(child);
43
+ // }
44
+ // }
45
+ // });
46
+ // return wrapper;
39
47
  }
40
48
  /**
41
49
  * JSX Development runtime - same as jsx but with additional dev checks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/jsx",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "JSX/TSX support for KT.js - Build UIs with JSX syntax while keeping direct DOM control",
5
5
  "author": {
6
6
  "name": "Kasukabe Tsumugi",