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

feature/#507 Implement autoarrange collection #508

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ecaf811
Merge pull request #479 from Lemoncode/vnext
brauliodiez May 9, 2024
0299b06
Refactor h1
deletidev May 22, 2024
3a5f352
Acccessibility improve html structure
deletidev May 22, 2024
a1fd804
Change h2 to h1 in modal
deletidev May 22, 2024
27557d9
Chaged label for pk
deletidev May 22, 2024
86bc22e
Modified labels for checkbox
deletidev May 22, 2024
089bc90
Merge pull request #489 from Lemoncode/fixaccesibility/#488-1-Landing…
brauliodiez May 22, 2024
aa0ff3f
Merge pull request #492 from Lemoncode/fixaccessibilitybug/#481-3-Add…
brauliodiez May 22, 2024
e79f76b
Merge pull request #493 from Lemoncode/fixaccessibilitybug/#483-5-Che…
brauliodiez May 22, 2024
7b81b52
Merge remote-tracking branch 'origin/main' into fixaccessibilitybug/#…
deletidev May 22, 2024
58f1ed7
Merge pull request #491 from Lemoncode/fixaccessibilitybug/#490-2-Imp…
brauliodiez May 22, 2024
85e7673
canvas accessibility removed header buttons
deletidev May 23, 2024
e9069aa
Merge remote-tracking branch 'origin/main' into fixaccessibilitybug/#…
deletidev May 23, 2024
79978b2
Merge pull request #495 from Lemoncode/fixaccessibilitybug/#485-8-Tak…
brauliodiez May 23, 2024
40134a4
Merge pull request #494 from Lemoncode/fixaccessibilitybug/#484-6-Che…
brauliodiez May 23, 2024
a1a459e
Add spaces, and delete invalid aria-label
deletidev May 23, 2024
615ccb6
added html structure to edit page
deletidev May 23, 2024
e9d47e8
Select the text inside the collection name input.
deletidev May 23, 2024
0cc30d2
Merge pull request #496 from Lemoncode/fixaccessibilitybug/#487-12-ma…
brauliodiez May 23, 2024
ef3fe87
Merge pull request #497 from Lemoncode/fixaccessibilitybug/#486-9-li-…
brauliodiez May 23, 2024
87b9668
Merge pull request #498 from Lemoncode/fixaccessibilitybug/#482-4-New…
brauliodiez May 23, 2024
31d0911
accessible custom selects
deletidev May 24, 2024
5a7c37e
Merge pull request #504 from Lemoncode/fixaccessibilitybug/custom-select
brauliodiez Jun 18, 2024
cae02c3
Prevent default behavior on arrow key press in useA11ySelect
deletidev Jun 18, 2024
f18e958
added cursor pointer to install button
deletidev Jun 18, 2024
b1bd029
removed an unnecessary ul
deletidev Jun 18, 2024
b2889e2
Merge pull request #505 from Lemoncode/fixaccessibilitybug/canvas-list
brauliodiez Jun 18, 2024
4686874
Change the labels of the expand nested fields button and add styles f…
deletidev Jun 20, 2024
8c51e6a
one comment deleted
deletidev Jun 20, 2024
1bf5e60
Merge pull request #506 from Lemoncode/fixaccessibilitybug/expand-but…
brauliodiez Jun 20, 2024
b14b551
#507 Added autoarrange collection
Ivanruii Jul 8, 2024
47ccf2b
Removed useless console.log
Ivanruii Jul 9, 2024
567f172
Removing useless function and directly applying the size of the table…
Ivanruii Jul 9, 2024
fb5f9d5
Added comments to facilitate the understanding of the code
Ivanruii Jul 9, 2024
d447e94
Added gap between tables in the placement
Ivanruii Jul 9, 2024
2423c0d
Added animation when creating a table
Ivanruii Jul 9, 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
74 changes: 40 additions & 34 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@
padding-top: 0;
padding-bottom: 4rem;
}
.info__company {
h1 {
display: flex;
align-items: center;
gap: 3%;
flex-direction: column;
}
.info__company img {
width: 12%;
height: 100%;
margin-top: 4px;
}
.info__company h2 {
.info__company {
display: flex;
align-items: center;
gap: 3%;
font-size: clamp(55px, 9vw, 10rem);
color: var(--accent);
background-image: linear-gradient(69deg, #96d9ab 30%, #ffffff 75%);
Expand All @@ -127,11 +129,11 @@
padding-top: 0.9rem;
width: 50%;
}
.info__text h3 {
.info__first {
font-weight: 400;
font-size: 30px;
}
.info__text p {
.info__community {
font-size: 24px;
padding-top: 1.2rem;
color: #fc5969;
Expand All @@ -149,6 +151,7 @@
font-weight: 600;
letter-spacing: 0.2px;
font-size: 20px;
cursor: pointer;
}
.info__group {
display: flex;
Expand Down Expand Up @@ -198,10 +201,10 @@
.info__text {
padding-top: 0;
}
.info__text h3 {
.info__first {
font-size: 26px;
}
.info__text p {
.info__community {
font-size: 20px;
}
.info__group {
Expand Down Expand Up @@ -284,10 +287,10 @@
font-size: 18px;
}

.info__text h3 {
.info__first {
font-size: 22px;
}
.info__text p {
.info__community {
font-size: 19px;
}
.github p {
Expand All @@ -304,7 +307,7 @@
width: 70px;
margin-top: 0;
}
.info__company h2 {
.info__company {
line-height: 1.1;
}
}
Expand Down Expand Up @@ -339,25 +342,28 @@
</a>
</header>
<main class="main">
<div class="info container">
<div class="info__company">
<img
src="/assets/logo_mongo_modeler_dark_mode.svg"
alt="Mongo Modeler Logo"
/>
<h2 class="info__company">Mongo Modeler</h2>
</div>
<h1 class="info__claim">
A free, online Data Modeling tool for MongoDB.
<section class="info container">
<h1>
<span class="info__company">
<img
src="/assets/logo_mongo_modeler_dark_mode.svg"
alt="Mongo Modeler Logo"
/>
Mongo Modeler</span
>
<span class="info__claim">
A free, online Data Modeling tool for MongoDB.
</span>
</h1>
<div class="info__detail">
<div class="info__text">
<h3>
<p class="info__first">
Mongo Modeler is a <span class="highlight">free</span>, open
source <span class="highlight">tool</span> for visualization of
<span class="highlight">MongoDB</span> schema design
</h3>
<p>Community preview</p>
</p>

<p class="info__community">Community preview</p>
<div class="info__group">
<a href="./editor.html" class="info__link"
>Launch MongoDB Designer</a
Expand All @@ -374,17 +380,17 @@ <h3>
></iframe>
</div>
</div>
</div>
<div class="github">
<p class="container">
Interested in suggesting a new feature or reporting a bug? Visit our
project's Github page to make your contribution.
<a href="https://github.com/Lemoncode/mongo-modeler" target="_blank"
>Go to Github</a
>
</p>
</div>
</section>
</main>
<footer class="github">
<p class="container">
Interested in suggesting a new feature or reporting a bug? Visit our
project's Github page to make your contribution.
<a href="https://github.com/Lemoncode/mongo-modeler" target="_blank"
>Go to Github</a
>
</p>
</footer>
<script>
let installPrompt = null;
const installButton = document.querySelector('#install');
Expand Down
19 changes: 19 additions & 0 deletions src/common/a11y/click-outside.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

export const useClickOutside = (
isOpen: boolean,
ref: React.RefObject<HTMLElement>,
callback: (e: MouseEvent) => void
) => {
const handleClickOutside = (e: MouseEvent) => {
callback(e);
};

React.useEffect(() => {
ref.current?.addEventListener('click', handleClickOutside);

return () => {
ref.current?.removeEventListener('click', handleClickOutside);
};
}, [isOpen]);
};
15 changes: 15 additions & 0 deletions src/common/a11y/common.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type BaseA11yOption<Option> = Option & {
tabIndex: number;
};

export type NestedOption<Option> = {
id: string;
children?: Option[];
};

export type FlatOption<Option extends NestedOption<Option>> = Omit<
Option,
'children'
> & {
parentId?: string;
};
13 changes: 13 additions & 0 deletions src/common/a11y/focus.common-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const getArrowUpIndex = (currentIndex: number) => {
const isFirstOption = currentIndex === 0;
return isFirstOption ? currentIndex : currentIndex - 1;
};

export const getArrowDownIndex = (currentIndex: number, options: any[]) => {
const isLastOption = currentIndex === options.length - 1;
return isLastOption ? currentIndex : currentIndex + 1;
};

export const getFocusedOption = <FocusableOption extends { tabIndex: number }>(
options: FocusableOption[]
) => options.find(option => option.tabIndex === 0);
6 changes: 6 additions & 0 deletions src/common/a11y/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './select';
export * from './nested-select';
export * from './on-key.hook';
export * from './focus.common-helpers';
export * from './nested-list';
export * from './common.model';
26 changes: 26 additions & 0 deletions src/common/a11y/list/focus.helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BaseA11yOption } from '../common.model';

export const setInitialFocus = <
Option,
A11yOption extends BaseA11yOption<Option>,
>(
options: Option[]
): A11yOption[] => {
const a11ySelectionOptions = options.map<A11yOption>(
(option, index) =>
({
...option,
tabIndex: index === 0 ? 0 : -1,
}) as unknown as A11yOption
);

return a11ySelectionOptions;
};

export const onFocusOption =
<Option>(option: BaseA11yOption<Option>) =>
(element: any) => {
if (option.tabIndex === 0) {
element?.focus();
}
};
2 changes: 2 additions & 0 deletions src/common/a11y/list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './list.hooks';
export * from './list.model';
95 changes: 95 additions & 0 deletions src/common/a11y/list/list.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React from 'react';
import { BaseA11yOption } from '../common.model';
import { getArrowDownIndex, getArrowUpIndex } from '../focus.common-helpers';
import { useOnKey } from '../on-key.hook';
import { onFocusOption, setInitialFocus } from './focus.helpers';
import { SetInitialFocusFn } from './list.model';
import { useOnTwoKeys } from '../on-two-Keys.hook';

export const useA11yList = <Option, A11yOption extends BaseA11yOption<Option>>(
options: Option[],
onSetInitialFocus: SetInitialFocusFn<Option, A11yOption> = setInitialFocus
) => {
const optionListRef = React.useRef<any>(null);
const [internalOptions, setInternalOptions] = React.useState<A11yOption[]>(
onSetInitialFocus(options)
);

const handleFocus = (event: KeyboardEvent) => {
const currentIndex = internalOptions.findIndex(
option => option.tabIndex === 0
);
const nextIndex =
event.key === 'ArrowUp'
? getArrowUpIndex(currentIndex)
: getArrowDownIndex(currentIndex, internalOptions);

if (currentIndex !== nextIndex) {
setInternalOptions(prevOptions =>
prevOptions.map((option, index) => {
switch (index) {
case currentIndex:
return {
...option,
tabIndex: -1,
};
case nextIndex:
return {
...option,
tabIndex: 0,
};
default:
return option;
}
})
);
}
};

const handleFirstAndLast = (value: number) => {
setInternalOptions(prevOptions =>
prevOptions.map((option, index) => {
switch (index) {
case value:
return {
...option,
tabIndex: 0,
};
default:
return {
...option,
tabIndex: -1,
};
}
})
);
};

//Need this for Mac users
useOnTwoKeys(
optionListRef,
['ArrowUp', 'ArrowDown'],
'Meta',
(event: KeyboardEvent) =>
event.key === 'ArrowUp'
? handleFirstAndLast(0)
: handleFirstAndLast(internalOptions.length - 1)
);

useOnKey(optionListRef, ['ArrowDown', 'ArrowUp'], (event: KeyboardEvent) => {
handleFocus(event);
});

useOnKey(optionListRef, ['Home', 'End'], (event: KeyboardEvent) =>
event.key === 'Home'
? handleFirstAndLast(0)
: handleFirstAndLast(internalOptions.length - 1)
);

return {
optionListRef,
options: internalOptions,
setOptions: setInternalOptions,
onFocusOption,
};
};
3 changes: 3 additions & 0 deletions src/common/a11y/list/list.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SetInitialFocusFn<Option, A11yOption> = (
options: Option[]
) => A11yOption[];
2 changes: 2 additions & 0 deletions src/common/a11y/nested-list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './nested-list.hooks';
export * from './nested-list.model';
29 changes: 29 additions & 0 deletions src/common/a11y/nested-list/nested-list.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
mapFlatOptionsToNestedListOptions,
mapNestedListOptionsToFlatOptions,
} from './nested-list.mappers';
import { NestedOption } from '../common.model';
import { useA11yNested } from '../nested.hooks';
import { useA11yList } from '../list';

export const useA11yNestedList = <Option extends NestedOption<Option>>(
options: Option[]
) => {
const flatOptions = mapNestedListOptionsToFlatOptions(options);

const {
optionListRef,
options: internalOptions,
setOptions,
onFocusOption,
} = useA11yList(flatOptions);

useA11yNested(optionListRef, internalOptions, setOptions);

return {
optionListRef,
options: mapFlatOptionsToNestedListOptions(internalOptions),
setOptions,
onFocusOption,
};
};
Loading
Loading