@floegence/redevplugin-ui 0.6.23 → 0.6.24

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,2 @@
1
+ export { Fragment, jsxDEV } from "./jsx-runtime.js";
2
+ export type { JSX } from "./jsx-runtime.js";
@@ -0,0 +1 @@
1
+ export { Fragment, jsxDEV } from "./jsx-runtime.js";
@@ -0,0 +1,27 @@
1
+ import type { OpaqueSurfaceAllowedTag } from "./opaque-surface-policy.gen.js";
2
+ import { type PluginUIElementVNode, type PluginUIVNode } from "./ui-reconciler.js";
3
+ export declare const Fragment: unique symbol;
4
+ export type PluginUIJSXChild = PluginUIVNode | string | number | boolean | null | undefined | readonly PluginUIJSXChild[];
5
+ export type PluginUIJSXProps = {
6
+ children?: PluginUIJSXChild;
7
+ [name: string]: unknown;
8
+ };
9
+ type PluginUIJSXType = OpaqueSurfaceAllowedTag | typeof Fragment | ((props: PluginUIJSXProps) => unknown);
10
+ export declare function jsx(type: PluginUIJSXType, props: PluginUIJSXProps | null, key?: string): PluginUIElementVNode;
11
+ export declare function jsxs(type: PluginUIJSXType, props: PluginUIJSXProps | null, key?: string): PluginUIElementVNode;
12
+ export declare function jsxDEV(type: PluginUIJSXType, props: PluginUIJSXProps | null, key?: string, _isStaticChildren?: boolean, _source?: unknown, _self?: unknown): PluginUIElementVNode;
13
+ export declare namespace JSX {
14
+ type Element = PluginUIElementVNode;
15
+ interface ElementChildrenAttribute {
16
+ children: unknown;
17
+ }
18
+ interface IntrinsicAttributes {
19
+ key: string;
20
+ }
21
+ type IntrinsicElements = {
22
+ [Tag in OpaqueSurfaceAllowedTag]: PluginUIJSXProps & {
23
+ key: string;
24
+ };
25
+ };
26
+ }
27
+ export {};
@@ -0,0 +1,84 @@
1
+ import { validatePluginUITree, } from "./ui-reconciler.js";
2
+ export const Fragment = Symbol("ReDevPlugin.Fragment");
3
+ const keyPattern = new RegExp("^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$");
4
+ const attributeAliases = new Map([
5
+ ["autoComplete", "autocomplete"],
6
+ ["className", "class"],
7
+ ["htmlFor", "for"],
8
+ ["maxLength", "maxlength"],
9
+ ["readOnly", "readonly"],
10
+ ["tabIndex", "tabindex"],
11
+ ]);
12
+ export function jsx(type, props, key) {
13
+ return createElement(type, props, key);
14
+ }
15
+ export function jsxs(type, props, key) {
16
+ return createElement(type, props, key);
17
+ }
18
+ export function jsxDEV(type, props, key, _isStaticChildren, _source, _self) {
19
+ return createElement(type, props, key);
20
+ }
21
+ function createElement(type, props, key) {
22
+ if (type === Fragment)
23
+ throw new TypeError("ReDevPlugin JSX does not support Fragment; use one keyed intrinsic element");
24
+ if (typeof type !== "string")
25
+ throw new TypeError("ReDevPlugin JSX supports intrinsic elements only");
26
+ if (typeof key !== "string" || !keyPattern.test(key)) {
27
+ throw new TypeError("ReDevPlugin JSX elements require a valid stable key");
28
+ }
29
+ const attributes = {};
30
+ const source = props ?? {};
31
+ for (const [rawName, value] of Object.entries(source)) {
32
+ if (rawName === "children" || rawName === "key" || value === undefined)
33
+ continue;
34
+ const name = attributeAliases.get(rawName) ?? rawName;
35
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
36
+ throw new TypeError(`ReDevPlugin JSX attribute ${rawName} must be a string, number, or boolean`);
37
+ }
38
+ attributes[name] = value;
39
+ }
40
+ const children = [];
41
+ appendChildren(children, source.children, key, []);
42
+ const tree = {
43
+ type: "element",
44
+ key,
45
+ tag: type,
46
+ ...(Object.keys(attributes).length > 0 ? { attributes } : {}),
47
+ ...(children.length > 0 ? { children } : {}),
48
+ };
49
+ return validatePluginUITree(tree);
50
+ }
51
+ function appendChildren(target, value, parentKey, path) {
52
+ if (value === null || value === undefined || typeof value === "boolean")
53
+ return;
54
+ if (Array.isArray(value)) {
55
+ value.forEach((child, index) => appendChildren(target, child, parentKey, [...path, index]));
56
+ return;
57
+ }
58
+ if (typeof value === "string" || typeof value === "number") {
59
+ const textPath = path.length > 0 ? path : [0];
60
+ target.push({ type: "text", key: textKey(parentKey, textPath), text: String(value) });
61
+ return;
62
+ }
63
+ if (typeof value === "object") {
64
+ target.push(value);
65
+ return;
66
+ }
67
+ throw new TypeError("ReDevPlugin JSX children must be VNodes or renderable primitive values");
68
+ }
69
+ function textKey(parentKey, path) {
70
+ const suffix = `.text.${path.join(".")}`;
71
+ const candidate = parentKey + suffix;
72
+ if (candidate.length <= 128)
73
+ return candidate;
74
+ const hashSuffix = `.text.${fnv1a(candidate)}`;
75
+ return parentKey.slice(0, 128 - hashSuffix.length) + hashSuffix;
76
+ }
77
+ function fnv1a(value) {
78
+ let hash = 0x811c9dc5;
79
+ for (let index = 0; index < value.length; index += 1) {
80
+ hash ^= value.charCodeAt(index);
81
+ hash = Math.imul(hash, 0x01000193);
82
+ }
83
+ return (hash >>> 0).toString(16).padStart(8, "0");
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/redevplugin-ui",
3
- "version": "0.6.23",
3
+ "version": "0.6.24",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -23,6 +23,14 @@
23
23
  "types": "./dist/plugin.d.ts",
24
24
  "default": "./dist/plugin.js"
25
25
  },
26
+ "./jsx-runtime": {
27
+ "types": "./dist/jsx-runtime.d.ts",
28
+ "default": "./dist/jsx-runtime.js"
29
+ },
30
+ "./jsx-dev-runtime": {
31
+ "types": "./dist/jsx-dev-runtime.d.ts",
32
+ "default": "./dist/jsx-dev-runtime.js"
33
+ },
26
34
  "./local-import": {
27
35
  "types": "./dist/local-import.d.ts",
28
36
  "default": "./dist/local-import.js"
@@ -32,7 +40,7 @@
32
40
  "dist"
33
41
  ],
34
42
  "dependencies": {
35
- "@floegence/redevplugin-contracts": "0.6.23"
43
+ "@floegence/redevplugin-contracts": "0.6.24"
36
44
  },
37
45
  "publishConfig": {
38
46
  "access": "public"
@@ -40,6 +48,6 @@
40
48
  "scripts": {
41
49
  "build": "tsc -p tsconfig.json",
42
50
  "typecheck": "tsc -p tsconfig.json --noEmit",
43
- "test": "tsc -p tsconfig.test.json && node --test dist-test/test/*.js"
51
+ "test": "tsc -p tsconfig.json && tsc -p tsconfig.test.json && node --test dist-test/test/*.js"
44
52
  }
45
53
  }