Last active
July 13, 2021 16:21
-
-
Save mattduffield/f92a57ebd86e64243f9d384650fae346 to your computer and use it in GitHub Desktop.
Smart Grid - Shadow DOM Working
This file contains hidden or 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
<!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 "main" (data-main attribute on script) | |
which is your src/main.js. | |
--> | |
<body> | |
<my-app></my-app> | |
<script src="/dist/entry-bundle.js" data-main="main"></script> | |
<script src="https://unpkg.com/[email protected]/common/data.js"></script> | |
<script type="module" src="https://unpkg.com/[email protected]/source/components/smart.ui.grid.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
{ | |
"dependencies": { | |
"aurelia": "latest" | |
} | |
} |
This file contains hidden or 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
import Aurelia from 'aurelia'; | |
import { MyApp } from './my-app'; | |
Aurelia.app(MyApp).start(); |
This file contains hidden or 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
<!-- | |
Try to create a paired css/scss/sass/less file like my-app.scss. | |
It will be automatically imported based on convention. | |
--> | |
<!-- | |
There is no bundler config you can change in Dumber Gist to | |
turn on shadow DOM. | |
But you can turn shadow DOM on by adding a meta tag in every | |
html template: | |
<use-shadow-dom> | |
--> | |
<use-shadow-dom></use-shadow-dom> | |
<h1>${message}</h1> | |
<smart-ui-grid id="grid"></smart-ui-grid> |
This file contains hidden or 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
import { $, $$ } from './util.js'; | |
export class MyApp { | |
message = 'Hello Aurelia 2!'; | |
attaching() { | |
this.dg = $('#grid'); | |
this.dg.dataSource = new Smart.DataAdapter( | |
{ | |
dataSource: [ | |
{ "EmployeeID": 1, "FirstName": "Nancy", "LastName": "Davolio", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1992-05-01 00:00:00", "BirthDate": "1948-12-08 00:00:00", "City": "Seattle", "Address": "507 - 20th Ave. E.Apt. 2A" }, | |
{ "EmployeeID": 2, "FirstName": "Andrew", "LastName": "Fuller", "ReportsTo": null, "Country": "USA", "Title": "Vice President, Sales", "HireDate": "1992-08-14 00:00:00", "BirthDate": "1952-02-19 00:00:00", "City": "Tacoma", "Address": "908 W. Capital Way" }, | |
{ "EmployeeID": 3, "FirstName": "Janet", "LastName": "Leverling", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1992-04-01 00:00:00", "BirthDate": "1963-08-30 00:00:00", "City": "Kirkland", "Address": "722 Moss Bay Blvd." }, | |
{ "EmployeeID": 4, "FirstName": "Margaret", "LastName": "Peacock", "ReportsTo": 2, "Country": "USA", "Title": "Sales Representative", "HireDate": "1993-05-03 00:00:00", "BirthDate": "1937-09-19 00:00:00", "City": "Redmond", "Address": "4110 Old Redmond Rd." }, | |
{ "EmployeeID": 5, "FirstName": "Steven", "LastName": "Buchanan", "ReportsTo": 2, "Country": "UK", "Title": "Sales Manager", "HireDate": "1993-10-17 00:00:00", "BirthDate": "1955-03-04 00:00:00", "City": "London", "Address": "14 Garrett Hill" }, | |
{ "EmployeeID": 6, "FirstName": "Michael", "LastName": "Suyama", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1993-10-17 00:00:00", "BirthDate": "1963-07-02 00:00:00", "City": "London", "Address": "Coventry House Miner Rd." }, | |
{ "EmployeeID": 7, "FirstName": "Robert", "LastName": "King", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1994-01-02 00:00:00", "BirthDate": "1960-05-29 00:00:00", "City": "London", "Address": "Edgeham Hollow Winchester Way" }, | |
{ "EmployeeID": 8, "FirstName": "Laura", "LastName": "Callahan", "ReportsTo": 2, "Country": "USA", "Title": "Inside Sales Coordinator", "HireDate": "1994-03-05 00:00:00", "BirthDate": "1958-01-09 00:00:00", "City": "Seattle", "Address": "4726 - 11th Ave. N.E." }, | |
{ "EmployeeID": 9, "FirstName": "Anne", "LastName": "Dodsworth", "ReportsTo": 5, "Country": "UK", "Title": "Sales Representative", "HireDate": "1994-11-15 00:00:00", "BirthDate": "1966-01-27 00:00:00", "City": "London", "Address": "7 Houndstooth Rd." } | |
], | |
dataFields: [ | |
'EmployeeID: number', | |
'ReportsTo: number', | |
'FirstName: string', | |
'LastName: string', | |
'Country: string', | |
'City: string', | |
'Address: string', | |
'Title: string', | |
'HireDate: date', | |
'BirthDate: date' | |
] | |
}); | |
this.dg.sorting = { enabled: true }; | |
this.dg.filtering = { enabled: true }; | |
this.dg.behavior - { columnResizeMode: 'growAndShrink' }; | |
this.dg.columns = [ | |
{ label: 'First Name', dataField: 'FirstName', width: 200 }, | |
{ label: 'Last Name', dataField: 'LastName', width: 200 }, | |
{ label: 'Title', dataField: 'Title', width: 160 }, | |
{ label: 'Birth Date', dataField: 'BirthDate', cellsFormat: 'd', width: 120 }, | |
{ label: 'Hire Date', dataField: 'HireDate', cellsFormat: 'd', width: 120 }, | |
{ label: 'Address', dataField: 'Address', width: 250 }, | |
{ label: 'City', dataField: 'City', width: 120 }, | |
{ label: 'Country', dataField: 'Country' } | |
]; | |
} | |
} |
This file contains hidden or 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
export const collectAllElementsDeep = (selector = null, root, cachedElements = null) => { | |
let allElements = []; | |
if (cachedElements) { | |
allElements = cachedElements; | |
} else { | |
const findAllElements = function(nodes) { | |
for (let i = 0, el; el = nodes[i]; ++i) { | |
allElements.push(el); | |
// If the element has a shadow root, dig deeper. | |
if (el.shadowRoot) { | |
findAllElements(el.shadowRoot.querySelectorAll('*')); | |
} | |
} | |
} | |
if(root.shadowRoot) { | |
findAllElements(root.shadowRoot.querySelectorAll('*')); | |
} | |
findAllElements(root.querySelectorAll('*')); | |
} | |
return allElements.filter(el => el.matches(selector)); | |
} | |
export const $ = (selector = null, root = document) => { | |
const [first = null] = collectAllElementsDeep(selector, root); | |
return first; | |
} | |
export const $$ = (selector = null, root = document) => { | |
return collectAllElementsDeep(selector, root); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment