@viewfly/platform-browser 2.0.0 → 2.0.2

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.
@@ -112,6 +112,11 @@ declare class OutputTranslator {
112
112
  declare class DomRenderer extends NativeRenderer<HTMLElement, Text> {
113
113
  static NAMESPACES: Record<string, string>;
114
114
  propMap: Record<string, Record<string, string>>;
115
+ /**
116
+ * IDL 属性赋 `''` 会被转成数字 0(如 maxLength/minLength),无法表示「未设置」。
117
+ * 这些键在移除时应删掉对应 content attribute。
118
+ */
119
+ private static readonly REMOVE_VIA_ATTRIBUTE;
115
120
  createElement(name: string, namespace: ElementNamespace): HTMLElement;
116
121
  createTextNode(textContent: string): Text;
117
122
  appendChild(parent: HTMLElement, newChild: any): void;
@@ -52,6 +52,10 @@ class DomRenderer extends NativeRenderer {
52
52
  node.textContent = '';
53
53
  }
54
54
  setProperty(node, key, value, namespace) {
55
+ if (value == null) {
56
+ this.removeProperty(node, key, namespace);
57
+ return;
58
+ }
55
59
  if (namespace) {
56
60
  const prefix = 'xlink:';
57
61
  if (key.startsWith(prefix)) {
@@ -89,8 +93,15 @@ class DomRenderer extends NativeRenderer {
89
93
  }
90
94
  return;
91
95
  }
92
- if (key in node) {
93
- node[key] = '';
96
+ const map = this.propMap[node.tagName];
97
+ const resolvedKey = map ? (map[key] || key) : key;
98
+ const attrName = DomRenderer.REMOVE_VIA_ATTRIBUTE[resolvedKey];
99
+ if (attrName) {
100
+ node.removeAttribute(attrName);
101
+ return;
102
+ }
103
+ if (resolvedKey in node) {
104
+ node[resolvedKey] = '';
94
105
  }
95
106
  else {
96
107
  node.removeAttribute(key);
@@ -165,6 +176,23 @@ Object.defineProperty(DomRenderer, "NAMESPACES", {
165
176
  mathml: 'http://www.w3.org/1998/Math/MathML',
166
177
  }
167
178
  });
179
+ /**
180
+ * IDL 属性赋 `''` 会被转成数字 0(如 maxLength/minLength),无法表示「未设置」。
181
+ * 这些键在移除时应删掉对应 content attribute。
182
+ */
183
+ Object.defineProperty(DomRenderer, "REMOVE_VIA_ATTRIBUTE", {
184
+ enumerable: true,
185
+ configurable: true,
186
+ writable: true,
187
+ value: {
188
+ maxLength: 'maxlength',
189
+ minLength: 'minlength',
190
+ size: 'size',
191
+ cols: 'cols',
192
+ rows: 'rows',
193
+ tabIndex: 'tabindex',
194
+ }
195
+ });
168
196
 
169
197
  function createApp(root, config = true) {
170
198
  const c = { autoUpdate: true };
package/bundles/index.js CHANGED
@@ -54,6 +54,10 @@ class DomRenderer extends core.NativeRenderer {
54
54
  node.textContent = '';
55
55
  }
56
56
  setProperty(node, key, value, namespace) {
57
+ if (value == null) {
58
+ this.removeProperty(node, key, namespace);
59
+ return;
60
+ }
57
61
  if (namespace) {
58
62
  const prefix = 'xlink:';
59
63
  if (key.startsWith(prefix)) {
@@ -91,8 +95,15 @@ class DomRenderer extends core.NativeRenderer {
91
95
  }
92
96
  return;
93
97
  }
94
- if (key in node) {
95
- node[key] = '';
98
+ const map = this.propMap[node.tagName];
99
+ const resolvedKey = map ? (map[key] || key) : key;
100
+ const attrName = DomRenderer.REMOVE_VIA_ATTRIBUTE[resolvedKey];
101
+ if (attrName) {
102
+ node.removeAttribute(attrName);
103
+ return;
104
+ }
105
+ if (resolvedKey in node) {
106
+ node[resolvedKey] = '';
96
107
  }
97
108
  else {
98
109
  node.removeAttribute(key);
@@ -167,6 +178,23 @@ Object.defineProperty(DomRenderer, "NAMESPACES", {
167
178
  mathml: 'http://www.w3.org/1998/Math/MathML',
168
179
  }
169
180
  });
181
+ /**
182
+ * IDL 属性赋 `''` 会被转成数字 0(如 maxLength/minLength),无法表示「未设置」。
183
+ * 这些键在移除时应删掉对应 content attribute。
184
+ */
185
+ Object.defineProperty(DomRenderer, "REMOVE_VIA_ATTRIBUTE", {
186
+ enumerable: true,
187
+ configurable: true,
188
+ writable: true,
189
+ value: {
190
+ maxLength: 'maxlength',
191
+ minLength: 'minlength',
192
+ size: 'size',
193
+ cols: 'cols',
194
+ rows: 'rows',
195
+ tabIndex: 'tabindex',
196
+ }
197
+ });
170
198
 
171
199
  function createApp(root, config = true) {
172
200
  const c = { autoUpdate: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/platform-browser",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "This project is used to enable the Viewfly framework to run in a browser.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",