@zambon-dev/ui 1.10.0 → 1.11.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.
package/CHANGELOG.md CHANGED
@@ -27,6 +27,18 @@ packages are listed under [Package history](#package-history) at the end.
27
27
 
28
28
  ### ⚠ Breaking Changes / Migration
29
29
 
30
+ ## [1.11.0] - 2026-12-06
31
+
32
+ ### Added
33
+
34
+ - `ng add @zambon-dev/ui` sets the package up in a standalone application. It installs the peer
35
+ dependencies, Tailwind CSS 4 and Font Awesome, and creates `.postcssrc.json`. It adds the global
36
+ stylesheets and the translation assets to `angular.json`, and the dark-theme script to
37
+ `index.html`. It also adds the HTTP client, translations, startup language and grid providers to
38
+ the application config. Running it twice changes nothing. An NgModule application is refused, and
39
+ nothing is changed. The shell providers that need your own values (API URL, JWT options, sidebar
40
+ service, routes) are printed as next steps.
41
+
30
42
  ## [1.10.0] - 2026-12-05
31
43
 
32
44
  ### Added
@@ -2834,7 +2846,8 @@ URL) in `AppConfig`, and implement a hub that pushes the notification list to cl
2834
2846
  available via [GitHub Releases](https://github.com/RicardoZambon/ZLibraries/releases) and the
2835
2847
  `shared-v*` tags.
2836
2848
 
2837
- [Unreleased]: https://github.com/RicardoZambon/ZLibraries/compare/ui-v1.10.0...HEAD
2849
+ [Unreleased]: https://github.com/RicardoZambon/ZLibraries/compare/ui-v1.11.0...HEAD
2850
+ [1.11.0]: https://github.com/RicardoZambon/ZLibraries/releases/tag/ui-v1.11.0
2838
2851
  [1.10.0]: https://github.com/RicardoZambon/ZLibraries/releases/tag/ui-v1.10.0
2839
2852
  [1.9.0]: https://github.com/RicardoZambon/ZLibraries/releases/tag/ui-v1.9.0
2840
2853
  [1.8.0]: https://github.com/RicardoZambon/ZLibraries/releases/tag/ui-v1.8.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zambon-dev/ui",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Angular 22 component library and application shell: form controls, a virtual-scroll data grid, modals, ribbon, sidebar, tabbed navigation, view base classes and authentication layouts, themed with Tailwind CSS 4 tokens.",
5
5
  "keywords": [
6
6
  "angular",
@@ -27,6 +27,15 @@
27
27
  "url": "https://github.com/RicardoZambon/ZLibraries/issues"
28
28
  },
29
29
  "homepage": "https://ricardozambon.github.io/ZLibraries/",
30
+ "schematics": "./schematics/collection.json",
31
+ "ng-add": {
32
+ "save": "dependencies"
33
+ },
34
+ "dependencies": {
35
+ "@angular-devkit/schematics": "^22.0.0",
36
+ "@schematics/angular": "^22.0.0",
37
+ "tslib": "^2.3.0"
38
+ },
30
39
  "peerDependencies": {
31
40
  "@angular/cdk": "^22.0.0",
32
41
  "@angular/common": "^22.0.0",
@@ -106,8 +115,5 @@
106
115
  "style": "styles/common.scss",
107
116
  "module": "fesm2022/zambon-dev-ui.mjs",
108
117
  "typings": "types/zambon-dev-ui.d.ts",
109
- "type": "module",
110
- "dependencies": {
111
- "tslib": "^2.3.0"
112
- }
118
+ "type": "module"
113
119
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "ng-add": {
5
+ "description": "Sets up @zambon-dev/ui in a standalone Angular application.",
6
+ "factory": "./ng-add/index#ngAdd",
7
+ "schema": "./ng-add/schema.json"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.I18N_ASSETS = exports.BUILD_DEPENDENCIES = void 0;
4
+ exports.ngAdd = ngAdd;
5
+ exports.withGlobalStyles = withGlobalStyles;
6
+ const schematics_1 = require("@angular-devkit/schematics");
7
+ const utility_1 = require("@schematics/angular/utility");
8
+ const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
9
+ const app_config_1 = require("@schematics/angular/utility/standalone/app_config");
10
+ const util_1 = require("@schematics/angular/utility/standalone/util");
11
+ const node_fs_1 = require("node:fs");
12
+ const node_path_1 = require("node:path");
13
+ const providers_1 = require("./providers");
14
+ /** Packages the styles need. They are not peer dependencies, so the consumer installs them. */
15
+ exports.BUILD_DEPENDENCIES = [
16
+ { name: 'tailwindcss', version: '^4.0.0', type: utility_1.DependencyType.Dev },
17
+ { name: '@tailwindcss/postcss', version: '^4.0.0', type: utility_1.DependencyType.Dev },
18
+ { name: '@tailwindcss/forms', version: '^0.5.9', type: utility_1.DependencyType.Dev },
19
+ { name: '@fortawesome/fontawesome-free', version: '^7.0.0', type: utility_1.DependencyType.Default },
20
+ ];
21
+ const FONT_AWESOME_CSS = '@fortawesome/fontawesome-free/css/all.css';
22
+ const THEME_CSS = '@zambon-dev/ui/styles/theme.css';
23
+ const COMMON_SCSS = '@zambon-dev/ui/styles/common.scss';
24
+ /** The same objects as `ZAMBON_FRAMEWORK_I18N_ASSET` and `ZAMBON_SHARED_I18N_ASSET`; a spec keeps them equal. */
25
+ exports.I18N_ASSETS = [
26
+ {
27
+ glob: '**/*.json',
28
+ input: 'node_modules/@zambon-dev/ui/i18n/framework',
29
+ output: 'assets/i18n/zambon-dev/framework',
30
+ },
31
+ { glob: '**/*.json', input: 'node_modules/@zambon-dev/ui/i18n/shared', output: 'assets/i18n/zambon-dev/shared' },
32
+ ];
33
+ const POSTCSS_PLUGIN = '@tailwindcss/postcss';
34
+ const POSTCSS_CONFIG_FILES = ['.postcssrc.json', 'postcss.config.json'];
35
+ /** Must match `THEME_STORAGE_KEY`, which `ThemeService` writes. */
36
+ const THEME_SCRIPT_MARKER = "localStorage.getItem('zambon-theme')";
37
+ const THEME_SCRIPT = ` <script>
38
+ (function () {
39
+ try {
40
+ var p = localStorage.getItem('zambon-theme') || 'light';
41
+ if (p === 'system') p = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
42
+ document.documentElement.dataset.theme = p;
43
+ } catch (e) {
44
+ document.documentElement.dataset.theme = 'light';
45
+ }
46
+ })();
47
+ </script>
48
+ `;
49
+ const DOCS_URL = 'https://ricardozambon.github.io/ZLibraries/guides/getting-started';
50
+ const NEXT_STEPS = `
51
+ @zambon-dev/ui is set up. Library components such as lib-button render now.
52
+
53
+ The full application shell (MainLayoutComponent and the sign-in screen) needs values only your
54
+ application knows, so add these to the application config yourself:
55
+ - APP_CONFIG with your API base URL
56
+ - JwtModule.forRoot(...) with your token getter and domains, and JwtInterceptor
57
+ - AuthInterceptor in HTTP_INTERCEPTORS
58
+ - { provide: AuthService, useExisting: AuthenticationService }
59
+ - { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
60
+ - { provide: SidebarService, useClass: <your SidebarService subclass> }
61
+ - routes for MainLayoutComponent and SharedAuthModule
62
+
63
+ To load your own translation files, add a resource such as
64
+ { prefix: '/assets/i18n/', suffix: '.json' } to appResources.
65
+
66
+ Full guide: ${DOCS_URL}
67
+ `;
68
+ function ngAdd(options) {
69
+ return async (tree, context) => {
70
+ const workspace = await (0, utility_1.readWorkspace)(tree);
71
+ const projectName = resolveProjectName(options.project, workspace.projects);
72
+ const project = workspace.projects.get(projectName);
73
+ if (!project || project.extensions['projectType'] !== 'application') {
74
+ throw new schematics_1.SchematicsException(`"${projectName}" is not an application in this workspace.`);
75
+ }
76
+ if (!project.targets.get('build')) {
77
+ throw new schematics_1.SchematicsException(`The project "${projectName}" has no build target.`);
78
+ }
79
+ const mainPath = await (0, util_1.getMainFilePath)(tree, projectName);
80
+ if (!(0, ng_ast_utils_1.isStandaloneApp)(tree, mainPath)) {
81
+ throw new schematics_1.SchematicsException(`ng add @zambon-dev/ui supports standalone applications only, and "${projectName}" bootstraps an NgModule ` +
82
+ `(${mainPath} calls bootstrapModule). Nothing was changed. ` +
83
+ `Follow the manual setup instead: ${DOCS_URL}`);
84
+ }
85
+ return (0, schematics_1.chain)([
86
+ addDependencies(),
87
+ updateBuildOptions(projectName, project),
88
+ addPostcssConfig(),
89
+ addThemeScript(project),
90
+ addProviders(projectName, mainPath, context),
91
+ (_, ctx) => ctx.logger.info(NEXT_STEPS),
92
+ ]);
93
+ };
94
+ }
95
+ function resolveProjectName(requested, projects) {
96
+ if (requested) {
97
+ return requested;
98
+ }
99
+ const applications = [...projects].filter(([, project]) => project.extensions['projectType'] === 'application');
100
+ if (applications.length === 1) {
101
+ return applications[0][0];
102
+ }
103
+ throw new schematics_1.SchematicsException('Name the application to set up with --project.');
104
+ }
105
+ function addDependencies() {
106
+ // The peer dependencies go into package.json too: the application config imports some of them,
107
+ // and a strict package manager would not let it import a package it does not declare.
108
+ const manifest = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', '..', 'package.json'), 'utf8'));
109
+ const peers = Object.entries(manifest.peerDependencies ?? {}).map(([name, version]) => ({
110
+ name,
111
+ version,
112
+ type: utility_1.DependencyType.Default,
113
+ }));
114
+ return (0, schematics_1.chain)([...peers, ...exports.BUILD_DEPENDENCIES].map((dependency) => (0, utility_1.addDependency)(dependency.name, dependency.version, {
115
+ type: dependency.type,
116
+ existing: utility_1.ExistingBehavior.Skip,
117
+ })));
118
+ }
119
+ function styleInput(entry) {
120
+ return typeof entry === 'string' ? entry : entry.input;
121
+ }
122
+ /** Adds the three global stylesheets in their required order, and skips any already loaded. */
123
+ function withGlobalStyles(existing, tree) {
124
+ const styles = [...existing];
125
+ const indexOf = (needle) => styles.findIndex((entry) => {
126
+ const input = styleInput(entry);
127
+ return input === needle || (tree.exists(input) && tree.readText(input).includes(needle));
128
+ });
129
+ if (indexOf(FONT_AWESOME_CSS) < 0) {
130
+ styles.unshift(FONT_AWESOME_CSS);
131
+ }
132
+ if (indexOf(THEME_CSS) < 0) {
133
+ styles.splice(indexOf(FONT_AWESOME_CSS) + 1, 0, THEME_CSS);
134
+ }
135
+ if (indexOf(COMMON_SCSS) < 0) {
136
+ styles.splice(indexOf(THEME_CSS) + 1, 0, COMMON_SCSS);
137
+ }
138
+ return styles;
139
+ }
140
+ function updateBuildOptions(projectName, project) {
141
+ return (tree) => {
142
+ const options = project.targets.get('build')?.options ?? {};
143
+ const styles = withGlobalStyles(options['styles'] ?? [], tree);
144
+ const assets = [...(options['assets'] ?? [])];
145
+ for (const asset of exports.I18N_ASSETS) {
146
+ const present = assets.some((entry) => (typeof entry === 'string' ? entry : entry.input) === asset.input);
147
+ if (!present) {
148
+ assets.push(asset);
149
+ }
150
+ }
151
+ return (0, utility_1.updateWorkspace)((workspace) => {
152
+ const build = workspace.projects.get(projectName)?.targets.get('build');
153
+ if (!build) {
154
+ return;
155
+ }
156
+ build.options ??= {};
157
+ build.options['styles'] = styles;
158
+ build.options['assets'] = assets;
159
+ });
160
+ };
161
+ }
162
+ function addPostcssConfig() {
163
+ return (tree, context) => {
164
+ const existing = POSTCSS_CONFIG_FILES.find((file) => tree.exists(file));
165
+ if (!existing) {
166
+ tree.create('.postcssrc.json', JSON.stringify({ plugins: { [POSTCSS_PLUGIN]: {} } }, null, 2) + '\n');
167
+ return;
168
+ }
169
+ let config;
170
+ try {
171
+ config = JSON.parse(tree.readText(existing));
172
+ }
173
+ catch {
174
+ context.logger.warn(`Could not read ${existing}. Add "${POSTCSS_PLUGIN}": {} to its plugins yourself.`);
175
+ return;
176
+ }
177
+ if (config.plugins?.[POSTCSS_PLUGIN]) {
178
+ return;
179
+ }
180
+ config.plugins = { ...config.plugins, [POSTCSS_PLUGIN]: {} };
181
+ tree.overwrite(existing, JSON.stringify(config, null, 2) + '\n');
182
+ };
183
+ }
184
+ function indexHtmlPath(project) {
185
+ const index = project.targets.get('build')?.options?.['index'];
186
+ if (typeof index === 'string') {
187
+ return index;
188
+ }
189
+ if (index?.input) {
190
+ return index.input;
191
+ }
192
+ return node_path_1.posix.join(project.sourceRoot ?? node_path_1.posix.join(project.root, 'src'), 'index.html');
193
+ }
194
+ /** Sets the theme before the first paint, so a user who chose dark never sees a flash of light. */
195
+ function addThemeScript(project) {
196
+ return (tree, context) => {
197
+ const path = indexHtmlPath(project);
198
+ if (!tree.exists(path)) {
199
+ context.logger.warn(`${path} not found. Add the dark-theme script yourself: ${DOCS_URL}`);
200
+ return;
201
+ }
202
+ const html = tree.readText(path);
203
+ if (html.includes(THEME_SCRIPT_MARKER)) {
204
+ return;
205
+ }
206
+ const headEnd = html.indexOf('</head>');
207
+ if (headEnd < 0) {
208
+ context.logger.warn(`${path} has no </head>. Add the dark-theme script yourself: ${DOCS_URL}`);
209
+ return;
210
+ }
211
+ // At the start of the </head> line, so the script is the last element in <head>.
212
+ const lineStart = html.lastIndexOf('\n', headEnd) + 1;
213
+ const atLineStart = html.slice(lineStart, headEnd).trim() === '';
214
+ const recorder = tree.beginUpdate(path);
215
+ recorder.insertLeft(atLineStart ? lineStart : headEnd, atLineStart ? THEME_SCRIPT : '\n' + THEME_SCRIPT);
216
+ tree.commitUpdate(recorder);
217
+ };
218
+ }
219
+ function addProviders(projectName, mainPath, context) {
220
+ return (tree) => {
221
+ const bootstrapCall = (0, util_1.findBootstrapApplicationCall)(tree, mainPath);
222
+ const configPath = (0, app_config_1.findAppConfig)(bootstrapCall, tree, mainPath)?.filePath ?? mainPath;
223
+ const source = tree.readText(configPath);
224
+ const rules = [];
225
+ for (const provider of providers_1.ROOT_PROVIDERS) {
226
+ if (provider.alreadyProvided.test(source)) {
227
+ context.logger.info(`Skipped ${provider.description}: already in ${configPath}.`);
228
+ const warning = provider.checkExisting?.(source);
229
+ if (warning) {
230
+ context.logger.warn(warning);
231
+ }
232
+ continue;
233
+ }
234
+ rules.push((0, utility_1.addRootProvider)(projectName, provider.code));
235
+ }
236
+ return (0, schematics_1.chain)(rules);
237
+ };
238
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ROOT_PROVIDERS = void 0;
4
+ /**
5
+ * Every root provider `ng add` adds, in order. This is the one list to change when the setup
6
+ * changes. Providers that need values only the application knows (the API URL, the JWT options,
7
+ * the sidebar service, the routes) are not here: `ng add` prints them as next steps instead.
8
+ */
9
+ exports.ROOT_PROVIDERS = [
10
+ {
11
+ description: 'HTTP client with class-based interceptors',
12
+ alreadyProvided: /\bprovideHttpClient\s*\(/,
13
+ code: ({ code, external }) => code `${external('provideHttpClient', '@angular/common/http')}(${external('withInterceptorsFromDi', '@angular/common/http')}())`,
14
+ checkExisting: (source) => /\bwithInterceptorsFromDi\s*\(/.test(source)
15
+ ? undefined
16
+ : 'provideHttpClient() is already in the application config without withInterceptorsFromDi(). ' +
17
+ 'Add it if you use AuthInterceptor: the package registers it as a class-based interceptor.',
18
+ },
19
+ {
20
+ description: 'translations for the framework and shared layers',
21
+ alreadyProvided: /\bprovideZambon(Shared|Framework)TranslateService\s*\(|\bprovideTranslateService\s*\(|\bTranslateModule\.forRoot\s*\(/,
22
+ code: ({ code, external }) => code `${external('provideZambonSharedTranslateService', '@zambon-dev/ui/shared')}({
23
+ defaultLanguage: 'en',
24
+ appResources: [...${external('ZAMBON_FRAMEWORK_I18N_RESOURCES', '@zambon-dev/ui/framework')}],
25
+ })`,
26
+ },
27
+ {
28
+ description: 'language selection at startup',
29
+ alreadyProvided: /\.addLangs\s*\(/,
30
+ code: ({ code, external }) => code `${external('provideAppInitializer', '@angular/core')}(() => {
31
+ const translate = ${external('inject', '@angular/core')}(${external('TranslateService', '@ngx-translate/core')});
32
+ translate.addLangs(['en', 'pt']);
33
+ translate.use(globalThis.localStorage?.getItem('language') ?? 'en');
34
+ })`,
35
+ },
36
+ {
37
+ description: 'grid messages as translation keys',
38
+ alreadyProvided: /\bGridConfigsProvider\b/,
39
+ code: ({ code, external }) => code `{ provide: ${external('GridConfigsProvider', '@zambon-dev/ui/library')}, useClass: ${external('FrameworkGridConfigsProvider', '@zambon-dev/ui/framework')} }`,
40
+ },
41
+ ];
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "ZambonDevUiNgAdd",
4
+ "title": "@zambon-dev/ui ng-add",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "The application to set up. Defaults to the project in the current folder, or the only application in the workspace.",
10
+ "$default": {
11
+ "$source": "projectName"
12
+ }
13
+ }
14
+ },
15
+ "required": []
16
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }