@almadar/ui 2.18.0 → 2.19.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/components/index.cjs +10 -6
- package/dist/components/index.js +10 -6
- package/dist/components/organisms/game/three/index.cjs +2 -4
- package/dist/components/organisms/game/three/index.js +2 -4
- package/dist/docs/index.cjs +33 -33
- package/dist/docs/index.js +11 -11
- package/dist/hooks/index.cjs +2 -4
- package/dist/hooks/index.js +1 -3
- package/dist/marketing/index.cjs +34 -28
- package/dist/marketing/index.js +21 -15
- package/dist/providers/EventBusProvider.d.ts +14 -4
- package/dist/providers/index.cjs +5 -6
- package/dist/providers/index.js +4 -5
- package/dist/runtime/OrbPreview.d.ts +39 -0
- package/dist/runtime/index.cjs +139 -2
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +138 -2
- package/package.json +1 -1
- package/dist/internals/event-bus-context.d.ts +0 -15
package/dist/runtime/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React110 from 'react';
|
|
2
2
|
import React110__default, { createContext, useCallback, useState, useRef, useLayoutEffect, useEffect, lazy, useContext, useMemo } from 'react';
|
|
3
|
+
import { EventBusContext } from '@almadar/ui/providers';
|
|
3
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
5
|
import '@tanstack/react-query';
|
|
5
6
|
import 'react-dom';
|
|
@@ -26,7 +27,6 @@ import { StateMachineManager, createContextFromBindings, interpolateValue, Effec
|
|
|
26
27
|
var __defProp = Object.defineProperty;
|
|
27
28
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
28
29
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
-
var EventBusContext = createContext(null);
|
|
30
30
|
function getGlobalEventBus() {
|
|
31
31
|
if (typeof window !== "undefined") {
|
|
32
32
|
return window.__kflowEventBus ?? null;
|
|
@@ -225,6 +225,7 @@ function useTranslate() {
|
|
|
225
225
|
}
|
|
226
226
|
typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
|
|
227
227
|
createContext(void 0);
|
|
228
|
+
createContext(null);
|
|
228
229
|
var FetchedDataContext = createContext(null);
|
|
229
230
|
function useFetchedDataContext() {
|
|
230
231
|
return useContext(FetchedDataContext);
|
|
@@ -2983,5 +2984,140 @@ function useSlotsActions() {
|
|
|
2983
2984
|
}
|
|
2984
2985
|
return actions;
|
|
2985
2986
|
}
|
|
2987
|
+
var runtimeCache = null;
|
|
2988
|
+
async function loadRuntime() {
|
|
2989
|
+
if (runtimeCache) return runtimeCache;
|
|
2990
|
+
const [providers, context, runtime, components] = await Promise.all([
|
|
2991
|
+
import('@almadar/ui/providers'),
|
|
2992
|
+
import('@almadar/ui/context'),
|
|
2993
|
+
import('@almadar/ui/runtime'),
|
|
2994
|
+
import('@almadar/ui/components')
|
|
2995
|
+
]);
|
|
2996
|
+
runtimeCache = {
|
|
2997
|
+
OrbitalProvider: providers.OrbitalProvider,
|
|
2998
|
+
UISlotProvider: context.UISlotProvider,
|
|
2999
|
+
SlotsProvider: runtime.SlotsProvider,
|
|
3000
|
+
EntitySchemaProvider: runtime.EntitySchemaProvider,
|
|
3001
|
+
VerificationProvider: providers.VerificationProvider,
|
|
3002
|
+
UISlotRenderer: components.UISlotRenderer,
|
|
3003
|
+
useResolvedSchema: runtime.useResolvedSchema,
|
|
3004
|
+
useTraitStateMachine: runtime.useTraitStateMachine,
|
|
3005
|
+
useSlotsActions: runtime.useSlotsActions,
|
|
3006
|
+
useSlots: runtime.useSlots,
|
|
3007
|
+
useUISlots: context.useUISlots
|
|
3008
|
+
};
|
|
3009
|
+
return runtimeCache;
|
|
3010
|
+
}
|
|
3011
|
+
function normalizeChild(child) {
|
|
3012
|
+
const { type, children, ...rest } = child;
|
|
3013
|
+
const normalizedChildren = Array.isArray(children) ? children.map((c) => normalizeChild(c)) : children;
|
|
3014
|
+
return {
|
|
3015
|
+
type,
|
|
3016
|
+
props: { ...rest, ...normalizedChildren !== void 0 ? { children: normalizedChildren } : {} }
|
|
3017
|
+
};
|
|
3018
|
+
}
|
|
3019
|
+
function SlotBridge({ rt }) {
|
|
3020
|
+
const slots = rt.useSlots();
|
|
3021
|
+
const { render, clear } = rt.useUISlots();
|
|
3022
|
+
useEffect(() => {
|
|
3023
|
+
for (const [slotName, slotState] of Object.entries(slots)) {
|
|
3024
|
+
if (slotState.patterns.length === 0) {
|
|
3025
|
+
clear(slotName);
|
|
3026
|
+
continue;
|
|
3027
|
+
}
|
|
3028
|
+
const entry = slotState.patterns[slotState.patterns.length - 1];
|
|
3029
|
+
const { type: patternType, children, ...inlineProps } = entry.pattern;
|
|
3030
|
+
const normalizedChildren = Array.isArray(children) ? children.map((c) => normalizeChild(c)) : children;
|
|
3031
|
+
render({
|
|
3032
|
+
target: slotName,
|
|
3033
|
+
pattern: patternType,
|
|
3034
|
+
props: {
|
|
3035
|
+
...inlineProps,
|
|
3036
|
+
...entry.props,
|
|
3037
|
+
...normalizedChildren !== void 0 ? { children: normalizedChildren } : {}
|
|
3038
|
+
},
|
|
3039
|
+
sourceTrait: slotState.source?.trait
|
|
3040
|
+
});
|
|
3041
|
+
}
|
|
3042
|
+
}, [slots]);
|
|
3043
|
+
return null;
|
|
3044
|
+
}
|
|
3045
|
+
function TraitInitializer({ rt, traits: traits2 }) {
|
|
3046
|
+
const slotsActions = rt.useSlotsActions();
|
|
3047
|
+
const { sendEvent } = rt.useTraitStateMachine(traits2, slotsActions, {});
|
|
3048
|
+
useEffect(() => {
|
|
3049
|
+
const t = setTimeout(() => sendEvent("INIT"), 50);
|
|
3050
|
+
return () => clearTimeout(t);
|
|
3051
|
+
}, [traits2]);
|
|
3052
|
+
return null;
|
|
3053
|
+
}
|
|
3054
|
+
function SchemaRunner({ rt, schema, mockData }) {
|
|
3055
|
+
const { traits: traits2, allEntities, ir } = rt.useResolvedSchema(schema);
|
|
3056
|
+
const allPageTraits = useMemo(() => {
|
|
3057
|
+
if (!ir?.pages || ir.pages.size <= 1) return traits2;
|
|
3058
|
+
const combined = [];
|
|
3059
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3060
|
+
for (const page of ir.pages.values()) {
|
|
3061
|
+
for (const t of page.traits) {
|
|
3062
|
+
const binding = t;
|
|
3063
|
+
const traitObj = binding.trait;
|
|
3064
|
+
const name = traitObj?.name ?? binding.name ?? "";
|
|
3065
|
+
if (name && !seen.has(name)) {
|
|
3066
|
+
seen.add(name);
|
|
3067
|
+
combined.push(t);
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
return combined.length > 0 ? combined : traits2;
|
|
3072
|
+
}, [ir, traits2]);
|
|
3073
|
+
return /* @__PURE__ */ jsx(rt.VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(rt.SlotsProvider, { children: /* @__PURE__ */ jsxs(rt.EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
|
|
3074
|
+
/* @__PURE__ */ jsx(TraitInitializer, { rt, traits: allPageTraits }),
|
|
3075
|
+
/* @__PURE__ */ jsx(SlotBridge, { rt }),
|
|
3076
|
+
/* @__PURE__ */ jsx(Box, { className: "min-h-full p-4", children: /* @__PURE__ */ jsx(rt.UISlotRenderer, { includeHud: true, hudMode: "inline", includeFloating: true }) })
|
|
3077
|
+
] }) }) });
|
|
3078
|
+
}
|
|
3079
|
+
function OrbPreview({
|
|
3080
|
+
schema,
|
|
3081
|
+
mockData = {},
|
|
3082
|
+
height = "400px",
|
|
3083
|
+
className
|
|
3084
|
+
}) {
|
|
3085
|
+
const [rt, setRt] = useState(null);
|
|
3086
|
+
const [error, setError] = useState(null);
|
|
3087
|
+
const parsedSchema = useMemo(() => {
|
|
3088
|
+
if (typeof schema === "string") {
|
|
3089
|
+
try {
|
|
3090
|
+
return JSON.parse(schema);
|
|
3091
|
+
} catch (e) {
|
|
3092
|
+
return { error: String(e) };
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
return schema;
|
|
3096
|
+
}, [schema]);
|
|
3097
|
+
useEffect(() => {
|
|
3098
|
+
loadRuntime().then(setRt).catch((e) => setError(String(e)));
|
|
3099
|
+
}, []);
|
|
3100
|
+
if (parsedSchema.error) {
|
|
3101
|
+
return /* @__PURE__ */ jsx(Box, { className, style: { height }, children: /* @__PURE__ */ jsxs(Typography, { as: "pre", color: "error", variant: "small", className: "font-mono whitespace-pre-wrap break-all m-0 p-4", children: [
|
|
3102
|
+
"Parse error: ",
|
|
3103
|
+
parsedSchema.error
|
|
3104
|
+
] }) });
|
|
3105
|
+
}
|
|
3106
|
+
if (error) {
|
|
3107
|
+
return /* @__PURE__ */ jsx(Box, { className, style: { height }, children: /* @__PURE__ */ jsx(Typography, { as: "pre", color: "error", variant: "small", className: "font-mono whitespace-pre-wrap break-all m-0 p-4", children: error }) });
|
|
3108
|
+
}
|
|
3109
|
+
if (!rt) {
|
|
3110
|
+
return /* @__PURE__ */ jsx(Box, { className: `flex items-center justify-center ${className ?? ""}`, style: { height }, children: /* @__PURE__ */ jsx(Typography, { color: "muted", variant: "small", children: "Loading runtime..." }) });
|
|
3111
|
+
}
|
|
3112
|
+
return /* @__PURE__ */ jsx(
|
|
3113
|
+
Box,
|
|
3114
|
+
{
|
|
3115
|
+
className: `overflow-auto border border-[var(--color-border)] rounded-[var(--radius-md)] ${className ?? ""}`,
|
|
3116
|
+
style: { height },
|
|
3117
|
+
children: /* @__PURE__ */ jsx(rt.OrbitalProvider, { initialData: mockData, skipTheme: true, verification: true, children: /* @__PURE__ */ jsx(rt.UISlotProvider, { children: /* @__PURE__ */ jsx(SchemaRunner, { rt, schema: parsedSchema, mockData }) }) })
|
|
3118
|
+
}
|
|
3119
|
+
);
|
|
3120
|
+
}
|
|
3121
|
+
OrbPreview.displayName = "OrbPreview";
|
|
2986
3122
|
|
|
2987
|
-
export { EntitySchemaProvider, SlotsProvider, TraitContext, TraitProvider, clearSchemaCache, createClientEffectHandlers, useEntityDefinition, useEntitySchema, useResolvedSchema, useSlotContent, useSlots, useSlotsActions, useTrait, useTraitContext, useTraitStateMachine };
|
|
3123
|
+
export { EntitySchemaProvider, OrbPreview, SlotsProvider, TraitContext, TraitProvider, clearSchemaCache, createClientEffectHandlers, useEntityDefinition, useEntitySchema, useResolvedSchema, useSlotContent, useSlots, useSlotsActions, useTrait, useTraitContext, useTraitStateMachine };
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { EventBusContextType } from '../hooks/event-bus-types';
|
|
2
|
-
/**
|
|
3
|
-
* Extended context type for backward compatibility.
|
|
4
|
-
*/
|
|
5
|
-
export interface EventBusContextTypeExtended extends EventBusContextType {
|
|
6
|
-
/** @deprecated Use useSelection from SelectionProvider instead. */
|
|
7
|
-
getSelectedEntity: () => unknown | null;
|
|
8
|
-
/** @deprecated Use useSelection from SelectionProvider instead. */
|
|
9
|
-
clearSelectedEntity: () => void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* The one and only EventBusContext.
|
|
13
|
-
* Imported by EventBusProvider (to provide) and useEventBus (to consume).
|
|
14
|
-
*/
|
|
15
|
-
export declare const EventBusContext: import("react").Context<EventBusContextTypeExtended | null>;
|