nova-trame 0.13.1__py3-none-any.whl → 0.14.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  """View Implementation for InputField."""
2
2
 
3
3
  import logging
4
+ import os
4
5
  import re
5
6
  from typing import Any, Dict, Optional, Union
6
7
 
@@ -20,7 +21,14 @@ class InputField:
20
21
  """Factory class for generating Vuetify input components."""
21
22
 
22
23
  @staticmethod
23
- def create_boilerplate_properties(v_model: Optional[Union[tuple[str, Any], str]]) -> dict:
24
+ def create_boilerplate_properties(
25
+ v_model: Optional[Union[tuple[str, Any], str]], debounce: int, throttle: int
26
+ ) -> dict:
27
+ if debounce == -1:
28
+ debounce = int(os.environ.get("NOVA_TRAME_DEFAULT_DEBOUNCE", 0))
29
+ if throttle == -1:
30
+ throttle = int(os.environ.get("NOVA_TRAME_DEFAULT_THROTTLE", 0))
31
+
24
32
  if not v_model:
25
33
  return {}
26
34
  if isinstance(v_model, tuple):
@@ -55,22 +63,45 @@ class InputField:
55
63
 
56
64
  args: Dict[str, Any] = {}
57
65
  if v_model:
58
- args |= {
59
- "v_model": v_model,
60
- "label": label,
61
- "help": help_dict,
62
- "update_modelValue": f"flushState('{object_name_in_state}')",
63
- }
66
+ args |= {"v_model": v_model, "label": label, "help": help_dict}
64
67
  if field_info:
65
68
  args |= {
66
69
  "rules": (f"[(v) => trigger('validate_pydantic_field', ['{field}', v, index])]",),
67
70
  }
71
+
72
+ if debounce > 0 and throttle > 0:
73
+ raise ValueError("debounce and throttle cannot be used together")
74
+
75
+ if debounce > 0:
76
+ args |= {
77
+ "update_modelValue": (
78
+ "window.delay_manager.debounce("
79
+ f" '{v_model}',"
80
+ f" () => flushState('{object_name_in_state}'),"
81
+ f" {debounce}"
82
+ ")"
83
+ )
84
+ }
85
+ elif throttle > 0:
86
+ args |= {
87
+ "update_modelValue": (
88
+ "window.delay_manager.throttle("
89
+ f" '{v_model}',"
90
+ f" () => flushState('{object_name_in_state}'),"
91
+ f" {throttle}"
92
+ ")"
93
+ )
94
+ }
95
+ else:
96
+ args |= {"update_modelValue": f"flushState('{object_name_in_state}')"}
68
97
  return args
69
98
 
70
99
  def __new__(
71
100
  cls,
72
101
  v_model: Optional[Union[tuple[str, Any], str]] = None,
73
102
  required: bool = False,
103
+ debounce: int = -1,
104
+ throttle: int = -1,
74
105
  type: str = "text",
75
106
  **kwargs: Any,
76
107
  ) -> AbstractElement:
@@ -84,6 +115,16 @@ class InputField:
84
115
  required : bool
85
116
  If true, the input will be visually marked as required and a required rule will be added to the end of the
86
117
  rules list.
118
+ debounce : int
119
+ Number of milliseconds to wait after the last user interaction with this field before attempting to update
120
+ the Trame state. If set to 0, then no debouncing will occur. If set to -1, then the environment variable
121
+ `NOVA_TRAME_DEFAULT_DEBOUNCE` will be used to set this (defaults to 0). See the `Lodash Docs
122
+ <https://lodash.com/docs/4.17.15#debounce>`_ for details.
123
+ throttle : int
124
+ Number of milliseconds to wait between updates to the Trame state when the user is interacting with this
125
+ field. If set to 0, then no throttling will occur. If set to -1, then the environment variable
126
+ `NOVA_TRAME_DEFAULT_THROTTLE` will be used to set this (defaults to 0). See the `Lodash Docs
127
+ <https://lodash.com/docs/4.17.15#throttle>`_ for details.
87
128
  type : str
88
129
  The type of input to create. This can be any of the following:
89
130
 
