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
74 changes: 38 additions & 36 deletions src/edit.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version="3.0">

<!-- the page URI without its fragment: the base for RDFa resolution in the browser -->
<xsl:function name="local:document-uri" as="xs:string">
<xsl:sequence select="substring-before(ixsl:get(ixsl:window(), 'location.href') || '#', '#')"/>
<xsl:sequence select="substring-before(ixsl:location() || '#', '#')"/>
</xsl:function>

<!-- editable regions are marked by convention with the rdfa-editor-content class
Expand All @@ -42,10 +42,7 @@ version="3.0">

<!-- the region the user is working in: selection first, then the last focused host -->
<xsl:function name="local:active-root" as="element()?">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="anchor" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:sequence select="($anchor ! local:root-of(.),
<xsl:sequence select="(local:anchor-node() ! local:root-of(.),
ixsl:get(local:editor-state(), 'activeBlock') ! local:root-of(.), local:roots()[1])[1]"/>
</xsl:function>

Expand Down Expand Up @@ -166,19 +163,14 @@ version="3.0">
<!-- toolbar actions resolve the block from the selection, falling back to the
last focused host (the block-type select steals focus - see ixsl:onfocusin) -->
<xsl:function name="local:current-block" as="element()?">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="anchor" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:sequence select="($anchor ! local:block-of(.), ixsl:get(local:editor-state(), 'activeBlock') ! local:block-of(.))[1]"/>
<xsl:sequence select="(local:anchor-node() ! local:block-of(.),
ixsl:get(local:editor-state(), 'activeBlock') ! local:block-of(.))[1]"/>
</xsl:function>

<!-- host-based resolution for actions that act on the leaf block the caret
sits in (block-type convert, quote toggle) rather than the top-level block -->
<xsl:function name="local:current-host" as="element()?">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="anchor" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:sequence select="($anchor ! local:host-of(.),
<xsl:sequence select="(local:anchor-node() ! local:host-of(.),
ixsl:get(local:editor-state(), 'activeBlock') ! local:host-of(.))[1]"/>
</xsl:function>

Expand Down Expand Up @@ -244,11 +236,31 @@ version="3.0">
then ixsl:call($selection, 'getRangeAt', [ 0 ]) else ()"/>
</xsl:function>

<!-- the selection anchor as a node (empty when no range) and its offset (0 then) -->
<xsl:function name="local:anchor-node" as="node()?">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:sequence select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
</xsl:function>

<xsl:function name="local:anchor-offset" as="xs:integer">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:sequence select="if (ixsl:get($selection, 'rangeCount') ge 1)
then xs:integer(ixsl:get($selection, 'anchorOffset')) else 0"/>
</xsl:function>

<xsl:function name="local:element" as="element()">
<xsl:param name="name" as="xs:string"/>
<xsl:sequence select="ixsl:call(ixsl:page(), 'createElement', [ $name ])"/>
</xsl:function>

<!-- the live value of the first input named $name under $scope (a dialog or form) -->
<xsl:function name="local:input-value" as="xs:string">
<xsl:param name="scope" as="element()"/>
<xsl:param name="name" as="xs:string"/>
<xsl:sequence select="string(ixsl:get(($scope//input[@name = $name])[1], 'value'))"/>
</xsl:function>

