-
Notifications
You must be signed in to change notification settings - Fork 60
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
83b5edb
add missing `is-collapsed` class to callout's div when closed
GamerGirlandCo 07baefe
add new modal component
GamerGirlandCo e5bbbba
add ability to `dc.require` the `obsidian` package
GamerGirlandCo 2b3a497
add `sort` function to `Groupings` namespace
GamerGirlandCo 83fd96b
add hooks and reducers to facilitate sorting
GamerGirlandCo e3d4b24
re-add sorting functionality to table view
GamerGirlandCo 5996813
export `TableContextProvider`
GamerGirlandCo bbc8dca
add table context getter prop to sort button
GamerGirlandCo 32f1d58
lift common props from table context into their own type
GamerGirlandCo e9dde80
create a `useAsync` hook and a companion `Suspend` component
GamerGirlandCo 8a06ed1
add `loader` parameter to `useEffect` dependencies
GamerGirlandCo 4ae3c08
make `Suspend` fallback prettier
GamerGirlandCo 1ac5022
update `useAsync` to be more resilient to race conditions
GamerGirlandCo 29cdf89
rewrite `useAsync` to use suspense boundaries properly
GamerGirlandCo 293ee74
expose `SETTINGS_CONTEXT`, `COMPONENT_CONTEXT`, `DATACORE_CONTEXT` an…
GamerGirlandCo 6cbd5ff
add ability to create views for queries that are treated like any oth…
GamerGirlandCo 69147b2
upgrade react-select to silence typescript errors
GamerGirlandCo d86f9e4
re-add vim codemirror plugin
GamerGirlandCo 894c335
re-add missing autocomplete and javascript language codemirror plugins
GamerGirlandCo da56bc3
add more dev deps to appease typescript
GamerGirlandCo cd33589
bring `@codemirror/view` up to date
GamerGirlandCo 3a4ddd0
silence more bogus errors
GamerGirlandCo 045aecc
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()).