Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1 class="display-5" data-i18n="home.master">
<div class="row">
<a
class="btn btn-success"
href="{{ '/gallery/' | relative_url }}"
href="{{ '/geo/' | relative_url }}"
data-i18n="home.try"
>Passer à la construction</a>
</div>
Expand Down
19 changes: 19 additions & 0 deletions _layouts/geometry_yml.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<head>
{% include three-imports.html %}
{% include head.html %}
<script type="module" src="/lib/modules/components/idf-viewer.js"></script>
<script type="module" src="/lib/modules/components/idf-legend.js"></script>
<script type="module" src="/lib/modules/components/geometry-editor.js"></script>
</head>
<body>
{% include menu.html %}
<main class="container-fluid">
<div class="scene-workspace">
<geometry-yml-editor></geometry-yml-editor>
<idf-viewer id="building" src=""></idf-viewer>
</div>
</main>
<obm-site-footer></obm-site-footer>
</body>
</html>
4 changes: 4 additions & 0 deletions geometry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: geometry_yml
permalink: /geo/
---
120 changes: 120 additions & 0 deletions lib/modules/components/geometry-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// geometry-yml-editor.js

import {
EditorView,
basicSetup,
yaml,
autocompletion
} from "/vendor/codemirror/cm-6.0.2-yaml-6.1.3-autocmp-6.0.0.js";


const basicCompletions = (context) => {
const word = context.matchBefore(/\w*/);

if (!word || (word.from === word.to && !context.explicit)) {
return null;
}

return {
from: word.from,
options: [
{ label: 'name', type: 'keyword' },
{ label: 'blocks', type: 'keyword' },
{ label: 'height', type: 'property' },
{ label: 'use_blocks_vars', type: 'property' },
{ label: 'constructions', type: 'property' },
{ label: 'floors', type: 'property' },
{ label: 'roofs', type: 'property' },
{ label: 'walls', type: 'property' },
{ label: 'apertures', type: 'property' },
{ label: 'doors', type: 'property' }
]
};
};


class GeometryYmlEditor extends HTMLElement {

constructor() {
super();
this.editor = null;
this._value = null;
}

connectedCallback() {
// Évite de créer plusieurs éditeurs sur le même élément.
if (this.editor) return;
const container = document.createElement('div');
container.className = 'geometry-yml-editor__container';
const style = document.createElement('style');
style.textContent = `
.geometry-yml-editor__container {
border: 1px solid #ccc;
border-radius: 4px;
overflow: hidden;
}
.geometry-yml-editor__container .cm-editor {
min-height: 400px;
max-height: 700px;
}
.geometry-yml-editor__container .cm-scroller {
overflow: auto;
}
`;
this.replaceChildren(style, container);
this.editor = new EditorView({
doc: this.value,
extensions: [
basicSetup,
yaml(),
autocompletion({
override: [basicCompletions]
}),
EditorView.updateListener.of((update) => {
if (update.docChanged) {
this.dispatchEvent(new CustomEvent('yaml-change', {
detail: {
value: update.state.doc.toString()
},
bubbles: true
}));
}
})
],
parent: container
});
}

disconnectedCallback() {
if (this.editor) {
this.editor.destroy();
this.editor = null;
}
}

get value() {
return this.editor
? this.editor.state.doc.toString()
: (this._value ?? this.getAttribute('value') ?? 'name: example\n');
}

// Permet de modifier le contenu depuis l'extérieur.
set value(text) {
this._value = text;
if (!this.editor) return;
this.editor.dispatch({
changes: {
from: 0,
to: this.editor.state.doc.length,
insert: text
}
});
}

// Permet de donner le focus à l'éditeur.
focus() {
this.editor?.focus();
}
}

customElements.define('geometry-yml-editor', GeometryYmlEditor);
Loading
Loading