pinokiod 8.3.32 → 8.3.34

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.32",
3
+ "version": "8.3.34",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  // ("Ask · <app>"), the empty text ("Ask Pinokio about <app>…"),
10
10
  // what the face says in the open view, and a chip with the
11
11
  // app's icon and name at the left of the open view's bottom row.
12
+ // click again -> close the view, keeping the app and the draft.
12
13
  // the chip's x, or another mode -> an ordinary Ask again.
13
14
  // send -> the same request the app's own page sends for "Ask Pinokio
14
15
  // about <app>" (POST /brain/ask with `app`), so the agent starts
@@ -35,12 +36,19 @@
35
36
  let chipIcon = null;
36
37
  let chipName = null;
37
38
  let chipX = null;
39
+ let activeButton = null;
38
40
  // { id, name, folder, icon }: the app's folder name, what it is called, the
39
41
  // folder's full path and its icon's address
40
42
  let app = null;
41
43
 
42
44
  const isBusy = () => Boolean(root) && root.dataset.busy === 'true';
43
45
  const onAsk = () => Boolean(root) && root.dataset.item === 'ask';
46
+ const isEngaged = () => root.dataset.engaged === 'true';
47
+
48
+ function setExpanded(button, expanded) {
49
+ button.classList.toggle('is-open', expanded);
50
+ button.setAttribute('aria-expanded', String(expanded));
51
+ }
44
52
 
45
53
  // The chip sits in the open view's bottom row (made by agent-bar-compose.js,
46
54
  // possibly after this file runs), at the left, after the mode chip.
@@ -80,6 +88,10 @@
80
88
  if (!root) return;
81
89
  // another mode: an Ask pointed at an app is no longer what the bar shows
82
90
  if (app && !onAsk()) app = null;
91
+ if (activeButton) {
92
+ setExpanded(activeButton, Boolean(app) && isEngaged());
93
+ if (!app) activeButton = null;
94
+ }
83
95
  if (!placeChip()) return;
84
96
  setHidden(chip, !app);
85
97
  if (!app) return;
@@ -92,13 +104,21 @@
92
104
  chipX.disabled = isBusy();
93
105
  }
94
106
 
95
- // Point the bar at an app: Ask, the cursor in the text.
96
- function point(next) {
97
- if (!root || isBusy() || !next || !next.id || !next.folder) return false;
107
+ function toggle(button) {
108
+ if (!root || isBusy()) return;
109
+ const next = fromButton(button);
110
+ if (!next.id || !next.folder) return;
111
+ if (onAsk() && isEngaged() && app?.folder === next.folder) {
112
+ bar.leave();
113
+ button.focus();
114
+ sync();
115
+ return;
116
+ }
117
+ if (activeButton && activeButton !== button) setExpanded(activeButton, false);
118
+ activeButton = button;
98
119
  app = next;
99
120
  bar.choose('ask');
100
121
  sync();
101
- return true;
102
122
  }
103
123
 
104
124
  // The user took the app off: an ordinary Ask, the cursor still in the text.
@@ -155,7 +175,7 @@
155
175
  // the home bar only; an app's page has its own bar, which is about that app already
156
176
  if (!document.body || document.body.classList.contains('app-page')) return;
157
177
  root = document.querySelector('.agent-bar');
158
- if (!root || typeof bar.choose !== 'function' || typeof bar.refresh !== 'function') {
178
+ if (!root || typeof bar.choose !== 'function' || typeof bar.refresh !== 'function' || typeof bar.leave !== 'function') {
159
179
  root = null;
160
180
  return;
161
181
  }
@@ -170,7 +190,7 @@
170
190
  };
171
191
  new MutationObserver(sync).observe(root, {
172
192
  attributes: true,
173
- attributeFilter: ['data-item', 'data-busy', 'data-compose', 'data-about'],
193
+ attributeFilter: ['data-item', 'data-busy', 'data-compose', 'data-about', 'data-engaged'],
174
194
  });
175
195
  sync();
176
196
  }
@@ -192,7 +212,7 @@
192
212
  if (!button) return;
193
213
  event.preventDefault();
194
214
  event.stopPropagation();
195
- point(fromButton(button));
215
+ toggle(button);
196
216
  }, true);
197
217
  // (and Enter or Space on the button is the button's, not the row's)
