@joryio/web-sdk 1.4.0-beta.7 → 1.4.0-beta.8

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.
@@ -35,6 +35,8 @@ export interface LiquidField {
35
35
  insert(tag: string): void;
36
36
  /** Close a pill's fallback popover; true when one was open. */
37
37
  closePop(): boolean;
38
+ /** Open the fallback popover of the (first) pill of this variable path; false when there is none. */
39
+ openPill(path: string): boolean;
38
40
  }
39
41
 
40
42
  /** The words of a pill's fallback popover: `title` has `{name}`, the field's label. */
@@ -154,7 +156,7 @@ export function liquidField(opts: {
154
156
  const input = h('input', { dir: 'auto', 'data-j': 'fallback', 'aria-label': title, maxlength: '200' });
155
157
  input.value = varFallback(v.src) || '';
156
158
  const err = h('div', { class: 'err', 'data-j': 'fallback-error', role: 'alert' });
157
- const done = h('button', { class: 'vc', type: 'button', 'data-j': 'fallback-done' }, words.done);
159
+ const done = h('button', { class: 'vc ui', type: 'button', 'data-j': 'fallback-done' }, words.done);
158
160
  const p = h('div', { class: 'pk fbp', role: 'dialog', 'aria-label': title, 'data-j': 'fallback-pop' }, h('label', { class: 'lbl' }, title), input, err, h('div', { class: 'help2' }, words.help), done);
159
161
  const finish = () => {
160
162
  closePop();
@@ -183,6 +185,11 @@ export function liquidField(opts: {
183
185
  }
184
186
  });
185
187
  done.addEventListener('click', finish);
188
+ // Focus leaving the popover (Tab away, a click elsewhere) closes it.
189
+ p.addEventListener('focusout', (e) => {
190
+ const to = e.relatedTarget as Node | null;
191
+ if (pop === p && (!to || !p.contains(to))) closePop();
192
+ });
186
193
  pop = p;
187
194
  el.appendChild(p);
188
195
  input.focus();
@@ -297,5 +304,13 @@ export function liquidField(opts: {
297
304
  emit();
298
305
  };
299
306
 
300
- return { el, set, insert, closePop };
307
+ const openPill = (path: string): boolean => {
308
+ if (!box || box.tagName !== 'DIV') return false;
309
+ const target = Array.from(box.querySelectorAll(`[${PILL_ATTR}]`)).filter((n) => n.getAttribute('data-path') === path)[0] as HTMLElement | undefined;
310
+ if (!target) return false;
311
+ openPop(target);
312
+ return true;
313
+ };
314
+
315
+ return { el, set, insert, closePop, openPill };
301
316
  }