Upload 14 files
Browse files- streamlit_app/__pycache__/app.cpython-310.pyc +0 -0
- streamlit_app/__pycache__/clean_tagged_question.cpython-310.pyc +0 -0
- streamlit_app/__pycache__/command.cpython-310.pyc +0 -0
- streamlit_app/__pycache__/tagged_question_parser.cpython-310.pyc +0 -0
- streamlit_app/app.py +245 -0
- streamlit_app/clean_tagged_question.py +63 -0
- streamlit_app/command.py +68 -0
- streamlit_app/flask_api.py +25 -0
- streamlit_app/lib/bindings/utils.js +189 -0
- streamlit_app/lib/tom-select/tom-select.complete.min.js +356 -0
- streamlit_app/lib/tom-select/tom-select.css +334 -0
- streamlit_app/lib/vis-9.1.2/vis-network.css +0 -0
- streamlit_app/lib/vis-9.1.2/vis-network.min.js +0 -0
- streamlit_app/tagged_question_parser.py +39 -0
streamlit_app/__pycache__/app.cpython-310.pyc
ADDED
Binary file (6.56 kB). View file
|
|
streamlit_app/__pycache__/clean_tagged_question.cpython-310.pyc
ADDED
Binary file (1.64 kB). View file
|
|
streamlit_app/__pycache__/command.cpython-310.pyc
ADDED
Binary file (1.98 kB). View file
|
|
streamlit_app/__pycache__/tagged_question_parser.cpython-310.pyc
ADDED
Binary file (1.18 kB). View file
|
|
streamlit_app/app.py
ADDED
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import re
|
3 |
+
import networkx as nx
|
4 |
+
from pyvis.network import Network
|
5 |
+
import streamlit.components.v1 as components
|
6 |
+
from command import get_tagged_question
|
7 |
+
from clean_tagged_question import clean_tagged_output
|
8 |
+
|
9 |
+
# Define a function to tag the question
|
10 |
+
def tag_question(text):
|
11 |
+
tagged_question = get_tagged_question(text)
|
12 |
+
|
13 |
+
tagged_question = clean_tagged_output(tagged_question, text)
|
14 |
+
|
15 |
+
return tagged_question
|
16 |
+
|
17 |
+
# Define a function to highlight the tagged question
|
18 |
+
def highlight_tags(text):
|
19 |
+
tag_styles = {
|
20 |
+
"qt": "background-color: yellow; padding: 1mm; border-radius: 8px;",
|
21 |
+
"t": "background-color: lightgreen; padding: 1mm; border-radius: 8px;",
|
22 |
+
"p": "background-color: lightblue; padding: 1mm; border-radius: 8px;",
|
23 |
+
"o": "background-color: lightcoral; padding: 1mm; border-radius: 8px;",
|
24 |
+
"s": "background-color: lightgrey; padding: 1mm; border-radius: 8px;",
|
25 |
+
"cc": "background-color: lightpink; padding: 1mm; border-radius: 8px;",
|
26 |
+
"off": "background-color: lightcyan; padding: 1mm; border-radius: 8px;",
|
27 |
+
"ref": "background-color: lightgoldenrodyellow; padding: 1mm; border-radius: 8px;",
|
28 |
+
"op": "background-color: burlywood; padding: 1mm; border-radius: 8px;"
|
29 |
+
}
|
30 |
+
|
31 |
+
highlighted_text = text
|
32 |
+
for tag, style in tag_styles.items():
|
33 |
+
highlighted_text = re.sub(f'<{tag}>(.*?)</{tag}>', f'<span style="{style}">\\1</span>', highlighted_text, flags=re.IGNORECASE)
|
34 |
+
|
35 |
+
return highlighted_text
|
36 |
+
|
37 |
+
def draw_interactive_graph(tagged_text):
|
38 |
+
node_size=10
|
39 |
+
G = nx.DiGraph() # Initialize a directed graph to maintain the direction of relationships.
|
40 |
+
|
41 |
+
# Split the tagged text by tags while preserving tags and excluding empty strings.
|
42 |
+
tokens = [token for token in re.split(r'(<[^>]+>[^<]+</[^>]+>)', tagged_text) if token.strip()]
|
43 |
+
print('tokenize the tagged question:', tokens)
|
44 |
+
|
45 |
+
# Define the central node, acting as the query's root.
|
46 |
+
current_subject = '?seed'
|
47 |
+
G.add_node(current_subject, color='yellow', size=node_size)
|
48 |
+
|
49 |
+
i = 0
|
50 |
+
while i < len(tokens):
|
51 |
+
token = tokens[i]
|
52 |
+
|
53 |
+
# Check for a question type followed by a type tag to establish a fundamental 'is_a' relation.
|
54 |
+
if '<qt>' in token and i+1 < len(tokens) and '<t>' in tokens[i+1]:
|
55 |
+
match = re.search(r'<t>(.*?)</t>', tokens[i+1])
|
56 |
+
if match:
|
57 |
+
entity = match.group(1)
|
58 |
+
G.add_node(entity, color='lightgreen', size=node_size)
|
59 |
+
G.add_edge(current_subject, entity, label='is_a')
|
60 |
+
i += 1
|
61 |
+
print('Case for a question type followed by a type tag')
|
62 |
+
print('entity:', entity)
|
63 |
+
print('predicate: is_a')
|
64 |
+
print('to process:', tokens[i+1:])
|
65 |
+
|
66 |
+
# Handle predicates which form the basis of relationships in the graph.
|
67 |
+
elif '<p>' in token:
|
68 |
+
predicate_match = re.search(r'<p>(.*?)</p>', token)
|
69 |
+
if predicate_match:
|
70 |
+
predicate = predicate_match.group(1)
|
71 |
+
|
72 |
+
# Check if the next token is <op> and update the predicate accordingly.
|
73 |
+
if i + 1 < len(tokens) and '<op>' in tokens[i + 1]:
|
74 |
+
op_match = re.search(r'<op>(.*?)</op>', tokens[i + 1])
|
75 |
+
if op_match:
|
76 |
+
predicate = f"{predicate} ({op_match.group(1)})"
|
77 |
+
i += 1 # Advance to skip the <op> tag.
|
78 |
+
|
79 |
+
# Case for a single predicate followed directly by an object.
|
80 |
+
if i+1 < len(tokens) and '<o>' in tokens[i+1]:
|
81 |
+
object_list = []
|
82 |
+
j = i + 1
|
83 |
+
# Gather all objects connected by this predicate, possibly separated by coordinating conjunctions.
|
84 |
+
while j < len(tokens) and ('<o>' in tokens[j] or '<cc>' in tokens[j]):
|
85 |
+
obj_match = re.search(r'<o>(.*?)</o>', tokens[j])
|
86 |
+
if obj_match:
|
87 |
+
object_list.append(obj_match.group(1))
|
88 |
+
j += 1
|
89 |
+
# Create edges from the predicate to each object found.
|
90 |
+
for obj in object_list:
|
91 |
+
G.add_node(obj, color='lightcoral', size=node_size)
|
92 |
+
G.add_edge(current_subject, obj, label=predicate)
|
93 |
+
i = j - 1 # Skip to the index past the last processed <o> or <cc>
|
94 |
+
print('Case for a single predicate followed directly by an object')
|
95 |
+
print('predicate:', predicate)
|
96 |
+
print('object_list:', object_list)
|
97 |
+
|
98 |
+
print('to process:', tokens[i+1:])
|
99 |
+
|
100 |
+
# Case for a predicate followed by another predicate and then an object,
|
101 |
+
# introducing an intermediate variable node for complex relationships.
|
102 |
+
elif i+2 < len(tokens) and '<p>' in tokens[i+1] and '<o>' in tokens[i+2]:
|
103 |
+
predicate2_match = re.search(r'<p>(.*?)</p>', tokens[i+1])
|
104 |
+
object_match = re.search(r'<o>(.*?)</o>', tokens[i+2])
|
105 |
+
if predicate2_match and object_match:
|
106 |
+
predicate2 = predicate2_match.group(1)
|
107 |
+
object = object_match.group(1)
|
108 |
+
new_variable = f"?o{i//3}" # Name new variables based on their position.
|
109 |
+
G.add_node(new_variable, color='orange', size=node_size)
|
110 |
+
G.add_edge(current_subject, new_variable, label=predicate)
|
111 |
+
G.add_edge(new_variable, object, label=predicate2)
|
112 |
+
i += 2
|
113 |
+
print('Case for a predicate followed by another predicate and then an object')
|
114 |
+
print('predicate:', predicate)
|
115 |
+
print('predicate2:', predicate2)
|
116 |
+
print('object:', object)
|
117 |
+
print('to process:', tokens[i+1:])
|
118 |
+
i += 1
|
119 |
+
|
120 |
+
# Set up and configure the network visualization.
|
121 |
+
net = Network(height="600px", width="100%", bgcolor="#000000", font_color="white")
|
122 |
+
net.from_nx(G)
|
123 |
+
net.show_buttons(filter_=['physics'])
|
124 |
+
|
125 |
+
# Save and display the interactive graph within the Streamlit app.
|
126 |
+
path = "/tmp"
|
127 |
+
net.save_graph(f"{path}/graph.html")
|
128 |
+
HtmlFile = open(f"{path}/graph.html", 'r', encoding='utf-8')
|
129 |
+
source_code = HtmlFile.read()
|
130 |
+
components.html(source_code, height=450, width=1000)
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
# Define an API endpoint within Streamlit
|
138 |
+
def api():
|
139 |
+
query_params = st.query_params
|
140 |
+
if 'text' in query_params:
|
141 |
+
print(query_params['text'])
|
142 |
+
user_input = query_params['text']
|
143 |
+
tagged_question = tag_question(user_input)
|
144 |
+
st.json({"tagged_question": tagged_question, "question": user_input})
|
145 |
+
else:
|
146 |
+
st.json({"error": "Please provide a 'text' query parameter."})
|
147 |
+
|
148 |
+
|
149 |
+
# API mode
|
150 |
+
if 'api' in st.query_params:
|
151 |
+
api()
|
152 |
+
else:
|
153 |
+
# Streamlit app
|
154 |
+
st.set_page_config(layout="wide")
|
155 |
+
st.markdown(
|
156 |
+
"""
|
157 |
+
<style>
|
158 |
+
.reportview-container {
|
159 |
+
background: #fff700;
|
160 |
+
color: white;
|
161 |
+
width: 90%;
|
162 |
+
margin: auto;
|
163 |
+
}
|
164 |
+
.sidebar .sidebar-content {
|
165 |
+
background: #fff700;
|
166 |
+
color: white;
|
167 |
+
}
|
168 |
+
|
169 |
+
body{
|
170 |
+
background: #fff700;
|
171 |
+
color: white;
|
172 |
+
}
|
173 |
+
</style>
|
174 |
+
<script>
|
175 |
+
document.addEventListener("DOMContentLoaded", function() {
|
176 |
+
var inputField = document.querySelector('input[type="text"]');
|
177 |
+
inputField.addEventListener("keypress", function(event) {
|
178 |
+
if (event.key === "Enter" || event.key === " ") {
|
179 |
+
event.preventDefault();
|
180 |
+
document.querySelector('button[type="submit"]').click();
|
181 |
+
}
|
182 |
+
});
|
183 |
+
});
|
184 |
+
</script>
|
185 |
+
""",
|
186 |
+
unsafe_allow_html=True
|
187 |
+
)
|
188 |
+
|
189 |
+
st.title("Star: NLQU")
|
190 |
+
# Create a text input box with a callback function
|
191 |
+
def update_input():
|
192 |
+
st.session_state.tagged_question = tag_question(st.session_state.user_input)
|
193 |
+
st.session_state.highlighted_question = highlight_tags(st.session_state.tagged_question)
|
194 |
+
|
195 |
+
if 'user_input' not in st.session_state:
|
196 |
+
st.session_state.user_input = ''
|
197 |
+
if 'tagged_question' not in st.session_state:
|
198 |
+
st.session_state.tagged_question = ''
|
199 |
+
if 'highlighted_question' not in st.session_state:
|
200 |
+
st.session_state.highlighted_question = ''
|
201 |
+
|
202 |
+
st.text_input("Ask a question:", key="user_input", on_change=update_input)
|
203 |
+
|
204 |
+
# Display the highlighted question
|
205 |
+
st.markdown(st.session_state.highlighted_question, unsafe_allow_html=True)
|
206 |
+
|
207 |
+
# Draw the interactive graph if there is a tagged question
|
208 |
+
if st.session_state.tagged_question:
|
209 |
+
draw_interactive_graph(st.session_state.tagged_question)
|
210 |
+
|
211 |
+
# Display the meaning of each color
|
212 |
+
legend_tags = re.findall(r'<(.*?)>.*?</\1>', st.session_state.tagged_question)
|
213 |
+
legend_tags = set(tag.split('>')[0] for tag in legend_tags)
|
214 |
+
legend_styles = {
|
215 |
+
"qt": "background-color: yellow; padding: 1mm; border-radius: 8px;",
|
216 |
+
"t": "background-color: lightgreen; padding: 1mm; border-radius: 8px;",
|
217 |
+
"p": "background-color: lightblue; padding: 1mm; border-radius: 8px;",
|
218 |
+
"o": "background-color: lightcoral; padding: 1mm; border-radius: 8px;",
|
219 |
+
"s": "background-color: lightgrey; padding: 1mm; border-radius: 8px;",
|
220 |
+
"cc": "background-color: lightpink; padding: 1mm; border-radius: 8px;",
|
221 |
+
"off": "background-color: lightcyan; padding: 1mm; border-radius: 8px;",
|
222 |
+
"ref": "background-color: lightgoldenrodyellow; padding: 1mm; border-radius: 8px;",
|
223 |
+
"op": "background-color: burlywood; padding: 1mm; border-radius: 8px;"
|
224 |
+
}
|
225 |
+
|
226 |
+
legend_labels = {
|
227 |
+
"qt": "Question Type",
|
228 |
+
"t": "Entity Type",
|
229 |
+
"p": "Predicate",
|
230 |
+
"o": "Object",
|
231 |
+
"s": "Subject",
|
232 |
+
"cc": "Coordinating Conjunction",
|
233 |
+
"off": "Offset",
|
234 |
+
"ref": "Reference",
|
235 |
+
"op": "Operator"
|
236 |
+
}
|
237 |
+
|
238 |
+
legend_html = "<div style='display: flex; flex-wrap: wrap;'>"
|
239 |
+
for tag in legend_tags:
|
240 |
+
if tag in legend_styles:
|
241 |
+
legend_html += f"<div style='margin-right: 10px;'><span style='{legend_styles[tag]}'>{legend_labels[tag]}</span></div>"
|
242 |
+
legend_html += "</div>"
|
243 |
+
|
244 |
+
st.markdown("### Legend:")
|
245 |
+
st.markdown(legend_html, unsafe_allow_html=True)
|
streamlit_app/clean_tagged_question.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
from fuzzywuzzy import fuzz
|
3 |
+
|
4 |
+
# Example tagged output and original question
|
5 |
+
tagged_output = "<o> <qt>What</qt> ddsfv <p>is the second largest</p> <t>country</t> <p> </p> to <p>see usa</p>"
|
6 |
+
original_question = "What is the second largest country in Egypt?"
|
7 |
+
|
8 |
+
# Step 1: Remove empty tags or tags with only whitespace
|
9 |
+
def _remove_empty_tags(text):
|
10 |
+
return re.sub(r'<(\w+)>[\s]*<\/\1>', '', text)
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
# Step 2: Fuzzy match and retain only relevant tagged parts
|
15 |
+
def _fuzzy_match_tags(cleaned_output, original_question):
|
16 |
+
tags = re.findall(r'<(\w+)>(.*?)<\/\1>', cleaned_output)
|
17 |
+
matched_tags = []
|
18 |
+
|
19 |
+
for tag, content in tags:
|
20 |
+
# Calculate the fuzzy match ratio between the content and the original question
|
21 |
+
ratio = fuzz.partial_ratio(content.strip(), original_question)
|
22 |
+
|
23 |
+
# You can adjust the threshold for what you consider a "match" (e.g., 80 or higher)
|
24 |
+
if ratio > 80:
|
25 |
+
matched_tags.append(f"<{tag}>{content.strip()}</{tag}>")
|
26 |
+
|
27 |
+
return " ".join(matched_tags)
|
28 |
+
|
29 |
+
def _trim_extra_words(tagged_output, original_question):
|
30 |
+
words = original_question.split()
|
31 |
+
last_word = words[-1] if words else ''
|
32 |
+
|
33 |
+
if not last_word:
|
34 |
+
return tagged_output # No trimming needed if no recognizable last word
|
35 |
+
|
36 |
+
# Pattern to find the last word followed by any potential HTML tag
|
37 |
+
pattern = re.compile(r'({}\b.*?</\w+>)'.format(re.escape(last_word)))
|
38 |
+
matches = pattern.findall(tagged_output)
|
39 |
+
|
40 |
+
if matches:
|
41 |
+
# Find the last match of the pattern
|
42 |
+
last_match = matches[-1]
|
43 |
+
# Find the index of this last match in the tagged output
|
44 |
+
last_index = tagged_output.rfind(last_match)
|
45 |
+
if last_index != -1:
|
46 |
+
# Cut off after the closing tag of the last match
|
47 |
+
return tagged_output[:last_index + len(last_match)]
|
48 |
+
return tagged_output # Return the original if no suitable pattern is found
|
49 |
+
|
50 |
+
def clean_tagged_output(tagged_output, original_question):
|
51 |
+
cleaned_output = _remove_empty_tags(tagged_output)
|
52 |
+
filtered_output = _fuzzy_match_tags(cleaned_output, original_question)
|
53 |
+
filtered_output = _trim_extra_words(filtered_output, original_question)
|
54 |
+
print('filtered_output:', filtered_output)
|
55 |
+
return filtered_output
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
cleaned_output = _remove_empty_tags(tagged_output)
|
59 |
+
print('cleaned_output:', cleaned_output)
|
60 |
+
|
61 |
+
filtered_output = _fuzzy_match_tags(cleaned_output, original_question)
|
62 |
+
|
63 |
+
print(filtered_output)
|
streamlit_app/command.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import os
|
3 |
+
import re
|
4 |
+
import shlex # For safely handling command line arguments
|
5 |
+
|
6 |
+
|
7 |
+
def _create_config_file(question):
|
8 |
+
# Path to the template and output config file
|
9 |
+
template_path = "/home/aorogat/custom_generation_config_bigModel.yaml"
|
10 |
+
output_path = "/tmp/dynamic_generation.yaml"
|
11 |
+
|
12 |
+
# Load the template from the file
|
13 |
+
with open(template_path, 'r') as file:
|
14 |
+
config_template = file.read()
|
15 |
+
|
16 |
+
# Replace the placeholder in the template with the actual question
|
17 |
+
updated_prompt = config_template.replace("Input: Which films directed by a dirctor died in 2014 and starring both Julia Roberts and Richard Gere?", f"Input: {question}")
|
18 |
+
maxLen = int(1.3*len(question))
|
19 |
+
print(f"maxLen: {maxLen}")
|
20 |
+
updated_prompt = updated_prompt.replace("max_new_tokens: 100", f"max_new_tokens: {maxLen}")
|
21 |
+
|
22 |
+
# Write the updated configuration to a new file
|
23 |
+
with open(output_path, 'w') as file:
|
24 |
+
file.write(updated_prompt)
|
25 |
+
|
26 |
+
print(f"Configuration file created at: {output_path}")
|
27 |
+
|
28 |
+
def get_tagged_question(question):
|
29 |
+
# Define the path to the virtual environment's activation script
|
30 |
+
activate_env = "/home/aorogat/myenv/bin/activate"
|
31 |
+
|
32 |
+
# Create configuration file with the question
|
33 |
+
_create_config_file(question)
|
34 |
+
|
35 |
+
print('get_tagged_question')
|
36 |
+
|
37 |
+
# Command to run within the virtual environment
|
38 |
+
command = f"tune run generate --config /tmp/dynamic_generation.yaml"
|
39 |
+
|
40 |
+
# Full command to activate the environment and run your command
|
41 |
+
full_command = f"source {activate_env} && {command}"
|
42 |
+
|
43 |
+
# Run the full command in a shell
|
44 |
+
try:
|
45 |
+
result = subprocess.run(full_command, shell=True, check=True, text=True, capture_output=True, executable="/bin/bash")
|
46 |
+
print("Command output:", result.stdout)
|
47 |
+
print("Command error output:", result.stderr)
|
48 |
+
|
49 |
+
output = result.stdout + result.stderr
|
50 |
+
# Extract the input and response using modified regular expressions
|
51 |
+
input_match = re.search(r'Input: (.*?)(?=Response:)', output, re.S) # re.S allows for multi-line matching
|
52 |
+
response_match = re.search(r'Response: (.*)', output)
|
53 |
+
|
54 |
+
response_match = response_match.group(1).strip()
|
55 |
+
|
56 |
+
if input_match and response_match:
|
57 |
+
print("Input Question: ", question)
|
58 |
+
print("Extracted Response: ", response_match)
|
59 |
+
else:
|
60 |
+
print("Input or Response not found in the output.")
|
61 |
+
|
62 |
+
except subprocess.CalledProcessError as e:
|
63 |
+
print("An error occurred:", e.stderr)
|
64 |
+
return response_match
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
# Call the function with a sample question
|
68 |
+
get_tagged_question("Who is the president of largest country in Africa?")
|
streamlit_app/flask_api.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, jsonify, request
|
2 |
+
from command import get_tagged_question
|
3 |
+
from clean_tagged_question import clean_tagged_output
|
4 |
+
|
5 |
+
# Define a function to tag the question
|
6 |
+
def tag_question(text):
|
7 |
+
tagged_question = get_tagged_question(text)
|
8 |
+
|
9 |
+
tagged_question = clean_tagged_output(tagged_question, text)
|
10 |
+
|
11 |
+
return tagged_question
|
12 |
+
|
13 |
+
ap = Flask(__name__)
|
14 |
+
|
15 |
+
@ap.route('/api', methods=['GET'])
|
16 |
+
def api():
|
17 |
+
user_input = request.args.get('text')
|
18 |
+
if user_input:
|
19 |
+
tagged_question = tag_question(user_input)
|
20 |
+
return jsonify({"tagged_question": tagged_question, "question": user_input})
|
21 |
+
else:
|
22 |
+
return jsonify({"error": "Please provide a 'text' query parameter."})
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
ap.run(debug=True)
|
streamlit_app/lib/bindings/utils.js
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function neighbourhoodHighlight(params) {
|
2 |
+
// console.log("in nieghbourhoodhighlight");
|
3 |
+
allNodes = nodes.get({ returnType: "Object" });
|
4 |
+
// originalNodes = JSON.parse(JSON.stringify(allNodes));
|
5 |
+
// if something is selected:
|
6 |
+
if (params.nodes.length > 0) {
|
7 |
+
highlightActive = true;
|
8 |
+
var i, j;
|
9 |
+
var selectedNode = params.nodes[0];
|
10 |
+
var degrees = 2;
|
11 |
+
|
12 |
+
// mark all nodes as hard to read.
|
13 |
+
for (let nodeId in allNodes) {
|
14 |
+
// nodeColors[nodeId] = allNodes[nodeId].color;
|
15 |
+
allNodes[nodeId].color = "rgba(200,200,200,0.5)";
|
16 |
+
if (allNodes[nodeId].hiddenLabel === undefined) {
|
17 |
+
allNodes[nodeId].hiddenLabel = allNodes[nodeId].label;
|
18 |
+
allNodes[nodeId].label = undefined;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
var connectedNodes = network.getConnectedNodes(selectedNode);
|
22 |
+
var allConnectedNodes = [];
|
23 |
+
|
24 |
+
// get the second degree nodes
|
25 |
+
for (i = 1; i < degrees; i++) {
|
26 |
+
for (j = 0; j < connectedNodes.length; j++) {
|
27 |
+
allConnectedNodes = allConnectedNodes.concat(
|
28 |
+
network.getConnectedNodes(connectedNodes[j])
|
29 |
+
);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
// all second degree nodes get a different color and their label back
|
34 |
+
for (i = 0; i < allConnectedNodes.length; i++) {
|
35 |
+
// allNodes[allConnectedNodes[i]].color = "pink";
|
36 |
+
allNodes[allConnectedNodes[i]].color = "rgba(150,150,150,0.75)";
|
37 |
+
if (allNodes[allConnectedNodes[i]].hiddenLabel !== undefined) {
|
38 |
+
allNodes[allConnectedNodes[i]].label =
|
39 |
+
allNodes[allConnectedNodes[i]].hiddenLabel;
|
40 |
+
allNodes[allConnectedNodes[i]].hiddenLabel = undefined;
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
// all first degree nodes get their own color and their label back
|
45 |
+
for (i = 0; i < connectedNodes.length; i++) {
|
46 |
+
// allNodes[connectedNodes[i]].color = undefined;
|
47 |
+
allNodes[connectedNodes[i]].color = nodeColors[connectedNodes[i]];
|
48 |
+
if (allNodes[connectedNodes[i]].hiddenLabel !== undefined) {
|
49 |
+
allNodes[connectedNodes[i]].label =
|
50 |
+
allNodes[connectedNodes[i]].hiddenLabel;
|
51 |
+
allNodes[connectedNodes[i]].hiddenLabel = undefined;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
// the main node gets its own color and its label back.
|
56 |
+
// allNodes[selectedNode].color = undefined;
|
57 |
+
allNodes[selectedNode].color = nodeColors[selectedNode];
|
58 |
+
if (allNodes[selectedNode].hiddenLabel !== undefined) {
|
59 |
+
allNodes[selectedNode].label = allNodes[selectedNode].hiddenLabel;
|
60 |
+
allNodes[selectedNode].hiddenLabel = undefined;
|
61 |
+
}
|
62 |
+
} else if (highlightActive === true) {
|
63 |
+
// console.log("highlightActive was true");
|
64 |
+
// reset all nodes
|
65 |
+
for (let nodeId in allNodes) {
|
66 |
+
// allNodes[nodeId].color = "purple";
|
67 |
+
allNodes[nodeId].color = nodeColors[nodeId];
|
68 |
+
// delete allNodes[nodeId].color;
|
69 |
+
if (allNodes[nodeId].hiddenLabel !== undefined) {
|
70 |
+
allNodes[nodeId].label = allNodes[nodeId].hiddenLabel;
|
71 |
+
allNodes[nodeId].hiddenLabel = undefined;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
highlightActive = false;
|
75 |
+
}
|
76 |
+
|
77 |
+
// transform the object into an array
|
78 |
+
var updateArray = [];
|
79 |
+
if (params.nodes.length > 0) {
|
80 |
+
for (let nodeId in allNodes) {
|
81 |
+
if (allNodes.hasOwnProperty(nodeId)) {
|
82 |
+
// console.log(allNodes[nodeId]);
|
83 |
+
updateArray.push(allNodes[nodeId]);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
nodes.update(updateArray);
|
87 |
+
} else {
|
88 |
+
// console.log("Nothing was selected");
|
89 |
+
for (let nodeId in allNodes) {
|
90 |
+
if (allNodes.hasOwnProperty(nodeId)) {
|
91 |
+
// console.log(allNodes[nodeId]);
|
92 |
+
// allNodes[nodeId].color = {};
|
93 |
+
updateArray.push(allNodes[nodeId]);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
nodes.update(updateArray);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
function filterHighlight(params) {
|
101 |
+
allNodes = nodes.get({ returnType: "Object" });
|
102 |
+
// if something is selected:
|
103 |
+
if (params.nodes.length > 0) {
|
104 |
+
filterActive = true;
|
105 |
+
let selectedNodes = params.nodes;
|
106 |
+
|
107 |
+
// hiding all nodes and saving the label
|
108 |
+
for (let nodeId in allNodes) {
|
109 |
+
allNodes[nodeId].hidden = true;
|
110 |
+
if (allNodes[nodeId].savedLabel === undefined) {
|
111 |
+
allNodes[nodeId].savedLabel = allNodes[nodeId].label;
|
112 |
+
allNodes[nodeId].label = undefined;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
for (let i=0; i < selectedNodes.length; i++) {
|
117 |
+
allNodes[selectedNodes[i]].hidden = false;
|
118 |
+
if (allNodes[selectedNodes[i]].savedLabel !== undefined) {
|
119 |
+
allNodes[selectedNodes[i]].label = allNodes[selectedNodes[i]].savedLabel;
|
120 |
+
allNodes[selectedNodes[i]].savedLabel = undefined;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
} else if (filterActive === true) {
|
125 |
+
// reset all nodes
|
126 |
+
for (let nodeId in allNodes) {
|
127 |
+
allNodes[nodeId].hidden = false;
|
128 |
+
if (allNodes[nodeId].savedLabel !== undefined) {
|
129 |
+
allNodes[nodeId].label = allNodes[nodeId].savedLabel;
|
130 |
+
allNodes[nodeId].savedLabel = undefined;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
filterActive = false;
|
134 |
+
}
|
135 |
+
|
136 |
+
// transform the object into an array
|
137 |
+
var updateArray = [];
|
138 |
+
if (params.nodes.length > 0) {
|
139 |
+
for (let nodeId in allNodes) {
|
140 |
+
if (allNodes.hasOwnProperty(nodeId)) {
|
141 |
+
updateArray.push(allNodes[nodeId]);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
nodes.update(updateArray);
|
145 |
+
} else {
|
146 |
+
for (let nodeId in allNodes) {
|
147 |
+
if (allNodes.hasOwnProperty(nodeId)) {
|
148 |
+
updateArray.push(allNodes[nodeId]);
|
149 |
+
}
|
150 |
+
}
|
151 |
+
nodes.update(updateArray);
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
function selectNode(nodes) {
|
156 |
+
network.selectNodes(nodes);
|
157 |
+
neighbourhoodHighlight({ nodes: nodes });
|
158 |
+
return nodes;
|
159 |
+
}
|
160 |
+
|
161 |
+
function selectNodes(nodes) {
|
162 |
+
network.selectNodes(nodes);
|
163 |
+
filterHighlight({nodes: nodes});
|
164 |
+
return nodes;
|
165 |
+
}
|
166 |
+
|
167 |
+
function highlightFilter(filter) {
|
168 |
+
let selectedNodes = []
|
169 |
+
let selectedProp = filter['property']
|
170 |
+
if (filter['item'] === 'node') {
|
171 |
+
let allNodes = nodes.get({ returnType: "Object" });
|
172 |
+
for (let nodeId in allNodes) {
|
173 |
+
if (allNodes[nodeId][selectedProp] && filter['value'].includes((allNodes[nodeId][selectedProp]).toString())) {
|
174 |
+
selectedNodes.push(nodeId)
|
175 |
+
}
|
176 |
+
}
|
177 |
+
}
|
178 |
+
else if (filter['item'] === 'edge'){
|
179 |
+
let allEdges = edges.get({returnType: 'object'});
|
180 |
+
// check if the selected property exists for selected edge and select the nodes connected to the edge
|
181 |
+
for (let edge in allEdges) {
|
182 |
+
if (allEdges[edge][selectedProp] && filter['value'].includes((allEdges[edge][selectedProp]).toString())) {
|
183 |
+
selectedNodes.push(allEdges[edge]['from'])
|
184 |
+
selectedNodes.push(allEdges[edge]['to'])
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
selectNodes(selectedNodes)
|
189 |
+
}
|
streamlit_app/lib/tom-select/tom-select.complete.min.js
ADDED
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Tom Select v2.0.0-rc.4
|
3 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
*/
|
5 |
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TomSelect=t()}(this,(function(){"use strict"
|
6 |
+
function e(e,t){e.split(/\s+/).forEach((e=>{t(e)}))}class t{constructor(){this._events={}}on(t,i){e(t,(e=>{this._events[e]=this._events[e]||[],this._events[e].push(i)}))}off(t,i){var s=arguments.length
|
7 |
+
0!==s?e(t,(e=>{if(1===s)return delete this._events[e]
|
8 |
+
e in this._events!=!1&&this._events[e].splice(this._events[e].indexOf(i),1)})):this._events={}}trigger(t,...i){var s=this
|
9 |
+
e(t,(e=>{if(e in s._events!=!1)for(let t of s._events[e])t.apply(s,i)}))}}var i
|
10 |
+
const s="[̀-ͯ·ʾ]",n=new RegExp(s,"g")
|
11 |
+
var o
|
12 |
+
const r={"æ":"ae","ⱥ":"a","ø":"o"},l=new RegExp(Object.keys(r).join("|"),"g"),a=[[67,67],[160,160],[192,438],[452,652],[961,961],[1019,1019],[1083,1083],[1281,1289],[1984,1984],[5095,5095],[7429,7441],[7545,7549],[7680,7935],[8580,8580],[9398,9449],[11360,11391],[42792,42793],[42802,42851],[42873,42897],[42912,42922],[64256,64260],[65313,65338],[65345,65370]],c=e=>e.normalize("NFKD").replace(n,"").toLowerCase().replace(l,(function(e){return r[e]})),d=(e,t="|")=>{if(1==e.length)return e[0]
|
13 |
+
var i=1
|
14 |
+
return e.forEach((e=>{i=Math.max(i,e.length)})),1==i?"["+e.join("")+"]":"(?:"+e.join(t)+")"},p=e=>{if(1===e.length)return[[e]]
|
15 |
+
var t=[]
|
16 |
+
return p(e.substring(1)).forEach((function(i){var s=i.slice(0)
|
17 |
+
s[0]=e.charAt(0)+s[0],t.push(s),(s=i.slice(0)).unshift(e.charAt(0)),t.push(s)})),t},u=e=>{void 0===o&&(o=(()=>{var e={}
|
18 |
+
a.forEach((t=>{for(let s=t[0];s<=t[1];s++){let t=String.fromCharCode(s),n=c(t)
|
19 |
+
if(n!=t.toLowerCase()){n in e||(e[n]=[n])
|
20 |
+
var i=new RegExp(d(e[n]),"iu")
|
21 |
+
t.match(i)||e[n].push(t)}}}))
|
22 |
+
var t=Object.keys(e)
|
23 |
+
t=t.sort(((e,t)=>t.length-e.length)),i=new RegExp("("+d(t)+"[̀-ͯ·ʾ]*)","g")
|
24 |
+
var s={}
|
25 |
+
return t.sort(((e,t)=>e.length-t.length)).forEach((t=>{var i=p(t).map((t=>(t=t.map((t=>e.hasOwnProperty(t)?d(e[t]):t)),d(t,""))))
|
26 |
+
s[t]=d(i)})),s})())
|
27 |
+
return e.normalize("NFKD").toLowerCase().split(i).map((e=>{if(""==e)return""
|
28 |
+
const t=c(e)
|
29 |
+
if(o.hasOwnProperty(t))return o[t]
|
30 |
+
const i=e.normalize("NFC")
|
31 |
+
return i!=e?d([e,i]):e})).join("")},h=(e,t)=>{if(e)return e[t]},g=(e,t)=>{if(e){for(var i,s=t.split(".");(i=s.shift())&&(e=e[i]););return e}},f=(e,t,i)=>{var s,n
|
32 |
+
return e?-1===(n=(e+="").search(t.regex))?0:(s=t.string.length/e.length,0===n&&(s+=.5),s*i):0},v=e=>(e+"").replace(/([\$\(-\+\.\?\[-\^\{-\}])/g,"\\$1"),m=(e,t)=>{var i=e[t]
|
33 |
+
if("function"==typeof i)return i
|
34 |
+
i&&!Array.isArray(i)&&(e[t]=[i])},y=(e,t)=>{if(Array.isArray(e))e.forEach(t)
|
35 |
+
else for(var i in e)e.hasOwnProperty(i)&&t(e[i],i)},O=(e,t)=>"number"==typeof e&&"number"==typeof t?e>t?1:e<t?-1:0:(e=c(e+"").toLowerCase())>(t=c(t+"").toLowerCase())?1:t>e?-1:0
|
36 |
+
class b{constructor(e,t){this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,i){if(!e||!e.length)return[]
|
37 |
+
const s=[],n=e.split(/\s+/)
|
38 |
+
var o
|
39 |
+
return i&&(o=new RegExp("^("+Object.keys(i).map(v).join("|")+"):(.*)$")),n.forEach((e=>{let i,n=null,r=null
|
40 |
+
o&&(i=e.match(o))&&(n=i[1],e=i[2]),e.length>0&&(r=v(e),this.settings.diacritics&&(r=u(r)),t&&(r="\\b"+r)),s.push({string:e,regex:r?new RegExp(r,"iu"):null,field:n})})),s}getScoreFunction(e,t){var i=this.prepareSearch(e,t)
|
41 |
+
return this._getScoreFunction(i)}_getScoreFunction(e){const t=e.tokens,i=t.length
|
42 |
+
if(!i)return function(){return 0}
|
43 |
+
const s=e.options.fields,n=e.weights,o=s.length,r=e.getAttrFn
|
44 |
+
if(!o)return function(){return 1}
|
45 |
+
const l=1===o?function(e,t){const i=s[0].field
|
46 |
+
return f(r(t,i),e,n[i])}:function(e,t){var i=0
|
47 |
+
if(e.field){const s=r(t,e.field)
|
48 |
+
!e.regex&&s?i+=1/o:i+=f(s,e,1)}else y(n,((s,n)=>{i+=f(r(t,n),e,s)}))
|
49 |
+
return i/o}
|
50 |
+
return 1===i?function(e){return l(t[0],e)}:"and"===e.options.conjunction?function(e){for(var s,n=0,o=0;n<i;n++){if((s=l(t[n],e))<=0)return 0
|
51 |
+
o+=s}return o/i}:function(e){var s=0
|
52 |
+
return y(t,(t=>{s+=l(t,e)})),s/i}}getSortFunction(e,t){var i=this.prepareSearch(e,t)
|
53 |
+
return this._getSortFunction(i)}_getSortFunction(e){var t,i,s
|
54 |
+
const n=this,o=e.options,r=!e.query&&o.sort_empty?o.sort_empty:o.sort,l=[],a=[]
|
55 |
+
if("function"==typeof r)return r.bind(this)
|
56 |
+
const c=function(t,i){return"$score"===t?i.score:e.getAttrFn(n.items[i.id],t)}
|
57 |
+
if(r)for(t=0,i=r.length;t<i;t++)(e.query||"$score"!==r[t].field)&&l.push(r[t])
|
58 |
+
if(e.query){for(s=!0,t=0,i=l.length;t<i;t++)if("$score"===l[t].field){s=!1
|
59 |
+
break}s&&l.unshift({field:"$score",direction:"desc"})}else for(t=0,i=l.length;t<i;t++)if("$score"===l[t].field){l.splice(t,1)
|
60 |
+
break}for(t=0,i=l.length;t<i;t++)a.push("desc"===l[t].direction?-1:1)
|
61 |
+
const d=l.length
|
62 |
+
if(d){if(1===d){const e=l[0].field,t=a[0]
|
63 |
+
return function(i,s){return t*O(c(e,i),c(e,s))}}return function(e,t){var i,s,n
|
64 |
+
for(i=0;i<d;i++)if(n=l[i].field,s=a[i]*O(c(n,e),c(n,t)))return s
|
65 |
+
return 0}}return null}prepareSearch(e,t){const i={}
|
66 |
+
var s=Object.assign({},t)
|
67 |
+
if(m(s,"sort"),m(s,"sort_empty"),s.fields){m(s,"fields")
|
68 |
+
const e=[]
|
69 |
+
s.fields.forEach((t=>{"string"==typeof t&&(t={field:t,weight:1}),e.push(t),i[t.field]="weight"in t?t.weight:1})),s.fields=e}return{options:s,query:e.toLowerCase().trim(),tokens:this.tokenize(e,s.respect_word_boundaries,i),total:0,items:[],weights:i,getAttrFn:s.nesting?g:h}}search(e,t){var i,s,n=this
|
70 |
+
s=this.prepareSearch(e,t),t=s.options,e=s.query
|
71 |
+
const o=t.score||n._getScoreFunction(s)
|
72 |
+
e.length?y(n.items,((e,n)=>{i=o(e),(!1===t.filter||i>0)&&s.items.push({score:i,id:n})})):y(n.items,((e,t)=>{s.items.push({score:1,id:t})}))
|
73 |
+
const r=n._getSortFunction(s)
|
74 |
+
return r&&s.items.sort(r),s.total=s.items.length,"number"==typeof t.limit&&(s.items=s.items.slice(0,t.limit)),s}}const w=e=>{if(e.jquery)return e[0]
|
75 |
+
if(e instanceof HTMLElement)return e
|
76 |
+
if(e.indexOf("<")>-1){let t=document.createElement("div")
|
77 |
+
return t.innerHTML=e.trim(),t.firstChild}return document.querySelector(e)},_=(e,t)=>{var i=document.createEvent("HTMLEvents")
|
78 |
+
i.initEvent(t,!0,!1),e.dispatchEvent(i)},I=(e,t)=>{Object.assign(e.style,t)},C=(e,...t)=>{var i=A(t);(e=x(e)).map((e=>{i.map((t=>{e.classList.add(t)}))}))},S=(e,...t)=>{var i=A(t);(e=x(e)).map((e=>{i.map((t=>{e.classList.remove(t)}))}))},A=e=>{var t=[]
|
79 |
+
return y(e,(e=>{"string"==typeof e&&(e=e.trim().split(/[\11\12\14\15\40]/)),Array.isArray(e)&&(t=t.concat(e))})),t.filter(Boolean)},x=e=>(Array.isArray(e)||(e=[e]),e),k=(e,t,i)=>{if(!i||i.contains(e))for(;e&&e.matches;){if(e.matches(t))return e
|
80 |
+
e=e.parentNode}},F=(e,t=0)=>t>0?e[e.length-1]:e[0],L=(e,t)=>{if(!e)return-1
|
81 |
+
t=t||e.nodeName
|
82 |
+
for(var i=0;e=e.previousElementSibling;)e.matches(t)&&i++
|
83 |
+
return i},P=(e,t)=>{y(t,((t,i)=>{null==t?e.removeAttribute(i):e.setAttribute(i,""+t)}))},E=(e,t)=>{e.parentNode&&e.parentNode.replaceChild(t,e)},T=(e,t)=>{if(null===t)return
|
84 |
+
if("string"==typeof t){if(!t.length)return
|
85 |
+
t=new RegExp(t,"i")}const i=e=>3===e.nodeType?(e=>{var i=e.data.match(t)
|
86 |
+
if(i&&e.data.length>0){var s=document.createElement("span")
|
87 |
+
s.className="highlight"
|
88 |
+
var n=e.splitText(i.index)
|
89 |
+
n.splitText(i[0].length)
|
90 |
+
var o=n.cloneNode(!0)
|
91 |
+
return s.appendChild(o),E(n,s),1}return 0})(e):((e=>{if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&("highlight"!==e.className||"SPAN"!==e.tagName))for(var t=0;t<e.childNodes.length;++t)t+=i(e.childNodes[t])})(e),0)
|
92 |
+
i(e)},V="undefined"!=typeof navigator&&/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey"
|
93 |
+
var j={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,copyClassesToDropdown:!1,placeholder:null,hidePlaceholder:null,shouldLoad:function(e){return e.length>0},render:{}}
|
94 |
+
const q=e=>null==e?null:D(e),D=e=>"boolean"==typeof e?e?"1":"0":e+"",N=e=>(e+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),z=(e,t)=>{var i
|
95 |
+
return function(s,n){var o=this
|
96 |
+
i&&(o.loading=Math.max(o.loading-1,0),clearTimeout(i)),i=setTimeout((function(){i=null,o.loadedSearches[s]=!0,e.call(o,s,n)}),t)}},R=(e,t,i)=>{var s,n=e.trigger,o={}
|
97 |
+
for(s in e.trigger=function(){var i=arguments[0]
|
98 |
+
if(-1===t.indexOf(i))return n.apply(e,arguments)
|
99 |
+
o[i]=arguments},i.apply(e,[]),e.trigger=n,o)n.apply(e,o[s])},H=(e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())},B=(e,t,i,s)=>{e.addEventListener(t,i,s)},K=(e,t)=>!!t&&(!!t[e]&&1===(t.altKey?1:0)+(t.ctrlKey?1:0)+(t.shiftKey?1:0)+(t.metaKey?1:0)),M=(e,t)=>{const i=e.getAttribute("id")
|
100 |
+
return i||(e.setAttribute("id",t),t)},Q=e=>e.replace(/[\\"']/g,"\\$&"),G=(e,t)=>{t&&e.append(t)}
|
101 |
+
function U(e,t){var i=Object.assign({},j,t),s=i.dataAttr,n=i.labelField,o=i.valueField,r=i.disabledField,l=i.optgroupField,a=i.optgroupLabelField,c=i.optgroupValueField,d=e.tagName.toLowerCase(),p=e.getAttribute("placeholder")||e.getAttribute("data-placeholder")
|
102 |
+
if(!p&&!i.allowEmptyOption){let t=e.querySelector('option[value=""]')
|
103 |
+
t&&(p=t.textContent)}var u,h,g,f,v,m,O={placeholder:p,options:[],optgroups:[],items:[],maxItems:null}
|
104 |
+
return"select"===d?(h=O.options,g={},f=1,v=e=>{var t=Object.assign({},e.dataset),i=s&&t[s]
|
105 |
+
return"string"==typeof i&&i.length&&(t=Object.assign(t,JSON.parse(i))),t},m=(e,t)=>{var s=q(e.value)
|
106 |
+
if(null!=s&&(s||i.allowEmptyOption)){if(g.hasOwnProperty(s)){if(t){var a=g[s][l]
|
107 |
+
a?Array.isArray(a)?a.push(t):g[s][l]=[a,t]:g[s][l]=t}}else{var c=v(e)
|
108 |
+
c[n]=c[n]||e.textContent,c[o]=c[o]||s,c[r]=c[r]||e.disabled,c[l]=c[l]||t,c.$option=e,g[s]=c,h.push(c)}e.selected&&O.items.push(s)}},O.maxItems=e.hasAttribute("multiple")?null:1,y(e.children,(e=>{var t,i,s
|
109 |
+
"optgroup"===(u=e.tagName.toLowerCase())?((s=v(t=e))[a]=s[a]||t.getAttribute("label")||"",s[c]=s[c]||f++,s[r]=s[r]||t.disabled,O.optgroups.push(s),i=s[c],y(t.children,(e=>{m(e,i)}))):"option"===u&&m(e)}))):(()=>{const t=e.getAttribute(s)
|
110 |
+
if(t)O.options=JSON.parse(t),y(O.options,(e=>{O.items.push(e[o])}))
|
111 |
+
else{var r=e.value.trim()||""
|
112 |
+
if(!i.allowEmptyOption&&!r.length)return
|
113 |
+
const t=r.split(i.delimiter)
|
114 |
+
y(t,(e=>{const t={}
|
115 |
+
t[n]=e,t[o]=e,O.options.push(t)})),O.items=t}})(),Object.assign({},j,O,t)}var W=0
|
116 |
+
class J extends(function(e){return e.plugins={},class extends e{constructor(...e){super(...e),this.plugins={names:[],settings:{},requested:{},loaded:{}}}static define(t,i){e.plugins[t]={name:t,fn:i}}initializePlugins(e){var t,i
|
117 |
+
const s=this,n=[]
|
118 |
+
if(Array.isArray(e))e.forEach((e=>{"string"==typeof e?n.push(e):(s.plugins.settings[e.name]=e.options,n.push(e.name))}))
|
119 |
+
else if(e)for(t in e)e.hasOwnProperty(t)&&(s.plugins.settings[t]=e[t],n.push(t))
|
120 |
+
for(;i=n.shift();)s.require(i)}loadPlugin(t){var i=this,s=i.plugins,n=e.plugins[t]
|
121 |
+
if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin')
|
122 |
+
s.requested[t]=!0,s.loaded[t]=n.fn.apply(i,[i.plugins.settings[t]||{}]),s.names.push(t)}require(e){var t=this,i=t.plugins
|
123 |
+
if(!t.plugins.loaded.hasOwnProperty(e)){if(i.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")')
|
124 |
+
t.loadPlugin(e)}return i.loaded[e]}}}(t)){constructor(e,t){var i
|
125 |
+
super(),this.order=0,this.isOpen=!1,this.isDisabled=!1,this.isInvalid=!1,this.isValid=!0,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.ignoreFocus=!1,this.hasOptions=!1,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],W++
|
126 |
+
var s=w(e)
|
127 |
+
if(s.tomselect)throw new Error("Tom Select already initialized on this element")
|
128 |
+
s.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(s,null)).getPropertyValue("direction")
|
129 |
+
const n=U(s,t)
|
130 |
+
this.settings=n,this.input=s,this.tabIndex=s.tabIndex||0,this.is_select_tag="select"===s.tagName.toLowerCase(),this.rtl=/rtl/i.test(i),this.inputId=M(s,"tomselect-"+W),this.isRequired=s.required,this.sifter=new b(this.options,{diacritics:n.diacritics}),n.mode=n.mode||(1===n.maxItems?"single":"multi"),"boolean"!=typeof n.hideSelected&&(n.hideSelected="multi"===n.mode),"boolean"!=typeof n.hidePlaceholder&&(n.hidePlaceholder="multi"!==n.mode)
|
131 |
+
var o=n.createFilter
|
132 |
+
"function"!=typeof o&&("string"==typeof o&&(o=new RegExp(o)),o instanceof RegExp?n.createFilter=e=>o.test(e):n.createFilter=()=>!0),this.initializePlugins(n.plugins),this.setupCallbacks(),this.setupTemplates()
|
133 |
+
const r=w("<div>"),l=w("<div>"),a=this._render("dropdown"),c=w('<div role="listbox" tabindex="-1">'),d=this.input.getAttribute("class")||"",p=n.mode
|
134 |
+
var u
|
135 |
+
if(C(r,n.wrapperClass,d,p),C(l,n.controlClass),G(r,l),C(a,n.dropdownClass,p),n.copyClassesToDropdown&&C(a,d),C(c,n.dropdownContentClass),G(a,c),w(n.dropdownParent||r).appendChild(a),n.hasOwnProperty("controlInput"))n.controlInput?(u=w(n.controlInput),this.focus_node=u):(u=w("<input/>"),this.focus_node=l)
|
136 |
+
else{u=w('<input type="text" autocomplete="off" size="1" />')
|
137 |
+
y(["autocorrect","autocapitalize","autocomplete"],(e=>{s.getAttribute(e)&&P(u,{[e]:s.getAttribute(e)})})),u.tabIndex=-1,l.appendChild(u),this.focus_node=u}this.wrapper=r,this.dropdown=a,this.dropdown_content=c,this.control=l,this.control_input=u,this.setup()}setup(){const e=this,t=e.settings,i=e.control_input,s=e.dropdown,n=e.dropdown_content,o=e.wrapper,r=e.control,l=e.input,a=e.focus_node,c={passive:!0},d=e.inputId+"-ts-dropdown"
|
138 |
+
P(n,{id:d}),P(a,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":d})
|
139 |
+
const p=M(a,e.inputId+"-ts-control"),u="label[for='"+(e=>e.replace(/['"\\]/g,"\\$&"))(e.inputId)+"']",h=document.querySelector(u),g=e.focus.bind(e)
|
140 |
+
if(h){B(h,"click",g),P(h,{for:p})
|
141 |
+
const t=M(h,e.inputId+"-ts-label")
|
142 |
+
P(a,{"aria-labelledby":t}),P(n,{"aria-labelledby":t})}if(o.style.width=l.style.width,e.plugins.names.length){const t="plugin-"+e.plugins.names.join(" plugin-")
|
143 |
+
C([o,s],t)}(null===t.maxItems||t.maxItems>1)&&e.is_select_tag&&P(l,{multiple:"multiple"}),e.settings.placeholder&&P(i,{placeholder:t.placeholder}),!e.settings.splitOn&&e.settings.delimiter&&(e.settings.splitOn=new RegExp("\\s*"+v(e.settings.delimiter)+"+\\s*")),t.load&&t.loadThrottle&&(t.load=z(t.load,t.loadThrottle)),e.control_input.type=l.type,B(s,"click",(t=>{const i=k(t.target,"[data-selectable]")
|
144 |
+
i&&(e.onOptionSelect(t,i),H(t,!0))})),B(r,"click",(t=>{var s=k(t.target,"[data-ts-item]",r)
|
145 |
+
s&&e.onItemSelect(t,s)?H(t,!0):""==i.value&&(e.onClick(),H(t,!0))})),B(i,"mousedown",(e=>{""!==i.value&&e.stopPropagation()})),B(a,"keydown",(t=>e.onKeyDown(t))),B(i,"keypress",(t=>e.onKeyPress(t))),B(i,"input",(t=>e.onInput(t))),B(a,"resize",(()=>e.positionDropdown()),c),B(a,"blur",(t=>e.onBlur(t))),B(a,"focus",(t=>e.onFocus(t))),B(a,"paste",(t=>e.onPaste(t)))
|
146 |
+
const f=t=>{const i=t.composedPath()[0]
|
147 |
+
if(!o.contains(i)&&!s.contains(i))return e.isFocused&&e.blur(),void e.inputState()
|
148 |
+
H(t,!0)}
|
149 |
+
var m=()=>{e.isOpen&&e.positionDropdown()}
|
150 |
+
B(document,"mousedown",f),B(window,"scroll",m,c),B(window,"resize",m,c),this._destroy=()=>{document.removeEventListener("mousedown",f),window.removeEventListener("sroll",m),window.removeEventListener("resize",m),h&&h.removeEventListener("click",g)},this.revertSettings={innerHTML:l.innerHTML,tabIndex:l.tabIndex},l.tabIndex=-1,l.insertAdjacentElement("afterend",e.wrapper),e.sync(!1),t.items=[],delete t.optgroups,delete t.options,B(l,"invalid",(t=>{e.isValid&&(e.isValid=!1,e.isInvalid=!0,e.refreshState())})),e.updateOriginalInput(),e.refreshItems(),e.close(!1),e.inputState(),e.isSetup=!0,l.disabled?e.disable():e.enable(),e.on("change",this.onChange),C(l,"tomselected","ts-hidden-accessible"),e.trigger("initialize"),!0===t.preload&&e.preload()}setupOptions(e=[],t=[]){this.addOptions(e),y(t,(e=>{this.registerOptionGroup(e)}))}setupTemplates(){var e=this,t=e.settings.labelField,i=e.settings.optgroupLabelField,s={optgroup:e=>{let t=document.createElement("div")
|
151 |
+
return t.className="optgroup",t.appendChild(e.options),t},optgroup_header:(e,t)=>'<div class="optgroup-header">'+t(e[i])+"</div>",option:(e,i)=>"<div>"+i(e[t])+"</div>",item:(e,i)=>"<div>"+i(e[t])+"</div>",option_create:(e,t)=>'<div class="create">Add <strong>'+t(e.input)+"</strong>…</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"}
|
152 |
+
e.settings.render=Object.assign({},s,e.settings.render)}setupCallbacks(){var e,t,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"}
|
153 |
+
for(e in i)(t=this.settings[i[e]])&&this.on(e,t)}sync(e=!0){const t=this,i=e?U(t.input,{delimiter:t.settings.delimiter}):t.settings
|
154 |
+
t.setupOptions(i.options,i.optgroups),t.setValue(i.items,!0),t.lastQuery=null}onClick(){var e=this
|
155 |
+
if(e.activeItems.length>0)return e.clearActiveItems(),void e.focus()
|
156 |
+
e.isFocused&&e.isOpen?e.blur():e.focus()}onMouseDown(){}onChange(){_(this.input,"input"),_(this.input,"change")}onPaste(e){var t=this
|
157 |
+
t.isFull()||t.isInputHidden||t.isLocked?H(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue()
|
158 |
+
if(e.match(t.settings.splitOn)){var i=e.trim().split(t.settings.splitOn)
|
159 |
+
y(i,(e=>{t.createItem(e)}))}}),0)}onKeyPress(e){var t=this
|
160 |
+
if(!t.isLocked){var i=String.fromCharCode(e.keyCode||e.which)
|
161 |
+
return t.settings.create&&"multi"===t.settings.mode&&i===t.settings.delimiter?(t.createItem(),void H(e)):void 0}H(e)}onKeyDown(e){var t=this
|
162 |
+
if(t.isLocked)9!==e.keyCode&&H(e)
|
163 |
+
else{switch(e.keyCode){case 65:if(K(V,e))return H(e),void t.selectAll()
|
164 |
+
break
|
165 |
+
case 27:return t.isOpen&&(H(e,!0),t.close()),void t.clearActiveItems()
|
166 |
+
case 40:if(!t.isOpen&&t.hasOptions)t.open()
|
167 |
+
else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1)
|
168 |
+
e&&t.setActiveOption(e)}return void H(e)
|
169 |
+
case 38:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1)
|
170 |
+
e&&t.setActiveOption(e)}return void H(e)
|
171 |
+
case 13:return void(t.isOpen&&t.activeOption?(t.onOptionSelect(e,t.activeOption),H(e)):t.settings.create&&t.createItem()&&H(e))
|
172 |
+
case 37:return void t.advanceSelection(-1,e)
|
173 |
+
case 39:return void t.advanceSelection(1,e)
|
174 |
+
case 9:return void(t.settings.selectOnTab&&(t.isOpen&&t.activeOption&&(t.onOptionSelect(e,t.activeOption),H(e)),t.settings.create&&t.createItem()&&H(e)))
|
175 |
+
case 8:case 46:return void t.deleteSelection(e)}t.isInputHidden&&!K(V,e)&&H(e)}}onInput(e){var t=this
|
176 |
+
if(!t.isLocked){var i=t.inputValue()
|
177 |
+
t.lastValue!==i&&(t.lastValue=i,t.settings.shouldLoad.call(t,i)&&t.load(i),t.refreshOptions(),t.trigger("type",i))}}onFocus(e){var t=this,i=t.isFocused
|
178 |
+
if(t.isDisabled)return t.blur(),void H(e)
|
179 |
+
t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.preload(),i||t.trigger("focus"),t.activeItems.length||(t.showInput(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e){if(!1!==document.hasFocus()){var t=this
|
180 |
+
if(t.isFocused){t.isFocused=!1,t.ignoreFocus=!1
|
181 |
+
var i=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")}
|
182 |
+
t.settings.create&&t.settings.createOnBlur?t.createItem(null,!1,i):i()}}}onOptionSelect(e,t){var i,s=this
|
183 |
+
t&&(t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?s.createItem(null,!0,(()=>{s.settings.closeAfterSelect&&s.close()})):void 0!==(i=t.dataset.value)&&(s.lastQuery=null,s.addItem(i),s.settings.closeAfterSelect&&s.close(),!s.settings.hideSelected&&e.type&&/click/.test(e.type)&&s.setActiveOption(t))))}onItemSelect(e,t){var i=this
|
184 |
+
return!i.isLocked&&"multi"===i.settings.mode&&(H(e),i.setActiveItem(t,e),!0)}canLoad(e){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(e)}load(e){const t=this
|
185 |
+
if(!t.canLoad(e))return
|
186 |
+
C(t.wrapper,t.settings.loadingClass),t.loading++
|
187 |
+
const i=t.loadCallback.bind(t)
|
188 |
+
t.settings.load.call(t,e,i)}loadCallback(e,t){const i=this
|
189 |
+
i.loading=Math.max(i.loading-1,0),i.lastQuery=null,i.clearActiveOption(),i.setupOptions(e,t),i.refreshOptions(i.isFocused&&!i.isInputHidden),i.loading||S(i.wrapper,i.settings.loadingClass),i.trigger("load",e,t)}preload(){var e=this.wrapper.classList
|
190 |
+
e.contains("preloaded")||(e.add("preloaded"),this.load(""))}setTextboxValue(e=""){var t=this.control_input
|
191 |
+
t.value!==e&&(t.value=e,_(t,"update"),this.lastValue=e)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){R(this,t?[]:["change"],(()=>{this.clear(t),this.addItems(e,t)}))}setMaxItems(e){0===e&&(e=null),this.settings.maxItems=e,this.refreshState()}setActiveItem(e,t){var i,s,n,o,r,l,a=this
|
192 |
+
if("single"!==a.settings.mode){if(!e)return a.clearActiveItems(),void(a.isFocused&&a.showInput())
|
193 |
+
if("click"===(i=t&&t.type.toLowerCase())&&K("shiftKey",t)&&a.activeItems.length){for(l=a.getLastActive(),(n=Array.prototype.indexOf.call(a.control.children,l))>(o=Array.prototype.indexOf.call(a.control.children,e))&&(r=n,n=o,o=r),s=n;s<=o;s++)e=a.control.children[s],-1===a.activeItems.indexOf(e)&&a.setActiveItemClass(e)
|
194 |
+
H(t)}else"click"===i&&K(V,t)||"keydown"===i&&K("shiftKey",t)?e.classList.contains("active")?a.removeActiveItem(e):a.setActiveItemClass(e):(a.clearActiveItems(),a.setActiveItemClass(e))
|
195 |
+
a.hideInput(),a.isFocused||a.focus()}}setActiveItemClass(e){const t=this,i=t.control.querySelector(".last-active")
|
196 |
+
i&&S(i,"last-active"),C(e,"active last-active"),t.trigger("item_select",e),-1==t.activeItems.indexOf(e)&&t.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e)
|
197 |
+
this.activeItems.splice(t,1),S(e,"active")}clearActiveItems(){S(this.activeItems,"active"),this.activeItems=[]}setActiveOption(e){e!==this.activeOption&&(this.clearActiveOption(),e&&(this.activeOption=e,P(this.focus_node,{"aria-activedescendant":e.getAttribute("id")}),P(e,{"aria-selected":"true"}),C(e,"active"),this.scrollToOption(e)))}scrollToOption(e,t){if(!e)return
|
198 |
+
const i=this.dropdown_content,s=i.clientHeight,n=i.scrollTop||0,o=e.offsetHeight,r=e.getBoundingClientRect().top-i.getBoundingClientRect().top+n
|
199 |
+
r+o>s+n?this.scroll(r-s+o,t):r<n&&this.scroll(r,t)}scroll(e,t){const i=this.dropdown_content
|
200 |
+
t&&(i.style.scrollBehavior=t),i.scrollTop=e,i.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(S(this.activeOption,"active"),P(this.activeOption,{"aria-selected":null})),this.activeOption=null,P(this.focus_node,{"aria-activedescendant":null})}selectAll(){if("single"===this.settings.mode)return
|
201 |
+
const e=this.controlChildren()
|
202 |
+
e.length&&(this.hideInput(),this.close(),this.activeItems=e,C(e,"active"))}inputState(){var e=this
|
203 |
+
e.control.contains(e.control_input)&&(P(e.control_input,{placeholder:e.settings.placeholder}),e.activeItems.length>0||!e.isFocused&&e.settings.hidePlaceholder&&e.items.length>0?(e.setTextboxValue(),e.isInputHidden=!0):(e.settings.hidePlaceholder&&e.items.length>0&&P(e.control_input,{placeholder:""}),e.isInputHidden=!1),e.wrapper.classList.toggle("input-hidden",e.isInputHidden))}hideInput(){this.inputState()}showInput(){this.inputState()}inputValue(){return this.control_input.value.trim()}focus(){var e=this
|
204 |
+
e.isDisabled||(e.ignoreFocus=!0,e.control_input.offsetWidth?e.control_input.focus():e.focus_node.focus(),setTimeout((()=>{e.ignoreFocus=!1,e.onFocus()}),0))}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e=this.settings,t=e.sortField
|
205 |
+
return"string"==typeof e.sortField&&(t=[{field:e.sortField}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting}}search(e){var t,i,s,n=this,o=this.getSearchOptions()
|
206 |
+
if(n.settings.score&&"function"!=typeof(s=n.settings.score.call(n,e)))throw new Error('Tom Select "score" setting must be a function that returns a function')
|
207 |
+
if(e!==n.lastQuery?(n.lastQuery=e,i=n.sifter.search(e,Object.assign(o,{score:s})),n.currentResults=i):i=Object.assign({},n.currentResults),n.settings.hideSelected)for(t=i.items.length-1;t>=0;t--){let e=q(i.items[t].id)
|
208 |
+
e&&-1!==n.items.indexOf(e)&&i.items.splice(t,1)}return i}refreshOptions(e=!0){var t,i,s,n,o,r,l,a,c,d,p
|
209 |
+
const u={},h=[]
|
210 |
+
var g,f=this,v=f.inputValue(),m=f.search(v),O=f.activeOption,b=f.settings.shouldOpen||!1,w=f.dropdown_content
|
211 |
+
for(O&&(c=O.dataset.value,d=O.closest("[data-group]")),n=m.items.length,"number"==typeof f.settings.maxOptions&&(n=Math.min(n,f.settings.maxOptions)),n>0&&(b=!0),t=0;t<n;t++){let e=m.items[t].id,n=f.options[e],l=f.getOption(e,!0)
|
212 |
+
for(f.settings.hideSelected||l.classList.toggle("selected",f.items.includes(e)),o=n[f.settings.optgroupField]||"",i=0,s=(r=Array.isArray(o)?o:[o])&&r.length;i<s;i++)o=r[i],f.optgroups.hasOwnProperty(o)||(o=""),u.hasOwnProperty(o)||(u[o]=document.createDocumentFragment(),h.push(o)),i>0&&(l=l.cloneNode(!0),P(l,{id:n.$id+"-clone-"+i,"aria-selected":null}),l.classList.add("ts-cloned"),S(l,"active")),c==e&&d&&d.dataset.group===o&&(O=l),u[o].appendChild(l)}this.settings.lockOptgroupOrder&&h.sort(((e,t)=>(f.optgroups[e]&&f.optgroups[e].$order||0)-(f.optgroups[t]&&f.optgroups[t].$order||0))),l=document.createDocumentFragment(),y(h,(e=>{if(f.optgroups.hasOwnProperty(e)&&u[e].children.length){let t=document.createDocumentFragment(),i=f.render("optgroup_header",f.optgroups[e])
|
213 |
+
G(t,i),G(t,u[e])
|
214 |
+
let s=f.render("optgroup",{group:f.optgroups[e],options:t})
|
215 |
+
G(l,s)}else G(l,u[e])})),w.innerHTML="",G(w,l),f.settings.highlight&&(g=w.querySelectorAll("span.highlight"),Array.prototype.forEach.call(g,(function(e){var t=e.parentNode
|
216 |
+
t.replaceChild(e.firstChild,e),t.normalize()})),m.query.length&&m.tokens.length&&y(m.tokens,(e=>{T(w,e.regex)})))
|
217 |
+
var _=e=>{let t=f.render(e,{input:v})
|
218 |
+
return t&&(b=!0,w.insertBefore(t,w.firstChild)),t}
|
219 |
+
if(f.loading?_("loading"):f.settings.shouldLoad.call(f,v)?0===m.items.length&&_("no_results"):_("not_loading"),(a=f.canCreate(v))&&(p=_("option_create")),f.hasOptions=m.items.length>0||a,b){if(m.items.length>0){if(!w.contains(O)&&"single"===f.settings.mode&&f.items.length&&(O=f.getOption(f.items[0])),!w.contains(O)){let e=0
|
220 |
+
p&&!f.settings.addPrecedence&&(e=1),O=f.selectable()[e]}}else p&&(O=p)
|
221 |
+
e&&!f.isOpen&&(f.open(),f.scrollToOption(O,"auto")),f.setActiveOption(O)}else f.clearActiveOption(),e&&f.isOpen&&f.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=!1){const i=this
|
222 |
+
if(Array.isArray(e))return i.addOptions(e,t),!1
|
223 |
+
const s=q(e[i.settings.valueField])
|
224 |
+
return null!==s&&!i.options.hasOwnProperty(s)&&(e.$order=e.$order||++i.order,e.$id=i.inputId+"-opt-"+e.$order,i.options[s]=e,i.lastQuery=null,t&&(i.userOptions[s]=t,i.trigger("option_add",s,e)),s)}addOptions(e,t=!1){y(e,(e=>{this.addOption(e,t)}))}registerOption(e){return this.addOption(e)}registerOptionGroup(e){var t=q(e[this.settings.optgroupValueField])
|
225 |
+
return null!==t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var i
|
226 |
+
t[this.settings.optgroupValueField]=e,(i=this.registerOptionGroup(t))&&this.trigger("optgroup_add",i,t)}removeOptionGroup(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.clearCache(),this.trigger("optgroup_remove",e))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(e,t){const i=this
|
227 |
+
var s,n
|
228 |
+
const o=q(e),r=q(t[i.settings.valueField])
|
229 |
+
if(null===o)return
|
230 |
+
if(!i.options.hasOwnProperty(o))return
|
231 |
+
if("string"!=typeof r)throw new Error("Value must be set in option data")
|
232 |
+
const l=i.getOption(o),a=i.getItem(o)
|
233 |
+
if(t.$order=t.$order||i.options[o].$order,delete i.options[o],i.uncacheValue(r),i.options[r]=t,l){if(i.dropdown_content.contains(l)){const e=i._render("option",t)
|
234 |
+
E(l,e),i.activeOption===l&&i.setActiveOption(e)}l.remove()}a&&(-1!==(n=i.items.indexOf(o))&&i.items.splice(n,1,r),s=i._render("item",t),a.classList.contains("active")&&C(s,"active"),E(a,s)),i.lastQuery=null}removeOption(e,t){const i=this
|
235 |
+
e=D(e),i.uncacheValue(e),delete i.userOptions[e],delete i.options[e],i.lastQuery=null,i.trigger("option_remove",e),i.removeItem(e,t)}clearOptions(){this.loadedSearches={},this.userOptions={},this.clearCache()
|
236 |
+
var e={}
|
237 |
+
y(this.options,((t,i)=>{this.items.indexOf(i)>=0&&(e[i]=this.options[i])})),this.options=this.sifter.items=e,this.lastQuery=null,this.trigger("option_clear")}getOption(e,t=!1){const i=q(e)
|
238 |
+
if(null!==i&&this.options.hasOwnProperty(i)){const e=this.options[i]
|
239 |
+
if(e.$div)return e.$div
|
240 |
+
if(t)return this._render("option",e)}return null}getAdjacent(e,t,i="option"){var s
|
241 |
+
if(!e)return null
|
242 |
+
s="item"==i?this.controlChildren():this.dropdown_content.querySelectorAll("[data-selectable]")
|
243 |
+
for(let i=0;i<s.length;i++)if(s[i]==e)return t>0?s[i+1]:s[i-1]
|
244 |
+
return null}getItem(e){if("object"==typeof e)return e
|
245 |
+
var t=q(e)
|
246 |
+
return null!==t?this.control.querySelector(`[data-value="${Q(t)}"]`):null}addItems(e,t){var i=this,s=Array.isArray(e)?e:[e]
|
247 |
+
for(let e=0,n=(s=s.filter((e=>-1===i.items.indexOf(e)))).length;e<n;e++)i.isPending=e<n-1,i.addItem(s[e],t)}addItem(e,t){R(this,t?[]:["change"],(()=>{var i,s
|
248 |
+
const n=this,o=n.settings.mode,r=q(e)
|
249 |
+
if((!r||-1===n.items.indexOf(r)||("single"===o&&n.close(),"single"!==o&&n.settings.duplicates))&&null!==r&&n.options.hasOwnProperty(r)&&("single"===o&&n.clear(t),"multi"!==o||!n.isFull())){if(i=n._render("item",n.options[r]),n.control.contains(i)&&(i=i.cloneNode(!0)),s=n.isFull(),n.items.splice(n.caretPos,0,r),n.insertAtCaret(i),n.isSetup){if(!n.isPending&&n.settings.hideSelected){let e=n.getOption(r),t=n.getAdjacent(e,1)
|
250 |
+
t&&n.setActiveOption(t)}n.isPending||n.refreshOptions(n.isFocused&&"single"!==o),0!=n.settings.closeAfterSelect&&n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",r,i),n.isPending||n.updateOriginalInput({silent:t})}(!n.isPending||!s&&n.isFull())&&(n.inputState(),n.refreshState())}}))}removeItem(e=null,t){const i=this
|
251 |
+
if(!(e=i.getItem(e)))return
|
252 |
+
var s,n
|
253 |
+
const o=e.dataset.value
|
254 |
+
s=L(e),e.remove(),e.classList.contains("active")&&(n=i.activeItems.indexOf(e),i.activeItems.splice(n,1),S(e,"active")),i.items.splice(s,1),i.lastQuery=null,!i.settings.persist&&i.userOptions.hasOwnProperty(o)&&i.removeOption(o,t),s<i.caretPos&&i.setCaret(i.caretPos-1),i.updateOriginalInput({silent:t}),i.refreshState(),i.positionDropdown(),i.trigger("item_remove",o,e)}createItem(e=null,t=!0,i=(()=>{})){var s,n=this,o=n.caretPos
|
255 |
+
if(e=e||n.inputValue(),!n.canCreate(e))return i(),!1
|
256 |
+
n.lock()
|
257 |
+
var r=!1,l=e=>{if(n.unlock(),!e||"object"!=typeof e)return i()
|
258 |
+
var s=q(e[n.settings.valueField])
|
259 |
+
if("string"!=typeof s)return i()
|
260 |
+
n.setTextboxValue(),n.addOption(e,!0),n.setCaret(o),n.addItem(s),n.refreshOptions(t&&"single"!==n.settings.mode),i(e),r=!0}
|
261 |
+
return s="function"==typeof n.settings.create?n.settings.create.call(this,e,l):{[n.settings.labelField]:e,[n.settings.valueField]:e},r||l(s),!0}refreshItems(){var e=this
|
262 |
+
e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.updateOriginalInput(),e.refreshState()}refreshState(){const e=this
|
263 |
+
e.refreshValidityState()
|
264 |
+
const t=e.isFull(),i=e.isLocked
|
265 |
+
e.wrapper.classList.toggle("rtl",e.rtl)
|
266 |
+
const s=e.wrapper.classList
|
267 |
+
var n
|
268 |
+
s.toggle("focus",e.isFocused),s.toggle("disabled",e.isDisabled),s.toggle("required",e.isRequired),s.toggle("invalid",!e.isValid),s.toggle("locked",i),s.toggle("full",t),s.toggle("input-active",e.isFocused&&!e.isInputHidden),s.toggle("dropdown-active",e.isOpen),s.toggle("has-options",(n=e.options,0===Object.keys(n).length)),s.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this
|
269 |
+
e.input.checkValidity&&(e.isValid=e.input.checkValidity(),e.isInvalid=!e.isValid)}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){const t=this
|
270 |
+
var i,s
|
271 |
+
const n=t.input.querySelector('option[value=""]')
|
272 |
+
if(t.is_select_tag){const e=[]
|
273 |
+
function o(i,s,o){return i||(i=w('<option value="'+N(s)+'">'+N(o)+"</option>")),i!=n&&t.input.append(i),e.push(i),i.selected=!0,i}t.input.querySelectorAll("option:checked").forEach((e=>{e.selected=!1})),0==t.items.length&&"single"==t.settings.mode?o(n,"",""):t.items.forEach((n=>{if(i=t.options[n],s=i[t.settings.labelField]||"",e.includes(i.$option)){o(t.input.querySelector(`option[value="${Q(n)}"]:not(:checked)`),n,s)}else i.$option=o(i.$option,n,s)}))}else t.input.value=t.getValue()
|
274 |
+
t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this
|
275 |
+
e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.isOpen=!0,P(e.focus_node,{"aria-expanded":"true"}),e.refreshState(),I(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),I(e.dropdown,{visibility:"visible",display:"block"}),e.focus(),e.trigger("dropdown_open",e.dropdown))}close(e=!0){var t=this,i=t.isOpen
|
276 |
+
e&&(t.setTextboxValue(),"single"===t.settings.mode&&t.items.length&&t.hideInput()),t.isOpen=!1,P(t.focus_node,{"aria-expanded":"false"}),I(t.dropdown,{display:"none"}),t.settings.hideSelected&&t.clearActiveOption(),t.refreshState(),i&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control,t=e.getBoundingClientRect(),i=e.offsetHeight+t.top+window.scrollY,s=t.left+window.scrollX
|
277 |
+
I(this.dropdown,{width:t.width+"px",top:i+"px",left:s+"px"})}}clear(e){var t=this
|
278 |
+
if(t.items.length){var i=t.controlChildren()
|
279 |
+
y(i,(e=>{t.removeItem(e,!0)})),t.showInput(),e||t.updateOriginalInput(),t.trigger("clear")}}insertAtCaret(e){const t=this,i=t.caretPos,s=t.control
|
280 |
+
s.insertBefore(e,s.children[i]),t.setCaret(i+1)}deleteSelection(e){var t,i,s,n,o,r=this
|
281 |
+
t=e&&8===e.keyCode?-1:1,i={start:(o=r.control_input).selectionStart||0,length:(o.selectionEnd||0)-(o.selectionStart||0)}
|
282 |
+
const l=[]
|
283 |
+
if(r.activeItems.length)n=F(r.activeItems,t),s=L(n),t>0&&s++,y(r.activeItems,(e=>l.push(e)))
|
284 |
+
else if((r.isFocused||"single"===r.settings.mode)&&r.items.length){const e=r.controlChildren()
|
285 |
+
t<0&&0===i.start&&0===i.length?l.push(e[r.caretPos-1]):t>0&&i.start===r.inputValue().length&&l.push(e[r.caretPos])}const a=l.map((e=>e.dataset.value))
|
286 |
+
if(!a.length||"function"==typeof r.settings.onDelete&&!1===r.settings.onDelete.call(r,a,e))return!1
|
287 |
+
for(H(e,!0),void 0!==s&&r.setCaret(s);l.length;)r.removeItem(l.pop())
|
288 |
+
return r.showInput(),r.positionDropdown(),r.refreshOptions(!1),!0}advanceSelection(e,t){var i,s,n=this
|
289 |
+
n.rtl&&(e*=-1),n.inputValue().length||(K(V,t)||K("shiftKey",t)?(s=(i=n.getLastActive(e))?i.classList.contains("active")?n.getAdjacent(i,e,"item"):i:e>0?n.control_input.nextElementSibling:n.control_input.previousElementSibling)&&(s.classList.contains("active")&&n.removeActiveItem(i),n.setActiveItemClass(s)):n.moveCaret(e))}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active")
|
290 |
+
if(t)return t
|
291 |
+
var i=this.control.querySelectorAll(".active")
|
292 |
+
return i?F(i,e):void 0}setCaret(e){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.close(),this.isLocked=!0,this.refreshState()}unlock(){this.isLocked=!1,this.refreshState()}disable(){var e=this
|
293 |
+
e.input.disabled=!0,e.control_input.disabled=!0,e.focus_node.tabIndex=-1,e.isDisabled=!0,e.lock()}enable(){var e=this
|
294 |
+
e.input.disabled=!1,e.control_input.disabled=!1,e.focus_node.tabIndex=e.tabIndex,e.isDisabled=!1,e.unlock()}destroy(){var e=this,t=e.revertSettings
|
295 |
+
e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML=t.innerHTML,e.input.tabIndex=t.tabIndex,S(e.input,"tomselected","ts-hidden-accessible"),e._destroy(),delete e.input.tomselect}render(e,t){return"function"!=typeof this.settings.render[e]?null:this._render(e,t)}_render(e,t){var i,s,n=""
|
296 |
+
const o=this
|
297 |
+
return"option"!==e&&"item"!=e||(n=D(t[o.settings.valueField])),null==(s=o.settings.render[e].call(this,t,N))||(s=w(s),"option"===e||"option_create"===e?t[o.settings.disabledField]?P(s,{"aria-disabled":"true"}):P(s,{"data-selectable":""}):"optgroup"===e&&(i=t.group[o.settings.optgroupValueField],P(s,{"data-group":i}),t.group[o.settings.disabledField]&&P(s,{"data-disabled":""})),"option"!==e&&"item"!==e||(P(s,{"data-value":n}),"item"===e?(C(s,o.settings.itemClass),P(s,{"data-ts-item":""})):(C(s,o.settings.optionClass),P(s,{role:"option",id:t.$id}),o.options[n].$div=s))),s}clearCache(){y(this.options,((e,t)=>{e.$div&&(e.$div.remove(),delete e.$div)}))}uncacheValue(e){const t=this.getOption(e)
|
298 |
+
t&&t.remove()}canCreate(e){return this.settings.create&&e.length>0&&this.settings.createFilter.call(this,e)}hook(e,t,i){var s=this,n=s[t]
|
299 |
+
s[t]=function(){var t,o
|
300 |
+
return"after"===e&&(t=n.apply(s,arguments)),o=i.apply(s,arguments),"instead"===e?o:("before"===e&&(t=n.apply(s,arguments)),t)}}}return J.define("change_listener",(function(){B(this.input,"change",(()=>{this.sync()}))})),J.define("checkbox_options",(function(){var e=this,t=e.onOptionSelect
|
301 |
+
e.settings.hideSelected=!1
|
302 |
+
var i=function(e){setTimeout((()=>{var t=e.querySelector("input")
|
303 |
+
e.classList.contains("selected")?t.checked=!0:t.checked=!1}),1)}
|
304 |
+
e.hook("after","setupTemplates",(()=>{var t=e.settings.render.option
|
305 |
+
e.settings.render.option=(i,s)=>{var n=w(t.call(e,i,s)),o=document.createElement("input")
|
306 |
+
o.addEventListener("click",(function(e){H(e)})),o.type="checkbox"
|
307 |
+
const r=q(i[e.settings.valueField])
|
308 |
+
return r&&e.items.indexOf(r)>-1&&(o.checked=!0),n.prepend(o),n}})),e.on("item_remove",(t=>{var s=e.getOption(t)
|
309 |
+
s&&(s.classList.remove("selected"),i(s))})),e.hook("instead","onOptionSelect",((s,n)=>{if(n.classList.contains("selected"))return n.classList.remove("selected"),e.removeItem(n.dataset.value),e.refreshOptions(),void H(s,!0)
|
310 |
+
t.call(e,s,n),i(n)}))})),J.define("clear_button",(function(e){const t=this,i=Object.assign({className:"clear-button",title:"Clear All",html:e=>`<div class="${e.className}" title="${e.title}">×</div>`},e)
|
311 |
+
t.on("initialize",(()=>{var e=w(i.html(i))
|
312 |
+
e.addEventListener("click",(e=>{t.clear(),"single"===t.settings.mode&&t.settings.allowEmptyOption&&t.addItem(""),e.preventDefault(),e.stopPropagation()})),t.control.appendChild(e)}))})),J.define("drag_drop",(function(){var e=this
|
313 |
+
if(!$.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".')
|
314 |
+
if("multi"===e.settings.mode){var t=e.lock,i=e.unlock
|
315 |
+
e.hook("instead","lock",(()=>{var i=$(e.control).data("sortable")
|
316 |
+
return i&&i.disable(),t.call(e)})),e.hook("instead","unlock",(()=>{var t=$(e.control).data("sortable")
|
317 |
+
return t&&t.enable(),i.call(e)})),e.on("initialize",(()=>{var t=$(e.control).sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:e.isLocked,start:(e,i)=>{i.placeholder.css("width",i.helper.css("width")),t.css({overflow:"visible"})},stop:()=>{t.css({overflow:"hidden"})
|
318 |
+
var i=[]
|
319 |
+
t.children("[data-value]").each((function(){this.dataset.value&&i.push(this.dataset.value)})),e.setValue(i)}})}))}})),J.define("dropdown_header",(function(e){const t=this,i=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:e=>'<div class="'+e.headerClass+'"><div class="'+e.titleRowClass+'"><span class="'+e.labelClass+'">'+e.title+'</span><a class="'+e.closeClass+'">×</a></div></div>'},e)
|
320 |
+
t.on("initialize",(()=>{var e=w(i.html(i)),s=e.querySelector("."+i.closeClass)
|
321 |
+
s&&s.addEventListener("click",(e=>{H(e,!0),t.close()})),t.dropdown.insertBefore(e,t.dropdown.firstChild)}))})),J.define("caret_position",(function(){var e=this
|
322 |
+
e.hook("instead","setCaret",(t=>{"single"!==e.settings.mode&&e.control.contains(e.control_input)?(t=Math.max(0,Math.min(e.items.length,t)))==e.caretPos||e.isPending||e.controlChildren().forEach(((i,s)=>{s<t?e.control_input.insertAdjacentElement("beforebegin",i):e.control.appendChild(i)})):t=e.items.length,e.caretPos=t})),e.hook("instead","moveCaret",(t=>{if(!e.isFocused)return
|
323 |
+
const i=e.getLastActive(t)
|
324 |
+
if(i){const s=L(i)
|
325 |
+
e.setCaret(t>0?s+1:s),e.setActiveItem()}else e.setCaret(e.caretPos+t)}))})),J.define("dropdown_input",(function(){var e=this
|
326 |
+
e.settings.shouldOpen=!0,e.hook("before","setup",(()=>{e.focus_node=e.control,C(e.control_input,"dropdown-input")
|
327 |
+
const t=w('<div class="dropdown-input-wrap">')
|
328 |
+
t.append(e.control_input),e.dropdown.insertBefore(t,e.dropdown.firstChild)})),e.on("initialize",(()=>{e.control_input.addEventListener("keydown",(t=>{switch(t.keyCode){case 27:return e.isOpen&&(H(t,!0),e.close()),void e.clearActiveItems()
|
329 |
+
case 9:e.focus_node.tabIndex=-1}return e.onKeyDown.call(e,t)})),e.on("blur",(()=>{e.focus_node.tabIndex=e.isDisabled?-1:e.tabIndex})),e.on("dropdown_open",(()=>{e.control_input.focus()}))
|
330 |
+
const t=e.onBlur
|
331 |
+
e.hook("instead","onBlur",(i=>{if(!i||i.relatedTarget!=e.control_input)return t.call(e)})),B(e.control_input,"blur",(()=>e.onBlur())),e.hook("before","close",(()=>{e.isOpen&&e.focus_node.focus()}))}))})),J.define("input_autogrow",(function(){var e=this
|
332 |
+
e.on("initialize",(()=>{var t=document.createElement("span"),i=e.control_input
|
333 |
+
t.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",e.wrapper.appendChild(t)
|
334 |
+
for(const e of["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"])t.style[e]=i.style[e]
|
335 |
+
var s=()=>{e.items.length>0?(t.textContent=i.value,i.style.width=t.clientWidth+"px"):i.style.width=""}
|
336 |
+
s(),e.on("update item_add item_remove",s),B(i,"input",s),B(i,"keyup",s),B(i,"blur",s),B(i,"update",s)}))})),J.define("no_backspace_delete",(function(){var e=this,t=e.deleteSelection
|
337 |
+
this.hook("instead","deleteSelection",(i=>!!e.activeItems.length&&t.call(e,i)))})),J.define("no_active_items",(function(){this.hook("instead","setActiveItem",(()=>{})),this.hook("instead","selectAll",(()=>{}))})),J.define("optgroup_columns",(function(){var e=this,t=e.onKeyDown
|
338 |
+
e.hook("instead","onKeyDown",(i=>{var s,n,o,r
|
339 |
+
if(!e.isOpen||37!==i.keyCode&&39!==i.keyCode)return t.call(e,i)
|
340 |
+
r=k(e.activeOption,"[data-group]"),s=L(e.activeOption,"[data-selectable]"),r&&(r=37===i.keyCode?r.previousSibling:r.nextSibling)&&(n=(o=r.querySelectorAll("[data-selectable]"))[Math.min(o.length-1,s)])&&e.setActiveOption(n)}))})),J.define("remove_button",(function(e){const t=Object.assign({label:"×",title:"Remove",className:"remove",append:!0},e)
|
341 |
+
var i=this
|
342 |
+
if(t.append){var s='<a href="javascript:void(0)" class="'+t.className+'" tabindex="-1" title="'+N(t.title)+'">'+t.label+"</a>"
|
343 |
+
i.hook("after","setupTemplates",(()=>{var e=i.settings.render.item
|
344 |
+
i.settings.render.item=(t,n)=>{var o=w(e.call(i,t,n)),r=w(s)
|
345 |
+
return o.appendChild(r),B(r,"mousedown",(e=>{H(e,!0)})),B(r,"click",(e=>{if(H(e,!0),!i.isLocked){var t=o.dataset.value
|
346 |
+
i.removeItem(t),i.refreshOptions(!1)}})),o}}))}})),J.define("restore_on_backspace",(function(e){const t=this,i=Object.assign({text:e=>e[t.settings.labelField]},e)
|
347 |
+
t.on("item_remove",(function(e){if(""===t.control_input.value.trim()){var s=t.options[e]
|
348 |
+
s&&t.setTextboxValue(i.text.call(t,s))}}))})),J.define("virtual_scroll",(function(){const e=this,t=e.canLoad,i=e.clearActiveOption,s=e.loadCallback
|
349 |
+
var n,o={},r=!1
|
350 |
+
if(!e.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method"
|
351 |
+
function l(t){return!("number"==typeof e.settings.maxOptions&&n.children.length>=e.settings.maxOptions)&&!(!(t in o)||!o[t])}e.settings.sortField=[{field:"$order"},{field:"$score"}],e.setNextUrl=function(e,t){o[e]=t},e.getUrl=function(t){if(t in o){const e=o[t]
|
352 |
+
return o[t]=!1,e}return o={},e.settings.firstUrl(t)},e.hook("instead","clearActiveOption",(()=>{if(!r)return i.call(e)})),e.hook("instead","canLoad",(i=>i in o?l(i):t.call(e,i))),e.hook("instead","loadCallback",((t,i)=>{r||e.clearOptions(),s.call(e,t,i),r=!1})),e.hook("after","refreshOptions",(()=>{const t=e.lastValue
|
353 |
+
var i
|
354 |
+
l(t)?(i=e.render("loading_more",{query:t}))&&i.setAttribute("data-selectable",""):t in o&&!n.querySelector(".no-results")&&(i=e.render("no_more_results",{query:t})),i&&(C(i,e.settings.optionClass),n.append(i))})),e.on("initialize",(()=>{n=e.dropdown_content,e.settings.render=Object.assign({},{loading_more:function(){return'<div class="loading-more-results">Loading more results ... </div>'},no_more_results:function(){return'<div class="no-more-results">No more results</div>'}},e.settings.render),n.addEventListener("scroll",(function(){n.clientHeight/(n.scrollHeight-n.scrollTop)<.95||l(e.lastValue)&&(r||(r=!0,e.load.call(e,e.lastValue)))}))}))})),J}))
|
355 |
+
var tomSelect=function(e,t){return new TomSelect(e,t)}
|
356 |
+
//# sourceMappingURL=tom-select.complete.min.js.map
|
streamlit_app/lib/tom-select/tom-select.css
ADDED
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* tom-select.css (v2.0.0-rc.4)
|
3 |
+
* Copyright (c) contributors
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
6 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
*
|
9 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
10 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
12 |
+
* governing permissions and limitations under the License.
|
13 |
+
*
|
14 |
+
*/
|
15 |
+
.ts-wrapper.plugin-drag_drop.multi > .ts-control > div.ui-sortable-placeholder {
|
16 |
+
visibility: visible !important;
|
17 |
+
background: #f2f2f2 !important;
|
18 |
+
background: rgba(0, 0, 0, 0.06) !important;
|
19 |
+
border: 0 none !important;
|
20 |
+
box-shadow: inset 0 0 12px 4px #fff; }
|
21 |
+
|
22 |
+
.ts-wrapper.plugin-drag_drop .ui-sortable-placeholder::after {
|
23 |
+
content: '!';
|
24 |
+
visibility: hidden; }
|
25 |
+
|
26 |
+
.ts-wrapper.plugin-drag_drop .ui-sortable-helper {
|
27 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); }
|
28 |
+
|
29 |
+
.plugin-checkbox_options .option input {
|
30 |
+
margin-right: 0.5rem; }
|
31 |
+
|
32 |
+
.plugin-clear_button .ts-control {
|
33 |
+
padding-right: calc( 1em + (3 * 6px)) !important; }
|
34 |
+
|
35 |
+
.plugin-clear_button .clear-button {
|
36 |
+
opacity: 0;
|
37 |
+
position: absolute;
|
38 |
+
top: 8px;
|
39 |
+
right: calc(8px - 6px);
|
40 |
+
margin-right: 0 !important;
|
41 |
+
background: transparent !important;
|
42 |
+
transition: opacity 0.5s;
|
43 |
+
cursor: pointer; }
|
44 |
+
|
45 |
+
.plugin-clear_button.single .clear-button {
|
46 |
+
right: calc(8px - 6px + 2rem); }
|
47 |
+
|
48 |
+
.plugin-clear_button.focus.has-items .clear-button,
|
49 |
+
.plugin-clear_button:hover.has-items .clear-button {
|
50 |
+
opacity: 1; }
|
51 |
+
|
52 |
+
.ts-wrapper .dropdown-header {
|
53 |
+
position: relative;
|
54 |
+
padding: 10px 8px;
|
55 |
+
border-bottom: 1px solid #d0d0d0;
|
56 |
+
background: #f8f8f8;
|
57 |
+
border-radius: 3px 3px 0 0; }
|
58 |
+
|
59 |
+
.ts-wrapper .dropdown-header-close {
|
60 |
+
position: absolute;
|
61 |
+
right: 8px;
|
62 |
+
top: 50%;
|
63 |
+
color: #303030;
|
64 |
+
opacity: 0.4;
|
65 |
+
margin-top: -12px;
|
66 |
+
line-height: 20px;
|
67 |
+
font-size: 20px !important; }
|
68 |
+
|
69 |
+
.ts-wrapper .dropdown-header-close:hover {
|
70 |
+
color: black; }
|
71 |
+
|
72 |
+
.plugin-dropdown_input.focus.dropdown-active .ts-control {
|
73 |
+
box-shadow: none;
|
74 |
+
border: 1px solid #d0d0d0; }
|
75 |
+
|
76 |
+
.plugin-dropdown_input .dropdown-input {
|
77 |
+
border: 1px solid #d0d0d0;
|
78 |
+
border-width: 0 0 1px 0;
|
79 |
+
display: block;
|
80 |
+
padding: 8px 8px;
|
81 |
+
box-shadow: none;
|
82 |
+
width: 100%;
|
83 |
+
background: transparent; }
|
84 |
+
|
85 |
+
.ts-wrapper.plugin-input_autogrow.has-items .ts-control > input {
|
86 |
+
min-width: 0; }
|
87 |
+
|
88 |
+
.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input {
|
89 |
+
flex: none;
|
90 |
+
min-width: 4px; }
|
91 |
+
.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::-webkit-input-placeholder {
|
92 |
+
color: transparent; }
|
93 |
+
.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::-ms-input-placeholder {
|
94 |
+
color: transparent; }
|
95 |
+
.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::placeholder {
|
96 |
+
color: transparent; }
|
97 |
+
|
98 |
+
.ts-dropdown.plugin-optgroup_columns .ts-dropdown-content {
|
99 |
+
display: flex; }
|
100 |
+
|
101 |
+
.ts-dropdown.plugin-optgroup_columns .optgroup {
|
102 |
+
border-right: 1px solid #f2f2f2;
|
103 |
+
border-top: 0 none;
|
104 |
+
flex-grow: 1;
|
105 |
+
flex-basis: 0;
|
106 |
+
min-width: 0; }
|
107 |
+
|
108 |
+
.ts-dropdown.plugin-optgroup_columns .optgroup:last-child {
|
109 |
+
border-right: 0 none; }
|
110 |
+
|
111 |
+
.ts-dropdown.plugin-optgroup_columns .optgroup:before {
|
112 |
+
display: none; }
|
113 |
+
|
114 |
+
.ts-dropdown.plugin-optgroup_columns .optgroup-header {
|
115 |
+
border-top: 0 none; }
|
116 |
+
|
117 |
+
.ts-wrapper.plugin-remove_button .item {
|
118 |
+
display: inline-flex;
|
119 |
+
align-items: center;
|
120 |
+
padding-right: 0 !important; }
|
121 |
+
|
122 |
+
.ts-wrapper.plugin-remove_button .item .remove {
|
123 |
+
color: inherit;
|
124 |
+
text-decoration: none;
|
125 |
+
vertical-align: middle;
|
126 |
+
display: inline-block;
|
127 |
+
padding: 2px 6px;
|
128 |
+
border-left: 1px solid #d0d0d0;
|
129 |
+
border-radius: 0 2px 2px 0;
|
130 |
+
box-sizing: border-box;
|
131 |
+
margin-left: 6px; }
|
132 |
+
|
133 |
+
.ts-wrapper.plugin-remove_button .item .remove:hover {
|
134 |
+
background: rgba(0, 0, 0, 0.05); }
|
135 |
+
|
136 |
+
.ts-wrapper.plugin-remove_button .item.active .remove {
|
137 |
+
border-left-color: #cacaca; }
|
138 |
+
|
139 |
+
.ts-wrapper.plugin-remove_button.disabled .item .remove:hover {
|
140 |
+
background: none; }
|
141 |
+
|
142 |
+
.ts-wrapper.plugin-remove_button.disabled .item .remove {
|
143 |
+
border-left-color: white; }
|
144 |
+
|
145 |
+
.ts-wrapper.plugin-remove_button .remove-single {
|
146 |
+
position: absolute;
|
147 |
+
right: 0;
|
148 |
+
top: 0;
|
149 |
+
font-size: 23px; }
|
150 |
+
|
151 |
+
.ts-wrapper {
|
152 |
+
position: relative; }
|
153 |
+
|
154 |
+
.ts-dropdown,
|
155 |
+
.ts-control,
|
156 |
+
.ts-control input {
|
157 |
+
color: #303030;
|
158 |
+
font-family: inherit;
|
159 |
+
font-size: 13px;
|
160 |
+
line-height: 18px;
|
161 |
+
font-smoothing: inherit; }
|
162 |
+
|
163 |
+
.ts-control,
|
164 |
+
.ts-wrapper.single.input-active .ts-control {
|
165 |
+
background: #fff;
|
166 |
+
cursor: text; }
|
167 |
+
|
168 |
+
.ts-control {
|
169 |
+
border: 1px solid #d0d0d0;
|
170 |
+
padding: 8px 8px;
|
171 |
+
width: 100%;
|
172 |
+
overflow: hidden;
|
173 |
+
position: relative;
|
174 |
+
z-index: 1;
|
175 |
+
box-sizing: border-box;
|
176 |
+
box-shadow: none;
|
177 |
+
border-radius: 3px;
|
178 |
+
display: flex;
|
179 |
+
flex-wrap: wrap; }
|
180 |
+
.ts-wrapper.multi.has-items .ts-control {
|
181 |
+
padding: calc( 8px - 2px - 0) 8px calc( 8px - 2px - 3px - 0); }
|
182 |
+
.full .ts-control {
|
183 |
+
background-color: #fff; }
|
184 |
+
.disabled .ts-control,
|
185 |
+
.disabled .ts-control * {
|
186 |
+
cursor: default !important; }
|
187 |
+
.focus .ts-control {
|
188 |
+
box-shadow: none; }
|
189 |
+
.ts-control > * {
|
190 |
+
vertical-align: baseline;
|
191 |
+
display: inline-block; }
|
192 |
+
.ts-wrapper.multi .ts-control > div {
|
193 |
+
cursor: pointer;
|
194 |
+
margin: 0 3px 3px 0;
|
195 |
+
padding: 2px 6px;
|
196 |
+
background: #f2f2f2;
|
197 |
+
color: #303030;
|
198 |
+
border: 0 solid #d0d0d0; }
|
199 |
+
.ts-wrapper.multi .ts-control > div.active {
|
200 |
+
background: #e8e8e8;
|
201 |
+
color: #303030;
|
202 |
+
border: 0 solid #cacaca; }
|
203 |
+
.ts-wrapper.multi.disabled .ts-control > div, .ts-wrapper.multi.disabled .ts-control > div.active {
|
204 |
+
color: #7d7c7c;
|
205 |
+
background: white;
|
206 |
+
border: 0 solid white; }
|
207 |
+
.ts-control > input {
|
208 |
+
flex: 1 1 auto;
|
209 |
+
min-width: 7rem;
|
210 |
+
display: inline-block !important;
|
211 |
+
padding: 0 !important;
|
212 |
+
min-height: 0 !important;
|
213 |
+
max-height: none !important;
|
214 |
+
max-width: 100% !important;
|
215 |
+
margin: 0 !important;
|
216 |
+
text-indent: 0 !important;
|
217 |
+
border: 0 none !important;
|
218 |
+
background: none !important;
|
219 |
+
line-height: inherit !important;
|
220 |
+
-webkit-user-select: auto !important;
|
221 |
+
-moz-user-select: auto !important;
|
222 |
+
-ms-user-select: auto !important;
|
223 |
+
user-select: auto !important;
|
224 |
+
box-shadow: none !important; }
|
225 |
+
.ts-control > input::-ms-clear {
|
226 |
+
display: none; }
|
227 |
+
.ts-control > input:focus {
|
228 |
+
outline: none !important; }
|
229 |
+
.has-items .ts-control > input {
|
230 |
+
margin: 0 4px !important; }
|
231 |
+
.ts-control.rtl {
|
232 |
+
text-align: right; }
|
233 |
+
.ts-control.rtl.single .ts-control:after {
|
234 |
+
left: 15px;
|
235 |
+
right: auto; }
|
236 |
+
.ts-control.rtl .ts-control > input {
|
237 |
+
margin: 0 4px 0 -2px !important; }
|
238 |
+
.disabled .ts-control {
|
239 |
+
opacity: 0.5;
|
240 |
+
background-color: #fafafa; }
|
241 |
+
.input-hidden .ts-control > input {
|
242 |
+
opacity: 0;
|
243 |
+
position: absolute;
|
244 |
+
left: -10000px; }
|
245 |
+
|
246 |
+
.ts-dropdown {
|
247 |
+
position: absolute;
|
248 |
+
top: 100%;
|
249 |
+
left: 0;
|
250 |
+
width: 100%;
|
251 |
+
z-index: 10;
|
252 |
+
border: 1px solid #d0d0d0;
|
253 |
+
background: #fff;
|
254 |
+
margin: 0.25rem 0 0 0;
|
255 |
+
border-top: 0 none;
|
256 |
+
box-sizing: border-box;
|
257 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
258 |
+
border-radius: 0 0 3px 3px; }
|
259 |
+
.ts-dropdown [data-selectable] {
|
260 |
+
cursor: pointer;
|
261 |
+
overflow: hidden; }
|
262 |
+
.ts-dropdown [data-selectable] .highlight {
|
263 |
+
background: rgba(125, 168, 208, 0.2);
|
264 |
+
border-radius: 1px; }
|
265 |
+
.ts-dropdown .option,
|
266 |
+
.ts-dropdown .optgroup-header,
|
267 |
+
.ts-dropdown .no-results,
|
268 |
+
.ts-dropdown .create {
|
269 |
+
padding: 5px 8px; }
|
270 |
+
.ts-dropdown .option, .ts-dropdown [data-disabled], .ts-dropdown [data-disabled] [data-selectable].option {
|
271 |
+
cursor: inherit;
|
272 |
+
opacity: 0.5; }
|
273 |
+
.ts-dropdown [data-selectable].option {
|
274 |
+
opacity: 1;
|
275 |
+
cursor: pointer; }
|
276 |
+
.ts-dropdown .optgroup:first-child .optgroup-header {
|
277 |
+
border-top: 0 none; }
|
278 |
+
.ts-dropdown .optgroup-header {
|
279 |
+
color: #303030;
|
280 |
+
background: #fff;
|
281 |
+
cursor: default; }
|
282 |
+
.ts-dropdown .create:hover,
|
283 |
+
.ts-dropdown .option:hover,
|
284 |
+
.ts-dropdown .active {
|
285 |
+
background-color: #f5fafd;
|
286 |
+
color: #495c68; }
|
287 |
+
.ts-dropdown .create:hover.create,
|
288 |
+
.ts-dropdown .option:hover.create,
|
289 |
+
.ts-dropdown .active.create {
|
290 |
+
color: #495c68; }
|
291 |
+
.ts-dropdown .create {
|
292 |
+
color: rgba(48, 48, 48, 0.5); }
|
293 |
+
.ts-dropdown .spinner {
|
294 |
+
display: inline-block;
|
295 |
+
width: 30px;
|
296 |
+
height: 30px;
|
297 |
+
margin: 5px 8px; }
|
298 |
+
.ts-dropdown .spinner:after {
|
299 |
+
content: " ";
|
300 |
+
display: block;
|
301 |
+
width: 24px;
|
302 |
+
height: 24px;
|
303 |
+
margin: 3px;
|
304 |
+
border-radius: 50%;
|
305 |
+
border: 5px solid #d0d0d0;
|
306 |
+
border-color: #d0d0d0 transparent #d0d0d0 transparent;
|
307 |
+
animation: lds-dual-ring 1.2s linear infinite; }
|
308 |
+
|
309 |
+
@keyframes lds-dual-ring {
|
310 |
+
0% {
|
311 |
+
transform: rotate(0deg); }
|
312 |
+
100% {
|
313 |
+
transform: rotate(360deg); } }
|
314 |
+
|
315 |
+
.ts-dropdown-content {
|
316 |
+
overflow-y: auto;
|
317 |
+
overflow-x: hidden;
|
318 |
+
max-height: 200px;
|
319 |
+
overflow-scrolling: touch;
|
320 |
+
scroll-behavior: smooth; }
|
321 |
+
|
322 |
+
.ts-hidden-accessible {
|
323 |
+
border: 0 !important;
|
324 |
+
clip: rect(0 0 0 0) !important;
|
325 |
+
-webkit-clip-path: inset(50%) !important;
|
326 |
+
clip-path: inset(50%) !important;
|
327 |
+
height: 1px !important;
|
328 |
+
overflow: hidden !important;
|
329 |
+
padding: 0 !important;
|
330 |
+
position: absolute !important;
|
331 |
+
width: 1px !important;
|
332 |
+
white-space: nowrap !important; }
|
333 |
+
|
334 |
+
/*# sourceMappingURL=tom-select.css.map */
|
streamlit_app/lib/vis-9.1.2/vis-network.css
ADDED
The diff for this file is too large to render.
See raw diff
|
|
streamlit_app/lib/vis-9.1.2/vis-network.min.js
ADDED
The diff for this file is too large to render.
See raw diff
|
|
streamlit_app/tagged_question_parser.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
def parse_tagged_content(tagged_text):
|
4 |
+
# Split the text into tokens including tags and text
|
5 |
+
tokens = re.split(r'(</?[^>]+>)', tagged_text)
|
6 |
+
stack = [] # Stack to hold tags and their content
|
7 |
+
results = [] # Final results list
|
8 |
+
|
9 |
+
for token in tokens:
|
10 |
+
stripped_token = token.strip()
|
11 |
+
if stripped_token.startswith('<') and not stripped_token.startswith('</'):
|
12 |
+
# If it's an opening tag, push an empty list to the stack for this tag
|
13 |
+
stack.append((stripped_token, []))
|
14 |
+
elif stripped_token.startswith('</'):
|
15 |
+
# When closing tag encountered, pop the stack
|
16 |
+
tag, content = stack.pop()
|
17 |
+
if tag[1:-1] != stripped_token[2:-1]:
|
18 |
+
raise ValueError("Mismatched tags found")
|
19 |
+
|
20 |
+
# Filter out empty strings and reduce single-element lists
|
21 |
+
filtered_content = [item for item in content if isinstance(item, tuple) or item.strip()]
|
22 |
+
|
23 |
+
# If the content is not empty and there's another tag on the stack, append to the last tag's content
|
24 |
+
if stack:
|
25 |
+
stack[-1][1].append((tag, filtered_content if len(filtered_content) > 1 else filtered_content[0]))
|
26 |
+
else:
|
27 |
+
# If the stack is empty, we're back at the root level, add to results
|
28 |
+
results.append((tag, filtered_content if len(filtered_content) > 1 else filtered_content[0]))
|
29 |
+
elif stripped_token:
|
30 |
+
# Non-tag text and nested tags are collected into the current tag's list
|
31 |
+
if stack:
|
32 |
+
stack[-1][1].append(stripped_token)
|
33 |
+
|
34 |
+
return results
|
35 |
+
|
36 |
+
# Example use case
|
37 |
+
tagged_text = "<qt>Which</qt> <t>film</t> <p>directed by</p> <o><t>director</t> <p>die in</p> <o>2016</o></o> <cc>and</cc> <p>starring</p> <o>Julia Roberts</o> <o>Richard Gere</o>"
|
38 |
+
parsed_output = parse_tagged_content(tagged_text)
|
39 |
+
print(parsed_output)
|