-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
174 lines (159 loc) · 5.22 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
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);
}
// source: https://html.spec.whatwg.org/multipage/indices.html
const boolean_attributes = new Set([
'allowfullscreen',
'allowpaymentrequest',
'async',
'autofocus',
'autoplay',
'checked',
'controls',
'default',
'defer',
'disabled',
'formnovalidate',
'hidden',
'ismap',
'loop',
'multiple',
'muted',
'nomodule',
'novalidate',
'open',
'playsinline',
'readonly',
'required',
'reversed',
'selected'
]);
const invalid_attribute_name_character = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
// https://infra.spec.whatwg.org/#noncharacter
function spread(args, classes_to_add) {
const attributes = Object.assign({}, ...args);
if (classes_to_add) {
if (attributes.class == null) {
attributes.class = classes_to_add;
}
else {
attributes.class += ' ' + classes_to_add;
}
}
let str = '';
Object.keys(attributes).forEach(name => {
if (invalid_attribute_name_character.test(name))
return;
const value = attributes[name];
if (value === true)
str += " " + name;
else if (boolean_attributes.has(name.toLowerCase())) {
if (value)
str += " " + name;
}
else if (value != null) {
str += ` ${name}="${String(value).replace(/"/g, '"').replace(/'/g, ''')}"`;
}
});
return str;
}
const escaped = {
'"': '"',
"'": ''',
'&': '&',
'<': '<',
'>': '>'
};
function escape(html) {
return String(html).replace(/["'&<>]/g, match => escaped[match]);
}
let on_destroy;
function create_ssr_component(fn) {
function $$render(result, props, bindings, slots) {
const parent_component = current_component;
const $$ = {
on_destroy,
context: new Map(parent_component ? parent_component.$$.context : []),
// these will be immediately discarded
on_mount: [],
before_update: [],
after_update: [],
callbacks: blank_object()
};
set_current_component({ $$ });
const html = fn(result, props, bindings, slots);
set_current_component(parent_component);
return html;
}
return {
render: (props = {}, options = {}) => {
on_destroy = [];
const result = { title: '', head: '', css: new Set() };
const html = $$render(result, props, {}, options);
run_all(on_destroy);
return {
html,
css: {
code: Array.from(result.css).map(css => css.code).join('\n'),
map: null // TODO
},
head: result.title + result.head
};
},
$$render
};
}
function add_attribute(name, value, boolean) {
if (value == null || (boolean && !value))
return '';
return ` ${name}${value === true ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`;
}
let libClassName = 'svelte-auto-complete';
const setConfiguration = obj => {
};
const DIRECTION = {
BOTTOM: 'BOTTOM',
LEFT: 'LEFT',
RIGHT: 'RIGHT',
TOP: 'TOP'
};
/* src/AutoComplete.svelte generated by Svelte v3.21.0 */
const AutoComplete = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
let { value = "" } = $$props;
let filteredOptions = [];
let input;
function filter() {
if (value.length < minLength) filteredOptions = []; else filteredOptions = options.filter(o => matchingFunction(value, getOptionText(o)) && value !== getOptionValue(o));
}
onMount(() => filter());
if ($$props.value === void 0 && $$bindings.value && value !== void 0) $$bindings.value(value);
let $$settled;
let $$rendered;
do {
$$settled = true;
let { direction = [DIRECTION.LEFT, DIRECTION.BOTTOM], getOptionText = o => o, getOptionValue = o => o, matchingFunction = (value, optionValue) => optionValue.toLowerCase().startsWith(value.toLowerCase()), options, value: providedValue, minLength = 0, onBlur, onFocus, onInput, ...nativeProps } = $$props;
$$rendered = `<input${spread([{ class: escape(libClassName) }, { type: "text" }, nativeProps])}${add_attribute("this", input, 1)}${add_attribute("value", value, 1)}>
${ ``}`;
} while (!$$settled);
return $$rendered;
});
export { AutoComplete, DIRECTION, setConfiguration };