stimeo-ui 0.18.1 → 0.19.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +324 -76
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +103 -16
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +31 -13
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +103 -16
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +155 -26
- data/dist/controllers/command_palette_controller.js +445 -117
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +303 -68
- data/dist/controllers/context_menu_controller.js +59 -30
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +72 -7
- data/dist/controllers/data_grid_controller.js +273 -51
- data/dist/controllers/date_range_picker_controller.js +27 -5
- data/dist/controllers/dialog_controller.js +330 -79
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +68 -18
- data/dist/controllers/drawer_controller.js +362 -92
- data/dist/controllers/dropdown_controller.js +64 -52
- data/dist/controllers/editable_controller.js +140 -12
- data/dist/controllers/empty_state_controller.js +193 -9
- data/dist/controllers/file_dropzone_controller.js +313 -23
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +205 -17
- data/dist/controllers/focus_controller.js +273 -57
- data/dist/controllers/form_field_controller.js +71 -14
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +75 -20
- data/dist/controllers/hover_card_controller.js +108 -39
- data/dist/controllers/input_mask_controller.js +95 -37
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +174 -83
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +45 -24
- data/dist/controllers/menubar_controller.js +232 -52
- data/dist/controllers/meter_controller.js +31 -9
- data/dist/controllers/multi_select_controller.js +195 -62
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +275 -21
- data/dist/controllers/network_status_controller.js +31 -9
- data/dist/controllers/number_input_controller.js +180 -71
- data/dist/controllers/otp_controller.js +97 -11
- data/dist/controllers/overflow_menu_controller.js +190 -24
- data/dist/controllers/pagination_controller.js +186 -24
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +466 -42
- data/dist/controllers/progress_controller.js +31 -9
- data/dist/controllers/radio_group_controller.js +279 -88
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +204 -8
- data/dist/controllers/scroll_area_controller.js +61 -19
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +240 -32
- data/dist/controllers/separator_controller.js +97 -58
- data/dist/controllers/sidebar_controller.js +368 -127
- data/dist/controllers/skeleton_controller.js +75 -20
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +75 -20
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +86 -33
- data/dist/controllers/submit_once_controller.js +31 -9
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +293 -29
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +282 -79
- data/dist/controllers/toolbar_controller.js +276 -15
- data/dist/controllers/tooltip_controller.js +244 -46
- data/dist/controllers/tree_view_controller.js +287 -57
- data/dist/index.js +2258 -1016
- 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();
|
|
@@ -71,7 +114,7 @@ var CompositionTracker = class {
|
|
|
71
114
|
this.#confirmedTarget = null;
|
|
72
115
|
if (confirmed === null || confirmed !== event.target) return false;
|
|
73
116
|
const inputType = event.inputType;
|
|
74
|
-
return
|
|
117
|
+
return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
|
|
75
118
|
}
|
|
76
119
|
#release(target) {
|
|
77
120
|
target.removeEventListener("compositionstart", this.#handleStart);
|
|
@@ -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() {
|
|
@@ -691,8 +764,8 @@ var InputMaskController = class extends Controller {
|
|
|
691
764
|
let result = applyMask(raw, this.patternValue, this.#tokens);
|
|
692
765
|
if (deletion !== null && result.masked === this.#lastValue) {
|
|
693
766
|
const target = deletion === "backward" ? anchor : anchor + 1;
|
|
694
|
-
const offset =
|
|
695
|
-
if (offset
|
|
767
|
+
const offset = tokenBoundary(this.patternValue, result.tokenFlags, target - 1);
|
|
768
|
+
if (offset < result.masked.length) {
|
|
696
769
|
anchor = target - 1;
|
|
697
770
|
result = applyMask(
|
|
698
771
|
result.masked.slice(0, offset) + result.masked.slice(offset + 1),
|
|
@@ -708,7 +781,7 @@ var InputMaskController = class extends Controller {
|
|
|
708
781
|
}
|
|
709
782
|
if (input.value !== result.masked) {
|
|
710
783
|
input.value = result.masked;
|
|
711
|
-
this.#restoreCaret(result.tokenFlags, anchor);
|
|
784
|
+
this.#restoreCaret(tokenBoundary(this.patternValue, result.tokenFlags, anchor));
|
|
712
785
|
}
|
|
713
786
|
this.#publish(result, result.masked);
|
|
714
787
|
if (result.masked === this.#lastValue) return;
|
|
@@ -770,22 +843,7 @@ var InputMaskController = class extends Controller {
|
|
|
770
843
|
#significantBefore(prefix) {
|
|
771
844
|
return applyMask(prefix, this.patternValue, this.#tokens).unmasked.length;
|
|
772
845
|
}
|
|
773
|
-
#restoreCaret(
|
|
774
|
-
let position;
|
|
775
|
-
if (n <= 0) {
|
|
776
|
-
let i = 0;
|
|
777
|
-
while (i < tokenFlags.length && !tokenFlags[i]) i += 1;
|
|
778
|
-
position = i;
|
|
779
|
-
} else {
|
|
780
|
-
const offset = tokenCharOffset(tokenFlags, n);
|
|
781
|
-
if (offset < 0) {
|
|
782
|
-
position = tokenFlags.length;
|
|
783
|
-
} else {
|
|
784
|
-
let j = offset + 1;
|
|
785
|
-
while (j < tokenFlags.length && !tokenFlags[j]) j += 1;
|
|
786
|
-
position = j;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
846
|
+
#restoreCaret(position) {
|
|
789
847
|
try {
|
|
790
848
|
this.element.setSelectionRange(position, position);
|
|
791
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
|
|