@adecore/intelligent-ui 0.25.5 → 0.25.7
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/catalog.d.ts +3 -0
- package/dist/catalog.js +2 -1
- package/dist/compiler.js +10 -5
- package/dist/prop-alias.d.ts +1 -0
- package/dist/prop-alias.js +6 -0
- package/dist/syntax.js +1 -1
- package/package.json +1 -1
- package/src/catalog.ts +2 -1
- package/src/compiler.ts +15 -5
- package/src/prop-alias.ts +6 -0
- package/src/syntax.ts +1 -1
package/dist/catalog.d.ts
CHANGED
package/dist/catalog.js
CHANGED
|
@@ -59,7 +59,8 @@ export const UI_CATALOG = {
|
|
|
59
59
|
detail: text.optional()
|
|
60
60
|
}),
|
|
61
61
|
parent: 'Timeline',
|
|
62
|
-
text: 'title'
|
|
62
|
+
text: 'title',
|
|
63
|
+
aliases: { time: 'at' }
|
|
63
64
|
},
|
|
64
65
|
Stats: { group: 'data', description: 'A small set of key numbers.', schema: empty, children: ['Stat'] },
|
|
65
66
|
Stat: {
|
package/dist/compiler.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isUiComponent, UI_CATALOG, UI_CATALOG_VERSION } from './catalog.js';
|
|
|
3
3
|
import { uiActionProp, uiActionTarget, uiLocalState } from './actions.js';
|
|
4
4
|
import { unreadableEventTime } from './event-warning.js';
|
|
5
5
|
import { uiNodeFallback, uiPlainText } from './fallback.js';
|
|
6
|
+
import { aliasedProp } from './prop-alias.js';
|
|
6
7
|
import { evaluateUiExpression, sameUiValue } from './expression.js';
|
|
7
8
|
import { parseUiSyntax, uiDiagnostic } from './syntax.js';
|
|
8
9
|
import {} from 'zod';
|
|
@@ -193,16 +194,20 @@ export function compileUiBlock(source, options) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
const actionProp = uiActionProp(syntax.type);
|
|
196
|
-
for (const [
|
|
197
|
-
safeKey(
|
|
198
|
-
if (
|
|
199
|
-
node.expressions[
|
|
197
|
+
for (const [written, expression] of Object.entries(syntax.props)) {
|
|
198
|
+
safeKey(written);
|
|
199
|
+
if (written === actionProp) {
|
|
200
|
+
node.expressions[written] = checkedAction(expression);
|
|
200
201
|
continue;
|
|
201
202
|
}
|
|
203
|
+
const key = aliasedProp(entry, written, syntax.props);
|
|
202
204
|
if (!Object.hasOwn(entry.schema.shape, key)) {
|
|
203
|
-
diagnose(new UiFailure('refused_prop', `${syntax.type} does not accept ${
|
|
205
|
+
diagnose(new UiFailure('refused_prop', `${syntax.type} does not accept ${written}.`), syntax.start, syntax.end, syntax.id);
|
|
204
206
|
continue;
|
|
205
207
|
}
|
|
208
|
+
if (key !== written && syntax.complete) {
|
|
209
|
+
diagnose(new UiFailure('renamed_prop', `${syntax.type} takes ${key}, not ${written}; read as ${key}.`), syntax.start, syntax.end, syntax.id);
|
|
210
|
+
}
|
|
206
211
|
if (isConstant(expression)) {
|
|
207
212
|
node.props[key] = evaluateUiExpression(expression, {}, budget);
|
|
208
213
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function aliasedProp(entry: object, written: string, props: Readonly<Record<string, unknown>>): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* The prop a written one stands for: its alias in the catalog, unless the real prop is written too, which then wins. */
|
|
2
|
+
export function aliasedProp(entry, written, props) {
|
|
3
|
+
const aliases = 'aliases' in entry ? entry.aliases : {};
|
|
4
|
+
const target = Object.hasOwn(aliases, written) ? aliases[written] : undefined;
|
|
5
|
+
return target === undefined || Object.hasOwn(props, target) ? written : target;
|
|
6
|
+
}
|
package/dist/syntax.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { safeKey, UiBudget, UiFailure } from './budget.js';
|
|
2
2
|
import { parseUiExpression } from './expression.js';
|
|
3
|
-
const WARNING_CODES = new Set(['refused_prop', 'too_many_series', 'too_many_children', 'unreadable_time']);
|
|
3
|
+
const WARNING_CODES = new Set(['refused_prop', 'renamed_prop', 'too_many_series', 'too_many_children', 'unreadable_time']);
|
|
4
4
|
export function uiDiagnostic(error, start, end, nodeId) {
|
|
5
5
|
const code = error instanceof UiFailure ? error.code : 'invalid_syntax';
|
|
6
6
|
return {
|
package/package.json
CHANGED
package/src/catalog.ts
CHANGED
|
@@ -65,7 +65,8 @@ export const UI_CATALOG = {
|
|
|
65
65
|
detail: text.optional()
|
|
66
66
|
}),
|
|
67
67
|
parent: 'Timeline',
|
|
68
|
-
text: 'title'
|
|
68
|
+
text: 'title',
|
|
69
|
+
aliases: { time: 'at' }
|
|
69
70
|
},
|
|
70
71
|
Stats: { group: 'data', description: 'A small set of key numbers.', schema: empty, children: ['Stat'] },
|
|
71
72
|
Stat: {
|
package/src/compiler.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { isUiComponent, UI_CATALOG, UI_CATALOG_VERSION } from './catalog.ts';
|
|
|
3
3
|
import { uiActionProp, uiActionTarget, uiLocalState } from './actions.ts';
|
|
4
4
|
import { unreadableEventTime } from './event-warning.ts';
|
|
5
5
|
import { uiNodeFallback, uiPlainText } from './fallback.ts';
|
|
6
|
+
import { aliasedProp } from './prop-alias.ts';
|
|
6
7
|
import { evaluateUiExpression, sameUiValue, type UiExpression, type UiValue } from './expression.ts';
|
|
7
8
|
import { parseUiSyntax, uiDiagnostic, type UiDiagnostic, type UiSyntaxNode } from './syntax.ts';
|
|
8
9
|
import { type z } from 'zod';
|
|
@@ -266,16 +267,25 @@ export function compileUiBlock(source: string, options: UiCompileOptions): UiBlo
|
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
const actionProp = uiActionProp(syntax.type);
|
|
269
|
-
for (const [
|
|
270
|
-
safeKey(
|
|
271
|
-
if (
|
|
272
|
-
node.expressions[
|
|
270
|
+
for (const [written, expression] of Object.entries(syntax.props)) {
|
|
271
|
+
safeKey(written);
|
|
272
|
+
if (written === actionProp) {
|
|
273
|
+
node.expressions[written] = checkedAction(expression);
|
|
273
274
|
continue;
|
|
274
275
|
}
|
|
276
|
+
const key = aliasedProp(entry, written, syntax.props);
|
|
275
277
|
if (!Object.hasOwn(entry.schema.shape, key)) {
|
|
276
|
-
diagnose(new UiFailure('refused_prop', `${syntax.type} does not accept ${
|
|
278
|
+
diagnose(new UiFailure('refused_prop', `${syntax.type} does not accept ${written}.`), syntax.start, syntax.end, syntax.id);
|
|
277
279
|
continue;
|
|
278
280
|
}
|
|
281
|
+
if (key !== written && syntax.complete) {
|
|
282
|
+
diagnose(
|
|
283
|
+
new UiFailure('renamed_prop', `${syntax.type} takes ${key}, not ${written}; read as ${key}.`),
|
|
284
|
+
syntax.start,
|
|
285
|
+
syntax.end,
|
|
286
|
+
syntax.id
|
|
287
|
+
);
|
|
288
|
+
}
|
|
279
289
|
if (isConstant(expression)) {
|
|
280
290
|
node.props[key] = evaluateUiExpression(expression, {}, budget);
|
|
281
291
|
} else {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* The prop a written one stands for: its alias in the catalog, unless the real prop is written too, which then wins. */
|
|
2
|
+
export function aliasedProp(entry: object, written: string, props: Readonly<Record<string, unknown>>): string {
|
|
3
|
+
const aliases = 'aliases' in entry ? (entry.aliases as Readonly<Record<string, string>>) : {};
|
|
4
|
+
const target = Object.hasOwn(aliases, written) ? aliases[written] : undefined;
|
|
5
|
+
return target === undefined || Object.hasOwn(props, target) ? written : target;
|
|
6
|
+
}
|
package/src/syntax.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface UiSyntax {
|
|
|
31
31
|
diagnostics: UiDiagnostic[];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const WARNING_CODES = new Set(['refused_prop', 'too_many_series', 'too_many_children', 'unreadable_time']);
|
|
34
|
+
const WARNING_CODES = new Set(['refused_prop', 'renamed_prop', 'too_many_series', 'too_many_children', 'unreadable_time']);
|
|
35
35
|
|
|
36
36
|
export function uiDiagnostic(error: unknown, start: number, end: number, nodeId?: string): UiDiagnostic {
|
|
37
37
|
const code = error instanceof UiFailure ? error.code : 'invalid_syntax';
|