@lynx-js/web-elements 0.10.0 → 0.10.1

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,13 @@
1
1
  # @lynx-js/web-elements
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: implement x-webview component ([#2061](https://github.com/lynx-family/lynx-stack/pull/2061))
8
+
9
+ - feat: support `recyclable="false"` on `list-item` and enable overflow visibility ([#2069](https://github.com/lynx-family/lynx-stack/pull/2069))
10
+
3
11
  ## 0.10.0
4
12
 
5
13
  ### Minor Changes
@@ -1,2 +1,3 @@
1
1
  export declare class ListItem extends HTMLElement {
2
+ static readonly notToFilterFalseAttributes: Set<string>;
2
3
  }
@@ -23,6 +23,9 @@ let ListItem = (() => {
23
23
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
24
24
  ListItem = _classThis = _classDescriptor.value;
25
25
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
26
+ }
27
+ static notToFilterFalseAttributes = new Set(['recyclable']);
28
+ static {
26
29
  __runInitializers(_classThis, _classExtraInitializers);
27
30
  }
28
31
  };
@@ -0,0 +1,10 @@
1
+ export declare class XWebView extends HTMLElement {
2
+ #private;
3
+ connectedCallback(): void;
4
+ disconnectedCallback(): void;
5
+ get src(): string | null;
6
+ set src(val: string | null);
7
+ get html(): string | null;
8
+ set html(val: string | null);
9
+ reload(): void;
10
+ }
@@ -0,0 +1,128 @@
1
+ import { __esDecorate, __runInitializers } from "tslib";
2
+ /*
3
+ // Copyright 2024 The Lynx Authors. All rights reserved.
4
+ // Licensed under the Apache License Version 2.0 that can be found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { Component, genDomGetter } from '../../element-reactive/index.js';
8
+ import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
9
+ import { templateXWebView } from '../htmlTemplates.js';
10
+ import { XWebViewAttribute } from './XWebViewAttribute.js';
11
+ let XWebView = (() => {
12
+ let _classDecorators = [Component('x-webview', [CommonEventsAndMethods, XWebViewAttribute], templateXWebView)];
13
+ let _classDescriptor;
14
+ let _classExtraInitializers = [];
15
+ let _classThis;
16
+ let _classSuper = HTMLElement;
17
+ var XWebView = class extends _classSuper {
18
+ static { _classThis = this; }
19
+ static {
20
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
21
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
22
+ XWebView = _classThis = _classDescriptor.value;
23
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
24
+ __runInitializers(_classThis, _classExtraInitializers);
25
+ }
26
+ #getWebView = genDomGetter(() => this.shadowRoot, '#webview');
27
+ /**
28
+ * @internal
29
+ */
30
+ #handleLoad = () => {
31
+ this.dispatchEvent(new CustomEvent('load', {
32
+ bubbles: true,
33
+ composed: true,
34
+ detail: {
35
+ url: this.#getWebView().src,
36
+ },
37
+ }));
38
+ this.dispatchEvent(new CustomEvent('bindload', {
39
+ bubbles: true,
40
+ composed: true,
41
+ detail: {
42
+ url: this.#getWebView().src,
43
+ },
44
+ }));
45
+ };
46
+ /**
47
+ * @internal
48
+ */
49
+ #handleError = (e) => {
50
+ this.dispatchEvent(new CustomEvent('error', {
51
+ bubbles: true,
52
+ composed: true,
53
+ detail: {
54
+ errorMsg: e.message || 'unknown error',
55
+ },
56
+ }));
57
+ this.dispatchEvent(new CustomEvent('binderror', {
58
+ bubbles: true,
59
+ composed: true,
60
+ detail: {
61
+ errorMsg: e.message || 'unknown error',
62
+ },
63
+ }));
64
+ };
65
+ /**
66
+ * @internal
67
+ */
68
+ #handleMessage = (e) => {
69
+ if (e.source !== this.#getWebView().contentWindow) {
70
+ return;
71
+ }
72
+ this.dispatchEvent(new CustomEvent('message', {
73
+ bubbles: true,
74
+ composed: true,
75
+ detail: {
76
+ msg: e.data, // compatible with bindmessage
77
+ data: e.data, // standard CustomEvent
78
+ },
79
+ }));
80
+ this.dispatchEvent(new CustomEvent('bindmessage', {
81
+ bubbles: true,
82
+ composed: true,
83
+ detail: {
84
+ msg: e.data,
85
+ },
86
+ }));
87
+ };
88
+ connectedCallback() {
89
+ this.#getWebView().addEventListener('load', this.#handleLoad);
90
+ this.#getWebView().addEventListener('error', this.#handleError);
91
+ window.addEventListener('message', this.#handleMessage);
92
+ }
93
+ disconnectedCallback() {
94
+ this.#getWebView().removeEventListener('load', this.#handleLoad);
95
+ this.#getWebView().removeEventListener('error', this.#handleError);
96
+ window.removeEventListener('message', this.#handleMessage);
97
+ }
98
+ get src() {
99
+ return this.getAttribute('src');
100
+ }
101
+ set src(val) {
102
+ if (val === null) {
103
+ this.removeAttribute('src');
104
+ }
105
+ else {
106
+ this.setAttribute('src', val);
107
+ }
108
+ }
109
+ get html() {
110
+ return this.getAttribute('html');
111
+ }
112
+ set html(val) {
113
+ if (val === null) {
114
+ this.removeAttribute('html');
115
+ }
116
+ else {
117
+ this.setAttribute('html', val);
118
+ }
119
+ }
120
+ reload() {
121
+ // eslint-disable-next-line no-self-assign
122
+ this.#getWebView().src = this.#getWebView().src;
123
+ }
124
+ };
125
+ return XWebView = _classThis;
126
+ })();
127
+ export { XWebView };
128
+ //# sourceMappingURL=XWebView.js.map
@@ -0,0 +1,8 @@
1
+ import { type AttributeReactiveClass } from '../../element-reactive/index.js';
2
+ export declare class XWebViewAttribute implements InstanceType<AttributeReactiveClass<typeof HTMLElement>> {
3
+ #private;
4
+ static observedAttributes: string[];
5
+ constructor(dom: HTMLElement);
6
+ _handleSrc: (this: void, newVal: string | null) => void;
7
+ _handleHtml: (this: void, newVal: string | null) => void;
8
+ }
@@ -0,0 +1,36 @@
1
+ import { __esDecorate, __runInitializers } from "tslib";
2
+ /*
3
+ // Copyright 2024 The Lynx Authors. All rights reserved.
4
+ // Licensed under the Apache License Version 2.0 that can be found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { bindToAttribute, genDomGetter, registerAttributeHandler, } from '../../element-reactive/index.js';
8
+ let XWebViewAttribute = (() => {
9
+ let __handleSrc_decorators;
10
+ let __handleSrc_initializers = [];
11
+ let __handleSrc_extraInitializers = [];
12
+ let __handleHtml_decorators;
13
+ let __handleHtml_initializers = [];
14
+ let __handleHtml_extraInitializers = [];
15
+ return class XWebViewAttribute {
16
+ static {
17
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
18
+ __handleSrc_decorators = [registerAttributeHandler('src', true)];
19
+ __handleHtml_decorators = [registerAttributeHandler('html', true)];
20
+ __esDecorate(null, null, __handleSrc_decorators, { kind: "field", name: "_handleSrc", static: false, private: false, access: { has: obj => "_handleSrc" in obj, get: obj => obj._handleSrc, set: (obj, value) => { obj._handleSrc = value; } }, metadata: _metadata }, __handleSrc_initializers, __handleSrc_extraInitializers);
21
+ __esDecorate(null, null, __handleHtml_decorators, { kind: "field", name: "_handleHtml", static: false, private: false, access: { has: obj => "_handleHtml" in obj, get: obj => obj._handleHtml, set: (obj, value) => { obj._handleHtml = value; } }, metadata: _metadata }, __handleHtml_initializers, __handleHtml_extraInitializers);
22
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
23
+ }
24
+ static observedAttributes = ['src', 'html'];
25
+ #dom;
26
+ #getWebView = genDomGetter(() => this.#dom.shadowRoot, '#webview');
27
+ constructor(dom) {
28
+ __runInitializers(this, __handleHtml_extraInitializers);
29
+ this.#dom = dom;
30
+ }
31
+ _handleSrc = __runInitializers(this, __handleSrc_initializers, bindToAttribute(this.#getWebView, 'src'));
32
+ _handleHtml = (__runInitializers(this, __handleSrc_extraInitializers), __runInitializers(this, __handleHtml_initializers, bindToAttribute(this.#getWebView, 'srcdoc')));
33
+ };
34
+ })();
35
+ export { XWebViewAttribute };
36
+ //# sourceMappingURL=XWebViewAttribute.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module elements/XWebView
3
+ *
4
+ * `x-webview` provides a web container that allows loading web pages.
5
+ *
6
+ * Attributes:
7
+ * - `src`: The URL of the web page to load.
8
+ * - `html`: The HTML content to load (via srcdoc).
9
+ *
10
+ * Events:
11
+ * - `bindload`: Fired when the page loads. Detail: `{ url }`.
12
+ * - `binderror`: Fired when an error occurs. Detail: `{ errorMsg }`.
13
+ * - `bindmessage`: Fired when a message is received from the page. Detail: `{ msg }`.
14
+ *
15
+ * Methods:
16
+ * - `reload()`: Reloads the current page.
17
+ */
18
+ export { XWebView } from './XWebView.js';
@@ -0,0 +1,22 @@
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
+ /**
5
+ * @module elements/XWebView
6
+ *
7
+ * `x-webview` provides a web container that allows loading web pages.
8
+ *
9
+ * Attributes:
10
+ * - `src`: The URL of the web page to load.
11
+ * - `html`: The HTML content to load (via srcdoc).
12
+ *
13
+ * Events:
14
+ * - `bindload`: Fired when the page loads. Detail: `{ url }`.
15
+ * - `binderror`: Fired when an error occurs. Detail: `{ errorMsg }`.
16
+ * - `bindmessage`: Fired when a message is received from the page. Detail: `{ msg }`.
17
+ *
18
+ * Methods:
19
+ * - `reload()`: Reloads the current page.
20
+ */
21
+ export { XWebView } from './XWebView.js';
22
+ //# sourceMappingURL=index.js.map
@@ -15,3 +15,4 @@ import './XView/index.js';
15
15
  import './XViewpagerNg/index.js';
