@lynx-js/web-elements-canary 0.10.0 → 0.10.1-canary-20251229-1bb269b6

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.10.1-canary-20251229091057-1bb269b6c6f58fba293587a98f3fa8e3160cbbba
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: implement x-webview component ([#2061](https://github.com/lynx-family/lynx-stack/pull/2061))
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
@@ -9,15 +15,15 @@
9
15
  ### Before
10
16
 
11
17
  ```js
12
- import '@lynx-js/web-elements-template';
13
- import '@lynx-js/web-elements-compat/LinearContainer';
18
+ import "@lynx-js/web-elements-template";
19
+ import "@lynx-js/web-elements-compat/LinearContainer";
14
20
  ```
15
21
 
16
22
  ### After
17
23
 
18
24
  ```js
19
- import '@lynx-js/web-elements/html-templates';
20
- import '@lynx-js/web-elements/compat/LinearContainer';
25
+ import "@lynx-js/web-elements/html-templates";
26
+ import "@lynx-js/web-elements/compat/LinearContainer";
21
27
  ```
22
28
 
23
29
  ### Patch Changes
@@ -702,8 +708,8 @@
702
708
  For compating usage, `@lynx-js/web-elements-compat/LinearContainer` is provided.
703
709
 
704
710
  ```javascript
705
- import '@lynx-js/web-elements-compat/LinearContainer';
706
- import '@lynx-js/web-elements/all';
711
+ import "@lynx-js/web-elements-compat/LinearContainer";
712
+ import "@lynx-js/web-elements/all";
707
713
  ```
708
714
 
709
715
  - f8d1d98: break: rename the `blur` and `focus` event to `lynxblur` and `lynxfocus` for x-input element
@@ -725,11 +731,11 @@
725
731
  There is also a simple way to use this feature
726
732
 
727
733
  ```javascript
728
- import { LynxCard } from '@lynx-js/web-core';
729
- import { loadElement } from '@lynx-js/web-elements/lazy';
730
- import '@lynx-js/web-elements/index.css';
731
- import '@lynx-js/web-core/index.css';
732
- import './index.css';
734
+ import { LynxCard } from "@lynx-js/web-core";
735
+ import { loadElement } from "@lynx-js/web-elements/lazy";
736
+ import "@lynx-js/web-elements/index.css";
737
+ import "@lynx-js/web-core/index.css";
738
+ import "./index.css";
733
739
 
734
740
  const lynxcard = new LynxCard({
735
741
  ...beforeConfigs,
@@ -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-canary",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-canary-20251229-1bb269b6",
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",
@@ -0,0 +1,5 @@
1
+ x-webview {
2
+ display: flex;
3
+ flex-direction: column;
4
+ overflow: hidden;
5
+ }