@tmdjr/ngx-editor-js2 20.0.3 → 20.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmdjr/ngx-editor-js2",
3
- "version": "20.0.3",
3
+ "version": "20.0.5",
4
4
  "schematics": "./schematics/collection.json",
5
5
  "peerDependencies": {
6
6
  "@angular/animations": "^20.0.4",
@@ -1,2 +1,2 @@
1
1
  import { Rule } from '@angular-devkit/schematics';
2
- export declare function ngAdd(): Rule;
2
+ export declare function ngAdd(options: any): Rule;
@@ -29,19 +29,28 @@ const optionalBlocks = {
29
29
  name: 'ngx-editor-js2-mermaidjs',
30
30
  package: '@tmdjr/ngx-editor-js2-mermaidjs',
31
31
  stylePath: 'dist/ngx-editor-js2-mermaidjs',
32
- peers: ['mermaid', '@ctrl/ngx-codemirror', '@types/codemirror'],
32
+ peers: [
33
+ { package: 'mermaid' },
34
+ { package: '@ctrl/ngx-codemirror' },
35
+ { package: '@types/codemirror' },
36
+ { package: 'codemirror', version: '5.65.9' },
37
+ ],
33
38
  },
34
39
  codemirror: {
35
40
  name: 'ngx-editor-js2-codemirror',
36
41
  package: '@tmdjr/ngx-editor-js2-codemirror',
37
42
  stylePath: 'dist/ngx-editor-js2-codemirror',
38
- peers: ['@ctrl/ngx-codemirror', '@types/codemirror'],
43
+ peers: [
44
+ { package: '@ctrl/ngx-codemirror' },
45
+ { package: '@types/codemirror' },
46
+ { package: 'codemirror', version: '5.65.9' },
47
+ ],
39
48
  },
40
49
  mfeLoader: {
41
50
  name: 'ngx-editor-js2-mfe-loader',
42
51
  package: '@tmdjr/ngx-editor-js2-mfe-loader',
43
52
  stylePath: 'dist/ngx-editor-js2-mfe-loader',
44
- peers: ['@angular-architects/module-federation'],
53
+ peers: [{ package: '@angular-architects/module-federation' }],
45
54
  },
46
55
  blockquotes: {
47
56
  name: 'ngx-editor-js2-blockquotes',
@@ -50,22 +59,10 @@ const optionalBlocks = {
50
59
  peers: [],
51
60
  },
52
61
  };
53
- function ngAdd() {
62
+ function ngAdd(options) {
54
63
  return (tree, context) => __awaiter(this, void 0, void 0, function* () {
55
- var _a, _b;
56
- const response = (_b = (yield ((_a = context.prompt) === null || _a === void 0 ? void 0 : _a.call(context, [
57
- {
58
- type: 'checkbox',
59
- name: 'blocks',
60
- message: 'Select optional Ngx-Editor-JS2 blocks to install:',
61
- choices: Object.keys(optionalBlocks).map((block) => ({
62
- name: block,
63
- message: block,
64
- checked: false,
65
- })),
66
- },
67
- ])))) !== null && _b !== void 0 ? _b : { blocks: [] };
68
- response.blocks.forEach((block) => {
64
+ const blocks = options.blocks || [];
65
+ blocks.forEach((block) => {
69
66
  const { package: pkg, peers } = optionalBlocks[block];
70
67
  (0, dependencies_1.addPackageJsonDependency)(tree, {
71
68
  type: dependencies_1.NodeDependencyType.Default,
@@ -73,56 +70,28 @@ function ngAdd() {
73
70
  version: 'latest',
74
71
  });
75
72
  peers.forEach((peer) => {
76
- const type = peer.startsWith('@types/')
73
+ var _a;
74
+ const type = peer.package.startsWith('@types/')
77
75
  ? dependencies_1.NodeDependencyType.Dev
78
76
  : dependencies_1.NodeDependencyType.Default;
79
77
  (0, dependencies_1.addPackageJsonDependency)(tree, {
80
78
  type,
81
- name: peer,
82
- version: 'latest',
79
+ name: peer.package,
80
+ version: (_a = peer.version) !== null && _a !== void 0 ? _a : 'latest',
83
81
  });
84
82
  });
85
83
  });
86
84
  context.addTask(new tasks_1.NodePackageInstallTask());
87
- const sourceRoot = yield getSourceRoot(tree, context);
88
- updateStylesScss(tree, response.blocks, context, sourceRoot);
89
- updateAppConfig(tree, response.blocks, context, sourceRoot);
90
- addCodeMirrorSetup(tree, response.blocks, context, sourceRoot);
85
+ const sourceRoot = options.project
86
+ ? getProjectSourceRoot(tree, options.project)
87
+ : 'src';
88
+ updateStylesScss(tree, blocks, context, sourceRoot);
89
+ updateAppConfig(tree, blocks, context, sourceRoot);
90
+ addCodeMirrorSetup(tree, blocks, context, sourceRoot);
91
91
  context.logger.info('✅ Installation setup complete.');
92
92
  return tree;
93
93
  });
94
94
  }
95
- function getSourceRoot(tree, context) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- var _a, _b;
98
- const buffer = tree.read('/angular.json');
99
- if (!buffer) {
100
- context.logger.error('❌ angular.json not found.');
101
- throw new Error('angular.json not found... get good');
102
- }
103
- const angularJson = JSON.parse(buffer.toString());
104
- // We need to get every project in the workspace
105
- const projects = Object.keys(angularJson.projects);
106
- // We will prompt the user to select a project
107
- const response = (_b = (yield ((_a = context.prompt) === null || _a === void 0 ? void 0 : _a.call(context, [
108
- {
109
- type: 'list',
110
- name: 'project',
111
- message: 'Select the Angular project to update:',
112
- choices: projects.map((project) => ({
113
- name: project,
114
- message: project,
115
- })),
116
- },
117
- ])))) !== null && _b !== void 0 ? _b : { project: projects[0] }; // fallback to first project
118
- const project = response.project;
119
- if (!project || !angularJson.projects[project]) {
120
- context.logger.error(`❌ Project ${project} not found in angular.json.`);
121
- throw new Error(`Project ${project} not found in angular.json`);
122
- }
123
- return angularJson.projects[project].sourceRoot;
124
- });
125
- }
126
95
  function updateStylesScss(tree, blocks, context, sourceRoot) {
127
96
  const stylePath = `${sourceRoot}/styles.scss`;
128
97
  if (!tree.exists(stylePath)) {
@@ -183,7 +152,7 @@ function updateAppConfig(tree, blocks, context, sourceRoot) {
183
152
  context.logger.info('🚀 app.config.ts updated successfully.');
184
153
  }
185
154
  function addCodeMirrorSetup(tree, selectedBlocks, context, sourceRoot) {
186
- const needsCodeMirror = selectedBlocks.some((block) => ['ngx-editor-js2-codemirror', 'ngx-editor-js2-mermaidjs'].includes(block));
155
+ const needsCodeMirror = selectedBlocks.some((block) => ['codemirror', 'mermaidjs'].includes(block));
187
156
  if (!needsCodeMirror) {
188
157
  context.logger.info('CodeMirror dependencies not selected; skipping setup.');
189
158
  return;
@@ -223,53 +192,13 @@ import 'codemirror/mode/xml/xml';
223
192
  context.logger.warn(`styles.scss not found at path: ${stylesPath}`);
224
193
  }
225
194
  }
226
- // async function updateAngularJson(
227
- // tree: Tree,
228
- // blocks: string[],
229
- // context: SchematicContext
230
- // ): Promise<string> {
231
- // const angularJsonPath = '/angular.json';
232
- // const buffer = tree.read(angularJsonPath);
233
- // if (!buffer) {
234
- // context.logger.error('❌ angular.json not found.');
235
- // throw new Error('angular.json not found... get good');
236
- // }
237
- // const angularJson = JSON.parse(buffer.toString());
238
- // // const project = angularJson.defaultProject;
239
- // // We need to get every project in the workspace
240
- // const projects = Object.keys(angularJson.projects);
241
- // // We will prompt the user to select a project
242
- // const response = await prompt<{ project: string }>({
243
- // type: 'select',
244
- // name: 'project',
245
- // message: 'Select the Angular project to update:',
246
- // choices: projects.map((project) => ({
247
- // name: project,
248
- // message: project,
249
- // })),
250
- // });
251
- // const project = response.project;
252
- // if (!project || !angularJson.projects[project]) {
253
- // context.logger.error(`❌ Project ${project} not found in angular.json.`);
254
- // throw new Error(`Project ${project} not found in angular.json`);
255
- // }
256
- // const includePaths =
257
- // angularJson.projects[project].architect.build.options
258
- // .stylePreprocessorOptions?.includePaths || [];
259
- // includePaths.push('dist/ngx-editor-js2');
260
- // blocks.forEach((block) => {
261
- // const stylePath = optionalBlocks[block].stylePath;
262
- // if (!includePaths.includes(stylePath)) {
263
- // includePaths.push(stylePath);
264
- // }
265
- // });
266
- // angularJson.projects[
267
- // project
268
- // ].architect.build.options.stylePreprocessorOptions = { includePaths };
269
- // tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
270
- // context.logger.info('🔧 angular.json updated successfully.');
271
- // return (
272
- // angularJson.projects[project].sourceRoot ||
273
- // angularJson.projects[project].root
274
- // );
275
- // }
195
+ function getProjectSourceRoot(tree, projectName) {
196
+ const buffer = tree.read('/angular.json');
197
+ if (!buffer)
198
+ throw new Error('angular.json not found');
199
+ const workspace = JSON.parse(buffer.toString());
200
+ const project = workspace.projects[projectName];
201
+ if (!project)
202
+ throw new Error(`Project ${projectName} not found`);
203
+ return project.sourceRoot || 'src';
204
+ }
@@ -7,7 +7,12 @@ import {
7
7
 
8
8
  const optionalBlocks: Record<
9
9
  string,
10
- { name: string; package: string; stylePath: string; peers: string[] }
10
+ {
11
+ name: string;
12
+ package: string;
13
+ stylePath: string;
14
+ peers: { package: string; version?: string }[];
15
+ }
11
16
  > = {
12
17
  image: {
13
18
  name: 'ngx-editor-js2-image',
@@ -25,19 +30,28 @@ const optionalBlocks: Record<
25
30
  name: 'ngx-editor-js2-mermaidjs',
26
31
  package: '@tmdjr/ngx-editor-js2-mermaidjs',
27
32
  stylePath: 'dist/ngx-editor-js2-mermaidjs',
28
- peers: ['mermaid', '@ctrl/ngx-codemirror', '@types/codemirror'],
33
+ peers: [
34
+ { package: 'mermaid' },
35
+ { package: '@ctrl/ngx-codemirror' },
36
+ { package: '@types/codemirror' },
37
+ { package: 'codemirror', version: '5.65.9' },
38
+ ],
29
39
  },
30
40
  codemirror: {
31
41
  name: 'ngx-editor-js2-codemirror',
32
42
  package: '@tmdjr/ngx-editor-js2-codemirror',
33
43
  stylePath: 'dist/ngx-editor-js2-codemirror',
34
- peers: ['@ctrl/ngx-codemirror', '@types/codemirror'],
44
+ peers: [
45
+ { package: '@ctrl/ngx-codemirror' },
46
+ { package: '@types/codemirror' },
47
+ { package: 'codemirror', version: '5.65.9' },
48
+ ],
35
49
  },
36
50
  mfeLoader: {
37
51
  name: 'ngx-editor-js2-mfe-loader',
38
52
  package: '@tmdjr/ngx-editor-js2-mfe-loader',
39
53
  stylePath: 'dist/ngx-editor-js2-mfe-loader',
40
- peers: ['@angular-architects/module-federation'],
54
+ peers: [{ package: '@angular-architects/module-federation' }],
41
55
  },
42
56
  blockquotes: {
43
57
  name: 'ngx-editor-js2-blockquotes',
@@ -47,22 +61,11 @@ const optionalBlocks: Record<
47
61
  },
48
62
  };
49
63
 
50
- export function ngAdd(): Rule {
64
+ export function ngAdd(options: any): Rule {
51
65
  return async (tree: Tree, context: SchematicContext) => {
52
- const response = (await context.prompt?.([
53
- {
54
- type: 'checkbox',
55
- name: 'blocks',
56
- message: 'Select optional Ngx-Editor-JS2 blocks to install:',
57
- choices: Object.keys(optionalBlocks).map((block) => ({
58
- name: block,
59
- message: block,
60
- checked: false,
61
- })),
62
- },
63
- ])) ?? { blocks: [] };
64
-
65
- response.blocks.forEach((block) => {
66
+ const blocks: string[] = options.blocks || [];
67
+
68
+ blocks.forEach((block) => {
66
69
  const { package: pkg, peers } = optionalBlocks[block];
67
70
  addPackageJsonDependency(tree, {
68
71
  type: NodeDependencyType.Default,
@@ -70,26 +73,26 @@ export function ngAdd(): Rule {
70
73
  version: 'latest',
71
74
  });
72
75
  peers.forEach((peer) => {
73
- const type = peer.startsWith('@types/')
76
+ const type = peer.package.startsWith('@types/')
74
77
  ? NodeDependencyType.Dev
75
78
  : NodeDependencyType.Default;
76
79
  addPackageJsonDependency(tree, {
77
80
  type,
78
- name: peer,
79
- version: 'latest',
81
+ name: peer.package,
82
+ version: peer.version ?? 'latest',
80
83
  });
81
84
  });
82
85
  });
83
86
 
84
87
  context.addTask(new NodePackageInstallTask());
85
88
 
86
- const sourceRoot = await getSourceRoot(tree, context);
87
-
88
- updateStylesScss(tree, response.blocks, context, sourceRoot);
89
+ const sourceRoot = options.project
90
+ ? getProjectSourceRoot(tree, options.project)
91
+ : 'src';
89
92
 
90
- updateAppConfig(tree, response.blocks, context, sourceRoot);
91
-
92
- addCodeMirrorSetup(tree, response.blocks, context, sourceRoot);
93
+ updateStylesScss(tree, blocks, context, sourceRoot);
94
+ updateAppConfig(tree, blocks, context, sourceRoot);
95
+ addCodeMirrorSetup(tree, blocks, context, sourceRoot);
93
96
 
94
97
  context.logger.info('✅ Installation setup complete.');
95
98
 
@@ -97,44 +100,6 @@ export function ngAdd(): Rule {
97
100
  };
98
101
  }
99
102
 
100
- async function getSourceRoot(
101
- tree: Tree,
102
- context: SchematicContext
103
- ): Promise<string> {
104
- const buffer = tree.read('/angular.json');
105
-
106
- if (!buffer) {
107
- context.logger.error('❌ angular.json not found.');
108
- throw new Error('angular.json not found... get good');
109
- }
110
-
111
- const angularJson = JSON.parse(buffer.toString());
112
-
113
- // We need to get every project in the workspace
114
- const projects = Object.keys(angularJson.projects);
115
- // We will prompt the user to select a project
116
- const response = (await context.prompt?.([
117
- {
118
- type: 'list',
119
- name: 'project',
120
- message: 'Select the Angular project to update:',
121
- choices: projects.map((project) => ({
122
- name: project,
123
- message: project,
124
- })),
125
- },
126
- ])) ?? { project: projects[0] }; // fallback to first project
127
-
128
- const project = response.project;
129
-
130
- if (!project || !angularJson.projects[project]) {
131
- context.logger.error(`❌ Project ${project} not found in angular.json.`);
132
- throw new Error(`Project ${project} not found in angular.json`);
133
- }
134
-
135
- return angularJson.projects[project].sourceRoot;
136
- }
137
-
138
103
  function updateStylesScss(
139
104
  tree: Tree,
140
105
  blocks: string[],
@@ -242,7 +207,7 @@ function addCodeMirrorSetup(
242
207
  sourceRoot: string
243
208
  ): void {
244
209
  const needsCodeMirror = selectedBlocks.some((block) =>
245
- ['ngx-editor-js2-codemirror', 'ngx-editor-js2-mermaidjs'].includes(block)
210
+ ['codemirror', 'mermaidjs'].includes(block)
246
211
  );
247
212
 
248
213
  if (!needsCodeMirror) {
@@ -292,62 +257,11 @@ import 'codemirror/mode/xml/xml';
292
257
  }
293
258
  }
294
259
 
295
- // async function updateAngularJson(
296
- // tree: Tree,
297
- // blocks: string[],
298
- // context: SchematicContext
299
- // ): Promise<string> {
300
- // const angularJsonPath = '/angular.json';
301
- // const buffer = tree.read(angularJsonPath);
302
-
303
- // if (!buffer) {
304
- // context.logger.error('❌ angular.json not found.');
305
- // throw new Error('angular.json not found... get good');
306
- // }
307
-
308
- // const angularJson = JSON.parse(buffer.toString());
309
-
310
- // // const project = angularJson.defaultProject;
311
- // // We need to get every project in the workspace
312
- // const projects = Object.keys(angularJson.projects);
313
- // // We will prompt the user to select a project
314
- // const response = await prompt<{ project: string }>({
315
- // type: 'select',
316
- // name: 'project',
317
- // message: 'Select the Angular project to update:',
318
- // choices: projects.map((project) => ({
319
- // name: project,
320
- // message: project,
321
- // })),
322
- // });
323
- // const project = response.project;
324
-
325
- // if (!project || !angularJson.projects[project]) {
326
- // context.logger.error(`❌ Project ${project} not found in angular.json.`);
327
- // throw new Error(`Project ${project} not found in angular.json`);
328
- // }
329
-
330
- // const includePaths =
331
- // angularJson.projects[project].architect.build.options
332
- // .stylePreprocessorOptions?.includePaths || [];
333
-
334
- // includePaths.push('dist/ngx-editor-js2');
335
- // blocks.forEach((block) => {
336
- // const stylePath = optionalBlocks[block].stylePath;
337
- // if (!includePaths.includes(stylePath)) {
338
- // includePaths.push(stylePath);
339
- // }
340
- // });
341
-
342
- // angularJson.projects[
343
- // project
344
- // ].architect.build.options.stylePreprocessorOptions = { includePaths };
345
- // tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
346
-
347
- // context.logger.info('🔧 angular.json updated successfully.');
348
-
349
- // return (
350
- // angularJson.projects[project].sourceRoot ||
351
- // angularJson.projects[project].root
352
- // );
353
- // }
260
+ function getProjectSourceRoot(tree: Tree, projectName: string): string {
261
+ const buffer = tree.read('/angular.json');
262
+ if (!buffer) throw new Error('angular.json not found');
263
+ const workspace = JSON.parse(buffer.toString());
264
+ const project = workspace.projects[projectName];
265
+ if (!project) throw new Error(`Project ${projectName} not found`);
266
+ return project.sourceRoot || 'src';
267
+ }
@@ -1,7 +1,30 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
3
  "$id": "NgAdd",
4
4
  "title": "Ng Add Options",
5
5
  "type": "object",
6
- "properties": {}
6
+ "properties": {
7
+ "blocks": {
8
+ "type": "array",
9
+ "description": "Optional Ngx-Editor-JS2 blocks to install",
10
+ "x-prompt": {
11
+ "message": "Select optional Ngx-Editor-JS2 blocks to install:",
12
+ "type": "list",
13
+ "multiselect": true,
14
+ "items": [
15
+ { "value": "image", "label": "Image" },
16
+ { "value": "popQuiz", "label": "Pop Quiz" },
17
+ { "value": "mermaidjs", "label": "MermaidJS" },
18
+ { "value": "codemirror", "label": "CodeMirror" },
19
+ { "value": "mfeLoader", "label": "MFE Loader" },
20
+ { "value": "blockquotes", "label": "Blockquotes" }
21
+ ]
22
+ }
23
+ },
24
+ "project": {
25
+ "type": "string",
26
+ "description": "The Angular project to update",
27
+ "x-prompt": "Which Angular project would you like to update?"
28
+ }
29
+ }
7
30
  }