198
218
  document.addEventListener('keydown', (event) => {
@@ -285,7 +285,7 @@
285
285
  }
286
286
 
287
287
  // The keyboard and click-away behaviour of a bar. `bar` is the bar's own
288
- // { isBusy, hasMenu, closeMenu, leave, fit }.
288
+ // { isBusy, hasMenu, closeMenu, leave, fit, trigger }.
289
289
  function bindBar(root, inner, bar) {
290
290
  // Keys typed in the bar must not reach page shortcuts.
291
291
  ['keydown', 'keypress', 'keyup'].forEach((type) => {
@@ -308,6 +308,8 @@
308
308
  // menu away. On a phone the box is the whole screen, so there is no outside.
309
309
  document.addEventListener('pointerdown', (event) => {
310
310
  const at = event.target;
311
+ // An external trigger handles opening and closing on its own click.
312
+ if (bar.trigger && at.closest?.(bar.trigger)) return;
311
313
  if (!inner.contains(at)) bar.leave();
312
314
  else if (bar.hasMenu() && !(at.closest && at.closest('.agent-bar__menu, button'))) bar.closeMenu();
313
315
  }, true);
@@ -1380,6 +1382,7 @@
1380
1382
  });
1381
1383
  go.addEventListener('click', submit);
1382
1384
  bindBar(root, inner, {
1385
+ trigger: '.home-ask-button',
1383
1386
  isBusy: () => state.busy,
1384
1387
  hasMenu: () => Boolean(state.menu),
1385
1388
  closeMenu: () => { state.menu = null; render(); },
@@ -9,7 +9,7 @@
9
9
  const askLabel = `Ask Pinokio about ${askName}`;
10
10
  %>
11
11
  <% if (askApp) { %>
12
- <button class='btn home-icon-btn home-ask-button' type='button' data-ask-app="<%= askApp %>" data-ask-folder="<%= askFolder %>" data-ask-name="<%= askName %>" data-ask-icon="<%= askIcon %>" title="<%= askLabel %>" aria-label="<%= askLabel %>">
12
+ <button class='btn home-icon-btn home-ask-button' type='button' data-ask-app="<%= askApp %>" data-ask-folder="<%= askFolder %>" data-ask-name="<%= askName %>" data-ask-icon="<%= askIcon %>" title="<%= askLabel %>" aria-label="<%= askLabel %>" aria-expanded="false">
13
13
  <i class="fa-regular fa-comment" aria-hidden="true"></i>
14
14
  </button>
15
15
  <% } %>
@@ -131,6 +131,42 @@ test('a click on a row\'s button points the bar at that app and does not open th
131
131
  assert.deepEqual(p.posts, [])
132
132
  })
133
133
 
134
+ test('pressing the same row button closes and reopens the bar with its draft', async (t) => {
135
+ const p = await home(t)
136
+ const button = p.askButton('demo')
137
+ const icon = button.querySelector('i')
138
+ const clickIcon = async () => {
139
+ icon.dispatchEvent(new p.window.MouseEvent('pointerdown', { bubbles: true, cancelable: true }))
140
+ button.focus()
141
+ await p.settle()
142
+ await p.click(icon)
143
+ }
144
+
145
+ await clickIcon()
146
+ assert.equal(p.root.dataset.compose, 'place')
147
+
148
+ p.input.value = 'a draft'
149
+ await clickIcon()
150
+ assert.equal(p.root.dataset.compose, undefined)
151
+ assert.equal(button.getAttribute('aria-expanded'), 'false')
152
+ assert.ok(!button.classList.contains('is-open'))
153
+ assert.equal(p.document.activeElement, button)
154
+
155
+ await clickIcon()
156
+ assert.equal(p.root.dataset.compose, 'place')
157
+ assert.equal(button.getAttribute('aria-expanded'), 'true')
158
+ assert.ok(button.classList.contains('is-open'))
159
+ assert.equal(p.root.dataset.about, 'demo')
160
+ assert.equal(p.input.value, 'a draft')
161
+ assert.deepEqual(p.rowClicks, [])
162
+ assert.deepEqual(p.posts, [])
163
+
164
+ p.document.body.dispatchEvent(new p.window.MouseEvent('pointerdown', { bubbles: true }))
165
+ await p.settle()
166
+ assert.equal(p.root.dataset.compose, undefined)
167
+ assert.equal(button.getAttribute('aria-expanded'), 'false')
168
+ })
169
+
134
170
  test('the remembered agent is shown as soon as the page opens, before the bar is used', async (t) => {
135
171
  const p = await home(t)
136
172
  assert.equal(p.bar.tool().value, 'codex')
@@ -169,6 +205,8 @@ test('another row\'s button points the bar at the other app', async (t) => {
169
205
  await p.click(p.askButton('demo'))
170
206
  await p.click(p.askButton('other'))
171
207
  assert.equal(p.root.dataset.about, 'other')
208
+ assert.equal(p.askButton('demo').getAttribute('aria-expanded'), 'false')
209
+ assert.equal(p.askButton('other').getAttribute('aria-expanded'), 'true')
172
210
  assert.equal(p.label(), 'Ask · Other')
173
211
  // no icon: the chip shows the name alone
174
212
  assert.equal(p.chip().querySelector('.agent-bar__about-icon').hidden, true)