@@ -120,7 +161,7 @@ class InputField:
120
161
  """
121
162
  server = get_server(None, client_type="vue3")
122
163
 
123
- kwargs = {**cls.create_boilerplate_properties(v_model), **kwargs}
164
+ kwargs = {**cls.create_boilerplate_properties(v_model, debounce, throttle), **kwargs}
124
165
 
125
166
  if "__events" not in kwargs or kwargs["__events"] is None:
126
167
  kwargs["__events"] = []
@@ -235,8 +276,8 @@ class InputField:
235
276
  def _setup_help(_input: AbstractElement, **kwargs: Any) -> None:
236
277
  help = kwargs.get("help", None)
237
278
  if help and isinstance(help, dict):
238
- _input.hint = help.get("hint", None)
239
279
  _input.placeholder = help.get("placeholder", None)
280
+ _input.title = help.get("hint", None)
240
281
 
241
282
  @staticmethod
242
283
  def _setup_required_label(input: AbstractElement) -> None:
@@ -0,0 +1,24 @@
1
+ class DelayManager {
2
+ constructor() {
3
+ this.debounces = {}
4
+ this.throttles = {}
5
+ }
6
+
7
+ debounce(id, func, wait) {
8
+ if (!(id in this.debounces)) {
9
+ this.debounces[id] = window.debounce(func, wait)
10
+ }
11
+
12
+ this.debounces[id]()
13
+ }
14
+
15
+ throttle(id, func, wait) {
16
+ if (!(id in this.throttles)) {
17
+ this.throttles[id] = window.throttle(func, wait)
18
+ }
19
+
20
+ this.throttles[id]()
21
+ }
22
+ }
23
+
24
+ window.delay_manager = new DelayManager()
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
3
+ *
4
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
5
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
6
+ *
7
+ * This software consists of voluntary contributions made by many
8
+ * individuals. For exact contribution history, see the revision history
9
+ * available at https://github.com/lodash/lodash
10
+ *
11
+ * The following license applies to all parts of this software except as
12
+ * documented below:
13
+ *
14
+ * ====
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining
17
+ * a copy of this software and associated documentation files (the
18
+ * "Software"), to deal in the Software without restriction, including
19
+ * without limitation the rights to use, copy, modify, merge, publish,
20
+ * distribute, sublicense, and/or sell copies of the Software, and to
21
+ * permit persons to whom the Software is furnished to do so, subject to
22
+ * the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be
25
+ * included in all copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+ *
35
+ * ====
36
+ *
37
+ * Copyright and related rights for sample code are waived via CC0. Sample
38
+ * code is defined as all source code displayed within the prose of the
39
+ * documentation.
40
+ *
41
+ * CC0: http://creativecommons.org/publicdomain/zero/1.0/
42
+ *
43
+ * ====
44
+ *
45
+ * Files located in the node_modules and vendor directories are externally
46
+ * maintained libraries used by this software which have their own
47
+ * licenses; we recommend you read them, as their terms may differ from the
48
+ * terms above.
49
+ */
50
+
51
+ /**
52
+ * Minified by jsDelivr using UglifyJS v3.1.10.
53
+ * Original file: /npm/lodash.debounce@4.0.8/index.js
54
+ *
55
+ * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
56
+ */
57
+ function debounce(e,t,r){function o(t){var r=f,o=c;return f=c=void 0,m=t,b=e.apply(o,r)}function n(e){var r=e-v;return void 0===v||r>=t||r<0||y&&e-m>=l}function i(){var e=now();if(n(e))return u(e);s=setTimeout(i,function(e){var r=t-(e-v);return y?nativeMin(r,l-(e-m)):r}(e))}function u(e){return s=void 0,p&&f?o(e):(f=c=void 0,b)}function a(){var e=now(),r=n(e);if(f=arguments,c=this,v=e,r){if(void 0===s)return function(e){return m=e,s=setTimeout(i,t),j?o(e):b}(v);if(y)return s=setTimeout(i,t),o(v)}return void 0===s&&(s=setTimeout(i,t)),b}var f,c,l,b,s,v,m=0,j=!1,y=!1,p=!0;if("function"!=typeof e)throw new TypeError(FUNC_ERROR_TEXT);return t=toNumber(t)||0,isObject(r)&&(j=!!r.leading,l=(y="maxWait"in r)?nativeMax(toNumber(r.maxWait)||0,t):l,p="trailing"in r?!!r.trailing:p),a.cancel=function(){void 0!==s&&clearTimeout(s),m=0,f=v=c=s=void 0},a.flush=function(){return void 0===s?b:u(now())},a}function isObject(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function isObjectLike(e){return!!e&&"object"==typeof e}function isSymbol(e){return"symbol"==typeof e||isObjectLike(e)&&objectToString.call(e)==symbolTag}function toNumber(e){if("number"==typeof e)return e;if(isSymbol(e))return NAN;if(isObject(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=isObject(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(reTrim,"");var r=reIsBinary.test(e);return r||reIsOctal.test(e)?freeParseInt(e.slice(2),r?2:8):reIsBadHex.test(e)?NAN:+e}var FUNC_ERROR_TEXT="Expected a function",NAN=NaN,symbolTag="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,freeParseInt=parseInt,freeGlobal="object"==typeof global&&global&&global.Object===Object&&global,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=freeGlobal||freeSelf||Function("return this")(),objectProto=Object.prototype,objectToString=objectProto.toString,nativeMax=Math.max,nativeMin=Math.min,now=function(){return root.Date.now()};window.debounce=debounce;
58
+ //# sourceMappingURL=/sm/a79a09ba42f2fc9121b50e9acc14e4678d879dc4f045b63230ef13e933e74f71.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
3
+ *
4
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
5
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
6
+ *
7
+ * This software consists of voluntary contributions made by many
8
+ * individuals. For exact contribution history, see the revision history
9
+ * available at https://github.com/lodash/lodash
10
+ *
11
+ * The following license applies to all parts of this software except as
12
+ * documented below:
13
+ *
14
+ * ====
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining
17
+ * a copy of this software and associated documentation files (the
18
+ * "Software"), to deal in the Software without restriction, including
19
+ * without limitation the rights to use, copy, modify, merge, publish,
20
+ * distribute, sublicense, and/or sell copies of the Software, and to
21
+ * permit persons to whom the Software is furnished to do so, subject to
22
+ * the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be
25
+ * included in all copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+ *
35
+ * ====
36
+ *
37
+ * Copyright and related rights for sample code are waived via CC0. Sample
38
+ * code is defined as all source code displayed within the prose of the
39
+ * documentation.
40
+ *
41
+ * CC0: http://creativecommons.org/publicdomain/zero/1.0/
42
+ *
43
+ * ====
44
+ *
45
+ * Files located in the node_modules and vendor directories are externally
46
+ * maintained libraries used by this software which have their own
47
+ * licenses; we recommend you read them, as their terms may differ from the
48
+ * terms above.
49
+ */
50
+
51
+ /**
52
+ * Minified by jsDelivr using Terser v5.19.2.
53
+ * Original file: /npm/lodash.throttle@4.1.1/index.js
54
+ *
55
+ * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
56
+ */
57
+ var FUNC_ERROR_TEXT="Expected a function",NAN=NaN,symbolTag="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,freeParseInt=parseInt,freeGlobal="object"==typeof global&&global&&global.Object===Object&&global,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=freeGlobal||freeSelf||Function("return this")(),objectProto=Object.prototype,objectToString=objectProto.toString,nativeMax=Math.max,nativeMin=Math.min,now=function(){return root.Date.now()};function debounce(t,e,n){var r,i,o,a,u,f,c=0,l=!1,b=!1,s=!0;if("function"!=typeof t)throw new TypeError(FUNC_ERROR_TEXT);function v(e){var n=r,o=i;return r=i=void 0,c=e,a=t.apply(o,n)}function m(t){var n=t-f;return void 0===f||n>=e||n<0||b&&t-c>=o}function y(){var t=now();if(m(t))return j(t);u=setTimeout(y,function(t){var n=e-(t-f);return b?nativeMin(n,o-(t-c)):n}(t))}function j(t){return u=void 0,s&&r?v(t):(r=i=void 0,a)}function g(){var t=now(),n=m(t);if(r=arguments,i=this,f=t,n){if(void 0===u)return function(t){return c=t,u=setTimeout(y,e),l?v(t):a}(f);if(b)return u=setTimeout(y,e),v(f)}return void 0===u&&(u=setTimeout(y,e)),a}return e=toNumber(e)||0,isObject(n)&&(l=!!n.leading,o=(b="maxWait"in n)?nativeMax(toNumber(n.maxWait)||0,e):o,s="trailing"in n?!!n.trailing:s),g.cancel=function(){void 0!==u&&clearTimeout(u),c=0,r=f=i=u=void 0},g.flush=function(){return void 0===u?a:j(now())},g}function throttle(t,e,n){var r=!0,i=!0;if("function"!=typeof t)throw new TypeError(FUNC_ERROR_TEXT);return isObject(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),debounce(t,e,{leading:r,maxWait:e,trailing:i})}function isObject(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function isObjectLike(t){return!!t&&"object"==typeof t}function isSymbol(t){return"symbol"==typeof t||isObjectLike(t)&&objectToString.call(t)==symbolTag}function toNumber(t){if("number"==typeof t)return t;if(isSymbol(t))return NAN;if(isObject(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=isObject(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(reTrim,"");var n=reIsBinary.test(t);return n||reIsOctal.test(t)?freeParseInt(t.slice(2),n?2:8):reIsBadHex.test(t)?NAN:+t}window.throttle=throttle;
58
+ //# sourceMappingURL=/sm/4821be4c17c96774933f52de28b42cf423cc8f3e273d4f8b4fb982a8aebf2981.map
@@ -103,6 +103,8 @@ class ThemedApp:
103
103
  shortcut
104
104
  ]
105
105
 
106
+ self.init_lodash()
107
+
106
108
  # Since this is only intended for theming Trame apps, I don't think we need to invoke the MVVM framework here,
107
109
  # and working directly with the Trame state makes this easier for me to manage.
108
110
  self.state.nova__menu = False
@@ -114,6 +116,19 @@ class ThemedApp:
114
116
  def state(self) -> State:
115
117
  return self.server.state
116
118
 
119
+ def init_lodash(self) -> None:
120
+ js_path = (Path(__file__).parent / "assets" / "js").resolve()
121
+ self.server.enable_module(
122
+ {
123
+ "scripts": [
124
+ "assets/js/lodash.debounce.min.js",
125
+ "assets/js/lodash.throttle.min.js",
126
+ "assets/js/delay_manager.js",
127
+ ],
128
+ "serve": {"assets/js": js_path},
129
+ }
130
+ )
131
+
117
132
  def init_mantid(self) -> None:
118
133
  """Initializes MantidManager.
