@livenetworks/ashlar 2.0.6 → 2.0.8

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.
Files changed (221) hide show
  1. package/LICENSE +641 -641
  2. package/components/COMPONENTS.md +1116 -1116
  3. package/components/index.js +81 -81
  4. package/components/ln-accordion/ln-accordion-dev.scss +8 -8
  5. package/components/ln-accordion/ln-accordion.js +1 -1
  6. package/components/ln-accordion/ln-accordion.schema.json +30 -30
  7. package/components/ln-accordion/src/ln-accordion.js +1 -0
  8. package/components/ln-ajax/ln-ajax-dev.scss +8 -8
  9. package/components/ln-ajax/ln-ajax.js +1 -1
  10. package/components/ln-ajax/ln-ajax.schema.json +30 -30
  11. package/components/ln-api-connector/ln-api-connector.js +1 -1
  12. package/components/ln-api-connector/ln-api-connector.schema.json +96 -96
  13. package/components/ln-api-connector/src/ln-api-connector.js +1 -0
  14. package/components/ln-api-queue/ln-api-queue.js +1 -1
  15. package/components/ln-api-queue/ln-api-queue.schema.json +34 -34
  16. package/components/ln-api-queue/src/ln-api-queue.js +3 -13
  17. package/components/ln-autoresize/ln-autoresize-dev.scss +8 -8
  18. package/components/ln-autoresize/ln-autoresize.js +1 -1
  19. package/components/ln-autoresize/ln-autoresize.schema.json +22 -22
  20. package/components/ln-autosave/ln-autosave-dev.scss +13 -13
  21. package/components/ln-autosave/ln-autosave.js +1 -1
  22. package/components/ln-autosave/ln-autosave.schema.json +48 -48
  23. package/components/ln-autosave/src/autosave-model.js +34 -34
  24. package/components/ln-chart/ln-chart.js +1 -1
  25. package/components/ln-chart/ln-chart.schema.json +146 -146
  26. package/components/ln-chart/src/chart-model.js +154 -154
  27. package/components/ln-circular-progress/ln-circular-progress.js +1 -1
  28. package/components/ln-circular-progress/ln-circular-progress.schema.json +42 -42
  29. package/components/ln-confirm/ln-confirm-dev.scss +24 -24
  30. package/components/ln-confirm/ln-confirm.js +1 -1
  31. package/components/ln-confirm/ln-confirm.schema.json +66 -66
  32. package/components/ln-confirm/src/ln-confirm.js +178 -178
  33. package/components/ln-core/crypto.js +286 -265
  34. package/components/ln-core/dom.js +115 -115
  35. package/components/ln-core/form.js +136 -136
  36. package/components/ln-core/helpers.js +33 -33
  37. package/components/ln-core/http.js +48 -48
  38. package/components/ln-core/index.js +1 -1
  39. package/components/ln-core/ln-core.schema.json +109 -109
  40. package/components/ln-core/locale.js +55 -55
  41. package/components/ln-core/matching.js +78 -78
  42. package/components/ln-core/number.js +125 -125
  43. package/components/ln-core/template.js +206 -206
  44. package/components/ln-couchdb-connector/README.md +4 -0
  45. package/components/ln-couchdb-connector/ln-couchdb-connector.js +1 -1
  46. package/components/ln-couchdb-connector/ln-couchdb-connector.schema.json +50 -50
  47. package/components/ln-couchdb-connector/src/ln-couchdb-connector.js +19 -1
  48. package/components/ln-data-coordinator/README.md +9 -38
  49. package/components/ln-data-coordinator/ln-data-coordinator-dev.scss +8 -8
  50. package/components/ln-data-coordinator/ln-data-coordinator.js +1 -1
  51. package/components/ln-data-coordinator/ln-data-coordinator.schema.json +16 -16
  52. package/components/ln-data-coordinator/src/data-read-policy.js +0 -7
  53. package/components/ln-data-coordinator/src/ln-data-coordinator.js +428 -1299
  54. package/components/ln-data-store/README.md +3 -2
  55. package/components/ln-data-store/ln-data-store-dev.scss +13 -13
  56. package/components/ln-data-store/ln-data-store.js +1 -1
  57. package/components/ln-data-store/ln-data-store.schema.json +84 -84
  58. package/components/ln-data-store/src/data-store-model.js +184 -155
  59. package/components/ln-data-store/src/ln-data-store.js +58 -11
  60. package/components/ln-date/README.md +4 -0
  61. package/components/ln-date/ln-date.js +1 -1
  62. package/components/ln-date/ln-date.schema.json +92 -92
  63. package/components/ln-date/src/date-model.js +186 -186
  64. package/components/ln-date/src/ln-date.js +3 -3
  65. package/components/ln-debug/ln-debug.js +1 -1
  66. package/components/ln-debug/ln-debug.schema.json +28 -28
  67. package/components/ln-debug/src/console-sink.js +19 -19
  68. package/components/ln-debug/src/gate.js +95 -95
  69. package/components/ln-debug/src/generated-attributes.js +2 -2
  70. package/components/ln-dropdown/ln-dropdown-dev.scss +13 -13
  71. package/components/ln-dropdown/ln-dropdown.js +1 -1
  72. package/components/ln-dropdown/ln-dropdown.schema.json +90 -90
  73. package/components/ln-editor/ln-editor.js +1 -1
  74. package/components/ln-editor/ln-editor.schema.json +58 -58
  75. package/components/ln-external-links/ln-external-links.js +1 -1
  76. package/components/ln-external-links/ln-external-links.schema.json +18 -18
  77. package/components/ln-fill/ln-fill.js +1 -1
  78. package/components/ln-fill/ln-fill.schema.json +23 -23
  79. package/components/ln-filter/ln-filter.js +1 -1
  80. package/components/ln-filter/ln-filter.schema.json +153 -153
  81. package/components/ln-filter/src/filter-model.js +185 -185
  82. package/components/ln-form/ln-form-dev.scss +8 -8
  83. package/components/ln-form/ln-form.js +1 -1
  84. package/components/ln-form/ln-form.schema.json +45 -45
  85. package/components/ln-http/ln-http.js +1 -1
  86. package/components/ln-http/ln-http.schema.json +6 -6
  87. package/components/ln-icon/ln-icon.schema.json +6 -6
  88. package/components/ln-include/ln-include.js +1 -1
  89. package/components/ln-include/ln-include.schema.json +23 -23
  90. package/components/ln-key/ln-key-dev.scss +18 -18
  91. package/components/ln-key/ln-key.js +1 -1
  92. package/components/ln-key/ln-key.schema.json +56 -56
  93. package/components/ln-key/src/ln-key.js +10 -10
  94. package/components/ln-link/ln-link-dev.scss +8 -8
  95. package/components/ln-link/ln-link.js +1 -1
  96. package/components/ln-link/ln-link.schema.json +22 -22
  97. package/components/ln-list/README.md +152 -152
  98. package/components/ln-list/ln-list-dev.scss +8 -8
  99. package/components/ln-list/ln-list.js +1 -1
  100. package/components/ln-list/ln-list.schema.json +166 -166
  101. package/components/ln-list/src/ln-list.js +4 -4
  102. package/components/ln-modal/README.md +4 -6
  103. package/components/ln-modal/ln-modal.js +1 -1
  104. package/components/ln-modal/ln-modal.schema.json +65 -65
  105. package/components/ln-modal/src/ln-modal.js +28 -8
  106. package/components/ln-nav/ln-nav.js +1 -1
  107. package/components/ln-nav/ln-nav.schema.json +25 -25
  108. package/components/ln-number/ln-number.js +1 -1
  109. package/components/ln-number/ln-number.schema.json +63 -63
  110. package/components/ln-number/src/number-model.js +31 -31
  111. package/components/ln-obfuscator/README.md +60 -60
  112. package/components/ln-obfuscator/ln-obfuscator.js +1 -1
  113. package/components/ln-obfuscator/ln-obfuscator.schema.json +49 -49
  114. package/components/ln-obfuscator/src/ln-obfuscator.js +159 -159
  115. package/components/ln-obfuscator/src/obfuscator-model.js +250 -250
  116. package/components/ln-options/ln-options.js +1 -1
  117. package/components/ln-options/ln-options.schema.json +41 -41
  118. package/components/ln-options/src/ln-options.js +1 -0
  119. package/components/ln-persist/README.md +151 -151
  120. package/components/ln-persist/ln-persist.js +1 -1
  121. package/components/ln-persist/ln-persist.schema.json +28 -28
  122. package/components/ln-persist/src/ln-persist.js +83 -83
  123. package/components/ln-picklist/README.md +230 -230
  124. package/components/ln-picklist/ln-picklist-dev.scss +22 -22
  125. package/components/ln-picklist/ln-picklist.js +1 -1
  126. package/components/ln-picklist/ln-picklist.schema.json +49 -49
  127. package/components/ln-picklist/src/ln-picklist.js +228 -228
  128. package/components/ln-popover/README.md +4 -0
  129. package/components/ln-popover/ln-popover-dev.scss +13 -13
  130. package/components/ln-popover/ln-popover.js +1 -1
  131. package/components/ln-popover/ln-popover.schema.json +82 -82
  132. package/components/ln-popover/src/ln-popover.js +9 -0
  133. package/components/ln-progress/ln-progress-dev.scss +8 -8
  134. package/components/ln-progress/ln-progress.js +1 -1
  135. package/components/ln-progress/ln-progress.schema.json +40 -40
  136. package/components/ln-router/ln-router.js +1 -1
  137. package/components/ln-router/ln-router.schema.json +76 -76
  138. package/components/ln-scroll/README.md +45 -45
  139. package/components/ln-scroll/ln-scroll.js +1 -1
  140. package/components/ln-scroll/ln-scroll.schema.json +85 -85
  141. package/components/ln-scroll/src/ln-scroll.js +150 -150
  142. package/components/ln-search/README.md +188 -188
  143. package/components/ln-search/ln-search.js +1 -1
  144. package/components/ln-search/ln-search.schema.json +103 -103
  145. package/components/ln-slug/ln-slug.js +1 -1
  146. package/components/ln-slug/ln-slug.schema.json +23 -23
  147. package/components/ln-sort/ln-sort.js +1 -1
  148. package/components/ln-sort/ln-sort.schema.json +104 -104
  149. package/components/ln-sort/src/ln-sort.js +321 -321
  150. package/components/ln-sort/src/sort-model.js +117 -117
  151. package/components/ln-sortable/ln-sortable-dev.scss +13 -13
  152. package/components/ln-sortable/ln-sortable.js +1 -1
  153. package/components/ln-sortable/ln-sortable.schema.json +36 -36
  154. package/components/ln-stat/ln-stat-dev.scss +8 -8
  155. package/components/ln-stat/ln-stat.js +1 -1
  156. package/components/ln-stat/ln-stat.schema.json +32 -32
  157. package/components/ln-stat/src/stat-model.js +28 -28
  158. package/components/ln-table/ln-table.js +1 -1
  159. package/components/ln-table/ln-table.schema.json +211 -211
  160. package/components/ln-table/src/ln-table.js +2 -0
  161. package/components/ln-table/src/table-model.js +98 -98
  162. package/components/ln-table-coordinator/ln-table-coordinator.js +1 -1
  163. package/components/ln-table-coordinator/ln-table-coordinator.schema.json +93 -93
  164. package/components/ln-table-coordinator/src/ln-table-coordinator.js +3 -3
  165. package/components/ln-tabs/README.md +2 -2
  166. package/components/ln-tabs/ln-tabs.js +1 -1
  167. package/components/ln-tabs/ln-tabs.schema.json +75 -75
  168. package/components/ln-tabs/src/ln-tabs.js +208 -207
  169. package/components/ln-tabs/src/tabs-model.js +82 -82
  170. package/components/ln-time/ln-time-dev.scss +13 -13
  171. package/components/ln-time/ln-time.js +1 -1
  172. package/components/ln-time/ln-time.schema.json +38 -38
  173. package/components/ln-toast/ln-toast.js +1 -1
  174. package/components/ln-toast/ln-toast.schema.json +65 -65
  175. package/components/ln-toggle/ln-toggle.js +1 -1
  176. package/components/ln-toggle/ln-toggle.schema.json +52 -52
  177. package/components/ln-tooltip/ln-tooltip.js +1 -1
  178. package/components/ln-tooltip/ln-tooltip.schema.json +86 -86
  179. package/components/ln-translations/ln-translations.js +1 -1
  180. package/components/ln-translations/ln-translations.schema.json +120 -120
  181. package/components/ln-ui-coordinator/README.md +62 -62
  182. package/components/ln-ui-coordinator/ln-ui-coordinator.js +1 -1
  183. package/components/ln-ui-coordinator/ln-ui-coordinator.schema.json +28 -28
  184. package/components/ln-ui-coordinator/src/ln-ui-coordinator.js +140 -140
  185. package/components/ln-upload/ln-upload.js +1 -1
  186. package/components/ln-upload/ln-upload.schema.json +193 -193
  187. package/components/ln-upload/src/upload-model.js +78 -78
  188. package/components/ln-validate/ln-validate.js +1 -1
  189. package/components/ln-validate/ln-validate.schema.json +50 -50
  190. package/components/ln-validate/src/validate-model.js +64 -64
  191. package/components/ln-websocket-connector/README.md +166 -166
  192. package/components/ln-websocket-connector/ln-websocket-connector.js +1 -1
  193. package/components/ln-websocket-connector/ln-websocket-connector.schema.json +29 -29
  194. package/components/ln-websocket-connector/src/ln-websocket-connector.js +283 -279
  195. package/ln-ashlar.html-data.json +7 -8
  196. package/package.json +84 -84
  197. package/theme/brand.css +73 -73
  198. package/theme/components/_confirm.scss +6 -6
  199. package/theme/components/_picklist.scss +3 -3
  200. package/theme/config/_palette.scss +274 -274
  201. package/theme/config/_theme.scss +292 -292
  202. package/theme/config/_tokens.scss +285 -285
  203. package/theme/config/mixins/_index.scss +62 -62
  204. package/theme/config/mixins/_picklist.scss +66 -66
  205. package/theme/ln-ashlar-dev.scss +66 -66
  206. package/theme/ln-ashlar-landing.scss +56 -56
  207. package/theme/ln-ashlar-theme.scss +63 -63
  208. package/theme/presentation/_bento.scss +151 -151
  209. package/theme/presentation/_cta.scss +111 -111
  210. package/theme/presentation/_effects.scss +216 -216
  211. package/theme/presentation/_features.scss +108 -108
  212. package/theme/presentation/_footer.scss +129 -129
  213. package/theme/presentation/_hero.scss +158 -158
  214. package/theme/presentation/_layout.scss +170 -170
  215. package/theme/presentation/_navbar.scss +140 -140
  216. package/theme/presentation/_pricing.scss +262 -262
  217. package/theme/presentation/_stats.scss +87 -87
  218. package/theme/presentation/_testimonials.scss +124 -124
  219. package/theme/presentation/_tokens.scss +39 -39
  220. package/theme/presentation/_typography.scss +163 -163
  221. package/web-types.json +12 -12
