Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(code): fix jank remounts on code preview iframe, improve top bar styles (#2032)

Seamus9f92bdf1db06
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
index df905ddda2..439fd596e9 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
@@ -359,7 +359,7 @@ export const SegmentedControl: ParentComponent<
class="border-r border-edge-muted last:border-r-0"
>
<KSegmentedControl.ItemInput class="absolute inset-0 pointer-events-none" />
- <KSegmentedControl.ItemLabel class="relative text-ink-muted size-full px-2 py-1 text-xs font-medium data-[checked]:text-ink data-[checked]:bg-ink/10 hover:text-ink hover:bg-ink/15 data-[checked]:hover:bg-ink/20 transition-colors duration-150 block">
+ <KSegmentedControl.ItemLabel class="relative text-ink-muted/70 size-full px-2.5 py-1 text-xs font-medium data-[checked]:text-ink data-[checked]:bg-edge/50 hover:text-ink hover:bg-ink/6 data-[checked]:hover:bg-edge/60 transition-colors duration-150 block">
{itemLabel()}
</KSegmentedControl.ItemLabel>
</KSegmentedControl.Item>
diff --git a/js/app/packages/block-code/component/Block.tsx b/js/app/packages/block-code/component/Block.tsx
index ff60c2c74c..063443e063 100644
--- a/js/app/packages/block-code/component/Block.tsx
+++ b/js/app/packages/block-code/component/Block.tsx
@@ -2,7 +2,14 @@ import { useIsNestedBlock } from '@core/block';
import { useBlockEntityCommands } from '@app/component/next-soup/actions';
import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';
import { blockMetadataSignal } from '@core/signal/load';
-import { createEffect, createMemo, createSignal, on, Show } from 'solid-js';
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ on,
+ Show,
+ Suspense,
+} from 'solid-js';
import { isHtmlFileType } from '../util/fileMode';
import { CodeMarkdown } from './CodeMarkdown';
import { CodeMirror } from './CodeMirror';
@@ -27,6 +34,10 @@ export default function BlockCode() {
})
);
+ createEffect(() => {
+ console.log('MDOE', mode());
+ });
+
return (
<DocumentBlockContainer usesCenterBar>
<Show when={!isNestedBlock} fallback={<CodeMarkdown />}>
@@ -38,7 +49,9 @@ export default function BlockCode() {
onModeChange={setMode}
/>
<Show when={mode() === 'render'} fallback={<CodeMirror />}>
- <HtmlPreview />
+ <Suspense>
+ <HtmlPreview />
+ </Suspense>
</Show>
</ModalsProvider>
</div>
diff --git a/js/app/packages/block-code/component/HtmlPreview.tsx b/js/app/packages/block-code/component/HtmlPreview.tsx
index 2232f1f8e7..28aa6d89aa 100644
--- a/js/app/packages/block-code/component/HtmlPreview.tsx
+++ b/js/app/packages/block-code/component/HtmlPreview.tsx
@@ -1,13 +1,17 @@
import { blockTextSignal } from '@core/signal/load';
+import { createEffect, createMemo } from 'solid-js';
export function HtmlPreview() {
- const blockText = blockTextSignal.get;
+ const blockText = createMemo(blockTextSignal.get);
+ createEffect(() => {
+ console.log(blockText());
+ });
return (
<div class="size-full bg-panel overflow-auto">
<iframe
title="HTML preview"
- class="size-full border-0 bg-white"
+ class="size-full border-0"
sandbox="allow-scripts"
referrerPolicy="no-referrer"
srcdoc={blockText() ?? ''}
diff --git a/js/app/packages/block-code/component/TopBar.tsx b/js/app/packages/block-code/component/TopBar.tsx
index aa32c8e59e..1de80ca9d6 100644
--- a/js/app/packages/block-code/component/TopBar.tsx
+++ b/js/app/packages/block-code/component/TopBar.tsx
@@ -15,7 +15,6 @@ import {
DocumentPropertiesButton,
PROPERTIES_DRAWER_ID,
} from '@core/component/DocumentPropertiesModal';
-import { SegmentedControl } from '@core/component/FormControls/SegmentControls';
import {
ReferencesButton,
REFERENCES_DRAWER_ID,
@@ -39,6 +38,7 @@ import { createCallback } from '@solid-primitives/rootless';
import type { Component } from 'solid-js';
import { Show } from 'solid-js';
import type { CodeBlockMode } from './Block';
+import { TabbedControl } from '@ui/components/TabbedControl';
const { track, TrackingEvents } = withAnalytics();
@@ -115,12 +115,11 @@ export const TopBar: Component<{
<Show when={props.isHtmlFile && !isMobile()}>
<SplitToolbarRight order={-1}>
- <SegmentedControl
+ <TabbedControl
list={[
{ value: 'render', label: 'Render' },
{ value: 'code', label: 'Code' },
]}
- size="SM"
value={props.mode}
onChange={(value) => props.onModeChange(value as CodeBlockMode)}
/>
diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsx
index ce830ce862..794b552e54 100644
--- a/js/app/packages/core/component/TopBar/ShareButton.tsx
+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx
@@ -11,7 +11,6 @@ import {
useBlockId,
useBlockName,
} from '@core/block';
-import { DeprecatedTextButton } from '@core/component/DeprecatedTextButton';
import { DropdownMenuContent, MenuItem } from '@core/component/Menu';
import { UserIcon } from '@core/component/UserIcon';
import { ENABLE_MARKDOWN_COMMENTS } from '@core/constant/featureFlags';
@@ -67,11 +66,11 @@ import {
onCleanup,
onMount,
Show,
+ Suspense,
Switch,
useContext,
} from 'solid-js';
import { match } from 'ts-pattern';
-import { DeprecatedIconButton } from '../DeprecatedIconButton';
import { DialogWrapper } from '../DialogWrapper';
import { ForwardToChannel } from '../ForwardToChannel';
import { Permissions } from '../SharePermissions';
@@ -79,6 +78,9 @@ import { toast } from '../Toast/Toast';
import { Tooltip } from '../Tooltip';
import { openLoginModal } from './LoginButton';
import { ScrollIndicators } from '../VerticalScrollIndicators';
+import { Button } from '@ui/components/Button';
+import { Dynamic } from 'solid-js/web';
+import ChevronDownIcon from '@icon/regular/caret-down.svg';
false && clickOutside;
@@ -542,13 +544,9 @@ export function ShareModal(props: ShareModalProps) {
<div class="shrink-0 flex flex-row items-center justify-between px-2 h-[40px] gap-2 border-b-1 border-b-edge-muted">
<div class="flex flex-row items-center gap-2">
<Dialog.CloseButton>
- <DeprecatedIconButton
- tooltip={{ label: 'Close' }}
- icon={CloseIcon}
- iconSize={16}
- theme="clear"
- size="sm"
- />
+ <Button tooltip="Close" variant="ghost" size="icon-sm">
+ <CloseIcon />
+ </Button>
</Dialog.CloseButton>
<Dialog.Title>{`Share: ${props.name}`}</Dialog.Title>
</div>
@@ -677,14 +675,15 @@ export function ShareModal(props: ShareModalProps) {
Public Link
</div>
<div class="flex items-center p-3 justify-between">
- <DeprecatedTextButton
- onClick={() => copyPublicLink()}
- text="Copy Link"
- height="h-[22px]"
- icon={IconLink}
- theme="accent"
- outline
- />
+ <Button
+ variant="secondary"
+ size="sm"
+ class="flex items-center gap-1 rounded-xs px-2"
+ onClick={copyPublicLink}
+ >
+ <IconLink class="size-4" />
+ Copy Link
+ </Button>
<ShareOptions
permissions={publicAccessLevel() ?? null}
hideNoAccess={props.itemType === 'chat'}
@@ -699,198 +698,6 @@ export function ShareModal(props: ShareModalProps) {
</Dialog>
);
}
-interface ShareButtonProps {
- userPermissions: Permissions; // user permissions are in service-storage/cognition V2 are unified @sharePermissionV2.ts
- copyLink?: () => void; // some blocks have their own copy link function e.g. canvas copies current (x,y) position
- name: string; // document name or chat name
- id: string; // document id or chat id
- itemType: ItemType;
- owner?: string;
-}
-
-export function ShareButton(props: ShareButtonProps) {
- const [isSharePermOpen, setIsSharePermOpen] = createSignal(false);
- const isBlockContext = isInBlock();
- const [fallbackPermissionsResource] = createResource(
- () => {
- if (isBlockContext || !props.id) return;
- return { id: props.id, itemType: props.itemType };
- },
- async (source) => {
- if (!source) return;
- const { id, itemType } = source;
- if (itemType === 'chat') {
- return cognitionApiServiceClient.getChatPermissions({ id });
- } else if (itemType === 'document') {
- return storageServiceClient.getDocumentPermissions({ document_id: id });
- } else if (itemType === 'project') {
- if (id === 'trash') {
- return;
- }
- return storageServiceClient.projects.getPermissions({ id });
- }
- },
- { initialValue: undefined }
- );
- const permissionsResource = isBlockContext
- ? permissionsBlockResource[0]
- : fallbackPermissionsResource;
- const isAuthenticated = useIsAuthenticated();
- const blockType = isBlockContext
- ? useBlockAliasedName()
- : (props.itemType as BlockName | BlockAlias);
- const blockId = isBlockContext ? useBlockId() : props.id;
-
- onMount(() => {
- if (!isBlockContext) return;
- const blockScopeId = blockHotkeyScopeSignal.get;
- registerHotkey({
- keyDownHandler: () => {
- if (!isAuthenticated()) {
- openLoginModal();
- } else {
- track(TrackingEvents.SHARE.OPEN);
- setIsSharePermOpen(true);
- }
- return true;
- },
- hotkeyToken: TOKENS.block.share,
- runWithInputFocused: true,
- scopeId: blockScopeId(),
- description: 'Share',
- hotkey: 'cmd+s',
- });
- });
-
- const referralCode = useReferralCode();
-
- const defaultUrl = () => {
- const params: Record<string, string> = {};
- const code = referralCode();
- if (code) {
- params.referral_code = code;
- }
- return buildSimpleEntityUrl(
- {
- id: blockId ?? '',
- type: blockType,
- },
- params
- );
- };
-
- const { track } = withAnalytics();
-
- const copyLink = createCallback(() => {
- if (props.copyLink) {
- return props.copyLink();
- }
-
- navigator.clipboard.writeText(defaultUrl());
- toast.success(
- 'Link copied to clipboard.',
- 'Sending this link in a Macro message will automatically update permissions to include recipients.'
- );
- });
-
- const ShareLinkAction = createMemo(() => {
- return {
- action: (e: MouseEvent | KeyboardEvent) => {
- e.stopPropagation();
- copyLink();
- },
- icon: IconLink,
- };
- });
-
- const shareAccessLevelText = createMemo(() => {
- const maybeResult = permissionsResource.latest;
- if (!maybeResult || isErr(maybeResult)) {
- return '';
- }
- const [, sharePermission] = maybeResult;
- if (sharePermission.isPublic) {
- return 'Public';
- }
- if (sharePermission.channelSharePermissions?.length) {
- return 'Shared';
- }
- return 'Just me';
- });
-
- return (
- <>
- <div class="border-1 border-edge-muted flex ml-1 items-stretch">
- <Tooltip
- tooltip={
- <div>
- {match(shareAccessLevelText())
- .when(
- (level) => level === 'Public',
- () => 'Anyone with the link can access this item'
- )
- .when(
- (level) => level === 'Shared',
- () => 'Shared with specific people or channels'
- )
- .when(
- (level) => level === 'Just me',
- () => 'Only you can access this item'
- )
- .otherwise(() => 'This item has been shared with you')}
- </div>
- }
- >
- <button
- class="text-[0.75rem] font-mono tracking-wide hover:bg-hover text-ink px-2 flex items-center gap-1 h-full"
- onClick={() => {
- if (!isAuthenticated()) {
- openLoginModal();
- } else {
- track(TrackingEvents.SHARE.OPEN);
- setIsSharePermOpen(true);
- }
- }}
- >
- <Switch fallback={<IconShared class="size-4" />}>
- <Match when={shareAccessLevelText() === 'Public'}>
- <IconGlobe class="size-4" />
- </Match>
- <Match when={shareAccessLevelText() === 'Shared'}>
- <IconUsers class="size-4" />
- </Match>
- <Match when={shareAccessLevelText() === 'Just me'}>
- <IconEyeSlash class="size-4" />
- </Match>
- </Switch>
- SHARE
- </button>
- </Tooltip>
-
- <div class="w-[1px] bg-edge-muted" />
-
- <DeprecatedIconButton
- tooltip={{ label: 'Copy Share Link' }}
- onClick={ShareLinkAction().action}
- icon={ShareLinkAction().icon}
- theme="clear"
- size="sm"
- />
- </div>
-
- <ShareModal
- setIsSharePermOpen={setIsSharePermOpen}
- userPermissions={props.userPermissions}
- isSharePermOpen={isSharePermOpen()}
- itemType={props.itemType}
- owner={props.owner}
- name={props.name}
- blockAlias={blockType}
- id={props.id}
- />
- </>
- );
-}
export function ShareTrigger(props: { copyLink?: () => void }) {
const shareCtx = useShareDialogContext();
@@ -979,7 +786,7 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
}
>
<button
- class="text-[0.75rem] font-mono tracking-wide hover:bg-hover text-ink px-2 flex items-center gap-1 h-full"
+ class="text-xs hover:bg-hover text-ink px-2 flex items-center gap-1 h-full"
onClick={() => {
if (!isAuthenticated()) {
openLoginModal();
@@ -1000,19 +807,21 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
<IconEyeSlash class="size-4" />
</Match>
</Switch>
- SHARE
+ Share
</button>
</Tooltip>
<div class="w-[1px] bg-edge-muted" />
- <DeprecatedIconButton
- tooltip={{ label: 'Copy Share Link' }}
+ <Button
+ tooltip="Copy Share Link"
onClick={ShareLinkAction().action}
- icon={ShareLinkAction().icon}
- theme="clear"
- size="sm"
- />
+ variant="ghost"
+ size="icon-sm"
+ class="p-1"
+ >
+ <Dynamic component={ShareLinkAction().icon} />
+ </Button>
</div>
);
}
@@ -1034,16 +843,18 @@ export function ShareBlockModal(props: {
if (!itemType) return null;
return (
- <ShareModal
- isSharePermOpen={ctx.isOpen()}
- setIsSharePermOpen={(v) => (v ? ctx.open() : ctx.close())}
- id={id}
- blockAlias={blockAlias}
- itemType={itemType}
- name={props.name ?? documentName() ?? ''}
- userPermissions={props.userPermissions ?? permissions()}
- owner={props.owner ?? ownerDerived()}
- />
+ <Suspense>
+ <ShareModal
+ isSharePermOpen={ctx.isOpen()}
+ setIsSharePermOpen={(v) => (v ? ctx.open() : ctx.close())}
+ id={id}
+ blockAlias={blockAlias}
+ itemType={itemType}
+ name={props.name ?? documentName() ?? ''}
+ userPermissions={props.userPermissions ?? permissions()}
+ owner={props.owner ?? ownerDerived()}
+ />
+ </Suspense>
);
}
@@ -1105,15 +916,14 @@ export function ShareOptions(props: {
return (
<DropdownMenu>
<DropdownMenu.Trigger disabled={props.disabled}>
- <DeprecatedTextButton
- text={currentValueText()}
+ <Button
disabled={props.disabled}
- width="w-[67px]"
- height="22px"
- theme="base"
- showChevron
- left
- />
+ class="min-w-[67px] h-[22px] py-2 pl-2 pr-1 rounded-xs flex items-center gap-1"
+ variant="secondary"
+ >
+ {currentValueText()}
+ <ChevronDownIcon class="size-4 text-ink-extra-muted/50" />
+ </Button>
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenuContent>
diff --git a/js/app/packages/ui/components/TabbedControl.tsx b/js/app/packages/ui/components/TabbedControl.tsx
new file mode 100644
index 0000000000..5126bee558
--- /dev/null
+++ b/js/app/packages/ui/components/TabbedControl.tsx
@@ -0,0 +1,42 @@
+import {
+ SegmentedControl as KSegmentedControl,
+ type SegmentedControlRootProps,
+} from '@kobalte/core/segmented-control';
+import { For, type ParentComponent } from 'solid-js';
+
+export const TabbedControl: ParentComponent<
+ {
+ list: { value: string; label: string }[];
+ value?: string;
+ defaultValue?: string;
+ } & Omit<SegmentedControlRootProps, 'defaultValue'>
+> = (props) => {
+ return (
+ <KSegmentedControl
+ class="w-full text-sm rounded-xs border border-edge-muted relative overflow-hidden"
+ value={props.value}
+ defaultValue={props.defaultValue ?? props.list[0]?.value}
+ onChange={props.onChange}
+ disabled={props.disabled}
+ >
+ <div class="relative" role="presentation">
+ <div class="flex" role="presentation">
+ <For each={props.list}>
+ {(item) => (
+ <KSegmentedControl.Item
+ value={item.value}
+ disabled={props.disabled}
+ class="border-r border-edge-muted last:border-r-0"
+ >
+ <KSegmentedControl.ItemInput class="absolute inset-0 pointer-events-none" />
+ <KSegmentedControl.ItemLabel class="relative text-ink-muted/70 size-full px-2.5 py-1 text-xs font-medium data-[checked]:text-ink data-[checked]:bg-edge/50 hover:text-ink hover:bg-ink/6 data-[checked]:hover:bg-edge/60 block">
+ {item.label}
+ </KSegmentedControl.ItemLabel>
+ </KSegmentedControl.Item>
+ )}
+ </For>
+ </div>
+ </div>
+ </KSegmentedControl>
+ );
+};
diff --git a/js/app/packages/ui/index.ts b/js/app/packages/ui/index.ts
index 586c504823..646e725f67 100644
--- a/js/app/packages/ui/index.ts
+++ b/js/app/packages/ui/index.ts
@@ -1 +1,2 @@
export { GlitchText } from './components/GlitchText';
+export { TabbedControl } from './components/TabbedControl';