@rozenite/controls-plugin 1.10.0 → 1.12.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/CHANGELOG.md +22 -0
- package/README.md +33 -0
- package/dist/react-native/chunks/useRozeniteControlsPlugin.require.cjs +1 -1
- package/dist/react-native/chunks/useRozeniteControlsPlugin.require.js +320 -256
- package/dist/react-native/index.d.ts +5 -1
- package/dist/rozenite.json +1 -1
- package/package.json +8 -7
- package/react-native.d.ts +8 -4
- package/react-native.ts +2 -0
- package/src/react-native/__tests__/controlsRegistry.test.ts +92 -0
- package/src/react-native/__tests__/useRozeniteControlsPlugin.test.tsx +211 -0
- package/src/react-native/controlsRegistry.ts +101 -0
- package/src/react-native/useControlsAgentTools.ts +21 -14
- package/src/react-native/useRozeniteControlsPlugin.ts +56 -27
- package/src/shared/types.ts +9 -1
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as
|
|
2
|
-
import {
|
|
3
|
-
import { useRozenitePluginAgentTool as
|
|
4
|
-
import { defineAgentToolContract as
|
|
5
|
-
const U = (
|
|
6
|
-
id:
|
|
7
|
-
type:
|
|
8
|
-
title:
|
|
9
|
-
value:
|
|
10
|
-
description:
|
|
11
|
-
disabled:
|
|
12
|
-
} :
|
|
13
|
-
id:
|
|
14
|
-
type:
|
|
15
|
-
title:
|
|
16
|
-
actionLabel:
|
|
17
|
-
description:
|
|
18
|
-
disabled:
|
|
19
|
-
} :
|
|
20
|
-
id:
|
|
21
|
-
type:
|
|
22
|
-
title:
|
|
23
|
-
value:
|
|
24
|
-
options:
|
|
25
|
-
description:
|
|
26
|
-
disabled:
|
|
1
|
+
import { useRozeniteDevToolsClient as x } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useRef as z, useSyncExternalStore as A, useEffect as h, useMemo as C } from "react";
|
|
3
|
+
import { useRozenitePluginAgentTool as v } from "@rozenite/agent-bridge";
|
|
4
|
+
import { defineAgentToolContract as w } from "@rozenite/agent-shared";
|
|
5
|
+
const U = (t, n) => t ? t(n) : { valid: !0 }, D = (t) => t.type === "text" ? t : t.type === "toggle" ? {
|
|
6
|
+
id: t.id,
|
|
7
|
+
type: t.type,
|
|
8
|
+
title: t.title,
|
|
9
|
+
value: t.value,
|
|
10
|
+
description: t.description,
|
|
11
|
+
disabled: t.disabled
|
|
12
|
+
} : t.type === "button" ? {
|
|
13
|
+
id: t.id,
|
|
14
|
+
type: t.type,
|
|
15
|
+
title: t.title,
|
|
16
|
+
actionLabel: t.actionLabel,
|
|
17
|
+
description: t.description,
|
|
18
|
+
disabled: t.disabled
|
|
19
|
+
} : t.type === "select" ? {
|
|
20
|
+
id: t.id,
|
|
21
|
+
type: t.type,
|
|
22
|
+
title: t.title,
|
|
23
|
+
value: t.value,
|
|
24
|
+
options: t.options,
|
|
25
|
+
description: t.description,
|
|
26
|
+
disabled: t.disabled
|
|
27
27
|
} : {
|
|
28
|
-
id:
|
|
29
|
-
type:
|
|
30
|
-
title:
|
|
31
|
-
value:
|
|
32
|
-
placeholder:
|
|
33
|
-
applyLabel:
|
|
34
|
-
description:
|
|
35
|
-
disabled:
|
|
36
|
-
},
|
|
37
|
-
id:
|
|
38
|
-
title:
|
|
39
|
-
description:
|
|
40
|
-
items:
|
|
41
|
-
})),
|
|
42
|
-
const
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
28
|
+
id: t.id,
|
|
29
|
+
type: t.type,
|
|
30
|
+
title: t.title,
|
|
31
|
+
value: t.value,
|
|
32
|
+
placeholder: t.placeholder,
|
|
33
|
+
applyLabel: t.applyLabel,
|
|
34
|
+
description: t.description,
|
|
35
|
+
disabled: t.disabled
|
|
36
|
+
}, m = (t) => t.map((n) => ({
|
|
37
|
+
id: n.id,
|
|
38
|
+
title: n.title,
|
|
39
|
+
description: n.description,
|
|
40
|
+
items: n.items.map(D)
|
|
41
|
+
})), O = (t) => {
|
|
42
|
+
const n = /* @__PURE__ */ new Map();
|
|
43
|
+
return t.forEach((r) => {
|
|
44
|
+
r.items.forEach((s) => {
|
|
45
|
+
const e = `${r.id}:${s.id}`;
|
|
46
|
+
s.type === "toggle" && n.set(e, {
|
|
47
47
|
type: "toggle",
|
|
48
|
-
validate:
|
|
49
|
-
onUpdate:
|
|
50
|
-
}),
|
|
48
|
+
validate: s.validate,
|
|
49
|
+
onUpdate: s.onUpdate
|
|
50
|
+
}), s.type === "button" && n.set(e, {
|
|
51
51
|
type: "button",
|
|
52
|
-
onPress:
|
|
53
|
-
}),
|
|
52
|
+
onPress: s.onPress
|
|
53
|
+
}), s.type === "select" && n.set(e, {
|
|
54
54
|
type: "select",
|
|
55
|
-
validate:
|
|
56
|
-
onUpdate:
|
|
57
|
-
}),
|
|
55
|
+
validate: s.validate,
|
|
56
|
+
onUpdate: s.onUpdate
|
|
57
|
+
}), s.type === "input" && n.set(e, {
|
|
58
58
|
type: "input",
|
|
59
|
-
validate:
|
|
60
|
-
onUpdate:
|
|
59
|
+
validate: s.validate,
|
|
60
|
+
onUpdate: s.onUpdate
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
|
-
}),
|
|
64
|
-
},
|
|
65
|
-
listSections:
|
|
63
|
+
}), n;
|
|
64
|
+
}, P = (t, n) => `${t}:${n}`, $ = "@rozenite/controls-plugin", E = {
|
|
65
|
+
listSections: w({
|
|
66
66
|
name: "list-sections",
|
|
67
67
|
description: "List all controls sections with their item IDs, types, and titles. Does not include values — call get-item for that.",
|
|
68
68
|
inputSchema: { type: "object", properties: {} }
|
|
69
69
|
}),
|
|
70
|
-
getItem:
|
|
70
|
+
getItem: w({
|
|
71
71
|
name: "get-item",
|
|
72
72
|
description: "Get full details of a single controls item including its current value. For select items this includes available options.",
|
|
73
73
|
inputSchema: {
|
|
@@ -79,7 +79,7 @@ const U = (o, e) => o ? o(e) : { valid: !0 }, z = (o) => o.type === "text" ? o :
|
|
|
79
79
|
required: ["sectionId", "itemId"]
|
|
80
80
|
}
|
|
81
81
|
}),
|
|
82
|
-
setValue:
|
|
82
|
+
setValue: w({
|
|
83
83
|
name: "set-value",
|
|
84
84
|
description: "Update the value of a toggle, select, or input item. Runs the validate callback when present. Fails for text (read-only) and button items.",
|
|
85
85
|
inputSchema: {
|
|
@@ -94,7 +94,7 @@ const U = (o, e) => o ? o(e) : { valid: !0 }, z = (o) => o.type === "text" ? o :
|
|
|
94
94
|
required: ["sectionId", "itemId", "value"]
|
|
95
95
|
}
|
|
96
96
|
}),
|
|
97
|
-
pressButton:
|
|
97
|
+
pressButton: w({
|
|
98
98
|
name: "press-button",
|
|
99
99
|
description: "Trigger a button item's action. Fails if the item is not a button or is disabled.",
|
|
100
100
|
inputSchema: {
|
|
@@ -106,321 +106,385 @@ const U = (o, e) => o ? o(e) : { valid: !0 }, z = (o) => o.type === "text" ? o :
|
|
|
106
106
|
required: ["sectionId", "itemId"]
|
|
107
107
|
}
|
|
108
108
|
})
|
|
109
|
-
},
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
112
|
-
const
|
|
109
|
+
}, R = (t, n, r) => {
|
|
110
|
+
const s = t.find((i) => i.id === n);
|
|
111
|
+
if (!s) {
|
|
112
|
+
const i = t.map((o) => o.id).join(", ");
|
|
113
113
|
throw new Error(
|
|
114
|
-
`Section "${
|
|
114
|
+
`Section "${n}" not found. Available: ${i || "(none)"}`
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
|
-
const
|
|
118
|
-
if (!
|
|
119
|
-
const
|
|
117
|
+
const e = s.items.find((i) => i.id === r);
|
|
118
|
+
if (!e) {
|
|
119
|
+
const i = s.items.map((o) => o.id).join(", ");
|
|
120
120
|
throw new Error(
|
|
121
|
-
`Item "${
|
|
121
|
+
`Item "${r}" not found in section "${n}". Available: ${i || "(none)"}`
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
|
-
return { section:
|
|
125
|
-
}, L = (
|
|
126
|
-
|
|
127
|
-
pluginId:
|
|
128
|
-
tool:
|
|
124
|
+
return { section: s, item: e };
|
|
125
|
+
}, L = (t, n = !0) => {
|
|
126
|
+
v({
|
|
127
|
+
pluginId: $,
|
|
128
|
+
tool: E.listSections,
|
|
129
|
+
enabled: n,
|
|
129
130
|
handler: () => ({
|
|
130
|
-
sections:
|
|
131
|
-
id:
|
|
132
|
-
title:
|
|
133
|
-
description:
|
|
134
|
-
items:
|
|
135
|
-
id:
|
|
136
|
-
type:
|
|
137
|
-
title:
|
|
138
|
-
disabled: "disabled" in
|
|
131
|
+
sections: t().map((r) => ({
|
|
132
|
+
id: r.id,
|
|
133
|
+
title: r.title,
|
|
134
|
+
description: r.description,
|
|
135
|
+
items: r.items.map((s) => ({
|
|
136
|
+
id: s.id,
|
|
137
|
+
type: s.type,
|
|
138
|
+
title: s.title,
|
|
139
|
+
disabled: "disabled" in s ? s.disabled : void 0
|
|
139
140
|
}))
|
|
140
141
|
}))
|
|
141
142
|
})
|
|
142
|
-
}),
|
|
143
|
-
pluginId:
|
|
144
|
-
tool:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
}), v({
|
|
144
|
+
pluginId: $,
|
|
145
|
+
tool: E.getItem,
|
|
146
|
+
enabled: n,
|
|
147
|
+
handler: ({ sectionId: r, itemId: s }) => {
|
|
148
|
+
const { item: e } = R(t(), r, s);
|
|
149
|
+
return e.type === "text" ? {
|
|
150
|
+
sectionId: r,
|
|
149
151
|
item: {
|
|
150
|
-
id:
|
|
151
|
-
type:
|
|
152
|
-
title:
|
|
153
|
-
value:
|
|
154
|
-
description:
|
|
152
|
+
id: e.id,
|
|
153
|
+
type: e.type,
|
|
154
|
+
title: e.title,
|
|
155
|
+
value: e.value,
|
|
156
|
+
description: e.description
|
|
155
157
|
}
|
|
156
|
-
} :
|
|
157
|
-
sectionId:
|
|
158
|
+
} : e.type === "toggle" ? {
|
|
159
|
+
sectionId: r,
|
|
158
160
|
item: {
|
|
159
|
-
id:
|
|
160
|
-
type:
|
|
161
|
-
title:
|
|
162
|
-
value:
|
|
163
|
-
description:
|
|
164
|
-
disabled:
|
|
161
|
+
id: e.id,
|
|
162
|
+
type: e.type,
|
|
163
|
+
title: e.title,
|
|
164
|
+
value: e.value,
|
|
165
|
+
description: e.description,
|
|
166
|
+
disabled: e.disabled
|
|
165
167
|
}
|
|
166
|
-
} :
|
|
167
|
-
sectionId:
|
|
168
|
+
} : e.type === "button" ? {
|
|
169
|
+
sectionId: r,
|
|
168
170
|
item: {
|
|
169
|
-
id:
|
|
170
|
-
type:
|
|
171
|
-
title:
|
|
172
|
-
actionLabel:
|
|
173
|
-
description:
|
|
174
|
-
disabled:
|
|
171
|
+
id: e.id,
|
|
172
|
+
type: e.type,
|
|
173
|
+
title: e.title,
|
|
174
|
+
actionLabel: e.actionLabel,
|
|
175
|
+
description: e.description,
|
|
176
|
+
disabled: e.disabled
|
|
175
177
|
}
|
|
176
|
-
} :
|
|
177
|
-
sectionId:
|
|
178
|
+
} : e.type === "select" ? {
|
|
179
|
+
sectionId: r,
|
|
178
180
|
item: {
|
|
179
|
-
id:
|
|
180
|
-
type:
|
|
181
|
-
title:
|
|
182
|
-
value:
|
|
183
|
-
options:
|
|
184
|
-
description:
|
|
185
|
-
disabled:
|
|
181
|
+
id: e.id,
|
|
182
|
+
type: e.type,
|
|
183
|
+
title: e.title,
|
|
184
|
+
value: e.value,
|
|
185
|
+
options: e.options,
|
|
186
|
+
description: e.description,
|
|
187
|
+
disabled: e.disabled
|
|
186
188
|
}
|
|
187
189
|
} : {
|
|
188
|
-
sectionId:
|
|
190
|
+
sectionId: r,
|
|
189
191
|
item: {
|
|
190
|
-
id:
|
|
191
|
-
type:
|
|
192
|
-
title:
|
|
193
|
-
value:
|
|
194
|
-
placeholder:
|
|
195
|
-
applyLabel:
|
|
196
|
-
description:
|
|
197
|
-
disabled:
|
|
192
|
+
id: e.id,
|
|
193
|
+
type: e.type,
|
|
194
|
+
title: e.title,
|
|
195
|
+
value: e.value,
|
|
196
|
+
placeholder: e.placeholder,
|
|
197
|
+
applyLabel: e.applyLabel,
|
|
198
|
+
description: e.description,
|
|
199
|
+
disabled: e.disabled
|
|
198
200
|
}
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
|
-
}),
|
|
202
|
-
pluginId:
|
|
203
|
-
tool:
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
}), v({
|
|
204
|
+
pluginId: $,
|
|
205
|
+
tool: E.setValue,
|
|
206
|
+
enabled: n,
|
|
207
|
+
handler: async ({ sectionId: r, itemId: s, value: e }) => {
|
|
208
|
+
const { item: i } = R(t(), r, s);
|
|
206
209
|
if (i.type === "text")
|
|
207
210
|
throw new Error(
|
|
208
|
-
`Item "${
|
|
211
|
+
`Item "${s}" is a read-only text item and cannot be updated.`
|
|
209
212
|
);
|
|
210
213
|
if (i.type === "button")
|
|
211
214
|
throw new Error(
|
|
212
|
-
`Item "${
|
|
215
|
+
`Item "${s}" is a button. Use press-button to trigger its action.`
|
|
213
216
|
);
|
|
214
217
|
if (i.disabled)
|
|
215
|
-
throw new Error(`Item "${
|
|
218
|
+
throw new Error(`Item "${s}" is disabled.`);
|
|
216
219
|
if (i.type === "toggle") {
|
|
217
|
-
if (typeof
|
|
220
|
+
if (typeof e != "boolean")
|
|
218
221
|
throw new Error(
|
|
219
|
-
`Expected boolean value for toggle item "${
|
|
222
|
+
`Expected boolean value for toggle item "${s}".`
|
|
220
223
|
);
|
|
221
224
|
if (i.validate) {
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
224
|
-
throw new Error(
|
|
225
|
+
const o = i.validate(e);
|
|
226
|
+
if (!o.valid)
|
|
227
|
+
throw new Error(o.message);
|
|
225
228
|
}
|
|
226
|
-
return await i.onUpdate(
|
|
229
|
+
return await i.onUpdate(e), { applied: !0, sectionId: r, itemId: s };
|
|
227
230
|
}
|
|
228
|
-
if (typeof
|
|
231
|
+
if (typeof e != "string")
|
|
229
232
|
throw new Error(
|
|
230
|
-
`Expected string value for ${i.type} item "${
|
|
233
|
+
`Expected string value for ${i.type} item "${s}".`
|
|
231
234
|
);
|
|
232
235
|
if (i.type === "select") {
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
236
|
+
const o = i.options.map((p) => p.value);
|
|
237
|
+
if (!o.includes(e))
|
|
235
238
|
throw new Error(
|
|
236
|
-
`Invalid option "${
|
|
239
|
+
`Invalid option "${e}" for item "${s}". Valid options: ${o.join(", ")}`
|
|
237
240
|
);
|
|
238
241
|
}
|
|
239
242
|
if (i.validate) {
|
|
240
|
-
const
|
|
241
|
-
if (!
|
|
242
|
-
throw new Error(
|
|
243
|
+
const o = i.validate(e);
|
|
244
|
+
if (!o.valid)
|
|
245
|
+
throw new Error(o.message);
|
|
243
246
|
}
|
|
244
|
-
return await i.onUpdate(
|
|
247
|
+
return await i.onUpdate(e), { applied: !0, sectionId: r, itemId: s };
|
|
245
248
|
}
|
|
246
|
-
}),
|
|
247
|
-
pluginId:
|
|
248
|
-
tool:
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
}), v({
|
|
250
|
+
pluginId: $,
|
|
251
|
+
tool: E.pressButton,
|
|
252
|
+
enabled: n,
|
|
253
|
+
handler: async ({ sectionId: r, itemId: s }) => {
|
|
254
|
+
const { item: e } = R(t(), r, s);
|
|
255
|
+
if (e.type !== "button")
|
|
252
256
|
throw new Error(
|
|
253
|
-
`Item "${
|
|
257
|
+
`Item "${s}" is not a button (type: ${e.type}). Use set-value to update its value.`
|
|
254
258
|
);
|
|
255
|
-
if (
|
|
256
|
-
throw new Error(`Button "${
|
|
257
|
-
return await
|
|
259
|
+
if (e.disabled)
|
|
260
|
+
throw new Error(`Button "${s}" is disabled.`);
|
|
261
|
+
return await e.onPress(), { pressed: !0, sectionId: r, itemId: s };
|
|
258
262
|
}
|
|
259
263
|
});
|
|
260
|
-
},
|
|
261
|
-
sections:
|
|
262
|
-
}) => {
|
|
263
|
-
|
|
264
|
+
}, T = {
|
|
265
|
+
sections: []
|
|
266
|
+
}, k = (t, n) => typeof n == "function" ? n(t) : {
|
|
267
|
+
...t,
|
|
268
|
+
...n,
|
|
269
|
+
sections: [...t.sections, ...n.sections]
|
|
270
|
+
}, j = () => {
|
|
271
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
272
|
+
let r = 0;
|
|
273
|
+
const s = () => t.keys().next().value, e = () => {
|
|
274
|
+
r += 1, n.forEach((o) => o());
|
|
275
|
+
}, i = (o) => {
|
|
276
|
+
const p = Array.from(t.entries());
|
|
277
|
+
return o ? p.findIndex(([a]) => a === o.id) === -1 ? [...p, [o.id, o.input]] : p.map(
|
|
278
|
+
([a, l]) => a === o.id ? [a, o.input] : [a, l]
|
|
279
|
+
) : p;
|
|
280
|
+
};
|
|
281
|
+
return {
|
|
282
|
+
set(o, p) {
|
|
283
|
+
const g = s();
|
|
284
|
+
t.set(o, p), g !== s() && e();
|
|
285
|
+
},
|
|
286
|
+
delete(o) {
|
|
287
|
+
t.delete(o), e();
|
|
288
|
+
},
|
|
289
|
+
getOptions(o) {
|
|
290
|
+
return i(o).map(([, p]) => p).reduce(k, T);
|
|
291
|
+
},
|
|
292
|
+
isOwner(o, p) {
|
|
293
|
+
return i(p)[0]?.[0] === o;
|
|
294
|
+
},
|
|
295
|
+
getSnapshot() {
|
|
296
|
+
return r;
|
|
297
|
+
},
|
|
298
|
+
subscribe(o) {
|
|
299
|
+
return n.add(o), () => {
|
|
300
|
+
n.delete(o);
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}, u = j(), _ = (t) => {
|
|
305
|
+
const n = x({
|
|
264
306
|
pluginId: "@rozenite/controls-plugin"
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
307
|
+
}), s = z(/* @__PURE__ */ Symbol("rozenite-controls")).current, e = A(
|
|
308
|
+
u.subscribe,
|
|
309
|
+
u.getSnapshot,
|
|
310
|
+
u.getSnapshot
|
|
311
|
+
);
|
|
312
|
+
h(() => () => {
|
|
313
|
+
u.delete(s);
|
|
314
|
+
}, [s]), h(() => {
|
|
315
|
+
u.set(s, t);
|
|
316
|
+
}, [t, s]);
|
|
317
|
+
const i = C(
|
|
318
|
+
() => u.isOwner(s, {
|
|
319
|
+
id: s,
|
|
320
|
+
input: t
|
|
321
|
+
}),
|
|
322
|
+
[t, e, s]
|
|
323
|
+
);
|
|
324
|
+
return L(
|
|
325
|
+
() => u.getOptions().sections,
|
|
326
|
+
i
|
|
327
|
+
), h(() => {
|
|
328
|
+
n && n.send("snapshot", {
|
|
272
329
|
type: "snapshot",
|
|
273
|
-
sections:
|
|
330
|
+
sections: m(u.getOptions().sections)
|
|
274
331
|
});
|
|
275
|
-
}, [
|
|
276
|
-
if (!
|
|
332
|
+
}, [n, t, e]), h(() => {
|
|
333
|
+
if (!n || !i)
|
|
277
334
|
return;
|
|
278
|
-
const
|
|
279
|
-
requestId:
|
|
280
|
-
sectionId:
|
|
281
|
-
itemId:
|
|
282
|
-
value:
|
|
335
|
+
const o = async ({
|
|
336
|
+
requestId: a,
|
|
337
|
+
sectionId: l,
|
|
338
|
+
itemId: d,
|
|
339
|
+
value: y
|
|
283
340
|
}) => {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
341
|
+
const f = P(l, d), c = O(
|
|
342
|
+
u.getOptions().sections
|
|
343
|
+
).get(f);
|
|
344
|
+
if (!c || c.type === "button") {
|
|
345
|
+
n.send("update-result", {
|
|
287
346
|
type: "update-result",
|
|
288
|
-
requestId:
|
|
289
|
-
sectionId:
|
|
290
|
-
itemId:
|
|
347
|
+
requestId: a,
|
|
348
|
+
sectionId: l,
|
|
349
|
+
itemId: d,
|
|
291
350
|
status: "error",
|
|
292
351
|
message: "Update target not found."
|
|
293
352
|
});
|
|
294
353
|
return;
|
|
295
354
|
}
|
|
296
355
|
try {
|
|
297
|
-
if (
|
|
298
|
-
if (typeof
|
|
299
|
-
|
|
356
|
+
if (c.type === "toggle") {
|
|
357
|
+
if (typeof y != "boolean") {
|
|
358
|
+
n.send("update-result", {
|
|
300
359
|
type: "update-result",
|
|
301
|
-
requestId:
|
|
302
|
-
sectionId:
|
|
303
|
-
itemId:
|
|
360
|
+
requestId: a,
|
|
361
|
+
sectionId: l,
|
|
362
|
+
itemId: d,
|
|
304
363
|
status: "error",
|
|
305
364
|
message: "Invalid toggle value."
|
|
306
365
|
});
|
|
307
366
|
return;
|
|
308
367
|
}
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
|
|
368
|
+
const S = U(c.validate, y);
|
|
369
|
+
if (!S.valid) {
|
|
370
|
+
n.send("update-result", {
|
|
312
371
|
type: "update-result",
|
|
313
|
-
requestId:
|
|
314
|
-
sectionId:
|
|
315
|
-
itemId:
|
|
372
|
+
requestId: a,
|
|
373
|
+
sectionId: l,
|
|
374
|
+
itemId: d,
|
|
316
375
|
status: "error",
|
|
317
|
-
message:
|
|
376
|
+
message: S.message
|
|
318
377
|
});
|
|
319
378
|
return;
|
|
320
379
|
}
|
|
321
|
-
await
|
|
380
|
+
await c.onUpdate(y), n.send("update-result", {
|
|
322
381
|
type: "update-result",
|
|
323
|
-
requestId:
|
|
324
|
-
sectionId:
|
|
325
|
-
itemId:
|
|
382
|
+
requestId: a,
|
|
383
|
+
sectionId: l,
|
|
384
|
+
itemId: d,
|
|
326
385
|
status: "ok"
|
|
327
386
|
});
|
|
328
387
|
return;
|
|
329
388
|
}
|
|
330
|
-
if (typeof
|
|
331
|
-
|
|
389
|
+
if (typeof y != "string") {
|
|
390
|
+
n.send("update-result", {
|
|
332
391
|
type: "update-result",
|
|
333
|
-
requestId:
|
|
334
|
-
sectionId:
|
|
335
|
-
itemId:
|
|
392
|
+
requestId: a,
|
|
393
|
+
sectionId: l,
|
|
394
|
+
itemId: d,
|
|
336
395
|
status: "error",
|
|
337
|
-
message: `Invalid ${
|
|
396
|
+
message: `Invalid ${c.type} value.`
|
|
338
397
|
});
|
|
339
398
|
return;
|
|
340
399
|
}
|
|
341
|
-
const
|
|
342
|
-
if (!
|
|
343
|
-
|
|
400
|
+
const b = U(c.validate, y);
|
|
401
|
+
if (!b.valid) {
|
|
402
|
+
n.send("update-result", {
|
|
344
403
|
type: "update-result",
|
|
345
|
-
requestId:
|
|
346
|
-
sectionId:
|
|
347
|
-
itemId:
|
|
404
|
+
requestId: a,
|
|
405
|
+
sectionId: l,
|
|
406
|
+
itemId: d,
|
|
348
407
|
status: "error",
|
|
349
|
-
message:
|
|
408
|
+
message: b.message
|
|
350
409
|
});
|
|
351
410
|
return;
|
|
352
411
|
}
|
|
353
|
-
await
|
|
412
|
+
await c.onUpdate(y), n.send("update-result", {
|
|
354
413
|
type: "update-result",
|
|
355
|
-
requestId:
|
|
356
|
-
sectionId:
|
|
357
|
-
itemId:
|
|
414
|
+
requestId: a,
|
|
415
|
+
sectionId: l,
|
|
416
|
+
itemId: d,
|
|
358
417
|
status: "ok"
|
|
359
418
|
});
|
|
360
|
-
} catch (
|
|
419
|
+
} catch (b) {
|
|
361
420
|
console.warn(
|
|
362
|
-
`[Rozenite] Controls Plugin: Update failed for ${
|
|
363
|
-
|
|
364
|
-
),
|
|
421
|
+
`[Rozenite] Controls Plugin: Update failed for ${l}/${d}.`,
|
|
422
|
+
b
|
|
423
|
+
), n.send("update-result", {
|
|
365
424
|
type: "update-result",
|
|
366
|
-
requestId:
|
|
367
|
-
sectionId:
|
|
368
|
-
itemId:
|
|
425
|
+
requestId: a,
|
|
426
|
+
sectionId: l,
|
|
427
|
+
itemId: d,
|
|
369
428
|
status: "error",
|
|
370
429
|
message: "Update failed on the device."
|
|
371
430
|
});
|
|
372
431
|
}
|
|
373
|
-
},
|
|
374
|
-
sectionId:
|
|
375
|
-
itemId:
|
|
376
|
-
action:
|
|
432
|
+
}, p = async ({
|
|
433
|
+
sectionId: a,
|
|
434
|
+
itemId: l,
|
|
435
|
+
action: d
|
|
377
436
|
}) => {
|
|
378
|
-
if (
|
|
437
|
+
if (d !== "press") {
|
|
379
438
|
console.warn(
|
|
380
|
-
`[Rozenite] Controls Plugin: Unsupported action "${
|
|
439
|
+
`[Rozenite] Controls Plugin: Unsupported action "${d}" for ${a}/${l}.`
|
|
381
440
|
);
|
|
382
441
|
return;
|
|
383
442
|
}
|
|
384
|
-
const
|
|
385
|
-
|
|
443
|
+
const y = P(a, l), f = O(
|
|
444
|
+
u.getOptions().sections
|
|
445
|
+
).get(y);
|
|
446
|
+
if (!f) {
|
|
386
447
|
console.warn(
|
|
387
|
-
`[Rozenite] Controls Plugin: Action target not found for ${
|
|
448
|
+
`[Rozenite] Controls Plugin: Action target not found for ${a}/${l}.`
|
|
388
449
|
);
|
|
389
450
|
return;
|
|
390
451
|
}
|
|
391
452
|
try {
|
|
392
|
-
if (
|
|
453
|
+
if (f.type !== "button") {
|
|
393
454
|
console.warn(
|
|
394
|
-
`[Rozenite] Controls Plugin: Invalid press action payload for ${
|
|
455
|
+
`[Rozenite] Controls Plugin: Invalid press action payload for ${a}/${l}.`
|
|
395
456
|
);
|
|
396
457
|
return;
|
|
397
458
|
}
|
|
398
|
-
await
|
|
399
|
-
} catch (
|
|
459
|
+
await f.onPress();
|
|
460
|
+
} catch (c) {
|
|
400
461
|
console.warn(
|
|
401
|
-
`[Rozenite] Controls Plugin: Action failed for ${
|
|
402
|
-
|
|
462
|
+
`[Rozenite] Controls Plugin: Action failed for ${a}/${l}.`,
|
|
463
|
+
c
|
|
403
464
|
);
|
|
404
465
|
}
|
|
405
|
-
},
|
|
406
|
-
|
|
407
|
-
|
|
466
|
+
}, g = [
|
|
467
|
+
n.onMessage("get-snapshot", () => {
|
|
468
|
+
n.send("snapshot", {
|
|
408
469
|
type: "snapshot",
|
|
409
|
-
sections:
|
|
470
|
+
sections: m(u.getOptions().sections)
|
|
410
471
|
});
|
|
411
472
|
}),
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
473
|
+
n.onMessage(
|
|
474
|
+
"update-request",
|
|
475
|
+
(a) => {
|
|
476
|
+
o(a);
|
|
477
|
+
}
|
|
478
|
+
),
|
|
479
|
+
n.onMessage("invoke-action", (a) => {
|
|
480
|
+
p(a);
|
|
417
481
|
})
|
|
418
482
|
];
|
|
419
483
|
return () => {
|
|
420
|
-
|
|
484
|
+
g.forEach((a) => a.remove());
|
|
421
485
|
};
|
|
422
|
-
}, [
|
|
486
|
+
}, [n, i]), n;
|
|
423
487
|
};
|
|
424
488
|
export {
|
|
425
|
-
|
|
489
|
+
_ as useRozeniteControlsPlugin
|
|
426
490
|
};
|