pinokiod 8.3.14 → 8.3.15
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/package.json
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// Each bar still decides everything it decides today: the modes, the folder
|
|
16
16
|
// names, what is sent. It draws itself again on every change and writes what it
|
|
17
17
|
// shows on .agent-bar (data-item, data-engaged, data-busy). This file watches
|
|
18
|
-
// that and lays the same parts out again. From a bar's own script it uses
|
|
19
|
-
//
|
|
18
|
+
// that and lays the same parts out again. From a bar's own script it uses
|
|
19
|
+
// leave() and tool(), on PinokioAgentBar or PinokioAgentBarApp, and the home
|
|
20
|
+
// bar's hint().
|
|
20
21
|
(function (window, document) {
|
|
21
22
|
'use strict';
|
|
22
23
|
if (window.PinokioAgentCompose) return;
|
|
@@ -47,6 +48,9 @@
|
|
|
47
48
|
download: 'What should we download?',
|
|
48
49
|
};
|
|
49
50
|
const LINK_GREETING = 'Ready when you are';
|
|
51
|
+
// said in the empty text while the cursor is not in it, where the bar's own
|
|
52
|
+
// line would repeat the greeting
|
|
53
|
+
const TYPE_HERE = 'Type here…';
|
|
50
54
|
// the starter text agent-bar.js gives Create plugin (PLUGIN_PROMPT_SEED there)
|
|
51
55
|
const PLUGIN_SEED = 'A Pinokio plugin for: ';
|
|
52
56
|
// The face: the filled mark the mode chip has at rest, and the same character
|
|
@@ -314,12 +318,27 @@
|
|
|
314
318
|
// to paste, so Download keeps its own placeholder.
|
|
315
319
|
// On an app's page the greeting is the bar's own line, which names the app.
|
|
316
320
|
const greetingNow = () => (isApp ? restPlaceholder.replace(/…$/, '') : (GREETINGS[item()] || ''));
|
|
321
|
+
// Under the large face the blinking cursor is all that marks the empty text
|
|
322
|
+
// as a place to type. Where there is none, the text says so itself, in the
|
|
323
|
+
// bar's own line at rest. A phone only shows the cursor with its keyboard:
|
|
324
|
+
// the view can be open with the keyboard down (a link that was followed
|
|
325
|
+
// without a tap, or the keyboard put away).
|
|
326
|
+
function keyboardUp() {
|
|
327
|
+
const vv = window.visualViewport;
|
|
328
|
+
return !vv || window.innerHeight - vv.height > 120;
|
|
329
|
+
}
|
|
330
|
+
const cursorShown = () => document.activeElement === input && (!isTouch() || keyboardUp());
|
|
331
|
+
function hintNow() {
|
|
332
|
+
if (cursorShown()) return '';
|
|
333
|
+
const rest = isApp ? restPlaceholder : (typeof host.hint === 'function' ? host.hint() : '');
|
|
334
|
+
return rest.replace(/…$/, '') === greet.textContent ? TYPE_HERE : rest;
|
|
335
|
+
}
|
|
317
336
|
function words() {
|
|
318
337
|
const large = shape === 'centre' || (shape === 'screen' && roomy);
|
|
319
338
|
const greeting = greetingNow();
|
|
320
339
|
greet.textContent = shape === 'centre' ? LINK_GREETING : greeting;
|
|
321
|
-
if (isApp) input.placeholder = shape && large ?
|
|
322
|
-
else if (shape && !isDownload()) input.placeholder = large ?
|
|
340
|
+
if (isApp) input.placeholder = shape && large ? hintNow() : restPlaceholder;
|
|
341
|
+
else if (shape && !isDownload()) input.placeholder = large ? hintNow() : greeting;
|
|
323
342
|
// what the on-screen keyboard prints on its Return key
|
|
324
343
|
input.enterKeyHint = isDownload() ? 'go' : (isTouch() ? 'enter' : 'send');
|
|
325
344
|
nameInputs.forEach((nameInput) => { nameInput.enterKeyHint = 'go'; });
|
|
@@ -579,6 +598,27 @@
|
|
|
579
598
|
if (shape && event.target.closest && event.target.closest(KEEPS_CURSOR)) event.preventDefault();
|
|
580
599
|
});
|
|
581
600
|
|
|
601
|
+
// A press on the box itself, anywhere that is not a button, a list or a
|
|
602
|
+
// field of its own, is a press on the text: the cursor stays in it, or goes
|
|
603
|
+
// to it. (A phone that refused the cursor its keyboard gives it on a tap,
|
|
604
|
+
// and only to a field that takes the cursor anew.)
|
|
605
|
+
const OWN_PRESS = 'button, a, input, textarea, select, label, .agent-bar__menu, .agent-bar__files';
|
|
606
|
+
const onBox = (event) => Boolean(shape) && Boolean(event.target.closest)
|
|
607
|
+
&& field.contains(event.target) && !event.target.closest(OWN_PRESS);
|
|
608
|
+
inner.addEventListener('pointerdown', (event) => {
|
|
609
|
+
if (onBox(event)) event.preventDefault();
|
|
610
|
+
});
|
|
611
|
+
inner.addEventListener('click', (event) => {
|
|
612
|
+
if (!onBox(event) || input.disabled) return;
|
|
613
|
+
if (document.activeElement === input && !cursorShown()) input.blur();
|
|
614
|
+
input.focus();
|
|
615
|
+
});
|
|
616
|
+
// (after the bar has drawn itself: leaving the bar takes the cursor out too,
|
|
617
|
+
// and the bar at rest has its own line)
|
|
618
|
+
const cursorMoved = () => window.setTimeout(() => { if (shape) words(); }, 0);
|
|
619
|
+
input.addEventListener('focus', cursorMoved);
|
|
620
|
+
input.addEventListener('blur', cursorMoved);
|
|
621
|
+
|
|
582
622
|
input.addEventListener('input', listen);
|
|
583
623
|
nameInputs.forEach((nameInput) => nameInput.addEventListener('input', listen));
|
|
584
624
|
|
|
@@ -981,9 +981,11 @@
|
|
|
981
981
|
state.menu = null;
|
|
982
982
|
render();
|
|
983
983
|
};
|
|
984
|
-
// for the compose view (agent-bar-compose.js): leave the bar; the chosen agent
|
|
984
|
+
// for the compose view (agent-bar-compose.js): leave the bar; the chosen agent;
|
|
985
|
+
// what the empty text says at rest
|
|
985
986
|
api.leave = leave;
|
|
986
987
|
api.tool = selectedTool;
|
|
988
|
+
api.hint = () => ITEMS[state.item].placeholder;
|
|
987
989
|
|
|
988
990
|
function toggleMenu(which) {
|
|
989
991
|
if (state.busy) return;
|
|
@@ -240,6 +240,63 @@ test('on a phone it is the full screen, with a close button and the back gesture
|
|
|
240
240
|
assert.equal(p.shape(), '')
|
|
241
241
|
})
|
|
242
242
|
|
|
243
|
+
test('with the large face and no cursor in the text, the empty text says where to type', async (t) => {
|
|
244
|
+
const p = await page(t, { search: '?universal&type=ask' })
|
|
245
|
+
assert.equal(p.window.PinokioAgentBar.open({ type: 'ask' }), true)
|
|
246
|
+
await settle(p.window)
|
|
247
|
+
assert.equal(p.shape(), 'centre')
|
|
248
|
+
assert.equal(p.input.placeholder, '', 'the cursor is there')
|
|
249
|
+
p.input.blur()
|
|
250
|
+
await settle(p.window)
|
|
251
|
+
assert.equal(p.shape(), 'centre')
|
|
252
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
|
|
253
|
+
await p.focus()
|
|
254
|
+
assert.equal(p.input.placeholder, '')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('on a phone the cursor counts only with the keyboard up', async (t) => {
|
|
258
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
259
|
+
// the keyboard takes part of the screen, or none of it
|
|
260
|
+
const vv = { height: 400, offsetTop: 0, addEventListener() {} }
|
|
261
|
+
p.window.visualViewport = vv
|
|
262
|
+
p.window.innerHeight = 800
|
|
263
|
+
await p.focus()
|
|
264
|
+
assert.equal(p.shape(), 'screen')
|
|
265
|
+
assert.equal(p.input.placeholder, '')
|
|
266
|
+
// put away: the cursor is still in the text as far as the page knows
|
|
267
|
+
vv.height = 800
|
|
268
|
+
p.window.dispatchEvent(new p.window.Event('resize'))
|
|
269
|
+
await settle(p.window)
|
|
270
|
+
assert.equal(p.document.activeElement, p.input)
|
|
271
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
|
|
272
|
+
// a mode whose line at rest is its greeting does not say it twice
|
|
273
|
+
await p.mode(1)
|
|
274
|
+
assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'What should this app do?')
|
|
275
|
+
assert.equal(p.input.placeholder, 'Type here…')
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('a press on the box, off its buttons, puts the cursor in the text', async (t) => {
|
|
279
|
+
const p = await page(t, { search: '?universal&type=ask' })
|
|
280
|
+
p.window.PinokioAgentBar.open({ type: 'ask' })
|
|
281
|
+
await settle(p.window)
|
|
282
|
+
p.input.blur()
|
|
283
|
+
await settle(p.window)
|
|
284
|
+
assert.notEqual(p.document.activeElement, p.input)
|
|
285
|
+
const greet = p.root.querySelector('.agent-compose__greet')
|
|
286
|
+
const down = new p.window.Event('pointerdown', { bubbles: true, cancelable: true })
|
|
287
|
+
greet.dispatchEvent(down)
|
|
288
|
+
assert.equal(down.defaultPrevented, true, 'the press does not take the cursor away')
|
|
289
|
+
greet.click()
|
|
290
|
+
await settle(p.window)
|
|
291
|
+
assert.equal(p.document.activeElement, p.input)
|
|
292
|
+
assert.equal(p.shape(), 'centre')
|
|
293
|
+
// a button of the box keeps its own press
|
|
294
|
+
p.input.blur()
|
|
295
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
296
|
+
await settle(p.window)
|
|
297
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
|
|
298
|
+
})
|
|
299
|
+
|
|
243
300
|
test('on a phone the bar at rest is one button: the mark opens the view, not the mode menu', async (t) => {
|
|
244
301
|
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
245
302
|
p.root.querySelector('.agent-bar__scope').click()
|