119
134
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nova-trame
3
- Version: 0.13.1
3
+ Version: 0.14.1
4
4
  Summary: A Python Package for injecting curated themes and custom components into Trame applications
5
5
  License: MIT
6
6
  Keywords: NDIP,Python,Trame,Vuetify
@@ -2,7 +2,7 @@ nova/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
2
2
  nova/trame/__init__.py,sha256=gFrAg1qva5PIqR5TjvPzAxLx103IKipJLqp3XXvrQL8,59
3
3
  nova/trame/model/remote_file_input.py,sha256=9KAf31ZHzpsh_aXUrNcF81Q5jvUZDWCzW1QATKls-Jk,3675
4
4
  nova/trame/view/components/__init__.py,sha256=fopr6mVqcpDcVYK9ue7SLUHyswgvRPcFESTq86mu1R8,128
5
- nova/trame/view/components/input_field.py,sha256=YyDJJKHBsAdLN-GFOhXEpwNs5aJHb0BBbstcQ6nbAQE,12680
5
+ nova/trame/view/components/input_field.py,sha256=yfNKDNIea4xv1CzAKIzbWk7kGi8Xt-pjJ6FvT_NFczQ,14728
6
6
  nova/trame/view/components/remote_file_input.py,sha256=k2yrwkell_g0sGnWR9XLL1LxkmFLr8-AGhduo8E-N4A,8669
