tectra-ng 0.2.6 → 0.3.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/README.md CHANGED
@@ -40,18 +40,27 @@
40
40
 
41
41
  ## Install
42
42
 
43
+ ```bash
44
+ ng add tectra-ng
45
+ ```
46
+
47
+ It installs every tectra package at the same version with the Angular peers, adds `provideTectra` with the preset you pick (`--style`, `--primary`, `--surface`) to `app.config.ts` and the fonts to `index.html`.
48
+
49
+ Without the Angular CLI, install it and provide a theme by hand:
50
+
43
51
  ```bash
44
52
  npm i tectra-ng
45
53
  ```
46
54
 
47
- It installs every tectra package at the same version. Provide a theme and import components from the packages themselves:
55
+ Then import components from the packages themselves:
48
56
 
49
57
  ```ts
50
58
  import { provideTectra } from '@tectra-ng/core/config';
59
+ import { TX_ICONS, provideTxIcons } from '@tectra-ng/icons';
51
60
  import { createTectraPreset } from '@tectra-ng/themes';
52
61
 
53
62
  export const appConfig: ApplicationConfig = {
54
- providers: [provideTectra({ preset: createTectraPreset({ primary: 'blue' }) })],
63
+ providers: [provideTectra({ preset: createTectraPreset({ primary: 'blue' }) }), provideTxIcons(TX_ICONS)],
55
64
  };
56
65
  ```
57
66
 
@@ -97,4 +106,6 @@ The code editor is not part of `tectra-ng` either — it carries the CodeMirror
97
106
  npm i @tectra-ng/code-editor
