Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(md): add checklist progress plugin to md and tasks (#5599)
Seamus28662dd11f6c
diff --git a/apps/web/src/features/block-md/component/InlineTaskProperties.tsx b/apps/web/src/features/block-md/component/InlineTaskProperties.tsxindex e08cd4986f..2b41037633 100644--- a/apps/web/src/features/block-md/component/InlineTaskProperties.tsx+++ b/apps/web/src/features/block-md/component/InlineTaskProperties.tsx@@ -4,6 +4,7 @@ import {useBlockAliasedName,useBlockId,} from '@core/block';+import { ProgressChip } from '@core/component/LexicalMarkdown/component/status/Progress';import { useCanEdit } from '@core/signal/permissions';import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';import { Modals } from '@property/component/modal';@@ -19,6 +20,7 @@ import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity'import type { EntityType } from '@service-properties/generated/schemas/entityType';import { createMemo, For, Show, Suspense } from 'solid-js';import { match } from 'ts-pattern';+import { mdStore } from '../signal/markdownBlockData';import { InlinePropertyValue } from './InlinePropertyValue';/**@@ -26,6 +28,7 @@ import { InlinePropertyValue } from './InlinePropertyValue';* Displays status, priority, and assignees in a single row, editable like in list view.*/export function InlineTaskProperties() {+ const md = mdStore.get;const blockId = useBlockId();const blockName = useBlockAliasedName();const canEdit = useCanEdit();@@ -91,6 +94,13 @@ export function InlineTaskProperties() {entityId={blockId}entityType={entityType}/>+ <Show when={blockName === 'task' && md.progressStats}>+ {(progressStats) => (+ <Show when={progressStats().total > 0}>+ <ProgressChip stats={progressStats()} />+ </Show>+ )}+ </Show><Modals /></PropertiesProvider></Show>diff --git a/apps/web/src/features/block-md/component/MarkdownEditor.tsx b/apps/web/src/features/block-md/component/MarkdownEditor.tsxindex 5b61b13aae..c3c4d2cb53 100644--- a/apps/web/src/features/block-md/component/MarkdownEditor.tsx+++ b/apps/web/src/features/block-md/component/MarkdownEditor.tsx@@ -49,6 +49,7 @@ import {CLOSE_INLINE_SEARCH_COMMAND,createDraggableBlockStore,createDragInsertStore,+ createProgressStatsStore,createWordcountStatsStore,DefaultShortcuts,diffPlugin,@@ -63,6 +64,7 @@ import {markdownPastePlugin,mentionsPlugin,pinnedPropertiesPlugin,+ progressPlugin,selectionDataPlugin,tabIndentationPlugin,tableCellResizerPlugin,@@ -964,6 +966,10 @@ export function MarkdownEditor(props: {);setMdStore('wordcountStats', wordcountStats);+ const [progressStats, setProgressStats] = createProgressStatsStore();+ plugins.use(progressPlugin({ setStore: setProgressStats }));+ setMdStore('progressStats', progressStats);+return (<LexicalWrapperContext.Provider value={lexicalWrapper}>{/* SCUFFED: are these the right transparency values? */}diff --git a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsxindex 9c03b2d4fe..d7be879488 100644--- a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx+++ b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx@@ -12,6 +12,7 @@ import { useSplitLayout } from '@components/app/split-layout/layout';import { useBlockAliasedName, useBlockId, useBlockName } from '@core/block';import { EntityIcon } from '@core/component/EntityIcon';import { openDocument } from '@core/component/LexicalMarkdown/component/core/BlockLink';+import { ProgressMeter } from '@core/component/LexicalMarkdown/component/status/Progress';import { Wordcount } from '@core/component/LexicalMarkdown/component/status/Wordcount';import {$getPinnedProperties,@@ -517,6 +518,15 @@ function StatsSectionContent() {<SidePanel.Row label="Characters"><Wordcount.Characters /></SidePanel.Row>+ <Show when={md.progressStats}>+ {(progressStats) => (+ <Show when={progressStats().total > 0}>+ <SidePanel.Row label="Progress">+ <ProgressMeter stats={progressStats()} />+ </SidePanel.Row>+ </Show>+ )}+ </Show></SidePanel.Grid></Wordcount.Root>)}diff --git a/apps/web/src/features/block-md/signal/markdownBlockData.ts b/apps/web/src/features/block-md/signal/markdownBlockData.tsindex 41824a9ecc..8a55fea55c 100644--- a/apps/web/src/features/block-md/signal/markdownBlockData.ts+++ b/apps/web/src/features/block-md/signal/markdownBlockData.ts@@ -1,6 +1,7 @@import { blockDataSignalAs, createBlockStore } from '@core/block';import type {PluginManager,+ ProgressStats,SelectionData,WordcountStats,} from '@core/component/LexicalMarkdown/plugins';@@ -33,6 +34,7 @@ export type MdData = {plugins?: PluginManager;selection?: Store<SelectionData>;wordcountStats?: Store<WordcountStats>;+ progressStats?: Store<ProgressStats>;notebook?: HTMLElement;scrollContainer?: HTMLElement;commentMargin?: HTMLElement;diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/status/Progress.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/status/Progress.tsxnew file mode 100644index 0000000000..451d876882--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/status/Progress.tsx@@ -0,0 +1,84 @@+import { cn, Layer, Tooltip } from '@ui';+import { createMemo, Show } from 'solid-js';+import type { Store } from 'solid-js/store';+import type { ProgressStats } from '../../plugins';++type ProgressProps = {+ stats: Store<ProgressStats>;+ class?: string;+};++function useProgress(stats: Store<ProgressStats>) {+ const ratio = createMemo(() => {+ if (stats.total === 0) return 0;+ return Math.max(0, Math.min(1, stats.completed / stats.total));+ });++ const percentage = createMemo(() => `${ratio() * 100}%`);+ const count = createMemo(() => `${stats.completed}/${stats.total}`);+ const tooltip = createMemo(+ () =>+ `${stats.completed} out of ${stats.total} ${+ stats.total === 1 ? 'step' : 'steps'+ } complete`+ );++ return { percentage, count, tooltip };+}++export function ProgressMeter(props: ProgressProps) {+ const progress = useProgress(props.stats);++ return (+ <Show when={props.stats.total > 0}>+ <div class={cn('flex min-w-0 items-center gap-2', props.class)}>+ <div+ class="h-1.5 min-w-12 flex-1 overflow-hidden rounded-full bg-edge-muted"+ aria-hidden="true"+ >+ <div+ class="h-full rounded-full bg-accent transition-[width] duration-200 ease-out"+ style={{ width: progress.percentage() }}+ />+ </div>+ <span class="shrink-0 tabular-nums text-ink-muted">+ {progress.count()}+ </span>+ </div>+ </Show>+ );+}++export function ProgressChip(props: ProgressProps) {+ const progress = useProgress(props.stats);++ return (+ <Show when={props.stats.total > 0}>+ <Layer depth={2}>+ <Tooltip label={progress.tooltip()} as="span">+ <div+ class={cn(+ 'inline-flex min-w-0 items-center gap-1.5 rounded-full border border-edge-muted',+ 'bg-surface px-2 py-1 leading-tight',+ props.class+ )}+ aria-label={progress.tooltip()}+ >+ <div+ class="h-1.5 w-14 overflow-hidden rounded-full bg-edge-muted"+ aria-hidden="true"+ >+ <div+ class="h-full rounded-full bg-accent transition-[width] duration-200 ease-out"+ style={{ width: progress.percentage() }}+ />+ </div>+ <span class="shrink-0 tabular-nums text-ink-muted">+ {progress.count()}+ </span>+ </div>+ </Tooltip>+ </Layer>+ </Show>+ );+}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.tsindex 30ab5380f4..23b022b09a 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts@@ -32,6 +32,7 @@ export * from './normalize-triple-click';export * from './pinned-properties';export * from './pluginManager';export * from './popup';+export * from './progress';// export * from './rewrite'; this has been sunset (for now)export * from './selection-data';export * from './shared';diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/index.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/index.tsnew file mode 100644index 0000000000..e4d4ee7812--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/index.ts@@ -0,0 +1 @@+export * from './progressPlugin';diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.test.tsnew file mode 100644index 0000000000..43c3f0aa49--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.test.ts@@ -0,0 +1,66 @@+import { $createListItemNode, $createListNode } from '@lexical/list';+import { SupportedNodeTypes } from '@macro-inc/lexical-core/node-list';+import { $createTextNode, $getRoot, createEditor } from 'lexical';+import { describe, expect, it } from 'vitest';+import { $getProgressStats } from './progressPlugin';++function $checkbox(text: string, checked: boolean) {+ const item = $createListItemNode(checked);+ item.append($createTextNode(text));+ return item;+}++function $bullet(text: string) {+ const item = $createListItemNode();+ item.append($createTextNode(text));+ return item;+}++describe('$getProgressStats', () => {+ it('counts checked and unchecked leaf checklist items', () => {+ const editor = createEditor({+ namespace: 'progress-plugin-test',+ nodes: SupportedNodeTypes,+ onError: (error) => {+ throw error;+ },+ });++ editor.update(+ () => {+ const checklist = $createListNode('check');+ const parent = $checkbox('group', true);+ const childList = $createListNode('check');+ childList.append($checkbox('nested todo', false));+ parent.append(childList);++ checklist.append(+ $checkbox('done', true),+ $checkbox('todo', false),+ $checkbox('also done', true),+ $checkbox(' ', true),+ parent+ );++ const bullets = $createListNode('bullet');+ bullets.append($bullet('not counted'));++ const nestedChecklist = $createListNode('check');+ nestedChecklist.append($checkbox('structural nested todo', false));+ const wrapper = $createListItemNode();+ wrapper.append(nestedChecklist);+ checklist.append(wrapper);++ $getRoot().clear().append(checklist, bullets);+ },+ { discrete: true }+ );++ editor.getEditorState().read(() => {+ expect($getProgressStats()).toEqual({+ completed: 2,+ total: 5,+ });+ });+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.tsnew file mode 100644index 0000000000..62fe5f0975--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/progress/progressPlugin.ts@@ -0,0 +1,81 @@+import { $isListItemNode, $isListNode, type ListItemNode } from '@lexical/list';+import {+ $getRoot,+ $isElementNode,+ type LexicalEditor,+ type LexicalNode,+ type UpdateListener,+} from 'lexical';+import { createStore, type SetStoreFunction } from 'solid-js/store';++export type ProgressStats = {+ completed: number;+ total: number;+};++export function createProgressStatsStore() {+ return createStore<ProgressStats>({+ completed: 0,+ total: 0,+ });+}++function $hasNestedList(node: ListItemNode): boolean {+ return node.getChildren().some($isListNode);+}++function $hasTextContent(node: ListItemNode): boolean {+ return node.getTextContent().trim() !== '';+}++export function $getProgressStats(): ProgressStats {+ const stats: ProgressStats = {+ completed: 0,+ total: 0,+ };++ function visit(node: LexicalNode) {+ if ($isListItemNode(node)) {+ const checked = node.getChecked();+ if (+ typeof checked === 'boolean' &&+ !$hasNestedList(node) &&+ $hasTextContent(node)+ ) {+ stats.total += 1;+ if (checked) stats.completed += 1;+ }+ }++ if ($isElementNode(node)) {+ for (const child of node.getChildren()) {+ visit(child);+ }+ }+ }++ visit($getRoot());++ return stats;+}++type ProgressPluginProps = {+ setStore: SetStoreFunction<ProgressStats>;+};++function registerProgressPlugin(+ editor: LexicalEditor,+ props: ProgressPluginProps+) {+ const countProgress: UpdateListener = ({ editorState }) => {+ const stats = editorState.read($getProgressStats);+ props.setStore('completed', stats.completed);+ props.setStore('total', stats.total);+ };++ return editor.registerUpdateListener(countProgress);+}++export function progressPlugin(props: ProgressPluginProps) {+ return (editor: LexicalEditor) => registerProgressPlugin(editor, props);+}