@rettangoli/fe 0.0.9 → 0.0.11

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": "@rettangoli/fe",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Frontend framework for building reactive web components",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli/build.js CHANGED
@@ -8,8 +8,9 @@ import {
8
8
  import esbuild from "esbuild";
9
9
  import { load as loadYaml } from "js-yaml";
10
10
  import { parse } from 'jempl';
11
- import { extractCategoryAndComponent } from '../common.js';
11
+ import { extractCategoryAndComponent } from '../commonBuild.js';
12
12
  import { getAllFiles } from '../commonBuild.js';
13
+ import path from "node:path";
13
14
 
14
15
  function capitalize(word) {
15
16
  return word ? word[0].toUpperCase() + word.slice(1) : word;
@@ -18,13 +19,12 @@ function capitalize(word) {
18
19
  // Function to process view files - loads YAML and creates temporary JS file
19
20
  export const writeViewFile = (view, category, component) => {
20
21
  // const { category, component } = extractCategoryAndComponent(filePath);
21
-
22
- const dir = `./.temp/${category}`;
22
+ const dir = path.join(".temp", category);
23
23
  if (!existsSync(dir)) {
24
24
  mkdirSync(dir, { recursive: true });
25
25
  }
26
26
  writeFileSync(
27
- `${dir}/${component}.view.js`,
27
+ path.join(dir, `${component}.view.js`),
28
28
  `export default ${JSON.stringify(view)};`,
29
29
  );
30
30
  };
@@ -41,6 +41,7 @@ export const bundleFile = async (options) => {
41
41
  loader: {
42
42
  ".wasm": "binary",
43
43
  },
44
+ platform: "browser",
44
45
  });
45
46
  };
46
47
 
@@ -83,10 +84,11 @@ const buildRettangoliFrontend = async (options) => {
83
84
  categories.push(category);
84
85
  }
85
86
 
87
+
86
88
  if (["handlers", "store"].includes(fileType)) {
87
89
  output += `import * as ${component}${capitalize(
88
90
  fileType,
89
- )} from '../${filePath}';\n`;
91
+ )} from '../${filePath.replaceAll(path.sep, "/")}';\n`;
90
92
 
91
93
  replaceMap[count] = `${component}${capitalize(fileType)}`;
92
94
  imports[category][component][fileType] = count;
@@ -4,9 +4,9 @@ import { load as loadYaml, loadAll } from "js-yaml";
4
4
  import { render, parse } from "jempl";
5
5
 
6
6
  import {
7
- extractCategoryAndComponent,
8
7
  flattenArrays,
9
8
  } from "../common.js";
9
+ import { extractCategoryAndComponent } from "../commonBuild.js";
10
10
  import { getAllFiles } from "../commonBuild.js";
11
11
  import path, { dirname } from "node:path";
12
12
 
package/src/cli/watch.js CHANGED
@@ -5,7 +5,7 @@ import { load as loadYaml } from "js-yaml";
5
5
  import { createServer } from 'vite'
6
6
  import { writeViewFile } from './build.js';
7
7
  import buildRettangoliFrontend from './build.js';
8
- import { extractCategoryAndComponent } from '../common.js';
8
+ import { extractCategoryAndComponent } from '../commonBuild.js';
9
9
 
10
10
  // Debounce mechanism to prevent excessive rebuilds
11
11
  let rebuildTimeout = null;
package/src/common.js CHANGED
@@ -165,13 +165,7 @@ export function createHttpClient(config) {
165
165
  }
166
166
 
167
167
 
168
- export const extractCategoryAndComponent = (filePath) => {
169
- const parts = filePath.split("/");
170
- const component = parts[parts.length - 1].split(".")[0];
171
- const category = parts[parts.length - 3];
172
- const fileType = parts[parts.length - 1].split(".")[1];
173
- return { category, component, fileType };
174
- }
168
+
175
169
 
176
170
 
177
171
 
@@ -2,7 +2,7 @@
2
2
  import { readdirSync, statSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
 
5
-
5
+ import { sep } from 'node:path';
6
6
  // Function to recursively get all files in a directory
7
7
  export function getAllFiles(dirPaths, arrayOfFiles = []) {
8
8
  dirPaths.forEach((dirPath) => {
@@ -19,4 +19,12 @@ export function getAllFiles(dirPaths, arrayOfFiles = []) {
19
19
  });
20
20
 
21
21
  return arrayOfFiles;
22
+ }
23
+
24
+ export const extractCategoryAndComponent = (filePath) => {
25
+ const parts = filePath.split(sep);
26
+ const component = parts[parts.length - 1].split(".")[0];
27
+ const category = parts[parts.length - 3];
28
+ const fileType = parts[parts.length - 1].split(".")[1];
29
+ return { category, component, fileType };
22
30
  }
@@ -365,10 +365,6 @@ class BaseComponent extends HTMLElement {
365
365
  if (oldValue !== newValue && this.render) {
366
366
  // Call handleOnUpdate if it exists
367
367
  if (this.handlers?.handleOnUpdate) {
368
- const changes = {
369
- oldAttrs: { [name]: oldValue },
370
- newAttrs: { [name]: newValue }
371
- };
372
368
  const deps = {
373
369
  ...this.deps,
374
370
  refIds: this.refIds,
@@ -377,7 +373,13 @@ class BaseComponent extends HTMLElement {
377
373
  store: this.store,
378
374
  render: this.render.bind(this),
379
375
  };
380
- this.handlers.handleOnUpdate(changes, deps);
376
+ const changes = {
377
+ oldAttrs: { [name]: oldValue },
378
+ newAttrs: { [name]: newValue },
379
+ oldProps: deps.props,
380
+ newProps: deps.props,
381
+ };
382
+ this.handlers.handleOnUpdate(deps, changes);
381
383
  } else {
382
384
  requestAnimationFrame(() => {
383
385
  this.render();
package/src/parser.js CHANGED
@@ -428,7 +428,7 @@ export const createVirtualDom = ({
428
428
  // Call the specific component's handleOnUpdate instead of the parent's onUpdate
429
429
  if (element.handlers && element.handlers.handleOnUpdate) {
430
430
  const deps = {
431
- ...(element.deps || {}),
431
+ ...(element.deps),
432
432
  store: element.store,
433
433
  render: element.render.bind(element),
434
434
  handlers: element.handlers,
@@ -436,12 +436,12 @@ export const createVirtualDom = ({
436
436
  refIds: element.refIds || {},
437
437
  getRefIds: () => element.refIds || {},
438
438
  };
439
- element.handlers.handleOnUpdate({
439
+ element.handlers.handleOnUpdate(deps, {
440
440
  oldProps,
441
441
  newProps,
442
442
  oldAttrs,
443
443
  newAttrs,
444
- }, deps);
444
+ });
445
445
  }
446
446
  });
447
447
  }