diff --git a/MANIFEST.in b/MANIFEST.in index f297faf..5cdfb04 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ -recursive-include pyvis/templates *.html \ No newline at end of file +recursive-include pyvis/templates * +recursive-include pyvis/lib * diff --git a/README.md b/README.md index 7e79cb4..0245196 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ python setup.py install [jsonpickle](https://jsonpickle.github.io/) +### Test Dependencies +[selenium](https://www.selenium.dev/documentation/webdriver/) + +[numpy](https://numpy.org/install/) ## Quick Start The most basic use case of a pyvis instance is to create a Network object and invoke methods: diff --git a/notebooks/NetworkOfThrones.csv b/notebooks/NetworkOfThrones.csv new file mode 100644 index 0000000..0da0ae0 --- /dev/null +++ b/notebooks/NetworkOfThrones.csv @@ -0,0 +1,354 @@ +,Source,Target,Weight +0,Aemon,Grenn,5 +1,Aemon,Samwell,31 +2,Aerys,Jaime,18 +3,Aerys,Robert,6 +4,Aerys,Tyrion,5 +5,Aerys,Tywin,8 +6,Alliser,Mance,5 +7,Amory,Oberyn,5 +8,Arya,Anguy,11 +9,Arya,Beric,23 +10,Arya,Bran,9 +11,Arya,Brynden,6 +12,Arya,Cersei,5 +13,Arya,Gendry,43 +14,Arya,Gregor,7 +15,Arya,Jaime,11 +16,Arya,Joffrey,6 +17,Arya,Jon,7 +18,Arya,Rickon,8 +19,Arya,Robert,4 +20,Arya,Roose,5 +21,Arya,Sandor,46 +22,Arya,Thoros,18 +23,Arya,Tyrion,5 +24,Balon,Loras,4 +25,Belwas,Barristan,18 +26,Belwas,Illyrio,10 +27,Beric,Anguy,4 +28,Beric,Gendry,4 +29,Beric,Thoros,21 +30,Bran,Hodor,96 +31,Bran,Jojen,46 +32,Bran,Jon,12 +33,Bran,Luwin,4 +34,Bran,Meera,54 +35,Bran,Nan,14 +36,Bran,Rickon,35 +37,Bran,Samwell,11 +38,Bran,Theon,11 +39,Brienne,Loras,7 +40,Bronn,Gregor,5 +41,Bronn,Podrick,19 +42,Brynden,Brynden,7 +43,Brynden,Lothar,4 +44,Brynden,Walder,5 +45,Catelyn,Bran,4 +46,Catelyn,Brienne,7 +47,Catelyn,Brynden,8 +48,Catelyn,Cersei,4 +49,Catelyn,Edmure,16 +50,Catelyn,Hoster,9 +51,Catelyn,Jaime,19 +52,Catelyn,Jeyne,10 +53,Catelyn,Lysa,8 +54,Catelyn,Petyr,5 +55,Catelyn,Robb,43 +56,Catelyn,Roose,4 +57,Catelyn,Roslin,6 +58,Catelyn,Sansa,8 +59,Catelyn,Stannis,4 +60,Catelyn,Tyrion,5 +61,Catelyn,Walder,19 +62,Cersei,Brienne,5 +63,Cersei,Bronn,4 +64,Cersei,Elia,4 +65,Cersei,Gregor,6 +66,Cersei,Ilyn,7 +67,Cersei,Jaime,36 +68,Cersei,Joffrey,23 +69,Cersei,Meryn,10 +70,Cersei,Pycelle,4 +71,Cersei,Robert,16 +72,Cersei,Sandor,6 +73,Cersei,Shae,4 +74,Cersei,Tyrion,46 +75,Cersei,Varys,4 +76,Craster,Karl,6 +77,Daario,Drogo,4 +78,Daario,Irri,5 +79,Daenerys,Aegon,8 +80,Daenerys,Barristan,20 +81,Daenerys,Belwas,26 +82,Daenerys,Daario,14 +83,Daenerys,Drogo,18 +84,Daenerys,Irri,17 +85,Daenerys,Jorah,47 +86,Daenerys,Kraznys,10 +87,Daenerys,Missandei,26 +88,Daenerys,Rakharo,7 +89,Daenerys,Rhaegar,12 +90,Daenerys,Robert,5 +91,Daenerys,Viserys,8 +92,Daenerys,Worm,14 +93,Davos,Cressen,4 +94,Davos,Salladhor,16 +95,Eddard,Arya,18 +96,Eddard,Beric,8 +97,Eddard,Bran,15 +98,Eddard,Catelyn,5 +99,Eddard,Cersei,6 +100,Eddard,Jaime,6 +101,Eddard,Jon,8 +102,Eddard,Rickon,8 +103,Eddard,Robb,13 +104,Eddard,Robert,10 +105,Eddard,Sandor,5 +106,Eddard,Sansa,6 +107,Eddison,Grenn,8 +108,Edmure,Brynden,7 +109,Edmure,Lothar,4 +110,Edmure,Roslin,16 +111,Edmure,Walder,9 +112,Gendry,Thoros,7 +113,Gilly,Craster,17 +114,Gregor,Elia,9 +115,Gregor,Ilyn,7 +116,Gregor,Meryn,7 +117,Gregor,Oberyn,24 +118,Gregor,Sandor,12 +119,Hodor,Jojen,35 +120,Hodor,Meera,41 +121,Hoster,Edmure,9 +122,Irri,Drogo,7 +123,Jaime,Balon,6 +124,Jaime,Barristan,4 +125,Jaime,Brienne,88 +126,Jaime,Edmure,5 +127,Jaime,Elia,4 +128,Jaime,Gregor,6 +129,Jaime,Joffrey,15 +130,Jaime,Loras,16 +131,Jaime,Meryn,11 +132,Jaime,Qyburn,11 +133,Jaime,Renly,7 +134,Jaime,Robert,17 +135,Jaime,Stannis,5 +136,Jaime,Tommen,8 +137,Jaime,Tyrion,31 +138,Janos,Alliser,9 +139,Janos,Bowen,5 +140,Janos,Mance,4 +141,Joffrey,Gregor,5 +142,Joffrey,Ilyn,4 +143,Joffrey,Kevan,8 +144,Joffrey,Loras,7 +145,Joffrey,Margaery,28 +146,Joffrey,Meryn,5 +147,Joffrey,Myrcella,5 +148,Joffrey,Oberyn,4 +149,Joffrey,Sandor,14 +150,Joffrey,Stannis,10 +151,Joffrey,Tommen,9 +152,Joffrey,Tyrion,54 +153,Jojen,Meera,33 +154,Jojen,Samwell,11 +155,Jon,Aemon,30 +156,Jon,Alliser,15 +157,Jon,Craster,7 +158,Jon,Dalla,6 +159,Jon,Eddison,4 +160,Jon,Gilly,9 +161,Jon,Grenn,25 +162,Jon,Janos,8 +163,Jon,Mance,69 +164,Jon,Meera,4 +165,Jon,Melisandre,7 +166,Jon,Orell,6 +167,Jon,Qhorin,31 +168,Jon,Rattleshirt,20 +169,Jon,Robert,5 +170,Jon,Samwell,52 +171,Jon,Stannis,9 +172,Jon,Styr,16 +173,Jon,Theon,8 +174,Jon,Val,12 +175,Jon,Ygritte,54 +176,Jon Arryn,Lysa,5 +177,Jon Arryn,Robert,6 +178,Jorah,Barristan,11 +179,Jorah,Belwas,13 +180,Jorah,Daario,7 +181,Jorah,Drogo,6 +182,Kevan,Lancel,7 +183,Kevan,Varys,5 +184,Loras,Margaery,9 +185,Loras,Olenna,5 +186,Lothar,Roslin,4 +187,Luwin,Nan,4 +188,Lysa,Cersei,4 +189,Lysa,Hoster,6 +190,Lysa,Marillion,10 +191,Lysa,Petyr,29 +192,Lysa,Robert Arryn,9 +193,Lysa,Tyrion,5 +194,Lysa,Tywin,4 +195,Mance,Craster,11 +196,Mance,Dalla,8 +197,Mance,Gilly,7 +198,Mance,Qhorin,10 +199,Mance,Rattleshirt,9 +200,Mance,Styr,7 +201,Mance,Val,8 +202,Mance,Ygritte,12 +203,Meera,Samwell,7 +204,Melisandre,Davos,30 +205,Melisandre,Samwell,5 +206,Meryn,Ilyn,5 +207,Missandei,Irri,4 +208,Myrcella,Tommen,5 +209,Myrcella,Tyrion,4 +210,Oberyn,Ellaria,6 +211,Oberyn,Mace,6 +212,Podrick,Margaery,4 +213,Rattleshirt,Qhorin,6 +214,Renly,Loras,8 +215,Renly,Margaery,7 +216,Renly,Varys,4 +217,Rhaegar,Barristan,5 +218,Rhaegar,Elia,7 +219,Rhaegar,Jorah,5 +220,Rhaegar,Robert,6 +221,Rickard,Brynden,4 +222,Rickon,Theon,8 +223,Robb,Arya,15 +224,Robb,Balon,6 +225,Robb,Bran,23 +226,Robb,Brienne,6 +227,Robb,Brynden,17 +228,Robb,Edmure,32 +229,Robb,Hodor,5 +230,Robb,Jaime,15 +231,Robb,Jeyne,18 +232,Robb,Joffrey,10 +233,Robb,Jon,14 +234,Robb,Lothar,10 +235,Robb,Petyr,5 +236,Robb,Ramsay,4 +237,Robb,Rickard,7 +238,Robb,Rickon,15 +239,Robb,Roose,4 +240,Robb,Sansa,15 +241,Robb,Stannis,4 +242,Robb,Theon,11 +243,Robb,Tyrion,12 +244,Robb,Tywin,12 +245,Robb,Walder,26 +246,Robert,Aemon,4 +247,Robert,Barristan,5 +248,Robert,Renly,4 +249,Robert,Stannis,5 +250,Robert,Thoros,4 +251,Robert Arryn,Marillion,4 +252,Roose,Brienne,4 +253,Samwell,Bowen,6 +254,Samwell,Craster,34 +255,Samwell,Eddison,12 +256,Samwell,Gilly,36 +257,Samwell,Grenn,43 +258,Samwell,Janos,6 +259,Samwell,Mance,10 +260,Samwell,Qhorin,5 +261,Sandor,Beric,15 +262,Sandor,Gendry,5 +263,Sandor,Ilyn,4 +264,Sandor,Meryn,4 +265,Sandor,Robert,6 +266,Sandor,Thoros,10 +267,Sansa,Arya,22 +268,Sansa,Bran,10 +269,Sansa,Brienne,5 +270,Sansa,Cersei,16 +271,Sansa,Jaime,10 +272,Sansa,Joffrey,35 +273,Sansa,Jon,4 +274,Sansa,Kevan,5 +275,Sansa,Loras,14 +276,Sansa,Lysa,28 +277,Sansa,Margaery,36 +278,Sansa,Marillion,9 +279,Sansa,Myrcella,4 +280,Sansa,Olenna,7 +281,Sansa,Petyr,28 +282,Sansa,Podrick,8 +283,Sansa,Renly,4 +284,Sansa,Rickon,7 +285,Sansa,Robert,5 +286,Sansa,Robert Arryn,6 +287,Sansa,Sandor,6 +288,Sansa,Shae,8 +289,Sansa,Tyrion,77 +290,Shae,Chataya,4 +291,Shae,Varys,8 +292,Shireen,Davos,5 +293,Stannis,Aemon,4 +294,Stannis,Balon,4 +295,Stannis,Davos,32 +296,Stannis,Melisandre,20 +297,Stannis,Renly,15 +298,Stannis,Samwell,13 +299,Tommen,Margaery,5 +300,Tyrion,Balon,4 +301,Tyrion,Bronn,31 +302,Tyrion,Chataya,5 +303,Tyrion,Doran,5 +304,Tyrion,Elia,5 +305,Tyrion,Ellaria,4 +306,Tyrion,Gregor,22 +307,Tyrion,Ilyn,5 +308,Tyrion,Janos,5 +309,Tyrion,Kevan,11 +310,Tyrion,Loras,6 +311,Tyrion,Mace,9 +312,Tyrion,Margaery,7 +313,Tyrion,Meryn,5 +314,Tyrion,Oberyn,25 +315,Tyrion,Petyr,12 +316,Tyrion,Podrick,28 +317,Tyrion,Pycelle,11 +318,Tyrion,Renly,6 +319,Tyrion,Robert,9 +320,Tyrion,Sandor,4 +321,Tyrion,Shae,21 +322,Tyrion,Stannis,6 +323,Tyrion,Varys,18 +324,Tywin,Balon,5 +325,Tywin,Brynden,4 +326,Tywin,Cersei,16 +327,Tywin,Gregor,7 +328,Tywin,Jaime,13 +329,Tywin,Joffrey,13 +330,Tywin,Kevan,14 +331,Tywin,Mace,5 +332,Tywin,Oberyn,6 +333,Tywin,Petyr,4 +334,Tywin,Podrick,5 +335,Tywin,Pycelle,5 +336,Tywin,Robert,11 +337,Tywin,Stannis,15 +338,Tywin,Tommen,4 +339,Tywin,Tyrion,39 +340,Tywin,Val,4 +341,Tywin,Varys,6 +342,Tywin,Walder,4 +343,Val,Dalla,7 +344,Varys,Pycelle,4 +345,Viserys,Rhaegar,7 +346,Viserys,Tyrion,4 +347,Walder,Lothar,12 +348,Walder,Petyr,6 +349,Walder,Roslin,6 +350,Walton,Jaime,10 +351,Ygritte,Qhorin,7 +352,Ygritte,Rattleshirt,9 diff --git a/notebooks/example.html b/notebooks/example.html index 689d070..66f6e7c 100644 --- a/notebooks/example.html +++ b/notebooks/example.html @@ -1,108 +1,349 @@ - - - - -
-

-
- - - - - - - - -
- - - - + + + + + + + + + + + + + + + +
+

+
+ + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + \ No newline at end of file diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb index e93d81b..f6a71f3 100644 --- a/notebooks/example.ipynb +++ b/notebooks/example.ipynb @@ -3,41 +3,43 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ - "import sys\n", - "sys.path.append('../')\n", + "import sys,os\n", + "sys.path.insert(0,os.path.realpath('..'))\n", "from pyvis.network import Network" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Basic Example" - ] - }, { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ - "" + "" ] }, "execution_count": 2, @@ -46,7 +48,7 @@ } ], "source": [ - "g = Network(notebook=True)\n", + "g = Network(notebook=True, cdn_resources='remote')\n", "g.add_nodes(range(5))\n", "g.add_edges([\n", " (0, 2),\n", @@ -61,36 +63,51 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Dot File example" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": { - "scrolled": true + "scrolled": true, + "pycharm": { + "name": "#%%\n" + } }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Local cdn resources have problems on chrome/safari when used in jupyter-notebook. \n" + ] + }, { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 9, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -133,15 +150,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Basic NetworkX example" ] }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, + "execution_count": 4, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "import networkx as nx" @@ -149,42 +174,39 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 5, "metadata": { - "scrolled": false + "pycharm": { + "name": "#%%\n" + } }, "outputs": [ { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'edge_scaling' is not defined", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)", + "Input \u001B[0;32mIn [5]\u001B[0m, in \u001B[0;36m\u001B[0;34m()\u001B[0m\n\u001B[1;32m 1\u001B[0m nxg \u001B[38;5;241m=\u001B[39m nx\u001B[38;5;241m.\u001B[39mrandom_tree(\u001B[38;5;241m20\u001B[39m)\n\u001B[0;32m----> 2\u001B[0m \u001B[43mg\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfrom_nx\u001B[49m\u001B[43m(\u001B[49m\u001B[43mnxg\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 3\u001B[0m g\u001B[38;5;241m.\u001B[39mshow(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mexample2.html\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n", + "File \u001B[0;32m~/pyvis/pyvis/pyvis/network.py:699\u001B[0m, in \u001B[0;36mNetwork.from_nx\u001B[0;34m(self, nx_graph, node_size_transf, edge_weight_transf, default_node_size, default_edge_weight, show_edge_weights)\u001B[0m\n\u001B[1;32m 697\u001B[0m \u001B[38;5;66;03m# if user does not pass a 'weight' argument\u001B[39;00m\n\u001B[1;32m 698\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m e[\u001B[38;5;241m2\u001B[39m] \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwidth\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m e[\u001B[38;5;241m2\u001B[39m]:\n\u001B[0;32m--> 699\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[43medge_scaling\u001B[49m:\n\u001B[1;32m 700\u001B[0m width_type \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[1;32m 701\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n", + "\u001B[0;31mNameError\u001B[0m: name 'edge_scaling' is not defined" + ] } ], "source": [ "nxg = nx.random_tree(20)\n", "g.from_nx(nxg)\n", - "g.show(\"example.html\")" + "g.show(\"example2.html\")" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Disabling Physics interaction" ] @@ -192,16 +214,20 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { "text/html": [ "\n", " " + "" ] }, "execution_count": 6, @@ -219,12 +245,16 @@ ], "source": [ "g.toggle_physics(False)\n", - "g.show(\"example.html\")" + "g.show(\"example3.html\")" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Explicit coordinates to layout nodes" ] @@ -232,16 +262,20 @@ { "cell_type": "code", "execution_count": 7, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { "text/html": [ "\n", " " + "" ] }, "execution_count": 7, @@ -258,27 +292,44 @@ } ], "source": [ - "g = Network(notebook=True)\n", + "g = Network(notebook=True,cdn_resources='remote')\n", "g.add_nodes([1,2,3],\n", " value=[10, 100, 400],\n", " title=[\"I am node 1\", \"node 2 here\", \"and im node 3\"],\n", " x=[21.4, 21.4, 21.4], y=[100.2, 223.54, 32.1],\n", " label=[\"NODE 1\", \"NODE 2\", \"NODE 3\"],\n", " color=[\"#00ff1e\", \"#162347\", \"#dd4b39\"])\n", - "g.show(\"example.html\")" + "g.show(\"example4.html\")" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ - "### Full Game of Thrones example" + "### Full Game of Thrones example\n", + "Filter and highlight options\n", + "\n", + "When select_menu is set as true, you can highlight a selected node and its neighboring edges and nodes.\n", + "This can be done by directly clicking on the node or selecting the node id from the drop down.\n", + "\n", + "When filter_menu is set as true, you can filter the nodes and edges based on the selected properties and their values.\n", + "\n", + "The above options work independently and can be clubbed together to achieve required customizations" ] }, { "cell_type": "code", "execution_count": 8, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + }, + "scrolled": false + }, "outputs": [ { "data": { @@ -286,8 +337,8 @@ "\n", " " + "" ] }, "execution_count": 8, @@ -306,11 +357,12 @@ "source": [ "import pandas as pd\n", "\n", - "got_net = Network(notebook=True, height=\"750px\", width=\"100%\", bgcolor=\"#222222\", font_color=\"white\")\n", + "got_net = Network(notebook=True,cdn_resources='remote', height=\"750px\", width=\"100%\", bgcolor=\"#222222\", font_color=\"white\",\n", + " select_menu=True, filter_menu=True)\n", "\n", "# set the physics layout of the network\n", "got_net.barnes_hut()\n", - "got_data = pd.read_csv(\"https://www.macalester.edu/~abeverid/data/stormofswords.csv\")\n", + "got_data = pd.read_csv(\"NetworkOfThrones.csv\")\n", "\n", "sources = got_data['Source']\n", "targets = got_data['Target']\n", @@ -334,12 +386,16 @@ " node[\"title\"] += \" Neighbors:
\" + \"
\".join(neighbor_map[node[\"id\"]])\n", " node[\"value\"] = len(neighbor_map[node[\"id\"]]) # this value attrribute for the node affects node size\n", "\n", - "got_net.show(\"example.html\")" + "got_net.show(\"example5.html\")" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Experimenting with options UI\n", "Scroll down underneath the graph to play around with the physics settings to acheive optimal layout and behavior. You can use the generate options button to display the JSON representation of the configuration." @@ -347,41 +403,26 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" } - ], + }, + "outputs": [], "source": [ "got_net.show_buttons(filter_=\"physics\")\n", - "got_net.show(\"example.html\")" + "got_net.show(\"example6.html\")" ] }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "got_net.set_options('''var options = {\n", @@ -397,10 +438,26 @@ "}''')" ] }, + { + "cell_type": "markdown", + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "### Custom properties \n", + "Any custom properties added to the graph will be passed on to the network and can be used for filtering when filter_menu is set to true." + ] + }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "import networkx as nx" @@ -408,32 +465,13 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" } - ], + }, + "outputs": [], "source": [ "nx_graph = nx.cycle_graph(10)\n", "nx_graph.nodes[1]['title'] = 'Number 1'\n", @@ -445,7 +483,7 @@ "nx_graph.add_edge(20, 21, weight=5)\n", "nx_graph.add_node(25, size=25, label='lonely', title='lonely node', group=3)\n", "\n", - "nt = Network(notebook=True, height=\"750px\", width=\"100%\")\n", + "nt = Network(notebook=True, height=\"750px\", width=\"100%\", cdn_resources='remote', filter_menu =True)\n", "\n", "nt.from_nx(nx_graph)\n", "nt.show(\"nx.html\")" @@ -454,14 +492,29 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -475,9 +528,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.8.12" } }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file diff --git a/notebooks/example2.html b/notebooks/example2.html new file mode 100644 index 0000000..b2a5e3d --- /dev/null +++ b/notebooks/example2.html @@ -0,0 +1,340 @@ + + + + + + + + + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/notebooks/example3.html b/notebooks/example3.html new file mode 100644 index 0000000..094a0fa --- /dev/null +++ b/notebooks/example3.html @@ -0,0 +1,340 @@ + + + + + + + + + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/notebooks/example4.html b/notebooks/example4.html new file mode 100644 index 0000000..5767339 --- /dev/null +++ b/notebooks/example4.html @@ -0,0 +1,340 @@ + + + + + + + + + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/notebooks/example5.html b/notebooks/example5.html new file mode 100644 index 0000000..e50b33b --- /dev/null +++ b/notebooks/example5.html @@ -0,0 +1,858 @@ + + + + + + + + + + + + + + + + +
+

+
+ + + + + +
+ +
+
+
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
0%
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/notebooks/example6.html b/notebooks/example6.html new file mode 100644 index 0000000..8e7a3b7 --- /dev/null +++ b/notebooks/example6.html @@ -0,0 +1,871 @@ + + + + + + + + + + + + + + + + +
+

+
+ + + + + +
+ +
+
+
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
0%
+
+
+
+
+
+ + +
+ + + + + \ No newline at end of file diff --git a/notebooks/nx.html b/notebooks/nx.html new file mode 100644 index 0000000..f2f3357 --- /dev/null +++ b/notebooks/nx.html @@ -0,0 +1,511 @@ + + + + + + + + + + + + + + + + +
+

+
+ + + + + +
+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/pyvis/example.html b/pyvis/example.html new file mode 100644 index 0000000..a6cca5a --- /dev/null +++ b/pyvis/example.html @@ -0,0 +1,144 @@ + + + + + + + + + + + +
+

+
+ + + + + + + +
+ +
+
+ + + + \ No newline at end of file diff --git a/pyvis/lib/bindings/utils.js b/pyvis/lib/bindings/utils.js new file mode 100644 index 0000000..088effe --- /dev/null +++ b/pyvis/lib/bindings/utils.js @@ -0,0 +1,189 @@ +function neighbourhoodHighlight(params) { + // console.log("in nieghbourhoodhighlight"); + allNodes = nodes.get({ returnType: "Object" }); + // originalNodes = JSON.parse(JSON.stringify(allNodes)); + // if something is selected: + if (params.nodes.length > 0) { + highlightActive = true; + var i, j; + var selectedNode = params.nodes[0]; + var degrees = 2; + + // mark all nodes as hard to read. + for (let nodeId in allNodes) { + // nodeColors[nodeId] = allNodes[nodeId].color; + allNodes[nodeId].color = "rgba(200,200,200,0.5)"; + if (allNodes[nodeId].hiddenLabel === undefined) { + allNodes[nodeId].hiddenLabel = allNodes[nodeId].label; + allNodes[nodeId].label = undefined; + } + } + var connectedNodes = network.getConnectedNodes(selectedNode); + var allConnectedNodes = []; + + // get the second degree nodes + for (i = 1; i < degrees; i++) { + for (j = 0; j < connectedNodes.length; j++) { + allConnectedNodes = allConnectedNodes.concat( + network.getConnectedNodes(connectedNodes[j]) + ); + } + } + + // all second degree nodes get a different color and their label back + for (i = 0; i < allConnectedNodes.length; i++) { + // allNodes[allConnectedNodes[i]].color = "pink"; + allNodes[allConnectedNodes[i]].color = "rgba(150,150,150,0.75)"; + if (allNodes[allConnectedNodes[i]].hiddenLabel !== undefined) { + allNodes[allConnectedNodes[i]].label = + allNodes[allConnectedNodes[i]].hiddenLabel; + allNodes[allConnectedNodes[i]].hiddenLabel = undefined; + } + } + + // all first degree nodes get their own color and their label back + for (i = 0; i < connectedNodes.length; i++) { + // allNodes[connectedNodes[i]].color = undefined; + allNodes[connectedNodes[i]].color = nodeColors[connectedNodes[i]]; + if (allNodes[connectedNodes[i]].hiddenLabel !== undefined) { + allNodes[connectedNodes[i]].label = + allNodes[connectedNodes[i]].hiddenLabel; + allNodes[connectedNodes[i]].hiddenLabel = undefined; + } + } + + // the main node gets its own color and its label back. + // allNodes[selectedNode].color = undefined; + allNodes[selectedNode].color = nodeColors[selectedNode]; + if (allNodes[selectedNode].hiddenLabel !== undefined) { + allNodes[selectedNode].label = allNodes[selectedNode].hiddenLabel; + allNodes[selectedNode].hiddenLabel = undefined; + } + } else if (highlightActive === true) { + // console.log("highlightActive was true"); + // reset all nodes + for (let nodeId in allNodes) { + // allNodes[nodeId].color = "purple"; + allNodes[nodeId].color = nodeColors[nodeId]; + // delete allNodes[nodeId].color; + if (allNodes[nodeId].hiddenLabel !== undefined) { + allNodes[nodeId].label = allNodes[nodeId].hiddenLabel; + allNodes[nodeId].hiddenLabel = undefined; + } + } + highlightActive = false; + } + + // transform the object into an array + var updateArray = []; + if (params.nodes.length > 0) { + for (let nodeId in allNodes) { + if (allNodes.hasOwnProperty(nodeId)) { + // console.log(allNodes[nodeId]); + updateArray.push(allNodes[nodeId]); + } + } + nodes.update(updateArray); + } else { + // console.log("Nothing was selected"); + for (let nodeId in allNodes) { + if (allNodes.hasOwnProperty(nodeId)) { + // console.log(allNodes[nodeId]); + // allNodes[nodeId].color = {}; + updateArray.push(allNodes[nodeId]); + } + } + nodes.update(updateArray); + } +} + +function filterHighlight(params) { + allNodes = nodes.get({ returnType: "Object" }); + // if something is selected: + if (params.nodes.length > 0) { + filterActive = true; + let selectedNodes = params.nodes; + + // hiding all nodes and saving the label + for (let nodeId in allNodes) { + allNodes[nodeId].hidden = true; + if (allNodes[nodeId].savedLabel === undefined) { + allNodes[nodeId].savedLabel = allNodes[nodeId].label; + allNodes[nodeId].label = undefined; + } + } + + for (let i=0; i < selectedNodes.length; i++) { + allNodes[selectedNodes[i]].hidden = false; + if (allNodes[selectedNodes[i]].savedLabel !== undefined) { + allNodes[selectedNodes[i]].label = allNodes[selectedNodes[i]].savedLabel; + allNodes[selectedNodes[i]].savedLabel = undefined; + } + } + + } else if (filterActive === true) { + // reset all nodes + for (let nodeId in allNodes) { + allNodes[nodeId].hidden = false; + if (allNodes[nodeId].savedLabel !== undefined) { + allNodes[nodeId].label = allNodes[nodeId].savedLabel; + allNodes[nodeId].savedLabel = undefined; + } + } + filterActive = false; + } + + // transform the object into an array + var updateArray = []; + if (params.nodes.length > 0) { + for (let nodeId in allNodes) { + if (allNodes.hasOwnProperty(nodeId)) { + updateArray.push(allNodes[nodeId]); + } + } + nodes.update(updateArray); + } else { + for (let nodeId in allNodes) { + if (allNodes.hasOwnProperty(nodeId)) { + updateArray.push(allNodes[nodeId]); + } + } + nodes.update(updateArray); + } +} + +function selectNode(nodes) { + network.selectNodes(nodes); + neighbourhoodHighlight({ nodes: nodes }); + return nodes; +} + +function selectNodes(nodes) { + network.selectNodes(nodes); + filterHighlight({nodes: nodes}); + return nodes; +} + +function highlightFilter(filter) { + let selectedNodes = [] + let selectedProp = filter['property'] + if (filter['item'] === 'node') { + let allNodes = nodes.get({ returnType: "Object" }); + for (let nodeId in allNodes) { + if (allNodes[nodeId][selectedProp] && filter['value'].includes((allNodes[nodeId][selectedProp]).toString())) { + selectedNodes.push(nodeId) + } + } + } + else if (filter['item'] === 'edge'){ + let allEdges = edges.get({returnType: 'object'}); + // check if the selected property exists for selected edge and select the nodes connected to the edge + for (let edge in allEdges) { + if (allEdges[edge][selectedProp] && filter['value'].includes((allEdges[edge][selectedProp]).toString())) { + selectedNodes.push(allEdges[edge]['from']) + selectedNodes.push(allEdges[edge]['to']) + } + } + } + selectNodes(selectedNodes) +} \ No newline at end of file diff --git a/pyvis/lib/tom-select/tom-select.complete.min.js b/pyvis/lib/tom-select/tom-select.complete.min.js new file mode 100644 index 0000000..e2e0211 --- /dev/null +++ b/pyvis/lib/tom-select/tom-select.complete.min.js @@ -0,0 +1,356 @@ +/** +* Tom Select v2.0.0-rc.4 +* Licensed under the Apache License, Version 2.0 (the "License"); +*/ +!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" +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 +0!==s?e(t,(e=>{if(1===s)return delete this._events[e] +e in this._events!=!1&&this._events[e].splice(this._events[e].indexOf(i),1)})):this._events={}}trigger(t,...i){var s=this +e(t,(e=>{if(e in s._events!=!1)for(let t of s._events[e])t.apply(s,i)}))}}var i +const s="[̀-ͯ·ʾ]",n=new RegExp(s,"g") +var o +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] +var i=1 +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]] +var t=[] +return p(e.substring(1)).forEach((function(i){var s=i.slice(0) +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={} +a.forEach((t=>{for(let s=t[0];s<=t[1];s++){let t=String.fromCharCode(s),n=c(t) +if(n!=t.toLowerCase()){n in e||(e[n]=[n]) +var i=new RegExp(d(e[n]),"iu") +t.match(i)||e[n].push(t)}}})) +var t=Object.keys(e) +t=t.sort(((e,t)=>t.length-e.length)),i=new RegExp("("+d(t)+"[̀-ͯ·ʾ]*)","g") +var s={} +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,"")))) +s[t]=d(i)})),s})()) +return e.normalize("NFKD").toLowerCase().split(i).map((e=>{if(""==e)return"" +const t=c(e) +if(o.hasOwnProperty(t))return o[t] +const i=e.normalize("NFC") +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 +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] +if("function"==typeof i)return i +i&&!Array.isArray(i)&&(e[t]=[i])},y=(e,t)=>{if(Array.isArray(e))e.forEach(t) +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=c(t+"").toLowerCase())?1:t>e?-1:0 +class b{constructor(e,t){this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,i){if(!e||!e.length)return[] +const s=[],n=e.split(/\s+/) +var o +return i&&(o=new RegExp("^("+Object.keys(i).map(v).join("|")+"):(.*)$")),n.forEach((e=>{let i,n=null,r=null +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) +return this._getScoreFunction(i)}_getScoreFunction(e){const t=e.tokens,i=t.length +if(!i)return function(){return 0} +const s=e.options.fields,n=e.weights,o=s.length,r=e.getAttrFn +if(!o)return function(){return 1} +const l=1===o?function(e,t){const i=s[0].field +return f(r(t,i),e,n[i])}:function(e,t){var i=0 +if(e.field){const s=r(t,e.field) +!e.regex&&s?i+=1/o:i+=f(s,e,1)}else y(n,((s,n)=>{i+=f(r(t,n),e,s)})) +return i/o} +return 1===i?function(e){return l(t[0],e)}:"and"===e.options.conjunction?function(e){for(var s,n=0,o=0;n{s+=l(t,e)})),s/i}}getSortFunction(e,t){var i=this.prepareSearch(e,t) +return this._getSortFunction(i)}_getSortFunction(e){var t,i,s +const n=this,o=e.options,r=!e.query&&o.sort_empty?o.sort_empty:o.sort,l=[],a=[] +if("function"==typeof r)return r.bind(this) +const c=function(t,i){return"$score"===t?i.score:e.getAttrFn(n.items[i.id],t)} +if(r)for(t=0,i=r.length;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 +s=this.prepareSearch(e,t),t=s.options,e=s.query +const o=t.score||n._getScoreFunction(s) +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})})) +const r=n._getSortFunction(s) +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] +if(e instanceof HTMLElement)return e +if(e.indexOf("<")>-1){let t=document.createElement("div") +return t.innerHTML=e.trim(),t.firstChild}return document.querySelector(e)},_=(e,t)=>{var i=document.createEvent("HTMLEvents") +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=[] +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 +e=e.parentNode}},F=(e,t=0)=>t>0?e[e.length-1]:e[0],L=(e,t)=>{if(!e)return-1 +t=t||e.nodeName +for(var i=0;e=e.previousElementSibling;)e.matches(t)&&i++ +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 +if("string"==typeof t){if(!t.length)return +t=new RegExp(t,"i")}const i=e=>3===e.nodeType?(e=>{var i=e.data.match(t) +if(i&&e.data.length>0){var s=document.createElement("span") +s.className="highlight" +var n=e.splitText(i.index) +n.splitText(i[0].length) +var o=n.cloneNode(!0) +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;t0},render:{}} +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,"""),z=(e,t)=>{var i +return function(s,n){var o=this +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={} +for(s in e.trigger=function(){var i=arguments[0] +if(-1===t.indexOf(i))return n.apply(e,arguments) +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") +return i||(e.setAttribute("id",t),t)},Q=e=>e.replace(/[\\"']/g,"\\$&"),G=(e,t)=>{t&&e.append(t)} +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") +if(!p&&!i.allowEmptyOption){let t=e.querySelector('option[value=""]') +t&&(p=t.textContent)}var u,h,g,f,v,m,O={placeholder:p,options:[],optgroups:[],items:[],maxItems:null} +return"select"===d?(h=O.options,g={},f=1,v=e=>{var t=Object.assign({},e.dataset),i=s&&t[s] +return"string"==typeof i&&i.length&&(t=Object.assign(t,JSON.parse(i))),t},m=(e,t)=>{var s=q(e.value) +if(null!=s&&(s||i.allowEmptyOption)){if(g.hasOwnProperty(s)){if(t){var a=g[s][l] +a?Array.isArray(a)?a.push(t):g[s][l]=[a,t]:g[s][l]=t}}else{var c=v(e) +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 +"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) +if(t)O.options=JSON.parse(t),y(O.options,(e=>{O.items.push(e[o])})) +else{var r=e.value.trim()||"" +if(!i.allowEmptyOption&&!r.length)return +const t=r.split(i.delimiter) +y(t,(e=>{const t={} +t[n]=e,t[o]=e,O.options.push(t)})),O.items=t}})(),Object.assign({},j,O,t)}var W=0 +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 +const s=this,n=[] +if(Array.isArray(e))e.forEach((e=>{"string"==typeof e?n.push(e):(s.plugins.settings[e.name]=e.options,n.push(e.name))})) +else if(e)for(t in e)e.hasOwnProperty(t)&&(s.plugins.settings[t]=e[t],n.push(t)) +for(;i=n.shift();)s.require(i)}loadPlugin(t){var i=this,s=i.plugins,n=e.plugins[t] +if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin') +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 +if(!t.plugins.loaded.hasOwnProperty(e)){if(i.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")') +t.loadPlugin(e)}return i.loaded[e]}}}(t)){constructor(e,t){var i +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++ +var s=w(e) +if(s.tomselect)throw new Error("Tom Select already initialized on this element") +s.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(s,null)).getPropertyValue("direction") +const n=U(s,t) +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) +var o=n.createFilter +"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() +const r=w("
"),l=w("
"),a=this._render("dropdown"),c=w('
'),d=this.input.getAttribute("class")||"",p=n.mode +var u +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(""),this.focus_node=l) +else{u=w('') +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" +P(n,{id:d}),P(a,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":d}) +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) +if(h){B(h,"click",g),P(h,{for:p}) +const t=M(h,e.inputId+"-ts-label") +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-") +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]") +i&&(e.onOptionSelect(t,i),H(t,!0))})),B(r,"click",(t=>{var s=k(t.target,"[data-ts-item]",r) +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))) +const f=t=>{const i=t.composedPath()[0] +if(!o.contains(i)&&!s.contains(i))return e.isFocused&&e.blur(),void e.inputState() +H(t,!0)} +var m=()=>{e.isOpen&&e.positionDropdown()} +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") +return t.className="optgroup",t.appendChild(e.options),t},optgroup_header:(e,t)=>'
'+t(e[i])+"
",option:(e,i)=>"
"+i(e[t])+"
",item:(e,i)=>"
"+i(e[t])+"
",option_create:(e,t)=>'
Add '+t(e.input)+"
",no_results:()=>'
No results found
',loading:()=>'
',not_loading:()=>{},dropdown:()=>"
"} +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"} +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 +t.setupOptions(i.options,i.optgroups),t.setValue(i.items,!0),t.lastQuery=null}onClick(){var e=this +if(e.activeItems.length>0)return e.clearActiveItems(),void e.focus() +e.isFocused&&e.isOpen?e.blur():e.focus()}onMouseDown(){}onChange(){_(this.input,"input"),_(this.input,"change")}onPaste(e){var t=this +t.isFull()||t.isInputHidden||t.isLocked?H(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue() +if(e.match(t.settings.splitOn)){var i=e.trim().split(t.settings.splitOn) +y(i,(e=>{t.createItem(e)}))}}),0)}onKeyPress(e){var t=this +if(!t.isLocked){var i=String.fromCharCode(e.keyCode||e.which) +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 +if(t.isLocked)9!==e.keyCode&&H(e) +else{switch(e.keyCode){case 65:if(K(V,e))return H(e),void t.selectAll() +break +case 27:return t.isOpen&&(H(e,!0),t.close()),void t.clearActiveItems() +case 40:if(!t.isOpen&&t.hasOptions)t.open() +else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1) +e&&t.setActiveOption(e)}return void H(e) +case 38:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1) +e&&t.setActiveOption(e)}return void H(e) +case 13:return void(t.isOpen&&t.activeOption?(t.onOptionSelect(e,t.activeOption),H(e)):t.settings.create&&t.createItem()&&H(e)) +case 37:return void t.advanceSelection(-1,e) +case 39:return void t.advanceSelection(1,e) +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))) +case 8:case 46:return void t.deleteSelection(e)}t.isInputHidden&&!K(V,e)&&H(e)}}onInput(e){var t=this +if(!t.isLocked){var i=t.inputValue() +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 +if(t.isDisabled)return t.blur(),void H(e) +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 +if(t.isFocused){t.isFocused=!1,t.ignoreFocus=!1 +var i=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")} +t.settings.create&&t.settings.createOnBlur?t.createItem(null,!1,i):i()}}}onOptionSelect(e,t){var i,s=this +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 +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 +if(!t.canLoad(e))return +C(t.wrapper,t.settings.loadingClass),t.loading++ +const i=t.loadCallback.bind(t) +t.settings.load.call(t,e,i)}loadCallback(e,t){const i=this +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 +e.contains("preloaded")||(e.add("preloaded"),this.load(""))}setTextboxValue(e=""){var t=this.control_input +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 +if("single"!==a.settings.mode){if(!e)return a.clearActiveItems(),void(a.isFocused&&a.showInput()) +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) +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)) +a.hideInput(),a.isFocused||a.focus()}}setActiveItemClass(e){const t=this,i=t.control.querySelector(".last-active") +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) +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 +const i=this.dropdown_content,s=i.clientHeight,n=i.scrollTop||0,o=e.offsetHeight,r=e.getBoundingClientRect().top-i.getBoundingClientRect().top+n +r+o>s+n?this.scroll(r-s+o,t):r0||!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 +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 +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() +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') +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) +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 +const u={},h=[] +var g,f=this,v=f.inputValue(),m=f.search(v),O=f.activeOption,b=f.settings.shouldOpen||!1,w=f.dropdown_content +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;t0&&(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]) +G(t,i),G(t,u[e]) +let s=f.render("optgroup",{group:f.optgroups[e],options:t}) +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 +t.replaceChild(e.firstChild,e),t.normalize()})),m.query.length&&m.tokens.length&&y(m.tokens,(e=>{T(w,e.regex)}))) +var _=e=>{let t=f.render(e,{input:v}) +return t&&(b=!0,w.insertBefore(t,w.firstChild)),t} +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 +p&&!f.settings.addPrecedence&&(e=1),O=f.selectable()[e]}}else p&&(O=p) +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 +if(Array.isArray(e))return i.addOptions(e,t),!1 +const s=q(e[i.settings.valueField]) +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]) +return null!==t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var i +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 +var s,n +const o=q(e),r=q(t[i.settings.valueField]) +if(null===o)return +if(!i.options.hasOwnProperty(o))return +if("string"!=typeof r)throw new Error("Value must be set in option data") +const l=i.getOption(o),a=i.getItem(o) +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) +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 +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() +var e={} +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) +if(null!==i&&this.options.hasOwnProperty(i)){const e=this.options[i] +if(e.$div)return e.$div +if(t)return this._render("option",e)}return null}getAdjacent(e,t,i="option"){var s +if(!e)return null +s="item"==i?this.controlChildren():this.dropdown_content.querySelectorAll("[data-selectable]") +for(let i=0;i0?s[i+1]:s[i-1] +return null}getItem(e){if("object"==typeof e)return e +var t=q(e) +return null!==t?this.control.querySelector(`[data-value="${Q(t)}"]`):null}addItems(e,t){var i=this,s=Array.isArray(e)?e:[e] +for(let e=0,n=(s=s.filter((e=>-1===i.items.indexOf(e)))).length;e{var i,s +const n=this,o=n.settings.mode,r=q(e) +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) +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 +if(!(e=i.getItem(e)))return +var s,n +const o=e.dataset.value +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{})){var s,n=this,o=n.caretPos +if(e=e||n.inputValue(),!n.canCreate(e))return i(),!1 +n.lock() +var r=!1,l=e=>{if(n.unlock(),!e||"object"!=typeof e)return i() +var s=q(e[n.settings.valueField]) +if("string"!=typeof s)return i() +n.setTextboxValue(),n.addOption(e,!0),n.setCaret(o),n.addItem(s),n.refreshOptions(t&&"single"!==n.settings.mode),i(e),r=!0} +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 +e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.updateOriginalInput(),e.refreshState()}refreshState(){const e=this +e.refreshValidityState() +const t=e.isFull(),i=e.isLocked +e.wrapper.classList.toggle("rtl",e.rtl) +const s=e.wrapper.classList +var n +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 +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 +var i,s +const n=t.input.querySelector('option[value=""]') +if(t.is_select_tag){const e=[] +function o(i,s,o){return i||(i=w('")),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() +t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this +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 +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 +I(this.dropdown,{width:t.width+"px",top:i+"px",left:s+"px"})}}clear(e){var t=this +if(t.items.length){var i=t.controlChildren() +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 +s.insertBefore(e,s.children[i]),t.setCaret(i+1)}deleteSelection(e){var t,i,s,n,o,r=this +t=e&&8===e.keyCode?-1:1,i={start:(o=r.control_input).selectionStart||0,length:(o.selectionEnd||0)-(o.selectionStart||0)} +const l=[] +if(r.activeItems.length)n=F(r.activeItems,t),s=L(n),t>0&&s++,y(r.activeItems,(e=>l.push(e))) +else if((r.isFocused||"single"===r.settings.mode)&&r.items.length){const e=r.controlChildren() +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)) +if(!a.length||"function"==typeof r.settings.onDelete&&!1===r.settings.onDelete.call(r,a,e))return!1 +for(H(e,!0),void 0!==s&&r.setCaret(s);l.length;)r.removeItem(l.pop()) +return r.showInput(),r.positionDropdown(),r.refreshOptions(!1),!0}advanceSelection(e,t){var i,s,n=this +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") +if(t)return t +var i=this.control.querySelectorAll(".active") +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 +e.input.disabled=!0,e.control_input.disabled=!0,e.focus_node.tabIndex=-1,e.isDisabled=!0,e.lock()}enable(){var e=this +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 +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="" +const o=this +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) +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] +s[t]=function(){var t,o +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 +e.settings.hideSelected=!1 +var i=function(e){setTimeout((()=>{var t=e.querySelector("input") +e.classList.contains("selected")?t.checked=!0:t.checked=!1}),1)} +e.hook("after","setupTemplates",(()=>{var t=e.settings.render.option +e.settings.render.option=(i,s)=>{var n=w(t.call(e,i,s)),o=document.createElement("input") +o.addEventListener("click",(function(e){H(e)})),o.type="checkbox" +const r=q(i[e.settings.valueField]) +return r&&e.items.indexOf(r)>-1&&(o.checked=!0),n.prepend(o),n}})),e.on("item_remove",(t=>{var s=e.getOption(t) +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) +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=>`
×
`},e) +t.on("initialize",(()=>{var e=w(i.html(i)) +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 +if(!$.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".') +if("multi"===e.settings.mode){var t=e.lock,i=e.unlock +e.hook("instead","lock",(()=>{var i=$(e.control).data("sortable") +return i&&i.disable(),t.call(e)})),e.hook("instead","unlock",(()=>{var t=$(e.control).data("sortable") +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"}) +var i=[] +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=>'
'+e.title+'×
'},e) +t.on("initialize",(()=>{var e=w(i.html(i)),s=e.querySelector("."+i.closeClass) +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 +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{if(!e.isFocused)return +const i=e.getLastActive(t) +if(i){const s=L(i) +e.setCaret(t>0?s+1:s),e.setActiveItem()}else e.setCaret(e.caretPos+t)}))})),J.define("dropdown_input",(function(){var e=this +e.settings.shouldOpen=!0,e.hook("before","setup",(()=>{e.focus_node=e.control,C(e.control_input,"dropdown-input") +const t=w('