create-basicjs 0.1.6 → 0.1.8

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
@@ -10,6 +10,8 @@ npx serve
10
10
 
11
11
  The project has everything in one folder: `index.htm`, your code in `app/`, and the library, components, examples and documents in `_basic/`. `AGENTS.md` and `CLAUDE.md` give the rules to AI coding tools, so you can open the folder in one and describe your app.
12
12
 
13
+ In the folder you are in: `npm create basicjs@latest .` (it must be empty, or hold only `.git` or the skill of an AI tool: `.claude/`, `.agents/`, `skills-lock.json`).
14
+
13
15
  ## Templates
14
16
 
15
17
  ```sh
@@ -4,6 +4,7 @@
4
4
  // npm create basicjs@latest my-app
5
5
  // npm create basicjs@latest my-app -- --template shop
6
6
  // npm create basicjs@latest my-app -- --template tauri (a desktop app: a whole project of its own)
7
+ // npm create basicjs@latest . (here: an empty folder, or one with only a skill of an AI tool or .git)
7
8
  // npx create-basicjs@latest update (in a project: replaces only _basic/)
8
9
 
9
10
  const crypto = require("crypto");
@@ -23,6 +24,7 @@ const HELP = `create-basicjs ${VERSION}
23
24
  npm create basicjs@latest my-app a new project
24
25
  npm create basicjs@latest my-app -- --template shop a project from a template
25
26
  npm create basicjs@latest my-app -- --template tauri a desktop app (Tauri 2 and Rust)
27
+ npm create basicjs@latest . here (an empty folder, or only .git, .claude, .agents)
26
28
  npm create basicjs@latest -- --list the templates
27
29
  npx create-basicjs@latest update in a project: replaces only _basic/
28
30
  `;
@@ -72,46 +74,64 @@ const addTemplate = function (target, name) {
72
74
  fs.cpSync(from, target, { recursive: true, force: true });
73
75
  };
74
76
 
77
+ // The project in the folder of the terminal (npm create basicjs@latest .): no cd
78
+ const cdLine = function (target, folder) {
79
+ return (target === process.cwd()) ? "" : " cd " + folder + "\n";
80
+ };
81
+
75
82
  // A whole project (Ex: tauri): its own files only, no starter under it
76
83
  const createProject = function (folder, target, name) {
77
- fs.cpSync(path.join(PROJECTS, name), target, { recursive: true });
84
+ fs.cpSync(path.join(PROJECTS, name), target, { recursive: true, force: false }); // WHY force: false: its .github/ next to the user's folders
78
85
  // WHY: npm leaves a .gitignore out of a package
79
86
  ["gitignore", path.join("src-tauri", "gitignore")].forEach(function (fileName) {
80
87
  const file = path.join(target, fileName);
81
88
  if (fs.existsSync(file)) fs.renameSync(file, path.join(path.dirname(file), ".gitignore"));
82
89
  });
83
90
  console.log("Ready: " + folder + " (template: " + name + ")");
84
- console.log("\n cd " + folder + "\n cargo tauri dev\n");
91
+ console.log("\n" + cdLine(target, folder) + " cargo tauri dev\n");
85
92
  console.log("It needs Rust and the Tauri CLI once: README.md, \"What you need\". The rules for an AI coding tool: AGENTS.md");
86
93
  };
87
94
 
95
+ // WHY: an AI coding tool's skill (npx skills add: .agents/, .claude/, skills-lock.json) or a git folder comes before
96
+ // the project; with them the project goes into the same folder. Only folders: a file of the user is never replaced.
97
+ const isNotContent = function (entry) {
98
+ if (entry.isDirectory()) return entry.name.startsWith(".");
99
+ return entry.name === "skills-lock.json" || entry.name === ".DS_Store";
100
+ };
101
+
102
+ const isEmptyFolder = function (target) {
103
+ if (!fs.existsSync(target)) return true;
104
+ return fs.readdirSync(target, { withFileTypes: true }).every(isNotContent);
105
+ };
106
+
88
107
  const create = function (options) {
89
108
  const folder = options.folder || DEFAULT_FOLDER;
90
109
  const target = path.resolve(folder);
91
- if (fs.existsSync(target) && fs.readdirSync(target).length) stop(folder + " is not empty: choose another folder.");
110
+ if (!isEmptyFolder(target)) stop(folder + " is not empty: choose another folder.");
92
111
  if (options.template && fs.existsSync(path.join(PROJECTS, options.template))) {
93
112
  createProject(folder, target, options.template);
94
113
  return;
95
114
  }
96
115
 
97
- fs.cpSync(STARTER, target, { recursive: true });
116
+ fs.cpSync(STARTER, target, { recursive: true, force: false });
98
117
  fs.renameSync(path.join(target, "gitignore"), path.join(target, ".gitignore")); // WHY: npm leaves a .gitignore out of a package
99
118
  fs.mkdirSync(path.join(target, "assets"), { recursive: true });
100
119
  if (options.template) addTemplate(target, options.template);
101
120
  useProjectName(target, path.basename(target));
102
121
 
103
122
  console.log("Ready: " + folder + (options.template ? " (template: " + options.template + ")" : ""));
104
- console.log("\n cd " + folder + "\n npx serve\n");
123
+ console.log("\n" + cdLine(target, folder) + " npx serve\n");
105
124
  console.log("Open the folder in an AI coding tool and describe your app. To publish: node _basic/tools/build.js");
106
125
  };
107
126
 
108
- // The AGENTS.md of the published versions (0.1.1 - 0.1.4), as a new project got it (sha256).
127
+ // The AGENTS.md of the published versions (0.1.1 - 0.1.7), as a new project got it (sha256).
109
128
  // WHY: an update replaced only _basic/, so an AGENTS.md nobody changed kept the names of an older kit
110
129
  // (styleName: "primary", ozdenType1, AutoLayout) next to a _basic/ that has them no more.
111
130
  const OLD_AGENTS_HASHES = [
112
131
  "2898b4e7a3e2b04754073f611bf26c13e8b2e5685c50582f10d1ae1f066ff8ba",
113
132
  "ad7764b34b6f3e8d33fd89b2b0238102ff78e5613916e2fe1e3d999efd64c6e0",
114
133
  "3092379ec5e7219f20dc64b6a69ac688c06b79d8c46d966977a2706d637b6811",
134
+ "95a7df2cb361b96743b0817cd27024b6a7bc04f32c74e2ccc39da8ddd3370d56", // 0.1.5 - 0.1.7
115
135
  ];
116
136
 
117
137
  const hashOf = function (text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-basicjs",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Create a project with basic.js and OzdenUI, ready to build with AI tools.",
5
5
  "bin": {
6
6
  "create-basicjs": "bin/create-basicjs.js"
@@ -28,6 +28,17 @@ Add a `<script>` line to `index.htm` for the component and for every file in its
28
28
 
29
29
  Pages load the source files (`name.js`). Components have no `.min.js` files.
30
30
 
31
+ ## A component that lacks something
32
+
33
+ First look in the header of `_basic/comp/name.js`: a param, an event (Ex: `onCellCreate`) or a `style` key may do it already. When none does, make your own version of the component, and add the feature there:
34
+
35
+ 1. Copy `_basic/comp/tiny-table.js` to `app/comp/tiny-table-plus.js` (a name that says what it adds).
36
+ 2. In the copy, replace the name everywhere: `TinyTable` → `TinyTablePlus` (this also renames `TinyTableDefaults` and `TinyTable.styles`).
37
+ 3. In `index.htm`, load the copy instead of the original, after the files it needs.
38
+ 4. Change the copy, and use `TinyTablePlus` in the app.
39
+
40
+ Never change the file in `_basic/`: an update replaces it. Your copy keeps working after an update, but it does not get its fixes: change only what the feature needs.
41
+
31
42
  ## Rules that are easy to miss
32
43
 
33
44
  - `const start = function () {}` is the entry point. basic.js creates the global `page` and then calls it. `loop()` runs every second when it exists.
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.8
@@ -73,16 +73,24 @@ const PhoneField = function(params = {}) {
73
73
  return box.countryCode + box.phoneMask;
74
74
  };
75
75
 
76
- // The cursor goes to the first empty digit (the first "_"), or to the end when the number is full.
76
+ // The place of the first empty digit (the first "_"), or the end when the number is full.
77
+ const getFirstEmptyDigitPos = function() {
78
+ const firstUnderscore = inputElem.value.indexOf("_");
79
+ return (firstUnderscore !== -1) ? firstUnderscore : inputElem.value.length;
80
+ };
81
+
82
+ // The cursor goes to the first empty digit.
77
83
  const setCursorToFirstUnderscore = function() {
78
84
  if (!inputElem) return;
79
- const firstUnderscore = inputElem.value.indexOf("_");
80
- if (inputElem.selectionStart === firstUnderscore) return;
85
+ if (inputElem.selectionStart === inputElem.value.indexOf("_")) return;
81
86
 
82
- const cursorPos = (firstUnderscore !== -1) ? firstUnderscore : inputElem.value.length;
87
+ const cursorPos = getFirstEmptyDigitPos();
83
88
  inputElem.setSelectionRange(cursorPos, cursorPos); // WHY: the caret must not jump to the end first.
84
89
  box.after(0, () => {
85
- inputElem.setSelectionRange(cursorPos, cursorPos); // WHY: this moves the caret (after the browser moved it).
90
+ // WHY the place again, not cursorPos: on a slow computer a key typed before this timer moved the first "_",
91
+ // and the old place put the next digit in the middle ("5550102030" became "+1 (535) 501-0200")
92
+ const cursorPosNow = getFirstEmptyDigitPos();
93
+ inputElem.setSelectionRange(cursorPosNow, cursorPosNow); // WHY: this moves the caret (after the browser moved it).
86
94
  });
87
95
  };
88
96
 
@@ -1,2 +1,2 @@
1
1
  /* Bismillah */
2
- "use strict";const PhoneFieldDefaults={required:1,titleText:"PHONE NUMBER",placeholder:"(auto)",warningText:"Invalid phone number format",warningColor:"#E5885E",countryCode:"+90",phoneMask:" (___) ___-____",unitText:"TR"},PhoneField=function(e={}){basic.applyStylePackage(e,TextField.styles,TextFieldDefaults),mergeIntoIfMissing(e,PhoneFieldDefaults),0==e.createInput&&(e.createInput=1);const t=startExtendedObject(TextField,e),n=t.input.inputElement;let u=t.countryCode;const o=function(){return t.countryCode+t.phoneMask},i=function(){if(!n)return;const e=n.value.indexOf("_");if(n.selectionStart===e)return;const u=-1!==e?e:n.value.length;n.setSelectionRange(u,u),t.after(0,()=>{n.setSelectionRange(u,u)})},r=function(e){const n=[u,t.countryCode].filter(function(t){return"string"==typeof t&&t.length>0&&0===e.indexOf(t)});return n.sort(function(e,t){return t.length-e.length}),n.length?e.substring(n[0].length):e},l=function(e,t){let n=0,u="";for(let o=0;o<e.length;o++)"_"===e[o]?n<t.length?(u+=t[n],n++):u+="_":u+=e[o];return u},a=function(e){let n=String(e).replace(/[^0-9]/g,"");const u=(t.phoneMask.match(/_/g)||[]).length,o=String(t.countryCode||"").replace(/[^0-9]/g,"");return n.length>u&&o&&0===n.indexOf("00"+o)&&(n=n.substring(2+o.length)),n.length>u&&o&&0===n.indexOf(o)&&(n=n.substring(o.length)),n.length>u&&"0"===n[0]&&(n=n.substring(1)),n.substring(0,u)},c=t.setValue;if(t.applyFormattedValueToInput=function(){let e=r(n.value).replace(/[^0-9]/g,"");const a=(t.phoneMask.match(/_/g)||[]).length;e=e.substring(0,a),c(l(o(),e)),u=t.countryCode,i()},t.setValue=function(e){const n=String(e??"");""!==n?(c(l(o(),a(r(n)))),u=t.countryCode):c("")},t.setPhoneMask=function(e){t.phoneMask=e,t.refreshInput()},t.setCountryCode=function(e){t.countryCode=e,t.refreshInput()},t.getValue=function(){const e=t.input.text;return e===o()?"":e},t.isValid=function(){const e=t.getValue();return e&&-1===e.indexOf("_")?1:0},t.refreshInput=function(){t.applyFormattedValueToInput(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),i(),t.value=n.value},t.fillAutoPlaceholder=function(){t.setPlaceholder(t.countryCode+t.phoneMask.replace(/_/g,()=>Math.floor(10*Math.random())))},"(auto)"==t.placeholder&&t.fillAutoPlaceholder(),1==t.createInput){t.focusFunc=function(){t.paintFocus(1),""===n.value.trim()&&(n.value=o()),i(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onFocus(t)},t.blurFunc=function(){t.paintFocus(0),n.value==o()&&t.setValue(""),t.onBlur(t)};["mousedown","mouseup","click","select"].forEach(function(e){n.addEventListener(e,function(){i()})}),n.addEventListener("keydown",function(e){"Backspace"===e.key&&function(e){const u=n.selectionStart,r=n.value,l=o();if(u<=l.indexOf("_"))return e.preventDefault(),void i();const a=r.slice(0,u),c=r.slice(u);let s=a.length-1;for(;s>=0&&"_"!==l[s];)s--;s>=0&&(n.value=a.substring(0,s)+"_"+a.substring(s+1)+c),e.preventDefault(),i(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onChange(t)}(e)}),n.addEventListener("paste",function(e){const n=e.clipboardData?e.clipboardData.getData("text"):"";n&&(e.preventDefault(),c(l(o(),a(n))),i(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onChange(t))}),t.inputFunc=function(){t.refreshInput(),t.onChange(t)}}return""!==n.value&&t.setValue(n.value),t.checkInputValue(),endExtendedObject(t)};
2
+ "use strict";const PhoneFieldDefaults={required:1,titleText:"PHONE NUMBER",placeholder:"(auto)",warningText:"Invalid phone number format",warningColor:"#E5885E",countryCode:"+90",phoneMask:" (___) ___-____",unitText:"TR"},PhoneField=function(e={}){basic.applyStylePackage(e,TextField.styles,TextFieldDefaults),mergeIntoIfMissing(e,PhoneFieldDefaults),0==e.createInput&&(e.createInput=1);const t=startExtendedObject(TextField,e),n=t.input.inputElement;let u=t.countryCode;const o=function(){return t.countryCode+t.phoneMask},i=function(){const e=n.value.indexOf("_");return-1!==e?e:n.value.length},r=function(){if(!n)return;if(n.selectionStart===n.value.indexOf("_"))return;const e=i();n.setSelectionRange(e,e),t.after(0,()=>{const e=i();n.setSelectionRange(e,e)})},l=function(e){const n=[u,t.countryCode].filter(function(t){return"string"==typeof t&&t.length>0&&0===e.indexOf(t)});return n.sort(function(e,t){return t.length-e.length}),n.length?e.substring(n[0].length):e},a=function(e,t){let n=0,u="";for(let o=0;o<e.length;o++)"_"===e[o]?n<t.length?(u+=t[n],n++):u+="_":u+=e[o];return u},c=function(e){let n=String(e).replace(/[^0-9]/g,"");const u=(t.phoneMask.match(/_/g)||[]).length,o=String(t.countryCode||"").replace(/[^0-9]/g,"");return n.length>u&&o&&0===n.indexOf("00"+o)&&(n=n.substring(2+o.length)),n.length>u&&o&&0===n.indexOf(o)&&(n=n.substring(o.length)),n.length>u&&"0"===n[0]&&(n=n.substring(1)),n.substring(0,u)},s=t.setValue;if(t.applyFormattedValueToInput=function(){let e=l(n.value).replace(/[^0-9]/g,"");const i=(t.phoneMask.match(/_/g)||[]).length;e=e.substring(0,i),s(a(o(),e)),u=t.countryCode,r()},t.setValue=function(e){const n=String(e??"");""!==n?(s(a(o(),c(l(n)))),u=t.countryCode):s("")},t.setPhoneMask=function(e){t.phoneMask=e,t.refreshInput()},t.setCountryCode=function(e){t.countryCode=e,t.refreshInput()},t.getValue=function(){const e=t.input.text;return e===o()?"":e},t.isValid=function(){const e=t.getValue();return e&&-1===e.indexOf("_")?1:0},t.refreshInput=function(){t.applyFormattedValueToInput(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),r(),t.value=n.value},t.fillAutoPlaceholder=function(){t.setPlaceholder(t.countryCode+t.phoneMask.replace(/_/g,()=>Math.floor(10*Math.random())))},"(auto)"==t.placeholder&&t.fillAutoPlaceholder(),1==t.createInput){t.focusFunc=function(){t.paintFocus(1),""===n.value.trim()&&(n.value=o()),r(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onFocus(t)},t.blurFunc=function(){t.paintFocus(0),n.value==o()&&t.setValue(""),t.onBlur(t)};["mousedown","mouseup","click","select"].forEach(function(e){n.addEventListener(e,function(){r()})}),n.addEventListener("keydown",function(e){"Backspace"===e.key&&function(e){const u=n.selectionStart,i=n.value,l=o();if(u<=l.indexOf("_"))return e.preventDefault(),void r();const a=i.slice(0,u),c=i.slice(u);let s=a.length-1;for(;s>=0&&"_"!==l[s];)s--;s>=0&&(n.value=a.substring(0,s)+"_"+a.substring(s+1)+c),e.preventDefault(),r(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onChange(t)}(e)}),n.addEventListener("paste",function(e){const n=e.clipboardData?e.clipboardData.getData("text"):"";n&&(e.preventDefault(),s(a(o(),c(n))),r(),t.checkIfInputIsRequiredAndEmpty(),t.showWarningIfNotValid(t.isValid()),t.onChange(t))}),t.inputFunc=function(){t.refreshInput(),t.onChange(t)}}return""!==n.value&&t.setValue(n.value),t.checkInputValue(),endExtendedObject(t)};
@@ -86,7 +86,18 @@ const PAGE_CHECK = function () {
86
86
  return false;
87
87
  };
88
88
 
89
- const checkCut = function (elem, rect) {
89
+ // WHY: an input is taller than its line of text, and a field moves it a few px to center the letters (SearchInput:
90
+ // 2 px up): the empty part above or under the text is not cut, the text is what must be seen.
91
+ const textLineOf = function (elem, rect) {
92
+ if (elem.tagName !== "INPUT") return rect;
93
+ const style = getComputedStyle(elem);
94
+ const lineHeight = Math.min(rect.height, parseFloat(style.lineHeight) || parseFloat(style.fontSize) * 1.3);
95
+ const middle = rect.top + rect.height / 2;
96
+ return { left: rect.left, right: rect.right, top: middle - lineHeight / 2, bottom: middle + lineHeight / 2 };
97
+ };
98
+
99
+ const checkCut = function (elem, elemRect) {
100
+ const rect = textLineOf(elem, elemRect);
90
101
  const hasEllipsis = (getComputedStyle(elem).textOverflow === "ellipsis");
91
102
  for (let item = elem.parentElement; item && item !== document.documentElement; item = item.parentElement) {
92
103
  const style = getComputedStyle(item);
@@ -98,7 +109,7 @@ const PAGE_CHECK = function () {
98
109
  if (isOutside) return; // A closed part: a panel that slides, a tab that is not shown
99
110
  const isCut = (rect.left < box.left - 1 || rect.right > box.right + 1 || rect.top < box.top - 1 || rect.bottom > box.bottom + 1);
100
111
  if (isCut && !hasEllipsis) {
101
- addOnce(report.cut, nameOf(elem) + " is " + Math.round(rect.width) + " x " + Math.round(rect.height) + ", its parent cuts it at " + Math.round(box.width) + " x " + Math.round(box.height));
112
+ addOnce(report.cut, nameOf(elem) + " is " + Math.round(elemRect.width) + " x " + Math.round(elemRect.height) + ", its parent cuts it at " + Math.round(box.width) + " x " + Math.round(box.height));
102
113
  return;
103
114
  }
104
115
  }