30 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-01-29 09:26:07 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2024-08-02 18:19:39 +08:00
exports.default = useHljs;
2024-01-29 09:26:07 +08:00
const vue_1 = require("vue");
const context_1 = require("../config-provider/src/context");
const _utils_1 = require("../_utils");
function useHljs(props, shouldHighlightRef) {
const NConfigProvider = (0, vue_1.inject)(context_1.configProviderInjectionKey, null);
if (process.env.NODE_ENV !== 'production') {
const warnHljs = () => {
if (!props.hljs && !(NConfigProvider === null || NConfigProvider === void 0 ? void 0 : NConfigProvider.mergedHljsRef.value)) {
(0, _utils_1.warn)('code', 'hljs is not set.');
}
};
if (!shouldHighlightRef) {
warnHljs();
}
else {
(0, vue_1.watchEffect)(() => {
if (shouldHighlightRef.value) {
warnHljs();
}
});
}
}
return (0, vue_1.computed)(() => {
return props.hljs || (NConfigProvider === null || NConfigProvider === void 0 ? void 0 : NConfigProvider.mergedHljsRef.value);
});
}