@viewfly/platform-browser 1.0.0-alpha.1 → 1.0.0-alpha.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.
@@ -1,16 +1,18 @@
1
1
  import { NativeRenderer } from '@viewfly/core';
2
- export declare class VDOMElement {
2
+ export declare class VDOMNode {
3
+ parent: VDOMElement | null;
4
+ remove(): void;
5
+ }
6
+ export declare class VDOMElement extends VDOMNode {
3
7
  name: string;
4
8
  props: Map<string, any>;
5
9
  children: Array<VDOMElement | VDOMText>;
6
10
  style: Map<string, any>;
7
11
  className: string;
8
- parent: VDOMElement | null;
9
12
  constructor(name: string);
10
13
  }
11
- export declare class VDOMText {
14
+ export declare class VDOMText extends VDOMNode {
12
15
  text: string;
13
- parent: VDOMElement | null;
14
16
  constructor(text: string);
15
17
  }
16
18
  /**
@@ -168,20 +168,34 @@ function createPortal(childRender, host) {
168
168
  };
169
169
  }
170
170
 
171
- class VDOMElement {
171
+ class VDOMNode {
172
+ constructor() {
173
+ this.parent = null;
174
+ }
175
+ remove() {
176
+ if (this.parent) {
177
+ const i = this.parent.children.indexOf(this);
178
+ if (i > -1) {
179
+ this.parent.children.splice(i, 1);
180
+ }
181
+ }
182
+ this.parent = null;
183
+ }
184
+ }
185
+ class VDOMElement extends VDOMNode {
172
186
  constructor(name) {
187
+ super();
173
188
  this.name = name;
174
189
  this.props = new Map();
175
190
  this.children = [];
176
191
  this.style = new Map();
177
192
  this.className = '';
178
- this.parent = null;
179
193
  }
180
194
  }
181
- class VDOMText {
195
+ class VDOMText extends VDOMNode {
182
196
  constructor(text) {
197
+ super();
183
198
  this.text = text;
184
- this.parent = null;
185
199
  }
186
200
  }
187
201
  /**
@@ -198,10 +212,12 @@ class HTMLRenderer extends NativeRenderer {
198
212
  node.props.set(key, value);
199
213
  }
200
214
  appendChild(parent, newChild) {
215
+ newChild.remove();
201
216
  parent.children.push(newChild);
202
217
  newChild.parent = parent;
203
218
  }
204
219
  prependChild(parent, newChild) {
220
+ newChild.remove();
205
221
  parent.children.unshift(newChild);
206
222
  newChild.parent = parent;
207
223
  }
@@ -224,21 +240,17 @@ class HTMLRenderer extends NativeRenderer {
224
240
  //
225
241
  }
226
242
  remove(node) {
227
- if (node.parent) {
228
- const i = node.parent.children.indexOf(node);
229
- if (i > -1) {
230
- node.parent.children.splice(i, 1);
231
- }
232
- }
233
- node.parent = null;
243
+ node.remove();
234
244
  }
235
245
  cleanChildren(node) {
246
+ node.children.forEach(i => i.parent = null);
236
247
  node.children = [];
237
248
  }
238
249
  syncTextContent(target, content) {
239
250
  target.text = content;
240
251
  }
241
252
  insertAfter(newNode, ref) {
253
+ newNode.remove();
242
254
  const parent = ref.parent;
243
255
  if (parent) {
244
256
  const i = parent.children.indexOf(ref);
@@ -284,7 +296,7 @@ class OutputTranslator {
284
296
  const attrs = Array.from(vDom.props.keys()).filter(key => key !== 'ref' && vDom.props.get(key) !== false).map(k => {
285
297
  const key = xssFilter.attrName(k);
286
298
  const value = vDom.props.get(k);
287
- return (value === true ? `${key}` : `${key}="${xssFilter.attrValue(`${value}`)}"`);
299
+ return (value === true && /^\w+$/.test(key) ? `${key}` : `${key}="${xssFilter.attrValue(`${value}`)}"`);
288
300
  });
289
301
  if (styles) {
290
302
  attrs.push(`style="${styles}"`);
@@ -346,4 +358,4 @@ OutputTranslator.simpleXSSFilter = {
346
358
  }
347
359
  };
348
360
 
349
- export { DomRenderer, HTMLRenderer, OutputTranslator, VDOMElement, VDOMText, createApp, createPortal };
361
+ export { DomRenderer, HTMLRenderer, OutputTranslator, VDOMElement, VDOMNode, VDOMText, createApp, createPortal };
package/bundles/index.js CHANGED
@@ -170,20 +170,34 @@ function createPortal(childRender, host) {
170
170
  };
171
171
  }
172
172
 
173
- class VDOMElement {
173
+ class VDOMNode {
174
+ constructor() {
175
+ this.parent = null;
176
+ }
177
+ remove() {
178
+ if (this.parent) {
179
+ const i = this.parent.children.indexOf(this);
180
+ if (i > -1) {
181
+ this.parent.children.splice(i, 1);
182
+ }
183
+ }
184
+ this.parent = null;
185
+ }
186
+ }
187
+ class VDOMElement extends VDOMNode {
174
188
  constructor(name) {
189
+ super();
175
190
  this.name = name;
176
191
  this.props = new Map();
177
192
  this.children = [];
178
193
  this.style = new Map();
179
194
  this.className = '';
180
- this.parent = null;
181
195
  }
182
196
  }
183
- class VDOMText {
197
+ class VDOMText extends VDOMNode {
184
198
  constructor(text) {
199
+ super();
185
200
  this.text = text;
186
- this.parent = null;
187
201
  }
188
202
  }
189
203
  /**
@@ -200,10 +214,12 @@ class HTMLRenderer extends core.NativeRenderer {
200
214
  node.props.set(key, value);
201
215
  }
202
216
  appendChild(parent, newChild) {
217
+ newChild.remove();
203
218
  parent.children.push(newChild);
204
219
  newChild.parent = parent;
205
220
  }
206
221
  prependChild(parent, newChild) {
222
+ newChild.remove();
207
223
  parent.children.unshift(newChild);
208
224
  newChild.parent = parent;
209
225
  }
@@ -226,21 +242,17 @@ class HTMLRenderer extends core.NativeRenderer {
226
242
  //
227
243
  }
228
244
  remove(node) {
229
- if (node.parent) {
230
- const i = node.parent.children.indexOf(node);
231
- if (i > -1) {
232
- node.parent.children.splice(i, 1);
233
- }
234
- }
235
- node.parent = null;
245
+ node.remove();
236
246
  }
237
247
  cleanChildren(node) {
248
+ node.children.forEach(i => i.parent = null);
238
249
  node.children = [];
239
250
  }
240
251
  syncTextContent(target, content) {
241
252
  target.text = content;
242
253
  }
243
254
  insertAfter(newNode, ref) {
255
+ newNode.remove();
244
256
  const parent = ref.parent;
245
257
  if (parent) {
246
258
  const i = parent.children.indexOf(ref);
@@ -286,7 +298,7 @@ class OutputTranslator {
286
298
  const attrs = Array.from(vDom.props.keys()).filter(key => key !== 'ref' && vDom.props.get(key) !== false).map(k => {
287
299
  const key = xssFilter.attrName(k);
288
300
  const value = vDom.props.get(k);
289
- return (value === true ? `${key}` : `${key}="${xssFilter.attrValue(`${value}`)}"`);
301
+ return (value === true && /^\w+$/.test(key) ? `${key}` : `${key}="${xssFilter.attrValue(`${value}`)}"`);
290
302
  });
291
303
  if (styles) {
292
304
  attrs.push(`style="${styles}"`);
@@ -352,6 +364,7 @@ exports.DomRenderer = DomRenderer;
352
364
  exports.HTMLRenderer = HTMLRenderer;
353
365
  exports.OutputTranslator = OutputTranslator;
354
366
  exports.VDOMElement = VDOMElement;
367
+ exports.VDOMNode = VDOMNode;
355
368
  exports.VDOMText = VDOMText;
356
369
  exports.createApp = createApp;
357
370
  exports.createPortal = createPortal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/platform-browser",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
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",
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "keywords": [],
14
14
  "dependencies": {
15
- "@viewfly/core": "^1.0.0-alpha.1",
15
+ "@viewfly/core": "^1.0.0-alpha.3",
16
16
  "csstype": "^3.1.2"
17
17
  },
18
18
  "devDependencies": {
@@ -33,5 +33,5 @@
33
33
  "bugs": {
34
34
  "url": "https://github.com/viewfly/viewfly.git/issues"
35
35
  },
36
- "gitHead": "8a25e6e350ba9cade6036506e7fe2aba4e4396ac"
36
+ "gitHead": "ef47d49227def3f760cec535ba7867e0e624f339"
37
37
  }