render-core 1.4.20 → 1.4.22

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.
@@ -5,27 +5,50 @@ import { locateInputAddress } from "../../system/utility/react/sectionUtility";
5
5
  * @param updater
6
6
  */
7
7
  export function get_proxy_for_method(data, updater) {
8
- var handel = {};
9
- handel["set"] = get_setter_for_method_proxy(updater);
10
- return new Proxy(data, handel);
11
- }
12
- /**
13
- * @param updater
14
- */
15
- function get_setter_for_method_proxy(updater) {
16
- var setter = function (obj, prop, value) {
17
- Reflect.set(obj, prop, value);
18
- update_Render(this);
19
- try {
20
- this.watcher[prop](obj[prop], value);
8
+ function isPlainObject(value) {
9
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
10
+ }
11
+ function createProxy(target) {
12
+ return new Proxy(target, {
13
+ set: function (obj, prop, value) {
14
+ var existed = prop in obj;
15
+ if (isPlainObject(value)) {
16
+ value = wrapObject(value);
17
+ }
18
+ Reflect.set(obj, prop, value);
19
+ // Only activate updater when an existing property of a plain object changes.
20
+ // Adding new properties or mutating arrays does not activate it.
21
+ if (isPlainObject(obj) && existed) {
22
+ update_Render(updater);
23
+ try {
24
+ if (updater.watcher && typeof updater.watcher[prop] === 'function') {
25
+ updater.watcher[prop](obj[prop], value);
26
+ }
27
+ }
28
+ catch (error) {
29
+ // silently ignore missing watchers
30
+ }
31
+ locateInputAddress(updater);
32
+ Reflect.deleteProperty(updater, 'origin');
33
+ }
34
+ return true;
35
+ }
36
+ });
37
+ }
38
+ function wrapObject(target) {
39
+ if (!isPlainObject(target)) {
40
+ return target;
21
41
  }
22
- catch (error) {
42
+ for (var _i = 0, _a = Object.keys(target); _i < _a.length; _i++) {
43
+ var key = _a[_i];
44
+ var value = target[key];
45
+ if (isPlainObject(value)) {
46
+ target[key] = wrapObject(value);
47
+ }
23
48
  }
24
- locateInputAddress(this);
25
- Reflect.deleteProperty(this, "origin");
26
- return true;
27
- };
28
- return setter.bind(updater);
49
+ return createProxy(target);
50
+ }
51
+ return wrapObject(data);
29
52
  }
30
53
  /**
31
54
  * @param origin
@@ -1,6 +1,6 @@
1
1
  import { ContextController } from "../../system/prototype/ContextController";
2
2
  /**
3
- * 更新渲染方法
3
+ * Method for upgrade
4
4
  * @param currentController
5
5
  */
6
6
  export declare function update_Render(currentController: ContextController): void;
@@ -4,7 +4,7 @@ import { findComponent } from "../delivery/delivery";
4
4
  import { getTemplate } from "../../system/utility/initiate/templateUtility";
5
5
  import { archive_mount, mountForUpdate } from "../../system/lifecycle/mount";
6
6
  /**
7
- * 更新渲染方法
7
+ * Method for upgrade
8
8
  * @param currentController
9
9
  */
10
10
  export function update_Render(currentController) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "render-core",
3
- "version": "1.4.20",
3
+ "version": "1.4.22",
4
4
  "description": "The extendable javascript web framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,13 +1,13 @@
1
1
  import { ContextController } from "../prototype/ContextController";
2
2
  /**
3
- * 该函数用于处理渲染后操作
3
+ * This function handles pre-render operations
4
4
  * @param currenController
5
5
  * @param child
6
6
  * @param parentController
7
7
  */
8
8
  export declare function after_process_for_init(currenController: ContextController, child: ChildNode, parentController: ContextController): void;
9
9
  /**
10
- * 该函数用于处理渲染后操作
10
+ * This function handles post-render operations
11
11
  * @param currentController
12
12
  * @param parentController
13
13
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 该函数用于处理渲染后操作
2
+ * This function handles pre-render operations
3
3
  * @param currenController
4
4
  * @param child
5
5
  * @param parentController
@@ -11,7 +11,7 @@ export function after_process_for_init(currenController, child, parentController
11
11
  parentController.lazyComponent.set(child.getAttribute("name"), controller.originalData);
12
12
  }
13
13
  /**
14
- * 该函数用于处理渲染后操作
14
+ * This function handles post-render operations
15
15
  * @param currentController
16
16
  * @param parentController
17
17
  */
@@ -1,7 +1,7 @@
1
1
  import { ContextController } from "../prototype/ContextController";
2
2
  import { Component } from "../../index";
3
3
  /**
4
- * This function is used to mount the dom to the html document.
4
+ * This function is used to mount the dom to the HTML document.
5
5
  * @param controller
6
6
  * @param proto
7
7
  * @param parent
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This function is used to mount the dom to the html document.
2
+ * This function is used to mount the dom to the HTML document.
3
3
  * @param controller
4
4
  * @param proto
5
5
  * @param parent
@@ -1,16 +0,0 @@
1
- import { Component } from "../index";
2
- export interface DirectiveLocation {
3
- directive: string;
4
- expression: string;
5
- element: string;
6
- line: number;
7
- column: number;
8
- }
9
- export interface LintError {
10
- rule: string;
11
- message: string;
12
- line: number;
13
- column: number;
14
- }
15
- export declare function lintComponent(component: Component): LintError[];
16
- export declare function lintComponents(components: Component[]): Map<string, LintError[]>;
@@ -1,123 +0,0 @@
1
- var BOOLEAN_CONDITION_DIRECTIVES = ["@if", "@show"];
2
- var ARRAY_ITERATION_DIRECTIVES = ["@for", "@map"];
3
- var MODEL_ELEMENT = ["INPUT", "SELECT", "TEXTAREA"];
4
- function parseTemplateForDirectives(template) {
5
- var directives = [];
6
- var lines = template.split("\n");
7
- for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {
8
- var line = lines[lineIndex];
9
- var directiveRegex = /@(\w+)(?:\s*=\s*"([^"]*)"|\s*=\s*'([^']*)')?/g;
10
- var match = void 0;
11
- while ((match = directiveRegex.exec(line)) !== null) {
12
- var directiveName = match[1];
13
- var expression = match[2] || match[3] || "";
14
- var elementMatch = line.match(/<(\w+)/);
15
- var element = elementMatch ? elementMatch[1] : "unknown";
16
- directives.push({
17
- directive: "@".concat(directiveName),
18
- expression: expression,
19
- element: element.toUpperCase(),
20
- line: lineIndex + 1,
21
- column: match.index + 1
22
- });
23
- }
24
- }
25
- return directives;
26
- }
27
- function inferType(value) {
28
- if (value === true || value === false)
29
- return "boolean";
30
- if (Array.isArray(value))
31
- return "array";
32
- if (typeof value === "number")
33
- return "number";
34
- if (typeof value === "string")
35
- return "string";
36
- if (typeof value === "object" && value !== null)
37
- return "object";
38
- if (value === null)
39
- return "null";
40
- return "unknown";
41
- }
42
- function getDataTypes(component) {
43
- var types = new Map();
44
- var data = component.getData();
45
- if (data && typeof data === "object") {
46
- Object.keys(data).forEach(function (key) {
47
- types.set(key, inferType(data[key]));
48
- });
49
- }
50
- return types;
51
- }
52
- function validateBooleanCondition(directive, component) {
53
- var dataTypes = getDataTypes(component);
54
- var actualType = dataTypes.get(directive.expression);
55
- if (actualType && actualType !== "boolean") {
56
- return {
57
- rule: "boolean-condition",
58
- message: "Directive '".concat(directive.directive, "' expects boolean but '").concat(directive.expression, "' is ").concat(actualType),
59
- line: directive.line,
60
- column: directive.column
61
- };
62
- }
63
- return null;
64
- }
65
- function validateArrayIteration(directive, component) {
66
- var dataTypes = getDataTypes(component);
67
- var actualType = dataTypes.get(directive.expression);
68
- if (actualType && actualType !== "array") {
69
- return {
70
- rule: "array-iteration",
71
- message: "Directive '".concat(directive.directive, "' expects array but '").concat(directive.expression, "' is ").concat(actualType),
72
- line: directive.line,
73
- column: directive.column
74
- };
75
- }
76
- return null;
77
- }
78
- function validateModelElement(directive, component) {
79
- if (MODEL_ELEMENT.indexOf(directive.element) === -1) {
80
- return {
81
- rule: "valid-model-element",
82
- message: "Directive '@model' can only be used on INPUT, SELECT, or TEXTAREA, but found '".concat(directive.element, "'"),
83
- line: directive.line,
84
- column: directive.column
85
- };
86
- }
87
- return null;
88
- }
89
- export function lintComponent(component) {
90
- var errors = [];
91
- var template = component.getTemplate();
92
- var directives = parseTemplateForDirectives(template);
93
- for (var _i = 0, directives_1 = directives; _i < directives_1.length; _i++) {
94
- var directive = directives_1[_i];
95
- if (BOOLEAN_CONDITION_DIRECTIVES.indexOf(directive.directive) !== -1) {
96
- var error = validateBooleanCondition(directive, component);
97
- if (error)
98
- errors.push(error);
99
- }
100
- if (ARRAY_ITERATION_DIRECTIVES.indexOf(directive.directive) !== -1) {
101
- var error = validateArrayIteration(directive, component);
102
- if (error)
103
- errors.push(error);
104
- }
105
- if (directive.directive === "@model") {
106
- var error = validateModelElement(directive, component);
107
- if (error)
108
- errors.push(error);
109
- }
110
- }
111
- return errors;
112
- }
113
- export function lintComponents(components) {
114
- var allErrors = new Map();
115
- for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
116
- var component = components_1[_i];
117
- var errors = lintComponent(component);
118
- if (errors.length > 0) {
119
- allErrors.set(component.getName(), errors);
120
- }
121
- }
122
- return allErrors;
123
- }
File without changes
@@ -1,4 +0,0 @@
1
- window.onerror = function (message, source, lineno, colno, error) {
2
- console.error("捕获到全局错误:", message, "在", source, "的第", lineno, "行");
3
- return true;
4
- };