domma-js 0.56.0 → 0.57.0

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.
Files changed (117) hide show
  1. package/assets/types/generated/public/assets/flags/africa.d.ts +6 -0
  2. package/assets/types/generated/public/assets/flags/americas.d.ts +6 -0
  3. package/assets/types/generated/public/assets/flags/asia.d.ts +6 -0
  4. package/assets/types/generated/public/assets/flags/europe.d.ts +9 -0
  5. package/assets/types/generated/public/assets/flags/index.d.ts +11 -0
  6. package/assets/types/generated/public/assets/flags/oceania.d.ts +2 -0
  7. package/assets/types/generated/public/assets/icons/buildings.d.ts +6 -0
  8. package/assets/types/generated/public/assets/icons/code.d.ts +2 -0
  9. package/assets/types/generated/public/assets/icons/commerce.d.ts +7 -0
  10. package/assets/types/generated/public/assets/icons/communication.d.ts +7 -0
  11. package/assets/types/generated/public/assets/icons/devices.d.ts +6 -0
  12. package/assets/types/generated/public/assets/icons/emojis.d.ts +6 -0
  13. package/assets/types/generated/public/assets/icons/files.d.ts +7 -0
  14. package/assets/types/generated/public/assets/icons/finance.d.ts +6 -0
  15. package/assets/types/generated/public/assets/icons/forms.d.ts +5 -0
  16. package/assets/types/generated/public/assets/icons/health.d.ts +6 -0
  17. package/assets/types/generated/public/assets/icons/index.d.ts +24 -0
  18. package/assets/types/generated/public/assets/icons/media.d.ts +7 -0
  19. package/assets/types/generated/public/assets/icons/navigation.d.ts +7 -0
  20. package/assets/types/generated/public/assets/icons/seasonal.d.ts +6 -0
  21. package/assets/types/generated/public/assets/icons/social.d.ts +7 -0
  22. package/assets/types/generated/public/assets/icons/sport.d.ts +6 -0
  23. package/assets/types/generated/public/assets/icons/status.d.ts +7 -0
  24. package/assets/types/generated/public/assets/icons/transport.d.ts +7 -0
  25. package/assets/types/generated/public/assets/icons/ui.d.ts +7 -0
  26. package/assets/types/generated/public/assets/icons/weather.d.ts +6 -0
  27. package/assets/types/generated/src/auth.d.ts +424 -0
  28. package/assets/types/generated/src/avatar.d.ts +270 -0
  29. package/assets/types/generated/src/binding-source.d.ts +58 -0
  30. package/assets/types/generated/src/butterfly-drawing.d.ts +2 -0
  31. package/assets/types/generated/src/component-factory.d.ts +150 -0
  32. package/assets/types/generated/src/component.d.ts +162 -0
  33. package/assets/types/generated/src/components/back-to-top.d.ts +150 -0
  34. package/assets/types/generated/src/components/badge.d.ts +208 -0
  35. package/assets/types/generated/src/components/card.d.ts +189 -0
  36. package/assets/types/generated/src/components/command-palette.d.ts +352 -0
  37. package/assets/types/generated/src/components/dropzone.d.ts +342 -0
  38. package/assets/types/generated/src/components/focus-trap.d.ts +238 -0
  39. package/assets/types/generated/src/components/loader.d.ts +133 -0
  40. package/assets/types/generated/src/components/modal.d.ts +341 -0
  41. package/assets/types/generated/src/components/range-slider.d.ts +267 -0
  42. package/assets/types/generated/src/components/shared.d.ts +91 -0
  43. package/assets/types/generated/src/components/split-pane.d.ts +239 -0
  44. package/assets/types/generated/src/components/toast.d.ts +284 -0
  45. package/assets/types/generated/src/components/tooltip.d.ts +200 -0
  46. package/assets/types/generated/src/components/virtual-list.d.ts +340 -0
  47. package/assets/types/generated/src/config.d.ts +193 -0
  48. package/assets/types/generated/src/context-cursor.d.ts +69 -0
  49. package/assets/types/generated/src/context-menu.d.ts +596 -0
  50. package/assets/types/generated/src/dates.d.ts +367 -0
  51. package/assets/types/generated/src/dom.d.ts +1221 -0
  52. package/assets/types/generated/src/effects.d.ts +1281 -0
  53. package/assets/types/generated/src/elements.d.ts +4996 -0
  54. package/assets/types/generated/src/escape.d.ts +5 -0
  55. package/assets/types/generated/src/flags-bundle.d.ts +4 -0
  56. package/assets/types/generated/src/flags.d.ts +338 -0
  57. package/assets/types/generated/src/forms.d.ts +1060 -0
  58. package/assets/types/generated/src/globals.d.ts +45 -0
  59. package/assets/types/generated/src/http.d.ts +131 -0
  60. package/assets/types/generated/src/i18n.d.ts +261 -0
  61. package/assets/types/generated/src/icons.d.ts +213 -0
  62. package/assets/types/generated/src/index.d.ts +249 -0
  63. package/assets/types/generated/src/input-group.d.ts +135 -0
  64. package/assets/types/generated/src/models.d.ts +968 -0
  65. package/assets/types/generated/src/popover.d.ts +412 -0
  66. package/assets/types/generated/src/router.d.ts +344 -0
  67. package/assets/types/generated/src/safe-url.d.ts +10 -0
  68. package/assets/types/generated/src/sanitize.d.ts +97 -0
  69. package/assets/types/generated/src/schema-builder.d.ts +420 -0
  70. package/assets/types/generated/src/skeleton.d.ts +135 -0
  71. package/assets/types/generated/src/smooth-caret.d.ts +61 -0
  72. package/assets/types/generated/src/sortable.d.ts +369 -0
  73. package/assets/types/generated/src/storage.d.ts +93 -0
  74. package/assets/types/generated/src/tables.d.ts +901 -0
  75. package/assets/types/generated/src/theme.d.ts +277 -0
  76. package/assets/types/generated/src/ticker-tape-drawing.d.ts +2 -0
  77. package/assets/types/generated/src/treeview.d.ts +504 -0
  78. package/assets/types/generated/src/utils.d.ts +1667 -0
  79. package/assets/types/generated/src/web-components/base/domma-element.d.ts +134 -0
  80. package/assets/types/generated/src/web-components/index.d.ts +14 -0
  81. package/assets/types/generated/vendor/domma-reactive.d.ts +587 -0
  82. package/assets/types/index.d.ts +104 -226
  83. package/package.json +5 -2
  84. package/public/dist/bundles/domma-complete.css +20 -14
  85. package/public/dist/bundles/domma-data-focused.css +20 -14
  86. package/public/dist/bundles/domma-essentials.css +20 -14
  87. package/public/dist/bundles/domma-full.css +20 -14
  88. package/public/dist/bundles/domma-minimal.css +8 -8
  89. package/public/dist/domma-flags.esm.js +3 -3
  90. package/public/dist/domma-flags.esm.js.map +1 -1
  91. package/public/dist/domma-flags.min.js +3 -3
  92. package/public/dist/domma-flags.min.js.map +1 -1
  93. package/public/dist/domma-syntax.min.js +3 -3
  94. package/public/dist/domma.css +3 -3
  95. package/public/dist/domma.esm.js +5 -5
  96. package/public/dist/domma.esm.js.map +1 -1
  97. package/public/dist/domma.min.js +5 -5
  98. package/public/dist/domma.min.js.map +1 -1
  99. package/public/dist/elements.css +9 -3
  100. package/public/dist/grid.css +3 -3
  101. package/public/dist/syntax.css +3 -3
  102. package/public/dist/themes/domma-themes.css +3 -3
  103. package/templates/kickstart/frontend/types/domma.d.ts +2 -1
  104. package/assets/types/config.d.ts +0 -136
  105. package/assets/types/dates.d.ts +0 -209
  106. package/assets/types/dom.d.ts +0 -448
  107. package/assets/types/elements.d.ts +0 -1168
  108. package/assets/types/flags.d.ts +0 -130
  109. package/assets/types/http.d.ts +0 -97
  110. package/assets/types/i18n.d.ts +0 -99
  111. package/assets/types/icons.d.ts +0 -147
  112. package/assets/types/models.d.ts +0 -260
  113. package/assets/types/smooth-caret.d.ts +0 -12
  114. package/assets/types/storage.d.ts +0 -93
  115. package/assets/types/tables.d.ts +0 -327
  116. package/assets/types/theme.d.ts +0 -137
  117. package/assets/types/utils.d.ts +0 -675
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Initials for a name.
3
+ *
4
+ * 'Jane Smith' -> 'JS' first and last word
5
+ * 'Jane Q. Public' -> 'JP'
6
+ * 'Madonna' -> 'M' one word, one letter
7
+ * 'jane.smith@example.com' -> 'JS' the part before the @, split on . _ - +
8
+ * 'Jean-Luc Picard' -> 'JP'
9
+ * 'Łukasz Żuk' -> 'ŁŻ'
10
+ * '王小明' -> '王'
11
+ * '', null, ' !! ' -> '' nothing to go on: callers show an icon
12
+ *
13
+ * Words are split on spaces, dots, underscores, hyphens and plus signs;
14
+ * anything that is not a letter or digit at the start of a word (quotes,
15
+ * brackets, emoji) is skipped, and bracketed notes like "(Admin)" are dropped.
16
+ * @param {string|null|undefined} name
17
+ * @returns {string}
18
+ */
19
+ export function avatarInitials(name: string | null | undefined): string;
20
+ /**
21
+ * The tone (0-7) for a name: FNV-1a over the trimmed, lower-cased, single-spaced
22
+ * name. Stable across pages, sessions and machines; case and spacing do not
23
+ * change it, so 'jane smith' and 'Jane Smith' match.
24
+ * @param {string} key
25
+ * @returns {number}
26
+ */
27
+ export function avatarTone(key: string): number;
28
+ /**
29
+ * Render one avatar.
30
+ * @overload
31
+ * @param {string|Element|ArrayLike<Element>|null} target
32
+ * @param {AvatarOptions} [options]
33
+ * @returns {AvatarHandle|null}
34
+ */
35
+ export function avatar(target: string | Element | ArrayLike<Element> | null, options?: AvatarOptions): AvatarHandle | null;
36
+ /**
37
+ * Render one avatar into a detached <span> for you to insert.
38
+ * @overload
39
+ * @param {AvatarOptions} options
40
+ * @returns {AvatarHandle}
41
+ */
42
+ export function avatar(options: AvatarOptions): AvatarHandle;
43
+ export namespace avatar {
44
+ export { avatarInitials as initials };
45
+ export { avatarTone as tone };
46
+ /**
47
+ * The live handle on an element, if any - the same answer as E.get(target, 'avatar').
48
+ * @param {string|Element|ArrayLike<Element>} target
49
+ * @returns {AvatarHandle|null}
50
+ */
51
+ export function get(target: string | Element | ArrayLike<Element>): AvatarHandle | null;
52
+ /**
53
+ * Turn every `[data-avatar]` under `root` (and `root` itself) into an avatar,
54
+ * once. Options come from `data-avatar-*`. Returns the new handles.
55
+ * @param {string|Element|Document} [root]
56
+ * @returns {AvatarHandle[]}
57
+ */
58
+ export function scan(root?: string | Element | Document): AvatarHandle[];
59
+ }
60
+ /**
61
+ * Render a stack of avatars with a "+N" overflow bubble.
62
+ *
63
+ * @param {string|Element|ArrayLike<Element>} target - a <ul>/<ol> to fill, or any element
64
+ * to put a new <ul> into (its content comes back on destroy())
65
+ * @param {AvatarGroupOptions} [options] - see GROUP_DEFAULTS
66
+ * @returns {AvatarGroupHandle|null} null if nothing matched
67
+ */
68
+ export function avatarGroup(target: string | Element | ArrayLike<Element>, options?: AvatarGroupOptions): AvatarGroupHandle | null;
69
+ export namespace avatarGroup {
70
+ /**
71
+ * The live group handle on a host element (or its list), if any - the same answer as E.get(target, 'avatar-group').
72
+ * @param {string|Element|ArrayLike<Element>} target
73
+ * @returns {AvatarGroupHandle|null}
74
+ */
75
+ function get(target: string | Element | ArrayLike<Element>): AvatarGroupHandle | null;
76
+ }
77
+ /** @type {AvatarSize[]} */
78
+ export const AVATAR_SIZES: AvatarSize[];
79
+ /** @type {AvatarShape[]} */
80
+ export const AVATAR_SHAPES: AvatarShape[];
81
+ /** @type {AvatarStatus[]} */
82
+ export const AVATAR_STATUSES: AvatarStatus[];
83
+ /** How many `.avatar-tone-*` classes elements.css defines. */
84
+ export const AVATAR_TONES: 8;
85
+ export default avatar;
86
+ export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl";
87
+ export type AvatarShape = "circle" | "rounded" | "square";
88
+ export type AvatarStatus = "online" | "away" | "busy" | "offline";
89
+ export type AvatarOptions = {
90
+ /**
91
+ * - The person: initials, tone and accessible name come from it
92
+ */
93
+ name?: string | null;
94
+ /**
95
+ * - Picture URL; falls back to the initials (or icon) if it fails to load
96
+ */
97
+ src?: string | null;
98
+ /**
99
+ * - Accessible name when it should differ from name
100
+ */
101
+ alt?: string | null;
102
+ /**
103
+ * - Size (default 'md')
104
+ */
105
+ size?: AvatarSize;
106
+ /**
107
+ * - Shape (default 'circle')
108
+ */
109
+ shape?: AvatarShape;
110
+ /**
111
+ * - Status dot; the word goes into the accessible name
112
+ */
113
+ status?: AvatarStatus | null;
114
+ /**
115
+ * - Words for the statuses in the accessible name, e.g. {busy: 'in a meeting'}
116
+ */
117
+ statusLabels?: Partial<Record<AvatarStatus, string>> | null;
118
+ /**
119
+ * - Icon name shown instead of initials ('user' when there is no name)
120
+ */
121
+ icon?: string | null;
122
+ /**
123
+ * - Hover text; true = the accessible name
124
+ */
125
+ title?: string | true | null;
126
+ /**
127
+ * - A primary-coloured ring (default false)
128
+ */
129
+ ring?: boolean;
130
+ /**
131
+ * - 0-7 to choose the tint; default is a hash of the name
132
+ */
133
+ tone?: number | null;
134
+ /**
135
+ * - aria-hidden: the name is written next to it (default false)
136
+ */
137
+ decorative?: boolean;
138
+ };
139
+ /**
140
+ * The handle E.avatar() returns. `options`, `initials`, `tone` and `label` are read only.
141
+ */
142
+ export type AvatarHandle = {
143
+ /**
144
+ * - The avatar element
145
+ */
146
+ element: HTMLElement;
147
+ /**
148
+ * - The options in force
149
+ */
150
+ options: AvatarOptions;
151
+ /**
152
+ * - The initials drawn ('' when an icon is shown)
153
+ */
154
+ initials: string;
155
+ /**
156
+ * - The tone 0-7, or null with nothing to hash
157
+ */
158
+ tone: number | null;
159
+ /**
160
+ * - The accessible name, e.g. 'Jane Smith (online)'
161
+ */
162
+ label: string;
163
+ /**
164
+ * - Merge options and redraw
165
+ */
166
+ update: (options?: AvatarOptions) => AvatarHandle;
167
+ /**
168
+ * - Restore the element's previous children, classes and attributes
169
+ */
170
+ destroy: () => HTMLElement;
171
+ };
172
+ /**
173
+ * `E.avatar` - the factory with `initials`, `tone`, `get` and `scan`.
174
+ */
175
+ export type AvatarStatic = typeof avatar;
176
+ /**
177
+ * One person in an avatar group.
178
+ */
179
+ export type AvatarPerson = {
180
+ name?: string;
181
+ src?: string;
182
+ status?: AvatarStatus;
183
+ /**
184
+ * - Makes the avatar a link
185
+ */
186
+ href?: string;
187
+ alt?: string;
188
+ icon?: string;
189
+ tone?: number;
190
+ /**
191
+ * - Hover text (default: the accessible name)
192
+ */
193
+ title?: string | true;
194
+ };
195
+ export type AvatarGroupOptions = {
196
+ /**
197
+ * - People, or plain names
198
+ */
199
+ people?: Array<AvatarPerson | string>;
200
+ /**
201
+ * - Show this many, then "+N"; null = everyone
202
+ */
203
+ max?: number | null;
204
+ /**
205
+ * - Size (default 'md')
206
+ */
207
+ size?: AvatarSize;
208
+ /**
209
+ * - Shape (default 'circle')
210
+ */
211
+ shape?: AvatarShape;
212
+ /**
213
+ * - 'none' | 'sm' | 'md' | 'lg', pixels, or any CSS length; null = the stylesheet's 25%
214
+ */
215
+ overlap?: "none" | "sm" | "md" | "lg" | number | string | null;
216
+ /**
217
+ * - Accessible name for the list
218
+ */
219
+ label?: string | null;
220
+ statusLabels?: Partial<Record<AvatarStatus, string>> | null;
221
+ /**
222
+ * - Called when "+N" is pressed, instead of the popover
223
+ */
224
+ onMore?: ((hidden: AvatarPerson[], event: MouseEvent) => void) | null;
225
+ /**
226
+ * - false: no popover, the hidden names go in the button's title (default true)
227
+ */
228
+ popover?: boolean;
229
+ /**
230
+ * - The "+N" button's accessible name (default '3 more: A, B and C')
231
+ */
232
+ moreLabel?: ((count: number, names: string[]) => string) | null;
233
+ };
234
+ /**
235
+ * The handle E.avatarGroup() returns. Everything but the methods is read only.
236
+ */
237
+ export type AvatarGroupHandle = {
238
+ /**
239
+ * - The <ul>
240
+ */
241
+ element: HTMLUListElement | HTMLOListElement;
242
+ options: AvatarGroupOptions;
243
+ people: AvatarPerson[];
244
+ /**
245
+ * - Drawn as avatars
246
+ */
247
+ shown: AvatarPerson[];
248
+ /**
249
+ * - Folded into "+N"
250
+ */
251
+ hidden: AvatarPerson[];
252
+ /**
253
+ * - The "+N" button, or null
254
+ */
255
+ more: HTMLButtonElement | null;
256
+ /**
257
+ * - The "+N" popover, or null
258
+ */
259
+ popover: import("./popover.js").PopoverInstance | null;
260
+ update: (options?: AvatarGroupOptions) => AvatarGroupHandle;
261
+ setPeople: (people: Array<AvatarPerson | string>) => AvatarGroupHandle;
262
+ /**
263
+ * - Remove everything and restore the host
264
+ */
265
+ destroy: () => HTMLElement;
266
+ };
267
+ /**
268
+ * `E.avatarGroup` - the factory with `get`.
269
+ */
270
+ export type AvatarGroupStatic = typeof avatarGroup;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The adapter between Domma's data and the binding engine.
3
+ *
4
+ * ── The contract, and the two ways it fails ──────────────────────────────────
5
+ *
6
+ * `domma-reactive` resolves every expression - `{{ }}`, `data-bind-*`,
7
+ * `data-if`, `data-on-*`, `data-model` - against ONE object, and writes back
8
+ * through that same object. Both halves matter, and getting either wrong fails
9
+ * SILENTLY, in two specific ways that this module exists to prevent:
10
+ *
11
+ * 1. A read-only snapshot swallows every `data-model` write. The control
12
+ * still looks correct, because what you see while typing is your own
13
+ * keystrokes, but the model never changes and nothing else bound to that
14
+ * field moves.
15
+ *
16
+ * 2. An object carrying no functions resolves no `data-on-*` handler. Every
17
+ * event binding logs "did not resolve to a function" and does nothing,
18
+ * while every other binding on the same element works perfectly.
19
+ *
20
+ * Both shipped, in `component-factory.js`, and were fixed in v0.37.0. The fix
21
+ * then existed twice - once there and once in `models.js` for `M.applyBindings`
22
+ * - in two slightly different shapes. This is that fix, once.
23
+ *
24
+ * ── Why a Proxy and not a merged object ──────────────────────────────────────
25
+ *
26
+ * Because reads must stay LIVE. A component's data is a snapshot, but
27
+ * `M.applyBindings` resolves against `model.tracked()`, where every read
28
+ * registers a dependency and every write routes through `set()`. Copying that
29
+ * into a plain object would flatten it into a snapshot and lose both halves.
30
+ *
31
+ * @module binding-source
32
+ */
33
+ /**
34
+ * Build the object the binding engine reads from and writes through.
35
+ *
36
+ * @template {object} T
37
+ * @param {T} primary Reads resolve here first; writes land here.
38
+ * For `M.applyBindings` this is a model's
39
+ * `tracked()` view, which is what makes a
40
+ * write reach the model.
41
+ * @param {object} [options]
42
+ * @param {Record<string, any>} [options.fallback] Consulted only when `primary` has no such
43
+ * key. Event handlers live here, so a data
44
+ * field of the same name always wins - a
45
+ * template mostly renders data, and a method
46
+ * quietly shadowing a rendered value is the
47
+ * worse failure.
48
+ * @param {(key: string, value: any) => void} [options.onWrite] Called `(key, value)` after a write lands
49
+ * on `primary`. Used where `primary` is a
50
+ * snapshot that cannot route the write
51
+ * itself, so the model has to be told.
52
+ * @returns {T} `primary` itself when there is nothing to layer, otherwise a
53
+ * Proxy over it.
54
+ */
55
+ export function createBindingSource<T extends unknown>(primary: T, { fallback, onWrite }?: {
56
+ fallback?: Record<string, any>;
57
+ onWrite?: (key: string, value: any) => void;
58
+ }): T;
@@ -0,0 +1,2 @@
1
+ /** Painted butterfly silhouette; size is the fully open wingspan in pixels. */
2
+ export function drawIllustratedButterfly(ctx: any, b: any): void;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Build and register a Custom Element class from a component definition.
3
+ *
4
+ * @template {Record<string, any>} [TData=Record<string, any>]
5
+ * @template {Record<string, any>} [TProps=Record<string, any>]
6
+ * @param {string} tagName Custom element tag (must contain a hyphen, or `domma-` is prefixed)
7
+ * @param {ComponentDefinition<TData, TProps>} definition Component definition object
8
+ * @returns {typeof DommaElement|undefined} The element class, or undefined when the tag is already registered
9
+ */
10
+ export function createComponent<TData extends Record<string, any> = Record<string, any>, TProps extends Record<string, any> = Record<string, any>>(tagName: string, definition: ComponentDefinition<TData, TProps>): typeof DommaElement | undefined;
11
+ export namespace components {
12
+ /**
13
+ * Define and register a new component.
14
+ *
15
+ * @template {Record<string, any>} [TData=Record<string, any>]
16
+ * @template {Record<string, any>} [TProps=Record<string, any>]
17
+ * @param {string} tagName Custom element tag name
18
+ * @param {ComponentDefinition<TData, TProps>} definition Component definition
19
+ * @returns {typeof DommaElement|undefined} The element class, or undefined when the tag is already registered
20
+ */
21
+ function define<TData extends Record<string, any> = Record<string, any>, TProps extends Record<string, any> = Record<string, any>>(tagName: string, definition: ComponentDefinition<TData, TProps>): typeof DommaElement | undefined;
22
+ /**
23
+ * Returns true if a component with this tag name has been registered.
24
+ * @param {string} tagName
25
+ * @returns {boolean}
26
+ */
27
+ function has(tagName: string): boolean;
28
+ /**
29
+ * Returns a copy of the component registry (for tooling / inspection).
30
+ * @returns {Map<string, ComponentDefinition>}
31
+ */
32
+ function registry(): Map<string, ComponentDefinition>;
33
+ const templateCache: Map<string, string>;
34
+ }
35
+ /**
36
+ * Valid primitive type tokens for component props.
37
+ */
38
+ export type PropType = "string" | "number" | "boolean" | "array" | "object" | "any";
39
+ /**
40
+ * A declared prop: an HTML attribute coerced to a type. `number` -> Number (NaN -> null),
41
+ * `boolean` -> '' / 'true' are true, 'false' false; `array` / `object` -> JSON.parse (the raw
42
+ * string when it is not JSON); anything else stays a string.
43
+ */
44
+ export type PropDefinition = {
45
+ /**
46
+ * - Expected type - a token or an `M.types.*` constant
47
+ */
48
+ type?: PropType | ((value: any) => boolean);
49
+ /**
50
+ * - Marks the prop as required (documentation only - not enforced)
51
+ */
52
+ required?: boolean;
53
+ /**
54
+ * - Value used when the attribute is absent; a function is called for it
55
+ */
56
+ default?: any;
57
+ };
58
+ /**
59
+ * `this` inside a component's hooks, computed properties and methods. Computed properties are
60
+ * also on it as getters (`this.fullName`) and methods as bound functions (`this.save()`).
61
+ */
62
+ export type ComponentContext<TData extends Record<string, any> = Record<string, any>, TProps extends Record<string, any> = Record<string, any>> = {
63
+ /**
64
+ * - Live, read-tracked view of the reactive data; reads inside a computed register a dependency
65
+ */
66
+ data: TData;
67
+ /**
68
+ * - Resolved prop values after type coercion (a copy)
69
+ */
70
+ props: TProps;
71
+ /**
72
+ * - The Shadow DOM root of this component
73
+ */
74
+ root: ShadowRoot;
75
+ /**
76
+ * - The host Custom Element
77
+ */
78
+ el: HTMLElement;
79
+ /**
80
+ * - Batch-update reactive data fields; bound template text updates surgically, then `onUpdated` runs
81
+ */
82
+ set: (updates: Partial<TData>) => void;
83
+ };
84
+ /**
85
+ * A component definition for `Domma.component(tagName, definition)`.
86
+ */
87
+ export type ComponentDefinition<TData extends Record<string, any> = Record<string, any>, TProps extends Record<string, any> = Record<string, any>> = {
88
+ /**
89
+ * - Inline Mustache template string. Use `templateUrl` for non-trivial templates
90
+ */
91
+ template?: string;
92
+ /**
93
+ * - URL to an external HTML template file, fetched once and cached across all instances
94
+ */
95
+ templateUrl?: string;
96
+ /**
97
+ * - Declared HTML attributes (camelCase name, kebab-case attribute) with type coercion and defaults
98
+ */
99
+ props?: Record<string, PropDefinition>;
100
+ /**
101
+ * - Factory returning the component's initial reactive state; called once per instance. Declare every field here
102
+ */
103
+ data?: () => TData;
104
+ /**
105
+ * - Derived values, memoised and recalculated when a field they read changes; available in templates and as `this.name`
106
+ */
107
+ computed?: Record<string, (this: ComponentContext<TData, TProps>) => any>;
108
+ /**
109
+ * - Functions bound to the component context; callable as `this.name()` and from `data-on-*` bindings
110
+ */
111
+ methods?: Record<string, (this: ComponentContext<TData, TProps>, ...args: any[]) => any>;
112
+ /**
113
+ * - Scoped CSS injected into the component's Shadow DOM `<style>` block
114
+ */
115
+ style?: string;
116
+ /**
117
+ * - Called before the template is rendered. Data and props are available
118
+ */
119
+ onBeforeMount?: (this: ComponentContext<TData, TProps>) => void;
120
+ /**
121
+ * - Called after the template is rendered and bindings are established (again when the element is re-connected)
122
+ */
123
+ onMount?: (this: ComponentContext<TData, TProps>) => void;
124
+ /**
125
+ * - Called once per flush after any data change, and after a prop change re-renders
126
+ */
127
+ onUpdated?: (this: ComponentContext<TData, TProps>) => void;
128
+ /**
129
+ * - Called when the element is removed from the DOM, before clean-up
130
+ */
131
+ onBeforeUnmount?: (this: ComponentContext<TData, TProps>) => void;
132
+ /**
133
+ * - Called after the element is removed and cleaned up
134
+ */
135
+ onUnmount?: (this: ComponentContext<TData, TProps>) => void;
136
+ /**
137
+ * - Called when an observed attribute (prop) changes, with the camelCase prop name and the raw attribute values
138
+ */
139
+ onPropsChanged?: (this: ComponentContext<TData, TProps>, name: string, oldValue: string | null, newValue: string | null) => void;
140
+ };
141
+ /**
142
+ * Binding controller returned by `TemplateCompiler.compile()` (domma-reactive): surgical updates
143
+ * for bound fields, full re-renders for structural changes.
144
+ */
145
+ export type TemplateBindings = import("../vendor/domma-reactive.js").BindingController;
146
+ /**
147
+ * The `components` namespace (`Domma.components`).
148
+ */
149
+ export type Components = typeof components;
150
+ import { DommaElement } from './web-components/base/domma-element.js';
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Instances on an element, newest last.
3
+ * @param {Element} element
4
+ * @returns {Component[]}
5
+ */
6
+ export function instancesOf(element: Element): Component[];
7
+ /**
8
+ * The kind of an instance: a Component's `static componentName`, or a `componentName`
9
+ * on a plain handle (skeleton, avatar) that registered itself.
10
+ * @param {Object} instance
11
+ * @returns {string|undefined}
12
+ */
13
+ export function componentNameOf(instance: any): string | undefined;
14
+ /**
15
+ * The newest instance on an element, optionally of one component kind.
16
+ * @param {Element} element
17
+ * @param {string} [name] - componentName, e.g. 'slideover'
18
+ * @returns {Component|null}
19
+ */
20
+ export function instanceOf(element: Element, name?: string): Component | null;
21
+ /**
22
+ * Add an instance to the registry. Component does this itself; factories whose objects
23
+ * are not Components (wrappers, handles) call it so E.get finds them too.
24
+ * @param {Element} element
25
+ * @param {Object} instance
26
+ */
27
+ export function register(element: Element, instance: any): void;
28
+ /**
29
+ * @param {Element} element
30
+ * @param {Object} instance
31
+ */
32
+ export function unregister(element: Element, instance: any): void;
33
+ export default Component;
34
+ /**
35
+ * A component event handler: gets the same arguments as the matching `onX` option.
36
+ * Returning false from a handler of a `before...` event cancels it.
37
+ */
38
+ export type ComponentEventHandler = (...args: any[]) => any;
39
+ /**
40
+ * The instance type every component shares (the Component base class).
41
+ */
42
+ export type ComponentInstance = Component;
43
+ /**
44
+ * A component event handler: gets the same arguments as the matching `onX` option.
45
+ * Returning false from a handler of a `before...` event cancels it.
46
+ * @typedef {(...args: any[]) => any} ComponentEventHandler
47
+ */
48
+ /**
49
+ * The instance type every component shares (the Component base class).
50
+ * @typedef {Component} ComponentInstance
51
+ */
52
+ declare class Component {
53
+ /** Used in `dm:<componentName>:<event>`. Subclasses set it - class names do not survive minification. */
54
+ static componentName: string;
55
+ /**
56
+ * @param {string|Element|null} [selector] - CSS selector or the host element
57
+ * @param {Record<string, any>} [options]
58
+ */
59
+ constructor(selector?: string | Element | null, options?: Record<string, any>);
60
+ /** The DOM element this component is attached to. @type {HTMLElement|null} */
61
+ element: HTMLElement | null;
62
+ /** Component options (defaults merged with what was passed). @type {Record<string, any>} */
63
+ options: Record<string, any>;
64
+ /** @protected @type {{element: EventTarget, event: string, handler: EventListenerOrEventListenerObject}[]} */
65
+ protected _eventHandlers: {
66
+ element: EventTarget;
67
+ event: string;
68
+ handler: EventListenerOrEventListenerObject;
69
+ }[];
70
+ /** @protected @type {Record<string, ComponentEventHandler[]>} */
71
+ protected _listeners: Record<string, ComponentEventHandler[]>;
72
+ /**
73
+ * Listen for a component event. The handler gets the same arguments as the matching
74
+ * `onX` option. Returning false from a handler of a `before...` event cancels it.
75
+ * @param {string} event - Event name, e.g. 'open', 'change', 'beforeclose'
76
+ * @param {ComponentEventHandler} handler
77
+ * @returns {this}
78
+ */
79
+ on(event: string, handler: ComponentEventHandler): this;
80
+ /**
81
+ * Listen once.
82
+ * @param {string} event
83
+ * @param {ComponentEventHandler} handler
84
+ * @returns {this}
85
+ */
86
+ once(event: string, handler: ComponentEventHandler): this;
87
+ /**
88
+ * Stop listening. Without a handler, removes every listener for the event.
89
+ * @param {string} event
90
+ * @param {ComponentEventHandler} [handler]
91
+ * @returns {this}
92
+ */
93
+ off(event: string, handler?: ComponentEventHandler): this;
94
+ /**
95
+ * Call the .on() listeners for an event.
96
+ * @param {string} event
97
+ * @param {...*} args
98
+ * @returns {boolean} false if a listener returned false
99
+ * @protected
100
+ */
101
+ protected _notify(event: string, ...args: any[]): boolean;
102
+ /**
103
+ * .on() listeners plus the `dm:<component>:<event>` DOM event - not the onX option.
104
+ * @param {string} event
105
+ * @param {...*} args
106
+ * @returns {boolean} false if a listener returned false or a DOM listener called preventDefault()
107
+ * @protected
108
+ */
109
+ protected _emit(event: string, ...args: any[]): boolean;
110
+ /**
111
+ * Fire an event the whole way: the `onX` option (called as `this.options.onX(...)` has
112
+ * always been called), then .on() listeners and the DOM event.
113
+ * @param {string} event - e.g. 'change' for onChange, 'beforeClose' or 'beforeclose' for onBeforeClose
114
+ * @param {...*} args
115
+ * @returns {*} the option's return value, or false when anything cancelled
116
+ * @protected
117
+ */
118
+ protected _fire(event: string, ...args: any[]): any;
119
+ /**
120
+ * The onX option for a lower-case event name ('beforeclose' -> onBeforeClose).
121
+ * @protected
122
+ * @param {string} key
123
+ * @returns {*}
124
+ */
125
+ protected _optionFor(key: string): any;
126
+ /**
127
+ * close() without the cancelable `beforeclose` - for destroy() and teardown that must
128
+ * not be refused. Still calls `this.close()` by name, so a patched close runs too.
129
+ * @param {...*} args - passed to close()
130
+ * @returns {*} close()'s return value
131
+ * @protected
132
+ */
133
+ protected _forcedClose(...args: any[]): any;
134
+ _forceClose: boolean;
135
+ /**
136
+ * The cancelable `beforeclose` an overlay's close() asks first. Skipped (true) while
137
+ * `_forcedClose()` runs.
138
+ * @param {...*} args - the same arguments onClose gets
139
+ * @returns {boolean} false when a handler refused
140
+ * @protected
141
+ */
142
+ protected _mayClose(...args: any[]): boolean;
143
+ /**
144
+ * Update component options at runtime
145
+ * @param {Record<string, any>} newOptions - New options to merge
146
+ * @returns {this} The component instance for chaining
147
+ */
148
+ setOptions(newOptions: Record<string, any>): this;
149
+ /**
150
+ * addEventListener that destroy() undoes.
151
+ * @protected
152
+ * @param {EventTarget} element
153
+ * @param {string} event
154
+ * @param {EventListenerOrEventListenerObject} handler
155
+ */
156
+ protected _addEventListener(element: EventTarget, event: string, handler: EventListenerOrEventListenerObject): void;
157
+ /**
158
+ * Destroy the component and clean up its event listeners.
159
+ * @returns {void}
160
+ */
161
+ destroy(): void;
162
+ }