@atscript/ui-fns 0.1.150 → 0.1.151
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/dist/index.cjs +128 -6
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +128 -7
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,124 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _atscript_ui = require("@atscript/ui");
|
|
3
3
|
//#region src/runtime/fn-compiler.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The hidden globals as one frozen object every call's sandbox inherits
|
|
6
|
+
* from. A call then copies only its own few scope keys instead of all ~80
|
|
7
|
+
* hidden names, while name resolution inside `with` is unchanged: scope keys,
|
|
8
|
+
* then the hidden globals (`null`), then `Object.prototype`, then the real
|
|
9
|
+
* globals. Both levels are frozen, so assigning any sandbox name still fails
|
|
10
|
+
* silently.
|
|
11
|
+
*/
|
|
12
|
+
const HIDDEN = Object.freeze(Object.fromEntries([
|
|
13
|
+
"global",
|
|
14
|
+
"process",
|
|
15
|
+
"Buffer",
|
|
16
|
+
"require",
|
|
17
|
+
"__filename",
|
|
18
|
+
"__dirname",
|
|
19
|
+
"exports",
|
|
20
|
+
"module",
|
|
21
|
+
"setImmediate",
|
|
22
|
+
"clearImmediate",
|
|
23
|
+
"setTimeout",
|
|
24
|
+
"clearTimeout",
|
|
25
|
+
"setInterval",
|
|
26
|
+
"clearInterval",
|
|
27
|
+
"queueMicrotask",
|
|
28
|
+
"queueGlobalMicrotask",
|
|
29
|
+
"globalThis",
|
|
30
|
+
"window",
|
|
31
|
+
"self",
|
|
32
|
+
"document",
|
|
33
|
+
"localStorage",
|
|
34
|
+
"sessionStorage",
|
|
35
|
+
"indexedDB",
|
|
36
|
+
"caches",
|
|
37
|
+
"console",
|
|
38
|
+
"performance",
|
|
39
|
+
"fetch",
|
|
40
|
+
"XMLHttpRequest",
|
|
41
|
+
"Image",
|
|
42
|
+
"Audio",
|
|
43
|
+
"navigator",
|
|
44
|
+
"navigation",
|
|
45
|
+
"location",
|
|
46
|
+
"history",
|
|
47
|
+
"screen",
|
|
48
|
+
"requestAnimationFrame",
|
|
49
|
+
"cancelAnimationFrame",
|
|
50
|
+
"cancelIdleCallback",
|
|
51
|
+
"captureEvents",
|
|
52
|
+
"chrome",
|
|
53
|
+
"clientInformation",
|
|
54
|
+
"addEventListener",
|
|
55
|
+
"removeEventListener",
|
|
56
|
+
"blur",
|
|
57
|
+
"close",
|
|
58
|
+
"closed",
|
|
59
|
+
"confirm",
|
|
60
|
+
"alert",
|
|
61
|
+
"customElements",
|
|
62
|
+
"dispatchEvent",
|
|
63
|
+
"debug",
|
|
64
|
+
"focus",
|
|
65
|
+
"find",
|
|
66
|
+
"frames",
|
|
67
|
+
"getSelection",
|
|
68
|
+
"getScreenDetails",
|
|
69
|
+
"getEventListeners",
|
|
70
|
+
"keys",
|
|
71
|
+
"launchQueue",
|
|
72
|
+
"parent",
|
|
73
|
+
"postMessage",
|
|
74
|
+
"print",
|
|
75
|
+
"profile",
|
|
76
|
+
"profileEnd",
|
|
77
|
+
"prompt",
|
|
78
|
+
"queryLocalFonts",
|
|
79
|
+
"queryObjects",
|
|
80
|
+
"releaseEvents",
|
|
81
|
+
"reportError",
|
|
82
|
+
"resizeBy",
|
|
83
|
+
"resizeTo",
|
|
84
|
+
"scheduler",
|
|
85
|
+
"stop",
|
|
86
|
+
"scroll",
|
|
87
|
+
"scrollBy",
|
|
88
|
+
"scrollTo",
|
|
89
|
+
"scrollY",
|
|
90
|
+
"scrollX",
|
|
91
|
+
"top",
|
|
92
|
+
"eval",
|
|
93
|
+
"__ctx__"
|
|
94
|
+
].map((name) => [name, null])));
|
|
95
|
+
/**
|
|
96
|
+
* The per-call sandbox: the scope's own keys on an object inheriting
|
|
97
|
+
* {@link HIDDEN}, frozen. A scope key that shadows a hidden (or inherited)
|
|
98
|
+
* name is defined rather than assigned — assignment would hit the frozen
|
|
99
|
+
* inherited property and throw.
|
|
100
|
+
*/
|
|
101
|
+
function sandbox(scope) {
|
|
102
|
+
const box = Object.create(HIDDEN);
|
|
103
|
+
const src = scope;
|
|
104
|
+
for (const key of Object.keys(src)) if (key in box) Object.defineProperty(box, key, {
|
|
105
|
+
value: src[key],
|
|
106
|
+
enumerable: true,
|
|
107
|
+
writable: true,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
110
|
+
else box[key] = src[key];
|
|
111
|
+
return Object.freeze(box);
|
|
112
|
+
}
|
|
113
|
+
function compileSandboxed(code) {
|
|
114
|
+
const body = new Function("__ctx__", `with(__ctx__){\n${code}\n}`);
|
|
115
|
+
return (scope) => body(sandbox(scope));
|
|
116
|
+
}
|
|
117
|
+
const fieldFns = /* @__PURE__ */ new Map();
|
|
118
|
+
const topFns = /* @__PURE__ */ new Map();
|
|
5
119
|
/**
|
|
6
120
|
* Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
|
|
7
|
-
* into a callable function.
|
|
121
|
+
* into a callable function. Compiled once per string and cached.
|
|
8
122
|
*
|
|
9
123
|
* The function string should be an arrow or regular function expression:
|
|
10
124
|
* `"(v, data, ctx, entry) => !data.firstName"`
|
|
@@ -13,8 +127,12 @@ const pool = new (require("@prostojs/deserialize-fn")).FNPool();
|
|
|
13
127
|
* `{ v, data, context, entry }`
|
|
14
128
|
*/
|
|
15
129
|
function compileFieldFn(fnStr) {
|
|
16
|
-
|
|
17
|
-
|
|
130
|
+
let fn = fieldFns.get(fnStr);
|
|
131
|
+
if (!fn) {
|
|
132
|
+
fn = compileSandboxed(`return (${fnStr})(v, data, context, entry)`);
|
|
133
|
+
fieldFns.set(fnStr, fn);
|
|
134
|
+
}
|
|
135
|
+
return fn;
|
|
18
136
|
}
|
|
19
137
|
/**
|
|
20
138
|
* Compiles a form-level function string from a `@ui.form.fn.title` or similar annotation.
|
|
@@ -26,8 +144,12 @@ function compileFieldFn(fnStr) {
|
|
|
26
144
|
* `{ data, context }`
|
|
27
145
|
*/
|
|
28
146
|
function compileTopFn(fnStr) {
|
|
29
|
-
|
|
30
|
-
|
|
147
|
+
let fn = topFns.get(fnStr);
|
|
148
|
+
if (!fn) {
|
|
149
|
+
fn = compileSandboxed(`return (${fnStr})(data, context)`);
|
|
150
|
+
topFns.set(fnStr, fn);
|
|
151
|
+
}
|
|
152
|
+
return fn;
|
|
31
153
|
}
|
|
32
154
|
/**
|
|
33
155
|
* Compiles a validator function string.
|
package/dist/index.d.cts
CHANGED
|
@@ -37,7 +37,7 @@ interface TFieldEvaluated {
|
|
|
37
37
|
//#region src/runtime/fn-compiler.d.ts
|
|
38
38
|
/**
|
|
39
39
|
* Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
|
|
40
|
-
* into a callable function.
|
|
40
|
+
* into a callable function. Compiled once per string and cached.
|
|
41
41
|
*
|
|
42
42
|
* The function string should be an arrow or regular function expression:
|
|
43
43
|
* `"(v, data, ctx, entry) => !data.firstName"`
|
package/dist/index.d.mts
CHANGED
|
@@ -37,7 +37,7 @@ interface TFieldEvaluated {
|
|
|
37
37
|
//#region src/runtime/fn-compiler.d.ts
|
|
38
38
|
/**
|
|
39
39
|
* Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
|
|
40
|
-
* into a callable function.
|
|
40
|
+
* into a callable function. Compiled once per string and cached.
|
|
41
41
|
*
|
|
42
42
|
* The function string should be an arrow or regular function expression:
|
|
43
43
|
* `"(v, data, ctx, entry) => !data.firstName"`
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,123 @@
|
|
|
1
1
|
import { META_READONLY, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_HIDDEN, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_TABLE_FN_ATTR, UI_TABLE_FN_PREFIX, UI_TYPE, asArray, getFieldMeta, resolveFieldProp, resolveOptions, resolveStatic, setDefaultValidatorPlugins, setResolver } from "@atscript/ui";
|
|
2
|
-
import { FNPool } from "@prostojs/deserialize-fn";
|
|
3
2
|
//#region src/runtime/fn-compiler.ts
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The hidden globals as one frozen object every call's sandbox inherits
|
|
5
|
+
* from. A call then copies only its own few scope keys instead of all ~80
|
|
6
|
+
* hidden names, while name resolution inside `with` is unchanged: scope keys,
|
|
7
|
+
* then the hidden globals (`null`), then `Object.prototype`, then the real
|
|
8
|
+
* globals. Both levels are frozen, so assigning any sandbox name still fails
|
|
9
|
+
* silently.
|
|
10
|
+
*/
|
|
11
|
+
const HIDDEN = Object.freeze(Object.fromEntries([
|
|
12
|
+
"global",
|
|
13
|
+
"process",
|
|
14
|
+
"Buffer",
|
|
15
|
+
"require",
|
|
16
|
+
"__filename",
|
|
17
|
+
"__dirname",
|
|
18
|
+
"exports",
|
|
19
|
+
"module",
|
|
20
|
+
"setImmediate",
|
|
21
|
+
"clearImmediate",
|
|
22
|
+
"setTimeout",
|
|
23
|
+
"clearTimeout",
|
|
24
|
+
"setInterval",
|
|
25
|
+
"clearInterval",
|
|
26
|
+
"queueMicrotask",
|
|
27
|
+
"queueGlobalMicrotask",
|
|
28
|
+
"globalThis",
|
|
29
|
+
"window",
|
|
30
|
+
"self",
|
|
31
|
+
"document",
|
|
32
|
+
"localStorage",
|
|
33
|
+
"sessionStorage",
|
|
34
|
+
"indexedDB",
|
|
35
|
+
"caches",
|
|
36
|
+
"console",
|
|
37
|
+
"performance",
|
|
38
|
+
"fetch",
|
|
39
|
+
"XMLHttpRequest",
|
|
40
|
+
"Image",
|
|
41
|
+
"Audio",
|
|
42
|
+
"navigator",
|
|
43
|
+
"navigation",
|
|
44
|
+
"location",
|
|
45
|
+
"history",
|
|
46
|
+
"screen",
|
|
47
|
+
"requestAnimationFrame",
|
|
48
|
+
"cancelAnimationFrame",
|
|
49
|
+
"cancelIdleCallback",
|
|
50
|
+
"captureEvents",
|
|
51
|
+
"chrome",
|
|
52
|
+
"clientInformation",
|
|
53
|
+
"addEventListener",
|
|
54
|
+
"removeEventListener",
|
|
55
|
+
"blur",
|
|
56
|
+
"close",
|
|
57
|
+
"closed",
|
|
58
|
+
"confirm",
|
|
59
|
+
"alert",
|
|
60
|
+
"customElements",
|
|
61
|
+
"dispatchEvent",
|
|
62
|
+
"debug",
|
|
63
|
+
"focus",
|
|
64
|
+
"find",
|
|
65
|
+
"frames",
|
|
66
|
+
"getSelection",
|
|
67
|
+
"getScreenDetails",
|
|
68
|
+
"getEventListeners",
|
|
69
|
+
"keys",
|
|
70
|
+
"launchQueue",
|
|
71
|
+
"parent",
|
|
72
|
+
"postMessage",
|
|
73
|
+
"print",
|
|
74
|
+
"profile",
|
|
75
|
+
"profileEnd",
|
|
76
|
+
"prompt",
|
|
77
|
+
"queryLocalFonts",
|
|
78
|
+
"queryObjects",
|
|
79
|
+
"releaseEvents",
|
|
80
|
+
"reportError",
|
|
81
|
+
"resizeBy",
|
|
82
|
+
"resizeTo",
|
|
83
|
+
"scheduler",
|
|
84
|
+
"stop",
|
|
85
|
+
"scroll",
|
|
86
|
+
"scrollBy",
|
|
87
|
+
"scrollTo",
|
|
88
|
+
"scrollY",
|
|
89
|
+
"scrollX",
|
|
90
|
+
"top",
|
|
91
|
+
"eval",
|
|
92
|
+
"__ctx__"
|
|
93
|
+
].map((name) => [name, null])));
|
|
94
|
+
/**
|
|
95
|
+
* The per-call sandbox: the scope's own keys on an object inheriting
|
|
96
|
+
* {@link HIDDEN}, frozen. A scope key that shadows a hidden (or inherited)
|
|
97
|
+
* name is defined rather than assigned — assignment would hit the frozen
|
|
98
|
+
* inherited property and throw.
|
|
99
|
+
*/
|
|
100
|
+
function sandbox(scope) {
|
|
101
|
+
const box = Object.create(HIDDEN);
|
|
102
|
+
const src = scope;
|
|
103
|
+
for (const key of Object.keys(src)) if (key in box) Object.defineProperty(box, key, {
|
|
104
|
+
value: src[key],
|
|
105
|
+
enumerable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
configurable: true
|
|
108
|
+
});
|
|
109
|
+
else box[key] = src[key];
|
|
110
|
+
return Object.freeze(box);
|
|
111
|
+
}
|
|
112
|
+
function compileSandboxed(code) {
|
|
113
|
+
const body = new Function("__ctx__", `with(__ctx__){\n${code}\n}`);
|
|
114
|
+
return (scope) => body(sandbox(scope));
|
|
115
|
+
}
|
|
116
|
+
const fieldFns = /* @__PURE__ */ new Map();
|
|
117
|
+
const topFns = /* @__PURE__ */ new Map();
|
|
5
118
|
/**
|
|
6
119
|
* Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
|
|
7
|
-
* into a callable function.
|
|
120
|
+
* into a callable function. Compiled once per string and cached.
|
|
8
121
|
*
|
|
9
122
|
* The function string should be an arrow or regular function expression:
|
|
10
123
|
* `"(v, data, ctx, entry) => !data.firstName"`
|
|
@@ -13,8 +126,12 @@ const pool = new FNPool();
|
|
|
13
126
|
* `{ v, data, context, entry }`
|
|
14
127
|
*/
|
|
15
128
|
function compileFieldFn(fnStr) {
|
|
16
|
-
|
|
17
|
-
|
|
129
|
+
let fn = fieldFns.get(fnStr);
|
|
130
|
+
if (!fn) {
|
|
131
|
+
fn = compileSandboxed(`return (${fnStr})(v, data, context, entry)`);
|
|
132
|
+
fieldFns.set(fnStr, fn);
|
|
133
|
+
}
|
|
134
|
+
return fn;
|
|
18
135
|
}
|
|
19
136
|
/**
|
|
20
137
|
* Compiles a form-level function string from a `@ui.form.fn.title` or similar annotation.
|
|
@@ -26,8 +143,12 @@ function compileFieldFn(fnStr) {
|
|
|
26
143
|
* `{ data, context }`
|
|
27
144
|
*/
|
|
28
145
|
function compileTopFn(fnStr) {
|
|
29
|
-
|
|
30
|
-
|
|
146
|
+
let fn = topFns.get(fnStr);
|
|
147
|
+
if (!fn) {
|
|
148
|
+
fn = compileSandboxed(`return (${fnStr})(data, context)`);
|
|
149
|
+
topFns.set(fnStr, fn);
|
|
150
|
+
}
|
|
151
|
+
return fn;
|
|
31
152
|
}
|
|
32
153
|
/**
|
|
33
154
|
* Compiles a validator function string.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui-fns",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.151",
|
|
4
4
|
"description": "Dynamic fn-compiled field properties for @atscript/ui (opt-in, uses new Function)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@atscript/ui": "^0.1.150"
|
|
50
|
+
"@atscript/ui": "^0.1.151"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
|
-
"@atscript/core": "^0.1.
|
|
55
|
-
"@atscript/typescript": "^0.1.
|
|
53
|
+
"@atscript/core": "^0.1.102",
|
|
54
|
+
"@atscript/typescript": "^0.1.102",
|
|
55
|
+
"@prostojs/deserialize-fn": "^0.0.5",
|
|
56
56
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@atscript/core": "^0.1.
|
|
60
|
-
"@atscript/typescript": "^0.1.
|
|
59
|
+
"@atscript/core": "^0.1.102",
|
|
60
|
+
"@atscript/typescript": "^0.1.102"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "vp pack",
|