@@ -1,321 +1,321 @@
1
- import { compareValues, detectValueType, dispatchCancelable, getLocale, hashGet, hashSet, hashSortDecode, hashSortEncode, queueBoot, readValue, registerComponent, resolveHashNamespace, attrStr, attrSpec, defineAttrs } from '../../ln-core';
2
- import { createSortComparator, getAriaSortValue, isExcludedSortItem, isSameSortTarget, normalizeSortDirection, resolveSortItems } from './sort-model.js';
3
-
4
- (function () {
5
- const DOM_SELECTOR = 'data-ln-sort';
6
- const DOM_ATTRIBUTE = 'lnSort';
7
- const FIELD_ATTR = 'data-ln-sort-field';
8
- const STATE_ATTR = 'data-ln-sort-state';
9
- const DIR_ATTR = 'data-ln-sort-dir';
10
- const HASH_ATTR = 'data-ln-hash';
11
-
12
- if (window[DOM_ATTRIBUTE] !== undefined) return;
13
-
14
- function _readOrNull(el, name) {
15
- return el.getAttribute(name) || null;
16
- }
17
-
18
- // ─── Attribute Contract (SSOT) ──────────────────────────
19
- const ATTRIBUTES = {
20
- 'data-ln-sort': { prop: 'targetId', type: 'string', read: attrStr, fallback: null, description: 'Target table or list element ID to sort' },
21
- 'data-ln-sort-field': { prop: 'field', type: 'string', read: _readOrNull, effect: _syncAttribute, description: 'Field name or column key to sort by' },
22
- 'data-ln-sort-dir': { type: 'enum', values: ['asc', 'desc'], fallback: 'asc', description: 'Default or requested sort direction' },
23
- 'data-ln-sort-items': { prop: 'itemsSelector', type: 'string', read: _readOrNull, description: 'CSS selector matching sortable child items' },
24
- 'data-ln-sort-state': { type: 'enum', values: ['asc', 'desc', 'none'], fallback: 'none', effect: _syncAttribute, description: 'Active sort state applied to column or control' },
25
- 'data-ln-hash': { type: 'string', effect: _syncAttribute, description: 'URL hash routing key for sort state persistence' }
26
- };
27
-
28
- const ATTR_SPEC = attrSpec(ATTRIBUTES);
29
-
30
- // Target-scoped initial DOM order cache.
31
- const _targetInitialOrders = new WeakMap();
32
-
33
- function _readItemValue(item, field, column) {
34
- if (field) {
35
- const el = item.querySelector('[data-ln-field="' + field + '"]');
36
- return el ? readValue(el) : '';
37
- }
38
- if (column !== null && column !== undefined && item.cells && item.cells[column]) {
39
- return readValue(item.cells[column]);
40
- }
41
- return readValue(item);
42
- }
43
-
44
- // ─── Component ─────────────────────────────────────────────
45
-
46
- function _component(dom) {
47
- this.dom = dom;
48
- defineAttrs(this, dom, ATTR_SPEC);
49
-
50
- const th = dom.closest('th');
51
- this.column = (!this.field && th) ? th.cellIndex : null;
52
-
53
- this._state = normalizeSortDirection(dom.getAttribute(STATE_ATTR));
54
- if (!dom.hasAttribute(STATE_ATTR)) {
55
- dom.setAttribute(STATE_ATTR, this._state);
56
- }
57
- this._destroyed = false;
58
-
59
- this.nsKey = resolveHashNamespace(dom, 'sort');
60
- this.hashEnabled = !!this.nsKey;
61
-
62
- const self = this;
63
-
64
- this._onClick = function (e) {
65
- const btn = e.target.closest('[' + DIR_ATTR + ']');
66
- if (!btn) return;
67
- const nextDir = normalizeSortDirection(btn.getAttribute(DIR_ATTR));
68
- self._apply(nextDir);
69
- };
70
- dom.addEventListener('click', this._onClick);
71
-
72
- this._onSortChange = function (e) {
73
- if (self._destroyed || !e.detail) return;
74
- const target = self._resolveTarget();
75
- const isOurTarget = (target && (e.target === target || target.contains(e.target)))
76
- || (e.detail.targetId && e.detail.targetId === self.targetId);
77
- if (!isOurTarget) return;
78
-
79
- const same = isSameSortTarget(
80
- { field: self.field, column: self.column },
81
- { field: e.detail.field, column: e.detail.column }
82
- );
83
-
84
- if (same) {
85
- const nextDir = normalizeSortDirection(e.detail.direction);
86
- if (nextDir && dom.getAttribute(STATE_ATTR) !== nextDir) {
87
- self._state = nextDir;
88
- dom.setAttribute(STATE_ATTR, nextDir);
89
- self._updateAriaSort(nextDir);
90
- }
91
- return;
92
- }
93
-
94
- // Mutual exclusion: reset losing instances without re-dispatching
95
- if (dom.getAttribute(STATE_ATTR) !== 'none') {
96
- self._state = 'none';
97
- dom.setAttribute(STATE_ATTR, 'none');
98
- self._updateAriaSort('none');
99
- }
100
- };
101
- document.addEventListener('ln-sort:change', this._onSortChange);
102
-
103
- // ─── Hash change listener ──────────────────────────────────
104
- this._onHashChange = function () {
105
- if (self._destroyed || !self.hashEnabled) return;
106
- const val = hashGet(self.nsKey);
107
- const decoded = hashSortDecode(val);
108
- if (decoded) {
109
- const matches = (self.field !== null && decoded.fieldOrColumn === self.field)
110
- || (self.column !== null && String(self.column) === decoded.fieldOrColumn);
111
- if (matches) {
112
- if (self._state !== decoded.direction) self._apply(decoded.direction, true);
113
- } else {
114
- if (self._state !== 'none') {
115
- self._state = 'none';
116
- dom.setAttribute(STATE_ATTR, 'none');
117
- self._updateAriaSort('none');
118
- }
119
- }
120
- } else {
121
- if (self._state !== 'none') {
122
- self._state = 'none';
123
- dom.setAttribute(STATE_ATTR, 'none');
124
- self._updateAriaSort('none');
125
- const target = self._resolveTarget();
126
- if (target) {
127
- const evt = dispatchCancelable(target, 'ln-sort:change', {
128
- field: self.field,
129
- column: self.column,
130
- direction: 'none',
131
- targetId: self.targetId
132
- });
133
- if (!evt.defaultPrevented) self._defaultSort(target, 'none');
134
- }
135
- }
136
- }
137
- };
138
-
139
- if (this.hashEnabled) {
140
- window.addEventListener('hashchange', this._onHashChange);
141
- }
142
-
143
- // ─── Restore State on Boot ─────────────────────────────────
144
- let restored = false;
145
-
146
- if (this.hashEnabled) {
147
- const hashVal = hashGet(this.nsKey);
148
- const decoded = hashSortDecode(hashVal);
149
- if (decoded) {
150
- const matches = (self.field !== null && decoded.fieldOrColumn === self.field)
151
- || (self.column !== null && String(self.column) === decoded.fieldOrColumn);
152
- if (matches) {
153
- queueBoot(function () {
154
- if (self._destroyed) return;
155
- self._apply(decoded.direction, true);
156
- });
157
- }
158
- restored = true;
159
- }
160
- }
161
-
162
- if (!restored) {
163
- const initialDir = normalizeSortDirection(dom.getAttribute(STATE_ATTR));
164
- if (initialDir && initialDir !== 'none') {
165
- queueBoot(function () {
166
- if (self._destroyed) return;
167
- self._apply(initialDir, true);
168
- });
169
- }
170
- }
171
-
172
- return this;
173
- }
174
-
175
- _component.prototype._resolveTarget = function () {
176
- return document.getElementById(this.targetId);
177
- };
178
-
179
- _component.prototype._updateAriaSort = function (direction) {
180
- const th = this.dom.closest('th');
181
- if (!th) return;
182
- th.setAttribute('aria-sort', getAriaSortValue(direction));
183
- };
184
-
185
- _component.prototype._apply = function (direction, skipStorage) {
186
- if (this._destroyed) return;
187
- if (!this.field && this.column === null) {
188
- const th = this.dom.closest('th');
189
- if (th && th.cellIndex !== undefined) this.column = th.cellIndex;
190
- }
191
- const normalized = normalizeSortDirection(direction);
192
- this._state = normalized;
193
- if (this.dom.getAttribute(STATE_ATTR) !== normalized) {
194
- this.dom.setAttribute(STATE_ATTR, normalized);
195
- }
196
-
197
- this._updateAriaSort(normalized);
198
-
199
- const target = this._resolveTarget();
200
- if (!target) return;
201
-
202
- const detail = {
203
- field: this.field,
204
- column: this.column,
205
- direction: normalized,
206
- targetId: this.targetId
207
- };
208
-
209
- if (!skipStorage) {
210
- if (this.hashEnabled) {
211
- const encoded = hashSortEncode(this.field !== null ? this.field : this.column, normalized);
212
- hashSet(this.nsKey, encoded);
213
- }
214
- }
215
-
216
- const evt = dispatchCancelable(target, 'ln-sort:change', detail);
217
- if (evt.defaultPrevented) return;
218
-
219
- this._defaultSort(target, normalized);
220
- };
221
-
222
- // ─── Default DOM behaviour ─────────────────────────────────
223
-
224
- _component.prototype._defaultSort = function (target, direction) {
225
- const allItems = resolveSortItems(target, this.itemsSelector);
226
- if (!allItems.length) return;
227
- const parent = allItems[0].parentNode;
228
-
229
- const items = allItems.filter(function (el) {
230
- return !isExcludedSortItem(el);
231
- });
232
- if (!items.length) return;
233
-
234
- if (!_targetInitialOrders.has(target)) {
235
- _targetInitialOrders.set(target, items.slice());
236
- }
237
-
238
- let ordered;
239
- if (direction === 'none') {
240
- const original = _targetInitialOrders.get(target) || items;
241
- _targetInitialOrders.delete(target);
242
- ordered = original.filter(function (el) {
243
- return el.parentNode === parent && !isExcludedSortItem(el);
244
- });
245
- } else {
246
- const field = this.field;
247
- const column = this.column;
248
- const values = items.map(function (el) { return _readItemValue(el, field, column); });
249
- const type = detectValueType(values);
250
- const collator = typeof Intl !== 'undefined'
251
- ? new Intl.Collator(getLocale(this.dom), { sensitivity: 'base', numeric: true })
252
- : null;
253
-
254
- const comparator = createSortComparator(direction, type, collator, function (el) {
255
- return _readItemValue(el, field, column);
256
- });
257
-
258
- ordered = items.slice().sort(comparator);
259
- }
260
-
261
- const frag = document.createDocumentFragment();
262
- let orderIdx = 0;
263
- for (let i = 0; i < allItems.length; i++) {
264
- const el = allItems[i];
265
- if (isExcludedSortItem(el)) {
266
- frag.appendChild(el);
267
- } else if (orderIdx < ordered.length) {
268
- frag.appendChild(ordered[orderIdx++]);
269
- }
270
- }
271
- parent.appendChild(frag);
272
- };
273
-
274
- // ─── Destroy ───────────────────────────────────────────────
275
-
276
- _component.prototype.destroy = function () {
277
- if (this._destroyed) return;
278
- this._destroyed = true;
279
- this.dom.removeEventListener('click', this._onClick);
280
- document.removeEventListener('ln-sort:change', this._onSortChange);
281
- if (this.hashEnabled && this._onHashChange) {
282
- window.removeEventListener('hashchange', this._onHashChange);
283
- }
284
- delete this.dom[DOM_ATTRIBUTE];
285
- };
286
-
287
- // ─── Attribute Sync ────────────────────────────────────────
288
-
289
- function _syncAttribute(el, attrName) {
290
- const instance = el[DOM_ATTRIBUTE];
291
- if (!instance || instance._destroyed) return;
292
- if (attrName === FIELD_ATTR) {
293
- const th = el.closest('th');
294
- instance.column = (!instance.field && th) ? th.cellIndex : null;
295
- } else if (attrName === STATE_ATTR) {
296
- const nextState = normalizeSortDirection(el.getAttribute(STATE_ATTR));
297
- if (nextState !== instance._state) {
298
- instance._apply(nextState);
299
- }
300
- } else if (attrName === HASH_ATTR) {
301
- if (instance.hashEnabled && instance._onHashChange) {
302
- window.removeEventListener('hashchange', instance._onHashChange);
303
- }
304
- instance.nsKey = resolveHashNamespace(el, 'sort');
305
- instance.hashEnabled = !!instance.nsKey;
306
- if (instance.hashEnabled) {
307
- window.addEventListener('hashchange', instance._onHashChange);
308
- }
309
- }
310
- }
311
-
312
- // ─── Registration ──────────────────────────────────────────
313
-
314
- registerComponent(DOM_SELECTOR, DOM_ATTRIBUTE, _component, 'ln-sort', {
315
- attributes: ATTRIBUTES,
316
- persist: {
317
- attr: STATE_ATTR,
318
- hashActive: function (el) { return !!resolveHashNamespace(el, 'sort'); }
319
- }
320
- });
321
- })();
1
+ import { compareValues, detectValueType, dispatchCancelable, getLocale, hashGet, hashSet, hashSortDecode, hashSortEncode, queueBoot, readValue, registerComponent, resolveHashNamespace, attrStr, attrSpec, defineAttrs } from '../../ln-core';
2
+ import { createSortComparator, getAriaSortValue, isExcludedSortItem, isSameSortTarget, normalizeSortDirection, resolveSortItems } from './sort-model.js';
3
+
4
+ (function () {
5
+ const DOM_SELECTOR = 'data-ln-sort';
6
+ const DOM_ATTRIBUTE = 'lnSort';
7
+ const FIELD_ATTR = 'data-ln-sort-field';
8
+ const STATE_ATTR = 'data-ln-sort-state';
9
+ const DIR_ATTR = 'data-ln-sort-dir';
10
+ const HASH_ATTR = 'data-ln-hash';
11
+
12
+ if (window[DOM_ATTRIBUTE] !== undefined) return;
13
+
14
+ function _readOrNull(el, name) {
15
+ return el.getAttribute(name) || null;
16
+ }
17
+
18
+ // ─── Attribute Contract (SSOT) ──────────────────────────
19
+ const ATTRIBUTES = {
20
+ 'data-ln-sort': { prop: 'targetId', type: 'string', read: attrStr, fallback: null, description: 'Target table or list element ID to sort' },
21
+ 'data-ln-sort-field': { prop: 'field', type: 'string', read: _readOrNull, effect: _syncAttribute, description: 'Field name or column key to sort by' },
22
+ 'data-ln-sort-dir': { type: 'enum', values: ['asc', 'desc'], fallback: 'asc', description: 'Default or requested sort direction' },
23
+ 'data-ln-sort-items': { prop: 'itemsSelector', type: 'string', read: _readOrNull, description: 'CSS selector matching sortable child items' },
24
+ 'data-ln-sort-state': { type: 'enum', values: ['asc', 'desc', 'none'], fallback: 'none', effect: _syncAttribute, description: 'Active sort state applied to column or control' },
25
+ 'data-ln-hash': { type: 'string', effect: _syncAttribute, description: 'URL hash routing key for sort state persistence' }
26
+ };
27
+
28
+ const ATTR_SPEC = attrSpec(ATTRIBUTES);
29
+
30
+ // Target-scoped initial DOM order cache.
31
+ const _targetInitialOrders = new WeakMap();
32
+
33
+ function _readItemValue(item, field, column) {
34
+ if (field) {
35
+ const el = item.querySelector('[data-ln-field="' + field + '"]');
36
+ return el ? readValue(el) : '';
37
+ }
38
+ if (column !== null && column !== undefined && item.cells && item.cells[column]) {
39
+ return readValue(item.cells[column]);
40
+ }
41
+ return readValue(item);
42
+ }
43
+
44
+ // ─── Component ─────────────────────────────────────────────
45
+
46
+ function _component(dom) {
47
+ this.dom = dom;
48
+ defineAttrs(this, dom, ATTR_SPEC);
49
+
50
+ const th = dom.closest('th');
51
+ this.column = (!this.field && th) ? th.cellIndex : null;
52
+
53
+ this._state = normalizeSortDirection(dom.getAttribute(STATE_ATTR));
54
+ if (!dom.hasAttribute(STATE_ATTR)) {
55
+ dom.setAttribute(STATE_ATTR, this._state);
56
+ }
57
+ this._destroyed = false;
58
+
59
+ this.nsKey = resolveHashNamespace(dom, 'sort');
60
+ this.hashEnabled = !!this.nsKey;
61
+
62
+ const self = this;
63
+
64
+ this._onClick = function (e) {
65
+ const btn = e.target.closest('[' + DIR_ATTR + ']');
66
+ if (!btn) return;
67
+ const nextDir = normalizeSortDirection(btn.getAttribute(DIR_ATTR));
68
+ self._apply(nextDir);
69
+ };
70
+ dom.addEventListener('click', this._onClick);
71
+
72
+ this._onSortChange = function (e) {
73
+ if (self._destroyed || !e.detail) return;
74
+ const target = self._resolveTarget();
75
+ const isOurTarget = (target && (e.target === target || target.contains(e.target)))
76
+ || (e.detail.targetId && e.detail.targetId === self.targetId);
77
+ if (!isOurTarget) return;
78
+
79
+ const same = isSameSortTarget(
80
+ { field: self.field, column: self.column },
81
+ { field: e.detail.field, column: e.detail.column }
82
+ );
83
+
84
+ if (same) {
85
+ const nextDir = normalizeSortDirection(e.detail.direction);
86
+ if (nextDir && dom.getAttribute(STATE_ATTR) !== nextDir) {
87
+ self._state = nextDir;
88
+ dom.setAttribute(STATE_ATTR, nextDir);
89
+ self._updateAriaSort(nextDir);
90
+ }
91
+ return;
92
+ }
93
+
94
+ // Mutual exclusion: reset losing instances without re-dispatching
95
+ if (dom.getAttribute(STATE_ATTR) !== 'none') {
96
+ self._state = 'none';
97
+ dom.setAttribute(STATE_ATTR, 'none');
98
+ self._updateAriaSort('none');
99
+ }
100
+ };
101
+ document.addEventListener('ln-sort:change', this._onSortChange);
102
+
103
+ // ─── Hash change listener ──────────────────────────────────
104
+ this._onHashChange = function () {
105
+ if (self._destroyed || !self.hashEnabled) return;
106
+ const val = hashGet(self.nsKey);
107
+ const decoded = hashSortDecode(val);
108
+ if (decoded) {
109
+ const matches = (self.field !== null && decoded.fieldOrColumn === self.field)
110
+ || (self.column !== null && String(self.column) === decoded.fieldOrColumn);
111
+ if (matches) {
112
+ if (self._state !== decoded.direction) self._apply(decoded.direction, true);
113
+ } else {
114
+ if (self._state !== 'none') {
115
+ self._state = 'none';
116
+ dom.setAttribute(STATE_ATTR, 'none');
117
+ self._updateAriaSort('none');
118
+ }
119
+ }
120
+ } else {
121
+ if (self._state !== 'none') {
122
+ self._state = 'none';
123
+ dom.setAttribute(STATE_ATTR, 'none');
124
+ self._updateAriaSort('none');
125
+ const target = self._resolveTarget();
126
+ if (target) {
127
+ const evt = dispatchCancelable(target, 'ln-sort:change', {
128
+ field: self.field,
129
+ column: self.column,
130
+ direction: 'none',
131
+ targetId: self.targetId
132
+ });
133
+ if (!evt.defaultPrevented) self._defaultSort(target, 'none');
134
+ }
135
+ }
136
+ }
137
+ };
138
+
139
+ if (this.hashEnabled) {
140
+ window.addEventListener('hashchange', this._onHashChange);
141
+ }
142
+
143
+ // ─── Restore State on Boot ─────────────────────────────────
144
+ let restored = false;
145
+
146
+ if (this.hashEnabled) {
147
+ const hashVal = hashGet(this.nsKey);
148
+ const decoded = hashSortDecode(hashVal);
149
+ if (decoded) {
150
+ const matches = (self.field !== null && decoded.fieldOrColumn === self.field)
151
+ || (self.column !== null && String(self.column) === decoded.fieldOrColumn);
152
+ if (matches) {
153
+ queueBoot(function () {
154
+ if (self._destroyed) return;
155
+ self._apply(decoded.direction, true);
156
+ });
157
+ }
158
+ restored = true;
159
+ }
160
+ }
161
+
162
+ if (!restored) {
163
+ const initialDir = normalizeSortDirection(dom.getAttribute(STATE_ATTR));
164
+ if (initialDir && initialDir !== 'none') {
165
+ queueBoot(function () {
166
+ if (self._destroyed) return;
167
+ self._apply(initialDir, true);
168
+ });
169
+ }
170
+ }
171
+
172
+ return this;
173
+ }
174
+
175
+ _component.prototype._resolveTarget = function () {
176
+ return document.getElementById(this.targetId);
177
+ };
178
+
179
+ _component.prototype._updateAriaSort = function (direction) {
180
+ const th = this.dom.closest('th');
181
+ if (!th) return;
182
+ th.setAttribute('aria-sort', getAriaSortValue(direction));
183
+ };
184
+
185
+ _component.prototype._apply = function (direction, skipStorage) {
186
+ if (this._destroyed) return;
187
+ if (!this.field && this.column === null) {
188
+ const th = this.dom.closest('th');
189
+ if (th && th.cellIndex !== undefined) this.column = th.cellIndex;
190
+ }
191
+ const normalized = normalizeSortDirection(direction);
192
+ this._state = normalized;
193
+ if (this.dom.getAttribute(STATE_ATTR) !== normalized) {
194
+ this.dom.setAttribute(STATE_ATTR, normalized);
195
+ }
196
+
197
+ this._updateAriaSort(normalized);
198
+
199
+ const target = this._resolveTarget();
200
+ if (!target) return;
201
+
202
+ const detail = {
203
+ field: this.field,
204
+ column: this.column,
205
+ direction: normalized,
206
+ targetId: this.targetId
207
+ };
208
+
209
+ if (!skipStorage) {
210
+ if (this.hashEnabled) {
211
+ const encoded = hashSortEncode(this.field !== null ? this.field : this.column, normalized);
212
+ hashSet(this.nsKey, encoded);
213
+ }
214
+ }
215
+
216
+ const evt = dispatchCancelable(target, 'ln-sort:change', detail);
217
+ if (evt.defaultPrevented) return;
218
+
219
+ this._defaultSort(target, normalized);
220
+ };
221
+
222
+ // ─── Default DOM behaviour ─────────────────────────────────
223
+
224
+ _component.prototype._defaultSort = function (target, direction) {
225
+ const allItems = resolveSortItems(target, this.itemsSelector);
226
+ if (!allItems.length) return;
227
+ const parent = allItems[0].parentNode;
228
+
229
+ const items = allItems.filter(function (el) {
230
+ return !isExcludedSortItem(el);
231
+ });
232
+ if (!items.length) return;
233
+
234
+ if (!_targetInitialOrders.has(target)) {
235
+ _targetInitialOrders.set(target, items.slice());
236
+ }
237
+
238
+ let ordered;
239
+ if (direction === 'none') {
240
+ const original = _targetInitialOrders.get(target) || items;
241
+ _targetInitialOrders.delete(target);
242
+ ordered = original.filter(function (el) {
243
+ return el.parentNode === parent && !isExcludedSortItem(el);
244
+ });
245
+ } else {
246
+ const field = this.field;
247
+ const column = this.column;
248
+ const values = items.map(function (el) { return _readItemValue(el, field, column); });
249
+ const type = detectValueType(values);
250
+ const collator = typeof Intl !== 'undefined'
251
+ ? new Intl.Collator(getLocale(this.dom), { sensitivity: 'base', numeric: true })
252
+ : null;
253
+
254
+ const comparator = createSortComparator(direction, type, collator, function (el) {
255
+ return _readItemValue(el, field, column);
256
+ });
257
+
258
+ ordered = items.slice().sort(comparator);
259
+ }
260
+
261
+ const frag = document.createDocumentFragment();
262
+ let orderIdx = 0;
263
+ for (let i = 0; i < allItems.length; i++) {
264
+ const el = allItems[i];
265
+ if (isExcludedSortItem(el)) {
266
+ frag.appendChild(el);
267
+ } else if (orderIdx < ordered.length) {
268
+ frag.appendChild(ordered[orderIdx++]);
269
+ }
270
+ }
271
+ parent.appendChild(frag);
272
+ };
273
+
274
+ // ─── Destroy ───────────────────────────────────────────────
275
+
276
+ _component.prototype.destroy = function () {
277
+ if (this._destroyed) return;
278
+ this._destroyed = true;
279
+ this.dom.removeEventListener('click', this._onClick);
280
+ document.removeEventListener('ln-sort:change', this._onSortChange);
281
+ if (this.hashEnabled && this._onHashChange) {
282
+ window.removeEventListener('hashchange', this._onHashChange);
283
+ }
284
+ delete this.dom[DOM_ATTRIBUTE];
285
+ };
286
+
287
+ // ─── Attribute Sync ────────────────────────────────────────
288
+
289
+ function _syncAttribute(el, attrName) {
290
+ const instance = el[DOM_ATTRIBUTE];
291
+ if (!instance || instance._destroyed) return;
292
+ if (attrName === FIELD_ATTR) {
293
+ const th = el.closest('th');
294
+ instance.column = (!instance.field && th) ? th.cellIndex : null;
295
+ } else if (attrName === STATE_ATTR) {
296
+ const nextState = normalizeSortDirection(el.getAttribute(STATE_ATTR));
297
+ if (nextState !== instance._state) {
298
+ instance._apply(nextState);
299
+ }
300
+ } else if (attrName === HASH_ATTR) {
301
+ if (instance.hashEnabled && instance._onHashChange) {
302
+ window.removeEventListener('hashchange', instance._onHashChange);
303
+ }
304
+ instance.nsKey = resolveHashNamespace(el, 'sort');
305
+ instance.hashEnabled = !!instance.nsKey;
306
+ if (instance.hashEnabled) {
307
+ window.addEventListener('hashchange', instance._onHashChange);
308
+ }
309
+ }
310
+ }
311
+
312
+ // ─── Registration ──────────────────────────────────────────
313
+
314
+ registerComponent(DOM_SELECTOR, DOM_ATTRIBUTE, _component, 'ln-sort', {
315
+ attributes: ATTRIBUTES,
316
+ persist: {
317
+ attr: STATE_ATTR,
318
+ hashActive: function (el) { return !!resolveHashNamespace(el, 'sort'); }
319
+ }
320
+ });
321
+ })();