@lango-project/lango-client 0.4.0 → 0.4.2
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/README.md +63 -4
- package/cli/.lango/runtime.mjs +24 -1
- package/cli/create.mjs +0 -0
- package/dist/.lango/runtime.mjs +24 -1
- package/dist/accordion.mjs +9 -8
- package/dist/accordion.mjs.map +1 -1
- package/dist/activities.mjs +8 -7
- package/dist/activities.mjs.map +1 -1
- package/dist/app.mjs +500 -50
- package/dist/app.mjs.map +1 -1
- package/dist/boot.mjs +3 -2
- package/dist/boot.mjs.map +1 -1
- package/dist/button.mjs +8 -7
- package/dist/button.mjs.map +1 -1
- package/dist/chip.mjs +5 -4
- package/dist/chip.mjs.map +1 -1
- package/dist/client.css +7 -0
- package/dist/combo_box.mjs +15 -14
- package/dist/combo_box.mjs.map +1 -1
- package/dist/content.mjs +9 -8
- package/dist/content.mjs.map +1 -1
- package/dist/control.mjs +2 -0
- package/dist/control.mjs.map +1 -1
- package/dist/date_input.mjs +3 -2
- package/dist/date_input.mjs.map +1 -1
- package/dist/dimensions.mjs +102 -0
- package/dist/dimensions.mjs.map +1 -0
- package/dist/error_reporter.mjs +6 -5
- package/dist/error_reporter.mjs.map +1 -1
- package/dist/fields.mjs +9 -8
- package/dist/fields.mjs.map +1 -1
- package/dist/file_input.mjs +19 -18
- package/dist/file_input.mjs.map +1 -1
- package/dist/form.mjs +15 -3
- package/dist/form.mjs.map +1 -1
- package/dist/heartbeat.mjs +12 -11
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +1 -1
- package/dist/input_changes.mjs +5 -4
- package/dist/input_changes.mjs.map +1 -1
- package/dist/longpoll.mjs +12 -11
- package/dist/longpoll.mjs.map +1 -1
- package/dist/main.mjs +45 -19
- package/dist/main.mjs.map +1 -1
- package/dist/menus.mjs +19 -18
- package/dist/menus.mjs.map +1 -1
- package/dist/navigation.mjs +7 -6
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +9 -8
- package/dist/numeric_input.mjs.map +1 -1
- package/dist/otp_input.mjs +5 -4
- package/dist/otp_input.mjs.map +1 -1
- package/dist/presentations.mjs +17 -16
- package/dist/presentations.mjs.map +1 -1
- package/dist/renderer.mjs +88 -12
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +167 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +809 -125
- package/dist/tables.mjs.map +1 -1
- package/dist/tabs.mjs +7 -6
- package/dist/tabs.mjs.map +1 -1
- package/dist/widgets.mjs +5 -4
- package/dist/widgets.mjs.map +1 -1
- package/docs/implementation.md +51 -0
- package/package.json +4 -3
- package/src/app.lango +358 -12
- package/src/control.lango +3 -0
- package/src/dimensions.lango +65 -0
- package/src/form.lango +13 -3
- package/src/heartbeat.lango +2 -2
- package/src/main.lango +24 -0
- package/src/renderer.lango +78 -9
- package/src/table_scope.lango +119 -0
- package/src/tables.lango +620 -105
- package/web/client.css +7 -0
- package/web/index.html +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostGlobal as __hostGlobal,
|
|
3
|
+
isNumber as __isNumber,
|
|
4
|
+
isString as __isString,
|
|
5
|
+
isBool as __isBool,
|
|
6
|
+
isObject as __isObject,
|
|
7
|
+
isArray as __isArray,
|
|
8
|
+
add as __add,
|
|
9
|
+
requireBoolean as __requireBoolean,
|
|
10
|
+
normalize as __normalize,
|
|
11
|
+
finite as __finite,
|
|
12
|
+
boundary as __boundary,
|
|
13
|
+
requireArity as __requireArity,
|
|
14
|
+
} from "./.lango/runtime.mjs";
|
|
15
|
+
|
|
16
|
+
export function measure(value, unit) {
|
|
17
|
+
__requireArity(arguments.length, [0, 1], "measure");
|
|
18
|
+
value = __boundary(value);
|
|
19
|
+
unit = __boundary(unit);
|
|
20
|
+
if (__requireBoolean(__requireBoolean(value === null) || __requireBoolean(value === __finite(-1)))) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(value))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isFinite(value))))) || __requireBoolean(value <= 0))) {
|
|
24
|
+
throw "Control dimensions must be positive numbers or -1 for automatic sizing";
|
|
25
|
+
}
|
|
26
|
+
return `${value}${unit}`;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function applyDimensions(element, props) {
|
|
31
|
+
__requireArity(arguments.length, [0, 1], "applyDimensions");
|
|
32
|
+
element = __boundary(element);
|
|
33
|
+
props = __boundary(props);
|
|
34
|
+
let width = measure(__normalize(props.width), "ch");
|
|
35
|
+
let height = measure(__normalize(props.height), "lh");
|
|
36
|
+
if (__requireBoolean(width !== null)) {
|
|
37
|
+
element.style.width = width;
|
|
38
|
+
element.style.maxWidth = "100%";
|
|
39
|
+
element.style.boxSizing = "border-box";
|
|
40
|
+
}
|
|
41
|
+
if (__requireBoolean(height !== null)) {
|
|
42
|
+
element.style.height = height;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function applyLayout(element, props) {
|
|
49
|
+
__requireArity(arguments.length, [0, 1], "applyLayout");
|
|
50
|
+
element = __boundary(element);
|
|
51
|
+
props = __boundary(props);
|
|
52
|
+
if (__normalize(props.type) === "container") {
|
|
53
|
+
let fluid = __normalize(props.fluid);
|
|
54
|
+
if (__requireBoolean(fluid === null)) {
|
|
55
|
+
fluid = false;
|
|
56
|
+
}
|
|
57
|
+
if (__requireBoolean(!__requireBoolean(__isBool(fluid)))) {
|
|
58
|
+
throw "Container fluid must be boolean";
|
|
59
|
+
}
|
|
60
|
+
if (__requireBoolean(fluid)) {
|
|
61
|
+
__add(element.classList, "container-fluid");
|
|
62
|
+
} else {
|
|
63
|
+
__add(element.classList, "container");
|
|
64
|
+
}
|
|
65
|
+
} else if (__normalize(props.type) === "row") {
|
|
66
|
+
__add(element.classList, "lango-row");
|
|
67
|
+
let gap = __normalize(props.gap);
|
|
68
|
+
if (__requireBoolean(gap === null)) {
|
|
69
|
+
gap = "normal";
|
|
70
|
+
}
|
|
71
|
+
if (gap === "small") {
|
|
72
|
+
__normalize(element.style.setProperty("--lango-gap", ".5rem"));
|
|
73
|
+
} else if (gap === "normal") {
|
|
74
|
+
__normalize(element.style.setProperty("--lango-gap", "1rem"));
|
|
75
|
+
} else if (gap === "large") {
|
|
76
|
+
__normalize(element.style.setProperty("--lango-gap", "1.5rem"));
|
|
77
|
+
} else {
|
|
78
|
+
throw "Row gap must be small, normal or large";
|
|
79
|
+
}
|
|
80
|
+
} else if (__normalize(props.type) === "col") {
|
|
81
|
+
__add(element.classList, "lango-col");
|
|
82
|
+
let basis = measure(__normalize(props.width), "ch");
|
|
83
|
+
let grow = __normalize(props.grow);
|
|
84
|
+
if (__requireBoolean(grow === null)) {
|
|
85
|
+
grow = basis === null;
|
|
86
|
+
}
|
|
87
|
+
if (__requireBoolean(!__requireBoolean(__isBool(grow)))) {
|
|
88
|
+
throw "Col grow must be boolean";
|
|
89
|
+
}
|
|
90
|
+
if (__requireBoolean(basis !== null)) {
|
|
91
|
+
__normalize(element.style.setProperty("--lango-basis", basis));
|
|
92
|
+
}
|
|
93
|
+
if (__requireBoolean(grow)) {
|
|
94
|
+
__normalize(element.style.setProperty("--lango-grow", "1"));
|
|
95
|
+
} else {
|
|
96
|
+
__normalize(element.style.setProperty("--lango-grow", "0"));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=dimensions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimensions.mjs","sources":["dimensions.lango"],"sourcesContent":["import js global Number\n\nexport measure(value, unit)\nexport applyDimensions(element, props)\nexport applyLayout(element, props)\n\nmeasure(value, unit)\n if value == null or value == -1\n return null\n if !is_number(value) or !Number/isFinite(value) or value <= 0\n throw \"Control dimensions must be positive numbers or -1 for automatic sizing\"\n return \"${value}${unit}\"\n\napplyDimensions(element, props)\n width = measure(props.width, \"ch\")\n height = measure(props.height, \"lh\")\n if width != null\n element.style.width = width\n element.style.maxWidth = \"100%\"\n element.style.boxSizing = \"border-box\"\n if height != null\n element.style.height = height\n return null\n\napplyLayout(element, props)\n switch props.type\n case \"container\"\n fluid = props.fluid\n if fluid == null\n fluid = false\n if !is_bool(fluid)\n throw \"Container fluid must be boolean\"\n if fluid\n element.classList.add(\"container-fluid\")\n else\n element.classList.add(\"container\")\n case \"row\"\n element.classList.add(\"lango-row\")\n gap = props.gap\n if gap == null\n gap = \"normal\"\n switch gap\n case \"small\"\n element.style.setProperty(\"--lango-gap\", \".5rem\")\n case \"normal\"\n element.style.setProperty(\"--lango-gap\", \"1rem\")\n case \"large\"\n element.style.setProperty(\"--lango-gap\", \"1.5rem\")\n else\n throw \"Row gap must be small, normal or large\"\n case \"col\"\n element.classList.add(\"lango-col\")\n basis = measure(props.width, \"ch\")\n grow = props.grow\n if grow == null\n grow = basis == null\n if !is_bool(grow)\n throw \"Col grow must be boolean\"\n if basis != null\n element.style.setProperty(\"--lango-basis\", basis)\n if grow\n element.style.setProperty(\"--lango-grow\", \"1\")\n else\n element.style.setProperty(\"--lango-grow\", \"0\")\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/error_reporter.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hostGlobal as __hostGlobal,
|
|
3
|
+
bindContexts as __bindContexts,
|
|
3
4
|
isNumber as __isNumber,
|
|
4
5
|
isString as __isString,
|
|
5
6
|
isBool as __isBool,
|
|
@@ -83,11 +84,11 @@ export class ErrorReporter {
|
|
|
83
84
|
}
|
|
84
85
|
schedule() {
|
|
85
86
|
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.active)) && __requireBoolean(!__requireBoolean(__normalize(this.#flight)))) && __requireBoolean(__normalize(this.#timer) === null)) && __requireBoolean(__normalize(this.#pending.length) > 0))) {
|
|
86
|
-
let action = () => {
|
|
87
|
+
let action = __bindContexts(() => {
|
|
87
88
|
this.#timer = null;
|
|
88
89
|
this.flush();
|
|
89
90
|
return null;
|
|
90
|
-
};
|
|
91
|
+
});
|
|
91
92
|
this.#timer = __normalize(this.#app.schedule(action, 0));
|
|
92
93
|
}
|
|
93
94
|
return null;
|
|
@@ -111,15 +112,15 @@ export class ErrorReporter {
|
|
|
111
112
|
}
|
|
112
113
|
this.#sent = __numericAdd(__normalize(this.#sent), 1);
|
|
113
114
|
this.#flight = true;
|
|
114
|
-
return __normalize(this.#app.report(__normalize(entry.form), __normalize(this.#url), __normalize(entry.report), this)).catch(__withArity((error) => {
|
|
115
|
+
return __normalize(this.#app.report(__normalize(entry.form), __normalize(this.#url), __normalize(entry.report), this)).catch(__withArity(__bindContexts((error) => {
|
|
115
116
|
error = __boundary(error);
|
|
116
117
|
return null;
|
|
117
118
|
return null;
|
|
118
|
-
}, [0], "closure")).finally(() => {
|
|
119
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
119
120
|
this.#flight = false;
|
|
120
121
|
this.schedule();
|
|
121
122
|
return null;
|
|
122
|
-
});
|
|
123
|
+
}));
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
125
126
|
dispose() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_reporter.mjs","sources":["error_reporter.lango"],"sourcesContent":["import js global Promise\nimport js global Math\nimport js global RegExp\n\nexport class ErrorReporter(app, url)\n properties\n active\n methods\n capture(source, code, name, form)\n schedule()\n flush()\n dispose()\n\nErrorReporter(app, url)\n app.checkUrl(url)\n @app = app\n @url = url\n @active = true\n @pending = []\n @timer = null\n @flight = false\n @window = app.now()\n @sent = 0\n\nErrorReporter:capture(source, code, name, form)\n if !@active or form == null or form.disposed\n return null\n if @app.now() - @window >= 60000\n @window = @app.now()\n @sent = 0\n if @sent >= 10\n return null\n sources = [\"ui\", \"window\", \"promise\"]\n valid = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !sources.includes(source) or !is_string(code) or !valid.test(code)\n return null\n if !is_string(name) or name.trim() == \"\" or name.length > 256\n name = null\n for @pending as entry\n previous = entry.report\n if entry.form == form and previous.source == source and previous.code == code and previous.name == name\n previous.count = Math/min(100, previous.count + 1)\n return null\n if @pending.length >= 20\n return null\n report = {\n source: source\n code: code\n count: 1\n }\n if name != null\n report.name = name\n @pending.add({\n form: form\n report: report\n })\n schedule()\n return null\n\nErrorReporter:schedule()\n if @active and !@flight and @timer == null and @pending.length > 0\n action = ()\n @timer = null\n flush()\n @timer = @app.schedule(action, 0)\n return null\n\nErrorReporter:flush()\n if !@active or @flight\n return Promise/resolve(null)\n if @sent >= 10\n @pending = []\n return Promise/resolve(null)\n entry = @pending.shift()\n if entry == null\n return Promise/resolve(null)\n if entry.form.disposed\n schedule()\n return Promise/resolve(null)\n @sent = @sent + 1\n @flight = true\n return chain @app.report(entry.form, @url, entry.report, @this)\n catch(error)\n return null\n finally\n @flight = false\n schedule()\n\nErrorReporter:dispose()\n @active = false\n @pending = []\n if @timer != null\n @app.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error_reporter.mjs","sources":["error_reporter.lango"],"sourcesContent":["import js global Promise\nimport js global Math\nimport js global RegExp\n\nexport class ErrorReporter(app, url)\n properties\n active\n methods\n capture(source, code, name, form)\n schedule()\n flush()\n dispose()\n\nErrorReporter(app, url)\n app.checkUrl(url)\n @app = app\n @url = url\n @active = true\n @pending = []\n @timer = null\n @flight = false\n @window = app.now()\n @sent = 0\n\nErrorReporter:capture(source, code, name, form)\n if !@active or form == null or form.disposed\n return null\n if @app.now() - @window >= 60000\n @window = @app.now()\n @sent = 0\n if @sent >= 10\n return null\n sources = [\"ui\", \"window\", \"promise\"]\n valid = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !sources.includes(source) or !is_string(code) or !valid.test(code)\n return null\n if !is_string(name) or name.trim() == \"\" or name.length > 256\n name = null\n for @pending as entry\n previous = entry.report\n if entry.form == form and previous.source == source and previous.code == code and previous.name == name\n previous.count = Math/min(100, previous.count + 1)\n return null\n if @pending.length >= 20\n return null\n report = {\n source: source\n code: code\n count: 1\n }\n if name != null\n report.name = name\n @pending.add({\n form: form\n report: report\n })\n schedule()\n return null\n\nErrorReporter:schedule()\n if @active and !@flight and @timer == null and @pending.length > 0\n action = ()\n @timer = null\n flush()\n @timer = @app.schedule(action, 0)\n return null\n\nErrorReporter:flush()\n if !@active or @flight\n return Promise/resolve(null)\n if @sent >= 10\n @pending = []\n return Promise/resolve(null)\n entry = @pending.shift()\n if entry == null\n return Promise/resolve(null)\n if entry.form.disposed\n schedule()\n return Promise/resolve(null)\n @sent = @sent + 1\n @flight = true\n return chain @app.report(entry.form, @url, entry.report, @this)\n catch(error)\n return null\n finally\n @flight = false\n schedule()\n\nErrorReporter:dispose()\n @active = false\n @pending = []\n if @timer != null\n @app.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/fields.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
hostGlobal as __hostGlobal,
|
|
5
5
|
hostGlobalCall as __hostGlobalCall,
|
|
6
6
|
xmlEscape as __xmlEscape,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
7
8
|
isNumber as __isNumber,
|
|
8
9
|
isString as __isString,
|
|
9
10
|
isBool as __isBool,
|
|
@@ -107,15 +108,15 @@ export class Input extends Field {
|
|
|
107
108
|
}
|
|
108
109
|
this.setValue(__normalize(props.value));
|
|
109
110
|
if (__requireBoolean(__normalize(this.#url) !== null)) {
|
|
110
|
-
let listener = () => {
|
|
111
|
+
let listener = __bindContexts(() => {
|
|
111
112
|
this.changed();
|
|
112
113
|
return null;
|
|
113
|
-
};
|
|
114
|
+
});
|
|
114
115
|
__normalize(input.addEventListener("input", listener));
|
|
115
|
-
let release = () => {
|
|
116
|
+
let release = __bindContexts(() => {
|
|
116
117
|
__normalize(input.removeEventListener("input", listener));
|
|
117
118
|
return null;
|
|
118
|
-
};
|
|
119
|
+
});
|
|
119
120
|
__add(this.release, release);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
@@ -151,17 +152,17 @@ export class Input extends Field {
|
|
|
151
152
|
if (__requireBoolean(__normalize(this.#timer) !== null)) {
|
|
152
153
|
__hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
|
|
153
154
|
}
|
|
154
|
-
let action = () => {
|
|
155
|
+
let action = __bindContexts(() => {
|
|
155
156
|
this.#timer = null;
|
|
156
157
|
if (__requireBoolean(!__requireBoolean(__normalize(this.form.disposed)))) {
|
|
157
|
-
__normalize(this.form.send(__normalize(this.#url))).catch(__withArity((error) => {
|
|
158
|
+
__normalize(this.form.send(__normalize(this.#url))).catch(__withArity(__bindContexts((error) => {
|
|
158
159
|
error = __boundary(error);
|
|
159
160
|
__normalize(this.form.app.error(__normalize(this.form), error));
|
|
160
161
|
return null;
|
|
161
|
-
}, [0], "closure"));
|
|
162
|
+
}), [0], "closure"));
|
|
162
163
|
}
|
|
163
164
|
return null;
|
|
164
|
-
};
|
|
165
|
+
});
|
|
165
166
|
this.#timer = __hostGlobalCall(["setTimeout"], action, 500);
|
|
166
167
|
return null;
|
|
167
168
|
return null;
|
package/dist/fields.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.mjs","sources":["fields.lango"],"sourcesContent":["import js global document\nimport js global Object\nimport js global setTimeout\nimport js global clearTimeout\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\n\nexport sameValue(first, second)\nexport class Field(form, props, input) : Control\n properties\n input\n labelElement\n methods\n setDisabled(value)\n\nField(form, props, input)\n super(form, props, cloneMarkup(\"field\", <div class=\"mb-3\"></div>))\n element = @element\n @input = input\n @readonly = props.readonly == true\n @labelElement = null\n input.id = controlId()\n if props.label != null\n @labelElement = document/createElement(\"label\")\n @labelElement.htmlFor = input.id\n @labelElement.className = \"form-label\"\n @labelElement.textContent = props.label\n element.appendChild(@labelElement)\n element.appendChild(input)\n if props.description != null\n description = document/createElement(\"div\")\n description.id = controlId()\n description.className = \"form-text\"\n description.textContent = props.description\n element.appendChild(description)\n input.setAttribute(\"aria-describedby\", description.id)\n if props.aria != null\n for props.aria as name: value\n input.setAttribute(\"aria-${name}\", value)\n input.required = props.required == true\n input.readOnly = @readonly\n if props.disableAutoComplete == true\n input.autocomplete = \"off\"\n # Derived fields are not initialized until this constructor returns.\n input.disabled = props.disabled == true\n if @readonly and (input.tagName == \"SELECT\" or input.tagName == \"FIELDSET\" or input.type == \"checkbox\" or input.type == \"range\")\n input.disabled = true\n validationTarget(input)\n\nField:setDisabled(value)\n @input.disabled = value\n if @readonly and (@input.tagName == \"SELECT\" or @input.tagName == \"FIELDSET\" or @input.type == \"checkbox\" or @input.type == \"range\")\n @input.disabled = true\n return @this\n\nexport class Input(form, props) : Field\n methods\n getValue()\n setValue(value)\n changed()\n dispose()\n\nInput(form, props)\n super(form, props, inputElement(props))\n input = @input\n @numeric = input.type == \"number\"\n @timer = null\n @form = form\n @url = props.url\n if props.placeholder != null\n input.placeholder = props.placeholder\n if props.maxLength != null\n input.maxLength = props.maxLength\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n setValue(props.value)\n if @url != null\n listener = ()\n changed()\n input.addEventListener(\"input\", listener)\n release = ()\n capture input\n capture listener\n input.removeEventListener(\"input\", listener)\n @release.add(release)\n\nInput:getValue()\n if @numeric\n if @input.value == \"\" or @input.validity.badInput\n return null\n try\n return @input.valueAsNumber\n catch error\n if error.message == \"NonFiniteNumber\"\n return null\n throw error\n return @input.value\n\nInput:setValue(value)\n if value == null\n @input.value = \"\"\n else\n @input.value = \"${value}\"\n return @this\n\nInput:changed()\n if @timer != null\n clearTimeout(@timer)\n action = ()\n @timer = null\n if !@form.disposed\n chain @form.send(@url)\n catch(error)\n @form.app.error(@form, error)\n @timer = setTimeout(action, 500)\n return null\n\nInput:dispose()\n if @timer != null\n clearTimeout(@timer)\n @timer = null\n return super.dispose()\n\nexport class Checkbox(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nCheckbox(form, props)\n super(form, props, cloneMarkup(\"checkbox\", <input type=\"checkbox\" class=\"form-check-input\" />))\n input = @input\n @element.classList.add(\"form-check\")\n if @labelElement != null\n @labelElement.className = \"form-check-label\"\n @element.insertBefore(input, @labelElement)\n initial = props.value\n if props.indeterminate == true\n initial = null\n setValue(initial)\n\nCheckbox:getValue()\n if @input.indeterminate\n return null\n return @input.checked\n\nCheckbox:setValue(value)\n if value != null and !is_bool(value)\n throw \"Checkbox value must be boolean or null\"\n @input.indeterminate = value == null\n @input.checked = value == true\n return @this\n\nexport class Switch(form, props) : Checkbox\n methods\n setValue(value)\n\nSwitch(form, props)\n super(form, props)\n @element.classList.add(\"form-switch\")\n @input.setAttribute(\"role\", \"switch\")\n setValue(props.value)\n\nSwitch:setValue(value)\n if value == null\n value = false\n if !is_bool(value)\n throw \"Switch value must be boolean\"\n return super.setValue(value)\n\nexport class Range(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRange(form, props)\n super(form, props, cloneMarkup(\"range\", <input type=\"range\" class=\"form-range\" />))\n input = @input\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n if props.steps != null\n input.step = props.steps\n if props.value != null\n setValue(props.value)\n\nRange:getValue()\n return @input.valueAsNumber\n\nRange:setValue(value)\n if !is_number(value)\n throw \"Range value must be a number\"\n @input.value = \"${value}\"\n return @this\n\nexport class Select(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nSelect(form, props)\n super(form, props, cloneMarkup(\"select\", <select class=\"form-select\"></select>))\n input = @input\n @options = props.options\n if @options == null\n @options = []\n for @options as option\n node = document/createElement(\"option\")\n node.textContent = option.label\n input.appendChild(node)\n setValue(props.value)\n\nSelect:getValue()\n if @input.selectedIndex < 0\n return null\n return @options[@input.selectedIndex].value\n\nSelect:setValue(value)\n @input.selectedIndex = -1\n index = 0\n for @options as option\n if sameValue(option.value, value)\n @input.selectedIndex = index\n break\n index = index + 1\n return @this\n\nexport class Radio(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRadio(form, props)\n super(form, props, cloneMarkup(\"radio\", <fieldset role=\"radiogroup\"></fieldset>))\n input = @input\n if props.label != null\n input.setAttribute(\"aria-label\", props.label)\n @options = props.options\n if @options == null\n @options = []\n @choices = []\n for @options as option\n choice = cloneMarkup(\"radio-choice\", <input type=\"radio\" class=\"form-check-input\" />)\n choice.id = controlId()\n choice.name = input.id\n choice.disabled = option.enabled == false\n choice.required = props.required == true\n label = document/createElement(\"label\")\n label.htmlFor = choice.id\n label.className = \"form-check-label\"\n label.textContent = option.label\n row = cloneMarkup(\"radio-row\", <div class=\"form-check\"></div>)\n row.appendChild(choice)\n row.appendChild(label)\n input.appendChild(row)\n @choices.add(choice)\n if Object/hasOwn(props, \"value\")\n setValue(props.value)\n else\n if props.selectedIndex != null and props.selectedIndex >= 0 and props.selectedIndex < @choices.length\n selected = @choices[props.selectedIndex]\n selected.checked = true\n\nRadio:getValue()\n index = 0\n for @choices as choice\n if choice.checked\n return @options[index].value\n index = index + 1\n return null\n\nRadio:setValue(value)\n selected = false\n index = 0\n for @choices as choice\n choice.checked = !selected and sameValue(@options[index].value, value)\n if choice.checked\n selected = true\n index = index + 1\n return @this\n\nsameValue(first, second)\n if is_array(first)\n if !is_array(second) or first.length != second.length\n return false\n index = 0\n for first as item\n if !sameValue(item, second[index])\n return false\n index = index + 1\n return true\n if is_object(first)\n if !is_object(second) or is_array(second) or Object/keys(first).length != Object/keys(second).length\n return false\n for first as name: value\n if !Object/hasOwn(second, name) or !sameValue(value, second[name])\n return false\n return true\n return first == second\n\ninputElement(props)\n input = cloneMarkup(\"input\", <input class=\"form-control\" />)\n variant = props.variant\n if variant == null\n variant = \"text\"\n variant = variant.toLowerCase()\n if variant == \"string\"\n variant = \"text\"\n allowed = [\"text\", \"email\", \"password\", \"search\", \"tel\", \"url\", \"number\", \"decimal\", \"money\"]\n if !allowed.includes(variant)\n throw \"Unsupported input variant: ${variant}\"\n if props.lines != null and props.lines > 1\n if variant != \"text\"\n throw \"Multiline input requires text or String\"\n input = cloneMarkup(\"textarea\", <textarea class=\"form-control\"></textarea>)\n input.rows = props.lines\n else\n input.type = variant\n if variant == \"decimal\" or variant == \"money\"\n input.type = \"text\"\n input.inputMode = \"decimal\"\n return input\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"fields.mjs","sources":["fields.lango"],"sourcesContent":["import js global document\nimport js global Object\nimport js global setTimeout\nimport js global clearTimeout\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\n\nexport sameValue(first, second)\nexport class Field(form, props, input) : Control\n properties\n input\n labelElement\n methods\n setDisabled(value)\n\nField(form, props, input)\n super(form, props, cloneMarkup(\"field\", <div class=\"mb-3\"></div>))\n element = @element\n @input = input\n @readonly = props.readonly == true\n @labelElement = null\n input.id = controlId()\n if props.label != null\n @labelElement = document/createElement(\"label\")\n @labelElement.htmlFor = input.id\n @labelElement.className = \"form-label\"\n @labelElement.textContent = props.label\n element.appendChild(@labelElement)\n element.appendChild(input)\n if props.description != null\n description = document/createElement(\"div\")\n description.id = controlId()\n description.className = \"form-text\"\n description.textContent = props.description\n element.appendChild(description)\n input.setAttribute(\"aria-describedby\", description.id)\n if props.aria != null\n for props.aria as name: value\n input.setAttribute(\"aria-${name}\", value)\n input.required = props.required == true\n input.readOnly = @readonly\n if props.disableAutoComplete == true\n input.autocomplete = \"off\"\n # Derived fields are not initialized until this constructor returns.\n input.disabled = props.disabled == true\n if @readonly and (input.tagName == \"SELECT\" or input.tagName == \"FIELDSET\" or input.type == \"checkbox\" or input.type == \"range\")\n input.disabled = true\n validationTarget(input)\n\nField:setDisabled(value)\n @input.disabled = value\n if @readonly and (@input.tagName == \"SELECT\" or @input.tagName == \"FIELDSET\" or @input.type == \"checkbox\" or @input.type == \"range\")\n @input.disabled = true\n return @this\n\nexport class Input(form, props) : Field\n methods\n getValue()\n setValue(value)\n changed()\n dispose()\n\nInput(form, props)\n super(form, props, inputElement(props))\n input = @input\n @numeric = input.type == \"number\"\n @timer = null\n @form = form\n @url = props.url\n if props.placeholder != null\n input.placeholder = props.placeholder\n if props.maxLength != null\n input.maxLength = props.maxLength\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n setValue(props.value)\n if @url != null\n listener = ()\n changed()\n input.addEventListener(\"input\", listener)\n release = ()\n capture input\n capture listener\n input.removeEventListener(\"input\", listener)\n @release.add(release)\n\nInput:getValue()\n if @numeric\n if @input.value == \"\" or @input.validity.badInput\n return null\n try\n return @input.valueAsNumber\n catch error\n if error.message == \"NonFiniteNumber\"\n return null\n throw error\n return @input.value\n\nInput:setValue(value)\n if value == null\n @input.value = \"\"\n else\n @input.value = \"${value}\"\n return @this\n\nInput:changed()\n if @timer != null\n clearTimeout(@timer)\n action = ()\n @timer = null\n if !@form.disposed\n chain @form.send(@url)\n catch(error)\n @form.app.error(@form, error)\n @timer = setTimeout(action, 500)\n return null\n\nInput:dispose()\n if @timer != null\n clearTimeout(@timer)\n @timer = null\n return super.dispose()\n\nexport class Checkbox(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nCheckbox(form, props)\n super(form, props, cloneMarkup(\"checkbox\", <input type=\"checkbox\" class=\"form-check-input\" />))\n input = @input\n @element.classList.add(\"form-check\")\n if @labelElement != null\n @labelElement.className = \"form-check-label\"\n @element.insertBefore(input, @labelElement)\n initial = props.value\n if props.indeterminate == true\n initial = null\n setValue(initial)\n\nCheckbox:getValue()\n if @input.indeterminate\n return null\n return @input.checked\n\nCheckbox:setValue(value)\n if value != null and !is_bool(value)\n throw \"Checkbox value must be boolean or null\"\n @input.indeterminate = value == null\n @input.checked = value == true\n return @this\n\nexport class Switch(form, props) : Checkbox\n methods\n setValue(value)\n\nSwitch(form, props)\n super(form, props)\n @element.classList.add(\"form-switch\")\n @input.setAttribute(\"role\", \"switch\")\n setValue(props.value)\n\nSwitch:setValue(value)\n if value == null\n value = false\n if !is_bool(value)\n throw \"Switch value must be boolean\"\n return super.setValue(value)\n\nexport class Range(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRange(form, props)\n super(form, props, cloneMarkup(\"range\", <input type=\"range\" class=\"form-range\" />))\n input = @input\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n if props.steps != null\n input.step = props.steps\n if props.value != null\n setValue(props.value)\n\nRange:getValue()\n return @input.valueAsNumber\n\nRange:setValue(value)\n if !is_number(value)\n throw \"Range value must be a number\"\n @input.value = \"${value}\"\n return @this\n\nexport class Select(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nSelect(form, props)\n super(form, props, cloneMarkup(\"select\", <select class=\"form-select\"></select>))\n input = @input\n @options = props.options\n if @options == null\n @options = []\n for @options as option\n node = document/createElement(\"option\")\n node.textContent = option.label\n input.appendChild(node)\n setValue(props.value)\n\nSelect:getValue()\n if @input.selectedIndex < 0\n return null\n return @options[@input.selectedIndex].value\n\nSelect:setValue(value)\n @input.selectedIndex = -1\n index = 0\n for @options as option\n if sameValue(option.value, value)\n @input.selectedIndex = index\n break\n index = index + 1\n return @this\n\nexport class Radio(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRadio(form, props)\n super(form, props, cloneMarkup(\"radio\", <fieldset role=\"radiogroup\"></fieldset>))\n input = @input\n if props.label != null\n input.setAttribute(\"aria-label\", props.label)\n @options = props.options\n if @options == null\n @options = []\n @choices = []\n for @options as option\n choice = cloneMarkup(\"radio-choice\", <input type=\"radio\" class=\"form-check-input\" />)\n choice.id = controlId()\n choice.name = input.id\n choice.disabled = option.enabled == false\n choice.required = props.required == true\n label = document/createElement(\"label\")\n label.htmlFor = choice.id\n label.className = \"form-check-label\"\n label.textContent = option.label\n row = cloneMarkup(\"radio-row\", <div class=\"form-check\"></div>)\n row.appendChild(choice)\n row.appendChild(label)\n input.appendChild(row)\n @choices.add(choice)\n if Object/hasOwn(props, \"value\")\n setValue(props.value)\n else\n if props.selectedIndex != null and props.selectedIndex >= 0 and props.selectedIndex < @choices.length\n selected = @choices[props.selectedIndex]\n selected.checked = true\n\nRadio:getValue()\n index = 0\n for @choices as choice\n if choice.checked\n return @options[index].value\n index = index + 1\n return null\n\nRadio:setValue(value)\n selected = false\n index = 0\n for @choices as choice\n choice.checked = !selected and sameValue(@options[index].value, value)\n if choice.checked\n selected = true\n index = index + 1\n return @this\n\nsameValue(first, second)\n if is_array(first)\n if !is_array(second) or first.length != second.length\n return false\n index = 0\n for first as item\n if !sameValue(item, second[index])\n return false\n index = index + 1\n return true\n if is_object(first)\n if !is_object(second) or is_array(second) or Object/keys(first).length != Object/keys(second).length\n return false\n for first as name: value\n if !Object/hasOwn(second, name) or !sameValue(value, second[name])\n return false\n return true\n return first == second\n\ninputElement(props)\n input = cloneMarkup(\"input\", <input class=\"form-control\" />)\n variant = props.variant\n if variant == null\n variant = \"text\"\n variant = variant.toLowerCase()\n if variant == \"string\"\n variant = \"text\"\n allowed = [\"text\", \"email\", \"password\", \"search\", \"tel\", \"url\", \"number\", \"decimal\", \"money\"]\n if !allowed.includes(variant)\n throw \"Unsupported input variant: ${variant}\"\n if props.lines != null and props.lines > 1\n if variant != \"text\"\n throw \"Multiline input requires text or String\"\n input = cloneMarkup(\"textarea\", <textarea class=\"form-control\"></textarea>)\n input.rows = props.lines\n else\n input.type = variant\n if variant == \"decimal\" or variant == \"money\"\n input.type = \"text\"\n input.inputMode = \"decimal\"\n return input\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/file_input.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { InputChanges } from "./input_changes.mjs";
|
|
|
4
4
|
import {
|
|
5
5
|
hostGlobal as __hostGlobal,
|
|
6
6
|
xmlEscape as __xmlEscape,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
7
8
|
isNumber as __isNumber,
|
|
8
9
|
isString as __isString,
|
|
9
10
|
isBool as __isBool,
|
|
@@ -51,15 +52,15 @@ export class FileInput extends Field {
|
|
|
51
52
|
}
|
|
52
53
|
this.setValue(__normalize(props.value));
|
|
53
54
|
this.setDisabled(__normalize(props.disabled) === true);
|
|
54
|
-
let listener = () => {
|
|
55
|
+
let listener = __bindContexts(() => {
|
|
55
56
|
this.#changed();
|
|
56
57
|
return null;
|
|
57
|
-
};
|
|
58
|
+
});
|
|
58
59
|
__normalize(this.input.addEventListener("change", listener));
|
|
59
|
-
let release = () => {
|
|
60
|
+
let release = __bindContexts(() => {
|
|
60
61
|
__normalize(this.input.removeEventListener("change", listener));
|
|
61
62
|
return null;
|
|
62
|
-
};
|
|
63
|
+
});
|
|
63
64
|
__add(this.release, release);
|
|
64
65
|
}
|
|
65
66
|
#clear() {
|
|
@@ -109,7 +110,7 @@ export class FileInput extends Field {
|
|
|
109
110
|
let reader = new (__hostGlobal(["FileReader"]))();
|
|
110
111
|
this.#reader = reader;
|
|
111
112
|
this.#pending = readFile(reader, file);
|
|
112
|
-
__normalize(this.#pending).then(__withArity((data) => {
|
|
113
|
+
__normalize(this.#pending).then(__withArity(__bindContexts((data) => {
|
|
113
114
|
data = __boundary(data);
|
|
114
115
|
if (__requireBoolean(__requireBoolean(generation === __normalize(this.#generation)) && __requireBoolean(!__requireBoolean(__normalize(this.#closed))))) {
|
|
115
116
|
this.#reader = null;
|
|
@@ -117,7 +118,7 @@ export class FileInput extends Field {
|
|
|
117
118
|
__normalize(this.#changes.changed());
|
|
118
119
|
}
|
|
119
120
|
return null;
|
|
120
|
-
}, [0], "closure")).catch(__withArity((error) => {
|
|
121
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
121
122
|
error = __boundary(error);
|
|
122
123
|
if (__requireBoolean(__requireBoolean(generation === __normalize(this.#generation)) && __requireBoolean(!__requireBoolean(__normalize(this.#closed))))) {
|
|
123
124
|
this.#reader = null;
|
|
@@ -125,7 +126,7 @@ export class FileInput extends Field {
|
|
|
125
126
|
__normalize(this.form.app.error(__normalize(this.form), error));
|
|
126
127
|
}
|
|
127
128
|
return null;
|
|
128
|
-
}, [0], "closure"));
|
|
129
|
+
}), [0], "closure"));
|
|
129
130
|
return null;
|
|
130
131
|
return null;
|
|
131
132
|
}
|
|
@@ -140,13 +141,13 @@ export class FileInput extends Field {
|
|
|
140
141
|
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
141
142
|
}
|
|
142
143
|
let pending = __normalize(this.#pending);
|
|
143
|
-
return pending.catch(__withArity((error) => {
|
|
144
|
+
return pending.catch(__withArity(__bindContexts((error) => {
|
|
144
145
|
error = __boundary(error);
|
|
145
146
|
if (__requireBoolean(pending === __normalize(this.#pending))) {
|
|
146
147
|
throw error;
|
|
147
148
|
}
|
|
148
149
|
return null;
|
|
149
|
-
}, [0], "closure")).then(__withArity((ignored) => {
|
|
150
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
150
151
|
ignored = __boundary(ignored);
|
|
151
152
|
if (__requireBoolean(pending !== __normalize(this.#pending))) {
|
|
152
153
|
return this.prepareValue();
|
|
@@ -156,7 +157,7 @@ export class FileInput extends Field {
|
|
|
156
157
|
}
|
|
157
158
|
return null;
|
|
158
159
|
return null;
|
|
159
|
-
}, [0], "closure"));
|
|
160
|
+
}), [0], "closure"));
|
|
160
161
|
return null;
|
|
161
162
|
}
|
|
162
163
|
getValue() {
|
|
@@ -194,10 +195,10 @@ function readFile(reader, file) {
|
|
|
194
195
|
__requireArity(arguments.length, [0, 1], "readFile");
|
|
195
196
|
reader = __boundary(reader);
|
|
196
197
|
file = __boundary(file);
|
|
197
|
-
let pending = new (__hostGlobal(["Promise"]))(__withArity((resolve, reject) => {
|
|
198
|
+
let pending = new (__hostGlobal(["Promise"]))(__withArity(__bindContexts((resolve, reject) => {
|
|
198
199
|
resolve = __boundary(resolve);
|
|
199
200
|
reject = __boundary(reject);
|
|
200
|
-
let load = () => {
|
|
201
|
+
let load = __bindContexts(() => {
|
|
201
202
|
let value = __normalize(reader.result);
|
|
202
203
|
let comma = __normalize(value.indexOf(","));
|
|
203
204
|
let mime = __normalize(file.type);
|
|
@@ -206,21 +207,21 @@ function readFile(reader, file) {
|
|
|
206
207
|
}
|
|
207
208
|
__call(resolve, { name: __normalize(file.name), mimeType: mime, size: __normalize(file.size), content: __normalize(value.slice(__numericAdd(comma, 1))) });
|
|
208
209
|
return null;
|
|
209
|
-
};
|
|
210
|
-
let fail = () => {
|
|
210
|
+
});
|
|
211
|
+
let fail = __bindContexts(() => {
|
|
211
212
|
__call(reject, "File could not be read");
|
|
212
213
|
return null;
|
|
213
|
-
};
|
|
214
|
-
let abort = () => {
|
|
214
|
+
});
|
|
215
|
+
let abort = __bindContexts(() => {
|
|
215
216
|
__call(reject, "File read cancelled");
|
|
216
217
|
return null;
|
|
217
|
-
};
|
|
218
|
+
});
|
|
218
219
|
__normalize(reader.addEventListener("load", load, { once: true }));
|
|
219
220
|
__normalize(reader.addEventListener("error", fail, { once: true }));
|
|
220
221
|
__normalize(reader.addEventListener("abort", abort, { once: true }));
|
|
221
222
|
__normalize(reader.readAsDataURL(file));
|
|
222
223
|
return null;
|
|
223
|
-
}, [0, 1], "closure"));
|
|
224
|
+
}), [0, 1], "closure"));
|
|
224
225
|
return pending;
|
|
225
226
|
return null;
|
|
226
227
|
}
|
package/dist/file_input.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_input.mjs","sources":["file_input.lango"],"sourcesContent":["import js global FileReader\nimport js global Promise\nimport js global Number\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport fileLimit(value = null)\n\nfileLimit(value = null)\n if value == null\n return 1048576\n if !is_number(value) or !Number/isSafeInteger(value) or value < 1\n throw \"File maxBytes must be a positive safe integer\"\n return value\n\nexport class FileInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n prepareValue()\n dispose()\n\nFileInput(form, props)\n super(form, props, cloneMarkup(\"file-input\", <input type=\"file\" class=\"form-control\" />))\n @limit = fileLimit(props.maxBytes)\n @locked = props.readonly == true\n @changes = new InputChanges(form, props.url)\n @generation = 0\n @pending = null\n @reader = null\n @data = null\n @failure = null\n @closed = false\n if props.accept != null\n if !is_string(props.accept)\n throw \"File accept must be text\"\n @input.accept = props.accept\n setValue(props.value)\n setDisabled(props.disabled == true)\n listener = ()\n changed()\n @input.addEventListener(\"change\", listener)\n release = ()\n capture listener\n @input.removeEventListener(\"change\", listener)\n @release.add(release)\n\nFileInput:clear()\n @generation = @generation + 1\n if @reader != null\n @reader.abort()\n @reader = null\n @pending = null\n @data = null\n @failure = null\n return null\n\nFileInput:setValue(value)\n if value != null\n throw \"File values can only be cleared programmatically\"\n clear()\n @input.value = \"\"\n return @this\n\nFileInput:setDisabled(value)\n @input.disabled = value or @locked == true\n return @this\n\nFileInput:changed()\n clear()\n files = @input.files\n if files.length == 0\n @changes.changed()\n return null\n file = files[0]\n if file.size > @limit\n @failure = \"File exceeds its ${@limit}-byte limit\"\n @form.app.error(@form, @failure)\n return null\n generation = @generation\n reader = new FileReader()\n @reader = reader\n @pending = readFile(reader, file)\n chain @pending\n then(data)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @data = data\n @changes.changed()\n catch(error)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @failure = error\n @form.app.error(@form, error)\n return null\n\nFileInput:prepareValue()\n if @closed\n return Promise/reject(\"File field is disposed\")\n if @failure != null\n return Promise/reject(@failure)\n if @pending == null\n return Promise/resolve(null)\n pending = @pending\n return chain pending\n catch(error)\n capture pending\n if pending == @pending\n throw error\n then(ignored)\n capture pending\n if pending != @pending\n return prepareValue()\n if @closed\n throw \"File field is disposed\"\n return null\n\nFileInput:getValue()\n if @failure != null\n throw @failure\n if @reader != null\n throw \"File is still being read\"\n return @data\n\nFileInput:dispose()\n @closed = true\n clear()\n @changes.dispose()\n super.dispose()\n return null\n\nreadFile(reader, file)\n pending = new Promise((resolve, reject)\n capture reader\n capture file\n load = ()\n capture reader\n capture file\n capture resolve\n value = reader.result\n comma = value.indexOf(\",\")\n mime = file.type\n if mime == \"\"\n mime = \"application/octet-stream\"\n resolve({\n name: file.name\n mimeType: mime\n size: file.size\n content: value.slice(comma + 1)\n })\n fail = ()\n capture reject\n reject(\"File could not be read\")\n abort = ()\n capture reject\n reject(\"File read cancelled\")\n reader.addEventListener(\"load\", load, {\n once: true\n })\n reader.addEventListener(\"error\", fail, {\n once: true\n })\n reader.addEventListener(\"abort\", abort, {\n once: true\n })\n reader.readAsDataURL(file)\n )\n return pending\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file_input.mjs","sources":["file_input.lango"],"sourcesContent":["import js global FileReader\nimport js global Promise\nimport js global Number\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport fileLimit(value = null)\n\nfileLimit(value = null)\n if value == null\n return 1048576\n if !is_number(value) or !Number/isSafeInteger(value) or value < 1\n throw \"File maxBytes must be a positive safe integer\"\n return value\n\nexport class FileInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n prepareValue()\n dispose()\n\nFileInput(form, props)\n super(form, props, cloneMarkup(\"file-input\", <input type=\"file\" class=\"form-control\" />))\n @limit = fileLimit(props.maxBytes)\n @locked = props.readonly == true\n @changes = new InputChanges(form, props.url)\n @generation = 0\n @pending = null\n @reader = null\n @data = null\n @failure = null\n @closed = false\n if props.accept != null\n if !is_string(props.accept)\n throw \"File accept must be text\"\n @input.accept = props.accept\n setValue(props.value)\n setDisabled(props.disabled == true)\n listener = ()\n changed()\n @input.addEventListener(\"change\", listener)\n release = ()\n capture listener\n @input.removeEventListener(\"change\", listener)\n @release.add(release)\n\nFileInput:clear()\n @generation = @generation + 1\n if @reader != null\n @reader.abort()\n @reader = null\n @pending = null\n @data = null\n @failure = null\n return null\n\nFileInput:setValue(value)\n if value != null\n throw \"File values can only be cleared programmatically\"\n clear()\n @input.value = \"\"\n return @this\n\nFileInput:setDisabled(value)\n @input.disabled = value or @locked == true\n return @this\n\nFileInput:changed()\n clear()\n files = @input.files\n if files.length == 0\n @changes.changed()\n return null\n file = files[0]\n if file.size > @limit\n @failure = \"File exceeds its ${@limit}-byte limit\"\n @form.app.error(@form, @failure)\n return null\n generation = @generation\n reader = new FileReader()\n @reader = reader\n @pending = readFile(reader, file)\n chain @pending\n then(data)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @data = data\n @changes.changed()\n catch(error)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @failure = error\n @form.app.error(@form, error)\n return null\n\nFileInput:prepareValue()\n if @closed\n return Promise/reject(\"File field is disposed\")\n if @failure != null\n return Promise/reject(@failure)\n if @pending == null\n return Promise/resolve(null)\n pending = @pending\n return chain pending\n catch(error)\n capture pending\n if pending == @pending\n throw error\n then(ignored)\n capture pending\n if pending != @pending\n return prepareValue()\n if @closed\n throw \"File field is disposed\"\n return null\n\nFileInput:getValue()\n if @failure != null\n throw @failure\n if @reader != null\n throw \"File is still being read\"\n return @data\n\nFileInput:dispose()\n @closed = true\n clear()\n @changes.dispose()\n super.dispose()\n return null\n\nreadFile(reader, file)\n pending = new Promise((resolve, reject)\n capture reader\n capture file\n load = ()\n capture reader\n capture file\n capture resolve\n value = reader.result\n comma = value.indexOf(\",\")\n mime = file.type\n if mime == \"\"\n mime = \"application/octet-stream\"\n resolve({\n name: file.name\n mimeType: mime\n size: file.size\n content: value.slice(comma + 1)\n })\n fail = ()\n capture reject\n reject(\"File could not be read\")\n abort = ()\n capture reject\n reject(\"File read cancelled\")\n reader.addEventListener(\"load\", load, {\n once: true\n })\n reader.addEventListener(\"error\", fail, {\n once: true\n })\n reader.addEventListener(\"abort\", abort, {\n once: true\n })\n reader.readAsDataURL(file)\n )\n return pending\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPA;;;;;;;;;;;;AA8HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/form.mjs
CHANGED
|
@@ -25,6 +25,7 @@ export class Form {
|
|
|
25
25
|
owned;
|
|
26
26
|
inheritedNames;
|
|
27
27
|
disposed;
|
|
28
|
+
stale;
|
|
28
29
|
element;
|
|
29
30
|
resources;
|
|
30
31
|
activity;
|
|
@@ -44,6 +45,7 @@ export class Form {
|
|
|
44
45
|
this.owned = [];
|
|
45
46
|
this.inheritedNames = [];
|
|
46
47
|
this.disposed = false;
|
|
48
|
+
this.stale = false;
|
|
47
49
|
this.element = null;
|
|
48
50
|
this.resources = [];
|
|
49
51
|
this.activity = new Activities(this);
|
|
@@ -133,7 +135,7 @@ export class Form {
|
|
|
133
135
|
}
|
|
134
136
|
prepareValue() {
|
|
135
137
|
let pending = [];
|
|
136
|
-
for (const
|
|
138
|
+
for (const control of __normalize(this.owned)) {
|
|
137
139
|
if (__requireBoolean(__normalize(control.prepareValue) !== null)) {
|
|
138
140
|
let ready = __normalize(control.prepareValue());
|
|
139
141
|
if (__requireBoolean(ready !== null)) {
|
|
@@ -194,8 +196,10 @@ export class Form {
|
|
|
194
196
|
__requireArity(arguments.length, [0], "setToken");
|
|
195
197
|
token = __boundary(token);
|
|
196
198
|
if (__requireBoolean(token !== null)) {
|
|
199
|
+
if (__requireBoolean(__normalize(this.app.saveToken(token)) === false)) {
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
197
202
|
this.token = token;
|
|
198
|
-
__normalize(this.app.saveToken(token));
|
|
199
203
|
if (__requireBoolean(__normalize(this.app.heartbeat) !== null)) {
|
|
200
204
|
__normalize(this.app.heartbeat.observe(token));
|
|
201
205
|
}
|
|
@@ -212,10 +216,15 @@ export class Form {
|
|
|
212
216
|
handle(packet) {
|
|
213
217
|
__requireArity(arguments.length, [0], "handle");
|
|
214
218
|
packet = __boundary(packet);
|
|
215
|
-
if (__requireBoolean(__normalize(this.disposed))) {
|
|
219
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.disposed)) || __requireBoolean(__normalize(this.stale)))) {
|
|
216
220
|
return null;
|
|
217
221
|
}
|
|
222
|
+
let previous = __normalize(this.token);
|
|
223
|
+
__normalize(this.app.beginLoginResponse(this, packet));
|
|
218
224
|
this.setToken(__normalize(packet.token));
|
|
225
|
+
if (__requireBoolean(__normalize(this.stale))) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
219
228
|
let body = __normalize(packet.body);
|
|
220
229
|
if (__requireBoolean(__normalize(body.view) !== null)) {
|
|
221
230
|
__normalize(this.app.renderer.show(this, __normalize(body.view)));
|
|
@@ -225,6 +234,8 @@ export class Form {
|
|
|
225
234
|
__normalize(this.app.command(this, cmd));
|
|
226
235
|
}
|
|
227
236
|
}
|
|
237
|
+
__normalize(this.app.completeLogin(this));
|
|
238
|
+
__normalize(this.app.observeAuthentication(this, previous, packet));
|
|
228
239
|
return null;
|
|
229
240
|
return null;
|
|
230
241
|
}
|
|
@@ -253,6 +264,7 @@ export class Form {
|
|
|
253
264
|
return null;
|
|
254
265
|
}
|
|
255
266
|
this.disposed = true;
|
|
267
|
+
__normalize(this.app.loginScopeDisposed(this));
|
|
256
268
|
for (const control of __normalize(this.owned.slice())) {
|
|
257
269
|
__normalize(control.dispose());
|
|
258
270
|
}
|
package/dist/form.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.mjs","sources":["form.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global Promise\nimport \"./activities\"\n class Activities\n\nexport class Form(app, parent = null, token = null)\n properties\n app\n parent\n token\n controls\n owned\n inheritedNames\n disposed\n element\n resources\n activity\n presentation\n inheritThrough\n spinner\n waiting\n methods\n register(name, control)\n unregister(control)\n find(name)\n inherited(name)\n getValue()\n prepareValue()\n setValue(values)\n setToken(token)\n send(url)\n handle(packet)\n related(other)\n clearValidation()\n clearResources()\n dispose()\n\nForm(app, parent = null, token = null)\n @app = app\n @parent = parent\n @token = token\n @controls = Object/create(null)\n @owned = []\n @inheritedNames = []\n @disposed = false\n @element = null\n @resources = []\n @activity = new Activities(@this)\n @presentation = null\n @inheritThrough = false\n @spinner = null\n @waiting = false\n app.forms.add(@this)\n\nForm:register(name, control)\n @owned.add(control)\n if name == null\n return control\n if !is_string(name) or name == \"\" or name.includes(\"/\") or name in @controls\n throw \"Invalid or duplicate control name: ${name}\"\n @controls[name] = control\n return control\n\nForm:unregister(control)\n for Object/keys(@controls) as name\n if @controls[name] == control\n Reflect/deleteProperty(@controls, name)\n index = @owned.indexOf(control)\n if index >= 0\n @owned.splice(index, 1)\n return null\n\nForm:find(name)\n parts = name.split(\"/\")\n current = @controls[parts.shift()]\n if current == null\n if @inheritedNames.includes(name) and @parent != null\n return inherited(name)\n throw \"Unknown control: ${name}\"\n if parts.length > 0\n if current.find == null\n throw \"Control has no named children: ${name}\"\n return current.find(parts.join(\"/\"))\n return current\n\nForm:inherited(name)\n parent = @parent\n loop while parent != null and parent.inheritThrough\n parent = parent.parent\n if parent == null\n throw \"Inherited value has no parent: ${name}\"\n return parent.find(name)\n\nForm:getValue()\n result = Object/create(null)\n for @controls as name: control\n result[name] = control.getValue()\n for @inheritedNames as name\n if @parent == null or name in result\n throw \"Invalid inherited name: ${name}\"\n source = inherited(name)\n result[name] = source.getValue()\n return result\n\nForm:prepareValue()\n pending = []\n for @
|
|
1
|
+
{"version":3,"file":"form.mjs","sources":["form.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global Promise\nimport \"./activities\"\n class Activities\n\nexport class Form(app, parent = null, token = null)\n properties\n app\n parent\n token\n controls\n owned\n inheritedNames\n disposed\n stale\n element\n resources\n activity\n presentation\n inheritThrough\n spinner\n waiting\n methods\n register(name, control)\n unregister(control)\n find(name)\n inherited(name)\n getValue()\n prepareValue()\n setValue(values)\n setToken(token)\n send(url)\n handle(packet)\n related(other)\n clearValidation()\n clearResources()\n dispose()\n\nForm(app, parent = null, token = null)\n @app = app\n @parent = parent\n @token = token\n @controls = Object/create(null)\n @owned = []\n @inheritedNames = []\n @disposed = false\n @stale = false\n @element = null\n @resources = []\n @activity = new Activities(@this)\n @presentation = null\n @inheritThrough = false\n @spinner = null\n @waiting = false\n app.forms.add(@this)\n\nForm:register(name, control)\n @owned.add(control)\n if name == null\n return control\n if !is_string(name) or name == \"\" or name.includes(\"/\") or name in @controls\n throw \"Invalid or duplicate control name: ${name}\"\n @controls[name] = control\n return control\n\nForm:unregister(control)\n for Object/keys(@controls) as name\n if @controls[name] == control\n Reflect/deleteProperty(@controls, name)\n index = @owned.indexOf(control)\n if index >= 0\n @owned.splice(index, 1)\n return null\n\nForm:find(name)\n parts = name.split(\"/\")\n current = @controls[parts.shift()]\n if current == null\n if @inheritedNames.includes(name) and @parent != null\n return inherited(name)\n throw \"Unknown control: ${name}\"\n if parts.length > 0\n if current.find == null\n throw \"Control has no named children: ${name}\"\n return current.find(parts.join(\"/\"))\n return current\n\nForm:inherited(name)\n parent = @parent\n loop while parent != null and parent.inheritThrough\n parent = parent.parent\n if parent == null\n throw \"Inherited value has no parent: ${name}\"\n return parent.find(name)\n\nForm:getValue()\n result = Object/create(null)\n for @controls as name: control\n result[name] = control.getValue()\n for @inheritedNames as name\n if @parent == null or name in result\n throw \"Invalid inherited name: ${name}\"\n source = inherited(name)\n result[name] = source.getValue()\n return result\n\nForm:prepareValue()\n pending = []\n for @owned as control\n if control.prepareValue != null\n ready = control.prepareValue()\n if ready != null\n pending.add(ready)\n for @inheritedNames as name\n source = inherited(name)\n if source.prepareValue != null\n inheritedReady = source.prepareValue()\n if inheritedReady != null\n pending.add(inheritedReady)\n if pending.length == 0\n return null\n return Promise/all(pending)\n\nForm:setValue(values)\n for values as name: value\n find(name).setValue(value)\n return @this\n\nForm:clearValidation()\n for @controls as name: control\n if control.clearValidation != null\n control.clearValidation()\n for @inheritedNames as name\n source = find(name)\n if source.clearValidation != null\n source.clearValidation()\n return null\n\nForm:clearResources()\n @activity.clear()\n resources = @resources\n @resources = []\n for resources as release\n release()\n return null\n\nForm:setToken(token)\n if token != null\n if @app.saveToken(token) == false\n return @this\n @token = token\n if @app.heartbeat != null\n @app.heartbeat.observe(token)\n return @this\n\nForm:send(url)\n return @app.send(@this, url)\n\nForm:handle(packet)\n if @disposed or @stale\n return null\n previous = @token\n @app.beginLoginResponse(@this, packet)\n setToken(packet.token)\n if @stale\n return null\n body = packet.body\n if body.view != null\n @app.renderer.show(@this, body.view)\n if body.cmds != null\n for body.cmds as cmd\n @app.command(@this, cmd)\n @app.completeLogin(@this)\n @app.observeAuthentication(@this, previous, packet)\n return null\n\nForm:related(other)\n node = other\n loop while node != null\n if node == @this\n return true\n node = node.parent\n node = @this\n loop while node != null\n if node == other\n return true\n node = node.parent\n return false\n\nForm:dispose()\n if @disposed\n return null\n @disposed = true\n @app.loginScopeDisposed(@this)\n for @owned.slice() as control\n control.dispose()\n clearResources()\n @controls = Object/create(null)\n alive = []\n for @app.forms as form\n if form != @this\n alive.add(form)\n @app.forms = alive\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/heartbeat.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hostGlobal as __hostGlobal,
|
|
3
|
+
bindContexts as __bindContexts,
|
|
3
4
|
isNumber as __isNumber,
|
|
4
5
|
isString as __isString,
|
|
5
6
|
isBool as __isBool,
|
|
@@ -58,7 +59,7 @@ export class Heartbeat {
|
|
|
58
59
|
live() {
|
|
59
60
|
let result = [];
|
|
60
61
|
for (const form of __normalize(this.#app.forms)) {
|
|
61
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(form.disposed))) && __requireBoolean(__normalize(form.token) !== null)) && __requireBoolean(!__requireBoolean(__normalize(result.includes(__normalize(form.token))))))) {
|
|
62
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(form.disposed))) && __requireBoolean(!__requireBoolean(__normalize(form.stale)))) && __requireBoolean(__normalize(form.token) !== null)) && __requireBoolean(!__requireBoolean(__normalize(result.includes(__normalize(form.token))))))) {
|
|
62
63
|
result.push(__normalize(form.token));
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -119,11 +120,11 @@ export class Heartbeat {
|
|
|
119
120
|
}
|
|
120
121
|
delay = __normalize(__hostGlobal(["Math"]).min(delay, __normalize(__hostGlobal(["Math"]).max(1, __numericAdd(__finite(60000 - current), last)))));
|
|
121
122
|
}
|
|
122
|
-
let action = () => {
|
|
123
|
+
let action = __bindContexts(() => {
|
|
123
124
|
this.#timer = null;
|
|
124
125
|
this.tick();
|
|
125
126
|
return null;
|
|
126
|
-
};
|
|
127
|
+
});
|
|
127
128
|
this.#timer = __normalize(this.#host.schedule(action, delay));
|
|
128
129
|
return null;
|
|
129
130
|
return null;
|
|
@@ -136,16 +137,16 @@ export class Heartbeat {
|
|
|
136
137
|
if (__requireBoolean(__normalize(this.due().length) > 0)) {
|
|
137
138
|
pending = __normalize(this.#app.ping());
|
|
138
139
|
}
|
|
139
|
-
return pending.catch(__withArity((error) => {
|
|
140
|
+
return pending.catch(__withArity(__bindContexts((error) => {
|
|
140
141
|
error = __boundary(error);
|
|
141
142
|
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.#disposed))) && __requireBoolean(__normalize(this.#app.root) !== null))) {
|
|
142
143
|
__normalize(this.#app.error(__normalize(this.#app.root), error, "PingFailed"));
|
|
143
144
|
}
|
|
144
145
|
return null;
|
|
145
|
-
}, [0], "closure")).finally(() => {
|
|
146
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
146
147
|
this.start();
|
|
147
148
|
return null;
|
|
148
|
-
});
|
|
149
|
+
}));
|
|
149
150
|
return null;
|
|
150
151
|
}
|
|
151
152
|
exchange() {
|
|
@@ -164,7 +165,7 @@ export class Heartbeat {
|
|
|
164
165
|
__requireArity(arguments.length, [0, 1], "batch");
|
|
165
166
|
pending = __boundary(pending);
|
|
166
167
|
tokens = __boundary(tokens);
|
|
167
|
-
return pending.then(__withArity((ignored) => {
|
|
168
|
+
return pending.then(__withArity(__bindContexts((ignored) => {
|
|
168
169
|
ignored = __boundary(ignored);
|
|
169
170
|
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
170
171
|
return null;
|
|
@@ -184,16 +185,16 @@ export class Heartbeat {
|
|
|
184
185
|
for (const token of tokens) {
|
|
185
186
|
this.#attempts[token] = current;
|
|
186
187
|
}
|
|
187
|
-
return __normalize(this.#app.post(__normalize(this.#url), { tokens: tokens }, header)).then(__withArity((packet) => {
|
|
188
|
+
return __normalize(this.#app.post(__normalize(this.#url), { tokens: tokens }, header)).then(__withArity(__bindContexts((packet) => {
|
|
188
189
|
packet = __boundary(packet);
|
|
189
190
|
if (__requireBoolean(!__requireBoolean(__normalize(this.#disposed)))) {
|
|
190
191
|
this.apply(tokens, packet.body.tokens);
|
|
191
192
|
}
|
|
192
193
|
return null;
|
|
193
194
|
return null;
|
|
194
|
-
}, [0], "closure"));
|
|
195
|
+
}), [0], "closure"));
|
|
195
196
|
return null;
|
|
196
|
-
}, [0], "closure"));
|
|
197
|
+
}), [0], "closure"));
|
|
197
198
|
return null;
|
|
198
199
|
}
|
|
199
200
|
apply(tokens, results) {
|
|
@@ -218,7 +219,7 @@ export class Heartbeat {
|
|
|
218
219
|
}
|
|
219
220
|
for (const item of results) {
|
|
220
221
|
for (const form of __normalize(this.#app.forms.slice())) {
|
|
221
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(form.disposed))) && __requireBoolean(__normalize(form.token) === __normalize(item.previous)))) {
|
|
222
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(form.disposed))) && __requireBoolean(!__requireBoolean(__normalize(form.stale)))) && __requireBoolean(__normalize(form.token) === __normalize(item.previous)))) {
|
|
222
223
|
if (__requireBoolean(__normalize(item.status) === 200)) {
|
|
223
224
|
__normalize(form.setToken(__normalize(item.token)));
|
|
224
225
|
} else {
|
package/dist/heartbeat.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.mjs","sources":["heartbeat.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global Date\nimport js global Math\nimport js global Promise\n\nexport class Heartbeat(app, host, url)\n methods\n now()\n observe(token)\n live()\n due()\n start()\n tick()\n exchange()\n batch(pending, tokens)\n apply(tokens, results)\n dispose()\n\nHeartbeat(app, host, url)\n @app = app\n @host = host\n @url = url\n @times = Object/create(null)\n @attempts = Object/create(null)\n @timer = null\n @disposed = false\n @started = false\n\nHeartbeat:now()\n if @host.now != null\n return @host.now()\n return Date/now()\n\nHeartbeat:observe(token)\n @times[token] = now()\n if @started\n start()\n return null\n\nHeartbeat:live()\n result = []\n for @app.forms as form\n if !form.disposed and form.token != null and !result.includes(form.token)\n result.add(form.token)\n return result\n\nHeartbeat:due()\n current = now()\n tokens = live()\n for Object/keys(@times) as token\n if !tokens.includes(token)\n Reflect/deleteProperty(@times, token)\n Reflect/deleteProperty(@attempts, token)\n result = []\n for tokens as token\n if !(token in @times)\n @times[token] = current\n last = @times[token]\n if token in @attempts\n if @attempts[token] > last\n last = @attempts[token]\n if current - last >= 60000\n result.add(token)\n return result\n\nHeartbeat:start()\n @started = true\n if @disposed or @host.schedule == null\n return null\n if @timer != null\n @host.cancelTimer(@timer)\n @timer = null\n current = now()\n tokens = live()\n if tokens.length == 0\n return null\n delay = 60000\n for tokens as token\n if !(token in @times)\n @times[token] = current\n last = @times[token]\n if token in @attempts\n if @attempts[token] > last\n last = @attempts[token]\n delay = Math/min(delay, Math/max(1, 60000 - current + last))\n action = ()\n @timer = null\n tick()\n @timer = @host.schedule(action, delay)\n return null\n\nHeartbeat:tick()\n if @disposed\n return Promise/resolve(null)\n pending = Promise/resolve(null)\n if due().length > 0\n pending = @app.ping()\n return chain pending\n catch(error)\n if !@disposed and @app.root != null\n @app.error(@app.root, error, \"PingFailed\")\n finally\n start()\n\nHeartbeat:exchange()\n if @disposed\n return Promise/resolve(null)\n tokens = due()\n pending = Promise/resolve(null)\n loop while tokens.length > 0\n pending = batch(pending, tokens.splice(0, 64))\n return pending\n\nHeartbeat:batch(pending, tokens)\n return chain pending\n then(ignored)\n capture tokens\n if @disposed\n return null\n header = null\n newest = -1\n for live() as token\n if @times[token] > newest\n header = token\n newest = @times[token]\n if header == null\n return null\n current = now()\n for tokens as token\n @attempts[token] = current\n return chain @app.post(@url, {\n tokens: tokens\n }, header)\n then(packet)\n capture tokens\n if !@disposed\n apply(tokens, packet.body.tokens)\n return null\n\nHeartbeat:apply(tokens, results)\n if !is_array(results) or results.length != tokens.length\n throw \"Invalid Ping response\"\n seen = []\n for results as item\n if !is_object(item) or !tokens.includes(item.previous) or seen.includes(item.previous)\n throw \"Invalid Ping response\"\n if !is_number(item.status) or item.status < 200 or item.status > 599\n throw \"Invalid Ping status\"\n if item.status == 200 and (!is_string(item.token) or item.token == \"\")\n throw \"Invalid Ping token\"\n seen.add(item.previous)\n for results as item\n for @app.forms.slice() as form\n if !form.disposed and form.token == item.previous\n if item.status == 200\n form.setToken(item.token)\n else\n @app.error(form, \"HTTP ${item.status}\", \"PingRejected\")\n return null\n\nHeartbeat:dispose()\n @disposed = true\n if @timer != null\n @host.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"heartbeat.mjs","sources":["heartbeat.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global Date\nimport js global Math\nimport js global Promise\n\nexport class Heartbeat(app, host, url)\n methods\n now()\n observe(token)\n live()\n due()\n start()\n tick()\n exchange()\n batch(pending, tokens)\n apply(tokens, results)\n dispose()\n\nHeartbeat(app, host, url)\n @app = app\n @host = host\n @url = url\n @times = Object/create(null)\n @attempts = Object/create(null)\n @timer = null\n @disposed = false\n @started = false\n\nHeartbeat:now()\n if @host.now != null\n return @host.now()\n return Date/now()\n\nHeartbeat:observe(token)\n @times[token] = now()\n if @started\n start()\n return null\n\nHeartbeat:live()\n result = []\n for @app.forms as form\n if !form.disposed and !form.stale and form.token != null and !result.includes(form.token)\n result.add(form.token)\n return result\n\nHeartbeat:due()\n current = now()\n tokens = live()\n for Object/keys(@times) as token\n if !tokens.includes(token)\n Reflect/deleteProperty(@times, token)\n Reflect/deleteProperty(@attempts, token)\n result = []\n for tokens as token\n if !(token in @times)\n @times[token] = current\n last = @times[token]\n if token in @attempts\n if @attempts[token] > last\n last = @attempts[token]\n if current - last >= 60000\n result.add(token)\n return result\n\nHeartbeat:start()\n @started = true\n if @disposed or @host.schedule == null\n return null\n if @timer != null\n @host.cancelTimer(@timer)\n @timer = null\n current = now()\n tokens = live()\n if tokens.length == 0\n return null\n delay = 60000\n for tokens as token\n if !(token in @times)\n @times[token] = current\n last = @times[token]\n if token in @attempts\n if @attempts[token] > last\n last = @attempts[token]\n delay = Math/min(delay, Math/max(1, 60000 - current + last))\n action = ()\n @timer = null\n tick()\n @timer = @host.schedule(action, delay)\n return null\n\nHeartbeat:tick()\n if @disposed\n return Promise/resolve(null)\n pending = Promise/resolve(null)\n if due().length > 0\n pending = @app.ping()\n return chain pending\n catch(error)\n if !@disposed and @app.root != null\n @app.error(@app.root, error, \"PingFailed\")\n finally\n start()\n\nHeartbeat:exchange()\n if @disposed\n return Promise/resolve(null)\n tokens = due()\n pending = Promise/resolve(null)\n loop while tokens.length > 0\n pending = batch(pending, tokens.splice(0, 64))\n return pending\n\nHeartbeat:batch(pending, tokens)\n return chain pending\n then(ignored)\n capture tokens\n if @disposed\n return null\n header = null\n newest = -1\n for live() as token\n if @times[token] > newest\n header = token\n newest = @times[token]\n if header == null\n return null\n current = now()\n for tokens as token\n @attempts[token] = current\n return chain @app.post(@url, {\n tokens: tokens\n }, header)\n then(packet)\n capture tokens\n if !@disposed\n apply(tokens, packet.body.tokens)\n return null\n\nHeartbeat:apply(tokens, results)\n if !is_array(results) or results.length != tokens.length\n throw \"Invalid Ping response\"\n seen = []\n for results as item\n if !is_object(item) or !tokens.includes(item.previous) or seen.includes(item.previous)\n throw \"Invalid Ping response\"\n if !is_number(item.status) or item.status < 200 or item.status > 599\n throw \"Invalid Ping status\"\n if item.status == 200 and (!is_string(item.token) or item.token == \"\")\n throw \"Invalid Ping token\"\n seen.add(item.previous)\n for results as item\n for @app.forms.slice() as form\n if !form.disposed and !form.stale and form.token == item.previous\n if item.status == 200\n form.setToken(item.token)\n else\n @app.error(form, \"HTTP ${item.status}\", \"PingRejected\")\n return null\n\nHeartbeat:dispose()\n @disposed = true\n if @timer != null\n @host.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|