static void RemoveValue(HtmlElement parentRowElem) { int parentDepth; if (!parentRowElem.TryGetAttribute(DepthAttribute, out parentDepth)) { return; } parentRowElem.RemoveCssClass("expanded"); parentRowElem.AddCssClass("collapsed"); var elem = parentRowElem.NextElementSibling; while (elem != null) { int depth; if (!((HtmlElement)elem).TryGetAttribute(DepthAttribute, out depth) || depth <= parentDepth) { return; } var nextElem = elem.NextElementSibling; elem.ParentElement.RemoveChild(elem); elem = nextElem; } }
void ConfirmDeleteCell(Cell cell, HtmlElement cellElem) { cellElem.AddCssClass("confirm-delete"); ClientSession.ViewControllers.Messages.PushMessage( Message.CreateInfoAlert( Catalog.GetString("Are you sure you want to delete this cell?"), Catalog.GetString("There is currently no way to undo this action.")) .WithAction(new MessageAction( MessageActionKind.Affirmative, "delete", Catalog.GetString("Delete"))) .WithAction(new MessageAction( MessageActionKind.Negative, "cancel", Catalog.GetString("Cancel"))) .WithActionResponseHandler((message, action) => { message.Dispose(); cellElem.RemoveCssClass("confirm-delete"); if (action.Id == "delete") { DeleteCell(cell); } })); }
public void Render(HtmlElement targetElem) { containerElem = document.CreateElement("div", @class: "render-manager-container"); document.AddEventListener("click", evnt => { if (menuElem == null) { return; } else if (evnt.Target == menuButtonElem) { menuElem.AddCssClass("open"); } else { menuElem.RemoveCssClass("open"); } }); BuildExpander(); if (itemStates.Count > 1) { BuildMenu(); } else { menuElem = null; menuButtonElem = null; } targetElem.AppendChild(containerElem); SelectItem(0); }
public XcbWorkbookPageView( XcbWebView webView, ClientSession clientSession, WorkbookPage workbookPage) : base(clientSession, workbookPage) { this.webView = webView ?? throw new ArgumentNullException(nameof(webView)); void ObserveWorkbookMutationModelChanges(dynamic self, dynamic args) => TableOfContentsNodeExtensions.RebuildFromJavaScript(workbookPage.TableOfContents, args [0]); webView.Document.Context.GlobalObject.xiexports.WorkbookMutationObserver.observeModelChanges( (ScriptAction)ObserveWorkbookMutationModelChanges); rendererContext = new RendererContext(clientSession, webView.Document); rendererContext.MemberReferenceRequested += OnRendererContextMemberReferenceRequested; rendererContext.AsyncRenderComplete += (sender, e) => { var view = focusedCellState?.View; // Image rendering can happen asynchronously. If the last cell is evaluated, and // the focus has shifted to a new last cell, make sure the new last cell's // input doesn't get pushed out of the view by the image load. if (view != null && focusedWorkbookCell != null && focusedWorkbookCell.NextCell == null) { SynchronizationContext.Current.Post(o => view.Focus(), null); } }; clientSession.Workbook.EditorHub.Events.Subscribe( new Observer <EditorEvent> (HandleEditorEvent)); var document = webView.Document; xiexports = document.Context.GlobalObject.xiexports; outputElement = document.CreateElement("main"); outputElement.AddCssClass("interactive-workspace"); outputElement.AddCssClass(HostEnvironment.OS == HostOS.macOS ? "is-mac" : "is-windows"); outputElement.AddCssClass( $"session-kind-{clientSession.SessionKind.ToString ().ToLowerInvariant ()}"); document.Body.AppendChild(outputElement); AppendFirstCellActions(outputElement); }
public static void ToggleCssClass(this HtmlElement element, string className) { if (className == null) { return; } if (!element.RemoveCssClass(className)) { element.AddCssClass(className); } }
public void RenderDiagnostic(InteractiveDiagnostic diagnostic) { if (diagnosticsElem == null) { diagnosticsElem = CreateContentContainer("diagnostics"); if (HasErrorDiagnostics) { diagnosticsElem.AddCssClass("error"); } ContentElement.AppendChild(diagnosticsElem); } var displayMessage = new StringBuilder(); var position = diagnostic.Span.StartLinePosition; var severity = diagnostic.Severity.ToString().ToLowerInvariant(); var listElem = diagnosticsElem.FirstElementChild; if (listElem == null) { diagnosticsElem.AppendChild(listElem = Document.CreateElement("ul")); } var itemElement = Document.CreateElement("li", @class: severity); if (diagnostic.Span.IsValid) { displayMessage.Append($"({position.Line + 1},{position.Character + 1}): "); itemElement.AddEventListener("click", evnt => { if (!WindowHasSelection) { editor.Focus(); editor.CursorPosition = position; } }); } displayMessage.Append(severity); if (!String.IsNullOrEmpty(diagnostic.Id)) { displayMessage.Append(' ').Append(diagnostic.Id); } displayMessage.Append(": ").Append(diagnostic.Message); itemElement.AppendChild(Document.CreateTextNode(displayMessage.ToString())); listElem.AppendChild(itemElement); }
void UpdateEvaluationDurationHidden() { if (evaluationDurationElem != null) { if (Prefs.Submissions.ShowExecutionTimings.GetValue() && evaluationDuration != TimeSpan.Zero) { evaluationDurationElem.RemoveCssClass("execution-duration-hidden"); } else { evaluationDurationElem.AddCssClass("execution-duration-hidden"); } } }
async Task LoadValueAsync(HtmlElement parentRowElem, HtmlElement valueElem, InteractiveObject obj, InteractiveObject.InteractMessage interactMessage) { var parent = parentRowElem.ParentElement; var insertBefore = parentRowElem.NextSibling; try { var result = (InteractiveObject)await Context.InteractAsync( this, obj, interactMessage); // Returns null when disconnected from agent if (result == null) { return; } parentRowElem.AddCssClass("expanded"); parentRowElem.RemoveCssClass("collapsed"); if (result.Members == null || result.Members.Length == 0) { parentRowElem.RemoveCssClass("expanded"); valueElem.RemoveChildren(); valueElem.AppendChild(Document.CreateElement("code", innerHtml: result.ToStringRepresentation.HtmlEscape())); return; } foreach (var row in RenderRows(result)) { // FIXME: JSC XCB InsertBefore binding throws an // NRE if insertBefore is null... it should instead // propagate the null to JS if (insertBefore != null) { parent.InsertBefore(row.Element, insertBefore); } else { parent.AppendChild(row.Element); } } } catch (Exception e) { valueElem.RemoveChildren(); Context.Render(RenderState.CreateChild(e), valueElem); } }
void BuildMenu() { menuElem = document.CreateElement("div"); menuElem.ClassName = "xiui-dropdown-menu"; menuButtonElem = document.CreateElement("div"); menuButtonElem.ClassName = "button"; menuElem.AppendChild(menuButtonElem); var menuItemsElem = document.CreateElement("ul"); menuItemsElem.ClassName = "menu"; menuElem.AppendChild(menuItemsElem); var suppressDisplayName = 0; for (int i = 0; i < itemStates.Count; i++) { var subrenderState = itemStates [i]; if (subrenderState.RendererRepresentation.Options.HasFlag( RendererRepresentationOptions.SuppressDisplayNameHint)) { suppressDisplayName++; } var menuItemElem = document.CreateElement("li"); subrenderState.MenuItemElem = menuItemElem; menuItemElem.SetAttribute(DataItemIndexAttr, i.ToString(System.Globalization.CultureInfo.InvariantCulture)); menuItemElem.AppendChild(document.CreateTextNode(subrenderState.Title)); menuItemElem.AddEventListener("click", HandleMenuItemClick); menuItemsElem.AppendChild(menuItemElem); } if (suppressDisplayName == itemStates.Count) { menuButtonElem.AddCssClass("no-label"); } }
void LayoutSelectedItem() { if (expanderElem != null && selectedItemState.Renderer.CanExpand) { containerElem.AppendChild(expanderElem); } if (selectedItemState.InlineRenderedElem != null) { containerElem.AppendChild(selectedItemState.InlineRenderedElem); } if (menuElem != null) { containerElem.AppendChild(menuElem); } if (selectedItemState.ExpandedRenderedElem != null) { containerElem.AppendChild(selectedItemState.ExpandedRenderedElem); } else { return; } if (selectedItemState.RendererRepresentation.Options.HasFlag( RendererRepresentationOptions.ForceExpand)) { expanderElem.AddCssClass("expanded"); selectedItemState.ExpandedRenderedElem.AddCssClass("expanded"); } else { expanderElem.RemoveCssClass("expanded"); selectedItemState.ExpandedRenderedElem.RemoveCssClass("expanded"); } }
HtmlElement CreateActionButton( HtmlElement cellElem, string title, string tooltip, string cssClass, string cellHoverClass, Action clickHandler) { var document = webView.Document; var button = document.CreateElement("button", cssClass); if (!String.IsNullOrWhiteSpace(tooltip)) { button.SetAttribute("title", tooltip); } var span = document.CreateElement("span"); span.AppendChild(document.CreateTextNode(title)); button.AppendChild(span); button.AddEventListener("click", evnt => clickHandler()); if (cellElem != null && cellHoverClass != null) { button.AddEventListener( "mouseenter", evnt => cellElem.AddCssClass(cellHoverClass)); button.AddEventListener( "mouseleave", evnt => cellElem.RemoveCssClass(cellHoverClass)); } return(button); }
void RenderSlice() { var lastChildIsEnumerable = false; if (source.Slice != null) { foreach (var item in source.Slice) { var itemElem = Document.CreateElement("li"); itemsElem.AppendChild(itemElem); RenderState.Context.Render(RenderState.CreateChild(item), itemElem); lastChildIsEnumerable = item is InteractiveEnumerable; } } if (lastChildIsEnumerable) { itemsElem.RemoveCssClass("intermediate"); } else { itemsElem.AddCssClass("intermediate"); } }