@serene-pub/sdk 0.6.0-pr-1
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/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host-element vocabulary (§3.5, R17, R22): every element a component
|
|
3
|
+
* may place, with the attributes it takes, the events it raises and the
|
|
4
|
+
* named slots it fills. A component runs in the page's UI worker and the
|
|
5
|
+
* host mirrors what it renders into the widget box; **this table is the
|
|
6
|
+
* allowlist the host's receiver enforces**, so an element, attribute or
|
|
7
|
+
* event not listed here never reaches the page.
|
|
8
|
+
*
|
|
9
|
+
* Two families:
|
|
10
|
+
*
|
|
11
|
+
* - **plain elements** — the HTML a widget lays text out with. Each takes
|
|
12
|
+
* `class` (scoped by the widget-CSS rule, like every widget's). `href` must
|
|
13
|
+
* be `https:` or a fragment and opens in a new tab only (`target="_blank"`;
|
|
14
|
+
* the host sets `rel="noopener noreferrer"` itself); `src` is the app's own
|
|
15
|
+
* media or the plugin's own files — never another host, because an image
|
|
16
|
+
* URL is a request the page makes, and a remote's only path out is its
|
|
17
|
+
* plugin's own server-side actions.
|
|
18
|
+
* - **`sp-*` sp elements** — elements the HOST renders, with its own components:
|
|
19
|
+
* one per piece of behaviour a widget needs and cannot fake from plain
|
|
20
|
+
* elements (a positioned popover, a menu, a dialog, tabs, form controls
|
|
21
|
+
* that keep the caret on the page, markdown that streams, a scroll that
|
|
22
|
+
* sticks to the bottom, a real document for a charting library).
|
|
23
|
+
*
|
|
24
|
+
* **Sp elements are unopinionated about style (R22).** An sp element renders the markup
|
|
25
|
+
* its behaviour needs and the structural hooks a skin targets — `.sp-<name>`
|
|
26
|
+
* on its root and the parts named in its `parts` — and no colour, radius or
|
|
27
|
+
* spacing beyond what the behaviour requires. A widget styles it through
|
|
28
|
+
* `class`; a skin does the rest. Unstyled-but-correct is the accepted
|
|
29
|
+
* failure mode, never a broken widget.
|
|
30
|
+
*
|
|
31
|
+
* **Form controls are host-owned.** `input`, `textarea`, `sp-composer-field`,
|
|
32
|
+
* `sp-combobox`, `sp-slider` and `sp-switch` raise their value on `input` /
|
|
33
|
+
* `change`; a component never writes `value` back except to reset it, so a
|
|
34
|
+
* keystroke is one message and the caret never moves.
|
|
35
|
+
*
|
|
36
|
+
* **Events** arrive as `CustomEvent`s whose `detail` each element's `doc`
|
|
37
|
+
* states; a plain control's carry `{ value }` (`{ checked }` for a checkbox),
|
|
38
|
+
* and a click carries nothing.
|
|
39
|
+
*
|
|
40
|
+
* Every element also takes `slot` (which named slot of its sp-element
|
|
41
|
+
* parent it fills) — not listed per element, allowed everywhere.
|
|
42
|
+
*
|
|
43
|
+
* Nothing here is an `on*` attribute, a `style` attribute, `script`, `style`
|
|
44
|
+
* or `iframe` — `sp-frame` is the one way to a real document, through the
|
|
45
|
+
* frame machinery (opaque origin, CSP, a MessageChannel port). The SDK's own
|
|
46
|
+
* tests hold that line.
|
|
47
|
+
*
|
|
48
|
+
* **Values are checked too** ({@link hostAttributeValueFinding}): a name in
|
|
49
|
+
* the table is not a licence for any value — `href` is `https:` or a
|
|
50
|
+
* fragment, `target` only `_blank` / `_self`, `input type` a short list. The
|
|
51
|
+
* receiver calls it for every attribute it mirrors; ids are the receiver's
|
|
52
|
+
* to prefix per widget box, so a remote cannot collide with the page's.
|
|
53
|
+
*
|
|
54
|
+
* @experimental 🚧 provisional until core's own session widgets render
|
|
55
|
+
* through it (C7, R21): the set may grow and an attribute may be renamed
|
|
56
|
+
* before then. It never shrinks after 1.0.
|
|
57
|
+
*/
|
|
58
|
+
const plain = (doc, attributes = [], events = []) => ({
|
|
59
|
+
attributes: [...attributes, 'class'],
|
|
60
|
+
events,
|
|
61
|
+
doc,
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Attributes every plain element accepts for accessibility. `aria-current`
|
|
65
|
+
* marks the current item of a list, stepper or trail and `aria-live` a live
|
|
66
|
+
* region; both take a closed value set ({@link HOST_ARIA_CURRENT},
|
|
67
|
+
* {@link HOST_ARIA_LIVE}), checked by {@link hostAttributeValueFinding}.
|
|
68
|
+
*/
|
|
69
|
+
const ARIA = [
|
|
70
|
+
'id',
|
|
71
|
+
'role',
|
|
72
|
+
'aria-label',
|
|
73
|
+
'aria-labelledby',
|
|
74
|
+
'aria-describedby',
|
|
75
|
+
'aria-hidden',
|
|
76
|
+
'aria-current',
|
|
77
|
+
'aria-live',
|
|
78
|
+
'title',
|
|
79
|
+
];
|
|
80
|
+
/**
|
|
81
|
+
* The allowlist. Keys are tag names; order is the order the `.d.ts` prints.
|
|
82
|
+
*
|
|
83
|
+
* @experimental 🚧 until C7 (see the module note).
|
|
84
|
+
*/
|
|
85
|
+
export const SP_HOST_ELEMENTS = {
|
|
86
|
+
// ── plain elements ────────────────────────────────────────────────────
|
|
87
|
+
div: plain('A block.', ARIA),
|
|
88
|
+
span: plain('An inline run.', ARIA),
|
|
89
|
+
p: plain('A paragraph.', ARIA),
|
|
90
|
+
ul: plain('An unordered list.', ARIA),
|
|
91
|
+
ol: plain('An ordered list.', ARIA),
|
|
92
|
+
li: plain('A list item.', ARIA),
|
|
93
|
+
h1: plain('A heading.', ARIA),
|
|
94
|
+
h2: plain('A heading.', ARIA),
|
|
95
|
+
h3: plain('A heading.', ARIA),
|
|
96
|
+
h4: plain('A heading.', ARIA),
|
|
97
|
+
strong: plain('Strong emphasis.', ARIA),
|
|
98
|
+
em: plain('Emphasis.', ARIA),
|
|
99
|
+
small: plain('Small print.', ARIA),
|
|
100
|
+
code: plain('Inline code.', ARIA),
|
|
101
|
+
kbd: plain('A key a person presses.', ARIA),
|
|
102
|
+
article: plain('A self-contained item (a message, a card).', ARIA),
|
|
103
|
+
header: plain("A group's heading row.", ARIA),
|
|
104
|
+
section: plain('A titled part of a component (label it: `aria-label` or a heading).', ARIA),
|
|
105
|
+
dl: plain('A description list.', ARIA),
|
|
106
|
+
dt: plain('A described term.', ARIA),
|
|
107
|
+
dd: plain("A term's description.", ARIA),
|
|
108
|
+
hr: plain('A thematic break.', ARIA),
|
|
109
|
+
br: plain('A line break.'),
|
|
110
|
+
table: plain('A table.', ARIA),
|
|
111
|
+
thead: plain('A table head.', ARIA),
|
|
112
|
+
tbody: plain('A table body.', ARIA),
|
|
113
|
+
tr: plain('A table row.', ARIA),
|
|
114
|
+
th: plain('A header cell.', [...ARIA, 'scope', 'colspan', 'rowspan']),
|
|
115
|
+
td: plain('A data cell.', [...ARIA, 'colspan', 'rowspan']),
|
|
116
|
+
button: plain('A button. `click` carries nothing.', [...ARIA, 'type', 'disabled', 'aria-pressed', 'aria-expanded'], ['click']),
|
|
117
|
+
input: plain('A host-owned text, number or checkbox input. `input` / `change` carry `{ value }` ' +
|
|
118
|
+
'(`{ checked }` for a checkbox); `value` written by the component resets it. `keys` names keys ' +
|
|
119
|
+
"the widget handles itself, in `sp-composer-field`'s words (`Escape Enter`, `Control+Enter`): each " +
|
|
120
|
+
'is kept from the field and raised as `key` (`{ key, shift, ctrl, meta }`); every other key is the ' +
|
|
121
|
+
"field's own, so a number field still steps on its arrows. `blur` (nothing carried) is the field " +
|
|
122
|
+
'losing focus — a number field raises `change` on every spinner step, so an editor that closes when ' +
|
|
123
|
+
'the person is done listens for `blur`.', [...ARIA, 'type', 'value', 'checked', 'placeholder', 'disabled', 'min', 'max', 'step', 'name', 'autocomplete', 'spellcheck', 'autofocus', 'keys'], ['input', 'change', 'key', 'blur']),
|
|
124
|
+
textarea: plain('A host-owned multi-line input. `input` / `change` carry `{ value }`.', [...ARIA, 'value', 'placeholder', 'disabled', 'rows', 'name', 'autocomplete', 'spellcheck', 'autofocus'], ['input', 'change']),
|
|
125
|
+
label: plain('A label for a control.', ['for', 'id']),
|
|
126
|
+
img: plain('An image. `src` is an app media URL (`/media/…`, a session asset `/session-assets/<id>`) or the plugin\'s own file (`/plugin-ui/…`) — never another host. ' +
|
|
127
|
+
'`loading` is `lazy` · `eager` and `decoding` `async` · `sync` · `auto` (1.2). `error` (nothing carried) is the image failing to load — a file deleted since, say — so a widget can draw its own stand-in rather than a broken image (1.2).', ['src', 'alt', 'width', 'height', 'id', 'title', 'loading', 'decoding'], ['error']),
|
|
128
|
+
a: plain('A link. `href` is `https:`, a fragment or one of the app\'s own files (`/media/…`, `/session-assets/…`); `target` may only be `_blank`, `download` names a saved file, and the host sets `rel="noopener noreferrer"`.', [...ARIA, 'href', 'target', 'download'], ['click']),
|
|
129
|
+
// ── host sp elements ────────────────────────────────────────────────────────
|
|
130
|
+
'sp-avatar': {
|
|
131
|
+
attributes: ['ref', 'size', 'class'],
|
|
132
|
+
events: [],
|
|
133
|
+
parts: ['sp-avatar-image', 'sp-avatar-fallback'],
|
|
134
|
+
doc: "A participant's avatar, by participant reference (`character:3`, `user:1`). `size` is `sm` · `md` · `lg`.",
|
|
135
|
+
},
|
|
136
|
+
'sp-icon': {
|
|
137
|
+
attributes: ['name', 'size', 'label', 'class'],
|
|
138
|
+
events: [],
|
|
139
|
+
doc: 'An icon from the app\'s set, by kebab-case name (`book-open`). With no `label` it is decorative.',
|
|
140
|
+
},
|
|
141
|
+
'sp-badge': {
|
|
142
|
+
attributes: ['tone', 'class'],
|
|
143
|
+
events: [],
|
|
144
|
+
doc: 'A short label. `tone` is `neutral` · `primary` · `success` · `warning` · `error`.',
|
|
145
|
+
},
|
|
146
|
+
'sp-progress': {
|
|
147
|
+
attributes: ['value', 'max', 'label', 'class'],
|
|
148
|
+
events: [],
|
|
149
|
+
parts: ['sp-progress-track', 'sp-progress-fill'],
|
|
150
|
+
doc: 'A progress bar. No `value` is indeterminate.',
|
|
151
|
+
},
|
|
152
|
+
'sp-tooltip': {
|
|
153
|
+
attributes: ['text', 'placement', 'class'],
|
|
154
|
+
events: [],
|
|
155
|
+
parts: ['sp-tooltip-panel'],
|
|
156
|
+
doc: 'A tooltip over its body, which is the trigger. `placement` is a side (`top` · `bottom` · `left` · `right`).',
|
|
157
|
+
},
|
|
158
|
+
'sp-popover': {
|
|
159
|
+
attributes: ['open', 'placement', 'label', 'class'],
|
|
160
|
+
events: ['open-change'],
|
|
161
|
+
slots: ['trigger'],
|
|
162
|
+
parts: ['sp-popover-panel'],
|
|
163
|
+
doc: 'A positioned panel. The `trigger` slot opens it; the body is the panel. `open-change` carries `{ open }`.',
|
|
164
|
+
},
|
|
165
|
+
'sp-menu': {
|
|
166
|
+
attributes: ['open', 'placement', 'label', 'class'],
|
|
167
|
+
events: ['select', 'open-change'],
|
|
168
|
+
slots: ['trigger'],
|
|
169
|
+
children: ['sp-menu-item'],
|
|
170
|
+
parts: ['sp-menu-panel', 'sp-menu-row'],
|
|
171
|
+
doc: 'A menu of actions. The `trigger` slot opens it. `select` carries `{ value }`; `open-change` carries `{ open }`.',
|
|
172
|
+
},
|
|
173
|
+
'sp-menu-item': {
|
|
174
|
+
attributes: ['value', 'disabled', 'class'],
|
|
175
|
+
events: [],
|
|
176
|
+
doc: 'One action in an `sp-menu`; its content (a label, an icon, a note) is the row\'s.',
|
|
177
|
+
},
|
|
178
|
+
'sp-dialog': {
|
|
179
|
+
attributes: ['open', 'label', 'class'],
|
|
180
|
+
events: ['open-change'],
|
|
181
|
+
slots: ['title', 'footer'],
|
|
182
|
+
parts: ['sp-dialog-backdrop', 'sp-dialog-panel'],
|
|
183
|
+
doc: 'A modal dialog, focus-trapped by the host. `open-change` carries `{ open }` — Escape and the backdrop close it.',
|
|
184
|
+
},
|
|
185
|
+
'sp-tabs': {
|
|
186
|
+
attributes: ['value', 'label', 'class'],
|
|
187
|
+
events: ['change'],
|
|
188
|
+
slots: ['list-end'],
|
|
189
|
+
children: ['sp-tab', 'sp-tab-panel'],
|
|
190
|
+
parts: ['sp-tabs-list', 'sp-tab-trigger'],
|
|
191
|
+
doc: 'Tabs. `sp-tab` children are the list, `sp-tab-panel` children the panels, matched by `value`; the `list-end` slot sits at the end of the list (an overflow control). `change` carries `{ value }`.',
|
|
192
|
+
},
|
|
193
|
+
'sp-tab': {
|
|
194
|
+
attributes: ['value', 'disabled', 'label', 'class'],
|
|
195
|
+
events: [],
|
|
196
|
+
doc: 'One tab in an `sp-tabs`; its content (a label, an icon) is the trigger\'s, `label` names the trigger when its content is only an icon, and its `class` is the trigger\'s too.',
|
|
197
|
+
},
|
|
198
|
+
'sp-tab-panel': {
|
|
199
|
+
attributes: ['value', 'class'],
|
|
200
|
+
events: [],
|
|
201
|
+
doc: 'The panel an `sp-tab` of the same `value` shows.',
|
|
202
|
+
},
|
|
203
|
+
'sp-accordion': {
|
|
204
|
+
attributes: ['value', 'multiple', 'class'],
|
|
205
|
+
events: ['change'],
|
|
206
|
+
children: ['sp-accordion-item'],
|
|
207
|
+
doc: 'Collapsible sections. `value` is the open item (space-separated when `multiple`). `change` carries `{ value }`.',
|
|
208
|
+
},
|
|
209
|
+
'sp-accordion-item': {
|
|
210
|
+
attributes: ['value', 'heading', 'level', 'class'],
|
|
211
|
+
events: [],
|
|
212
|
+
parts: ['sp-accordion-trigger', 'sp-accordion-panel'],
|
|
213
|
+
doc: 'One section of an `sp-accordion`; `heading` is its trigger text (a heading of `level` 2–6, default 3), its body the panel.',
|
|
214
|
+
},
|
|
215
|
+
'sp-switch': {
|
|
216
|
+
attributes: ['checked', 'disabled', 'label', 'class'],
|
|
217
|
+
events: ['change'],
|
|
218
|
+
doc: 'A host-owned on/off switch. `change` carries `{ checked }`.',
|
|
219
|
+
},
|
|
220
|
+
'sp-slider': {
|
|
221
|
+
attributes: ['value', 'min', 'max', 'step', 'disabled', 'label', 'class'],
|
|
222
|
+
events: ['input', 'change'],
|
|
223
|
+
doc: 'A host-owned slider. `input` (while dragging) and `change` (on release) carry `{ value }`.',
|
|
224
|
+
},
|
|
225
|
+
'sp-combobox': {
|
|
226
|
+
attributes: ['value', 'placeholder', 'disabled', 'label', 'class'],
|
|
227
|
+
events: ['input', 'change'],
|
|
228
|
+
children: ['sp-option'],
|
|
229
|
+
doc: 'A host-owned searchable select. `input` carries `{ query }` as the person types; `change` carries `{ value }`.',
|
|
230
|
+
},
|
|
231
|
+
'sp-option': {
|
|
232
|
+
attributes: ['value', 'disabled', 'class'],
|
|
233
|
+
events: [],
|
|
234
|
+
doc: 'One option of an `sp-combobox`; its body is the label.',
|
|
235
|
+
},
|
|
236
|
+
'sp-message-body': {
|
|
237
|
+
attributes: ['text', 'streaming', 'class'],
|
|
238
|
+
events: ['open-image'],
|
|
239
|
+
doc: "A message's text, rendered as the app renders messages (markdown, quotes, actions) by the host. Update `text` as message pushes arrive; `streaming` shows the in-progress state. `open-image` (`{ src }`) fires when a person clicks an image in the text.",
|
|
240
|
+
},
|
|
241
|
+
'sp-composer-field': {
|
|
242
|
+
attributes: [
|
|
243
|
+
'value',
|
|
244
|
+
'placeholder',
|
|
245
|
+
'disabled',
|
|
246
|
+
'label',
|
|
247
|
+
'rows',
|
|
248
|
+
'class',
|
|
249
|
+
'submit-on',
|
|
250
|
+
'keys',
|
|
251
|
+
'field-class',
|
|
252
|
+
'spellcheck',
|
|
253
|
+
'aria-invalid',
|
|
254
|
+
'aria-describedby',
|
|
255
|
+
'aria-controls',
|
|
256
|
+
'aria-activedescendant',
|
|
257
|
+
'aria-autocomplete',
|
|
258
|
+
'autofocus',
|
|
259
|
+
],
|
|
260
|
+
events: ['input', 'change', 'submit', 'key', 'focus'],
|
|
261
|
+
doc: "The app's composer text field, host-owned: the caret stays on the page. `input` / `change` carry `{ value }`; " +
|
|
262
|
+
'`submit` carries `{ value }` on the send key (Enter without Shift) unless `submit-on="none"`. `keys` names ' +
|
|
263
|
+
'keys the widget handles itself (`ArrowUp ArrowDown Tab Escape Enter`; a bare `Enter` leaves Shift+Enter to ' +
|
|
264
|
+
'the field), or a key only while a modifier is held (`Control+Enter Meta+Enter`; `Control`, `Meta`, `Shift`): each is ' +
|
|
265
|
+
'kept from the field and raised as `key` (`{ key, shift, ctrl, meta }`). `autofocus` (core\'s alone) gives the ' +
|
|
266
|
+
'field the caret, at its end, as it lands. The `aria-*` given here go on the field itself; `field-class` ' +
|
|
267
|
+
"replaces the field's own classes (a composer skin styles the field, not its wrapper).",
|
|
268
|
+
},
|
|
269
|
+
'sp-file-picker': {
|
|
270
|
+
attributes: ['accept', 'multiple', 'disabled', 'class'],
|
|
271
|
+
events: ['files'],
|
|
272
|
+
doc: "🚧 Opens the device's file picker when its body is clicked (1.3). The body is the widget's own control — a `button` " +
|
|
273
|
+
'it draws and names (`aria-label="Attach files"`) — so its look and label stay the widget\'s. `accept` is the ' +
|
|
274
|
+
"picker's filter (`image/png,.md`), `multiple` lets several be chosen, `disabled` opens nothing. `files` carries " +
|
|
275
|
+
'`{ files: File[] }`, the chosen files as the page holds them. A file `input` is not in the vocabulary ' +
|
|
276
|
+
'(`input type`): this is the one way to a file.',
|
|
277
|
+
},
|
|
278
|
+
'sp-drop-zone': {
|
|
279
|
+
attributes: ['disabled', 'label', 'class'],
|
|
280
|
+
events: ['files'],
|
|
281
|
+
parts: ['sp-drop-zone-overlay'],
|
|
282
|
+
doc: '🚧 A region files can be dropped onto or pasted into (1.3). Its body is the region. While files are dragged over it the ' +
|
|
283
|
+
'host shows an overlay (`sp-drop-zone-overlay`) saying `label` (default "Drop to attach"). `files` carries ' +
|
|
284
|
+
'`{ files: File[], via: "drop" | "paste" }` — a drop, or a paste of files (a screenshot) anywhere inside the region; ' +
|
|
285
|
+
'a paste of text stays the field\'s.',
|
|
286
|
+
},
|
|
287
|
+
'sp-scroll': {
|
|
288
|
+
attributes: ['stick', 'label', 'class'],
|
|
289
|
+
events: ['reach-start'],
|
|
290
|
+
doc: 'A scroll region. `stick="bottom"` keeps it anchored to the end as content grows, as a log does (`stick="top"` for a newest-first log); scrolled away from that end, what is on screen stays put as rows arrive above or below. `reach-start` fires when the far end from `stick` is reached (load older).',
|
|
291
|
+
},
|
|
292
|
+
'sp-host-view': {
|
|
293
|
+
attributes: ['name', 'channel', 'class'],
|
|
294
|
+
events: [],
|
|
295
|
+
doc: "🚧 One of the host's own views, drawn by the host where the element sits (`name` from `HOST_VIEW_NAMES`). The widget places it and never sees inside it — what the host draws there is the viewer's, not the widget's. `channel` (1.1) says which channel the place is for — a channel-pinned conversation's turn controls and action chips are that channel's listing; absent, the host's own composer channel.",
|
|
296
|
+
},
|
|
297
|
+
'sp-frame': {
|
|
298
|
+
attributes: ['src', 'props', 'title', 'class'],
|
|
299
|
+
events: ['action', 'error', 'invoke'],
|
|
300
|
+
doc: "A real document inside the widget, for what needs one (a rich-text editor, a charting library that measures). `src` is a document the plugin ships; `props` is JSON forwarded as the frame's props. The document's `invoke` is raised unresolved — `detail: { key, messageId?, payload?, blockId? }` — for the component to pass to `ctx.invoke(key, …)`, so the press meets this widget's actions and gate.",
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
/** The host sp elements alone — the elements the host must implement (C1b's boot gate). @experimental */
|
|
304
|
+
export const SP_ELEMENT_TAGS = Object.keys(SP_HOST_ELEMENTS).filter((t) => t.startsWith('sp-'));
|
|
305
|
+
const isTag = (tag) => Object.hasOwn(SP_HOST_ELEMENTS, tag);
|
|
306
|
+
/** Is this element in the vocabulary? @experimental */
|
|
307
|
+
export function isHostElement(tag) {
|
|
308
|
+
return isTag(tag.toLowerCase());
|
|
309
|
+
}
|
|
310
|
+
/** Does this element accept this attribute? `slot` is accepted on every element. @experimental */
|
|
311
|
+
export function hostAttributeAllowed(tag, attribute) {
|
|
312
|
+
const t = tag.toLowerCase();
|
|
313
|
+
if (!isTag(t))
|
|
314
|
+
return false;
|
|
315
|
+
return (attribute === 'slot' ||
|
|
316
|
+
GLOBAL_ATTRIBUTES.includes(attribute) ||
|
|
317
|
+
isDataAttribute(attribute) ||
|
|
318
|
+
/^aria-[a-z]+$/.test(attribute) ||
|
|
319
|
+
SP_HOST_ELEMENTS[t].attributes.includes(attribute));
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Attributes every element takes (C0b), besides `aria-*` (all of them; the
|
|
323
|
+
* ones naming an element by id are the host's to prefix) and a widget's own
|
|
324
|
+
* `data-*`: `hidden` and `inert` hide and disable what the widget drew;
|
|
325
|
+
* `role`; `tabindex` (0 or -1 — into the tab order or out of it, never
|
|
326
|
+
* ahead of the page's); and `style`, holding CUSTOM PROPERTIES only
|
|
327
|
+
* (`--sp-fill: 40%`), which the widget's skin reads — a declaration of its
|
|
328
|
+
* own could fetch (`url()`) or cover the page.
|
|
329
|
+
* @experimental
|
|
330
|
+
*/
|
|
331
|
+
export const GLOBAL_ATTRIBUTES = ['hidden', 'inert', 'role', 'tabindex', 'style'];
|
|
332
|
+
/** One `style` value's custom properties, or why it holds something else. @experimental */
|
|
333
|
+
export function customPropertiesFinding(value) {
|
|
334
|
+
for (const decl of value.split(';')) {
|
|
335
|
+
const d = decl.trim();
|
|
336
|
+
if (!d)
|
|
337
|
+
continue;
|
|
338
|
+
const m = /^(--[A-Za-z0-9_-]+)\s*:\s*(.*)$/s.exec(d);
|
|
339
|
+
if (!m)
|
|
340
|
+
return `style '${value}' — custom properties only (--name: value); a widget's skin reads them`;
|
|
341
|
+
if (/url\s*\(|src\s*\(|image\s*\(|image-set|expression\s*\(|\\|@import|[<>]/i.test(m[2]))
|
|
342
|
+
return `style '${value}' — a custom property's value is plain data (no url(), no escapes)`;
|
|
343
|
+
}
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* A widget's own `data-*` attribute — what its skin and a style pack key
|
|
348
|
+
* off. `data-sp-*` is the HOST's (`data-sp-owner` decides whose rules an
|
|
349
|
+
* element falls under), so a widget never writes one.
|
|
350
|
+
* @experimental
|
|
351
|
+
*/
|
|
352
|
+
export const isDataAttribute = (attribute) => /^data-[a-z0-9][a-z0-9-]*$/.test(attribute) && !attribute.startsWith('data-sp-');
|
|
353
|
+
/** `input type`s a component may place — no `file`, `password`, `submit`, `image`, `hidden`. */
|
|
354
|
+
/**
|
|
355
|
+
* 🚧 The host views a widget may place with `sp-host-view` (C0b) — parts of
|
|
356
|
+
* the page that belong to the session, not to any widget: the status strips
|
|
357
|
+
* above the composer and the composer's own page tabs. The list grows; a name
|
|
358
|
+
* the host does not know renders nothing.
|
|
359
|
+
* @experimental
|
|
360
|
+
*/
|
|
361
|
+
export const HOST_VIEW_NAMES = [
|
|
362
|
+
'session-banners',
|
|
363
|
+
'session-actions',
|
|
364
|
+
'retrieval-notice',
|
|
365
|
+
'run-progress',
|
|
366
|
+
'session-controls',
|
|
367
|
+
'session-workflow',
|
|
368
|
+
'retrieval-preview',
|
|
369
|
+
'session-usage',
|
|
370
|
+
'scene-images',
|
|
371
|
+
'session-statistics',
|
|
372
|
+
];
|
|
373
|
+
/** 🚧 The `aria-current` values an element may carry — the ARIA tokens, no free text. @experimental */
|
|
374
|
+
export const HOST_ARIA_CURRENT = ['page', 'step', 'location', 'date', 'time', 'true', 'false'];
|
|
375
|
+
/**
|
|
376
|
+
* 🚧 The `aria-live` values an element may carry: `off` and `polite` only.
|
|
377
|
+
* Never `assertive` — it interrupts whatever the screen reader is saying,
|
|
378
|
+
* and a widget is one box among many on a page the person is using; a
|
|
379
|
+
* widget that shouts over the composer or the page's own announcements
|
|
380
|
+
* takes the reader away from the person. The page keeps assertive for its
|
|
381
|
+
* own alerts.
|
|
382
|
+
* @experimental
|
|
383
|
+
*/
|
|
384
|
+
export const HOST_ARIA_LIVE = ['off', 'polite'];
|
|
385
|
+
/** @experimental */
|
|
386
|
+
export const HOST_INPUT_TYPES = ['text', 'search', 'number', 'checkbox', 'radio', 'range', 'email', 'url', 'color', 'date', 'time'];
|
|
387
|
+
const HTTPS = /^https:\/\/[^\s]+$/i;
|
|
388
|
+
/**
|
|
389
|
+
* An app media URL: the app's own `/media/…`, `/plugin-ui/…` or
|
|
390
|
+
* `/session-assets/…` routes, same origin. A query is allowed — every face
|
|
391
|
+
* the page resolves names its revision (`/media/<uuid>?v=thumb&r=3`) — a dot
|
|
392
|
+
* segment never: `/media/../api/x` is `/api/x` once the browser resolves it,
|
|
393
|
+
* and an image is a GET the page makes with its own cookies.
|
|
394
|
+
*
|
|
395
|
+
* A session asset — a message part's image or file, a block's image — is
|
|
396
|
+
* the route's own shape and nothing more: `/session-assets/<file id>`, a
|
|
397
|
+
* positive integer, with an optional query (`?v=thumb`). The route only
|
|
398
|
+
* redirects to `/media/<id>`, whose access check is the wall; a path under
|
|
399
|
+
* the id is no asset the app serves. Which session a file belongs to is not
|
|
400
|
+
* in its address, so that is the server's to judge, never the URL's.
|
|
401
|
+
*/
|
|
402
|
+
const APP_MEDIA = /^\/(media|plugin-ui)\/[A-Za-z0-9._~%\/-]+(\?[A-Za-z0-9._~%=&-]*)?$/;
|
|
403
|
+
const SESSION_ASSET = /^\/session-assets\/[1-9][0-9]*(\?[A-Za-z0-9._~%=&-]*)?$/;
|
|
404
|
+
const DOT_SEGMENT = /(^|\/)(\.|%2e){1,2}(\/|$)/i;
|
|
405
|
+
const isAppMedia = (v) => SESSION_ASSET.test(v) || (APP_MEDIA.test(v) && !DOT_SEGMENT.test(v.split('?')[0]));
|
|
406
|
+
/**
|
|
407
|
+
* One `keys` token — `sp-composer-field`'s and a plain `input`'s (R80): a
|
|
408
|
+
* key, after any number of the modifiers the host reads (`Control+Enter`,
|
|
409
|
+
* `Shift+Meta+ArrowUp`). The key holds no `+`: {@link hostKeysMatch} splits
|
|
410
|
+
* a token at its `+`s, so `+` or `Control++` would read as an empty key. A
|
|
411
|
+
* modifier the host does not read (`Alt+`, `Ctrl+`, a lowercase `control+`)
|
|
412
|
+
* or a token that ends at its `+` would be a key no press ever matches —
|
|
413
|
+
* kept from nothing, and silently — so it is refused instead.
|
|
414
|
+
*/
|
|
415
|
+
const HOST_KEYS_TOKEN = /^(?:(?:Control|Meta|Shift)\+)*[^+]+$/;
|
|
416
|
+
/** The elements that take `keys`, and raise `key` for a press it names. */
|
|
417
|
+
const KEYED_TAGS = new Set(['sp-composer-field', 'input']);
|
|
418
|
+
/** The modifiers a `keys` token may name before its key, and how a press holds each. */
|
|
419
|
+
const HELD_MODIFIERS = new Map([
|
|
420
|
+
['Control', (p) => p.ctrlKey],
|
|
421
|
+
['Meta', (p) => p.metaKey],
|
|
422
|
+
['Shift', (p) => p.shiftKey],
|
|
423
|
+
]);
|
|
424
|
+
/**
|
|
425
|
+
* 🚧 Does this `keys` value name this press (R80)? THE reading of the
|
|
426
|
+
* grammar, for every element that takes `keys`: a bare key names it whatever
|
|
427
|
+
* is held — except that a bare `Enter` leaves Shift+Enter to the field (a
|
|
428
|
+
* composer's newline) — and `Control+Enter` names it only while Control is
|
|
429
|
+
* held (every modifier the token names held; others may be too). A press
|
|
430
|
+
* mid-composition is named by nothing.
|
|
431
|
+
* @experimental
|
|
432
|
+
*/
|
|
433
|
+
export function hostKeysMatch(keys, press) {
|
|
434
|
+
if (!keys || press.isComposing)
|
|
435
|
+
return false;
|
|
436
|
+
for (const token of keys.split(/\s+/)) {
|
|
437
|
+
if (!token)
|
|
438
|
+
continue;
|
|
439
|
+
const held = token.split('+');
|
|
440
|
+
const key = held.pop() ?? '';
|
|
441
|
+
if (key !== press.key)
|
|
442
|
+
continue;
|
|
443
|
+
if (held.length ? held.every((m) => HELD_MODIFIERS.get(m)?.(press) ?? false) : !(key === 'Enter' && press.shiftKey))
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
/** 🚧 The `key` event's detail for this press (R80). @experimental */
|
|
449
|
+
export function hostKeyEventDetail(press) {
|
|
450
|
+
return { key: press.key, shift: press.shiftKey, ctrl: press.ctrlKey, meta: press.metaKey };
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Why this value may not be written to this attribute, or `undefined` if it
|
|
454
|
+
* may. Assumes {@link hostAttributeAllowed} already said the name is fine.
|
|
455
|
+
* Per tag where one attribute means two things (`sp-frame`'s `src` is a
|
|
456
|
+
* document its plugin ships, a plain `img`'s is a URL).
|
|
457
|
+
* @experimental
|
|
458
|
+
*/
|
|
459
|
+
export function hostAttributeValueFinding(tag, attribute, value) {
|
|
460
|
+
const t = tag.toLowerCase();
|
|
461
|
+
const v = value.trim();
|
|
462
|
+
if (attribute === 'style')
|
|
463
|
+
return customPropertiesFinding(v);
|
|
464
|
+
if (attribute === 'tabindex')
|
|
465
|
+
return v === '0' || v === '-1' ? undefined : `tabindex '${value}' — 0 or -1`;
|
|
466
|
+
if (attribute === 'aria-current')
|
|
467
|
+
return HOST_ARIA_CURRENT.includes(v)
|
|
468
|
+
? undefined
|
|
469
|
+
: `aria-current '${value}' — one of ${HOST_ARIA_CURRENT.join(', ')}`;
|
|
470
|
+
if (attribute === 'aria-live')
|
|
471
|
+
return HOST_ARIA_LIVE.includes(v)
|
|
472
|
+
? undefined
|
|
473
|
+
: `aria-live '${value}' — off or polite (never assertive: a widget does not interrupt the reader)`;
|
|
474
|
+
if (attribute === 'href') {
|
|
475
|
+
// A person clicks a link, so it may name the app's own files (a
|
|
476
|
+
// download, an attachment) as well as another site.
|
|
477
|
+
if (v.startsWith('#') || HTTPS.test(v) || isAppMedia(v))
|
|
478
|
+
return undefined;
|
|
479
|
+
return `${t} href '${value}' — https: links, #fragments and the app's own files only`;
|
|
480
|
+
}
|
|
481
|
+
if (t === 'sp-host-view' && attribute === 'name')
|
|
482
|
+
return HOST_VIEW_NAMES.includes(v) ? undefined : `sp-host-view name '${value}' — one of ${HOST_VIEW_NAMES.join(', ')}`;
|
|
483
|
+
if (t === 'sp-composer-field' && attribute === 'submit-on')
|
|
484
|
+
return v === 'enter' || v === 'none' ? undefined : `sp-composer-field submit-on '${value}' — enter or none`;
|
|
485
|
+
if (KEYED_TAGS.has(t) && attribute === 'keys') {
|
|
486
|
+
const bad = v.split(/\s+/).find((token) => token && !HOST_KEYS_TOKEN.test(token));
|
|
487
|
+
return bad === undefined
|
|
488
|
+
? undefined
|
|
489
|
+
: `${t} keys '${bad}' — a key, after any of the modifiers Control+, Meta+ and Shift+ (Control+Enter)`;
|
|
490
|
+
}
|
|
491
|
+
if (t === 'img' && attribute === 'loading')
|
|
492
|
+
return v === 'lazy' || v === 'eager' ? undefined : `img loading '${value}' — lazy or eager`;
|
|
493
|
+
if (t === 'img' && attribute === 'decoding')
|
|
494
|
+
return v === 'async' || v === 'sync' || v === 'auto' ? undefined : `img decoding '${value}' — async, sync or auto`;
|
|
495
|
+
if (t === 'sp-scroll' && attribute === 'stick')
|
|
496
|
+
return v === 'top' || v === 'bottom' ? undefined : `sp-scroll stick '${value}' — top or bottom`;
|
|
497
|
+
if (attribute === 'src') {
|
|
498
|
+
if (t === 'sp-frame')
|
|
499
|
+
return /^[A-Za-z0-9_-][A-Za-z0-9._-]*(\/[A-Za-z0-9._-]+)*$/.test(v) && !v.split('/').some((s) => s === '.' || s === '..')
|
|
500
|
+
? undefined
|
|
501
|
+
: `sp-frame src '${value}' — a document path inside the plugin`;
|
|
502
|
+
// Never another host: an image URL is a request the PAGE makes, so an
|
|
503
|
+
// https image would be a way out for what a remote was shown.
|
|
504
|
+
return isAppMedia(v) ? undefined : `${t} src '${value}' — the app's media or the plugin's own files only`;
|
|
505
|
+
}
|
|
506
|
+
// `_self` would navigate the app away; the host sets `rel` itself.
|
|
507
|
+
if (attribute === 'target')
|
|
508
|
+
return v === '_blank' ? undefined : `target '${value}' — only _blank`;
|
|
509
|
+
if (t === 'input' && attribute === 'type')
|
|
510
|
+
return HOST_INPUT_TYPES.includes(v.toLowerCase())
|
|
511
|
+
? undefined
|
|
512
|
+
: `input type '${value}' — one of ${HOST_INPUT_TYPES.join(', ')}`;
|
|
513
|
+
if (attribute === 'props' && t === 'sp-frame') {
|
|
514
|
+
try {
|
|
515
|
+
const p = JSON.parse(v);
|
|
516
|
+
return p && typeof p === 'object' && !Array.isArray(p) ? undefined : 'sp-frame props — a JSON object';
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
return 'sp-frame props — a JSON object';
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return undefined;
|
|
523
|
+
}
|
|
524
|
+
/** Does this element raise this event? @experimental */
|
|
525
|
+
export function hostEventAllowed(tag, event) {
|
|
526
|
+
const t = tag.toLowerCase();
|
|
527
|
+
return isTag(t) && SP_HOST_ELEMENTS[t].events.includes(event);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* 🚧 The events the page re-delivers (C7): `click` alone. The receiver
|
|
531
|
+
* forwards an event only from the node that listens for it, and only the
|
|
532
|
+
* vocabulary's listeners exist — a button hears `click`; the `span` label
|
|
533
|
+
* inside it does not, nor the `svg` an icon draws for itself — so a click on
|
|
534
|
+
* a button's label or icon was lost. Never `change`, `input` and the rest: a
|
|
535
|
+
* descendant's, re-delivered, would arrive as the ANCESTOR's own event
|
|
536
|
+
* carrying the descendant's value.
|
|
537
|
+
* @experimental
|
|
538
|
+
*/
|
|
539
|
+
export const REDELIVERED_EVENTS = ['click'];
|
|
540
|
+
const takes = (el, type) => isTag(el.localName) && SP_HOST_ELEMENTS[el.localName].events.includes(type);
|
|
541
|
+
/**
|
|
542
|
+
* 🚧 Where the page re-delivers an event that started on `origin`, or `null`
|
|
543
|
+
* when it does not: the nearest element strictly inside `territory` (a
|
|
544
|
+
* remote's box, or a panel one of its elements portaled out) that takes the
|
|
545
|
+
* event, above where it starts. It starts at `origin` (a text node's parent)
|
|
546
|
+
* — or, inside markup a host element drew for itself, at that element (the
|
|
547
|
+
* outermost whose `ownsMarkup(origin)` says so). `null` when where it starts
|
|
548
|
+
* takes the event (its own listener hears it), when nothing below
|
|
549
|
+
* `territory` does, when `origin` is `territory` or outside it, and for an
|
|
550
|
+
* event not in {@link REDELIVERED_EVENTS}.
|
|
551
|
+
*
|
|
552
|
+
* Reads the DOM and dispatches nothing: the page and the component harness
|
|
553
|
+
* share it, and each dispatches {@link redeliveredCopy} there.
|
|
554
|
+
* @experimental
|
|
555
|
+
*/
|
|
556
|
+
export function redeliveryTarget(origin, type, territory) {
|
|
557
|
+
if (!REDELIVERED_EVENTS.includes(type))
|
|
558
|
+
return null;
|
|
559
|
+
if (origin === territory || !territory.contains(origin))
|
|
560
|
+
return null;
|
|
561
|
+
const originEl = origin.nodeType === 1 ? origin : origin.parentElement;
|
|
562
|
+
// A text node straight inside the territory: nothing below it encloses it.
|
|
563
|
+
if (!originEl || originEl === territory)
|
|
564
|
+
return null;
|
|
565
|
+
let start = originEl;
|
|
566
|
+
for (let n = origin; n && n !== territory; n = n.parentNode) {
|
|
567
|
+
const el = n;
|
|
568
|
+
if (typeof el.ownsMarkup === 'function' && el.ownsMarkup(origin))
|
|
569
|
+
start = el;
|
|
570
|
+
}
|
|
571
|
+
if (takes(start, type))
|
|
572
|
+
return null;
|
|
573
|
+
for (let n = start.parentElement; n && n !== territory; n = n.parentElement)
|
|
574
|
+
if (takes(n, type))
|
|
575
|
+
return n;
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* 🚧 The copy the page dispatches at {@link redeliveryTarget}: unbubbling, and
|
|
580
|
+
* a `CustomEvent` — never a `MouseEvent`, whose dispatch runs an `<a>`'s or a
|
|
581
|
+
* `<button>`'s activation, so the person's own click (which activates it on
|
|
582
|
+
* its way up) would activate it twice: two downloads, two tabs. The listener
|
|
583
|
+
* it reaches forwards nothing of it; the page's summary is read off the
|
|
584
|
+
* person's event. Made in the event's own window, so a DOM beside another
|
|
585
|
+
* realm's globals (a test's) dispatches it.
|
|
586
|
+
* @experimental
|
|
587
|
+
*/
|
|
588
|
+
export function redeliveredCopy(e) {
|
|
589
|
+
const view = e.target?.ownerDocument?.defaultView;
|
|
590
|
+
const Custom = view?.CustomEvent ?? CustomEvent;
|
|
591
|
+
return new Custom(e.type, { bubbles: false, cancelable: e.cancelable });
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* 🚧 Where the page raises `key` for a keydown (R80): the plain `input` the
|
|
595
|
+
* press landed on, when it sits strictly inside `territory` (a remote's box,
|
|
596
|
+
* or a panel one of its elements portaled out) and its `keys` names the
|
|
597
|
+
* press ({@link hostKeysMatch}) — else `null`. `sp-composer-field` reads its
|
|
598
|
+
* own `keys`, by the same rule. Reads the DOM and dispatches nothing: the
|
|
599
|
+
* page and the component harness share it, and each keeps the press from the
|
|
600
|
+
* field (`preventDefault`) and dispatches {@link hostKeyEvent} there.
|
|
601
|
+
* @experimental
|
|
602
|
+
*/
|
|
603
|
+
export function keyedInputTarget(e, territory) {
|
|
604
|
+
const t = e.target;
|
|
605
|
+
if (!t || t.nodeType !== 1 || t.localName !== 'input')
|
|
606
|
+
return null;
|
|
607
|
+
if (t === territory || !territory.contains(t))
|
|
608
|
+
return null;
|
|
609
|
+
return hostKeysMatch(t.getAttribute('keys'), e) ? t : null;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* 🚧 The `key` event the page dispatches at {@link keyedInputTarget} (R80):
|
|
613
|
+
* a `CustomEvent` carrying {@link HostKeyEventDetail}, unbubbling — the
|
|
614
|
+
* receiver listens on the field itself, and the page has no business with
|
|
615
|
+
* it. Made in the press's own window, as {@link redeliveredCopy} is.
|
|
616
|
+
* @experimental
|
|
617
|
+
*/
|
|
618
|
+
export function hostKeyEvent(e) {
|
|
619
|
+
const view = e.target?.ownerDocument?.defaultView;
|
|
620
|
+
const Custom = view?.CustomEvent ?? CustomEvent;
|
|
621
|
+
return new Custom('key', { detail: hostKeyEventDetail(e), bubbles: false });
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* The editor typings for the vocabulary, as the text of a `.d.ts` — shipped
|
|
625
|
+
* from the SDK as `@serene-pub/sdk/host-elements` so an editor and the CLI
|
|
626
|
+
* know every element, attribute, event and slot. Generated from the table,
|
|
627
|
+
* so the typings cannot disagree with what the host accepts; a test holds
|
|
628
|
+
* the checked-in file to this output.
|
|
629
|
+
* @experimental
|
|
630
|
+
*/
|
|
631
|
+
export function hostElementsDts() {
|
|
632
|
+
const lines = [
|
|
633
|
+
'// Generated from SP_HOST_ELEMENTS (sdk/src/hostElements.ts) — do not edit.',
|
|
634
|
+
'// Regenerate: npm run host-elements -w sdk',
|
|
635
|
+
'',
|
|
636
|
+
'/** Attributes are strings on the wire; booleans are present-or-absent. @experimental 🚧 until C7 settles. */',
|
|
637
|
+
'type SpAttr = string | number | boolean | null | undefined',
|
|
638
|
+
'',
|
|
639
|
+
'/** Every element a component may place, with the attributes each accepts. @experimental 🚧 until C7 settles. */',
|
|
640
|
+
'export interface SpHostElements {',
|
|
641
|
+
];
|
|
642
|
+
for (const [tag, spec] of Object.entries(SP_HOST_ELEMENTS)) {
|
|
643
|
+
const extra = [
|
|
644
|
+
spec.slots?.length ? `Slots: ${spec.slots.map((s) => `\`${s}\``).join(', ')}.` : '',
|
|
645
|
+
spec.children?.length ? `Children: ${spec.children.map((c) => `\`<${c}>\``).join(', ')}.` : '',
|
|
646
|
+
tag.startsWith('sp-')
|
|
647
|
+
? `Parts: ${[tag, ...(spec.parts ?? [])].map((p) => `\`.${p}\``).join(', ')}.`
|
|
648
|
+
: '',
|
|
649
|
+
spec.events.length ? `Events: ${spec.events.map((e) => `\`${e}\``).join(', ')}.` : '',
|
|
650
|
+
].filter(Boolean);
|
|
651
|
+
lines.push(`\t/**`, `\t * ${spec.doc}`);
|
|
652
|
+
for (const e of extra)
|
|
653
|
+
lines.push(`\t * ${e}`);
|
|
654
|
+
lines.push(`\t */`);
|
|
655
|
+
lines.push(`\t'${tag}': {`);
|
|
656
|
+
for (const a of spec.attributes)
|
|
657
|
+
lines.push(`\t\t'${a}'?: SpAttr`);
|
|
658
|
+
// Any element may fill an sp element's named slot.
|
|
659
|
+
lines.push(`\t\tslot?: string`);
|
|
660
|
+
lines.push(`\t}`);
|
|
661
|
+
}
|
|
662
|
+
lines.push('}', '');
|
|
663
|
+
lines.push('/** Every tag a component may place. @experimental 🚧 until C7 settles. */');
|
|
664
|
+
lines.push('export type SpHostTag = keyof SpHostElements');
|
|
665
|
+
lines.push('');
|
|
666
|
+
lines.push('/** The events each tag raises, for `addEventListener` typing. @experimental 🚧 until C7 settles. */');
|
|
667
|
+
lines.push('export interface SpHostEvents {');
|
|
668
|
+
for (const [tag, spec] of Object.entries(SP_HOST_ELEMENTS))
|
|
669
|
+
if (spec.events.length)
|
|
670
|
+
lines.push(`\t'${tag}': ${spec.events.map((e) => `'${e}'`).join(' | ')}`);
|
|
671
|
+
lines.push('}', '');
|
|
672
|
+
return lines.join('\n');
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* @experimental 🚧 with the vocabulary it versions (F1).
|
|
676
|
+
*
|
|
677
|
+
* The version of the host-element vocabulary's PUBLIC SHAPE — every tag in
|
|
678
|
+
* {@link SP_HOST_ELEMENTS} with its attributes, events, slots, children and
|
|
679
|
+
* parts, and the closed value lists beside it ({@link GLOBAL_ATTRIBUTES},
|
|
680
|
+
* {@link HOST_VIEW_NAMES}, {@link HOST_ARIA_CURRENT}, {@link HOST_ARIA_LIVE},
|
|
681
|
+
* {@link HOST_INPUT_TYPES}). A built component records the one it was built
|
|
682
|
+
* against (`builtAgainst.hostElements`, F1), and a host refuses to mount one
|
|
683
|
+
* whose MAJOR it lacks (`componentBuiltAgainstFinding`).
|
|
684
|
+
*
|
|
685
|
+
* `major.minor`, never a hash: a hash changes on every addition and cannot
|
|
686
|
+
* tell "grew" (harmless — a year-old component places nothing new) from
|
|
687
|
+
* "shrank" (fatal — it places what the host now drops). So:
|
|
688
|
+
*
|
|
689
|
+
* - **minor** bumps when the shape GROWS: a tag, an attribute, an event, a
|
|
690
|
+
* slot, a part, a value. A component built for a newer minor still mounts
|
|
691
|
+
* on an older host — what that host does not know it drops, the
|
|
692
|
+
* vocabulary's stated failure mode (unstyled-but-correct, R22).
|
|
693
|
+
* - **major** bumps when anything is REMOVED, RENAMED or NARROWED (a value
|
|
694
|
+
* list loses a value, an event changes its `detail`). A host that has
|
|
695
|
+
* moved to a new major still lists the majors it keeps mounting.
|
|
696
|
+
*
|
|
697
|
+
* A test pins a hash of the shape to this version (`sdk-tests/
|
|
698
|
+
* componentBuiltAgainst.test.ts`): change the table without bumping this and
|
|
699
|
+
* the suite says which to bump. `doc` strings are not the shape.
|
|
700
|
+
*/
|
|
701
|
+
export const HOST_ELEMENTS_VERSION = '1.3';
|
|
702
|
+
//# sourceMappingURL=hostElements.js.map
|