@druid-ui/component 1.0.8 → 1.0.10

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.
@@ -0,0 +1,89 @@
1
+ // src/index.ts
2
+ import { d as dfunc } from "druid:ui/ui";
3
+
4
+ // src/utils.ts
5
+ import { log, rerender, setHook } from "druid:ui/ui";
6
+ var callbackMap = {};
7
+ var registerHooks = (id, fnresult) => {
8
+ switch (true) {
9
+ case !!fnresult.init:
10
+ setHook(id, "init");
11
+ callbackMap[id] = {
12
+ ...callbackMap[id],
13
+ init: fnresult.init
14
+ };
15
+ break;
16
+ }
17
+ };
18
+ var createDFunc = (dfunc2) => {
19
+ return (tag, props, ...children) => {
20
+ children = children.flat();
21
+ if (typeof tag !== "string") {
22
+ if (typeof tag === "function") {
23
+ const fnresult = tag(props);
24
+ if (fnresult?.view) {
25
+ const id3 = fnresult.view(props);
26
+ registerHooks(id3, fnresult);
27
+ return id3;
28
+ } else {
29
+ return tag(props);
30
+ }
31
+ }
32
+ const id2 = tag.view(props);
33
+ registerHooks(id2, tag);
34
+ return id2;
35
+ }
36
+ const ps = { prop: [], on: [] };
37
+ const cbObj = {};
38
+ if (props) {
39
+ for (const [key, value] of Object.entries(props)) {
40
+ if (value instanceof Function) {
41
+ const eventKey = key.startsWith("on") ? key.slice(2).toLowerCase() : key;
42
+ cbObj[eventKey] = value;
43
+ ps.on.push(eventKey);
44
+ } else {
45
+ if (typeof value === "boolean") {
46
+ if (value) {
47
+ ps.prop.push({ key, value: "true" });
48
+ }
49
+ continue;
50
+ }
51
+ ps.prop.push({ key, value });
52
+ }
53
+ }
54
+ }
55
+ const id = dfunc2(
56
+ tag,
57
+ ps,
58
+ children.filter((c) => typeof c !== "boolean").map((c) => c?.toString())
59
+ );
60
+ callbackMap[id] = {
61
+ ...callbackMap[id],
62
+ ...cbObj
63
+ };
64
+ return id;
65
+ };
66
+ };
67
+
68
+ // src/index.ts
69
+ import { Event } from "druid:ui/utils";
70
+ import { log as log2 } from "druid:ui/ui";
71
+ var d2 = createDFunc(dfunc);
72
+
73
+ // src/jsx-runtime.ts
74
+ function jsx(type, props) {
75
+ const { children, ...rest } = props || {};
76
+ if (children !== void 0) {
77
+ return d2(type, rest, children);
78
+ }
79
+ return d2(type, rest);
80
+ }
81
+ var jsxs = jsx;
82
+ var jsxDEV = jsx;
83
+ var Fragment = Symbol.for("react.fragment");
84
+ export {
85
+ Fragment,
86
+ jsx,
87
+ jsxDEV,
88
+ jsxs
89
+ };
@@ -0,0 +1,8 @@
1
+ export declare function jsx(type: any, props: any): string | void | {
2
+ view: (props?: any) => string;
3
+ init?: () => void;
4
+ };
5
+ export declare const jsxs: typeof jsx;
6
+ export declare const jsxDEV: typeof jsx;
7
+ export declare const Fragment: unique symbol;
8
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx-runtime.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;gBAgB+kB,CAAC;;EAVxnB;AAGD,eAAO,MAAM,IAAI,YAAM,CAAC;AAGxB,eAAO,MAAM,MAAM,YAAM,CAAC;AAG1B,eAAO,MAAM,QAAQ,eAA+B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@druid-ui/component",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -18,6 +18,11 @@
18
18
  "./jsx": {
19
19
  "types": "./src/jsx.d.ts"
20
20
  },
21
+ "./jsx-runtime": {
22
+ "types": "./dist/types/jsx-runtime.d.ts",
23
+ "import": "./dist/jsx-runtime.js",
24
+ "default": "./dist/jsx-runtime.js"
25
+ },
21
26
  "./types": {
22
27
  "types": "./dist/types/druid-ui.d.ts"
23
28
  }
@@ -27,9 +32,10 @@
27
32
  "src"
28
33
  ],
29
34
  "scripts": {
30
- "build": "npm run build:types-ui && npm run build:lib && npm run build:raw && npm run build:types",
35
+ "build": "npm run build:types-ui && npm run build:lib && npm run build:raw && npm run build:jsx-runtime && npm run build:types",
31
36
  "build:lib": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=esm --external:druid:ui/ui --external:druid:ui/utils --external:druid:ui/component --external:@druid-ui/host",
32
37
  "build:raw": "esbuild src/raw.ts --bundle --outfile=dist/raw.js --format=esm --external:@druid-ui/host --external:druid:ui/ui --external:druid:ui/utils --external:druid:ui/component",
38
+ "build:jsx-runtime": "esbuild src/jsx-runtime.ts --bundle --outfile=dist/jsx-runtime.js --format=esm --external:druid:ui/ui --external:druid:ui/utils --external:druid:ui/component --external:@druid-ui/host",
33
39
  "build:types": "tsc --emitDeclarationOnly --outDir dist/types",
34
40
  "build:types-ui": "druid-ui-gen-types druid-ui --out-dir=dist/types"
35
41
  },
@@ -0,0 +1,19 @@
1
+ import { d } from "./index";
2
+
3
+ // Adapter for React JSX runtime - extracts children from props
4
+ export function jsx(type: any, props: any) {
5
+ const { children, ...rest } = props || {};
6
+ if (children !== undefined) {
7
+ return d(type, rest, children);
8
+ }
9
+ return d(type, rest);
10
+ }
11
+
12
+ // jsxs is the same as jsx (used for multiple children)
13
+ export const jsxs = jsx;
14
+
15
+ // jsxDEV is the same for development
16
+ export const jsxDEV = jsx;
17
+
18
+ // Fragment is just an empty element for druid-ui
19
+ export const Fragment = Symbol.for("react.fragment");
package/src/utils.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { Props } from "druid:ui/ui";
2
- import type { Event } from "../types";
3
- import type { Context } from "druid:ui/component";
4
- export declare function fnv1aHash(str: string): string;
5
- export declare const eventMap: Record<string, Record<string, Function>>;
6
- export declare function emit(nodeid: string, event: string, e: Event): void;
7
- export declare const createDFunc: (dfunc: (element: string, props: Props, children: string[]) => string) => (tag: string | {
8
- view: (props?: any) => void;
9
- } | ((props?: any) => void), props?: Record<string, any>, ...children: string[]) => string | void;
10
- export declare const asyncCallback: (id: string, result: {
11
- tag: "ok" | "err";
12
- val: any;
13
- }) => void;
14
- export declare const rawAsyncToPromise: <T>(fn: (...args: any[]) => any) => (...args: any[]) => Promise<T>;
15
- export declare const createComponent: (j: (ctx: Context) => string | JSX.Element) => {
16
- init: (ctx: Context) => string | JSX.Element;
17
- emit: typeof emit;
18
- asyncComplete: (id: string, result: {
19
- tag: "ok" | "err";
20
- val: any;
21
- }) => void;
22
- };