minitel-standalone
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -9,2 +9,3 @@ "use strict"; | ||
const locationdescriptor_js_1 = require("../locationdescriptor.js"); | ||
const invalidrender_js_1 = require("./invalidrender.js"); | ||
class MinitelObject extends node_events_1.EventEmitter { | ||
@@ -20,3 +21,9 @@ constructor(children, attributes, minitel) { | ||
} | ||
this.attributes = attributes; | ||
this.attributes = new Proxy(attributes, { | ||
set: (function (target, prop, val) { | ||
target[prop] = val; | ||
this.minitel.invalidateRender(); | ||
return true; | ||
}).bind(this), | ||
}); | ||
} | ||
@@ -47,2 +54,5 @@ appendChild(child) { | ||
let result = this.render(attributes, (0, utils_js_1.inheritedProps)(Object.assign(Object.assign(Object.assign({}, inheritedAttributes), this.attributes), forcedAttributes))); | ||
if (this.minitel.renderInvalidated) { | ||
throw new invalidrender_js_1.InvalidRender(); | ||
} | ||
if (!attributes.visible) { | ||
@@ -49,0 +59,0 @@ result = richchargrid_js_1.RichCharGrid.fill(attributes.width || 0, attributes.height || 0, fillChar); |
@@ -10,9 +10,17 @@ import { Focusable, FocusableAttributes } from '../abstract/focusable.js'; | ||
defaultAttributes: InputAttributes; | ||
value: string; | ||
focused: boolean; | ||
_value: string; | ||
_focused: boolean; | ||
keepElmDesc: true; | ||
cursorActuallyAt: [number, number]; | ||
scrollDelta: [number, number]; | ||
_cursorActuallyAt: [number, number]; | ||
_scrollDelta: [number, number]; | ||
lastFocusCursorX: number; | ||
constructor(children: [], attributes: Partial<InputAttributes>, minitel: Minitel); | ||
set value(newValue: string); | ||
get value(): string; | ||
set cursorActuallyAt(newPos: [number, number]); | ||
get cursorActuallyAt(): [number, number]; | ||
set scrollDelta(newDelta: [number, number]); | ||
get scrollDelta(): [number, number]; | ||
set focused(val: boolean); | ||
get focused(): boolean; | ||
constrainCursor(): void; | ||
@@ -19,0 +27,0 @@ keyEventListener(key: string): void; |
@@ -12,10 +12,46 @@ "use strict"; | ||
this.defaultAttributes = Input.defaultAttributes; | ||
this.value = ''; | ||
this.focused = false; | ||
this._value = ''; | ||
this._focused = false; | ||
this.keepElmDesc = true; | ||
this.cursorActuallyAt = [0, 0]; | ||
this.scrollDelta = [0, 0]; | ||
this._cursorActuallyAt = [0, 0]; | ||
this._scrollDelta = [0, 0]; | ||
this.lastFocusCursorX = 0; | ||
this.on('key', this.keyEventListener); | ||
} | ||
set value(newValue) { | ||
this._value = newValue; | ||
this.minitel.invalidateRender(); | ||
} | ||
get value() { | ||
return this._value; | ||
} | ||
set cursorActuallyAt(newPos) { | ||
this._cursorActuallyAt = [newPos[0], newPos[1]]; | ||
this.minitel.invalidateRender(); | ||
} | ||
get cursorActuallyAt() { | ||
return this._cursorActuallyAt; | ||
} | ||
set scrollDelta(newDelta) { | ||
this._scrollDelta = [newDelta[0], newDelta[1]]; | ||
this.minitel.invalidateRender(); | ||
} | ||
get scrollDelta() { | ||
return this._scrollDelta; | ||
} | ||
set focused(val) { | ||
if (val) { | ||
if (this.minitel.focusedObj) | ||
this.minitel.focusedObj.focused = false; | ||
this.minitel.invalidateRender(); | ||
this._focused = true; | ||
} | ||
else { | ||
this.minitel.invalidateRender(); | ||
this._focused = false; | ||
} | ||
} | ||
get focused() { | ||
return this._focused; | ||
} | ||
constrainCursor() { | ||
@@ -22,0 +58,0 @@ this.cursorActuallyAt[0] = Math.min(this.cursorActuallyAt[0], this.value.split('\n').length - 1); |
@@ -18,2 +18,3 @@ /// <reference types="node" /> | ||
static defaultScreenAttributes: CharAttributes; | ||
renderInvalidated: boolean; | ||
stream: Duplex; | ||
@@ -25,2 +26,3 @@ previousRender: RichCharGrid; | ||
constructor(stream: Duplex, settings: Partial<MinitelSettings>); | ||
invalidateRender(): void; | ||
renderString(): string; | ||
@@ -27,0 +29,0 @@ toCursorMove(y: number, x: number): string; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const inputConstants_js_1 = require("../inputConstants.js"); | ||
const invalidrender_js_1 = require("../abstract/invalidrender.js"); | ||
class Minitel extends container_js_1.Container { | ||
@@ -14,2 +15,3 @@ constructor(stream, settings) { | ||
super([], {}, that); | ||
this.renderInvalidated = false; | ||
this.focusedObj = null; | ||
@@ -75,7 +77,22 @@ this.lastImmediate = null; | ||
} | ||
invalidateRender() { | ||
this.renderInvalidated = true; | ||
} | ||
renderString() { | ||
const renderGrid = this.renderWrapper({}, { | ||
width: 40, | ||
height: 24 + +this.settings.statusBar, | ||
}); | ||
this.renderInvalidated = false; | ||
let renderGrid; | ||
try { | ||
renderGrid = this.renderWrapper({}, { | ||
width: 40, | ||
height: 24 + +this.settings.statusBar, | ||
}); | ||
} | ||
catch (err) { | ||
if (err instanceof invalidrender_js_1.InvalidRender) { | ||
return this.renderString(); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
renderGrid.setHeight(24 + +this.settings.statusBar, 'start', new richchar_js_1.RichChar(' ')); | ||
@@ -82,0 +99,0 @@ renderGrid.setWidth(40, 'start', new richchar_js_1.RichChar(' ')); |
@@ -10,9 +10,12 @@ import { Focusable } from '../abstract/focusable.js'; | ||
defaultAttributes: ScrollableAttributes; | ||
focused: boolean; | ||
_focused: boolean; | ||
keepElmDesc: true; | ||
private prevScrollDelta; | ||
scrollDelta: [number, number]; | ||
_scrollDelta: [number, number]; | ||
private artificialBlink; | ||
blinkShown: boolean; | ||
blink(): void; | ||
get scrollDelta(): [number, number]; | ||
set focused(val: boolean); | ||
get focused(): boolean; | ||
blinkHandler(): void; | ||
@@ -19,0 +22,0 @@ constructor(children: never[] | undefined, attributes: Partial<ScrollableAttributes>, minitel: Minitel); |
@@ -13,2 +13,20 @@ "use strict"; | ||
} | ||
get scrollDelta() { | ||
return this._scrollDelta; | ||
} | ||
set focused(val) { | ||
if (val) { | ||
if (this.minitel.focusedObj) | ||
this.minitel.focusedObj.focused = false; | ||
this.minitel.invalidateRender(); | ||
this._focused = true; | ||
} | ||
else { | ||
this.minitel.invalidateRender(); | ||
this._focused = false; | ||
} | ||
} | ||
get focused() { | ||
return this._focused; | ||
} | ||
blinkHandler() { | ||
@@ -29,6 +47,6 @@ if (this.focused || !this.blinkShown) { | ||
this.defaultAttributes = Scrollable.defaultAttributes; | ||
this.focused = false; | ||
this._focused = false; | ||
this.keepElmDesc = true; | ||
this.prevScrollDelta = null; | ||
this.scrollDelta = [0, 0]; | ||
this._scrollDelta = [0, 0]; | ||
this.artificialBlink = null; | ||
@@ -35,0 +53,0 @@ this.blinkShown = true; |
{ | ||
"name": "minitel-standalone", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "A standalone package for minitel components", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,2 +9,3 @@ import { EventEmitter } from 'node:events'; | ||
import { LocationDescriptor } from '../locationdescriptor.js'; | ||
import { InvalidRender } from './invalidrender.js'; | ||
@@ -35,3 +36,9 @@ export class MinitelObject<T extends MinitelObjectAttributes = MinitelObjectAttributes, U extends Record<string, any[]> = Record<string, any[]>> extends EventEmitter<U> { | ||
} | ||
this.attributes = attributes; | ||
this.attributes = new Proxy(attributes, { | ||
set: (function (this: MinitelObject, target: Record<string | symbol, any>, prop: string | symbol, val: any) { | ||
target[prop] = val; | ||
this.minitel.invalidateRender(); | ||
return true; | ||
}).bind(this), | ||
}) as Partial<T>; | ||
} | ||
@@ -74,2 +81,5 @@ appendChild(child: MinitelObject) { | ||
})); | ||
if (this.minitel.renderInvalidated) { | ||
throw new InvalidRender(); | ||
} | ||
if (!attributes.visible) { | ||
@@ -76,0 +86,0 @@ result = RichCharGrid.fill(attributes.width || 0, attributes.height || 0, fillChar); |
@@ -26,7 +26,7 @@ import { Focusable, FocusableAttributes } from '../abstract/focusable.js'; | ||
defaultAttributes = Input.defaultAttributes; | ||
value = ''; | ||
focused = false; | ||
_value = ''; | ||
_focused = false; | ||
keepElmDesc = true as const; | ||
cursorActuallyAt = [0, 0] as [number, number]; | ||
scrollDelta = [0, 0] as [number, number]; | ||
_cursorActuallyAt = [0, 0] as [number, number]; | ||
_scrollDelta = [0, 0] as [number, number]; | ||
lastFocusCursorX = 0; | ||
@@ -42,2 +42,36 @@ constructor( | ||
} | ||
set value(newValue: string) { | ||
this._value = newValue; | ||
this.minitel.invalidateRender(); | ||
} | ||
get value() { | ||
return this._value; | ||
} | ||
set cursorActuallyAt(newPos: [number, number]) { | ||
this._cursorActuallyAt = [newPos[0], newPos[1]]; | ||
this.minitel.invalidateRender(); | ||
} | ||
get cursorActuallyAt() { | ||
return this._cursorActuallyAt; | ||
} | ||
set scrollDelta(newDelta: [number, number]) { | ||
this._scrollDelta = [newDelta[0], newDelta[1]]; | ||
this.minitel.invalidateRender(); | ||
} | ||
get scrollDelta() { | ||
return this._scrollDelta; | ||
} | ||
set focused(val) { | ||
if (val) { | ||
if (this.minitel.focusedObj) this.minitel.focusedObj.focused = false; | ||
this.minitel.invalidateRender(); | ||
this._focused = true; | ||
} else { | ||
this.minitel.invalidateRender(); | ||
this._focused = false; | ||
} | ||
} | ||
get focused() { | ||
return this._focused; | ||
} | ||
constrainCursor() { | ||
@@ -44,0 +78,0 @@ this.cursorActuallyAt[0] = Math.min( |
@@ -12,2 +12,3 @@ import { Duplex } from 'stream'; | ||
import { expectNextChars } from '../inputConstants.js'; | ||
import { InvalidRender } from '../abstract/invalidrender.js'; | ||
@@ -31,2 +32,3 @@ export interface MinitelSettings { | ||
}; | ||
renderInvalidated: boolean = false; | ||
stream: Duplex; | ||
@@ -109,7 +111,20 @@ previousRender: RichCharGrid; | ||
} | ||
invalidateRender(): void { | ||
this.renderInvalidated = true; | ||
} | ||
renderString(): string { | ||
const renderGrid = this.renderWrapper({}, { | ||
width: 40, | ||
height: 24 + +this.settings.statusBar, | ||
}); | ||
this.renderInvalidated = false; | ||
let renderGrid; | ||
try { | ||
renderGrid = this.renderWrapper({}, { | ||
width: 40, | ||
height: 24 + +this.settings.statusBar, | ||
}); | ||
} catch (err) { | ||
if (err instanceof InvalidRender) { | ||
return this.renderString(); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
@@ -116,0 +131,0 @@ renderGrid.setHeight(24 + +this.settings.statusBar, 'start', new RichChar(' ')); |
@@ -20,6 +20,6 @@ import { Focusable } from '../abstract/focusable.js'; | ||
defaultAttributes = Scrollable.defaultAttributes; | ||
focused = false; | ||
_focused = false; | ||
keepElmDesc: true = true; | ||
private prevScrollDelta: [number, number] | null = null; | ||
scrollDelta: [number, number] = [0, 0]; | ||
_scrollDelta: [number, number] = [0, 0]; | ||
private artificialBlink: NodeJS.Timeout | null = null; | ||
@@ -35,2 +35,18 @@ blinkShown = true; | ||
} | ||
get scrollDelta() { | ||
return this._scrollDelta; | ||
} | ||
set focused(val) { | ||
if (val) { | ||
if (this.minitel.focusedObj) this.minitel.focusedObj.focused = false; | ||
this.minitel.invalidateRender(); | ||
this._focused = true; | ||
} else { | ||
this.minitel.invalidateRender(); | ||
this._focused = false; | ||
} | ||
} | ||
get focused() { | ||
return this._focused; | ||
} | ||
blinkHandler() { | ||
@@ -37,0 +53,0 @@ if (this.focused || !this.blinkShown) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
188865
72
4093