@syware/jlib 0.12.1 → 0.13.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/dist/atoms/jl-avatar.css.js +1 -1
- package/dist/atoms/jl-avatar.js +1 -8
- package/dist/atoms/jl-button.css.js +1 -1
- package/dist/atoms/jl-button.js +4 -6
- package/dist/atoms/jl-checkbox.css.js +1 -1
- package/dist/atoms/jl-checkbox.js +8 -10
- package/dist/atoms/jl-chip.css.js +1 -1
- package/dist/atoms/jl-chip.js +3 -11
- package/dist/atoms/jl-divider.css.js +1 -1
- package/dist/atoms/jl-divider.js +1 -5
- package/dist/atoms/jl-icon.css.js +1 -1
- package/dist/atoms/jl-icon.d.ts +2 -0
- package/dist/atoms/jl-icon.js +5 -1
- package/dist/atoms/jl-input.d.ts +7 -2
- package/dist/atoms/jl-input.js +36 -31
- package/dist/atoms/jl-link.css.js +1 -1
- package/dist/atoms/jl-link.js +3 -6
- package/dist/atoms/jl-rating.css.js +1 -1
- package/dist/atoms/jl-rating.d.ts +2 -2
- package/dist/atoms/jl-rating.js +17 -35
- package/dist/atoms/jl-select.d.ts +8 -3
- package/dist/atoms/jl-select.js +26 -13
- package/dist/atoms/jl-skeleton.d.ts +1 -0
- package/dist/atoms/jl-skeleton.js +4 -1
- package/dist/atoms/jl-slider.d.ts +4 -0
- package/dist/atoms/jl-slider.js +29 -15
- package/dist/atoms/jl-switch.css.js +1 -1
- package/dist/atoms/jl-switch.js +2 -8
- package/dist/atoms/jl-textarea.css.js +1 -1
- package/dist/atoms/jl-textarea.d.ts +4 -5
- package/dist/atoms/jl-textarea.js +15 -30
- package/dist/lib/calendar.js +3 -2
- package/dist/lib/floating.d.ts +10 -0
- package/dist/lib/floating.js +27 -8
- package/dist/lib/flow.d.ts +7 -3
- package/dist/lib/flow.js +19 -8
- package/dist/lib/indicator.d.ts +16 -0
- package/dist/lib/indicator.js +32 -6
- package/dist/lib/intl.d.ts +6 -0
- package/dist/lib/intl.js +19 -0
- package/dist/lib/palette.js +1 -6
- package/dist/lib/table.d.ts +14 -2
- package/dist/lib/table.js +50 -39
- package/dist/molecules/jl-accordion-item.css.js +1 -1
- package/dist/molecules/jl-accordion-item.js +1 -5
- package/dist/molecules/jl-account-button.css.js +1 -1
- package/dist/molecules/jl-account-button.js +1 -5
- package/dist/molecules/jl-alert.css.js +1 -1
- package/dist/molecules/jl-alert.d.ts +5 -5
- package/dist/molecules/jl-alert.js +4 -13
- package/dist/molecules/jl-avatar-group.d.ts +7 -5
- package/dist/molecules/jl-avatar-group.js +15 -5
- package/dist/molecules/jl-breadcrumb.d.ts +7 -4
- package/dist/molecules/jl-breadcrumb.js +32 -8
- package/dist/molecules/jl-calendar.d.ts +12 -3
- package/dist/molecules/jl-calendar.js +79 -48
- package/dist/molecules/jl-card.css.js +1 -1
- package/dist/molecules/jl-card.js +2 -8
- package/dist/molecules/jl-chip-group.css.js +1 -1
- package/dist/molecules/jl-chip-group.d.ts +6 -2
- package/dist/molecules/jl-chip-group.js +13 -18
- package/dist/molecules/jl-code-block.css.js +1 -1
- package/dist/molecules/jl-code-block.d.ts +7 -5
- package/dist/molecules/jl-code-block.js +19 -22
- package/dist/molecules/jl-combobox.css.js +1 -1
- package/dist/molecules/jl-combobox.d.ts +4 -0
- package/dist/molecules/jl-combobox.js +33 -19
- package/dist/molecules/jl-date-picker.d.ts +6 -0
- package/dist/molecules/jl-date-picker.js +29 -9
- package/dist/molecules/jl-empty.css.js +1 -1
- package/dist/molecules/jl-empty.js +4 -19
- package/dist/molecules/jl-field.css.js +1 -1
- package/dist/molecules/jl-field.d.ts +7 -1
- package/dist/molecules/jl-field.js +35 -23
- package/dist/molecules/jl-file-drop.css.js +1 -1
- package/dist/molecules/jl-file-drop.js +1 -3
- package/dist/molecules/jl-input-list.css.js +1 -1
- package/dist/molecules/jl-input-list.d.ts +12 -1
- package/dist/molecules/jl-input-list.js +81 -51
- package/dist/molecules/jl-list-item.css.js +1 -1
- package/dist/molecules/jl-list-item.d.ts +3 -1
- package/dist/molecules/jl-list-item.js +26 -27
- package/dist/molecules/jl-load-state.css.js +1 -1
- package/dist/molecules/jl-load-state.d.ts +6 -1
- package/dist/molecules/jl-load-state.js +15 -18
- package/dist/molecules/jl-menu.d.ts +1 -0
- package/dist/molecules/jl-menu.js +9 -2
- package/dist/molecules/jl-pagination.css.js +1 -1
- package/dist/molecules/jl-pagination.d.ts +7 -1
- package/dist/molecules/jl-pagination.js +43 -35
- package/dist/molecules/jl-search.css.js +1 -1
- package/dist/molecules/jl-search.js +4 -12
- package/dist/molecules/jl-segmented.css.js +1 -1
- package/dist/molecules/jl-segmented.d.ts +4 -2
- package/dist/molecules/jl-segmented.js +19 -26
- package/dist/molecules/jl-stat.css.js +1 -1
- package/dist/molecules/jl-stat.js +2 -8
- package/dist/molecules/jl-steps.d.ts +10 -3
- package/dist/molecules/jl-steps.js +82 -49
- package/dist/molecules/jl-tabs.d.ts +5 -2
- package/dist/molecules/jl-tabs.js +31 -25
- package/dist/molecules/jl-tag-input.css.js +1 -1
- package/dist/molecules/jl-tag-input.d.ts +13 -1
- package/dist/molecules/jl-tag-input.js +57 -30
- package/dist/molecules/jl-timeline.css.js +1 -1
- package/dist/molecules/jl-timeline.d.ts +3 -1
- package/dist/molecules/jl-timeline.js +9 -14
- package/dist/molecules/jl-toast.css.js +1 -1
- package/dist/molecules/jl-toast.js +2 -10
- package/dist/molecules/jl-tooltip.d.ts +2 -1
- package/dist/molecules/jl-tooltip.js +11 -15
- package/dist/organisms/jl-command-palette.css.js +1 -1
- package/dist/organisms/jl-command-palette.d.ts +8 -1
- package/dist/organisms/jl-command-palette.js +73 -42
- package/dist/organisms/jl-confirm.css.js +1 -1
- package/dist/organisms/jl-confirm.js +1 -5
- package/dist/organisms/jl-dialog.css.js +1 -1
- package/dist/organisms/jl-dialog.js +1 -5
- package/dist/organisms/jl-drawer.css.js +1 -1
- package/dist/organisms/jl-drawer.js +1 -3
- package/dist/organisms/jl-flow.d.ts +18 -2
- package/dist/organisms/jl-flow.js +128 -44
- package/dist/organisms/jl-navbar.css.js +1 -1
- package/dist/organisms/jl-navbar.d.ts +1 -1
- package/dist/organisms/jl-navbar.js +3 -5
- package/dist/organisms/jl-page-header.css.js +1 -1
- package/dist/organisms/jl-page-header.js +1 -5
- package/dist/organisms/jl-page-outlet.d.ts +4 -3
- package/dist/organisms/jl-page-outlet.js +7 -8
- package/dist/organisms/jl-side-nav.css.js +1 -1
- package/dist/organisms/jl-side-nav.d.ts +9 -2
- package/dist/organisms/jl-side-nav.js +44 -16
- package/dist/organisms/jl-tab-bar.css.js +1 -1
- package/dist/organisms/jl-tab-bar.js +0 -2
- package/dist/organisms/jl-table.css.js +1 -1
- package/dist/organisms/jl-table.d.ts +18 -6
- package/dist/organisms/jl-table.js +91 -57
- package/dist/organisms/jl-tree.css.js +1 -1
- package/dist/organisms/jl-tree.d.ts +16 -13
- package/dist/organisms/jl-tree.js +72 -70
- package/package.json +1 -1
package/dist/atoms/jl-rating.js
CHANGED
|
@@ -11,14 +11,10 @@ import { Star } from "lucide";
|
|
|
11
11
|
import { jsx } from "@jadis/core/jsx-runtime";
|
|
12
12
|
// src/atoms/jl-rating.tsx
|
|
13
13
|
registerIcons({ star: Star });
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
md: 20,
|
|
17
|
-
sm: 16
|
|
18
|
-
};
|
|
14
|
+
var ICON_SIZE = 20;
|
|
15
|
+
var DEFAULT_ICON = "star";
|
|
19
16
|
var DEFAULT_MAX = 5;
|
|
20
17
|
var MAX_LIMIT = 10;
|
|
21
|
-
var NO_PREVIEW = 0;
|
|
22
18
|
/**
|
|
23
19
|
* A row of stars (or hearts, or any icon) to give a score: a click, the arrows or a digit set it, and choosing the
|
|
24
20
|
* score already given clears it. Hovering previews the score a click would give.
|
|
@@ -40,11 +36,8 @@ var JlRating = class extends JlFormControl {
|
|
|
40
36
|
this.reflect("readonly", value);
|
|
41
37
|
this._refs.slider.toggleAttribute("aria-readonly", value);
|
|
42
38
|
}, { attribute: "readonly" });
|
|
43
|
-
icon = this.useChange(
|
|
44
|
-
size = this.useChange("md", (value) => {
|
|
45
|
-
this.reflect("size", value);
|
|
46
|
-
this.renderIcons();
|
|
47
|
-
}, {
|
|
39
|
+
icon = this.useChange(DEFAULT_ICON, () => this.renderIcons(), { attribute: "icon" });
|
|
40
|
+
size = this.useChange("md", (value) => this.reflect("size", value), {
|
|
48
41
|
attribute: "size",
|
|
49
42
|
parse: oneOf(CONTROL_SIZES, "md")
|
|
50
43
|
});
|
|
@@ -61,8 +54,8 @@ var JlRating = class extends JlFormControl {
|
|
|
61
54
|
this._refs.slider.toggleAttribute("aria-invalid", value);
|
|
62
55
|
}, { attribute: "invalid" });
|
|
63
56
|
_state = {
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
drawnIcon: "",
|
|
58
|
+
formDisabled: false
|
|
66
59
|
};
|
|
67
60
|
_refs = this.useRefs((ref) => ({
|
|
68
61
|
icons: ref(".icons"),
|
|
@@ -89,8 +82,6 @@ var JlRating = class extends JlFormControl {
|
|
|
89
82
|
const slider = this._refs.slider;
|
|
90
83
|
this.on(slider, "keydown", (event) => this.onKey(event));
|
|
91
84
|
this.on(slider, "click", (event) => this.onChoose(event));
|
|
92
|
-
this.on(slider, "pointermove", (event) => this.onHover(event));
|
|
93
|
-
this.on(slider, "pointerleave", () => this.setPreview(NO_PREVIEW));
|
|
94
85
|
}
|
|
95
86
|
resetValue() {
|
|
96
87
|
this.value.set(clampedNumber(0, 0, MAX_LIMIT)(this.getAttribute("value")));
|
|
@@ -112,22 +103,12 @@ var JlRating = class extends JlFormControl {
|
|
|
112
103
|
onChoose(event) {
|
|
113
104
|
const chosen = this.iconValueAt(event);
|
|
114
105
|
if (chosen === null || !this.canChange()) return;
|
|
115
|
-
this.setPreview(NO_PREVIEW);
|
|
116
106
|
this.commit(ratingAfterChoice(this.current(), chosen));
|
|
117
107
|
}
|
|
118
|
-
onHover(event) {
|
|
119
|
-
if (!this.canChange()) return;
|
|
120
|
-
this.setPreview(this.iconValueAt(event) ?? NO_PREVIEW);
|
|
121
|
-
}
|
|
122
108
|
iconValueAt(event) {
|
|
123
109
|
const icon = event.target.closest("[data-value]");
|
|
124
110
|
return icon === null ? null : Number(icon.dataset.value);
|
|
125
111
|
}
|
|
126
|
-
setPreview(preview) {
|
|
127
|
-
if (preview === this._state.preview) return;
|
|
128
|
-
this._state.preview = preview;
|
|
129
|
-
this.renderValue();
|
|
130
|
-
}
|
|
131
112
|
/** The value as the scale shows it: never past its end. */
|
|
132
113
|
current() {
|
|
133
114
|
return Math.min(this.value.get(), this.max.get());
|
|
@@ -144,24 +125,26 @@ var JlRating = class extends JlFormControl {
|
|
|
144
125
|
renderLabel() {
|
|
145
126
|
this._refs.slider.setAttribute("aria-label", this.label.get() || jlText("rating"));
|
|
146
127
|
}
|
|
128
|
+
/** Draws the row of icons again only for another icon or another count. */
|
|
147
129
|
renderIcons() {
|
|
148
|
-
const name = this.icon.get()
|
|
149
|
-
const
|
|
150
|
-
const
|
|
130
|
+
const name = this.icon.get() || DEFAULT_ICON;
|
|
131
|
+
const max = this.max.get();
|
|
132
|
+
const row = this._refs.icons;
|
|
133
|
+
if (name === this._state.drawnIcon && row.childElementCount === max) return;
|
|
134
|
+
this._state.drawnIcon = name;
|
|
135
|
+
const icons = Array.from({ length: max }, (_, index) => /* @__PURE__ */ jsx("span", {
|
|
151
136
|
class: "icon",
|
|
152
137
|
"data-value": String(index + 1),
|
|
153
|
-
children: iconElement(name,
|
|
138
|
+
children: iconElement(name, ICON_SIZE)
|
|
154
139
|
}));
|
|
155
|
-
|
|
140
|
+
row.replaceChildren(...icons);
|
|
156
141
|
this.renderValue();
|
|
157
142
|
}
|
|
143
|
+
/** The score, in the icons and for screen readers; the score a pointer would give is the CSS's. */
|
|
158
144
|
renderValue() {
|
|
159
145
|
const value = this.current();
|
|
160
146
|
const max = this.max.get();
|
|
161
|
-
const
|
|
162
|
-
const shown = preview === NO_PREVIEW ? value : preview;
|
|
163
|
-
for (const icon of this._refs.icons.querySelectorAll("[data-value]")) icon.classList.toggle("on", Number(icon.dataset.value) <= shown);
|
|
164
|
-
this.reflect("previewing", preview !== NO_PREVIEW);
|
|
147
|
+
for (const icon of this._refs.icons.querySelectorAll("[data-value]")) icon.classList.toggle("on", Number(icon.dataset.value) <= value);
|
|
165
148
|
const slider = this._refs.slider;
|
|
166
149
|
slider.setAttribute("aria-valuenow", String(value));
|
|
167
150
|
slider.setAttribute("aria-valuemax", String(max));
|
|
@@ -184,7 +167,6 @@ var JlRating = class extends JlFormControl {
|
|
|
184
167
|
this.reflect("disabled", disabled);
|
|
185
168
|
this._refs.slider.tabIndex = off ? -1 : 0;
|
|
186
169
|
this._refs.slider.toggleAttribute("aria-disabled", off);
|
|
187
|
-
this.setPreview(NO_PREVIEW);
|
|
188
170
|
}
|
|
189
171
|
};
|
|
190
172
|
JlRating.register();
|
|
@@ -51,6 +51,7 @@ export declare class JlSelect<Value extends string = string> extends JlFormContr
|
|
|
51
51
|
}>>;
|
|
52
52
|
private readonly _form;
|
|
53
53
|
private _kept;
|
|
54
|
+
private readonly _drawn;
|
|
54
55
|
private readonly _refs;
|
|
55
56
|
focus(options?: FocusOptions): void;
|
|
56
57
|
templateHtml(): Node;
|
|
@@ -60,7 +61,9 @@ export declare class JlSelect<Value extends string = string> extends JlFormContr
|
|
|
60
61
|
/** The browser calls it for a disabled fieldset and for the element's own disabled attribute, even before render. */
|
|
61
62
|
protected setDisabledByForm(disabled: boolean): void;
|
|
62
63
|
private renderDisabled;
|
|
63
|
-
/** The
|
|
64
|
+
/** The `<option>` and `<optgroup>` the page wrote inside, used when `options` is empty. */
|
|
65
|
+
private lightOptions;
|
|
66
|
+
/** The options from `options`, or else copies of the page's own. */
|
|
64
67
|
private optionNodes;
|
|
65
68
|
private placeholderNodes;
|
|
66
69
|
/**
|
|
@@ -70,9 +73,11 @@ export declare class JlSelect<Value extends string = string> extends JlFormContr
|
|
|
70
73
|
private renderOptions;
|
|
71
74
|
/** Another value among the options drawn: only the option kept for an unknown value comes or goes. */
|
|
72
75
|
private renderChosen;
|
|
73
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Another placeholder: its own option is written, added or removed, the others left as they are. Only one that
|
|
78
|
+
* comes or goes can change the option shown.
|
|
79
|
+
*/
|
|
74
80
|
private renderPlaceholder;
|
|
75
|
-
private writePlaceholder;
|
|
76
81
|
/** The option kept for a value no option has goes once another value is chosen. */
|
|
77
82
|
private dropKept;
|
|
78
83
|
/**
|
package/dist/atoms/jl-select.js
CHANGED
|
@@ -21,6 +21,7 @@ var optionElement = (option) => /* @__PURE__ */ jsx("option", {
|
|
|
21
21
|
disabled: option.disabled === true,
|
|
22
22
|
children: option.label
|
|
23
23
|
});
|
|
24
|
+
var sameNodes = (nodes, others) => nodes.length === others.length && nodes.every((node, index) => node === others[index]);
|
|
24
25
|
var groupNodes = (group) => {
|
|
25
26
|
const options = group.options.map(optionElement);
|
|
26
27
|
return group.label === null ? options : [/* @__PURE__ */ jsx("optgroup", {
|
|
@@ -58,7 +59,7 @@ var JlSelect = class extends JlFormControl {
|
|
|
58
59
|
required = this.useChange(false, (value) => {
|
|
59
60
|
this._refs.native.required = value;
|
|
60
61
|
this.reflect("required", value);
|
|
61
|
-
this.
|
|
62
|
+
this.mirrorValidity(this._refs.native);
|
|
62
63
|
}, { attribute: "required" });
|
|
63
64
|
disabled = this.useChange(false, (value) => {
|
|
64
65
|
this.reflect("disabled", value);
|
|
@@ -71,6 +72,7 @@ var JlSelect = class extends JlFormControl {
|
|
|
71
72
|
}, { attribute: "invalid" });
|
|
72
73
|
_form = { disabled: false };
|
|
73
74
|
_kept;
|
|
75
|
+
_drawn = { light: [] };
|
|
74
76
|
_refs = this.useRefs((ref) => ({ native: ref("select") }));
|
|
75
77
|
focus(options) {
|
|
76
78
|
this._refs.native.focus(options);
|
|
@@ -99,7 +101,6 @@ var JlSelect = class extends JlFormControl {
|
|
|
99
101
|
this.value.set(value);
|
|
100
102
|
this.events.emit("change", value);
|
|
101
103
|
});
|
|
102
|
-
if (this.options.get().length > 0) return;
|
|
103
104
|
this.renderOptions();
|
|
104
105
|
}
|
|
105
106
|
resetValue() {
|
|
@@ -113,11 +114,15 @@ var JlSelect = class extends JlFormControl {
|
|
|
113
114
|
renderDisabled() {
|
|
114
115
|
this._refs.native.disabled = this.disabled.get() || this._form.disabled;
|
|
115
116
|
}
|
|
116
|
-
/** The
|
|
117
|
-
|
|
117
|
+
/** The `<option>` and `<optgroup>` the page wrote inside, used when `options` is empty. */
|
|
118
|
+
lightOptions() {
|
|
119
|
+
return this.options.get().length > 0 ? [] : [...this.querySelectorAll(LIGHT_OPTIONS)];
|
|
120
|
+
}
|
|
121
|
+
/** The options from `options`, or else copies of the page's own. */
|
|
122
|
+
optionNodes(light) {
|
|
118
123
|
const options = this.options.get();
|
|
119
124
|
if (options.length > 0) return groupOptions(options).flatMap(groupNodes);
|
|
120
|
-
return
|
|
125
|
+
return light.map((node) => node.cloneNode(true));
|
|
121
126
|
}
|
|
122
127
|
placeholderNodes() {
|
|
123
128
|
const placeholder = this.placeholder.get();
|
|
@@ -135,36 +140,43 @@ var JlSelect = class extends JlFormControl {
|
|
|
135
140
|
* inside an option, an option the page added and removed before its check ran.
|
|
136
141
|
*/
|
|
137
142
|
renderOptions() {
|
|
138
|
-
this.
|
|
143
|
+
const options = this.options.get();
|
|
144
|
+
const light = this.lightOptions();
|
|
145
|
+
if (options === this._drawn.options && sameNodes(light, this._drawn.light)) return;
|
|
146
|
+
this._drawn.options = options;
|
|
147
|
+
this._drawn.light = light;
|
|
148
|
+
this._refs.native.replaceChildren(...this.placeholderNodes(), ...this.optionNodes(light));
|
|
139
149
|
this._kept = void 0;
|
|
140
150
|
this.keepUnknownValue();
|
|
141
151
|
this.renderValue();
|
|
142
152
|
}
|
|
143
153
|
/** Another value among the options drawn: only the option kept for an unknown value comes or goes. */
|
|
144
154
|
renderChosen() {
|
|
155
|
+
if (this._drawn.options === void 0 || this.value.get() === this._drawn.value) return;
|
|
145
156
|
this.dropKept();
|
|
146
157
|
this.keepUnknownValue();
|
|
147
158
|
this.renderValue();
|
|
148
159
|
}
|
|
149
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Another placeholder: its own option is written, added or removed, the others left as they are. Only one that
|
|
162
|
+
* comes or goes can change the option shown.
|
|
163
|
+
*/
|
|
150
164
|
renderPlaceholder() {
|
|
151
|
-
this.writePlaceholder();
|
|
152
|
-
this.renderValue();
|
|
153
|
-
}
|
|
154
|
-
writePlaceholder() {
|
|
155
165
|
const native = this._refs.native;
|
|
156
166
|
const shown = native.querySelector(`:scope > option.${PLACEHOLDER_CLASS}`);
|
|
157
167
|
const placeholder = this.placeholder.get();
|
|
168
|
+
if (this._drawn.options === void 0 || shown === null && placeholder === "") return;
|
|
158
169
|
if (shown === null) {
|
|
159
170
|
native.prepend(...this.placeholderNodes());
|
|
171
|
+
this.renderValue();
|
|
160
172
|
return;
|
|
161
173
|
}
|
|
162
174
|
if (placeholder === "") {
|
|
163
175
|
shown.remove();
|
|
176
|
+
this.renderValue();
|
|
164
177
|
return;
|
|
165
178
|
}
|
|
166
|
-
if (shown.text
|
|
167
|
-
shown.text = placeholder;
|
|
179
|
+
if (shown.text !== placeholder) shown.text = placeholder;
|
|
168
180
|
}
|
|
169
181
|
/** The option kept for a value no option has goes once another value is chosen. */
|
|
170
182
|
dropKept() {
|
|
@@ -194,6 +206,7 @@ var JlSelect = class extends JlFormControl {
|
|
|
194
206
|
renderValue() {
|
|
195
207
|
const native = this._refs.native;
|
|
196
208
|
native.selectedIndex = this.shownIndex();
|
|
209
|
+
this._drawn.value = this.value.get();
|
|
197
210
|
this.reflect("placeholder-shown", native.selectedOptions[0]?.classList.contains(PLACEHOLDER_CLASS) === true);
|
|
198
211
|
this.internals.setFormValue(native.value);
|
|
199
212
|
this.mirrorValidity(native);
|
|
@@ -29,6 +29,7 @@ export declare class JlSkeleton extends JlElement {
|
|
|
29
29
|
private readonly _refs;
|
|
30
30
|
templateHtml(): Node;
|
|
31
31
|
templateCss(): string;
|
|
32
|
+
/** As many bones as lines (one for a block or a circle): only those missing are added, those too many removed. */
|
|
32
33
|
private renderBones;
|
|
33
34
|
private setLength;
|
|
34
35
|
}
|
|
@@ -46,9 +46,12 @@ var JlSkeleton = class extends JlElement {
|
|
|
46
46
|
templateCss() {
|
|
47
47
|
return css`${BASE_STYLES}${jl_skeleton_default}`;
|
|
48
48
|
}
|
|
49
|
+
/** As many bones as lines (one for a block or a circle): only those missing are added, those too many removed. */
|
|
49
50
|
renderBones() {
|
|
50
51
|
const count = this.shape.get() === "text" ? Math.round(this.lines.get()) : 1;
|
|
51
|
-
this._refs.bones
|
|
52
|
+
const bones = this._refs.bones;
|
|
53
|
+
for (const bone of [...bones.children].slice(count)) bone.remove();
|
|
54
|
+
bones.append(...Array.from({ length: count - bones.childElementCount }, () => /* @__PURE__ */ jsx("span", { class: "bone" })));
|
|
52
55
|
}
|
|
53
56
|
setLength(property, value) {
|
|
54
57
|
const length = cssLength(value);
|
|
@@ -47,6 +47,7 @@ export declare class JlSlider extends JlFormControl {
|
|
|
47
47
|
set(setter: boolean | ((prevState: boolean) => boolean)): void;
|
|
48
48
|
}>>;
|
|
49
49
|
private readonly _form;
|
|
50
|
+
private readonly _ticks;
|
|
50
51
|
private readonly _refs;
|
|
51
52
|
focus(options?: FocusOptions): void;
|
|
52
53
|
templateHtml(): Node;
|
|
@@ -61,5 +62,8 @@ export declare class JlSlider extends JlFormControl {
|
|
|
61
62
|
private renderRange;
|
|
62
63
|
/** The fill, the shown number and the form's value, from the value the native input kept. */
|
|
63
64
|
private renderPosition;
|
|
65
|
+
/** Makes the ticks once per list of marks, every readable one, then places them. */
|
|
64
66
|
private renderMarks;
|
|
67
|
+
/** Puts each tick where its value sits between the bounds; one outside them is hidden. */
|
|
68
|
+
private placeMarks;
|
|
65
69
|
}
|
package/dist/atoms/jl-slider.js
CHANGED
|
@@ -12,6 +12,13 @@ var DEFAULT_MAX = 100;
|
|
|
12
12
|
var DEFAULT_STEP = 1;
|
|
13
13
|
var DEFAULT_VALUE = 0;
|
|
14
14
|
var EDGES = /* @__PURE__ */ new Map([[0, "start"], [1, "end"]]);
|
|
15
|
+
var tickElement = (mark) => /* @__PURE__ */ jsxs("span", {
|
|
16
|
+
class: "mark",
|
|
17
|
+
children: [/* @__PURE__ */ jsx("span", { class: "tick" }), mark.label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
18
|
+
class: "mark-label",
|
|
19
|
+
children: mark.label
|
|
20
|
+
})]
|
|
21
|
+
});
|
|
15
22
|
/**
|
|
16
23
|
* A number picked by dragging along a track, on the browser's own range input: the arrow keys, Page Up/Down,
|
|
17
24
|
* Home and End move it. The track fills in the accent colour up to the thumb.
|
|
@@ -40,6 +47,7 @@ var JlSlider = class extends JlFormControl {
|
|
|
40
47
|
this.renderDisabled();
|
|
41
48
|
}, { attribute: "disabled" });
|
|
42
49
|
_form = { disabled: false };
|
|
50
|
+
_ticks = { ticks: [] };
|
|
43
51
|
_refs = this.useRefs((ref) => ({
|
|
44
52
|
marks: ref(".marks"),
|
|
45
53
|
native: ref("input"),
|
|
@@ -108,7 +116,7 @@ var JlSlider = class extends JlFormControl {
|
|
|
108
116
|
/** New bounds move the thumb and the marks. */
|
|
109
117
|
renderRange() {
|
|
110
118
|
this.render();
|
|
111
|
-
this.
|
|
119
|
+
this.placeMarks();
|
|
112
120
|
}
|
|
113
121
|
/** The fill, the shown number and the form's value, from the value the native input kept. */
|
|
114
122
|
renderPosition() {
|
|
@@ -118,26 +126,32 @@ var JlSlider = class extends JlFormControl {
|
|
|
118
126
|
this._refs.output.textContent = native.value;
|
|
119
127
|
this.internals.setFormValue(native.value);
|
|
120
128
|
}
|
|
129
|
+
/** Makes the ticks once per list of marks, every readable one, then places them. */
|
|
121
130
|
renderMarks() {
|
|
131
|
+
const from = this.marks.get();
|
|
132
|
+
if (from === this._ticks.from) return;
|
|
133
|
+
const marks = marksOf(from, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
134
|
+
this._ticks.from = from;
|
|
135
|
+
this._ticks.ticks = marks.map((mark) => ({
|
|
136
|
+
element: tickElement(mark),
|
|
137
|
+
mark
|
|
138
|
+
}));
|
|
139
|
+
this._refs.marks.replaceChildren(...this._ticks.ticks.map((tick) => tick.element));
|
|
140
|
+
this.placeMarks();
|
|
141
|
+
}
|
|
142
|
+
/** Puts each tick where its value sits between the bounds; one outside them is hidden. */
|
|
143
|
+
placeMarks() {
|
|
122
144
|
const min = this.min.get();
|
|
123
145
|
const max = this.max.get();
|
|
124
|
-
const
|
|
125
|
-
const container = this._refs.marks;
|
|
126
|
-
container.hidden = marks.length === 0;
|
|
127
|
-
this.reflect("has-labels", marks.some((mark) => mark.label !== void 0));
|
|
128
|
-
container.replaceChildren(...marks.map((mark) => {
|
|
129
|
-
const element = /* @__PURE__ */ jsxs("span", {
|
|
130
|
-
class: "mark",
|
|
131
|
-
children: [/* @__PURE__ */ jsx("span", { class: "tick" }), mark.label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
132
|
-
class: "mark-label",
|
|
133
|
-
children: mark.label
|
|
134
|
-
})]
|
|
135
|
-
});
|
|
146
|
+
for (const { element, mark } of this._ticks.ticks) {
|
|
136
147
|
const fraction = fractionOf(mark.value, min, max);
|
|
148
|
+
element.hidden = mark.value < min || mark.value > max;
|
|
137
149
|
element.style.setProperty("--at", String(fraction));
|
|
138
150
|
setOrRemove(element, "data-edge", EDGES.get(fraction) ?? "");
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
}
|
|
152
|
+
const shown = this._ticks.ticks.filter((tick) => !tick.element.hidden);
|
|
153
|
+
this._refs.marks.hidden = shown.length === 0;
|
|
154
|
+
this.reflect("has-labels", shown.some((tick) => tick.mark.label !== void 0));
|
|
141
155
|
}
|
|
142
156
|
};
|
|
143
157
|
JlSlider.register();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/atoms/jl-switch.css?inline
|
|
2
|
-
var jl_switch_default = ":host{vertical-align:middle;--track-width:36px;--track-height:20px;--thumb:14px;display:inline-flex}:host([size=sm]){--track-width:28px;--track-height:16px;--thumb:10px}.wrap{color:var(--jl-text);font-size:var(--jl-font-md);cursor:pointer;align-items:flex-start;gap:10px;line-height:20px;display:inline-flex}:host([size=sm]) .wrap{font-size:var(--jl-font-sm)}.track{width:var(--track-width);height:var(--track-height);margin-top:calc((20px - var(--track-height)) / 2);flex:none;display:inline-flex;position:relative}.native{border:1px solid var(--jl-line-strong);border-radius:var(--jl-radius-pill);background:var(--jl-surface-3);width:100%;height:100%;cursor:inherit;appearance:none;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease), box-shadow var(--jl-fast) var(--jl-ease);margin:0;position:absolute;inset:0}.wrap:hover .native:not(:disabled){border-color:color-mix(in srgb, var(--jl-line-strong) 60%, var(--jl-text) 18%)}.native:checked{border-color:var(--jl-accent);background:var(--jl-accent)}.wrap:hover .native:checked:not(:disabled){border-color:var(--jl-accent-strong);background:var(--jl-accent-strong)}.thumb{top:calc((var(--track-height) - var(--thumb)) / 2);left:calc((var(--track-height) - var(--thumb)) / 2);width:var(--thumb);height:var(--thumb);background:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease), background var(--jl-fast) var(--jl-ease);border-radius:50%;position:absolute}.native:checked+.thumb{background:var(--jl-on-accent);transform:translateX(calc(var(--track-width) - var(--track-height)))}.text{align-self:baseline;gap:2px;display:grid}.description{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:18px}:host([disabled]) .wrap,:host(:disabled) .wrap{cursor:not-allowed;opacity:.5}";
|
|
2
|
+
var jl_switch_default = ":host{vertical-align:middle;--track-width:36px;--track-height:20px;--thumb:14px;display:inline-flex}:host([size=sm]){--track-width:28px;--track-height:16px;--thumb:10px}.wrap{color:var(--jl-text);font-size:var(--jl-font-md);cursor:pointer;align-items:flex-start;gap:10px;line-height:20px;display:inline-flex}:host([size=sm]) .wrap{font-size:var(--jl-font-sm)}.track{width:var(--track-width);height:var(--track-height);margin-top:calc((20px - var(--track-height)) / 2);flex:none;display:inline-flex;position:relative}.native{border:1px solid var(--jl-line-strong);border-radius:var(--jl-radius-pill);background:var(--jl-surface-3);width:100%;height:100%;cursor:inherit;appearance:none;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease), box-shadow var(--jl-fast) var(--jl-ease);margin:0;position:absolute;inset:0}.wrap:hover .native:not(:disabled){border-color:color-mix(in srgb, var(--jl-line-strong) 60%, var(--jl-text) 18%)}.native:checked{border-color:var(--jl-accent);background:var(--jl-accent)}.wrap:hover .native:checked:not(:disabled){border-color:var(--jl-accent-strong);background:var(--jl-accent-strong)}.thumb{top:calc((var(--track-height) - var(--thumb)) / 2);left:calc((var(--track-height) - var(--thumb)) / 2);width:var(--thumb);height:var(--thumb);background:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease), background var(--jl-fast) var(--jl-ease);border-radius:50%;position:absolute}.native:checked+.thumb{background:var(--jl-on-accent);transform:translateX(calc(var(--track-width) - var(--track-height)))}.text{align-self:baseline;gap:2px;display:grid}.label:empty,.description:empty{display:none}.description{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:18px}:host([disabled]) .wrap,:host(:disabled) .wrap{cursor:not-allowed;opacity:.5}";
|
|
3
3
|
export { jl_switch_default as default };
|
package/dist/atoms/jl-switch.js
CHANGED
|
@@ -19,13 +19,11 @@ var JlSwitch = class extends JlFormControl {
|
|
|
19
19
|
/** The text beside the switch. */
|
|
20
20
|
label = this.useChange("", (value) => {
|
|
21
21
|
this._refs.label.textContent = value;
|
|
22
|
-
this._refs.label.hidden = value === "";
|
|
23
22
|
this.renderText();
|
|
24
23
|
}, { attribute: "label" });
|
|
25
24
|
/** A smaller line under the label. */
|
|
26
25
|
description = this.useChange("", (value) => {
|
|
27
26
|
this._refs.description.textContent = value;
|
|
28
|
-
this._refs.description.hidden = value === "";
|
|
29
27
|
this.renderText();
|
|
30
28
|
}, { attribute: "description" });
|
|
31
29
|
/**
|
|
@@ -77,14 +75,10 @@ var JlSwitch = class extends JlFormControl {
|
|
|
77
75
|
hidden: true,
|
|
78
76
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
79
77
|
class: "title",
|
|
80
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
81
|
-
class: "label",
|
|
82
|
-
hidden: true
|
|
83
|
-
}), /* @__PURE__ */ jsx("slot", {})]
|
|
78
|
+
children: [/* @__PURE__ */ jsx("span", { class: "label" }), /* @__PURE__ */ jsx("slot", {})]
|
|
84
79
|
}), /* @__PURE__ */ jsx("span", {
|
|
85
80
|
id: "description",
|
|
86
|
-
class: "description"
|
|
87
|
-
hidden: true
|
|
81
|
+
class: "description"
|
|
88
82
|
})]
|
|
89
83
|
})]
|
|
90
84
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/atoms/jl-textarea.css?inline
|
|
2
|
-
var jl_textarea_default = ":host{display:block}.field{gap:6px;display:grid}.control{align-items:stretch;padding:0}.native{height:auto;min-height:calc(var(--jl-control-md) - 2px);border-radius:inherit;resize:vertical;
|
|
2
|
+
var jl_textarea_default = ":host{display:block}.field{gap:6px;display:grid}.control{align-items:stretch;padding:0}.native{--padding-y:8px;height:auto;min-height:calc(var(--jl-control-md) - 2px);padding:var(--padding-y) 12px;border-radius:inherit;resize:vertical;display:block}:host([autosize]) .native{field-sizing:content;min-height:max(calc(var(--jl-control-md) - 2px), calc(var(--rows,1) * 1lh + 2 * var(--padding-y)));max-height:calc(var(--max-rows) * 1lh + 2 * var(--padding-y));resize:none}:host([readonly]) .control{background:var(--jl-surface-2)}.counter{color:var(--jl-muted);font-family:var(--jl-font-mono);font-size:var(--jl-font-xs);font-variant-numeric:tabular-nums;justify-self:end;line-height:16px}.counter[data-full]{color:var(--jl-warn)}";
|
|
3
3
|
export { jl_textarea_default as default };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { JlFormControl } from '../base/jl-form-control';
|
|
2
2
|
/**
|
|
3
3
|
* A text field of several lines that takes part in forms. `rows` sets its height; with `autosize` it grows with
|
|
4
|
-
* its text up to `max-rows
|
|
4
|
+
* its text up to `max-rows`, sized by the browser (CSS `field-sizing`): nothing is measured. A `maxlength` shows a
|
|
5
|
+
* counter under the field.
|
|
5
6
|
*/
|
|
6
7
|
export declare class JlTextarea extends JlFormControl {
|
|
7
8
|
static readonly selector = "jl-textarea";
|
|
@@ -74,8 +75,6 @@ export declare class JlTextarea extends JlFormControl {
|
|
|
74
75
|
private renderMaxlength;
|
|
75
76
|
private renderCounter;
|
|
76
77
|
private setFlag;
|
|
77
|
-
/**
|
|
78
|
-
private
|
|
79
|
-
/** The height of `max-rows` lines (never fewer than `rows`), or no limit without it. */
|
|
80
|
-
private heightLimit;
|
|
78
|
+
/** The lines an autosized area grows to, for its CSS; left out without a limit, which leaves its max-height none. */
|
|
79
|
+
private renderMaxRows;
|
|
81
80
|
}
|
|
@@ -7,10 +7,10 @@ import { jsx, jsxs } from "@jadis/core/jsx-runtime";
|
|
|
7
7
|
// src/atoms/jl-textarea.tsx
|
|
8
8
|
var DEFAULT_ROWS = 3;
|
|
9
9
|
var UNLIMITED_ROWS = 0;
|
|
10
|
-
var FALLBACK_LINE_HEIGHT = 20;
|
|
11
10
|
/**
|
|
12
11
|
* A text field of several lines that takes part in forms. `rows` sets its height; with `autosize` it grows with
|
|
13
|
-
* its text up to `max-rows
|
|
12
|
+
* its text up to `max-rows`, sized by the browser (CSS `field-sizing`): nothing is measured. A `maxlength` shows a
|
|
13
|
+
* counter under the field.
|
|
14
14
|
*/
|
|
15
15
|
var JlTextarea = class extends JlFormControl {
|
|
16
16
|
static selector = "jl-textarea";
|
|
@@ -18,16 +18,14 @@ var JlTextarea = class extends JlFormControl {
|
|
|
18
18
|
value = this.useChange("", (value) => this.renderValue(value), { attribute: "value" });
|
|
19
19
|
placeholder = this.useChange("", (value) => setOrRemove(this._refs.native, "placeholder", value), { attribute: "placeholder" });
|
|
20
20
|
rows = this.useChange(DEFAULT_ROWS, (value) => {
|
|
21
|
-
this._refs.native
|
|
22
|
-
|
|
21
|
+
const native = this._refs.native;
|
|
22
|
+
native.rows = Math.max(1, value);
|
|
23
|
+
native.style.setProperty("--rows", String(native.rows));
|
|
23
24
|
}, { attribute: "rows" });
|
|
24
25
|
/** Grows with the text, from `rows` up to `max-rows`. */
|
|
25
|
-
autosize = this.useChange(false, (value) => {
|
|
26
|
-
this.reflect("autosize", value);
|
|
27
|
-
this.fit();
|
|
28
|
-
}, { attribute: "autosize" });
|
|
26
|
+
autosize = this.useChange(false, (value) => this.reflect("autosize", value), { attribute: "autosize" });
|
|
29
27
|
/** The most lines an autosized area grows to before it scrolls; 0 for no limit. */
|
|
30
|
-
maxRows = this.useChange(UNLIMITED_ROWS, () => this.
|
|
28
|
+
maxRows = this.useChange(UNLIMITED_ROWS, (value) => this.renderMaxRows(value), { attribute: "max-rows" });
|
|
31
29
|
/** The most characters it takes; shows a counter under the field. */
|
|
32
30
|
maxlength = this.useChange("", (value) => this.renderMaxlength(value), { attribute: "maxlength" });
|
|
33
31
|
/** The field's name for screen readers, when no visible label names it. */
|
|
@@ -84,7 +82,6 @@ var JlTextarea = class extends JlFormControl {
|
|
|
84
82
|
this.events.emit("input", native.value);
|
|
85
83
|
});
|
|
86
84
|
this.on(native, "change", () => this.events.emit("change", native.value));
|
|
87
|
-
this.fit();
|
|
88
85
|
}
|
|
89
86
|
resetValue() {
|
|
90
87
|
this.value.set(this.getAttribute("value") ?? "");
|
|
@@ -103,7 +100,6 @@ var JlTextarea = class extends JlFormControl {
|
|
|
103
100
|
this.internals.setFormValue(value);
|
|
104
101
|
this.mirrorValidity(native);
|
|
105
102
|
this.renderCounter();
|
|
106
|
-
this.fit();
|
|
107
103
|
}
|
|
108
104
|
renderMaxlength(maxlength) {
|
|
109
105
|
setOrRemove(this._refs.native, "maxlength", maxlength);
|
|
@@ -124,25 +120,14 @@ var JlTextarea = class extends JlFormControl {
|
|
|
124
120
|
this.reflect(name, value);
|
|
125
121
|
this.mirrorValidity(this._refs.native);
|
|
126
122
|
}
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
native.style.height = `${height}px`;
|
|
136
|
-
native.style.overflowY = native.scrollHeight > limit ? "auto" : "hidden";
|
|
137
|
-
}
|
|
138
|
-
/** The height of `max-rows` lines (never fewer than `rows`), or no limit without it. */
|
|
139
|
-
heightLimit(native) {
|
|
140
|
-
const maxRows = this.maxRows.get();
|
|
141
|
-
if (maxRows <= UNLIMITED_ROWS) return Number.POSITIVE_INFINITY;
|
|
142
|
-
const style = getComputedStyle(native);
|
|
143
|
-
const padding = Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom);
|
|
144
|
-
const lineHeight = Number.parseFloat(style.lineHeight) || FALLBACK_LINE_HEIGHT;
|
|
145
|
-
return Math.max(maxRows, this.rows.get()) * lineHeight + padding;
|
|
123
|
+
/** The lines an autosized area grows to, for its CSS; left out without a limit, which leaves its max-height none. */
|
|
124
|
+
renderMaxRows(maxRows) {
|
|
125
|
+
const style = this._refs.native.style;
|
|
126
|
+
if (maxRows <= UNLIMITED_ROWS) {
|
|
127
|
+
style.removeProperty("--max-rows");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
style.setProperty("--max-rows", String(maxRows));
|
|
146
131
|
}
|
|
147
132
|
};
|
|
148
133
|
JlTextarea.register();
|
package/dist/lib/calendar.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dateTimeFormat } from "./intl.js";
|
|
1
2
|
// src/lib/calendar.ts
|
|
2
3
|
var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
4
|
var MS_PER_DAY = 864e5;
|
|
@@ -144,7 +145,7 @@ function dateAfterKey(date, key, firstDay, shift = false) {
|
|
|
144
145
|
* `options`. Made once and used for many dates, as a calendar page does.
|
|
145
146
|
*/
|
|
146
147
|
function dateFormatter(locale, options = { dateStyle: "medium" }) {
|
|
147
|
-
const format =
|
|
148
|
+
const format = dateTimeFormat(locale, {
|
|
148
149
|
...options,
|
|
149
150
|
timeZone: UTC
|
|
150
151
|
});
|
|
@@ -194,7 +195,7 @@ var DATE_TEXT = /^[\d\s./,-]*$/;
|
|
|
194
195
|
var NOT_DIGITS = /\D+/;
|
|
195
196
|
var isDatePart = (type) => DATE_PARTS.some((part) => part === type);
|
|
196
197
|
/** A date written in digits in a locale, cut in its parts: `25`, `.`, `10`, `.`, `2026`. */
|
|
197
|
-
var numericParts = (locale) =>
|
|
198
|
+
var numericParts = (locale) => dateTimeFormat(locale, {
|
|
198
199
|
...NUMERIC_DATE,
|
|
199
200
|
timeZone: UTC
|
|
200
201
|
}).formatToParts(new Date(utcTime(A_SUNDAY)));
|
package/dist/lib/floating.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export declare const PLACEMENTS: readonly Placement[];
|
|
|
7
7
|
export declare function computePosition(anchor: Rect, floating: Size, viewport: Size, placement: Placement, gap?: number): Point & {
|
|
8
8
|
placement: Placement;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Puts a fixed-position element next to its anchor, and gives what it measured: the anchor's rect, the element's
|
|
12
|
+
* rect where it went, and the placement it got after flipping. Something drawn from them (an arrow) needs no reading
|
|
13
|
+
* after the writes, which would lay the page out again.
|
|
14
|
+
*/
|
|
15
|
+
export declare function positionFloating(anchor: Element, floating: HTMLElement, placement: Placement, gap?: number): {
|
|
16
|
+
anchor: Rect;
|
|
17
|
+
floating: Rect;
|
|
18
|
+
placement: Placement;
|
|
19
|
+
};
|
|
10
20
|
/** Puts a fixed-position element next to its anchor; returns the placement it got after flipping. */
|
|
11
21
|
export declare function placeFloating(anchor: Element, floating: HTMLElement, placement: Placement, gap?: number): Placement;
|
|
12
22
|
/** Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. */
|
package/dist/lib/floating.js
CHANGED
|
@@ -92,21 +92,40 @@ function computePosition(anchor, floating, viewport, placement, gap = DEFAULT_GA
|
|
|
92
92
|
top: isVertical(finalSide) ? point.top : clamp(point.top, VIEWPORT_MARGIN, maxTop)
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
/**
|
|
96
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Puts a fixed-position element next to its anchor, and gives what it measured: the anchor's rect, the element's
|
|
97
|
+
* rect where it went, and the placement it got after flipping. Something drawn from them (an arrow) needs no reading
|
|
98
|
+
* after the writes, which would lay the page out again.
|
|
99
|
+
*/
|
|
100
|
+
function positionFloating(anchor, floating, placement, gap) {
|
|
97
101
|
const rect = anchor.getBoundingClientRect();
|
|
98
102
|
const viewport = {
|
|
99
103
|
height: window.innerHeight,
|
|
100
104
|
width: document.documentElement.clientWidth
|
|
101
105
|
};
|
|
102
|
-
const
|
|
106
|
+
const size = {
|
|
103
107
|
height: floating.offsetHeight,
|
|
104
108
|
width: floating.offsetWidth
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
};
|
|
110
|
+
const result = computePosition(rect, size, viewport, placement, gap);
|
|
111
|
+
const left = Math.round(result.left);
|
|
112
|
+
const top = Math.round(result.top);
|
|
113
|
+
floating.style.left = `${left}px`;
|
|
114
|
+
floating.style.top = `${top}px`;
|
|
108
115
|
floating.dataset.placement = result.placement;
|
|
109
|
-
return
|
|
116
|
+
return {
|
|
117
|
+
anchor: rect,
|
|
118
|
+
floating: {
|
|
119
|
+
...size,
|
|
120
|
+
left,
|
|
121
|
+
top
|
|
122
|
+
},
|
|
123
|
+
placement: result.placement
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Puts a fixed-position element next to its anchor; returns the placement it got after flipping. */
|
|
127
|
+
function placeFloating(anchor, floating, placement, gap) {
|
|
128
|
+
return positionFloating(anchor, floating, placement, gap).placement;
|
|
110
129
|
}
|
|
111
130
|
/** Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. */
|
|
112
131
|
function followAnchor(anchor, floating, placement, signal, gap) {
|
|
@@ -124,4 +143,4 @@ function followAnchor(anchor, floating, placement, signal, gap) {
|
|
|
124
143
|
});
|
|
125
144
|
update();
|
|
126
145
|
}
|
|
127
|
-
export { PLACEMENTS, computePosition, followAnchor, placeFloating };
|
|
146
|
+
export { PLACEMENTS, computePosition, followAnchor, placeFloating, positionFloating };
|