cayo 0.9.5 → 0.9.9

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/lib/codegen.js CHANGED
@@ -45,7 +45,9 @@ export function generateCayoRuntime(components, config) {
45
45
  function generateRender(contents) {
46
46
  return (
47
47
  `
48
- export default function render() {
48
+ export default function render(cb) {
49
+ var target = function (node) { return node; }
50
+ if (cb) target = cb;
49
51
  ${contents}
50
52
  }
51
53
  `
@@ -68,7 +70,7 @@ export function generateComponentInstance(cayoId, componentName) {
68
70
  return (
69
71
  `
70
72
  new ${componentName}({
71
- target: document.querySelector('[data-cayo-id="${cayoId}"]'),
73
+ target: target(document.querySelector('[data-cayo-id="${cayoId}"]')),
72
74
  hydrate: true,
73
75
  props: getProps('${cayoId}'),
74
76
  });
@@ -19,6 +19,7 @@
19
19
  const json = JSON.stringify($$restProps);
20
20
  </script>
21
21
 
22
- <div data-cayo-id={name ? `${name}-${hash()}` : ''} data-cayo-props={json}><slot/></div>
23
- <slot/>
22
+ <div data-cayo-id={name ? `${name}-${hash()}` : ''} data-cayo-props={json}>
23
+ <slot/>
24
+ </div>
24
25
 
package/lib/renderer.js CHANGED
@@ -28,16 +28,20 @@ export class Renderer {
28
28
  cssTag += `<style>${css.code}</style>`;
29
29
  }
30
30
 
31
+ // NOTE: Q: why the `() => str` for 2nd replacement arg?
32
+ // A: In case there's dollar signs in that there string
33
+ // https://stackoverflow.com/questions/9423722/string-replace-weird-behavior-when-using-dollar-sign-as-replacement
34
+
31
35
  return {
32
36
  html: this.template.html
33
37
  // Ignore placeholders wrapped in HTML comments
34
38
  .replace(/<!--[^]*\%cayo\.\w+\%[^]*-->/g, '')
35
39
  // Replace placeholders in template
36
- .replace('%cayo.title%', !head.includes('<title>') ? `<title>${title}</title>` : '')
37
- .replace('%cayo.head%', head)
38
- .replace('%cayo.body%', html)
39
- .replace('%cayo.css%', cssTag)
40
- .replace('%cayo.script%', `<script type="module" src="./index.js"></script>`)
40
+ .replace('%cayo.title%', () => !head.includes('<title>') ? `<title>${title}</title>` : '')
41
+ .replace('%cayo.head%', () => head)
42
+ .replace('%cayo.body%', () => html)
43
+ .replace('%cayo.css%', () => cssTag)
44
+ .replace('%cayo.script%', () => `<script type="module" src="./index.js"></script>`)
41
45
  ,
42
46
  css: css,
43
47
  }
package/lib/utils.js CHANGED
@@ -61,7 +61,7 @@ export async function getComponentModulePaths(srcPath) {
61
61
 
62
62
  export async function createPageManifest(pagesPath, outDir, srcPath) {
63
63
  const pagePaths = await getPageModulePaths(pagesPath);
64
- const nonCayoComponentPaths = await fg([path.resolve(srcPath, './components/**/*!([.cayo]).svelte')]);
64
+ const componentPaths = await fg([path.resolve(srcPath, './components/**/*.svelte')]);
65
65
  let importPages = `import { createRequire } from 'module';\n`
66
66
  importPages += `const require = createRequire(import.meta.url);\n`
67
67
  importPages += `require('svelte/register');\n`;
@@ -75,7 +75,7 @@ export async function createPageManifest(pagesPath, outDir, srcPath) {
75
75
  })
76
76
  importPages += '}\n';
77
77
 
78
- nonCayoComponentPaths.forEach((path) => {
78
+ componentPaths.forEach((path) => {
79
79
  importPages += `delete require.cache['${path}'];\n`;
80
80
  });
81
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cayo",
3
- "version": "0.9.5",
3
+ "version": "0.9.9",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "start": "node cayo dev --projectRoot test"
@@ -0,0 +1,5 @@
1
+ <script>
2
+
3
+ </script>
4
+ ok
5
+ <!-- <slot></slot> -->
package/test/src/index.js CHANGED
@@ -1,5 +1,17 @@
1
1
  // console.log("I'm main");
2
+
3
+ const cb = (node) => {
4
+ console.log('im side effecting');
5
+ console.log(node);
6
+ return node;
7
+ }
8
+
9
+ function replaceContents ( node ) {
10
+ node.innerHTML = '';
11
+ return node;
12
+ }
13
+
2
14
  import { default as renderComponents } from './cayo-runtime.js';
3
15
  document.addEventListener('DOMContentLoaded', () => {
4
- renderComponents();
16
+ renderComponents(replaceContents);
5
17
  });
@@ -16,6 +16,8 @@ I'm index howdy ok<br>
16
16
  <a href="/hey/" class="red">Hey</a>
17
17
  <a href="/some/page/" class="red">Some</a>
18
18
 
19
+ <Cayo name="Test" object={{ some: 'what?$staticlink$'}}><div>Default Content</div></Cayo>
20
+
19
21
  <Cayo name="Cool" beans='ayo'>Whaaat</Cayo>
20
22
  <Cayo name="Cool" beans='beeeeaaaaasnnss' />
21
23
  <Cayo name="Cool" beans='NOT BEANS' />