@lynx-js/web-elements 0.5.2 → 0.5.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lynx-js/web-elements
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: add `layoutchange` event support for x-view and x-text ([#408](https://github.com/lynx-family/lynx-stack/pull/408))
8
+
3
9
  ## 0.5.2
4
10
 
5
11
  ### Patch Changes
@@ -8,8 +8,9 @@ import { Component, html } from '@lynx-js/web-elements-reactive';
8
8
  import { LynxExposure } from '../common/Exposure.js';
9
9
  import { XTextTruncation } from './XTextTruncation.js';
10
10
  import { ScrollIntoView } from '../ScrollView/ScrollIntoView.js';
11
+ import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
11
12
  let XText = (() => {
12
- let _classDecorators = [Component('x-text', [LynxExposure, XTextTruncation], html `<div id="inner-box" part="inner-box"><slot></slot><slot name="inline-truncation"></slot></div>`)];
13
+ let _classDecorators = [Component('x-text', [LynxExposure, CommonEventsAndMethods, XTextTruncation], html `<div id="inner-box" part="inner-box"><slot></slot><slot name="inline-truncation"></slot></div>`)];
13
14
  let _classDescriptor;
14
15
  let _classExtraInitializers = [];
15
16
  let _classThis;
@@ -7,8 +7,9 @@ import { __esDecorate, __runInitializers } from "tslib";
7
7
  import { Component } from '@lynx-js/web-elements-reactive';
8
8
  import { ScrollIntoView } from '../ScrollView/ScrollIntoView.js';
9
9
  import { LynxExposure } from '../common/Exposure.js';
10
+ import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
10
11
  let XView = (() => {
11
- let _classDecorators = [Component('x-view', [LynxExposure])];
12
+ let _classDecorators = [Component('x-view', [LynxExposure, CommonEventsAndMethods])];
12
13
  let _classDescriptor;
13
14
  let _classExtraInitializers = [];
14
15
  let _classThis;
@@ -0,0 +1,6 @@
1
+ export declare class CommonEventsAndMethods {
2
+ #private;
3
+ static readonly observedAttributes: never[];
4
+ constructor(currentElement: HTMLElement);
5
+ __handleScrollUpperThresholdEventEnabled: (enabled: boolean) => void;
6
+ }
@@ -0,0 +1,61 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { __esDecorate, __runInitializers } from "tslib";
5
+ import { commonComponentEventSetting } from './commonEventInitConfiguration.js';
6
+ import { registerEventEnableStatusChangeHandler } from '@lynx-js/web-elements-reactive';
7
+ let CommonEventsAndMethods = (() => {
8
+ let ___handleScrollUpperThresholdEventEnabled_decorators;
9
+ let ___handleScrollUpperThresholdEventEnabled_initializers = [];
10
+ let ___handleScrollUpperThresholdEventEnabled_extraInitializers = [];
11
+ return class CommonEventsAndMethods {
12
+ static {
13
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
14
+ ___handleScrollUpperThresholdEventEnabled_decorators = [registerEventEnableStatusChangeHandler('layoutchange')];
15
+ __esDecorate(null, null, ___handleScrollUpperThresholdEventEnabled_decorators, { kind: "field", name: "__handleScrollUpperThresholdEventEnabled", static: false, private: false, access: { has: obj => "__handleScrollUpperThresholdEventEnabled" in obj, get: obj => obj.__handleScrollUpperThresholdEventEnabled, set: (obj, value) => { obj.__handleScrollUpperThresholdEventEnabled = value; } }, metadata: _metadata }, ___handleScrollUpperThresholdEventEnabled_initializers, ___handleScrollUpperThresholdEventEnabled_extraInitializers);
16
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
17
+ }
18
+ static observedAttributes = [];
19
+ #dom;
20
+ #observing = false;
21
+ #resizeObserver;
22
+ constructor(currentElement) {
23
+ __runInitializers(this, ___handleScrollUpperThresholdEventEnabled_extraInitializers);
24
+ this.#dom = currentElement;
25
+ }
26
+ __handleScrollUpperThresholdEventEnabled = __runInitializers(this, ___handleScrollUpperThresholdEventEnabled_initializers, (enabled) => {
27
+ if (enabled) {
28
+ if (!this.#resizeObserver) {
29
+ this.#resizeObserver = new ResizeObserver(([entry]) => {
30
+ if (entry) {
31
+ // The layoutchange event is the border box of the element
32
+ const { width, height, left, right, top, bottom } = entry.contentRect;
33
+ const id = this.#dom.id;
34
+ this.#dom.dispatchEvent(new CustomEvent('layoutchange', {
35
+ detail: {
36
+ width,
37
+ height,
38
+ left,
39
+ right,
40
+ top,
41
+ bottom,
42
+ id,
43
+ },
44
+ ...commonComponentEventSetting,
45
+ }));
46
+ }
47
+ });
48
+ if (!this.#observing) {
49
+ this.#resizeObserver.observe(this.#dom);
50
+ this.#observing = true;
51
+ }
52
+ }
53
+ }
54
+ else {
55
+ this.#resizeObserver?.disconnect();
56
+ }
57
+ });
58
+ };
59
+ })();
60
+ export { CommonEventsAndMethods };
61
+ //# sourceMappingURL=CommonEventsAndMethods.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-elements",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",