render-core 1.3.39 → 1.3.40

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.
@@ -3,33 +3,6 @@ import { AppTip } from "../tips/appTip";
3
3
  * This class is associated with localStorage.
4
4
  */
5
5
  export declare class AppController implements AppTip {
6
- private readonly fields;
7
- constructor();
8
- /**
9
- * This method is used to add custom data.
10
- * @param fields
11
- */
12
- saveFields(fields: {}): void;
13
- /**
14
- * 更新数据
15
- * @private
16
- */
17
- loadFields(): void;
18
- /**
19
- * store fields
20
- */
21
- storeFields(): void;
22
- /**
23
- *
24
- * @param field
25
- * @param value
26
- */
27
- setField(field: string, value: any): void;
28
- /**
29
- * 获取数据
30
- * @param field
31
- */
32
- getField(field: string): any;
33
6
  /**
34
7
  * 资源定向
35
8
  * @param url
@@ -1,117 +1,10 @@
1
1
  import { locate, redirect } from "../../http/redirect/redirect";
2
- import { status_read, status_write } from "../../index";
3
2
  /**
4
3
  * This class is associated with localStorage.
5
4
  */
6
5
  var AppController = /** @class */ (function () {
7
- //系统变量
8
6
  function AppController() {
9
- this.fields = {
10
- system_theme: {
11
- data: "default",
12
- react: true,
13
- push: true,
14
- callback: function (value, context) {
15
- context.saveFields({
16
- "system_theme": {
17
- data: value,
18
- react: true,
19
- down: false
20
- }
21
- });
22
- context.storeFields();
23
- context.loadFields();
24
- }
25
- }
26
- };
27
7
  }
28
- /**
29
- * This method is used to add custom data.
30
- * @param fields
31
- */
32
- AppController.prototype.saveFields = function (fields) {
33
- for (var fieldsKey in fields) {
34
- if (Reflect.has(this.fields, fieldsKey)) {
35
- console.log("This filed is a system filed, please have a new name for the filed:" + fieldsKey);
36
- }
37
- else {
38
- Reflect.set(this.fields, fieldsKey, fields[fieldsKey]);
39
- }
40
- }
41
- };
42
- /**
43
- * 更新数据
44
- * @private
45
- */
46
- AppController.prototype.loadFields = function () {
47
- for (var fieldsKey in this.fields) {
48
- if (this.fields[fieldsKey].react) {
49
- if (status_read({
50
- type: "local",
51
- fields: [fieldsKey]
52
- })[fieldsKey]) {
53
- this.fields[fieldsKey].data = status_read({
54
- type: "local",
55
- fields: [fieldsKey]
56
- })[fieldsKey]["data"];
57
- }
58
- }
59
- if (this.fields[fieldsKey].push) {
60
- // @ts-ignore
61
- this.fields[fieldsKey].callback(this.fields[fieldsKey]["data"], window.context);
62
- }
63
- }
64
- };
65
- /**
66
- * store fields
67
- */
68
- AppController.prototype.storeFields = function () {
69
- for (var fieldsKey in this.fields) {
70
- if (!status_read({
71
- type: "local",
72
- fields: [fieldsKey]
73
- })[fieldsKey]) {
74
- var data = {};
75
- Reflect.set(data, fieldsKey, {
76
- data: this.fields[fieldsKey]["data"]
77
- });
78
- status_write({
79
- type: "local",
80
- fields: data
81
- });
82
- }
83
- }
84
- };
85
- /**
86
- *
87
- * @param field
88
- * @param value
89
- */
90
- AppController.prototype.setField = function (field, value) {
91
- var data = {};
92
- Reflect.set(data, field, {
93
- data: value
94
- });
95
- //写入数
96
- status_write({
97
- type: "local",
98
- fields: data
99
- });
100
- //更新数据
101
- this.loadFields();
102
- };
103
- /**
104
- * 获取数据
105
- * @param field
106
- */
107
- AppController.prototype.getField = function (field) {
108
- if (this.fields[field]) {
109
- return this.fields[field].data;
110
- }
111
- else {
112
- return null;
113
- }
114
- };
115
8
  /**
116
9
  * 资源定向
117
10
  * @param url
@@ -1,5 +1,3 @@
1
1
  export interface RenderTip {
2
2
  use(callable: any): void;
3
- configApp(config: {}): void;
4
- configContext(config: {}): void;
5
3
  }
@@ -15,15 +15,3 @@ export declare function themeStyle(component: Component, styleLib: Map<string, o
15
15
  * @param tag
16
16
  */
17
17
  export declare function styleResolve(tag: string): void;
18
- /**
19
- *
20
- * @param theme
21
- */
22
- export declare function reloadStyle(theme: string): void;
23
- /**
24
- *
25
- * @param tag
26
- * @param theme
27
- */
28
- export declare function changeStyle(tag: string, theme: string): void;
29
- export declare function changeTheme(theme: string): void;
@@ -36,8 +36,7 @@ export function themeStyle(component, styleLib) {
36
36
  * @param tag
37
37
  */
38
38
  export function styleResolve(tag) {
39
- // @ts-ignore
40
- var theme = window.context.getField("system_theme");
39
+ var theme = getUrlParam("theme");
41
40
  if (Reflect.get(window, "styleLib").get(tag.toUpperCase()).get(theme) === undefined) {
42
41
  console.log("tag:" + tag + " has no theme " + theme);
43
42
  if (Reflect.get(window, "styleLib").get(tag.toUpperCase()).get("default") === undefined) {
@@ -52,63 +51,17 @@ export function styleResolve(tag) {
52
51
  }
53
52
  }
54
53
  /**
55
- *
56
- * @param theme
54
+ * 从url中获取主题参数
55
+ * @param name
57
56
  */
58
- export function reloadStyle(theme) {
59
- Reflect.get(window, "styleLib").forEach(function (value, key) {
60
- var styles = document.getElementsByTagName("style");
61
- for (var i = 0; i < styles.length; i++) {
62
- if (styles[i].getAttribute("tag") === key) {
63
- var style = document.createElement('style');
64
- if (value.get(theme)) {
65
- var text = document.createTextNode(value.get(theme));
66
- style.appendChild(text);
67
- style.setAttribute("tag", key.toUpperCase());
68
- style.setAttribute("theme", theme);
69
- var head = document.getElementsByTagName('head')[0];
70
- head.replaceChild(style, styles[i]);
71
- }
72
- }
73
- }
74
- });
75
- }
76
- /**
77
- *
78
- * @param tag
79
- * @param theme
80
- */
81
- export function changeStyle(tag, theme) {
82
- var styleTxt = Reflect.get(window, "styleLib").get(tag.toUpperCase()).get(theme);
83
- if (styleTxt === undefined) {
84
- console.log("Dont`t find this style!");
85
- }
86
- else {
87
- var style = document.createElement('style');
88
- var text = document.createTextNode(styleTxt);
89
- style.appendChild(text);
90
- style.setAttribute("tag", tag.toUpperCase());
91
- style.setAttribute("theme", theme);
92
- var head = document.getElementsByTagName('head')[0];
93
- var target = head.querySelector("style" + "[tag=" + tag.toUpperCase() + "]");
94
- head.replaceChild(style, target);
57
+ function getUrlParam(name) {
58
+ //构造一个含有目标参数的正则表达式对象
59
+ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
60
+ //匹配目标参数
61
+ var r = window.location.search.substr(1).match(reg);
62
+ //返回参数值
63
+ if (r != null) {
64
+ return decodeURI(r[2]);
95
65
  }
96
- }
97
- export function changeTheme(theme) {
98
- Reflect.get(window, "styleLib").forEach(function (value, key) {
99
- var styles = document.getElementsByTagName("style");
100
- for (var i = 0; i < styles.length; i++) {
101
- if (styles[i].getAttribute("tag") === key) {
102
- var style = document.createElement('style');
103
- if (value.get(theme)) {
104
- var text = document.createTextNode(value.get(theme));
105
- style.appendChild(text);
106
- style.setAttribute("tag", key.toUpperCase());
107
- style.setAttribute("theme", theme);
108
- var head = document.getElementsByTagName('head')[0];
109
- head.replaceChild(style, styles[i]);
110
- }
111
- }
112
- }
113
- });
66
+ return undefined;
114
67
  }
package/index.d.ts CHANGED
@@ -9,19 +9,8 @@ export declare class RenderJS implements RenderTip {
9
9
  readonly tagLib: Map<string, Component>;
10
10
  readonly styleLib: Map<string, Map<string, string>>;
11
11
  private readonly application;
12
- private readonly context;
13
12
  page: PageController;
14
13
  constructor();
15
- /**
16
- *
17
- * @param config
18
- */
19
- configApp(config: {}): void;
20
- /**
21
- *
22
- * @param config
23
- */
24
- configContext(config: {}): void;
25
14
  /**
26
15
  *
27
16
  * @param callable
@@ -53,19 +42,3 @@ export declare class RenderJS implements RenderTip {
53
42
  * @param func
54
43
  */
55
44
  export declare function registerElements(name: string, func: any): void;
56
- /**
57
- * This is the read api of status.
58
- * @param config
59
- */
60
- export declare function status_read(config: {
61
- type: string;
62
- fields: string[];
63
- }): any;
64
- /**
65
- * This is the write api of status.
66
- * @param config
67
- */
68
- export declare function status_write(config: {
69
- type: string;
70
- fields: {};
71
- }): void;
package/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import { PageController } from "./class/controller/pageController";
2
2
  import { registerTagLib, render } from "./runtime/tools";
3
3
  import { AppController } from "./class/controller/appController";
4
- import { ContextController } from "./class/controller/contextController";
5
- import { localStorageEngine_read, sessionStorageEngin_read } from "./status/read/read";
6
- import { localStorageEngine_write, sessionStorageEngin_write } from "./status/write/write";
7
4
  /**
8
5
  * This class is the application class.
9
6
  */
@@ -15,31 +12,11 @@ var RenderJS = /** @class */ (function () {
15
12
  this.styleLib = new Map();
16
13
  //initiate the application controller
17
14
  this.application = new AppController();
18
- //initiate the context controller
19
- this.context = new ContextController();
20
15
  //initiate the page controller
21
16
  this.page = new PageController();
22
17
  //initiate the config object
23
18
  this.config = {};
24
19
  }
25
- /**
26
- *
27
- * @param config
28
- */
29
- RenderJS.prototype.configApp = function (config) {
30
- this.application.saveFields(config);
31
- this.application.storeFields();
32
- this.application.loadFields();
33
- };
34
- /**
35
- *
36
- * @param config
37
- */
38
- RenderJS.prototype.configContext = function (config) {
39
- this.context.saveFields(config);
40
- this.context.storeFields();
41
- this.context.loadFields();
42
- };
43
20
  /**
44
21
  *
45
22
  * @param callable
@@ -61,7 +38,6 @@ var RenderJS = /** @class */ (function () {
61
38
  Reflect.set(window, "tagLib", this.tagLib);
62
39
  Reflect.set(window, "styleLib", this.styleLib);
63
40
  Reflect.set(window, "appSite", this.application);
64
- Reflect.set(window, "context", this.context);
65
41
  Reflect.set(window, "page", this.page);
66
42
  };
67
43
  /**
@@ -92,39 +68,3 @@ export { RenderJS };
92
68
  export function registerElements(name, func) {
93
69
  Reflect.set(window, name, func);
94
70
  }
95
- /**
96
- * This is the read api of status.
97
- * @param config
98
- */
99
- export function status_read(config) {
100
- var fields = config.fields;
101
- var message = {};
102
- if (config.type == "session") {
103
- fields.forEach(function (value) {
104
- message[value] = sessionStorageEngin_read(value);
105
- });
106
- }
107
- else {
108
- fields.forEach(function (value) {
109
- message[value] = localStorageEngine_read(value);
110
- });
111
- }
112
- return message;
113
- }
114
- /**
115
- * This is the write api of status.
116
- * @param config
117
- */
118
- export function status_write(config) {
119
- var fields = Object.getOwnPropertyNames(config.fields);
120
- if (config.type == "session") {
121
- fields.forEach(function (value) {
122
- sessionStorageEngin_write(value, config.fields);
123
- });
124
- }
125
- else {
126
- fields.forEach(function (value) {
127
- localStorageEngine_write(value, config.fields);
128
- });
129
- }
130
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "render-core",
3
- "version": "1.3.39",
3
+ "version": "1.3.40",
4
4
  "description": "The extendable javascript web framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/runtime/tools.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Component } from "../class/component/component";
2
2
  import { themeStyle } from "../core/utility/styleUtility";
3
3
  import { renderHtml } from "./runtime";
4
- import { changeApplicationTheme, changeSessionTheme, changeTagTheme } from "../func/Theme";
5
4
  /**
6
5
  * This function is used to save the prototype component class in the window object.
7
6
  * So, you can hava a tip that we custom a property named 'tagLib' in the window object.
@@ -39,11 +38,6 @@ export function render(renderjs) {
39
38
  renderjs.tagLib.forEach(function (component) {
40
39
  themeStyle(component, renderjs.styleLib);
41
40
  });
42
- renderjs.configContext({});
43
- renderjs.configApp({});
44
- renderjs.registerElements("changeTagTheme", changeTagTheme);
45
- renderjs.registerElements("changeSessionTheme", changeSessionTheme);
46
- renderjs.registerElements("changeApplicationTheme", changeApplicationTheme);
47
41
  //开始渲染
48
42
  renderHtml(document.body.children, renderjs.page);
49
43
  }
@@ -1,18 +0,0 @@
1
- export declare class ContextController {
2
- private readonly fields;
3
- constructor();
4
- saveFields(fields: {}): void;
5
- loadFields(): void;
6
- storeFields(): void;
7
- /**
8
- * 写入数据
9
- * @param field
10
- * @param value
11
- */
12
- setField(field: string, value: any): void;
13
- /**
14
- * 获取数据
15
- * @param field
16
- */
17
- getField(field: string): any;
18
- }
@@ -1,79 +0,0 @@
1
- import { status_read, status_write } from "../../index";
2
- var ContextController = /** @class */ (function () {
3
- function ContextController() {
4
- this.fields = {};
5
- }
6
- ContextController.prototype.saveFields = function (fields) {
7
- for (var fieldsKey in fields) {
8
- if (Reflect.has(this.fields, fieldsKey)) {
9
- console.log("This field is a system field, please have a new name for the field:" + fieldsKey);
10
- }
11
- else {
12
- Reflect.set(this.fields, fieldsKey, fields[fieldsKey]);
13
- }
14
- }
15
- };
16
- ContextController.prototype.loadFields = function () {
17
- for (var fieldsKey in this.fields) {
18
- if (this.fields[fieldsKey].react) {
19
- if (status_read({
20
- type: "session",
21
- fields: [fieldsKey]
22
- })[fieldsKey]) {
23
- this.fields[fieldsKey].data = status_read({
24
- type: "session",
25
- fields: [fieldsKey]
26
- })[fieldsKey]["data"];
27
- }
28
- }
29
- if (this.fields[fieldsKey].down) {
30
- // @ts-ignore
31
- this.fields[fieldsKey].callback(this.fields[fieldsKey]["data"], window.appSite);
32
- }
33
- }
34
- };
35
- ContextController.prototype.storeFields = function () {
36
- for (var fieldsKey in this.fields) {
37
- var data = {};
38
- Reflect.set(data, fieldsKey, {
39
- data: this.fields[fieldsKey]["data"]
40
- });
41
- status_write({
42
- type: "session",
43
- fields: data
44
- });
45
- }
46
- };
47
- /**
48
- * 写入数据
49
- * @param field
50
- * @param value
51
- */
52
- ContextController.prototype.setField = function (field, value) {
53
- var data = {};
54
- Reflect.set(data, field, {
55
- data: value
56
- });
57
- //写入数据
58
- status_write({
59
- type: "session",
60
- fields: data
61
- });
62
- //更新数据
63
- this.loadFields();
64
- };
65
- /**
66
- * 获取数据
67
- * @param field
68
- */
69
- ContextController.prototype.getField = function (field) {
70
- if (this.fields[field]) {
71
- return this.fields[field].data;
72
- }
73
- else {
74
- return null;
75
- }
76
- };
77
- return ContextController;
78
- }());
79
- export { ContextController };
package/func/Theme.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- *
3
- * @param tag
4
- * @param theme
5
- */
6
- export declare function changeTagTheme(tag: string, theme: string): void;
7
- /**
8
- *
9
- * @param theme
10
- */
11
- export declare function changeSessionTheme(theme: string): void;
12
- /**
13
- *
14
- * @param theme
15
- */
16
- export declare function changeApplicationTheme(theme: string): void;
package/func/Theme.js DELETED
@@ -1,27 +0,0 @@
1
- import { changeStyle, changeTheme } from "../core/utility/styleUtility";
2
- /**
3
- *
4
- * @param tag
5
- * @param theme
6
- */
7
- export function changeTagTheme(tag, theme) {
8
- changeStyle(tag, theme);
9
- }
10
- /**
11
- *
12
- * @param theme
13
- */
14
- export function changeSessionTheme(theme) {
15
- var application = Reflect.get(window, "context");
16
- application.setField("system_theme", theme);
17
- changeTheme(application.getField("system_theme"));
18
- }
19
- /**
20
- *
21
- * @param theme
22
- */
23
- export function changeApplicationTheme(theme) {
24
- var application = Reflect.get(window, "appSite");
25
- application.setField("system_theme", theme);
26
- changeTheme(application.getField("system_theme"));
27
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * This function is used to get value from sessionStorage.
3
- * @param filed
4
- */
5
- export declare function sessionStorageEngin_read(filed: string): any;
6
- /**
7
- * This function is used to get value from localStorage.
8
- * @param filed
9
- */
10
- export declare function localStorageEngine_read(filed: string): any;
@@ -1,26 +0,0 @@
1
- /**
2
- * This function is used to get value from sessionStorage.
3
- * @param filed
4
- */
5
- export function sessionStorageEngin_read(filed) {
6
- if (sessionStorage.getItem(filed) !== null) {
7
- return JSON.parse(sessionStorage.getItem(filed));
8
- }
9
- else {
10
- console.warn("The sessionStorage has not init the key:" + filed);
11
- return null;
12
- }
13
- }
14
- /**
15
- * This function is used to get value from localStorage.
16
- * @param filed
17
- */
18
- export function localStorageEngine_read(filed) {
19
- if (localStorage.getItem(filed) !== null) {
20
- return JSON.parse(localStorage.getItem(filed));
21
- }
22
- else {
23
- console.warn("The localStorage has not init the key:" + filed);
24
- return null;
25
- }
26
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * This function is used to store the key-value to sessionStorage.
3
- * @param filed
4
- * @param fields
5
- */
6
- export declare function sessionStorageEngin_write(filed: string, fields: {}): void;
7
- /**
8
- * This function is used to store the key-value to localStorage.
9
- * @param filed
10
- * @param fields
11
- */
12
- export declare function localStorageEngine_write(filed: string, fields: {}): void;
@@ -1,92 +0,0 @@
1
- /**
2
- * This function is used to store the key-value to sessionStorage.
3
- * @param filed
4
- * @param fields
5
- */
6
- export function sessionStorageEngin_write(filed, fields) {
7
- if (sessionStorage.getItem(filed) !== null) {
8
- switch (typeof fields[filed]) {
9
- case "string":
10
- sessionStorage.setItem(filed, fields[filed]);
11
- break;
12
- case "number":
13
- sessionStorage.setItem(filed, fields[filed]);
14
- break;
15
- case "boolean":
16
- sessionStorage.setItem(filed, fields[filed]);
17
- break;
18
- case "bigint":
19
- sessionStorage.setItem(filed, fields[filed]);
20
- break;
21
- case "object":
22
- sessionStorage.setItem(filed, JSON.stringify(fields[filed]));
23
- break;
24
- }
25
- }
26
- else {
27
- console.warn("The sessionStorage has no key:" + filed + ", which will be stored to sessionStorage!");
28
- switch (typeof fields[filed]) {
29
- case "string":
30
- sessionStorage.setItem(filed, fields[filed]);
31
- break;
32
- case "number":
33
- sessionStorage.setItem(filed, fields[filed]);
34
- break;
35
- case "boolean":
36
- sessionStorage.setItem(filed, fields[filed]);
37
- break;
38
- case "bigint":
39
- sessionStorage.setItem(filed, fields[filed]);
40
- break;
41
- case "object":
42
- sessionStorage.setItem(filed, JSON.stringify(fields[filed]));
43
- break;
44
- }
45
- }
46
- }
47
- /**
48
- * This function is used to store the key-value to localStorage.
49
- * @param filed
50
- * @param fields
51
- */
52
- export function localStorageEngine_write(filed, fields) {
53
- if (localStorage.getItem(filed) !== null) {
54
- switch (typeof fields[filed]) {
55
- case "string":
56
- localStorage.setItem(filed, fields[filed]);
57
- break;
58
- case "number":
59
- localStorage.setItem(filed, fields[filed]);
60
- break;
61
- case "boolean":
62
- localStorage.setItem(filed, fields[filed]);
63
- break;
64
- case "bigint":
65
- localStorage.setItem(filed, fields[filed]);
66
- break;
67
- case "object":
68
- localStorage.setItem(filed, JSON.stringify(fields[filed]));
69
- break;
70
- }
71
- }
72
- else {
73
- console.warn("The localStorage has no key:" + filed + ", which will be stored to localStorage!");
74
- switch (typeof fields[filed]) {
75
- case "string":
76
- localStorage.setItem(filed, fields[filed]);
77
- break;
78
- case "number":
79
- localStorage.setItem(filed, fields[filed]);
80
- break;
81
- case "boolean":
82
- localStorage.setItem(filed, fields[filed]);
83
- break;
84
- case "bigint":
85
- localStorage.setItem(filed, fields[filed]);
86
- break;
87
- case "object":
88
- localStorage.setItem(filed, JSON.stringify(fields[filed]));
89
- break;
90
- }
91
- }
92
- }