@unson/brainbase-mcp 0.50.14 → 0.50.18

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.
@@ -93,8 +93,8 @@ export function workspaceSearchControl(doc, { input, appearance } = {}) {
93
93
  }
94
94
 
95
95
  /** A shared title bar, with an optional search input owned by the caller. */
96
- export function workspaceTopbar(doc, { title = '', query, tabs, tools } = {}) {
97
- const header = el(doc, 'header', { className: 'bb-ws-topbar' });
96
+ export function workspaceTopbar(doc, { title = '', query, tabs, tools, wrap = false } = {}) {
97
+ const header = el(doc, 'header', { className: `bb-ws-topbar${wrap ? ' bb-ws-topbar--wrap' : ''}` });
98
98
  header.append(el(doc, 'h1', { text: title }));
99
99
  let search;
100
100
  let currentQuery;
@@ -143,7 +143,7 @@ function workspaceLightDismiss(doc, dialog, close) {
143
143
  }
144
144
 
145
145
  /** A reusable right inspector whose content can refresh without replacing the modal. */
146
- export function workspaceDetailDrawer(doc, { title = '詳細', opener, onClose } = {}) {
146
+ export function workspaceDetailDrawer(doc, { title = '詳細', opener, onClose, beforeClose } = {}) {
147
147
  const dialog = workspaceApplyDrawer(el(doc, 'dialog', { className: 'bb-ws-dialog bb-ws-detail-drawer' }));
148
148
  const titleId = `bb-ws-inspector-${nextWorkspaceSequence()}`;
149
149
  dialog.setAttribute('aria-labelledby', titleId);
@@ -161,6 +161,7 @@ export function workspaceDetailDrawer(doc, { title = '詳細', opener, onClose }
161
161
  };
162
162
  const close = ({ restoreFocus = true, immediate = false } = {}) => {
163
163
  if (!dialog.open) return;
164
+ if (!immediate && beforeClose?.() === false) return;
164
165
  // Clear the caller's open state before an asynchronous content update arrives.
165
166
  if (cancelClosing && !immediate) return;
166
167
  if (!cancelClosing) onClose?.();
@@ -216,7 +217,7 @@ export function workspaceHostActions(actions) {
216
217
 
217
218
  export function workspaceButton(doc, { text, variant = 'default', onClick, disabled = false, attrs = {} } = {}) {
218
219
  const button = el(doc, 'button', {
219
- className: `bb-ws-button${variant === 'primary' ? ' is-primary' : variant === 'danger' ? ' is-danger' : variant === 'quiet' ? ' is-quiet' : ''}`,
220
+ className: `bb-ws-button${variant === 'primary' ? ' is-primary' : variant === 'danger' ? ' is-danger' : variant === 'quiet' ? ' is-quiet' : variant === 'icon' ? ' is-icon' : ''}`,
220
221
  text,
221
222
  attrs: { type: 'button', disabled, ...attrs },
222
223
  });
@@ -360,12 +361,16 @@ function nextWorkspaceSequence() {
360
361
  const next = ++workspaceSequence;
361
362
  return workspaceIdScope ? `${encodeURIComponent(workspaceIdScope)}-${next}` : next;
362
363
  }
364
+ const workspaceHelpDismissers = new WeakMap();
365
+
363
366
  /** Shared explanatory help: hover/focus above the control, click for touch. */
364
- export function workspaceHelp(doc, { text, label } = {}) {
365
- const wrap = el(doc, 'span', { className: 'bb-ws-help' });
366
- const control = workspaceButton(doc, { text: 'i', attrs: { 'aria-label': `${label}の説明`, 'aria-expanded': 'false' } });
367
+ export function workspaceHelp(doc, { text, label, content, icon = 'i', placement } = {}) {
368
+ const wrap = el(doc, content === undefined ? 'span' : 'div', { className: 'bb-ws-help' });
369
+ const control = workspaceButton(doc, { text: icon, attrs: { 'aria-label': `${label}の説明`, 'aria-expanded': 'false' } });
367
370
  control.className = 'bb-ws-help-button';
368
- const bubble = el(doc, 'span', { className: 'bb-ws-help-bubble', text, attrs: { id: `bb-ws-help-${nextWorkspaceSequence()}`, role: 'tooltip' } });
371
+ const bubble = el(doc, content === undefined ? 'span' : 'div', { className: 'bb-ws-help-bubble', text, attrs: { id: `bb-ws-help-${nextWorkspaceSequence()}`, role: 'tooltip' } });
372
+ if (content !== undefined) { bubble.textContent = ''; appendContent(bubble, doc, content); }
373
+ if (placement === 'bottom-end') toggleWorkspaceClass(wrap, 'bb-ws-help--bottom-end', true);
369
374
  control.setAttribute('aria-describedby', bubble.id || bubble.getAttribute?.('id') || bubble.attributes?.id);
370
375
  control.addEventListener('click', event => {
371
376
  event.stopPropagation(); event.preventDefault();
@@ -373,13 +378,26 @@ export function workspaceHelp(doc, { text, label } = {}) {
373
378
  wrap.classList.remove('is-dismissed');
374
379
  control.setAttribute('aria-expanded', String(opened));
375
380
  });
376
- wrap.addEventListener('mouseleave', () => wrap.classList.remove('is-dismissed'));
377
- control.addEventListener('blur', () => { wrap.classList.remove('is-open', 'is-dismissed'); control.setAttribute('aria-expanded', 'false'); });
378
- control.addEventListener('keydown', event => {
379
- if (event.key !== 'Escape') return;
380
- wrap.classList.remove('is-open'); wrap.classList.add('is-dismissed');
381
- control.setAttribute('aria-expanded', 'false'); event.stopPropagation();
381
+ let hovered = false;
382
+ wrap.addEventListener('mouseenter', () => { hovered = true; });
383
+ wrap.addEventListener('mouseleave', () => {
384
+ hovered = false;
385
+ if (!wrap.contains?.(doc.activeElement)) wrap.classList.remove('is-dismissed');
382
386
  });
387
+ wrap.addEventListener('focusout', event => {
388
+ if (wrap.contains?.(event.relatedTarget)) return;
389
+ wrap.classList.remove('is-open'); control.setAttribute('aria-expanded', 'false');
390
+ if (!hovered) wrap.classList.remove('is-dismissed');
391
+ });
392
+ const dismissExplanation = event => {
393
+ if (event.key !== 'Escape' || event.defaultPrevented || wrap.classList.contains('is-dismissed')) return false;
394
+ if (!wrap.classList.contains('is-open') && !hovered && !wrap.contains?.(doc.activeElement)) return false;
395
+ event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation?.();
396
+ wrap.classList.remove('is-open'); wrap.classList.add('is-dismissed');
397
+ control.setAttribute('aria-expanded', 'false'); return true;
398
+ };
399
+ workspaceHelpDismissers.set(wrap, dismissExplanation);
400
+ control.addEventListener('keydown', dismissExplanation);
383
401
  wrap.append(control, bubble); return wrap;
384
402
  }
385
403
 
@@ -429,17 +447,26 @@ export function workspaceCloseDrawer(dialog, finish) {
429
447
  }
430
448
 
431
449
  /** Native modal, optionally a right drawer. close() animates; dispose() tears down immediately. */
432
- export function workspaceDialog(doc, { title, content, opener, presentation = 'center', onClose } = {}) {
450
+ export function workspaceDialog(doc, { title, content, opener, presentation = 'center', onClose, appearance, headerTools } = {}) {
433
451
  const dialog = el(doc, 'dialog', { className: 'bb-ws-dialog' });
452
+ if (appearance === 'compact') toggleWorkspaceClass(dialog, 'bb-ws-dialog--compact', true);
434
453
  if (presentation === 'drawer') workspaceApplyDrawer(dialog);
435
454
  const headingId = `bb-ws-dialog-${nextWorkspaceSequence()}`;
436
455
  dialog.setAttribute('aria-labelledby', headingId);
437
456
  const head = el(doc, 'header', { className: 'bb-ws-dialog-head' });
438
457
  const nativeClose = dialog.close.bind(dialog);
439
458
  let disposed = false;
459
+ const dismissVisibleHelp = event => {
460
+ if (event.key !== 'Escape' || event.defaultPrevented) return;
461
+ for (const help of dialog.querySelectorAll?.('.bb-ws-help') ?? []) {
462
+ if (workspaceHelpDismissers.get(help)?.(event)) return;
463
+ }
464
+ };
465
+ dialog.addEventListener('keydown', dismissVisibleHelp, true);
440
466
  const cleanup = () => {
441
467
  if (disposed) return;
442
468
  disposed = true;
469
+ dialog.removeEventListener('keydown', dismissVisibleHelp, true);
443
470
  drawerClosings.get(dialog)?.();
444
471
  dialog.remove();
445
472
  try { onClose?.(); } finally {
@@ -459,7 +486,11 @@ export function workspaceDialog(doc, { title, content, opener, presentation = 'c
459
486
  nativeClose(); cleanup();
460
487
  };
461
488
  const close = workspaceButton(doc, { text: '×', attrs: { 'aria-label': '閉じる' }, onClick: () => dialog.close() });
462
- head.append(el(doc, 'h2', { text: title, attrs: { id: headingId } }), close);
489
+ head.append(el(doc, 'h2', { text: title, attrs: { id: headingId } }));
490
+ if (headerTools) {
491
+ const tools = el(doc, 'div', { className: 'bb-ws-dialog-tools' }); appendContent(tools, doc, headerTools); head.append(tools);
492
+ }
493
+ head.append(close);
463
494
  const body = el(doc, 'div', { className: 'bb-ws-dialog-body' }); appendContent(body, doc, content);
464
495
  dialog.append(head, body); doc.body.append(dialog);
465
496
  dialog.addEventListener('cancel', event => { event.preventDefault(); dialog.close(); });
@@ -476,6 +507,145 @@ export function workspaceFilterChip(doc, { label, onRemove, attrs = {} } = {}) {
476
507
  return chip;
477
508
  }
478
509
 
510
+ const anchoredPopoverBindings = new WeakMap();
511
+
512
+ /** Non-modal anchored surface. Content and visibility have independent lifecycles. */
513
+ export function workspaceAnchoredPopover(doc, {
514
+ anchor, positionAnchor = anchor, content, label, surface = 'default', width = 276, placement = 'bottom', align = 'start', padding, onClose,
515
+ } = {}) {
516
+ if (!anchor || typeof anchor.getBoundingClientRect !== 'function') throw new TypeError('popover_anchor_required');
517
+ if (!positionAnchor || typeof positionAnchor.getBoundingClientRect !== 'function') throw new TypeError('popover_position_anchor_required');
518
+ const element = el(doc, 'div', { className: `bb-ws-anchored-popover${surface === 'muted' ? ' bb-ws-anchored-popover--muted' : ''}`, attrs: {
519
+ role: 'dialog', 'aria-label': label || '詳細', tabindex: '-1', id: `bb-ws-popover-${nextWorkspaceSequence()}`,
520
+ } });
521
+ if (padding === 'none') toggleWorkspaceClass(element, 'bb-ws-anchored-popover--flush', true);
522
+ const binding = anchoredPopoverBindings.get(anchor) || { original: new Map(['aria-controls', 'aria-expanded', 'aria-haspopup'].map(name => [name, anchor.getAttribute?.(name)])) };
523
+ const displaced = binding.owner;
524
+ const owner = {};
525
+ binding.owner = owner; anchoredPopoverBindings.set(anchor, binding);
526
+ displaced?.revoke?.();
527
+ const ownsAnchor = () => anchoredPopoverBindings.get(anchor)?.owner === owner;
528
+ const panelId = element.getAttribute('id');
529
+ anchor.setAttribute('aria-controls', panelId); anchor.setAttribute('aria-haspopup', 'dialog'); anchor.setAttribute('aria-expanded', 'false');
530
+ if (Number.isFinite(width) && width > 0) element.style?.setProperty('--bb-anchored-width', `${width}px`);
531
+ let opened = false;
532
+ let destroyed = false;
533
+ let modalHost;
534
+ const view = doc.defaultView;
535
+ const setContent = next => {
536
+ if (destroyed) return;
537
+ element.replaceChildren(); appendContent(element, doc, next);
538
+ if (opened) reposition();
539
+ };
540
+ const reposition = () => {
541
+ if (!opened || destroyed) return;
542
+ if (anchor.isConnected === false || positionAnchor.isConnected === false) { close({ restoreFocus: false }); return; }
543
+ const at = positionAnchor.getBoundingClientRect();
544
+ const box = element.getBoundingClientRect();
545
+ const viewportWidth = view?.innerWidth || doc.documentElement?.clientWidth || 1024;
546
+ const viewportHeight = view?.innerHeight || doc.documentElement?.clientHeight || 768;
547
+ // offset dimensions are layout sizes, unaffected by the entrance transform.
548
+ const panelWidth = element.offsetWidth || box.width || box.right - box.left;
549
+ const panelHeight = element.offsetHeight || box.height || box.bottom - box.top;
550
+ const x = align === 'end' ? at.right - panelWidth : align === 'center' ? at.left + ((at.width ?? at.right - at.left) - panelWidth) / 2 : at.left;
551
+ const y = placement === 'overlap' ? at.top - 10 : at.bottom + 4;
552
+ element.style?.setProperty('left', `${Math.max(8, Math.min(x, viewportWidth - panelWidth - 8))}px`);
553
+ element.style?.setProperty('top', `${Math.max(8, Math.min(y, viewportHeight - panelHeight - 8))}px`);
554
+ };
555
+ const removeListeners = () => {
556
+ doc.removeEventListener?.('pointerdown', outside); doc.removeEventListener?.('keydown', escape);
557
+ doc.removeEventListener?.('scroll', reposition, true); view?.removeEventListener?.('resize', reposition);
558
+ modalHost?.removeEventListener?.('close', modalClosed); modalHost = undefined;
559
+ };
560
+ const close = ({ restoreFocus = true } = {}) => {
561
+ if (!opened) return;
562
+ opened = false; removeListeners(); element.hidden = true; element.inert = true;
563
+ element.setAttribute('aria-hidden', 'true');
564
+ if (ownsAnchor()) anchor.setAttribute('aria-expanded', 'false');
565
+ if (restoreFocus && anchor.isConnected) anchor.focus?.({ preventScroll: true });
566
+ onClose?.();
567
+ };
568
+ const modalClosed = () => close({ restoreFocus: false });
569
+ const outside = event => {
570
+ if (!element.contains?.(event.target) && !anchor.contains?.(event.target)) close({ restoreFocus: false });
571
+ };
572
+ const escape = event => {
573
+ if (event.key !== 'Escape' || event.defaultPrevented) return;
574
+ event.preventDefault(); event.stopPropagation(); close();
575
+ };
576
+ const open = ({ focus = true } = {}) => {
577
+ if (destroyed || opened || !ownsAnchor() || anchor.isConnected === false || positionAnchor.isConnected === false || anchor.disabled || anchor.getAttribute?.('aria-disabled') === 'true') return;
578
+ // A surface opened inside a native modal must remain inside that top layer.
579
+ const modal = anchor.closest?.('dialog[open]');
580
+ (modal || doc.body).append(element); modalHost = modal;
581
+ modalHost?.addEventListener?.('close', modalClosed);
582
+ opened = true; element.hidden = false; element.inert = false; element.removeAttribute('aria-hidden');
583
+ anchor.setAttribute('aria-expanded', 'true'); reposition();
584
+ if (!opened) return;
585
+ doc.addEventListener?.('pointerdown', outside); doc.addEventListener?.('keydown', escape);
586
+ doc.addEventListener?.('scroll', reposition, true); view?.addEventListener?.('resize', reposition);
587
+ if (focus) (element.querySelector?.('button:not(:disabled),input:not(:disabled),select:not(:disabled),[tabindex="0"]') || element).focus?.({ preventScroll: true });
588
+ };
589
+ owner.revoke = () => close({ restoreFocus: false });
590
+ element.hidden = true; element.inert = true; element.setAttribute('aria-hidden', 'true');
591
+ setContent(content);
592
+ return { element, setContent, open, close, reposition, get isOpen() { return opened; }, destroy() {
593
+ if (destroyed) return;
594
+ destroyed = true; close({ restoreFocus: false }); removeListeners(); element.remove();
595
+ // Do not overwrite a newer surface bound to the same trigger.
596
+ if (ownsAnchor()) {
597
+ anchoredPopoverBindings.delete(anchor);
598
+ for (const [name, value] of binding.original) {
599
+ if (value === null || value === undefined) anchor.removeAttribute?.(name); else anchor.setAttribute(name, value);
600
+ }
601
+ }
602
+ } };
603
+ }
604
+
605
+ /** A checkable row with sibling status/actions, so retry buttons never nest in buttons. */
606
+ export function workspaceSelectionRow(doc, { label, checked = false, disabled = false, leading, trailing, color, onChange } = {}) {
607
+ const root = el(doc, 'div', { className: 'bb-ws-selection-row' });
608
+ const control = workspaceButton(doc, { attrs: { role: 'checkbox', 'aria-label': label } });
609
+ control.className += ' bb-ws-selection-control';
610
+ const check = el(doc, 'span', { className: 'bb-ws-selection-check', attrs: { 'aria-hidden': 'true' } });
611
+ check.append(workspaceActionIcon(doc, 'check')); control.append(check);
612
+ if (leading) appendContent(control, doc, leading);
613
+ control.append(el(doc, 'span', { className: 'bb-ws-selection-label', text: label }));
614
+ root.append(control);
615
+ if (trailing) {
616
+ const slot = el(doc, 'span', { className: 'bb-ws-selection-trailing' }); appendContent(slot, doc, trailing); root.append(slot);
617
+ }
618
+ if (color) root.style?.setProperty('--bb-selection-color', color);
619
+ let selected = Boolean(checked), unavailable = Boolean(disabled), destroyed = false;
620
+ const update = ({ checked: nextChecked, disabled: nextDisabled } = {}) => {
621
+ if (destroyed) return;
622
+ if (nextChecked !== undefined) selected = Boolean(nextChecked);
623
+ if (nextDisabled !== undefined) unavailable = Boolean(nextDisabled);
624
+ control.setAttribute('aria-checked', String(selected)); control.disabled = unavailable;
625
+ toggleWorkspaceClass(root, 'is-disabled', unavailable);
626
+ };
627
+ const click = () => { if (!destroyed && !unavailable) { update({ checked: !selected }); onChange?.(selected); } };
628
+ control.addEventListener('click', click); update();
629
+ return { root, control, update, destroy() { destroyed = true; control.removeEventListener?.('click', click); } };
630
+ }
631
+
632
+ /** Native button keyboard activation with controlled switch state. */
633
+ export function workspaceSwitch(doc, { label, checked = false, disabled = false, onChange } = {}) {
634
+ const control = workspaceButton(doc, { attrs: { role: 'switch', 'aria-label': label } });
635
+ control.className += ' bb-ws-switch';
636
+ control.append(el(doc, 'span', { className: 'bb-ws-switch-track', attrs: { 'aria-hidden': 'true' } }), el(doc, 'span', { text: label }));
637
+ let selected = Boolean(checked), unavailable = Boolean(disabled), destroyed = false;
638
+ const update = ({ checked: nextChecked, disabled: nextDisabled } = {}) => {
639
+ if (destroyed) return;
640
+ if (nextChecked !== undefined) selected = Boolean(nextChecked);
641
+ if (nextDisabled !== undefined) unavailable = Boolean(nextDisabled);
642
+ control.setAttribute('aria-checked', String(selected)); control.disabled = unavailable;
643
+ };
644
+ const click = () => { if (!destroyed && !unavailable) { update({ checked: !selected }); onChange?.(selected); } };
645
+ control.addEventListener('click', click); update();
646
+ return { root: control, control, update, destroy() { destroyed = true; control.removeEventListener?.('click', click); } };
647
+ }
648
+
479
649
  /** One filter choice; callers retain selection and lifecycle ownership. */
480
650
  export function workspaceFilterOption(doc, { label, count, checked = false, disabled = false, role = 'radio', attrs = {}, onClick } = {}) {
481
651
  const button = workspaceButton(doc, { attrs: { ...attrs, role, 'aria-checked': String(checked) }, disabled, onClick });
@@ -653,12 +823,20 @@ function comboboxText(value) {
653
823
  export function workspaceCombobox(doc, {
654
824
  label, options = [], value = '', placeholder = '選択してください', searchLabel, searchPlaceholder = '絞り込む',
655
825
  emptyText = '一致する候補はありません', limit = 100, searchable = 'auto', className, onChange,
656
- multiple = false, values = [], renderIcon, showCount = true, showHints = true, align = 'start', appearance,
826
+ multiple = false, values = [], selectionLabel = '', renderIcon, showCount = true, showHints = true, align = 'start', appearance, boxed = false, matchTriggerWidth = false, triggerHeight, popupWidth, active = false,
657
827
  } = {}) {
658
828
  const sequence = nextWorkspaceSequence();
659
829
  const listId = `bb-ws-combobox-${sequence}-list`;
660
830
  const root = el(doc, 'span', { className: ['bb-ws-combobox', className].filter(Boolean).join(' ') });
661
831
  if (appearance === 'compact') toggleWorkspaceClass(root, 'bb-ws-combobox--compact', true);
832
+ if (boxed) { toggleWorkspaceClass(root, 'is-boxed', true); toggleWorkspaceClass(root, 'bb-ws-combobox--stable-box', true); }
833
+ if (active) toggleWorkspaceClass(root, 'is-active', true);
834
+ if (matchTriggerWidth) toggleWorkspaceClass(root, 'bb-ws-combobox--match-width', true);
835
+ if (triggerHeight === 32) toggleWorkspaceClass(root, 'bb-ws-combobox--tall', true);
836
+ if (Number.isFinite(popupWidth) && popupWidth > 0) {
837
+ toggleWorkspaceClass(root, 'bb-ws-combobox--fixed-width', true);
838
+ root.style?.setProperty('--bb-combobox-popup-width', `${popupWidth}px`);
839
+ }
662
840
  if (multiple) root.classList?.add('bb-ws-combobox-multiple');
663
841
  if (align === 'end') root.classList?.add('bb-ws-combobox-align-end');
664
842
  const trigger = el(doc, 'button', { className: 'bb-ws-combobox-trigger', attrs: { type: 'button', 'aria-haspopup': 'listbox', 'aria-expanded': 'false', 'aria-controls': listId } });
@@ -676,7 +854,7 @@ export function workspaceCombobox(doc, {
676
854
  popup.append(search, list, status);
677
855
  root.append(trigger, popup);
678
856
 
679
- const state = { options: [], values: [...new Set((Array.isArray(values) ? values : []).map(String))].filter(Boolean), value: String(value ?? ''), query: '', active: -1, shown: [], open: false, disabled: false };
857
+ const state = { selectionLabel: String(selectionLabel ?? ''), options: [], values: [...new Set((Array.isArray(values) ? values : []).map(String))].filter(Boolean), value: String(value ?? ''), query: '', active: -1, shown: [], open: false, disabled: false };
680
858
  let exitTimer;
681
859
  const cancelExit = () => { clearTimeout(exitTimer); exitTimer = undefined; popup.removeEventListener?.('animationend', exitEnded); toggleWorkspaceClass(popup, 'is-closing', false); };
682
860
  const finishExit = () => { cancelExit(); if (!state.open) popup.hidden = true; };
@@ -695,9 +873,9 @@ export function workspaceCombobox(doc, {
695
873
  function renderTrigger() {
696
874
  const option = multiple ? (state.values.length === 1 ? state.options.find(option => option.value === state.values[0]) : state.options.find(option => !option.value)) : chosen();
697
875
  const summary = multiple && state.values.length > 1 ? `${state.values.length}件選択中` : null;
698
- const text = summary || (option ? option.label : multiple ? state.values.join('、') || placeholder : state.value || placeholder);
876
+ const text = state.selectionLabel || summary || (option ? option.label : multiple ? state.values.join('、') || placeholder : state.value || placeholder);
699
877
  triggerText.textContent = text;
700
- if (!summary && option && typeof renderIcon === 'function') {
878
+ if (!state.selectionLabel && !summary && option && typeof renderIcon === 'function') {
701
879
  const icon = renderIcon(option);
702
880
  if (icon) { triggerText.textContent = ''; triggerText.append(icon, el(doc, 'span', { className: 'bb-ws-combobox-text', text })); }
703
881
  }
@@ -835,13 +1013,15 @@ export function workspaceCombobox(doc, {
835
1013
  get values() { return [...state.values]; },
836
1014
  get isOpen() { return state.open; },
837
1015
  open, close,
838
- update({ options: nextOptions, value: nextValue, values: nextValues, disabled } = {}) {
839
- const previous = JSON.stringify([state.options, state.value, state.values, state.disabled]);
1016
+ update({ options: nextOptions, value: nextValue, values: nextValues, selectionLabel: nextSelectionLabel, disabled, active: nextActive } = {}) {
1017
+ if (nextActive !== undefined) toggleWorkspaceClass(root, 'is-active', Boolean(nextActive));
1018
+ const previous = JSON.stringify([state.options, state.value, state.values, state.selectionLabel, state.disabled]);
840
1019
  if (nextOptions !== undefined) setOptions(nextOptions);
1020
+ if (nextSelectionLabel !== undefined) state.selectionLabel = String(nextSelectionLabel ?? '');
841
1021
  if (nextValue !== undefined) state.value = String(nextValue ?? '');
842
1022
  if (nextValues !== undefined) state.values = [...new Set((Array.isArray(nextValues) ? nextValues : []).map(String))].filter(Boolean);
843
1023
  if (disabled !== undefined) { state.disabled = Boolean(disabled); if (state.disabled) close(false); }
844
- if (previous === JSON.stringify([state.options, state.value, state.values, state.disabled])) return;
1024
+ if (previous === JSON.stringify([state.options, state.value, state.values, state.selectionLabel, state.disabled])) return;
845
1025
  renderTrigger();
846
1026
  if (state.open) { search.hidden = !usesSearch(); renderList(); }
847
1027
  },
@@ -854,7 +1034,14 @@ export function workspaceActionIcon(doc, name) {
854
1034
  const svg = typeof doc.createElementNS === 'function' ? doc.createElementNS('http://www.w3.org/2000/svg', 'svg') : doc.createElement('svg');
855
1035
  for (const [key, value] of Object.entries({ class: 'bb-ws-action-icon', viewBox: '0 0 24 24', 'aria-hidden': 'true' })) svg.setAttribute(key, value);
856
1036
  const path = typeof doc.createElementNS === 'function' ? doc.createElementNS('http://www.w3.org/2000/svg', 'path') : doc.createElement('path');
857
- const paths = { check: 'M5 12l5 5 9-10', sliders: 'M4 8h8M18 8h2M4 16h2M12 16h8 M17.4 8a2.4 2.4 0 1 1-4.8 0 2.4 2.4 0 0 1 4.8 0 M11.4 16a2.4 2.4 0 1 1-4.8 0 2.4 2.4 0 0 1 4.8 0', plus: 'M12 5v14M5 12h14', search: 'M21 21l-4.35-4.35M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0', filter: 'M4 7h16M7 12h10M10 17h4', sort: 'M8 4v16m-3-3 3 3 3-3M16 20V4m-3 3 3-3 3 3' };
1037
+ const paths = { edit: 'M4 20h4L19 9l-4-4L4 16z M13.5 6.5l4 4', undo: 'M4 5v5h5 M4.6 10A8 8 0 1 1 6.3 17.7', check: 'M5 12l5 5 9-10', sliders: 'M4 8h8M18 8h2M4 16h2M12 16h8 M17.4 8a2.4 2.4 0 1 1-4.8 0 2.4 2.4 0 0 1 4.8 0 M11.4 16a2.4 2.4 0 1 1-4.8 0 2.4 2.4 0 0 1 4.8 0', plus: 'M12 5v14M5 12h14', search: 'M21 21l-4.35-4.35M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0', filter: 'M4 7h16M7 12h10M10 17h4', sort: 'M8 4v16m-3-3 3 3 3-3M16 20V4m-3 3 3-3 3 3' };
1038
+ Object.assign(paths, {
1039
+ clock: 'M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0 M12 7v5l3 2',
1040
+ users: 'M12.2 8a3.2 3.2 0 1 1-6.4 0 3.2 3.2 0 0 1 6.4 0 M3 20c0-3.3 2.7-5.5 6-5.5s6 2.2 6 5.5 M16 5.2a3.2 3.2 0 0 1 0 5.6 M18 14.8c1.9.7 3 2.5 3 5.2',
1041
+ calendar: 'M5 4h14a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2 M8 2v4 M16 2v4 M3 10h18',
1042
+ share: 'M20.6 5a2.6 2.6 0 1 1-5.2 0 2.6 2.6 0 0 1 5.2 0 M8.6 12a2.6 2.6 0 1 1-5.2 0 2.6 2.6 0 0 1 5.2 0 M20.6 19a2.6 2.6 0 1 1-5.2 0 2.6 2.6 0 0 1 5.2 0 M8.3 10.7l7.4-4.3 M8.3 13.3l7.4 4.3',
1043
+ folder: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z',
1044
+ });
858
1045
  path.setAttribute('d', paths[name] || paths.filter); svg.append(path); return svg;
859
1046
  }
860
1047
 
@@ -1113,8 +1300,8 @@ export function workspaceControlRow(doc, { label, control, tight = false } = {})
1113
1300
  return root;
1114
1301
  }
1115
1302
 
1116
- export function workspaceFormRow(doc, { label, control, required = false, top = false } = {}) {
1117
- const root = el(doc, 'div', { className: `bb-ws-form-row${top ? ' is-top' : ''}` });
1303
+ export function workspaceFormRow(doc, { label, control, required = false, top = false, appearance } = {}) {
1304
+ const root = el(doc, 'div', { className: `bb-ws-form-row${top ? ' is-top' : ''}${appearance === 'quiet' ? ' is-quiet' : ''}` });
1118
1305
  const caption = el(doc, control?.id ? 'label' : 'span', { className: 'bb-ws-form-label', text: label,
1119
1306
  attrs: { for: control?.id || undefined } });
1120
1307
  if (required) {
@@ -1128,8 +1315,8 @@ export function workspaceFormRow(doc, { label, control, required = false, top =
1128
1315
  }
1129
1316
 
1130
1317
  /** Uses the canonical modal, Escape/backdrop/close animation and focus return. */
1131
- export function workspaceInputFrame(doc, { title, opener, onClose, tools = [], preview, rows = [], footer = [], showTitle = true } = {}) {
1132
- const drawer = workspaceDetailDrawer(doc, { title, opener, onClose });
1318
+ export function workspaceInputFrame(doc, { title, opener, onClose, beforeClose, tools = [], preview, rows = [], footer = [], showTitle = true } = {}) {
1319
+ const drawer = workspaceDetailDrawer(doc, { title, opener, onClose, beforeClose });
1133
1320
  drawer.dialog.classList.add('bb-ws-input-frame');
1134
1321
  if (tools.length) drawer.dialog.classList.add('has-tools');
1135
1322
  drawer.dialog.querySelector('.bb-ws-detail-closebar > button')?.setAttribute('aria-label', '閉じる');
@@ -272,6 +272,67 @@ function round2(value) {
272
272
  return Math.round(value * 100) / 100;
273
273
  }
274
274
 
275
+ /*
276
+ * The straight-street layout of 0.50.13 and earlier, kept only so that a hosting page which still holds
277
+ * an older world module can import these names from this file during a deploy. Nothing in this package
278
+ * calls them; remove them once every host checks exports per screen rather than per file.
279
+ */
280
+ const LEGACY_STREETS = Object.freeze({ frontLot: 4, backLot: 10, row: 3.4, cross: 2.6 });
281
+ const LEGACY_LOT_COLUMNS = Object.freeze([
282
+ { x: -LEGACY_STREETS.frontLot, facing: 1 },
283
+ { x: LEGACY_STREETS.frontLot, facing: -1 },
284
+ { x: -LEGACY_STREETS.backLot, facing: 1 },
285
+ { x: LEGACY_STREETS.backLot, facing: -1 },
286
+ ]);
287
+
288
+ /** @deprecated since 0.50.14; districts are laid out by `districtRingLots`. */
289
+ export function districtStreetLots(sites, { minRows = 4 } = {}) {
290
+ const groups = new Map();
291
+ for (const site of sites ?? []) {
292
+ const label = typeof site.purpose_label === 'string' && site.purpose_label.trim() ? site.purpose_label.trim() : null;
293
+ const key = label ?? '';
294
+ if (!groups.has(key)) groups.set(key, { key, label, sites: [] });
295
+ groups.get(key).sites.push(site);
296
+ }
297
+ const blocks = [...groups.values()].map((group) => ({ ...group, sites: group.sites.sort(byCreation) }));
298
+ blocks.sort((a, b) => {
299
+ if ((a.label === null) !== (b.label === null)) return a.label === null ? 1 : -1;
300
+ const first = byCreation(a.sites[0], b.sites[0]);
301
+ return first !== 0 ? first : a.key.localeCompare(b.key);
302
+ });
303
+ const rowsOf = (block) => Math.max(1, Math.ceil(block.sites.length / LEGACY_LOT_COLUMNS.length));
304
+ const rows = blocks.reduce((sum, block) => sum + rowsOf(block), 0);
305
+ const used = rows * LEGACY_STREETS.row + Math.max(0, blocks.length - 1) * LEGACY_STREETS.cross;
306
+ const length = Math.max(used, minRows * LEGACY_STREETS.row);
307
+ const lots = {};
308
+ const streets = [];
309
+ let cursor = -used / 2;
310
+ for (const block of blocks) {
311
+ const blockRows = rowsOf(block);
312
+ block.sites.forEach((site, index) => {
313
+ const row = Math.floor(index / LEGACY_LOT_COLUMNS.length);
314
+ const column = LEGACY_LOT_COLUMNS[index % LEGACY_LOT_COLUMNS.length];
315
+ lots[site.task_id] = { x: column.x, z: round2(cursor + (row + 0.5) * LEGACY_STREETS.row), facing: column.facing, street: block.key };
316
+ });
317
+ streets.push({ key: block.key, label: block.label, count: block.sites.length, z_from: round2(cursor), z_to: round2(cursor + blockRows * LEGACY_STREETS.row) });
318
+ cursor += blockRows * LEGACY_STREETS.row + LEGACY_STREETS.cross;
319
+ }
320
+ return { lots, streets, rows, length };
321
+ }
322
+
323
+ /** @deprecated since 0.50.14; districts are laid out by `districtRingPlan`. */
324
+ export function districtGroundPlan(length) {
325
+ const plazaRadius = 3.85;
326
+ const plazaZ = -length / 2 - 1.5 - plazaRadius;
327
+ return {
328
+ gateZ: length / 2 + 4,
329
+ plazaZ,
330
+ plazaRadius,
331
+ hallZ: plazaZ - 5.4,
332
+ street: { from: plazaZ + plazaRadius, to: length / 2 + 12 },
333
+ };
334
+ }
335
+
275
336
  /*
276
337
  * The town grows (story-world-work-sites-and-gaps-v1, AC-22〜24). It grows only from evidenced outcomes
277
338
  * and closed gaps, never from activity: counting completions or edits would let splitting work inflate it.