98
107
  ```
99
108
 
109
+ Upgrading from 0.2: [UPGRADING.md](https://github.com/kulakovskyi/tectra-ng/blob/main/UPGRADING.md).
110
+
100
111
  Docs and examples: [tectra-ng.com](https://tectra-ng.com) · MIT license.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tectra-ng",
3
- "version": "0.2.6",
3
+ "version": "0.3.0",
4
4
  "description": "Angular UI component library in one install: 80+ standalone components on signals (table, datepicker, select, dialog, toast, tree), design tokens, light and dark themes, charts, icons, brand logos and flags.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://tectra-ng.com",
@@ -57,17 +57,21 @@
57
57
  "icons"
58
58
  ],
59
59
  "dependencies": {
60
- "@tectra-ng/tokens": "^0.2.6",
61
- "@tectra-ng/themes": "^0.2.6",
62
- "@tectra-ng/core": "^0.2.6",
63
- "@tectra-ng/icons": "^0.2.6",
64
- "@tectra-ng/brand-icons": "^0.2.6",
65
- "@tectra-ng/flags": "^0.2.6",
66
- "@tectra-ng/qr": "^0.2.6",
67
- "@tectra-ng/ui": "^0.2.6",
68
- "@tectra-ng/charts": "^0.2.6",
69
- "@tectra-ng/utils": "^0.2.6",
70
- "@tectra-ng/blocks": "^0.2.6"
60
+ "@tectra-ng/tokens": "^0.3.0",
61
+ "@tectra-ng/themes": "^0.3.0",
62
+ "@tectra-ng/core": "^0.3.0",
63
+ "@tectra-ng/icons": "^0.3.0",
64
+ "@tectra-ng/brand-icons": "^0.3.0",
65
+ "@tectra-ng/flags": "^0.3.0",
66
+ "@tectra-ng/qr": "^0.3.0",
67
+ "@tectra-ng/ui": "^0.3.0",
68
+ "@tectra-ng/charts": "^0.3.0",
69
+ "@tectra-ng/utils": "^0.3.0",
70
+ "@tectra-ng/blocks": "^0.3.0"
71
+ },
72
+ "schematics": "./schematics/collection.json",
73
+ "ng-add": {
74
+ "save": "dependencies"
71
75
  },
72
76
  "publishConfig": {
73
77
  "access": "public"
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "ng-add": {
5
+ "description": "Adds tectra to an Angular application: peer packages, provideTectra with a preset and the fonts.",
6
+ "factory": "./ng-add/index#ngAdd",
7
+ "schema": "./ng-add/schema.json"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FONT_LINKS = exports.ANGULAR_PEERS = exports.MIN_ANGULAR_MAJOR = void 0;
4
+ exports.ngAdd = ngAdd;
5
+ exports.presetOptions = presetOptions;
6
+ exports.resolveProject = resolveProject;
7
+ exports.readAngularRange = readAngularRange;
8
+ exports.indexPath = indexPath;
9
+ exports.insertFontLinks = insertFontLinks;
10
+ const schematics_1 = require("@angular-devkit/schematics");
11
+ const utility_1 = require("@schematics/angular/utility");
12
+ exports.MIN_ANGULAR_MAJOR = 22;
13
+ exports.ANGULAR_PEERS = ['@angular/cdk', '@angular/forms', '@angular/router'];
14
+ exports.FONT_LINKS = [
15
+ '<link rel="preconnect" href="https://fonts.googleapis.com" />',
16
+ '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />',
17
+ '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Onest:wght@100..900&family=JetBrains+Mono:wght@400;500&display=swap" />',
18
+ ];
19
+ function ngAdd(options) {
20
+ return async (tree) => {
21
+ const workspace = await (0, utility_1.readWorkspace)(tree);
22
+ const projectName = resolveProject(workspace, options.project);
23
+ const project = workspace.projects.get(projectName);
24
+ const angularRange = readAngularRange(tree);
25
+ return (0, schematics_1.chain)([
26
+ addPeers(tree, angularRange, options.skipInstall === true),
27
+ addProvider(tree, projectName, project, options),
28
+ options.icons === false ? (0, schematics_1.noop)() : addIcons(tree, projectName, project),
29
+ options.fonts === false ? (0, schematics_1.noop)() : addFonts(project),
30
+ ]);
31
+ };
32
+ }
33
+ function presetOptions({ style = 'tectra', primary = 'blue', surface = 'ink' }, styleSymbol = `${style}Style`) {
34
+ return [style !== 'tectra' ? `style: ${styleSymbol}` : '', `primary: '${primary}'`, surface !== 'ink' ? `surface: '${surface}'` : '']
35
+ .filter(Boolean)
36
+ .join(', ');
37
+ }
38
+ function resolveProject(workspace, requested) {
39
+ const applications = [...workspace.projects.entries()].filter(([, project]) => project.extensions['projectType'] === 'application').map(([name]) => name);
40
+ if (requested) {
41
+ if (!applications.includes(requested)) {
42
+ throw new schematics_1.SchematicsException(`"${requested}" is not an application of this workspace. Applications: ${applications.join(', ') || 'none'}.`);
43
+ }
44
+ return requested;
45
+ }
46
+ if (applications.length === 1) {
47
+ return applications[0];
48
+ }
49
+ if (applications.length === 0) {
50
+ throw new schematics_1.SchematicsException('This workspace has no application. Create one with "ng generate application" and run "ng add tectra-ng" again.');
51
+ }
52
+ throw new schematics_1.SchematicsException(`This workspace has several applications (${applications.join(', ')}). Pick one with --project.`);
53
+ }
54
+ function readAngularRange(tree) {
55
+ const manifest = tree.readJson('/package.json');
56
+ const range = manifest.dependencies?.['@angular/core'] ?? manifest.devDependencies?.['@angular/core'];
57
+ if (!range) {
58
+ throw new schematics_1.SchematicsException('No @angular/core in package.json. tectra is added to an Angular application.');
59
+ }
60
+ const major = Number(/\d+/.exec(range)?.[0]);
61
+ if (!(major >= exports.MIN_ANGULAR_MAJOR)) {
62
+ throw new schematics_1.SchematicsException(`tectra needs Angular ${exports.MIN_ANGULAR_MAJOR} or newer; this application uses @angular/core ${range}.`);
63
+ }
64
+ return range;
65
+ }
66
+ function addPeers(tree, range, skipInstall) {
67
+ const manifest = tree.readJson('/package.json');
68
+ const missing = exports.ANGULAR_PEERS.filter((name) => !manifest.dependencies?.[name] && !manifest.devDependencies?.[name]);
69
+ return (0, schematics_1.chain)(missing.map((name) => (0, utility_1.addDependency)(name, range, {
70
+ type: utility_1.DependencyType.Default,
71
+ existing: utility_1.ExistingBehavior.Skip,
72
+ install: skipInstall ? utility_1.InstallBehavior.None : utility_1.InstallBehavior.Auto,
73
+ })));
74
+ }
75
+ function addProvider(tree, projectName, project, options) {
76
+ const existing = findProvider(tree, sourceRoot(project));
77
+ if (existing) {
78
+ return (_tree, context) => {
79
+ context.logger.info(`provideTectra is already set up in ${existing}; left as it is.`);
80
+ };
81
+ }
82
+ return (0, schematics_1.chain)([
83
+ (0, utility_1.addRootProvider)(projectName, ({ code, external }) => {
84
+ const provideTectra = external('provideTectra', '@tectra-ng/core/config');
85
+ const createTectraPreset = external('createTectraPreset', '@tectra-ng/themes');
86
+ const style = options.style && options.style !== 'tectra' ? external(`${options.style}Style`, '@tectra-ng/themes') : undefined;
87
+ return code `${provideTectra}({ preset: ${createTectraPreset}({ ${presetOptions(options, style)} }) })`;
88
+ }),
89
+ (_tree, context) => {
90
+ context.logger.info(`tectra is set up with createTectraPreset({ ${presetOptions(options)} }).`);
91
+ context.logger.info("Next: import a component, for example import { TxButton } from '@tectra-ng/ui/button'. Docs: https://tectra-ng.com/getting-started");
92
+ },
93
+ ]);
94
+ }
95
+ function addIcons(tree, projectName, project) {
96
+ const existing = findProvider(tree, sourceRoot(project), 'provideTxIcons(');
97
+ if (existing) {
98
+ return (_tree, context) => {
99
+ context.logger.info(`provideTxIcons is already set up in ${existing}; left as it is.`);
100
+ };
101
+ }
102
+ return (0, schematics_1.chain)([
103
+ (0, utility_1.addRootProvider)(projectName, ({ code, external }) => code `${external('provideTxIcons', '@tectra-ng/icons')}(${external('TX_ICONS', '@tectra-ng/icons')})`),
104
+ (_tree, context) => {
105
+ context.logger.info('All 334 icons are registered with provideTxIcons(TX_ICONS). To ship only the icons you use, list them instead: provideTxIcons({ plus: txIconPlus }).');
106
+ },
107
+ ]);
108
+ }
109
+ function findProvider(tree, root, call = 'provideTectra(') {
110
+ let found;
111
+ tree.getDir(root).visit((path) => {
112
+ if (!found && path.endsWith('.ts') && !path.endsWith('.spec.ts') && tree.readText(path).includes(call)) {
113
+ found = path;
114
+ }
115
+ });
116
+ return found;
117
+ }
118
+ function sourceRoot(project) {
119
+ return project.sourceRoot ?? `${project.root ? `${project.root}/` : ''}src`;
120
+ }
121
+ function indexPath(project) {
122
+ const index = project.targets.get('build')?.options?.['index'];
123
+ if (typeof index === 'string') {
124
+ return index;
125
+ }
126
+ if (index && typeof index === 'object' && 'input' in index && typeof index['input'] === 'string') {
127
+ return index['input'];
128
+ }
129
+ return `${sourceRoot(project)}/index.html`;
130
+ }
131
+ function insertFontLinks(html) {
132
+ const at = html.indexOf('</head>');
133
+ if (at < 0) {
134
+ return undefined;
135
+ }
136
+ const lineStart = html.lastIndexOf('\n', at - 1) + 1;
137
+ const closeIndent = html.slice(lineStart, at);
138
+ if (closeIndent.trim() !== '') {
139
+ return `${html.slice(0, at)}${exports.FONT_LINKS.join('')}${html.slice(at)}`;
140
+ }
141
+ const previous = html.slice(0, lineStart).trimEnd().split('\n').pop() ?? '';
142
+ const indent = previous.trim().startsWith('<head') ? `${closeIndent} ` : previous.slice(0, previous.length - previous.trimStart().length);
143
+ return `${html.slice(0, lineStart)}${exports.FONT_LINKS.map((link) => `${indent}${link}\n`).join('')}${html.slice(lineStart)}`;
144
+ }
145
+ function addFonts(project) {
146
+ return (tree, context) => {
147
+ const path = indexPath(project);
148
+ if (!tree.exists(path)) {
149
+ context.logger.warn(`No ${path}; add the fonts by hand: ${exports.FONT_LINKS.join(' ')}`);
150
+ return;
151
+ }
152
+ const html = tree.readText(path);
153
+ if (html.includes('family=Onest')) {
154
+ context.logger.info(`The fonts are already in ${path}.`);
155
+ return;
156
+ }
157
+ const updated = insertFontLinks(html);
158
+ if (!updated) {
159
+ context.logger.warn(`${path} has no </head>; add the fonts by hand: ${exports.FONT_LINKS.join(' ')}`);
160
+ return;
161
+ }
162
+ tree.overwrite(path, updated);
163
+ };
164
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,51 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "TectraNgAdd",
4
+ "title": "Add tectra",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "The application to set up. Defaults to the only application of the workspace.",
10
+ "$default": {
11
+ "$source": "projectName"
12
+ }
13
+ },
14
+ "style": {
15
+ "type": "string",
16
+ "description": "The style of the preset.",
17
+ "enum": ["tectra", "soft", "edge", "paper"],
18
+ "default": "tectra",
19
+ "x-prompt": "Which style?"
20
+ },
21
+ "primary": {
22
+ "type": "string",
23
+ "description": "The primary colour of the preset.",
24
+ "enum": ["noir", "emerald", "green", "lime", "orange", "amber", "yellow", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose"],
25
+ "default": "blue",
26
+ "x-prompt": "Which primary colour?"
27
+ },
28
+ "surface": {
29
+ "type": "string",
30
+ "description": "The surface (neutral) palette of the preset.",
31
+ "enum": ["ink", "slate", "gray", "zinc", "neutral", "stone", "soho", "viva", "ocean", "mauve", "olive", "mist", "taupe"],
32
+ "default": "ink"
33
+ },
34
+ "fonts": {
35
+ "type": "boolean",
36
+ "description": "Add the Onest and JetBrains Mono fonts to index.html.",
37
+ "default": true
38
+ },
39
+ "icons": {
40
+ "type": "boolean",
41
+ "description": "Register all tectra icons with provideTxIcons(TX_ICONS). Turn off to register only the icons the app uses.",
42
+ "default": true
43
+ },
44
+ "skipInstall": {
45
+ "type": "boolean",
46
+ "description": "Do not run the package manager after adding missing peer packages.",
47
+ "default": false
48
+ }
49
+ },
50
+ "required": []
51
+ }