/* eslint-disable @typescript-eslint/no-unused-vars */
/**
 * Angular wrapper for Bryntum CodeEditor
 */

import { Component, ElementRef, EventEmitter, Output, Input, SimpleChange, SimpleChanges, OnDestroy, OnInit } from '@angular/core';

import WrapperHelper from './wrapper.helper';

import { AlignSpec, Base, CodeEditor, CodeEditorListeners, Color, Container, ContainerItemConfig, ContainerLayoutConfig, DomConfig, KeyMapConfig, Layout, MaskConfig, MenuItemConfig, MenuItemEntry, Model, PagingToolbarConfig, Panel, PanelCollapserConfig, PanelCollapserOverlayConfig, PanelHeader, ReactJSX, Rectangle, Scroller, ScrollerConfig, StateProvider, TabConfig, Tool, ToolConfig, ToolbarConfig, ToolbarItems, TooltipConfig, VueConfig, Widget } from '@bryntum/gantt';

import { DomHelper, StringHelper } from '@bryntum/gantt';
import { initThemeInShadowRoots } from './shadowdom.helper';

export type BryntumCodeEditorProps = {
    // Configs
    /**
     * Element (or element id) to adopt as this Widget's encapsulating element. The widget's
     * content will be placed inside this element.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-adopt)
     */
    adopt ? : HTMLElement|string
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-align)
     */
    align ? : AlignSpec|string
    /**
     * When this widget is a child of a [Container](https://bryntum.com/products/gantt/docs/api/Core/widget/Container), it will by default be participating in a
     * flexbox layout. This config allows you to set this widget's
     * [align-self](https://developer.mozilla.org/en-US/docs/Web/CSS/align-self) style.
     */
    alignSelf ? : string
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating) and being shown through [showBy](#Core/widget/Widget#function-showBy).*
     * `true` to show a connector arrow pointing to the align target.
     */
    anchor ? : boolean
    /**
     * Element (or the id of an element) to append this widget's element to. Can be configured, or set once at
     * runtime. To access the element of a rendered widget, see [element](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-element).
     */
    appendTo ? : HTMLElement|string
    /**
     * A localizable string (May contain `'L{}'` tokens which resolve in the locale file) to inject
     * into an element which will be linked using the `aria-describedby` attribute.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-ariaDescription)
     */
    ariaDescription ? : string
    /**
     * A localizable string (May contain `'L{}'` tokens which resolve in the locale file) to inject as
     * the `aria-label` attribute.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-ariaLabel)
     */
    ariaLabel ? : string
    /**
     * Update assigned [record](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#config-record) automatically on field changes
     */
    autoUpdateRecord ? : boolean
    /**
     * A Config object representing the configuration of a [Toolbar](https://bryntum.com/products/gantt/docs/api/Core/widget/Toolbar),
     * or array of config objects representing the child items of a Toolbar. Another way to add a bbar is to use [strips](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-strips).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-bbar)
     */
    bbar ? : (ContainerItemConfig|string)[]|ToolbarConfig|PagingToolbarConfig|null
    /**
     * Custom CSS classes to add to the panel's body element.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-bodyCls)
     */
    bodyCls ? : string|object
    /**
     * Set `true` to add a border to this container's element.
     */
    border ? : boolean
    /**
     * An object where property names with a truthy value indicate which events should bubble up the ownership
     * hierarchy when triggered.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-bubbleEvents)
     */
    bubbleEvents ? : object
    /**
     * Set to `false` to not call onXXX method names (e.g. `onShow`, `onClick`), as an easy way to listen for events.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-callOnFunctions)
     */
    callOnFunctions ? : boolean
    /**
     * By default, if an event handler throws an exception, the error propagates up the stack and the
     * application state is undefined. Code which follows the event handler will *not* be executed.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-catchEventHandlerExceptions)
     */
    catchEventHandlerExceptions ? : boolean
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * Set to `true` to centre the Widget in browser viewport space.
     */
    centered ? : boolean
    /**
     * Custom CSS classes to add to element.
     * May be specified as a space separated string, or as an object in which property names
     * with truthy values are used as the class names:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-cls)
     */
    cls ? : string|object
    /**
     * The path from which to load the Monaco editor.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-codePath)
     */
    codePath ? : string
    /**
     * Controls whether the panel is collapsed (the body of the panel is hidden while only the header is
     * visible). Only valid if the panel is [collapsible](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-collapsible).
     */
    collapsed ? : boolean
    /**
     * This config enables collapsibility for the panel. See [collapsed](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-collapsed).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-collapsible)
     */
    collapsible ? : boolean|PanelCollapserConfig|PanelCollapserOverlayConfig
    /**
     * Applies the specified color to the widget, by setting the `--b-primary` CSS variable in the widgets
     * `style` block.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-color)
     */
    color ? : Color
    /**
     * Programmatic control over which column to start in when used in a grid layout.
     */
    column ? : number
    config ? : object
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating) or [positioned](#Core/widget/Widget#config-positioned).*
     * Element, Widget or Rectangle to which this Widget is constrained.
     */
    constrainTo ? : HTMLElement|Widget|Rectangle
    /**
     * The HTML content that coexists with sibling elements which may have been added to the
     * [contentElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-contentElement) by plugins and features.
     * When specifying html, this widget's element will also have the [htmlCls](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-htmlCls)
     * class added to its classList, to allow targeted styling.
     */
    content ? : string
    /**
     * Custom CSS classes to add to the [contentElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-contentElement).
     * May be specified as a space separated string, or as an object in which property names
     * with truthy values are used as the class names:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-contentElementCls)
     */
    contentElementCls ? : string|object
    /**
     * When this Widget configuration is used in the Grid's RowExpander feature's `widget` config, provide the
     * field on the expanded record to use for populating this widget's store (if applicable)
     */
    dataField ? : string
    /**
     * Object to apply to elements dataset (each key will be used as a data-attribute on the element)
     */
    dataset ? : Record<string, string>
    /**
     * The name of the property to set when a single value is to be applied to this Widget. Such as when used
     * in a grid WidgetColumn, this is the property to which the column's `field` is applied.
     */
    defaultBindProperty ? : string
    /**
     * A [query](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#function-query) selector function which can identify the descendant widget to which
     * focus should be directed by default.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-defaultFocus)
     * @param {Core.widget.Widget} widget Widget passed to method
     * @returns {boolean} truthy value if widget is the default one
     */
    defaultFocus ? : ((widget: Widget) => boolean)|string
    /**
     * A config object containing default settings to apply to all child widgets.
     */
    defaults ? : ContainerItemConfig
    /**
     * Check for CSS compatibility and inclusion related issues and try to auto fix them. Performs the following
     * checks:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-detectCSSCompatibilityIssues)
     */
    detectCSSCompatibilityIssues ? : boolean
    /**
     * Disable or enable the widget. It is similar to [readOnly](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-readOnly) except a disabled widget
     * cannot be focused, uses a different rendition (usually greyish) and does not allow selecting its value.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-disabled)
     */
    disabled ? : boolean|'inert'
    /**
     * Controls the placement of this widget when it is added to a [panel's ](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel)
     * [strips collection](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-strips). Typical values for this config are `'top'`,
     * `'bottom'`, `'left'`, or `'right'`, which cause the widget to be placed on that side of the panel's
     * body. Such widgets are called "edge strips".
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-dock)
     */
    dock ? : 'top'|'bottom'|'left'|'right'|'start'|'end'|'header'|'pre-header'|object
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * Set to `true` to be able to drag a widget freely on the page. Or set to an object with a ´handleSelector´
     * property which controls when a drag should start.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-draggable)
     * @property {string} handleSelector CSS selector used to determine if drag can be started from a mouse-downed element inside the widget
     */
    draggable ? : boolean|object
    /**
     * Make this Panel a docked drawer which slides out from one side of the browser viewport by default.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-drawer)
     * @param {'start','left','end','right','top','bottom'} [side] The side of the viewport to dock the drawer to.  * `'start'` means the `inline-start` side. * `'end'` means the `inline-end` side.
     * @param {string,number} [size] The size of the drawer in its collapsible axis.
     * @param {boolean} [inline] If using the [appendTo](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-appendTo) config to place the drawer inside a host widget, this may be set to `true` to make the drawer inline within that host. Note that, if using this, the layout of the host element must have `flex-direction` set appropriately.
     * @param {boolean,object} [autoClose] Specifies what user actions should automatically close the drawer. Defaults to closing when the user clicks outside of the drawer or when focus moves outside of the drawer.
     * @param {boolean,string} [autoClose.mousedown] If the user clicks outside of the drawer, the drawer will automatically be hidden. If the value is a string, it is used as a CSS selector to filter clicks which should close the drawer.
     * @param {boolean,string} [autoClose.focusout] If focus moves outside of the drawer, the drawer will automatically be hidden.
     * @param {string} [autoClose.mouseout] Hides the drawer when the mouse leaves the drawer after the `autoCloseDelay` period.
     * @param {number} [autoCloseDelay] When using `mouseout`, this is the delay in milliseconds
     */
    drawer ? : boolean|{ side?: 'start'|'left'|'end'|'right'|'top'|'bottom', size?: string|number, inline?: boolean, autoClose?: boolean|{ mousedown?: boolean|string, focusout?: boolean|string, mouseout?: string }, autoCloseDelay?: number }
    /**
     * An editor configuration object to be passed to https://microsoft.github.io/monaco-editor/docs.html#functions/editor.create.html
     */
    editor ? : object
    /**
     * An object specifying attributes to assign to the root element of this widget.
     * Set `null` value to attribute to remove it.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-elementAttributes)
     */
    elementAttributes ? : Record<string, string|null>
    extraData ? : any
    /**
     * When this widget is a child of a [Container](https://bryntum.com/products/gantt/docs/api/Core/widget/Container), it will by default be participating in a
     * flexbox layout. This config allows you to set this widget's
     * [flex](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) style.
     * This may be configured as a single number or a `&lt;flex-grow&gt; &lt;flex-shrink&gt; &lt;flex-basis&gt;` format string.
     * numeric-only values are interpreted as the `flex-grow` value.
     */
    flex ? : number|string
    /**
     * Set to `true` to move the widget out of the document flow and position it
     * absolutely in browser viewport space.
     */
    floating ? : boolean
    /**
     * Config object of a footer. May contain a `dock`, `html` and a `cls` property. A footer is not a widget,
     * but rather plain HTML that follows the last element of the panel's body and [strips](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-strips).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-footer)
     * @property {'top','right','bottom','left','start','end'} dock Where to dock
     * @property {string} html Html to populate the footer with
     * @property {string} cls CSS class to add to the footer
     */
    footer ? : object|string
    /**
     * A config [object](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#typedef-PanelHeader) for the panel's header or a string in place of a `title`.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-header)
     */
    header ? : string|boolean|PanelHeader
    /**
     * Widget's height, used to set element `style.height`. Either specify a valid height string or a number,
     * which will get 'px' appended. We recommend using CSS as the primary way to control height, but in some
     * cases this config is convenient.
     */
    height ? : string|number
    /**
     * Configure with true to make widget initially hidden.
     */
    hidden ? : boolean
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-hideAnimation)
     */
    hideAnimation ? : boolean|object
    /**
     * Specify `true` to make this container hide when it has no visible children (Either empty
     * or all children hidden).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-hideWhenEmpty)
     */
    hideWhenEmpty ? : boolean
    /**
     * The HTML to display initially or a function returning the markup (called at widget construction time).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-html)
     * @param {Core.widget.Widget} widget The calling Widget
     */
    html ? : string|((widget: Widget) => void)|DomConfig|DomConfig[]|VueConfig|ReactJSX
    /**
     * The CSS class(es) to add when HTML content is being applied to this widget.
     */
    htmlCls ? : string|object
    /**
     * An icon to show before the [title](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-title). Either pass a CSS class as a string, or pass a
     * [DomConfig](https://bryntum.com/products/gantt/docs/api/Core/helper/DomHelper#typedef-DomConfig) object describing an element to represent the icon.
     */
    icon ? : string|DomConfig
    /**
     * Widget id, if not specified one will be generated. Also used for lookups through Widget.getById
     */
    id ? : string
    /**
     * Determines if the widgets read-only state should be controlled by its parent.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-ignoreParentReadOnly)
     */
    ignoreParentReadOnly ? : boolean
    /**
     * Convenience setting to align input fields of child widgets. By default, the Field input element is
     * placed immediately following the `label`. If you prefer to have all input fields aligned to the
     * right, set this config to `'end'`.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-inputFieldAlign)
     */
    inputFieldAlign ? : 'start'|'end'
    /**
     * Element (or element id) to insert this widget before. If provided, [appendTo](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-appendTo) config is ignored.
     */
    insertBefore ? : HTMLElement|string
    /**
     * Element (or element id) to append this widget element to, as a first child. If provided, [appendTo](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-appendTo) config is ignored.
     */
    insertFirst ? : HTMLElement|string
    /**
     * An optional CSS class to add to child items of this container.
     */
    itemCls ? : string
    /**
     * An object containing typed child widget config objects or Widgets. May also be specified
     * as an array.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-items)
     */
    items ? : Record<string, ContainerItemConfig|MenuItemEntry>|(ContainerItemConfig|MenuItemEntry|Widget)[]
    /**
     * An object whose keys are the [key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) name
     * and optional modifier prefixes: `'Ctrl+'`, `'Alt+'`, `'Meta+'`, and `'Shift+'` (case-insensitive). The values
     * are the name of the instance method to call when the keystroke is received.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-keyMap)
     */
    keyMap ? : Record<string, KeyMapConfig>
    /**
     * Convenience setting to use same label placement on all child widgets.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-labelPosition)
     */
    labelPosition ? : 'before'|'above'|'align-before'|'auto'|null
    /**
     * Sets `labelWidth´ for all children of this Container, that does not define their own `labelWidth`.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-labelWidth)
     */
    labelWidth ? : number|null
    /**
     * The language being edited may be set and read using this property.
     */
    language ? : string
    /**
     * The short name of a helper class which manages rendering and styling of child items.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-layout)
     */
    layout ? : string|ContainerLayoutConfig
    /**
     * The CSS style properties to apply to the [contentElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-contentElement).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-layoutStyle)
     */
    layoutStyle ? : object
    /**
     * An array of [child item](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#config-items) *config objects* which is to be converted into
     * instances only when this Container is rendered, rather than eagerly at construct time.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-lazyItems)
     */
    lazyItems ? : Record<string, ContainerItemConfig>|ContainerItemConfig[]|Widget[]
    /**
     * The listener set for this object.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-listeners)
     */
    listeners ? : CodeEditorListeners
    /**
     * A class translations of which are used for translating this entity.
     * This is often used when translations of an item are defined on its container class.
     * For example:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-localeClass)
     */
    localeClass ? : typeof Base
    /**
     * Set to `false` to disable localization of this object.
     */
    localizable ? : boolean
    /**
     * List of properties which values should be translated automatically upon a locale applying.
     * In case there is a need to localize not typical value (not a String value or a field with re-defined setter/getter),
     * you could use 'localeKey' meta configuration.
     * Example:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-localizableProperties)
     */
    localizableProperties ? : string[]
    /**
     * Widget's margin. This may be configured as a single number or a `TRBL` format string.
     * numeric-only values are interpreted as pixels.
     */
    margin ? : number|string
    /**
     * This config object contains the defaults for the [Mask](https://bryntum.com/products/gantt/docs/api/Core/widget/Mask) created for the
     * [masked](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-masked) config. Any properties specified in the `masked` config will override these
     * values.
     */
    maskDefaults ? : MaskConfig
    /**
     * Set to `true` to apply the default mask to the widget. Alternatively, this can be the mask message or a
     * [Mask](https://bryntum.com/products/gantt/docs/api/Core/widget/Mask) config object.
     */
    masked ? : boolean|string|MaskConfig
    /**
     * The element's maxHeight. Can be either a String or a Number (which will have 'px' appended). Note that
     * like [height](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-height), *reading* the value will return the numeric value in pixels.
     */
    maxHeight ? : string|number
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-maximizeOnMobile)
     */
    maximizeOnMobile ? : number|string
    /**
     * The elements maxWidth. Can be either a String or a Number (which will have 'px' appended). Note that
     * like [width](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-width), *reading* the value will return the numeric value in pixels.
     */
    maxWidth ? : string|number
    /**
     * The element's minHeight. Can be either a String or a Number (which will have 'px' appended). Note that
     * like [height](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-height), *reading* the value will return the numeric value in pixels.
     */
    minHeight ? : string|number
    /**
     * The elements minWidth. Can be either a String or a Number (which will have 'px' appended). Note that
     * like [width](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-width), *reading* the value will return the numeric value in pixels.
     */
    minWidth ? : string|number
    /**
     * When this is configured as `true` a [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
     * is used to monitor this element for size changes caused by either style manipulation, or by CSS
     * layout.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-monitorResize)
     * @property {boolean} immediate Set to `true` to receive resize notifications immediately.
     */
    monitorResize ? : boolean|object
    /**
     * An object containing default config objects which may be referenced by name in the [items](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#config-items)
     * config. For example, a specialized [Menu](https://bryntum.com/products/gantt/docs/api/Core/widget/Menu) subclass may have a `namedItems` default
     * value defined like this:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-namedItems)
     */
    namedItems ? : Record<string, ContainerItemConfig>
    /**
     * Set to `true` when a widget is rendered into another widget's [contentElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-contentElement), but must
     * not participate in the standard layout of that widget, and must be positioned relatively to that
     * widget's [contentElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-contentElement).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-positioned)
     */
    positioned ? : boolean
    /**
     * Prevent tooltip from being displayed on touch devices. Useful for example for buttons that display a
     * menu on click etc, since the tooltip would be displayed at the same time.
     */
    preventTooltipOnTouch ? : boolean
    /**
     * The read-only state of the editor may be set and read. This state is by default reflected
     * by an icon in the bottom toolbar.
     */
    readOnly ? : boolean
    /**
     * [Record](https://bryntum.com/products/gantt/docs/api/Core/data/Model) whose values will be used to populate fields in the container.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-record)
     */
    record ? : Model
    relayStoreEvents ? : boolean
    /**
     * Either a default `rendition` to apply to all child widgets, or a map of renditions keyed by child widget
     * `type`.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-rendition)
     */
    rendition ? : string|Record<string, string>|null
    /**
     * Configure as `true` to have the component display a translucent ripple when its
     * [focusElement](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-focusElement), or [element](#Core/widget/Widget#property-element) is tapped <em>if the
     * current theme supports ripples</em>. Out of the box, only the Material theme supports ripples.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-ripple)
     * @property {string} [delegate] A CSS selector to filter which child elements trigger ripples. By default, the ripple is clipped to the triggering element.
     * @property {string} [color] A CSS color name or specification.
     * @property {number} [radius] The ending radius of the ripple. Note that it will be clipped by the target element by default.
     * @property {string} [clip] A string which describes how to clip the ripple if it is not to be clipped to the default element. Either the property of the widget to use as the clipping element, or a selector to allow clipping to the closest matching ancestor to the target element.
     */
    ripple ? : boolean|object
    /**
     * The ARIA role to apply to this widget's element. By default, this is set to `'presentation'` to avoid
     * accidentally applying a role which may interfere with screen readers.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-role)
     */
    role ? : string
    /**
     * If you are rendering this widget to a shadow root inside a web component, set this config to the shadowRoot. If not inside a web component, set it to `document.body`
     */
    rootElement ? : ShadowRoot|HTMLElement
    /**
     * This may be configured as `true` to make the widget's element use the `direction:rtl` style.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-rtl)
     */
    rtl ? : boolean
    /**
     * Specifies whether (and optionally in which axes) a Widget may scroll. `true` means this widget may scroll
     * in both axes. May be an object containing boolean `overflowX` and `overflowY` properties which are
     * applied to CSS style properties `overflowX` and `overflowY`. If they are boolean, they are translated to
     * CSS overflow properties thus:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-scrollable)
     */
    scrollable ? : boolean|ScrollerConfig|Scroller
    /**
     * Defines what to do if document is scrolled while Widget is visible (only relevant when floating is set to `true`).
     * Valid values: ´null´: do nothing, ´hide´: hide the widget or ´realign´: realign to the target if possible.
     */
    scrollAction ? : 'hide'|'realign'|null
    /**
     * *Only valid if this Widget is [floating](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-floating).*
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-showAnimation)
     */
    showAnimation ? : boolean|object
    /**
     * Set to `false` to not show the tooltip when this widget is [disabled](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-disabled)
     */
    showTooltipWhenDisabled ? : boolean
    /**
     * Programmatic control over how many columns to span when used in a grid layout.
     */
    span ? : number
    /**
     * This value can be one of the following:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-stateful)
     */
    stateful ? : boolean|object|string[]
    /**
     * The events that, when fired by this component, should trigger it to save its state by calling
     * [saveState](https://bryntum.com/products/gantt/docs/api/Core/mixin/State#function-saveState).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-statefulEvents)
     */
    statefulEvents ? : object|string[]
    /**
     * The key to use when saving this object's state in the [stateProvider](https://bryntum.com/products/gantt/docs/api/Core/mixin/State#config-stateProvider). If this config is
     * not assigned, and [stateful](https://bryntum.com/products/gantt/docs/api/Core/mixin/State#config-stateful) is not set to `false`, the [id](#Core/widget/Widget#config-id)
     * (if explicitly specified) will be used as the `stateId`.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-stateId)
     */
    stateId ? : string
    /**
     * The `StateProvider` to use to save and restore this object's [state](https://bryntum.com/products/gantt/docs/api/Core/mixin/State#property-state). By default, `state`
     * will be saved using the [default state provider](https://bryntum.com/products/gantt/docs/api/Core/state/StateProvider#property-instance-static).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-stateProvider)
     */
    stateProvider ? : StateProvider
    /**
     * The status message displayed un the bottom toolbar may be set and read using this property.
     */
    status ? : string
    /**
     * Specify `true` to match fields by their `name` property only when assigning a [record](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#config-record),
     * without falling back to `ref`.
     */
    strictRecordMapping ? : boolean
    /**
     * An object containing widgets keyed by name. By default (when no `type` is given), strips are
     * [toolbars](https://bryntum.com/products/gantt/docs/api/Core/widget/Toolbar). If you want to pass an array, you can use
     * the toolbar's [items](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#config-items).
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-strips)
     */
    strips ? : Record<string, ContainerItemConfig>
    /**
     * A configuration for the [tab](https://bryntum.com/products/gantt/docs/api/Core/widget/Tab) created for this widget when it is placed in a
     * [TabPanel](https://bryntum.com/products/gantt/docs/api/Core/widget/TabPanel). For example, this config can be used to control the icon of the `tab` for
     * this widget:
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-tab)
     */
    tab ? : boolean|TabConfig
    /**
     * When this container is used as a tab in a TabPanel, these items are added to the
     * [TabBar](https://bryntum.com/products/gantt/docs/api/Core/widget/TabBar) when this container is the active tab.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-tabBarItems)
     */
    tabBarItems ? : ToolbarItems[]|Widget[]
    /**
     * The tag name of this Widget's root element
     */
    tag ? : string
    /**
     * A Config object representing the configuration of a [Toolbar](https://bryntum.com/products/gantt/docs/api/Core/widget/Toolbar),
     * or array of config objects representing the child items of a Toolbar.
     * This creates a toolbar docked to the top of the panel immediately below the header.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-tbar)
     */
    tbar ? : (ContainerItemConfig|string)[]|ToolbarConfig|PagingToolbarConfig|null
    /**
     * The text being edited may be set and read using this property.
     */
    text ? : string
    /**
     * Text alignment: 'left', 'center' or 'right'. Also accepts direction neutral 'start' and 'end'.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-textAlign)
     */
    textAlign ? : 'left'|'center'|'right'|'start'|'end'
    /**
     * Specify `true` for a container used to show text markup. It will apply the CSS class `b-text-content`
     * which specifies a default max-width that makes long text more readable.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-textContent)
     */
    textContent ? : boolean
    /**
     * The Monaco theme to use. If not specified, it defaults to `'vs'`;
     */
    theme ? : 'vs'|'vs-dark'|'hc-black'|'hc-light'
    /**
     * A title to display in the header or owning TabPanel. Causes creation and docking of a header
     * to the top if no header is configured.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-title)
     */
    title ? : string
    /**
     * The [tools](https://bryntum.com/products/gantt/docs/api/Core/widget/Tool) to add either before or after the `title` in the Panel header. Each
     * property name is the reference by which an instantiated tool may be retrieved from the live
     * `[tools](https://bryntum.com/products/gantt/docs/api/Core/widget/mixin/Toolable#property-tools)` property.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-tools)
     */
    tools ? : Record<string, ToolConfig>|null
    /**
     * Tooltip for the widget, either as a string or as a Tooltip config object.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-tooltip)
     */
    tooltip ? : string|TooltipConfig|null
    /**
     * By default, tabbing within a Panel is not contained, ie you can TAB out of the Panel
     * forwards or backwards.
     * Configure this as `true` to disallow tabbing out of the Panel, and make tabbing circular within this Panel.
     */
    trapFocus ? : boolean
    type ? : 'codeeditor'
    /**
     * Custom CSS class name suffixes to apply to the elements rendered by this widget. This may be specified
     * as a space separated string, an array of strings, or as an object in which property names with truthy
     * values are used as the class names.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-ui)
     */
    ui ? : 'plain'|'toolbar'|string|object
    /**
     * A widgets weight determines its position among siblings when added to a [Container](https://bryntum.com/products/gantt/docs/api/Core/widget/Container).
     * Higher weights go further down.
     */
    weight ? : number
    /**
     * Widget's width, used to set element `style.width`. Either specify a valid width string or a number, which
     * will get 'px' appended. We recommend using CSS as the primary way to control width, but in some cases
     * this config is convenient.
     */
    width ? : string|number
    /**
     * The x position for the widget.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-x)
     */
    x ? : number
    /**
     * The y position for the widget.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#config-y)
     */
    y ? : number

}

