Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
8d7905e5
Commit
8d7905e5
authored
2 years ago
by
Loïc Correnson
Browse files
Options
Downloads
Patches
Plain Diff
[dome] new data/array component
parent
3cdcaaab
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ivette/src/dome/renderer/data/arrays.ts
+45
-0
45 additions, 0 deletions
ivette/src/dome/renderer/data/arrays.ts
ivette/src/dome/renderer/dnd.tsx
+1
-22
1 addition, 22 deletions
ivette/src/dome/renderer/dnd.tsx
with
46 additions
and
22 deletions
ivette/src/dome/renderer/data/arrays.ts
0 → 100644
+
45
−
0
View file @
8d7905e5
/* ************************************************************************ */
/* */
/* This file is part of Frama-C. */
/* */
/* Copyright (C) 2007-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
/* you can redistribute it and/or modify it under the terms of the GNU */
/* Lesser General Public License as published by the Free Software */
/* Foundation, version 2.1. */
/* */
/* It is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* See the GNU Lesser General Public License version 2.1 */
/* for more details (enclosed in the file licenses/LGPLv2.1). */
/* */
/* ************************************************************************ */
/**
Safe ARRAY utilities.
@packageDocumentation
@module dome/data/arrays
*/
/** Swaps items at index i and j if they are both in range. */
export
function
swap
<
A
>
(
ls
:
A
[],
a
:
number
,
b
:
number
):
A
[]
{
const
n
=
ls
.
length
;
if
(
a
===
b
||
0
>
a
||
a
>=
n
||
0
>
b
||
b
>=
n
)
return
ls
;
const
[
i
,
j
]
=
a
<
b
?
[
a
,
b
]
:
[
b
,
a
];
return
ls
.
slice
(
0
,
i
).
concat
(
ls
.
slice
(
i
+
1
,
j
+
1
),
ls
[
i
],
ls
.
slice
(
j
+
1
));
}
/** Remove item at index i when in range. */
export
function
removeAt
<
A
>
(
ls
:
A
[],
k
:
number
):
A
[]
{
return
0
<=
k
&&
k
<
ls
.
length
?
ls
.
slice
(
0
,
k
).
concat
(
ls
.
slice
(
k
+
1
))
:
ls
;
}
/** Insert an item at index i when in range or off-by-one. */
export
function
insertAt
<
A
>
(
ls
:
A
[],
id
:
A
,
k
:
number
):
A
[]
{
return
0
<=
k
&&
k
<=
ls
.
length
?
ls
.
slice
(
0
,
k
).
concat
(
id
,
ls
.
slice
(
k
))
:
ls
;
}
This diff is collapsed.
Click to expand it.
ivette/src/dome/renderer/dnd.tsx
+
1
−
22
View file @
8d7905e5
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
classes
,
styles
}
from
'
dome/misc/utils
'
;
import
{
classes
,
styles
}
from
'
dome/misc/utils
'
;
import
{
swap
}
from
'
dome/data/arrays
'
;
import
{
import
{
DraggableCore
,
DraggableCore
,
DraggableEvent
,
DraggableEvent
,
...
@@ -412,28 +413,6 @@ export function DragSource(props: DragSourceProps): JSX.Element {
...
@@ -412,28 +413,6 @@ export function DragSource(props: DragSourceProps): JSX.Element {
);
);
}
}
/* -------------------------------------------------------------------------- */
/* --- Ordering --- */
/* -------------------------------------------------------------------------- */
/** Swaps items at index i and j if they are both in range. */
export
function
swap
<
A
>
(
ls
:
A
[],
a
:
number
,
b
:
number
):
A
[]
{
const
n
=
ls
.
length
;
if
(
a
===
b
||
0
>
a
||
a
>=
n
||
0
>
b
||
b
>=
n
)
return
ls
;
const
[
i
,
j
]
=
a
<
b
?
[
a
,
b
]
:
[
b
,
a
];
return
ls
.
slice
(
0
,
i
).
concat
(
ls
.
slice
(
i
+
1
,
j
+
1
),
ls
[
i
],
ls
.
slice
(
j
+
1
));
}
/** Remove item at index i when in range. */
export
function
removeAt
<
A
>
(
ls
:
A
[],
k
:
number
):
A
[]
{
return
0
<=
k
&&
k
<
ls
.
length
?
ls
.
slice
(
0
,
k
).
concat
(
ls
.
slice
(
k
+
1
))
:
ls
;
}
/** Insert an item at index i when in range or off-by-one. */
export
function
insertAt
<
A
>
(
ls
:
A
[],
id
:
A
,
k
:
number
):
A
[]
{
return
0
<=
k
&&
k
<=
ls
.
length
?
ls
.
slice
(
0
,
k
).
concat
(
id
,
ls
.
slice
(
k
))
:
ls
;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- List Container --- */
/* --- List Container --- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment