apprun 3.28.9 → 3.28.12

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/esm/vdom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vdom.js","sourceRoot":"","sources":["../src/vdom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACnE,MAAM,UAAU,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,MAAO;IAC3C,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AACD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"vdom.js","sourceRoot":"","sources":["../src/vdom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,IAAI,MAAM,EAAE,QAAQ,EAAE,CAAC"}
@@ -39,22 +39,24 @@ export const customElement = (componentClass, options = {}) => class CustomEleme
39
39
  enumerable: true
40
40
  });
41
41
  });
42
- const children = this.children ? Array.from(this.children) : [];
43
- children.forEach(el => el.parentElement.removeChild(el));
44
- this._component = new componentClass(Object.assign(Object.assign({}, props), { children })).mount(this._shadowRoot, opts);
45
- // attach props to component
46
- this._component._props = props;
47
- // expose dispatchEvent
48
- this._component.dispatchEvent = this.dispatchEvent.bind(this);
49
- if (this._component.mounted) {
50
- const new_state = this._component.mounted(props, children, this._component.state);
51
- if (typeof new_state !== 'undefined')
52
- this._component.state = new_state;
53
- }
54
- this.on = this._component.on.bind(this._component);
55
- this.run = this._component.run.bind(this._component);
56
- if (!(opts.render === false))
57
- this._component.run('.');
42
+ requestAnimationFrame(() => {
43
+ const children = this.children ? Array.from(this.children) : [];
44
+ children.forEach(el => el.parentElement.removeChild(el));
45
+ this._component = new componentClass(Object.assign(Object.assign({}, props), { children })).mount(this._shadowRoot, opts);
46
+ // attach props to component
47
+ this._component._props = props;
48
+ // expose dispatchEvent
49
+ this._component.dispatchEvent = this.dispatchEvent.bind(this);
50
+ if (this._component.mounted) {
51
+ const new_state = this._component.mounted(props, children, this._component.state);
52
+ if (typeof new_state !== 'undefined')
53
+ this._component.state = new_state;
54
+ }
55
+ this.on = this._component.on.bind(this._component);
56
+ this.run = this._component.run.bind(this._component);
57
+ if (!(opts.render === false))
58
+ this._component.run('.');
59
+ });
58
60
  }
59
61
  }
60
62
  disconnectedCallback() {
@@ -1 +1 @@
1
- {"version":3,"file":"web-component.js","sourceRoot":"","sources":["../src/web-component.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,UAAgC,EAAE,EAAE,EAAE,CAAC,MAAM,aAAc,SAAQ,WAAW;IAM1H;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IACD,IAAI,SAAS,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7C,MAAM,KAAK,kBAAkB;QAC3B,kEAAkE;QAClE,OAAO,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,iBAAiB;QACf,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACxC,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC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,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YAErE,IAAI,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,EAAE;gBACrD,MAAM,CAAC,qBAAqB,CAAC,GAAG,EAAE;oBAChC,kEAAkE;oBAClE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBAC1B,CAAC,CAAC,CAAA;aACH;SACF;IACH,CAAC;CACF,CAAA;AAED,eAAe,CAAC,IAAY,EAAE,cAAc,EAAE,OAA8B,EAAE,EAAE;IAC9E,CAAC,OAAO,cAAc,KAAK,WAAW,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAA;AAChH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "apprun",
3
- "version": "3.28.9",
3
+ "version": "3.28.12",
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",
7
7
  "types": "apprun.d.ts",
8
+ "type": "module",
8
9
  "bin": {
9
10
  "apprun": "apprun-cli.js"
10
11
  },
@@ -38,24 +39,24 @@
38
39
  },
39
40
  "homepage": "https://github.com/yysun/apprun#readme",
40
41
  "devDependencies": {
41
- "@rollup/plugin-commonjs": "^21.0.2",
42
+ "@rollup/plugin-commonjs": "^21.0.3",
42
43
  "@rollup/plugin-node-resolve": "^13.1.3",
43
44
  "@types/jest": "^27.4.1",
44
45
  "jest": "^27.5.1",
45
46
  "json-loader": "^0.5.7",
46
- "lit-html": "^2.2.0",
47
+ "lit-html": "^2.2.1",
47
48
  "marked": "^4.0.12",
48
- "rollup": "^2.68.0",
49
+ "rollup": "^2.70.1",
49
50
  "rollup-plugin-filesize": "^9.1.2",
50
51
  "rollup-plugin-node-resolve": "^5.2.0",
51
52
  "rollup-plugin-sourcemaps": "^0.6.3",
52
53
  "rollup-plugin-terser": "^7.0.2",
53
- "ts-jest": "^27.1.3",
54
- "ts-loader": "^9.2.6",
55
- "typescript": "^4.5.5",
56
- "webpack": "^5.69.1",
54
+ "ts-jest": "^27.1.4",
55
+ "ts-loader": "^9.2.8",
56
+ "typescript": "^4.6.3",
57
+ "webpack": "^5.71.0",
57
58
  "webpack-cli": "^4.9.2",
58
- "webpack-dev-server": "^4.7.4"
59
+ "webpack-dev-server": "^4.8.0"
59
60
  },
60
61
  "jest": {
61
62
  "testEnvironment": "jsdom",
@@ -2,7 +2,7 @@ import app from './apprun'
2
2
  export {
3
3
  app, Component, View, Action, Update, on, update, event, EventOptions,
4
4
  customElement, CustomElementOptions,
5
- ROUTER_404_EVENT, ROUTER_EVENT
5
+ ROUTER_404_EVENT, ROUTER_EVENT, safeHTML
6
6
  } from './apprun'
7
7
  import { createElement, render, Fragment, html, svg, run } from './vdom-lit-html';
8
8
  export { html, svg, render, run }
package/src/apprun.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import app from './app';
2
- import { createElement, render, Fragment } from './vdom';
2
+ import { createElement, render, Fragment,safeHTML } from './vdom';
3
3
  import { Component } from './component';
4
4
  import { VNode, View, Action, Update, EventOptions, ActionOptions, MountOptions, AppStartOptions } from './types';
5
5
  import { on, update, customElement } from './decorator';
@@ -50,9 +50,8 @@ if (typeof document === 'object') {
50
50
  }
51
51
  });
52
52
  }
