Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <a-folder id="root"></a-folder>
              
            
!

CSS

              
                body {
  padding: 10px;
}

@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,700');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Roboto Mono", "Lucida Console", Monaco, monospace;
  font-size: 14px;
  color: #000;
}

ul {
  list-style: none;
}

li {
  padding-left: 20px;
  position: relative;
  line-height: 2em;
}

li:before{
  position: absolute;
  left: 5px;
  top: -2px;
  content: '';
  display: block;
  height: 1em;
  border-bottom: 1px solid #bbb;
  width: 10px;
}

li:after {
  position: absolute;
  left: 5px;
  bottom: 0;
  content: '';
  display: block;
  border-left: 1px solid #bbb;
  height: 100%;
}

.loading {
  color: black;
  padding-left: 20px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.loading:after {
  content: "...";
}

.hasChildren > a-folder > span, .hasChildren > span {
  transition: all .1s ease-in-out;
  cursor: pointer;
  border-bottom: 1px dotted #000;
}

.hasChildren > a-folder > span:hover, .hasChildren > span:hover {
  opacity: .5;
}
              
            
!

JS

              
                import {
	DeepObservable,
	fixture,
	ObservableObject,
	restModel,
	StacheElement
} from "//unpkg.com/can@pre/ecosystem.mjs";

// Stores the next entity id to use.
let entityId = 1;

// Returns an array of entities for the given `parentId`.
// Makes sure the `depth` of entities doesn’t exceed 5.
const makeEntities = function(parentId, depth) {
	if (depth > 5) {
		return [];
	}
	// The number of entities to create.
	const entitiesCount = fixture.rand(10);

	// The array of entities we will return.
	const entities = [];

	for (let i = 0; i < entitiesCount; i++) {
		// The id for this entity
		const id = "" + entityId++;

		// If the entity is a folder or file
		const isFolder = Math.random() > 0.3;

		// The children for this folder.
		const children = isFolder ? makeEntities(id, depth + 1) : [];

		const entity = {
			id: id,
			name: (isFolder ? "Folder" : "File") + " " + id,
			parentId: parentId,
			type: isFolder ? "folder" : "file",
			hasChildren: children.length > 0
		};
		entities.push(entity);

		// Add the children of a folder
		[].push.apply(entities, children);
	}
	return entities;
};

// Make the entities for the demo
const entities = makeEntities("0", 0);

// Add them to a client-like DB store
const entitiesStore = fixture.store(entities);

// Trap requests to /api/entities to read items from the entities store.
fixture("/api/entities", entitiesStore);

// Make requests to /api/entities take 1 second
fixture.delay = 1000;

class Entity extends ObservableObject {
	static props = {
		id: { type: String, identity: true },
		name: String,
		parentId: String,
		hasChildren: Boolean,
		type: String
	};
}

Entity.connection = restModel({
	Map: Entity,
	url: "/api/entities"
});

class AFolder extends StacheElement {
	static view = `
		<span on:click="this.toggleOpen()">{{ this.folder.name }}</span>
		{{# if(this.isOpen) }}
			{{# if(this.entitiesPromise.isPending) }}
				<div class="loading">Loading</div>
			{{ else }}
				<ul>
					{{# for(entity of this.entitiesPromise.value) }}
						<li class=" {{entity.type}}
							{{# if(entity.hasChildren) }}hasChildren{{/ if }}">
							{{# eq(entity.type, 'file') }}
								📝 <span>{{ entity.name }}</span>
							{{ else }}
								📁 <a-folder folder:from="entity" />
							{{/ eq }}
						</li>
					{{/ for }}
				</ul>
			{{/ if }}
		{{/ if }}
	`;

	static props = {
		folder: Entity,
		isOpen: false,

		get entitiesPromise() {
			if (this.folder) {
				return Entity.getList({ filter: { parentId: this.folder.id } });
			}
		}
	};

	toggleOpen() {
		this.isOpen = !this.isOpen;
	}
}
customElements.define("a-folder", AFolder);

window.root.assign({
	isOpen: true,
	folder: new Entity({
		id: "0",
		name: "ROOT/",
		hasChildren: true,
		type: "folder"
	})
});
              
            
!
999px

Console