MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / handle_message

Method handle_message

webiojs/src/handlers/output.ts:54–108  ·  view source on GitHub ↗
(msg: Command)

Source from the content-addressed store, hash-verified

52 }
53
54 handle_message(msg: Command) {
55 let output_to_root = false;
56 if (msg.command === 'output') {
57 let elem;
58 try {
59 elem = getWidgetElement(msg.spec);
60 } catch (e) {
61 return console.error(`Handle command error: "${e}"\nCommand:\n${JSON.stringify(msg)}`);
62 }
63
64 let container_elem = $(msg.spec.scope);
65
66 if (config.outputAnimation && this.is_elem_visible(elem) && container_elem.length == 1) elem.hide();
67
68 if (container_elem.length === 0)
69 return console.error(`Scope '${msg.spec.scope}' not found`);
70
71 if (!msg.spec.scope || msg.spec.scope === '#pywebio-scope-ROOT') output_to_root = true;
72
73 if (msg.spec.position === 0)
74 container_elem.prepend(elem);
75 else if (msg.spec.position === -1)
76 container_elem.append(elem);
77 else {
78 for (let con of container_elem) {
79 let pos = $(con.children).eq(msg.spec.position);
80 if (msg.spec.position >= 0)
81 elem.insertBefore(pos);
82 else
83 elem.insertAfter(pos);
84 }
85 }
86
87 // to avoid widget width exceeding page width
88 // show horizon scroll bar when content too wide
89 if (elem.width() > this.container_elem.width())
90 elem.wrap($(document.createElement('div')).css('overflow', 'auto'));
91
92 if (this.is_elem_visible(elem) && container_elem.length == 1) { // 输出内容为可见标签且输出目的scope唯一
93 if (config.outputAnimation)
94 elem.fadeIn({
95 complete: () => {
96 // 当设置了AutoScrollBottom、并且当前输出输出到页面末尾时,滚动到底部
97 if (state.AutoScrollBottom && output_to_root)
98 this.scroll_bottom();
99 }
100 });
101 else if (state.AutoScrollBottom && output_to_root)
102 this.scroll_bottom();
103 }
104 trigger_output_widget_show_event();
105 } else if (msg.command === 'output_ctl') {
106 this.handle_output_ctl(msg);
107 }
108 };
109
110 handle_output_ctl(msg: Command) {
111 if (msg.spec.set_scope !== undefined) {

Callers

nothing calls this directly

Calls 7

is_elem_visibleMethod · 0.95
scroll_bottomMethod · 0.95
handle_output_ctlMethod · 0.95
getWidgetElementFunction · 0.90
appendMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected