@rangular-framework/compiler 1.0.3 → 1.1.0
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.
|
@@ -156,7 +156,7 @@ function renderCatalogMarkdown(catalog) {
|
|
|
156
156
|
lines.push('');
|
|
157
157
|
lines.push('## Primitives and their props');
|
|
158
158
|
lines.push('');
|
|
159
|
-
lines.push('Props are parsed from `packages/ui/src/primitives.tsx`; the primitives are shipped source typed `any`, so every prop type is `any
|
|
159
|
+
lines.push('Props are parsed from `packages/ui/src/primitives.tsx`; the primitives are shipped source typed `any`, so every prop type is listed as `any`.');
|
|
160
160
|
lines.push('');
|
|
161
161
|
for (const p of catalog.primitives) {
|
|
162
162
|
lines.push(`### ${p.name}`);
|
|
@@ -14,6 +14,7 @@ exports.generateComponent = generateComponent;
|
|
|
14
14
|
const icons_1 = require("../../../ui/src/icons");
|
|
15
15
|
const datetime_1 = require("../../../ui/src/datetime");
|
|
16
16
|
const chart_1 = require("../../../ui/src/chart");
|
|
17
|
+
const tokens_1 = require("../../../ui/src/tokens");
|
|
17
18
|
const parseDirective_1 = require("../class/parseDirective");
|
|
18
19
|
const formInit_1 = require("../class/formInit");
|
|
19
20
|
const diagnostics_1 = require("../diagnostics");
|
|
@@ -2670,6 +2671,25 @@ class Generator {
|
|
|
2670
2671
|
diagnostics.push((0, diagnostics_1.error)('GEN_SWITCH_COLOR', `<switch> color '${color}' is not a switch colour role; the switch keeps the primary colour`, el.pos.line, el.pos.column, 'Use color="primary" (the default), or color="success" for a green on state'));
|
|
2671
2672
|
}
|
|
2672
2673
|
}
|
|
2674
|
+
// A gradient's custom stops (from, via, to) are hex colours or
|
|
2675
|
+
// colour role names; anything else is a GEN_GRADIENT_STOP error
|
|
2676
|
+
// and the stop is dropped, so the theme stop takes its place.
|
|
2677
|
+
// Bound stops ([from] and friends) pass through and resolve at
|
|
2678
|
+
// runtime against the theme, the [color] binding rule.
|
|
2679
|
+
const dropStops = new Set();
|
|
2680
|
+
if (el.tag.toLowerCase() === 'gradient') {
|
|
2681
|
+
for (const stopName of ['from', 'via', 'to']) {
|
|
2682
|
+
const stopValue = el.attrs[stopName];
|
|
2683
|
+
if (stopValue === undefined)
|
|
2684
|
+
continue;
|
|
2685
|
+
const isHex = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(stopValue);
|
|
2686
|
+
const isRole = Object.prototype.hasOwnProperty.call(tokens_1.colours.light, stopValue);
|
|
2687
|
+
if (!isHex && !isRole) {
|
|
2688
|
+
diagnostics.push((0, diagnostics_1.error)('GEN_GRADIENT_STOP', `<gradient> ${stopName} '${stopValue}' is not a hex colour or a colour role; the stop was dropped and the theme gradient stop is used`, el.pos.line, el.pos.column, 'Write the stop as a hex colour (from="#fbcfe8") or a colour role name (via="accent")'));
|
|
2689
|
+
dropStops.add(stopName);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2673
2693
|
for (const [name, value] of Object.entries(el.attrs)) {
|
|
2674
2694
|
if (name === 'class')
|
|
2675
2695
|
continue;
|
|
@@ -2690,6 +2710,8 @@ class Generator {
|
|
|
2690
2710
|
continue;
|
|
2691
2711
|
if (name === 'tooltip' && dropTooltip)
|
|
2692
2712
|
continue;
|
|
2713
|
+
if (dropStops.has(name))
|
|
2714
|
+
continue;
|
|
2693
2715
|
// A button's type is forms machinery (Stage 8): type="submit"
|
|
2694
2716
|
// is consumed by the submit rewrite below, never a prop.
|
|
2695
2717
|
if (isButtonEl && name === 'type')
|
|
@@ -35,7 +35,7 @@ exports.DIAGNOSTIC_CODES = {
|
|
|
35
35
|
CLS_NO_COMPONENT: 'No class decorated with @Component was found in the source file.',
|
|
36
36
|
CLS_PARSE: 'The TypeScript source has a syntax error. TypeScript reads on with error recovery, so classes and fields after the error can be silently missing or misread; the compiler reports the parse error itself instead of guessing.',
|
|
37
37
|
GEN_SETTER_COLLISION: 'A component method has the same name as a generated state setter (set + a field name, or a form field touched setter). The generated code would declare the name twice and one would overwrite the other, so the method must be renamed.',
|
|
38
|
-
GEN_IMPORT_CLASSLESS: 'A relative import binds names from a file that declares no component, service, pipe or directive. Exported constants with literal values in such a file are carried into the generated code (0.6.5); any other name used from it would be undefined at run time, so the compiler reports the import instead of dropping it silently.',
|
|
38
|
+
GEN_IMPORT_CLASSLESS: 'A relative import binds names from a file that declares no component, service, pipe or directive. Exported constants with literal values in such a file are carried into the generated code (this has been the behaviour since version 0.6.5); any other name used from it would be undefined at run time, so the compiler reports the import instead of dropping it silently.',
|
|
39
39
|
CMP_TEMPLATE: 'The component template could not be resolved (missing inline template and templateUrl).',
|
|
40
40
|
CSS_SELECTOR: 'A CSS selector is not an element or .class selector; the rule was skipped.',
|
|
41
41
|
CSS_DECL: 'A CSS declaration is malformed (expected "property: value").',
|
|
@@ -76,6 +76,7 @@ exports.DIAGNOSTIC_CODES = {
|
|
|
76
76
|
GEN_PICKER_PRESENTATION: 'A <datetime-picker> carries a presentation attribute; the picker always opens in a modal and takes no presentation.',
|
|
77
77
|
GEN_BUTTON_COLOR: 'A <button> color is not one of the six colour roles (primary, secondary, danger, warning, success, neutral); the button keeps the primary colour.',
|
|
78
78
|
GEN_SWITCH_COLOR: 'A <switch> color is not one of the two colour roles (primary, success); the switch keeps the primary colour.',
|
|
79
|
+
GEN_GRADIENT_STOP: 'A <gradient> stop (from, via, to) is not a hex colour or a colour role name; the stop was dropped and the theme gradient stop is used instead.',
|
|
79
80
|
GEN_CHART_TYPE: 'A <chart> type is not one of the three chart types (bar, line, pie); the chart would draw bars instead.',
|
|
80
81
|
GEN_OTP_LENGTH: 'An <otp> length is outside the supported 4 to 8; the generated control clamps it to the nearest of the two.',
|
|
81
82
|
GEN_PICKER_INTERVAL: 'A <datetime-picker> minuteInterval is not 1 or 5; the generated code uses the nearest of the two.',
|
|
@@ -1346,7 +1346,20 @@ function renderPreview(component, ast, data = {}) {
|
|
|
1346
1346
|
return cls ? `<span class="${escapeHtml(cls)}"${dirStyle}>${inner}</span>` : `<span${dirStyle}>${inner}</span>`;
|
|
1347
1347
|
}
|
|
1348
1348
|
case 'card': return `<section class="card"${dirStyle}>${inner}</section>`;
|
|
1349
|
-
case 'gradient':
|
|
1349
|
+
case 'gradient': {
|
|
1350
|
+
// Custom stops (the dawn wash round): from, via and to as
|
|
1351
|
+
// hex colours or colour role names paint the same gradient
|
|
1352
|
+
// RgGradient draws in the app; an absent stop falls back to
|
|
1353
|
+
// the theme stop, stop by stop.
|
|
1354
|
+
const stopCss = (v, fallback) => v === undefined ? fallback : v.startsWith('#') ? v : `var(--role-${kebabRole(v)})`;
|
|
1355
|
+
const from = el.attrs['from'], via = el.attrs['via'], to = el.attrs['to'];
|
|
1356
|
+
if (from === undefined && via === undefined && to === undefined) {
|
|
1357
|
+
return `<div class="gradient"${dirStyle}>${inner}</div>`;
|
|
1358
|
+
}
|
|
1359
|
+
const bg = `background: linear-gradient(115deg, ${stopCss(from, t.colors.gradientFrom)}, ${stopCss(via, t.colors.gradientVia)} 52%, ${stopCss(to, t.colors.gradientTo)});`;
|
|
1360
|
+
const styleAttr = dirStyle ? dirStyle.replace('style="', `style="${bg} `) : ` style="${bg}"`;
|
|
1361
|
+
return `<div class="gradient"${styleAttr}>${inner}</div>`;
|
|
1362
|
+
}
|
|
1350
1363
|
case 'sheet': {
|
|
1351
1364
|
const open = rawBound(el, 'open', scope);
|
|
1352
1365
|
if (open !== undefined && !truthy(open))
|
|
@@ -39,7 +39,7 @@ exports.ELEMENT_PROPS = {
|
|
|
39
39
|
'fab': ['label'],
|
|
40
40
|
'file-picker': ['disabled', 'kind', 'label', 'multiple', 'placeholder', 'style'],
|
|
41
41
|
'form': ['icon', 'label', 'meta', 'plain', 'style'],
|
|
42
|
-
'gradient': ['style'],
|
|
42
|
+
'gradient': ['from', 'style', 'to', 'via'],
|
|
43
43
|
'grid-list': ['cols', 'mode', 'style'],
|
|
44
44
|
'grid-tile': ['__widthPct', 'style'],
|
|
45
45
|
'h1': ['style', 'variant'],
|