@Component({
    selector : 'bryntum-code-editor',
    template : ''
})
export class BryntumCodeEditorComponent implements OnInit, OnDestroy {

    public static instanceClass = CodeEditor;

    public static instanceName = 'CodeEditor';

    private static bryntumEvents: string[] = [
        'onBeforeDestroy',
        'onBeforeHide',
        'onBeforeSetRecord',
        'onBeforeShow',
        'onBeforeStateApply',
        'onBeforeStateSave',
        'onCatchAll',
        'onCollapse',
        'onDestroy',
        'onDirtyStateChange',
        'onElementCreated',
        'onExpand',
        'onFocusIn',
        'onFocusOut',
        'onHide',
        'onPaint',
        'onReadOnly',
        'onRecompose',
        'onResize',
        'onShow',
        'onToolClick'
    ];

    private static bryntumFeatureNames: string[] = [

    ];

    private static bryntumConfigs: string[] = BryntumCodeEditorComponent.bryntumFeatureNames.concat([
        'adopt',
        'align',
        'alignSelf',
        'anchor',
        'appendTo',
        'ariaDescription',
        'ariaLabel',
        'autoUpdateRecord',
        'bbar',
        'bodyCls',
        'border',
        'bubbleEvents',
        'callOnFunctions',
        'catchEventHandlerExceptions',
        'centered',
        'cls',
        'codePath',
        'collapsed',
        'collapsible',
        'color',
        'column',
        'config',
        'constrainTo',
        'content',
        'contentElementCls',
        'dataField',
        'dataset',
        'defaultBindProperty',
        'defaultFocus',
        'defaults',
        'detectCSSCompatibilityIssues',
        'disabled',
        'dock',
        'draggable',
        'drawer',
        'editor',
        'elementAttributes',
        'extraData',
        'flex',
        'floating',
        'footer',
        'header',
        'height',
        'hidden',
        'hideAnimation',
        'hideWhenEmpty',
        'html',
        'htmlCls',
        'icon',
        'id',
        'ignoreParentReadOnly',
        'inputFieldAlign',
        'insertBefore',
        'insertFirst',
        'itemCls',
        'items',
        'keyMap',
        'labelPosition',
        'labelWidth',
        'language',
        'layout',
        'layoutStyle',
        'lazyItems',
        'listeners',
        'localeClass',
        'localizable',
        'localizableProperties',
        'margin',
        'maskDefaults',
        'masked',
        'maxHeight',
        'maximizeOnMobile',
        'maxWidth',
        'minHeight',
        'minWidth',
        'monitorResize',
        'namedItems',
        'positioned',
        'preventTooltipOnTouch',
        'readOnly',
        'record',
        'relayStoreEvents',
        'rendition',
        'ripple',
        'role',
        'rootElement',
        'rtl',
        'scrollable',
        'scrollAction',
        'showAnimation',
        'showTooltipWhenDisabled',
        'span',
        'stateful',
        'statefulEvents',
        'stateId',
        'stateProvider',
        'status',
        'strictRecordMapping',
        'strips',
        'tab',
        'tabBarItems',
        'tag',
        'tbar',
        'text',
        'textAlign',
        'textContent',
        'theme',
        'title',
        'tools',
        'tooltip',
        'trapFocus',
        'type',
        'ui',
        'weight',
        'width',
        'x',
        'y'
    ]);

