| 26 | } |
| 27 | |
| 28 | export class OutputHandler implements CommandHandler { |
| 29 | session: Session; |
| 30 | |
| 31 | accept_command = ['output', 'output_ctl']; |
| 32 | |
| 33 | private readonly container_parent: JQuery; |
| 34 | private readonly container_elem: JQuery; |
| 35 | |
| 36 | constructor(session: Session, container_elem: JQuery) { |
| 37 | this.session = session; |
| 38 | this.container_elem = container_elem; |
| 39 | this.container_parent = this.container_elem.parent(); |
| 40 | } |
| 41 | |
| 42 | scroll_bottom() { |
| 43 | body_scroll_to($('.pywebio'), 'bottom', null, 15); |
| 44 | }; |
| 45 | |
| 46 | is_elem_visible(elem: JQuery) { |
| 47 | try { |
| 48 | return DISPLAY_NONE_TAGS.indexOf(elem[0].tagName.toLowerCase()) == -1; |
| 49 | } catch (e) { |
| 50 | } |
| 51 | return false; |
| 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…