Skip to content

Commit

Permalink
fix: Element display & updates handling
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Jul 5, 2024
1 parent 560e279 commit 34f7a54
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
17 changes: 14 additions & 3 deletions apps/web/src/lib/editor/extensions/block-action-menu/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const options: Record<
const OptionsDropdown: Component<OptionsDropdownProps> = (props) => {
const [opened, setOpened] = createSignal(false);
const availableOptions = createMemo(() => {
opened;
opened();

return (
options[props.node.type.name]?.filter((option) => {
Expand Down Expand Up @@ -138,14 +138,25 @@ const OptionsDropdown: Component<OptionsDropdownProps> = (props) => {
<div class="flex flex-col gap-1">
<For each={availableOptions()}>
{(option) => {
const path = (): string => {
if (!opened()) return "";

return typeof option.icon === "function" ? option.icon(props) : option.icon;
};
const label = (): string => {
if (!opened()) return "";

return typeof option.label === "function" ? option.label(props) : option.label;
};

return (
<IconButton
class="m-0 w-full justify-start"
text={option.color || "soft"}
color={option.color || "base"}
variant="text"
path={typeof option.icon === "function" ? option.icon(props) : option.icon}
label={typeof option.label === "function" ? option.label(props) : option.label}
path={path()}
label={label()}
onClick={() => {
option.onClick(props);
setOpened(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const BlockActionMenuPlugin = Extension.create({
onFocus() {
box.style.display = "block";
},
onSelectionUpdate() {
onTransaction() {
repositionMenu(this.editor as SolidEditor);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ElementDisplay } from "./view-manager";
import { isElementSelection } from "./selection";
import { NodeViewRendererProps } from "@tiptap/core";
import { SolidEditor, SolidRenderer } from "@vrite/tiptap-solid";
import { ExtensionElementViewContext, ExtensionElement } from "@vrite/sdk/extensions";
Expand Down Expand Up @@ -119,6 +120,14 @@ const customNodeView = ({
contentHole.append(buttonContainer);
}

const { selection } = editor.state;
const selectionPos = selection.$from.pos;
const pos = typeof props.getPos === "function" ? props.getPos() : null;

if (pos === selectionPos && isElementSelection(selection)) {
wrapper.classList.add("ring", "ring-primary", "ring-2");
}

return {
onSelect() {
wrapper.classList.add("ring", "ring-primary", "ring-2");
Expand Down
15 changes: 13 additions & 2 deletions apps/web/src/lib/editor/extensions/xml-node-menu/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,21 @@ const ElementMenuEditor = lazy(async () => {
return;
}

// TODO: Handle word wrap
if (code) {
code.textContent = value;
// WARNING: This is a private API
const viewModel = (codeEditor as any)._modelData.viewModel as Pick<
monaco.editor.ITextModel,
"getLineCount" | "getLineContent"
>;

requestAnimationFrame(() => {
let viewModelContent = "";

for (let i = 1; i <= viewModel.getLineCount(); i++) {
viewModelContent += `${viewModel.getLineContent(i)}\n`;
}

code.textContent = viewModelContent.trim();
code.style.minHeight = `${codeEditor.getContentHeight()}px`;
});
}
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/views/content-piece/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ const ContentPieceView: Component = () => {
/>
</div>
</CollapsibleSection>
<CollapsibleSection icon={mdiCodeJson} label="Custom data" defaultOpened={false}>
<CollapsibleSection
icon={mdiCodeJson}
label="Custom JSON data"
defaultOpened={false}
>
<div class="w-full">
<CustomDataSection
editable={editable()}
Expand Down

0 comments on commit 34f7a54

Please sign in to comment.