    private static bryntumConfigsOnly: string[] = [
        'adopt',
        'align',
        'anchor',
        'ariaDescription',
        'ariaLabel',
        'autoUpdateRecord',
        'bbar',
        'bodyCls',
        'border',
        'bubbleEvents',
        'centered',
        'codePath',
        'collapsible',
        'color',
        'config',
        'constrainTo',
        'contentElementCls',
        'dataField',
        'defaultBindProperty',
        'defaultFocus',
        'defaults',
        'detectCSSCompatibilityIssues',
        'dock',
        'draggable',
        'drawer',
        'editor',
        'elementAttributes',
        'floating',
        'footer',
        'header',
        'hideAnimation',
        'hideWhenEmpty',
        'htmlCls',
        'icon',
        'ignoreParentReadOnly',
        'itemCls',
        'lazyItems',
        'listeners',
        'localeClass',
        'localizable',
        'localizableProperties',
        'maskDefaults',
        'masked',
        'monitorResize',
        'namedItems',
        'positioned',
        'preventTooltipOnTouch',
        'relayStoreEvents',
        'ripple',
        'role',
        'rootElement',
        'scrollAction',
        'showAnimation',
        'showTooltipWhenDisabled',
        'stateful',
        'statefulEvents',
        'stateId',
        'stateProvider',
        'strips',
        'tab',
        'tabBarItems',
        'tag',
        'tbar',
        'textAlign',
        'textContent',
        'trapFocus',
        'type',
        'ui',
        'weight'
    ];

