Skip to content

Commit

Permalink
refactor(*): bump to typedoc 0.25.3 and typedoc 5.2.2
Browse files Browse the repository at this point in the history
Closes #12
  • Loading branch information
simeonoff committed Oct 31, 2023
1 parent 60165c9 commit a35dc57
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 99 deletions.
89 changes: 39 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
"sass-loader": "^10.1.0",
"style-loader": "^3.3.1",
"ts-loader": "^8.0.12",
"typedoc": "^0.23.21",
"typescript": "^4.9.5",
"typedoc": "^0.25.3",
"typescript": "^5.2.2",
"url-loader": "^4.1.1",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.0",
"webpack-merge": "^5.7.3"
},
"peerDependecies": {
"typedoc": "^0.23.21",
"typedoc-plugin-localization": "^3.0.1"
"typedoc": "^0.25.3",
"typedoc-plugin-localization": "^3.0.2"
}
}
22 changes: 22 additions & 0 deletions src/assets/css/elements/_buttons.sass
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,25 @@

&:hover
color: #fff

pre
button
position: absolute
inset-block-start: 4px
inset-inline-end: 4px
background: transparent
color: #09f
border: 1px solid #09f
font-size: 12px
font-weight: 600
text-transform: uppercase
padding: 9px 16px
transition: all .25s ease-in-out

&:hover
background: #09f
color: #fff
&:active
background: transparent
color: #09f

17 changes: 12 additions & 5 deletions src/assets/js/src/typedoc/components/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,31 @@ function bindEvents(
});
}

function checkIndex(state: SearchState, searchEl: HTMLElement) {
async function checkIndex(state: SearchState, searchEl: HTMLElement) {
if (state.index) return;

if (window.searchData) {
searchEl.classList.remove("loading");
searchEl.classList.add("ready");
state.data = window.searchData;
state.index = Index.load(window.searchData.index);

const res = await fetch(window.searchData as unknown as RequestInfo);
const json = new Blob([await res.arrayBuffer()])
.stream()
.pipeThrough(new DecompressionStream("gzip"));

const data: IData = await new Response(json).json();
state.data = data;
state.index = Index.load(data.index);
}
}

function updateResults(
async function updateResults(
searchEl: HTMLElement,
results: HTMLElement,
query: HTMLInputElement,
state: SearchState
) {
checkIndex(state, searchEl);
await checkIndex(state, searchEl);
// Don't clear results if loading state is not ready,
// because loading or error message can be removed.
if (!state.index || !state.data) return;
Expand Down
31 changes: 13 additions & 18 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { copy } from "fs-extra";
import { cpSync } from 'fs';
import { resolve } from 'path';
import { navigation } from './partials/navigation';
import { index } from './partials/index';
import { memberSources } from './partials/member.sources';
Expand All @@ -8,16 +8,16 @@ import { reflectionTemplate } from './templates/reflection';
import { memberSignatureBody } from './partials/member.signature.body';
import { breadcrumb } from './partials/breadcrumb';

import { Application, DefaultTheme, DefaultThemeRenderContext, JSX, Options, PageEvent, Reflection, Renderer, RendererEvent } from "typedoc";
import { Application, DefaultTheme, DefaultThemeRenderContext, JSX, Options, PageEvent, Reflection, RenderTemplate, Renderer, RendererEvent } from "typedoc";
import { defaultLayout } from "./layouts/default";

function bind<F, L extends any[], R>(fn: (f: F, ...a: L) => R, first: F) {
return (...r: L) => fn(first, ...r);
}

export class IgThemeRenderContext extends DefaultThemeRenderContext {
constructor(theme: DefaultTheme, options: Options) {
super(theme, options);
constructor(theme: DefaultTheme, page: PageEvent<Reflection>, options: Options) {
super(theme, page, options);

this.reflectionTemplate = bind(reflectionTemplate, this);
this.navigation = bind(navigation, this);
Expand All @@ -27,9 +27,9 @@ export class IgThemeRenderContext extends DefaultThemeRenderContext {
this.memberSignatureBody = bind(memberSignatureBody, this);
this.breadcrumb = bind(breadcrumb, this);

this.defaultLayout = (props: PageEvent<Reflection>) => {
this.defaultLayout = (template: RenderTemplate<PageEvent<Reflection>>, props: PageEvent<Reflection>) => {
return (
defaultLayout(this, props)
defaultLayout(this, template, props)
);
}
}
Expand All @@ -41,22 +41,17 @@ export class IgTheme extends DefaultTheme {
public constructor(renderer: Renderer) {
super(renderer);

renderer.on(RendererEvent.END, async () => {
const out = this.application.options.getValue('out');

await copy(
path.join(
process.cwd(),
'/node_modules/ig-typedoc-theme/dist/assets',
),
path.join(out, '/assets'),
);
renderer.on(RendererEvent.END, () => {
const from = resolve(__dirname, "./assets");
const to = resolve(this.application.options.getValue("out"), "assets");
cpSync(from, to, { recursive: true });
});
}

override getRenderContext(): IgThemeRenderContext {
override getRenderContext(pageEvent: PageEvent<Reflection>): IgThemeRenderContext {
this._ctx ||= new IgThemeRenderContext(
this,
pageEvent,
this.application.options
);
return this._ctx;
Expand Down
Loading

0 comments on commit a35dc57

Please sign in to comment.