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

tldraw using /sync #158

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
755582c
rough proof of concept prototype
robertschnuell Jan 18, 2024
760e72e
adding invite function from /write to /draw
robertschnuell Jan 19, 2024
eb4b433
The template should === the name of the service provider, which is `t…
fnwbr Jan 19, 2024
ee8050d
Bring `join_rule`, and `type` in line with other services (such as /w…
fnwbr Jan 19, 2024
f55b28d
Add tldraw auth provider stub
fnwbr Jan 19, 2024
b9abdd0
Merge branch 'main' into tldraw
fnwbr Jan 19, 2024
f53bfcb
mute notifications for tldraw rooms
robertschnuell Feb 2, 2024
5aec7f8
Merge branch 'main' into tldraw
fnwbr Feb 2, 2024
315bdcb
Update icons and package-lock.json after merge w/ main
fnwbr Feb 2, 2024
bc076ef
Remove unused imports
fnwbr Feb 2, 2024
78b359a
Merge branch 'main' into tldraw
fnwbr Feb 28, 2024
a69bde2
Fix previous merge w/ main
fnwbr Feb 28, 2024
465f7a1
Random cleanups, let Prettier do its thing & use Tailwind
fnwbr Feb 28, 2024
665f9df
Update tldraw to 2.0.0-beta.4
fnwbr Feb 28, 2024
4c48732
Add _tldrawOverrides.css (forgot this in previous commit)
fnwbr Feb 28, 2024
df11b4c
https://tldraw.dev/examples/basic/infer-dark-mode
fnwbr Feb 28, 2024
23df32f
Make ESLint happy
fnwbr Feb 28, 2024
7fb7b10
Merge branch 'main' into tldraw
fnwbr Feb 28, 2024
763b889
Fix dependencies
fnwbr Feb 28, 2024
d767a75
Merge branch 'main' into tldraw
fnwbr Mar 5, 2024
a468a91
Merge branch 'main' into tldraw
fnwbr Mar 6, 2024
540dc16
Merge branch 'main' into tldraw
fnwbr Mar 7, 2024
510e7af
Tidy up and move /pages/draw directory to /pages/tldraw
fnwbr Mar 7, 2024
5cea59d
Replace "TldrawMatrixProvider" with an in-page room-specific Matrix c…
fnwbr Mar 7, 2024
9031185
Merge branch 'main' into tldraw-alternative-roadblock
fnwbr Mar 12, 2024
0bd939e
Bring back TldrawAuthProvider
fnwbr Mar 12, 2024
cad98c6
Update tldraw to latest 2.0.2
fnwbr Mar 19, 2024
e73d201
Use /sync call to read + write tldraw shapes from and to the Matrix
fnwbr Mar 19, 2024
a103db6
Remove now unused files from Robert's prototype
fnwbr Mar 19, 2024
fc7cd2b
Make sure we always set the thread ROOT event ID
fnwbr Mar 20, 2024
514e824
Always render a new TldrawEditor per Matrix room
fnwbr Mar 20, 2024
de7b353
Use a 2500ms interval to throttle sending changes to the Matrix
fnwbr Mar 20, 2024
ece6d81
Allow for read-only tldraws
fnwbr Mar 20, 2024
41e1f93
Fix dependencies
fnwbr Mar 20, 2024
c677b0a
Add @TODO
fnwbr Mar 20, 2024
a99a87a
Add debug logs
fnwbr Mar 20, 2024
df987fc
Specify set of tldraw tools that we want (requires [email protected])
fnwbr Mar 21, 2024
946f203
Hide main menu + pages menu
fnwbr Mar 21, 2024
741d85d
Fix signout not working
fnwbr Mar 21, 2024
734ceba
adding local assets
robertschnuell Mar 21, 2024
fce93a2
Removed tlDraw logs/overlay from production.
robertschnuell Mar 26, 2024
fb6f81b
fixing the newly introduced tldraw 'content disappearing bug' (hopefu…
robertschnuell Mar 26, 2024
fcd821b
force focusing the editor
robertschnuell Mar 27, 2024
5ffc71e
autoFocus does not need to be set.
robertschnuell Mar 27, 2024
780a016
fix: do not try to (re-)auth via tldraw provider
andirueckel Apr 10, 2024
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
12 changes: 12 additions & 0 deletions assets/_tldrawOverrides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.tl-container {
--layer-background: 20;
--layer-grid: 21;
--layer-canvas: 22;
--layer-shapes: 30;
--layer-panels: 30;
--layer-menus: 31;
--layer-overlays: 32;
--layer-toasts: 33;
--layer-cursor: 34;
--layer-following-indicator: 35;
}
6 changes: 6 additions & 0 deletions components/TldrawEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Tldraw } from 'tldraw';

/**
* Make sure to use NextJS' `dynamic()` helper to import this component.
*/
export default Tldraw;
7 changes: 7 additions & 0 deletions components/layouts/partials/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export default function Navigation({ closeNavigation }) {
</Link>
</li>
)}
{ _.get(getConfig(), 'publicRuntimeConfig.authProviders.tldraw.path') && (
<li>
<Link href={getConfig().publicRuntimeConfig.authProviders.tldraw.path}>
{ getConfig().publicRuntimeConfig.authProviders.tldraw.path }
</Link>
</li>
) }
</List>
<List>
<li>
Expand Down
2 changes: 2 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = {
// path: '/sketch',
// baseUrl: 'http://spacedeck.localhost',
// },
tldraw: {
},
},
// contextRootSpaceRoomId: '!gB.....Ewlvdq:matrix.org',
account: {
Expand Down
2 changes: 2 additions & 0 deletions lib/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MatrixAuthProvider from './auth/MatrixAuthProvider';
import PeerTubeAuthProvider from './auth/PeerTubeAuthProvider';
import MyPadsAuthProvider from './auth/MyPadsAuthProvider';
import SpacedeckAuthProvider from './auth/SpacedeckAuthProvider';
import TldrawAuthProvider from '@/lib/auth/TldrawAuthProvider';

/*
Mapping of authentication provider types and which corresponding class should be used to actually perform
Expand All @@ -19,6 +20,7 @@ const AuthProviders = {
peerTube: PeerTubeAuthProvider,
etherpad: MyPadsAuthProvider,
spacedeck: SpacedeckAuthProvider,
tldraw: TldrawAuthProvider,
};

function useAuthProvider() {
Expand Down
18 changes: 17 additions & 1 deletion lib/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'rea
import getConfig from 'next/config';
import _ from 'lodash';
import { useImmer } from 'use-immer';
import { ClientEvent, EventTimeline, EventType, RoomEvent } from 'matrix-js-sdk';
import { ClientEvent, EventTimeline, EventType, RoomEvent, PushRuleKind, PushRuleActionName } from 'matrix-js-sdk';

import logger from './Logging';

Expand Down Expand Up @@ -49,6 +49,21 @@ function useMatrixProvider(auth) {

const roomState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);

const pushRules = matrixClient.getAccountData('m.push_rules')?.event?.content?.global?.override;
const rule = pushRules?.find((rule) => rule.rule_id === roomId);
const metaEvent = roomState.getStateEvents('dev.medienhaus.meta', '')?.getContent();

// we check if we have an metaevent avaialble and if the template is 'sketch-link' and if the rule is not set to 'dont_notify' we will set a push rule to 'dont_notify' for this room
// for future purposes we should not check for item instead for the templates which needs to be muted
if (metaEvent && metaEvent.type === 'item') {
if (!rule || !rule?.actions.includes(PushRuleActionName.DontNotify)) {
matrixClient.addPushRule('global', PushRuleKind.Override, roomId, {
conditions: [{ kind: 'event_match', key: 'room_id', pattern: roomId }],
actions: [PushRuleActionName.DontNotify],
});
}
}

return {
roomId,
name: room.name,
Expand Down Expand Up @@ -212,6 +227,7 @@ function useMatrixProvider(auth) {
*/
(event, room) => {
// If this is a timeline event for a room that we're not a member of, we want to ignore it
// console.log('RoomTimelineEvent', event, room);
if (room.getMyMembership() !== 'join') return;

// Update our room-typical stores (rooms, spaces, directMessages)
Expand Down
5 changes: 5 additions & 0 deletions lib/Tldraw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import getConfig from 'next/config';

const path = getConfig().publicRuntimeConfig.authProviders.tldraw?.path || '/draw';

export { path };
7 changes: 7 additions & 0 deletions lib/auth/TldrawAuthProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* This is a stub. tldraw is not -really- an authentication provider.
* (see https://github.com/medienhaus/medienhaus-spaces/issues/152)
*/
class TldrawAuthProvider {}

export default TldrawAuthProvider;
13 changes: 13 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ module.exports = {
);
}

if (SpacesConfig.authProviders.tldraw) {
rewriteConfig.push(
{
source: SpacesConfig.authProviders.tldraw.path,
destination: '/tldraw',
},
{
source: SpacesConfig.authProviders.tldraw.path + '/:roomId',
destination: '/tldraw/:roomId',
},
);
}

return rewriteConfig;
},
};
Loading
Loading