domma-js 0.56.0 → 0.58.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.
- package/README.md +2 -2
- package/assets/types/generated/public/assets/flags/africa.d.ts +6 -0
- package/assets/types/generated/public/assets/flags/americas.d.ts +6 -0
- package/assets/types/generated/public/assets/flags/asia.d.ts +6 -0
- package/assets/types/generated/public/assets/flags/europe.d.ts +9 -0
- package/assets/types/generated/public/assets/flags/index.d.ts +11 -0
- package/assets/types/generated/public/assets/flags/oceania.d.ts +2 -0
- package/assets/types/generated/public/assets/icons/buildings.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/code.d.ts +2 -0
- package/assets/types/generated/public/assets/icons/commerce.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/communication.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/devices.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/emojis.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/files.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/finance.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/forms.d.ts +5 -0
- package/assets/types/generated/public/assets/icons/health.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/index.d.ts +24 -0
- package/assets/types/generated/public/assets/icons/media.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/navigation.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/seasonal.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/social.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/sport.d.ts +6 -0
- package/assets/types/generated/public/assets/icons/status.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/transport.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/ui.d.ts +7 -0
- package/assets/types/generated/public/assets/icons/weather.d.ts +6 -0
- package/assets/types/generated/src/auth.d.ts +424 -0
- package/assets/types/generated/src/avatar.d.ts +270 -0
- package/assets/types/generated/src/binding-source.d.ts +58 -0
- package/assets/types/generated/src/butterfly-drawing.d.ts +2 -0
- package/assets/types/generated/src/component-factory.d.ts +150 -0
- package/assets/types/generated/src/component.d.ts +162 -0
- package/assets/types/generated/src/components/back-to-top.d.ts +150 -0
- package/assets/types/generated/src/components/badge.d.ts +208 -0
- package/assets/types/generated/src/components/card.d.ts +189 -0
- package/assets/types/generated/src/components/command-palette.d.ts +352 -0
- package/assets/types/generated/src/components/dropzone.d.ts +342 -0
- package/assets/types/generated/src/components/focus-trap.d.ts +238 -0
- package/assets/types/generated/src/components/loader.d.ts +133 -0
- package/assets/types/generated/src/components/modal.d.ts +339 -0
- package/assets/types/generated/src/components/range-slider.d.ts +267 -0
- package/assets/types/generated/src/components/shared.d.ts +91 -0
- package/assets/types/generated/src/components/split-pane.d.ts +239 -0
- package/assets/types/generated/src/components/toast.d.ts +284 -0
- package/assets/types/generated/src/components/tooltip.d.ts +200 -0
- package/assets/types/generated/src/components/virtual-list.d.ts +340 -0
- package/assets/types/generated/src/config.d.ts +193 -0
- package/assets/types/generated/src/context-cursor.d.ts +69 -0
- package/assets/types/generated/src/context-menu.d.ts +596 -0
- package/assets/types/generated/src/dates.d.ts +367 -0
- package/assets/types/generated/src/dom.d.ts +1221 -0
- package/assets/types/generated/src/effects.d.ts +1281 -0
- package/assets/types/generated/src/elements.d.ts +4994 -0
- package/assets/types/generated/src/escape.d.ts +5 -0
- package/assets/types/generated/src/flags-bundle.d.ts +4 -0
- package/assets/types/generated/src/flags.d.ts +338 -0
- package/assets/types/generated/src/forms.d.ts +1060 -0
- package/assets/types/generated/src/globals.d.ts +45 -0
- package/assets/types/generated/src/http.d.ts +131 -0
- package/assets/types/generated/src/i18n.d.ts +261 -0
- package/assets/types/generated/src/icons.d.ts +213 -0
- package/assets/types/generated/src/index.d.ts +249 -0
- package/assets/types/generated/src/input-group.d.ts +135 -0
- package/assets/types/generated/src/models.d.ts +968 -0
- package/assets/types/generated/src/popover.d.ts +413 -0
- package/assets/types/generated/src/router.d.ts +344 -0
- package/assets/types/generated/src/safe-url.d.ts +10 -0
- package/assets/types/generated/src/sanitize.d.ts +97 -0
- package/assets/types/generated/src/schema-builder.d.ts +420 -0
- package/assets/types/generated/src/skeleton.d.ts +135 -0
- package/assets/types/generated/src/smooth-caret.d.ts +61 -0
- package/assets/types/generated/src/sortable.d.ts +368 -0
- package/assets/types/generated/src/storage.d.ts +93 -0
- package/assets/types/generated/src/tables.d.ts +901 -0
- package/assets/types/generated/src/theme.d.ts +262 -0
- package/assets/types/generated/src/ticker-tape-drawing.d.ts +2 -0
- package/assets/types/generated/src/treeview.d.ts +504 -0
- package/assets/types/generated/src/utils.d.ts +1667 -0
- package/assets/types/generated/src/web-components/base/domma-element.d.ts +134 -0
- package/assets/types/generated/src/web-components/index.d.ts +14 -0
- package/assets/types/generated/vendor/domma-reactive.d.ts +587 -0
- package/assets/types/index.d.ts +104 -226
- package/package.json +5 -2
- package/public/dist/bundles/domma-complete.css +20 -14
- package/public/dist/bundles/domma-data-focused.css +20 -14
- package/public/dist/bundles/domma-essentials.css +20 -14
- package/public/dist/bundles/domma-full.css +20 -14
- package/public/dist/bundles/domma-minimal.css +8 -8
- package/public/dist/domma-flags.esm.js +3 -3
- package/public/dist/domma-flags.esm.js.map +1 -1
- package/public/dist/domma-flags.min.js +3 -3
- package/public/dist/domma-flags.min.js.map +1 -1
- package/public/dist/domma-syntax.min.js +3 -3
- package/public/dist/domma.css +3 -3
- package/public/dist/domma.esm.js +5 -5
- package/public/dist/domma.esm.js.map +1 -1
- package/public/dist/domma.min.js +5 -5
- package/public/dist/domma.min.js.map +1 -1
- package/public/dist/elements.css +9 -3
- package/public/dist/grid.css +3 -3
- package/public/dist/syntax.css +3 -3
- package/public/dist/themes/domma-themes.css +3 -3
- package/templates/kickstart/.claude/snippets.md +1 -1
- package/templates/kickstart/CLAUDE.md +1 -1
- package/templates/kickstart/frontend/types/domma.d.ts +7 -4
- package/templates/kickstart-spa/.claude/snippets.md +1 -1
- package/assets/types/config.d.ts +0 -136
- package/assets/types/dates.d.ts +0 -209
- package/assets/types/dom.d.ts +0 -448
- package/assets/types/elements.d.ts +0 -1168
- package/assets/types/flags.d.ts +0 -130
- package/assets/types/http.d.ts +0 -97
- package/assets/types/i18n.d.ts +0 -99
- package/assets/types/icons.d.ts +0 -147
- package/assets/types/models.d.ts +0 -260
- package/assets/types/smooth-caret.d.ts +0 -12
- package/assets/types/storage.d.ts +0 -93
- package/assets/types/tables.d.ts +0 -327
- package/assets/types/theme.d.ts +0 -137
- package/assets/types/utils.d.ts +0 -675
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} BackToTopOptions
|
|
3
|
+
* @property {number|null} [showAfter] - Px scrolled before it shows (null: one viewport / container height)
|
|
4
|
+
* @property {number} [duration=300] - Scroll animation duration in ms (0 under reduced motion)
|
|
5
|
+
* @property {import('../elements.js').BackToTopPosition} [position='bottom-right'] - Button position
|
|
6
|
+
* @property {number|{bottom?: number, right?: number, left?: number}|null} [offset] - Px from the edges (null: the stylesheet's)
|
|
7
|
+
* @property {string|HTMLElement|null} [target] - Scroll container to watch (null: the window)
|
|
8
|
+
* @property {number|null} [zIndex] - z-index for the button
|
|
9
|
+
* @property {string} [label='Scroll back to top'] - aria-label when the button has none
|
|
10
|
+
* @property {((backToTop: BackToTopInstance) => void)|null} [onShow] - When the button shows
|
|
11
|
+
* @property {((backToTop: BackToTopInstance) => void)|null} [onHide] - When the button hides
|
|
12
|
+
* @property {((backToTop: BackToTopInstance) => void)|null} [onScroll] - When a scroll to the top starts
|
|
13
|
+
*/
|
|
14
|
+
/** @typedef {BackToTop} BackToTopInstance */
|
|
15
|
+
export class BackToTop extends Component {
|
|
16
|
+
static defaults: {
|
|
17
|
+
showAfter: any;
|
|
18
|
+
duration: number;
|
|
19
|
+
position: string;
|
|
20
|
+
offset: any;
|
|
21
|
+
target: any;
|
|
22
|
+
zIndex: any;
|
|
23
|
+
label: string;
|
|
24
|
+
onShow: any;
|
|
25
|
+
onHide: any;
|
|
26
|
+
onScroll: any;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('./shared.js').ComponentTarget} selector - A button / link / `.dm-back-to-top` to use; anything else adds a button to the body
|
|
30
|
+
* @param {BackToTopOptions} [options]
|
|
31
|
+
*/
|
|
32
|
+
constructor(selector: import("./shared.js").ComponentTarget, options?: BackToTopOptions);
|
|
33
|
+
_made: boolean;
|
|
34
|
+
_visible: boolean;
|
|
35
|
+
_scrolling: boolean;
|
|
36
|
+
/** The button element. @type {HTMLElement} */
|
|
37
|
+
button: HTMLElement;
|
|
38
|
+
_place(): void;
|
|
39
|
+
_container(): any;
|
|
40
|
+
_watch(): void;
|
|
41
|
+
_box: any;
|
|
42
|
+
_scrollTarget: any;
|
|
43
|
+
_onScroll: () => void;
|
|
44
|
+
_check(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Scroll to the top; `duration` overrides the option for this call.
|
|
47
|
+
* @param {number} [duration] - ms
|
|
48
|
+
* @returns {this}
|
|
49
|
+
*/
|
|
50
|
+
scroll(duration?: number): this;
|
|
51
|
+
/**
|
|
52
|
+
* Show the button.
|
|
53
|
+
* @returns {this}
|
|
54
|
+
*/
|
|
55
|
+
show(): this;
|
|
56
|
+
/**
|
|
57
|
+
* Hide the button.
|
|
58
|
+
* @returns {this}
|
|
59
|
+
*/
|
|
60
|
+
hide(): this;
|
|
61
|
+
/**
|
|
62
|
+
* Alias of show(), by name.
|
|
63
|
+
* @returns {this}
|
|
64
|
+
*/
|
|
65
|
+
open(...args: any[]): this;
|
|
66
|
+
/**
|
|
67
|
+
* Alias of hide(), by name.
|
|
68
|
+
* @returns {this}
|
|
69
|
+
*/
|
|
70
|
+
close(...args: any[]): this;
|
|
71
|
+
/**
|
|
72
|
+
* Toggle button visibility.
|
|
73
|
+
* @returns {this}
|
|
74
|
+
*/
|
|
75
|
+
toggle(): this;
|
|
76
|
+
/** @returns {boolean} */
|
|
77
|
+
isVisible(): boolean;
|
|
78
|
+
/** @returns {boolean} */
|
|
79
|
+
isOpen(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The button element.
|
|
82
|
+
* @returns {HTMLElement}
|
|
83
|
+
*/
|
|
84
|
+
getButton(): HTMLElement;
|
|
85
|
+
/**
|
|
86
|
+
* @param {number|string|null} value - Px; null or '' for one viewport / container height
|
|
87
|
+
* @returns {this}
|
|
88
|
+
*/
|
|
89
|
+
setShowAfter(value: number | string | null): this;
|
|
90
|
+
/**
|
|
91
|
+
* @param {import('../elements.js').BackToTopPosition} position
|
|
92
|
+
* @returns {this}
|
|
93
|
+
*/
|
|
94
|
+
setPosition(position: import("../elements.js").BackToTopPosition): this;
|
|
95
|
+
/**
|
|
96
|
+
* @param {BackToTopOptions['offset']} offset
|
|
97
|
+
* @returns {this}
|
|
98
|
+
*/
|
|
99
|
+
setOffset(offset: BackToTopOptions["offset"]): this;
|
|
100
|
+
_applyOptions(): void;
|
|
101
|
+
}
|
|
102
|
+
export default BackToTop;
|
|
103
|
+
export type BackToTopOptions = {
|
|
104
|
+
/**
|
|
105
|
+
* - Px scrolled before it shows (null: one viewport / container height)
|
|
106
|
+
*/
|
|
107
|
+
showAfter?: number | null;
|
|
108
|
+
/**
|
|
109
|
+
* - Scroll animation duration in ms (0 under reduced motion)
|
|
110
|
+
*/
|
|
111
|
+
duration?: number;
|
|
112
|
+
/**
|
|
113
|
+
* - Button position
|
|
114
|
+
*/
|
|
115
|
+
position?: import("../elements.js").BackToTopPosition;
|
|
116
|
+
/**
|
|
117
|
+
* - Px from the edges (null: the stylesheet's)
|
|
118
|
+
*/
|
|
119
|
+
offset?: number | {
|
|
120
|
+
bottom?: number;
|
|
121
|
+
right?: number;
|
|
122
|
+
left?: number;
|
|
123
|
+
} | null;
|
|
124
|
+
/**
|
|
125
|
+
* - Scroll container to watch (null: the window)
|
|
126
|
+
*/
|
|
127
|
+
target?: string | HTMLElement | null;
|
|
128
|
+
/**
|
|
129
|
+
* - z-index for the button
|
|
130
|
+
*/
|
|
131
|
+
zIndex?: number | null;
|
|
132
|
+
/**
|
|
133
|
+
* - aria-label when the button has none
|
|
134
|
+
*/
|
|
135
|
+
label?: string;
|
|
136
|
+
/**
|
|
137
|
+
* - When the button shows
|
|
138
|
+
*/
|
|
139
|
+
onShow?: ((backToTop: BackToTopInstance) => void) | null;
|
|
140
|
+
/**
|
|
141
|
+
* - When the button hides
|
|
142
|
+
*/
|
|
143
|
+
onHide?: ((backToTop: BackToTopInstance) => void) | null;
|
|
144
|
+
/**
|
|
145
|
+
* - When a scroll to the top starts
|
|
146
|
+
*/
|
|
147
|
+
onScroll?: ((backToTop: BackToTopInstance) => void) | null;
|
|
148
|
+
};
|
|
149
|
+
export type BackToTopInstance = BackToTop;
|
|
150
|
+
import Component from '../component.js';
|