7
7
  nova/trame/view/components/visualization/__init__.py,sha256=kDX1fkbtAgXSGlqhlMNhYYoYrq-hfS636smjgLsh6gg,84
8
8
  nova/trame/view/components/visualization/interactive_2d_plot.py,sha256=foZCMoqbuahT5dtqIQvm8C4ZJcY9P211eJEcpQJltmM,3421
@@ -13,12 +13,15 @@ nova/trame/view/layouts/vbox.py,sha256=Q4EvrtGJORyNF6AnCLGXToy8XU6yofiO5_kt7hK-A
13
13
  nova/trame/view/theme/__init__.py,sha256=70_marDlTigIcPEOGiJb2JTs-8b2sGM5SlY7XBPtBDM,54
14
14
  nova/trame/view/theme/assets/core_style.scss,sha256=AktysiiCYLeiTzCTtYwkksiUVmqb4S23RlDcW8L1ebI,518
15
15
  nova/trame/view/theme/assets/favicon.png,sha256=Xbp1nUmhcBDeObjsebEbEAraPDZ_M163M_ZLtm5AbQc,1927
16
+ nova/trame/view/theme/assets/js/delay_manager.js,sha256=H_9mikPKxwtLBWWmOIk5A_47iiE2XmFeoLHdrG6J73Y,504
17
+ nova/trame/view/theme/assets/js/lodash.debounce.min.js,sha256=GLzlQH04WDUNYN7i39ttHHejSdu-CpAvfWgDgKDn-OY,4448
18
+ nova/trame/view/theme/assets/js/lodash.throttle.min.js,sha256=9csqjX-M-LVGJnF3z4ha1R_36O5AfkFE8rPHkxmt3tE,4677
16
19
  nova/trame/view/theme/assets/vuetify_config.json,sha256=7WGV6rO7hv2sapGsX9yy1d-dINshYFXRNX99D9I3dKQ,4780
