@elmethis/core 0.2.6 → 0.2.8
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent,
|
|
1
|
+
import { defineComponent, createElementBlock, openBlock, normalizeClass } from "vue";
|
|
2
2
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
3
3
|
__name: "ElmFragmentIdentifier",
|
|
4
4
|
props: {
|
|
@@ -14,17 +14,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
14
14
|
target.scrollIntoView({ behavior: "smooth" });
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
onMounted(() => {
|
|
18
|
-
nextTick(() => {
|
|
19
|
-
const hash = window.location.hash;
|
|
20
|
-
if (hash && hash.startsWith("#")) {
|
|
21
|
-
const element = document.querySelector(hash);
|
|
22
|
-
if (element) {
|
|
23
|
-
element.scrollIntoView({ behavior: "smooth" });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
17
|
return (_ctx, _cache) => {
|
|
29
18
|
return openBlock(), createElementBlock("span", {
|
|
30
19
|
class: normalizeClass(_ctx.$style.fragment),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, ref, useSlots, createBlock, openBlock, resolveDynamicComponent, normalizeStyle, unref, normalizeClass, withCtx, createCommentVNode, createElementBlock, h } from "vue";
|
|
1
|
+
import { defineComponent, ref, useSlots, createBlock, openBlock, resolveDynamicComponent, normalizeStyle, unref, normalizeClass, withCtx, createCommentVNode, createElementBlock, h, isVNode } from "vue";
|
|
2
2
|
import { useIntersectionObserver } from "@vueuse/core";
|
|
3
3
|
import { kebabCase } from "lodash-es";
|
|
4
4
|
import ElmFragmentIdentifier from "./ElmFragmentIdentifier.vue.mjs";
|
|
@@ -29,14 +29,34 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
29
29
|
});
|
|
30
30
|
const slots = useSlots();
|
|
31
31
|
const renderSlots = () => {
|
|
32
|
-
if (
|
|
33
|
-
return h("span", {}, props.text);
|
|
34
|
-
} else if (slots.default != null) {
|
|
32
|
+
if (slots.default != null) {
|
|
35
33
|
return slots.default();
|
|
34
|
+
} else if (props.text != null) {
|
|
35
|
+
return h("span", {}, props.text);
|
|
36
36
|
} else {
|
|
37
37
|
return h("span");
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
const extractTextFromVNode = (vnodes) => {
|
|
41
|
+
const nodes = Array.isArray(vnodes) ? vnodes : [vnodes];
|
|
42
|
+
const extract = (node) => {
|
|
43
|
+
if (typeof node.children === "string") {
|
|
44
|
+
return node.children;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(node.children)) {
|
|
47
|
+
return node.children.map((child) => {
|
|
48
|
+
return isVNode(child) ? extract(child) : typeof child === "string" ? child : "";
|
|
49
|
+
}).join("");
|
|
50
|
+
}
|
|
51
|
+
return "";
|
|
52
|
+
};
|
|
53
|
+
return nodes.map(extract).join("");
|
|
54
|
+
};
|
|
55
|
+
const extractId = () => {
|
|
56
|
+
if (props.id) return props.id;
|
|
57
|
+
if (slots.default) return kebabCase(extractTextFromVNode(slots.default()));
|
|
58
|
+
return kebabCase(props.text);
|
|
59
|
+
};
|
|
40
60
|
return (_ctx, _cache) => {
|
|
41
61
|
return openBlock(), createBlock(resolveDynamicComponent(`h${_ctx.level}`), {
|
|
42
62
|
ref_key: "target",
|
|
@@ -57,7 +77,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
57
77
|
(openBlock(), createBlock(resolveDynamicComponent(() => renderSlots()))),
|
|
58
78
|
!_ctx.disableFragmentIdentifier ? (openBlock(), createBlock(ElmFragmentIdentifier, {
|
|
59
79
|
key: 0,
|
|
60
|
-
id:
|
|
80
|
+
id: extractId()
|
|
61
81
|
}, null, 8, ["id"])) : createCommentVNode("", true),
|
|
62
82
|
_ctx.level === 2 ? (openBlock(), createElementBlock("span", {
|
|
63
83
|
key: 1,
|