16
16
  import './XList/index.js';
17
17
  import './XList/ListItem.js';
18
+ import './XWebView/index.js';
@@ -15,4 +15,5 @@ import './XView/index.js';
15
15
  import './XViewpagerNg/index.js';
16
16
  import './XList/index.js';
17
17
  import './XList/ListItem.js';
18
+ import './XWebView/index.js';
18
19
  //# sourceMappingURL=all.js.map
@@ -17,4 +17,5 @@ export declare const templateInlineImage: (attributes: {
17
17
  }) => string;
18
18
  export declare const templateXTextarea = "<style>\n #textarea:focus,\n #textarea:focus-visible {\n border: inherit;\n outline: inherit;\n }\n</style>\n<form id=\"form\" part=\"form\" method=\"dialog\">\n <textarea id=\"textarea\" part=\"textarea\"></textarea>\n</form>";
19
19
  export declare const templateXViewpageNg = "<style>\n #bounce-padding {\n display: none;\n flex: 0 0 0;\n align-self: stretch;\n scroll-snap-align: none;\n flex-basis: 100%;\n }\n #content {\n flex: 0 0 100%;\n flex-direction: row;\n align-self: stretch;\n display: inherit;\n justify-content: inherit;\n align-items: inherit;\n overflow: inherit;\n scrollbar-width: none;\n scroll-snap-type: inherit;\n }\n #content::-webkit-scrollbar {\n display: none;\n }\n</style>\n<div id=\"bounce-padding\" part=\"bounce-padding\"></div>\n<div id=\"content\" part=\"content\">\n <slot></slot>\n</div>";
