stimeo-ui 0.18.0 → 0.18.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -2
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +89 -45
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +77 -11
- data/dist/controllers/bulk_select_controller.js +6 -9
- data/dist/controllers/character_counter_controller.js +77 -11
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/combobox_controller.js +71 -6
- data/dist/controllers/command_palette_controller.js +161 -51
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +89 -45
- data/dist/controllers/context_menu_controller.js +1 -1
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +71 -6
- data/dist/controllers/data_grid_controller.js +77 -42
- data/dist/controllers/date_range_picker_controller.js +2 -1
- data/dist/controllers/dialog_controller.js +89 -45
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +13 -7
- data/dist/controllers/drawer_controller.js +89 -45
- data/dist/controllers/dropdown_controller.js +1 -1
- data/dist/controllers/editable_controller.js +72 -6
- data/dist/controllers/empty_state_controller.js +6 -5
- data/dist/controllers/file_dropzone_controller.js +13 -11
- data/dist/controllers/flash_controller.js +6 -5
- data/dist/controllers/focus_controller.js +89 -45
- data/dist/controllers/form_field_controller.js +6 -5
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +50 -16
- data/dist/controllers/hover_card_controller.js +1 -1
- data/dist/controllers/input_mask_controller.js +117 -36
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +80 -47
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +1 -1
- data/dist/controllers/menubar_controller.js +4 -6
- data/dist/controllers/meter_controller.js +6 -5
- data/dist/controllers/multi_select_controller.js +107 -22
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +17 -12
- data/dist/controllers/network_status_controller.js +6 -5
- data/dist/controllers/number_input_controller.js +154 -66
- data/dist/controllers/otp_controller.js +71 -6
- data/dist/controllers/overflow_menu_controller.js +7 -2
- data/dist/controllers/pagination_controller.js +7 -2
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/pointer_drag_controller.js +6 -1
- data/dist/controllers/popover_controller.js +21 -8
- data/dist/controllers/progress_controller.js +6 -5
- data/dist/controllers/radio_group_controller.js +85 -49
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +7 -2
- data/dist/controllers/scroll_area_controller.js +11 -7
- data/dist/controllers/scrollspy_controller.js +61 -29
- data/dist/controllers/separator_controller.js +72 -54
- data/dist/controllers/sidebar_controller.js +89 -45
- data/dist/controllers/skeleton_controller.js +50 -16
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +50 -16
- data/dist/controllers/sticky_observer_controller.js +61 -29
- data/dist/controllers/submit_once_controller.js +6 -5
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tags_input_controller.js +83 -20
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toggle_group_controller.js +84 -44
- data/dist/controllers/toolbar_controller.js +78 -8
- data/dist/controllers/tooltip_controller.js +1 -1
- data/dist/controllers/tree_view_controller.js +87 -49
- data/dist/index.js +566 -288
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -10,7 +10,50 @@ function isCompositionInputType(inputType) {
|
|
|
10
10
|
return inputType !== void 0 && COMPOSITION_INPUT_TYPES.has(inputType);
|
|
11
11
|
}
|
|
12
12
|
var BEFORE_MORPH_ATTRIBUTE = "turbo:before-morph-attribute";
|
|
13
|
-
var textOf = (element) =>
|
|
13
|
+
var textOf = (element) => {
|
|
14
|
+
if ("value" in element) return element.value;
|
|
15
|
+
return element instanceof Element ? element.textContent : void 0;
|
|
16
|
+
};
|
|
17
|
+
var nodesOf = (element) => {
|
|
18
|
+
const nodes = [];
|
|
19
|
+
if ("value" in element || !(element instanceof Element)) return nodes;
|
|
20
|
+
const walker = element.ownerDocument.createTreeWalker(element);
|
|
21
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) nodes.push(node);
|
|
22
|
+
return nodes;
|
|
23
|
+
};
|
|
24
|
+
var folded = (text) => text.replaceAll("\xA0", " ");
|
|
25
|
+
var startOf = (node, data, replaced, caret) => {
|
|
26
|
+
const text = folded(node.data);
|
|
27
|
+
const composed = folded(data);
|
|
28
|
+
if (replaced?.startContainer === node && text.startsWith(composed, replaced.startOffset)) {
|
|
29
|
+
return replaced.startOffset;
|
|
30
|
+
}
|
|
31
|
+
const start = text.lastIndexOf(composed, caret);
|
|
32
|
+
return start !== -1 && start + composed.length >= caret ? start : -1;
|
|
33
|
+
};
|
|
34
|
+
var spotOf = (element, replaced, data) => {
|
|
35
|
+
if ("value" in element || !(element instanceof Element)) return null;
|
|
36
|
+
const selection = element.ownerDocument.getSelection();
|
|
37
|
+
const node = selection?.focusNode;
|
|
38
|
+
if (!(node instanceof Text) || node.data === "" || !element.contains(node)) return null;
|
|
39
|
+
const range = element.ownerDocument.createRange();
|
|
40
|
+
const start = typeof data === "string" && data !== "" ? startOf(node, data, replaced, selection?.focusOffset ?? 0) : -1;
|
|
41
|
+
if (start === -1) {
|
|
42
|
+
range.selectNodeContents(node);
|
|
43
|
+
} else {
|
|
44
|
+
range.setStart(node, start);
|
|
45
|
+
range.setEnd(node, start + data.length);
|
|
46
|
+
}
|
|
47
|
+
return range;
|
|
48
|
+
};
|
|
49
|
+
var replacedBy = (event) => typeof event.getTargetRanges === "function" ? event.getTargetRanges()[0] ?? null : null;
|
|
50
|
+
var rewritten = ({ element, text, nodes, spot }) => {
|
|
51
|
+
if (spot !== null) {
|
|
52
|
+
return spot.collapsed || !(element instanceof Node && element.contains(spot.startContainer));
|
|
53
|
+
}
|
|
54
|
+
const current = nodesOf(element);
|
|
55
|
+
return textOf(element) !== text || current.length !== nodes.length || current.some((node, index) => node !== nodes[index]);
|
|
56
|
+
};
|
|
14
57
|
var holdsFocus = (element) => element instanceof Node && element.getRootNode().activeElement === element;
|
|
15
58
|
var CompositionTracker = class {
|
|
16
59
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -101,11 +144,11 @@ var CompositionTracker = class {
|
|
|
101
144
|
}
|
|
102
145
|
#settle() {
|
|
103
146
|
const composition = this.#composition;
|
|
104
|
-
if (composition === null) return;
|
|
105
|
-
const { target, element
|
|
147
|
+
if (composition === null || !this.#observedTargets.has(composition.target)) return;
|
|
148
|
+
const { target, element } = composition;
|
|
106
149
|
if (target instanceof Node && element instanceof Node && !target.contains(element)) {
|
|
107
150
|
this.#composition = null;
|
|
108
|
-
} else if (
|
|
151
|
+
} else if (rewritten(composition)) {
|
|
109
152
|
this.#abandon(false);
|
|
110
153
|
}
|
|
111
154
|
}
|
|
@@ -130,7 +173,14 @@ var CompositionTracker = class {
|
|
|
130
173
|
this.#owe(true);
|
|
131
174
|
const target = event.currentTarget;
|
|
132
175
|
const element = event.target;
|
|
133
|
-
this.#composition = {
|
|
176
|
+
this.#composition = {
|
|
177
|
+
target,
|
|
178
|
+
element,
|
|
179
|
+
text: textOf(element),
|
|
180
|
+
nodes: nodesOf(element),
|
|
181
|
+
spot: spotOf(element, null, void 0),
|
|
182
|
+
replaced: null
|
|
183
|
+
};
|
|
134
184
|
this.#runAbandon();
|
|
135
185
|
this.#onStart?.(event);
|
|
136
186
|
};
|
|
@@ -154,6 +204,10 @@ var CompositionTracker = class {
|
|
|
154
204
|
if (this.#composition !== null && !keyComposing && !isComposing && inputType && !isCompositionInputType(inputType)) {
|
|
155
205
|
this.#abandon(true);
|
|
156
206
|
}
|
|
207
|
+
const composition = this.#composition;
|
|
208
|
+
if (composition !== null && event.target === composition.element) {
|
|
209
|
+
composition.replaced = replacedBy(event);
|
|
210
|
+
}
|
|
157
211
|
this.#runAbandon();
|
|
158
212
|
};
|
|
159
213
|
#handleInput = (event) => {
|
|
@@ -161,6 +215,15 @@ var CompositionTracker = class {
|
|
|
161
215
|
const { isTrusted, isComposing, inputType } = event;
|
|
162
216
|
if (composition !== null && event.target === composition.element && (isTrusted || isComposing || isCompositionInputType(inputType))) {
|
|
163
217
|
composition.text = textOf(composition.element);
|
|
218
|
+
composition.nodes = nodesOf(composition.element);
|
|
219
|
+
if (isCompositionInputType(inputType)) {
|
|
220
|
+
composition.spot = spotOf(
|
|
221
|
+
composition.element,
|
|
222
|
+
composition.replaced,
|
|
223
|
+
event.data
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
composition.replaced = null;
|
|
164
227
|
} else {
|
|
165
228
|
this.#settle();
|
|
166
229
|
}
|
|
@@ -181,7 +244,9 @@ var CompositionTracker = class {
|
|
|
181
244
|
const composition = this.#composition;
|
|
182
245
|
if (composition?.target !== event.currentTarget || event.target !== composition.element) return;
|
|
183
246
|
const detail = event.detail;
|
|
184
|
-
if (detail?.attributeName === "value"
|
|
247
|
+
if (detail?.attributeName === "value" && "value" in composition.element) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
}
|
|
185
250
|
};
|
|
186
251
|
};
|
|
187
252
|
|
|
@@ -245,11 +310,16 @@ var DetachGate = class _DetachGate {
|
|
|
245
310
|
}
|
|
246
311
|
};
|
|
247
312
|
|
|
313
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
248
314
|
function inheritsFieldsetDisabled(control) {
|
|
249
315
|
let fieldset = control.closest("fieldset[disabled]");
|
|
250
316
|
while (fieldset) {
|
|
251
|
-
|
|
252
|
-
|
|
317
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
318
|
+
const legend = Array.from(fieldset.children).find(
|
|
319
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
320
|
+
);
|
|
321
|
+
if (!legend?.contains(control)) return true;
|
|
322
|
+
}
|
|
253
323
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
254
324
|
}
|
|
255
325
|
return false;
|
|
@@ -524,7 +594,8 @@ function applyMask(value, pattern, tokens) {
|
|
|
524
594
|
} else {
|
|
525
595
|
masked += patternChar;
|
|
526
596
|
tokenFlags.push(false);
|
|
527
|
-
|
|
597
|
+
const literal = value.slice(valueIndex, valueIndex + patternChar.length);
|
|
598
|
+
if (halfWidthChar(literal) === halfWidthChar(patternChar)) valueIndex += patternChar.length;
|
|
528
599
|
}
|
|
529
600
|
}
|
|
530
601
|
return {
|
|
@@ -560,14 +631,16 @@ function deletionOf(event) {
|
|
|
560
631
|
if (!inputType.startsWith("delete")) return null;
|
|
561
632
|
return inputType.endsWith("Forward") ? "forward" : "backward";
|
|
562
633
|
}
|
|
563
|
-
function
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
634
|
+
function tokenBoundary(pattern, tokenFlags, tokensBefore) {
|
|
635
|
+
const characters = pattern[Symbol.iterator]();
|
|
636
|
+
let offset = 0;
|
|
637
|
+
for (const token of tokenFlags) {
|
|
638
|
+
if (token && tokensBefore === 0) break;
|
|
639
|
+
const character = characters.next().value ?? "";
|
|
640
|
+
if (token) tokensBefore -= 1;
|
|
641
|
+
offset += token ? 1 : character.length;
|
|
642
|
+
}
|
|
643
|
+
return offset;
|
|
571
644
|
}
|
|
572
645
|
var InputMaskController = class extends Controller {
|
|
573
646
|
get #unmaskAttribute() {
|
|
@@ -590,6 +663,27 @@ var InputMaskController = class extends Controller {
|
|
|
590
663
|
#textBeforeComposition = "";
|
|
591
664
|
#formatted = null;
|
|
592
665
|
#shown = { result: null, empty: true };
|
|
666
|
+
#edits = new ListenerSet();
|
|
667
|
+
#onBeforeInput = (event) => {
|
|
668
|
+
const data = event.data;
|
|
669
|
+
if (event.defaultPrevented || !event.cancelable || event.inputType !== "insertText" || data === null || Array.from(data).length !== 1 || !this.#started || this.#composition.isComposing(event))
|
|
670
|
+
return;
|
|
671
|
+
const input = this.element;
|
|
672
|
+
const start = input.selectionStart;
|
|
673
|
+
const end = input.selectionEnd;
|
|
674
|
+
if (start === null || end === null || start === end || input.readOnly || input.disabled || inheritsFieldsetDisabled(input) || !input.isConnected || !this.application.element.contains(input) || !(input.getAttribute("data-controller") ?? "").split(/\s+/).includes(this.identifier) || this.patternValue === "" || this.#formatted !== this.#declared || input.value !== this.#lastValue)
|
|
675
|
+
return;
|
|
676
|
+
const prefix = applyMask(input.value.slice(0, start), this.patternValue, this.#tokens);
|
|
677
|
+
for (const character of Array.from(this.patternValue).slice(prefix.tokenFlags.length)) {
|
|
678
|
+
const token = this.#tokens.get(character);
|
|
679
|
+
if (token) {
|
|
680
|
+
if (acceptedForm(token, data) === null) event.preventDefault();
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (halfWidthChar(data) === halfWidthChar(character)) return;
|
|
684
|
+
}
|
|
685
|
+
event.preventDefault();
|
|
686
|
+
};
|
|
593
687
|
#composition = new CompositionTracker({
|
|
594
688
|
onStart: () => {
|
|
595
689
|
this.#textBeforeComposition = this.element.value;
|
|
@@ -625,6 +719,7 @@ var InputMaskController = class extends Controller {
|
|
|
625
719
|
this.#morph.observe(this.element);
|
|
626
720
|
this.#started = true;
|
|
627
721
|
this.#composition.observe(this.element);
|
|
722
|
+
this.#edits.add(this.element, "beforeinput", this.#onBeforeInput);
|
|
628
723
|
if (!this.unmaskToHiddenValue) this.#withdraw();
|
|
629
724
|
if (this.#composition.isComposing()) {
|
|
630
725
|
this.#reformat("reconcile");
|
|
@@ -639,6 +734,7 @@ var InputMaskController = class extends Controller {
|
|
|
639
734
|
disconnect() {
|
|
640
735
|
this.#morph.disconnect();
|
|
641
736
|
this.#started = false;
|
|
737
|
+
this.#edits.dispose();
|
|
642
738
|
this.#composition.disconnect();
|
|
643
739
|
this.#adoption.clearAll();
|
|
644
740
|
this.#gate.disconnected(this, () => this.#retractRaw());
|
|
@@ -668,8 +764,8 @@ var InputMaskController = class extends Controller {
|
|
|
668
764
|
let result = applyMask(raw, this.patternValue, this.#tokens);
|
|
669
765
|
if (deletion !== null && result.masked === this.#lastValue) {
|
|
670
766
|
const target = deletion === "backward" ? anchor : anchor + 1;
|
|
671
|
-
const offset =
|
|
672
|
-
if (offset
|
|
767
|
+
const offset = tokenBoundary(this.patternValue, result.tokenFlags, target - 1);
|
|
768
|
+
if (offset < result.masked.length) {
|
|
673
769
|
anchor = target - 1;
|
|
674
770
|
result = applyMask(
|
|
675
771
|
result.masked.slice(0, offset) + result.masked.slice(offset + 1),
|
|
@@ -685,7 +781,7 @@ var InputMaskController = class extends Controller {
|
|
|
685
781
|
}
|
|
686
782
|
if (input.value !== result.masked) {
|
|
687
783
|
input.value = result.masked;
|
|
688
|
-
this.#restoreCaret(result.tokenFlags, anchor);
|
|
784
|
+
this.#restoreCaret(tokenBoundary(this.patternValue, result.tokenFlags, anchor));
|
|
689
785
|
}
|
|
690
786
|
this.#publish(result, result.masked);
|
|
691
787
|
if (result.masked === this.#lastValue) return;
|
|
@@ -747,22 +843,7 @@ var InputMaskController = class extends Controller {
|
|
|
747
843
|
#significantBefore(prefix) {
|
|
748
844
|
return applyMask(prefix, this.patternValue, this.#tokens).unmasked.length;
|
|
749
845
|
}
|
|
750
|
-
#restoreCaret(
|
|
751
|
-
let position;
|
|
752
|
-
if (n <= 0) {
|
|
753
|
-
let i = 0;
|
|
754
|
-
while (i < tokenFlags.length && !tokenFlags[i]) i += 1;
|
|
755
|
-
position = i;
|
|
756
|
-
} else {
|
|
757
|
-
const offset = tokenCharOffset(tokenFlags, n);
|
|
758
|
-
if (offset < 0) {
|
|
759
|
-
position = tokenFlags.length;
|
|
760
|
-
} else {
|
|
761
|
-
let j = offset + 1;
|
|
762
|
-
while (j < tokenFlags.length && !tokenFlags[j]) j += 1;
|
|
763
|
-
position = j;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
846
|
+
#restoreCaret(position) {
|
|
766
847
|
try {
|
|
767
848
|
this.element.setSelectionRange(position, position);
|
|
768
849
|
} catch {
|
|
@@ -31,70 +31,102 @@ function queryRoot(selector) {
|
|
|
31
31
|
}
|
|
32
32
|
var IntersectionWatcher = class {
|
|
33
33
|
#onEntries;
|
|
34
|
-
#
|
|
35
|
-
#active = false;
|
|
36
|
-
#usingPlatformDefaults = false;
|
|
34
|
+
#session = null;
|
|
37
35
|
constructor(onEntries) {
|
|
38
36
|
this.#onEntries = onEntries;
|
|
39
37
|
}
|
|
40
38
|
get active() {
|
|
41
|
-
return this.#active;
|
|
39
|
+
return this.#session?.active ?? false;
|
|
42
40
|
}
|
|
43
41
|
get usingPlatformDefaults() {
|
|
44
|
-
return this.#usingPlatformDefaults;
|
|
42
|
+
return this.#session?.usingPlatformDefaults ?? false;
|
|
45
43
|
}
|
|
46
44
|
start(targets, options = {}) {
|
|
47
|
-
this
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const previous = this.#session;
|
|
46
|
+
const session = {
|
|
47
|
+
observer: null,
|
|
48
|
+
active: false,
|
|
49
|
+
usingPlatformDefaults: false
|
|
50
|
+
};
|
|
51
|
+
this.#session = session;
|
|
52
52
|
let observer = null;
|
|
53
53
|
try {
|
|
54
|
+
if (previous) this.#release(previous);
|
|
55
|
+
if (this.#session !== session) return false;
|
|
56
|
+
if (typeof IntersectionObserver === "undefined") return false;
|
|
57
|
+
const list = Array.isArray(targets) ? targets : [targets];
|
|
58
|
+
const empty = list.length === 0;
|
|
59
|
+
if (this.#session !== session) return false;
|
|
60
|
+
if (empty) return false;
|
|
61
|
+
const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
|
|
62
|
+
if (this.#session !== session) return false;
|
|
54
63
|
const onEntries = (entries) => {
|
|
55
|
-
if (this.#
|
|
64
|
+
if (this.#session === session && session.active) this.#onEntries(entries);
|
|
56
65
|
};
|
|
66
|
+
let usingPlatformDefaults = false;
|
|
57
67
|
try {
|
|
58
|
-
|
|
68
|
+
const configured = {
|
|
59
69
|
root,
|
|
60
70
|
rootMargin: options.rootMargin,
|
|
61
71
|
threshold: options.threshold
|
|
62
|
-
}
|
|
72
|
+
};
|
|
73
|
+
if (this.#session !== session) return false;
|
|
74
|
+
observer = new IntersectionObserver(onEntries, configured);
|
|
63
75
|
} catch (error) {
|
|
76
|
+
if (this.#session !== session) return false;
|
|
64
77
|
console.warn(
|
|
65
78
|
"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
|
|
66
79
|
error
|
|
67
80
|
);
|
|
81
|
+
if (this.#session !== session) return false;
|
|
68
82
|
observer = new IntersectionObserver(onEntries, { root });
|
|
69
|
-
|
|
83
|
+
usingPlatformDefaults = true;
|
|
84
|
+
}
|
|
85
|
+
if (this.#session !== session) {
|
|
86
|
+
this.#release(session, observer);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
session.observer = observer;
|
|
90
|
+
for (const target of list) {
|
|
91
|
+
if (this.#session !== session) return false;
|
|
92
|
+
observer.observe(target);
|
|
93
|
+
if (this.#session !== session) {
|
|
94
|
+
this.#release(session, observer);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
70
97
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
if (this.#session !== session) return false;
|
|
99
|
+
session.usingPlatformDefaults = usingPlatformDefaults;
|
|
100
|
+
session.active = true;
|
|
74
101
|
return true;
|
|
75
102
|
} catch (error) {
|
|
76
|
-
observer
|
|
77
|
-
this.#observer = null;
|
|
78
|
-
this.#active = false;
|
|
79
|
-
this.#usingPlatformDefaults = false;
|
|
103
|
+
this.#release(session, observer);
|
|
80
104
|
throw error;
|
|
81
105
|
}
|
|
82
106
|
}
|
|
83
107
|
rearm(target) {
|
|
84
|
-
|
|
108
|
+
const session = this.#session;
|
|
109
|
+
const observer = session?.observer;
|
|
110
|
+
if (!session?.active || !observer) return;
|
|
85
111
|
try {
|
|
86
|
-
|
|
87
|
-
this.#
|
|
112
|
+
observer.unobserve(target);
|
|
113
|
+
if (this.#session !== session) return;
|
|
114
|
+
observer.observe(target);
|
|
115
|
+
if (this.#session !== session) this.#release(session, observer);
|
|
88
116
|
} catch (error) {
|
|
89
|
-
this
|
|
117
|
+
if (this.#session === session) this.#session = null;
|
|
118
|
+
this.#release(session, observer);
|
|
90
119
|
throw error;
|
|
91
120
|
}
|
|
92
121
|
}
|
|
93
122
|
stop() {
|
|
94
|
-
|
|
95
|
-
this.#
|
|
96
|
-
this.#
|
|
97
|
-
|
|
123
|
+
const session = this.#session;
|
|
124
|
+
this.#session = null;
|
|
125
|
+
if (session) this.#release(session);
|
|
126
|
+
}
|
|
127
|
+
#release(session, observer = session.observer) {
|
|
128
|
+
session.observer = null;
|
|
129
|
+
observer?.disconnect();
|
|
98
130
|
}
|
|
99
131
|
};
|
|
100
132
|
|
|
@@ -14,70 +14,102 @@ function queryRoot(selector) {
|
|
|
14
14
|
}
|
|
15
15
|
var IntersectionWatcher = class {
|
|
16
16
|
#onEntries;
|
|
17
|
-
#
|
|
18
|
-
#active = false;
|
|
19
|
-
#usingPlatformDefaults = false;
|
|
17
|
+
#session = null;
|
|
20
18
|
constructor(onEntries) {
|
|
21
19
|
this.#onEntries = onEntries;
|
|
22
20
|
}
|
|
23
21
|
get active() {
|
|
24
|
-
return this.#active;
|
|
22
|
+
return this.#session?.active ?? false;
|
|
25
23
|
}
|
|
26
24
|
get usingPlatformDefaults() {
|
|
27
|
-
return this.#usingPlatformDefaults;
|
|
25
|
+
return this.#session?.usingPlatformDefaults ?? false;
|
|
28
26
|
}
|
|
29
27
|
start(targets, options = {}) {
|
|
30
|
-
this
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const previous = this.#session;
|
|
29
|
+
const session = {
|
|
30
|
+
observer: null,
|
|
31
|
+
active: false,
|
|
32
|
+
usingPlatformDefaults: false
|
|
33
|
+
};
|
|
34
|
+
this.#session = session;
|
|
35
35
|
let observer = null;
|
|
36
36
|
try {
|
|
37
|
+
if (previous) this.#release(previous);
|
|
38
|
+
if (this.#session !== session) return false;
|
|
39
|
+
if (typeof IntersectionObserver === "undefined") return false;
|
|
40
|
+
const list = Array.isArray(targets) ? targets : [targets];
|
|
41
|
+
const empty = list.length === 0;
|
|
42
|
+
if (this.#session !== session) return false;
|
|
43
|
+
if (empty) return false;
|
|
44
|
+
const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
|
|
45
|
+
if (this.#session !== session) return false;
|
|
37
46
|
const onEntries = (entries) => {
|
|
38
|
-
if (this.#
|
|
47
|
+
if (this.#session === session && session.active) this.#onEntries(entries);
|
|
39
48
|
};
|
|
49
|
+
let usingPlatformDefaults = false;
|
|
40
50
|
try {
|
|
41
|
-
|
|
51
|
+
const configured = {
|
|
42
52
|
root,
|
|
43
53
|
rootMargin: options.rootMargin,
|
|
44
54
|
threshold: options.threshold
|
|
45
|
-
}
|
|
55
|
+
};
|
|
56
|
+
if (this.#session !== session) return false;
|
|
57
|
+
observer = new IntersectionObserver(onEntries, configured);
|
|
46
58
|
} catch (error) {
|
|
59
|
+
if (this.#session !== session) return false;
|
|
47
60
|
console.warn(
|
|
48
61
|
"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
|
|
49
62
|
error
|
|
50
63
|
);
|
|
64
|
+
if (this.#session !== session) return false;
|
|
51
65
|
observer = new IntersectionObserver(onEntries, { root });
|
|
52
|
-
|
|
66
|
+
usingPlatformDefaults = true;
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
if (this.#session !== session) {
|
|
69
|
+
this.#release(session, observer);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
session.observer = observer;
|
|
73
|
+
for (const target of list) {
|
|
74
|
+
if (this.#session !== session) return false;
|
|
75
|
+
observer.observe(target);
|
|
76
|
+
if (this.#session !== session) {
|
|
77
|
+
this.#release(session, observer);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (this.#session !== session) return false;
|
|
82
|
+
session.usingPlatformDefaults = usingPlatformDefaults;
|
|
83
|
+
session.active = true;
|
|
57
84
|
return true;
|
|
58
85
|
} catch (error) {
|
|
59
|
-
observer
|
|
60
|
-
this.#observer = null;
|
|
61
|
-
this.#active = false;
|
|
62
|
-
this.#usingPlatformDefaults = false;
|
|
86
|
+
this.#release(session, observer);
|
|
63
87
|
throw error;
|
|
64
88
|
}
|
|
65
89
|
}
|
|
66
90
|
rearm(target) {
|
|
67
|
-
|
|
91
|
+
const session = this.#session;
|
|
92
|
+
const observer = session?.observer;
|
|
93
|
+
if (!session?.active || !observer) return;
|
|
68
94
|
try {
|
|
69
|
-
|
|
70
|
-
this.#
|
|
95
|
+
observer.unobserve(target);
|
|
96
|
+
if (this.#session !== session) return;
|
|
97
|
+
observer.observe(target);
|
|
98
|
+
if (this.#session !== session) this.#release(session, observer);
|
|
71
99
|
} catch (error) {
|
|
72
|
-
this
|
|
100
|
+
if (this.#session === session) this.#session = null;
|
|
101
|
+
this.#release(session, observer);
|
|
73
102
|
throw error;
|
|
74
103
|
}
|
|
75
104
|
}
|
|
76
105
|
stop() {
|
|
77
|
-
|
|
78
|
-
this.#
|
|
79
|
-
this.#
|
|
80
|
-
|
|
106
|
+
const session = this.#session;
|
|
107
|
+
this.#session = null;
|
|
108
|
+
if (session) this.#release(session);
|
|
109
|
+
}
|
|
110
|
+
#release(session, observer = session.observer) {
|
|
111
|
+
session.observer = null;
|
|
112
|
+
observer?.disconnect();
|
|
81
113
|
}
|
|
82
114
|
};
|
|
83
115
|
|