@operato/input 1.11.3 → 1.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,7 @@ export class OxInputCode extends OxFormField {
57
57
 
58
58
  private _self_changing: boolean = false
59
59
  private _editor?: EditorView
60
+ private _changed: boolean = false
60
61
 
61
62
  updated(changes: PropertyValues<this>) {
62
63
  if (changes.has('value') && this.editor && !this._self_changing) {
@@ -95,25 +96,15 @@ export class OxInputCode extends OxFormField {
95
96
  oneDark,
96
97
  syntaxHighlighting(oneDarkHighlightStyle),
97
98
  highlightActiveLine(),
98
- keymap.of([
99
- ...historyKeymap,
100
- indentWithTab,
101
- {
102
- key: 'Escape',
103
- run: (view: EditorView) => {
104
- togglefullscreen(this)
105
- return true
106
- }
107
- }
108
- ]),
109
- EditorView.updateListener.of(v => {
99
+ keymap.of([...historyKeymap, indentWithTab]),
100
+ EditorView.updateListener.of(async v => {
110
101
  if (v.docChanged) {
111
102
  this._self_changing = true
112
- this.value = v.state.doc.toString()
113
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
114
- requestAnimationFrame(() => {
115
- this._self_changing = false
116
- })
103
+ this._changed = true
104
+
105
+ await this.updateComplete
106
+
107
+ this._self_changing = false
117
108
  }
118
109
  })
119
110
  ],
@@ -121,6 +112,32 @@ export class OxInputCode extends OxFormField {
121
112
  })
122
113
  }
123
114
 
115
+ this._editor.contentDOM.addEventListener('keydown', event => {
116
+ event.stopPropagation()
117
+
118
+ if (event.key === 'Escape') {
119
+ togglefullscreen(this._editor!.contentDOM)
120
+ }
121
+ })
122
+
123
+ this._editor.contentDOM.addEventListener('blur', e => {
124
+ if (!this._changed) {
125
+ return
126
+ }
127
+
128
+ this.value = this._editor!.state.doc.toString()
129
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
130
+ })
131
+
132
+ // this._editor.contentDOM.addEventListener('change', async e => {
133
+ // this._self_changing = true
134
+ // this._changed = true
135
+
136
+ // await this.updateComplete
137
+
138
+ // this._self_changing = false
139
+ // })
140
+
124
141
  return this._editor
125
142
  }
126
143
  }