17
- nova/trame/view/theme/theme.py,sha256=-5lq8u34eQ9j1bMeB5b63BiAdpi92WI2o-fJKcrwl3o,11401
20
+ nova/trame/view/theme/theme.py,sha256=aNaQec73bfxVkNODBA9wWkPLzLUjsx5oWEoQCQ-0fLE,11867
18
21
  nova/trame/view/utilities/local_storage.py,sha256=vD8f2VZIpxhIKjZwEaD7siiPCTZO4cw9AfhwdawwYLY,3218
19
22
  nova/trame/view_model/remote_file_input.py,sha256=WHWCQkZBGeKLe1aTPbtVNI8tn-PDt64mi1-561uuBpQ,3320
20
- nova_trame-0.13.1.dist-info/LICENSE,sha256=MOqZ8tPMKy8ZETJ2-HEvFTZ7dYNlg3gXmBkV-Y9i8bw,1061
21
- nova_trame-0.13.1.dist-info/METADATA,sha256=ivedQKUq-ZJ2jk1e0aXkeHjbvtxXWLyOBGNl-lijv5E,1240
22
- nova_trame-0.13.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
- nova_trame-0.13.1.dist-info/entry_points.txt,sha256=J2AmeSwiTYZ4ZqHHp9HO6v4MaYQTTBPbNh6WtoqOT58,42
24
- nova_trame-0.13.1.dist-info/RECORD,,
23
+ nova_trame-0.14.1.dist-info/LICENSE,sha256=MOqZ8tPMKy8ZETJ2-HEvFTZ7dYNlg3gXmBkV-Y9i8bw,1061
24
+ nova_trame-0.14.1.dist-info/METADATA,sha256=vZyO-5ZpujJ_1vM4tWrmjHGwPnqBHbbERsc-GnHkq0o,1240
25
+ nova_trame-0.14.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
26
+ nova_trame-0.14.1.dist-info/entry_points.txt,sha256=J2AmeSwiTYZ4ZqHHp9HO6v4MaYQTTBPbNh6WtoqOT58,42
27
+ nova_trame-0.14.1.dist-info/RECORD,,