mirror of
https://github.com/atom/atom.git
synced 2026-02-16 01:25:13 -05:00
Upgrade existing selectors after attaching atom-styles element
Style elements don’t have a .sheet property until they are actually attached to the DOM. Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
@@ -18,6 +18,9 @@ class StylesElement extends HTMLElement
|
||||
@styleElementClonesByOriginalElement = new WeakMap
|
||||
|
||||
attachedCallback: ->
|
||||
if @context is 'atom-text-editor'
|
||||
for styleElement in @children
|
||||
@upgradeDeprecatedSelectors(styleElement)
|
||||
@initialize()
|
||||
|
||||
detachedCallback: ->
|
||||
@@ -48,6 +51,7 @@ class StylesElement extends HTMLElement
|
||||
return unless @styleElementMatchesContext(styleElement)
|
||||
|
||||
styleElementClone = styleElement.cloneNode(true)
|
||||
styleElementClone.sourcePath = styleElement.sourcePath
|
||||
styleElementClone.context = styleElement.context
|
||||
@styleElementClonesByOriginalElement.set(styleElement, styleElementClone)
|
||||
|
||||
@@ -61,7 +65,7 @@ class StylesElement extends HTMLElement
|
||||
@insertBefore(styleElementClone, insertBefore)
|
||||
|
||||
if @context is 'atom-text-editor'
|
||||
@upgradeDeprecatedSelectors(styleElementClone, styleElement.sourcePath)
|
||||
@upgradeDeprecatedSelectors(styleElementClone)
|
||||
|
||||
@emitter.emit 'did-add-style-element', styleElementClone
|
||||
|
||||
@@ -82,7 +86,9 @@ class StylesElement extends HTMLElement
|
||||
styleElementMatchesContext: (styleElement) ->
|
||||
not @context? or styleElement.context is @context
|
||||
|
||||
upgradeDeprecatedSelectors: (styleElement, sourcePath) ->
|
||||
upgradeDeprecatedSelectors: (styleElement) ->
|
||||
return unless styleElement.sheet?
|
||||
|
||||
upgradedSelectors = []
|
||||
|
||||
for rule in styleElement.sheet.cssRules
|
||||
@@ -99,7 +105,7 @@ class StylesElement extends HTMLElement
|
||||
upgradedSelectors.push({inputSelector, outputSelector})
|
||||
|
||||
if upgradedSelectors.length > 0
|
||||
warning = "Upgraded the following syntax theme selectors in `#{sourcePath}` for shadow DOM compatibility:\n\n"
|
||||
warning = "Upgraded the following syntax theme selectors in `#{styleElement.sourcePath}` for shadow DOM compatibility:\n\n"
|
||||
for {inputSelector, outputSelector} in upgradedSelectors
|
||||
warning += "`#{inputSelector}` => `#{outputSelector}`\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user