svelte-lazy
Advanced tools
Comparing version 1.0.7 to 1.0.8
142
index.js
@@ -391,2 +391,39 @@ (function (global, factory) { | ||
} | ||
function get_spread_update(levels, updates) { | ||
const update = {}; | ||
const to_null_out = {}; | ||
const accounted_for = { $$scope: 1 }; | ||
let i = levels.length; | ||
while (i--) { | ||
const o = levels[i]; | ||
const n = updates[i]; | ||
if (n) { | ||
for (const key in o) { | ||
if (!(key in n)) | ||
to_null_out[key] = 1; | ||
} | ||
for (const key in n) { | ||
if (!accounted_for[key]) { | ||
update[key] = n[key]; | ||
accounted_for[key] = 1; | ||
} | ||
} | ||
levels[i] = n; | ||
} | ||
else { | ||
for (const key in o) { | ||
accounted_for[key] = 1; | ||
} | ||
} | ||
} | ||
for (const key in to_null_out) { | ||
if (!(key in update)) | ||
update[key] = undefined; | ||
} | ||
return update; | ||
} | ||
function get_spread_object(spread_props) { | ||
return typeof spread_props === 'object' && spread_props !== null ? spread_props : {}; | ||
} | ||
function create_component(block) { | ||
@@ -530,6 +567,13 @@ block && block.c(); | ||
let current; | ||
const switch_instance_spread_levels = [/*placeholderProps*/ ctx[1]]; | ||
var switch_value = /*placeholder*/ ctx[0]; | ||
function switch_props(ctx) { | ||
return {}; | ||
let switch_instance_props = {}; | ||
for (let i = 0; i < switch_instance_spread_levels.length; i += 1) { | ||
switch_instance_props = assign(switch_instance_props, switch_instance_spread_levels[i]); | ||
} | ||
return { props: switch_instance_props }; | ||
} | ||
@@ -555,2 +599,6 @@ | ||
p(ctx, dirty) { | ||
const switch_instance_changes = (dirty & /*placeholderProps*/ 2) | ||
? get_spread_update(switch_instance_spread_levels, [get_spread_object(/*placeholderProps*/ ctx[1])]) | ||
: {}; | ||
if (switch_value !== (switch_value = /*placeholder*/ ctx[0])) { | ||
@@ -576,2 +624,4 @@ if (switch_instance) { | ||
} | ||
} else if (switch_value) { | ||
switch_instance.$set(switch_instance_changes); | ||
} | ||
@@ -622,2 +672,3 @@ }, | ||
let div; | ||
let show_if; | ||
let current_block_type_index; | ||
@@ -631,7 +682,8 @@ let if_block; | ||
if (typeof /*placeholder*/ ctx[0] === "string") return 0; | ||
if (typeof /*placeholder*/ ctx[0] === "function") return 1; | ||
if (dirty & /*placeholder*/ 1) show_if = !!["function", "object"].includes(typeof /*placeholder*/ ctx[0]); | ||
if (show_if) return 1; | ||
return -1; | ||
} | ||
if (~(current_block_type_index = select_block_type(ctx))) { | ||
if (~(current_block_type_index = select_block_type(ctx, -1))) { | ||
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); | ||
@@ -657,3 +709,3 @@ } | ||
let previous_block_index = current_block_type_index; | ||
current_block_type_index = select_block_type(ctx); | ||
current_block_type_index = select_block_type(ctx, dirty); | ||
@@ -713,8 +765,10 @@ if (current_block_type_index === previous_block_index) { | ||
let { placeholder = null } = $$props; | ||
let { placeholderProps = null } = $$props; | ||
$$self.$$set = $$props => { | ||
if ("placeholder" in $$props) $$invalidate(0, placeholder = $$props.placeholder); | ||
if ("placeholderProps" in $$props) $$invalidate(1, placeholderProps = $$props.placeholderProps); | ||
}; | ||
return [placeholder]; | ||
return [placeholder, placeholderProps]; | ||
} | ||
@@ -725,3 +779,3 @@ | ||
super(); | ||
init(this, options, instance, create_fragment, safe_not_equal, { placeholder: 0 }); | ||
init(this, options, instance, create_fragment, safe_not_equal, { placeholder: 0, placeholderProps: 1 }); | ||
} | ||
@@ -737,3 +791,6 @@ } | ||
placeholder_1 = new Placeholder({ | ||
props: { placeholder: /*placeholder*/ ctx[1] } | ||
props: { | ||
placeholder: /*placeholder*/ ctx[1], | ||
placeholderProps: /*placeholderProps*/ ctx[2] | ||
} | ||
}); | ||
@@ -752,2 +809,3 @@ | ||
if (dirty & /*placeholder*/ 2) placeholder_1_changes.placeholder = /*placeholder*/ ctx[1]; | ||
if (dirty & /*placeholderProps*/ 4) placeholder_1_changes.placeholderProps = /*placeholderProps*/ ctx[2]; | ||
placeholder_1.$set(placeholder_1_changes); | ||
@@ -777,6 +835,6 @@ }, | ||
let current; | ||
const default_slot_template = /*$$slots*/ ctx[13].default; | ||
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[12], null); | ||
const default_slot_template = /*$$slots*/ ctx[14].default; | ||
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[13], null); | ||
const default_slot_or_fallback = default_slot || fallback_block(); | ||
let if_block = /*contentDisplay*/ ctx[3] === "hide" && create_if_block_1$1(ctx); | ||
let if_block = /*contentDisplay*/ ctx[4] === "hide" && create_if_block_1$1(ctx); | ||
@@ -791,3 +849,3 @@ return { | ||
attr(div, "class", contentClass); | ||
attr(div, "style", /*contentStyle*/ ctx[4]); | ||
attr(div, "style", /*contentStyle*/ ctx[5]); | ||
}, | ||
@@ -808,16 +866,16 @@ m(target, anchor) { | ||
if (default_slot) { | ||
if (default_slot.p && dirty & /*$$scope*/ 4096) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[12], dirty, null, null); | ||
if (default_slot.p && dirty & /*$$scope*/ 8192) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[13], dirty, null, null); | ||
} | ||
} | ||
if (!current || dirty & /*contentStyle*/ 16) { | ||
attr(div, "style", /*contentStyle*/ ctx[4]); | ||
if (!current || dirty & /*contentStyle*/ 32) { | ||
attr(div, "style", /*contentStyle*/ ctx[5]); | ||
} | ||
if (/*contentDisplay*/ ctx[3] === "hide") { | ||
if (/*contentDisplay*/ ctx[4] === "hide") { | ||
if (if_block) { | ||
if_block.p(ctx, dirty); | ||
if (dirty & /*contentDisplay*/ 8) { | ||
if (dirty & /*contentDisplay*/ 16) { | ||
transition_in(if_block, 1); | ||
@@ -893,3 +951,6 @@ } | ||
placeholder_1 = new Placeholder({ | ||
props: { placeholder: /*placeholder*/ ctx[1] } | ||
props: { | ||
placeholder: /*placeholder*/ ctx[1], | ||
placeholderProps: /*placeholderProps*/ ctx[2] | ||
} | ||
}); | ||
@@ -908,2 +969,3 @@ | ||
if (dirty & /*placeholder*/ 2) placeholder_1_changes.placeholder = /*placeholder*/ ctx[1]; | ||
if (dirty & /*placeholderProps*/ 4) placeholder_1_changes.placeholderProps = /*placeholderProps*/ ctx[2]; | ||
placeholder_1.$set(placeholder_1_changes); | ||
@@ -938,3 +1000,3 @@ }, | ||
function select_block_type(ctx, dirty) { | ||
if (/*loaded*/ ctx[2]) return 0; | ||
if (/*loaded*/ ctx[3]) return 0; | ||
return 1; | ||
@@ -950,3 +1012,3 @@ } | ||
if_block.c(); | ||
attr(div, "class", /*rootClass*/ ctx[5]); | ||
attr(div, "class", /*rootClass*/ ctx[6]); | ||
}, | ||
@@ -959,3 +1021,3 @@ m(target, anchor) { | ||
if (!mounted) { | ||
dispose = action_destroyer(load_action = /*load*/ ctx[6].call(null, div)); | ||
dispose = action_destroyer(load_action = /*load*/ ctx[7].call(null, div)); | ||
mounted = true; | ||
@@ -1062,2 +1124,3 @@ } | ||
let { placeholder = null } = $$props; | ||
let { placeholderProps = null } = $$props; | ||
let { class: className = "" } = $$props; | ||
@@ -1077,3 +1140,3 @@ const rootClass = "svelte-lazy" + (className ? " " + className : ""); | ||
if (nodeTop <= expectedTop) { | ||
$$invalidate(2, loaded = true); | ||
$$invalidate(3, loaded = true); | ||
resetHeight(node); | ||
@@ -1132,3 +1195,3 @@ onload && onload(node); | ||
if (!img.complete) { | ||
$$invalidate(3, contentDisplay = "hide"); | ||
$$invalidate(4, contentDisplay = "hide"); | ||
@@ -1138,3 +1201,3 @@ node.addEventListener( | ||
() => { | ||
$$invalidate(3, contentDisplay = ""); | ||
$$invalidate(4, contentDisplay = ""); | ||
node.style.height = "auto"; | ||
@@ -1149,3 +1212,3 @@ }, | ||
// Keep passed height if there is error | ||
$$invalidate(3, contentDisplay = ""); | ||
$$invalidate(4, contentDisplay = ""); | ||
}, | ||
@@ -1166,10 +1229,11 @@ { capture: true, once: true } | ||
$$self.$$set = $$props => { | ||
if ("height" in $$props) $$invalidate(7, height = $$props.height); | ||
if ("offset" in $$props) $$invalidate(8, offset = $$props.offset); | ||
if ("height" in $$props) $$invalidate(8, height = $$props.height); | ||
if ("offset" in $$props) $$invalidate(9, offset = $$props.offset); | ||
if ("fadeOption" in $$props) $$invalidate(0, fadeOption = $$props.fadeOption); | ||
if ("resetHeightDelay" in $$props) $$invalidate(9, resetHeightDelay = $$props.resetHeightDelay); | ||
if ("onload" in $$props) $$invalidate(10, onload = $$props.onload); | ||
if ("resetHeightDelay" in $$props) $$invalidate(10, resetHeightDelay = $$props.resetHeightDelay); | ||
if ("onload" in $$props) $$invalidate(11, onload = $$props.onload); | ||
if ("placeholder" in $$props) $$invalidate(1, placeholder = $$props.placeholder); | ||
if ("class" in $$props) $$invalidate(11, className = $$props.class); | ||
if ("$$scope" in $$props) $$invalidate(12, $$scope = $$props.$$scope); | ||
if ("placeholderProps" in $$props) $$invalidate(2, placeholderProps = $$props.placeholderProps); | ||
if ("class" in $$props) $$invalidate(12, className = $$props.class); | ||
if ("$$scope" in $$props) $$invalidate(13, $$scope = $$props.$$scope); | ||
}; | ||
@@ -1180,4 +1244,4 @@ | ||
$$self.$$.update = () => { | ||
if ($$self.$$.dirty & /*contentDisplay*/ 8) { | ||
$$invalidate(4, contentStyle = contentDisplay === "hide" ? "display: none" : ""); | ||
if ($$self.$$.dirty & /*contentDisplay*/ 16) { | ||
$$invalidate(5, contentStyle = contentDisplay === "hide" ? "display: none" : ""); | ||
} | ||
@@ -1189,2 +1253,3 @@ }; | ||
placeholder, | ||
placeholderProps, | ||
loaded, | ||
@@ -1210,9 +1275,10 @@ contentDisplay, | ||
init(this, options, instance$1, create_fragment$1, safe_not_equal, { | ||
height: 7, | ||
offset: 8, | ||
height: 8, | ||
offset: 9, | ||
fadeOption: 0, | ||
resetHeightDelay: 9, | ||
onload: 10, | ||
resetHeightDelay: 10, | ||
onload: 11, | ||
placeholder: 1, | ||
class: 11 | ||
placeholderProps: 2, | ||
class: 12 | ||
}); | ||
@@ -1219,0 +1285,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"main": "index.js", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"types": "index.d.ts", | ||
@@ -40,3 +40,3 @@ "repository": "leafOfTree/svelte-lazy", | ||
"index.mjs", | ||
"index.js", | ||
"index.js", | ||
"index.d.ts" | ||
@@ -43,0 +43,0 @@ ], |
@@ -43,2 +43,4 @@ # svelte-lazy [![Build Status][1]][2] [![npm version][3]][4] | ||
- `placeholderProps: Object` Default `null`. When using a component as a placeholder, the props will be passed to it. | ||
- `class: String` Default: `''`. Additional class for the container div. It will be `svelte-lazy ${class}`. | ||
@@ -92,2 +94,6 @@ | ||
## Test | ||
npm test | ||
## Refs | ||
@@ -94,0 +100,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80452
2322
107