asciidoctor-tabs 1.0.0.alpha.11 → 1.0.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fabd40d3903b96a2982c4bb90a3a6d783fe55369bea21e06f98e4ec97a306bd
4
- data.tar.gz: b6259434eb0eafd0c3c8a5a51bc1f786a111120fe68786ad21b4ad52b737412b
3
+ metadata.gz: 461e1d2d860df917423ed9dea49891739dd1129bda4aabb4bb9a9fc9bfbd09d8
4
+ data.tar.gz: 85189a9d92e881b4570f395357673b42d3bdd272fed80d2b1b718a3d67ff13a7
5
5
  SHA512:
6
- metadata.gz: 8990b67f318bbe16cb3441dadc8f8af8cbb78b4e8f31f53da1c4e8ef855e51eb458a024e1ed2886ceb66bc58bc38ab860c244e2a500bf13c43f87bf2b4212155
7
- data.tar.gz: baca94e8a45013ef881a2a2bc689225225892d145a877a6ec51d7bb4cf697fb98ae7bdd57f516fa831170b9e8e7b6c1c60e0310a5f850ddefcb046225ba7077b
6
+ metadata.gz: 1d3cf0e88c3852b1660f133bff1253d674b0ffa2ed38d0e1e700cbb1e7d41449582c007df86d8f1af20539717d5bdcbff85f8f732b47255b0198eddaa87378bd
7
+ data.tar.gz: fe30e9640c17b3cdbd64f78ead25dc37735eaf5275c1a75f918b00d185caceb3499673aad700938ed117be83c7ffa6e30b4e5e84ae08f46b55df47d2571d72f1
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,31 @@
4
4
  This document provides a curated view of the changes to Asciidoctor Tabs per release.
5
5
  For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
6
6
 
7
+ == 1.0.0-beta.1 (2023-01-30) - @mojavelinux
8
+
9
+ === Added
10
+
11
+ * Pass through role attribute on tabs block (#43)
12
+ * Add configuration option to save sync selection (i.e., sync ID) in local or session storage (#44)
13
+
14
+ === Fixed
15
+
16
+ * Use correct selector to unhide panel of first tab while tabs are loading
17
+
18
+ === Details
19
+
20
+ {url-repo}/releases/tag/v1.0.0-beta.1[git tag] | {url-repo}/compare/v1.0.0-alpha.12\...v1.0.0-beta.1[full diff]
21
+
22
+ == 1.0.0-alpha.12 (2022-12-23) - @mojavelinux
23
+
24
+ === Fixed
25
+
26
+ * Wrap div with class `tablecontainer` around tables inside tabpanel to prevent tables from overflowing bounds while honoring width (#41)
27
+
28
+ === Details
29
+
30
+ {url-repo}/releases/tag/v1.0.0-alpha.12[git tag] | {url-repo}/compare/v1.0.0-alpha.11\...v1.0.0-alpha.12[full diff]
31
+
7
32
  == 1.0.0-alpha.11 (2022-12-08) - @mojavelinux
8
33
 
9
34
  === Changed
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Asciidoctor Tabs
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
- v1.0.0-alpha.11, 2022-12-08
3
+ v1.0.0-beta.1, 2023-01-30
4
4
  :idprefix:
5
5
  :idseparator: -
6
6
  ifndef::env-github[:icons: font]
@@ -128,6 +128,10 @@ Tab B:: Contents of tab B in second tabset.
128
128
  Alternately, you can set the `sync` option on each tabs block.
129
129
  If you want to delist a tabs block from sync, set the `nosync` option on that block.
130
130
 
131
+ If you want to persist the sync selection, assign a value to the `data-sync-storage-key` attribute on the `<script>` tag.
132
+ By default, the sync selection will be assigned to the specified key in local storage.
133
+ You can set the `data-sync-storage-scope` attribute on the `<script>` tag to `session` to use session storage instead.
134
+
131
135
  == Usage
132
136
 
133
137
  === CLI
data/data/css/tabs.css CHANGED
@@ -58,12 +58,6 @@
58
58
  padding: 1.25em;
59
59
  }
60
60
 
61
- .tabpanel > table.tableblock {
62
- border-width: 0;
63
- display: block;
64
- overflow-x: auto;
65
- }
66
-
67
61
  .tablist > ul li,
68
62
  .tabpanel {
69
63
  border: 1px solid #dcdcdc;
@@ -73,7 +67,7 @@
73
67
  border-bottom: 0;
74
68
  }
75
69
 
76
- .tabs.is-loading .tabpanel:not(:first-child),
70
+ .tabs.is-loading .tabpanel + .tabpanel,
77
71
  .tabs:not(.is-loading) .tabpanel.is-hidden {
78
72
  display: none;
79
73
  }
@@ -82,8 +76,21 @@
82
76
  margin-top: 0;
83
77
  }
84
78
 
79
+ /* #content is a signature of the Asciidoctor standalone HTML output */
85
80
  #content .tabpanel > :last-child,
86
81
  #content .tabpanel > :last-child > :last-child,
87
82
  #content .tabpanel > :last-child > :last-child > li:last-child > :last-child {
88
83
  margin-bottom: 0;
89
84
  }
