@symbo.ls/windows
v3.14.719
Published
Unified modal / dialog system. One `ModalRoot` at the app shell hosts a stack of layers; each layer is a separate visible window so a modal can open another modal. Replaces:
Downloads
1,233
Maintainers
Keywords
Readme
@symbo.ls/windows
Unified modal / dialog system. One ModalRoot at the app shell hosts a
stack of layers; each layer is a separate visible window so a modal can
open another modal. Replaces:
- per-component
Modaldefinitions that each declared their ownstateKeyon root state - native
window.alert/window.confirm/window.prompt(which block the JS event loop and ship the host OS's chrome instead of the app's design system)
Wiring
Once per shell — at the app's entry point alongside the SDK + router plugins:
import { windowsComponents } from '@symbo.ls/windows/components'
import { windowsFunctions } from '@symbo.ls/windows/functions'
// 1. Register the plugin's components + functions into context
Object.assign(context.components, windowsComponents)
Object.assign(context.functions, windowsFunctions)
// 2. Add ModalRoot once at the root of your shell tree
const shell = {
Header: {},
Main: {},
Footer: {},
ModalRoot: {}, // ← this line, that's the whole wiring
}The window chrome comes from the design system's ModalWindow (the sheet)
and ModalHeader (the head row), plus Button, Input, Hgroup and
Icon. When the design system defines no ModalWindow / ModalHeader
(an app without a brand library), the plugin's own fallbacks render: the
default config's opaque dialog sheet theme, B padding and the
radiusSheet radius, and a start/space-between head row. They are
registered as smbls.ModalWindow / smbls.ModalHeader, like the
smbls.CancelButton fallback, so a host's own component of the same name
always wins, even when the host spreads windowsComponents into its own
registry.
On a phone (below mobileL, 768 px) every modal is the bottom sheet: full
width on the bottom edge, top corners only, at most 92% of the screen, a
grabber, and the modalInUp entry. The window half is the plugin's
ModalPhoneSheet component, a base UNDER the host's ModalWindow: a
ModalWindow that sets its own @mobileL keys or SheetGrabber wins per
key, and every key it does not set keeps the phone sheet's. A host's own
ModalPhoneSheet (registered under that bare name) replaces the plugin's
window half for every modal. The frame half stays on ModalLayer: below
mobileL the layer drops its gutter and seats the window on the bottom
edge.
Calling
From any element handler:
el.call('confirmDialog', {
title: 'Delete event?',
message: 'This permanently removes "Standup" from everyone’s calendar.',
confirmText: 'Delete',
confirmTheme: 'red',
icon: 'trash',
onConfirm: () => el.call('deleteEvent', id),
onCancel: () => {}, // optional
})
el.call('alertDialog', {
title: 'Saved',
message: 'Your changes are live.',
onOk: () => {}, // optional
})
el.call('promptDialog', {
title: 'Rename page',
message: 'New name:',
defaultValue: oldName,
placeholder: 'Untitled',
onConfirm: (value) => el.call('renamePage', value),
onCancel: () => {}, // optional
})
// Custom content — caller provides a DOMQL fragment
const layerId = el.call('openModal', {
template: 'custom',
content: {
H2: { text: 'Custom modal' },
P: { text: 'Anything DOMQL goes here.' },
Button: { text: 'Done', onClick: (e, btn) => btn.call('closeModal', layerId) },
},
})Default texts
A field the caller leaves out shows the template's default: Confirm's
title, message, Cancel and Confirm; Alert's title and OK; Prompt's title,
Cancel and OK. Each default is a polyglot key in the framework's
dialog.* namespace. dialog.cancel and dialog.ok are the same keys
the default-config Dialog reads, so one translation serves every
framework dialog. The defaults and their resolver are the framework's
own: DIALOG_COPY and resolveDialogCopy in @symbo.ls/default-config
(re-exported by smbls), the one table both this plugin and Dialog
read.
| Default | Key | en | ka |
|---|---|---|---|
| Cancel (Confirm, Prompt) | dialog.cancel | Cancel | გაუქმება |
| OK (Alert, Prompt) | dialog.ok | OK | კარგი |
| Confirm (Confirm) | dialog.confirm | Confirm | დადასტურება |
| Confirm title | dialog.confirmTitle | Are you sure? | დარწმუნებული ხართ? |
| Confirm message | dialog.confirmMessage | This action cannot be undone. | ამ მოქმედების გაუქმება შეუძლებელია. |
| Alert title | dialog.alertTitle | Notice | შეტყობინება |
| Prompt title | dialog.promptTitle | Enter a value | შეიყვანეთ მნიშვნელობა |
The first answer wins:
- the caller's own field (
title,message,cancelText,confirmText,okText); - the project's polyglot for the key: its static and server catalogs, the translations its shared libraries merge in, and its default-language fallback;
- the framework default for the active language (
en,ka); - English.
A project without polyglot, or with a polyglot that does not know the key, never shows the raw key. To word a default your own way, add its key to your polyglot catalog:
context.polyglot = {
defaultLang: 'ka',
languages: ['ka', 'en'],
translations: {
ka: { 'dialog.cancel': 'არა' },
en: { 'dialog.cancel': 'Not now' },
},
}A dialog that is open during a language switch keeps the language it opened in. The next dialog opens in the new language.
Stacking
Up to 5 layers (ModalLayer_0 through ModalLayer_4). Layer N
z-indexes at 2000 + N*10, so layer 1 always renders above layer 0.
ESC closes the topmost layer and backdrop clicks dismiss, unless
dismissOnBackdrop: false was passed to openModal: such a layer
(the onboarding workspace gate, say) closes only through its own
actions.
Accessible name
Every window is a role="dialog", aria-modal="true" surface named by
its heading: aria-labelledby="modal-title-<layerId>". Each layer slot
keeps all four templates in the DOM and shows one, and only the shown
template's heading carries that id, so the name always comes from the
heading on screen:
confirmDialog/alertDialog/promptDialog— the visible heading:title, or the template's default (Are you sure?,Notice,Enter a value, in the project's language: see Default texts) when the title is absent or blank.openModal({ template: 'custom' })— passtitleto name the dialog; it renders as a visually hidden heading. Without atitlethe window carries noaria-labelledby: a heading insidecontentdoes not name the dialog.
Rules followed
- FA101 / FA102 — flat
el.Xprops +onClick/onInit/onDestroy(noel.props.X, noon.click). - FA201 — mutable state lives in
state.stackon ModalRoot, never on globalScope. - FA204 — Prompt's input draft uses
scope: { value: '' }. - FA207 — top-level
const _layerText = (el, field, fallback) => ...helpers, no nestedfunctiondeclarations inside handlers. - FA514 — ESC listener attached via
onInit/onDestroylifecycle, not at module load. The previouswindow.__modalEscBoundpattern inworkspace/packages/shared/components/Modal.jsis the exact anti-pattern this plugin retires. - REUSE rule — Window chrome extends the host's
ModalWindow/ModalHeader(the plugin'ssmbls.fallbacks only fill a gap); buttons extendButton; inputs extendInput; icons extendIcon. No re-definition of built-ins.
