-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GH-105 Multi-sheet support * Can save multiple sheets in a single JSON file. * Can rename sheets * Fully compatible with Helix * Single sheets fallback to default behavior (to maintain consistency with Helix & existing projects) * Can delete sheets * Reads existing multi-sheets Resolves: #150 * Improve tests
- Loading branch information
1 parent
3a0c21b
commit 936c59f
Showing
20 changed files
with
493 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
:host { | ||
display: flex; | ||
gap: var(--spacing-200); | ||
margin-bottom: var(--spacing-200); | ||
} | ||
|
||
svg { | ||
display: none; | ||
} | ||
|
||
ul { | ||
margin: 0; | ||
padding: 0; | ||
list-style: none; | ||
display: flex; | ||
gap: var(--spacing-200); | ||
} | ||
|
||
li { | ||
background: rgb(220 220 220); | ||
border-radius: 6px; | ||
line-height: 32px; | ||
padding: 0 0 0 12px; | ||
overflow: hidden; | ||
} | ||
|
||
input { | ||
border: none; | ||
padding: 0 6px; | ||
background: rgb(255 255 255 / 40%); | ||
} | ||
|
||
button, | ||
input[type="text"] { | ||
font-family: var(--body-font-family); | ||
} | ||
|
||
li.active { | ||
background: rgb(180 180 180); | ||
} | ||
|
||
li button { | ||
background: none; | ||
border: none; | ||
padding: 7px 10px; | ||
font-weight: 700; | ||
} | ||
|
||
li button[value="select"] { | ||
font-weight: 400; | ||
} | ||
|
||
form { | ||
display: flex; | ||
gap: 4px; | ||
} | ||
|
||
button:hover { | ||
color: #FFF; | ||
background-color: var(--spectrum-blue-800); | ||
} | ||
|
||
.icon { | ||
color: rgb(0 0 0 / 40%); | ||
display: block; | ||
width: 18px; | ||
height: 18px; | ||
} | ||
|
||
button:hover .icon { | ||
color: #FFF; | ||
} | ||
|
||
.action-container { | ||
display: flex; | ||
} | ||
|
||
.add-sheet { | ||
font-weight: 700; | ||
background: none; | ||
border: 2px solid var(--s2-gray-800); | ||
border-radius: 6px; | ||
padding: 0 12px; | ||
} | ||
|
||
.add-sheet:hover { | ||
background-color: var(--spectrum-blue-800); | ||
border: 2px solid var(--spectrum-blue-800); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { LitElement, html, nothing } from '../../deps/lit/lit-core.min.js'; | ||
import { getNx } from '../../scripts/utils.js'; | ||
|
||
const { default: getStyle } = await import(`${getNx()}/utils/styles.js`); | ||
const { default: getSvg } = await import(`${getNx()}/utils/svg.js`); | ||
|
||
const style = await getStyle(import.meta.url); | ||
|
||
const SHEET_TEMPLATE = { minDimensions: [20, 20], sheetName: 'data' }; | ||
const ICONS = [ | ||
'/blocks/edit/img/Smock_Delete_18_N.svg', | ||
'/blocks/edit/img/Smock_Edit_18_N.svg', | ||
'/blocks/edit/img/Smock_Cancel_18_N.svg', | ||
'/blocks/edit/img/Smock_Checkmark_18_N.svg', | ||
]; | ||
|
||
class DaSheetTabs extends LitElement { | ||
static properties = { | ||
_names: { attribute: false }, | ||
_active: { attribute: false }, | ||
_edit: { attribute: false }, | ||
}; | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this.shadowRoot.adoptedStyleSheets = [style]; | ||
getSvg({ parent: this.shadowRoot, paths: ICONS }); | ||
this._names = this.getNames(); | ||
this.showSheet(0); | ||
} | ||
|
||
showSheet(idx) { | ||
this._active = idx; | ||
this.sheetContents.forEach((sheet) => { sheet.style.display = 'none'; }); | ||
this.sheetContents[idx].style.display = 'block'; | ||
} | ||
|
||
getNames() { | ||
return this.jexcel.map((sheet) => sheet.name); | ||
} | ||
|
||
get tabContainer() { | ||
return this.parentElement.querySelector('.jexcel_tabs'); | ||
} | ||
|
||
get jexcel() { | ||
return this.tabContainer.jexcel; | ||
} | ||
|
||
get hiddenTabs() { | ||
const parent = this.tabContainer.querySelector(':scope > div:first-child'); | ||
return parent.querySelectorAll('.jexcel_tab_link'); | ||
} | ||
|
||
get sheetContents() { | ||
const parent = this.tabContainer.querySelector(':scope > div:last-child'); | ||
return parent.querySelectorAll('.jexcel_container'); | ||
} | ||
|
||
handleAdd() { | ||
const sheets = [{ | ||
...SHEET_TEMPLATE, | ||
sheetName: `data-${this.jexcel.length + 1}`, | ||
}]; | ||
// Add the new tab | ||
window.jspreadsheet.tabs(this.tabContainer, sheets); | ||
// Set the sheet name for later use | ||
this.jexcel.slice(-1)[0].name = sheets[0].sheetName; | ||
// Refresh the tab names | ||
this._names = this.getNames(); | ||
// Only set active as jspreadsheet will set the visibility of the sheet | ||
this._active = this.jexcel.length - 1; | ||
// Set the tab to be in edit mode | ||
this._edit = this.jexcel.length - 1; | ||
} | ||
|
||
handleEdit(e, idx) { | ||
e.preventDefault(); | ||
if (e.submitter.value === 'select') { | ||
this.showSheet(idx); | ||
return; | ||
} | ||
if (e.submitter.value === 'edit') { | ||
this._edit = idx; | ||
return; | ||
} | ||
if (e.submitter.value === 'cancel') { | ||
this._edit = null; | ||
return; | ||
} | ||
if (e.submitter.value === 'remove') { | ||
this._names.splice(idx, 1); | ||
this.jexcel.splice(idx, 1); | ||
this.hiddenTabs[idx].remove(); | ||
this.sheetContents[idx].remove(); | ||
this._edit = null; | ||
this.showSheet(0); | ||
return; | ||
} | ||
if (e.submitter.value === 'confirm') { | ||
const entries = Object.fromEntries(new FormData(e.target)); | ||
this._names[idx] = entries.name; | ||
this.jexcel[idx].name = entries.name; | ||
this.hiddenTabs[idx].innerHTML = entries.name; | ||
this._edit = null; | ||
} | ||
} | ||
|
||
render() { | ||
if (!this._names) return nothing; | ||
|
||
return html` | ||
<ul> | ||
${this._names.map((name, idx) => html` | ||
<li class="${idx === this._active ? 'active' : ''}" @click=${() => this.showSheet(idx)}> | ||
<form @submit=${(e) => this.handleEdit(e, idx)}> | ||
${idx === this._edit ? html` | ||
<input type="text" name="name" value="${name}" /> | ||
` : html` | ||
<button value="select"><span>${name}</span></button> | ||
`} | ||
${idx === this._edit ? html` | ||
<div class="action-container"> | ||
<button aria-label="Confirm" value="confirm"> | ||
<svg class="icon"><use href="#spectrum-Checkmark"/></svg> | ||
</button> | ||
<button aria-label="Cancel" value="cancel"> | ||
<svg class="icon"><use href="#spectrum-Cancel"/></svg> | ||
</button> | ||
<button aria-label="Remove" value="remove"> | ||
<svg class="icon"><use href="#spectrum-Delete"/></svg> | ||
</button> | ||
</div> | ||
` : html` | ||
<button aria-label="Edit" value="edit"> | ||
<svg class="icon"><use href="#spectrum-Edit"/></svg> | ||
</button> | ||
`} | ||
</form> | ||
</li>`)} | ||
</ul> | ||
<button class="add-sheet" @click=${this.handleAdd}>Add sheet</button> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('da-sheet-tabs', DaSheetTabs); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.