@druid-ui/component 2.0.0 → 2.1.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/dist/index.js CHANGED
@@ -7,7 +7,10 @@ var callbackMap = {};
7
7
  function emit(nodeid, event, e) {
8
8
  log(`Emit called for nodeid: ${nodeid}, event: ${event}`);
9
9
  const callbacks = callbackMap[nodeid];
10
- callbacks?.[event]?.(e);
10
+ const result = callbacks?.[event]?.(e);
11
+ if (result instanceof Promise) {
12
+ result.then(() => rerender());
13
+ }
11
14
  }
12
15
  var registerHooks = (id, fnresult) => {
13
16
  switch (true) {
@@ -0,0 +1,18 @@
1
+ // src/jsx-runtime.ts
2
+ import { d } from "./index";
3
+ function jsx(type, props) {
4
+ const { children, ...rest } = props || {};
5
+ if (children !== void 0) {
6
+ return d(type, rest, children);
7
+ }
8
+ return d(type, rest);
9
+ }
10
+ var jsxs = jsx;
11
+ var jsxDEV = jsx;
12
+ var Fragment = Symbol.for("react.fragment");
13
+ export {
14
+ Fragment,
15
+ jsx,
16
+ jsxDEV,
17
+ jsxs
18
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,eAAO,MAAM,CAAC;gBAEy3B,CAAC;QAAsB,CAAC;WAA8B,CAAC,yBAA+B,CAAC;gBAAwB,CAAC;QAAsB,CAAC;;gBAAxB,CAAC;;CAFp9B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,eAAO,MAAM,CAAC;gBAEmwB,CAAC;QAAsB,CAAC;WAA8B,CAAC,yBAA+B,CAAC;gBAAwB,CAAC;QAAsB,CAAC;;gBAAxB,CAAC;;CAF91B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
@@ -1,7 +1,5 @@
1
1
  declare module 'druid:ui/utils' {
2
- export interface Context {
3
- path: string,
4
- }
2
+ export type Context = Array<[string, string]>;
5
3
 
6
4
  export class Event implements Disposable {
7
5
  constructor(value: string, checked: boolean)
@@ -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"}
@@ -1,7 +1,6 @@
1
1
  import { d } from "druid:ui/ui";
2
2
  import type { Event } from "@druid-ui/host";
3
3
  import type { Context } from "druid:ui/component";
4
- export declare function fnv1aHash(str: string): string;
5
4
  export declare const callbackMap: Record<string, Record<string, Function>>;
6
5
  export declare function emit(nodeid: string, event: string, e: Event): void;
7
6
  export declare const createDFunc: (dfunc: typeof d) => (tag: string | {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":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AAU,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;UAFT,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,MAAM;WAAS,MAAM,IAAI;CAyD3E,CAAC;AAQF,eAAO,MAAM,aAAa,GACxB,IAAI,MAAM,EACV,QAAQ;IAAE,GAAG,EAAE,IAAI,GAAG,KAAK,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,SAaxC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC3B,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,MAC9B,GAAG,MAAM,GAAG,EAAE,eAKd,CAAC;AAEJ,eAAO,MAAM,eAAe,GAAI,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,GAAG,GAAG,CAAC,OAAO;gBAC3D,OAAO;;wBA1Bf,MAAM,UACF;QAAE,GAAG,EAAE,IAAI,GAAG,KAAK,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAE;CA4BvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@druid-ui/component",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -10,14 +10,14 @@
10
10
  "import": "./dist/index.js",
11
11
  "default": "./dist/index.js"
12
12
  },
13
- "./raw": {
14
- "types": "./dist/types/raw.d.ts",
15
- "import": "./dist/raw.js",
16
- "default": "./dist/raw.js"
17
- },
18
13
  "./jsx": {
19
14
  "types": "./src/jsx.d.ts"
20
15
  },
16
+ "./jsx-runtime": {
17
+ "types": "./dist/types/jsx-runtime.d.ts",
18
+ "import": "./dist/jsx-runtime.js",
19
+ "default": "./dist/jsx-runtime.js"
20
+ },
21
21
  "./types": {
22
22
  "types": "./dist/types/druid-ui.d.ts"
23
23
  }
@@ -27,9 +27,9 @@
27
27
  "src"
28
28
  ],
29
29
  "scripts": {
30
- "build": "npm run build:types-ui && npm run build:lib && npm run build:raw && npm run build:types",
30
+ "build": "npm run build:types-ui && npm run build:lib && npm run build:jsx-runtime && npm run build:types",
31
31
  "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
- "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",
32
+ "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 --external:./index",
33
33
  "build:types": "tsc --emitDeclarationOnly --outDir dist/types",
34
34
  "build:types-ui": "druid-ui-gen-types druid-ui --out-dir=dist/types"
35
35
  },
@@ -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.ts CHANGED
@@ -3,22 +3,16 @@ import { log, rerender, d, setHook } from "druid:ui/ui";
3
3
  import type { Event } from "@druid-ui/host";
4
4
  import type { Context } from "druid:ui/component";
5
5
 
6
- export function fnv1aHash(str: string) {
7
- let hash = 0x811c9dc5; // FNV offset basis
8
- for (let i = 0; i < str.length; i++) {
9
- hash ^= str.charCodeAt(i);
10
- hash +=
11
- (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
12
- }
13
- return (hash >>> 0).toString(36);
14
- }
15
-
16
6
  export const callbackMap: Record<string, Record<string, Function>> = {};
17
7
 
18
8
  export function emit(nodeid: string, event: string, e: Event) {
19
9
  log(`Emit called for nodeid: ${nodeid}, event: ${event}`);
20
10
  const callbacks = callbackMap[nodeid];
21
- callbacks?.[event]?.(e);
11
+ const result = callbacks?.[event]?.(e);
12
+ // if we have have shim3 with async support, we can call rerender external only
13
+ if (result instanceof Promise) {
14
+ result.then(() => rerender());
15
+ }
22
16
  }
23
17
 
24
18
  const registerHooks = (
package/dist/raw.js DELETED
@@ -1,106 +0,0 @@
1
- // src/utils.ts
2
- import { log, rerender, setHook } from "druid:ui/ui";
3
- var callbackMap = {};
4
- function emit(nodeid, event, e) {
5
- log(`Emit called for nodeid: ${nodeid}, event: ${event}`);
6
- const callbacks = callbackMap[nodeid];
7
- callbacks?.[event]?.(e);
8
- }
9
- var registerHooks = (id, fnresult) => {
10
- switch (true) {
11
- case !!fnresult.init:
12
- setHook(id, "init");
13
- callbackMap[id] = {
14
- ...callbackMap[id],
15
- init: fnresult.init
16
- };
17
- break;
18
- }
19
- };
20
- var createDFunc = (dfunc2) => {
21
- return (tag, props, ...children) => {
22
- children = children.flat();
23
- if (typeof tag !== "string") {
24
- if (typeof tag === "function") {
25
- const fnresult = tag(props);
26
- if (fnresult?.view) {
27
- const id3 = fnresult.view(props);
28
- registerHooks(id3, fnresult);
29
- return id3;
30
- } else {
31
- return tag(props);
32
- }
33
- }
34
- const id2 = tag.view(props);
35
- registerHooks(id2, tag);
36
- return id2;
37
- }
38
- const ps = { prop: [], on: [] };
39
- const cbObj = {};
40
- if (props) {
41
- for (const [key, value] of Object.entries(props)) {
42
- if (value instanceof Function) {
43
- const eventKey = key.startsWith("on") ? key.slice(2).toLowerCase() : key;
44
- cbObj[eventKey] = value;
45
- ps.on.push(eventKey);
46
- } else {
47
- if (typeof value === "boolean") {
48
- if (value) {
49
- ps.prop.push({ key, value: "true" });
50
- }
51
- continue;
52
- }
53
- ps.prop.push({ key, value });
54
- }
55
- }
56
- }
57
- const id = dfunc2(
58
- tag,
59
- ps,
60
- children.filter((c) => typeof c !== "boolean").map((c) => c?.toString())
61
- );
62
- callbackMap[id] = {
63
- ...callbackMap[id],
64
- ...cbObj
65
- };
66
- return id;
67
- };
68
- };
69
- var pendingOperations = /* @__PURE__ */ new Map();
70
- var asyncCallback = (id, result) => {
71
- log(`Async callback received for id: ${id} with result: ${result.tag}`);
72
- const pending = pendingOperations.get(id);
73
- if (pending) {
74
- if (result.tag === "ok") {
75
- pending.resolve(result.val);
76
- } else {
77
- pending.reject(new Error(result.val));
78
- }
79
- pendingOperations.delete(id);
80
- rerender();
81
- }
82
- };
83
- var rawAsyncToPromise = (fn) => (...args) => {
84
- return new Promise((resolve, reject) => {
85
- const asyncId = fn(...args);
86
- pendingOperations.set(asyncId, { resolve, reject });
87
- });
88
- };
89
- var createComponent = (j) => ({
90
- init: (ctx) => j(ctx),
91
- emit,
92
- asyncComplete: asyncCallback
93
- });
94
-
95
- // src/raw.ts
96
- var dfunc = window["druid-ui"]?.d || (() => {
97
- throw new Error("druid.d function not defined");
98
- });
99
- var d2 = createDFunc(dfunc);
100
- var log2 = (msg) => console.log("UI LOG:", msg);
101
- export {
102
- createComponent,
103
- d2 as d,
104
- log2 as log,
105
- rawAsyncToPromise
106
- };
@@ -1,13 +0,0 @@
1
- export declare const d: (tag: string | {
2
- view: (props?: any) => string;
3
- init?: () => void;
4
- } | ((props?: any) => void) | ((props?: any) => {
5
- view: (props?: any) => string;
6
- init?: () => void;
7
- }), props?: Record<string, any>, ...children: string[] | Array<string[]>) => string | void | {
8
- view: (props?: any) => string;
9
- init?: () => void;
10
- };
11
- export declare const log: (msg: string) => void;
12
- export { createComponent, rawAsyncToPromise } from "./utils";
13
- //# sourceMappingURL=raw.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/raw.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,CAAC;gBAKouB,CAAC;QAAsB,CAAC;WAA8B,CAAC,yBAA+B,CAAC;gBAAwB,CAAC;QAAsB,CAAC;;gBAAxB,CAAC;;CAL/zB,CAAC;AAEpC,eAAO,MAAM,GAAG,GAAI,KAAK,MAAM,SAAgC,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
package/src/raw.ts DELETED
@@ -1,14 +0,0 @@
1
- //this file fully works in the browser, this hopefully can be remvoved in the future and unified with
2
- import { createDFunc } from "./utils";
3
-
4
- const dfunc =
5
- window["druid-ui"]?.d ||
6
- (() => {
7
- throw new Error("druid.d function not defined");
8
- });
9
-
10
- export const d = createDFunc(dfunc);
11
-
12
- export const log = (msg: string) => console.log("UI LOG:", msg);
13
-
14
- export { createComponent, rawAsyncToPromise } from "./utils";
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
- };