53
-
54
53
  export type StatelessComponent<T = {}> = (args: T) => string | VNode | void;
55
- export { app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment }
54
+ export { app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment, safeHTML }
56
55
  export { update as event };
57
56
  export { ROUTER_EVENT, ROUTER_404_EVENT };
58
57
  export { customElement, CustomElementOptions, AppStartOptions };
package/src/component.ts CHANGED
@@ -144,7 +144,7 @@ export class Component<T = any, E = any> {
144
144
 
145
145
  if (options.route) {
146
146
  this.update = this.update || {};
147
- this.update[options.route] = REFRESH;
147
+ if (!this.update[options.route]) this.update[options.route] = REFRESH;
148
148
  }
149
149
 
150
150
  this.add_actions();
package/src/directive.ts CHANGED
@@ -19,15 +19,15 @@ const apply_directive = (key: string, props: {}, tag, component) => {
19
19
  const event = props[key];
20
20
  key = key.substring(1)
21
21
  if (typeof event === 'boolean') {
22
- props[key] = e => component.run(key, e);
22
+ props[key] = e => component.run ? component.run(key, e) : app.run(key, e);
23
23
  } else if (typeof event === 'string') {
24
- props[key] = e => component.run(event, e);
24
+ props[key] = e => component.run ? component.run(event, e) : app.run(event, e);
25
25
  } else if (typeof event === 'function') {
26
26
  props[key] = e => component.setState(event(component.state, e));
27
27
  } else if (Array.isArray(event)) {
28
28
  const [handler, ...p] = event;
29
29
  if (typeof handler === 'string') {
30
- props[key] = e => component.run(handler, ...p, e);
30
+ props[key] = e => component.run ? component.run(handler, ...p, e) : app.run(handler, ...p, e);
31
31
  } else if (typeof handler === 'function') {
32
32
  props[key] = e => component.setState(handler(component.state, ...p, e));
33
33
  }
@@ -4,6 +4,7 @@ import { createElement, updateElement, Fragment } from './vdom-my';
4
4
  import { render, svg, html, noChange, nothing } from 'lit-html';
5
5
  import { directive, Directive, Part, PartInfo, PartType, EventPart } from 'lit-html/directive.js';
6
6
  import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
7
+ import app from './apprun';
7
8
 
8
9
  function _render(element, vdom, parent?) {
9
10
  if (!vdom) return;
@@ -45,7 +46,10 @@ export class RunDirective extends Directive {
45
46
  }
46
47
  const [event, ...args] = params;
47
48
  if (typeof event === 'string') {
48
- element[`on${name}`] = e => getComponent().run(event, ...args, e);
49
+ element[`on${name}`] = e => {
50
+ const component = getComponent();
51
+ component ? component.run(event, ...args, e) : app.run(event, ...args, e)
52
+ }
49
53
  } else if (typeof event === 'function') {
50
54
  element[`on${name}`] = e => getComponent().setState(event(getComponent().state, ...args, e));
51
55
  }
package/src/vdom-my.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { VDOM, VNode } from './types';
2
+ import directive from './directive';
2
3
  export type Element = any; //HTMLElement | SVGSVGElement | SVGElement;
3
4
 
4
5
  export function Fragment(props, ...children): any[] {
@@ -36,10 +37,14 @@ export function createElement(tag: string | Function | [], props?: {}, ...childr
36
37
 
37
38
  const keyCache = new WeakMap();
38
39
 
39
- export const updateElement = render;
40
+ export const updateElement = (element: Element, nodes: VDOM, component = {}) => {
41
+ // tslint:disable-next-line
42
+ if (nodes == null || nodes === false) return;
43
+ nodes = directive(nodes, component);
44
+ render(element, nodes, component);
45
+ }
40
46
 
41
- export function render(element: Element, nodes: VDOM, parent = {}) {
42
- // console.log('render', element, node);
47
+ function render(element: Element, nodes: VDOM, parent = {}) {
43
48
  // tslint:disable-next-line
44
49
  if (nodes == null || nodes === false) return;
45
50
 
@@ -130,6 +135,12 @@ function updateChildren(element, children, isSvg: boolean) {
130
135
  }
131
136
  }
132
137
 
138
+ export const safeHTML = (html: string) => {
139
+ const div = document.createElement('section');
140
+ div.insertAdjacentHTML('afterbegin', html)
141
+ return Array.from(div.childNodes);
142
+ }
143
+
133
144
  function createText(node) {
134
145
  if (node?.indexOf('_html:') === 0) { // ?
135
146
  const div = document.createElement('div');
package/src/vdom.ts CHANGED
@@ -1,7 +1,4 @@
1
- import { createElement, updateElement, Fragment } from './vdom-my';
2
- export function render(element, html, parent?) {
3
- updateElement(element, html, parent);
4
- }
5
- export { createElement, Fragment };
1
+ import { createElement, updateElement, Fragment, safeHTML } from './vdom-my';
2
+ export { createElement, Fragment, updateElement as render, safeHTML };
6
3
 
7
4
 
@@ -59,20 +59,22 @@ export const customElement = (componentClass, options: CustomElementOptions = {}
59
59
  });
60
60
  })
61
61
 
62
- const children = this.children ? Array.from(this.children) : [];
63
- children.forEach(el => el.parentElement.removeChild(el));
64
- this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);
65
- // attach props to component
66
- this._component._props = props;
67
- // expose dispatchEvent
68
- this._component.dispatchEvent = this.dispatchEvent.bind(this)
69
- if (this._component.mounted) {
70
- const new_state = this._component.mounted(props, children, this._component.state);
71
- if (typeof new_state !== 'undefined') this._component.state = new_state;
72
- }
73
- this.on = this._component.on.bind(this._component);
74
- this.run = this._component.run.bind(this._component);
75
- if (!(opts.render===false)) this._component.run('.');
62
+ requestAnimationFrame(() => {
63
+ const children = this.children ? Array.from(this.children) : [];
64
+ children.forEach(el => el.parentElement.removeChild(el));
65
+ this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);
66
+ // attach props to component
67
+ this._component._props = props;
68
+ // expose dispatchEvent
69
+ this._component.dispatchEvent = this.dispatchEvent.bind(this)
70
+ if (this._component.mounted) {
71
+ const new_state = this._component.mounted(props, children, this._component.state);
72
+ if (typeof new_state !== 'undefined') this._component.state = new_state;
73
+ }
74
+ this.on = this._component.on.bind(this._component);
75
+ this.run = this._component.run.bind(this._component);
76
+ if (!(opts.render === false)) this._component.run('.');
77
+ });
76
78
  }
77
79
  }
78
80
 
File without changes