mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 00:39:30 +08:00
1915 lines
60 KiB
Text
1915 lines
60 KiB
Text
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["svelte-typeahead"] = {}));
|
|
})(this, (function (exports) { 'use strict';
|
|
|
|
function noop() { }
|
|
function assign(tar, src) {
|
|
// @ts-ignore
|
|
for (const k in src)
|
|
tar[k] = src[k];
|
|
return tar;
|
|
}
|
|
function run(fn) {
|
|
return fn();
|
|
}
|
|
function blank_object() {
|
|
return Object.create(null);
|
|
}
|
|
function run_all(fns) {
|
|
fns.forEach(run);
|
|
}
|
|
function is_function(thing) {
|
|
return typeof thing === 'function';
|
|
}
|
|
function safe_not_equal(a, b) {
|
|
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
|
}
|
|
function is_empty(obj) {
|
|
return Object.keys(obj).length === 0;
|
|
}
|
|
function create_slot(definition, ctx, $$scope, fn) {
|
|
if (definition) {
|
|
const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
|
|
return definition[0](slot_ctx);
|
|
}
|
|
}
|
|
function get_slot_context(definition, ctx, $$scope, fn) {
|
|
return definition[1] && fn
|
|
? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
|
|
: $$scope.ctx;
|
|
}
|
|
function get_slot_changes(definition, $$scope, dirty, fn) {
|
|
if (definition[2] && fn) {
|
|
const lets = definition[2](fn(dirty));
|
|
if ($$scope.dirty === undefined) {
|
|
return lets;
|
|
}
|
|
if (typeof lets === 'object') {
|
|
const merged = [];
|
|
const len = Math.max($$scope.dirty.length, lets.length);
|
|
for (let i = 0; i < len; i += 1) {
|
|
merged[i] = $$scope.dirty[i] | lets[i];
|
|
}
|
|
return merged;
|
|
}
|
|
return $$scope.dirty | lets;
|
|
}
|
|
return $$scope.dirty;
|
|
}
|
|
function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
|
|
if (slot_changes) {
|
|
const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
|
|
slot.p(slot_context, slot_changes);
|
|
}
|
|
}
|
|
function get_all_dirty_from_scope($$scope) {
|
|
if ($$scope.ctx.length > 32) {
|
|
const dirty = [];
|
|
const length = $$scope.ctx.length / 32;
|
|
for (let i = 0; i < length; i++) {
|
|
dirty[i] = -1;
|
|
}
|
|
return dirty;
|
|
}
|
|
return -1;
|
|
}
|
|
function exclude_internal_props(props) {
|
|
const result = {};
|
|
for (const k in props)
|
|
if (k[0] !== '$')
|
|
result[k] = props[k];
|
|
return result;
|
|
}
|
|
function compute_rest_props(props, keys) {
|
|
const rest = {};
|
|
keys = new Set(keys);
|
|
for (const k in props)
|
|
if (!keys.has(k) && k[0] !== '$')
|
|
rest[k] = props[k];
|
|
return rest;
|
|
}
|
|
function compute_slots(slots) {
|
|
const result = {};
|
|
for (const key in slots) {
|
|
result[key] = true;
|
|
}
|
|
return result;
|
|
}
|
|
function append(target, node) {
|
|
target.appendChild(node);
|
|
}
|
|
function append_styles(target, style_sheet_id, styles) {
|
|
const append_styles_to = get_root_for_style(target);
|
|
if (!append_styles_to.getElementById(style_sheet_id)) {
|
|
const style = element('style');
|
|
style.id = style_sheet_id;
|
|
style.textContent = styles;
|
|
append_stylesheet(append_styles_to, style);
|
|
}
|
|
}
|
|
function get_root_for_style(node) {
|
|
if (!node)
|
|
return document;
|
|
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
|
|
if (root && root.host) {
|
|
return root;
|
|
}
|
|
return node.ownerDocument;
|
|
}
|
|
function append_stylesheet(node, style) {
|
|
append(node.head || node, style);
|
|
}
|
|
function insert(target, node, anchor) {
|
|
target.insertBefore(node, anchor || null);
|
|
}
|
|
function detach(node) {
|
|
node.parentNode.removeChild(node);
|
|
}
|
|
function destroy_each(iterations, detaching) {
|
|
for (let i = 0; i < iterations.length; i += 1) {
|
|
if (iterations[i])
|
|
iterations[i].d(detaching);
|
|
}
|
|
}
|
|
function element(name) {
|
|
return document.createElement(name);
|
|
}
|
|
function svg_element(name) {
|
|
return document.createElementNS('http://www.w3.org/2000/svg', name);
|
|
}
|
|
function text(data) {
|
|
return document.createTextNode(data);
|
|
}
|
|
function space() {
|
|
return text(' ');
|
|
}
|
|
function empty() {
|
|
return text('');
|
|
}
|
|
function listen(node, event, handler, options) {
|
|
node.addEventListener(event, handler, options);
|
|
return () => node.removeEventListener(event, handler, options);
|
|
}
|
|
function prevent_default(fn) {
|
|
return function (event) {
|
|
event.preventDefault();
|
|
// @ts-ignore
|
|
return fn.call(this, event);
|
|
};
|
|
}
|
|
function attr(node, attribute, value) {
|
|
if (value == null)
|
|
node.removeAttribute(attribute);
|
|
else if (node.getAttribute(attribute) !== value)
|
|
node.setAttribute(attribute, value);
|
|
}
|
|
function set_attributes(node, attributes) {
|
|
// @ts-ignore
|
|
const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
|
|
for (const key in attributes) {
|
|
if (attributes[key] == null) {
|
|
node.removeAttribute(key);
|
|
}
|
|
else if (key === 'style') {
|
|
node.style.cssText = attributes[key];
|
|
}
|
|
else if (key === '__value') {
|
|
node.value = node[key] = attributes[key];
|
|
}
|
|
else if (descriptors[key] && descriptors[key].set) {
|
|
node[key] = attributes[key];
|
|
}
|
|
else {
|
|
attr(node, key, attributes[key]);
|
|
}
|
|
}
|
|
}
|
|
function children(element) {
|
|
return Array.from(element.childNodes);
|
|
}
|
|
function set_data(text, data) {
|
|
data = '' + data;
|
|
if (text.wholeText !== data)
|
|
text.data = data;
|
|
}
|
|
function set_input_value(input, value) {
|
|
input.value = value == null ? '' : value;
|
|
}
|
|
function toggle_class(element, name, toggle) {
|
|
element.classList[toggle ? 'add' : 'remove'](name);
|
|
}
|
|
function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
|
|
const e = document.createEvent('CustomEvent');
|
|
e.initCustomEvent(type, bubbles, cancelable, detail);
|
|
return e;
|
|
}
|
|
class HtmlTag {
|
|
constructor(is_svg = false) {
|
|
this.is_svg = false;
|
|
this.is_svg = is_svg;
|
|
this.e = this.n = null;
|
|
}
|
|
c(html) {
|
|
this.h(html);
|
|
}
|
|
m(html, target, anchor = null) {
|
|
if (!this.e) {
|
|
if (this.is_svg)
|
|
this.e = svg_element(target.nodeName);
|
|
else
|
|
this.e = element(target.nodeName);
|
|
this.t = target;
|
|
this.c(html);
|
|
}
|
|
this.i(anchor);
|
|
}
|
|
h(html) {
|
|
this.e.innerHTML = html;
|
|
this.n = Array.from(this.e.childNodes);
|
|
}
|
|
i(anchor) {
|
|
for (let i = 0; i < this.n.length; i += 1) {
|
|
insert(this.t, this.n[i], anchor);
|
|
}
|
|
}
|
|
p(html) {
|
|
this.d();
|
|
this.h(html);
|
|
this.i(this.a);
|
|
}
|
|
d() {
|
|
this.n.forEach(detach);
|
|
}
|
|
}
|
|
|
|
let current_component;
|
|
function set_current_component(component) {
|
|
current_component = component;
|
|
}
|
|
function get_current_component() {
|
|
if (!current_component)
|
|
throw new Error('Function called outside component initialization');
|
|
return current_component;
|
|
}
|
|
function onMount(fn) {
|
|
get_current_component().$$.on_mount.push(fn);
|
|
}
|
|
function afterUpdate(fn) {
|
|
get_current_component().$$.after_update.push(fn);
|
|
}
|
|
function createEventDispatcher() {
|
|
const component = get_current_component();
|
|
return (type, detail, { cancelable = false } = {}) => {
|
|
const callbacks = component.$$.callbacks[type];
|
|
if (callbacks) {
|
|
// TODO are there situations where events could be dispatched
|
|
// in a server (non-DOM) environment?
|
|
const event = custom_event(type, detail, { cancelable });
|
|
callbacks.slice().forEach(fn => {
|
|
fn.call(component, event);
|
|
});
|
|
return !event.defaultPrevented;
|
|
}
|
|
return true;
|
|
};
|
|
}
|
|
// TODO figure out if we still want to support
|
|
// shorthand events, or if we want to implement
|
|
// a real bubbling mechanism
|
|
function bubble(component, event) {
|
|
const callbacks = component.$$.callbacks[event.type];
|
|
if (callbacks) {
|
|
// @ts-ignore
|
|
callbacks.slice().forEach(fn => fn.call(this, event));
|
|
}
|
|
}
|
|
|
|
const dirty_components = [];
|
|
const binding_callbacks = [];
|
|
const render_callbacks = [];
|
|
const flush_callbacks = [];
|
|
const resolved_promise = Promise.resolve();
|
|
let update_scheduled = false;
|
|
function schedule_update() {
|
|
if (!update_scheduled) {
|
|
update_scheduled = true;
|
|
resolved_promise.then(flush);
|
|
}
|
|
}
|
|
function tick() {
|
|
schedule_update();
|
|
return resolved_promise;
|
|
}
|
|
function add_render_callback(fn) {
|
|
render_callbacks.push(fn);
|
|
}
|
|
function add_flush_callback(fn) {
|
|
flush_callbacks.push(fn);
|
|
}
|
|
// flush() calls callbacks in this order:
|
|
// 1. All beforeUpdate callbacks, in order: parents before children
|
|
// 2. All bind:this callbacks, in reverse order: children before parents.
|
|
// 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
|
|
// for afterUpdates called during the initial onMount, which are called in
|
|
// reverse order: children before parents.
|
|
// Since callbacks might update component values, which could trigger another
|
|
// call to flush(), the following steps guard against this:
|
|
// 1. During beforeUpdate, any updated components will be added to the
|
|
// dirty_components array and will cause a reentrant call to flush(). Because
|
|
// the flush index is kept outside the function, the reentrant call will pick
|
|
// up where the earlier call left off and go through all dirty components. The
|
|
// current_component value is saved and restored so that the reentrant call will
|
|
// not interfere with the "parent" flush() call.
|
|
// 2. bind:this callbacks cannot trigger new flush() calls.
|
|
// 3. During afterUpdate, any updated components will NOT have their afterUpdate
|
|
// callback called a second time; the seen_callbacks set, outside the flush()
|
|
// function, guarantees this behavior.
|
|
const seen_callbacks = new Set();
|
|
let flushidx = 0; // Do *not* move this inside the flush() function
|
|
function flush() {
|
|
const saved_component = current_component;
|
|
do {
|
|
// first, call beforeUpdate functions
|
|
// and update components
|
|
while (flushidx < dirty_components.length) {
|
|
const component = dirty_components[flushidx];
|
|
flushidx++;
|
|
set_current_component(component);
|
|
update(component.$$);
|
|
}
|
|
set_current_component(null);
|
|
dirty_components.length = 0;
|
|
flushidx = 0;
|
|
while (binding_callbacks.length)
|
|
binding_callbacks.pop()();
|
|
// then, once components are updated, call
|
|
// afterUpdate functions. This may cause
|
|
// subsequent updates...
|
|
for (let i = 0; i < render_callbacks.length; i += 1) {
|
|
const callback = render_callbacks[i];
|
|
if (!seen_callbacks.has(callback)) {
|
|
// ...so guard against infinite loops
|
|
seen_callbacks.add(callback);
|
|
callback();
|
|
}
|
|
}
|
|
render_callbacks.length = 0;
|
|
} while (dirty_components.length);
|
|
while (flush_callbacks.length) {
|
|
flush_callbacks.pop()();
|
|
}
|
|
update_scheduled = false;
|
|
seen_callbacks.clear();
|
|
set_current_component(saved_component);
|
|
}
|
|
function update($$) {
|
|
if ($$.fragment !== null) {
|
|
$$.update();
|
|
run_all($$.before_update);
|
|
const dirty = $$.dirty;
|
|
$$.dirty = [-1];
|
|
$$.fragment && $$.fragment.p($$.ctx, dirty);
|
|
$$.after_update.forEach(add_render_callback);
|
|
}
|
|
}
|
|
const outroing = new Set();
|
|
let outros;
|
|
function group_outros() {
|
|
outros = {
|
|
r: 0,
|
|
c: [],
|
|
p: outros // parent group
|
|
};
|
|
}
|
|
function check_outros() {
|
|
if (!outros.r) {
|
|
run_all(outros.c);
|
|
}
|
|
outros = outros.p;
|
|
}
|
|
function transition_in(block, local) {
|
|
if (block && block.i) {
|
|
outroing.delete(block);
|
|
block.i(local);
|
|
}
|
|
}
|
|
function transition_out(block, local, detach, callback) {
|
|
if (block && block.o) {
|
|
if (outroing.has(block))
|
|
return;
|
|
outroing.add(block);
|
|
outros.c.push(() => {
|
|
outroing.delete(block);
|
|
if (callback) {
|
|
if (detach)
|
|
block.d(1);
|
|
callback();
|
|
}
|
|
});
|
|
block.o(local);
|
|
}
|
|
}
|
|
|
|
function get_spread_update(levels, updates) {
|
|
const update = {};
|
|
const to_null_out = {};
|
|
const accounted_for = { $$scope: 1 };
|
|
let i = levels.length;
|
|
while (i--) {
|
|
const o = levels[i];
|
|
const n = updates[i];
|
|
if (n) {
|
|
for (const key in o) {
|
|
if (!(key in n))
|
|
to_null_out[key] = 1;
|
|
}
|
|
for (const key in n) {
|
|
if (!accounted_for[key]) {
|
|
update[key] = n[key];
|
|
accounted_for[key] = 1;
|
|
}
|
|
}
|
|
levels[i] = n;
|
|
}
|
|
else {
|
|
for (const key in o) {
|
|
accounted_for[key] = 1;
|
|
}
|
|
}
|
|
}
|
|
for (const key in to_null_out) {
|
|
if (!(key in update))
|
|
update[key] = undefined;
|
|
}
|
|
return update;
|
|
}
|
|
function get_spread_object(spread_props) {
|
|
return typeof spread_props === 'object' && spread_props !== null ? spread_props : {};
|
|
}
|
|
|
|
function bind(component, name, callback) {
|
|
const index = component.$$.props[name];
|
|
if (index !== undefined) {
|
|
component.$$.bound[index] = callback;
|
|
callback(component.$$.ctx[index]);
|
|
}
|
|
}
|
|
function create_component(block) {
|
|
block && block.c();
|
|
}
|
|
function mount_component(component, target, anchor, customElement) {
|
|
const { fragment, on_mount, on_destroy, after_update } = component.$$;
|
|
fragment && fragment.m(target, anchor);
|
|
if (!customElement) {
|
|
// onMount happens before the initial afterUpdate
|
|
add_render_callback(() => {
|
|
const new_on_destroy = on_mount.map(run).filter(is_function);
|
|
if (on_destroy) {
|
|
on_destroy.push(...new_on_destroy);
|
|
}
|
|
else {
|
|
// Edge case - component was destroyed immediately,
|
|
// most likely as a result of a binding initialising
|
|
run_all(new_on_destroy);
|
|
}
|
|
component.$$.on_mount = [];
|
|
});
|
|
}
|
|
after_update.forEach(add_render_callback);
|
|
}
|
|
function destroy_component(component, detaching) {
|
|
const $$ = component.$$;
|
|
if ($$.fragment !== null) {
|
|
run_all($$.on_destroy);
|
|
$$.fragment && $$.fragment.d(detaching);
|
|
// TODO null out other refs, including component.$$ (but need to
|
|
// preserve final state?)
|
|
$$.on_destroy = $$.fragment = null;
|
|
$$.ctx = [];
|
|
}
|
|
}
|
|
function make_dirty(component, i) {
|
|
if (component.$$.dirty[0] === -1) {
|
|
dirty_components.push(component);
|
|
schedule_update();
|
|
component.$$.dirty.fill(0);
|
|
}
|
|
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
|
|
}
|
|
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
|
|
const parent_component = current_component;
|
|
set_current_component(component);
|
|
const $$ = component.$$ = {
|
|
fragment: null,
|
|
ctx: null,
|
|
// state
|
|
props,
|
|
update: noop,
|
|
not_equal,
|
|
bound: blank_object(),
|
|
// lifecycle
|
|
on_mount: [],
|
|
on_destroy: [],
|
|
on_disconnect: [],
|
|
before_update: [],
|
|
after_update: [],
|
|
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
|
|
// everything else
|
|
callbacks: blank_object(),
|
|
dirty,
|
|
skip_bound: false,
|
|
root: options.target || parent_component.$$.root
|
|
};
|
|
append_styles && append_styles($$.root);
|
|
let ready = false;
|
|
$$.ctx = instance
|
|
? instance(component, options.props || {}, (i, ret, ...rest) => {
|
|
const value = rest.length ? rest[0] : ret;
|
|
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
|
|
if (!$$.skip_bound && $$.bound[i])
|
|
$$.bound[i](value);
|
|
if (ready)
|
|
make_dirty(component, i);
|
|
}
|
|
return ret;
|
|
})
|
|
: [];
|
|
$$.update();
|
|
ready = true;
|
|
run_all($$.before_update);
|
|
// `false` as a special case of no DOM component
|
|
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
|
|
if (options.target) {
|
|
if (options.hydrate) {
|
|
const nodes = children(options.target);
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
$$.fragment && $$.fragment.l(nodes);
|
|
nodes.forEach(detach);
|
|
}
|
|
else {
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
$$.fragment && $$.fragment.c();
|
|
}
|
|
if (options.intro)
|
|
transition_in(component.$$.fragment);
|
|
mount_component(component, options.target, options.anchor, options.customElement);
|
|
flush();
|
|
}
|
|
set_current_component(parent_component);
|
|
}
|
|
/**
|
|
* Base class for Svelte components. Used when dev=false.
|
|
*/
|
|
class SvelteComponent {
|
|
$destroy() {
|
|
destroy_component(this, 1);
|
|
this.$destroy = noop;
|
|
}
|
|
$on(type, callback) {
|
|
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
|
|
callbacks.push(callback);
|
|
return () => {
|
|
const index = callbacks.indexOf(callback);
|
|
if (index !== -1)
|
|
callbacks.splice(index, 1);
|
|
};
|
|
}
|
|
$set($$props) {
|
|
if (this.$$set && !is_empty($$props)) {
|
|
this.$$.skip_bound = true;
|
|
this.$$set($$props);
|
|
this.$$.skip_bound = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
var fuzzy$1 = {exports: {}};
|
|
|
|
/*
|
|
* Fuzzy
|
|
* https://github.com/myork/fuzzy
|
|
*
|
|
* Copyright (c) 2012 Matt York
|
|
* Licensed under the MIT license.
|
|
*/
|
|
|
|
(function (module, exports) {
|
|
(function() {
|
|
|
|
var fuzzy = {};
|
|
|
|
// Use in node or in browser
|
|
{
|
|
module.exports = fuzzy;
|
|
}
|
|
|
|
// Return all elements of `array` that have a fuzzy
|
|
// match against `pattern`.
|
|
fuzzy.simpleFilter = function(pattern, array) {
|
|
return array.filter(function(str) {
|
|
return fuzzy.test(pattern, str);
|
|
});
|
|
};
|
|
|
|
// Does `pattern` fuzzy match `str`?
|
|
fuzzy.test = function(pattern, str) {
|
|
return fuzzy.match(pattern, str) !== null;
|
|
};
|
|
|
|
// If `pattern` matches `str`, wrap each matching character
|
|
// in `opts.pre` and `opts.post`. If no match, return null
|
|
fuzzy.match = function(pattern, str, opts) {
|
|
opts = opts || {};
|
|
var patternIdx = 0
|
|
, result = []
|
|
, len = str.length
|
|
, totalScore = 0
|
|
, currScore = 0
|
|
// prefix
|
|
, pre = opts.pre || ''
|
|
// suffix
|
|
, post = opts.post || ''
|
|
// String to compare against. This might be a lowercase version of the
|
|
// raw string
|
|
, compareString = opts.caseSensitive && str || str.toLowerCase()
|
|
, ch;
|
|
|
|
pattern = opts.caseSensitive && pattern || pattern.toLowerCase();
|
|
|
|
// For each character in the string, either add it to the result
|
|
// or wrap in template if it's the next string in the pattern
|
|
for(var idx = 0; idx < len; idx++) {
|
|
ch = str[idx];
|
|
if(compareString[idx] === pattern[patternIdx]) {
|
|
ch = pre + ch + post;
|
|
patternIdx += 1;
|
|
|
|
// consecutive characters should increase the score more than linearly
|
|
currScore += 1 + currScore;
|
|
} else {
|
|
currScore = 0;
|
|
}
|
|
totalScore += currScore;
|
|
result[result.length] = ch;
|
|
}
|
|
|
|
// return rendered string if we have a match for every char
|
|
if(patternIdx === pattern.length) {
|
|
// if the string is an exact match with pattern, totalScore should be maxed
|
|
totalScore = (compareString === pattern) ? Infinity : totalScore;
|
|
return {rendered: result.join(''), score: totalScore};
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
// The normal entry point. Filters `arr` for matches against `pattern`.
|
|
// It returns an array with matching values of the type:
|
|
//
|
|
// [{
|
|
// string: '<b>lah' // The rendered string
|
|
// , index: 2 // The index of the element in `arr`
|
|
// , original: 'blah' // The original element in `arr`
|
|
// }]
|
|
//
|
|
// `opts` is an optional argument bag. Details:
|
|
//
|
|
// opts = {
|
|
// // string to put before a matching character
|
|
// pre: '<b>'
|
|
//
|
|
// // string to put after matching character
|
|
// , post: '</b>'
|
|
//
|
|
// // Optional function. Input is an entry in the given arr`,
|
|
// // output should be the string to test `pattern` against.
|
|
// // In this example, if `arr = [{crying: 'koala'}]` we would return
|
|
// // 'koala'.
|
|
// , extract: function(arg) { return arg.crying; }
|
|
// }
|
|
fuzzy.filter = function(pattern, arr, opts) {
|
|
if(!arr || arr.length === 0) {
|
|
return [];
|
|
}
|
|
if (typeof pattern !== 'string') {
|
|
return arr;
|
|
}
|
|
opts = opts || {};
|
|
return arr
|
|
.reduce(function(prev, element, idx, arr) {
|
|
var str = element;
|
|
if(opts.extract) {
|
|
str = opts.extract(element);
|
|
}
|
|
var rendered = fuzzy.match(pattern, str, opts);
|
|
if(rendered != null) {
|
|
prev[prev.length] = {
|
|
string: rendered.rendered
|
|
, score: rendered.score
|
|
, index: idx
|
|
, original: element
|
|
};
|
|
}
|
|
return prev;
|
|
}, [])
|
|
|
|
// Sort by score. Browsers are inconsistent wrt stable/unstable
|
|
// sorting, so force stable by using the index in the case of tie.
|
|
// See http://ofb.net/~sethml/is-sort-stable.html
|
|
.sort(function(a,b) {
|
|
var compare = b.score - a.score;
|
|
if(compare) return compare;
|
|
return a.index - b.index;
|
|
});
|
|
};
|
|
|
|
|
|
}());
|
|
}(fuzzy$1));
|
|
|
|
var fuzzy = fuzzy$1.exports;
|
|
|
|
/* node_modules/svelte-search/src/Search.svelte generated by Svelte v3.48.0 */
|
|
|
|
function add_css$1(target) {
|
|
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}");
|
|
}
|
|
|
|
const get_label_slot_changes = dirty => ({});
|
|
const get_label_slot_context = ctx => ({});
|
|
|
|
// (60:23) {label}
|
|
function fallback_block$1(ctx) {
|
|
let t;
|
|
|
|
return {
|
|
c() {
|
|
t = text(/*label*/ ctx[2]);
|
|
},
|
|
m(target, anchor) {
|
|
insert(target, t, anchor);
|
|
},
|
|
p(ctx, dirty) {
|
|
if (dirty & /*label*/ 4) set_data(t, /*label*/ ctx[2]);
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(t);
|
|
}
|
|
};
|
|
}
|
|
|
|
function create_fragment$1(ctx) {
|
|
let form;
|
|
let label_1;
|
|
let label_1_id_value;
|
|
let t;
|
|
let input;
|
|
let form_role_value;
|
|
let form_aria_labelledby_value;
|
|
let current;
|
|
let mounted;
|
|
let dispose;
|
|
const label_slot_template = /*#slots*/ ctx[10].label;
|
|
const label_slot = create_slot(label_slot_template, ctx, /*$$scope*/ ctx[9], get_label_slot_context);
|
|
const label_slot_or_fallback = label_slot || fallback_block$1(ctx);
|
|
|
|
let input_levels = [
|
|
{ name: "search" },
|
|
{ type: "search" },
|
|
{ placeholder: "Search..." },
|
|
{ autocomplete: "off" },
|
|
{ spellcheck: "false" },
|
|
/*$$restProps*/ ctx[6],
|
|
{ id: /*id*/ ctx[4] }
|
|
];
|
|
|
|
let input_data = {};
|
|
|
|
for (let i = 0; i < input_levels.length; i += 1) {
|
|
input_data = assign(input_data, input_levels[i]);
|
|
}
|
|
|
|
return {
|
|
c() {
|
|
form = element("form");
|
|
label_1 = element("label");
|
|
if (label_slot_or_fallback) label_slot_or_fallback.c();
|
|
t = space();
|
|
input = element("input");
|
|
attr(label_1, "id", label_1_id_value = "" + (/*id*/ ctx[4] + "-label"));
|
|
attr(label_1, "for", /*id*/ ctx[4]);
|
|
attr(label_1, "class", "svelte-5m0wg6");
|
|
toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]);
|
|
set_attributes(input, input_data);
|
|
toggle_class(input, "svelte-5m0wg6", true);
|
|
attr(form, "data-svelte-search", "");
|
|
attr(form, "role", form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search");
|
|
|
|
attr(form, "aria-labelledby", form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5]
|
|
? null
|
|
: /*id*/ ctx[4]);
|
|
},
|
|
m(target, anchor) {
|
|
insert(target, form, anchor);
|
|
append(form, label_1);
|
|
|
|
if (label_slot_or_fallback) {
|
|
label_slot_or_fallback.m(label_1, null);
|
|
}
|
|
|
|
append(form, t);
|
|
append(form, input);
|
|
if (input.autofocus) input.focus();
|
|
/*input_binding*/ ctx[17](input);
|
|
set_input_value(input, /*value*/ ctx[0]);
|
|
current = true;
|
|
|
|
if (!mounted) {
|
|
dispose = [
|
|
listen(input, "input", /*input_input_handler*/ ctx[18]),
|
|
listen(input, "input", /*input_handler*/ ctx[12]),
|
|
listen(input, "change", /*change_handler*/ ctx[13]),
|
|
listen(input, "focus", /*focus_handler*/ ctx[14]),
|
|
listen(input, "blur", /*blur_handler*/ ctx[15]),
|
|
listen(input, "keydown", /*keydown_handler*/ ctx[16]),
|
|
listen(form, "submit", prevent_default(/*submit_handler*/ ctx[11]))
|
|
];
|
|
|
|
mounted = true;
|
|
}
|
|
},
|
|
p(ctx, [dirty]) {
|
|
if (label_slot) {
|
|
if (label_slot.p && (!current || dirty & /*$$scope*/ 512)) {
|
|
update_slot_base(
|
|
label_slot,
|
|
label_slot_template,
|
|
ctx,
|
|
/*$$scope*/ ctx[9],
|
|
!current
|
|
? get_all_dirty_from_scope(/*$$scope*/ ctx[9])
|
|
: get_slot_changes(label_slot_template, /*$$scope*/ ctx[9], dirty, get_label_slot_changes),
|
|
get_label_slot_context
|
|
);
|
|
}
|
|
} else {
|
|
if (label_slot_or_fallback && label_slot_or_fallback.p && (!current || dirty & /*label*/ 4)) {
|
|
label_slot_or_fallback.p(ctx, !current ? -1 : dirty);
|
|
}
|
|
}
|
|
|
|
if (!current || dirty & /*id*/ 16 && label_1_id_value !== (label_1_id_value = "" + (/*id*/ ctx[4] + "-label"))) {
|
|
attr(label_1, "id", label_1_id_value);
|
|
}
|
|
|
|
if (!current || dirty & /*id*/ 16) {
|
|
attr(label_1, "for", /*id*/ ctx[4]);
|
|
}
|
|
|
|
if (dirty & /*hideLabel*/ 8) {
|
|
toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]);
|
|
}
|
|
|
|
set_attributes(input, input_data = get_spread_update(input_levels, [
|
|
{ name: "search" },
|
|
{ type: "search" },
|
|
{ placeholder: "Search..." },
|
|
{ autocomplete: "off" },
|
|
{ spellcheck: "false" },
|
|
dirty & /*$$restProps*/ 64 && /*$$restProps*/ ctx[6],
|
|
(!current || dirty & /*id*/ 16) && { id: /*id*/ ctx[4] }
|
|
]));
|
|
|
|
if (dirty & /*value*/ 1) {
|
|
set_input_value(input, /*value*/ ctx[0]);
|
|
}
|
|
|
|
toggle_class(input, "svelte-5m0wg6", true);
|
|
|
|
if (!current || dirty & /*removeFormAriaAttributes*/ 32 && form_role_value !== (form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search")) {
|
|
attr(form, "role", form_role_value);
|
|
}
|
|
|
|
if (!current || dirty & /*removeFormAriaAttributes, id*/ 48 && form_aria_labelledby_value !== (form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5]
|
|
? null
|
|
: /*id*/ ctx[4])) {
|
|
attr(form, "aria-labelledby", form_aria_labelledby_value);
|
|
}
|
|
},
|
|
i(local) {
|
|
if (current) return;
|
|
transition_in(label_slot_or_fallback, local);
|
|
current = true;
|
|
},
|
|
o(local) {
|
|
transition_out(label_slot_or_fallback, local);
|
|
current = false;
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(form);
|
|
if (label_slot_or_fallback) label_slot_or_fallback.d(detaching);
|
|
/*input_binding*/ ctx[17](null);
|
|
mounted = false;
|
|
run_all(dispose);
|
|
}
|
|
};
|
|
}
|
|
|
|
function instance$1($$self, $$props, $$invalidate) {
|
|
const omit_props_names = [
|
|
"value","autofocus","debounce","label","hideLabel","id","ref","removeFormAriaAttributes"
|
|
];
|
|
|
|
let $$restProps = compute_rest_props($$props, omit_props_names);
|
|
let { $$slots: slots = {}, $$scope } = $$props;
|
|
let { value = "" } = $$props;
|
|
let { autofocus = false } = $$props;
|
|
let { debounce = 0 } = $$props;
|
|
let { label = "Label" } = $$props;
|
|
let { hideLabel = false } = $$props;
|
|
let { id = "search" + Math.random().toString(36) } = $$props;
|
|
let { ref = null } = $$props;
|
|
let { removeFormAriaAttributes = false } = $$props;
|
|
const dispatch = createEventDispatcher();
|
|
let prevValue = value;
|
|
let timeout = undefined;
|
|
let calling = false;
|
|
|
|
function debounced(cb) {
|
|
if (calling) return;
|
|
calling = true;
|
|
|
|
timeout = setTimeout(
|
|
() => {
|
|
cb();
|
|
calling = false;
|
|
},
|
|
debounce
|
|
);
|
|
}
|
|
|
|
onMount(() => {
|
|
if (autofocus) window.requestAnimationFrame(() => ref.focus());
|
|
return () => clearTimeout(timeout);
|
|
});
|
|
|
|
afterUpdate(() => {
|
|
if (value.length > 0 && value !== prevValue) {
|
|
if (debounce > 0) {
|
|
debounced(() => dispatch("type", value));
|
|
} else {
|
|
dispatch("type", value);
|
|
}
|
|
}
|
|
|
|
if (value.length === 0 && prevValue.length > 0) dispatch("clear");
|
|
prevValue = value;
|
|
});
|
|
|
|
function submit_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function input_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function change_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function focus_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function blur_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function keydown_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function input_binding($$value) {
|
|
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
ref = $$value;
|
|
$$invalidate(1, ref);
|
|
});
|
|
}
|
|
|
|
function input_input_handler() {
|
|
value = this.value;
|
|
$$invalidate(0, value);
|
|
}
|
|
|
|
$$self.$$set = $$new_props => {
|
|
$$props = assign(assign({}, $$props), exclude_internal_props($$new_props));
|
|
$$invalidate(6, $$restProps = compute_rest_props($$props, omit_props_names));
|
|
if ('value' in $$new_props) $$invalidate(0, value = $$new_props.value);
|
|
if ('autofocus' in $$new_props) $$invalidate(7, autofocus = $$new_props.autofocus);
|
|
if ('debounce' in $$new_props) $$invalidate(8, debounce = $$new_props.debounce);
|
|
if ('label' in $$new_props) $$invalidate(2, label = $$new_props.label);
|
|
if ('hideLabel' in $$new_props) $$invalidate(3, hideLabel = $$new_props.hideLabel);
|
|
if ('id' in $$new_props) $$invalidate(4, id = $$new_props.id);
|
|
if ('ref' in $$new_props) $$invalidate(1, ref = $$new_props.ref);
|
|
if ('removeFormAriaAttributes' in $$new_props) $$invalidate(5, removeFormAriaAttributes = $$new_props.removeFormAriaAttributes);
|
|
if ('$$scope' in $$new_props) $$invalidate(9, $$scope = $$new_props.$$scope);
|
|
};
|
|
|
|
return [
|
|
value,
|
|
ref,
|
|
label,
|
|
hideLabel,
|
|
id,
|
|
removeFormAriaAttributes,
|
|
$$restProps,
|
|
autofocus,
|
|
debounce,
|
|
$$scope,
|
|
slots,
|
|
submit_handler,
|
|
input_handler,
|
|
change_handler,
|
|
focus_handler,
|
|
blur_handler,
|
|
keydown_handler,
|
|
input_binding,
|
|
input_input_handler
|
|
];
|
|
}
|
|
|
|
class Search extends SvelteComponent {
|
|
constructor(options) {
|
|
super();
|
|
|
|
init(
|
|
this,
|
|
options,
|
|
instance$1,
|
|
create_fragment$1,
|
|
safe_not_equal,
|
|
{
|
|
value: 0,
|
|
autofocus: 7,
|
|
debounce: 8,
|
|
label: 2,
|
|
hideLabel: 3,
|
|
id: 4,
|
|
ref: 1,
|
|
removeFormAriaAttributes: 5
|
|
},
|
|
add_css$1
|
|
);
|
|
}
|
|
}
|
|
|
|
var Search$1 = Search;
|
|
|
|
/* src/Typeahead.svelte generated by Svelte v3.48.0 */
|
|
|
|
function add_css(target) {
|
|
append_styles(target, "svelte-9wywte", "[data-svelte-typeahead].svelte-9wywte.svelte-9wywte{position:relative;background-color:#fff}ul.svelte-9wywte.svelte-9wywte{position:absolute;top:100%;left:0;width:100%;padding:0;list-style:none;background-color:inherit;box-shadow:0 4px 8px rgba(0, 0, 0, 0.1)}[aria-expanded=\"true\"].svelte-9wywte ul.svelte-9wywte{z-index:1}li.svelte-9wywte.svelte-9wywte,.no-results.svelte-9wywte.svelte-9wywte{padding:0.25rem 1rem}li.svelte-9wywte.svelte-9wywte{cursor:pointer}li.svelte-9wywte.svelte-9wywte:not(:last-of-type){border-bottom:1px solid #e0e0e0}li.svelte-9wywte.svelte-9wywte:hover{background-color:#e5e5e5}.selected.svelte-9wywte.svelte-9wywte{background-color:#e5e5e5}.selected.svelte-9wywte.svelte-9wywte:hover{background-color:#cacaca}.disabled.svelte-9wywte.svelte-9wywte{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}");
|
|
}
|
|
|
|
const get_no_results_slot_changes = dirty => ({
|
|
value: dirty[0] & /*value*/ 1,
|
|
result: dirty[0] & /*results*/ 2
|
|
});
|
|
|
|
const get_no_results_slot_context = ctx => ({
|
|
value: /*value*/ ctx[0],
|
|
result: /*result*/ ctx[42],
|
|
index: /*index*/ ctx[44]
|
|
});
|
|
|
|
function get_each_context(ctx, list, i) {
|
|
const child_ctx = ctx.slice();
|
|
child_ctx[42] = list[i];
|
|
child_ctx[44] = i;
|
|
return child_ctx;
|
|
}
|
|
|
|
const get_default_slot_changes = dirty => ({
|
|
result: dirty[0] & /*results*/ 2,
|
|
value: dirty[0] & /*value*/ 1
|
|
});
|
|
|
|
const get_default_slot_context = ctx => ({
|
|
result: /*result*/ ctx[42],
|
|
index: /*index*/ ctx[44],
|
|
value: /*value*/ ctx[0]
|
|
});
|
|
|
|
// (201:4) {#if showResults}
|
|
function create_if_block_1(ctx) {
|
|
let each_1_anchor;
|
|
let current;
|
|
let each_value = /*results*/ ctx[1];
|
|
let each_blocks = [];
|
|
|
|
for (let i = 0; i < each_value.length; i += 1) {
|
|
each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
|
|
}
|
|
|
|
const out = i => transition_out(each_blocks[i], 1, 1, () => {
|
|
each_blocks[i] = null;
|
|
});
|
|
|
|
return {
|
|
c() {
|
|
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
each_blocks[i].c();
|
|
}
|
|
|
|
each_1_anchor = empty();
|
|
},
|
|
m(target, anchor) {
|
|
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
each_blocks[i].m(target, anchor);
|
|
}
|
|
|
|
insert(target, each_1_anchor, anchor);
|
|
current = true;
|
|
},
|
|
p(ctx, dirty) {
|
|
if (dirty[0] & /*id, selectedIndex, results, select, $$scope, value*/ 2097479) {
|
|
each_value = /*results*/ ctx[1];
|
|
let i;
|
|
|
|
for (i = 0; i < each_value.length; i += 1) {
|
|
const child_ctx = get_each_context(ctx, each_value, i);
|
|
|
|
if (each_blocks[i]) {
|
|
each_blocks[i].p(child_ctx, dirty);
|
|
transition_in(each_blocks[i], 1);
|
|
} else {
|
|
each_blocks[i] = create_each_block(child_ctx);
|
|
each_blocks[i].c();
|
|
transition_in(each_blocks[i], 1);
|
|
each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
|
|
}
|
|
}
|
|
|
|
group_outros();
|
|
|
|
for (i = each_value.length; i < each_blocks.length; i += 1) {
|
|
out(i);
|
|
}
|
|
|
|
check_outros();
|
|
}
|
|
},
|
|
i(local) {
|
|
if (current) return;
|
|
|
|
for (let i = 0; i < each_value.length; i += 1) {
|
|
transition_in(each_blocks[i]);
|
|
}
|
|
|
|
current = true;
|
|
},
|
|
o(local) {
|
|
each_blocks = each_blocks.filter(Boolean);
|
|
|
|
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
transition_out(each_blocks[i]);
|
|
}
|
|
|
|
current = false;
|
|
},
|
|
d(detaching) {
|
|
destroy_each(each_blocks, detaching);
|
|
if (detaching) detach(each_1_anchor);
|
|
}
|
|
};
|
|
}
|
|
|
|
// (219:41)
|
|
function fallback_block(ctx) {
|
|
let html_tag;
|
|
let raw_value = /*result*/ ctx[42].string + "";
|
|
let html_anchor;
|
|
|
|
return {
|
|
c() {
|
|
html_tag = new HtmlTag(false);
|
|
html_anchor = empty();
|
|
html_tag.a = html_anchor;
|
|
},
|
|
m(target, anchor) {
|
|
html_tag.m(raw_value, target, anchor);
|
|
insert(target, html_anchor, anchor);
|
|
},
|
|
p(ctx, dirty) {
|
|
if (dirty[0] & /*results*/ 2 && raw_value !== (raw_value = /*result*/ ctx[42].string + "")) html_tag.p(raw_value);
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(html_anchor);
|
|
if (detaching) html_tag.d();
|
|
}
|
|
};
|
|
}
|
|
|
|
// (202:6) {#each results as result, index}
|
|
function create_each_block(ctx) {
|
|
let li;
|
|
let t;
|
|
let li_id_value;
|
|
let li_aria_selected_value;
|
|
let current;
|
|
let mounted;
|
|
let dispose;
|
|
const default_slot_template = /*#slots*/ ctx[22].default;
|
|
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[21], get_default_slot_context);
|
|
const default_slot_or_fallback = default_slot || fallback_block(ctx);
|
|
|
|
function click_handler_1() {
|
|
return /*click_handler_1*/ ctx[36](/*result*/ ctx[42], /*index*/ ctx[44]);
|
|
}
|
|
|
|
function mouseenter_handler() {
|
|
return /*mouseenter_handler*/ ctx[37](/*result*/ ctx[42], /*index*/ ctx[44]);
|
|
}
|
|
|
|
return {
|
|
c() {
|
|
li = element("li");
|
|
if (default_slot_or_fallback) default_slot_or_fallback.c();
|
|
t = space();
|
|
attr(li, "role", "option");
|
|
attr(li, "id", li_id_value = "" + (/*id*/ ctx[2] + "-result-" + /*index*/ ctx[44]));
|
|
attr(li, "aria-selected", li_aria_selected_value = /*selectedIndex*/ ctx[6] === /*index*/ ctx[44]);
|
|
attr(li, "class", "svelte-9wywte");
|
|
toggle_class(li, "selected", /*selectedIndex*/ ctx[6] === /*index*/ ctx[44]);
|
|
toggle_class(li, "disabled", /*result*/ ctx[42].disabled);
|
|
},
|
|
m(target, anchor) {
|
|
insert(target, li, anchor);
|
|
|
|
if (default_slot_or_fallback) {
|
|
default_slot_or_fallback.m(li, null);
|
|
}
|
|
|
|
append(li, t);
|
|
current = true;
|
|
|
|
if (!mounted) {
|
|
dispose = [
|
|
listen(li, "click", click_handler_1),
|
|
listen(li, "mouseenter", mouseenter_handler)
|
|
];
|
|
|
|
mounted = true;
|
|
}
|
|
},
|
|
p(new_ctx, dirty) {
|
|
ctx = new_ctx;
|
|
|
|
if (default_slot) {
|
|
if (default_slot.p && (!current || dirty[0] & /*$$scope, results, value*/ 2097155)) {
|
|
update_slot_base(
|
|
default_slot,
|
|
default_slot_template,
|
|
ctx,
|
|
/*$$scope*/ ctx[21],
|
|
!current
|
|
? get_all_dirty_from_scope(/*$$scope*/ ctx[21])
|
|
: get_slot_changes(default_slot_template, /*$$scope*/ ctx[21], dirty, get_default_slot_changes),
|
|
get_default_slot_context
|
|
);
|
|
}
|
|
} else {
|
|
if (default_slot_or_fallback && default_slot_or_fallback.p && (!current || dirty[0] & /*results*/ 2)) {
|
|
default_slot_or_fallback.p(ctx, !current ? [-1, -1] : dirty);
|
|
}
|
|
}
|
|
|
|
if (!current || dirty[0] & /*id*/ 4 && li_id_value !== (li_id_value = "" + (/*id*/ ctx[2] + "-result-" + /*index*/ ctx[44]))) {
|
|
attr(li, "id", li_id_value);
|
|
}
|
|
|
|
if (!current || dirty[0] & /*selectedIndex*/ 64 && li_aria_selected_value !== (li_aria_selected_value = /*selectedIndex*/ ctx[6] === /*index*/ ctx[44])) {
|
|
attr(li, "aria-selected", li_aria_selected_value);
|
|
}
|
|
|
|
if (dirty[0] & /*selectedIndex*/ 64) {
|
|
toggle_class(li, "selected", /*selectedIndex*/ ctx[6] === /*index*/ ctx[44]);
|
|
}
|
|
|
|
if (dirty[0] & /*results*/ 2) {
|
|
toggle_class(li, "disabled", /*result*/ ctx[42].disabled);
|
|
}
|
|
},
|
|
i(local) {
|
|
if (current) return;
|
|
transition_in(default_slot_or_fallback, local);
|
|
current = true;
|
|
},
|
|
o(local) {
|
|
transition_out(default_slot_or_fallback, local);
|
|
current = false;
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(li);
|
|
if (default_slot_or_fallback) default_slot_or_fallback.d(detaching);
|
|
mounted = false;
|
|
run_all(dispose);
|
|
}
|
|
};
|
|
}
|
|
|
|
// (225:4) {#if $$slots["no-results"] && !hideDropdown && value.length > 0 && results.length === 0}
|
|
function create_if_block(ctx) {
|
|
let div;
|
|
let current;
|
|
const no_results_slot_template = /*#slots*/ ctx[22]["no-results"];
|
|
const no_results_slot = create_slot(no_results_slot_template, ctx, /*$$scope*/ ctx[21], get_no_results_slot_context);
|
|
|
|
return {
|
|
c() {
|
|
div = element("div");
|
|
if (no_results_slot) no_results_slot.c();
|
|
attr(div, "class", "svelte-9wywte");
|
|
toggle_class(div, "no-results", true);
|
|
},
|
|
m(target, anchor) {
|
|
insert(target, div, anchor);
|
|
|
|
if (no_results_slot) {
|
|
no_results_slot.m(div, null);
|
|
}
|
|
|
|
current = true;
|
|
},
|
|
p(ctx, dirty) {
|
|
if (no_results_slot) {
|
|
if (no_results_slot.p && (!current || dirty[0] & /*$$scope, value, results*/ 2097155)) {
|
|
update_slot_base(
|
|
no_results_slot,
|
|
no_results_slot_template,
|
|
ctx,
|
|
/*$$scope*/ ctx[21],
|
|
!current
|
|
? get_all_dirty_from_scope(/*$$scope*/ ctx[21])
|
|
: get_slot_changes(no_results_slot_template, /*$$scope*/ ctx[21], dirty, get_no_results_slot_changes),
|
|
get_no_results_slot_context
|
|
);
|
|
}
|
|
}
|
|
},
|
|
i(local) {
|
|
if (current) return;
|
|
transition_in(no_results_slot, local);
|
|
current = true;
|
|
},
|
|
o(local) {
|
|
transition_out(no_results_slot, local);
|
|
current = false;
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(div);
|
|
if (no_results_slot) no_results_slot.d(detaching);
|
|
}
|
|
};
|
|
}
|
|
|
|
function create_fragment(ctx) {
|
|
let div;
|
|
let search;
|
|
let updating_ref;
|
|
let updating_value;
|
|
let t0;
|
|
let ul;
|
|
let t1;
|
|
let ul_aria_labelledby_value;
|
|
let ul_id_value;
|
|
let div_aria_owns_value;
|
|
let div_id_value;
|
|
let current;
|
|
let mounted;
|
|
let dispose;
|
|
|
|
const search_spread_levels = [
|
|
{ id: /*id*/ ctx[2] },
|
|
{ removeFormAriaAttributes: true },
|
|
/*$$restProps*/ ctx[11],
|
|
{ "aria-autocomplete": "list" },
|
|
{
|
|
"aria-controls": "" + (/*id*/ ctx[2] + "-listbox")
|
|
},
|
|
{
|
|
"aria-labelledby": "" + (/*id*/ ctx[2] + "-label")
|
|
},
|
|
{
|
|
"aria-activedescendant": /*selectedIndex*/ ctx[6] >= 0 && !/*hideDropdown*/ ctx[3] && /*results*/ ctx[1].length > 0
|
|
? `${/*id*/ ctx[2]}-result-${/*selectedIndex*/ ctx[6]}`
|
|
: null
|
|
}
|
|
];
|
|
|
|
function search_ref_binding(value) {
|
|
/*search_ref_binding*/ ctx[24](value);
|
|
}
|
|
|
|
function search_value_binding(value) {
|
|
/*search_value_binding*/ ctx[25](value);
|
|
}
|
|
|
|
let search_props = {};
|
|
|
|
for (let i = 0; i < search_spread_levels.length; i += 1) {
|
|
search_props = assign(search_props, search_spread_levels[i]);
|
|
}
|
|
|
|
if (/*searchRef*/ ctx[5] !== void 0) {
|
|
search_props.ref = /*searchRef*/ ctx[5];
|
|
}
|
|
|
|
if (/*value*/ ctx[0] !== void 0) {
|
|
search_props.value = /*value*/ ctx[0];
|
|
}
|
|
|
|
search = new Search$1({ props: search_props });
|
|
binding_callbacks.push(() => bind(search, 'ref', search_ref_binding));
|
|
binding_callbacks.push(() => bind(search, 'value', search_value_binding));
|
|
search.$on("type", /*type_handler*/ ctx[26]);
|
|
search.$on("input", /*input_handler*/ ctx[27]);
|
|
search.$on("change", /*change_handler*/ ctx[28]);
|
|
search.$on("focus", /*focus_handler*/ ctx[29]);
|
|
search.$on("focus", /*focus_handler_1*/ ctx[30]);
|
|
search.$on("clear", /*clear_handler*/ ctx[31]);
|
|
search.$on("clear", /*clear_handler_1*/ ctx[32]);
|
|
search.$on("blur", /*blur_handler*/ ctx[33]);
|
|
search.$on("keydown", /*keydown_handler*/ ctx[34]);
|
|
search.$on("keydown", /*keydown_handler_1*/ ctx[35]);
|
|
let if_block0 = /*showResults*/ ctx[7] && create_if_block_1(ctx);
|
|
let if_block1 = /*$$slots*/ ctx[10]["no-results"] && !/*hideDropdown*/ ctx[3] && /*value*/ ctx[0].length > 0 && /*results*/ ctx[1].length === 0 && create_if_block(ctx);
|
|
|
|
return {
|
|
c() {
|
|
div = element("div");
|
|
create_component(search.$$.fragment);
|
|
t0 = space();
|
|
ul = element("ul");
|
|
if (if_block0) if_block0.c();
|
|
t1 = space();
|
|
if (if_block1) if_block1.c();
|
|
attr(ul, "role", "listbox");
|
|
attr(ul, "aria-labelledby", ul_aria_labelledby_value = "" + (/*id*/ ctx[2] + "-label"));
|
|
attr(ul, "id", ul_id_value = "" + (/*id*/ ctx[2] + "-listbox"));
|
|
attr(ul, "class", "svelte-9wywte");
|
|
toggle_class(ul, "svelte-typeahead-list", true);
|
|
attr(div, "data-svelte-typeahead", "");
|
|
attr(div, "role", "combobox");
|
|
attr(div, "aria-haspopup", "listbox");
|
|
attr(div, "aria-owns", div_aria_owns_value = "" + (/*id*/ ctx[2] + "-listbox"));
|
|
attr(div, "aria-expanded", /*showResults*/ ctx[7]);
|
|
attr(div, "id", div_id_value = "" + (/*id*/ ctx[2] + "-typeahead"));
|
|
attr(div, "class", "svelte-9wywte");
|
|
toggle_class(div, "dropdown", /*results*/ ctx[1].length > 0);
|
|
},
|
|
m(target, anchor) {
|
|
insert(target, div, anchor);
|
|
mount_component(search, div, null);
|
|
append(div, t0);
|
|
append(div, ul);
|
|
if (if_block0) if_block0.m(ul, null);
|
|
append(ul, t1);
|
|
if (if_block1) if_block1.m(ul, null);
|
|
/*div_binding*/ ctx[38](div);
|
|
current = true;
|
|
|
|
if (!mounted) {
|
|
dispose = listen(window, "click", /*click_handler*/ ctx[23]);
|
|
mounted = true;
|
|
}
|
|
},
|
|
p(ctx, dirty) {
|
|
const search_changes = (dirty[0] & /*id, $$restProps, selectedIndex, hideDropdown, results*/ 2126)
|
|
? get_spread_update(search_spread_levels, [
|
|
dirty[0] & /*id*/ 4 && { id: /*id*/ ctx[2] },
|
|
search_spread_levels[1],
|
|
dirty[0] & /*$$restProps*/ 2048 && get_spread_object(/*$$restProps*/ ctx[11]),
|
|
search_spread_levels[3],
|
|
dirty[0] & /*id*/ 4 && {
|
|
"aria-controls": "" + (/*id*/ ctx[2] + "-listbox")
|
|
},
|
|
dirty[0] & /*id*/ 4 && {
|
|
"aria-labelledby": "" + (/*id*/ ctx[2] + "-label")
|
|
},
|
|
dirty[0] & /*selectedIndex, hideDropdown, results, id*/ 78 && {
|
|
"aria-activedescendant": /*selectedIndex*/ ctx[6] >= 0 && !/*hideDropdown*/ ctx[3] && /*results*/ ctx[1].length > 0
|
|
? `${/*id*/ ctx[2]}-result-${/*selectedIndex*/ ctx[6]}`
|
|
: null
|
|
}
|
|
])
|
|
: {};
|
|
|
|
if (!updating_ref && dirty[0] & /*searchRef*/ 32) {
|
|
updating_ref = true;
|
|
search_changes.ref = /*searchRef*/ ctx[5];
|
|
add_flush_callback(() => updating_ref = false);
|
|
}
|
|
|
|
if (!updating_value && dirty[0] & /*value*/ 1) {
|
|
updating_value = true;
|
|
search_changes.value = /*value*/ ctx[0];
|
|
add_flush_callback(() => updating_value = false);
|
|
}
|
|
|
|
search.$set(search_changes);
|
|
|
|
if (/*showResults*/ ctx[7]) {
|
|
if (if_block0) {
|
|
if_block0.p(ctx, dirty);
|
|
|
|
if (dirty[0] & /*showResults*/ 128) {
|
|
transition_in(if_block0, 1);
|
|
}
|
|
} else {
|
|
if_block0 = create_if_block_1(ctx);
|
|
if_block0.c();
|
|
transition_in(if_block0, 1);
|
|
if_block0.m(ul, t1);
|
|
}
|
|
} else if (if_block0) {
|
|
group_outros();
|
|
|
|
transition_out(if_block0, 1, 1, () => {
|
|
if_block0 = null;
|
|
});
|
|
|
|
check_outros();
|
|
}
|
|
|
|
if (/*$$slots*/ ctx[10]["no-results"] && !/*hideDropdown*/ ctx[3] && /*value*/ ctx[0].length > 0 && /*results*/ ctx[1].length === 0) {
|
|
if (if_block1) {
|
|
if_block1.p(ctx, dirty);
|
|
|
|
if (dirty[0] & /*$$slots, hideDropdown, value, results*/ 1035) {
|
|
transition_in(if_block1, 1);
|
|
}
|
|
} else {
|
|
if_block1 = create_if_block(ctx);
|
|
if_block1.c();
|
|
transition_in(if_block1, 1);
|
|
if_block1.m(ul, null);
|
|
}
|
|
} else if (if_block1) {
|
|
group_outros();
|
|
|
|
transition_out(if_block1, 1, 1, () => {
|
|
if_block1 = null;
|
|
});
|
|
|
|
check_outros();
|
|
}
|
|
|
|
if (!current || dirty[0] & /*id*/ 4 && ul_aria_labelledby_value !== (ul_aria_labelledby_value = "" + (/*id*/ ctx[2] + "-label"))) {
|
|
attr(ul, "aria-labelledby", ul_aria_labelledby_value);
|
|
}
|
|
|
|
if (!current || dirty[0] & /*id*/ 4 && ul_id_value !== (ul_id_value = "" + (/*id*/ ctx[2] + "-listbox"))) {
|
|
attr(ul, "id", ul_id_value);
|
|
}
|
|
|
|
if (!current || dirty[0] & /*id*/ 4 && div_aria_owns_value !== (div_aria_owns_value = "" + (/*id*/ ctx[2] + "-listbox"))) {
|
|
attr(div, "aria-owns", div_aria_owns_value);
|
|
}
|
|
|
|
if (!current || dirty[0] & /*showResults*/ 128) {
|
|
attr(div, "aria-expanded", /*showResults*/ ctx[7]);
|
|
}
|
|
|
|
if (!current || dirty[0] & /*id*/ 4 && div_id_value !== (div_id_value = "" + (/*id*/ ctx[2] + "-typeahead"))) {
|
|
attr(div, "id", div_id_value);
|
|
}
|
|
|
|
if (dirty[0] & /*results*/ 2) {
|
|
toggle_class(div, "dropdown", /*results*/ ctx[1].length > 0);
|
|
}
|
|
},
|
|
i(local) {
|
|
if (current) return;
|
|
transition_in(search.$$.fragment, local);
|
|
transition_in(if_block0);
|
|
transition_in(if_block1);
|
|
current = true;
|
|
},
|
|
o(local) {
|
|
transition_out(search.$$.fragment, local);
|
|
transition_out(if_block0);
|
|
transition_out(if_block1);
|
|
current = false;
|
|
},
|
|
d(detaching) {
|
|
if (detaching) detach(div);
|
|
destroy_component(search);
|
|
if (if_block0) if_block0.d();
|
|
if (if_block1) if_block1.d();
|
|
/*div_binding*/ ctx[38](null);
|
|
mounted = false;
|
|
dispose();
|
|
}
|
|
};
|
|
}
|
|
|
|
function instance($$self, $$props, $$invalidate) {
|
|
let options;
|
|
let resultsId;
|
|
let showResults;
|
|
|
|
const omit_props_names = [
|
|
"id","value","data","extract","disable","filter","autoselect","inputAfterSelect","results","focusAfterSelect","limit"
|
|
];
|
|
|
|
let $$restProps = compute_rest_props($$props, omit_props_names);
|
|
let { $$slots: slots = {}, $$scope } = $$props;
|
|
const $$slots = compute_slots(slots);
|
|
let { id = "typeahead-" + Math.random().toString(36) } = $$props;
|
|
let { value = "" } = $$props;
|
|
let { data = [] } = $$props;
|
|
let { extract = item => item } = $$props;
|
|
let { disable = item => false } = $$props;
|
|
let { filter = item => false } = $$props;
|
|
let { autoselect = true } = $$props;
|
|
let { inputAfterSelect = "update" } = $$props;
|
|
let { results = [] } = $$props;
|
|
let { focusAfterSelect = false } = $$props;
|
|
let { limit = Infinity } = $$props;
|
|
const dispatch = createEventDispatcher();
|
|
let comboboxRef = null;
|
|
let searchRef = null;
|
|
let hideDropdown = false;
|
|
let selectedIndex = -1;
|
|
let prevResults = "";
|
|
|
|
afterUpdate(() => {
|
|
if (prevResults !== resultsId && autoselect) {
|
|
$$invalidate(6, selectedIndex = 0);
|
|
}
|
|
|
|
if (prevResults !== resultsId && !$$slots["no-results"]) {
|
|
$$invalidate(3, hideDropdown = results.length === 0);
|
|
}
|
|
|
|
prevResults = resultsId;
|
|
});
|
|
|
|
async function select() {
|
|
const result = results[selectedIndex];
|
|
if (result.disabled) return;
|
|
const selectedValue = extract(result.original);
|
|
const searchedValue = value;
|
|
if (inputAfterSelect == "clear") $$invalidate(0, value = "");
|
|
if (inputAfterSelect == "update") $$invalidate(0, value = selectedValue);
|
|
|
|
dispatch("select", {
|
|
selectedIndex,
|
|
searched: searchedValue,
|
|
selected: selectedValue,
|
|
original: result.original,
|
|
originalIndex: result.index
|
|
});
|
|
|
|
await tick();
|
|
if (focusAfterSelect) searchRef.focus();
|
|
$$invalidate(3, hideDropdown = true);
|
|
}
|
|
|
|
/** @type {(direction: -1 | 1) => void} */
|
|
function change(direction) {
|
|
let index = direction === 1 && selectedIndex === results.length - 1
|
|
? 0
|
|
: selectedIndex + direction;
|
|
|
|
if (index < 0) index = results.length - 1;
|
|
let disabled = results[index].disabled;
|
|
|
|
while (disabled) {
|
|
if (index === results.length) {
|
|
index = 0;
|
|
} else {
|
|
index += direction;
|
|
}
|
|
|
|
disabled = results[index].disabled;
|
|
}
|
|
|
|
$$invalidate(6, selectedIndex = index);
|
|
}
|
|
|
|
const click_handler = ({ target }) => {
|
|
if (!hideDropdown && comboboxRef && !comboboxRef.contains(target)) {
|
|
$$invalidate(3, hideDropdown = true);
|
|
}
|
|
};
|
|
|
|
function search_ref_binding(value) {
|
|
searchRef = value;
|
|
$$invalidate(5, searchRef);
|
|
}
|
|
|
|
function search_value_binding(value$1) {
|
|
value = value$1;
|
|
$$invalidate(0, value);
|
|
}
|
|
|
|
function type_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function input_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function change_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function focus_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
const focus_handler_1 = () => {
|
|
$$invalidate(3, hideDropdown = false);
|
|
};
|
|
|
|
function clear_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
const clear_handler_1 = () => {
|
|
$$invalidate(3, hideDropdown = false);
|
|
};
|
|
|
|
function blur_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
function keydown_handler(event) {
|
|
bubble.call(this, $$self, event);
|
|
}
|
|
|
|
const keydown_handler_1 = e => {
|
|
if (results.length === 0) return;
|
|
|
|
switch (e.key) {
|
|
case "Enter":
|
|
select();
|
|
break;
|
|
case "ArrowDown":
|
|
e.preventDefault();
|
|
change(1);
|
|
break;
|
|
case "ArrowUp":
|
|
e.preventDefault();
|
|
change(-1);
|
|
break;
|
|
case "Escape":
|
|
e.preventDefault();
|
|
$$invalidate(0, value = "");
|
|
searchRef.focus();
|
|
$$invalidate(3, hideDropdown = true);
|
|
break;
|
|
}
|
|
};
|
|
|
|
const click_handler_1 = (result, index) => {
|
|
if (result.disabled) return;
|
|
$$invalidate(6, selectedIndex = index);
|
|
select();
|
|
};
|
|
|
|
const mouseenter_handler = (result, index) => {
|
|
if (result.disabled) return;
|
|
$$invalidate(6, selectedIndex = index);
|
|
};
|
|
|
|
function div_binding($$value) {
|
|
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
comboboxRef = $$value;
|
|
$$invalidate(4, comboboxRef);
|
|
});
|
|
}
|
|
|
|
$$self.$$set = $$new_props => {
|
|
$$props = assign(assign({}, $$props), exclude_internal_props($$new_props));
|
|
$$invalidate(11, $$restProps = compute_rest_props($$props, omit_props_names));
|
|
if ('id' in $$new_props) $$invalidate(2, id = $$new_props.id);
|
|
if ('value' in $$new_props) $$invalidate(0, value = $$new_props.value);
|
|
if ('data' in $$new_props) $$invalidate(12, data = $$new_props.data);
|
|
if ('extract' in $$new_props) $$invalidate(13, extract = $$new_props.extract);
|
|
if ('disable' in $$new_props) $$invalidate(14, disable = $$new_props.disable);
|
|
if ('filter' in $$new_props) $$invalidate(15, filter = $$new_props.filter);
|
|
if ('autoselect' in $$new_props) $$invalidate(16, autoselect = $$new_props.autoselect);
|
|
if ('inputAfterSelect' in $$new_props) $$invalidate(17, inputAfterSelect = $$new_props.inputAfterSelect);
|
|
if ('results' in $$new_props) $$invalidate(1, results = $$new_props.results);
|
|
if ('focusAfterSelect' in $$new_props) $$invalidate(18, focusAfterSelect = $$new_props.focusAfterSelect);
|
|
if ('limit' in $$new_props) $$invalidate(19, limit = $$new_props.limit);
|
|
if ('$$scope' in $$new_props) $$invalidate(21, $$scope = $$new_props.$$scope);
|
|
};
|
|
|
|
$$self.$$.update = () => {
|
|
if ($$self.$$.dirty[0] & /*extract*/ 8192) {
|
|
$$invalidate(20, options = { pre: "<mark>", post: "</mark>", extract });
|
|
}
|
|
|
|
if ($$self.$$.dirty[0] & /*value, data, options, limit, filter, disable*/ 1626113) {
|
|
$$invalidate(1, results = fuzzy.filter(value, data, options).filter(({ score }) => score > 0).slice(0, limit).filter(result => !filter(result.original)).map(result => ({
|
|
...result,
|
|
disabled: disable(result.original)
|
|
})));
|
|
}
|
|
|
|
if ($$self.$$.dirty[0] & /*results, extract*/ 8194) {
|
|
resultsId = results.map(result => extract(result.original)).join("");
|
|
}
|
|
|
|
if ($$self.$$.dirty[0] & /*hideDropdown, results*/ 10) {
|
|
$$invalidate(7, showResults = !hideDropdown && results.length > 0);
|
|
}
|
|
};
|
|
|
|
return [
|
|
value,
|
|
results,
|
|
id,
|
|
hideDropdown,
|
|
comboboxRef,
|
|
searchRef,
|
|
selectedIndex,
|
|
showResults,
|
|
select,
|
|
change,
|
|
$$slots,
|
|
$$restProps,
|
|
data,
|
|
extract,
|
|
disable,
|
|
filter,
|
|
autoselect,
|
|
inputAfterSelect,
|
|
focusAfterSelect,
|
|
limit,
|
|
options,
|
|
$$scope,
|
|
slots,
|
|
click_handler,
|
|
search_ref_binding,
|
|
search_value_binding,
|
|
type_handler,
|
|
input_handler,
|
|
change_handler,
|
|
focus_handler,
|
|
focus_handler_1,
|
|
clear_handler,
|
|
clear_handler_1,
|
|
blur_handler,
|
|
keydown_handler,
|
|
keydown_handler_1,
|
|
click_handler_1,
|
|
mouseenter_handler,
|
|
div_binding
|
|
];
|
|
}
|
|
|
|
class Typeahead extends SvelteComponent {
|
|
constructor(options) {
|
|
super();
|
|
|
|
init(
|
|
this,
|
|
options,
|
|
instance,
|
|
create_fragment,
|
|
safe_not_equal,
|
|
{
|
|
id: 2,
|
|
value: 0,
|
|
data: 12,
|
|
extract: 13,
|
|
disable: 14,
|
|
filter: 15,
|
|
autoselect: 16,
|
|
inputAfterSelect: 17,
|
|
results: 1,
|
|
focusAfterSelect: 18,
|
|
limit: 19
|
|
},
|
|
add_css,
|
|
[-1, -1]
|
|
);
|
|
}
|
|
}
|
|
|
|
var Typeahead$1 = Typeahead;
|
|
|
|
exports["default"] = Typeahead$1;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
}));
|