@public-ui/kolibri-cli 4.0.0-rc.0 → 4.0.0-rc.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.
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RenameKolEventNamesTasks = exports.RenameKolEventNamesTask = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const types_1 = require("../../../../types");
9
+ const reuse_1 = require("../../../shares/reuse");
10
+ const abstract_task_1 = require("../../abstract-task");
11
+ const EVENT_REPLACEMENTS = {
12
+ kolBlur: 'blur',
13
+ kolChange: 'change',
14
+ kolChangeHeaderCells: 'changeheadercells',
15
+ kolChangePage: 'changepage',
16
+ kolChangePageSize: 'changepagesize',
17
+ kolClick: 'click',
18
+ kolClose: 'close',
19
+ kolCreate: 'create',
20
+ kolFocus: 'focus',
21
+ kolInput: 'input',
22
+ kolKeydown: 'keydown',
23
+ kolMousedown: 'mousedown',
24
+ kolReset: 'reset',
25
+ kolSelect: 'select',
26
+ kolSelectionChange: 'selectionchange',
27
+ kolSort: 'sort',
28
+ kolSubmit: 'submit',
29
+ kolToggle: 'toggle',
30
+ };
31
+ class RenameKolEventNamesTask extends abstract_task_1.AbstractTask {
32
+ constructor(versionRange) {
33
+ super('rename-kol-events', 'Rename kol* DOM events to their native names', [...types_1.FILE_EXTENSIONS], versionRange);
34
+ }
35
+ static getInstance(versionRange) {
36
+ const identifier = `${versionRange}-rename-kol-events`;
37
+ if (!this.instances.has(identifier)) {
38
+ this.instances.set(identifier, new RenameKolEventNamesTask(versionRange));
39
+ }
40
+ return this.instances.get(identifier);
41
+ }
42
+ run(baseDir) {
43
+ (0, reuse_1.filterFilesByExt)(baseDir, this.extensions).forEach((file) => {
44
+ const content = fs_1.default.readFileSync(file, 'utf8');
45
+ const newContent = this.replaceEventNames(content);
46
+ if (content !== newContent) {
47
+ reuse_1.MODIFIED_FILES.add(file);
48
+ fs_1.default.writeFileSync(file, newContent);
49
+ }
50
+ });
51
+ }
52
+ replaceEventNames(content) {
53
+ // Sort by key length descending to ensure longer event names are replaced first
54
+ // This prevents partial replacements (e.g., kolChange before kolChangeHeaderCells)
55
+ const sortedEntries = Object.entries(EVENT_REPLACEMENTS).sort(([keyA], [keyB]) => keyB.length - keyA.length);
56
+ return sortedEntries.reduce((updatedContent, [oldName, newName]) => {
57
+ return this.replaceEventNameInEventContexts(updatedContent, oldName, newName);
58
+ }, content);
59
+ }
60
+ replaceEventNameInEventContexts(content, oldName, newName) {
61
+ let updatedContent = content;
62
+ // Handle addEventListener('kolX', ...)
63
+ const addEventListenerPattern = new RegExp(`(addEventListener\\s*\\(\\s*['"])${oldName}(['"])`, 'g');
64
+ updatedContent = updatedContent.replace(addEventListenerPattern, `$1${newName}$2`);
65
+ // Handle removeEventListener('kolX', ...)
66
+ const removeEventListenerPattern = new RegExp(`(removeEventListener\\s*\\(\\s*['"])${oldName}(['"])`, 'g');
67
+ updatedContent = updatedContent.replace(removeEventListenerPattern, `$1${newName}$2`);
68
+ // Handle new CustomEvent('kolX', ...)
69
+ const customEventPattern = new RegExp(`(new\\s+CustomEvent\\s*\\(\\s*['"])${oldName}(['"])`, 'g');
70
+ updatedContent = updatedContent.replace(customEventPattern, `$1${newName}$2`);
71
+ // Handle assignments and object property values: foo = 'kolX', { event: 'kolX' }
72
+ const assignmentPattern = new RegExp(`([=:]\\s*['"])${oldName}(['"])`, 'g');
73
+ updatedContent = updatedContent.replace(assignmentPattern, `$1${newName}$2`);
74
+ // Handle JSX/TSX event handler props: onKolClick -> onClick, etc.
75
+ const capitalize = (value) => (value.length === 0 ? value : value[0].toUpperCase() + value.slice(1));
76
+ const oldPropName = `on${capitalize(oldName)}`;
77
+ const newPropName = `on${capitalize(newName)}`;
78
+ const jsxPropPattern = new RegExp(`\\b${oldPropName}\\b`, 'g');
79
+ updatedContent = updatedContent.replace(jsxPropPattern, newPropName);
80
+ // Handle simple template literals: `kolX`
81
+ const templateLiteralPattern = new RegExp(`(\`)${oldName}(\`)`, 'g');
82
+ updatedContent = updatedContent.replace(templateLiteralPattern, `$1${newName}$2`);
83
+ const dispatchEventPattern = new RegExp(`(dispatchEvent\\s*\\(\\s*new\\s+Event\\s*\\(\\s*['"])${oldName}(['"])`, 'g');
84
+ updatedContent = updatedContent.replace(dispatchEventPattern, `$1${newName}$2`);
85
+ const koliBriCreatorPattern = new RegExp(`(dispatchEvent\\s*\\(\\s*createKoliBriEvent\\s*\\(\\s*['"])${oldName}(['"])`, 'g');
86
+ updatedContent = updatedContent.replace(koliBriCreatorPattern, `$1${newName}$2`);
87
+ // Handle bare event names at statement boundaries and as function arguments
88
+ // Match: (start of line, whitespace, or parenthesis)eventName(whitespace, comma, semicolon, or end of line)
89
+ // This handles cases like:
90
+ // - kolChange (standalone at end of line)
91
+ // - addEventListener(kolClick, handler)
92
+ // - dispatchEvent(new Event(kolX))
93
+ // Negative lookahead/lookbehind would be better but JavaScript regex support is limited
94
+ // So we match the surrounding context and preserve it
95
+ const bareEventPattern = new RegExp(`(^|[\\s(])${oldName}([\\s,;\\n]|$)`, 'gm');
96
+ updatedContent = updatedContent.replace(bareEventPattern, `$1${newName}$2`);
97
+ return updatedContent;
98
+ }
99
+ }
100
+ exports.RenameKolEventNamesTask = RenameKolEventNamesTask;
101
+ const renameKolEventNamesTaskInstance = RenameKolEventNamesTask.getInstance('^4');
102
+ exports.RenameKolEventNamesTasks = [renameKolEventNamesTaskInstance];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.v4Tasks = void 0;
4
4
  const clear_button_1 = require("./clear-button");
5
+ const events_1 = require("./events");
5
6
  const focus_1 = require("./focus");
6
7
  const id_1 = require("./id");
7
8
  const link_1 = require("./link");
@@ -17,6 +18,7 @@ exports.v4Tasks.push(...msg_1.RemoveMsgPropsTasks);
17
18
  exports.v4Tasks.push(...clear_button_1.RenameClearButtonPropTasks);
18
19
  exports.v4Tasks.push(focus_1.RenameKolFocusMethodsTask.getInstance('^4'));
19
20
  exports.v4Tasks.push(modal_1.RenameTagNameKolModalToKolDialog);
21
+ exports.v4Tasks.push(...events_1.RenameKolEventNamesTasks);
20
22
  exports.v4Tasks.push(toast_1.RemoveToastVariantTask.getInstance('^4'));
21
23
  exports.v4Tasks.push(toaster_1.RemoveToasterGetInstanceOptionsTask.getInstance('^4'));
22
24
  exports.v4Tasks.push(loader_1.UpdateLoaderImportPathTask.getInstance('^4'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@public-ui/kolibri-cli",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.0-rc.1",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": {
@@ -29,7 +29,8 @@
29
29
  "prettier": "3.7.4",
30
30
  "prettier-plugin-organize-imports": "4.3.0",
31
31
  "semver": "7.7.3",
32
- "typed-bem": "1.0.2"
32
+ "typed-bem": "1.0.2",
33
+ "@public-ui/components": "4.0.0-rc.1"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/node": "24.10.4",
@@ -43,13 +44,15 @@
43
44
  "eslint-plugin-json": "3.1.0",
44
45
  "eslint-plugin-jsx-a11y": "6.10.2",
45
46
  "eslint-plugin-react": "7.37.5",
46
- "knip": "5.73.4",
47
+ "knip": "5.80.0",
47
48
  "mocha": "11.7.5",
48
49
  "nodemon": "3.1.11",
49
50
  "rimraf": "6.1.2",
50
51
  "ts-node": "10.9.2",
51
- "typescript": "5.9.3",
52
- "@public-ui/components": "4.0.0-rc.0"
52
+ "typescript": "5.9.3"
53
+ },
54
+ "engines": {
55
+ "node": ">=22"
53
56
  },
54
57
  "files": [
55
58
  "dist"