    private static bryntumProps: string[] = BryntumCodeEditorComponent.bryntumFeatureNames.concat([
        'alignSelf',
        'appendTo',
        'callOnFunctions',
        'catchEventHandlerExceptions',
        'cls',
        'collapsed',
        'column',
        'content',
        'dataset',
        'disabled',
        'extraData',
        'flex',
        'height',
        'hidden',
        'html',
        'id',
        'inputFieldAlign',
        'insertBefore',
        'insertFirst',
        'items',
        'keyMap',
        'labelPosition',
        'labelWidth',
        'language',
        'layout',
        'layoutStyle',
        'margin',
        'maxHeight',
        'maximizeOnMobile',
        'maxWidth',
        'minHeight',
        'minWidth',
        'parent',
        'readOnly',
        'record',
        'rendition',
        'rtl',
        'scrollable',
        'span',
        'state',
        'status',
        'strictRecordMapping',
        'text',
        'theme',
        'title',
        'tools',
        'tooltip',
        'values',
        'width',
        'x',
        'y'
    ]);

    private elementRef: ElementRef;
    public instance!: CodeEditor;

    private bryntumConfig = {
        adopt            : undefined,
        appendTo         : undefined,
        href             : undefined,
        angularComponent : this,
        features         : {},
        listeners        : {}
    };

