khaerens commited on
Commit
efad059
1 Parent(s): b9584cf

removed requirements.txt hack

Browse files
.vscode/settings.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "workbench.colorCustomizations": {
3
- "activityBar.background": "#09323E",
4
- "titleBar.activeBackground": "#0C4656",
5
- "titleBar.activeForeground": "#F6FCFE"
6
- }
7
- }
 
 
 
 
 
 
 
 
__pycache__/rebel.cpython-310.pyc ADDED
Binary file (3.89 kB). View file
 
__pycache__/utils.cpython-310.pyc ADDED
Binary file (390 Bytes). View file
 
app.py CHANGED
@@ -1,12 +1,5 @@
1
- from logging import disable
2
- from pkg_resources import EggMetadata
3
  import streamlit as st
4
  import streamlit.components.v1 as components
5
- import networkx as nx
6
- import matplotlib.pyplot as plt
7
- from pyvis.network import Network
8
- from streamlit.state.session_state import SessionState
9
- from streamlit.type_util import Key
10
  import rebel
11
  import wikipedia
12
  from utils import clip_text
@@ -16,22 +9,22 @@ import os
16
  MAX_TOPICS = 3
17
 
18
  wiki_state_variables = {
19
- 'has_run_wiki':False,
20
  'wiki_suggestions': [],
21
- 'wiki_text' : [],
22
- 'nodes':[],
23
- "topics":[],
24
- "html_wiki":""
25
  }
26
 
27
  free_text_state_variables = {
28
- 'has_run_free':False,
29
- "html_free":""
30
-
31
  }
32
 
33
  BUTTON_COLUMS = 4
34
 
 
35
  def wiki_init_state_variables():
36
  for k in free_text_state_variables.keys():
37
  if k in st.session_state:
@@ -41,8 +34,10 @@ def wiki_init_state_variables():
41
  if k not in st.session_state:
42
  st.session_state[k] = v
43
 
 
44
  def wiki_generate_graph():
45
- st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
 
46
 
47
  if 'wiki_text' not in st.session_state:
48
  return
@@ -52,20 +47,23 @@ def wiki_generate_graph():
52
  with st.spinner(text="Generating graph..."):
53
  texts = st.session_state['wiki_text']
54
  st.session_state['nodes'] = []
