Skip to content

Instantly share code, notes, and snippets.

@euglv
Forked from 3cp/index.html
Last active November 19, 2024 08:20
Show Gist options
  • Save euglv/af84e525e5d72b340c64ada8c75f8b90 to your computer and use it in GitHub Desktop.
Save euglv/af84e525e5d72b340c64ada8c75f8b90 to your computer and use it in GitHub Desktop.
bcx-aurelia-reorderable-repeat example: multi-lists
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to aurelia-bootstrapper
(data-main attribute on script) for Aurelia,
The aurelia bootstrapper then loads up user module "main"
(aurelia-app attribute on <body>) which is your src/main.js.
-->
<body aurelia-app="main">
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script>
</body>
</html>
{
"dependencies": {
"aurelia-bootstrapper": "^2.3.3"
}
}
<template>
<require from="./container"></require>
<container></container>
</template>
export class App {
message = 'Hello Aurelia!';
}
.container {
display: flex;
align-items: start;
width: 250px;
margin: 5px;
}
.list {
flex: 1 1 0;
margin: 10px;
padding: 10px;
background-color: #eee;
}
.item {
display: block;
box-sizing: border-box;
border: 1px solid #888;
height: 40px;
text-align: center;
line-height: 40px;
overflow: hidden;
background: white;
}
.item:not(:first-child) {
margin-top: -1px;
}
.item.reorderable-repeat-dragging-me {
visibility: visible; /* unset visibility: hidden */
color: transparent; /* hide text */
background-color: #ddd;
}
.list .placeholder {
display: none;
}
.list .reorderable-repeat-reordering:not(.reorderable-repeat-dragging-me) .placeholder {
--b1: 100% 0 0;
--b2: 96.1151% 0 0;
display: inline-block;
border:blue solid 1px;
min-width: 100px;
min-height: 1rem;
background-image: repeating-linear-gradient(45deg, var(--fallback-b1, oklch(var(--b1))), var(--fallback-b1, oklch(var(--b1))) 13px, var(--fallback-b2, oklch(var(--b2))) 13px, var(--fallback-b2, oklch(var(--b2))) 14px);
background-size: 40px 40px;
}
li.reorderable-repeat-dragging-me {
visibility: visible; /* unset visibility: hidden */
/*color: transparent; /* hide text */
background-color: green;
background-image: repeating-linear-gradient(45deg, var(--fallback-b1, oklch(var(--b1))), var(--fallback-b1, oklch(var(--b1))) 13px, var(--fallback-b2, oklch(var(--b2))) 13px, var(--fallback-b2, oklch(var(--b2))) 14px);
background-size: 40px 40px;
opacity:0.5;
}
<template>
<require from="./container.css"></require>
<require from="./list-item"></require>
<div class="container">
<div class="list">
Numbers
<div
class="item"
reorderable-repeat.for="item of numbers"
reorderable-group="alphanumeric">
${item.name || item}
</div>
</div>
<div class="list">
Letters
<div
class="item"
reorderable-repeat.for="item of letters"
reorderable-group="alphanumeric">
${item.name || item}
</div>
</div>
</div>
<div class="container">
<div class="list">
Tree
<list-item item.bind="root">
</list-item>
</div>
</div>
</template>
export class Container {
numbers = [0, 1, 2];
letters = ['a', 'b'];
name = 'root';
children = [
{name: 'level1'},
{name: 'level1'},
{name: 'level1', children: [
{name: 'level2',
children: [{name: 'level3'}]
},
{name: 'level2'}
]},
{name: 'level1'}
];
root;
constructor() {
this.root = this
};
}
<template>
${item.name || item}
<ul reorderable-group-for.bind="item.children">
<li if.bind="item.children.length" as-element="list-item" reorderable-repeat.for="child of item.children" reorderable-group="alphanumeric" item.bind="child"></li>
<li else class="placeholder" reorderable-group-for.bind="item.children"> </li>
</ul>
</template>
import {inject, bindable, computedFrom} from 'aurelia-framework';
import {DndService} from 'bcx-aurelia-dnd';
export class ListItem {
@bindable item;
itemChanged(item) {
if (! (item instanceof Object)
return this.item = {name: item, children: []};
if (!item.children)
item.children = [];
}
}
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging('info')
.plugin('bcx-aurelia-reorderable-repeat');
aurelia.start().then(() => aurelia.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment