Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.0 #145

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions dist/cayo.svelte.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create_ssr_component, compute_rest_props, add_attribute } from 'svelte/internal';
import { create_ssr_component, compute_rest_props, spread, escape_object, escape_attribute_value } from 'svelte/internal';

function getWarnings(src, badProps) {
const warnings = {};
Expand Down Expand Up @@ -41,8 +41,9 @@ function checkBadProps(warnings, src, keys) {
/* src/cayo.svelte generated by Svelte v3.49.0 */

const Cayo = create_ssr_component(($$result, $$props, $$bindings, slots) => {
let $$restProps = compute_rest_props($$props, ["src"]);
let $$restProps = compute_rest_props($$props, ["src","attributes"]);
let { src } = $$props;
let { attributes } = $$props;

// Save unserializable prop keys (during stringification)
// so we can report them later
Expand Down Expand Up @@ -74,8 +75,23 @@ const Cayo = create_ssr_component(($$result, $$props, $$bindings, slots) => {
}

if ($$props.src === void 0 && $$bindings.src && src !== void 0) $$bindings.src(src);

return `<div${add_attribute("data-cayo-id", cayoInstanceData['data-cayo-id'], 0)}${add_attribute("data-cayo-src", cayoInstanceData['data-cayo-src'], 0)}${add_attribute("data-cayo-warn", cayoInstanceData['data-cayo-warn'], 0)}>
if ($$props.attributes === void 0 && $$bindings.attributes && attributes !== void 0) $$bindings.attributes(attributes);

return `<div${spread(
[
escape_object(attributes),
{
"data-cayo-id": escape_attribute_value(cayoInstanceData['data-cayo-id'])
},
{
"data-cayo-src": escape_attribute_value(cayoInstanceData['data-cayo-src'])
},
{
"data-cayo-warn": escape_attribute_value(cayoInstanceData['data-cayo-warn'])
}
],
{}
)}>
${`<script data-cayo-props type="application/json">${props}</script>`}
${slots.default ? slots.default({}) : ``}
</div>`;
Expand Down
7 changes: 7 additions & 0 deletions lib/core/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ export function generateComponentInstance(cayoId, componentName) {
return (
`
cayos['${cayoId}'] = {};
cayos['${cayoId}'].id = '${cayoId}';
cayos['${cayoId}'].target = document.querySelector('[data-cayo-id="${cayoId}"]');
cayos['${cayoId}'].instance = new ${componentName}({
target: target(cayos['${cayoId}'].target),
hydrate: true,
props: getProps(cayos['${cayoId}'].target),
});
cayos['${cayoId}'].event = new CustomEvent('cayo:init', {
detail: {
cayo: cayos['${cayoId}'],
},
});
document.dispatchEvent(cayos['${cayoId}'].event);
`
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/render/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ export async function processPage(content, page, _cayo, logger) {
}

function tagsExist(source) {
const doctype = source.match(/<!DOCTYPE[\s\S]*>/);
const doctype = source.match(/(?<doctype><!DOCTYPE[\s\S]*?>)/);
const head = source.match(/<head[\s\S]*>(?<innerHTML>[\s\S]*)<\/head>/);
const body = source.match(/<body[\s\S]*>(?<innerHTML>[\s\S]*)<\/body>/);
const html = source.match(/<html[\s\S]*>(?<innerHTML>[\s\S]*)<\/html>/);
return {
doctype: doctype === null ? false : doctype,
doctype: doctype === null ? false : doctype.groups.doctype,
html: html === null ? false : html.groups,
head: head === null ? false : head.groups,
body: body === null ? false : body.groups,
Expand Down
4 changes: 3 additions & 1 deletion src/cayo.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
export let src;
import { getWarnings } from './cayo-warnings.js';
export let src;
export let attributes;

// Save unserializable prop keys (during stringification)
// so we can report them later
Expand Down Expand Up @@ -31,6 +32,7 @@
</script>

<div
{...attributes}
data-cayo-id={cayoInstanceData['data-cayo-id']}
data-cayo-src={cayoInstanceData['data-cayo-src']}
data-cayo-warn={cayoInstanceData['data-cayo-warn']}
Expand Down
1 change: 0 additions & 1 deletion template/src/__template.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down