Skip to content
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

feat: page editor #240

Merged
merged 51 commits into from
Mar 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d3836a3
TipTap basic editor
badgeth-dao Mar 1, 2023
e11c45b
Merge branch 'master' into tip-tap
badgeth-dao Mar 6, 2023
202589a
Exploring tip tap commands
badgeth-dao Mar 6, 2023
9059533
Exploring how to toggle state
badgeth-dao Mar 6, 2023
8b42d2f
Rendering tip tap custom react component
badgeth-dao Mar 7, 2023
779f498
Show header boolean prop toggle added to entity table container
badgeth-dao Mar 7, 2023
2e0ce78
Rename react component to table-node
badgeth-dao Mar 7, 2023
1633096
Insert table with click
badgeth-dao Mar 7, 2023
6536fc6
Memoize this shit
badgeth-dao Mar 7, 2023
6542d84
Inserting table node with a paragraph after
badgeth-dao Mar 7, 2023
766b9af
Command list looking fly
badgeth-dao Mar 8, 2023
e11e8b2
Image start
badgeth-dao Mar 8, 2023
44bb000
Memoize some things
badgeth-dao Mar 8, 2023
10635d5
Custom v2 page for reading/writing TipTap
badgeth-dao Mar 8, 2023
2c1efac
Exploring how to add this plus button in tiptap...
badgeth-dao Mar 8, 2023
2c1ccf0
It works for plus button too
badgeth-dao Mar 8, 2023
9e2c9a8
Commands looking good
badgeth-dao Mar 9, 2023
3f13cc7
Frustrating ability to style components
badgeth-dao Mar 9, 2023
1d84ab5
Command list showing up properly
badgeth-dao Mar 9, 2023
bf2e50b
Command list popover best
badgeth-dao Mar 9, 2023
0b1957d
Merge branch 'master' into tip-tap-v2-bugfix
badgeth-dao Mar 10, 2023
2e5501d
Type fetching for table
badgeth-dao Mar 10, 2023
8f10b20
Simpler command code
badgeth-dao Mar 10, 2023
fbd4b86
Inserting table of type
badgeth-dao Mar 10, 2023
e0fc423
Type fixing
badgeth-dao Mar 10, 2023
b0f0379
Working on serializing data
badgeth-dao Mar 10, 2023
a2958f2
Wire up Docker to TipTap's private registry
badgeth-dao Mar 14, 2023
2c9636b
Producing a lot of blocks
badgeth-dao Mar 14, 2023
ff7bf8f
Loading blocks step 1
badgeth-dao Mar 14, 2023
8425719
Load blocks
badgeth-dao Mar 14, 2023
7ac4e3f
More comments on how this Editing works
badgeth-dao Mar 15, 2023
9b8c5c3
Tiptap hell
badgeth-dao Mar 15, 2023
f303a6b
WIP on block IDs triple
badgeth-dao Mar 15, 2023
50b72e9
Tip tap v2 hell
badgeth-dao Mar 15, 2023
1f6ef2e
Content goodness
badgeth-dao Mar 15, 2023
94c38cf
Minor clean up on the code
badgeth-dao Mar 15, 2023
8784f8f
WIP
badgeth-dao Mar 16, 2023
373af10
Making entity-store look like edit-events
badgeth-dao Mar 16, 2023
1cdf01e
Setting the parent entity on blocks
badgeth-dao Mar 16, 2023
1871b82
Clean up unused code in editor
badgeth-dao Mar 17, 2023
f5bae4d
Figuring out how to create our home-brew UUID extension
badgeth-dao Mar 17, 2023
ae61e50
ID generation working
badgeth-dao Mar 20, 2023
6a3604e
Update test
badgeth-dao Mar 20, 2023
9290320
Fixing re-render and id problem
badgeth-dao Mar 20, 2023
f82dd14
Remove unused packages
badgeth-dao Mar 20, 2023
d34e011
Ensure paste works for editor
badgeth-dao Mar 20, 2023
f8ccffb
Make name property from EntityStore computed
badgeth-dao Mar 21, 2023
d289bd4
Remove unneeded memoization and guard statement
badgeth-dao Mar 21, 2023
b36ff25
Remove uneeded useEffect
badgeth-dao Mar 22, 2023
63e6ce1
Rebuilt
badgeth-dao Mar 22, 2023
6e97e6c
Merge branch 'master' into tip-tap-editor
badgeth-dao Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make name property from EntityStore computed
badgeth-dao committed Mar 21, 2023
commit f8ccffba63dfd3829856930f4e09199123c08d90
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ describe('Editable Entity Page', () => {
<EntityStoreProvider
id={'1'}
spaceId={'1'}
name="Banana"
initialBlockIdsTriple={null}
initialBlockTriples={[]}
initialTriples={[]}
@@ -49,7 +48,6 @@ describe('Editable Entity Page', () => {
<EntityStoreProvider
id={'1'}
spaceId={'1'}
name="Banana"
initialBlockIdsTriple={null}
initialBlockTriples={[]}
initialTriples={[]}
8 changes: 7 additions & 1 deletion apps/web/modules/components/entity/editor/editor.tsx
Original file line number Diff line number Diff line change
@@ -36,6 +36,10 @@ export const Editor = ({ editable = true }: Props) => {
editable: editable,
content: entityStore.editorJson,
onBlur({ editor }) {
/*
Responsible for converting all editor blocks to triples
Fires after the IdExtension's onBlur event which sets the "id" attribute on all nodes
*/
entityStore.updateEditorBlocks(editor);
},
editorProps: {
@@ -45,12 +49,14 @@ export const Editor = ({ editable = true }: Props) => {
[editable]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEditor takes a dependency array - I think there's potential for problems if entityStore.editorJson isn't fully hydrated by the time we reach this point.

We don't always want editorJson as a dependency however, since it will update onBlur and defocus and close our command popover triggered by the "/" or the "+" button.

Will know if this is a problem once we put it into our actual entity page.

);

const openCommandMenu = () => editor?.chain().focus().insertContent('/').run();

return editor ? (
<>
<EditorContent editor={editor} />
<FloatingMenu editor={editor}>
<div className="absolute -left-12 -top-3">
<SquareButton onClick={() => editor.chain().focus().insertContent('/').run()} icon="plus" />
<SquareButton onClick={openCommandMenu} icon="plus" />
</div>
</FloatingMenu>
</>
4 changes: 4 additions & 0 deletions apps/web/modules/components/entity/editor/id-extension.tsx
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ export const IdExtension = Extension.create({
];
},
onBlur() {
/*
Responsible for setting the "id" attribute on all news nodes
Fires before the Editor's onBlur event which saves the editor blocks to the entity store
*/
const { view, state } = this.editor;
const { tr, doc } = state;

Original file line number Diff line number Diff line change
@@ -16,13 +16,11 @@ interface Props {
initialSchemaTriples: Triple[];
initialBlockIdsTriple: Triple | null;
initialBlockTriples: Triple[];
name: string;
}

export function EntityStoreProvider({
id,
spaceId,
name,
children,
initialBlockIdsTriple,
initialBlockTriples,
@@ -35,7 +33,6 @@ export function EntityStoreProvider({
const store = useMemo(() => {
return new EntityStore({
api: network,
name,
spaceId,
initialBlockIdsTriple,
initialBlockTriples,
@@ -47,7 +44,6 @@ export function EntityStoreProvider({
}, [
network,
spaceId,
name,
initialBlockTriples,
initialTriples,
initialBlockIdsTriple,
14 changes: 8 additions & 6 deletions apps/web/modules/entity/entity-store/entity-store.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import { INetwork } from '~/modules/services/network';
import { Triple } from '~/modules/triple';
import { EntityValue, Triple as TripleType } from '~/modules/types';
import { Value } from '~/modules/value';
import { Entity } from '..';

const markdownConverter = new showdown.Converter();

@@ -77,7 +78,6 @@ interface IEntityStoreConfig {
initialBlockIdsTriple: TripleType | null;
initialBlockTriples: TripleType[];
ActionsStore: ActionsStore;
name: string;
}

export class EntityStore implements IEntityStore {
@@ -94,7 +94,7 @@ export class EntityStore implements IEntityStore {
hiddenSchemaIds$: Observable<string[]> = observable<string[]>([]);
ActionsStore: ActionsStore;
abortController: AbortController = new AbortController();
name: string;
name: ObservableComputed<string>;

constructor({
api,
@@ -105,13 +105,11 @@ export class EntityStore implements IEntityStore {
spaceId,
id,
ActionsStore,
name,
}: IEntityStoreConfig) {
const defaultTriples = createInitialDefaultTriples(spaceId, id);

this.id = id;
this.api = api;
this.name = name;
this.schemaTriples$ = observable([...initialSchemaTriples, ...defaultTriples]);
this.spaceId = spaceId;
this.ActionsStore = ActionsStore;
@@ -139,6 +137,10 @@ export class EntityStore implements IEntityStore {
);
});

this.name = computed(() => {
return Entity.name(this.triples$.get()) || '';
});

this.blockTriples$ = computed(() => {
const spaceActions = ActionsStore.actions$.get()[spaceId] ?? [];
const blockIds = this.blockIds$.get();
@@ -475,7 +477,7 @@ export class EntityStore implements IEntityStore {
entityName: this.nodeName(node),
attributeId: SYSTEM_IDS.PARENT_ENTITY,
attributeName: 'Parent Entity',
value: { id: this.id, type: 'entity', name: this.name },
value: { id: this.id, type: 'entity', name: this.name.get() },
})
);
}
@@ -520,7 +522,7 @@ export class EntityStore implements IEntityStore {
const triple = Triple.withId({
space: this.spaceId,
entityId: this.id,
entityName: this.name,
entityName: this.name.get(),
attributeId: SYSTEM_IDS.BLOCKS,
attributeName: 'Blocks',
value: {
1 change: 0 additions & 1 deletion apps/web/pages/space/[id]/[entityId].tsx
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ export default function EntityPage(props: Props) {
return (
<EntityStoreProvider
id={props.id}
name={props.name}
spaceId={props.space}
initialTriples={props.triples}
initialSchemaTriples={props.schemaTriples}
1 change: 0 additions & 1 deletion apps/web/pages/space/[id]/[entityId]/v2.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm making changes to the main [entityId].tsx page which will probably cause issues when you try and migrate this v2 page over. We might want to get in my versioning changes on the page before we migrate the editor over.

Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ export default function EntityPage(props: Props) {
<EntityStoreProvider
id={props.id}
spaceId={props.space}
name={props.name}
initialTriples={props.triples}
initialSchemaTriples={props.schemaTriples}
initialBlockIdsTriple={props.blockIdsTriple}
1 change: 0 additions & 1 deletion apps/web/pages/space/[id]/create-entity.tsx
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ export default function CreateEntity({ spaceId }: Props) {
<EntityStoreProvider
id={newId}
spaceId={spaceId}
name=""
initialTriples={[]}
initialSchemaTriples={[]}
initialBlockTriples={[]}