85
+
86
+ .tablecontainer {
87
+ overflow-x: auto;
88
+ }
89
+
90
+ #content .tablecontainer {
91
+ margin-bottom: 1.25em;
92
+ }
93
+
94
+ #content .tablecontainer > table.tableblock {
95
+ margin-bottom: 0;
96
+ }
data/data/js/tabs.js CHANGED
@@ -1,38 +1,45 @@
1
1
  ;(function () { /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */
2
2
  'use strict'
3
3
 
4
+ var config = (document.currentScript || {}).dataset || {}
4
5
  var forEach = Array.prototype.forEach
5
6
 
6
7
  init(document.querySelectorAll('.tabs'))
7
8
 
8
9
  function init (tabsBlocks) {
9
10
  if (!tabsBlocks.length) return
11
+ var preferredSyncId = 'syncStorageKey' in config
12
+ ? window[(config.syncStorageScope || 'local') + 'Storage'].getItem(config.syncStorageKey)
13
+ : undefined
10
14
  forEach.call(tabsBlocks, function (tabs) {
11
15
  var syncIds = tabs.classList.contains('is-sync') ? {} : undefined
12
16
  var tablist = tabs.querySelector('.tablist ul')
13
17
  tablist.setAttribute('role', 'tablist')
18
+ var first, selectedTab
14
19
  forEach.call(tablist.querySelectorAll('li'), function (tab, idx) {
15
20
  tab.setAttribute('role', (tab.className = 'tab')) // NOTE converter may not have set class on li
16
- var id, anchor
21
+ var id, anchor, syncId
17
22
  if (!(id = tab.id)) {
18
23
  if (!(anchor = tab.querySelector('a[id]'))) return // invalid state
19
24
  tab.id = id = anchor.parentNode.removeChild(anchor).id
20
25
  }
21
26
  var panel = tabs.querySelector('.tabpanel[aria-labelledby~="' + id + '"]')
22
27
  if (!panel) return // invalid state
28
+ if (!idx) first = { tab: tab, panel: panel }
23
29
  tab.tabIndex = -1
30
+ syncIds && !((syncId = tab.textContent.trim()) in syncIds) && (syncIds[(tab.dataset.syncId = syncId)] = true)
31
+ ? syncId === preferredSyncId ? toggleSelected((selectedTab = tab), true) : toggleHidden(panel, true)
32
+ : (syncId = toggleHidden(panel, true))
24
33
  tab.setAttribute('aria-controls', panel.id)
25
34
  panel.setAttribute('role', 'tabpanel')
26
- idx ? toggleHidden(panel, true) : toggleSelected(tab, true)
27
- var onClick = activateTab
28
- var instance = { tabs: tabs, tab: tab, panel: panel }
29
- var syncId
30
- if (syncIds && !((syncId = tab.textContent.trim()) in syncIds)) {
31
- syncIds[(tab.dataset.syncId = syncId)] = true
32
- onClick = activateTabSync
33
- }
34
- tab.addEventListener('click', onClick.bind(instance))
35
+ forEach.call(panel.querySelectorAll('table.tableblock'), function (table) {
36
+ var container = Object.assign(document.createElement('div'), { className: 'tablecontainer' })
37
+ table.parentNode.insertBefore(container, table).appendChild(table)
38
+ })
39
+ var onClick = syncId === undefined ? activateTab : activateTabSync
40
+ tab.addEventListener('click', onClick.bind({ tabs: tabs, tab: tab, panel: panel }))
35
41
  })
42
+ if (!selectedTab && first) toggleSelected(first.tab, true) || toggleHidden(first.panel, false)
36
43
  })
37
44
  onHashChange()
38
45
  forEach.call(tabsBlocks, function (tabs) {
@@ -51,6 +58,9 @@
51
58
  forEach.call(tabs.querySelectorAll('.tabpanel'), function (el) {
52
59
  toggleHidden(el, el !== panel)
53
60
  })
61
+ if (!this.isSync && 'syncStorageKey' in config && tab.dataset.syncId !== undefined) {
62
+ window[(config.syncStorageScope || 'local') + 'Storage'].setItem(config.syncStorageKey, tab.dataset.syncId)
63
+ }
54
64
  if (!e) return
55
65
  var loc = window.location
56
66
  var hashIdx = loc.hash ? loc.href.indexOf('#') : -1
@@ -64,7 +74,7 @@
64
74
  var thisTab = this.tab
65
75
  var initialY = tabs.getBoundingClientRect().y
66
76
  forEach.call(document.querySelectorAll('.tabs .tablist .tab'), function (tab) {
67
- if (tab !== thisTab && tab.dataset.syncId === thisTab.dataset.syncId) activateTab.call({ tab: tab })
77
+ if (tab !== thisTab && tab.dataset.syncId === thisTab.dataset.syncId) activateTab.call({ tab: tab, isSync: true })
68
78
  })
69
79
  var shiftedBy = tabs.getBoundingClientRect().y - initialY
70
80
  if (shiftedBy && (shiftedBy = Math.round(shiftedBy))) window.scrollBy({ top: shiftedBy, behavior: 'instant' })
@@ -75,7 +85,7 @@
75
85
  }
76
86
 
77
87
  function toggleSelected (el, state) {
78
- el.setAttribute('aria-selected', state)
88
+ el.setAttribute('aria-selected', '' + state)
79
89
  el.classList.toggle('is-selected', state)
80
90
  el.tabIndex = state ? 0 : -1
81
91
  }
@@ -85,6 +95,6 @@
85
95
  if (!id) return
86
96
  var tab = document.getElementById(~id.indexOf('%') ? decodeURIComponent(id) : id)
87
97
  if (!(tab && tab.classList.contains('tab'))) return
88
- tab.dataset.syncId ? activateTabSync.call({ tab: tab }) : activateTab.call({ tab: tab })
98
+ tab.dataset.syncId === undefined ? activateTab.call({ tab: tab }) : activateTabSync.call({ tab: tab })
89
99
  }
90
100
  })()
@@ -18,8 +18,9 @@ module Asciidoctor
18
18
  end
19
19
  tabs_number = doc.counter 'tabs-number'
20
20
  tabs_id = attrs['id'] || (generate_id %(tabs #{tabs_number}), doc)
21
- sync = !(block.option? 'nosync') && ((block.option? 'sync') || (doc.option? 'tabs-sync')) ? ' is-sync' : nil
22
- tabs = create_open_block parent, nil, { 'id' => tabs_id, 'role' => %(tabs#{sync || ''} is-loading) }
21
+ tabs_sync = !(block.option? 'nosync') && ((block.option? 'sync') || (doc.option? 'tabs-sync')) ? ' is-sync' : ''
22
+ tabs_role = (tabs_role = attrs['role']) ? %( #{tabs_role}) : ''
23
+ tabs = create_open_block parent, nil, { 'id' => tabs_id, 'role' => %(tabs#{tabs_sync}#{tabs_role} is-loading) }
23
24
  tabs.title = attrs['title']
24
25
  tablist = create_list parent, :ulist, { 'role' => 'tablist' }
25
26
  panes = {}
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Tabs
5
- VERSION = '1.0.0.alpha.11'
5
+ VERSION = '1.0.0.beta.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.11
4
+ version: 1.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-08 00:00:00.000000000 Z
11
+ date: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor