@link-foundation/ui-components 0.0.0-stage → 0.0.0

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 (402) hide show
  1. package/CONFIGURATIONS.md +74 -0
  2. package/ICONS.md +76 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1499 -2
  5. package/bin/lino-network.mjs +71 -0
  6. package/dist/icons/ATTRIBUTION.md +602 -0
  7. package/dist/icons/NOTICE.lino +1261 -0
  8. package/dist/icons/brand.js +31 -0
  9. package/dist/icons/brand.svg +3 -0
  10. package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
  11. package/dist/icons/licenses/brand/LICENSE.md +30 -0
  12. package/dist/icons/licenses/lucide/LICENSE +43 -0
  13. package/dist/icons/licenses/material-symbols/LICENSE +202 -0
  14. package/dist/icons/licenses/material-symbols/NOTICE +12 -0
  15. package/dist/icons/licenses/tabler/LICENSE +21 -0
  16. package/dist/icons/lucide.js +681 -0
  17. package/dist/icons/lucide.svg +34 -0
  18. package/dist/icons/material-symbols.js +681 -0
  19. package/dist/icons/material-symbols.svg +34 -0
  20. package/dist/icons/own.js +521 -0
  21. package/dist/icons/own.svg +34 -0
  22. package/dist/icons/tabler.js +681 -0
  23. package/dist/icons/tabler.svg +34 -0
  24. package/dist/network-layout-NOTICE.md +6 -0
  25. package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
  26. package/dist/network-layout-d3-force-LICENSE.txt +13 -0
  27. package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
  28. package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
  29. package/dist/network-layout-dagre-LICENSE.txt +19 -0
  30. package/dist/network-layout.worker.mjs +2 -0
  31. package/package.json +246 -4
  32. package/src/a11y/announce.js +88 -0
  33. package/src/a11y/bind-machine.js +181 -0
  34. package/src/a11y/focus.js +169 -0
  35. package/src/a11y/index.d.ts +89 -0
  36. package/src/a11y/index.js +19 -0
  37. package/src/a11y/keys.js +182 -0
  38. package/src/a11y/roving.js +167 -0
  39. package/src/a11y/typeahead.js +82 -0
  40. package/src/behavior/actions.js +235 -0
  41. package/src/behavior/diagnostics.js +73 -0
  42. package/src/behavior/dom.d.ts +38 -0
  43. package/src/behavior/dom.js +420 -0
  44. package/src/behavior/index.d.ts +211 -0
  45. package/src/behavior/index.js +29 -0
  46. package/src/behavior/interpret.js +454 -0
  47. package/src/behavior/machines/disclosure.lino +46 -0
  48. package/src/behavior/machines/index.js +91 -0
  49. package/src/behavior/machines/toggle.lino +25 -0
  50. package/src/behavior/parse-machine.js +367 -0
  51. package/src/charts/README.md +78 -0
  52. package/src/charts/activity-layout.js +350 -0
  53. package/src/charts/activity-model.js +130 -0
  54. package/src/charts/activity-validation.js +31 -0
  55. package/src/charts/chart-model.js +667 -0
  56. package/src/charts/chart.js +518 -0
  57. package/src/charts/echarts-adapter.d.ts +23 -0
  58. package/src/charts/echarts-adapter.js +240 -0
  59. package/src/charts/element.js +330 -0
  60. package/src/charts/errors.js +62 -0
  61. package/src/charts/gauge.js +27 -0
  62. package/src/charts/index.d.ts +344 -0
  63. package/src/charts/index.js +59 -0
  64. package/src/charts/layout.js +542 -0
  65. package/src/charts/lino.js +158 -0
  66. package/src/charts/mark-options.js +78 -0
  67. package/src/charts/read.js +101 -0
  68. package/src/charts/renderer-features.js +8 -0
  69. package/src/charts/scales.js +223 -0
  70. package/src/charts/small-model.js +223 -0
  71. package/src/charts/small-svg.js +269 -0
  72. package/src/charts/sparkline.js +27 -0
  73. package/src/charts/stat-tile.js +37 -0
  74. package/src/charts/summary.js +193 -0
  75. package/src/charts/svg-renderer.js +226 -0
  76. package/src/charts/svg.js +69 -0
  77. package/src/charts/tag-cloud.js +129 -0
  78. package/src/charts/tokens.js +171 -0
  79. package/src/charts/tooltip.js +47 -0
  80. package/src/charts/values.js +146 -0
  81. package/src/chat/README.md +142 -0
  82. package/src/chat/actions.js +75 -0
  83. package/src/chat/chat-contract.js +95 -0
  84. package/src/chat/chat-list.js +42 -0
  85. package/src/chat/chat-model.js +125 -0
  86. package/src/chat/chat.css +228 -0
  87. package/src/chat/composer.js +131 -0
  88. package/src/chat/day-separator.js +12 -0
  89. package/src/chat/dom.js +33 -0
  90. package/src/chat/follow.js +49 -0
  91. package/src/chat/index.d.ts +142 -0
  92. package/src/chat/index.js +13 -0
  93. package/src/chat/message-bubble.js +191 -0
  94. package/src/chat/message-stream.js +331 -0
  95. package/src/chat/reasoning-trace.js +70 -0
  96. package/src/chat/selection.js +39 -0
  97. package/src/chat/skins/bubbles.lino +2 -0
  98. package/src/chat/skins/cards.lino +4 -0
  99. package/src/chat/skins/compact.lino +4 -0
  100. package/src/chat/skins/signal.lino +25 -0
  101. package/src/chat/skins/t3.lino +25 -0
  102. package/src/chat/skins/telegram.lino +31 -0
  103. package/src/chat/skins/whatsapp.lino +25 -0
  104. package/src/chat/stream-keys.js +57 -0
  105. package/src/chat/stream-window.js +159 -0
  106. package/src/chat/vocabulary.js +19 -0
  107. package/src/controls/accordion.js +160 -0
  108. package/src/controls/avatar.js +80 -0
  109. package/src/controls/badge.js +48 -0
  110. package/src/controls/button-template.js +32 -0
  111. package/src/controls/button.js +97 -0
  112. package/src/controls/catalog.lino +84 -0
  113. package/src/controls/checkbox.js +112 -0
  114. package/src/controls/chip.js +140 -0
  115. package/src/controls/choices.js +45 -0
  116. package/src/controls/color-field.js +217 -0
  117. package/src/controls/color-popover.js +135 -0
  118. package/src/controls/color-rgb.js +80 -0
  119. package/src/controls/color.js +67 -0
  120. package/src/controls/combobox.js +192 -0
  121. package/src/controls/dom.js +261 -0
  122. package/src/controls/icon-button.js +33 -0
  123. package/src/controls/index.d.ts +163 -0
  124. package/src/controls/index.js +182 -0
  125. package/src/controls/kinds-text.js +358 -0
  126. package/src/controls/kinds.lino +350 -0
  127. package/src/controls/label.js +52 -0
  128. package/src/controls/link.js +101 -0
  129. package/src/controls/listbox.js +144 -0
  130. package/src/controls/machines/button.lino +20 -0
  131. package/src/controls/machines/checkbox.lino +17 -0
  132. package/src/controls/machines/chip.lino +20 -0
  133. package/src/controls/machines/color-field.lino +23 -0
  134. package/src/controls/machines/combobox.lino +82 -0
  135. package/src/controls/machines/icon-button.lino +20 -0
  136. package/src/controls/machines/index.js +586 -0
  137. package/src/controls/machines/number-field.lino +71 -0
  138. package/src/controls/machines/radio-group.lino +17 -0
  139. package/src/controls/machines/select.lino +122 -0
  140. package/src/controls/machines/slider.lino +99 -0
  141. package/src/controls/machines/switch.lino +19 -0
  142. package/src/controls/machines/text-area.lino +26 -0
  143. package/src/controls/machines/text-field.lino +26 -0
  144. package/src/controls/number-field.js +239 -0
  145. package/src/controls/numeric-keys.js +125 -0
  146. package/src/controls/option.js +54 -0
  147. package/src/controls/progress.js +76 -0
  148. package/src/controls/radio-group.js +234 -0
  149. package/src/controls/select.js +229 -0
  150. package/src/controls/slider.js +234 -0
  151. package/src/controls/stories.js +172 -0
  152. package/src/controls/styles.css +1060 -0
  153. package/src/controls/switch.js +95 -0
  154. package/src/controls/text-area.js +39 -0
  155. package/src/controls/text-field.js +131 -0
  156. package/src/controls/vocabulary.js +164 -0
  157. package/src/data/data.css +95 -0
  158. package/src/data/index.d.ts +83 -0
  159. package/src/data/index.js +10 -0
  160. package/src/data/keyboard.js +189 -0
  161. package/src/data/list.js +215 -0
  162. package/src/data/render-data.js +116 -0
  163. package/src/data/selection-dom.js +39 -0
  164. package/src/data/selection-model.js +43 -0
  165. package/src/data/sort-model.js +42 -0
  166. package/src/data/source.js +45 -0
  167. package/src/data/table.js +160 -0
  168. package/src/data/tree-model.js +41 -0
  169. package/src/data/tree.js +55 -0
  170. package/src/data/viewport.js +216 -0
  171. package/src/data/virtual-range.js +92 -0
  172. package/src/data/vocabulary.js +67 -0
  173. package/src/diagrams/diagram-model.js +511 -0
  174. package/src/diagrams/diagram.js +204 -0
  175. package/src/diagrams/index.d.ts +225 -0
  176. package/src/diagrams/index.js +48 -0
  177. package/src/diagrams/layout-dagre.js +164 -0
  178. package/src/diagrams/layout-plugins.js +131 -0
  179. package/src/diagrams/mermaid-export.js +232 -0
  180. package/src/diagrams/mermaid-view.js +229 -0
  181. package/src/diagrams/svg-diagram.js +215 -0
  182. package/src/editor/code-editor.js +206 -0
  183. package/src/editor/documents-model.js +170 -0
  184. package/src/editor/documents-persistence.js +85 -0
  185. package/src/editor/editor-engine.js +22 -0
  186. package/src/editor/editor-ui.js +203 -0
  187. package/src/editor/editor.css +106 -0
  188. package/src/editor/engines/codemirror.js +227 -0
  189. package/src/editor/engines/monaco.js +219 -0
  190. package/src/editor/index.d.ts +111 -0
  191. package/src/editor/index.js +14 -0
  192. package/src/editor/lino-highlight.js +106 -0
  193. package/src/editor/lino-structure.js +85 -0
  194. package/src/editor/validate-lino.js +43 -0
  195. package/src/embed/README.md +161 -0
  196. package/src/embed/controller.js +223 -0
  197. package/src/embed/element.js +141 -0
  198. package/src/embed/index.d.ts +75 -0
  199. package/src/embed/index.js +9 -0
  200. package/src/embed/providers/telegram.d.ts +3 -0
  201. package/src/embed/providers/telegram.js +38 -0
  202. package/src/embed/providers/vk.d.ts +3 -0
  203. package/src/embed/providers/vk.js +42 -0
  204. package/src/embed/providers/x.d.ts +3 -0
  205. package/src/embed/providers/x.js +31 -0
  206. package/src/embed/registry.js +35 -0
  207. package/src/embed/script.js +73 -0
  208. package/src/embed/view.js +122 -0
  209. package/src/icons/adapters/lucide.d.ts +15 -0
  210. package/src/icons/adapters/lucide.js +142 -0
  211. package/src/icons/adapters/material-symbols.d.ts +13 -0
  212. package/src/icons/adapters/material-symbols.js +113 -0
  213. package/src/icons/adapters/shared.d.ts +38 -0
  214. package/src/icons/adapters/shared.js +157 -0
  215. package/src/icons/adapters/simple-icons.d.ts +9 -0
  216. package/src/icons/adapters/simple-icons.js +38 -0
  217. package/src/icons/adapters/tabler.d.ts +9 -0
  218. package/src/icons/adapters/tabler.js +86 -0
  219. package/src/icons/icon-registry.js +215 -0
  220. package/src/icons/icon.js +356 -0
  221. package/src/icons/index.d.ts +123 -0
  222. package/src/icons/index.js +30 -0
  223. package/src/icons/names.js +51 -0
  224. package/src/icons/own-icons.js +521 -0
  225. package/src/icons/presentation.js +55 -0
  226. package/src/icons/svg.js +136 -0
  227. package/src/index.d.ts +14 -0
  228. package/src/index.js +40 -0
  229. package/src/layout/README.md +102 -0
  230. package/src/layout/app-shell.js +150 -0
  231. package/src/layout/catalog.lino +27 -0
  232. package/src/layout/dock-model.js +576 -0
  233. package/src/layout/dock-view.js +312 -0
  234. package/src/layout/dock.js +352 -0
  235. package/src/layout/dom.js +312 -0
  236. package/src/layout/grid.js +192 -0
  237. package/src/layout/index.d.ts +267 -0
  238. package/src/layout/index.js +60 -0
  239. package/src/layout/layer-manager.js +120 -0
  240. package/src/layout/layout.css +760 -0
  241. package/src/layout/menu.js +141 -0
  242. package/src/layout/nav-strip.js +174 -0
  243. package/src/layout/page-links.js +166 -0
  244. package/src/layout/panel.js +26 -0
  245. package/src/layout/pref-switches.js +209 -0
  246. package/src/layout/split-model.js +270 -0
  247. package/src/layout/split.js +430 -0
  248. package/src/layout/stack.js +86 -0
  249. package/src/layout/surfaces.js +119 -0
  250. package/src/layout/tab-group.js +151 -0
  251. package/src/layout/tab-strip.js +277 -0
  252. package/src/layout/vocabulary.js +229 -0
  253. package/src/layout/window-frame.js +222 -0
  254. package/src/layout/window.js +146 -0
  255. package/src/links-view/animator.js +144 -0
  256. package/src/links-view/configuration-classes.js +150 -0
  257. package/src/links-view/configuration-model.js +191 -0
  258. package/src/links-view/configuration-notations.js +230 -0
  259. package/src/links-view/configurations.d.ts +73 -0
  260. package/src/links-view/configurations.js +33 -0
  261. package/src/links-view/create-layout-runner.js +79 -0
  262. package/src/links-view/doublet-curves.js +239 -0
  263. package/src/links-view/doublet-layout.js +148 -0
  264. package/src/links-view/doublet-markers.js +109 -0
  265. package/src/links-view/doublet-options.js +369 -0
  266. package/src/links-view/doublet-svg.js +156 -0
  267. package/src/links-view/doublet.js +230 -0
  268. package/src/links-view/export.js +146 -0
  269. package/src/links-view/geometry.js +409 -0
  270. package/src/links-view/index.d.ts +1029 -0
  271. package/src/links-view/index.js +140 -0
  272. package/src/links-view/labels.js +28 -0
  273. package/src/links-view/layout-worker-entry.mjs +2 -0
  274. package/src/links-view/layout-worker.js +28 -0
  275. package/src/links-view/layouts/circle.js +7 -0
  276. package/src/links-view/layouts/force.js +76 -0
  277. package/src/links-view/layouts/grid.js +7 -0
  278. package/src/links-view/layouts/hex.js +8 -0
  279. package/src/links-view/layouts/index.js +15 -0
  280. package/src/links-view/layouts/layered.js +29 -0
  281. package/src/links-view/layouts/regular.js +27 -0
  282. package/src/links-view/layouts/spiral.js +10 -0
  283. package/src/links-view/link-view.js +494 -0
  284. package/src/links-view/links-gallery.js +306 -0
  285. package/src/links-view/links-network.js +496 -0
  286. package/src/links-view/lino-network-source.js +122 -0
  287. package/src/links-view/lino-network.js +233 -0
  288. package/src/links-view/lino-to-network.js +252 -0
  289. package/src/links-view/markers.js +192 -0
  290. package/src/links-view/model.js +233 -0
  291. package/src/links-view/network-editor/dom.js +36 -0
  292. package/src/links-view/network-editor/editor.js +202 -0
  293. package/src/links-view/network-editor/model.js +163 -0
  294. package/src/links-view/network-editor/options.js +265 -0
  295. package/src/links-view/network-editor/panels.js +423 -0
  296. package/src/links-view/network-editor/presets.js +76 -0
  297. package/src/links-view/network-editor/provider.js +93 -0
  298. package/src/links-view/network-editor/remap.js +45 -0
  299. package/src/links-view/network-editor/schema.js +224 -0
  300. package/src/links-view/network-editor/share.js +232 -0
  301. package/src/links-view/network-editor/styles.js +19 -0
  302. package/src/links-view/network-editor/url-sync.js +131 -0
  303. package/src/links-view/network-interaction.js +228 -0
  304. package/src/links-view/network-model.js +85 -0
  305. package/src/links-view/network-renderer.js +259 -0
  306. package/src/links-view/network-scene.js +245 -0
  307. package/src/links-view/network-source.js +82 -0
  308. package/src/links-view/network-vocabulary.js +18 -0
  309. package/src/links-view/presentation.js +199 -0
  310. package/src/links-view/render-canvas.js +102 -0
  311. package/src/links-view/render-svg.js +118 -0
  312. package/src/links-view/scene.js +233 -0
  313. package/src/links-view/solver-job.js +106 -0
  314. package/src/links-view/tokens.js +114 -0
  315. package/src/links-view/zoom-pan.js +203 -0
  316. package/src/overlays/catalog.lino +89 -0
  317. package/src/overlays/context-menu.js +110 -0
  318. package/src/overlays/dialog.js +117 -0
  319. package/src/overlays/dom.js +168 -0
  320. package/src/overlays/drawer.js +8 -0
  321. package/src/overlays/index.d.ts +80 -0
  322. package/src/overlays/index.js +25 -0
  323. package/src/overlays/kinds.lino +137 -0
  324. package/src/overlays/list-popover.js +129 -0
  325. package/src/overlays/machines/index.js +71 -0
  326. package/src/overlays/machines/surface.lino +11 -0
  327. package/src/overlays/machines/tabs.lino +7 -0
  328. package/src/overlays/machines/toast.lino +16 -0
  329. package/src/overlays/machines/tooltip.lino +29 -0
  330. package/src/overlays/menu.js +240 -0
  331. package/src/overlays/popover.js +194 -0
  332. package/src/overlays/position.js +84 -0
  333. package/src/overlays/radial-geometry.js +38 -0
  334. package/src/overlays/radial-menu.js +50 -0
  335. package/src/overlays/styles.css +155 -0
  336. package/src/overlays/tabs.js +125 -0
  337. package/src/overlays/toast-queue.js +105 -0
  338. package/src/overlays/toast.js +163 -0
  339. package/src/overlays/tooltip.js +110 -0
  340. package/src/overlays/vocabulary.js +3 -0
  341. package/src/settings/conditions.js +44 -0
  342. package/src/settings/control-for.js +62 -0
  343. package/src/settings/field-control.js +201 -0
  344. package/src/settings/index.d.ts +201 -0
  345. package/src/settings/index.js +3 -0
  346. package/src/settings/messages.js +112 -0
  347. package/src/settings/miniature.js +26 -0
  348. package/src/settings/panel-actions.js +234 -0
  349. package/src/settings/panel-model.js +49 -0
  350. package/src/settings/panel-refresh.js +56 -0
  351. package/src/settings/panel-rows.js +200 -0
  352. package/src/settings/preset-cards.js +43 -0
  353. package/src/settings/saved-looks.js +227 -0
  354. package/src/settings/section-layout.js +95 -0
  355. package/src/settings/section-tabs.js +175 -0
  356. package/src/settings/settings-panel.js +192 -0
  357. package/src/settings/settings.css +178 -0
  358. package/stories/accordion.lino +14 -0
  359. package/stories/alert-dialog.lino +4 -0
  360. package/stories/app-bar.lino +10 -0
  361. package/stories/avatar.lino +7 -0
  362. package/stories/badge.lino +12 -0
  363. package/stories/button.lino +17 -0
  364. package/stories/card.lino +10 -0
  365. package/stories/checkbox.lino +14 -0
  366. package/stories/chip.lino +19 -0
  367. package/stories/color-field.lino +9 -0
  368. package/stories/combobox.lino +10 -0
  369. package/stories/container.lino +11 -0
  370. package/stories/context-menu.lino +15 -0
  371. package/stories/dialog.lino +16 -0
  372. package/stories/drawer.lino +12 -0
  373. package/stories/icon-button.lino +13 -0
  374. package/stories/label.lino +7 -0
  375. package/stories/link-cards.lino +9 -0
  376. package/stories/link.lino +9 -0
  377. package/stories/menu-item.lino +6 -0
  378. package/stories/menu-separator.lino +7 -0
  379. package/stories/menu.lino +30 -0
  380. package/stories/nav-strip.lino +11 -0
  381. package/stories/number-field.lino +16 -0
  382. package/stories/option.lino +10 -0
  383. package/stories/paper.lino +11 -0
  384. package/stories/popover.lino +4 -0
  385. package/stories/pref-switches.lino +4 -0
  386. package/stories/progress.lino +14 -0
  387. package/stories/radial-menu.lino +19 -0
  388. package/stories/radio-group.lino +22 -0
  389. package/stories/radio.lino +10 -0
  390. package/stories/section-nav.lino +9 -0
  391. package/stories/select.lino +16 -0
  392. package/stories/slider.lino +14 -0
  393. package/stories/switch.lino +10 -0
  394. package/stories/tab-panel.lino +7 -0
  395. package/stories/tab.lino +7 -0
  396. package/stories/tabs.lino +25 -0
  397. package/stories/text-area.lino +12 -0
  398. package/stories/text-field.lino +23 -0
  399. package/stories/titled-section.lino +7 -0
  400. package/stories/toast.lino +3 -0
  401. package/stories/toaster.lino +2 -0
  402. package/stories/tooltip.lino +3 -0
@@ -0,0 +1,106 @@
1
+ /* Editor parts use the same tokens as the basic controls. */
2
+ ui-code-editor {
3
+ display: block;
4
+ color: var(--color-on-surface, CanvasText);
5
+ background: var(--color-surface, Canvas);
6
+ border: 1px solid var(--color-outline, GrayText);
7
+ border-radius: var(--shape-corner-medium, 8px);
8
+ overflow: hidden;
9
+ }
10
+ ui-code-editor [role='tablist'],
11
+ .ui-editor-toolbar,
12
+ .ui-editor-conflict > div {
13
+ display: flex;
14
+ flex-wrap: wrap;
15
+ gap: var(--space-small, 8px);
16
+ padding: var(--space-small, 8px);
17
+ }
18
+ ui-code-editor [role='tab'] {
19
+ font: inherit;
20
+ padding: var(--space-small, 8px) var(--space-medium, 16px);
21
+ background: var(--color-surface-container, Canvas);
22
+ color: inherit;
23
+ border: 1px solid var(--color-outline, GrayText);
24
+ border-radius: var(--shape-corner-small, 4px);
25
+ }
26
+ ui-code-editor [role='tab'][aria-selected='true'] {
27
+ border-bottom: 3px solid var(--color-primary, Highlight);
28
+ font-weight: bold;
29
+ }
30
+ ui-code-editor :focus-visible {
31
+ outline: 2px solid var(--color-primary, Highlight);
32
+ outline-offset: 2px;
33
+ }
34
+ .ui-editor-area {
35
+ min-height: 18rem;
36
+ border-block: 1px solid var(--color-outline, GrayText);
37
+ }
38
+ .ui-editor-area .cm-editor {
39
+ background: var(--color-surface, Canvas);
40
+ color: var(--color-on-surface, CanvasText);
41
+ }
42
+ .ui-editor-area .cm-gutters {
43
+ background: var(--color-surface-container, Canvas);
44
+ color: var(--color-on-surface-variant, CanvasText);
45
+ border-color: var(--color-outline, GrayText);
46
+ }
47
+ .ui-editor-area .cm-cursor {
48
+ border-color: var(--color-on-surface, CanvasText);
49
+ }
50
+ .ui-lino-id,
51
+ .ui-lino-colon,
52
+ .ui-lino-paren {
53
+ color: var(--color-primary, LinkText);
54
+ font-weight: bold;
55
+ }
56
+ .ui-lino-string {
57
+ color: var(--color-editor-string, var(--color-on-surface, CanvasText));
58
+ }
59
+ .ui-lino-comment {
60
+ color: var(--color-on-surface-variant, CanvasText);
61
+ font-style: italic;
62
+ }
63
+ .ui-lino-match {
64
+ outline: 1px solid var(--color-primary, Highlight);
65
+ }
66
+ .ui-editor-conflict {
67
+ padding: var(--space-small, 8px);
68
+ background: var(--color-surface-container, Canvas);
69
+ border-block: 2px solid var(--color-primary, Highlight);
70
+ }
71
+ .ui-editor-compare {
72
+ display: grid;
73
+ grid-template-columns: repeat(2, minmax(0, 1fr));
74
+ gap: var(--space-medium, 16px);
75
+ padding: var(--space-medium, 16px);
76
+ }
77
+ .ui-editor-compare pre {
78
+ overflow: auto;
79
+ white-space: pre-wrap;
80
+ overflow-wrap: anywhere;
81
+ }
82
+ ui-code-editor [hidden] {
83
+ display: none;
84
+ }
85
+ ui-code-editor [aria-label='Diagnostics'] {
86
+ white-space: pre-wrap;
87
+ overflow-wrap: anywhere;
88
+ }
89
+ ui-code-editor [aria-label='Diagnostics']:empty {
90
+ display: none;
91
+ }
92
+ ui-code-editor [aria-label='Diagnostics'] button {
93
+ font: inherit;
94
+ text-align: start;
95
+ color: var(--color-error, CanvasText);
96
+ background: transparent;
97
+ border: 0;
98
+ }
99
+ @media (forced-colors: active) {
100
+ .ui-lino-match {
101
+ outline-color: Highlight;
102
+ }
103
+ ui-code-editor [role='tab'][aria-selected='true'] {
104
+ border-color: Highlight;
105
+ }
106
+ }
@@ -0,0 +1,227 @@
1
+ /** CodeMirror 6 is imported only by the selected adapter. */
2
+ import { highlightLino } from '../lino-highlight.js';
3
+ import { linoStructure } from '../lino-structure.js';
4
+ import { diagnosticOffset } from '../validate-lino.js';
5
+
6
+ async function languageSupport(name) {
7
+ switch (name) {
8
+ case 'javascript':
9
+ return (await import('@codemirror/lang-javascript')).javascript();
10
+ case 'css':
11
+ return (await import('@codemirror/lang-css')).css();
12
+ case 'json':
13
+ return (await import('@codemirror/lang-json')).json();
14
+ case 'markdown':
15
+ return (await import('@codemirror/lang-markdown')).markdown();
16
+ default:
17
+ return [];
18
+ }
19
+ }
20
+
21
+ /** Shared lexical decorations and parser-confirmed bracket matches. */
22
+ function linoDecorations(view, Decoration) {
23
+ const text = view.state.doc.toString();
24
+ const marks = highlightLino(text).map((t) => ({
25
+ from: t.from,
26
+ to: t.to,
27
+ className: `ui-lino-${t.type}`,
28
+ }));
29
+ const cursor = view.state.selection.main.head;
30
+ const structure = linoStructure(text);
31
+ for (const pair of structure.pairs) {
32
+ if ([pair.from, pair.from + 1, pair.to - 1, pair.to].includes(cursor)) {
33
+ for (const at of [pair.from, pair.to - 1]) {
34
+ marks.push({ from: at, to: at + 1, className: 'ui-lino-match' });
35
+ }
36
+ }
37
+ }
38
+ return {
39
+ structure,
40
+ decorations: Decoration.set(
41
+ marks.map((m) =>
42
+ Decoration.mark({ class: m.className }).range(m.from, m.to)
43
+ ),
44
+ true
45
+ ),
46
+ };
47
+ }
48
+
49
+ function syntaxColors(language, tags) {
50
+ return language.syntaxHighlighting(
51
+ language.HighlightStyle.define([
52
+ {
53
+ tag: [tags.keyword, tags.name],
54
+ color: 'var(--color-primary, LinkText)',
55
+ },
56
+ {
57
+ tag: [tags.string, tags.number, tags.bool],
58
+ color: 'var(--color-editor-string, CanvasText)',
59
+ },
60
+ {
61
+ tag: tags.comment,
62
+ color: 'var(--color-on-surface-variant, CanvasText)',
63
+ fontStyle: 'italic',
64
+ },
65
+ { tag: tags.heading, fontWeight: 'bold' },
66
+ ])
67
+ );
68
+ }
69
+
70
+ function createLinoPlugin(ViewPlugin, Decoration) {
71
+ return ViewPlugin.fromClass(
72
+ class {
73
+ constructor(view) {
74
+ Object.assign(this, linoDecorations(view, Decoration));
75
+ }
76
+ update(update) {
77
+ if (update.docChanged || update.selectionSet) {
78
+ Object.assign(this, linoDecorations(update.view, Decoration));
79
+ }
80
+ }
81
+ },
82
+ { decorations: (plugin) => plugin.decorations }
83
+ );
84
+ }
85
+
86
+ /** @returns {Promise<import('../editor-engine.js').EditorEngine>} */
87
+ export async function createCodeMirrorEngine(
88
+ parent,
89
+ { label = 'Source editor', onChange = () => {} } = {}
90
+ ) {
91
+ const [state, viewApi, language, commands, lint, { tags }] =
92
+ await Promise.all([
93
+ import('@codemirror/state'),
94
+ import('@codemirror/view'),
95
+ import('@codemirror/language'),
96
+ import('@codemirror/commands'),
97
+ import('@codemirror/lint'),
98
+ import('@lezer/highlight'),
99
+ ]);
100
+ const { EditorState } = state;
101
+ const { EditorView, ViewPlugin, Decoration, keymap } = viewApi;
102
+ const sessions = new Map();
103
+ let current = null;
104
+ let revision = 0;
105
+ let destroyed = false;
106
+ let readOnly = false;
107
+ const access = new state.Compartment();
108
+ // Keep the DOM focusable and copyable in Safari; the state facet blocks input.
109
+ const accessExtensions = () => EditorState.readOnly.of(readOnly);
110
+ const lino = createLinoPlugin(ViewPlugin, Decoration);
111
+ const base = [
112
+ commands.history(),
113
+ keymap.of([
114
+ ...commands.defaultKeymap,
115
+ ...commands.historyKeymap,
116
+ ...language.foldKeymap,
117
+ commands.indentWithTab,
118
+ ]),
119
+ EditorView.contentAttributes.of({ 'aria-label': label, tabindex: '0' }),
120
+ access.of(accessExtensions()),
121
+ EditorView.lineWrapping,
122
+ viewApi.lineNumbers(),
123
+ language.foldGutter(),
124
+ syntaxColors(language, tags),
125
+ EditorView.updateListener.of((update) => {
126
+ if (update.docChanged && current) {
127
+ onChange(update.state.doc.toString(), current.id);
128
+ }
129
+ }),
130
+ EditorView.theme({
131
+ '&': { minHeight: '18rem' },
132
+ '.cm-content': { fontFamily: 'monospace' },
133
+ '.cm-scroller': { overflow: 'auto' },
134
+ }),
135
+ ];
136
+ const view = new EditorView({
137
+ parent,
138
+ state: EditorState.create({ extensions: base }),
139
+ });
140
+ function setReadOnly(enabled) {
141
+ readOnly = enabled;
142
+ if (view.state.facet(EditorState.readOnly) !== enabled) {
143
+ view.dispatch({ effects: access.reconfigure(accessExtensions()) });
144
+ }
145
+ }
146
+ return {
147
+ setReadOnly,
148
+ async setDocument(doc) {
149
+ if (
150
+ current?.id === doc.id &&
151
+ current.language === doc.language &&
152
+ view.state.doc.toString() === doc.text
153
+ ) {
154
+ return;
155
+ }
156
+ const run = ++revision;
157
+ if (current) {
158
+ sessions.set(current.id, {
159
+ state: view.state,
160
+ language: current.language,
161
+ });
162
+ }
163
+ const extension = await languageSupport(doc.language);
164
+ if (destroyed || run !== revision) {
165
+ return;
166
+ }
167
+ const previous = sessions.get(doc.id);
168
+ const restored =
169
+ previous?.language === doc.language &&
170
+ previous.state.doc.toString() === doc.text;
171
+ const extras =
172
+ doc.language === 'lino'
173
+ ? [
174
+ lino,
175
+ language.foldService.of(
176
+ (s, from, to) =>
177
+ view
178
+ .plugin(lino)
179
+ ?.structure.folds.find(
180
+ (f) => f.from >= from && f.from <= to
181
+ ) ?? null
182
+ ),
183
+ ]
184
+ : [extension, language.bracketMatching()];
185
+ current = doc;
186
+ view.setState(
187
+ restored
188
+ ? previous.state
189
+ : EditorState.create({ doc: doc.text, extensions: [...base, extras] })
190
+ );
191
+ setReadOnly(readOnly);
192
+ },
193
+ setDiagnostics(diagnostics) {
194
+ const text = view.state.doc.toString();
195
+ view.dispatch(
196
+ lint.setDiagnostics(
197
+ view.state,
198
+ diagnostics.map((d) => {
199
+ const from = diagnosticOffset(text, d);
200
+ return {
201
+ from,
202
+ to: Math.min(text.length, from + 1),
203
+ severity: d.severity,
204
+ message: d.message,
205
+ };
206
+ })
207
+ )
208
+ );
209
+ },
210
+ focus(offset) {
211
+ if (offset !== undefined) {
212
+ view.dispatch({
213
+ selection: { anchor: Math.min(offset, view.state.doc.length) },
214
+ scrollIntoView: true,
215
+ });
216
+ }
217
+ view.focus();
218
+ },
219
+ destroy() {
220
+ destroyed = true;
221
+ revision++;
222
+ sessions.clear();
223
+ view.destroy();
224
+ },
225
+ view,
226
+ };
227
+ }
@@ -0,0 +1,219 @@
1
+ /** Optional desktop adapter. Host bundlers configure Monaco's worker URLs. */
2
+ import { highlightLinoLine } from '../lino-highlight.js';
3
+ import { linoStructure } from '../lino-structure.js';
4
+
5
+ const tokenState = (continuation = '') => ({
6
+ continuation,
7
+ clone() {
8
+ return tokenState(this.continuation);
9
+ },
10
+ equals(other) {
11
+ return other?.continuation === this.continuation;
12
+ },
13
+ });
14
+
15
+ function registerLino(monaco) {
16
+ if (monaco.languages.getLanguages().some((lang) => lang.id === 'lino')) {
17
+ return;
18
+ }
19
+ monaco.languages.register({ id: 'lino' });
20
+ monaco.languages.setTokensProvider('lino', {
21
+ getInitialState: () => tokenState(),
22
+ tokenize(line, state) {
23
+ const result = highlightLinoLine(line, state.continuation);
24
+ return {
25
+ tokens: result.tokens.map((t) => ({
26
+ startIndex: t.from,
27
+ scopes: `${t.type}.lino`,
28
+ })),
29
+ endState: tokenState(result.continuation),
30
+ };
31
+ },
32
+ });
33
+ monaco.languages.setLanguageConfiguration('lino', {
34
+ brackets: [['(', ')']],
35
+ autoClosingPairs: [{ open: '(', close: ')', notIn: ['string', 'comment'] }],
36
+ });
37
+ monaco.languages.registerFoldingRangeProvider('lino', {
38
+ provideFoldingRanges(model) {
39
+ return linoStructure(model.getValue()).folds.map((fold) => ({
40
+ start: model.getPositionAt(fold.from).lineNumber,
41
+ end: model.getPositionAt(fold.to).lineNumber,
42
+ }));
43
+ },
44
+ });
45
+ }
46
+
47
+ function configureTheme(monaco, win) {
48
+ const dark = win.matchMedia('(prefers-color-scheme: dark)');
49
+ for (const [name, base, foreground] of [
50
+ ['light', 'vs', '202124'],
51
+ ['dark', 'vs-dark', 'e8eaed'],
52
+ ]) {
53
+ monaco.editor.defineTheme(`ui-lino-${name}`, {
54
+ base,
55
+ inherit: true,
56
+ colors: {},
57
+ rules: [
58
+ { token: 'paren.lino', foreground },
59
+ { token: 'colon.lino', foreground },
60
+ { token: 'word.lino', foreground },
61
+ { token: 'id.lino', foreground: name === 'dark' ? '82b1ff' : '164ca0' },
62
+ {
63
+ token: 'string.lino',
64
+ foreground: name === 'dark' ? '8cdbb1' : '136b36',
65
+ },
66
+ {
67
+ token: 'comment.lino',
68
+ foreground: name === 'dark' ? 'b9b9c3' : '555563',
69
+ },
70
+ ],
71
+ });
72
+ }
73
+ const update = () =>
74
+ monaco.editor.setTheme(`ui-lino-${dark.matches ? 'dark' : 'light'}`);
75
+ update();
76
+ dark.addEventListener('change', update);
77
+ return () => dark.removeEventListener('change', update);
78
+ }
79
+
80
+ function matchingLinks(editor, monaco) {
81
+ const marks = editor.createDecorationsCollection();
82
+ const update = () => {
83
+ const model = editor.getModel();
84
+ const position = editor.getPosition();
85
+ const at = model && position ? model.getOffsetAt(position) : -1;
86
+ const pair =
87
+ model?.getLanguageId() === 'lino'
88
+ ? linoStructure(model.getValue()).pairs.find(
89
+ (p) =>
90
+ p.from === at ||
91
+ p.from + 1 === at ||
92
+ p.to === at ||
93
+ p.to - 1 === at
94
+ )
95
+ : null;
96
+ marks.set(
97
+ pair
98
+ ? [pair.from, pair.to - 1].map((offset) => {
99
+ const start = model.getPositionAt(offset);
100
+ const end = model.getPositionAt(offset + 1);
101
+ return {
102
+ range: new monaco.Range(
103
+ start.lineNumber,
104
+ start.column,
105
+ end.lineNumber,
106
+ end.column
107
+ ),
108
+ options: { inlineClassName: 'ui-lino-match' },
109
+ };
110
+ })
111
+ : []
112
+ );
113
+ };
114
+ const cursor = editor.onDidChangeCursorPosition(update);
115
+ const content = editor.onDidChangeModelContent(update);
116
+ const model = editor.onDidChangeModel(update);
117
+ return () => {
118
+ cursor.dispose();
119
+ content.dispose();
120
+ model.dispose();
121
+ marks.clear();
122
+ };
123
+ }
124
+
125
+ export async function createMonacoEngine(
126
+ parent,
127
+ {
128
+ label = 'Source editor',
129
+ onChange = () => {},
130
+ loadMonaco = () => import('monaco-editor'),
131
+ } = {}
132
+ ) {
133
+ const monaco = await loadMonaco();
134
+ registerLino(monaco);
135
+ const disposeTheme = configureTheme(monaco, parent.ownerDocument.defaultView);
136
+ const models = new Map();
137
+ const selections = new Map();
138
+ let current;
139
+ let applying = false;
140
+ const editor = monaco.editor.create(parent, {
141
+ ariaLabel: label,
142
+ automaticLayout: true,
143
+ minimap: { enabled: false },
144
+ fixedOverflowWidgets: true,
145
+ matchBrackets: 'never',
146
+ bracketPairColorization: { enabled: false },
147
+ });
148
+ const disposeMatches = matchingLinks(editor, monaco);
149
+ const listener = editor.onDidChangeModelContent(() => {
150
+ if (!applying) {
151
+ onChange(editor.getValue(), current);
152
+ }
153
+ });
154
+ return {
155
+ setReadOnly(readOnly) {
156
+ editor.updateOptions({ readOnly, domReadOnly: readOnly });
157
+ },
158
+ setDocument(doc) {
159
+ applying = true;
160
+ try {
161
+ if (current !== doc.id && current !== undefined) {
162
+ selections.set(current, editor.saveViewState());
163
+ }
164
+ if (!models.has(doc.id)) {
165
+ models.set(doc.id, monaco.editor.createModel(doc.text, doc.language));
166
+ }
167
+ const model = models.get(doc.id);
168
+ if (model.getLanguageId() !== doc.language) {
169
+ monaco.editor.setModelLanguage(model, doc.language);
170
+ }
171
+ if (model.getValue() !== doc.text) {
172
+ model.setValue(doc.text);
173
+ }
174
+ if (current !== doc.id) {
175
+ editor.setModel(model);
176
+ editor.restoreViewState(selections.get(doc.id) ?? null);
177
+ }
178
+ current = doc.id;
179
+ } finally {
180
+ applying = false;
181
+ }
182
+ },
183
+ setDiagnostics(diagnostics) {
184
+ const model = editor.getModel();
185
+ if (model) {
186
+ monaco.editor.setModelMarkers(
187
+ model,
188
+ 'lino',
189
+ diagnostics.map((d) => ({
190
+ startLineNumber: d.line,
191
+ startColumn: d.column,
192
+ endLineNumber: d.line,
193
+ endColumn: d.column + 1,
194
+ severity:
195
+ d.severity === 'error'
196
+ ? monaco.MarkerSeverity.Error
197
+ : monaco.MarkerSeverity.Warning,
198
+ message: d.message,
199
+ }))
200
+ );
201
+ }
202
+ },
203
+ focus(offset) {
204
+ if (offset !== undefined && editor.getModel()) {
205
+ editor.setPosition(editor.getModel().getPositionAt(offset));
206
+ }
207
+ editor.focus();
208
+ },
209
+ destroy() {
210
+ listener.dispose();
211
+ disposeTheme();
212
+ disposeMatches();
213
+ editor.dispose();
214
+ for (const model of models.values()) {
215
+ model.dispose();
216
+ }
217
+ },
218
+ };
219
+ }
@@ -0,0 +1,111 @@
1
+ export interface EditorDiagnostic {
2
+ line: number;
3
+ column: number;
4
+ message: string;
5
+ severity: 'error' | 'warning';
6
+ }
7
+ export interface EditorDocument {
8
+ id: string;
9
+ title: string;
10
+ text: string;
11
+ saved: string;
12
+ language: string;
13
+ dirty: boolean;
14
+ incoming: string | null;
15
+ }
16
+ export interface EditorStorage {
17
+ getItem(key: string): string | null;
18
+ setItem(key: string, value: string): void;
19
+ }
20
+ export interface DocumentsOptions {
21
+ storage?: EditorStorage;
22
+ key?: string;
23
+ clock?: {
24
+ setTimeout(fn: () => void, ms: number): unknown;
25
+ clearTimeout(id: unknown): void;
26
+ };
27
+ }
28
+ export interface DocumentsModel {
29
+ readonly documents: EditorDocument[];
30
+ readonly active: EditorDocument | null;
31
+ get(id: string): EditorDocument | null;
32
+ subscribe(fn: (event: { type: string; id: string }) => void): () => void;
33
+ open(doc: {
34
+ id: string;
35
+ text?: string;
36
+ title?: string;
37
+ language?: string;
38
+ }): EditorDocument;
39
+ switch(id: string): void;
40
+ edit(id: string, text: string): void;
41
+ save(id: string): string;
42
+ close(id: string, options?: { discard?: boolean }): 'closed' | 'unsaved';
43
+ externalUpdate(
44
+ id: string,
45
+ text: string
46
+ ): 'updated' | 'unchanged' | 'conflict';
47
+ resolve(id: string, choice: 'mine' | 'theirs'): void;
48
+ destroy(): void;
49
+ }
50
+ export interface EditorEngine {
51
+ setDocument(
52
+ document: Pick<EditorDocument, 'id' | 'text' | 'language'>
53
+ ): void | Promise<void>;
54
+ setDiagnostics(diagnostics: EditorDiagnostic[]): void;
55
+ setReadOnly(readOnly: boolean): void;
56
+ focus(offset?: number): void;
57
+ destroy(): void;
58
+ }
59
+ export interface EditorOptions extends DocumentsOptions {
60
+ model?: DocumentsModel;
61
+ engine?: 'codemirror' | 'monaco';
62
+ label?: string;
63
+ confirmClose?: (document: EditorDocument) => boolean;
64
+ engineOptions?: { loadMonaco?: () => Promise<unknown> };
65
+ }
66
+ export interface CodeEditorElement extends HTMLElement {
67
+ editorOptions: EditorOptions;
68
+ readonly model: DocumentsModel;
69
+ readonly ready: Promise<void>;
70
+ openDocument: DocumentsModel['open'];
71
+ externalUpdate: DocumentsModel['externalUpdate'];
72
+ focusEditor(offset?: number): void;
73
+ }
74
+ export function validateLino(text: string): {
75
+ ok: boolean;
76
+ diagnostics: EditorDiagnostic[];
77
+ };
78
+ export function diagnosticOffset(
79
+ text: string,
80
+ diagnostic: Pick<EditorDiagnostic, 'line' | 'column'>
81
+ ): number;
82
+ export function highlightLino(text: string): {
83
+ type: 'paren' | 'id' | 'colon' | 'string' | 'comment' | 'word';
84
+ from: number;
85
+ to: number;
86
+ }[];
87
+ export function linoStructure(text: string): {
88
+ pairs: { from: number; to: number }[];
89
+ folds: { from: number; to: number }[];
90
+ };
91
+ export function createDocumentsModel(
92
+ options?: DocumentsOptions
93
+ ): DocumentsModel;
94
+ export function createEditorEngine(
95
+ name: 'codemirror' | 'monaco',
96
+ parent: HTMLElement,
97
+ options?: Record<string, unknown>
98
+ ): Promise<EditorEngine>;
99
+ export function defineCodeEditor(window?: Window & typeof globalThis): void;
100
+ export function mountCodeEditor(
101
+ host: HTMLElement,
102
+ options?: EditorOptions
103
+ ): {
104
+ model: DocumentsModel;
105
+ ready: Promise<void>;
106
+ focus(offset?: number): void;
107
+ destroy(): void;
108
+ };
109
+ export function registerEditor(
110
+ target?: Map<string, object> | Record<string, object>
111
+ ): object;
@@ -0,0 +1,14 @@
1
+ export { validateLino, diagnosticOffset } from './validate-lino.js';
2
+ export { highlightLino } from './lino-highlight.js';
3
+ export { linoStructure } from './lino-structure.js';
4
+ export { createDocumentsModel } from './documents-model.js';
5
+ export { createEditorEngine } from './editor-engine.js';
6
+ export {
7
+ defineCodeEditor,
8
+ mountCodeEditor,
9
+ registerEditor,
10
+ } from './code-editor.js';
11
+
12
+ import { defineCodeEditor, registerEditor } from './code-editor.js';
13
+ defineCodeEditor();
14
+ registerEditor();