svelte-typeahead 4.4.1 → 5.0.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/lib/index.mjs DELETED
@@ -1,1994 +0,0 @@
1
- function noop() { }
2
- function assign(tar, src) {
3
- // @ts-ignore
4
- for (const k in src)
5
- tar[k] = src[k];
6
- return tar;
7
- }
8
- function run(fn) {
9
- return fn();
10
- }
11
- function blank_object() {
12
- return Object.create(null);
13
- }
14
- function run_all(fns) {
15
- fns.forEach(run);
16
- }
17
- function is_function(thing) {
18
- return typeof thing === 'function';
19
- }
20
- function safe_not_equal(a, b) {
21
- return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
22
- }
23
- function is_empty(obj) {
24
- return Object.keys(obj).length === 0;
25
- }
26
- function create_slot(definition, ctx, $$scope, fn) {
27
- if (definition) {
28
- const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
29
- return definition[0](slot_ctx);
30
- }
31
- }
32
- function get_slot_context(definition, ctx, $$scope, fn) {
33
- return definition[1] && fn
34
- ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
35
- : $$scope.ctx;
36
- }
37
- function get_slot_changes(definition, $$scope, dirty, fn) {
38
- if (definition[2] && fn) {
39
- const lets = definition[2](fn(dirty));
40
- if ($$scope.dirty === undefined) {
41
- return lets;
42
- }
43
- if (typeof lets === 'object') {
44
- const merged = [];
45
- const len = Math.max($$scope.dirty.length, lets.length);
46
- for (let i = 0; i < len; i += 1) {
47
- merged[i] = $$scope.dirty[i] | lets[i];
48
- }
49
- return merged;
50
- }
51
- return $$scope.dirty | lets;
52
- }
53
- return $$scope.dirty;
54
- }
55
- function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
56
- if (slot_changes) {
57
- const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
58
- slot.p(slot_context, slot_changes);
59
- }
60
- }
61
- function get_all_dirty_from_scope($$scope) {
62
- if ($$scope.ctx.length > 32) {
63
- const dirty = [];
64
- const length = $$scope.ctx.length / 32;
65
- for (let i = 0; i < length; i++) {
66
- dirty[i] = -1;
67
- }
68
- return dirty;
69
- }
70
- return -1;
71
- }
72
- function exclude_internal_props(props) {
73
- const result = {};
74
- for (const k in props)
75
- if (k[0] !== '$')
76
- result[k] = props[k];
77
- return result;
78
- }
79
- function compute_rest_props(props, keys) {
80
- const rest = {};
81
- keys = new Set(keys);
82
- for (const k in props)
83
- if (!keys.has(k) && k[0] !== '$')
84
- rest[k] = props[k];
85
- return rest;
86
- }
87
- function compute_slots(slots) {
88
- const result = {};
89
- for (const key in slots) {
90
- result[key] = true;
91
- }
92
- return result;
93
- }
94
- function append(target, node) {
95
- target.appendChild(node);
96
- }
97
- function append_styles(target, style_sheet_id, styles) {
98
- const append_styles_to = get_root_for_style(target);
99
- if (!append_styles_to.getElementById(style_sheet_id)) {
100
- const style = element('style');
101
- style.id = style_sheet_id;
102
- style.textContent = styles;
103
- append_stylesheet(append_styles_to, style);
104
- }
105
- }
106
- function get_root_for_style(node) {
107
- if (!node)
108
- return document;
109
- const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
110
- if (root && root.host) {
111
- return root;
112
- }
113
- return node.ownerDocument;
114
- }
115
- function append_stylesheet(node, style) {
116
- append(node.head || node, style);
117
- return style.sheet;
118
- }
119
- function insert(target, node, anchor) {
120
- target.insertBefore(node, anchor || null);
121
- }
122
- function detach(node) {
123
- node.parentNode.removeChild(node);
124
- }
125
- function destroy_each(iterations, detaching) {
126
- for (let i = 0; i < iterations.length; i += 1) {
127
- if (iterations[i])
128
- iterations[i].d(detaching);
129
- }
130
- }
131
- function element(name) {
132
- return document.createElement(name);
133
- }
134
- function svg_element(name) {
135
- return document.createElementNS('http://www.w3.org/2000/svg', name);
136
- }
137
- function text(data) {
138
- return document.createTextNode(data);
139
- }
140
- function space() {
141
- return text(' ');
142
- }
143
- function empty() {
144
- return text('');
145
- }
146
- function listen(node, event, handler, options) {
147
- node.addEventListener(event, handler, options);
148
- return () => node.removeEventListener(event, handler, options);
149
- }
150
- function prevent_default(fn) {
151
- return function (event) {
152
- event.preventDefault();
153
- // @ts-ignore
154
- return fn.call(this, event);
155
- };
156
- }
157
- function attr(node, attribute, value) {
158
- if (value == null)
159
- node.removeAttribute(attribute);
160
- else if (node.getAttribute(attribute) !== value)
161
- node.setAttribute(attribute, value);
162
- }
163
- function set_attributes(node, attributes) {
164
- // @ts-ignore
165
- const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
166
- for (const key in attributes) {
167
- if (attributes[key] == null) {
168
- node.removeAttribute(key);
169
- }
170
- else if (key === 'style') {
171
- node.style.cssText = attributes[key];
172
- }
173
- else if (key === '__value') {
174
- node.value = node[key] = attributes[key];
175
- }
176
- else if (descriptors[key] && descriptors[key].set) {
177
- node[key] = attributes[key];
178
- }
179
- else {
180
- attr(node, key, attributes[key]);
181
- }
182
- }
183
- }
184
- function children(element) {
185
- return Array.from(element.childNodes);
186
- }
187
- function set_data(text, data) {
188
- data = '' + data;
189
- if (text.wholeText !== data)
190
- text.data = data;
191
- }
192
- function set_input_value(input, value) {
193
- input.value = value == null ? '' : value;
194
- }
195
- function toggle_class(element, name, toggle) {
196
- element.classList[toggle ? 'add' : 'remove'](name);
197
- }
198
- function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
199
- const e = document.createEvent('CustomEvent');
200
- e.initCustomEvent(type, bubbles, cancelable, detail);
201
- return e;
202
- }
203
- class HtmlTag {
204
- constructor(is_svg = false) {
205
- this.is_svg = false;
206
- this.is_svg = is_svg;
207
- this.e = this.n = null;
208
- }
209
- c(html) {
210
- this.h(html);
211
- }
212
- m(html, target, anchor = null) {
213
- if (!this.e) {
214
- if (this.is_svg)
215
- this.e = svg_element(target.nodeName);
216
- else
217
- this.e = element(target.nodeName);
218
- this.t = target;
219
- this.c(html);
220
- }
221
- this.i(anchor);
222
- }
223
- h(html) {
224
- this.e.innerHTML = html;
225
- this.n = Array.from(this.e.childNodes);
226
- }
227
- i(anchor) {
228
- for (let i = 0; i < this.n.length; i += 1) {
229
- insert(this.t, this.n[i], anchor);
230
- }
231
- }
232
- p(html) {
233
- this.d();
234
- this.h(html);
235
- this.i(this.a);
236
- }
237
- d() {
238
- this.n.forEach(detach);
239
- }
240
- }
241
-
242
- let current_component;
243
- function set_current_component(component) {
244
- current_component = component;
245
- }
246
- function get_current_component() {
247
- if (!current_component)
248
- throw new Error('Function called outside component initialization');
249
- return current_component;
250
- }
251
- /**
252
- * The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.
253
- * It must be called during the component's initialisation (but doesn't need to live *inside* the component;
254
- * it can be called from an external module).
255
- *
256
- * `onMount` does not run inside a [server-side component](/docs#run-time-server-side-component-api).
257
- *
258
- * https://svelte.dev/docs#run-time-svelte-onmount
259
- */
260
- function onMount(fn) {
261
- get_current_component().$$.on_mount.push(fn);
262
- }
263
- /**
264
- * Schedules a callback to run immediately after the component has been updated.
265
- *
266
- * The first time the callback runs will be after the initial `onMount`
267
- */
268
- function afterUpdate(fn) {
269
- get_current_component().$$.after_update.push(fn);
270
- }
271
- /**
272
- * Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname).
273
- * Event dispatchers are functions that can take two arguments: `name` and `detail`.
274
- *
275
- * Component events created with `createEventDispatcher` create a
276
- * [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent).
277
- * These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture).
278
- * The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail)
279
- * property and can contain any type of data.
280
- *
281
- * https://svelte.dev/docs#run-time-svelte-createeventdispatcher
282
- */
283
- function createEventDispatcher() {
284
- const component = get_current_component();
285
- return (type, detail, { cancelable = false } = {}) => {
286
- const callbacks = component.$$.callbacks[type];
287
- if (callbacks) {
288
- // TODO are there situations where events could be dispatched
289
- // in a server (non-DOM) environment?
290
- const event = custom_event(type, detail, { cancelable });
291
- callbacks.slice().forEach(fn => {
292
- fn.call(component, event);
293
- });
294
- return !event.defaultPrevented;
295
- }
296
- return true;
297
- };
298
- }
299
- // TODO figure out if we still want to support
300
- // shorthand events, or if we want to implement
301
- // a real bubbling mechanism
302
- function bubble(component, event) {
303
- const callbacks = component.$$.callbacks[event.type];
304
- if (callbacks) {
305
- // @ts-ignore
306
- callbacks.slice().forEach(fn => fn.call(this, event));
307
- }
308
- }
309
-
310
- const dirty_components = [];
311
- const binding_callbacks = [];
312
- const render_callbacks = [];
313
- const flush_callbacks = [];
314
- const resolved_promise = Promise.resolve();
315
- let update_scheduled = false;
316
- function schedule_update() {
317
- if (!update_scheduled) {
318
- update_scheduled = true;
319
- resolved_promise.then(flush);
320
- }
321
- }
322
- function tick() {
323
- schedule_update();
324
- return resolved_promise;
325
- }
326
- function add_render_callback(fn) {
327
- render_callbacks.push(fn);
328
- }
329
- function add_flush_callback(fn) {
330
- flush_callbacks.push(fn);
331
- }
332
- // flush() calls callbacks in this order:
333
- // 1. All beforeUpdate callbacks, in order: parents before children
334
- // 2. All bind:this callbacks, in reverse order: children before parents.
335
- // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
336
- // for afterUpdates called during the initial onMount, which are called in
337
- // reverse order: children before parents.
338
- // Since callbacks might update component values, which could trigger another
339
- // call to flush(), the following steps guard against this:
340
- // 1. During beforeUpdate, any updated components will be added to the
341
- // dirty_components array and will cause a reentrant call to flush(). Because
342
- // the flush index is kept outside the function, the reentrant call will pick
343
- // up where the earlier call left off and go through all dirty components. The
344
- // current_component value is saved and restored so that the reentrant call will
345
- // not interfere with the "parent" flush() call.
346
- // 2. bind:this callbacks cannot trigger new flush() calls.
347
- // 3. During afterUpdate, any updated components will NOT have their afterUpdate
348
- // callback called a second time; the seen_callbacks set, outside the flush()
349
- // function, guarantees this behavior.
350
- const seen_callbacks = new Set();
351
- let flushidx = 0; // Do *not* move this inside the flush() function
352
- function flush() {
353
- const saved_component = current_component;
354
- do {
355
- // first, call beforeUpdate functions
356
- // and update components
357
- while (flushidx < dirty_components.length) {
358
- const component = dirty_components[flushidx];
359
- flushidx++;
360
- set_current_component(component);
361
- update(component.$$);
362
- }
363
- set_current_component(null);
364
- dirty_components.length = 0;
365
- flushidx = 0;
366
- while (binding_callbacks.length)
367
- binding_callbacks.pop()();
368
- // then, once components are updated, call
369
- // afterUpdate functions. This may cause
370
- // subsequent updates...
371
- for (let i = 0; i < render_callbacks.length; i += 1) {
372
- const callback = render_callbacks[i];
373
- if (!seen_callbacks.has(callback)) {
374
- // ...so guard against infinite loops
375
- seen_callbacks.add(callback);
376
- callback();
377
- }
378
- }
379
- render_callbacks.length = 0;
380
- } while (dirty_components.length);
381
- while (flush_callbacks.length) {
382
- flush_callbacks.pop()();
383
- }
384
- update_scheduled = false;
385
- seen_callbacks.clear();
386
- set_current_component(saved_component);
387
- }
388
- function update($$) {
389
- if ($$.fragment !== null) {
390
- $$.update();
391
- run_all($$.before_update);
392
- const dirty = $$.dirty;
393
- $$.dirty = [-1];
394
- $$.fragment && $$.fragment.p($$.ctx, dirty);
395
- $$.after_update.forEach(add_render_callback);
396
- }
397
- }
398
- const outroing = new Set();
399
- let outros;
400
- function group_outros() {
401
- outros = {
402
- r: 0,
403
- c: [],
404
- p: outros // parent group
405
- };
406
- }
407
- function check_outros() {
408
- if (!outros.r) {
409
- run_all(outros.c);
410
- }
411
- outros = outros.p;
412
- }
413
- function transition_in(block, local) {
414
- if (block && block.i) {
415
- outroing.delete(block);
416
- block.i(local);
417
- }
418
- }
419
- function transition_out(block, local, detach, callback) {
420
- if (block && block.o) {
421
- if (outroing.has(block))
422
- return;
423
- outroing.add(block);
424
- outros.c.push(() => {
425
- outroing.delete(block);
426
- if (callback) {
427
- if (detach)
428
- block.d(1);
429
- callback();
430
- }
431
- });
432
- block.o(local);
433
- }
434
- else if (callback) {
435
- callback();
436
- }
437
- }
438
-
439
- function get_spread_update(levels, updates) {
440
- const update = {};
441
- const to_null_out = {};
442
- const accounted_for = { $$scope: 1 };
443
- let i = levels.length;
444
- while (i--) {
445
- const o = levels[i];
446
- const n = updates[i];
447
- if (n) {
448
- for (const key in o) {
449
- if (!(key in n))
450
- to_null_out[key] = 1;
451
- }
452
- for (const key in n) {
453
- if (!accounted_for[key]) {
454
- update[key] = n[key];
455
- accounted_for[key] = 1;
456
- }
457
- }
458
- levels[i] = n;
459
- }
460
- else {
461
- for (const key in o) {
462
- accounted_for[key] = 1;
463
- }
464
- }
465
- }
466
- for (const key in to_null_out) {
467
- if (!(key in update))
468
- update[key] = undefined;
469
- }
470
- return update;
471
- }
472
- function get_spread_object(spread_props) {
473
- return typeof spread_props === 'object' && spread_props !== null ? spread_props : {};
474
- }
475
-
476
- function bind(component, name, callback) {
477
- const index = component.$$.props[name];
478
- if (index !== undefined) {
479
- component.$$.bound[index] = callback;
480
- callback(component.$$.ctx[index]);
481
- }
482
- }
483
- function create_component(block) {
484
- block && block.c();
485
- }
486
- function mount_component(component, target, anchor, customElement) {
487
- const { fragment, after_update } = component.$$;
488
- fragment && fragment.m(target, anchor);
489
- if (!customElement) {
490
- // onMount happens before the initial afterUpdate
491
- add_render_callback(() => {
492
- const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
493
- // if the component was destroyed immediately
494
- // it will update the `$$.on_destroy` reference to `null`.
495
- // the destructured on_destroy may still reference to the old array
496
- if (component.$$.on_destroy) {
497
- component.$$.on_destroy.push(...new_on_destroy);
498
- }
499
- else {
500
- // Edge case - component was destroyed immediately,
501
- // most likely as a result of a binding initialising
502
- run_all(new_on_destroy);
503
- }
504
- component.$$.on_mount = [];
505
- });
506
- }
507
- after_update.forEach(add_render_callback);
508
- }
509
- function destroy_component(component, detaching) {
510
- const $$ = component.$$;
511
- if ($$.fragment !== null) {
512
- run_all($$.on_destroy);
513
- $$.fragment && $$.fragment.d(detaching);
514
- // TODO null out other refs, including component.$$ (but need to
515
- // preserve final state?)
516
- $$.on_destroy = $$.fragment = null;
517
- $$.ctx = [];
518
- }
519
- }
520
- function make_dirty(component, i) {
521
- if (component.$$.dirty[0] === -1) {
522
- dirty_components.push(component);
523
- schedule_update();
524
- component.$$.dirty.fill(0);
525
- }
526
- component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
527
- }
528
- function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
529
- const parent_component = current_component;
530
- set_current_component(component);
531
- const $$ = component.$$ = {
532
- fragment: null,
533
- ctx: [],
534
- // state
535
- props,
536
- update: noop,
537
- not_equal,
538
- bound: blank_object(),
539
- // lifecycle
540
- on_mount: [],
541
- on_destroy: [],
542
- on_disconnect: [],
543
- before_update: [],
544
- after_update: [],
545
- context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
546
- // everything else
547
- callbacks: blank_object(),
548
- dirty,
549
- skip_bound: false,
550
- root: options.target || parent_component.$$.root
551
- };
552
- append_styles && append_styles($$.root);
553
- let ready = false;
554
- $$.ctx = instance
555
- ? instance(component, options.props || {}, (i, ret, ...rest) => {
556
- const value = rest.length ? rest[0] : ret;
557
- if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
558
- if (!$$.skip_bound && $$.bound[i])
559
- $$.bound[i](value);
560
- if (ready)
561
- make_dirty(component, i);
562
- }
563
- return ret;
564
- })
565
- : [];
566
- $$.update();
567
- ready = true;
568
- run_all($$.before_update);
569
- // `false` as a special case of no DOM component
570
- $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
571
- if (options.target) {
572
- if (options.hydrate) {
573
- const nodes = children(options.target);
574
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
575
- $$.fragment && $$.fragment.l(nodes);
576
- nodes.forEach(detach);
577
- }
578
- else {
579
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
580
- $$.fragment && $$.fragment.c();
581
- }
582
- if (options.intro)
583
- transition_in(component.$$.fragment);
584
- mount_component(component, options.target, options.anchor, options.customElement);
585
- flush();
586
- }
587
- set_current_component(parent_component);
588
- }
589
- /**
590
- * Base class for Svelte components. Used when dev=false.
591
- */
592
- class SvelteComponent {
593
- $destroy() {
594
- destroy_component(this, 1);
595
- this.$destroy = noop;
596
- }
597
- $on(type, callback) {
598
- if (!is_function(callback)) {
599
- return noop;
600
- }
601
- const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
602
- callbacks.push(callback);
603
- return () => {
604
- const index = callbacks.indexOf(callback);
605
- if (index !== -1)
606
- callbacks.splice(index, 1);
607
- };
608
- }
609
- $set($$props) {
610
- if (this.$$set && !is_empty($$props)) {
611
- this.$$.skip_bound = true;
612
- this.$$set($$props);
613
- this.$$.skip_bound = false;
614
- }
615
- }
616
- }
617
-
618
- var fuzzy$1 = {exports: {}};
619
-
620
- /*
621
- * Fuzzy
622
- * https://github.com/myork/fuzzy
623
- *
624
- * Copyright (c) 2012 Matt York
625
- * Licensed under the MIT license.
626
- */
627
-
628
- (function (module, exports) {
629
- (function() {
630
-
631
- var fuzzy = {};
632
-
633
- // Use in node or in browser
634
- {
635
- module.exports = fuzzy;
636
- }
637
-
638
- // Return all elements of `array` that have a fuzzy
639
- // match against `pattern`.
640
- fuzzy.simpleFilter = function(pattern, array) {
641
- return array.filter(function(str) {
642
- return fuzzy.test(pattern, str);
643
- });
644
- };
645
-
646
- // Does `pattern` fuzzy match `str`?
647
- fuzzy.test = function(pattern, str) {
648
- return fuzzy.match(pattern, str) !== null;
649
- };
650
-
651
- // If `pattern` matches `str`, wrap each matching character
652
- // in `opts.pre` and `opts.post`. If no match, return null
653
- fuzzy.match = function(pattern, str, opts) {
654
- opts = opts || {};
655
- var patternIdx = 0
656
- , result = []
657
- , len = str.length
658
- , totalScore = 0
659
- , currScore = 0
660
- // prefix
661
- , pre = opts.pre || ''
662
- // suffix
663
- , post = opts.post || ''
664
- // String to compare against. This might be a lowercase version of the
665
- // raw string
666
- , compareString = opts.caseSensitive && str || str.toLowerCase()
667
- , ch;
668
-
669
- pattern = opts.caseSensitive && pattern || pattern.toLowerCase();
670
-
671
- // For each character in the string, either add it to the result
672
- // or wrap in template if it's the next string in the pattern
673
- for(var idx = 0; idx < len; idx++) {
674
- ch = str[idx];
675
- if(compareString[idx] === pattern[patternIdx]) {
676
- ch = pre + ch + post;
677
- patternIdx += 1;
678
-
679
- // consecutive characters should increase the score more than linearly
680
- currScore += 1 + currScore;
681
- } else {
682
- currScore = 0;
683
- }
684
- totalScore += currScore;
685
- result[result.length] = ch;
686
- }
687
-
688
- // return rendered string if we have a match for every char
689
- if(patternIdx === pattern.length) {
690
- // if the string is an exact match with pattern, totalScore should be maxed
691
- totalScore = (compareString === pattern) ? Infinity : totalScore;
692
- return {rendered: result.join(''), score: totalScore};
693
- }
694
-
695
- return null;
696
- };
697
-
698
- // The normal entry point. Filters `arr` for matches against `pattern`.
699
- // It returns an array with matching values of the type:
700
- //
701
- // [{
702
- // string: '<b>lah' // The rendered string
703
- // , index: 2 // The index of the element in `arr`
704
- // , original: 'blah' // The original element in `arr`
705
- // }]
706
- //
707
- // `opts` is an optional argument bag. Details:
708
- //
709
- // opts = {
710
- // // string to put before a matching character
711
- // pre: '<b>'
712
- //
713
- // // string to put after matching character
714
- // , post: '</b>'
715
- //
716
- // // Optional function. Input is an entry in the given arr`,
717
- // // output should be the string to test `pattern` against.
718
- // // In this example, if `arr = [{crying: 'koala'}]` we would return
719
- // // 'koala'.
720
- // , extract: function(arg) { return arg.crying; }
721
- // }
722
- fuzzy.filter = function(pattern, arr, opts) {
723
- if(!arr || arr.length === 0) {
724
- return [];
725
- }
726
- if (typeof pattern !== 'string') {
727
- return arr;
728
- }
729
- opts = opts || {};
730
- return arr
731
- .reduce(function(prev, element, idx, arr) {
732
- var str = element;
733
- if(opts.extract) {
734
- str = opts.extract(element);
735
- }
736
- var rendered = fuzzy.match(pattern, str, opts);
737
- if(rendered != null) {
738
- prev[prev.length] = {
739
- string: rendered.rendered
740
- , score: rendered.score
741
- , index: idx
742
- , original: element
743
- };
744
- }
745
- return prev;
746
- }, [])
747
-
748
- // Sort by score. Browsers are inconsistent wrt stable/unstable
749
- // sorting, so force stable by using the index in the case of tie.
750
- // See http://ofb.net/~sethml/is-sort-stable.html
751
- .sort(function(a,b) {
752
- var compare = b.score - a.score;
753
- if(compare) return compare;
754
- return a.index - b.index;
755
- });
756
- };
757
-
758
-
759
- }());
760
- }(fuzzy$1));
761
-
762
- var fuzzy = fuzzy$1.exports;
763
-
764
- /* node_modules/svelte-search/src/Search.svelte generated by Svelte v3.52.0 */
765
-
766
- function add_css$1(target) {
767
- append_styles(target, "svelte-5m0wg6", ".hide-label.svelte-5m0wg6{position:absolute;height:1px;width:1px;overflow:hidden;clip:rect(1px 1px 1px 1px);clip:rect(1px, 1px, 1px, 1px);white-space:nowrap}");
768
- }
769
-
770
- const get_label_slot_changes = dirty => ({});
771
- const get_label_slot_context = ctx => ({});
772
-
773
- // (60:23) {label}
774
- function fallback_block$1(ctx) {
775
- let t;
776
-
777
- return {
778
- c() {
779
- t = text(/*label*/ ctx[2]);
780
- },
781
- m(target, anchor) {
782
- insert(target, t, anchor);
783
- },
784
- p(ctx, dirty) {
785
- if (dirty & /*label*/ 4) set_data(t, /*label*/ ctx[2]);
786
- },
787
- d(detaching) {
788
- if (detaching) detach(t);
789
- }
790
- };
791
- }
792
-
793
- function create_fragment$1(ctx) {
794
- let form;
795
- let label_1;
796
- let label_1_id_value;
797
- let t;
798
- let input;
799
- let form_role_value;
800
- let form_aria_labelledby_value;
801
- let current;
802
- let mounted;
803
- let dispose;
804
- const label_slot_template = /*#slots*/ ctx[10].label;
805
- const label_slot = create_slot(label_slot_template, ctx, /*$$scope*/ ctx[9], get_label_slot_context);
806
- const label_slot_or_fallback = label_slot || fallback_block$1(ctx);
807
-
808
- let input_levels = [
809
- { name: "search" },
810
- { type: "search" },
811
- { placeholder: "Search..." },
812
- { autocomplete: "off" },
813
- { spellcheck: "false" },
814
- /*$$restProps*/ ctx[6],
815
- { id: /*id*/ ctx[4] }
816
- ];
817
-
818
- let input_data = {};
819
-
820
- for (let i = 0; i < input_levels.length; i += 1) {
821
- input_data = assign(input_data, input_levels[i]);
822
- }
823
-
824
- return {
825
- c() {
826
- form = element("form");
827
- label_1 = element("label");
828
- if (label_slot_or_fallback) label_slot_or_fallback.c();
829
- t = space();
830
- input = element("input");
831
- attr(label_1, "id", label_1_id_value = "" + (/*id*/ ctx[4] + "-label"));
832
- attr(label_1, "for", /*id*/ ctx[4]);
833
- attr(label_1, "class", "svelte-5m0wg6");
834
- toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]);
835
- set_attributes(input, input_data);
836
- toggle_class(input, "svelte-5m0wg6", true);
837
- attr(form, "data-svelte-search", "");
838
- attr(form, "role", form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search");
839
-
840
- attr(form, "aria-labelledby", form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5]
841
- ? null
842
- : /*id*/ ctx[4]);
843
- },
844
- m(target, anchor) {
845
- insert(target, form, anchor);
846
- append(form, label_1);
847
-
848
- if (label_slot_or_fallback) {
849
- label_slot_or_fallback.m(label_1, null);
850
- }
851
-
852
- append(form, t);
853
- append(form, input);
854
- if (input.autofocus) input.focus();
855
- /*input_binding*/ ctx[17](input);
856
- set_input_value(input, /*value*/ ctx[0]);
857
- current = true;
858
-
859
- if (!mounted) {
860
- dispose = [
861
- listen(input, "input", /*input_input_handler*/ ctx[18]),
862
- listen(input, "input", /*input_handler*/ ctx[12]),
863
- listen(input, "change", /*change_handler*/ ctx[13]),
864
- listen(input, "focus", /*focus_handler*/ ctx[14]),
865
- listen(input, "blur", /*blur_handler*/ ctx[15]),
866
- listen(input, "keydown", /*keydown_handler*/ ctx[16]),
867
- listen(form, "submit", prevent_default(/*submit_handler*/ ctx[11]))
868
- ];
869
-
870
- mounted = true;
871
- }
872
- },
873
- p(ctx, [dirty]) {
874
- if (label_slot) {
875
- if (label_slot.p && (!current || dirty & /*$$scope*/ 512)) {
876
- update_slot_base(
877
- label_slot,
878
- label_slot_template,
879
- ctx,
880
- /*$$scope*/ ctx[9],
881
- !current
882
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[9])
883
- : get_slot_changes(label_slot_template, /*$$scope*/ ctx[9], dirty, get_label_slot_changes),
884
- get_label_slot_context
885
- );
886
- }
887
- } else {
888
- if (label_slot_or_fallback && label_slot_or_fallback.p && (!current || dirty & /*label*/ 4)) {
889
- label_slot_or_fallback.p(ctx, !current ? -1 : dirty);
890
- }
891
- }
892
-
893
- if (!current || dirty & /*id*/ 16 && label_1_id_value !== (label_1_id_value = "" + (/*id*/ ctx[4] + "-label"))) {
894
- attr(label_1, "id", label_1_id_value);
895
- }
896
-
897
- if (!current || dirty & /*id*/ 16) {
898
- attr(label_1, "for", /*id*/ ctx[4]);
899
- }
900
-
901
- if (!current || dirty & /*hideLabel*/ 8) {
902
- toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]);
903
- }
904
-
905
- set_attributes(input, input_data = get_spread_update(input_levels, [
906
- { name: "search" },
907
- { type: "search" },
908
- { placeholder: "Search..." },
909
- { autocomplete: "off" },
910
- { spellcheck: "false" },
911
- dirty & /*$$restProps*/ 64 && /*$$restProps*/ ctx[6],
912
- (!current || dirty & /*id*/ 16) && { id: /*id*/ ctx[4] }
913
- ]));
914
-
915
- if (dirty & /*value*/ 1) {
916
- set_input_value(input, /*value*/ ctx[0]);
917
- }
918
-
919
- toggle_class(input, "svelte-5m0wg6", true);
920
-
921
- if (!current || dirty & /*removeFormAriaAttributes*/ 32 && form_role_value !== (form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search")) {
922
- attr(form, "role", form_role_value);
923
- }
924
-
925
- if (!current || dirty & /*removeFormAriaAttributes, id*/ 48 && form_aria_labelledby_value !== (form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5]
926
- ? null
927
- : /*id*/ ctx[4])) {
928
- attr(form, "aria-labelledby", form_aria_labelledby_value);
929
- }
930
- },
931
- i(local) {
932
- if (current) return;
933
- transition_in(label_slot_or_fallback, local);
934
- current = true;
935
- },
936
- o(local) {
937
- transition_out(label_slot_or_fallback, local);
938
- current = false;
939
- },
940
- d(detaching) {
941
- if (detaching) detach(form);
942
- if (label_slot_or_fallback) label_slot_or_fallback.d(detaching);
943
- /*input_binding*/ ctx[17](null);
944
- mounted = false;
945
- run_all(dispose);
946
- }
947
- };
948
- }
949
-
950
- function instance$1($$self, $$props, $$invalidate) {
951
- const omit_props_names = [
952
- "value","autofocus","debounce","label","hideLabel","id","ref","removeFormAriaAttributes"
953
- ];
954
-
955
- let $$restProps = compute_rest_props($$props, omit_props_names);
956
- let { $$slots: slots = {}, $$scope } = $$props;
957
- let { value = "" } = $$props;
958
- let { autofocus = false } = $$props;
959
- let { debounce = 0 } = $$props;
960
- let { label = "Label" } = $$props;
961
- let { hideLabel = false } = $$props;
962
- let { id = "search" + Math.random().toString(36) } = $$props;
963
- let { ref = null } = $$props;
964
- let { removeFormAriaAttributes = false } = $$props;
965
- const dispatch = createEventDispatcher();
966
- let prevValue = value;
967
- let timeout = undefined;
968
- let calling = false;
969
-
970
- function debounced(cb) {
971
- if (calling) return;
972
- calling = true;
973
-
974
- timeout = setTimeout(
975
- () => {
976
- cb();
977
- calling = false;
978
- },
979
- debounce
980
- );
981
- }
982
-
983
- onMount(() => {
984
- if (autofocus) window.requestAnimationFrame(() => ref.focus());
985
- return () => clearTimeout(timeout);
986
- });
987
-
988
- afterUpdate(() => {
989
- if (value.length > 0 && value !== prevValue) {
990
- if (debounce > 0) {
991
- debounced(() => dispatch("type", value));
992
- } else {
993
- dispatch("type", value);
994
- }
995
- }
996
-
997
- if (value.length === 0 && prevValue.length > 0) dispatch("clear");
998
- prevValue = value;
999
- });
1000
-
1001
- function submit_handler(event) {
1002
- bubble.call(this, $$self, event);
1003
- }
1004
-
1005
- function input_handler(event) {
1006
- bubble.call(this, $$self, event);
1007
- }
1008
-
1009
- function change_handler(event) {
1010
- bubble.call(this, $$self, event);
1011
- }
1012
-
1013
- function focus_handler(event) {
1014
- bubble.call(this, $$self, event);
1015
- }
1016
-
1017
- function blur_handler(event) {
1018
- bubble.call(this, $$self, event);
1019
- }
1020
-
1021
- function keydown_handler(event) {
1022
- bubble.call(this, $$self, event);
1023
- }
1024
-
1025
- function input_binding($$value) {
1026
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1027
- ref = $$value;
1028
- $$invalidate(1, ref);
1029
- });
1030
- }
1031
-
1032
- function input_input_handler() {
1033
- value = this.value;
1034
- $$invalidate(0, value);
1035
- }
1036
-
1037
- $$self.$$set = $$new_props => {
1038
- $$props = assign(assign({}, $$props), exclude_internal_props($$new_props));
1039
- $$invalidate(6, $$restProps = compute_rest_props($$props, omit_props_names));
1040
- if ('value' in $$new_props) $$invalidate(0, value = $$new_props.value);
1041
- if ('autofocus' in $$new_props) $$invalidate(7, autofocus = $$new_props.autofocus);
1042
- if ('debounce' in $$new_props) $$invalidate(8, debounce = $$new_props.debounce);
1043
- if ('label' in $$new_props) $$invalidate(2, label = $$new_props.label);
1044
- if ('hideLabel' in $$new_props) $$invalidate(3, hideLabel = $$new_props.hideLabel);
1045
- if ('id' in $$new_props) $$invalidate(4, id = $$new_props.id);
1046
- if ('ref' in $$new_props) $$invalidate(1, ref = $$new_props.ref);
1047
- if ('removeFormAriaAttributes' in $$new_props) $$invalidate(5, removeFormAriaAttributes = $$new_props.removeFormAriaAttributes);
1048
- if ('$$scope' in $$new_props) $$invalidate(9, $$scope = $$new_props.$$scope);
1049
- };
1050
-
1051
- return [
1052
- value,
1053
- ref,
1054
- label,
1055
- hideLabel,
1056
- id,
1057
- removeFormAriaAttributes,
1058
- $$restProps,
1059
- autofocus,
1060
- debounce,
1061
- $$scope,
1062
- slots,
1063
- submit_handler,
1064
- input_handler,
1065
- change_handler,
1066
- focus_handler,
1067
- blur_handler,
1068
- keydown_handler,
1069
- input_binding,
1070
- input_input_handler
1071
- ];
1072
- }
1073
-
1074
- class Search extends SvelteComponent {
1075
- constructor(options) {
1076
- super();
1077
-
1078
- init(
1079
- this,
1080
- options,
1081
- instance$1,
1082
- create_fragment$1,
1083
- safe_not_equal,
1084
- {
1085
- value: 0,
1086
- autofocus: 7,
1087
- debounce: 8,
1088
- label: 2,
1089
- hideLabel: 3,
1090
- id: 4,
1091
- ref: 1,
1092
- removeFormAriaAttributes: 5
1093
- },
1094
- add_css$1
1095
- );
1096
- }
1097
- }
1098
-
1099
- var Search$1 = Search;
1100
-
1101
- /* src/Typeahead.svelte generated by Svelte v3.52.0 */
1102
-
1103
- function add_css(target) {
1104
- append_styles(target, "svelte-1t4elht", "[data-svelte-typeahead].svelte-1t4elht.svelte-1t4elht{position:relative;background-color:#fff}ul.svelte-1t4elht.svelte-1t4elht{position:absolute;top:100%;left:0;width:100%;margin:0;padding:0;list-style:none;background-color:inherit;box-shadow:0 4px 8px rgba(0, 0, 0, 0.1)}[aria-expanded=\"true\"].svelte-1t4elht ul.svelte-1t4elht{z-index:1}li.svelte-1t4elht.svelte-1t4elht,.no-results.svelte-1t4elht.svelte-1t4elht{padding:0.25rem 1rem}li.svelte-1t4elht.svelte-1t4elht{cursor:pointer}li.svelte-1t4elht.svelte-1t4elht:not(:last-of-type){border-bottom:1px solid #e0e0e0}li.svelte-1t4elht.svelte-1t4elht:hover{background-color:#e5e5e5}.selected.svelte-1t4elht.svelte-1t4elht{background-color:#e5e5e5}.selected.svelte-1t4elht.svelte-1t4elht:hover{background-color:#cacaca}.disabled.svelte-1t4elht.svelte-1t4elht{opacity:0.4;cursor:not-allowed}[data-svelte-search] label{margin-bottom:0.25rem;display:inline-flex;font-size:0.875rem}[data-svelte-search] input{width:100%;padding:0.5rem 0.75rem;background:none;font-size:1rem;border:0;border-radius:0;border:1px solid #e5e5e5}[data-svelte-search] input:focus{outline-color:#0f62fe;outline-offset:2px;outline-width:1px}");
1105
- }
1106
-
1107
- const get_no_results_slot_changes = dirty => ({
1108
- value: dirty[0] & /*value*/ 1,
1109
- result: dirty[0] & /*results*/ 2
1110
- });
1111
-
1112
- const get_no_results_slot_context = ctx => ({
1113
- value: /*value*/ ctx[0],
1114
- result: /*result*/ ctx[47],
1115
- index: /*index*/ ctx[49]
1116
- });
1117
-
1118
- function get_each_context(ctx, list, i) {
1119
- const child_ctx = ctx.slice();
1120
- child_ctx[47] = list[i];
1121
- child_ctx[49] = i;
1122
- return child_ctx;
1123
- }
1124
-
1125
- const get_default_slot_changes = dirty => ({
1126
- result: dirty[0] & /*results*/ 2,
1127
- value: dirty[0] & /*value*/ 1
1128
- });
1129
-
1130
- const get_default_slot_context = ctx => ({
1131
- result: /*result*/ ctx[47],
1132
- index: /*index*/ ctx[49],
1133
- value: /*value*/ ctx[0]
1134
- });
1135
-
1136
- // (247:4) {#if showResults}
1137
- function create_if_block_1(ctx) {
1138
- let each_1_anchor;
1139
- let current;
1140
- let each_value = /*results*/ ctx[1];
1141
- let each_blocks = [];
1142
-
1143
- for (let i = 0; i < each_value.length; i += 1) {
1144
- each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
1145
- }
1146
-
1147
- const out = i => transition_out(each_blocks[i], 1, 1, () => {
1148
- each_blocks[i] = null;
1149
- });
1150
-
1151
- return {
1152
- c() {
1153
- for (let i = 0; i < each_blocks.length; i += 1) {
1154
- each_blocks[i].c();
1155
- }
1156
-
1157
- each_1_anchor = empty();
1158
- },
1159
- m(target, anchor) {
1160
- for (let i = 0; i < each_blocks.length; i += 1) {
1161
- each_blocks[i].m(target, anchor);
1162
- }
1163
-
1164
- insert(target, each_1_anchor, anchor);
1165
- current = true;
1166
- },
1167
- p(ctx, dirty) {
1168
- if (dirty[0] & /*id, selectedIndex, results, select, $$scope, value*/ 67111943) {
1169
- each_value = /*results*/ ctx[1];
1170
- let i;
1171
-
1172
- for (i = 0; i < each_value.length; i += 1) {
1173
- const child_ctx = get_each_context(ctx, each_value, i);
1174
-
1175
- if (each_blocks[i]) {
1176
- each_blocks[i].p(child_ctx, dirty);
1177
- transition_in(each_blocks[i], 1);
1178
- } else {
1179
- each_blocks[i] = create_each_block(child_ctx);
1180
- each_blocks[i].c();
1181
- transition_in(each_blocks[i], 1);
1182
- each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
1183
- }
1184
- }
1185
-
1186
- group_outros();
1187
-
1188
- for (i = each_value.length; i < each_blocks.length; i += 1) {
1189
- out(i);
1190
- }
1191
-
1192
- check_outros();
1193
- }
1194
- },
1195
- i(local) {
1196
- if (current) return;
1197
-
1198
- for (let i = 0; i < each_value.length; i += 1) {
1199
- transition_in(each_blocks[i]);
1200
- }
1201
-
1202
- current = true;
1203
- },
1204
- o(local) {
1205
- each_blocks = each_blocks.filter(Boolean);
1206
-
1207
- for (let i = 0; i < each_blocks.length; i += 1) {
1208
- transition_out(each_blocks[i]);
1209
- }
1210
-
1211
- current = false;
1212
- },
1213
- d(detaching) {
1214
- destroy_each(each_blocks, detaching);
1215
- if (detaching) detach(each_1_anchor);
1216
- }
1217
- };
1218
- }
1219
-
1220
- // (266:41)
1221
- function fallback_block(ctx) {
1222
- let html_tag;
1223
- let raw_value = /*result*/ ctx[47].string + "";
1224
- let html_anchor;
1225
-
1226
- return {
1227
- c() {
1228
- html_tag = new HtmlTag(false);
1229
- html_anchor = empty();
1230
- html_tag.a = html_anchor;
1231
- },
1232
- m(target, anchor) {
1233
- html_tag.m(raw_value, target, anchor);
1234
- insert(target, html_anchor, anchor);
1235
- },
1236
- p(ctx, dirty) {
1237
- if (dirty[0] & /*results*/ 2 && raw_value !== (raw_value = /*result*/ ctx[47].string + "")) html_tag.p(raw_value);
1238
- },
1239
- d(detaching) {
1240
- if (detaching) detach(html_anchor);
1241
- if (detaching) html_tag.d();
1242
- }
1243
- };
1244
- }
1245
-
1246
- // (248:6) {#each results as result, index}
1247
- function create_each_block(ctx) {
1248
- let li;
1249
- let t;
1250
- let li_id_value;
1251
- let li_aria_selected_value;
1252
- let current;
1253
- let mounted;
1254
- let dispose;
1255
- const default_slot_template = /*#slots*/ ctx[27].default;
1256
- const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[26], get_default_slot_context);
1257
- const default_slot_or_fallback = default_slot || fallback_block(ctx);
1258
-
1259
- function click_handler_1() {
1260
- return /*click_handler_1*/ ctx[40](/*result*/ ctx[47], /*index*/ ctx[49]);
1261
- }
1262
-
1263
- function mouseenter_handler() {
1264
- return /*mouseenter_handler*/ ctx[41](/*result*/ ctx[47], /*index*/ ctx[49]);
1265
- }
1266
-
1267
- return {
1268
- c() {
1269
- li = element("li");
1270
- if (default_slot_or_fallback) default_slot_or_fallback.c();
1271
- t = space();
1272
- attr(li, "role", "option");
1273
- attr(li, "id", li_id_value = "" + (/*id*/ ctx[2] + "-result-" + /*index*/ ctx[49]));
1274
- attr(li, "aria-selected", li_aria_selected_value = /*selectedIndex*/ ctx[10] === /*index*/ ctx[49]);
1275
- attr(li, "class", "svelte-1t4elht");
1276
- toggle_class(li, "selected", /*selectedIndex*/ ctx[10] === /*index*/ ctx[49]);
1277
- toggle_class(li, "disabled", /*result*/ ctx[47].disabled);
1278
- },
1279
- m(target, anchor) {
1280
- insert(target, li, anchor);
1281
-
1282
- if (default_slot_or_fallback) {
1283
- default_slot_or_fallback.m(li, null);
1284
- }
1285
-
1286
- append(li, t);
1287
- current = true;
1288
-
1289
- if (!mounted) {
1290
- dispose = [
1291
- listen(li, "click", click_handler_1),
1292
- listen(li, "mouseenter", mouseenter_handler)
1293
- ];
1294
-
1295
- mounted = true;
1296
- }
1297
- },
1298
- p(new_ctx, dirty) {
1299
- ctx = new_ctx;
1300
-
1301
- if (default_slot) {
1302
- if (default_slot.p && (!current || dirty[0] & /*$$scope, results, value*/ 67108867)) {
1303
- update_slot_base(
1304
- default_slot,
1305
- default_slot_template,
1306
- ctx,
1307
- /*$$scope*/ ctx[26],
1308
- !current
1309
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
1310
- : get_slot_changes(default_slot_template, /*$$scope*/ ctx[26], dirty, get_default_slot_changes),
1311
- get_default_slot_context
1312
- );
1313
- }
1314
- } else {
1315
- if (default_slot_or_fallback && default_slot_or_fallback.p && (!current || dirty[0] & /*results*/ 2)) {
1316
- default_slot_or_fallback.p(ctx, !current ? [-1, -1] : dirty);
1317
- }
1318
- }
1319
-
1320
- if (!current || dirty[0] & /*id*/ 4 && li_id_value !== (li_id_value = "" + (/*id*/ ctx[2] + "-result-" + /*index*/ ctx[49]))) {
1321
- attr(li, "id", li_id_value);
1322
- }
1323
-
1324
- if (!current || dirty[0] & /*selectedIndex*/ 1024 && li_aria_selected_value !== (li_aria_selected_value = /*selectedIndex*/ ctx[10] === /*index*/ ctx[49])) {
1325
- attr(li, "aria-selected", li_aria_selected_value);
1326
- }
1327
-
1328
- if (!current || dirty[0] & /*selectedIndex*/ 1024) {
1329
- toggle_class(li, "selected", /*selectedIndex*/ ctx[10] === /*index*/ ctx[49]);
1330
- }
1331
-
1332
- if (!current || dirty[0] & /*results*/ 2) {
1333
- toggle_class(li, "disabled", /*result*/ ctx[47].disabled);
1334
- }
1335
- },
1336
- i(local) {
1337
- if (current) return;
1338
- transition_in(default_slot_or_fallback, local);
1339
- current = true;
1340
- },
1341
- o(local) {
1342
- transition_out(default_slot_or_fallback, local);
1343
- current = false;
1344
- },
1345
- d(detaching) {
1346
- if (detaching) detach(li);
1347
- if (default_slot_or_fallback) default_slot_or_fallback.d(detaching);
1348
- mounted = false;
1349
- run_all(dispose);
1350
- }
1351
- };
1352
- }
1353
-
1354
- // (272:4) {#if $$slots["no-results"] && !hideDropdown && value.length > 0 && results.length === 0}
1355
- function create_if_block(ctx) {
1356
- let div;
1357
- let current;
1358
- const no_results_slot_template = /*#slots*/ ctx[27]["no-results"];
1359
- const no_results_slot = create_slot(no_results_slot_template, ctx, /*$$scope*/ ctx[26], get_no_results_slot_context);
1360
-
1361
- return {
1362
- c() {
1363
- div = element("div");
1364
- if (no_results_slot) no_results_slot.c();
1365
- attr(div, "class", "svelte-1t4elht");
1366
- toggle_class(div, "no-results", true);
1367
- },
1368
- m(target, anchor) {
1369
- insert(target, div, anchor);
1370
-
1371
- if (no_results_slot) {
1372
- no_results_slot.m(div, null);
1373
- }
1374
-
1375
- current = true;
1376
- },
1377
- p(ctx, dirty) {
1378
- if (no_results_slot) {
1379
- if (no_results_slot.p && (!current || dirty[0] & /*$$scope, value, results*/ 67108867)) {
1380
- update_slot_base(
1381
- no_results_slot,
1382
- no_results_slot_template,
1383
- ctx,
1384
- /*$$scope*/ ctx[26],
1385
- !current
1386
- ? get_all_dirty_from_scope(/*$$scope*/ ctx[26])
1387
- : get_slot_changes(no_results_slot_template, /*$$scope*/ ctx[26], dirty, get_no_results_slot_changes),
1388
- get_no_results_slot_context
1389
- );
1390
- }
1391
- }
1392
- },
1393
- i(local) {
1394
- if (current) return;
1395
- transition_in(no_results_slot, local);
1396
- current = true;
1397
- },
1398
- o(local) {
1399
- transition_out(no_results_slot, local);
1400
- current = false;
1401
- },
1402
- d(detaching) {
1403
- if (detaching) detach(div);
1404
- if (no_results_slot) no_results_slot.d(detaching);
1405
- }
1406
- };
1407
- }
1408
-
1409
- function create_fragment(ctx) {
1410
- let div;
1411
- let search;
1412
- let updating_ref;
1413
- let updating_value;
1414
- let t0;
1415
- let ul;
1416
- let t1;
1417
- let ul_aria_labelledby_value;
1418
- let ul_id_value;
1419
- let div_aria_controls_value;
1420
- let div_id_value;
1421
- let current;
1422
- let mounted;
1423
- let dispose;
1424
-
1425
- const search_spread_levels = [
1426
- { id: /*id*/ ctx[2] },
1427
- { removeFormAriaAttributes: true },
1428
- /*$$restProps*/ ctx[16],
1429
- { "aria-autocomplete": "list" },
1430
- {
1431
- "aria-controls": "" + (/*id*/ ctx[2] + "-listbox")
1432
- },
1433
- {
1434
- "aria-labelledby": "" + (/*id*/ ctx[2] + "-label")
1435
- },
1436
- {
1437
- "aria-activedescendant": /*selectedIndex*/ ctx[10] >= 0 && !/*hideDropdown*/ ctx[5] && /*results*/ ctx[1].length > 0
1438
- ? `${/*id*/ ctx[2]}-result-${/*selectedIndex*/ ctx[10]}`
1439
- : null
1440
- }
1441
- ];
1442
-
1443
- function search_ref_binding(value) {
1444
- /*search_ref_binding*/ ctx[29](value);
1445
- }
1446
-
1447
- function search_value_binding(value) {
1448
- /*search_value_binding*/ ctx[30](value);
1449
- }
1450
-
1451
- let search_props = {};
1452
-
1453
- for (let i = 0; i < search_spread_levels.length; i += 1) {
1454
- search_props = assign(search_props, search_spread_levels[i]);
1455
- }
1456
-
1457
- if (/*searchRef*/ ctx[9] !== void 0) {
1458
- search_props.ref = /*searchRef*/ ctx[9];
1459
- }
1460
-
1461
- if (/*value*/ ctx[0] !== void 0) {
1462
- search_props.value = /*value*/ ctx[0];
1463
- }
1464
-
1465
- search = new Search$1({ props: search_props });
1466
- binding_callbacks.push(() => bind(search, 'ref', search_ref_binding));
1467
- binding_callbacks.push(() => bind(search, 'value', search_value_binding));
1468
- search.$on("type", /*type_handler*/ ctx[31]);
1469
- search.$on("input", /*input_handler*/ ctx[32]);
1470
- search.$on("change", /*change_handler*/ ctx[33]);
1471
- search.$on("focus", /*focus_handler*/ ctx[34]);
1472
- search.$on("focus", /*focus_handler_1*/ ctx[35]);
1473
- search.$on("clear", /*clear_handler*/ ctx[36]);
1474
- search.$on("clear", /*open*/ ctx[13]);
1475
- search.$on("blur", /*blur_handler*/ ctx[37]);
1476
- search.$on("keydown", /*keydown_handler*/ ctx[38]);
1477
- search.$on("keydown", /*keydown_handler_1*/ ctx[39]);
1478
- let if_block0 = /*showResults*/ ctx[7] && create_if_block_1(ctx);
1479
- let if_block1 = /*$$slots*/ ctx[15]["no-results"] && !/*hideDropdown*/ ctx[5] && /*value*/ ctx[0].length > 0 && /*results*/ ctx[1].length === 0 && create_if_block(ctx);
1480
-
1481
- return {
1482
- c() {
1483
- div = element("div");
1484
- create_component(search.$$.fragment);
1485
- t0 = space();
1486
- ul = element("ul");
1487
- if (if_block0) if_block0.c();
1488
- t1 = space();
1489
- if (if_block1) if_block1.c();
1490
- attr(ul, "role", "listbox");
1491
- attr(ul, "aria-labelledby", ul_aria_labelledby_value = "" + (/*id*/ ctx[2] + "-label"));
1492
- attr(ul, "id", ul_id_value = "" + (/*id*/ ctx[2] + "-listbox"));
1493
- attr(ul, "class", "svelte-1t4elht");
1494
- toggle_class(ul, "svelte-typeahead-list", true);
1495
- attr(div, "data-svelte-typeahead", "");
1496
- attr(div, "role", "combobox");
1497
- attr(div, "aria-haspopup", "listbox");
1498
- attr(div, "aria-controls", div_aria_controls_value = "" + (/*id*/ ctx[2] + "-listbox"));
1499
- attr(div, "aria-expanded", /*showResults*/ ctx[7]);
1500
- attr(div, "id", div_id_value = "" + (/*id*/ ctx[2] + "-typeahead"));
1501
- attr(div, "class", "svelte-1t4elht");
1502
- toggle_class(div, "dropdown", /*results*/ ctx[1].length > 0);
1503
- },
1504
- m(target, anchor) {
1505
- insert(target, div, anchor);
1506
- mount_component(search, div, null);
1507
- append(div, t0);
1508
- append(div, ul);
1509
- if (if_block0) if_block0.m(ul, null);
1510
- append(ul, t1);
1511
- if (if_block1) if_block1.m(ul, null);
1512
- /*div_binding*/ ctx[42](div);
1513
- current = true;
1514
-
1515
- if (!mounted) {
1516
- dispose = listen(window, "click", /*click_handler*/ ctx[28]);
1517
- mounted = true;
1518
- }
1519
- },
1520
- p(ctx, dirty) {
1521
- const search_changes = (dirty[0] & /*id, $$restProps, selectedIndex, hideDropdown, results*/ 66598)
1522
- ? get_spread_update(search_spread_levels, [
1523
- dirty[0] & /*id*/ 4 && { id: /*id*/ ctx[2] },
1524
- search_spread_levels[1],
1525
- dirty[0] & /*$$restProps*/ 65536 && get_spread_object(/*$$restProps*/ ctx[16]),
1526
- search_spread_levels[3],
1527
- dirty[0] & /*id*/ 4 && {
1528
- "aria-controls": "" + (/*id*/ ctx[2] + "-listbox")
1529
- },
1530
- dirty[0] & /*id*/ 4 && {
1531
- "aria-labelledby": "" + (/*id*/ ctx[2] + "-label")
1532
- },
1533
- dirty[0] & /*selectedIndex, hideDropdown, results, id*/ 1062 && {
1534
- "aria-activedescendant": /*selectedIndex*/ ctx[10] >= 0 && !/*hideDropdown*/ ctx[5] && /*results*/ ctx[1].length > 0
1535
- ? `${/*id*/ ctx[2]}-result-${/*selectedIndex*/ ctx[10]}`
1536
- : null
1537
- }
1538
- ])
1539
- : {};
1540
-
1541
- if (!updating_ref && dirty[0] & /*searchRef*/ 512) {
1542
- updating_ref = true;
1543
- search_changes.ref = /*searchRef*/ ctx[9];
1544
- add_flush_callback(() => updating_ref = false);
1545
- }
1546
-
1547
- if (!updating_value && dirty[0] & /*value*/ 1) {
1548
- updating_value = true;
1549
- search_changes.value = /*value*/ ctx[0];
1550
- add_flush_callback(() => updating_value = false);
1551
- }
1552
-
1553
- search.$set(search_changes);
1554
-
1555
- if (/*showResults*/ ctx[7]) {
1556
- if (if_block0) {
1557
- if_block0.p(ctx, dirty);
1558
-
1559
- if (dirty[0] & /*showResults*/ 128) {
1560
- transition_in(if_block0, 1);
1561
- }
1562
- } else {
1563
- if_block0 = create_if_block_1(ctx);
1564
- if_block0.c();
1565
- transition_in(if_block0, 1);
1566
- if_block0.m(ul, t1);
1567
- }
1568
- } else if (if_block0) {
1569
- group_outros();
1570
-
1571
- transition_out(if_block0, 1, 1, () => {
1572
- if_block0 = null;
1573
- });
1574
-
1575
- check_outros();
1576
- }
1577
-
1578
- if (/*$$slots*/ ctx[15]["no-results"] && !/*hideDropdown*/ ctx[5] && /*value*/ ctx[0].length > 0 && /*results*/ ctx[1].length === 0) {
1579
- if (if_block1) {
1580
- if_block1.p(ctx, dirty);
1581
-
1582
- if (dirty[0] & /*$$slots, hideDropdown, value, results*/ 32803) {
1583
- transition_in(if_block1, 1);
1584
- }
1585
- } else {
1586
- if_block1 = create_if_block(ctx);
1587
- if_block1.c();
1588
- transition_in(if_block1, 1);
1589
- if_block1.m(ul, null);
1590
- }
1591
- } else if (if_block1) {
1592
- group_outros();
1593
-
1594
- transition_out(if_block1, 1, 1, () => {
1595
- if_block1 = null;
1596
- });
1597
-
1598
- check_outros();
1599
- }
1600
-
1601
- if (!current || dirty[0] & /*id*/ 4 && ul_aria_labelledby_value !== (ul_aria_labelledby_value = "" + (/*id*/ ctx[2] + "-label"))) {
1602
- attr(ul, "aria-labelledby", ul_aria_labelledby_value);
1603
- }
1604
-
1605
- if (!current || dirty[0] & /*id*/ 4 && ul_id_value !== (ul_id_value = "" + (/*id*/ ctx[2] + "-listbox"))) {
1606
- attr(ul, "id", ul_id_value);
1607
- }
1608
-
1609
- if (!current || dirty[0] & /*id*/ 4 && div_aria_controls_value !== (div_aria_controls_value = "" + (/*id*/ ctx[2] + "-listbox"))) {
1610
- attr(div, "aria-controls", div_aria_controls_value);
1611
- }
1612
-
1613
- if (!current || dirty[0] & /*showResults*/ 128) {
1614
- attr(div, "aria-expanded", /*showResults*/ ctx[7]);
1615
- }
1616
-
1617
- if (!current || dirty[0] & /*id*/ 4 && div_id_value !== (div_id_value = "" + (/*id*/ ctx[2] + "-typeahead"))) {
1618
- attr(div, "id", div_id_value);
1619
- }
1620
-
1621
- if (!current || dirty[0] & /*results*/ 2) {
1622
- toggle_class(div, "dropdown", /*results*/ ctx[1].length > 0);
1623
- }
1624
- },
1625
- i(local) {
1626
- if (current) return;
1627
- transition_in(search.$$.fragment, local);
1628
- transition_in(if_block0);
1629
- transition_in(if_block1);
1630
- current = true;
1631
- },
1632
- o(local) {
1633
- transition_out(search.$$.fragment, local);
1634
- transition_out(if_block0);
1635
- transition_out(if_block1);
1636
- current = false;
1637
- },
1638
- d(detaching) {
1639
- if (detaching) detach(div);
1640
- destroy_component(search);
1641
- if (if_block0) if_block0.d();
1642
- if (if_block1) if_block1.d();
1643
- /*div_binding*/ ctx[42](null);
1644
- mounted = false;
1645
- dispose();
1646
- }
1647
- };
1648
- }
1649
-
1650
- function instance($$self, $$props, $$invalidate) {
1651
- let options;
1652
- let resultsId;
1653
- let showResults;
1654
-
1655
- const omit_props_names = [
1656
- "id","value","data","extract","disable","filter","autoselect","inputAfterSelect","results","focusAfterSelect","showDropdownOnFocus","showAllResultsOnFocus","limit"
1657
- ];
1658
-
1659
- let $$restProps = compute_rest_props($$props, omit_props_names);
1660
- let { $$slots: slots = {}, $$scope } = $$props;
1661
- const $$slots = compute_slots(slots);
1662
- let { id = "typeahead-" + Math.random().toString(36) } = $$props;
1663
- let { value = "" } = $$props;
1664
- let { data = [] } = $$props;
1665
- let { extract = item => item } = $$props;
1666
- let { disable = item => false } = $$props;
1667
- let { filter = item => false } = $$props;
1668
- let { autoselect = true } = $$props;
1669
- let { inputAfterSelect = "update" } = $$props;
1670
- let { results = [] } = $$props;
1671
- let { focusAfterSelect = false } = $$props;
1672
- let { showDropdownOnFocus = false } = $$props;
1673
- let { showAllResultsOnFocus = false } = $$props;
1674
- let { limit = Infinity } = $$props;
1675
- const dispatch = createEventDispatcher();
1676
- let comboboxRef = null;
1677
- let searchRef = null;
1678
- let hideDropdown = false;
1679
- let selectedIndex = -1;
1680
- let prevResults = "";
1681
- let isFocused = false;
1682
-
1683
- afterUpdate(() => {
1684
- if (prevResults !== resultsId && autoselect) {
1685
- $$invalidate(10, selectedIndex = getNextNonDisabledIndex());
1686
- }
1687
-
1688
- if (prevResults !== resultsId && !$$slots["no-results"]) {
1689
- $$invalidate(5, hideDropdown = results.length === 0);
1690
- }
1691
-
1692
- prevResults = resultsId;
1693
- });
1694
-
1695
- async function select() {
1696
- const result = results[selectedIndex];
1697
- if (result.disabled) return;
1698
- const selectedValue = extract(result.original);
1699
- const searchedValue = value;
1700
- if (inputAfterSelect == "clear") $$invalidate(0, value = "");
1701
- if (inputAfterSelect == "update") $$invalidate(0, value = selectedValue);
1702
-
1703
- dispatch("select", {
1704
- selectedIndex,
1705
- searched: searchedValue,
1706
- selected: selectedValue,
1707
- original: result.original,
1708
- originalIndex: result.index
1709
- });
1710
-
1711
- await tick();
1712
- if (focusAfterSelect) searchRef.focus();
1713
- close();
1714
- }
1715
-
1716
- /** @type {() => number} */
1717
- function getNextNonDisabledIndex() {
1718
- let index = 0;
1719
- let disabled = results[index]?.disabled ?? false;
1720
-
1721
- while (disabled) {
1722
- if (index === results.length) {
1723
- index = 0;
1724
- } else {
1725
- index += 1;
1726
- }
1727
-
1728
- disabled = results[index]?.disabled ?? false;
1729
- }
1730
-
1731
- return index;
1732
- }
1733
-
1734
- /** @type {(direction: -1 | 1) => void} */
1735
- function change(direction) {
1736
- let index = direction === 1 && selectedIndex === results.length - 1
1737
- ? 0
1738
- : selectedIndex + direction;
1739
-
1740
- if (index < 0) index = results.length - 1;
1741
- let disabled = results[index].disabled;
1742
-
1743
- while (disabled) {
1744
- if (index === results.length) {
1745
- index = 0;
1746
- } else {
1747
- index += direction;
1748
- }
1749
-
1750
- disabled = results[index].disabled;
1751
- }
1752
-
1753
- $$invalidate(10, selectedIndex = index);
1754
- }
1755
-
1756
- const open = () => $$invalidate(5, hideDropdown = false);
1757
-
1758
- const close = () => {
1759
- $$invalidate(5, hideDropdown = true);
1760
- $$invalidate(6, isFocused = false);
1761
- };
1762
-
1763
- const click_handler = ({ target }) => {
1764
- if (!hideDropdown && !comboboxRef?.contains(target)) {
1765
- close();
1766
- }
1767
- };
1768
-
1769
- function search_ref_binding(value) {
1770
- searchRef = value;
1771
- $$invalidate(9, searchRef);
1772
- }
1773
-
1774
- function search_value_binding(value$1) {
1775
- value = value$1;
1776
- $$invalidate(0, value);
1777
- }
1778
-
1779
- function type_handler(event) {
1780
- bubble.call(this, $$self, event);
1781
- }
1782
-
1783
- function input_handler(event) {
1784
- bubble.call(this, $$self, event);
1785
- }
1786
-
1787
- function change_handler(event) {
1788
- bubble.call(this, $$self, event);
1789
- }
1790
-
1791
- function focus_handler(event) {
1792
- bubble.call(this, $$self, event);
1793
- }
1794
-
1795
- const focus_handler_1 = () => {
1796
- open();
1797
-
1798
- if (showDropdownOnFocus || showAllResultsOnFocus) {
1799
- $$invalidate(7, showResults = true);
1800
- $$invalidate(6, isFocused = true);
1801
- }
1802
- };
1803
-
1804
- function clear_handler(event) {
1805
- bubble.call(this, $$self, event);
1806
- }
1807
-
1808
- function blur_handler(event) {
1809
- bubble.call(this, $$self, event);
1810
- }
1811
-
1812
- function keydown_handler(event) {
1813
- bubble.call(this, $$self, event);
1814
- }
1815
-
1816
- const keydown_handler_1 = e => {
1817
- if (results.length === 0) return;
1818
-
1819
- switch (e.key) {
1820
- case "Enter":
1821
- select();
1822
- break;
1823
- case "ArrowDown":
1824
- e.preventDefault();
1825
- change(1);
1826
- break;
1827
- case "ArrowUp":
1828
- e.preventDefault();
1829
- change(-1);
1830
- break;
1831
- case "Escape":
1832
- e.preventDefault();
1833
- $$invalidate(0, value = "");
1834
- searchRef?.focus();
1835
- close();
1836
- break;
1837
- }
1838
- };
1839
-
1840
- const click_handler_1 = (result, index) => {
1841
- if (result.disabled) return;
1842
- $$invalidate(10, selectedIndex = index);
1843
- select();
1844
- };
1845
-
1846
- const mouseenter_handler = (result, index) => {
1847
- if (result.disabled) return;
1848
- $$invalidate(10, selectedIndex = index);
1849
- };
1850
-
1851
- function div_binding($$value) {
1852
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1853
- comboboxRef = $$value;
1854
- $$invalidate(8, comboboxRef);
1855
- });
1856
- }
1857
-
1858
- $$self.$$set = $$new_props => {
1859
- $$props = assign(assign({}, $$props), exclude_internal_props($$new_props));
1860
- $$invalidate(16, $$restProps = compute_rest_props($$props, omit_props_names));
1861
- if ('id' in $$new_props) $$invalidate(2, id = $$new_props.id);
1862
- if ('value' in $$new_props) $$invalidate(0, value = $$new_props.value);
1863
- if ('data' in $$new_props) $$invalidate(17, data = $$new_props.data);
1864
- if ('extract' in $$new_props) $$invalidate(18, extract = $$new_props.extract);
1865
- if ('disable' in $$new_props) $$invalidate(19, disable = $$new_props.disable);
1866
- if ('filter' in $$new_props) $$invalidate(20, filter = $$new_props.filter);
1867
- if ('autoselect' in $$new_props) $$invalidate(21, autoselect = $$new_props.autoselect);
1868
- if ('inputAfterSelect' in $$new_props) $$invalidate(22, inputAfterSelect = $$new_props.inputAfterSelect);
1869
- if ('results' in $$new_props) $$invalidate(1, results = $$new_props.results);
1870
- if ('focusAfterSelect' in $$new_props) $$invalidate(23, focusAfterSelect = $$new_props.focusAfterSelect);
1871
- if ('showDropdownOnFocus' in $$new_props) $$invalidate(3, showDropdownOnFocus = $$new_props.showDropdownOnFocus);
1872
- if ('showAllResultsOnFocus' in $$new_props) $$invalidate(4, showAllResultsOnFocus = $$new_props.showAllResultsOnFocus);
1873
- if ('limit' in $$new_props) $$invalidate(24, limit = $$new_props.limit);
1874
- if ('$$scope' in $$new_props) $$invalidate(26, $$scope = $$new_props.$$scope);
1875
- };
1876
-
1877
- $$self.$$.update = () => {
1878
- if ($$self.$$.dirty[0] & /*extract*/ 262144) {
1879
- $$invalidate(25, options = { pre: "<mark>", post: "</mark>", extract });
1880
- }
1881
-
1882
- if ($$self.$$.dirty[0] & /*value, data, options, limit, filter, disable*/ 52035585) {
1883
- $$invalidate(1, results = fuzzy.filter(value, data, options).filter(({ score }) => score > 0).slice(0, limit).filter(result => !filter(result.original)).map(result => ({
1884
- ...result,
1885
- disabled: disable(result.original)
1886
- })));
1887
- }
1888
-
1889
- if ($$self.$$.dirty[0] & /*isFocused, showAllResultsOnFocus, value, data, filter, disable, extract*/ 1966161) {
1890
- if (isFocused && showAllResultsOnFocus && value.length === 0) {
1891
- $$invalidate(1, results = data.filter(datum => !filter(datum)).map((original, index) => ({
1892
- disabled: disable(original),
1893
- index,
1894
- original,
1895
- score: 0,
1896
- string: extract(original)
1897
- })));
1898
- }
1899
- }
1900
-
1901
- if ($$self.$$.dirty[0] & /*results, extract*/ 262146) {
1902
- resultsId = results.map(result => extract(result.original)).join("");
1903
- }
1904
-
1905
- if ($$self.$$.dirty[0] & /*hideDropdown, results*/ 34) {
1906
- $$invalidate(7, showResults = !hideDropdown && results.length > 0);
1907
- }
1908
-
1909
- if ($$self.$$.dirty[0] & /*showDropdownOnFocus, showResults, isFocused*/ 200) {
1910
- if (showDropdownOnFocus) {
1911
- $$invalidate(7, showResults = showResults && isFocused);
1912
- }
1913
- }
1914
- };
1915
-
1916
- return [
1917
- value,
1918
- results,
1919
- id,
1920
- showDropdownOnFocus,
1921
- showAllResultsOnFocus,
1922
- hideDropdown,
1923
- isFocused,
1924
- showResults,
1925
- comboboxRef,
1926
- searchRef,
1927
- selectedIndex,
1928
- select,
1929
- change,
1930
- open,
1931
- close,
1932
- $$slots,
1933
- $$restProps,
1934
- data,
1935
- extract,
1936
- disable,
1937
- filter,
1938
- autoselect,
1939
- inputAfterSelect,
1940
- focusAfterSelect,
1941
- limit,
1942
- options,
1943
- $$scope,
1944
- slots,
1945
- click_handler,
1946
- search_ref_binding,
1947
- search_value_binding,
1948
- type_handler,
1949
- input_handler,
1950
- change_handler,
1951
- focus_handler,
1952
- focus_handler_1,
1953
- clear_handler,
1954
- blur_handler,
1955
- keydown_handler,
1956
- keydown_handler_1,
1957
- click_handler_1,
1958
- mouseenter_handler,
1959
- div_binding
1960
- ];
1961
- }
1962
-
1963
- class Typeahead extends SvelteComponent {
1964
- constructor(options) {
1965
- super();
1966
-
1967
- init(
1968
- this,
1969
- options,
1970
- instance,
1971
- create_fragment,
1972
- safe_not_equal,
1973
- {
1974
- id: 2,
1975
- value: 0,
1976
- data: 17,
1977
- extract: 18,
1978
- disable: 19,
1979
- filter: 20,
1980
- autoselect: 21,
1981
- inputAfterSelect: 22,
1982
- results: 1,
1983
- focusAfterSelect: 23,
1984
- showDropdownOnFocus: 3,
1985
- showAllResultsOnFocus: 4,
1986
- limit: 24
1987
- },
1988
- add_css,
1989
- [-1, -1]
1990
- );
1991
- }
1992
- }
1993
-
1994
- export { Typeahead as default };