coralite 0.27.0 → 0.28.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
@@ -32,20 +32,12 @@ Before using the Coralite CLI, ensure that it's installed on your system. You ca
32
32
 
33
33
  ```bash
34
34
  npm install -g coralite
35
- # or
36
- yarn global add coralite
37
- # or
38
- pnpm add -g coralite
39
35
  ```
40
36
 
41
37
  You can also install coralite as a development dependency:
42
38
 
43
39
  ```bash
44
40
  npm install --save-dev coralite
45
- # or
46
- yarn add -D coralite
47
- # or
48
- pnpm add -D coralite
49
41
  ```
50
42
 
51
43
  ## Basic Syntax
@@ -64,14 +56,14 @@ Replace `[options]` with the desired flags and arguments.
64
56
 
65
57
  To generate a website using Coralite, you must provide three essential options:
66
58
 
67
- - **-t or --templates**: The path to your templates directory containing reusable UI elements (e.g., `-t src/templates`).
59
+ - **-t or --components**: The path to your components directory containing reusable UI elements (e.g., `-t src/components`).
68
60
  - **-p or --pages**: The path to your pages directory where static HTML files reside (e.g., `-p src/pages`).
69
61
  - **--output or -o**: The output directory for the generated site (e.g., `--output dist`).
70
62
 
71
63
  Here's an example of how these options might look:
72
64
 
73
65
  ```bash
74
- coralite --templates path/to/templates --pages path/to/pages --output dist
66
+ coralite --components path/to/components --pages path/to/pages --output dist
75
67
  ```
76
68
 
77
69
  ## Optional Options
@@ -81,5 +73,5 @@ coralite --templates path/to/templates --pages path/to/pages --output dist
81
73
  Run the CLI in dry-run mode to preview the actions that would be performed without actually generating the website. This is useful for debugging or when you want to check potential issues before committing changes:
82
74
 
83
75
  ```bash
84
- coralite --templates path/to/templates --pages path/to/pages --output dist --dry-run
76
+ coralite --components path/to/components --pages path/to/pages --output dist --dry-run
85
77
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AAEH;;;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B;+BAxBxB,iBAAiB;oCAkBtB,mBAAmB;0CAAnB,mBAAmB;qCAAnB,mBAAmB;sCAAnB,mBAAmB;oCAAnB,mBAAmB"}
package/dist/lib/index.js CHANGED
@@ -6615,6 +6615,18 @@ function findAndExtractScript(code) {
6615
6615
  if (node.callee && node.callee.type === "Identifier" && node.callee.name === "defineComponent") {
6616
6616
  const firstArg = node.arguments[0];
6617
6617
  if (firstArg && firstArg.type === "ObjectExpression") {
6618
+ const tokensProp = firstArg.properties.find(
6619
+ (prop) => prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "tokens"
6620
+ );
6621
+ let tokens = [];
6622
+ if (tokensProp && tokensProp.type === "Property" && tokensProp.value.type === "ObjectExpression") {
6623
+ tokens = tokensProp.value.properties.map((p) => {
6624
+ if (p.type === "Property") {
6625
+ return p.key.type === "Identifier" ? p.key.name : p.key.type === "Literal" ? p.key.value : void 0;
6626
+ }
6627
+ return void 0;
6628
+ }).filter(Boolean);
6629
+ }
6618
6630
  const clientProp = firstArg.properties.find(
6619
6631
  (prop) => prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "client"
6620
6632
  );
@@ -6733,6 +6745,15 @@ function findAndExtractScript(code) {
6733
6745
  result.setupContent = setupContent;
6734
6746
  }
6735
6747
  }
6748
+ if (result && tokens.length > 0) {
6749
+ result.tokens = tokens;
6750
+ }
6751
+ } else if (tokens.length > 0) {
6752
+ result = {
6753
+ content: "export default function(){}",
6754
+ lineOffset: 0,
6755
+ tokens
6756
+ };
6736
6757
  }
6737
6758
  }
6738
6759
  }
@@ -9438,11 +9459,14 @@ ScriptManager.prototype.compileStandaloneComponent = async function(componentId,
9438
9459
  if (parts.length > 0) {
9439
9460
  const importStr = parts.join(", ");
9440
9461
  entryCodeParts.push(`import ${importStr} from ${specifier}${attributesString};
9462
+ `);
9463
+ } else if (!importDefinition.namespaceExport) {
9464
+ entryCodeParts.push(`import ${specifier}${attributesString};
9441
9465
  `);
9442
9466
  }
9443
9467
  }
9444
9468
  }
9445
- const importsObjContent = Object.keys(importMap).length > 0 ? `const componentImports = { ${Object.entries(importMap).map(([key, value]) => `${key}: ${value}`).join(", ")} };` : "const componentImports = {};";
9469
+ const importsObjContent = Object.keys(importMap).length > 0 ? `const componentImports = { ${Object.entries(importMap).map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const componentImports = {};";
9446
9470
  entryCodeParts.push(importsObjContent + "\n");
9447
9471
  entryCodeParts.push(`
9448
9472
  function kebabToCamel(str) {
@@ -9534,13 +9558,68 @@ function cleanKeys(object) {
9534
9558
  `);
9535
9559
  entryCodeParts.push(`
9536
9560
  class ${componentId.replace(/[-.:]/g, "_")} extends HTMLElement {
9561
+ static get observedAttributes() {
9562
+ return ${JSON.stringify(scriptContent?.tokens || [])};
9563
+ }
9564
+
9537
9565
  constructor() {
9538
9566
  super();
9539
9567
  this.attachShadow({ mode: 'open' });
9568
+ this._initialized = false;
9569
+ }
9570
+
9571
+ attributeChangedCallback(name, oldValue, newValue) {
9572
+ if (oldValue !== newValue) {
9573
+ if (this._context && this._context.values) {
9574
+ this._context.values[name] = newValue;
9575
+ }
9576
+ this.updateDOM(name, newValue);
9577
+ }
9578
+ }
9579
+
9580
+ updateDOM(name, newValue) {
9581
+ if (!this.shadowRoot) return;
9582
+
9583
+ // Find text nodes that contain the token mapping
9584
+ const walker = document.createTreeWalker(this.shadowRoot, NodeFilter.SHOW_TEXT, null, false);
9585
+ let node;
9586
+ const tokenStr = \`{{ \${name} }}\`;
9587
+
9588
+ while ((node = walker.nextNode())) {
9589
+ // Check if original data or textContent contains the token map
9590
+ if (node._coraliteTokens && node._coraliteTokens.includes(name)) {
9591
+ // We know this text node holds the value, let's re-render its text based on current context
9592
+ let newText = node._coraliteOriginalText;
9593
+ for (const token of node._coraliteTokens) {
9594
+ newText = newText.split(\`{{ \${token} }}\`).join(this._context.values[token] !== undefined ? this._context.values[token] : '');
9595
+ }
9596
+ node.nodeValue = newText;
9597
+ node.nodeValue = newText;
9598
+ }
9599
+ }
9600
+
9601
+ // Also update attributes that might have bindings
9602
+ const elements = this.shadowRoot.querySelectorAll('*');
9603
+ for (const el of elements) {
9604
+ if (el._coraliteAttrs) {
9605
+ for (const [attrName, originalValue] of Object.entries(el._coraliteAttrs)) {
9606
+ if (originalValue.includes(tokenStr)) {
9607
+ let newAttrValue = originalValue;
9608
+ // replace all tokens in this attribute
9609
+ const tokenMatches = originalValue.match(/\\{\\{([^}]+)\\}\\}/g) || [];
9610
+ for (const match of tokenMatches) {
9611
+ const tokenKey = match.replace(/\\{|\\}/g, '').trim();
9612
+ newAttrValue = newAttrValue.split(match).join(this._context.values[tokenKey] !== undefined ? this._context.values[tokenKey] : '');
9613
+ }
9614
+ el.setAttribute(attrName, newAttrValue);
9615
+ }
9616
+ }
9617
+ }
9618
+ }
9540
9619
  }
9541
9620
 
9542
9621
  async connectedCallback() {
9543
- // 1. Map DOM Attributes to values
9622
+ // Map DOM Attributes to values
9544
9623
  const domAttributes = {};
9545
9624
  for (let i = 0; i < this.attributes.length; i++) {
9546
9625
  const attribute = this.attributes[i];
@@ -9548,17 +9627,18 @@ class ${componentId.replace(/[-.:]/g, "_")} extends HTMLElement {
9548
9627
  }
9549
9628
  const initialValues = cleanKeys(domAttributes);
9550
9629
 
9551
- // 2. Hydrate Refs
9630
+ // Hydrate Refs
9552
9631
  const refs = {};
9553
9632
 
9554
- // 3. Setup context
9555
- const context = {
9633
+ // Setup context
9634
+ this._context = {
9556
9635
  instanceId: this.id || Math.random().toString(36).substr(2, 9),
9557
9636
  componentId: "${componentId}",
9558
9637
  values: initialValues,
9559
9638
  root: this.shadowRoot,
9560
9639
  imports: componentImports // Standalone imports are bundled within the component
9561
9640
  };
9641
+ const context = this._context;
9562
9642
 
9563
9643
  const setupValues = await getSetups(context);
9564
9644
  context.values = { ...context.values, ...setupValues };
@@ -9567,18 +9647,51 @@ class ${componentId.replace(/[-.:]/g, "_")} extends HTMLElement {
9567
9647
  let htmlPayload = \`${htmlPayload.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
9568
9648
  const cssPayload = \`${cssPayload.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
9569
9649
 
9570
- // Replace text tokens in the payload (rudimentary support for standalone components without the full AST engine)
9571
- for (const [key, value] of Object.entries(context.values)) {
9572
- const token = \`{{ \${key} }}\`;
9573
- htmlPayload = htmlPayload.split(token).join(value);
9574
- }
9575
-
9576
9650
  let styles = '';
9577
9651
  if (cssPayload) {
9578
9652
  styles = \`<style>\${cssPayload}</style>\`;
9579
9653
  }
9654
+
9655
+ // Set raw HTML first before token replacement to preserve slots structure
9580
9656
  this.shadowRoot.innerHTML = styles + htmlPayload;
9581
9657
 
9658
+ // Extract tokens mapped to DOM nodes for reactivity
9659
+ const walker = document.createTreeWalker(this.shadowRoot, NodeFilter.SHOW_TEXT, null, false);
9660
+ let node;
9661
+ while ((node = walker.nextNode())) {
9662
+ const text = node.textContent || '';
9663
+ const tokens = (text.match(/\\{\\{([^}]+)\\}\\}/g) || []).map(t => t.replace(/\\{|\\}/g, '').trim());
9664
+
9665
+ if (tokens.length > 0) {
9666
+ node._coraliteTokens = tokens;
9667
+ node._coraliteOriginalText = text;
9668
+
9669
+ let newText = text;
9670
+ for (const token of tokens) {
9671
+ newText = newText.split(\`{{ \${token} }}\`).join(context.values[token] !== undefined ? context.values[token] : '');
9672
+ }
9673
+ node.nodeValue = newText;
9674
+ }
9675
+ }
9676
+
9677
+ // Attribute reactivity
9678
+ const allElements = this.shadowRoot.querySelectorAll('*');
9679
+ for (const el of allElements) {
9680
+ for (const attr of el.attributes) {
9681
+ if (attr.value.includes('{{')) {
9682
+ if (!el._coraliteAttrs) el._coraliteAttrs = {};
9683
+ el._coraliteAttrs[attr.name] = attr.value;
9684
+
9685
+ let newAttrValue = attr.value;
9686
+ const tokens = (attr.value.match(/\\{\\{([^}]+)\\}\\}/g) || []).map(t => t.replace(/\\{|\\}/g, '').trim());
9687
+ for (const token of tokens) {
9688
+ newAttrValue = newAttrValue.split(\`{{ \${token} }}\`).join(context.values[token] !== undefined ? context.values[token] : '');
9689
+ }
9690
+ el.setAttribute(attr.name, newAttrValue);
9691
+ }
9692
+ }
9693
+ }
9694
+
9582
9695
  // Post-render ref extraction
9583
9696
  const refElements = this.shadowRoot.querySelectorAll('[ref]');
9584
9697
  refElements.forEach(el => {
@@ -9594,6 +9707,10 @@ class ${componentId.replace(/[-.:]/g, "_")} extends HTMLElement {
9594
9707
 
9595
9708
  // 4. Execute User Script
9596
9709
  if (typeof userComponentFn === 'function') {
9710
+ if (this._initialized) {
9711
+ return;
9712
+ }
9713
+ this._initialized = true;
9597
9714
  await userComponentFn.call(this, context);
9598
9715
  }
9599
9716
  }
@@ -9626,6 +9743,13 @@ customElements.define("${componentId}", ${componentId.replace(/[-.:]/g, "_")});
9626
9743
  pluginData: { index }
9627
9744
  };
9628
9745
  });
9746
+ pluginBuild.onResolve({ filter: /^coralite-component\// }, (args) => {
9747
+ const componentId2 = args.path.replace("coralite-component/", "");
9748
+ return {
9749
+ path: `./${componentId2}.js`,
9750
+ external: true
9751
+ };
9752
+ });
9629
9753
  pluginBuild.onLoad({
9630
9754
  filter: /.*/,
9631
9755
  namespace: "coralite-script-module"
@@ -9669,7 +9793,7 @@ customElements.define("${componentId}", ${componentId.replace(/[-.:]/g, "_")});
9669
9793
  }
9670
9794
  }
9671
9795
  }
9672
- const importsObjContent2 = Object.keys(importMap2).length > 0 ? `const pluginImports = { ${Object.entries(importMap2).map(([key, value]) => `${key}: ${value}`).join(", ")} };` : "const pluginImports = {};";
9796
+ const importsObjContent2 = Object.keys(importMap2).length > 0 ? `const pluginImports = { ${Object.entries(importMap2).map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const pluginImports = {};";
9673
9797
  contents += importsObjContent2 + "\n";
9674
9798
  const configContent = module.config ? `const pluginConfig = ${JSON.stringify(module.config)};` : "const pluginConfig = {};";
9675
9799
  contents += configContent + "\n";
@@ -9901,7 +10025,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9901
10025
  }
9902
10026
  }
9903
10027
  }
9904
- const importsObjContent = Object.keys(importMap).length > 0 ? `const componentImports = { ${Object.entries(importMap).map(([key, value]) => `${key}: ${value}`).join(", ")} };` : "const componentImports = {};";
10028
+ const importsObjContent = Object.keys(importMap).length > 0 ? `const componentImports = { ${Object.entries(importMap).map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const componentImports = {};";
9905
10029
  contents += importsObjContent + "\n";
9906
10030
  contents += "export default componentImports;";
9907
10031
  return {
@@ -9953,7 +10077,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9953
10077
  }
9954
10078
  }
9955
10079
  }
9956
- const importsObjContent = Object.keys(importMap).length > 0 ? `const pluginImports = { ${Object.entries(importMap).map(([key, value]) => `${key}: ${value}`).join(", ")} };` : "const pluginImports = {};";
10080
+ const importsObjContent = Object.keys(importMap).length > 0 ? `const pluginImports = { ${Object.entries(importMap).map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const pluginImports = {};";
9957
10081
  contents += importsObjContent + "\n";
9958
10082
  const configContent = module.config ? `const pluginConfig = ${JSON.stringify(module.config)};` : "const pluginConfig = {};";
9959
10083
  contents += configContent + "\n";
@@ -10677,7 +10801,10 @@ Coralite.prototype._generateStandaloneComponents = async function* () {
10677
10801
  );
10678
10802
  yield {
10679
10803
  type: "component",
10680
- path: component.path,
10804
+ path: {
10805
+ ...component.path,
10806
+ filename: component.path.filename.replace(/\.html$/, ".js")
10807
+ },
10681
10808
  content: compiledCode,
10682
10809
  duration: performance.now() - startTime
10683
10810
  };
@@ -10941,17 +11068,15 @@ Coralite.prototype.build = async function(...args) {
10941
11068
  });
10942
11069
  }
10943
11070
  await Promise.all(executing);
10944
- if (this.options.standaloneOutput) {
10945
- for await (const result of this._generateStandaloneComponents()) {
10946
- if (signal?.aborted) throw signal.reason;
10947
- if (typeof callback === "function") {
10948
- const transformed = await callback(result);
10949
- if (transformed) {
10950
- results.push(transformed);
10951
- }
10952
- } else {
10953
- results.push(result);
11071
+ for await (const result of this._generateStandaloneComponents()) {
11072
+ if (signal?.aborted) throw signal.reason;
11073
+ if (typeof callback === "function") {
11074
+ const transformed = await callback(result);
11075
+ if (transformed) {
11076
+ results.push(transformed);
10954
11077
  }
11078
+ } else {
11079
+ results.push(result);
10955
11080
  }
10956
11081
  }
10957
11082
  return results;
@@ -10982,15 +11107,19 @@ Coralite.prototype.save = async function(output, path2, options = {}) {
10982
11107
  const signal = options?.signal;
10983
11108
  const createdDir = {};
10984
11109
  const results = await this.build(path2, options, async (result) => {
10985
- let relDir, outDir, outFile, contentToWrite;
11110
+ let relativeDir, outDir, outFile, contentToWrite;
10986
11111
  if (result.type === "component") {
10987
- relDir = relative(this.options.path.components, result.path.dirname);
10988
- outDir = join2(this.options.standaloneOutput, relDir);
10989
- outFile = join2(outDir, result.path.filename.replace(".html", ".js"));
11112
+ relativeDir = relative(this.options.path.components, result.path.dirname);
11113
+ if (this.options.standaloneOutput) {
11114
+ outDir = join2(output, this.options.standaloneOutput, relativeDir);
11115
+ } else {
11116
+ outDir = join2(output, "components", relativeDir);
11117
+ }
11118
+ outFile = join2(outDir, result.path.filename);
10990
11119
  contentToWrite = result.content;
10991
11120
  } else {
10992
- relDir = relative(this.options.path.pages, result.path.dirname);
10993
- outDir = join2(output, relDir);
11121
+ relativeDir = relative(this.options.path.pages, result.path.dirname);
11122
+ outDir = join2(output, relativeDir);
10994
11123
  outFile = join2(outDir, result.path.filename);
10995
11124
  contentToWrite = result.content;
10996
11125
  }