repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
movies | github_2023 | oktay | typescript | movie | const movie = ({ region }: WatchProvidersRequestParams) =>
api.fetcher<ListResponse<WatchProvider>>({
endpoint: `watch/providers/movie`,
params: {
watch_region: region,
},
}) | /**
* Fetches the list of Movie watch providers based on the specified region.
*
* @param {WatchProvidersRequestParams} params - The request parameters.
* @returns {Promise<ListResponse<WatchProvider>>} - The list of Movie watch providers.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/api/watch-providers/index.ts#L22-L28 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | tv | const tv = ({ region }: WatchProvidersRequestParams) =>
api.fetcher<ListResponse<WatchProvider>>({
endpoint: `watch/providers/tv`,
params: {
watch_region: region,
},
}) | /**
* Fetches the list of TV watch providers based on the specified region.
*
* @param {WatchProvidersRequestParams} params - The request parameters.
* @returns {Promise<ListResponse<WatchProvider>>} - The list of TV watch providers.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/api/watch-providers/index.ts#L36-L42 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | content | const content = (string: string) => {
return string
.split("\n")
.filter((section) => section !== "")
.map((section) => `<p>${section}</p>`)
.join("")
} | /**
* Formats a given string into HTML paragraphs. Each line in the input string becomes a separate paragraph.
* @param string The input string to format.
* @returns A string of HTML paragraphs.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/format.ts#L6-L12 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | runtime | const runtime = (minutes: number) => {
const hours = Math.floor(minutes / 60)
const mins = minutes % 60
return `${hours ? hours + "h" : ""} ${mins}min`
} | /**
* Formats a duration from minutes into a human-readable string.
* @param minutes The duration in minutes.
* @returns A string representing the duration in hours and minutes.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/format.ts#L19-L24 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | date | const date = (date: string) => {
return new Date(date).toLocaleDateString("en-US", {
dateStyle: "long",
})
} | /**
* Formats a date string into a human-readable long date format.
* @param date The date string to format.
* @returns A string representing the formatted date.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/format.ts#L31-L35 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | year | const year = (date: string) => new Date(date).getFullYear() | /**
* Extracts the year from a date string.
* @param date The date string to extract the year from.
* @returns The year as a number.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/format.ts#L42-L42 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | currency | const currency = (x: number) => {
const formatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 0,
})
return formatter.format(x)
} | /**
* Formats a number into a currency string.
* @param x The number to format.
* @returns A string representing the formatted currency.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/format.ts#L49-L56 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | url | const url = (path: string, type: ImageSize = "original") => {
if (!path) {
console.error("Invalid image path provided.")
return "/placeholder.png"
}
return `https://image.tmdb.org/t/p/${type}/${path}`
} | /**
* Generates a URL for an image.
* @param path The path of the image.
* @param type The size of the image as defined in `imageSizes`.
* @returns The URL of the image or a placeholder image URL if the path is invalid.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/image.ts#L56-L62 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | poster | const poster = (path: string, size: PosterSize = "original") => {
return url(path, imageSizes.poster[size])
} | /**
* Generates a URL for a poster image.
* @param path The path of the poster image.
* @param size The size of the poster image as defined in `imageSizes.poster`.
* @returns The URL of the poster image.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/image.ts#L70-L72 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | backdrop | const backdrop = (path: string, size: BackdropSize = "original") => {
return url(path, imageSizes.backdrop[size])
} | /**
* Generates a URL for a backdrop image.
* @param path The path of the backdrop image.
* @param size The size of the backdrop image as defined in `imageSizes.backdrop`.
* @returns The URL of the backdrop image.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/image.ts#L80-L82 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | profile | const profile = (path: string, size: ProfileSize = "original") => {
return url(path, imageSizes.profile[size])
} | /**
* Generates a URL for a profile image.
* @param path The path of the profile image.
* @param size The size of the profile image as defined in `imageSizes.profile`.
* @returns The URL of the profile image.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/image.ts#L90-L92 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | logo | const logo = (path: string, size: LogoSize = "original") => {
return url(path, imageSizes.logo[size])
} | /**
* Generates the URL for a logo image.
* @param path - The path of the image.
* @param size - The size of the logo image. Defaults to "original".
* @returns The URL of the logo image.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/image.ts#L100-L102 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | video | const video = (key: string, autoplay: boolean = false) =>
`https://www.youtube.com/embed/${key}?rel=0&showinfo=0&autoplay=${
autoplay ? 1 : 0
}` | /**
* Generates a URL for embedding a YouTube video.
* @param key The unique identifier for the YouTube video.
* @param autoplay Optional parameter to enable autoplay of the video. Defaults to false.
* @returns The URL for embedding the YouTube video with specified parameters.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/yt.ts#L7-L10 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
movies | github_2023 | oktay | typescript | thumbnail | const thumbnail = (key: string) =>
`https://img.youtube.com/vi/${key}/hqdefault.jpg` | /**
* Generates a URL for a YouTube video thumbnail.
* @param key The unique identifier for the YouTube video.
* @returns The URL for the video's thumbnail image.
*/ | https://github.com/oktay/movies/blob/56e0581305db8ee2b9876a79e770cc9230dae787/tmdb/utils/yt.ts#L17-L18 | 56e0581305db8ee2b9876a79e770cc9230dae787 |
marimo | github_2023 | marimo-team | typescript | Throw | const Throw = () => {
throw error;
}; | // Most likely, configuration failed to parse. | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/main.tsx#L45-L47 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | hashString | const hashString = (str: string) => {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = (hash << 5) - hash + char;
hash = Math.trunc(hash); // Convert to 32bit integer
}
return hash;
}; | // Simple hash function to convert a string to a number | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/components/charts/chart-skeleton.tsx#L11-L19 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | generateHeights | const generateHeights = (numBars: number, maxHeight: number, seed: string) => {
const heights = [];
let randomSeed = hashString(seed);
for (let i = 0; i < numBars; i++) {
randomSeed = (randomSeed * 9301 + 49_297) % 233_280;
const random = randomSeed / 233_280;
const height = Math.abs(Math.floor(random... | // Utility function to generate deterministic random heights based on a seed | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/components/charts/chart-skeleton.tsx#L22-L32 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | extractDatasets | function extractDatasets(input: string): DataTable[] {
const datasets = store.get(datasetTablesAtom);
const existingDatasets = Maps.keyBy(datasets, (dataset) => dataset.name);
// Extract dataset mentions from the input
const mentionedDatasets = input.match(/@([\w.]+)/g) || [];
// Filter to only include data... | /**
* Extracts datasets from the input.
* Datasets are referenced with @<dataset_name> in the input.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/components/editor/ai/completion-utils.ts#L44-L56 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | useRunCells | function useRunCells() {
const { prepareForRun } = useCellActions();
const runCells = useEvent(async (cellIds: CellId[]) => {
if (cellIds.length === 0) {
return;
}
const { cellHandles, cellData } = getNotebook();
const codes: string[] = [];
for (const cellId of cellIds) {
const re... | /**
* Creates a function that runs the given cells.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/components/editor/cell/useRunCells.ts#L42-L70 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | handleResize | const handleResize = () => {
fitAddon.fit();
}; | // Handle resize | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/components/terminal/terminal.tsx#L73-L75 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | initialNotebookState | function initialNotebookState(): NotebookState {
if (isStaticNotebook()) {
const {
cellCodes,
cellConfigs,
cellConsoleOutputs,
cellIds,
cellNames,
cellOutputs,
} = parseStaticState();
const cellData: Record<CellId, CellData> = {};
const cellRuntime: Record<CellId, C... | /**
* Initial state of the notebook.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/cells/cells.ts#L121-L182 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | updateCellRuntimeState | function updateCellRuntimeState(
state: NotebookState,
cellId: CellId,
cellReducer: ReducerWithoutAction<CellRuntimeState>,
) {
if (!(cellId in state.cellRuntime)) {
Logger.warn(`Cell ${cellId} not found in state`);
return state;
}
return {
...state,
cellRuntime: {
...state.cellRuntim... | // Helper function to update a cell in the array | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/cells/cells.ts#L1183-L1200 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | isCursorInText | function isCursorInText(state: EditorState) {
const { head } = state.selection.main;
const text = state.doc.sliceString(head - 1, head);
return /\w/.test(text);
} | // Checks if the cursor is in a text element | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/completion/hints.ts#L88-L92 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CopilotLanguageServerClient.signOut | signOut() {
return this._request("signOut", {});
} | // AUTH | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/copilot/language-server.ts#L112-L114 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CopilotLanguageServerClient.acceptCompletion | acceptCompletion(params: CopilotAcceptCompletionParams) {
return this._request("notifyAccepted", params);
} | // COMPLETIONS | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/copilot/language-server.ts#L157-L159 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | findInDirection | const findInDirection = (direction: "next" | "prev") =>
searchCommand(({ query }) => {
const views = getAllEditorViews();
// Get starting view from the store
const currentView = store.get(findReplaceAtom).currentView || {
view: views[0],
range: { from: 0, to: 0 },
};
let startingPosit... | /**
* Move the selection to the first match (next or previous) after the global selection.
* Will wrap around to the start of the document when it reaches the end.
*
* This is a modified version of the original findNext/findPrev function,
* that searches through all views, instead of just the current one.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/find-replace/navigate.ts#L35-L96 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | MetaUnderlineVariablePlugin.windowBlur | private keydown = (event: KeyboardEvent) => {
if (event.key === "Meta" || event.key === "Control") {
this.commandClickMode = true;
this.view.dom.addEventListener("mousemove", this.mousemove);
this.view.dom.addEventListener("click", this.click);
}
} | // Handle window blur event to reset state | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/underline.ts | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | MetaUnderlineVariablePlugin.clearUnderline | private clearUnderline() {
if (this.hoveredRange) {
this.view.dispatch({ effects: removeUnderlines.of(null) });
this.hoveredRange = null;
}
} | // Only clear the underline if we have some underline | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/underline.ts#L174-L179 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getWordUnderCursor | function getWordUnderCursor(state: EditorState) {
const { from, to } = state.selection.main;
if (from === to) {
const { startToken, endToken } = getPositionAtWordBounds(state.doc, from);
return state.doc.sliceString(startToken, endToken);
}
return state.doc.sliceString(from, to);
} | /**
* Get the word under the cursor.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/utils.ts#L16-L24 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getCellIdOfDefinition | function getCellIdOfDefinition(
variables: Variables,
variableName: string,
): CellId | null {
if (!variableName) {
return null;
}
const variable = variables[variableName as VariableName];
if (!variable || variable.declaredBy.length === 0) {
return null;
}
return variable.declaredBy[0];
} | /**
* Get the cell id of the definition of the given variable.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/utils.ts#L29-L41 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getEditorForVariable | function getEditorForVariable(
editor: EditorView,
variableName: string,
): EditorView | null {
// If it's a private variable, we only want to go to the
// definition if it's in the same cell
if (isPrivateVariable(variableName)) {
return editor;
}
const variables = store.get(variablesAtom);
const ... | /**
* @param editor The editor view at which the command was invoked.
* @param variableName The name of the variable to go to.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/utils.ts#L97-L115 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getEditorForCell | function getEditorForCell(cellId: CellId): EditorView | null {
const notebookState = store.get(notebookAtom);
return notebookState.cellHandles[cellId].current?.editorView ?? null;
} | /**
* Go to the given line number in the editor view.
* @param view The editor view to go to.
* @param line The line number to go to.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/go-to-definition/utils.ts#L122-L125 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | doubleCharacterListener | function doubleCharacterListener(
character: string,
predicate: (view: EditorView) => boolean,
onDoubleCharacter: (view: EditorView) => boolean,
): Extension {
let lastKey = "";
let lastKeyTime = 0;
return keymap.of([
{
any: (view, event) => {
const key = event.key;
const time = ev... | /**
* Listen for a double keypress of a character and call a callback.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/keymaps/keymaps.ts#L66-L104 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | languageToggle | function languageToggle() {
const languages = getLanguageAdapters();
// Cycle through the language to find the next one that supports the code
const findNextLanguage = (code: string, index: number): LanguageAdapter => {
const language = languages[index % languages.length];
if (language.isSupported(code)) ... | // Keymap to toggle between languages | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/language/extension.ts#L70-L107 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | findNextLanguage | const findNextLanguage = (code: string, index: number): LanguageAdapter => {
const language = languages[index % languages.length];
if (language.isSupported(code)) {
return language;
}
return findNextLanguage(code, index + 1);
}; | // Cycle through the language to find the next one that supports the code | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/language/extension.ts#L73-L79 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | triggerUpdate | const triggerUpdate = () => {
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: view.state.doc.toString(),
},
});
}; | // Send noop update code event, which will trigger an update to the new output variable name | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/language/panel.tsx#L37-L45 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | createPlaceholder | const createPlaceholder = () => {
const placeholderText = document.createElement("span");
placeholderText.append(document.createTextNode(beforeText));
const link = document.createElement("span");
link.textContent = linkText;
link.classList.add("cm-clickable-placeholder");
link.onclick = (evt) =>... | // Create a placeholder | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/placeholder/extensions.ts#L63-L76 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getThemeConfig | const getThemeConfig = () => ({
variant: "light",
settings: {
background: "#ffffff",
foreground: "#000000",
caret: "#000000",
selection: "#d7d4f0",
lineHighlight: "#cceeff44",
gutterBackground: "var(--color-background)",
gutterForeground: "var(--gray-10)",
},
styles: [
{ tag: t.c... | // Helper function to get theme configuration from the source | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/codemirror/theme/__tests__/light.test.ts#L7-L36 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | addConnection | function addConnection(
connections: DataSourceConnection[],
state: DataSourceState,
): DataSourceState {
return reducer(state, {
type: "addDataSourceConnection",
payload: {
connections: connections,
},
});
} | // Helper function to add connections | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/datasets/__tests__/data-source.test.ts#L15-L25 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | filterDataSources | function filterDataSources(payload: VariableName[]) {
return reducer(baseState, {
type: "filterDataSourcesFromVariables",
payload: payload,
});
} | // helper function to filter data sources by variable names | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/datasets/__tests__/data-source.test.ts#L133-L138 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | getHighestHeader | const getHighestHeader = (outline: Outline) => {
if (outline.items.length === 0) {
return 7; // default to imaginary H7
}
return Math.min(...outline.items.map((item) => item.level));
}; | // Higher header is the lowest value | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/outline.ts#L96-L101 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElement.init | private init() {
if (this.initialized) {
return;
}
const objectId = UIElementId.parseOrThrow(this);
this.inputListener = (e: MarimoValueInputEventType) => {
// TODO: just fill in the objectId and let the document handle
// broadcast? that would still let other elements c... | // set at construction time | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/ui-element.ts#L92-L129 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElement.reset | reset() {
const child = this.firstElementChild;
if (isCustomMarimoElement(child)) {
child.reset();
} else {
Logger.error(
"[marimo-ui-element] first child must have a reset method",
);
}
} | /**
* Reset the value of the child element to its initial value.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/ui-element.ts#L169-L178 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElement.observedAttributes | static get observedAttributes() {
return ["random-id"];
} | // remount its child. | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/ui-element.ts#L183-L185 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.INSTANCE | static get INSTANCE(): UIElementRegistry {
const KEY = "_marimo_private_UIElementRegistry";
if (!window[KEY]) {
window[KEY] = new UIElementRegistry();
}
return window[KEY] as UIElementRegistry;
} | /**
* Shared instance of UIElementRegistry since this must be a singleton.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L34-L40 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.registerInstance | registerInstance(objectId: UIElementId, instance: HTMLElement) {
const entry = this.entries.get(objectId);
if (entry === undefined) {
this.entries.set(objectId, {
objectId: objectId,
value: parseInitialValue(instance, this),
elements: new Set([instance]),
});
} else {
... | /**
* Register an instance of a UIElement
*
* @param objectId - id of the UIElement
* @param instance - the HTMLElement that the UIElement wraps
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L67-L78 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.removeInstance | removeInstance(objectId: UIElementId, instance: HTMLElement) {
const entry = this.entries.get(objectId);
// The UIElement can be removed from the registry before all
// instances are removed: UIElement removal is triggered
// when the tied Python object goes out of scope, but instance
// removal is ... | /**
* Remove an instance of a UIElement
*
* @remarks
* Should be called when a UIElement node is removed from the DOM.
*
* @param objectId - id of the UIElement
* @param instance - the HTMLElement to remove
*
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L90-L100 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.removeElementsByCell | removeElementsByCell(cellId: CellId) {
const objectIds = [...this.entries.keys()].filter((objectId) =>
objectId.startsWith(`${cellId}-`),
);
objectIds.forEach((objectId) => {
this.entries.delete(objectId);
});
} | /**
* Remove all UIElements associated with a particular cell from the registry.
*
* Doesn't destroy or unmount HTML elements, just removes associated state
* from the registry.
*
* @param cellId - stringified cellId
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L110-L118 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.lookupValue | lookupValue(objectId: string): ValueType {
const entry = this.entries.get(objectId);
return entry === undefined ? undefined : entry.value;
} | /**
* Get the value of a registered UIElement.
*
* @param objectId - id of the UIElement
* @returns the value for `objectId`, or `undefined` if the object was not found.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L126-L129 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | UIElementRegistry.broadcastValueUpdate | broadcastValueUpdate(
initiator: HTMLElement,
objectId: UIElementId,
value: ValueType,
): void {
const entry = this.entries.get(objectId);
if (entry !== undefined) {
entry.value = value;
entry.elements.forEach((element) => {
if (element !== initiator) {
element.dispat... | /**
* Broadcast `value` to instances of the component with id `objectId`
*
* Additionally, sends a message to alert the app that an object has a new
* value that should be sent to the kernel.
*
* @param initiator - child element that initiated the broadcast
* @param objectId - id of the UIElement
... | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/dom/uiregistry.ts#L173-L203 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | IslandsPyodideBridge.INSTANCE | static get INSTANCE(): IslandsPyodideBridge {
const KEY = "_marimo_private_IslandsPyodideBridge";
if (!window[KEY]) {
window[KEY] = new IslandsPyodideBridge();
}
return window[KEY] as IslandsPyodideBridge;
} | /**
* Lazy singleton instance of the IslandsPyodideBridge.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/islands/bridge.ts#L22-L28 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | maybeNoop | const maybeNoop = (fn: (e: KeyboardEvent) => void) =>
// eslint-disable-next-line @typescript-eslint/no-empty-function
alwaysShowRun ? () => {} : fn; | // No need to register, if display is default. | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/islands/components/output-wrapper.tsx#L60-L62 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | DelayRender | const DelayRender: React.FC<PropsWithChildren> = ({ children }) => {
return <div className="animate-delayed-show-200">{children}</div>;
}; | // Render delay for children 200ms, using only css | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/islands/components/output-wrapper.tsx#L145-L147 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | loadPyodideAndPackages | async function loadPyodideAndPackages() {
const marimoVersion = getMarimoVersion();
const pyodideVersion = getPyodideVersion(marimoVersion);
try {
self.controller = new ReadonlyWasmController();
self.pyodide = await self.controller.bootstrap({
version: marimoVersion,
pyodideVersion: pyodideVer... | // Initialize pyodide | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/islands/worker/worker.tsx#L29-L44 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | RuntimeState.INSTANCE | static get INSTANCE(): RuntimeState {
const KEY = "_marimo_private_RuntimeState";
if (!window[KEY]) {
window[KEY] = new RuntimeState(UI_ELEMENT_REGISTRY);
}
return window[KEY] as RuntimeState;
} | /**
* Shared instance of RuntimeState since this must be a singleton.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/kernel/RuntimeState.ts#L19-L25 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | RuntimeState.start | start(sendComponentValues: RunRequests["sendComponentValues"]) {
if (this.hasStarted) {
Logger.warn("RuntimeState already started");
return;
}
this._sendComponentValues = sendComponentValues;
document.addEventListener(
MarimoValueReadyEvent.TYPE,
this.handleReadyEvent,
);
... | /**
* Start listening for events from UIElements
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/kernel/RuntimeState.ts#L44-L55 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | RuntimeState.stop | stop() {
if (!this.hasStarted) {
Logger.warn("RuntimeState already stopped");
return;
}
document.removeEventListener(
MarimoValueReadyEvent.TYPE,
this.handleReadyEvent,
);
this.hasStarted = false;
} | /**
* Stop listening for events from UIElements
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/kernel/RuntimeState.ts#L60-L70 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | setupURL | function setupURL(search = "") {
const url = new URL("http://localhost:3000");
url.search = search;
window.history.pushState({}, "", `${url.pathname}${url.search}`);
return url;
} | // Helper to set up URL and searchParams | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/kernel/__tests__/handlers.test.ts#L7-L12 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | VirtualFileTracker.INSTANCE | static get INSTANCE(): VirtualFileTracker {
const KEY = "_marimo_private_VirtualFileTracker";
if (!window[KEY]) {
window[KEY] = new VirtualFileTracker();
}
return window[KEY] as VirtualFileTracker;
} | /**
* Shared instance of VirtualFileTracker since this must be a singleton.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/static/virtual-file-tracker.ts#L15-L21 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | MessageBuffer.start | start = () => {
this.started = true;
// Flush the buffer
this.buffer.forEach((data) => this.onMessage(data));
this.buffer = [];
} | /**
* Start processing messages
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/wasm/worker/message-buffer.ts | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | loadPyodideAndPackages | async function loadPyodideAndPackages() {
try {
// Import pyodide
const marimoVersion = getMarimoVersion();
const pyodideVersion = getPyodideVersion(marimoVersion);
// Bootstrap the controller
const controller = await getController(marimoVersion);
self.controller = controller;
self.pyodid... | // Initialize | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/wasm/worker/save-worker.ts#L29-L54 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | loadPyodideAndPackages | async function loadPyodideAndPackages() {
try {
const marimoVersion = getMarimoVersion();
const pyodideVersion = getPyodideVersion(marimoVersion);
const controller = await t.wrapAsync(getController)(marimoVersion);
self.controller = controller;
rpc.send.initializingMessage({
message: "Loadin... | // Initialize pyodide | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/core/wasm/worker/worker.ts#L45-L64 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | eventListener | const eventListener = (event: any) => savedListener.current(event); | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/hooks/useEventListener.ts#L58-L58 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | observeScript | const observeScript = (script: HTMLScriptElement) => {
const observer = new MutationObserver(() => {
const newStatus = script.dataset.status;
if (newStatus) {
setStatus(newStatus as ScriptStatus);
}
});
observer.observe(script, {
attributes: true,
attr... | // observes DOM changes and updates the status | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/hooks/useScript.ts#L38-L50 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | PluginSlotInternal | function PluginSlotInternal<T>(
{ hostElement, plugin, children, getInitialValue }: PluginSlotProps<T>,
ref: React.Ref<PluginSlotHandle>,
): JSX.Element {
const [childNodes, setChildNodes] = useState<ReactNode>(children);
const [value, setValue] = useState<T>(getInitialValue());
const { theme } = useTheme();
... | /* Handles synchronization of value on behalf of the component */ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/core/registerReactComponent.tsx#L82-L219 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | shouldCopyStyleSheet | function shouldCopyStyleSheet(sheet: CSSStyleSheet): boolean {
if (!sheet.href) {
return false;
}
// Must end with .css
if (!sheet.href.endsWith(".css")) {
return false;
}
if (
sheet.href.includes("127.0.0.1") &&
(process.env.NODE_ENV === "test" || process.env.NODE_ENV === "development")
... | // Copy the stylesheet to the shadow root if it is local | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/core/registerReactComponent.tsx#L477-L499 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | handleUpdate | const handleUpdate = (e: MarimoValueInputEventType) => {
const target = e.detail.element;
if (target === null || !(target instanceof Node)) {
return;
}
const objectId = getUIElementObjectId(target);
if (objectId === null) {
return;
}
const key = elementIds[objec... | // Spy on child input events to update state | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/DictPlugin.tsx#L53-L73 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | handleUpdate | const handleUpdate = (e: MarimoValueInputEventType) => {
const target = e.detail.element;
if (target === null || !(target instanceof Node)) {
return;
}
const objectId = getUIElementObjectId(target);
if (objectId === elementId) {
setInternalValue(e.detail.value);
}
... | // Spy on when the plugin generates an event (MarimoValueInputEvent) | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/FormPlugin.tsx#L240-L249 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | valueMap | const valueMap = (sliderValue: number): number => {
if (props.data.steps && props.data.steps.length > 0) {
return props.data.steps[sliderValue];
}
return sliderValue;
}; | // Create the valueMap function | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/SliderPlugin.tsx#L43-L48 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | runAnyWidgetModule | async function runAnyWidgetModule(
widgetDef: AnyWidget,
model: Model<T>,
el: HTMLElement,
) {
const experimental: Experimental = {
invoke: async (name, msg, options) => {
const message =
"anywidget.invoke not supported in marimo. Please file an issue at https://github.com/marimo-team/marimo/i... | /**
* Run the anywidget module
*
* @param widgetDef - The anywidget definition
* @param model - The model to pass to the widget
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx#L139-L158 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | Model.receiveCustomMessage | receiveCustomMessage(message: any, buffers?: DataView[]): void {
const response = WidgetMessageSchema.safeParse(message);
if (response.success) {
const data = response.data;
switch (data.method) {
case "update":
this.updateAndEmitDiffs(data.state as T);
break;
cas... | /**
* When receiving a message from the backend.
* We want to notify all listeners with `msg:custom`
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx#L291-L309 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | makeFieldSuggestionQueryCreator | function makeFieldSuggestionQueryCreator(params: {
type: keyof ResultingCharts;
limit: number;
additionalFieldQuery: FieldQuery;
}): QueryCreator {
const { type, limit, additionalFieldQuery } = params;
return {
type,
limit: limit,
createQuery(query: Query): Query {
return {
spec: {
... | // This code is adapted and simplified from https://github.com/vega/voyager | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/data-explorer/queries/field-suggestion.ts#L9-L31 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | safeGet | const safeGet = (obj: any, key: string): [z.ZodType] | [] => {
if (obj[key]) {
return obj[key];
}
return [];
}; | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/data-frames/utils/operators.ts#L195-L200 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | customBooleanParser | const customBooleanParser = (v: string) => {
if (v === "True") {
return true;
}
if (v === "False") {
return false;
}
return previousBooleanParser(v);
}; | // Custom boolean parser: | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/loader.ts#L112-L120 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | uniquifyColumnNames | function uniquifyColumnNames(csvData: string): string {
if (!csvData?.includes(",")) {
return csvData;
}
return mapColumnNames(csvData, (headerNames) => {
const existingNames = new Set<string>();
return headerNames.map((name) => {
const uniqueName = getUniqueKey(name, existingNames);
exis... | /**
* Make column names unique by appending a zero-width space to the end of each duplicate column name.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/loader.ts#L242-L255 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | replacePeriodsInColumnNames | function replacePeriodsInColumnNames(csvData: string): string {
// This looks like a period but it's actually a one-dot leader
// https://www.compart.com/en/unicode/U+2024
const ONE_DOT_LEADER = "․";
if (!csvData?.includes(".")) {
return csvData;
}
return mapColumnNames(csvData, (headerNames) => {
... | /**
* Replace periods in column names with a one-dot leader.
* This is because some downstream libraries use periods as a nested key separator.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/loader.ts#L261-L272 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | makeLegendSelectable | function makeLegendSelectable(
spec: VegaLiteUnitSpec,
fieldSelection: boolean | string[],
): VegaLiteUnitSpec {
// If fieldSelection is false, we don't do anything
if (fieldSelection === false) {
return spec;
}
let legendFields = findEncodedFields(spec);
// If fieldSelection is an array, we filter t... | /**
* Given a spec, add the necessary parameters to make the legend selectable.
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/make-selectable.ts#L86-L110 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | makeChartSelectable | function makeChartSelectable(
spec: VegaLiteUnitSpec,
chartSelection: boolean | "interval" | "point",
/**
* If the spec is part of a layer, we need to know the layer number.
* This is so we can give unique names to the parameters.
*/
layerNum: number | undefined,
): VegaLiteUnitSpec {
// If chartSele... | /**
* Given a spec, add the necessary parameters to make the chart selectable.
*
* Not supported marks:
* - geoshape
* - text
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/make-selectable.ts#L119-L164 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | makeChartPanZoom | function makeChartPanZoom(spec: VegaLiteUnitSpec): VegaLiteUnitSpec {
let mark: Mark | undefined;
try {
mark = Marks.getMarkType(spec.mark);
} catch {
// noop
}
// We don't do anything if the mark is geoshape
if (mark === "geoshape") {
return spec;
}
const params = spec.params || [];
co... | /**
* Given a spec, add the necessary parameters to make the chart pan/zoomable.
*
* Not supported marks:
* - geoshape
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/make-selectable.ts#L172-L196 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | makeChartInteractive | function makeChartInteractive<T extends GenericVegaSpec>(spec: T): T {
const prevEncodings = "encoding" in spec ? spec.encoding : undefined;
const params = spec.params || [];
const paramNames = params.map((param) => param.name);
if (params.length === 0) {
return spec;
}
const mark = Marks.getMarkType(... | /**
* Makes a chart clickable and adds an opacity encoding to the chart.
*
* Not supported marks:
* - text
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/impl/vega/make-selectable.ts#L204-L230 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | listener | const listener = (e: PopStateEvent | HashChangeEvent) => {
handleFindMatch(window.location);
}; | // Listen for route changes | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/plugins/layout/RoutesPlugin.tsx#L60-L62 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | TreeNode.geDescendantCount | geDescendantCount(): number {
return this.children.reduce(
(acc, child) => acc + 1 + child.geDescendantCount(),
0,
);
} | /**
* Recursively count the number of nodes in the tree
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L34-L39 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.getDescendants | getDescendants(id: T): T[] {
const node = this.nodes.find((n) => n.value === id);
if (!node) {
Logger.warn(
`Node ${id} not found in tree. Valid ids: ${this.topLevelIds}`,
);
return [];
}
return node.getDescendants();
} | /**
* Get the descendants of the given node
*
* Only works for the top-level nodes
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L100-L109 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.isCollapsed | isCollapsed(id: T): boolean {
const node = this.nodes.find((n) => n.value === id);
if (!node) {
Logger.warn(
`Node ${id} not found in tree. Valid ids: ${this.topLevelIds}`,
);
return false;
}
return node.isCollapsed;
} | /**
* Check if the given node is collapsed
*
* Only works for the top-level nodes
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L116-L125 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.indexOfOrThrow | indexOfOrThrow(id: T): CellIndex {
const index = this.nodes.findIndex((n) => n.value === id);
if (index === -1) {
throw new Error(
`Node ${id} not found in tree. Valid ids: ${this.topLevelIds}`,
);
}
return index as CellIndex;
} | /**
* Get the index of the given node, or throw
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L130-L138 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.moveToFront | moveToFront(id: T): CollapsibleTree<T> {
const index = this.indexOfOrThrow(id);
return this.withNodes(arrayMove(this.nodes, index, 0));
} | /**
* Move the given node to the front
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L143-L146 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.moveToBack | moveToBack(id: T): CollapsibleTree<T> {
const index = this.indexOfOrThrow(id);
return this.withNodes(arrayMove(this.nodes, index, this.nodes.length - 1));
} | /**
* Move the given node to the back
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L151-L154 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.collapse | collapse(id: T, until: T | undefined): CollapsibleTree<T> {
const nodeIndex = this.nodes.findIndex((n) => n.value === id);
if (nodeIndex === -1) {
throw new Error(
`Node ${id} not found in tree. Valid ids: ${this.topLevelIds}`,
);
}
const untilIndex =
until === undefined
... | /**
* Collapse everything past the given node @param id
* until @param until or the end of the tree
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L160-L191 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.expand | expand(id: T): CollapsibleTree<T> {
const nodeIndex = this.nodes.findIndex((n) => n.value === id);
if (nodeIndex === -1) {
throw new Error(
`Node ${id} not found in tree. Valid ids: ${this.topLevelIds}`,
);
}
let nodes = [...this.nodes];
const node = nodes[nodeIndex];
if (!n... | /**
* Expand a node and all of its children
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L196-L214 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.move | move(fromIdx: number, toIdx: number): CollapsibleTree<T> {
return this.withNodes(arrayMove(this.nodes, fromIdx, toIdx));
} | /**
* Move a node from one index to another
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L219-L221 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.at | at(index: number): T | undefined {
return this.nodes.at(index)?.value;
} | /**
* Get the node at the given index
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L226-L228 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.atOrThrow | atOrThrow(index: number): T {
const node = this.nodes.at(index);
if (node === undefined) {
throw new Error(`Node at index ${index} not found in tree`);
}
return node.value;
} | /**
* Get the node at the given index
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L233-L239 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.first | first(): T {
return this.atOrThrow(0);
} | /**
* Get the first node, or throw
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L244-L246 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.last | last(): T {
return this.atOrThrow(this.nodes.length - 1);
} | /**
* Get the last node, or throw
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L251-L253 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.insert | insert(id: T, index: number): CollapsibleTree<T> {
return this.withNodes(
arrayInsert(this.nodes, index, new TreeNode(id, false, [])),
);
} | /**
* Insert a node at the given index
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L258-L262 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.insertAtEnd | insertAtEnd(id: T): CollapsibleTree<T> {
return this.insert(id, this.nodes.length);
} | /**
* Insert a node at the end
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L267-L269 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.insertAtStart | insertAtStart(id: T): CollapsibleTree<T> {
return this.insert(id, 0);
} | /**
* Insert a node at the start
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L274-L276 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.deleteAtIndex | deleteAtIndex(idx: number): CollapsibleTree<T> {
const id = this.atOrThrow(idx);
let tree = this.withNodes(this.nodes);
try {
tree = tree.expand(id);
} catch {
// Don't care if its not expanded
}
return this.withNodes(arrayDelete(tree.nodes, idx));
} | /**
* Delete a node, expand if it was collapsed
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L281-L290 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.getCount | getCount(id: T): number {
return this.nodes.find((n) => n.value === id)?.geDescendantCount() ?? 0;
} | /**
* Get the number of nodes in the tree, not-including the given node
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L300-L302 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
marimo | github_2023 | marimo-team | typescript | CollapsibleTree.findAndExpandDeep | findAndExpandDeep(id: T): CollapsibleTree<T> {
const found = this.find(id);
if (found.length === 0) {
return this;
}
let result = this.withNodes(this.nodes);
for (const node of found) {
try {
result = result.expand(node);
} catch {
// Don't care if its the last node... | /**
* Find and expand the node and all of its children
*/ | https://github.com/marimo-team/marimo/blob/9278cf55bf66c3151bed36b1e0084151058c6012/frontend/src/utils/id-tree.tsx#L307-L322 | 9278cf55bf66c3151bed36b1e0084151058c6012 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.