@mmapp/react 0.1.0-alpha.20 → 0.1.0-alpha.22
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.
Potentially problematic release.
This version of @mmapp/react might be problematic. Click here for more details.
- package/dist/chunk-XWBUADY2.mjs +2039 -0
- package/dist/index.js +92 -11
- package/dist/index.mjs +1 -1
- package/dist/input-YMO6H7RP.mjs +224 -0
- package/dist/player/index.js +92 -11
- package/dist/player/index.mjs +1 -1
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -1123,9 +1123,10 @@ var init_input = __esm({
|
|
|
1123
1123
|
}
|
|
1124
1124
|
}, [value]);
|
|
1125
1125
|
const handleChange = (0, import_react37.useCallback)((e) => {
|
|
1126
|
-
|
|
1126
|
+
const val = e.target.value;
|
|
1127
|
+
setLocalValue(val);
|
|
1127
1128
|
if (typeof onChange === "function") {
|
|
1128
|
-
onChange(
|
|
1129
|
+
onChange(val);
|
|
1129
1130
|
}
|
|
1130
1131
|
}, [onChange]);
|
|
1131
1132
|
const displayValue = isControlled ? value ?? "" : localValue;
|
|
@@ -1191,8 +1192,9 @@ var init_input = __esm({
|
|
|
1191
1192
|
if (value != null && String(value) !== localValue) setLocalValue(String(value));
|
|
1192
1193
|
}, [value]);
|
|
1193
1194
|
const handleChange = (0, import_react37.useCallback)((e) => {
|
|
1194
|
-
|
|
1195
|
-
|
|
1195
|
+
const val = e.target.value;
|
|
1196
|
+
setLocalValue(val);
|
|
1197
|
+
if (typeof onChange === "function") onChange(val);
|
|
1196
1198
|
}, [onChange]);
|
|
1197
1199
|
const displayValue = isControlled ? value ?? "" : localValue;
|
|
1198
1200
|
const opts = Array.isArray(options) ? options : [];
|
|
@@ -5915,6 +5917,14 @@ function resolveFunction(name, rawArgs, scope) {
|
|
|
5915
5917
|
function resolveAction(name, rawArgs, scope) {
|
|
5916
5918
|
const actions = scope.$action;
|
|
5917
5919
|
if (!actions) return void 0;
|
|
5920
|
+
if (name === "seq") {
|
|
5921
|
+
return () => {
|
|
5922
|
+
for (const arg of rawArgs) {
|
|
5923
|
+
const resolved = resolveBinding(arg.trim(), scope);
|
|
5924
|
+
if (typeof resolved === "function") resolved();
|
|
5925
|
+
}
|
|
5926
|
+
};
|
|
5927
|
+
}
|
|
5918
5928
|
if (rawArgs.length === 0) {
|
|
5919
5929
|
const actionFn2 = actions[name];
|
|
5920
5930
|
if (typeof actionFn2 === "function") return actionFn2;
|
|
@@ -5928,6 +5938,24 @@ function resolveAction(name, rawArgs, scope) {
|
|
|
5928
5938
|
};
|
|
5929
5939
|
}
|
|
5930
5940
|
function resolveCondition(expression, scope) {
|
|
5941
|
+
const arrowMatch = expression.match(/^\(\)\s*=>\s*(.+)$/s);
|
|
5942
|
+
if (arrowMatch) {
|
|
5943
|
+
const body = arrowMatch[1].trim();
|
|
5944
|
+
const actionCallMatch = body.match(/^\(?(\$action)\)?\.(\w+)\((.*)?\)$/s);
|
|
5945
|
+
if (actionCallMatch) {
|
|
5946
|
+
const [, , method, argsStr] = actionCallMatch;
|
|
5947
|
+
return () => {
|
|
5948
|
+
const actionFn = scope.$action?.[method];
|
|
5949
|
+
if (typeof actionFn !== "function") return;
|
|
5950
|
+
const args = argsStr ? splitArgs(argsStr.trim()).map((a) => resolveBinding(a.trim(), scope)) : [];
|
|
5951
|
+
return actionFn(...args);
|
|
5952
|
+
};
|
|
5953
|
+
}
|
|
5954
|
+
return () => {
|
|
5955
|
+
const context2 = buildEvalContext(scope);
|
|
5956
|
+
return evaluateExpression(body, context2);
|
|
5957
|
+
};
|
|
5958
|
+
}
|
|
5931
5959
|
const context = buildEvalContext(scope);
|
|
5932
5960
|
return evaluateExpression(expression, context);
|
|
5933
5961
|
}
|
|
@@ -5951,6 +5979,11 @@ function buildEvalContext(scope) {
|
|
|
5951
5979
|
}
|
|
5952
5980
|
if (scope.$item) ctx.item = scope.$item;
|
|
5953
5981
|
if (scope.$index != null) ctx.index = scope.$index;
|
|
5982
|
+
for (const [key, value] of Object.entries(scope)) {
|
|
5983
|
+
if (!key.startsWith("$") && !(key in ctx) && value !== void 0) {
|
|
5984
|
+
ctx[key] = value;
|
|
5985
|
+
}
|
|
5986
|
+
}
|
|
5954
5987
|
if (scope.state_data) ctx.state_data = scope.state_data;
|
|
5955
5988
|
if (scope.memory) ctx.memory = scope.memory;
|
|
5956
5989
|
if (scope.context) ctx.context = scope.context;
|
|
@@ -5959,17 +5992,34 @@ function buildEvalContext(scope) {
|
|
|
5959
5992
|
function buildActionScope(opts) {
|
|
5960
5993
|
const { resolver, instanceId, slug, setLocal, router, toast, refreshQuery, onEvent } = opts;
|
|
5961
5994
|
return {
|
|
5962
|
-
transition: async (
|
|
5963
|
-
|
|
5995
|
+
transition: async (idOrName, nameOrId, data) => {
|
|
5996
|
+
let targetId;
|
|
5997
|
+
let transitionName;
|
|
5998
|
+
if (nameOrId) {
|
|
5999
|
+
targetId = idOrName;
|
|
6000
|
+
transitionName = nameOrId;
|
|
6001
|
+
} else {
|
|
6002
|
+
transitionName = idOrName;
|
|
6003
|
+
targetId = instanceId;
|
|
6004
|
+
}
|
|
5964
6005
|
if (!targetId) {
|
|
5965
6006
|
console.warn("[action] transition called without instanceId");
|
|
5966
6007
|
return;
|
|
5967
6008
|
}
|
|
5968
|
-
await resolver.transition(targetId,
|
|
6009
|
+
await resolver.transition(targetId, transitionName, data);
|
|
5969
6010
|
refreshQuery?.();
|
|
5970
6011
|
},
|
|
5971
|
-
create: async (
|
|
5972
|
-
|
|
6012
|
+
create: async (slugOrData, data) => {
|
|
6013
|
+
let targetSlug;
|
|
6014
|
+
let fields;
|
|
6015
|
+
if (typeof slugOrData === "object") {
|
|
6016
|
+
targetSlug = slug || "";
|
|
6017
|
+
fields = slugOrData;
|
|
6018
|
+
} else {
|
|
6019
|
+
targetSlug = slugOrData || slug || "";
|
|
6020
|
+
fields = data;
|
|
6021
|
+
}
|
|
6022
|
+
const id = await resolver.create(targetSlug, fields);
|
|
5973
6023
|
refreshQuery?.();
|
|
5974
6024
|
return id;
|
|
5975
6025
|
},
|
|
@@ -6571,7 +6621,35 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
6571
6621
|
const enrichedScope = (0, import_react44.useMemo)(() => {
|
|
6572
6622
|
const handleCreate = () => {
|
|
6573
6623
|
if (primarySlug && resolver) {
|
|
6574
|
-
|
|
6624
|
+
const fields = {};
|
|
6625
|
+
for (const [key, val] of Object.entries(localState)) {
|
|
6626
|
+
if (key.startsWith("new_") && val != null && val !== "") {
|
|
6627
|
+
fields[key.slice(4)] = val;
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6630
|
+
resolver.create(primarySlug, Object.keys(fields).length > 0 ? fields : void 0).then(() => {
|
|
6631
|
+
for (const key of Object.keys(localState)) {
|
|
6632
|
+
if (key.startsWith("new_")) handleSetLocal(key, "");
|
|
6633
|
+
}
|
|
6634
|
+
handleSetLocal("show_create", false);
|
|
6635
|
+
handleRefreshQuery();
|
|
6636
|
+
});
|
|
6637
|
+
}
|
|
6638
|
+
};
|
|
6639
|
+
const handleUpdate = (id) => {
|
|
6640
|
+
if (primarySlug && resolver) {
|
|
6641
|
+
const fields = {};
|
|
6642
|
+
for (const [key, val] of Object.entries(localState)) {
|
|
6643
|
+
if (key.startsWith("edit_") && val != null && val !== "") {
|
|
6644
|
+
fields[key.slice(5)] = val;
|
|
6645
|
+
}
|
|
6646
|
+
}
|
|
6647
|
+
if (Object.keys(fields).length > 0) {
|
|
6648
|
+
resolver.update(id, fields).then(() => {
|
|
6649
|
+
handleSetLocal("editing_id", null);
|
|
6650
|
+
handleRefreshQuery();
|
|
6651
|
+
});
|
|
6652
|
+
}
|
|
6575
6653
|
}
|
|
6576
6654
|
};
|
|
6577
6655
|
const setSearch = (e) => {
|
|
@@ -6581,15 +6659,18 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
6581
6659
|
const enrichedAction = {
|
|
6582
6660
|
...scope.$action,
|
|
6583
6661
|
handleCreate,
|
|
6662
|
+
handleUpdate,
|
|
6584
6663
|
setSearch
|
|
6585
6664
|
};
|
|
6586
|
-
const
|
|
6665
|
+
const baseInstance = scope.$instance ?? { id: "", state: "", fields: {} };
|
|
6666
|
+
const enrichedInstance = { ...baseInstance, handleCreate, handleUpdate, setSearch };
|
|
6587
6667
|
return {
|
|
6588
6668
|
...scope,
|
|
6589
6669
|
$action: enrichedAction,
|
|
6590
6670
|
$instance: enrichedInstance,
|
|
6591
6671
|
// Also add at top-level for direct access
|
|
6592
6672
|
handleCreate,
|
|
6673
|
+
handleUpdate,
|
|
6593
6674
|
setSearch
|
|
6594
6675
|
};
|
|
6595
6676
|
}, [scope, primarySlug, resolver, handleRefreshQuery, handleSetLocal]);
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// src/player/atoms/input.tsx
|
|
2
|
+
import { useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
var inputBase = {
|
|
5
|
+
padding: "6px 12px",
|
|
6
|
+
border: "1px solid #e2e8f0",
|
|
7
|
+
borderRadius: 6,
|
|
8
|
+
fontSize: 14,
|
|
9
|
+
outline: "none",
|
|
10
|
+
width: "100%",
|
|
11
|
+
boxSizing: "border-box",
|
|
12
|
+
background: "#fff",
|
|
13
|
+
color: "#1a202c",
|
|
14
|
+
transition: "border-color 0.15s"
|
|
15
|
+
};
|
|
16
|
+
var TextInput = ({
|
|
17
|
+
value,
|
|
18
|
+
onChange,
|
|
19
|
+
onBlur,
|
|
20
|
+
placeholder,
|
|
21
|
+
label,
|
|
22
|
+
type,
|
|
23
|
+
name,
|
|
24
|
+
disabled,
|
|
25
|
+
required,
|
|
26
|
+
error,
|
|
27
|
+
helperText,
|
|
28
|
+
multiline,
|
|
29
|
+
rows,
|
|
30
|
+
maxLength,
|
|
31
|
+
className,
|
|
32
|
+
style,
|
|
33
|
+
bind: _bind
|
|
34
|
+
}) => {
|
|
35
|
+
const isControlled = typeof onChange === "function";
|
|
36
|
+
const [localValue, setLocalValue] = useState(value ?? "");
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (value != null && String(value) !== localValue) {
|
|
39
|
+
setLocalValue(String(value));
|
|
40
|
+
}
|
|
41
|
+
}, [value]);
|
|
42
|
+
const handleChange = useCallback((e) => {
|
|
43
|
+
const val = e.target.value;
|
|
44
|
+
setLocalValue(val);
|
|
45
|
+
if (typeof onChange === "function") {
|
|
46
|
+
onChange(val);
|
|
47
|
+
}
|
|
48
|
+
}, [onChange]);
|
|
49
|
+
const displayValue = isControlled ? value ?? "" : localValue;
|
|
50
|
+
const hasError = Boolean(error);
|
|
51
|
+
const inputStyle = {
|
|
52
|
+
...inputBase,
|
|
53
|
+
borderColor: hasError ? "#e53e3e" : "#e2e8f0",
|
|
54
|
+
...style
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", { className, style: { width: "100%" }, children: [
|
|
57
|
+
label ? /* @__PURE__ */ jsxs("label", { style: { display: "block", fontSize: 13, fontWeight: 500, marginBottom: 4, color: "#4a5568" }, children: [
|
|
58
|
+
String(label),
|
|
59
|
+
required ? /* @__PURE__ */ jsx("span", { style: { color: "#e53e3e" }, children: " *" }) : null
|
|
60
|
+
] }) : null,
|
|
61
|
+
multiline ? /* @__PURE__ */ jsx(
|
|
62
|
+
"textarea",
|
|
63
|
+
{
|
|
64
|
+
value: displayValue,
|
|
65
|
+
onChange: handleChange,
|
|
66
|
+
onBlur,
|
|
67
|
+
placeholder,
|
|
68
|
+
name,
|
|
69
|
+
disabled: Boolean(disabled),
|
|
70
|
+
required: Boolean(required),
|
|
71
|
+
rows: Number(rows) || 3,
|
|
72
|
+
maxLength: maxLength ? Number(maxLength) : void 0,
|
|
73
|
+
style: inputStyle
|
|
74
|
+
}
|
|
75
|
+
) : /* @__PURE__ */ jsx(
|
|
76
|
+
"input",
|
|
77
|
+
{
|
|
78
|
+
type: type ?? "text",
|
|
79
|
+
value: displayValue,
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onBlur,
|
|
82
|
+
placeholder,
|
|
83
|
+
name,
|
|
84
|
+
disabled: Boolean(disabled),
|
|
85
|
+
required: Boolean(required),
|
|
86
|
+
maxLength: maxLength ? Number(maxLength) : void 0,
|
|
87
|
+
style: inputStyle
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
error || helperText ? /* @__PURE__ */ jsx("div", { style: { fontSize: 12, marginTop: 2, color: hasError ? "#e53e3e" : "#a0aec0" }, children: String(error || helperText) }) : null
|
|
91
|
+
] });
|
|
92
|
+
};
|
|
93
|
+
var Select = ({
|
|
94
|
+
value,
|
|
95
|
+
onChange,
|
|
96
|
+
options,
|
|
97
|
+
placeholder,
|
|
98
|
+
label,
|
|
99
|
+
disabled,
|
|
100
|
+
required,
|
|
101
|
+
error,
|
|
102
|
+
name,
|
|
103
|
+
className,
|
|
104
|
+
style
|
|
105
|
+
}) => {
|
|
106
|
+
const [localValue, setLocalValue] = useState(value ?? "");
|
|
107
|
+
const isControlled = typeof onChange === "function";
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (value != null && String(value) !== localValue) setLocalValue(String(value));
|
|
110
|
+
}, [value]);
|
|
111
|
+
const handleChange = useCallback((e) => {
|
|
112
|
+
const val = e.target.value;
|
|
113
|
+
setLocalValue(val);
|
|
114
|
+
if (typeof onChange === "function") onChange(val);
|
|
115
|
+
}, [onChange]);
|
|
116
|
+
const displayValue = isControlled ? value ?? "" : localValue;
|
|
117
|
+
const opts = Array.isArray(options) ? options : [];
|
|
118
|
+
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
119
|
+
label ? /* @__PURE__ */ jsxs("label", { style: { display: "block", fontSize: 13, fontWeight: 500, marginBottom: 4, color: "#4a5568" }, children: [
|
|
120
|
+
String(label),
|
|
121
|
+
required ? /* @__PURE__ */ jsx("span", { style: { color: "#e53e3e" }, children: " *" }) : null
|
|
122
|
+
] }) : null,
|
|
123
|
+
/* @__PURE__ */ jsxs(
|
|
124
|
+
"select",
|
|
125
|
+
{
|
|
126
|
+
value: displayValue,
|
|
127
|
+
onChange: handleChange,
|
|
128
|
+
disabled: Boolean(disabled),
|
|
129
|
+
name,
|
|
130
|
+
style: {
|
|
131
|
+
...inputBase,
|
|
132
|
+
borderColor: error ? "#e53e3e" : "#e2e8f0",
|
|
133
|
+
...style
|
|
134
|
+
},
|
|
135
|
+
children: [
|
|
136
|
+
placeholder ? /* @__PURE__ */ jsx("option", { value: "", children: String(placeholder) }) : null,
|
|
137
|
+
opts.map((opt, i) => {
|
|
138
|
+
const val = typeof opt === "object" ? opt.value : opt;
|
|
139
|
+
const lbl = typeof opt === "object" ? opt.label ?? val : opt;
|
|
140
|
+
return /* @__PURE__ */ jsx("option", { value: String(val), children: String(lbl) }, String(val) ?? i);
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
] });
|
|
146
|
+
};
|
|
147
|
+
var Toggle = ({ value, checked, onChange, label, disabled, className, style }) => {
|
|
148
|
+
const isOn = Boolean(value ?? checked);
|
|
149
|
+
const handleClick = useCallback(() => {
|
|
150
|
+
if (disabled) return;
|
|
151
|
+
if (typeof onChange === "function") onChange(!isOn);
|
|
152
|
+
}, [onChange, isOn, disabled]);
|
|
153
|
+
return /* @__PURE__ */ jsxs(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
className,
|
|
157
|
+
style: { display: "flex", alignItems: "center", gap: 8, ...style },
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ jsx(
|
|
160
|
+
"button",
|
|
161
|
+
{
|
|
162
|
+
role: "switch",
|
|
163
|
+
"aria-checked": isOn,
|
|
164
|
+
disabled: Boolean(disabled),
|
|
165
|
+
onClick: handleClick,
|
|
166
|
+
style: {
|
|
167
|
+
width: 40,
|
|
168
|
+
height: 22,
|
|
169
|
+
borderRadius: 11,
|
|
170
|
+
border: "none",
|
|
171
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
172
|
+
background: isOn ? "#3182ce" : "#cbd5e0",
|
|
173
|
+
padding: 2,
|
|
174
|
+
transition: "background 0.2s",
|
|
175
|
+
display: "flex",
|
|
176
|
+
alignItems: "center"
|
|
177
|
+
},
|
|
178
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
179
|
+
width: 18,
|
|
180
|
+
height: 18,
|
|
181
|
+
borderRadius: "50%",
|
|
182
|
+
background: "#fff",
|
|
183
|
+
transform: isOn ? "translateX(18px)" : "translateX(0)",
|
|
184
|
+
transition: "transform 0.2s",
|
|
185
|
+
boxShadow: "0 1px 3px rgba(0,0,0,0.2)"
|
|
186
|
+
} })
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
label ? /* @__PURE__ */ jsx("span", { style: { fontSize: 14 }, children: String(label) }) : null
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
var Slider = ({ value, onChange, min, max, step, label, disabled, className, style }) => {
|
|
195
|
+
const numVal = Number(value) || Number(min) || 0;
|
|
196
|
+
const handleChange = useCallback((e) => {
|
|
197
|
+
if (typeof onChange === "function") onChange(Number(e.target.value));
|
|
198
|
+
}, [onChange]);
|
|
199
|
+
return /* @__PURE__ */ jsxs("div", { className, style: { ...style }, children: [
|
|
200
|
+
label ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", fontSize: 13, marginBottom: 4 }, children: [
|
|
201
|
+
/* @__PURE__ */ jsx("span", { style: { color: "#4a5568", fontWeight: 500 }, children: String(label) }),
|
|
202
|
+
/* @__PURE__ */ jsx("span", { style: { color: "#718096" }, children: numVal })
|
|
203
|
+
] }) : null,
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
"input",
|
|
206
|
+
{
|
|
207
|
+
type: "range",
|
|
208
|
+
value: numVal,
|
|
209
|
+
onChange: handleChange,
|
|
210
|
+
min: Number(min) ?? 0,
|
|
211
|
+
max: Number(max) ?? 100,
|
|
212
|
+
step: Number(step) ?? 1,
|
|
213
|
+
disabled: Boolean(disabled),
|
|
214
|
+
style: { width: "100%" }
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] });
|
|
218
|
+
};
|
|
219
|
+
export {
|
|
220
|
+
Select,
|
|
221
|
+
Slider,
|
|
222
|
+
TextInput,
|
|
223
|
+
Toggle
|
|
224
|
+
};
|
package/dist/player/index.js
CHANGED
|
@@ -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
|
},
|
|
@@ -2753,7 +2803,35 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
2753
2803
|
const enrichedScope = (0, import_react12.useMemo)(() => {
|
|
2754
2804
|
const handleCreate = () => {
|
|
2755
2805
|
if (primarySlug && resolver) {
|
|
2756
|
-
|
|
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
|
+
}
|
|
2757
2835
|
}
|
|
2758
2836
|
};
|
|
2759
2837
|
const setSearch = (e) => {
|
|
@@ -2763,15 +2841,18 @@ var NodeRenderer = ({ node, fallback }) => {
|
|
|
2763
2841
|
const enrichedAction = {
|
|
2764
2842
|
...scope.$action,
|
|
2765
2843
|
handleCreate,
|
|
2844
|
+
handleUpdate,
|
|
2766
2845
|
setSearch
|
|
2767
2846
|
};
|
|
2768
|
-
const
|
|
2847
|
+
const baseInstance = scope.$instance ?? { id: "", state: "", fields: {} };
|
|
2848
|
+
const enrichedInstance = { ...baseInstance, handleCreate, handleUpdate, setSearch };
|
|
2769
2849
|
return {
|
|
2770
2850
|
...scope,
|
|
2771
2851
|
$action: enrichedAction,
|
|
2772
2852
|
$instance: enrichedInstance,
|
|
2773
2853
|
// Also add at top-level for direct access
|
|
2774
2854
|
handleCreate,
|
|
2855
|
+
handleUpdate,
|
|
2775
2856
|
setSearch
|
|
2776
2857
|
};
|
|
2777
2858
|
}, [scope, primarySlug, resolver, handleRefreshQuery, handleSetLocal]);
|
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.22",
|
|
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
|
}
|