-
Notifications
You must be signed in to change notification settings - Fork 57
implement view pages #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GamerGirlandCo
wants to merge
23
commits into
master
Choose a base branch
from
feat/view-pages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
implement view pages #102
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
72985bc
add missing `is-collapsed` class to callout's div when closed
GamerGirlandCo 841d48e
add new modal component
GamerGirlandCo 626d437
add ability to `dc.require` the `obsidian` package
GamerGirlandCo db33036
add `sort` function to `Groupings` namespace
GamerGirlandCo a4fad0e
add hooks and reducers to facilitate sorting
GamerGirlandCo b979e2b
re-add sorting functionality to table view
GamerGirlandCo 5e5007f
export `TableContextProvider`
GamerGirlandCo d131f4e
add table context getter prop to sort button
GamerGirlandCo 3dc0d9e
lift common props from table context into their own type
GamerGirlandCo 199960a
create a `useAsync` hook and a companion `Suspend` component
GamerGirlandCo 5ce8f79
add `loader` parameter to `useEffect` dependencies
GamerGirlandCo d4246cb
make `Suspend` fallback prettier
GamerGirlandCo 7ece762
update `useAsync` to be more resilient to race conditions
GamerGirlandCo 221c5fc
rewrite `useAsync` to use suspense boundaries properly
GamerGirlandCo f205e63
expose `SETTINGS_CONTEXT`, `COMPONENT_CONTEXT`, `DATACORE_CONTEXT` an…
GamerGirlandCo 629f915
add ability to create views for queries that are treated like any oth…
GamerGirlandCo 1d5a4e5
upgrade react-select to silence typescript errors
GamerGirlandCo ea02777
re-add vim codemirror plugin
GamerGirlandCo 0848f4a
re-add missing autocomplete and javascript language codemirror plugins
GamerGirlandCo 26d7c6d
add more dev deps to appease typescript
GamerGirlandCo 10e5fe2
bring `@codemirror/view` up to date
GamerGirlandCo c8745c9
silence more bogus errors
GamerGirlandCo 279ffd2
move select augmentation to proper folder, re-export some things
GamerGirlandCo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
| import { | ||
| ReactNode, | ||
| RefObject, | ||
| forwardRef, | ||
| useContext, | ||
| createContext, | ||
| memo, | ||
| Context as ReactContext, | ||
| useEffect, | ||
| useRef, | ||
| createPortal, | ||
| ComponentProps, | ||
| ForwardedRef, | ||
| useImperativeHandle, | ||
| useMemo, | ||
| } from "preact/compat"; | ||
| import { App, Modal as ObsidianModal } from "obsidian"; | ||
| import { APP_CONTEXT } from "ui/markdown"; | ||
| import { Literal } from "expression/literal"; | ||
| import { VNode } from "preact"; | ||
|
|
||
| class DatacoreModal extends ObsidianModal { | ||
| constructor(app: App, public openCallback?: ObsidianModal["onOpen"], public onCancel?: ObsidianModal["onClose"]) { | ||
| super(app); | ||
| } | ||
| public onOpen() { | ||
| super.onOpen(); | ||
| this.openCallback?.(); | ||
| } | ||
| public onClose() { | ||
| super.onClose(); | ||
| this.onCancel?.(); | ||
| } | ||
| } | ||
|
|
||
| class SubmittableDatacoreModal<T> extends DatacoreModal { | ||
| constructor( | ||
| app: App, | ||
| public submitCallback?: (result: T) => void | Promise<void>, | ||
| public openCallback?: ObsidianModal["onOpen"], | ||
| public onCancel?: ObsidianModal["onClose"] | ||
| ) { | ||
| super(app, openCallback, onCancel); | ||
| } | ||
| public onSubmit(result: T) { | ||
| this.close(); | ||
| this.submitCallback?.(result); | ||
| } | ||
| } | ||
|
|
||
| export class Modals { | ||
| get submittableModal() { | ||
| return SubmittableDatacoreModal; | ||
| } | ||
| get modal() { | ||
| return DatacoreModal; | ||
| } | ||
| } | ||
|
|
||
| interface ModalContextType<M extends ObsidianModal> { | ||
| modal: M; | ||
| } | ||
|
|
||
| interface BaseModalProps { | ||
| title?: Literal | VNode | ReactNode; | ||
| children: ReactNode; | ||
| onCancel?: ObsidianModal["onClose"]; | ||
| onOpen?: ObsidianModal["onOpen"]; | ||
| } | ||
|
|
||
| const MODAL_CONTEXT = createContext<ModalContextType<any> | null>(null); | ||
|
|
||
| function ModalContext<M extends ObsidianModal>({ modal, children }: { modal: M; children: ReactNode }) { | ||
| const Ctx = MODAL_CONTEXT as ReactContext<ModalContextType<M>>; | ||
| return <Ctx.Provider value={{ modal }}>{children}</Ctx.Provider>; | ||
| } | ||
|
|
||
| function useReusableImperativeHandle<M extends ObsidianModal>(modal: M, ref: ForwardedRef<M>) { | ||
| useImperativeHandle(ref, () => modal, [modal]); | ||
| } | ||
|
|
||
| function InnerSubmittableModal<T>( | ||
| { | ||
| children, | ||
| onSubmit, | ||
| onCancel, | ||
| onOpen, | ||
| title, | ||
| }: BaseModalProps & { | ||
| onSubmit?: (result: T) => void | Promise<void>; | ||
| }, | ||
| ref: ForwardedRef<SubmittableDatacoreModal<T>> | ||
| ) { | ||
| const app = useContext(APP_CONTEXT)!; | ||
| const modal = useMemo( | ||
| () => new SubmittableDatacoreModal<T>(app, onSubmit, onOpen, onCancel), | ||
| [app, onSubmit, onOpen, onCancel] | ||
| ); | ||
| useReusableImperativeHandle(modal, ref); | ||
| return ( | ||
| <ModalContext modal={modal}> | ||
| {createPortal(<>{title}</>, modal.titleEl)} | ||
| {createPortal(<>{children}</>, modal.contentEl)} | ||
| </ModalContext> | ||
| ); | ||
| } | ||
|
|
||
| function InnerModal({ children, onCancel, onOpen, title }: BaseModalProps, ref: ForwardedRef<DatacoreModal>) { | ||
| const app = useContext(APP_CONTEXT)!; | ||
| const modal = useMemo(() => new DatacoreModal(app, onOpen, onCancel), [app, onOpen, onCancel]); | ||
| useReusableImperativeHandle(modal, ref); | ||
| return ( | ||
| <ModalContext modal={modal}> | ||
| {createPortal(<>{title}</>, modal.titleEl)} | ||
| {createPortal(<>{children}</>, modal.contentEl)} | ||
| </ModalContext> | ||
| ); | ||
| } | ||
|
|
||
| export function useModalContext<M extends ObsidianModal>() { | ||
| return useContext(MODAL_CONTEXT) as ModalContextType<M>; | ||
| } | ||
|
|
||
| export const SubmittableModal = forwardRef(InnerSubmittableModal) as typeof InnerSubmittableModal; | ||
|
|
||
| export const Modal = forwardRef(InnerModal) as typeof InnerModal; |
This file contains hidden or 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,56 @@ | ||
| import { createContext } from "preact"; | ||
| import { Dispatch, useMemo, useReducer, Reducer, useContext } from "preact/hooks"; | ||
|
|
||
| /** The ways that the table can be sorted. */ | ||
| export type SortDirection = "ascending" | "descending"; | ||
| export type SortOn = { type: "column"; id: string; direction: SortDirection }; | ||
|
|
||
| export type TableAction = { type: "sort-column"; column: string; direction: SortDirection | undefined }; | ||
|
|
||
| export interface TableState { | ||
| /** mapping of column ids to sort directions */ | ||
| sorts: Record<string, SortDirection>; | ||
| } | ||
|
|
||
| export function tableReducer(state: TableState, action: TableAction): TableState { | ||
| switch (action.type) { | ||
| case "sort-column": { | ||
| const newSorts = {...state.sorts}; | ||
| if (action.direction === undefined) { | ||
| delete newSorts[action.column]; | ||
| } else { | ||
| newSorts[action.column] = action.direction; | ||
| } | ||
| return { | ||
| ...state, | ||
| sorts: newSorts, | ||
| }; | ||
| } | ||
| } | ||
| console.warn("datacore: Encountered unrecognized operation: " + (action as TableAction).type); | ||
| return state; | ||
| } | ||
|
|
||
| export function useTableDispatch(initial: TableState | (() => TableState)): [TableState, Dispatch<TableAction>] { | ||
| const init = useMemo(() => (typeof initial == "function" ? initial() : initial), []); | ||
| return useReducer(tableReducer as Reducer<TableState, TableAction>, init); | ||
| } | ||
|
|
||
| export type CommonTableContext = TableState & { | ||
| dispatch: Dispatch<TableAction> | ||
| } | ||
|
|
||
| export type TableContext = CommonTableContext & { | ||
| } | ||
|
|
||
| export const TABLE_CONTEXT = createContext<TableContext | null>(null); | ||
|
|
||
| export const COMMON_TABLE_CONTEXT = createContext<CommonTableContext | null>(null); | ||
|
|
||
| export function useTableContext() { | ||
| return useContext(TABLE_CONTEXT); | ||
| } | ||
|
|
||
| export function useCommonTableContext() { | ||
| return useContext(COMMON_TABLE_CONTEXT); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I'd do it like this - it's better to expose hook functions which load this data instead (like
dc.useSettings()).