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,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ;gBACzB,CAAC,CAAC,CAAC,CACD,MAAM,EACN;oBACC,GAAG,EAAE,QAAQ;oBACb,KAAK;oBACL,OAAO,oBACH,OAAO,IACV,sBAAsB,kBACrB,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IACzB,mBAAmB,IAEvB;oBACD,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE;oBACnC,KAAK,EAAE,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK;oBACnE,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,IAAI,CAAC,OAAO;iBACrB,EACD,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CACtE;gBACH,CAAC,CAAC,IAAI;SACP,CACD,CAAC;IACH,CAAC;CACD,CAAA;AA/HoB,IAAI;IADxB,KAAK,CAAC,GAAG,CAAC;GACU,IAAI,CA+HxB;eA/HoB,IAAI","sourcesContent":["import WidgetBase from '@dojo/framework/core/WidgetBase';\nimport { v, w } from '@dojo/framework/core/vdom';\nimport { FocusMixin, FocusProperties } from '@dojo/framework/core/mixins/Focus';\nimport I18nMixin from '@dojo/framework/core/mixins/I18n';\nimport ThemedMixin, { theme } from '@dojo/framework/core/mixins/Themed';\nimport { DNode } from '@dojo/framework/core/interfaces';\nimport { uuid } from '@dojo/framework/core/util';\nimport { Keys } from '../common/util';\nimport TextInput from '../text-input/index';\nimport Button from '../button/index';\nimport Icon from '../icon/index';\n\nimport bundle from './nls/Grid';\nimport * as fixedCss from './styles/cell.m.css';\nimport * as css from '../theme/default/grid-cell.m.css';\n\nexport interface CellProperties extends FocusProperties {\n\t/** The display value (or widget) of the cell */\n\tvalue: string | DNode;\n\t/** If the cell's value may be updated */\n\teditable?: boolean;\n\t/** The underlying string value of the cell (used by the editor) */\n\trawValue: string;\n\t/** Called when the Cell's value is saved by the editor */\n\tupdater: (value: any) => void;\n\t/** The width (in pixels) */\n\twidth?: number;\n}\n\n@theme(css)\nexport default class Cell extends I18nMixin(ThemedMixin(FocusMixin(WidgetBase)))<CellProperties> {\n\tprivate _editing = false;\n\tprivate _editingValue = '';\n\tprivate _focusKey!: string;\n\tprivate _idBase = uuid();\n\n\tprivate _callFocus(key: string) {\n\t\tthis._focusKey = key;\n\t\tthis.focus();\n\t}\n\n\tprivate _onEdit = () => {\n\t\tconst { editable } = this.properties;\n\t\tif (editable) {\n\t\t\tthis._editing = true;\n\t\t\tthis._callFocus('input');\n\t\t\tthis._editingValue = this.properties.rawValue;\n\t\t\tthis.invalidate();\n\t\t}\n\t};\n\n\tprivate _onBlur() {\n\t\tif (this._editing) {\n\t\t\tthis._onSave();\n\t\t}\n\t}\n\n\tprivate _onInput(value: string) {\n\t\tthis._editingValue = value;\n\t}\n\n\tprivate _onKeyDown(key: number) {\n\t\tif (key === Keys.Enter) {\n\t\t\tthis._onSave();\n\t\t\tthis._callFocus('button');\n\t\t} else if (key === Keys.Escape) {\n\t\t\tthis._editing = false;\n\t\t\tthis._callFocus('button');\n\t\t\tthis.invalidate();\n\t\t}\n\t}\n\n\tprivate _onSave() {\n\t\tthis._editing = false;\n\t\tthis.properties.updater(this._editingValue);\n\t\tthis.invalidate();\n\t}\n\n\tprotected renderContent(): DNode {\n\t\tconst { value } = this.properties;\n\t\treturn v(\n\t\t\t'div',\n\t\t\t{\n\t\t\t\tkey: 'content',\n\t\t\t\tid: this._idBase,\n\t\t\t\tondblclick: this._onEdit\n\t\t\t},\n\t\t\t[value]\n\t\t);\n\t}\n\n\tprotected render(): DNode {\n\t\tlet { editable, rawValue, theme, classes, width } = this.properties;\n\t\tconst { format, messages } = this.localizeBundle(bundle);\n\n\t\tconst passedInputClasses = (classes && classes['@dojo/widgets/text-input']) || {};\n\t\tconst passedButtonClasses = (classes && classes['@dojo/widgets/button']) || {};\n\n\t\treturn v(\n\t\t\t'div',\n\t\t\t{\n\t\t\t\trole: 'cell',\n\t\t\t\tstyles: width\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tflex: `0 1 ${width}px`\n\t\t\t\t\t  }\n\t\t\t\t\t: {},\n\t\t\t\tclasses: [this.theme(css.root), fixedCss.rootFixed]\n\t\t\t},\n\t\t\t[\n\t\t\t\tthis._editing\n\t\t\t\t\t? w(\n\t\t\t\t\t\t\tTextInput,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkey: 'input',\n\t\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\t\tclasses: {\n\t\t\t\t\t\t\t\t\t...classes,\n\t\t\t\t\t\t\t\t\t'@dojo/widgets/text-input': {\n\t\t\t\t\t\t\t\t\t\tinput: [this.theme(css.input)],\n\t\t\t\t\t\t\t\t\t\t...passedInputClasses\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tlabelHidden: true,\n\t\t\t\t\t\t\t\tfocus: this._focusKey === 'input' ? this.shouldFocus : () => false,\n\t\t\t\t\t\t\t\tinitialValue: this._editingValue,\n\t\t\t\t\t\t\t\tonValue: this._onInput,\n\t\t\t\t\t\t\t\tonBlur: this._onBlur,\n\t\t\t\t\t\t\t\tonKeyDown: this._onKeyDown\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[{ label: format('editValue', { value: rawValue }) }]\n\t\t\t\t\t  )\n\t\t\t\t\t: this.renderContent(),\n\t\t\t\teditable && !this._editing\n\t\t\t\t\t? w(\n\t\t\t\t\t\t\tButton,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkey: 'button',\n\t\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\t\tclasses: {\n\t\t\t\t\t\t\t\t\t...classes,\n\t\t\t\t\t\t\t\t\t'@dojo/widgets/button': {\n\t\t\t\t\t\t\t\t\t\troot: [this.theme(css.edit)],\n\t\t\t\t\t\t\t\t\t\t...passedButtonClasses\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\taria: { describedby: this._idBase },\n\t\t\t\t\t\t\t\tfocus: this._focusKey === 'button' ? this.shouldFocus : () => false,\n\t\t\t\t\t\t\t\ttype: 'button',\n\t\t\t\t\t\t\t\tonClick: this._onEdit\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[w(Icon, { type: 'editIcon', altText: messages.edit, classes, theme })]\n\t\t\t\t\t  )\n\t\t\t\t\t: null\n\t\t\t]\n\t\t);\n\t}\n}\n"]}