<!-- focus the host of $node, then collapse the caret there -->
<xsl:template name="local:focus-caret">
<xsl:param name="node"/>
Expand Down Expand Up @@ -1373,11 +1385,8 @@ version="3.0">
<xsl:with-param name="host" select="$item"/>
</xsl:call-template>
<!-- text-node caret references survive reparenting -->
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="caret-node" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:variable name="caret-offset" as="xs:integer"
select="if (exists($caret-node)) then xs:integer(ixsl:get($selection, 'anchorOffset')) else 0"/>
<xsl:variable name="caret-node" as="node()?" select="local:anchor-node()"/>
<xsl:variable name="caret-offset" as="xs:integer" select="local:anchor-offset()"/>
<xsl:variable name="target" as="element()?"
select="$prev/*[not(@data-role)][last()][self::ul or self::ol]"/>
<xsl:if test="empty($target)">
Expand Down Expand Up @@ -1437,11 +1446,8 @@ version="3.0">
<xsl:call-template name="local:push-undo">
<xsl:with-param name="host" select="$item"/>
</xsl:call-template>
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="caret-node" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:variable name="caret-offset" as="xs:integer"
select="if (exists($caret-node)) then xs:integer(ixsl:get($selection, 'anchorOffset')) else 0"/>
<xsl:variable name="caret-node" as="node()?" select="local:anchor-node()"/>
<xsl:variable name="caret-offset" as="xs:integer" select="local:anchor-offset()"/>
<xsl:variable name="followers" as="element()*" select="$item/following-sibling::li"/>
<xsl:if test="exists($followers)">
<xsl:variable name="target" as="element()?"
Expand Down Expand Up @@ -1807,11 +1813,8 @@ version="3.0">
<xsl:call-template name="local:push-undo">
<xsl:with-param name="host" select="$quote"/>
</xsl:call-template>
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="caret-node" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:variable name="caret-offset" as="xs:integer"
select="if (exists($caret-node)) then xs:integer(ixsl:get($selection, 'anchorOffset')) else 0"/>
<xsl:variable name="caret-node" as="node()?" select="local:anchor-node()"/>
<xsl:variable name="caret-offset" as="xs:integer" select="local:anchor-offset()"/>
<xsl:call-template name="local:remove-chrome">
<xsl:with-param name="block" select="$quote"/>
</xsl:call-template>
Expand Down Expand Up @@ -1893,16 +1896,15 @@ version="3.0">
<xsl:with-param name="root" select="$snapshot-root"/>
<xsl:with-param name="snapshot" select="$snapshot"/>
</xsl:call-template>
<xsl:variable name="selection" select="local:selection()"/>
<!-- host-of, not block-of: $block may be a nested host (a paragraph in a
quote or cell) whose top-level block is the container. Restore only a
node that MOVES with the children (a descendant); an element-level
caret on the block itself dangles after replaceWith, so it falls back
to the start of the new block (matters for empty-block conversions) -->
<xsl:variable name="caret-node" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode')[local:host-of(.) is $block][not(. is $block)] else ()"/>
<xsl:variable name="caret-node" as="node()?"
select="local:anchor-node()[local:host-of(.) is $block][not(. is $block)]"/>
<xsl:variable name="caret-offset" as="xs:integer"
select="if (exists($caret-node)) then xs:integer(ixsl:get($selection, 'anchorOffset')) else 0"/>
select="if (exists($caret-node)) then local:anchor-offset() else 0"/>

<xsl:variable name="new" as="element()" select="ixsl:call(ixsl:page(), 'createElement', [ $name ])"/>
<xsl:for-each select="$block/(@about | @property | @typeof | @resource | @content
Expand Down Expand Up @@ -2145,7 +2147,7 @@ version="3.0">

<xsl:template match="button[contains-token(@class, 'link-save')]" mode="ixsl:onclick">
<xsl:variable name="href" as="xs:string"
select="string(ixsl:get((ancestor::div[@id = 'link-dialog']//input[@name = 'href'])[1], 'value'))"/>
select="local:input-value(ancestor::div[@id = 'link-dialog'][1], 'href')"/>
<xsl:if test="$href ne ''">
<xsl:variable name="editing" select="ixsl:get(local:editor-state(), 'editingLink')"/>
<xsl:choose>
Expand Down Expand Up @@ -2261,17 +2263,17 @@ version="3.0">

