@lynx-js/web-elements 0.7.4 → 0.7.6

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,37 @@
1
1
  # @lynx-js/web-elements
2
2
 
3
+ ## 0.7.6
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: incorrect syntax for x-canvas part ([#1067](https://github.com/lynx-family/lynx-stack/pull/1067))
8
+
9
+ - feat: x-input && x-textarea add attribute input-filter, which can filter input value. ([#1037](https://github.com/lynx-family/lynx-stack/pull/1037))
10
+
11
+ - fix: incorrect top style of x-foldview-slot-ng if the toolbar is wrapped in lynx-wrapper ([#1101](https://github.com/lynx-family/lynx-stack/pull/1101))
12
+
13
+ - perf: add loading="lazy" for image element ([#1056](https://github.com/lynx-family/lynx-stack/pull/1056))
14
+
15
+ https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/img#loading
16
+
17
+ - fix: --lynx-color will be removed, and if color contains `gradient` it will be processed as transparent. ([#1069](https://github.com/lynx-family/lynx-stack/pull/1069))
18
+
19
+ - Updated dependencies [[`62d1078`](https://github.com/lynx-family/lynx-stack/commit/62d1078e67f2aba216a0d97bf1ad9ece624e498e)]:
20
+ - @lynx-js/web-elements-template@0.7.6
21
+
22
+ ## 0.7.5
23
+
24
+ ### Patch Changes
25
+
26
+ - feat: x-input && x-textarea add new method: `getValue`, which returns the value of the input element, selectionStart and selectEnd when success. ([#982](https://github.com/lynx-family/lynx-stack/pull/982))
27
+
28
+ - feat: x-input and x-textarea bindinput event return structures add `selectionStart`, `selectionEnd`, and `textLength`, `textLength` are marked as @deprecated ([#996](https://github.com/lynx-family/lynx-stack/pull/996))
29
+
30
+ - feat: x-input and x-textarea support bindselection event, the returned type structure is `{ selectionStart: number; selectionEnd: number }`. ([#990](https://github.com/lynx-family/lynx-stack/pull/990))
31
+
32
+ - Updated dependencies []:
33
+ - @lynx-js/web-elements-template@0.7.5
34
+
3
35
  ## 0.7.4
4
36
 
5
37
  ### Patch Changes
@@ -1,4 +1,5 @@
1
1
  export declare class XFoldviewHeaderNg extends HTMLElement {
2
+ #private;
2
3
  connectedCallback(): void;
3
4
  dispose(): void;
4
5
  }
@@ -7,6 +7,7 @@ import { __esDecorate, __runInitializers } from "tslib";
7
7
  import { Component } from '@lynx-js/web-elements-reactive';
8
8
  import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
9
9
  import { resizeObserver } from './XFoldviewNg.js';
10
+ import { getCombinedDirectParentElement } from '../common/getCombinedParentElement.js';
10
11
  let XFoldviewHeaderNg = (() => {
11
12
  let _classDecorators = [Component('x-foldview-header-ng', [
12
13
  CommonEventsAndMethods,
@@ -24,11 +25,14 @@ let XFoldviewHeaderNg = (() => {
24
25
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
25
26
  __runInitializers(_classThis, _classExtraInitializers);
26
27
  }
28
+ #parentResizeObserver = undefined;
27
29
  connectedCallback() {
28
- this.parentElement?.[resizeObserver]?.observe(this);
30
+ const parentElement = getCombinedDirectParentElement(this, 'X-FOLDVIEW-NG');
31
+ this.#parentResizeObserver = parentElement?.[resizeObserver];
32
+ this.#parentResizeObserver?.observe(this);
29
33
  }
30
34
  dispose() {
31
- this.parentElement?.[resizeObserver]?.unobserve(this);
35
+ this.#parentResizeObserver?.unobserve(this);
32
36
  }
33
37
  };
34
38
  return XFoldviewHeaderNg = _classThis;
@@ -1,4 +1,5 @@
1
1
  export declare class XFoldviewToolbarNg extends HTMLElement {
2
+ #private;
2
3
  connectedCallback(): void;
3
4
  dispose(): void;
4
5
  }
@@ -7,6 +7,7 @@ import { __esDecorate, __runInitializers } from "tslib";
7
7
  import { Component } from '@lynx-js/web-elements-reactive';
8
8
  import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
9
9
  import { resizeObserver } from './XFoldviewNg.js';
10
+ import { getCombinedDirectParentElement } from '../common/getCombinedParentElement.js';
10
11
  let XFoldviewToolbarNg = (() => {
11
12
  let _classDecorators = [Component('x-foldview-toolbar-ng', [
12
13
  CommonEventsAndMethods,
@@ -24,11 +25,14 @@ let XFoldviewToolbarNg = (() => {
24
25
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
25
26
  __runInitializers(_classThis, _classExtraInitializers);
26
27
  }
28
+ #parentResizeObserver = undefined;
27
29
  connectedCallback() {
28
- this.parentElement?.[resizeObserver]?.observe(this);
30
+ const parentElement = getCombinedDirectParentElement(this, 'X-FOLDVIEW-NG');
31
+ this.#parentResizeObserver = parentElement?.[resizeObserver];
32
+ this.#parentResizeObserver?.observe(this);
29
33
  }
30
34
  dispose() {
31
- this.parentElement?.[resizeObserver]?.unobserve(this);
35
+ this.#parentResizeObserver?.unobserve(this);
32
36
  }
33
37
  };
34
38
  return XFoldviewToolbarNg = _classThis;
@@ -10,6 +10,11 @@ export declare class XInput extends HTMLElement {
10
10
  value: string;
11
11
  index: number;
12
12
  }): void;
13
+ getValue(): {
14
+ value: string;
15
+ selectionBegin: number | null;
16
+ selectionEnd: number | null;
17
+ };
13
18
  sendDelEvent(params: {
14
19
  action: number;
15
20
  length: number;
@@ -64,6 +64,14 @@ let XInput = (() => {
64
64
  input.setSelectionRange(cursorIndex, cursorIndex);
65
65
  }
66
66
  }
67
+ getValue() {
68
+ const input = this.#getInput();
69
+ return {
70
+ value: input.value,
71
+ selectionBegin: input.selectionStart,
72
+ selectionEnd: input.selectionEnd,
73
+ };
74
+ }
67
75
  sendDelEvent(params) {
68
76
  let { action, length } = params;
69
77
  const input = this.#getInput();
@@ -10,16 +10,19 @@ import { renameEvent } from '../common/renameEvent.js';
10
10
  import { registerEventEnableStatusChangeHandler } from '@lynx-js/web-elements-reactive';
11
11
  let XInputEvents = (() => {
12
12
  let _instanceExtraInitializers = [];
13
- let _private_handleEnableConfirmEvent_decorators;
14
- let _private_handleEnableConfirmEvent_descriptor;
13
+ let _private_handleEnableInputEvent_decorators;
14
+ let _private_handleEnableInputEvent_descriptor;
15
15
  let _private_handleSendComposingInput_decorators;
16
16
  let _private_handleSendComposingInput_descriptor;
17
+ let _private_handleEnableSelectionEvent_decorators;
18
+ let _private_handleEnableSelectionEvent_descriptor;
17
19
  return class XInputEvents {
18
20
  static {
19
21
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
20
- _private_handleEnableConfirmEvent_decorators = [registerEventEnableStatusChangeHandler('input')];
22
+ _private_handleEnableInputEvent_decorators = [registerAttributeHandler('input-filter', true), registerEventEnableStatusChangeHandler('input')];
21
23
  _private_handleSendComposingInput_decorators = [registerAttributeHandler('send-composing-input', true)];
22
- __esDecorate(this, _private_handleEnableConfirmEvent_descriptor = { value: __setFunctionName(function (status) {
24
+ _private_handleEnableSelectionEvent_decorators = [registerEventEnableStatusChangeHandler('selection')];
25
+ __esDecorate(this, _private_handleEnableInputEvent_descriptor = { value: __setFunctionName(function (status) {
23
26
  const input = this.#getInputElement();
24
27
  if (status) {
25
28
  input.addEventListener('input', this.#teleportInput, { passive: true });
@@ -29,18 +32,28 @@ let XInputEvents = (() => {
29
32
  input.removeEventListener('input', this.#teleportInput);
30
33
  input.removeEventListener('compositionend', this.#teleportCompositionendInput);
31
34
  }
32
- }, "#handleEnableConfirmEvent") }, _private_handleEnableConfirmEvent_decorators, { kind: "method", name: "#handleEnableConfirmEvent", static: false, private: true, access: { has: obj => #handleEnableConfirmEvent in obj, get: obj => obj.#handleEnableConfirmEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
35
+ }, "#handleEnableInputEvent") }, _private_handleEnableInputEvent_decorators, { kind: "method", name: "#handleEnableInputEvent", static: false, private: true, access: { has: obj => #handleEnableInputEvent in obj, get: obj => obj.#handleEnableInputEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
33
36
  __esDecorate(this, _private_handleSendComposingInput_descriptor = { value: __setFunctionName(function (newVal) {
34
37
  this.#sendComposingInput = newVal !== null;
35
38
  }, "#handleSendComposingInput") }, _private_handleSendComposingInput_decorators, { kind: "method", name: "#handleSendComposingInput", static: false, private: true, access: { has: obj => #handleSendComposingInput in obj, get: obj => obj.#handleSendComposingInput }, metadata: _metadata }, null, _instanceExtraInitializers);
39
+ __esDecorate(this, _private_handleEnableSelectionEvent_descriptor = { value: __setFunctionName(function (status) {
40
+ if (status) {
41
+ this.#getInputElement().addEventListener('select', this.#selectEvent, {
42
+ passive: true,
43
+ });
44
+ }
45
+ else {
46
+ this.#getInputElement().removeEventListener('select', this.#selectEvent);
47
+ }
48
+ }, "#handleEnableSelectionEvent") }, _private_handleEnableSelectionEvent_decorators, { kind: "method", name: "#handleEnableSelectionEvent", static: false, private: true, access: { has: obj => #handleEnableSelectionEvent in obj, get: obj => obj.#handleEnableSelectionEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
36
49
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
37
50
  }
38
- static observedAttributes = ['send-composing-input'];
51
+ static observedAttributes = ['send-composing-input', 'input-filter'];
39
52
  #dom = __runInitializers(this, _instanceExtraInitializers);
40
53
  #sendComposingInput = false;
41
54
  #getInputElement = genDomGetter(() => this.#dom.shadowRoot, '#input');
42
55
  #getFormElement = genDomGetter(() => this.#dom.shadowRoot, '#form');
43
- get #handleEnableConfirmEvent() { return _private_handleEnableConfirmEvent_descriptor.value; }
56
+ get #handleEnableInputEvent() { return _private_handleEnableInputEvent_descriptor.value; }
44
57
  get #handleSendComposingInput() { return _private_handleSendComposingInput_descriptor.value; }
45
58
  #teleportEvent = (event) => {
46
59
  const eventType = renameEvent[event.type] ?? event.type;
@@ -53,35 +66,63 @@ let XInputEvents = (() => {
53
66
  };
54
67
  #teleportInput = (event) => {
55
68
  const input = this.#getInputElement();
56
- const value = input.value;
69
+ const inputFilter = this.#dom.getAttribute('input-filter');
70
+ const filterValue = inputFilter
71
+ ? input.value.replace(new RegExp(inputFilter, 'g'), '')
72
+ : input.value;
57
73
  const isComposing = event.isComposing;
74
+ input.value = filterValue;
58
75
  if (isComposing && !this.#sendComposingInput)
59
76
  return;
60
77
  this.#dom.dispatchEvent(new CustomEvent('input', {
61
78
  ...commonComponentEventSetting,
62
79
  detail: {
63
- value,
64
- textLength: value.length,
80
+ value: filterValue,
81
+ /** @deprecated */
82
+ textLength: filterValue.length,
83
+ /** @deprecated */
65
84
  cursor: input.selectionStart,
66
85
  isComposing,
86
+ selectionStart: input.selectionStart,
87
+ selectionEnd: input.selectionEnd,
67
88
  },
68
89
  }));
69
90
  };
70
91
  #teleportCompositionendInput = () => {
71
92
  const input = this.#getInputElement();
72
- const value = input.value;
93
+ const inputFilter = this.#dom.getAttribute('input-filter');
94
+ const filterValue = inputFilter
95
+ ? input.value.replace(new RegExp(inputFilter, 'g'), '')
96
+ : input.value;
97
+ input.value = filterValue;
73
98
  // if #sendComposingInput set true, #teleportInput will send detail
74
99
  if (!this.#sendComposingInput) {
75
100
  this.#dom.dispatchEvent(new CustomEvent('input', {
76
101
  ...commonComponentEventSetting,
77
102
  detail: {
78
- value,
79
- textLength: value.length,
103
+ value: filterValue,
104
+ /** @deprecated */
105
+ textLength: filterValue.length,
106
+ /** @deprecated */
80
107
  cursor: input.selectionStart,
108
+ isComposing: false,
109
+ selectionStart: input.selectionStart,
110
+ selectionEnd: input.selectionEnd,
81
111
  },
82
112
  }));
83
113
  }
84
114
  };
115
+ get #handleEnableSelectionEvent() { return _private_handleEnableSelectionEvent_descriptor.value; }
116
+ #selectEvent = () => {
117
+ const input = this.#getInputElement();
118
+ this.#dom.dispatchEvent(new CustomEvent('selection', {
119
+ ...commonComponentEventSetting,
120
+ detail: {
121
+ selectionStart: input.selectionStart,
122
+ selectionEnd: input.selectionEnd,
123
+ },
124
+ }));
125
+ };
85
126
  #blockHtmlEvent = (event) => {
86
127
  if (event.target === this.#getInputElement()
87
128
  && typeof event.detail === 'number') {
@@ -9,6 +9,11 @@ export declare class XTextarea extends HTMLElement {
9
9
  value: string;
10
10
  index: number;
11
11
  }): void;
12
+ getValue(): {
13
+ value: string;
14
+ selectionBegin: number;
15
+ selectionEnd: number;
16
+ };
12
17
  sendDelEvent(params: {
13
18
  action: number;
14
19
  length: number;
@@ -62,6 +62,14 @@ let XTextarea = (() => {
62
62
  input.setSelectionRange(cursorIndex, cursorIndex);
63
63
  }
64
64
  }
65
+ getValue() {
66
+ const input = this.#getTextarea();
67
+ return {
68
+ value: input.value,
69
+ selectionBegin: input.selectionStart,
70
+ selectionEnd: input.selectionEnd,
71
+ };
72
+ }
65
73
  sendDelEvent(params) {
66
74
  let { action, length } = params;
67
75
  const input = this.#getTextarea();
@@ -14,11 +14,14 @@ let XTextareaEvents = (() => {
14
14
  let _private_handleEnableConfirmEvent_descriptor;
15
15
  let _private_handleSendComposingInput_decorators;
16
16
  let _private_handleSendComposingInput_descriptor;
17
+ let _private_handleEnableSelectionEvent_decorators;
18
+ let _private_handleEnableSelectionEvent_descriptor;
17
19
  return class XTextareaEvents {
18
20
  static {
19
21
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
20
- _private_handleEnableConfirmEvent_decorators = [registerEventEnableStatusChangeHandler('input')];
22
+ _private_handleEnableConfirmEvent_decorators = [registerAttributeHandler('input-filter', true), registerEventEnableStatusChangeHandler('input')];
21
23
  _private_handleSendComposingInput_decorators = [registerAttributeHandler('send-composing-input', true)];
24
+ _private_handleEnableSelectionEvent_decorators = [registerEventEnableStatusChangeHandler('selection')];
22
25
  __esDecorate(this, _private_handleEnableConfirmEvent_descriptor = { value: __setFunctionName(function (status) {
23
26
  const textareaElement = this.#getTextareaElement();
24
27
  if (status) {
@@ -33,9 +36,19 @@ let XTextareaEvents = (() => {
33
36
  __esDecorate(this, _private_handleSendComposingInput_descriptor = { value: __setFunctionName(function (newVal) {
34
37
  this.#sendComposingInput = newVal !== null;
35
38
  }, "#handleSendComposingInput") }, _private_handleSendComposingInput_decorators, { kind: "method", name: "#handleSendComposingInput", static: false, private: true, access: { has: obj => #handleSendComposingInput in obj, get: obj => obj.#handleSendComposingInput }, metadata: _metadata }, null, _instanceExtraInitializers);
39
+ __esDecorate(this, _private_handleEnableSelectionEvent_descriptor = { value: __setFunctionName(function (status) {
40
+ if (status) {
41
+ this.#getTextareaElement().addEventListener('select', this.#selectEvent, {
42
+ passive: true,
43
+ });
44
+ }
45
+ else {
46
+ this.#getTextareaElement().removeEventListener('select', this.#selectEvent);
47
+ }
48
+ }, "#handleEnableSelectionEvent") }, _private_handleEnableSelectionEvent_decorators, { kind: "method", name: "#handleEnableSelectionEvent", static: false, private: true, access: { has: obj => #handleEnableSelectionEvent in obj, get: obj => obj.#handleEnableSelectionEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
36
49
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
37
50
  }
38
- static observedAttributes = ['send-composing-input'];
51
+ static observedAttributes = ['send-composing-input', 'input-filter'];
39
52
  #dom = __runInitializers(this, _instanceExtraInitializers);
40
53
  #sendComposingInput = false;
41
54
  #getTextareaElement = genDomGetter(() => this.#dom.shadowRoot, '#textarea');
@@ -53,35 +66,63 @@ let XTextareaEvents = (() => {
53
66
  };
54
67
  #teleportInput = (event) => {
55
68
  const input = this.#getTextareaElement();
56
- const value = input.value;
69
+ const inputFilter = this.#dom.getAttribute('input-filter');
70
+ const filterValue = inputFilter
71
+ ? input.value.replace(new RegExp(inputFilter, 'g'), '')
72
+ : input.value;
57
73
  const isComposing = event.isComposing;
74
+ input.value = filterValue;
58
75
  if (isComposing && !this.#sendComposingInput)
59
76
  return;
60
77
  this.#dom.dispatchEvent(new CustomEvent('input', {
61
78
  ...commonComponentEventSetting,
62
79
  detail: {
63
- value,
64
- textLength: value.length,
80
+ value: filterValue,
81
+ /** @deprecated */
82
+ textLength: filterValue.length,
83
+ /** @deprecated */
65
84
  cursor: input.selectionStart,
66
85
  isComposing,
86
+ selectionStart: input.selectionStart,
87
+ selectionEnd: input.selectionEnd,
67
88
  },
68
89
  }));
69
90
  };
70
91
  #teleportCompositionendInput = () => {
71
92
  const input = this.#getTextareaElement();
72
- const value = input.value;
93
+ const inputFilter = this.#dom.getAttribute('input-filter');
94
+ const filterValue = inputFilter
95
+ ? input.value.replace(new RegExp(inputFilter, 'g'), '')
96
+ : input.value;
97
+ input.value = filterValue;
73
98
  // if #sendComposingInput set true, #teleportInput will send detail
74
99
  if (!this.#sendComposingInput) {
75
100
  this.#dom.dispatchEvent(new CustomEvent('input', {
76
101
  ...commonComponentEventSetting,
77
102
  detail: {
78
- value,
79
- textLength: value.length,
103
+ value: filterValue,
104
+ /** @deprecated */
105
+ textLength: filterValue.length,
106
+ /** @deprecated */
80
107
  cursor: input.selectionStart,
108
+ isComposing: false,
109
+ selectionStart: input.selectionStart,
110
+ selectionEnd: input.selectionEnd,
81
111
  },
82
112
  }));
83
113
  }
84
114
  };
115
+ get #handleEnableSelectionEvent() { return _private_handleEnableSelectionEvent_descriptor.value; }
116
+ #selectEvent = () => {
117
+ const input = this.#getTextareaElement();
118
+ this.#dom.dispatchEvent(new CustomEvent('selection', {
119
+ ...commonComponentEventSetting,
120
+ detail: {
121
+ selectionStart: input.selectionStart,
122
+ selectionEnd: input.selectionEnd,
123
+ },
124
+ }));
125
+ };
85
126
  #blockHtmlEvent = (event) => {
86
127
  if (event.target === this.#getTextareaElement()
87
128
  && typeof event.detail === 'number') {
@@ -0,0 +1 @@
1
+ export declare const getCombinedDirectParentElement: <T extends HTMLElement>(element: HTMLElement, parentTagName: string) => T | undefined;
@@ -0,0 +1,11 @@
1
+ export const getCombinedDirectParentElement = (element, parentTagName) => {
2
+ let parentElement = element.parentElement;
3
+ if (parentElement?.tagName === 'LYNX-WRAPPER') {
4
+ parentElement = parentElement.parentElement;
5
+ }
6
+ if (parentElement?.tagName === parentTagName) {
7
+ return parentElement;
8
+ }
9
+ return;
10
+ };
11
+ //# sourceMappingURL=getCombinedParentElement.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-elements",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  "dependencies": {
103
103
  "@lynx-js/web-elements-reactive": "0.2.2",
104
- "@lynx-js/web-elements-template": "0.7.4"
104
+ "@lynx-js/web-elements-template": "0.7.6"
105
105
  },
106
106
  "devDependencies": {
107
107
  "tslib": "^2.8.1"
@@ -10,7 +10,7 @@ x-canvas {
10
10
  x-canvas > * {
11
11
  display: none !important;
12
12
  }
13
- x-canvas::part {
13
+ x-canvas::part(canvas) {
14
14
  height: 100%;
15
15
  width: 100%;
16
16
  }
@@ -8,11 +8,15 @@ x-text {
8
8
  display: flex;
9
9
  overflow-wrap: break-word;
10
10
  align-items: stretch;
11
- color: var(--lynx-color);
12
11
  background-image: var(--lynx-text-bg-color);
12
+ color: initial;
13
13
  }
14
+
15
+ x-text > x-text, x-text > lynx-wrapper > x-text {
16
+ color: inherit;
17
+ }
18
+
14
19
  x-text:not(x-text > x-text):not(x-text > lynx-wrapper > x-text) {
15
- --lynx-color: canvastext;
16
20
  --lynx-text-bg-color: initial;
17
21
  }
18
22