-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from forman/refactor-demo
Refactor demo
- Loading branch information
Showing
29 changed files
with
420 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright © 2023 Norman Fomferra | ||
* Permissions are hereby granted under the terms of the MIT License: | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { | ||
type ExtensionContext, | ||
activateExtension, | ||
getExtensionId, | ||
registerExtension, | ||
} from "@/core"; | ||
import { registerCommand, registerContributionPoints } from "@/contrib"; | ||
import { selectView, clearView } from "./store"; | ||
|
||
// The app's manifest. | ||
import appManifest from "../package.json"; | ||
|
||
function activate(ctx: ExtensionContext) { | ||
// Register app-level commands | ||
ctx.subscriptions.push(registerCommand("app.selectView", selectView)); | ||
ctx.subscriptions.push(registerCommand("app.clearView", clearView)); | ||
} | ||
|
||
export function initApp() { | ||
// log.setLevel(log.LogLevel.OFF); | ||
|
||
// Register a number of app-level contribution points | ||
registerContributionPoints(); | ||
// Register the app as "extension" so its own contributions | ||
// in package.json are recognized. | ||
registerExtension(appManifest, { | ||
module: { activate }, | ||
}); | ||
// Activate the application | ||
void activateExtension(getExtensionId(appManifest)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright © 2023 Norman Fomferra | ||
* Permissions are hereby granted under the terms of the MIT License: | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { create } from "zustand"; | ||
|
||
export interface AppState { | ||
viewId: string | null; | ||
} | ||
|
||
export interface AppMethods { | ||
selectView(viewId: string | null): void; | ||
} | ||
|
||
export const useAppStore = create<AppState & AppMethods>()((set) => ({ | ||
viewId: null, | ||
selectView: (viewId: string | null) => set({ viewId }), | ||
})); | ||
|
||
export function useAppContext(): Record<string, unknown> { | ||
return useAppStore() as unknown as Record<string, unknown>; | ||
} | ||
|
||
export function selectView(viewId: string | null) { | ||
useAppStore.getState().selectView(viewId); | ||
} | ||
|
||
export function clearView() { | ||
useAppStore.getState().selectView(null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright © 2023 Norman Fomferra | ||
* Permissions are hereby granted under the terms of the MIT License: | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
interface ApiLinkProps { | ||
type?: | ||
| "classes " | ||
| "functions" | ||
| "interfaces" | ||
| "modules" | ||
| "types" | ||
| "variables"; | ||
module?: string; | ||
name: string; | ||
text?: string; | ||
} | ||
|
||
const baseUrl = "https://forman.github.io/extendit"; | ||
|
||
export function ApiLink({ type, module, name, text }: ApiLinkProps) { | ||
const href = [ | ||
baseUrl, | ||
type ?? "functions", | ||
`${module ?? "core"}.${name}.html`, | ||
].join("/"); | ||
return ( | ||
<code> | ||
<a href={href} target="_blank"> | ||
{text ?? name} | ||
</a> | ||
</code> | ||
); | ||
} | ||
|
||
export default ApiLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright © 2023 Norman Fomferra | ||
* Permissions are hereby granted under the terms of the MIT License: | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { | ||
getExtensionDisplayName, | ||
getExtensionId, | ||
registerExtension, | ||
} from "@/core"; | ||
import { useExtensions } from "@/react"; | ||
|
||
import type { ExtensionManifest } from "@/core"; | ||
|
||
import manifest1 from "../extensions/my-extension-1/package.json"; | ||
import manifest2 from "../extensions/my-extension-2/package.json"; | ||
import manifest3 from "../extensions/my-extension-3/package.json"; | ||
import ApiLink from "./ApiLink"; | ||
|
||
const availableExtensions: [string, ExtensionManifest][] = [ | ||
["my-extension-1", manifest1], | ||
["my-extension-2", manifest2], | ||
["my-extension-3", manifest3], | ||
]; | ||
|
||
const extensionsPath = "/src/demo/extensions"; | ||
|
||
function AvailableExtensions() { | ||
const extensions = useExtensions(); | ||
|
||
function hasExtension(id: string) { | ||
return Boolean(extensions.find((e) => e.id === id)); | ||
} | ||
|
||
return ( | ||
<div className="row2-item"> | ||
<h1>Available Extensions</h1> | ||
<p> | ||
Click to install an extension. Installing means registering an extension | ||
in the application using the <ApiLink name="registerExtension" />{" "} | ||
function. | ||
</p> | ||
<div className="button-bar"> | ||
{availableExtensions.map(([extPath, manifest]) => { | ||
return ( | ||
<button | ||
key={getExtensionId(manifest)} | ||
disabled={hasExtension(getExtensionId(manifest))} | ||
onClick={() => | ||
registerExtension(manifest, { | ||
pathResolver: (path) => | ||
`${extensionsPath}/${extPath}/${path}`, | ||
}) | ||
} | ||
type="button" | ||
> | ||
{getExtensionDisplayName(manifest)} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default AvailableExtensions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.