-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ember-cli-babel ruins lives :( (or maybe just babel) Blocked by: NullVoxPopuli/ember-statechart-component#149 which is in-turn blocked by: emberjs/ember-cli-babel#419 which is then blocked by ember-data... *for some reason*. (I don't use ember-data here, so idgaf) Further work is blocked by embroider-build/embroider#1038
- Loading branch information
1 parent
53322d0
commit 432dffe
Showing
25 changed files
with
3,845 additions
and
4,060 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
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
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,42 @@ | ||
import { setOwner } from '@ember/application'; | ||
import { destroy, registerDestructor } from '@ember/destroyable'; | ||
import { capabilities as modifierCapabilities, setModifierManager } from '@ember/modifier'; | ||
|
||
class FunctionalModifierManager { | ||
capabilities = modifierCapabilities('3.22'); | ||
|
||
createModifier(fn, args) { | ||
return { fn, args, element: undefined, destructor: undefined }; | ||
} | ||
|
||
installModifier(state, element) { | ||
state.element = element; | ||
this.setupModifier(state); | ||
} | ||
|
||
updateModifier(state) { | ||
this.destroyModifier(state); | ||
this.setupModifier(state); | ||
} | ||
|
||
setupModifier(state) { | ||
let { fn, args, element } = state; | ||
|
||
state.destructor = fn(element, args.positional, args.named); | ||
} | ||
|
||
destroyModifier(state) { | ||
if (typeof state.destructor === 'function') { | ||
state.destructor(); | ||
} | ||
} | ||
|
||
getDebugName(fn) { | ||
return fn.name || '(anonymous function)'; | ||
} | ||
} | ||
|
||
const FUNCTIONAL_MODIFIER_MANAGER = new FunctionalModifierManager(); | ||
const FUNCTIONAL_MODIFIER_MANAGER_FACTORY = () => FUNCTIONAL_MODIFIER_MANAGER; | ||
|
||
setModifierManager(FUNCTIONAL_MODIFIER_MANAGER_FACTORY, Function.prototype); |
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
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 |
---|---|---|
@@ -1,42 +1,15 @@ | ||
import { isDestroyed, isDestroying } from '@ember/destroyable'; | ||
import { action } from '@ember/object'; | ||
|
||
import { Modifier } from 'ember-could-get-used-to-this'; | ||
|
||
import { getHighlighter } from './-utils/highlighting'; | ||
|
||
interface Args { | ||
positional: [unknown /* used to trigger updates */]; | ||
} | ||
export default class HighlightCodeBlocks extends Modifier<Args> { | ||
get isSafe() { | ||
return !isDestroyed(this) && !isDestroying(this); | ||
} | ||
|
||
setup() { | ||
this.highlight(); | ||
} | ||
|
||
update() { | ||
this.highlight(); | ||
export default async function highlightCodeBlocks(element: HTMLElement, _: unknown) { | ||
if (!_) { | ||
console.warn(`No argument was passed to {{highlight-code-blocks}}. Updates won't be detected`); | ||
} | ||
|
||
@action | ||
async highlight() { | ||
if (!this.args.positional[0]) { | ||
console.warn( | ||
`No argument was passed to {{highlight-code-blocks}}. Updates won't be detected` | ||
); | ||
} | ||
|
||
if (this.isSafe && this.element) { | ||
let elements = this.element.querySelectorAll('pre > code'); | ||
let elements = element.querySelectorAll('pre > code'); | ||
|
||
for (let element of elements) { | ||
let hljs = await getHighlighter(); | ||
for (let element of elements) { | ||
let hljs = await getHighlighter(); | ||
|
||
hljs.highlightElement(element as HTMLElement); | ||
} | ||
} | ||
hljs.highlightElement(element as HTMLElement); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,36 +1,25 @@ | ||
import { isDestroyed, isDestroying } from '@ember/destroyable'; | ||
import { action } from '@ember/object'; | ||
|
||
import { Modifier } from 'ember-could-get-used-to-this'; | ||
import { guidFor } from '@ember/object/internals'; | ||
|
||
import { getHighlighter, getPurifier } from './-utils/highlighting'; | ||
|
||
export default class Highlighted extends Modifier { | ||
get isSafe() { | ||
return !isDestroyed(this) && !isDestroying(this); | ||
} | ||
/** | ||
* NOTE: this cannot have a destructor, because it is async | ||
*/ | ||
export default async function highlighted(element, code) { | ||
let guid = guidFor(element); | ||
|
||
get code() { | ||
return this.args.positional[0]; | ||
} | ||
element.setAttribute('id', guid); | ||
|
||
setup() { | ||
this.highlight(this.code); | ||
} | ||
let [hljs, purify] = await Promise.all([getHighlighter(), getPurifier()]); | ||
|
||
update() { | ||
this.highlight(this.code); | ||
// because the above is async, it's possible that the element | ||
// has been removed from the DOM | ||
if (!window.body.getElementById(guid)) { | ||
return; | ||
} | ||
|
||
@action | ||
async highlight(code) { | ||
if (this.isSafe && this.element) { | ||
let [hljs, purify] = await Promise.all([getHighlighter(), getPurifier()]); | ||
|
||
let target = this.element.querySelector('code'); | ||
let { value } = hljs.highlight(code, { language: target.classList[0] }); | ||
let target = element.querySelector('code'); | ||
let { value } = hljs.highlight(code, { language: target.classList[0] }); | ||
|
||
target.innerHTML = purify.sanitize(value); | ||
} | ||
} | ||
target.innerHTML = purify.sanitize(value); | ||
} |
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 |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import { modifier } from 'ember-could-get-used-to-this'; | ||
|
||
type PositionalArgs = [number, number]; | ||
|
||
export default modifier(function positionFromTop( | ||
element: HTMLElement, | ||
[lines, padding]: PositionalArgs | ||
) { | ||
export default function positionFromTop(element: HTMLElement, [lines, padding]: PositionalArgs) { | ||
let container = element.parentElement as Element; | ||
let lineHeight = getComputedStyle(container).lineHeight; | ||
|
||
element.setAttribute('style', `top: calc(${padding} + ${lineHeight} * ${lines - 1})`); | ||
}); | ||
} |
Oops, something went wrong.