    constructor(element: ElementRef) {
        this.elementRef = element;
    }

    // Configs only
    @Input() adopt                        ! : HTMLElement|string;
    @Input() align                        ! : AlignSpec|string;
    @Input() anchor                       ! : boolean;
    @Input() ariaDescription              ! : string;
    @Input() ariaLabel                    ! : string;
    @Input() autoUpdateRecord             ! : boolean;
    @Input() bbar                         ! : (ContainerItemConfig|string)[]|ToolbarConfig|PagingToolbarConfig|null;
    @Input() bodyCls                      ! : string|object;
    @Input() border                       ! : boolean;
    @Input() bubbleEvents                 ! : object;
    @Input() centered                     ! : boolean;
    @Input() codePath                     ! : string;
    @Input() collapsible                  ! : boolean|PanelCollapserConfig|PanelCollapserOverlayConfig;
    @Input() color                        ! : Color;
    @Input() config                       ! : object;
    @Input() constrainTo                  ! : HTMLElement|Widget|Rectangle;
    @Input() contentElementCls            ! : string|object;
    @Input() dataField                    ! : string;
    @Input() defaultBindProperty          ! : string;
    @Input() defaultFocus                 ! : ((widget: Widget) => boolean)|string;
    @Input() defaults                     ! : ContainerItemConfig;
    @Input() detectCSSCompatibilityIssues ! : boolean;
    @Input() dock                         ! : 'top'|'bottom'|'left'|'right'|'start'|'end'|'header'|'pre-header'|object;
    @Input() draggable                    ! : boolean|object;
    @Input() drawer                       ! : boolean|{ side?: 'start'|'left'|'end'|'right'|'top'|'bottom', size?: string|number, inline?: boolean, autoClose?: boolean|{ mousedown?: boolean|string, focusout?: boolean|string, mouseout?: string }, autoCloseDelay?: number };
    @Input() editor                       ! : object;
    @Input() elementAttributes            ! : Record<string, string|null>;
    @Input() floating                     ! : boolean;
    @Input() footer                       ! : object|string;
    @Input() header                       ! : string|boolean|PanelHeader;
    @Input() hideAnimation                ! : boolean|object;
    @Input() hideWhenEmpty                ! : boolean;
    @Input() htmlCls                      ! : string|object;
    @Input() icon                         ! : string|DomConfig;
    @Input() ignoreParentReadOnly         ! : boolean;
    @Input() itemCls                      ! : string;
    @Input() lazyItems                    ! : Record<string, ContainerItemConfig>|ContainerItemConfig[]|Widget[];
    @Input() listeners                    ! : CodeEditorListeners;
    @Input() localeClass                  ! : typeof Base;
    @Input() localizable                  ! : boolean;
    @Input() localizableProperties        ! : string[];
    @Input() maskDefaults                 ! : MaskConfig;
    @Input() masked                       ! : boolean|string|MaskConfig;
    @Input() monitorResize                ! : boolean|object;
    @Input() namedItems                   ! : Record<string, ContainerItemConfig>;
    @Input() positioned                   ! : boolean;
    @Input() preventTooltipOnTouch        ! : boolean;
    @Input() relayStoreEvents             ! : boolean;
    @Input() ripple                       ! : boolean|object;
    @Input() role                         ! : string;
    @Input() rootElement                  ! : ShadowRoot|HTMLElement;
    @Input() scrollAction                 ! : 'hide'|'realign'|null;
    @Input() showAnimation                ! : boolean|object;
    @Input() showTooltipWhenDisabled      ! : boolean;
    @Input() stateful                     ! : boolean|object|string[];
    @Input() statefulEvents               ! : object|string[];
    @Input() stateId                      ! : string;
    @Input() stateProvider                ! : StateProvider;
    @Input() strips                       ! : Record<string, ContainerItemConfig>;
    @Input() tab                          ! : boolean|TabConfig;
    @Input() tabBarItems                  ! : ToolbarItems[]|Widget[];
    @Input() tag                          ! : string;
    @Input() tbar                         ! : (ContainerItemConfig|string)[]|ToolbarConfig|PagingToolbarConfig|null;
    @Input() textAlign                    ! : 'left'|'center'|'right'|'start'|'end';
    @Input() textContent                  ! : boolean;
    @Input() trapFocus                    ! : boolean;
    @Input() type                         ! : 'codeeditor';
    @Input() ui                           ! : 'plain'|'toolbar'|string|object;
    @Input() weight                       ! : number;

    // Configs and properties
    @Input() alignSelf                   ! : string;
    @Input() appendTo                    ! : HTMLElement|string;
    @Input() callOnFunctions             ! : boolean;
    @Input() catchEventHandlerExceptions ! : boolean;
    @Input() cls                         ! : string|object;
    @Input() collapsed                   ! : boolean;
    @Input() column                      ! : number;
    @Input() content                     ! : string;
    @Input() dataset                     ! : object|Record<string, string>;
    @Input() disabled                    ! : boolean|'inert';
    @Input() extraData                   ! : any;
    @Input() flex                        ! : number|string;
    @Input() height                      ! : number|string;
    @Input() hidden                      ! : boolean;
    @Input() html                        ! : string|((widget: Widget) => void)|DomConfig|DomConfig[]|VueConfig|ReactJSX|(string|((widget: Widget) => void)|DomConfig|DomConfig[]|VueConfig|ReactJSX);
    @Input() id                          ! : string;
    @Input() inputFieldAlign             ! : 'start'|'end';
    @Input() insertBefore                ! : HTMLElement|string;
    @Input() insertFirst                 ! : HTMLElement|string;
    @Input() items                       ! : (ContainerItemConfig|MenuItemConfig|Widget)[]|Record<string, ContainerItemConfig|MenuItemConfig>|Widget[]|Record<string, ContainerItemConfig|MenuItemEntry>|(ContainerItemConfig|MenuItemEntry|Widget)[];
    @Input() keyMap                      ! : Record<string, KeyMapConfig>;
    @Input() labelPosition               ! : 'before'|'above'|'align-before'|'auto'|null;
    @Input() labelWidth                  ! : number|null;
    @Input() language                    ! : string;
    @Input() layout                      ! : Layout|string|ContainerLayoutConfig;
    @Input() layoutStyle                 ! : object;
    @Input() margin                      ! : number|string;
    @Input() maxHeight                   ! : string|number;
    @Input() maximizeOnMobile            ! : number|string;
    @Input() maxWidth                    ! : string|number;
    @Input() minHeight                   ! : string|number;
    @Input() minWidth                    ! : string|number;
    @Input() readOnly                    ! : boolean;
    @Input() record                      ! : Model;
    @Input() rendition                   ! : string|Record<string, string>|null;
    @Input() rtl                         ! : boolean;
    @Input() scrollable                  ! : Scroller|boolean|ScrollerConfig;
    @Input() span                        ! : number;
    @Input() status                      ! : string;
    @Input() strictRecordMapping         ! : boolean;
    @Input() text                        ! : string;
    @Input() theme                       ! : 'vs'|'vs-dark'|'hc-black'|'hc-light';
    @Input() title                       ! : string;
    @Input() tools                       ! : Record<string, Tool|ToolConfig>|null|Record<string, Tool>|Record<string, ToolConfig>;
    @Input() tooltip                     ! : string|TooltipConfig|null;
    @Input() width                       ! : number|string;
    @Input() x                           ! : number;
    @Input() y                           ! : number;

    // Properties only
    @Input() parent ! : Widget;
    @Input() state  ! : any;
    @Input() values ! : Record<string, object>;

    // Events emitters
    /**
     * Fires before an object is destroyed.
     * @param {object} event Event object
     * @param {Core.Base} event.source The Object that is being destroyed.
     */
    @Output() onBeforeDestroy: any = new EventEmitter<((event: { source: Base }) => void)|string>();
    /**
     * Triggered before a widget is hidden. Return `false` to prevent the action.
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source The widget being hidden.
     */
    @Output() onBeforeHide: any = new EventEmitter<((event: { source: Widget }) => Promise<boolean>|boolean|void)|string>();
    /**
     * Fired before this container will load record values into its child fields. This is useful if you
     * want to modify the UI before data is loaded (e.g. set some input field to be readonly)
     * @param {object} event Event object
     * @param {Core.widget.Container} event.source The container
     * @param {Core.data.Model} event.record The record
     */
    @Output() onBeforeSetRecord: any = new EventEmitter<((event: { source: Container, record: Model }) => void)|string>();
    /**
     * Triggered before a widget is shown. Return `false` to prevent the action.
     * @param {object} event Event object
     * @param {Core.widget.Widget,any} event.source The widget being shown
     */
    @Output() onBeforeShow: any = new EventEmitter<((event: { source: Widget|any }) => Promise<boolean>|boolean|void)|string>();
    /**
     * Fired before state is applied to the source. Allows editing the state object or preventing the operation.
     * @param {object} event Event object
     * @param {any} event.state State object config
     */
    @Output() onBeforeStateApply: any = new EventEmitter<((event: { state: any }) => Promise<boolean>|boolean|void)|string>();
    /**
     * Fired before state is saved by the StateProvider. Allows editing the state object or preventing the operation.
     * @param {object} event Event object
     * @param {any} event.state State object config
     */
    @Output() onBeforeStateSave: any = new EventEmitter<((event: { state: any }) => Promise<boolean>|boolean|void)|string>();
    /**
     * Fires when any other event is fired from the object.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#event-catchAll)
     * @param {object} event Event object
     * @param {{[key: string]: any, type: string}} event.event The Object that contains event details
     * @param {string} event.event.type The type of the event which is caught by the listener
     */
    @Output() onCatchAll: any = new EventEmitter<((event: {[key: string]: any, type: string}) => void)|string>();
    /**
     * Fires when a Panel is collapsed using the [collapsible](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-collapsible) setting.
     * @param {object} event Event object
     * @param {Core.widget.Panel} event.source This Panel.
     */
    @Output() onCollapse: any = new EventEmitter<((event: { source: Panel }) => void)|string>();
    /**
     * Fires when an object is destroyed.
     * @param {object} event Event object
     * @param {Core.Base} event.source The Object that is being destroyed.
     */
    @Output() onDestroy: any = new EventEmitter<((event: { source: Base }) => void)|string>();
    /**
     * Fires when a field is mutated and the state of the [hasChanges](https://bryntum.com/products/gantt/docs/api/Core/widget/Container#property-hasChanges) property changes
     * @param {object} event Event object
     * @param {Core.widget.Container} event.source The container.
     * @param {boolean} event.dirty The dirty state of the Container - `true` if there are any fields which have been changed since initial load.
     */
    @Output() onDirtyStateChange: any = new EventEmitter<((event: { source: Container, dirty: boolean }) => void)|string>();
    /**
     * Triggered when a widget's [element](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#property-element) is available.
     * @param {object} event Event object
     * @param {HTMLElement} event.element The Widget's element.
     */
    @Output() onElementCreated: any = new EventEmitter<((event: { element: HTMLElement }) => void)|string>();
    /**
     * Fires when a Panel is expanded using the [collapsible](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-collapsible) setting.
     * @param {object} event Event object
     * @param {Core.widget.Panel} event.source This Panel.
     */
    @Output() onExpand: any = new EventEmitter<((event: { source: Panel }) => void)|string>();
    /**
     * Fired when focus enters this Widget.
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source This Widget
     * @param {HTMLElement} event.fromElement The element which lost focus.
     * @param {HTMLElement} event.toElement The element which gained focus.
     * @param {Core.widget.Widget} event.fromWidget The widget which lost focus.
     * @param {Core.widget.Widget} event.toWidget The widget which gained focus.
     * @param {boolean} event.backwards `true` if the `toElement` is before the `fromElement` in document order.
     */
    @Output() onFocusIn: any = new EventEmitter<((event: { source: Widget, fromElement: HTMLElement, toElement: HTMLElement, fromWidget: Widget, toWidget: Widget, backwards: boolean }) => void)|string>();
    /**
     * Fired when focus exits this Widget's ownership tree. This is different from a `blur` event.
     * focus moving from within this Widget's ownership tree, even if there are floating widgets
     * will not trigger this event. This is when focus exits this widget completely.
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source This Widget
     * @param {HTMLElement} event.fromElement The element which lost focus.
     * @param {HTMLElement} event.toElement The element which gained focus.
     * @param {Core.widget.Widget} event.fromWidget The widget which lost focus.
     * @param {Core.widget.Widget} event.toWidget The widget which gained focus.
     * @param {boolean} event.backwards `true` if the `toElement` is before the `fromElement` in document order.
     */
    @Output() onFocusOut: any = new EventEmitter<((event: { source: Widget, fromElement: HTMLElement, toElement: HTMLElement, fromWidget: Widget, toWidget: Widget, backwards: boolean }) => void)|string>();
    /**
     * Triggered after a widget was hidden
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source The widget
     */
    @Output() onHide: any = new EventEmitter<((event: { source: Widget }) => void)|string>();
    /**
     * Triggered when a widget which had been in a non-visible state for any reason
     * achieves visibility.
     * [More...](https://bryntum.com/products/gantt/docs/api/Core/widget/CodeEditor#event-paint)
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source The widget being painted.
     * @param {boolean} event.firstPaint `true` if this is the first paint.
     */
    @Output() onPaint: any = new EventEmitter<((event: { source: Widget, firstPaint: boolean }) => void)|string>();
    /**
     * Fired when a Widget's read only state is toggled
     * @param {object} event Event object
     * @param {boolean} event.readOnly Read only or not
     */
    @Output() onReadOnly: any = new EventEmitter<((event: { readOnly: boolean }) => void)|string>();
    /**
     * This event is fired after a widget's elements have been synchronized due to a direct or indirect call
     * to [recompose](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#function-recompose), if this results in some change to the widget's rendered DOM elements.
     */
    @Output() onRecompose: any = new EventEmitter<(() => void)|string>();
    /**
     * Fired when the encapsulating element of a Widget resizes *only when [monitorResize](https://bryntum.com/products/gantt/docs/api/Core/widget/Widget#config-monitorResize) is `true`*.
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source This Widget
     * @param {number} event.width The new width
     * @param {number} event.height The new height
     * @param {number} event.oldWidth The old width
     * @param {number} event.oldHeight The old height
     */
    @Output() onResize: any = new EventEmitter<((event: { source: Widget, width: number, height: number, oldWidth: number, oldHeight: number }) => void)|string>();
    /**
     * Triggered after a widget is shown.
     * @param {object} event Event object
     * @param {Core.widget.Widget} event.source The widget
     */
    @Output() onShow: any = new EventEmitter<((event: { source: Widget }) => void)|string>();
    /**
     * A header [tool](https://bryntum.com/products/gantt/docs/api/Core/widget/Panel#config-tools) has been clicked.
     * @param {object} event Event object
     * @param {Core.widget.Tool} event.source This Panel.
     * @param {Core.widget.Tool} event.tool The tool which is being clicked.
     */
    @Output() onToolClick: any = new EventEmitter<((event: { source: Tool, tool: Tool }) => void)|string>();