<xsl:template match="button[contains-token(@class, 'figure-save')]" mode="ixsl:onclick">
<xsl:variable name="dialog" as="element()" select="ancestor::div[@id = 'figure-dialog']"/>
<xsl:variable name="src" as="xs:string" select="string(ixsl:get(($dialog//input[@name = 'src'])[1], 'value'))"/>
<xsl:variable name="src" as="xs:string" select="local:input-value($dialog, 'src')"/>
<xsl:if test="$src ne ''">
<xsl:call-template name="local:push-undo"/>
<xsl:variable name="figure" as="element()" select="local:element('figure')"/>
<xsl:variable name="img" as="element()" select="local:element('img')"/>
<ixsl:set-attribute name="src" select="$src" object="$img"/>
<ixsl:set-attribute name="alt" select="string(ixsl:get(($dialog//input[@name = 'alt'])[1], 'value'))" object="$img"/>
<ixsl:set-attribute name="alt" select="local:input-value($dialog, 'alt')" object="$img"/>
<!-- focusable so the image is a keyboard-navigation island (see local:nav-targets) -->
<ixsl:set-attribute name="tabindex" select="'-1'" object="$img"/>
<xsl:variable name="figcaption" as="element()" select="local:element('figcaption')"/>
<ixsl:set-property name="textContent" select="string(ixsl:get(($dialog//input[@name = 'caption'])[1], 'value'))" object="$figcaption"/>
<ixsl:set-property name="textContent" select="local:input-value($dialog, 'caption')" object="$figcaption"/>
<ixsl:set-attribute name="contenteditable" select="'true'" object="$figcaption"/>
<xsl:sequence select="ixsl:call($figure, 'appendChild', [ $img ])[current-date() lt xs:date('2000-01-01')]"/>
<xsl:sequence select="ixsl:call($figure, 'appendChild', [ $figcaption ])[current-date() lt xs:date('2000-01-01')]"/>
Expand Down
14 changes: 7 additions & 7 deletions src/ldh-blocks.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,14 @@ version="3.0">
<xsl:template match="button[contains-token(@class, 'ldh-block-save')]" mode="ixsl:onclick">
<xsl:variable name="dialog" as="element()" select="ancestor::div[@id = 'ldh-block-dialog']"/>
<xsl:variable name="type" as="xs:string" select="string(ixsl:get(($dialog//select[@name = 'block-type-iri'])[1], 'value'))"/>
<xsl:variable name="about" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'about'])[1], 'value')))"/>
<xsl:variable name="reference-uri" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'reference-uri'])[1], 'value')))"/>
<xsl:variable name="view-query" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'view-query'])[1], 'value')))"/>
<xsl:variable name="view-mode" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'view-mode'])[1], 'value')))"/>
<xsl:variable name="chart-query" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'chart-query'])[1], 'value')))"/>
<xsl:variable name="about" as="xs:string" select="normalize-space(local:input-value($dialog, 'about'))"/>
<xsl:variable name="reference-uri" as="xs:string" select="normalize-space(local:input-value($dialog, 'reference-uri'))"/>
<xsl:variable name="view-query" as="xs:string" select="normalize-space(local:input-value($dialog, 'view-query'))"/>
<xsl:variable name="view-mode" as="xs:string" select="normalize-space(local:input-value($dialog, 'view-mode'))"/>
<xsl:variable name="chart-query" as="xs:string" select="normalize-space(local:input-value($dialog, 'chart-query'))"/>
<xsl:variable name="chart-type" as="xs:string" select="string(ixsl:get(($dialog//select[@name = 'chart-type'])[1], 'value'))"/>
<xsl:variable name="chart-category" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'chart-category'])[1], 'value')))"/>
<xsl:variable name="chart-series" as="xs:string" select="normalize-space(string(ixsl:get(($dialog//input[@name = 'chart-series'])[1], 'value')))"/>
<xsl:variable name="chart-category" as="xs:string" select="normalize-space(local:input-value($dialog, 'chart-category'))"/>
<xsl:variable name="chart-series" as="xs:string" select="normalize-space(local:input-value($dialog, 'chart-series'))"/>
<xsl:variable name="reference" as="xs:boolean" select="$type = 'urn:rdfa-editor:reference'"/>
<xsl:variable name="valid" as="xs:boolean" select="
if ($reference) then local:is-absolute-iri($reference-uri)
Expand Down
15 changes: 8 additions & 7 deletions src/navigate.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ version="3.0">
</xsl:function>

<xsl:template name="local:update-breadcrumb">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="node" select="(
(if (ixsl:get($selection, 'rangeCount') ge 1) then ixsl:get($selection, 'anchorNode') else ()),
<xsl:variable name="node" select="(local:anchor-node(),
ixsl:get(local:editor-state(), 'activeBlock'))[1]"/>
<xsl:variable name="leaf" as="element()?" select="$node/ancestor-or-self::*[1]"/>
<xsl:choose>
Expand Down Expand Up @@ -443,12 +441,15 @@ version="3.0">
<xsl:for-each select="local:roots()//*[contains-token(@class, 'rdfa-invalid')]">
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'remove', [ 'rdfa-invalid' ])[current-date() lt xs:date('2000-01-01')]"/>
</xsl:for-each>
<xsl:variable name="lintable" as="element()*" select="local:roots() ! lint:lintable(.)"/>
<xsl:for-each select="$lintable[exists((lint:element-issues(.), lint:nesting-issues(.)))]">
<!-- the issue functions run once per element: markers and the badge count
both derive from the same evaluation (this fires on every mutation) -->
<xsl:variable name="linted" as="map(*)*" select="local:roots() ! lint:lintable(.) ! map{
'element': .,
'issues': count((lint:element-issues(.), lint:nesting-issues(.))) }"/>
<xsl:for-each select="$linted[?issues gt 0]?element">
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'add', [ 'rdfa-invalid' ])[current-date() lt xs:date('2000-01-01')]"/>
</xsl:for-each>
<xsl:variable name="count" as="xs:integer"
select="count($lintable ! (lint:element-issues(.), lint:nesting-issues(.)))"/>
<xsl:variable name="count" as="xs:integer" select="sum($linted?issues)"/>
<xsl:for-each select="id('lint-badge', ixsl:page())">
<xsl:choose>
<xsl:when test="$count gt 0">
Expand Down
14 changes: 5 additions & 9 deletions src/overlay.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,11 @@ version="3.0">
<xsl:map>
<xsl:map-entry key="'property'" select="local:typeahead-value($form, 'property')"/>
<xsl:map-entry key="'typeof'" select="local:typeahead-value($form, 'typeof')"/>
<xsl:map-entry key="'subject'"
select="string(ixsl:get(($form//input[@name = 'subject'])[1], 'value'))[. ne '']"/>
<xsl:map-entry key="'object'"
select="string(ixsl:get(($form//input[@name = 'object'])[1], 'value'))[. ne '']"/>
<xsl:map-entry key="'value'"
select="string(ixsl:get(($form//input[@name = 'value'])[1], 'value'))[. ne '']"/>
<xsl:map-entry key="'subject'" select="local:input-value($form, 'subject')[. ne '']"/>
<xsl:map-entry key="'object'" select="local:input-value($form, 'object')[. ne '']"/>
<xsl:map-entry key="'value'" select="local:input-value($form, 'value')[. ne '']"/>
<xsl:map-entry key="'datatype'" select="local:select-or-custom($form, 'datatype', 'custom-datatype')"/>
<xsl:map-entry key="'lang'"
select="string(ixsl:get(($form//input[@name = 'lang'])[1], 'value'))[. ne '']"/>
<xsl:map-entry key="'lang'" select="local:input-value($form, 'lang')[. ne '']"/>
</xsl:map>
</xsl:function>

