@mmapp/react 0.1.0-alpha.19 → 0.1.0-alpha.21
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/actions-HOXZPBTT.mjs +116 -0
- package/dist/chunk-FBKUGKQI.mjs +1938 -0
- package/dist/chunk-XWBUADY2.mjs +2039 -0
- package/dist/chunk-ZAHMWAER.mjs +1960 -0
- package/dist/index.js +121 -18
- package/dist/index.mjs +1 -1
- package/dist/input-YMO6H7RP.mjs +224 -0
- package/dist/player/index.js +121 -18
- package/dist/player/index.mjs +1 -1
- package/package.json +8 -4
package/dist/player/index.js
CHANGED
|
@@ -999,7 +999,7 @@ var init_actions = __esm({
|
|
|
999
999
|
},
|
|
1000
1000
|
children: [
|
|
1001
1001
|
isLoading || loadingProp ? "\u23F3" : icon ? String(icon) : null,
|
|
1002
|
-
text != null ? String(text) : null,
|
|
1002
|
+
text != null ? typeof text === "string" || typeof text === "number" ? String(text) : text : null,
|
|
1003
1003
|
iconRight ? String(iconRight) : null
|
|
1004
1004
|
]
|
|
1005
1005
|
}
|
|
@@ -1127,9 +1127,10 @@ var init_input = __esm({
|
|
|
1127
1127
|
}
|
|
1128
1128
|
}, [value]);
|
|
1129
1129
|
const handleChange = (0, import_react5.useCallback)((e) => {
|
|
1130
|
-
|
|
1130
|
+
const val = e.target.value;
|
|
1131
|
+
setLocalValue(val);
|
|
1131
1132
|
if (typeof onChange === "function") {
|
|
1132
|
-
onChange(
|
|
1133
|
+
onChange(val);
|
|
1133
1134
|
}
|
|
1134
1135
|
}, [onChange]);
|
|
1135
1136
|
const displayValue = isControlled ? value ?? "" : localValue;
|
|
@@ -1195,8 +1196,9 @@ var init_input = __esm({
|
|
|
1195
1196
|
if (value != null && String(value) !== localValue) setLocalValue(String(value));
|
|
1196
1197
|
}, [value]);
|
|
1197
1198
|
const handleChange = (0, import_react5.useCallback)((e) => {
|
|
1198
|
-
|
|
1199
|
-
|
|
1199
|
+
const val = e.target.value;
|
|
1200
|
+
setLocalValue(val);
|
|
1201
|
+
if (typeof onChange === "function") onChange(val);
|
|
1200
1202
|
}, [onChange]);
|
|
1201
1203
|
const displayValue = isControlled ? value ?? "" : localValue;
|
|
1202
1204
|
const opts = Array.isArray(options) ? options : [];
|
|
@@ -2083,6 +2085,14 @@ function resolveFunction(name, rawArgs, scope) {
|
|
|
2083
2085
|
function resolveAction(name, rawArgs, scope) {
|
|
2084
2086
|
const actions = scope.$action;
|
|
2085
2087
|
if (!actions) return void 0;
|
|
2088
|
+
if (name === "seq") {
|
|
2089
|
+
return () => {
|
|
2090
|
+
for (const arg of rawArgs) {
|
|
2091
|
+
const resolved = resolveBinding(arg.trim(), scope);
|
|
2092
|
+
if (typeof resolved === "function") resolved();
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2086
2096
|
if (rawArgs.length === 0) {
|
|
2087
2097
|
const actionFn2 = actions[name];
|
|
2088
2098
|
if (typeof actionFn2 === "function") return actionFn2;
|
|
@@ -2096,6 +2106,24 @@ function resolveAction(name, rawArgs, scope) {
|
|
|
2096
2106
|
};
|
|
2097
2107
|
}
|
|
2098
2108
|
function resolveCondition(expression, scope) {
|
|
2109
|
+
const arrowMatch = expression.match(/^\(\)\s*=>\s*(.+)$/s);
|
|
2110
|
+
if (arrowMatch) {
|
|
2111
|
+
const body = arrowMatch[1].trim();
|
|
2112
|
+
const actionCallMatch = body.match(/^\(?(\$action)\)?\.(\w+)\((.*)?\)$/s);
|
|
2113
|
+
if (actionCallMatch) {
|
|
2114
|
+
const [, , method, argsStr] = actionCallMatch;
|
|
2115
|
+
return () => {
|
|
2116
|
+
const actionFn = scope.$action?.[method];
|
|
2117
|
+
if (typeof actionFn !== "function") return;
|
|
2118
|
+
const args = argsStr ? splitArgs(argsStr.trim()).map((a) => resolveBinding(a.trim(), scope)) : [];
|
|
2119
|
+
return actionFn(...args);
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
return () => {
|
|
2123
|
+
const context2 = buildEvalContext(scope);
|
|
2124
|
+
return evaluateExpression(body, context2);
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2099
2127
|
const context = buildEvalContext(scope);
|
|
2100
2128
|
return evaluateExpression(expression, context);
|
|
2101
2129
|
}
|
|
@@ -2119,6 +2147,11 @@ function buildEvalContext(scope) {
|
|
|
2119
2147
|
}
|
|
2120
2148
|
if (scope.$item) ctx.item = scope.$item;
|
|
2121
2149
|
if (scope.$index != null) ctx.index = scope.$index;
|
|
2150
|
+
for (const [key, value] of Object.entries(scope)) {
|
|
2151
|
+
if (!key.startsWith("$") && !(key in ctx) && value !== void 0) {
|
|
2152
|
+
ctx[key] = value;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2122
2155
|
if (scope.state_data) ctx.state_data = scope.state_data;
|
|
2123
2156
|
if (scope.memory) ctx.memory = scope.memory;
|
|
2124
2157
|
if (scope.context) ctx.context = scope.context;
|
|
@@ -2127,17 +2160,34 @@ function buildEvalContext(scope) {
|
|
|
2127
2160
|
function buildActionScope(opts) {
|
|
2128
2161
|
const { resolver, instanceId, slug, setLocal, router, toast, refreshQuery, onEvent } = opts;
|
|
2129
2162
|
return {
|
|
2130
|
-
transition: async (
|
|
2131
|
-
|
|
2163
|
+
transition: async (idOrName, nameOrId, data) => {
|
|
2164
|
+
let targetId;
|
|
2165
|
+
let transitionName;
|
|
2166
|
+
if (nameOrId) {
|
|
2167
|
+
targetId = idOrName;
|
|
2168
|
+
transitionName = nameOrId;
|
|
2169
|
+
} else {
|
|
2170
|
+
transitionName = idOrName;
|
|
2171
|
+
targetId = instanceId;
|
|
2172
|
+
}
|
|
2132
2173
|
if (!targetId) {
|
|
2133
2174
|
console.warn("[action] transition called without instanceId");
|
|
2134
2175
|
return;
|
|
2135
2176
|
}
|
|
2136
|
-
await resolver.transition(targetId,
|
|
2177
|
+
await resolver.transition(targetId, transitionName, data);
|
|
2137
2178
|
refreshQuery?.();
|
|
2138
2179
|
},
|
|
2139
|
-
create: async (
|
|
2140
|
-
|
|
2180
|
+
create: async (slugOrData, data) => {
|
|
2181
|
+
let targetSlug;
|
|
2182
|
+
let fields;
|
|
2183
|
+
if (typeof slugOrData === "object") {
|
|
2184
|
+
targetSlug = slug || "";
|
|
2185
|
+
fields = slugOrData;
|
|
2186
|
+
} else {
|
|
2187
|
+
targetSlug = slugOrData || slug || "";
|
|
2188
|
+
fields = data;
|
|
2189
|
+
}
|
|
2190
|
+
const id = await resolver.create(targetSlug, fields);
|
|
2141
2191
|
refreshQuery?.();
|
|
2142
2192
|
return id;
|
|
2143
2193
|
},
|
|
@@ -2460,6 +2510,14 @@ var PlayerProvider = ({
|
|
|
2460
2510
|
|
|
2461
2511
|
// src/player/ExperienceRenderer.tsx
|
|
2462
2512
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2513
|
+
var SharedLocalContext = import_react12.default.createContext({
|
|
2514
|
+
state: {},
|
|
2515
|
+
setLocal: () => {
|
|
2516
|
+
}
|
|
2517
|
+
});
|
|
2518
|
+
function useSharedLocal() {
|
|
2519
|
+
return import_react12.default.useContext(SharedLocalContext);
|
|
2520
|
+
}
|
|
2463
2521
|
var NodeErrorBoundary = class extends import_react12.default.Component {
|
|
2464
2522
|
constructor(props) {
|
|
2465
2523
|
super(props);
|
|
@@ -2677,13 +2735,19 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
2677
2735
|
const resolver = playerCtx?.resolver ?? null;
|
|
2678
2736
|
const atomRegistry = playerCtx?.atomRegistry;
|
|
2679
2737
|
const themeTokens = useTheme();
|
|
2738
|
+
const sharedLocal = useSharedLocal();
|
|
2680
2739
|
const localDefaults = node.config?.localDefaults ?? {};
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2740
|
+
(0, import_react12.useEffect)(() => {
|
|
2741
|
+
if (Object.keys(localDefaults).length > 0) {
|
|
2742
|
+
for (const [key, value] of Object.entries(localDefaults)) {
|
|
2743
|
+
if (sharedLocal.state[key] === void 0) {
|
|
2744
|
+
sharedLocal.setLocal(key, value);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2686
2748
|
}, []);
|
|
2749
|
+
const localState = sharedLocal.state;
|
|
2750
|
+
const handleSetLocal = sharedLocal.setLocal;
|
|
2687
2751
|
const [, setFetchVersion] = (0, import_react12.useState)(0);
|
|
2688
2752
|
const handleRefreshQuery = (0, import_react12.useCallback)(() => {
|
|
2689
2753
|
setFetchVersion((v) => v + 1);
|
|
@@ -2739,7 +2803,35 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
2739
2803
|
const enrichedScope = (0, import_react12.useMemo)(() => {
|
|
2740
2804
|
const handleCreate = () => {
|
|
2741
2805
|
if (primarySlug && resolver) {
|
|
2742
|
-
|
|
2806
|
+
const fields = {};
|
|
2807
|
+
for (const [key, val] of Object.entries(localState)) {
|
|
2808
|
+
if (key.startsWith("new_") && val != null && val !== "") {
|
|
2809
|
+
fields[key.slice(4)] = val;
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
resolver.create(primarySlug, Object.keys(fields).length > 0 ? fields : void 0).then(() => {
|
|
2813
|
+
for (const key of Object.keys(localState)) {
|
|
2814
|
+
if (key.startsWith("new_")) handleSetLocal(key, "");
|
|
2815
|
+
}
|
|
2816
|
+
handleSetLocal("show_create", false);
|
|
2817
|
+
handleRefreshQuery();
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
const handleUpdate = (id) => {
|
|
2822
|
+
if (primarySlug && resolver) {
|
|
2823
|
+
const fields = {};
|
|
2824
|
+
for (const [key, val] of Object.entries(localState)) {
|
|
2825
|
+
if (key.startsWith("edit_") && val != null && val !== "") {
|
|
2826
|
+
fields[key.slice(5)] = val;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
if (Object.keys(fields).length > 0) {
|
|
2830
|
+
resolver.update(id, fields).then(() => {
|
|
2831
|
+
handleSetLocal("editing_id", null);
|
|
2832
|
+
handleRefreshQuery();
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2743
2835
|
}
|
|
2744
2836
|
};
|
|
2745
2837
|
const setSearch = (e) => {
|
|
@@ -2749,15 +2841,18 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
2749
2841
|
const enrichedAction = {
|
|
2750
2842
|
...scope.$action,
|
|
2751
2843
|
handleCreate,
|
|
2844
|
+
handleUpdate,
|
|
2752
2845
|
setSearch
|
|
2753
2846
|
};
|
|
2754
|
-
const
|
|
2847
|
+
const baseInstance = scope.$instance ?? { id: "", state: "", fields: {} };
|
|
2848
|
+
const enrichedInstance = { ...baseInstance, handleCreate, handleUpdate, setSearch };
|
|
2755
2849
|
return {
|
|
2756
2850
|
...scope,
|
|
2757
2851
|
$action: enrichedAction,
|
|
2758
2852
|
$instance: enrichedInstance,
|
|
2759
2853
|
// Also add at top-level for direct access
|
|
2760
2854
|
handleCreate,
|
|
2855
|
+
handleUpdate,
|
|
2761
2856
|
setSearch
|
|
2762
2857
|
};
|
|
2763
2858
|
}, [scope, primarySlug, resolver, handleRefreshQuery, handleSetLocal]);
|
|
@@ -2834,6 +2929,14 @@ var ExperienceRenderer = ({
|
|
|
2834
2929
|
}) => {
|
|
2835
2930
|
const playerCtx = usePlayerContext();
|
|
2836
2931
|
const nodes = Array.isArray(tree) ? tree : [tree];
|
|
2932
|
+
const [sharedLocalState, setSharedLocalState] = (0, import_react12.useState)({});
|
|
2933
|
+
const handleSharedSetLocal = (0, import_react12.useCallback)((key, value) => {
|
|
2934
|
+
setSharedLocalState((prev) => ({ ...prev, [key]: value }));
|
|
2935
|
+
}, []);
|
|
2936
|
+
const sharedLocal = (0, import_react12.useMemo)(() => ({
|
|
2937
|
+
state: sharedLocalState,
|
|
2938
|
+
setLocal: handleSharedSetLocal
|
|
2939
|
+
}), [sharedLocalState, handleSharedSetLocal]);
|
|
2837
2940
|
const rootScope = (0, import_react12.useMemo)(() => buildScope({
|
|
2838
2941
|
auth: playerCtx?.auth ?? initialScope?.auth,
|
|
2839
2942
|
entity,
|
|
@@ -2864,7 +2967,7 @@ var ExperienceRenderer = ({
|
|
|
2864
2967
|
}
|
|
2865
2968
|
}
|
|
2866
2969
|
}), [playerCtx?.auth, entity, initialScope]);
|
|
2867
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ScopeContext.Provider, { value: rootScope, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className, children: nodes.map((node, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NodeErrorBoundary, { nodeId: node.id, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NodeRenderer, { node, fallback }) }, node.id ?? i)) }) });
|
|
2970
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SharedLocalContext.Provider, { value: sharedLocal, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ScopeContext.Provider, { value: rootScope, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className, children: nodes.map((node, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NodeErrorBoundary, { nodeId: node.id, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NodeRenderer, { node, fallback }) }, node.id ?? i)) }) }) });
|
|
2868
2971
|
};
|
|
2869
2972
|
|
|
2870
2973
|
// src/player/resolver.ts
|
package/dist/player/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmapp/react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"description": "React integration for the MindMatrix Player — hooks, components, and WebSocket bridge for browser-side workflow engines",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -35,9 +35,13 @@
|
|
|
35
35
|
"@tanstack/react-query": ">=5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@mmapp/player-core": "
|
|
38
|
+
"@mmapp/player-core": "workspace:*"
|
|
39
39
|
},
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^19.0.0",
|
|
42
|
+
"react": "^19.0.0",
|
|
43
|
+
"tsup": "^8.0.0",
|
|
44
|
+
"typescript": "^5.4.0",
|
|
45
|
+
"vitest": "^1.5.0"
|
|
42
46
|
}
|
|
43
47
|
}
|