apprun 3.28.12 → 3.28.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apprun",
3
- "version": "3.28.12",
3
+ "version": "3.28.15",
4
4
  "description": "JavaScript library that has Elm inspired architecture, event pub-sub and components",
5
5
  "main": "dist/apprun.js",
6
6
  "module": "dist/apprun.esm.js",
package/src/app.ts CHANGED
@@ -9,6 +9,7 @@ export class App {
9
9
  public render;
10
10
  public Fragment;
11
11
  public webComponent;
12
+ public safeHTML;
12
13
 
13
14
  constructor() {
14
15
  this._events = {};
@@ -136,12 +136,12 @@ const _components = (print?) => {
136
136
 
137
137
  if (components instanceof Map) {
138
138
  for (let [key, comps] of components) {
139
- const element = typeof key === 'string' ? document.getElementById(key) : key;
139
+ const element = typeof key === 'string' ? document.getElementById(key) || document.querySelector(key): key;
140
140
  data.push({ element, comps });
141
141
  }
142
142
  } else {
143
143
  Object.keys(components).forEach(el => {
144
- const element = typeof el === 'string' ? document.getElementById(el) : el;
144
+ const element = typeof el === 'string' ? document.getElementById(el) || document.querySelector(el): el;
145
145
  data.push({ element, comps: components[el] });
146
146
  });
147
147
  }
package/src/apprun.ts CHANGED
@@ -14,18 +14,20 @@ export interface IApp {
14
14
  run(name: string, ...args: any[]): number;
15
15
  h(tag: string | Function, props, ...children): VNode | VNode[];
16
16
  createElement(tag: string | Function, props, ...children): VNode | VNode[];
17
- render(element: HTMLElement, node: VNode): void;
17
+ render(element: Element | string, node: VNode): void;
18
18
  Fragment(props, ...children): any[];
19
19
  route?: Route;
20
20
  webComponent(name: string, componentClass, options?: CustomElementOptions): void;
21
+ safeHTML(html: string): any[];
21
22
  }
22
23
 
23
24
  app.h = app.createElement = createElement;
24
25
  app.render = render;
25
26
  app.Fragment = Fragment;
26
27
  app.webComponent = webComponent;
28
+ app.safeHTML = safeHTML;
27
29
 
28
- app.start = <T, E = any>(element?: Element, model?: T, view?: View<T>, update?: Update<T, E>,
30
+ app.start = <T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
29
31
  options?: AppStartOptions<T>): Component<T, E> => {
30
32
  const opts = { render: true, global_event: true, ...options };
31
33
  const component = new Component<T, E>(model, view, update);
@@ -62,6 +64,7 @@ if (typeof window === 'object') {
62
64
  window['React'] = app;
63
65
  window['on'] = on;
64
66
  window['customElement'] = customElement;
67
+ window['safeHTML'] = safeHTML;
65
68
  }
66
69
 
67
70
 
package/src/component.ts CHANGED
@@ -40,8 +40,8 @@ export class Component<T = any, E = any> {
40
40
 
41
41
  if (typeof document !== 'object') return;
42
42
 
43
- const el = (typeof this.element === 'string') ?
44
- document.getElementById(this.element) : this.element;
43
+ const el = (typeof this.element === 'string' && this.element) ?
44
+ document.getElementById(this.element) || document.querySelector(this.element) : this.element;
45
45
 
46
46
  if (el) {
47
47
  const tracking_attr = '_c';
package/src/vdom-my.ts CHANGED
@@ -37,22 +37,21 @@ export function createElement(tag: string | Function | [], props?: {}, ...childr
37
37
 
38
38
  const keyCache = new WeakMap();
39
39
 
40
- export const updateElement = (element: Element, nodes: VDOM, component = {}) => {
40
+ export const updateElement = (element: Element | string, nodes: VDOM, component = {}) => {
41
41
  // tslint:disable-next-line
42
42
  if (nodes == null || nodes === false) return;
43
+ const el = (typeof element === 'string' && element) ?
44
+ document.getElementById(element) || document.querySelector(element) : element;
43
45
  nodes = directive(nodes, component);
44
- render(element, nodes, component);
46
+ render(el, nodes, component);
45
47
  }
46
48
 
47
49
  function render(element: Element, nodes: VDOM, parent = {}) {
48
50
  // tslint:disable-next-line
49
51
  if (nodes == null || nodes === false) return;
50
-
51
52
  nodes = createComponent(nodes, parent);
52
-
53
- const isSvg = element?.nodeName === "SVG";
54
-
55
53
  if (!element) return;
54
+ const isSvg = element.nodeName === "SVG";
56
55
  if (Array.isArray(nodes)) {
57
56
  updateChildren(element, nodes, isSvg);
58
57
  } else {
@@ -120,7 +119,7 @@ function updateChildren(element, children, isSvg: boolean) {
120
119
  }
121
120
  }
122
121
 
123
- let n = element.childNodes.length;
122
+ let n = element.childNodes?.length || 0;
124
123
  while (n > len) {
125
124
  element.removeChild(element.lastChild);
126
125
  n--;
@@ -138,7 +137,7 @@ function updateChildren(element, children, isSvg: boolean) {
138
137
  export const safeHTML = (html: string) => {
139
138
  const div = document.createElement('section');
140
139
  div.insertAdjacentHTML('afterbegin', html)
141
- return Array.from(div.childNodes);
140
+ return Array.from(div.children);
142
141
  }
143
142
 
144
143
  function createText(node) {