Expand All @@ -126,7 +122,7 @@ version="3.0">
<xsl:variable name="value" as="xs:string"
select="string(ixsl:get(($form//select[@name = $select-name])[1], 'value'))"/>
<xsl:sequence select="if ($value eq $local:custom)
then string(ixsl:get(($form//input[@name = $custom-name])[1], 'value'))[. ne '']
then local:input-value($form, $custom-name)[. ne '']
else $value[. ne '']"/>
</xsl:function>

Expand Down
12 changes: 6 additions & 6 deletions src/select.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ version="3.0">
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="island" as="element()?" select="($raw?node/ancestor-or-self::*[local:island(.)])[1]"/>
<xsl:variable name="chrome" as="element()?" select="($raw?node/ancestor-or-self::*[@data-role])[1]"/>
<!-- one ancestor walk serves both probes: this runs per mousemove during a sweep -->
<xsl:variable name="ancestors" as="element()*" select="$raw?node/ancestor-or-self::*"/>
<xsl:variable name="island" as="element()?" select="($ancestors[local:island(.)])[1]"/>
<xsl:variable name="chrome" as="element()?" select="($ancestors[@data-role])[1]"/>
<xsl:choose>
<!-- a point inside an object-block island (its rendering or its RDFa
spans) escapes to just after the island: sweep anchors never sit
Expand Down Expand Up @@ -257,17 +259,15 @@ version="3.0">
<xsl:variable name="target" as="node()?" select="ixsl:get($event, 'target')"/>
<xsl:variable name="button" as="xs:double" select="number(ixsl:get($event, 'button'))"/>
<xsl:if test="$button = 0 and empty($target/ancestor-or-self::*[@data-role])">
<xsl:variable name="selection" select="local:selection()"/>
<xsl:variable name="anchor-node" select="if (ixsl:get($selection, 'rangeCount') ge 1)
then ixsl:get($selection, 'anchorNode') else ()"/>
<xsl:variable name="anchor-node" as="node()?" select="local:anchor-node()"/>
<xsl:variable name="point" as="map(*)?" select="local:caret-at-point(
xs:double(ixsl:get($event, 'clientX')), xs:double(ixsl:get($event, 'clientY')))"/>
<xsl:choose>
<!-- an anchor outside any region is the host page's - never hijacked -->
<xsl:when test="ixsl:get($event, 'shiftKey') = true()
and exists(local:root-of($anchor-node)) and exists($point)">
<xsl:sequence select="ixsl:call($event, 'preventDefault', [])[current-date() lt xs:date('2000-01-01')]"/>
<xsl:variable name="anchor-offset" as="xs:integer" select="xs:integer(ixsl:get($selection, 'anchorOffset'))"/>
<xsl:variable name="anchor-offset" as="xs:integer" select="local:anchor-offset()"/>
<xsl:call-template name="local:extend-selection-to">
<xsl:with-param name="anchor-node" select="$anchor-node"/>
<xsl:with-param name="anchor-offset" select="$anchor-offset"/>
Expand Down
Loading
Loading