@solercia/ui 0.1.1 → 0.3.1
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/CHANGELOG.md +202 -0
- package/README.md +38 -9
- package/fesm2022/solercia-ui.mjs +10006 -4161
- package/fesm2022/solercia-ui.mjs.map +1 -1
- package/package.json +4 -2
- package/types/solercia-ui.d.ts +2226 -20
- package/schematics/collection.json +0 -34
- package/schematics/entity/files/api/__name__-api.service.ts.template +0 -51
- package/schematics/entity/files/index.ts.template +0 -2
- package/schematics/entity/files/model/__name__.model.ts.template +0 -16
- package/schematics/entity/index.js +0 -40
- package/schematics/entity/schema.json +0 -19
- package/schematics/feature/files/index.ts.template +0 -1
- package/schematics/feature/files/ui/__name__.component.ts.template +0 -41
- package/schematics/feature/index.js +0 -40
- package/schematics/feature/schema.json +0 -19
- package/schematics/migrations/1-noop/index.js +0 -19
- package/schematics/migrations.json +0 -10
- package/schematics/ng-add/index.js +0 -254
- package/schematics/ng-add/schema.json +0 -18
- package/schematics/package.json +0 -3
- package/schematics/page/files/__name__.routes.ts.template +0 -6
- package/schematics/page/files/index.ts.template +0 -2
- package/schematics/page/files/ui/__name__-page.component.ts.template +0 -31
- package/schematics/page/index.js +0 -38
- package/schematics/page/schema.json +0 -19
- package/schematics/utils.js +0 -127
- package/schematics/widget/files/index.ts.template +0 -1
- package/schematics/widget/files/ui/__name__.component.ts.template +0 -54
- package/schematics/widget/index.js +0 -40
- package/schematics/widget/schema.json +0 -19
package/schematics/page/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.page = page;
|
|
4
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
/**
|
|
7
|
-
* `ng g @solercia/ui:page <name>` — crea `<sourceRoot>/pages/<name>/` con la
|
|
8
|
-
* page standalone `OnPush`, sus rutas locales (`<name>.routes.ts`) y su
|
|
9
|
-
* `index.ts` (public API), calcados del molde real de `boki-front`
|
|
10
|
-
* (`src/pages/login/`): selector `sol-<name>-page`, clase `<Name>PageComponent`
|
|
11
|
-
* (SIN prefijo `Sol` — reservado a `shared/ui`), textos por `I18nService.t()`.
|
|
12
|
-
*
|
|
13
|
-
* `pages/` NO tiene barrel agregador (lazy-loading por ruta): a diferencia de
|
|
14
|
-
* `feature`/`entity`/`widget`, este generador no toca ningún `index.ts` fuera
|
|
15
|
-
* de la carpeta de la page. La página queda lista para cablearse a mano en
|
|
16
|
-
* las rutas del host (el mensaje final imprime el snippet exacto).
|
|
17
|
-
*/
|
|
18
|
-
function page(options) {
|
|
19
|
-
return async (tree, context) => {
|
|
20
|
-
if (!options.name?.trim()) {
|
|
21
|
-
throw new Error('El schematic "page" requiere un nombre, ej. `ng g @solercia/ui:page catalog`.');
|
|
22
|
-
}
|
|
23
|
-
const sourceRoot = await (0, utils_1.resolveSourceRoot)(tree, options.project);
|
|
24
|
-
const name = (0, utils_1.toDasherized)(options.name);
|
|
25
|
-
const className = (0, utils_1.toClassName)(options.name);
|
|
26
|
-
const camelName = (0, utils_1.toCamelCase)(options.name);
|
|
27
|
-
const selector = `sol-${name}-page`;
|
|
28
|
-
const targetDir = `${sourceRoot}/pages/${name}`;
|
|
29
|
-
(0, utils_1.upsertI18nKey)(tree, context, 'pages', camelName, 'title', className, `${sourceRoot}/assets/i18n/es-CO.json`);
|
|
30
|
-
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
31
|
-
(0, schematics_1.applyTemplates)({ name, className, camelName, selector }),
|
|
32
|
-
(0, schematics_1.move)(targetDir),
|
|
33
|
-
]);
|
|
34
|
-
context.logger.info(`[@solercia/ui] Page "${name}" creada en ${targetDir}/. Cablea la ruta lazy en tu router:\n` +
|
|
35
|
-
` { path: '${name}', loadChildren: () => import('@pages/${name}').then((m) => m.${camelName}Routes) }`);
|
|
36
|
-
return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$id": "SolerciaUiPage",
|
|
4
|
-
"title": "Solercia UI page schematic",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
"name": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "Nombre de la page (kebab-case recomendado, ej. \"catalog\").",
|
|
10
|
-
"$default": { "$source": "argv", "index": 0 }
|
|
11
|
-
},
|
|
12
|
-
"project": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"description": "Proyecto Angular objetivo. Por defecto, el proyecto de tipo application del workspace.",
|
|
15
|
-
"$default": { "$source": "projectName" }
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"required": ["name"]
|
|
19
|
-
}
|
package/schematics/utils.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SOURCE_ROOT = void 0;
|
|
4
|
-
exports.toClassName = toClassName;
|
|
5
|
-
exports.toDasherized = toDasherized;
|
|
6
|
-
exports.toCamelCase = toCamelCase;
|
|
7
|
-
exports.toPluralKebab = toPluralKebab;
|
|
8
|
-
exports.resolveProjectName = resolveProjectName;
|
|
9
|
-
exports.resolveSourceRoot = resolveSourceRoot;
|
|
10
|
-
exports.upsertI18nKey = upsertI18nKey;
|
|
11
|
-
exports.appendToLayerBarrel = appendToLayerBarrel;
|
|
12
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
-
const utility_1 = require("@schematics/angular/utility");
|
|
14
|
-
const schematics_2 = require("@angular-devkit/schematics");
|
|
15
|
-
/**
|
|
16
|
-
* Utilidades compartidas por los generadores `page`/`feature`/`entity`/`widget`
|
|
17
|
-
* y por el schematic `ng-add` de `@solercia/ui`.
|
|
18
|
-
*
|
|
19
|
-
* Viven en `schematics/` (NO en `src/`) porque corren en Node al momento de
|
|
20
|
-
* generar código — nunca se empaquetan en el runtime del navegador. Se
|
|
21
|
-
* compilan aparte (`tsconfig.schematics.json`) y se copian al `dist` junto
|
|
22
|
-
* con `collection.json`, cada `schema.json` y las plantillas `files/`.
|
|
23
|
-
*/
|
|
24
|
-
/** Nombre de la carpeta raíz de código fuente FSD (convención fija del ecosistema). */
|
|
25
|
-
exports.DEFAULT_SOURCE_ROOT = 'src';
|
|
26
|
-
/** Alias `Sol*` reservado a `shared/ui` (CONVENCIONES-FRONT-SOLERCIA §5): los
|
|
27
|
-
* generadores de page/feature/entity/widget NUNCA anteponen `Sol` al nombre
|
|
28
|
-
* de clase — solo el prefijo `sol-` del selector es universal en la app. */
|
|
29
|
-
function toClassName(name) {
|
|
30
|
-
return schematics_2.strings.classify(name);
|
|
31
|
-
}
|
|
32
|
-
function toDasherized(name) {
|
|
33
|
-
return schematics_2.strings.dasherize(name);
|
|
34
|
-
}
|
|
35
|
-
function toCamelCase(name) {
|
|
36
|
-
return schematics_2.strings.camelize(name);
|
|
37
|
-
}
|
|
38
|
-
/** Pluralización naive para nombres de recursos REST (`tag` → `tags`, `faq` → `faqs`).
|
|
39
|
-
* Suficiente para el andamiaje generado; el desarrollador ajusta si el plural es irregular. */
|
|
40
|
-
function toPluralKebab(name) {
|
|
41
|
-
const dasherized = toDasherized(name);
|
|
42
|
-
return dasherized.endsWith('s') ? dasherized : `${dasherized}s`;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Resuelve el nombre del proyecto Angular objetivo: el explícito (`--project`),
|
|
46
|
-
* o si no se dio ninguno, el primer proyecto de tipo `application` del
|
|
47
|
-
* workspace (o el primero que exista). `null` cuando no hay `angular.json`
|
|
48
|
-
* (p. ej. un `Tree` de test vacío).
|
|
49
|
-
*/
|
|
50
|
-
async function resolveProjectName(tree, projectName) {
|
|
51
|
-
if (!tree.exists('/angular.json')) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const workspace = await (0, utility_1.readWorkspace)(tree);
|
|
55
|
-
return (projectName ??
|
|
56
|
-
[...workspace.projects.keys()].find((candidate) => {
|
|
57
|
-
return workspace.projects.get(candidate)?.extensions?.['projectType'] === 'application';
|
|
58
|
-
}) ??
|
|
59
|
-
[...workspace.projects.keys()][0] ??
|
|
60
|
-
null);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Resuelve el `sourceRoot` del proyecto Angular objetivo (por defecto `src`).
|
|
64
|
-
* Usa `angular.json` cuando existe (workspace real); cae a {@link DEFAULT_SOURCE_ROOT}
|
|
65
|
-
* cuando no hay workspace (p. ej. un `Tree` de test vacío), para que los
|
|
66
|
-
* generadores sigan siendo utilizables de forma aislada en `SchematicTestRunner`.
|
|
67
|
-
*/
|
|
68
|
-
async function resolveSourceRoot(tree, projectName) {
|
|
69
|
-
const name = await resolveProjectName(tree, projectName);
|
|
70
|
-
if (!name) {
|
|
71
|
-
return exports.DEFAULT_SOURCE_ROOT;
|
|
72
|
-
}
|
|
73
|
-
const workspace = await (0, utility_1.readWorkspace)(tree);
|
|
74
|
-
const project = workspace.projects.get(name);
|
|
75
|
-
if (!project) {
|
|
76
|
-
throw new schematics_1.SchematicsException(`El proyecto "${name}" no existe en angular.json.`);
|
|
77
|
-
}
|
|
78
|
-
return project.sourceRoot ?? `${project.root}/${exports.DEFAULT_SOURCE_ROOT}`.replace(/^\//, '');
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Inserta (idempotente) una clave i18n anidada en el JSON `es-CO` del host, bajo
|
|
82
|
-
* `namespace.camelName.leafKey`. Si el archivo no existe (host sin i18n Transloco
|
|
83
|
-
* cableado como boki-front), no falla: solo avisa por el logger — el andamiaje
|
|
84
|
-
* FSD generado sigue siendo válido, solo falta la traducción manual.
|
|
85
|
-
*/
|
|
86
|
-
function upsertI18nKey(tree, context, namespace, camelName, leafKey, value, i18nPath = `${exports.DEFAULT_SOURCE_ROOT}/assets/i18n/es-CO.json`) {
|
|
87
|
-
if (!tree.exists(i18nPath)) {
|
|
88
|
-
context.logger.warn(`[@solercia/ui] No se encontró "${i18nPath}" — agrega manualmente la clave ` +
|
|
89
|
-
`"${namespace}.${camelName}.${leafKey}" al catálogo i18n del proyecto.`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const raw = tree.read(i18nPath);
|
|
93
|
-
if (!raw) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let json;
|
|
97
|
-
try {
|
|
98
|
-
json = JSON.parse(raw.toString('utf-8'));
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
context.logger.warn(`[@solercia/ui] "${i18nPath}" no es JSON válido — se omite la inserción de claves i18n.`);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const nsBucket = (json[namespace] ??= {});
|
|
105
|
-
const entryBucket = (nsBucket[camelName] ??= {});
|
|
106
|
-
if (entryBucket[leafKey] === undefined) {
|
|
107
|
-
entryBucket[leafKey] = value;
|
|
108
|
-
tree.overwrite(i18nPath, `${JSON.stringify(json, null, 2)}\n`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Agrega (idempotente) una línea `export ... from './<name>';` al barrel agregador
|
|
113
|
-
* de una capa (`widgets/index.ts`, `features/index.ts`, `entities/index.ts`). Las
|
|
114
|
-
* `pages/` NO tienen agregador (lazy-loading por ruta, ver `pages/index.ts` real
|
|
115
|
-
* de boki-front) — los generadores de `page` nunca llaman esta función.
|
|
116
|
-
*/
|
|
117
|
-
function appendToLayerBarrel(tree, barrelPath, exportLine) {
|
|
118
|
-
if (!tree.exists(barrelPath)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const raw = tree.read(barrelPath)?.toString('utf-8') ?? '';
|
|
122
|
-
if (raw.includes(exportLine)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const separator = raw.length > 0 && !raw.endsWith('\n') ? '\n' : '';
|
|
126
|
-
tree.overwrite(barrelPath, `${raw}${separator}${exportLine}\n`);
|
|
127
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { <%= className %>Component } from './ui/<%= name %>.component';
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Component, ChangeDetectionStrategy, input, output, inject } from '@angular/core';
|
|
2
|
-
import { I18nService } from '@shared/i18n';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Widget generado por `ng g @solercia/ui:widget <%= name %>`.
|
|
6
|
-
*
|
|
7
|
-
* Standalone + `OnPush` + signals (`input()`/`output()`) + textos por clave
|
|
8
|
-
* i18n (`widgets.<%= camelName %>.*`), calcado del molde de `@solercia/ui`
|
|
9
|
-
* (ver `src/widgets/stat-card/ui/stat-card.component.ts` en boki-front).
|
|
10
|
-
* Los widgets son bloques autónomos: pueden componer features/entities, a
|
|
11
|
-
* diferencia de `shared/ui` (que solo admite componentes tontos).
|
|
12
|
-
*/
|
|
13
|
-
@Component({
|
|
14
|
-
standalone: true,
|
|
15
|
-
selector: '<%= selector %>',
|
|
16
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
17
|
-
template: `
|
|
18
|
-
<div class="<%= name %>">
|
|
19
|
-
<span class="<%= name %>__label">{{ titleLabel() }}</span>
|
|
20
|
-
@if (value()) {
|
|
21
|
-
<span class="<%= name %>__value">{{ value() }}</span>
|
|
22
|
-
}
|
|
23
|
-
</div>
|
|
24
|
-
`,
|
|
25
|
-
styles: [`
|
|
26
|
-
.<%= name %> {
|
|
27
|
-
display: flex;
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap: var(--sol-space-sm, 8px);
|
|
30
|
-
padding: var(--sol-space-md, 16px);
|
|
31
|
-
background: var(--sol-card-bg, var(--sol-bg-surface, #fff));
|
|
32
|
-
border-radius: var(--sol-card-radius, var(--sol-border-radius-lg, 12px));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.<%= name %>__label {
|
|
36
|
-
color: var(--sol-color-text-secondary);
|
|
37
|
-
font-size: var(--sol-font-size-sm, 12px);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.<%= name %>__value {
|
|
41
|
-
color: var(--sol-color-text-primary);
|
|
42
|
-
font-weight: var(--sol-font-weight-bold, 600);
|
|
43
|
-
}
|
|
44
|
-
`],
|
|
45
|
-
})
|
|
46
|
-
export class <%= className %>Component {
|
|
47
|
-
private readonly i18n = inject(I18nService);
|
|
48
|
-
|
|
49
|
-
/** Ajusta el tipo/valor por defecto al contrato real del widget. */
|
|
50
|
-
readonly value = input<string>('');
|
|
51
|
-
readonly activated = output<void>();
|
|
52
|
-
|
|
53
|
-
readonly titleLabel = this.i18n.t('widgets.<%= camelName %>.title');
|
|
54
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.widget = widget;
|
|
4
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
/**
|
|
7
|
-
* `ng g @solercia/ui:widget <name>` — crea `<sourceRoot>/widgets/<name>/` con
|
|
8
|
-
* un componente standalone `OnPush` con signals, calcado del molde real
|
|
9
|
-
* (`src/widgets/stat-card/ui/stat-card.component.ts`): selector `sol-<name>`,
|
|
10
|
-
* clase `<Name>Component` (SIN prefijo `Sol` — reservado a `shared/ui`),
|
|
11
|
-
* textos por `I18nService.t('widgets.<camelName>.*')`.
|
|
12
|
-
*
|
|
13
|
-
* Actualiza (idempotente) el barrel agregador `<sourceRoot>/widgets/index.ts`
|
|
14
|
-
* además del `index.ts` propio de la carpeta nueva.
|
|
15
|
-
*/
|
|
16
|
-
function widget(options) {
|
|
17
|
-
return async (tree, context) => {
|
|
18
|
-
if (!options.name?.trim()) {
|
|
19
|
-
throw new Error('El schematic "widget" requiere un nombre, ej. `ng g @solercia/ui:widget stat-card`.');
|
|
20
|
-
}
|
|
21
|
-
const sourceRoot = await (0, utils_1.resolveSourceRoot)(tree, options.project);
|
|
22
|
-
const name = (0, utils_1.toDasherized)(options.name);
|
|
23
|
-
const className = (0, utils_1.toClassName)(options.name);
|
|
24
|
-
const camelName = (0, utils_1.toCamelCase)(options.name);
|
|
25
|
-
const selector = `sol-${name}`;
|
|
26
|
-
const targetDir = `${sourceRoot}/widgets/${name}`;
|
|
27
|
-
(0, utils_1.upsertI18nKey)(tree, context, 'widgets', camelName, 'title', className, `${sourceRoot}/assets/i18n/es-CO.json`);
|
|
28
|
-
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
29
|
-
(0, schematics_1.applyTemplates)({ name, className, camelName, selector }),
|
|
30
|
-
(0, schematics_1.move)(targetDir),
|
|
31
|
-
]);
|
|
32
|
-
return (0, schematics_1.chain)([
|
|
33
|
-
(0, schematics_1.mergeWith)(templateSource),
|
|
34
|
-
(host) => {
|
|
35
|
-
(0, utils_1.appendToLayerBarrel)(host, `${sourceRoot}/widgets/index.ts`, `export { ${className}Component } from './${name}';`);
|
|
36
|
-
return host;
|
|
37
|
-
},
|
|
38
|
-
]);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$id": "SolerciaUiWidget",
|
|
4
|
-
"title": "Solercia UI widget schematic",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
"name": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "Nombre del widget (kebab-case recomendado, ej. \"stat-card\").",
|
|
10
|
-
"$default": { "$source": "argv", "index": 0 }
|
|
11
|
-
},
|
|
12
|
-
"project": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"description": "Proyecto Angular objetivo. Por defecto, el proyecto de tipo application del workspace.",
|
|
15
|
-
"$default": { "$source": "projectName" }
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"required": ["name"]
|
|
19
|
-
}
|