20
+ export declare const templateXWebView = "<style>\n iframe {\n width: 100%;\n height: 100%;\n border: none;\n }\n</style>\n<iframe id=\"webview\" part=\"webview\"></iframe>";
20
21
  export declare const templateXSvg: () => string;
@@ -326,6 +326,14 @@ export const templateXViewpageNg = `<style>
326
326
  <div id="content" part="content">
327
327
  <slot></slot>
328
328
  </div>`;
329
+ export const templateXWebView = `<style>
330
+ iframe {
331
+ width: 100%;
332
+ height: 100%;
333
+ border: none;
334
+ }
335
+ </style>
336
+ <iframe id="webview" part="webview"></iframe>`;
329
337
  export const templateXSvg = () => {
330
338
  return `<img part="img" alt="" loading="lazy" id="img" /> `;
331
339
  };
package/elements.css CHANGED
@@ -16,3 +16,4 @@
16
16
  @import url("./src/elements/XSwiper/x-swiper.css");
17
17
  @import url("./src/elements/XTextarea/x-textarea.css");
18
18
  @import url("./src/elements/XList/x-list.css");
19
+ @import url("./src/elements/XWebView/x-webview.css");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-elements",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -106,6 +106,11 @@
106
106
  "types": "./dist/elements/XList/index.d.ts",
