@intent-framework/dom 0.1.0-alpha.4 → 0.1.0-alpha.6
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/index.js +48 -17
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -100,6 +100,8 @@ function renderDom(screenDef, options) {
|
|
|
100
100
|
if (!reasonEl) {
|
|
101
101
|
reasonEl = document.createElement("p");
|
|
102
102
|
reasonEl.id = reasonId;
|
|
103
|
+
reasonEl.className = "intent-blocked-reason";
|
|
104
|
+
reasonEl.setAttribute("role", "alert");
|
|
103
105
|
form.appendChild(reasonEl);
|
|
104
106
|
}
|
|
105
107
|
reasonEl.textContent = act.blockedReasons[0];
|
|
@@ -157,6 +159,8 @@ function renderDom(screenDef, options) {
|
|
|
157
159
|
if (event.key !== "Enter") return;
|
|
158
160
|
if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) return;
|
|
159
161
|
if (input.tagName === "TEXTAREA") return;
|
|
162
|
+
if (input.tagName === "SELECT") return;
|
|
163
|
+
if (input.type === "checkbox") return;
|
|
160
164
|
const defaultAction = findDefaultAction(screenDef.acts);
|
|
161
165
|
if (!defaultAction || !defaultAction.enabled.current) return;
|
|
162
166
|
event.preventDefault();
|
|
@@ -203,20 +207,42 @@ function buildDom(screenDef, showScreenName, showSemanticIds) {
|
|
|
203
207
|
if (sid) label.setAttribute("data-intent-ask", sid);
|
|
204
208
|
}
|
|
205
209
|
container.appendChild(label);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
const control = createInputForAsk(ask);
|
|
211
|
+
control.id = ask.id;
|
|
212
|
+
control.name = ask.id;
|
|
209
213
|
if (showSemanticIds && askSemanticIds) {
|
|
210
214
|
const sid = askSemanticIds.get(ask.id);
|
|
211
|
-
if (sid)
|
|
215
|
+
if (sid) control.setAttribute("data-intent-ask", sid);
|
|
212
216
|
}
|
|
213
|
-
if (ask.required)
|
|
214
|
-
if (ask.kind === "contact" && ask.contactKind)
|
|
215
|
-
|
|
217
|
+
if (ask.required) control.required = true;
|
|
218
|
+
if (ask.kind === "contact" && ask.contactKind) control.setAttribute("autocomplete", ask.contactKind);
|
|
219
|
+
if (typeof ask.state.value === "boolean") {
|
|
216
220
|
const stateObj = ask.state;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
control.checked = stateObj.value;
|
|
222
|
+
control.addEventListener("change", () => {
|
|
223
|
+
stateObj.set(control.checked);
|
|
224
|
+
});
|
|
225
|
+
} else if (ask.kind === "choice") {
|
|
226
|
+
const stateObj = ask.state;
|
|
227
|
+
const select = control;
|
|
228
|
+
for (const opt of stateObj.options) {
|
|
229
|
+
const option = document.createElement("option");
|
|
230
|
+
option.value = opt;
|
|
231
|
+
option.textContent = opt;
|
|
232
|
+
select.appendChild(option);
|
|
233
|
+
}
|
|
234
|
+
select.value = stateObj.value;
|
|
235
|
+
select.addEventListener("change", () => {
|
|
236
|
+
stateObj.set(select.value);
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
const textInput = control;
|
|
240
|
+
textInput.addEventListener("input", () => {
|
|
241
|
+
const stateObj = ask.state;
|
|
242
|
+
if (typeof stateObj.set === "function") stateObj.set(textInput.value);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
container.appendChild(control);
|
|
220
246
|
if (ask.hintText) {
|
|
221
247
|
const hint = document.createElement("p");
|
|
222
248
|
hint.id = `${ask.id}-hint`;
|
|
@@ -232,9 +258,9 @@ function buildDom(screenDef, showScreenName, showSemanticIds) {
|
|
|
232
258
|
if (!defaultAction.enabled.current) hint.style.display = "none";
|
|
233
259
|
container.appendChild(hint);
|
|
234
260
|
if (defaultAction.enabled.current) {
|
|
235
|
-
const existing =
|
|
236
|
-
if (existing)
|
|
237
|
-
else
|
|
261
|
+
const existing = control.getAttribute("aria-describedby");
|
|
262
|
+
if (existing) control.setAttribute("aria-describedby", `${existing} ${hintId}`);
|
|
263
|
+
else control.setAttribute("aria-describedby", hintId);
|
|
238
264
|
}
|
|
239
265
|
}
|
|
240
266
|
form.appendChild(container);
|
|
@@ -256,6 +282,8 @@ function buildDom(screenDef, showScreenName, showSemanticIds) {
|
|
|
256
282
|
button.setAttribute("aria-describedby", reasonId);
|
|
257
283
|
const reasonEl = document.createElement("p");
|
|
258
284
|
reasonEl.id = reasonId;
|
|
285
|
+
reasonEl.className = "intent-blocked-reason";
|
|
286
|
+
reasonEl.setAttribute("role", "alert");
|
|
259
287
|
reasonEl.textContent = act.blockedReasons[0];
|
|
260
288
|
form.appendChild(reasonEl);
|
|
261
289
|
}
|
|
@@ -275,13 +303,16 @@ function updateFeedback(act, output) {
|
|
|
275
303
|
else output.textContent = "";
|
|
276
304
|
}
|
|
277
305
|
function createInputForAsk(ask) {
|
|
306
|
+
if (typeof ask.state.value === "boolean") {
|
|
307
|
+
const input$1 = document.createElement("input");
|
|
308
|
+
input$1.type = "checkbox";
|
|
309
|
+
return input$1;
|
|
310
|
+
}
|
|
311
|
+
if (ask.kind === "choice") return document.createElement("select");
|
|
278
312
|
const input = document.createElement("input");
|
|
279
313
|
if (ask.kind === "contact" && ask.contactKind === "email") input.type = "email";
|
|
280
314
|
else if (ask.kind === "secret") input.type = "password";
|
|
281
|
-
else
|
|
282
|
-
input.type = "text";
|
|
283
|
-
input.setAttribute("role", "combobox");
|
|
284
|
-
} else input.type = "text";
|
|
315
|
+
else input.type = "text";
|
|
285
316
|
return input;
|
|
286
317
|
}
|
|
287
318
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.0-alpha.
|
|
6
|
+
"version": "0.1.0-alpha.6",
|
|
7
7
|
"description": "DOM materializer for Intent screens and router",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@intent-framework/core": "^0.1.0-alpha.
|
|
30
|
-
"@intent-framework/router": "^0.1.0-alpha.
|
|
29
|
+
"@intent-framework/core": "^0.1.0-alpha.6",
|
|
30
|
+
"@intent-framework/router": "^0.1.0-alpha.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"jsdom": "^29.1.1",
|