    /**
     * Create and append the underlying widget
     */
    ngOnInit(): void {
        const
            me = this,
            {
                elementRef,
                bryntumConfig
            } = me,
            {
                instanceClass,
                instanceName,
                bryntumConfigs,
                bryntumEvents
            } = BryntumCodeEditorComponent;

        bryntumConfigs.filter(prop => prop in this).forEach(prop => {
            // @ts-ignore
            WrapperHelper.applyPropValue(bryntumConfig, prop, this[prop]);
            if (['features', 'config'].includes(prop)) {
                WrapperHelper.devWarningConfigProp(instanceName, prop);
            }
        });
        // @ts-ignore
        bryntumEvents.filter(event => this[event] && this[event].observers.length > 0).forEach(event => {
            const
                uncapitalize = (str: string) => str.charAt(0).toLowerCase() + str.slice(1),
                eventName = (str: string) => uncapitalize(str.slice(2));

            // @ts-ignore
            bryntumConfig.listeners[eventName(event)] = e => {
                // @ts-ignore
                me[event].emit(e);
                // EventEmitter does not return values in the normal way, work around it by setting `returnValue` flag
                // in Angular listeners
                return e.returnValue;
            };
        });

        // If component has no container specified in config then use adopt to Wrapper's element
        const
            containerParam = [
                'adopt',
                'appendTo',
                'insertAfter',
                'insertBefore'
                // @ts-ignore
            ].find(prop => bryntumConfig[prop]);
        if (!containerParam) {
            if (instanceName === 'Button' || elementRef.nativeElement.getRootNode() instanceof ShadowRoot) {
                // Button should always be <a> or <button> inside owner element
                bryntumConfig.appendTo = elementRef.nativeElement;
            }
            else {
                bryntumConfig.adopt = elementRef.nativeElement;
            }
        }
        else {
            WrapperHelper.devWarningContainer(instanceName, containerParam);
        }

        // In shadow DOM (e.g. Angular ViewEncapsulation.ShadowDom), theme CSS from document.head
        // does not cascade into the shadow root. Inject a matching <link> so Bryntum's CSS check
        // finds the theme. The @font-face rules from component styles are also extracted to
        // document scope so document.fonts detects them (shadow-root @font-face is not reliably
        // included in document.fonts across all browsers).
        const shadowRoot = elementRef.nativeElement.getRootNode();
        if (shadowRoot instanceof ShadowRoot) {
            initThemeInShadowRoots();
            BryntumCodeEditorComponent.ensureFontsInDocument(shadowRoot);
        }

        // @ts-ignore
        me.instance = instanceName === 'Widget' ? Widget.create(bryntumConfig) : new instanceClass(bryntumConfig);

    }

    /**
     * Extracts all @font-face declarations from a shadow root's stylesheets and adds them to
     * document.head as a single <style> element. This is needed because @font-face rules inside
     * a shadow root are not reliably included in document.fonts across all browsers, causing
     * Bryntum's CSS compatibility check to incorrectly report missing fonts.
     * Safe to call multiple times — the extraction runs only once per page.
     */
    private static ensureFontsInDocument(shadowRoot: ShadowRoot): void {
        if (document.querySelector('#b-shadow-root-fonts')) {
            return;
        }

        const fontFaceRules: string[] = [];

        const extractFromSheet = (sheet: CSSStyleSheet): void => {
            try {
                const rules = sheet.cssRules;
                for (let i = 0; i < rules.length; i++) {
                    if (rules[i].type === CSSRule.FONT_FACE_RULE) {
                        fontFaceRules.push(rules[i].cssText);
                    }
                }
            }
            catch (_e) {
                // Cross-origin access may throw; silently skip
            }
        };

        // adoptedStyleSheets (Angular 14+ / modern browsers)
        const adoptedSheets: CSSStyleSheet[] = (shadowRoot as any).adoptedStyleSheets ?? [];
        adoptedSheets.forEach(sheet => extractFromSheet(sheet));

        // <style> elements (older Angular or fallback)
        shadowRoot.querySelectorAll('style').forEach(el => {
            if (el.sheet) {
                extractFromSheet(el.sheet);
            }
        });

        if (fontFaceRules.length > 0) {
            const style = document.createElement('style');
            style.id = 'b-shadow-root-fonts';
            style.textContent = fontFaceRules.join('\n');
            document.head.appendChild(style);
        }
    }

    /**
     * Watch for changes
     * @param changes
     */
    ngOnChanges(changes: SimpleChanges): void {
        const
            { instance } = this,
            { instanceName } = BryntumCodeEditorComponent;
        if (!instance) {
            return;
        }
        // Iterate over all changes
        Object.entries(changes).forEach(([prop, change]) => {
            const
                newValue = (change as SimpleChange).currentValue,
                { instance } = this,
                { bryntumConfigsOnly, bryntumProps } = BryntumCodeEditorComponent;
            if (bryntumProps.includes(prop)) {
                WrapperHelper.applyPropValue(instance, prop, newValue, false);
                if (bryntumConfigsOnly.includes(prop)) {
                    WrapperHelper.devWarningUpdateProp(instanceName, prop);
                }
            }
        });
    }

    /**
     * Destroy the component
     */
    ngOnDestroy(): void {
        // @ts-ignore
        if (this.instance && this.instance.destroy) {
            this.instance.destroy();
        }
    }
}