107
107
  "default": "./dist/elements/XList/index.js"
108
108
  },
109
+ "./XWebView": {
110
+ "source": "./src/elements/XWebView/index.ts",
111
+ "types": "./dist/elements/XWebView/index.d.ts",
112
+ "default": "./dist/elements/XWebView/index.js"
113
+ },
109
114
  "./html-templates": {
110
115
  "source": "./src/elements/htmlTemplates.ts",
111
116
  "types": "./dist/elements/htmlTemplates.d.ts",
@@ -17,7 +17,8 @@ x-list > *:not(list-item) {
17
17
  display: none;
18
18
  }
19
19
 
20
- x-list::part(content), x-list[list-type="waterfall"]::part(waterfall-content) {
20
+ x-list::part(content),
21
+ x-list[list-type="waterfall"]::part(waterfall-content) {
21
22
  display: flex;
22
23
  flex: 0 0 auto;
23
24
  flex-wrap: nowrap;
@@ -36,15 +37,18 @@ x-list::part(content), x-list[list-type="waterfall"]::part(waterfall-content) {
36
37
  column-gap: inherit;
37
38
  }
38
39
 
39
- x-list::part(content), x-list::part(slot) {
40
+ x-list::part(content),
41
+ x-list::part(slot) {
40
42
  --lynx-display: inherit;
41
43
  }
42
44
 
43
- x-list, x-list::part(content) {
45
+ x-list,
46
+ x-list::part(content) {
44
47
  scrollbar-width: none;
45
48
  }
46
49
 
47
- x-list::-webkit-scrollbar, x-list::part(content)::-webkit-scrollbar {
50
+ x-list::-webkit-scrollbar,
51
+ x-list::part(content)::-webkit-scrollbar {
48
52
  display: none;
49
53
  }
50
54
 
@@ -65,11 +69,17 @@ list-item {
65
69
  contain-intrinsic-size: none auto var(--estimated-main-axis-size-px, 100cqh);
66
70
  }
67
71
 
72
+ list-item[recyclable="false"] {
73
+ content-visibility: visible;
74
+ contain: initial;
75
+ }
76
+
68
77
  x-list[scroll-orientation="horizontal"] list-item {
69
78
  contain-intrinsic-size: auto var(--estimated-main-axis-size-px, 100cqw) none;
70
79
  }
71
80
 
72
- x-list > list-item, x-list > lynx-wrapper > list-item {
81
+ x-list > list-item,
82
+ x-list > lynx-wrapper > list-item {
73
83
  display: flex;
74
84
  }
75
85
 
@@ -124,7 +134,8 @@ x-list[sticky="true"][scroll-orientation="horizontal"]
124
134
  right: var(--list-item-sticky-offset);
125
135
  }
126
136
 
127
- x-list[item-snap], x-list[paging-enabled] {
137
+ x-list[item-snap],
138
+ x-list[paging-enabled] {
128
139
  scroll-snap-type: y mandatory;
129
140
  scroll-snap-stop: always;
130
141
  }
@@ -134,7 +145,8 @@ x-list[paging-enabled][scroll-orientation="horizontal"] {
134
145
  scroll-snap-type: x mandatory;
135
146
  }
136
147
 
137
- x-list[item-snap] > list-item, x-list[item-snap] > lynx-wrapper > list-item {
148
+ x-list[item-snap] > list-item,
149
+ x-list[item-snap] > lynx-wrapper > list-item {
138
150
  scroll-snap-align: start;
139
151
  }
140
152
 
@@ -0,0 +1,5 @@
1
+ x-webview {
2
+ display: flex;
3
+ flex-direction: column;
4
+ overflow: hidden;
5
+ }