1
0
Эх сурвалжийг харах

feat: add `input_auto_focus` and `input_panel_fixed` configurations in `set_env()`

feat: add ``input_panel_fixed`` configuration in `set_env()`
wangweimin 4 жил өмнө
parent
commit
8faaac5e0e

+ 5 - 3
pywebio/session/__init__.py

@@ -483,8 +483,10 @@ def set_env(**env_info):
     * ``output_animation`` (bool): Whether to enable output animation, enabled by default
     * ``auto_scroll_bottom`` (bool): Whether to automatically scroll the page to the bottom after output content, it is closed by default.  Note that after enabled, only outputting to ROOT scope can trigger automatic scrolling.
     * ``http_pull_interval`` (int): The period of HTTP polling messages (in milliseconds, default 1000ms), only available in sessions based on HTTP connection.
-    * ``input_panel_min_height`` (int): The minimum height of input panel (in pixel, default 300px), it should be larger than 75px.
-    * ``input_panel_init_height`` (int): The initial height of input panel (in pixel, default 300px), it should be larger than 175px.
+    * ``input_panel_fixed`` (bool): Whether to make input panel fixed at bottom, enabled by default
+    * ``input_panel_min_height`` (int): The minimum height of input panel (in pixel, default 300px), it should be larger than 75px. Available only when ``input_panel_fixed=True``
+    * ``input_panel_init_height`` (int): The initial height of input panel (in pixel, default 300px), it should be larger than 175px. Available only when ``input_panel_fixed=True``
+    * ``input_auto_focus`` (bool): Whether to focus on input automatically after showing input panel, default is ``True``
 
     Example::
 
@@ -492,7 +494,7 @@ def set_env(**env_info):
     """
     from ..io_ctrl import send_msg
     assert all(k in ('title', 'output_animation', 'auto_scroll_bottom', 'http_pull_interval',
-                     'input_panel_min_height', 'input_panel_init_height')
+                     'input_panel_min_height', 'input_panel_init_height', 'input_panel_fixed', 'input_auto_focus')
                for k in env_info.keys())
     send_msg('set_env', spec=env_info)
 

+ 8 - 0
webiojs/src/handlers/env.ts

@@ -33,5 +33,13 @@ export class EnvSettingHandler implements CommandHandler {
         if (spec.input_panel_init_height !== undefined) {
             state.InputPanelInitHeight = spec.input_panel_init_height;
         }
+
+        if(spec.input_panel_fixed !== undefined){
+            state.FixedInputPanel =  spec.input_panel_fixed;
+        }
+
+        if(spec.input_auto_focus !== undefined){
+            state.AutoFocusOnInput =  spec.input_auto_focus;
+        }
     }
 }

+ 2 - 1
webiojs/src/handlers/input.ts

@@ -38,7 +38,8 @@ export class InputHandler implements CommandHandler {
         if (old_ctrls)
             old_ctrls[old_ctrls.length - 1].after_show();
 
-        $('[auto_focus="true"]').focus();
+        if(state.AutoFocusOnInput)
+            $('[auto_focus="true"]').focus();
     };
 
     // hide old_ctrls显示的表单,激活 task_id 对应的表单

+ 3 - 1
webiojs/src/state.ts

@@ -6,7 +6,9 @@ export let state = {
     CurrentSession: null as Session,  // 当前正在活跃的会话
     ShowDuration: 200,  // ms, 显示表单的过渡动画时长
     InputPanelMinHeight: 300,  // 输入panel的最小高度
-    InputPanelInitHeight: 300  // 输入panel的初始高度
+    InputPanelInitHeight: 300,  // 输入panel的初始高度
+    FixedInputPanel:true,
+    AutoFocusOnInput:true
 };
 
 // 应用配置

+ 1 - 0
webiojs/src/ui.ts

@@ -44,6 +44,7 @@ function fixed_input_init_height() { // 返回当前的输入panel的初始高
 
 
 function toggle_input_panel_style(fixed: boolean) {
+    fixed = state.FixedInputPanel && fixed;
     if (!fixed) {
         input_panel.removeClass('fixed');
         end_space.height(0);