55
- nodes = rebel.generate_knowledge_graph(texts, st.session_state["GRAPH_FILENAME"])
56
- HtmlFile = open(st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
 
 
57
  source_code = HtmlFile.read()
58
  st.session_state["html_wiki"] = source_code
59
  os.remove(st.session_state["GRAPH_FILENAME"])
60
  for n in nodes:
61
  n = n.lower()
62
  if n not in st.session_state['topics']:
63
- possible_topics = wikipedia.search(n, results = 2)
64
  st.session_state['nodes'].extend(possible_topics)
65
  st.session_state['nodes'] = list(set(st.session_state['nodes']))
66
  st.session_state['has_run_wiki'] = True
67
  st.success('Done!')
68
 
 
69
  def wiki_show_suggestion():
70
  st.session_state['wiki_suggestions'] = []
71
  with st.spinner(text="fetching wiki topics..."):
@@ -74,7 +72,9 @@ def wiki_show_suggestion():
74
  if (text is not None) and (text != ""):
75
  subjects = text.split(",")[:MAX_TOPICS]
76
  for subj in subjects:
77
- st.session_state['wiki_suggestions'] += wikipedia.search(subj, results = 3)
 
 
78
 
79
  def wiki_show_text(page_title):
80
  with st.spinner(text="fetching wiki page..."):
@@ -92,6 +92,7 @@ def wiki_show_text(page_title):
92
  except wikipedia.WikipediaException:
93
  st.session_state['wiki_suggestions'].remove(page_title)
94
 
 
95
  def wiki_add_text(term):
96
  if len(st.session_state['wiki_text']) > MAX_TOPICS:
97
  return
@@ -113,16 +114,20 @@ def wiki_add_text(term):
113
  print(e)
114
  st.session_state['nodes'].remove(term)
115
 
 
116
  def wiki_reset_session():
117
  for k in wiki_state_variables:
118
  del st.session_state[k]
119
 
 
120
  def free_reset_session():
121
  for k in free_text_state_variables:
122
  del st.session_state[k]
123
 
 
124
  def free_text_generate():
125
- st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
 
126
  text = st.session_state['free_text'][0:100]
127
  rebel.generate_knowledge_graph([text], st.session_state["GRAPH_FILENAME"])
128
  HtmlFile = open(st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
@@ -131,9 +136,13 @@ def free_text_generate():
131
  os.remove(st.session_state["GRAPH_FILENAME"])
132
  st.session_state['has_run_free'] = True
133
 
 
134
  def free_text_layout():
135
- st.text_area("Free text", key="free_text", height=5, value="Tardigrades, known colloquially as water bears or moss piglets, are a phylum of eight-legged segmented micro-animals.")
136
- st.button("Generate", on_click=free_text_generate, key="free_text_generate")
 
 
 
137
 
138
  def free_test_init_state_variables():
139
  for k in wiki_state_variables.keys():
@@ -144,47 +153,51 @@ def free_test_init_state_variables():
144
  if k not in st.session_state:
145
  st.session_state[k] = v
146
 
 
147
  st.title('RE:Belle')
148
  st.markdown(
149
- """
150
  ### Building Beautiful Knowledge Graphs With REBEL
151
  """)
152
  st.selectbox(
153
- 'input method',
154
- ('wikipedia', 'free text'), key="input_method")
155
 
156
 
157
  def show_wiki_hub_page():
158
  st.sidebar.button("Reset", on_click=wiki_reset_session, key="reset_key")
159
 
160
  st.sidebar.markdown(
161
- """
162
  ## How To Create a Graph:
163
  - Enter wikipedia search terms, separated by comma's
164
  - Choose one or more of the suggested topics (max 3)
165
  - Click generate!
166
  """
167
- )
168
  cols = st.columns([8, 1])
169
  with cols[0]:
170
- st.text_input("wikipedia search term", on_change=wiki_show_suggestion, key="text", value="graphs, are, awesome")
 
171
  with cols[1]:
172
  st.text('')
173
  st.text('')
174
- st.button("Search", on_click=wiki_show_suggestion, key="show_suggestion_key")
 
175
 
176
  if len(st.session_state['wiki_suggestions']) != 0:
177
  num_buttons = len(st.session_state['wiki_suggestions'])
178
  num_cols = num_buttons if 0 < num_buttons < BUTTON_COLUMS else BUTTON_COLUMS
179
- columns = st.columns([1] * num_cols )
180
  for q in range(1 + num_buttons//num_cols):
181
  for i, (c, s) in enumerate(zip(columns, st.session_state['wiki_suggestions'][q*num_cols: (q+1)*num_cols])):
182
  with c:
183
- st.button(s, on_click=wiki_show_text, args=(s,), key=str(i)+s+"wiki_suggestion")
 
184
 
185
  if len(st.session_state['wiki_text']) != 0:
186
  for i, t in enumerate(st.session_state['wiki_text']):
187
- new_expander = st.expander(label=t[:30] + "...", expanded=(i==0))
188
  with new_expander:
189
  st.markdown(t)
190
 
@@ -209,23 +222,27 @@ def show_wiki_hub_page():
209
  for q in range(1 + num_buttons//num_cols):
210
  for i, (c, s) in enumerate(zip(columns, st.session_state["nodes"][q*num_cols: (q+1)*num_cols])):
211
  with c:
212
- st.button(s, on_click=wiki_add_text, args=(s,), key=str(i)+s)
 
 
213
 
214
  def show_free_text_hub_page():
215
- st.sidebar.button("Reset", on_click=free_reset_session, key="free_reset_key")
 
216
  st.sidebar.markdown(
217
- """
218
  ## How To Create a Graph:
219
  - Enter a text you'd like to see as a graph.
220
  - Click generate!
221
  """
222
- )
223
 
224
  free_text_layout()
225
 
226
  if st.session_state['has_run_free']:
227
  components.html(st.session_state["html_free"], width=720, height=600)
228
 
 
229
  if st.session_state['input_method'] == "wikipedia":
230
  wiki_init_state_variables()
231
  show_wiki_hub_page()
@@ -234,9 +251,8 @@ else:
234
  show_free_text_hub_page()
235
 
236
 
237
-
238
  st.sidebar.markdown(
239
- """
240
  ## What This Is And Why We Built it
241
 
242
  This space shows how a transformer network can be used to convert *human* text into a computer-queryable format: a **knowledge graph**. Knowledge graphs are graphs where each node (or *vertex* if you're fancy) represent a concept/person/thing and each edge the link between those concepts. If you'd like to know more, you can read [this blogpost](https://www.ml6.eu/knowhow/knowledge-graphs-an-introduction-and-business-applications).
@@ -248,9 +264,9 @@ There is one problem though: building knowledge graphs from scratch is a time-co
248
  )
249
 
250
  st.sidebar.markdown(
251
- """
252
  *Credits for the REBEL model go out to Pere-Lluís Huguet Cabot and Roberto Navigli.
253
  The code can be found [here](https://github.com/Babelscape/rebel),
254
  and the original paper [here](https://github.com/Babelscape/rebel/blob/main/docs/EMNLP_2021_REBEL__Camera_Ready_.pdf)*
255
  """
256
- )
 
 
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
 
 
 
 
 
3
  import rebel
4
  import wikipedia
5
  from utils import clip_text
 
9
  MAX_TOPICS = 3
10
 
11
  wiki_state_variables = {
12
+ 'has_run_wiki': False,
13
  'wiki_suggestions': [],
14
+ 'wiki_text': [],
15
+ 'nodes': [],
16
+ "topics": [],
17
+ "html_wiki": ""
18
  }
19
 
20
  free_text_state_variables = {
21
+ 'has_run_free': False,
22
+ "html_free": ""
 
23
  }
24
 
25
  BUTTON_COLUMS = 4
26
 
27
+
28
  def wiki_init_state_variables():
29
  for k in free_text_state_variables.keys():
30
  if k in st.session_state:
 
34
  if k not in st.session_state:
35
  st.session_state[k] = v
36
 
37
+
38
  def wiki_generate_graph():
39
+ st.session_state["GRAPH_FILENAME"] = str(
40
+ dt.now().timestamp()*1000) + ".html"
41
 
42
  if 'wiki_text' not in st.session_state:
43
  return
 
47
  with st.spinner(text="Generating graph..."):
48
  texts = st.session_state['wiki_text']
49
  st.session_state['nodes'] = []
50
+ nodes = rebel.generate_knowledge_graph(
51
+ texts, st.session_state["GRAPH_FILENAME"])
52
+ HtmlFile = open(
53
+ st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
54
  source_code = HtmlFile.read()
55
  st.session_state["html_wiki"] = source_code
56
  os.remove(st.session_state["GRAPH_FILENAME"])
57
  for n in nodes:
58
  n = n.lower()
59
  if n not in st.session_state['topics']:
60
+ possible_topics = wikipedia.search(n, results=2)
61
  st.session_state['nodes'].extend(possible_topics)
62
  st.session_state['nodes'] = list(set(st.session_state['nodes']))
63
  st.session_state['has_run_wiki'] = True
64
  st.success('Done!')
65
 
66
+
67
  def wiki_show_suggestion():
68
  st.session_state['wiki_suggestions'] = []
69
  with st.spinner(text="fetching wiki topics..."):
 
72
  if (text is not None) and (text != ""):
73
  subjects = text.split(",")[:MAX_TOPICS]
74
  for subj in subjects:
75
+ st.session_state['wiki_suggestions'] += wikipedia.search(
76
+ subj, results=3)
77
+
78
 
79
  def wiki_show_text(page_title):
80
  with st.spinner(text="fetching wiki page..."):
 
92
  except wikipedia.WikipediaException:
93
  st.session_state['wiki_suggestions'].remove(page_title)
94
 
95
+
96
  def wiki_add_text(term):
97
  if len(st.session_state['wiki_text']) > MAX_TOPICS:
98
  return
 
114
  print(e)
115
  st.session_state['nodes'].remove(term)
116
 
117
+
118
  def wiki_reset_session():
119
  for k in wiki_state_variables:
120
  del st.session_state[k]
121
 
122
+
123
  def free_reset_session():
124
  for k in free_text_state_variables:
125
  del st.session_state[k]
126
 
127
+
128
  def free_text_generate():
129
+ st.session_state["GRAPH_FILENAME"] = str(
130
+ dt.now().timestamp()*1000) + ".html"
131
  text = st.session_state['free_text'][0:100]
132
  rebel.generate_knowledge_graph([text], st.session_state["GRAPH_FILENAME"])
133
  HtmlFile = open(st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
 
136
  os.remove(st.session_state["GRAPH_FILENAME"])
137
  st.session_state['has_run_free'] = True
138
 
139
+
140
  def free_text_layout():
141
+ st.text_area("Free text", key="free_text", height=5,
142
+ value="Tardigrades, known colloquially as water bears or moss piglets, are a phylum of eight-legged segmented micro-animals.")
143
+ st.button("Generate", on_click=free_text_generate,
144
+ key="free_text_generate")
145
+
146
 
147
  def free_test_init_state_variables():
148
  for k in wiki_state_variables.keys():
 
153
  if k not in st.session_state:
154
  st.session_state[k] = v
155
 
156
+
157
  st.title('RE:Belle')
158
  st.markdown(
159
+ """
160
  ### Building Beautiful Knowledge Graphs With REBEL
161
  """)
162
  st.selectbox(
163
+ 'input method',
164
+ ('wikipedia', 'free text'), key="input_method")
165
 
166
 
167
  def show_wiki_hub_page():
168
  st.sidebar.button("Reset", on_click=wiki_reset_session, key="reset_key")
169
 
170
  st.sidebar.markdown(
171
+ """
172
  ## How To Create a Graph:
173
  - Enter wikipedia search terms, separated by comma's
174
  - Choose one or more of the suggested topics (max 3)
175
  - Click generate!
176
  """
177
+ )
178
  cols = st.columns([8, 1])
179
  with cols[0]:
180
+ st.text_input("wikipedia search term", on_change=wiki_show_suggestion,
181
+ key="text", value="graphs, are, awesome")
182
  with cols[1]:
183
  st.text('')
184
  st.text('')
185
+ st.button("Search", on_click=wiki_show_suggestion,
186
+ key="show_suggestion_key")
187
 
188
  if len(st.session_state['wiki_suggestions']) != 0:
189
  num_buttons = len(st.session_state['wiki_suggestions'])
190
  num_cols = num_buttons if 0 < num_buttons < BUTTON_COLUMS else BUTTON_COLUMS
191
+ columns = st.columns([1] * num_cols)
192
  for q in range(1 + num_buttons//num_cols):
193
  for i, (c, s) in enumerate(zip(columns, st.session_state['wiki_suggestions'][q*num_cols: (q+1)*num_cols])):
194
  with c:
195
+ st.button(s, on_click=wiki_show_text, args=(
196
+ s,), key=str(i)+s+"wiki_suggestion")
197
 
198
  if len(st.session_state['wiki_text']) != 0:
199
  for i, t in enumerate(st.session_state['wiki_text']):
200
+ new_expander = st.expander(label=t[:30] + "...", expanded=(i == 0))
201
  with new_expander:
202
  st.markdown(t)
203
 
 
222
  for q in range(1 + num_buttons//num_cols):
223
  for i, (c, s) in enumerate(zip(columns, st.session_state["nodes"][q*num_cols: (q+1)*num_cols])):
224
  with c:
225
+ st.button(s, on_click=wiki_add_text,
226
+ args=(s,), key=str(i)+s)
227
+
228
 
229
  def show_free_text_hub_page():
230
+ st.sidebar.button("Reset", on_click=free_reset_session,
231
+ key="free_reset_key")
232
  st.sidebar.markdown(
233
+ """
234
  ## How To Create a Graph:
235
  - Enter a text you'd like to see as a graph.
236
  - Click generate!
237
  """
238
+ )
239
 
240
  free_text_layout()
241
 
242
  if st.session_state['has_run_free']:
243
  components.html(st.session_state["html_free"], width=720, height=600)
244
 
245
+
246
  if st.session_state['input_method'] == "wikipedia":
247
  wiki_init_state_variables()
248
  show_wiki_hub_page()
 
251
  show_free_text_hub_page()
252
 
253
 
 
254
  st.sidebar.markdown(
255
+ """
256
  ## What This Is And Why We Built it
257
 
258
  This space shows how a transformer network can be used to convert *human* text into a computer-queryable format: a **knowledge graph**. Knowledge graphs are graphs where each node (or *vertex* if you're fancy) represent a concept/person/thing and each edge the link between those concepts. If you'd like to know more, you can read [this blogpost](https://www.ml6.eu/knowhow/knowledge-graphs-an-introduction-and-business-applications).
 
264
  )
265
 
266
  st.sidebar.markdown(
267
+ """
268
  *Credits for the REBEL model go out to Pere-Lluís Huguet Cabot and Roberto Navigli.
269
  The code can be found [here](https://github.com/Babelscape/rebel),
270
  and the original paper [here](https://github.com/Babelscape/rebel/blob/main/docs/EMNLP_2021_REBEL__Camera_Ready_.pdf)*
271
  """
272
+ )
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
+ }
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),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>&hellip;</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}">&times;</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+'">&times;</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:"&times;",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
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 */
lib/vis-9.1.2/vis-network.css ADDED
The diff for this file is too large to render. See raw diff
 
lib/vis-9.1.2/vis-network.min.js ADDED
The diff for this file is too large to render. See raw diff
 
rebel.py CHANGED
@@ -3,7 +3,6 @@ from transformers import pipeline
3
  from pyvis.network import Network
4
  from functools import lru_cache
5
  import spacy
6
- from spacy import displacy
7
 
8
 
9
  DEFAULT_LABEL_COLORS = {
@@ -27,17 +26,18 @@ DEFAULT_LABEL_COLORS = {
27
  "PERCENT": "#e4e7d2",
28
  }
29
 
 
30
  def generate_knowledge_graph(texts: List[str], filename: str):
31
  nlp = spacy.load("en_core_web_sm")
32
  doc = nlp("\n".join(texts).lower())
33
  NERs = [ent.text for ent in doc.ents]
34
- NER_types = [ent.label_ for ent in doc.ents]
35
 
36
  triplets = []
37
  for triplet in texts:
38
  triplets.extend(generate_partial_graph(triplet))
39
- heads = [ t["head"].lower() for t in triplets]
40
- tails = [ t["tail"].lower() for t in triplets]
41
 
42
  nodes = list(set(heads + tails))
43
  net = Network(directed=True, width="700px", height="700px")
@@ -57,7 +57,7 @@ def generate_knowledge_graph(texts: List[str], filename: str):
57
  net.add_node(n, shape="circle")
58
 
59
  unique_triplets = set()
60
- stringify_trip = lambda x : x["tail"] + x["head"] + x["type"].lower()
61
  for triplet in triplets:
62
  if stringify_trip(triplet) not in unique_triplets:
63
  net.add_edge(triplet["head"].lower(), triplet["tail"].lower(),
@@ -78,8 +78,22 @@ def generate_knowledge_graph(texts: List[str], filename: str):
78
 
79
  @lru_cache(maxsize=16)
80
  def generate_partial_graph(text: str):
81
- triplet_extractor = pipeline('text2text-generation', model='Babelscape/rebel-large', tokenizer='Babelscape/rebel-large')
82
- a = triplet_extractor(text, return_tensors=True, return_text=False)[0]["generated_token_ids"]["output_ids"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  extracted_text = triplet_extractor.tokenizer.batch_decode(a)
84
  extracted_triplets = extract_triplets(extracted_text[0])
85
  return extracted_triplets
@@ -97,13 +111,15 @@ def extract_triplets(text):
97
  if token == "<triplet>":
98
  current = 't'
99
  if relation != '':
100
- triplets.append({'head': subject.strip(), 'type': relation.strip(),'tail': object_.strip()})
 
101
  relation = ''
102
  subject = ''
103
  elif token == "<subj>":
104
  current = 's'
105
  if relation != '':
106
- triplets.append({'head': subject.strip(), 'type': relation.strip(),'tail': object_.strip()})
 
107
  object_ = ''
108
  elif token == "<obj>":
109
  current = 'o'
@@ -116,7 +132,12 @@ def extract_triplets(text):
116
  elif current == 'o':
117
  relation += ' ' + token
118
  if subject != '' and relation != '' and object_ != '':
119
- triplets.append({'head': subject.strip(), 'type': relation.strip(),'tail': object_.strip()})
 
120
 
121
  return triplets
122
 
 
 
 
 
 
3
  from pyvis.network import Network
4
  from functools import lru_cache
5
  import spacy
 
6
 
7
 
8
  DEFAULT_LABEL_COLORS = {
 
26
  "PERCENT": "#e4e7d2",
27
  }
28
 
29
+
30
  def generate_knowledge_graph(texts: List[str], filename: str):
31
  nlp = spacy.load("en_core_web_sm")
32
  doc = nlp("\n".join(texts).lower())
33
  NERs = [ent.text for ent in doc.ents]
34
+ NER_types = [ent.label_ for ent in doc.ents]
35
 
36
  triplets = []
37
  for triplet in texts:
38
  triplets.extend(generate_partial_graph(triplet))
39
+ heads = [t["head"].lower() for t in triplets]
40
+ tails = [t["tail"].lower() for t in triplets]
41
 
42
  nodes = list(set(heads + tails))
43
  net = Network(directed=True, width="700px", height="700px")
 
57
  net.add_node(n, shape="circle")
58
 
59
  unique_triplets = set()
60
+ def stringify_trip(x): return x["tail"] + x["head"] + x["type"].lower()
61
  for triplet in triplets:
62
  if stringify_trip(triplet) not in unique_triplets:
63
  net.add_edge(triplet["head"].lower(), triplet["tail"].lower(),
 
78
 
79
  @lru_cache(maxsize=16)
80
  def generate_partial_graph(text: str):
81
+ triplet_extractor = pipeline(
82
+ 'text2text-generation',
83
+ model='Babelscape/rebel-large',
84
+ tokenizer='Babelscape/rebel-large'
85
+ )
86
+
87
+ triples = triplet_extractor(
88
+ text,
89
+ return_tensors=True,
90
+ return_text=False)
91
+
92
+ if len(triples) == 0:
93
+ return []
94
+
95
+ a = [triples[0]["generated_token_ids"]]
96
+
97
  extracted_text = triplet_extractor.tokenizer.batch_decode(a)
98
  extracted_triplets = extract_triplets(extracted_text[0])
99
  return extracted_triplets
 
111
  if token == "<triplet>":
112
  current = 't'
113
  if relation != '':
114
+ triplets.append(
115
+ {'head': subject.strip(), 'type': relation.strip(), 'tail': object_.strip()})
116
  relation = ''
117
  subject = ''
118
  elif token == "<subj>":
119
  current = 's'
120
  if relation != '':
121
+ triplets.append(
122
+ {'head': subject.strip(), 'type': relation.strip(), 'tail': object_.strip()})
123
  object_ = ''
124
  elif token == "<obj>":
125
  current = 'o'
 
132
  elif current == 'o':
133
  relation += ' ' + token
134
  if subject != '' and relation != '' and object_ != '':
135
+ triplets.append(
136
+ {'head': subject.strip(), 'type': relation.strip(), 'tail': object_.strip()})
137
 
138
  return triplets
139
 
140
+
141
+ if __name__ == "__main__":
142
+ generate_knowledge_graph(
143
+ ["The dog is happy", "The cat is sad"], "test.html")
requirements.txt CHANGED
@@ -1,124 +1,9 @@
1
- altair==4.2.0
2
- argon2-cffi==21.3.0
3
- argon2-cffi-bindings==21.2.0
4
- astor==0.8.1
5
- attrs==21.4.0
6
- backcall==0.2.0
7
- backports.zoneinfo==0.2.1
8
- base58==2.1.1
9
- beautifulsoup4==4.10.0
10
- bleach==4.1.0
11
- blinker==1.4
12
- blis==0.7.5
13
- cachetools==5.0.0
14
- catalogue==2.0.6
15
- certifi==2021.10.8
16
- cffi==1.15.0
17
- charset-normalizer==2.0.10
18
- click==7.1.2
19
- cycler==0.11.0
20
- cymem==2.0.6
21
- debugpy==1.5.1
22
- decorator==5.1.1
23
- defusedxml==0.7.1
24
- entrypoints==0.3
25
- filelock==3.4.2
26
- fonttools==4.28.5
27
- gitdb==4.0.9
28
- GitPython==3.1.26
29
- got==0.0.1
30
- huggingface-hub==0.2.1
31
- idna==3.3
32
- importlib-resources==5.4.0
33
- ipykernel==6.6.1
34
- ipython==7.31.0
35
- ipython-genutils==0.2.0
36
- ipywidgets==7.6.5
37
- jedi==0.18.1
38
- Jinja2==3.0.3
39
- joblib==1.1.0
40
- jsonpickle==2.0.0
41
- jsonschema==4.3.3
42
- jupyter-client==7.1.0
43
- jupyter-core==4.9.1
44
- jupyterlab-pygments==0.1.2
45
- jupyterlab-widgets==1.0.2
46
- kiwisolver==1.3.2
47
- langcodes==3.3.0
48
- MarkupSafe==2.0.1
49
- matplotlib==3.5.1
50
- matplotlib-inline==0.1.3
51
- mistune==0.8.4
52
- murmurhash==1.0.6
53
- nbclient==0.5.9
54
- nbconvert==6.4.0
55
- nbformat==5.1.3
56
- nest-asyncio==1.5.4
57
- networkx==2.6.3
58
- notebook==6.4.6
59
- numpy==1.22.0
60
- packaging==21.3
61
- pandas==1.3.5
62
- pandocfilters==1.5.0
63
- parso==0.8.3
64
- pathy==0.6.1
65
- pexpect==4.8.0
66
- pickleshare==0.7.5
67
- Pillow==9.0.0
68
- preshed==3.0.6
69
- prometheus-client==0.12.0
70
- prompt-toolkit==3.0.24
71
- protobuf==3.19.3
72
- ptyprocess==0.7.0
73
- pyarrow==6.0.1
74
- pycparser==2.21
75
- pydantic==1.8.2
76
- pydeck==0.7.1
77
- Pygments==2.11.2
78
- Pympler==1.0.1
79
- pyparsing==3.0.6
80
- pyrsistent==0.18.0
81
- python-dateutil==2.8.2
82
- pytz==2021.3
83
- pytz-deprecation-shim==0.1.0.post0
84
  pyvis==0.1.9
85
- PyYAML==6.0
86
- pyzmq==22.3.0
87
- regex==2021.11.10
88
- requests==2.27.1
89
- sacremoses==0.0.47
90
- Send2Trash==1.8.0
91
- six==1.16.0
92
- smart-open==5.2.1
93
- smmap==5.0.0
94
- soupsieve==2.3.1
95
- spacy==3.2.1
96
- spacy-legacy==3.0.8
97
- spacy-loggers==1.0.1
98
- srsly==2.4.2
99
- streamlit==1.3.1
100
- terminado==0.12.1
101
- testpath==0.5.0
102
- thinc==8.0.13
103
- tokenizers==0.10.3
104
- toml==0.10.2
105
- toolz==0.11.2
106
- torch==1.10.1
107
- tornado==6.1
108
- tqdm==4.62.3
109
- traitlets==5.1.1
110
- transformers==4.15.0
111
- typer==0.4.0
112
- typing-extensions==4.0.1
113
- tzdata==2021.5
114
- tzlocal==4.1
115
- urllib3==1.26.8
116
- validators==0.18.2
117
- wasabi==0.9.0
118
- watchdog==2.1.6
119
- wcwidth==0.2.5
120
- webencodings==0.5.1
121
- widgetsnbextension==3.5.2
122
- wikipedia==1.4.0
123
- zipp==3.7.0
124
  https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.2.0/en_core_web_sm-3.2.0.tar.gz#egg=en_core_web_sm
 
 
1
+ streamlit
2
+ matplotlib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  pyvis==0.1.9
4
+ networkx
5
+ transformers
6
+ spacy
7
+ wikipedia
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.2.0/en_core_web_sm-3.2.0.tar.gz#egg=en_core_web_sm
9
+ torch