Skip to content

Commit a36de7f

Browse files
authored
Merge pull request #514 from rdkcentral/release/2.12.0
Release - v2.12.0
2 parents 4a3ecc1 + bd0c4f6 commit a36de7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+567
-1183
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## v2.12.0
4+
*26 oct 2023*
5+
6+
- Introduced a named export for Lightning in the ESM build to support direct module augmentation with `@lightningjs/core`, resolving issues with default export augmentation. (#480)
7+
- Modified the export structure to support tree-shaking. Lightning's ES modules can now be selectively imported /tree-shaken. (#490)
8+
- Enabled development in both TypeScript and JavaScript. Migrated specific files and ensured all source module files are appropriately managed in the `dist` directory.
9+
- Separated the Lightning Inspector with types as its own export.
10+
- Resolved an inconsistency in the zSorting algorithm where elements with the same zIndex were not correctly sorted by updateTreeOrder. (#443)
11+
- Addressed an exception causing infinite loops when accessing the texture.source property after text updates. This fix streamlines access to the renderInfo property without triggering a maximum call stack exception. (#447 and #348)
12+
- Resolved an issue where adding an already existing element to childList would throw an error. (#311 and #509)
13+
- Fixed an issue where SVG `txError` events were not being triggered due to missed error captures.
14+
- Fixed an issue where `txLoaded` event in elements over-fired due to incorrect texture change identification.
15+
16+
317
## v2.11.0
418
*31 july 2023*
519

banner.vite-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function banner(bannerText: string): Plugin {
1212
generateBundle(options, bundle) {
1313
// Add banner to the beginning of each chunk
1414
Object.keys(bundle).forEach((key) => {
15-
const file = bundle[key];
15+
const file = bundle[key]!;
1616
if (file.type === 'chunk') {
1717
file.code = bannerText + '\n' + file.code;
1818
}
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* If not stated otherwise in this file or this component's LICENSE file the
33
* following copyright and licenses apply:
44
*
5-
* Copyright 2022 Metrological
5+
* Copyright 2023 Metrological
66
*
77
* Licensed under the Apache License, Version 2.0 (the License);
88
* you may not use this file except in compliance with the License.
@@ -16,10 +16,28 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import lng from './lightning.mjs';
19+
import type {
20+
Application,
21+
Component,
22+
Element,
23+
ElementCore,
24+
ElementTexturizer,
25+
Stage,
26+
Texture,
27+
} from "../dist/src";
28+
29+
declare interface ILng {
30+
Application?: typeof Application;
31+
Component?: typeof Component;
32+
Element: typeof Element;
33+
ElementCore: typeof ElementCore;
34+
ElementTexturizer: typeof ElementTexturizer;
35+
Stage: typeof Stage;
36+
Texture: typeof Texture;
37+
}
2038

2139
declare global {
2240
interface Window {
23-
attachInspector?(Lightning: typeof lng): void;
41+
attachInspector(lng: ILng): void;
2442
}
2543
}

devtools/lightning-inspect.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,18 +843,20 @@ window.attachInspector = function({Application, Element, ElementCore, Stage, Com
843843
updateTextureAttribs(this)
844844
}
845845

846-
const _updateFocus = Application.prototype.__updateFocus
847-
Application.prototype.__updateFocus = function() {
848-
const prev = this._focusPath && this._focusPath.length ? this._focusPath[this._focusPath.length - 1] : null;
849-
_updateFocus.apply(this, arguments)
850-
const focused = this._focusPath && this._focusPath.length ? this._focusPath[this._focusPath.length - 1] : null;
851-
852-
if (prev != focused) {
853-
if (prev) {
854-
val(prev, 'focused', false, false);
855-
}
856-
if (focused) {
857-
val(focused, 'focused', true, false);
846+
if (typeof Application !== "undefined") {
847+
const _updateFocus = Application.prototype.__updateFocus
848+
Application.prototype.__updateFocus = function() {
849+
const prev = this._focusPath && this._focusPath.length ? this._focusPath[this._focusPath.length - 1] : null;
850+
_updateFocus.apply(this, arguments)
851+
const focused = this._focusPath && this._focusPath.length ? this._focusPath[this._focusPath.length - 1] : null;
852+
853+
if (prev != focused) {
854+
if (prev) {
855+
val(prev, 'focused', false, false);
856+
}
857+
if (focused) {
858+
val(focused, 'focused', true, false);
859+
}
858860
}
859861
}
860862
}

docs/PackageExports/index.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Package Exports / Tree Shaking
2+
3+
The Lightning Core NPM package exports both the Lightning Core library (the default package export: "@lightningjs/core") as well as the Lightning Inspector ("@lightningjs/core/inspector"). Both the [ES](https://nodejs.org/api/esm.html#modules-ecmascript-modules) and [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules) module styles are supported by both package exports.
4+
5+
> CommonJS is currently provided mainly to support older build tooling that may still be in use by applications. It is recommended that you upgrade/configure your build tools/bundler to utilize the ES modules when possible.
6+
7+
## Lightning Core (Tree Shakable ESM Exports)
8+
9+
```js
10+
// ESM (tree shakable named exports)
11+
import { Application, Component } from "@lightningjs/core";
12+
```
13+
14+
Lightning Core has historically always been available as a single default exported object from which you can access all of the various Lightning classes. As of version 2.12, when using ESM, each Lightning class is now also available as a seperate tree shakable named export.
15+
16+
Exclusively using the named ESM exports in your application enables the potential for your chosen bundler to [tree shake](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) Lightning's code so that the parts of Lightning that are not utilized by your application are left out of your bundle, reducing its size.
17+
18+
> Important: In order for tree shaking to be successful, your entire application, including any dependencies that are also dependent on Lightning must also utilize the named ESM exports. At the time of this writing, no published Lightning-based NPM packages utilize the tree shakable exports. So if your application is dependent on any, your bundler will be unable to tree shake Lightning.
19+
20+
## Lightning Core (Default Export)
21+
22+
```js
23+
// ESM (default export)
24+
import Lightning from "@lightningjs/core";
25+
26+
// CommonJS
27+
const Lightning = require("@lightningjs/core");
28+
```
29+
30+
The default export, as mentioned above, has historically been the main way users import Lightning Core. All of Lightning Core is available from this single exported object and as such, if imported, will prevent your chosen bundler from being able to tree shake Lightning.
31+
32+
## Lightning Inspector
33+
34+
```js
35+
// ESM
36+
import "@lightningjs/core/inspector";
37+
38+
// ESM (Dynamic)
39+
await import("@lightningjs/core/inspector");
40+
41+
// CommonJS
42+
require("@lightningjs/core/inspector");
43+
```
44+
45+
Outside of including the Lightning Inspector via a seperate `<script>` tag in your application's HTML, you can import/require it as of version 2.12:
46+
47+
The Inspector itself does not export any functions/classes/etc via either module style, but it does execute when included and places an `attachInspector()` method onto the browser's `window` object.
48+
49+
> If you choose this method, care should be taken to make sure the Inspector is not bundled with production code.

docs/TypeScript/Augmentation.md

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ There are certain global type structures provided by Lightning Core that your ap
44

55
The following are the TypeScript interfaces exported by Lightning Core that are designed for augmentation. You may find need to augment other available interfaces. In this event, please let us know what interfaces you are augmenting so we may add use guidelines to this page (or submit a [PR](https://github.com/rdkcentral/Lightning/pulls)!).
66

7+
> As of version 2.12, interface augmentation can be done without using the Lightning SDK or other hacks.
8+
79
## Component Key Handlers
810

911
Key Handlers are the methods you implement in your Components in order to handle key events. These are based on the Key Map provided during Application initialization. Often times the default set of key handlers that come with Lightning are good enough. But sometimes you need to add additional keys to it or replace it altogether. Lightning's TypeScript implementation includes the default key map set of handlers in the Component class. This allows you to write your class and have TypeScript make sure the parameters/return values are proper:
@@ -39,17 +41,13 @@ See the examples below.
3941
When this interface is augmented, you add additional key handlers to the existing default set.
4042

4143
```ts
42-
import '@lightningjs/sdk'
43-
44-
declare module '@lightningjs/sdk' {
45-
namespace Lightning {
46-
namespace Component {
47-
interface DefaultKeyHandlers {
48-
_captureHome?(e: KeyboardEvent): boolean | void;
49-
_captureHomeRelease?(e: KeyboardEvent): boolean | void;
50-
_handleHome?(e: KeyboardEvent): boolean | void;
51-
_handleHomeRelease?(e: KeyboardEvent): boolean | void;
52-
}
44+
declare module '@lightningjs/core' {
45+
namespace Component {
46+
interface DefaultKeyHandlers {
47+
_captureHome?(e: KeyboardEvent): boolean | void;
48+
_captureHomeRelease?(e: KeyboardEvent): boolean | void;
49+
_handleHome?(e: KeyboardEvent): boolean | void;
50+
_handleHomeRelease?(e: KeyboardEvent): boolean | void;
5351
}
5452
}
5553
}
@@ -62,37 +60,29 @@ When this interface is augmented, the entire set of `DefaultKeyHandlers` are rep
6260

6361
Example:
6462
```ts
65-
import '@lightningjs/sdk'
66-
67-
declare module '@lightningjs/sdk' {
68-
namespace Lightning {
69-
namespace Component {
70-
interface CustomKeyHandlers {
71-
_captureHome?(e: KeyboardEvent): boolean | void;
72-
_captureHomeRelease?(e: KeyboardEvent): boolean | void;
73-
_handleHome?(e: KeyboardEvent): boolean | void;
74-
_handleHomeRelease?(e: KeyboardEvent): boolean | void;
75-
}
63+
declare module '@lightningjs/core' {
64+
namespace Component {
65+
interface CustomKeyHandlers {
66+
_captureHome?(e: KeyboardEvent): boolean | void;
67+
_captureHomeRelease?(e: KeyboardEvent): boolean | void;
68+
_handleHome?(e: KeyboardEvent): boolean | void;
69+
_handleHomeRelease?(e: KeyboardEvent): boolean | void;
7670
}
7771
}
7872
}
7973
```
8074

8175
## Lightning.Component.FireAncestorsMap
8276

83-
Augmenting this interface this allows you to globally add to the events available in the `firstAncestors()` method available in any Component.
77+
Augmenting this interface this allows you to globally add to the events available in the `fireAncestors()` method available in any Component.
8478

8579
Example:
8680
```ts
87-
import '@lightningjs/sdk'
88-
89-
declare module '@lightningjs/sdk' {
90-
namespace Lightning {
91-
namespace Component {
92-
interface FireAncestorsMap {
93-
$itemCreated(): void;
94-
$selectItem(item: string, index: number): void;
95-
}
81+
declare module '@lightningjs/core' {
82+
namespace Component {
83+
interface FireAncestorsMap {
84+
$itemCreated(): void;
85+
$selectItem(item: string, index: number): void;
9686
}
9787
}
9888
}
@@ -111,16 +101,12 @@ Some applications opt to use the root Application component (available from any
111101

112102
Example:
113103
```ts
114-
import '@lightningjs/sdk'
115-
116-
declare module '@lightningjs/sdk' {
117-
namespace Lightning {
118-
namespace Application {
119-
interface EventMap {
120-
titleLoaded(): void;
121-
ratingColor(color: number): void;
122-
setBackground(evt: { src: string }): void;
123-
}
104+
declare module '@lightningjs/core' {
105+
namespace Application {
106+
interface EventMap {
107+
titleLoaded(): void;
108+
ratingColor(color: number): void;
109+
setBackground(evt: { src: string }): void;
124110
}
125111
}
126112
}

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The Reference Documentation for Lightning Core contains detailed descriptions ab
55

66
## Table of Contents
77
<!---TOC_start--->
8+
* [Package Exports / Tree Shaking](PackageExports/index.md)
89
* [Runtime Configuration](RuntimeConfig/index.md)
910
* [Render Engine](RenderEngine/index.md)
1011
* [Render Tree](RenderEngine/RenderTree.md)

fixTsImportsFromJs.vite-plugin.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Plugin } from 'vite';
2+
3+
/**
4+
* This Vite plugin ensures that TypeScript modules imported from JavaScript
5+
* modules are resolved correctly.
6+
*/
7+
export function fixTsImportsFromJs(): Plugin {
8+
return {
9+
name: 'fix-ts-imports-from-js',
10+
async resolveId(source, importer = '', options) {
11+
let resolution = await this.resolve(source, importer, {
12+
skipSelf: true,
13+
...options
14+
});
15+
// If there was no resolution and the importer file is JavaScript and the source
16+
// ends in `.js` lets see if we can resolve a `.ts` file
17+
if (!resolution && (importer.endsWith('.js') || importer.endsWith('.mjs')) &&
18+
(source.endsWith('.js') || source.endsWith('.mjs'))) {
19+
const newSource = source.replace(/\.mjs$/, '.mts').replace(/\.js$/, '.ts');
20+
resolution = await this.resolve(newSource, importer, {
21+
skipSelf: true,
22+
...options
23+
});
24+
}
25+
return resolution;
26+
},
27+
};
28+
}

index.d.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)